text
stringlengths
157
7.64M
meta
dict
(* Title: HOL/Algebra/Coset.thy Authors: Florian Kammueller, L C Paulson, Stephan Hohe With additional contributions from Martin Baillon and Paulo Emílio de Vilhena. *) theory Coset imports Group begin section ‹Cosets and Quotient Groups› definition r_coset :: "[_, 'a set, 'a] ⇒ 'a set" (infixl "#>ı" 60) where "H #>⇘G⇙ a = (⋃h∈H. {h ⊗⇘G⇙ a})" definition l_coset :: "[_, 'a, 'a set] ⇒ 'a set" (infixl "<#ı" 60) where "a <#⇘G⇙ H = (⋃h∈H. {a ⊗⇘G⇙ h})" definition RCOSETS :: "[_, 'a set] ⇒ ('a set)set" ("rcosetsı _" [81] 80) where "rcosets⇘G⇙ H = (⋃a∈carrier G. {H #>⇘G⇙ a})" definition set_mult :: "[_, 'a set ,'a set] ⇒ 'a set" (infixl "<#>ı" 60) where "H <#>⇘G⇙ K = (⋃h∈H. ⋃k∈K. {h ⊗⇘G⇙ k})" definition SET_INV :: "[_,'a set] ⇒ 'a set" ("set'_invı _" [81] 80) where "set_inv⇘G⇙ H = (⋃h∈H. {inv⇘G⇙ h})" locale normal = subgroup + group + assumes coset_eq: "(∀x ∈ carrier G. H #> x = x <# H)" abbreviation normal_rel :: "['a set, ('a, 'b) monoid_scheme] ⇒ bool" (infixl "⊲" 60) where "H ⊲ G ≡ normal H G" lemma (in comm_group) subgroup_imp_normal: "subgroup A G ⟹ A ⊲ G" by (simp add: normal_def (*‹?H ⊲ ?G ≡ subgroup ?H ?G ∧ Group.group ?G ∧ normal_axioms ?H ?G›*) normal_axioms_def (*‹normal_axioms ?H ?G ≡ ∀x∈carrier ?G. ?H #>⇘?G⇙ x = x <#⇘?G⇙ ?H›*) l_coset_def (*‹?a <#⇘?G⇙ ?H = (⋃h∈?H. {?a ⊗⇘?G⇙ h})›*) r_coset_def (*‹?H #>⇘?G⇙ ?a = (⋃h∈?H. {h ⊗⇘?G⇙ ?a})›*) m_comm (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ ?x ⊗ ?y = ?y ⊗ ?x›*) subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*)) lemma l_coset_eq_set_mult: ✐‹contributor ‹Martin Baillon›› fixes G (structure) shows "x <# H = {x} <#> H" unfolding l_coset_def set_mult_def (*goal: ‹(⋃h∈H. {x ⊗ h}) = (⋃h∈{x}. ⋃k∈H. {h ⊗ k})›*) by simp lemma r_coset_eq_set_mult: ✐‹contributor ‹Martin Baillon›› fixes G (structure) shows "H #> x = H <#> {x}" unfolding r_coset_def set_mult_def (*goal: ‹(⋃h::'a::type∈H::'a::type set. {h ⊗ (x::'a::type)}) = (⋃h::'a::type∈H. ⋃k::'a::type∈{x}. {h ⊗ k})›*) by simp lemma (in subgroup) rcosets_non_empty: ✐‹contributor ‹Paulo Emílio de Vilhena›› assumes "R ∈ rcosets H" shows "R ≠ {}" proof (-) (*goal: ‹R ≠ {}›*) obtain g where "g ∈ carrier G" "R = H #> g" (*goal: ‹(⋀g. ⟦g ∈ carrier G; R = H #> g⟧ ⟹ thesis) ⟹ thesis›*) using assms (*‹(R::'a::type set) ∈ rcosets (H::'a::type set)›*) unfolding RCOSETS_def (*goal: ‹(⋀g. ⟦g ∈ carrier G; R = H #> g⟧ ⟹ thesis) ⟹ thesis›*) by blast hence "𝟭 ⊗ g ∈ R" using one_closed (*‹𝟭 ∈ H›*) unfolding r_coset_def (*goal: ‹𝟭 ⊗ g ∈ R›*) by blast thus "?thesis" (*goal: ‹R ≠ {}›*) by blast qed lemma (in group) diff_neutralizes: ✐‹contributor ‹Paulo Emílio de Vilhena›› assumes "subgroup H G" "R ∈ rcosets H" shows "⋀r1 r2. ⟦ r1 ∈ R; r2 ∈ R ⟧ ⟹ r1 ⊗ (inv r2) ∈ H" proof (-) (*goal: ‹⋀r1 r2. ⟦r1 ∈ R; r2 ∈ R⟧ ⟹ r1 ⊗ inv r2 ∈ H›*) fix r1 and r2 assume r1: "r1 ∈ R" and r2: "r2 ∈ R" (*‹(r1::'a) ∈ (R::'a set)› ‹(r2::'a) ∈ (R::'a set)›*) obtain g where g: "g ∈ carrier G" "R = H #> g" (*goal: ‹(⋀g. ⟦g ∈ carrier G; R = H #> g⟧ ⟹ thesis) ⟹ thesis›*) using assms (*‹subgroup (H::'a::type set) G› ‹R ∈ rcosets H›*) unfolding RCOSETS_def (*goal: ‹(⋀g. ⟦g ∈ carrier G; R = H #> g⟧ ⟹ thesis) ⟹ thesis›*) by blast then obtain h1 and h2 where h1: "h1 ∈ H" "r1 = h1 ⊗ g" and h2: "h2 ∈ H" "r2 = h2 ⊗ g" (*goal: ‹(⋀h1 h2. ⟦h1 ∈ H; r1 = h1 ⊗ g; h2 ∈ H; r2 = h2 ⊗ g⟧ ⟹ thesis) ⟹ thesis›*) using r1 (*‹(r1::'a) ∈ (R::'a set)›*) r2 (*‹r2 ∈ R›*) unfolding r_coset_def (*goal: ‹(⋀h1 h2. ⟦h1 ∈ H; r1 = h1 ⊗ g; h2 ∈ H; r2 = h2 ⊗ g⟧ ⟹ thesis) ⟹ thesis›*) by blast hence "r1 ⊗ (inv r2) = (h1 ⊗ g) ⊗ ((inv g) ⊗ (inv h2))" using inv_mult_group (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ inv (?x ⊗ ?y) = inv ?y ⊗ inv ?x›*) is_group (*‹Group.group G›*) assms(1) (*‹subgroup H G›*) g(1) (*‹g ∈ carrier G›*) subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*) by fastforce also (*calculation: ‹r1 ⊗ inv r2 = h1 ⊗ g ⊗ (inv g ⊗ inv h2)›*) have " ... = (h1 ⊗ (g ⊗ inv g) ⊗ inv h2)" using h1 (*‹(h1::'a) ∈ (H::'a set)› ‹r1 = h1 ⊗ g›*) h2 (*‹h2 ∈ H› ‹r2 = h2 ⊗ g›*) assms(1) (*‹subgroup H G›*) g(1) (*‹g ∈ carrier G›*) inv_closed (*‹?x ∈ carrier G ⟹ inv ?x ∈ carrier G›*) m_closed (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ ?x ⊗ ?y ∈ carrier G›*) monoid.m_assoc (*‹⟦Group.monoid ?G; ?x ∈ carrier ?G; ?y ∈ carrier ?G; ?z ∈ carrier ?G⟧ ⟹ ?x ⊗⇘?G⇙ ?y ⊗⇘?G⇙ ?z = ?x ⊗⇘?G⇙ (?y ⊗⇘?G⇙ ?z)›*) monoid_axioms (*‹Group.monoid G›*) subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*) proof (-) (*goal: ‹⟦h1 ∈ H; r1 = h1 ⊗ g; h2 ∈ H; r2 = h2 ⊗ g; subgroup H G; g ∈ carrier G; ⋀x. x ∈ carrier G ⟹ inv x ∈ carrier G; ⋀x y. ⟦x ∈ carrier G; y ∈ carrier G⟧ ⟹ x ⊗ y ∈ carrier G; ⋀G x y z. ⟦Group.monoid G; x ∈ carrier G; y ∈ carrier G; z ∈ carrier G⟧ ⟹ x ⊗⇘G⇙ y ⊗⇘G⇙ z = x ⊗⇘G⇙ (y ⊗⇘G⇙ z); Group.monoid G; ⋀H G x. ⟦subgroup H G; x ∈ H⟧ ⟹ x ∈ carrier G⟧ ⟹ h1 ⊗ g ⊗ (inv g ⊗ inv h2) = h1 ⊗ (g ⊗ inv g) ⊗ inv h2›*) have "h1 ∈ carrier G" by (meson subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*) assms( (*‹subgroup H G›*) 1) h1( (*‹h1 ∈ H›*) 1)) moreover have "h2 ∈ carrier G" by (meson subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*) assms( (*‹subgroup H G›*) 1) h2( (*‹h2 ∈ H›*) 1)) ultimately show "?thesis" (*goal: ‹h1 ⊗ g ⊗ (inv g ⊗ inv h2) = h1 ⊗ (g ⊗ inv g) ⊗ inv h2›*) using g(1) (*‹(g::'a) ∈ carrier G›*) inv_closed (*‹?x ∈ carrier G ⟹ inv ?x ∈ carrier G›*) m_assoc (*‹⟦?x ∈ carrier G; ?y ∈ carrier G; ?z ∈ carrier G⟧ ⟹ ?x ⊗ ?y ⊗ ?z = ?x ⊗ (?y ⊗ ?z)›*) m_closed (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ ?x ⊗ ?y ∈ carrier G›*) by presburger qed finally (*calculation: ‹r1 ⊗ inv r2 = h1 ⊗ (g ⊗ inv g) ⊗ inv h2›*) have "r1 ⊗ inv r2 = h1 ⊗ inv h2" using assms(1) (*‹subgroup (H::'a set) G›*) g(1) (*‹g ∈ carrier G›*) h1(1) (*‹h1 ∈ H›*) subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*) by fastforce thus "r1 ⊗ inv r2 ∈ H" by (metis assms( (*‹subgroup (H::'a set) G›*) 1) h1( (*‹(h1::'a) ∈ (H::'a set)›*) 1) h2( (*‹(h2::'a) ∈ (H::'a set)›*) 1) subgroup_def (*‹subgroup (?H::?'a set) (?G::(?'a, ?'b) monoid_scheme) ≡ (?H ⊆ carrier ?G ∧ (∀(x::?'a) y::?'a. x ∈ ?H ⟶ y ∈ ?H ⟶ x ⊗⇘?G⇙ y ∈ ?H)) ∧ 𝟭⇘?G⇙ ∈ ?H ∧ (∀x::?'a. x ∈ ?H ⟶ inv⇘?G⇙ x ∈ ?H)›*)) qed lemma mono_set_mult: "⟦ H ⊆ H'; K ⊆ K' ⟧ ⟹ H <#>⇘G⇙ K ⊆ H' <#>⇘G⇙ K'" ✐‹contributor ‹Paulo Emílio de Vilhena›› unfolding set_mult_def (*goal: ‹⟦H ⊆ H'; K ⊆ K'⟧ ⟹ (⋃h∈H. ⋃k∈K. {h ⊗⇘G⇙ k}) ⊆ (⋃h∈H'. ⋃k∈K'. {h ⊗⇘G⇙ k})›*) by (simp add: UN_mono (*‹⟦?A ⊆ ?B; ⋀x. x ∈ ?A ⟹ ?f x ⊆ ?g x⟧ ⟹ ⋃ (?f ` ?A) ⊆ ⋃ (?g ` ?B)›*)) subsection ‹Stable Operations for Subgroups› lemma set_mult_consistent [simp]: ✐‹contributor ‹Paulo Emílio de Vilhena›› "N <#>⇘(G ⦇ carrier := H ⦈)⇙ K = N <#>⇘G⇙ K" unfolding set_mult_def (*goal: ‹(⋃h∈N. ⋃k∈K. {h ⊗⇘G⦇carrier := H⦈⇙ k}) = (⋃h∈N. ⋃k∈K. {h ⊗⇘G⇙ k})›*) by simp lemma r_coset_consistent [simp]: ✐‹contributor ‹Paulo Emílio de Vilhena›› "I #>⇘G ⦇ carrier := H ⦈⇙ h = I #>⇘G⇙ h" unfolding r_coset_def (*goal: ‹(⋃ha∈I. {ha ⊗⇘G⦇carrier := H⦈⇙ h}) = (⋃ha∈I. {ha ⊗⇘G⇙ h})›*) by simp lemma l_coset_consistent [simp]: ✐‹contributor ‹Paulo Emílio de Vilhena›› "h <#⇘G ⦇ carrier := H ⦈⇙ I = h <#⇘G⇙ I" unfolding l_coset_def (*goal: ‹(⋃ha::'a∈I::'a set. {(h::'a) ⊗⇘(G::('a, 'b) monoid_scheme)⦇carrier := H::'a set⦈⇙ ha}) = (⋃ha::'a∈I. {h ⊗⇘G⇙ ha})›*) by simp subsection ‹Basic Properties of set multiplication› lemma (in group) setmult_subset_G: assumes "H ⊆ carrier G" "K ⊆ carrier G" shows "H <#> K ⊆ carrier G" using assms (*‹H ⊆ carrier G› ‹K ⊆ carrier G›*) by (auto simp add: set_mult_def (*‹?H <#>⇘?G⇙ ?K = (⋃h∈?H. ⋃k∈?K. {h ⊗⇘?G⇙ k})›*) subsetD (*‹⟦?A ⊆ ?B; ?c ∈ ?A⟧ ⟹ ?c ∈ ?B›*)) lemma (in monoid) set_mult_closed: assumes "H ⊆ carrier G" "K ⊆ carrier G" shows "H <#> K ⊆ carrier G" using assms (*‹H ⊆ carrier G› ‹K ⊆ carrier G›*) by (auto simp add: set_mult_def (*‹(?H::?'a::type set) <#>⇘?G::(?'a, ?'b) monoid_scheme⇙ (?K::?'a::type set) = (⋃h::?'a::type∈?H. ⋃k::?'a::type∈?K. {h ⊗⇘?G⇙ k})›*) subsetD (*‹⟦(?A::?'a::type set) ⊆ (?B::?'a::type set); (?c::?'a::type) ∈ ?A⟧ ⟹ ?c ∈ ?B›*)) lemma (in group) set_mult_assoc: ✐‹contributor ‹Martin Baillon›› assumes "M ⊆ carrier G" "H ⊆ carrier G" "K ⊆ carrier G" shows "(M <#> H) <#> K = M <#> (H <#> K)" proof (standard) (*goals: 1. ‹(M::'a set) <#> (H::'a set) <#> (K::'a set) ⊆ M <#> (H <#> K)› 2. ‹(M::'a set) <#> ((H::'a set) <#> (K::'a set)) ⊆ M <#> H <#> K›*) show "(M <#> H) <#> K ⊆ M <#> (H <#> K)" proof (standard) (*goal: ‹⋀x::'a. x ∈ (M::'a set) <#> (H::'a set) <#> (K::'a set) ⟹ x ∈ M <#> (H <#> K)›*) fix x assume "x ∈ (M <#> H) <#> K" (*‹(x::'a) ∈ (M::'a set) <#> (H::'a set) <#> (K::'a set)›*) then obtain m and h and k where x: "m ∈ M" "h ∈ H" "k ∈ K" "x = (m ⊗ h) ⊗ k" (*goal: ‹(⋀(m::'a) (h::'a) k::'a. ⟦m ∈ (M::'a set); h ∈ (H::'a set); k ∈ (K::'a set); (x::'a) = m ⊗ h ⊗ k⟧ ⟹ thesis::bool) ⟹ thesis›*) unfolding set_mult_def (*goal: ‹(⋀m h k. ⟦m ∈ M; h ∈ H; k ∈ K; x = m ⊗ h ⊗ k⟧ ⟹ thesis) ⟹ thesis›*) by blast hence "x = m ⊗ (h ⊗ k)" using assms (*‹(M::'a set) ⊆ carrier G› ‹H ⊆ carrier G› ‹K ⊆ carrier G›*) m_assoc (*‹⟦(?x::'a) ∈ carrier G; (?y::'a) ∈ carrier G; (?z::'a) ∈ carrier G⟧ ⟹ ?x ⊗ ?y ⊗ ?z = ?x ⊗ (?y ⊗ ?z)›*) by blast thus "x ∈ M <#> (H <#> K)" unfolding set_mult_def (*goal: ‹(x::'a::type) ∈ (⋃h::'a::type∈M::'a::type set. ⋃k::'a::type∈⋃h::'a::type∈H::'a::type set. ⋃k::'a::type∈K::'a::type set. {h ⊗ k}. {h ⊗ k})›*) using x (*‹m ∈ M› ‹h ∈ H› ‹k ∈ K› ‹x = m ⊗ h ⊗ k›*) by blast qed next (*goal: ‹M <#> (H <#> K) ⊆ M <#> H <#> K›*) show "M <#> (H <#> K) ⊆ (M <#> H) <#> K" proof (standard) (*goal: ‹⋀x. x ∈ M <#> (H <#> K) ⟹ x ∈ M <#> H <#> K›*) fix x assume "x ∈ M <#> (H <#> K)" (*‹(x::'a) ∈ (M::'a set) <#> ((H::'a set) <#> (K::'a set))›*) then obtain m and h and k where x: "m ∈ M" "h ∈ H" "k ∈ K" "x = m ⊗ (h ⊗ k)" (*goal: ‹(⋀m h k. ⟦m ∈ M; h ∈ H; k ∈ K; x = m ⊗ (h ⊗ k)⟧ ⟹ thesis) ⟹ thesis›*) unfolding set_mult_def (*goal: ‹(⋀m h k. ⟦m ∈ M; h ∈ H; k ∈ K; x = m ⊗ (h ⊗ k)⟧ ⟹ thesis) ⟹ thesis›*) by blast hence "x = (m ⊗ h) ⊗ k" using assms (*‹(M::'a set) ⊆ carrier G› ‹(H::'a set) ⊆ carrier G› ‹K ⊆ carrier G›*) m_assoc (*‹⟦(?x::'a) ∈ carrier G; (?y::'a) ∈ carrier G; (?z::'a) ∈ carrier G⟧ ⟹ ?x ⊗ ?y ⊗ ?z = ?x ⊗ (?y ⊗ ?z)›*) rev_subsetD (*‹⟦?c ∈ ?A; ?A ⊆ ?B⟧ ⟹ ?c ∈ ?B›*) by metis thus "x ∈ (M <#> H) <#> K" unfolding set_mult_def (*goal: ‹x ∈ (⋃h∈⋃h∈M. ⋃k∈H. {h ⊗ k}. ⋃k∈K. {h ⊗ k})›*) using x (*‹m ∈ M› ‹h ∈ H› ‹k ∈ K› ‹(x::'a) = (m::'a) ⊗ ((h::'a) ⊗ (k::'a))›*) by blast qed qed subsection ‹Basic Properties of Cosets› lemma (in group) coset_mult_assoc: assumes "M ⊆ carrier G" "g ∈ carrier G" "h ∈ carrier G" shows "(M #> g) #> h = M #> (g ⊗ h)" using assms (*‹M ⊆ carrier G› ‹g ∈ carrier G› ‹h ∈ carrier G›*) by (force simp add: r_coset_def (*‹(?H::?'a set) #>⇘?G::(?'a, ?'b) monoid_scheme⇙ (?a::?'a) = (⋃h::?'a∈?H. {h ⊗⇘?G⇙ ?a})›*) m_assoc (*‹⟦(?x::'a) ∈ carrier G; (?y::'a) ∈ carrier G; (?z::'a) ∈ carrier G⟧ ⟹ ?x ⊗ ?y ⊗ ?z = ?x ⊗ (?y ⊗ ?z)›*)) lemma (in group) coset_assoc: assumes "x ∈ carrier G" "y ∈ carrier G" "H ⊆ carrier G" shows "x <# (H #> y) = (x <# H) #> y" using set_mult_assoc[of "{x}" H "{y}"] (*‹⟦{x} ⊆ carrier G; H ⊆ carrier G; {y} ⊆ carrier G⟧ ⟹ {x} <#> H <#> {y} = {x} <#> (H <#> {y})›*) by (simp add: l_coset_eq_set_mult (*‹?x <#⇘?G⇙ ?H = {?x} <#>⇘?G⇙ ?H›*) r_coset_eq_set_mult (*‹?H #>⇘?G⇙ ?x = ?H <#>⇘?G⇙ {?x}›*) assms (*‹x ∈ carrier G› ‹y ∈ carrier G› ‹H ⊆ carrier G›*)) lemma (in group) coset_mult_one [simp]: "M ⊆ carrier G ==> M #> 𝟭 = M" by (force simp add: r_coset_def (*‹?H #>⇘?G⇙ ?a = (⋃h∈?H. {h ⊗⇘?G⇙ ?a})›*)) lemma (in group) coset_mult_inv1: assumes "M #> (x ⊗ (inv y)) = M" and "x ∈ carrier G" "y ∈ carrier G" "M ⊆ carrier G" shows "M #> x = M #> y" using assms (*‹M #> x ⊗ inv y = M› ‹x ∈ carrier G› ‹y ∈ carrier G› ‹M ⊆ carrier G›*) by (metis coset_mult_assoc (*‹⟦?M ⊆ carrier G; ?g ∈ carrier G; ?h ∈ carrier G⟧ ⟹ ?M #> ?g #> ?h = ?M #> ?g ⊗ ?h›*) group.inv_solve_right (*‹⟦Group.group ?G; ?a ∈ carrier ?G; ?b ∈ carrier ?G; ?c ∈ carrier ?G⟧ ⟹ (?a = ?b ⊗⇘?G⇙ inv⇘?G⇙ ?c) = (?b = ?a ⊗⇘?G⇙ ?c)›*) is_group (*‹Group.group G›*) subgroup_def (*‹subgroup ?H ?G ≡ (?H ⊆ carrier ?G ∧ (∀x y. x ∈ ?H ⟶ y ∈ ?H ⟶ x ⊗⇘?G⇙ y ∈ ?H)) ∧ 𝟭⇘?G⇙ ∈ ?H ∧ (∀x. x ∈ ?H ⟶ inv⇘?G⇙ x ∈ ?H)›*) subgroup_self (*‹subgroup (carrier G) G›*)) lemma (in group) coset_mult_inv2: assumes "M #> x = M #> y" and "x ∈ carrier G" "y ∈ carrier G" "M ⊆ carrier G" shows "M #> (x ⊗ (inv y)) = M " using assms (*‹M #> x = M #> y› ‹x ∈ carrier G› ‹y ∈ carrier G› ‹M ⊆ carrier G›*) by (metis group.coset_mult_assoc (*‹⟦Group.group ?G; ?M ⊆ carrier ?G; ?g ∈ carrier ?G; ?h ∈ carrier ?G⟧ ⟹ ?M #>⇘?G⇙ ?g #>⇘?G⇙ ?h = ?M #>⇘?G⇙ ?g ⊗⇘?G⇙ ?h›*) group.coset_mult_one (*‹⟦Group.group ?G; ?M ⊆ carrier ?G⟧ ⟹ ?M #>⇘?G⇙ 𝟭⇘?G⇙ = ?M›*) inv_closed (*‹?x ∈ carrier G ⟹ inv ?x ∈ carrier G›*) is_group (*‹Group.group G›*) r_inv (*‹?x ∈ carrier G ⟹ ?x ⊗ inv ?x = 𝟭›*)) lemma (in group) coset_join1: assumes "H #> x = H" and "x ∈ carrier G" "subgroup H G" shows "x ∈ H" using assms (*‹H #> x = H› ‹x ∈ carrier G› ‹subgroup H G›*) r_coset_def (*‹(?H::?'a set) #>⇘?G::(?'a, ?'b) monoid_scheme⇙ (?a::?'a) = (⋃h::?'a∈?H. {h ⊗⇘?G⇙ ?a})›*) l_one (*‹?x ∈ carrier G ⟹ 𝟭 ⊗ ?x = ?x›*) subgroup.one_closed (*‹subgroup ?H ?G ⟹ 𝟭⇘?G⇙ ∈ ?H›*) sym (*‹(?s::?'a::type) = (?t::?'a::type) ⟹ ?t = ?s›*) by fastforce lemma (in group) solve_equation: assumes "subgroup H G" "x ∈ H" "y ∈ H" shows "∃h ∈ H. y = h ⊗ x" proof (-) (*goal: ‹∃h∈H. y = h ⊗ x›*) have "y = (y ⊗ (inv x)) ⊗ x" using assms (*‹subgroup (H::'a set) G› ‹(x::'a) ∈ (H::'a set)› ‹y ∈ H›*) by (simp add: m_assoc (*‹⟦?x ∈ carrier G; ?y ∈ carrier G; ?z ∈ carrier G⟧ ⟹ ?x ⊗ ?y ⊗ ?z = ?x ⊗ (?y ⊗ ?z)›*) subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*)) moreover have "y ⊗ (inv x) ∈ H" using assms (*‹subgroup H G› ‹x ∈ H› ‹(y::'a) ∈ (H::'a set)›*) by (simp add: subgroup_def (*‹subgroup (?H::?'a set) (?G::(?'a, ?'b) monoid_scheme) ≡ (?H ⊆ carrier ?G ∧ (∀(x::?'a) y::?'a. x ∈ ?H ⟶ y ∈ ?H ⟶ x ⊗⇘?G⇙ y ∈ ?H)) ∧ 𝟭⇘?G⇙ ∈ ?H ∧ (∀x::?'a. x ∈ ?H ⟶ inv⇘?G⇙ x ∈ ?H)›*)) ultimately show "?thesis" (*goal: ‹∃h∈H. y = h ⊗ x›*) by blast qed lemma (in group_hom) inj_on_one_iff: "inj_on h (carrier G) ⟷ (∀x. x ∈ carrier G ⟶ h x = one H ⟶ x = one G)" using G.solve_equation (*‹⟦subgroup ?H G; ?x ∈ ?H; ?y ∈ ?H⟧ ⟹ ∃h∈?H. ?y = h ⊗ ?x›*) G.subgroup_self (*‹subgroup (carrier G) G›*) by (force simp: inj_on_def (*‹inj_on (?f::?'a ⇒ ?'b) (?A::?'a set) = (∀x::?'a∈?A. ∀y::?'a∈?A. ?f x = ?f y ⟶ x = y)›*)) lemma inj_on_one_iff': "⟦h ∈ hom G H; group G; group H⟧ ⟹ inj_on h (carrier G) ⟷ (∀x. x ∈ carrier G ⟶ h x = one H ⟶ x = one G)" using group_hom.inj_on_one_iff (*‹group_hom ?G ?H ?h ⟹ inj_on ?h (carrier ?G) = (∀x. x ∈ carrier ?G ⟶ ?h x = 𝟭⇘?H⇙ ⟶ x = 𝟭⇘?G⇙)›*) group_hom.intro (*‹⟦Group.group (?G::(?'a, ?'b) monoid_scheme); Group.group (?H::(?'c, ?'d) monoid_scheme); group_hom_axioms ?G ?H (?h::?'a ⇒ ?'c)⟧ ⟹ group_hom ?G ?H ?h›*) group_hom_axioms.intro (*‹?h ∈ hom ?G ?H ⟹ group_hom_axioms ?G ?H ?h›*) by blast lemma mon_iff_hom_one: "⟦group G; group H⟧ ⟹ f ∈ mon G H ⟷ f ∈ hom G H ∧ (∀x. x ∈ carrier G ∧ f x = 𝟭⇘H⇙ ⟶ x = 𝟭⇘G⇙)" by (auto simp: mon_def (*‹mon (?G::(?'a, ?'c) monoid_scheme) (?H::(?'b, ?'d) monoid_scheme) = {f::?'a::type ⇒ ?'b::type ∈ hom ?G ?H. inj_on f (carrier ?G)}›*) inj_on_one_iff' (*‹⟦(?h::?'a::type ⇒ ?'b::type) ∈ hom (?G::(?'a, ?'c) monoid_scheme) (?H::(?'b, ?'d) monoid_scheme); Group.group ?G; Group.group ?H⟧ ⟹ inj_on ?h (carrier ?G) = (∀x::?'a::type. x ∈ carrier ?G ⟶ ?h x = 𝟭⇘?H⇙ ⟶ x = 𝟭⇘?G⇙)›*)) lemma (in group_hom) iso_iff: "h ∈ iso G H ⟷ carrier H ⊆ h ` carrier G ∧ (∀x∈carrier G. h x = 𝟭⇘H⇙ ⟶ x = 𝟭)" by (auto simp: iso_def (*‹Group.iso ?G ?H = {h ∈ hom ?G ?H. bij_betw h (carrier ?G) (carrier ?H)}›*) bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*) inj_on_one_iff (*‹inj_on h (carrier G) = (∀x. x ∈ carrier G ⟶ h x = 𝟭⇘H⇙ ⟶ x = 𝟭)›*)) lemma (in group) repr_independence: assumes "y ∈ H #> x" "x ∈ carrier G" "subgroup H G" shows "H #> x = H #> y" using assms (*‹y ∈ H #> x› ‹x ∈ carrier G› ‹subgroup H G›*) by (auto simp add: r_coset_def (*‹?H #>⇘?G⇙ ?a = (⋃h∈?H. {h ⊗⇘?G⇙ ?a})›*) m_assoc [symmetric] (*‹⟦?x ∈ carrier G; ?y ∈ carrier G; ?z ∈ carrier G⟧ ⟹ ?x ⊗ (?y ⊗ ?z) = ?x ⊗ ?y ⊗ ?z›*) subgroup.subset [THEN subsetD] (*‹⟦subgroup ?A ?G1; ?c ∈ ?A⟧ ⟹ ?c ∈ carrier ?G1›*) subgroup.m_closed (*‹⟦subgroup ?H ?G; ?x ∈ ?H; ?y ∈ ?H⟧ ⟹ ?x ⊗⇘?G⇙ ?y ∈ ?H›*) solve_equation (*‹⟦subgroup ?H G; ?x ∈ ?H; ?y ∈ ?H⟧ ⟹ ∃h∈?H. ?y = h ⊗ ?x›*)) lemma (in group) coset_join2: assumes "x ∈ carrier G" "subgroup H G" "x ∈ H" shows "H #> x = H" using assms (*‹x ∈ carrier G› ‹subgroup H G› ‹x ∈ H›*) by (force simp add: subgroup.m_closed (*‹⟦subgroup (?H::?'a::type set) (?G::(?'a, ?'b) monoid_scheme); (?x::?'a::type) ∈ ?H; (?y::?'a::type) ∈ ?H⟧ ⟹ ?x ⊗⇘?G⇙ ?y ∈ ?H›*) r_coset_def (*‹(?H::?'a::type set) #>⇘?G::(?'a, ?'b) monoid_scheme⇙ (?a::?'a::type) = (⋃h::?'a::type∈?H. {h ⊗⇘?G⇙ ?a})›*) solve_equation (*‹⟦subgroup (?H::'a::type set) G; (?x::'a::type) ∈ ?H; (?y::'a::type) ∈ ?H⟧ ⟹ ∃h::'a::type∈?H. ?y = h ⊗ ?x›*)) lemma (in group) coset_join3: assumes "x ∈ carrier G" "subgroup H G" "x ∈ H" shows "x <# H = H" proof (standard) (*goals: 1. ‹(x::'a) <# (H::'a set) ⊆ H› 2. ‹(H::'a set) ⊆ (x::'a) <# H›*) have "⋀h. h ∈ H ⟹ x ⊗ h ∈ H" using assms (*‹x ∈ carrier G› ‹subgroup H G› ‹(x::'a) ∈ (H::'a set)›*) by (simp add: subgroup.m_closed (*‹⟦subgroup ?H ?G; ?x ∈ ?H; ?y ∈ ?H⟧ ⟹ ?x ⊗⇘?G⇙ ?y ∈ ?H›*)) thus "x <# H ⊆ H" unfolding l_coset_def (*goal: ‹(⋃h∈H. {x ⊗ h}) ⊆ H›*) by blast next (*goal: ‹(H::'a::type set) ⊆ (x::'a::type) <# H›*) have "⋀h. h ∈ H ⟹ x ⊗ ((inv x) ⊗ h) = h" by (metis (no_types, lifting) assms (*‹(x::'a) ∈ carrier G› ‹subgroup (H::'a set) G› ‹(x::'a) ∈ (H::'a set)›*) group.inv_closed (*‹⟦Group.group (?G::(?'a, ?'b) monoid_scheme); (?x::?'a) ∈ carrier ?G⟧ ⟹ inv⇘?G⇙ ?x ∈ carrier ?G›*) group.inv_solve_left (*‹⟦Group.group (?G::(?'a, ?'b) monoid_scheme); (?a::?'a) ∈ carrier ?G; (?b::?'a) ∈ carrier ?G; (?c::?'a) ∈ carrier ?G⟧ ⟹ (?a = inv⇘?G⇙ ?b ⊗⇘?G⇙ ?c) = (?c = ?b ⊗⇘?G⇙ ?a)›*) is_group (*‹Group.group G›*) monoid.m_closed (*‹⟦Group.monoid (?G::(?'a, ?'b) monoid_scheme); (?x::?'a) ∈ carrier ?G; (?y::?'a) ∈ carrier ?G⟧ ⟹ ?x ⊗⇘?G⇙ ?y ∈ carrier ?G›*) monoid_axioms (*‹Group.monoid G›*) subgroup.mem_carrier (*‹⟦subgroup (?H::?'a set) (?G::(?'a, ?'b) monoid_scheme); (?x::?'a) ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*)) moreover have "⋀h. h ∈ H ⟹ (inv x) ⊗ h ∈ H" by (simp add: assms (*‹(x::'a::type) ∈ carrier G› ‹subgroup (H::'a::type set) G› ‹(x::'a::type) ∈ (H::'a::type set)›*) subgroup.m_closed (*‹⟦subgroup (?H::?'a::type set) (?G::(?'a, ?'b) monoid_scheme); (?x::?'a::type) ∈ ?H; (?y::?'a::type) ∈ ?H⟧ ⟹ ?x ⊗⇘?G⇙ ?y ∈ ?H›*) subgroup.m_inv_closed (*‹⟦subgroup (?H::?'a::type set) (?G::(?'a, ?'b) monoid_scheme); (?x::?'a::type) ∈ ?H⟧ ⟹ inv⇘?G⇙ ?x ∈ ?H›*)) ultimately show "H ⊆ x <# H" unfolding l_coset_def (*goal: ‹(H::'a::type set) ⊆ (⋃h::'a::type∈H. {(x::'a::type) ⊗ h})›*) by blast qed lemma (in monoid) r_coset_subset_G: "⟦ H ⊆ carrier G; x ∈ carrier G ⟧ ⟹ H #> x ⊆ carrier G" by (auto simp add: r_coset_def (*‹?H #>⇘?G⇙ ?a = (⋃h∈?H. {h ⊗⇘?G⇙ ?a})›*)) lemma (in group) rcosI: "⟦ h ∈ H; H ⊆ carrier G; x ∈ carrier G ⟧ ⟹ h ⊗ x ∈ H #> x" by (auto simp add: r_coset_def (*‹(?H::?'a set) #>⇘?G::(?'a, ?'b) monoid_scheme⇙ (?a::?'a) = (⋃h::?'a∈?H. {h ⊗⇘?G⇙ ?a})›*)) lemma (in group) rcosetsI: "⟦H ⊆ carrier G; x ∈ carrier G⟧ ⟹ H #> x ∈ rcosets H" by (auto simp add: RCOSETS_def (*‹rcosets⇘?G⇙ ?H = (⋃a∈carrier ?G. {?H #>⇘?G⇙ a})›*)) lemma (in group) rcos_self: "⟦ x ∈ carrier G; subgroup H G ⟧ ⟹ x ∈ H #> x" by (metis l_one (*‹?x ∈ carrier G ⟹ 𝟭 ⊗ ?x = ?x›*) rcosI (*‹⟦?h ∈ ?H; ?H ⊆ carrier G; ?x ∈ carrier G⟧ ⟹ ?h ⊗ ?x ∈ ?H #> ?x›*) subgroup_def (*‹subgroup ?H ?G ≡ (?H ⊆ carrier ?G ∧ (∀x y. x ∈ ?H ⟶ y ∈ ?H ⟶ x ⊗⇘?G⇙ y ∈ ?H)) ∧ 𝟭⇘?G⇙ ∈ ?H ∧ (∀x. x ∈ ?H ⟶ inv⇘?G⇙ x ∈ ?H)›*)) text (in group) ‹Opposite of @{thm [source] "repr_independence"}› lemma (in group) repr_independenceD: assumes "subgroup H G" "y ∈ carrier G" and "H #> x = H #> y" shows "y ∈ H #> x" using assms (*‹subgroup H G› ‹y ∈ carrier G› ‹H #> x = H #> y›*) by (simp add: rcos_self (*‹⟦?x ∈ carrier G; subgroup ?H G⟧ ⟹ ?x ∈ ?H #> ?x›*)) text ‹Elements of a right coset are in the carrier› lemma (in subgroup) elemrcos_carrier: assumes "group G" "a ∈ carrier G" and "a' ∈ H #> a" shows "a' ∈ carrier G" by (meson assms (*‹Group.group G› ‹a ∈ carrier G› ‹a' ∈ H #> a›*) group.is_monoid (*‹Group.group ?G ⟹ Group.monoid ?G›*) monoid.r_coset_subset_G (*‹⟦Group.monoid ?G; ?H ⊆ carrier ?G; ?x ∈ carrier ?G⟧ ⟹ ?H #>⇘?G⇙ ?x ⊆ carrier ?G›*) subset (*‹H ⊆ carrier G›*) subsetCE (*‹⟦?A ⊆ ?B; ?c ∉ ?A ⟹ ?P; ?c ∈ ?B ⟹ ?P⟧ ⟹ ?P›*)) lemma (in subgroup) rcos_const: assumes "group G" "h ∈ H" shows "H #> h = H" using group.coset_join2[OF assms ( 1 ), of h H] (*‹⟦h ∈ carrier G; subgroup H G; h ∈ H⟧ ⟹ H #> h = H›*) by (simp add: assms( (*‹h ∈ H›*) 2) subgroup_axioms (*‹subgroup H G›*)) lemma (in subgroup) rcos_module_imp: assumes "group G" "x ∈ carrier G" and "x' ∈ H #> x" shows "(x' ⊗ inv x) ∈ H" proof (-) (*goal: ‹x' ⊗ inv x ∈ H›*) obtain h where h: "h ∈ H" "x' = h ⊗ x" (*goal: ‹(⋀h. ⟦h ∈ H; x' = h ⊗ x⟧ ⟹ thesis) ⟹ thesis›*) using assms(3) (*‹x' ∈ H #> x›*) unfolding r_coset_def (*goal: ‹(⋀h. ⟦h ∈ H; x' = h ⊗ x⟧ ⟹ thesis) ⟹ thesis›*) by blast hence "x' ⊗ inv x = h" by (metis assms (*‹Group.group G› ‹x ∈ carrier G› ‹x' ∈ H #> x›*) elemrcos_carrier (*‹⟦Group.group G; ?a ∈ carrier G; ?a' ∈ H #> ?a⟧ ⟹ ?a' ∈ carrier G›*) group.inv_solve_right (*‹⟦Group.group ?G; ?a ∈ carrier ?G; ?b ∈ carrier ?G; ?c ∈ carrier ?G⟧ ⟹ (?a = ?b ⊗⇘?G⇙ inv⇘?G⇙ ?c) = (?b = ?a ⊗⇘?G⇙ ?c)›*) mem_carrier (*‹?x ∈ H ⟹ ?x ∈ carrier G›*)) thus "?thesis" (*goal: ‹x' ⊗ inv x ∈ H›*) using h (*‹h ∈ H› ‹(x'::'a) = (h::'a) ⊗ (x::'a)›*) by blast qed lemma (in subgroup) rcos_module_rev: assumes "group G" "x ∈ carrier G" "x' ∈ carrier G" and "(x' ⊗ inv x) ∈ H" shows "x' ∈ H #> x" proof (-) (*goal: ‹x' ∈ H #> x›*) obtain h where h: "h ∈ H" "x' ⊗ inv x = h" (*goal: ‹(⋀h. ⟦h ∈ H; x' ⊗ inv x = h⟧ ⟹ thesis) ⟹ thesis›*) using assms(4) (*‹(x'::'a) ⊗ inv (x::'a) ∈ (H::'a set)›*) unfolding r_coset_def (*goal: ‹(⋀h. ⟦h ∈ H; x' ⊗ inv x = h⟧ ⟹ thesis) ⟹ thesis›*) by blast hence "x' = h ⊗ x" by (metis assms (*‹Group.group G› ‹x ∈ carrier G› ‹x' ∈ carrier G› ‹x' ⊗ inv x ∈ H›*) group.inv_solve_right (*‹⟦Group.group ?G; ?a ∈ carrier ?G; ?b ∈ carrier ?G; ?c ∈ carrier ?G⟧ ⟹ (?a = ?b ⊗⇘?G⇙ inv⇘?G⇙ ?c) = (?b = ?a ⊗⇘?G⇙ ?c)›*) mem_carrier (*‹?x ∈ H ⟹ ?x ∈ carrier G›*)) thus "?thesis" (*goal: ‹x' ∈ H #> x›*) using h (*‹(h::'a) ∈ (H::'a set)› ‹x' ⊗ inv x = h›*) unfolding r_coset_def (*goal: ‹x' ∈ (⋃h∈H. {h ⊗ x})›*) by blast qed text ‹Module property of right cosets› lemma (in subgroup) rcos_module: assumes "group G" "x ∈ carrier G" "x' ∈ carrier G" shows "(x' ∈ H #> x) = (x' ⊗ inv x ∈ H)" using rcos_module_rev (*‹⟦Group.group G; (?x::'a) ∈ carrier G; (?x'::'a) ∈ carrier G; ?x' ⊗ inv ?x ∈ (H::'a set)⟧ ⟹ ?x' ∈ H #> ?x›*) rcos_module_imp (*‹⟦Group.group G; ?x ∈ carrier G; ?x' ∈ H #> ?x⟧ ⟹ ?x' ⊗ inv ?x ∈ H›*) assms (*‹Group.group G› ‹x ∈ carrier G› ‹x' ∈ carrier G›*) by blast text ‹Right cosets are subsets of the carrier.› lemma (in subgroup) rcosets_carrier: assumes "group G" "X ∈ rcosets H" shows "X ⊆ carrier G" using assms (*‹Group.group G› ‹X ∈ rcosets H›*) elemrcos_carrier (*‹⟦Group.group G; ?a ∈ carrier G; ?a' ∈ H #> ?a⟧ ⟹ ?a' ∈ carrier G›*) singletonD (*‹?b ∈ {?a} ⟹ ?b = ?a›*) subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*) unfolding RCOSETS_def (*goal: ‹X ⊆ carrier G›*) by force text ‹Multiplication of general subsets› lemma (in comm_group) mult_subgroups: assumes HG: "subgroup H G" and KG: "subgroup K G" shows "subgroup (H <#> K) G" proof (rule subgroup.intro (*‹⟦?H ⊆ carrier ?G; ⋀x y. ⟦x ∈ ?H; y ∈ ?H⟧ ⟹ x ⊗⇘?G⇙ y ∈ ?H; 𝟭⇘?G⇙ ∈ ?H; ⋀x. x ∈ ?H ⟹ inv⇘?G⇙ x ∈ ?H⟧ ⟹ subgroup ?H ?G›*)) (*goals: 1. ‹(H::'a set) <#> (K::'a set) ⊆ carrier G› 2. ‹⋀(x::'a) y::'a. ⟦x ∈ (H::'a set) <#> (K::'a set); y ∈ H <#> K⟧ ⟹ x ⊗ y ∈ H <#> K› 3. ‹𝟭 ∈ (H::'a set) <#> (K::'a set)› 4. ‹⋀x::'a. x ∈ (H::'a set) <#> (K::'a set) ⟹ inv x ∈ H <#> K›*) show "H <#> K ⊆ carrier G" by (simp add: setmult_subset_G (*‹⟦?H ⊆ carrier G; ?K ⊆ carrier G⟧ ⟹ ?H <#> ?K ⊆ carrier G›*) assms (*‹subgroup H G› ‹subgroup K G›*) subgroup.subset (*‹subgroup ?H ?G ⟹ ?H ⊆ carrier ?G›*)) next (*goals: 1. ‹⋀(x::'a) y::'a. ⟦x ∈ (H::'a set) <#> (K::'a set); y ∈ H <#> K⟧ ⟹ x ⊗ y ∈ H <#> K› 2. ‹𝟭 ∈ (H::'a set) <#> (K::'a set)› 3. ‹⋀x::'a. x ∈ (H::'a set) <#> (K::'a set) ⟹ inv x ∈ H <#> K›*) have "𝟭 ⊗ 𝟭 ∈ H <#> K" unfolding set_mult_def (*goal: ‹𝟭 ⊗ 𝟭 ∈ (⋃h∈H. ⋃k∈K. {h ⊗ k})›*) using assms (*‹subgroup H G› ‹subgroup K G›*) subgroup.one_closed (*‹subgroup ?H ?G ⟹ 𝟭⇘?G⇙ ∈ ?H›*) by blast thus "𝟭 ∈ H <#> K" by simp next (*goals: 1. ‹⋀x y. ⟦x ∈ H <#> K; y ∈ H <#> K⟧ ⟹ x ⊗ y ∈ H <#> K› 2. ‹⋀x. x ∈ H <#> K ⟹ inv x ∈ H <#> K›*) show "⋀x. x ∈ H <#> K ⟹ inv x ∈ H <#> K" proof (-) (*goal: ‹⋀x. x ∈ H <#> K ⟹ inv x ∈ H <#> K›*) fix x assume "x ∈ H <#> K" (*‹(x::'a) ∈ (H::'a set) <#> (K::'a set)›*) then obtain h and k where hk: "h ∈ H" "k ∈ K" "x = h ⊗ k" (*goal: ‹(⋀h k. ⟦h ∈ H; k ∈ K; x = h ⊗ k⟧ ⟹ thesis) ⟹ thesis›*) unfolding set_mult_def (*goal: ‹(⋀(h::'a::type) k::'a::type. ⟦h ∈ (H::'a::type set); k ∈ (K::'a::type set); (x::'a::type) = h ⊗ k⟧ ⟹ thesis::bool) ⟹ thesis›*) by blast hence "inv x = (inv k) ⊗ (inv h)" by (meson inv_mult_group (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ inv (?x ⊗ ?y) = inv ?y ⊗ inv ?x›*) assms (*‹subgroup H G› ‹subgroup K G›*) subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*)) hence "inv x = (inv h) ⊗ (inv k)" by (metis hk (*‹h ∈ H› ‹k ∈ K› ‹x = h ⊗ k›*) inv_mult (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ inv (?x ⊗ ?y) = inv ?x ⊗ inv ?y›*) assms (*‹subgroup H G› ‹subgroup K G›*) subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*)) thus "inv x ∈ H <#> K" unfolding set_mult_def (*goal: ‹inv x ∈ (⋃h∈H. ⋃k∈K. {h ⊗ k})›*) using hk (*‹h ∈ H› ‹k ∈ K› ‹x = h ⊗ k›*) assms (*‹subgroup (H::'a::type set) G› ‹subgroup (K::'a set) G›*) by (metis (no_types, lifting) UN_iff (*‹((?b::?'a) ∈ ⋃ ((?B::?'b ⇒ ?'a set) ` (?A::?'b set))) = (∃x::?'b∈?A. ?b ∈ ?B x)›*) singletonI (*‹(?a::?'a) ∈ {?a}›*) subgroup_def (*‹subgroup (?H::?'a set) (?G::(?'a, ?'b) monoid_scheme) ≡ (?H ⊆ carrier ?G ∧ (∀(x::?'a) y::?'a. x ∈ ?H ⟶ y ∈ ?H ⟶ x ⊗⇘?G⇙ y ∈ ?H)) ∧ 𝟭⇘?G⇙ ∈ ?H ∧ (∀x::?'a. x ∈ ?H ⟶ inv⇘?G⇙ x ∈ ?H)›*)) qed next (*goal: ‹⋀x y. ⟦x ∈ H <#> K; y ∈ H <#> K⟧ ⟹ x ⊗ y ∈ H <#> K›*) show "⋀x y. x ∈ H <#> K ⟹ y ∈ H <#> K ⟹ x ⊗ y ∈ H <#> K" proof (-) (*goal: ‹⋀x y. ⟦x ∈ H <#> K; y ∈ H <#> K⟧ ⟹ x ⊗ y ∈ H <#> K›*) fix x and y assume "x ∈ H <#> K" "y ∈ H <#> K" (*‹(x::'a) ∈ (H::'a set) <#> (K::'a set)› ‹(y::'a) ∈ (H::'a set) <#> (K::'a set)›*) then obtain h1 and k1 and h2 and k2 where h1k1: "h1 ∈ H" "k1 ∈ K" "x = h1 ⊗ k1" and h2k2: "h2 ∈ H" "k2 ∈ K" "y = h2 ⊗ k2" (*goal: ‹(⋀h1 k1 h2 k2. ⟦h1 ∈ H; k1 ∈ K; x = h1 ⊗ k1; h2 ∈ H; k2 ∈ K; y = h2 ⊗ k2⟧ ⟹ thesis) ⟹ thesis›*) unfolding set_mult_def (*goal: ‹(⋀(h1::'a) (k1::'a) (h2::'a) k2::'a. ⟦h1 ∈ (H::'a set); k1 ∈ (K::'a set); (x::'a) = h1 ⊗ k1; h2 ∈ H; k2 ∈ K; (y::'a) = h2 ⊗ k2⟧ ⟹ thesis::bool) ⟹ thesis›*) by blast with KG (*‹subgroup K G›*) HG (*‹subgroup (H::'a set) G›*) have carr: "k1 ∈ carrier G" "h1 ∈ carrier G" "k2 ∈ carrier G" "h2 ∈ carrier G" apply - (*goals: 1. ‹⟦subgroup K G; subgroup H G; h1 ∈ H; k1 ∈ K; x = h1 ⊗ k1; h2 ∈ H; k2 ∈ K; y = h2 ⊗ k2⟧ ⟹ k1 ∈ carrier G› 2. ‹⟦subgroup K G; subgroup H G; h1 ∈ H; k1 ∈ K; x = h1 ⊗ k1; h2 ∈ H; k2 ∈ K; y = h2 ⊗ k2⟧ ⟹ h1 ∈ carrier G› 3. ‹⟦subgroup K G; subgroup H G; h1 ∈ H; k1 ∈ K; x = h1 ⊗ k1; h2 ∈ H; k2 ∈ K; y = h2 ⊗ k2⟧ ⟹ k2 ∈ carrier G› 4. ‹⟦subgroup K G; subgroup H G; h1 ∈ H; k1 ∈ K; x = h1 ⊗ k1; h2 ∈ H; k2 ∈ K; y = h2 ⊗ k2⟧ ⟹ h2 ∈ carrier G› discuss goal 1*) apply (meson subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*)) (*discuss goal 2*) apply (meson subgroup.mem_carrier (*‹⟦subgroup (?H::?'a set) (?G::(?'a, ?'b) monoid_scheme); (?x::?'a) ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*)) (*discuss goal 3*) apply (meson subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*)) (*discuss goal 4*) apply (meson subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*)) (*proven 4 subgoals*) . have "x ⊗ y = (h1 ⊗ k1) ⊗ (h2 ⊗ k2)" using h1k1 (*‹h1 ∈ H› ‹(k1::'a::type) ∈ (K::'a::type set)› ‹x = h1 ⊗ k1›*) h2k2 (*‹h2 ∈ H› ‹(k2::'a) ∈ (K::'a set)› ‹y = h2 ⊗ k2›*) by simp also (*calculation: ‹x ⊗ y = h1 ⊗ k1 ⊗ (h2 ⊗ k2)›*) have " ... = h1 ⊗ (k1 ⊗ h2) ⊗ k2" by (simp add: carr (*‹k1 ∈ carrier G› ‹h1 ∈ carrier G› ‹k2 ∈ carrier G› ‹h2 ∈ carrier G›*) comm_groupE( (*‹⟦comm_group ?G; ?x ∈ carrier ?G; ?y ∈ carrier ?G; ?z ∈ carrier ?G⟧ ⟹ ?x ⊗⇘?G⇙ ?y ⊗⇘?G⇙ ?z = ?x ⊗⇘?G⇙ (?y ⊗⇘?G⇙ ?z)›*) 3) comm_group_axioms (*‹comm_group G›*)) also (*calculation: ‹x ⊗ y = h1 ⊗ (k1 ⊗ h2) ⊗ k2›*) have " ... = h1 ⊗ (h2 ⊗ k1) ⊗ k2" by (simp add: carr (*‹k1 ∈ carrier G› ‹h1 ∈ carrier G› ‹k2 ∈ carrier G› ‹h2 ∈ carrier G›*) m_comm (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ ?x ⊗ ?y = ?y ⊗ ?x›*)) finally (*calculation: ‹x ⊗ y = h1 ⊗ (h2 ⊗ k1) ⊗ k2›*) have "x ⊗ y = (h1 ⊗ h2) ⊗ (k1 ⊗ k2)" by (simp add: carr (*‹k1 ∈ carrier G› ‹h1 ∈ carrier G› ‹k2 ∈ carrier G› ‹h2 ∈ carrier G›*) comm_groupE( (*‹⟦comm_group ?G; ?x ∈ carrier ?G; ?y ∈ carrier ?G; ?z ∈ carrier ?G⟧ ⟹ ?x ⊗⇘?G⇙ ?y ⊗⇘?G⇙ ?z = ?x ⊗⇘?G⇙ (?y ⊗⇘?G⇙ ?z)›*) 3) comm_group_axioms (*‹comm_group G›*)) thus "x ⊗ y ∈ H <#> K" unfolding set_mult_def (*goal: ‹x ⊗ y ∈ (⋃h∈H. ⋃k∈K. {h ⊗ k})›*) using subgroup.m_closed[OF assms ( 1 ) h1k1 ( 1 ) h2k2 ( 1 )] (*‹h1 ⊗ h2 ∈ H›*) subgroup.m_closed[OF assms ( 2 ) h1k1 ( 2 ) h2k2 ( 2 )] (*‹(k1::'a::type) ⊗ (k2::'a::type) ∈ (K::'a::type set)›*) by blast qed qed lemma (in subgroup) lcos_module_rev: assumes "group G" "x ∈ carrier G" "x' ∈ carrier G" and "(inv x ⊗ x') ∈ H" shows "x' ∈ x <# H" proof (-) (*goal: ‹(x'::'a) ∈ (x::'a) <# (H::'a set)›*) obtain h where h: "h ∈ H" "inv x ⊗ x' = h" (*goal: ‹(⋀h. ⟦h ∈ H; inv x ⊗ x' = h⟧ ⟹ thesis) ⟹ thesis›*) using assms(4) (*‹inv (x::'a::type) ⊗ (x'::'a::type) ∈ (H::'a::type set)›*) unfolding l_coset_def (*goal: ‹(⋀h. ⟦h ∈ H; inv x ⊗ x' = h⟧ ⟹ thesis) ⟹ thesis›*) by blast hence "x' = x ⊗ h" by (metis assms (*‹Group.group G› ‹(x::'a) ∈ carrier G› ‹(x'::'a) ∈ carrier G› ‹inv (x::'a) ⊗ (x'::'a) ∈ (H::'a set)›*) group.inv_solve_left (*‹⟦Group.group (?G::(?'a, ?'b) monoid_scheme); (?a::?'a) ∈ carrier ?G; (?b::?'a) ∈ carrier ?G; (?c::?'a) ∈ carrier ?G⟧ ⟹ (?a = inv⇘?G⇙ ?b ⊗⇘?G⇙ ?c) = (?c = ?b ⊗⇘?G⇙ ?a)›*) mem_carrier (*‹(?x::'a) ∈ (H::'a set) ⟹ ?x ∈ carrier G›*)) thus "?thesis" (*goal: ‹x' ∈ x <# H›*) using h (*‹h ∈ H› ‹inv x ⊗ x' = h›*) unfolding l_coset_def (*goal: ‹x' ∈ (⋃h∈H. {x ⊗ h})›*) by blast qed subsection ‹Normal subgroups› lemma normal_imp_subgroup: "H ⊲ G ⟹ subgroup H G" by (rule normal.axioms( (*‹?H ⊲ ?G ⟹ subgroup ?H ?G›*) 1)) lemma (in group) normalI: "subgroup H G ⟹ (∀x ∈ carrier G. H #> x = x <# H) ⟹ H ⊲ G" by (simp add: normal_def (*‹?H ⊲ ?G ≡ subgroup ?H ?G ∧ Group.group ?G ∧ normal_axioms ?H ?G›*) normal_axioms_def (*‹normal_axioms ?H ?G ≡ ∀x∈carrier ?G. ?H #>⇘?G⇙ x = x <#⇘?G⇙ ?H›*) is_group (*‹Group.group G›*)) lemma (in normal) inv_op_closed1: assumes "x ∈ carrier G" and "h ∈ H" shows "(inv x) ⊗ h ⊗ x ∈ H" proof (-) (*goal: ‹inv x ⊗ h ⊗ x ∈ H›*) have "h ⊗ x ∈ x <# H" using assms (*‹x ∈ carrier G› ‹h ∈ H›*) coset_eq (*‹∀x∈carrier G. H #> x = x <# H›*) assms(1) (*‹x ∈ carrier G›*) unfolding r_coset_def (*goal: ‹h ⊗ x ∈ x <# H›*) by blast then obtain h' where "h' ∈ H" "h ⊗ x = x ⊗ h'" (*goal: ‹(⋀h'. ⟦h' ∈ H; h ⊗ x = x ⊗ h'⟧ ⟹ thesis) ⟹ thesis›*) unfolding l_coset_def (*goal: ‹(⋀h'. ⟦h' ∈ H; h ⊗ x = x ⊗ h'⟧ ⟹ thesis) ⟹ thesis›*) by blast thus "?thesis" (*goal: ‹inv x ⊗ h ⊗ x ∈ H›*) by (metis assms (*‹x ∈ carrier G› ‹h ∈ H›*) inv_closed (*‹?x ∈ carrier G ⟹ inv ?x ∈ carrier G›*) l_inv (*‹?x ∈ carrier G ⟹ inv ?x ⊗ ?x = 𝟭›*) l_one (*‹?x ∈ carrier G ⟹ 𝟭 ⊗ ?x = ?x›*) m_assoc (*‹⟦?x ∈ carrier G; ?y ∈ carrier G; ?z ∈ carrier G⟧ ⟹ ?x ⊗ ?y ⊗ ?z = ?x ⊗ (?y ⊗ ?z)›*) mem_carrier (*‹?x ∈ H ⟹ ?x ∈ carrier G›*)) qed lemma (in normal) inv_op_closed2: assumes "x ∈ carrier G" and "h ∈ H" shows "x ⊗ h ⊗ (inv x) ∈ H" using assms (*‹x ∈ carrier G› ‹h ∈ H›*) inv_op_closed1 (*‹⟦?x ∈ carrier G; ?h ∈ H⟧ ⟹ inv ?x ⊗ ?h ⊗ ?x ∈ H›*) by (metis inv_closed (*‹?x ∈ carrier G ⟹ inv ?x ∈ carrier G›*) inv_inv (*‹?x ∈ carrier G ⟹ inv (inv ?x) = ?x›*)) lemma (in comm_group) normal_iff_subgroup: "N ⊲ G ⟷ subgroup N G" proof (standard) (*goals: 1. ‹N ⊲ G ⟹ subgroup N G› 2. ‹subgroup N G ⟹ N ⊲ G›*) assume "subgroup N G" (*‹subgroup (N::'a set) G›*) then show "N ⊲ G" apply unfold_locales (*goals: 1. ‹subgroup N G ⟹ N ⊆ carrier G› 2. ‹⋀x y. ⟦subgroup N G; x ∈ N; y ∈ N⟧ ⟹ x ⊗ y ∈ N› 3. ‹subgroup N G ⟹ 𝟭 ∈ N› 4. ‹⋀x. ⟦subgroup N G; x ∈ N⟧ ⟹ inv x ∈ N› 5. ‹subgroup N G ⟹ ∀x∈carrier G. N #> x = x <# N› discuss goal 1*) apply ((auto simp: subgroupE (*‹subgroup ?H G ⟹ ?H ⊆ carrier G› ‹subgroup ?H G ⟹ ?H ≠ {}› ‹⟦subgroup ?H G; ?a ∈ ?H⟧ ⟹ inv ?a ∈ ?H› ‹⟦subgroup ?H G; ?a ∈ ?H; ?b ∈ ?H⟧ ⟹ ?a ⊗ ?b ∈ ?H›*) subgroup.one_closed (*‹subgroup ?H ?G ⟹ 𝟭⇘?G⇙ ∈ ?H›*) l_coset_def (*‹?a <#⇘?G⇙ ?H = (⋃h∈?H. {?a ⊗⇘?G⇙ h})›*) r_coset_def (*‹?H #>⇘?G⇙ ?a = (⋃h∈?H. {h ⊗⇘?G⇙ ?a})›*) m_comm (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ ?x ⊗ ?y = ?y ⊗ ?x›*) subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*))[1]) (*discuss goal 2*) apply ((auto simp: subgroupE (*‹subgroup ?H G ⟹ ?H ⊆ carrier G› ‹subgroup ?H G ⟹ ?H ≠ {}› ‹⟦subgroup ?H G; ?a ∈ ?H⟧ ⟹ inv ?a ∈ ?H› ‹⟦subgroup ?H G; ?a ∈ ?H; ?b ∈ ?H⟧ ⟹ ?a ⊗ ?b ∈ ?H›*) subgroup.one_closed (*‹subgroup ?H ?G ⟹ 𝟭⇘?G⇙ ∈ ?H›*) l_coset_def (*‹?a <#⇘?G⇙ ?H = (⋃h∈?H. {?a ⊗⇘?G⇙ h})›*) r_coset_def (*‹?H #>⇘?G⇙ ?a = (⋃h∈?H. {h ⊗⇘?G⇙ ?a})›*) m_comm (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ ?x ⊗ ?y = ?y ⊗ ?x›*) subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*))[1]) (*discuss goal 3*) apply ((auto simp: subgroupE (*‹subgroup ?H G ⟹ ?H ⊆ carrier G› ‹subgroup ?H G ⟹ ?H ≠ {}› ‹⟦subgroup ?H G; ?a ∈ ?H⟧ ⟹ inv ?a ∈ ?H› ‹⟦subgroup ?H G; ?a ∈ ?H; ?b ∈ ?H⟧ ⟹ ?a ⊗ ?b ∈ ?H›*) subgroup.one_closed (*‹subgroup ?H ?G ⟹ 𝟭⇘?G⇙ ∈ ?H›*) l_coset_def (*‹?a <#⇘?G⇙ ?H = (⋃h∈?H. {?a ⊗⇘?G⇙ h})›*) r_coset_def (*‹?H #>⇘?G⇙ ?a = (⋃h∈?H. {h ⊗⇘?G⇙ ?a})›*) m_comm (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ ?x ⊗ ?y = ?y ⊗ ?x›*) subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*))[1]) (*discuss goal 4*) apply ((auto simp: subgroupE (*‹subgroup ?H G ⟹ ?H ⊆ carrier G› ‹subgroup ?H G ⟹ ?H ≠ {}› ‹⟦subgroup ?H G; ?a ∈ ?H⟧ ⟹ inv ?a ∈ ?H› ‹⟦subgroup ?H G; ?a ∈ ?H; ?b ∈ ?H⟧ ⟹ ?a ⊗ ?b ∈ ?H›*) subgroup.one_closed (*‹subgroup ?H ?G ⟹ 𝟭⇘?G⇙ ∈ ?H›*) l_coset_def (*‹?a <#⇘?G⇙ ?H = (⋃h∈?H. {?a ⊗⇘?G⇙ h})›*) r_coset_def (*‹?H #>⇘?G⇙ ?a = (⋃h∈?H. {h ⊗⇘?G⇙ ?a})›*) m_comm (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ ?x ⊗ ?y = ?y ⊗ ?x›*) subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*))[1]) (*discuss goal 5*) apply ((auto simp: subgroupE (*‹subgroup ?H G ⟹ ?H ⊆ carrier G› ‹subgroup ?H G ⟹ ?H ≠ {}› ‹⟦subgroup ?H G; ?a ∈ ?H⟧ ⟹ inv ?a ∈ ?H› ‹⟦subgroup ?H G; ?a ∈ ?H; ?b ∈ ?H⟧ ⟹ ?a ⊗ ?b ∈ ?H›*) subgroup.one_closed (*‹subgroup ?H ?G ⟹ 𝟭⇘?G⇙ ∈ ?H›*) l_coset_def (*‹?a <#⇘?G⇙ ?H = (⋃h∈?H. {?a ⊗⇘?G⇙ h})›*) r_coset_def (*‹?H #>⇘?G⇙ ?a = (⋃h∈?H. {h ⊗⇘?G⇙ ?a})›*) m_comm (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ ?x ⊗ ?y = ?y ⊗ ?x›*) subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*))[1]) (*proven 5 subgoals*) . qed (simp add: normal_imp_subgroup (*‹?H ⊲ ?G ⟹ subgroup ?H ?G›*)) (*solved the remaining goal: ‹N ⊲ G ⟹ subgroup N G›*) text‹Alternative characterization of normal subgroups› lemma (in group) normal_inv_iff: "(N ⊲ G) = (subgroup N G ∧ (∀x ∈ carrier G. ∀h ∈ N. x ⊗ h ⊗ (inv x) ∈ N))" (is "_ = ?rhs") proof (standard) (*goals: 1. ‹N ⊲ G ⟹ subgroup N G ∧ (∀x∈carrier G. ∀h∈N. x ⊗ h ⊗ inv x ∈ N)› 2. ‹subgroup N G ∧ (∀x∈carrier G. ∀h∈N. x ⊗ h ⊗ inv x ∈ N) ⟹ N ⊲ G›*) assume N: "N ⊲ G" (*‹(N::'a set) ⊲ G›*) show "?rhs" by (blast intro: N (*‹N ⊲ G›*) normal.inv_op_closed2 (*‹⟦?H ⊲ ?G; ?x ∈ carrier ?G; ?h ∈ ?H⟧ ⟹ ?x ⊗⇘?G⇙ ?h ⊗⇘?G⇙ inv⇘?G⇙ ?x ∈ ?H›*) normal_imp_subgroup (*‹?H ⊲ ?G ⟹ subgroup ?H ?G›*)) next (*goal: ‹subgroup N G ∧ (∀x∈carrier G. ∀h∈N. x ⊗ h ⊗ inv x ∈ N) ⟹ N ⊲ G›*) assume "?rhs" (*‹subgroup (N::'a set) G ∧ (∀x::'a∈carrier G. ∀h::'a∈N. x ⊗ h ⊗ inv x ∈ N)›*) hence sg: "subgroup N G" and closed: "⋀x. x∈carrier G ⟹ ∀h∈N. x ⊗ h ⊗ inv x ∈ N" apply - (*goals: 1. ‹subgroup N G ∧ (∀x∈carrier G. ∀h∈N. x ⊗ h ⊗ inv x ∈ N) ⟹ subgroup N G› 2. ‹⋀x. ⟦x ∈ carrier G; subgroup N G ∧ (∀x∈carrier G. ∀h∈N. x ⊗ h ⊗ inv x ∈ N)⟧ ⟹ ∀h∈N. x ⊗ h ⊗ inv x ∈ N› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . hence sb: "N ⊆ carrier G" by (simp add: subgroup.subset (*‹subgroup ?H ?G ⟹ ?H ⊆ carrier ?G›*)) show "N ⊲ G" apply (intro normalI [OF sg] (*‹∀x∈carrier G. N #> x = x <# N ⟹ N ⊲ G›*)) (*goal: ‹(N::'a set) ⊲ G›*) apply (simp add: l_coset_def (*‹?a <#⇘?G⇙ ?H = (⋃h∈?H. {?a ⊗⇘?G⇙ h})›*) r_coset_def (*‹?H #>⇘?G⇙ ?a = (⋃h∈?H. {h ⊗⇘?G⇙ ?a})›*)) (*goal: ‹∀x∈carrier G. N #> x = x <# N›*) proof (clarify) (*goal: ‹⋀x. x ∈ carrier G ⟹ (⋃h∈N. {h ⊗ x}) = (⋃h∈N. {x ⊗ h})›*) fix x assume x: "x ∈ carrier G" (*‹(x::'a) ∈ carrier G›*) show "(⋃h∈N. {h ⊗ x}) = (⋃h∈N. {x ⊗ h})" proof (standard) (*goals: 1. ‹(⋃h∈N. {h ⊗ x}) ⊆ (⋃h∈N. {x ⊗ h})› 2. ‹(⋃h∈N. {x ⊗ h}) ⊆ (⋃h∈N. {h ⊗ x})›*) show "(⋃h∈N. {h ⊗ x}) ⊆ (⋃h∈N. {x ⊗ h})" proof (clarify) (*goal: ‹⋀(xa::'a) h::'a. h ∈ (N::'a set) ⟹ h ⊗ (x::'a) ∈ (⋃h::'a∈N. {x ⊗ h})›*) fix n assume n: "n ∈ N" (*‹(n::'a) ∈ (N::'a set)›*) show "n ⊗ x ∈ (⋃h∈N. {x ⊗ h})" proof (standard) (*goals: 1. ‹(?a::'a) ∈ (N::'a set)› 2. ‹(n::'a) ⊗ (x::'a) ∈ {x ⊗ (?a::'a)}›*) from closed[of "inv x"] (*‹inv (x::'a) ∈ carrier G ⟹ ∀h::'a∈N::'a set. inv x ⊗ h ⊗ inv (inv x) ∈ N›*) show "inv x ⊗ n ⊗ x ∈ N" by (simp add: x (*‹(x::'a::type) ∈ carrier G›*) n (*‹(n::'a::type) ∈ (N::'a::type set)›*)) show "n ⊗ x ∈ {x ⊗ (inv x ⊗ n ⊗ x)}" by (simp add: x (*‹x ∈ carrier G›*) n (*‹n ∈ N›*) m_assoc [symmetric] (*‹⟦?x ∈ carrier G; ?y ∈ carrier G; ?z ∈ carrier G⟧ ⟹ ?x ⊗ (?y ⊗ ?z) = ?x ⊗ ?y ⊗ ?z›*) sb [THEN subsetD] (*‹?c ∈ N ⟹ ?c ∈ carrier G›*)) qed qed next (*goal: ‹(⋃h∈N. {x ⊗ h}) ⊆ (⋃h∈N. {h ⊗ x})›*) show "(⋃h∈N. {x ⊗ h}) ⊆ (⋃h∈N. {h ⊗ x})" proof (clarify) (*goal: ‹⋀(xa::'a) h::'a. h ∈ (N::'a set) ⟹ (x::'a) ⊗ h ∈ (⋃h::'a∈N. {h ⊗ x})›*) fix n assume n: "n ∈ N" (*‹(n::'a) ∈ (N::'a set)›*) show "x ⊗ n ∈ (⋃h∈N. {h ⊗ x})" proof (standard) (*goals: 1. ‹?a ∈ N› 2. ‹x ⊗ n ∈ {?a ⊗ x}›*) show "x ⊗ n ⊗ inv x ∈ N" by (simp add: x (*‹x ∈ carrier G›*) n (*‹n ∈ N›*) closed (*‹?x ∈ carrier G ⟹ ∀h∈N. ?x ⊗ h ⊗ inv ?x ∈ N›*)) show "x ⊗ n ∈ {x ⊗ n ⊗ inv x ⊗ x}" by (simp add: x (*‹x ∈ carrier G›*) n (*‹n ∈ N›*) m_assoc (*‹⟦?x ∈ carrier G; ?y ∈ carrier G; ?z ∈ carrier G⟧ ⟹ ?x ⊗ ?y ⊗ ?z = ?x ⊗ (?y ⊗ ?z)›*) sb [THEN subsetD] (*‹?c ∈ N ⟹ ?c ∈ carrier G›*)) qed qed qed qed qed corollary (in group) normal_invI: assumes "subgroup N G" and "⋀x h. ⟦ x ∈ carrier G; h ∈ N ⟧ ⟹ x ⊗ h ⊗ inv x ∈ N" shows "N ⊲ G" using assms (*‹subgroup (N::'a set) G› ‹⟦?x ∈ carrier G; ?h ∈ N⟧ ⟹ ?x ⊗ ?h ⊗ inv ?x ∈ N›*) normal_inv_iff (*‹(?N::'a set) ⊲ G = (subgroup ?N G ∧ (∀x::'a∈carrier G. ∀h::'a∈?N. x ⊗ h ⊗ inv x ∈ ?N))›*) by blast corollary (in group) normal_invE: assumes "N ⊲ G" shows "subgroup N G" and "⋀x h. ⟦ x ∈ carrier G; h ∈ N ⟧ ⟹ x ⊗ h ⊗ inv x ∈ N" using assms (*‹N ⊲ G›*) normal_inv_iff (*‹?N ⊲ G = (subgroup ?N G ∧ (∀x∈carrier G. ∀h∈?N. x ⊗ h ⊗ inv x ∈ ?N))›*) (*goals: 1. ‹subgroup N G› 2. ‹⋀x h. ⟦x ∈ carrier G; h ∈ N⟧ ⟹ x ⊗ h ⊗ inv x ∈ N› discuss goal 1*) apply blast (*discuss goal 2*) apply (simp add: assms (*‹(N::'a set) ⊲ G›*) normal.inv_op_closed2 (*‹⟦(?H::?'a set) ⊲ (?G::(?'a, ?'b) monoid_scheme); (?x::?'a) ∈ carrier ?G; (?h::?'a) ∈ ?H⟧ ⟹ ?x ⊗⇘?G⇙ ?h ⊗⇘?G⇙ inv⇘?G⇙ ?x ∈ ?H›*)) (*proven 2 subgoals*) . lemma (in group) one_is_normal: "{𝟭} ⊲ G" using normal_invI (*‹⟦subgroup ?N G; ⋀x h. ⟦x ∈ carrier G; h ∈ ?N⟧ ⟹ x ⊗ h ⊗ inv x ∈ ?N⟧ ⟹ ?N ⊲ G›*) triv_subgroup (*‹subgroup {𝟭} G›*) by force text ‹The intersection of two normal subgroups is, again, a normal subgroup.› lemma (in group) normal_subgroup_intersect: assumes "M ⊲ G" and "N ⊲ G" shows "M ∩ N ⊲ G" using assms (*‹(M::'a set) ⊲ G› ‹N ⊲ G›*) normal_inv_iff (*‹?N ⊲ G = (subgroup ?N G ∧ (∀x∈carrier G. ∀h∈?N. x ⊗ h ⊗ inv x ∈ ?N))›*) subgroups_Inter_pair (*‹⟦subgroup ?I G; subgroup ?J G⟧ ⟹ subgroup (?I ∩ ?J) G›*) by force text ‹Being a normal subgroup is preserved by surjective homomorphisms.› lemma (in normal) surj_hom_normal_subgroup: assumes φ: "group_hom G F φ" assumes φsurj: "φ ` (carrier G) = carrier F" shows "(φ ` H) ⊲ F" proof (rule group.normalI (*‹⟦Group.group ?G; subgroup ?H ?G; ∀x∈carrier ?G. ?H #>⇘?G⇙ x = x <#⇘?G⇙ ?H⟧ ⟹ ?H ⊲ ?G›*)) (*goals: 1. ‹Group.group (F::('c, 'd) monoid_scheme)› 2. ‹subgroup ((φ::'a ⇒ 'c) ` (H::'a set)) (F::('c, 'd) monoid_scheme)› 3. ‹∀x::'c∈carrier (F::('c, 'd) monoid_scheme). (φ::'a ⇒ 'c) ` (H::'a set) #>⇘F⇙ x = x <#⇘F⇙ φ ` H›*) show "group F" using "φ" (*‹group_hom G F φ›*) group_hom.axioms(2) (*‹group_hom ?G ?H ?h ⟹ Group.group ?H›*) by blast next (*goals: 1. ‹subgroup (φ ` H) F› 2. ‹∀x∈carrier F. φ ` H #>⇘F⇙ x = x <#⇘F⇙ φ ` H›*) show "subgroup (φ ` H) F" using "φ" (*‹group_hom G F φ›*) group_hom.subgroup_img_is_subgroup (*‹⟦group_hom (?G::(?'a, ?'b) monoid_scheme) (?H::(?'c, ?'d) monoid_scheme) (?h::?'a ⇒ ?'c); subgroup (?I::?'a set) ?G⟧ ⟹ subgroup (?h ` ?I) ?H›*) subgroup_axioms (*‹subgroup H G›*) by blast next (*goal: ‹∀x∈carrier F. φ ` H #>⇘F⇙ x = x <#⇘F⇙ φ ` H›*) show "∀x∈carrier F. φ ` H #>⇘F⇙ x = x <#⇘F⇙ φ ` H" proof (standard) (*goal: ‹⋀x. x ∈ carrier F ⟹ φ ` H #>⇘F⇙ x = x <#⇘F⇙ φ ` H›*) fix f assume f: "f ∈ carrier F" (*‹(f::'c) ∈ carrier (F::('c, 'd) monoid_scheme)›*) with "φsurj" (*‹(φ::'a ⇒ 'c) ` carrier G = carrier (F::('c, 'd) monoid_scheme)›*) obtain g where g: "g ∈ carrier G" "f = φ g" (*goal: ‹(⋀g. ⟦g ∈ carrier G; f = φ g⟧ ⟹ thesis) ⟹ thesis›*) by auto hence "φ ` H #>⇘F⇙ f = φ ` H #>⇘F⇙ φ g" by simp also (*calculation: ‹φ ` H #>⇘F⇙ f = φ ` H #>⇘F⇙ φ g›*) have "... = (λx. (φ x) ⊗⇘F⇙ (φ g)) ` H" unfolding r_coset_def image_def (*goal: ‹⋃ {y. ∃x∈{y. ∃x∈H. y = φ x}. y = {x ⊗⇘F⇙ φ g}} = {y. ∃x∈H. y = φ x ⊗⇘F⇙ φ g}›*) by auto also (*calculation: ‹φ ` H #>⇘F⇙ f = (λx. φ x ⊗⇘F⇙ φ g) ` H›*) have "... = (λx. φ (x ⊗ g)) ` H" using subset (*‹H ⊆ carrier G›*) g (*‹g ∈ carrier G› ‹(f::'c::type) = (φ::'a::type ⇒ 'c::type) (g::'a::type)›*) "φ" (*‹group_hom G F φ›*) group_hom.hom_mult (*‹⟦group_hom ?G ?H ?h; ?x ∈ carrier ?G; ?y ∈ carrier ?G⟧ ⟹ ?h (?x ⊗⇘?G⇙ ?y) = ?h ?x ⊗⇘?H⇙ ?h ?y›*) unfolding image_def (*goal: ‹{y. ∃x∈H. y = φ x ⊗⇘F⇙ φ g} = {y. ∃x∈H. y = φ (x ⊗ g)}›*) by fastforce also (*calculation: ‹φ ` H #>⇘F⇙ f = (λx. φ (x ⊗ g)) ` H›*) have "... = φ ` (H #> g)" using "φ" (*‹group_hom G F φ›*) unfolding r_coset_def (*goal: ‹(λx. φ (x ⊗ g)) ` H = φ ` (⋃h∈H. {h ⊗ g})›*) by auto also (*calculation: ‹φ ` H #>⇘F⇙ f = φ ` (H #> g)›*) have "... = φ ` (g <# H)" by (metis coset_eq (*‹∀x∈carrier G. H #> x = x <# H›*) g( (*‹g ∈ carrier G›*) 1)) also (*calculation: ‹(φ::'a ⇒ 'c) ` (H::'a set) #>⇘F::('c, 'd) monoid_scheme⇙ (f::'c) = φ ` ((g::'a) <# H)›*) have "... = (λx. φ (g ⊗ x)) ` H" using "φ" (*‹group_hom G (F::('c, 'd) monoid_scheme) (φ::'a ⇒ 'c)›*) unfolding l_coset_def (*goal: ‹φ ` (⋃h∈H. {g ⊗ h}) = (λx. φ (g ⊗ x)) ` H›*) by auto also (*calculation: ‹φ ` H #>⇘F⇙ f = (λx. φ (g ⊗ x)) ` H›*) have "... = (λx. (φ g) ⊗⇘F⇙ (φ x)) ` H" using subset (*‹H ⊆ carrier G›*) g (*‹g ∈ carrier G› ‹(f::'c) = (φ::'a ⇒ 'c) (g::'a)›*) "φ" (*‹group_hom G (F::('c, 'd) monoid_scheme) (φ::'a ⇒ 'c)›*) group_hom.hom_mult (*‹⟦group_hom ?G ?H ?h; ?x ∈ carrier ?G; ?y ∈ carrier ?G⟧ ⟹ ?h (?x ⊗⇘?G⇙ ?y) = ?h ?x ⊗⇘?H⇙ ?h ?y›*) by fastforce also (*calculation: ‹(φ::'a ⇒ 'c) ` (H::'a set) #>⇘F::('c, 'd) monoid_scheme⇙ (f::'c) = (λx::'a. φ (g::'a) ⊗⇘F⇙ φ x) ` H›*) have "... = φ g <#⇘F⇙ φ ` H" unfolding l_coset_def image_def (*goal: ‹{y. ∃x∈H. y = φ g ⊗⇘F⇙ φ x} = ⋃ {y. ∃x∈{y. ∃x∈H. y = φ x}. y = {φ g ⊗⇘F⇙ x}}›*) by auto also (*calculation: ‹φ ` H #>⇘F⇙ f = φ g <#⇘F⇙ φ ` H›*) have "... = f <#⇘F⇙ φ ` H" using g (*‹(g::'a::type) ∈ carrier G› ‹f = φ g›*) by simp finally (*calculation: ‹(φ::'a::type ⇒ 'c::type) ` (H::'a::type set) #>⇘F::('c, 'd) monoid_scheme⇙ (f::'c::type) = f <#⇘F⇙ φ ` H›*) show "φ ` H #>⇘F⇙ f = f <#⇘F⇙ φ ` H" . qed qed text ‹Being a normal subgroup is preserved by group isomorphisms.› lemma iso_normal_subgroup: assumes φ: "φ ∈ iso G F" "group G" "group F" "H ⊲ G" shows "(φ ` H) ⊲ F" by (meson assms (*‹φ ∈ Group.iso G F› ‹Group.group G› ‹Group.group F› ‹H ⊲ G›*) Group.iso_iff (*‹(?h ∈ Group.iso ?G ?H) = (?h ∈ hom ?G ?H ∧ ?h ` carrier ?G = carrier ?H ∧ inj_on ?h (carrier ?G))›*) group_hom_axioms_def (*‹group_hom_axioms ?G ?H ?h ≡ ?h ∈ hom ?G ?H›*) group_hom_def (*‹group_hom ?G ?H ?h ≡ Group.group ?G ∧ Group.group ?H ∧ group_hom_axioms ?G ?H ?h›*) normal.surj_hom_normal_subgroup (*‹⟦?H ⊲ ?G; group_hom ?G ?F ?φ; ?φ ` carrier ?G = carrier ?F⟧ ⟹ ?φ ` ?H ⊲ ?F›*)) text ‹The set product of two normal subgroups is a normal subgroup.› lemma (in group) setmult_lcos_assoc: "⟦H ⊆ carrier G; K ⊆ carrier G; x ∈ carrier G⟧ ⟹ (x <# H) <#> K = x <# (H <#> K)" by (force simp add: l_coset_def (*‹?a <#⇘?G⇙ ?H = (⋃h∈?H. {?a ⊗⇘?G⇙ h})›*) set_mult_def (*‹?H <#>⇘?G⇙ ?K = (⋃h∈?H. ⋃k∈?K. {h ⊗⇘?G⇙ k})›*) m_assoc (*‹⟦?x ∈ carrier G; ?y ∈ carrier G; ?z ∈ carrier G⟧ ⟹ ?x ⊗ ?y ⊗ ?z = ?x ⊗ (?y ⊗ ?z)›*)) subsection‹More Properties of Left Cosets› lemma (in group) l_repr_independence: assumes "y ∈ x <# H" "x ∈ carrier G" and HG: "subgroup H G" shows "x <# H = y <# H" proof (-) (*goal: ‹x <# H = y <# H›*) obtain h' where h': "h' ∈ H" "y = x ⊗ h'" (*goal: ‹(⋀h'. ⟦h' ∈ H; y = x ⊗ h'⟧ ⟹ thesis) ⟹ thesis›*) using assms(1) (*‹y ∈ x <# H›*) unfolding l_coset_def (*goal: ‹(⋀h'. ⟦h' ∈ H; y = x ⊗ h'⟧ ⟹ thesis) ⟹ thesis›*) by blast hence "x ⊗ h = y ⊗ ((inv h') ⊗ h)" if "h ∈ H" for h proof (-) (*goal: ‹⟦h' ∈ H; y = x ⊗ h'⟧ ⟹ x ⊗ h = y ⊗ (inv h' ⊗ h)›*) have "h' ∈ carrier G" by (meson HG (*‹subgroup H G›*) h'( (*‹h' ∈ H›*) 1) subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*)) moreover have "h ∈ carrier G" by (meson HG (*‹subgroup H G›*) subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*) that (*‹h ∈ H›*)) ultimately show "?thesis" (*goal: ‹x ⊗ h = y ⊗ (inv h' ⊗ h)›*) by (metis assms( (*‹x ∈ carrier G›*) 2) h'( (*‹y = x ⊗ h'›*) 2) inv_closed (*‹?x ∈ carrier G ⟹ inv ?x ∈ carrier G›*) inv_solve_right (*‹⟦?a ∈ carrier G; ?b ∈ carrier G; ?c ∈ carrier G⟧ ⟹ (?a = ?b ⊗ inv ?c) = (?b = ?a ⊗ ?c)›*) m_assoc (*‹⟦?x ∈ carrier G; ?y ∈ carrier G; ?z ∈ carrier G⟧ ⟹ ?x ⊗ ?y ⊗ ?z = ?x ⊗ (?y ⊗ ?z)›*) m_closed (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ ?x ⊗ ?y ∈ carrier G›*)) qed hence "⋀xh. xh ∈ x <# H ⟹ xh ∈ y <# H" unfolding l_coset_def (*goal: ‹⋀xh. xh ∈ (⋃h∈H. {x ⊗ h}) ⟹ xh ∈ (⋃h∈H. {y ⊗ h})›*) by (metis (no_types, lifting) UN_iff (*‹(?b ∈ ⋃ (?B ` ?A)) = (∃x∈?A. ?b ∈ ?B x)›*) HG (*‹subgroup H G›*) h'( (*‹h' ∈ H›*) 1) subgroup_def (*‹subgroup ?H ?G ≡ (?H ⊆ carrier ?G ∧ (∀x y. x ∈ ?H ⟶ y ∈ ?H ⟶ x ⊗⇘?G⇙ y ∈ ?H)) ∧ 𝟭⇘?G⇙ ∈ ?H ∧ (∀x. x ∈ ?H ⟶ inv⇘?G⇙ x ∈ ?H)›*)) moreover have "⋀h. h ∈ H ⟹ y ⊗ h = x ⊗ (h' ⊗ h)" using h' (*‹(h'::'a) ∈ (H::'a set)› ‹y = x ⊗ h'›*) by (meson assms( (*‹x ∈ carrier G›*) 2) HG (*‹subgroup H G›*) m_assoc (*‹⟦?x ∈ carrier G; ?y ∈ carrier G; ?z ∈ carrier G⟧ ⟹ ?x ⊗ ?y ⊗ ?z = ?x ⊗ (?y ⊗ ?z)›*) subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*)) hence "⋀yh. yh ∈ y <# H ⟹ yh ∈ x <# H" unfolding l_coset_def (*goal: ‹⋀yh::'a. yh ∈ (⋃h::'a∈H::'a set. {(y::'a) ⊗ h}) ⟹ yh ∈ (⋃h::'a∈H. {(x::'a) ⊗ h})›*) using subgroup.m_closed[OF HG h' ( 1 )] (*‹?y ∈ H ⟹ h' ⊗ ?y ∈ H›*) by blast ultimately show "?thesis" (*goal: ‹x <# H = y <# H›*) by blast qed lemma (in group) lcos_m_assoc: "⟦ M ⊆ carrier G; g ∈ carrier G; h ∈ carrier G ⟧ ⟹ g <# (h <# M) = (g ⊗ h) <# M" by (force simp add: l_coset_def (*‹?a <#⇘?G⇙ ?H = (⋃h∈?H. {?a ⊗⇘?G⇙ h})›*) m_assoc (*‹⟦?x ∈ carrier G; ?y ∈ carrier G; ?z ∈ carrier G⟧ ⟹ ?x ⊗ ?y ⊗ ?z = ?x ⊗ (?y ⊗ ?z)›*)) lemma (in group) lcos_mult_one: "M ⊆ carrier G ⟹ 𝟭 <# M = M" by (force simp add: l_coset_def (*‹?a <#⇘?G⇙ ?H = (⋃h∈?H. {?a ⊗⇘?G⇙ h})›*)) lemma (in group) l_coset_subset_G: "⟦ H ⊆ carrier G; x ∈ carrier G ⟧ ⟹ x <# H ⊆ carrier G" by (auto simp add: l_coset_def (*‹?a <#⇘?G⇙ ?H = (⋃h∈?H. {?a ⊗⇘?G⇙ h})›*) subsetD (*‹⟦?A ⊆ ?B; ?c ∈ ?A⟧ ⟹ ?c ∈ ?B›*)) lemma (in group) l_coset_carrier: "⟦ y ∈ x <# H; x ∈ carrier G; subgroup H G ⟧ ⟹ y ∈ carrier G" by (auto simp add: l_coset_def (*‹(?a::?'a::type) <#⇘?G::(?'a, ?'b) monoid_scheme⇙ (?H::?'a::type set) = (⋃h::?'a::type∈?H. {?a ⊗⇘?G⇙ h})›*) m_assoc (*‹⟦(?x::'a::type) ∈ carrier G; (?y::'a::type) ∈ carrier G; (?z::'a::type) ∈ carrier G⟧ ⟹ ?x ⊗ ?y ⊗ ?z = ?x ⊗ (?y ⊗ ?z)›*) subgroup.subset [THEN subsetD] (*‹⟦subgroup (?A::?'a::type set) (?G1::(?'a, ?'b1) monoid_scheme); (?c::?'a::type) ∈ ?A⟧ ⟹ ?c ∈ carrier ?G1›*) subgroup.m_closed (*‹⟦subgroup (?H::?'a::type set) (?G::(?'a, ?'b) monoid_scheme); (?x::?'a::type) ∈ ?H; (?y::?'a::type) ∈ ?H⟧ ⟹ ?x ⊗⇘?G⇙ ?y ∈ ?H›*)) lemma (in group) l_coset_swap: assumes "y ∈ x <# H" "x ∈ carrier G" "subgroup H G" shows "x ∈ y <# H" using assms(2) (*‹x ∈ carrier G›*) l_repr_independence[OF assms] (*‹(x::'a::type) <# (H::'a::type set) = (y::'a::type) <# H›*) subgroup.one_closed[OF assms ( 3 )] (*‹𝟭 ∈ H›*) unfolding l_coset_def (*goal: ‹x ∈ (⋃h∈H. {y ⊗ h})›*) by fastforce lemma (in group) subgroup_mult_id: assumes "subgroup H G" shows "H <#> H = H" proof (standard) (*goals: 1. ‹H <#> H ⊆ H› 2. ‹H ⊆ H <#> H›*) show "H <#> H ⊆ H" unfolding set_mult_def (*goal: ‹(⋃h∈H. ⋃k∈H. {h ⊗ k}) ⊆ H›*) using subgroup.m_closed[OF assms] (*‹⟦?x ∈ H; ?y ∈ H⟧ ⟹ ?x ⊗ ?y ∈ H›*) by (simp add: UN_subset_iff (*‹(⋃ ((?A::?'b ⇒ ?'a set) ` (?I::?'b set)) ⊆ (?B::?'a set)) = (∀i::?'b∈?I. ?A i ⊆ ?B)›*)) show "H ⊆ H <#> H" proof (standard) (*goal: ‹⋀x::'a. x ∈ (H::'a set) ⟹ x ∈ H <#> H›*) fix x assume x: "x ∈ H" (*‹(x::'a) ∈ (H::'a set)›*) thus "x ∈ H <#> H" unfolding set_mult_def (*goal: ‹x ∈ (⋃h∈H. ⋃k∈H. {h ⊗ k})›*) using subgroup.m_closed[OF assms subgroup.one_closed [ OF assms ] x] (*‹𝟭 ⊗ x ∈ H›*) subgroup.one_closed[OF assms] (*‹𝟭 ∈ H›*) using assms (*‹subgroup H G›*) subgroup.mem_carrier (*‹⟦subgroup (?H::?'a set) (?G::(?'a, ?'b) monoid_scheme); (?x::?'a) ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*) by force qed qed subsubsection ‹Set of Inverses of an ‹r_coset›.› lemma (in normal) rcos_inv: assumes x: "x ∈ carrier G" shows "set_inv (H #> x) = H #> (inv x)" proof (simp add: r_coset_def (*‹?H #>⇘?G⇙ ?a = (⋃h∈?H. {h ⊗⇘?G⇙ ?a})›*) SET_INV_def (*‹set_inv⇘?G⇙ ?H = (⋃h∈?H. {inv⇘?G⇙ h})›*) x (*‹x ∈ carrier G›*) inv_mult_group (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ inv (?x ⊗ ?y) = inv ?y ⊗ inv ?x›*), safe) (*goals: 1. ‹⋀(xa::'a::type) xaa::'a::type. xaa ∈ (H::'a::type set) ⟹ inv (x::'a::type) ⊗ inv xaa ∈ (⋃h::'a::type∈H. {h ⊗ inv x})› 2. ‹⋀(xa::'a::type) h::'a::type. h ∈ (H::'a::type set) ⟹ h ⊗ inv (x::'a::type) ∈ (⋃xa::'a::type∈H. {inv x ⊗ inv xa})›*) fix h assume h: "h ∈ H" (*‹(h::'a) ∈ (H::'a set)›*) show "inv x ⊗ inv h ∈ (⋃j∈H. {j ⊗ inv x})" proof (standard) (*goals: 1. ‹(?a::'a) ∈ (H::'a set)› 2. ‹inv (x::'a) ⊗ inv (h::'a) ∈ {(?a::'a) ⊗ inv x}›*) show "inv x ⊗ inv h ⊗ x ∈ H" by (simp add: inv_op_closed1 (*‹⟦(?x::'a) ∈ carrier G; (?h::'a) ∈ (H::'a set)⟧ ⟹ inv ?x ⊗ ?h ⊗ ?x ∈ H›*) h (*‹(h::'a) ∈ (H::'a set)›*) x (*‹(x::'a) ∈ carrier G›*)) show "inv x ⊗ inv h ∈ {inv x ⊗ inv h ⊗ x ⊗ inv x}" by (simp add: h (*‹h ∈ H›*) x (*‹x ∈ carrier G›*) m_assoc (*‹⟦?x ∈ carrier G; ?y ∈ carrier G; ?z ∈ carrier G⟧ ⟹ ?x ⊗ ?y ⊗ ?z = ?x ⊗ (?y ⊗ ?z)›*)) qed show "h ⊗ inv x ∈ (⋃j∈H. {inv x ⊗ inv j})" proof (standard) (*goals: 1. ‹?a ∈ H› 2. ‹h ⊗ inv x ∈ {inv x ⊗ inv ?a}›*) show "x ⊗ inv h ⊗ inv x ∈ H" by (simp add: inv_op_closed2 (*‹⟦?x ∈ carrier G; ?h ∈ H⟧ ⟹ ?x ⊗ ?h ⊗ inv ?x ∈ H›*) h (*‹h ∈ H›*) x (*‹x ∈ carrier G›*)) show "h ⊗ inv x ∈ {inv x ⊗ inv (x ⊗ inv h ⊗ inv x)}" by (simp add: h (*‹h ∈ H›*) x (*‹x ∈ carrier G›*) m_assoc [symmetric] (*‹⟦?x ∈ carrier G; ?y ∈ carrier G; ?z ∈ carrier G⟧ ⟹ ?x ⊗ (?y ⊗ ?z) = ?x ⊗ ?y ⊗ ?z›*) inv_mult_group (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ inv (?x ⊗ ?y) = inv ?y ⊗ inv ?x›*)) qed qed subsubsection ‹Theorems for ‹<#>› with ‹#>› or ‹<#›.› lemma (in group) setmult_rcos_assoc: "⟦H ⊆ carrier G; K ⊆ carrier G; x ∈ carrier G⟧ ⟹ H <#> (K #> x) = (H <#> K) #> x" using set_mult_assoc[of H K "{x}"] (*‹⟦H ⊆ carrier G; K ⊆ carrier G; {x} ⊆ carrier G⟧ ⟹ H <#> K <#> {x} = H <#> (K <#> {x})›*) by (simp add: r_coset_eq_set_mult (*‹?H #>⇘?G⇙ ?x = ?H <#>⇘?G⇙ {?x}›*)) lemma (in group) rcos_assoc_lcos: "⟦H ⊆ carrier G; K ⊆ carrier G; x ∈ carrier G⟧ ⟹ (H #> x) <#> K = H <#> (x <# K)" using set_mult_assoc[of H "{x}" K] (*‹⟦H ⊆ carrier G; {x} ⊆ carrier G; K ⊆ carrier G⟧ ⟹ H <#> {x} <#> K = H <#> ({x} <#> K)›*) by (simp add: l_coset_eq_set_mult (*‹?x <#⇘?G⇙ ?H = {?x} <#>⇘?G⇙ ?H›*) r_coset_eq_set_mult (*‹?H #>⇘?G⇙ ?x = ?H <#>⇘?G⇙ {?x}›*)) lemma (in normal) rcos_mult_step1: "⟦x ∈ carrier G; y ∈ carrier G⟧ ⟹ (H #> x) <#> (H #> y) = (H <#> (x <# H)) #> y" by (simp add: setmult_rcos_assoc (*‹⟦?H ⊆ carrier G; ?K ⊆ carrier G; ?x ∈ carrier G⟧ ⟹ ?H <#> (?K #> ?x) = ?H <#> ?K #> ?x›*) r_coset_subset_G (*‹⟦?H ⊆ carrier G; ?x ∈ carrier G⟧ ⟹ ?H #> ?x ⊆ carrier G›*) subset (*‹H ⊆ carrier G›*) l_coset_subset_G (*‹⟦?H ⊆ carrier G; ?x ∈ carrier G⟧ ⟹ ?x <# ?H ⊆ carrier G›*) rcos_assoc_lcos (*‹⟦?H ⊆ carrier G; ?K ⊆ carrier G; ?x ∈ carrier G⟧ ⟹ ?H #> ?x <#> ?K = ?H <#> (?x <# ?K)›*)) lemma (in normal) rcos_mult_step2: "⟦x ∈ carrier G; y ∈ carrier G⟧ ⟹ (H <#> (x <# H)) #> y = (H <#> (H #> x)) #> y" apply (insert coset_eq (*‹∀x∈carrier G. H #> x = x <# H›*)) (*goal: ‹⟦x ∈ carrier G; y ∈ carrier G⟧ ⟹ H <#> (x <# H) #> y = H <#> (H #> x) #> y›*) by (simp add: normal_def (*‹(?H::?'a set) ⊲ (?G::(?'a, ?'b) monoid_scheme) ≡ subgroup ?H ?G ∧ Group.group ?G ∧ normal_axioms ?H ?G›*)) lemma (in normal) rcos_mult_step3: "⟦x ∈ carrier G; y ∈ carrier G⟧ ⟹ (H <#> (H #> x)) #> y = H #> (x ⊗ y)" by (simp add: setmult_rcos_assoc (*‹⟦?H ⊆ carrier G; ?K ⊆ carrier G; ?x ∈ carrier G⟧ ⟹ ?H <#> (?K #> ?x) = ?H <#> ?K #> ?x›*) coset_mult_assoc (*‹⟦?M ⊆ carrier G; ?g ∈ carrier G; ?h ∈ carrier G⟧ ⟹ ?M #> ?g #> ?h = ?M #> ?g ⊗ ?h›*) subgroup_mult_id (*‹subgroup ?H G ⟹ ?H <#> ?H = ?H›*) normal.axioms (*‹?H ⊲ ?G ⟹ subgroup ?H ?G› ‹?H ⊲ ?G ⟹ Group.group ?G› ‹?H ⊲ ?G ⟹ normal_axioms ?H ?G›*) subset (*‹H ⊆ carrier G›*) normal_axioms (*‹H ⊲ G›*)) lemma (in normal) rcos_sum: "⟦x ∈ carrier G; y ∈ carrier G⟧ ⟹ (H #> x) <#> (H #> y) = H #> (x ⊗ y)" by (simp add: rcos_mult_step1 (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ H #> ?x <#> (H #> ?y) = H <#> (?x <# H) #> ?y›*) rcos_mult_step2 (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ H <#> (?x <# H) #> ?y = H <#> (H #> ?x) #> ?y›*) rcos_mult_step3 (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ H <#> (H #> ?x) #> ?y = H #> ?x ⊗ ?y›*)) lemma (in normal) rcosets_mult_eq: "M ∈ rcosets H ⟹ H <#> M = M" ― ‹generalizes ‹subgroup_mult_id›› by (auto simp add: RCOSETS_def (*‹rcosets⇘?G⇙ ?H = (⋃a∈carrier ?G. {?H #>⇘?G⇙ a})›*) subset (*‹H ⊆ carrier G›*) setmult_rcos_assoc (*‹⟦?H ⊆ carrier G; ?K ⊆ carrier G; ?x ∈ carrier G⟧ ⟹ ?H <#> (?K #> ?x) = ?H <#> ?K #> ?x›*) subgroup_mult_id (*‹subgroup ?H G ⟹ ?H <#> ?H = ?H›*) normal.axioms (*‹?H ⊲ ?G ⟹ subgroup ?H ?G› ‹?H ⊲ ?G ⟹ Group.group ?G› ‹?H ⊲ ?G ⟹ normal_axioms ?H ?G›*) normal_axioms (*‹H ⊲ G›*)) subsubsection‹An Equivalence Relation› definition r_congruent :: "[('a,'b)monoid_scheme, 'a set] ⇒ ('a*'a)set" ("rcongı _") where "rcong⇘G⇙ H = {(x,y). x ∈ carrier G ∧ y ∈ carrier G ∧ inv⇘G⇙ x ⊗⇘G⇙ y ∈ H}" lemma (in subgroup) equiv_rcong: assumes "group G" shows "equiv (carrier G) (rcong H)" proof (-) (*goal: ‹equiv (carrier G) rcong H›*) interpret group G by fact show "?thesis" (*goal: ‹equiv (carrier G) rcong H›*) proof (intro equivI (*‹⟦refl_on ?A ?r; sym ?r; trans ?r⟧ ⟹ equiv ?A ?r›*)) (*goals: 1. ‹refl_on (carrier G) rcong H› 2. ‹sym rcong H› 3. ‹trans rcong H›*) have "rcong H ⊆ carrier G × carrier G" by (auto simp add: r_congruent_def (*‹rcong⇘?G::(?'a, ?'b) monoid_scheme⇙ ?H::?'a set = {(x::?'a, y::?'a). x ∈ carrier ?G ∧ y ∈ carrier ?G ∧ inv⇘?G⇙ x ⊗⇘?G⇙ y ∈ ?H}›*)) thus "refl_on (carrier G) (rcong H)" by (auto simp add: r_congruent_def (*‹rcong⇘?G⇙ ?H = {(x, y). x ∈ carrier ?G ∧ y ∈ carrier ?G ∧ inv⇘?G⇙ x ⊗⇘?G⇙ y ∈ ?H}›*) refl_on_def (*‹refl_on ?A ?r = (?r ⊆ ?A × ?A ∧ (∀x∈?A. (x, x) ∈ ?r))›*)) next (*goals: 1. ‹sym rcong H› 2. ‹trans rcong H›*) show "sym (rcong H)" apply (simp add: r_congruent_def (*‹rcong⇘?G⇙ ?H = {(x, y). x ∈ carrier ?G ∧ y ∈ carrier ?G ∧ inv⇘?G⇙ x ⊗⇘?G⇙ y ∈ ?H}›*) sym_def (*‹sym ?r = (∀x y. (x, y) ∈ ?r ⟶ (y, x) ∈ ?r)›*)) (*goal: ‹sym rcong H›*) proof (clarify) (*goal: ‹⋀x y. ⟦x ∈ carrier G; y ∈ carrier G; inv x ⊗ y ∈ H⟧ ⟹ inv y ⊗ x ∈ H›*) fix x and y assume [simp]: "x ∈ carrier G" "y ∈ carrier G" and "inv x ⊗ y ∈ H" (*‹(x::'a) ∈ carrier G› ‹(y::'a) ∈ carrier G› ‹inv (x::'a) ⊗ (y::'a) ∈ (H::'a set)›*) hence "inv (inv x ⊗ y) ∈ H" by simp thus "inv y ⊗ x ∈ H" by (simp add: inv_mult_group (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ inv (?x ⊗ ?y) = inv ?y ⊗ inv ?x›*)) qed next (*goal: ‹trans rcong H›*) show "trans (rcong H)" apply (simp add: r_congruent_def (*‹rcong⇘?G⇙ ?H = {(x, y). x ∈ carrier ?G ∧ y ∈ carrier ?G ∧ inv⇘?G⇙ x ⊗⇘?G⇙ y ∈ ?H}›*) trans_def (*‹trans ?r = (∀x y z. (x, y) ∈ ?r ⟶ (y, z) ∈ ?r ⟶ (x, z) ∈ ?r)›*)) (*goal: ‹trans rcong H::'a set›*) proof (clarify) (*goal: ‹⋀(x::'a) (y::'a) z::'a. ⟦x ∈ carrier G; y ∈ carrier G; inv x ⊗ y ∈ (H::'a set); z ∈ carrier G; inv y ⊗ z ∈ H⟧ ⟹ inv x ⊗ z ∈ H›*) fix x and y and z assume [simp]: "x ∈ carrier G" "y ∈ carrier G" "z ∈ carrier G" and "inv x ⊗ y ∈ H" and "inv y ⊗ z ∈ H" (*‹(x::'a) ∈ carrier G› ‹(y::'a) ∈ carrier G› ‹(z::'a) ∈ carrier G› ‹inv (x::'a) ⊗ (y::'a) ∈ (H::'a set)› ‹inv (y::'a) ⊗ (z::'a) ∈ (H::'a set)›*) hence "(inv x ⊗ y) ⊗ (inv y ⊗ z) ∈ H" by simp hence "inv x ⊗ (y ⊗ inv y) ⊗ z ∈ H" by (simp add: m_assoc (*‹⟦?x ∈ carrier G; ?y ∈ carrier G; ?z ∈ carrier G⟧ ⟹ ?x ⊗ ?y ⊗ ?z = ?x ⊗ (?y ⊗ ?z)›*) del: r_inv (*‹?x ∈ carrier G ⟹ ?x ⊗ inv ?x = 𝟭›*) Units_r_inv (*‹?x ∈ Units G ⟹ ?x ⊗ inv ?x = 𝟭›*)) thus "inv x ⊗ z ∈ H" by simp qed qed qed text‹Equivalence classes of ‹rcong› correspond to left cosets. Was there a mistake in the definitions? I'd have expected them to correspond to right cosets.› (* CB: This is correct, but subtle. We call H #> a the right coset of a relative to H. According to Jacobson, this is what the majority of group theory literature does. He then defines the notion of congruence relation ~ over monoids as equivalence relation with a ~ a' & b ~ b' ⟹ a*b ~ a'*b'. Our notion of right congruence induced by K: rcong K appears only in the context where K is a normal subgroup. Jacobson doesn't name it. But in this context left and right cosets are identical. *) lemma (in subgroup) l_coset_eq_rcong: assumes "group G" assumes a: "a ∈ carrier G" shows "a <# H = (rcong H) `` {a}" proof (-) (*goal: ‹a <# H = rcong H `` {a}›*) interpret group G by fact show "?thesis" (*goal: ‹a <# H = rcong H `` {a}›*) by (force simp add: r_congruent_def (*‹rcong⇘?G⇙ ?H = {(x, y). x ∈ carrier ?G ∧ y ∈ carrier ?G ∧ inv⇘?G⇙ x ⊗⇘?G⇙ y ∈ ?H}›*) l_coset_def (*‹?a <#⇘?G⇙ ?H = (⋃h∈?H. {?a ⊗⇘?G⇙ h})›*) m_assoc [symmetric] (*‹⟦?x ∈ carrier G; ?y ∈ carrier G; ?z ∈ carrier G⟧ ⟹ ?x ⊗ (?y ⊗ ?z) = ?x ⊗ ?y ⊗ ?z›*) a (*‹a ∈ carrier G›*)) qed subsubsection‹Two Distinct Right Cosets are Disjoint› lemma (in group) rcos_equation: assumes "subgroup H G" assumes p: "ha ⊗ a = h ⊗ b" "a ∈ carrier G" "b ∈ carrier G" "h ∈ H" "ha ∈ H" "hb ∈ H" shows "hb ⊗ a ∈ (⋃h∈H. {h ⊗ b})" proof (-) (*goal: ‹(hb::'a) ⊗ (a::'a) ∈ (⋃h::'a∈H::'a set. {h ⊗ (b::'a)})›*) interpret subgroup H G by fact from p (*‹ha ⊗ a = h ⊗ b› ‹a ∈ carrier G› ‹b ∈ carrier G› ‹h ∈ H› ‹ha ∈ H› ‹hb ∈ H›*) show "?thesis" (*goal: ‹hb ⊗ a ∈ (⋃h∈H. {h ⊗ b})›*) apply (rule_tac UN_I [of "hb ⊗ ((inv ha) ⊗ h)"] (*‹⟦(hb::'a::type) ⊗ (inv (ha::'a::type) ⊗ (h::'a::type)) ∈ (?A::'a::type set); (?b::?'b::type) ∈ (?B::'a::type ⇒ ?'b::type set) (hb ⊗ (inv ha ⊗ h))⟧ ⟹ ?b ∈ ⋃ (?B ` ?A)›*)) (*goals: 1. ‹⟦(ha::'a) ⊗ (a::'a) = (h::'a) ⊗ (b::'a); a ∈ carrier G; b ∈ carrier G; h ∈ (H::'a set); ha ∈ H; (hb::'a) ∈ H⟧ ⟹ hb ⊗ (inv ha ⊗ h) ∈ H› 2. ‹⟦(ha::'a) ⊗ (a::'a) = (h::'a) ⊗ (b::'a); a ∈ carrier G; b ∈ carrier G; h ∈ (H::'a set); ha ∈ H; (hb::'a) ∈ H⟧ ⟹ hb ⊗ a ∈ {hb ⊗ (inv ha ⊗ h) ⊗ b}› discuss goal 1*) apply ((auto simp: inv_solve_left (*‹⟦?a ∈ carrier G; ?b ∈ carrier G; ?c ∈ carrier G⟧ ⟹ (?a = inv ?b ⊗ ?c) = (?c = ?b ⊗ ?a)›*) m_assoc (*‹⟦?x ∈ carrier G; ?y ∈ carrier G; ?z ∈ carrier G⟧ ⟹ ?x ⊗ ?y ⊗ ?z = ?x ⊗ (?y ⊗ ?z)›*))[1]) (*discuss goal 2*) apply ((auto simp: inv_solve_left (*‹⟦?a ∈ carrier G; ?b ∈ carrier G; ?c ∈ carrier G⟧ ⟹ (?a = inv ?b ⊗ ?c) = (?c = ?b ⊗ ?a)›*) m_assoc (*‹⟦?x ∈ carrier G; ?y ∈ carrier G; ?z ∈ carrier G⟧ ⟹ ?x ⊗ ?y ⊗ ?z = ?x ⊗ (?y ⊗ ?z)›*))[1]) (*proven 2 subgoals*) . qed lemma (in group) rcos_disjoint: assumes "subgroup H G" shows "pairwise disjnt (rcosets H)" proof (-) (*goal: ‹pairwise disjnt (rcosets H)›*) interpret subgroup H G by fact show "?thesis" (*goal: ‹pairwise disjnt (rcosets H)›*) unfolding RCOSETS_def r_coset_def pairwise_def disjnt_def (*goal: ‹∀x∈⋃a∈carrier G. {⋃h∈H. {h ⊗ a}}. ∀y∈⋃a∈carrier G. {⋃h∈H. {h ⊗ a}}. x ≠ y ⟶ x ∩ y = {}›*) by (blast intro: rcos_equation (*‹⟦subgroup ?H G; ?ha ⊗ ?a = ?h ⊗ ?b; ?a ∈ carrier G; ?b ∈ carrier G; ?h ∈ ?H; ?ha ∈ ?H; ?hb ∈ ?H⟧ ⟹ ?hb ⊗ ?a ∈ (⋃h∈?H. {h ⊗ ?b})›*) assms (*‹subgroup H G›*) sym (*‹?s = ?t ⟹ ?t = ?s›*)) qed subsection ‹Further lemmas for ‹r_congruent›› text ‹The relation is a congruence› lemma (in normal) congruent_rcong: shows "congruent2 (rcong H) (rcong H) (λa b. a ⊗ b <# H)" proof (intro congruent2I[of "carrier G" _ "carrier G" _] (*‹⟦equiv (carrier G) (?r1.0::('a::type × 'a::type) set); equiv (carrier G) (?r2.0::('a::type × 'a::type) set); ⋀(y::'a::type) (z::'a::type) w::'a::type. ⟦w ∈ carrier G; (y, z) ∈ ?r1.0⟧ ⟹ (?f::'a::type ⇒ 'a::type ⇒ ?'c::type) y w = ?f z w; ⋀(y::'a::type) (z::'a::type) w::'a::type. ⟦w ∈ carrier G; (y, z) ∈ ?r2.0⟧ ⟹ ?f w y = ?f w z⟧ ⟹ congruent2 ?r1.0 ?r2.0 ?f›*) equiv_rcong (*‹Group.group G ⟹ equiv (carrier G) rcong H::'a::type set›*) is_group (*‹Group.group G›*)) (*goals: 1. ‹⋀y z w. ⟦w ∈ carrier G; (y, z) ∈ rcong H⟧ ⟹ y ⊗ w <# H = z ⊗ w <# H› 2. ‹⋀y z w. ⟦w ∈ carrier G; (y, z) ∈ rcong H⟧ ⟹ w ⊗ y <# H = w ⊗ z <# H›*) fix a and b and c assume abrcong: "(a, b) ∈ rcong H" and ccarr: "c ∈ carrier G" (*‹(a::'a, b::'a) ∈ rcong H::'a set› ‹(c::'a) ∈ carrier G›*) from abrcong (*‹(a, b) ∈ rcong H›*) have acarr: "a ∈ carrier G" and bcarr: "b ∈ carrier G" and abH: "inv a ⊗ b ∈ H" unfolding r_congruent_def (*goals: 1. ‹a ∈ carrier G› 2. ‹b ∈ carrier G› 3. ‹inv a ⊗ b ∈ H›*) apply - (*goals: 1. ‹(a, b) ∈ {(x, y). x ∈ carrier G ∧ y ∈ carrier G ∧ inv x ⊗ y ∈ H} ⟹ a ∈ carrier G› 2. ‹(a, b) ∈ {(x, y). x ∈ carrier G ∧ y ∈ carrier G ∧ inv x ⊗ y ∈ H} ⟹ b ∈ carrier G› 3. ‹(a, b) ∈ {(x, y). x ∈ carrier G ∧ y ∈ carrier G ∧ inv x ⊗ y ∈ H} ⟹ inv a ⊗ b ∈ H› discuss goal 1*) apply fast (*discuss goal 2*) apply fast (*discuss goal 3*) apply fast (*proven 3 subgoals*) . note carr = acarr (*‹a ∈ carrier G›*) bcarr (*‹b ∈ carrier G›*) ccarr (*‹c ∈ carrier G›*) from ccarr (*‹c ∈ carrier G›*) abH (*‹inv a ⊗ b ∈ H›*) have "inv c ⊗ (inv a ⊗ b) ⊗ c ∈ H" by (rule inv_op_closed1 (*‹⟦(?x::'a) ∈ carrier G; (?h::'a) ∈ (H::'a set)⟧ ⟹ inv ?x ⊗ ?h ⊗ ?x ∈ H›*)) moreover from carr (*‹a ∈ carrier G› ‹b ∈ carrier G› ‹c ∈ carrier G›*) inv_closed (*‹?x ∈ carrier G ⟹ inv ?x ∈ carrier G›*) have "inv c ⊗ (inv a ⊗ b) ⊗ c = (inv c ⊗ inv a) ⊗ (b ⊗ c)" by (force cong: m_assoc (*‹⟦(?x::'a) ∈ carrier G; (?y::'a) ∈ carrier G; (?z::'a) ∈ carrier G⟧ ⟹ ?x ⊗ ?y ⊗ ?z = ?x ⊗ (?y ⊗ ?z)›*)) moreover from carr (*‹a ∈ carrier G› ‹b ∈ carrier G› ‹c ∈ carrier G›*) inv_closed (*‹(?x::'a::type) ∈ carrier G ⟹ inv ?x ∈ carrier G›*) have "… = (inv (a ⊗ c)) ⊗ (b ⊗ c)" by (simp add: inv_mult_group (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ inv (?x ⊗ ?y) = inv ?y ⊗ inv ?x›*)) ultimately have "(inv (a ⊗ c)) ⊗ (b ⊗ c) ∈ H" by simp from carr (*‹a ∈ carrier G› ‹b ∈ carrier G› ‹c ∈ carrier G›*) this (*‹inv (a ⊗ c) ⊗ (b ⊗ c) ∈ H›*) have "(b ⊗ c) ∈ (a ⊗ c) <# H" by (simp add: lcos_module_rev[OF is_group] (*‹⟦?x ∈ carrier G; ?x' ∈ carrier G; inv ?x ⊗ ?x' ∈ H⟧ ⟹ ?x' ∈ ?x <# H›*)) from carr (*‹a ∈ carrier G› ‹b ∈ carrier G› ‹c ∈ carrier G›*) this (*‹b ⊗ c ∈ a ⊗ c <# H›*) is_subgroup (*‹subgroup H G›*) show "(a ⊗ c) <# H = (b ⊗ c) <# H" apply (intro l_repr_independence (*‹⟦?y ∈ ?x <# ?H; ?x ∈ carrier G; subgroup ?H G⟧ ⟹ ?x <# ?H = ?y <# ?H›*)) (*goals: 1. ‹⟦a ∈ carrier G; b ∈ carrier G; c ∈ carrier G; b ⊗ c ∈ a ⊗ c <# H; subgroup H G⟧ ⟹ b ⊗ c ∈ a ⊗ c <# H› 2. ‹⟦a ∈ carrier G; b ∈ carrier G; c ∈ carrier G; b ⊗ c ∈ a ⊗ c <# H; subgroup H G⟧ ⟹ a ⊗ c ∈ carrier G› 3. ‹⟦a ∈ carrier G; b ∈ carrier G; c ∈ carrier G; b ⊗ c ∈ a ⊗ c <# H; subgroup H G⟧ ⟹ subgroup H G› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) . next (*goal: ‹⋀(y::'a) (z::'a) w::'a. ⟦w ∈ carrier G; (y, z) ∈ rcong H::'a set⟧ ⟹ w ⊗ y <# H = w ⊗ z <# H›*) fix a and b and c assume abrcong: "(a, b) ∈ rcong H" and ccarr: "c ∈ carrier G" (*‹(a::'a, b::'a) ∈ rcong H::'a set› ‹(c::'a) ∈ carrier G›*) from ccarr (*‹c ∈ carrier G›*) have "c ∈ Units G" by simp hence cinvc_one: "inv c ⊗ c = 𝟭" by (rule Units_l_inv (*‹(?x::'a) ∈ Units G ⟹ inv ?x ⊗ ?x = 𝟭›*)) from abrcong (*‹(a, b) ∈ rcong H›*) have acarr: "a ∈ carrier G" and bcarr: "b ∈ carrier G" and abH: "inv a ⊗ b ∈ H" apply - (*goals: 1. ‹(a, b) ∈ rcong H ⟹ a ∈ carrier G› 2. ‹(a, b) ∈ rcong H ⟹ b ∈ carrier G› 3. ‹(a, b) ∈ rcong H ⟹ inv a ⊗ b ∈ H› discuss goal 1*) apply ((unfold r_congruent_def (*‹rcong⇘?G::(?'a, ?'b) monoid_scheme⇙ ?H::?'a set = {(x::?'a, y::?'a). x ∈ carrier ?G ∧ y ∈ carrier ?G ∧ inv⇘?G⇙ x ⊗⇘?G⇙ y ∈ ?H}›*))[1]) (*top goal: ‹(a, b) ∈ rcong H ⟹ a ∈ carrier G› and 2 goals remain*) apply fast (*discuss goal 2*) apply ((unfold r_congruent_def (*‹rcong⇘?G⇙ ?H = {(x, y). x ∈ carrier ?G ∧ y ∈ carrier ?G ∧ inv⇘?G⇙ x ⊗⇘?G⇙ y ∈ ?H}›*))[1]) (*top goal: ‹(a::'a, b::'a) ∈ rcong H::'a set ⟹ b ∈ carrier G› and 1 goal remains*) apply fast (*discuss goal 3*) apply ((unfold r_congruent_def (*‹rcong⇘?G⇙ ?H = {(x, y). x ∈ carrier ?G ∧ y ∈ carrier ?G ∧ inv⇘?G⇙ x ⊗⇘?G⇙ y ∈ ?H}›*))[1]) (*goal: ‹(a, b) ∈ rcong H ⟹ inv a ⊗ b ∈ H›*) apply fast (*proven 3 subgoals*) . note carr = acarr (*‹a ∈ carrier G›*) bcarr (*‹b ∈ carrier G›*) ccarr (*‹c ∈ carrier G›*) from carr (*‹a ∈ carrier G› ‹(b::'a::type) ∈ carrier G› ‹c ∈ carrier G›*) inv_closed (*‹?x ∈ carrier G ⟹ inv ?x ∈ carrier G›*) have "inv a ⊗ b = inv a ⊗ (𝟭 ⊗ b)" by simp also (*calculation: ‹inv a ⊗ b = inv a ⊗ (𝟭 ⊗ b)›*) from carr (*‹a ∈ carrier G› ‹b ∈ carrier G› ‹c ∈ carrier G›*) inv_closed (*‹?x ∈ carrier G ⟹ inv ?x ∈ carrier G›*) have "… = inv a ⊗ (inv c ⊗ c) ⊗ b" by simp also (*calculation: ‹inv a ⊗ b = inv a ⊗ (inv c ⊗ c) ⊗ b›*) from carr (*‹a ∈ carrier G› ‹b ∈ carrier G› ‹c ∈ carrier G›*) inv_closed (*‹?x ∈ carrier G ⟹ inv ?x ∈ carrier G›*) have "… = (inv a ⊗ inv c) ⊗ (c ⊗ b)" by (force cong: m_assoc (*‹⟦?x ∈ carrier G; ?y ∈ carrier G; ?z ∈ carrier G⟧ ⟹ ?x ⊗ ?y ⊗ ?z = ?x ⊗ (?y ⊗ ?z)›*)) also (*calculation: ‹inv a ⊗ b = inv a ⊗ inv c ⊗ (c ⊗ b)›*) from carr (*‹a ∈ carrier G› ‹b ∈ carrier G› ‹c ∈ carrier G›*) inv_closed (*‹?x ∈ carrier G ⟹ inv ?x ∈ carrier G›*) have "… = inv (c ⊗ a) ⊗ (c ⊗ b)" by (simp add: inv_mult_group (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ inv (?x ⊗ ?y) = inv ?y ⊗ inv ?x›*)) finally (*calculation: ‹inv a ⊗ b = inv (c ⊗ a) ⊗ (c ⊗ b)›*) have "inv a ⊗ b = inv (c ⊗ a) ⊗ (c ⊗ b)" . from abH (*‹inv a ⊗ b ∈ H›*) this (*‹inv a ⊗ b = inv (c ⊗ a) ⊗ (c ⊗ b)›*) have "inv (c ⊗ a) ⊗ (c ⊗ b) ∈ H" by simp from carr (*‹(a::'a) ∈ carrier G› ‹b ∈ carrier G› ‹c ∈ carrier G›*) this (*‹inv ((c::'a) ⊗ (a::'a)) ⊗ (c ⊗ (b::'a)) ∈ (H::'a set)›*) have "(c ⊗ b) ∈ (c ⊗ a) <# H" by (simp add: lcos_module_rev[OF is_group] (*‹⟦?x ∈ carrier G; ?x' ∈ carrier G; inv ?x ⊗ ?x' ∈ H⟧ ⟹ ?x' ∈ ?x <# H›*)) from carr (*‹a ∈ carrier G› ‹b ∈ carrier G› ‹c ∈ carrier G›*) this (*‹c ⊗ b ∈ c ⊗ a <# H›*) is_subgroup (*‹subgroup (H::'a set) G›*) show "(c ⊗ a) <# H = (c ⊗ b) <# H" apply (intro l_repr_independence (*‹⟦(?y::'a) ∈ (?x::'a) <# (?H::'a set); ?x ∈ carrier G; subgroup ?H G⟧ ⟹ ?x <# ?H = ?y <# ?H›*)) (*goals: 1. ‹⟦a ∈ carrier G; b ∈ carrier G; c ∈ carrier G; c ⊗ b ∈ c ⊗ a <# H; subgroup H G⟧ ⟹ c ⊗ b ∈ c ⊗ a <# H› 2. ‹⟦a ∈ carrier G; b ∈ carrier G; c ∈ carrier G; c ⊗ b ∈ c ⊗ a <# H; subgroup H G⟧ ⟹ c ⊗ a ∈ carrier G› 3. ‹⟦a ∈ carrier G; b ∈ carrier G; c ∈ carrier G; c ⊗ b ∈ c ⊗ a <# H; subgroup H G⟧ ⟹ subgroup H G› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) . qed subsection ‹Order of a Group and Lagrange's Theorem› definition order :: "('a, 'b) monoid_scheme ⇒ nat" where "order S = card (carrier S)" lemma iso_same_order: assumes "φ ∈ iso G H" shows "order G = order H" by (metis assms (*‹φ ∈ Group.iso G H›*) is_isoI (*‹?h ∈ Group.iso ?G ?H ⟹ ?G ≅ ?H›*) iso_same_card (*‹?G ≅ ?H ⟹ card (carrier ?G) = card (carrier ?H)›*) order_def (*‹order ?S = card (carrier ?S)›*) order_def (*‹order ?S = card (carrier ?S)›*)) lemma (in monoid) order_gt_0_iff_finite: "0 < order G ⟷ finite (carrier G)" by (auto simp add: order_def (*‹order ?S = card (carrier ?S)›*) card_gt_0_iff (*‹(0 < card ?A) = (?A ≠ {} ∧ finite ?A)›*)) lemma (in group) order_one_triv_iff: shows "(order G = 1) = (carrier G = {𝟭})" by (metis One_nat_def (*‹(1::nat) = Suc (0::nat)›*) card.empty (*‹card {} = (0::nat)›*) card_Suc_eq (*‹(card (?A::?'a::type set) = Suc (?k::nat)) = (∃(b::?'a::type) B::?'a::type set. ?A = insert b B ∧ b ∉ B ∧ card B = ?k ∧ (?k = (0::nat) ⟶ B = {}))›*) empty_iff (*‹((?c::?'a::type) ∈ {}) = False›*) one_closed (*‹𝟭 ∈ carrier G›*) order_def (*‹order (?S::(?'a, ?'b) monoid_scheme) = card (carrier ?S)›*) singleton_iff (*‹((?b::?'a::type) ∈ {?a::?'a::type}) = (?b = ?a)›*)) lemma (in group) rcosets_part_G: assumes "subgroup H G" shows "⋃(rcosets H) = carrier G" proof (-) (*goal: ‹⋃ (rcosets H) = carrier G›*) interpret subgroup H G by fact show "?thesis" (*goal: ‹⋃ (rcosets H) = carrier G›*) unfolding RCOSETS_def r_coset_def (*goal: ‹⋃ (⋃a∈carrier G. {⋃h∈H. {h ⊗ a}}) = carrier G›*) by auto qed lemma (in group) cosets_finite: "⟦c ∈ rcosets H; H ⊆ carrier G; finite (carrier G)⟧ ⟹ finite c" unfolding RCOSETS_def (*goal: ‹⟦c ∈ (⋃a∈carrier G. {H #> a}); H ⊆ carrier G; finite (carrier G)⟧ ⟹ finite c›*) by (auto simp add: r_coset_subset_G [THEN finite_subset] (*‹⟦?H1 ⊆ carrier G; ?x1 ∈ carrier G; finite (carrier G)⟧ ⟹ finite (?H1 #> ?x1)›*)) text‹The next two lemmas support the proof of ‹card_cosets_equal›.› lemma (in group) inj_on_f: assumes "H ⊆ carrier G" and a: "a ∈ carrier G" shows "inj_on (λy. y ⊗ inv a) (H #> a)" proof (standard) (*goal: ‹⋀x y. ⟦x ∈ H #> a; y ∈ H #> a; x ⊗ inv a = y ⊗ inv a⟧ ⟹ x = y›*) fix x and y assume "x ∈ H #> a" "y ∈ H #> a" and xy: "x ⊗ inv a = y ⊗ inv a" (*‹(x::'a) ∈ (H::'a set) #> (a::'a)› ‹(y::'a) ∈ (H::'a set) #> (a::'a)› ‹(x::'a) ⊗ inv (a::'a) = (y::'a) ⊗ inv a›*) then have "x ∈ carrier G" "y ∈ carrier G" using assms (*‹H ⊆ carrier G› ‹a ∈ carrier G›*) r_coset_subset_G (*‹⟦(?H::'a set) ⊆ carrier G; (?x::'a) ∈ carrier G⟧ ⟹ ?H #> ?x ⊆ carrier G›*) apply - (*goals: 1. ‹⟦(x::'a) ∈ (H::'a set) #> (a::'a); (y::'a) ∈ H #> a; x ⊗ inv a = y ⊗ inv a; H ⊆ carrier G; a ∈ carrier G; ⋀(H::'a set) x::'a. ⟦H ⊆ carrier G; x ∈ carrier G⟧ ⟹ H #> x ⊆ carrier G⟧ ⟹ x ∈ carrier G› 2. ‹⟦(x::'a) ∈ (H::'a set) #> (a::'a); (y::'a) ∈ H #> a; x ⊗ inv a = y ⊗ inv a; H ⊆ carrier G; a ∈ carrier G; ⋀(H::'a set) x::'a. ⟦H ⊆ carrier G; x ∈ carrier G⟧ ⟹ H #> x ⊆ carrier G⟧ ⟹ y ∈ carrier G› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) . with xy (*‹x ⊗ inv a = y ⊗ inv a›*) a (*‹a ∈ carrier G›*) show "x = y" by auto qed lemma (in group) inj_on_g: "⟦H ⊆ carrier G; a ∈ carrier G⟧ ⟹ inj_on (λy. y ⊗ a) H" by (force simp add: inj_on_def (*‹inj_on ?f ?A = (∀x∈?A. ∀y∈?A. ?f x = ?f y ⟶ x = y)›*) subsetD (*‹⟦?A ⊆ ?B; ?c ∈ ?A⟧ ⟹ ?c ∈ ?B›*)) (* ************************************************************************** *) lemma (in group) card_cosets_equal: assumes "R ∈ rcosets H" "H ⊆ carrier G" shows "∃f. bij_betw f H R" proof (-) (*goal: ‹∃f::'a::type ⇒ 'a::type. bij_betw f (H::'a::type set) (R::'a::type set)›*) obtain g where g: "g ∈ carrier G" "R = H #> g" (*goal: ‹(⋀g::'a. ⟦g ∈ carrier G; (R::'a set) = (H::'a set) #> g⟧ ⟹ thesis::bool) ⟹ thesis›*) using assms(1) (*‹R ∈ rcosets H›*) unfolding RCOSETS_def (*goal: ‹(⋀g. ⟦g ∈ carrier G; R = H #> g⟧ ⟹ thesis) ⟹ thesis›*) by blast let ?f = "λh. h ⊗ g" have "⋀r. r ∈ R ⟹ ∃h ∈ H. ?f h = r" proof (-) (*goal: ‹⋀r. r ∈ R ⟹ ∃h∈H. h ⊗ g = r›*) fix r assume "r ∈ R" (*‹(r::'a) ∈ (R::'a set)›*) then obtain h where "h ∈ H" "r = h ⊗ g" (*goal: ‹(⋀h::'a. ⟦h ∈ (H::'a set); (r::'a) = h ⊗ (g::'a)⟧ ⟹ thesis::bool) ⟹ thesis›*) using g (*‹g ∈ carrier G› ‹R = H #> g›*) unfolding r_coset_def (*goal: ‹(⋀h. ⟦h ∈ H; r = h ⊗ g⟧ ⟹ thesis) ⟹ thesis›*) by blast thus "∃h ∈ H. ?f h = r" by blast qed hence "R ⊆ ?f ` H" by blast moreover have "?f ` H ⊆ R" using g (*‹(g::'a) ∈ carrier G› ‹(R::'a set) = (H::'a set) #> (g::'a)›*) unfolding r_coset_def (*goal: ‹(λh. h ⊗ g) ` H ⊆ R›*) by blast ultimately show "?thesis" (*goal: ‹∃f. bij_betw f H R›*) using inj_on_g (*‹⟦?H ⊆ carrier G; ?a ∈ carrier G⟧ ⟹ inj_on (λy. y ⊗ ?a) ?H›*) unfolding bij_betw_def (*goal: ‹∃f. inj_on f H ∧ f ` H = R›*) using assms(2) (*‹(H::'a set) ⊆ carrier G›*) g(1) (*‹g ∈ carrier G›*) by auto qed corollary (in group) card_rcosets_equal: assumes "R ∈ rcosets H" "H ⊆ carrier G" shows "card H = card R" using card_cosets_equal (*‹⟦(?R::'a set) ∈ rcosets (?H::'a set); ?H ⊆ carrier G⟧ ⟹ ∃f::'a ⇒ 'a. bij_betw f ?H ?R›*) assms (*‹(R::'a set) ∈ rcosets (H::'a set)› ‹(H::'a set) ⊆ carrier G›*) bij_betw_same_card (*‹bij_betw ?f ?A ?B ⟹ card ?A = card ?B›*) by blast corollary (in group) rcosets_finite: assumes "R ∈ rcosets H" "H ⊆ carrier G" "finite H" shows "finite R" using card_cosets_equal (*‹⟦(?R::'a set) ∈ rcosets (?H::'a set); ?H ⊆ carrier G⟧ ⟹ ∃f::'a ⇒ 'a. bij_betw f ?H ?R›*) assms (*‹R ∈ rcosets H› ‹H ⊆ carrier G› ‹finite H›*) bij_betw_finite (*‹bij_betw ?f ?A ?B ⟹ finite ?A = finite ?B›*) is_group (*‹Group.group G›*) by blast (* ************************************************************************** *) lemma (in group) rcosets_subset_PowG: "subgroup H G ⟹ rcosets H ⊆ Pow(carrier G)" using rcosets_part_G (*‹subgroup (?H::'a::type set) G ⟹ ⋃ (rcosets ?H) = carrier G›*) by auto proposition (in group) lagrange_finite: assumes "finite(carrier G)" and HG: "subgroup H G" shows "card(rcosets H) * card(H) = order(G)" proof (-) (*goal: ‹card (rcosets H) * card H = order G›*) have "card H * card (rcosets H) = card (⋃(rcosets H))" proof (rule card_partition (*‹⟦finite ?C; finite (⋃ ?C); ⋀c. c ∈ ?C ⟹ card c = ?k; ⋀c1 c2. ⟦c1 ∈ ?C; c2 ∈ ?C; c1 ≠ c2⟧ ⟹ c1 ∩ c2 = {}⟧ ⟹ ?k * card ?C = card (⋃ ?C)›*)) (*goals: 1. ‹finite (rcosets H)› 2. ‹finite (⋃ (rcosets H))› 3. ‹⋀c. c ∈ rcosets H ⟹ card c = card H› 4. ‹⋀c1 c2. ⟦c1 ∈ rcosets H; c2 ∈ rcosets H; c1 ≠ c2⟧ ⟹ c1 ∩ c2 = {}›*) show "⋀c1 c2. ⟦c1 ∈ rcosets H; c2 ∈ rcosets H; c1 ≠ c2⟧ ⟹ c1 ∩ c2 = {}" using HG (*‹subgroup H G›*) rcos_disjoint (*‹subgroup ?H G ⟹ pairwise disjnt (rcosets ?H)›*) by (auto simp: pairwise_def (*‹pairwise ?R ?S = (∀x∈?S. ∀y∈?S. x ≠ y ⟶ ?R x y)›*) disjnt_def (*‹disjnt ?A ?B = (?A ∩ ?B = {})›*)) qed (auto simp: assms (*‹finite (carrier G)› ‹subgroup H G›*) finite_UnionD (*‹finite (⋃ ?A) ⟹ finite ?A›*) rcosets_part_G (*‹subgroup ?H G ⟹ ⋃ (rcosets ?H) = carrier G›*) card_rcosets_equal (*‹⟦?R ∈ rcosets ?H; ?H ⊆ carrier G⟧ ⟹ card ?H = card ?R›*) subgroup.subset (*‹subgroup ?H ?G ⟹ ?H ⊆ carrier ?G›*)) (*solves the remaining goals: 1. ‹finite (rcosets H)› 2. ‹finite (⋃ (rcosets H))› 3. ‹⋀c. c ∈ rcosets H ⟹ card c = card H›*) then show "?thesis" (*goal: ‹card (rcosets H) * card H = order G›*) by (simp add: HG (*‹subgroup H G›*) mult.commute (*‹?a * ?b = ?b * ?a›*) order_def (*‹order ?S = card (carrier ?S)›*) rcosets_part_G (*‹subgroup ?H G ⟹ ⋃ (rcosets ?H) = carrier G›*)) qed theorem (in group) lagrange: assumes "subgroup H G" shows "card (rcosets H) * card H = order G" proof (cases "finite (carrier G)") (*goals: 1. ‹finite (carrier G) ⟹ card (rcosets (H::'a set)) * card H = order G› 2. ‹infinite (carrier G) ⟹ card (rcosets (H::'a set)) * card H = order G›*) case True (*‹finite (carrier G)›*) thus "?thesis" (*goal: ‹card (rcosets H) * card H = order G›*) using lagrange_finite (*‹⟦finite (carrier G); subgroup (?H::'a set) G⟧ ⟹ card (rcosets ?H) * card ?H = order G›*) assms (*‹subgroup H G›*) by simp next (*goal: ‹infinite (carrier G) ⟹ card (rcosets H) * card H = order G›*) case False (*‹infinite (carrier G)›*) thus "?thesis" (*goal: ‹card (rcosets (H::'a set)) * card H = order G›*) proof (cases "finite H") (*goals: 1. ‹⟦infinite (carrier G); finite (H::'a::type set)⟧ ⟹ card (rcosets H) * card H = order G› 2. ‹⟦infinite (carrier G); infinite (H::'a::type set)⟧ ⟹ card (rcosets H) * card H = order G›*) case False (*‹infinite H›*) thus "?thesis" (*goal: ‹card (rcosets H) * card H = order G›*) using ‹infinite (carrier G)› (*‹infinite (carrier G)›*) by (simp add: order_def (*‹order ?S = card (carrier ?S)›*)) next (*goal: ‹⟦infinite (carrier G); finite H⟧ ⟹ card (rcosets H) * card H = order G›*) case True (*‹finite H›*) have "infinite (rcosets H)" proof (standard) (*goal: ‹finite (rcosets (H::'a set)) ⟹ False›*) assume "finite (rcosets H)" (*‹finite (rcosets (H::'a set))›*) hence finite_rcos: "finite (rcosets H)" by simp hence "card (⋃(rcosets H)) = (∑R∈(rcosets H). card R)" using card_Union_disjoint[of "rcosets H"] (*‹⟦pairwise disjnt (rcosets H); ⋀A. A ∈ rcosets H ⟹ finite A⟧ ⟹ card (⋃ (rcosets H)) = sum card (rcosets H)›*) ‹finite H› (*‹finite H›*) rcos_disjoint[OF assms ( 1 )] (*‹pairwise disjnt (rcosets H)›*) rcosets_finite[where ?H = H] (*‹⟦?R ∈ rcosets H; H ⊆ carrier G; finite H⟧ ⟹ finite ?R›*) by (simp add: assms (*‹subgroup (H::'a::type set) G›*) subgroup.subset (*‹subgroup (?H::?'a::type set) (?G::(?'a, ?'b) monoid_scheme) ⟹ ?H ⊆ carrier ?G›*)) hence "order G = (∑R∈(rcosets H). card R)" by (simp add: assms (*‹subgroup H G›*) order_def (*‹order ?S = card (carrier ?S)›*) rcosets_part_G (*‹subgroup ?H G ⟹ ⋃ (rcosets ?H) = carrier G›*)) hence "order G = (∑R∈(rcosets H). card H)" using card_rcosets_equal (*‹⟦(?R::'a::type set) ∈ rcosets (?H::'a::type set); ?H ⊆ carrier G⟧ ⟹ card ?H = card ?R›*) by (simp add: assms (*‹subgroup H G›*) subgroup.subset (*‹subgroup ?H ?G ⟹ ?H ⊆ carrier ?G›*)) hence "order G = (card H) * (card (rcosets H))" by simp hence "order G ≠ 0" using finite_rcos (*‹finite (rcosets H)›*) ‹finite H› (*‹finite H›*) assms (*‹subgroup H G›*) ex_in_conv (*‹(∃x::?'a::type. x ∈ (?A::?'a::type set)) = (?A ≠ {})›*) rcosets_part_G (*‹subgroup ?H G ⟹ ⋃ (rcosets ?H) = carrier G›*) subgroup.one_closed (*‹subgroup (?H::?'a::type set) (?G::(?'a, ?'b) monoid_scheme) ⟹ 𝟭⇘?G⇙ ∈ ?H›*) by fastforce thus False using ‹infinite (carrier G)› (*‹infinite (carrier G)›*) order_gt_0_iff_finite (*‹(0 < order G) = finite (carrier G)›*) by blast qed thus "?thesis" (*goal: ‹card (rcosets H) * card H = order G›*) using ‹infinite (carrier G)› (*‹infinite (carrier G)›*) by (simp add: order_def (*‹order (?S::(?'a, ?'b) monoid_scheme) = card (carrier ?S)›*)) qed qed text ‹The cardinality of the right cosets of the trivial subgroup is the cardinality of the group itself:› corollary (in group) card_rcosets_triv: assumes "finite (carrier G)" shows "card (rcosets {𝟭}) = order G" using lagrange (*‹subgroup ?H G ⟹ card (rcosets ?H) * card ?H = order G›*) triv_subgroup (*‹subgroup {𝟭} G›*) by fastforce subsection ‹Quotient Groups: Factorization of a Group› definition FactGroup :: "[('a,'b) monoid_scheme, 'a set] ⇒ ('a set) monoid" (infixl "Mod" 65) ― ‹Actually defined for groups rather than monoids› where "FactGroup G H = ⦇carrier = rcosets⇘G⇙ H, mult = set_mult G, one = H⦈" lemma (in normal) setmult_closed: "⟦K1 ∈ rcosets H; K2 ∈ rcosets H⟧ ⟹ K1 <#> K2 ∈ rcosets H" by (auto simp add: rcos_sum (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ H #> ?x <#> (H #> ?y) = H #> ?x ⊗ ?y›*) RCOSETS_def (*‹rcosets⇘?G⇙ ?H = (⋃a∈carrier ?G. {?H #>⇘?G⇙ a})›*)) lemma (in normal) setinv_closed: "K ∈ rcosets H ⟹ set_inv K ∈ rcosets H" by (auto simp add: rcos_inv (*‹?x ∈ carrier G ⟹ set_inv (H #> ?x) = H #> inv ?x›*) RCOSETS_def (*‹rcosets⇘?G⇙ ?H = (⋃a∈carrier ?G. {?H #>⇘?G⇙ a})›*)) lemma (in normal) rcosets_assoc: "⟦M1 ∈ rcosets H; M2 ∈ rcosets H; M3 ∈ rcosets H⟧ ⟹ M1 <#> M2 <#> M3 = M1 <#> (M2 <#> M3)" by (simp add: group.set_mult_assoc (*‹⟦Group.group ?G; ?M ⊆ carrier ?G; ?H ⊆ carrier ?G; ?K ⊆ carrier ?G⟧ ⟹ ?M <#>⇘?G⇙ ?H <#>⇘?G⇙ ?K = ?M <#>⇘?G⇙ (?H <#>⇘?G⇙ ?K)›*) is_group (*‹Group.group G›*) rcosets_carrier (*‹⟦Group.group G; ?X ∈ rcosets H⟧ ⟹ ?X ⊆ carrier G›*)) lemma (in subgroup) subgroup_in_rcosets: assumes "group G" shows "H ∈ rcosets H" proof (-) (*goal: ‹H ∈ rcosets H›*) interpret group G by fact from "_" (*‹PROP ?psi ⟹ PROP ?psi›*) subgroup_axioms (*‹subgroup H G›*) have "H #> 𝟭 = H" apply (rule coset_join2 (*‹⟦?x ∈ carrier G; subgroup ?H G; ?x ∈ ?H⟧ ⟹ ?H #> ?x = ?H›*)) (*goals: 1. ‹𝟭 ∈ carrier G› 2. ‹𝟭 ∈ H› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . then show "?thesis" (*goal: ‹H ∈ rcosets H›*) by (auto simp add: RCOSETS_def (*‹rcosets⇘?G⇙ ?H = (⋃a∈carrier ?G. {?H #>⇘?G⇙ a})›*)) qed lemma (in normal) rcosets_inv_mult_group_eq: "M ∈ rcosets H ⟹ set_inv M <#> M = H" by (auto simp add: RCOSETS_def (*‹rcosets⇘?G::(?'a, ?'b) monoid_scheme⇙ (?H::?'a set) = (⋃a::?'a∈carrier ?G. {?H #>⇘?G⇙ a})›*) rcos_inv (*‹(?x::'a) ∈ carrier G ⟹ set_inv ((H::'a set) #> ?x) = H #> inv ?x›*) rcos_sum (*‹⟦(?x::'a) ∈ carrier G; (?y::'a) ∈ carrier G⟧ ⟹ (H::'a set) #> ?x <#> (H #> ?y) = H #> ?x ⊗ ?y›*) subgroup.subset (*‹subgroup (?H::?'a set) (?G::(?'a, ?'b) monoid_scheme) ⟹ ?H ⊆ carrier ?G›*) normal.axioms (*‹(?H::?'a set) ⊲ (?G::(?'a, ?'b) monoid_scheme) ⟹ subgroup ?H ?G› ‹(?H::?'a set) ⊲ (?G::(?'a, ?'b) monoid_scheme) ⟹ Group.group ?G› ‹(?H::?'a set) ⊲ (?G::(?'a, ?'b) monoid_scheme) ⟹ normal_axioms ?H ?G›*) normal_axioms (*‹(H::'a set) ⊲ G›*)) theorem (in normal) factorgroup_is_group: "group (G Mod H)" proof (-) (*goal: ‹Group.group (G Mod H)›*) have "⋀x. x ∈ rcosets H ⟹ ∃y∈rcosets H. y <#> x = H" using rcosets_inv_mult_group_eq (*‹?M ∈ rcosets H ⟹ set_inv ?M <#> ?M = H›*) setinv_closed (*‹(?K::'a set) ∈ rcosets (H::'a set) ⟹ set_inv ?K ∈ rcosets H›*) by blast then show "?thesis" (*goal: ‹Group.group (G Mod H)›*) unfolding FactGroup_def (*goal: ‹Group.group ⦇carrier = rcosets H, mult = (<#>), one = H⦈›*) apply (intro groupI (*‹⟦⋀x y. ⟦x ∈ carrier ?G; y ∈ carrier ?G⟧ ⟹ x ⊗⇘?G⇙ y ∈ carrier ?G; 𝟭⇘?G⇙ ∈ carrier ?G; ⋀x y z. ⟦x ∈ carrier ?G; y ∈ carrier ?G; z ∈ carrier ?G⟧ ⟹ x ⊗⇘?G⇙ y ⊗⇘?G⇙ z = x ⊗⇘?G⇙ (y ⊗⇘?G⇙ z); ⋀x. x ∈ carrier ?G ⟹ 𝟭⇘?G⇙ ⊗⇘?G⇙ x = x; ⋀x. x ∈ carrier ?G ⟹ ∃y∈carrier ?G. y ⊗⇘?G⇙ x = 𝟭⇘?G⇙⟧ ⟹ Group.group ?G›*)) (*goals: 1. ‹⋀x y. ⟦⋀x. x ∈ rcosets H ⟹ ∃y∈rcosets H. y <#> x = H; x ∈ carrier ⦇carrier = rcosets H, mult = (<#>), one = H⦈; y ∈ carrier ⦇carrier = rcosets H, mult = (<#>), one = H⦈⟧ ⟹ x ⊗⇘⦇carrier = rcosets H, mult = (<#>), one = H⦈⇙ y ∈ carrier ⦇carrier = rcosets H, mult = (<#>), one = H⦈› 2. ‹(⋀x. x ∈ rcosets H ⟹ ∃y∈rcosets H. y <#> x = H) ⟹ 𝟭⇘⦇carrier = rcosets H, mult = (<#>), one = H⦈⇙ ∈ carrier ⦇carrier = rcosets H, mult = (<#>), one = H⦈› 3. ‹⋀x y z. ⟦⋀x. x ∈ rcosets H ⟹ ∃y∈rcosets H. y <#> x = H; x ∈ carrier ⦇carrier = rcosets H, mult = (<#>), one = H⦈; y ∈ carrier ⦇carrier = rcosets H, mult = (<#>), one = H⦈; z ∈ carrier ⦇carrier = rcosets H, mult = (<#>), one = H⦈⟧ ⟹ x ⊗⇘⦇carrier = rcosets H, mult = (<#>), one = H⦈⇙ y ⊗⇘⦇carrier = rcosets H, mult = (<#>), one = H⦈⇙ z = x ⊗⇘⦇carrier = rcosets H, mult = (<#>), one = H⦈⇙ (y ⊗⇘⦇carrier = rcosets H, mult = (<#>), one = H⦈⇙ z)› 4. ‹⋀x. ⟦⋀x. x ∈ rcosets H ⟹ ∃y∈rcosets H. y <#> x = H; x ∈ carrier ⦇carrier = rcosets H, mult = (<#>), one = H⦈⟧ ⟹ 𝟭⇘⦇carrier = rcosets H, mult = (<#>), one = H⦈⇙ ⊗⇘⦇carrier = rcosets H, mult = (<#>), one = H⦈⇙ x = x› 5. ‹⋀x. ⟦⋀x. x ∈ rcosets H ⟹ ∃y∈rcosets H. y <#> x = H; x ∈ carrier ⦇carrier = rcosets H, mult = (<#>), one = H⦈⟧ ⟹ ∃y∈carrier ⦇carrier = rcosets H, mult = (<#>), one = H⦈. y ⊗⇘⦇carrier = rcosets H, mult = (<#>), one = H⦈⇙ x = 𝟭⇘⦇carrier = rcosets H, mult = (<#>), one = H⦈⇙› discuss goal 1*) apply ((auto simp: setmult_closed (*‹⟦?K1.0 ∈ rcosets H; ?K2.0 ∈ rcosets H⟧ ⟹ ?K1.0 <#> ?K2.0 ∈ rcosets H›*) subgroup_in_rcosets (*‹Group.group G ⟹ H ∈ rcosets H›*) rcosets_assoc (*‹⟦?M1.0 ∈ rcosets H; ?M2.0 ∈ rcosets H; ?M3.0 ∈ rcosets H⟧ ⟹ ?M1.0 <#> ?M2.0 <#> ?M3.0 = ?M1.0 <#> (?M2.0 <#> ?M3.0)›*) rcosets_mult_eq (*‹?M ∈ rcosets H ⟹ H <#> ?M = ?M›*))[1]) (*discuss goal 2*) apply ((auto simp: setmult_closed (*‹⟦(?K1.0::'a set) ∈ rcosets (H::'a set); (?K2.0::'a set) ∈ rcosets H⟧ ⟹ ?K1.0 <#> ?K2.0 ∈ rcosets H›*) subgroup_in_rcosets (*‹Group.group G ⟹ (H::'a set) ∈ rcosets H›*) rcosets_assoc (*‹⟦(?M1.0::'a set) ∈ rcosets (H::'a set); (?M2.0::'a set) ∈ rcosets H; (?M3.0::'a set) ∈ rcosets H⟧ ⟹ ?M1.0 <#> ?M2.0 <#> ?M3.0 = ?M1.0 <#> (?M2.0 <#> ?M3.0)›*) rcosets_mult_eq (*‹(?M::'a set) ∈ rcosets (H::'a set) ⟹ H <#> ?M = ?M›*))[1]) (*discuss goal 3*) apply ((auto simp: setmult_closed (*‹⟦?K1.0 ∈ rcosets H; ?K2.0 ∈ rcosets H⟧ ⟹ ?K1.0 <#> ?K2.0 ∈ rcosets H›*) subgroup_in_rcosets (*‹Group.group G ⟹ H ∈ rcosets H›*) rcosets_assoc (*‹⟦?M1.0 ∈ rcosets H; ?M2.0 ∈ rcosets H; ?M3.0 ∈ rcosets H⟧ ⟹ ?M1.0 <#> ?M2.0 <#> ?M3.0 = ?M1.0 <#> (?M2.0 <#> ?M3.0)›*) rcosets_mult_eq (*‹?M ∈ rcosets H ⟹ H <#> ?M = ?M›*))[1]) (*discuss goal 4*) apply ((auto simp: setmult_closed (*‹⟦?K1.0 ∈ rcosets H; ?K2.0 ∈ rcosets H⟧ ⟹ ?K1.0 <#> ?K2.0 ∈ rcosets H›*) subgroup_in_rcosets (*‹Group.group G ⟹ H ∈ rcosets H›*) rcosets_assoc (*‹⟦?M1.0 ∈ rcosets H; ?M2.0 ∈ rcosets H; ?M3.0 ∈ rcosets H⟧ ⟹ ?M1.0 <#> ?M2.0 <#> ?M3.0 = ?M1.0 <#> (?M2.0 <#> ?M3.0)›*) rcosets_mult_eq (*‹?M ∈ rcosets H ⟹ H <#> ?M = ?M›*))[1]) (*discuss goal 5*) apply ((auto simp: setmult_closed (*‹⟦?K1.0 ∈ rcosets H; ?K2.0 ∈ rcosets H⟧ ⟹ ?K1.0 <#> ?K2.0 ∈ rcosets H›*) subgroup_in_rcosets (*‹Group.group G ⟹ H ∈ rcosets H›*) rcosets_assoc (*‹⟦?M1.0 ∈ rcosets H; ?M2.0 ∈ rcosets H; ?M3.0 ∈ rcosets H⟧ ⟹ ?M1.0 <#> ?M2.0 <#> ?M3.0 = ?M1.0 <#> (?M2.0 <#> ?M3.0)›*) rcosets_mult_eq (*‹?M ∈ rcosets H ⟹ H <#> ?M = ?M›*))[1]) (*proven 5 subgoals*) . qed lemma carrier_FactGroup: "carrier(G Mod N) = (λx. r_coset G N x) ` carrier G" by (auto simp: FactGroup_def (*‹(?G::(?'a, ?'b) monoid_scheme) Mod (?H::?'a::type set) = ⦇carrier = rcosets⇘?G⇙ ?H, mult = (<#>⇘?G⇙), one = ?H⦈›*) RCOSETS_def (*‹rcosets⇘?G::(?'a, ?'b) monoid_scheme⇙ (?H::?'a::type set) = (⋃a::?'a::type∈carrier ?G. {?H #>⇘?G⇙ a})›*)) lemma one_FactGroup [simp]: "one(G Mod N) = N" by (auto simp: FactGroup_def (*‹?G Mod ?H = ⦇carrier = rcosets⇘?G⇙ ?H, mult = (<#>⇘?G⇙), one = ?H⦈›*)) lemma mult_FactGroup [simp]: "monoid.mult (G Mod N) = set_mult G" by (auto simp: FactGroup_def (*‹(?G::(?'a, ?'b) monoid_scheme) Mod (?H::?'a set) = ⦇carrier = rcosets⇘?G⇙ ?H, mult = (<#>⇘?G⇙), one = ?H⦈›*)) lemma (in normal) inv_FactGroup: assumes "X ∈ carrier (G Mod H)" shows "inv⇘G Mod H⇙ X = set_inv X" proof (-) (*goal: ‹inv⇘G Mod H⇙ X = set_inv X›*) have X: "X ∈ rcosets H" using assms (*‹X ∈ carrier (G Mod H)›*) by (simp add: FactGroup_def (*‹(?G::(?'a, ?'b) monoid_scheme) Mod (?H::?'a set) = ⦇carrier = rcosets⇘?G⇙ ?H, mult = (<#>⇘?G⇙), one = ?H⦈›*)) moreover have "set_inv X <#> X = H" using X (*‹X ∈ rcosets H›*) by (simp add: normal.rcosets_inv_mult_group_eq (*‹⟦?H ⊲ ?G; ?M ∈ rcosets⇘?G⇙ ?H⟧ ⟹ set_inv⇘?G⇙ ?M <#>⇘?G⇙ ?M = ?H›*) normal_axioms (*‹H ⊲ G›*)) moreover have "Group.group (G Mod H)" using normal.factorgroup_is_group (*‹?H ⊲ ?G ⟹ Group.group (?G Mod ?H)›*) normal_axioms (*‹H ⊲ G›*) by blast ultimately show "?thesis" (*goal: ‹inv⇘G Mod H⇙ X = set_inv X›*) by (simp add: FactGroup_def (*‹?G Mod ?H = ⦇carrier = rcosets⇘?G⇙ ?H, mult = (<#>⇘?G⇙), one = ?H⦈›*) group.inv_equality (*‹⟦Group.group ?G; ?y ⊗⇘?G⇙ ?x = 𝟭⇘?G⇙; ?x ∈ carrier ?G; ?y ∈ carrier ?G⟧ ⟹ inv⇘?G⇙ ?x = ?y›*) normal.setinv_closed (*‹⟦?H ⊲ ?G; ?K ∈ rcosets⇘?G⇙ ?H⟧ ⟹ set_inv⇘?G⇙ ?K ∈ rcosets⇘?G⇙ ?H›*) normal_axioms (*‹H ⊲ G›*)) qed text‹The coset map is a homomorphism from \<^term>‹G› to the quotient group \<^term>‹G Mod H›› lemma (in normal) r_coset_hom_Mod: "(λa. H #> a) ∈ hom G (G Mod H)" by (auto simp add: FactGroup_def (*‹?G Mod ?H = ⦇carrier = rcosets⇘?G⇙ ?H, mult = (<#>⇘?G⇙), one = ?H⦈›*) RCOSETS_def (*‹rcosets⇘?G⇙ ?H = (⋃a∈carrier ?G. {?H #>⇘?G⇙ a})›*) Pi_def (*‹Pi ?A ?B = {f. ∀x. x ∈ ?A ⟶ f x ∈ ?B x}›*) hom_def (*‹hom ?G ?H = {h ∈ carrier ?G → carrier ?H. ∀x∈carrier ?G. ∀y∈carrier ?G. h (x ⊗⇘?G⇙ y) = h x ⊗⇘?H⇙ h y}›*) rcos_sum (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ H #> ?x <#> (H #> ?y) = H #> ?x ⊗ ?y›*)) lemma (in comm_group) set_mult_commute: assumes "N ⊆ carrier G" "x ∈ rcosets N" "y ∈ rcosets N" shows "x <#> y = y <#> x" using assms (*‹N ⊆ carrier G› ‹x ∈ rcosets N› ‹(y::'a set) ∈ rcosets (N::'a set)›*) unfolding set_mult_def RCOSETS_def (*goal: ‹(⋃h∈x. ⋃k∈y. {h ⊗ k}) = (⋃h∈y. ⋃k∈x. {h ⊗ k})›*) apply auto (*goals: 1. ‹⋀xa xaa h k. ⟦N ⊆ carrier G; xa ∈ carrier G; x = N #> xa; xaa ∈ carrier G; y = N #> xaa; h ∈ N #> xa; k ∈ N #> xaa⟧ ⟹ ∃x∈N #> xaa. ∃xa∈N #> xa. h ⊗ k = x ⊗ xa› 2. ‹⋀xa xaa h k. ⟦N ⊆ carrier G; xa ∈ carrier G; x = N #> xa; xaa ∈ carrier G; y = N #> xaa; h ∈ N #> xaa; k ∈ N #> xa⟧ ⟹ ∃x∈N #> xa. ∃xa∈N #> xaa. h ⊗ k = x ⊗ xa› discuss goal 1*) apply (metis m_comm (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ ?x ⊗ ?y = ?y ⊗ ?x›*) r_coset_subset_G (*‹⟦?H ⊆ carrier G; ?x ∈ carrier G⟧ ⟹ ?H #> ?x ⊆ carrier G›*) subsetCE (*‹⟦?A ⊆ ?B; ?c ∉ ?A ⟹ ?P; ?c ∈ ?B ⟹ ?P⟧ ⟹ ?P›*)) (*discuss goal 2*) apply (metis m_comm (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ ?x ⊗ ?y = ?y ⊗ ?x›*) r_coset_subset_G (*‹⟦?H ⊆ carrier G; ?x ∈ carrier G⟧ ⟹ ?H #> ?x ⊆ carrier G›*) subsetCE (*‹⟦?A ⊆ ?B; ?c ∉ ?A ⟹ ?P; ?c ∈ ?B ⟹ ?P⟧ ⟹ ?P›*)) (*proven 2 subgoals*) . lemma (in comm_group) abelian_FactGroup: assumes "subgroup N G" shows "comm_group(G Mod N)" proof (rule group.group_comm_groupI (*‹⟦Group.group ?G; ⋀x y. ⟦x ∈ carrier ?G; y ∈ carrier ?G⟧ ⟹ x ⊗⇘?G⇙ y = y ⊗⇘?G⇙ x⟧ ⟹ comm_group ?G›*)) (*goals: 1. ‹Group.group (G Mod (N::'a::type set))› 2. ‹⋀(x::'a::type set) y::'a::type set. ⟦x ∈ carrier (G Mod (N::'a::type set)); y ∈ carrier (G Mod N)⟧ ⟹ x ⊗⇘G Mod N⇙ y = y ⊗⇘G Mod N⇙ x›*) have "N ⊲ G" by (simp add: assms (*‹subgroup N G›*) normal_iff_subgroup (*‹?N ⊲ G = subgroup ?N G›*)) then show "Group.group (G Mod N)" by (simp add: normal.factorgroup_is_group (*‹?H ⊲ ?G ⟹ Group.group (?G Mod ?H)›*)) fix x :: "'a set" and y :: "'a set" assume "x ∈ carrier (G Mod N)" "y ∈ carrier (G Mod N)" (*‹(x::'a set) ∈ carrier (G Mod (N::'a set))› ‹(y::'a set) ∈ carrier (G Mod (N::'a set))›*) then show "x ⊗⇘G Mod N⇙ y = y ⊗⇘G Mod N⇙ x" by (metis FactGroup_def (*‹?G Mod ?H = ⦇carrier = rcosets⇘?G⇙ ?H, mult = (<#>⇘?G⇙), one = ?H⦈›*) assms (*‹subgroup N G›*) mult_FactGroup (*‹(⊗⇘?G Mod ?N⇙) = (<#>⇘?G⇙)›*) partial_object.simps( (*‹carrier ⦇carrier = ?carrier, … = ?more⦈ = ?carrier›*) 1) set_mult_commute (*‹⟦?N ⊆ carrier G; ?x ∈ rcosets ?N; ?y ∈ rcosets ?N⟧ ⟹ ?x <#> ?y = ?y <#> ?x›*) subgroup_def (*‹subgroup ?H ?G ≡ (?H ⊆ carrier ?G ∧ (∀x y. x ∈ ?H ⟶ y ∈ ?H ⟶ x ⊗⇘?G⇙ y ∈ ?H)) ∧ 𝟭⇘?G⇙ ∈ ?H ∧ (∀x. x ∈ ?H ⟶ inv⇘?G⇙ x ∈ ?H)›*)) qed lemma FactGroup_universal: assumes "h ∈ hom G H" "N ⊲ G" and h: "⋀x y. ⟦x ∈ carrier G; y ∈ carrier G; r_coset G N x = r_coset G N y⟧ ⟹ h x = h y" obtains g where "g ∈ hom (G Mod N) H" "⋀x. x ∈ carrier G ⟹ g(r_coset G N x) = h x" proof (-) (*goal: ‹(⋀g. ⟦g ∈ hom (G Mod N) H; ⋀x. x ∈ carrier G ⟹ g (N #>⇘G⇙ x) = h x⟧ ⟹ thesis) ⟹ thesis›*) obtain g where g: "⋀x. x ∈ carrier G ⟹ h x = g(r_coset G N x)" (*goal: ‹(⋀g. (⋀x. x ∈ carrier G ⟹ h x = g (N #>⇘G⇙ x)) ⟹ thesis) ⟹ thesis›*) using h (*‹⟦?x ∈ carrier G; ?y ∈ carrier G; N #>⇘G⇙ ?x = N #>⇘G⇙ ?y⟧ ⟹ h ?x = h ?y›*) function_factors_left_gen[of "λx. x ∈ carrier G" "r_coset G N" h] (*‹(∀x y. x ∈ carrier G ∧ y ∈ carrier G ∧ N #>⇘G⇙ x = N #>⇘G⇙ y ⟶ h x = h y) = (∃ha. ∀x. x ∈ carrier G ⟶ h x = ha (N #>⇘G⇙ x))›*) by blast show thesis proof (standard) (*goals: 1. ‹?g ∈ hom (G Mod N) H› 2. ‹⋀x. x ∈ carrier G ⟹ ?g (N #>⇘G⇙ x) = h x›*) show "g ∈ hom (G Mod N) H" proof (rule homI (*‹⟦⋀x. x ∈ carrier ?G ⟹ ?h x ∈ carrier ?H; ⋀x y. ⟦x ∈ carrier ?G; y ∈ carrier ?G⟧ ⟹ ?h (x ⊗⇘?G⇙ y) = ?h x ⊗⇘?H⇙ ?h y⟧ ⟹ ?h ∈ hom ?G ?H›*)) (*goals: 1. ‹⋀x. x ∈ carrier (G Mod N) ⟹ g x ∈ carrier H› 2. ‹⋀x y. ⟦x ∈ carrier (G Mod N); y ∈ carrier (G Mod N)⟧ ⟹ g (x ⊗⇘G Mod N⇙ y) = g x ⊗⇘H⇙ g y›*) show "g (u ⊗⇘G Mod N⇙ v) = g u ⊗⇘H⇙ g v" if "u ∈ carrier (G Mod N)" "v ∈ carrier (G Mod N)" for u and v proof (-) (*goal: ‹(g::'a set ⇒ 'b) ((u::'a set) ⊗⇘(G::('a, 'c) monoid_scheme) Mod (N::'a set)⇙ (v::'a set)) = g u ⊗⇘H::('b, 'd) monoid_scheme⇙ g v›*) from that (*‹(u::'a set) ∈ carrier ((G::('a, 'c) monoid_scheme) Mod (N::'a set))› ‹v ∈ carrier (G Mod N)›*) obtain x and y where xy: "x ∈ carrier G" "u = r_coset G N x" "y ∈ carrier G" "v = r_coset G N y" (*goal: ‹(⋀x y. ⟦x ∈ carrier G; u = N #>⇘G⇙ x; y ∈ carrier G; v = N #>⇘G⇙ y⟧ ⟹ thesis) ⟹ thesis›*) by (auto simp: carrier_FactGroup (*‹carrier ((?G::(?'a, ?'b) monoid_scheme) Mod (?N::?'a set)) = (#>⇘?G⇙) ?N ` carrier ?G›*)) then have "h (x ⊗⇘G⇙ y) = h x ⊗⇘H⇙ h y" by (metis hom_mult [OF ‹h ∈ hom G H›] (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ h (?x ⊗⇘G⇙ ?y) = h ?x ⊗⇘H⇙ h ?y›*)) then show "?thesis" (*goal: ‹g (u ⊗⇘G Mod N⇙ v) = g u ⊗⇘H⇙ g v›*) by (metis Coset.mult_FactGroup (*‹(⊗⇘(?G::(?'a, ?'b) monoid_scheme) Mod (?N::?'a::type set)⇙) = (<#>⇘?G⇙)›*) xy (*‹(x::'a::type) ∈ carrier (G::('a, 'c) monoid_scheme)› ‹(u::'a::type set) = (N::'a::type set) #>⇘G::('a, 'c) monoid_scheme⇙ (x::'a::type)› ‹(y::'a::type) ∈ carrier (G::('a, 'c) monoid_scheme)› ‹(v::'a::type set) = (N::'a::type set) #>⇘G::('a, 'c) monoid_scheme⇙ (y::'a::type)›*) ‹N ⊲ G› g (*‹(?x::'a::type) ∈ carrier (G::('a, 'c) monoid_scheme) ⟹ (h::'a::type ⇒ 'b::type) ?x = (g::'a::type set ⇒ 'b::type) ((N::'a::type set) #>⇘G⇙ ?x)›*) group.subgroup_self (*‹Group.group (?G::(?'a, ?'b) monoid_scheme) ⟹ subgroup (carrier ?G) ?G›*) normal.axioms( (*‹(?H::?'a::type set) ⊲ (?G::(?'a, ?'b) monoid_scheme) ⟹ Group.group ?G›*) 2) normal.rcos_sum (*‹⟦(?H::?'a::type set) ⊲ (?G::(?'a, ?'b) monoid_scheme); (?x::?'a::type) ∈ carrier ?G; (?y::?'a::type) ∈ carrier ?G⟧ ⟹ ?H #>⇘?G⇙ ?x <#>⇘?G⇙ (?H #>⇘?G⇙ ?y) = ?H #>⇘?G⇙ ?x ⊗⇘?G⇙ ?y›*) subgroup_def (*‹subgroup (?H::?'a::type set) (?G::(?'a, ?'b) monoid_scheme) ≡ (?H ⊆ carrier ?G ∧ (∀(x::?'a::type) y::?'a::type. x ∈ ?H ⟶ y ∈ ?H ⟶ x ⊗⇘?G⇙ y ∈ ?H)) ∧ 𝟭⇘?G⇙ ∈ ?H ∧ (∀x::?'a::type. x ∈ ?H ⟶ inv⇘?G⇙ x ∈ ?H)›*)) qed qed (use ‹h ∈ hom G H› in ‹auto simp: carrier_FactGroup Pi_iff hom_def simp flip: g›) (*solved the remaining goal: ‹⋀x. x ∈ carrier (G Mod N) ⟹ g x ∈ carrier H›*) qed (auto simp flip: g (*‹?x ∈ carrier G ⟹ h ?x = g (N #>⇘G⇙ ?x)›*)) (*solved the remaining goal: ‹⋀x. x ∈ carrier G ⟹ g (N #>⇘G⇙ x) = h x›*) qed lemma (in normal) FactGroup_pow: fixes k::nat assumes "a ∈ carrier G" shows "pow (FactGroup G H) (r_coset G H a) k = r_coset G H (pow G a k)" proof (induction k) (*goals: 1. ‹(H #> a) [^]⇘G Mod H⇙ 0 = H #> a [^] 0› 2. ‹⋀k. (H #> a) [^]⇘G Mod H⇙ k = H #> a [^] k ⟹ (H #> a) [^]⇘G Mod H⇙ Suc k = H #> a [^] Suc k›*) case 0 (*no hyothesis introduced yet*) then show "?case" (*goal: ‹(H #> a) [^]⇘G Mod H⇙ 0 = H #> a [^] 0›*) by (simp add: r_coset_def (*‹(?H::?'a set) #>⇘?G::(?'a, ?'b) monoid_scheme⇙ (?a::?'a) = (⋃h::?'a∈?H. {h ⊗⇘?G⇙ ?a})›*)) next (*goal: ‹⋀k::nat. (H #> (a::'a)) [^]⇘G Mod (H::'a set)⇙ k = H #> a [^] k ⟹ (H #> a) [^]⇘G Mod H⇙ Suc k = H #> a [^] Suc k›*) case (Suc k) (*‹(H #> a) [^]⇘G Mod H⇙ k = H #> a [^] k›*) then show "?case" (*goal: ‹(H #> a) [^]⇘G Mod H⇙ Suc k = H #> a [^] Suc k›*) by (simp add: assms (*‹a ∈ carrier G›*) rcos_sum (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ H #> ?x <#> (H #> ?y) = H #> ?x ⊗ ?y›*)) qed lemma (in normal) FactGroup_int_pow: fixes k::int assumes "a ∈ carrier G" shows "pow (FactGroup G H) (r_coset G H a) k = r_coset G H (pow G a k)" by (metis Group.group.axioms( (*‹Group.group (?G::(?'a, ?'b) monoid_scheme) ⟹ Group.monoid ?G›*) 1) image_eqI (*‹⟦(?b::?'a) = (?f::?'b ⇒ ?'a) (?x::?'b); ?x ∈ (?A::?'b set)⟧ ⟹ ?b ∈ ?f ` ?A›*) is_group (*‹Group.group G›*) monoid.nat_pow_closed (*‹⟦Group.monoid (?G::(?'a, ?'b) monoid_scheme); (?x::?'a) ∈ carrier ?G⟧ ⟹ ?x [^]⇘?G⇙ (?n::nat) ∈ carrier ?G›*) int_pow_def2 (*‹(?a::?'a) [^]⇘?G::(?'a, ?'b) monoid_scheme⇙ (?z::int) = (if ?z < (0::int) then inv⇘?G⇙ (?a [^]⇘?G⇙ nat (- ?z)) else ?a [^]⇘?G⇙ nat ?z)›*) assms (*‹(a::'a) ∈ carrier G›*) FactGroup_pow (*‹(?a::'a) ∈ carrier G ⟹ (H #> ?a) [^]⇘G Mod (H::'a set)⇙ (?k::nat) = H #> ?a [^] ?k›*) carrier_FactGroup (*‹carrier ((?G::(?'a, ?'b) monoid_scheme) Mod (?N::?'a set)) = (#>⇘?G⇙) ?N ` carrier ?G›*) inv_FactGroup (*‹(?X::'a set) ∈ carrier (G Mod (H::'a set)) ⟹ inv⇘G Mod H⇙ ?X = set_inv ?X›*) rcos_inv (*‹(?x::'a) ∈ carrier G ⟹ set_inv ((H::'a set) #> ?x) = H #> inv ?x›*)) subsection‹The First Isomorphism Theorem› text‹The quotient by the kernel of a homomorphism is isomorphic to the range of that homomorphism.› definition kernel :: "('a, 'm) monoid_scheme ⇒ ('b, 'n) monoid_scheme ⇒ ('a ⇒ 'b) ⇒ 'a set" ― ‹the kernel of a homomorphism› where "kernel G H h = {x. x ∈ carrier G ∧ h x = 𝟭⇘H⇙}" lemma (in group_hom) subgroup_kernel: "subgroup (kernel G H h) G" by (auto simp add: kernel_def (*‹kernel (?G::(?'a, ?'m) monoid_scheme) (?H::(?'b, ?'n) monoid_scheme) (?h::?'a::type ⇒ ?'b::type) = {x::?'a::type ∈ carrier ?G. ?h x = 𝟭⇘?H⇙}›*) group.intro (*‹⟦Group.monoid (?G::(?'a, ?'b) monoid_scheme); Group.group_axioms ?G⟧ ⟹ Group.group ?G›*) intro: subgroup.intro (*‹⟦(?H::?'a::type set) ⊆ carrier (?G::(?'a, ?'b) monoid_scheme); ⋀(x::?'a::type) y::?'a::type. ⟦x ∈ ?H; y ∈ ?H⟧ ⟹ x ⊗⇘?G⇙ y ∈ ?H; 𝟭⇘?G⇙ ∈ ?H; ⋀x::?'a::type. x ∈ ?H ⟹ inv⇘?G⇙ x ∈ ?H⟧ ⟹ subgroup ?H ?G›*)) text‹The kernel of a homomorphism is a normal subgroup› lemma (in group_hom) normal_kernel: "(kernel G H h) ⊲ G" apply (simp only: G.normal_inv_iff (*‹?N ⊲ G = (subgroup ?N G ∧ (∀x∈carrier G. ∀h∈?N. x ⊗ h ⊗ inv x ∈ ?N))›*) subgroup_kernel (*‹subgroup (kernel G H h) G›*)) (*goal: ‹kernel G H h ⊲ G›*) by (simp add: kernel_def (*‹kernel ?G ?H ?h = {x ∈ carrier ?G. ?h x = 𝟭⇘?H⇙}›*)) lemma iso_kernel_image: assumes "group G" "group H" shows "f ∈ iso G H ⟷ f ∈ hom G H ∧ kernel G H f = {𝟭⇘G⇙} ∧ f ` carrier G = carrier H" (is "?lhs = ?rhs") proof (intro iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*) conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹f ∈ Group.iso G H ⟹ f ∈ hom G H› 2. ‹f ∈ Group.iso G H ⟹ kernel G H f = {𝟭⇘G⇙}› 3. ‹f ∈ Group.iso G H ⟹ f ` carrier G = carrier H› 4. ‹f ∈ hom G H ∧ kernel G H f = {𝟭⇘G⇙} ∧ f ` carrier G = carrier H ⟹ f ∈ Group.iso G H›*) assume f: "?lhs" (*‹(f::'a ⇒ 'c) ∈ Group.iso (G::('a, 'b) monoid_scheme) (H::('c, 'd) monoid_scheme)›*) show "f ∈ hom G H" using Group.iso_iff (*‹(?h ∈ Group.iso ?G ?H) = (?h ∈ hom ?G ?H ∧ ?h ` carrier ?G = carrier ?H ∧ inj_on ?h (carrier ?G))›*) f (*‹(f::'a::type ⇒ 'c::type) ∈ Group.iso (G::('a, 'b) monoid_scheme) (H::('c, 'd) monoid_scheme)›*) by blast show "kernel G H f = {𝟭⇘G⇙}" using assms (*‹Group.group G› ‹Group.group H›*) f (*‹(f::'a::type ⇒ 'c::type) ∈ Group.iso (G::('a, 'b) monoid_scheme) (H::('c, 'd) monoid_scheme)›*) Group.group_def (*‹Group.group ?G ≡ Group.monoid ?G ∧ Group.group_axioms ?G›*) hom_one (*‹⟦?h ∈ hom ?G ?H; Group.group ?G; Group.group ?H⟧ ⟹ ?h 𝟭⇘?G⇙ = 𝟭⇘?H⇙›*) by (fastforce simp add: kernel_def (*‹kernel ?G ?H ?h = {x ∈ carrier ?G. ?h x = 𝟭⇘?H⇙}›*) iso_iff_mon_epi (*‹(?f ∈ Group.iso ?G ?H) = (?f ∈ mon ?G ?H ∧ ?f ∈ epi ?G ?H)›*) mon_iff_hom_one (*‹⟦Group.group ?G; Group.group ?H⟧ ⟹ (?f ∈ mon ?G ?H) = (?f ∈ hom ?G ?H ∧ (∀x. x ∈ carrier ?G ∧ ?f x = 𝟭⇘?H⇙ ⟶ x = 𝟭⇘?G⇙))›*) set_eq_iff (*‹(?A = ?B) = (∀x. (x ∈ ?A) = (x ∈ ?B))›*)) show "f ` carrier G = carrier H" by (meson Group.iso_iff (*‹(?h ∈ Group.iso ?G ?H) = (?h ∈ hom ?G ?H ∧ ?h ` carrier ?G = carrier ?H ∧ inj_on ?h (carrier ?G))›*) f (*‹f ∈ Group.iso G H›*)) next (*goal: ‹f ∈ hom G H ∧ kernel G H f = {𝟭⇘G⇙} ∧ f ` carrier G = carrier H ⟹ f ∈ Group.iso G H›*) assume "?rhs" (*‹(f::'a ⇒ 'c) ∈ hom (G::('a, 'b) monoid_scheme) (H::('c, 'd) monoid_scheme) ∧ kernel G H f = {𝟭⇘G⇙} ∧ f ` carrier G = carrier H›*) with assms (*‹Group.group (G::('a, 'b) monoid_scheme)› ‹Group.group H›*) show "?lhs" by (auto simp: kernel_def (*‹kernel ?G ?H ?h = {x ∈ carrier ?G. ?h x = 𝟭⇘?H⇙}›*) iso_def (*‹Group.iso ?G ?H = {h ∈ hom ?G ?H. bij_betw h (carrier ?G) (carrier ?H)}›*) bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*) inj_on_one_iff' (*‹⟦?h ∈ hom ?G ?H; Group.group ?G; Group.group ?H⟧ ⟹ inj_on ?h (carrier ?G) = (∀x. x ∈ carrier ?G ⟶ ?h x = 𝟭⇘?H⇙ ⟶ x = 𝟭⇘?G⇙)›*)) qed lemma (in group_hom) FactGroup_nonempty: assumes "X ∈ carrier (G Mod kernel G H h)" shows "X ≠ {}" using assms (*‹X ∈ carrier (G Mod kernel G H h)›*) unfolding FactGroup_def (*goal: ‹X ≠ {}›*) by (metis group_hom.subgroup_kernel (*‹group_hom ?G ?H ?h ⟹ subgroup (kernel ?G ?H ?h) ?G›*) group_hom_axioms (*‹group_hom G H h›*) partial_object.simps( (*‹carrier ⦇carrier = ?carrier, … = ?more⦈ = ?carrier›*) 1) subgroup.rcosets_non_empty (*‹⟦subgroup ?H ?G; ?R ∈ rcosets⇘?G⇙ ?H⟧ ⟹ ?R ≠ {}›*)) lemma (in group_hom) FactGroup_universal_kernel: assumes "N ⊲ G" and h: "N ⊆ kernel G H h" obtains g where "g ∈ hom (G Mod N) H" "⋀x. x ∈ carrier G ⟹ g(r_coset G N x) = h x" proof (-) (*goal: ‹(⋀g::'a::type set ⇒ 'c::type. ⟦g ∈ hom (G Mod (N::'a::type set)) (H::('c, 'd) monoid_scheme); ⋀x::'a::type. x ∈ carrier G ⟹ g (N #> x) = (h::'a::type ⇒ 'c::type) x⟧ ⟹ thesis::bool) ⟹ thesis›*) have "h x = h y" if "x ∈ carrier G" "y ∈ carrier G" "r_coset G N x = r_coset G N y" for x and y proof (-) (*goal: ‹h x = h y›*) have "x ⊗⇘G⇙ inv⇘G⇙ y ∈ N" using ‹N ⊲ G› (*‹N ⊲ G›*) group.rcos_self (*‹⟦Group.group ?G; ?x ∈ carrier ?G; subgroup ?H ?G⟧ ⟹ ?x ∈ ?H #>⇘?G⇙ ?x›*) normal.axioms(2) (*‹?H ⊲ ?G ⟹ Group.group ?G›*) normal_imp_subgroup (*‹?H ⊲ ?G ⟹ subgroup ?H ?G›*) subgroup.rcos_module_imp (*‹⟦subgroup ?H ?G; Group.group ?G; ?x ∈ carrier ?G; ?x' ∈ ?H #>⇘?G⇙ ?x⟧ ⟹ ?x' ⊗⇘?G⇙ inv⇘?G⇙ ?x ∈ ?H›*) that (*‹x ∈ carrier G› ‹y ∈ carrier G› ‹(N::'a::type set) #> (x::'a::type) = N #> (y::'a::type)›*) by metis with h (*‹(N::'a set) ⊆ kernel G (H::('c, 'd) monoid_scheme) (h::'a ⇒ 'c)›*) have xy: "x ⊗⇘G⇙ inv⇘G⇙ y ∈ kernel G H h" by blast have "h x ⊗⇘H⇙ inv⇘H⇙(h y) = h (x ⊗⇘G⇙ inv⇘G⇙ y)" by (simp add: that (*‹x ∈ carrier G› ‹y ∈ carrier G› ‹N #> x = N #> y›*)) also (*calculation: ‹h x ⊗⇘H⇙ inv⇘H⇙ h y = h (x ⊗ inv y)›*) have "… = 𝟭⇘H⇙" using xy (*‹x ⊗ inv y ∈ kernel G H h›*) by (simp add: kernel_def (*‹kernel ?G ?H ?h = {x ∈ carrier ?G. ?h x = 𝟭⇘?H⇙}›*)) finally (*calculation: ‹h x ⊗⇘H⇙ inv⇘H⇙ h y = 𝟭⇘H⇙›*) have "h x ⊗⇘H⇙ inv⇘H⇙(h y) = 𝟭⇘H⇙" . then show "?thesis" (*goal: ‹h x = h y›*) using H.inv_equality (*‹⟦?y ⊗⇘H⇙ ?x = 𝟭⇘H⇙; ?x ∈ carrier H; ?y ∈ carrier H⟧ ⟹ inv⇘H⇙ ?x = ?y›*) that (*‹x ∈ carrier G› ‹y ∈ carrier G› ‹N #> x = N #> y›*) by fastforce qed with FactGroup_universal[OF homh ‹N ⊲ G›] (*‹⟦⋀x y. ⟦x ∈ carrier G; y ∈ carrier G; N #> x = N #> y⟧ ⟹ h x = h y; ⋀g. ⟦g ∈ hom (G Mod N) H; ⋀x. x ∈ carrier G ⟹ g (N #> x) = h x⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) that (*‹⟦?g ∈ hom (G Mod N) H; ⋀x. x ∈ carrier G ⟹ ?g (N #> x) = h x⟧ ⟹ thesis›*) show thesis by metis qed lemma (in group_hom) FactGroup_the_elem_mem: assumes X: "X ∈ carrier (G Mod (kernel G H h))" shows "the_elem (h`X) ∈ carrier H" proof (-) (*goal: ‹the_elem (h ` X) ∈ carrier H›*) from X (*‹X ∈ carrier (G Mod kernel G H h)›*) obtain g where g: "g ∈ carrier G" and "X = kernel G H h #> g" (*goal: ‹(⋀g. ⟦g ∈ carrier G; X = kernel G H h #> g⟧ ⟹ thesis) ⟹ thesis›*) by (auto simp add: FactGroup_def (*‹(?G::(?'a, ?'b) monoid_scheme) Mod (?H::?'a set) = ⦇carrier = rcosets⇘?G⇙ ?H, mult = (<#>⇘?G⇙), one = ?H⦈›*) RCOSETS_def (*‹rcosets⇘?G::(?'a, ?'b) monoid_scheme⇙ (?H::?'a set) = (⋃a::?'a∈carrier ?G. {?H #>⇘?G⇙ a})›*)) hence "h ` X = {h g}" by (auto simp add: kernel_def (*‹kernel ?G ?H ?h = {x ∈ carrier ?G. ?h x = 𝟭⇘?H⇙}›*) r_coset_def (*‹?H #>⇘?G⇙ ?a = (⋃h∈?H. {h ⊗⇘?G⇙ ?a})›*) g (*‹g ∈ carrier G›*) intro!: imageI (*‹?x ∈ ?A ⟹ ?f ?x ∈ ?f ` ?A›*)) thus "?thesis" (*goal: ‹the_elem (h ` X) ∈ carrier H›*) by (auto simp add: g (*‹g ∈ carrier G›*)) qed lemma (in group_hom) FactGroup_hom: "(λX. the_elem (h`X)) ∈ hom (G Mod (kernel G H h)) H" proof (-) (*goal: ‹(λX::'a set. the_elem ((h::'a ⇒ 'c) ` X)) ∈ hom (G Mod kernel G (H::('c, 'd) monoid_scheme) h) H›*) have "the_elem (h ` (X <#> X')) = the_elem (h ` X) ⊗⇘H⇙ the_elem (h ` X')" if X: "X ∈ carrier (G Mod kernel G H h)" and X': "X' ∈ carrier (G Mod kernel G H h)" for X and X' proof (-) (*goal: ‹the_elem (h ` (X <#> X')) = the_elem (h ` X) ⊗⇘H⇙ the_elem (h ` X')›*) obtain g and g' where "g ∈ carrier G" and "g' ∈ carrier G" and "X = kernel G H h #> g" and "X' = kernel G H h #> g'" (*goal: ‹(⋀g g'. ⟦g ∈ carrier G; g' ∈ carrier G; X = kernel G H h #> g; X' = kernel G H h #> g'⟧ ⟹ thesis) ⟹ thesis›*) using X (*‹X ∈ carrier (G Mod kernel G H h)›*) X' (*‹X' ∈ carrier (G Mod kernel G H h)›*) by (auto simp add: FactGroup_def (*‹?G Mod ?H = ⦇carrier = rcosets⇘?G⇙ ?H, mult = (<#>⇘?G⇙), one = ?H⦈›*) RCOSETS_def (*‹rcosets⇘?G⇙ ?H = (⋃a∈carrier ?G. {?H #>⇘?G⇙ a})›*)) hence all: "∀x∈X. h x = h g" "∀x∈X'. h x = h g'" and Xsub: "X ⊆ carrier G" and X'sub: "X' ⊆ carrier G" apply - (*goals: 1. ‹⟦g ∈ carrier G; g' ∈ carrier G; X = kernel G H h #> g; X' = kernel G H h #> g'⟧ ⟹ ∀x∈X. h x = h g› 2. ‹⟦g ∈ carrier G; g' ∈ carrier G; X = kernel G H h #> g; X' = kernel G H h #> g'⟧ ⟹ ∀x∈X'. h x = h g'› 3. ‹⟦g ∈ carrier G; g' ∈ carrier G; X = kernel G H h #> g; X' = kernel G H h #> g'⟧ ⟹ X ⊆ carrier G› 4. ‹⟦g ∈ carrier G; g' ∈ carrier G; X = kernel G H h #> g; X' = kernel G H h #> g'⟧ ⟹ X' ⊆ carrier G› discuss goal 1*) apply (force simp add: kernel_def (*‹kernel ?G ?H ?h = {x ∈ carrier ?G. ?h x = 𝟭⇘?H⇙}›*) r_coset_def (*‹?H #>⇘?G⇙ ?a = (⋃h∈?H. {h ⊗⇘?G⇙ ?a})›*) image_def (*‹?f ` ?A = {y. ∃x∈?A. y = ?f x}›*)) (*discuss goal 2*) apply (force simp add: kernel_def (*‹kernel ?G ?H ?h = {x ∈ carrier ?G. ?h x = 𝟭⇘?H⇙}›*) r_coset_def (*‹?H #>⇘?G⇙ ?a = (⋃h∈?H. {h ⊗⇘?G⇙ ?a})›*) image_def (*‹?f ` ?A = {y. ∃x∈?A. y = ?f x}›*)) (*discuss goal 3*) apply (force simp add: kernel_def (*‹kernel ?G ?H ?h = {x ∈ carrier ?G. ?h x = 𝟭⇘?H⇙}›*) r_coset_def (*‹?H #>⇘?G⇙ ?a = (⋃h∈?H. {h ⊗⇘?G⇙ ?a})›*) image_def (*‹?f ` ?A = {y. ∃x∈?A. y = ?f x}›*)) (*discuss goal 4*) apply (force simp add: kernel_def (*‹kernel ?G ?H ?h = {x ∈ carrier ?G. ?h x = 𝟭⇘?H⇙}›*) r_coset_def (*‹?H #>⇘?G⇙ ?a = (⋃h∈?H. {h ⊗⇘?G⇙ ?a})›*) image_def (*‹?f ` ?A = {y. ∃x∈?A. y = ?f x}›*)) (*proven 4 subgoals*) . hence "h ` (X <#> X') = {h g ⊗⇘H⇙ h g'}" using X (*‹X ∈ carrier (G Mod kernel G H h)›*) X' (*‹X' ∈ carrier (G Mod kernel G H h)›*) by (auto dest!: FactGroup_nonempty (*‹?X ∈ carrier (G Mod kernel G H h) ⟹ ?X ≠ {}›*) intro!: image_eqI (*‹⟦?b = ?f ?x; ?x ∈ ?A⟧ ⟹ ?b ∈ ?f ` ?A›*) simp add: set_mult_def (*‹?H <#>⇘?G⇙ ?K = (⋃h∈?H. ⋃k∈?K. {h ⊗⇘?G⇙ k})›*) subsetD [OF Xsub] (*‹?c ∈ X ⟹ ?c ∈ carrier G›*) subsetD [OF X'sub] (*‹?c ∈ X' ⟹ ?c ∈ carrier G›*)) then show "the_elem (h ` (X <#> X')) = the_elem (h ` X) ⊗⇘H⇙ the_elem (h ` X')" by (auto simp add: all (*‹∀x∈X. h x = h g› ‹∀x∈X'. h x = h g'›*) FactGroup_nonempty (*‹?X ∈ carrier (G Mod kernel G H h) ⟹ ?X ≠ {}›*) X (*‹X ∈ carrier (G Mod kernel G H h)›*) X' (*‹X' ∈ carrier (G Mod kernel G H h)›*) the_elem_image_unique (*‹⟦?A ≠ {}; ⋀y. y ∈ ?A ⟹ ?f y = ?f ?x⟧ ⟹ the_elem (?f ` ?A) = ?f ?x›*)) qed then show "?thesis" (*goal: ‹(λX. the_elem (h ` X)) ∈ hom (G Mod kernel G H h) H›*) by (simp add: hom_def (*‹hom ?G ?H = {h ∈ carrier ?G → carrier ?H. ∀x∈carrier ?G. ∀y∈carrier ?G. h (x ⊗⇘?G⇙ y) = h x ⊗⇘?H⇙ h y}›*) FactGroup_the_elem_mem (*‹?X ∈ carrier (G Mod kernel G H h) ⟹ the_elem (h ` ?X) ∈ carrier H›*) normal.factorgroup_is_group [OF normal_kernel] (*‹Group.group (G Mod kernel G H h)›*) group.axioms (*‹Group.group ?G ⟹ Group.monoid ?G› ‹Group.group ?G ⟹ Group.group_axioms ?G›*) monoid.m_closed (*‹⟦Group.monoid ?G; ?x ∈ carrier ?G; ?y ∈ carrier ?G⟧ ⟹ ?x ⊗⇘?G⇙ ?y ∈ carrier ?G›*)) qed text‹Lemma for the following injectivity result› lemma (in group_hom) FactGroup_subset: assumes "g ∈ carrier G" "g' ∈ carrier G" "h g = h g'" shows "kernel G H h #> g ⊆ kernel G H h #> g'" unfolding kernel_def r_coset_def (*goal: ‹(⋃h∈{x ∈ carrier G. h x = 𝟭⇘H⇙}. {h ⊗ g}) ⊆ (⋃h∈{x ∈ carrier G. h x = 𝟭⇘H⇙}. {h ⊗ g'})›*) proof (clarsimp) (*goal: ‹⋀ha. ⟦ha ∈ carrier G; h ha = 𝟭⇘H⇙⟧ ⟹ ∃x. x ∈ carrier G ∧ h x = 𝟭⇘H⇙ ∧ ha ⊗ g = x ⊗ g'›*) fix y assume "y ∈ carrier G" "h y = 𝟭⇘H⇙" (*‹(y::'a) ∈ carrier G› ‹(h::'a ⇒ 'c) (y::'a) = 𝟭⇘H::('c, 'd) monoid_scheme⇙›*) with assms (*‹(g::'a) ∈ carrier G› ‹g' ∈ carrier G› ‹h g = h g'›*) show "∃x. x ∈ carrier G ∧ h x = 𝟭⇘H⇙ ∧ y ⊗ g = x ⊗ g'" apply (rule_tac x="y ⊗ g ⊗ inv g'" in exI (*‹?P ?x ⟹ ∃x. ?P x›*)) (*goal: ‹∃x. x ∈ carrier G ∧ h x = 𝟭⇘H⇙ ∧ y ⊗ g = x ⊗ g'›*) by (auto simp: G.m_assoc (*‹⟦(?x::'a::type) ∈ carrier G; (?y::'a::type) ∈ carrier G; (?z::'a::type) ∈ carrier G⟧ ⟹ ?x ⊗ ?y ⊗ ?z = ?x ⊗ (?y ⊗ ?z)›*)) qed lemma (in group_hom) FactGroup_inj_on: "inj_on (λX. the_elem (h ` X)) (carrier (G Mod kernel G H h))" apply (simp add: inj_on_def (*‹inj_on ?f ?A = (∀x∈?A. ∀y∈?A. ?f x = ?f y ⟶ x = y)›*)) (*goal: ‹inj_on (λX. the_elem (h ` X)) (carrier (G Mod kernel G H h))›*) proof (clarify) (*goal: ‹⋀x y. ⟦x ∈ carrier (G Mod kernel G H h); y ∈ carrier (G Mod kernel G H h); the_elem (h ` x) = the_elem (h ` y)⟧ ⟹ x = y›*) fix X and X' assume X: "X ∈ carrier (G Mod kernel G H h)" and X': "X' ∈ carrier (G Mod kernel G H h)" (*‹(X::'a set) ∈ carrier (G Mod kernel G (H::('c, 'd) monoid_scheme) (h::'a ⇒ 'c))› ‹(X'::'a set) ∈ carrier (G Mod kernel G (H::('c, 'd) monoid_scheme) (h::'a ⇒ 'c))›*) then obtain g and g' where gX: "g ∈ carrier G" "g' ∈ carrier G" "X = kernel G H h #> g" "X' = kernel G H h #> g'" (*goal: ‹(⋀g g'. ⟦g ∈ carrier G; g' ∈ carrier G; X = kernel G H h #> g; X' = kernel G H h #> g'⟧ ⟹ thesis) ⟹ thesis›*) by (auto simp add: FactGroup_def (*‹?G Mod ?H = ⦇carrier = rcosets⇘?G⇙ ?H, mult = (<#>⇘?G⇙), one = ?H⦈›*) RCOSETS_def (*‹rcosets⇘?G⇙ ?H = (⋃a∈carrier ?G. {?H #>⇘?G⇙ a})›*)) hence all: "∀x∈X. h x = h g" "∀x∈X'. h x = h g'" apply - (*goals: 1. ‹⟦(g::'a::type) ∈ carrier G; (g'::'a::type) ∈ carrier G; (X::'a::type set) = kernel G (H::('c, 'd) monoid_scheme) (h::'a::type ⇒ 'c::type) #> g; (X'::'a::type set) = kernel G H h #> g'⟧ ⟹ ∀x::'a::type∈X. h x = h g› 2. ‹⟦(g::'a::type) ∈ carrier G; (g'::'a::type) ∈ carrier G; (X::'a::type set) = kernel G (H::('c, 'd) monoid_scheme) (h::'a::type ⇒ 'c::type) #> g; (X'::'a::type set) = kernel G H h #> g'⟧ ⟹ ∀x::'a::type∈X'. h x = h g'› discuss goal 1*) apply (force simp add: kernel_def (*‹kernel ?G ?H ?h = {x ∈ carrier ?G. ?h x = 𝟭⇘?H⇙}›*) r_coset_def (*‹?H #>⇘?G⇙ ?a = (⋃h∈?H. {h ⊗⇘?G⇙ ?a})›*) image_def (*‹?f ` ?A = {y. ∃x∈?A. y = ?f x}›*)) (*discuss goal 2*) apply (force simp add: kernel_def (*‹kernel (?G::(?'a, ?'m) monoid_scheme) (?H::(?'b, ?'n) monoid_scheme) (?h::?'a ⇒ ?'b) = {x::?'a ∈ carrier ?G. ?h x = 𝟭⇘?H⇙}›*) r_coset_def (*‹(?H::?'a set) #>⇘?G::(?'a, ?'b) monoid_scheme⇙ (?a::?'a) = (⋃h::?'a∈?H. {h ⊗⇘?G⇙ ?a})›*) image_def (*‹(?f::?'a ⇒ ?'b) ` (?A::?'a set) = {y::?'b. ∃x::?'a∈?A. y = ?f x}›*)) (*proven 2 subgoals*) . assume "the_elem (h ` X) = the_elem (h ` X')" (*‹the_elem ((h::'a ⇒ 'c) ` (X::'a set)) = the_elem (h ` (X'::'a set))›*) hence h: "h g = h g'" by (simp add: all (*‹∀x∈X. h x = h g› ‹∀x∈X'. h x = h g'›*) FactGroup_nonempty (*‹?X ∈ carrier (G Mod kernel G H h) ⟹ ?X ≠ {}›*) X (*‹X ∈ carrier (G Mod kernel G H h)›*) X' (*‹X' ∈ carrier (G Mod kernel G H h)›*) the_elem_image_unique (*‹⟦?A ≠ {}; ⋀y. y ∈ ?A ⟹ ?f y = ?f ?x⟧ ⟹ the_elem (?f ` ?A) = ?f ?x›*)) show "X=X'" apply (rule equalityI (*‹⟦(?A::?'a::type set) ⊆ (?B::?'a::type set); ?B ⊆ ?A⟧ ⟹ ?A = ?B›*)) (*goals: 1. ‹X ⊆ X'› 2. ‹X' ⊆ X› discuss goal 1*) apply (simp add: FactGroup_subset (*‹⟦?g ∈ carrier G; ?g' ∈ carrier G; h ?g = h ?g'⟧ ⟹ kernel G H h #> ?g ⊆ kernel G H h #> ?g'›*) h (*‹h g = h g'›*) gX (*‹g ∈ carrier G› ‹g' ∈ carrier G› ‹X = kernel G H h #> g› ‹X' = kernel G H h #> g'›*)) (*discuss goal 2*) apply (simp add: FactGroup_subset (*‹⟦?g ∈ carrier G; ?g' ∈ carrier G; h ?g = h ?g'⟧ ⟹ kernel G H h #> ?g ⊆ kernel G H h #> ?g'›*) h (*‹h g = h g'›*) gX (*‹g ∈ carrier G› ‹g' ∈ carrier G› ‹X = kernel G H h #> g› ‹X' = kernel G H h #> g'›*)) (*proven 2 subgoals*) . qed text‹If the homomorphism \<^term>‹h› is onto \<^term>‹H›, then so is the homomorphism from the quotient group› lemma (in group_hom) FactGroup_onto: assumes h: "h ` carrier G = carrier H" shows "(λX. the_elem (h ` X)) ` carrier (G Mod kernel G H h) = carrier H" proof (standard) (*goals: 1. ‹(λX. the_elem (h ` X)) ` carrier (G Mod kernel G H h) ⊆ carrier H› 2. ‹carrier H ⊆ (λX. the_elem (h ` X)) ` carrier (G Mod kernel G H h)›*) show "(λX. the_elem (h ` X)) ` carrier (G Mod kernel G H h) ⊆ carrier H" by (auto simp add: FactGroup_the_elem_mem (*‹?X ∈ carrier (G Mod kernel G H h) ⟹ the_elem (h ` ?X) ∈ carrier H›*)) show "carrier H ⊆ (λX. the_elem (h ` X)) ` carrier (G Mod kernel G H h)" proof (standard) (*goal: ‹⋀x. x ∈ carrier H ⟹ x ∈ (λX. the_elem (h ` X)) ` carrier (G Mod kernel G H h)›*) fix y assume y: "y ∈ carrier H" (*‹(y::'c) ∈ carrier (H::('c, 'd) monoid_scheme)›*) with h (*‹h ` carrier G = carrier H›*) obtain g where g: "g ∈ carrier G" "h g = y" (*goal: ‹(⋀g. ⟦g ∈ carrier G; h g = y⟧ ⟹ thesis) ⟹ thesis›*) by (blast elim: equalityE (*‹⟦?A = ?B; ⟦?A ⊆ ?B; ?B ⊆ ?A⟧ ⟹ ?P⟧ ⟹ ?P›*)) hence "(⋃x∈kernel G H h #> g. {h x}) = {y}" by (auto simp add: y (*‹(y::'c::type) ∈ carrier (H::('c, 'd) monoid_scheme)›*) kernel_def (*‹kernel (?G::(?'a, ?'m) monoid_scheme) (?H::(?'b, ?'n) monoid_scheme) (?h::?'a::type ⇒ ?'b::type) = {x::?'a::type ∈ carrier ?G. ?h x = 𝟭⇘?H⇙}›*) r_coset_def (*‹(?H::?'a::type set) #>⇘?G::(?'a, ?'b) monoid_scheme⇙ (?a::?'a::type) = (⋃h::?'a::type∈?H. {h ⊗⇘?G⇙ ?a})›*)) with g (*‹(g::'a) ∈ carrier G› ‹h g = y›*) show "y ∈ (λX. the_elem (h ` X)) ` carrier (G Mod kernel G H h)" apply (auto intro!: bexI (*‹⟦?P ?x; ?x ∈ ?A⟧ ⟹ ∃x∈?A. ?P x›*) image_eqI (*‹⟦?b = ?f ?x; ?x ∈ ?A⟧ ⟹ ?b ∈ ?f ` ?A›*) simp add: FactGroup_def (*‹?G Mod ?H = ⦇carrier = rcosets⇘?G⇙ ?H, mult = (<#>⇘?G⇙), one = ?H⦈›*) RCOSETS_def (*‹rcosets⇘?G⇙ ?H = (⋃a∈carrier ?G. {?H #>⇘?G⇙ a})›*)) (*goal: ‹y ∈ (λX. the_elem (h ` X)) ` carrier (G Mod kernel G H h)›*) apply (subst the_elem_image_unique (*‹⟦?A ≠ {}; ⋀y. y ∈ ?A ⟹ ?f y = ?f ?x⟧ ⟹ the_elem (?f ` ?A) = ?f ?x›*)) (*goals: 1. ‹⟦g ∈ carrier G; (⋃x∈kernel G H h #> g. {h x}) = {h g}; y = h g⟧ ⟹ kernel G H h #> g ≠ {}› 2. ‹⋀ya. ⟦g ∈ carrier G; (⋃x∈kernel G H h #> g. {h x}) = {h g}; y = h g; ya ∈ kernel G H h #> g⟧ ⟹ h ya = h ?x29› 3. ‹⟦g ∈ carrier G; (⋃x∈kernel G H h #> g. {h x}) = {h g}; y = h g⟧ ⟹ h g = h ?x29› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . qed qed text‹If \<^term>‹h› is a homomorphism from \<^term>‹G› onto \<^term>‹H›, then the quotient group \<^term>‹G Mod (kernel G H h)› is isomorphic to \<^term>‹H›.› theorem (in group_hom) FactGroup_iso_set: "h ` carrier G = carrier H ⟹ (λX. the_elem (h`X)) ∈ iso (G Mod (kernel G H h)) H" by (simp add: iso_def (*‹Group.iso (?G::(?'a, ?'c) monoid_scheme) (?H::(?'b, ?'d) monoid_scheme) = {h::?'a ⇒ ?'b ∈ hom ?G ?H. bij_betw h (carrier ?G) (carrier ?H)}›*) FactGroup_hom (*‹(λX::'a set. the_elem ((h::'a ⇒ 'c) ` X)) ∈ hom (G Mod kernel G (H::('c, 'd) monoid_scheme) h) H›*) FactGroup_inj_on (*‹inj_on (λX::'a set. the_elem ((h::'a ⇒ 'c) ` X)) (carrier (G Mod kernel G (H::('c, 'd) monoid_scheme) h))›*) bij_betw_def (*‹bij_betw (?f::?'a ⇒ ?'b) (?A::?'a set) (?B::?'b set) = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*) FactGroup_onto (*‹(h::'a ⇒ 'c) ` carrier G = carrier (H::('c, 'd) monoid_scheme) ⟹ (λX::'a set. the_elem (h ` X)) ` carrier (G Mod kernel G H h) = carrier H›*)) corollary (in group_hom) FactGroup_iso : "h ` carrier G = carrier H ⟹ (G Mod (kernel G H h))≅ H" using FactGroup_iso_set (*‹h ` carrier G = carrier H ⟹ (λX. the_elem (h ` X)) ∈ Group.iso (G Mod kernel G H h) H›*) unfolding is_iso_def (*goal: ‹h ` carrier G = carrier H ⟹ Group.iso (G Mod kernel G H h) H ≠ {}›*) by auto lemma (in group_hom) trivial_hom_iff: ✐‹contributor ‹Paulo Emílio de Vilhena›› "h ` (carrier G) = { 𝟭⇘H⇙ } ⟷ kernel G H h = carrier G" unfolding kernel_def (*goal: ‹(h ` carrier G = {𝟭⇘H⇙}) = ({x ∈ carrier G. h x = 𝟭⇘H⇙} = carrier G)›*) using one_closed (*‹(h::'a ⇒ 'c) 𝟭 ∈ carrier (H::('c, 'd) monoid_scheme)›*) by force lemma (in group_hom) trivial_ker_imp_inj: ✐‹contributor ‹Paulo Emílio de Vilhena›› assumes "kernel G H h = { 𝟭 }" shows "inj_on h (carrier G)" proof (rule inj_onI (*‹(⋀x y. ⟦x ∈ ?A; y ∈ ?A; ?f x = ?f y⟧ ⟹ x = y) ⟹ inj_on ?f ?A›*)) (*goal: ‹⋀x y. ⟦x ∈ carrier G; y ∈ carrier G; h x = h y⟧ ⟹ x = y›*) fix g1 and g2 assume A: "g1 ∈ carrier G" "g2 ∈ carrier G" "h g1 = h g2" (*‹(g1::'a) ∈ carrier G› ‹(g2::'a) ∈ carrier G› ‹(h::'a ⇒ 'c) (g1::'a) = h (g2::'a)›*) hence "h (g1 ⊗ (inv g2)) = 𝟭⇘H⇙" by simp hence "g1 ⊗ (inv g2) = 𝟭" using A (*‹g1 ∈ carrier G› ‹g2 ∈ carrier G› ‹h g1 = h g2›*) assms (*‹kernel G (H::('c, 'd) monoid_scheme) (h::'a::type ⇒ 'c::type) = {𝟭}›*) unfolding kernel_def (*goal: ‹g1 ⊗ inv g2 = 𝟭›*) by blast thus "g1 = g2" using A (*‹(g1::'a) ∈ carrier G› ‹g2 ∈ carrier G› ‹h g1 = h g2›*) G.inv_equality (*‹⟦?y ⊗ ?x = 𝟭; ?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ inv ?x = ?y›*) G.inv_inv (*‹(?x::'a) ∈ carrier G ⟹ inv (inv ?x) = ?x›*) by blast qed lemma (in group_hom) inj_iff_trivial_ker: shows "inj_on h (carrier G) ⟷ kernel G H h = { 𝟭 }" proof (standard) (*goals: 1. ‹inj_on h (carrier G) ⟹ kernel G H h = {𝟭}› 2. ‹kernel G H h = {𝟭} ⟹ inj_on h (carrier G)›*) assume inj: "inj_on h (carrier G)" (*‹inj_on (h::'a ⇒ 'c) (carrier G)›*) show "kernel G H h = { 𝟭 }" unfolding kernel_def (*goal: ‹{x::'a::type ∈ carrier G. (h::'a::type ⇒ 'c::type) x = 𝟭⇘H::('c, 'd) monoid_scheme⇙} = {𝟭}›*) proof (auto) (*goal: ‹⋀x. ⟦x ∈ carrier G; h x = 𝟭⇘H⇙⟧ ⟹ x = 𝟭›*) fix a assume "a ∈ carrier G" "h a = 𝟭⇘H⇙" (*‹(a::'a) ∈ carrier G› ‹(h::'a ⇒ 'c) (a::'a) = 𝟭⇘H::('c, 'd) monoid_scheme⇙›*) thus "a = 𝟭" using inj (*‹inj_on h (carrier G)›*) hom_one (*‹(h::'a ⇒ 'c) 𝟭 = 𝟭⇘H::('c, 'd) monoid_scheme⇙›*) unfolding inj_on_def (*goal: ‹(a::'a) = 𝟭›*) by force qed next (*goal: ‹kernel G H h = {𝟭} ⟹ inj_on h (carrier G)›*) show "kernel G H h = { 𝟭 } ⟹ inj_on h (carrier G)" using trivial_ker_imp_inj (*‹kernel G H h = {𝟭} ⟹ inj_on h (carrier G)›*) by simp qed lemma (in group_hom) induced_group_hom': assumes "subgroup I G" shows "group_hom (G ⦇ carrier := I ⦈) H h" proof (-) (*goal: ‹group_hom (G⦇carrier := I::'a::type set⦈) (H::('c, 'd) monoid_scheme) (h::'a::type ⇒ 'c::type)›*) have "h ∈ hom (G ⦇ carrier := I ⦈) H" using homh (*‹h ∈ hom G H›*) subgroup.subset[OF assms] (*‹I ⊆ carrier G›*) unfolding hom_def (*goal: ‹h ∈ {h ∈ carrier (G⦇carrier := I⦈) → carrier H. ∀x∈carrier (G⦇carrier := I⦈). ∀y∈carrier (G⦇carrier := I⦈). h (x ⊗⇘G⦇carrier := I⦈⇙ y) = h x ⊗⇘H⇙ h y}›*) apply auto (*goal: ‹h ∈ {h ∈ carrier (G⦇carrier := I⦈) → carrier H. ∀x∈carrier (G⦇carrier := I⦈). ∀y∈carrier (G⦇carrier := I⦈). h (x ⊗⇘G⦇carrier := I⦈⇙ y) = h x ⊗⇘H⇙ h y}›*) by (meson hom_mult (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ h (?x ⊗ ?y) = h ?x ⊗⇘H⇙ h ?y›*) subsetCE (*‹⟦?A ⊆ ?B; ?c ∉ ?A ⟹ ?P; ?c ∈ ?B ⟹ ?P⟧ ⟹ ?P›*)) thus "?thesis" (*goal: ‹group_hom (G⦇carrier := I⦈) H h›*) using subgroup.subgroup_is_group[OF assms G.group_axioms] (*‹Group.group (G⦇carrier := I⦈)›*) group_axioms (*‹Group.group H›*) unfolding group_hom_def group_hom_axioms_def (*goal: ‹Group.group (G⦇carrier := I⦈) ∧ Group.group H ∧ h ∈ hom (G⦇carrier := I⦈) H›*) by auto qed lemma (in group_hom) inj_on_subgroup_iff_trivial_ker: assumes "subgroup I G" shows "inj_on h I ⟷ kernel (G ⦇ carrier := I ⦈) H h = { 𝟭 }" using group_hom.inj_iff_trivial_ker[OF induced_group_hom' [ OF assms ]] (*‹inj_on h (carrier (G⦇carrier := I⦈)) = (kernel (G⦇carrier := I⦈) H h = {𝟭⇘G⦇carrier := I⦈⇙})›*) by simp lemma set_mult_hom: assumes "h ∈ hom G H" "I ⊆ carrier G" and "J ⊆ carrier G" shows "h ` (I <#>⇘G⇙ J) = (h ` I) <#>⇘H⇙ (h ` J)" proof (standard) (*goals: 1. ‹h ` (I <#>⇘G⇙ J) ⊆ h ` I <#>⇘H⇙ h ` J› 2. ‹h ` I <#>⇘H⇙ h ` J ⊆ h ` (I <#>⇘G⇙ J)›*) show "h ` (I <#>⇘G⇙ J) ⊆ (h ` I) <#>⇘H⇙ (h ` J)" proof (standard) (*goal: ‹⋀x. x ∈ h ` (I <#>⇘G⇙ J) ⟹ x ∈ h ` I <#>⇘H⇙ h ` J›*) fix a assume "a ∈ h ` (I <#>⇘G⇙ J)" (*‹(a::'b) ∈ (h::'a ⇒ 'b) ` ((I::'a set) <#>⇘G::('a, 'c) monoid_scheme⇙ (J::'a set))›*) then obtain i and j where i: "i ∈ I" and j: "j ∈ J" and "a = h (i ⊗⇘G⇙ j)" (*goal: ‹(⋀i j. ⟦i ∈ I; j ∈ J; a = h (i ⊗⇘G⇙ j)⟧ ⟹ thesis) ⟹ thesis›*) unfolding set_mult_def (*goal: ‹(⋀i j. ⟦i ∈ I; j ∈ J; a = h (i ⊗⇘G⇙ j)⟧ ⟹ thesis) ⟹ thesis›*) by auto hence "a = (h i) ⊗⇘H⇙ (h j)" using assms (*‹(h::'a ⇒ 'b) ∈ hom (G::('a, 'c) monoid_scheme) (H::('b, 'd) monoid_scheme)› ‹I ⊆ carrier G› ‹(J::'a set) ⊆ carrier (G::('a, 'c) monoid_scheme)›*) unfolding hom_def (*goal: ‹a = h i ⊗⇘H⇙ h j›*) by blast thus "a ∈ (h ` I) <#>⇘H⇙ (h ` J)" using i (*‹i ∈ I›*) j (*‹j ∈ J›*) unfolding set_mult_def (*goal: ‹a ∈ (⋃ha∈h ` I. ⋃k∈h ` J. {ha ⊗⇘H⇙ k})›*) by auto qed next (*goal: ‹h ` I <#>⇘H⇙ h ` J ⊆ h ` (I <#>⇘G⇙ J)›*) show "(h ` I) <#>⇘H⇙ (h ` J) ⊆ h ` (I <#>⇘G⇙ J)" proof (standard) (*goal: ‹⋀x. x ∈ h ` I <#>⇘H⇙ h ` J ⟹ x ∈ h ` (I <#>⇘G⇙ J)›*) fix a assume "a ∈ (h ` I) <#>⇘H⇙ (h ` J)" (*‹(a::'b) ∈ (h::'a ⇒ 'b) ` (I::'a set) <#>⇘H::('b, 'd) monoid_scheme⇙ h ` (J::'a set)›*) then obtain i and j where i: "i ∈ I" and j: "j ∈ J" and "a = (h i) ⊗⇘H⇙ (h j)" (*goal: ‹(⋀i j. ⟦i ∈ I; j ∈ J; a = h i ⊗⇘H⇙ h j⟧ ⟹ thesis) ⟹ thesis›*) unfolding set_mult_def (*goal: ‹(⋀i j. ⟦i ∈ I; j ∈ J; a = h i ⊗⇘H⇙ h j⟧ ⟹ thesis) ⟹ thesis›*) by auto hence "a = h (i ⊗⇘G⇙ j)" using assms (*‹h ∈ hom G H› ‹I ⊆ carrier G› ‹J ⊆ carrier G›*) unfolding hom_def (*goal: ‹a = h (i ⊗⇘G⇙ j)›*) by fastforce thus "a ∈ h ` (I <#>⇘G⇙ J)" using i (*‹i ∈ I›*) j (*‹j ∈ J›*) unfolding set_mult_def (*goal: ‹(a::'b) ∈ (h::'a ⇒ 'b) ` (⋃h::'a∈I::'a set. ⋃k::'a∈J::'a set. {h ⊗⇘G::('a, 'c) monoid_scheme⇙ k})›*) by auto qed qed corollary coset_hom: assumes "h ∈ hom G H" "I ⊆ carrier G" "a ∈ carrier G" shows "h ` (a <#⇘G⇙ I) = h a <#⇘H⇙ (h ` I)" and "h ` (I #>⇘G⇙ a) = (h ` I) #>⇘H⇙ h a" unfolding l_coset_eq_set_mult r_coset_eq_set_mult (*goals: 1. ‹h ` ({a} <#>⇘G⇙ I) = {h a} <#>⇘H⇙ h ` I› 2. ‹h ` (I <#>⇘G⇙ {a}) = h ` I <#>⇘H⇙ {h a}›*) using assms (*‹h ∈ hom G H› ‹I ⊆ carrier G› ‹a ∈ carrier G›*) set_mult_hom[OF assms ( 1 )] (*‹⟦?I ⊆ carrier G; ?J ⊆ carrier G⟧ ⟹ h ` (?I <#>⇘G⇙ ?J) = h ` ?I <#>⇘H⇙ h ` ?J›*) apply - (*goals: 1. ‹⟦(h::'a ⇒ 'b) ∈ hom (G::('a, 'c) monoid_scheme) (H::('b, 'd) monoid_scheme); (I::'a set) ⊆ carrier G; (a::'a) ∈ carrier G; ⋀(I::'a set) J::'a set. ⟦I ⊆ carrier G; J ⊆ carrier G⟧ ⟹ h ` (I <#>⇘G⇙ J) = h ` I <#>⇘H⇙ h ` J⟧ ⟹ h ` ({a} <#>⇘G⇙ I) = {h a} <#>⇘H⇙ h ` I› 2. ‹⟦(h::'a ⇒ 'b) ∈ hom (G::('a, 'c) monoid_scheme) (H::('b, 'd) monoid_scheme); (I::'a set) ⊆ carrier G; (a::'a) ∈ carrier G; ⋀(I::'a set) J::'a set. ⟦I ⊆ carrier G; J ⊆ carrier G⟧ ⟹ h ` (I <#>⇘G⇙ J) = h ` I <#>⇘H⇙ h ` J⟧ ⟹ h ` (I <#>⇘G⇙ {a}) = h ` I <#>⇘H⇙ {h a}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . corollary (in group_hom) set_mult_ker_hom: assumes "I ⊆ carrier G" shows "h ` (I <#> (kernel G H h)) = h ` I" and "h ` ((kernel G H h) <#> I) = h ` I" proof (-) (*goals: 1. ‹h ` (I <#> kernel G H h) = h ` I› 2. ‹h ` (kernel G H h <#> I) = h ` I›*) have ker_in_carrier: "kernel G H h ⊆ carrier G" unfolding kernel_def (*goal: ‹{x ∈ carrier G. h x = 𝟭⇘H⇙} ⊆ carrier G›*) by auto have "h ` (kernel G H h) = { 𝟭⇘H⇙ }" unfolding kernel_def (*goal: ‹h ` {x ∈ carrier G. h x = 𝟭⇘H⇙} = {𝟭⇘H⇙}›*) by force moreover have "h ` I ⊆ carrier H" using assms (*‹I ⊆ carrier G›*) by auto hence "(h ` I) <#>⇘H⇙ { 𝟭⇘H⇙ } = h ` I" and "{ 𝟭⇘H⇙ } <#>⇘H⇙ (h ` I) = h ` I" unfolding set_mult_def (*goals: 1. ‹(⋃h∈h ` I. ⋃k∈{𝟭⇘H⇙}. {h ⊗⇘H⇙ k}) = h ` I› 2. ‹(⋃ha∈{𝟭⇘H⇙}. ⋃k∈h ` I. {ha ⊗⇘H⇙ k}) = h ` I›*) apply - (*goals: 1. ‹(h::'a::type ⇒ 'c::type) ` (I::'a::type set) ⊆ carrier (H::('c, 'd) monoid_scheme) ⟹ (⋃h::'c::type∈h ` I. ⋃k::'c::type∈{𝟭⇘H⇙}. {h ⊗⇘H⇙ k}) = h ` I› 2. ‹(h::'a::type ⇒ 'c::type) ` (I::'a::type set) ⊆ carrier (H::('c, 'd) monoid_scheme) ⟹ (⋃ha::'c::type∈{𝟭⇘H⇙}. ⋃k::'c::type∈h ` I. {ha ⊗⇘H⇙ k}) = h ` I› discuss goal 1*) apply force (*discuss goal 2*) apply force (*proven 2 subgoals*) . ultimately show "h ` (I <#> (kernel G H h)) = h ` I" and "h ` ((kernel G H h) <#> I) = h ` I" using set_mult_hom[OF homh assms ker_in_carrier] (*‹h ` (I <#> kernel G H h) = h ` I <#>⇘H⇙ h ` kernel G H h›*) set_mult_hom[OF homh ker_in_carrier assms] (*‹h ` (kernel G H h <#> I) = h ` kernel G H h <#>⇘H⇙ h ` I›*) apply - (*goals: 1. ‹⟦h ` kernel G H h = {𝟭⇘H⇙}; h ` I <#>⇘H⇙ {𝟭⇘H⇙} = h ` I; {𝟭⇘H⇙} <#>⇘H⇙ h ` I = h ` I; h ` (I <#> kernel G H h) = h ` I <#>⇘H⇙ h ` kernel G H h; h ` (kernel G H h <#> I) = h ` kernel G H h <#>⇘H⇙ h ` I⟧ ⟹ h ` (I <#> kernel G H h) = h ` I› 2. ‹⟦h ` kernel G H h = {𝟭⇘H⇙}; h ` I <#>⇘H⇙ {𝟭⇘H⇙} = h ` I; {𝟭⇘H⇙} <#>⇘H⇙ h ` I = h ` I; h ` (I <#> kernel G H h) = h ` I <#>⇘H⇙ h ` kernel G H h; h ` (kernel G H h <#> I) = h ` kernel G H h <#>⇘H⇙ h ` I⟧ ⟹ h ` (kernel G H h <#> I) = h ` I› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . qed subsubsection‹Trivial homomorphisms› definition trivial_homomorphism where "trivial_homomorphism G H f ≡ f ∈ hom G H ∧ (∀x ∈ carrier G. f x = one H)" lemma trivial_homomorphism_kernel: "trivial_homomorphism G H f ⟷ f ∈ hom G H ∧ kernel G H f = carrier G" by (auto simp: trivial_homomorphism_def (*‹trivial_homomorphism (?G::(?'a, ?'b) monoid_scheme) (?H::(?'c, ?'d) monoid_scheme) (?f::?'a ⇒ ?'c) ≡ ?f ∈ hom ?G ?H ∧ (∀x::?'a∈carrier ?G. ?f x = 𝟭⇘?H⇙)›*) kernel_def (*‹kernel (?G::(?'a, ?'m) monoid_scheme) (?H::(?'b, ?'n) monoid_scheme) (?h::?'a ⇒ ?'b) = {x::?'a ∈ carrier ?G. ?h x = 𝟭⇘?H⇙}›*)) lemma (in group) trivial_homomorphism_image: "trivial_homomorphism G H f ⟷ f ∈ hom G H ∧ f ` carrier G = {one H}" apply (auto simp: trivial_homomorphism_def (*‹trivial_homomorphism ?G ?H ?f ≡ ?f ∈ hom ?G ?H ∧ (∀x∈carrier ?G. ?f x = 𝟭⇘?H⇙)›*)) (*goal: ‹trivial_homomorphism G H f = (f ∈ hom G H ∧ f ` carrier G = {𝟭⇘H⇙})›*) by (metis one_closed (*‹𝟭 ∈ carrier G›*) rev_image_eqI (*‹⟦?x ∈ ?A; ?b = ?f ?x⟧ ⟹ ?b ∈ ?f ` ?A›*)) subsection ‹Image kernel theorems› lemma group_Int_image_ker: assumes f: "f ∈ hom G H" and g: "g ∈ hom H K" and "inj_on (g ∘ f) (carrier G)" "group G" "group H" "group K" shows "(f ` carrier G) ∩ (kernel H K g) = {𝟭⇘H⇙}" proof (-) (*goal: ‹(f::'a ⇒ 'b) ` carrier (G::('a, 'c) monoid_scheme) ∩ kernel (H::('b, 'd) monoid_scheme) (K::('e, 'f) monoid_scheme) (g::'b ⇒ 'e) = {𝟭⇘H⇙}›*) have "(f ` carrier G) ∩ (kernel H K g) ⊆ {𝟭⇘H⇙}" using assms (*‹f ∈ hom G H› ‹g ∈ hom H K› ‹inj_on (g ∘ f) (carrier G)› ‹Group.group G› ‹Group.group H› ‹Group.group K›*) apply (clarsimp simp: kernel_def (*‹kernel ?G ?H ?h = {x ∈ carrier ?G. ?h x = 𝟭⇘?H⇙}›*) o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*)) (*goal: ‹f ` carrier G ∩ kernel H K g ⊆ {𝟭⇘H⇙}›*) by (metis group.is_monoid (*‹Group.group ?G ⟹ Group.monoid ?G›*) hom_one (*‹⟦?h ∈ hom ?G ?H; Group.group ?G; Group.group ?H⟧ ⟹ ?h 𝟭⇘?G⇙ = 𝟭⇘?H⇙›*) inj_on_eq_iff (*‹⟦inj_on ?f ?A; ?x ∈ ?A; ?y ∈ ?A⟧ ⟹ (?f ?x = ?f ?y) = (?x = ?y)›*) monoid.one_closed (*‹Group.monoid ?G ⟹ 𝟭⇘?G⇙ ∈ carrier ?G›*)) moreover have "one H ∈ f ` carrier G" by (metis f (*‹f ∈ hom G H›*) ‹group G› ‹group H› group.is_monoid (*‹Group.group ?G ⟹ Group.monoid ?G›*) hom_one (*‹⟦?h ∈ hom ?G ?H; Group.group ?G; Group.group ?H⟧ ⟹ ?h 𝟭⇘?G⇙ = 𝟭⇘?H⇙›*) image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*) monoid.one_closed (*‹Group.monoid ?G ⟹ 𝟭⇘?G⇙ ∈ carrier ?G›*)) moreover have "one H ∈ kernel H K g" unfolding kernel_def (*goal: ‹𝟭⇘H⇙ ∈ {x ∈ carrier H. g x = 𝟭⇘K⇙}›*) using Group.group_def (*‹Group.group (?G::(?'a, ?'b) monoid_scheme) ≡ Group.monoid ?G ∧ Group.group_axioms ?G›*) ‹group H› (*‹Group.group (H::('b, 'd) monoid_scheme)›*) ‹group K› (*‹Group.group K›*) g (*‹g ∈ hom H K›*) hom_one (*‹⟦(?h::?'a ⇒ ?'b) ∈ hom (?G::(?'a, ?'c) monoid_scheme) (?H::(?'b, ?'d) monoid_scheme); Group.group ?G; Group.group ?H⟧ ⟹ ?h 𝟭⇘?G⇙ = 𝟭⇘?H⇙›*) by blast ultimately show "?thesis" (*goal: ‹f ` carrier G ∩ kernel H K g = {𝟭⇘H⇙}›*) by blast qed lemma group_sum_image_ker: assumes f: "f ∈ hom G H" and g: "g ∈ hom H K" and eq: "(g ∘ f) ` (carrier G) = carrier K" and "group G" "group H" "group K" shows "set_mult H (f ` carrier G) (kernel H K g) = carrier H" (is "?lhs = ?rhs") proof (standard) (*goals: 1. ‹f ` carrier G <#>⇘H⇙ kernel H K g ⊆ carrier H› 2. ‹carrier H ⊆ f ` carrier G <#>⇘H⇙ kernel H K g›*) show "?lhs ⊆ ?rhs" apply (clarsimp simp: kernel_def (*‹kernel ?G ?H ?h = {x ∈ carrier ?G. ?h x = 𝟭⇘?H⇙}›*) set_mult_def (*‹?H <#>⇘?G⇙ ?K = (⋃h∈?H. ⋃k∈?K. {h ⊗⇘?G⇙ k})›*)) (*goal: ‹f ` carrier G <#>⇘H⇙ kernel H K g ⊆ carrier H›*) by (meson ‹group H› f (*‹f ∈ hom G H›*) group.is_monoid (*‹Group.group ?G ⟹ Group.monoid ?G›*) hom_in_carrier (*‹⟦?h ∈ hom ?G ?H; ?x ∈ carrier ?G⟧ ⟹ ?h ?x ∈ carrier ?H›*) monoid.m_closed (*‹⟦Group.monoid ?G; ?x ∈ carrier ?G; ?y ∈ carrier ?G⟧ ⟹ ?x ⊗⇘?G⇙ ?y ∈ carrier ?G›*)) have "∃x∈carrier G. ∃z. z ∈ carrier H ∧ g z = 𝟭⇘K⇙ ∧ y = f x ⊗⇘H⇙ z" if y: "y ∈ carrier H" for y proof (-) (*goal: ‹∃x∈carrier G. ∃z. z ∈ carrier H ∧ g z = 𝟭⇘K⇙ ∧ y = f x ⊗⇘H⇙ z›*) have "g y ∈ carrier K" using g (*‹g ∈ hom H K›*) hom_carrier (*‹?h ∈ hom ?G ?H ⟹ ?h ` carrier ?G ⊆ carrier ?H›*) that (*‹y ∈ carrier H›*) by blast with assms (*‹f ∈ hom G H› ‹(g::'b::type ⇒ 'e::type) ∈ hom (H::('b, 'd) monoid_scheme) (K::('e, 'f) monoid_scheme)› ‹(g ∘ f) ` carrier G = carrier K› ‹Group.group G› ‹Group.group H› ‹Group.group K›*) obtain x where x: "x ∈ carrier G" "(g ∘ f) x = g y" (*goal: ‹(⋀x::'a. ⟦x ∈ carrier (G::('a, 'c) monoid_scheme); ((g::'b ⇒ 'e) ∘ (f::'a ⇒ 'b)) x = g (y::'b)⟧ ⟹ thesis::bool) ⟹ thesis›*) by (metis image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*)) with assms (*‹f ∈ hom G H› ‹(g::'b ⇒ 'e) ∈ hom (H::('b, 'd) monoid_scheme) (K::('e, 'f) monoid_scheme)› ‹((g::'b ⇒ 'e) ∘ (f::'a ⇒ 'b)) ` carrier (G::('a, 'c) monoid_scheme) = carrier (K::('e, 'f) monoid_scheme)› ‹Group.group G› ‹Group.group H› ‹Group.group K›*) have invf: "inv⇘H⇙ f x ⊗⇘H⇙ y ∈ carrier H" by (metis group.subgroup_self (*‹Group.group ?G ⟹ subgroup (carrier ?G) ?G›*) hom_carrier (*‹?h ∈ hom ?G ?H ⟹ ?h ` carrier ?G ⊆ carrier ?H›*) image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*) subgroup_def (*‹subgroup ?H ?G ≡ (?H ⊆ carrier ?G ∧ (∀x y. x ∈ ?H ⟶ y ∈ ?H ⟶ x ⊗⇘?G⇙ y ∈ ?H)) ∧ 𝟭⇘?G⇙ ∈ ?H ∧ (∀x. x ∈ ?H ⟶ inv⇘?G⇙ x ∈ ?H)›*) y (*‹y ∈ carrier H›*)) moreover have "g (inv⇘H⇙ f x ⊗⇘H⇙ y) = 𝟭⇘K⇙" proof (-) (*goal: ‹(g::'b ⇒ 'e) (inv⇘H⇙ (f::'a ⇒ 'b) (x::'a) ⊗⇘H::('b, 'd) monoid_scheme⇙ (y::'b)) = 𝟭⇘K::('e, 'f) monoid_scheme⇙›*) have "inv⇘H⇙ f x ∈ carrier H" by (meson ‹group H› f (*‹f ∈ hom G H›*) group.inv_closed (*‹⟦Group.group ?G; ?x ∈ carrier ?G⟧ ⟹ inv⇘?G⇙ ?x ∈ carrier ?G›*) hom_carrier (*‹?h ∈ hom ?G ?H ⟹ ?h ` carrier ?G ⊆ carrier ?H›*) image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*) x( (*‹x ∈ carrier G›*) 1)) then have "g (inv⇘H⇙ f x ⊗⇘H⇙ y) = g (inv⇘H⇙ f x) ⊗⇘K⇙ g y" by (simp add: hom_mult [OF g] (*‹⟦?x ∈ carrier H; ?y ∈ carrier H⟧ ⟹ g (?x ⊗⇘H⇙ ?y) = g ?x ⊗⇘K⇙ g ?y›*) y (*‹y ∈ carrier H›*)) also (*calculation: ‹g (inv⇘H⇙ f x ⊗⇘H⇙ y) = g (inv⇘H⇙ f x) ⊗⇘K⇙ g y›*) have "… = inv⇘K⇙ (g (f x)) ⊗⇘K⇙ g y" using assms (*‹f ∈ hom G H› ‹(g::'b::type ⇒ 'e::type) ∈ hom (H::('b, 'd) monoid_scheme) (K::('e, 'f) monoid_scheme)› ‹((g::'b::type ⇒ 'e::type) ∘ (f::'a::type ⇒ 'b::type)) ` carrier (G::('a, 'c) monoid_scheme) = carrier (K::('e, 'f) monoid_scheme)› ‹Group.group G› ‹Group.group H› ‹Group.group K›*) x(1) (*‹(x::'a::type) ∈ carrier (G::('a, 'c) monoid_scheme)›*) by (metis (mono_tags, lifting) group_hom.hom_inv (*‹⟦group_hom ?G ?H ?h; ?x ∈ carrier ?G⟧ ⟹ ?h (inv⇘?G⇙ ?x) = inv⇘?H⇙ ?h ?x›*) group_hom.intro (*‹⟦Group.group ?G; Group.group ?H; group_hom_axioms ?G ?H ?h⟧ ⟹ group_hom ?G ?H ?h›*) group_hom_axioms.intro (*‹?h ∈ hom ?G ?H ⟹ group_hom_axioms ?G ?H ?h›*) hom_carrier (*‹?h ∈ hom ?G ?H ⟹ ?h ` carrier ?G ⊆ carrier ?H›*) image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*)) also (*calculation: ‹g (inv⇘H⇙ f x ⊗⇘H⇙ y) = inv⇘K⇙ g (f x) ⊗⇘K⇙ g y›*) have "… = 𝟭⇘K⇙" using ‹g y ∈ carrier K› (*‹g y ∈ carrier K›*) assms(6) (*‹Group.group K›*) group.l_inv (*‹⟦Group.group ?G; ?x ∈ carrier ?G⟧ ⟹ inv⇘?G⇙ ?x ⊗⇘?G⇙ ?x = 𝟭⇘?G⇙›*) x(2) (*‹(g ∘ f) x = g y›*) by fastforce finally (*calculation: ‹g (inv⇘H⇙ f x ⊗⇘H⇙ y) = 𝟭⇘K⇙›*) show "?thesis" (*goal: ‹g (inv⇘H⇙ f x ⊗⇘H⇙ y) = 𝟭⇘K⇙›*) . qed moreover have "y = f x ⊗⇘H⇙ (inv⇘H⇙ f x ⊗⇘H⇙ y)" using x (*‹(x::'a) ∈ carrier (G::('a, 'c) monoid_scheme)› ‹(g ∘ f) x = g y›*) y (*‹y ∈ carrier H›*) by (meson ‹group H› invf (*‹inv⇘H⇙ f x ⊗⇘H⇙ y ∈ carrier H›*) f (*‹f ∈ hom G H›*) group.inv_solve_left' (*‹⟦Group.group ?G; ?a ∈ carrier ?G; ?b ∈ carrier ?G; ?c ∈ carrier ?G⟧ ⟹ (inv⇘?G⇙ ?b ⊗⇘?G⇙ ?c = ?a) = (?c = ?b ⊗⇘?G⇙ ?a)›*) hom_in_carrier (*‹⟦?h ∈ hom ?G ?H; ?x ∈ carrier ?G⟧ ⟹ ?h ?x ∈ carrier ?H›*)) ultimately show "?thesis" (*goal: ‹∃x∈carrier G. ∃z. z ∈ carrier H ∧ g z = 𝟭⇘K⇙ ∧ y = f x ⊗⇘H⇙ z›*) using x (*‹x ∈ carrier G› ‹((g::'b ⇒ 'e) ∘ (f::'a ⇒ 'b)) (x::'a) = g (y::'b)›*) y (*‹y ∈ carrier H›*) by force qed then show "?rhs ⊆ ?lhs" by (auto simp: kernel_def (*‹kernel ?G ?H ?h = {x ∈ carrier ?G. ?h x = 𝟭⇘?H⇙}›*) set_mult_def (*‹?H <#>⇘?G⇙ ?K = (⋃h∈?H. ⋃k∈?K. {h ⊗⇘?G⇙ k})›*)) qed lemma group_sum_ker_image: assumes f: "f ∈ hom G H" and g: "g ∈ hom H K" and eq: "(g ∘ f) ` (carrier G) = carrier K" and "group G" "group H" "group K" shows "set_mult H (kernel H K g) (f ` carrier G) = carrier H" (is "?lhs = ?rhs") proof (standard) (*goals: 1. ‹kernel H K g <#>⇘H⇙ f ` carrier G ⊆ carrier H› 2. ‹carrier H ⊆ kernel H K g <#>⇘H⇙ f ` carrier G›*) show "?lhs ⊆ ?rhs" apply (clarsimp simp: kernel_def (*‹kernel ?G ?H ?h = {x ∈ carrier ?G. ?h x = 𝟭⇘?H⇙}›*) set_mult_def (*‹?H <#>⇘?G⇙ ?K = (⋃h∈?H. ⋃k∈?K. {h ⊗⇘?G⇙ k})›*)) (*goal: ‹kernel H K g <#>⇘H⇙ f ` carrier G ⊆ carrier H›*) by (meson ‹group H› f (*‹f ∈ hom G H›*) group.is_monoid (*‹Group.group ?G ⟹ Group.monoid ?G›*) hom_in_carrier (*‹⟦?h ∈ hom ?G ?H; ?x ∈ carrier ?G⟧ ⟹ ?h ?x ∈ carrier ?H›*) monoid.m_closed (*‹⟦Group.monoid ?G; ?x ∈ carrier ?G; ?y ∈ carrier ?G⟧ ⟹ ?x ⊗⇘?G⇙ ?y ∈ carrier ?G›*)) have "∃w∈carrier H. ∃x ∈ carrier G. g w = 𝟭⇘K⇙ ∧ y = w ⊗⇘H⇙ f x" if y: "y ∈ carrier H" for y proof (-) (*goal: ‹∃w∈carrier H. ∃x∈carrier G. g w = 𝟭⇘K⇙ ∧ y = w ⊗⇘H⇙ f x›*) have "g y ∈ carrier K" using g (*‹g ∈ hom H K›*) hom_carrier (*‹?h ∈ hom ?G ?H ⟹ ?h ` carrier ?G ⊆ carrier ?H›*) that (*‹y ∈ carrier H›*) by blast with assms (*‹f ∈ hom G H› ‹g ∈ hom H K› ‹(g ∘ f) ` carrier G = carrier K› ‹Group.group G› ‹Group.group H› ‹Group.group K›*) obtain x where x: "x ∈ carrier G" "(g ∘ f) x = g y" (*goal: ‹(⋀x. ⟦x ∈ carrier G; (g ∘ f) x = g y⟧ ⟹ thesis) ⟹ thesis›*) by (metis image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*)) with assms (*‹(f::'a ⇒ 'b) ∈ hom (G::('a, 'c) monoid_scheme) (H::('b, 'd) monoid_scheme)› ‹g ∈ hom H K› ‹((g::'b ⇒ 'e) ∘ (f::'a ⇒ 'b)) ` carrier (G::('a, 'c) monoid_scheme) = carrier (K::('e, 'f) monoid_scheme)› ‹Group.group G› ‹Group.group H› ‹Group.group K›*) have carr: "(y ⊗⇘H⇙ inv⇘H⇙ f x) ∈ carrier H" by (metis group.subgroup_self (*‹Group.group ?G ⟹ subgroup (carrier ?G) ?G›*) hom_carrier (*‹?h ∈ hom ?G ?H ⟹ ?h ` carrier ?G ⊆ carrier ?H›*) image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*) subgroup_def (*‹subgroup ?H ?G ≡ (?H ⊆ carrier ?G ∧ (∀x y. x ∈ ?H ⟶ y ∈ ?H ⟶ x ⊗⇘?G⇙ y ∈ ?H)) ∧ 𝟭⇘?G⇙ ∈ ?H ∧ (∀x. x ∈ ?H ⟶ inv⇘?G⇙ x ∈ ?H)›*) y (*‹y ∈ carrier H›*)) moreover have "g (y ⊗⇘H⇙ inv⇘H⇙ f x) = 𝟭⇘K⇙" proof (-) (*goal: ‹g (y ⊗⇘H⇙ inv⇘H⇙ f x) = 𝟭⇘K⇙›*) have "inv⇘H⇙ f x ∈ carrier H" by (meson ‹group H› f (*‹(f::'a::type ⇒ 'b::type) ∈ hom (G::('a, 'c) monoid_scheme) (H::('b, 'd) monoid_scheme)›*) group.inv_closed (*‹⟦Group.group (?G::(?'a, ?'b) monoid_scheme); (?x::?'a::type) ∈ carrier ?G⟧ ⟹ inv⇘?G⇙ ?x ∈ carrier ?G›*) hom_carrier (*‹(?h::?'a::type ⇒ ?'b::type) ∈ hom (?G::(?'a, ?'c) monoid_scheme) (?H::(?'b, ?'d) monoid_scheme) ⟹ ?h ` carrier ?G ⊆ carrier ?H›*) image_subset_iff (*‹((?f::?'b::type ⇒ ?'a::type) ` (?A::?'b::type set) ⊆ (?B::?'a::type set)) = (∀x::?'b::type∈?A. ?f x ∈ ?B)›*) x( (*‹(x::'a::type) ∈ carrier (G::('a, 'c) monoid_scheme)›*) 1)) then have "g (y ⊗⇘H⇙ inv⇘H⇙ f x) = g y ⊗⇘K⇙ g (inv⇘H⇙ f x)" by (simp add: hom_mult [OF g] (*‹⟦?x ∈ carrier H; ?y ∈ carrier H⟧ ⟹ g (?x ⊗⇘H⇙ ?y) = g ?x ⊗⇘K⇙ g ?y›*) y (*‹y ∈ carrier H›*)) also (*calculation: ‹g (y ⊗⇘H⇙ inv⇘H⇙ f x) = g y ⊗⇘K⇙ g (inv⇘H⇙ f x)›*) have "… = g y ⊗⇘K⇙ inv⇘K⇙ (g (f x))" using assms (*‹f ∈ hom G H› ‹g ∈ hom H K› ‹(g ∘ f) ` carrier G = carrier K› ‹Group.group G› ‹Group.group H› ‹Group.group K›*) x(1) (*‹x ∈ carrier G›*) by (metis group_hom.hom_inv (*‹⟦group_hom ?G ?H ?h; ?x ∈ carrier ?G⟧ ⟹ ?h (inv⇘?G⇙ ?x) = inv⇘?H⇙ ?h ?x›*) group_hom_axioms.intro (*‹?h ∈ hom ?G ?H ⟹ group_hom_axioms ?G ?H ?h›*) group_hom_def (*‹group_hom ?G ?H ?h ≡ Group.group ?G ∧ Group.group ?H ∧ group_hom_axioms ?G ?H ?h›*) hom_in_carrier (*‹⟦?h ∈ hom ?G ?H; ?x ∈ carrier ?G⟧ ⟹ ?h ?x ∈ carrier ?H›*)) also (*calculation: ‹(g::'b::type ⇒ 'e::type) ((y::'b::type) ⊗⇘H::('b, 'd) monoid_scheme⇙ inv⇘H⇙ (f::'a::type ⇒ 'b::type) (x::'a::type)) = g y ⊗⇘K::('e, 'f) monoid_scheme⇙ inv⇘K⇙ g (f x)›*) have "… = 𝟭⇘K⇙" using ‹g y ∈ carrier K› (*‹g y ∈ carrier K›*) assms(6) (*‹Group.group K›*) group.l_inv (*‹⟦Group.group ?G; ?x ∈ carrier ?G⟧ ⟹ inv⇘?G⇙ ?x ⊗⇘?G⇙ ?x = 𝟭⇘?G⇙›*) x(2) (*‹(g ∘ f) x = g y›*) by (simp add: group.r_inv (*‹⟦Group.group ?G; ?x ∈ carrier ?G⟧ ⟹ ?x ⊗⇘?G⇙ inv⇘?G⇙ ?x = 𝟭⇘?G⇙›*)) finally (*calculation: ‹(g::'b ⇒ 'e) ((y::'b) ⊗⇘H::('b, 'd) monoid_scheme⇙ inv⇘H⇙ (f::'a ⇒ 'b) (x::'a)) = 𝟭⇘K::('e, 'f) monoid_scheme⇙›*) show "?thesis" (*goal: ‹g (y ⊗⇘H⇙ inv⇘H⇙ f x) = 𝟭⇘K⇙›*) . qed moreover have "y = (y ⊗⇘H⇙ inv⇘H⇙ f x) ⊗⇘H⇙ f x" using x (*‹x ∈ carrier G› ‹((g::'b ⇒ 'e) ∘ (f::'a ⇒ 'b)) (x::'a) = g (y::'b)›*) y (*‹y ∈ carrier H›*) by (meson ‹group H› carr (*‹y ⊗⇘H⇙ inv⇘H⇙ f x ∈ carrier H›*) f (*‹f ∈ hom G H›*) group.inv_solve_right (*‹⟦Group.group ?G; ?a ∈ carrier ?G; ?b ∈ carrier ?G; ?c ∈ carrier ?G⟧ ⟹ (?a = ?b ⊗⇘?G⇙ inv⇘?G⇙ ?c) = (?b = ?a ⊗⇘?G⇙ ?c)›*) hom_carrier (*‹?h ∈ hom ?G ?H ⟹ ?h ` carrier ?G ⊆ carrier ?H›*) image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*)) ultimately show "?thesis" (*goal: ‹∃w∈carrier H. ∃x∈carrier G. g w = 𝟭⇘K⇙ ∧ y = w ⊗⇘H⇙ f x›*) using x (*‹x ∈ carrier G› ‹(g ∘ f) x = g y›*) y (*‹y ∈ carrier H›*) by force qed then show "?rhs ⊆ ?lhs" by (force simp: kernel_def (*‹kernel ?G ?H ?h = {x ∈ carrier ?G. ?h x = 𝟭⇘?H⇙}›*) set_mult_def (*‹?H <#>⇘?G⇙ ?K = (⋃h∈?H. ⋃k∈?K. {h ⊗⇘?G⇙ k})›*)) qed lemma group_semidirect_sum_ker_image: assumes "(g ∘ f) ∈ iso G K" "f ∈ hom G H" "g ∈ hom H K" "group G" "group H" "group K" shows "(kernel H K g) ∩ (f ` carrier G) = {𝟭⇘H⇙}" "kernel H K g <#>⇘H⇙ (f ` carrier G) = carrier H" using assms (*‹(g::'c::type ⇒ 'b::type) ∘ (f::'a::type ⇒ 'c::type) ∈ Group.iso (G::('a, 'd) monoid_scheme) (K::('b, 'e) monoid_scheme)› ‹f ∈ hom G H› ‹g ∈ hom H K› ‹Group.group G› ‹Group.group H› ‹Group.group K›*) apply - (*goals: 1. ‹⟦(g::'c ⇒ 'b) ∘ (f::'a ⇒ 'c) ∈ Group.iso (G::('a, 'd) monoid_scheme) (K::('b, 'e) monoid_scheme); f ∈ hom G (H::('c, 'f) monoid_scheme); g ∈ hom H K; Group.group G; Group.group H; Group.group K⟧ ⟹ kernel H K g ∩ f ` carrier G = {𝟭⇘H⇙}› 2. ‹⟦(g::'c ⇒ 'b) ∘ (f::'a ⇒ 'c) ∈ Group.iso (G::('a, 'd) monoid_scheme) (K::('b, 'e) monoid_scheme); f ∈ hom G (H::('c, 'f) monoid_scheme); g ∈ hom H K; Group.group G; Group.group H; Group.group K⟧ ⟹ kernel H K g <#>⇘H⇙ f ` carrier G = carrier H› discuss goal 1*) apply (simp add: iso_iff_mon_epi (*‹(?f ∈ Group.iso ?G ?H) = (?f ∈ mon ?G ?H ∧ ?f ∈ epi ?G ?H)›*) group_Int_image_ker (*‹⟦?f ∈ hom ?G ?H; ?g ∈ hom ?H ?K; inj_on (?g ∘ ?f) (carrier ?G); Group.group ?G; Group.group ?H; Group.group ?K⟧ ⟹ ?f ` carrier ?G ∩ kernel ?H ?K ?g = {𝟭⇘?H⇙}›*) group_sum_ker_image (*‹⟦?f ∈ hom ?G ?H; ?g ∈ hom ?H ?K; (?g ∘ ?f) ` carrier ?G = carrier ?K; Group.group ?G; Group.group ?H; Group.group ?K⟧ ⟹ kernel ?H ?K ?g <#>⇘?H⇙ ?f ` carrier ?G = carrier ?H›*) epi_def (*‹epi ?G ?H = {f ∈ hom ?G ?H. f ` carrier ?G = carrier ?H}›*) mon_def (*‹mon ?G ?H = {f ∈ hom ?G ?H. inj_on f (carrier ?G)}›*) Int_commute [of "kernel H K g"] (*‹kernel H K g ∩ ?B = ?B ∩ kernel H K g›*)) (*discuss goal 2*) apply (simp add: iso_iff_mon_epi (*‹(?f ∈ Group.iso ?G ?H) = (?f ∈ mon ?G ?H ∧ ?f ∈ epi ?G ?H)›*) group_Int_image_ker (*‹⟦?f ∈ hom ?G ?H; ?g ∈ hom ?H ?K; inj_on (?g ∘ ?f) (carrier ?G); Group.group ?G; Group.group ?H; Group.group ?K⟧ ⟹ ?f ` carrier ?G ∩ kernel ?H ?K ?g = {𝟭⇘?H⇙}›*) group_sum_ker_image (*‹⟦?f ∈ hom ?G ?H; ?g ∈ hom ?H ?K; (?g ∘ ?f) ` carrier ?G = carrier ?K; Group.group ?G; Group.group ?H; Group.group ?K⟧ ⟹ kernel ?H ?K ?g <#>⇘?H⇙ ?f ` carrier ?G = carrier ?H›*) epi_def (*‹epi ?G ?H = {f ∈ hom ?G ?H. f ` carrier ?G = carrier ?H}›*) mon_def (*‹mon ?G ?H = {f ∈ hom ?G ?H. inj_on f (carrier ?G)}›*) Int_commute [of "kernel H K g"] (*‹kernel H K g ∩ ?B = ?B ∩ kernel H K g›*)) (*proven 2 subgoals*) . lemma group_semidirect_sum_image_ker: assumes f: "f ∈ hom G H" and g: "g ∈ hom H K" and iso: "(g ∘ f) ∈ iso G K" and "group G" "group H" "group K" shows "(f ` carrier G) ∩ (kernel H K g) = {𝟭⇘H⇙}" "f ` carrier G <#>⇘H⇙ (kernel H K g) = carrier H" using group_Int_image_ker[OF f g] (*‹⟦inj_on ((g::'b ⇒ 'e) ∘ (f::'a ⇒ 'b)) (carrier (G::('a, 'c) monoid_scheme)); Group.group G; Group.group (H::('b, 'd) monoid_scheme); Group.group (K::('e, 'f) monoid_scheme)⟧ ⟹ f ` carrier G ∩ kernel H K g = {𝟭⇘H⇙}›*) group_sum_image_ker[OF f g] (*‹⟦(g ∘ f) ` carrier G = carrier K; Group.group G; Group.group H; Group.group K⟧ ⟹ f ` carrier G <#>⇘H⇙ kernel H K g = carrier H›*) assms (*‹f ∈ hom G H› ‹g ∈ hom H K› ‹g ∘ f ∈ Group.iso G K› ‹Group.group G› ‹Group.group (H::('b, 'd) monoid_scheme)› ‹Group.group K›*) apply - (*goals: 1. ‹⟦⟦inj_on ((g::'b ⇒ 'e) ∘ (f::'a ⇒ 'b)) (carrier (G::('a, 'c) monoid_scheme)); Group.group G; Group.group (H::('b, 'd) monoid_scheme); Group.group (K::('e, 'f) monoid_scheme)⟧ ⟹ f ` carrier G ∩ kernel H K g = {𝟭⇘H⇙}; ⟦(g ∘ f) ` carrier G = carrier K; Group.group G; Group.group H; Group.group K⟧ ⟹ f ` carrier G <#>⇘H⇙ kernel H K g = carrier H; f ∈ hom G H; g ∈ hom H K; g ∘ f ∈ Group.iso G K; Group.group G; Group.group H; Group.group K⟧ ⟹ f ` carrier G ∩ kernel H K g = {𝟭⇘H⇙}› 2. ‹⟦⟦inj_on ((g::'b ⇒ 'e) ∘ (f::'a ⇒ 'b)) (carrier (G::('a, 'c) monoid_scheme)); Group.group G; Group.group (H::('b, 'd) monoid_scheme); Group.group (K::('e, 'f) monoid_scheme)⟧ ⟹ f ` carrier G ∩ kernel H K g = {𝟭⇘H⇙}; ⟦(g ∘ f) ` carrier G = carrier K; Group.group G; Group.group H; Group.group K⟧ ⟹ f ` carrier G <#>⇘H⇙ kernel H K g = carrier H; f ∈ hom G H; g ∈ hom H K; g ∘ f ∈ Group.iso G K; Group.group G; Group.group H; Group.group K⟧ ⟹ f ` carrier G <#>⇘H⇙ kernel H K g = carrier H› discuss goal 1*) apply (simp add: iso_def (*‹Group.iso (?G::(?'a, ?'c) monoid_scheme) (?H::(?'b, ?'d) monoid_scheme) = {h::?'a::type ⇒ ?'b::type ∈ hom ?G ?H. bij_betw h (carrier ?G) (carrier ?H)}›*) bij_betw_def (*‹bij_betw (?f::?'a::type ⇒ ?'b::type) (?A::?'a::type set) (?B::?'b::type set) = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*)) (*discuss goal 2*) apply (simp add: iso_def (*‹Group.iso (?G::(?'a, ?'c) monoid_scheme) (?H::(?'b, ?'d) monoid_scheme) = {h::?'a ⇒ ?'b ∈ hom ?G ?H. bij_betw h (carrier ?G) (carrier ?H)}›*) bij_betw_def (*‹bij_betw (?f::?'a ⇒ ?'b) (?A::?'a set) (?B::?'b set) = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*)) (*proven 2 subgoals*) . subsection ‹Factor Groups and Direct product› lemma (in group) DirProd_normal : ✐‹contributor ‹Martin Baillon›› assumes "group K" and "H ⊲ G" and "N ⊲ K" shows "H × N ⊲ G ×× K" proof (intro group.normal_invI[OF DirProd_group[OF group_axioms assms(1)]] (*‹⟦subgroup (?N::('a × 'c) set) (G ×× (K::('c, 'd) monoid_scheme)); ⋀(x::'a × 'c) h::'a × 'c. ⟦x ∈ carrier (G ×× K); h ∈ ?N⟧ ⟹ x ⊗⇘G ×× K⇙ h ⊗⇘G ×× K⇙ inv⇘G ×× K⇙ x ∈ ?N⟧ ⟹ ?N ⊲ G ×× K›*)) (*goals: 1. ‹subgroup (H × N) (G ×× K)› 2. ‹⋀x h. ⟦x ∈ carrier (G ×× K); h ∈ H × N⟧ ⟹ x ⊗⇘G ×× K⇙ h ⊗⇘G ×× K⇙ inv⇘G ×× K⇙ x ∈ H × N›*) show sub: "subgroup (H × N) (G ×× K)" using DirProd_subgroups[OF group_axioms normal_imp_subgroup [ OF assms ( 2 ) ] assms ( 1 ) normal_imp_subgroup [ OF assms ( 3 ) ]] (*‹subgroup (H × N) (G ×× K)›*) . show "⋀x h. x ∈ carrier (G××K) ⟹ h ∈ H×N ⟹ x ⊗⇘G××K⇙ h ⊗⇘G××K⇙ inv⇘G××K⇙ x ∈ H×N" proof (-) (*goal: ‹⋀x h. ⟦x ∈ carrier (G ×× K); h ∈ H × N⟧ ⟹ x ⊗⇘G ×× K⇙ h ⊗⇘G ×× K⇙ inv⇘G ×× K⇙ x ∈ H × N›*) fix x and h assume xGK: "x ∈ carrier (G ×× K)" and hHN: " h ∈ H × N" (*‹(x::'a × 'c) ∈ carrier (G ×× (K::('c, 'd) monoid_scheme))› ‹(h::'a × 'c) ∈ (H::'a set) × (N::'c set)›*) hence hGK: "h ∈ carrier (G ×× K)" using subgroup.subset[OF sub] (*‹H × N ⊆ carrier (G ×× K)›*) by auto from xGK (*‹x ∈ carrier (G ×× K)›*) obtain x1 and x2 where x1x2: "x1 ∈ carrier G" "x2 ∈ carrier K" "x = (x1,x2)" (*goal: ‹(⋀x1 x2. ⟦x1 ∈ carrier G; x2 ∈ carrier K; x = (x1, x2)⟧ ⟹ thesis) ⟹ thesis›*) unfolding DirProd_def (*goal: ‹(⋀x1 x2. ⟦x1 ∈ carrier G; x2 ∈ carrier K; x = (x1, x2)⟧ ⟹ thesis) ⟹ thesis›*) by fastforce from hHN (*‹(h::'a::type × 'c::type) ∈ (H::'a::type set) × (N::'c::type set)›*) obtain h1 and h2 where h1h2: "h1 ∈ H" "h2 ∈ N" "h = (h1,h2)" (*goal: ‹(⋀h1 h2. ⟦h1 ∈ H; h2 ∈ N; h = (h1, h2)⟧ ⟹ thesis) ⟹ thesis›*) unfolding DirProd_def (*goal: ‹(⋀(h1::'a::type) h2::'c::type. ⟦h1 ∈ (H::'a::type set); h2 ∈ (N::'c::type set); (h::'a::type × 'c::type) = (h1, h2)⟧ ⟹ thesis::bool) ⟹ thesis›*) by fastforce hence h1h2GK: "h1 ∈ carrier G" "h2 ∈ carrier K" using normal_imp_subgroup (*‹?H ⊲ ?G ⟹ subgroup ?H ?G›*) subgroup.subset (*‹subgroup ?H ?G ⟹ ?H ⊆ carrier ?G›*) assms (*‹Group.group K› ‹H ⊲ G› ‹(N::'c set) ⊲ (K::('c, 'd) monoid_scheme)›*) apply - (*goals: 1. ‹⟦h1 ∈ H; h2 ∈ N; h = (h1, h2); ⋀H G. H ⊲ G ⟹ subgroup H G; ⋀H G. subgroup H G ⟹ H ⊆ carrier G; Group.group K; H ⊲ G; N ⊲ K⟧ ⟹ h1 ∈ carrier G› 2. ‹⟦h1 ∈ H; h2 ∈ N; h = (h1, h2); ⋀H G. H ⊲ G ⟹ subgroup H G; ⋀H G. subgroup H G ⟹ H ⊆ carrier G; Group.group K; H ⊲ G; N ⊲ K⟧ ⟹ h2 ∈ carrier K› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) . have "inv⇘G ×× K⇙ x = (inv⇘G⇙ x1,inv⇘K⇙ x2)" using inv_DirProd[OF group_axioms assms ( 1 ) x1x2 ( 1 ) x1x2 ( 2 )] (*‹inv⇘G ×× K⇙ (x1, x2) = (inv x1, inv⇘K⇙ x2)›*) x1x2 (*‹x1 ∈ carrier G› ‹(x2::'c) ∈ carrier (K::('c, 'd) monoid_scheme)› ‹x = (x1, x2)›*) by auto hence "x ⊗⇘G ×× K⇙ h ⊗⇘G ×× K⇙ inv⇘G ×× K⇙ x = (x1 ⊗ h1 ⊗ inv x1,x2 ⊗⇘K⇙ h2 ⊗⇘K⇙ inv⇘K⇙ x2)" using h1h2 (*‹h1 ∈ H› ‹h2 ∈ N› ‹h = (h1, h2)›*) x1x2 (*‹x1 ∈ carrier G› ‹x2 ∈ carrier K› ‹x = (x1, x2)›*) h1h2GK (*‹(h1::'a) ∈ carrier G› ‹h2 ∈ carrier K›*) by auto moreover have "x1 ⊗ h1 ⊗ inv x1 ∈ H" "x2 ⊗⇘K⇙ h2 ⊗⇘K⇙ inv⇘K⇙ x2 ∈ N" using assms (*‹Group.group K› ‹(H::'a::type set) ⊲ G› ‹N ⊲ K›*) x1x2 (*‹(x1::'a) ∈ carrier G› ‹x2 ∈ carrier K› ‹x = (x1, x2)›*) h1h2 (*‹h1 ∈ H› ‹h2 ∈ N› ‹h = (h1, h2)›*) assms (*‹Group.group K› ‹H ⊲ G› ‹N ⊲ K›*) apply - (*goals: 1. ‹⟦Group.group (K::('c, 'd) monoid_scheme); (H::'a set) ⊲ G; (N::'c set) ⊲ K; (x1::'a) ∈ carrier G; (x2::'c) ∈ carrier K; (x::'a × 'c) = (x1, x2); (h1::'a) ∈ H; (h2::'c) ∈ N; (h::'a × 'c) = (h1, h2); Group.group K; H ⊲ G; N ⊲ K⟧ ⟹ x1 ⊗ h1 ⊗ inv x1 ∈ H› 2. ‹⟦Group.group (K::('c, 'd) monoid_scheme); (H::'a set) ⊲ G; (N::'c set) ⊲ K; (x1::'a) ∈ carrier G; (x2::'c) ∈ carrier K; (x::'a × 'c) = (x1, x2); (h1::'a) ∈ H; (h2::'c) ∈ N; (h::'a × 'c) = (h1, h2); Group.group K; H ⊲ G; N ⊲ K⟧ ⟹ x2 ⊗⇘K⇙ h2 ⊗⇘K⇙ inv⇘K⇙ x2 ∈ N› discuss goal 1*) apply (simp add: normal.inv_op_closed2 (*‹⟦?H ⊲ ?G; ?x ∈ carrier ?G; ?h ∈ ?H⟧ ⟹ ?x ⊗⇘?G⇙ ?h ⊗⇘?G⇙ inv⇘?G⇙ ?x ∈ ?H›*)) (*discuss goal 2*) apply (simp add: normal.inv_op_closed2 (*‹⟦?H ⊲ ?G; ?x ∈ carrier ?G; ?h ∈ ?H⟧ ⟹ ?x ⊗⇘?G⇙ ?h ⊗⇘?G⇙ inv⇘?G⇙ ?x ∈ ?H›*)) (*proven 2 subgoals*) . hence "(x1 ⊗ h1 ⊗ inv x1, x2 ⊗⇘K⇙ h2 ⊗⇘K⇙ inv⇘K⇙ x2)∈ H × N" by auto ultimately show " x ⊗⇘G ×× K⇙ h ⊗⇘G ×× K⇙ inv⇘G ×× K⇙ x ∈ H × N" by auto qed qed lemma (in group) FactGroup_DirProd_multiplication_iso_set : ✐‹contributor ‹Martin Baillon›› assumes "group K" and "H ⊲ G" and "N ⊲ K" shows "(λ (X, Y). X × Y) ∈ iso ((G Mod H) ×× (K Mod N)) (G ×× K Mod H × N)" proof (-) (*goal: ‹(λ(X, Y). X × Y) ∈ Group.iso ((G Mod H) ×× (K Mod N)) (G ×× K Mod H × N)›*) have R: "(λ(X, Y). X × Y) ∈ carrier (G Mod H) × carrier (K Mod N) → carrier (G ×× K Mod H × N)" unfolding r_coset_def Sigma_def DirProd_def FactGroup_def RCOSETS_def (*goal: ‹(λ(X::'a set, Y::'c set). ⋃x::'a∈X. ⋃y::'c∈Y. {(x, y)}) ∈ (⋃x::'a set∈carrier ⦇carrier = ⋃a::'a∈carrier G. {⋃h::'a∈H::'a set. {h ⊗ a}}, mult = (<#>), one = H⦈. ⋃y::'c set∈carrier ⦇carrier = ⋃a::'c∈carrier K. {⋃h::'c∈N::'c set. {h ⊗⇘K::('c, 'd) monoid_scheme⇙ a}}, mult = (<#>⇘K⇙), one = N⦈. {(x, y)}) → carrier ⦇carrier = ⋃a::'a × 'c∈carrier ⦇carrier = ⋃x::'a∈carrier G. ⋃y::'c∈carrier K. {(x, y)}, mult = λ(g::'a, h::'c) (g'::'a, h'::'c). (g ⊗ g', h ⊗⇘K⇙ h'), one = (𝟭, 𝟭⇘K⇙)⦈. {⋃h::'a × 'c∈⋃x::'a∈H. ⋃y::'c∈N. {(x, y)}. {h ⊗⇘⦇carrier = ⋃x::'a∈carrier G. ⋃y::'c∈carrier K. {(x, y)}, mult = λ(g::'a, h::'c) (g'::'a, h'::'c). (g ⊗ g', h ⊗⇘K⇙ h'), one = (𝟭, 𝟭⇘K⇙)⦈⇙ a}}, mult = (<#>⇘⦇carrier = ⋃x::'a∈carrier G. ⋃y::'c∈carrier K. {(x, y)}, mult = λ(g::'a, h::'c) (g'::'a, h'::'c). (g ⊗ g', h ⊗⇘K⇙ h'), one = (𝟭, 𝟭⇘K⇙)⦈⇙), one = ⋃x::'a∈H. ⋃y::'c∈N. {(x, y)}⦈›*) by force moreover have "(∀x∈carrier (G Mod H). ∀y∈carrier (K Mod N). ∀xa∈carrier (G Mod H). ∀ya∈carrier (K Mod N). (x <#> xa) × (y <#>⇘K⇙ ya) = x × y <#>⇘G ×× K⇙ xa × ya)" unfolding set_mult_def (*goal: ‹∀x∈carrier (G Mod H). ∀y∈carrier (K Mod N). ∀xa∈carrier (G Mod H). ∀ya∈carrier (K Mod N). (⋃h∈x. ⋃k∈xa. {h ⊗ k}) × (⋃h∈y. ⋃k∈ya. {h ⊗⇘K⇙ k}) = (⋃h∈x × y. ⋃k∈xa × ya. {h ⊗⇘G ×× K⇙ k})›*) by force moreover have "(∀x∈carrier (G Mod H). ∀y∈carrier (K Mod N). ∀xa∈carrier (G Mod H). ∀ya∈carrier (K Mod N). x × y = xa × ya ⟶ x = xa ∧ y = ya)" unfolding FactGroup_def (*goal: ‹∀x∈carrier ⦇carrier = rcosets H, mult = (<#>), one = H⦈. ∀y∈carrier ⦇carrier = rcosets⇘K⇙ N, mult = (<#>⇘K⇙), one = N⦈. ∀xa∈carrier ⦇carrier = rcosets H, mult = (<#>), one = H⦈. ∀ya∈carrier ⦇carrier = rcosets⇘K⇙ N, mult = (<#>⇘K⇙), one = N⦈. x × y = xa × ya ⟶ x = xa ∧ y = ya›*) using times_eq_iff (*‹(?A × ?B = ?C × ?D) = (?A = ?C ∧ ?B = ?D ∨ (?A = {} ∨ ?B = {}) ∧ (?C = {} ∨ ?D = {}))›*) subgroup.rcosets_non_empty (*‹⟦subgroup ?H ?G; ?R ∈ rcosets⇘?G⇙ ?H⟧ ⟹ ?R ≠ {}›*) by (metis assms( (*‹H ⊲ G›*) 2) assms( (*‹N ⊲ K›*) 3) normal_def (*‹?H ⊲ ?G ≡ subgroup ?H ?G ∧ Group.group ?G ∧ normal_axioms ?H ?G›*) partial_object.select_convs( (*‹carrier ⦇carrier = ?carrier, … = ?more⦈ = ?carrier›*) 1)) moreover have "(λ(X, Y). X × Y) ` (carrier (G Mod H) × carrier (K Mod N)) = carrier (G ×× K Mod H × N)" proof (-) (*goal: ‹(λ(X, Y). X × Y) ` (carrier (G Mod H) × carrier (K Mod N)) = carrier (G ×× K Mod H × N)›*) have 1: "⋀x a b. ⟦a ∈ carrier (G Mod H); b ∈ carrier (K Mod N)⟧ ⟹ a × b ∈ carrier (G ×× K Mod H × N)" using R (*‹(λ(X, Y). X × Y) ∈ carrier (G Mod H) × carrier (K Mod N) → carrier (G ×× K Mod H × N)›*) by force have 2: "⋀z. z ∈ carrier (G ×× K Mod H × N) ⟹ ∃x∈carrier (G Mod H). ∃y∈carrier (K Mod N). z = x × y" unfolding DirProd_def FactGroup_def RCOSETS_def r_coset_def (*goal: ‹⋀z::('a × 'c) set. z ∈ carrier ⦇carrier = ⋃a::'a × 'c∈carrier ⦇carrier = carrier G × carrier K, mult = λ(g::'a, h::'c) (g'::'a, h'::'c). (g ⊗ g', h ⊗⇘K⇙ h'), one = (𝟭, 𝟭⇘K⇙)⦈. {⋃h::'a × 'c∈(H::'a set) × (N::'c set). {h ⊗⇘⦇carrier = carrier G × carrier (K::('c, 'd) monoid_scheme), mult = λ(g::'a, h::'c) (g'::'a, h'::'c). (g ⊗ g', h ⊗⇘K⇙ h'), one = (𝟭, 𝟭⇘K⇙)⦈⇙ a}}, mult = (<#>⇘⦇carrier = carrier G × carrier K, mult = λ(g::'a, h::'c) (g'::'a, h'::'c). (g ⊗ g', h ⊗⇘K⇙ h'), one = (𝟭, 𝟭⇘K⇙)⦈⇙), one = H × N⦈ ⟹ ∃x::'a set∈carrier ⦇carrier = ⋃a::'a∈carrier G. {⋃h::'a∈H. {h ⊗ a}}, mult = (<#>), one = H⦈. ∃y::'c set∈carrier ⦇carrier = ⋃a::'c∈carrier K. {⋃h::'c∈N. {h ⊗⇘K⇙ a}}, mult = (<#>⇘K⇙), one = N⦈. z = x × y›*) by force show "?thesis" (*goal: ‹(λ(X, Y). X × Y) ` (carrier (G Mod H) × carrier (K Mod N)) = carrier (G ×× K Mod H × N)›*) unfolding image_def (*goal: ‹{y. ∃x∈carrier (G Mod H) × carrier (K Mod N). y = (case x of (X, Y) ⇒ X × Y)} = carrier (G ×× K Mod H × N)›*) by (auto simp: intro: 1 (*‹⟦?a ∈ carrier (G Mod H); ?b ∈ carrier (K Mod N)⟧ ⟹ ?a × ?b ∈ carrier (G ×× K Mod H × N)›*) 2 (*‹?z1 ∈ carrier (G ×× K Mod H × N) ⟹ ∃x∈carrier (G Mod H). ∃y∈carrier (K Mod N). ?z1 = x × y›*)) qed ultimately show "?thesis" (*goal: ‹(λ(X, Y). X × Y) ∈ Group.iso ((G Mod H) ×× (K Mod N)) (G ×× K Mod H × N)›*) unfolding iso_def hom_def bij_betw_def inj_on_def (*goal: ‹(λ(X, Y). X × Y) ∈ {h ∈ {h ∈ carrier ((G Mod H) ×× (K Mod N)) → carrier (G ×× K Mod H × N). ∀x∈carrier ((G Mod H) ×× (K Mod N)). ∀y∈carrier ((G Mod H) ×× (K Mod N)). h (x ⊗⇘(G Mod H) ×× (K Mod N)⇙ y) = h x ⊗⇘G ×× K Mod H × N⇙ h y}. (∀x∈carrier ((G Mod H) ×× (K Mod N)). ∀y∈carrier ((G Mod H) ×× (K Mod N)). h x = h y ⟶ x = y) ∧ h ` carrier ((G Mod H) ×× (K Mod N)) = carrier (G ×× K Mod H × N)}›*) by simp qed corollary (in group) FactGroup_DirProd_multiplication_iso_1 : ✐‹contributor ‹Martin Baillon›› assumes "group K" and "H ⊲ G" and "N ⊲ K" shows " ((G Mod H) ×× (K Mod N)) ≅ (G ×× K Mod H × N)" unfolding is_iso_def (*goal: ‹Group.iso ((G Mod H) ×× (K Mod N)) (G ×× K Mod H × N) ≠ {}›*) using FactGroup_DirProd_multiplication_iso_set (*‹⟦Group.group ?K; ?H ⊲ G; ?N ⊲ ?K⟧ ⟹ (λ(X, Y). X × Y) ∈ Group.iso ((G Mod ?H) ×× (?K Mod ?N)) (G ×× ?K Mod ?H × ?N)›*) assms (*‹Group.group K› ‹H ⊲ G› ‹N ⊲ K›*) by auto corollary (in group) FactGroup_DirProd_multiplication_iso_2 : ✐‹contributor ‹Martin Baillon›› assumes "group K" and "H ⊲ G" and "N ⊲ K" shows "(G ×× K Mod H × N) ≅ ((G Mod H) ×× (K Mod N))" using FactGroup_DirProd_multiplication_iso_1 (*‹⟦Group.group (?K::(?'c, ?'d) monoid_scheme); (?H::'a set) ⊲ G; (?N::?'c set) ⊲ ?K⟧ ⟹ (G Mod ?H) ×× (?K Mod ?N) ≅ G ×× ?K Mod ?H × ?N›*) group.iso_sym (*‹⟦Group.group ?G; ?G ≅ ?H⟧ ⟹ ?H ≅ ?G›*) assms (*‹Group.group K› ‹(H::'a::type set) ⊲ G› ‹N ⊲ K›*) DirProd_group[OF normal.factorgroup_is_group normal.factorgroup_is_group] (*‹⟦?H2 ⊲ ?G2; ?H1 ⊲ ?G1⟧ ⟹ Group.group ((?G2 Mod ?H2) ×× (?G1 Mod ?H1))›*) by blast subsubsection "More Lemmas about set multiplication" text ‹A group multiplied by a subgroup stays the same› lemma (in group) set_mult_carrier_idem: assumes "subgroup H G" shows "(carrier G) <#> H = carrier G" proof (standard) (*goals: 1. ‹carrier G <#> H ⊆ carrier G› 2. ‹carrier G ⊆ carrier G <#> H›*) show "(carrier G)<#>H ⊆ carrier G" unfolding set_mult_def (*goal: ‹(⋃h∈carrier G. ⋃k∈H. {h ⊗ k}) ⊆ carrier G›*) using subgroup.subset (*‹subgroup ?H ?G ⟹ ?H ⊆ carrier ?G›*) assms (*‹subgroup (H::'a set) G›*) by blast next (*goal: ‹carrier G ⊆ carrier G <#> H›*) have " (carrier G) #> 𝟭 = carrier G" unfolding set_mult_def r_coset_def group_axioms (*goal: ‹(⋃h∈carrier G. {h ⊗ 𝟭}) = carrier G›*) by simp moreover have "(carrier G) #> 𝟭 ⊆ (carrier G) <#> H" unfolding set_mult_def r_coset_def (*goal: ‹(⋃h∈carrier G. {h ⊗ 𝟭}) ⊆ (⋃h∈carrier G. ⋃k∈H. {h ⊗ k})›*) using assms (*‹subgroup (H::'a set) G›*) subgroup.one_closed[OF assms] (*‹𝟭 ∈ H›*) by blast ultimately show "carrier G ⊆ (carrier G) <#> H" by simp qed text ‹Same lemma as above, but everything is included in a subgroup› lemma (in group) set_mult_subgroup_idem: assumes HG: "subgroup H G" and NG: "subgroup N (G ⦇ carrier := H ⦈)" shows "H <#> N = H" using group.set_mult_carrier_idem[OF subgroup.subgroup_is_group [ OF HG group_axioms ] NG] (*‹carrier (G⦇carrier := H⦈) <#>⇘G⦇carrier := H⦈⇙ N = carrier (G⦇carrier := H⦈)›*) by simp text ‹A normal subgroup is commutative with set multiplication› lemma (in group) commut_normal: assumes "subgroup H G" and "N⊲G" shows "H<#>N = N<#>H" proof (-) (*goal: ‹(H::'a::type set) <#> (N::'a::type set) = N <#> H›*) have aux1: "{H <#> N} = {⋃h∈H. h <# N }" unfolding set_mult_def l_coset_def (*goal: ‹{⋃h∈H. ⋃k∈N. {h ⊗ k}} = {⋃h∈H. ⋃ha∈N. {h ⊗ ha}}›*) by auto also (*calculation: ‹{(H::'a set) <#> (N::'a set)} = {⋃h::'a∈H. h <# N}›*) have "... = {⋃h∈H. N #> h }" using assms (*‹subgroup H G› ‹(N::'a::type set) ⊲ G›*) normal.coset_eq (*‹?H ⊲ ?G ⟹ ∀x∈carrier ?G. ?H #>⇘?G⇙ x = x <#⇘?G⇙ ?H›*) subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*) by fastforce moreover have aux2: "{N <#> H} = {⋃h∈H. N #> h }" unfolding set_mult_def r_coset_def (*goal: ‹{⋃h∈N. ⋃k∈H. {h ⊗ k}} = {⋃h∈H. ⋃ha∈N. {ha ⊗ h}}›*) by auto ultimately show "H<#>N = N<#>H" by simp qed text ‹Same lemma as above, but everything is included in a subgroup› lemma (in group) commut_normal_subgroup: assumes "subgroup H G" and "N ⊲ (G⦇ carrier := H ⦈)" and "subgroup K (G ⦇ carrier := H ⦈)" shows "K <#> N = N <#> K" by (metis assms( (*‹N ⊲ G⦇carrier := H⦈›*) 2) assms( (*‹subgroup K (G⦇carrier := H⦈)›*) 3) group.commut_normal (*‹⟦Group.group ?G; subgroup ?H ?G; ?N ⊲ ?G⟧ ⟹ ?H <#>⇘?G⇙ ?N = ?N <#>⇘?G⇙ ?H›*) normal.axioms( (*‹?H ⊲ ?G ⟹ Group.group ?G›*) 2) set_mult_consistent (*‹?N <#>⇘?G⦇carrier := ?H⦈⇙ ?K = ?N <#>⇘?G⇙ ?K›*)) subsubsection "Lemmas about intersection and normal subgroups" text ‹Mostly by Jakob von Raumer› lemma (in group) normal_inter: assumes "subgroup H G" and "subgroup K G" and "H1⊲G⦇carrier := H⦈" shows "(H1∩K)⊲(G⦇carrier:= (H∩K)⦈)" proof (-) (*goal: ‹H1 ∩ K ⊲ G⦇carrier := H ∩ K⦈›*) define HK and H1K and GH and GHK where "HK = H∩K" and "H1K=H1∩K" and "GH =G⦇carrier := H⦈" and "GHK = (G⦇carrier:= (H∩K)⦈)" show "H1K⊲GHK" proof (intro group.normal_invI[of GHK H1K] (*‹⟦Group.group (GHK::('a, 'b) monoid_scheme); subgroup (H1K::'a set) GHK; ⋀(x::'a) h::'a. ⟦x ∈ carrier GHK; h ∈ H1K⟧ ⟹ x ⊗⇘GHK⇙ h ⊗⇘GHK⇙ inv⇘GHK⇙ x ∈ H1K⟧ ⟹ H1K ⊲ GHK›*)) (*goals: 1. ‹Group.group (GHK::('a, 'b) monoid_scheme)› 2. ‹subgroup (H1K::'a::type set) (GHK::('a, 'b) monoid_scheme)› 3. ‹⋀(x::'a::type) h::'a::type. ⟦x ∈ carrier (GHK::('a, 'b) monoid_scheme); h ∈ (H1K::'a::type set)⟧ ⟹ x ⊗⇘GHK⇙ h ⊗⇘GHK⇙ inv⇘GHK⇙ x ∈ H1K›*) show "Group.group GHK" using GHK_def (*‹GHK = G⦇carrier := H ∩ K⦈›*) subgroups_Inter_pair (*‹⟦subgroup (?I::'a set) G; subgroup (?J::'a set) G⟧ ⟹ subgroup (?I ∩ ?J) G›*) subgroup_imp_group (*‹subgroup (?H::'a set) G ⟹ Group.group (G⦇carrier := ?H⦈)›*) assms (*‹subgroup H G› ‹subgroup K G› ‹H1 ⊲ G⦇carrier := H⦈›*) by blast next (*goals: 1. ‹subgroup H1K GHK› 2. ‹⋀x h. ⟦x ∈ carrier GHK; h ∈ H1K⟧ ⟹ x ⊗⇘GHK⇙ h ⊗⇘GHK⇙ inv⇘GHK⇙ x ∈ H1K›*) have H1K_incl: "subgroup H1K (G⦇carrier:= (H∩K)⦈)" proof (intro subgroup_incl (*‹⟦subgroup ?I G; subgroup ?J G; ?I ⊆ ?J⟧ ⟹ subgroup ?I (G⦇carrier := ?J⦈)›*)) (*goals: 1. ‹subgroup (H1K::'a set) G› 2. ‹subgroup ((H::'a set) ∩ (K::'a set)) G› 3. ‹(H1K::'a set) ⊆ (H::'a set) ∩ (K::'a set)›*) show "subgroup H1K G" using assms (*‹subgroup H G› ‹subgroup K G› ‹H1 ⊲ G⦇carrier := H⦈›*) normal_imp_subgroup (*‹?H ⊲ ?G ⟹ subgroup ?H ?G›*) subgroups_Inter_pair (*‹⟦subgroup ?I G; subgroup ?J G⟧ ⟹ subgroup (?I ∩ ?J) G›*) incl_subgroup (*‹⟦subgroup ?J G; subgroup ?I (G⦇carrier := ?J⦈)⟧ ⟹ subgroup ?I G›*) H1K_def (*‹H1K = H1 ∩ K›*) by blast next (*goals: 1. ‹subgroup ((H::'a set) ∩ (K::'a set)) G› 2. ‹(H1K::'a set) ⊆ (H::'a set) ∩ (K::'a set)›*) show "subgroup (H∩K) G" using HK_def (*‹(HK::'a set) = (H::'a set) ∩ (K::'a set)›*) subgroups_Inter_pair (*‹⟦subgroup ?I G; subgroup ?J G⟧ ⟹ subgroup (?I ∩ ?J) G›*) assms (*‹subgroup H G› ‹subgroup K G› ‹H1 ⊲ G⦇carrier := H⦈›*) by auto next (*goal: ‹H1K ⊆ H ∩ K›*) have "H1 ⊆ (carrier (G⦇carrier:=H⦈))" using assms(3) (*‹H1 ⊲ G⦇carrier := H⦈›*) normal_imp_subgroup (*‹?H ⊲ ?G ⟹ subgroup ?H ?G›*) subgroup.subset (*‹subgroup (?H::?'a::type set) (?G::(?'a, ?'b) monoid_scheme) ⟹ ?H ⊆ carrier ?G›*) by blast also (*calculation: ‹H1 ⊆ carrier (G⦇carrier := H⦈)›*) have "... ⊆ H" by simp thus "H1K ⊆H∩K" using H1K_def (*‹H1K = H1 ∩ K›*) calculation (*‹H1 ⊆ carrier (G⦇carrier := H⦈)›*) by auto qed thus "subgroup H1K GHK" using GHK_def (*‹GHK = G⦇carrier := H ∩ K⦈›*) by simp next (*goal: ‹⋀x h. ⟦x ∈ carrier GHK; h ∈ H1K⟧ ⟹ x ⊗⇘GHK⇙ h ⊗⇘GHK⇙ inv⇘GHK⇙ x ∈ H1K›*) show "⋀ x h. x∈carrier GHK ⟹ h∈H1K ⟹ x ⊗⇘GHK⇙ h ⊗⇘GHK⇙ inv⇘GHK⇙ x∈ H1K" proof (-) (*goal: ‹⋀x h. ⟦x ∈ carrier GHK; h ∈ H1K⟧ ⟹ x ⊗⇘GHK⇙ h ⊗⇘GHK⇙ inv⇘GHK⇙ x ∈ H1K›*) have invHK: "⟦y∈HK⟧ ⟹ inv⇘GHK⇙ y = inv⇘GH⇙ y" using m_inv_consistent (*‹⟦subgroup ?H G; ?x ∈ ?H⟧ ⟹ inv⇘G⦇carrier := ?H⦈⇙ ?x = inv ?x›*) assms (*‹subgroup H G› ‹subgroup K G› ‹H1 ⊲ G⦇carrier := H⦈›*) HK_def (*‹HK = H ∩ K›*) GH_def (*‹GH = G⦇carrier := H⦈›*) GHK_def (*‹GHK = G⦇carrier := H ∩ K⦈›*) subgroups_Inter_pair (*‹⟦subgroup ?I G; subgroup ?J G⟧ ⟹ subgroup (?I ∩ ?J) G›*) by simp have multHK: "⟦x∈HK;y∈HK⟧ ⟹ x ⊗⇘(G⦇carrier:=HK⦈)⇙ y = x ⊗ y" using HK_def (*‹(HK::'a::type set) = (H::'a::type set) ∩ (K::'a::type set)›*) by simp fix x assume p: "x∈carrier GHK" (*‹(x::'a) ∈ carrier (GHK::('a, 'b) monoid_scheme)›*) fix h assume p2: "h:H1K" (*‹(h::'a) ∈ (H1K::'a set)›*) have "carrier(GHK)⊆HK" using GHK_def (*‹GHK = G⦇carrier := H ∩ K⦈›*) HK_def (*‹HK = H ∩ K›*) by simp hence xHK: "x∈HK" using p (*‹x ∈ carrier GHK›*) by auto hence invx: "inv⇘GHK⇙ x = inv⇘GH⇙ x" using invHK (*‹(y::'a) ∈ (HK::'a set) ⟹ inv⇘GHK::('a, 'b) monoid_scheme⇙ y = inv⇘GH::('a, 'b) monoid_scheme⇙ y›*) assms (*‹subgroup H G› ‹subgroup (K::'a::type set) G› ‹(H1::'a::type set) ⊲ G⦇carrier := H::'a::type set⦈›*) GHK_def (*‹GHK = G⦇carrier := H ∩ K⦈›*) HK_def (*‹HK = H ∩ K›*) GH_def (*‹GH = G⦇carrier := H⦈›*) m_inv_consistent (*‹⟦subgroup ?H G; ?x ∈ ?H⟧ ⟹ inv⇘G⦇carrier := ?H⦈⇙ ?x = inv ?x›*) subgroups_Inter_pair (*‹⟦subgroup ?I G; subgroup ?J G⟧ ⟹ subgroup (?I ∩ ?J) G›*) by simp have "H1⊆carrier(GH)" using assms (*‹subgroup H G› ‹subgroup K G› ‹H1 ⊲ G⦇carrier := H⦈›*) GH_def (*‹GH = G⦇carrier := H⦈›*) normal_imp_subgroup (*‹?H ⊲ ?G ⟹ subgroup ?H ?G›*) subgroup.subset (*‹subgroup ?H ?G ⟹ ?H ⊆ carrier ?G›*) by blast hence hHK: "h∈HK" using p2 (*‹h ∈ H1K›*) H1K_def (*‹(H1K::'a set) = (H1::'a set) ∩ (K::'a set)›*) HK_def (*‹HK = H ∩ K›*) GH_def (*‹(GH::('a, 'b) monoid_scheme) = G⦇carrier := H::'a set⦈›*) by auto hence xhx_egal: "x ⊗⇘GHK⇙ h ⊗⇘GHK⇙ inv⇘GHK⇙x = x ⊗⇘GH⇙ h ⊗⇘GH⇙ inv⇘GH⇙ x" using invx (*‹inv⇘GHK⇙ x = inv⇘GH⇙ x›*) invHK (*‹y ∈ HK ⟹ inv⇘GHK⇙ y = inv⇘GH⇙ y›*) multHK (*‹⟦x ∈ HK; y ∈ HK⟧ ⟹ x ⊗⇘G⦇carrier := HK⦈⇙ y = x ⊗ y›*) GHK_def (*‹GHK = G⦇carrier := H ∩ K⦈›*) GH_def (*‹GH = G⦇carrier := H⦈›*) by auto have xH: "x∈carrier(GH)" using xHK (*‹x ∈ HK›*) HK_def (*‹HK = H ∩ K›*) GH_def (*‹GH = G⦇carrier := H⦈›*) by auto have hH: "h∈carrier(GH)" using hHK (*‹h ∈ HK›*) HK_def (*‹HK = H ∩ K›*) GH_def (*‹(GH::('a, 'b) monoid_scheme) = G⦇carrier := H::'a set⦈›*) by auto have "(∀x∈carrier (GH). ∀h∈H1. x ⊗⇘GH⇙ h ⊗⇘GH⇙ inv⇘GH⇙ x ∈ H1)" using assms (*‹subgroup (H::'a set) G› ‹subgroup K G› ‹H1 ⊲ G⦇carrier := H⦈›*) GH_def (*‹GH = G⦇carrier := H⦈›*) normal.inv_op_closed2 (*‹⟦?H ⊲ ?G; ?x ∈ carrier ?G; ?h ∈ ?H⟧ ⟹ ?x ⊗⇘?G⇙ ?h ⊗⇘?G⇙ inv⇘?G⇙ ?x ∈ ?H›*) by fastforce hence INCL_1: "x ⊗⇘GH⇙ h ⊗⇘GH⇙ inv⇘GH⇙ x ∈ H1" using xH (*‹x ∈ carrier GH›*) H1K_def (*‹H1K = H1 ∩ K›*) p2 (*‹h ∈ H1K›*) by blast have " x ⊗⇘GH⇙ h ⊗⇘GH⇙ inv⇘GH⇙ x ∈ HK" using assms (*‹subgroup H G› ‹subgroup (K::'a set) G› ‹H1 ⊲ G⦇carrier := H⦈›*) HK_def (*‹HK = H ∩ K›*) subgroups_Inter_pair (*‹⟦subgroup ?I G; subgroup ?J G⟧ ⟹ subgroup (?I ∩ ?J) G›*) hHK (*‹h ∈ HK›*) xHK (*‹x ∈ HK›*) by (metis GH_def (*‹GH = G⦇carrier := H⦈›*) inf.cobounded1 (*‹inf ?a ?b ≤ ?a›*) subgroup_def (*‹subgroup ?H ?G ≡ (?H ⊆ carrier ?G ∧ (∀x y. x ∈ ?H ⟶ y ∈ ?H ⟶ x ⊗⇘?G⇙ y ∈ ?H)) ∧ 𝟭⇘?G⇙ ∈ ?H ∧ (∀x. x ∈ ?H ⟶ inv⇘?G⇙ x ∈ ?H)›*) subgroup_incl (*‹⟦subgroup ?I G; subgroup ?J G; ?I ⊆ ?J⟧ ⟹ subgroup ?I (G⦇carrier := ?J⦈)›*)) hence " x ⊗⇘GH⇙ h ⊗⇘GH⇙ inv⇘GH⇙ x ∈ K" using HK_def (*‹HK = H ∩ K›*) by simp hence " x ⊗⇘GH⇙ h ⊗⇘GH⇙ inv⇘GH⇙ x ∈ H1K" using INCL_1 (*‹(x::'a) ⊗⇘GH⇙ (h::'a) ⊗⇘GH::('a, 'b) monoid_scheme⇙ inv⇘GH⇙ x ∈ (H1::'a set)›*) H1K_def (*‹H1K = H1 ∩ K›*) by auto thus "x ⊗⇘GHK⇙ h ⊗⇘GHK⇙ inv⇘GHK⇙ x ∈ H1K" using xhx_egal (*‹x ⊗⇘GHK⇙ h ⊗⇘GHK⇙ inv⇘GHK⇙ x = x ⊗⇘GH⇙ h ⊗⇘GH⇙ inv⇘GH⇙ x›*) by simp qed qed qed lemma (in group) normal_Int_subgroup: assumes "subgroup H G" and "N ⊲ G" shows "(N∩H) ⊲ (G⦇carrier := H⦈)" proof (-) (*goal: ‹N ∩ H ⊲ G⦇carrier := H⦈›*) define K where "K = carrier G" have "G⦇carrier := K⦈ = G" using K_def (*‹K = carrier G›*) by auto moreover have "subgroup K G" using K_def (*‹K = carrier G›*) subgroup_self (*‹subgroup (carrier G) G›*) by blast moreover have "normal N (G ⦇carrier :=K⦈)" using assms (*‹subgroup H G› ‹N ⊲ G›*) K_def (*‹K = carrier G›*) by simp ultimately have "N ∩ H ⊲ G⦇carrier := K ∩ H⦈" using normal_inter[of K H N] (*‹⟦subgroup K G; subgroup H G; N ⊲ G⦇carrier := K⦈⟧ ⟹ N ∩ H ⊲ G⦇carrier := K ∩ H⦈›*) assms(1) (*‹subgroup H G›*) by blast moreover have "K ∩ H = H" using K_def (*‹(K::'a set) = carrier G›*) assms (*‹subgroup H G› ‹N ⊲ G›*) subgroup.subset (*‹subgroup ?H ?G ⟹ ?H ⊆ carrier ?G›*) by blast ultimately show "normal (N∩H) (G⦇carrier := H⦈)" by auto qed lemma (in group) normal_restrict_supergroup: assumes "subgroup S G" "N ⊲ G" "N ⊆ S" shows "N ⊲ (G⦇carrier := S⦈)" by (metis assms (*‹subgroup S G› ‹N ⊲ G› ‹N ⊆ S›*) inf.absorb_iff1 (*‹(?a ≤ ?b) = (inf ?a ?b = ?a)›*) normal_Int_subgroup (*‹⟦subgroup ?H G; ?N ⊲ G⟧ ⟹ ?N ∩ ?H ⊲ G⦇carrier := ?H⦈›*)) text ‹A subgroup relation survives factoring by a normal subgroup.› lemma (in group) normal_subgroup_factorize: assumes "N ⊲ G" and "N ⊆ H" and "subgroup H G" shows "subgroup (rcosets⇘G⦇carrier := H⦈⇙ N) (G Mod N)" proof (-) (*goal: ‹subgroup (rcosets⇘G⦇carrier := H⦈⇙ N) (G Mod N)›*) interpret GModN: group "G Mod N" using assms(1) (*‹N ⊲ G›*) by (rule normal.factorgroup_is_group (*‹(?H::?'a set) ⊲ (?G::(?'a, ?'b) monoid_scheme) ⟹ Group.group (?G Mod ?H)›*)) have "N ⊲ G⦇carrier := H⦈" using assms (*‹N ⊲ G› ‹N ⊆ H› ‹subgroup H G›*) by (metis normal_restrict_supergroup (*‹⟦subgroup ?S G; ?N ⊲ G; ?N ⊆ ?S⟧ ⟹ ?N ⊲ G⦇carrier := ?S⦈›*)) hence grpHN: "group (G⦇carrier := H⦈ Mod N)" by (rule normal.factorgroup_is_group (*‹?H ⊲ ?G ⟹ Group.group (?G Mod ?H)›*)) have "(<#>⇘G⦇carrier:=H⦈⇙) = (λU K. (⋃h∈U. ⋃k∈K. {h ⊗⇘G⦇carrier := H⦈⇙ k}))" using set_mult_def (*‹(?H::?'a::type set) <#>⇘?G::(?'a, ?'b) monoid_scheme⇙ (?K::?'a::type set) = (⋃h::?'a::type∈?H. ⋃k::?'a::type∈?K. {h ⊗⇘?G⇙ k})›*) by metis moreover have "… = (λU K. (⋃h∈U. ⋃k∈K. {h ⊗⇘G⇙ k}))" by auto moreover have "(<#>) = (λU K. (⋃h∈U. ⋃k∈K. {h ⊗ k}))" using set_mult_def (*‹?H <#>⇘?G⇙ ?K = (⋃h∈?H. ⋃k∈?K. {h ⊗⇘?G⇙ k})›*) by metis ultimately have "(<#>⇘G⦇carrier:=H⦈⇙) = (<#>⇘G⇙)" by simp with grpHN (*‹Group.group (G⦇carrier := H⦈ Mod N)›*) have "group ((G Mod N)⦇carrier := (rcosets⇘G⦇carrier := H⦈⇙ N)⦈)" unfolding FactGroup_def (*goal: ‹Group.group (⦇carrier = rcosets N, mult = (<#>), one = N⦈⦇carrier := rcosets⇘G⦇carrier := H⦈⇙ N⦈)›*) by auto moreover have "rcosets⇘G⦇carrier := H⦈⇙ N ⊆ carrier (G Mod N)" unfolding FactGroup_def RCOSETS_def r_coset_def (*goal: ‹(⋃a∈carrier (G⦇carrier := H⦈). {⋃h∈N. {h ⊗⇘G⦇carrier := H⦈⇙ a}}) ⊆ carrier ⦇carrier = ⋃a∈carrier G. {⋃h∈N. {h ⊗ a}}, mult = (<#>), one = N⦈›*) using assms(3) (*‹subgroup (H::'a set) G›*) subgroup.subset (*‹subgroup ?H ?G ⟹ ?H ⊆ carrier ?G›*) by fastforce ultimately show "?thesis" (*goal: ‹subgroup (rcosets⇘G⦇carrier := H::'a::type set⦈⇙ (N::'a::type set)) (G Mod N)›*) using GModN.group_incl_imp_subgroup (*‹⟦?H ⊆ carrier (G Mod N); Group.group ((G Mod N)⦇carrier := ?H⦈)⟧ ⟹ subgroup ?H (G Mod N)›*) by blast qed text ‹A normality relation survives factoring by a normal subgroup.› lemma (in group) normality_factorization: assumes NG: "N ⊲ G" and NH: "N ⊆ H" and HG: "H ⊲ G" shows "(rcosets⇘G⦇carrier := H⦈⇙ N) ⊲ (G Mod N)" proof (-) (*goal: ‹rcosets⇘G⦇carrier := H⦈⇙ N ⊲ G Mod N›*) from assms(1) (*‹N ⊲ G›*) interpret GModN: group "G Mod N" by (metis normal.factorgroup_is_group (*‹?H ⊲ ?G ⟹ Group.group (?G Mod ?H)›*)) show "?thesis" (*goal: ‹rcosets⇘G⦇carrier := H::'a set⦈⇙ (N::'a set) ⊲ G Mod N›*) unfolding GModN.normal_inv_iff (*goal: ‹subgroup (rcosets⇘G⦇carrier := H⦈⇙ N) (G Mod N) ∧ (∀x∈carrier (G Mod N). ∀h∈rcosets⇘G⦇carrier := H⦈⇙ N. x ⊗⇘G Mod N⇙ h ⊗⇘G Mod N⇙ inv⇘G Mod N⇙ x ∈ rcosets⇘G⦇carrier := H⦈⇙ N)›*) proof (intro conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*) strip (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q› ‹(⋀x. ?P x) ⟹ ∀x. ?P x› ‹(⋀x. x ∈ ?A ⟹ ?P x) ⟹ ∀x∈?A. ?P x›*)) (*goals: 1. ‹subgroup (rcosets⇘G⦇carrier := H⦈⇙ N) (G Mod N)› 2. ‹⋀x h. ⟦x ∈ carrier (G Mod N); h ∈ rcosets⇘G⦇carrier := H⦈⇙ N⟧ ⟹ x ⊗⇘G Mod N⇙ h ⊗⇘G Mod N⇙ inv⇘G Mod N⇙ x ∈ rcosets⇘G⦇carrier := H⦈⇙ N›*) show "subgroup (rcosets⇘G⦇carrier := H⦈⇙ N) (G Mod N)" using assms (*‹N ⊲ G› ‹(N::'a::type set) ⊆ (H::'a::type set)› ‹H ⊲ G›*) normal_imp_subgroup (*‹?H ⊲ ?G ⟹ subgroup ?H ?G›*) normal_subgroup_factorize (*‹⟦?N ⊲ G; ?N ⊆ ?H; subgroup ?H G⟧ ⟹ subgroup (rcosets⇘G⦇carrier := ?H⦈⇙ ?N) (G Mod ?N)›*) by force next (*goal: ‹⋀x h. ⟦x ∈ carrier (G Mod N); h ∈ rcosets⇘G⦇carrier := H⦈⇙ N⟧ ⟹ x ⊗⇘G Mod N⇙ h ⊗⇘G Mod N⇙ inv⇘G Mod N⇙ x ∈ rcosets⇘G⦇carrier := H⦈⇙ N›*) fix U and V assume U: "U ∈ carrier (G Mod N)" and V: "V ∈ rcosets⇘G⦇carrier := H⦈⇙ N" (*‹(U::'a set) ∈ carrier (G Mod (N::'a set))› ‹(V::'a set) ∈ rcosets⇘G⦇carrier := H::'a set⦈⇙ (N::'a set)›*) then obtain g where g: "g ∈ carrier G" "U = N #> g" (*goal: ‹(⋀g. ⟦g ∈ carrier G; U = N #> g⟧ ⟹ thesis) ⟹ thesis›*) unfolding FactGroup_def RCOSETS_def (*goal: ‹(⋀g. ⟦g ∈ carrier G; U = N #> g⟧ ⟹ thesis) ⟹ thesis›*) by auto from V (*‹(V::'a set) ∈ rcosets⇘G⦇carrier := H::'a set⦈⇙ (N::'a set)›*) obtain h where h: "h ∈ H" "V = N #> h" (*goal: ‹(⋀h. ⟦h ∈ H; V = N #> h⟧ ⟹ thesis) ⟹ thesis›*) unfolding FactGroup_def RCOSETS_def r_coset_def (*goal: ‹(⋀h::'a. ⟦h ∈ (H::'a set); (V::'a set) = (⋃ha::'a∈N::'a set. {ha ⊗ h})⟧ ⟹ thesis::bool) ⟹ thesis›*) by auto hence hG: "h ∈ carrier G" using HG (*‹(H::'a set) ⊲ G›*) normal_imp_subgroup (*‹?H ⊲ ?G ⟹ subgroup ?H ?G›*) subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*) by force hence ghG: "g ⊗ h ∈ carrier G" using g (*‹g ∈ carrier G› ‹U = N #> g›*) m_closed (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ ?x ⊗ ?y ∈ carrier G›*) by auto from g (*‹g ∈ carrier G› ‹(U::'a set) = (N::'a set) #> (g::'a)›*) h (*‹h ∈ H› ‹V = N #> h›*) have "g ⊗ h ⊗ inv g ∈ H" using HG (*‹H ⊲ G›*) normal_inv_iff (*‹?N ⊲ G = (subgroup ?N G ∧ (∀x∈carrier G. ∀h∈?N. x ⊗ h ⊗ inv x ∈ ?N))›*) by auto moreover have "U <#> V <#> inv⇘G Mod N⇙ U = N #> (g ⊗ h ⊗ inv g)" proof (-) (*goal: ‹U <#> V <#> inv⇘G Mod N⇙ U = N #> g ⊗ h ⊗ inv g›*) from g (*‹g ∈ carrier G› ‹U = N #> g›*) U (*‹U ∈ carrier (G Mod N)›*) have "inv⇘G Mod N⇙ U = N #> inv g" using NG (*‹N ⊲ G›*) normal.inv_FactGroup (*‹⟦?H ⊲ ?G; ?X ∈ carrier (?G Mod ?H)⟧ ⟹ inv⇘?G Mod ?H⇙ ?X = set_inv⇘?G⇙ ?X›*) normal.rcos_inv (*‹⟦?H ⊲ ?G; ?x ∈ carrier ?G⟧ ⟹ set_inv⇘?G⇙ (?H #>⇘?G⇙ ?x) = ?H #>⇘?G⇙ inv⇘?G⇙ ?x›*) by fastforce hence "U <#> V <#> inv⇘G Mod N⇙ U = (N #> g) <#> (N #> h) <#> (N #> inv g)" using g (*‹g ∈ carrier G› ‹U = N #> g›*) h (*‹(h::'a) ∈ (H::'a set)› ‹V = N #> h›*) by simp also (*calculation: ‹(U::'a::type set) <#> (V::'a::type set) <#> inv⇘G Mod (N::'a::type set)⇙ U = N #> (g::'a::type) <#> (N #> (h::'a::type)) <#> (N #> inv g)›*) have "… = N #> (g ⊗ h ⊗ inv g)" using g (*‹g ∈ carrier G› ‹U = N #> g›*) hG (*‹h ∈ carrier G›*) NG (*‹N ⊲ G›*) inv_closed (*‹?x ∈ carrier G ⟹ inv ?x ∈ carrier G›*) ghG (*‹g ⊗ h ∈ carrier G›*) normal.rcos_sum (*‹⟦?H ⊲ ?G; ?x ∈ carrier ?G; ?y ∈ carrier ?G⟧ ⟹ ?H #>⇘?G⇙ ?x <#>⇘?G⇙ (?H #>⇘?G⇙ ?y) = ?H #>⇘?G⇙ ?x ⊗⇘?G⇙ ?y›*) by force finally (*calculation: ‹(U::'a set) <#> (V::'a set) <#> inv⇘G Mod (N::'a set)⇙ U = N #> (g::'a) ⊗ (h::'a) ⊗ inv g›*) show "?thesis" (*goal: ‹U <#> V <#> inv⇘G Mod N⇙ U = N #> g ⊗ h ⊗ inv g›*) . qed ultimately show "U ⊗⇘G Mod N⇙ V ⊗⇘G Mod N⇙ inv⇘G Mod N⇙ U ∈ rcosets⇘G⦇carrier := H⦈⇙ N" unfolding RCOSETS_def r_coset_def (*goal: ‹U ⊗⇘G Mod N⇙ V ⊗⇘G Mod N⇙ inv⇘G Mod N⇙ U ∈ (⋃a∈carrier (G⦇carrier := H⦈). {⋃h∈N. {h ⊗⇘G⦇carrier := H⦈⇙ a}})›*) by auto qed qed text ‹Factorizing by the trivial subgroup is an isomorphism.› lemma (in group) trivial_factor_iso: shows "the_elem ∈ iso (G Mod {𝟭}) G" proof (-) (*goal: ‹the_elem ∈ Group.iso (G Mod {𝟭}) G›*) have "group_hom G G (λx. x)" unfolding group_hom_def group_hom_axioms_def hom_def (*goal: ‹Group.group G ∧ Group.group G ∧ (λx. x) ∈ {h ∈ carrier G → carrier G. ∀x∈carrier G. ∀y∈carrier G. h (x ⊗ y) = h x ⊗ h y}›*) using is_group (*‹Group.group G›*) by simp moreover have "(λx. x) ` carrier G = carrier G" by simp moreover have "kernel G G (λx. x) = {𝟭}" unfolding kernel_def (*goal: ‹{x ∈ carrier G. x = 𝟭} = {𝟭}›*) by auto ultimately show "?thesis" (*goal: ‹the_elem ∈ Group.iso (G Mod {𝟭}) G›*) using group_hom.FactGroup_iso_set (*‹⟦group_hom (?G::(?'a, ?'b) monoid_scheme) (?H::(?'c, ?'d) monoid_scheme) (?h::?'a::type ⇒ ?'c::type); ?h ` carrier ?G = carrier ?H⟧ ⟹ (λX::?'a::type set. the_elem (?h ` X)) ∈ Group.iso (?G Mod kernel ?G ?H ?h) ?H›*) by force qed text ‹And the dual theorem to the previous one: Factorizing by the group itself gives the trivial group› lemma (in group) self_factor_iso: shows "(λX. the_elem ((λx. 𝟭) ` X)) ∈ iso (G Mod (carrier G)) (G⦇ carrier := {𝟭} ⦈)" proof (-) (*goal: ‹(λX. the_elem ((λx. 𝟭) ` X)) ∈ Group.iso (G Mod carrier G) (G⦇carrier := {𝟭}⦈)›*) have "group (G⦇carrier := {𝟭}⦈)" by (metis subgroup_imp_group (*‹subgroup (?H::'a set) G ⟹ Group.group (G⦇carrier := ?H⦈)›*) triv_subgroup (*‹subgroup {𝟭} G›*)) hence "group_hom G (G⦇carrier := {𝟭}⦈) (λx. 𝟭)" unfolding group_hom_def group_hom_axioms_def hom_def (*goal: ‹Group.group G ∧ Group.group (G⦇carrier := {𝟭}⦈) ∧ (λx. 𝟭) ∈ {h ∈ carrier G → carrier (G⦇carrier := {𝟭}⦈). ∀x∈carrier G. ∀y∈carrier G. h (x ⊗ y) = h x ⊗⇘G⦇carrier := {𝟭}⦈⇙ h y}›*) using is_group (*‹Group.group G›*) by auto moreover have "(λx. 𝟭) ` carrier G = carrier (G⦇carrier := {𝟭}⦈)" by auto moreover have "kernel G (G⦇carrier := {𝟭}⦈) (λx. 𝟭) = carrier G" unfolding kernel_def (*goal: ‹{x::'a ∈ carrier G. 𝟭 = 𝟭⇘G⦇carrier := {𝟭}⦈⇙} = carrier G›*) by auto ultimately show "?thesis" (*goal: ‹(λX. the_elem ((λx. 𝟭) ` X)) ∈ Group.iso (G Mod carrier G) (G⦇carrier := {𝟭}⦈)›*) using group_hom.FactGroup_iso_set (*‹⟦group_hom ?G ?H ?h; ?h ` carrier ?G = carrier ?H⟧ ⟹ (λX. the_elem (?h ` X)) ∈ Group.iso (?G Mod kernel ?G ?H ?h) ?H›*) by force qed text ‹Factoring by a normal subgroups yields the trivial group iff the subgroup is the whole group.› lemma (in normal) fact_group_trivial_iff: assumes "finite (carrier G)" shows "(carrier (G Mod H) = {𝟭⇘G Mod H⇙}) ⟷ (H = carrier G)" proof (standard) (*goals: 1. ‹carrier (G Mod (H::'a set)) = {𝟭⇘G Mod H⇙} ⟹ H = carrier G› 2. ‹(H::'a set) = carrier G ⟹ carrier (G Mod H) = {𝟭⇘G Mod H⇙}›*) assume "carrier (G Mod H) = {𝟭⇘G Mod H⇙}" (*‹carrier (G Mod (H::'a set)) = {𝟭⇘G Mod H⇙}›*) moreover have "order (G Mod H) * card H = order G" by (simp add: FactGroup_def (*‹?G Mod ?H = ⦇carrier = rcosets⇘?G⇙ ?H, mult = (<#>⇘?G⇙), one = ?H⦈›*) lagrange (*‹subgroup ?H G ⟹ card (rcosets ?H) * card ?H = order G›*) order_def (*‹order ?S = card (carrier ?S)›*) subgroup_axioms (*‹subgroup H G›*)) ultimately have "card H = order G" unfolding order_def (*goal: ‹card H = card (carrier G)›*) by auto thus "H = carrier G" by (simp add: assms (*‹finite (carrier G)›*) card_subset_eq (*‹⟦finite ?B; ?A ⊆ ?B; card ?A = card ?B⟧ ⟹ ?A = ?B›*) order_def (*‹order ?S = card (carrier ?S)›*) subset (*‹H ⊆ carrier G›*)) next (*goal: ‹H = carrier G ⟹ carrier (G Mod H) = {𝟭⇘G Mod H⇙}›*) assume "H = carrier G" (*‹(H::'a set) = carrier G›*) with assms (*‹finite (carrier G)›*) is_subgroup (*‹subgroup H G›*) lagrange (*‹subgroup ?H G ⟹ card (rcosets ?H) * card ?H = order G›*) have "card (rcosets H) * order G = order G" by (simp add: order_def (*‹order ?S = card (carrier ?S)›*)) then have "card (rcosets H) = 1" using assms (*‹finite (carrier G)›*) order_gt_0_iff_finite (*‹(0 < order G) = finite (carrier G)›*) by auto hence "order (G Mod H) = 1" unfolding order_def FactGroup_def (*goal: ‹card (carrier ⦇carrier = rcosets H, mult = (<#>), one = H⦈) = 1›*) by auto thus "carrier (G Mod H) = {𝟭⇘G Mod H⇙}" using factorgroup_is_group (*‹Group.group (G Mod H)›*) by (metis group.order_one_triv_iff (*‹Group.group ?G ⟹ (order ?G = 1) = (carrier ?G = {𝟭⇘?G⇙})›*)) qed text ‹The union of all the cosets contained in a subgroup of a quotient group acts as a represenation for that subgroup.› lemma (in normal) factgroup_subgroup_union_char: assumes "subgroup A (G Mod H)" shows "(⋃A) = {x ∈ carrier G. H #> x ∈ A}" proof (standard) (*goals: 1. ‹⋃ (A::'a set set) ⊆ {x::'a ∈ carrier G. (H::'a set) #> x ∈ A}› 2. ‹{x::'a ∈ carrier G. (H::'a set) #> x ∈ (A::'a set set)} ⊆ ⋃ A›*) show "⋃A ⊆ {x ∈ carrier G. H #> x ∈ A}" proof (standard) (*goal: ‹⋀x. x ∈ ⋃ A ⟹ x ∈ {x ∈ carrier G. H #> x ∈ A}›*) fix x assume x: "x ∈ ⋃A" (*‹(x::'a) ∈ ⋃ (A::'a set set)›*) then obtain a where a: "a ∈ A" "x ∈ a" and xx: "x ∈ carrier G" (*goal: ‹(⋀a. ⟦a ∈ A; x ∈ a; x ∈ carrier G⟧ ⟹ thesis) ⟹ thesis›*) using subgroup.subset (*‹subgroup ?H ?G ⟹ ?H ⊆ carrier ?G›*) assms (*‹subgroup A (G Mod H)›*) by (force simp add: FactGroup_def (*‹?G Mod ?H = ⦇carrier = rcosets⇘?G⇙ ?H, mult = (<#>⇘?G⇙), one = ?H⦈›*) RCOSETS_def (*‹rcosets⇘?G⇙ ?H = (⋃a∈carrier ?G. {?H #>⇘?G⇙ a})›*) r_coset_def (*‹?H #>⇘?G⇙ ?a = (⋃h∈?H. {h ⊗⇘?G⇙ ?a})›*)) from assms (*‹subgroup A (G Mod H)›*) a (*‹a ∈ A› ‹(x::'a) ∈ (a::'a set)›*) obtain y where y: "y ∈ carrier G" "a = H #> y" (*goal: ‹(⋀y. ⟦y ∈ carrier G; a = H #> y⟧ ⟹ thesis) ⟹ thesis›*) using subgroup.subset (*‹subgroup ?H ?G ⟹ ?H ⊆ carrier ?G›*) unfolding FactGroup_def RCOSETS_def (*goal: ‹(⋀y. ⟦y ∈ carrier G; a = H #> y⟧ ⟹ thesis) ⟹ thesis›*) by force with a (*‹(a::'a set) ∈ (A::'a set set)› ‹x ∈ a›*) have "x ∈ H #> y" by simp hence "H #> y = H #> x" using y (*‹(y::'a::type) ∈ carrier G› ‹(a::'a::type set) = (H::'a::type set) #> (y::'a::type)›*) is_subgroup (*‹subgroup H G›*) repr_independence (*‹⟦?y ∈ ?H #> ?x; ?x ∈ carrier G; subgroup ?H G⟧ ⟹ ?H #> ?x = ?H #> ?y›*) by auto with y(2) (*‹a = H #> y›*) a(1) (*‹a ∈ A›*) have "H #> x ∈ A" by auto with xx (*‹x ∈ carrier G›*) show "x ∈ {x ∈ carrier G. H #> x ∈ A}" by simp qed next (*goal: ‹{x ∈ carrier G. H #> x ∈ A} ⊆ ⋃ A›*) show "{x ∈ carrier G. H #> x ∈ A} ⊆ ⋃A" using rcos_self (*‹⟦?x ∈ carrier G; subgroup ?H G⟧ ⟹ ?x ∈ ?H #> ?x›*) subgroup_axioms (*‹subgroup (H::'a set) G›*) by auto qed lemma (in normal) factgroup_subgroup_union_subgroup: assumes "subgroup A (G Mod H)" shows "subgroup (⋃A) G" proof (-) (*goal: ‹subgroup (⋃ A) G›*) have "subgroup {x ∈ carrier G. H #> x ∈ A} G" proof (standard) (*goals: 1. ‹{x ∈ carrier G. H #> x ∈ A} ⊆ carrier G› 2. ‹⋀x y. ⟦x ∈ {x ∈ carrier G. H #> x ∈ A}; y ∈ {x ∈ carrier G. H #> x ∈ A}⟧ ⟹ x ⊗ y ∈ {x ∈ carrier G. H #> x ∈ A}› 3. ‹𝟭 ∈ {x ∈ carrier G. H #> x ∈ A}› 4. ‹⋀x. x ∈ {x ∈ carrier G. H #> x ∈ A} ⟹ inv x ∈ {x ∈ carrier G. H #> x ∈ A}›*) show "{x ∈ carrier G. H #> x ∈ A} ⊆ carrier G" by auto next (*goals: 1. ‹⋀(x::'a) y::'a. ⟦x ∈ {x::'a ∈ carrier G. (H::'a set) #> x ∈ (A::'a set set)}; y ∈ {x::'a ∈ carrier G. H #> x ∈ A}⟧ ⟹ x ⊗ y ∈ {x::'a ∈ carrier G. H #> x ∈ A}› 2. ‹𝟭 ∈ {x::'a ∈ carrier G. (H::'a set) #> x ∈ (A::'a set set)}› 3. ‹⋀x::'a. x ∈ {x::'a ∈ carrier G. (H::'a set) #> x ∈ (A::'a set set)} ⟹ inv x ∈ {x::'a ∈ carrier G. H #> x ∈ A}›*) fix x and y assume xy: "x ∈ {x ∈ carrier G. H #> x ∈ A}" "y ∈ {x ∈ carrier G. H #> x ∈ A}" (*‹(x::'a) ∈ {x::'a ∈ carrier G. (H::'a set) #> x ∈ (A::'a set set)}› ‹(y::'a) ∈ {x::'a ∈ carrier G. (H::'a set) #> x ∈ (A::'a set set)}›*) then have "(H #> x) <#> (H #> y) ∈ A" using subgroup.m_closed (*‹⟦subgroup ?H ?G; ?x ∈ ?H; ?y ∈ ?H⟧ ⟹ ?x ⊗⇘?G⇙ ?y ∈ ?H›*) assms (*‹subgroup A (G Mod H)›*) unfolding FactGroup_def (*goal: ‹H #> x <#> (H #> y) ∈ A›*) by fastforce hence "H #> (x ⊗ y) ∈ A" using xy (*‹x ∈ {x ∈ carrier G. H #> x ∈ A}› ‹y ∈ {x ∈ carrier G. H #> x ∈ A}›*) rcos_sum (*‹⟦(?x::'a::type) ∈ carrier G; (?y::'a::type) ∈ carrier G⟧ ⟹ (H::'a::type set) #> ?x <#> (H #> ?y) = H #> ?x ⊗ ?y›*) by force with xy (*‹x ∈ {x ∈ carrier G. H #> x ∈ A}› ‹y ∈ {x ∈ carrier G. H #> x ∈ A}›*) show "x ⊗ y ∈ {x ∈ carrier G. H #> x ∈ A}" by blast next (*goals: 1. ‹𝟭 ∈ {x::'a::type ∈ carrier G. (H::'a::type set) #> x ∈ (A::'a::type set set)}› 2. ‹⋀x::'a::type. x ∈ {x::'a::type ∈ carrier G. (H::'a::type set) #> x ∈ (A::'a::type set set)} ⟹ inv x ∈ {x::'a::type ∈ carrier G. H #> x ∈ A}›*) have "H #> 𝟭 ∈ A" using assms (*‹subgroup (A::'a::type set set) (G Mod (H::'a::type set))›*) subgroup.one_closed (*‹subgroup ?H ?G ⟹ 𝟭⇘?G⇙ ∈ ?H›*) subset (*‹H ⊆ carrier G›*) by fastforce with assms (*‹subgroup (A::'a::type set set) (G Mod (H::'a::type set))›*) one_closed (*‹𝟭 ∈ carrier G›*) show "𝟭 ∈ {x ∈ carrier G. H #> x ∈ A}" by simp next (*goal: ‹⋀x::'a. x ∈ {x::'a ∈ carrier G. (H::'a set) #> x ∈ (A::'a set set)} ⟹ inv x ∈ {x::'a ∈ carrier G. H #> x ∈ A}›*) fix x assume x: "x ∈ {x ∈ carrier G. H #> x ∈ A}" (*‹(x::'a) ∈ {x::'a ∈ carrier G. (H::'a set) #> x ∈ (A::'a set set)}›*) hence invx: "inv x ∈ carrier G" using inv_closed (*‹?x ∈ carrier G ⟹ inv ?x ∈ carrier G›*) by simp from assms (*‹subgroup A (G Mod H)›*) x (*‹x ∈ {x ∈ carrier G. H #> x ∈ A}›*) have "set_inv (H #> x) ∈ A" using subgroup.m_inv_closed (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ inv⇘?G⇙ ?x ∈ ?H›*) using inv_FactGroup (*‹?X ∈ carrier (G Mod H) ⟹ inv⇘G Mod H⇙ ?X = set_inv ?X›*) subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*) by fastforce with invx (*‹inv x ∈ carrier G›*) show "inv x ∈ {x ∈ carrier G. H #> x ∈ A}" using rcos_inv (*‹(?x::'a) ∈ carrier G ⟹ set_inv ((H::'a set) #> ?x) = H #> inv ?x›*) x (*‹x ∈ {x ∈ carrier G. H #> x ∈ A}›*) by force qed with assms (*‹subgroup A (G Mod H)›*) factgroup_subgroup_union_char (*‹subgroup ?A (G Mod H) ⟹ ⋃ ?A = {x ∈ carrier G. H #> x ∈ ?A}›*) show "?thesis" (*goal: ‹subgroup (⋃ A) G›*) by auto qed lemma (in normal) factgroup_subgroup_union_normal: assumes "A ⊲ (G Mod H)" shows "⋃A ⊲ G" proof (-) (*goal: ‹⋃ A ⊲ G›*) have "{x ∈ carrier G. H #> x ∈ A} ⊲ G" unfolding normal_def normal_axioms_def (*goal: ‹subgroup {x ∈ carrier G. H #> x ∈ A} G ∧ Group.group G ∧ (∀x∈carrier G. {x ∈ carrier G. H #> x ∈ A} #> x = x <# {x ∈ carrier G. H #> x ∈ A})›*) proof (intro conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*) strip (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q› ‹(⋀x. ?P x) ⟹ ∀x. ?P x› ‹(⋀x. x ∈ ?A ⟹ ?P x) ⟹ ∀x∈?A. ?P x›*)) (*goals: 1. ‹subgroup {x ∈ carrier G. H #> x ∈ A} G› 2. ‹Group.group G› 3. ‹⋀x. x ∈ carrier G ⟹ {x ∈ carrier G. H #> x ∈ A} #> x = x <# {x ∈ carrier G. H #> x ∈ A}›*) from assms (*‹A ⊲ G Mod H›*) show "subgroup {x ∈ carrier G. H #> x ∈ A} G" by (metis (full_types) factgroup_subgroup_union_char (*‹subgroup ?A (G Mod H) ⟹ ⋃ ?A = {x ∈ carrier G. H #> x ∈ ?A}›*) factgroup_subgroup_union_subgroup (*‹subgroup ?A (G Mod H) ⟹ subgroup (⋃ ?A) G›*) normal_imp_subgroup (*‹?H ⊲ ?G ⟹ subgroup ?H ?G›*)) next (*goals: 1. ‹Group.group G› 2. ‹⋀x. x ∈ carrier G ⟹ {x ∈ carrier G. H #> x ∈ A} #> x = x <# {x ∈ carrier G. H #> x ∈ A}›*) interpret Anormal: normal A "(G Mod H)" using assms (*‹(A::'a set set) ⊲ G Mod (H::'a set)›*) by simp show "{x ∈ carrier G. H #> x ∈ A} #> x = x <# {x ∈ carrier G. H #> x ∈ A}" if x: "x ∈ carrier G" for x proof (-) (*goal: ‹{x ∈ carrier G. H #> x ∈ A} #> x = x <# {x ∈ carrier G. H #> x ∈ A}›*) { fix y assume y: "y ∈ {x ∈ carrier G. H #> x ∈ A} #> x" (*‹(y::'a) ∈ {x::'a ∈ carrier G. (H::'a set) #> x ∈ (A::'a set set)} #> (x::'a)›*) then obtain x' where x': "x' ∈ carrier G" "H #> x' ∈ A" "y = x' ⊗ x" (*goal: ‹(⋀x'. ⟦x' ∈ carrier G; H #> x' ∈ A; y = x' ⊗ x⟧ ⟹ thesis) ⟹ thesis›*) unfolding r_coset_def (*goal: ‹(⋀x'::'a::type. ⟦x' ∈ carrier G; (⋃h::'a::type∈H::'a::type set. {h ⊗ x'}) ∈ (A::'a::type set set); (y::'a::type) = x' ⊗ (x::'a::type)⟧ ⟹ thesis::bool) ⟹ thesis›*) by auto from x(1) (*‹x ∈ carrier G›*) have Hx: "H #> x ∈ carrier (G Mod H)" unfolding FactGroup_def RCOSETS_def (*goal: ‹H #> x ∈ carrier ⦇carrier = ⋃a∈carrier G. {H #> a}, mult = (<#>), one = H⦈›*) by force with x' (*‹x' ∈ carrier G› ‹H #> x' ∈ A› ‹y = x' ⊗ x›*) have "(inv⇘G Mod H⇙ (H #> x)) ⊗⇘G Mod H⇙ (H #> x') ⊗⇘G Mod H⇙ (H #> x) ∈ A" using Anormal.inv_op_closed1 (*‹⟦(?x::'a set) ∈ carrier (G Mod (H::'a set)); (?h::'a set) ∈ (A::'a set set)⟧ ⟹ inv⇘G Mod H⇙ ?x ⊗⇘G Mod H⇙ ?h ⊗⇘G Mod H⇙ ?x ∈ A›*) by auto hence "(set_inv (H #> x)) <#> (H #> x') <#> (H #> x) ∈ A" using inv_FactGroup (*‹?X ∈ carrier (G Mod H) ⟹ inv⇘G Mod H⇙ ?X = set_inv ?X›*) Hx (*‹H #> x ∈ carrier (G Mod H)›*) unfolding FactGroup_def (*goal: ‹set_inv (H #> x) <#> (H #> x') <#> (H #> x) ∈ A›*) by auto hence "(H #> (inv x)) <#> (H #> x') <#> (H #> x) ∈ A" using x(1) (*‹x ∈ carrier G›*) by (metis rcos_inv (*‹?x ∈ carrier G ⟹ set_inv (H #> ?x) = H #> inv ?x›*)) hence "H #> (inv x ⊗ x' ⊗ x) ∈ A" by (metis inv_closed (*‹(?x::'a::type) ∈ carrier G ⟹ inv ?x ∈ carrier G›*) m_closed (*‹⟦(?x::'a::type) ∈ carrier G; (?y::'a::type) ∈ carrier G⟧ ⟹ ?x ⊗ ?y ∈ carrier G›*) rcos_sum (*‹⟦(?x::'a::type) ∈ carrier G; (?y::'a::type) ∈ carrier G⟧ ⟹ (H::'a::type set) #> ?x <#> (H #> ?y) = H #> ?x ⊗ ?y›*) x'( (*‹(x'::'a::type) ∈ carrier G›*) 1) x( (*‹(x::'a::type) ∈ carrier G›*) 1)) moreover have "inv x ⊗ x' ⊗ x ∈ carrier G" using x (*‹x ∈ carrier G›*) x' (*‹x' ∈ carrier G› ‹H #> x' ∈ A› ‹y = x' ⊗ x›*) by (metis inv_closed (*‹(?x::'a) ∈ carrier G ⟹ inv ?x ∈ carrier G›*) m_closed (*‹⟦(?x::'a) ∈ carrier G; (?y::'a) ∈ carrier G⟧ ⟹ ?x ⊗ ?y ∈ carrier G›*)) ultimately have xcoset: "x ⊗ (inv x ⊗ x' ⊗ x) ∈ x <# {x ∈ carrier G. H #> x ∈ A}" unfolding l_coset_def (*goal: ‹x ⊗ (inv x ⊗ x' ⊗ x) ∈ (⋃h∈{x ∈ carrier G. H #> x ∈ A}. {x ⊗ h})›*) using x(1) (*‹x ∈ carrier G›*) by auto have "x ⊗ (inv x ⊗ x' ⊗ x) = (x ⊗ inv x) ⊗ x' ⊗ x" by (metis Units_eq (*‹Units G = carrier G›*) Units_inv_Units (*‹?x ∈ Units G ⟹ inv ?x ∈ Units G›*) m_assoc (*‹⟦?x ∈ carrier G; ?y ∈ carrier G; ?z ∈ carrier G⟧ ⟹ ?x ⊗ ?y ⊗ ?z = ?x ⊗ (?y ⊗ ?z)›*) m_closed (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ ?x ⊗ ?y ∈ carrier G›*) x'( (*‹x' ∈ carrier G›*) 1) x( (*‹x ∈ carrier G›*) 1)) also (*calculation: ‹x ⊗ (inv x ⊗ x' ⊗ x) = x ⊗ inv x ⊗ x' ⊗ x›*) have "… = y" by (simp add: x (*‹x ∈ carrier G›*) x' (*‹x' ∈ carrier G› ‹H #> x' ∈ A› ‹y = x' ⊗ x›*)) finally (*calculation: ‹x ⊗ (inv x ⊗ x' ⊗ x) = y›*) have "x ⊗ (inv x ⊗ x' ⊗ x) = y" . with xcoset (*‹x ⊗ (inv x ⊗ x' ⊗ x) ∈ x <# {x ∈ carrier G. H #> x ∈ A}›*) have "y ∈ x <# {x ∈ carrier G. H #> x ∈ A}" by auto } moreover { fix y assume y: "y ∈ x <# {x ∈ carrier G. H #> x ∈ A}" (*‹(y::'a) ∈ (x::'a) <# {x::'a ∈ carrier G. (H::'a set) #> x ∈ (A::'a set set)}›*) then obtain x' where x': "x' ∈ carrier G" "H #> x' ∈ A" "y = x ⊗ x'" (*goal: ‹(⋀x'. ⟦x' ∈ carrier G; H #> x' ∈ A; y = x ⊗ x'⟧ ⟹ thesis) ⟹ thesis›*) unfolding l_coset_def (*goal: ‹(⋀x'. ⟦x' ∈ carrier G; H #> x' ∈ A; y = x ⊗ x'⟧ ⟹ thesis) ⟹ thesis›*) by auto from x(1) (*‹x ∈ carrier G›*) have invx: "inv x ∈ carrier G" by (rule inv_closed (*‹(?x::'a) ∈ carrier G ⟹ inv ?x ∈ carrier G›*)) hence Hinvx: "H #> (inv x) ∈ carrier (G Mod H)" unfolding FactGroup_def RCOSETS_def (*goal: ‹H #> inv x ∈ carrier ⦇carrier = ⋃a∈carrier G. {H #> a}, mult = (<#>), one = H⦈›*) by force with x' (*‹x' ∈ carrier G› ‹H #> x' ∈ A› ‹y = x ⊗ x'›*) have "(inv⇘G Mod H⇙ (H #> inv x)) ⊗⇘G Mod H⇙ (H #> x') ⊗⇘G Mod H⇙ (H #> inv x) ∈ A" using invx (*‹inv x ∈ carrier G›*) Anormal.inv_op_closed1 (*‹⟦(?x::'a::type set) ∈ carrier (G Mod (H::'a::type set)); (?h::'a::type set) ∈ (A::'a::type set set)⟧ ⟹ inv⇘G Mod H⇙ ?x ⊗⇘G Mod H⇙ ?h ⊗⇘G Mod H⇙ ?x ∈ A›*) by auto hence "(set_inv (H #> inv x)) <#> (H #> x') <#> (H #> inv x) ∈ A" using inv_FactGroup (*‹?X ∈ carrier (G Mod H) ⟹ inv⇘G Mod H⇙ ?X = set_inv ?X›*) Hinvx (*‹H #> inv x ∈ carrier (G Mod H)›*) unfolding FactGroup_def (*goal: ‹set_inv (H #> inv x) <#> (H #> x') <#> (H #> inv x) ∈ A›*) by auto hence "H #> (x ⊗ x' ⊗ inv x) ∈ A" by (simp add: rcos_inv (*‹?x ∈ carrier G ⟹ set_inv (H #> ?x) = H #> inv ?x›*) rcos_sum (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ H #> ?x <#> (H #> ?y) = H #> ?x ⊗ ?y›*) x (*‹x ∈ carrier G›*) x'( (*‹x' ∈ carrier G›*) 1)) moreover have "x ⊗ x' ⊗ inv x ∈ carrier G" using x (*‹x ∈ carrier G›*) x' (*‹x' ∈ carrier G› ‹H #> x' ∈ A› ‹y = x ⊗ x'›*) by (metis inv_closed (*‹?x ∈ carrier G ⟹ inv ?x ∈ carrier G›*) m_closed (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ ?x ⊗ ?y ∈ carrier G›*)) ultimately have xcoset: "(x ⊗ x' ⊗ inv x) ⊗ x ∈ {x ∈ carrier G. H #> x ∈ A} #> x" unfolding r_coset_def (*goal: ‹x ⊗ x' ⊗ inv x ⊗ x ∈ (⋃h∈{x ∈ carrier G. (⋃h∈H. {h ⊗ x}) ∈ A}. {h ⊗ x})›*) using invx (*‹inv x ∈ carrier G›*) by auto have "(x ⊗ x' ⊗ inv x) ⊗ x = (x ⊗ x') ⊗ (inv x ⊗ x)" by (metis Units_eq (*‹Units G = carrier G›*) Units_inv_Units (*‹?x ∈ Units G ⟹ inv ?x ∈ Units G›*) m_assoc (*‹⟦?x ∈ carrier G; ?y ∈ carrier G; ?z ∈ carrier G⟧ ⟹ ?x ⊗ ?y ⊗ ?z = ?x ⊗ (?y ⊗ ?z)›*) m_closed (*‹⟦?x ∈ carrier G; ?y ∈ carrier G⟧ ⟹ ?x ⊗ ?y ∈ carrier G›*) x'( (*‹x' ∈ carrier G›*) 1) x( (*‹x ∈ carrier G›*) 1)) also (*calculation: ‹(x::'a) ⊗ (x'::'a) ⊗ inv x ⊗ x = x ⊗ x' ⊗ (inv x ⊗ x)›*) have "… = y" by (simp add: x (*‹x ∈ carrier G›*) x' (*‹x' ∈ carrier G› ‹H #> x' ∈ A› ‹y = x ⊗ x'›*)) finally (*calculation: ‹x ⊗ x' ⊗ inv x ⊗ x = y›*) have "x ⊗ x' ⊗ inv x ⊗ x = y" . with xcoset (*‹x ⊗ x' ⊗ inv x ⊗ x ∈ {x ∈ carrier G. H #> x ∈ A} #> x›*) have "y ∈ {x ∈ carrier G. H #> x ∈ A} #> x" by auto } ultimately show "?thesis" (*goal: ‹{x ∈ carrier G. H #> x ∈ A} #> x = x <# {x ∈ carrier G. H #> x ∈ A}›*) by auto qed qed (auto) (*solved the remaining goal: ‹Group.group G›*) with assms (*‹A ⊲ G Mod H›*) show "?thesis" (*goal: ‹⋃ (A::'a::type set set) ⊲ G›*) by (metis (full_types) factgroup_subgroup_union_char (*‹subgroup ?A (G Mod H) ⟹ ⋃ ?A = {x ∈ carrier G. H #> x ∈ ?A}›*) normal_imp_subgroup (*‹?H ⊲ ?G ⟹ subgroup ?H ?G›*)) qed lemma (in normal) factgroup_subgroup_union_factor: assumes "subgroup A (G Mod H)" shows "A = rcosets⇘G⦇carrier := ⋃A⦈⇙ H" using assms (*‹subgroup A (G Mod H)›*) subgroup.mem_carrier (*‹⟦subgroup ?H ?G; ?x ∈ ?H⟧ ⟹ ?x ∈ carrier ?G›*) factgroup_subgroup_union_char (*‹subgroup ?A (G Mod H) ⟹ ⋃ ?A = {x ∈ carrier G. H #> x ∈ ?A}›*) by (fastforce simp: RCOSETS_def (*‹rcosets⇘?G⇙ ?H = (⋃a∈carrier ?G. {?H #>⇘?G⇙ a})›*) FactGroup_def (*‹?G Mod ?H = ⦇carrier = rcosets⇘?G⇙ ?H, mult = (<#>⇘?G⇙), one = ?H⦈›*)) section ‹Flattening the type of group carriers› text ‹Flattening here means to convert the type of group elements from 'a set to 'a. This is possible whenever the empty set is not an element of the group. By Jakob von Raumer› definition flatten where "flatten (G::('a set, 'b) monoid_scheme) rep = ⦇carrier=(rep ` (carrier G)), monoid.mult=(λ x y. rep ((the_inv_into (carrier G) rep x) ⊗⇘G⇙ (the_inv_into (carrier G) rep y))), one=rep 𝟭⇘G⇙ ⦈" lemma flatten_set_group_hom: assumes group: "group G" assumes inj: "inj_on rep (carrier G)" shows "rep ∈ hom G (flatten G rep)" by (force simp add: hom_def (*‹hom ?G ?H = {h ∈ carrier ?G → carrier ?H. ∀x∈carrier ?G. ∀y∈carrier ?G. h (x ⊗⇘?G⇙ y) = h x ⊗⇘?H⇙ h y}›*) flatten_def (*‹flatten ?G ?rep = ⦇carrier = ?rep ` carrier ?G, mult = λx y. ?rep (the_inv_into (carrier ?G) ?rep x ⊗⇘?G⇙ the_inv_into (carrier ?G) ?rep y), one = ?rep 𝟭⇘?G⇙⦈›*) inj (*‹inj_on rep (carrier G)›*) the_inv_into_f_f (*‹⟦inj_on ?f ?A; ?x ∈ ?A⟧ ⟹ the_inv_into ?A ?f (?f ?x) = ?x›*)) lemma flatten_set_group: assumes "group G" "inj_on rep (carrier G)" shows "group (flatten G rep)" proof (rule groupI (*‹⟦⋀x y. ⟦x ∈ carrier ?G; y ∈ carrier ?G⟧ ⟹ x ⊗⇘?G⇙ y ∈ carrier ?G; 𝟭⇘?G⇙ ∈ carrier ?G; ⋀x y z. ⟦x ∈ carrier ?G; y ∈ carrier ?G; z ∈ carrier ?G⟧ ⟹ x ⊗⇘?G⇙ y ⊗⇘?G⇙ z = x ⊗⇘?G⇙ (y ⊗⇘?G⇙ z); ⋀x. x ∈ carrier ?G ⟹ 𝟭⇘?G⇙ ⊗⇘?G⇙ x = x; ⋀x. x ∈ carrier ?G ⟹ ∃y∈carrier ?G. y ⊗⇘?G⇙ x = 𝟭⇘?G⇙⟧ ⟹ Group.group ?G›*)) (*goals: 1. ‹⋀x y. ⟦x ∈ carrier (flatten G rep); y ∈ carrier (flatten G rep)⟧ ⟹ x ⊗⇘flatten G rep⇙ y ∈ carrier (flatten G rep)› 2. ‹𝟭⇘flatten G rep⇙ ∈ carrier (flatten G rep)› 3. ‹⋀x y z. ⟦x ∈ carrier (flatten G rep); y ∈ carrier (flatten G rep); z ∈ carrier (flatten G rep)⟧ ⟹ x ⊗⇘flatten G rep⇙ y ⊗⇘flatten G rep⇙ z = x ⊗⇘flatten G rep⇙ (y ⊗⇘flatten G rep⇙ z)› 4. ‹⋀x. x ∈ carrier (flatten G rep) ⟹ 𝟭⇘flatten G rep⇙ ⊗⇘flatten G rep⇙ x = x› 5. ‹⋀x. x ∈ carrier (flatten G rep) ⟹ ∃y∈carrier (flatten G rep). y ⊗⇘flatten G rep⇙ x = 𝟭⇘flatten G rep⇙›*) fix x and y assume "x ∈ carrier (flatten G rep)" and "y ∈ carrier (flatten G rep)" (*‹(x::'c) ∈ carrier (flatten (G::('a set, 'b) monoid_scheme) (rep::'a set ⇒ 'c))› ‹(y::'c) ∈ carrier (flatten (G::('a set, 'b) monoid_scheme) (rep::'a set ⇒ 'c))›*) then show "x ⊗⇘flatten G rep⇙ y ∈ carrier (flatten G rep)" using assms (*‹Group.group G› ‹inj_on rep (carrier G)›*) group.surj_const_mult (*‹⟦Group.group ?G; ?a ∈ carrier ?G⟧ ⟹ (⊗⇘?G⇙) ?a ` carrier ?G = carrier ?G›*) the_inv_into_f_f (*‹⟦inj_on ?f ?A; ?x ∈ ?A⟧ ⟹ the_inv_into ?A ?f (?f ?x) = ?x›*) by (fastforce simp: flatten_def (*‹flatten ?G ?rep = ⦇carrier = ?rep ` carrier ?G, mult = λx y. ?rep (the_inv_into (carrier ?G) ?rep x ⊗⇘?G⇙ the_inv_into (carrier ?G) ?rep y), one = ?rep 𝟭⇘?G⇙⦈›*)) next (*goals: 1. ‹𝟭⇘flatten G rep⇙ ∈ carrier (flatten G rep)› 2. ‹⋀x y z. ⟦x ∈ carrier (flatten G rep); y ∈ carrier (flatten G rep); z ∈ carrier (flatten G rep)⟧ ⟹ x ⊗⇘flatten G rep⇙ y ⊗⇘flatten G rep⇙ z = x ⊗⇘flatten G rep⇙ (y ⊗⇘flatten G rep⇙ z)› 3. ‹⋀x. x ∈ carrier (flatten G rep) ⟹ 𝟭⇘flatten G rep⇙ ⊗⇘flatten G rep⇙ x = x› 4. ‹⋀x. x ∈ carrier (flatten G rep) ⟹ ∃y∈carrier (flatten G rep). y ⊗⇘flatten G rep⇙ x = 𝟭⇘flatten G rep⇙›*) show "𝟭⇘flatten G rep⇙ ∈ carrier (flatten G rep)" unfolding flatten_def (*goal: ‹𝟭⇘⦇carrier = rep ` carrier G, mult = λx y. rep (the_inv_into (carrier G) rep x ⊗⇘G⇙ the_inv_into (carrier G) rep y), one = rep 𝟭⇘G⇙⦈⇙ ∈ carrier ⦇carrier = rep ` carrier G, mult = λx y. rep (the_inv_into (carrier G) rep x ⊗⇘G⇙ the_inv_into (carrier G) rep y), one = rep 𝟭⇘G⇙⦈›*) by (simp add: assms (*‹Group.group G› ‹inj_on rep (carrier G)›*) group.is_monoid (*‹Group.group ?G ⟹ Group.monoid ?G›*)) next (*goals: 1. ‹⋀x y z. ⟦x ∈ carrier (flatten G rep); y ∈ carrier (flatten G rep); z ∈ carrier (flatten G rep)⟧ ⟹ x ⊗⇘flatten G rep⇙ y ⊗⇘flatten G rep⇙ z = x ⊗⇘flatten G rep⇙ (y ⊗⇘flatten G rep⇙ z)› 2. ‹⋀x. x ∈ carrier (flatten G rep) ⟹ 𝟭⇘flatten G rep⇙ ⊗⇘flatten G rep⇙ x = x› 3. ‹⋀x. x ∈ carrier (flatten G rep) ⟹ ∃y∈carrier (flatten G rep). y ⊗⇘flatten G rep⇙ x = 𝟭⇘flatten G rep⇙›*) fix x and y and z assume "x ∈ carrier (flatten G rep)" "y ∈ carrier (flatten G rep)" "z ∈ carrier (flatten G rep)" (*‹(x::'c) ∈ carrier (flatten (G::('a set, 'b) monoid_scheme) (rep::'a set ⇒ 'c))› ‹(y::'c) ∈ carrier (flatten (G::('a set, 'b) monoid_scheme) (rep::'a set ⇒ 'c))› ‹(z::'c) ∈ carrier (flatten (G::('a set, 'b) monoid_scheme) (rep::'a set ⇒ 'c))›*) then show "x ⊗⇘flatten G rep⇙ y ⊗⇘flatten G rep⇙ z = x ⊗⇘flatten G rep⇙ (y ⊗⇘flatten G rep⇙ z)" by (auto simp: assms (*‹Group.group G› ‹inj_on rep (carrier G)›*) flatten_def (*‹flatten ?G ?rep = ⦇carrier = ?rep ` carrier ?G, mult = λx y. ?rep (the_inv_into (carrier ?G) ?rep x ⊗⇘?G⇙ the_inv_into (carrier ?G) ?rep y), one = ?rep 𝟭⇘?G⇙⦈›*) group.is_monoid (*‹Group.group ?G ⟹ Group.monoid ?G›*) monoid.m_assoc (*‹⟦Group.monoid ?G; ?x ∈ carrier ?G; ?y ∈ carrier ?G; ?z ∈ carrier ?G⟧ ⟹ ?x ⊗⇘?G⇙ ?y ⊗⇘?G⇙ ?z = ?x ⊗⇘?G⇙ (?y ⊗⇘?G⇙ ?z)›*) monoid.m_closed (*‹⟦Group.monoid ?G; ?x ∈ carrier ?G; ?y ∈ carrier ?G⟧ ⟹ ?x ⊗⇘?G⇙ ?y ∈ carrier ?G›*) the_inv_into_f_f (*‹⟦inj_on ?f ?A; ?x ∈ ?A⟧ ⟹ the_inv_into ?A ?f (?f ?x) = ?x›*)) next (*goals: 1. ‹⋀x. x ∈ carrier (flatten G rep) ⟹ 𝟭⇘flatten G rep⇙ ⊗⇘flatten G rep⇙ x = x› 2. ‹⋀x. x ∈ carrier (flatten G rep) ⟹ ∃y∈carrier (flatten G rep). y ⊗⇘flatten G rep⇙ x = 𝟭⇘flatten G rep⇙›*) fix x assume x: "x ∈ carrier (flatten G rep)" (*‹(x::'c) ∈ carrier (flatten (G::('a set, 'b) monoid_scheme) (rep::'a set ⇒ 'c))›*) then show "𝟭⇘flatten G rep⇙ ⊗⇘flatten G rep⇙ x = x" by (auto simp: assms (*‹Group.group G› ‹inj_on rep (carrier G)›*) group.is_monoid (*‹Group.group ?G ⟹ Group.monoid ?G›*) the_inv_into_f_f (*‹⟦inj_on ?f ?A; ?x ∈ ?A⟧ ⟹ the_inv_into ?A ?f (?f ?x) = ?x›*) flatten_def (*‹flatten ?G ?rep = ⦇carrier = ?rep ` carrier ?G, mult = λx y. ?rep (the_inv_into (carrier ?G) ?rep x ⊗⇘?G⇙ the_inv_into (carrier ?G) ?rep y), one = ?rep 𝟭⇘?G⇙⦈›*)) then have "∃y∈carrier G. rep (y ⊗⇘G⇙ z) = rep 𝟭⇘G⇙" if "z ∈ carrier G" for z by (metis ‹group G› group.l_inv_ex (*‹⟦Group.group ?G; ?x ∈ carrier ?G⟧ ⟹ ∃y∈carrier ?G. y ⊗⇘?G⇙ ?x = 𝟭⇘?G⇙›*) that (*‹z ∈ carrier G›*)) with assms (*‹Group.group (G::('a set, 'b) monoid_scheme)› ‹inj_on (rep::'a::type set ⇒ 'c::type) (carrier (G::('a set, 'b) monoid_scheme))›*) x (*‹x ∈ carrier (flatten G rep)›*) show "∃y∈carrier (flatten G rep). y ⊗⇘flatten G rep⇙ x = 𝟭⇘flatten G rep⇙" by (auto simp: flatten_def (*‹flatten ?G ?rep = ⦇carrier = ?rep ` carrier ?G, mult = λx y. ?rep (the_inv_into (carrier ?G) ?rep x ⊗⇘?G⇙ the_inv_into (carrier ?G) ?rep y), one = ?rep 𝟭⇘?G⇙⦈›*) the_inv_into_f_f (*‹⟦inj_on ?f ?A; ?x ∈ ?A⟧ ⟹ the_inv_into ?A ?f (?f ?x) = ?x›*)) qed lemma (in normal) flatten_set_group_mod_inj: shows "inj_on (λU. SOME g. g ∈ U) (carrier (G Mod H))" proof (rule inj_onI (*‹(⋀x y. ⟦x ∈ ?A; y ∈ ?A; ?f x = ?f y⟧ ⟹ x = y) ⟹ inj_on ?f ?A›*)) (*goal: ‹⋀x y. ⟦x ∈ carrier (G Mod H); y ∈ carrier (G Mod H); (SOME g. g ∈ x) = (SOME g. g ∈ y)⟧ ⟹ x = y›*) fix U and V assume U: "U ∈ carrier (G Mod H)" and V: "V ∈ carrier (G Mod H)" (*‹(U::'a set) ∈ carrier (G Mod (H::'a set))› ‹(V::'a set) ∈ carrier (G Mod (H::'a set))›*) then obtain g and h where g: "U = H #> g" "g ∈ carrier G" and h: "V = H #> h" "h ∈ carrier G" (*goal: ‹(⋀g h. ⟦U = H #> g; g ∈ carrier G; V = H #> h; h ∈ carrier G⟧ ⟹ thesis) ⟹ thesis›*) unfolding FactGroup_def RCOSETS_def (*goal: ‹(⋀g h. ⟦U = H #> g; g ∈ carrier G; V = H #> h; h ∈ carrier G⟧ ⟹ thesis) ⟹ thesis›*) by auto hence notempty: "U ≠ {}" "V ≠ {}" apply - (*goals: 1. ‹⟦U = H #> g; g ∈ carrier G; V = H #> h; h ∈ carrier G⟧ ⟹ U ≠ {}› 2. ‹⟦U = H #> g; g ∈ carrier G; V = H #> h; h ∈ carrier G⟧ ⟹ V ≠ {}› discuss goal 1*) apply (metis empty_iff (*‹((?c::?'a) ∈ {}) = False›*) is_subgroup (*‹subgroup (H::'a set) G›*) rcos_self (*‹⟦(?x::'a) ∈ carrier G; subgroup (?H::'a set) G⟧ ⟹ ?x ∈ ?H #> ?x›*)) (*discuss goal 2*) apply (metis empty_iff (*‹(?c ∈ {}) = False›*) is_subgroup (*‹subgroup H G›*) rcos_self (*‹⟦?x ∈ carrier G; subgroup ?H G⟧ ⟹ ?x ∈ ?H #> ?x›*)) (*proven 2 subgoals*) . assume "(SOME g. g ∈ U) = (SOME g. g ∈ V)" (*‹(SOME g::'a. g ∈ (U::'a set)) = (SOME g::'a. g ∈ (V::'a set))›*) with notempty (*‹U ≠ {}› ‹V ≠ {}›*) have "(SOME g. g ∈ U) ∈ U ∩ V" by (metis IntI (*‹⟦?c ∈ ?A; ?c ∈ ?B⟧ ⟹ ?c ∈ ?A ∩ ?B›*) ex_in_conv (*‹(∃x. x ∈ ?A) = (?A ≠ {})›*) someI (*‹?P ?x ⟹ ?P (Eps ?P)›*)) thus "U = V" by (metis Int_iff (*‹(?c ∈ ?A ∩ ?B) = (?c ∈ ?A ∧ ?c ∈ ?B)›*) g (*‹U = H #> g› ‹g ∈ carrier G›*) h (*‹V = H #> h› ‹h ∈ carrier G›*) is_subgroup (*‹subgroup H G›*) repr_independence (*‹⟦?y ∈ ?H #> ?x; ?x ∈ carrier G; subgroup ?H G⟧ ⟹ ?H #> ?x = ?H #> ?y›*)) qed lemma (in normal) flatten_set_group_mod: shows "group (flatten (G Mod H) (λU. SOME g. g ∈ U))" by (simp add: factorgroup_is_group (*‹Group.group (G Mod (H::'a set))›*) flatten_set_group (*‹⟦Group.group (?G::(?'a set, ?'b) monoid_scheme); inj_on (?rep::?'a set ⇒ ?'c) (carrier ?G)⟧ ⟹ Group.group (flatten ?G ?rep)›*) flatten_set_group_mod_inj (*‹inj_on (λU::'a set. SOME g::'a. g ∈ U) (carrier (G Mod (H::'a set)))›*)) lemma (in normal) flatten_set_group_mod_iso: shows "(λU. SOME g. g ∈ U) ∈ iso (G Mod H) (flatten (G Mod H) (λU. SOME g. g ∈ U))" proof (-) (*goal: ‹(λU. SOME g. g ∈ U) ∈ Group.iso (G Mod H) (flatten (G Mod H) (λU. SOME g. g ∈ U))›*) have "(λU. SOME g. g ∈ U) ∈ hom (G Mod H) (flatten (G Mod H) (λU. SOME g. g ∈ U))" using factorgroup_is_group (*‹Group.group (G Mod H)›*) flatten_set_group_hom (*‹⟦Group.group (?G::(?'a set, ?'b) monoid_scheme); inj_on (?rep::?'a::type set ⇒ ?'c::type) (carrier ?G)⟧ ⟹ ?rep ∈ hom ?G (flatten ?G ?rep)›*) flatten_set_group_mod_inj (*‹inj_on (λU. SOME g. g ∈ U) (carrier (G Mod H))›*) by blast moreover have "inj_on (λU. SOME g. g ∈ U) (carrier (G Mod H))" using flatten_set_group_mod_inj (*‹inj_on (λU. SOME g. g ∈ U) (carrier (G Mod H))›*) by blast ultimately show "?thesis" (*goal: ‹(λU. SOME g. g ∈ U) ∈ Group.iso (G Mod H) (flatten (G Mod H) (λU. SOME g. g ∈ U))›*) by (simp add: iso_def (*‹Group.iso ?G ?H = {h ∈ hom ?G ?H. bij_betw h (carrier ?G) (carrier ?H)}›*) bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*) flatten_def (*‹flatten ?G ?rep = ⦇carrier = ?rep ` carrier ?G, mult = λx y. ?rep (the_inv_into (carrier ?G) ?rep x ⊗⇘?G⇙ the_inv_into (carrier ?G) ?rep y), one = ?rep 𝟭⇘?G⇙⦈›*)) qed end
{ "path": "Isabelle2024/src/HOL/Algebra/Coset.thy", "repo": "Isabelle2024", "sha": "1f04909087455c55d370d187d0b01b1e100c01a9117e04493d8d2f7fed044951" }
section ‹Standard Rules› text ‹We define the standard rules here, and prove the relation to standard rules. This means proving that the graph rules do what they say they do.› theory StandardRules imports StandardModels RuleSemanticsConnection begin text ‹Definition 16 makes this remark. We don't have a specific version of Definition 16.› lemma conflict_free: ":G:⟦A_Lbl l⟧ = {} ⟷ (∀ (l',x,y)∈edges G. l' ≠ l)" by (auto simp:getRel_def (*‹getRel (?l::?'b::type) (?G::(?'b::type, ?'a::type) labeled_graph) = {(x::?'a::type, y::?'a::type). (?l, x, y) ∈ edges ?G}›*)) text ‹Definition 17, abstractly. It's unlikely that we wish to use the top rule for any symbol except top, but stating it abstractly makes it consistent with the other rules.› (* Definition 17 *) definition top_rule :: "'l ⇒ ('l,nat) Graph_PreRule" where "top_rule t = (LG {} {0,1},LG {(t,0,1)} {0,1})" text ‹Proof that definition 17 does what it says it does.› lemma top_rule[simp]: assumes "graph G" shows "maintained (top_rule r) G ⟷ vertices G × vertices G = getRel r G" proof (standard) (*goals: 1. ‹maintained (top_rule r) G ⟹ vertices G × vertices G = getRel r G› 2. ‹vertices G × vertices G = getRel r G ⟹ maintained (top_rule r) G›*) assume a: "maintained (top_rule r) G" (*‹maintained (top_rule (r::'a)) (G::('a, 'b) labeled_graph)›*) { fix a and b assume "a ∈ vertices G" "b ∈ vertices G" (*‹(a::'b) ∈ vertices (G::('a, 'b) labeled_graph)› ‹(b::'b) ∈ vertices (G::('a, 'b) labeled_graph)›*) hence "graph_homomorphism (LG {} {0, 1}) G {(0::nat,a),(1,b)}" using assms (*‹graph (G::('a, 'b) labeled_graph)›*) unfolding graph_homomorphism_def univalent_def (*goal: ‹vertices (LG {} {0::nat, 1::nat}) = Domain {(0::nat, a::'b::type), (1::nat, b::'b::type)} ∧ graph (LG {} {0::nat, 1::nat}) ∧ graph (G::('a::type, 'b::type) labeled_graph) ∧ {(0::nat, a), (1::nat, b)} `` vertices (LG {} {0::nat, 1::nat}) ⊆ vertices G ∧ (∀(x::nat) (y::'b::type) z::'b::type. (x, y) ∈ {(0::nat, a), (1::nat, b)} ∧ (x, z) ∈ {(0::nat, a), (1::nat, b)} ⟶ z = y) ∧ edge_preserving {(0::nat, a), (1::nat, b)} (edges (LG {} {0::nat, 1::nat})) (edges G)›*) by auto with a[unfolded maintained_def top_rule_def] (*‹∀f. graph_homomorphism (fst (LG {} {0, 1}, LG {(r, 0, 1)} {0, 1})) G f ⟶ extensible (LG {} {0, 1}, LG {(r, 0, 1)} {0, 1}) G f›*) extensible_refl_concr (*‹graph_homomorphism (LG ?e₁ ?v) ?G ?f ⟹ extensible (LG ?e₁ ?v, LG ?e₂ ?v) ?G ?f = graph_homomorphism (LG ?e₂ ?v) ?G ?f›*) have "graph_homomorphism (LG {(r, 0, 1)} {0::nat, 1}) G {(0::nat, a), (1, b)}" by simp hence "(a, b) ∈ getRel r G" unfolding graph_homomorphism_def2 graph_union_iff getRel_def (*goal: ‹(a, b) ∈ {(x, y). (r, x, y) ∈ edges G}›*) by auto } thus "vertices G × vertices G = getRel r G" using getRel_dom[OF assms] (*‹(?a::'b::type, ?b::'b::type) ∈ getRel (?l::'a::type) (G::('a::type, 'b::type) labeled_graph) ⟹ ?a ∈ vertices G› ‹(?a, ?b) ∈ getRel ?l G ⟹ ?b ∈ vertices G›*) by auto next (*goal: ‹vertices G × vertices G = getRel r G ⟹ maintained (top_rule r) G›*) assume a: "vertices G × vertices G = getRel r G" (*‹vertices (G::('a, 'b) labeled_graph) × vertices G = getRel (r::'a) G›*) { fix f assume a2: "graph_homomorphism (fst (top_rule r)) G f" (*‹graph_homomorphism (fst (top_rule (r::'a))) (G::('a, 'b) labeled_graph) (f::(nat × 'b) set)›*) hence f: "f `` {0, 1} ⊆ vertices G" "on_triple f `` {} ⊆ edges G" "univalent f" "Domain f = {0, 1}" unfolding top_rule_def prod.sel graph_homomorphism_concr_graph[OF assms graph_empty_e] (*goals: 1. ‹f `` {0, 1} ⊆ vertices G› 2. ‹on_triple f `` {} ⊆ edges G› 3. ‹univalent f› 4. ‹Domain f = {0, 1}›*) apply - (*goals: 1. ‹f `` {0, 1} ⊆ vertices G ∧ on_triple f `` {} ⊆ edges G ∧ univalent f ∧ Domain f = {0, 1} ⟹ f `` {0, 1} ⊆ vertices G› 2. ‹f `` {0, 1} ⊆ vertices G ∧ on_triple f `` {} ⊆ edges G ∧ univalent f ∧ Domain f = {0, 1} ⟹ on_triple f `` {} ⊆ edges G› 3. ‹f `` {0, 1} ⊆ vertices G ∧ on_triple f `` {} ⊆ edges G ∧ univalent f ∧ Domain f = {0, 1} ⟹ univalent f› 4. ‹f `` {0, 1} ⊆ vertices G ∧ on_triple f `` {} ⊆ edges G ∧ univalent f ∧ Domain f = {0, 1} ⟹ Domain f = {0, 1}› discuss goal 1*) apply argo (*discuss goal 2*) apply argo (*discuss goal 3*) apply argo (*discuss goal 4*) apply argo (*proven 4 subgoals*) . from a2 (*‹graph_homomorphism (fst (top_rule r)) G f›*) have ih: "graph_homomorphism (LG {} {0, 1}) G f" unfolding top_rule_def (*goal: ‹graph_homomorphism (LG {} {0::nat, 1::nat}) (G::('a, 'b) labeled_graph) (f::(nat × 'b) set)›*) by auto have "extensible (top_rule r) G f" unfolding top_rule_def extensible_refl_concr[OF ih] graph_homomorphism_concr_graph[OF assms graph_single] (*goal: ‹f `` {0, 1} ⊆ vertices G ∧ on_triple f `` {(r, 0, 1)} ⊆ edges G ∧ univalent f ∧ Domain f = {0, 1}›*) using f (*‹f `` {0, 1} ⊆ vertices G› ‹on_triple f `` {} ⊆ edges G› ‹univalent (f::(nat × 'b) set)› ‹Domain f = {0, 1}›*) a[unfolded getRel_def] (*‹vertices (G::('a, 'b) labeled_graph) × vertices G = {(x::'b, y::'b). (r::'a, x, y) ∈ edges G}›*) by fastforce } thus "maintained (top_rule r) G" unfolding maintained_def (*goal: ‹∀f. graph_homomorphism (fst (top_rule r)) G f ⟶ extensible (top_rule r) G f›*) by auto qed text ‹Definition 18.› (* Definition 18 *) definition nonempty_rule :: "('l,nat) Graph_PreRule" where "nonempty_rule = (LG {} {},LG {} {0})" text ‹Proof that definition 18 does what it says it does.› lemma nonempty_rule[simp]: assumes "graph G" shows "maintained nonempty_rule G ⟷ vertices G ≠ {}" proof (-) (*goal: ‹maintained nonempty_rule G = (vertices G ≠ {})›*) have "vertices G = {} ⟹ graph_homomorphism (LG {} {0}) G x ⟹ False" "v ∈ vertices G ⟹ graph_homomorphism (LG {} {0}) G {(0,v)}" for v :: 'b and x :: "(nat × 'b) set" unfolding graph_homomorphism_concr_graph[OF assms graph_empty_e] univalent_def (*goals: 1. ‹⟦vertices (G::('a, 'b) labeled_graph) = {}; (x::(nat × 'b) set) `` {0::nat} ⊆ vertices G ∧ on_triple x `` {} ⊆ edges G ∧ (∀(xa::nat) (y::'b) z::'b. (xa, y) ∈ x ∧ (xa, z) ∈ x ⟶ z = y) ∧ Domain x = {0::nat}⟧ ⟹ False› 2. ‹(v::'b) ∈ vertices (G::('a, 'b) labeled_graph) ⟹ {(0::'c, v)} `` {0::'c} ⊆ vertices G ∧ on_triple {(0::'c, v)} `` {} ⊆ edges G ∧ (∀(x::'c) (y::'b) z::'b. (x, y) ∈ {(0::'c, v)} ∧ (x, z) ∈ {(0::'c, v)} ⟶ z = y) ∧ Domain {(0::'c, v)} = {0::'c}›*) (*goals: 1. ‹⟦vertices G = {}; x `` {0} ⊆ vertices G ∧ on_triple x `` {} ⊆ edges G ∧ (∀xa y z. (xa, y) ∈ x ∧ (xa, z) ∈ x ⟶ z = y) ∧ Domain x = {0}⟧ ⟹ False› 2. ‹v ∈ vertices G ⟹ {(0, v)} `` {0} ⊆ vertices G ∧ on_triple {(0, v)} `` {} ⊆ edges G ∧ (∀x y z. (x, y) ∈ {(0, v)} ∧ (x, z) ∈ {(0, v)} ⟶ z = y) ∧ Domain {(0, v)} = {0}› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) . thus "?thesis" (*goal: ‹maintained nonempty_rule G = (vertices G ≠ {})›*) unfolding nonempty_rule_def maintained_def extensible_def (*goal: ‹(∀f. graph_homomorphism (fst (LG {} {}, LG {} {0})) G f ⟶ (∃g. graph_homomorphism (snd (LG {} {}, LG {} {0})) G g ∧ agree_on (fst (LG {} {}, LG {} {0})) f g)) = (vertices G ≠ {})›*) by (auto intro:assms (*‹graph G›*)) qed text ‹Definition 19.› definition reflexivity_rule :: "'l ⇒ ('l,nat) Graph_PreRule" where "reflexivity_rule t = (LG {} {0},LG {(t,0,0)} {0})" definition symmetry_rule :: "'l ⇒ ('l,nat) Graph_PreRule" where "symmetry_rule t = (transl_rule (A_Cnv (A_Lbl t) ⊑ A_Lbl t))" definition transitive_rule :: "'l ⇒ ('l,nat) Graph_PreRule" where "transitive_rule t = (transl_rule (A_Cmp (A_Lbl t) (A_Lbl t) ⊑ A_Lbl t))" definition congruence_rule :: "'l ⇒ 'l ⇒ ('l,nat) Graph_PreRule" where "congruence_rule t l = (transl_rule (A_Cmp (A_Cmp (A_Lbl t) (A_Lbl l)) (A_Lbl t) ⊑ A_Lbl l))" abbreviation congruence_rules :: "'l ⇒ 'l set ⇒ ('l,nat) Graph_PreRule set" where "congruence_rules t L ≡ congruence_rule t ` L" lemma are_rules[intro]: "graph_rule nonempty_rule" "graph_rule (top_rule t)" "graph_rule (reflexivity_rule i)" unfolding reflexivity_rule_def top_rule_def nonempty_rule_def graph_homomorphism_def (*goals: 1. ‹(vertices (fst (LG {} {}, LG {} {0})) = Domain (Id_on (vertices (fst (LG {} {}, LG {} {0})))) ∧ graph (fst (LG {} {}, LG {} {0})) ∧ graph (snd (LG {} {}, LG {} {0})) ∧ Id_on (vertices (fst (LG {} {}, LG {} {0}))) `` vertices (fst (LG {} {}, LG {} {0})) ⊆ vertices (snd (LG {} {}, LG {} {0})) ∧ univalent (Id_on (vertices (fst (LG {} {}, LG {} {0})))) ∧ edge_preserving (Id_on (vertices (fst (LG {} {}, LG {} {0})))) (edges (fst (LG {} {}, LG {} {0}))) (edges (snd (LG {} {}, LG {} {0})))) ∧ finite_graph (snd (LG {} {}, LG {} {0}))› 2. ‹(vertices (fst (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1})) = Domain (Id_on (vertices (fst (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1})))) ∧ graph (fst (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1})) ∧ graph (snd (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1})) ∧ Id_on (vertices (fst (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1}))) `` vertices (fst (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1})) ⊆ vertices (snd (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1})) ∧ univalent (Id_on (vertices (fst (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1})))) ∧ edge_preserving (Id_on (vertices (fst (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1})))) (edges (fst (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1}))) (edges (snd (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1})))) ∧ finite_graph (snd (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1}))› 3. ‹(vertices (fst (LG {} {0}, LG {(i, 0, 0)} {0})) = Domain (Id_on (vertices (fst (LG {} {0}, LG {(i, 0, 0)} {0})))) ∧ graph (fst (LG {} {0}, LG {(i, 0, 0)} {0})) ∧ graph (snd (LG {} {0}, LG {(i, 0, 0)} {0})) ∧ Id_on (vertices (fst (LG {} {0}, LG {(i, 0, 0)} {0}))) `` vertices (fst (LG {} {0}, LG {(i, 0, 0)} {0})) ⊆ vertices (snd (LG {} {0}, LG {(i, 0, 0)} {0})) ∧ univalent (Id_on (vertices (fst (LG {} {0}, LG {(i, 0, 0)} {0})))) ∧ edge_preserving (Id_on (vertices (fst (LG {} {0}, LG {(i, 0, 0)} {0})))) (edges (fst (LG {} {0}, LG {(i, 0, 0)} {0}))) (edges (snd (LG {} {0}, LG {(i, 0, 0)} {0})))) ∧ finite_graph (snd (LG {} {0}, LG {(i, 0, 0)} {0}))›*) (*goals: 1. ‹(vertices (fst (LG {} {}, LG {} {0})) = Domain (Id_on (vertices (fst (LG {} {}, LG {} {0})))) ∧ graph (fst (LG {} {}, LG {} {0})) ∧ graph (snd (LG {} {}, LG {} {0})) ∧ Id_on (vertices (fst (LG {} {}, LG {} {0}))) `` vertices (fst (LG {} {}, LG {} {0})) ⊆ vertices (snd (LG {} {}, LG {} {0})) ∧ univalent (Id_on (vertices (fst (LG {} {}, LG {} {0})))) ∧ edge_preserving (Id_on (vertices (fst (LG {} {}, LG {} {0})))) (edges (fst (LG {} {}, LG {} {0}))) (edges (snd (LG {} {}, LG {} {0})))) ∧ finite_graph (snd (LG {} {}, LG {} {0}))› 2. ‹(vertices (fst (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1})) = Domain (Id_on (vertices (fst (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1})))) ∧ graph (fst (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1})) ∧ graph (snd (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1})) ∧ Id_on (vertices (fst (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1}))) `` vertices (fst (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1})) ⊆ vertices (snd (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1})) ∧ univalent (Id_on (vertices (fst (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1})))) ∧ edge_preserving (Id_on (vertices (fst (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1})))) (edges (fst (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1}))) (edges (snd (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1})))) ∧ finite_graph (snd (LG {} {0, 1}, LG {(t, 0, 1)} {0, 1}))› 3. ‹(vertices (fst (LG {} {0}, LG {(i, 0, 0)} {0})) = Domain (Id_on (vertices (fst (LG {} {0}, LG {(i, 0, 0)} {0})))) ∧ graph (fst (LG {} {0}, LG {(i, 0, 0)} {0})) ∧ graph (snd (LG {} {0}, LG {(i, 0, 0)} {0})) ∧ Id_on (vertices (fst (LG {} {0}, LG {(i, 0, 0)} {0}))) `` vertices (fst (LG {} {0}, LG {(i, 0, 0)} {0})) ⊆ vertices (snd (LG {} {0}, LG {(i, 0, 0)} {0})) ∧ univalent (Id_on (vertices (fst (LG {} {0}, LG {(i, 0, 0)} {0})))) ∧ edge_preserving (Id_on (vertices (fst (LG {} {0}, LG {(i, 0, 0)} {0})))) (edges (fst (LG {} {0}, LG {(i, 0, 0)} {0}))) (edges (snd (LG {} {0}, LG {(i, 0, 0)} {0})))) ∧ finite_graph (snd (LG {} {0}, LG {(i, 0, 0)} {0}))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . text ‹Just before Lemma 7, we remark that if I is an identity, it maintains the identity rules.› lemma ident_rel_refl: assumes "graph G" "ident_rel idt G" shows "maintained (reflexivity_rule idt) G" unfolding reflexivity_rule_def (*goal: ‹maintained (LG {} {0::nat}, LG {(idt::'a::type, 0::nat, 0::nat)} {0::nat}) (G::('a::type, 'b::type) labeled_graph)›*) proof (rule maintainedI (*‹(⋀f. graph_homomorphism ?A ?G f ⟹ extensible (?A, ?B) ?G f) ⟹ maintained (?A, ?B) ?G›*)) (*goal: ‹⋀f. graph_homomorphism (LG {} {0}) G f ⟹ extensible (LG {} {0}, LG {(idt, 0, 0)} {0}) G f›*) fix f assume "graph_homomorphism (LG {} {0::nat}) G f" (*‹graph_homomorphism (LG {} {0::nat}) (G::('a, 'b) labeled_graph) (f::(nat × 'b) set)›*) hence f: "Domain f = {0}" "graph G" "f `` {0} ⊆ vertices G" "univalent f" unfolding graph_homomorphism_def (*goals: 1. ‹Domain f = {0}› 2. ‹graph G› 3. ‹f `` {0} ⊆ vertices G› 4. ‹univalent f›*) apply - (*goals: 1. ‹vertices (LG {} {0::nat}) = Domain (f::(nat × 'b::type) set) ∧ graph (LG {} {0::nat}) ∧ graph (G::('a::type, 'b::type) labeled_graph) ∧ f `` vertices (LG {} {0::nat}) ⊆ vertices G ∧ univalent f ∧ edge_preserving f (edges (LG {} {0::nat})) (edges G) ⟹ Domain f = {0::nat}› 2. ‹vertices (LG {} {0::nat}) = Domain (f::(nat × 'b::type) set) ∧ graph (LG {} {0::nat}) ∧ graph (G::('a::type, 'b::type) labeled_graph) ∧ f `` vertices (LG {} {0::nat}) ⊆ vertices G ∧ univalent f ∧ edge_preserving f (edges (LG {} {0::nat})) (edges G) ⟹ graph G› 3. ‹vertices (LG {} {0::nat}) = Domain (f::(nat × 'b::type) set) ∧ graph (LG {} {0::nat}) ∧ graph (G::('a::type, 'b::type) labeled_graph) ∧ f `` vertices (LG {} {0::nat}) ⊆ vertices G ∧ univalent f ∧ edge_preserving f (edges (LG {} {0::nat})) (edges G) ⟹ f `` {0::nat} ⊆ vertices G› 4. ‹vertices (LG {} {0::nat}) = Domain (f::(nat × 'b::type) set) ∧ graph (LG {} {0::nat}) ∧ graph (G::('a::type, 'b::type) labeled_graph) ∧ f `` vertices (LG {} {0::nat}) ⊆ vertices G ∧ univalent f ∧ edge_preserving f (edges (LG {} {0::nat})) (edges G) ⟹ univalent f› discuss goal 1*) apply force (*discuss goal 2*) apply force (*discuss goal 3*) apply force (*discuss goal 4*) apply force (*proven 4 subgoals*) . from assms(2) (*‹ident_rel idt G›*) univalentD[OF f ( 4 )] (*‹⟦(?x, ?y) ∈ f; (?x, ?z) ∈ f⟧ ⟹ ?z = ?y›*) f(3) (*‹(f::(nat × 'b::type) set) `` {0::nat} ⊆ vertices (G::('a::type, 'b::type) labeled_graph)›*) have "edge_preserving f {(idt, 0, 0)} (edges G)" unfolding edge_preserving (*goal: ‹on_triple (f::(nat × 'b) set) `` {(idt::'a, 0::nat, 0::nat)} ⊆ edges (G::('a, 'b) labeled_graph)›*) by (auto simp:getRel_def (*‹getRel ?l ?G = {(x, y). (?l, x, y) ∈ edges ?G}›*) set_eq_iff (*‹(?A = ?B) = (∀x. (x ∈ ?A) = (x ∈ ?B))›*) image_def (*‹?f ` ?A = {y. ∃x∈?A. y = ?f x}›*)) with f (*‹Domain f = {0}› ‹graph G› ‹f `` {0} ⊆ vertices G› ‹univalent f›*) have "graph_homomorphism (LG {(idt, 0, 0)} {0}) G f" "agree_on (LG {} {0}) f f" using assms (*‹graph (G::('a, 'b) labeled_graph)› ‹ident_rel idt G›*) unfolding graph_homomorphism_def labeled_graph.sel agree_on_def univalent_def (*goals: 1. ‹{0::nat} = Domain (f::(nat × 'b) set) ∧ graph (LG {(idt::'a, 0::nat, 0::nat)} {0::nat}) ∧ graph (G::('a, 'b) labeled_graph) ∧ f `` {0::nat} ⊆ vertices G ∧ (∀(x::nat) (y::'b) z::'b. (x, y) ∈ f ∧ (x, z) ∈ f ⟶ z = y) ∧ edge_preserving f {(idt, 0::nat, 0::nat)} (edges G)› 2. ‹∀v::nat∈{0::nat}. (f::(nat × 'b) set) `` {v} = f `` {v}›*) apply - (*goals: 1. ‹⟦Domain f = {0}; graph G; f `` {0} ⊆ vertices G; ∀x y z. (x, y) ∈ f ∧ (x, z) ∈ f ⟶ z = y; edge_preserving f {(idt, 0, 0)} (edges G); graph G; ident_rel idt G⟧ ⟹ {0} = Domain f ∧ graph (LG {(idt, 0, 0)} {0}) ∧ graph G ∧ f `` {0} ⊆ vertices G ∧ (∀x y z. (x, y) ∈ f ∧ (x, z) ∈ f ⟶ z = y) ∧ edge_preserving f {(idt, 0, 0)} (edges G)› 2. ‹⟦Domain f = {0}; graph G; f `` {0} ⊆ vertices G; ∀x y z. (x, y) ∈ f ∧ (x, z) ∈ f ⟶ z = y; edge_preserving f {(idt, 0, 0)} (edges G); graph G; ident_rel idt G⟧ ⟹ ∀v∈{0}. f `` {v} = f `` {v}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . then show "extensible (LG {} {0}, LG {(idt, 0, 0)} {0}) G f" unfolding extensible_def prod.sel (*goal: ‹∃g. graph_homomorphism (LG {(idt, 0, 0)} {0}) G g ∧ agree_on (LG {} {0}) f g›*) by auto qed lemma assumes "ident_rel idt G" shows ident_rel_trans:"maintained (transitive_rule idt) G" and ident_rel_symm :"maintained (symmetry_rule idt) G" and ident_rel_cong :"maintained (congruence_rule idt l) G" unfolding transitive_rule_def symmetry_rule_def congruence_rule_def (*goals: 1. ‹maintained (transl_rule (A_Cmp (A_Lbl (idt::'b)) (A_Lbl idt) ⊑ A_Lbl idt)) (G::('b, 'a) labeled_graph)› 2. ‹maintained (transl_rule (A_Cnv (A_Lbl (idt::'b)) ⊑ A_Lbl idt)) (G::('b, 'a) labeled_graph)› 3. ‹maintained (transl_rule (A_Cmp (A_Cmp (A_Lbl (idt::'b)) (A_Lbl (l::'b))) (A_Lbl idt) ⊑ A_Lbl l)) (G::('b, 'a) labeled_graph)›*) (*goals: 1. ‹maintained (transl_rule (A_Cmp (A_Lbl idt) (A_Lbl idt) ⊑ A_Lbl idt)) G› 2. ‹maintained (transl_rule (A_Cnv (A_Lbl idt) ⊑ A_Lbl idt)) G› 3. ‹maintained (transl_rule (A_Cmp (A_Cmp (A_Lbl idt) (A_Lbl l)) (A_Lbl idt) ⊑ A_Lbl l)) G› discuss goal 1*) apply (intro maintained_holds (*‹:?G::(?'b::type, ?'a::type) labeled_graph:⟦?e⇩L::?'b::type allegorical_term⟧ ⊆ :?G:⟦?e⇩R::?'b::type allegorical_term⟧ ⟹ maintained (transl_rule (?e⇩L ⊑ ?e⇩R)) ?G›*)) (*top goal: ‹maintained (transl_rule (A_Cmp (A_Lbl (idt::'b)) (A_Lbl idt) ⊑ A_Lbl idt)) (G::('b, 'a) labeled_graph)› and 2 goals remain*) apply ((insert assms (*‹ident_rel idt G›*))[1]) (*top goal: ‹:G:⟦A_Cmp (A_Lbl idt) (A_Lbl idt)⟧ ⊆ :G:⟦A_Lbl idt⟧› and 2 goals remain*) apply force (*discuss goal 2*) apply ((insert assms (*‹ident_rel idt G›*))[1]) (*top goal: ‹maintained (transl_rule (A_Cnv (A_Lbl (idt::'b::type)) ⊑ A_Lbl idt)) (G::('b::type, 'a::type) labeled_graph)› and 1 goal remains*) apply (intro maintained_holds (*‹:?G:⟦?e⇩L⟧ ⊆ :?G:⟦?e⇩R⟧ ⟹ maintained (transl_rule (?e⇩L ⊑ ?e⇩R)) ?G›*)) (*top goal: ‹ident_rel idt G ⟹ maintained (transl_rule (A_Cnv (A_Lbl idt) ⊑ A_Lbl idt)) G› and 1 goal remains*) apply ((insert assms (*‹ident_rel idt G›*))[1]) (*top goal: ‹ident_rel idt G ⟹ :G:⟦A_Cnv (A_Lbl idt)⟧ ⊆ :G:⟦A_Lbl idt⟧› and 1 goal remains*) apply force (*discuss goal 3*) apply ((insert assms (*‹ident_rel idt G›*))[1]) (*goal: ‹maintained (transl_rule (A_Cmp (A_Cmp (A_Lbl idt) (A_Lbl l)) (A_Lbl idt) ⊑ A_Lbl l)) G›*) apply ((insert assms (*‹ident_rel idt G›*))[1]) (*goal: ‹ident_rel idt G ⟹ maintained (transl_rule (A_Cmp (A_Cmp (A_Lbl idt) (A_Lbl l)) (A_Lbl idt) ⊑ A_Lbl l)) G›*) apply (intro maintained_holds (*‹:?G:⟦?e⇩L⟧ ⊆ :?G:⟦?e⇩R⟧ ⟹ maintained (transl_rule (?e⇩L ⊑ ?e⇩R)) ?G›*)) (*goal: ‹⟦ident_rel idt G; ident_rel idt G⟧ ⟹ maintained (transl_rule (A_Cmp (A_Cmp (A_Lbl idt) (A_Lbl l)) (A_Lbl idt) ⊑ A_Lbl l)) G›*) apply (insert assms (*‹ident_rel idt G›*)) (*goal: ‹⟦ident_rel (idt::'b::type) (G::('b::type, 'a::type) labeled_graph); ident_rel idt G⟧ ⟹ :G:⟦A_Cmp (A_Cmp (A_Lbl idt) (A_Lbl (l::'b::type))) (A_Lbl idt)⟧ ⊆ :G:⟦A_Lbl l⟧›*) apply force (*proven 3 subgoals*) . text ‹Definition 19.› definition identity_rules :: "'a Standard_Constant set ⇒ (('a Standard_Constant, nat) Graph_PreRule) set" where "identity_rules L ≡ {reflexivity_rule S_Idt,transitive_rule S_Idt,symmetry_rule S_Idt} ∪ congruence_rules S_Idt L" lemma identity_rules_graph_rule: assumes "x ∈ identity_rules L" shows "graph_rule x" proof (-) (*goal: ‹graph_rule x›*) from graph_rule_translation (*‹graph_rule (translation ?X, translation (A_Int ?X ?Y))›*) have gr: "⋀ u v . graph_rule (transl_rule (u ⊑ v))" by auto consider "x = reflexivity_rule S_Idt" | "x = transitive_rule S_Idt" | "x = symmetry_rule S_Idt" | "∃ v w. x = congruence_rule v w" (*goal: ‹⟦x = reflexivity_rule S_Idt ⟹ thesis; x = transitive_rule S_Idt ⟹ thesis; x = symmetry_rule S_Idt ⟹ thesis; ∃v w. x = congruence_rule v w ⟹ thesis⟧ ⟹ thesis›*) using assms (*‹x ∈ identity_rules L›*) unfolding identity_rules_def Un_iff (*goal: ‹⟦x = reflexivity_rule S_Idt ⟹ thesis; x = transitive_rule S_Idt ⟹ thesis; x = symmetry_rule S_Idt ⟹ thesis; ∃v w. x = congruence_rule v w ⟹ thesis⟧ ⟹ thesis›*) by blast thus "?thesis" (*goal: ‹graph_rule x›*) using gr (*‹graph_rule (transl_rule ((?u::?'b1::type allegorical_term) ⊑ (?v::?'b1::type allegorical_term)))›*) are_rules(3) (*‹graph_rule (reflexivity_rule (?i::?'c))›*) unfolding congruence_rule_def transitive_rule_def symmetry_rule_def (*goal: ‹graph_rule (x::('a Standard_Constant, nat) labeled_graph × ('a Standard_Constant, nat) labeled_graph)›*) apply cases (*goals: 1. ‹⟦⋀u v. graph_rule (transl_rule (u ⊑ v)); ⋀i. graph_rule (reflexivity_rule i); x = reflexivity_rule S_Idt⟧ ⟹ graph_rule x› 2. ‹⟦⋀u v. graph_rule (transl_rule (u ⊑ v)); ⋀i. graph_rule (reflexivity_rule i); x = transl_rule (A_Cmp 𝟭 𝟭 ⊑ 𝟭)⟧ ⟹ graph_rule x› 3. ‹⟦⋀u v. graph_rule (transl_rule (u ⊑ v)); ⋀i. graph_rule (reflexivity_rule i); x = transl_rule (A_Cnv 𝟭 ⊑ 𝟭)⟧ ⟹ graph_rule x› 4. ‹⟦⋀u v. graph_rule (transl_rule (u ⊑ v)); ⋀i. graph_rule (reflexivity_rule i); ∃v w. x = transl_rule (A_Cmp (A_Cmp (A_Lbl v) (A_Lbl w)) (A_Lbl v) ⊑ A_Lbl w)⟧ ⟹ graph_rule x› discuss goal 1*) apply fast (*discuss goal 2*) apply fast (*discuss goal 3*) apply fast (*discuss goal 4*) apply fast (*proven 4 subgoals*) . qed text ‹Definition 19, showing that the properties indeed do what they claim to do.› lemma assumes g[intro]:"graph (G :: ('a, 'b) labeled_graph)" shows reflexivity_rule: "maintained (reflexivity_rule l) G ⟹ refl_on (vertices G) (getRel l G)" and transitive_rule: "maintained (transitive_rule l) G ⟹ trans (getRel l G)" and symmetry_rule: "maintained (symmetry_rule l) G ⟹ sym (getRel l G)" proof (-) (*goals: 1. ‹maintained (reflexivity_rule l) G ⟹ refl_on (vertices G) (getRel l G)› 2. ‹maintained (transitive_rule l) G ⟹ trans (getRel l G)› 3. ‹maintained (symmetry_rule l) G ⟹ sym (getRel l G)›*) { from assms (*‹graph G›*) have gr: "getRel l G ⊆ vertices G × vertices G" by (auto simp:getRel_def (*‹getRel ?l ?G = {(x, y). (?l, x, y) ∈ edges ?G}›*)) assume m: "maintained (reflexivity_rule l) G" (is "maintained ?r G") (*‹maintained (reflexivity_rule (l::'a)) (G::('a, 'b) labeled_graph)›*) note [simp] = reflexivity_rule_def (*‹reflexivity_rule ?t = (LG {} {0}, LG {(?t, 0, 0)} {0})›*) show r: "refl_on (vertices G) (getRel l G)" proof (rule refl_onI[OF gr] (*‹(⋀x::'b::type. x ∈ vertices (G::('a::type, 'b::type) labeled_graph) ⟹ (x, x) ∈ getRel (l::'a::type) G) ⟹ refl_on (vertices G) (getRel l G)›*)) (*goal: ‹⋀x. x ∈ vertices G ⟹ (x, x) ∈ getRel l G›*) fix x assume assm: "x ∈ vertices G" (*‹(x::'b) ∈ vertices (G::('a, 'b) labeled_graph)›*) define f where "f = {(0::nat,x)}" have "graph_homomorphism (fst ?r) G f" using assm (*‹x ∈ vertices G›*) by (auto simp:graph_homomorphism_def (*‹graph_homomorphism ?G₁ ?G₂ ?f = (vertices ?G₁ = Domain ?f ∧ graph ?G₁ ∧ graph ?G₂ ∧ ?f `` vertices ?G₁ ⊆ vertices ?G₂ ∧ univalent ?f ∧ edge_preserving ?f (edges ?G₁) (edges ?G₂))›*) univalent_def (*‹univalent ?R = (∀x y z. (x, y) ∈ ?R ∧ (x, z) ∈ ?R ⟶ z = y)›*) f_def (*‹f = {(0, x)}›*)) from m[unfolded maintained_def] (*‹∀f. graph_homomorphism (fst (reflexivity_rule l)) G f ⟶ extensible (reflexivity_rule l) G f›*) this (*‹graph_homomorphism (fst (reflexivity_rule l)) G f›*) obtain g :: "(nat×'b) set" where g: "graph_homomorphism (snd ?r) G g" "agree_on (fst ?r) f g" (*goal: ‹(⋀g. ⟦graph_homomorphism (snd (reflexivity_rule l)) G g; agree_on (fst (reflexivity_rule l)) f g⟧ ⟹ thesis) ⟹ thesis›*) unfolding extensible_def (*goal: ‹(⋀g. ⟦graph_homomorphism (snd (reflexivity_rule l)) G g; agree_on (fst (reflexivity_rule l)) f g⟧ ⟹ thesis) ⟹ thesis›*) by blast have "⋀ n v. (n,v) ∈ g ⟹ (n = 0) ∧ (v = x)" using g (*‹graph_homomorphism (snd (reflexivity_rule l)) G g› ‹agree_on (fst (reflexivity_rule (l::'a))) (f::(nat × 'b) set) (g::(nat × 'b) set)›*) unfolding agree_on_def graph_homomorphism_def f_def (*goal: ‹⋀n v. (n, v) ∈ g ⟹ n = 0 ∧ v = x›*) by auto with g(2) (*‹agree_on (fst (reflexivity_rule l)) f g›*) have "g = {(0,x)}" unfolding agree_on_def f_def (*goal: ‹g = {(0, x)}›*) by auto with g(1) (*‹graph_homomorphism (snd (reflexivity_rule l)) G g›*) show "(x,x)∈ getRel l G" unfolding graph_homomorphism_def edge_preserving getRel_def (*goal: ‹(x, x) ∈ {(x, y). (l, x, y) ∈ edges G}›*) by auto qed } { assume m: "maintained (transitive_rule l) G" (*‹maintained (transitive_rule (l::'a)) (G::('a, 'b) labeled_graph)›*) from m[unfolded maintained_holds_subset_iff [ OF g ] transitive_rule_def] (*‹:G:⟦A_Cmp (A_Lbl l) (A_Lbl l)⟧ ⊆ :G:⟦A_Lbl l⟧›*) show "trans (getRel l G)" unfolding trans_def (*goal: ‹(Id ∪ getRel l G) O getRel l G = getRel l G›*) by auto } { assume m: "maintained (symmetry_rule l) G" (*‹maintained (symmetry_rule (l::'a)) (G::('a, 'b) labeled_graph)›*) from m[unfolded maintained_holds_subset_iff [ OF g ] symmetry_rule_def] (*‹:G::('a, 'b) labeled_graph:⟦A_Cnv (A_Lbl (l::'a))⟧ ⊆ :G:⟦A_Lbl l⟧›*) show "sym (getRel l G)" unfolding sym_def (*goal: ‹∀(x::'b) y::'b. (x, y) ∈ getRel (l::'a) (G::('a, 'b) labeled_graph) ⟶ (y, x) ∈ getRel l G›*) by auto } qed lemma finite_identity_rules[intro]: assumes "finite L" shows "finite (identity_rules L)" using assms (*‹finite (L::'a::type Standard_Constant set)›*) unfolding identity_rules_def (*goal: ‹finite ({reflexivity_rule S_Idt, transitive_rule S_Idt, symmetry_rule S_Idt} ∪ congruence_rules S_Idt L)›*) by auto lemma equivalence: assumes gr:"graph G" and m:"maintainedA {reflexivity_rule I,transitive_rule I,symmetry_rule I} G" shows "equiv (vertices G) (getRel I G)" proof (rule equivI (*‹⟦refl_on (?A::?'a set) (?r::(?'a × ?'a) set); sym ?r; trans ?r⟧ ⟹ equiv ?A ?r›*)) (*goals: 1. ‹refl_on (vertices G) (getRel I G)› 2. ‹sym (getRel I G)› 3. ‹trans (getRel I G)›*) show "refl_on (vertices G) (getRel I G)" using m (*‹maintainedA {reflexivity_rule (I::'a), transitive_rule I, symmetry_rule I} (G::('a, 'b) labeled_graph)›*) apply (intro reflexivity_rule[OF gr] (*‹maintained (reflexivity_rule ?l) G ⟹ refl_on (vertices G) (getRel ?l G)›*)) (*goal: ‹refl_on (vertices G) (getRel I G)›*) by auto show "sym (getRel I G)" using m (*‹maintainedA {reflexivity_rule I, transitive_rule I, symmetry_rule I} G›*) apply (intro symmetry_rule[OF gr] (*‹maintained (symmetry_rule ?l) G ⟹ sym (getRel ?l G)›*)) (*goal: ‹sym (getRel I G)›*) by auto show "trans (getRel I G)" using m (*‹maintainedA {reflexivity_rule I, transitive_rule I, symmetry_rule I} G›*) apply (intro transitive_rule[OF gr] (*‹maintained (transitive_rule ?l) G ⟹ trans (getRel ?l G)›*)) (*goal: ‹trans (getRel I G)›*) by auto qed lemma congruence_rule: (* Transitivity is not needed for this proof, but it's more convenient to reuse in this form *) assumes g:"graph G" and mA:"maintainedA {reflexivity_rule I,transitive_rule I,symmetry_rule I} G" and m:"maintained (congruence_rule I l) G" shows "(λ v. getRel l G `` {v}) respects (getRel I G)" (is "?g1") and "(λ v. (getRel l G)¯ `` {v}) respects (getRel I G)" (is "?g2") proof (-) (*goals: 1. ‹(λv. getRel l G `` {v}) respects getRel I G› 2. ‹(λv. (getRel l G)¯ `` {v}) respects getRel I G›*) note eq = equivalence[OF g mA] (*‹equiv (vertices G) (getRel I G)›*) { fix y and z assume aI: "(y, z)∈getRel I G" (*‹(y::'b, z::'b) ∈ getRel (I::'a) (G::('a, 'b) labeled_graph)›*) hence a2: "(z, y)∈getRel I G" using eq[unfolded equiv_def sym_def] (*‹refl_on (vertices G) (getRel I G) ∧ (∀x y. (x, y) ∈ getRel I G ⟶ (y, x) ∈ getRel I G) ∧ trans (getRel I G)›*) by auto hence a3: "(z, z)∈getRel I G" "(y, y)∈getRel I G" using eq[unfolded equiv_def refl_on_def] (*‹(getRel I G ⊆ vertices G × vertices G ∧ (∀x∈vertices G. (x, x) ∈ getRel I G)) ∧ sym (getRel I G) ∧ trans (getRel I G)›*) apply - (*goals: 1. ‹⟦(z, y) ∈ getRel I G; (getRel I G ⊆ vertices G × vertices G ∧ (∀x∈vertices G. (x, x) ∈ getRel I G)) ∧ sym (getRel I G) ∧ trans (getRel I G)⟧ ⟹ (z, z) ∈ getRel I G› 2. ‹⟦(z, y) ∈ getRel I G; (getRel I G ⊆ vertices G × vertices G ∧ (∀x∈vertices G. (x, x) ∈ getRel I G)) ∧ sym (getRel I G) ∧ trans (getRel I G)⟧ ⟹ (y, y) ∈ getRel I G› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . { fix x { assume al: "(y,x) ∈ getRel l G" (*‹(y::'b, x::'b) ∈ getRel (l::'a) (G::('a, 'b) labeled_graph)›*) hence "x ∈ vertices G" using g (*‹graph (G::('a, 'b) labeled_graph)›*) unfolding getRel_def (*goal: ‹x ∈ vertices G›*) by auto hence r: "(x,x) ∈ getRel I G" using eq[unfolded equiv_def refl_on_def] (*‹(getRel I G ⊆ vertices G × vertices G ∧ (∀x∈vertices G. (x, x) ∈ getRel I G)) ∧ sym (getRel I G) ∧ trans (getRel I G)›*) by auto note relcompI[OF relcompI [ OF a2 al ] r] (*‹(z, x) ∈ (getRel I G O getRel l G) O getRel I G›*) } note yx = this (*‹(y, x) ∈ getRel l G ⟹ (z, x) ∈ (getRel I G O getRel l G) O getRel I G›*) { assume al: "(z,x) ∈ getRel l G" (*‹(z::'b, x::'b) ∈ getRel (l::'a) (G::('a, 'b) labeled_graph)›*) hence "x ∈ vertices G" using g (*‹graph G›*) unfolding getRel_def (*goal: ‹x ∈ vertices G›*) by auto hence r: "(x,x) ∈ getRel I G" using eq[unfolded equiv_def refl_on_def] (*‹(getRel I G ⊆ vertices G × vertices G ∧ (∀x∈vertices G. (x, x) ∈ getRel I G)) ∧ sym (getRel I G) ∧ trans (getRel I G)›*) by auto note relcompI[OF relcompI [ OF aI al ] r] (*‹(y::'b, x::'b) ∈ (getRel (I::'a) (G::('a, 'b) labeled_graph) O getRel (l::'a) G) O getRel I G›*) } note zx = this (*‹(z, x) ∈ getRel l G ⟹ (y, x) ∈ (getRel I G O getRel l G) O getRel I G›*) from zx (*‹(z, x) ∈ getRel l G ⟹ (y, x) ∈ (getRel I G O getRel l G) O getRel I G›*) yx (*‹(y::'b::type, x::'b::type) ∈ getRel (l::'a::type) (G::('a::type, 'b::type) labeled_graph) ⟹ (z::'b::type, x) ∈ (getRel (I::'a::type) G O getRel l G) O getRel I G›*) m[unfolded maintained_holds_subset_iff [ OF g ] congruence_rule_def] (*‹:G:⟦A_Cmp (A_Cmp (A_Lbl I) (A_Lbl l)) (A_Lbl I)⟧ ⊆ :G:⟦A_Lbl l⟧›*) have "(y,x) ∈ getRel l G ⟷ (z,x) ∈ getRel l G" by auto } note v1 = this (*‹((y, ?x2) ∈ getRel l G) = ((z, ?x2) ∈ getRel l G)›*) { fix x { assume al: "(x,y) ∈ getRel l G" (*‹(x::'b, y::'b) ∈ getRel (l::'a) (G::('a, 'b) labeled_graph)›*) hence "x ∈ vertices G" using g (*‹graph (G::('a, 'b) labeled_graph)›*) unfolding getRel_def (*goal: ‹(x::'b) ∈ vertices (G::('a, 'b) labeled_graph)›*) by auto hence r: "(x,x) ∈ getRel I G" using eq[unfolded equiv_def refl_on_def] (*‹(getRel I G ⊆ vertices G × vertices G ∧ (∀x∈vertices G. (x, x) ∈ getRel I G)) ∧ sym (getRel I G) ∧ trans (getRel I G)›*) by auto note relcompI[OF relcompI [ OF r al ] aI] (*‹(x, z) ∈ (getRel I G O getRel l G) O getRel I G›*) } note yx = this (*‹(x, y) ∈ getRel l G ⟹ (x, z) ∈ (getRel I G O getRel l G) O getRel I G›*) { assume al: "(x,z) ∈ getRel l G" (*‹(x::'b, z::'b) ∈ getRel (l::'a) (G::('a, 'b) labeled_graph)›*) hence "x ∈ vertices G" using g (*‹graph G›*) unfolding getRel_def (*goal: ‹x ∈ vertices G›*) by auto hence r: "(x,x) ∈ getRel I G" using eq[unfolded equiv_def refl_on_def] (*‹(getRel I G ⊆ vertices G × vertices G ∧ (∀x∈vertices G. (x, x) ∈ getRel I G)) ∧ sym (getRel I G) ∧ trans (getRel I G)›*) by auto note relcompI[OF relcompI [ OF r al ] a2] (*‹(x, y) ∈ (getRel I G O getRel l G) O getRel I G›*) } note zx = this (*‹(x, z) ∈ getRel l G ⟹ (x, y) ∈ (getRel I G O getRel l G) O getRel I G›*) from zx (*‹(x, z) ∈ getRel l G ⟹ (x, y) ∈ (getRel I G O getRel l G) O getRel I G›*) yx (*‹(x, y) ∈ getRel l G ⟹ (x, z) ∈ (getRel I G O getRel l G) O getRel I G›*) m[unfolded maintained_holds_subset_iff [ OF g ] congruence_rule_def] (*‹:G:⟦A_Cmp (A_Cmp (A_Lbl I) (A_Lbl l)) (A_Lbl I)⟧ ⊆ :G:⟦A_Lbl l⟧›*) have "(x,y) ∈ getRel l G ⟷ (x,z) ∈ getRel l G" by auto } note v2 = this (*‹((?x2, y) ∈ getRel l G) = ((?x2, z) ∈ getRel l G)›*) from v1 (*‹((y, ?x2) ∈ getRel l G) = ((z, ?x2) ∈ getRel l G)›*) v2 (*‹((?x2::'b, y::'b) ∈ getRel (l::'a) (G::('a, 'b) labeled_graph)) = ((?x2, z::'b) ∈ getRel l G)›*) have "getRel l G `` {y} = getRel l G `` {z}" "(getRel l G)¯ `` {y} = (getRel l G)¯ `` {z}" apply - (*goals: 1. ‹⟦⋀x. ((y, x) ∈ getRel l G) = ((z, x) ∈ getRel l G); ⋀x. ((x, y) ∈ getRel l G) = ((x, z) ∈ getRel l G)⟧ ⟹ getRel l G `` {y} = getRel l G `` {z}› 2. ‹⟦⋀x. ((y, x) ∈ getRel l G) = ((z, x) ∈ getRel l G); ⋀x. ((x, y) ∈ getRel l G) = ((x, z) ∈ getRel l G)⟧ ⟹ (getRel l G)¯ `` {y} = (getRel l G)¯ `` {z}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . } thus "?g1" "?g2" unfolding congruent_def (*goals: 1. ‹∀(y, z)∈getRel I G. getRel l G `` {y} = getRel l G `` {z}› 2. ‹∀(y, z)∈getRel I G. (getRel l G)¯ `` {y} = (getRel l G)¯ `` {z}›*) apply - (*goals: 1. ‹⟦⋀(y::'b::type) z::'b::type. (y, z) ∈ getRel (I::'a::type) (G::('a::type, 'b::type) labeled_graph) ⟹ getRel (l::'a::type) G `` {y} = getRel l G `` {z}; ⋀(y::'b::type) z::'b::type. (y, z) ∈ getRel I G ⟹ (getRel l G)¯ `` {y} = (getRel l G)¯ `` {z}⟧ ⟹ ∀(y::'b::type, z::'b::type)∈getRel I G. getRel l G `` {y} = getRel l G `` {z}› 2. ‹⟦⋀(y::'b::type) z::'b::type. (y, z) ∈ getRel (I::'a::type) (G::('a::type, 'b::type) labeled_graph) ⟹ getRel (l::'a::type) G `` {y} = getRel l G `` {z}; ⋀(y::'b::type) z::'b::type. (y, z) ∈ getRel I G ⟹ (getRel l G)¯ `` {y} = (getRel l G)¯ `` {z}⟧ ⟹ ∀(y::'b::type, z::'b::type)∈getRel I G. (getRel l G)¯ `` {y} = (getRel l G)¯ `` {z}› discuss goal 1*) apply force (*discuss goal 2*) apply force (*proven 2 subgoals*) . qed text ‹Lemma 7, strengthened with an extra property to make subsequent proofs easier to carry out.› lemma identity_rules: assumes "graph G" "maintainedA (identity_rules L) G" "fst ` edges G ⊆ L" shows "∃ f. f o f = f ∧ ident_rel S_Idt (map_graph_fn G f) ∧ subgraph (map_graph_fn G f) G ∧ (∀ l x y. (l,x,y) ∈ edges G ⟷ (l,f x,f y) ∈ edges G)" proof (-) (*goal: ‹∃f::'b::type ⇒ 'b::type. f ∘ f = f ∧ ident_rel S_Idt (map_graph_fn (G::('a::type Standard_Constant, 'b::type) labeled_graph) f) ∧ subgraph (map_graph_fn G f) G ∧ (∀(l::'a::type Standard_Constant) (x::'b::type) y::'b::type. ((l, x, y) ∈ edges G) = ((l, f x, f y) ∈ edges G))›*) have ma: "maintainedA {reflexivity_rule S_Idt, transitive_rule S_Idt, symmetry_rule S_Idt} G" using assms(2) (*‹maintainedA (identity_rules (L::'a::type Standard_Constant set)) (G::('a::type Standard_Constant, 'b::type) labeled_graph)›*) by (auto simp:identity_rules_def (*‹identity_rules ?L ≡ {reflexivity_rule S_Idt, transitive_rule S_Idt, symmetry_rule S_Idt} ∪ congruence_rules S_Idt ?L›*)) note equiv = equivalence[OF assms ( 1 ) this] (*‹equiv (vertices G) (getRel S_Idt G)›*) { fix l and x and y assume "(x, y) ∈ getRel l G" (*‹(x::'b, y::'b) ∈ getRel (l::'a Standard_Constant) (G::('a Standard_Constant, 'b) labeled_graph)›*) hence l: "l ∈ L" using assms(3) (*‹fst ` edges G ⊆ L›*) unfolding getRel_def (*goal: ‹l ∈ L›*) by auto have r1: "(λv. getRel l G `` {v}) respects getRel S_Idt G" apply (intro congruence_rule[OF assms(1) ma] (*‹maintained (congruence_rule S_Idt ?l) G ⟹ (λv. getRel ?l G `` {v}) respects getRel S_Idt G› ‹maintained (congruence_rule S_Idt ?l) G ⟹ (λv. (getRel ?l G)¯ `` {v}) respects getRel S_Idt G›*)) (*goal: ‹(λv::'b. getRel (l::'a Standard_Constant) (G::('a Standard_Constant, 'b) labeled_graph) `` {v}) respects getRel S_Idt G›*) using assms(2) (*‹maintainedA (identity_rules L) G›*) l (*‹l ∈ L›*) unfolding identity_rules_def (*goal: ‹maintained (congruence_rule S_Idt l) G›*) by auto have r2: "(λv. (getRel l G)¯ `` {v}) respects getRel S_Idt G" apply (intro congruence_rule[OF assms(1) ma] (*‹maintained (congruence_rule S_Idt ?l) G ⟹ (λv. getRel ?l G `` {v}) respects getRel S_Idt G› ‹maintained (congruence_rule S_Idt ?l) G ⟹ (λv. (getRel ?l G)¯ `` {v}) respects getRel S_Idt G›*)) (*goal: ‹(λv. (getRel l G)¯ `` {v}) respects getRel S_Idt G›*) using assms(2) (*‹maintainedA (identity_rules L) G›*) l (*‹l ∈ L›*) unfolding identity_rules_def (*goal: ‹maintained (congruence_rule S_Idt l) G›*) by auto note congr = r1 (*‹(λv. getRel l G `` {v}) respects getRel S_Idt G›*) r2 (*‹(λv. (getRel l G)¯ `` {v}) respects getRel S_Idt G›*) } note congr = this (*‹(?x2, ?y2) ∈ getRel ?l2 G ⟹ (λv. getRel ?l2 G `` {v}) respects getRel S_Idt G› ‹(?x2, ?y2) ∈ getRel ?l2 G ⟹ (λv. (getRel ?l2 G)¯ `` {v}) respects getRel S_Idt G›*) define P where P: "P = (λ x y. y ∈ getRel S_Idt G `` {x})" { fix x assume a: "getRel S_Idt G `` {x} ≠ {}" (*‹getRel S_Idt (G::('a Standard_Constant, 'b) labeled_graph) `` {x::'b} ≠ {}›*) hence "∃ y. P x y" unfolding P (*goal: ‹∃y::'b::type. y ∈ getRel S_Idt (G::('a::type Standard_Constant, 'b::type) labeled_graph) `` {x::'b::type}›*) by auto hence p: "P x (Eps (P x))" unfolding some_eq_ex (*goal: ‹Ex ((P::'b ⇒ 'b ⇒ bool) (x::'b))›*) by auto { fix y assume b: "P x y" (*‹(P::'b ⇒ 'b ⇒ bool) (x::'b) (y::'b)›*) hence "(x,y) ∈ getRel S_Idt G" unfolding P (*goal: ‹(x, y) ∈ getRel S_Idt G›*) by auto from equiv_class_eq[OF equiv this] (*‹getRel S_Idt G `` {x} = getRel S_Idt G `` {y}›*) have "getRel S_Idt G `` {x} = getRel S_Idt G `` {y}" . } note u = this[OF p] (*‹getRel S_Idt G `` {x} = getRel S_Idt G `` {Eps (P x)}›*) have "getRel S_Idt G `` {Eps (P x)} = getRel S_Idt G `` {x}" unfolding u (*goal: ‹getRel S_Idt G `` {Eps (P x)} = getRel S_Idt G `` {Eps (P x)}›*) by (fact refl (*‹?t = ?t›*)) hence "Eps (P (Eps (P x))) = Eps (P x)" unfolding P (*goal: ‹(SOME y. y ∈ getRel S_Idt G `` {SOME y. y ∈ getRel S_Idt G `` {x}}) = (SOME y. y ∈ getRel S_Idt G `` {x})›*) by auto } note P_eq = this (*‹getRel S_Idt G `` {?x2} ≠ {} ⟹ Eps (P (Eps (P ?x2))) = Eps (P ?x2)›*) define f where f: "f = (λ x. (if getRel S_Idt G `` {x} = {} then x else (SOME y. P x y)))" have "(f ∘ f) x = f x" for x proof (cases "getRel S_Idt G `` {x} = {}") (*goals: 1. ‹getRel S_Idt G `` {x} = {} ⟹ (f ∘ f) x = f x› 2. ‹getRel S_Idt G `` {x} ≠ {} ⟹ (f ∘ f) x = f x›*) case False (*‹getRel S_Idt G `` {x} ≠ {}›*) then show "?thesis" (*goal: ‹(f ∘ f) x = f x›*) using P_eq (*‹getRel S_Idt G `` {?x2} ≠ {} ⟹ Eps (P (Eps (P ?x2))) = Eps (P ?x2)›*) by (simp add:o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*) f (*‹f = (λx. if getRel S_Idt G `` {x} = {} then x else SOME y. P x y)›*)) qed (auto simp:o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*) f (*‹f = (λx. if getRel S_Idt G `` {x} = {} then x else SOME y. P x y)›*)) (*solved the remaining goal: ‹getRel S_Idt G `` {x} = {} ⟹ (f ∘ f) x = f x›*) hence idemp: "f o f = f" by auto from equivE (*‹⟦equiv ?A ?r; ⟦refl_on ?A ?r; sym ?r; trans ?r⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) equiv (*‹equiv (vertices (G::('a::type Standard_Constant, 'b::type) labeled_graph)) (getRel S_Idt G)›*) have refl: "refl_on (vertices G) (getRel S_Idt G)" by auto hence [intro]: "x ∈ vertices G ⟹ (x, x) ∈ getRel S_Idt G" for x unfolding refl_on_def (*goal: ‹x ∈ vertices G ⟹ (x, x) ∈ getRel S_Idt G›*) by auto hence vert_P: "x ∈ vertices G ⟹ (x, Eps (P x)) ∈ getRel S_Idt G" for x unfolding P getRel_def (*goal: ‹x ∈ vertices G ⟹ (x, SOME y. y ∈ {(x, y). (S_Idt, x, y) ∈ edges G} `` {x}) ∈ {(x, y). (S_Idt, x, y) ∈ edges G}›*) by (metis tfl_some (*‹∀P x. P x ⟶ P (Eps P)›*) Image_singleton_iff (*‹(?b ∈ ?r `` {?a}) = ((?a, ?b) ∈ ?r)›*) getRel_def (*‹getRel ?l ?G = {(x, y). (?l, x, y) ∈ edges ?G}›*)) have r1: "x ∈ vertices G ⟷ P x x" for x using refl (*‹refl_on (vertices G) (getRel S_Idt G)›*) unfolding refl_on_def P (*goal: ‹((x::'b) ∈ vertices (G::('a Standard_Constant, 'b) labeled_graph)) = (x ∈ getRel S_Idt G `` {x})›*) by auto have r2[simp]: "getRel S_Idt G `` {x} = {} ⟷ x ∉ vertices G" for x using refl (*‹refl_on (vertices G) (getRel S_Idt G)›*) assms(1) (*‹graph G›*) unfolding refl_on_def (*goal: ‹(getRel S_Idt G `` {x} = {}) = (x ∉ vertices G)›*) by auto { fix x and y assume "(S_Idt,x,y)∈ edges G" (*‹(S_Idt, x::'b, y::'b) ∈ edges (G::('a Standard_Constant, 'b) labeled_graph)›*) hence "(x,y) ∈ getRel S_Idt G" unfolding getRel_def (*goal: ‹(x::'b::type, y::'b::type) ∈ {(x::'b::type, y::'b::type). (S_Idt, x, y) ∈ edges (G::('a::type Standard_Constant, 'b::type) labeled_graph)}›*) by auto hence "getRel S_Idt G `` {x} = getRel S_Idt G `` {y}" using equiv_class_eq[OF equiv] (*‹(?a, ?b) ∈ getRel S_Idt G ⟹ getRel S_Idt G `` {?a} = getRel S_Idt G `` {?b}›*) by metis hence "Eps (P x) = Eps (P y)" unfolding P (*goal: ‹(SOME y. y ∈ getRel S_Idt G `` {x}) = (SOME ya. ya ∈ getRel S_Idt G `` {y})›*) by auto } note idt_eq = this (*‹(S_Idt, ?x2, ?y2) ∈ edges G ⟹ Eps (P ?x2) = Eps (P ?y2)›*) have ident: "ident_rel S_Idt (map_graph_fn G f)" proof (rule ident_relI (*‹⟦⋀x. x ∈ vertices ?G ⟹ (x, x) ∈ getRel ?idt ?G; ⋀x y. (x, y) ∈ getRel ?idt ?G ⟹ x = y; ⋀x y. (x, y) ∈ getRel ?idt ?G ⟹ x ∈ vertices ?G⟧ ⟹ ident_rel ?idt ?G›*), goal_cases) (*goals: 1. ‹⋀x. x ∈ vertices (map_graph_fn G f) ⟹ (x, x) ∈ getRel S_Idt (map_graph_fn G f)› 2. ‹⋀x y. (x, y) ∈ getRel S_Idt (map_graph_fn G f) ⟹ x = y› 3. ‹⋀x y. (x, y) ∈ getRel S_Idt (map_graph_fn G f) ⟹ x ∈ vertices (map_graph_fn G f)›*) case (1 x) (*‹x ∈ vertices (map_graph_fn G f)›*) thus "?case" (*goal: ‹(x, x) ∈ getRel S_Idt (map_graph_fn G f)›*) unfolding f (*goal: ‹(x, x) ∈ getRel S_Idt (map_graph_fn G (λx. if getRel S_Idt G `` {x} = {} then x else Eps (P x)))›*) by auto next (*goals: 1. ‹⋀x y. (x, y) ∈ getRel S_Idt (map_graph_fn G f) ⟹ x = y› 2. ‹⋀x y. (x, y) ∈ getRel S_Idt (map_graph_fn G f) ⟹ x ∈ vertices (map_graph_fn G f)›*) case (2 x y) (*‹(x, y) ∈ getRel S_Idt (map_graph_fn G f)›*) thus "?case" (*goal: ‹(x::'b) = (y::'b)›*) unfolding getRel_def (*goal: ‹(x::'b) = (y::'b)›*) by (auto simp:f (*‹f = (λx. if getRel S_Idt G `` {x} = {} then x else SOME y. P x y)›*) intro!:idt_eq (*‹(S_Idt, ?x2, ?y2) ∈ edges G ⟹ Eps (P ?x2) = Eps (P ?y2)›*)) next (*goal: ‹⋀(x::'b) y::'b. (x, y) ∈ getRel S_Idt (map_graph_fn (G::('a Standard_Constant, 'b) labeled_graph) (f::'b ⇒ 'b)) ⟹ x ∈ vertices (map_graph_fn G f)›*) case (3 x y) (*‹(x, y) ∈ getRel S_Idt (map_graph_fn G f)›*) thus "?case" (*goal: ‹x ∈ vertices (map_graph_fn G f)›*) unfolding getRel_def (*goal: ‹(x::'b) ∈ vertices (map_graph_fn (G::('a Standard_Constant, 'b) labeled_graph) (f::'b ⇒ 'b))›*) by auto qed { fix l and x and y assume a: "(l,x,y) ∈ edges G" "x ∈ vertices G" "y ∈ vertices G" (*‹(l::'a Standard_Constant, x::'b, y::'b) ∈ edges (G::('a Standard_Constant, 'b) labeled_graph)› ‹(x::'b) ∈ vertices (G::('a Standard_Constant, 'b) labeled_graph)› ‹(y::'b) ∈ vertices (G::('a Standard_Constant, 'b) labeled_graph)›*) hence f: "(f x, x) ∈ getRel S_Idt G" "(f y, y) ∈ getRel S_Idt G" using vert_P (*‹?x ∈ vertices G ⟹ (?x, Eps (P ?x)) ∈ getRel S_Idt G›*) equivE[OF equiv] (*‹(⟦refl_on (vertices G) (getRel S_Idt G); sym (getRel S_Idt G); trans (getRel S_Idt G)⟧ ⟹ ?thesis) ⟹ ?thesis›*) sym_def (*‹sym (?r::(?'a × ?'a) set) = (∀(x::?'a) y::?'a. (x, y) ∈ ?r ⟶ (y, x) ∈ ?r)›*) unfolding f (*goals: 1. ‹(if getRel S_Idt G `` {x} = {} then x else Eps (P x), x) ∈ getRel S_Idt G› 2. ‹(if getRel S_Idt G `` {y} = {} then y else Eps (P y), y) ∈ getRel S_Idt G›*) apply - (*goals: 1. ‹⟦(l, x, y) ∈ edges G; x ∈ vertices G; y ∈ vertices G; ⋀x. x ∈ vertices G ⟹ (x, Eps (P x)) ∈ getRel S_Idt G; ⋀thesis. (⟦refl_on (vertices G) (getRel S_Idt G); sym (getRel S_Idt G); trans (getRel S_Idt G)⟧ ⟹ thesis) ⟹ thesis; ⋀r. sym r = (∀x y. (x, y) ∈ r ⟶ (y, x) ∈ r)⟧ ⟹ (if getRel S_Idt G `` {x} = {} then x else Eps (P x), x) ∈ getRel S_Idt G› 2. ‹⟦(l, x, y) ∈ edges G; x ∈ vertices G; y ∈ vertices G; ⋀x. x ∈ vertices G ⟹ (x, Eps (P x)) ∈ getRel S_Idt G; ⋀thesis. (⟦refl_on (vertices G) (getRel S_Idt G); sym (getRel S_Idt G); trans (getRel S_Idt G)⟧ ⟹ thesis) ⟹ thesis; ⋀r. sym r = (∀x y. (x, y) ∈ r ⟶ (y, x) ∈ r)⟧ ⟹ (if getRel S_Idt G `` {y} = {} then y else Eps (P y), y) ∈ getRel S_Idt G› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . from a (*‹(l, x, y) ∈ edges G› ‹x ∈ vertices G› ‹(y::'b::type) ∈ vertices (G::('a::type Standard_Constant, 'b::type) labeled_graph)›*) have gr: "(x, y) ∈ getRel l G" unfolding getRel_def (*goal: ‹(x, y) ∈ {(x, y). (l, x, y) ∈ edges G}›*) by auto from congruentD[OF congr ( 1 ) [ OF gr ] f ( 1 )] (*‹getRel (l::'a::type Standard_Constant) (G::('a::type Standard_Constant, 'b::type) labeled_graph) `` {(f::'b::type ⇒ 'b::type) (x::'b::type)} = getRel l G `` {x}›*) congruentD[OF congr ( 2 ) [ OF gr ] f ( 2 )] (*‹(getRel l G)¯ `` {f y} = (getRel l G)¯ `` {y}›*) a(1) (*‹(l::'a::type Standard_Constant, x::'b::type, y::'b::type) ∈ edges (G::('a::type Standard_Constant, 'b::type) labeled_graph)›*) have "(l,f x, f y) ∈ edges G" unfolding set_eq_iff getRel_def (*goal: ‹(l, f x, f y) ∈ edges G›*) by auto } note gu1 = this (*‹⟦(?l2, ?x2, ?y2) ∈ edges G; ?x2 ∈ vertices G; ?y2 ∈ vertices G⟧ ⟹ (?l2, f ?x2, f ?y2) ∈ edges G›*) { fix x assume a: "x ∈ vertices G" (*‹(x::'b) ∈ vertices (G::('a Standard_Constant, 'b) labeled_graph)›*) with vert_P (*‹?x ∈ vertices G ⟹ (?x, Eps (P ?x)) ∈ getRel S_Idt G›*) have "(x,Eps (P x)) ∈ getRel S_Idt G" by auto hence "Eps (P x) ∈ vertices G" using assms(1) (*‹graph (G::('a::type Standard_Constant, 'b::type) labeled_graph)›*) unfolding getRel_def (*goal: ‹Eps (P x) ∈ vertices G›*) by auto hence "f x ∈ vertices G" using a (*‹x ∈ vertices G›*) unfolding f (*goal: ‹(if getRel S_Idt G `` {x} = {} then x else Eps (P x)) ∈ vertices G›*) by auto } note gu2 = this (*‹(?x2::'b) ∈ vertices (G::('a Standard_Constant, 'b) labeled_graph) ⟹ (f::'b ⇒ 'b) ?x2 ∈ vertices G›*) have "graph_union (map_graph_fn G f) G = G" using gu1 (*‹⟦(?l2, ?x2, ?y2) ∈ edges G; ?x2 ∈ vertices G; ?y2 ∈ vertices G⟧ ⟹ (?l2, f ?x2, f ?y2) ∈ edges G›*) gu2 (*‹?x2 ∈ vertices G ⟹ f ?x2 ∈ vertices G›*) assms(1) (*‹graph G›*) unfolding graph_union_def (*goal: ‹LG (edges (map_graph_fn G f) ∪ edges G) (vertices (map_graph_fn G f) ∪ vertices G) = G›*) apply (cases G) (*goal: ‹LG (edges (map_graph_fn G f) ∪ edges G) (vertices (map_graph_fn G f) ∪ vertices G) = G›*) by auto hence subg: "subgraph (map_graph_fn G f) G" unfolding subgraph_def (*goal: ‹graph (map_graph_fn G f) ∧ graph G ∧ graph_union (map_graph_fn G f) G = G›*) using assms(1) (*‹graph G›*) by auto have congr: "((l, x, y) ∈ edges G) = ((l, f x, f y) ∈ edges G)" for l and x and y proof (standard) (*goals: 1. ‹(l, x, y) ∈ edges G ⟹ (l, f x, f y) ∈ edges G› 2. ‹(l, f x, f y) ∈ edges G ⟹ (l, x, y) ∈ edges G›*) assume a: "((l, f x, f y) ∈ edges G)" (*‹(l::'a Standard_Constant, (f::'b ⇒ 'b) (x::'b), f (y::'b)) ∈ edges (G::('a Standard_Constant, 'b) labeled_graph)›*) hence gr: "(f x, f y) ∈ getRel l G" unfolding getRel_def (*goal: ‹(f x, f y) ∈ {(x, y). (l, x, y) ∈ edges G}›*) by auto from a (*‹(l::'a Standard_Constant, (f::'b ⇒ 'b) (x::'b), f (y::'b)) ∈ edges (G::('a Standard_Constant, 'b) labeled_graph)›*) have fv: "f x ∈ vertices G" "f y ∈ vertices G" using assms(1) (*‹graph (G::('a Standard_Constant, 'b) labeled_graph)›*) apply - (*goals: 1. ‹⟦(l, f x, f y) ∈ edges G; graph G⟧ ⟹ f x ∈ vertices G› 2. ‹⟦(l, f x, f y) ∈ edges G; graph G⟧ ⟹ f y ∈ vertices G› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . { fix x assume a: "f x ∈ vertices G" "x ∉ vertices G" (*‹(f::'b ⇒ 'b) (x::'b) ∈ vertices (G::('a Standard_Constant, 'b) labeled_graph)› ‹(x::'b) ∉ vertices (G::('a Standard_Constant, 'b) labeled_graph)›*) with assms(1) (*‹graph G›*) have "getRel S_Idt G `` {x} = {}" by auto with a (*‹f x ∈ vertices G› ‹x ∉ vertices G›*) f (*‹(f::'b ⇒ 'b) = (λx::'b. if getRel S_Idt (G::('a Standard_Constant, 'b) labeled_graph) `` {x} = {} then x else SOME y::'b. (P::'b ⇒ 'b ⇒ bool) x y)›*) have False by auto } with fv (*‹(f::'b::type ⇒ 'b::type) (x::'b::type) ∈ vertices (G::('a::type Standard_Constant, 'b::type) labeled_graph)› ‹(f::'b::type ⇒ 'b::type) (y::'b::type) ∈ vertices (G::('a::type Standard_Constant, 'b::type) labeled_graph)›*) have v: "x ∈ vertices G" "y ∈ vertices G" apply - (*goals: 1. ‹⟦(f::'b ⇒ 'b) (x::'b) ∈ vertices (G::('a Standard_Constant, 'b) labeled_graph); f (y::'b) ∈ vertices G; ⋀xa::'b. ⟦f xa ∈ vertices G; xa ∉ vertices G⟧ ⟹ False⟧ ⟹ x ∈ vertices G› 2. ‹⟦(f::'b ⇒ 'b) (x::'b) ∈ vertices (G::('a Standard_Constant, 'b) labeled_graph); f (y::'b) ∈ vertices G; ⋀xa::'b. ⟦f xa ∈ vertices G; xa ∉ vertices G⟧ ⟹ False⟧ ⟹ y ∈ vertices G› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have gx: "(x, f x) ∈ getRel S_Idt G" and gy: "(y, f y) ∈ getRel S_Idt G" (*goals: 1. ‹(x, f x) ∈ getRel S_Idt G› 2. ‹(y, f y) ∈ getRel S_Idt G› discuss goal 1*) apply ((auto simp: f (*‹f = (λx. if getRel S_Idt G `` {x} = {} then x else SOME y. P x y)›*) v (*‹x ∈ vertices G› ‹y ∈ vertices G›*) vert_P (*‹?x ∈ vertices G ⟹ (?x, Eps (P ?x)) ∈ getRel S_Idt G›*))[1]) (*discuss goal 2*) apply ((auto simp: f (*‹f = (λx. if getRel S_Idt G `` {x} = {} then x else SOME y. P x y)›*) v (*‹x ∈ vertices G› ‹y ∈ vertices G›*) vert_P (*‹?x ∈ vertices G ⟹ (?x, Eps (P ?x)) ∈ getRel S_Idt G›*))[1]) (*proven 2 subgoals*) . from congruentD[OF congr ( 1 ) [ OF gr ] gx] (*‹getRel l G `` {x} = getRel l G `` {f x}›*) gr (*‹(f x, f y) ∈ getRel l G›*) have "(x, f y) ∈ getRel l G" by auto with congruentD[OF congr ( 2 ) [ OF gr ] gy] (*‹(getRel (l::'a::type Standard_Constant) (G::('a::type Standard_Constant, 'b::type) labeled_graph))¯ `` {y::'b::type} = (getRel l G)¯ `` {(f::'b::type ⇒ 'b::type) y}›*) have "(x, y) ∈ getRel l G" by auto thus "((l, x, y) ∈ edges G)" unfolding getRel_def (*goal: ‹(l, x, y) ∈ edges G›*) by auto next (*goal: ‹(l, x, y) ∈ edges G ⟹ (l, f x, f y) ∈ edges G›*) assume e: "((l, x, y) ∈ edges G)" (*‹(l::'a Standard_Constant, x::'b, y::'b) ∈ edges (G::('a Standard_Constant, 'b) labeled_graph)›*) hence "x ∈ vertices G" "y ∈ vertices G" using assms(1) (*‹graph (G::('a Standard_Constant, 'b) labeled_graph)›*) apply - (*goals: 1. ‹⟦(l, x, y) ∈ edges G; graph G⟧ ⟹ x ∈ vertices G› 2. ‹⟦(l, x, y) ∈ edges G; graph G⟧ ⟹ y ∈ vertices G› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . from gu1[OF e this] (*‹(l::'a Standard_Constant, (f::'b ⇒ 'b) (x::'b), f (y::'b)) ∈ edges (G::('a Standard_Constant, 'b) labeled_graph)›*) show "((l, f x, f y) ∈ edges G)" . qed from idemp (*‹f ∘ f = f›*) ident (*‹ident_rel S_Idt (map_graph_fn G f)›*) subg (*‹subgraph (map_graph_fn (G::('a Standard_Constant, 'b) labeled_graph) (f::'b ⇒ 'b)) G›*) congr (*‹((?l::'a Standard_Constant, ?x::'b, ?y::'b) ∈ edges (G::('a Standard_Constant, 'b) labeled_graph)) = ((?l, (f::'b ⇒ 'b) ?x, f ?y) ∈ edges G)›*) show "?thesis" (*goal: ‹∃f. f ∘ f = f ∧ ident_rel S_Idt (map_graph_fn G f) ∧ subgraph (map_graph_fn G f) G ∧ (∀l x y. ((l, x, y) ∈ edges G) = ((l, f x, f y) ∈ edges G))›*) by auto qed text ‹The idempotency property of Lemma 7 suffices to show that 'maintained' is preserved.› lemma idemp_embedding_maintained_preserved: assumes subg:"subgraph (map_graph_fn G f) G" and f:"⋀ x. x∈vertices G ⟹ (f o f) x = f x" and maint:"maintained r G" shows "maintained r (map_graph_fn G f)" proof (-) (*goal: ‹maintained r (map_graph_fn G f)›*) { fix h assume hom_h: "graph_homomorphism (fst r) (map_graph_fn G f) h" (*‹graph_homomorphism (fst (r::('a, 'c) labeled_graph × ('a, 'c) labeled_graph)) (map_graph_fn (G::('a, 'b) labeled_graph) (f::'b ⇒ 'b)) (h::('c × 'b) set)›*) from subgraph_preserves_hom[OF subg this] (*‹graph_homomorphism (fst r) G h›*) maint[unfolded maintained_def extensible_def] (*‹∀f. graph_homomorphism (fst r) G f ⟶ (∃g. graph_homomorphism (snd r) G g ∧ agree_on (fst r) f g)›*) obtain g where g: "graph_homomorphism (snd r) G g" "agree_on (fst r) h g" (*goal: ‹(⋀g. ⟦graph_homomorphism (snd r) G g; agree_on (fst r) h g⟧ ⟹ thesis) ⟹ thesis›*) by blast { fix v and x have subs: "h `` {v} ⊆ vertices (map_graph_fn G f)" using hom_h[unfolded graph_homomorphism_def] (*‹vertices (fst r) = Domain h ∧ graph (fst r) ∧ graph (map_graph_fn G f) ∧ h `` vertices (fst r) ⊆ vertices (map_graph_fn G f) ∧ univalent h ∧ edge_preserving h (edges (fst r)) (edges (map_graph_fn G f))›*) by auto assume "v∈vertices (fst r)" and x: "(v, x) ∈ g" (*‹(v::'c) ∈ vertices (fst (r::('a, 'c) labeled_graph × ('a, 'c) labeled_graph))› ‹(v::'c, x::'b) ∈ (g::('c × 'b) set)›*) hence "g `` {v} = h `` {v}" using g(2)[unfolded agree_on_def, rule_format, of v] (*‹v ∈ vertices (fst r) ⟹ h `` {v} = g `` {v}›*) by auto hence "g `` {v} ⊆ vertices (map_graph_fn G f)" using subs (*‹h `` {v} ⊆ vertices (map_graph_fn G f)›*) by auto hence x2: "x ∈ vertices (map_graph_fn G f)" using x (*‹(v, x) ∈ g›*) by auto then obtain y where "x = f y" "y ∈ vertices G" (*goal: ‹(⋀y. ⟦x = f y; y ∈ vertices G⟧ ⟹ thesis) ⟹ thesis›*) by auto hence f: "f x = x" using f (*‹?x ∈ vertices G ⟹ (f ∘ f) ?x = f ?x›*) x2 (*‹(x::'b) ∈ vertices (map_graph_fn (G::('a, 'b) labeled_graph) (f::'b ⇒ 'b))›*) unfolding o_def (*goal: ‹(f::'b ⇒ 'b) (x::'b) = x›*) by metis from x2 (*‹x ∈ vertices (map_graph_fn G f)›*) subgraph_subset[OF subg] (*‹vertices (map_graph_fn G f) ⊆ vertices G› ‹edges (restrict (map_graph_fn (G::('a, 'b) labeled_graph) (f::'b ⇒ 'b))) ⊆ edges G›*) have "(x, f x) ∈ on_graph G f" by auto with x (*‹(v, x) ∈ g›*) have "(v, x) ∈ g O on_graph G f" "f x = x" unfolding f (*goals: 1. ‹(v, x) ∈ g O on_graph G f› 2. ‹x = x›*) apply - (*goals: 1. ‹⟦(v, x) ∈ g; (x, x) ∈ on_graph G f⟧ ⟹ (v, x) ∈ g O on_graph G f› 2. ‹⟦(v, x) ∈ g; (x, x) ∈ on_graph G f⟧ ⟹ x = x› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . } hence agr: "agree_on (fst r) h (g O on_graph G f)" using g(2) (*‹agree_on (fst (r::('a, 'c) labeled_graph × ('a, 'c) labeled_graph)) (h::('c × 'b) set) (g::('c × 'b) set)›*) unfolding agree_on_def (*goal: ‹∀v∈vertices (fst r). h `` {v} = (g O on_graph G f) `` {v}›*) by auto have "extensible r (map_graph_fn G f) h" unfolding extensible_def (*goal: ‹∃g. graph_homomorphism (snd r) (map_graph_fn G f) g ∧ agree_on (fst r) h g›*) using graph_homomorphism_on_graph[OF g ( 1 )] (*‹graph_homomorphism (snd r) (map_graph_fn G ?f) (g O on_graph G ?f)›*) agr (*‹agree_on (fst r) h (g O on_graph G f)›*) by blast } thus "?thesis" (*goal: ‹maintained r (map_graph_fn G f)›*) unfolding maintained_def (*goal: ‹∀fa. graph_homomorphism (fst r) (map_graph_fn G f) fa ⟶ extensible r (map_graph_fn G f) fa›*) by blast qed text ‹Definition 20.› definition const_exists where "const_exists c ≡ transl_rule (⊤ ⊑ A_Cmp (A_Cmp ⊤ (A_Lbl (S_Const c))) ⊤)" definition const_exists_rev where "const_exists_rev c ≡ transl_rule (A_Cmp (A_Cmp (A_Lbl (S_Const c)) ⊤) (A_Lbl (S_Const c)) ⊑ A_Lbl (S_Const c))" definition const_prop where "const_prop c ≡ transl_rule (A_Lbl (S_Const c) ⊑ 𝟭)" definition const_disj where "const_disj c₁ c₂ ≡ transl_rule (A_Cmp (A_Lbl (S_Const c₁)) (A_Lbl (S_Const c₂)) ⊑ ⊥)" lemma constant_rules: assumes "standard' C G" "c ∈ C" shows "maintained (const_exists c) G" "maintained (const_exists_rev c) G" "maintained (const_prop c) G" "c' ∈ C ⟹ c ≠ c' ⟹ maintained (const_disj c c') G" proof (-) (*goals: 1. ‹maintained (const_exists c) G› 2. ‹maintained (const_exists_rev c) G› 3. ‹maintained (const_prop c) G› 4. ‹⟦c' ∈ C; c ≠ c'⟧ ⟹ maintained (const_disj c c') G›*) note a = assms[unfolded standard_def] (*‹graph G ∧ vertices G ≠ {} ∧ ident_rel S_Idt G ∧ getRel S_Bot G = {} ∧ getRel S_Top G = {(x, y). x ∈ vertices G ∧ y ∈ vertices G} ∧ (∀(l, v)∈(λc. (S_Const c, Inl c)) ` C. getRel l G = {(v, v)})› ‹c ∈ C›*) from a (*‹graph G ∧ vertices G ≠ {} ∧ ident_rel S_Idt G ∧ getRel S_Bot G = {} ∧ getRel S_Top G = {(x, y). x ∈ vertices G ∧ y ∈ vertices G} ∧ (∀(l, v)∈(λc. (S_Const c, Inl c)) ` C. getRel l G = {(v, v)})› ‹c ∈ C›*) have g: "graph G" by auto from a (*‹graph G ∧ vertices G ≠ {} ∧ ident_rel S_Idt G ∧ getRel S_Bot G = {} ∧ getRel S_Top G = {(x, y). x ∈ vertices G ∧ y ∈ vertices G} ∧ (∀(l, v)∈(λc. (S_Const c, Inl c)) ` C. getRel l G = {(v, v)})› ‹c ∈ C›*) have gr_c: "getRel (S_Const c) G = {(Inl c, Inl c)}" "getRel S_Idt G = Id_on (vertices G)" "getRel S_Bot G = {}" "getRel S_Top G = vertices G × vertices G" apply - (*goals: 1. ‹⟦graph G ∧ vertices G ≠ {} ∧ ident_rel S_Idt G ∧ getRel S_Bot G = {} ∧ getRel S_Top G = {(x, y). x ∈ vertices G ∧ y ∈ vertices G} ∧ (∀(l, v)∈(λc. (S_Const c, Inl c)) ` C. getRel l G = {(v, v)}); c ∈ C⟧ ⟹ getRel (S_Const c) G = {(Inl c, Inl c)}› 2. ‹⟦graph G ∧ vertices G ≠ {} ∧ ident_rel S_Idt G ∧ getRel S_Bot G = {} ∧ getRel S_Top G = {(x, y). x ∈ vertices G ∧ y ∈ vertices G} ∧ (∀(l, v)∈(λc. (S_Const c, Inl c)) ` C. getRel l G = {(v, v)}); c ∈ C⟧ ⟹ getRel S_Idt G = Id_on (vertices G)› 3. ‹⟦graph G ∧ vertices G ≠ {} ∧ ident_rel S_Idt G ∧ getRel S_Bot G = {} ∧ getRel S_Top G = {(x, y). x ∈ vertices G ∧ y ∈ vertices G} ∧ (∀(l, v)∈(λc. (S_Const c, Inl c)) ` C. getRel l G = {(v, v)}); c ∈ C⟧ ⟹ getRel S_Bot G = {}› 4. ‹⟦graph G ∧ vertices G ≠ {} ∧ ident_rel S_Idt G ∧ getRel S_Bot G = {} ∧ getRel S_Top G = {(x, y). x ∈ vertices G ∧ y ∈ vertices G} ∧ (∀(l, v)∈(λc. (S_Const c, Inl c)) ` C. getRel l G = {(v, v)}); c ∈ C⟧ ⟹ getRel S_Top G = vertices G × vertices G› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . with g (*‹graph G›*) have inlc: "Inl c ∈ vertices G" by (metis getRel_dom( (*‹⟦graph ?G; (?a, ?b) ∈ getRel ?l ?G⟧ ⟹ ?a ∈ vertices ?G›*) 1) singletonI (*‹?a ∈ {?a}›*)) thus "maintained (const_exists c) G" "maintained (const_exists_rev c) G" "maintained (const_prop c) G" unfolding const_prop_def const_exists_rev_def const_exists_def maintained_holds_subset_iff[OF g] (*goals: 1. ‹:G:⟦⊤⟧ ⊆ :G:⟦A_Cmp (A_Cmp ⊤ (A_Lbl (S_Const c))) ⊤⟧› 2. ‹:G:⟦A_Cmp (A_Cmp (A_Lbl (S_Const c)) ⊤) (A_Lbl (S_Const c))⟧ ⊆ :G:⟦A_Lbl (S_Const c)⟧› 3. ‹:G:⟦A_Lbl (S_Const c)⟧ ⊆ :G:⟦𝟭⟧›*) apply - (*goals: 1. ‹Inl c ∈ vertices G ⟹ :G:⟦⊤⟧ ⊆ :G:⟦A_Cmp (A_Cmp ⊤ (A_Lbl (S_Const c))) ⊤⟧› 2. ‹Inl c ∈ vertices G ⟹ :G:⟦A_Cmp (A_Cmp (A_Lbl (S_Const c)) ⊤) (A_Lbl (S_Const c))⟧ ⊆ :G:⟦A_Lbl (S_Const c)⟧› 3. ‹Inl c ∈ vertices G ⟹ :G:⟦A_Lbl (S_Const c)⟧ ⊆ :G:⟦𝟭⟧› discuss goal 1*) apply ((auto simp:gr_c (*‹getRel (S_Const c) G = {(Inl c, Inl c)}› ‹getRel S_Idt G = Id_on (vertices G)› ‹getRel S_Bot G = {}› ‹getRel S_Top G = vertices G × vertices G›*) relcomp_unfold (*‹?r O ?s = {(x, z). ∃y. (x, y) ∈ ?r ∧ (y, z) ∈ ?s}›*))[1]) (*discuss goal 2*) apply ((auto simp:gr_c (*‹getRel (S_Const c) G = {(Inl c, Inl c)}› ‹getRel S_Idt G = Id_on (vertices G)› ‹getRel S_Bot G = {}› ‹getRel S_Top G = vertices G × vertices G›*) relcomp_unfold (*‹?r O ?s = {(x, z). ∃y. (x, y) ∈ ?r ∧ (y, z) ∈ ?s}›*))[1]) (*discuss goal 3*) apply ((auto simp:gr_c (*‹getRel (S_Const c) G = {(Inl c, Inl c)}› ‹getRel S_Idt G = Id_on (vertices G)› ‹getRel S_Bot G = {}› ‹getRel S_Top G = vertices G × vertices G›*) relcomp_unfold (*‹?r O ?s = {(x, z). ∃y. (x, y) ∈ ?r ∧ (y, z) ∈ ?s}›*))[1]) (*proven 3 subgoals*) . assume "c' ∈ C" (*‹(c'::'a) ∈ (C::'a set)›*) with a (*‹graph G ∧ vertices G ≠ {} ∧ ident_rel S_Idt G ∧ getRel S_Bot G = {} ∧ getRel S_Top G = {(x, y). x ∈ vertices G ∧ y ∈ vertices G} ∧ (∀(l, v)∈(λc. (S_Const c, Inl c)) ` C. getRel l G = {(v, v)})› ‹c ∈ C›*) have gr_c': "getRel (S_Const c') G = {(Inl c', Inl c')}" by auto thus "c ≠ c' ⟹ maintained (const_disj c c') G" unfolding const_disj_def maintained_holds_subset_iff[OF g] (*goal: ‹c ≠ c' ⟹ :G:⟦A_Cmp (A_Lbl (S_Const c)) (A_Lbl (S_Const c'))⟧ ⊆ :G:⟦⊥⟧›*) using gr_c (*‹getRel (S_Const c) G = {(Inl c, Inl c)}› ‹getRel S_Idt G = Id_on (vertices G)› ‹getRel S_Bot G = {}› ‹getRel S_Top G = vertices G × vertices G›*) by auto qed definition constant_rules where "constant_rules C ≡ const_exists ` C ∪ const_exists_rev ` C ∪ const_prop ` C ∪ {const_disj c₁ c₂ | c₁ c₂. c₁ ∈ C ∧ c₂ ∈ C ∧ c₁ ≠ c₂}" lemma constant_rules_graph_rule: assumes "x ∈ constant_rules C" shows "graph_rule x" proof (-) (*goal: ‹graph_rule x›*) from graph_rule_translation (*‹graph_rule (translation ?X, translation (A_Int ?X ?Y))›*) have gr: "⋀ u v . graph_rule (transl_rule (u ⊑ v))" by auto consider "∃ v. x = const_exists v" | "∃ v. x = const_exists_rev v" | "∃ v. x = const_prop v" | "∃ v w. x = const_disj v w" (*goal: ‹⟦∃v::'a::type. (x::('a::type Standard_Constant, nat) labeled_graph × ('a::type Standard_Constant, nat) labeled_graph) = const_exists v ⟹ thesis::bool; ∃v::'a::type. x = const_exists_rev v ⟹ thesis; ∃v::'a::type. x = const_prop v ⟹ thesis; ∃(v::'a::type) w::'a::type. x = const_disj v w ⟹ thesis⟧ ⟹ thesis›*) using assms (*‹x ∈ constant_rules C›*) unfolding constant_rules_def Un_iff (*goal: ‹⟦∃v. x = const_exists v ⟹ thesis; ∃v. x = const_exists_rev v ⟹ thesis; ∃v. x = const_prop v ⟹ thesis; ∃v w. x = const_disj v w ⟹ thesis⟧ ⟹ thesis›*) by blast thus "?thesis" (*goal: ‹graph_rule x›*) using gr (*‹graph_rule (transl_rule (?u ⊑ ?v))›*) unfolding const_exists_def const_exists_rev_def const_prop_def const_disj_def (*goal: ‹graph_rule x›*) apply cases (*goals: 1. ‹⟦⋀u v. graph_rule (transl_rule (u ⊑ v)); ∃v. x = transl_rule (⊤ ⊑ A_Cmp (A_Cmp ⊤ (A_Lbl (S_Const v))) ⊤)⟧ ⟹ graph_rule x› 2. ‹⟦⋀u v. graph_rule (transl_rule (u ⊑ v)); ∃v. x = transl_rule (A_Cmp (A_Cmp (A_Lbl (S_Const v)) ⊤) (A_Lbl (S_Const v)) ⊑ A_Lbl (S_Const v))⟧ ⟹ graph_rule x› 3. ‹⟦⋀u v. graph_rule (transl_rule (u ⊑ v)); ∃v. x = transl_rule (A_Lbl (S_Const v) ⊑ 𝟭)⟧ ⟹ graph_rule x› 4. ‹⟦⋀u v. graph_rule (transl_rule (u ⊑ v)); ∃v w. x = transl_rule (A_Cmp (A_Lbl (S_Const v)) (A_Lbl (S_Const w)) ⊑ ⊥)⟧ ⟹ graph_rule x› discuss goal 1*) apply fast (*discuss goal 2*) apply fast (*discuss goal 3*) apply fast (*discuss goal 4*) apply fast (*proven 4 subgoals*) . qed lemma finite_constant[intro]: assumes "finite C" shows "finite (constant_rules C)" proof (-) (*goal: ‹finite (constant_rules C)›*) have "{const_disj c₁ c₂ | c₁ c₂. c₁ ∈ C ∧ c₂ ∈ C ∧ c₁ ≠ c₂} ⊆ case_prod const_disj ` (C × C)" by auto moreover have "finite …" using assms (*‹finite C›*) by auto ultimately have "finite {const_disj c₁ c₂ | c₁ c₂. c₁ ∈ C ∧ c₂ ∈ C ∧ c₁ ≠ c₂}" by (rule finite_subset (*‹⟦?A ⊆ ?B; finite ?B⟧ ⟹ finite ?A›*)) thus "?thesis" (*goal: ‹finite (constant_rules C)›*) unfolding constant_rules_def (*goal: ‹finite (const_exists ` C ∪ const_exists_rev ` C ∪ const_prop ` C ∪ {const_disj c₁ c₂ |c₁ c₂. c₁ ∈ C ∧ c₂ ∈ C ∧ c₁ ≠ c₂})›*) using assms (*‹finite C›*) by blast qed lemma standard_maintains_constant_rules: assumes "standard' C G" "R∈constant_rules C" shows "maintained R G" proof (-) (*goal: ‹maintained R G›*) from assms(2)[unfolded constant_rules_def] (*‹R ∈ const_exists ` C ∪ const_exists_rev ` C ∪ const_prop ` C ∪ {const_disj c₁ c₂ |c₁ c₂. c₁ ∈ C ∧ c₂ ∈ C ∧ c₁ ≠ c₂}›*) consider "∃ c ∈ C. R = const_exists c" | "∃ c ∈ C. R = const_exists_rev c" | "∃ c ∈ C. R = const_prop c" | "∃ c₁ c₂. c₁ ∈ C ∧ c₂ ∈ C ∧ c₁ ≠ c₂ ∧ R = const_disj c₁ c₂" (*goal: ‹⟦∃c∈C. R = const_exists c ⟹ thesis; ∃c∈C. R = const_exists_rev c ⟹ thesis; ∃c∈C. R = const_prop c ⟹ thesis; ∃c₁ c₂. c₁ ∈ C ∧ c₂ ∈ C ∧ c₁ ≠ c₂ ∧ R = const_disj c₁ c₂ ⟹ thesis⟧ ⟹ thesis›*) by blast from this (*‹⟦∃c∈C. R = const_exists c ⟹ ?thesis2; ∃c∈C. R = const_exists_rev c ⟹ ?thesis2; ∃c∈C. R = const_prop c ⟹ ?thesis2; ∃c₁ c₂. c₁ ∈ C ∧ c₂ ∈ C ∧ c₁ ≠ c₂ ∧ R = const_disj c₁ c₂ ⟹ ?thesis2⟧ ⟹ ?thesis2›*) assms(1) (*‹standard' C G›*) show "?thesis" (*goal: ‹maintained R G›*) apply cases (*goals: 1. ‹⟦standard' C G; ∃c∈C. R = const_exists c⟧ ⟹ maintained R G› 2. ‹⟦standard' C G; ∃c∈C. R = const_exists_rev c⟧ ⟹ maintained R G› 3. ‹⟦standard' C G; ∃c∈C. R = const_prop c⟧ ⟹ maintained R G› 4. ‹⟦standard' C G; ∃c₁ c₂. c₁ ∈ C ∧ c₂ ∈ C ∧ c₁ ≠ c₂ ∧ R = const_disj c₁ c₂⟧ ⟹ maintained R G› discuss goal 1*) apply ((auto simp:constant_rules (*‹⟦standard' ?C ?G; ?c ∈ ?C⟧ ⟹ maintained (const_exists ?c) ?G› ‹⟦standard' ?C ?G; ?c ∈ ?C⟧ ⟹ maintained (const_exists_rev ?c) ?G› ‹⟦standard' ?C ?G; ?c ∈ ?C⟧ ⟹ maintained (const_prop ?c) ?G› ‹⟦standard' ?C ?G; ?c ∈ ?C; ?c' ∈ ?C; ?c ≠ ?c'⟧ ⟹ maintained (const_disj ?c ?c') ?G›*))[1]) (*discuss goal 2*) apply ((auto simp:constant_rules (*‹⟦standard' ?C ?G; ?c ∈ ?C⟧ ⟹ maintained (const_exists ?c) ?G› ‹⟦standard' ?C ?G; ?c ∈ ?C⟧ ⟹ maintained (const_exists_rev ?c) ?G› ‹⟦standard' ?C ?G; ?c ∈ ?C⟧ ⟹ maintained (const_prop ?c) ?G› ‹⟦standard' ?C ?G; ?c ∈ ?C; ?c' ∈ ?C; ?c ≠ ?c'⟧ ⟹ maintained (const_disj ?c ?c') ?G›*))[1]) (*discuss goal 3*) apply ((auto simp:constant_rules (*‹⟦standard' ?C ?G; ?c ∈ ?C⟧ ⟹ maintained (const_exists ?c) ?G› ‹⟦standard' ?C ?G; ?c ∈ ?C⟧ ⟹ maintained (const_exists_rev ?c) ?G› ‹⟦standard' ?C ?G; ?c ∈ ?C⟧ ⟹ maintained (const_prop ?c) ?G› ‹⟦standard' ?C ?G; ?c ∈ ?C; ?c' ∈ ?C; ?c ≠ ?c'⟧ ⟹ maintained (const_disj ?c ?c') ?G›*))[1]) (*discuss goal 4*) apply ((auto simp:constant_rules (*‹⟦standard' ?C ?G; ?c ∈ ?C⟧ ⟹ maintained (const_exists ?c) ?G› ‹⟦standard' ?C ?G; ?c ∈ ?C⟧ ⟹ maintained (const_exists_rev ?c) ?G› ‹⟦standard' ?C ?G; ?c ∈ ?C⟧ ⟹ maintained (const_prop ?c) ?G› ‹⟦standard' ?C ?G; ?c ∈ ?C; ?c' ∈ ?C; ?c ≠ ?c'⟧ ⟹ maintained (const_disj ?c ?c') ?G›*))[1]) (*proven 4 subgoals*) . qed lemma constant_rules_empty[simp]: "constant_rules {} = {}" by (auto simp:constant_rules_def (*‹constant_rules ?C ≡ const_exists ` ?C ∪ const_exists_rev ` ?C ∪ const_prop ` ?C ∪ {const_disj c₁ c₂ |c₁ c₂. c₁ ∈ ?C ∧ c₂ ∈ ?C ∧ c₁ ≠ c₂}›*)) text ‹Definition 20, continued.› definition standard_rules :: "'a set ⇒ 'a Standard_Constant set ⇒ (('a Standard_Constant, nat) labeled_graph × ('a Standard_Constant, nat) labeled_graph) set" where "standard_rules C L ≡ constant_rules C ∪ identity_rules L ∪ {top_rule S_Top,nonempty_rule}" lemma constant_rules_mono: assumes "C₁ ⊆ C₂" shows "constant_rules C₁ ⊆ constant_rules C₂" using assms (*‹C₁ ⊆ C₂›*) unfolding constant_rules_def (*goal: ‹const_exists ` C₁ ∪ const_exists_rev ` C₁ ∪ const_prop ` C₁ ∪ {const_disj c₁ c₂ |c₁ c₂. c₁ ∈ C₁ ∧ c₂ ∈ C₁ ∧ c₁ ≠ c₂} ⊆ const_exists ` C₂ ∪ const_exists_rev ` C₂ ∪ const_prop ` C₂ ∪ {const_disj c₁ c₂ |c₁ c₂. c₁ ∈ C₂ ∧ c₂ ∈ C₂ ∧ c₁ ≠ c₂}›*) apply (intro Un_mono (*‹⟦?A ⊆ ?C; ?B ⊆ ?D⟧ ⟹ ?A ∪ ?B ⊆ ?C ∪ ?D›*)) (*goals: 1. ‹C₁ ⊆ C₂ ⟹ const_exists ` C₁ ⊆ const_exists ` C₂› 2. ‹C₁ ⊆ C₂ ⟹ const_exists_rev ` C₁ ⊆ const_exists_rev ` C₂› 3. ‹C₁ ⊆ C₂ ⟹ const_prop ` C₁ ⊆ const_prop ` C₂› 4. ‹C₁ ⊆ C₂ ⟹ {const_disj c₁ c₂ |c₁ c₂. c₁ ∈ C₁ ∧ c₂ ∈ C₁ ∧ c₁ ≠ c₂} ⊆ {const_disj c₁ c₂ |c₁ c₂. c₁ ∈ C₂ ∧ c₂ ∈ C₂ ∧ c₁ ≠ c₂}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . (* also works with just auto, this is faster *) lemma identity_rules_mono: assumes "C₁ ⊆ C₂" shows "identity_rules C₁ ⊆ identity_rules C₂" using assms (*‹C₁ ⊆ C₂›*) unfolding identity_rules_def (*goal: ‹{reflexivity_rule S_Idt, transitive_rule S_Idt, symmetry_rule S_Idt} ∪ congruence_rules S_Idt C₁ ⊆ {reflexivity_rule S_Idt, transitive_rule S_Idt, symmetry_rule S_Idt} ∪ congruence_rules S_Idt C₂›*) by auto lemma standard_rules_mono: assumes "C₁ ⊆ C₂" "L₁ ⊆ L₂" shows "standard_rules C₁ L₁ ⊆ standard_rules C₂ L₂" using constant_rules_mono[OF assms ( 1 )] (*‹constant_rules C₁ ⊆ constant_rules C₂›*) identity_rules_mono[OF assms ( 2 )] (*‹identity_rules (L₁::'a Standard_Constant set) ⊆ identity_rules (L₂::'a Standard_Constant set)›*) unfolding standard_rules_def (*goal: ‹constant_rules C₁ ∪ identity_rules L₁ ∪ {top_rule S_Top, nonempty_rule} ⊆ constant_rules C₂ ∪ identity_rules L₂ ∪ {top_rule S_Top, nonempty_rule}›*) by auto lemma maintainedA_invmono: assumes "C₁ ⊆ C₂" "L₁ ⊆ L₂" shows "maintainedA (standard_rules C₂ L₂) G ⟹ maintainedA (standard_rules C₁ L₁) G" using standard_rules_mono[OF assms] (*‹standard_rules C₁ L₁ ⊆ standard_rules C₂ L₂›*) by auto lemma maintained_preserved_by_isomorphism: assumes "⋀ x. x ∈ vertices G ⟹ (f ∘ g) x = x" "graph G" and "maintained r (map_graph_fn G g)" shows "maintained r G" proof (cases r) (*goal: ‹⋀a b. r = (a, b) ⟹ maintained r G›*) case (Pair L R) (*‹r = (L, R)›*) show "?thesis" (*goal: ‹maintained (r::('b, 'd) labeled_graph × ('b, 'd) labeled_graph) (G::('b, 'a) labeled_graph)›*) unfolding Pair (*goal: ‹maintained (L, R) G›*) apply standard (*goal: ‹maintained (L, R) G›*) proof (goal_cases) (*goal: ‹⋀f. graph_homomorphism L G f ⟹ extensible (L, R) G f›*) case (1 h) (*‹graph_homomorphism L G h›*) from assms(3)[unfolded maintained_def Pair] (*‹∀f. graph_homomorphism (fst (L, R)) (map_graph_fn G g) f ⟶ extensible (L, R) (map_graph_fn G g) f›*) graph_homomorphism_on_graph[OF this, of g] (*‹graph_homomorphism L (map_graph_fn G g) (h O on_graph G g)›*) have "extensible (L, R) (map_graph_fn G g) (h O on_graph G g)" by auto then obtain h2 where h2: "graph_homomorphism R (map_graph_fn G g) h2" "agree_on L (h O on_graph G g) h2" (*goal: ‹(⋀h2. ⟦graph_homomorphism R (map_graph_fn G g) h2; agree_on L (h O on_graph G g) h2⟧ ⟹ thesis) ⟹ thesis›*) unfolding extensible_def (*goal: ‹(⋀h2. ⟦graph_homomorphism R (map_graph_fn G g) h2; agree_on L (h O on_graph G g) h2⟧ ⟹ thesis) ⟹ thesis›*) by auto from "1" (*‹graph_homomorphism (L::('b::type, 'd::type) labeled_graph) (G::('b::type, 'a::type) labeled_graph) (h::('d::type × 'a::type) set)›*) have h_id: "h O Id_on (vertices G) = h" unfolding graph_homomorphism_def (*goal: ‹h O Id_on (vertices G) = h›*) by auto let ?h = "h2 O on_graph (map_graph_fn G g) f" from assms(1) (*‹(?x::'a) ∈ vertices (G::('b, 'a) labeled_graph) ⟹ ((f::'c ⇒ 'a) ∘ (g::'a ⇒ 'c)) ?x = ?x›*) have "on_graph G (f ∘ g) = Id_on (vertices G)" by auto hence "map_graph_fn G (f ∘ g) = G" using assms(2) (*‹graph G›*) map_graph_fn_id (*‹map_graph_fn ?X id = restrict ?X› ‹map_graph (Id_on (vertices ?X)) ?X = restrict ?X›*) by auto with graph_homomorphism_on_graph[OF h2 ( 1 ), of f] (*‹graph_homomorphism R (map_graph_fn (map_graph_fn G g) f) (h2 O on_graph (map_graph_fn G g) f)›*) have igh: "graph_homomorphism R G ?h" by auto have "g x = g xa ⟹ x ∈ (vertices G) ⟹ xa ∈ (vertices G) ⟹ x = xa" for x and xa using assms(1) (*‹?x ∈ vertices G ⟹ (f ∘ g) ?x = ?x›*) o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*) by metis hence "g x = g xa ⟹ x ∈ (vertices G) ⟹ xa ∈ (vertices G) ⟹ (x, xa) ∈ Id_on (vertices G)" for x and xa by auto hence id: "(on_graph G g) O on_graph (map_graph_fn G g) f = Id_on (vertices G)" using assms(1) (*‹?x ∈ vertices G ⟹ (f ∘ g) ?x = ?x›*) by auto from agree_on_ext[OF h2 ( 2 ), of "on_graph (map_graph_fn G g) f", unfolded O_assoc] (*‹agree_on L (h O on_graph G g O on_graph (map_graph_fn G g) f) (h2 O on_graph (map_graph_fn G g) f)›*) have agh: "agree_on L h ?h" unfolding agree_on_def id h_id (*goal: ‹∀v∈vertices L. h `` {v} = (h2 O on_graph (map_graph_fn G g) f) `` {v}›*) . from igh (*‹graph_homomorphism R G (h2 O on_graph (map_graph_fn G g) f)›*) agh (*‹agree_on L h (h2 O on_graph (map_graph_fn G g) f)›*) show "?case" (*goal: ‹extensible (L, R) G h›*) unfolding extensible_def (*goal: ‹∃g. graph_homomorphism (snd (L, R)) G g ∧ agree_on (fst (L, R)) h g›*) by auto qed qed lemma standard_identity_rules: assumes "standard' C G" shows "maintained (reflexivity_rule S_Idt) G" "maintained (transitive_rule S_Idt) G" "maintained (symmetry_rule S_Idt) G" "maintained (congruence_rule S_Idt l) G" proof (-) (*goals: 1. ‹maintained (reflexivity_rule S_Idt) G› 2. ‹maintained (transitive_rule S_Idt) G› 3. ‹maintained (symmetry_rule S_Idt) G› 4. ‹maintained (congruence_rule S_Idt l) G›*) note a = assms[unfolded standard_def] (*‹graph (G::('a Standard_Constant, 'a + 'b) labeled_graph) ∧ vertices G ≠ {} ∧ ident_rel S_Idt G ∧ getRel S_Bot G = {} ∧ getRel S_Top G = {(x::'a + 'b, y::'a + 'b). x ∈ vertices G ∧ y ∈ vertices G} ∧ (∀(l::'a Standard_Constant, v::'a + 'b)∈(λc::'a. (S_Const c, Inl c)) ` (C::'a set). getRel l G = {(v, v)})›*) from a (*‹graph G ∧ vertices G ≠ {} ∧ ident_rel S_Idt G ∧ getRel S_Bot G = {} ∧ getRel S_Top G = {(x, y). x ∈ vertices G ∧ y ∈ vertices G} ∧ (∀(l, v)∈(λc. (S_Const c, Inl c)) ` C. getRel l G = {(v, v)})›*) have g: "graph G" by auto from a (*‹graph (G::('a::type Standard_Constant, 'a::type + 'b::type) labeled_graph) ∧ vertices G ≠ {} ∧ ident_rel S_Idt G ∧ getRel S_Bot G = {} ∧ getRel S_Top G = {(x::'a::type + 'b::type, y::'a::type + 'b::type). x ∈ vertices G ∧ y ∈ vertices G} ∧ (∀(l::'a::type Standard_Constant, v::'a::type + 'b::type)∈(λc::'a::type. (S_Const c, Inl c)) ` (C::'a::type set). getRel l G = {(v, v)})›*) have gr: "getRel S_Idt G = Id_on (vertices G)" "getRel S_Bot G = {}" "getRel S_Top G = vertices G × vertices G" and v_gr: "∀a b. ((S_Idt, a, b) ∈ edges G) = (a ∈ vertices G ∧ b = a)" unfolding getRel_def (*goals: 1. ‹{(x, y). (S_Idt, x, y) ∈ edges G} = Id_on (vertices G)› 2. ‹{(x, y). (S_Bot, x, y) ∈ edges G} = {}› 3. ‹{(x, y). (S_Top, x, y) ∈ edges G} = vertices G × vertices G› 4. ‹∀a b. ((S_Idt, a, b) ∈ edges G) = (a ∈ vertices G ∧ b = a)›*) apply - (*goals: 1. ‹graph G ∧ vertices G ≠ {} ∧ {(x, y). (S_Idt, x, y) ∈ edges G} = (λx. (x, x)) ` vertices G ∧ {(x, y). (S_Bot, x, y) ∈ edges G} = {} ∧ {(x, y). (S_Top, x, y) ∈ edges G} = {(x, y). x ∈ vertices G ∧ y ∈ vertices G} ∧ (∀(l, v)∈(λc. (S_Const c, Inl c)) ` C. {(x, y). (l, x, y) ∈ edges G} = {(v, v)}) ⟹ {(x, y). (S_Idt, x, y) ∈ edges G} = Id_on (vertices G)› 2. ‹graph G ∧ vertices G ≠ {} ∧ {(x, y). (S_Idt, x, y) ∈ edges G} = (λx. (x, x)) ` vertices G ∧ {(x, y). (S_Bot, x, y) ∈ edges G} = {} ∧ {(x, y). (S_Top, x, y) ∈ edges G} = {(x, y). x ∈ vertices G ∧ y ∈ vertices G} ∧ (∀(l, v)∈(λc. (S_Const c, Inl c)) ` C. {(x, y). (l, x, y) ∈ edges G} = {(v, v)}) ⟹ {(x, y). (S_Bot, x, y) ∈ edges G} = {}› 3. ‹graph G ∧ vertices G ≠ {} ∧ {(x, y). (S_Idt, x, y) ∈ edges G} = (λx. (x, x)) ` vertices G ∧ {(x, y). (S_Bot, x, y) ∈ edges G} = {} ∧ {(x, y). (S_Top, x, y) ∈ edges G} = {(x, y). x ∈ vertices G ∧ y ∈ vertices G} ∧ (∀(l, v)∈(λc. (S_Const c, Inl c)) ` C. {(x, y). (l, x, y) ∈ edges G} = {(v, v)}) ⟹ {(x, y). (S_Top, x, y) ∈ edges G} = vertices G × vertices G› 4. ‹graph G ∧ vertices G ≠ {} ∧ {(x, y). (S_Idt, x, y) ∈ edges G} = (λx. (x, x)) ` vertices G ∧ {(x, y). (S_Bot, x, y) ∈ edges G} = {} ∧ {(x, y). (S_Top, x, y) ∈ edges G} = {(x, y). x ∈ vertices G ∧ y ∈ vertices G} ∧ (∀(l, v)∈(λc. (S_Const c, Inl c)) ` C. {(x, y). (l, x, y) ∈ edges G} = {(v, v)}) ⟹ ∀a b. ((S_Idt, a, b) ∈ edges G) = (a ∈ vertices G ∧ b = a)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . thus "maintained (transitive_rule S_Idt) G" "maintained (symmetry_rule S_Idt) G" "maintained (congruence_rule S_Idt l) G" unfolding transitive_rule_def symmetry_rule_def congruence_rule_def maintained_holds_subset_iff[OF g] (*goals: 1. ‹:G:⟦A_Cmp 𝟭 𝟭⟧ ⊆ :G:⟦𝟭⟧› 2. ‹:G:⟦A_Cnv 𝟭⟧ ⊆ :G:⟦𝟭⟧› 3. ‹:G:⟦A_Cmp (A_Cmp 𝟭 (A_Lbl l)) 𝟭⟧ ⊆ :G:⟦A_Lbl l⟧›*) (*goals: 1. ‹:G:⟦A_Cmp 𝟭 𝟭⟧ ⊆ :G:⟦𝟭⟧› 2. ‹:G:⟦A_Cnv 𝟭⟧ ⊆ :G:⟦𝟭⟧› 3. ‹:G:⟦A_Cmp (A_Cmp 𝟭 (A_Lbl l)) 𝟭⟧ ⊆ :G:⟦A_Lbl l⟧› discuss goal 1*) apply ((auto simp:gr (*‹getRel S_Idt G = Id_on (vertices G)› ‹getRel S_Bot G = {}› ‹getRel S_Top G = vertices G × vertices G›*) relcomp_unfold (*‹?r O ?s = {(x, z). ∃y. (x, y) ∈ ?r ∧ (y, z) ∈ ?s}›*))[1]) (*discuss goal 2*) apply ((auto simp:gr (*‹getRel S_Idt G = Id_on (vertices G)› ‹getRel S_Bot G = {}› ‹getRel S_Top G = vertices G × vertices G›*) relcomp_unfold (*‹?r O ?s = {(x, z). ∃y. (x, y) ∈ ?r ∧ (y, z) ∈ ?s}›*))[1]) (*discuss goal 3*) apply ((auto simp:gr (*‹getRel S_Idt G = Id_on (vertices G)› ‹getRel S_Bot G = {}› ‹getRel S_Top G = vertices G × vertices G›*) relcomp_unfold (*‹?r O ?s = {(x, z). ∃y. (x, y) ∈ ?r ∧ (y, z) ∈ ?s}›*))[1]) (*proven 3 subgoals*) . { fix f :: "(nat × ('a + 'b)) set" assume "graph_homomorphism (LG {} {0}) G f" (*‹graph_homomorphism (LG {} {0::nat}) (G::('a Standard_Constant, 'a + 'b) labeled_graph) (f::(nat × ('a + 'b)) set)›*) hence u: "univalent f" and d: "Domain f = {0}" and r: "f `` {0} ⊆ vertices G" unfolding graph_homomorphism_def (*goals: 1. ‹univalent (f::(nat × ('a + 'b)) set)› 2. ‹Domain (f::(nat × ('a + 'b)) set) = {0::nat}› 3. ‹(f::(nat × ('a + 'b)) set) `` {0::nat} ⊆ vertices (G::('a Standard_Constant, 'a + 'b) labeled_graph)›*) apply - (*goals: 1. ‹vertices (LG {} {0}) = Domain f ∧ graph (LG {} {0}) ∧ graph G ∧ f `` vertices (LG {} {0}) ⊆ vertices G ∧ univalent f ∧ edge_preserving f (edges (LG {} {0})) (edges G) ⟹ univalent f› 2. ‹vertices (LG {} {0}) = Domain f ∧ graph (LG {} {0}) ∧ graph G ∧ f `` vertices (LG {} {0}) ⊆ vertices G ∧ univalent f ∧ edge_preserving f (edges (LG {} {0})) (edges G) ⟹ Domain f = {0}› 3. ‹vertices (LG {} {0}) = Domain f ∧ graph (LG {} {0}) ∧ graph G ∧ f `` vertices (LG {} {0}) ⊆ vertices G ∧ univalent f ∧ edge_preserving f (edges (LG {} {0})) (edges G) ⟹ f `` {0} ⊆ vertices G› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*goal: ‹vertices (LG {} {0}) = Domain f ∧ graph (LG {} {0}) ∧ graph G ∧ f `` vertices (LG {} {0}) ⊆ vertices G ∧ univalent f ∧ edge_preserving f (edges (LG {} {0})) (edges G) ⟹ f `` {0} ⊆ vertices G›*) apply (msorry) (*proven 3 subgoals*) . from d (*‹Domain (f::(nat × ('a + 'b)) set) = {0::nat}›*) obtain v where v: "(0,v) ∈ f" (*goal: ‹(⋀v. (0, v) ∈ f ⟹ thesis) ⟹ thesis›*) by auto hence f: "f = {(0,v)}" using d (*‹Domain f = {0}›*) insert_iff (*‹(?a ∈ insert ?b ?A) = (?a = ?b ∨ ?a ∈ ?A)›*) mk_disjoint_insert (*‹?a ∈ ?A ⟹ ∃B. ?A = insert ?a B ∧ ?a ∉ B›*) all_not_in_conv (*‹(∀x. x ∉ ?A) = (?A = {})›*) old.prod.exhaust (*‹(⋀a b. ?y = (a, b) ⟹ ?P) ⟹ ?P›*) u[unfolded univalent_def] (*‹∀x y z. (x, y) ∈ f ∧ (x, z) ∈ f ⟶ z = y›*) Domain.intros[of _ _ f, unfolded d, THEN singletonD] (*‹(?b::nat, ?b1::'a + 'b) ∈ (f::(nat × ('a + 'b)) set) ⟹ ?b = (0::nat)›*) by (metis (no_types)) from v (*‹(0, v) ∈ f›*) r (*‹f `` {0} ⊆ vertices G›*) have v: "v ∈ vertices G" by auto with v_gr (*‹∀a b. ((S_Idt, a, b) ∈ edges G) = (a ∈ vertices G ∧ b = a)›*) have "(S_Idt, v, v) ∈ edges G" by auto hence "edge_preserving {(0, v)} {(S_Idt, 0, 0)} (edges G)" unfolding edge_preserving (*goal: ‹on_triple {(0, v)} `` {(S_Idt, 0, 0)} ⊆ edges G›*) by auto hence "graph_homomorphism (LG {(S_Idt, 0, 0)} {0}) G f" unfolding f graph_homomorphism_def (*goal: ‹vertices (LG {(S_Idt, 0, 0)} {0}) = Domain {(0, v)} ∧ graph (LG {(S_Idt, 0, 0)} {0}) ∧ graph G ∧ {(0, v)} `` vertices (LG {(S_Idt, 0, 0)} {0}) ⊆ vertices G ∧ univalent {(0, v)} ∧ edge_preserving {(0, v)} (edges (LG {(S_Idt, 0, 0)} {0})) (edges G)›*) using g (*‹graph G›*) v (*‹(v::'a + 'b) ∈ vertices (G::('a Standard_Constant, 'a + 'b) labeled_graph)›*) by (auto simp:univalent_def (*‹univalent ?R = (∀x y z. (x, y) ∈ ?R ∧ (x, z) ∈ ?R ⟶ z = y)›*)) } thus "maintained (reflexivity_rule S_Idt) G" unfolding reflexivity_rule_def maintained_def (*goal: ‹∀f. graph_homomorphism (fst (LG {} {0}, LG {(S_Idt, 0, 0)} {0})) G f ⟶ extensible (LG {} {0}, LG {(S_Idt, 0, 0)} {0}) G f›*) by auto qed lemma standard_maintains_identity_rules: assumes "standard' C G" "x∈identity_rules L" shows "maintained x G" proof (-) (*goal: ‹maintained x G›*) consider "x = reflexivity_rule S_Idt" | "x = transitive_rule S_Idt" | "x = symmetry_rule S_Idt" | "∃ l. x = congruence_rule S_Idt l" (*goal: ‹⟦(x::('a Standard_Constant, nat) labeled_graph × ('a Standard_Constant, nat) labeled_graph) = reflexivity_rule S_Idt ⟹ thesis::bool; x = transitive_rule S_Idt ⟹ thesis; x = symmetry_rule S_Idt ⟹ thesis; ∃l::'a Standard_Constant. x = congruence_rule S_Idt l ⟹ thesis⟧ ⟹ thesis›*) using assms (*‹standard' C G› ‹x ∈ identity_rules L›*) unfolding identity_rules_def Un_iff (*goal: ‹⟦x = reflexivity_rule S_Idt ⟹ thesis; x = transitive_rule S_Idt ⟹ thesis; x = symmetry_rule S_Idt ⟹ thesis; ∃l. x = congruence_rule S_Idt l ⟹ thesis⟧ ⟹ thesis›*) by blast thus "?thesis" (*goal: ‹maintained x G›*) using standard_identity_rules[OF assms ( 1 )] (*‹maintained (reflexivity_rule S_Idt) G› ‹maintained (transitive_rule S_Idt) (G::('a Standard_Constant, 'a + 'b) labeled_graph)› ‹maintained (symmetry_rule S_Idt) G› ‹maintained (congruence_rule S_Idt (?l::'a Standard_Constant)) (G::('a Standard_Constant, 'a + 'b) labeled_graph)›*) apply cases (*goals: 1. ‹⟦maintained (reflexivity_rule S_Idt) G; maintained (transitive_rule S_Idt) G; maintained (symmetry_rule S_Idt) G; ⋀l. maintained (congruence_rule S_Idt l) G; x = reflexivity_rule S_Idt⟧ ⟹ maintained x G› 2. ‹⟦maintained (reflexivity_rule S_Idt) G; maintained (transitive_rule S_Idt) G; maintained (symmetry_rule S_Idt) G; ⋀l. maintained (congruence_rule S_Idt l) G; x = transitive_rule S_Idt⟧ ⟹ maintained x G› 3. ‹⟦maintained (reflexivity_rule S_Idt) G; maintained (transitive_rule S_Idt) G; maintained (symmetry_rule S_Idt) G; ⋀l. maintained (congruence_rule S_Idt l) G; x = symmetry_rule S_Idt⟧ ⟹ maintained x G› 4. ‹⟦maintained (reflexivity_rule S_Idt) G; maintained (transitive_rule S_Idt) G; maintained (symmetry_rule S_Idt) G; ⋀l. maintained (congruence_rule S_Idt l) G; ∃l. x = congruence_rule S_Idt l⟧ ⟹ maintained x G› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . qed lemma standard_maintains_rules: assumes "standard' C G" shows "maintainedA (standard_rules C L) G" proof (standard) (*goal: ‹⋀R. R ∈ standard_rules C L ⟹ maintained R G›*) fix R assume "R ∈ standard_rules C L" (*‹(R::('a Standard_Constant, nat) labeled_graph × ('a Standard_Constant, nat) labeled_graph) ∈ standard_rules (C::'a set) (L::'a Standard_Constant set)›*) then consider "R ∈ constant_rules C" | "R ∈ identity_rules L" | "R = top_rule S_Top" | "R = nonempty_rule" (*goal: ‹⟦R ∈ constant_rules C ⟹ thesis; R ∈ identity_rules L ⟹ thesis; R = top_rule S_Top ⟹ thesis; R = nonempty_rule ⟹ thesis⟧ ⟹ thesis›*) by (auto simp:standard_rules_def (*‹standard_rules ?C ?L ≡ constant_rules ?C ∪ identity_rules ?L ∪ {top_rule S_Top, nonempty_rule}›*)) thus "maintained R G" using assms (*‹standard' C G›*) standard_maintains_constant_rules[OF assms] (*‹(?R::('a Standard_Constant, nat) labeled_graph × ('a Standard_Constant, nat) labeled_graph) ∈ constant_rules (C::'a set) ⟹ maintained ?R (G::('a Standard_Constant, 'a + 'b) labeled_graph)›*) standard_maintains_identity_rules[OF assms] (*‹?x ∈ identity_rules ?L ⟹ maintained ?x G›*) apply cases (*goals: 1. ‹⟦standard' C G; ⋀R. R ∈ constant_rules C ⟹ maintained R G; ⋀x L. x ∈ identity_rules L ⟹ maintained x G; R ∈ constant_rules C⟧ ⟹ maintained R G› 2. ‹⟦standard' C G; ⋀R. R ∈ constant_rules C ⟹ maintained R G; ⋀x L. x ∈ identity_rules L ⟹ maintained x G; R ∈ identity_rules L⟧ ⟹ maintained R G› 3. ‹⟦standard' C G; ⋀R. R ∈ constant_rules C ⟹ maintained R G; ⋀x L. x ∈ identity_rules L ⟹ maintained x G; R = top_rule S_Top⟧ ⟹ maintained R G› 4. ‹⟦standard' C G; ⋀R. R ∈ constant_rules C ⟹ maintained R G; ⋀x L. x ∈ identity_rules L ⟹ maintained x G; R = nonempty_rule⟧ ⟹ maintained R G› discuss goal 1*) apply ((auto simp:standard_def (*‹standard ?C ?b ?t ?idt ?G ≡ graph ?G ∧ vertices ?G ≠ {} ∧ ident_rel ?idt ?G ∧ getRel ?b ?G = {} ∧ getRel ?t ?G = {(x, y). x ∈ vertices ?G ∧ y ∈ vertices ?G} ∧ (∀(l, v)∈?C. getRel l ?G = {(v, v)})›*))[1]) (*discuss goal 2*) apply ((auto simp:standard_def (*‹standard (?C::(?'l × ?'v) set) (?b::?'l) (?t::?'l) (?idt::?'l) (?G::(?'l, ?'v) labeled_graph) ≡ graph ?G ∧ vertices ?G ≠ {} ∧ ident_rel ?idt ?G ∧ getRel ?b ?G = {} ∧ getRel ?t ?G = {(x::?'v, y::?'v). x ∈ vertices ?G ∧ y ∈ vertices ?G} ∧ (∀(l::?'l, v::?'v)∈?C. getRel l ?G = {(v, v)})›*))[1]) (*discuss goal 3*) apply ((auto simp:standard_def (*‹standard (?C::(?'l × ?'v) set) (?b::?'l) (?t::?'l) (?idt::?'l) (?G::(?'l, ?'v) labeled_graph) ≡ graph ?G ∧ vertices ?G ≠ {} ∧ ident_rel ?idt ?G ∧ getRel ?b ?G = {} ∧ getRel ?t ?G = {(x::?'v, y::?'v). x ∈ vertices ?G ∧ y ∈ vertices ?G} ∧ (∀(l::?'l, v::?'v)∈?C. getRel l ?G = {(v, v)})›*))[1]) (*discuss goal 4*) apply ((auto simp:standard_def (*‹standard (?C::(?'l::type × ?'v::type) set) (?b::?'l::type) (?t::?'l::type) (?idt::?'l::type) (?G::(?'l::type, ?'v::type) labeled_graph) ≡ graph ?G ∧ vertices ?G ≠ {} ∧ ident_rel ?idt ?G ∧ getRel ?b ?G = {} ∧ getRel ?t ?G = {(x::?'v::type, y::?'v::type). x ∈ vertices ?G ∧ y ∈ vertices ?G} ∧ (∀(l::?'l::type, v::?'v::type)∈?C. getRel l ?G = {(v, v)})›*))[1]) (*proven 4 subgoals*) . qed text ‹A case-split rule.› lemma standard_rules_edges: assumes "(lhs, rhs) ∈ standard_rules C L" "(l, x, y) ∈ edges rhs" shows "(l = S_Bot ⟹ thesis) ⟹ (l = S_Top ⟹ thesis) ⟹ (l = S_Idt ⟹ thesis) ⟹ (l ∈ S_Const ` C ⟹ thesis) ⟹ (l ∈ L ⟹ thesis) ⟹ thesis" using assms (*‹(lhs::('a Standard_Constant, nat) labeled_graph, rhs::('a Standard_Constant, nat) labeled_graph) ∈ standard_rules (C::'a set) (L::'a Standard_Constant set)› ‹(l, x, y) ∈ edges rhs›*) [simproc del : defined_all] (*‹TERM _›*) by (auto simp: Let_def (*‹Let ?s ?f ≡ ?f ?s›*) standard_rules_def (*‹standard_rules ?C ?L ≡ constant_rules ?C ∪ identity_rules ?L ∪ {top_rule S_Top, nonempty_rule}›*) constant_rules_def (*‹constant_rules ?C ≡ const_exists ` ?C ∪ const_exists_rev ` ?C ∪ const_prop ` ?C ∪ {const_disj c₁ c₂ |c₁ c₂. c₁ ∈ ?C ∧ c₂ ∈ ?C ∧ c₁ ≠ c₂}›*) identity_rules_def (*‹identity_rules ?L ≡ {reflexivity_rule S_Idt, transitive_rule S_Idt, symmetry_rule S_Idt} ∪ congruence_rules S_Idt ?L›*) const_exists_def (*‹const_exists ?c ≡ transl_rule (⊤ ⊑ A_Cmp (A_Cmp ⊤ (A_Lbl (S_Const ?c))) ⊤)›*) const_exists_rev_def (*‹const_exists_rev ?c ≡ transl_rule (A_Cmp (A_Cmp (A_Lbl (S_Const ?c)) ⊤) (A_Lbl (S_Const ?c)) ⊑ A_Lbl (S_Const ?c))›*) const_prop_def (*‹const_prop ?c ≡ transl_rule (A_Lbl (S_Const ?c) ⊑ 𝟭)›*) const_disj_def (*‹const_disj ?c₁ ?c₂ ≡ transl_rule (A_Cmp (A_Lbl (S_Const ?c₁)) (A_Lbl (S_Const ?c₂)) ⊑ ⊥)›*) reflexivity_rule_def (*‹reflexivity_rule ?t = (LG {} {0}, LG {(?t, 0, 0)} {0})›*) transitive_rule_def (*‹transitive_rule ?t = transl_rule (A_Cmp (A_Lbl ?t) (A_Lbl ?t) ⊑ A_Lbl ?t)›*) symmetry_rule_def (*‹symmetry_rule ?t = transl_rule (A_Cnv (A_Lbl ?t) ⊑ A_Lbl ?t)›*) congruence_rule_def (*‹congruence_rule ?t ?l = transl_rule (A_Cmp (A_Cmp (A_Lbl ?t) (A_Lbl ?l)) (A_Lbl ?t) ⊑ A_Lbl ?l)›*) top_rule_def (*‹top_rule ?t = (LG {} {0, 1}, LG {(?t, 0, 1)} {0, 1})›*) nonempty_rule_def (*‹nonempty_rule = (LG {} {}, LG {} {0})›*)) text ‹Lemma 8. This is a slightly stronger version of Lemma 8: we reason about maintained rather than holds, and the quantification for maintained happens within the existential quantifier, rather than outside. Due to the type system of Isabelle, we construct the concrete type @{term std_graph} for G. This in contrast to arguing that 'there exists a type large enough', as in the paper.› lemma maintained_standard_noconstants: assumes mnt:"maintainedA (standard_rules C L) G'" and gr:"graph (G'::('V Standard_Constant, 'V') labeled_graph)" "fst ` edges G' ⊆ L" (* Graph on labels L *) and cf:"getRel S_Bot G' = {}" (* Conflict free *) shows "∃ f g (G::('V, 'V') std_graph). G = map_graph_fn G (f o g) ∧ G = map_graph_fn G' f ∧ subgraph (map_graph_fn G g) G' ∧ standard' C G ∧ (∀ r. maintained r G' ⟶ maintained r G) ∧ (∀ x y e. x ∈ vertices G' ⟶ y ∈ vertices G' ⟶ (g (f x), g (f y)) ∈ :map_graph_fn G g:⟦e⟧ ⟶ (x,y) ∈ :G':⟦e⟧)" proof (-) (*goal: ‹∃f g G. G = map_graph_fn G (f ∘ g) ∧ G = map_graph_fn G' f ∧ subgraph (map_graph_fn G g) G' ∧ standard' C G ∧ (∀r. maintained r G' ⟶ maintained r G) ∧ (∀x y e. x ∈ vertices G' ⟶ y ∈ vertices G' ⟶ (g (f x), g (f y)) ∈ :map_graph_fn G g:⟦e⟧ ⟶ (x, y) ∈ :G':⟦e⟧)›*) note mnt = mnt[unfolded standard_rules_def] (*‹maintainedA (constant_rules C ∪ identity_rules L ∪ {top_rule S_Top, nonempty_rule}) G'›*) from mnt (*‹maintainedA (constant_rules C ∪ identity_rules L ∪ {top_rule S_Top, nonempty_rule}) G'›*) have "maintainedA (identity_rules L) G'" by auto from identity_rules[OF gr ( 1 ) this gr ( 2 )] (*‹∃f. f ∘ f = f ∧ ident_rel S_Idt (map_graph_fn G' f) ∧ subgraph (map_graph_fn G' f) G' ∧ (∀l x y. ((l, x, y) ∈ edges G') = ((l, f x, f y) ∈ edges G'))›*) obtain h where h: "h ∘ h = h" "ident_rel S_Idt (map_graph_fn G' h)" "subgraph (map_graph_fn G' h) G'" "((l, x, y) ∈ edges G') = ((l, h x, h y) ∈ edges G')" for l and x and y (*goal: ‹(⋀h::'V'::type ⇒ 'V'::type. ⟦h ∘ h = h; ident_rel S_Idt (map_graph_fn (G'::('V::type Standard_Constant, 'V'::type) labeled_graph) h); subgraph (map_graph_fn G' h) G'; ⋀(l::'V::type Standard_Constant) (x::'V'::type) y::'V'::type. ((l, x, y) ∈ edges G') = ((l, h x, h y) ∈ edges G')⟧ ⟹ thesis::bool) ⟹ thesis›*) by blast have mg: "⋀ r. maintained r G' ⟹ maintained r (map_graph_fn G' h)" using idemp_embedding_maintained_preserved[OF h ( 3 )] (*‹⟦⋀x. x ∈ vertices G' ⟹ (h ∘ h) x = h x; maintained ?r G'⟧ ⟹ maintained ?r (map_graph_fn G' h)›*) h(1) (*‹(h::'V' ⇒ 'V') ∘ h = h›*) by auto from mnt (*‹maintainedA (constant_rules C ∪ identity_rules L ∪ {top_rule S_Top, nonempty_rule}) G'›*) have tr: "maintained (top_rule S_Top) G'" and ne: "maintained nonempty_rule G'" apply - (*goals: 1. ‹maintainedA (constant_rules (C::'V set) ∪ identity_rules (L::'V Standard_Constant set) ∪ {top_rule S_Top, nonempty_rule}) (G'::('V Standard_Constant, 'V') labeled_graph) ⟹ maintained (top_rule S_Top) G'› 2. ‹maintainedA (constant_rules (C::'V set) ∪ identity_rules (L::'V Standard_Constant set) ∪ {top_rule S_Top, nonempty_rule}) (G'::('V Standard_Constant, 'V') labeled_graph) ⟹ maintained nonempty_rule G'› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . from nonempty_rule[OF gr ( 1 )] (*‹maintained nonempty_rule G' = (vertices G' ≠ {})›*) ne (*‹maintained nonempty_rule G'›*) obtain x where x: "x ∈ vertices G'" (*goal: ‹(⋀x::'V'. x ∈ vertices (G'::('V Standard_Constant, 'V') labeled_graph) ⟹ thesis::bool) ⟹ thesis›*) by blast from tr[unfolded top_rule [ OF gr ( 1 ) ]] (*‹vertices G' × vertices G' = getRel S_Top G'›*) x (*‹x ∈ vertices G'›*) have top_nonempty: "(x, x) ∈ getRel S_Top G'" by auto have "⋀ c. c ∈ C ⟹ ∃v. (v, v) ∈ getRel (S_Const c) (map_graph_fn G' h)" proof (goal_cases) (*goal: ‹⋀c. c ∈ C ⟹ ∃v. (v, v) ∈ getRel (S_Const c) (map_graph_fn G' h)›*) case (1 c) (*‹c ∈ C›*) with mnt (*‹maintainedA (constant_rules C ∪ identity_rules L ∪ {top_rule S_Top, nonempty_rule}) G'›*) have cr5: "maintained (const_exists c) G'" and cr7: "maintained (const_prop c) G'" unfolding constant_rules_def (*goals: 1. ‹maintained (const_exists c) G'› 2. ‹maintained (const_prop c) G'›*) apply - (*goals: 1. ‹⟦maintainedA (const_exists ` C ∪ const_exists_rev ` C ∪ const_prop ` C ∪ {const_disj c₁ c₂ |c₁ c₂. c₁ ∈ C ∧ c₂ ∈ C ∧ c₁ ≠ c₂} ∪ identity_rules L ∪ {top_rule S_Top, nonempty_rule}) G'; c ∈ C⟧ ⟹ maintained (const_exists c) G'› 2. ‹⟦maintainedA (const_exists ` C ∪ const_exists_rev ` C ∪ const_prop ` C ∪ {const_disj c₁ c₂ |c₁ c₂. c₁ ∈ C ∧ c₂ ∈ C ∧ c₁ ≠ c₂} ∪ identity_rules L ∪ {top_rule S_Top, nonempty_rule}) G'; c ∈ C⟧ ⟹ maintained (const_prop c) G'› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) . from top_nonempty (*‹(x, x) ∈ getRel S_Top G'›*) cr5[unfolded maintained_holds_subset_iff [ OF gr ( 1 ) ] const_exists_def] (*‹:G':⟦⊤⟧ ⊆ :G':⟦A_Cmp (A_Cmp ⊤ (A_Lbl (S_Const c))) ⊤⟧›*) obtain y and z where yz: "(y,z) ∈ getRel (S_Const c) G'" (*goal: ‹(⋀(y::'V'::type) z::'V'::type. (y, z) ∈ getRel (S_Const (c::'V::type)) (G'::('V::type Standard_Constant, 'V'::type) labeled_graph) ⟹ thesis::bool) ⟹ thesis›*) by auto from this (*‹(y, z) ∈ getRel (S_Const c) G'›*) gr(1) (*‹graph G'›*) have yzv: "y ∈ vertices G'" "z ∈ vertices G'" apply - (*goals: 1. ‹⟦(y, z) ∈ getRel (S_Const c) G'; graph G'⟧ ⟹ y ∈ vertices G'› 2. ‹⟦(y, z) ∈ getRel (S_Const c) G'; graph G'⟧ ⟹ z ∈ vertices G'› discuss goal 1*) apply ((auto simp:getRel_def (*‹getRel ?l ?G = {(x, y). (?l, x, y) ∈ edges ?G}›*))[1]) (*discuss goal 2*) apply ((auto simp:getRel_def (*‹getRel ?l ?G = {(x, y). (?l, x, y) ∈ edges ?G}›*))[1]) (*proven 2 subgoals*) . from getRel_hom[OF yz yzv] (*‹((?f::'V' ⇒ ?'c) (y::'V'), ?f (z::'V')) ∈ getRel (S_Const (c::'V)) (map_graph_fn (G'::('V Standard_Constant, 'V') labeled_graph) ?f)›*) have hi: "(h y,h z) ∈ getRel (S_Const c) (map_graph_fn G' h)" . with h(2) (*‹ident_rel S_Idt (map_graph_fn G' h)›*) cr7[THEN mg, unfolded maintained_holds_subset_iff [ OF map_graph_fn_graphI ] const_prop_def] (*‹:map_graph_fn G' h:⟦A_Lbl (S_Const c)⟧ ⊆ :map_graph_fn G' h:⟦𝟭⟧›*) have "h y = h z" by force thus "∃ v. (v,v) ∈ getRel (S_Const c) (map_graph_fn G' h)" using hi (*‹(h y, h z) ∈ getRel (S_Const c) (map_graph_fn G' h)›*) by auto qed hence "∀ c. ∃ v. c ∈ C ⟶ (v, v) ∈ getRel (S_Const c) (map_graph_fn G' h)" by blast from choice[OF this] (*‹∃f. ∀x. x ∈ C ⟶ (f x, f x) ∈ getRel (S_Const x) (map_graph_fn G' h)›*) obtain m where m: "⋀ x. x ∈ C ⟹ (m x, m x) ∈ getRel (S_Const x) (map_graph_fn G' h)" (*goal: ‹(⋀m. (⋀x. x ∈ C ⟹ (m x, m x) ∈ getRel (S_Const x) (map_graph_fn G' h)) ⟹ thesis) ⟹ thesis›*) by blast let ?m' = "λ x. if x ∈ m ` C then Inl (the_inv_into C m x) else Inr x" define f where "f ≡ ?m' o h" have "⋀ x y. x ∈ C ⟹ y ∈ C ⟹ m x = m y ⟹ x = y" proof (goal_cases) (*goal: ‹⋀x y. ⟦x ∈ C; y ∈ C; m x = m y⟧ ⟹ x = y›*) case (1 x y) (*‹(x::'V) ∈ (C::'V set)› ‹y ∈ C› ‹m x = m y›*) with m (*‹?x1 ∈ C ⟹ (m ?x1, m ?x1) ∈ getRel (S_Const ?x1) (map_graph_fn G' h)›*) have "(m x,m x) ∈ getRel (S_Const y) (map_graph_fn G' h)" "(m x,m x) ∈ getRel (S_Const x) (map_graph_fn G' h)" apply - (*goals: 1. ‹⟦⋀x. x ∈ C ⟹ (m x, m x) ∈ getRel (S_Const x) (map_graph_fn G' h); x ∈ C; y ∈ C; m x = m y⟧ ⟹ (m x, m x) ∈ getRel (S_Const y) (map_graph_fn G' h)› 2. ‹⟦⋀x. x ∈ C ⟹ (m x, m x) ∈ getRel (S_Const x) (map_graph_fn G' h); x ∈ C; y ∈ C; m x = m y⟧ ⟹ (m x, m x) ∈ getRel (S_Const x) (map_graph_fn G' h)› discuss goal 1*) apply metis (*discuss goal 2*) apply metis (*proven 2 subgoals*) . hence mx: "(m x,m x) ∈ getRel (S_Const y) G'" "(m x,m x) ∈ getRel (S_Const x) G'" using h(3) (*‹subgraph (map_graph_fn G' h) G'›*) apply - (*goals: 1. ‹⟦(m x, m x) ∈ getRel (S_Const y) (map_graph_fn G' h); (m x, m x) ∈ getRel (S_Const x) (map_graph_fn G' h); subgraph (map_graph_fn G' h) G'⟧ ⟹ (m x, m x) ∈ getRel (S_Const y) G'› 2. ‹⟦(m x, m x) ∈ getRel (S_Const y) (map_graph_fn G' h); (m x, m x) ∈ getRel (S_Const x) (map_graph_fn G' h); subgraph (map_graph_fn G' h) G'⟧ ⟹ (m x, m x) ∈ getRel (S_Const x) G'› discuss goal 1*) apply force (*discuss goal 2*) apply force (*proven 2 subgoals*) . from "1"(1,2) (*‹x ∈ C› ‹y ∈ C›*) mnt (*‹maintainedA (constant_rules C ∪ identity_rules L ∪ {top_rule S_Top, nonempty_rule}) G'›*) have cr8: "x ≠ y ⟹ maintained (const_disj x y) G'" unfolding constant_rules_def (*goal: ‹x ≠ y ⟹ maintained (const_disj x y) G'›*) by blast from cr8[unfolded maintained_holds_subset_iff [ OF gr ( 1 ) ] const_disj_def] (*‹x ≠ y ⟹ :G':⟦A_Cmp (A_Lbl (S_Const x)) (A_Lbl (S_Const y))⟧ ⊆ :G':⟦⊥⟧›*) mx (*‹(m x, m x) ∈ getRel (S_Const y) G'› ‹(m x, m x) ∈ getRel (S_Const x) G'›*) have "x≠y⟹(m x,m x) ∈ :G':⟦⊥⟧" by auto thus "x = y" using cf (*‹getRel S_Bot (G'::('V Standard_Constant, 'V') labeled_graph) = {}›*) by auto qed hence "univalent (converse (BNF_Def.Gr C m))" unfolding univalent_def (*goal: ‹∀x y z. (x, y) ∈ (BNF_Def.Gr C m)¯ ∧ (x, z) ∈ (BNF_Def.Gr C m)¯ ⟶ z = y›*) by auto hence inj_m: "inj_on m C" unfolding inj_on_def (*goal: ‹∀x∈C. ∀y∈C. m x = m y ⟶ x = y›*) by auto from inj_on_the_inv_into[OF inj_m] (*‹inj_on (the_inv_into C m) (m ` C)›*) have inj_m': "inj ?m'" unfolding inj_on_def (*goal: ‹∀x∈UNIV. ∀y∈UNIV. (if x ∈ m ` C then Inl (the_inv_into C m x) else Inr x) = (if y ∈ m ` C then Inl (the_inv_into C m y) else Inr y) ⟶ x = y›*) by auto define G where "G = map_graph_fn G' f" hence G: "graph G" "f x ∈ vertices G" "getRel S_Bot G = {}" using x (*‹(x::'V'::type) ∈ vertices (G'::('V::type Standard_Constant, 'V'::type) labeled_graph)›*) cf (*‹getRel S_Bot G' = {}›*) unfolding getRel_def (*goals: 1. ‹graph G› 2. ‹f x ∈ vertices G› 3. ‹{(x, y). (S_Bot, x, y) ∈ edges G} = {}›*) apply - (*goals: 1. ‹⟦G = map_graph_fn G' f; x ∈ vertices G'; {(x, y). (S_Bot, x, y) ∈ edges G'} = {}⟧ ⟹ graph G› 2. ‹⟦G = map_graph_fn G' f; x ∈ vertices G'; {(x, y). (S_Bot, x, y) ∈ edges G'} = {}⟧ ⟹ f x ∈ vertices G› 3. ‹⟦G = map_graph_fn G' f; x ∈ vertices G'; {(x, y). (S_Bot, x, y) ∈ edges G'} = {}⟧ ⟹ {(x, y). (S_Bot, x, y) ∈ edges G} = {}› discuss goal 1*) apply force (*discuss goal 2*) apply force (*discuss goal 3*) apply force (*proven 3 subgoals*) . from comp_inj_on[OF inj_on_the_inv_into [ OF inj_m ] inj_Inl, unfolded o_def] (*‹inj_on (λx. Inl (the_inv_into C m x)) (m ` C)›*) inj_Inr (*‹inj_on Inr ?A›*) have inj_m': "inj_on ?m' (vertices G')" unfolding inj_on_def (*goal: ‹∀x∈vertices G'. ∀y∈vertices G'. (if x ∈ m ` C then Inl (the_inv_into C m x) else Inr x) = (if y ∈ m ` C then Inl (the_inv_into C m y) else Inr y) ⟶ x = y›*) by auto define g where "g = the_inv_into (vertices G') ?m'" have gf_h: "⋀ x. x ∈ vertices G' ⟹ (g o f) x = h x" unfolding g_def f_def o_def (*goal: ‹⋀x. x ∈ vertices G' ⟹ the_inv_into (vertices G') (λx. if x ∈ m ` C then Inl (the_inv_into C m x) else Inr x) (if h x ∈ m ` C then Inl (the_inv_into C m (h x)) else Inr (h x)) = h x›*) apply (rule the_inv_into_f_f[OF inj_m'] (*‹?x ∈ vertices G' ⟹ the_inv_into (vertices G') (λx. if x ∈ m ` C then Inl (the_inv_into C m x) else Inr x) (if ?x ∈ m ` C then Inl (the_inv_into C m ?x) else Inr ?x) = ?x›*)) (*goal: ‹⋀x. x ∈ vertices G' ⟹ the_inv_into (vertices G') (λx. if x ∈ m ` C then Inl (the_inv_into C m x) else Inr x) (if h x ∈ m ` C then Inl (the_inv_into C m (h x)) else Inr (h x)) = h x›*) using h (*‹h ∘ h = h› ‹ident_rel S_Idt (map_graph_fn G' h)› ‹subgraph (map_graph_fn G' h) G'› ‹((?l, ?x, ?y) ∈ edges G') = ((?l, h ?x, h ?y) ∈ edges G')›*) unfolding subgraph_def graph_union_iff (*goal: ‹⋀x. x ∈ vertices G' ⟹ h x ∈ vertices G'›*) by auto have mg_eq: "map_graph_fn G' (g ∘ f) = map_graph_fn G' h" by (rule map_graph_fn_eqI[OF gf_h] (*‹(⋀x::?'a. x ∈ vertices (?G::(?'b, ?'a) labeled_graph) ⟹ (?x2::?'a ⇒ 'V') x ∈ vertices (G'::('V Standard_Constant, 'V') labeled_graph)) ⟹ map_graph_fn ?G (λx::?'a. ((g::'V + 'V' ⇒ 'V') ∘ (f::'V' ⇒ 'V + 'V')) (?x2 x)) = map_graph_fn ?G (λx::?'a. (h::'V' ⇒ 'V') (?x2 x))›*)) have "⋀ x. x ∈ vertices G' ⟹ h x ∈ vertices G'" using h(3) (*‹subgraph (map_graph_fn G' h) G'›*) unfolding subgraph_def graph_union_iff (*goal: ‹⋀x. x ∈ vertices G' ⟹ h x ∈ vertices G'›*) apply (cases G') (*goal: ‹⋀x. x ∈ vertices G' ⟹ h x ∈ vertices G'›*) by auto hence gf_id: "⋀ x. x ∈ vertices G' ⟹ (g o f) (h x) = (h x)" using h(1) (*‹h ∘ h = h›*) gf_h (*‹?x1 ∈ vertices G' ⟹ (g ∘ f) ?x1 = h ?x1›*) unfolding o_def (*goal: ‹⋀x::'V'::type. x ∈ vertices (G'::('V::type Standard_Constant, 'V'::type) labeled_graph) ⟹ (g::'V::type + 'V'::type ⇒ 'V'::type) ((f::'V'::type ⇒ 'V::type + 'V'::type) ((h::'V'::type ⇒ 'V'::type) x)) = h x›*) by metis { fix x assume "x ∈ vertices G" (*‹(x::'V + 'V') ∈ vertices (G::('V Standard_Constant, 'V + 'V') labeled_graph)›*) then obtain y where y: "f y = x" "y ∈ vertices G'" (*goal: ‹(⋀y. ⟦f y = x; y ∈ vertices G'⟧ ⟹ thesis) ⟹ thesis›*) unfolding G_def (*goal: ‹(⋀y. ⟦f y = x; y ∈ vertices G'⟧ ⟹ thesis) ⟹ thesis›*) by auto from gf_h[OF y ( 2 )] (*‹(g ∘ f) y = h y›*) have "(f o g) (f y) = f (h y)" unfolding o_def (*goal: ‹f (g (f y)) = f (h y)›*) by auto also (*calculation: ‹(f ∘ g) (f y) = f (h y)›*) have "… = f y" using h(1) (*‹h ∘ h = h›*) unfolding f_def o_def (*goal: ‹(if (h::'V' ⇒ 'V') (h (y::'V')) ∈ (m::'V ⇒ 'V') ` (C::'V set) then Inl (the_inv_into C m (h (h y))) else Inr (h (h y))) = (if h y ∈ m ` C then Inl (the_inv_into C m (h y)) else Inr (h y))›*) by metis finally (*calculation: ‹(f ∘ g) (f y) = f y›*) have "(f o g) x = x" unfolding y (*goal: ‹(f ∘ g) x = x›*) . } note fg_id = this (*‹?xa3 ∈ vertices G ⟹ (f ∘ g) ?xa3 = ?xa3›*) have fg_inv: "map_graph_fn G (f o g) = G" using h(1) (*‹h ∘ h = h›*) G_def (*‹(G::('V Standard_Constant, 'V + 'V') labeled_graph) = map_graph_fn (G'::('V Standard_Constant, 'V') labeled_graph) (f::'V' ⇒ 'V + 'V')›*) f_def (*‹f ≡ (λx. if x ∈ m ` C then Inl (the_inv_into C m x) else Inr x) ∘ h›*) mg_eq (*‹map_graph_fn G' (g ∘ f) = map_graph_fn G' h›*) map_graph_fn_comp (*‹map_graph_fn (?G::(?'a, ?'c) labeled_graph) ((?f::?'d ⇒ ?'b) ∘ (?g::?'c ⇒ ?'d)) = map_graph_fn (map_graph_fn ?G ?g) ?f›*) by (metis (no_types, lifting)) have ir: "ident_rel S_Idt G" unfolding set_eq_iff (*goal: ‹∀x::('V::type + 'V'::type) × ('V::type + 'V'::type). (x ∈ getRel S_Idt (G::('V::type Standard_Constant, 'V::type + 'V'::type) labeled_graph)) = (x ∈ (λx::'V::type + 'V'::type. (x, x)) ` vertices G)›*) proof (standard, standard, goal_cases) (*goals: 1. ‹⋀x. x ∈ getRel S_Idt G ⟹ x ∈ (λx. (x, x)) ` vertices G› 2. ‹⋀x. x ∈ (λx. (x, x)) ` vertices G ⟹ x ∈ getRel S_Idt G›*) case (1 x) (*‹x ∈ getRel S_Idt G›*) from this[unfolded G_def] (*‹(x::('V + 'V') × ('V + 'V')) ∈ getRel S_Idt (map_graph_fn (G'::('V Standard_Constant, 'V') labeled_graph) (f::'V' ⇒ 'V + 'V'))›*) obtain v1 and v2 where v: "(v1,v2) ∈ getRel S_Idt G'" "x = (f v1,f v2)" (*goal: ‹(⋀v1 v2. ⟦(v1, v2) ∈ getRel S_Idt G'; x = (f v1, f v2)⟧ ⟹ thesis) ⟹ thesis›*) unfolding getRel_def map_graph_def on_triple_def (*goal: ‹(⋀v1 v2. ⟦(v1, v2) ∈ {(x, y). (S_Idt, x, y) ∈ edges G'}; x = (f v1, f v2)⟧ ⟹ thesis) ⟹ thesis›*) by auto hence vv: "v1 ∈ vertices G'" "v2 ∈ vertices G'" using gr (*‹graph G'› ‹fst ` edges G' ⊆ L›*) unfolding getRel_def (*goals: 1. ‹v1 ∈ vertices G'› 2. ‹v2 ∈ vertices G'›*) apply - (*goals: 1. ‹⟦(v1, v2) ∈ {(x, y). (S_Idt, x, y) ∈ edges G'}; x = (f v1, f v2); graph G'; fst ` edges G' ⊆ L⟧ ⟹ v1 ∈ vertices G'› 2. ‹⟦(v1, v2) ∈ {(x, y). (S_Idt, x, y) ∈ edges G'}; x = (f v1, f v2); graph G'; fst ` edges G' ⊆ L⟧ ⟹ v2 ∈ vertices G'› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . with h(2) (*‹ident_rel S_Idt (map_graph_fn G' h)›*) v(1) (*‹(v1, v2) ∈ getRel S_Idt G'›*) have "h v1 = h v2" unfolding image_def (*goal: ‹h v1 = h v2›*) by blast hence x: "x = (f v1,f v1)" unfolding f_def v (*goal: ‹(((λx. if x ∈ m ` C then Inl (the_inv_into C m x) else Inr x) ∘ h) v1, ((λx. if x ∈ m ` C then Inl (the_inv_into C m x) else Inr x) ∘ h) v2) = (((λx. if x ∈ m ` C then Inl (the_inv_into C m x) else Inr x) ∘ h) v1, ((λx. if x ∈ m ` C then Inl (the_inv_into C m x) else Inr x) ∘ h) v1)›*) by auto from vv(1) (*‹v1 ∈ vertices G'›*) show "?case" (*goal: ‹x ∈ (λx. (x, x)) ` vertices G›*) unfolding x G_def (*goal: ‹(f v1, f v1) ∈ (λx. (x, x)) ` vertices (map_graph_fn G' f)›*) by auto next (*goal: ‹⋀x. x ∈ (λx. (x, x)) ` vertices G ⟹ x ∈ getRel S_Idt G›*) case (2 x) (*‹x ∈ (λx. (x, x)) ` vertices G›*) hence x: "fst x = snd x" "fst x ∈ vertices G" apply - (*goals: 1. ‹(x::('V + 'V') × ('V + 'V')) ∈ (λx::'V + 'V'. (x, x)) ` vertices (G::('V Standard_Constant, 'V + 'V') labeled_graph) ⟹ fst x = snd x› 2. ‹(x::('V + 'V') × ('V + 'V')) ∈ (λx::'V + 'V'. (x, x)) ` vertices (G::('V Standard_Constant, 'V + 'V') labeled_graph) ⟹ fst x ∈ vertices G› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . hence "(fst x) ∈ f ` vertices G'" unfolding G_def o_def (*goal: ‹fst x ∈ f ` vertices G'›*) by auto then obtain v where v: "v ∈ vertices G'" "f v = fst x" (*goal: ‹(⋀v. ⟦v ∈ vertices G'; f v = fst x⟧ ⟹ thesis) ⟹ thesis›*) by auto hence hv: "h v ∈ vertices (map_graph_fn G' h)" by simp hence "(h v,h v) ∈ getRel S_Idt (map_graph_fn G' h)" unfolding h(2) (*goal: ‹((h::'V' ⇒ 'V') (v::'V'), h v) ∈ (λx::'V'. (x, x)) ` vertices (map_graph_fn (G'::('V Standard_Constant, 'V') labeled_graph) h)›*) by auto from getRel_hom[OF this hv hv] (*‹(?f (h v), ?f (h v)) ∈ getRel S_Idt (map_graph_fn (map_graph_fn G' h) ?f)›*) have "(?m' (h v),?m' (h v)) ∈ getRel S_Idt (map_graph_fn G' (?m' o h))" unfolding map_graph_fn_comp (*goal: ‹(if h v ∈ m ` C then Inl (the_inv_into C m (h v)) else Inr (h v), if h v ∈ m ` C then Inl (the_inv_into C m (h v)) else Inr (h v)) ∈ getRel S_Idt (map_graph_fn (map_graph_fn G' h) (λx. if x ∈ m ` C then Inl (the_inv_into C m x) else Inr x))›*) by fast hence "(f v,f v) ∈ getRel S_Idt (map_graph_fn G' f)" unfolding f_def (*goal: ‹(((λx. if x ∈ m ` C then Inl (the_inv_into C m x) else Inr x) ∘ h) v, ((λx. if x ∈ m ` C then Inl (the_inv_into C m x) else Inr x) ∘ h) v) ∈ getRel S_Idt (map_graph_fn G' ((λx. if x ∈ m ` C then Inl (the_inv_into C m x) else Inr x) ∘ h))›*) by auto hence "(fst x,snd x) ∈ getRel S_Idt G" unfolding x v G_def (*goal: ‹(snd x, snd x) ∈ getRel S_Idt (map_graph_fn G' f)›*) by auto thus "?case" (*goal: ‹x ∈ getRel S_Idt G›*) unfolding G_def (*goal: ‹x ∈ getRel S_Idt (map_graph_fn G' f)›*) by auto qed from tr[unfolded top_rule [ OF gr ( 1 ) ]] (*‹vertices G' × vertices G' = getRel S_Top G'›*) have tr0: "getRel S_Top (map_graph_fn G' h) = {(x,y). x ∈ vertices (map_graph_fn G' h) ∧ y ∈ vertices (map_graph_fn G' h)}" and tr: "getRel S_Top G = {(x, y). x ∈ vertices G ∧ y ∈ vertices G}" unfolding G_def getRel_def on_triple_def map_graph_def (*goals: 1. ‹{(x, y). (S_Top, x, y) ∈ edges (LG ({((l, s, t), l', s', t'). l = l' ∧ (s, s') ∈ on_graph G' h ∧ (t, t') ∈ on_graph G' h} `` edges G') (on_graph G' h `` vertices G'))} = {(x, y). x ∈ vertices (LG ({((l, s, t), l', s', t'). l = l' ∧ (s, s') ∈ on_graph G' h ∧ (t, t') ∈ on_graph G' h} `` edges G') (on_graph G' h `` vertices G')) ∧ y ∈ vertices (LG ({((l, s, t), l', s', t'). l = l' ∧ (s, s') ∈ on_graph G' h ∧ (t, t') ∈ on_graph G' h} `` edges G') (on_graph G' h `` vertices G'))}› 2. ‹{(x, y). (S_Top, x, y) ∈ edges (LG ({((l, s, t), l', s', t'). l = l' ∧ (s, s') ∈ on_graph G' f ∧ (t, t') ∈ on_graph G' f} `` edges G') (on_graph G' f `` vertices G'))} = {(x, y). x ∈ vertices (LG ({((l, s, t), l', s', t'). l = l' ∧ (s, s') ∈ on_graph G' f ∧ (t, t') ∈ on_graph G' f} `` edges G') (on_graph G' f `` vertices G')) ∧ y ∈ vertices (LG ({((l, s, t), l', s', t'). l = l' ∧ (s, s') ∈ on_graph G' f ∧ (t, t') ∈ on_graph G' f} `` edges G') (on_graph G' f `` vertices G'))}›*) apply - (*goals: 1. ‹vertices G' × vertices G' = {(x, y). (S_Top, x, y) ∈ edges G'} ⟹ {(x, y). (S_Top, x, y) ∈ edges (LG ({((l, s, t), l', s', t'). l = l' ∧ (s, s') ∈ on_graph G' h ∧ (t, t') ∈ on_graph G' h} `` edges G') (on_graph G' h `` vertices G'))} = {(x, y). x ∈ vertices (LG ({((l, s, t), l', s', t'). l = l' ∧ (s, s') ∈ on_graph G' h ∧ (t, t') ∈ on_graph G' h} `` edges G') (on_graph G' h `` vertices G')) ∧ y ∈ vertices (LG ({((l, s, t), l', s', t'). l = l' ∧ (s, s') ∈ on_graph G' h ∧ (t, t') ∈ on_graph G' h} `` edges G') (on_graph G' h `` vertices G'))}› 2. ‹vertices G' × vertices G' = {(x, y). (S_Top, x, y) ∈ edges G'} ⟹ {(x, y). (S_Top, x, y) ∈ edges (LG ({((l, s, t), l', s', t'). l = l' ∧ (s, s') ∈ on_graph G' f ∧ (t, t') ∈ on_graph G' f} `` edges G') (on_graph G' f `` vertices G'))} = {(x, y). x ∈ vertices (LG ({((l, s, t), l', s', t'). l = l' ∧ (s, s') ∈ on_graph G' f ∧ (t, t') ∈ on_graph G' f} `` edges G') (on_graph G' f `` vertices G')) ∧ y ∈ vertices (LG ({((l, s, t), l', s', t'). l = l' ∧ (s, s') ∈ on_graph G' f ∧ (t, t') ∈ on_graph G' f} `` edges G') (on_graph G' f `` vertices G'))}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have m: "⋀ x. x ∈ C ⟹ {(m x, m x)} = getRel (S_Const x) (map_graph_fn G' h)" proof (standard) (*goals: 1. ‹⋀x. x ∈ C ⟹ {(m x, m x)} ⊆ getRel (S_Const x) (map_graph_fn G' h)› 2. ‹⋀x. x ∈ C ⟹ getRel (S_Const x) (map_graph_fn G' h) ⊆ {(m x, m x)}›*) fix x assume x: "x ∈ C" (*‹(x::'V) ∈ (C::'V set)›*) { fix y and z assume a: "(y,z) ∈ getRel (S_Const x) (map_graph_fn G' h)" (*‹(y::'V', z::'V') ∈ getRel (S_Const (x::'V)) (map_graph_fn (G'::('V Standard_Constant, 'V') labeled_graph) (h::'V' ⇒ 'V'))›*) let ?t = "getRel S_Top (map_graph_fn G' h)" let ?r = "getRel (S_Const x) (map_graph_fn G' h)" have mx: "(m x,m x) ∈ getRel (S_Const x) (map_graph_fn G' h)" using m (*‹?x1 ∈ C ⟹ (m ?x1, m ?x1) ∈ getRel (S_Const ?x1) (map_graph_fn G' h)›*) x (*‹x ∈ C›*) by auto with a (*‹(y::'V', z::'V') ∈ getRel (S_Const (x::'V)) (map_graph_fn (G'::('V Standard_Constant, 'V') labeled_graph) (h::'V' ⇒ 'V'))›*) have v: "y ∈ vertices (map_graph_fn G' h)" "z ∈ vertices (map_graph_fn G' h)" "m x ∈ vertices (map_graph_fn G' h)" unfolding getRel_def (*goals: 1. ‹y ∈ vertices (map_graph_fn G' h)› 2. ‹z ∈ vertices (map_graph_fn G' h)› 3. ‹m x ∈ vertices (map_graph_fn G' h)›*) apply - (*goals: 1. ‹⟦(y::'V', z::'V') ∈ {(x::'V', y::'V'). (S_Const (x::'V), x, y) ∈ edges (map_graph_fn (G'::('V Standard_Constant, 'V') labeled_graph) (h::'V' ⇒ 'V'))}; ((m::'V ⇒ 'V') x, m x) ∈ {(x::'V', y::'V'). (S_Const x, x, y) ∈ edges (map_graph_fn G' h)}⟧ ⟹ y ∈ vertices (map_graph_fn G' h)› 2. ‹⟦(y::'V', z::'V') ∈ {(x::'V', y::'V'). (S_Const (x::'V), x, y) ∈ edges (map_graph_fn (G'::('V Standard_Constant, 'V') labeled_graph) (h::'V' ⇒ 'V'))}; ((m::'V ⇒ 'V') x, m x) ∈ {(x::'V', y::'V'). (S_Const x, x, y) ∈ edges (map_graph_fn G' h)}⟧ ⟹ z ∈ vertices (map_graph_fn G' h)› 3. ‹⟦(y::'V', z::'V') ∈ {(x::'V', y::'V'). (S_Const (x::'V), x, y) ∈ edges (map_graph_fn (G'::('V Standard_Constant, 'V') labeled_graph) (h::'V' ⇒ 'V'))}; ((m::'V ⇒ 'V') x, m x) ∈ {(x::'V', y::'V'). (S_Const x, x, y) ∈ edges (map_graph_fn G' h)}⟧ ⟹ m x ∈ vertices (map_graph_fn G' h)› discuss goal 1*) apply force (*discuss goal 2*) apply force (*discuss goal 3*) apply force (*proven 3 subgoals*) . with tr0 (*‹getRel S_Top (map_graph_fn (G'::('V Standard_Constant, 'V') labeled_graph) (h::'V' ⇒ 'V')) = {(x::'V', y::'V'). x ∈ vertices (map_graph_fn G' h) ∧ y ∈ vertices (map_graph_fn G' h)}›*) have "(m x,y) ∈ ?t" "(z,m x) ∈ ?t" apply - (*goals: 1. ‹⟦getRel S_Top (map_graph_fn G' h) = {(x, y). x ∈ vertices (map_graph_fn G' h) ∧ y ∈ vertices (map_graph_fn G' h)}; y ∈ vertices (map_graph_fn G' h); z ∈ vertices (map_graph_fn G' h); m x ∈ vertices (map_graph_fn G' h)⟧ ⟹ (m x, y) ∈ getRel S_Top (map_graph_fn G' h)› 2. ‹⟦getRel S_Top (map_graph_fn G' h) = {(x, y). x ∈ vertices (map_graph_fn G' h) ∧ y ∈ vertices (map_graph_fn G' h)}; y ∈ vertices (map_graph_fn G' h); z ∈ vertices (map_graph_fn G' h); m x ∈ vertices (map_graph_fn G' h)⟧ ⟹ (z, m x) ∈ getRel S_Top (map_graph_fn G' h)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . with a (*‹(y, z) ∈ getRel (S_Const x) (map_graph_fn G' h)›*) mx (*‹(m x, m x) ∈ getRel (S_Const x) (map_graph_fn G' h)›*) have lhs: "(m x,z) ∈ ?r O ?t O ?r" "(y,m x) ∈ ?r O ?t O ?r" apply - (*goals: 1. ‹⟦(y, z) ∈ getRel (S_Const x) (map_graph_fn G' h); (m x, m x) ∈ getRel (S_Const x) (map_graph_fn G' h); (m x, y) ∈ getRel S_Top (map_graph_fn G' h); (z, m x) ∈ getRel S_Top (map_graph_fn G' h)⟧ ⟹ (m x, z) ∈ getRel (S_Const x) (map_graph_fn G' h) O getRel S_Top (map_graph_fn G' h) O getRel (S_Const x) (map_graph_fn G' h)› 2. ‹⟦(y, z) ∈ getRel (S_Const x) (map_graph_fn G' h); (m x, m x) ∈ getRel (S_Const x) (map_graph_fn G' h); (m x, y) ∈ getRel S_Top (map_graph_fn G' h); (z, m x) ∈ getRel S_Top (map_graph_fn G' h)⟧ ⟹ (y, m x) ∈ getRel (S_Const x) (map_graph_fn G' h) O getRel S_Top (map_graph_fn G' h) O getRel (S_Const x) (map_graph_fn G' h)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . from x (*‹x ∈ C›*) mnt (*‹maintainedA (constant_rules C ∪ identity_rules L ∪ {top_rule S_Top, nonempty_rule}) G'›*) have "maintained (const_exists_rev x) G'" and "maintained (const_prop x) G'" unfolding constant_rules_def (*goals: 1. ‹maintained (const_exists_rev (x::'V)) (G'::('V Standard_Constant, 'V') labeled_graph)› 2. ‹maintained (const_prop (x::'V)) (G'::('V Standard_Constant, 'V') labeled_graph)›*) apply - (*goals: 1. ‹⟦x ∈ C; maintainedA (const_exists ` C ∪ const_exists_rev ` C ∪ const_prop ` C ∪ {const_disj c₁ c₂ |c₁ c₂. c₁ ∈ C ∧ c₂ ∈ C ∧ c₁ ≠ c₂} ∪ identity_rules L ∪ {top_rule S_Top, nonempty_rule}) G'⟧ ⟹ maintained (const_exists_rev x) G'› 2. ‹⟦x ∈ C; maintainedA (const_exists ` C ∪ const_exists_rev ` C ∪ const_prop ` C ∪ {const_disj c₁ c₂ |c₁ c₂. c₁ ∈ C ∧ c₂ ∈ C ∧ c₁ ≠ c₂} ∪ identity_rules L ∪ {top_rule S_Top, nonempty_rule}) G'⟧ ⟹ maintained (const_prop x) G'› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) . hence cr6: "maintained (const_exists_rev x) (map_graph_fn G' h)" and cr7: "maintained (const_prop x) (map_graph_fn G' h)" apply - (*goals: 1. ‹⟦maintained (const_exists_rev x) G'; maintained (const_prop x) G'⟧ ⟹ maintained (const_exists_rev x) (map_graph_fn G' h)› 2. ‹⟦maintained (const_exists_rev x) G'; maintained (const_prop x) G'⟧ ⟹ maintained (const_prop x) (map_graph_fn G' h)› discuss goal 1*) apply (intro mg (*‹maintained ?r G' ⟹ maintained ?r (map_graph_fn G' h)›*)) (*top goal: ‹⟦maintained (const_exists_rev x) G'; maintained (const_prop x) G'⟧ ⟹ maintained (const_exists_rev x) (map_graph_fn G' h)› and 1 goal remains*) apply force (*discuss goal 2*) apply (intro mg (*‹maintained (?r::('V Standard_Constant, ?'b1) labeled_graph × ('V Standard_Constant, ?'b1) labeled_graph) (G'::('V Standard_Constant, 'V') labeled_graph) ⟹ maintained ?r (map_graph_fn G' (h::'V' ⇒ 'V'))›*)) (*goal: ‹⟦maintained (const_exists_rev x) G'; maintained (const_prop x) G'⟧ ⟹ maintained (const_prop x) (map_graph_fn G' h)›*) apply force (*proven 2 subgoals*) . hence "(m x,z) ∈ getRel S_Idt (map_graph_fn G' h)" "(y,m x) ∈ getRel S_Idt (map_graph_fn G' h)" using lhs (*‹((m::'V ⇒ 'V') (x::'V), z::'V') ∈ getRel (S_Const x) (map_graph_fn (G'::('V Standard_Constant, 'V') labeled_graph) (h::'V' ⇒ 'V')) O getRel S_Top (map_graph_fn G' h) O getRel (S_Const x) (map_graph_fn G' h)› ‹(y::'V', (m::'V ⇒ 'V') (x::'V)) ∈ getRel (S_Const x) (map_graph_fn (G'::('V Standard_Constant, 'V') labeled_graph) (h::'V' ⇒ 'V')) O getRel S_Top (map_graph_fn G' h) O getRel (S_Const x) (map_graph_fn G' h)›*) unfolding maintained_holds_subset_iff[OF map_graph_fn_graphI] const_exists_rev_def const_prop_def (*goals: 1. ‹(m x, z) ∈ getRel S_Idt (map_graph_fn G' h)› 2. ‹(y, m x) ∈ getRel S_Idt (map_graph_fn G' h)›*) apply - (*goals: 1. ‹⟦:map_graph_fn G' h:⟦A_Cmp (A_Cmp (A_Lbl (S_Const x)) ⊤) (A_Lbl (S_Const x))⟧ ⊆ :map_graph_fn G' h:⟦A_Lbl (S_Const x)⟧; :map_graph_fn G' h:⟦A_Lbl (S_Const x)⟧ ⊆ :map_graph_fn G' h:⟦𝟭⟧; (m x, z) ∈ getRel (S_Const x) (map_graph_fn G' h) O getRel S_Top (map_graph_fn G' h) O getRel (S_Const x) (map_graph_fn G' h); (y, m x) ∈ getRel (S_Const x) (map_graph_fn G' h) O getRel S_Top (map_graph_fn G' h) O getRel (S_Const x) (map_graph_fn G' h)⟧ ⟹ (m x, z) ∈ getRel S_Idt (map_graph_fn G' h)› 2. ‹⟦:map_graph_fn G' h:⟦A_Cmp (A_Cmp (A_Lbl (S_Const x)) ⊤) (A_Lbl (S_Const x))⟧ ⊆ :map_graph_fn G' h:⟦A_Lbl (S_Const x)⟧; :map_graph_fn G' h:⟦A_Lbl (S_Const x)⟧ ⊆ :map_graph_fn G' h:⟦𝟭⟧; (m x, z) ∈ getRel (S_Const x) (map_graph_fn G' h) O getRel S_Top (map_graph_fn G' h) O getRel (S_Const x) (map_graph_fn G' h); (y, m x) ∈ getRel (S_Const x) (map_graph_fn G' h) O getRel S_Top (map_graph_fn G' h) O getRel (S_Const x) (map_graph_fn G' h)⟧ ⟹ (y, m x) ∈ getRel S_Idt (map_graph_fn G' h)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . hence "y = m x" "z = m x" using h(2) (*‹ident_rel S_Idt (map_graph_fn G' h)›*) apply - (*goals: 1. ‹⟦(m x, z) ∈ getRel S_Idt (map_graph_fn G' h); (y, m x) ∈ getRel S_Idt (map_graph_fn G' h); ident_rel S_Idt (map_graph_fn G' h)⟧ ⟹ y = m x› 2. ‹⟦(m x, z) ∈ getRel S_Idt (map_graph_fn G' h); (y, m x) ∈ getRel S_Idt (map_graph_fn G' h); ident_rel S_Idt (map_graph_fn G' h)⟧ ⟹ z = m x› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . } thus "getRel (S_Const x) (map_graph_fn G' h) ⊆ {(m x, m x)}" by auto qed (insert m (*‹?x1 ∈ C ⟹ (m ?x1, m ?x1) ∈ getRel (S_Const ?x1) (map_graph_fn G' h)›*), auto) (*solved the remaining goal: ‹⋀x. x ∈ C ⟹ {(m x, m x)} ⊆ getRel (S_Const x) (map_graph_fn G' h)›*) from mg_eq (*‹map_graph_fn G' (g ∘ f) = map_graph_fn G' h›*) have mg_eq: "map_graph_fn G g = map_graph_fn G' h" unfolding G_def map_graph_fn_comp (*goal: ‹map_graph_fn (map_graph_fn G' f) g = map_graph_fn G' h›*) . { fix l fix v :: "'V + 'V'" assume a: "(l, v)∈(λc. (S_Const c, Inl c)) ` C" (*‹(l::'V Standard_Constant, v::'V + 'V') ∈ (λc::'V. (S_Const c, Inl c)) ` (C::'V set)›*) hence "getRel l G = {(v, v)}" using m (*‹?x1 ∈ C ⟹ {(m ?x1, m ?x1)} = getRel (S_Const ?x1) (map_graph_fn G' h)›*) proof (cases l) (*goals: 1. ‹⟦(l, v) ∈ (λc. (S_Const c, Inl c)) ` C; ⋀x. x ∈ C ⟹ {(m x, m x)} = getRel (S_Const x) (map_graph_fn G' h); l = S_Top⟧ ⟹ getRel l G = {(v, v)}› 2. ‹⟦(l, v) ∈ (λc. (S_Const c, Inl c)) ` C; ⋀x. x ∈ C ⟹ {(m x, m x)} = getRel (S_Const x) (map_graph_fn G' h); l = S_Bot⟧ ⟹ getRel l G = {(v, v)}› 3. ‹⟦(l, v) ∈ (λc. (S_Const c, Inl c)) ` C; ⋀x. x ∈ C ⟹ {(m x, m x)} = getRel (S_Const x) (map_graph_fn G' h); l = S_Idt⟧ ⟹ getRel l G = {(v, v)}› 4. ‹⋀x4. ⟦(l, v) ∈ (λc. (S_Const c, Inl c)) ` C; ⋀x. x ∈ C ⟹ {(m x, m x)} = getRel (S_Const x) (map_graph_fn G' h); l = S_Const x4⟧ ⟹ getRel l G = {(v, v)}›*) case (S_Const x) (*‹l = S_Const x›*) hence x: "l = S_Const x" "v = Inl x" "x ∈ C" using a (*‹(l, v) ∈ (λc. (S_Const c, Inl c)) ` C›*) apply - (*goals: 1. ‹⟦l = S_Const x; (l, v) ∈ (λc. (S_Const c, Inl c)) ` C⟧ ⟹ l = S_Const x› 2. ‹⟦l = S_Const x; (l, v) ∈ (λc. (S_Const c, Inl c)) ` C⟧ ⟹ v = Inl x› 3. ‹⟦l = S_Const x; (l, v) ∈ (λc. (S_Const c, Inl c)) ` C⟧ ⟹ x ∈ C› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . hence mx: "m x ∈ m ` C" by auto from m[OF x ( 3 )] (*‹{(m x, m x)} = getRel (S_Const x) (map_graph_fn G' h)›*) have "(m x,m x) ∈ getRel (S_Const x) (map_graph_fn G' h)" by auto hence "(S_Const x,m x,m x) ∈ edges (map_graph_fn G' h)" unfolding getRel_def (*goal: ‹(S_Const x, m x, m x) ∈ edges (map_graph_fn G' h)›*) by auto hence "m x ∈ vertices (map_graph_fn G' h)" unfolding map_graph_def Image_def (*goal: ‹m x ∈ vertices (LG {y. ∃x∈edges G'. (x, y) ∈ on_triple (on_graph G' h)} {y. ∃x∈vertices G'. (x, y) ∈ on_graph G' h})›*) by auto then obtain x' where x': "m x = h x'" "x' ∈ vertices G'" (*goal: ‹(⋀x'::'V'::type. ⟦(m::'V::type ⇒ 'V'::type) (x::'V::type) = (h::'V'::type ⇒ 'V'::type) x'; x' ∈ vertices (G'::('V::type Standard_Constant, 'V'::type) labeled_graph)⟧ ⟹ thesis::bool) ⟹ thesis›*) by auto from h(1) (*‹h ∘ h = h›*) have hmx[simp]: "h (m x) = m x" unfolding x' o_def (*goal: ‹h (h x') = h x'›*) by metis hence fmx: "f (m x) = v" unfolding x f_def (*goal: ‹((λx. if x ∈ m ` C then Inl (the_inv_into C m x) else Inr x) ∘ h) (m x) = Inl x›*) using the_inv_into_f_f[OF inj_m] (*‹?x ∈ C ⟹ the_inv_into C m (m ?x) = ?x›*) inj_m[unfolded inj_on_def, rule_format, OF x ( 3 )] (*‹⟦?y ∈ C; m x = m ?y⟧ ⟹ x = ?y›*) mx (*‹m x ∈ m ` C›*) by auto have "{(f (m x), f (m x))} = getRel l (map_graph_fn G (f ∘ g))" unfolding map_graph_fn_comp getRel_hom_map[OF map_graph_fn_graphI] m[OF x ( 3 ), folded mg_eq x ( 1 ), symmetric] (*goal: ‹{(f (m x), f (m x))} = map_prod f f ` {(m x, m x)}›*) by auto hence gr: "getRel l G = {(f (m x), f (m x))}" unfolding fg_inv (*goal: ‹getRel l G = {(f (m x), f (m x))}›*) by blast show "?thesis" (*goal: ‹getRel l G = {(v, v)}›*) unfolding gr fmx (*goal: ‹{(v, v)} = {(v, v)}›*) by (fact refl (*‹?t = ?t›*)) qed (auto) (*solves the remaining goals: 1. ‹⟦(l, v) ∈ (λc. (S_Const c, Inl c)) ` C; ⋀x. x ∈ C ⟹ {(m x, m x)} = getRel (S_Const x) (map_graph_fn G' h); l = S_Top⟧ ⟹ getRel l G = {(v, v)}› 2. ‹⟦(l, v) ∈ (λc. (S_Const c, Inl c)) ` C; ⋀x. x ∈ C ⟹ {(m x, m x)} = getRel (S_Const x) (map_graph_fn G' h); l = S_Bot⟧ ⟹ getRel l G = {(v, v)}› 3. ‹⟦(l, v) ∈ (λc. (S_Const c, Inl c)) ` C; ⋀x. x ∈ C ⟹ {(m x, m x)} = getRel (S_Const x) (map_graph_fn G' h); l = S_Idt⟧ ⟹ getRel l G = {(v, v)}›*) } note cr = this (*‹(?l3, ?v3) ∈ (λc. (S_Const c, Inl c)) ` C ⟹ getRel ?l3 G = {(?v3, ?v3)}›*) have sg: "subgraph (map_graph_fn G g) G'" unfolding mg_eq (*goal: ‹subgraph (map_graph_fn (G'::('V Standard_Constant, 'V') labeled_graph) (h::'V' ⇒ 'V')) G'›*) using h(3) (*‹subgraph (map_graph_fn G' h) G'›*) . have std: "standard' C G" unfolding standard_def (*goal: ‹graph G ∧ vertices G ≠ {} ∧ ident_rel S_Idt G ∧ getRel S_Bot G = {} ∧ getRel S_Top G = {(x, y). x ∈ vertices G ∧ y ∈ vertices G} ∧ (∀(l, v)∈(λc. (S_Const c, Inl c)) ` C. getRel l G = {(v, v)})›*) using G (*‹graph G› ‹f x ∈ vertices G› ‹getRel S_Bot G = {}›*) ir (*‹ident_rel S_Idt G›*) tr (*‹getRel S_Top G = {(x, y). x ∈ vertices G ∧ y ∈ vertices G}›*) cr (*‹(?l3, ?v3) ∈ (λc. (S_Const c, Inl c)) ` C ⟹ getRel ?l3 G = {(?v3, ?v3)}›*) by blast have mtd: "⋀r. maintained r G' ⟹ maintained r G" proof (goal_cases) (*goal: ‹⋀r. maintained r G' ⟹ maintained r G›*) case (1 r) (*‹maintained r G'›*) from mg[OF 1, folded mg_eq] (*‹maintained r (map_graph_fn G g)›*) maintained_preserved_by_isomorphism[OF fg_id G ( 1 )] (*‹⟦⋀x. x ∈ vertices G ⟹ x ∈ vertices G; maintained ?r (map_graph_fn G g)⟧ ⟹ maintained ?r G›*) show "?case" (*goal: ‹maintained r G›*) by metis qed { fix x and y and e assume "x ∈ vertices G'" "y ∈ vertices G'" "(g (f x), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦e⟧" (*‹(x::'V') ∈ vertices (G'::('V Standard_Constant, 'V') labeled_graph)› ‹(y::'V') ∈ vertices (G'::('V Standard_Constant, 'V') labeled_graph)› ‹((g::'V + 'V' ⇒ 'V') ((f::'V' ⇒ 'V + 'V') (x::'V')), g (f (y::'V'))) ∈ :map_graph_fn (map_graph_fn (G'::('V Standard_Constant, 'V') labeled_graph) f) g:⟦e::'V Standard_Constant allegorical_term⟧›*) hence "(x,y) ∈ :G':⟦e⟧" proof (induct e arbitrary: x y) (*goals: 1. ‹⋀e1 e2 x y. ⟦⋀x y. ⟦x ∈ vertices G'; y ∈ vertices G'; (g (f x), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦e1⟧⟧ ⟹ (x, y) ∈ :G':⟦e1⟧; ⋀x y. ⟦x ∈ vertices G'; y ∈ vertices G'; (g (f x), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦e2⟧⟧ ⟹ (x, y) ∈ :G':⟦e2⟧; x ∈ vertices G'; y ∈ vertices G'; (g (f x), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦A_Int e1 e2⟧⟧ ⟹ (x, y) ∈ :G':⟦A_Int e1 e2⟧› 2. ‹⋀e1 e2 x y. ⟦⋀x y. ⟦x ∈ vertices G'; y ∈ vertices G'; (g (f x), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦e1⟧⟧ ⟹ (x, y) ∈ :G':⟦e1⟧; ⋀x y. ⟦x ∈ vertices G'; y ∈ vertices G'; (g (f x), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦e2⟧⟧ ⟹ (x, y) ∈ :G':⟦e2⟧; x ∈ vertices G'; y ∈ vertices G'; (g (f x), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦A_Cmp e1 e2⟧⟧ ⟹ (x, y) ∈ :G':⟦A_Cmp e1 e2⟧› 3. ‹⋀e x y. ⟦⋀x y. ⟦x ∈ vertices G'; y ∈ vertices G'; (g (f x), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦e⟧⟧ ⟹ (x, y) ∈ :G':⟦e⟧; x ∈ vertices G'; y ∈ vertices G'; (g (f x), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦A_Cnv e⟧⟧ ⟹ (x, y) ∈ :G':⟦A_Cnv e⟧› 4. ‹⋀x xa y. ⟦xa ∈ vertices G'; y ∈ vertices G'; (g (f xa), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦A_Lbl x⟧⟧ ⟹ (xa, y) ∈ :G':⟦A_Lbl x⟧›*) case (A_Cmp e1 e2) (*‹⟦(?x2::'V') ∈ vertices (G'::('V Standard_Constant, 'V') labeled_graph); (?y2::'V') ∈ vertices G'; ((g::'V + 'V' ⇒ 'V') ((f::'V' ⇒ 'V + 'V') ?x2), g (f ?y2)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦e1::'V Standard_Constant allegorical_term⟧⟧ ⟹ (?x2, ?y2) ∈ :G':⟦e1⟧› ‹⟦?x2 ∈ vertices G'; ?y2 ∈ vertices G'; (g (f ?x2), g (f ?y2)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦e2⟧⟧ ⟹ (?x2, ?y2) ∈ :G':⟦e2⟧› ‹x ∈ vertices G'› ‹y ∈ vertices G'› ‹(g (f x), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦A_Cmp e1 e2⟧›*) then obtain z where z: "(g (f x), z) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦e1⟧" "(z, g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦e2⟧" (*goal: ‹(⋀z. ⟦(g (f x), z) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦e1⟧; (z, g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦e2⟧⟧ ⟹ thesis) ⟹ thesis›*) by auto hence "z ∈ vertices (map_graph_fn (map_graph_fn G' f) g)" using semantics_in_vertices(1)[OF map_graph_fn_graphI] (*‹(?a, ?b) ∈ :map_graph_fn ?G1 ?f1:⟦?e⟧ ⟹ ?a ∈ vertices (map_graph_fn ?G1 ?f1)›*) by metis then obtain z' where z': "z = g (f z')" "z' ∈ vertices G'" (*goal: ‹(⋀z'. ⟦z = g (f z'); z' ∈ vertices G'⟧ ⟹ thesis) ⟹ thesis›*) by auto with A_Cmp(1)[OF A_Cmp ( 3 ) z' ( 2 ) z ( 1 ) [ unfolded z' ]] (*‹(x, z') ∈ :G':⟦e1⟧›*) A_Cmp(2)[OF z' ( 2 ) A_Cmp ( 4 ) z ( 2 ) [ unfolded z' ]] (*‹(z', y) ∈ :G':⟦e2⟧›*) have "(x, y) ∈ (:G':⟦e1⟧) O (:G':⟦e2⟧)" by auto then show "?case" (*goal: ‹(x, y) ∈ :G':⟦A_Cmp e1 e2⟧›*) by auto next (*goals: 1. ‹⋀e1 e2 x y. ⟦⋀x y. ⟦x ∈ vertices G'; y ∈ vertices G'; (g (f x), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦e1⟧⟧ ⟹ (x, y) ∈ :G':⟦e1⟧; ⋀x y. ⟦x ∈ vertices G'; y ∈ vertices G'; (g (f x), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦e2⟧⟧ ⟹ (x, y) ∈ :G':⟦e2⟧; x ∈ vertices G'; y ∈ vertices G'; (g (f x), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦A_Int e1 e2⟧⟧ ⟹ (x, y) ∈ :G':⟦A_Int e1 e2⟧› 2. ‹⋀e x y. ⟦⋀x y. ⟦x ∈ vertices G'; y ∈ vertices G'; (g (f x), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦e⟧⟧ ⟹ (x, y) ∈ :G':⟦e⟧; x ∈ vertices G'; y ∈ vertices G'; (g (f x), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦A_Cnv e⟧⟧ ⟹ (x, y) ∈ :G':⟦A_Cnv e⟧› 3. ‹⋀x xa y. ⟦xa ∈ vertices G'; y ∈ vertices G'; (g (f xa), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦A_Lbl x⟧⟧ ⟹ (xa, y) ∈ :G':⟦A_Lbl x⟧›*) case (A_Lbl l) (*‹x ∈ vertices G'› ‹y ∈ vertices G'› ‹(g (f x), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦A_Lbl l⟧›*) hence "(l, g (f x), g (f y)) ∈ edges (map_graph_fn G g)" by (auto simp:getRel_def (*‹getRel ?l ?G = {(x, y). (?l, x, y) ∈ edges ?G}›*) G_def (*‹G = map_graph_fn G' f›*)) then obtain x' and y' where "(l, x', y') ∈ edges G" "g (f x) = g x'" "g (f y) = g y'" (*goal: ‹(⋀(x'::'V::type + 'V'::type) y'::'V::type + 'V'::type. ⟦(l::'V::type Standard_Constant, x', y') ∈ edges (G::('V::type Standard_Constant, 'V::type + 'V'::type) labeled_graph); (g::'V::type + 'V'::type ⇒ 'V'::type) ((f::'V'::type ⇒ 'V::type + 'V'::type) (x::'V'::type)) = g x'; g (f (y::'V'::type)) = g y'⟧ ⟹ thesis::bool) ⟹ thesis›*) by auto then obtain x' and y' where xy: "(l, x', y') ∈ edges G'" "g (f x) = g (f x')" "g (f y) = g (f y')" (*goal: ‹(⋀x' y'. ⟦(l, x', y') ∈ edges G'; g (f x) = g (f x'); g (f y) = g (f y')⟧ ⟹ thesis) ⟹ thesis›*) unfolding G_def (*goal: ‹(⋀x' y'. ⟦(l, x', y') ∈ edges G'; g (f x) = g (f x'); g (f y) = g (f y')⟧ ⟹ thesis) ⟹ thesis›*) by auto hence "x' ∈ vertices G'" "y' ∈ vertices G'" using gr(1) (*‹graph G'›*) apply - (*goals: 1. ‹⟦(l, x', y') ∈ edges G'; g (f x) = g (f x'); g (f y) = g (f y'); graph G'⟧ ⟹ x' ∈ vertices G'› 2. ‹⟦(l, x', y') ∈ edges G'; g (f x) = g (f x'); g (f y) = g (f y'); graph G'⟧ ⟹ y' ∈ vertices G'› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . from this[THEN gf_h, unfolded o_def] (*‹(g::'V::type + 'V'::type ⇒ 'V'::type) ((f::'V'::type ⇒ 'V::type + 'V'::type) (x'::'V'::type)) = (h::'V'::type ⇒ 'V'::type) x'› ‹g (f y') = h y'›*) A_Lbl(1,2)[THEN gf_h, unfolded o_def] (*‹g (f x) = h x› ‹g (f y) = h y›*) have "h x = h x'" "h y = h y'" using xy(2,3) (*‹g (f x) = g (f x')› ‹g (f y) = g (f y')›*) apply - (*goals: 1. ‹⟦g (f x') = h x'; g (f y') = h y'; g (f x) = h x; g (f y) = h y; g (f x) = g (f x'); g (f y) = g (f y')⟧ ⟹ h x = h x'› 2. ‹⟦g (f x') = h x'; g (f y') = h y'; g (f x) = h x; g (f y) = h y; g (f x) = g (f x'); g (f y) = g (f y')⟧ ⟹ h y = h y'› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . hence "(l, x, y) ∈ edges G'" using h(4)[of l x y] (*‹((l, x, y) ∈ edges G') = ((l, h x, h y) ∈ edges G')›*) h(4)[of l x' y'] (*‹((l, x', y') ∈ edges G') = ((l, h x', h y') ∈ edges G')›*) xy(1) (*‹(l, x', y') ∈ edges G'›*) by auto then show "?case" (*goal: ‹(x, y) ∈ :G':⟦A_Lbl l⟧›*) by (simp add:getRel_def (*‹getRel ?l ?G = {(x, y). (?l, x, y) ∈ edges ?G}›*)) qed (auto) (*solves the remaining goals: 1. ‹⋀(e1::'V::type Standard_Constant allegorical_term) (e2::'V::type Standard_Constant allegorical_term) (x::'V'::type) y::'V'::type. ⟦⋀(x::'V'::type) y::'V'::type. ⟦x ∈ vertices (G'::('V::type Standard_Constant, 'V'::type) labeled_graph); y ∈ vertices G'; ((g::'V::type + 'V'::type ⇒ 'V'::type) ((f::'V'::type ⇒ 'V::type + 'V'::type) x), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦e1⟧⟧ ⟹ (x, y) ∈ :G':⟦e1⟧; ⋀(x::'V'::type) y::'V'::type. ⟦x ∈ vertices G'; y ∈ vertices G'; (g (f x), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦e2⟧⟧ ⟹ (x, y) ∈ :G':⟦e2⟧; x ∈ vertices G'; y ∈ vertices G'; (g (f x), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦A_Int e1 e2⟧⟧ ⟹ (x, y) ∈ :G':⟦A_Int e1 e2⟧› 2. ‹⋀(e::'V::type Standard_Constant allegorical_term) (x::'V'::type) y::'V'::type. ⟦⋀(x::'V'::type) y::'V'::type. ⟦x ∈ vertices (G'::('V::type Standard_Constant, 'V'::type) labeled_graph); y ∈ vertices G'; ((g::'V::type + 'V'::type ⇒ 'V'::type) ((f::'V'::type ⇒ 'V::type + 'V'::type) x), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦e⟧⟧ ⟹ (x, y) ∈ :G':⟦e⟧; x ∈ vertices G'; y ∈ vertices G'; (g (f x), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦A_Cnv e⟧⟧ ⟹ (x, y) ∈ :G':⟦A_Cnv e⟧›*) } hence cons: "(∀ x y e. x ∈ vertices G' ⟶ y ∈ vertices G' ⟶ (g (f x), g (f y)) ∈ :map_graph_fn G g:⟦e⟧ ⟶ (x,y) ∈ :G':⟦e⟧)" unfolding G_def (*goal: ‹∀x y e. x ∈ vertices G' ⟶ y ∈ vertices G' ⟶ (g (f x), g (f y)) ∈ :map_graph_fn (map_graph_fn G' f) g:⟦e⟧ ⟶ (x, y) ∈ :G':⟦e⟧›*) by auto show "?thesis" (*goal: ‹∃(f::'V' ⇒ 'V + 'V') (g::'V + 'V' ⇒ 'V') G::('V Standard_Constant, 'V + 'V') labeled_graph. G = map_graph_fn G (f ∘ g) ∧ G = map_graph_fn (G'::('V Standard_Constant, 'V') labeled_graph) f ∧ subgraph (map_graph_fn G g) G' ∧ standard' (C::'V set) G ∧ (∀r::('V Standard_Constant, 'a) labeled_graph × ('V Standard_Constant, 'a) labeled_graph. maintained r G' ⟶ maintained r G) ∧ (∀(x::'V') (y::'V') e::'V Standard_Constant allegorical_term. x ∈ vertices G' ⟶ y ∈ vertices G' ⟶ (g (f x), g (f y)) ∈ :map_graph_fn G g:⟦e⟧ ⟶ (x, y) ∈ :G':⟦e⟧)›*) using cons (*‹∀x y e. x ∈ vertices G' ⟶ y ∈ vertices G' ⟶ (g (f x), g (f y)) ∈ :map_graph_fn G g:⟦e⟧ ⟶ (x, y) ∈ :G':⟦e⟧›*) G_def (*‹G = map_graph_fn G' f›*) fg_inv[symmetric] (*‹(G::('V Standard_Constant, 'V + 'V') labeled_graph) = map_graph_fn G ((f::'V' ⇒ 'V + 'V') ∘ (g::'V + 'V' ⇒ 'V'))›*) sg (*‹subgraph (map_graph_fn (G::('V::type Standard_Constant, 'V::type + 'V'::type) labeled_graph) (g::'V::type + 'V'::type ⇒ 'V'::type)) (G'::('V::type Standard_Constant, 'V'::type) labeled_graph)›*) std (*‹standard' C G›*) mtd (*‹maintained (?r1::('V Standard_Constant, ?'b2) labeled_graph × ('V Standard_Constant, ?'b2) labeled_graph) (G'::('V Standard_Constant, 'V') labeled_graph) ⟹ maintained ?r1 (G::('V Standard_Constant, 'V + 'V') labeled_graph)›*) by blast qed end
{ "path": "afp-2025-02-12/thys/Graph_Saturation/StandardRules.thy", "repo": "afp-2025-02-12", "sha": "55a9f695c9ff5ce75a09a60e090141048b81eb3dcb37a4123489ca2fa4386e98" }
(* Title: The pi-calculus Author/Maintainer: Jesper Bengtson (jebe.dk), 2012 *) theory Strong_Early_Bisim_Pres imports Strong_Early_Bisim Strong_Early_Sim_Pres begin (************* Preservation rules *************) lemma tauPres: fixes P :: pi and Q :: pi assumes "P ∼ Q" shows "τ.(P) ∼ τ.(Q)" proof (-) (*goal: ‹τ.(P::pi) ∼ τ.(Q::pi)›*) let ?X = "{(τ.(P), τ.(Q)) | P Q. P ∼ Q}" from ‹P ∼ Q› (*‹P ∼ Q›*) have "(τ.(P), τ.(Q)) ∈ ?X" by auto thus "?thesis" (*goal: ‹τ.(P::pi) ∼ τ.(Q::pi)›*) apply (coinduct rule: bisimCoinduct) (*goals: 1. ‹⋀R S. (R, S) ∈ {(τ.P, τ.Q) |P Q. P ∼ Q} ⟹ R ↝[({(τ.P, τ.Q) |P Q. P ∼ Q} ∪ bisim)] S› 2. ‹⋀R S. (R, S) ∈ {(τ.P, τ.Q) |P Q. P ∼ Q} ⟹ (S, R) ∈ {(τ.P, τ.Q) |P Q. P ∼ Q}› discuss goal 1*) apply ((auto intro: tauPres (*‹(?P, ?Q) ∈ ?Rel ⟹ τ.?P ↝[?Rel] τ.?Q›*) dest: bisimE (*‹?P ∼ ?Q ⟹ ?P ↝[bisim] ?Q› ‹?P ∼ ?Q ⟹ ?Q ∼ ?P›*))[1]) (*discuss goal 2*) apply ((auto intro: tauPres (*‹(?P, ?Q) ∈ ?Rel ⟹ τ.?P ↝[?Rel] τ.?Q›*) dest: bisimE (*‹?P ∼ ?Q ⟹ ?P ↝[bisim] ?Q› ‹?P ∼ ?Q ⟹ ?Q ∼ ?P›*))[1]) (*proven 2 subgoals*) . qed lemma inputPres: fixes P :: pi and Q :: pi and a :: name and x :: name assumes PSimQ: "∀y. P[x::=y] ∼ Q[x::=y]" shows "a<x>.P ∼ a<x>.Q" proof (-) (*goal: ‹a<x>.P ∼ a<x>.Q›*) let ?X = "{(a<x>.P, a<x>.Q) | a x P Q. ∀y. P[x::=y] ∼ Q[x::=y]}" { fix axP and axQ and p assume "(axP, axQ) ∈ ?X" (*‹(axP::pi, axQ::pi) ∈ {(a<x>.P, a<x>.Q) |(a::name) (x::name) (P::pi) Q::pi. ∀y::name. P[x::=y] ∼ Q[x::=y]}›*) then obtain a and x and P and Q where A: "∀y. P[x::=y] ∼ Q[x::=y]" and B: "axP = a<x>.P" and C: "axQ = a<x>.Q" (*goal: ‹(⋀P x Q a. ⟦∀y. P[x::=y] ∼ Q[x::=y]; axP = a<x>.P; axQ = a<x>.Q⟧ ⟹ thesis) ⟹ thesis›*) by auto have "⋀y. ((p::name prm) ∙ P)[(p ∙ x)::=y] ∼ (p ∙ Q)[(p ∙ x)::=y]" proof (-) (*goal: ‹⋀y. (p ∙ P)[(p ∙ x)::=y] ∼ (p ∙ Q)[(p ∙ x)::=y]›*) fix y from A (*‹∀y::name. (P::pi)[(x::name)::=y] ∼ (Q::pi)[x::=y]›*) have "P[x::=(rev p ∙ y)] ∼ Q[x::=(rev p ∙ y)]" by blast hence "(p ∙ (P[x::=(rev p ∙ y)])) ∼ p ∙ (Q[x::=(rev p ∙ y)])" by (rule bisimClosed (*‹?P ∼ ?Q ⟹ ?p ∙ ?P ∼ ?p ∙ ?Q›*)) thus "(p ∙ P)[(p ∙ x)::=y] ∼ (p ∙ Q)[(p ∙ x)::=y]" by (simp add: eqvts (*‹(?p1::(name × name) list) ∙ ((?P1::pi) ∼ (?Q1::pi)) = ?p1 ∙ ?P1 ∼ ?p1 ∙ ?Q1› ‹(?P::pi) ∼ (?Q::pi) ⟹ (?p::(name × name) list) ∙ ?P ∼ ?p ∙ ?Q› ‹(?pi1::(name × name) list) ∙ (?x1.1::pi) ⟼ (?x2.1::residual) = ?pi1 ∙ ?x1.1 ⟼ ?pi1 ∙ ?x2.1› ‹(?x1.0::pi) ⟼ (?x2.0::residual) ⟹ (?pi::(name × name) list) ∙ ?x1.0 ⟼ ?pi ∙ ?x2.0› ‹(?pi::(name × name) list) ∙ (?x2.0::freeRes) ≺ (?x1.0::pi) = ?pi ∙ ?x2.0 ≺ ?pi ∙ ?x1.0› ‹(?pi::(name × name) list) ∙ (?x3.0::name)<ν(?x1.0::name)> ≺ (?x2.0::pi) = (?pi ∙ ?x3.0)<ν(?pi ∙ ?x1.0)> ≺ (?pi ∙ ?x2.0)› ‹(?pi::(name × name) list) ∙ τ = τ› ‹(?pi::(name × name) list) ∙ (?x2.0::name)[(?x1.0::name)] = (?pi ∙ ?x2.0)[(?pi ∙ ?x1.0)]› ‹(?pi::(name × name) list) ∙ (?x2.0::name)<(?x1.0::name)> = (?pi ∙ ?x2.0)<(?pi ∙ ?x1.0)>› ‹(?p::(name × name) list) ∙ (?P::pi)[<(?σ::(name × name) list)>] = (?p ∙ ?P)[<(?p ∙ ?σ)>]› ‹(?p::(name × name) list) ∙ (?P::pi)[(?a::name)::=(?b::name)] = (?p ∙ ?P)[(?p ∙ ?a)::=(?p ∙ ?b)]› ‹(?p::(name × name) list) ∙ (?a::name)[(?b::name)::=(?c::name)] = (?p ∙ ?a)[(?p ∙ ?b)::=(?p ∙ ?c)]› and more 65 facts*) pt_pi_rev[OF pt_name_inst, OF at_name_inst] (*‹(?pi::(name × name) list) ∙ rev ?pi ∙ (?x::?'x1) = ?x›*)) qed hence "((p::name prm) ∙ axP, p ∙ axQ) ∈ ?X" using B (*‹axP = a<x>.P›*) C (*‹axQ = a<x>.Q›*) by auto } hence "eqvt ?X" by (simp add: eqvt_def (*‹eqvt ?Rel ≡ ∀x perma. x ∈ ?Rel ⟶ perma ∙ x ∈ ?Rel›*)) from PSimQ (*‹∀y. P[x::=y] ∼ Q[x::=y]›*) have "(a<x>.P, a<x>.Q) ∈ ?X" by auto thus "?thesis" (*goal: ‹a<x>.P ∼ a<x>.Q›*) proof (coinduct rule: bisimCoinduct) (*goals: 1. ‹⋀R S. (R, S) ∈ {(a<x>.P, a<x>.Q) |a x P Q. ∀y. P[x::=y] ∼ Q[x::=y]} ⟹ R ↝[({(a<x>.P, a<x>.Q) |a x P Q. ∀y. P[x::=y] ∼ Q[x::=y]} ∪ bisim)] S› 2. ‹⋀R S. (R, S) ∈ {(a<x>.P, a<x>.Q) |a x P Q. ∀y. P[x::=y] ∼ Q[x::=y]} ⟹ (S, R) ∈ {(a<x>.P, a<x>.Q) |a x P Q. ∀y. P[x::=y] ∼ Q[x::=y]}›*) case (cSim P Q) (*‹(P, Q) ∈ {(a<x>.P, a<x>.Q) |a x P Q. ∀y. P[x::=y] ∼ Q[x::=y]}›*) thus "?case" (*goal: ‹P ↝[({(a<x>.P, a<x>.Q) |a x P Q. ∀y. P[x::=y] ∼ Q[x::=y]} ∪ bisim)] Q›*) using ‹eqvt ?X› (*‹eqvt {(a<x>.P, a<x>.Q) |a x P Q. ∀y. P[x::=y] ∼ Q[x::=y]}›*) by (force intro: inputPres (*‹⟦∀y. (?P[?x::=y], ?Q[?x::=y]) ∈ ?Rel; eqvt ?Rel⟧ ⟹ ?a<?x>.?P ↝[?Rel] ?a<?x>.?Q›*)) next (*goal: ‹⋀R S. (R, S) ∈ {(a<x>.P, a<x>.Q) |a x P Q. ∀y. P[x::=y] ∼ Q[x::=y]} ⟹ (S, R) ∈ {(a<x>.P, a<x>.Q) |a x P Q. ∀y. P[x::=y] ∼ Q[x::=y]}›*) case (cSym P Q) (*‹(P, Q) ∈ {(a<x>.P, a<x>.Q) |a x P Q. ∀y. P[x::=y] ∼ Q[x::=y]}›*) thus "?case" (*goal: ‹(Q, P) ∈ {(a<x>.P, a<x>.Q) |a x P Q. ∀y. P[x::=y] ∼ Q[x::=y]}›*) by (blast dest: bisimE (*‹?P ∼ ?Q ⟹ ?P ↝[bisim] ?Q› ‹?P ∼ ?Q ⟹ ?Q ∼ ?P›*)) qed qed lemma outputPres: fixes P :: pi and Q :: pi and a :: name and b :: name assumes "P ∼ Q" shows "a{b}.P ∼ a{b}.Q" proof (-) (*goal: ‹a{b}.P ∼ a{b}.Q›*) let ?X = "{(a{b}.P, a{b}.Q) | a b P Q. P ∼ Q}" from ‹P ∼ Q› (*‹P ∼ Q›*) have "(a{b}.P, a{b}.Q) ∈ ?X" by auto thus "?thesis" (*goal: ‹a{b}.P ∼ a{b}.Q›*) apply (coinduct rule: bisimCoinduct) (*goals: 1. ‹⋀R S. (R, S) ∈ {(a{b}.P, a{b}.Q) |a b P Q. P ∼ Q} ⟹ R ↝[({(a{b}.P, a{b}.Q) |a b P Q. P ∼ Q} ∪ bisim)] S› 2. ‹⋀R S. (R, S) ∈ {(a{b}.P, a{b}.Q) |a b P Q. P ∼ Q} ⟹ (S, R) ∈ {(a{b}.P, a{b}.Q) |a b P Q. P ∼ Q}› discuss goal 1*) apply (blast intro: outputPres (*‹(?P, ?Q) ∈ ?Rel ⟹ ?a{?b}.?P ↝[?Rel] ?a{?b}.?Q›*) dest: bisimE (*‹?P ∼ ?Q ⟹ ?P ↝[bisim] ?Q› ‹?P ∼ ?Q ⟹ ?Q ∼ ?P›*)) (*discuss goal 2*) apply (blast intro: outputPres (*‹(?P, ?Q) ∈ ?Rel ⟹ ?a{?b}.?P ↝[?Rel] ?a{?b}.?Q›*) dest: bisimE (*‹?P ∼ ?Q ⟹ ?P ↝[bisim] ?Q› ‹?P ∼ ?Q ⟹ ?Q ∼ ?P›*)) (*proven 2 subgoals*) . qed lemma matchPres: fixes P :: pi and Q :: pi and a :: name and b :: name assumes "P ∼ Q" shows "[a⌢b]P ∼ [a⌢b]Q" proof (-) (*goal: ‹[a⌢b]P ∼ [a⌢b]Q›*) let ?X = "{x. ∃P Q a b. P ∼ Q ∧ x = ([a⌢b]P, [a⌢b]Q)}" from assms (*‹P ∼ Q›*) have "([a⌢b]P, [a⌢b]Q) ∈ ?X" by blast thus "?thesis" (*goal: ‹[a⌢b]P ∼ [a⌢b]Q›*) apply (coinduct rule: bisimCoinduct) (*goals: 1. ‹⋀R S. (R, S) ∈ {x. ∃P Q a b. P ∼ Q ∧ x = ([a⌢b]P, [a⌢b]Q)} ⟹ R ↝[({x. ∃P Q a b. P ∼ Q ∧ x = ([a⌢b]P, [a⌢b]Q)} ∪ bisim)] S› 2. ‹⋀R S. (R, S) ∈ {x. ∃P Q a b. P ∼ Q ∧ x = ([a⌢b]P, [a⌢b]Q)} ⟹ (S, R) ∈ {x. ∃P Q a b. P ∼ Q ∧ x = ([a⌢b]P, [a⌢b]Q)}› discuss goal 1*) apply (blast intro: matchPres (*‹⟦?P ↝[?Rel] ?Q; ?Rel ⊆ ?Rel'⟧ ⟹ [?a⌢?b]?P ↝[?Rel'] [?a⌢?b]?Q›*) dest: bisimE (*‹?P ∼ ?Q ⟹ ?P ↝[bisim] ?Q› ‹?P ∼ ?Q ⟹ ?Q ∼ ?P›*)) (*discuss goal 2*) apply (blast intro: matchPres (*‹⟦(?P::pi) ↝[(?Rel::(pi × pi) set)] (?Q::pi); ?Rel ⊆ (?Rel'::(pi × pi) set)⟧ ⟹ [(?a::name)⌢(?b::name)]?P ↝[?Rel'] [?a⌢?b]?Q›*) dest: bisimE (*‹(?P::pi) ∼ (?Q::pi) ⟹ ?P ↝[bisim] ?Q› ‹(?P::pi) ∼ (?Q::pi) ⟹ ?Q ∼ ?P›*)) (*proven 2 subgoals*) . qed lemma mismatchPres: fixes P :: pi and Q :: pi and a :: name and b :: name assumes "P ∼ Q" shows "[a≠b]P ∼ [a≠b]Q" proof (-) (*goal: ‹[a≠b]P ∼ [a≠b]Q›*) let ?X = "{x. ∃P Q a b. P ∼ Q ∧ x = ([a≠b]P, [a≠b]Q)}" from assms (*‹P ∼ Q›*) have "([a≠b]P, [a≠b]Q) ∈ ?X" by blast thus "?thesis" (*goal: ‹[a≠b]P ∼ [a≠b]Q›*) apply (coinduct rule: bisimCoinduct) (*goals: 1. ‹⋀R S. (R, S) ∈ {x. ∃P Q a b. P ∼ Q ∧ x = ([a≠b]P, [a≠b]Q)} ⟹ R ↝[({x. ∃P Q a b. P ∼ Q ∧ x = ([a≠b]P, [a≠b]Q)} ∪ bisim)] S› 2. ‹⋀R S. (R, S) ∈ {x. ∃P Q a b. P ∼ Q ∧ x = ([a≠b]P, [a≠b]Q)} ⟹ (S, R) ∈ {x. ∃P Q a b. P ∼ Q ∧ x = ([a≠b]P, [a≠b]Q)}› discuss goal 1*) apply (blast intro: mismatchPres (*‹⟦?P ↝[?Rel] ?Q; ?Rel ⊆ ?Rel'⟧ ⟹ [?a≠?b]?P ↝[?Rel'] [?a≠?b]?Q›*) dest: bisimE (*‹?P ∼ ?Q ⟹ ?P ↝[bisim] ?Q› ‹?P ∼ ?Q ⟹ ?Q ∼ ?P›*)) (*discuss goal 2*) apply (blast intro: mismatchPres (*‹⟦?P ↝[?Rel] ?Q; ?Rel ⊆ ?Rel'⟧ ⟹ [?a≠?b]?P ↝[?Rel'] [?a≠?b]?Q›*) dest: bisimE (*‹?P ∼ ?Q ⟹ ?P ↝[bisim] ?Q› ‹?P ∼ ?Q ⟹ ?Q ∼ ?P›*)) (*proven 2 subgoals*) . qed lemma sumPres: fixes P :: pi and Q :: pi and R :: pi assumes "P ∼ Q" shows "P ⊕ R ∼ Q ⊕ R" proof (-) (*goal: ‹P ⊕ R ∼ Q ⊕ R›*) let ?X = "{(P ⊕ R, Q ⊕ R) | P Q R. P ∼ Q}" from assms (*‹P ∼ Q›*) have "(P ⊕ R, Q ⊕ R) ∈ ?X" by blast thus "?thesis" (*goal: ‹P ⊕ R ∼ Q ⊕ R›*) apply (coinduct rule: bisimCoinduct) (*goals: 1. ‹⋀R S. (R, S) ∈ {(P ⊕ R, Q ⊕ R) |P Q R. P ∼ Q} ⟹ R ↝[({(P ⊕ R, Q ⊕ R) |P Q R. P ∼ Q} ∪ bisim)] S› 2. ‹⋀R S. (R, S) ∈ {(P ⊕ R, Q ⊕ R) |P Q R. P ∼ Q} ⟹ (S, R) ∈ {(P ⊕ R, Q ⊕ R) |P Q R. P ∼ Q}› discuss goal 1*) apply ((auto dest: bisimE (*‹?P ∼ ?Q ⟹ ?P ↝[bisim] ?Q› ‹?P ∼ ?Q ⟹ ?Q ∼ ?P›*) intro: reflexive (*‹?P ∼ ?P›*) sumPres (*‹⟦?P ↝[?Rel] ?Q; Id ⊆ ?Rel'; ?Rel ⊆ ?Rel'⟧ ⟹ ?P ⊕ ?R ↝[?Rel'] ?Q ⊕ ?R›*))[1]) (*discuss goal 2*) apply ((auto dest: bisimE (*‹?P ∼ ?Q ⟹ ?P ↝[bisim] ?Q› ‹?P ∼ ?Q ⟹ ?Q ∼ ?P›*) intro: reflexive (*‹?P ∼ ?P›*) sumPres (*‹⟦?P ↝[?Rel] ?Q; Id ⊆ ?Rel'; ?Rel ⊆ ?Rel'⟧ ⟹ ?P ⊕ ?R ↝[?Rel'] ?Q ⊕ ?R›*))[1]) (*proven 2 subgoals*) . qed lemma resPres: fixes P :: pi and Q :: pi and x :: name assumes "P ∼ Q" shows "<νx>P ∼ <νx>Q" proof (-) (*goal: ‹<νx>P ∼ <νx>Q›*) let ?X = "{x. ∃P Q. P ∼ Q ∧ (∃a. x = (<νa>P, <νa>Q))}" from assms (*‹P ∼ Q›*) have "(<νx>P, <νx>Q) ∈ ?X" by blast thus "?thesis" (*goal: ‹<νx>P ∼ <νx>Q›*) proof (coinduct rule: bisimCoinduct) (*goals: 1. ‹⋀R S. (R, S) ∈ {x. ∃P Q. P ∼ Q ∧ (∃a. x = (<νa>P, <νa>Q))} ⟹ R ↝[({x. ∃P Q. P ∼ Q ∧ (∃a. x = (<νa>P, <νa>Q))} ∪ bisim)] S› 2. ‹⋀R S. (R, S) ∈ {x. ∃P Q. P ∼ Q ∧ (∃a. x = (<νa>P, <νa>Q))} ⟹ (S, R) ∈ {x. ∃P Q. P ∼ Q ∧ (∃a. x = (<νa>P, <νa>Q))}›*) case (cSim xP xQ) (*‹(xP, xQ) ∈ {x. ∃P Q. P ∼ Q ∧ (∃a. x = (<νa>P, <νa>Q))}›*) moreover { fix P and Q and a assume "P ∼ Q" (*‹(P::pi) ∼ (Q::pi)›*) hence "P ↝[bisim] Q" by (rule bisimE (*‹?P ∼ ?Q ⟹ ?P ↝[bisim] ?Q› ‹?P ∼ ?Q ⟹ ?Q ∼ ?P›*)) moreover have "⋀P Q a. P ∼ Q ⟹ (<νa>P, <νa>Q) ∈ ?X ∪ bisim" by blast moreover have "bisim ⊆ ?X ∪ bisim" by blast moreover have "eqvt bisim" by (rule eqvt (*‹eqvt bisim›*)) moreover have "eqvt (?X ∪ bisim)" using eqvts (*‹?p1 ∙ (?P1 ∼ ?Q1) = ?p1 ∙ ?P1 ∼ ?p1 ∙ ?Q1› ‹?P ∼ ?Q ⟹ ?p ∙ ?P ∼ ?p ∙ ?Q› ‹?pi1 ∙ ?x1.1 ⟼ ?x2.1 = ?pi1 ∙ ?x1.1 ⟼ ?pi1 ∙ ?x2.1› ‹?x1.0 ⟼ ?x2.0 ⟹ ?pi ∙ ?x1.0 ⟼ ?pi ∙ ?x2.0› ‹?pi ∙ ?x2.0 ≺ ?x1.0 = ?pi ∙ ?x2.0 ≺ ?pi ∙ ?x1.0› ‹?pi ∙ ?x3.0<ν?x1.0> ≺ ?x2.0 = (?pi ∙ ?x3.0)<ν(?pi ∙ ?x1.0)> ≺ (?pi ∙ ?x2.0)› ‹?pi ∙ τ = τ› ‹?pi ∙ ?x2.0[?x1.0] = (?pi ∙ ?x2.0)[(?pi ∙ ?x1.0)]› ‹(?pi::(name × name) list) ∙ (?x2.0::name)<(?x1.0::name)> = (?pi ∙ ?x2.0)<(?pi ∙ ?x1.0)>› ‹?p ∙ ?P[<?σ>] = (?p ∙ ?P)[<(?p ∙ ?σ)>]› ‹?p ∙ ?P[?a::=?b] = (?p ∙ ?P)[(?p ∙ ?a)::=(?p ∙ ?b)]› ‹?p ∙ ?a[?b::=?c] = (?p ∙ ?a)[(?p ∙ ?b)::=(?p ∙ ?c)]› and more 65 facts*) apply (auto simp add: eqvt_def (*‹eqvt ?Rel ≡ ∀x perma. x ∈ ?Rel ⟶ perma ∙ x ∈ ?Rel›*)) (*goal: ‹eqvt ({x::pi × pi. ∃(P::pi) Q::pi. P ∼ Q ∧ (∃a::name. x = (<νa>P, <νa>Q))} ∪ bisim)›*) by blast ultimately have "<νa>P ↝[(?X ∪ bisim)] <νa>Q" by (rule Strong_Early_Sim_Pres.resPres (*‹⟦?P ↝[?Rel] ?Q; ⋀R S y. (R, S) ∈ ?Rel ⟹ (<νy>R, <νy>S) ∈ ?Rel'; ?Rel ⊆ ?Rel'; eqvt ?Rel; eqvt ?Rel'⟧ ⟹ <ν?x>?P ↝[?Rel'] <ν?x>?Q›*)) } ultimately show "?case" (*goal: ‹xP ↝[({x. ∃P Q. P ∼ Q ∧ (∃a. x = (<νa>P, <νa>Q))} ∪ bisim)] xQ›*) by auto next (*goal: ‹⋀(R::pi) S::pi. (R, S) ∈ {x::pi × pi. ∃(P::pi) Q::pi. P ∼ Q ∧ (∃a::name. x = (<νa>P, <νa>Q))} ⟹ (S, R) ∈ {x::pi × pi. ∃(P::pi) Q::pi. P ∼ Q ∧ (∃a::name. x = (<νa>P, <νa>Q))}›*) case (cSym xP xQ) (*‹(xP, xQ) ∈ {x. ∃P Q. P ∼ Q ∧ (∃a. x = (<νa>P, <νa>Q))}›*) thus "?case" (*goal: ‹(xQ, xP) ∈ {x. ∃P Q. P ∼ Q ∧ (∃a. x = (<νa>P, <νa>Q))}›*) by (auto dest: bisimE (*‹?P ∼ ?Q ⟹ ?P ↝[bisim] ?Q› ‹?P ∼ ?Q ⟹ ?Q ∼ ?P›*)) qed qed lemma parPres: fixes P :: pi and Q :: pi and R :: pi and T :: pi assumes "P ∼ Q" shows "P ∥ R ∼ Q ∥ R" proof (-) (*goal: ‹P ∥ R ∼ Q ∥ R›*) let ?X = "{(resChain lst (P ∥ R), resChain lst (Q ∥ R)) | lst P Q R. P ∼ Q}" have BC: "⋀P Q. P ∥ Q = resChain [] (P ∥ Q)" by auto from assms (*‹P ∼ Q›*) have "(P ∥ R, Q ∥ R) ∈ ?X" by (blast intro: BC (*‹?P ∥ ?Q = resChain [] (?P ∥ ?Q)›*)) thus "?thesis" (*goal: ‹P ∥ R ∼ Q ∥ R›*) proof (coinduct rule: bisimWeakCoinduct) (*goals: 1. ‹⋀P Q. (P, Q) ∈ {(resChain lst (P ∥ R), resChain lst (Q ∥ R)) |lst P Q R. P ∼ Q} ⟹ P ↝[{(resChain lst (P ∥ R), resChain lst (Q ∥ R)) |lst P Q R. P ∼ Q}] Q› 2. ‹⋀P Q. (P, Q) ∈ {(resChain lst (P ∥ R), resChain lst (Q ∥ R)) |lst P Q R. P ∼ Q} ⟹ (Q, P) ∈ {(resChain lst (P ∥ R), resChain lst (Q ∥ R)) |lst P Q R. P ∼ Q}›*) case (cSim PR QR) (*‹(PR, QR) ∈ {(resChain lst (P ∥ R), resChain lst (Q ∥ R)) |lst P Q R. P ∼ Q}›*) moreover { fix lst and P and Q and R assume "P ∼ Q" (*‹(P::pi) ∼ (Q::pi)›*) have "eqvt ?X" using eqvts (*‹(?p1::(name × name) list) ∙ ((?P1::pi) ∼ (?Q1::pi)) = ?p1 ∙ ?P1 ∼ ?p1 ∙ ?Q1› ‹?P ∼ ?Q ⟹ ?p ∙ ?P ∼ ?p ∙ ?Q› ‹?pi1 ∙ ?x1.1 ⟼ ?x2.1 = ?pi1 ∙ ?x1.1 ⟼ ?pi1 ∙ ?x2.1› ‹?x1.0 ⟼ ?x2.0 ⟹ ?pi ∙ ?x1.0 ⟼ ?pi ∙ ?x2.0› ‹?pi ∙ ?x2.0 ≺ ?x1.0 = ?pi ∙ ?x2.0 ≺ ?pi ∙ ?x1.0› ‹?pi ∙ ?x3.0<ν?x1.0> ≺ ?x2.0 = (?pi ∙ ?x3.0)<ν(?pi ∙ ?x1.0)> ≺ (?pi ∙ ?x2.0)› ‹?pi ∙ τ = τ› ‹?pi ∙ ?x2.0[?x1.0] = (?pi ∙ ?x2.0)[(?pi ∙ ?x1.0)]› ‹?pi ∙ ?x2.0<?x1.0> = (?pi ∙ ?x2.0)<(?pi ∙ ?x1.0)>› ‹?p ∙ ?P[<?σ>] = (?p ∙ ?P)[<(?p ∙ ?σ)>]› ‹(?p::(name × name) list) ∙ (?P::pi)[(?a::name)::=(?b::name)] = (?p ∙ ?P)[(?p ∙ ?a)::=(?p ∙ ?b)]› ‹?p ∙ ?a[?b::=?c] = (?p ∙ ?a)[(?p ∙ ?b)::=(?p ∙ ?c)]› and more 65 facts*) apply (auto simp add: eqvt_def (*‹eqvt ?Rel ≡ ∀x perma. x ∈ ?Rel ⟶ perma ∙ x ∈ ?Rel›*)) (*goal: ‹eqvt {(resChain lst (P ∥ R), resChain lst (Q ∥ R)) |lst P Q R. P ∼ Q}›*) by blast moreover have Res: "⋀P Q x. (P, Q) ∈ ?X ⟹ (<νx>P, <νx>Q) ∈ ?X" apply auto (*goal: ‹⋀(P::pi) (Q::pi) x::name. (P, Q) ∈ {(resChain lst (P ∥ R), resChain lst (Q ∥ R)) |(lst::name list) (P::pi) (Q::pi) R::pi. P ∼ Q} ⟹ (<νx>P, <νx>Q) ∈ {(resChain lst (P ∥ R), resChain lst (Q ∥ R)) |(lst::name list) (P::pi) (Q::pi) R::pi. P ∼ Q}›*) apply (rule_tac x="x#lst" in exI (*‹?P ?x ⟹ ∃x. ?P x›*)) (*goal: ‹⋀x lst Pa Qa R. Pa ∼ Qa ⟹ ∃lsta P Q. (∃Ra. <νx>resChain lst (Pa ∥ R) = resChain lsta (P ∥ Ra) ∧ <νx>resChain lst (Qa ∥ R) = resChain lsta (Q ∥ Ra)) ∧ P ∼ Q›*) by auto moreover { from ‹P ∼ Q› (*‹P ∼ Q›*) have "P ↝[bisim] Q" by (rule bisimE (*‹?P ∼ ?Q ⟹ ?P ↝[bisim] ?Q› ‹?P ∼ ?Q ⟹ ?Q ∼ ?P›*)) moreover note ‹P ∼ Q› (*‹P ∼ Q›*) moreover have "⋀P Q R. P ∼ Q ⟹ (P ∥ R, Q ∥ R) ∈ ?X" by (blast intro: BC (*‹?P ∥ ?Q = resChain [] (?P ∥ ?Q)›*)) ultimately have "P ∥ R ↝[?X] Q ∥ R" using Res (*‹(?P, ?Q) ∈ {(resChain lst (P ∥ R), resChain lst (Q ∥ R)) |lst P Q R. P ∼ Q} ⟹ (<ν?x>?P, <ν?x>?Q) ∈ {(resChain lst (P ∥ R), resChain lst (Q ∥ R)) |lst P Q R. P ∼ Q}›*) apply (rule parPres (*‹⟦?P ↝[?Rel] ?Q; (?P, ?Q) ∈ ?Rel; ⋀S T U. (S, T) ∈ ?Rel ⟹ (S ∥ U, T ∥ U) ∈ ?Rel'; ⋀S T x. (S, T) ∈ ?Rel' ⟹ (<νx>S, <νx>T) ∈ ?Rel'⟧ ⟹ ?P ∥ ?R ↝[?Rel'] ?Q ∥ ?R›*)) (*goals: 1. ‹⋀S T U. S ∼ T ⟹ S ∼ T› 2. ‹⋀S T x. (S, T) ∈ {(resChain lst (P ∥ R), resChain lst (Q ∥ R)) |lst P Q R. P ∼ Q} ⟹ (S, T) ∈ {(resChain lst (P ∥ R), resChain lst (Q ∥ R)) |lst P Q R. P ∼ Q}› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) } ultimately have "resChain lst (P ∥ R) ↝[?X] resChain lst (Q ∥ R)" by (rule resChainI (*‹⟦eqvt ?Rel; ⋀R S x. (R, S) ∈ ?Rel ⟹ (<νx>R, <νx>S) ∈ ?Rel; ?P ↝[?Rel] ?Q⟧ ⟹ resChain ?lst ?P ↝[?Rel] resChain ?lst ?Q›*)) } ultimately show "?case" (*goal: ‹PR ↝[{(resChain lst (P ∥ R), resChain lst (Q ∥ R)) |lst P Q R. P ∼ Q}] QR›*) by auto next (*goal: ‹⋀P Q. (P, Q) ∈ {(resChain lst (P ∥ R), resChain lst (Q ∥ R)) |lst P Q R. P ∼ Q} ⟹ (Q, P) ∈ {(resChain lst (P ∥ R), resChain lst (Q ∥ R)) |lst P Q R. P ∼ Q}›*) case (cSym P Q) (*‹(P, Q) ∈ {(resChain lst (P ∥ R), resChain lst (Q ∥ R)) |lst P Q R. P ∼ Q}›*) thus "?case" (*goal: ‹(Q, P) ∈ {(resChain lst (P ∥ R), resChain lst (Q ∥ R)) |lst P Q R. P ∼ Q}›*) by (auto dest: bisimE (*‹(?P::pi) ∼ (?Q::pi) ⟹ ?P ↝[bisim] ?Q› ‹(?P::pi) ∼ (?Q::pi) ⟹ ?Q ∼ ?P›*)) qed qed lemma bangRelBisimE: fixes P :: pi and Q :: pi and Rel :: "(pi × pi) set" assumes A: "(P, Q) ∈ bangRel Rel" and Sym: "⋀P Q. (P, Q) ∈ Rel ⟹ (Q, P) ∈ Rel" shows "(Q, P) ∈ bangRel Rel" proof (-) (*goal: ‹(Q, P) ∈ bangRel Rel›*) from A (*‹(P, Q) ∈ bangRel Rel›*) show "?thesis" (*goal: ‹(Q::pi, P::pi) ∈ bangRel (Rel::(pi × pi) set)›*) proof (induct) (*goals: 1. ‹⋀P Q. (P, Q) ∈ Rel ⟹ (!Q, !P) ∈ bangRel Rel› 2. ‹⋀R T P Q. ⟦(R, T) ∈ Rel; (P, Q) ∈ bangRel Rel; (Q, P) ∈ bangRel Rel⟧ ⟹ (T ∥ Q, R ∥ P) ∈ bangRel Rel› 3. ‹⋀P Q a. ⟦(P, Q) ∈ bangRel Rel; (Q, P) ∈ bangRel Rel⟧ ⟹ (<νa>Q, <νa>P) ∈ bangRel Rel›*) fix P and Q assume "(P, Q) ∈ Rel" (*‹(P::pi, Q::pi) ∈ (Rel::(pi × pi) set)›*) hence "(Q, P) ∈ Rel" by (rule Sym (*‹(?P, ?Q) ∈ Rel ⟹ (?Q, ?P) ∈ Rel›*)) thus "(!Q, !P) ∈ bangRel Rel" by (rule BRBang (*‹(?P, ?Q) ∈ ?Rel ⟹ (!?P, !?Q) ∈ bangRel ?Rel›*)) next (*goals: 1. ‹⋀R T P Q. ⟦(R, T) ∈ Rel; (P, Q) ∈ bangRel Rel; (Q, P) ∈ bangRel Rel⟧ ⟹ (T ∥ Q, R ∥ P) ∈ bangRel Rel› 2. ‹⋀P Q a. ⟦(P, Q) ∈ bangRel Rel; (Q, P) ∈ bangRel Rel⟧ ⟹ (<νa>Q, <νa>P) ∈ bangRel Rel›*) fix P and Q and R and T assume RRelT: "(R, T) ∈ Rel" (*‹(R::pi, T::pi) ∈ (Rel::(pi × pi) set)›*) assume IH: "(Q, P) ∈ bangRel Rel" (*‹(Q::pi, P::pi) ∈ bangRel (Rel::(pi × pi) set)›*) from RRelT (*‹(R, T) ∈ Rel›*) have "(T, R) ∈ Rel" by (rule Sym (*‹(?P::pi, ?Q::pi) ∈ (Rel::(pi × pi) set) ⟹ (?Q, ?P) ∈ Rel›*)) thus "(T ∥ Q, R ∥ P) ∈ bangRel Rel" using IH (*‹(Q, P) ∈ bangRel Rel›*) by (rule BRPar (*‹⟦(?R, ?T) ∈ ?Rel; (?P, ?Q) ∈ bangRel ?Rel⟧ ⟹ (?R ∥ ?P, ?T ∥ ?Q) ∈ bangRel ?Rel›*)) next (*goal: ‹⋀P Q a. ⟦(P, Q) ∈ bangRel Rel; (Q, P) ∈ bangRel Rel⟧ ⟹ (<νa>Q, <νa>P) ∈ bangRel Rel›*) fix P and Q and a assume "(Q, P) ∈ bangRel Rel" (*‹(Q::pi, P::pi) ∈ bangRel (Rel::(pi × pi) set)›*) thus "(<νa>Q, <νa>P) ∈ bangRel Rel" by (rule BRRes (*‹(?P, ?Q) ∈ bangRel ?Rel ⟹ (<ν?a>?P, <ν?a>?Q) ∈ bangRel ?Rel›*)) qed qed lemma bangPres: fixes P :: pi and Q :: pi assumes PBiSimQ: "P ∼ Q" shows "!P ∼ !Q" proof (-) (*goal: ‹!P ∼ !Q›*) let ?X = "bangRel bisim" from PBiSimQ (*‹P ∼ Q›*) have "(!P, !Q) ∈ ?X" by (rule BRBang (*‹(?P, ?Q) ∈ ?Rel ⟹ (!?P, !?Q) ∈ bangRel ?Rel›*)) thus "?thesis" (*goal: ‹!P ∼ !Q›*) proof (coinduct rule: bisimWeakCoinduct) (*goals: 1. ‹⋀(P::pi) Q::pi. (P, Q) ∈ bangRel bisim ⟹ P ↝[bangRel bisim] Q› 2. ‹⋀(P::pi) Q::pi. (P, Q) ∈ bangRel bisim ⟹ (Q, P) ∈ bangRel bisim›*) case (cSim bP bQ) (*‹(bP, bQ) ∈ bangRel bisim›*) { fix P and Q assume "(P, Q) ∈ ?X" (*‹(P::pi, Q::pi) ∈ bangRel bisim›*) hence "P ↝[?X] Q" proof (induct) (*goals: 1. ‹⋀P Q. P ∼ Q ⟹ !P ↝[bangRel bisim] !Q› 2. ‹⋀R T P Q. ⟦R ∼ T; (P, Q) ∈ bangRel bisim; P ↝[bangRel bisim] Q⟧ ⟹ R ∥ P ↝[bangRel bisim] T ∥ Q› 3. ‹⋀P Q a. ⟦(P, Q) ∈ bangRel bisim; P ↝[bangRel bisim] Q⟧ ⟹ <νa>P ↝[bangRel bisim] <νa>Q›*) fix P and Q assume "P ∼ Q" (*‹(P::pi) ∼ (Q::pi)›*) thus "!P ↝[?X] !Q" using bisimE(1) (*‹?P ∼ ?Q ⟹ ?P ↝[bisim] ?Q›*) eqvt (*‹eqvt bisim›*) by (rule Strong_Early_Sim_Pres.bangPres (*‹⟦(?P::pi, ?Q::pi) ∈ (?Rel::(pi × pi) set); ⋀(R::pi) S::pi. (R, S) ∈ ?Rel ⟹ R ↝[?Rel] S; eqvt ?Rel⟧ ⟹ !?P ↝[bangRel ?Rel] !?Q›*)) next (*goals: 1. ‹⋀R T P Q. ⟦R ∼ T; (P, Q) ∈ bangRel bisim; P ↝[bangRel bisim] Q⟧ ⟹ R ∥ P ↝[bangRel bisim] T ∥ Q› 2. ‹⋀P Q a. ⟦(P, Q) ∈ bangRel bisim; P ↝[bangRel bisim] Q⟧ ⟹ <νa>P ↝[bangRel bisim] <νa>Q›*) fix P and Q and R and T assume RBiSimT: "R ∼ T" (*‹(R::pi) ∼ (T::pi)›*) assume PBangRelQ: "(P, Q) ∈ ?X" (*‹(P::pi, Q::pi) ∈ bangRel bisim›*) assume PSimQ: "P ↝[?X] Q" (*‹(P::pi) ↝[bangRel bisim] (Q::pi)›*) from RBiSimT (*‹R ∼ T›*) have "R ↝[bisim] T" by (blast dest: bisimE (*‹?P ∼ ?Q ⟹ ?P ↝[bisim] ?Q› ‹?P ∼ ?Q ⟹ ?Q ∼ ?P›*)) thus "R ∥ P ↝[?X] T ∥ Q" using PSimQ (*‹P ↝[bangRel bisim] Q›*) RBiSimT (*‹R ∼ T›*) PBangRelQ (*‹(P::pi, Q::pi) ∈ bangRel bisim›*) BRPar (*‹⟦(?R, ?T) ∈ ?Rel; (?P, ?Q) ∈ bangRel ?Rel⟧ ⟹ (?R ∥ ?P, ?T ∥ ?Q) ∈ bangRel ?Rel›*) BRRes (*‹(?P, ?Q) ∈ bangRel ?Rel ⟹ (<ν?a>?P, <ν?a>?Q) ∈ bangRel ?Rel›*) eqvt (*‹eqvt bisim›*) eqvtBangRel (*‹eqvt (?Rel::(pi × pi) set) ⟹ eqvt (bangRel ?Rel)›*) by (blast intro: Strong_Early_Sim_Pres.parCompose (*‹⟦?P ↝[?Rel] ?Q; ?R ↝[?Rel'] ?S; (?P, ?Q) ∈ ?Rel; (?R, ?S) ∈ ?Rel'; ⋀P' Q' R' S'. ⟦(P', Q') ∈ ?Rel; (R', S') ∈ ?Rel'⟧ ⟹ (P' ∥ R', Q' ∥ S') ∈ ?Rel''; ⋀S T x. (S, T) ∈ ?Rel'' ⟹ (<νx>S, <νx>T) ∈ ?Rel''⟧ ⟹ ?P ∥ ?R ↝[?Rel''] ?Q ∥ ?S›*)) next (*goal: ‹⋀P Q a. ⟦(P, Q) ∈ bangRel bisim; P ↝[bangRel bisim] Q⟧ ⟹ <νa>P ↝[bangRel bisim] <νa>Q›*) fix P and Q and a assume "P ↝[?X] Q" (*‹(P::pi) ↝[bangRel bisim] (Q::pi)›*) moreover from eqvtBangRel (*‹eqvt ?Rel ⟹ eqvt (bangRel ?Rel)›*) eqvt (*‹eqvt bisim›*) have "eqvt ?X" by blast ultimately show "<νa>P ↝[?X] <νa>Q" using BRRes (*‹(?P, ?Q) ∈ bangRel ?Rel ⟹ (<ν?a>?P, <ν?a>?Q) ∈ bangRel ?Rel›*) by (blast intro: Strong_Early_Sim_Pres.resPres (*‹⟦?P ↝[?Rel] ?Q; ⋀R S y. (R, S) ∈ ?Rel ⟹ (<νy>R, <νy>S) ∈ ?Rel'; ?Rel ⊆ ?Rel'; eqvt ?Rel; eqvt ?Rel'⟧ ⟹ <ν?x>?P ↝[?Rel'] <ν?x>?Q›*)) qed } with ‹(bP, bQ) ∈ ?X› (*‹(bP, bQ) ∈ bangRel bisim›*) show "?case" (*goal: ‹bP ↝[bangRel bisim] bQ›*) by blast next (*goal: ‹⋀P Q. (P, Q) ∈ bangRel bisim ⟹ (Q, P) ∈ bangRel bisim›*) case (cSym bP bQ) (*‹(bP, bQ) ∈ bangRel bisim›*) thus "?case" (*goal: ‹(bQ::pi, bP::pi) ∈ bangRel bisim›*) by (metis bangRelSymetric (*‹⟦(?P, ?Q) ∈ bangRel ?Rel; ⋀P Q. (P, Q) ∈ ?Rel ⟹ (Q, P) ∈ ?Rel⟧ ⟹ (?Q, ?P) ∈ bangRel ?Rel›*) bisimE (*‹?P ∼ ?Q ⟹ ?P ↝[bisim] ?Q› ‹?P ∼ ?Q ⟹ ?Q ∼ ?P›*)) qed qed end
{ "path": "afp-2025-02-12/thys/Pi_Calculus/Strong_Early_Bisim_Pres.thy", "repo": "afp-2025-02-12", "sha": "7f1697498a0eb757420b9da7f7b05ce3f185bd5bb467fa5d6b46dd04a89691cb" }
theory Uncertainty_Principle imports "QHLProver.Complex_Matrix" begin section‹Setup› abbreviation bra_ket ("⟨_|_⟩") where "⟨u|v⟩ ≡ inner_prod u v" text‹Fix an n-dimensional normalized quantum state $\psi$.› locale quantum_state = fixes n:: nat and ψ:: "complex Matrix.vec" assumes dim[simp]: "ψ ∈ carrier_vec n" and normalized[simp]: "⟨ψ|ψ⟩ = 1" begin text‹Observables on $\psi$ are hermitian matrices of appropriate dimensions.› abbreviation observable:: "complex Matrix.mat ⇒ bool" where "observable A ≡ A ∈ carrier_mat n n ∧ hermitian A" text‹ The mean value of an observable A is defined as $\langle \psi | A | \psi \rangle$. It is useful to have a scalar matrix of appropriate dimension containing this value. On paper, this is usually implicit. › abbreviation mean_mat :: "complex Matrix.mat ⇒ complex Matrix.mat" ("⟪_⟫") where "⟪A⟫ ≡ ⟨ψ| A *⇩v ψ⟩ ⋅⇩m 1⇩m n" text‹ The standard deviation of an observable A = $\sqrt {\langle \psi | A^2 | \psi \rangle - \langle \psi | A | \psi \rangle^2}$. Since the standard deviation is real (see lemma std-dev-real), we can define it as being of type real using norm. This simultaneously restricts it to positive values. (powers of two are expanded for simplicity) › abbreviation std_dev :: "complex Matrix.mat ⇒ real" ("Δ") where "Δ A ≡ norm (csqrt (⟨ψ| (A * A *⇩v ψ)⟩ - ⟨ψ| A *⇩v ψ⟩ * ⟨ψ| A *⇩v ψ⟩))" end abbreviation commutator :: "complex Matrix.mat ⇒ complex Matrix.mat ⇒ complex Matrix.mat" ("⟦_,_⟧") where "commutator A B ≡ (A * B - B * A)" abbreviation anticommutator :: "complex Matrix.mat ⇒ complex Matrix.mat ⇒ complex Matrix.mat" ("⦃_,_⦄") where "anticommutator A B ≡ (A * B + B * A)" section‹Auxiliary Lemmas› lemma inner_prod_distrib_add_mat: fixes u v :: "complex vec" assumes "u ∈ carrier_vec n" "v ∈ carrier_vec m" "A ∈ carrier_mat n m" "B ∈ carrier_mat n m" shows "⟨u| (A + B) *⇩v v⟩ = ⟨u| A *⇩v v⟩ + ⟨u| B *⇩v v⟩" apply (subst add_mult_distrib_mat_vec (*‹⟦?A ∈ carrier_mat ?nr ?nc; ?B ∈ carrier_mat ?nr ?nc; ?v ∈ carrier_vec ?nc⟧ ⟹ (?A + ?B) *⇩v ?v = ?A *⇩v ?v + ?B *⇩v ?v›*)) (*goal: ‹⟨u|(A + B) *⇩v v⟩ = ⟨u|A *⇩v v⟩ + ⟨u|B *⇩v v⟩›*) using assms (*‹u ∈ carrier_vec n› ‹v ∈ carrier_vec m› ‹A ∈ carrier_mat n m› ‹B ∈ carrier_mat n m›*) apply - (*goals: 1. ‹⟦u ∈ carrier_vec n; v ∈ carrier_vec m; A ∈ carrier_mat n m; B ∈ carrier_mat n m⟧ ⟹ A ∈ carrier_mat ?nr ?nc› 2. ‹⟦u ∈ carrier_vec n; v ∈ carrier_vec m; A ∈ carrier_mat n m; B ∈ carrier_mat n m⟧ ⟹ B ∈ carrier_mat ?nr ?nc› 3. ‹⟦u ∈ carrier_vec n; v ∈ carrier_vec m; A ∈ carrier_mat n m; B ∈ carrier_mat n m⟧ ⟹ v ∈ carrier_vec ?nc› 4. ‹⟦u ∈ carrier_vec n; v ∈ carrier_vec m; A ∈ carrier_mat n m; B ∈ carrier_mat n m⟧ ⟹ ⟨u|A *⇩v v + B *⇩v v⟩ = ⟨u|A *⇩v v⟩ + ⟨u|B *⇩v v⟩› discuss goal 1*) apply ((auto intro: inner_prod_distrib_right (*‹⟦?u ∈ carrier_vec ?n; ?v ∈ carrier_vec ?n; ?w ∈ carrier_vec ?n⟧ ⟹ ⟨?u|?v + ?w⟩ = ⟨?u|?v⟩ + ⟨?u|?w⟩›*))[1]) (*discuss goal 2*) apply ((auto intro: inner_prod_distrib_right (*‹⟦?u ∈ carrier_vec ?n; ?v ∈ carrier_vec ?n; ?w ∈ carrier_vec ?n⟧ ⟹ ⟨?u|?v + ?w⟩ = ⟨?u|?v⟩ + ⟨?u|?w⟩›*))[1]) (*discuss goal 3*) apply ((auto intro: inner_prod_distrib_right (*‹⟦(?u::?'a::conjugatable_field vec) ∈ carrier_vec (?n::nat); (?v::?'a::conjugatable_field vec) ∈ carrier_vec ?n; (?w::?'a::conjugatable_field vec) ∈ carrier_vec ?n⟧ ⟹ ⟨?u|?v + ?w⟩ = ⟨?u|?v⟩ + ⟨?u|?w⟩›*))[1]) (*discuss goal 4*) apply ((auto intro: inner_prod_distrib_right (*‹⟦?u ∈ carrier_vec ?n; ?v ∈ carrier_vec ?n; ?w ∈ carrier_vec ?n⟧ ⟹ ⟨?u|?v + ?w⟩ = ⟨?u|?v⟩ + ⟨?u|?w⟩›*))[1]) (*proven 4 subgoals*) . lemma inner_prod_distrib_minus_mat: fixes u v :: "complex vec" assumes "u ∈ carrier_vec n" "v ∈ carrier_vec m" "A ∈ carrier_mat n m" "B ∈ carrier_mat n m" shows "⟨u| (A - B) *⇩v v⟩ = ⟨u| A *⇩v v⟩ - ⟨u| B *⇩v v⟩" apply (subst minus_mult_distrib_mat_vec (*‹⟦?A ∈ carrier_mat ?nr ?nc; ?B ∈ carrier_mat ?nr ?nc; ?v ∈ carrier_vec ?nc⟧ ⟹ (?A - ?B) *⇩v ?v = ?A *⇩v ?v - ?B *⇩v ?v›*)) (*goal: ‹⟨u|(A - B) *⇩v v⟩ = ⟨u|A *⇩v v⟩ - ⟨u|B *⇩v v⟩›*) using assms (*‹u ∈ carrier_vec n› ‹v ∈ carrier_vec m› ‹A ∈ carrier_mat n m› ‹B ∈ carrier_mat n m›*) apply - (*goals: 1. ‹⟦u ∈ carrier_vec n; v ∈ carrier_vec m; A ∈ carrier_mat n m; B ∈ carrier_mat n m⟧ ⟹ A ∈ carrier_mat ?nr ?nc› 2. ‹⟦u ∈ carrier_vec n; v ∈ carrier_vec m; A ∈ carrier_mat n m; B ∈ carrier_mat n m⟧ ⟹ B ∈ carrier_mat ?nr ?nc› 3. ‹⟦u ∈ carrier_vec n; v ∈ carrier_vec m; A ∈ carrier_mat n m; B ∈ carrier_mat n m⟧ ⟹ v ∈ carrier_vec ?nc› 4. ‹⟦u ∈ carrier_vec n; v ∈ carrier_vec m; A ∈ carrier_mat n m; B ∈ carrier_mat n m⟧ ⟹ ⟨u|A *⇩v v - B *⇩v v⟩ = ⟨u|A *⇩v v⟩ - ⟨u|B *⇩v v⟩› discuss goal 1*) apply ((auto intro: inner_prod_minus_distrib_right (*‹⟦?u ∈ carrier_vec ?n; ?v ∈ carrier_vec ?n; ?w ∈ carrier_vec ?n⟧ ⟹ ⟨?u|?v - ?w⟩ = ⟨?u|?v⟩ - ⟨?u|?w⟩›*))[1]) (*discuss goal 2*) apply ((auto intro: inner_prod_minus_distrib_right (*‹⟦?u ∈ carrier_vec ?n; ?v ∈ carrier_vec ?n; ?w ∈ carrier_vec ?n⟧ ⟹ ⟨?u|?v - ?w⟩ = ⟨?u|?v⟩ - ⟨?u|?w⟩›*))[1]) (*discuss goal 3*) apply ((auto intro: inner_prod_minus_distrib_right (*‹⟦?u ∈ carrier_vec ?n; ?v ∈ carrier_vec ?n; ?w ∈ carrier_vec ?n⟧ ⟹ ⟨?u|?v - ?w⟩ = ⟨?u|?v⟩ - ⟨?u|?w⟩›*))[1]) (*discuss goal 4*) apply ((auto intro: inner_prod_minus_distrib_right (*‹⟦?u ∈ carrier_vec ?n; ?v ∈ carrier_vec ?n; ?w ∈ carrier_vec ?n⟧ ⟹ ⟨?u|?v - ?w⟩ = ⟨?u|?v⟩ - ⟨?u|?w⟩›*))[1]) (*proven 4 subgoals*) . text‹Proving the usual Cauchy-Schwarz inequality using its formulation for complex vector spaces.› lemma Cauchy_Schwarz: assumes "v ∈ carrier_vec n" "u ∈ carrier_vec n" shows "norm (⟨u|v⟩)^2 ≤ Re (⟨u|u⟩ * ⟨v|v⟩)" proof (-) (*goal: ‹(cmod ⟨u|v⟩)² ≤ Re (⟨u|u⟩ * ⟨v|v⟩)›*) have "norm (⟨u|v⟩)^2 ≤ (⟨u|u⟩ * ⟨v|v⟩)" using assms (*‹v ∈ carrier_vec n› ‹u ∈ carrier_vec n›*) by (metis Cauchy_Schwarz_complex_vec (*‹⟦?x ∈ carrier_vec ?n; ?y ∈ carrier_vec ?n⟧ ⟹ ⟨?x|?y⟩ * ⟨?y|?x⟩ ≤ ⟨?x|?x⟩ * ⟨?y|?y⟩›*) complex_norm_square (*‹complex_of_real ((cmod ?z)²) = ?z * cnj ?z›*) conjugate_complex_def (*‹conjugate ≡ cnj›*) inner_prod_swap (*‹⟦?y ∈ carrier_vec ?n; ?x ∈ carrier_vec ?n⟧ ⟹ ⟨?y|?x⟩ = conjugate ⟨?x|?y⟩›*)) moreover have "(⟨u|u⟩ * ⟨v|v⟩) ∈ ℝ" by (simp add: complex_is_Real_iff (*‹((?z::complex) ∈ ℝ) = (Im ?z = (0::real))›*)) ultimately show "?thesis" (*goal: ‹(cmod ⟨u::complex vec|v::complex vec⟩)² ≤ Re (⟨u|u⟩ * ⟨v|v⟩)›*) by (simp add: less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) qed context quantum_state begin text‹Show that the the standard deviation yields a real value. This justifies our definition in terms of the norm.› lemma std_dev_real: assumes "observable A" shows "csqrt (⟨ψ| (A * A *⇩v ψ)⟩ - ⟨ψ| A *⇩v ψ⟩ * ⟨ψ| A *⇩v ψ⟩) ∈ ℝ" proof (subst csqrt_of_real_nonneg (*‹⟦Im ?x = 0; 0 ≤ Re ?x⟧ ⟹ csqrt ?x = complex_of_real (sqrt (Re ?x))›*)) (*goals: 1. ‹Im (⟨ψ|A * A *⇩v ψ⟩ - ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩) = 0› 2. ‹0 ≤ Re (⟨ψ|A * A *⇩v ψ⟩ - ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩)› 3. ‹complex_of_real (sqrt (Re (⟨ψ|A * A *⇩v ψ⟩ - ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩))) ∈ ℝ›*) have "(⟨ψ|A * A *⇩v ψ⟩ - ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩) ∈ ℝ" apply (intro Reals_diff (*‹⟦?a ∈ ℝ; ?b ∈ ℝ⟧ ⟹ ?a - ?b ∈ ℝ›*) Reals_mult (*‹⟦?a ∈ ℝ; ?b ∈ ℝ⟧ ⟹ ?a * ?b ∈ ℝ›*) hermitian_inner_prod_real (*‹⟦?A ∈ carrier_mat ?n ?n; ?v ∈ carrier_vec ?n; hermitian ?A⟧ ⟹ ⟨?v|?A *⇩v ?v⟩ ∈ ℝ›*)) (*goal: ‹⟨ψ|A * A *⇩v ψ⟩ - ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩ ∈ ℝ›*) using assms (*‹observable A›*) by (auto simp: hermitian_def (*‹hermitian ?A = (adjoint ?A = ?A)›*) adjoint_mult (*‹⟦?A ∈ carrier_mat ?n ?m; ?B ∈ carrier_mat ?m ?l⟧ ⟹ adjoint (?A * ?B) = adjoint ?B * adjoint ?A›*)) then show "Im (⟨ψ|A * A *⇩v ψ⟩ - ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩) = 0" using complex_is_Real_iff (*‹(?z ∈ ℝ) = (Im ?z = 0)›*) by simp next (*goals: 1. ‹0 ≤ Re (⟨ψ|A * A *⇩v ψ⟩ - ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩)› 2. ‹complex_of_real (sqrt (Re (⟨ψ|A * A *⇩v ψ⟩ - ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩))) ∈ ℝ›*) have "*": "adjoint A = A" using assms (*‹observable A›*) hermitian_def (*‹hermitian ?A = (adjoint ?A = ?A)›*) by blast have "⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩ ≤ ⟨ψ|ψ⟩ * ⟨ψ|A * A *⇩v ψ⟩" apply (subst assoc_mult_mat_vec (*‹⟦(?A::?'a mat) ∈ carrier_mat (?n₁::nat) (?n₂::nat); (?B::?'a mat) ∈ carrier_mat ?n₂ (?n₃::nat); (?v::?'a vec) ∈ carrier_vec ?n₃⟧ ⟹ ?A * ?B *⇩v ?v = ?A *⇩v (?B *⇩v ?v)›*)) (*goal: ‹⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩ ≤ ⟨ψ|ψ⟩ * ⟨ψ|A * A *⇩v ψ⟩›*) prefer 4 (*top goal: ‹⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩ ≤ ⟨ψ|ψ⟩ * ⟨ψ|A *⇩v (A *⇩v ψ)⟩› and 3 goals remain*) apply (subst (2) adjoint_def_alter (*‹⟦?v ∈ carrier_vec ?n; ?w ∈ carrier_vec ?m; ?A ∈ carrier_mat ?n ?m⟧ ⟹ ⟨?v|?A *⇩v ?w⟩ = ⟨adjoint ?A *⇩v ?v|?w⟩›*)) (*top goal: ‹⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩ ≤ ⟨ψ|ψ⟩ * ⟨ψ|A *⇩v (A *⇩v ψ)⟩› and 3 goals remain*) prefer 4 (*top goal: ‹⟨ψ::complex vec|(A::complex mat) *⇩v ψ⟩ * ⟨adjoint A *⇩v ψ|ψ⟩ ≤ ⟨ψ|ψ⟩ * ⟨ψ|A *⇩v (A *⇩v ψ)⟩› and 6 goals remain*) apply (subst (2) adjoint_def_alter (*‹⟦?v ∈ carrier_vec ?n; ?w ∈ carrier_vec ?m; ?A ∈ carrier_mat ?n ?m⟧ ⟹ ⟨?v|?A *⇩v ?w⟩ = ⟨adjoint ?A *⇩v ?v|?w⟩›*)) (*top goal: ‹⟨ψ|A *⇩v ψ⟩ * ⟨adjoint A *⇩v ψ|ψ⟩ ≤ ⟨ψ|ψ⟩ * ⟨ψ|A *⇩v (A *⇩v ψ)⟩› and 6 goals remain*) prefer 4 (*top goal: ‹⟨ψ::complex vec|(A::complex mat) *⇩v ψ⟩ * ⟨adjoint A *⇩v ψ|ψ⟩ ≤ ⟨ψ|ψ⟩ * ⟨adjoint A *⇩v ψ|A *⇩v ψ⟩› and 9 goals remain*) apply (subst (1 2) * (*‹adjoint A = A›*)) (*top goal: ‹⟨ψ|A *⇩v ψ⟩ * ⟨adjoint A *⇩v ψ|ψ⟩ ≤ ⟨ψ|ψ⟩ * ⟨adjoint A *⇩v ψ|A *⇩v ψ⟩› and 9 goals remain*) apply (rule Cauchy_Schwarz_complex_vec[OF dim] (*‹(?y::complex vec) ∈ carrier_vec (n::nat) ⟹ ⟨ψ::complex vec|?y⟩ * ⟨?y|ψ⟩ ≤ ⟨ψ|ψ⟩ * ⟨?y|?y⟩›*)) (*top goal: ‹⟨ψ|A *⇩v ψ⟩ * ⟨A *⇩v ψ|ψ⟩ ≤ ⟨ψ|ψ⟩ * ⟨A *⇩v ψ|A *⇩v ψ⟩› and 9 goals remain*) using assms (*‹observable A›*) by auto then show "0 ≤ Re (⟨ψ|A * A *⇩v ψ⟩ - ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩)" by (simp add: less_eq_complex_def (*‹((?x::complex) ≤ (?y::complex)) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) qed (simp) (*solved the remaining goal: ‹complex_of_real (sqrt (Re (⟨ψ|A * A *⇩v ψ⟩ - ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩))) ∈ ℝ›*) text‹This is an alternative way of formulating the standard deviation.› lemma std_dev_alt: assumes "observable A" shows "Δ A = norm (csqrt (⟨ψ| (A - ⟪A⟫) * (A - ⟪A⟫) *⇩v ψ⟩))" proof (-) (*goal: ‹cmod (csqrt (⟨ψ|A * A *⇩v ψ⟩ - ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩)) = cmod (csqrt ⟨ψ|(A - ⟪A⟫) * (A - ⟪A⟫) *⇩v ψ⟩)›*) have "(A - ⟪A⟫) * (A - ⟪A⟫) = (A + - ⟪A⟫) * (A + - ⟪A⟫)" using assms (*‹observable A›*) minus_add_uminus_mat (*‹⟦?A ∈ carrier_mat ?nr ?nc; ?B ∈ carrier_mat ?nr ?nc⟧ ⟹ ?A - ?B = ?A + - ?B›*) by force also (*calculation: ‹(A - ⟪A⟫) * (A - ⟪A⟫) = (A + - ⟪A⟫) * (A + - ⟪A⟫)›*) have "*": "... = A * A + A * - ⟪A⟫ + - ⟪A⟫ * A + - ⟪A⟫ * - ⟪A⟫" apply (mat_assoc n) (*goal: ‹(A + - ⟪A⟫) * (A + - ⟪A⟫) = A * A + A * - ⟪A⟫ + - ⟪A⟫ * A + - ⟪A⟫ * - ⟪A⟫›*) using assms (*‹observable A›*) apply - (*goals: 1. ‹observable A ⟹ 1⇩m n ∈ carrier_mat n n› 2. ‹observable A ⟹ A ∈ carrier_mat n n› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . also (*calculation: ‹((A::complex mat) - ⟪A⟫) * (A - ⟪A⟫) = A * A + A * - ⟪A⟫ + - ⟪A⟫ * A + - ⟪A⟫ * - ⟪A⟫›*) have "... = A * A - ⟪A⟫ * A - ⟪A⟫ * A + ⟪A⟫ * ⟪A⟫" using uminus_mult_right_mat (*‹dim_col (?A::?'a::ring mat) = dim_row (?B::?'a::ring mat) ⟹ ?A * - ?B = - (?A * ?B)›*) assms (*‹observable A›*) by auto also (*calculation: ‹(A - ⟪A⟫) * (A - ⟪A⟫) = A * A - ⟪A⟫ * A - ⟪A⟫ * A + ⟪A⟫ * ⟪A⟫›*) have "... = A * A - ⟨ψ| A *⇩v ψ⟩ ⋅⇩m A - ⟨ψ| A *⇩v ψ⟩ ⋅⇩m A + ⟪A⟫ * ⟪A⟫" using assms (*‹observable (A::complex mat)›*) by auto finally (*calculation: ‹(A - ⟪A⟫) * (A - ⟪A⟫) = A * A - ⟨ψ|A *⇩v ψ⟩ ⋅⇩m A - ⟨ψ|A *⇩v ψ⟩ ⋅⇩m A + ⟪A⟫ * ⟪A⟫›*) have 1: "⟨ψ| (A - ⟪A⟫) * (A - ⟪A⟫) *⇩v ψ⟩ = ⟨ψ| (A * A - ⟨ψ| A *⇩v ψ⟩ ⋅⇩m A - ⟨ψ| A *⇩v ψ⟩ ⋅⇩m A + ⟪A⟫ * ⟪A⟫) *⇩v ψ⟩" by simp have 2: "⟨ψ| (A * A - ⟨ψ| A *⇩v ψ⟩ ⋅⇩m A - ⟨ψ| A *⇩v ψ⟩ ⋅⇩m A + ⟪A⟫ * ⟪A⟫) *⇩v ψ⟩ = ⟨ψ|A * A *⇩v ψ⟩ - ⟨ψ|⟨ψ|A *⇩v ψ⟩ ⋅⇩m A *⇩v ψ⟩ - ⟨ψ|⟨ψ|A *⇩v ψ⟩ ⋅⇩m A *⇩v ψ⟩ + ⟨ψ|⟪A⟫ * ⟪A⟫ *⇩v ψ⟩" apply (subst inner_prod_distrib_add_mat (*‹⟦?u ∈ carrier_vec ?n; ?v ∈ carrier_vec ?m; ?A ∈ carrier_mat ?n ?m; ?B ∈ carrier_mat ?n ?m⟧ ⟹ ⟨?u|(?A + ?B) *⇩v ?v⟩ = ⟨?u|?A *⇩v ?v⟩ + ⟨?u|?B *⇩v ?v⟩›*)) (*goal: ‹⟨ψ|(A * A - ⟨ψ|A *⇩v ψ⟩ ⋅⇩m A - ⟨ψ|A *⇩v ψ⟩ ⋅⇩m A + ⟪A⟫ * ⟪A⟫) *⇩v ψ⟩ = ⟨ψ|A * A *⇩v ψ⟩ - ⟨ψ|⟨ψ|A *⇩v ψ⟩ ⋅⇩m A *⇩v ψ⟩ - ⟨ψ|⟨ψ|A *⇩v ψ⟩ ⋅⇩m A *⇩v ψ⟩ + ⟨ψ|⟪A⟫ * ⟪A⟫ *⇩v ψ⟩›*) prefer 5 (*top goal: ‹⟨ψ|(A * A - ⟨ψ|A *⇩v ψ⟩ ⋅⇩m A - ⟨ψ|A *⇩v ψ⟩ ⋅⇩m A) *⇩v ψ⟩ + ⟨ψ|⟪A⟫ * ⟪A⟫ *⇩v ψ⟩ = ⟨ψ|A * A *⇩v ψ⟩ - ⟨ψ|⟨ψ|A *⇩v ψ⟩ ⋅⇩m A *⇩v ψ⟩ - ⟨ψ|⟨ψ|A *⇩v ψ⟩ ⋅⇩m A *⇩v ψ⟩ + ⟨ψ|⟪A⟫ * ⟪A⟫ *⇩v ψ⟩› and 4 goals remain*) apply (subst inner_prod_distrib_minus_mat (*‹⟦?u ∈ carrier_vec ?n; ?v ∈ carrier_vec ?m; ?A ∈ carrier_mat ?n ?m; ?B ∈ carrier_mat ?n ?m⟧ ⟹ ⟨?u|(?A - ?B) *⇩v ?v⟩ = ⟨?u|?A *⇩v ?v⟩ - ⟨?u|?B *⇩v ?v⟩›*)) (*top goal: ‹⟨ψ|(A * A - ⟨ψ|A *⇩v ψ⟩ ⋅⇩m A - ⟨ψ|A *⇩v ψ⟩ ⋅⇩m A) *⇩v ψ⟩ + ⟨ψ|⟪A⟫ * ⟪A⟫ *⇩v ψ⟩ = ⟨ψ|A * A *⇩v ψ⟩ - ⟨ψ|⟨ψ|A *⇩v ψ⟩ ⋅⇩m A *⇩v ψ⟩ - ⟨ψ|⟨ψ|A *⇩v ψ⟩ ⋅⇩m A *⇩v ψ⟩ + ⟨ψ|⟪A⟫ * ⟪A⟫ *⇩v ψ⟩› and 4 goals remain*) prefer 5 (*top goal: ‹⟨ψ::complex vec|((A::complex mat) * A - ⟨ψ|A *⇩v ψ⟩ ⋅⇩m A) *⇩v ψ⟩ - ⟨ψ|⟨ψ|A *⇩v ψ⟩ ⋅⇩m A *⇩v ψ⟩ + ⟨ψ|⟪A⟫ * ⟪A⟫ *⇩v ψ⟩ = ⟨ψ|A * A *⇩v ψ⟩ - ⟨ψ|⟨ψ|A *⇩v ψ⟩ ⋅⇩m A *⇩v ψ⟩ - ⟨ψ|⟨ψ|A *⇩v ψ⟩ ⋅⇩m A *⇩v ψ⟩ + ⟨ψ|⟪A⟫ * ⟪A⟫ *⇩v ψ⟩› and 8 goals remain*) apply (subst inner_prod_distrib_minus_mat (*‹⟦?u ∈ carrier_vec ?n; ?v ∈ carrier_vec ?m; ?A ∈ carrier_mat ?n ?m; ?B ∈ carrier_mat ?n ?m⟧ ⟹ ⟨?u|(?A - ?B) *⇩v ?v⟩ = ⟨?u|?A *⇩v ?v⟩ - ⟨?u|?B *⇩v ?v⟩›*)) (*top goal: ‹⟨ψ|(A * A - ⟨ψ|A *⇩v ψ⟩ ⋅⇩m A) *⇩v ψ⟩ - ⟨ψ|⟨ψ|A *⇩v ψ⟩ ⋅⇩m A *⇩v ψ⟩ + ⟨ψ|⟪A⟫ * ⟪A⟫ *⇩v ψ⟩ = ⟨ψ|A * A *⇩v ψ⟩ - ⟨ψ|⟨ψ|A *⇩v ψ⟩ ⋅⇩m A *⇩v ψ⟩ - ⟨ψ|⟨ψ|A *⇩v ψ⟩ ⋅⇩m A *⇩v ψ⟩ + ⟨ψ|⟪A⟫ * ⟪A⟫ *⇩v ψ⟩› and 8 goals remain*) using assms (*‹observable A›*) by auto have 3: "⟨ψ|⟨ψ|A *⇩v ψ⟩ ⋅⇩m A *⇩v ψ⟩ = ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩" by (metis assms (*‹observable A›*) dim (*‹ψ ∈ carrier_vec n›*) inner_prod_smult_left (*‹⟦?u ∈ carrier_vec ?n; ?v ∈ carrier_vec ?n⟧ ⟹ ⟨?u|?a ⋅⇩v ?v⟩ = ?a * ⟨?u|?v⟩›*) mult_mat_vec_carrier (*‹⟦?A ∈ carrier_mat ?nr ?n; ?v ∈ carrier_vec ?n⟧ ⟹ ?A *⇩v ?v ∈ carrier_vec ?nr›*) smult_mat_mult_mat_vec_assoc (*‹⟦?A ∈ carrier_mat ?n ?m; ?w ∈ carrier_vec ?m⟧ ⟹ ?a ⋅⇩m ?A *⇩v ?w = ?a ⋅⇩v (?A *⇩v ?w)›*)) have "⟨ψ|⟪A⟫ * ⟪A⟫ *⇩v ψ⟩ = ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|⟪A⟫ *⇩v ψ⟩" apply (subst mult_smult_assoc_mat (*‹⟦?A ∈ carrier_mat ?nr ?n; ?B ∈ carrier_mat ?n ?nc⟧ ⟹ ?k ⋅⇩m ?A * ?B = ?k ⋅⇩m (?A * ?B)›*)) (*goal: ‹⟨ψ::complex vec|⟪A::complex mat⟫ * ⟪A⟫ *⇩v ψ⟩ = ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|⟪A⟫ *⇩v ψ⟩›*) prefer 3 (*top goal: ‹⟨ψ::complex vec|⟨ψ|(A::complex mat) *⇩v ψ⟩ ⋅⇩m (1⇩m (n::nat) * ⟪A⟫) *⇩v ψ⟩ = ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|⟪A⟫ *⇩v ψ⟩› and 2 goals remain*) apply (subst smult_mat_mult_mat_vec_assoc (*‹⟦(?A::?'a mat) ∈ carrier_mat (?n::nat) (?m::nat); (?w::?'a vec) ∈ carrier_vec ?m⟧ ⟹ (?a::?'a) ⋅⇩m ?A *⇩v ?w = ?a ⋅⇩v (?A *⇩v ?w)›*)) (*top goal: ‹⟨ψ::complex vec|⟨ψ|(A::complex mat) *⇩v ψ⟩ ⋅⇩m (1⇩m (n::nat) * ⟪A⟫) *⇩v ψ⟩ = ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|⟪A⟫ *⇩v ψ⟩› and 2 goals remain*) prefer 3 (*top goal: ‹⟨ψ|⟨ψ|A *⇩v ψ⟩ ⋅⇩v (1⇩m n * ⟪A⟫ *⇩v ψ)⟩ = ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|⟪A⟫ *⇩v ψ⟩› and 4 goals remain*) apply (subst inner_prod_smult_left (*‹⟦?u ∈ carrier_vec ?n; ?v ∈ carrier_vec ?n⟧ ⟹ ⟨?u|?a ⋅⇩v ?v⟩ = ?a * ⟨?u|?v⟩›*)) (*top goal: ‹⟨ψ|⟨ψ|A *⇩v ψ⟩ ⋅⇩v (1⇩m n * ⟪A⟫ *⇩v ψ)⟩ = ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|⟪A⟫ *⇩v ψ⟩› and 4 goals remain*) using assms (*‹observable A›*) by (auto intro!: mult_mat_vec_carrier (*‹⟦?A ∈ carrier_mat ?nr ?n; ?v ∈ carrier_vec ?n⟧ ⟹ ?A *⇩v ?v ∈ carrier_vec ?nr›*)) also (*calculation: ‹⟨ψ::complex vec|⟪A::complex mat⟫ * ⟪A⟫ *⇩v ψ⟩ = ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|⟪A⟫ *⇩v ψ⟩›*) have "... = ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩" apply (subst smult_mat_mult_mat_vec_assoc (*‹⟦(?A::?'a mat) ∈ carrier_mat (?n::nat) (?m::nat); (?w::?'a vec) ∈ carrier_vec ?m⟧ ⟹ (?a::?'a) ⋅⇩m ?A *⇩v ?w = ?a ⋅⇩v (?A *⇩v ?w)›*)) (*goal: ‹⟨ψ|A *⇩v ψ⟩ * ⟨ψ|⟪A⟫ *⇩v ψ⟩ = ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩›*) prefer 3 (*top goal: ‹⟨ψ|A *⇩v ψ⟩ * ⟨ψ|⟨ψ|A *⇩v ψ⟩ ⋅⇩v (1⇩m n *⇩v ψ)⟩ = ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩› and 2 goals remain*) apply (subst inner_prod_smult_left[where n = n] (*‹⟦?u ∈ carrier_vec n; ?v ∈ carrier_vec n⟧ ⟹ ⟨?u|?a ⋅⇩v ?v⟩ = ?a * ⟨?u|?v⟩›*)) (*top goal: ‹⟨ψ|A *⇩v ψ⟩ * ⟨ψ|⟨ψ|A *⇩v ψ⟩ ⋅⇩v (1⇩m n *⇩v ψ)⟩ = ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩› and 2 goals remain*) using assms (*‹observable (A::complex mat)›*) (*goals: 1. ‹(ψ::complex vec) ∈ carrier_vec (n::nat)› 2. ‹1⇩m (n::nat) *⇩v (ψ::complex vec) ∈ carrier_vec n› 3. ‹⟨ψ::complex vec|(A::complex mat) *⇩v ψ⟩ * (⟨ψ|A *⇩v ψ⟩ * ⟨ψ|1⇩m (n::nat) *⇩v ψ⟩) = ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩› 4. ‹1⇩m (n::nat) ∈ carrier_mat (?n::nat) (?m::nat)› 5. ‹(ψ::complex vec) ∈ carrier_vec (?m::nat)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) by ((auto)[1]) (*proven 5 subgoals*) finally (*calculation: ‹⟨ψ|⟪A⟫ * ⟪A⟫ *⇩v ψ⟩ = ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩›*) have 4: "⟨ψ|⟪A⟫ * ⟪A⟫ *⇩v ψ⟩ = ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩" by simp show "?thesis" (*goal: ‹cmod (csqrt (⟨ψ|A * A *⇩v ψ⟩ - ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩)) = cmod (csqrt ⟨ψ|(A - ⟪A⟫) * (A - ⟪A⟫) *⇩v ψ⟩)›*) by (simp add: 1 (*‹⟨ψ|(A - ⟪A⟫) * (A - ⟪A⟫) *⇩v ψ⟩ = ⟨ψ|(A * A - ⟨ψ|A *⇩v ψ⟩ ⋅⇩m A - ⟨ψ|A *⇩v ψ⟩ ⋅⇩m A + ⟪A⟫ * ⟪A⟫) *⇩v ψ⟩›*) 2 (*‹⟨ψ|(A * A - ⟨ψ|A *⇩v ψ⟩ ⋅⇩m A - ⟨ψ|A *⇩v ψ⟩ ⋅⇩m A + ⟪A⟫ * ⟪A⟫) *⇩v ψ⟩ = ⟨ψ|A * A *⇩v ψ⟩ - ⟨ψ|⟨ψ|A *⇩v ψ⟩ ⋅⇩m A *⇩v ψ⟩ - ⟨ψ|⟨ψ|A *⇩v ψ⟩ ⋅⇩m A *⇩v ψ⟩ + ⟨ψ|⟪A⟫ * ⟪A⟫ *⇩v ψ⟩›*) 3 (*‹⟨ψ|⟨ψ|A *⇩v ψ⟩ ⋅⇩m A *⇩v ψ⟩ = ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩›*) 4 (*‹⟨ψ|⟪A⟫ * ⟪A⟫ *⇩v ψ⟩ = ⟨ψ|A *⇩v ψ⟩ * ⟨ψ|A *⇩v ψ⟩›*)) qed section‹Main Proof› text‹Note that when swapping two observables inside an inner product, it is the same as conjugating the result.› lemma cnj_observables: assumes "observable A" "observable B" shows "cnj ⟨ψ| (A * B) *⇩v ψ⟩ = ⟨ψ| (B * A) *⇩v ψ⟩" proof (-) (*goal: ‹cnj ⟨ψ|A * B *⇩v ψ⟩ = ⟨ψ|B * A *⇩v ψ⟩›*) have "cnj (conjugate ⟨A * B *⇩v ψ|ψ⟩) = ⟨adjoint (B * A) *⇩v ψ|ψ⟩" using assms (*‹observable A› ‹observable B›*) by (metis (full_types) adjoint_mult (*‹⟦?A ∈ carrier_mat ?n ?m; ?B ∈ carrier_mat ?m ?l⟧ ⟹ adjoint (?A * ?B) = adjoint ?B * adjoint ?A›*) complex_cnj_cnj (*‹cnj (cnj ?z) = ?z›*) conjugate_complex_def (*‹conjugate ≡ cnj›*) hermitian_def (*‹hermitian ?A = (adjoint ?A = ?A)›*)) then show "?thesis" (*goal: ‹cnj ⟨ψ|A * B *⇩v ψ⟩ = ⟨ψ|B * A *⇩v ψ⟩›*) using assms (*‹observable (A::complex mat)› ‹observable B›*) by (metis adjoint_def_alter (*‹⟦?v ∈ carrier_vec ?n; ?w ∈ carrier_vec ?m; ?A ∈ carrier_mat ?n ?m⟧ ⟹ ⟨?v|?A *⇩v ?w⟩ = ⟨adjoint ?A *⇩v ?v|?w⟩›*) dim (*‹ψ ∈ carrier_vec n›*) inner_prod_swap (*‹⟦?y ∈ carrier_vec ?n; ?x ∈ carrier_vec ?n⟧ ⟹ ⟨?y|?x⟩ = conjugate ⟨?x|?y⟩›*) mult_carrier_mat (*‹⟦?A ∈ carrier_mat ?nr ?n; ?B ∈ carrier_mat ?n ?nc⟧ ⟹ ?A * ?B ∈ carrier_mat ?nr ?nc›*) mult_mat_vec_carrier (*‹⟦?A ∈ carrier_mat ?nr ?n; ?v ∈ carrier_vec ?n⟧ ⟹ ?A *⇩v ?v ∈ carrier_vec ?nr›*)) qed text‹ With the above lemma we can make two observations about the behaviour of the commutator/ anticommutator inside an inner product. › lemma commutator_im: assumes "observable A" "observable B" shows "⟨ψ| ⟦A, B⟧ *⇩v ψ⟩ = 2 * 𝗂 * Im(⟨ψ| A * B *⇩v ψ⟩)" proof (-) (*goal: ‹⟨ψ|⟦A,B⟧ *⇩v ψ⟩ = 2 * 𝗂 * complex_of_real (Im ⟨ψ|A * B *⇩v ψ⟩)›*) have "⟨ψ| ⟦A, B⟧ *⇩v ψ⟩ = ⟨ψ| A * B *⇩v ψ⟩ - ⟨ψ| B * A *⇩v ψ⟩" using assms (*‹observable (A::complex mat)› ‹observable B›*) by (auto intro!: inner_prod_distrib_minus_mat (*‹⟦?u ∈ carrier_vec ?n; ?v ∈ carrier_vec ?m; ?A ∈ carrier_mat ?n ?m; ?B ∈ carrier_mat ?n ?m⟧ ⟹ ⟨?u|(?A - ?B) *⇩v ?v⟩ = ⟨?u|?A *⇩v ?v⟩ - ⟨?u|?B *⇩v ?v⟩›*)) also (*calculation: ‹⟨ψ|⟦A,B⟧ *⇩v ψ⟩ = ⟨ψ|A * B *⇩v ψ⟩ - ⟨ψ|B * A *⇩v ψ⟩›*) have "... = ⟨ψ| A * B *⇩v ψ⟩ - cnj ⟨ψ| A * B *⇩v ψ⟩" apply (subst cnj_observables[OF assms] (*‹cnj ⟨ψ|A * B *⇩v ψ⟩ = ⟨ψ|B * A *⇩v ψ⟩›*)) (*goal: ‹⟨ψ|A * B *⇩v ψ⟩ - ⟨ψ|B * A *⇩v ψ⟩ = ⟨ψ|A * B *⇩v ψ⟩ - cnj ⟨ψ|A * B *⇩v ψ⟩›*) by simp finally (*calculation: ‹⟨ψ|⟦A,B⟧ *⇩v ψ⟩ = ⟨ψ|A * B *⇩v ψ⟩ - cnj ⟨ψ|A * B *⇩v ψ⟩›*) show "?thesis" (*goal: ‹⟨ψ|⟦A,B⟧ *⇩v ψ⟩ = 2 * 𝗂 * complex_of_real (Im ⟨ψ|A * B *⇩v ψ⟩)›*) using complex_diff_cnj (*‹(?z::complex) - cnj ?z = complex_of_real ((2::real) * Im ?z) * 𝗂›*) by simp qed lemma anticommutator_re: assumes "observable A" "observable B" shows "⟨ψ| ⦃A, B⦄ *⇩v ψ⟩ = 2 * Re(⟨ψ| A * B *⇩v ψ⟩)" proof (-) (*goal: ‹⟨ψ::complex vec|⦃A::complex mat,B::complex mat⦄ *⇩v ψ⟩ = complex_of_real ((2::real) * Re ⟨ψ|A * B *⇩v ψ⟩)›*) have "⟨ψ| ⦃A, B⦄ *⇩v ψ⟩ = ⟨ψ| A * B *⇩v ψ⟩ + ⟨ψ| B * A *⇩v ψ⟩" using assms (*‹observable A› ‹observable B›*) by (auto intro!: inner_prod_distrib_add_mat (*‹⟦?u ∈ carrier_vec ?n; ?v ∈ carrier_vec ?m; ?A ∈ carrier_mat ?n ?m; ?B ∈ carrier_mat ?n ?m⟧ ⟹ ⟨?u|(?A + ?B) *⇩v ?v⟩ = ⟨?u|?A *⇩v ?v⟩ + ⟨?u|?B *⇩v ?v⟩›*)) also (*calculation: ‹⟨ψ|⦃A,B⦄ *⇩v ψ⟩ = ⟨ψ|A * B *⇩v ψ⟩ + ⟨ψ|B * A *⇩v ψ⟩›*) have "... = ⟨ψ| A * B *⇩v ψ⟩ + cnj ⟨ψ| A * B *⇩v ψ⟩" apply (subst cnj_observables[OF assms] (*‹cnj ⟨ψ|A * B *⇩v ψ⟩ = ⟨ψ|B * A *⇩v ψ⟩›*)) (*goal: ‹⟨ψ::complex vec|(A::complex mat) * (B::complex mat) *⇩v ψ⟩ + ⟨ψ|B * A *⇩v ψ⟩ = ⟨ψ|A * B *⇩v ψ⟩ + cnj ⟨ψ|A * B *⇩v ψ⟩›*) by simp finally (*calculation: ‹⟨ψ::complex vec|⦃A::complex mat,B::complex mat⦄ *⇩v ψ⟩ = ⟨ψ|A * B *⇩v ψ⟩ + cnj ⟨ψ|A * B *⇩v ψ⟩›*) show "?thesis" (*goal: ‹⟨ψ|⦃A,B⦄ *⇩v ψ⟩ = complex_of_real (2 * Re ⟨ψ|A * B *⇩v ψ⟩)›*) using complex_add_cnj (*‹?z + cnj ?z = complex_of_real (2 * Re ?z)›*) by simp qed text‹ This intermediate step already looks similar to the uncertainty principle. The LHS will play the role of the lower bound in the uncertainty principle. The RHS will turn into the standard deviation of our observables under a certain substitution. › lemma commutator_ineq: assumes "observable A" "observable B" shows "(norm ⟨ψ| ⟦A, B⟧ *⇩v ψ⟩)^2 ≤ 4 * Re (⟨ψ| A * A *⇩v ψ⟩ * ⟨ψ| B * B *⇩v ψ⟩)" proof (-) (*goal: ‹(cmod ⟨ψ|⟦A,B⟧ *⇩v ψ⟩)² ≤ 4 * Re (⟨ψ|A * A *⇩v ψ⟩ * ⟨ψ|B * B *⇩v ψ⟩)›*) let ?x = "Re(⟨ψ| A * B *⇩v ψ⟩)" let ?y = "Im(⟨ψ| A * B *⇩v ψ⟩)" have im: "(norm ⟨ψ| ⟦A, B⟧ *⇩v ψ⟩)^2 = 4 * ?y^2" apply (subst commutator_im[OF assms] (*‹⟨ψ|⟦A,B⟧ *⇩v ψ⟩ = 2 * 𝗂 * complex_of_real (Im ⟨ψ|A * B *⇩v ψ⟩)›*)) (*goal: ‹(cmod ⟨ψ|⟦A,B⟧ *⇩v ψ⟩)² = 4 * (Im ⟨ψ|A * B *⇩v ψ⟩)²›*) using cmod_power2 (*‹(cmod ?z)² = (Re ?z)² + (Im ?z)²›*) by simp have re: "(norm ⟨ψ| ⦃A, B⦄ *⇩v ψ⟩)^2 = 4 * ?x^2" apply (subst anticommutator_re[OF assms] (*‹⟨ψ|⦃A,B⦄ *⇩v ψ⟩ = complex_of_real (2 * Re ⟨ψ|A * B *⇩v ψ⟩)›*)) (*goal: ‹(cmod ⟨ψ|⦃A,B⦄ *⇩v ψ⟩)² = 4 * (Re ⟨ψ|A * B *⇩v ψ⟩)²›*) using cmod_power2 (*‹(cmod ?z)² = (Re ?z)² + (Im ?z)²›*) by simp from im (*‹(cmod ⟨ψ|⟦A,B⟧ *⇩v ψ⟩)² = 4 * (Im ⟨ψ|A * B *⇩v ψ⟩)²›*) re (*‹(cmod ⟨ψ|⦃A,B⦄ *⇩v ψ⟩)² = 4 * (Re ⟨ψ|A * B *⇩v ψ⟩)²›*) have "(norm ⟨ψ| ⟦A, B⟧ *⇩v ψ⟩)^2 + (norm ⟨ψ| ⦃A, B⦄ *⇩v ψ⟩)^2 = 4 * (?x^2 + ?y^2)" by simp also (*calculation: ‹(cmod ⟨ψ|⟦A,B⟧ *⇩v ψ⟩)² + (cmod ⟨ψ|⦃A,B⦄ *⇩v ψ⟩)² = 4 * ((Re ⟨ψ|A * B *⇩v ψ⟩)² + (Im ⟨ψ|A * B *⇩v ψ⟩)²)›*) have "... = 4 * norm(⟨ψ| A * B *⇩v ψ⟩)^2" using cmod_power2 (*‹(cmod ?z)² = (Re ?z)² + (Im ?z)²›*) by simp also (*calculation: ‹(cmod ⟨ψ|⟦A,B⟧ *⇩v ψ⟩)² + (cmod ⟨ψ|⦃A,B⦄ *⇩v ψ⟩)² = 4 * (cmod ⟨ψ|A * B *⇩v ψ⟩)²›*) have "... = 4 * norm(⟨A *⇩v ψ| B *⇩v ψ⟩)^2" apply (subst assoc_mult_mat_vec (*‹⟦?A ∈ carrier_mat ?n₁ ?n₂; ?B ∈ carrier_mat ?n₂ ?n₃; ?v ∈ carrier_vec ?n₃⟧ ⟹ ?A * ?B *⇩v ?v = ?A *⇩v (?B *⇩v ?v)›*)) (*goal: ‹4 * (cmod ⟨ψ|A * B *⇩v ψ⟩)² = 4 * (cmod ⟨A *⇩v ψ|B *⇩v ψ⟩)²›*) prefer 4 (*top goal: ‹4 * (cmod ⟨ψ|A *⇩v (B *⇩v ψ)⟩)² = 4 * (cmod ⟨A *⇩v ψ|B *⇩v ψ⟩)²› and 3 goals remain*) apply (subst adjoint_def_alter (*‹⟦?v ∈ carrier_vec ?n; ?w ∈ carrier_vec ?m; ?A ∈ carrier_mat ?n ?m⟧ ⟹ ⟨?v|?A *⇩v ?w⟩ = ⟨adjoint ?A *⇩v ?v|?w⟩›*)) (*top goal: ‹(4::real) * (cmod ⟨ψ::complex vec|(A::complex mat) *⇩v ((B::complex mat) *⇩v ψ)⟩)² = (4::real) * (cmod ⟨A *⇩v ψ|B *⇩v ψ⟩)²› and 3 goals remain*) using assms (*‹observable A› ‹observable B›*) hermitian_def (*‹hermitian ?A = (adjoint ?A = ?A)›*) by (auto, force) also (*calculation: ‹(cmod ⟨ψ::complex vec|⟦A::complex mat,B::complex mat⟧ *⇩v ψ⟩)² + (cmod ⟨ψ|⦃A,B⦄ *⇩v ψ⟩)² = (4::real) * (cmod ⟨A *⇩v ψ|B *⇩v ψ⟩)²›*) have "... ≤ 4 * Re (⟨A *⇩v ψ| A *⇩v ψ⟩ * ⟨B *⇩v ψ| B *⇩v ψ⟩)" by (smt (verit) assms (*‹observable A› ‹observable B›*) Cauchy_Schwarz (*‹⟦?v ∈ carrier_vec ?n; ?u ∈ carrier_vec ?n⟧ ⟹ (cmod ⟨?u|?v⟩)² ≤ Re (⟨?u|?u⟩ * ⟨?v|?v⟩)›*) dim (*‹ψ ∈ carrier_vec n›*) mult_mat_vec_carrier (*‹⟦?A ∈ carrier_mat ?nr ?n; ?v ∈ carrier_vec ?n⟧ ⟹ ?A *⇩v ?v ∈ carrier_vec ?nr›*)) also (*calculation: ‹(cmod ⟨ψ|⟦A,B⟧ *⇩v ψ⟩)² + (cmod ⟨ψ|⦃A,B⦄ *⇩v ψ⟩)² ≤ 4 * Re (⟨A *⇩v ψ|A *⇩v ψ⟩ * ⟨B *⇩v ψ|B *⇩v ψ⟩)›*) have "... = 4 * Re (⟨ψ| A * A *⇩v ψ⟩ * ⟨ψ| B * B *⇩v ψ⟩)" apply (subst (1 2) assoc_mult_mat_vec (*‹⟦(?A::?'a mat) ∈ carrier_mat (?n₁::nat) (?n₂::nat); (?B::?'a mat) ∈ carrier_mat ?n₂ (?n₃::nat); (?v::?'a vec) ∈ carrier_vec ?n₃⟧ ⟹ ?A * ?B *⇩v ?v = ?A *⇩v (?B *⇩v ?v)›*)) (*goal: ‹4 * Re (⟨A *⇩v ψ|A *⇩v ψ⟩ * ⟨B *⇩v ψ|B *⇩v ψ⟩) = 4 * Re (⟨ψ|A * A *⇩v ψ⟩ * ⟨ψ|B * B *⇩v ψ⟩)›*) prefer 7 (*top goal: ‹4 * Re (⟨A *⇩v ψ|A *⇩v ψ⟩ * ⟨B *⇩v ψ|B *⇩v ψ⟩) = 4 * Re (⟨ψ|A *⇩v (A *⇩v ψ)⟩ * ⟨ψ|B *⇩v (B *⇩v ψ)⟩)› and 6 goals remain*) apply (subst (3 4) adjoint_def_alter (*‹⟦?v ∈ carrier_vec ?n; ?w ∈ carrier_vec ?m; ?A ∈ carrier_mat ?n ?m⟧ ⟹ ⟨?v|?A *⇩v ?w⟩ = ⟨adjoint ?A *⇩v ?v|?w⟩›*)) (*top goal: ‹4 * Re (⟨A *⇩v ψ|A *⇩v ψ⟩ * ⟨B *⇩v ψ|B *⇩v ψ⟩) = 4 * Re (⟨ψ|A *⇩v (A *⇩v ψ)⟩ * ⟨ψ|B *⇩v (B *⇩v ψ)⟩)› and 6 goals remain*) using assms (*‹observable A› ‹observable (B::complex mat)›*) by (auto simp: hermitian_def (*‹hermitian ?A = (adjoint ?A = ?A)›*)) finally (*calculation: ‹(cmod ⟨ψ|⟦A,B⟧ *⇩v ψ⟩)² + (cmod ⟨ψ|⦃A,B⦄ *⇩v ψ⟩)² ≤ 4 * Re (⟨ψ|A * A *⇩v ψ⟩ * ⟨ψ|B * B *⇩v ψ⟩)›*) show "?thesis" (*goal: ‹(cmod ⟨ψ|⟦A,B⟧ *⇩v ψ⟩)² ≤ 4 * Re (⟨ψ|A * A *⇩v ψ⟩ * ⟨ψ|B * B *⇩v ψ⟩)›*) using norm_ge_zero (*‹0 ≤ norm ?x›*) by (smt (verit, ccfv_threshold) zero_le_power2 (*‹0 ≤ ?a²›*)) qed text‹ This is part of the substitution we need in the final proof. This lemma shows that the commutator simplifies nicely under that substitution. › lemma commutator_sub_mean[simp]: assumes "A ∈ carrier_mat n n" "B ∈ carrier_mat n n" shows "⟦A - ⟪A⟫, B - ⟪B⟫⟧ = ⟦A,B⟧" proof (-) (*goal: ‹⟦A - ⟪A⟫,B - ⟪B⟫⟧ = ⟦A,B⟧›*) have "⟦A - ⟪A⟫, B - ⟪B⟫⟧ = A * B - ⟪A⟫ * B - A * ⟪B⟫ - ⟪A⟫ * (- ⟪B⟫) - (B * A + (- (⟪B⟫ * A)) + (- (B * ⟪A⟫)) - ⟪B⟫ * (- ⟪A⟫))" apply (mat_assoc n) (*goal: ‹⟦A - ⟪A⟫,B - ⟪B⟫⟧ = A * B - ⟪A⟫ * B - A * ⟪B⟫ - ⟪A⟫ * - ⟪B⟫ - (B * A + - (⟪B⟫ * A) + - (B * ⟪A⟫) - ⟪B⟫ * - ⟪A⟫)›*) using assms (*‹A ∈ carrier_mat n n› ‹B ∈ carrier_mat n n›*) apply - (*goals: 1. ‹⟦A ∈ carrier_mat n n; B ∈ carrier_mat n n⟧ ⟹ 1⇩m n ∈ carrier_mat n n› 2. ‹⟦A ∈ carrier_mat n n; B ∈ carrier_mat n n⟧ ⟹ B ∈ carrier_mat n n› 3. ‹⟦A ∈ carrier_mat n n; B ∈ carrier_mat n n⟧ ⟹ A ∈ carrier_mat n n› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . also (*calculation: ‹⟦A - ⟪A⟫,B - ⟪B⟫⟧ = A * B - ⟪A⟫ * B - A * ⟪B⟫ - ⟪A⟫ * - ⟪B⟫ - (B * A + - (⟪B⟫ * A) + - (B * ⟪A⟫) - ⟪B⟫ * - ⟪A⟫)›*) have "... = A * B - ⟪A⟫ * B - A * ⟪B⟫ - (- (⟪A⟫ * ⟪B⟫)) - (B * A + (- (⟪B⟫ * A)) + (- (B * ⟪A⟫)) - (- (⟪B⟫ * ⟪A⟫)))" using assms (*‹A ∈ carrier_mat n n› ‹B ∈ carrier_mat n n›*) by auto also (*calculation: ‹⟦A - ⟪A⟫,B - ⟪B⟫⟧ = A * B - ⟪A⟫ * B - A * ⟪B⟫ - - (⟪A⟫ * ⟪B⟫) - (B * A + - (⟪B⟫ * A) + - (B * ⟪A⟫) - - (⟪B⟫ * ⟪A⟫))›*) have "... = A * B - ⟪A⟫ * B - A * ⟪B⟫ + - (- (⟪A⟫ * ⟪B⟫)) - (B * A + (- (⟪B⟫ * A)) + (- (B * ⟪A⟫)) + (- (- (⟪B⟫ * ⟪A⟫))))" apply (mat_assoc n) (*goal: ‹A * B - ⟪A⟫ * B - A * ⟪B⟫ - - (⟪A⟫ * ⟪B⟫) - (B * A + - (⟪B⟫ * A) + - (B * ⟪A⟫) - - (⟪B⟫ * ⟪A⟫)) = A * B - ⟪A⟫ * B - A * ⟪B⟫ + - (- (⟪A⟫ * ⟪B⟫)) - (B * A + - (⟪B⟫ * A) + - (B * ⟪A⟫) + - (- (⟪B⟫ * ⟪A⟫)))›*) using assms (*‹A ∈ carrier_mat n n› ‹B ∈ carrier_mat n n›*) apply - (*goals: 1. ‹⟦A ∈ carrier_mat n n; B ∈ carrier_mat n n⟧ ⟹ 1⇩m n ∈ carrier_mat n n› 2. ‹⟦A ∈ carrier_mat n n; B ∈ carrier_mat n n⟧ ⟹ B ∈ carrier_mat n n› 3. ‹⟦A ∈ carrier_mat n n; B ∈ carrier_mat n n⟧ ⟹ A ∈ carrier_mat n n› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . also (*calculation: ‹⟦A - ⟪A⟫,B - ⟪B⟫⟧ = A * B - ⟪A⟫ * B - A * ⟪B⟫ + - (- (⟪A⟫ * ⟪B⟫)) - (B * A + - (⟪B⟫ * A) + - (B * ⟪A⟫) + - (- (⟪B⟫ * ⟪A⟫)))›*) have "... = A * B - ⟪A⟫ * B - A * ⟪B⟫ + ⟪A⟫ * ⟪B⟫ - (B * A + (- (⟪B⟫ * A)) + (- (B * ⟪A⟫)) + ⟪B⟫ * ⟪A⟫)" by simp also (*calculation: ‹⟦A - ⟪A⟫,B - ⟪B⟫⟧ = A * B - ⟪A⟫ * B - A * ⟪B⟫ + ⟪A⟫ * ⟪B⟫ - (B * A + - (⟪B⟫ * A) + - (B * ⟪A⟫) + ⟪B⟫ * ⟪A⟫)›*) have "... = A * B - ⟪A⟫ * B - A * ⟪B⟫ + ⟪A⟫ * ⟪B⟫ - B * A + (- (- (⟪B⟫ * A))) + (- (- (B * ⟪A⟫))) - ⟪B⟫ * ⟪A⟫" apply (mat_assoc n) (*goal: ‹A * B - ⟪A⟫ * B - A * ⟪B⟫ + ⟪A⟫ * ⟪B⟫ - (B * A + - (⟪B⟫ * A) + - (B * ⟪A⟫) + ⟪B⟫ * ⟪A⟫) = A * B - ⟪A⟫ * B - A * ⟪B⟫ + ⟪A⟫ * ⟪B⟫ - B * A + - (- (⟪B⟫ * A)) + - (- (B * ⟪A⟫)) - ⟪B⟫ * ⟪A⟫›*) using assms (*‹(A::complex mat) ∈ carrier_mat (n::nat) n› ‹(B::complex mat) ∈ carrier_mat (n::nat) n›*) apply - (*goals: 1. ‹⟦A ∈ carrier_mat n n; B ∈ carrier_mat n n⟧ ⟹ 1⇩m n ∈ carrier_mat n n› 2. ‹⟦A ∈ carrier_mat n n; B ∈ carrier_mat n n⟧ ⟹ B ∈ carrier_mat n n› 3. ‹⟦A ∈ carrier_mat n n; B ∈ carrier_mat n n⟧ ⟹ A ∈ carrier_mat n n› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . also (*calculation: ‹⟦A - ⟪A⟫,B - ⟪B⟫⟧ = A * B - ⟪A⟫ * B - A * ⟪B⟫ + ⟪A⟫ * ⟪B⟫ - B * A + - (- (⟪B⟫ * A)) + - (- (B * ⟪A⟫)) - ⟪B⟫ * ⟪A⟫›*) have "... =A * B - ⟪A⟫ * B - A * ⟪B⟫ + ⟪A⟫ * ⟪B⟫ - B * A + ⟪B⟫ * A + B * ⟪A⟫ - ⟪B⟫ * ⟪A⟫" using uminus_uminus_mat (*‹- (- ?A) = ?A›*) by simp also (*calculation: ‹⟦A - ⟪A⟫,B - ⟪B⟫⟧ = A * B - ⟪A⟫ * B - A * ⟪B⟫ + ⟪A⟫ * ⟪B⟫ - B * A + ⟪B⟫ * A + B * ⟪A⟫ - ⟪B⟫ * ⟪A⟫›*) have "...= A * B - ⟪A⟫ * B - A * ⟪B⟫ + ⟪A⟫ * ⟪B⟫ - B * A + A * ⟪B⟫ + ⟪A⟫ * B - ⟪A⟫ * ⟪B⟫" using assms (*‹A ∈ carrier_mat n n› ‹B ∈ carrier_mat n n›*) by auto also (*calculation: ‹⟦A - ⟪A⟫,B - ⟪B⟫⟧ = A * B - ⟪A⟫ * B - A * ⟪B⟫ + ⟪A⟫ * ⟪B⟫ - B * A + A * ⟪B⟫ + ⟪A⟫ * B - ⟪A⟫ * ⟪B⟫›*) have "...= A * B - B * A + ⟪A⟫ * B - ⟪A⟫ * B + A * ⟪B⟫ - A * ⟪B⟫ + ⟪A⟫ * ⟪B⟫ - ⟪A⟫ * ⟪B⟫" apply (mat_assoc n) (*goal: ‹A * B - ⟪A⟫ * B - A * ⟪B⟫ + ⟪A⟫ * ⟪B⟫ - B * A + A * ⟪B⟫ + ⟪A⟫ * B - ⟪A⟫ * ⟪B⟫ = ⟦A,B⟧ + ⟪A⟫ * B - ⟪A⟫ * B + A * ⟪B⟫ - A * ⟪B⟫ + ⟪A⟫ * ⟪B⟫ - ⟪A⟫ * ⟪B⟫›*) using assms (*‹A ∈ carrier_mat n n› ‹B ∈ carrier_mat n n›*) apply - (*goals: 1. ‹⟦A ∈ carrier_mat n n; B ∈ carrier_mat n n⟧ ⟹ 1⇩m n ∈ carrier_mat n n› 2. ‹⟦A ∈ carrier_mat n n; B ∈ carrier_mat n n⟧ ⟹ B ∈ carrier_mat n n› 3. ‹⟦A ∈ carrier_mat n n; B ∈ carrier_mat n n⟧ ⟹ A ∈ carrier_mat n n› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . finally (*calculation: ‹⟦A - ⟪A⟫,B - ⟪B⟫⟧ = ⟦A,B⟧ + ⟪A⟫ * B - ⟪A⟫ * B + A * ⟪B⟫ - A * ⟪B⟫ + ⟪A⟫ * ⟪B⟫ - ⟪A⟫ * ⟪B⟫›*) show "?thesis" (*goal: ‹⟦A - ⟪A⟫,B - ⟪B⟫⟧ = ⟦A,B⟧›*) using assms (*‹A ∈ carrier_mat n n› ‹B ∈ carrier_mat n n›*) minus_r_inv_mat (*‹?A ∈ carrier_mat ?nr ?nc ⟹ ?A - ?A = 0⇩m ?nr ?nc›*) by auto qed theorem uncertainty_principle: assumes "observable C" "observable D" shows "Δ C * Δ D ≥ norm ⟨ψ|⟦C,D⟧ *⇩v ψ⟩ / 2" proof (-) (*goal: ‹cmod ⟨ψ|⟦C,D⟧ *⇩v ψ⟩ / 2 ≤ cmod (csqrt (⟨ψ|C * C *⇩v ψ⟩ - ⟨ψ|C *⇩v ψ⟩ * ⟨ψ|C *⇩v ψ⟩)) * cmod (csqrt (⟨ψ|D * D *⇩v ψ⟩ - ⟨ψ|D *⇩v ψ⟩ * ⟨ψ|D *⇩v ψ⟩))›*) let ?A = "C - ⟪C⟫" let ?B = "D - ⟪D⟫" from assms (*‹observable C› ‹observable D›*) have observables_A_B: "observable ?A" "observable ?B" using hermitian_inner_prod_real (*‹⟦?A ∈ carrier_mat ?n ?n; ?v ∈ carrier_vec ?n; hermitian ?A⟧ ⟹ ⟨?v|?A *⇩v ?v⟩ ∈ ℝ›*) assms (*‹observable C› ‹observable D›*) Reals_cnj_iff (*‹((?z::complex) ∈ ℝ) = (cnj ?z = ?z)›*) apply - (*goals: 1. ‹⟦observable C; observable D; ⋀A n v. ⟦A ∈ carrier_mat n n; v ∈ carrier_vec n; hermitian A⟧ ⟹ ⟨v|A *⇩v v⟩ ∈ ℝ; observable C; observable D; ⋀z. (z ∈ ℝ) = (cnj z = z)⟧ ⟹ observable (C - ⟪C⟫)› 2. ‹⟦observable C; observable D; ⋀A n v. ⟦A ∈ carrier_mat n n; v ∈ carrier_vec n; hermitian A⟧ ⟹ ⟨v|A *⇩v v⟩ ∈ ℝ; observable C; observable D; ⋀z. (z ∈ ℝ) = (cnj z = z)⟧ ⟹ observable (D - ⟪D⟫)› discuss goal 1*) apply ((auto simp: hermitian_def (*‹hermitian ?A = (adjoint ?A = ?A)›*) adjoint_minus (*‹⟦?A ∈ carrier_mat ?n ?m; ?B ∈ carrier_mat ?n ?m⟧ ⟹ adjoint (?A - ?B) = adjoint ?A - adjoint ?B›*) adjoint_one (*‹adjoint (1⇩m ?n) = 1⇩m ?n›*) adjoint_scale (*‹adjoint (?a ⋅⇩m ?A) = conjugate ?a ⋅⇩m adjoint ?A›*))[1]) (*discuss goal 2*) apply ((auto simp: hermitian_def (*‹hermitian (?A::?'a mat) = (adjoint ?A = ?A)›*) adjoint_minus (*‹⟦(?A::?'a mat) ∈ carrier_mat (?n::nat) (?m::nat); (?B::?'a mat) ∈ carrier_mat ?n ?m⟧ ⟹ adjoint (?A - ?B) = adjoint ?A - adjoint ?B›*) adjoint_one (*‹adjoint (1⇩m (?n::nat)) = 1⇩m ?n›*) adjoint_scale (*‹adjoint ((?a::?'a) ⋅⇩m (?A::?'a mat)) = conjugate ?a ⋅⇩m adjoint ?A›*))[1]) (*proven 2 subgoals*) . have "(norm ⟨ψ| ⟦?A, ?B⟧ *⇩v ψ⟩)^2 ≤ 4 * Re ((⟨ψ| ?A * ?A *⇩v ψ⟩) * (⟨ψ| ?B * ?B *⇩v ψ⟩))" using commutator_ineq[OF observables_A_B] (*‹(cmod ⟨ψ|⟦C - ⟪C⟫,D - ⟪D⟫⟧ *⇩v ψ⟩)² ≤ 4 * Re (⟨ψ|(C - ⟪C⟫) * (C - ⟪C⟫) *⇩v ψ⟩ * ⟨ψ|(D - ⟪D⟫) * (D - ⟪D⟫) *⇩v ψ⟩)›*) by auto then have "(norm ⟨ψ| ⟦C, D⟧ *⇩v ψ⟩)^2 ≤ 4 * Re ((⟨ψ| ?A * ?A *⇩v ψ⟩) * (⟨ψ| ?B * ?B *⇩v ψ⟩))" using assms (*‹observable C› ‹observable D›*) by simp then have "sqrt ((norm (⟨ψ| ⟦C, D⟧ *⇩v ψ⟩))^2) ≤ sqrt (4 * Re ((⟨ψ| ?A * ?A *⇩v ψ⟩) * (⟨ψ| ?B * ?B *⇩v ψ⟩)))" using real_sqrt_le_mono (*‹?x ≤ ?y ⟹ sqrt ?x ≤ sqrt ?y›*) by blast then have "norm (⟨ψ| ⟦C, D⟧ *⇩v ψ⟩) ≤ 2 * sqrt (Re ((⟨ψ| ?A * ?A *⇩v ψ⟩) * (⟨ψ| ?B * ?B *⇩v ψ⟩)))" by (auto cong: real_sqrt_mult (*‹sqrt (?x * ?y) = sqrt ?x * sqrt ?y›*)) then have "norm (⟨ψ| ⟦C, D⟧ *⇩v ψ⟩) ≤ 2 * sqrt ( ¦Re ((⟨ψ| ?A * ?A *⇩v ψ⟩) * (⟨ψ| ?B * ?B *⇩v ψ⟩))¦)" by (smt (verit, ccfv_SIG) real_sqrt_le_iff (*‹(sqrt ?x ≤ sqrt ?y) = (?x ≤ ?y)›*)) then have "norm (⟨ψ| ⟦C, D⟧ *⇩v ψ⟩) ≤ 2 * sqrt (norm ((⟨ψ| ?A * ?A *⇩v ψ⟩) * (⟨ψ| ?B * ?B *⇩v ψ⟩)))" by (auto simp: in_Reals_norm (*‹?z ∈ ℝ ⟹ cmod ?z = ¦Re ?z¦›*) Reals_cnj_iff (*‹(?z ∈ ℝ) = (cnj ?z = ?z)›*) cnj_observables (*‹⟦observable ?A; observable ?B⟧ ⟹ cnj ⟨ψ|?A * ?B *⇩v ψ⟩ = ⟨ψ|?B * ?A *⇩v ψ⟩›*) observables_A_B (*‹observable (C - ⟪C⟫)› ‹observable (D - ⟪D⟫)›*)) then have "norm (⟨ψ| ⟦C, D⟧ *⇩v ψ⟩) ≤ 2 * norm (csqrt (⟨ψ| ?A * ?A *⇩v ψ⟩)) * norm (csqrt (⟨ψ| ?B * ?B *⇩v ψ⟩))" by (simp add: norm_mult (*‹norm (?x * ?y) = norm ?x * norm ?y›*) real_sqrt_mult (*‹sqrt (?x * ?y) = sqrt ?x * sqrt ?y›*)) then show "Δ C * Δ D ≥ norm ⟨ψ|⟦C, D⟧ *⇩v ψ⟩ / 2" using assms (*‹observable C› ‹observable D›*) by (auto cong: std_dev_alt (*‹observable ?A ⟹ cmod (csqrt (⟨ψ|?A * ?A *⇩v ψ⟩ - ⟨ψ|?A *⇩v ψ⟩ * ⟨ψ|?A *⇩v ψ⟩)) = cmod (csqrt ⟨ψ|(?A - ⟪?A⟫) * (?A - ⟪?A⟫) *⇩v ψ⟩)›*)) qed end end
{ "path": "afp-2025-02-12/thys/Uncertainty_Principle/Uncertainty_Principle.thy", "repo": "afp-2025-02-12", "sha": "998f7f0546983fe39fb851e4506f882cfb8c49675399aae22af7762c1c49f2d6" }
(* Title: HOL/HOLCF/Universal.thy Author: Brian Huffman *) section ‹A universal bifinite domain› theory Universal imports Bifinite Completion "HOL-Library.Nat_Bijection" begin no_notation binomial (infixl "choose" 65) subsection ‹Basis for universal domain› subsubsection ‹Basis datatype› type_synonym ubasis = nat definition node :: "nat ⇒ ubasis ⇒ ubasis set ⇒ ubasis" where "node i a S = Suc (prod_encode (i, prod_encode (a, set_encode S)))" lemma node_not_0 [simp]: "node i a S ≠ 0" unfolding node_def (*goal: ‹Suc (prod_encode (i, prod_encode (a, set_encode S))) ≠ 0›*) by simp lemma node_gt_0 [simp]: "0 < node i a S" unfolding node_def (*goal: ‹0 < Suc (prod_encode (i, prod_encode (a, set_encode S)))›*) by simp lemma node_inject [simp]: "⟦finite S; finite T⟧ ⟹ node i a S = node j b T ⟷ i = j ∧ a = b ∧ S = T" unfolding node_def (*goal: ‹⟦finite S; finite T⟧ ⟹ (Suc (prod_encode (i, prod_encode (a, set_encode S))) = Suc (prod_encode (j, prod_encode (b, set_encode T)))) = (i = j ∧ a = b ∧ S = T)›*) by (simp add: prod_encode_eq (*‹(prod_encode ?x = prod_encode ?y) = (?x = ?y)›*) set_encode_eq (*‹⟦finite ?A; finite ?B⟧ ⟹ (set_encode ?A = set_encode ?B) = (?A = ?B)›*)) lemma node_gt0: "i < node i a S" unfolding node_def less_Suc_eq_le (*goal: ‹i ≤ prod_encode (i, prod_encode (a, set_encode S))›*) by (rule le_prod_encode_1 (*‹?a ≤ prod_encode (?a, ?b)›*)) lemma node_gt1: "a < node i a S" unfolding node_def less_Suc_eq_le (*goal: ‹a ≤ prod_encode (i, prod_encode (a, set_encode S))›*) by (rule order_trans [OF le_prod_encode_1 le_prod_encode_2] (*‹?x ≤ prod_encode (?a1, prod_encode (?x, ?b2))›*)) lemma nat_less_power2: "n < 2^n" by (fact less_exp (*‹?n < 2 ^ ?n›*)) lemma node_gt2: "⟦finite S; b ∈ S⟧ ⟹ b < node i a S" unfolding node_def less_Suc_eq_le set_encode_def (*goal: ‹⟦finite (S::nat set); (b::nat) ∈ S⟧ ⟹ b ≤ prod_encode (i::nat, prod_encode (a::nat, sum ((^) (2::nat)) S))›*) apply (rule order_trans [OF _ le_prod_encode_2] (*‹?x ≤ ?y ⟹ ?x ≤ prod_encode (?a1, ?y)›*)) (*goal: ‹⟦finite S; b ∈ S⟧ ⟹ b ≤ prod_encode (i, prod_encode (a, sum ((^) 2) S))›*) apply (rule order_trans [OF _ le_prod_encode_2] (*‹?x ≤ ?y ⟹ ?x ≤ prod_encode (?a1, ?y)›*)) (*goal: ‹⟦finite S; b ∈ S⟧ ⟹ b ≤ prod_encode (a, sum ((^) 2) S)›*) apply (rule order_trans [where y="sum ((^) 2) {b}"] (*‹⟦?x ≤ sum ((^) 2) {b}; sum ((^) 2) {b} ≤ ?z⟧ ⟹ ?x ≤ ?z›*)) (*goals: 1. ‹⟦finite S; b ∈ S⟧ ⟹ b ≤ sum ((^) 2) {b}› 2. ‹⟦finite S; b ∈ S⟧ ⟹ sum ((^) 2) {b} ≤ sum ((^) 2) S› discuss goal 1*) apply (simp add: nat_less_power2 [THEN order_less_imp_le] (*‹?x ≤ 2 ^ ?x›*)) (*discuss goal 2*) apply (erule sum_mono2 (*‹⟦finite ?B; ?A ⊆ ?B; ⋀b. b ∈ ?B - ?A ⟹ 0 ≤ ?f b⟧ ⟹ sum ?f ?A ≤ sum ?f ?B›*)) (*goals: 1. ‹b ∈ S ⟹ {b} ⊆ S› 2. ‹⋀ba. ⟦b ∈ S; ba ∈ S - {b}⟧ ⟹ 0 ≤ 2 ^ ba› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma eq_prod_encode_pairI: "⟦fst (prod_decode x) = a; snd (prod_decode x) = b⟧ ⟹ x = prod_encode (a, b)" apply (erule subst (*‹⟦?s = ?t; ?P ?s⟧ ⟹ ?P ?t›*)) (*goal: ‹⟦fst (prod_decode (x::nat)) = (a::nat); snd (prod_decode x) = (b::nat)⟧ ⟹ x = prod_encode (a, b)›*) apply (erule subst (*‹⟦?s = ?t; ?P ?s⟧ ⟹ ?P ?t›*)) (*goal: ‹snd (prod_decode (x::nat)) = (b::nat) ⟹ x = prod_encode (fst (prod_decode x), b)›*) by simp lemma node_cases: assumes 1: "x = 0 ⟹ P" assumes 2: "⋀i a S. ⟦finite S; x = node i a S⟧ ⟹ P" shows "P" apply (cases x) (*goals: 1. ‹x = 0 ⟹ P› 2. ‹⋀nat. x = Suc nat ⟹ P› discuss goal 1*) apply (erule 1 (*‹x = 0 ⟹ P›*)) (*discuss goal 2*) apply (rule 2 (*‹⟦finite ?S; x = node ?i ?a ?S⟧ ⟹ P›*)) (*goals: 1. ‹⋀nat. x = Suc nat ⟹ finite (?S1 nat)› 2. ‹⋀nat. x = Suc nat ⟹ x = node (?i1 nat) (?a1 nat) (?S1 nat)› discuss goal 1*) apply (rule finite_set_decode (*‹finite (set_decode ?n)›*)) (*discuss goal 2*) apply (simp add: node_def (*‹node ?i ?a ?S = Suc (prod_encode (?i, prod_encode (?a, set_encode ?S)))›*)) (*goal: ‹⋀nat::nat. (x::nat) = Suc nat ⟹ x = node ((?i1::nat ⇒ nat) nat) ((?a1::nat ⇒ nat) nat) (set_decode ((?n4::nat ⇒ nat) nat))›*) apply (rule eq_prod_encode_pairI [OF refl] (*‹snd (prod_decode ?x) = ?b ⟹ ?x = prod_encode (fst (prod_decode ?x), ?b)›*)) (*goal: ‹⋀nat. x = Suc nat ⟹ nat = prod_encode (?i1 nat, prod_encode (?a1 nat, ?n4 nat))›*) apply (rule eq_prod_encode_pairI [OF refl refl] (*‹?x = prod_encode (fst (prod_decode ?x), snd (prod_decode ?x))›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma node_induct: assumes 1: "P 0" assumes 2: "⋀i a S. ⟦P a; finite S; ∀b∈S. P b⟧ ⟹ P (node i a S)" shows "P x" apply (induct x rule: nat_less_induct (*‹(⋀n. ∀m<n. ?P m ⟹ ?P n) ⟹ ?P ?n›*)) (*goal: ‹P x›*) apply (case_tac n rule: node_cases) (*goals: 1. ‹⋀n. ⟦∀m<n. P m; n = 0⟧ ⟹ P n› 2. ‹⋀n i a S. ⟦∀m<n. P m; finite S; n = node i a S⟧ ⟹ P n› discuss goal 1*) apply (simp add: 1 (*‹(P::nat ⇒ bool) (0::nat)›*)) (*discuss goal 2*) apply (simp add: 2 (*‹⟦P ?a; finite ?S; ∀b∈?S. P b⟧ ⟹ P (node ?i ?a ?S)›*) node_gt1 (*‹?a < node ?i ?a ?S›*) node_gt2 (*‹⟦finite ?S; ?b ∈ ?S⟧ ⟹ ?b < node ?i ?a ?S›*)) (*proven 2 subgoals*) . subsubsection ‹Basis ordering› inductive ubasis_le :: "nat ⇒ nat ⇒ bool" where ubasis_le_refl: "ubasis_le a a" | ubasis_le_trans: "⟦ubasis_le a b; ubasis_le b c⟧ ⟹ ubasis_le a c" | ubasis_le_lower: "finite S ⟹ ubasis_le a (node i a S)" | ubasis_le_upper: "⟦finite S; b ∈ S; ubasis_le a b⟧ ⟹ ubasis_le (node i a S) b" lemma ubasis_le_minimal: "ubasis_le 0 x" apply (induct x rule: node_induct (*‹⟦?P 0; ⋀i a S. ⟦?P a; finite S; ∀b∈S. ?P b⟧ ⟹ ?P (node i a S)⟧ ⟹ ?P ?x›*)) (*goals: 1. ‹ubasis_le 0 0› 2. ‹⋀i a S. ⟦ubasis_le 0 a; finite S; ∀b∈S. ubasis_le 0 b⟧ ⟹ ubasis_le 0 (node i a S)› discuss goal 1*) apply (rule ubasis_le_refl (*‹ubasis_le ?a ?a›*)) (*discuss goal 2*) apply (erule ubasis_le_trans (*‹⟦ubasis_le ?a ?b; ubasis_le ?b ?c⟧ ⟹ ubasis_le ?a ?c›*)) (*goal: ‹⋀(i::nat) (a::nat) S::nat set. ⟦ubasis_le (0::nat) a; finite S; ∀b::nat∈S. ubasis_le (0::nat) b⟧ ⟹ ubasis_le (0::nat) (node i a S)›*) apply (erule ubasis_le_lower (*‹finite ?S ⟹ ubasis_le ?a (node ?i ?a ?S)›*)) (*proven 2 subgoals*) . interpretation udom: preorder ubasis_le apply standard (*goals: 1. ‹⋀x::nat. ubasis_le x x› 2. ‹⋀(x::nat) (y::nat) z::nat. ⟦ubasis_le x y; ubasis_le y z⟧ ⟹ ubasis_le x z› discuss goal 1*) apply (rule ubasis_le_refl (*‹ubasis_le ?a ?a›*)) (*discuss goal 2*) apply (erule (1) ubasis_le_trans (*‹⟦ubasis_le ?a ?b; ubasis_le ?b ?c⟧ ⟹ ubasis_le ?a ?c›*)) (*proven 2 subgoals*) . subsubsection ‹Generic take function› function ubasis_until :: "(ubasis ⇒ bool) ⇒ ubasis ⇒ ubasis" where "ubasis_until P 0 = 0" | "finite S ⟹ ubasis_until P (node i a S) = (if P (node i a S) then node i a S else ubasis_until P a)" apply clarify apply (rule_tac x=b in node_cases) apply simp_all done termination ubasis_until apply (relation "measure snd") apply (rule wf_measure) apply (simp add: node_gt1) done lemma ubasis_until: "P 0 ⟹ P (ubasis_until P x)" apply (induct x rule: node_induct (*‹⟦?P 0; ⋀i a S. ⟦?P a; finite S; ∀b∈S. ?P b⟧ ⟹ ?P (node i a S)⟧ ⟹ ?P ?x›*)) (*goals: 1. ‹(P::nat ⇒ bool) (0::nat) ⟹ P (ubasis_until P (0::nat))› 2. ‹⋀(i::nat) (a::nat) S::nat set. ⟦(P::nat ⇒ bool) (0::nat) ⟹ P (ubasis_until P a); finite S; ∀b::nat∈S. P (0::nat) ⟶ P (ubasis_until P b); P (0::nat)⟧ ⟹ P (ubasis_until P (node i a S))› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma ubasis_until': "0 < ubasis_until P x ⟹ P (ubasis_until P x)" apply (induct x rule: node_induct (*‹⟦?P 0; ⋀i a S. ⟦?P a; finite S; ∀b∈S. ?P b⟧ ⟹ ?P (node i a S)⟧ ⟹ ?P ?x›*)) (*goals: 1. ‹0 < ubasis_until P 0 ⟹ P (ubasis_until P 0)› 2. ‹⋀i a S. ⟦0 < ubasis_until P a ⟹ P (ubasis_until P a); finite S; ∀b∈S. 0 < ubasis_until P b ⟶ P (ubasis_until P b); 0 < ubasis_until P (node i a S)⟧ ⟹ P (ubasis_until P (node i a S))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma ubasis_until_same: "P x ⟹ ubasis_until P x = x" apply (induct x rule: node_induct (*‹⟦?P 0; ⋀i a S. ⟦?P a; finite S; ∀b∈S. ?P b⟧ ⟹ ?P (node i a S)⟧ ⟹ ?P ?x›*)) (*goals: 1. ‹P 0 ⟹ ubasis_until P 0 = 0› 2. ‹⋀i a S. ⟦P a ⟹ ubasis_until P a = a; finite S; ∀b∈S. P b ⟶ ubasis_until P b = b; P (node i a S)⟧ ⟹ ubasis_until P (node i a S) = node i a S› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma ubasis_until_idem: "P 0 ⟹ ubasis_until P (ubasis_until P x) = ubasis_until P x" by (rule ubasis_until_same [OF ubasis_until] (*‹(?P1::nat ⇒ bool) (0::nat) ⟹ ubasis_until (?P::nat ⇒ bool) (?x::nat) = ?x›*)) lemma ubasis_until_0: "∀x. x ≠ 0 ⟶ ¬ P x ⟹ ubasis_until P x = 0" apply (induct x rule: node_induct (*‹⟦(?P::nat ⇒ bool) (0::nat); ⋀(i::nat) (a::nat) S::nat set. ⟦?P a; finite S; ∀b::nat∈S. ?P b⟧ ⟹ ?P (node i a S)⟧ ⟹ ?P (?x::nat)›*)) (*goals: 1. ‹∀x. x ≠ 0 ⟶ ¬ P x ⟹ ubasis_until P 0 = 0› 2. ‹⋀i a S. ⟦∀x. x ≠ 0 ⟶ ¬ P x ⟹ ubasis_until P a = 0; finite S; ∀b∈S. (∀x. x ≠ 0 ⟶ ¬ P x) ⟶ ubasis_until P b = 0; ∀x. x ≠ 0 ⟶ ¬ P x⟧ ⟹ ubasis_until P (node i a S) = 0› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma ubasis_until_less: "ubasis_le (ubasis_until P x) x" apply (induct x rule: node_induct (*‹⟦(?P::nat ⇒ bool) (0::nat); ⋀(i::nat) (a::nat) S::nat set. ⟦?P a; finite S; ∀b::nat∈S. ?P b⟧ ⟹ ?P (node i a S)⟧ ⟹ ?P (?x::nat)›*)) (*goals: 1. ‹ubasis_le (ubasis_until (P::nat ⇒ bool) (0::nat)) (0::nat)› 2. ‹⋀(i::nat) (a::nat) S::nat set. ⟦ubasis_le (ubasis_until (P::nat ⇒ bool) a) a; finite S; ∀b::nat∈S. ubasis_le (ubasis_until P b) b⟧ ⟹ ubasis_le (ubasis_until P (node i a S)) (node i a S)› discuss goal 1*) apply (simp add: ubasis_le_refl (*‹ubasis_le ?a ?a›*)) (*discuss goal 2*) apply (simp add: ubasis_le_refl (*‹ubasis_le ?a ?a›*)) (*goal: ‹⋀(i::nat) (a::nat) S::nat set. ⟦ubasis_le (ubasis_until (P::nat ⇒ bool) a) a; finite S; ∀b::nat∈S. ubasis_le (ubasis_until P b) b⟧ ⟹ ubasis_le (ubasis_until P (node i a S)) (node i a S)›*) apply (rule impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goal: ‹⋀i a S. ⟦ubasis_le (ubasis_until P a) a; finite S; ∀b∈S. ubasis_le (ubasis_until P b) b⟧ ⟹ ¬ P (node i a S) ⟶ ubasis_le (ubasis_until P a) (node i a S)›*) apply (erule ubasis_le_trans (*‹⟦ubasis_le ?a ?b; ubasis_le ?b ?c⟧ ⟹ ubasis_le ?a ?c›*)) (*goal: ‹⋀(i::nat) (a::nat) S::nat set. ⟦ubasis_le (ubasis_until (P::nat ⇒ bool) a) a; finite S; ∀b::nat∈S. ubasis_le (ubasis_until P b) b; ¬ P (node i a S)⟧ ⟹ ubasis_le (ubasis_until P a) (node i a S)›*) apply (erule ubasis_le_lower (*‹finite (?S::nat set) ⟹ ubasis_le (?a::nat) (node (?i::nat) ?a ?S)›*)) (*proven 2 subgoals*) . lemma ubasis_until_chain: assumes PQ: "⋀x. P x ⟹ Q x" shows "ubasis_le (ubasis_until P x) (ubasis_until Q x)" apply (induct x rule: node_induct (*‹⟦?P 0; ⋀i a S. ⟦?P a; finite S; ∀b∈S. ?P b⟧ ⟹ ?P (node i a S)⟧ ⟹ ?P ?x›*)) (*goals: 1. ‹ubasis_le (ubasis_until (P::nat ⇒ bool) (0::nat)) (ubasis_until (Q::nat ⇒ bool) (0::nat))› 2. ‹⋀(i::nat) (a::nat) S::nat set. ⟦ubasis_le (ubasis_until (P::nat ⇒ bool) a) (ubasis_until (Q::nat ⇒ bool) a); finite S; ∀b::nat∈S. ubasis_le (ubasis_until P b) (ubasis_until Q b)⟧ ⟹ ubasis_le (ubasis_until P (node i a S)) (ubasis_until Q (node i a S))› discuss goal 1*) apply (simp add: ubasis_le_refl (*‹ubasis_le ?a ?a›*)) (*discuss goal 2*) apply (simp add: ubasis_le_refl (*‹ubasis_le ?a ?a›*)) (*goal: ‹⋀i a S. ⟦ubasis_le (ubasis_until P a) (ubasis_until Q a); finite S; ∀b∈S. ubasis_le (ubasis_until P b) (ubasis_until Q b)⟧ ⟹ ubasis_le (ubasis_until P (node i a S)) (ubasis_until Q (node i a S))›*) apply (simp add: PQ (*‹P ?x ⟹ Q ?x›*)) (*goal: ‹⋀(i::nat) (a::nat) S::nat set. ⟦ubasis_le (ubasis_until (P::nat ⇒ bool) a) (ubasis_until (Q::nat ⇒ bool) a); finite S; ∀b::nat∈S. ubasis_le (ubasis_until P b) (ubasis_until Q b)⟧ ⟹ (P (node i a S) ⟶ ¬ Q (node i a S) ⟶ ubasis_le (node i a S) (ubasis_until Q a)) ∧ (¬ P (node i a S) ⟶ Q (node i a S) ⟶ ubasis_le (ubasis_until P a) (node i a S))›*) apply clarify (*goal: ‹⋀i a S. ⟦ubasis_le (ubasis_until P a) (ubasis_until Q a); finite S; ∀b∈S. ubasis_le (ubasis_until P b) (ubasis_until Q b)⟧ ⟹ ¬ P (node i a S) ⟶ Q (node i a S) ⟶ ubasis_le (ubasis_until P a) (node i a S)›*) apply (rule ubasis_le_trans (*‹⟦ubasis_le ?a ?b; ubasis_le ?b ?c⟧ ⟹ ubasis_le ?a ?c›*)) (*goals: 1. ‹⋀i a S. ⟦ubasis_le (ubasis_until P a) (ubasis_until Q a); finite S; ∀b∈S. ubasis_le (ubasis_until P b) (ubasis_until Q b); ¬ P (node i a S); Q (node i a S)⟧ ⟹ ubasis_le (ubasis_until P a) (?b12 i a S)› 2. ‹⋀i a S. ⟦ubasis_le (ubasis_until P a) (ubasis_until Q a); finite S; ∀b∈S. ubasis_le (ubasis_until P b) (ubasis_until Q b); ¬ P (node i a S); Q (node i a S)⟧ ⟹ ubasis_le (?b12 i a S) (node i a S)› discuss goal 1*) apply (rule ubasis_until_less (*‹ubasis_le (ubasis_until ?P ?x) ?x›*)) (*discuss goal 2*) apply (erule ubasis_le_lower (*‹finite ?S ⟹ ubasis_le ?a (node ?i ?a ?S)›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma ubasis_until_mono: assumes "⋀i a S b. ⟦finite S; P (node i a S); b ∈ S; ubasis_le a b⟧ ⟹ P b" shows "ubasis_le a b ⟹ ubasis_le (ubasis_until P a) (ubasis_until P b)" proof (induct set: ubasis_le) (*goals: 1. ‹⋀a. ubasis_le (ubasis_until P a) (ubasis_until P a)› 2. ‹⋀a b c. ⟦ubasis_le a b; ubasis_le (ubasis_until P a) (ubasis_until P b); ubasis_le b c; ubasis_le (ubasis_until P b) (ubasis_until P c)⟧ ⟹ ubasis_le (ubasis_until P a) (ubasis_until P c)› 3. ‹⋀S a i. finite S ⟹ ubasis_le (ubasis_until P a) (ubasis_until P (node i a S))› 4. ‹⋀S b a i. ⟦finite S; b ∈ S; ubasis_le a b; ubasis_le (ubasis_until P a) (ubasis_until P b)⟧ ⟹ ubasis_le (ubasis_until P (node i a S)) (ubasis_until P b)›*) case (ubasis_le_refl a) (*no hyothesis introduced yet*) show "?case" (*goal: ‹ubasis_le (ubasis_until P a) (ubasis_until P a)›*) by (rule ubasis_le.ubasis_le_refl (*‹ubasis_le ?a ?a›*)) next (*goals: 1. ‹⋀a b c. ⟦ubasis_le a b; ubasis_le (ubasis_until P a) (ubasis_until P b); ubasis_le b c; ubasis_le (ubasis_until P b) (ubasis_until P c)⟧ ⟹ ubasis_le (ubasis_until P a) (ubasis_until P c)› 2. ‹⋀S a i. finite S ⟹ ubasis_le (ubasis_until P a) (ubasis_until P (node i a S))› 3. ‹⋀S b a i. ⟦finite S; b ∈ S; ubasis_le a b; ubasis_le (ubasis_until P a) (ubasis_until P b)⟧ ⟹ ubasis_le (ubasis_until P (node i a S)) (ubasis_until P b)›*) case (ubasis_le_trans a b c) (*‹ubasis_le a b› ‹ubasis_le (ubasis_until P a) (ubasis_until P b)› ‹ubasis_le b c› ‹ubasis_le (ubasis_until P b) (ubasis_until P c)›*) thus "?case" (*goal: ‹ubasis_le (ubasis_until P a) (ubasis_until P c)›*) apply - (*goal: ‹ubasis_le (ubasis_until P a) (ubasis_until P c)›*) apply (rule ubasis_le.ubasis_le_trans (*‹⟦ubasis_le ?a ?b; ubasis_le ?b ?c⟧ ⟹ ubasis_le ?a ?c›*)) (*goals: 1. ‹⟦ubasis_le a b; ubasis_le (ubasis_until P a) (ubasis_until P b); ubasis_le b c; ubasis_le (ubasis_until P b) (ubasis_until P c)⟧ ⟹ ubasis_le (ubasis_until P a) ?b4› 2. ‹⟦ubasis_le a b; ubasis_le (ubasis_until P a) (ubasis_until P b); ubasis_le b c; ubasis_le (ubasis_until P b) (ubasis_until P c)⟧ ⟹ ubasis_le ?b4 (ubasis_until P c)› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) next (*goals: 1. ‹⋀S a i. finite S ⟹ ubasis_le (ubasis_until P a) (ubasis_until P (node i a S))› 2. ‹⋀S b a i. ⟦finite S; b ∈ S; ubasis_le a b; ubasis_le (ubasis_until P a) (ubasis_until P b)⟧ ⟹ ubasis_le (ubasis_until P (node i a S)) (ubasis_until P b)›*) case (ubasis_le_lower S a i) (*‹finite (S::nat set)›*) thus "?case" (*goal: ‹ubasis_le (ubasis_until (P::nat ⇒ bool) (a::nat)) (ubasis_until P (node (i::nat) a (S::nat set)))›*) apply (clarsimp simp add: ubasis_le_refl (*‹ubasis_le ?a ?a›*)) (*goal: ‹ubasis_le (ubasis_until (P::nat ⇒ bool) (a::nat)) (ubasis_until P (node (i::nat) a (S::nat set)))›*) apply (rule ubasis_le_trans [OF ubasis_until_less] (*‹ubasis_le (?b::nat) (?c::nat) ⟹ ubasis_le (ubasis_until (?P1::nat ⇒ bool) ?b) ?c›*)) (*goal: ‹⟦finite S; P (node i a S)⟧ ⟹ ubasis_le (ubasis_until P a) (node i a S)›*) by (erule ubasis_le.ubasis_le_lower (*‹finite ?S ⟹ ubasis_le ?a (node ?i ?a ?S)›*)) next (*goal: ‹⋀S b a i. ⟦finite S; b ∈ S; ubasis_le a b; ubasis_le (ubasis_until P a) (ubasis_until P b)⟧ ⟹ ubasis_le (ubasis_until P (node i a S)) (ubasis_until P b)›*) case (ubasis_le_upper S b a i) (*‹finite (S::nat set)› ‹b ∈ S› ‹ubasis_le a b› ‹ubasis_le (ubasis_until P a) (ubasis_until P b)›*) thus "?case" (*goal: ‹ubasis_le (ubasis_until (P::nat ⇒ bool) (node (i::nat) (a::nat) (S::nat set))) (ubasis_until P (b::nat))›*) apply clarsimp (*goal: ‹ubasis_le (ubasis_until P (node i a S)) (ubasis_until P b)›*) apply (subst ubasis_until_same (*‹?P ?x ⟹ ubasis_until ?P ?x = ?x›*)) (*goals: 1. ‹⟦finite S; b ∈ S; ubasis_le a b; ubasis_le (ubasis_until P a) (ubasis_until P b); P (node i a S)⟧ ⟹ P b› 2. ‹⟦finite S; b ∈ S; ubasis_le a b; ubasis_le (ubasis_until P a) (ubasis_until P b); P (node i a S)⟧ ⟹ ubasis_le (node i a S) b› discuss goal 1*) apply (erule (3) assms (*‹⟦finite ?S; P (node ?i ?a ?S); ?b ∈ ?S; ubasis_le ?a ?b⟧ ⟹ P ?b›*)) (*discuss goal 2*) apply (erule (2) ubasis_le.ubasis_le_upper (*‹⟦finite ?S; ?b ∈ ?S; ubasis_le ?a ?b⟧ ⟹ ubasis_le (node ?i ?a ?S) ?b›*)) (*proven 2 subgoals*) . qed lemma finite_range_ubasis_until: "finite {x. P x} ⟹ finite (range (ubasis_until P))" apply (rule finite_subset [where B="insert 0 {x. P x}"] (*‹⟦(?A::nat set) ⊆ insert (0::nat) {x::nat. (P::nat ⇒ bool) x}; finite (insert (0::nat) {x::nat. P x})⟧ ⟹ finite ?A›*)) (*goals: 1. ‹finite {x::nat. (P::nat ⇒ bool) x} ⟹ range (ubasis_until P) ⊆ insert (0::nat) {x::nat. P x}› 2. ‹finite {x::nat. (P::nat ⇒ bool) x} ⟹ finite (insert (0::nat) {x::nat. P x})› discuss goal 1*) apply (clarsimp simp add: ubasis_until' (*‹(0::nat) < ubasis_until (?P::nat ⇒ bool) (?x::nat) ⟹ ?P (ubasis_until ?P ?x)›*)) (*discuss goal 2*) apply simp (*proven 2 subgoals*) . subsection ‹Defining the universal domain by ideal completion› typedef udom = "{S. udom.ideal S}" by (rule udom.ex_ideal) instantiation udom :: below begin definition "x ⊑ y ⟷ Rep_udom x ⊆ Rep_udom y" instance .. end instance udom :: po using type_definition_udom below_udom_def by (rule udom.typedef_ideal_po) instance udom :: cpo using type_definition_udom below_udom_def by (rule udom.typedef_ideal_cpo) definition udom_principal :: "nat ⇒ udom" where "udom_principal t = Abs_udom {u. ubasis_le u t}" lemma ubasis_countable: "∃f::ubasis ⇒ nat. inj f" apply (rule exI (*‹?P ?x ⟹ ∃x. ?P x›*)) (*goal: ‹∃f. inj f›*) by (rule inj_on_id (*‹inj_on id ?A›*)) interpretation udom: ideal_completion ubasis_le udom_principal Rep_udom using type_definition_udom (*‹type_definition Rep_udom Abs_udom (Collect udom.ideal)›*) below_udom_def (*‹((?x::udom) ⊑ (?y::udom)) = (Rep_udom ?x ⊆ Rep_udom ?y)›*) using udom_principal_def (*‹udom_principal ?t = Abs_udom {u. ubasis_le u ?t}›*) ubasis_countable (*‹∃f. inj f›*) by (rule udom.typedef_ideal_completion (*‹⟦type_definition ?Rep ?Abs (Collect udom.ideal); ⋀x y. (x ⊑ y) = (?Rep x ⊆ ?Rep y); ⋀a. ?principal a = ?Abs {b. ubasis_le b a}; ∃f. inj f⟧ ⟹ ideal_completion ubasis_le ?principal ?Rep›*)) text ‹Universal domain is pointed› lemma udom_minimal: "udom_principal 0 ⊑ x" apply (induct x rule: udom.principal_induct (*‹⟦adm ?P; ⋀a. ?P (udom_principal a)⟧ ⟹ ?P ?x›*)) (*goals: 1. ‹adm ((⊑) (udom_principal 0))› 2. ‹⋀a. udom_principal 0 ⊑ udom_principal a› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: ubasis_le_minimal (*‹ubasis_le (0::nat) (?x::nat)›*)) (*proven 2 subgoals*) . instance udom :: pcpo by intro_classes (fast intro: udom_minimal) lemma inst_udom_pcpo: "⊥ = udom_principal 0" by (rule udom_minimal [THEN bottomI, symmetric] (*‹⊥ = udom_principal 0›*)) subsection ‹Compact bases of domains› typedef 'a compact_basis = "{x::'a::pcpo. compact x}" by auto lemma Rep_compact_basis' [simp]: "compact (Rep_compact_basis a)" by (rule Rep_compact_basis [unfolded mem_Collect_eq] (*‹compact (Rep_compact_basis ?x)›*)) lemma Abs_compact_basis_inverse' [simp]: "compact x ⟹ Rep_compact_basis (Abs_compact_basis x) = x" by (rule Abs_compact_basis_inverse [unfolded mem_Collect_eq] (*‹compact (?y::?'a) ⟹ Rep_compact_basis (Abs_compact_basis ?y) = ?y›*)) instantiation compact_basis :: (pcpo) below begin definition compact_le_def: "(⊑) ≡ (λx y. Rep_compact_basis x ⊑ Rep_compact_basis y)" instance .. end instance compact_basis :: (pcpo) po using type_definition_compact_basis compact_le_def by (rule typedef_po) definition approximants :: "'a ⇒ 'a compact_basis set" where "approximants = (λx. {a. Rep_compact_basis a ⊑ x})" definition compact_bot :: "'a::pcpo compact_basis" where "compact_bot = Abs_compact_basis ⊥" lemma Rep_compact_bot [simp]: "Rep_compact_basis compact_bot = ⊥" unfolding compact_bot_def (*goal: ‹Rep_compact_basis (Abs_compact_basis ⊥) = ⊥›*) by simp lemma compact_bot_minimal [simp]: "compact_bot ⊑ a" unfolding compact_le_def Rep_compact_bot (*goal: ‹⊥ ⊑ Rep_compact_basis a›*) by simp subsection ‹Universality of \emph{udom}› text ‹We use a locale to parameterize the construction over a chain of approx functions on the type to be embedded.› locale bifinite_approx_chain = approx_chain approx for approx :: "nat ⇒ 'a::bifinite → 'a" begin subsubsection ‹Choosing a maximal element from a finite set› lemma finite_has_maximal: fixes A :: "'a compact_basis set" shows "⟦finite A; A ≠ {}⟧ ⟹ ∃x∈A. ∀y∈A. x ⊑ y ⟶ x = y" proof (induct rule: finite_ne_induct (*‹⟦finite ?F; ?F ≠ {}; ⋀x. ?P {x}; ⋀x F. ⟦finite F; F ≠ {}; x ∉ F; ?P F⟧ ⟹ ?P (insert x F)⟧ ⟹ ?P ?F›*)) (*goals: 1. ‹⋀x. ∃xa∈{x}. ∀y∈{x}. xa ⊑ y ⟶ xa = y› 2. ‹⋀x F. ⟦finite F; F ≠ {}; x ∉ F; ∃x∈F. ∀y∈F. x ⊑ y ⟶ x = y⟧ ⟹ ∃xa∈insert x F. ∀y∈insert x F. xa ⊑ y ⟶ xa = y›*) case (singleton x) (*no hyothesis introduced yet*) show "?case" (*goal: ‹∃xa∈{x}. ∀y∈{x}. xa ⊑ y ⟶ xa = y›*) by simp next (*goal: ‹⋀(x::'a compact_basis) F::'a compact_basis set. ⟦finite F; F ≠ {}; x ∉ F; ∃x::'a compact_basis∈F. ∀y::'a compact_basis∈F. x ⊑ y ⟶ x = y⟧ ⟹ ∃xa::'a compact_basis∈insert x F. ∀y::'a compact_basis∈insert x F. xa ⊑ y ⟶ xa = y›*) case (insert a A) (*‹finite (A::'a compact_basis set)› ‹A ≠ {}› ‹a ∉ A› ‹∃x∈A. ∀y∈A. x ⊑ y ⟶ x = y›*) from ‹∃x∈A. ∀y∈A. x ⊑ y ⟶ x = y› (*‹∃x∈A. ∀y∈A. x ⊑ y ⟶ x = y›*) obtain x where x: "x ∈ A" and x_eq: "⋀y. ⟦y ∈ A; x ⊑ y⟧ ⟹ x = y" (*goal: ‹(⋀x. ⟦x ∈ A; ⋀y. ⟦y ∈ A; x ⊑ y⟧ ⟹ x = y⟧ ⟹ thesis) ⟹ thesis›*) by fast show "?case" (*goal: ‹∃x∈insert a A. ∀y∈insert a A. x ⊑ y ⟶ x = y›*) proof (intro bexI (*‹⟦?P ?x; ?x ∈ ?A⟧ ⟹ ∃x∈?A. ?P x›*) ballI (*‹(⋀x. x ∈ ?A ⟹ ?P x) ⟹ ∀x∈?A. ?P x›*) impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goals: 1. ‹⋀y::'a compact_basis. ⟦y ∈ insert (a::'a compact_basis) (A::'a compact_basis set); (?x::'a compact_basis) ⊑ y⟧ ⟹ ?x = y› 2. ‹(?x::'a compact_basis) ∈ insert (a::'a compact_basis) (A::'a compact_basis set)›*) fix y assume "y ∈ insert a A" and "(if x ⊑ a then a else x) ⊑ y" (*‹(y::'a compact_basis) ∈ insert (a::'a compact_basis) (A::'a compact_basis set)› ‹(if (x::'a compact_basis) ⊑ (a::'a compact_basis) then a else x) ⊑ (y::'a compact_basis)›*) thus "(if x ⊑ a then a else x) = y" apply auto (*goals: 1. ‹⟦a ⊑ y; y ∈ A; x ⊑ a⟧ ⟹ a = y› 2. ‹⟦x ⊑ y; y ∈ A; x \<notsqsubseteq> a⟧ ⟹ x = y› discuss goal 1*) apply (frule (1) below_trans (*‹⟦?x ⊑ ?y; ?y ⊑ ?z⟧ ⟹ ?x ⊑ ?z›*)) (*top goal: ‹⟦a ⊑ y; y ∈ A; x ⊑ a⟧ ⟹ a = y› and 1 goal remains*) apply (frule (1) x_eq (*‹⟦?y ∈ A; x ⊑ ?y⟧ ⟹ x = ?y›*)) (*top goal: ‹⟦a ⊑ y; y ∈ A; x ⊑ a; x ⊑ y⟧ ⟹ a = y› and 1 goal remains*) apply (rule below_antisym (*‹⟦(?x::?'a) ⊑ (?y::?'a); ?y ⊑ ?x⟧ ⟹ ?x = ?y›*)) (*goals: 1. ‹⟦(a::'a::bifinite compact_basis) ⊑ (y::'a::bifinite compact_basis); y ∈ (A::'a::bifinite compact_basis set); (x::'a::bifinite compact_basis) ⊑ a; x ⊑ y; x = y⟧ ⟹ a ⊑ y› 2. ‹⟦(a::'a::bifinite compact_basis) ⊑ (y::'a::bifinite compact_basis); y ∈ (A::'a::bifinite compact_basis set); (x::'a::bifinite compact_basis) ⊑ a; x ⊑ y; x = y⟧ ⟹ y ⊑ a› discuss goal 1*) apply assumption (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (erule (1) x_eq (*‹⟦?y ∈ A; x ⊑ ?y⟧ ⟹ x = ?y›*)) (*proven 2 subgoals*) . next (*goal: ‹(if (x::'a compact_basis) ⊑ (a::'a compact_basis) then a else x) ∈ insert a (A::'a compact_basis set)›*) show "(if x ⊑ a then a else x) ∈ insert a A" by (simp add: x (*‹x ∈ A›*)) qed qed definition choose :: "'a compact_basis set ⇒ 'a compact_basis" where "choose A = (SOME x. x ∈ {x∈A. ∀y∈A. x ⊑ y ⟶ x = y})" lemma choose_lemma: "⟦finite A; A ≠ {}⟧ ⟹ choose A ∈ {x∈A. ∀y∈A. x ⊑ y ⟶ x = y}" unfolding choose_def (*goal: ‹⟦finite (A::'a compact_basis set); A ≠ {}⟧ ⟹ (SOME x::'a compact_basis. x ∈ {x::'a compact_basis ∈ A. ∀y::'a compact_basis∈A. x ⊑ y ⟶ x = y}) ∈ {x::'a compact_basis ∈ A. ∀y::'a compact_basis∈A. x ⊑ y ⟶ x = y}›*) apply (rule someI_ex (*‹∃x. ?P x ⟹ ?P (SOME x. ?P x)›*)) (*goal: ‹⟦finite A; A ≠ {}⟧ ⟹ (SOME x. x ∈ {x ∈ A. ∀y∈A. x ⊑ y ⟶ x = y}) ∈ {x ∈ A. ∀y∈A. x ⊑ y ⟶ x = y}›*) apply (frule (1) finite_has_maximal (*‹⟦finite ?A; ?A ≠ {}⟧ ⟹ ∃x∈?A. ∀y∈?A. x ⊑ y ⟶ x = y›*)) (*goal: ‹⟦finite A; A ≠ {}⟧ ⟹ ∃x. x ∈ {x ∈ A. ∀y∈A. x ⊑ y ⟶ x = y}›*) by fast lemma maximal_choose: "⟦finite A; y ∈ A; choose A ⊑ y⟧ ⟹ choose A = y" apply (cases "A = {}") (*goals: 1. ‹⟦finite A; y ∈ A; choose A ⊑ y; A = {}⟧ ⟹ choose A = y› 2. ‹⟦finite A; y ∈ A; choose A ⊑ y; A ≠ {}⟧ ⟹ choose A = y› discuss goal 1*) apply simp (*discuss goal 2*) apply (frule (1) choose_lemma (*‹⟦finite (?A::'a compact_basis set); ?A ≠ {}⟧ ⟹ choose ?A ∈ {x::'a compact_basis ∈ ?A. ∀y::'a compact_basis∈?A. x ⊑ y ⟶ x = y}›*)) (*goal: ‹⟦finite A; y ∈ A; choose A ⊑ y; A ≠ {}⟧ ⟹ choose A = y›*) apply simp (*proven 2 subgoals*) . lemma choose_in: "⟦finite A; A ≠ {}⟧ ⟹ choose A ∈ A" apply (frule (1) choose_lemma (*‹⟦finite ?A; ?A ≠ {}⟧ ⟹ choose ?A ∈ {x ∈ ?A. ∀y∈?A. x ⊑ y ⟶ x = y}›*)) (*goal: ‹⟦finite A; A ≠ {}⟧ ⟹ choose A ∈ A›*) by simp function choose_pos :: "'a compact_basis set ⇒ 'a compact_basis ⇒ nat" where "choose_pos A x = (if finite A ∧ x ∈ A ∧ x ≠ choose A then Suc (choose_pos (A - {choose A}) x) else 0)" by auto termination choose_pos apply (relation "measure (card ∘ fst)", simp) apply clarsimp apply (rule card_Diff1_less) apply assumption apply (erule choose_in) apply clarsimp done declare choose_pos.simps [simp del] lemma choose_pos_choose: "finite A ⟹ choose_pos A (choose A) = 0" by (simp add: choose_pos.simps (*‹choose_pos ?A ?x = (if finite ?A ∧ ?x ∈ ?A ∧ ?x ≠ choose ?A then Suc (choose_pos (?A - {choose ?A}) ?x) else 0)›*)) lemma inj_on_choose_pos [OF refl]: "⟦card A = n; finite A⟧ ⟹ inj_on (choose_pos A) A" apply (induct n arbitrary: A) (*goals: 1. ‹⋀A. ⟦card A = 0; finite A⟧ ⟹ inj_on (choose_pos A) A› 2. ‹⋀n A. ⟦⋀A. ⟦card A = n; finite A⟧ ⟹ inj_on (choose_pos A) A; card A = Suc n; finite A⟧ ⟹ inj_on (choose_pos A) A› discuss goal 1*) apply simp (*discuss goal 2*) apply (case_tac "A = {}") (*goals: 1. ‹⋀n A. ⟦⋀A. ⟦card A = n; finite A⟧ ⟹ inj_on (choose_pos A) A; card A = Suc n; finite A; A = {}⟧ ⟹ inj_on (choose_pos A) A› 2. ‹⋀n A. ⟦⋀A. ⟦card A = n; finite A⟧ ⟹ inj_on (choose_pos A) A; card A = Suc n; finite A; A ≠ {}⟧ ⟹ inj_on (choose_pos A) A› discuss goal 1*) apply simp (*discuss goal 2*) apply (frule (1) choose_in (*‹⟦finite ?A; ?A ≠ {}⟧ ⟹ choose ?A ∈ ?A›*)) (*goal: ‹⋀n A. ⟦⋀A. ⟦card A = n; finite A⟧ ⟹ inj_on (choose_pos A) A; card A = Suc n; finite A; A ≠ {}⟧ ⟹ inj_on (choose_pos A) A›*) apply (rule inj_onI (*‹(⋀(x::?'a) y::?'a. ⟦x ∈ (?A::?'a set); y ∈ ?A; (?f::?'a ⇒ ?'b) x = ?f y⟧ ⟹ x = y) ⟹ inj_on ?f ?A›*)) (*goal: ‹⋀n A. ⟦⋀A. ⟦card A = n; finite A⟧ ⟹ inj_on (choose_pos A) A; card A = Suc n; finite A; A ≠ {}; choose A ∈ A⟧ ⟹ inj_on (choose_pos A) A›*) apply (drule_tac x="A - {choose A}" in meta_spec (*‹(⋀x. PROP ?P x) ⟹ PROP ?P ?x›*)) (*goal: ‹⋀n A x y. ⟦⋀A. ⟦card A = n; finite A⟧ ⟹ inj_on (choose_pos A) A; card A = Suc n; finite A; A ≠ {}; choose A ∈ A; x ∈ A; y ∈ A; choose_pos A x = choose_pos A y⟧ ⟹ x = y›*) apply simp (*goal: ‹⋀n A x y. ⟦card A = Suc n; finite A; A ≠ {}; choose A ∈ A; x ∈ A; y ∈ A; choose_pos A x = choose_pos A y; ⟦card (A - {choose A}) = n; finite (A - {choose A})⟧ ⟹ inj_on (choose_pos (A - {choose A})) (A - {choose A})⟧ ⟹ x = y›*) apply (simp add: choose_pos.simps (*‹choose_pos (?A::'a::bifinite compact_basis set) (?x::'a::bifinite compact_basis) = (if finite ?A ∧ ?x ∈ ?A ∧ ?x ≠ choose ?A then Suc (choose_pos (?A - {choose ?A}) ?x) else (0::nat))›*)) (*goal: ‹⋀(n::nat) (A::'a::bifinite compact_basis set) (x::'a::bifinite compact_basis) y::'a::bifinite compact_basis. ⟦card A = Suc n; finite A; A ≠ {}; choose A ∈ A; x ∈ A; y ∈ A; choose_pos A x = choose_pos A y; inj_on (choose_pos (A - {choose A})) (A - {choose A})⟧ ⟹ x = y›*) apply (simp split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) (*goal: ‹⋀n A x y. ⟦card A = Suc n; finite A; A ≠ {}; choose A ∈ A; x ∈ A; y ∈ A; (if x ≠ choose A then Suc (choose_pos (A - {choose A}) x) else 0) = (if y ≠ choose A then Suc (choose_pos (A - {choose A}) y) else 0); inj_on (choose_pos (A - {choose A})) (A - {choose A})⟧ ⟹ x = y›*) apply (erule (1) inj_onD (*‹⟦inj_on ?f ?A; ?f ?x = ?f ?y; ?x ∈ ?A; ?y ∈ ?A⟧ ⟹ ?x = ?y›*)) (*goals: 1. ‹⋀n A x y. ⟦card A = Suc n; finite A; A ≠ {}; choose A ∈ A; x ∈ A; y ∈ A; y ≠ choose A; x ≠ choose A; choose_pos (A - {choose A}) x = choose_pos (A - {choose A}) y⟧ ⟹ x ∈ A - {choose A}› 2. ‹⋀n A x y. ⟦card A = Suc n; finite A; A ≠ {}; choose A ∈ A; x ∈ A; y ∈ A; y ≠ choose A; x ≠ choose A; choose_pos (A - {choose A}) x = choose_pos (A - {choose A}) y⟧ ⟹ y ∈ A - {choose A}› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma choose_pos_bounded [OF refl]: "⟦card A = n; finite A; x ∈ A⟧ ⟹ choose_pos A x < n" apply (induct n arbitrary: A) (*goals: 1. ‹⋀A. ⟦card A = 0; finite A; x ∈ A⟧ ⟹ choose_pos A x < 0› 2. ‹⋀n A. ⟦⋀A. ⟦card A = n; finite A; x ∈ A⟧ ⟹ choose_pos A x < n; card A = Suc n; finite A; x ∈ A⟧ ⟹ choose_pos A x < Suc n› discuss goal 1*) apply simp (*discuss goal 2*) apply (case_tac "A = {}") (*goals: 1. ‹⋀n A. ⟦⋀A. ⟦card A = n; finite A; x ∈ A⟧ ⟹ choose_pos A x < n; card A = Suc n; finite A; x ∈ A; A = {}⟧ ⟹ choose_pos A x < Suc n› 2. ‹⋀n A. ⟦⋀A. ⟦card A = n; finite A; x ∈ A⟧ ⟹ choose_pos A x < n; card A = Suc n; finite A; x ∈ A; A ≠ {}⟧ ⟹ choose_pos A x < Suc n› discuss goal 1*) apply simp (*discuss goal 2*) apply (frule (1) choose_in (*‹⟦finite (?A::'a::bifinite compact_basis set); ?A ≠ {}⟧ ⟹ choose ?A ∈ ?A›*)) (*goal: ‹⋀n A. ⟦⋀A. ⟦card A = n; finite A; x ∈ A⟧ ⟹ choose_pos A x < n; card A = Suc n; finite A; x ∈ A; A ≠ {}⟧ ⟹ choose_pos A x < Suc n›*) apply (subst choose_pos.simps (*‹choose_pos ?A ?x = (if finite ?A ∧ ?x ∈ ?A ∧ ?x ≠ choose ?A then Suc (choose_pos (?A - {choose ?A}) ?x) else 0)›*)) (*goal: ‹⋀n A. ⟦⋀A. ⟦card A = n; finite A; x ∈ A⟧ ⟹ choose_pos A x < n; card A = Suc n; finite A; x ∈ A; A ≠ {}; choose A ∈ A⟧ ⟹ choose_pos A x < Suc n›*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma choose_pos_lessD: "⟦choose_pos A x < choose_pos A y; finite A; x ∈ A; y ∈ A⟧ ⟹ x \<notsqsubseteq> y" apply (induct A x arbitrary: y rule: choose_pos.induct) (*goal: ‹⟦choose_pos A x < choose_pos A y; finite A; x ∈ A; y ∈ A⟧ ⟹ x \<notsqsubseteq> y›*) apply simp (*goal: ‹⋀A x y. ⟦⋀y. ⟦finite A ∧ x ∈ A ∧ x ≠ choose A; choose_pos (A - {choose A}) x < choose_pos (A - {choose A}) y; finite (A - {choose A}); x ∈ A - {choose A}; y ∈ A - {choose A}⟧ ⟹ x \<notsqsubseteq> y; choose_pos A x < choose_pos A y; finite A; x ∈ A; y ∈ A⟧ ⟹ x \<notsqsubseteq> y›*) apply (case_tac "x = choose A") (*goals: 1. ‹⋀A x y. ⟦⋀y. ⟦x ≠ choose A; choose_pos (A - {choose A}) x < choose_pos (A - {choose A}) y; y ∈ A ∧ y ≠ choose A⟧ ⟹ x \<notsqsubseteq> y; choose_pos A x < choose_pos A y; finite A; x ∈ A; y ∈ A; x = choose A⟧ ⟹ x \<notsqsubseteq> y› 2. ‹⋀A x y. ⟦⋀y. ⟦x ≠ choose A; choose_pos (A - {choose A}) x < choose_pos (A - {choose A}) y; y ∈ A ∧ y ≠ choose A⟧ ⟹ x \<notsqsubseteq> y; choose_pos A x < choose_pos A y; finite A; x ∈ A; y ∈ A; x ≠ choose A⟧ ⟹ x \<notsqsubseteq> y› discuss goal 1*) apply simp (*top goal: ‹⋀A x y. ⟦⋀y. ⟦x ≠ choose A; choose_pos (A - {choose A}) x < choose_pos (A - {choose A}) y; y ∈ A ∧ y ≠ choose A⟧ ⟹ x \<notsqsubseteq> y; choose_pos A x < choose_pos A y; finite A; x ∈ A; y ∈ A; x = choose A⟧ ⟹ x \<notsqsubseteq> y› and 1 goal remains*) apply (rule notI (*‹(?P::bool ⟹ False) ⟹ ¬ ?P›*)) (*top goal: ‹⋀A x y. ⟦choose_pos A (choose A) < choose_pos A y; finite A; choose A ∈ A; y ∈ A; x = choose A⟧ ⟹ choose A \<notsqsubseteq> y› and 1 goal remains*) apply (frule (2) maximal_choose (*‹⟦finite ?A; ?y ∈ ?A; choose ?A ⊑ ?y⟧ ⟹ choose ?A = ?y›*)) (*top goal: ‹⋀A x y. ⟦choose_pos A (choose A) < choose_pos A y; finite A; choose A ∈ A; y ∈ A; x = choose A; choose A ⊑ y⟧ ⟹ False› and 1 goal remains*) apply simp (*discuss goal 2*) apply (case_tac "y = choose A") (*goals: 1. ‹⋀A x y. ⟦⋀y. ⟦x ≠ choose A; choose_pos (A - {choose A}) x < choose_pos (A - {choose A}) y; y ∈ A ∧ y ≠ choose A⟧ ⟹ x \<notsqsubseteq> y; choose_pos A x < choose_pos A y; finite A; x ∈ A; y ∈ A; x ≠ choose A; y = choose A⟧ ⟹ x \<notsqsubseteq> y› 2. ‹⋀A x y. ⟦⋀y. ⟦x ≠ choose A; choose_pos (A - {choose A}) x < choose_pos (A - {choose A}) y; y ∈ A ∧ y ≠ choose A⟧ ⟹ x \<notsqsubseteq> y; choose_pos A x < choose_pos A y; finite A; x ∈ A; y ∈ A; x ≠ choose A; y ≠ choose A⟧ ⟹ x \<notsqsubseteq> y› discuss goal 1*) apply (simp add: choose_pos_choose (*‹finite ?A ⟹ choose_pos ?A (choose ?A) = 0›*)) (*discuss goal 2*) apply (drule_tac x=y in meta_spec (*‹(⋀x. PROP ?P x) ⟹ PROP ?P ?x›*)) (*goal: ‹⋀(A::'a::bifinite compact_basis set) (x::'a::bifinite compact_basis) y::'a::bifinite compact_basis. ⟦⋀y::'a::bifinite compact_basis. ⟦x ≠ choose A; choose_pos (A - {choose A}) x < choose_pos (A - {choose A}) y; y ∈ A ∧ y ≠ choose A⟧ ⟹ x \<notsqsubseteq> y; choose_pos A x < choose_pos A y; finite A; x ∈ A; y ∈ A; x ≠ choose A; y ≠ choose A⟧ ⟹ x \<notsqsubseteq> y›*) apply simp (*goal: ‹⋀A x y. ⟦choose_pos A x < choose_pos A y; finite A; x ∈ A; y ∈ A; x ≠ choose A; y ≠ choose A; ⟦x ≠ choose A; choose_pos (A - {choose A}) x < choose_pos (A - {choose A}) y; y ∈ A ∧ y ≠ choose A⟧ ⟹ x \<notsqsubseteq> y⟧ ⟹ x \<notsqsubseteq> y›*) apply (erule meta_mp (*‹⟦PROP ?P ⟹ PROP ?Q; PROP ?P⟧ ⟹ PROP ?Q›*)) (*goal: ‹⋀A x y. ⟦choose_pos A x < choose_pos A y; finite A; x ∈ A; y ∈ A; x ≠ choose A; y ≠ choose A; choose_pos (A - {choose A}) x < choose_pos (A - {choose A}) y ⟹ x \<notsqsubseteq> y⟧ ⟹ x \<notsqsubseteq> y›*) apply (simp add: choose_pos.simps (*‹choose_pos ?A ?x = (if finite ?A ∧ ?x ∈ ?A ∧ ?x ≠ choose ?A then Suc (choose_pos (?A - {choose ?A}) ?x) else 0)›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) . subsubsection ‹Compact basis take function› primrec cb_take :: "nat ⇒ 'a compact_basis ⇒ 'a compact_basis" where "cb_take 0 = (λx. compact_bot)" | "cb_take (Suc n) = (λa. Abs_compact_basis (approx n⋅(Rep_compact_basis a)))" declare cb_take.simps [simp del] lemma cb_take_zero [simp]: "cb_take 0 a = compact_bot" by (simp only: cb_take.simps (*‹cb_take 0 = (λx. compact_bot)› ‹cb_take (Suc ?n) = (λa. Abs_compact_basis (approx ?n⋅(Rep_compact_basis a)))›*)) lemma Rep_cb_take: "Rep_compact_basis (cb_take (Suc n) a) = approx n⋅(Rep_compact_basis a)" by (simp add: cb_take.simps( (*‹cb_take (Suc ?n) = (λa. Abs_compact_basis (approx ?n⋅(Rep_compact_basis a)))›*) 2)) lemmas approx_Rep_compact_basis = Rep_cb_take [symmetric] lemma cb_take_covers: "∃n. cb_take n x = x" apply (subgoal_tac "∃n. cb_take (Suc n) x = x") (*goals: 1. ‹∃n. cb_take (Suc n) x = x ⟹ ∃n. cb_take n x = x› 2. ‹∃n. cb_take (Suc n) x = x› discuss goal 1*) apply fast (*discuss goal 2*) apply (simp add: Rep_compact_basis_inject [symmetric] (*‹(?x = ?y) = (Rep_compact_basis ?x = Rep_compact_basis ?y)›*)) (*goal: ‹∃n. cb_take (Suc n) x = x›*) apply (simp add: Rep_cb_take (*‹Rep_compact_basis (cb_take (Suc ?n) ?a) = approx ?n⋅(Rep_compact_basis ?a)›*)) (*goal: ‹∃n. Rep_compact_basis (cb_take (Suc n) x) = Rep_compact_basis x›*) apply (rule compact_eq_approx (*‹compact ?x ⟹ ∃i. approx i⋅?x = ?x›*)) (*goal: ‹∃n::nat. (approx::nat ⇒ 'a → 'a) n⋅(Rep_compact_basis (x::'a compact_basis)) = Rep_compact_basis x›*) apply (rule Rep_compact_basis' (*‹compact (Rep_compact_basis (?a::?'a compact_basis))›*)) (*proven 2 subgoals*) . lemma cb_take_less: "cb_take n x ⊑ x" unfolding compact_le_def (*goal: ‹Rep_compact_basis (cb_take (n::nat) (x::'a::bifinite compact_basis)) ⊑ Rep_compact_basis x›*) apply (cases n) (*goals: 1. ‹(n::nat) = (0::nat) ⟹ Rep_compact_basis (cb_take n (x::'a compact_basis)) ⊑ Rep_compact_basis x› 2. ‹⋀nat::nat. (n::nat) = Suc nat ⟹ Rep_compact_basis (cb_take n (x::'a compact_basis)) ⊑ Rep_compact_basis x› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: Rep_cb_take (*‹Rep_compact_basis (cb_take (Suc ?n) ?a) = approx ?n⋅(Rep_compact_basis ?a)›*) approx_below (*‹approx ?i⋅?x ⊑ ?x›*)) (*proven 2 subgoals*) . lemma cb_take_idem: "cb_take n (cb_take n x) = cb_take n x" unfolding Rep_compact_basis_inject[symmetric] (*goal: ‹Rep_compact_basis (cb_take n (cb_take n x)) = Rep_compact_basis (cb_take n x)›*) apply (cases n) (*goals: 1. ‹(n::nat) = (0::nat) ⟹ Rep_compact_basis (cb_take n (cb_take n (x::'a compact_basis))) = Rep_compact_basis (cb_take n x)› 2. ‹⋀nat::nat. (n::nat) = Suc nat ⟹ Rep_compact_basis (cb_take n (cb_take n (x::'a compact_basis))) = Rep_compact_basis (cb_take n x)› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: Rep_cb_take (*‹Rep_compact_basis (cb_take (Suc ?n) ?a) = approx ?n⋅(Rep_compact_basis ?a)›*) approx_idem (*‹approx ?i⋅(approx ?i⋅?x) = approx ?i⋅?x›*)) (*proven 2 subgoals*) . lemma cb_take_mono: "x ⊑ y ⟹ cb_take n x ⊑ cb_take n y" unfolding compact_le_def (*goal: ‹Rep_compact_basis x ⊑ Rep_compact_basis y ⟹ Rep_compact_basis (cb_take n x) ⊑ Rep_compact_basis (cb_take n y)›*) apply (cases n) (*goals: 1. ‹⟦Rep_compact_basis x ⊑ Rep_compact_basis y; n = 0⟧ ⟹ Rep_compact_basis (cb_take n x) ⊑ Rep_compact_basis (cb_take n y)› 2. ‹⋀nat. ⟦Rep_compact_basis x ⊑ Rep_compact_basis y; n = Suc nat⟧ ⟹ Rep_compact_basis (cb_take n x) ⊑ Rep_compact_basis (cb_take n y)› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: Rep_cb_take (*‹Rep_compact_basis (cb_take (Suc ?n) ?a) = approx ?n⋅(Rep_compact_basis ?a)›*) monofun_cfun_arg (*‹?x ⊑ ?y ⟹ ?f⋅?x ⊑ ?f⋅?y›*)) (*proven 2 subgoals*) . lemma cb_take_chain_le: "m ≤ n ⟹ cb_take m x ⊑ cb_take n x" unfolding compact_le_def (*goal: ‹m ≤ n ⟹ Rep_compact_basis (cb_take m x) ⊑ Rep_compact_basis (cb_take n x)›*) apply (cases m) (*goals: 1. ‹⟦m ≤ n; m = 0⟧ ⟹ Rep_compact_basis (cb_take m x) ⊑ Rep_compact_basis (cb_take n x)› 2. ‹⋀nat. ⟦m ≤ n; m = Suc nat⟧ ⟹ Rep_compact_basis (cb_take m x) ⊑ Rep_compact_basis (cb_take n x)› discuss goal 1*) apply simp (*discuss goal 2*) apply (cases n) (*goals: 1. ‹⋀nat. ⟦m ≤ n; m = Suc nat; n = 0⟧ ⟹ Rep_compact_basis (cb_take m x) ⊑ Rep_compact_basis (cb_take n x)› 2. ‹⋀nat nata. ⟦m ≤ n; m = Suc nat; n = Suc nata⟧ ⟹ Rep_compact_basis (cb_take m x) ⊑ Rep_compact_basis (cb_take n x)› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: Rep_cb_take (*‹Rep_compact_basis (cb_take (Suc ?n) ?a) = approx ?n⋅(Rep_compact_basis ?a)›*)) (*goal: ‹⋀(nat::nat) nata::nat. ⟦(m::nat) ≤ (n::nat); m = Suc nat; n = Suc nata⟧ ⟹ Rep_compact_basis (cb_take m (x::'a compact_basis)) ⊑ Rep_compact_basis (cb_take n x)›*) apply (rule chain_mono (*‹⟦chain (?Y::nat ⇒ ?'a::po); (?i::nat) ≤ (?j::nat)⟧ ⟹ ?Y ?i ⊑ ?Y ?j›*)) (*goals: 1. ‹⋀nat nata. ⟦nat ≤ nata; m = Suc nat; n = Suc nata⟧ ⟹ chain (λa. approx a⋅(Rep_compact_basis x))› 2. ‹⋀nat nata. ⟦nat ≤ nata; m = Suc nat; n = Suc nata⟧ ⟹ nat ≤ nata› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma finite_range_cb_take: "finite (range (cb_take n))" apply (cases n) (*goals: 1. ‹n = 0 ⟹ finite (range (cb_take n))› 2. ‹⋀nat. n = Suc nat ⟹ finite (range (cb_take n))› discuss goal 1*) apply (subgoal_tac "range (cb_take 0) = {compact_bot}") (*goals: 1. ‹⟦n = 0; range (cb_take 0) = {compact_bot}⟧ ⟹ finite (range (cb_take n))› 2. ‹n = 0 ⟹ range (cb_take 0) = {compact_bot}› discuss goal 1*) apply simp (*discuss goal 2*) apply force (*proven 2 subgoals*) (*discuss goal 2*) apply (rule finite_imageD [where f="Rep_compact_basis"] (*‹⟦finite (Rep_compact_basis ` (?A::?'b1 compact_basis set)); inj_on Rep_compact_basis ?A⟧ ⟹ finite ?A›*)) (*goals: 1. ‹⋀nat. n = Suc nat ⟹ finite (Rep_compact_basis ` range (cb_take n))› 2. ‹⋀nat. n = Suc nat ⟹ inj_on Rep_compact_basis (range (cb_take n))› discuss goal 1*) apply (rule finite_subset [where B="range (λx. approx (n - 1)⋅x)"] (*‹⟦?A ⊆ range (Rep_cfun (approx (n - 1))); finite (range (Rep_cfun (approx (n - 1))))⟧ ⟹ finite ?A›*)) (*goals: 1. ‹⋀nat. n = Suc nat ⟹ Rep_compact_basis ` range (cb_take n) ⊆ range (Rep_cfun (approx (n - 1)))› 2. ‹⋀nat. n = Suc nat ⟹ finite (range (Rep_cfun (approx (n - 1))))› discuss goal 1*) apply (clarsimp simp add: Rep_cb_take (*‹Rep_compact_basis (cb_take (Suc ?n) ?a) = approx ?n⋅(Rep_compact_basis ?a)›*)) (*discuss goal 2*) apply (rule finite_range_approx (*‹finite (range (Rep_cfun (approx ?i)))›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply (rule inj_onI (*‹(⋀(x::?'a) y::?'a. ⟦x ∈ (?A::?'a set); y ∈ ?A; (?f::?'a ⇒ ?'b) x = ?f y⟧ ⟹ x = y) ⟹ inj_on ?f ?A›*)) (*goal: ‹⋀nat::nat. (n::nat) = Suc nat ⟹ inj_on Rep_compact_basis (range (cb_take n))›*) apply (simp add: Rep_compact_basis_inject (*‹(Rep_compact_basis (?x::?'a compact_basis) = Rep_compact_basis (?y::?'a compact_basis)) = (?x = ?y)›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) . subsubsection ‹Rank of basis elements› definition rank :: "'a compact_basis ⇒ nat" where "rank x = (LEAST n. cb_take n x = x)" lemma compact_approx_rank: "cb_take (rank x) x = x" unfolding rank_def (*goal: ‹cb_take (LEAST n::nat. cb_take n (x::'a::bifinite compact_basis) = x) x = x›*) apply (rule LeastI_ex (*‹∃x. ?P x ⟹ ?P (Least ?P)›*)) (*goal: ‹cb_take (LEAST n::nat. cb_take n (x::'a::bifinite compact_basis) = x) x = x›*) by (rule cb_take_covers (*‹∃n::nat. cb_take n (?x::'a compact_basis) = ?x›*)) lemma rank_leD: "rank x ≤ n ⟹ cb_take n x = x" apply (rule below_antisym [OF cb_take_less] (*‹?y ⊑ cb_take ?n1 ?y ⟹ cb_take ?n1 ?y = ?y›*)) (*goal: ‹rank x ≤ n ⟹ cb_take n x = x›*) apply (subst compact_approx_rank [symmetric] (*‹?t = cb_take (rank ?t) ?t›*)) (*goal: ‹rank x ≤ n ⟹ x ⊑ cb_take n x›*) by (erule cb_take_chain_le (*‹?m ≤ ?n ⟹ cb_take ?m ?x ⊑ cb_take ?n ?x›*)) lemma rank_leI: "cb_take n x = x ⟹ rank x ≤ n" unfolding rank_def (*goal: ‹cb_take (n::nat) (x::'a::bifinite compact_basis) = x ⟹ (LEAST n::nat. cb_take n x = x) ≤ n›*) by (rule Least_le (*‹?P ?k ⟹ (LEAST x. ?P x) ≤ ?k›*)) lemma rank_le_iff: "rank x ≤ n ⟷ cb_take n x = x" apply (rule iffI [OF rank_leD rank_leI] (*‹⟦rank ?x1 ≤ ?n1 ⟹ rank ?x2 ≤ ?n2; cb_take ?n2 ?x2 = ?x2 ⟹ cb_take ?n1 ?x1 = ?x1⟧ ⟹ (rank ?x1 ≤ ?n1) = (cb_take ?n2 ?x2 = ?x2)›*)) (*goals: 1. ‹rank x ≤ n ⟹ rank x ≤ n› 2. ‹cb_take n x = x ⟹ cb_take n x = x› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) lemma rank_compact_bot [simp]: "rank compact_bot = 0" using rank_leI[of 0 compact_bot] (*‹cb_take 0 compact_bot = compact_bot ⟹ rank compact_bot ≤ 0›*) by simp lemma rank_eq_0_iff [simp]: "rank x = 0 ⟷ x = compact_bot" using rank_le_iff[of x 0] (*‹(rank x ≤ 0) = (cb_take 0 x = x)›*) by auto definition rank_le :: "'a compact_basis ⇒ 'a compact_basis set" where "rank_le x = {y. rank y ≤ rank x}" definition rank_lt :: "'a compact_basis ⇒ 'a compact_basis set" where "rank_lt x = {y. rank y < rank x}" definition rank_eq :: "'a compact_basis ⇒ 'a compact_basis set" where "rank_eq x = {y. rank y = rank x}" lemma rank_eq_cong: "rank x = rank y ⟹ rank_eq x = rank_eq y" unfolding rank_eq_def (*goal: ‹rank x = rank y ⟹ {y. rank y = rank x} = {ya. rank ya = rank y}›*) by simp lemma rank_lt_cong: "rank x = rank y ⟹ rank_lt x = rank_lt y" unfolding rank_lt_def (*goal: ‹rank x = rank y ⟹ {y. rank y < rank x} = {ya. rank ya < rank y}›*) by simp lemma rank_eq_subset: "rank_eq x ⊆ rank_le x" unfolding rank_eq_def rank_le_def (*goal: ‹{y. rank y = rank x} ⊆ {y. rank y ≤ rank x}›*) by auto lemma rank_lt_subset: "rank_lt x ⊆ rank_le x" unfolding rank_lt_def rank_le_def (*goal: ‹{y. rank y < rank x} ⊆ {y. rank y ≤ rank x}›*) by auto lemma finite_rank_le: "finite (rank_le x)" unfolding rank_le_def (*goal: ‹finite {y::'a compact_basis. rank y ≤ rank (x::'a compact_basis)}›*) apply (rule finite_subset [where B="range (cb_take (rank x))"] (*‹⟦?A ⊆ range (cb_take (rank x)); finite (range (cb_take (rank x)))⟧ ⟹ finite ?A›*)) (*goals: 1. ‹{y::'a compact_basis. rank y ≤ rank (x::'a compact_basis)} ⊆ range (cb_take (rank x))› 2. ‹finite (range (cb_take (rank (x::'a compact_basis))))› discuss goal 1*) apply clarify (*top goal: ‹{y. rank y ≤ rank x} ⊆ range (cb_take (rank x))› and 1 goal remains*) apply (rule range_eqI (*‹?b = ?f ?x ⟹ ?b ∈ range ?f›*)) (*top goal: ‹⋀xa::'a compact_basis. rank xa ≤ rank (x::'a compact_basis) ⟹ xa ∈ range (cb_take (rank x))› and 1 goal remains*) apply (erule rank_leD [symmetric] (*‹rank ?t ≤ ?n ⟹ ?t = cb_take ?n ?t›*)) (*discuss goal 2*) apply (rule finite_range_cb_take (*‹finite (range (cb_take ?n))›*)) (*proven 2 subgoals*) . lemma finite_rank_eq: "finite (rank_eq x)" by (rule finite_subset [OF rank_eq_subset finite_rank_le] (*‹finite (rank_eq (?x1::'a compact_basis))›*)) lemma finite_rank_lt: "finite (rank_lt x)" by (rule finite_subset [OF rank_lt_subset finite_rank_le] (*‹finite (rank_lt (?x1::'a compact_basis))›*)) lemma rank_lt_Int_rank_eq: "rank_lt x ∩ rank_eq x = {}" unfolding rank_lt_def rank_eq_def rank_le_def (*goal: ‹{y. rank y < rank x} ∩ {y. rank y = rank x} = {}›*) by auto lemma rank_lt_Un_rank_eq: "rank_lt x ∪ rank_eq x = rank_le x" unfolding rank_lt_def rank_eq_def rank_le_def (*goal: ‹{y. rank y < rank x} ∪ {y. rank y = rank x} = {y. rank y ≤ rank x}›*) by auto subsubsection ‹Sequencing basis elements› definition place :: "'a compact_basis ⇒ nat" where "place x = card (rank_lt x) + choose_pos (rank_eq x) x" lemma place_bounded: "place x < card (rank_le x)" unfolding place_def (*goal: ‹card (rank_lt x) + choose_pos (rank_eq x) x < card (rank_le x)›*) apply (rule ord_less_eq_trans (*‹⟦(?a::?'a::ord) < (?b::?'a::ord); ?b = (?c::?'a::ord)⟧ ⟹ ?a < ?c›*)) (*goals: 1. ‹card (rank_lt x) + choose_pos (rank_eq x) x < ?b› 2. ‹?b = card (rank_le x)› discuss goal 1*) apply (rule add_strict_left_mono (*‹?a < ?b ⟹ ?c + ?a < ?c + ?b›*)) (*top goal: ‹card (rank_lt x) + choose_pos (rank_eq x) x < ?b› and 1 goal remains*) apply (rule choose_pos_bounded (*‹⟦finite ?A; ?x ∈ ?A⟧ ⟹ choose_pos ?A ?x < card ?A›*)) (*goals: 1. ‹finite (rank_eq x)› 2. ‹x ∈ rank_eq x› discuss goal 1*) apply (rule finite_rank_eq (*‹finite (rank_eq ?x)›*)) (*discuss goal 2*) apply (simp add: rank_eq_def (*‹rank_eq ?x = {y. rank y = rank ?x}›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply (subst card_Un_disjoint [symmetric] (*‹⟦finite ?A; finite ?B; ?A ∩ ?B = {}⟧ ⟹ card ?A + card ?B = card (?A ∪ ?B)›*)) (*goals: 1. ‹finite (rank_lt (x::'a compact_basis))› 2. ‹finite (rank_eq (x::'a compact_basis))› 3. ‹rank_lt (x::'a compact_basis) ∩ rank_eq x = {}› 4. ‹card (rank_lt (x::'a compact_basis) ∪ rank_eq x) = card (rank_le x)› discuss goal 1*) apply (rule finite_rank_lt (*‹finite (rank_lt ?x)›*)) (*discuss goal 2*) apply (rule finite_rank_eq (*‹finite (rank_eq ?x)›*)) (*discuss goal 3*) apply (rule rank_lt_Int_rank_eq (*‹rank_lt ?x ∩ rank_eq ?x = {}›*)) (*discuss goal 4*) apply (simp add: rank_lt_Un_rank_eq (*‹rank_lt ?x ∪ rank_eq ?x = rank_le ?x›*)) (*proven 4 subgoals*) (*proven 2 subgoals*) . lemma place_ge: "card (rank_lt x) ≤ place x" unfolding place_def (*goal: ‹card (rank_lt x) ≤ card (rank_lt x) + choose_pos (rank_eq x) x›*) by simp lemma place_rank_mono: fixes x y :: "'a compact_basis" shows "rank x < rank y ⟹ place x < place y" apply (rule less_le_trans [OF place_bounded] (*‹card (rank_le ?x1) ≤ ?z ⟹ place ?x1 < ?z›*)) (*goal: ‹rank (x::'a compact_basis) < rank (y::'a compact_basis) ⟹ place x < place y›*) apply (rule order_trans [OF _ place_ge] (*‹?x ≤ card (rank_lt ?x1) ⟹ ?x ≤ place ?x1›*)) (*goal: ‹rank (x::'a::bifinite compact_basis) < rank (y::'a::bifinite compact_basis) ⟹ card (rank_le x) ≤ place y›*) apply (rule card_mono (*‹⟦finite (?B::?'a set); (?A::?'a set) ⊆ ?B⟧ ⟹ card ?A ≤ card ?B›*)) (*goals: 1. ‹rank x < rank y ⟹ finite (rank_lt y)› 2. ‹rank x < rank y ⟹ rank_le x ⊆ rank_lt y› discuss goal 1*) apply (rule finite_rank_lt (*‹finite (rank_lt ?x)›*)) (*discuss goal 2*) apply (simp add: rank_le_def (*‹rank_le (?x::'a compact_basis) = {y::'a compact_basis. rank y ≤ rank ?x}›*) rank_lt_def (*‹rank_lt (?x::'a compact_basis) = {y::'a compact_basis. rank y < rank ?x}›*) subset_eq (*‹((?A::?'a set) ⊆ (?B::?'a set)) = (∀x::?'a∈?A. x ∈ ?B)›*)) (*proven 2 subgoals*) . lemma place_eqD: "place x = place y ⟹ x = y" apply (rule linorder_cases [where x="rank x" and y="rank y"] (*‹⟦rank x < rank y ⟹ ?P; rank x = rank y ⟹ ?P; rank y < rank x ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹⟦place x = place y; rank x < rank y⟧ ⟹ x = y› 2. ‹⟦place x = place y; rank x = rank y⟧ ⟹ x = y› 3. ‹⟦place x = place y; rank y < rank x⟧ ⟹ x = y› discuss goal 1*) apply (drule place_rank_mono (*‹rank ?x < rank ?y ⟹ place ?x < place ?y›*)) (*top goal: ‹⟦place x = place y; rank x < rank y⟧ ⟹ x = y› and 2 goals remain*) apply simp (*discuss goal 2*) apply (simp add: place_def (*‹place ?x = card (rank_lt ?x) + choose_pos (rank_eq ?x) ?x›*)) (*top goal: ‹⟦place x = place y; rank x = rank y⟧ ⟹ x = y› and 1 goal remains*) apply (rule inj_on_choose_pos [where A="rank_eq x", THEN inj_onD] (*‹⟦finite (rank_eq x); choose_pos (rank_eq x) ?x = choose_pos (rank_eq x) ?y; ?x ∈ rank_eq x; ?y ∈ rank_eq x⟧ ⟹ ?x = ?y›*)) (*goals: 1. ‹⟦card (rank_lt (x::'a compact_basis)) + choose_pos (rank_eq x) x = card (rank_lt (y::'a compact_basis)) + choose_pos (rank_eq y) y; rank x = rank y⟧ ⟹ finite (rank_eq x)› 2. ‹⟦card (rank_lt (x::'a compact_basis)) + choose_pos (rank_eq x) x = card (rank_lt (y::'a compact_basis)) + choose_pos (rank_eq y) y; rank x = rank y⟧ ⟹ choose_pos (rank_eq x) x = choose_pos (rank_eq x) y› 3. ‹⟦card (rank_lt (x::'a compact_basis)) + choose_pos (rank_eq x) x = card (rank_lt (y::'a compact_basis)) + choose_pos (rank_eq y) y; rank x = rank y⟧ ⟹ x ∈ rank_eq x› 4. ‹⟦card (rank_lt (x::'a compact_basis)) + choose_pos (rank_eq x) x = card (rank_lt (y::'a compact_basis)) + choose_pos (rank_eq y) y; rank x = rank y⟧ ⟹ y ∈ rank_eq x› discuss goal 1*) apply (rule finite_rank_eq (*‹finite (rank_eq ?x)›*)) (*discuss goal 2*) apply (simp cong: rank_lt_cong (*‹rank ?x = rank ?y ⟹ rank_lt ?x = rank_lt ?y›*) rank_eq_cong (*‹rank ?x = rank ?y ⟹ rank_eq ?x = rank_eq ?y›*)) (*discuss goal 3*) apply (simp add: rank_eq_def (*‹rank_eq ?x = {y. rank y = rank ?x}›*)) (*discuss goal 4*) apply (simp add: rank_eq_def (*‹rank_eq ?x = {y. rank y = rank ?x}›*)) (*proven 4 subgoals*) (*discuss goal 3*) apply (drule place_rank_mono (*‹rank (?x::'a compact_basis) < rank (?y::'a compact_basis) ⟹ place ?x < place ?y›*)) (*goal: ‹⟦place x = place y; rank y < rank x⟧ ⟹ x = y›*) apply simp (*proven 3 subgoals*) . lemma inj_place: "inj place" apply (rule inj_onI (*‹(⋀x y. ⟦x ∈ ?A; y ∈ ?A; ?f x = ?f y⟧ ⟹ x = y) ⟹ inj_on ?f ?A›*)) (*goal: ‹inj place›*) by (erule place_eqD (*‹place (?x::'a::bifinite compact_basis) = place (?y::'a::bifinite compact_basis) ⟹ ?x = ?y›*)) subsubsection ‹Embedding and projection on basis elements› definition sub :: "'a compact_basis ⇒ 'a compact_basis" where "sub x = (case rank x of 0 ⇒ compact_bot | Suc k ⇒ cb_take k x)" lemma rank_sub_less: "x ≠ compact_bot ⟹ rank (sub x) < rank x" unfolding sub_def (*goal: ‹x ≠ compact_bot ⟹ rank (case rank x of 0 ⇒ compact_bot | Suc k ⇒ cb_take k x) < rank x›*) apply (cases "rank x") (*goals: 1. ‹⟦x ≠ compact_bot; rank x = 0⟧ ⟹ rank (case rank x of 0 ⇒ compact_bot | Suc k ⇒ cb_take k x) < rank x› 2. ‹⋀nat. ⟦x ≠ compact_bot; rank x = Suc nat⟧ ⟹ rank (case rank x of 0 ⇒ compact_bot | Suc k ⇒ cb_take k x) < rank x› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: less_Suc_eq_le (*‹(?m < Suc ?n) = (?m ≤ ?n)›*)) (*goal: ‹⋀nat. ⟦x ≠ compact_bot; rank x = Suc nat⟧ ⟹ rank (case rank x of 0 ⇒ compact_bot | Suc k ⇒ cb_take k x) < rank x›*) apply (rule rank_leI (*‹cb_take ?n ?x = ?x ⟹ rank ?x ≤ ?n›*)) (*goal: ‹⋀nat. ⟦x ≠ compact_bot; rank x = Suc nat⟧ ⟹ rank (cb_take nat x) ≤ nat›*) apply (rule cb_take_idem (*‹cb_take ?n (cb_take ?n ?x) = cb_take ?n ?x›*)) (*proven 2 subgoals*) . lemma place_sub_less: "x ≠ compact_bot ⟹ place (sub x) < place x" apply (rule place_rank_mono (*‹rank ?x < rank ?y ⟹ place ?x < place ?y›*)) (*goal: ‹(x::'a::bifinite compact_basis) ≠ compact_bot ⟹ place (sub x) < place x›*) by (erule rank_sub_less (*‹?x ≠ compact_bot ⟹ rank (sub ?x) < rank ?x›*)) lemma sub_below: "sub x ⊑ x" unfolding sub_def (*goal: ‹(case rank x of 0 ⇒ compact_bot | Suc k ⇒ cb_take k x) ⊑ x›*) apply (cases "rank x") (*goals: 1. ‹rank x = 0 ⟹ (case rank x of 0 ⇒ compact_bot | Suc k ⇒ cb_take k x) ⊑ x› 2. ‹⋀nat. rank x = Suc nat ⟹ (case rank x of 0 ⇒ compact_bot | Suc k ⇒ cb_take k x) ⊑ x› discuss goal 1*) apply (simp add: cb_take_less (*‹cb_take ?n ?x ⊑ ?x›*)) (*discuss goal 2*) apply (simp add: cb_take_less (*‹cb_take ?n ?x ⊑ ?x›*)) (*proven 2 subgoals*) . lemma rank_less_imp_below_sub: "⟦x ⊑ y; rank x < rank y⟧ ⟹ x ⊑ sub y" unfolding sub_def (*goal: ‹⟦x ⊑ y; rank x < rank y⟧ ⟹ x ⊑ (case rank y of 0 ⇒ compact_bot | Suc k ⇒ cb_take k y)›*) apply (cases "rank y") (*goals: 1. ‹⟦x ⊑ y; rank x < rank y; rank y = 0⟧ ⟹ x ⊑ (case rank y of 0 ⇒ compact_bot | Suc k ⇒ cb_take k y)› 2. ‹⋀nat. ⟦x ⊑ y; rank x < rank y; rank y = Suc nat⟧ ⟹ x ⊑ (case rank y of 0 ⇒ compact_bot | Suc k ⇒ cb_take k y)› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: less_Suc_eq_le (*‹(?m < Suc ?n) = (?m ≤ ?n)›*)) (*goal: ‹⋀nat. ⟦x ⊑ y; rank x < rank y; rank y = Suc nat⟧ ⟹ x ⊑ (case rank y of 0 ⇒ compact_bot | Suc k ⇒ cb_take k y)›*) apply (subgoal_tac "cb_take nat x ⊑ cb_take nat y") (*goals: 1. ‹⋀nat. ⟦x ⊑ y; rank x ≤ nat; rank y = Suc nat; cb_take nat x ⊑ cb_take nat y⟧ ⟹ x ⊑ cb_take nat y› 2. ‹⋀nat. ⟦x ⊑ y; rank x ≤ nat; rank y = Suc nat⟧ ⟹ cb_take nat x ⊑ cb_take nat y› discuss goal 1*) apply (simp add: rank_leD (*‹rank (?x::'a compact_basis) ≤ (?n::nat) ⟹ cb_take ?n ?x = ?x›*)) (*discuss goal 2*) apply (erule cb_take_mono (*‹?x ⊑ ?y ⟹ cb_take ?n ?x ⊑ cb_take ?n ?y›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) . function basis_emb :: "'a compact_basis ⇒ ubasis" where "basis_emb x = (if x = compact_bot then 0 else node (place x) (basis_emb (sub x)) (basis_emb ` {y. place y < place x ∧ x ⊑ y}))" by simp_all termination basis_emb by (relation "measure place") (simp_all add: place_sub_less) declare basis_emb.simps [simp del] lemma basis_emb_compact_bot [simp]: "basis_emb compact_bot = 0" using basis_emb.simps[of compact_bot] (*‹basis_emb compact_bot = (if compact_bot = compact_bot then 0 else node (place compact_bot) (basis_emb (sub compact_bot)) (basis_emb ` {y. place y < place compact_bot ∧ compact_bot ⊑ y}))›*) by simp lemma basis_emb_rec: "basis_emb x = node (place x) (basis_emb (sub x)) (basis_emb ` {y. place y < place x ∧ x ⊑ y})" if "x ≠ compact_bot" using that (*‹x ≠ compact_bot›*) basis_emb.simps[of x] (*‹basis_emb x = (if x = compact_bot then 0 else node (place x) (basis_emb (sub x)) (basis_emb ` {y. place y < place x ∧ x ⊑ y}))›*) by simp lemma basis_emb_eq_0_iff [simp]: "basis_emb x = 0 ⟷ x = compact_bot" apply (cases "x = compact_bot") (*goals: 1. ‹x = compact_bot ⟹ (basis_emb x = 0) = (x = compact_bot)› 2. ‹x ≠ compact_bot ⟹ (basis_emb x = 0) = (x = compact_bot)› discuss goal 1*) apply (simp add: basis_emb_rec (*‹?x ≠ compact_bot ⟹ basis_emb ?x = node (place ?x) (basis_emb (sub ?x)) (basis_emb ` {y. place y < place ?x ∧ ?x ⊑ y})›*)) (*discuss goal 2*) apply (simp add: basis_emb_rec (*‹?x ≠ compact_bot ⟹ basis_emb ?x = node (place ?x) (basis_emb (sub ?x)) (basis_emb ` {y. place y < place ?x ∧ ?x ⊑ y})›*)) (*proven 2 subgoals*) . lemma fin1: "finite {y. place y < place x ∧ x ⊑ y}" apply (subst Collect_conj_eq (*‹{x. ?P x ∧ ?Q x} = {x. ?P x} ∩ {x. ?Q x}›*)) (*goal: ‹finite {y::'a::bifinite compact_basis. place y < place (x::'a::bifinite compact_basis) ∧ x ⊑ y}›*) apply (rule finite_Int (*‹finite ?F ∨ finite ?G ⟹ finite (?F ∩ ?G)›*)) (*goal: ‹finite ({xa::'a compact_basis. place xa < place (x::'a compact_basis)} ∩ Collect ((⊑) x))›*) apply (rule disjI1 (*‹?P ⟹ ?P ∨ ?Q›*)) (*goal: ‹finite {xa. place xa < place x} ∨ finite (Collect ((⊑) x))›*) apply (subgoal_tac "finite (place -` {n. n < place x})") (*goals: 1. ‹finite (place -` {n::nat. n < place (x::'a compact_basis)}) ⟹ finite {xa::'a compact_basis. place xa < place x}› 2. ‹finite (place -` {n::nat. n < place (x::'a compact_basis)})› discuss goal 1*) apply simp (*discuss goal 2*) apply (rule finite_vimageI [OF _ inj_place] (*‹finite ?F ⟹ finite (place -` ?F)›*)) (*goal: ‹finite (place -` {n. n < place x})›*) apply (simp add: lessThan_def [symmetric] (*‹{x::?'a::ord. x < (?u::?'a::ord)} ≡ {..<?u}›*)) (*proven 2 subgoals*) . lemma fin2: "finite (basis_emb ` {y. place y < place x ∧ x ⊑ y})" by (rule finite_imageI [OF fin1] (*‹finite (?h ` {y. place y < place ?x1 ∧ ?x1 ⊑ y})›*)) lemma rank_place_mono: "⟦place x < place y; x ⊑ y⟧ ⟹ rank x < rank y" apply (rule linorder_cases (*‹⟦?x < ?y ⟹ ?P; ?x = ?y ⟹ ?P; ?y < ?x ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹⟦place (x::'a compact_basis) < place (y::'a compact_basis); x ⊑ y; (?x::?'a) < (?y::?'a)⟧ ⟹ rank x < rank y› 2. ‹⟦place (x::'a compact_basis) < place (y::'a compact_basis); x ⊑ y; (?x::?'a) = (?y::?'a)⟧ ⟹ rank x < rank y› 3. ‹⟦place (x::'a compact_basis) < place (y::'a compact_basis); x ⊑ y; (?y::?'a) < (?x::?'a)⟧ ⟹ rank x < rank y› discuss goal 1*) apply assumption (*discuss goal 2*) apply (simp add: place_def (*‹place ?x = card (rank_lt ?x) + choose_pos (rank_eq ?x) ?x›*) cong: rank_lt_cong (*‹rank ?x = rank ?y ⟹ rank_lt ?x = rank_lt ?y›*) rank_eq_cong (*‹rank ?x = rank ?y ⟹ rank_eq ?x = rank_eq ?y›*)) (*top goal: ‹⟦place x < place y; x ⊑ y; rank x = rank y⟧ ⟹ rank x < rank y› and 1 goal remains*) apply (drule choose_pos_lessD (*‹⟦choose_pos ?A ?x < choose_pos ?A ?y; finite ?A; ?x ∈ ?A; ?y ∈ ?A⟧ ⟹ ?x \<notsqsubseteq> ?y›*)) (*goals: 1. ‹⟦x ⊑ y; rank x = rank y⟧ ⟹ finite (rank_eq y)› 2. ‹⟦x ⊑ y; rank x = rank y⟧ ⟹ x ∈ rank_eq y› 3. ‹⟦x ⊑ y; rank x = rank y⟧ ⟹ y ∈ rank_eq y› 4. ‹⟦x ⊑ y; rank x = rank y; x \<notsqsubseteq> y⟧ ⟹ False› discuss goal 1*) apply (rule finite_rank_eq (*‹finite (rank_eq (?x::'a compact_basis))›*)) (*discuss goal 2*) apply (simp add: rank_eq_def (*‹rank_eq ?x = {y. rank y = rank ?x}›*)) (*discuss goal 3*) apply (simp add: rank_eq_def (*‹rank_eq ?x = {y. rank y = rank ?x}›*)) (*discuss goal 4*) apply simp (*proven 4 subgoals*) (*discuss goal 3*) apply (drule place_rank_mono (*‹rank ?x < rank ?y ⟹ place ?x < place ?y›*)) (*goal: ‹⟦place x < place y; x ⊑ y; rank y < rank x⟧ ⟹ rank x < rank y›*) apply simp (*proven 3 subgoals*) . lemma basis_emb_mono: "x ⊑ y ⟹ ubasis_le (basis_emb x) (basis_emb y)" proof (induct "max (place x) (place y)" arbitrary: x y rule: less_induct) (*goal: ‹⋀x y. ⟦⋀xa ya. ⟦max (place xa) (place ya) < max (place x) (place y); xa ⊑ ya⟧ ⟹ ubasis_le (basis_emb xa) (basis_emb ya); x ⊑ y⟧ ⟹ ubasis_le (basis_emb x) (basis_emb y)›*) case less (*‹⟦max (place (?x::'a compact_basis)) (place (?y::'a compact_basis)) < max (place (x::'a compact_basis)) (place (y::'a compact_basis)); ?x ⊑ ?y⟧ ⟹ ubasis_le (basis_emb ?x) (basis_emb ?y)› ‹x ⊑ y›*) show "?case" (*goal: ‹ubasis_le (basis_emb x) (basis_emb y)›*) proof (rule linorder_cases (*‹⟦(?x::?'a) < (?y::?'a) ⟹ ?P::bool; ?x = ?y ⟹ ?P; ?y < ?x ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹?x < ?y ⟹ ubasis_le (basis_emb x) (basis_emb y)› 2. ‹?x = ?y ⟹ ubasis_le (basis_emb x) (basis_emb y)› 3. ‹?y < ?x ⟹ ubasis_le (basis_emb x) (basis_emb y)›*) assume "place x < place y" (*‹place (x::'a compact_basis) < place (y::'a compact_basis)›*) then have "rank x < rank y" using ‹x ⊑ y› (*‹(x::'a::bifinite compact_basis) ⊑ (y::'a::bifinite compact_basis)›*) by (rule rank_place_mono (*‹⟦place (?x::'a compact_basis) < place (?y::'a compact_basis); ?x ⊑ ?y⟧ ⟹ rank ?x < rank ?y›*)) with ‹place x < place y› (*‹place (x::'a compact_basis) < place (y::'a compact_basis)›*) show "?case" (*goal: ‹ubasis_le (basis_emb x) (basis_emb y)›*) apply (case_tac "y = compact_bot") (*goals: 1. ‹⟦place (x::'a compact_basis) < place (y::'a compact_basis); rank x < rank y; y = compact_bot⟧ ⟹ ubasis_le (basis_emb x) (basis_emb y)› 2. ‹⟦place (x::'a compact_basis) < place (y::'a compact_basis); rank x < rank y; y ≠ compact_bot⟧ ⟹ ubasis_le (basis_emb x) (basis_emb y)› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: basis_emb.simps [of y] (*‹basis_emb y = (if y = compact_bot then 0 else node (place y) (basis_emb (sub y)) (basis_emb ` {y. place y < place y ∧ y ⊑ y}))›*)) (*goal: ‹⟦place x < place y; rank x < rank y; y ≠ compact_bot⟧ ⟹ ubasis_le (basis_emb x) (basis_emb y)›*) apply (rule ubasis_le_trans [OF _ ubasis_le_lower [OF fin2]] (*‹ubasis_le ?a ?b ⟹ ubasis_le ?a (node ?i1 ?b (basis_emb ` {y. place y < place ?x2 ∧ ?x2 ⊑ y}))›*)) (*goal: ‹⟦place (x::'a::bifinite compact_basis) < place (y::'a::bifinite compact_basis); rank x < rank y; y ≠ compact_bot⟧ ⟹ ubasis_le (basis_emb x) (node (place y) (basis_emb (sub y)) (basis_emb ` {y::'a::bifinite compact_basis. place y < place y ∧ y ⊑ y}))›*) apply (rule less (*‹⟦max (place (?x::'a compact_basis)) (place (?y::'a compact_basis)) < max (place (x::'a compact_basis)) (place (y::'a compact_basis)); ?x ⊑ ?y⟧ ⟹ ubasis_le (basis_emb ?x) (basis_emb ?y)› ‹(x::'a compact_basis) ⊑ (y::'a compact_basis)›*)) (*goals: 1. ‹⟦place x < place y; rank x < rank y; y ≠ compact_bot⟧ ⟹ max (place x) (place (sub y)) < max (place x) (place y)› 2. ‹⟦place x < place y; rank x < rank y; y ≠ compact_bot⟧ ⟹ x ⊑ sub y› discuss goal 1*) apply (simp add: less_max_iff_disj (*‹(?z < max ?x ?y) = (?z < ?x ∨ ?z < ?y)›*)) (*top goal: ‹⟦place x < place y; rank x < rank y; y ≠ compact_bot⟧ ⟹ max (place x) (place (sub y)) < max (place x) (place y)› and 1 goal remains*) apply (erule place_sub_less (*‹(?x::'a::bifinite compact_basis) ≠ compact_bot ⟹ place (sub ?x) < place ?x›*)) (*discuss goal 2*) apply (erule rank_less_imp_below_sub [OF ‹x ⊑ y›] (*‹rank x < rank y ⟹ x ⊑ sub y›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) . next (*goals: 1. ‹place x = place y ⟹ ubasis_le (basis_emb x) (basis_emb y)› 2. ‹place y < place x ⟹ ubasis_le (basis_emb x) (basis_emb y)›*) assume "place x = place y" (*‹place (x::'a compact_basis) = place (y::'a compact_basis)›*) hence "x = y" by (rule place_eqD (*‹place ?x = place ?y ⟹ ?x = ?y›*)) thus "?case" (*goal: ‹ubasis_le (basis_emb x) (basis_emb y)›*) by (simp add: ubasis_le_refl (*‹ubasis_le (?a::nat) ?a›*)) next (*goal: ‹place y < place x ⟹ ubasis_le (basis_emb x) (basis_emb y)›*) assume "place x > place y" (*‹place (y::'a compact_basis) < place (x::'a compact_basis)›*) with ‹x ⊑ y› (*‹x ⊑ y›*) show "?case" (*goal: ‹ubasis_le (basis_emb (x::'a compact_basis)) (basis_emb (y::'a compact_basis))›*) apply (case_tac "x = compact_bot") (*goals: 1. ‹⟦x ⊑ y; place y < place x; x = compact_bot⟧ ⟹ ubasis_le (basis_emb x) (basis_emb y)› 2. ‹⟦x ⊑ y; place y < place x; x ≠ compact_bot⟧ ⟹ ubasis_le (basis_emb x) (basis_emb y)› discuss goal 1*) apply (simp add: ubasis_le_minimal (*‹ubasis_le (0::nat) (?x::nat)›*)) (*discuss goal 2*) apply (simp add: basis_emb.simps [of x] (*‹basis_emb x = (if x = compact_bot then 0 else node (place x) (basis_emb (sub x)) (basis_emb ` {y. place y < place x ∧ x ⊑ y}))›*)) (*goal: ‹⟦x ⊑ y; place y < place x; x ≠ compact_bot⟧ ⟹ ubasis_le (basis_emb x) (basis_emb y)›*) apply (rule ubasis_le_upper [OF fin2] (*‹⟦?b ∈ basis_emb ` {y. place y < place ?x1 ∧ ?x1 ⊑ y}; ubasis_le ?a ?b⟧ ⟹ ubasis_le (node ?i ?a (basis_emb ` {y. place y < place ?x1 ∧ ?x1 ⊑ y})) ?b›*)) (*goals: 1. ‹⟦(x::'a compact_basis) ⊑ (y::'a compact_basis); place y < place x; x ≠ compact_bot⟧ ⟹ basis_emb y ∈ basis_emb ` {y::'a compact_basis. place y < place x ∧ x ⊑ y}› 2. ‹⟦(x::'a compact_basis) ⊑ (y::'a compact_basis); place y < place x; x ≠ compact_bot⟧ ⟹ ubasis_le (basis_emb (sub x)) (basis_emb y)› discuss goal 1*) apply simp (*discuss goal 2*) apply (rule less (*‹⟦max (place ?x) (place ?y) < max (place x) (place y); ?x ⊑ ?y⟧ ⟹ ubasis_le (basis_emb ?x) (basis_emb ?y)› ‹x ⊑ y›*)) (*goals: 1. ‹⟦x ⊑ y; place y < place x; x ≠ compact_bot⟧ ⟹ max (place (sub x)) (place y) < max (place x) (place y)› 2. ‹⟦x ⊑ y; place y < place x; x ≠ compact_bot⟧ ⟹ sub x ⊑ y› discuss goal 1*) apply (simp add: less_max_iff_disj (*‹((?z::?'a) < max (?x::?'a) (?y::?'a)) = (?z < ?x ∨ ?z < ?y)›*)) (*top goal: ‹⟦x ⊑ y; place y < place x; x ≠ compact_bot⟧ ⟹ max (place (sub x)) (place y) < max (place x) (place y)› and 1 goal remains*) apply (erule place_sub_less (*‹?x ≠ compact_bot ⟹ place (sub ?x) < place ?x›*)) (*discuss goal 2*) apply (erule rev_below_trans (*‹⟦?y ⊑ ?z; ?x ⊑ ?y⟧ ⟹ ?x ⊑ ?z›*)) (*goal: ‹⟦x ⊑ y; place y < place x; x ≠ compact_bot⟧ ⟹ sub x ⊑ y›*) apply (rule sub_below (*‹sub ?x ⊑ ?x›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . qed qed lemma inj_basis_emb: "inj basis_emb" proof (rule injI (*‹(⋀x y. ?f x = ?f y ⟹ x = y) ⟹ inj ?f›*)) (*goal: ‹⋀x y. basis_emb x = basis_emb y ⟹ x = y›*) fix x and y assume "basis_emb x = basis_emb y" (*‹basis_emb (x::'a compact_basis) = basis_emb (y::'a compact_basis)›*) then show "x = y" apply (cases "x = compact_bot ∨ y = compact_bot") (*goals: 1. ‹⟦basis_emb (x::'a::bifinite compact_basis) = basis_emb (y::'a::bifinite compact_basis); x = compact_bot ∨ y = compact_bot⟧ ⟹ x = y› 2. ‹⟦basis_emb (x::'a::bifinite compact_basis) = basis_emb (y::'a::bifinite compact_basis); ¬ (x = compact_bot ∨ y = compact_bot)⟧ ⟹ x = y› discuss goal 1*) apply ((auto simp add: basis_emb_rec (*‹?x ≠ compact_bot ⟹ basis_emb ?x = node (place ?x) (basis_emb (sub ?x)) (basis_emb ` {y. place y < place ?x ∧ ?x ⊑ y})›*) fin2 (*‹finite (basis_emb ` {y. place y < place ?x ∧ ?x ⊑ y})›*) place_eqD (*‹place ?x = place ?y ⟹ ?x = ?y›*))[1]) (*discuss goal 2*) apply ((auto simp add: basis_emb_rec (*‹?x ≠ compact_bot ⟹ basis_emb ?x = node (place ?x) (basis_emb (sub ?x)) (basis_emb ` {y. place y < place ?x ∧ ?x ⊑ y})›*) fin2 (*‹finite (basis_emb ` {y. place y < place ?x ∧ ?x ⊑ y})›*) place_eqD (*‹place ?x = place ?y ⟹ ?x = ?y›*))[1]) (*proven 2 subgoals*) . qed definition basis_prj :: "ubasis ⇒ 'a compact_basis" where "basis_prj x = inv basis_emb (ubasis_until (λx. x ∈ range (basis_emb :: 'a compact_basis ⇒ ubasis)) x)" lemma basis_prj_basis_emb: "⋀x. basis_prj (basis_emb x) = x" unfolding basis_prj_def (*goal: ‹⋀x. inv basis_emb (ubasis_until (λx. x ∈ range basis_emb) (basis_emb x)) = x›*) apply (subst ubasis_until_same (*‹(?P::nat ⇒ bool) (?x::nat) ⟹ ubasis_until ?P ?x = ?x›*)) (*goals: 1. ‹⋀x::'a::bifinite compact_basis. basis_emb x ∈ range basis_emb› 2. ‹⋀x::'a::bifinite compact_basis. inv basis_emb (basis_emb x) = x› discuss goal 1*) apply (rule rangeI (*‹?f ?x ∈ range ?f›*)) (*discuss goal 2*) apply (rule inv_f_f (*‹inj ?f ⟹ inv ?f (?f ?x) = ?x›*)) (*goal: ‹⋀x::'a compact_basis. inv basis_emb (basis_emb x) = x›*) apply (rule inj_basis_emb (*‹inj basis_emb›*)) (*proven 2 subgoals*) . lemma basis_prj_node: "⟦finite S; node i a S ∉ range (basis_emb :: 'a compact_basis ⇒ nat)⟧ ⟹ basis_prj (node i a S) = (basis_prj a :: 'a compact_basis)" unfolding basis_prj_def (*goal: ‹⟦finite (S::nat set); node (i::nat) (a::nat) S ∉ range basis_emb⟧ ⟹ inv basis_emb (ubasis_until (λx::nat. x ∈ range basis_emb) (node i a S)) = inv basis_emb (ubasis_until (λx::nat. x ∈ range basis_emb) a)›*) by simp lemma basis_prj_0: "basis_prj 0 = compact_bot" apply (subst basis_emb_compact_bot [symmetric] (*‹0 = basis_emb compact_bot›*)) (*goal: ‹basis_prj 0 = compact_bot›*) by (rule basis_prj_basis_emb (*‹basis_prj (basis_emb (?x::'a::bifinite compact_basis)) = ?x›*)) lemma node_eq_basis_emb_iff: "finite S ⟹ node i a S = basis_emb x ⟷ x ≠ compact_bot ∧ i = place x ∧ a = basis_emb (sub x) ∧ S = basis_emb ` {y. place y < place x ∧ x ⊑ y}" apply (cases "x = compact_bot") (*goals: 1. ‹⟦finite S; x = compact_bot⟧ ⟹ (node i a S = basis_emb x) = (x ≠ compact_bot ∧ i = place x ∧ a = basis_emb (sub x) ∧ S = basis_emb ` {y. place y < place x ∧ x ⊑ y})› 2. ‹⟦finite S; x ≠ compact_bot⟧ ⟹ (node i a S = basis_emb x) = (x ≠ compact_bot ∧ i = place x ∧ a = basis_emb (sub x) ∧ S = basis_emb ` {y. place y < place x ∧ x ⊑ y})› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: basis_emb.simps [of x] (*‹basis_emb (x::'a compact_basis) = (if x = compact_bot then 0::nat else node (place x) (basis_emb (sub x)) (basis_emb ` {y::'a compact_basis. place y < place x ∧ x ⊑ y}))›*)) (*goal: ‹⟦finite S; x ≠ compact_bot⟧ ⟹ (node i a S = basis_emb x) = (x ≠ compact_bot ∧ i = place x ∧ a = basis_emb (sub x) ∧ S = basis_emb ` {y. place y < place x ∧ x ⊑ y})›*) apply (simp add: fin2 (*‹finite (basis_emb ` {y. place y < place ?x ∧ ?x ⊑ y})›*)) (*proven 2 subgoals*) . lemma basis_prj_mono: "ubasis_le a b ⟹ basis_prj a ⊑ basis_prj b" proof (induct a b rule: ubasis_le.induct (*‹⟦ubasis_le ?x1.0 ?x2.0; ⋀a. ?P a a; ⋀a b c. ⟦ubasis_le a b; ?P a b; ubasis_le b c; ?P b c⟧ ⟹ ?P a c; ⋀S a i. finite S ⟹ ?P a (node i a S); ⋀S b a i. ⟦finite S; b ∈ S; ubasis_le a b; ?P a b⟧ ⟹ ?P (node i a S) b⟧ ⟹ ?P ?x1.0 ?x2.0›*)) (*goals: 1. ‹⋀a. basis_prj a ⊑ basis_prj a› 2. ‹⋀a b c. ⟦ubasis_le a b; basis_prj a ⊑ basis_prj b; ubasis_le b c; basis_prj b ⊑ basis_prj c⟧ ⟹ basis_prj a ⊑ basis_prj c› 3. ‹⋀S a i. finite S ⟹ basis_prj a ⊑ basis_prj (node i a S)› 4. ‹⋀S b a i. ⟦finite S; b ∈ S; ubasis_le a b; basis_prj a ⊑ basis_prj b⟧ ⟹ basis_prj (node i a S) ⊑ basis_prj b›*) case (ubasis_le_refl a) (*no hyothesis introduced yet*) show "?case" (*goal: ‹basis_prj a ⊑ basis_prj a›*) by (rule below_refl (*‹?x ⊑ ?x›*)) next (*goals: 1. ‹⋀a b c. ⟦ubasis_le a b; basis_prj a ⊑ basis_prj b; ubasis_le b c; basis_prj b ⊑ basis_prj c⟧ ⟹ basis_prj a ⊑ basis_prj c› 2. ‹⋀S a i. finite S ⟹ basis_prj a ⊑ basis_prj (node i a S)› 3. ‹⋀S b a i. ⟦finite S; b ∈ S; ubasis_le a b; basis_prj a ⊑ basis_prj b⟧ ⟹ basis_prj (node i a S) ⊑ basis_prj b›*) case (ubasis_le_trans a b c) (*‹ubasis_le a b› ‹basis_prj a ⊑ basis_prj b› ‹ubasis_le (b::nat) (c::nat)› ‹basis_prj (b::nat) ⊑ basis_prj (c::nat)›*) thus "?case" (*goal: ‹basis_prj a ⊑ basis_prj c›*) apply - (*goal: ‹basis_prj (a::nat) ⊑ basis_prj (c::nat)›*) apply (rule below_trans (*‹⟦(?x::?'a::po) ⊑ (?y::?'a::po); ?y ⊑ (?z::?'a::po)⟧ ⟹ ?x ⊑ ?z›*)) (*goals: 1. ‹⟦ubasis_le a b; basis_prj a ⊑ basis_prj b; ubasis_le b c; basis_prj b ⊑ basis_prj c⟧ ⟹ basis_prj a ⊑ ?y4› 2. ‹⟦ubasis_le a b; basis_prj a ⊑ basis_prj b; ubasis_le b c; basis_prj b ⊑ basis_prj c⟧ ⟹ ?y4 ⊑ basis_prj c› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) next (*goals: 1. ‹⋀S a i. finite S ⟹ basis_prj a ⊑ basis_prj (node i a S)› 2. ‹⋀S b a i. ⟦finite S; b ∈ S; ubasis_le a b; basis_prj a ⊑ basis_prj b⟧ ⟹ basis_prj (node i a S) ⊑ basis_prj b›*) case (ubasis_le_lower S a i) (*‹finite (S::nat set)›*) thus "?case" (*goal: ‹basis_prj a ⊑ basis_prj (node i a S)›*) apply (cases "node i a S ∈ range (basis_emb :: 'a compact_basis ⇒ nat)") (*goals: 1. ‹⟦finite S; node i a S ∈ range basis_emb⟧ ⟹ basis_prj a ⊑ basis_prj (node i a S)› 2. ‹⟦finite S; node i a S ∉ range basis_emb⟧ ⟹ basis_prj a ⊑ basis_prj (node i a S)› discuss goal 1*) apply (erule rangeE (*‹⟦?b ∈ range ?f; ⋀x. ?b = ?f x ⟹ ?P⟧ ⟹ ?P›*)) (*top goal: ‹⟦finite (S::nat set); node (i::nat) (a::nat) S ∈ range basis_emb⟧ ⟹ basis_prj a ⊑ basis_prj (node i a S)› and 1 goal remains*) apply (rename_tac x) (*top goal: ‹⋀x. ⟦finite S; node i a S = basis_emb x⟧ ⟹ basis_prj a ⊑ basis_prj (node i a S)› and 1 goal remains*) apply (simp add: basis_prj_basis_emb (*‹basis_prj (basis_emb (?x::'a::bifinite compact_basis)) = ?x›*)) (*top goal: ‹⋀x::'a compact_basis. ⟦finite (S::nat set); node (i::nat) (a::nat) S = basis_emb x⟧ ⟹ basis_prj a ⊑ basis_prj (node i a S)› and 1 goal remains*) apply (simp add: node_eq_basis_emb_iff (*‹finite ?S ⟹ (node ?i ?a ?S = basis_emb ?x) = (?x ≠ compact_bot ∧ ?i = place ?x ∧ ?a = basis_emb (sub ?x) ∧ ?S = basis_emb ` {y. place y < place ?x ∧ ?x ⊑ y})›*)) (*top goal: ‹⋀x. ⟦finite S; node i a S = basis_emb x⟧ ⟹ basis_prj a ⊑ x› and 1 goal remains*) apply (simp add: basis_prj_basis_emb (*‹basis_prj (basis_emb ?x) = ?x›*)) (*top goal: ‹⋀x. ⟦finite (basis_emb ` {y. place y < place x ∧ x ⊑ y}); x ≠ compact_bot ∧ i = place x ∧ a = basis_emb (sub x) ∧ S = basis_emb ` {y. place y < place x ∧ x ⊑ y}⟧ ⟹ basis_prj (basis_emb (sub x)) ⊑ x› and 1 goal remains*) apply (rule sub_below (*‹sub ?x ⊑ ?x›*)) (*discuss goal 2*) apply (simp add: basis_prj_node (*‹⟦finite ?S; node ?i ?a ?S ∉ range basis_emb⟧ ⟹ basis_prj (node ?i ?a ?S) = basis_prj ?a›*)) (*proven 2 subgoals*) . next (*goal: ‹⋀S b a i. ⟦finite S; b ∈ S; ubasis_le a b; basis_prj a ⊑ basis_prj b⟧ ⟹ basis_prj (node i a S) ⊑ basis_prj b›*) case (ubasis_le_upper S b a i) (*‹finite S› ‹(b::nat) ∈ (S::nat set)› ‹ubasis_le a b› ‹basis_prj a ⊑ basis_prj b›*) thus "?case" (*goal: ‹basis_prj (node i a S) ⊑ basis_prj b›*) apply (cases "node i a S ∈ range (basis_emb :: 'a compact_basis ⇒ nat)") (*goals: 1. ‹⟦finite (S::nat set); (b::nat) ∈ S; ubasis_le (a::nat) b; basis_prj a ⊑ basis_prj b; node (i::nat) a S ∈ range basis_emb⟧ ⟹ basis_prj (node i a S) ⊑ basis_prj b› 2. ‹⟦finite (S::nat set); (b::nat) ∈ S; ubasis_le (a::nat) b; basis_prj a ⊑ basis_prj b; node (i::nat) a S ∉ range basis_emb⟧ ⟹ basis_prj (node i a S) ⊑ basis_prj b› discuss goal 1*) apply (erule rangeE (*‹⟦(?b::?'a::type) ∈ range (?f::?'b::type ⇒ ?'a::type); ⋀x::?'b::type. ?b = ?f x ⟹ ?P::bool⟧ ⟹ ?P›*)) (*top goal: ‹⟦finite S; b ∈ S; ubasis_le a b; basis_prj a ⊑ basis_prj b; node i a S ∈ range basis_emb⟧ ⟹ basis_prj (node i a S) ⊑ basis_prj b› and 1 goal remains*) apply (rename_tac x) (*top goal: ‹⋀x. ⟦finite S; b ∈ S; ubasis_le a b; basis_prj a ⊑ basis_prj b; node i a S = basis_emb x⟧ ⟹ basis_prj (node i a S) ⊑ basis_prj b› and 1 goal remains*) apply (simp add: basis_prj_basis_emb (*‹basis_prj (basis_emb (?x::'a::bifinite compact_basis)) = ?x›*)) (*top goal: ‹⋀x. ⟦finite S; b ∈ S; ubasis_le a b; basis_prj a ⊑ basis_prj b; node i a S = basis_emb x⟧ ⟹ basis_prj (node i a S) ⊑ basis_prj b› and 1 goal remains*) apply (clarsimp simp add: node_eq_basis_emb_iff (*‹finite ?S ⟹ (node ?i ?a ?S = basis_emb ?x) = (?x ≠ compact_bot ∧ ?i = place ?x ∧ ?a = basis_emb (sub ?x) ∧ ?S = basis_emb ` {y. place y < place ?x ∧ ?x ⊑ y})›*)) (*top goal: ‹⋀x. ⟦finite S; b ∈ S; ubasis_le a b; basis_prj a ⊑ basis_prj b; node i a S = basis_emb x⟧ ⟹ x ⊑ basis_prj b› and 1 goal remains*) apply (simp add: basis_prj_basis_emb (*‹basis_prj (basis_emb (?x::'a::bifinite compact_basis)) = ?x›*)) (*discuss goal 2*) apply (simp add: basis_prj_node (*‹⟦finite ?S; node ?i ?a ?S ∉ range basis_emb⟧ ⟹ basis_prj (node ?i ?a ?S) = basis_prj ?a›*)) (*proven 2 subgoals*) . qed lemma basis_emb_prj_less: "ubasis_le (basis_emb (basis_prj x)) x" unfolding basis_prj_def (*goal: ‹ubasis_le (basis_emb (inv basis_emb (ubasis_until (λx. x ∈ range basis_emb) x))) x›*) apply (subst f_inv_into_f [where f=basis_emb] (*‹?y ∈ basis_emb ` ?A ⟹ basis_emb (inv_into ?A basis_emb ?y) = ?y›*)) (*goals: 1. ‹ubasis_until (λx::nat. x ∈ range basis_emb) (x::nat) ∈ range basis_emb› 2. ‹ubasis_le (ubasis_until (λx::nat. x ∈ range basis_emb) (x::nat)) x› discuss goal 1*) apply (rule ubasis_until (*‹?P 0 ⟹ ?P (ubasis_until ?P ?x)›*)) (*top goal: ‹ubasis_until (λx::nat. x ∈ range basis_emb) (x::nat) ∈ range basis_emb› and 1 goal remains*) apply (rule range_eqI [where x=compact_bot] (*‹?b = ?f compact_bot ⟹ ?b ∈ range ?f›*)) (*top goal: ‹0 ∈ range basis_emb› and 1 goal remains*) apply simp (*discuss goal 2*) apply (rule ubasis_until_less (*‹ubasis_le (ubasis_until ?P ?x) ?x›*)) (*proven 2 subgoals*) . lemma ideal_completion: "ideal_completion below Rep_compact_basis (approximants :: 'a ⇒ _)" proof (standard) (*goals: 1. ‹⋀x. below.ideal (approximants x)› 2. ‹⋀Y. chain Y ⟹ approximants (⨆i. Y i) = (⋃i. approximants (Y i))› 3. ‹⋀a. approximants (Rep_compact_basis a) = {b. b ⊑ a}› 4. ‹⋀x y. approximants x ⊆ approximants y ⟹ x ⊑ y› 5. ‹∃f. inj f›*) fix w :: 'a show "below.ideal (approximants w)" proof (rule below.idealI (*‹⟦∃x. x ∈ ?A; ⋀x y. ⟦x ∈ ?A; y ∈ ?A⟧ ⟹ ∃z∈?A. x ⊑ z ∧ y ⊑ z; ⋀x y. ⟦x ⊑ y; y ∈ ?A⟧ ⟹ x ∈ ?A⟧ ⟹ below.ideal ?A›*)) (*goals: 1. ‹∃x::'a::bifinite compact_basis. x ∈ approximants (w::'a::bifinite)› 2. ‹⋀(x::'a::bifinite compact_basis) y::'a::bifinite compact_basis. ⟦x ∈ approximants (w::'a::bifinite); y ∈ approximants w⟧ ⟹ ∃z::'a::bifinite compact_basis∈approximants w. x ⊑ z ∧ y ⊑ z› 3. ‹⋀(x::'a::bifinite compact_basis) y::'a::bifinite compact_basis. ⟦x ⊑ y; y ∈ approximants (w::'a::bifinite)⟧ ⟹ x ∈ approximants w›*) have "Abs_compact_basis (approx 0⋅w) ∈ approximants w" by (simp add: approximants_def (*‹approximants = (λx::?'a. {a::?'a compact_basis. Rep_compact_basis a ⊑ x})›*) approx_below (*‹(approx::nat ⇒ 'a → 'a) (?i::nat)⋅(?x::'a) ⊑ ?x›*)) thus "∃x. x ∈ approximants w" by standard next (*goals: 1. ‹⋀x y. ⟦x ∈ approximants w; y ∈ approximants w⟧ ⟹ ∃z∈approximants w. x ⊑ z ∧ y ⊑ z› 2. ‹⋀x y. ⟦x ⊑ y; y ∈ approximants w⟧ ⟹ x ∈ approximants w›*) fix x :: "'a compact_basis" and y :: "'a compact_basis" assume x: "x ∈ approximants w" and y: "y ∈ approximants w" (*‹(x::'a compact_basis) ∈ approximants (w::'a)› ‹(y::'a compact_basis) ∈ approximants (w::'a)›*) obtain i where i: "approx i⋅(Rep_compact_basis x) = Rep_compact_basis x" (*goal: ‹(⋀i::nat. (approx::nat ⇒ 'a → 'a) i⋅(Rep_compact_basis (x::'a compact_basis)) = Rep_compact_basis x ⟹ thesis::bool) ⟹ thesis›*) using compact_eq_approx (*‹compact ?x ⟹ ∃i. approx i⋅?x = ?x›*) Rep_compact_basis' (*‹compact (Rep_compact_basis (?a::?'a::pcpo compact_basis))›*) by fast obtain j where j: "approx j⋅(Rep_compact_basis y) = Rep_compact_basis y" (*goal: ‹(⋀j::nat. (approx::nat ⇒ 'a → 'a) j⋅(Rep_compact_basis (y::'a compact_basis)) = Rep_compact_basis y ⟹ thesis::bool) ⟹ thesis›*) using compact_eq_approx (*‹compact (?x::'a::bifinite) ⟹ ∃i::nat. (approx::nat ⇒ 'a::bifinite → 'a::bifinite) i⋅?x = ?x›*) Rep_compact_basis' (*‹compact (Rep_compact_basis ?a)›*) by fast let ?z = "Abs_compact_basis (approx (max i j)⋅w)" have "?z ∈ approximants w" by (simp add: approximants_def (*‹approximants = (λx. {a. Rep_compact_basis a ⊑ x})›*) approx_below (*‹approx ?i⋅?x ⊑ ?x›*)) moreover from x (*‹x ∈ approximants w›*) y (*‹y ∈ approximants w›*) have "x ⊑ ?z ∧ y ⊑ ?z" apply (simp add: approximants_def (*‹approximants = (λx. {a. Rep_compact_basis a ⊑ x})›*) compact_le_def (*‹(⊑) ≡ λx y. Rep_compact_basis x ⊑ Rep_compact_basis y›*)) (*goal: ‹x ⊑ Abs_compact_basis (approx (max i j)⋅w) ∧ y ⊑ Abs_compact_basis (approx (max i j)⋅w)›*) by (metis i (*‹approx i⋅(Rep_compact_basis x) = Rep_compact_basis x›*) j (*‹approx j⋅(Rep_compact_basis y) = Rep_compact_basis y›*) monofun_cfun (*‹⟦?f ⊑ ?g; ?x ⊑ ?y⟧ ⟹ ?f⋅?x ⊑ ?g⋅?y›*) chain_mono (*‹⟦chain ?Y; ?i ≤ ?j⟧ ⟹ ?Y ?i ⊑ ?Y ?j›*) chain_approx (*‹chain approx›*) max.cobounded1 (*‹?a ≤ max ?a ?b›*) max.cobounded2 (*‹?b ≤ max ?a ?b›*)) ultimately show "∃z ∈ approximants w. x ⊑ z ∧ y ⊑ z" by standard next (*goal: ‹⋀x y. ⟦x ⊑ y; y ∈ approximants w⟧ ⟹ x ∈ approximants w›*) fix x :: "'a compact_basis" and y :: "'a compact_basis" assume "x ⊑ y" "y ∈ approximants w" (*‹(x::'a compact_basis) ⊑ (y::'a compact_basis)› ‹(y::'a compact_basis) ∈ approximants (w::'a)›*) thus "x ∈ approximants w" unfolding approximants_def compact_le_def (*goal: ‹x ∈ {a. Rep_compact_basis a ⊑ w}›*) by (auto elim: below_trans (*‹⟦?x ⊑ ?y; ?y ⊑ ?z⟧ ⟹ ?x ⊑ ?z›*)) qed next (*goals: 1. ‹⋀Y::nat ⇒ 'a. chain Y ⟹ approximants (⨆i::nat. Y i) = (⋃i::nat. approximants (Y i))› 2. ‹⋀a::'a compact_basis. approximants (Rep_compact_basis a) = {b::'a compact_basis. b ⊑ a}› 3. ‹⋀(x::'a) y::'a. approximants x ⊆ approximants y ⟹ x ⊑ y› 4. ‹∃f::'a compact_basis ⇒ nat. inj f›*) fix Y :: "nat ⇒ 'a" assume "chain Y" (*‹chain (Y::nat ⇒ 'a)›*) thus "approximants (⨆i. Y i) = (⋃i. approximants (Y i))" unfolding approximants_def (*goal: ‹{a. Rep_compact_basis a ⊑ Lub Y} = (⋃i. {a. Rep_compact_basis a ⊑ Y i})›*) by (auto simp add: compact_below_lub_iff (*‹⟦compact ?x; chain ?Y⟧ ⟹ (?x ⊑ (⨆i. ?Y i)) = (∃i. ?x ⊑ ?Y i)›*)) next (*goals: 1. ‹⋀a. approximants (Rep_compact_basis a) = {b. b ⊑ a}› 2. ‹⋀x y. approximants x ⊆ approximants y ⟹ x ⊑ y› 3. ‹∃f. inj f›*) fix a :: "'a compact_basis" show "approximants (Rep_compact_basis a) = {b. b ⊑ a}" unfolding approximants_def compact_le_def (*goal: ‹{aa::'a::bifinite compact_basis. Rep_compact_basis aa ⊑ Rep_compact_basis (a::'a::bifinite compact_basis)} = {b::'a::bifinite compact_basis. Rep_compact_basis b ⊑ Rep_compact_basis a}›*) by standard next (*goals: 1. ‹⋀x y. approximants x ⊆ approximants y ⟹ x ⊑ y› 2. ‹∃f. inj f›*) fix x :: 'a and y :: 'a assume "approximants x ⊆ approximants y" (*‹approximants (x::'a) ⊆ approximants (y::'a)›*) hence "∀z. compact z ⟶ z ⊑ x ⟶ z ⊑ y" apply (simp add: approximants_def (*‹approximants = (λx. {a. Rep_compact_basis a ⊑ x})›*) subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*)) (*goal: ‹∀z. compact z ⟶ z ⊑ x ⟶ z ⊑ y›*) by (metis Abs_compact_basis_inverse' (*‹compact ?x ⟹ Rep_compact_basis (Abs_compact_basis ?x) = ?x›*)) hence "(⨆i. approx i⋅x) ⊑ y" by (simp add: lub_below (*‹⟦chain ?S; ⋀i. ?S i ⊑ ?x⟧ ⟹ (⨆i. ?S i) ⊑ ?x›*) approx_below (*‹approx ?i⋅?x ⊑ ?x›*)) thus "x ⊑ y" by (simp add: lub_distribs (*‹⟦chain ?F; chain ?Y⟧ ⟹ (⨆i. ?F i⋅(?Y i)) = (⨆i. ?F i)⋅(⨆i. ?Y i)› ‹⟦⋀x. chain (λi. ?F i x); ⋀i. cont (?F i)⟧ ⟹ (⨆i. Λ x. ?F i x) = (Λ x. ⨆i. ?F i x)›*)) next (*goal: ‹∃f. inj f›*) show "∃f::'a compact_basis ⇒ nat. inj f" apply (rule exI (*‹?P ?x ⟹ ∃x. ?P x›*)) (*goal: ‹∃f. inj f›*) by (rule inj_place (*‹inj place›*)) qed end interpretation compact_basis: ideal_completion below Rep_compact_basis "approximants :: 'a::bifinite ⇒ 'a compact_basis set" proof (-) (*goal: ‹ideal_completion (⊑) Rep_compact_basis approximants›*) obtain a :: "nat ⇒ 'a → 'a" where "approx_chain a" (*goal: ‹(⋀a::nat ⇒ 'a → 'a. approx_chain a ⟹ thesis::bool) ⟹ thesis›*) using bifinite (*‹∃a. approx_chain a›*) by standard hence "bifinite_approx_chain a" unfolding bifinite_approx_chain_def (*goal: ‹approx_chain a›*) . thus "ideal_completion below Rep_compact_basis (approximants :: 'a ⇒ _)" by (rule bifinite_approx_chain.ideal_completion (*‹bifinite_approx_chain (?approx::nat ⇒ ?'a::bifinite → ?'a::bifinite) ⟹ ideal_completion (⊑) Rep_compact_basis approximants›*)) qed subsubsection ‹EP-pair from any bifinite domain into \emph{udom}› context bifinite_approx_chain begin definition udom_emb :: "'a → udom" where "udom_emb = compact_basis.extension (λx. udom_principal (basis_emb x))" definition udom_prj :: "udom → 'a" where "udom_prj = udom.extension (λx. Rep_compact_basis (basis_prj x))" lemma udom_emb_principal: "udom_emb⋅(Rep_compact_basis x) = udom_principal (basis_emb x)" unfolding udom_emb_def (*goal: ‹compact_basis.extension (λx::'a compact_basis. udom_principal (basis_emb x))⋅(Rep_compact_basis (x::'a compact_basis)) = udom_principal (basis_emb x)›*) apply (rule compact_basis.extension_principal (*‹(⋀(a::?'a::bifinite compact_basis) b::?'a::bifinite compact_basis. a ⊑ b ⟹ (?f::?'a::bifinite compact_basis ⇒ ?'c::cpo) a ⊑ ?f b) ⟹ compact_basis.extension ?f⋅(Rep_compact_basis (?a::?'a::bifinite compact_basis)) = ?f ?a›*)) (*goal: ‹compact_basis.extension (λx. udom_principal (basis_emb x))⋅(Rep_compact_basis x) = udom_principal (basis_emb x)›*) apply (rule udom.principal_mono (*‹ubasis_le ?a ?b ⟹ udom_principal ?a ⊑ udom_principal ?b›*)) (*goal: ‹⋀a b. a ⊑ b ⟹ udom_principal (basis_emb a) ⊑ udom_principal (basis_emb b)›*) by (erule basis_emb_mono (*‹?x ⊑ ?y ⟹ ubasis_le (basis_emb ?x) (basis_emb ?y)›*)) lemma udom_prj_principal: "udom_prj⋅(udom_principal x) = Rep_compact_basis (basis_prj x)" unfolding udom_prj_def (*goal: ‹udom.extension (λx. Rep_compact_basis (basis_prj x))⋅(udom_principal x) = Rep_compact_basis (basis_prj x)›*) apply (rule udom.extension_principal (*‹(⋀a b. ubasis_le a b ⟹ ?f a ⊑ ?f b) ⟹ udom.extension ?f⋅(udom_principal ?a) = ?f ?a›*)) (*goal: ‹udom.extension (λx. Rep_compact_basis (basis_prj x))⋅(udom_principal x) = Rep_compact_basis (basis_prj x)›*) apply (rule compact_basis.principal_mono (*‹?a ⊑ ?b ⟹ Rep_compact_basis ?a ⊑ Rep_compact_basis ?b›*)) (*goal: ‹⋀a b. ubasis_le a b ⟹ Rep_compact_basis (basis_prj a) ⊑ Rep_compact_basis (basis_prj b)›*) by (erule basis_prj_mono (*‹ubasis_le ?a ?b ⟹ basis_prj ?a ⊑ basis_prj ?b›*)) lemma ep_pair_udom: "ep_pair udom_emb udom_prj" apply standard (*goals: 1. ‹⋀x. udom_prj⋅(udom_emb⋅x) = x› 2. ‹⋀y. udom_emb⋅(udom_prj⋅y) ⊑ y› discuss goal 1*) apply (rule compact_basis.principal_induct (*‹⟦adm ?P; ⋀a. ?P (Rep_compact_basis a)⟧ ⟹ ?P ?x›*)) (*goals: 1. ‹⋀x. adm (λa. udom_prj⋅(udom_emb⋅a) = a)› 2. ‹⋀x a. udom_prj⋅(udom_emb⋅(Rep_compact_basis a)) = Rep_compact_basis a› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: udom_emb_principal (*‹udom_emb⋅(Rep_compact_basis ?x) = udom_principal (basis_emb ?x)›*) udom_prj_principal (*‹udom_prj⋅(udom_principal ?x) = Rep_compact_basis (basis_prj ?x)›*)) (*top goal: ‹⋀x a. udom_prj⋅(udom_emb⋅(Rep_compact_basis a)) = Rep_compact_basis a› and 1 goal remains*) apply (simp add: basis_prj_basis_emb (*‹basis_prj (basis_emb ?x) = ?x›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply (rule udom.principal_induct (*‹⟦adm ?P; ⋀a. ?P (udom_principal a)⟧ ⟹ ?P ?x›*)) (*goals: 1. ‹⋀y. adm (λa. udom_emb⋅(udom_prj⋅a) ⊑ a)› 2. ‹⋀y a. udom_emb⋅(udom_prj⋅(udom_principal a)) ⊑ udom_principal a› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: udom_emb_principal (*‹udom_emb⋅(Rep_compact_basis ?x) = udom_principal (basis_emb ?x)›*) udom_prj_principal (*‹udom_prj⋅(udom_principal ?x) = Rep_compact_basis (basis_prj ?x)›*)) (*goal: ‹⋀y a. udom_emb⋅(udom_prj⋅(udom_principal a)) ⊑ udom_principal a›*) apply (rule basis_emb_prj_less (*‹ubasis_le (basis_emb (basis_prj ?x)) ?x›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) . end abbreviation "udom_emb ≡ bifinite_approx_chain.udom_emb" abbreviation "udom_prj ≡ bifinite_approx_chain.udom_prj" lemmas ep_pair_udom = bifinite_approx_chain.ep_pair_udom [unfolded bifinite_approx_chain_def] subsection ‹Chain of approx functions for type \emph{udom}› definition udom_approx :: "nat ⇒ udom → udom" where "udom_approx i = udom.extension (λx. udom_principal (ubasis_until (λy. y ≤ i) x))" lemma udom_approx_mono: "ubasis_le a b ⟹ udom_principal (ubasis_until (λy. y ≤ i) a) ⊑ udom_principal (ubasis_until (λy. y ≤ i) b)" apply (rule udom.principal_mono (*‹ubasis_le ?a ?b ⟹ udom_principal ?a ⊑ udom_principal ?b›*)) (*goal: ‹ubasis_le a b ⟹ udom_principal (ubasis_until (λy. y ≤ i) a) ⊑ udom_principal (ubasis_until (λy. y ≤ i) b)›*) apply (rule ubasis_until_mono (*‹⟦⋀i a S b. ⟦finite S; ?P (node i a S); b ∈ S; ubasis_le a b⟧ ⟹ ?P b; ubasis_le ?a ?b⟧ ⟹ ubasis_le (ubasis_until ?P ?a) (ubasis_until ?P ?b)›*)) (*goals: 1. ‹⋀ia aa S ba. ⟦ubasis_le a b; finite S; node ia aa S ≤ i; ba ∈ S; ubasis_le aa ba⟧ ⟹ ba ≤ i› 2. ‹ubasis_le a b ⟹ ubasis_le a b› discuss goal 1*) apply (frule (2) order_less_le_trans [OF node_gt2] (*‹⟦finite ?S1; ?x ∈ ?S1; node ?i1 ?a1 ?S1 ≤ ?z⟧ ⟹ ?x < ?z›*)) (*top goal: ‹⋀ia aa S ba. ⟦ubasis_le a b; finite S; node ia aa S ≤ i; ba ∈ S; ubasis_le aa ba⟧ ⟹ ba ≤ i› and 1 goal remains*) apply (erule order_less_imp_le (*‹?x < ?y ⟹ ?x ≤ ?y›*)) (*discuss goal 2*) apply assumption (*proven 2 subgoals*) . lemma adm_mem_finite: "⟦cont f; finite S⟧ ⟹ adm (λx. f x ∈ S)" apply (erule adm_subst (*‹⟦cont ?t; adm ?P⟧ ⟹ adm (λx. ?P (?t x))›*)) (*goal: ‹⟦cont f; finite S⟧ ⟹ adm (λx. f x ∈ S)›*) apply (induct set: finite) (*goals: 1. ‹adm (λa. a ∈ {})› 2. ‹⋀x F. ⟦finite F; x ∉ F; adm (λa. a ∈ F)⟧ ⟹ adm (λa. a ∈ insert x F)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma udom_approx_principal: "udom_approx i⋅(udom_principal x) = udom_principal (ubasis_until (λy. y ≤ i) x)" unfolding udom_approx_def (*goal: ‹udom.extension (λx::nat. udom_principal (ubasis_until (λy::nat. y ≤ (i::nat)) x))⋅(udom_principal (x::nat)) = udom_principal (ubasis_until (λy::nat. y ≤ i) x)›*) apply (rule udom.extension_principal (*‹(⋀a b. ubasis_le a b ⟹ ?f a ⊑ ?f b) ⟹ udom.extension ?f⋅(udom_principal ?a) = ?f ?a›*)) (*goal: ‹udom.extension (λx. udom_principal (ubasis_until (λy. y ≤ i) x))⋅(udom_principal x) = udom_principal (ubasis_until (λy. y ≤ i) x)›*) by (erule udom_approx_mono (*‹ubasis_le ?a ?b ⟹ udom_principal (ubasis_until (λy. y ≤ ?i) ?a) ⊑ udom_principal (ubasis_until (λy. y ≤ ?i) ?b)›*)) lemma finite_deflation_udom_approx: "finite_deflation (udom_approx i)" proof (standard) (*goals: 1. ‹⋀x. udom_approx i⋅(udom_approx i⋅x) = udom_approx i⋅x› 2. ‹⋀x. udom_approx i⋅x ⊑ x› 3. ‹finite {x. udom_approx i⋅x = x}›*) fix x show "udom_approx i⋅(udom_approx i⋅x) = udom_approx i⋅x" apply (induct x rule: udom.principal_induct (*‹⟦adm (?P::udom ⇒ bool); ⋀a::nat. ?P (udom_principal a)⟧ ⟹ ?P (?x::udom)›*)) (*goals: 1. ‹adm (λa. udom_approx i⋅(udom_approx i⋅a) = udom_approx i⋅a)› 2. ‹⋀a. udom_approx i⋅(udom_approx i⋅(udom_principal a)) = udom_approx i⋅(udom_principal a)› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: udom_approx_principal (*‹udom_approx ?i⋅(udom_principal ?x) = udom_principal (ubasis_until (λy. y ≤ ?i) ?x)›*) ubasis_until_idem (*‹?P 0 ⟹ ubasis_until ?P (ubasis_until ?P ?x) = ubasis_until ?P ?x›*)) (*proven 2 subgoals*) . next (*goals: 1. ‹⋀x. udom_approx i⋅x ⊑ x› 2. ‹finite {x. udom_approx i⋅x = x}›*) fix x show "udom_approx i⋅x ⊑ x" apply (induct x rule: udom.principal_induct (*‹⟦adm (?P::udom ⇒ bool); ⋀a::nat. ?P (udom_principal a)⟧ ⟹ ?P (?x::udom)›*)) (*goals: 1. ‹adm (λa. udom_approx i⋅a ⊑ a)› 2. ‹⋀a. udom_approx i⋅(udom_principal a) ⊑ udom_principal a› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: udom_approx_principal (*‹udom_approx (?i::nat)⋅(udom_principal (?x::nat)) = udom_principal (ubasis_until (λy::nat. y ≤ ?i) ?x)›*) ubasis_until_less (*‹ubasis_le (ubasis_until (?P::nat ⇒ bool) (?x::nat)) ?x›*)) (*proven 2 subgoals*) . next (*goal: ‹finite {x::udom. udom_approx (i::nat)⋅x = x}›*) have "*": "finite (range (λx. udom_principal (ubasis_until (λy. y ≤ i) x)))" apply (subst range_composition [where f=udom_principal] (*‹range (λx::?'b. udom_principal ((?g::?'b ⇒ nat) x)) = udom_principal ` range ?g›*)) (*goal: ‹finite (range (λx. udom_principal (ubasis_until (λy. y ≤ i) x)))›*) by (simp add: finite_range_ubasis_until (*‹finite {x::nat. (?P::nat ⇒ bool) x} ⟹ finite (range (ubasis_until ?P))›*)) show "finite {x. udom_approx i⋅x = x}" apply (rule finite_range_imp_finite_fixes (*‹finite (range ?f) ⟹ finite {x. ?f x = x}›*)) (*goal: ‹finite {x. udom_approx i⋅x = x}›*) apply (rule rev_finite_subset [OF *] (*‹(?A::udom set) ⊆ range (λx::nat. udom_principal (ubasis_until (λy::nat. y ≤ (i::nat)) x)) ⟹ finite ?A›*)) (*goal: ‹finite (range (Rep_cfun (udom_approx (i::nat))))›*) apply clarsimp (*goal: ‹range (Rep_cfun (udom_approx i)) ⊆ range (λx. udom_principal (ubasis_until (λy. y ≤ i) x))›*) apply (rename_tac x) (*goal: ‹⋀xa. udom_approx i⋅xa ∈ range (λx. udom_principal (ubasis_until (λy. y ≤ i) x))›*) apply (induct_tac x rule: udom.principal_induct) (*goals: 1. ‹⋀x. adm (λa. udom_approx i⋅a ∈ range (λx. udom_principal (ubasis_until (λy. y ≤ i) x)))› 2. ‹⋀x a. udom_approx i⋅(udom_principal a) ∈ range (λx. udom_principal (ubasis_until (λy. y ≤ i) x))› discuss goal 1*) apply (simp add: adm_mem_finite (*‹⟦cont (?f::?'a::cpo ⇒ ?'b::cpo); finite (?S::?'b::cpo set)⟧ ⟹ adm (λx::?'a::cpo. ?f x ∈ ?S)›*) * (*‹finite (range (λx::nat. udom_principal (ubasis_until (λy::nat. y ≤ (i::nat)) x)))›*)) (*discuss goal 2*) apply (simp add: udom_approx_principal (*‹udom_approx ?i⋅(udom_principal ?x) = udom_principal (ubasis_until (λy. y ≤ ?i) ?x)›*)) (*proven 2 subgoals*) . qed interpretation udom_approx: finite_deflation "udom_approx i" by (rule finite_deflation_udom_approx (*‹finite_deflation (udom_approx ?i)›*)) lemma chain_udom_approx [simp]: "chain (λi. udom_approx i)" unfolding udom_approx_def (*goal: ‹chain (λi. udom.extension (λx. udom_principal (ubasis_until (λy. y ≤ i) x)))›*) apply (rule chainI (*‹(⋀i. ?Y i ⊑ ?Y (Suc i)) ⟹ chain ?Y›*)) (*goal: ‹chain (λi. udom.extension (λx. udom_principal (ubasis_until (λy. y ≤ i) x)))›*) apply (rule udom.extension_mono (*‹⟦⋀a b. ubasis_le a b ⟹ ?f a ⊑ ?f b; ⋀a b. ubasis_le a b ⟹ ?g a ⊑ ?g b; ⋀a. ?f a ⊑ ?g a⟧ ⟹ udom.extension ?f ⊑ udom.extension ?g›*)) (*goals: 1. ‹⋀i a b. ubasis_le a b ⟹ udom_principal (ubasis_until (λy. y ≤ i) a) ⊑ udom_principal (ubasis_until (λy. y ≤ i) b)› 2. ‹⋀i a b. ubasis_le a b ⟹ udom_principal (ubasis_until (λy. y ≤ Suc i) a) ⊑ udom_principal (ubasis_until (λy. y ≤ Suc i) b)› 3. ‹⋀i a. udom_principal (ubasis_until (λy. y ≤ i) a) ⊑ udom_principal (ubasis_until (λy. y ≤ Suc i) a)› discuss goal 1*) apply (erule udom_approx_mono (*‹ubasis_le ?a ?b ⟹ udom_principal (ubasis_until (λy. y ≤ ?i) ?a) ⊑ udom_principal (ubasis_until (λy. y ≤ ?i) ?b)›*)) (*discuss goal 2*) apply (erule udom_approx_mono (*‹ubasis_le ?a ?b ⟹ udom_principal (ubasis_until (λy. y ≤ ?i) ?a) ⊑ udom_principal (ubasis_until (λy. y ≤ ?i) ?b)›*)) (*discuss goal 3*) apply (rule udom.principal_mono (*‹ubasis_le ?a ?b ⟹ udom_principal ?a ⊑ udom_principal ?b›*)) (*goal: ‹⋀(i::nat) a::nat. udom_principal (ubasis_until (λy::nat. y ≤ i) a) ⊑ udom_principal (ubasis_until (λy::nat. y ≤ Suc i) a)›*) apply (rule ubasis_until_chain (*‹(⋀x. ?P x ⟹ ?Q x) ⟹ ubasis_le (ubasis_until ?P ?x) (ubasis_until ?Q ?x)›*)) (*goal: ‹⋀i a. ubasis_le (ubasis_until (λy. y ≤ i) a) (ubasis_until (λy. y ≤ Suc i) a)›*) apply simp (*proven 3 subgoals*) . lemma lub_udom_approx [simp]: "(⨆i. udom_approx i) = ID" apply (rule cfun_eqI (*‹(⋀x::?'a. (?f::?'a → ?'b)⋅x = (?g::?'a → ?'b)⋅x) ⟹ ?f = ?g›*)) (*goal: ‹(⨆i. udom_approx i) = ID›*) apply (simp add: contlub_cfun_fun (*‹chain ?F ⟹ (⨆i. ?F i)⋅?x = (⨆i. ?F i⋅?x)›*)) (*goal: ‹⋀x. (⨆i. udom_approx i)⋅x = ID⋅x›*) apply (rule below_antisym (*‹⟦?x ⊑ ?y; ?y ⊑ ?x⟧ ⟹ ?x = ?y›*)) (*goals: 1. ‹⋀x. (⨆i. udom_approx i⋅x) ⊑ x› 2. ‹⋀x. x ⊑ (⨆i. udom_approx i⋅x)› discuss goal 1*) apply (rule lub_below (*‹⟦chain ?S; ⋀i. ?S i ⊑ ?x⟧ ⟹ (⨆i. ?S i) ⊑ ?x›*)) (*goals: 1. ‹⋀x::udom. chain (λi::nat. udom_approx i⋅x)› 2. ‹⋀(x::udom) i::nat. udom_approx i⋅x ⊑ x› discuss goal 1*) apply simp (*discuss goal 2*) apply (rule udom_approx.below (*‹udom_approx ?i⋅?x ⊑ ?x›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply (rule_tac x=x in udom.principal_induct (*‹⟦adm (?P::udom ⇒ bool); ⋀a::nat. ?P (udom_principal a)⟧ ⟹ ?P (?x::udom)›*)) (*goals: 1. ‹⋀x. adm (λa. a ⊑ (⨆i. udom_approx i⋅a))› 2. ‹⋀x a. udom_principal a ⊑ (⨆i. udom_approx i⋅(udom_principal a))› discuss goal 1*) apply (simp add: lub_distribs (*‹⟦chain (?F::nat ⇒ ?'a::cpo → ?'b::cpo); chain (?Y::nat ⇒ ?'a::cpo)⟧ ⟹ (⨆i::nat. ?F i⋅(?Y i)) = (⨆i::nat. ?F i)⋅(⨆i::nat. ?Y i)› ‹⟦⋀x::?'a::cpo. chain (λi::nat. (?F::nat ⇒ ?'a::cpo ⇒ ?'b::cpo) i x); ⋀i::nat. cont (?F i)⟧ ⟹ (⨆i::nat. Λ (x::?'a::cpo). ?F i x) = (Λ (x::?'a::cpo). ⨆i::nat. ?F i x)›*)) (*discuss goal 2*) apply (rule_tac i=a in below_lub (*‹⟦chain ?S; ?x ⊑ ?S ?i⟧ ⟹ ?x ⊑ (⨆i. ?S i)›*)) (*goals: 1. ‹⋀x a. chain (λi. udom_approx i⋅(udom_principal a))› 2. ‹⋀x a. udom_principal a ⊑ udom_approx a⋅(udom_principal a)› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: udom_approx_principal (*‹udom_approx ?i⋅(udom_principal ?x) = udom_principal (ubasis_until (λy. y ≤ ?i) ?x)›*)) (*goal: ‹⋀x a. udom_principal a ⊑ udom_approx a⋅(udom_principal a)›*) apply (simp add: ubasis_until_same (*‹?P ?x ⟹ ubasis_until ?P ?x = ?x›*) ubasis_le_refl (*‹ubasis_le ?a ?a›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma udom_approx [simp]: "approx_chain udom_approx" proof (standard) (*goals: 1. ‹chain udom_approx› 2. ‹(⨆i. udom_approx i) = ID›*) show "chain (λi. udom_approx i)" by (rule chain_udom_approx (*‹chain udom_approx›*)) show "(⨆i. udom_approx i) = ID" by (rule lub_udom_approx (*‹(⨆i. udom_approx i) = ID›*)) qed instance udom :: bifinite by standard (fast intro: udom_approx) hide_const (open) node notation binomial (infixl "choose" 65) end
{ "path": "Isabelle2024/src/HOL/HOLCF/Universal.thy", "repo": "Isabelle2024", "sha": "5f53c7ae070a6ad0081d98f12d2b1b2185b5629401303604863ca0fbae9ed5ae" }
section ‹The Proof System› theory OG_Hoare imports OG_Tran begin primrec assertions :: "'a ann_com ⇒ ('a assn) set" where "assertions (AnnBasic r f) = {r}" | "assertions (AnnSeq c1 c2) = assertions c1 ∪ assertions c2" | "assertions (AnnCond1 r b c1 c2) = {r} ∪ assertions c1 ∪ assertions c2" | "assertions (AnnCond2 r b c) = {r} ∪ assertions c" | "assertions (AnnWhile r b i c) = {r, i} ∪ assertions c" | "assertions (AnnAwait r b c) = {r}" primrec atomics :: "'a ann_com ⇒ ('a assn × 'a com) set" where "atomics (AnnBasic r f) = {(r, Basic f)}" | "atomics (AnnSeq c1 c2) = atomics c1 ∪ atomics c2" | "atomics (AnnCond1 r b c1 c2) = atomics c1 ∪ atomics c2" | "atomics (AnnCond2 r b c) = atomics c" | "atomics (AnnWhile r b i c) = atomics c" | "atomics (AnnAwait r b c) = {(r ∩ b, c)}" primrec com :: "'a ann_triple_op ⇒ 'a ann_com_op" where "com (c, q) = c" primrec post :: "'a ann_triple_op ⇒ 'a assn" where "post (c, q) = q" definition interfree_aux :: "('a ann_com_op × 'a assn × 'a ann_com_op) ⇒ bool" where "interfree_aux ≡ λ(co, q, co'). co'= None ∨ (∀(r,a) ∈ atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p ∈ assertions (the co). ∥= (p ∩ r) a p)))" definition interfree :: "(('a ann_triple_op) list) ⇒ bool" where "interfree Ts ≡ ∀i j. i < length Ts ∧ j < length Ts ∧ i ≠ j ⟶ interfree_aux (com (Ts!i), post (Ts!i), com (Ts!j)) " inductive oghoare :: "'a assn ⇒ 'a com ⇒ 'a assn ⇒ bool" ("(3∥- _//_//_)" [90,55,90] 50) and ann_hoare :: "'a ann_com ⇒ 'a assn ⇒ bool" ("(2⊢ _// _)" [60,90] 45) where AnnBasic: "r ⊆ {s. f s ∈ q} ⟹ ⊢ (AnnBasic r f) q" | AnnSeq: "⟦ ⊢ c0 pre c1; ⊢ c1 q ⟧ ⟹ ⊢ (AnnSeq c0 c1) q" | AnnCond1: "⟦ r ∩ b ⊆ pre c1; ⊢ c1 q; r ∩ -b ⊆ pre c2; ⊢ c2 q⟧ ⟹ ⊢ (AnnCond1 r b c1 c2) q" | AnnCond2: "⟦ r ∩ b ⊆ pre c; ⊢ c q; r ∩ -b ⊆ q ⟧ ⟹ ⊢ (AnnCond2 r b c) q" | AnnWhile: "⟦ r ⊆ i; i ∩ b ⊆ pre c; ⊢ c i; i ∩ -b ⊆ q ⟧ ⟹ ⊢ (AnnWhile r b i c) q" | AnnAwait: "⟦ atom_com c; ∥- (r ∩ b) c q ⟧ ⟹ ⊢ (AnnAwait r b c) q" | AnnConseq: "⟦⊢ c q; q ⊆ q' ⟧ ⟹ ⊢ c q'" | Parallel: "⟦ ∀i<length Ts. ∃c q. Ts!i = (Some c, q) ∧ ⊢ c q; interfree Ts ⟧ ⟹ ∥- (⋂i∈{i. i<length Ts}. pre(the(com(Ts!i)))) Parallel Ts (⋂i∈{i. i<length Ts}. post(Ts!i))" | Basic: "∥- {s. f s ∈q} (Basic f) q" | Seq: "⟦ ∥- p c1 r; ∥- r c2 q ⟧ ⟹ ∥- p (Seq c1 c2) q " | Cond: "⟦ ∥- (p ∩ b) c1 q; ∥- (p ∩ -b) c2 q ⟧ ⟹ ∥- p (Cond b c1 c2) q" | While: "⟦ ∥- (p ∩ b) c p ⟧ ⟹ ∥- p (While b i c) (p ∩ -b)" | Conseq: "⟦ p' ⊆ p; ∥- p c q ; q ⊆ q' ⟧ ⟹ ∥- p' c q'" section ‹Soundness› (* In the version Isabelle-10-Sep-1999: HOL: The THEN and ELSE parts of conditional expressions (if P then x else y) are no longer simplified. (This allows the simplifier to unfold recursive functional programs.) To restore the old behaviour, we declare @{text "lemmas [cong del] = if_weak_cong"}. *) lemmas [cong del] = if_weak_cong lemmas ann_hoare_induct = oghoare_ann_hoare.induct [THEN conjunct2] lemmas oghoare_induct = oghoare_ann_hoare.induct [THEN conjunct1] lemmas AnnBasic = oghoare_ann_hoare.AnnBasic lemmas AnnSeq = oghoare_ann_hoare.AnnSeq lemmas AnnCond1 = oghoare_ann_hoare.AnnCond1 lemmas AnnCond2 = oghoare_ann_hoare.AnnCond2 lemmas AnnWhile = oghoare_ann_hoare.AnnWhile lemmas AnnAwait = oghoare_ann_hoare.AnnAwait lemmas AnnConseq = oghoare_ann_hoare.AnnConseq lemmas Parallel = oghoare_ann_hoare.Parallel lemmas Basic = oghoare_ann_hoare.Basic lemmas Seq = oghoare_ann_hoare.Seq lemmas Cond = oghoare_ann_hoare.Cond lemmas While = oghoare_ann_hoare.While lemmas Conseq = oghoare_ann_hoare.Conseq subsection ‹Soundness of the System for Atomic Programs› lemma Basic_ntran [rule_format]: "(Basic f, s) -Pn→ (Parallel Ts, t) ⟶ All_None Ts ⟶ t = f s" apply (induct "n") (*goals: 1. ‹(Basic f, s) -P0→ (Parallel Ts, t) ⟶ All_None Ts ⟶ t = f s› 2. ‹⋀n. (Basic f, s) -Pn→ (Parallel Ts, t) ⟶ All_None Ts ⟶ t = f s ⟹ (Basic f, s) -PSuc n→ (Parallel Ts, t) ⟶ All_None Ts ⟶ t = f s› discuss goal 1*) apply (simp (no_asm)) (*discuss goal 2*) apply (fast dest: relpow_Suc_D2 (*‹(?x, ?z) ∈ ?R ^^ Suc ?n ⟹ ∃y. (?x, y) ∈ ?R ∧ (y, ?z) ∈ ?R ^^ ?n›*) Parallel_empty_lemma (*‹(Parallel [], ?s) -P?n→ (Parallel ?Ts, ?t) ⟹ ?Ts = [] ∧ ?n = 0 ∧ ?s = ?t›*) elim: transition_cases (*‹⟦(Parallel ?T, ?s) -P1→ ?t; ⋀i c q r t. ⟦?t = (Parallel (?T[i := (r, q)]), t); i < length ?T; ?T ! i = (Some c, q); (Some c, ?s) -1→ (r, t)⟧ ⟹ ?P⟧ ⟹ ?P› ‹⟦(Basic ?f, ?s) -P1→ ?t; ?t = (Parallel [], ?f ?s) ⟹ ?P⟧ ⟹ ?P› ‹⟦(Seq ?c1.0 ?c2.0, ?s) -P1→ ?t; ⋀Ts. ⟦?c1.0 = Parallel Ts; ?t = (?c2.0, ?s); All_None Ts⟧ ⟹ ?P; ⋀c2 t. ⟦?t = (Seq c2 ?c2.0, t); (?c1.0, ?s) -P1→ (c2, t)⟧ ⟹ ?P⟧ ⟹ ?P› ‹⟦(Cond ?b ?c1.0 ?c2.0, ?s) -P1→ ?t; ⟦?t = (?c1.0, ?s); ?s ∈ ?b⟧ ⟹ ?P; ⟦?t = (?c2.0, ?s); ?s ∉ ?b⟧ ⟹ ?P⟧ ⟹ ?P› ‹⟦(While ?b ?i ?c, ?s) -P1→ ?t; ⟦?t = (Parallel [], ?s); ?s ∉ ?b⟧ ⟹ ?P; ⟦?t = (Seq ?c (While ?b ?i ?c), ?s); ?s ∈ ?b⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*proven 2 subgoals*) . lemma SEM_fwhile: "SEM S (p ∩ b) ⊆ p ⟹ SEM (fwhile b S k) p ⊆ (p ∩ -b)" apply (induct "k") (*goals: 1. ‹SEM S (p ∩ b) ⊆ p ⟹ SEM (fwhile b S 0) p ⊆ p ∩ - b› 2. ‹⋀k. ⟦SEM S (p ∩ b) ⊆ p ⟹ SEM (fwhile b S k) p ⊆ p ∩ - b; SEM S (p ∩ b) ⊆ p⟧ ⟹ SEM (fwhile b S (Suc k)) p ⊆ p ∩ - b› discuss goal 1*) apply (simp (no_asm) add: L3_5v_lemma3 (*‹SEM (Ω) ?S = {}›*)) (*discuss goal 2*) apply (simp (no_asm) add: L3_5iv (*‹SEM (Cond ?b ?c1.0 ?c2.0) ?X = SEM ?c1.0 (?X ∩ ?b) ∪ SEM ?c2.0 (?X ∩ - ?b)›*) L3_5ii (*‹SEM (Seq ?c1.0 ?c2.0) ?X = SEM ?c2.0 (SEM ?c1.0 ?X)›*) Parallel_empty (*‹?Ts = [] ⟹ SEM (Parallel ?Ts) ?X = ?X›*)) (*goal: ‹⋀k::nat. ⟦SEM (S::'a::type com) ((p::'a::type set) ∩ (b::'a::type set)) ⊆ p ⟹ SEM (fwhile b S k) p ⊆ p ∩ - b; SEM S (p ∩ b) ⊆ p⟧ ⟹ SEM (fwhile b S (Suc k)) p ⊆ p ∩ - b›*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹⋀k. ⟦SEM S (p ∩ b) ⊆ p ⟹ SEM (fwhile b S k) p ⊆ p ∩ - b; SEM S (p ∩ b) ⊆ p⟧ ⟹ SEM (fwhile b S k) (SEM S (p ∩ b)) ⊆ p› 2. ‹⋀k. ⟦SEM S (p ∩ b) ⊆ p ⟹ SEM (fwhile b S k) p ⊆ p ∩ - b; SEM S (p ∩ b) ⊆ p⟧ ⟹ SEM (Basic id) (p ∩ - b) ⊆ p ∧ SEM (fwhile b S k) (SEM S (p ∩ b)) ⊆ - b ∧ SEM (Basic id) (p ∩ - b) ⊆ - b› discuss goal 1*) apply (blast dest: L3_5i (*‹?X ⊆ ?Y ⟹ SEM ?c ?X ⊆ SEM ?c ?Y›*)) (*discuss goal 2*) apply (simp add: SEM_def (*‹SEM ?c ?S ≡ ⋃ (sem ?c ` ?S)›*) sem_def (*‹sem ?c ≡ λs. {t. ∃Ts. (?c, s) -P*→ (Parallel Ts, t) ∧ All_None Ts}›*) id_def (*‹id = (λx. x)›*)) (*goal: ‹⋀k. ⟦SEM S (p ∩ b) ⊆ p ⟹ SEM (fwhile b S k) p ⊆ p ∩ - b; SEM S (p ∩ b) ⊆ p⟧ ⟹ SEM (Basic id) (p ∩ - b) ⊆ p ∧ SEM (fwhile b S k) (SEM S (p ∩ b)) ⊆ - b ∧ SEM (Basic id) (p ∩ - b) ⊆ - b›*) apply (auto dest: Basic_ntran (*‹⟦(Basic ?f, ?s) -P?n→ (Parallel ?Ts, ?t); All_None ?Ts⟧ ⟹ ?t = ?f ?s›*) rtrancl_imp_UN_relpow (*‹?p ∈ ?R⇧* ⟹ ?p ∈ ⋃ (range ((^^) ?R))›*)) (*goal: ‹⋀k. ⟦(⋃x∈p. {t. ∃Ts. (fwhile b S k, x) -P*→ (Parallel Ts, t) ∧ All_None Ts}) ⊆ p ∧ (⋃x∈p. {t. ∃Ts. (fwhile b S k, x) -P*→ (Parallel Ts, t) ∧ All_None Ts}) ⊆ - b; (⋃x∈p ∩ b. {t. ∃Ts. (S, x) -P*→ (Parallel Ts, t) ∧ All_None Ts}) ⊆ p⟧ ⟹ (⋃x∈p ∩ - b. {t. ∃Ts. (Basic (λx. x), x) -P*→ (Parallel Ts, t) ∧ All_None Ts}) ⊆ p ∧ (⋃x∈p ∩ b. ⋃x∈{t. ∃Ts. (S, x) -P*→ (Parallel Ts, t) ∧ All_None Ts}. {t. ∃Ts. (fwhile b S k, x) -P*→ (Parallel Ts, t) ∧ All_None Ts}) ⊆ - b ∧ (⋃x∈p ∩ - b. {t. ∃Ts. (Basic (λx. x), x) -P*→ (Parallel Ts, t) ∧ All_None Ts}) ⊆ - b›*) apply blast (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma atom_hoare_sound [rule_format]: " ∥- p c q ⟶ atom_com(c) ⟶ ∥= p c q" apply (unfold com_validity_def (*‹∥= ?p ?c ?q ≡ SEM ?c ?p ⊆ ?q›*)) (*goal: ‹∥- p c q ⟶ atom_com c ⟶ ∥= p c q›*) apply (rule oghoare_induct (*‹⟦⋀r f q. r ⊆ {s. f s ∈ q} ⟹ ?P2.0 (AnnBasic r f) q; ⋀c0 c1 q. ⟦⊢ c0 pre c1; ?P2.0 c0 (pre c1); ⊢ c1 q; ?P2.0 c1 q⟧ ⟹ ?P2.0 (AnnSeq c0 c1) q; ⋀r b c1 q c2. ⟦r ∩ b ⊆ pre c1; ⊢ c1 q; ?P2.0 c1 q; r ∩ - b ⊆ pre c2; ⊢ c2 q; ?P2.0 c2 q⟧ ⟹ ?P2.0 (AnnCond1 r b c1 c2) q; ⋀r b c q. ⟦r ∩ b ⊆ pre c; ⊢ c q; ?P2.0 c q; r ∩ - b ⊆ q⟧ ⟹ ?P2.0 (AnnCond2 r b c) q; ⋀r i b c q. ⟦r ⊆ i; i ∩ b ⊆ pre c; ⊢ c i; ?P2.0 c i; i ∩ - b ⊆ q⟧ ⟹ ?P2.0 (AnnWhile r b i c) q; ⋀c r b q. ⟦atom_com c; ∥- (r ∩ b) c q; ?P1.0 (r ∩ b) c q⟧ ⟹ ?P2.0 (AnnAwait r b c) q; ⋀c q q'. ⟦⊢ c q; ?P2.0 c q; q ⊆ q'⟧ ⟹ ?P2.0 c q'; ⋀Ts. ⟦∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ ⊢ c q ∧ ?P2.0 c q; interfree Ts⟧ ⟹ ?P1.0 (⋂i∈{i. i < length Ts}. pre (the (OG_Hoare.com (Ts ! i)))) (Parallel Ts) (⋂i∈{i. i < length Ts}. OG_Hoare.post (Ts ! i)); ⋀f q. ?P1.0 {s. f s ∈ q} (Basic f) q; ⋀p c1 r c2 q. ⟦∥- p c1 r; ?P1.0 p c1 r; ∥- r c2 q; ?P1.0 r c2 q⟧ ⟹ ?P1.0 p (Seq c1 c2) q; ⋀p b c1 q c2. ⟦∥- (p ∩ b) c1 q; ?P1.0 (p ∩ b) c1 q; ∥- (p ∩ - b) c2 q; ?P1.0 (p ∩ - b) c2 q⟧ ⟹ ?P1.0 p (Cond b c1 c2) q; ⋀p b c i. ⟦∥- (p ∩ b) c p; ?P1.0 (p ∩ b) c p⟧ ⟹ ?P1.0 p (While b i c) (p ∩ - b); ⋀p' p c q q'. ⟦p' ⊆ p; ∥- p c q; ?P1.0 p c q; q ⊆ q'⟧ ⟹ ?P1.0 p' c q'⟧ ⟹ ∥- ?x1.0 ?x2.0 ?x3.0 ⟶ ?P1.0 ?x1.0 ?x2.0 ?x3.0›*)) (*goal: ‹∥- p c q ⟶ atom_com c ⟶ SEM c p ⊆ q›*) apply simp_all (*top goal: ‹⋀r f q. r ⊆ {s. f s ∈ q} ⟹ ?P2.0 (AnnBasic r f) q› and 12 goals remain*) apply (simp add: SEM_def (*‹SEM (?c::?'a com) (?S::?'a set) ≡ ⋃ (sem ?c ` ?S)›*) sem_def (*‹sem (?c::?'a com) ≡ λs::?'a. {t::?'a. ∃Ts::(?'a ann_com option × ?'a set) list. (?c, s) -P*→ (Parallel Ts, t) ∧ All_None Ts}›*)) (*top goal: ‹⋀f q. SEM (Basic f) {s. f s ∈ q} ⊆ q› and 4 goals remain*) apply (fast dest: rtrancl_imp_UN_relpow (*‹?p ∈ ?R⇧* ⟹ ?p ∈ ⋃ (range ((^^) ?R))›*) Basic_ntran (*‹⟦(Basic ?f, ?s) -P?n→ (Parallel ?Ts, ?t); All_None ?Ts⟧ ⟹ ?t = ?f ?s›*)) (*top goal: ‹⋀f q. (⋃x∈{s. f s ∈ q}. {t. ∃Ts. (Basic f, x) -P*→ (Parallel Ts, t) ∧ All_None Ts}) ⊆ q› and 4 goals remain*) apply (rule impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*top goal: ‹⋀p c1 r c2 q. ⟦∥- p c1 r; atom_com c1 ⟶ SEM c1 p ⊆ r; ∥- r c2 q; atom_com c2 ⟶ SEM c2 r ⊆ q⟧ ⟹ atom_com c1 ∧ atom_com c2 ⟶ SEM (Seq c1 c2) p ⊆ q› and 3 goals remain*) apply (rule subset_trans (*‹⟦?A ⊆ ?B; ?B ⊆ ?C⟧ ⟹ ?A ⊆ ?C›*)) (*top goal: ‹⋀(p::'a set) (c1::'a com) (r::'a set) (c2::'a com) q::'a set. ⟦∥- p c1 r; atom_com c1 ⟶ SEM c1 p ⊆ r; ∥- r c2 q; atom_com c2 ⟶ SEM c2 r ⊆ q; atom_com c1 ∧ atom_com c2⟧ ⟹ SEM (Seq c1 c2) p ⊆ q› and 3 goals remain*) prefer 2 (*top goal: ‹⋀p c1 r c2 q. ⟦∥- p c1 r; atom_com c1 ⟶ SEM c1 p ⊆ r; ∥- r c2 q; atom_com c2 ⟶ SEM c2 r ⊆ q; atom_com c1 ∧ atom_com c2⟧ ⟹ ?B28 p c1 r c2 q ⊆ q› and 4 goals remain*) apply simp (*top goal: ‹⋀p c1 r c2 q. ⟦∥- p c1 r; atom_com c1 ⟶ SEM c1 p ⊆ r; ∥- r c2 q; atom_com c2 ⟶ SEM c2 r ⊆ q; atom_com c1 ∧ atom_com c2⟧ ⟹ ?B28 p c1 r c2 q ⊆ q› and 4 goals remain*) apply (simp add: L3_5ii (*‹SEM (Seq ?c1.0 ?c2.0) ?X = SEM ?c2.0 (SEM ?c1.0 ?X)›*) L3_5i (*‹?X ⊆ ?Y ⟹ SEM ?c ?X ⊆ SEM ?c ?Y›*)) (*top goal: ‹⋀p c1 r c2 q. ⟦∥- p c1 r; atom_com c1 ⟶ SEM c1 p ⊆ r; ∥- r c2 q; atom_com c2 ⟶ SEM c2 r ⊆ q; atom_com c1 ∧ atom_com c2⟧ ⟹ SEM (Seq c1 c2) p ⊆ SEM c2 r› and 3 goals remain*) apply (simp add: L3_5iv (*‹SEM (Cond ?b ?c1.0 ?c2.0) ?X = SEM ?c1.0 (?X ∩ ?b) ∪ SEM ?c2.0 (?X ∩ - ?b)›*)) (*top goal: ‹⋀p b c1 q c2. ⟦∥- (p ∩ b) c1 q; atom_com c1 ⟶ SEM c1 (p ∩ b) ⊆ q; ∥- (p ∩ - b) c2 q; atom_com c2 ⟶ SEM c2 (p ∩ - b) ⊆ q⟧ ⟹ atom_com c1 ∧ atom_com c2 ⟶ SEM (Cond b c1 c2) p ⊆ q› and 2 goals remain*) apply (force simp add: L3_5v (*‹SEM (While ?b ?i ?c) = (λx. ⋃k. SEM (fwhile ?b ?c k) x)›*) dest: SEM_fwhile (*‹SEM ?S (?p ∩ ?b) ⊆ ?p ⟹ SEM (fwhile ?b ?S ?k) ?p ⊆ ?p ∩ - ?b›*)) (*top goal: ‹⋀p b c i. ⟦∥- (p ∩ b) c p; atom_com c ⟶ SEM c (p ∩ b) ⊆ p⟧ ⟹ atom_com c ⟶ SEM (While b i c) p ⊆ p ∧ SEM (While b i c) p ⊆ - b› and 1 goal remains*) by (force simp add: SEM_def (*‹SEM ?c ?S ≡ ⋃ (sem ?c ` ?S)›*) sem_def (*‹sem ?c ≡ λs. {t. ∃Ts. (?c, s) -P*→ (Parallel Ts, t) ∧ All_None Ts}›*)) subsection ‹Soundness of the System for Component Programs› inductive_cases ann_transition_cases: "(None,s) -1→ (c', s')" "(Some (AnnBasic r f),s) -1→ (c', s')" "(Some (AnnSeq c1 c2), s) -1→ (c', s')" "(Some (AnnCond1 r b c1 c2), s) -1→ (c', s')" "(Some (AnnCond2 r b c), s) -1→ (c', s')" "(Some (AnnWhile r b I c), s) -1→ (c', s')" "(Some (AnnAwait r b c),s) -1→ (c', s')" text ‹Strong Soundness for Component Programs:› lemma ann_hoare_case_analysis [rule_format]: "⊢ C q' ⟶ ((∀r f. C = AnnBasic r f ⟶ (∃q. r ⊆ {s. f s ∈ q} ∧ q ⊆ q')) ∧ (∀c0 c1. C = AnnSeq c0 c1 ⟶ (∃q. q ⊆ q' ∧ ⊢ c0 pre c1 ∧ ⊢ c1 q)) ∧ (∀r b c1 c2. C = AnnCond1 r b c1 c2 ⟶ (∃q. q ⊆ q' ∧ r ∩ b ⊆ pre c1 ∧ ⊢ c1 q ∧ r ∩ -b ⊆ pre c2 ∧ ⊢ c2 q)) ∧ (∀r b c. C = AnnCond2 r b c ⟶ (∃q. q ⊆ q' ∧ r ∩ b ⊆ pre c ∧ ⊢ c q ∧ r ∩ -b ⊆ q)) ∧ (∀r i b c. C = AnnWhile r b i c ⟶ (∃q. q ⊆ q' ∧ r ⊆ i ∧ i ∩ b ⊆ pre c ∧ ⊢ c i ∧ i ∩ -b ⊆ q)) ∧ (∀r b c. C = AnnAwait r b c ⟶ (∃q. q ⊆ q' ∧ ∥- (r ∩ b) c q)))" apply (rule ann_hoare_induct (*‹⟦⋀(r::?'a set) (f::?'a ⇒ ?'a) q::?'a set. r ⊆ {s::?'a. f s ∈ q} ⟹ (?P2.0::?'a ann_com ⇒ ?'a set ⇒ bool) (AnnBasic r f) q; ⋀(c0::?'a ann_com) (c1::?'a ann_com) q::?'a set. ⟦⊢ c0 pre c1; ?P2.0 c0 (pre c1); ⊢ c1 q; ?P2.0 c1 q⟧ ⟹ ?P2.0 (AnnSeq c0 c1) q; ⋀(r::?'a set) (b::?'a set) (c1::?'a ann_com) (q::?'a set) c2::?'a ann_com. ⟦r ∩ b ⊆ pre c1; ⊢ c1 q; ?P2.0 c1 q; r ∩ - b ⊆ pre c2; ⊢ c2 q; ?P2.0 c2 q⟧ ⟹ ?P2.0 (AnnCond1 r b c1 c2) q; ⋀(r::?'a set) (b::?'a set) (c::?'a ann_com) q::?'a set. ⟦r ∩ b ⊆ pre c; ⊢ c q; ?P2.0 c q; r ∩ - b ⊆ q⟧ ⟹ ?P2.0 (AnnCond2 r b c) q; ⋀(r::?'a set) (i::?'a set) (b::?'a set) (c::?'a ann_com) q::?'a set. ⟦r ⊆ i; i ∩ b ⊆ pre c; ⊢ c i; ?P2.0 c i; i ∩ - b ⊆ q⟧ ⟹ ?P2.0 (AnnWhile r b i c) q; ⋀(c::?'a com) (r::?'a set) (b::?'a set) q::?'a set. ⟦atom_com c; ∥- (r ∩ b) c q; (?P1.0::?'a set ⇒ ?'a com ⇒ ?'a set ⇒ bool) (r ∩ b) c q⟧ ⟹ ?P2.0 (AnnAwait r b c) q; ⋀(c::?'a ann_com) (q::?'a set) q'::?'a set. ⟦⊢ c q; ?P2.0 c q; q ⊆ q'⟧ ⟹ ?P2.0 c q'; ⋀Ts::(?'a ann_com option × ?'a set) list. ⟦∀i<length Ts. ∃(c::?'a ann_com) q::?'a set. Ts ! i = (Some c, q) ∧ ⊢ c q ∧ ?P2.0 c q; interfree Ts⟧ ⟹ ?P1.0 (⋂i::nat∈{i::nat. i < length Ts}. pre (the (OG_Hoare.com (Ts ! i)))) (Parallel Ts) (⋂i::nat∈{i::nat. i < length Ts}. OG_Hoare.post (Ts ! i)); ⋀(f::?'a ⇒ ?'a) q::?'a set. ?P1.0 {s::?'a. f s ∈ q} (Basic f) q; ⋀(p::?'a set) (c1::?'a com) (r::?'a set) (c2::?'a com) q::?'a set. ⟦∥- p c1 r; ?P1.0 p c1 r; ∥- r c2 q; ?P1.0 r c2 q⟧ ⟹ ?P1.0 p (Seq c1 c2) q; ⋀(p::?'a set) (b::?'a set) (c1::?'a com) (q::?'a set) c2::?'a com. ⟦∥- (p ∩ b) c1 q; ?P1.0 (p ∩ b) c1 q; ∥- (p ∩ - b) c2 q; ?P1.0 (p ∩ - b) c2 q⟧ ⟹ ?P1.0 p (Cond b c1 c2) q; ⋀(p::?'a set) (b::?'a set) (c::?'a com) i::?'a set. ⟦∥- (p ∩ b) c p; ?P1.0 (p ∩ b) c p⟧ ⟹ ?P1.0 p (While b i c) (p ∩ - b); ⋀(p'::?'a set) (p::?'a set) (c::?'a com) (q::?'a set) q'::?'a set. ⟦p' ⊆ p; ∥- p c q; ?P1.0 p c q; q ⊆ q'⟧ ⟹ ?P1.0 p' c q'⟧ ⟹ ⊢ (?x4.0::?'a ann_com) (?x5.0::?'a set) ⟶ ?P2.0 ?x4.0 ?x5.0›*)) (*goal: ‹⊢ C q' ⟶ (∀r f. C = AnnBasic r f ⟶ (∃q. r ⊆ {s. f s ∈ q} ∧ q ⊆ q')) ∧ (∀c0 c1. C = AnnSeq c0 c1 ⟶ (∃q⊆q'. ⊢ c0 pre c1 ∧ ⊢ c1 q)) ∧ (∀r b c1 c2. C = AnnCond1 r b c1 c2 ⟶ (∃q⊆q'. r ∩ b ⊆ pre c1 ∧ ⊢ c1 q ∧ r ∩ - b ⊆ pre c2 ∧ ⊢ c2 q)) ∧ (∀r b c. C = AnnCond2 r b c ⟶ (∃q⊆q'. r ∩ b ⊆ pre c ∧ ⊢ c q ∧ r ∩ - b ⊆ q)) ∧ (∀r i b c. C = AnnWhile r b i c ⟶ (∃q⊆q'. r ⊆ i ∧ i ∩ b ⊆ pre c ∧ ⊢ c i ∧ i ∩ - b ⊆ q)) ∧ (∀r b c. C = AnnAwait r b c ⟶ (∃q⊆q'. ∥- (r ∩ b) c q))›*) apply simp_all (*top goal: ‹⋀r f q. r ⊆ {s. f s ∈ q} ⟹ (∀ra fa. AnnBasic r f = AnnBasic ra fa ⟶ (∃qa. ra ⊆ {s. fa s ∈ qa} ∧ qa ⊆ q)) ∧ (∀c0 c1. AnnBasic r f = AnnSeq c0 c1 ⟶ (∃qa⊆q. ⊢ c0 pre c1 ∧ ⊢ c1 qa)) ∧ (∀ra b c1 c2. AnnBasic r f = AnnCond1 ra b c1 c2 ⟶ (∃qa⊆q. ra ∩ b ⊆ pre c1 ∧ ⊢ c1 qa ∧ ra ∩ - b ⊆ pre c2 ∧ ⊢ c2 qa)) ∧ (∀ra b c. AnnBasic r f = AnnCond2 ra b c ⟶ (∃qa⊆q. ra ∩ b ⊆ pre c ∧ ⊢ c qa ∧ ra ∩ - b ⊆ qa)) ∧ (∀ra i b c. AnnBasic r f = AnnWhile ra b i c ⟶ (∃qa⊆q. ra ⊆ i ∧ i ∩ b ⊆ pre c ∧ ⊢ c i ∧ i ∩ - b ⊆ qa)) ∧ (∀ra b c. AnnBasic r f = AnnAwait ra b c ⟶ (∃qa⊆q. ∥- (ra ∩ b) c qa))› and 12 goals remain*) apply ((rule_tac x=q in exI (*‹?P ?x ⟹ ∃x. ?P x›*), simp)+) (*top goal: ‹⋀r f q. r ⊆ {s. f s ∈ q} ⟹ ∃qa. r ⊆ {s. f s ∈ qa} ∧ qa ⊆ q› and 6 goals remain*) apply ((rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*), clarify, simp, clarify, rule_tac x=qa in exI (*‹?P ?x ⟹ ∃x. ?P x›*), fast)+) (*goal: ‹⋀(c::'a::type ann_com) (q::'a::type set) q'::'a::type set. ⟦⊢ c q; (∀(r::'a::type set) f::'a::type ⇒ 'a::type. c = AnnBasic r f ⟶ (∃qa::'a::type set. r ⊆ {s::'a::type. f s ∈ qa} ∧ qa ⊆ q)) ∧ (∀(c0::'a::type ann_com) c1::'a::type ann_com. c = AnnSeq c0 c1 ⟶ (∃qa⊆q. ⊢ c0 pre c1 ∧ ⊢ c1 qa)) ∧ (∀(r::'a::type set) (b::'a::type set) (c1::'a::type ann_com) c2::'a::type ann_com. c = AnnCond1 r b c1 c2 ⟶ (∃qa⊆q. r ∩ b ⊆ pre c1 ∧ ⊢ c1 qa ∧ r ∩ - b ⊆ pre c2 ∧ ⊢ c2 qa)) ∧ (∀(r::'a::type set) (b::'a::type set) ca::'a::type ann_com. c = AnnCond2 r b ca ⟶ (∃qa⊆q. r ∩ b ⊆ pre ca ∧ ⊢ ca qa ∧ r ∩ - b ⊆ qa)) ∧ (∀(r::'a::type set) (i::'a::type set) (b::'a::type set) ca::'a::type ann_com. c = AnnWhile r b i ca ⟶ (∃qa⊆q. r ⊆ i ∧ i ∩ b ⊆ pre ca ∧ ⊢ ca i ∧ i ∩ - b ⊆ qa)) ∧ (∀(r::'a::type set) (b::'a::type set) ca::'a::type com. c = AnnAwait r b ca ⟶ (∃qa⊆q. ∥- (r ∩ b) ca qa)); q ⊆ q'⟧ ⟹ (∀(r::'a::type set) f::'a::type ⇒ 'a::type. c = AnnBasic r f ⟶ (∃q::'a::type set. r ⊆ {s::'a::type. f s ∈ q} ∧ q ⊆ q')) ∧ (∀(c0::'a::type ann_com) c1::'a::type ann_com. c = AnnSeq c0 c1 ⟶ (∃q⊆q'. ⊢ c0 pre c1 ∧ ⊢ c1 q)) ∧ (∀(r::'a::type set) (b::'a::type set) (c1::'a::type ann_com) c2::'a::type ann_com. c = AnnCond1 r b c1 c2 ⟶ (∃q⊆q'. r ∩ b ⊆ pre c1 ∧ ⊢ c1 q ∧ r ∩ - b ⊆ pre c2 ∧ ⊢ c2 q)) ∧ (∀(r::'a::type set) (b::'a::type set) ca::'a::type ann_com. c = AnnCond2 r b ca ⟶ (∃q⊆q'. r ∩ b ⊆ pre ca ∧ ⊢ ca q ∧ r ∩ - b ⊆ q)) ∧ (∀(r::'a::type set) (i::'a::type set) (b::'a::type set) ca::'a::type ann_com. c = AnnWhile r b i ca ⟶ (∃q⊆q'. r ⊆ i ∧ i ∩ b ⊆ pre ca ∧ ⊢ ca i ∧ i ∩ - b ⊆ q)) ∧ (∀(r::'a::type set) (b::'a::type set) ca::'a::type com. c = AnnAwait r b ca ⟶ (∃q⊆q'. ∥- (r ∩ b) ca q))›*) by (clarify, simp, clarify, rule_tac x=qa in exI (*‹(?P::?'a ⇒ bool) (?x::?'a) ⟹ ∃x::?'a. ?P x›*), fast) lemma Help: "(transition ∩ {(x,y). True}) = (transition)" by force lemma Strong_Soundness_aux_aux [rule_format]: "(co, s) -1→ (co', t) ⟶ (∀c. co = Some c ⟶ s∈ pre c ⟶ (∀q. ⊢ c q ⟶ (if co' = None then t∈q else t ∈ pre(the co') ∧ ⊢ (the co') q )))" apply (rule ann_transition_transition.induct [THEN conjunct1] (*‹⟦⋀r f s. ?P1.1 (Some (AnnBasic r f)) s None (f s); ⋀c0 s t c1. ⟦(Some c0, s) -1→ (None, t); ?P1.1 (Some c0) s None t⟧ ⟹ ?P1.1 (Some (AnnSeq c0 c1)) s (Some c1) t; ⋀c0 s c2 t c1. ⟦(Some c0, s) -1→ (Some c2, t); ?P1.1 (Some c0) s (Some c2) t⟧ ⟹ ?P1.1 (Some (AnnSeq c0 c1)) s (Some (AnnSeq c2 c1)) t; ⋀s b r c1 c2. s ∈ b ⟹ ?P1.1 (Some (AnnCond1 r b c1 c2)) s (Some c1) s; ⋀s b r c1 c2. s ∉ b ⟹ ?P1.1 (Some (AnnCond1 r b c1 c2)) s (Some c2) s; ⋀s b r c. s ∈ b ⟹ ?P1.1 (Some (AnnCond2 r b c)) s (Some c) s; ⋀s b r c. s ∉ b ⟹ ?P1.1 (Some (AnnCond2 r b c)) s None s; ⋀s b r i c. s ∉ b ⟹ ?P1.1 (Some (AnnWhile r b i c)) s None s; ⋀s b r i c. s ∈ b ⟹ ?P1.1 (Some (AnnWhile r b i c)) s (Some (AnnSeq c (AnnWhile i b i c))) s; ⋀s b c t r. ⟦s ∈ b; atom_com c; ((c, s), Parallel [], t) ∈ (transition ∩ {(x, y). ?P2.1 x y})⇧*⟧ ⟹ ?P1.1 (Some (AnnAwait r b c)) s None t; ⋀i Ts c q s r t. ⟦i < length Ts; Ts ! i = (Some c, q); (Some c, s) -1→ (r, t); ?P1.1 (Some c) s r t⟧ ⟹ ?P2.1 (Parallel Ts, s) (Parallel (Ts[i := (r, q)]), t); ⋀f s. ?P2.1 (Basic f, s) (Parallel [], f s); ⋀Ts c s. All_None Ts ⟹ ?P2.1 (Seq (Parallel Ts) c, s) (c, s); ⋀c0 s c2 t c1. ⟦(c0, s) -P1→ (c2, t); ?P2.1 (c0, s) (c2, t)⟧ ⟹ ?P2.1 (Seq c0 c1, s) (Seq c2 c1, t); ⋀s b c1 c2. s ∈ b ⟹ ?P2.1 (Cond b c1 c2, s) (c1, s); ⋀s b c1 c2. s ∉ b ⟹ ?P2.1 (Cond b c1 c2, s) (c2, s); ⋀s b i c. s ∉ b ⟹ ?P2.1 (While b i c, s) (Parallel [], s); ⋀s b i c. s ∈ b ⟹ ?P2.1 (While b i c, s) (Seq c (While b i c), s)⟧ ⟹ (?x1.1, ?x2.1) -1→ (?x3.1, ?x4.1) ⟶ ?P1.1 ?x1.1 ?x2.1 ?x3.1 ?x4.1›*)) (*goal: ‹(co, s) -1→ (co', t) ⟶ (∀c. co = Some c ⟶ s ∈ pre c ⟶ (∀q. ⊢ c q ⟶ (if co' = None then t ∈ q else t ∈ pre (the co') ∧ ⊢ the co' q)))›*) apply simp_all (*top goal: ‹⋀r f s. ∀c. Some (AnnBasic r f) = Some c ⟶ s ∈ pre c ⟶ (∀q. ⊢ c q ⟶ (if None = None then f s ∈ q else f s ∈ pre (the None) ∧ ⊢ the None q))› and 17 goals remain*) apply clarify (*top goal: ‹⋀(r::'a set) (f::'a ⇒ 'a) s::'a. s ∈ r ⟶ (∀q::'a set. ⊢ AnnBasic r f q ⟶ f s ∈ q)› and 9 goals remain*) apply (frule ann_hoare_case_analysis (*‹⊢ ?C ?q' ⟹ (∀r f. ?C = AnnBasic r f ⟶ (∃q. r ⊆ {s. f s ∈ q} ∧ q ⊆ ?q')) ∧ (∀c0 c1. ?C = AnnSeq c0 c1 ⟶ (∃q⊆?q'. ⊢ c0 pre c1 ∧ ⊢ c1 q)) ∧ (∀r b c1 c2. ?C = AnnCond1 r b c1 c2 ⟶ (∃q⊆?q'. r ∩ b ⊆ pre c1 ∧ ⊢ c1 q ∧ r ∩ - b ⊆ pre c2 ∧ ⊢ c2 q)) ∧ (∀r b c. ?C = AnnCond2 r b c ⟶ (∃q⊆?q'. r ∩ b ⊆ pre c ∧ ⊢ c q ∧ r ∩ - b ⊆ q)) ∧ (∀r i b c. ?C = AnnWhile r b i c ⟶ (∃q⊆?q'. r ⊆ i ∧ i ∩ b ⊆ pre c ∧ ⊢ c i ∧ i ∩ - b ⊆ q)) ∧ (∀r b c. ?C = AnnAwait r b c ⟶ (∃q⊆?q'. ∥- (r ∩ b) c q))›*)) (*top goal: ‹⋀r f s q. ⟦s ∈ r; ⊢ AnnBasic r f q⟧ ⟹ f s ∈ q› and 9 goals remain*) apply force (*top goal: ‹⋀r f s q. ⟦s ∈ r; ⊢ AnnBasic r f q; (∀ra fa. AnnBasic r f = AnnBasic ra fa ⟶ (∃qa. ra ⊆ {s. fa s ∈ qa} ∧ qa ⊆ q)) ∧ (∀c0 c1. AnnBasic r f = AnnSeq c0 c1 ⟶ (∃qa⊆q. ⊢ c0 pre c1 ∧ ⊢ c1 qa)) ∧ (∀ra b c1 c2. AnnBasic r f = AnnCond1 ra b c1 c2 ⟶ (∃qa⊆q. ra ∩ b ⊆ pre c1 ∧ ⊢ c1 qa ∧ ra ∩ - b ⊆ pre c2 ∧ ⊢ c2 qa)) ∧ (∀ra b c. AnnBasic r f = AnnCond2 ra b c ⟶ (∃qa⊆q. ra ∩ b ⊆ pre c ∧ ⊢ c qa ∧ ra ∩ - b ⊆ qa)) ∧ (∀ra i b c. AnnBasic r f = AnnWhile ra b i c ⟶ (∃qa⊆q. ra ⊆ i ∧ i ∩ b ⊆ pre c ∧ ⊢ c i ∧ i ∩ - b ⊆ qa)) ∧ (∀ra b c. AnnBasic r f = AnnAwait ra b c ⟶ (∃qa⊆q. ∥- (ra ∩ b) c qa))⟧ ⟹ f s ∈ q› and 9 goals remain*) apply clarify (*top goal: ‹⋀c0 s t c1. ⟦(Some c0, s) -1→ (None, t); s ∈ pre c0 ⟶ (∀q. ⊢ c0 q ⟶ t ∈ q)⟧ ⟹ s ∈ pre c0 ⟶ (∀q. ⊢ AnnSeq c0 c1 q ⟶ t ∈ pre c1 ∧ ⊢ c1 q)› and 8 goals remain*) apply (frule ann_hoare_case_analysis (*‹⊢ ?C ?q' ⟹ (∀r f. ?C = AnnBasic r f ⟶ (∃q. r ⊆ {s. f s ∈ q} ∧ q ⊆ ?q')) ∧ (∀c0 c1. ?C = AnnSeq c0 c1 ⟶ (∃q⊆?q'. ⊢ c0 pre c1 ∧ ⊢ c1 q)) ∧ (∀r b c1 c2. ?C = AnnCond1 r b c1 c2 ⟶ (∃q⊆?q'. r ∩ b ⊆ pre c1 ∧ ⊢ c1 q ∧ r ∩ - b ⊆ pre c2 ∧ ⊢ c2 q)) ∧ (∀r b c. ?C = AnnCond2 r b c ⟶ (∃q⊆?q'. r ∩ b ⊆ pre c ∧ ⊢ c q ∧ r ∩ - b ⊆ q)) ∧ (∀r i b c. ?C = AnnWhile r b i c ⟶ (∃q⊆?q'. r ⊆ i ∧ i ∩ b ⊆ pre c ∧ ⊢ c i ∧ i ∩ - b ⊆ q)) ∧ (∀r b c. ?C = AnnAwait r b c ⟶ (∃q⊆?q'. ∥- (r ∩ b) c q))›*), simp) (*top goal: ‹⋀c0 s t c1 q. ⟦(Some c0, s) -1→ (None, t); s ∈ pre c0; ⊢ AnnSeq c0 c1 q; ∀q. ⊢ c0 q ⟶ t ∈ q⟧ ⟹ t ∈ pre c1 ∧ ⊢ c1 q› and 8 goals remain*) apply (fast intro: AnnConseq (*‹⟦⊢ (?c::?'a ann_com) (?q::?'a set); ?q ⊆ (?q'::?'a set)⟧ ⟹ ⊢ ?c ?q'›*)) (*top goal: ‹⋀(c0::'a ann_com) (s::'a) (t::'a) (c1::'a ann_com) q::'a set. ⟦(Some c0, s) -1→ (None, t); s ∈ pre c0; ⊢ AnnSeq c0 c1 q; ∀q::'a set. ⊢ c0 q ⟶ t ∈ q; ∃qa⊆q. ⊢ c0 pre c1 ∧ ⊢ c1 qa⟧ ⟹ t ∈ pre c1 ∧ ⊢ c1 q› and 8 goals remain*) apply clarify (*top goal: ‹⋀c0 s c2 t c1. ⟦(Some c0, s) -1→ (Some c2, t); s ∈ pre c0 ⟶ (∀q. ⊢ c0 q ⟶ t ∈ pre c2 ∧ ⊢ c2 q)⟧ ⟹ s ∈ pre c0 ⟶ (∀q. ⊢ AnnSeq c0 c1 q ⟶ t ∈ pre c2 ∧ ⊢ AnnSeq c2 c1 q)› and 7 goals remain*) apply (frule ann_hoare_case_analysis (*‹⊢ ?C ?q' ⟹ (∀r f. ?C = AnnBasic r f ⟶ (∃q. r ⊆ {s. f s ∈ q} ∧ q ⊆ ?q')) ∧ (∀c0 c1. ?C = AnnSeq c0 c1 ⟶ (∃q⊆?q'. ⊢ c0 pre c1 ∧ ⊢ c1 q)) ∧ (∀r b c1 c2. ?C = AnnCond1 r b c1 c2 ⟶ (∃q⊆?q'. r ∩ b ⊆ pre c1 ∧ ⊢ c1 q ∧ r ∩ - b ⊆ pre c2 ∧ ⊢ c2 q)) ∧ (∀r b c. ?C = AnnCond2 r b c ⟶ (∃q⊆?q'. r ∩ b ⊆ pre c ∧ ⊢ c q ∧ r ∩ - b ⊆ q)) ∧ (∀r i b c. ?C = AnnWhile r b i c ⟶ (∃q⊆?q'. r ⊆ i ∧ i ∩ b ⊆ pre c ∧ ⊢ c i ∧ i ∩ - b ⊆ q)) ∧ (∀r b c. ?C = AnnAwait r b c ⟶ (∃q⊆?q'. ∥- (r ∩ b) c q))›*), simp) (*top goal: ‹⋀c0 s c2 t c1 q. ⟦(Some c0, s) -1→ (Some c2, t); s ∈ pre c0; ⊢ AnnSeq c0 c1 q; ∀q. ⊢ c0 q ⟶ t ∈ pre c2 ∧ ⊢ c2 q⟧ ⟹ t ∈ pre c2 ∧ ⊢ AnnSeq c2 c1 q› and 7 goals remain*) apply clarify (*top goal: ‹⋀c0 s c2 t c1 q. ⟦(Some c0, s) -1→ (Some c2, t); s ∈ pre c0; ⊢ AnnSeq c0 c1 q; ∀q. ⊢ c0 q ⟶ t ∈ pre c2 ∧ ⊢ c2 q; ∃qa⊆q. ⊢ c0 pre c1 ∧ ⊢ c1 qa⟧ ⟹ t ∈ pre c2 ∧ ⊢ AnnSeq c2 c1 q› and 7 goals remain*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*top goal: ‹⋀c0 s c2 t c1 q qa. ⟦(Some c0, s) -1→ (Some c2, t); s ∈ pre c0; ⊢ AnnSeq c0 c1 q; ∀q. ⊢ c0 q ⟶ t ∈ pre c2 ∧ ⊢ c2 q; qa ⊆ q; ⊢ c0 pre c1; ⊢ c1 qa⟧ ⟹ t ∈ pre c2 ∧ ⊢ AnnSeq c2 c1 q› and 7 goals remain*) apply force (*top goal: ‹⋀c0 s c2 t c1 q qa. ⟦(Some c0, s) -1→ (Some c2, t); s ∈ pre c0; ⊢ AnnSeq c0 c1 q; ∀q. ⊢ c0 q ⟶ t ∈ pre c2 ∧ ⊢ c2 q; qa ⊆ q; ⊢ c0 pre c1; ⊢ c1 qa⟧ ⟹ t ∈ pre c2› and 8 goals remain*) apply (rule AnnSeq (*‹⟦⊢ ?c0.0 pre ?c1.0; ⊢ ?c1.0 ?q⟧ ⟹ ⊢ AnnSeq ?c0.0 ?c1.0 ?q›*), simp) (*top goal: ‹⋀c0 s c2 t c1 q qa. ⟦(Some c0, s) -1→ (Some c2, t); s ∈ pre c0; ⊢ AnnSeq c0 c1 q; ∀q. ⊢ c0 q ⟶ t ∈ pre c2 ∧ ⊢ c2 q; qa ⊆ q; ⊢ c0 pre c1; ⊢ c1 qa⟧ ⟹ ⊢ AnnSeq c2 c1 q› and 7 goals remain*) apply (fast intro: AnnConseq (*‹⟦⊢ ?c ?q; ?q ⊆ ?q'⟧ ⟹ ⊢ ?c ?q'›*)) (*top goal: ‹⋀c0 s c2 t c1 q qa. ⟦(Some c0, s) -1→ (Some c2, t); s ∈ pre c0; ⊢ AnnSeq c0 c1 q; ∀q. ⊢ c0 q ⟶ t ∈ pre c2 ∧ ⊢ c2 q; qa ⊆ q; ⊢ c0 pre c1; ⊢ c1 qa⟧ ⟹ ⊢ c1 q› and 7 goals remain*) apply clarify (*top goal: ‹⋀s b r c1 c2. s ∈ b ⟹ s ∈ r ⟶ (∀q. ⊢ AnnCond1 r b c1 c2 q ⟶ s ∈ pre c1 ∧ ⊢ c1 q)› and 6 goals remain*) apply (frule ann_hoare_case_analysis (*‹⊢ ?C ?q' ⟹ (∀r f. ?C = AnnBasic r f ⟶ (∃q. r ⊆ {s. f s ∈ q} ∧ q ⊆ ?q')) ∧ (∀c0 c1. ?C = AnnSeq c0 c1 ⟶ (∃q⊆?q'. ⊢ c0 pre c1 ∧ ⊢ c1 q)) ∧ (∀r b c1 c2. ?C = AnnCond1 r b c1 c2 ⟶ (∃q⊆?q'. r ∩ b ⊆ pre c1 ∧ ⊢ c1 q ∧ r ∩ - b ⊆ pre c2 ∧ ⊢ c2 q)) ∧ (∀r b c. ?C = AnnCond2 r b c ⟶ (∃q⊆?q'. r ∩ b ⊆ pre c ∧ ⊢ c q ∧ r ∩ - b ⊆ q)) ∧ (∀r i b c. ?C = AnnWhile r b i c ⟶ (∃q⊆?q'. r ⊆ i ∧ i ∩ b ⊆ pre c ∧ ⊢ c i ∧ i ∩ - b ⊆ q)) ∧ (∀r b c. ?C = AnnAwait r b c ⟶ (∃q⊆?q'. ∥- (r ∩ b) c q))›*), simp) (*top goal: ‹⋀s b r c1 c2 q. ⟦s ∈ b; s ∈ r; ⊢ AnnCond1 r b c1 c2 q⟧ ⟹ s ∈ pre c1 ∧ ⊢ c1 q› and 6 goals remain*) apply (fast intro: AnnConseq (*‹⟦⊢ ?c ?q; ?q ⊆ ?q'⟧ ⟹ ⊢ ?c ?q'›*)) (*top goal: ‹⋀(s::'a) (b::'a set) (r::'a set) (c1::'a ann_com) (c2::'a ann_com) q::'a set. ⟦s ∈ b; s ∈ r; ⊢ AnnCond1 r b c1 c2 q; ∃qa⊆q. r ∩ b ⊆ pre c1 ∧ ⊢ c1 qa ∧ r ∩ - b ⊆ pre c2 ∧ ⊢ c2 qa⟧ ⟹ s ∈ pre c1 ∧ ⊢ c1 q› and 6 goals remain*) apply clarify (*top goal: ‹⋀s b r c1 c2. s ∉ b ⟹ s ∈ r ⟶ (∀q. ⊢ AnnCond1 r b c1 c2 q ⟶ s ∈ pre c2 ∧ ⊢ c2 q)› and 5 goals remain*) apply (frule ann_hoare_case_analysis (*‹⊢ ?C ?q' ⟹ (∀r f. ?C = AnnBasic r f ⟶ (∃q. r ⊆ {s. f s ∈ q} ∧ q ⊆ ?q')) ∧ (∀c0 c1. ?C = AnnSeq c0 c1 ⟶ (∃q⊆?q'. ⊢ c0 pre c1 ∧ ⊢ c1 q)) ∧ (∀r b c1 c2. ?C = AnnCond1 r b c1 c2 ⟶ (∃q⊆?q'. r ∩ b ⊆ pre c1 ∧ ⊢ c1 q ∧ r ∩ - b ⊆ pre c2 ∧ ⊢ c2 q)) ∧ (∀r b c. ?C = AnnCond2 r b c ⟶ (∃q⊆?q'. r ∩ b ⊆ pre c ∧ ⊢ c q ∧ r ∩ - b ⊆ q)) ∧ (∀r i b c. ?C = AnnWhile r b i c ⟶ (∃q⊆?q'. r ⊆ i ∧ i ∩ b ⊆ pre c ∧ ⊢ c i ∧ i ∩ - b ⊆ q)) ∧ (∀r b c. ?C = AnnAwait r b c ⟶ (∃q⊆?q'. ∥- (r ∩ b) c q))›*), simp) (*top goal: ‹⋀(s::'a) (b::'a set) (r::'a set) (c1::'a ann_com) (c2::'a ann_com) q::'a set. ⟦s ∉ b; s ∈ r; ⊢ AnnCond1 r b c1 c2 q⟧ ⟹ s ∈ pre c2 ∧ ⊢ c2 q› and 5 goals remain*) apply (fast intro: AnnConseq (*‹⟦⊢ (?c::?'a ann_com) (?q::?'a set); ?q ⊆ (?q'::?'a set)⟧ ⟹ ⊢ ?c ?q'›*)) (*top goal: ‹⋀s b r c1 c2 q. ⟦s ∉ b; s ∈ r; ⊢ AnnCond1 r b c1 c2 q; ∃qa⊆q. r ∩ b ⊆ pre c1 ∧ ⊢ c1 qa ∧ r ∩ - b ⊆ pre c2 ∧ ⊢ c2 qa⟧ ⟹ s ∈ pre c2 ∧ ⊢ c2 q› and 5 goals remain*) apply clarify (*top goal: ‹⋀(s::'a) (b::'a set) (r::'a set) c::'a ann_com. s ∈ b ⟹ s ∈ r ⟶ (∀q::'a set. ⊢ AnnCond2 r b c q ⟶ s ∈ pre c ∧ ⊢ c q)› and 4 goals remain*) apply (frule ann_hoare_case_analysis (*‹⊢ ?C ?q' ⟹ (∀r f. ?C = AnnBasic r f ⟶ (∃q. r ⊆ {s. f s ∈ q} ∧ q ⊆ ?q')) ∧ (∀c0 c1. ?C = AnnSeq c0 c1 ⟶ (∃q⊆?q'. ⊢ c0 pre c1 ∧ ⊢ c1 q)) ∧ (∀r b c1 c2. ?C = AnnCond1 r b c1 c2 ⟶ (∃q⊆?q'. r ∩ b ⊆ pre c1 ∧ ⊢ c1 q ∧ r ∩ - b ⊆ pre c2 ∧ ⊢ c2 q)) ∧ (∀r b c. ?C = AnnCond2 r b c ⟶ (∃q⊆?q'. r ∩ b ⊆ pre c ∧ ⊢ c q ∧ r ∩ - b ⊆ q)) ∧ (∀r i b c. ?C = AnnWhile r b i c ⟶ (∃q⊆?q'. r ⊆ i ∧ i ∩ b ⊆ pre c ∧ ⊢ c i ∧ i ∩ - b ⊆ q)) ∧ (∀r b c. ?C = AnnAwait r b c ⟶ (∃q⊆?q'. ∥- (r ∩ b) c q))›*), simp) (*top goal: ‹⋀s b r c q. ⟦s ∈ b; s ∈ r; ⊢ AnnCond2 r b c q⟧ ⟹ s ∈ pre c ∧ ⊢ c q› and 4 goals remain*) apply (fast intro: AnnConseq (*‹⟦⊢ (?c::?'a ann_com) (?q::?'a set); ?q ⊆ (?q'::?'a set)⟧ ⟹ ⊢ ?c ?q'›*)) (*top goal: ‹⋀(s::'a) (b::'a set) (r::'a set) (c::'a ann_com) q::'a set. ⟦s ∈ b; s ∈ r; ⊢ AnnCond2 r b c q; ∃qa⊆q. r ∩ b ⊆ pre c ∧ ⊢ c qa ∧ r ∩ - b ⊆ qa⟧ ⟹ s ∈ pre c ∧ ⊢ c q› and 4 goals remain*) apply clarify (*top goal: ‹⋀s b r c. s ∉ b ⟹ s ∈ r ⟶ (∀q. ⊢ AnnCond2 r b c q ⟶ s ∈ q)› and 3 goals remain*) apply (frule ann_hoare_case_analysis (*‹⊢ ?C ?q' ⟹ (∀r f. ?C = AnnBasic r f ⟶ (∃q. r ⊆ {s. f s ∈ q} ∧ q ⊆ ?q')) ∧ (∀c0 c1. ?C = AnnSeq c0 c1 ⟶ (∃q⊆?q'. ⊢ c0 pre c1 ∧ ⊢ c1 q)) ∧ (∀r b c1 c2. ?C = AnnCond1 r b c1 c2 ⟶ (∃q⊆?q'. r ∩ b ⊆ pre c1 ∧ ⊢ c1 q ∧ r ∩ - b ⊆ pre c2 ∧ ⊢ c2 q)) ∧ (∀r b c. ?C = AnnCond2 r b c ⟶ (∃q⊆?q'. r ∩ b ⊆ pre c ∧ ⊢ c q ∧ r ∩ - b ⊆ q)) ∧ (∀r i b c. ?C = AnnWhile r b i c ⟶ (∃q⊆?q'. r ⊆ i ∧ i ∩ b ⊆ pre c ∧ ⊢ c i ∧ i ∩ - b ⊆ q)) ∧ (∀r b c. ?C = AnnAwait r b c ⟶ (∃q⊆?q'. ∥- (r ∩ b) c q))›*), simp) (*top goal: ‹⋀(s::'a) (b::'a set) (r::'a set) (c::'a ann_com) q::'a set. ⟦s ∉ b; s ∈ r; ⊢ AnnCond2 r b c q⟧ ⟹ s ∈ q› and 3 goals remain*) apply (fast intro: AnnConseq (*‹⟦⊢ (?c::?'a::type ann_com) (?q::?'a::type set); ?q ⊆ (?q'::?'a::type set)⟧ ⟹ ⊢ ?c ?q'›*)) (*top goal: ‹⋀s b r c q. ⟦s ∉ b; s ∈ r; ⊢ AnnCond2 r b c q; ∃qa⊆q. r ∩ b ⊆ pre c ∧ ⊢ c qa ∧ r ∩ - b ⊆ qa⟧ ⟹ s ∈ q› and 3 goals remain*) apply clarify (*top goal: ‹⋀s b r i c. s ∉ b ⟹ s ∈ r ⟶ (∀q. ⊢ AnnWhile r b i c q ⟶ s ∈ q)› and 2 goals remain*) apply (frule ann_hoare_case_analysis (*‹⊢ ?C ?q' ⟹ (∀r f. ?C = AnnBasic r f ⟶ (∃q. r ⊆ {s. f s ∈ q} ∧ q ⊆ ?q')) ∧ (∀c0 c1. ?C = AnnSeq c0 c1 ⟶ (∃q⊆?q'. ⊢ c0 pre c1 ∧ ⊢ c1 q)) ∧ (∀r b c1 c2. ?C = AnnCond1 r b c1 c2 ⟶ (∃q⊆?q'. r ∩ b ⊆ pre c1 ∧ ⊢ c1 q ∧ r ∩ - b ⊆ pre c2 ∧ ⊢ c2 q)) ∧ (∀r b c. ?C = AnnCond2 r b c ⟶ (∃q⊆?q'. r ∩ b ⊆ pre c ∧ ⊢ c q ∧ r ∩ - b ⊆ q)) ∧ (∀r i b c. ?C = AnnWhile r b i c ⟶ (∃q⊆?q'. r ⊆ i ∧ i ∩ b ⊆ pre c ∧ ⊢ c i ∧ i ∩ - b ⊆ q)) ∧ (∀r b c. ?C = AnnAwait r b c ⟶ (∃q⊆?q'. ∥- (r ∩ b) c q))›*), simp) (*top goal: ‹⋀s b r i c q. ⟦s ∉ b; s ∈ r; ⊢ AnnWhile r b i c q⟧ ⟹ s ∈ q› and 2 goals remain*) apply force (*top goal: ‹⋀s b r i c q. ⟦s ∉ b; s ∈ r; ⊢ AnnWhile r b i c q; ∃qa⊆q. r ⊆ i ∧ i ∩ b ⊆ pre c ∧ ⊢ c i ∧ i ∩ - b ⊆ qa⟧ ⟹ s ∈ q› and 2 goals remain*) apply clarify (*top goal: ‹⋀s b r i c. s ∈ b ⟹ s ∈ r ⟶ (∀q. ⊢ AnnWhile r b i c q ⟶ s ∈ pre c ∧ ⊢ AnnSeq c (AnnWhile i b i c) q)› and 1 goal remains*) apply (frule ann_hoare_case_analysis (*‹⊢ ?C ?q' ⟹ (∀r f. ?C = AnnBasic r f ⟶ (∃q. r ⊆ {s. f s ∈ q} ∧ q ⊆ ?q')) ∧ (∀c0 c1. ?C = AnnSeq c0 c1 ⟶ (∃q⊆?q'. ⊢ c0 pre c1 ∧ ⊢ c1 q)) ∧ (∀r b c1 c2. ?C = AnnCond1 r b c1 c2 ⟶ (∃q⊆?q'. r ∩ b ⊆ pre c1 ∧ ⊢ c1 q ∧ r ∩ - b ⊆ pre c2 ∧ ⊢ c2 q)) ∧ (∀r b c. ?C = AnnCond2 r b c ⟶ (∃q⊆?q'. r ∩ b ⊆ pre c ∧ ⊢ c q ∧ r ∩ - b ⊆ q)) ∧ (∀r i b c. ?C = AnnWhile r b i c ⟶ (∃q⊆?q'. r ⊆ i ∧ i ∩ b ⊆ pre c ∧ ⊢ c i ∧ i ∩ - b ⊆ q)) ∧ (∀r b c. ?C = AnnAwait r b c ⟶ (∃q⊆?q'. ∥- (r ∩ b) c q))›*), simp) (*top goal: ‹⋀s b r i c q. ⟦s ∈ b; s ∈ r; ⊢ AnnWhile r b i c q⟧ ⟹ s ∈ pre c ∧ ⊢ AnnSeq c (AnnWhile i b i c) q› and 1 goal remains*) apply auto (*top goal: ‹⋀(s::'a::type) (b::'a::type set) (r::'a::type set) (i::'a::type set) (c::'a::type ann_com) q::'a::type set. ⟦s ∈ b; s ∈ r; ⊢ AnnWhile r b i c q; ∃qa⊆q. r ⊆ i ∧ i ∩ b ⊆ pre c ∧ ⊢ c i ∧ i ∩ - b ⊆ qa⟧ ⟹ s ∈ pre c ∧ ⊢ AnnSeq c (AnnWhile i b i c) q› and 1 goal remains*) apply (rule AnnSeq (*‹⟦⊢ (?c0.0::?'a::type ann_com) pre (?c1.0::?'a::type ann_com); ⊢ ?c1.0 (?q::?'a::type set)⟧ ⟹ ⊢ AnnSeq ?c0.0 ?c1.0 ?q›*)) (*top goal: ‹⋀s b r i c q qa. ⟦s ∈ b; s ∈ r; ⊢ AnnWhile r b i c q; qa ⊆ q; r ⊆ i; i ∩ b ⊆ pre c; ⊢ c i; i ∩ - b ⊆ qa⟧ ⟹ ⊢ AnnSeq c (AnnWhile i b i c) q› and 1 goal remains*) apply simp (*top goal: ‹⋀s b r i c q qa. ⟦s ∈ b; s ∈ r; ⊢ AnnWhile r b i c q; qa ⊆ q; r ⊆ i; i ∩ b ⊆ pre c; ⊢ c i; i ∩ - b ⊆ qa⟧ ⟹ ⊢ c pre (AnnWhile i b i c)› and 2 goals remain*) apply (rule AnnWhile (*‹⟦?r ⊆ ?i; ?i ∩ ?b ⊆ pre ?c; ⊢ ?c ?i; ?i ∩ - ?b ⊆ ?q⟧ ⟹ ⊢ AnnWhile ?r ?b ?i ?c ?q›*)) (*top goal: ‹⋀s b r i c q qa. ⟦s ∈ b; s ∈ r; ⊢ AnnWhile r b i c q; qa ⊆ q; r ⊆ i; i ∩ b ⊆ pre c; ⊢ c i; i ∩ - b ⊆ qa⟧ ⟹ ⊢ AnnWhile i b i c q› and 1 goal remains*) apply simp_all (*top goal: ‹⋀s b r i c q qa. ⟦s ∈ b; s ∈ r; ⊢ AnnWhile r b i c q; qa ⊆ q; r ⊆ i; i ∩ b ⊆ pre c; ⊢ c i; i ∩ - b ⊆ qa⟧ ⟹ i ⊆ i› and 4 goals remain*) apply (frule ann_hoare_case_analysis (*‹⊢ ?C ?q' ⟹ (∀r f. ?C = AnnBasic r f ⟶ (∃q. r ⊆ {s. f s ∈ q} ∧ q ⊆ ?q')) ∧ (∀c0 c1. ?C = AnnSeq c0 c1 ⟶ (∃q⊆?q'. ⊢ c0 pre c1 ∧ ⊢ c1 q)) ∧ (∀r b c1 c2. ?C = AnnCond1 r b c1 c2 ⟶ (∃q⊆?q'. r ∩ b ⊆ pre c1 ∧ ⊢ c1 q ∧ r ∩ - b ⊆ pre c2 ∧ ⊢ c2 q)) ∧ (∀r b c. ?C = AnnCond2 r b c ⟶ (∃q⊆?q'. r ∩ b ⊆ pre c ∧ ⊢ c q ∧ r ∩ - b ⊆ q)) ∧ (∀r i b c. ?C = AnnWhile r b i c ⟶ (∃q⊆?q'. r ⊆ i ∧ i ∩ b ⊆ pre c ∧ ⊢ c i ∧ i ∩ - b ⊆ q)) ∧ (∀r b c. ?C = AnnAwait r b c ⟶ (∃q⊆?q'. ∥- (r ∩ b) c q))›*), simp) (*goal: ‹⋀s b c t r q. ⟦s ∈ b; atom_com c; (c, s) -P*→ (Parallel [], t); s ∈ r; ⊢ AnnAwait r b c q⟧ ⟹ t ∈ q›*) apply clarify (*goal: ‹⋀s b c t r q. ⟦s ∈ b; atom_com c; (c, s) -P*→ (Parallel [], t); s ∈ r; ⊢ AnnAwait r b c q; ∃qa⊆q. ∥- (r ∩ b) c qa⟧ ⟹ t ∈ q›*) apply (drule atom_hoare_sound (*‹⟦∥- ?p ?c ?q; atom_com ?c⟧ ⟹ ∥= ?p ?c ?q›*)) (*goal: ‹⋀s b c t r q qa. ⟦s ∈ b; atom_com c; (c, s) -P*→ (Parallel [], t); s ∈ r; ⊢ AnnAwait r b c q; qa ⊆ q; ∥- (r ∩ b) c qa⟧ ⟹ t ∈ q›*) apply simp (*top goal: ‹⋀s b c t r q qa. ⟦s ∈ b; atom_com c; (c, s) -P*→ (Parallel [], t); s ∈ r; ⊢ AnnAwait r b c q; qa ⊆ q⟧ ⟹ atom_com c› and 1 goal remains*) apply (simp add: com_validity_def (*‹∥= ?p ?c ?q ≡ SEM ?c ?p ⊆ ?q›*) SEM_def (*‹SEM ?c ?S ≡ ⋃ (sem ?c ` ?S)›*) sem_def (*‹sem ?c ≡ λs. {t. ∃Ts. (?c, s) -P*→ (Parallel Ts, t) ∧ All_None Ts}›*)) (*goal: ‹⋀(s::'a) (b::'a set) (c::'a com) (t::'a) (r::'a set) (q::'a set) qa::'a set. ⟦s ∈ b; atom_com c; (c, s) -P*→ (Parallel [], t); s ∈ r; ⊢ AnnAwait r b c q; qa ⊆ q; ∥= (r ∩ b) c qa⟧ ⟹ t ∈ q›*) apply (simp add: Help (*‹transition ∩ {(x, y). True} = transition›*) All_None_def (*‹All_None ?Ts ≡ ∀(c, q)∈set ?Ts. c = None›*)) (*goal: ‹⋀(s::'a) (b::'a set) (c::'a com) (t::'a) (r::'a set) (q::'a set) qa::'a set. ⟦s ∈ b; atom_com c; (c, s) -P*→ (Parallel [], t); s ∈ r; ⊢ AnnAwait r b c q; qa ⊆ q; (⋃x::'a∈r ∩ b. {t::'a. ∃Ts::('a ann_com option × 'a set) list. (c, x) -P*→ (Parallel Ts, t) ∧ All_None Ts}) ⊆ qa⟧ ⟹ t ∈ q›*) by force lemma Strong_Soundness_aux: "⟦ (Some c, s) -*→ (co, t); s ∈ pre c; ⊢ c q ⟧ ⟹ if co = None then t ∈ q else t ∈ pre (the co) ∧ ⊢ (the co) q" apply (erule rtrancl_induct2 (*‹⟦((?ax::?'a, ?ay::?'b), ?bx::?'a, ?by::?'b) ∈ (?r::((?'a × ?'b) × ?'a × ?'b) set)⇧*; (?P::?'a ⇒ ?'b ⇒ bool) ?ax ?ay; ⋀(a::?'a) (b::?'b) (aa::?'a) ba::?'b. ⟦((?ax, ?ay), a, b) ∈ ?r⇧*; ((a, b), aa, ba) ∈ ?r; ?P a b⟧ ⟹ ?P aa ba⟧ ⟹ ?P ?bx ?by›*)) (*goals: 1. ‹⟦s ∈ pre c; ⊢ c q⟧ ⟹ if Some c = None then s ∈ q else s ∈ pre (the (Some c)) ∧ ⊢ the (Some c) q› 2. ‹⋀a b aa ba. ⟦s ∈ pre c; ⊢ c q; (Some c, s) -*→ (a, b); (a, b) -1→ (aa, ba); if a = None then b ∈ q else b ∈ pre (the a) ∧ ⊢ the a q⟧ ⟹ if aa = None then ba ∈ q else ba ∈ pre (the aa) ∧ ⊢ the aa q› discuss goal 1*) apply simp (*discuss goal 2*) apply (case_tac "a") (*goals: 1. ‹⋀(a::'a ann_com option) (b::'a) (aa::'a ann_com option) ba::'a. ⟦(s::'a) ∈ pre (c::'a ann_com); ⊢ c (q::'a set); (Some c, s) -*→ (a, b); (a, b) -1→ (aa, ba); if a = None then b ∈ q else b ∈ pre (the a) ∧ ⊢ the a q; a = None⟧ ⟹ if aa = None then ba ∈ q else ba ∈ pre (the aa) ∧ ⊢ the aa q› 2. ‹⋀(a::'a ann_com option) (b::'a) (aa::'a ann_com option) (ba::'a) ab::'a ann_com. ⟦(s::'a) ∈ pre (c::'a ann_com); ⊢ c (q::'a set); (Some c, s) -*→ (a, b); (a, b) -1→ (aa, ba); if a = None then b ∈ q else b ∈ pre (the a) ∧ ⊢ the a q; a = Some ab⟧ ⟹ if aa = None then ba ∈ q else ba ∈ pre (the aa) ∧ ⊢ the aa q› discuss goal 1*) apply (fast elim: ann_transition_cases (*‹(None, ?s::?'a) -1→ (?c'::?'a ann_com option, ?s'::?'a) ⟹ ?P::bool› ‹⟦(Some (AnnBasic (?r::?'a set) (?f::?'a ⇒ ?'a)), ?s::?'a) -1→ (?c'::?'a ann_com option, ?s'::?'a); ⟦?c' = None; ?s' = ?f ?s⟧ ⟹ ?P::bool⟧ ⟹ ?P› ‹⟦(Some (AnnSeq (?c1.0::?'a ann_com) (?c2.0::?'a ann_com)), ?s::?'a) -1→ (?c'::?'a ann_com option, ?s'::?'a); ⟦?c' = Some ?c2.0; (Some ?c1.0, ?s) -1→ (None, ?s')⟧ ⟹ ?P::bool; ⋀c2::?'a ann_com. ⟦?c' = Some (AnnSeq c2 ?c2.0); (Some ?c1.0, ?s) -1→ (Some c2, ?s')⟧ ⟹ ?P⟧ ⟹ ?P› ‹⟦(Some (AnnCond1 (?r::?'a set) (?b::?'a set) (?c1.0::?'a ann_com) (?c2.0::?'a ann_com)), ?s::?'a) -1→ (?c'::?'a ann_com option, ?s'::?'a); ⟦?c' = Some ?c1.0; ?s' = ?s; ?s ∈ ?b⟧ ⟹ ?P::bool; ⟦?c' = Some ?c2.0; ?s' = ?s; ?s ∉ ?b⟧ ⟹ ?P⟧ ⟹ ?P› ‹⟦(Some (AnnCond2 (?r::?'a set) (?b::?'a set) (?c::?'a ann_com)), ?s::?'a) -1→ (?c'::?'a ann_com option, ?s'::?'a); ⟦?c' = Some ?c; ?s' = ?s; ?s ∈ ?b⟧ ⟹ ?P::bool; ⟦?c' = None; ?s' = ?s; ?s ∉ ?b⟧ ⟹ ?P⟧ ⟹ ?P› ‹⟦(Some (AnnWhile (?r::?'a set) (?b::?'a set) (?I::?'a set) (?c::?'a ann_com)), ?s::?'a) -1→ (?c'::?'a ann_com option, ?s'::?'a); ⟦?c' = None; ?s' = ?s; ?s ∉ ?b⟧ ⟹ ?P::bool; ⟦?c' = Some (AnnSeq ?c (AnnWhile ?I ?b ?I ?c)); ?s' = ?s; ?s ∈ ?b⟧ ⟹ ?P⟧ ⟹ ?P› ‹⟦(Some (AnnAwait (?r::?'a set) (?b::?'a set) (?c::?'a com)), ?s::?'a) -1→ (?c'::?'a ann_com option, ?s'::?'a); ⟦?c' = None; ?s ∈ ?b; atom_com ?c; (?c, ?s) -P*→ (Parallel [], ?s')⟧ ⟹ ?P::bool⟧ ⟹ ?P›*)) (*discuss goal 2*) apply (erule Strong_Soundness_aux_aux (*‹⟦(?co, ?s) -1→ (?co', ?t); ?co = Some ?c; ?s ∈ pre ?c; ⊢ ?c ?q⟧ ⟹ if ?co' = None then ?t ∈ ?q else ?t ∈ pre (the ?co') ∧ ⊢ the ?co' ?q›*)) (*goals: 1. ‹⋀(a::'a::type ann_com option) (b::'a::type) (aa::'a::type ann_com option) (ba::'a::type) ab::'a::type ann_com. ⟦(s::'a::type) ∈ pre (c::'a::type ann_com); ⊢ c (q::'a::type set); (Some c, s) -*→ (a, b); if a = None then b ∈ q else b ∈ pre (the a) ∧ ⊢ the a q; a = Some ab⟧ ⟹ a = Some ((?c8::'a::type ann_com option ⇒ 'a::type ⇒ 'a::type ann_com option ⇒ 'a::type ⇒ 'a::type ann_com ⇒ 'a::type ann_com) a b aa ba ab)› 2. ‹⋀(a::'a::type ann_com option) (b::'a::type) (aa::'a::type ann_com option) (ba::'a::type) ab::'a::type ann_com. ⟦(s::'a::type) ∈ pre (c::'a::type ann_com); ⊢ c (q::'a::type set); (Some c, s) -*→ (a, b); if a = None then b ∈ q else b ∈ pre (the a) ∧ ⊢ the a q; a = Some ab⟧ ⟹ b ∈ pre ((?c8::'a::type ann_com option ⇒ 'a::type ⇒ 'a::type ann_com option ⇒ 'a::type ⇒ 'a::type ann_com ⇒ 'a::type ann_com) a b aa ba ab)› 3. ‹⋀(a::'a::type ann_com option) (b::'a::type) (aa::'a::type ann_com option) (ba::'a::type) ab::'a::type ann_com. ⟦(s::'a::type) ∈ pre (c::'a::type ann_com); ⊢ c (q::'a::type set); (Some c, s) -*→ (a, b); if a = None then b ∈ q else b ∈ pre (the a) ∧ ⊢ the a q; a = Some ab⟧ ⟹ ⊢ (?c8::'a::type ann_com option ⇒ 'a::type ⇒ 'a::type ann_com option ⇒ 'a::type ⇒ 'a::type ann_com ⇒ 'a::type ann_com) a b aa ba ab q› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma Strong_Soundness: "⟦ (Some c, s)-*→(co, t); s ∈ pre c; ⊢ c q ⟧ ⟹ if co = None then t∈q else t ∈ pre (the co)" by (force dest:Strong_Soundness_aux (*‹⟦(Some ?c, ?s) -*→ (?co, ?t); ?s ∈ pre ?c; ⊢ ?c ?q⟧ ⟹ if ?co = None then ?t ∈ ?q else ?t ∈ pre (the ?co) ∧ ⊢ the ?co ?q›*)) lemma ann_hoare_sound: "⊢ c q ⟹ ⊨ c q" apply (unfold ann_com_validity_def (*‹⊨ ?c ?q ≡ ann_SEM ?c (pre ?c) ⊆ ?q›*) ann_SEM_def (*‹ann_SEM ?c ?S ≡ ⋃ (ann_sem ?c ` ?S)›*) ann_sem_def (*‹ann_sem ?c ≡ λs. {t. (Some ?c, s) -*→ (None, t)}›*)) (*goal: ‹⊢ c q ⟹ ⊨ c q›*) apply clarify (*goal: ‹⊢ c q ⟹ (⋃s∈pre c. {t. (Some c, s) -*→ (None, t)}) ⊆ q›*) apply (drule Strong_Soundness (*‹⟦(Some (?c::?'a ann_com), ?s::?'a) -*→ (?co::?'a ann_com option, ?t::?'a); ?s ∈ pre ?c; ⊢ ?c (?q::?'a set)⟧ ⟹ if ?co = None then ?t ∈ ?q else ?t ∈ pre (the ?co)›*)) (*goals: 1. ‹⋀x s. ⟦⊢ c q; s ∈ pre c⟧ ⟹ s ∈ pre c› 2. ‹⋀x s. ⟦⊢ c q; s ∈ pre c⟧ ⟹ ⊢ c ?q3 x s› 3. ‹⋀x s. ⟦⊢ c q; s ∈ pre c; if None = None then x ∈ ?q3 x s else x ∈ pre (the None)⟧ ⟹ x ∈ q› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) . subsection ‹Soundness of the System for Parallel Programs› lemma Parallel_length_post_P1: "(Parallel Ts,s) -P1→ (R', t) ⟹ (∃Rs. R' = (Parallel Rs) ∧ (length Rs) = (length Ts) ∧ (∀i. i<length Ts ⟶ post(Rs ! i) = post(Ts ! i)))" apply (erule transition_cases (*‹⟦(Parallel (?T::(?'a::type ann_com option × ?'a::type set) list), ?s::?'a::type) -P1→ (?t::?'a::type com × ?'a::type); ⋀(i::nat) (c::?'a::type ann_com) (q::?'a::type set) (r::?'a::type ann_com option) t::?'a::type. ⟦?t = (Parallel (?T[i := (r, q)]), t); i < length ?T; ?T ! i = (Some c, q); (Some c, ?s) -1→ (r, t)⟧ ⟹ ?P::bool⟧ ⟹ ?P› ‹⟦(Basic (?f::?'a::type ⇒ ?'a::type), ?s::?'a::type) -P1→ (?t::?'a::type com × ?'a::type); ?t = (Parallel [], ?f ?s) ⟹ ?P::bool⟧ ⟹ ?P› ‹⟦(Seq (?c1.0::?'a::type com) (?c2.0::?'a::type com), ?s::?'a::type) -P1→ (?t::?'a::type com × ?'a::type); ⋀Ts::(?'a::type ann_com option × ?'a::type set) list. ⟦?c1.0 = Parallel Ts; ?t = (?c2.0, ?s); All_None Ts⟧ ⟹ ?P::bool; ⋀(c2::?'a::type com) t::?'a::type. ⟦?t = (Seq c2 ?c2.0, t); (?c1.0, ?s) -P1→ (c2, t)⟧ ⟹ ?P⟧ ⟹ ?P› ‹⟦(Cond (?b::?'a::type set) (?c1.0::?'a::type com) (?c2.0::?'a::type com), ?s::?'a::type) -P1→ (?t::?'a::type com × ?'a::type); ⟦?t = (?c1.0, ?s); ?s ∈ ?b⟧ ⟹ ?P::bool; ⟦?t = (?c2.0, ?s); ?s ∉ ?b⟧ ⟹ ?P⟧ ⟹ ?P› ‹⟦(While (?b::?'a::type set) (?i::?'a::type set) (?c::?'a::type com), ?s::?'a::type) -P1→ (?t::?'a::type com × ?'a::type); ⟦?t = (Parallel [], ?s); ?s ∉ ?b⟧ ⟹ ?P::bool; ⟦?t = (Seq ?c (While ?b ?i ?c), ?s); ?s ∈ ?b⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goal: ‹(Parallel Ts, s) -P1→ (R', t) ⟹ ∃Rs. R' = Parallel Rs ∧ length Rs = length Ts ∧ (∀i<length Ts. OG_Hoare.post (Rs ! i) = OG_Hoare.post (Ts ! i))›*) apply simp (*goal: ‹⋀i c q r ta. ⟦(R', t) = (Parallel (Ts[i := (r, q)]), ta); i < length Ts; Ts ! i = (Some c, q); (Some c, s) -1→ (r, ta)⟧ ⟹ ∃Rs. R' = Parallel Rs ∧ length Rs = length Ts ∧ (∀i<length Ts. OG_Hoare.post (Rs ! i) = OG_Hoare.post (Ts ! i))›*) apply clarify (*goal: ‹⋀(i::nat) (c::'a ann_com) (q::'a set) r::'a ann_com option. ⟦(R'::'a com) = Parallel ((Ts::('a ann_com option × 'a set) list)[i := (r, q)]); i < length Ts; Ts ! i = (Some c, q); (Some c, s::'a) -1→ (r, t::'a)⟧ ⟹ ∀ia<length Ts. OG_Hoare.post (Ts[i := (r, q)] ! ia) = OG_Hoare.post (Ts ! ia)›*) apply (case_tac "i=ia") (*goals: 1. ‹⋀i c q r ia. ⟦R' = Parallel (Ts[i := (r, q)]); i < length Ts; Ts ! i = (Some c, q); (Some c, s) -1→ (r, t); ia < length Ts; i = ia⟧ ⟹ OG_Hoare.post (Ts[i := (r, q)] ! ia) = OG_Hoare.post (Ts ! ia)› 2. ‹⋀i c q r ia. ⟦R' = Parallel (Ts[i := (r, q)]); i < length Ts; Ts ! i = (Some c, q); (Some c, s) -1→ (r, t); ia < length Ts; i ≠ ia⟧ ⟹ OG_Hoare.post (Ts[i := (r, q)] ! ia) = OG_Hoare.post (Ts ! ia)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma Parallel_length_post_PStar: "(Parallel Ts,s) -P*→ (R',t) ⟹ (∃Rs. R' = (Parallel Rs) ∧ (length Rs) = (length Ts) ∧ (∀i. i<length Ts ⟶ post(Ts ! i) = post(Rs ! i)))" apply (erule rtrancl_induct2 (*‹⟦((?ax, ?ay), ?bx, ?by) ∈ ?r⇧*; ?P ?ax ?ay; ⋀a b aa ba. ⟦((?ax, ?ay), a, b) ∈ ?r⇧*; ((a, b), aa, ba) ∈ ?r; ?P a b⟧ ⟹ ?P aa ba⟧ ⟹ ?P ?bx ?by›*)) (*goals: 1. ‹∃Rs. Parallel Ts = Parallel Rs ∧ length Rs = length Ts ∧ (∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rs ! i))› 2. ‹⋀a b aa ba. ⟦(Parallel Ts, s) -P*→ (a, b); (a, b) -P1→ (aa, ba); ∃Rs. a = Parallel Rs ∧ length Rs = length Ts ∧ (∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rs ! i))⟧ ⟹ ∃Rs. aa = Parallel Rs ∧ length Rs = length Ts ∧ (∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rs ! i))› discuss goal 1*) apply simp (*discuss goal 2*) apply clarify (*goal: ‹⋀a b aa ba. ⟦(Parallel Ts, s) -P*→ (a, b); (a, b) -P1→ (aa, ba); ∃Rs. a = Parallel Rs ∧ length Rs = length Ts ∧ (∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rs ! i))⟧ ⟹ ∃Rs. aa = Parallel Rs ∧ length Rs = length Ts ∧ (∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rs ! i))›*) apply simp (*goal: ‹⋀a b aa ba Rs. ⟦(Parallel Ts, s) -P*→ (Parallel Rs, b); (Parallel Rs, b) -P1→ (aa, ba); length Rs = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rs ! i)⟧ ⟹ ∃Rs. aa = Parallel Rs ∧ length Rs = length Ts ∧ (∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rs ! i))›*) apply (drule Parallel_length_post_P1 (*‹(Parallel ?Ts, ?s) -P1→ (?R', ?t) ⟹ ∃Rs. ?R' = Parallel Rs ∧ length Rs = length ?Ts ∧ (∀i<length ?Ts. OG_Hoare.post (Rs ! i) = OG_Hoare.post (?Ts ! i))›*)) (*goal: ‹⋀(b::'a) (aa::'a com) (ba::'a) Rs::('a ann_com option × 'a set) list. ⟦(Parallel (Ts::('a ann_com option × 'a set) list), s::'a) -P*→ (Parallel Rs, b); (Parallel Rs, b) -P1→ (aa, ba); length Rs = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rs ! i)⟧ ⟹ ∃Rsa::('a ann_com option × 'a set) list. aa = Parallel Rsa ∧ length Rsa = length Ts ∧ (∀i<length Ts. OG_Hoare.post (Rs ! i) = OG_Hoare.post (Rsa ! i))›*) apply auto (*proven 2 subgoals*) . lemma assertions_lemma: "pre c ∈ assertions c" apply (rule ann_com_com.induct [THEN conjunct1] (*‹⟦⋀x1 x2. ?P1.1 (AnnBasic x1 x2); ⋀x1 x2. ⟦?P1.1 x1; ?P1.1 x2⟧ ⟹ ?P1.1 (AnnSeq x1 x2); ⋀x1 x2 x3 x4. ⟦?P1.1 x3; ?P1.1 x4⟧ ⟹ ?P1.1 (AnnCond1 x1 x2 x3 x4); ⋀x1 x2 x3. ?P1.1 x3 ⟹ ?P1.1 (AnnCond2 x1 x2 x3); ⋀x1 x2 x3 x4. ?P1.1 x4 ⟹ ?P1.1 (AnnWhile x1 x2 x3 x4); ⋀x1 x2 x3. ?P2.1 x3 ⟹ ?P1.1 (AnnAwait x1 x2 x3); ⋀x. (⋀xa xaa xaaa. ⟦xa ∈ set x; xaa ∈ Basic_BNFs.fsts xa; xaaa ∈ set_option xaa⟧ ⟹ ?P1.1 xaaa) ⟹ ?P2.1 (Parallel x); ⋀x. ?P2.1 (Basic x); ⋀x1 x2. ⟦?P2.1 x1; ?P2.1 x2⟧ ⟹ ?P2.1 (Seq x1 x2); ⋀x1 x2 x3. ⟦?P2.1 x2; ?P2.1 x3⟧ ⟹ ?P2.1 (Cond x1 x2 x3); ⋀x1 x2 x3. ?P2.1 x3 ⟹ ?P2.1 (While x1 x2 x3)⟧ ⟹ ?P1.1 ?ann_com1›*)) (*goals: 1. ‹⋀(x1::'a::type set) x2::'a::type ⇒ 'a::type. pre (AnnBasic x1 x2) ∈ assertions (AnnBasic x1 x2)› 2. ‹⋀(x1::'a::type ann_com) x2::'a::type ann_com. ⟦pre x1 ∈ assertions x1; pre x2 ∈ assertions x2⟧ ⟹ pre (AnnSeq x1 x2) ∈ assertions (AnnSeq x1 x2)› 3. ‹⋀(x1::'a::type set) (x2::'a::type set) (x3::'a::type ann_com) x4::'a::type ann_com. ⟦pre x3 ∈ assertions x3; pre x4 ∈ assertions x4⟧ ⟹ pre (AnnCond1 x1 x2 x3 x4) ∈ assertions (AnnCond1 x1 x2 x3 x4)› 4. ‹⋀(x1::'a::type set) (x2::'a::type set) x3::'a::type ann_com. pre x3 ∈ assertions x3 ⟹ pre (AnnCond2 x1 x2 x3) ∈ assertions (AnnCond2 x1 x2 x3)› 5. ‹⋀(x1::'a::type set) (x2::'a::type set) (x3::'a::type set) x4::'a::type ann_com. pre x4 ∈ assertions x4 ⟹ pre (AnnWhile x1 x2 x3 x4) ∈ assertions (AnnWhile x1 x2 x3 x4)› 6. ‹⋀(x1::'a::type set) (x2::'a::type set) x3::'a::type com. (?P2.1::'a::type com ⇒ bool) x3 ⟹ pre (AnnAwait x1 x2 x3) ∈ assertions (AnnAwait x1 x2 x3)› 7. ‹⋀x::('a::type ann_com option × 'a::type set) list. (⋀(xa::'a::type ann_com option × 'a::type set) (xaa::'a::type ann_com option) xaaa::'a::type ann_com. ⟦xa ∈ set x; xaa ∈ Basic_BNFs.fsts xa; xaaa ∈ set_option xaa⟧ ⟹ pre xaaa ∈ assertions xaaa) ⟹ (?P2.1::'a::type com ⇒ bool) (Parallel x)› 8. ‹⋀x::'a::type ⇒ 'a::type. (?P2.1::'a::type com ⇒ bool) (Basic x)› 9. ‹⋀(x1::'a::type com) x2::'a::type com. ⟦(?P2.1::'a::type com ⇒ bool) x1; ?P2.1 x2⟧ ⟹ ?P2.1 (Seq x1 x2)› 10. ‹⋀(x1::'a::type set) (x2::'a::type com) x3::'a::type com. ⟦(?P2.1::'a::type com ⇒ bool) x2; ?P2.1 x3⟧ ⟹ ?P2.1 (Cond x1 x2 x3)› 11. ‹⋀(x1::'a::type set) (x2::'a::type set) x3::'a::type com. (?P2.1::'a::type com ⇒ bool) x3 ⟹ ?P2.1 (While x1 x2 x3)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*discuss goal 9*) apply ((auto)[1]) (*discuss goal 10*) apply ((auto)[1]) (*discuss goal 11*) apply ((auto)[1]) (*proven 11 subgoals*) . lemma interfree_aux1 [rule_format]: "(c,s) -1→ (r,t) ⟶ (interfree_aux(c1, q1, c) ⟶ interfree_aux(c1, q1, r))" apply (rule ann_transition_transition.induct [THEN conjunct1] (*‹⟦⋀r f s. ?P1.1 (Some (AnnBasic r f)) s None (f s); ⋀c0 s t c1. ⟦(Some c0, s) -1→ (None, t); ?P1.1 (Some c0) s None t⟧ ⟹ ?P1.1 (Some (AnnSeq c0 c1)) s (Some c1) t; ⋀c0 s c2 t c1. ⟦(Some c0, s) -1→ (Some c2, t); ?P1.1 (Some c0) s (Some c2) t⟧ ⟹ ?P1.1 (Some (AnnSeq c0 c1)) s (Some (AnnSeq c2 c1)) t; ⋀s b r c1 c2. s ∈ b ⟹ ?P1.1 (Some (AnnCond1 r b c1 c2)) s (Some c1) s; ⋀s b r c1 c2. s ∉ b ⟹ ?P1.1 (Some (AnnCond1 r b c1 c2)) s (Some c2) s; ⋀s b r c. s ∈ b ⟹ ?P1.1 (Some (AnnCond2 r b c)) s (Some c) s; ⋀s b r c. s ∉ b ⟹ ?P1.1 (Some (AnnCond2 r b c)) s None s; ⋀s b r i c. s ∉ b ⟹ ?P1.1 (Some (AnnWhile r b i c)) s None s; ⋀s b r i c. s ∈ b ⟹ ?P1.1 (Some (AnnWhile r b i c)) s (Some (AnnSeq c (AnnWhile i b i c))) s; ⋀s b c t r. ⟦s ∈ b; atom_com c; ((c, s), Parallel [], t) ∈ (transition ∩ {(x, y). ?P2.1 x y})⇧*⟧ ⟹ ?P1.1 (Some (AnnAwait r b c)) s None t; ⋀i Ts c q s r t. ⟦i < length Ts; Ts ! i = (Some c, q); (Some c, s) -1→ (r, t); ?P1.1 (Some c) s r t⟧ ⟹ ?P2.1 (Parallel Ts, s) (Parallel (Ts[i := (r, q)]), t); ⋀f s. ?P2.1 (Basic f, s) (Parallel [], f s); ⋀Ts c s. All_None Ts ⟹ ?P2.1 (Seq (Parallel Ts) c, s) (c, s); ⋀c0 s c2 t c1. ⟦(c0, s) -P1→ (c2, t); ?P2.1 (c0, s) (c2, t)⟧ ⟹ ?P2.1 (Seq c0 c1, s) (Seq c2 c1, t); ⋀s b c1 c2. s ∈ b ⟹ ?P2.1 (Cond b c1 c2, s) (c1, s); ⋀s b c1 c2. s ∉ b ⟹ ?P2.1 (Cond b c1 c2, s) (c2, s); ⋀s b i c. s ∉ b ⟹ ?P2.1 (While b i c, s) (Parallel [], s); ⋀s b i c. s ∈ b ⟹ ?P2.1 (While b i c, s) (Seq c (While b i c), s)⟧ ⟹ (?x1.1, ?x2.1) -1→ (?x3.1, ?x4.1) ⟶ ?P1.1 ?x1.1 ?x2.1 ?x3.1 ?x4.1›*)) (*goals: 1. ‹⋀r f s. interfree_aux (c1, q1, Some (AnnBasic r f)) ⟶ interfree_aux (c1, q1, None)› 2. ‹⋀c0 s t c1a. ⟦(Some c0, s) -1→ (None, t); interfree_aux (c1, q1, Some c0) ⟶ interfree_aux (c1, q1, None)⟧ ⟹ interfree_aux (c1, q1, Some (AnnSeq c0 c1a)) ⟶ interfree_aux (c1, q1, Some c1a)› 3. ‹⋀c0 s c2 t c1a. ⟦(Some c0, s) -1→ (Some c2, t); interfree_aux (c1, q1, Some c0) ⟶ interfree_aux (c1, q1, Some c2)⟧ ⟹ interfree_aux (c1, q1, Some (AnnSeq c0 c1a)) ⟶ interfree_aux (c1, q1, Some (AnnSeq c2 c1a))› 4. ‹⋀s b r c1a c2. s ∈ b ⟹ interfree_aux (c1, q1, Some (AnnCond1 r b c1a c2)) ⟶ interfree_aux (c1, q1, Some c1a)› 5. ‹⋀s b r c1a c2. s ∉ b ⟹ interfree_aux (c1, q1, Some (AnnCond1 r b c1a c2)) ⟶ interfree_aux (c1, q1, Some c2)› 6. ‹⋀s b r c. s ∈ b ⟹ interfree_aux (c1, q1, Some (AnnCond2 r b c)) ⟶ interfree_aux (c1, q1, Some c)› 7. ‹⋀s b r c. s ∉ b ⟹ interfree_aux (c1, q1, Some (AnnCond2 r b c)) ⟶ interfree_aux (c1, q1, None)› 8. ‹⋀s b r i c. s ∉ b ⟹ interfree_aux (c1, q1, Some (AnnWhile r b i c)) ⟶ interfree_aux (c1, q1, None)› 9. ‹⋀s b r i c. s ∈ b ⟹ interfree_aux (c1, q1, Some (AnnWhile r b i c)) ⟶ interfree_aux (c1, q1, Some (AnnSeq c (AnnWhile i b i c)))› 10. ‹⋀s b c t r. ⟦s ∈ b; atom_com c; ((c, s), Parallel [], t) ∈ (transition ∩ {(x, y). ?P2.1 x y})⇧*⟧ ⟹ interfree_aux (c1, q1, Some (AnnAwait r b c)) ⟶ interfree_aux (c1, q1, None)› 11. ‹⋀i Ts c q s r t. ⟦i < length Ts; Ts ! i = (Some c, q); (Some c, s) -1→ (r, t); interfree_aux (c1, q1, Some c) ⟶ interfree_aux (c1, q1, r)⟧ ⟹ ?P2.1 (Parallel Ts, s) (Parallel (Ts[i := (r, q)]), t)› 12. ‹⋀f s. ?P2.1 (Basic f, s) (Parallel [], f s)› 13. ‹⋀Ts c s. All_None Ts ⟹ ?P2.1 (Seq (Parallel Ts) c, s) (c, s)› 14. ‹⋀c0 s c2 t c1. ⟦(c0, s) -P1→ (c2, t); ?P2.1 (c0, s) (c2, t)⟧ ⟹ ?P2.1 (Seq c0 c1, s) (Seq c2 c1, t)› 15. ‹⋀s b c1 c2. s ∈ b ⟹ ?P2.1 (Cond b c1 c2, s) (c1, s)› 16. ‹⋀s b c1 c2. s ∉ b ⟹ ?P2.1 (Cond b c1 c2, s) (c2, s)› 17. ‹⋀s b i c. s ∉ b ⟹ ?P2.1 (While b i c, s) (Parallel [], s)› 18. ‹⋀s b i c. s ∈ b ⟹ ?P2.1 (While b i c, s) (Seq c (While b i c), s)› discuss goal 1*) apply ((safe)[1]) (*top goal: ‹⋀(r::'a set) (f::'a ⇒ 'a) s::'a. interfree_aux (c1::'a ann_com option, q1::'a set, Some (AnnBasic r f)) ⟶ interfree_aux (c1, q1, None)› and 17 goals remain*) apply (simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 2*) apply ((safe)[1]) (*goals: 1. ‹⋀c0 s t c1a. ⟦(Some c0, s) -1→ (None, t); interfree_aux (c1, q1, Some (AnnSeq c0 c1a)); ¬ interfree_aux (c1, q1, Some c0)⟧ ⟹ interfree_aux (c1, q1, Some c1a)› 2. ‹⋀c0 s t c1a. ⟦(Some c0, s) -1→ (None, t); interfree_aux (c1, q1, Some (AnnSeq c0 c1a)); interfree_aux (c1, q1, None)⟧ ⟹ interfree_aux (c1, q1, Some c1a)› discuss goal 1*) apply (simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 2*) apply (simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*proven 2 subgoals*) (*discuss goal 3*) apply ((safe)[1]) (*goals: 1. ‹⋀c0 s c2 t c1a. ⟦(Some c0, s) -1→ (Some c2, t); interfree_aux (c1, q1, Some (AnnSeq c0 c1a)); ¬ interfree_aux (c1, q1, Some c0)⟧ ⟹ interfree_aux (c1, q1, Some (AnnSeq c2 c1a))› 2. ‹⋀c0 s c2 t c1a. ⟦(Some c0, s) -1→ (Some c2, t); interfree_aux (c1, q1, Some (AnnSeq c0 c1a)); interfree_aux (c1, q1, Some c2)⟧ ⟹ interfree_aux (c1, q1, Some (AnnSeq c2 c1a))› discuss goal 1*) apply (simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 2*) apply (simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co::?'a::type ann_com option, q::?'a::type set, co'::?'a::type ann_com option). co' = None ∨ (∀(r::?'a::type set, a::?'a::type com)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p::?'a::type set∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*top goal: ‹⋀(c0::'a ann_com) (s::'a) (c2::'a ann_com) (t::'a) c1a::'a ann_com. ⟦(Some c0, s) -1→ (Some c2, t); interfree_aux (c1::'a ann_com option, q1::'a set, Some (AnnSeq c0 c1a)); interfree_aux (c1, q1, Some c2)⟧ ⟹ interfree_aux (c1, q1, Some (AnnSeq c2 c1a))› and 15 goals remain*) apply force (*proven 2 subgoals*) (*discuss goal 4*) apply ((safe)[1]) (*top goal: ‹⋀(s::'a::type) (b::'a::type set) (r::'a::type set) (c1a::'a::type ann_com) c2::'a::type ann_com. s ∈ b ⟹ interfree_aux (c1::'a::type ann_com option, q1::'a::type set, Some (AnnCond1 r b c1a c2)) ⟶ interfree_aux (c1, q1, Some c1a)› and 14 goals remain*) apply (simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 5*) apply ((safe)[1]) (*top goal: ‹⋀s b r c1a c2. s ∉ b ⟹ interfree_aux (c1, q1, Some (AnnCond1 r b c1a c2)) ⟶ interfree_aux (c1, q1, Some c2)› and 13 goals remain*) apply (simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 6*) apply ((safe)[1]) (*top goal: ‹⋀s b r c. s ∈ b ⟹ interfree_aux (c1, q1, Some (AnnCond2 r b c)) ⟶ interfree_aux (c1, q1, Some c)› and 12 goals remain*) apply (simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 7*) apply ((safe)[1]) (*top goal: ‹⋀s b r c. s ∉ b ⟹ interfree_aux (c1, q1, Some (AnnCond2 r b c)) ⟶ interfree_aux (c1, q1, None)› and 11 goals remain*) apply (simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 8*) apply ((safe)[1]) (*top goal: ‹⋀s b r i c. s ∉ b ⟹ interfree_aux (c1, q1, Some (AnnWhile r b i c)) ⟶ interfree_aux (c1, q1, None)› and 10 goals remain*) apply (simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co::?'a ann_com option, q::?'a set, co'::?'a ann_com option). co' = None ∨ (∀(r::?'a set, a::?'a com)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p::?'a set∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 9*) apply ((safe)[1]) (*top goal: ‹⋀s b r i c. s ∈ b ⟹ interfree_aux (c1, q1, Some (AnnWhile r b i c)) ⟶ interfree_aux (c1, q1, Some (AnnSeq c (AnnWhile i b i c)))› and 9 goals remain*) apply (simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 10*) apply ((safe)[1]) (*top goal: ‹⋀(s::'a::type) (b::'a::type set) (c::'a::type com) (t::'a::type) r::'a::type set. ⟦s ∈ b; atom_com c; ((c, s), Parallel [], t) ∈ (transition ∩ {(x::'a::type com × 'a::type, y::'a::type com × 'a::type). (?P2.1::'a::type com × 'a::type ⇒ 'a::type com × 'a::type ⇒ bool) x y})⇧*⟧ ⟹ interfree_aux (c1::'a::type ann_com option, q1::'a::type set, Some (AnnAwait r b c)) ⟶ interfree_aux (c1, q1, None)› and 8 goals remain*) apply (simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 11*) apply ((safe)[1]) (*goals: 1. ‹⋀(i::nat) (Ts::('a::type ann_com option × 'a::type set) list) (c::'a::type ann_com) (q::'a::type set) (s::'a::type) (r::'a::type ann_com option) t::'a::type. ⟦i < length Ts; Ts ! i = (Some c, q); (Some c, s) -1→ (r, t); ¬ interfree_aux (c1::'a::type ann_com option, q1::'a::type set, Some c)⟧ ⟹ (?P2.1::'a::type com × 'a::type ⇒ 'a::type com × 'a::type ⇒ bool) (Parallel Ts, s) (Parallel (Ts[i := (r, q)]), t)› 2. ‹⋀(i::nat) (Ts::('a::type ann_com option × 'a::type set) list) (c::'a::type ann_com) (q::'a::type set) (s::'a::type) (r::'a::type ann_com option) t::'a::type. ⟦i < length Ts; Ts ! i = (Some c, q); (Some c, s) -1→ (r, t); interfree_aux (c1::'a::type ann_com option, q1::'a::type set, r)⟧ ⟹ (?P2.1::'a::type com × 'a::type ⇒ 'a::type com × 'a::type ⇒ bool) (Parallel Ts, s) (Parallel (Ts[i := (r, q)]), t)› discuss goal 1*) apply (rule TrueI (*‹True›*)) (*discuss goal 2*) apply (simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*proven 2 subgoals*) (*discuss goal 12*) apply (simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 13*) apply (simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 14*) apply (simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 15*) apply (simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co::?'a ann_com option, q::?'a set, co'::?'a ann_com option). co' = None ∨ (∀(r::?'a set, a::?'a com)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p::?'a set∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 16*) apply (simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 17*) apply (simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 18*) apply (simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*proven 18 subgoals*) . lemma interfree_aux2 [rule_format]: "(c,s) -1→ (r,t) ⟶ (interfree_aux(c, q, a) ⟶ interfree_aux(r, q, a) )" apply (rule ann_transition_transition.induct [THEN conjunct1] (*‹⟦⋀r f s. ?P1.1 (Some (AnnBasic r f)) s None (f s); ⋀c0 s t c1. ⟦(Some c0, s) -1→ (None, t); ?P1.1 (Some c0) s None t⟧ ⟹ ?P1.1 (Some (AnnSeq c0 c1)) s (Some c1) t; ⋀c0 s c2 t c1. ⟦(Some c0, s) -1→ (Some c2, t); ?P1.1 (Some c0) s (Some c2) t⟧ ⟹ ?P1.1 (Some (AnnSeq c0 c1)) s (Some (AnnSeq c2 c1)) t; ⋀s b r c1 c2. s ∈ b ⟹ ?P1.1 (Some (AnnCond1 r b c1 c2)) s (Some c1) s; ⋀s b r c1 c2. s ∉ b ⟹ ?P1.1 (Some (AnnCond1 r b c1 c2)) s (Some c2) s; ⋀s b r c. s ∈ b ⟹ ?P1.1 (Some (AnnCond2 r b c)) s (Some c) s; ⋀s b r c. s ∉ b ⟹ ?P1.1 (Some (AnnCond2 r b c)) s None s; ⋀s b r i c. s ∉ b ⟹ ?P1.1 (Some (AnnWhile r b i c)) s None s; ⋀s b r i c. s ∈ b ⟹ ?P1.1 (Some (AnnWhile r b i c)) s (Some (AnnSeq c (AnnWhile i b i c))) s; ⋀s b c t r. ⟦s ∈ b; atom_com c; ((c, s), Parallel [], t) ∈ (transition ∩ {(x, y). ?P2.1 x y})⇧*⟧ ⟹ ?P1.1 (Some (AnnAwait r b c)) s None t; ⋀i Ts c q s r t. ⟦i < length Ts; Ts ! i = (Some c, q); (Some c, s) -1→ (r, t); ?P1.1 (Some c) s r t⟧ ⟹ ?P2.1 (Parallel Ts, s) (Parallel (Ts[i := (r, q)]), t); ⋀f s. ?P2.1 (Basic f, s) (Parallel [], f s); ⋀Ts c s. All_None Ts ⟹ ?P2.1 (Seq (Parallel Ts) c, s) (c, s); ⋀c0 s c2 t c1. ⟦(c0, s) -P1→ (c2, t); ?P2.1 (c0, s) (c2, t)⟧ ⟹ ?P2.1 (Seq c0 c1, s) (Seq c2 c1, t); ⋀s b c1 c2. s ∈ b ⟹ ?P2.1 (Cond b c1 c2, s) (c1, s); ⋀s b c1 c2. s ∉ b ⟹ ?P2.1 (Cond b c1 c2, s) (c2, s); ⋀s b i c. s ∉ b ⟹ ?P2.1 (While b i c, s) (Parallel [], s); ⋀s b i c. s ∈ b ⟹ ?P2.1 (While b i c, s) (Seq c (While b i c), s)⟧ ⟹ (?x1.1, ?x2.1) -1→ (?x3.1, ?x4.1) ⟶ ?P1.1 ?x1.1 ?x2.1 ?x3.1 ?x4.1›*)) (*goals: 1. ‹⋀r f s. interfree_aux (Some (AnnBasic r f), q, a) ⟶ interfree_aux (None, q, a)› 2. ‹⋀c0 s t c1. ⟦(Some c0, s) -1→ (None, t); interfree_aux (Some c0, q, a) ⟶ interfree_aux (None, q, a)⟧ ⟹ interfree_aux (Some (AnnSeq c0 c1), q, a) ⟶ interfree_aux (Some c1, q, a)› 3. ‹⋀c0 s c2 t c1. ⟦(Some c0, s) -1→ (Some c2, t); interfree_aux (Some c0, q, a) ⟶ interfree_aux (Some c2, q, a)⟧ ⟹ interfree_aux (Some (AnnSeq c0 c1), q, a) ⟶ interfree_aux (Some (AnnSeq c2 c1), q, a)› 4. ‹⋀s b r c1 c2. s ∈ b ⟹ interfree_aux (Some (AnnCond1 r b c1 c2), q, a) ⟶ interfree_aux (Some c1, q, a)› 5. ‹⋀s b r c1 c2. s ∉ b ⟹ interfree_aux (Some (AnnCond1 r b c1 c2), q, a) ⟶ interfree_aux (Some c2, q, a)› 6. ‹⋀s b r c. s ∈ b ⟹ interfree_aux (Some (AnnCond2 r b c), q, a) ⟶ interfree_aux (Some c, q, a)› 7. ‹⋀s b r c. s ∉ b ⟹ interfree_aux (Some (AnnCond2 r b c), q, a) ⟶ interfree_aux (None, q, a)› 8. ‹⋀s b r i c. s ∉ b ⟹ interfree_aux (Some (AnnWhile r b i c), q, a) ⟶ interfree_aux (None, q, a)› 9. ‹⋀s b r i c. s ∈ b ⟹ interfree_aux (Some (AnnWhile r b i c), q, a) ⟶ interfree_aux (Some (AnnSeq c (AnnWhile i b i c)), q, a)› 10. ‹⋀s b c t r. ⟦s ∈ b; atom_com c; ((c, s), Parallel [], t) ∈ (transition ∩ {(x, y). ?P2.1 x y})⇧*⟧ ⟹ interfree_aux (Some (AnnAwait r b c), q, a) ⟶ interfree_aux (None, q, a)› 11. ‹⋀i Ts c qa s r t. ⟦i < length Ts; Ts ! i = (Some c, qa); (Some c, s) -1→ (r, t); interfree_aux (Some c, q, a) ⟶ interfree_aux (r, q, a)⟧ ⟹ ?P2.1 (Parallel Ts, s) (Parallel (Ts[i := (r, qa)]), t)› 12. ‹⋀f s. ?P2.1 (Basic f, s) (Parallel [], f s)› 13. ‹⋀Ts c s. All_None Ts ⟹ ?P2.1 (Seq (Parallel Ts) c, s) (c, s)› 14. ‹⋀c0 s c2 t c1. ⟦(c0, s) -P1→ (c2, t); ?P2.1 (c0, s) (c2, t)⟧ ⟹ ?P2.1 (Seq c0 c1, s) (Seq c2 c1, t)› 15. ‹⋀s b c1 c2. s ∈ b ⟹ ?P2.1 (Cond b c1 c2, s) (c1, s)› 16. ‹⋀s b c1 c2. s ∉ b ⟹ ?P2.1 (Cond b c1 c2, s) (c2, s)› 17. ‹⋀s b i c. s ∉ b ⟹ ?P2.1 (While b i c, s) (Parallel [], s)› 18. ‹⋀s b i c. s ∈ b ⟹ ?P2.1 (While b i c, s) (Seq c (While b i c), s)› discuss goal 1*) apply (force simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 2*) apply (force simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 3*) apply (force simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 4*) apply (force simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 5*) apply (force simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 6*) apply (force simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 7*) apply (force simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 8*) apply (force simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 9*) apply (force simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 10*) apply (force simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co::?'a::type ann_com option, q::?'a::type set, co'::?'a::type ann_com option). co' = None ∨ (∀(r::?'a::type set, a::?'a::type com)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p::?'a::type set∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 11*) apply (force simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 12*) apply (force simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 13*) apply (force simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 14*) apply (force simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co::?'a ann_com option, q::?'a set, co'::?'a ann_com option). co' = None ∨ (∀(r::?'a set, a::?'a com)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p::?'a set∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 15*) apply (force simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 16*) apply (force simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 17*) apply (force simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 18*) apply (force simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*proven 18 subgoals*) . lemma interfree_lemma: "⟦ (Some c, s) -1→ (r, t);interfree Ts ; i<length Ts; Ts!i = (Some c, q) ⟧ ⟹ interfree (Ts[i:= (r, q)])" apply (simp add: interfree_def (*‹interfree ?Ts ≡ ∀i j. i < length ?Ts ∧ j < length ?Ts ∧ i ≠ j ⟶ interfree_aux (OG_Hoare.com (?Ts ! i), OG_Hoare.post (?Ts ! i), OG_Hoare.com (?Ts ! j))›*)) (*goal: ‹⟦(Some c, s) -1→ (r, t); interfree Ts; i < length Ts; Ts ! i = (Some c, q)⟧ ⟹ interfree (Ts[i := (r, q)])›*) apply clarify (*goal: ‹⟦(Some c, s) -1→ (r, t); ∀i j. i < length Ts ∧ j < length Ts ∧ i ≠ j ⟶ interfree_aux (OG_Hoare.com (Ts ! i), OG_Hoare.post (Ts ! i), OG_Hoare.com (Ts ! j)); i < length Ts; Ts ! i = (Some c, q)⟧ ⟹ ∀ia j. ia < length Ts ∧ j < length Ts ∧ ia ≠ j ⟶ interfree_aux (OG_Hoare.com (Ts[i := (r, q)] ! ia), OG_Hoare.post (Ts[i := (r, q)] ! ia), OG_Hoare.com (Ts[i := (r, q)] ! j))›*) apply (case_tac "i=j") (*goals: 1. ‹⋀(ia::nat) j::nat. ⟦(Some (c::'a ann_com), s::'a) -1→ (r::'a ann_com option, t::'a); ∀(i::nat) j::nat. i < length (Ts::('a ann_com option × 'a set) list) ∧ j < length Ts ∧ i ≠ j ⟶ interfree_aux (OG_Hoare.com (Ts ! i), OG_Hoare.post (Ts ! i), OG_Hoare.com (Ts ! j)); (i::nat) < length Ts; Ts ! i = (Some c, q::'a set); ia < length Ts; j < length Ts; ia ≠ j; i = j⟧ ⟹ interfree_aux (OG_Hoare.com (Ts[i := (r, q)] ! ia), OG_Hoare.post (Ts[i := (r, q)] ! ia), OG_Hoare.com (Ts[i := (r, q)] ! j))› 2. ‹⋀(ia::nat) j::nat. ⟦(Some (c::'a ann_com), s::'a) -1→ (r::'a ann_com option, t::'a); ∀(i::nat) j::nat. i < length (Ts::('a ann_com option × 'a set) list) ∧ j < length Ts ∧ i ≠ j ⟶ interfree_aux (OG_Hoare.com (Ts ! i), OG_Hoare.post (Ts ! i), OG_Hoare.com (Ts ! j)); (i::nat) < length Ts; Ts ! i = (Some c, q::'a set); ia < length Ts; j < length Ts; ia ≠ j; i ≠ j⟧ ⟹ interfree_aux (OG_Hoare.com (Ts[i := (r, q)] ! ia), OG_Hoare.post (Ts[i := (r, q)] ! ia), OG_Hoare.com (Ts[i := (r, q)] ! j))› discuss goal 1*) apply (drule_tac t = "ia" in not_sym (*‹?t ≠ ?s ⟹ ?s ≠ ?t›*)) (*top goal: ‹⋀ia j. ⟦(Some c, s) -1→ (r, t); ∀i j. i < length Ts ∧ j < length Ts ∧ i ≠ j ⟶ interfree_aux (OG_Hoare.com (Ts ! i), OG_Hoare.post (Ts ! i), OG_Hoare.com (Ts ! j)); i < length Ts; Ts ! i = (Some c, q); ia < length Ts; j < length Ts; ia ≠ j; i = j⟧ ⟹ interfree_aux (OG_Hoare.com (Ts[i := (r, q)] ! ia), OG_Hoare.post (Ts[i := (r, q)] ! ia), OG_Hoare.com (Ts[i := (r, q)] ! j))› and 1 goal remains*) apply simp (*top goal: ‹⋀(ia::nat) j::nat. ⟦(Some (c::'a ann_com), s::'a) -1→ (r::'a ann_com option, t::'a); ∀(i::nat) j::nat. i < length (Ts::('a ann_com option × 'a set) list) ∧ j < length Ts ∧ i ≠ j ⟶ interfree_aux (OG_Hoare.com (Ts ! i), OG_Hoare.post (Ts ! i), OG_Hoare.com (Ts ! j)); (i::nat) < length Ts; Ts ! i = (Some c, q::'a set); ia < length Ts; j < length Ts; i = j; j ≠ ia⟧ ⟹ interfree_aux (OG_Hoare.com (Ts[i := (r, q)] ! ia), OG_Hoare.post (Ts[i := (r, q)] ! ia), OG_Hoare.com (Ts[i := (r, q)] ! j))› and 1 goal remains*) apply (force elim: interfree_aux1 (*‹⟦(?c, ?s) -1→ (?r, ?t); interfree_aux (?c1.0, ?q1.0, ?c)⟧ ⟹ interfree_aux (?c1.0, ?q1.0, ?r)›*)) (*discuss goal 2*) apply simp (*goal: ‹⋀ia j. ⟦(Some c, s) -1→ (r, t); ∀i j. i < length Ts ∧ j < length Ts ∧ i ≠ j ⟶ interfree_aux (OG_Hoare.com (Ts ! i), OG_Hoare.post (Ts ! i), OG_Hoare.com (Ts ! j)); i < length Ts; Ts ! i = (Some c, q); ia < length Ts; j < length Ts; ia ≠ j; i ≠ j⟧ ⟹ interfree_aux (OG_Hoare.com (Ts[i := (r, q)] ! ia), OG_Hoare.post (Ts[i := (r, q)] ! ia), OG_Hoare.com (Ts[i := (r, q)] ! j))›*) apply (force elim: interfree_aux2 (*‹⟦(?c, ?s) -1→ (?r, ?t); interfree_aux (?c, ?q, ?a)⟧ ⟹ interfree_aux (?r, ?q, ?a)›*) simp add:nth_list_update (*‹?i < length ?xs ⟹ ?xs[?i := ?x] ! ?j = (if ?i = ?j then ?x else ?xs ! ?j)›*)) (*proven 2 subgoals*) . text ‹Strong Soundness Theorem for Parallel Programs:› lemma Parallel_Strong_Soundness_Seq_aux: "⟦interfree Ts; i<length Ts; com(Ts ! i) = Some(AnnSeq c0 c1) ⟧ ⟹ interfree (Ts[i:=(Some c0, pre c1)])" apply (simp add: interfree_def (*‹interfree ?Ts ≡ ∀i j. i < length ?Ts ∧ j < length ?Ts ∧ i ≠ j ⟶ interfree_aux (OG_Hoare.com (?Ts ! i), OG_Hoare.post (?Ts ! i), OG_Hoare.com (?Ts ! j))›*)) (*goal: ‹⟦interfree Ts; i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnSeq c0 c1)⟧ ⟹ interfree (Ts[i := (Some c0, pre c1)])›*) apply clarify (*goal: ‹⟦∀i j. i < length Ts ∧ j < length Ts ∧ i ≠ j ⟶ interfree_aux (OG_Hoare.com (Ts ! i), OG_Hoare.post (Ts ! i), OG_Hoare.com (Ts ! j)); i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnSeq c0 c1)⟧ ⟹ ∀ia j. ia < length Ts ∧ j < length Ts ∧ ia ≠ j ⟶ interfree_aux (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia), OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! ia), OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! j))›*) apply (case_tac "i=j") (*goals: 1. ‹⋀(ia::nat) j::nat. ⟦∀(i::nat) j::nat. i < length (Ts::('a ann_com option × 'a set) list) ∧ j < length Ts ∧ i ≠ j ⟶ interfree_aux (OG_Hoare.com (Ts ! i), OG_Hoare.post (Ts ! i), OG_Hoare.com (Ts ! j)); (i::nat) < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnSeq (c0::'a ann_com) (c1::'a ann_com)); ia < length Ts; j < length Ts; ia ≠ j; i = j⟧ ⟹ interfree_aux (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia), OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! ia), OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! j))› 2. ‹⋀(ia::nat) j::nat. ⟦∀(i::nat) j::nat. i < length (Ts::('a ann_com option × 'a set) list) ∧ j < length Ts ∧ i ≠ j ⟶ interfree_aux (OG_Hoare.com (Ts ! i), OG_Hoare.post (Ts ! i), OG_Hoare.com (Ts ! j)); (i::nat) < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnSeq (c0::'a ann_com) (c1::'a ann_com)); ia < length Ts; j < length Ts; ia ≠ j; i ≠ j⟧ ⟹ interfree_aux (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia), OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! ia), OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! j))› discuss goal 1*) apply (force simp add: nth_list_update (*‹?i < length ?xs ⟹ ?xs[?i := ?x] ! ?j = (if ?i = ?j then ?x else ?xs ! ?j)›*) interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*discuss goal 2*) apply (case_tac "i=ia") (*goals: 1. ‹⋀ia j. ⟦∀i j. i < length Ts ∧ j < length Ts ∧ i ≠ j ⟶ interfree_aux (OG_Hoare.com (Ts ! i), OG_Hoare.post (Ts ! i), OG_Hoare.com (Ts ! j)); i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnSeq c0 c1); ia < length Ts; j < length Ts; ia ≠ j; i ≠ j; i = ia⟧ ⟹ interfree_aux (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia), OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! ia), OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! j))› 2. ‹⋀ia j. ⟦∀i j. i < length Ts ∧ j < length Ts ∧ i ≠ j ⟶ interfree_aux (OG_Hoare.com (Ts ! i), OG_Hoare.post (Ts ! i), OG_Hoare.com (Ts ! j)); i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnSeq c0 c1); ia < length Ts; j < length Ts; ia ≠ j; i ≠ j; i ≠ ia⟧ ⟹ interfree_aux (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia), OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! ia), OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! j))› discuss goal 1*) apply (erule_tac x=ia in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀ia j. ⟦∀i j. i < length Ts ∧ j < length Ts ∧ i ≠ j ⟶ interfree_aux (OG_Hoare.com (Ts ! i), OG_Hoare.post (Ts ! i), OG_Hoare.com (Ts ! j)); i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnSeq c0 c1); ia < length Ts; j < length Ts; ia ≠ j; i ≠ j; i = ia⟧ ⟹ interfree_aux (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia), OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! ia), OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! j))› and 1 goal remains*) apply (force simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*) assertions_lemma (*‹pre ?c ∈ assertions ?c›*)) (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma Parallel_Strong_Soundness_Seq [rule_format (no_asm)]: "⟦ ∀i<length Ts. (if com(Ts!i) = None then b ∈ post(Ts!i) else b ∈ pre(the(com(Ts!i))) ∧ ⊢ the(com(Ts!i)) post(Ts!i)); com(Ts ! i) = Some(AnnSeq c0 c1); i<length Ts; interfree Ts ⟧ ⟹ (∀ia<length Ts. (if com(Ts[i:=(Some c0, pre c1)]! ia) = None then b ∈ post(Ts[i:=(Some c0, pre c1)]! ia) else b ∈ pre(the(com(Ts[i:=(Some c0, pre c1)]! ia))) ∧ ⊢ the(com(Ts[i:=(Some c0, pre c1)]! ia)) post(Ts[i:=(Some c0, pre c1)]! ia))) ∧ interfree (Ts[i:= (Some c0, pre c1)])" apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹⟦∀i<length Ts. if OG_Hoare.com (Ts ! i) = None then b ∈ OG_Hoare.post (Ts ! i) else b ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i); OG_Hoare.com (Ts ! i) = Some (AnnSeq c0 c1); i < length Ts; interfree Ts⟧ ⟹ ∀ia<length Ts. if OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia) = None then b ∈ OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! ia) else b ∈ pre (the (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia))) ∧ ⊢ the (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia)) OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! ia)› 2. ‹⟦∀i<length Ts. if OG_Hoare.com (Ts ! i) = None then b ∈ OG_Hoare.post (Ts ! i) else b ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i); OG_Hoare.com (Ts ! i) = Some (AnnSeq c0 c1); i < length Ts; interfree Ts⟧ ⟹ interfree (Ts[i := (Some c0, pre c1)])› discuss goal 1*) apply safe (*top goal: ‹⟦∀i<length Ts. if OG_Hoare.com (Ts ! i) = None then b ∈ OG_Hoare.post (Ts ! i) else b ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i); OG_Hoare.com (Ts ! i) = Some (AnnSeq c0 c1); i < length Ts; interfree Ts⟧ ⟹ ∀ia<length Ts. if OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia) = None then b ∈ OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! ia) else b ∈ pre (the (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia))) ∧ ⊢ the (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia)) OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! ia)› and 1 goal remains*) apply (case_tac "i=ia") (*goals: 1. ‹⋀ia. ⟦∀i<length Ts. if OG_Hoare.com (Ts ! i) = None then b ∈ OG_Hoare.post (Ts ! i) else b ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i); OG_Hoare.com (Ts ! i) = Some (AnnSeq c0 c1); i < length Ts; interfree Ts; ia < length Ts; i = ia⟧ ⟹ if OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia) = None then b ∈ OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! ia) else b ∈ pre (the (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia))) ∧ ⊢ the (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia)) OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! ia)› 2. ‹⋀ia. ⟦∀i<length Ts. if OG_Hoare.com (Ts ! i) = None then b ∈ OG_Hoare.post (Ts ! i) else b ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i); OG_Hoare.com (Ts ! i) = Some (AnnSeq c0 c1); i < length Ts; interfree Ts; ia < length Ts; i ≠ ia⟧ ⟹ if OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia) = None then b ∈ OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! ia) else b ∈ pre (the (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia))) ∧ ⊢ the (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia)) OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! ia)› discuss goal 1*) apply simp (*top goal: ‹⋀ia. ⟦∀i<length Ts. if OG_Hoare.com (Ts ! i) = None then b ∈ OG_Hoare.post (Ts ! i) else b ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i); OG_Hoare.com (Ts ! i) = Some (AnnSeq c0 c1); i < length Ts; interfree Ts; ia < length Ts; i = ia⟧ ⟹ if OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia) = None then b ∈ OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! ia) else b ∈ pre (the (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia))) ∧ ⊢ the (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia)) OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! ia)› and 2 goals remain*) apply (force dest: ann_hoare_case_analysis (*‹⊢ ?C ?q' ⟹ (∀r f. ?C = AnnBasic r f ⟶ (∃q. r ⊆ {s. f s ∈ q} ∧ q ⊆ ?q')) ∧ (∀c0 c1. ?C = AnnSeq c0 c1 ⟶ (∃q⊆?q'. ⊢ c0 pre c1 ∧ ⊢ c1 q)) ∧ (∀r b c1 c2. ?C = AnnCond1 r b c1 c2 ⟶ (∃q⊆?q'. r ∩ b ⊆ pre c1 ∧ ⊢ c1 q ∧ r ∩ - b ⊆ pre c2 ∧ ⊢ c2 q)) ∧ (∀r b c. ?C = AnnCond2 r b c ⟶ (∃q⊆?q'. r ∩ b ⊆ pre c ∧ ⊢ c q ∧ r ∩ - b ⊆ q)) ∧ (∀r i b c. ?C = AnnWhile r b i c ⟶ (∃q⊆?q'. r ⊆ i ∧ i ∩ b ⊆ pre c ∧ ⊢ c i ∧ i ∩ - b ⊆ q)) ∧ (∀r b c. ?C = AnnAwait r b c ⟶ (∃q⊆?q'. ∥- (r ∩ b) c q))›*)) (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (fast elim: Parallel_Strong_Soundness_Seq_aux (*‹⟦interfree (?Ts::(?'a::type ann_com option × ?'a::type set) list); (?i::nat) < length ?Ts; OG_Hoare.com (?Ts ! ?i) = Some (AnnSeq (?c0.0::?'a::type ann_com) (?c1.0::?'a::type ann_com))⟧ ⟹ interfree (?Ts[?i := (Some ?c0.0, pre ?c1.0)])›*)) (*proven 2 subgoals*) . lemma Parallel_Strong_Soundness_aux_aux [rule_format]: "(Some c, b) -1→ (co, t) ⟶ (∀Ts. i<length Ts ⟶ com(Ts ! i) = Some c ⟶ (∀i<length Ts. (if com(Ts ! i) = None then b∈post(Ts!i) else b∈pre(the(com(Ts!i))) ∧ ⊢ the(com(Ts!i)) post(Ts!i))) ⟶ interfree Ts ⟶ (∀j. j<length Ts ∧ i≠j ⟶ (if com(Ts!j) = None then t∈post(Ts!j) else t∈pre(the(com(Ts!j))) ∧ ⊢ the(com(Ts!j)) post(Ts!j))) )" apply (rule ann_transition_transition.induct [THEN conjunct1] (*‹⟦⋀r f s. ?P1.1 (Some (AnnBasic r f)) s None (f s); ⋀c0 s t c1. ⟦(Some c0, s) -1→ (None, t); ?P1.1 (Some c0) s None t⟧ ⟹ ?P1.1 (Some (AnnSeq c0 c1)) s (Some c1) t; ⋀c0 s c2 t c1. ⟦(Some c0, s) -1→ (Some c2, t); ?P1.1 (Some c0) s (Some c2) t⟧ ⟹ ?P1.1 (Some (AnnSeq c0 c1)) s (Some (AnnSeq c2 c1)) t; ⋀s b r c1 c2. s ∈ b ⟹ ?P1.1 (Some (AnnCond1 r b c1 c2)) s (Some c1) s; ⋀s b r c1 c2. s ∉ b ⟹ ?P1.1 (Some (AnnCond1 r b c1 c2)) s (Some c2) s; ⋀s b r c. s ∈ b ⟹ ?P1.1 (Some (AnnCond2 r b c)) s (Some c) s; ⋀s b r c. s ∉ b ⟹ ?P1.1 (Some (AnnCond2 r b c)) s None s; ⋀s b r i c. s ∉ b ⟹ ?P1.1 (Some (AnnWhile r b i c)) s None s; ⋀s b r i c. s ∈ b ⟹ ?P1.1 (Some (AnnWhile r b i c)) s (Some (AnnSeq c (AnnWhile i b i c))) s; ⋀s b c t r. ⟦s ∈ b; atom_com c; ((c, s), Parallel [], t) ∈ (transition ∩ {(x, y). ?P2.1 x y})⇧*⟧ ⟹ ?P1.1 (Some (AnnAwait r b c)) s None t; ⋀i Ts c q s r t. ⟦i < length Ts; Ts ! i = (Some c, q); (Some c, s) -1→ (r, t); ?P1.1 (Some c) s r t⟧ ⟹ ?P2.1 (Parallel Ts, s) (Parallel (Ts[i := (r, q)]), t); ⋀f s. ?P2.1 (Basic f, s) (Parallel [], f s); ⋀Ts c s. All_None Ts ⟹ ?P2.1 (Seq (Parallel Ts) c, s) (c, s); ⋀c0 s c2 t c1. ⟦(c0, s) -P1→ (c2, t); ?P2.1 (c0, s) (c2, t)⟧ ⟹ ?P2.1 (Seq c0 c1, s) (Seq c2 c1, t); ⋀s b c1 c2. s ∈ b ⟹ ?P2.1 (Cond b c1 c2, s) (c1, s); ⋀s b c1 c2. s ∉ b ⟹ ?P2.1 (Cond b c1 c2, s) (c2, s); ⋀s b i c. s ∉ b ⟹ ?P2.1 (While b i c, s) (Parallel [], s); ⋀s b i c. s ∈ b ⟹ ?P2.1 (While b i c, s) (Seq c (While b i c), s)⟧ ⟹ (?x1.1, ?x2.1) -1→ (?x3.1, ?x4.1) ⟶ ?P1.1 ?x1.1 ?x2.1 ?x3.1 ?x4.1›*)) (*goal: ‹(Some c, b) -1→ (co, t) ⟶ (∀Ts. i < length Ts ⟶ OG_Hoare.com (Ts ! i) = Some c ⟶ (∀i<length Ts. if OG_Hoare.com (Ts ! i) = None then b ∈ OG_Hoare.post (Ts ! i) else b ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i)) ⟶ interfree Ts ⟶ (∀j. j < length Ts ∧ i ≠ j ⟶ (if OG_Hoare.com (Ts ! j) = None then t ∈ OG_Hoare.post (Ts ! j) else t ∈ pre (the (OG_Hoare.com (Ts ! j))) ∧ ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j))))›*) apply safe (*top goal: ‹⋀r f s. ∀Ts. i < length Ts ⟶ OG_Hoare.com (Ts ! i) = Some (AnnBasic r f) ⟶ (∀i<length Ts. if OG_Hoare.com (Ts ! i) = None then s ∈ OG_Hoare.post (Ts ! i) else s ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i)) ⟶ interfree Ts ⟶ (∀j. j < length Ts ∧ i ≠ j ⟶ (if OG_Hoare.com (Ts ! j) = None then f s ∈ OG_Hoare.post (Ts ! j) else f s ∈ pre (the (OG_Hoare.com (Ts ! j))) ∧ ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j)))› and 17 goals remain*) prefer 11 (*top goal: ‹⋀(ia::nat) (Ts::('a::type ann_com option × 'a::type set) list) (c::'a::type ann_com) (q::'a::type set) (s::'a::type) (r::'a::type ann_com option) t::'a::type. ⟦ia < length Ts; Ts ! ia = (Some c, q); (Some c, s) -1→ (r, t); ∀Ts::('a::type ann_com option × 'a::type set) list. (i::nat) < length Ts ⟶ OG_Hoare.com (Ts ! i) = Some c ⟶ (∀i<length Ts. if OG_Hoare.com (Ts ! i) = None then s ∈ OG_Hoare.post (Ts ! i) else s ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i)) ⟶ interfree Ts ⟶ (∀j::nat. j < length Ts ∧ i ≠ j ⟶ (if OG_Hoare.com (Ts ! j) = None then t ∈ OG_Hoare.post (Ts ! j) else t ∈ pre (the (OG_Hoare.com (Ts ! j))) ∧ ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j)))⟧ ⟹ (?P2.1::'a::type com × 'a::type ⇒ 'a::type com × 'a::type ⇒ bool) (Parallel Ts, s) (Parallel (Ts[ia := (r, q)]), t)› and 17 goals remain*) apply (rule TrueI (*‹True›*)) (*top goal: ‹⋀ia Ts c q s r t. ⟦ia < length Ts; Ts ! ia = (Some c, q); (Some c, s) -1→ (r, t); ∀Ts. i < length Ts ⟶ OG_Hoare.com (Ts ! i) = Some c ⟶ (∀i<length Ts. if OG_Hoare.com (Ts ! i) = None then s ∈ OG_Hoare.post (Ts ! i) else s ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i)) ⟶ interfree Ts ⟶ (∀j. j < length Ts ∧ i ≠ j ⟶ (if OG_Hoare.com (Ts ! j) = None then t ∈ OG_Hoare.post (Ts ! j) else t ∈ pre (the (OG_Hoare.com (Ts ! j))) ∧ ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j)))⟧ ⟹ ?P2.1 (Parallel Ts, s) (Parallel (Ts[ia := (r, q)]), t)› and 17 goals remain*) apply simp_all (*top goal: ‹⋀(r::'a::type set) (f::'a::type ⇒ 'a::type) (s::'a::type) (Ts::('a::type ann_com option × 'a::type set) list) j::nat. ⟦(i::nat) < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnBasic r f); ∀i<length Ts. if OG_Hoare.com (Ts ! i) = None then s ∈ OG_Hoare.post (Ts ! i) else s ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i); interfree Ts; j < length Ts; i ≠ j⟧ ⟹ if OG_Hoare.com (Ts ! j) = None then f s ∈ OG_Hoare.post (Ts ! j) else f s ∈ pre (the (OG_Hoare.com (Ts ! j))) ∧ ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j)› and 16 goals remain*) apply (erule_tac x = "i" in all_dupE (*‹⟦∀x. ?P x; ⟦?P ?x; ∀x. ?P x⟧ ⟹ ?R⟧ ⟹ ?R›*), erule (1) notE (*‹⟦¬ ?P; ?P⟧ ⟹ ?R›*) impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀r f s Ts j. ⟦i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnBasic r f); ∀i<length Ts. if OG_Hoare.com (Ts ! i) = None then s ∈ OG_Hoare.post (Ts ! i) else s ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i); interfree Ts; j < length Ts; i ≠ j⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ f s ∈ OG_Hoare.post (Ts ! j)) ∧ ((∃y. OG_Hoare.com (Ts ! j) = Some y) ⟶ f s ∈ pre (the (OG_Hoare.com (Ts ! j))))› and 3 goals remain*) apply (erule_tac x = "j" in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule (1) notE (*‹⟦¬ ?P; ?P⟧ ⟹ ?R›*) impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀r f s Ts j. ⟦i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnBasic r f); interfree Ts; j < length Ts; i ≠ j; ∀x<length Ts. if OG_Hoare.com (Ts ! x) = None then s ∈ OG_Hoare.post (Ts ! x) else s ∈ pre (the (OG_Hoare.com (Ts ! x))) ∧ ⊢ the (OG_Hoare.com (Ts ! x)) OG_Hoare.post (Ts ! x); if OG_Hoare.com (Ts ! i) = None then s ∈ OG_Hoare.post (Ts ! i) else s ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i)⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ f s ∈ OG_Hoare.post (Ts ! j)) ∧ ((∃y. OG_Hoare.com (Ts ! j) = Some y) ⟶ f s ∈ pre (the (OG_Hoare.com (Ts ! j))))› and 3 goals remain*) apply (simp add: interfree_def (*‹interfree ?Ts ≡ ∀i j. i < length ?Ts ∧ j < length ?Ts ∧ i ≠ j ⟶ interfree_aux (OG_Hoare.com (?Ts ! i), OG_Hoare.post (?Ts ! i), OG_Hoare.com (?Ts ! j))›*)) (*top goal: ‹⋀r f s Ts j. ⟦i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnBasic r f); interfree Ts; j < length Ts; i ≠ j; if OG_Hoare.com (Ts ! i) = None then s ∈ OG_Hoare.post (Ts ! i) else s ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i); if OG_Hoare.com (Ts ! j) = None then s ∈ OG_Hoare.post (Ts ! j) else s ∈ pre (the (OG_Hoare.com (Ts ! j))) ∧ ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j)⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ f s ∈ OG_Hoare.post (Ts ! j)) ∧ ((∃y. OG_Hoare.com (Ts ! j) = Some y) ⟶ f s ∈ pre (the (OG_Hoare.com (Ts ! j))))› and 3 goals remain*) apply (erule_tac x = "j" in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), simp) (*top goal: ‹⋀r f s Ts j. ⟦i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnBasic r f); ∀i j. i < length Ts ∧ j < length Ts ∧ i ≠ j ⟶ interfree_aux (OG_Hoare.com (Ts ! i), OG_Hoare.post (Ts ! i), OG_Hoare.com (Ts ! j)); j < length Ts; i ≠ j; s ∈ r ∧ ⊢ AnnBasic r f OG_Hoare.post (Ts ! i); if OG_Hoare.com (Ts ! j) = None then s ∈ OG_Hoare.post (Ts ! j) else s ∈ pre (the (OG_Hoare.com (Ts ! j))) ∧ ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j)⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ f s ∈ OG_Hoare.post (Ts ! j)) ∧ ((∃y. OG_Hoare.com (Ts ! j) = Some y) ⟶ f s ∈ pre (the (OG_Hoare.com (Ts ! j))))› and 3 goals remain*) apply (erule_tac x = "i" in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), simp) (*top goal: ‹⋀(r::'a set) (f::'a ⇒ 'a) (s::'a) (Ts::('a ann_com option × 'a set) list) j::nat. ⟦(i::nat) < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnBasic r f); j < length Ts; i ≠ j; s ∈ r ∧ ⊢ AnnBasic r f OG_Hoare.post (Ts ! i); if OG_Hoare.com (Ts ! j) = None then s ∈ OG_Hoare.post (Ts ! j) else s ∈ pre (the (OG_Hoare.com (Ts ! j))) ∧ ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j); ∀ja::nat. ja < length Ts ∧ j ≠ ja ⟶ interfree_aux (OG_Hoare.com (Ts ! j), OG_Hoare.post (Ts ! j), OG_Hoare.com (Ts ! ja))⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ f s ∈ OG_Hoare.post (Ts ! j)) ∧ ((∃y::'a ann_com. OG_Hoare.com (Ts ! j) = Some y) ⟶ f s ∈ pre (the (OG_Hoare.com (Ts ! j))))› and 3 goals remain*) apply (drule_tac t = "i" in not_sym (*‹?t ≠ ?s ⟹ ?s ≠ ?t›*)) (*top goal: ‹⋀r f s Ts j. ⟦i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnBasic r f); j < length Ts; i ≠ j; s ∈ r ∧ ⊢ AnnBasic r f OG_Hoare.post (Ts ! i); if OG_Hoare.com (Ts ! j) = None then s ∈ OG_Hoare.post (Ts ! j) else s ∈ pre (the (OG_Hoare.com (Ts ! j))) ∧ ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j); interfree_aux (OG_Hoare.com (Ts ! j), OG_Hoare.post (Ts ! j), Some (AnnBasic r f))⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ f s ∈ OG_Hoare.post (Ts ! j)) ∧ ((∃y. OG_Hoare.com (Ts ! j) = Some y) ⟶ f s ∈ pre (the (OG_Hoare.com (Ts ! j))))› and 3 goals remain*) apply (case_tac "com(Ts ! j)=None") (*top goal: ‹⋀r f s Ts j. ⟦i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnBasic r f); j < length Ts; s ∈ r ∧ ⊢ AnnBasic r f OG_Hoare.post (Ts ! i); if OG_Hoare.com (Ts ! j) = None then s ∈ OG_Hoare.post (Ts ! j) else s ∈ pre (the (OG_Hoare.com (Ts ! j))) ∧ ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j); interfree_aux (OG_Hoare.com (Ts ! j), OG_Hoare.post (Ts ! j), Some (AnnBasic r f)); j ≠ i⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ f s ∈ OG_Hoare.post (Ts ! j)) ∧ ((∃y. OG_Hoare.com (Ts ! j) = Some y) ⟶ f s ∈ pre (the (OG_Hoare.com (Ts ! j))))› and 3 goals remain*) apply (force intro: converse_rtrancl_into_rtrancl (*‹⟦(?a::?'a, ?b::?'a) ∈ (?r::(?'a × ?'a) set); (?b, ?c::?'a) ∈ ?r⇧*⟧ ⟹ (?a, ?c) ∈ ?r⇧*›*) simp add: interfree_aux_def (*‹interfree_aux ≡ λ(co::?'a ann_com option, q::?'a set, co'::?'a ann_com option). co' = None ∨ (∀(r::?'a set, a::?'a com)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p::?'a set∈assertions (the co). ∥= (p ∩ r) a p)))›*) com_validity_def (*‹∥= (?p::?'a set) (?c::?'a com) (?q::?'a set) ≡ SEM ?c ?p ⊆ ?q›*) SEM_def (*‹SEM (?c::?'a com) (?S::?'a set) ≡ ⋃ (sem ?c ` ?S)›*) sem_def (*‹sem (?c::?'a com) ≡ λs::?'a. {t::?'a. ∃Ts::(?'a ann_com option × ?'a set) list. (?c, s) -P*→ (Parallel Ts, t) ∧ All_None Ts}›*) All_None_def (*‹All_None (?Ts::(?'a ann_com option × ?'a set) list) ≡ ∀(c::?'a ann_com option, q::?'a set)∈set ?Ts. c = None›*)) (*top goal: ‹⋀(r::'a set) (f::'a ⇒ 'a) (s::'a) (Ts::('a ann_com option × 'a set) list) j::nat. ⟦(i::nat) < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnBasic r f); j < length Ts; s ∈ r ∧ ⊢ AnnBasic r f OG_Hoare.post (Ts ! i); if OG_Hoare.com (Ts ! j) = None then s ∈ OG_Hoare.post (Ts ! j) else s ∈ pre (the (OG_Hoare.com (Ts ! j))) ∧ ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j); interfree_aux (OG_Hoare.com (Ts ! j), OG_Hoare.post (Ts ! j), Some (AnnBasic r f)); j ≠ i; OG_Hoare.com (Ts ! j) = None⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ f s ∈ OG_Hoare.post (Ts ! j)) ∧ ((∃y::'a ann_com. OG_Hoare.com (Ts ! j) = Some y) ⟶ f s ∈ pre (the (OG_Hoare.com (Ts ! j))))› and 4 goals remain*) apply (simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co::?'a ann_com option, q::?'a set, co'::?'a ann_com option). co' = None ∨ (∀(r::?'a set, a::?'a com)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p::?'a set∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*top goal: ‹⋀r f s Ts j. ⟦i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnBasic r f); j < length Ts; s ∈ r ∧ ⊢ AnnBasic r f OG_Hoare.post (Ts ! i); if OG_Hoare.com (Ts ! j) = None then s ∈ OG_Hoare.post (Ts ! j) else s ∈ pre (the (OG_Hoare.com (Ts ! j))) ∧ ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j); interfree_aux (OG_Hoare.com (Ts ! j), OG_Hoare.post (Ts ! j), Some (AnnBasic r f)); j ≠ i; OG_Hoare.com (Ts ! j) ≠ None⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ f s ∈ OG_Hoare.post (Ts ! j)) ∧ ((∃y. OG_Hoare.com (Ts ! j) = Some y) ⟶ f s ∈ pre (the (OG_Hoare.com (Ts ! j))))› and 3 goals remain*) apply clarify (*top goal: ‹⋀r f s Ts j. ⟦i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnBasic r f); j < length Ts; s ∈ r ∧ ⊢ AnnBasic r f OG_Hoare.post (Ts ! i); s ∈ pre (the (OG_Hoare.com (Ts ! j))) ∧ ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j); ∥= (OG_Hoare.post (Ts ! j) ∩ r) Basic f OG_Hoare.post (Ts ! j) ∧ (∀p∈assertions (the (OG_Hoare.com (Ts ! j))). ∥= (p ∩ r) Basic f p); j ≠ i; ∃y. OG_Hoare.com (Ts ! j) = Some y⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ f s ∈ OG_Hoare.post (Ts ! j)) ∧ f s ∈ pre (the (OG_Hoare.com (Ts ! j)))› and 3 goals remain*) apply simp (*top goal: ‹⋀r f s Ts j y. ⟦i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnBasic r f); j < length Ts; j ≠ i; OG_Hoare.com (Ts ! j) = Some y; s ∈ r; ⊢ AnnBasic r f OG_Hoare.post (Ts ! i); s ∈ pre (the (OG_Hoare.com (Ts ! j))); ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j); ∥= (OG_Hoare.post (Ts ! j) ∩ r) Basic f OG_Hoare.post (Ts ! j); ∀p∈assertions (the (OG_Hoare.com (Ts ! j))). ∥= (p ∩ r) Basic f p⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ f s ∈ OG_Hoare.post (Ts ! j)) ∧ f s ∈ pre (the (OG_Hoare.com (Ts ! j)))› and 3 goals remain*) apply (erule_tac x="pre y" in ballE (*‹⟦∀x∈?A. ?P x; ?P ?x ⟹ ?Q; ?x ∉ ?A ⟹ ?Q⟧ ⟹ ?Q›*)) (*top goal: ‹⋀(r::'a set) (f::'a ⇒ 'a) (s::'a) (Ts::('a ann_com option × 'a set) list) (j::nat) y::'a ann_com. ⟦(i::nat) < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnBasic r f); j < length Ts; j ≠ i; OG_Hoare.com (Ts ! j) = Some y; s ∈ r; ⊢ AnnBasic r f OG_Hoare.post (Ts ! i); s ∈ pre y; ⊢ y OG_Hoare.post (Ts ! j); ∥= (OG_Hoare.post (Ts ! j) ∩ r) Basic f OG_Hoare.post (Ts ! j); ∀p::'a set∈assertions y. ∥= (p ∩ r) Basic f p⟧ ⟹ f s ∈ pre y› and 3 goals remain*) apply (force intro: converse_rtrancl_into_rtrancl (*‹⟦(?a, ?b) ∈ ?r; (?b, ?c) ∈ ?r⇧*⟧ ⟹ (?a, ?c) ∈ ?r⇧*›*) simp add: com_validity_def (*‹∥= ?p ?c ?q ≡ SEM ?c ?p ⊆ ?q›*) SEM_def (*‹SEM ?c ?S ≡ ⋃ (sem ?c ` ?S)›*) sem_def (*‹sem ?c ≡ λs. {t. ∃Ts. (?c, s) -P*→ (Parallel Ts, t) ∧ All_None Ts}›*) All_None_def (*‹All_None ?Ts ≡ ∀(c, q)∈set ?Ts. c = None›*)) (*top goal: ‹⋀r f s Ts j y. ⟦i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnBasic r f); j < length Ts; j ≠ i; OG_Hoare.com (Ts ! j) = Some y; s ∈ r; ⊢ AnnBasic r f OG_Hoare.post (Ts ! i); s ∈ pre y; ⊢ y OG_Hoare.post (Ts ! j); ∥= (OG_Hoare.post (Ts ! j) ∩ r) Basic f OG_Hoare.post (Ts ! j); ∥= (pre y ∩ r) Basic f pre y⟧ ⟹ f s ∈ pre y› and 4 goals remain*) apply (simp add:assertions_lemma (*‹pre ?c ∈ assertions ?c›*)) (*top goal: ‹⋀(r::'a set) (f::'a ⇒ 'a) (s::'a) (Ts::('a ann_com option × 'a set) list) (j::nat) y::'a ann_com. ⟦(i::nat) < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnBasic r f); j < length Ts; j ≠ i; OG_Hoare.com (Ts ! j) = Some y; s ∈ r; ⊢ AnnBasic r f OG_Hoare.post (Ts ! i); s ∈ pre y; ⊢ y OG_Hoare.post (Ts ! j); ∥= (OG_Hoare.post (Ts ! j) ∩ r) Basic f OG_Hoare.post (Ts ! j); pre y ∉ assertions y⟧ ⟹ f s ∈ pre y› and 3 goals remain*) apply (erule_tac x = "Ts[i:=(Some c0, pre c1)]" in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀c0 s t c1 Ts j. ⟦(Some c0, s) -1→ (None, t); ∀Ts. i < length Ts ⟶ OG_Hoare.com (Ts ! i) = Some c0 ⟶ (∀i<length Ts. if OG_Hoare.com (Ts ! i) = None then s ∈ OG_Hoare.post (Ts ! i) else s ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i)) ⟶ interfree Ts ⟶ (∀j. j < length Ts ∧ i ≠ j ⟶ (if OG_Hoare.com (Ts ! j) = None then t ∈ OG_Hoare.post (Ts ! j) else t ∈ pre (the (OG_Hoare.com (Ts ! j))) ∧ ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j))); i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnSeq c0 c1); ∀i<length Ts. if OG_Hoare.com (Ts ! i) = None then s ∈ OG_Hoare.post (Ts ! i) else s ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i); interfree Ts; j < length Ts; i ≠ j⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ t ∈ OG_Hoare.post (Ts ! j)) ∧ ((∃y. OG_Hoare.com (Ts ! j) = Some y) ⟶ t ∈ pre (the (OG_Hoare.com (Ts ! j))))› and 2 goals remain*) apply (drule Parallel_Strong_Soundness_Seq (*‹⟦∀i<length ?Ts. if OG_Hoare.com (?Ts ! i) = None then ?b ∈ OG_Hoare.post (?Ts ! i) else ?b ∈ pre (the (OG_Hoare.com (?Ts ! i))) ∧ ⊢ the (OG_Hoare.com (?Ts ! i)) OG_Hoare.post (?Ts ! i); OG_Hoare.com (?Ts ! ?i) = Some (AnnSeq ?c0.0 ?c1.0); ?i < length ?Ts; interfree ?Ts⟧ ⟹ (∀ia<length ?Ts. if OG_Hoare.com (?Ts[?i := (Some ?c0.0, pre ?c1.0)] ! ia) = None then ?b ∈ OG_Hoare.post (?Ts[?i := (Some ?c0.0, pre ?c1.0)] ! ia) else ?b ∈ pre (the (OG_Hoare.com (?Ts[?i := (Some ?c0.0, pre ?c1.0)] ! ia))) ∧ ⊢ the (OG_Hoare.com (?Ts[?i := (Some ?c0.0, pre ?c1.0)] ! ia)) OG_Hoare.post (?Ts[?i := (Some ?c0.0, pre ?c1.0)] ! ia)) ∧ interfree (?Ts[?i := (Some ?c0.0, pre ?c1.0)])›*), (simp)+) (*top goal: ‹⋀(c0::'a::type ann_com) (s::'a::type) (t::'a::type) (c1::'a::type ann_com) (Ts::('a::type ann_com option × 'a::type set) list) j::nat. ⟦(Some c0, s) -1→ (None, t); (i::nat) < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnSeq c0 c1); ∀i<length Ts. if OG_Hoare.com (Ts ! i) = None then s ∈ OG_Hoare.post (Ts ! i) else s ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i); interfree Ts; j < length Ts; i ≠ j; i < length (Ts[i := (Some c0, pre c1)]) ⟶ OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! i) = Some c0 ⟶ (∀ia<length (Ts[i := (Some c0, pre c1)]). if OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia) = None then s ∈ OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! ia) else s ∈ pre (the (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia))) ∧ ⊢ the (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia)) OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! ia)) ⟶ interfree (Ts[i := (Some c0, pre c1)]) ⟶ (∀j::nat. j < length (Ts[i := (Some c0, pre c1)]) ∧ i ≠ j ⟶ (if OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! j) = None then t ∈ OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! j) else t ∈ pre (the (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! j))) ∧ ⊢ the (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! j)) OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! j)))⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ t ∈ OG_Hoare.post (Ts ! j)) ∧ ((∃y::'a::type ann_com. OG_Hoare.com (Ts ! j) = Some y) ⟶ t ∈ pre (the (OG_Hoare.com (Ts ! j))))› and 2 goals remain*) apply (erule_tac x = "Ts[i:=(Some c0, pre c1)]" in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀c0 s c2 t c1 Ts j. ⟦(Some c0, s) -1→ (Some c2, t); ∀Ts. i < length Ts ⟶ OG_Hoare.com (Ts ! i) = Some c0 ⟶ (∀i<length Ts. if OG_Hoare.com (Ts ! i) = None then s ∈ OG_Hoare.post (Ts ! i) else s ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i)) ⟶ interfree Ts ⟶ (∀j. j < length Ts ∧ i ≠ j ⟶ (if OG_Hoare.com (Ts ! j) = None then t ∈ OG_Hoare.post (Ts ! j) else t ∈ pre (the (OG_Hoare.com (Ts ! j))) ∧ ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j))); i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnSeq c0 c1); ∀i<length Ts. if OG_Hoare.com (Ts ! i) = None then s ∈ OG_Hoare.post (Ts ! i) else s ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i); interfree Ts; j < length Ts; i ≠ j⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ t ∈ OG_Hoare.post (Ts ! j)) ∧ ((∃y. OG_Hoare.com (Ts ! j) = Some y) ⟶ t ∈ pre (the (OG_Hoare.com (Ts ! j))))› and 1 goal remains*) apply (drule Parallel_Strong_Soundness_Seq (*‹⟦∀i<length ?Ts. if OG_Hoare.com (?Ts ! i) = None then ?b ∈ OG_Hoare.post (?Ts ! i) else ?b ∈ pre (the (OG_Hoare.com (?Ts ! i))) ∧ ⊢ the (OG_Hoare.com (?Ts ! i)) OG_Hoare.post (?Ts ! i); OG_Hoare.com (?Ts ! ?i) = Some (AnnSeq ?c0.0 ?c1.0); ?i < length ?Ts; interfree ?Ts⟧ ⟹ (∀ia<length ?Ts. if OG_Hoare.com (?Ts[?i := (Some ?c0.0, pre ?c1.0)] ! ia) = None then ?b ∈ OG_Hoare.post (?Ts[?i := (Some ?c0.0, pre ?c1.0)] ! ia) else ?b ∈ pre (the (OG_Hoare.com (?Ts[?i := (Some ?c0.0, pre ?c1.0)] ! ia))) ∧ ⊢ the (OG_Hoare.com (?Ts[?i := (Some ?c0.0, pre ?c1.0)] ! ia)) OG_Hoare.post (?Ts[?i := (Some ?c0.0, pre ?c1.0)] ! ia)) ∧ interfree (?Ts[?i := (Some ?c0.0, pre ?c1.0)])›*), (simp)+) (*top goal: ‹⋀c0 s c2 t c1 Ts j. ⟦(Some c0, s) -1→ (Some c2, t); i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnSeq c0 c1); ∀i<length Ts. if OG_Hoare.com (Ts ! i) = None then s ∈ OG_Hoare.post (Ts ! i) else s ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i); interfree Ts; j < length Ts; i ≠ j; i < length (Ts[i := (Some c0, pre c1)]) ⟶ OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! i) = Some c0 ⟶ (∀ia<length (Ts[i := (Some c0, pre c1)]). if OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia) = None then s ∈ OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! ia) else s ∈ pre (the (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia))) ∧ ⊢ the (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! ia)) OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! ia)) ⟶ interfree (Ts[i := (Some c0, pre c1)]) ⟶ (∀j. j < length (Ts[i := (Some c0, pre c1)]) ∧ i ≠ j ⟶ (if OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! j) = None then t ∈ OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! j) else t ∈ pre (the (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! j))) ∧ ⊢ the (OG_Hoare.com (Ts[i := (Some c0, pre c1)] ! j)) OG_Hoare.post (Ts[i := (Some c0, pre c1)] ! j)))⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ t ∈ OG_Hoare.post (Ts ! j)) ∧ ((∃y. OG_Hoare.com (Ts ! j) = Some y) ⟶ t ∈ pre (the (OG_Hoare.com (Ts ! j))))› and 1 goal remains*) apply (rule_tac x = "i" in allE (*‹⟦∀x::?'a. (?P::?'a ⇒ bool) x; ?P (?x::?'a) ⟹ ?R::bool⟧ ⟹ ?R›*), assumption, erule (1) notE (*‹⟦¬ ?P; ?P⟧ ⟹ ?R›*) impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goal: ‹⋀s b c t r Ts j. ⟦s ∈ b; atom_com c; (c, s) -P*→ (Parallel [], t); i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnAwait r b c); ∀i<length Ts. if OG_Hoare.com (Ts ! i) = None then s ∈ OG_Hoare.post (Ts ! i) else s ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i); interfree Ts; j < length Ts; i ≠ j⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ t ∈ OG_Hoare.post (Ts ! j)) ∧ ((∃y. OG_Hoare.com (Ts ! j) = Some y) ⟶ t ∈ pre (the (OG_Hoare.com (Ts ! j))))›*) apply (erule_tac x = "j" in allE (*‹⟦∀x::?'a. (?P::?'a ⇒ bool) x; ?P (?x::?'a) ⟹ ?R::bool⟧ ⟹ ?R›*), erule (1) notE (*‹⟦¬ ?P; ?P⟧ ⟹ ?R›*) impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goal: ‹⋀s b c t r Ts j. ⟦s ∈ b; atom_com c; (c, s) -P*→ (Parallel [], t); i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnAwait r b c); ∀i<length Ts. if OG_Hoare.com (Ts ! i) = None then s ∈ OG_Hoare.post (Ts ! i) else s ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i); interfree Ts; j < length Ts; i ≠ j; if OG_Hoare.com (Ts ! i) = None then s ∈ OG_Hoare.post (Ts ! i) else s ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i)⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ t ∈ OG_Hoare.post (Ts ! j)) ∧ ((∃y. OG_Hoare.com (Ts ! j) = Some y) ⟶ t ∈ pre (the (OG_Hoare.com (Ts ! j))))›*) apply (simp add: interfree_def (*‹interfree ?Ts ≡ ∀i j. i < length ?Ts ∧ j < length ?Ts ∧ i ≠ j ⟶ interfree_aux (OG_Hoare.com (?Ts ! i), OG_Hoare.post (?Ts ! i), OG_Hoare.com (?Ts ! j))›*)) (*goal: ‹⋀s b c t r Ts j. ⟦s ∈ b; atom_com c; (c, s) -P*→ (Parallel [], t); i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnAwait r b c); interfree Ts; j < length Ts; i ≠ j; if OG_Hoare.com (Ts ! i) = None then s ∈ OG_Hoare.post (Ts ! i) else s ∈ pre (the (OG_Hoare.com (Ts ! i))) ∧ ⊢ the (OG_Hoare.com (Ts ! i)) OG_Hoare.post (Ts ! i); if OG_Hoare.com (Ts ! j) = None then s ∈ OG_Hoare.post (Ts ! j) else s ∈ pre (the (OG_Hoare.com (Ts ! j))) ∧ ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j)⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ t ∈ OG_Hoare.post (Ts ! j)) ∧ ((∃y. OG_Hoare.com (Ts ! j) = Some y) ⟶ t ∈ pre (the (OG_Hoare.com (Ts ! j))))›*) apply (erule_tac x = "j" in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), simp) (*goal: ‹⋀s b c t r Ts j. ⟦s ∈ b; atom_com c; (c, s) -P*→ (Parallel [], t); i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnAwait r b c); ∀i j. i < length Ts ∧ j < length Ts ∧ i ≠ j ⟶ interfree_aux (OG_Hoare.com (Ts ! i), OG_Hoare.post (Ts ! i), OG_Hoare.com (Ts ! j)); j < length Ts; i ≠ j; s ∈ r ∧ ⊢ AnnAwait r b c OG_Hoare.post (Ts ! i); if OG_Hoare.com (Ts ! j) = None then s ∈ OG_Hoare.post (Ts ! j) else s ∈ pre (the (OG_Hoare.com (Ts ! j))) ∧ ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j)⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ t ∈ OG_Hoare.post (Ts ! j)) ∧ ((∃y. OG_Hoare.com (Ts ! j) = Some y) ⟶ t ∈ pre (the (OG_Hoare.com (Ts ! j))))›*) apply (erule_tac x = "i" in allE (*‹⟦∀x::?'a. (?P::?'a ⇒ bool) x; ?P (?x::?'a) ⟹ ?R::bool⟧ ⟹ ?R›*), simp) (*goal: ‹⋀s b c t r Ts j. ⟦s ∈ b; atom_com c; (c, s) -P*→ (Parallel [], t); i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnAwait r b c); j < length Ts; i ≠ j; s ∈ r ∧ ⊢ AnnAwait r b c OG_Hoare.post (Ts ! i); if OG_Hoare.com (Ts ! j) = None then s ∈ OG_Hoare.post (Ts ! j) else s ∈ pre (the (OG_Hoare.com (Ts ! j))) ∧ ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j); ∀ja. ja < length Ts ∧ j ≠ ja ⟶ interfree_aux (OG_Hoare.com (Ts ! j), OG_Hoare.post (Ts ! j), OG_Hoare.com (Ts ! ja))⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ t ∈ OG_Hoare.post (Ts ! j)) ∧ ((∃y. OG_Hoare.com (Ts ! j) = Some y) ⟶ t ∈ pre (the (OG_Hoare.com (Ts ! j))))›*) apply (drule_tac t = "i" in not_sym (*‹?t ≠ ?s ⟹ ?s ≠ ?t›*)) (*goal: ‹⋀s b c t r Ts j. ⟦s ∈ b; atom_com c; (c, s) -P*→ (Parallel [], t); i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnAwait r b c); j < length Ts; i ≠ j; s ∈ r ∧ ⊢ AnnAwait r b c OG_Hoare.post (Ts ! i); if OG_Hoare.com (Ts ! j) = None then s ∈ OG_Hoare.post (Ts ! j) else s ∈ pre (the (OG_Hoare.com (Ts ! j))) ∧ ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j); interfree_aux (OG_Hoare.com (Ts ! j), OG_Hoare.post (Ts ! j), Some (AnnAwait r b c))⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ t ∈ OG_Hoare.post (Ts ! j)) ∧ ((∃y. OG_Hoare.com (Ts ! j) = Some y) ⟶ t ∈ pre (the (OG_Hoare.com (Ts ! j))))›*) apply (case_tac "com(Ts ! j)=None") (*goal: ‹⋀(s::'a::type) (b::'a::type set) (c::'a::type com) (t::'a::type) (r::'a::type set) (Ts::('a::type ann_com option × 'a::type set) list) j::nat. ⟦s ∈ b; atom_com c; (c, s) -P*→ (Parallel [], t); (i::nat) < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnAwait r b c); j < length Ts; s ∈ r ∧ ⊢ AnnAwait r b c OG_Hoare.post (Ts ! i); if OG_Hoare.com (Ts ! j) = None then s ∈ OG_Hoare.post (Ts ! j) else s ∈ pre (the (OG_Hoare.com (Ts ! j))) ∧ ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j); interfree_aux (OG_Hoare.com (Ts ! j), OG_Hoare.post (Ts ! j), Some (AnnAwait r b c)); j ≠ i⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ t ∈ OG_Hoare.post (Ts ! j)) ∧ ((∃y::'a::type ann_com. OG_Hoare.com (Ts ! j) = Some y) ⟶ t ∈ pre (the (OG_Hoare.com (Ts ! j))))›*) apply (force intro: converse_rtrancl_into_rtrancl (*‹⟦(?a, ?b) ∈ ?r; (?b, ?c) ∈ ?r⇧*⟧ ⟹ (?a, ?c) ∈ ?r⇧*›*) simp add: interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*) com_validity_def (*‹∥= ?p ?c ?q ≡ SEM ?c ?p ⊆ ?q›*) SEM_def (*‹SEM ?c ?S ≡ ⋃ (sem ?c ` ?S)›*) sem_def (*‹sem ?c ≡ λs. {t. ∃Ts. (?c, s) -P*→ (Parallel Ts, t) ∧ All_None Ts}›*) All_None_def (*‹All_None ?Ts ≡ ∀(c, q)∈set ?Ts. c = None›*) Help (*‹transition ∩ {(x, y). True} = transition›*)) (*top goal: ‹⋀s b c t r Ts j. ⟦s ∈ b; atom_com c; (c, s) -P*→ (Parallel [], t); i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnAwait r b c); j < length Ts; s ∈ r ∧ ⊢ AnnAwait r b c OG_Hoare.post (Ts ! i); if OG_Hoare.com (Ts ! j) = None then s ∈ OG_Hoare.post (Ts ! j) else s ∈ pre (the (OG_Hoare.com (Ts ! j))) ∧ ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j); interfree_aux (OG_Hoare.com (Ts ! j), OG_Hoare.post (Ts ! j), Some (AnnAwait r b c)); j ≠ i; OG_Hoare.com (Ts ! j) = None⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ t ∈ OG_Hoare.post (Ts ! j)) ∧ ((∃y. OG_Hoare.com (Ts ! j) = Some y) ⟶ t ∈ pre (the (OG_Hoare.com (Ts ! j))))› and 1 goal remains*) apply (simp add:interfree_aux_def (*‹interfree_aux ≡ λ(co, q, co'). co' = None ∨ (∀(r, a)∈atomics (the co'). ∥= (q ∩ r) a q ∧ (co = None ∨ (∀p∈assertions (the co). ∥= (p ∩ r) a p)))›*)) (*goal: ‹⋀s b c t r Ts j. ⟦s ∈ b; atom_com c; (c, s) -P*→ (Parallel [], t); i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnAwait r b c); j < length Ts; s ∈ r ∧ ⊢ AnnAwait r b c OG_Hoare.post (Ts ! i); if OG_Hoare.com (Ts ! j) = None then s ∈ OG_Hoare.post (Ts ! j) else s ∈ pre (the (OG_Hoare.com (Ts ! j))) ∧ ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j); interfree_aux (OG_Hoare.com (Ts ! j), OG_Hoare.post (Ts ! j), Some (AnnAwait r b c)); j ≠ i; OG_Hoare.com (Ts ! j) ≠ None⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ t ∈ OG_Hoare.post (Ts ! j)) ∧ ((∃y. OG_Hoare.com (Ts ! j) = Some y) ⟶ t ∈ pre (the (OG_Hoare.com (Ts ! j))))›*) apply clarify (*goal: ‹⋀s b c t r Ts j. ⟦s ∈ b; atom_com c; (c, s) -P*→ (Parallel [], t); i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnAwait r b c); j < length Ts; s ∈ r ∧ ⊢ AnnAwait r b c OG_Hoare.post (Ts ! i); s ∈ pre (the (OG_Hoare.com (Ts ! j))) ∧ ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j); ∥= (OG_Hoare.post (Ts ! j) ∩ (r ∩ b)) c OG_Hoare.post (Ts ! j) ∧ (∀p∈assertions (the (OG_Hoare.com (Ts ! j))). ∥= (p ∩ (r ∩ b)) c p); j ≠ i; ∃y. OG_Hoare.com (Ts ! j) = Some y⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ t ∈ OG_Hoare.post (Ts ! j)) ∧ t ∈ pre (the (OG_Hoare.com (Ts ! j)))›*) apply simp (*goal: ‹⋀s b c t r Ts j y. ⟦s ∈ b; atom_com c; (c, s) -P*→ (Parallel [], t); i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnAwait r b c); j < length Ts; j ≠ i; OG_Hoare.com (Ts ! j) = Some y; s ∈ r; ⊢ AnnAwait r b c OG_Hoare.post (Ts ! i); s ∈ pre (the (OG_Hoare.com (Ts ! j))); ⊢ the (OG_Hoare.com (Ts ! j)) OG_Hoare.post (Ts ! j); ∥= (OG_Hoare.post (Ts ! j) ∩ (r ∩ b)) c OG_Hoare.post (Ts ! j); ∀p∈assertions (the (OG_Hoare.com (Ts ! j))). ∥= (p ∩ (r ∩ b)) c p⟧ ⟹ (OG_Hoare.com (Ts ! j) = None ⟶ t ∈ OG_Hoare.post (Ts ! j)) ∧ t ∈ pre (the (OG_Hoare.com (Ts ! j)))›*) apply (erule_tac x="pre y" in ballE (*‹⟦∀x∈?A. ?P x; ?P ?x ⟹ ?Q; ?x ∉ ?A ⟹ ?Q⟧ ⟹ ?Q›*)) (*goal: ‹⋀s b c t r Ts j y. ⟦s ∈ b; atom_com c; (c, s) -P*→ (Parallel [], t); i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnAwait r b c); j < length Ts; j ≠ i; OG_Hoare.com (Ts ! j) = Some y; s ∈ r; ⊢ AnnAwait r b c OG_Hoare.post (Ts ! i); s ∈ pre y; ⊢ y OG_Hoare.post (Ts ! j); ∥= (OG_Hoare.post (Ts ! j) ∩ (r ∩ b)) c OG_Hoare.post (Ts ! j); ∀p∈assertions y. ∥= (p ∩ (r ∩ b)) c p⟧ ⟹ t ∈ pre y›*) apply (force intro: converse_rtrancl_into_rtrancl (*‹⟦(?a, ?b) ∈ ?r; (?b, ?c) ∈ ?r⇧*⟧ ⟹ (?a, ?c) ∈ ?r⇧*›*) simp add: com_validity_def (*‹∥= ?p ?c ?q ≡ SEM ?c ?p ⊆ ?q›*) SEM_def (*‹SEM ?c ?S ≡ ⋃ (sem ?c ` ?S)›*) sem_def (*‹sem ?c ≡ λs. {t. ∃Ts. (?c, s) -P*→ (Parallel Ts, t) ∧ All_None Ts}›*) All_None_def (*‹All_None ?Ts ≡ ∀(c, q)∈set ?Ts. c = None›*) Help (*‹transition ∩ {(x, y). True} = transition›*)) (*top goal: ‹⋀s b c t r Ts j y. ⟦s ∈ b; atom_com c; (c, s) -P*→ (Parallel [], t); i < length Ts; OG_Hoare.com (Ts ! i) = Some (AnnAwait r b c); j < length Ts; j ≠ i; OG_Hoare.com (Ts ! j) = Some y; s ∈ r; ⊢ AnnAwait r b c OG_Hoare.post (Ts ! i); s ∈ pre y; ⊢ y OG_Hoare.post (Ts ! j); ∥= (OG_Hoare.post (Ts ! j) ∩ (r ∩ b)) c OG_Hoare.post (Ts ! j); ∥= (pre y ∩ (r ∩ b)) c pre y⟧ ⟹ t ∈ pre y› and 1 goal remains*) by (simp add:assertions_lemma (*‹pre ?c ∈ assertions ?c›*)) lemma Parallel_Strong_Soundness_aux [rule_format]: "⟦(Ts',s) -P*→ (Rs',t); Ts' = (Parallel Ts); interfree Ts; ∀i. i<length Ts ⟶ (∃c q. (Ts ! i) = (Some c, q) ∧ s∈(pre c) ∧ ⊢ c q ) ⟧ ⟹ ∀Rs. Rs' = (Parallel Rs) ⟶ (∀j. j<length Rs ⟶ (if com(Rs ! j) = None then t∈post(Ts ! j) else t∈pre(the(com(Rs ! j))) ∧ ⊢ the(com(Rs ! j)) post(Ts ! j))) ∧ interfree Rs" apply (erule rtrancl_induct2 (*‹⟦((?ax, ?ay), ?bx, ?by) ∈ ?r⇧*; ?P ?ax ?ay; ⋀a b aa ba. ⟦((?ax, ?ay), a, b) ∈ ?r⇧*; ((a, b), aa, ba) ∈ ?r; ?P a b⟧ ⟹ ?P aa ba⟧ ⟹ ?P ?bx ?by›*)) (*goals: 1. ‹⟦Ts' = Parallel Ts; interfree Ts; ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q⟧ ⟹ ∀Rs. Ts' = Parallel Rs ⟶ (∀j<length Rs. if OG_Hoare.com (Rs ! j) = None then s ∈ OG_Hoare.post (Ts ! j) else s ∈ pre (the (OG_Hoare.com (Rs ! j))) ∧ ⊢ the (OG_Hoare.com (Rs ! j)) OG_Hoare.post (Ts ! j)) ∧ interfree Rs› 2. ‹⋀a b aa ba. ⟦Ts' = Parallel Ts; interfree Ts; ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q; (Ts', s) -P*→ (a, b); (a, b) -P1→ (aa, ba); ∀Rs. a = Parallel Rs ⟶ (∀j<length Rs. if OG_Hoare.com (Rs ! j) = None then b ∈ OG_Hoare.post (Ts ! j) else b ∈ pre (the (OG_Hoare.com (Rs ! j))) ∧ ⊢ the (OG_Hoare.com (Rs ! j)) OG_Hoare.post (Ts ! j)) ∧ interfree Rs⟧ ⟹ ∀Rs. aa = Parallel Rs ⟶ (∀j<length Rs. if OG_Hoare.com (Rs ! j) = None then ba ∈ OG_Hoare.post (Ts ! j) else ba ∈ pre (the (OG_Hoare.com (Rs ! j))) ∧ ⊢ the (OG_Hoare.com (Rs ! j)) OG_Hoare.post (Ts ! j)) ∧ interfree Rs› discuss goal 1*) apply clarify (*top goal: ‹⟦Ts' = Parallel Ts; interfree Ts; ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q⟧ ⟹ ∀Rs. Ts' = Parallel Rs ⟶ (∀j<length Rs. if OG_Hoare.com (Rs ! j) = None then s ∈ OG_Hoare.post (Ts ! j) else s ∈ pre (the (OG_Hoare.com (Rs ! j))) ∧ ⊢ the (OG_Hoare.com (Rs ! j)) OG_Hoare.post (Ts ! j)) ∧ interfree Rs› and 1 goal remains*) apply force (*discuss goal 2*) apply clarify (*goal: ‹⋀a b aa ba. ⟦Ts' = Parallel Ts; interfree Ts; ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q; (Ts', s) -P*→ (a, b); (a, b) -P1→ (aa, ba); ∀Rs. a = Parallel Rs ⟶ (∀j<length Rs. if OG_Hoare.com (Rs ! j) = None then b ∈ OG_Hoare.post (Ts ! j) else b ∈ pre (the (OG_Hoare.com (Rs ! j))) ∧ ⊢ the (OG_Hoare.com (Rs ! j)) OG_Hoare.post (Ts ! j)) ∧ interfree Rs⟧ ⟹ ∀Rs. aa = Parallel Rs ⟶ (∀j<length Rs. if OG_Hoare.com (Rs ! j) = None then ba ∈ OG_Hoare.post (Ts ! j) else ba ∈ pre (the (OG_Hoare.com (Rs ! j))) ∧ ⊢ the (OG_Hoare.com (Rs ! j)) OG_Hoare.post (Ts ! j)) ∧ interfree Rs›*) apply (drule Parallel_length_post_PStar (*‹(Parallel ?Ts, ?s) -P*→ (?R', ?t) ⟹ ∃Rs. ?R' = Parallel Rs ∧ length Rs = length ?Ts ∧ (∀i<length ?Ts. OG_Hoare.post (?Ts ! i) = OG_Hoare.post (Rs ! i))›*)) (*goal: ‹⋀a b aa ba Rs. ⟦interfree Ts; ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q; (Parallel Ts, s) -P*→ (a, b); (a, b) -P1→ (Parallel Rs, ba); ∀Rs. a = Parallel Rs ⟶ (∀j<length Rs. if OG_Hoare.com (Rs ! j) = None then b ∈ OG_Hoare.post (Ts ! j) else b ∈ pre (the (OG_Hoare.com (Rs ! j))) ∧ ⊢ the (OG_Hoare.com (Rs ! j)) OG_Hoare.post (Ts ! j)) ∧ interfree Rs; Ts' = Parallel Ts⟧ ⟹ (∀j<length Rs. if OG_Hoare.com (Rs ! j) = None then ba ∈ OG_Hoare.post (Ts ! j) else ba ∈ pre (the (OG_Hoare.com (Rs ! j))) ∧ ⊢ the (OG_Hoare.com (Rs ! j)) OG_Hoare.post (Ts ! j)) ∧ interfree Rs›*) apply clarify (*goal: ‹⋀a b aa ba Rs. ⟦interfree Ts; ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q; (a, b) -P1→ (Parallel Rs, ba); ∀Rs. a = Parallel Rs ⟶ (∀j<length Rs. if OG_Hoare.com (Rs ! j) = None then b ∈ OG_Hoare.post (Ts ! j) else b ∈ pre (the (OG_Hoare.com (Rs ! j))) ∧ ⊢ the (OG_Hoare.com (Rs ! j)) OG_Hoare.post (Ts ! j)) ∧ interfree Rs; Ts' = Parallel Ts; ∃Rs. a = Parallel Rs ∧ length Rs = length Ts ∧ (∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rs ! i))⟧ ⟹ (∀j<length Rs. if OG_Hoare.com (Rs ! j) = None then ba ∈ OG_Hoare.post (Ts ! j) else ba ∈ pre (the (OG_Hoare.com (Rs ! j))) ∧ ⊢ the (OG_Hoare.com (Rs ! j)) OG_Hoare.post (Ts ! j)) ∧ interfree Rs›*) apply (ind_cases "(Parallel Ts, s) -P1→ (Parallel Rs, t)" for Ts s Rs t) (*goal: ‹⋀(a::'a com) (b::'a) (aa::'a com) (ba::'a) (Rs::('a ann_com option × 'a set) list) Rsa::('a ann_com option × 'a set) list. ⟦interfree (Ts::('a ann_com option × 'a set) list); ∀i<length Ts. ∃(c::'a ann_com) q::'a set. Ts ! i = (Some c, q) ∧ (s::'a) ∈ pre c ∧ ⊢ c q; (Parallel Rsa, b) -P1→ (Parallel Rs, ba); ∀Rs::('a ann_com option × 'a set) list. Parallel Rsa = Parallel Rs ⟶ (∀j<length Rs. if OG_Hoare.com (Rs ! j) = None then b ∈ OG_Hoare.post (Ts ! j) else b ∈ pre (the (OG_Hoare.com (Rs ! j))) ∧ ⊢ the (OG_Hoare.com (Rs ! j)) OG_Hoare.post (Ts ! j)) ∧ interfree Rs; (Ts'::'a com) = Parallel Ts; length Rsa = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rsa ! i)⟧ ⟹ (∀j<length Rs. if OG_Hoare.com (Rs ! j) = None then ba ∈ OG_Hoare.post (Ts ! j) else ba ∈ pre (the (OG_Hoare.com (Rs ! j))) ∧ ⊢ the (OG_Hoare.com (Rs ! j)) OG_Hoare.post (Ts ! j)) ∧ interfree Rs›*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹⋀(a::'a com) (b::'a) (aa::'a com) (ba::'a) (Rs::('a ann_com option × 'a set) list) (Rsa::('a ann_com option × 'a set) list) (i::nat) (c::'a ann_com) (q::'a set) r::'a ann_com option. ⟦interfree (Ts::('a ann_com option × 'a set) list); ∀i<length Ts. ∃(c::'a ann_com) q::'a set. Ts ! i = (Some c, q) ∧ (s::'a) ∈ pre c ∧ ⊢ c q; ∀Rs::('a ann_com option × 'a set) list. Parallel Rsa = Parallel Rs ⟶ (∀j<length Rs. if OG_Hoare.com (Rs ! j) = None then b ∈ OG_Hoare.post (Ts ! j) else b ∈ pre (the (OG_Hoare.com (Rs ! j))) ∧ ⊢ the (OG_Hoare.com (Rs ! j)) OG_Hoare.post (Ts ! j)) ∧ interfree Rs; (Ts'::'a com) = Parallel Ts; length Rsa = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rsa ! i); Rs = Rsa[i := (r, q)]; i < length Rsa; Rsa ! i = (Some c, q); (Some c, b) -1→ (r, ba)⟧ ⟹ ∀j<length Rs. if OG_Hoare.com (Rs ! j) = None then ba ∈ OG_Hoare.post (Ts ! j) else ba ∈ pre (the (OG_Hoare.com (Rs ! j))) ∧ ⊢ the (OG_Hoare.com (Rs ! j)) OG_Hoare.post (Ts ! j)› 2. ‹⋀(a::'a com) (b::'a) (aa::'a com) (ba::'a) (Rs::('a ann_com option × 'a set) list) (Rsa::('a ann_com option × 'a set) list) (i::nat) (c::'a ann_com) (q::'a set) r::'a ann_com option. ⟦interfree (Ts::('a ann_com option × 'a set) list); ∀i<length Ts. ∃(c::'a ann_com) q::'a set. Ts ! i = (Some c, q) ∧ (s::'a) ∈ pre c ∧ ⊢ c q; ∀Rs::('a ann_com option × 'a set) list. Parallel Rsa = Parallel Rs ⟶ (∀j<length Rs. if OG_Hoare.com (Rs ! j) = None then b ∈ OG_Hoare.post (Ts ! j) else b ∈ pre (the (OG_Hoare.com (Rs ! j))) ∧ ⊢ the (OG_Hoare.com (Rs ! j)) OG_Hoare.post (Ts ! j)) ∧ interfree Rs; (Ts'::'a com) = Parallel Ts; length Rsa = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rsa ! i); Rs = Rsa[i := (r, q)]; i < length Rsa; Rsa ! i = (Some c, q); (Some c, b) -1→ (r, ba)⟧ ⟹ interfree Rs› discuss goal 1*) apply clarify (*top goal: ‹⋀a b aa ba Rs Rsa i c q r. ⟦interfree Ts; ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q; ∀Rs. Parallel Rsa = Parallel Rs ⟶ (∀j<length Rs. if OG_Hoare.com (Rs ! j) = None then b ∈ OG_Hoare.post (Ts ! j) else b ∈ pre (the (OG_Hoare.com (Rs ! j))) ∧ ⊢ the (OG_Hoare.com (Rs ! j)) OG_Hoare.post (Ts ! j)) ∧ interfree Rs; Ts' = Parallel Ts; length Rsa = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rsa ! i); Rs = Rsa[i := (r, q)]; i < length Rsa; Rsa ! i = (Some c, q); (Some c, b) -1→ (r, ba)⟧ ⟹ ∀j<length Rs. if OG_Hoare.com (Rs ! j) = None then ba ∈ OG_Hoare.post (Ts ! j) else ba ∈ pre (the (OG_Hoare.com (Rs ! j))) ∧ ⊢ the (OG_Hoare.com (Rs ! j)) OG_Hoare.post (Ts ! j)› and 1 goal remains*) apply (case_tac "i=j") (*goals: 1. ‹⋀(a::'a com) (b::'a) (aa::'a com) (ba::'a) (Rs::('a ann_com option × 'a set) list) (Rsa::('a ann_com option × 'a set) list) (i::nat) (c::'a ann_com) (q::'a set) (r::'a ann_com option) j::nat. ⟦interfree (Ts::('a ann_com option × 'a set) list); ∀i<length Ts. ∃(c::'a ann_com) q::'a set. Ts ! i = (Some c, q) ∧ (s::'a) ∈ pre c ∧ ⊢ c q; ∀Rs::('a ann_com option × 'a set) list. Parallel Rsa = Parallel Rs ⟶ (∀j<length Rs. if OG_Hoare.com (Rs ! j) = None then b ∈ OG_Hoare.post (Ts ! j) else b ∈ pre (the (OG_Hoare.com (Rs ! j))) ∧ ⊢ the (OG_Hoare.com (Rs ! j)) OG_Hoare.post (Ts ! j)) ∧ interfree Rs; (Ts'::'a com) = Parallel Ts; length Rsa = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rsa ! i); i < length Rsa; Rsa ! i = (Some c, q); (Some c, b) -1→ (r, ba); j < length (Rsa[i := (r, q)]); i = j⟧ ⟹ if OG_Hoare.com (Rsa[i := (r, q)] ! j) = None then ba ∈ OG_Hoare.post (Ts ! j) else ba ∈ pre (the (OG_Hoare.com (Rsa[i := (r, q)] ! j))) ∧ ⊢ the (OG_Hoare.com (Rsa[i := (r, q)] ! j)) OG_Hoare.post (Ts ! j)› 2. ‹⋀(a::'a com) (b::'a) (aa::'a com) (ba::'a) (Rs::('a ann_com option × 'a set) list) (Rsa::('a ann_com option × 'a set) list) (i::nat) (c::'a ann_com) (q::'a set) (r::'a ann_com option) j::nat. ⟦interfree (Ts::('a ann_com option × 'a set) list); ∀i<length Ts. ∃(c::'a ann_com) q::'a set. Ts ! i = (Some c, q) ∧ (s::'a) ∈ pre c ∧ ⊢ c q; ∀Rs::('a ann_com option × 'a set) list. Parallel Rsa = Parallel Rs ⟶ (∀j<length Rs. if OG_Hoare.com (Rs ! j) = None then b ∈ OG_Hoare.post (Ts ! j) else b ∈ pre (the (OG_Hoare.com (Rs ! j))) ∧ ⊢ the (OG_Hoare.com (Rs ! j)) OG_Hoare.post (Ts ! j)) ∧ interfree Rs; (Ts'::'a com) = Parallel Ts; length Rsa = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rsa ! i); i < length Rsa; Rsa ! i = (Some c, q); (Some c, b) -1→ (r, ba); j < length (Rsa[i := (r, q)]); i ≠ j⟧ ⟹ if OG_Hoare.com (Rsa[i := (r, q)] ! j) = None then ba ∈ OG_Hoare.post (Ts ! j) else ba ∈ pre (the (OG_Hoare.com (Rsa[i := (r, q)] ! j))) ∧ ⊢ the (OG_Hoare.com (Rsa[i := (r, q)] ! j)) OG_Hoare.post (Ts ! j)› discuss goal 1*) apply (simp split del:if_split (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))›*)) (*top goal: ‹⋀a b aa ba Rs Rsa i c q r j. ⟦interfree Ts; ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q; ∀Rs. Parallel Rsa = Parallel Rs ⟶ (∀j<length Rs. if OG_Hoare.com (Rs ! j) = None then b ∈ OG_Hoare.post (Ts ! j) else b ∈ pre (the (OG_Hoare.com (Rs ! j))) ∧ ⊢ the (OG_Hoare.com (Rs ! j)) OG_Hoare.post (Ts ! j)) ∧ interfree Rs; Ts' = Parallel Ts; length Rsa = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rsa ! i); i < length Rsa; Rsa ! i = (Some c, q); (Some c, b) -1→ (r, ba); j < length (Rsa[i := (r, q)]); i = j⟧ ⟹ if OG_Hoare.com (Rsa[i := (r, q)] ! j) = None then ba ∈ OG_Hoare.post (Ts ! j) else ba ∈ pre (the (OG_Hoare.com (Rsa[i := (r, q)] ! j))) ∧ ⊢ the (OG_Hoare.com (Rsa[i := (r, q)] ! j)) OG_Hoare.post (Ts ! j)› and 2 goals remain*) apply (erule Strong_Soundness_aux_aux (*‹⟦(?co, ?s) -1→ (?co', ?t); ?co = Some ?c; ?s ∈ pre ?c; ⊢ ?c ?q⟧ ⟹ if ?co' = None then ?t ∈ ?q else ?t ∈ pre (the ?co') ∧ ⊢ the ?co' ?q›*)) (*goals: 1. ‹⋀b ba Rsa i c q r j. ⟦interfree Ts; ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q; (∀j<length Ts. if OG_Hoare.com (Rsa ! j) = None then b ∈ OG_Hoare.post (Rsa ! j) else b ∈ pre (the (OG_Hoare.com (Rsa ! j))) ∧ ⊢ the (OG_Hoare.com (Rsa ! j)) OG_Hoare.post (Rsa ! j)) ∧ interfree Rsa; Ts' = Parallel Ts; length Rsa = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rsa ! i); j < length Ts; Rsa ! j = (Some c, q); i = j⟧ ⟹ Some c = Some (?c71 b ba Rsa i c q r j)› 2. ‹⋀b ba Rsa i c q r j. ⟦interfree Ts; ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q; (∀j<length Ts. if OG_Hoare.com (Rsa ! j) = None then b ∈ OG_Hoare.post (Rsa ! j) else b ∈ pre (the (OG_Hoare.com (Rsa ! j))) ∧ ⊢ the (OG_Hoare.com (Rsa ! j)) OG_Hoare.post (Rsa ! j)) ∧ interfree Rsa; Ts' = Parallel Ts; length Rsa = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rsa ! i); j < length Ts; Rsa ! j = (Some c, q); i = j⟧ ⟹ b ∈ pre (?c71 b ba Rsa i c q r j)› 3. ‹⋀b ba Rsa i c q r j. ⟦interfree Ts; ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q; (∀j<length Ts. if OG_Hoare.com (Rsa ! j) = None then b ∈ OG_Hoare.post (Rsa ! j) else b ∈ pre (the (OG_Hoare.com (Rsa ! j))) ∧ ⊢ the (OG_Hoare.com (Rsa ! j)) OG_Hoare.post (Rsa ! j)) ∧ interfree Rsa; Ts' = Parallel Ts; length Rsa = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rsa ! i); j < length Ts; Rsa ! j = (Some c, q); i = j⟧ ⟹ ⊢ ?c71 b ba Rsa i c q r j q› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*top goal: ‹⋀(b::'a) (ba::'a) (Rsa::('a ann_com option × 'a set) list) (i::nat) (c::'a ann_com) (q::'a set) (r::'a ann_com option) j::nat. ⟦interfree (Ts::('a ann_com option × 'a set) list); ∀i<length Ts. ∃(c::'a ann_com) q::'a set. Ts ! i = (Some c, q) ∧ (s::'a) ∈ pre c ∧ ⊢ c q; (∀j<length Ts. if OG_Hoare.com (Rsa ! j) = None then b ∈ OG_Hoare.post (Rsa ! j) else b ∈ pre (the (OG_Hoare.com (Rsa ! j))) ∧ ⊢ the (OG_Hoare.com (Rsa ! j)) OG_Hoare.post (Rsa ! j)) ∧ interfree Rsa; (Ts'::'a com) = Parallel Ts; length Rsa = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rsa ! i); j < length Ts; Rsa ! j = (Some c, q); i = j⟧ ⟹ b ∈ pre c› and 3 goals remain*) apply force (*discuss goal 3*) apply force (*proven 3 subgoals*) (*discuss goal 2*) apply (simp split del: if_split (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))›*)) (*top goal: ‹⋀a b aa ba Rs Rsa i c q r j. ⟦interfree Ts; ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q; ∀Rs. Parallel Rsa = Parallel Rs ⟶ (∀j<length Rs. if OG_Hoare.com (Rs ! j) = None then b ∈ OG_Hoare.post (Ts ! j) else b ∈ pre (the (OG_Hoare.com (Rs ! j))) ∧ ⊢ the (OG_Hoare.com (Rs ! j)) OG_Hoare.post (Ts ! j)) ∧ interfree Rs; Ts' = Parallel Ts; length Rsa = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rsa ! i); i < length Rsa; Rsa ! i = (Some c, q); (Some c, b) -1→ (r, ba); j < length (Rsa[i := (r, q)]); i ≠ j⟧ ⟹ if OG_Hoare.com (Rsa[i := (r, q)] ! j) = None then ba ∈ OG_Hoare.post (Ts ! j) else ba ∈ pre (the (OG_Hoare.com (Rsa[i := (r, q)] ! j))) ∧ ⊢ the (OG_Hoare.com (Rsa[i := (r, q)] ! j)) OG_Hoare.post (Ts ! j)› and 1 goal remains*) apply (erule Parallel_Strong_Soundness_aux_aux (*‹⟦(Some ?c, ?b) -1→ (?co, ?t); ?i < length ?Ts; OG_Hoare.com (?Ts ! ?i) = Some ?c; ⋀i. i < length ?Ts ⟹ if OG_Hoare.com (?Ts ! i) = None then ?b ∈ OG_Hoare.post (?Ts ! i) else ?b ∈ pre (the (OG_Hoare.com (?Ts ! i))) ∧ ⊢ the (OG_Hoare.com (?Ts ! i)) OG_Hoare.post (?Ts ! i); interfree ?Ts; ?j < length ?Ts ∧ ?i ≠ ?j⟧ ⟹ if OG_Hoare.com (?Ts ! ?j) = None then ?t ∈ OG_Hoare.post (?Ts ! ?j) else ?t ∈ pre (the (OG_Hoare.com (?Ts ! ?j))) ∧ ⊢ the (OG_Hoare.com (?Ts ! ?j)) OG_Hoare.post (?Ts ! ?j)›*)) (*goals: 1. ‹⋀b ba Rsa i c q r j. ⟦interfree Ts; ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q; (∀j<length Ts. if OG_Hoare.com (Rsa ! j) = None then b ∈ OG_Hoare.post (Rsa ! j) else b ∈ pre (the (OG_Hoare.com (Rsa ! j))) ∧ ⊢ the (OG_Hoare.com (Rsa ! j)) OG_Hoare.post (Rsa ! j)) ∧ interfree Rsa; Ts' = Parallel Ts; length Rsa = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rsa ! i); i < length Ts; Rsa ! i = (Some c, q); j < length Ts; i ≠ j⟧ ⟹ ?i90 b ba Rsa i c q r j < length Rsa› 2. ‹⋀b ba Rsa i c q r j. ⟦interfree Ts; ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q; (∀j<length Ts. if OG_Hoare.com (Rsa ! j) = None then b ∈ OG_Hoare.post (Rsa ! j) else b ∈ pre (the (OG_Hoare.com (Rsa ! j))) ∧ ⊢ the (OG_Hoare.com (Rsa ! j)) OG_Hoare.post (Rsa ! j)) ∧ interfree Rsa; Ts' = Parallel Ts; length Rsa = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rsa ! i); i < length Ts; Rsa ! i = (Some c, q); j < length Ts; i ≠ j⟧ ⟹ OG_Hoare.com (Rsa ! ?i90 b ba Rsa i c q r j) = Some c› 3. ‹⋀b ba Rsa i c q r j ia. ⟦interfree Ts; ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q; (∀j<length Ts. if OG_Hoare.com (Rsa ! j) = None then b ∈ OG_Hoare.post (Rsa ! j) else b ∈ pre (the (OG_Hoare.com (Rsa ! j))) ∧ ⊢ the (OG_Hoare.com (Rsa ! j)) OG_Hoare.post (Rsa ! j)) ∧ interfree Rsa; Ts' = Parallel Ts; length Rsa = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rsa ! i); i < length Ts; Rsa ! i = (Some c, q); j < length Ts; i ≠ j; ia < length Rsa⟧ ⟹ if OG_Hoare.com (Rsa ! ia) = None then b ∈ OG_Hoare.post (Rsa ! ia) else b ∈ pre (the (OG_Hoare.com (Rsa ! ia))) ∧ ⊢ the (OG_Hoare.com (Rsa ! ia)) OG_Hoare.post (Rsa ! ia)› 4. ‹⋀b ba Rsa i c q r j. ⟦interfree Ts; ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q; (∀j<length Ts. if OG_Hoare.com (Rsa ! j) = None then b ∈ OG_Hoare.post (Rsa ! j) else b ∈ pre (the (OG_Hoare.com (Rsa ! j))) ∧ ⊢ the (OG_Hoare.com (Rsa ! j)) OG_Hoare.post (Rsa ! j)) ∧ interfree Rsa; Ts' = Parallel Ts; length Rsa = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rsa ! i); i < length Ts; Rsa ! i = (Some c, q); j < length Ts; i ≠ j⟧ ⟹ interfree Rsa› 5. ‹⋀b ba Rsa i c q r j. ⟦interfree Ts; ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q; (∀j<length Ts. if OG_Hoare.com (Rsa ! j) = None then b ∈ OG_Hoare.post (Rsa ! j) else b ∈ pre (the (OG_Hoare.com (Rsa ! j))) ∧ ⊢ the (OG_Hoare.com (Rsa ! j)) OG_Hoare.post (Rsa ! j)) ∧ interfree Rsa; Ts' = Parallel Ts; length Rsa = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rsa ! i); i < length Ts; Rsa ! i = (Some c, q); j < length Ts; i ≠ j⟧ ⟹ j < length Rsa ∧ ?i90 b ba Rsa i c q r j ≠ j› discuss goal 1*) apply (simp add: split (*‹(case (?a, ?b) of (c, d) ⇒ ?f c d) = ?f ?a ?b›*) del:if_split (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))›*)) (*discuss goal 2*) apply (simp add: split (*‹(case (?a, ?b) of (c, d) ⇒ ?f c d) = ?f ?a ?b›*) del:if_split (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))›*)) (*discuss goal 3*) apply (simp add: split (*‹(case (?a, ?b) of (c, d) ⇒ ?f c d) = ?f ?a ?b›*) del:if_split (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))›*)) (*top goal: ‹⋀b ba Rsa i c q r j ia. ⟦interfree Ts; ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q; (∀j<length Ts. if OG_Hoare.com (Rsa ! j) = None then b ∈ OG_Hoare.post (Rsa ! j) else b ∈ pre (the (OG_Hoare.com (Rsa ! j))) ∧ ⊢ the (OG_Hoare.com (Rsa ! j)) OG_Hoare.post (Rsa ! j)) ∧ interfree Rsa; Ts' = Parallel Ts; length Rsa = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rsa ! i); i < length Ts; Rsa ! i = (Some c, q); j < length Ts; i ≠ j; ia < length Rsa⟧ ⟹ if OG_Hoare.com (Rsa ! ia) = None then b ∈ OG_Hoare.post (Rsa ! ia) else b ∈ pre (the (OG_Hoare.com (Rsa ! ia))) ∧ ⊢ the (OG_Hoare.com (Rsa ! ia)) OG_Hoare.post (Rsa ! ia)› and 3 goals remain*) apply force (*discuss goal 4*) apply (simp add: split (*‹(case (?a, ?b) of (c, d) ⇒ ?f c d) = ?f ?a ?b›*) del:if_split (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))›*)) (*discuss goal 5*) apply (simp add: split (*‹(case (?a, ?b) of (c, d) ⇒ ?f c d) = ?f ?a ?b›*) del:if_split (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))›*)) (*proven 5 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply (simp add: split (*‹(case (?a, ?b) of (c, d) ⇒ ?f c d) = ?f ?a ?b›*) del:if_split (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))›*)) (*goal: ‹⋀(a::'a com) (b::'a) (aa::'a com) (ba::'a) (Rs::('a ann_com option × 'a set) list) (Rsa::('a ann_com option × 'a set) list) (i::nat) (c::'a ann_com) (q::'a set) r::'a ann_com option. ⟦interfree (Ts::('a ann_com option × 'a set) list); ∀i<length Ts. ∃(c::'a ann_com) q::'a set. Ts ! i = (Some c, q) ∧ (s::'a) ∈ pre c ∧ ⊢ c q; ∀Rs::('a ann_com option × 'a set) list. Parallel Rsa = Parallel Rs ⟶ (∀j<length Rs. if OG_Hoare.com (Rs ! j) = None then b ∈ OG_Hoare.post (Ts ! j) else b ∈ pre (the (OG_Hoare.com (Rs ! j))) ∧ ⊢ the (OG_Hoare.com (Rs ! j)) OG_Hoare.post (Ts ! j)) ∧ interfree Rs; (Ts'::'a com) = Parallel Ts; length Rsa = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rsa ! i); Rs = Rsa[i := (r, q)]; i < length Rsa; Rsa ! i = (Some c, q); (Some c, b) -1→ (r, ba)⟧ ⟹ interfree Rs›*) apply (rule interfree_lemma (*‹⟦(Some (?c::?'a ann_com), ?s::?'a) -1→ (?r::?'a ann_com option, ?t::?'a); interfree (?Ts::(?'a ann_com option × ?'a set) list); (?i::nat) < length ?Ts; ?Ts ! ?i = (Some ?c, ?q::?'a set)⟧ ⟹ interfree (?Ts[?i := (?r, ?q)])›*)) (*goals: 1. ‹⋀(b::'a) (ba::'a) (Rs::('a ann_com option × 'a set) list) (Rsa::('a ann_com option × 'a set) list) (i::nat) (c::'a ann_com) (q::'a set) r::'a ann_com option. ⟦interfree (Ts::('a ann_com option × 'a set) list); ∀i<length Ts. ∃(c::'a ann_com) q::'a set. Ts ! i = (Some c, q) ∧ (s::'a) ∈ pre c ∧ ⊢ c q; (∀j<length Ts. if OG_Hoare.com (Rsa ! j) = None then b ∈ OG_Hoare.post (Rsa ! j) else b ∈ pre (the (OG_Hoare.com (Rsa ! j))) ∧ ⊢ the (OG_Hoare.com (Rsa ! j)) OG_Hoare.post (Rsa ! j)) ∧ interfree Rsa; (Ts'::'a com) = Parallel Ts; length Rsa = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rsa ! i); Rs = Rsa[i := (r, q)]; i < length Ts; Rsa ! i = (Some c, q); (Some c, b) -1→ (r, ba)⟧ ⟹ (Some ((?c103::'a ⇒ 'a ⇒ ('a ann_com option × 'a set) list ⇒ ('a ann_com option × 'a set) list ⇒ nat ⇒ 'a ann_com ⇒ 'a set ⇒ 'a ann_com option ⇒ 'a ann_com) b ba Rs Rsa i c q r), (?s103::'a ⇒ 'a ⇒ ('a ann_com option × 'a set) list ⇒ ('a ann_com option × 'a set) list ⇒ nat ⇒ 'a ann_com ⇒ 'a set ⇒ 'a ann_com option ⇒ 'a) b ba Rs Rsa i c q r) -1→ (r, (?t103::'a ⇒ 'a ⇒ ('a ann_com option × 'a set) list ⇒ ('a ann_com option × 'a set) list ⇒ nat ⇒ 'a ann_com ⇒ 'a set ⇒ 'a ann_com option ⇒ 'a) b ba Rs Rsa i c q r)› 2. ‹⋀(b::'a) (ba::'a) (Rs::('a ann_com option × 'a set) list) (Rsa::('a ann_com option × 'a set) list) (i::nat) (c::'a ann_com) (q::'a set) r::'a ann_com option. ⟦interfree (Ts::('a ann_com option × 'a set) list); ∀i<length Ts. ∃(c::'a ann_com) q::'a set. Ts ! i = (Some c, q) ∧ (s::'a) ∈ pre c ∧ ⊢ c q; (∀j<length Ts. if OG_Hoare.com (Rsa ! j) = None then b ∈ OG_Hoare.post (Rsa ! j) else b ∈ pre (the (OG_Hoare.com (Rsa ! j))) ∧ ⊢ the (OG_Hoare.com (Rsa ! j)) OG_Hoare.post (Rsa ! j)) ∧ interfree Rsa; (Ts'::'a com) = Parallel Ts; length Rsa = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rsa ! i); Rs = Rsa[i := (r, q)]; i < length Ts; Rsa ! i = (Some c, q); (Some c, b) -1→ (r, ba)⟧ ⟹ interfree Rsa› 3. ‹⋀(b::'a) (ba::'a) (Rs::('a ann_com option × 'a set) list) (Rsa::('a ann_com option × 'a set) list) (i::nat) (c::'a ann_com) (q::'a set) r::'a ann_com option. ⟦interfree (Ts::('a ann_com option × 'a set) list); ∀i<length Ts. ∃(c::'a ann_com) q::'a set. Ts ! i = (Some c, q) ∧ (s::'a) ∈ pre c ∧ ⊢ c q; (∀j<length Ts. if OG_Hoare.com (Rsa ! j) = None then b ∈ OG_Hoare.post (Rsa ! j) else b ∈ pre (the (OG_Hoare.com (Rsa ! j))) ∧ ⊢ the (OG_Hoare.com (Rsa ! j)) OG_Hoare.post (Rsa ! j)) ∧ interfree Rsa; (Ts'::'a com) = Parallel Ts; length Rsa = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rsa ! i); Rs = Rsa[i := (r, q)]; i < length Ts; Rsa ! i = (Some c, q); (Some c, b) -1→ (r, ba)⟧ ⟹ i < length Rsa› 4. ‹⋀(b::'a) (ba::'a) (Rs::('a ann_com option × 'a set) list) (Rsa::('a ann_com option × 'a set) list) (i::nat) (c::'a ann_com) (q::'a set) r::'a ann_com option. ⟦interfree (Ts::('a ann_com option × 'a set) list); ∀i<length Ts. ∃(c::'a ann_com) q::'a set. Ts ! i = (Some c, q) ∧ (s::'a) ∈ pre c ∧ ⊢ c q; (∀j<length Ts. if OG_Hoare.com (Rsa ! j) = None then b ∈ OG_Hoare.post (Rsa ! j) else b ∈ pre (the (OG_Hoare.com (Rsa ! j))) ∧ ⊢ the (OG_Hoare.com (Rsa ! j)) OG_Hoare.post (Rsa ! j)) ∧ interfree Rsa; (Ts'::'a com) = Parallel Ts; length Rsa = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rsa ! i); Rs = Rsa[i := (r, q)]; i < length Ts; Rsa ! i = (Some c, q); (Some c, b) -1→ (r, ba)⟧ ⟹ Rsa ! i = (Some ((?c103::'a ⇒ 'a ⇒ ('a ann_com option × 'a set) list ⇒ ('a ann_com option × 'a set) list ⇒ nat ⇒ 'a ann_com ⇒ 'a set ⇒ 'a ann_com option ⇒ 'a ann_com) b ba Rs Rsa i c q r), q)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*discuss goal 4*) apply simp (*proven 4 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma Parallel_Strong_Soundness: "⟦(Parallel Ts, s) -P*→ (Parallel Rs, t); interfree Ts; j<length Rs; ∀i. i<length Ts ⟶ (∃c q. Ts ! i = (Some c, q) ∧ s∈pre c ∧ ⊢ c q) ⟧ ⟹ if com(Rs ! j) = None then t∈post(Ts ! j) else t∈pre (the(com(Rs ! j)))" apply (drule Parallel_Strong_Soundness_aux (*‹⟦(?Ts', ?s) -P*→ (?Rs', ?t); ?Ts' = Parallel ?Ts; interfree ?Ts; ⋀i. i < length ?Ts ⟹ ∃c q. ?Ts ! i = (Some c, q) ∧ ?s ∈ pre c ∧ ⊢ c q; ?Rs' = Parallel ?Rs⟧ ⟹ (∀j<length ?Rs. if OG_Hoare.com (?Rs ! j) = None then ?t ∈ OG_Hoare.post (?Ts ! j) else ?t ∈ pre (the (OG_Hoare.com (?Rs ! j))) ∧ ⊢ the (OG_Hoare.com (?Rs ! j)) OG_Hoare.post (?Ts ! j)) ∧ interfree ?Rs›*)) (*goals: 1. ‹⟦interfree Ts; j < length Rs; ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q⟧ ⟹ Parallel Ts = Parallel ?Ts› 2. ‹⟦interfree Ts; j < length Rs; ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q⟧ ⟹ interfree ?Ts› 3. ‹⋀i. ⟦interfree Ts; j < length Rs; ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q; i < length ?Ts⟧ ⟹ ∃c q. ?Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q› 4. ‹⟦interfree Ts; j < length Rs; ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q⟧ ⟹ Parallel Rs = Parallel ?Rs› 5. ‹⟦interfree Ts; j < length Rs; ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ s ∈ pre c ∧ ⊢ c q; (∀j<length ?Rs. if OG_Hoare.com (?Rs ! j) = None then t ∈ OG_Hoare.post (?Ts ! j) else t ∈ pre (the (OG_Hoare.com (?Rs ! j))) ∧ ⊢ the (OG_Hoare.com (?Rs ! j)) OG_Hoare.post (?Ts ! j)) ∧ interfree ?Rs⟧ ⟹ if OG_Hoare.com (Rs ! j) = None then t ∈ OG_Hoare.post (Ts ! j) else t ∈ pre (the (OG_Hoare.com (Rs ! j)))› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*discuss goal 4*) apply simp (*discuss goal 5*) apply simp (*proven 5 subgoals*) . lemma oghoare_sound [rule_format]: "∥- p c q ⟶ ∥= p c q" apply (unfold com_validity_def (*‹∥= ?p ?c ?q ≡ SEM ?c ?p ⊆ ?q›*)) (*goal: ‹∥- p c q ⟶ ∥= p c q›*) apply (rule oghoare_induct (*‹⟦⋀r f q. r ⊆ {s. f s ∈ q} ⟹ ?P2.0 (AnnBasic r f) q; ⋀c0 c1 q. ⟦⊢ c0 pre c1; ?P2.0 c0 (pre c1); ⊢ c1 q; ?P2.0 c1 q⟧ ⟹ ?P2.0 (AnnSeq c0 c1) q; ⋀r b c1 q c2. ⟦r ∩ b ⊆ pre c1; ⊢ c1 q; ?P2.0 c1 q; r ∩ - b ⊆ pre c2; ⊢ c2 q; ?P2.0 c2 q⟧ ⟹ ?P2.0 (AnnCond1 r b c1 c2) q; ⋀r b c q. ⟦r ∩ b ⊆ pre c; ⊢ c q; ?P2.0 c q; r ∩ - b ⊆ q⟧ ⟹ ?P2.0 (AnnCond2 r b c) q; ⋀r i b c q. ⟦r ⊆ i; i ∩ b ⊆ pre c; ⊢ c i; ?P2.0 c i; i ∩ - b ⊆ q⟧ ⟹ ?P2.0 (AnnWhile r b i c) q; ⋀c r b q. ⟦atom_com c; ∥- (r ∩ b) c q; ?P1.0 (r ∩ b) c q⟧ ⟹ ?P2.0 (AnnAwait r b c) q; ⋀c q q'. ⟦⊢ c q; ?P2.0 c q; q ⊆ q'⟧ ⟹ ?P2.0 c q'; ⋀Ts. ⟦∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ ⊢ c q ∧ ?P2.0 c q; interfree Ts⟧ ⟹ ?P1.0 (⋂i∈{i. i < length Ts}. pre (the (OG_Hoare.com (Ts ! i)))) (Parallel Ts) (⋂i∈{i. i < length Ts}. OG_Hoare.post (Ts ! i)); ⋀f q. ?P1.0 {s. f s ∈ q} (Basic f) q; ⋀p c1 r c2 q. ⟦∥- p c1 r; ?P1.0 p c1 r; ∥- r c2 q; ?P1.0 r c2 q⟧ ⟹ ?P1.0 p (Seq c1 c2) q; ⋀p b c1 q c2. ⟦∥- (p ∩ b) c1 q; ?P1.0 (p ∩ b) c1 q; ∥- (p ∩ - b) c2 q; ?P1.0 (p ∩ - b) c2 q⟧ ⟹ ?P1.0 p (Cond b c1 c2) q; ⋀p b c i. ⟦∥- (p ∩ b) c p; ?P1.0 (p ∩ b) c p⟧ ⟹ ?P1.0 p (While b i c) (p ∩ - b); ⋀p' p c q q'. ⟦p' ⊆ p; ∥- p c q; ?P1.0 p c q; q ⊆ q'⟧ ⟹ ?P1.0 p' c q'⟧ ⟹ ∥- ?x1.0 ?x2.0 ?x3.0 ⟶ ?P1.0 ?x1.0 ?x2.0 ?x3.0›*)) (*goal: ‹∥- p c q ⟶ SEM c p ⊆ q›*) apply ((rule TrueI (*‹True›*))+) (*top goal: ‹⋀r f q. r ⊆ {s. f s ∈ q} ⟹ ?P2.0 (AnnBasic r f) q› and 12 goals remain*) apply (simp add: SEM_def (*‹SEM ?c ?S ≡ ⋃ (sem ?c ` ?S)›*) sem_def (*‹sem ?c ≡ λs. {t. ∃Ts. (?c, s) -P*→ (Parallel Ts, t) ∧ All_None Ts}›*)) (*top goal: ‹⋀Ts::('a ann_com option × 'a set) list. ⟦∀i<length Ts. ∃(c::'a ann_com) q::'a set. Ts ! i = (Some c, q) ∧ ⊢ c q ∧ True; interfree Ts⟧ ⟹ SEM (Parallel Ts) (⋂i::nat∈{i::nat. i < length Ts}. pre (the (OG_Hoare.com (Ts ! i)))) ⊆ (⋂i::nat∈{i::nat. i < length Ts}. OG_Hoare.post (Ts ! i))› and 5 goals remain*) apply (clarify, rename_tac x y i Ts') (*top goal: ‹⋀Ts. ⟦∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ ⊢ c q; interfree Ts⟧ ⟹ (⋃x∈⋂i∈{i. i < length Ts}. pre (the (OG_Hoare.com (Ts ! i))). {t. ∃Tsa. (Parallel Ts, x) -P*→ (Parallel Tsa, t) ∧ All_None Tsa}) ⊆ (⋂i∈{i. i < length Ts}. OG_Hoare.post (Ts ! i))› and 5 goals remain*) apply (frule Parallel_length_post_PStar (*‹(Parallel ?Ts, ?s) -P*→ (?R', ?t) ⟹ ∃Rs. ?R' = Parallel Rs ∧ length Rs = length ?Ts ∧ (∀i<length ?Ts. OG_Hoare.post (?Ts ! i) = OG_Hoare.post (Rs ! i))›*)) (*top goal: ‹⋀Ts x y i Ts'. ⟦∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ ⊢ c q; interfree Ts; y ∈ (⋂i∈{i. i < length Ts}. pre (the (OG_Hoare.com (Ts ! i)))); i < length Ts; (Parallel Ts, y) -P*→ (Parallel Ts', x); All_None Ts'⟧ ⟹ x ∈ OG_Hoare.post (Ts ! i)› and 5 goals remain*) apply clarify (*top goal: ‹⋀(Ts::('a::type ann_com option × 'a::type set) list) (x::'a::type) (y::'a::type) (i::nat) Ts'::('a::type ann_com option × 'a::type set) list. ⟦∀i<length Ts. ∃(c::'a::type ann_com) q::'a::type set. Ts ! i = (Some c, q) ∧ ⊢ c q; interfree Ts; y ∈ (⋂i::nat∈{i::nat. i < length Ts}. pre (the (OG_Hoare.com (Ts ! i)))); i < length Ts; (Parallel Ts, y) -P*→ (Parallel Ts', x); All_None Ts'; ∃Rs::('a::type ann_com option × 'a::type set) list. Parallel Ts' = Parallel Rs ∧ length Rs = length Ts ∧ (∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rs ! i))⟧ ⟹ x ∈ OG_Hoare.post (Ts ! i)› and 5 goals remain*) apply (drule_tac j=i in Parallel_Strong_Soundness (*‹⟦(Parallel ?Ts, ?s) -P*→ (Parallel ?Rs, ?t); interfree ?Ts; ?j < length ?Rs; ∀i<length ?Ts. ∃c q. ?Ts ! i = (Some c, q) ∧ ?s ∈ pre c ∧ ⊢ c q⟧ ⟹ if OG_Hoare.com (?Rs ! ?j) = None then ?t ∈ OG_Hoare.post (?Ts ! ?j) else ?t ∈ pre (the (OG_Hoare.com (?Rs ! ?j)))›*)) (*top goal: ‹⋀Ts x y i Ts' Rs. ⟦∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ ⊢ c q; interfree Ts; y ∈ (⋂i∈{i. i < length Ts}. pre (the (OG_Hoare.com (Ts ! i)))); i < length Ts; (Parallel Ts, y) -P*→ (Parallel Rs, x); All_None Rs; length Rs = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rs ! i)⟧ ⟹ x ∈ OG_Hoare.post (Ts ! i)› and 5 goals remain*) apply clarify (*top goal: ‹⋀Ts x y i Ts' Rs. ⟦∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ ⊢ c q; interfree Ts; y ∈ (⋂i∈{i. i < length Ts}. pre (the (OG_Hoare.com (Ts ! i)))); i < length Ts; All_None Rs; length Rs = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rs ! i)⟧ ⟹ interfree Ts› and 8 goals remain*) apply simp (*top goal: ‹⋀(Ts::('a ann_com option × 'a set) list) (x::'a) (y::'a) (i::nat) (Ts'::('a ann_com option × 'a set) list) Rs::('a ann_com option × 'a set) list. ⟦∀i<length Ts. ∃(c::'a ann_com) q::'a set. Ts ! i = (Some c, q) ∧ ⊢ c q; interfree Ts; y ∈ (⋂i::nat∈{i::nat. i < length Ts}. pre (the (OG_Hoare.com (Ts ! i)))); i < length Ts; All_None Rs; length Rs = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rs ! i)⟧ ⟹ i < length Rs› and 7 goals remain*) apply force (*top goal: ‹⋀Ts x y i Ts' Rs. ⟦∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ ⊢ c q; interfree Ts; y ∈ (⋂i∈{i. i < length Ts}. pre (the (OG_Hoare.com (Ts ! i)))); i < length Ts; All_None Rs; length Rs = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rs ! i)⟧ ⟹ ∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ y ∈ pre c ∧ ⊢ c q› and 6 goals remain*) apply simp (*top goal: ‹⋀Ts x y i Ts' Rs. ⟦∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ ⊢ c q; interfree Ts; y ∈ (⋂i∈{i. i < length Ts}. pre (the (OG_Hoare.com (Ts ! i)))); i < length Ts; All_None Rs; length Rs = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rs ! i); if OG_Hoare.com (Rs ! i) = None then x ∈ OG_Hoare.post (Ts ! i) else x ∈ pre (the (OG_Hoare.com (Rs ! i)))⟧ ⟹ x ∈ OG_Hoare.post (Ts ! i)› and 5 goals remain*) apply (erule_tac V = "∀i. P i" for P in thin_rl (*‹⟦PROP ?V; PROP ?W⟧ ⟹ PROP ?W›*)) (*top goal: ‹⋀Ts x y i Rs. ⟦∀i<length Ts. ∃c q. Ts ! i = (Some c, q) ∧ ⊢ c q; interfree Ts; ∀x<length Ts. y ∈ pre (the (OG_Hoare.com (Ts ! x))); i < length Ts; All_None Rs; length Rs = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rs ! i); if OG_Hoare.com (Rs ! i) = None then x ∈ OG_Hoare.post (Rs ! i) else x ∈ pre (the (OG_Hoare.com (Rs ! i)))⟧ ⟹ x ∈ OG_Hoare.post (Rs ! i)› and 5 goals remain*) apply (drule_tac s = "length Rs" in sym (*‹?s = ?t ⟹ ?t = ?s›*)) (*top goal: ‹⋀Ts x y i Rs. ⟦interfree Ts; ∀x<length Ts. y ∈ pre (the (OG_Hoare.com (Ts ! x))); i < length Ts; All_None Rs; length Rs = length Ts; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rs ! i); if OG_Hoare.com (Rs ! i) = None then x ∈ OG_Hoare.post (Rs ! i) else x ∈ pre (the (OG_Hoare.com (Rs ! i)))⟧ ⟹ x ∈ OG_Hoare.post (Rs ! i)› and 5 goals remain*) apply (erule allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption) (*top goal: ‹⋀(Ts::('a ann_com option × 'a set) list) (x::'a) (y::'a) (i::nat) Rs::('a ann_com option × 'a set) list. ⟦interfree Ts; ∀x<length Ts. y ∈ pre (the (OG_Hoare.com (Ts ! x))); i < length Ts; All_None Rs; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rs ! i); if OG_Hoare.com (Rs ! i) = None then x ∈ OG_Hoare.post (Rs ! i) else x ∈ pre (the (OG_Hoare.com (Rs ! i))); length Ts = length Rs⟧ ⟹ x ∈ OG_Hoare.post (Rs ! i)› and 5 goals remain*) apply (force dest: nth_mem (*‹?n < length ?xs ⟹ ?xs ! ?n ∈ set ?xs›*) simp add: All_None_def (*‹All_None ?Ts ≡ ∀(c, q)∈set ?Ts. c = None›*)) (*top goal: ‹⋀Ts x y i Rs. ⟦interfree Ts; i < length Ts; All_None Rs; ∀i<length Ts. OG_Hoare.post (Ts ! i) = OG_Hoare.post (Rs ! i); if OG_Hoare.com (Rs ! i) = None then x ∈ OG_Hoare.post (Rs ! i) else x ∈ pre (the (OG_Hoare.com (Rs ! i))); length Ts = length Rs; y ∈ pre (the (OG_Hoare.com (Ts ! i)))⟧ ⟹ x ∈ OG_Hoare.post (Rs ! i)› and 5 goals remain*) apply (simp add: SEM_def (*‹SEM ?c ?S ≡ ⋃ (sem ?c ` ?S)›*) sem_def (*‹sem ?c ≡ λs. {t. ∃Ts. (?c, s) -P*→ (Parallel Ts, t) ∧ All_None Ts}›*)) (*top goal: ‹⋀(f::'a ⇒ 'a) q::'a set. SEM (Basic f) {s::'a. f s ∈ q} ⊆ q› and 4 goals remain*) apply (force dest: rtrancl_imp_UN_relpow (*‹?p ∈ ?R⇧* ⟹ ?p ∈ ⋃ (range ((^^) ?R))›*) Basic_ntran (*‹⟦(Basic ?f, ?s) -P?n→ (Parallel ?Ts, ?t); All_None ?Ts⟧ ⟹ ?t = ?f ?s›*)) (*top goal: ‹⋀f q. (⋃x∈{s. f s ∈ q}. {t. ∃Ts. (Basic f, x) -P*→ (Parallel Ts, t) ∧ All_None Ts}) ⊆ q› and 4 goals remain*) apply (rule subset_trans (*‹⟦?A ⊆ ?B; ?B ⊆ ?C⟧ ⟹ ?A ⊆ ?C›*)) (*top goal: ‹⋀p c1 r c2 q. ⟦∥- p c1 r; SEM c1 p ⊆ r; ∥- r c2 q; SEM c2 r ⊆ q⟧ ⟹ SEM (Seq c1 c2) p ⊆ q› and 3 goals remain*) prefer 2 (*top goal: ‹⋀p c1 r c2 q. ⟦∥- p c1 r; SEM c1 p ⊆ r; ∥- r c2 q; SEM c2 r ⊆ q⟧ ⟹ ?B79 p c1 r c2 q ⊆ q› and 4 goals remain*) apply assumption (*top goal: ‹⋀p c1 r c2 q. ⟦∥- p c1 r; SEM c1 p ⊆ r; ∥- r c2 q; SEM c2 r ⊆ q⟧ ⟹ ?B79 p c1 r c2 q ⊆ q› and 4 goals remain*) apply (simp add: L3_5ii (*‹SEM (Seq ?c1.0 ?c2.0) ?X = SEM ?c2.0 (SEM ?c1.0 ?X)›*) L3_5i (*‹?X ⊆ ?Y ⟹ SEM ?c ?X ⊆ SEM ?c ?Y›*)) (*top goal: ‹⋀(p::'a set) (c1::'a com) (r::'a set) (c2::'a com) q::'a set. ⟦∥- p c1 r; SEM c1 p ⊆ r; ∥- r c2 q; SEM c2 r ⊆ q⟧ ⟹ SEM (Seq c1 c2) p ⊆ SEM c2 r› and 3 goals remain*) apply (simp add: L3_5iv (*‹SEM (Cond (?b::?'a set) (?c1.0::?'a com) (?c2.0::?'a com)) (?X::?'a set) = SEM ?c1.0 (?X ∩ ?b) ∪ SEM ?c2.0 (?X ∩ - ?b)›*)) (*top goal: ‹⋀p b c1 q c2. ⟦∥- (p ∩ b) c1 q; SEM c1 (p ∩ b) ⊆ q; ∥- (p ∩ - b) c2 q; SEM c2 (p ∩ - b) ⊆ q⟧ ⟹ SEM (Cond b c1 c2) p ⊆ q› and 2 goals remain*) apply (simp add: L3_5v (*‹SEM (While ?b ?i ?c) = (λx. ⋃k. SEM (fwhile ?b ?c k) x)›*)) (*top goal: ‹⋀(p::'a set) (b::'a set) (c::'a com) i::'a set. ⟦∥- (p ∩ b) c p; SEM c (p ∩ b) ⊆ p⟧ ⟹ SEM (While b i c) p ⊆ p ∩ - b› and 1 goal remains*) apply (blast dest: SEM_fwhile (*‹SEM ?S (?p ∩ ?b) ⊆ ?p ⟹ SEM (fwhile ?b ?S ?k) ?p ⊆ ?p ∩ - ?b›*)) (*top goal: ‹⋀p b c. ⟦∥- (p ∩ b) c p; SEM c (p ∩ b) ⊆ p⟧ ⟹ (⋃k. SEM (fwhile b c k) p) ⊆ p ∧ (⋃k. SEM (fwhile b c k) p) ⊆ - b› and 1 goal remains*) by (auto simp add: SEM_def (*‹SEM ?c ?S ≡ ⋃ (sem ?c ` ?S)›*) sem_def (*‹sem ?c ≡ λs. {t. ∃Ts. (?c, s) -P*→ (Parallel Ts, t) ∧ All_None Ts}›*)) end
{ "path": "Isabelle2024/src/HOL/Hoare_Parallel/OG_Hoare.thy", "repo": "Isabelle2024", "sha": "ae755d774145c68a3ba4f9e3793fef9ea7325a233a2b8681c4dc1a2ce83f2cd4" }
(* Title: HOL/Library/Code_Target_Nat.thy Author: Florian Haftmann, TU Muenchen *) section ‹Implementation of natural numbers by target-language integers› theory Code_Target_Nat imports Code_Abstract_Nat begin subsection ‹Implementation for \<^typ>‹nat›› context includes natural.lifting integer.lifting begin lift_definition Nat :: "integer ⇒ nat" is nat . lemma [code_post]: "Nat 0 = 0" "Nat 1 = 1" "Nat (numeral k) = numeral k" (*goals: 1. ‹local.Nat 0 = 0› 2. ‹local.Nat 1 = 1› 3. ‹local.Nat (numeral k) = numeral k› discuss goal 1*) apply transfer (*top goal: ‹local.Nat 0 = 0› and 2 goals remain*) apply simp (*discuss goal 2*) apply transfer (*top goal: ‹local.Nat 1 = 1› and 1 goal remains*) apply simp (*discuss goal 3*) apply transfer (*goal: ‹local.Nat (numeral k) = numeral k›*) apply simp (*proven 3 subgoals*) . lemma [code_abbrev]: "integer_of_nat = of_nat" apply transfer (*goal: ‹integer_of_nat = of_nat›*) by rule lemma [code_unfold]: "Int.nat (int_of_integer k) = nat_of_integer k" apply transfer (*goal: ‹nat (int_of_integer (k::integer)) = nat_of_integer k›*) by rule lemma [code abstype]: "Code_Target_Nat.Nat (integer_of_nat n) = n" apply transfer (*goal: ‹local.Nat (integer_of_nat n) = n›*) by simp lemma [code abstract]: "integer_of_nat (nat_of_integer k) = max 0 k" apply transfer (*goal: ‹integer_of_nat (nat_of_integer k) = max 0 k›*) by auto lemma [code_abbrev]: "nat_of_integer (numeral k) = nat_of_num k" apply transfer (*goal: ‹nat_of_integer (numeral (k::num)) = nat_of_num k›*) by (simp add: nat_of_num_numeral (*‹nat_of_num = numeral›*)) context begin qualified definition natural :: "num ⇒ nat" where [simp]: "natural = nat_of_num" lemma [code_computation_unfold]: "numeral = natural" "nat_of_num = natural" (*goals: 1. ‹numeral = natural› 2. ‹nat_of_num = natural› discuss goal 1*) apply (simp add: nat_of_num_numeral (*‹nat_of_num = numeral›*)) (*discuss goal 2*) apply (simp add: nat_of_num_numeral (*‹nat_of_num = numeral›*)) (*proven 2 subgoals*) . end lemma [code abstract]: "integer_of_nat (nat_of_num n) = integer_of_num n" by (simp add: nat_of_num_numeral (*‹nat_of_num = numeral›*) integer_of_nat_numeral (*‹integer_of_nat (numeral ?n) = numeral ?n›*)) lemma [code abstract]: "integer_of_nat 0 = 0" apply transfer (*goal: ‹integer_of_nat 0 = 0›*) by simp lemma [code abstract]: "integer_of_nat 1 = 1" apply transfer (*goal: ‹integer_of_nat (1::nat) = (1::integer)›*) by simp lemma [code]: "Suc n = n + 1" by simp lemma [code abstract]: "integer_of_nat (m + n) = of_nat m + of_nat n" apply transfer (*goal: ‹integer_of_nat (m + n) = of_nat m + of_nat n›*) by simp lemma [code abstract]: "integer_of_nat (m - n) = max 0 (of_nat m - of_nat n)" apply transfer (*goal: ‹integer_of_nat (m - n) = max 0 (of_nat m - of_nat n)›*) by simp lemma [code abstract]: "integer_of_nat (m * n) = of_nat m * of_nat n" apply transfer (*goal: ‹integer_of_nat (m * n) = of_nat m * of_nat n›*) by (simp add: of_nat_mult (*‹of_nat (?m * ?n) = of_nat ?m * of_nat ?n›*)) lemma [code abstract]: "integer_of_nat (m div n) = of_nat m div of_nat n" apply transfer (*goal: ‹integer_of_nat ((m::nat) div (n::nat)) = of_nat m div of_nat n›*) by (simp add: zdiv_int (*‹int ((?m::nat) div (?n::nat)) = int ?m div int ?n›*)) lemma [code abstract]: "integer_of_nat (m mod n) = of_nat m mod of_nat n" apply transfer (*goal: ‹integer_of_nat ((m::nat) mod (n::nat)) = of_nat m mod of_nat n›*) by (simp add: zmod_int (*‹int (?m mod ?n) = int ?m mod int ?n›*)) context includes integer.lifting begin lemma divmod_nat_code [code]: ✐‹contributor ‹René Thiemann›› ✐‹contributor ‹Akihisa Yamada›› "Euclidean_Rings.divmod_nat m n = ( let k = integer_of_nat m; l = integer_of_nat n in map_prod nat_of_integer nat_of_integer (if k = 0 then (0, 0) else if l = 0 then (0, k) else Code_Numeral.divmod_abs k l))" apply (simp add: prod_eq_iff (*‹(?s = ?t) = (fst ?s = fst ?t ∧ snd ?s = snd ?t)›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) Euclidean_Rings.divmod_nat_def (*‹Euclidean_Rings.divmod_nat ?m ?n = (?m div ?n, ?m mod ?n)›*)) (*goal: ‹Euclidean_Rings.divmod_nat (m::nat) (n::nat) = (let k::integer = integer_of_nat m; l::integer = integer_of_nat n in map_prod nat_of_integer nat_of_integer (if k = (0::integer) then (0::integer, 0::integer) else if l = (0::integer) then (0::integer, k) else Code_Numeral.divmod_abs k l))›*) apply transfer (*goal: ‹(integer_of_nat n = 0 ⟶ (integer_of_nat m = 0 ⟶ m div n = 0 ∧ m mod n = 0) ∧ (integer_of_nat m ≠ 0 ⟶ m div n = 0 ∧ m mod n = m)) ∧ (integer_of_nat n ≠ 0 ⟶ (integer_of_nat m = 0 ⟶ m div n = 0 ∧ m mod n = 0) ∧ (integer_of_nat m ≠ 0 ⟶ m div n = nat_of_integer (¦integer_of_nat m¦ div ¦integer_of_nat n¦) ∧ m mod n = nat_of_integer (¦integer_of_nat m¦ mod ¦integer_of_nat n¦)))›*) by (simp add: nat_div_distrib (*‹(0::int) ≤ (?x::int) ⟹ nat (?x div (?y::int)) = nat ?x div nat ?y›*) nat_mod_distrib (*‹⟦(0::int) ≤ (?x::int); (0::int) ≤ (?y::int)⟧ ⟹ nat (?x mod ?y) = nat ?x mod nat ?y›*)) end lemma [code]: "divmod m n = map_prod nat_of_integer nat_of_integer (divmod m n)" apply (simp only: prod_eq_iff (*‹((?s::?'a × ?'b) = (?t::?'a × ?'b)) = (fst ?s = fst ?t ∧ snd ?s = snd ?t)›*) divmod_def (*‹divmod (?m::num) (?n::num) = (numeral ?m div numeral ?n, numeral ?m mod numeral ?n)›*) map_prod_def (*‹map_prod (?f::?'a ⇒ ?'c) (?g::?'b ⇒ ?'d) = (λ(x::?'a, y::?'b). (?f x, ?g y))›*) case_prod_beta (*‹(case ?p::?'b × ?'c of (x::?'b, xa::?'c) ⇒ (?f::?'b ⇒ ?'c ⇒ ?'a) x xa) = ?f (fst ?p) (snd ?p)›*) fst_conv (*‹fst (?x1.0::?'a, ?x2.0::?'b) = ?x1.0›*) snd_conv (*‹snd (?x1.0::?'aa, ?x2.0::?'a) = ?x2.0›*)) (*goal: ‹divmod (m::num) (n::num) = map_prod nat_of_integer nat_of_integer (divmod m n)›*) apply transfer (*goal: ‹numeral m div numeral n = nat_of_integer (numeral m div numeral n) ∧ numeral m mod numeral n = nat_of_integer (numeral m mod numeral n)›*) by (simp only: nat_div_distrib (*‹0 ≤ ?x ⟹ nat (?x div ?y) = nat ?x div nat ?y›*) nat_mod_distrib (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ nat (?x mod ?y) = nat ?x mod nat ?y›*) zero_le_numeral (*‹0 ≤ numeral ?n›*) nat_numeral (*‹nat (numeral ?k) = numeral ?k›*)) lemma [code]: "HOL.equal m n = HOL.equal (of_nat m :: integer) (of_nat n)" apply transfer (*goal: ‹equal_class.equal m n = equal_class.equal (of_nat m) (of_nat n)›*) by (simp add: equal (*‹equal_class.equal = (=)›*)) lemma [code]: "m ≤ n ⟷ (of_nat m :: integer) ≤ of_nat n" by simp lemma [code]: "m < n ⟷ (of_nat m :: integer) < of_nat n" by simp lemma num_of_nat_code [code]: "num_of_nat = num_of_integer ∘ of_nat" apply transfer (*goal: ‹num_of_nat = num_of_integer ∘ of_nat›*) by (simp add: fun_eq_iff (*‹((?f::?'a ⇒ ?'b) = (?g::?'a ⇒ ?'b)) = (∀x::?'a. ?f x = ?g x)›*)) end lemma (in semiring_1) of_nat_code_if: "of_nat n = (if n = 0 then 0 else let (m, q) = Euclidean_Rings.divmod_nat n 2; m' = 2 * of_nat m in if q = 0 then m' else m' + 1)" apply (cases n) (*goals: 1. ‹n = 0 ⟹ of_nat n = (if n = 0 then 0 else let (m, q) = Euclidean_Rings.divmod_nat n 2; m' = 2 * of_nat m in if q = 0 then m' else m' + 1)› 2. ‹⋀nat. n = Suc nat ⟹ of_nat n = (if n = 0 then 0 else let (m, q) = Euclidean_Rings.divmod_nat n 2; m' = 2 * of_nat m in if q = 0 then m' else m' + 1)› discuss goal 1*) apply (simp add: Let_def (*‹Let (?s::?'a) (?f::?'a ⇒ ?'b) ≡ ?f ?s›*) Euclidean_Rings.divmod_nat_def (*‹Euclidean_Rings.divmod_nat (?m::nat) (?n::nat) = (?m div ?n, ?m mod ?n)›*) ac_simps (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)› ‹(?a::?'a) * (?b::?'a) * (?c::?'a) = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)› ‹(((?a::bool) ∧ (?b::bool)) ∧ (?c::bool)) = (?a ∧ ?b ∧ ?c)› ‹((?a::bool) ∧ (?b::bool)) = (?b ∧ ?a)› ‹((?b::bool) ∧ (?a::bool) ∧ (?c::bool)) = (?a ∧ ?b ∧ ?c)› ‹(((?a::bool) ∨ (?b::bool)) ∨ (?c::bool)) = (?a ∨ ?b ∨ ?c)› ‹((?a::bool) ∨ (?b::bool)) = (?b ∨ ?a)› ‹((?b::bool) ∨ (?a::bool) ∨ (?c::bool)) = (?a ∨ ?b ∨ ?c)› and more 34 facts*) flip: of_nat_numeral (*‹of_nat (numeral (?n::num)) = numeral ?n›*) of_nat_mult (*‹of_nat ((?m::nat) * (?n::nat)) = of_nat ?m * of_nat ?n›*) minus_mod_eq_mult_div (*‹(?a::?'a) - ?a mod (?b::?'a) = ?b * (?a div ?b)›*)) (*discuss goal 2*) apply (simp add: Let_def (*‹Let (?s::?'a::type) (?f::?'a::type ⇒ ?'b::type) ≡ ?f ?s›*) Euclidean_Rings.divmod_nat_def (*‹Euclidean_Rings.divmod_nat (?m::nat) (?n::nat) = (?m div ?n, ?m mod ?n)›*) ac_simps (*‹(?a::?'a::semigroup_add) + (?b::?'a::semigroup_add) + (?c::?'a::semigroup_add) = ?a + (?b + ?c)› ‹(?a::?'a::ab_semigroup_add) + (?b::?'a::ab_semigroup_add) = ?b + ?a› ‹(?b::?'a::ab_semigroup_add) + ((?a::?'a::ab_semigroup_add) + (?c::?'a::ab_semigroup_add)) = ?a + (?b + ?c)› ‹(?a::?'a::semigroup_mult) * (?b::?'a::semigroup_mult) * (?c::?'a::semigroup_mult) = ?a * (?b * ?c)› ‹(?a::?'a::ab_semigroup_mult) * (?b::?'a::ab_semigroup_mult) = ?b * ?a› ‹(?b::?'a::ab_semigroup_mult) * ((?a::?'a::ab_semigroup_mult) * (?c::?'a::ab_semigroup_mult)) = ?a * (?b * ?c)› ‹(((?a::bool) ∧ (?b::bool)) ∧ (?c::bool)) = (?a ∧ ?b ∧ ?c)› ‹((?a::bool) ∧ (?b::bool)) = (?b ∧ ?a)› ‹((?b::bool) ∧ (?a::bool) ∧ (?c::bool)) = (?a ∧ ?b ∧ ?c)› ‹(((?a::bool) ∨ (?b::bool)) ∨ (?c::bool)) = (?a ∨ ?b ∨ ?c)› ‹((?a::bool) ∨ (?b::bool)) = (?b ∨ ?a)› ‹((?b::bool) ∨ (?a::bool) ∨ (?c::bool)) = (?a ∨ ?b ∨ ?c)› and more 34 facts*) flip: of_nat_numeral (*‹of_nat (numeral (?n::num)) = numeral ?n›*) of_nat_mult (*‹of_nat ((?m::nat) * (?n::nat)) = of_nat ?m * of_nat ?n›*) minus_mod_eq_mult_div (*‹(?a::?'a::semiring_modulo) - ?a mod (?b::?'a::semiring_modulo) = ?b * (?a div ?b)›*)) (*proven 2 subgoals*) . declare of_nat_code_if [code] definition int_of_nat :: "nat ⇒ int" where [code_abbrev]: "int_of_nat = of_nat" lemma [code]: "int_of_nat n = int_of_integer (of_nat n)" by (simp add: int_of_nat_def (*‹int_of_nat = int›*)) lemma [code abstract]: "integer_of_nat (nat k) = max 0 (integer_of_int k)" including integer.lifting apply transfer (*goal: ‹integer_of_nat (nat (k::int)) = max (0::integer) (integer_of_int k)›*) by auto definition char_of_nat :: "nat ⇒ char" where [code_abbrev]: "char_of_nat = char_of" definition nat_of_char :: "char ⇒ nat" where [code_abbrev]: "nat_of_char = of_char" lemma [code]: "char_of_nat = char_of_integer ∘ integer_of_nat" including integer.lifting unfolding char_of_integer_def char_of_nat_def (*goal: ‹char_of = char_of ∘ integer_of_nat›*) apply transfer (*goal: ‹char_of = char_of ∘ integer_of_nat›*) by (simp add: fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*)) lemma [code abstract]: "integer_of_nat (nat_of_char c) = integer_of_char c" apply (cases c) (*goal: ‹integer_of_nat (nat_of_char c) = integer_of_char c›*) by (simp add: nat_of_char_def (*‹nat_of_char = of_char›*) integer_of_char_def (*‹integer_of_char = of_char›*) integer_of_nat_eq_of_nat (*‹integer_of_nat = of_nat›*)) lemma term_of_nat_code [code]: ― ‹Use \<^term>‹Code_Numeral.nat_of_integer› in term reconstruction instead of \<^term>‹Code_Target_Nat.Nat› such that reconstructed terms can be fed back to the code generator› "term_of_class.term_of n = Code_Evaluation.App (Code_Evaluation.Const (STR ''Code_Numeral.nat_of_integer'') (typerep.Typerep (STR ''fun'') [typerep.Typerep (STR ''Code_Numeral.integer'') [], typerep.Typerep (STR ''Nat.nat'') []])) (term_of_class.term_of (integer_of_nat n))" by (simp add: term_of_anything (*‹term_of_class.term_of ?x ≡ ?t›*)) lemma nat_of_integer_code_post [code_post]: "nat_of_integer 0 = 0" "nat_of_integer 1 = 1" "nat_of_integer (numeral k) = numeral k" including integer.lifting (*goals: 1. ‹nat_of_integer (0::integer) = (0::nat)› 2. ‹nat_of_integer (1::integer) = (1::nat)› 3. ‹nat_of_integer (numeral (k::num)) = numeral k› discuss goal 1*) apply transfer (*top goal: ‹nat_of_integer 0 = 0› and 2 goals remain*) apply simp (*discuss goal 2*) apply transfer (*top goal: ‹nat_of_integer (1::integer) = (1::nat)› and 1 goal remains*) apply simp (*discuss goal 3*) apply transfer (*goal: ‹nat_of_integer (numeral k) = numeral k›*) apply simp (*proven 3 subgoals*) . code_identifier code_module Code_Target_Nat ⇀ (SML) Arith and (OCaml) Arith and (Haskell) Arith end
{ "path": "Isabelle2024/src/HOL/Library/Code_Target_Nat.thy", "repo": "Isabelle2024", "sha": "33af182eacc76c7b30adaad7813767ac102c56dd4b6d38e8d24f5734b24266c9" }
chapter ‹Arithmetic Constructs› text ‹Less genereric syntax, more committed towards embedding arithmetics› (*<*) theory Syntax_Arith imports Syntax begin (*>*) text ‹(An embedding of) the syntax of arithmetic, obtained by adding plus and times› locale Syntax_Arith_aux = Syntax_with_Connectives_Rename var trm fmla Var FvarsT substT Fvars subst eql cnj imp all exi + Syntax_with_Numerals_and_Connectives_False_Disj var trm fmla Var FvarsT substT Fvars subst eql cnj imp all exi fls dsj num for var :: "'var set" and trm :: "'trm set" and fmla :: "'fmla set" and Var FvarsT substT Fvars subst and eql cnj imp all exi and fls and dsj and num + fixes zer :: "'trm" and suc :: "'trm ⇒ 'trm" and pls :: "'trm ⇒ 'trm ⇒ 'trm" and tms :: "'trm ⇒ 'trm ⇒ 'trm" assumes Fvars_zero[simp,intro!]: "FvarsT zer = {}" and substT_zer[simp]: "⋀ t x. t ∈ trm ⟹ x ∈ var ⟹ substT zer t x = zer" and suc[simp]: "⋀t. t ∈ trm ⟹ suc t ∈ trm" and FvarsT_suc[simp]: "⋀ t. t ∈ trm ⟹ FvarsT (suc t) = FvarsT t" and substT_suc[simp]: "⋀ t1 t x. t1 ∈ trm ⟹ t ∈ trm ⟹ x ∈ var ⟹ substT (suc t1) t x = suc (substT t1 t x)" and pls[simp]: "⋀ t1 t2. t1 ∈ trm ⟹ t2 ∈ trm ⟹ pls t1 t2 ∈ trm" and Fvars_pls[simp]: "⋀ t1 t2. t1 ∈ trm ⟹ t2 ∈ trm ⟹ FvarsT (pls t1 t2) = FvarsT t1 ∪ FvarsT t2" and substT_pls[simp]: "⋀ t1 t2 t x. t1 ∈ trm ⟹ t2 ∈ trm ⟹ t ∈ trm ⟹ x ∈ var ⟹ substT (pls t1 t2) t x = pls (substT t1 t x) (substT t2 t x)" and tms[simp]: "⋀ t1 t2. t1 ∈ trm ⟹ t2 ∈ trm ⟹ tms t1 t2 ∈ trm" and Fvars_tms[simp]: "⋀ t1 t2. t1 ∈ trm ⟹ t2 ∈ trm ⟹ FvarsT (tms t1 t2) = FvarsT t1 ∪ FvarsT t2" and substT_tms[simp]: "⋀ t1 t2 t x. t1 ∈ trm ⟹ t2 ∈ trm ⟹ t ∈ trm ⟹ x ∈ var ⟹ substT (tms t1 t2) t x = tms (substT t1 t x) (substT t2 t x)" begin text ‹The embedding of numbers into our abstract notion of numerals (not required to be surjective)› fun Num :: "nat ⇒ 'trm" where "Num 0 = zer" |"Num (Suc n) = suc (Num n)" end ― ‹context @{locale Syntax_Arith_aux}› locale Syntax_Arith = Syntax_Arith_aux var trm fmla Var FvarsT substT Fvars subst eql cnj imp all exi fls dsj num zer suc pls tms for var :: "'var set" and trm :: "'trm set" and fmla :: "'fmla set" and Var FvarsT substT Fvars subst and eql cnj imp all exi and fls and dsj and num zer suc pls tms + assumes ― ‹We assume that numbers are the only numerals:› num_Num: "num = range Num" begin lemma Num[simp,intro!]: "Num n ∈ num" using num_Num (*‹(num::'trm::type set) = range Num›*) by auto lemma FvarsT_Num[simp]: "FvarsT (Num n) = {}" by auto lemma substT_Num[simp]: "x ∈ var ⟹ t ∈ trm ⟹ substT (Num n) t x = Num n" by auto lemma zer[simp,intro!]: "zer ∈ num" and suc_num[simp]: "⋀n. n ∈ num ⟹ suc n ∈ num" (*goals: 1. ‹zer ∈ num› 2. ‹⋀n. n ∈ num ⟹ suc n ∈ num› discuss goal 1*) apply (metis Num (*‹Num ?n ∈ num›*) Num.simps( (*‹Num 0 = zer›*) 1)) (*discuss goal 2*) apply (metis Num (*‹Num ?n ∈ num›*) Num.simps( (*‹Num (Suc ?n) = suc (Num ?n)›*) 2) imageE (*‹⟦?b ∈ ?f ` ?A; ⋀x. ⟦?b = ?f x; x ∈ ?A⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) num_Num (*‹num = range Num›*)) (*proven 2 subgoals*) . section ‹Arithmetic Terms› text ‹Arithmetic terms are inductively defined to contain the numerals and the variables and be closed under the arithmetic operators:› inductive_set atrm :: "'trm set" where atrm_num[simp]: "n ∈ num ⟹ n ∈ atrm" |atrm_Var[simp,intro]: "x ∈ var ⟹ Var x ∈ atrm" |atrm_suc[simp,intro]: "t ∈ atrm ⟹ suc t ∈ atrm" |atrm_pls[simp,intro]: "t ∈ atrm ⟹ t' ∈ atrm ⟹ pls t t' ∈ atrm" |atrm_tms[simp,intro]: "t ∈ atrm ⟹ t' ∈ atrm ⟹ tms t t' ∈ atrm" lemma atrm_imp_trm[simp]: assumes "t ∈ atrm" shows "t ∈ trm" using assms (*‹t ∈ atrm›*) apply induct (*goals: 1. ‹⋀n. n ∈ num ⟹ n ∈ trm› 2. ‹⋀x. x ∈ var ⟹ Var x ∈ trm› 3. ‹⋀t. ⟦t ∈ atrm; t ∈ trm⟧ ⟹ suc t ∈ trm› 4. ‹⋀t t'. ⟦t ∈ atrm; t ∈ trm; t' ∈ atrm; t' ∈ trm⟧ ⟹ pls t t' ∈ trm› 5. ‹⋀t t'. ⟦t ∈ atrm; t ∈ trm; t' ∈ atrm; t' ∈ trm⟧ ⟹ tms t t' ∈ trm› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . lemma atrm_trm: "atrm ⊆ trm" using atrm_imp_trm (*‹(?t::'trm) ∈ atrm ⟹ ?t ∈ (trm::'trm set)›*) by auto lemma zer_atrm[simp]: "zer ∈ atrm" by auto lemma Num_atrm[simp]: "Num n ∈ atrm" by auto lemma substT_atrm[simp]: assumes "r ∈ atrm" and "x ∈ var" and "t ∈ atrm" shows "substT r t x ∈ atrm" using assms (*‹r ∈ atrm› ‹x ∈ var› ‹t ∈ atrm›*) apply induct (*goals: 1. ‹⋀n. ⟦n ∈ num; x ∈ var; t ∈ atrm⟧ ⟹ substT n t x ∈ atrm› 2. ‹⋀xa. ⟦xa ∈ var; x ∈ var; t ∈ atrm⟧ ⟹ substT (Var xa) t x ∈ atrm› 3. ‹⋀ta. ⟦ta ∈ atrm; ⟦x ∈ var; t ∈ atrm⟧ ⟹ substT ta t x ∈ atrm; x ∈ var; t ∈ atrm⟧ ⟹ substT (suc ta) t x ∈ atrm› 4. ‹⋀ta t'. ⟦ta ∈ atrm; ⟦x ∈ var; t ∈ atrm⟧ ⟹ substT ta t x ∈ atrm; t' ∈ atrm; ⟦x ∈ var; t ∈ atrm⟧ ⟹ substT t' t x ∈ atrm; x ∈ var; t ∈ atrm⟧ ⟹ substT (pls ta t') t x ∈ atrm› 5. ‹⋀ta t'. ⟦ta ∈ atrm; ⟦x ∈ var; t ∈ atrm⟧ ⟹ substT ta t x ∈ atrm; t' ∈ atrm; ⟦x ∈ var; t ∈ atrm⟧ ⟹ substT t' t x ∈ atrm; x ∈ var; t ∈ atrm⟧ ⟹ substT (tms ta t') t x ∈ atrm› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . text ‹Whereas we did not assume the rich set of formula-substitution properties to hold for all terms, we can prove that these properties hold for arithmetic terms.› text ‹Properties for arithmetic terms corresponding to the axioms for formulas:› lemma FvarsT_substT: assumes "s ∈ atrm" "t ∈ trm" "x ∈ var" shows "FvarsT (substT s t x) = (FvarsT s - {x}) ∪ (if x ∈ FvarsT s then FvarsT t else {})" using assms (*‹s ∈ atrm› ‹t ∈ trm› ‹x ∈ var›*) apply induct (*goals: 1. ‹⋀n. ⟦n ∈ num; t ∈ trm; x ∈ var⟧ ⟹ FvarsT (substT n t x) = FvarsT n - {x} ∪ (if x ∈ FvarsT n then FvarsT t else {})› 2. ‹⋀xa. ⟦xa ∈ var; t ∈ trm; x ∈ var⟧ ⟹ FvarsT (substT (Var xa) t x) = FvarsT (Var xa) - {x} ∪ (if x ∈ FvarsT (Var xa) then FvarsT t else {})› 3. ‹⋀ta. ⟦ta ∈ atrm; ⟦t ∈ trm; x ∈ var⟧ ⟹ FvarsT (substT ta t x) = FvarsT ta - {x} ∪ (if x ∈ FvarsT ta then FvarsT t else {}); t ∈ trm; x ∈ var⟧ ⟹ FvarsT (substT (suc ta) t x) = FvarsT (suc ta) - {x} ∪ (if x ∈ FvarsT (suc ta) then FvarsT t else {})› 4. ‹⋀ta t'. ⟦ta ∈ atrm; ⟦t ∈ trm; x ∈ var⟧ ⟹ FvarsT (substT ta t x) = FvarsT ta - {x} ∪ (if x ∈ FvarsT ta then FvarsT t else {}); t' ∈ atrm; ⟦t ∈ trm; x ∈ var⟧ ⟹ FvarsT (substT t' t x) = FvarsT t' - {x} ∪ (if x ∈ FvarsT t' then FvarsT t else {}); t ∈ trm; x ∈ var⟧ ⟹ FvarsT (substT (pls ta t') t x) = FvarsT (pls ta t') - {x} ∪ (if x ∈ FvarsT (pls ta t') then FvarsT t else {})› 5. ‹⋀ta t'. ⟦ta ∈ atrm; ⟦t ∈ trm; x ∈ var⟧ ⟹ FvarsT (substT ta t x) = FvarsT ta - {x} ∪ (if x ∈ FvarsT ta then FvarsT t else {}); t' ∈ atrm; ⟦t ∈ trm; x ∈ var⟧ ⟹ FvarsT (substT t' t x) = FvarsT t' - {x} ∪ (if x ∈ FvarsT t' then FvarsT t else {}); t ∈ trm; x ∈ var⟧ ⟹ FvarsT (substT (tms ta t') t x) = FvarsT (tms ta t') - {x} ∪ (if x ∈ FvarsT (tms ta t') then FvarsT t else {})› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . lemma substT_compose_eq_or: assumes "s ∈ atrm" "t1 ∈ trm" "t2 ∈ trm" "x1 ∈ var" "x2 ∈ var" and "x1 = x2 ∨ x2 ∉ FvarsT s" shows "substT (substT s t1 x1) t2 x2 = substT s (substT t1 t2 x2) x1" using assms (*‹(s::'trm) ∈ atrm› ‹t1 ∈ trm› ‹t2 ∈ trm› ‹x1 ∈ var› ‹x2 ∈ var› ‹x1 = x2 ∨ x2 ∉ FvarsT s›*) apply induct (*goal: ‹substT (substT s t1 x1) t2 x2 = substT s (substT t1 t2 x2) x1›*) subgoal for by auto subgoal for by auto subgoal for by (metis FvarsT_suc (*‹(?t::'trm) ∈ (trm::'trm set) ⟹ (FvarsT::'trm ⇒ 'var set) ((suc::'trm ⇒ 'trm) ?t) = FvarsT ?t›*) atrm_imp_trm (*‹(?t::'trm) ∈ atrm ⟹ ?t ∈ (trm::'trm set)›*) substT (*‹⟦(?t1.0::'trm) ∈ (trm::'trm set); (?t::'trm) ∈ trm; (?x::'var) ∈ (var::'var set)⟧ ⟹ (substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) ?t1.0 ?t ?x ∈ trm›*) substT_suc (*‹⟦(?t1.0::'trm) ∈ (trm::'trm set); (?t::'trm) ∈ trm; (?x::'var) ∈ (var::'var set)⟧ ⟹ (substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) ((suc::'trm ⇒ 'trm) ?t1.0) ?t ?x = suc (substT ?t1.0 ?t ?x)›*)) subgoal for by (metis Fvars_pls (*‹⟦?t1.0 ∈ trm; ?t2.0 ∈ trm⟧ ⟹ FvarsT (pls ?t1.0 ?t2.0) = FvarsT ?t1.0 ∪ FvarsT ?t2.0›*) UnCI (*‹(?c ∉ ?B ⟹ ?c ∈ ?A) ⟹ ?c ∈ ?A ∪ ?B›*) atrm_imp_trm (*‹?t ∈ atrm ⟹ ?t ∈ trm›*) substT (*‹⟦?t1.0 ∈ trm; ?t ∈ trm; ?x ∈ var⟧ ⟹ substT ?t1.0 ?t ?x ∈ trm›*) substT_pls (*‹⟦?t1.0 ∈ trm; ?t2.0 ∈ trm; ?t ∈ trm; ?x ∈ var⟧ ⟹ substT (pls ?t1.0 ?t2.0) ?t ?x = pls (substT ?t1.0 ?t ?x) (substT ?t2.0 ?t ?x)›*)) subgoal for by (metis Fvars_tms (*‹⟦?t1.0 ∈ trm; ?t2.0 ∈ trm⟧ ⟹ FvarsT (tms ?t1.0 ?t2.0) = FvarsT ?t1.0 ∪ FvarsT ?t2.0›*) UnCI (*‹(?c ∉ ?B ⟹ ?c ∈ ?A) ⟹ ?c ∈ ?A ∪ ?B›*) atrm_imp_trm (*‹?t ∈ atrm ⟹ ?t ∈ trm›*) substT (*‹⟦?t1.0 ∈ trm; ?t ∈ trm; ?x ∈ var⟧ ⟹ substT ?t1.0 ?t ?x ∈ trm›*) substT_tms (*‹⟦?t1.0 ∈ trm; ?t2.0 ∈ trm; ?t ∈ trm; ?x ∈ var⟧ ⟹ substT (tms ?t1.0 ?t2.0) ?t ?x = tms (substT ?t1.0 ?t ?x) (substT ?t2.0 ?t ?x)›*)) . lemma substT_compose_diff: assumes "s ∈ atrm" "t1 ∈ trm" "t2 ∈ trm" "x1 ∈ var" "x2 ∈ var" and "x1 ≠ x2" "x1 ∉ FvarsT t2" shows "substT (substT s t1 x1) t2 x2 = substT (substT s t2 x2) (substT t1 t2 x2) x1" using assms (*‹s ∈ atrm› ‹(t1::'trm::type) ∈ (trm::'trm::type set)› ‹t2 ∈ trm› ‹x1 ∈ var› ‹x2 ∈ var› ‹x1 ≠ x2› ‹x1 ∉ FvarsT t2›*) apply induct (*goal: ‹substT (substT s t1 x1) t2 x2 = substT (substT s t2 x2) (substT t1 t2 x2) x1›*) subgoal for by auto subgoal for by auto subgoal for by (metis atrm_imp_trm (*‹?t ∈ atrm ⟹ ?t ∈ trm›*) substT (*‹⟦?t1.0 ∈ trm; ?t ∈ trm; ?x ∈ var⟧ ⟹ substT ?t1.0 ?t ?x ∈ trm›*) substT_suc (*‹⟦?t1.0 ∈ trm; ?t ∈ trm; ?x ∈ var⟧ ⟹ substT (suc ?t1.0) ?t ?x = suc (substT ?t1.0 ?t ?x)›*)) subgoal for by (metis atrm_imp_trm (*‹?t ∈ atrm ⟹ ?t ∈ trm›*) substT (*‹⟦?t1.0 ∈ trm; ?t ∈ trm; ?x ∈ var⟧ ⟹ substT ?t1.0 ?t ?x ∈ trm›*) substT_pls (*‹⟦?t1.0 ∈ trm; ?t2.0 ∈ trm; ?t ∈ trm; ?x ∈ var⟧ ⟹ substT (pls ?t1.0 ?t2.0) ?t ?x = pls (substT ?t1.0 ?t ?x) (substT ?t2.0 ?t ?x)›*)) subgoal for by (metis atrm_imp_trm (*‹?t ∈ atrm ⟹ ?t ∈ trm›*) substT (*‹⟦?t1.0 ∈ trm; ?t ∈ trm; ?x ∈ var⟧ ⟹ substT ?t1.0 ?t ?x ∈ trm›*) substT_tms (*‹⟦?t1.0 ∈ trm; ?t2.0 ∈ trm; ?t ∈ trm; ?x ∈ var⟧ ⟹ substT (tms ?t1.0 ?t2.0) ?t ?x = tms (substT ?t1.0 ?t ?x) (substT ?t2.0 ?t ?x)›*)) . lemma substT_same_Var[simp]: assumes "s ∈ atrm" "x ∈ var" shows "substT s (Var x) x = s" using assms (*‹s ∈ atrm› ‹(x::'var::type) ∈ (var::'var::type set)›*) apply induct (*goals: 1. ‹⋀n::'trm. ⟦n ∈ (num::'trm set); (x::'var) ∈ (var::'var set)⟧ ⟹ (substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) n ((Var::'var ⇒ 'trm) x) x = n› 2. ‹⋀xa::'var. ⟦xa ∈ (var::'var set); (x::'var) ∈ var⟧ ⟹ (substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) ((Var::'var ⇒ 'trm) xa) (Var x) x = Var xa› 3. ‹⋀t::'trm. ⟦t ∈ atrm; (x::'var) ∈ (var::'var set) ⟹ (substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) t ((Var::'var ⇒ 'trm) x) x = t; x ∈ var⟧ ⟹ substT ((suc::'trm ⇒ 'trm) t) (Var x) x = suc t› 4. ‹⋀(t::'trm) t'::'trm. ⟦t ∈ atrm; (x::'var) ∈ (var::'var set) ⟹ (substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) t ((Var::'var ⇒ 'trm) x) x = t; t' ∈ atrm; x ∈ var ⟹ substT t' (Var x) x = t'; x ∈ var⟧ ⟹ substT ((pls::'trm ⇒ 'trm ⇒ 'trm) t t') (Var x) x = pls t t'› 5. ‹⋀(t::'trm) t'::'trm. ⟦t ∈ atrm; (x::'var) ∈ (var::'var set) ⟹ (substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) t ((Var::'var ⇒ 'trm) x) x = t; t' ∈ atrm; x ∈ var ⟹ substT t' (Var x) x = t'; x ∈ var⟧ ⟹ substT ((tms::'trm ⇒ 'trm ⇒ 'trm) t t') (Var x) x = tms t t'› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . text ‹... and corresponding to some corollaries we proved for formulas (with essentially the same proofs):› lemma in_FvarsT_substTD: "y ∈ FvarsT (substT r t x) ⟹ r ∈ atrm ⟹ t ∈ trm ⟹ x ∈ var ⟹ y ∈ (FvarsT r - {x}) ∪ (if x ∈ FvarsT r then FvarsT t else {})" using FvarsT_substT (*‹⟦?s ∈ atrm; ?t ∈ trm; ?x ∈ var⟧ ⟹ FvarsT (substT ?s ?t ?x) = FvarsT ?s - {?x} ∪ (if ?x ∈ FvarsT ?s then FvarsT ?t else {})›*) by auto lemma substT_compose_same: "⋀ s t1 t2 x. s ∈ atrm ⟹ t1 ∈ trm ⟹ t2 ∈ trm ⟹ x ∈ var ⟹ substT (substT s t1 x) t2 x = substT s (substT t1 t2 x) x" using substT_compose_eq_or (*‹⟦?s ∈ atrm; ?t1.0 ∈ trm; ?t2.0 ∈ trm; ?x1.0 ∈ var; ?x2.0 ∈ var; ?x1.0 = ?x2.0 ∨ ?x2.0 ∉ FvarsT ?s⟧ ⟹ substT (substT ?s ?t1.0 ?x1.0) ?t2.0 ?x2.0 = substT ?s (substT ?t1.0 ?t2.0 ?x2.0) ?x1.0›*) by blast lemma substT_substT[simp]: assumes s[simp]: "s ∈ atrm" and t[simp]:"t ∈ trm" and x[simp]:"x ∈ var" and y[simp]:"y ∈ var" assumes yy: "x ≠ y" "y ∉ FvarsT s" shows "substT (substT s (Var y) x) t y = substT s t x" using substT_compose_eq_or[OF s _ t x y, of "Var y"] (*‹⟦Var y ∈ trm; x = y ∨ y ∉ FvarsT s⟧ ⟹ substT (substT s (Var y) x) t y = substT s (substT (Var y) t y) x›*) using subst_notIn (*‹⟦?φ ∈ fmla; ?t ∈ trm; ?x ∈ var; ?x ∉ Fvars ?φ⟧ ⟹ subst ?φ ?t ?x = ?φ›*) yy (*‹x ≠ y› ‹y ∉ FvarsT s›*) by simp lemma substT_comp: "⋀ x y s t. s ∈ atrm ⟹ t ∈ trm ⟹ x ∈ var ⟹ y ∈ var ⟹ x ≠ y ⟹ y ∉ FvarsT t ⟹ substT (substT s (Var x) y) t x = substT (substT s t x) t y" by (simp add: substT_compose_diff (*‹⟦(?s::'trm) ∈ atrm; (?t1.0::'trm) ∈ (trm::'trm set); (?t2.0::'trm) ∈ trm; (?x1.0::'var) ∈ (var::'var set); (?x2.0::'var) ∈ var; ?x1.0 ≠ ?x2.0; ?x1.0 ∉ (FvarsT::'trm ⇒ 'var set) ?t2.0⟧ ⟹ (substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) (substT ?s ?t1.0 ?x1.0) ?t2.0 ?x2.0 = substT (substT ?s ?t2.0 ?x2.0) (substT ?t1.0 ?t2.0 ?x2.0) ?x1.0›*)) text ‹Now the corresponding development of parallel substitution for arithmetic terms:› lemma rawpsubstT_atrm[simp,intro]: assumes "r ∈ atrm" and "snd ` (set txs) ⊆ var" and "fst ` (set txs) ⊆ atrm" shows "rawpsubstT r txs ∈ atrm" using assms (*‹(r::'trm::type) ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set (txs::('trm × 'var) list) ⊆ atrm›*) apply (induct txs arbitrary: r) (*goals: 1. ‹⋀r. ⟦r ∈ atrm; snd ` set [] ⊆ var; fst ` set [] ⊆ atrm⟧ ⟹ rawpsubstT r [] ∈ atrm› 2. ‹⋀a txs r. ⟦⋀r. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm⟧ ⟹ rawpsubstT r txs ∈ atrm; r ∈ atrm; snd ` set (a # txs) ⊆ var; fst ` set (a # txs) ⊆ atrm⟧ ⟹ rawpsubstT r (a # txs) ∈ atrm› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma psubstT_atrm[simp,intro]: assumes "r ∈ atrm" and "snd ` (set txs) ⊆ var" and "fst ` (set txs) ⊆ atrm" shows "psubstT r txs ∈ atrm" proof (-) (*goal: ‹psubstT r txs ∈ atrm›*) have txs_trm: "fst ` (set txs) ⊆ trm" using assms (*‹r ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm›*) atrm_trm (*‹atrm ⊆ trm›*) by auto define us where us: "us ≡ getFrN (map snd txs) (r # map fst txs) [] (length txs)" have us_facts: "set us ⊆ var" "set us ∩ FvarsT r = {}" "set us ∩ ⋃ (FvarsT ` (fst ` (set txs))) = {}" "set us ∩ snd ` (set txs) = {}" "length us = length txs" "distinct us" using assms(1,2) (*‹r ∈ atrm› ‹snd ` set txs ⊆ var›*) txs_trm (*‹fst ` set txs ⊆ trm›*) unfolding us (*goals: 1. ‹set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ⊆ var› 2. ‹set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ FvarsT r = {}› 3. ‹set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ ⋃ (FvarsT ` fst ` set txs) = {}› 4. ‹set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ snd ` set txs = {}› 5. ‹length (getFrN (map snd txs) (r # map fst txs) [] (length txs)) = length txs› 6. ‹distinct (getFrN (map snd txs) (r # map fst txs) [] (length txs))›*) using getFrN_FvarsT[of "map snd txs" "r # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd (txs::('trm × 'var) list)) ⊆ (var::'var set); set ((r::'trm) # map fst txs) ⊆ (trm::'trm set); set [] ⊆ (fmla::'fmla set); (?t::'trm) ∈ set (r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ (FvarsT::'trm ⇒ 'var set) ?t = {}›*) getFrN_Fvars[of "map snd txs" "r # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; ?φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ Fvars ?φ = {}›*) getFrN_var[of "map snd txs" "r # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd (txs::('trm × 'var) list)) ⊆ (var::'var set); set ((r::'trm) # map fst txs) ⊆ (trm::'trm set); set [] ⊆ (fmla::'fmla set); (?t::'trm) ∈ set (r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}›*) getFrN_length[of "map snd txs" "r # map fst txs" "[]" "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r # map fst txs) [] (length txs)) = length txs›*) getFrN_distinct[of "map snd txs" "r # map fst txs" "[]" "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ distinct (getFrN (map snd txs) (r # map fst txs) [] (length txs))›*) apply - (*top goal: ‹set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ⊆ var› and 5 goals remain*) subgoal for by auto subgoal for by auto subgoal for by auto subgoal for by force (*goals: 1. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; ⋀t. ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ FvarsT t = {}; ⋀φ. ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ Fvars φ = {}; ⋀t. ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}; ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r # map fst txs) [] (length txs)) = length txs; ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ distinct (getFrN (map snd txs) (r # map fst txs) [] (length txs))⟧ ⟹ length (getFrN (map snd txs) (r # map fst txs) [] (length txs)) = length txs› 2. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; ⋀t. ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ FvarsT t = {}; ⋀φ. ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ Fvars φ = {}; ⋀t. ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}; ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r # map fst txs) [] (length txs)) = length txs; ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ distinct (getFrN (map snd txs) (r # map fst txs) [] (length txs))⟧ ⟹ distinct (getFrN (map snd txs) (r # map fst txs) [] (length txs))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . show "?thesis" (*goal: ‹psubstT (r::'trm) (txs::('trm × 'var) list) ∈ atrm›*) using assms (*‹r ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm›*) us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT r = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct us›*) unfolding psubstT_def (*goal: ‹(let xs = map snd txs; ts = map fst txs; us = getFrN xs (r # ts) [] (length xs) in rawpsubstT (rawpsubstT r (zip (map Var us) xs)) (zip ts us)) ∈ atrm›*) by (force simp: Let_def (*‹Let (?s::?'a) (?f::?'a ⇒ ?'b) ≡ ?f ?s›*) us[symmetric] (*‹getFrN (map snd (txs::('trm × 'var) list)) ((r::'trm) # map fst txs) [] (length txs) ≡ us::'var list›*) intro!: rawpsubstT_atrm[of _ "zip (map fst txs) us"] (*‹⟦(?r::'trm) ∈ atrm; snd ` set (zip (map fst (txs::('trm × 'var) list)) (us::'var list)) ⊆ (var::'var set); fst ` set (zip (map fst txs) us) ⊆ atrm⟧ ⟹ rawpsubstT ?r (zip (map fst txs) us) ∈ atrm›*) dest!: set_zip_D (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) qed lemma Fvars_rawpsubst_su: assumes "r ∈ atrm" and "snd ` (set txs) ⊆ var" and "fst ` (set txs) ⊆ atrm" shows "FvarsT (rawpsubstT r txs) ⊆ (FvarsT r - snd ` (set txs)) ∪ (⋃ {FvarsT t | t x . (t,x) ∈ set txs})" using assms (*‹r ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm›*) proof (induction txs arbitrary: r) (*goals: 1. ‹⋀r. ⟦r ∈ atrm; snd ` set [] ⊆ var; fst ` set [] ⊆ atrm⟧ ⟹ FvarsT (rawpsubstT r []) ⊆ FvarsT r - snd ` set [] ∪ ⋃ {uu_. ∃t x. uu_ = FvarsT t ∧ (t, x) ∈ set []}› 2. ‹⋀a txs r. ⟦⋀r. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm⟧ ⟹ FvarsT (rawpsubstT r txs) ⊆ FvarsT r - snd ` set txs ∪ ⋃ {uu_. ∃t x. uu_ = FvarsT t ∧ (t, x) ∈ set txs}; r ∈ atrm; snd ` set (a # txs) ⊆ var; fst ` set (a # txs) ⊆ atrm⟧ ⟹ FvarsT (rawpsubstT r (a # txs)) ⊆ FvarsT r - snd ` set (a # txs) ∪ ⋃ {uu_. ∃t x. uu_ = FvarsT t ∧ (t, x) ∈ set (a # txs)}›*) case (Cons tx txs r) (*‹⟦?r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm⟧ ⟹ FvarsT (rawpsubstT ?r txs) ⊆ FvarsT ?r - snd ` set txs ∪ ⋃ {uu_. ∃t x. uu_ = FvarsT t ∧ (t, x) ∈ set txs}› ‹r ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm›*) then obtain t and x where tx: "tx = (t,x)" (*goal: ‹(⋀t x. tx = (t, x) ⟹ thesis) ⟹ thesis›*) by force have t: "t ∈ trm" and x: "x ∈ var" using Cons.prems (*‹r ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm›*) unfolding tx (*goals: 1. ‹t ∈ trm› 2. ‹x ∈ var›*) apply - (*goals: 1. ‹⟦r ∈ atrm; snd ` set ((t, x) # txs) ⊆ var; fst ` set ((t, x) # txs) ⊆ atrm⟧ ⟹ t ∈ trm› 2. ‹⟦r ∈ atrm; snd ` set ((t, x) # txs) ⊆ var; fst ` set ((t, x) # txs) ⊆ atrm⟧ ⟹ x ∈ var› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . define χ where "χ ≡ substT r t x" have 0: "FvarsT χ = FvarsT r - {x} ∪ (if x ∈ FvarsT r then FvarsT t else {})" using Cons.prems (*‹r ∈ atrm› ‹snd ` set ((tx::'trm × 'var) # (txs::('trm × 'var) list)) ⊆ (var::'var set)› ‹fst ` set ((tx::'trm × 'var) # (txs::('trm × 'var) list)) ⊆ atrm›*) unfolding "χ_def" (*goal: ‹FvarsT (substT r t x) = FvarsT r - {x} ∪ (if x ∈ FvarsT r then FvarsT t else {})›*) by (auto simp: tx (*‹tx = (t, x)›*) t (*‹t ∈ trm›*) FvarsT_substT (*‹⟦?s ∈ atrm; ?t ∈ trm; ?x ∈ var⟧ ⟹ FvarsT (substT ?s ?t ?x) = FvarsT ?s - {?x} ∪ (if ?x ∈ FvarsT ?s then FvarsT ?t else {})›*)) have "χ": "χ ∈ trm" "χ ∈ atrm" unfolding "χ_def" (*goals: 1. ‹substT r t x ∈ trm› 2. ‹substT r t x ∈ atrm›*) using Cons.prems (*‹r ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm›*) t (*‹(t::'trm) ∈ (trm::'trm set)›*) x (*‹x ∈ var›*) apply - (*goals: 1. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; t ∈ trm; x ∈ var⟧ ⟹ substT r t x ∈ trm› 2. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; t ∈ trm; x ∈ var⟧ ⟹ substT r t x ∈ atrm› discuss goal 1*) apply ((msorry)[1]) (*discuss goal 2*) apply ((msorry)[1]) (*proven 2 subgoals*) . have "FvarsT (rawpsubstT χ txs) ⊆ (FvarsT χ - snd ` (set txs)) ∪ (⋃ {FvarsT t | t x . (t,x) ∈ set txs})" using Cons.prems (*‹r ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm›*) "χ" (*‹χ ∈ trm› ‹(χ::'trm) ∈ atrm›*) apply ((intro Cons.IH (*‹⟦?r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm⟧ ⟹ FvarsT (rawpsubstT ?r txs) ⊆ FvarsT ?r - snd ` set txs ∪ ⋃ {uu_. ∃t x. uu_ = FvarsT t ∧ (t, x) ∈ set txs}›*))[1]) (*goals: 1. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; χ ∈ trm; χ ∈ atrm⟧ ⟹ χ ∈ atrm› 2. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; χ ∈ trm; χ ∈ atrm⟧ ⟹ snd ` set txs ⊆ var› 3. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; χ ∈ trm; χ ∈ atrm⟧ ⟹ fst ` set txs ⊆ atrm› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . also (*calculation: ‹FvarsT (rawpsubstT χ txs) ⊆ FvarsT χ - snd ` set txs ∪ ⋃ {uu_. ∃t x. uu_ = FvarsT t ∧ (t, x) ∈ set txs}›*) have "… ⊆ FvarsT r - insert x (snd ` set txs) ∪ ⋃{FvarsT ta |ta. ∃xa. ta = t ∧ xa = x ∨ (ta, xa) ∈ set txs}" (is "_ ⊆ ?R") by (auto simp: 0 (*‹FvarsT χ = FvarsT r - {x} ∪ (if x ∈ FvarsT r then FvarsT t else {})›*) tx (*‹tx = (t, x)›*) Cons.prems (*‹r ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm›*)) finally (*calculation: ‹(FvarsT::'trm ⇒ 'var set) (rawpsubstT (χ::'trm) (txs::('trm × 'var) list)) ⊆ FvarsT (r::'trm) - insert (x::'var) (snd ` set txs) ∪ ⋃ {FvarsT ta |ta::'trm. ∃xa::'var. ta = (t::'trm) ∧ xa = x ∨ (ta, xa) ∈ set txs}›*) have 1: "FvarsT (rawpsubstT χ txs) ⊆ ?R" . have 2: "FvarsT χ = FvarsT r - {x} ∪ (if x ∈ FvarsT r then FvarsT t else {})" using Cons.prems (*‹r ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm›*) t (*‹t ∈ trm›*) x (*‹x ∈ var›*) unfolding "χ_def" (*goal: ‹FvarsT (substT r t x) = FvarsT r - {x} ∪ (if x ∈ FvarsT r then FvarsT t else {})›*) using FvarsT_substT (*‹⟦?s ∈ atrm; ?t ∈ trm; ?x ∈ var⟧ ⟹ FvarsT (substT ?s ?t ?x) = FvarsT ?s - {?x} ∪ (if ?x ∈ FvarsT ?s then FvarsT ?t else {})›*) by auto show "?case" (*goal: ‹FvarsT (rawpsubstT r (tx # txs)) ⊆ FvarsT r - snd ` set (tx # txs) ∪ ⋃ {uu_. ∃t x. uu_ = FvarsT t ∧ (t, x) ∈ set (tx # txs)}›*) using "1" (*‹FvarsT (rawpsubstT χ txs) ⊆ FvarsT r - insert x (snd ` set txs) ∪ ⋃ {FvarsT ta |ta. ∃xa. ta = t ∧ xa = x ∨ (ta, xa) ∈ set txs}›*) by (simp add: tx (*‹(tx::'trm × 'var) = (t::'trm, x::'var)›*) χ_def[symmetric] (*‹(substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) (r::'trm) (t::'trm) (x::'var) ≡ χ::'trm›*) 2 (*‹(FvarsT::'trm ⇒ 'var set) (χ::'trm) = FvarsT (r::'trm) - {x::'var} ∪ (if x ∈ FvarsT r then FvarsT (t::'trm) else {})›*)) qed (auto) (*solved the remaining goal: ‹⋀r. ⟦r ∈ atrm; snd ` set [] ⊆ var; fst ` set [] ⊆ atrm⟧ ⟹ FvarsT (rawpsubstT r []) ⊆ FvarsT r - snd ` set [] ∪ ⋃ {uu_. ∃t x. uu_ = FvarsT t ∧ (t, x) ∈ set []}›*) lemma in_FvarsT_rawpsubstT_imp: assumes "y ∈ FvarsT (rawpsubstT r txs)" and "r ∈ atrm" and "snd ` (set txs) ⊆ var" and "fst ` (set txs) ⊆ atrm" shows "(y ∈ FvarsT r - snd ` (set txs)) ∨ (y ∈ ⋃ { FvarsT t | t x . (t,x) ∈ set txs})" using Fvars_rawpsubst_su[OF assms ( 2 - 4 )] (*‹FvarsT (rawpsubstT r txs) ⊆ FvarsT r - snd ` set txs ∪ ⋃ {uu_. ∃t x. uu_ = FvarsT t ∧ (t, x) ∈ set txs}›*) using assms(1) (*‹(y::'var::type) ∈ (FvarsT::'trm::type ⇒ 'var::type set) (rawpsubstT (r::'trm::type) (txs::('trm::type × 'var::type) list))›*) by blast lemma FvarsT_rawpsubstT: assumes "r ∈ atrm" and "snd ` (set txs) ⊆ var" and "fst ` (set txs) ⊆ atrm" and "distinct (map snd txs)" and "∀ x ∈ snd ` (set txs). ∀ t ∈ fst ` (set txs). x ∉ FvarsT t" shows "FvarsT (rawpsubstT r txs) = (FvarsT r - snd ` (set txs)) ∪ (⋃ {if x ∈ FvarsT r then FvarsT t else {} | t x . (t,x) ∈ set txs})" using assms (*‹(r::'trm) ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set (txs::('trm × 'var) list) ⊆ atrm› ‹distinct (map snd (txs::('trm::type × 'var::type) list))› ‹∀x∈snd ` set txs. ∀t∈fst ` set txs. x ∉ FvarsT t›*) proof (induction txs arbitrary: r) (*goals: 1. ‹⋀r. ⟦r ∈ atrm; snd ` set [] ⊆ var; fst ` set [] ⊆ atrm; distinct (map snd []); ∀x∈snd ` set []. ∀t∈fst ` set []. x ∉ FvarsT t⟧ ⟹ FvarsT (rawpsubstT r []) = FvarsT r - snd ` set [] ∪ ⋃ {if x ∈ FvarsT r then FvarsT t else {} |t x. (t, x) ∈ set []}› 2. ‹⋀a txs r. ⟦⋀r. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ∀x∈snd ` set txs. ∀t∈fst ` set txs. x ∉ FvarsT t⟧ ⟹ FvarsT (rawpsubstT r txs) = FvarsT r - snd ` set txs ∪ ⋃ {if x ∈ FvarsT r then FvarsT t else {} |t x. (t, x) ∈ set txs}; r ∈ atrm; snd ` set (a # txs) ⊆ var; fst ` set (a # txs) ⊆ atrm; distinct (map snd (a # txs)); ∀x∈snd ` set (a # txs). ∀t∈fst ` set (a # txs). x ∉ FvarsT t⟧ ⟹ FvarsT (rawpsubstT r (a # txs)) = FvarsT r - snd ` set (a # txs) ∪ ⋃ {if x ∈ FvarsT r then FvarsT t else {} |t x. (t, x) ∈ set (a # txs)}›*) case (Cons a txs r) (*‹⟦?r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ∀x∈snd ` set txs. ∀t∈fst ` set txs. x ∉ FvarsT t⟧ ⟹ FvarsT (rawpsubstT ?r txs) = FvarsT ?r - snd ` set txs ∪ ⋃ {if x ∈ FvarsT ?r then FvarsT t else {} |t x. (t, x) ∈ set txs}› ‹(r::'trm) ∈ atrm› ‹snd ` set (a # txs) ⊆ var› ‹fst ` set (a # txs) ⊆ atrm› ‹distinct (map snd ((a::'trm::type × 'var::type) # (txs::('trm::type × 'var::type) list)))› ‹∀x::'var::type∈snd ` set ((a::'trm::type × 'var::type) # (txs::('trm::type × 'var::type) list)). ∀t::'trm::type∈fst ` set (a # txs). x ∉ (FvarsT::'trm::type ⇒ 'var::type set) t›*) then obtain t and x where a: "a = (t,x)" (*goal: ‹(⋀(t::'trm::type) x::'var::type. (a::'trm::type × 'var::type) = (t, x) ⟹ thesis::bool) ⟹ thesis›*) by force have t: "t ∈ trm" and x: "x ∈ var" using Cons.prems (*‹r ∈ atrm› ‹snd ` set (a # txs) ⊆ var› ‹fst ` set (a # txs) ⊆ atrm› ‹distinct (map snd (a # txs))› ‹∀x∈snd ` set (a # txs). ∀t∈fst ` set (a # txs). x ∉ FvarsT t›*) unfolding a (*goals: 1. ‹t ∈ trm› 2. ‹x ∈ var›*) apply - (*goals: 1. ‹⟦r ∈ atrm; snd ` set ((t, x) # txs) ⊆ var; fst ` set ((t, x) # txs) ⊆ atrm; distinct (map snd ((t, x) # txs)); ∀xa∈snd ` set ((t, x) # txs). ∀t∈fst ` set ((t, x) # txs). xa ∉ FvarsT t⟧ ⟹ t ∈ trm› 2. ‹⟦r ∈ atrm; snd ` set ((t, x) # txs) ⊆ var; fst ` set ((t, x) # txs) ⊆ atrm; distinct (map snd ((t, x) # txs)); ∀xa∈snd ` set ((t, x) # txs). ∀t∈fst ` set ((t, x) # txs). xa ∉ FvarsT t⟧ ⟹ x ∈ var› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have xt: "x ∉ FvarsT t ∧ snd ` set txs ∩ FvarsT t = {}" using Cons.prems (*‹r ∈ atrm› ‹snd ` set (a # txs) ⊆ var› ‹fst ` set (a # txs) ⊆ atrm› ‹distinct (map snd ((a::'trm × 'var) # (txs::('trm × 'var) list)))› ‹∀x∈snd ` set (a # txs). ∀t∈fst ` set (a # txs). x ∉ FvarsT t›*) unfolding a (*goal: ‹x ∉ FvarsT t ∧ snd ` set txs ∩ FvarsT t = {}›*) by auto hence 0: "FvarsT r - {x} ∪ FvarsT t - snd ` set txs = FvarsT r - insert x (snd ` set txs) ∪ FvarsT t" by auto have x_txs: "⋀ta xa. (ta, xa) ∈ set txs ⟹ x ≠ xa" using ‹distinct (map snd (a # txs))› (*‹distinct (map snd (a # txs))›*) unfolding a (*goal: ‹⋀ta xa. (ta, xa) ∈ set txs ⟹ x ≠ xa›*) by (auto simp: rev_image_eqI (*‹⟦?x ∈ ?A; ?b = ?f ?x⟧ ⟹ ?b ∈ ?f ` ?A›*)) define χ where "χ_def": "χ ≡ substT r t x" have "χ": "χ ∈ trm" "χ ∈ atrm" unfolding "χ_def" (*goals: 1. ‹substT r t x ∈ trm› 2. ‹substT r t x ∈ atrm›*) using Cons.prems (*‹(r::'trm) ∈ atrm› ‹snd ` set ((a::'trm × 'var) # (txs::('trm × 'var) list)) ⊆ (var::'var set)› ‹fst ` set (a # txs) ⊆ atrm› ‹distinct (map snd (a # txs))› ‹∀x∈snd ` set (a # txs). ∀t∈fst ` set (a # txs). x ∉ FvarsT t›*) t (*‹(t::'trm::type) ∈ (trm::'trm::type set)›*) x (*‹(x::'var) ∈ (var::'var set)›*) apply - (*goals: 1. ‹⟦r ∈ atrm; snd ` set (a # txs) ⊆ var; fst ` set (a # txs) ⊆ atrm; distinct (map snd (a # txs)); ∀x∈snd ` set (a # txs). ∀t∈fst ` set (a # txs). x ∉ FvarsT t; t ∈ trm; x ∈ var⟧ ⟹ substT r t x ∈ trm› 2. ‹⟦r ∈ atrm; snd ` set (a # txs) ⊆ var; fst ` set (a # txs) ⊆ atrm; distinct (map snd (a # txs)); ∀x∈snd ` set (a # txs). ∀t∈fst ` set (a # txs). x ∉ FvarsT t; t ∈ trm; x ∈ var⟧ ⟹ substT r t x ∈ atrm› discuss goal 1*) apply ((auto simp: a (*‹(a::'trm × 'var) = (t::'trm, x::'var)›*))[1]) (*discuss goal 2*) apply ((auto simp: a (*‹(a::'trm::type × 'var::type) = (t::'trm::type, x::'var::type)›*))[1]) (*proven 2 subgoals*) . have 1: "FvarsT (rawpsubstT χ txs) = (FvarsT χ - snd ` (set txs)) ∪ (⋃ {if x ∈ FvarsT χ then FvarsT t else {} | t x . (t,x) ∈ set txs})" using Cons.prems (*‹r ∈ atrm› ‹snd ` set (a # txs) ⊆ var› ‹fst ` set (a # txs) ⊆ atrm› ‹distinct (map snd (a # txs))› ‹∀x∈snd ` set (a # txs). ∀t∈fst ` set (a # txs). x ∉ FvarsT t›*) "χ" (*‹χ ∈ trm› ‹(χ::'trm) ∈ atrm›*) apply (intro Cons.IH (*‹⟦?r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ∀x∈snd ` set txs. ∀t∈fst ` set txs. x ∉ FvarsT t⟧ ⟹ FvarsT (rawpsubstT ?r txs) = FvarsT ?r - snd ` set txs ∪ ⋃ {if x ∈ FvarsT ?r then FvarsT t else {} |t x. (t, x) ∈ set txs}›*)) (*goals: 1. ‹⟦r ∈ atrm; snd ` set (a # txs) ⊆ var; fst ` set (a # txs) ⊆ atrm; distinct (map snd (a # txs)); ∀x∈snd ` set (a # txs). ∀t∈fst ` set (a # txs). x ∉ FvarsT t; χ ∈ trm; χ ∈ atrm⟧ ⟹ χ ∈ atrm› 2. ‹⟦r ∈ atrm; snd ` set (a # txs) ⊆ var; fst ` set (a # txs) ⊆ atrm; distinct (map snd (a # txs)); ∀x∈snd ` set (a # txs). ∀t∈fst ` set (a # txs). x ∉ FvarsT t; χ ∈ trm; χ ∈ atrm⟧ ⟹ snd ` set txs ⊆ var› 3. ‹⟦r ∈ atrm; snd ` set (a # txs) ⊆ var; fst ` set (a # txs) ⊆ atrm; distinct (map snd (a # txs)); ∀x∈snd ` set (a # txs). ∀t∈fst ` set (a # txs). x ∉ FvarsT t; χ ∈ trm; χ ∈ atrm⟧ ⟹ fst ` set txs ⊆ atrm› 4. ‹⟦r ∈ atrm; snd ` set (a # txs) ⊆ var; fst ` set (a # txs) ⊆ atrm; distinct (map snd (a # txs)); ∀x∈snd ` set (a # txs). ∀t∈fst ` set (a # txs). x ∉ FvarsT t; χ ∈ trm; χ ∈ atrm⟧ ⟹ distinct (map snd txs)› 5. ‹⟦r ∈ atrm; snd ` set (a # txs) ⊆ var; fst ` set (a # txs) ⊆ atrm; distinct (map snd (a # txs)); ∀x∈snd ` set (a # txs). ∀t∈fst ` set (a # txs). x ∉ FvarsT t; χ ∈ trm; χ ∈ atrm⟧ ⟹ ∀x∈snd ` set txs. ∀t∈fst ` set txs. x ∉ FvarsT t› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . have 2: "FvarsT χ = FvarsT r - {x} ∪ (if x ∈ FvarsT r then FvarsT t else {})" using Cons.prems (*‹r ∈ atrm› ‹snd ` set (a # txs) ⊆ var› ‹fst ` set (a # txs) ⊆ atrm› ‹distinct (map snd ((a::'trm::type × 'var::type) # (txs::('trm::type × 'var::type) list)))› ‹∀x::'var∈snd ` set ((a::'trm × 'var) # (txs::('trm × 'var) list)). ∀t::'trm∈fst ` set (a # txs). x ∉ (FvarsT::'trm ⇒ 'var set) t›*) t (*‹t ∈ trm›*) x (*‹x ∈ var›*) unfolding "χ_def" (*goal: ‹FvarsT (substT r t x) = FvarsT r - {x} ∪ (if x ∈ FvarsT r then FvarsT t else {})›*) using FvarsT_substT (*‹⟦?s ∈ atrm; ?t ∈ trm; ?x ∈ var⟧ ⟹ FvarsT (substT ?s ?t ?x) = FvarsT ?s - {?x} ∪ (if ?x ∈ FvarsT ?s then FvarsT ?t else {})›*) by auto define f where "f ≡ λta xa. if xa ∈ FvarsT r then FvarsT ta else {}" have 3: "⋃ {f ta xa |ta xa. (ta, xa) ∈ set ((t, x) # txs)} = f t x ∪ (⋃ {f ta xa |ta xa. (ta, xa) ∈ set txs})" by auto have 4: "snd ` set ((t, x) # txs) = {x} ∪ snd ` set txs" by auto have 5: "f t x ∩ snd ` set txs = {}" unfolding f_def (*goal: ‹(if x ∈ FvarsT r then FvarsT t else {}) ∩ snd ` set txs = {}›*) using xt (*‹x ∉ FvarsT t ∧ snd ` set txs ∩ FvarsT t = {}›*) by auto have 6: "⋃ {if xa ∈ FvarsT r - {x} ∪ f t x then FvarsT ta else {} | ta xa. (ta, xa) ∈ set txs} = (⋃ {f ta xa | ta xa. (ta, xa) ∈ set txs})" unfolding f_def (*goal: ‹⋃ {if xa ∈ FvarsT r - {x} ∪ (if x ∈ FvarsT r then FvarsT t else {}) then FvarsT ta else {} |ta xa. (ta, xa) ∈ set txs} = ⋃ {if xa ∈ FvarsT r then FvarsT ta else {} |ta xa. (ta, xa) ∈ set txs}›*) using xt (*‹x ∉ FvarsT t ∧ snd ` set txs ∩ FvarsT t = {}›*) x_txs (*‹(?ta, ?xa) ∈ set txs ⟹ x ≠ ?xa›*) by (fastforce split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) have "FvarsT r - {x} ∪ f t x - snd ` set txs ∪ ⋃ {if xa ∈ FvarsT r - {x} ∪ f t x then FvarsT ta else {} | ta xa. (ta, xa) ∈ set txs} = FvarsT r - snd ` set ((t, x) # txs) ∪ ⋃ {f ta xa |ta xa. (ta, xa) ∈ set ((t, x) # txs)}" unfolding "3" "4" "6" (*goal: ‹FvarsT r - {x} ∪ f t x - snd ` set txs ∪ ⋃ {f ta xa |ta xa. (ta, xa) ∈ set txs} = FvarsT r - ({x} ∪ snd ` set txs) ∪ (f t x ∪ ⋃ {f ta xa |ta xa. (ta, xa) ∈ set txs})›*) unfolding Un_Diff2[OF 5] Un_assoc (*goal: ‹FvarsT r - {x} - snd ` set txs ∪ (f t x ∪ ⋃ {f ta xa |ta xa. (ta, xa) ∈ set txs}) = FvarsT r - ({x} ∪ snd ` set txs) ∪ (f t x ∪ ⋃ {f ta xa |ta xa. (ta, xa) ∈ set txs})›*) unfolding Diff_Diff_Un (*goal: ‹FvarsT r - ({x} ∪ snd ` set txs) ∪ (f t x ∪ ⋃ {f ta xa |ta xa. (ta, xa) ∈ set txs}) = FvarsT r - ({x} ∪ snd ` set txs) ∪ (f t x ∪ ⋃ {f ta xa |ta xa. (ta, xa) ∈ set txs})›*) by standard thus "?case" (*goal: ‹FvarsT (rawpsubstT r (a # txs)) = FvarsT r - snd ` set (a # txs) ∪ ⋃ {if x ∈ FvarsT r then FvarsT t else {} |t x. (t, x) ∈ set (a # txs)}›*) unfolding a rawpsubstT.simps "1" "2" "χ_def"[symmetric] f_def (*goal: ‹FvarsT r - {x} ∪ (if x ∈ FvarsT r then FvarsT t else {}) - snd ` set txs ∪ ⋃ {if xa ∈ FvarsT r - {x} ∪ (if x ∈ FvarsT r then FvarsT t else {}) then FvarsT ta else {} |ta xa. (ta, xa) ∈ set txs} = FvarsT r - snd ` set ((t, x) # txs) ∪ ⋃ {if xa ∈ FvarsT r then FvarsT ta else {} |ta xa. (ta, xa) ∈ set ((t, x) # txs)}›*) by simp qed (auto) (*solved the remaining goal: ‹⋀r. ⟦r ∈ atrm; snd ` set [] ⊆ var; fst ` set [] ⊆ atrm; distinct (map snd []); ∀x∈snd ` set []. ∀t∈fst ` set []. x ∉ FvarsT t⟧ ⟹ FvarsT (rawpsubstT r []) = FvarsT r - snd ` set [] ∪ ⋃ {if x ∈ FvarsT r then FvarsT t else {} |t x. (t, x) ∈ set []}›*) lemma in_FvarsT_rawpsubstTD: assumes "y ∈ FvarsT (rawpsubstT r txs)" and "r ∈ atrm" and "snd ` (set txs) ⊆ var" and "fst ` (set txs) ⊆ atrm" and "distinct (map snd txs)" and "∀ x ∈ snd ` (set txs). ∀ t ∈ fst ` (set txs). x ∉ FvarsT t" shows "(y ∈ FvarsT r - snd ` (set txs)) ∨ (y ∈ ⋃ {if x ∈ FvarsT r then FvarsT t else {} | t x . (t,x) ∈ set txs})" using FvarsT_rawpsubstT (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; distinct (map snd ?txs); ∀x∈snd ` set ?txs. ∀t∈fst ` set ?txs. x ∉ FvarsT t⟧ ⟹ FvarsT (rawpsubstT ?r ?txs) = FvarsT ?r - snd ` set ?txs ∪ ⋃ {if x ∈ FvarsT ?r then FvarsT t else {} |t x. (t, x) ∈ set ?txs}›*) assms (*‹y ∈ FvarsT (rawpsubstT r txs)› ‹r ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹distinct (map snd (txs::('trm::type × 'var::type) list))› ‹∀x∈snd ` set txs. ∀t∈fst ` set txs. x ∉ FvarsT t›*) by auto lemma FvarsT_psubstT: assumes "r ∈ atrm" and "snd ` (set txs) ⊆ var" and "fst ` (set txs) ⊆ atrm" and "distinct (map snd txs)" shows "FvarsT (psubstT r txs) = (FvarsT r - snd ` (set txs)) ∪ (⋃ {if x ∈ FvarsT r then FvarsT t else {} | t x . (t,x) ∈ set txs})" proof (-) (*goal: ‹FvarsT (psubstT r txs) = FvarsT r - snd ` set txs ∪ ⋃ {if x ∈ FvarsT r then FvarsT t else {} |t x. (t, x) ∈ set txs}›*) have txs_trm: "fst ` (set txs) ⊆ trm" using assms (*‹r ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹distinct (map snd (txs::('trm × 'var) list))›*) by auto define us where us: "us ≡ getFrN (map snd txs) (r # map fst txs) [] (length txs)" have us_facts: "set us ⊆ var" "set us ∩ FvarsT r = {}" "set us ∩ ⋃ (FvarsT ` (fst ` (set txs))) = {}" "set us ∩ snd ` (set txs) = {}" "length us = length txs" "distinct us" using assms(1,2) (*‹r ∈ atrm› ‹snd ` set txs ⊆ var›*) txs_trm (*‹fst ` set txs ⊆ trm›*) unfolding us (*goals: 1. ‹set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ⊆ var› 2. ‹set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ FvarsT r = {}› 3. ‹set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ ⋃ (FvarsT ` fst ` set txs) = {}› 4. ‹set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ snd ` set txs = {}› 5. ‹length (getFrN (map snd txs) (r # map fst txs) [] (length txs)) = length txs› 6. ‹distinct (getFrN (map snd txs) (r # map fst txs) [] (length txs))›*) using getFrN_FvarsT[of "map snd txs" "r # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ FvarsT ?t = {}›*) getFrN_Fvars[of "map snd txs" "r # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; ?φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ Fvars ?φ = {}›*) getFrN_var[of "map snd txs" "r # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}›*) getFrN_length[of "map snd txs" "r # map fst txs" "[]" "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r # map fst txs) [] (length txs)) = length txs›*) getFrN_length[of "map snd txs" "r # map fst txs" "[]" "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r # map fst txs) [] (length txs)) = length txs›*) apply - (*top goal: ‹set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ⊆ var› and 5 goals remain*) subgoal for by auto subgoal for by auto subgoal for by auto subgoal for by force (*goals: 1. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; ⋀t. ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ FvarsT t = {}; ⋀φ. ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ Fvars φ = {}; ⋀t. ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}; ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r # map fst txs) [] (length txs)) = length txs; ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r # map fst txs) [] (length txs)) = length txs⟧ ⟹ length (getFrN (map snd txs) (r # map fst txs) [] (length txs)) = length txs› 2. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; ⋀t. ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ FvarsT t = {}; ⋀φ. ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ Fvars φ = {}; ⋀t. ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}; ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r # map fst txs) [] (length txs)) = length txs; ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r # map fst txs) [] (length txs)) = length txs⟧ ⟹ distinct (getFrN (map snd txs) (r # map fst txs) [] (length txs))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have [simp]: "⋀ aa b. b ∈ set (map snd txs) ⟹ aa ∈ set (map Var us) ⟹ b ∉ FvarsT aa" using us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT r = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set (us::'var list) ∩ snd ` set (txs::('trm × 'var) list) = {}› ‹length us = length txs› ‹distinct us›*) by (fastforce simp: image_def (*‹?f ` ?A = {y. ∃x∈?A. y = ?f x}›*) Int_def (*‹?A ∩ ?B = {x ∈ ?A. x ∈ ?B}›*)) have [simp]: "⋀b ac bc. b ∈ set us ⟹ b ∈ FvarsT ac ⟹ (ac, bc) ∉ set txs" using us_facts(3) (*‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}›*) by (fastforce simp: image_def (*‹?f ` ?A = {y. ∃x∈?A. y = ?f x}›*) Int_def (*‹?A ∩ ?B = {x ∈ ?A. x ∈ ?B}›*)) define χ where "χ_def": "χ ≡ rawpsubstT r (zip (map Var us) (map snd txs))" have "χ": "χ ∈ atrm" unfolding "χ_def" (*goal: ‹rawpsubstT r (zip (map Var us) (map snd txs)) ∈ atrm›*) using assms (*‹r ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹distinct (map snd txs)›*) using us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT r = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct us›*) apply (intro rawpsubstT_atrm (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT ?r ?txs ∈ atrm›*)) (*goals: 1. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ r ∈ atrm› 2. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ snd ` set (zip (map Var us) (map snd txs)) ⊆ var› 3. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ fst ` set (zip (map Var us) (map snd txs)) ⊆ atrm› discuss goal 1*) apply (force dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) (*discuss goal 2*) apply (force dest!: set_zip_D (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) (*discuss goal 3*) apply (force dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) (*proven 3 subgoals*) . hence "χ ∈ trm" by auto note "χ" = "χ" (*‹χ ∈ atrm›*) this (*‹χ ∈ trm›*) have set_us: "set us = snd ` (set (zip (map fst txs) us))" using us_facts (*‹set us ⊆ var› ‹set (us::'var list) ∩ (FvarsT::'trm ⇒ 'var set) (r::'trm) = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct us›*) apply (intro snd_set_zip[symmetric] (*‹length ?xs = length ?ys ⟹ set ?ys = snd ` set (zip ?xs ?ys)›*)) (*goal: ‹set us = snd ` set (zip (map fst txs) us)›*) by auto have set_txs: "snd ` set txs = snd ` (set (zip (map Var us) (map snd txs)))" using us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT r = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct us›*) apply (intro snd_set_zip_map_snd[symmetric] (*‹length ?xs = length ?ys ⟹ snd ` set ?ys = snd ` set (zip ?xs (map snd ?ys))›*)) (*goal: ‹snd ` set txs = snd ` set (zip (map Var us) (map snd txs))›*) by auto have "⋀ t x. (t, x) ∈ set (zip (map Var us) (map snd txs)) ⟹ ∃ u. t = Var u" using us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT r = {}› ‹set (us::'var list) ∩ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set (txs::('trm × 'var) list)) = {}› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct us›*) set_zip_leftD (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs›*) by fastforce hence 00: "⋀ t x. (t, x) ∈ set (zip (map Var us) (map snd txs)) ⟷ (∃ u ∈ var. t = Var u ∧ (Var u, x) ∈ set (zip (map Var us) (map snd txs)))" using us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT r = {}› ‹set (us::'var list) ∩ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set (txs::('trm × 'var) list)) = {}› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct us›*) set_zip_leftD (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs›*) by fastforce have "FvarsT χ = FvarsT r - snd ` set txs ∪ ⋃{if x ∈ FvarsT r then FvarsT t else {} |t x. (t, x) ∈ set (zip (map Var us) (map snd txs))}" unfolding "χ_def" set_txs (*goal: ‹FvarsT (rawpsubstT r (zip (map Var us) (map snd txs))) = FvarsT r - snd ` set (zip (map Var us) (map snd txs)) ∪ ⋃ {if x ∈ FvarsT r then FvarsT t else {} |t x. (t, x) ∈ set (zip (map Var us) (map snd txs))}›*) using assms (*‹r ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹distinct (map snd (txs::('trm × 'var) list))›*) us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT r = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct us›*) set_txs (*‹snd ` set txs = snd ` set (zip (map Var us) (map snd txs))›*) apply (intro FvarsT_rawpsubstT (*‹⟦(?r::'trm) ∈ atrm; snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ atrm; distinct (map snd ?txs); ∀x::'var∈snd ` set ?txs. ∀t::'trm∈fst ` set ?txs. x ∉ (FvarsT::'trm ⇒ 'var set) t⟧ ⟹ FvarsT (rawpsubstT ?r ?txs) = FvarsT ?r - snd ` set ?txs ∪ ⋃ {if x ∈ FvarsT ?r then FvarsT t else {} |(t::'trm) x::'var. (t, x) ∈ set ?txs}›*)) (*goals: 1. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; snd ` set txs = snd ` set (zip (map Var us) (map snd txs))⟧ ⟹ r ∈ atrm› 2. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; snd ` set txs = snd ` set (zip (map Var us) (map snd txs))⟧ ⟹ snd ` set (zip (map Var us) (map snd txs)) ⊆ var› 3. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; snd ` set txs = snd ` set (zip (map Var us) (map snd txs))⟧ ⟹ fst ` set (zip (map Var us) (map snd txs)) ⊆ atrm› 4. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; snd ` set txs = snd ` set (zip (map Var us) (map snd txs))⟧ ⟹ distinct (map snd (zip (map Var us) (map snd txs)))› 5. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; snd ` set txs = snd ` set (zip (map Var us) (map snd txs))⟧ ⟹ ∀x∈snd ` set (zip (map Var us) (map snd txs)). ∀t∈fst ` set (zip (map Var us) (map snd txs)). x ∉ FvarsT t› discuss goal 1*) apply (force dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) (*discuss goal 2*) apply (force dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) (*discuss goal 3*) apply (force dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) (*discuss goal 4*) apply (force dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) (*discuss goal 5*) apply (force dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) (*proven 5 subgoals*) . also (*calculation: ‹FvarsT χ = FvarsT r - snd ` set txs ∪ ⋃ {if x ∈ FvarsT r then FvarsT t else {} |t x. (t, x) ∈ set (zip (map Var us) (map snd txs))}›*) have "… = FvarsT r - snd ` set txs ∪ ⋃{if x ∈ FvarsT r then {u} else {} |u x. u ∈ var ∧ (Var u, x) ∈ set (zip (map Var us) (map snd txs))}" (is "… = ?R") apply (subst 00 (*‹((?t, ?x) ∈ set (zip (map Var us) (map snd txs))) = (∃u∈var. ?t = Var u ∧ (Var u, ?x) ∈ set (zip (map Var us) (map snd txs)))›*)) (*goal: ‹FvarsT r - snd ` set txs ∪ ⋃ {if x ∈ FvarsT r then FvarsT t else {} |t x. (t, x) ∈ set (zip (map Var us) (map snd txs))} = FvarsT r - snd ` set txs ∪ ⋃ {if x ∈ FvarsT r then {u} else {} |u x. u ∈ var ∧ (Var u, x) ∈ set (zip (map Var us) (map snd txs))}›*) by (metis (no_types, opaque_lifting) FvarsT_Var (*‹?x ∈ var ⟹ FvarsT (Var ?x) = {?x}›*)) finally (*calculation: ‹FvarsT χ = FvarsT r - snd ` set txs ∪ ⋃ {if x ∈ FvarsT r then {u} else {} |u x. u ∈ var ∧ (Var u, x) ∈ set (zip (map Var us) (map snd txs))}›*) have 0: "FvarsT χ = ?R" . have 1: "FvarsT (rawpsubstT χ (zip (map fst txs) us)) = (FvarsT χ - set us) ∪ (⋃ {if u ∈ FvarsT χ then FvarsT t else {} | t u . (t,u) ∈ set (zip (map fst txs) us)})" unfolding us_facts set_us (*goal: ‹FvarsT (rawpsubstT χ (zip (map fst txs) us)) = FvarsT χ - snd ` set (zip (map fst txs) us) ∪ ⋃ {if u ∈ FvarsT χ then FvarsT t else {} |t u. (t, u) ∈ set (zip (map fst txs) us)}›*) using assms (*‹r ∈ atrm› ‹snd ` set (txs::('trm::type × 'var::type) list) ⊆ (var::'var::type set)› ‹fst ` set txs ⊆ atrm› ‹distinct (map snd txs)›*) "χ" (*‹χ ∈ atrm› ‹χ ∈ trm›*) apply (intro FvarsT_rawpsubstT (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; distinct (map snd ?txs); ∀x∈snd ` set ?txs. ∀t∈fst ` set ?txs. x ∉ FvarsT t⟧ ⟹ FvarsT (rawpsubstT ?r ?txs) = FvarsT ?r - snd ` set ?txs ∪ ⋃ {if x ∈ FvarsT ?r then FvarsT t else {} |t x. (t, x) ∈ set ?txs}›*)) (*goal: ‹(FvarsT::'trm::type ⇒ 'var::type set) (rawpsubstT (χ::'trm::type) (zip (map fst (txs::('trm::type × 'var::type) list)) (us::'var::type list))) = FvarsT χ - snd ` set (zip (map fst txs) us) ∪ ⋃ {if u ∈ FvarsT χ then FvarsT t else {} |(t::'trm::type) u::'var::type. (t, u) ∈ set (zip (map fst txs) us)}›*) subgoal for by auto subgoal for using us_facts (*‹set (us::'var list) ⊆ (var::'var set)› ‹set us ∩ FvarsT r = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹length (us::'var list) = length (txs::('trm × 'var) list)› ‹distinct us›*) by (auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) subgoal for using us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT r = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set (us::'var list) ∩ snd ` set (txs::('trm × 'var) list) = {}› ‹length (us::'var list) = length (txs::('trm × 'var) list)› ‹distinct us›*) by (auto dest!: set_zip_D (*‹(?x::?'a::type, ?y::?'b::type) ∈ set (zip (?xs::?'a::type list) (?ys::?'b::type list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) subgoal for using us_facts (*‹set (us::'var list) ⊆ (var::'var set)› ‹set (us::'var::type list) ∩ (FvarsT::'trm::type ⇒ 'var::type set) (r::'trm::type) = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct us›*) by (auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) subgoal for by (auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) . have 2: "FvarsT χ - set us = FvarsT r - snd ` set txs" unfolding "0" (*goal: ‹FvarsT r - snd ` set txs ∪ ⋃ {if x ∈ FvarsT r then {u} else {} |u x. u ∈ var ∧ (Var u, x) ∈ set (zip (map Var us) (map snd txs))} - set us = FvarsT r - snd ` set txs›*) apply auto (*goal: ‹FvarsT r - snd ` set txs ∪ ⋃ {if x ∈ FvarsT r then {u} else {} |u x. u ∈ var ∧ (Var u, x) ∈ set (zip (map Var us) (map snd txs))} - set us = FvarsT r - snd ` set txs›*) using set_zip_leftD (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs›*) us_facts(1) (*‹set us ⊆ var›*) apply fastforce (*top goal: ‹⋀u xa. ⟦u ∉ set us; u ∈ var; (Var u, xa) ∈ set (zip (map Var us) (map snd txs)); u ∉ FvarsT r; xa ∈ FvarsT r⟧ ⟹ False› and 2 goals remain*) using set_zip_leftD (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs›*) us_facts(1) (*‹set us ⊆ var›*) apply fastforce (*top goal: ‹⋀(a::'trm) (b::'var) xa::'var. ⟦b ∉ set (us::'var list); (a, b) ∈ set (txs::('trm × 'var) list); b ∈ (var::'var set); ((Var::'var ⇒ 'trm) b, xa) ∈ set (zip (map Var us) (map snd txs)); xa ∈ (FvarsT::'trm ⇒ 'var set) (r::'trm)⟧ ⟹ False› and 1 goal remains*) using us_facts(2) (*‹set us ∩ FvarsT r = {}›*) by auto have 3: "(⋃ {if u ∈ FvarsT χ then FvarsT t else {} | t u . (t,u) ∈ set (zip (map fst txs) us)}) = (⋃ {if x ∈ FvarsT r then FvarsT t else {} | t x . (t,x) ∈ set txs})" proof (safe) (*goals: 1. ‹⋀(x::'var) (X::'var set) (t::'trm) u::'var. ⟦x ∈ (if u ∈ (FvarsT::'trm ⇒ 'var set) (χ::'trm) then FvarsT t else {}); (t, u) ∈ set (zip (map fst (txs::('trm × 'var) list)) (us::'var list))⟧ ⟹ x ∈ ⋃ {if x ∈ FvarsT (r::'trm) then FvarsT t else {} |(t::'trm) x::'var. (t, x) ∈ set txs}› 2. ‹⋀(x::'var) (X::'var set) (t::'trm) xa::'var. ⟦x ∈ (if xa ∈ (FvarsT::'trm ⇒ 'var set) (r::'trm) then FvarsT t else {}); (t, xa) ∈ set (txs::('trm × 'var) list)⟧ ⟹ x ∈ ⋃ {if u ∈ FvarsT (χ::'trm) then FvarsT t else {} |(t::'trm) u::'var. (t, u) ∈ set (zip (map fst txs) (us::'var list))}›*) fix xx and tt and y assume xx: "xx ∈ (if y ∈ FvarsT χ then FvarsT tt else {})" and ty: "(tt, y) ∈ set (zip (map fst txs) us)" (*‹(xx::'var) ∈ (if (y::'var) ∈ (FvarsT::'trm ⇒ 'var set) (χ::'trm) then FvarsT (tt::'trm) else {})› ‹(tt::'trm, y::'var) ∈ set (zip (map fst (txs::('trm × 'var) list)) (us::'var list))›*) have ttin: "tt ∈ fst ` set txs" using ty (*‹(tt::'trm::type, y::'var::type) ∈ set (zip (map fst (txs::('trm::type × 'var::type) list)) (us::'var::type list))›*) using set_zip_leftD (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs›*) by fastforce have yin: "y ∈ set us" using ty (*‹(tt, y) ∈ set (zip (map fst txs) us)›*) by (meson set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) have yvar: "y ∈ var" using us_facts (*‹set (us::'var::type list) ⊆ (var::'var::type set)› ‹set us ∩ FvarsT r = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct us›*) yin (*‹y ∈ set us›*) by auto have ynotin: "y ∉ snd ` set txs" "y ∉ FvarsT r" using yin (*‹y ∈ set us›*) us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT r = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct (us::'var list)›*) apply - (*goals: 1. ‹⟦y ∈ set us; set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ y ∉ snd ` set txs› 2. ‹⟦y ∈ set us; set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ y ∉ FvarsT r› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . show "xx ∈ ⋃{if x ∈ FvarsT r then FvarsT t else {} |t x. (t, x) ∈ set txs}" proof (cases "y ∈ FvarsT χ") (*goals: 1. ‹y ∈ FvarsT χ ⟹ xx ∈ ⋃ {if x ∈ FvarsT r then FvarsT t else {} |t x. (t, x) ∈ set txs}› 2. ‹y ∉ FvarsT χ ⟹ xx ∈ ⋃ {if x ∈ FvarsT r then FvarsT t else {} |t x. (t, x) ∈ set txs}›*) case True (*‹y ∈ FvarsT χ›*) note y = True (*‹y ∈ FvarsT χ›*) hence xx: "xx ∈ FvarsT tt" using xx (*‹(xx::'var::type) ∈ (if (y::'var::type) ∈ (FvarsT::'trm::type ⇒ 'var::type set) (χ::'trm::type) then FvarsT (tt::'trm::type) else {})›*) by simp obtain x where xr: "x ∈ FvarsT r" and yx: "(Var y, x) ∈ set (zip (map Var us) (map snd txs))" (*goal: ‹(⋀x. ⟦x ∈ FvarsT r; (Var y, x) ∈ set (zip (map Var us) (map snd txs))⟧ ⟹ thesis) ⟹ thesis›*) using y (*‹y ∈ FvarsT χ›*) ynotin (*‹y ∉ snd ` set txs› ‹y ∉ FvarsT r›*) unfolding "0" (*goal: ‹(⋀x. ⟦x ∈ FvarsT r; (Var y, x) ∈ set (zip (map Var us) (map snd txs))⟧ ⟹ thesis) ⟹ thesis›*) by (auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) have yx: "(y, x) ∈ set (zip us (map snd txs))" using yvar (*‹y ∈ var›*) us_facts (*‹set (us::'var::type list) ⊆ (var::'var::type set)› ‹set us ∩ FvarsT r = {}› ‹set (us::'var::type list) ∩ ⋃ ((FvarsT::'trm::type ⇒ 'var::type set) ` fst ` set (txs::('trm::type × 'var::type) list)) = {}› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct us›*) apply (intro inj_on_set_zip_map[OF inj_on_Var yx] (*‹⟦set us ⊆ var; y ∈ var; length us = length (map snd txs)⟧ ⟹ (y, x) ∈ set (zip us (map snd txs))›*)) (*goals: 1. ‹⟦y ∈ var; set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ set us ⊆ var› 2. ‹⟦y ∈ var; set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ y ∈ var› 3. ‹⟦y ∈ var; set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ length us = length (map snd txs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . have "(tt, x) ∈ set txs" apply (rule set_zip_map_fst_snd[OF yx ty] (*‹⟦distinct (map snd txs); distinct us; length us = length txs⟧ ⟹ (tt, x) ∈ set txs›*)) (*goal: ‹(tt::'trm::type, x::'var::type) ∈ set (txs::('trm::type × 'var::type) list)›*) using ‹distinct (map snd txs)› (*‹distinct (map snd (txs::('trm::type × 'var::type) list))›*) us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT r = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹length (us::'var list) = length (txs::('trm × 'var) list)› ‹distinct us›*) apply - (*goals: 1. ‹⟦distinct (map snd (txs::('trm × 'var) list)); set (us::'var list) ⊆ (var::'var set); set us ∩ (FvarsT::'trm ⇒ 'var set) (r::'trm) = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ distinct (map snd txs)› 2. ‹⟦distinct (map snd (txs::('trm × 'var) list)); set (us::'var list) ⊆ (var::'var set); set us ∩ (FvarsT::'trm ⇒ 'var set) (r::'trm) = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ distinct us› 3. ‹⟦distinct (map snd (txs::('trm × 'var) list)); set (us::'var list) ⊆ (var::'var set); set us ∩ (FvarsT::'trm ⇒ 'var set) (r::'trm) = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ length us = length txs› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . thus "?thesis" (*goal: ‹xx ∈ ⋃ {if x ∈ FvarsT r then FvarsT t else {} |t x. (t, x) ∈ set txs}›*) using xx (*‹(xx::'var::type) ∈ (FvarsT::'trm::type ⇒ 'var::type set) (tt::'trm::type)›*) xr (*‹x ∈ FvarsT r›*) by auto qed (insert xx (*‹(xx::'var::type) ∈ (FvarsT::'trm::type ⇒ 'var::type set) (tt::'trm::type)›*), auto) (*solved the remaining goal: ‹(y::'var::type) ∉ (FvarsT::'trm::type ⇒ 'var::type set) (χ::'trm::type) ⟹ (xx::'var::type) ∈ ⋃ {if x ∈ FvarsT (r::'trm::type) then FvarsT t else {} |(t::'trm::type) x::'var::type. (t, x) ∈ set (txs::('trm::type × 'var::type) list)}›*) next (*goal: ‹⋀x X t xa. ⟦x ∈ (if xa ∈ FvarsT r then FvarsT t else {}); (t, xa) ∈ set txs⟧ ⟹ x ∈ ⋃ {if u ∈ FvarsT χ then FvarsT t else {} |t u. (t, u) ∈ set (zip (map fst txs) us)}›*) fix y and tt and xx assume y: "y ∈ (if xx ∈ FvarsT r then FvarsT tt else {})" and tx: "(tt, xx) ∈ set txs" (*‹(y::'var) ∈ (if (xx::'var) ∈ (FvarsT::'trm ⇒ 'var set) (r::'trm) then FvarsT (tt::'trm) else {})› ‹(tt::'trm, xx::'var) ∈ set (txs::('trm × 'var) list)›*) hence xxsnd: "xx ∈ snd ` set txs" by force obtain u where uin: "u ∈ set us" and uxx: "(u, xx) ∈ set (zip us (map snd txs))" (*goal: ‹(⋀u. ⟦u ∈ set us; (u, xx) ∈ set (zip us (map snd txs))⟧ ⟹ thesis) ⟹ thesis›*) by (metis xxsnd (*‹xx ∈ snd ` set txs›*) in_set_impl_in_set_zip2 (*‹⟦length ?xs = length ?ys; ?y ∈ set ?ys; ⋀x. (x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?thesis⟧ ⟹ ?thesis›*) length_map (*‹length (map ?f ?xs) = length ?xs›*) set_map (*‹set (map ?f ?xs) = ?f ` set ?xs›*) set_zip_leftD (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs›*) us_facts( (*‹length us = length txs›*) 5)) hence uvar: "u ∈ var" using us_facts (*‹set (us::'var list) ⊆ (var::'var set)› ‹set us ∩ FvarsT r = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct (us::'var list)›*) by auto show "y ∈ ⋃{if u ∈ FvarsT χ then FvarsT t else {} |t u. (t, u) ∈ set (zip (map fst txs) us)}" proof (cases "xx ∈ FvarsT r") (*goals: 1. ‹xx ∈ FvarsT r ⟹ y ∈ ⋃ {if u ∈ FvarsT χ then FvarsT t else {} |t u. (t, u) ∈ set (zip (map fst txs) us)}› 2. ‹xx ∉ FvarsT r ⟹ y ∈ ⋃ {if u ∈ FvarsT χ then FvarsT t else {} |t u. (t, u) ∈ set (zip (map fst txs) us)}›*) case True (*‹xx ∈ FvarsT r›*) note xx = True (*‹xx ∈ FvarsT r›*) hence y: "y ∈ FvarsT tt" using y (*‹y ∈ (if xx ∈ FvarsT r then FvarsT tt else {})›*) by auto have "(Var u, xx) ∈ set (zip (map Var us) (map snd txs))" apply (rule set_zip_length_map[OF uxx] (*‹length us = length (map snd txs) ⟹ (?f u, xx) ∈ set (zip (map ?f us) (map snd txs))›*)) (*goal: ‹((Var::'var ⇒ 'trm) (u::'var), xx::'var) ∈ set (zip (map Var (us::'var list)) (map snd (txs::('trm × 'var) list)))›*) using us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT r = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct us›*) by auto hence "uχ": "u ∈ FvarsT χ" using uin (*‹u ∈ set us›*) xx (*‹xx ∈ FvarsT r›*) uvar (*‹u ∈ var›*) unfolding "0" (*goal: ‹u ∈ FvarsT r - snd ` set txs ∪ ⋃ {if x ∈ FvarsT r then {u} else {} |u x. u ∈ var ∧ (Var u, x) ∈ set (zip (map Var us) (map snd txs))}›*) by auto have ttu: "(tt, u) ∈ set (zip (map fst txs) us)" apply (rule set_zip_map_fst_snd2[OF uxx tx] (*‹⟦distinct (map snd txs); distinct us; length us = length txs⟧ ⟹ (tt, u) ∈ set (zip (map fst txs) us)›*)) (*goal: ‹(tt, u) ∈ set (zip (map fst txs) us)›*) using assms (*‹r ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹distinct (map snd txs)›*) us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT r = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct us›*) apply - (*goals: 1. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ distinct (map snd txs)› 2. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ distinct us› 3. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ length us = length txs› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . show "?thesis" (*goal: ‹y ∈ ⋃ {if u ∈ FvarsT χ then FvarsT t else {} |t u. (t, u) ∈ set (zip (map fst txs) us)}›*) using "uχ" (*‹u ∈ FvarsT χ›*) ttu (*‹(tt, u) ∈ set (zip (map fst txs) us)›*) y (*‹y ∈ FvarsT tt›*) by auto qed (insert y (*‹y ∈ FvarsT tt›*), auto) (*solved the remaining goal: ‹xx ∉ FvarsT r ⟹ y ∈ ⋃ {if u ∈ FvarsT χ then FvarsT t else {} |t u. (t, u) ∈ set (zip (map fst txs) us)}›*) qed show "?thesis" (*goal: ‹FvarsT (psubstT r txs) = FvarsT r - snd ` set txs ∪ ⋃ {if x ∈ FvarsT r then FvarsT t else {} |t x. (t, x) ∈ set txs}›*) by (simp add: psubstT_def (*‹psubstT ?t ?txs = (let xs = map snd ?txs; ts = map fst ?txs; us = getFrN xs (?t # ts) [] (length xs) in rawpsubstT (rawpsubstT ?t (zip (map Var us) xs)) (zip ts us))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) us[symmetric] (*‹getFrN (map snd txs) (r # map fst txs) [] (length txs) ≡ us›*) χ_def[symmetric] (*‹rawpsubstT r (zip (map Var us) (map snd txs)) ≡ χ›*) 1 (*‹FvarsT (rawpsubstT χ (zip (map fst txs) us)) = FvarsT χ - set us ∪ ⋃ {if u ∈ FvarsT χ then FvarsT t else {} |t u. (t, u) ∈ set (zip (map fst txs) us)}›*) 2 (*‹FvarsT χ - set us = FvarsT r - snd ` set txs›*) 3 (*‹⋃ {if u ∈ FvarsT χ then FvarsT t else {} |t u. (t, u) ∈ set (zip (map fst txs) us)} = ⋃ {if x ∈ FvarsT r then FvarsT t else {} |t x. (t, x) ∈ set txs}›*)) qed lemma in_FvarsT_psubstTD: assumes "y ∈ FvarsT (psubstT r txs)" and "r ∈ atrm" and "snd ` (set txs) ⊆ var" and "fst ` (set txs) ⊆ atrm" and "distinct (map snd txs)" shows "y ∈ (FvarsT r - snd ` (set txs)) ∪ (⋃ {if x ∈ FvarsT r then FvarsT t else {} | t x . (t,x) ∈ set txs})" using assms (*‹(y::'var) ∈ (FvarsT::'trm ⇒ 'var set) (psubstT (r::'trm) (txs::('trm × 'var) list))› ‹r ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set (txs::('trm × 'var) list) ⊆ atrm› ‹distinct (map snd (txs::('trm × 'var) list))›*) FvarsT_psubstT (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; distinct (map snd ?txs)⟧ ⟹ FvarsT (psubstT ?r ?txs) = FvarsT ?r - snd ` set ?txs ∪ ⋃ {if x ∈ FvarsT ?r then FvarsT t else {} |t x. (t, x) ∈ set ?txs}›*) by auto lemma substT2_fresh_switch: assumes "r ∈ atrm" "t ∈ trm" "s ∈ trm" "x ∈ var" "y ∈ var" and "x ≠ y" "x ∉ FvarsT s" "y ∉ FvarsT t" shows "substT (substT r s y) t x = substT (substT r t x) s y" (is "?L = ?R") using assms (*‹r ∈ atrm› ‹t ∈ trm› ‹s ∈ trm› ‹x ∈ var› ‹y ∈ var› ‹x ≠ y› ‹x ∉ FvarsT s› ‹y ∉ FvarsT t›*) by (simp add: substT_compose_diff[of r s t y x] (*‹⟦r ∈ atrm; s ∈ trm; t ∈ trm; y ∈ var; x ∈ var; y ≠ x; y ∉ FvarsT t⟧ ⟹ substT (substT r s y) t x = substT (substT r t x) (substT s t x) y›*)) lemma rawpsubst2_fresh_switch: assumes "r ∈ atrm" "t ∈ trm" "s ∈ trm" "x ∈ var" "y ∈ var" and "x ≠ y" "x ∉ FvarsT s" "y ∉ FvarsT t" shows "rawpsubstT r ([(s,y),(t,x)]) = rawpsubstT r ([(t,x),(s,y)])" using assms (*‹(r::'trm) ∈ atrm› ‹t ∈ trm› ‹(s::'trm) ∈ (trm::'trm set)› ‹x ∈ var› ‹y ∈ var› ‹x ≠ y› ‹x ∉ FvarsT s› ‹y ∉ FvarsT t›*) by (simp add: substT2_fresh_switch (*‹⟦?r ∈ atrm; ?t ∈ trm; ?s ∈ trm; ?x ∈ var; ?y ∈ var; ?x ≠ ?y; ?x ∉ FvarsT ?s; ?y ∉ FvarsT ?t⟧ ⟹ substT (substT ?r ?s ?y) ?t ?x = substT (substT ?r ?t ?x) ?s ?y›*)) (* this actually works for any trms, does not need atrms: *) lemma rawpsubstT_compose: assumes "t ∈ trm" and "snd ` (set txs1) ⊆ var" and "fst ` (set txs1) ⊆ atrm" and "snd ` (set txs2) ⊆ var" and "fst ` (set txs2) ⊆ atrm" shows "rawpsubstT (rawpsubstT t txs1) txs2 = rawpsubstT t (txs1 @ txs2)" using assms (*‹t ∈ trm› ‹snd ` set txs1 ⊆ var› ‹fst ` set txs1 ⊆ atrm› ‹snd ` set txs2 ⊆ var› ‹fst ` set txs2 ⊆ atrm›*) apply (induct txs1 arbitrary: txs2 t) (*goal: ‹rawpsubstT (rawpsubstT t txs1) txs2 = rawpsubstT t (txs1 @ txs2)›*) subgoal for by simp subgoal for tx1 and txs1 and txs2 and t apply (cases tx1) (*goal: ‹⟦⋀txs2 t. ⟦t ∈ trm; snd ` set txs1 ⊆ var; fst ` set txs1 ⊆ atrm; snd ` set txs2 ⊆ var; fst ` set txs2 ⊆ atrm⟧ ⟹ rawpsubstT (rawpsubstT t txs1) txs2 = rawpsubstT t (txs1 @ txs2); t ∈ trm; snd ` set (tx1 # txs1) ⊆ var; fst ` set (tx1 # txs1) ⊆ atrm; snd ` set txs2 ⊆ var; fst ` set txs2 ⊆ atrm⟧ ⟹ rawpsubstT (rawpsubstT t (tx1 # txs1)) txs2 = rawpsubstT t ((tx1 # txs1) @ txs2)›*) by auto . lemma rawpsubstT_subst_fresh_switch: assumes "r ∈ atrm" "snd ` (set txs) ⊆ var" and "fst ` (set txs) ⊆ atrm" and "∀ x ∈ snd ` (set txs). x ∉ FvarsT s" and "∀ t ∈ fst ` (set txs). y ∉ FvarsT t" and "distinct (map snd txs)" and "s ∈ atrm" and "y ∈ var" "y ∉ snd ` (set txs)" shows "rawpsubstT (substT r s y) txs = rawpsubstT r (txs @ [(s,y)])" using assms (*‹r ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹∀x∈snd ` set txs. x ∉ FvarsT s› ‹∀t∈fst ` set txs. y ∉ FvarsT t› ‹distinct (map snd (txs::('trm × 'var) list))› ‹s ∈ atrm› ‹(y::'var) ∈ (var::'var set)› ‹y ∉ snd ` set txs›*) proof (induction txs arbitrary: r s y) (*goals: 1. ‹⋀r s y. ⟦r ∈ atrm; snd ` set [] ⊆ var; fst ` set [] ⊆ atrm; ∀x∈snd ` set []. x ∉ FvarsT s; ∀t∈fst ` set []. y ∉ FvarsT t; distinct (map snd []); s ∈ atrm; y ∈ var; y ∉ snd ` set []⟧ ⟹ rawpsubstT (substT r s y) [] = rawpsubstT r ([] @ [(s, y)])› 2. ‹⋀a txs r s y. ⟦⋀r s y. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT s; ∀t∈fst ` set txs. y ∉ FvarsT t; distinct (map snd txs); s ∈ atrm; y ∈ var; y ∉ snd ` set txs⟧ ⟹ rawpsubstT (substT r s y) txs = rawpsubstT r (txs @ [(s, y)]); r ∈ atrm; snd ` set (a # txs) ⊆ var; fst ` set (a # txs) ⊆ atrm; ∀x∈snd ` set (a # txs). x ∉ FvarsT s; ∀t∈fst ` set (a # txs). y ∉ FvarsT t; distinct (map snd (a # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (a # txs)⟧ ⟹ rawpsubstT (substT r s y) (a # txs) = rawpsubstT r ((a # txs) @ [(s, y)])›*) case (Cons tx txs) (*‹⟦?r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT ?s; ∀t∈fst ` set txs. ?y ∉ FvarsT t; distinct (map snd txs); ?s ∈ atrm; ?y ∈ var; ?y ∉ snd ` set txs⟧ ⟹ rawpsubstT (substT ?r ?s ?y) txs = rawpsubstT ?r (txs @ [(?s, ?y)])› ‹r ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm› ‹∀x::'var∈snd ` set ((tx::'trm × 'var) # (txs::('trm × 'var) list)). x ∉ (FvarsT::'trm ⇒ 'var set) (s::'trm)› ‹∀t∈fst ` set (tx # txs). y ∉ FvarsT t› ‹distinct (map snd (tx # txs))› ‹(s::'trm) ∈ atrm› ‹y ∈ var› ‹y ∉ snd ` set (tx # txs)›*) obtain t and x where tx[simp]: "tx = (t,x)" (*goal: ‹(⋀t x. tx = (t, x) ⟹ thesis) ⟹ thesis›*) by force have x: "x ∈ var" and t: "t ∈ trm" using Cons (*‹⟦(?r::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; ∀x::'var∈snd ` set txs. x ∉ (FvarsT::'trm ⇒ 'var set) (?s::'trm); ∀t::'trm∈fst ` set txs. (?y::'var) ∉ FvarsT t; distinct (map snd txs); ?s ∈ atrm; ?y ∈ var; ?y ∉ snd ` set txs⟧ ⟹ rawpsubstT ((substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) ?r ?s ?y) txs = rawpsubstT ?r (txs @ [(?s, ?y)])› ‹(r::'trm) ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm› ‹∀x∈snd ` set (tx # txs). x ∉ FvarsT s› ‹∀t∈fst ` set (tx # txs). y ∉ FvarsT t› ‹distinct (map snd (tx # txs))› ‹s ∈ atrm› ‹(y::'var) ∈ (var::'var set)› ‹y ∉ snd ` set (tx # txs)›*) unfolding tx (*goals: 1. ‹x ∈ var› 2. ‹t ∈ trm›*) apply - (*goals: 1. ‹⟦⋀r s y. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT s; ∀t∈fst ` set txs. y ∉ FvarsT t; distinct (map snd txs); s ∈ atrm; y ∈ var; y ∉ snd ` set txs⟧ ⟹ rawpsubstT (substT r s y) txs = rawpsubstT r (txs @ [(s, y)]); r ∈ atrm; snd ` set ((t, x) # txs) ⊆ var; fst ` set ((t, x) # txs) ⊆ atrm; ∀x∈snd ` set ((t, x) # txs). x ∉ FvarsT s; ∀t∈fst ` set ((t, x) # txs). y ∉ FvarsT t; distinct (map snd ((t, x) # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set ((t, x) # txs)⟧ ⟹ x ∈ var› 2. ‹⟦⋀r s y. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT s; ∀t∈fst ` set txs. y ∉ FvarsT t; distinct (map snd txs); s ∈ atrm; y ∈ var; y ∉ snd ` set txs⟧ ⟹ rawpsubstT (substT r s y) txs = rawpsubstT r (txs @ [(s, y)]); r ∈ atrm; snd ` set ((t, x) # txs) ⊆ var; fst ` set ((t, x) # txs) ⊆ atrm; ∀x∈snd ` set ((t, x) # txs). x ∉ FvarsT s; ∀t∈fst ` set ((t, x) # txs). y ∉ FvarsT t; distinct (map snd ((t, x) # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set ((t, x) # txs)⟧ ⟹ t ∈ trm› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have "rawpsubstT r ((s, y) # (t, x) # txs) = rawpsubstT r ([(s, y),(t, x)] @ txs)" by simp also (*calculation: ‹rawpsubstT (r::'trm) ((s::'trm, y::'var) # (t::'trm, x::'var) # (txs::('trm × 'var) list)) = rawpsubstT r ([(s, y), (t, x)] @ txs)›*) have "… = rawpsubstT (rawpsubstT r [(s, y),(t, x)]) txs" using Cons (*‹⟦?r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT ?s; ∀t∈fst ` set txs. ?y ∉ FvarsT t; distinct (map snd txs); ?s ∈ atrm; ?y ∈ var; ?y ∉ snd ` set txs⟧ ⟹ rawpsubstT (substT ?r ?s ?y) txs = rawpsubstT ?r (txs @ [(?s, ?y)])› ‹r ∈ atrm› ‹snd ` set ((tx::'trm × 'var) # (txs::('trm × 'var) list)) ⊆ (var::'var set)› ‹fst ` set (tx # txs) ⊆ atrm› ‹∀x∈snd ` set (tx # txs). x ∉ FvarsT s› ‹∀t∈fst ` set (tx # txs). y ∉ FvarsT t› ‹distinct (map snd (tx # txs))› ‹s ∈ atrm› ‹y ∈ var› ‹y ∉ snd ` set (tx # txs)›*) by auto also (*calculation: ‹rawpsubstT r ((s, y) # (t, x) # txs) = rawpsubstT (rawpsubstT r [(s, y), (t, x)]) txs›*) have "rawpsubstT r [(s, y),(t, x)] = rawpsubstT r [(t, x),(s, y)]" using Cons (*‹⟦?r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT ?s; ∀t∈fst ` set txs. ?y ∉ FvarsT t; distinct (map snd txs); ?s ∈ atrm; ?y ∈ var; ?y ∉ snd ` set txs⟧ ⟹ rawpsubstT (substT ?r ?s ?y) txs = rawpsubstT ?r (txs @ [(?s, ?y)])› ‹r ∈ atrm› ‹snd ` set ((tx::'trm::type × 'var::type) # (txs::('trm::type × 'var::type) list)) ⊆ (var::'var::type set)› ‹fst ` set (tx # txs) ⊆ atrm› ‹∀x∈snd ` set (tx # txs). x ∉ FvarsT s› ‹∀t∈fst ` set (tx # txs). y ∉ FvarsT t› ‹distinct (map snd (tx # txs))› ‹s ∈ atrm› ‹y ∈ var› ‹y ∉ snd ` set (tx # txs)›*) apply (intro rawpsubst2_fresh_switch (*‹⟦?r ∈ atrm; ?t ∈ trm; ?s ∈ trm; ?x ∈ var; ?y ∈ var; ?x ≠ ?y; ?x ∉ FvarsT ?s; ?y ∉ FvarsT ?t⟧ ⟹ rawpsubstT ?r [(?s, ?y), (?t, ?x)] = rawpsubstT ?r [(?t, ?x), (?s, ?y)]›*)) (*goals: 1. ‹⟦⋀r s y. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT s; ∀t∈fst ` set txs. y ∉ FvarsT t; distinct (map snd txs); s ∈ atrm; y ∈ var; y ∉ snd ` set txs⟧ ⟹ rawpsubstT (substT r s y) txs = rawpsubstT r (txs @ [(s, y)]); r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ r ∈ atrm› 2. ‹⟦⋀r s y. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT s; ∀t∈fst ` set txs. y ∉ FvarsT t; distinct (map snd txs); s ∈ atrm; y ∈ var; y ∉ snd ` set txs⟧ ⟹ rawpsubstT (substT r s y) txs = rawpsubstT r (txs @ [(s, y)]); r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ t ∈ trm› 3. ‹⟦⋀r s y. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT s; ∀t∈fst ` set txs. y ∉ FvarsT t; distinct (map snd txs); s ∈ atrm; y ∈ var; y ∉ snd ` set txs⟧ ⟹ rawpsubstT (substT r s y) txs = rawpsubstT r (txs @ [(s, y)]); r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ s ∈ trm› 4. ‹⟦⋀r s y. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT s; ∀t∈fst ` set txs. y ∉ FvarsT t; distinct (map snd txs); s ∈ atrm; y ∈ var; y ∉ snd ` set txs⟧ ⟹ rawpsubstT (substT r s y) txs = rawpsubstT r (txs @ [(s, y)]); r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ x ∈ var› 5. ‹⟦⋀r s y. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT s; ∀t∈fst ` set txs. y ∉ FvarsT t; distinct (map snd txs); s ∈ atrm; y ∈ var; y ∉ snd ` set txs⟧ ⟹ rawpsubstT (substT r s y) txs = rawpsubstT r (txs @ [(s, y)]); r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ y ∈ var› 6. ‹⟦⋀r s y. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT s; ∀t∈fst ` set txs. y ∉ FvarsT t; distinct (map snd txs); s ∈ atrm; y ∈ var; y ∉ snd ` set txs⟧ ⟹ rawpsubstT (substT r s y) txs = rawpsubstT r (txs @ [(s, y)]); r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ x ≠ y› 7. ‹⟦⋀r s y. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT s; ∀t∈fst ` set txs. y ∉ FvarsT t; distinct (map snd txs); s ∈ atrm; y ∈ var; y ∉ snd ` set txs⟧ ⟹ rawpsubstT (substT r s y) txs = rawpsubstT r (txs @ [(s, y)]); r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ x ∉ FvarsT s› 8. ‹⟦⋀r s y. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT s; ∀t∈fst ` set txs. y ∉ FvarsT t; distinct (map snd txs); s ∈ atrm; y ∈ var; y ∉ snd ` set txs⟧ ⟹ rawpsubstT (substT r s y) txs = rawpsubstT r (txs @ [(s, y)]); r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ y ∉ FvarsT t› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*proven 8 subgoals*) . also (*calculation: ‹rawpsubstT (r::'trm::type) ((s::'trm::type, y::'var::type) # (t::'trm::type, x::'var::type) # (txs::('trm::type × 'var::type) list)) = rawpsubstT (rawpsubstT r [(t, x), (s, y)]) txs›*) have "rawpsubstT (rawpsubstT r [(t, x),(s, y)]) txs = rawpsubstT r ([(t, x),(s, y)] @ txs)" using Cons (*‹⟦?r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT ?s; ∀t∈fst ` set txs. ?y ∉ FvarsT t; distinct (map snd txs); ?s ∈ atrm; ?y ∈ var; ?y ∉ snd ` set txs⟧ ⟹ rawpsubstT (substT ?r ?s ?y) txs = rawpsubstT ?r (txs @ [(?s, ?y)])› ‹r ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm› ‹∀x∈snd ` set (tx # txs). x ∉ FvarsT s› ‹∀t::'trm∈fst ` set ((tx::'trm × 'var) # (txs::('trm × 'var) list)). (y::'var) ∉ (FvarsT::'trm ⇒ 'var set) t› ‹distinct (map snd (tx # txs))› ‹s ∈ atrm› ‹(y::'var) ∈ (var::'var set)› ‹y ∉ snd ` set (tx # txs)›*) apply (intro rawpsubstT_compose (*‹⟦?t ∈ trm; snd ` set ?txs1.0 ⊆ var; fst ` set ?txs1.0 ⊆ atrm; snd ` set ?txs2.0 ⊆ var; fst ` set ?txs2.0 ⊆ atrm⟧ ⟹ rawpsubstT (rawpsubstT ?t ?txs1.0) ?txs2.0 = rawpsubstT ?t (?txs1.0 @ ?txs2.0)›*)) (*goals: 1. ‹⟦⋀r s y. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT s; ∀t∈fst ` set txs. y ∉ FvarsT t; distinct (map snd txs); s ∈ atrm; y ∈ var; y ∉ snd ` set txs⟧ ⟹ rawpsubstT (substT r s y) txs = rawpsubstT r (txs @ [(s, y)]); r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ r ∈ trm› 2. ‹⟦⋀r s y. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT s; ∀t∈fst ` set txs. y ∉ FvarsT t; distinct (map snd txs); s ∈ atrm; y ∈ var; y ∉ snd ` set txs⟧ ⟹ rawpsubstT (substT r s y) txs = rawpsubstT r (txs @ [(s, y)]); r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ snd ` set [(t, x), (s, y)] ⊆ var› 3. ‹⟦⋀r s y. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT s; ∀t∈fst ` set txs. y ∉ FvarsT t; distinct (map snd txs); s ∈ atrm; y ∈ var; y ∉ snd ` set txs⟧ ⟹ rawpsubstT (substT r s y) txs = rawpsubstT r (txs @ [(s, y)]); r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ fst ` set [(t, x), (s, y)] ⊆ atrm› 4. ‹⟦⋀r s y. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT s; ∀t∈fst ` set txs. y ∉ FvarsT t; distinct (map snd txs); s ∈ atrm; y ∈ var; y ∉ snd ` set txs⟧ ⟹ rawpsubstT (substT r s y) txs = rawpsubstT r (txs @ [(s, y)]); r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ snd ` set txs ⊆ var› 5. ‹⟦⋀r s y. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT s; ∀t∈fst ` set txs. y ∉ FvarsT t; distinct (map snd txs); s ∈ atrm; y ∈ var; y ∉ snd ` set txs⟧ ⟹ rawpsubstT (substT r s y) txs = rawpsubstT r (txs @ [(s, y)]); r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ fst ` set txs ⊆ atrm› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . also (*calculation: ‹rawpsubstT r ((s, y) # (t, x) # txs) = rawpsubstT r ([(t, x), (s, y)] @ txs)›*) have "… = rawpsubstT (substT r t x) (txs @ [(s,y)])" using Cons (*‹⟦(?r::'trm::type) ∈ atrm; snd ` set (txs::('trm::type × 'var::type) list) ⊆ (var::'var::type set); fst ` set txs ⊆ atrm; ∀x::'var::type∈snd ` set txs. x ∉ (FvarsT::'trm::type ⇒ 'var::type set) (?s::'trm::type); ∀t::'trm::type∈fst ` set txs. (?y::'var::type) ∉ FvarsT t; distinct (map snd txs); ?s ∈ atrm; ?y ∈ var; ?y ∉ snd ` set txs⟧ ⟹ rawpsubstT ((substT::'trm::type ⇒ 'trm::type ⇒ 'var::type ⇒ 'trm::type) ?r ?s ?y) txs = rawpsubstT ?r (txs @ [(?s, ?y)])› ‹r ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm› ‹∀x∈snd ` set (tx # txs). x ∉ FvarsT s› ‹∀t∈fst ` set (tx # txs). y ∉ FvarsT t› ‹distinct (map snd (tx # txs))› ‹s ∈ atrm› ‹(y::'var) ∈ (var::'var set)› ‹y ∉ snd ` set (tx # txs)›*) by auto also (*calculation: ‹rawpsubstT (r::'trm) ((s::'trm, y::'var) # (t::'trm, x::'var) # (txs::('trm × 'var) list)) = rawpsubstT ((substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) r t x) (txs @ [(s, y)])›*) have "… = rawpsubstT r (((t, x) # txs) @ [(s, y)])" by simp finally (*calculation: ‹rawpsubstT r ((s, y) # (t, x) # txs) = rawpsubstT r (((t, x) # txs) @ [(s, y)])›*) show "?case" (*goal: ‹rawpsubstT (substT r s y) (tx # txs) = rawpsubstT r ((tx # txs) @ [(s, y)])›*) unfolding tx (*goal: ‹rawpsubstT (substT r s y) ((t, x) # txs) = rawpsubstT r (((t, x) # txs) @ [(s, y)])›*) by auto qed (auto) (*solved the remaining goal: ‹⋀r s y. ⟦r ∈ atrm; snd ` set [] ⊆ var; fst ` set [] ⊆ atrm; ∀x∈snd ` set []. x ∉ FvarsT s; ∀t∈fst ` set []. y ∉ FvarsT t; distinct (map snd []); s ∈ atrm; y ∈ var; y ∉ snd ` set []⟧ ⟹ rawpsubstT (substT r s y) [] = rawpsubstT r ([] @ [(s, y)])›*) lemma substT_rawpsubstT_fresh_switch: assumes "r ∈ atrm" "snd ` (set txs) ⊆ var" and "fst ` (set txs) ⊆ atrm" and "∀ x ∈ snd ` (set txs). x ∉ FvarsT s" and "∀ t ∈ fst ` (set txs). y ∉ FvarsT t" and "distinct (map snd txs)" and "s ∈ atrm" and "y ∈ var" "y ∉ snd ` (set txs)" shows "substT (rawpsubstT r txs) s y = rawpsubstT r ((s,y) # txs)" using assms (*‹r ∈ atrm› ‹snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set)› ‹fst ` set txs ⊆ atrm› ‹∀x::'var::type∈snd ` set (txs::('trm::type × 'var::type) list). x ∉ (FvarsT::'trm::type ⇒ 'var::type set) (s::'trm::type)› ‹∀t∈fst ` set txs. y ∉ FvarsT t› ‹distinct (map snd txs)› ‹s ∈ atrm› ‹y ∈ var› ‹y ∉ snd ` set txs›*) proof (induction txs arbitrary: r s y) (*goals: 1. ‹⋀r s y. ⟦r ∈ atrm; snd ` set [] ⊆ var; fst ` set [] ⊆ atrm; ∀x∈snd ` set []. x ∉ FvarsT s; ∀t∈fst ` set []. y ∉ FvarsT t; distinct (map snd []); s ∈ atrm; y ∈ var; y ∉ snd ` set []⟧ ⟹ substT (rawpsubstT r []) s y = rawpsubstT r [(s, y)]› 2. ‹⋀a txs r s y. ⟦⋀r s y. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT s; ∀t∈fst ` set txs. y ∉ FvarsT t; distinct (map snd txs); s ∈ atrm; y ∈ var; y ∉ snd ` set txs⟧ ⟹ substT (rawpsubstT r txs) s y = rawpsubstT r ((s, y) # txs); r ∈ atrm; snd ` set (a # txs) ⊆ var; fst ` set (a # txs) ⊆ atrm; ∀x∈snd ` set (a # txs). x ∉ FvarsT s; ∀t∈fst ` set (a # txs). y ∉ FvarsT t; distinct (map snd (a # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (a # txs)⟧ ⟹ substT (rawpsubstT r (a # txs)) s y = rawpsubstT r ((s, y) # a # txs)›*) case (Cons tx txs) (*‹⟦?r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT ?s; ∀t∈fst ` set txs. ?y ∉ FvarsT t; distinct (map snd txs); ?s ∈ atrm; ?y ∈ var; ?y ∉ snd ` set txs⟧ ⟹ substT (rawpsubstT ?r txs) ?s ?y = rawpsubstT ?r ((?s, ?y) # txs)› ‹r ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm› ‹∀x∈snd ` set (tx # txs). x ∉ FvarsT s› ‹∀t::'trm∈fst ` set ((tx::'trm × 'var) # (txs::('trm × 'var) list)). (y::'var) ∉ (FvarsT::'trm ⇒ 'var set) t› ‹distinct (map snd (tx # txs))› ‹(s::'trm) ∈ atrm› ‹y ∈ var› ‹y ∉ snd ` set (tx # txs)›*) obtain t and x where tx[simp]: "tx = (t,x)" (*goal: ‹(⋀t x. tx = (t, x) ⟹ thesis) ⟹ thesis›*) by force have x: "x ∈ var" and t: "t ∈ trm" using Cons (*‹⟦?r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT ?s; ∀t∈fst ` set txs. ?y ∉ FvarsT t; distinct (map snd txs); ?s ∈ atrm; ?y ∈ var; ?y ∉ snd ` set txs⟧ ⟹ substT (rawpsubstT ?r txs) ?s ?y = rawpsubstT ?r ((?s, ?y) # txs)› ‹(r::'trm) ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm› ‹∀x∈snd ` set (tx # txs). x ∉ FvarsT s› ‹∀t∈fst ` set (tx # txs). y ∉ FvarsT t› ‹distinct (map snd (tx # txs))› ‹(s::'trm) ∈ atrm› ‹(y::'var::type) ∈ (var::'var::type set)› ‹y ∉ snd ` set (tx # txs)›*) unfolding tx (*goals: 1. ‹x ∈ var› 2. ‹t ∈ trm›*) apply - (*goals: 1. ‹⟦⋀r s y. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT s; ∀t∈fst ` set txs. y ∉ FvarsT t; distinct (map snd txs); s ∈ atrm; y ∈ var; y ∉ snd ` set txs⟧ ⟹ substT (rawpsubstT r txs) s y = rawpsubstT r ((s, y) # txs); r ∈ atrm; snd ` set ((t, x) # txs) ⊆ var; fst ` set ((t, x) # txs) ⊆ atrm; ∀x∈snd ` set ((t, x) # txs). x ∉ FvarsT s; ∀t∈fst ` set ((t, x) # txs). y ∉ FvarsT t; distinct (map snd ((t, x) # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set ((t, x) # txs)⟧ ⟹ x ∈ var› 2. ‹⟦⋀r s y. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT s; ∀t∈fst ` set txs. y ∉ FvarsT t; distinct (map snd txs); s ∈ atrm; y ∈ var; y ∉ snd ` set txs⟧ ⟹ substT (rawpsubstT r txs) s y = rawpsubstT r ((s, y) # txs); r ∈ atrm; snd ` set ((t, x) # txs) ⊆ var; fst ` set ((t, x) # txs) ⊆ atrm; ∀x∈snd ` set ((t, x) # txs). x ∉ FvarsT s; ∀t∈fst ` set ((t, x) # txs). y ∉ FvarsT t; distinct (map snd ((t, x) # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set ((t, x) # txs)⟧ ⟹ t ∈ trm› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have "substT (rawpsubstT (substT r t x) txs) s y = rawpsubstT (substT r t x) ((s,y) # txs)" using Cons.prems (*‹r ∈ atrm› ‹snd ` set ((tx::'trm::type × 'var::type) # (txs::('trm::type × 'var::type) list)) ⊆ (var::'var::type set)› ‹fst ` set (tx # txs) ⊆ atrm› ‹∀x∈snd ` set (tx # txs). x ∉ FvarsT s› ‹∀t∈fst ` set (tx # txs). y ∉ FvarsT t› ‹distinct (map snd (tx # txs))› ‹s ∈ atrm› ‹y ∈ var› ‹y ∉ snd ` set (tx # txs)›*) apply (intro Cons.IH (*‹⟦?r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; ∀x∈snd ` set txs. x ∉ FvarsT ?s; ∀t∈fst ` set txs. ?y ∉ FvarsT t; distinct (map snd txs); ?s ∈ atrm; ?y ∈ var; ?y ∉ snd ` set txs⟧ ⟹ substT (rawpsubstT ?r txs) ?s ?y = rawpsubstT ?r ((?s, ?y) # txs)›*)) (*goals: 1. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ substT r t x ∈ atrm› 2. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ snd ` set txs ⊆ var› 3. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ fst ` set txs ⊆ atrm› 4. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ ∀x∈snd ` set txs. x ∉ FvarsT s› 5. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ ∀t∈fst ` set txs. y ∉ FvarsT t› 6. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ distinct (map snd txs)› 7. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ s ∈ atrm› 8. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ y ∈ var› 9. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ y ∉ snd ` set txs› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*discuss goal 9*) apply ((auto)[1]) (*proven 9 subgoals*) . also (*calculation: ‹substT (rawpsubstT (substT r t x) txs) s y = rawpsubstT (substT r t x) ((s, y) # txs)›*) have "… = rawpsubstT (rawpsubstT r [(t,x)]) ((s,y) # txs)" by simp also (*calculation: ‹(substT::'trm::type ⇒ 'trm::type ⇒ 'var::type ⇒ 'trm::type) (rawpsubstT (substT (r::'trm::type) (t::'trm::type) (x::'var::type)) (txs::('trm::type × 'var::type) list)) (s::'trm::type) (y::'var::type) = rawpsubstT (rawpsubstT r [(t, x)]) ((s, y) # txs)›*) have "… = rawpsubstT r ([(t,x)] @ ((s,y) # txs))" using Cons.prems (*‹r ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm› ‹∀x∈snd ` set (tx # txs). x ∉ FvarsT s› ‹∀t∈fst ` set (tx # txs). y ∉ FvarsT t› ‹distinct (map snd (tx # txs))› ‹s ∈ atrm› ‹(y::'var) ∈ (var::'var set)› ‹y ∉ snd ` set (tx # txs)›*) apply (intro rawpsubstT_compose (*‹⟦?t ∈ trm; snd ` set ?txs1.0 ⊆ var; fst ` set ?txs1.0 ⊆ atrm; snd ` set ?txs2.0 ⊆ var; fst ` set ?txs2.0 ⊆ atrm⟧ ⟹ rawpsubstT (rawpsubstT ?t ?txs1.0) ?txs2.0 = rawpsubstT ?t (?txs1.0 @ ?txs2.0)›*)) (*goals: 1. ‹⟦(r::'trm) ∈ atrm; snd ` set ((tx::'trm × 'var) # (txs::('trm × 'var) list)) ⊆ (var::'var set); fst ` set (tx # txs) ⊆ atrm; ∀x::'var∈snd ` set (tx # txs). x ∉ (FvarsT::'trm ⇒ 'var set) (s::'trm); ∀t::'trm∈fst ` set (tx # txs). (y::'var) ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ r ∈ (trm::'trm set)› 2. ‹⟦(r::'trm) ∈ atrm; snd ` set ((tx::'trm × 'var) # (txs::('trm × 'var) list)) ⊆ (var::'var set); fst ` set (tx # txs) ⊆ atrm; ∀x::'var∈snd ` set (tx # txs). x ∉ (FvarsT::'trm ⇒ 'var set) (s::'trm); ∀t::'trm∈fst ` set (tx # txs). (y::'var) ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ snd ` set [(t::'trm, x::'var)] ⊆ var› 3. ‹⟦(r::'trm) ∈ atrm; snd ` set ((tx::'trm × 'var) # (txs::('trm × 'var) list)) ⊆ (var::'var set); fst ` set (tx # txs) ⊆ atrm; ∀x::'var∈snd ` set (tx # txs). x ∉ (FvarsT::'trm ⇒ 'var set) (s::'trm); ∀t::'trm∈fst ` set (tx # txs). (y::'var) ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ fst ` set [(t::'trm, x::'var)] ⊆ atrm› 4. ‹⟦(r::'trm) ∈ atrm; snd ` set ((tx::'trm × 'var) # (txs::('trm × 'var) list)) ⊆ (var::'var set); fst ` set (tx # txs) ⊆ atrm; ∀x::'var∈snd ` set (tx # txs). x ∉ (FvarsT::'trm ⇒ 'var set) (s::'trm); ∀t::'trm∈fst ` set (tx # txs). (y::'var) ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ snd ` set ((s, y) # txs) ⊆ var› 5. ‹⟦(r::'trm) ∈ atrm; snd ` set ((tx::'trm × 'var) # (txs::('trm × 'var) list)) ⊆ (var::'var set); fst ` set (tx # txs) ⊆ atrm; ∀x::'var∈snd ` set (tx # txs). x ∉ (FvarsT::'trm ⇒ 'var set) (s::'trm); ∀t::'trm∈fst ` set (tx # txs). (y::'var) ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ fst ` set ((s, y) # txs) ⊆ atrm› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . also (*calculation: ‹substT (rawpsubstT (substT r t x) txs) s y = rawpsubstT r ([(t, x)] @ (s, y) # txs)›*) have "… = rawpsubstT r ([(t,x),(s,y)] @ txs)" by simp also (*calculation: ‹substT (rawpsubstT (substT r t x) txs) s y = rawpsubstT r ([(t, x), (s, y)] @ txs)›*) have "… = rawpsubstT (rawpsubstT r [(t,x),(s,y)]) txs" using Cons.prems (*‹r ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm› ‹∀x∈snd ` set (tx # txs). x ∉ FvarsT s› ‹∀t∈fst ` set (tx # txs). y ∉ FvarsT t› ‹distinct (map snd (tx # txs))› ‹s ∈ atrm› ‹y ∈ var› ‹y ∉ snd ` set (tx # txs)›*) apply (intro rawpsubstT_compose[symmetric] (*‹⟦?t ∈ trm; snd ` set ?txs1.0 ⊆ var; fst ` set ?txs1.0 ⊆ atrm; snd ` set ?txs2.0 ⊆ var; fst ` set ?txs2.0 ⊆ atrm⟧ ⟹ rawpsubstT ?t (?txs1.0 @ ?txs2.0) = rawpsubstT (rawpsubstT ?t ?txs1.0) ?txs2.0›*)) (*goals: 1. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ r ∈ trm› 2. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ snd ` set [(t, x), (s, y)] ⊆ var› 3. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ fst ` set [(t, x), (s, y)] ⊆ atrm› 4. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ snd ` set txs ⊆ var› 5. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ fst ` set txs ⊆ atrm› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . also (*calculation: ‹substT (rawpsubstT (substT r t x) txs) s y = rawpsubstT (rawpsubstT r [(t, x), (s, y)]) txs›*) have "rawpsubstT r [(t,x),(s,y)] = rawpsubstT r [(s,y),(t,x)]" using Cons.prems (*‹(r::'trm::type) ∈ atrm› ‹snd ` set ((tx::'trm × 'var) # (txs::('trm × 'var) list)) ⊆ (var::'var set)› ‹fst ` set (tx # txs) ⊆ atrm› ‹∀x∈snd ` set (tx # txs). x ∉ FvarsT s› ‹∀t∈fst ` set (tx # txs). y ∉ FvarsT t› ‹distinct (map snd (tx # txs))› ‹(s::'trm) ∈ atrm› ‹y ∈ var› ‹y ∉ snd ` set (tx # txs)›*) apply (intro rawpsubst2_fresh_switch (*‹⟦?r ∈ atrm; ?t ∈ trm; ?s ∈ trm; ?x ∈ var; ?y ∈ var; ?x ≠ ?y; ?x ∉ FvarsT ?s; ?y ∉ FvarsT ?t⟧ ⟹ rawpsubstT ?r [(?s, ?y), (?t, ?x)] = rawpsubstT ?r [(?t, ?x), (?s, ?y)]›*)) (*goals: 1. ‹⟦(r::'trm::type) ∈ atrm; snd ` set ((tx::'trm::type × 'var::type) # (txs::('trm::type × 'var::type) list)) ⊆ (var::'var::type set); fst ` set (tx # txs) ⊆ atrm; ∀x::'var::type∈snd ` set (tx # txs). x ∉ (FvarsT::'trm::type ⇒ 'var::type set) (s::'trm::type); ∀t::'trm::type∈fst ` set (tx # txs). (y::'var::type) ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ r ∈ atrm› 2. ‹⟦(r::'trm::type) ∈ atrm; snd ` set ((tx::'trm::type × 'var::type) # (txs::('trm::type × 'var::type) list)) ⊆ (var::'var::type set); fst ` set (tx # txs) ⊆ atrm; ∀x::'var::type∈snd ` set (tx # txs). x ∉ (FvarsT::'trm::type ⇒ 'var::type set) (s::'trm::type); ∀t::'trm::type∈fst ` set (tx # txs). (y::'var::type) ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ s ∈ (trm::'trm::type set)› 3. ‹⟦(r::'trm::type) ∈ atrm; snd ` set ((tx::'trm::type × 'var::type) # (txs::('trm::type × 'var::type) list)) ⊆ (var::'var::type set); fst ` set (tx # txs) ⊆ atrm; ∀x::'var::type∈snd ` set (tx # txs). x ∉ (FvarsT::'trm::type ⇒ 'var::type set) (s::'trm::type); ∀t::'trm::type∈fst ` set (tx # txs). (y::'var::type) ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ (t::'trm::type) ∈ (trm::'trm::type set)› 4. ‹⟦(r::'trm::type) ∈ atrm; snd ` set ((tx::'trm::type × 'var::type) # (txs::('trm::type × 'var::type) list)) ⊆ (var::'var::type set); fst ` set (tx # txs) ⊆ atrm; ∀x::'var::type∈snd ` set (tx # txs). x ∉ (FvarsT::'trm::type ⇒ 'var::type set) (s::'trm::type); ∀t::'trm::type∈fst ` set (tx # txs). (y::'var::type) ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ y ∈ var› 5. ‹⟦(r::'trm::type) ∈ atrm; snd ` set ((tx::'trm::type × 'var::type) # (txs::('trm::type × 'var::type) list)) ⊆ (var::'var::type set); fst ` set (tx # txs) ⊆ atrm; ∀x::'var::type∈snd ` set (tx # txs). x ∉ (FvarsT::'trm::type ⇒ 'var::type set) (s::'trm::type); ∀t::'trm::type∈fst ` set (tx # txs). (y::'var::type) ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ (x::'var::type) ∈ var› 6. ‹⟦(r::'trm::type) ∈ atrm; snd ` set ((tx::'trm::type × 'var::type) # (txs::('trm::type × 'var::type) list)) ⊆ (var::'var::type set); fst ` set (tx # txs) ⊆ atrm; ∀x::'var::type∈snd ` set (tx # txs). x ∉ (FvarsT::'trm::type ⇒ 'var::type set) (s::'trm::type); ∀t::'trm::type∈fst ` set (tx # txs). (y::'var::type) ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ y ≠ (x::'var::type)› 7. ‹⟦(r::'trm::type) ∈ atrm; snd ` set ((tx::'trm::type × 'var::type) # (txs::('trm::type × 'var::type) list)) ⊆ (var::'var::type set); fst ` set (tx # txs) ⊆ atrm; ∀x::'var::type∈snd ` set (tx # txs). x ∉ (FvarsT::'trm::type ⇒ 'var::type set) (s::'trm::type); ∀t::'trm::type∈fst ` set (tx # txs). (y::'var::type) ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ y ∉ FvarsT (t::'trm::type)› 8. ‹⟦(r::'trm::type) ∈ atrm; snd ` set ((tx::'trm::type × 'var::type) # (txs::('trm::type × 'var::type) list)) ⊆ (var::'var::type set); fst ` set (tx # txs) ⊆ atrm; ∀x::'var::type∈snd ` set (tx # txs). x ∉ (FvarsT::'trm::type ⇒ 'var::type set) (s::'trm::type); ∀t::'trm::type∈fst ` set (tx # txs). (y::'var::type) ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ (x::'var::type) ∉ FvarsT s› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*proven 8 subgoals*) . also (*calculation: ‹(substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) (rawpsubstT (substT (r::'trm) (t::'trm) (x::'var)) (txs::('trm × 'var) list)) (s::'trm) (y::'var) = rawpsubstT (rawpsubstT r [(s, y), (t, x)]) txs›*) have "rawpsubstT (rawpsubstT r [(s,y),(t,x)]) txs = rawpsubstT r ([(s,y),(t,x)] @ txs)" using Cons.prems (*‹r ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm› ‹∀x∈snd ` set (tx # txs). x ∉ FvarsT s› ‹∀t∈fst ` set (tx # txs). y ∉ FvarsT t› ‹distinct (map snd (tx # txs))› ‹s ∈ atrm› ‹y ∈ var› ‹(y::'var::type) ∉ snd ` set ((tx::'trm::type × 'var::type) # (txs::('trm::type × 'var::type) list))›*) apply (intro rawpsubstT_compose (*‹⟦?t ∈ trm; snd ` set ?txs1.0 ⊆ var; fst ` set ?txs1.0 ⊆ atrm; snd ` set ?txs2.0 ⊆ var; fst ` set ?txs2.0 ⊆ atrm⟧ ⟹ rawpsubstT (rawpsubstT ?t ?txs1.0) ?txs2.0 = rawpsubstT ?t (?txs1.0 @ ?txs2.0)›*)) (*goals: 1. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ r ∈ trm› 2. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ snd ` set [(s, y), (t, x)] ⊆ var› 3. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ fst ` set [(s, y), (t, x)] ⊆ atrm› 4. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ snd ` set txs ⊆ var› 5. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; ∀x∈snd ` set (tx # txs). x ∉ FvarsT s; ∀t∈fst ` set (tx # txs). y ∉ FvarsT t; distinct (map snd (tx # txs)); s ∈ atrm; y ∈ var; y ∉ snd ` set (tx # txs)⟧ ⟹ fst ` set txs ⊆ atrm› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . finally (*calculation: ‹substT (rawpsubstT (substT r t x) txs) s y = rawpsubstT r ([(s, y), (t, x)] @ txs)›*) show "?case" (*goal: ‹substT (rawpsubstT r (tx # txs)) s y = rawpsubstT r ((s, y) # tx # txs)›*) by simp qed (auto) (*solved the remaining goal: ‹⋀r s y. ⟦r ∈ atrm; snd ` set [] ⊆ var; fst ` set [] ⊆ atrm; ∀x∈snd ` set []. x ∉ FvarsT s; ∀t∈fst ` set []. y ∉ FvarsT t; distinct (map snd []); s ∈ atrm; y ∈ var; y ∉ snd ` set []⟧ ⟹ substT (rawpsubstT r []) s y = rawpsubstT r [(s, y)]›*) lemma rawpsubstT_compose_freshVar: assumes "r ∈ atrm" "snd ` (set txs) ⊆ var" and "fst ` (set txs) ⊆ atrm" and "distinct (map snd txs)" and "⋀ i j. i < j ⟹ j < length txs ⟹ snd (txs!j) ∉ FvarsT (fst (txs!i))" and us_facts: "set us ⊆ var" "set us ∩ FvarsT r = {}" "set us ∩ ⋃ (FvarsT ` (fst ` (set txs))) = {}" "set us ∩ snd ` (set txs) = {}" "length us = length txs" "distinct us" shows "rawpsubstT (rawpsubstT r (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT r txs" using assms (*‹(r::'trm) ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹distinct (map snd txs)› ‹⟦?i < ?j; ?j < length txs⟧ ⟹ snd (txs ! ?j) ∉ FvarsT (fst (txs ! ?i))› ‹set us ⊆ var› ‹set us ∩ FvarsT r = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct (us::'var list)›*) proof (induction txs arbitrary: us r) (*goals: 1. ‹⋀us r. ⟦r ∈ atrm; snd ` set [] ⊆ var; fst ` set [] ⊆ atrm; distinct (map snd []); ⋀i j. ⟦i < j; j < length []⟧ ⟹ snd ([] ! j) ∉ FvarsT (fst ([] ! i)); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set []) = {}; set us ∩ snd ` set [] = {}; length us = length []; distinct us⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map Var us) (map snd []))) (zip (map fst []) us) = rawpsubstT r []› 2. ‹⋀a txs us r. ⟦⋀us r. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT r txs; r ∈ atrm; snd ` set (a # txs) ⊆ var; fst ` set (a # txs) ⊆ atrm; distinct (map snd (a # txs)); ⋀i j. ⟦i < j; j < length (a # txs)⟧ ⟹ snd ((a # txs) ! j) ∉ FvarsT (fst ((a # txs) ! i)); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set (a # txs)) = {}; set us ∩ snd ` set (a # txs) = {}; length us = length (a # txs); distinct us⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map Var us) (map snd (a # txs)))) (zip (map fst (a # txs)) us) = rawpsubstT r (a # txs)›*) case (Cons tx txs uus r) (*‹⟦?r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); set ?us ⊆ var; set ?us ∩ FvarsT ?r = {}; set ?us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set ?us ∩ snd ` set txs = {}; length ?us = length txs; distinct ?us⟧ ⟹ rawpsubstT (rawpsubstT ?r (zip (map Var ?us) (map snd txs))) (zip (map fst txs) ?us) = rawpsubstT ?r txs› ‹r ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm› ‹distinct (map snd (tx # txs))› ‹⟦?i < ?j; ?j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! ?j) ∉ FvarsT (fst ((tx # txs) ! ?i))› ‹set (uus::'var list) ⊆ (var::'var set)› ‹set uus ∩ FvarsT r = {}› ‹set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}› ‹set uus ∩ snd ` set (tx # txs) = {}› ‹length uus = length (tx # txs)› ‹distinct (uus::'var list)›*) obtain t and x where tx[simp]: "tx = (t,x)" (*goal: ‹(⋀t x. tx = (t, x) ⟹ thesis) ⟹ thesis›*) by force obtain u and us where uus[simp]: "uus = u # us" (*goal: ‹(⋀u us. uus = u # us ⟹ thesis) ⟹ thesis›*) using Cons (*‹⟦?r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); set ?us ⊆ var; set ?us ∩ FvarsT ?r = {}; set ?us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set ?us ∩ snd ` set txs = {}; length ?us = length txs; distinct ?us⟧ ⟹ rawpsubstT (rawpsubstT ?r (zip (map Var ?us) (map snd txs))) (zip (map fst txs) ?us) = rawpsubstT ?r txs› ‹r ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm› ‹distinct (map snd (tx # txs))› ‹⟦?i < ?j; ?j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! ?j) ∉ FvarsT (fst ((tx # txs) ! ?i))› ‹set uus ⊆ var› ‹set uus ∩ FvarsT r = {}› ‹set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}› ‹set uus ∩ snd ` set (tx # txs) = {}› ‹length uus = length (tx # txs)› ‹distinct uus›*) apply (cases uus) (*goals: 1. ‹⟦⋀(u::'var) us::'var list. (uus::'var list) = u # us ⟹ thesis::bool; ⋀(r::'trm) us::'var list. ⟦r ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀(i::nat) j::nat. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ (FvarsT::'trm ⇒ 'var set) (fst (txs ! i)); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map (Var::'var ⇒ 'trm) us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT r txs; (r::'trm) ∈ atrm; snd ` set ((tx::'trm × 'var) # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀(i::nat) j::nat. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus; uus = []⟧ ⟹ thesis› 2. ‹⋀(a::'var) list::'var list. ⟦⋀(u::'var) us::'var list. (uus::'var list) = u # us ⟹ thesis::bool; ⋀(r::'trm) us::'var list. ⟦r ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀(i::nat) j::nat. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ (FvarsT::'trm ⇒ 'var set) (fst (txs ! i)); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map (Var::'var ⇒ 'trm) us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT r txs; (r::'trm) ∈ atrm; snd ` set ((tx::'trm × 'var) # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀(i::nat) j::nat. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus; uus = a # list⟧ ⟹ thesis› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have us_facts: "set us ⊆ var" "set us ∩ FvarsT r = {}" "set us ∩ ⋃ (FvarsT ` (fst ` (set txs))) = {}" "set us ∩ snd ` (set txs) = {}" "length us = length txs" "distinct us" and u_facts: "u ∈ var" "u ∉ FvarsT r" "u ∉ ⋃ (FvarsT ` (fst ` (set txs)))" "u ∉ snd ` (set txs)" "u ∉ set us" using Cons (*‹⟦(?r::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀(i::nat) j::nat. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ (FvarsT::'trm ⇒ 'var set) (fst (txs ! i)); set (?us::'var list) ⊆ var; set ?us ∩ FvarsT ?r = {}; set ?us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set ?us ∩ snd ` set txs = {}; length ?us = length txs; distinct ?us⟧ ⟹ rawpsubstT (rawpsubstT ?r (zip (map (Var::'var ⇒ 'trm) ?us) (map snd txs))) (zip (map fst txs) ?us) = rawpsubstT ?r txs› ‹r ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm› ‹distinct (map snd (tx # txs))› ‹⟦?i < ?j; ?j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! ?j) ∉ FvarsT (fst ((tx # txs) ! ?i))› ‹set uus ⊆ var› ‹set uus ∩ FvarsT r = {}› ‹set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}› ‹set uus ∩ snd ` set (tx # txs) = {}› ‹length uus = length (tx # txs)› ‹distinct (uus::'var list)›*) apply - (*goals: 1. ‹⟦⋀r us. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT r txs; r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ set us ⊆ var› 2. ‹⟦⋀r us. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT r txs; r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ set us ∩ FvarsT r = {}› 3. ‹⟦⋀r us. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT r txs; r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› 4. ‹⟦⋀r us. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT r txs; r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ set us ∩ snd ` set txs = {}› 5. ‹⟦⋀r us. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT r txs; r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ length us = length txs› 6. ‹⟦⋀r us. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT r txs; r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ distinct us› 7. ‹⟦⋀r us. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT r txs; r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ u ∈ var› 8. ‹⟦⋀r us. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT r txs; r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ u ∉ FvarsT r› 9. ‹⟦⋀r us. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT r txs; r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ u ∉ ⋃ (FvarsT ` fst ` set txs)› 10. ‹⟦⋀r us. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT r txs; r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ u ∉ snd ` set txs› 11. ‹⟦⋀r us. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT r txs; r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ u ∉ set us› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*discuss goal 9*) apply ((auto)[1]) (*discuss goal 10*) apply ((auto)[1]) (*discuss goal 11*) apply ((auto)[1]) (*proven 11 subgoals*) . have [simp]: "⋀ bb xaa ab. bb ∈ FvarsT (Var xaa) ⟹ (ab, bb) ∈ set txs ⟹ xaa ∉ set us" using us_facts(1,4) (*‹set us ⊆ var› ‹set us ∩ snd ` set txs = {}›*) by force let ?uxs = "zip (map Var us) (map snd txs)" have 1: "rawpsubstT (substT r (Var u) x) ?uxs = rawpsubstT r (?uxs @ [(Var u,x)])" using Cons.prems (*‹(r::'trm) ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm› ‹distinct (map snd ((tx::'trm × 'var) # (txs::('trm × 'var) list)))› ‹⟦?i < ?j; ?j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! ?j) ∉ FvarsT (fst ((tx # txs) ! ?i))› ‹set uus ⊆ var› ‹set uus ∩ FvarsT r = {}› ‹set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}› ‹set uus ∩ snd ` set (tx # txs) = {}› ‹length uus = length (tx # txs)› ‹distinct uus›*) u_facts (*‹u ∈ var› ‹u ∉ FvarsT r› ‹u ∉ ⋃ (FvarsT ` fst ` set txs)› ‹u ∉ snd ` set txs› ‹u ∉ set us›*) apply (intro rawpsubstT_subst_fresh_switch (*‹⟦(?r::'trm) ∈ atrm; snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ atrm; ∀x::'var∈snd ` set ?txs. x ∉ (FvarsT::'trm ⇒ 'var set) (?s::'trm); ∀t::'trm∈fst ` set ?txs. (?y::'var) ∉ FvarsT t; distinct (map snd ?txs); ?s ∈ atrm; ?y ∈ var; ?y ∉ snd ` set ?txs⟧ ⟹ rawpsubstT ((substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) ?r ?s ?y) ?txs = rawpsubstT ?r (?txs @ [(?s, ?y)])›*)) (*goal: ‹rawpsubstT (substT r (Var u) x) (zip (map Var us) (map snd txs)) = rawpsubstT r (zip (map Var us) (map snd txs) @ [(Var u, x)])›*) subgoal for by auto subgoal for by (auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) subgoal for by (fastforce dest!: set_zip_D (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) subgoal for by (auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) subgoal for by (fastforce dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) (*goals: 1. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus; u ∈ var; u ∉ FvarsT r; u ∉ ⋃ (FvarsT ` fst ` set txs); u ∉ snd ` set txs; u ∉ set us⟧ ⟹ distinct (map snd (zip (map Var us) (map snd txs)))› 2. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus; u ∈ var; u ∉ FvarsT r; u ∉ ⋃ (FvarsT ` fst ` set txs); u ∉ snd ` set txs; u ∉ set us⟧ ⟹ Var u ∈ atrm› 3. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus; u ∈ var; u ∉ FvarsT r; u ∉ ⋃ (FvarsT ` fst ` set txs); u ∉ snd ` set txs; u ∉ set us⟧ ⟹ x ∈ var› 4. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus; u ∈ var; u ∉ FvarsT r; u ∉ ⋃ (FvarsT ` fst ` set txs); u ∉ snd ` set txs; u ∉ set us⟧ ⟹ x ∉ snd ` set (zip (map Var us) (map snd txs))› discuss goal 1*) apply ((auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 2*) apply ((auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 3*) apply ((auto dest!: set_zip_D (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 4*) apply ((auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*proven 4 subgoals*) . let ?uuxs = "zip (map Var uus) (map snd (tx # txs))" let ?tus = "zip (map fst txs) us" let ?ttxs = "zip (map fst (tx # txs)) uus" have 2: "u ∈ FvarsT (rawpsubstT r (zip (map Var us) (map snd txs))) ⟹ False" apply (drule in_FvarsT_rawpsubstTD (*‹⟦?y ∈ FvarsT (rawpsubstT ?r ?txs); ?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; distinct (map snd ?txs); ∀x∈snd ` set ?txs. ∀t∈fst ` set ?txs. x ∉ FvarsT t⟧ ⟹ ?y ∈ FvarsT ?r - snd ` set ?txs ∨ ?y ∈ ⋃ {if x ∈ FvarsT ?r then FvarsT t else {} |t x. (t, x) ∈ set ?txs}›*)) (*goal: ‹u ∈ FvarsT (rawpsubstT r (zip (map Var us) (map snd txs))) ⟹ False›*) apply - (*top goal: ‹r ∈ atrm› and 5 goals remain*) subgoal for using Cons.prems (*‹r ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm› ‹distinct (map snd (tx # txs))› ‹⟦?i < ?j; ?j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! ?j) ∉ FvarsT (fst ((tx # txs) ! ?i))› ‹set uus ⊆ var› ‹set uus ∩ FvarsT r = {}› ‹set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}› ‹set uus ∩ snd ` set (tx # txs) = {}› ‹length uus = length (tx # txs)› ‹distinct uus›*) by auto subgoal for using Cons.prems (*‹r ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm› ‹distinct (map snd (tx # txs))› ‹⟦?i < ?j; ?j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! ?j) ∉ FvarsT (fst ((tx # txs) ! ?i))› ‹set uus ⊆ var› ‹set uus ∩ FvarsT r = {}› ‹set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}› ‹set uus ∩ snd ` set (tx # txs) = {}› ‹length uus = length (tx # txs)› ‹distinct uus›*) by (auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) subgoal for using Cons.prems (*‹r ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm› ‹distinct (map snd ((tx::'trm × 'var) # (txs::('trm × 'var) list)))› ‹⟦?i < ?j; ?j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! ?j) ∉ FvarsT (fst ((tx # txs) ! ?i))› ‹set uus ⊆ var› ‹set (uus::'var list) ∩ (FvarsT::'trm ⇒ 'var set) (r::'trm) = {}› ‹set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}› ‹set uus ∩ snd ` set (tx # txs) = {}› ‹length uus = length (tx # txs)› ‹distinct uus›*) by (force dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) subgoal for using Cons.prems (*‹(r::'trm::type) ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set ((tx::'trm × 'var) # (txs::('trm × 'var) list)) ⊆ atrm› ‹distinct (map snd (tx # txs))› ‹⟦?i < ?j; ?j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! ?j) ∉ FvarsT (fst ((tx # txs) ! ?i))› ‹set uus ⊆ var› ‹set (uus::'var list) ∩ (FvarsT::'trm ⇒ 'var set) (r::'trm) = {}› ‹set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}› ‹set uus ∩ snd ` set (tx # txs) = {}› ‹length (uus::'var::type list) = length ((tx::'trm::type × 'var::type) # (txs::('trm::type × 'var::type) list))› ‹distinct uus›*) by (auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) subgoal for by (auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) subgoal for using us_facts(1,4,5) (*‹set us ⊆ var› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs›*) Cons.prems(7) (*‹set uus ∩ FvarsT r = {}›*) by (fastforce dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) simp: u_facts( (*‹u ∉ set us›*) 5)) . have 3: "(tt, xx) ∉ set txs" if "xx ∈ FvarsT t" for tt and xx unfolding set_conv_nth mem_Collect_eq (*goal: ‹∄i. (tt, xx) = txs ! i ∧ i < length txs›*) proof (safe) (*goal: ‹⋀i. ⟦(tt, xx) = txs ! i; i < length txs⟧ ⟹ False›*) fix i assume "(tt, xx) = txs ! i" "i < length txs" (*‹(tt::'trm, xx::'var) = (txs::('trm × 'var) list) ! (i::nat)› ‹(i::nat) < length (txs::('trm × 'var) list)›*) then show False using that (*‹(xx::'var) ∈ (FvarsT::'trm ⇒ 'var set) (t::'trm)›*) Cons.prems(4) (*‹distinct (map snd (tx # txs))›*) Cons.prems(5)[of 0 "Suc i"] (*‹⟦0 < Suc i; Suc i < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! Suc i) ∉ FvarsT (fst ((tx # txs) ! 0))›*) tx (*‹tx = (t, x)›*) by (auto simp: nth_Cons' (*‹(?x # ?xs) ! ?n = (if ?n = 0 then ?x else ?xs ! (?n - 1))›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) dest: sym (*‹?s = ?t ⟹ ?t = ?s›*)) qed have 00: "rawpsubstT (rawpsubstT r ?uuxs) ?ttxs = rawpsubstT (substT (rawpsubstT r (?uxs @ [(Var u, x)])) t u) ?tus" by (simp add: 1 (*‹rawpsubstT ((substT::'trm::type ⇒ 'trm::type ⇒ 'var::type ⇒ 'trm::type) (r::'trm::type) ((Var::'var::type ⇒ 'trm::type) (u::'var::type)) (x::'var::type)) (zip (map Var (us::'var::type list)) (map snd (txs::('trm::type × 'var::type) list))) = rawpsubstT r (zip (map Var us) (map snd txs) @ [(Var u, x)])›*)) have "rawpsubstT r (?uxs @ [(Var u, x)]) = rawpsubstT (rawpsubstT r ?uxs) [(Var u, x)]" using Cons.prems (*‹(r::'trm::type) ∈ atrm› ‹snd ` set ((tx::'trm::type × 'var::type) # (txs::('trm::type × 'var::type) list)) ⊆ (var::'var::type set)› ‹fst ` set (tx # txs) ⊆ atrm› ‹distinct (map snd (tx # txs))› ‹⟦?i < ?j; ?j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! ?j) ∉ FvarsT (fst ((tx # txs) ! ?i))› ‹set uus ⊆ var› ‹set uus ∩ FvarsT r = {}› ‹set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}› ‹set uus ∩ snd ` set (tx # txs) = {}› ‹length uus = length (tx # txs)› ‹distinct uus›*) apply (intro rawpsubstT_compose[symmetric] (*‹⟦?t ∈ trm; snd ` set ?txs1.0 ⊆ var; fst ` set ?txs1.0 ⊆ atrm; snd ` set ?txs2.0 ⊆ var; fst ` set ?txs2.0 ⊆ atrm⟧ ⟹ rawpsubstT ?t (?txs1.0 @ ?txs2.0) = rawpsubstT (rawpsubstT ?t ?txs1.0) ?txs2.0›*)) (*goals: 1. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ r ∈ trm› 2. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ snd ` set (zip (map Var us) (map snd txs)) ⊆ var› 3. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ fst ` set (zip (map Var us) (map snd txs)) ⊆ atrm› 4. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ snd ` set [(Var u, x)] ⊆ var› 5. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ fst ` set [(Var u, x)] ⊆ atrm› discuss goal 1*) apply ((auto 0 3 dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 2*) apply ((auto 0 3 dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 3*) apply ((auto 0 3 dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 4*) apply ((auto 0 3 dest!: set_zip_D (*‹(?x::?'a::type, ?y::?'b::type) ∈ set (zip (?xs::?'a::type list) (?ys::?'b::type list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 5*) apply ((auto 0 3 dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*proven 5 subgoals*) . also (*calculation: ‹rawpsubstT r (zip (map Var us) (map snd txs) @ [(Var u, x)]) = rawpsubstT (rawpsubstT r (zip (map Var us) (map snd txs))) [(Var u, x)]›*) have "rawpsubstT (rawpsubstT r ?uxs) [(Var u, x)] = substT (rawpsubstT r ?uxs) (Var u) x" by simp finally (*calculation: ‹rawpsubstT r (zip (map Var us) (map snd txs) @ [(Var u, x)]) = substT (rawpsubstT r (zip (map Var us) (map snd txs))) (Var u) x›*) have "substT (rawpsubstT r (?uxs @ [(Var u, x)])) t u = substT (substT (rawpsubstT r ?uxs) (Var u) x) t u" by simp also (*calculation: ‹substT (rawpsubstT r (zip (map Var us) (map snd txs) @ [(Var u, x)])) t u = substT (substT (rawpsubstT r (zip (map Var us) (map snd txs))) (Var u) x) t u›*) have "… = substT (rawpsubstT r ?uxs) t x" using Cons (*‹⟦?r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); set ?us ⊆ var; set ?us ∩ FvarsT ?r = {}; set ?us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set ?us ∩ snd ` set txs = {}; length ?us = length txs; distinct ?us⟧ ⟹ rawpsubstT (rawpsubstT ?r (zip (map Var ?us) (map snd txs))) (zip (map fst txs) ?us) = rawpsubstT ?r txs› ‹r ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm› ‹distinct (map snd (tx # txs))› ‹⟦?i < ?j; ?j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! ?j) ∉ FvarsT (fst ((tx # txs) ! ?i))› ‹set uus ⊆ var› ‹set uus ∩ FvarsT r = {}› ‹set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}› ‹set (uus::'var list) ∩ snd ` set ((tx::'trm × 'var) # (txs::('trm × 'var) list)) = {}› ‹length uus = length (tx # txs)› ‹distinct uus›*) "2" (*‹u ∈ FvarsT (rawpsubstT r (zip (map Var us) (map snd txs))) ⟹ False›*) apply (intro substT_substT (*‹⟦?s ∈ atrm; ?t ∈ trm; ?x ∈ var; ?y ∈ var; ?x ≠ ?y; ?y ∉ FvarsT ?s⟧ ⟹ substT (substT ?s (Var ?y) ?x) ?t ?y = substT ?s ?t ?x›*)) (*goals: 1. ‹⟦⋀r us. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT r txs; r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus; u ∈ FvarsT (rawpsubstT r (zip (map Var us) (map snd txs))) ⟹ False⟧ ⟹ rawpsubstT r (zip (map Var us) (map snd txs)) ∈ atrm› 2. ‹⟦⋀r us. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT r txs; r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus; u ∈ FvarsT (rawpsubstT r (zip (map Var us) (map snd txs))) ⟹ False⟧ ⟹ t ∈ trm› 3. ‹⟦⋀r us. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT r txs; r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus; u ∈ FvarsT (rawpsubstT r (zip (map Var us) (map snd txs))) ⟹ False⟧ ⟹ x ∈ var› 4. ‹⟦⋀r us. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT r txs; r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus; u ∈ FvarsT (rawpsubstT r (zip (map Var us) (map snd txs))) ⟹ False⟧ ⟹ u ∈ var› 5. ‹⟦⋀r us. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT r txs; r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus; u ∈ FvarsT (rawpsubstT r (zip (map Var us) (map snd txs))) ⟹ False⟧ ⟹ x ≠ u› 6. ‹⟦⋀r us. ⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT r txs; r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus; u ∈ FvarsT (rawpsubstT r (zip (map Var us) (map snd txs))) ⟹ False⟧ ⟹ u ∉ FvarsT (rawpsubstT r (zip (map Var us) (map snd txs)))› discuss goal 1*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of r] (*‹⟦r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT r ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 2*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of r] (*‹⟦(r::'trm) ∈ atrm; snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT r ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 3*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of r] (*‹⟦r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT r ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 4*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of r] (*‹⟦(r::'trm) ∈ atrm; snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT r ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 5*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of r] (*‹⟦r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT r ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 6*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of r] (*‹⟦(r::'trm) ∈ atrm; snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT r ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*proven 6 subgoals*) . also (*calculation: ‹substT (rawpsubstT r (zip (map Var us) (map snd txs) @ [(Var u, x)])) t u = substT (rawpsubstT r (zip (map Var us) (map snd txs))) t x›*) have "… = rawpsubstT r ((t,x) # ?uxs)" using Cons.prems (*‹r ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm› ‹distinct (map snd (tx # txs))› ‹⟦?i < ?j; ?j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! ?j) ∉ FvarsT (fst ((tx # txs) ! ?i))› ‹set uus ⊆ var› ‹set uus ∩ FvarsT r = {}› ‹set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}› ‹set (uus::'var::type list) ∩ snd ` set ((tx::'trm::type × 'var::type) # (txs::('trm::type × 'var::type) list)) = {}› ‹length (uus::'var list) = length ((tx::'trm × 'var) # (txs::('trm × 'var) list))› ‹distinct uus›*) "3" (*‹?xx ∈ FvarsT t ⟹ (?tt, ?xx) ∉ set txs›*) apply (intro substT_rawpsubstT_fresh_switch (*‹⟦(?r::'trm::type) ∈ atrm; snd ` set (?txs::('trm::type × 'var::type) list) ⊆ (var::'var::type set); fst ` set ?txs ⊆ atrm; ∀x::'var::type∈snd ` set ?txs. x ∉ (FvarsT::'trm::type ⇒ 'var::type set) (?s::'trm::type); ∀t::'trm::type∈fst ` set ?txs. (?y::'var::type) ∉ FvarsT t; distinct (map snd ?txs); ?s ∈ atrm; ?y ∈ var; ?y ∉ snd ` set ?txs⟧ ⟹ (substT::'trm::type ⇒ 'trm::type ⇒ 'var::type ⇒ 'trm::type) (rawpsubstT ?r ?txs) ?s ?y = rawpsubstT ?r ((?s, ?y) # ?txs)›*)) (*goals: 1. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus; ⋀xx tt. xx ∈ FvarsT t ⟹ (tt, xx) ∉ set txs⟧ ⟹ r ∈ atrm› 2. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus; ⋀xx tt. xx ∈ FvarsT t ⟹ (tt, xx) ∉ set txs⟧ ⟹ snd ` set (zip (map Var us) (map snd txs)) ⊆ var› 3. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus; ⋀xx tt. xx ∈ FvarsT t ⟹ (tt, xx) ∉ set txs⟧ ⟹ fst ` set (zip (map Var us) (map snd txs)) ⊆ atrm› 4. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus; ⋀xx tt. xx ∈ FvarsT t ⟹ (tt, xx) ∉ set txs⟧ ⟹ ∀x∈snd ` set (zip (map Var us) (map snd txs)). x ∉ FvarsT t› 5. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus; ⋀xx tt. xx ∈ FvarsT t ⟹ (tt, xx) ∉ set txs⟧ ⟹ ∀t∈fst ` set (zip (map Var us) (map snd txs)). x ∉ FvarsT t› 6. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus; ⋀xx tt. xx ∈ FvarsT t ⟹ (tt, xx) ∉ set txs⟧ ⟹ distinct (map snd (zip (map Var us) (map snd txs)))› 7. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus; ⋀xx tt. xx ∈ FvarsT t ⟹ (tt, xx) ∉ set txs⟧ ⟹ t ∈ atrm› 8. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus; ⋀xx tt. xx ∈ FvarsT t ⟹ (tt, xx) ∉ set txs⟧ ⟹ x ∈ var› 9. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus; ⋀xx tt. xx ∈ FvarsT t ⟹ (tt, xx) ∉ set txs⟧ ⟹ x ∉ snd ` set (zip (map Var us) (map snd txs))› discuss goal 1*) apply ((auto 0 3 dest!: set_zip_D (*‹(?x::?'a::type, ?y::?'b::type) ∈ set (zip (?xs::?'a::type list) (?ys::?'b::type list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) FvarsT_VarD (*‹⟦(?x::'var::type) ∈ (FvarsT::'trm::type ⇒ 'var::type set) ((Var::'var::type ⇒ 'trm::type) (?y::'var::type)); ?y ∈ (var::'var::type set)⟧ ⟹ ?x = ?y›*))[1]) (*discuss goal 2*) apply ((auto 0 3 dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*))[1]) (*discuss goal 3*) apply ((auto 0 3 dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*))[1]) (*discuss goal 4*) apply ((auto 0 3 dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*))[1]) (*discuss goal 5*) apply ((auto 0 3 dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*))[1]) (*discuss goal 6*) apply ((auto 0 3 dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*))[1]) (*discuss goal 7*) apply ((auto 0 3 dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*))[1]) (*discuss goal 8*) apply ((auto 0 3 dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*))[1]) (*discuss goal 9*) apply ((auto 0 3 dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*))[1]) (*proven 9 subgoals*) . also (*calculation: ‹(substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) (rawpsubstT (r::'trm) (zip (map (Var::'var ⇒ 'trm) (us::'var list)) (map snd (txs::('trm × 'var) list)) @ [(Var (u::'var), x::'var)])) (t::'trm) u = rawpsubstT r ((t, x) # zip (map Var us) (map snd txs))›*) have "… = rawpsubstT r ([(t,x)] @ ?uxs)" by simp also (*calculation: ‹(substT::'trm::type ⇒ 'trm::type ⇒ 'var::type ⇒ 'trm::type) (rawpsubstT (r::'trm::type) (zip (map (Var::'var::type ⇒ 'trm::type) (us::'var::type list)) (map snd (txs::('trm::type × 'var::type) list)) @ [(Var (u::'var::type), x::'var::type)])) (t::'trm::type) u = rawpsubstT r ([(t, x)] @ zip (map Var us) (map snd txs))›*) have "… = rawpsubstT (rawpsubstT r [(t,x)]) ?uxs" using Cons.prems (*‹(r::'trm::type) ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ atrm› ‹distinct (map snd (tx # txs))› ‹⟦?i < ?j; ?j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! ?j) ∉ FvarsT (fst ((tx # txs) ! ?i))› ‹set uus ⊆ var› ‹set uus ∩ FvarsT r = {}› ‹set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}› ‹set uus ∩ snd ` set (tx # txs) = {}› ‹length uus = length (tx # txs)› ‹distinct (uus::'var list)›*) apply (intro rawpsubstT_compose[symmetric] (*‹⟦?t ∈ trm; snd ` set ?txs1.0 ⊆ var; fst ` set ?txs1.0 ⊆ atrm; snd ` set ?txs2.0 ⊆ var; fst ` set ?txs2.0 ⊆ atrm⟧ ⟹ rawpsubstT ?t (?txs1.0 @ ?txs2.0) = rawpsubstT (rawpsubstT ?t ?txs1.0) ?txs2.0›*)) (*goals: 1. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ r ∈ trm› 2. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ snd ` set [(t, x)] ⊆ var› 3. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ fst ` set [(t, x)] ⊆ atrm› 4. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ snd ` set (zip (map Var us) (map snd txs)) ⊆ var› 5. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ fst ` set (zip (map Var us) (map snd txs)) ⊆ atrm› discuss goal 1*) apply ((auto 0 3 dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 2*) apply ((auto 0 3 dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 3*) apply ((auto 0 3 dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 4*) apply ((auto 0 3 dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 5*) apply ((auto 0 3 dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*proven 5 subgoals*) . finally (*calculation: ‹substT (rawpsubstT r (zip (map Var us) (map snd txs) @ [(Var u, x)])) t u = rawpsubstT (rawpsubstT r [(t, x)]) (zip (map Var us) (map snd txs))›*) have "rawpsubstT (substT (rawpsubstT r (?uxs @ [(Var u, x)])) t u) ?tus = rawpsubstT (rawpsubstT (rawpsubstT r [(t,x)]) ?uxs) ?tus" by auto hence "rawpsubstT (rawpsubstT r ?uuxs) ?ttxs = rawpsubstT (rawpsubstT (rawpsubstT r [(t,x)]) ?uxs) ?tus" using "00" (*‹rawpsubstT (rawpsubstT r (zip (map Var uus) (map snd (tx # txs)))) (zip (map fst (tx # txs)) uus) = rawpsubstT (substT (rawpsubstT r (zip (map Var us) (map snd txs) @ [(Var u, x)])) t u) (zip (map fst txs) us)›*) by auto also (*calculation: ‹rawpsubstT (rawpsubstT (r::'trm::type) (zip (map (Var::'var::type ⇒ 'trm::type) (uus::'var::type list)) (map snd ((tx::'trm::type × 'var::type) # (txs::('trm::type × 'var::type) list))))) (zip (map fst (tx # txs)) uus) = rawpsubstT (rawpsubstT (rawpsubstT r [(t::'trm::type, x::'var::type)]) (zip (map Var (us::'var::type list)) (map snd txs))) (zip (map fst txs) us)›*) have "… = rawpsubstT (rawpsubstT r [(t,x)]) txs" using Cons.prems (*‹r ∈ atrm› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set ((tx::'trm × 'var) # (txs::('trm × 'var) list)) ⊆ atrm› ‹distinct (map snd ((tx::'trm × 'var) # (txs::('trm × 'var) list)))› ‹⟦?i < ?j; ?j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! ?j) ∉ FvarsT (fst ((tx # txs) ! ?i))› ‹set (uus::'var list) ⊆ (var::'var set)› ‹set uus ∩ FvarsT r = {}› ‹set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}› ‹set (uus::'var::type list) ∩ snd ` set ((tx::'trm::type × 'var::type) # (txs::('trm::type × 'var::type) list)) = {}› ‹length uus = length (tx # txs)› ‹distinct uus›*) apply (intro Cons.IH (*‹⟦?r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); set ?us ⊆ var; set ?us ∩ FvarsT ?r = {}; set ?us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set ?us ∩ snd ` set txs = {}; length ?us = length txs; distinct ?us⟧ ⟹ rawpsubstT (rawpsubstT ?r (zip (map Var ?us) (map snd txs))) (zip (map fst txs) ?us) = rawpsubstT ?r txs›*)) (*goal: ‹rawpsubstT (rawpsubstT (rawpsubstT r [(t, x)]) (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT (rawpsubstT r [(t, x)]) txs›*) subgoal for by auto subgoal for by auto subgoal for by auto subgoal for by auto subgoal for by (metis Suc_leI (*‹(?m::nat) < (?n::nat) ⟹ Suc ?m ≤ ?n›*) le_imp_less_Suc (*‹(?m::nat) ≤ (?n::nat) ⟹ ?m < Suc ?n›*) length_Cons (*‹length ((?x::?'a) # (?xs::?'a list)) = Suc (length ?xs)›*) nth_Cons_Suc (*‹((?x::?'a) # (?xs::?'a list)) ! Suc (?n::nat) = ?xs ! ?n›*)) subgoal for by auto subgoal for by (auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) in_FvarsT_substTD (*‹⟦?y ∈ FvarsT (substT ?r ?t ?x); ?r ∈ atrm; ?t ∈ trm; ?x ∈ var⟧ ⟹ ?y ∈ FvarsT ?r - {?x} ∪ (if ?x ∈ FvarsT ?r then FvarsT ?t else {})›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) (*goals: 1. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› 2. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ set us ∩ snd ` set txs = {}› 3. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ length us = length txs› 4. ‹⟦r ∈ atrm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ atrm; distinct (map snd (tx # txs)); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i)); set uus ⊆ var; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` fst ` set (tx # txs)) = {}; set uus ∩ snd ` set (tx # txs) = {}; length uus = length (tx # txs); distinct uus⟧ ⟹ distinct us› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . finally (*calculation: ‹rawpsubstT (rawpsubstT r (zip (map Var uus) (map snd (tx # txs)))) (zip (map fst (tx # txs)) uus) = rawpsubstT (rawpsubstT r [(t, x)]) txs›*) show "?case" (*goal: ‹rawpsubstT (rawpsubstT r (zip (map Var uus) (map snd (tx # txs)))) (zip (map fst (tx # txs)) uus) = rawpsubstT r (tx # txs)›*) by simp qed (auto) (*solved the remaining goal: ‹⋀us r. ⟦r ∈ atrm; snd ` set [] ⊆ var; fst ` set [] ⊆ atrm; distinct (map snd []); ⋀i j. ⟦i < j; j < length []⟧ ⟹ snd ([] ! j) ∉ FvarsT (fst ([] ! i)); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set []) = {}; set us ∩ snd ` set [] = {}; length us = length []; distinct us⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map Var us) (map snd []))) (zip (map fst []) us) = rawpsubstT r []›*) lemma rawpsubstT_compose_freshVar2_aux: assumes r[simp]: "r ∈ atrm" and ts: "set ts ⊆ atrm" and xs: "set xs ⊆ var" "distinct xs" and us_facts: "set us ⊆ var" "distinct us" "set us ∩ FvarsT r = {}" "set us ∩ ⋃ (FvarsT ` (set ts)) = {}" "set us ∩ set xs = {}" and vs_facts: "set vs ⊆ var" "distinct vs" "set vs ∩ FvarsT r = {}" "set vs ∩ ⋃ (FvarsT ` (set ts)) = {}" "set vs ∩ set xs = {}" and l: "length us = length xs" "length vs = length xs" "length ts = length xs" and (* Extra hypothesis, only to get induction through: *) d: "set us ∩ set vs = {}" shows "rawpsubstT (rawpsubstT r (zip (map Var us) xs)) (zip ts us) = rawpsubstT (rawpsubstT r (zip (map Var vs) xs)) (zip ts vs)" using assms (*‹r ∈ atrm› ‹set ts ⊆ atrm› ‹set xs ⊆ var› ‹distinct xs› ‹set us ⊆ var› ‹distinct us› ‹set us ∩ FvarsT r = {}› ‹set us ∩ ⋃ (FvarsT ` set ts) = {}› ‹set us ∩ set xs = {}› ‹set (vs::'var list) ⊆ (var::'var set)› ‹distinct vs› ‹set vs ∩ FvarsT r = {}› and more 6 facts*) proof (induction xs arbitrary: r ts us vs) (*goals: 1. ‹⋀(r::'trm::type) (ts::'trm::type list) (us::'var::type list) vs::'var::type list. ⟦r ∈ atrm; set ts ⊆ atrm; set [] ⊆ (var::'var::type set); distinct []; set us ⊆ var; distinct us; set us ∩ (FvarsT::'trm::type ⇒ 'var::type set) r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set [] = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set [] = {}; length us = length []; length vs = length []; length ts = length []; set us ∩ set vs = {}⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map (Var::'var::type ⇒ 'trm::type) us) [])) (zip ts us) = rawpsubstT (rawpsubstT r (zip (map Var vs) [])) (zip ts vs)› 2. ‹⋀(a::'var::type) (xs::'var::type list) (r::'trm::type) (ts::'trm::type list) (us::'var::type list) vs::'var::type list. ⟦⋀(r::'trm::type) (ts::'trm::type list) (us::'var::type list) vs::'var::type list. ⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ (var::'var::type set); distinct xs; set us ⊆ var; distinct us; set us ∩ (FvarsT::'trm::type ⇒ 'var::type set) r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set us ∩ set vs = {}⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map (Var::'var::type ⇒ 'trm::type) us) xs)) (zip ts us) = rawpsubstT (rawpsubstT r (zip (map Var vs) xs)) (zip ts vs); r ∈ atrm; set ts ⊆ atrm; set (a # xs) ⊆ var; distinct (a # xs); set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set (a # xs) = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set (a # xs) = {}; length us = length (a # xs); length vs = length (a # xs); length ts = length (a # xs); set us ∩ set vs = {}⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map Var us) (a # xs))) (zip ts us) = rawpsubstT (rawpsubstT r (zip (map Var vs) (a # xs))) (zip ts vs)›*) case (Cons x xs r tts uus vvs) (*‹⟦?r ∈ atrm; set ?ts ⊆ atrm; set xs ⊆ var; distinct xs; set ?us ⊆ var; distinct ?us; set ?us ∩ FvarsT ?r = {}; set ?us ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?us ∩ set xs = {}; set ?vs ⊆ var; distinct ?vs; set ?vs ∩ FvarsT ?r = {}; set ?vs ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?vs ∩ set xs = {}; length ?us = length xs; length ?vs = length xs; length ?ts = length xs; set ?us ∩ set ?vs = {}⟧ ⟹ rawpsubstT (rawpsubstT ?r (zip (map Var ?us) xs)) (zip ?ts ?us) = rawpsubstT (rawpsubstT ?r (zip (map Var ?vs) xs)) (zip ?ts ?vs)› ‹r ∈ atrm› ‹set tts ⊆ atrm› ‹set (x # xs) ⊆ var› ‹distinct (x # xs)› ‹set uus ⊆ var› ‹distinct uus› ‹set uus ∩ FvarsT r = {}› ‹set uus ∩ ⋃ (FvarsT ` set tts) = {}› ‹set (uus::'var list) ∩ set ((x::'var) # (xs::'var list)) = {}› ‹set vvs ⊆ var› ‹distinct vvs› ‹set (vvs::'var list) ∩ (FvarsT::'trm ⇒ 'var set) (r::'trm) = {}› ‹set vvs ∩ ⋃ (FvarsT ` set tts) = {}› ‹set (vvs::'var::type list) ∩ set ((x::'var::type) # (xs::'var::type list)) = {}› ‹length uus = length (x # xs)› ‹length vvs = length (x # xs)› ‹length tts = length (x # xs)› ‹set uus ∩ set vvs = {}›*) obtain t and ts and u and us and v and vs where tts[simp]: "tts = t # ts" and lts[simp]: "length ts = length xs" and uus[simp]: "uus = u # us" and lus[simp]: "length us = length xs" and vvs[simp]: "vvs = v # vs" and lvs[simp]: "length vs = length xs" (*goal: ‹(⋀t ts u us v vs. ⟦tts = t # ts; length ts = length xs; uus = u # us; length us = length xs; vvs = v # vs; length vs = length xs⟧ ⟹ thesis) ⟹ thesis›*) using ‹length uus = length (x # xs)› (*‹length uus = length (x # xs)›*) ‹length vvs = length (x # xs)› (*‹length vvs = length (x # xs)›*) ‹length tts = length (x # xs)› (*‹length (tts::'trm::type list) = length ((x::'var::type) # (xs::'var::type list))›*) apply (cases tts) (*goal: ‹(⋀(t::'trm::type) (ts::'trm::type list) (u::'var::type) (us::'var::type list) (v::'var::type) vs::'var::type list. ⟦(tts::'trm::type list) = t # ts; length ts = length (xs::'var::type list); (uus::'var::type list) = u # us; length us = length xs; (vvs::'var::type list) = v # vs; length vs = length xs⟧ ⟹ thesis::bool) ⟹ thesis›*) subgoal for by auto subgoal for apply (cases uus) (*goal: ‹⟦⋀t ts u us v vs. ⟦tts = t # ts; length ts = length xs; uus = u # us; length us = length xs; vvs = v # vs; length vs = length xs⟧ ⟹ thesis; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); tts = a_ # list_⟧ ⟹ thesis›*) subgoal for by auto subgoal for apply (cases vvs) (*goals: 1. ‹⟦⋀t ts u us v vs. ⟦tts = t # ts; length ts = length xs; uus = u # us; length us = length xs; vvs = v # vs; length vs = length xs⟧ ⟹ thesis; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); tts = a_ # list_; uus = aa_ # lista_; vvs = []⟧ ⟹ thesis› 2. ‹⋀ab listb. ⟦⋀t ts u us v vs. ⟦tts = t # ts; length ts = length xs; uus = u # us; length us = length xs; vvs = v # vs; length vs = length xs⟧ ⟹ thesis; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); tts = a_ # list_; uus = aa_ # lista_; vvs = ab # listb⟧ ⟹ thesis› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . . . let ?rux = "substT r (Var u) x" let ?rvx = "substT r (Var v) x" have 0: "rawpsubstT (rawpsubstT ?rux (zip (map Var us) xs)) (zip ts us) = rawpsubstT (rawpsubstT ?rux (zip (map Var vs) xs)) (zip ts vs)" using Cons.prems (*‹r ∈ atrm› ‹set tts ⊆ atrm› ‹set (x # xs) ⊆ var› ‹distinct ((x::'var::type) # (xs::'var::type list))› ‹set uus ⊆ var› ‹distinct uus› ‹set (uus::'var list) ∩ (FvarsT::'trm ⇒ 'var set) (r::'trm) = {}› ‹set (uus::'var::type list) ∩ ⋃ ((FvarsT::'trm::type ⇒ 'var::type set) ` set (tts::'trm::type list)) = {}› ‹set uus ∩ set (x # xs) = {}› ‹set vvs ⊆ var› ‹distinct vvs› ‹set vvs ∩ FvarsT r = {}› and more 6 facts*) apply (intro Cons.IH (*‹⟦?r ∈ atrm; set ?ts ⊆ atrm; set xs ⊆ var; distinct xs; set ?us ⊆ var; distinct ?us; set ?us ∩ FvarsT ?r = {}; set ?us ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?us ∩ set xs = {}; set ?vs ⊆ var; distinct ?vs; set ?vs ∩ FvarsT ?r = {}; set ?vs ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?vs ∩ set xs = {}; length ?us = length xs; length ?vs = length xs; length ?ts = length xs; set ?us ∩ set ?vs = {}⟧ ⟹ rawpsubstT (rawpsubstT ?r (zip (map Var ?us) xs)) (zip ?ts ?us) = rawpsubstT (rawpsubstT ?r (zip (map Var ?vs) xs)) (zip ?ts ?vs)›*)) (*goals: 1. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ substT r (Var u) x ∈ atrm› 2. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ set ts ⊆ atrm› 3. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ set xs ⊆ var› 4. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ distinct xs› 5. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ set us ⊆ var› 6. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ distinct us› 7. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ set us ∩ FvarsT (substT r (Var u) x) = {}› 8. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ set us ∩ ⋃ (FvarsT ` set ts) = {}› 9. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ set us ∩ set xs = {}› 10. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ set vs ⊆ var› 11. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ distinct vs› 12. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ set vs ∩ FvarsT (substT r (Var u) x) = {}› 13. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ set vs ∩ ⋃ (FvarsT ` set ts) = {}› 14. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ set vs ∩ set xs = {}› 15. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ length us = length xs› 16. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ length vs = length xs› 17. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ length ts = length xs› 18. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ set us ∩ set vs = {}› discuss goal 1*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: FvarsT_substT (*‹⟦?s ∈ atrm; ?t ∈ trm; ?x ∈ var⟧ ⟹ FvarsT (substT ?s ?t ?x) = FvarsT ?s - {?x} ∪ (if ?x ∈ FvarsT ?s then FvarsT ?t else {})›*))[1]) (*discuss goal 2*) apply ((auto intro!: rawpsubstT (*‹⟦(?t::'trm::type) ∈ (trm::'trm::type set); snd ` set (?txs::('trm::type × 'var::type) list) ⊆ (var::'var::type set); fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x::?'a::type, ?y::?'b::type) ∈ set (zip (?xs::?'a::type list) (?ys::?'b::type list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: FvarsT_substT (*‹⟦(?s::'trm::type) ∈ atrm; (?t::'trm::type) ∈ (trm::'trm::type set); (?x::'var::type) ∈ (var::'var::type set)⟧ ⟹ (FvarsT::'trm::type ⇒ 'var::type set) ((substT::'trm::type ⇒ 'trm::type ⇒ 'var::type ⇒ 'trm::type) ?s ?t ?x) = FvarsT ?s - {?x} ∪ (if ?x ∈ FvarsT ?s then FvarsT ?t else {})›*))[1]) (*discuss goal 3*) apply ((auto intro!: rawpsubstT (*‹⟦(?t::'trm) ∈ (trm::'trm set); snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: FvarsT_substT (*‹⟦(?s::'trm) ∈ atrm; (?t::'trm) ∈ (trm::'trm set); (?x::'var) ∈ (var::'var set)⟧ ⟹ (FvarsT::'trm ⇒ 'var set) ((substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) ?s ?t ?x) = FvarsT ?s - {?x} ∪ (if ?x ∈ FvarsT ?s then FvarsT ?t else {})›*))[1]) (*discuss goal 4*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: FvarsT_substT (*‹⟦?s ∈ atrm; ?t ∈ trm; ?x ∈ var⟧ ⟹ FvarsT (substT ?s ?t ?x) = FvarsT ?s - {?x} ∪ (if ?x ∈ FvarsT ?s then FvarsT ?t else {})›*))[1]) (*discuss goal 5*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: FvarsT_substT (*‹⟦?s ∈ atrm; ?t ∈ trm; ?x ∈ var⟧ ⟹ FvarsT (substT ?s ?t ?x) = FvarsT ?s - {?x} ∪ (if ?x ∈ FvarsT ?s then FvarsT ?t else {})›*))[1]) (*discuss goal 6*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: FvarsT_substT (*‹⟦?s ∈ atrm; ?t ∈ trm; ?x ∈ var⟧ ⟹ FvarsT (substT ?s ?t ?x) = FvarsT ?s - {?x} ∪ (if ?x ∈ FvarsT ?s then FvarsT ?t else {})›*))[1]) (*discuss goal 7*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: FvarsT_substT (*‹⟦?s ∈ atrm; ?t ∈ trm; ?x ∈ var⟧ ⟹ FvarsT (substT ?s ?t ?x) = FvarsT ?s - {?x} ∪ (if ?x ∈ FvarsT ?s then FvarsT ?t else {})›*))[1]) (*discuss goal 8*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: FvarsT_substT (*‹⟦?s ∈ atrm; ?t ∈ trm; ?x ∈ var⟧ ⟹ FvarsT (substT ?s ?t ?x) = FvarsT ?s - {?x} ∪ (if ?x ∈ FvarsT ?s then FvarsT ?t else {})›*))[1]) (*discuss goal 9*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: FvarsT_substT (*‹⟦?s ∈ atrm; ?t ∈ trm; ?x ∈ var⟧ ⟹ FvarsT (substT ?s ?t ?x) = FvarsT ?s - {?x} ∪ (if ?x ∈ FvarsT ?s then FvarsT ?t else {})›*))[1]) (*discuss goal 10*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: FvarsT_substT (*‹⟦?s ∈ atrm; ?t ∈ trm; ?x ∈ var⟧ ⟹ FvarsT (substT ?s ?t ?x) = FvarsT ?s - {?x} ∪ (if ?x ∈ FvarsT ?s then FvarsT ?t else {})›*))[1]) (*discuss goal 11*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: FvarsT_substT (*‹⟦?s ∈ atrm; ?t ∈ trm; ?x ∈ var⟧ ⟹ FvarsT (substT ?s ?t ?x) = FvarsT ?s - {?x} ∪ (if ?x ∈ FvarsT ?s then FvarsT ?t else {})›*))[1]) (*discuss goal 12*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: FvarsT_substT (*‹⟦?s ∈ atrm; ?t ∈ trm; ?x ∈ var⟧ ⟹ FvarsT (substT ?s ?t ?x) = FvarsT ?s - {?x} ∪ (if ?x ∈ FvarsT ?s then FvarsT ?t else {})›*))[1]) (*discuss goal 13*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: FvarsT_substT (*‹⟦?s ∈ atrm; ?t ∈ trm; ?x ∈ var⟧ ⟹ FvarsT (substT ?s ?t ?x) = FvarsT ?s - {?x} ∪ (if ?x ∈ FvarsT ?s then FvarsT ?t else {})›*))[1]) (*discuss goal 14*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: FvarsT_substT (*‹⟦?s ∈ atrm; ?t ∈ trm; ?x ∈ var⟧ ⟹ FvarsT (substT ?s ?t ?x) = FvarsT ?s - {?x} ∪ (if ?x ∈ FvarsT ?s then FvarsT ?t else {})›*))[1]) (*discuss goal 15*) apply ((auto intro!: rawpsubstT (*‹⟦(?t::'trm::type) ∈ (trm::'trm::type set); snd ` set (?txs::('trm::type × 'var::type) list) ⊆ (var::'var::type set); fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x::?'a::type, ?y::?'b::type) ∈ set (zip (?xs::?'a::type list) (?ys::?'b::type list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: FvarsT_substT (*‹⟦(?s::'trm::type) ∈ atrm; (?t::'trm::type) ∈ (trm::'trm::type set); (?x::'var::type) ∈ (var::'var::type set)⟧ ⟹ (FvarsT::'trm::type ⇒ 'var::type set) ((substT::'trm::type ⇒ 'trm::type ⇒ 'var::type ⇒ 'trm::type) ?s ?t ?x) = FvarsT ?s - {?x} ∪ (if ?x ∈ FvarsT ?s then FvarsT ?t else {})›*))[1]) (*discuss goal 16*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: FvarsT_substT (*‹⟦?s ∈ atrm; ?t ∈ trm; ?x ∈ var⟧ ⟹ FvarsT (substT ?s ?t ?x) = FvarsT ?s - {?x} ∪ (if ?x ∈ FvarsT ?s then FvarsT ?t else {})›*))[1]) (*discuss goal 17*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: FvarsT_substT (*‹⟦?s ∈ atrm; ?t ∈ trm; ?x ∈ var⟧ ⟹ FvarsT (substT ?s ?t ?x) = FvarsT ?s - {?x} ∪ (if ?x ∈ FvarsT ?s then FvarsT ?t else {})›*))[1]) (*discuss goal 18*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: FvarsT_substT (*‹⟦?s ∈ atrm; ?t ∈ trm; ?x ∈ var⟧ ⟹ FvarsT (substT ?s ?t ?x) = FvarsT ?s - {?x} ∪ (if ?x ∈ FvarsT ?s then FvarsT ?t else {})›*))[1]) (*proven 18 subgoals*) . have 1: "rawpsubstT ?rux (zip (map Var vs) xs) = substT (rawpsubstT r (zip (map Var vs) xs)) (Var u) x" using Cons.prems (*‹r ∈ atrm› ‹set tts ⊆ atrm› ‹set (x # xs) ⊆ var› ‹distinct (x # xs)› ‹set uus ⊆ var› ‹distinct uus› ‹set uus ∩ FvarsT r = {}› ‹set uus ∩ ⋃ (FvarsT ` set tts) = {}› ‹set (uus::'var::type list) ∩ set ((x::'var::type) # (xs::'var::type list)) = {}› ‹set vvs ⊆ var› ‹distinct vvs› ‹set vvs ∩ FvarsT r = {}› and more 6 facts*) apply (intro substT_rawpsubstT_fresh_switch[simplified,symmetric] (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; ∀x∈set ?txs. snd x ∉ FvarsT ?s; ∀t∈set ?txs. ?y ∉ FvarsT (fst t); distinct (map snd ?txs); ?s ∈ atrm; ?y ∈ var; ?y ∉ snd ` set ?txs⟧ ⟹ rawpsubstT (substT ?r ?s ?y) ?txs = substT (rawpsubstT ?r ?txs) ?s ?y›*)) (*goals: 1. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ r ∈ atrm› 2. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ snd ` set (zip (map Var vs) xs) ⊆ var› 3. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ fst ` set (zip (map Var vs) xs) ⊆ atrm› 4. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ ∀x∈set (zip (map Var vs) xs). snd x ∉ FvarsT (Var u)› 5. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ ∀t∈set (zip (map Var vs) xs). x ∉ FvarsT (fst t)› 6. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ distinct (map snd (zip (map Var vs) xs))› 7. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ Var u ∈ atrm› 8. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ x ∈ var› 9. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ x ∉ snd ` set (zip (map Var vs) xs)› discuss goal 1*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*))[1]) (*discuss goal 2*) apply ((auto intro!: rawpsubstT (*‹⟦(?t::'trm) ∈ (trm::'trm set); snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: subset_eq (*‹((?A::?'a set) ⊆ (?B::?'a set)) = (∀x::?'a∈?A. x ∈ ?B)›*))[1]) (*discuss goal 3*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*))[1]) (*discuss goal 4*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*))[1]) (*discuss goal 5*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*))[1]) (*discuss goal 6*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*))[1]) (*discuss goal 7*) apply ((auto intro!: rawpsubstT (*‹⟦(?t::'trm) ∈ (trm::'trm set); snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: subset_eq (*‹((?A::?'a set) ⊆ (?B::?'a set)) = (∀x::?'a∈?A. x ∈ ?B)›*))[1]) (*discuss goal 8*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*))[1]) (*discuss goal 9*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*))[1]) (*proven 9 subgoals*) . have 11: "rawpsubstT ?rvx (zip (map Var vs) xs) = substT (rawpsubstT r (zip (map Var vs) xs)) (Var v) x" using Cons.prems (*‹(r::'trm) ∈ atrm› ‹set tts ⊆ atrm› ‹set (x # xs) ⊆ var› ‹distinct ((x::'var::type) # (xs::'var::type list))› ‹set uus ⊆ var› ‹distinct uus› ‹set uus ∩ FvarsT r = {}› ‹set uus ∩ ⋃ (FvarsT ` set tts) = {}› ‹set uus ∩ set (x # xs) = {}› ‹set vvs ⊆ var› ‹distinct vvs› ‹set vvs ∩ FvarsT r = {}› and more 6 facts*) apply (intro substT_rawpsubstT_fresh_switch[simplified,symmetric] (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; ∀x∈set ?txs. snd x ∉ FvarsT ?s; ∀t∈set ?txs. ?y ∉ FvarsT (fst t); distinct (map snd ?txs); ?s ∈ atrm; ?y ∈ var; ?y ∉ snd ` set ?txs⟧ ⟹ rawpsubstT (substT ?r ?s ?y) ?txs = substT (rawpsubstT ?r ?txs) ?s ?y›*)) (*goals: 1. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ r ∈ atrm› 2. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ snd ` set (zip (map Var vs) xs) ⊆ var› 3. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ fst ` set (zip (map Var vs) xs) ⊆ atrm› 4. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ ∀x∈set (zip (map Var vs) xs). snd x ∉ FvarsT (Var v)› 5. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ ∀t∈set (zip (map Var vs) xs). x ∉ FvarsT (fst t)› 6. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ distinct (map snd (zip (map Var vs) xs))› 7. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ Var v ∈ atrm› 8. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ x ∈ var› 9. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ x ∉ snd ` set (zip (map Var vs) xs)› discuss goal 1*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*))[1]) (*discuss goal 2*) apply ((auto intro!: rawpsubstT (*‹⟦(?t::'trm) ∈ (trm::'trm set); snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: subset_eq (*‹((?A::?'a set) ⊆ (?B::?'a set)) = (∀x::?'a∈?A. x ∈ ?B)›*))[1]) (*discuss goal 3*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*))[1]) (*discuss goal 4*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*))[1]) (*discuss goal 5*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*))[1]) (*discuss goal 6*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*))[1]) (*discuss goal 7*) apply ((auto intro!: rawpsubstT (*‹⟦(?t::'trm) ∈ (trm::'trm set); snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: subset_eq (*‹((?A::?'a set) ⊆ (?B::?'a set)) = (∀x::?'a∈?A. x ∈ ?B)›*))[1]) (*discuss goal 8*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*))[1]) (*discuss goal 9*) apply ((auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*))[1]) (*proven 9 subgoals*) . have "substT (substT (rawpsubstT r (zip (map Var vs) xs)) (Var u) x) t u = substT (rawpsubstT r (zip (map Var vs) xs)) t x" using Cons.prems (*‹r ∈ atrm› ‹set tts ⊆ atrm› ‹set (x # xs) ⊆ var› ‹distinct ((x::'var::type) # (xs::'var::type list))› ‹set (uus::'var list) ⊆ (var::'var set)› ‹distinct uus› ‹set uus ∩ FvarsT r = {}› ‹set uus ∩ ⋃ (FvarsT ` set tts) = {}› ‹set uus ∩ set (x # xs) = {}› ‹set vvs ⊆ var› ‹distinct (vvs::'var list)› ‹set (vvs::'var list) ∩ (FvarsT::'trm ⇒ 'var set) (r::'trm) = {}› and more 6 facts*) apply (intro substT_substT (*‹⟦?s ∈ atrm; ?t ∈ trm; ?x ∈ var; ?y ∈ var; ?x ≠ ?y; ?y ∉ FvarsT ?s⟧ ⟹ substT (substT ?s (Var ?y) ?x) ?t ?y = substT ?s ?t ?x›*)) (*goals: 1. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ rawpsubstT r (zip (map Var vs) xs) ∈ atrm› 2. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ t ∈ trm› 3. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ x ∈ var› 4. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ u ∈ var› 5. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ x ≠ u› 6. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ u ∉ FvarsT (rawpsubstT r (zip (map Var vs) xs))› discuss goal 1*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of r] (*‹⟦r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT r ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) in_FvarsT_rawpsubstT_imp (*‹⟦?y ∈ FvarsT (rawpsubstT ?r ?txs); ?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ ?y ∈ FvarsT ?r - snd ` set ?txs ∨ ?y ∈ ⋃ {uu_. ∃t x. uu_ = FvarsT t ∧ (t, x) ∈ set ?txs}›*) FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*) simp: FvarsT_rawpsubstT (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; distinct (map snd ?txs); ∀x∈snd ` set ?txs. ∀t∈fst ` set ?txs. x ∉ FvarsT t⟧ ⟹ FvarsT (rawpsubstT ?r ?txs) = FvarsT ?r - snd ` set ?txs ∪ ⋃ {if x ∈ FvarsT ?r then FvarsT t else {} |t x. (t, x) ∈ set ?txs}›*))[1]) (*discuss goal 2*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of r] (*‹⟦r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT r ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) in_FvarsT_rawpsubstT_imp (*‹⟦?y ∈ FvarsT (rawpsubstT ?r ?txs); ?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ ?y ∈ FvarsT ?r - snd ` set ?txs ∨ ?y ∈ ⋃ {uu_. ∃t x. uu_ = FvarsT t ∧ (t, x) ∈ set ?txs}›*) FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*) simp: FvarsT_rawpsubstT (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; distinct (map snd ?txs); ∀x∈snd ` set ?txs. ∀t∈fst ` set ?txs. x ∉ FvarsT t⟧ ⟹ FvarsT (rawpsubstT ?r ?txs) = FvarsT ?r - snd ` set ?txs ∪ ⋃ {if x ∈ FvarsT ?r then FvarsT t else {} |t x. (t, x) ∈ set ?txs}›*))[1]) (*discuss goal 3*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of r] (*‹⟦r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT r ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) in_FvarsT_rawpsubstT_imp (*‹⟦?y ∈ FvarsT (rawpsubstT ?r ?txs); ?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ ?y ∈ FvarsT ?r - snd ` set ?txs ∨ ?y ∈ ⋃ {uu_. ∃t x. uu_ = FvarsT t ∧ (t, x) ∈ set ?txs}›*) FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*) simp: FvarsT_rawpsubstT (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; distinct (map snd ?txs); ∀x∈snd ` set ?txs. ∀t∈fst ` set ?txs. x ∉ FvarsT t⟧ ⟹ FvarsT (rawpsubstT ?r ?txs) = FvarsT ?r - snd ` set ?txs ∪ ⋃ {if x ∈ FvarsT ?r then FvarsT t else {} |t x. (t, x) ∈ set ?txs}›*))[1]) (*discuss goal 4*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of r] (*‹⟦r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT r ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) in_FvarsT_rawpsubstT_imp (*‹⟦?y ∈ FvarsT (rawpsubstT ?r ?txs); ?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ ?y ∈ FvarsT ?r - snd ` set ?txs ∨ ?y ∈ ⋃ {uu_. ∃t x. uu_ = FvarsT t ∧ (t, x) ∈ set ?txs}›*) FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*) simp: FvarsT_rawpsubstT (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; distinct (map snd ?txs); ∀x∈snd ` set ?txs. ∀t∈fst ` set ?txs. x ∉ FvarsT t⟧ ⟹ FvarsT (rawpsubstT ?r ?txs) = FvarsT ?r - snd ` set ?txs ∪ ⋃ {if x ∈ FvarsT ?r then FvarsT t else {} |t x. (t, x) ∈ set ?txs}›*))[1]) (*discuss goal 5*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of r] (*‹⟦r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT r ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) in_FvarsT_rawpsubstT_imp (*‹⟦?y ∈ FvarsT (rawpsubstT ?r ?txs); ?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ ?y ∈ FvarsT ?r - snd ` set ?txs ∨ ?y ∈ ⋃ {uu_. ∃t x. uu_ = FvarsT t ∧ (t, x) ∈ set ?txs}›*) FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*) simp: FvarsT_rawpsubstT (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; distinct (map snd ?txs); ∀x∈snd ` set ?txs. ∀t∈fst ` set ?txs. x ∉ FvarsT t⟧ ⟹ FvarsT (rawpsubstT ?r ?txs) = FvarsT ?r - snd ` set ?txs ∪ ⋃ {if x ∈ FvarsT ?r then FvarsT t else {} |t x. (t, x) ∈ set ?txs}›*))[1]) (*discuss goal 6*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of r] (*‹⟦(r::'trm) ∈ atrm; snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT r ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) in_FvarsT_rawpsubstT_imp (*‹⟦(?y::'var) ∈ (FvarsT::'trm ⇒ 'var set) (rawpsubstT (?r::'trm) (?txs::('trm × 'var) list)); ?r ∈ atrm; snd ` set ?txs ⊆ (var::'var set); fst ` set ?txs ⊆ atrm⟧ ⟹ ?y ∈ FvarsT ?r - snd ` set ?txs ∨ ?y ∈ ⋃ {uu_::'var set. ∃(t::'trm) x::'var. uu_ = FvarsT t ∧ (t, x) ∈ set ?txs}›*) FvarsT_VarD (*‹⟦(?x::'var) ∈ (FvarsT::'trm ⇒ 'var set) ((Var::'var ⇒ 'trm) (?y::'var)); ?y ∈ (var::'var set)⟧ ⟹ ?x = ?y›*) simp: FvarsT_rawpsubstT (*‹⟦(?r::'trm) ∈ atrm; snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ atrm; distinct (map snd ?txs); ∀x::'var∈snd ` set ?txs. ∀t::'trm∈fst ` set ?txs. x ∉ (FvarsT::'trm ⇒ 'var set) t⟧ ⟹ FvarsT (rawpsubstT ?r ?txs) = FvarsT ?r - snd ` set ?txs ∪ ⋃ {if x ∈ FvarsT ?r then FvarsT t else {} |(t::'trm) x::'var. (t, x) ∈ set ?txs}›*))[1]) (*proven 6 subgoals*) . also (*calculation: ‹substT (substT (rawpsubstT r (zip (map Var vs) xs)) (Var u) x) t u = substT (rawpsubstT r (zip (map Var vs) xs)) t x›*) have "… = substT (substT (rawpsubstT r (zip (map Var vs) xs)) (Var v) x) t v" using Cons.prems (*‹(r::'trm) ∈ atrm› ‹set tts ⊆ atrm› ‹set (x # xs) ⊆ var› ‹distinct (x # xs)› ‹set uus ⊆ var› ‹distinct (uus::'var list)› ‹set (uus::'var::type list) ∩ (FvarsT::'trm::type ⇒ 'var::type set) (r::'trm::type) = {}› ‹set uus ∩ ⋃ (FvarsT ` set tts) = {}› ‹set uus ∩ set (x # xs) = {}› ‹set vvs ⊆ var› ‹distinct vvs› ‹set vvs ∩ FvarsT r = {}› and more 6 facts*) apply (intro substT_substT[symmetric] (*‹⟦?s ∈ atrm; ?t ∈ trm; ?x ∈ var; ?y ∈ var; ?x ≠ ?y; ?y ∉ FvarsT ?s⟧ ⟹ substT ?s ?t ?x = substT (substT ?s (Var ?y) ?x) ?t ?y›*)) (*goals: 1. ‹⟦(r::'trm) ∈ atrm; set (tts::'trm list) ⊆ atrm; set ((x::'var) # (xs::'var list)) ⊆ (var::'var set); distinct (x # xs); set (uus::'var list) ⊆ var; distinct uus; set uus ∩ (FvarsT::'trm ⇒ 'var set) r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set (vvs::'var list) ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ rawpsubstT r (zip (map (Var::'var ⇒ 'trm) (vs::'var list)) xs) ∈ atrm› 2. ‹⟦(r::'trm) ∈ atrm; set (tts::'trm list) ⊆ atrm; set ((x::'var) # (xs::'var list)) ⊆ (var::'var set); distinct (x # xs); set (uus::'var list) ⊆ var; distinct uus; set uus ∩ (FvarsT::'trm ⇒ 'var set) r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set (vvs::'var list) ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ (t::'trm) ∈ (trm::'trm set)› 3. ‹⟦(r::'trm) ∈ atrm; set (tts::'trm list) ⊆ atrm; set ((x::'var) # (xs::'var list)) ⊆ (var::'var set); distinct (x # xs); set (uus::'var list) ⊆ var; distinct uus; set uus ∩ (FvarsT::'trm ⇒ 'var set) r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set (vvs::'var list) ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ x ∈ var› 4. ‹⟦(r::'trm) ∈ atrm; set (tts::'trm list) ⊆ atrm; set ((x::'var) # (xs::'var list)) ⊆ (var::'var set); distinct (x # xs); set (uus::'var list) ⊆ var; distinct uus; set uus ∩ (FvarsT::'trm ⇒ 'var set) r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set (vvs::'var list) ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ (v::'var) ∈ var› 5. ‹⟦(r::'trm) ∈ atrm; set (tts::'trm list) ⊆ atrm; set ((x::'var) # (xs::'var list)) ⊆ (var::'var set); distinct (x # xs); set (uus::'var list) ⊆ var; distinct uus; set uus ∩ (FvarsT::'trm ⇒ 'var set) r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set (vvs::'var list) ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ x ≠ (v::'var)› 6. ‹⟦(r::'trm) ∈ atrm; set (tts::'trm list) ⊆ atrm; set ((x::'var) # (xs::'var list)) ⊆ (var::'var set); distinct (x # xs); set (uus::'var list) ⊆ var; distinct uus; set uus ∩ (FvarsT::'trm ⇒ 'var set) r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set (vvs::'var list) ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ (v::'var) ∉ FvarsT (rawpsubstT r (zip (map (Var::'var ⇒ 'trm) (vs::'var list)) xs))› discuss goal 1*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of r] (*‹⟦r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT r ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) in_FvarsT_rawpsubstT_imp (*‹⟦?y ∈ FvarsT (rawpsubstT ?r ?txs); ?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ ?y ∈ FvarsT ?r - snd ` set ?txs ∨ ?y ∈ ⋃ {uu_. ∃t x. uu_ = FvarsT t ∧ (t, x) ∈ set ?txs}›*) FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*) simp: FvarsT_rawpsubstT (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; distinct (map snd ?txs); ∀x∈snd ` set ?txs. ∀t∈fst ` set ?txs. x ∉ FvarsT t⟧ ⟹ FvarsT (rawpsubstT ?r ?txs) = FvarsT ?r - snd ` set ?txs ∪ ⋃ {if x ∈ FvarsT ?r then FvarsT t else {} |t x. (t, x) ∈ set ?txs}›*))[1]) (*discuss goal 2*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of r] (*‹⟦r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT r ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) in_FvarsT_rawpsubstT_imp (*‹⟦?y ∈ FvarsT (rawpsubstT ?r ?txs); ?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ ?y ∈ FvarsT ?r - snd ` set ?txs ∨ ?y ∈ ⋃ {uu_. ∃t x. uu_ = FvarsT t ∧ (t, x) ∈ set ?txs}›*) FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*) simp: FvarsT_rawpsubstT (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; distinct (map snd ?txs); ∀x∈snd ` set ?txs. ∀t∈fst ` set ?txs. x ∉ FvarsT t⟧ ⟹ FvarsT (rawpsubstT ?r ?txs) = FvarsT ?r - snd ` set ?txs ∪ ⋃ {if x ∈ FvarsT ?r then FvarsT t else {} |t x. (t, x) ∈ set ?txs}›*))[1]) (*discuss goal 3*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of r] (*‹⟦r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT r ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) in_FvarsT_rawpsubstT_imp (*‹⟦?y ∈ FvarsT (rawpsubstT ?r ?txs); ?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ ?y ∈ FvarsT ?r - snd ` set ?txs ∨ ?y ∈ ⋃ {uu_. ∃t x. uu_ = FvarsT t ∧ (t, x) ∈ set ?txs}›*) FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*) simp: FvarsT_rawpsubstT (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; distinct (map snd ?txs); ∀x∈snd ` set ?txs. ∀t∈fst ` set ?txs. x ∉ FvarsT t⟧ ⟹ FvarsT (rawpsubstT ?r ?txs) = FvarsT ?r - snd ` set ?txs ∪ ⋃ {if x ∈ FvarsT ?r then FvarsT t else {} |t x. (t, x) ∈ set ?txs}›*))[1]) (*discuss goal 4*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of r] (*‹⟦r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT r ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) in_FvarsT_rawpsubstT_imp (*‹⟦?y ∈ FvarsT (rawpsubstT ?r ?txs); ?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ ?y ∈ FvarsT ?r - snd ` set ?txs ∨ ?y ∈ ⋃ {uu_. ∃t x. uu_ = FvarsT t ∧ (t, x) ∈ set ?txs}›*) FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*) simp: FvarsT_rawpsubstT (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; distinct (map snd ?txs); ∀x∈snd ` set ?txs. ∀t∈fst ` set ?txs. x ∉ FvarsT t⟧ ⟹ FvarsT (rawpsubstT ?r ?txs) = FvarsT ?r - snd ` set ?txs ∪ ⋃ {if x ∈ FvarsT ?r then FvarsT t else {} |t x. (t, x) ∈ set ?txs}›*))[1]) (*discuss goal 5*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of r] (*‹⟦r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT r ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) in_FvarsT_rawpsubstT_imp (*‹⟦?y ∈ FvarsT (rawpsubstT ?r ?txs); ?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ ?y ∈ FvarsT ?r - snd ` set ?txs ∨ ?y ∈ ⋃ {uu_. ∃t x. uu_ = FvarsT t ∧ (t, x) ∈ set ?txs}›*) FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*) simp: FvarsT_rawpsubstT (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; distinct (map snd ?txs); ∀x∈snd ` set ?txs. ∀t∈fst ` set ?txs. x ∉ FvarsT t⟧ ⟹ FvarsT (rawpsubstT ?r ?txs) = FvarsT ?r - snd ` set ?txs ∪ ⋃ {if x ∈ FvarsT ?r then FvarsT t else {} |t x. (t, x) ∈ set ?txs}›*))[1]) (*discuss goal 6*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of r] (*‹⟦r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT r ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) in_FvarsT_rawpsubstT_imp (*‹⟦?y ∈ FvarsT (rawpsubstT ?r ?txs); ?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ ?y ∈ FvarsT ?r - snd ` set ?txs ∨ ?y ∈ ⋃ {uu_. ∃t x. uu_ = FvarsT t ∧ (t, x) ∈ set ?txs}›*) FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*) simp: FvarsT_rawpsubstT (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; distinct (map snd ?txs); ∀x∈snd ` set ?txs. ∀t∈fst ` set ?txs. x ∉ FvarsT t⟧ ⟹ FvarsT (rawpsubstT ?r ?txs) = FvarsT ?r - snd ` set ?txs ∪ ⋃ {if x ∈ FvarsT ?r then FvarsT t else {} |t x. (t, x) ∈ set ?txs}›*))[1]) (*proven 6 subgoals*) . finally (*calculation: ‹substT (substT (rawpsubstT r (zip (map Var vs) xs)) (Var u) x) t u = substT (substT (rawpsubstT r (zip (map Var vs) xs)) (Var v) x) t v›*) have 2: "substT (substT (rawpsubstT r (zip (map Var vs) xs)) (Var u) x) t u = substT (substT (rawpsubstT r (zip (map Var vs) xs)) (Var v) x) t v" . have "rawpsubstT (substT (rawpsubstT ?rux (zip (map Var us) xs)) t u) (zip ts us) = substT (rawpsubstT (rawpsubstT ?rux (zip (map Var us) xs)) (zip ts us)) t u" using Cons.prems (*‹r ∈ atrm› ‹set tts ⊆ atrm› ‹set ((x::'var::type) # (xs::'var::type list)) ⊆ (var::'var::type set)› ‹distinct (x # xs)› ‹set uus ⊆ var› ‹distinct uus› ‹set uus ∩ FvarsT r = {}› ‹set uus ∩ ⋃ (FvarsT ` set tts) = {}› ‹set uus ∩ set (x # xs) = {}› ‹set vvs ⊆ var› ‹distinct vvs› ‹set vvs ∩ FvarsT r = {}› and more 6 facts*) apply (intro substT_rawpsubstT_fresh_switch[simplified,symmetric] (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; ∀x∈set ?txs. snd x ∉ FvarsT ?s; ∀t∈set ?txs. ?y ∉ FvarsT (fst t); distinct (map snd ?txs); ?s ∈ atrm; ?y ∈ var; ?y ∉ snd ` set ?txs⟧ ⟹ rawpsubstT (substT ?r ?s ?y) ?txs = substT (rawpsubstT ?r ?txs) ?s ?y›*)) (*goals: 1. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ rawpsubstT (substT r (Var u) x) (zip (map Var us) xs) ∈ atrm› 2. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ snd ` set (zip ts us) ⊆ var› 3. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ fst ` set (zip ts us) ⊆ atrm› 4. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ ∀x∈set (zip ts us). snd x ∉ FvarsT t› 5. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ ∀t∈set (zip ts us). u ∉ FvarsT (fst t)› 6. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ distinct (map snd (zip ts us))› 7. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ t ∈ atrm› 8. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ u ∈ var› 9. ‹⟦r ∈ atrm; set tts ⊆ atrm; set (x # xs) ⊆ var; distinct (x # xs); set uus ⊆ var; distinct uus; set uus ∩ FvarsT r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set vvs ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ u ∉ snd ` set (zip ts us)› discuss goal 1*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of ?rux] (*‹⟦(substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) (r::'trm) ((Var::'var ⇒ 'trm) (u::'var)) (x::'var) ∈ atrm; snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT (substT r (Var u) x) ?txs ∈ atrm›*) substT_atrm (*‹⟦(?r::'trm) ∈ atrm; (?x::'var) ∈ (var::'var set); (?t::'trm) ∈ atrm⟧ ⟹ (substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) ?r ?t ?x ∈ atrm›*) dest!: set_zip_D (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 2*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of ?rux] (*‹⟦substT r (Var u) x ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT (substT r (Var u) x) ?txs ∈ atrm›*) substT_atrm (*‹⟦?r ∈ atrm; ?x ∈ var; ?t ∈ atrm⟧ ⟹ substT ?r ?t ?x ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 3*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of ?rux] (*‹⟦substT r (Var u) x ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT (substT r (Var u) x) ?txs ∈ atrm›*) substT_atrm (*‹⟦?r ∈ atrm; ?x ∈ var; ?t ∈ atrm⟧ ⟹ substT ?r ?t ?x ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 4*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of ?rux] (*‹⟦substT r (Var u) x ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT (substT r (Var u) x) ?txs ∈ atrm›*) substT_atrm (*‹⟦?r ∈ atrm; ?x ∈ var; ?t ∈ atrm⟧ ⟹ substT ?r ?t ?x ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 5*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of ?rux] (*‹⟦(substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) (r::'trm) ((Var::'var ⇒ 'trm) (u::'var)) (x::'var) ∈ atrm; snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT (substT r (Var u) x) ?txs ∈ atrm›*) substT_atrm (*‹⟦(?r::'trm) ∈ atrm; (?x::'var) ∈ (var::'var set); (?t::'trm) ∈ atrm⟧ ⟹ (substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) ?r ?t ?x ∈ atrm›*) dest!: set_zip_D (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 6*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of ?rux] (*‹⟦(substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) (r::'trm) ((Var::'var ⇒ 'trm) (u::'var)) (x::'var) ∈ atrm; snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT (substT r (Var u) x) ?txs ∈ atrm›*) substT_atrm (*‹⟦(?r::'trm) ∈ atrm; (?x::'var) ∈ (var::'var set); (?t::'trm) ∈ atrm⟧ ⟹ (substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) ?r ?t ?x ∈ atrm›*) dest!: set_zip_D (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 7*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of ?rux] (*‹⟦substT r (Var u) x ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT (substT r (Var u) x) ?txs ∈ atrm›*) substT_atrm (*‹⟦?r ∈ atrm; ?x ∈ var; ?t ∈ atrm⟧ ⟹ substT ?r ?t ?x ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 8*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of ?rux] (*‹⟦(substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) (r::'trm) ((Var::'var ⇒ 'trm) (u::'var)) (x::'var) ∈ atrm; snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT (substT r (Var u) x) ?txs ∈ atrm›*) substT_atrm (*‹⟦(?r::'trm) ∈ atrm; (?x::'var) ∈ (var::'var set); (?t::'trm) ∈ atrm⟧ ⟹ (substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) ?r ?t ?x ∈ atrm›*) dest!: set_zip_D (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 9*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of ?rux] (*‹⟦substT r (Var u) x ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT (substT r (Var u) x) ?txs ∈ atrm›*) substT_atrm (*‹⟦?r ∈ atrm; ?x ∈ var; ?t ∈ atrm⟧ ⟹ substT ?r ?t ?x ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*proven 9 subgoals*) . also (*calculation: ‹rawpsubstT (substT (rawpsubstT (substT r (Var u) x) (zip (map Var us) xs)) t u) (zip ts us) = substT (rawpsubstT (rawpsubstT (substT r (Var u) x) (zip (map Var us) xs)) (zip ts us)) t u›*) have "… = substT (rawpsubstT (rawpsubstT ?rux (zip (map Var vs) xs)) (zip ts vs)) t u" unfolding "0" (*goal: ‹substT (rawpsubstT (rawpsubstT (substT r (Var u) x) (zip (map Var vs) xs)) (zip ts vs)) t u = substT (rawpsubstT (rawpsubstT (substT r (Var u) x) (zip (map Var vs) xs)) (zip ts vs)) t u›*) by standard also (*calculation: ‹rawpsubstT (substT (rawpsubstT (substT r (Var u) x) (zip (map Var us) xs)) t u) (zip ts us) = substT (rawpsubstT (rawpsubstT (substT r (Var u) x) (zip (map Var vs) xs)) (zip ts vs)) t u›*) have "… = rawpsubstT (substT (rawpsubstT ?rux (zip (map Var vs) xs)) t u) (zip ts vs)" using Cons.prems (*‹r ∈ atrm› ‹set tts ⊆ atrm› ‹set ((x::'var) # (xs::'var list)) ⊆ (var::'var set)› ‹distinct (x # xs)› ‹set uus ⊆ var› ‹distinct uus› ‹set (uus::'var::type list) ∩ (FvarsT::'trm::type ⇒ 'var::type set) (r::'trm::type) = {}› ‹set uus ∩ ⋃ (FvarsT ` set tts) = {}› ‹set uus ∩ set (x # xs) = {}› ‹set vvs ⊆ var› ‹distinct (vvs::'var::type list)› ‹set vvs ∩ FvarsT r = {}› and more 6 facts*) apply (intro substT_rawpsubstT_fresh_switch[simplified] (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; ∀x∈set ?txs. snd x ∉ FvarsT ?s; ∀t∈set ?txs. ?y ∉ FvarsT (fst t); distinct (map snd ?txs); ?s ∈ atrm; ?y ∈ var; ?y ∉ snd ` set ?txs⟧ ⟹ substT (rawpsubstT ?r ?txs) ?s ?y = rawpsubstT (substT ?r ?s ?y) ?txs›*)) (*goals: 1. ‹⟦(r::'trm) ∈ atrm; set (tts::'trm list) ⊆ atrm; set ((x::'var) # (xs::'var list)) ⊆ (var::'var set); distinct (x # xs); set (uus::'var list) ⊆ var; distinct uus; set uus ∩ (FvarsT::'trm ⇒ 'var set) r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set (vvs::'var list) ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ rawpsubstT ((substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) r ((Var::'var ⇒ 'trm) (u::'var)) x) (zip (map Var (vs::'var list)) xs) ∈ atrm› 2. ‹⟦(r::'trm) ∈ atrm; set (tts::'trm list) ⊆ atrm; set ((x::'var) # (xs::'var list)) ⊆ (var::'var set); distinct (x # xs); set (uus::'var list) ⊆ var; distinct uus; set uus ∩ (FvarsT::'trm ⇒ 'var set) r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set (vvs::'var list) ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ snd ` set (zip (ts::'trm list) (vs::'var list)) ⊆ var› 3. ‹⟦(r::'trm) ∈ atrm; set (tts::'trm list) ⊆ atrm; set ((x::'var) # (xs::'var list)) ⊆ (var::'var set); distinct (x # xs); set (uus::'var list) ⊆ var; distinct uus; set uus ∩ (FvarsT::'trm ⇒ 'var set) r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set (vvs::'var list) ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ fst ` set (zip (ts::'trm list) (vs::'var list)) ⊆ atrm› 4. ‹⟦(r::'trm) ∈ atrm; set (tts::'trm list) ⊆ atrm; set ((x::'var) # (xs::'var list)) ⊆ (var::'var set); distinct (x # xs); set (uus::'var list) ⊆ var; distinct uus; set uus ∩ (FvarsT::'trm ⇒ 'var set) r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set (vvs::'var list) ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ ∀x::'trm × 'var∈set (zip (ts::'trm list) (vs::'var list)). snd x ∉ FvarsT (t::'trm)› 5. ‹⟦(r::'trm) ∈ atrm; set (tts::'trm list) ⊆ atrm; set ((x::'var) # (xs::'var list)) ⊆ (var::'var set); distinct (x # xs); set (uus::'var list) ⊆ var; distinct uus; set uus ∩ (FvarsT::'trm ⇒ 'var set) r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set (vvs::'var list) ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ ∀t::'trm × 'var∈set (zip (ts::'trm list) (vs::'var list)). (u::'var) ∉ FvarsT (fst t)› 6. ‹⟦(r::'trm) ∈ atrm; set (tts::'trm list) ⊆ atrm; set ((x::'var) # (xs::'var list)) ⊆ (var::'var set); distinct (x # xs); set (uus::'var list) ⊆ var; distinct uus; set uus ∩ (FvarsT::'trm ⇒ 'var set) r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set (vvs::'var list) ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ distinct (map snd (zip (ts::'trm list) (vs::'var list)))› 7. ‹⟦(r::'trm) ∈ atrm; set (tts::'trm list) ⊆ atrm; set ((x::'var) # (xs::'var list)) ⊆ (var::'var set); distinct (x # xs); set (uus::'var list) ⊆ var; distinct uus; set uus ∩ (FvarsT::'trm ⇒ 'var set) r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set (vvs::'var list) ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ (t::'trm) ∈ atrm› 8. ‹⟦(r::'trm) ∈ atrm; set (tts::'trm list) ⊆ atrm; set ((x::'var) # (xs::'var list)) ⊆ (var::'var set); distinct (x # xs); set (uus::'var list) ⊆ var; distinct uus; set uus ∩ (FvarsT::'trm ⇒ 'var set) r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set (vvs::'var list) ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ (u::'var) ∈ var› 9. ‹⟦(r::'trm) ∈ atrm; set (tts::'trm list) ⊆ atrm; set ((x::'var) # (xs::'var list)) ⊆ (var::'var set); distinct (x # xs); set (uus::'var list) ⊆ var; distinct uus; set uus ∩ (FvarsT::'trm ⇒ 'var set) r = {}; set uus ∩ ⋃ (FvarsT ` set tts) = {}; set uus ∩ set (x # xs) = {}; set (vvs::'var list) ⊆ var; distinct vvs; set vvs ∩ FvarsT r = {}; set vvs ∩ ⋃ (FvarsT ` set tts) = {}; set vvs ∩ set (x # xs) = {}; length uus = length (x # xs); length vvs = length (x # xs); length tts = length (x # xs); set uus ∩ set vvs = {}⟧ ⟹ (u::'var) ∉ snd ` set (zip (ts::'trm list) (vs::'var list))› discuss goal 1*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of ?rux] (*‹⟦substT r (Var u) x ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT (substT r (Var u) x) ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 2*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of ?rux] (*‹⟦substT r (Var u) x ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT (substT r (Var u) x) ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 3*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of ?rux] (*‹⟦substT r (Var u) x ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT (substT r (Var u) x) ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 4*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of ?rux] (*‹⟦(substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) (r::'trm) ((Var::'var ⇒ 'trm) (u::'var)) (x::'var) ∈ atrm; snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT (substT r (Var u) x) ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 5*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of ?rux] (*‹⟦(substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) (r::'trm) ((Var::'var ⇒ 'trm) (u::'var)) (x::'var) ∈ atrm; snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT (substT r (Var u) x) ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 6*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of ?rux] (*‹⟦(substT::'trm::type ⇒ 'trm::type ⇒ 'var::type ⇒ 'trm::type) (r::'trm::type) ((Var::'var::type ⇒ 'trm::type) (u::'var::type)) (x::'var::type) ∈ atrm; snd ` set (?txs::('trm::type × 'var::type) list) ⊆ (var::'var::type set); fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT (substT r (Var u) x) ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x::?'a::type, ?y::?'b::type) ∈ set (zip (?xs::?'a::type list) (?ys::?'b::type list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 7*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of ?rux] (*‹⟦substT r (Var u) x ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT (substT r (Var u) x) ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 8*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of ?rux] (*‹⟦substT r (Var u) x ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT (substT r (Var u) x) ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 9*) apply ((auto 0 3 intro!: rawpsubstT_atrm[of ?rux] (*‹⟦substT r (Var u) x ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ rawpsubstT (substT r (Var u) x) ?txs ∈ atrm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*proven 9 subgoals*) . also (*calculation: ‹rawpsubstT (substT (rawpsubstT (substT r (Var u) x) (zip (map Var us) xs)) t u) (zip ts us) = rawpsubstT (substT (rawpsubstT (substT r (Var u) x) (zip (map Var vs) xs)) t u) (zip ts vs)›*) have "… = rawpsubstT (substT (substT (rawpsubstT r (zip (map Var vs) xs)) (Var u) x) t u) (zip ts vs)" unfolding "1" (*goal: ‹rawpsubstT ((substT::'trm::type ⇒ 'trm::type ⇒ 'var::type ⇒ 'trm::type) (substT (rawpsubstT (r::'trm::type) (zip (map (Var::'var::type ⇒ 'trm::type) (vs::'var::type list)) (xs::'var::type list))) (Var (u::'var::type)) (x::'var::type)) (t::'trm::type) u) (zip (ts::'trm::type list) vs) = rawpsubstT (substT (substT (rawpsubstT r (zip (map Var vs) xs)) (Var u) x) t u) (zip ts vs)›*) by standard also (*calculation: ‹rawpsubstT (substT (rawpsubstT (substT r (Var u) x) (zip (map Var us) xs)) t u) (zip ts us) = rawpsubstT (substT (substT (rawpsubstT r (zip (map Var vs) xs)) (Var u) x) t u) (zip ts vs)›*) have "… = rawpsubstT (substT (substT (rawpsubstT r (zip (map Var vs) xs)) (Var v) x) t v) (zip ts vs)" unfolding "2" (*goal: ‹rawpsubstT (substT (substT (rawpsubstT r (zip (map Var vs) xs)) (Var v) x) t v) (zip ts vs) = rawpsubstT (substT (substT (rawpsubstT r (zip (map Var vs) xs)) (Var v) x) t v) (zip ts vs)›*) by standard also (*calculation: ‹rawpsubstT (substT (rawpsubstT (substT r (Var u) x) (zip (map Var us) xs)) t u) (zip ts us) = rawpsubstT (substT (substT (rawpsubstT r (zip (map Var vs) xs)) (Var v) x) t v) (zip ts vs)›*) have "… = rawpsubstT (substT (rawpsubstT ?rvx (zip (map Var vs) xs)) t v) (zip ts vs)" unfolding "11" (*goal: ‹rawpsubstT (substT (substT (rawpsubstT r (zip (map Var vs) xs)) (Var v) x) t v) (zip ts vs) = rawpsubstT (substT (substT (rawpsubstT r (zip (map Var vs) xs)) (Var v) x) t v) (zip ts vs)›*) by standard finally (*calculation: ‹rawpsubstT (substT (rawpsubstT (substT r (Var u) x) (zip (map Var us) xs)) t u) (zip ts us) = rawpsubstT (substT (rawpsubstT (substT r (Var v) x) (zip (map Var vs) xs)) t v) (zip ts vs)›*) have "rawpsubstT (substT (rawpsubstT ?rux (zip (map Var us) xs)) t u) (zip ts us) = rawpsubstT (substT (rawpsubstT ?rvx (zip (map Var vs) xs)) t v) (zip ts vs)" . thus "?case" (*goal: ‹rawpsubstT (rawpsubstT (r::'trm) (zip (map (Var::'var ⇒ 'trm) (uus::'var list)) ((x::'var) # (xs::'var list)))) (zip (tts::'trm list) uus) = rawpsubstT (rawpsubstT r (zip (map Var (vvs::'var list)) (x # xs))) (zip tts vvs)›*) by simp qed (auto) (*solved the remaining goal: ‹⋀r ts us vs. ⟦r ∈ atrm; set ts ⊆ atrm; set [] ⊆ var; distinct []; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set [] = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set [] = {}; length us = length []; length vs = length []; length ts = length []; set us ∩ set vs = {}⟧ ⟹ rawpsubstT (rawpsubstT r (zip (map Var us) [])) (zip ts us) = rawpsubstT (rawpsubstT r (zip (map Var vs) [])) (zip ts vs)›*) (* ... now getting rid of the disjointness hypothesis: *) lemma rawpsubstT_compose_freshVar2: assumes r[simp]: "r ∈ atrm" and ts: "set ts ⊆ atrm" and xs: "set xs ⊆ var" "distinct xs" and us_facts: "set us ⊆ var" "distinct us" "set us ∩ FvarsT r = {}" "set us ∩ ⋃ (FvarsT ` (set ts)) = {}" "set us ∩ set xs = {}" and vs_facts: "set vs ⊆ var" "distinct vs" "set vs ∩ FvarsT r = {}" "set vs ∩ ⋃ (FvarsT ` (set ts)) = {}" "set vs ∩ set xs = {}" and l: "length us = length xs" "length vs = length xs" "length ts = length xs" shows "rawpsubstT (rawpsubstT r (zip (map Var us) xs)) (zip ts us) = rawpsubstT (rawpsubstT r (zip (map Var vs) xs)) (zip ts vs)" (is "?L = ?R") proof (-) (*goal: ‹rawpsubstT (rawpsubstT r (zip (map Var us) xs)) (zip ts us) = rawpsubstT (rawpsubstT r (zip (map Var vs) xs)) (zip ts vs)›*) have ts_trm: "set ts ⊆ trm" using ts (*‹set ts ⊆ atrm›*) by auto define ws where "ws = getFrN (xs @ us @ vs) (r # ts) [] (length xs)" have ws_facts: "set ws ⊆ var" "distinct ws" "set ws ∩ FvarsT r = {}" "set ws ∩ ⋃ (FvarsT ` (set ts)) = {}" "set ws ∩ set xs = {}" "set ws ∩ set us = {}" "set ws ∩ set vs = {}" "length ws = length xs" using assms(1) (*‹(r::'trm) ∈ atrm›*) ts_trm (*‹set ts ⊆ trm›*) assms(3-17) (*‹set xs ⊆ var› ‹distinct xs› ‹set us ⊆ var› ‹distinct us› ‹set us ∩ FvarsT r = {}› ‹set us ∩ ⋃ (FvarsT ` set ts) = {}› ‹set (us::'var list) ∩ set (xs::'var list) = {}› ‹set vs ⊆ var› ‹distinct (vs::'var list)› ‹set vs ∩ FvarsT r = {}› ‹set vs ∩ ⋃ (FvarsT ` set ts) = {}› ‹set (vs::'var::type list) ∩ set (xs::'var::type list) = {}› and more 3 facts*) unfolding ws_def (*goals: 1. ‹set (getFrN (xs @ us @ vs) (r # ts) [] (length xs)) ⊆ var› 2. ‹distinct (getFrN (xs @ us @ vs) (r # ts) [] (length xs))› 3. ‹set (getFrN (xs @ us @ vs) (r # ts) [] (length xs)) ∩ FvarsT r = {}› 4. ‹set (getFrN (xs @ us @ vs) (r # ts) [] (length xs)) ∩ ⋃ (FvarsT ` set ts) = {}› 5. ‹set (getFrN (xs @ us @ vs) (r # ts) [] (length xs)) ∩ set xs = {}› 6. ‹set (getFrN (xs @ us @ vs) (r # ts) [] (length xs)) ∩ set us = {}› 7. ‹set (getFrN (xs @ us @ vs) (r # ts) [] (length xs)) ∩ set vs = {}› 8. ‹length (getFrN (xs @ us @ vs) (r # ts) [] (length xs)) = length xs›*) using getFrN_Fvars[of "xs @ us @ vs" "r # ts" "[]" _ "length xs"] (*‹⟦set (xs @ us @ vs) ⊆ var; set (r # ts) ⊆ trm; set [] ⊆ fmla; ?φ ∈ set []⟧ ⟹ set (getFrN (xs @ us @ vs) (r # ts) [] (length xs)) ∩ Fvars ?φ = {}›*) getFrN_FvarsT[of "xs @ us @ vs" "r # ts" "[]" _ "length xs"] (*‹⟦set (xs @ us @ vs) ⊆ var; set (r # ts) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (r # ts)⟧ ⟹ set (getFrN (xs @ us @ vs) (r # ts) [] (length xs)) ∩ FvarsT ?t = {}›*) getFrN_var[of "xs @ us @ vs" "r # ts" "[]" _ "length xs"] (*‹⟦set (xs @ us @ vs) ⊆ var; set (r # ts) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (r # ts)⟧ ⟹ set (getFrN (xs @ us @ vs) (r # ts) [] (length xs)) ∩ set (xs @ us @ vs) = {}›*) getFrN_length[of "xs @ us @ vs" "r # ts" "[]" "length xs"] (*‹⟦set ((xs::'var list) @ (us::'var list) @ (vs::'var list)) ⊆ (var::'var set); set ((r::'trm) # (ts::'trm list)) ⊆ (trm::'trm set); set [] ⊆ (fmla::'fmla set)⟧ ⟹ length (getFrN (xs @ us @ vs) (r # ts) [] (length xs)) = length xs›*) apply - (*top goal: ‹set (getFrN (xs @ us @ vs) (r # ts) [] (length xs)) ⊆ var› and 7 goals remain*) subgoal for by auto subgoal for by auto subgoal for by auto subgoal for by force subgoal for by force subgoal for by force subgoal for by force by auto have "?L = rawpsubstT (rawpsubstT r (zip (map Var ws) xs)) (zip ts ws)" using assms (*‹(r::'trm::type) ∈ atrm› ‹set ts ⊆ atrm› ‹set xs ⊆ var› ‹distinct xs› ‹set us ⊆ var› ‹distinct (us::'var list)› ‹set us ∩ FvarsT r = {}› ‹set us ∩ ⋃ (FvarsT ` set ts) = {}› ‹set (us::'var list) ∩ set (xs::'var list) = {}› ‹set vs ⊆ var› ‹distinct vs› ‹set vs ∩ FvarsT r = {}› and more 5 facts*) ws_facts (*‹set ws ⊆ var› ‹distinct ws› ‹set (ws::'var::type list) ∩ (FvarsT::'trm::type ⇒ 'var::type set) (r::'trm::type) = {}› ‹set ws ∩ ⋃ (FvarsT ` set ts) = {}› ‹set (ws::'var list) ∩ set (xs::'var list) = {}› ‹set ws ∩ set us = {}› ‹set (ws::'var list) ∩ set (vs::'var list) = {}› ‹length ws = length xs›*) apply (intro rawpsubstT_compose_freshVar2_aux (*‹⟦(?r::'trm) ∈ atrm; set (?ts::'trm list) ⊆ atrm; set (?xs::'var list) ⊆ (var::'var set); distinct ?xs; set (?us::'var list) ⊆ var; distinct ?us; set ?us ∩ (FvarsT::'trm ⇒ 'var set) ?r = {}; set ?us ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?us ∩ set ?xs = {}; set (?vs::'var list) ⊆ var; distinct ?vs; set ?vs ∩ FvarsT ?r = {}; set ?vs ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?vs ∩ set ?xs = {}; length ?us = length ?xs; length ?vs = length ?xs; length ?ts = length ?xs; set ?us ∩ set ?vs = {}⟧ ⟹ rawpsubstT (rawpsubstT ?r (zip (map (Var::'var ⇒ 'trm) ?us) ?xs)) (zip ?ts ?us) = rawpsubstT (rawpsubstT ?r (zip (map Var ?vs) ?xs)) (zip ?ts ?vs)›*)) (*goals: 1. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ r ∈ atrm› 2. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ set ts ⊆ atrm› 3. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ set xs ⊆ var› 4. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ distinct xs› 5. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ set us ⊆ var› 6. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ distinct us› 7. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ set us ∩ FvarsT r = {}› 8. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ set us ∩ ⋃ (FvarsT ` set ts) = {}› 9. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ set us ∩ set xs = {}› 10. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ set ws ⊆ var› 11. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ distinct ws› 12. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ set ws ∩ FvarsT r = {}› 13. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ set ws ∩ ⋃ (FvarsT ` set ts) = {}› 14. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ set ws ∩ set xs = {}› 15. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ length us = length xs› 16. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ length ws = length xs› 17. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ length ts = length xs› 18. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ set us ∩ set ws = {}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*discuss goal 9*) apply ((auto)[1]) (*discuss goal 10*) apply ((auto)[1]) (*discuss goal 11*) apply ((auto)[1]) (*discuss goal 12*) apply ((auto)[1]) (*discuss goal 13*) apply ((auto)[1]) (*discuss goal 14*) apply ((auto)[1]) (*discuss goal 15*) apply ((auto)[1]) (*discuss goal 16*) apply ((auto)[1]) (*discuss goal 17*) apply ((auto)[1]) (*discuss goal 18*) apply ((auto)[1]) (*proven 18 subgoals*) . also (*calculation: ‹rawpsubstT (rawpsubstT r (zip (map Var us) xs)) (zip ts us) = rawpsubstT (rawpsubstT r (zip (map Var ws) xs)) (zip ts ws)›*) have "… = ?R" using assms (*‹r ∈ atrm› ‹set (ts::'trm list) ⊆ atrm› ‹set xs ⊆ var› ‹distinct (xs::'var list)› ‹set us ⊆ var› ‹distinct us› ‹set (us::'var::type list) ∩ (FvarsT::'trm::type ⇒ 'var::type set) (r::'trm::type) = {}› ‹set us ∩ ⋃ (FvarsT ` set ts) = {}› ‹set us ∩ set xs = {}› ‹set vs ⊆ var› ‹distinct vs› ‹set vs ∩ FvarsT r = {}› and more 5 facts*) ws_facts (*‹set ws ⊆ var› ‹distinct ws› ‹set ws ∩ FvarsT r = {}› ‹set ws ∩ ⋃ (FvarsT ` set ts) = {}› ‹set ws ∩ set xs = {}› ‹set ws ∩ set us = {}› ‹set ws ∩ set vs = {}› ‹length ws = length xs›*) apply (intro rawpsubstT_compose_freshVar2_aux (*‹⟦?r ∈ atrm; set ?ts ⊆ atrm; set ?xs ⊆ var; distinct ?xs; set ?us ⊆ var; distinct ?us; set ?us ∩ FvarsT ?r = {}; set ?us ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?us ∩ set ?xs = {}; set ?vs ⊆ var; distinct ?vs; set ?vs ∩ FvarsT ?r = {}; set ?vs ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?vs ∩ set ?xs = {}; length ?us = length ?xs; length ?vs = length ?xs; length ?ts = length ?xs; set ?us ∩ set ?vs = {}⟧ ⟹ rawpsubstT (rawpsubstT ?r (zip (map Var ?us) ?xs)) (zip ?ts ?us) = rawpsubstT (rawpsubstT ?r (zip (map Var ?vs) ?xs)) (zip ?ts ?vs)›*)) (*goals: 1. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ r ∈ atrm› 2. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ set ts ⊆ atrm› 3. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ set xs ⊆ var› 4. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ distinct xs› 5. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ set ws ⊆ var› 6. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ distinct ws› 7. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ set ws ∩ FvarsT r = {}› 8. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ set ws ∩ ⋃ (FvarsT ` set ts) = {}› 9. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ set ws ∩ set xs = {}› 10. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ set vs ⊆ var› 11. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ distinct vs› 12. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ set vs ∩ FvarsT r = {}› 13. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ set vs ∩ ⋃ (FvarsT ` set ts) = {}› 14. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ set vs ∩ set xs = {}› 15. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ length ws = length xs› 16. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ length vs = length xs› 17. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ length ts = length xs› 18. ‹⟦r ∈ atrm; set ts ⊆ atrm; set xs ⊆ var; distinct xs; set us ⊆ var; distinct us; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` set ts) = {}; set us ∩ set xs = {}; set vs ⊆ var; distinct vs; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` set ts) = {}; set vs ∩ set xs = {}; length us = length xs; length vs = length xs; length ts = length xs; set ws ⊆ var; distinct ws; set ws ∩ FvarsT r = {}; set ws ∩ ⋃ (FvarsT ` set ts) = {}; set ws ∩ set xs = {}; set ws ∩ set us = {}; set ws ∩ set vs = {}; length ws = length xs⟧ ⟹ set ws ∩ set vs = {}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*discuss goal 9*) apply ((auto)[1]) (*discuss goal 10*) apply ((auto)[1]) (*discuss goal 11*) apply ((auto)[1]) (*discuss goal 12*) apply ((auto)[1]) (*discuss goal 13*) apply ((auto)[1]) (*discuss goal 14*) apply ((auto)[1]) (*discuss goal 15*) apply ((auto)[1]) (*discuss goal 16*) apply ((auto)[1]) (*discuss goal 17*) apply ((auto)[1]) (*discuss goal 18*) apply ((auto)[1]) (*proven 18 subgoals*) . finally (*calculation: ‹rawpsubstT (rawpsubstT r (zip (map Var us) xs)) (zip ts us) = rawpsubstT (rawpsubstT r (zip (map Var vs) xs)) (zip ts vs)›*) show "?thesis" (*goal: ‹rawpsubstT (rawpsubstT r (zip (map Var us) xs)) (zip ts us) = rawpsubstT (rawpsubstT r (zip (map Var vs) xs)) (zip ts vs)›*) . qed lemma in_fst_image: "a ∈ fst ` AB ⟷ (∃b. (a,b) ∈ AB)" by force (* For many cases, the simpler rawpsubstT can replace psubst: *) lemma psubstT_eq_rawpsubstT: assumes "r ∈ atrm" "snd ` (set txs) ⊆ var" and "fst ` (set txs) ⊆ atrm" and "distinct (map snd txs)" (* ... namely, when the substituted variables do not belong to trms substituted for previous variables: *) and "⋀ i j. i < j ⟹ j < length txs ⟹ snd (txs!j) ∉ FvarsT (fst (txs!i))" shows "psubstT r txs = rawpsubstT r txs" proof (-) (*goal: ‹psubstT r txs = rawpsubstT r txs›*) have txs_trm: "r ∈ trm" "fst ` (set txs) ⊆ trm" using assms (*‹r ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set (txs::('trm::type × 'var::type) list) ⊆ atrm› ‹distinct (map snd txs)› ‹⟦?i < ?j; ?j < length txs⟧ ⟹ snd (txs ! ?j) ∉ FvarsT (fst (txs ! ?i))›*) apply - (*goals: 1. ‹⟦(r::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀(i::nat) j::nat. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ (FvarsT::'trm ⇒ 'var set) (fst (txs ! i))⟧ ⟹ r ∈ (trm::'trm set)› 2. ‹⟦(r::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); ⋀(i::nat) j::nat. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ (FvarsT::'trm ⇒ 'var set) (fst (txs ! i))⟧ ⟹ fst ` set txs ⊆ (trm::'trm set)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . note frt = getFrN_FvarsT[of "map snd txs" "r # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ FvarsT ?t = {}›*) and fr = getFrN_Fvars[of "map snd txs" "r # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; ?φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ Fvars ?φ = {}›*) and var = getFrN_var[of "map snd txs" "r # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd (txs::('trm × 'var) list)) ⊆ (var::'var set); set ((r::'trm) # map fst txs) ⊆ (trm::'trm set); set [] ⊆ (fmla::'fmla set); (?t::'trm) ∈ set (r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}›*) and l = getFrN_length[of "map snd txs" "r # map fst txs" "[]" "length txs"] (*‹⟦set (map snd (txs::('trm × 'var) list)) ⊆ (var::'var set); set ((r::'trm) # map fst txs) ⊆ (trm::'trm set); set [] ⊆ (fmla::'fmla set)⟧ ⟹ length (getFrN (map snd txs) (r # map fst txs) [] (length txs)) = length txs›*) define us where us: "us ≡ getFrN (map snd txs) (r # map fst txs) [] (length txs)" have us_facts: "set us ⊆ var" "set us ∩ FvarsT r = {}" "set us ∩ ⋃ (FvarsT ` (fst ` (set txs))) = {}" "set us ∩ snd ` (set txs) = {}" "length us = length txs" "distinct us" using assms(2,4,5) (*‹snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set)› ‹distinct (map snd txs)› ‹⟦?i < ?j; ?j < length txs⟧ ⟹ snd (txs ! ?j) ∉ FvarsT (fst (txs ! ?i))›*) txs_trm (*‹r ∈ trm› ‹fst ` set txs ⊆ trm›*) unfolding us (*goals: 1. ‹set (getFrN (map snd (txs::('trm × 'var) list)) ((r::'trm) # map fst txs) [] (length txs)) ⊆ (var::'var set)› 2. ‹set (getFrN (map snd (txs::('trm × 'var) list)) ((r::'trm) # map fst txs) [] (length txs)) ∩ (FvarsT::'trm ⇒ 'var set) r = {}› 3. ‹set (getFrN (map snd (txs::('trm × 'var) list)) ((r::'trm) # map fst txs) [] (length txs)) ∩ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set txs) = {}› 4. ‹set (getFrN (map snd (txs::('trm × 'var) list)) ((r::'trm) # map fst txs) [] (length txs)) ∩ snd ` set txs = {}› 5. ‹length (getFrN (map snd (txs::('trm × 'var) list)) ((r::'trm) # map fst txs) [] (length txs)) = length txs› 6. ‹distinct (getFrN (map snd (txs::('trm × 'var) list)) ((r::'trm) # map fst txs) [] (length txs))›*) apply - (*top goal: ‹set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ⊆ var› and 5 goals remain*) subgoal for by auto subgoal for using frt (*‹⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ FvarsT ?t = {}›*) by auto subgoal for using frt (*‹⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ FvarsT ?t = {}›*) apply (simp add: in_fst_image (*‹((?a::?'a) ∈ fst ` (?AB::(?'a × ?'b) set)) = (∃b::?'b. (?a, b) ∈ ?AB)›*) Int_def (*‹(?A::?'a set) ∩ (?B::?'a set) = {x::?'a ∈ ?A. x ∈ ?B}›*)) (*goal: ‹⟦snd ` set txs ⊆ var; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); r ∈ trm; fst ` set txs ⊆ trm⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ ⋃ (FvarsT ` fst ` set txs) = {}›*) by (metis prod.collapse (*‹(fst (?prod::?'a × ?'b), snd ?prod) = ?prod›*)) subgoal for using var (*‹⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}›*) apply (simp add: in_fst_image (*‹(?a ∈ fst ` ?AB) = (∃b. (?a, b) ∈ ?AB)›*) Int_def (*‹?A ∩ ?B = {x ∈ ?A. x ∈ ?B}›*)) (*goal: ‹⟦snd ` set txs ⊆ var; distinct (map snd txs); ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i)); r ∈ trm; fst ` set txs ⊆ trm⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ snd ` set txs = {}›*) by metis subgoal for using l (*‹⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r # map fst txs) [] (length txs)) = length txs›*) by auto subgoal for by auto . show "?thesis" (*goal: ‹psubstT r txs = rawpsubstT r txs›*) using rawpsubstT_compose_freshVar (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; distinct (map snd ?txs); ⋀i j. ⟦i < j; j < length ?txs⟧ ⟹ snd (?txs ! j) ∉ FvarsT (fst (?txs ! i)); set ?us ⊆ var; set ?us ∩ FvarsT ?r = {}; set ?us ∩ ⋃ (FvarsT ` fst ` set ?txs) = {}; set ?us ∩ snd ` set ?txs = {}; length ?us = length ?txs; distinct ?us⟧ ⟹ rawpsubstT (rawpsubstT ?r (zip (map Var ?us) (map snd ?txs))) (zip (map fst ?txs) ?us) = rawpsubstT ?r ?txs›*) assms (*‹r ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹distinct (map snd txs)› ‹⟦?i < ?j; ?j < length txs⟧ ⟹ snd (txs ! ?j) ∉ FvarsT (fst (txs ! ?i))›*) us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT r = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct us›*) by (simp add: psubstT_def (*‹psubstT ?t ?txs = (let xs = map snd ?txs; ts = map fst ?txs; us = getFrN xs (?t # ts) [] (length xs) in rawpsubstT (rawpsubstT ?t (zip (map Var us) xs)) (zip ts us))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) us[symmetric] (*‹getFrN (map snd txs) (r # map fst txs) [] (length txs) ≡ us›*)) qed (* Some particular cases: *) lemma psubstT_eq_substT: assumes "r ∈ atrm" "x ∈ var" and "t ∈ atrm" shows "psubstT r [(t,x)] = substT r t x" proof (-) (*goal: ‹psubstT r [(t, x)] = substT r t x›*) have "psubstT r [(t,x)] = rawpsubstT r [(t,x)]" using assms (*‹r ∈ atrm› ‹x ∈ var› ‹t ∈ atrm›*) apply (intro psubstT_eq_rawpsubstT (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; distinct (map snd ?txs); ⋀i j. ⟦i < j; j < length ?txs⟧ ⟹ snd (?txs ! j) ∉ FvarsT (fst (?txs ! i))⟧ ⟹ psubstT ?r ?txs = rawpsubstT ?r ?txs›*)) (*goals: 1. ‹⟦(r::'trm) ∈ atrm; (x::'var) ∈ (var::'var set); (t::'trm) ∈ atrm⟧ ⟹ r ∈ atrm› 2. ‹⟦(r::'trm) ∈ atrm; (x::'var) ∈ (var::'var set); (t::'trm) ∈ atrm⟧ ⟹ snd ` set [(t, x)] ⊆ var› 3. ‹⟦(r::'trm) ∈ atrm; (x::'var) ∈ (var::'var set); (t::'trm) ∈ atrm⟧ ⟹ fst ` set [(t, x)] ⊆ atrm› 4. ‹⟦(r::'trm) ∈ atrm; (x::'var) ∈ (var::'var set); (t::'trm) ∈ atrm⟧ ⟹ distinct (map snd [(t, x)])› 5. ‹⋀(i::nat) j::nat. ⟦(r::'trm) ∈ atrm; (x::'var) ∈ (var::'var set); (t::'trm) ∈ atrm; i < j; j < length [(t, x)]⟧ ⟹ snd ([(t, x)] ! j) ∉ (FvarsT::'trm ⇒ 'var set) (fst ([(t, x)] ! i))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . thus "?thesis" (*goal: ‹psubstT r [(t, x)] = substT r t x›*) by auto qed lemma psubstT_eq_rawpsubst2: assumes "r ∈ atrm" "x1 ∈ var" "x2 ∈ var" "t1 ∈ atrm" "t2 ∈ atrm" and "x1 ≠ x2" "x2 ∉ FvarsT t1" shows "psubstT r [(t1,x1),(t2,x2)] = rawpsubstT r [(t1,x1),(t2,x2)]" using assms (*‹(r::'trm::type) ∈ atrm› ‹x1 ∈ var› ‹x2 ∈ var› ‹t1 ∈ atrm› ‹t2 ∈ atrm› ‹x1 ≠ x2› ‹(x2::'var) ∉ (FvarsT::'trm ⇒ 'var set) (t1::'trm)›*) using less_SucE (*‹⟦?m < Suc ?n; ?m < ?n ⟹ ?P; ?m = ?n ⟹ ?P⟧ ⟹ ?P›*) apply (intro psubstT_eq_rawpsubstT (*‹⟦(?r::'trm) ∈ atrm; snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ atrm; distinct (map snd ?txs); ⋀(i::nat) j::nat. ⟦i < j; j < length ?txs⟧ ⟹ snd (?txs ! j) ∉ (FvarsT::'trm ⇒ 'var set) (fst (?txs ! i))⟧ ⟹ psubstT ?r ?txs = rawpsubstT ?r ?txs›*)) (*goals: 1. ‹⟦(r::'trm) ∈ atrm; (x1::'var) ∈ (var::'var set); (x2::'var) ∈ var; (t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; x1 ≠ x2; x2 ∉ (FvarsT::'trm ⇒ 'var set) t1; ⋀(m::nat) (n::nat) P::bool. ⟦m < Suc n; m < n ⟹ P; m = n ⟹ P⟧ ⟹ P⟧ ⟹ r ∈ atrm› 2. ‹⟦(r::'trm) ∈ atrm; (x1::'var) ∈ (var::'var set); (x2::'var) ∈ var; (t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; x1 ≠ x2; x2 ∉ (FvarsT::'trm ⇒ 'var set) t1; ⋀(m::nat) (n::nat) P::bool. ⟦m < Suc n; m < n ⟹ P; m = n ⟹ P⟧ ⟹ P⟧ ⟹ snd ` set [(t1, x1), (t2, x2)] ⊆ var› 3. ‹⟦(r::'trm) ∈ atrm; (x1::'var) ∈ (var::'var set); (x2::'var) ∈ var; (t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; x1 ≠ x2; x2 ∉ (FvarsT::'trm ⇒ 'var set) t1; ⋀(m::nat) (n::nat) P::bool. ⟦m < Suc n; m < n ⟹ P; m = n ⟹ P⟧ ⟹ P⟧ ⟹ fst ` set [(t1, x1), (t2, x2)] ⊆ atrm› 4. ‹⟦(r::'trm) ∈ atrm; (x1::'var) ∈ (var::'var set); (x2::'var) ∈ var; (t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; x1 ≠ x2; x2 ∉ (FvarsT::'trm ⇒ 'var set) t1; ⋀(m::nat) (n::nat) P::bool. ⟦m < Suc n; m < n ⟹ P; m = n ⟹ P⟧ ⟹ P⟧ ⟹ distinct (map snd [(t1, x1), (t2, x2)])› 5. ‹⋀(i::nat) j::nat. ⟦(r::'trm) ∈ atrm; (x1::'var) ∈ (var::'var set); (x2::'var) ∈ var; (t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; x1 ≠ x2; x2 ∉ (FvarsT::'trm ⇒ 'var set) t1; ⋀(m::nat) (n::nat) P::bool. ⟦m < Suc n; m < n ⟹ P; m = n ⟹ P⟧ ⟹ P; i < j; j < length [(t1, x1), (t2, x2)]⟧ ⟹ snd ([(t1, x1), (t2, x2)] ! j) ∉ FvarsT (fst ([(t1, x1), (t2, x2)] ! i))› discuss goal 1*) apply force (*discuss goal 2*) apply force (*discuss goal 3*) apply force (*discuss goal 4*) apply force (*discuss goal 5*) apply force (*proven 5 subgoals*) . lemma psubstT_eq_rawpsubst3: assumes "r ∈ atrm" "x1 ∈ var" "x2 ∈ var" "x3 ∈ var" "t1 ∈ atrm" "t2 ∈ atrm" "t3 ∈ atrm" and "x1 ≠ x2" "x1 ≠ x3" "x2 ≠ x3" "x2 ∉ FvarsT t1" "x3 ∉ FvarsT t1" "x3 ∉ FvarsT t2" shows "psubstT r [(t1,x1),(t2,x2),(t3,x3)] = rawpsubstT r [(t1,x1),(t2,x2),(t3,x3)]" using assms (*‹r ∈ atrm› ‹x1 ∈ var› ‹x2 ∈ var› ‹x3 ∈ var› ‹(t1::'trm) ∈ atrm› ‹t2 ∈ atrm› ‹(t3::'trm::type) ∈ atrm› ‹x1 ≠ x2› ‹(x1::'var) ≠ (x3::'var)› ‹x2 ≠ x3› ‹x2 ∉ FvarsT t1› ‹(x3::'var) ∉ (FvarsT::'trm ⇒ 'var set) (t1::'trm)› and more 1 facts*) less_SucE (*‹⟦?m < Suc ?n; ?m < ?n ⟹ ?P; ?m = ?n ⟹ ?P⟧ ⟹ ?P›*) less_Suc_eq_0_disj (*‹(?m < Suc ?n) = (?m = 0 ∨ (∃j. ?m = Suc j ∧ j < ?n))›*) apply (intro psubstT_eq_rawpsubstT (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; distinct (map snd ?txs); ⋀i j. ⟦i < j; j < length ?txs⟧ ⟹ snd (?txs ! j) ∉ FvarsT (fst (?txs ! i))⟧ ⟹ psubstT ?r ?txs = rawpsubstT ?r ?txs›*)) (*goals: 1. ‹⟦r ∈ atrm; x1 ∈ var; x2 ∈ var; x3 ∈ var; t1 ∈ atrm; t2 ∈ atrm; t3 ∈ atrm; x1 ≠ x2; x1 ≠ x3; x2 ≠ x3; x2 ∉ FvarsT t1; x3 ∉ FvarsT t1; x3 ∉ FvarsT t2; ⋀m n P. ⟦m < Suc n; m < n ⟹ P; m = n ⟹ P⟧ ⟹ P; ⋀m n. (m < Suc n) = (m = 0 ∨ (∃j. m = Suc j ∧ j < n))⟧ ⟹ r ∈ atrm› 2. ‹⟦r ∈ atrm; x1 ∈ var; x2 ∈ var; x3 ∈ var; t1 ∈ atrm; t2 ∈ atrm; t3 ∈ atrm; x1 ≠ x2; x1 ≠ x3; x2 ≠ x3; x2 ∉ FvarsT t1; x3 ∉ FvarsT t1; x3 ∉ FvarsT t2; ⋀m n P. ⟦m < Suc n; m < n ⟹ P; m = n ⟹ P⟧ ⟹ P; ⋀m n. (m < Suc n) = (m = 0 ∨ (∃j. m = Suc j ∧ j < n))⟧ ⟹ snd ` set [(t1, x1), (t2, x2), (t3, x3)] ⊆ var› 3. ‹⟦r ∈ atrm; x1 ∈ var; x2 ∈ var; x3 ∈ var; t1 ∈ atrm; t2 ∈ atrm; t3 ∈ atrm; x1 ≠ x2; x1 ≠ x3; x2 ≠ x3; x2 ∉ FvarsT t1; x3 ∉ FvarsT t1; x3 ∉ FvarsT t2; ⋀m n P. ⟦m < Suc n; m < n ⟹ P; m = n ⟹ P⟧ ⟹ P; ⋀m n. (m < Suc n) = (m = 0 ∨ (∃j. m = Suc j ∧ j < n))⟧ ⟹ fst ` set [(t1, x1), (t2, x2), (t3, x3)] ⊆ atrm› 4. ‹⟦r ∈ atrm; x1 ∈ var; x2 ∈ var; x3 ∈ var; t1 ∈ atrm; t2 ∈ atrm; t3 ∈ atrm; x1 ≠ x2; x1 ≠ x3; x2 ≠ x3; x2 ∉ FvarsT t1; x3 ∉ FvarsT t1; x3 ∉ FvarsT t2; ⋀m n P. ⟦m < Suc n; m < n ⟹ P; m = n ⟹ P⟧ ⟹ P; ⋀m n. (m < Suc n) = (m = 0 ∨ (∃j. m = Suc j ∧ j < n))⟧ ⟹ distinct (map snd [(t1, x1), (t2, x2), (t3, x3)])› 5. ‹⋀i j. ⟦r ∈ atrm; x1 ∈ var; x2 ∈ var; x3 ∈ var; t1 ∈ atrm; t2 ∈ atrm; t3 ∈ atrm; x1 ≠ x2; x1 ≠ x3; x2 ≠ x3; x2 ∉ FvarsT t1; x3 ∉ FvarsT t1; x3 ∉ FvarsT t2; ⋀m n P. ⟦m < Suc n; m < n ⟹ P; m = n ⟹ P⟧ ⟹ P; ⋀m n. (m < Suc n) = (m = 0 ∨ (∃j. m = Suc j ∧ j < n)); i < j; j < length [(t1, x1), (t2, x2), (t3, x3)]⟧ ⟹ snd ([(t1, x1), (t2, x2), (t3, x3)] ! j) ∉ FvarsT (fst ([(t1, x1), (t2, x2), (t3, x3)] ! i))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . lemma psubstT_eq_rawpsubst4: assumes "r ∈ atrm" "x1 ∈ var" "x2 ∈ var" "x3 ∈ var" "x4 ∈ var" "t1 ∈ atrm" "t2 ∈ atrm" "t3 ∈ atrm" "t4 ∈ atrm" and "x1 ≠ x2" "x1 ≠ x3" "x2 ≠ x3" "x1 ≠ x4" "x2 ≠ x4" "x3 ≠ x4" "x2 ∉ FvarsT t1" "x3 ∉ FvarsT t1" "x3 ∉ FvarsT t2" "x4 ∉ FvarsT t1" "x4 ∉ FvarsT t2" "x4 ∉ FvarsT t3" shows "psubstT r [(t1,x1),(t2,x2),(t3,x3),(t4,x4)] = rawpsubstT r [(t1,x1),(t2,x2),(t3,x3),(t4,x4)]" using assms (*‹r ∈ atrm› ‹(x1::'var) ∈ (var::'var set)› ‹x2 ∈ var› ‹x3 ∈ var› ‹x4 ∈ var› ‹t1 ∈ atrm› ‹t2 ∈ atrm› ‹(t3::'trm) ∈ atrm› ‹(t4::'trm) ∈ atrm› ‹x1 ≠ x2› ‹x1 ≠ x3› ‹x2 ≠ x3› and more 9 facts*) less_SucE (*‹⟦?m < Suc ?n; ?m < ?n ⟹ ?P; ?m = ?n ⟹ ?P⟧ ⟹ ?P›*) less_Suc_eq_0_disj (*‹((?m::nat) < Suc (?n::nat)) = (?m = (0::nat) ∨ (∃j::nat. ?m = Suc j ∧ j < ?n))›*) apply (intro psubstT_eq_rawpsubstT (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; distinct (map snd ?txs); ⋀i j. ⟦i < j; j < length ?txs⟧ ⟹ snd (?txs ! j) ∉ FvarsT (fst (?txs ! i))⟧ ⟹ psubstT ?r ?txs = rawpsubstT ?r ?txs›*)) (*goals: 1. ‹⟦r ∈ atrm; x1 ∈ var; x2 ∈ var; x3 ∈ var; x4 ∈ var; t1 ∈ atrm; t2 ∈ atrm; t3 ∈ atrm; t4 ∈ atrm; x1 ≠ x2; x1 ≠ x3; x2 ≠ x3; x1 ≠ x4; x2 ≠ x4; x3 ≠ x4; x2 ∉ FvarsT t1; x3 ∉ FvarsT t1; x3 ∉ FvarsT t2; x4 ∉ FvarsT t1; x4 ∉ FvarsT t2; x4 ∉ FvarsT t3; ⋀m n P. ⟦m < Suc n; m < n ⟹ P; m = n ⟹ P⟧ ⟹ P; ⋀m n. (m < Suc n) = (m = 0 ∨ (∃j. m = Suc j ∧ j < n))⟧ ⟹ r ∈ atrm› 2. ‹⟦r ∈ atrm; x1 ∈ var; x2 ∈ var; x3 ∈ var; x4 ∈ var; t1 ∈ atrm; t2 ∈ atrm; t3 ∈ atrm; t4 ∈ atrm; x1 ≠ x2; x1 ≠ x3; x2 ≠ x3; x1 ≠ x4; x2 ≠ x4; x3 ≠ x4; x2 ∉ FvarsT t1; x3 ∉ FvarsT t1; x3 ∉ FvarsT t2; x4 ∉ FvarsT t1; x4 ∉ FvarsT t2; x4 ∉ FvarsT t3; ⋀m n P. ⟦m < Suc n; m < n ⟹ P; m = n ⟹ P⟧ ⟹ P; ⋀m n. (m < Suc n) = (m = 0 ∨ (∃j. m = Suc j ∧ j < n))⟧ ⟹ snd ` set [(t1, x1), (t2, x2), (t3, x3), (t4, x4)] ⊆ var› 3. ‹⟦r ∈ atrm; x1 ∈ var; x2 ∈ var; x3 ∈ var; x4 ∈ var; t1 ∈ atrm; t2 ∈ atrm; t3 ∈ atrm; t4 ∈ atrm; x1 ≠ x2; x1 ≠ x3; x2 ≠ x3; x1 ≠ x4; x2 ≠ x4; x3 ≠ x4; x2 ∉ FvarsT t1; x3 ∉ FvarsT t1; x3 ∉ FvarsT t2; x4 ∉ FvarsT t1; x4 ∉ FvarsT t2; x4 ∉ FvarsT t3; ⋀m n P. ⟦m < Suc n; m < n ⟹ P; m = n ⟹ P⟧ ⟹ P; ⋀m n. (m < Suc n) = (m = 0 ∨ (∃j. m = Suc j ∧ j < n))⟧ ⟹ fst ` set [(t1, x1), (t2, x2), (t3, x3), (t4, x4)] ⊆ atrm› 4. ‹⟦r ∈ atrm; x1 ∈ var; x2 ∈ var; x3 ∈ var; x4 ∈ var; t1 ∈ atrm; t2 ∈ atrm; t3 ∈ atrm; t4 ∈ atrm; x1 ≠ x2; x1 ≠ x3; x2 ≠ x3; x1 ≠ x4; x2 ≠ x4; x3 ≠ x4; x2 ∉ FvarsT t1; x3 ∉ FvarsT t1; x3 ∉ FvarsT t2; x4 ∉ FvarsT t1; x4 ∉ FvarsT t2; x4 ∉ FvarsT t3; ⋀m n P. ⟦m < Suc n; m < n ⟹ P; m = n ⟹ P⟧ ⟹ P; ⋀m n. (m < Suc n) = (m = 0 ∨ (∃j. m = Suc j ∧ j < n))⟧ ⟹ distinct (map snd [(t1, x1), (t2, x2), (t3, x3), (t4, x4)])› 5. ‹⋀i j. ⟦r ∈ atrm; x1 ∈ var; x2 ∈ var; x3 ∈ var; x4 ∈ var; t1 ∈ atrm; t2 ∈ atrm; t3 ∈ atrm; t4 ∈ atrm; x1 ≠ x2; x1 ≠ x3; x2 ≠ x3; x1 ≠ x4; x2 ≠ x4; x3 ≠ x4; x2 ∉ FvarsT t1; x3 ∉ FvarsT t1; x3 ∉ FvarsT t2; x4 ∉ FvarsT t1; x4 ∉ FvarsT t2; x4 ∉ FvarsT t3; ⋀m n P. ⟦m < Suc n; m < n ⟹ P; m = n ⟹ P⟧ ⟹ P; ⋀m n. (m < Suc n) = (m = 0 ∨ (∃j. m = Suc j ∧ j < n)); i < j; j < length [(t1, x1), (t2, x2), (t3, x3), (t4, x4)]⟧ ⟹ snd ([(t1, x1), (t2, x2), (t3, x3), (t4, x4)] ! j) ∉ FvarsT (fst ([(t1, x1), (t2, x2), (t3, x3), (t4, x4)] ! i))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . lemma rawpsubstT_same_Var[simp]: assumes "r ∈ atrm" "set xs ⊆ var" shows "rawpsubstT r (map (λx. (Var x,x)) xs) = r" using assms (*‹r ∈ atrm› ‹set xs ⊆ var›*) apply (induct xs) (*goals: 1. ‹⟦r ∈ atrm; set [] ⊆ var⟧ ⟹ rawpsubstT r (map (λx. (Var x, x)) []) = r› 2. ‹⋀a xs. ⟦⟦r ∈ atrm; set xs ⊆ var⟧ ⟹ rawpsubstT r (map (λx. (Var x, x)) xs) = r; r ∈ atrm; set (a # xs) ⊆ var⟧ ⟹ rawpsubstT r (map (λx. (Var x, x)) (a # xs)) = r› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma psubstT_same_Var[simp]: assumes "r ∈ atrm" "set xs ⊆ var" and "distinct xs" shows "psubstT r (map (λx. (Var x,x)) xs) = r" proof (-) (*goal: ‹psubstT r (map (λx. (Var x, x)) xs) = r›*) have "psubstT r (map (λx. (Var x,x)) xs) = rawpsubstT r (map (λx. (Var x,x)) xs)" using assms (*‹r ∈ atrm› ‹set xs ⊆ var› ‹distinct xs›*) FvarsT_Var[of "xs ! _"] (*‹xs ! ?uu3 ∈ var ⟹ FvarsT (Var (xs ! ?uu3)) = {xs ! ?uu3}›*) nth_mem[of _ xs] (*‹?n < length xs ⟹ xs ! ?n ∈ set xs›*) apply (intro psubstT_eq_rawpsubstT (*‹⟦?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; distinct (map snd ?txs); ⋀i j. ⟦i < j; j < length ?txs⟧ ⟹ snd (?txs ! j) ∉ FvarsT (fst (?txs ! i))⟧ ⟹ psubstT ?r ?txs = rawpsubstT ?r ?txs›*)) (*goals: 1. ‹⟦r ∈ atrm; set xs ⊆ var; distinct xs; ⋀uu. xs ! uu ∈ var ⟹ FvarsT (Var (xs ! uu)) = {xs ! uu}; ⋀n. n < length xs ⟹ xs ! n ∈ set xs⟧ ⟹ r ∈ atrm› 2. ‹⟦r ∈ atrm; set xs ⊆ var; distinct xs; ⋀uu. xs ! uu ∈ var ⟹ FvarsT (Var (xs ! uu)) = {xs ! uu}; ⋀n. n < length xs ⟹ xs ! n ∈ set xs⟧ ⟹ snd ` set (map (λx. (Var x, x)) xs) ⊆ var› 3. ‹⟦r ∈ atrm; set xs ⊆ var; distinct xs; ⋀uu. xs ! uu ∈ var ⟹ FvarsT (Var (xs ! uu)) = {xs ! uu}; ⋀n. n < length xs ⟹ xs ! n ∈ set xs⟧ ⟹ fst ` set (map (λx. (Var x, x)) xs) ⊆ atrm› 4. ‹⟦r ∈ atrm; set xs ⊆ var; distinct xs; ⋀uu. xs ! uu ∈ var ⟹ FvarsT (Var (xs ! uu)) = {xs ! uu}; ⋀n. n < length xs ⟹ xs ! n ∈ set xs⟧ ⟹ distinct (map snd (map (λx. (Var x, x)) xs))› 5. ‹⋀i j. ⟦r ∈ atrm; set xs ⊆ var; distinct xs; ⋀uu. xs ! uu ∈ var ⟹ FvarsT (Var (xs ! uu)) = {xs ! uu}; ⋀n. n < length xs ⟹ xs ! n ∈ set xs; i < j; j < length (map (λx. (Var x, x)) xs)⟧ ⟹ snd (map (λx. (Var x, x)) xs ! j) ∉ FvarsT (fst (map (λx. (Var x, x)) xs ! i))› discuss goal 1*) apply ((auto simp: o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*) distinct_conv_nth (*‹distinct ?xs = (∀i<length ?xs. ∀j<length ?xs. i ≠ j ⟶ ?xs ! i ≠ ?xs ! j)›*) dest!: FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*))[1]) (*discuss goal 2*) apply ((auto simp: o_def (*‹(?f::?'b::type ⇒ ?'c::type) ∘ (?g::?'a::type ⇒ ?'b::type) = (λx::?'a::type. ?f (?g x))›*) distinct_conv_nth (*‹distinct (?xs::?'a::type list) = (∀i<length ?xs. ∀j<length ?xs. i ≠ j ⟶ ?xs ! i ≠ ?xs ! j)›*) dest!: FvarsT_VarD (*‹⟦(?x::'var::type) ∈ (FvarsT::'trm::type ⇒ 'var::type set) ((Var::'var::type ⇒ 'trm::type) (?y::'var::type)); ?y ∈ (var::'var::type set)⟧ ⟹ ?x = ?y›*))[1]) (*discuss goal 3*) apply ((auto simp: o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*) distinct_conv_nth (*‹distinct ?xs = (∀i<length ?xs. ∀j<length ?xs. i ≠ j ⟶ ?xs ! i ≠ ?xs ! j)›*) dest!: FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*))[1]) (*discuss goal 4*) apply ((auto simp: o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*) distinct_conv_nth (*‹distinct ?xs = (∀i<length ?xs. ∀j<length ?xs. i ≠ j ⟶ ?xs ! i ≠ ?xs ! j)›*) dest!: FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*))[1]) (*discuss goal 5*) apply ((auto simp: o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*) distinct_conv_nth (*‹distinct ?xs = (∀i<length ?xs. ∀j<length ?xs. i ≠ j ⟶ ?xs ! i ≠ ?xs ! j)›*) dest!: FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*))[1]) (*proven 5 subgoals*) . thus "?thesis" (*goal: ‹psubstT r (map (λx. (Var x, x)) xs) = r›*) using assms (*‹r ∈ atrm› ‹set xs ⊆ var› ‹distinct xs›*) by auto qed (* The following holds for all trms, so no need to prove it for a trms: *) thm psubstT_notIn (***) (* Behavior of psubst w.r.t. equality formulas: *) lemma rawpsubst_eql: assumes "t1 ∈ trm" "t2 ∈ trm" and "snd ` (set txs) ⊆ var" "fst ` (set txs) ⊆ trm" shows "rawpsubst (eql t1 t2) txs = eql (rawpsubstT t1 txs) (rawpsubstT t2 txs)" using assms (*‹t1 ∈ trm› ‹(t2::'trm::type) ∈ (trm::'trm::type set)› ‹snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set)› ‹fst ` set (txs::('trm × 'var) list) ⊆ (trm::'trm set)›*) apply (induct txs arbitrary: t1 t2) (*goal: ‹rawpsubst (eql t1 t2) txs = eql (rawpsubstT t1 txs) (rawpsubstT t2 txs)›*) subgoal for by auto subgoal for tx and txs and t1 and t2 apply (cases tx) (*goal: ‹⟦⋀t1 t2. ⟦t1 ∈ trm; t2 ∈ trm; snd ` set txs ⊆ var; fst ` set txs ⊆ trm⟧ ⟹ rawpsubst (eql t1 t2) txs = eql (rawpsubstT t1 txs) (rawpsubstT t2 txs); t1 ∈ trm; t2 ∈ trm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ trm⟧ ⟹ rawpsubst (eql t1 t2) (tx # txs) = eql (rawpsubstT t1 (tx # txs)) (rawpsubstT t2 (tx # txs))›*) by auto . lemma psubst_eql[simp]: assumes "t1 ∈ atrm" "t2 ∈ atrm" and "snd ` (set txs) ⊆ var" "fst ` (set txs) ⊆ atrm" and "distinct (map snd txs)" shows "psubst (eql t1 t2) txs = eql (psubstT t1 txs) (psubstT t2 txs)" proof (-) (*goal: ‹psubst (eql t1 t2) txs = eql (psubstT t1 txs) (psubstT t2 txs)›*) have t12: "fst ` (set txs) ⊆ trm" using assms (*‹t1 ∈ atrm› ‹t2 ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set (txs::('trm × 'var) list) ⊆ atrm› ‹distinct (map snd txs)›*) by auto define us where us: "us ≡ getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs)" have us_facts: "set us ⊆ var" "set us ∩ FvarsT t1 = {}" "set us ∩ FvarsT t2 = {}" "set us ∩ ⋃ (FvarsT ` (fst ` (set txs))) = {}" "set us ∩ snd ` (set txs) = {}" "length us = length txs" "distinct us" using assms(1-3) (*‹t1 ∈ atrm› ‹t2 ∈ atrm› ‹snd ` set txs ⊆ var›*) t12 (*‹fst ` set txs ⊆ trm›*) unfolding us (*goals: 1. ‹set (getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs)) ⊆ var› 2. ‹set (getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs)) ∩ FvarsT t1 = {}› 3. ‹set (getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs)) ∩ FvarsT t2 = {}› 4. ‹set (getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs)) ∩ ⋃ (FvarsT ` fst ` set txs) = {}› 5. ‹set (getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs)) ∩ snd ` set txs = {}› 6. ‹length (getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs)) = length txs› 7. ‹distinct (getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs))›*) using getFrN_Fvars[of "map snd txs" "map fst txs" "[eql t1 t2]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (map fst txs) ⊆ trm; set [eql t1 t2] ⊆ fmla; ?φ ∈ set [eql t1 t2]⟧ ⟹ set (getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs)) ∩ Fvars ?φ = {}›*) getFrN_FvarsT[of "map snd txs" "map fst txs" "[eql t1 t2]" _ "length txs"] (*‹⟦set (map snd (txs::('trm × 'var) list)) ⊆ (var::'var set); set (map fst txs) ⊆ (trm::'trm set); set [(eql::'trm ⇒ 'trm ⇒ 'fmla) (t1::'trm) (t2::'trm)] ⊆ (fmla::'fmla set); (?t::'trm) ∈ set (map fst txs)⟧ ⟹ set (getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs)) ∩ (FvarsT::'trm ⇒ 'var set) ?t = {}›*) getFrN_var[of "map snd txs" "map fst txs" "[eql t1 t2]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (map fst txs) ⊆ trm; set [eql t1 t2] ⊆ fmla; ?t ∈ set (map fst txs)⟧ ⟹ set (getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs)) ∩ set (map snd txs) = {}›*) getFrN_length[of "map snd txs" "map fst txs" "[eql t1 t2]" "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (map fst txs) ⊆ trm; set [eql t1 t2] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs)) = length txs›*) apply - (*top goal: ‹set (getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs)) ⊆ var› and 6 goals remain*) subgoal for by auto subgoal for by force subgoal for by force subgoal for by fastforce subgoal for by (fastforce simp: image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*)) (*goals: 1. ‹⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; ⋀φ. ⟦set (map snd txs) ⊆ var; set (map fst txs) ⊆ trm; set [eql t1 t2] ⊆ fmla; φ ∈ set [eql t1 t2]⟧ ⟹ set (getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs)) ∩ Fvars φ = {}; ⋀t. ⟦set (map snd txs) ⊆ var; set (map fst txs) ⊆ trm; set [eql t1 t2] ⊆ fmla; t ∈ set (map fst txs)⟧ ⟹ set (getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs)) ∩ FvarsT t = {}; ⋀t. ⟦set (map snd txs) ⊆ var; set (map fst txs) ⊆ trm; set [eql t1 t2] ⊆ fmla; t ∈ set (map fst txs)⟧ ⟹ set (getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs)) ∩ set (map snd txs) = {}; ⟦set (map snd txs) ⊆ var; set (map fst txs) ⊆ trm; set [eql t1 t2] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs)) = length txs⟧ ⟹ length (getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs)) = length txs› 2. ‹⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; ⋀φ. ⟦set (map snd txs) ⊆ var; set (map fst txs) ⊆ trm; set [eql t1 t2] ⊆ fmla; φ ∈ set [eql t1 t2]⟧ ⟹ set (getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs)) ∩ Fvars φ = {}; ⋀t. ⟦set (map snd txs) ⊆ var; set (map fst txs) ⊆ trm; set [eql t1 t2] ⊆ fmla; t ∈ set (map fst txs)⟧ ⟹ set (getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs)) ∩ FvarsT t = {}; ⋀t. ⟦set (map snd txs) ⊆ var; set (map fst txs) ⊆ trm; set [eql t1 t2] ⊆ fmla; t ∈ set (map fst txs)⟧ ⟹ set (getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs)) ∩ set (map snd txs) = {}; ⟦set (map snd txs) ⊆ var; set (map fst txs) ⊆ trm; set [eql t1 t2] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs)) = length txs⟧ ⟹ distinct (getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . define vs1 where vs1: "vs1 ≡ getFrN (map snd txs) (t1 # map fst txs) [] (length txs)" have vs1_facts: "set vs1 ⊆ var" "set vs1 ∩ FvarsT t1 = {}" "set vs1 ∩ ⋃ (FvarsT ` (fst ` (set txs))) = {}" "set vs1 ∩ snd ` (set txs) = {}" "length vs1 = length txs" "distinct vs1" using assms(1-3) (*‹t1 ∈ atrm› ‹t2 ∈ atrm› ‹snd ` set txs ⊆ var›*) t12 (*‹fst ` set txs ⊆ trm›*) unfolding vs1 (*goals: 1. ‹set (getFrN (map snd txs) (t1 # map fst txs) [] (length txs)) ⊆ var› 2. ‹set (getFrN (map snd txs) (t1 # map fst txs) [] (length txs)) ∩ FvarsT t1 = {}› 3. ‹set (getFrN (map snd txs) (t1 # map fst txs) [] (length txs)) ∩ ⋃ (FvarsT ` fst ` set txs) = {}› 4. ‹set (getFrN (map snd txs) (t1 # map fst txs) [] (length txs)) ∩ snd ` set txs = {}› 5. ‹length (getFrN (map snd txs) (t1 # map fst txs) [] (length txs)) = length txs› 6. ‹distinct (getFrN (map snd txs) (t1 # map fst txs) [] (length txs))›*) using getFrN_Fvars[of "map snd txs" "t1 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (t1 # map fst txs) ⊆ trm; set [] ⊆ fmla; ?φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (t1 # map fst txs) [] (length txs)) ∩ Fvars ?φ = {}›*) getFrN_FvarsT[of "map snd txs" "t1 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd (txs::('trm::type × 'var::type) list)) ⊆ (var::'var::type set); set ((t1::'trm::type) # map fst txs) ⊆ (trm::'trm::type set); set [] ⊆ (fmla::'fmla::type set); (?t::'trm::type) ∈ set (t1 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (t1 # map fst txs) [] (length txs)) ∩ (FvarsT::'trm::type ⇒ 'var::type set) ?t = {}›*) getFrN_var[of "map snd txs" "t1 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd (txs::('trm::type × 'var::type) list)) ⊆ (var::'var::type set); set ((t1::'trm::type) # map fst txs) ⊆ (trm::'trm::type set); set [] ⊆ (fmla::'fmla::type set); (?t::'trm::type) ∈ set (t1 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (t1 # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}›*) getFrN_length[of "map snd txs" "t1 # map fst txs" "[]" "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (t1 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (t1 # map fst txs) [] (length txs)) = length txs›*) apply - (*top goal: ‹set (getFrN (map snd txs) (t1 # map fst txs) [] (length txs)) ⊆ var› and 5 goals remain*) subgoal for by auto subgoal for by force subgoal for by auto subgoal for by force subgoal for by (fastforce simp: image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*)) by auto define vs2 where vs2: "vs2 ≡ getFrN (map snd txs) (t2 # map fst txs) [] (length txs)" have vs2_facts: "set vs2 ⊆ var" "set vs2 ∩ FvarsT t2 = {}" "set vs2 ∩ ⋃ (FvarsT ` (fst ` (set txs))) = {}" "set vs2 ∩ snd ` (set txs) = {}" "length vs2 = length txs" "distinct vs2" using assms(1-3) (*‹t1 ∈ atrm› ‹t2 ∈ atrm› ‹snd ` set txs ⊆ var›*) t12 (*‹fst ` set txs ⊆ trm›*) unfolding vs2 (*goals: 1. ‹set (getFrN (map snd txs) (t2 # map fst txs) [] (length txs)) ⊆ var› 2. ‹set (getFrN (map snd txs) (t2 # map fst txs) [] (length txs)) ∩ FvarsT t2 = {}› 3. ‹set (getFrN (map snd txs) (t2 # map fst txs) [] (length txs)) ∩ ⋃ (FvarsT ` fst ` set txs) = {}› 4. ‹set (getFrN (map snd txs) (t2 # map fst txs) [] (length txs)) ∩ snd ` set txs = {}› 5. ‹length (getFrN (map snd txs) (t2 # map fst txs) [] (length txs)) = length txs› 6. ‹distinct (getFrN (map snd txs) (t2 # map fst txs) [] (length txs))›*) using getFrN_Fvars[of "map snd txs" "t2 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (t2 # map fst txs) ⊆ trm; set [] ⊆ fmla; ?φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (t2 # map fst txs) [] (length txs)) ∩ Fvars ?φ = {}›*) getFrN_FvarsT[of "map snd txs" "t2 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (t2 # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (t2 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (t2 # map fst txs) [] (length txs)) ∩ FvarsT ?t = {}›*) getFrN_var[of "map snd txs" "t2 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd (txs::('trm::type × 'var::type) list)) ⊆ (var::'var::type set); set ((t2::'trm::type) # map fst txs) ⊆ (trm::'trm::type set); set [] ⊆ (fmla::'fmla::type set); (?t::'trm::type) ∈ set (t2 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (t2 # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}›*) getFrN_length[of "map snd txs" "t2 # map fst txs" "[]" "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (t2 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (t2 # map fst txs) [] (length txs)) = length txs›*) apply - (*top goal: ‹set (getFrN (map snd txs) (t2 # map fst txs) [] (length txs)) ⊆ var› and 5 goals remain*) subgoal for by auto subgoal for by force subgoal for by auto subgoal for by force subgoal for by (fastforce simp: image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*)) by auto let ?tus = "zip (map fst txs) us" let ?uxs = "zip (map Var us) (map snd txs)" let ?e = "rawpsubst (eql t1 t2) ?uxs" have e: "?e = eql (rawpsubstT t1 ?uxs) (rawpsubstT t2 ?uxs)" apply (rule rawpsubst_eql (*‹⟦(?t1.0::'trm) ∈ (trm::'trm set); (?t2.0::'trm) ∈ trm; snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubst ((eql::'trm ⇒ 'trm ⇒ 'fmla) ?t1.0 ?t2.0) ?txs = eql (rawpsubstT ?t1.0 ?txs) (rawpsubstT ?t2.0 ?txs)›*)) (*goal: ‹rawpsubst (eql t1 t2) (zip (map Var us) (map snd txs)) = eql (rawpsubstT t1 (zip (map Var us) (map snd txs))) (rawpsubstT t2 (zip (map Var us) (map snd txs)))›*) using assms (*‹t1 ∈ atrm› ‹(t2::'trm) ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹distinct (map snd txs)›*) us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT t1 = {}› ‹set us ∩ FvarsT t2 = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct us›*) apply - (*goals: 1. ‹⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ t1 ∈ trm› 2. ‹⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ t2 ∈ trm› 3. ‹⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ snd ` set (zip (map Var us) (map snd txs)) ⊆ var› 4. ‹⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ fst ` set (zip (map Var us) (map snd txs)) ⊆ trm› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*top goal: ‹⟦(t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ snd ` set (zip (map (Var::'var ⇒ 'trm) us) (map snd txs)) ⊆ var› and 1 goal remains*) apply (drule set_zip_rightD (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?y ∈ set ?ys›*)) (*top goal: ‹⋀a b. ⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ (⋃a∈set txs. FvarsT (fst a)) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; (a, b) ∈ set (zip (map Var us) (map snd txs))⟧ ⟹ b ∈ var› and 1 goal remains*) apply simp (*top goal: ‹⋀a b. ⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ (⋃a∈set txs. FvarsT (fst a)) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; b ∈ set (map snd txs)⟧ ⟹ b ∈ var› and 1 goal remains*) apply blast (*discuss goal 4*) apply ((auto)[1]) (*goal: ‹⟦(t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ fst ` set (zip (map (Var::'var ⇒ 'trm) us) (map snd txs)) ⊆ (trm::'trm set)›*) apply (drule set_zip_leftD (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs›*)) (*goal: ‹⋀a b. ⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ (⋃a∈set txs. FvarsT (fst a)) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; (a, b) ∈ set (zip (map Var us) (map snd txs))⟧ ⟹ a ∈ trm›*) apply simp (*goal: ‹⋀(a::'trm) b::'var. ⟦(t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ (⋃a::'trm × 'var∈set txs. FvarsT (fst a)) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; a ∈ set (map (Var::'var ⇒ 'trm) us)⟧ ⟹ a ∈ (trm::'trm set)›*) apply blast (*proven 4 subgoals*) . have 0: "rawpsubst ?e ?tus = eql (rawpsubstT (rawpsubstT t1 ?uxs) ?tus) (rawpsubstT (rawpsubstT t2 ?uxs) ?tus)" unfolding e (*goal: ‹rawpsubst (eql (rawpsubstT t1 (zip (map Var us) (map snd txs))) (rawpsubstT t2 (zip (map Var us) (map snd txs)))) (zip (map fst txs) us) = eql (rawpsubstT (rawpsubstT t1 (zip (map Var us) (map snd txs))) (zip (map fst txs) us)) (rawpsubstT (rawpsubstT t2 (zip (map Var us) (map snd txs))) (zip (map fst txs) us))›*) using assms (*‹(t1::'trm) ∈ atrm› ‹t2 ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹distinct (map snd txs)›*) us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT t1 = {}› ‹set us ∩ FvarsT t2 = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct us›*) apply (intro rawpsubst_eql (*‹⟦?t1.0 ∈ trm; ?t2.0 ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubst (eql ?t1.0 ?t2.0) ?txs = eql (rawpsubstT ?t1.0 ?txs) (rawpsubstT ?t2.0 ?txs)›*)) (*goal: ‹rawpsubst (eql (rawpsubstT t1 (zip (map Var us) (map snd txs))) (rawpsubstT t2 (zip (map Var us) (map snd txs)))) (zip (map fst txs) us) = eql (rawpsubstT (rawpsubstT t1 (zip (map Var us) (map snd txs))) (zip (map fst txs) us)) (rawpsubstT (rawpsubstT t2 (zip (map Var us) (map snd txs))) (zip (map fst txs) us))›*) subgoal for by (auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) subgoal for by (auto intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) subgoal for by (auto intro!: rawpsubstT (*‹⟦(?t::'trm::type) ∈ (trm::'trm::type set); snd ` set (?txs::('trm::type × 'var::type) list) ⊆ (var::'var::type set); fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x::?'a::type, ?y::?'b::type) ∈ set (zip (?xs::?'a::type list) (?ys::?'b::type list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) subgoal for by (fastforce intro!: rawpsubstT (*‹⟦(?t::'trm) ∈ (trm::'trm set); snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) . have 1: "rawpsubstT (rawpsubstT t1 ?uxs) ?tus = rawpsubstT (rawpsubstT t1 (zip (map Var vs1) (map snd txs))) (zip (map fst txs) vs1)" using assms (*‹t1 ∈ atrm› ‹(t2::'trm::type) ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹distinct (map snd txs)›*) us_facts (*‹set us ⊆ var› ‹set (us::'var list) ∩ (FvarsT::'trm ⇒ 'var set) (t1::'trm) = {}› ‹set us ∩ FvarsT t2 = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set (us::'var::type list) ∩ snd ` set (txs::('trm::type × 'var::type) list) = {}› ‹length us = length txs› ‹distinct us›*) vs1_facts (*‹set vs1 ⊆ var› ‹set vs1 ∩ FvarsT t1 = {}› ‹set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set vs1 ∩ snd ` set txs = {}› ‹length vs1 = length txs› ‹distinct vs1›*) apply (intro rawpsubstT_compose_freshVar2 (*‹⟦?r ∈ atrm; set ?ts ⊆ atrm; set ?xs ⊆ var; distinct ?xs; set ?us ⊆ var; distinct ?us; set ?us ∩ FvarsT ?r = {}; set ?us ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?us ∩ set ?xs = {}; set ?vs ⊆ var; distinct ?vs; set ?vs ∩ FvarsT ?r = {}; set ?vs ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?vs ∩ set ?xs = {}; length ?us = length ?xs; length ?vs = length ?xs; length ?ts = length ?xs⟧ ⟹ rawpsubstT (rawpsubstT ?r (zip (map Var ?us) ?xs)) (zip ?ts ?us) = rawpsubstT (rawpsubstT ?r (zip (map Var ?vs) ?xs)) (zip ?ts ?vs)›*)) (*goals: 1. ‹⟦(t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set (vs1::'var list) ⊆ var; set vs1 ∩ FvarsT t1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ t1 ∈ atrm› 2. ‹⟦(t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set (vs1::'var list) ⊆ var; set vs1 ∩ FvarsT t1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set (map fst txs) ⊆ atrm› 3. ‹⟦(t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set (vs1::'var list) ⊆ var; set vs1 ∩ FvarsT t1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set (map snd txs) ⊆ var› 4. ‹⟦(t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set (vs1::'var list) ⊆ var; set vs1 ∩ FvarsT t1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ distinct (map snd txs)› 5. ‹⟦(t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set (vs1::'var list) ⊆ var; set vs1 ∩ FvarsT t1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set us ⊆ var› 6. ‹⟦(t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set (vs1::'var list) ⊆ var; set vs1 ∩ FvarsT t1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ distinct us› 7. ‹⟦(t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set (vs1::'var list) ⊆ var; set vs1 ∩ FvarsT t1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set us ∩ FvarsT t1 = {}› 8. ‹⟦(t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set (vs1::'var list) ⊆ var; set vs1 ∩ FvarsT t1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set us ∩ ⋃ (FvarsT ` set (map fst txs)) = {}› 9. ‹⟦(t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set (vs1::'var list) ⊆ var; set vs1 ∩ FvarsT t1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set us ∩ set (map snd txs) = {}› 10. ‹⟦(t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set (vs1::'var list) ⊆ var; set vs1 ∩ FvarsT t1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set vs1 ⊆ var› 11. ‹⟦(t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set (vs1::'var list) ⊆ var; set vs1 ∩ FvarsT t1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ distinct vs1› 12. ‹⟦(t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set (vs1::'var list) ⊆ var; set vs1 ∩ FvarsT t1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set vs1 ∩ FvarsT t1 = {}› 13. ‹⟦(t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set (vs1::'var list) ⊆ var; set vs1 ∩ FvarsT t1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set vs1 ∩ ⋃ (FvarsT ` set (map fst txs)) = {}› 14. ‹⟦(t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set (vs1::'var list) ⊆ var; set vs1 ∩ FvarsT t1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set vs1 ∩ set (map snd txs) = {}› 15. ‹⟦(t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set (vs1::'var list) ⊆ var; set vs1 ∩ FvarsT t1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ length us = length (map snd txs)› 16. ‹⟦(t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set (vs1::'var list) ⊆ var; set vs1 ∩ FvarsT t1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ length vs1 = length (map snd txs)› 17. ‹⟦(t1::'trm) ∈ atrm; (t2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set (vs1::'var list) ⊆ var; set vs1 ∩ FvarsT t1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ length (map fst txs) = length (map snd txs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*discuss goal 9*) apply ((auto)[1]) (*discuss goal 10*) apply ((auto)[1]) (*discuss goal 11*) apply ((auto)[1]) (*discuss goal 12*) apply ((auto)[1]) (*discuss goal 13*) apply ((auto)[1]) (*discuss goal 14*) apply ((auto)[1]) (*discuss goal 15*) apply ((auto)[1]) (*discuss goal 16*) apply ((auto)[1]) (*discuss goal 17*) apply ((auto)[1]) (*proven 17 subgoals*) . have 2: "rawpsubstT (rawpsubstT t2 ?uxs) ?tus = rawpsubstT (rawpsubstT t2 (zip (map Var vs2) (map snd txs))) (zip (map fst txs) vs2)" using assms (*‹t1 ∈ atrm› ‹t2 ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹distinct (map snd txs)›*) us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT t1 = {}› ‹set us ∩ FvarsT t2 = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set (us::'var::type list) ∩ snd ` set (txs::('trm::type × 'var::type) list) = {}› ‹length us = length txs› ‹distinct us›*) vs2_facts (*‹set vs2 ⊆ var› ‹set vs2 ∩ FvarsT t2 = {}› ‹set (vs2::'var list) ∩ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set (txs::('trm × 'var) list)) = {}› ‹set vs2 ∩ snd ` set txs = {}› ‹length vs2 = length txs› ‹distinct (vs2::'var list)›*) apply (intro rawpsubstT_compose_freshVar2 (*‹⟦?r ∈ atrm; set ?ts ⊆ atrm; set ?xs ⊆ var; distinct ?xs; set ?us ⊆ var; distinct ?us; set ?us ∩ FvarsT ?r = {}; set ?us ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?us ∩ set ?xs = {}; set ?vs ⊆ var; distinct ?vs; set ?vs ∩ FvarsT ?r = {}; set ?vs ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?vs ∩ set ?xs = {}; length ?us = length ?xs; length ?vs = length ?xs; length ?ts = length ?xs⟧ ⟹ rawpsubstT (rawpsubstT ?r (zip (map Var ?us) ?xs)) (zip ?ts ?us) = rawpsubstT (rawpsubstT ?r (zip (map Var ?vs) ?xs)) (zip ?ts ?vs)›*)) (*goals: 1. ‹⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT t2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ t2 ∈ atrm› 2. ‹⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT t2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set (map fst txs) ⊆ atrm› 3. ‹⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT t2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set (map snd txs) ⊆ var› 4. ‹⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT t2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ distinct (map snd txs)› 5. ‹⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT t2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set us ⊆ var› 6. ‹⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT t2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ distinct us› 7. ‹⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT t2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set us ∩ FvarsT t2 = {}› 8. ‹⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT t2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set us ∩ ⋃ (FvarsT ` set (map fst txs)) = {}› 9. ‹⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT t2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set us ∩ set (map snd txs) = {}› 10. ‹⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT t2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set vs2 ⊆ var› 11. ‹⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT t2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ distinct vs2› 12. ‹⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT t2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set vs2 ∩ FvarsT t2 = {}› 13. ‹⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT t2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set vs2 ∩ ⋃ (FvarsT ` set (map fst txs)) = {}› 14. ‹⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT t2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set vs2 ∩ set (map snd txs) = {}› 15. ‹⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT t2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ length us = length (map snd txs)› 16. ‹⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT t2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ length vs2 = length (map snd txs)› 17. ‹⟦t1 ∈ atrm; t2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT t1 = {}; set us ∩ FvarsT t2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT t2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ length (map fst txs) = length (map snd txs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*discuss goal 9*) apply ((auto)[1]) (*discuss goal 10*) apply ((auto)[1]) (*discuss goal 11*) apply ((auto)[1]) (*discuss goal 12*) apply ((auto)[1]) (*discuss goal 13*) apply ((auto)[1]) (*discuss goal 14*) apply ((auto)[1]) (*discuss goal 15*) apply ((auto)[1]) (*discuss goal 16*) apply ((auto)[1]) (*discuss goal 17*) apply ((auto)[1]) (*proven 17 subgoals*) . show "?thesis" (*goal: ‹psubst (eql t1 t2) txs = eql (psubstT t1 txs) (psubstT t2 txs)›*) unfolding psubstT_def psubst_def (*goal: ‹(let xs::'var::type list = map snd (txs::('trm::type × 'var::type) list); ts::'trm::type list = map fst txs; us::'var::type list = getFrN xs ts [(eql::'trm::type ⇒ 'trm::type ⇒ 'fmla::type) (t1::'trm::type) (t2::'trm::type)] (length xs) in rawpsubst (rawpsubst (eql t1 t2) (zip (map (Var::'var::type ⇒ 'trm::type) us) xs)) (zip ts us)) = eql (let xs::'var::type list = map snd txs; ts::'trm::type list = map fst txs; us::'var::type list = getFrN xs (t1 # ts) [] (length xs) in rawpsubstT (rawpsubstT t1 (zip (map Var us) xs)) (zip ts us)) (let xs::'var::type list = map snd txs; ts::'trm::type list = map fst txs; us::'var::type list = getFrN xs (t2 # ts) [] (length xs) in rawpsubstT (rawpsubstT t2 (zip (map Var us) xs)) (zip ts us))›*) by (simp add: Let_def (*‹Let ?s ?f ≡ ?f ?s›*) us[symmetric] (*‹getFrN (map snd txs) (map fst txs) [eql t1 t2] (length txs) ≡ us›*) vs1[symmetric] (*‹getFrN (map snd txs) (t1 # map fst txs) [] (length txs) ≡ vs1›*) vs2[symmetric] (*‹getFrN (map snd txs) (t2 # map fst txs) [] (length txs) ≡ vs2›*) 0 (*‹rawpsubst (rawpsubst (eql t1 t2) (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = eql (rawpsubstT (rawpsubstT t1 (zip (map Var us) (map snd txs))) (zip (map fst txs) us)) (rawpsubstT (rawpsubstT t2 (zip (map Var us) (map snd txs))) (zip (map fst txs) us))›*) 1 (*‹rawpsubstT (rawpsubstT t1 (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT (rawpsubstT t1 (zip (map Var vs1) (map snd txs))) (zip (map fst txs) vs1)›*) 2 (*‹rawpsubstT (rawpsubstT t2 (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT (rawpsubstT t2 (zip (map Var vs2) (map snd txs))) (zip (map fst txs) vs2)›*)) qed (* psubst versus the exists-unique quantifier: *) lemma psubst_exu[simp]: assumes "φ ∈ fmla" "x ∈ var" "snd ` set txs ⊆ var" "fst ` set txs ⊆ atrm" "x ∉ snd ` set txs" "x ∉ (⋃t ∈ fst ` set txs. FvarsT t)" "distinct (map snd txs)" shows "psubst (exu x φ) txs = exu x (psubst φ txs)" proof (-) (*goal: ‹psubst (exu x φ) txs = exu x (psubst φ txs)›*) have f: "fst ` set txs ⊆ trm" using assms (*‹φ ∈ fmla› ‹x ∈ var› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹(x::'var) ∉ snd ` set (txs::('trm × 'var) list)› ‹x ∉ ⋃ (FvarsT ` fst ` set txs)› ‹distinct (map snd txs)›*) by (meson atrm_trm (*‹atrm ⊆ trm›*) subset_trans (*‹⟦?A ⊆ ?B; ?B ⊆ ?C⟧ ⟹ ?A ⊆ ?C›*)) note assms1 = assms(1-3) (*‹φ ∈ fmla› ‹(x::'var) ∈ (var::'var set)› ‹snd ` set txs ⊆ var›*) assms(5-7) (*‹(x::'var) ∉ snd ` set (txs::('trm × 'var) list)› ‹x ∉ ⋃ (FvarsT ` fst ` set txs)› ‹distinct (map snd txs)›*) f (*‹fst ` set txs ⊆ trm›*) define u where u: "u ≡ getFr (x # map snd txs) (map fst txs) [φ]" have u_facts: "u ∈ var" "u ≠ x" "u ∉ snd ` set txs" "u ∉ (⋃t ∈ fst ` set txs. FvarsT t)" "u ∉ Fvars φ" unfolding u (*goals: 1. ‹getFr (x # map snd txs) (map fst txs) [φ] ∈ var› 2. ‹getFr (x # map snd txs) (map fst txs) [φ] ≠ x› 3. ‹getFr (x # map snd txs) (map fst txs) [φ] ∉ snd ` set txs› 4. ‹getFr (x # map snd txs) (map fst txs) [φ] ∉ ⋃ (FvarsT ` fst ` set txs)› 5. ‹getFr (x # map snd txs) (map fst txs) [φ] ∉ Fvars φ›*) using f (*‹fst ` set txs ⊆ trm›*) getFr_FvarsT_Fvars[of "x # map snd txs" "map fst txs" "[φ]"] (*‹⟦set (x # map snd txs) ⊆ var; set (map fst txs) ⊆ trm; set [φ] ⊆ fmla⟧ ⟹ getFr (x # map snd txs) (map fst txs) [φ] ∈ var ∧ getFr (x # map snd txs) (map fst txs) [φ] ∉ set (x # map snd txs) ∧ (?t ∈ set (map fst txs) ⟶ getFr (x # map snd txs) (map fst txs) [φ] ∉ FvarsT ?t) ∧ (?φ ∈ set [φ] ⟶ getFr (x # map snd txs) (map fst txs) [φ] ∉ Fvars ?φ)›*) apply - (*goals: 1. ‹⟦fst ` set txs ⊆ trm; ⋀t φ'. ⟦set (x # map snd txs) ⊆ var; set (map fst txs) ⊆ trm; set [φ] ⊆ fmla⟧ ⟹ getFr (x # map snd txs) (map fst txs) [φ] ∈ var ∧ getFr (x # map snd txs) (map fst txs) [φ] ∉ set (x # map snd txs) ∧ (t ∈ set (map fst txs) ⟶ getFr (x # map snd txs) (map fst txs) [φ] ∉ FvarsT t) ∧ (φ' ∈ set [φ] ⟶ getFr (x # map snd txs) (map fst txs) [φ] ∉ Fvars φ')⟧ ⟹ getFr (x # map snd txs) (map fst txs) [φ] ∈ var› 2. ‹⟦fst ` set txs ⊆ trm; ⋀t φ'. ⟦set (x # map snd txs) ⊆ var; set (map fst txs) ⊆ trm; set [φ] ⊆ fmla⟧ ⟹ getFr (x # map snd txs) (map fst txs) [φ] ∈ var ∧ getFr (x # map snd txs) (map fst txs) [φ] ∉ set (x # map snd txs) ∧ (t ∈ set (map fst txs) ⟶ getFr (x # map snd txs) (map fst txs) [φ] ∉ FvarsT t) ∧ (φ' ∈ set [φ] ⟶ getFr (x # map snd txs) (map fst txs) [φ] ∉ Fvars φ')⟧ ⟹ getFr (x # map snd txs) (map fst txs) [φ] ≠ x› 3. ‹⟦fst ` set txs ⊆ trm; ⋀t φ'. ⟦set (x # map snd txs) ⊆ var; set (map fst txs) ⊆ trm; set [φ] ⊆ fmla⟧ ⟹ getFr (x # map snd txs) (map fst txs) [φ] ∈ var ∧ getFr (x # map snd txs) (map fst txs) [φ] ∉ set (x # map snd txs) ∧ (t ∈ set (map fst txs) ⟶ getFr (x # map snd txs) (map fst txs) [φ] ∉ FvarsT t) ∧ (φ' ∈ set [φ] ⟶ getFr (x # map snd txs) (map fst txs) [φ] ∉ Fvars φ')⟧ ⟹ getFr (x # map snd txs) (map fst txs) [φ] ∉ snd ` set txs› 4. ‹⟦fst ` set txs ⊆ trm; ⋀t φ'. ⟦set (x # map snd txs) ⊆ var; set (map fst txs) ⊆ trm; set [φ] ⊆ fmla⟧ ⟹ getFr (x # map snd txs) (map fst txs) [φ] ∈ var ∧ getFr (x # map snd txs) (map fst txs) [φ] ∉ set (x # map snd txs) ∧ (t ∈ set (map fst txs) ⟶ getFr (x # map snd txs) (map fst txs) [φ] ∉ FvarsT t) ∧ (φ' ∈ set [φ] ⟶ getFr (x # map snd txs) (map fst txs) [φ] ∉ Fvars φ')⟧ ⟹ getFr (x # map snd txs) (map fst txs) [φ] ∉ ⋃ (FvarsT ` fst ` set txs)› 5. ‹⟦fst ` set txs ⊆ trm; ⋀t φ'. ⟦set (x # map snd txs) ⊆ var; set (map fst txs) ⊆ trm; set [φ] ⊆ fmla⟧ ⟹ getFr (x # map snd txs) (map fst txs) [φ] ∈ var ∧ getFr (x # map snd txs) (map fst txs) [φ] ∉ set (x # map snd txs) ∧ (t ∈ set (map fst txs) ⟶ getFr (x # map snd txs) (map fst txs) [φ] ∉ FvarsT t) ∧ (φ' ∈ set [φ] ⟶ getFr (x # map snd txs) (map fst txs) [φ] ∉ Fvars φ')⟧ ⟹ getFr (x # map snd txs) (map fst txs) [φ] ∉ Fvars φ› discuss goal 1*) apply ((auto simp: assms (*‹φ ∈ fmla› ‹x ∈ var› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹x ∉ snd ` set txs› ‹x ∉ ⋃ (FvarsT ` fst ` set txs)› ‹distinct (map snd txs)›*))[1]) (*discuss goal 2*) apply ((auto simp: assms (*‹(φ::'fmla) ∈ (fmla::'fmla set)› ‹(x::'var) ∈ (var::'var set)› ‹snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set)› ‹fst ` set (txs::('trm × 'var) list) ⊆ atrm› ‹(x::'var) ∉ snd ` set (txs::('trm × 'var) list)› ‹(x::'var) ∉ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set (txs::('trm × 'var) list))› ‹distinct (map snd (txs::('trm × 'var) list))›*))[1]) (*discuss goal 3*) apply ((auto simp: assms (*‹φ ∈ fmla› ‹x ∈ var› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹x ∉ snd ` set txs› ‹x ∉ ⋃ (FvarsT ` fst ` set txs)› ‹distinct (map snd txs)›*))[1]) (*discuss goal 4*) apply ((auto simp: assms (*‹φ ∈ fmla› ‹x ∈ var› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹x ∉ snd ` set txs› ‹x ∉ ⋃ (FvarsT ` fst ` set txs)› ‹distinct (map snd txs)›*))[1]) (*discuss goal 5*) apply ((auto simp: assms (*‹(φ::'fmla) ∈ (fmla::'fmla set)› ‹(x::'var) ∈ (var::'var set)› ‹snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set)› ‹fst ` set (txs::('trm × 'var) list) ⊆ atrm› ‹(x::'var) ∉ snd ` set (txs::('trm × 'var) list)› ‹(x::'var) ∉ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set (txs::('trm × 'var) list))› ‹distinct (map snd (txs::('trm × 'var) list))›*))[1]) (*proven 5 subgoals*) . hence [simp]: "psubst (subst φ (Var u) x) txs = subst (psubst φ txs) (Var u) x" using assms (*‹(φ::'fmla) ∈ (fmla::'fmla set)› ‹x ∈ var› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹(x::'var::type) ∉ snd ` set (txs::('trm::type × 'var::type) list)› ‹x ∉ ⋃ (FvarsT ` fst ` set txs)› ‹distinct (map snd txs)›*) apply (intro psubst_subst_fresh_switch (*‹⟦?φ ∈ fmla; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm; ∀x∈snd ` set ?txs. x ∉ FvarsT ?s; ∀t∈fst ` set ?txs. ?y ∉ FvarsT t; distinct (map snd ?txs); ?s ∈ trm; ?y ∈ var; ?y ∉ snd ` set ?txs⟧ ⟹ psubst (subst ?φ ?s ?y) ?txs = subst (psubst ?φ ?txs) ?s ?y›*) f (*‹fst ` set txs ⊆ trm›*)) (*goals: 1. ‹⟦u ∈ var; u ≠ x; u ∉ snd ` set txs; u ∉ ⋃ (FvarsT ` fst ` set txs); u ∉ Fvars φ; φ ∈ fmla; x ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; x ∉ ⋃ (FvarsT ` fst ` set txs); distinct (map snd txs)⟧ ⟹ φ ∈ fmla› 2. ‹⟦u ∈ var; u ≠ x; u ∉ snd ` set txs; u ∉ ⋃ (FvarsT ` fst ` set txs); u ∉ Fvars φ; φ ∈ fmla; x ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; x ∉ ⋃ (FvarsT ` fst ` set txs); distinct (map snd txs)⟧ ⟹ snd ` set txs ⊆ var› 3. ‹⟦u ∈ var; u ≠ x; u ∉ snd ` set txs; u ∉ ⋃ (FvarsT ` fst ` set txs); u ∉ Fvars φ; φ ∈ fmla; x ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; x ∉ ⋃ (FvarsT ` fst ` set txs); distinct (map snd txs)⟧ ⟹ ∀x∈snd ` set txs. x ∉ FvarsT (Var u)› 4. ‹⟦u ∈ var; u ≠ x; u ∉ snd ` set txs; u ∉ ⋃ (FvarsT ` fst ` set txs); u ∉ Fvars φ; φ ∈ fmla; x ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; x ∉ ⋃ (FvarsT ` fst ` set txs); distinct (map snd txs)⟧ ⟹ ∀t∈fst ` set txs. x ∉ FvarsT t› 5. ‹⟦u ∈ var; u ≠ x; u ∉ snd ` set txs; u ∉ ⋃ (FvarsT ` fst ` set txs); u ∉ Fvars φ; φ ∈ fmla; x ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; x ∉ ⋃ (FvarsT ` fst ` set txs); distinct (map snd txs)⟧ ⟹ distinct (map snd txs)› 6. ‹⟦u ∈ var; u ≠ x; u ∉ snd ` set txs; u ∉ ⋃ (FvarsT ` fst ` set txs); u ∉ Fvars φ; φ ∈ fmla; x ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; x ∉ ⋃ (FvarsT ` fst ` set txs); distinct (map snd txs)⟧ ⟹ Var u ∈ trm› 7. ‹⟦u ∈ var; u ≠ x; u ∉ snd ` set txs; u ∉ ⋃ (FvarsT ` fst ` set txs); u ∉ Fvars φ; φ ∈ fmla; x ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; x ∉ ⋃ (FvarsT ` fst ` set txs); distinct (map snd txs)⟧ ⟹ x ∈ var› 8. ‹⟦u ∈ var; u ≠ x; u ∉ snd ` set txs; u ∉ ⋃ (FvarsT ` fst ` set txs); u ∉ Fvars φ; φ ∈ fmla; x ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; x ∉ ⋃ (FvarsT ` fst ` set txs); distinct (map snd txs)⟧ ⟹ x ∉ snd ` set txs› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*proven 8 subgoals*) . show "?thesis" (*goal: ‹psubst (exu x φ) txs = exu x (psubst φ txs)›*) using f (*‹fst ` set txs ⊆ trm›*) assms (*‹φ ∈ fmla› ‹x ∈ var› ‹snd ` set (txs::('trm::type × 'var::type) list) ⊆ (var::'var::type set)› ‹fst ` set txs ⊆ atrm› ‹x ∉ snd ` set txs› ‹x ∉ ⋃ (FvarsT ` fst ` set txs)› ‹distinct (map snd txs)›*) u_facts (*‹u ∈ var› ‹u ≠ x› ‹u ∉ snd ` set txs› ‹(u::'var) ∉ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set (txs::('trm × 'var) list))› ‹(u::'var) ∉ (Fvars::'fmla ⇒ 'var set) (φ::'fmla)›*) apply (subst exu_def_var[of _ u "psubst φ txs"] (*‹⟦?x ∈ var; u ∈ var; u ≠ ?x; u ∉ Fvars (psubst φ txs); psubst φ txs ∈ fmla⟧ ⟹ exu ?x (psubst φ txs) = cnj (exi ?x (psubst φ txs)) (exi u (all ?x (imp (psubst φ txs) (eql (Var ?x) (Var u)))))›*)) (*goals: 1. ‹⟦fst ` set txs ⊆ trm; φ ∈ fmla; x ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; x ∉ ⋃ (FvarsT ` fst ` set txs); distinct (map snd txs); u ∈ var; u ≠ x; u ∉ snd ` set txs; u ∉ ⋃ (FvarsT ` fst ` set txs); u ∉ Fvars φ⟧ ⟹ x ∈ var› 2. ‹⟦fst ` set txs ⊆ trm; φ ∈ fmla; x ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; x ∉ ⋃ (FvarsT ` fst ` set txs); distinct (map snd txs); u ∈ var; u ≠ x; u ∉ snd ` set txs; u ∉ ⋃ (FvarsT ` fst ` set txs); u ∉ Fvars φ⟧ ⟹ u ∈ var› 3. ‹⟦fst ` set txs ⊆ trm; φ ∈ fmla; x ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; x ∉ ⋃ (FvarsT ` fst ` set txs); distinct (map snd txs); u ∈ var; u ≠ x; u ∉ snd ` set txs; u ∉ ⋃ (FvarsT ` fst ` set txs); u ∉ Fvars φ⟧ ⟹ u ≠ x› 4. ‹⟦fst ` set txs ⊆ trm; φ ∈ fmla; x ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; x ∉ ⋃ (FvarsT ` fst ` set txs); distinct (map snd txs); u ∈ var; u ≠ x; u ∉ snd ` set txs; u ∉ ⋃ (FvarsT ` fst ` set txs); u ∉ Fvars φ⟧ ⟹ u ∉ Fvars (psubst φ txs)› 5. ‹⟦fst ` set txs ⊆ trm; φ ∈ fmla; x ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; x ∉ ⋃ (FvarsT ` fst ` set txs); distinct (map snd txs); u ∈ var; u ≠ x; u ∉ snd ` set txs; u ∉ ⋃ (FvarsT ` fst ` set txs); u ∉ Fvars φ⟧ ⟹ psubst φ txs ∈ fmla› 6. ‹⟦fst ` set txs ⊆ trm; φ ∈ fmla; x ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; x ∉ ⋃ (FvarsT ` fst ` set txs); distinct (map snd txs); u ∈ var; u ≠ x; u ∉ snd ` set txs; u ∉ ⋃ (FvarsT ` fst ` set txs); u ∉ Fvars φ⟧ ⟹ psubst (exu x φ) txs = cnj (exi x (psubst φ txs)) (exi u (all x (imp (psubst φ txs) (eql (Var x) (Var u)))))› discuss goal 1*) apply ((auto dest!: in_Fvars_psubstD (*‹⟦?y ∈ Fvars (psubst ?φ ?txs); ?φ ∈ fmla; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm; distinct (map snd ?txs)⟧ ⟹ ?y ∈ Fvars ?φ - snd ` set ?txs ∪ ⋃ {if x ∈ Fvars ?φ then FvarsT t else {} |t x. (t, x) ∈ set ?txs}›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) simp: exu_def_var[of _ u] (*‹⟦?x ∈ var; u ∈ var; u ≠ ?x; u ∉ Fvars ?φ; ?φ ∈ fmla⟧ ⟹ exu ?x ?φ = cnj (exi ?x ?φ) (exi u (all ?x (imp ?φ (eql (Var ?x) (Var u)))))›*))[1]) (*discuss goal 2*) apply ((auto dest!: in_Fvars_psubstD (*‹⟦?y ∈ Fvars (psubst ?φ ?txs); ?φ ∈ fmla; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm; distinct (map snd ?txs)⟧ ⟹ ?y ∈ Fvars ?φ - snd ` set ?txs ∪ ⋃ {if x ∈ Fvars ?φ then FvarsT t else {} |t x. (t, x) ∈ set ?txs}›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) simp: exu_def_var[of _ u] (*‹⟦?x ∈ var; u ∈ var; u ≠ ?x; u ∉ Fvars ?φ; ?φ ∈ fmla⟧ ⟹ exu ?x ?φ = cnj (exi ?x ?φ) (exi u (all ?x (imp ?φ (eql (Var ?x) (Var u)))))›*))[1]) (*discuss goal 3*) apply ((auto dest!: in_Fvars_psubstD (*‹⟦?y ∈ Fvars (psubst ?φ ?txs); ?φ ∈ fmla; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm; distinct (map snd ?txs)⟧ ⟹ ?y ∈ Fvars ?φ - snd ` set ?txs ∪ ⋃ {if x ∈ Fvars ?φ then FvarsT t else {} |t x. (t, x) ∈ set ?txs}›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) simp: exu_def_var[of _ u] (*‹⟦?x ∈ var; u ∈ var; u ≠ ?x; u ∉ Fvars ?φ; ?φ ∈ fmla⟧ ⟹ exu ?x ?φ = cnj (exi ?x ?φ) (exi u (all ?x (imp ?φ (eql (Var ?x) (Var u)))))›*))[1]) (*discuss goal 4*) apply ((auto dest!: in_Fvars_psubstD (*‹⟦?y ∈ Fvars (psubst ?φ ?txs); ?φ ∈ fmla; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm; distinct (map snd ?txs)⟧ ⟹ ?y ∈ Fvars ?φ - snd ` set ?txs ∪ ⋃ {if x ∈ Fvars ?φ then FvarsT t else {} |t x. (t, x) ∈ set ?txs}›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) simp: exu_def_var[of _ u] (*‹⟦?x ∈ var; u ∈ var; u ≠ ?x; u ∉ Fvars ?φ; ?φ ∈ fmla⟧ ⟹ exu ?x ?φ = cnj (exi ?x ?φ) (exi u (all ?x (imp ?φ (eql (Var ?x) (Var u)))))›*))[1]) (*discuss goal 5*) apply ((auto dest!: in_Fvars_psubstD (*‹⟦?y ∈ Fvars (psubst ?φ ?txs); ?φ ∈ fmla; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm; distinct (map snd ?txs)⟧ ⟹ ?y ∈ Fvars ?φ - snd ` set ?txs ∪ ⋃ {if x ∈ Fvars ?φ then FvarsT t else {} |t x. (t, x) ∈ set ?txs}›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) simp: exu_def_var[of _ u] (*‹⟦?x ∈ var; u ∈ var; u ≠ ?x; u ∉ Fvars ?φ; ?φ ∈ fmla⟧ ⟹ exu ?x ?φ = cnj (exi ?x ?φ) (exi u (all ?x (imp ?φ (eql (Var ?x) (Var u)))))›*))[1]) (*discuss goal 6*) apply ((auto dest!: in_Fvars_psubstD (*‹⟦?y ∈ Fvars (psubst ?φ ?txs); ?φ ∈ fmla; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm; distinct (map snd ?txs)⟧ ⟹ ?y ∈ Fvars ?φ - snd ` set ?txs ∪ ⋃ {if x ∈ Fvars ?φ then FvarsT t else {} |t x. (t, x) ∈ set ?txs}›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) simp: exu_def_var[of _ u] (*‹⟦?x ∈ var; u ∈ var; u ≠ ?x; u ∉ Fvars ?φ; ?φ ∈ fmla⟧ ⟹ exu ?x ?φ = cnj (exi ?x ?φ) (exi u (all ?x (imp ?φ (eql (Var ?x) (Var u)))))›*))[1]) (*proven 6 subgoals*) . qed (* psubst versus the arithmetic trm constructors: *) (* We already have: *) thm psubstT_Var_not[no_vars] lemma rawpsubstT_Var_in: assumes "snd ` (set txs) ⊆ var" "fst ` (set txs) ⊆ trm" and "distinct (map snd txs)" and "(s,y) ∈ set txs" and "⋀ i j. i < j ⟹ j < length txs ⟹ snd (txs!j) ∉ FvarsT (fst (txs!i))" shows "rawpsubstT (Var y) txs = s" using assms (*‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ trm› ‹distinct (map snd txs)› ‹(s, y) ∈ set txs› ‹⟦?i < ?j; ?j < length txs⟧ ⟹ snd (txs ! ?j) ∉ FvarsT (fst (txs ! ?i))›*) proof (induction txs) (*goals: 1. ‹⟦snd ` set [] ⊆ var; fst ` set [] ⊆ trm; distinct (map snd []); (s, y) ∈ set []; ⋀i j. ⟦i < j; j < length []⟧ ⟹ snd ([] ! j) ∉ FvarsT (fst ([] ! i))⟧ ⟹ rawpsubstT (Var y) [] = s› 2. ‹⋀a txs. ⟦⟦snd ` set txs ⊆ var; fst ` set txs ⊆ trm; distinct (map snd txs); (s, y) ∈ set txs; ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i))⟧ ⟹ rawpsubstT (Var y) txs = s; snd ` set (a # txs) ⊆ var; fst ` set (a # txs) ⊆ trm; distinct (map snd (a # txs)); (s, y) ∈ set (a # txs); ⋀i j. ⟦i < j; j < length (a # txs)⟧ ⟹ snd ((a # txs) ! j) ∉ FvarsT (fst ((a # txs) ! i))⟧ ⟹ rawpsubstT (Var y) (a # txs) = s›*) case (Cons tx txs) (*‹⟦snd ` set txs ⊆ var; fst ` set txs ⊆ trm; distinct (map snd txs); (s, y) ∈ set txs; ⋀i j. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ FvarsT (fst (txs ! i))⟧ ⟹ rawpsubstT (Var y) txs = s› ‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ trm› ‹distinct (map snd (tx # txs))› ‹(s, y) ∈ set (tx # txs)› ‹⟦?i < ?j; ?j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! ?j) ∉ FvarsT (fst ((tx # txs) ! ?i))›*) obtain t and x where tx[simp]: "tx = (t,x)" (*goal: ‹(⋀t x. tx = (t, x) ⟹ thesis) ⟹ thesis›*) apply (cases tx) (*goal: ‹(⋀t x. tx = (t, x) ⟹ thesis) ⟹ thesis›*) by auto have 00: "FvarsT t ∩ snd ` set txs = {}" using Cons.prems(5)[of 0 "Suc _"] (*‹⟦0 < Suc ?uu3; Suc ?uu3 < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! Suc ?uu3) ∉ FvarsT (fst ((tx # txs) ! 0))›*) by (auto simp: set_conv_nth (*‹set (?xs::?'a::type list) = {?xs ! i |i::nat. i < length ?xs}›*)) have "rawpsubstT (substT (Var y) t x) txs = s" proof (cases "y = x") (*goals: 1. ‹(y::'var) = (x::'var) ⟹ rawpsubstT ((substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) ((Var::'var ⇒ 'trm) y) (t::'trm) x) (txs::('trm × 'var) list) = (s::'trm)› 2. ‹(y::'var) ≠ (x::'var) ⟹ rawpsubstT ((substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) ((Var::'var ⇒ 'trm) y) (t::'trm) x) (txs::('trm × 'var) list) = (s::'trm)›*) case [simp]: True (*‹(y::'var) = (x::'var)›*) hence [simp]: "s = t" using ‹distinct (map snd (tx # txs))› (*‹distinct (map snd (tx # txs))›*) ‹(s, y) ∈ set (tx # txs)› (*‹(s, y) ∈ set (tx # txs)›*) using image_iff (*‹((?z::?'a::type) ∈ (?f::?'b::type ⇒ ?'a::type) ` (?A::?'b::type set)) = (∃x::?'b::type∈?A. ?z = ?f x)›*) by fastforce show "?thesis" (*goal: ‹rawpsubstT (substT (Var y) t x) txs = s›*) using Cons.prems (*‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ trm› ‹distinct (map snd (tx # txs))› ‹(s::'trm::type, y::'var::type) ∈ set ((tx::'trm::type × 'var::type) # (txs::('trm::type × 'var::type) list))› ‹⟦?i < ?j; ?j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! ?j) ∉ FvarsT (fst ((tx # txs) ! ?i))›*) "00" (*‹FvarsT t ∩ snd ` set txs = {}›*) by auto next (*goal: ‹y ≠ x ⟹ rawpsubstT (substT (Var y) t x) txs = s›*) case False (*‹y ≠ x›*) hence [simp]: "substT (Var y) t x = Var y" using Cons.prems (*‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ trm› ‹distinct (map snd (tx # txs))› ‹(s, y) ∈ set (tx # txs)› ‹⟦?i < ?j; ?j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! ?j) ∉ FvarsT (fst ((tx # txs) ! ?i))›*) apply (intro substT_notIn (*‹⟦?x ∈ var; ?t1.0 ∈ trm; ?t2.0 ∈ trm; ?x ∉ FvarsT ?t1.0⟧ ⟹ substT ?t1.0 ?t2.0 ?x = ?t1.0›*)) (*goals: 1. ‹⟦y ≠ x; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ trm; distinct (map snd (tx # txs)); (s, y) ∈ set (tx # txs); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i))⟧ ⟹ x ∈ var› 2. ‹⟦y ≠ x; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ trm; distinct (map snd (tx # txs)); (s, y) ∈ set (tx # txs); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i))⟧ ⟹ Var y ∈ trm› 3. ‹⟦y ≠ x; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ trm; distinct (map snd (tx # txs)); (s, y) ∈ set (tx # txs); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i))⟧ ⟹ t ∈ trm› 4. ‹⟦y ≠ x; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ trm; distinct (map snd (tx # txs)); (s, y) ∈ set (tx # txs); ⋀i j. ⟦i < j; j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! j) ∉ FvarsT (fst ((tx # txs) ! i))⟧ ⟹ x ∉ FvarsT (Var y)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . have "rawpsubstT (Var y) txs = s" using Cons.prems (*‹snd ` set (tx # txs) ⊆ var› ‹fst ` set (tx # txs) ⊆ trm› ‹distinct (map snd (tx # txs))› ‹(s, y) ∈ set (tx # txs)› ‹⟦?i < ?j; ?j < length (tx # txs)⟧ ⟹ snd ((tx # txs) ! ?j) ∉ FvarsT (fst ((tx # txs) ! ?i))›*) apply (intro Cons.IH (*‹⟦snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ (trm::'trm set); distinct (map snd txs); (s::'trm, y::'var) ∈ set txs; ⋀(i::nat) j::nat. ⟦i < j; j < length txs⟧ ⟹ snd (txs ! j) ∉ (FvarsT::'trm ⇒ 'var set) (fst (txs ! i))⟧ ⟹ rawpsubstT ((Var::'var ⇒ 'trm) y) txs = s›*)) (*goal: ‹rawpsubstT (Var y) txs = s›*) subgoal for by auto subgoal for by auto subgoal for by auto subgoal for using False (*‹y ≠ x›*) by auto subgoal for by (metis length_Cons (*‹length (?x # ?xs) = Suc (length ?xs)›*) less_Suc_eq_0_disj (*‹(?m < Suc ?n) = (?m = 0 ∨ (∃j. ?m = Suc j ∧ j < ?n))›*) nth_Cons_Suc (*‹(?x # ?xs) ! Suc ?n = ?xs ! ?n›*)) . thus "?thesis" (*goal: ‹rawpsubstT (substT (Var y) t x) txs = s›*) by simp qed thus "?case" (*goal: ‹rawpsubstT ((Var::'var ⇒ 'trm) (y::'var)) ((tx::'trm × 'var) # (txs::('trm × 'var) list)) = (s::'trm)›*) by simp qed (auto) (*solved the remaining goal: ‹⟦snd ` set [] ⊆ (var::'var set); fst ` set [] ⊆ (trm::'trm set); distinct (map snd []); (s::'trm, y::'var) ∈ set []; ⋀(i::nat) j::nat. ⟦i < j; j < length []⟧ ⟹ snd ([] ! j) ∉ (FvarsT::'trm ⇒ 'var set) (fst ([] ! i))⟧ ⟹ rawpsubstT ((Var::'var ⇒ 'trm) y) [] = s›*) lemma psubstT_Var_in: assumes "y ∈ var" "snd ` (set txs) ⊆ var" "fst ` (set txs) ⊆ trm" and "distinct (map snd txs)" and "(s,y) ∈ set txs" shows "psubstT (Var y) txs = s" proof (-) (*goal: ‹psubstT (Var y) txs = s›*) define us where us: "us ≡ getFrN (map snd txs) (Var y # map fst txs) [] (length txs)" have us_facts: "set us ⊆ var" "set us ∩ ⋃ (FvarsT ` (fst ` (set txs))) = {}" "y ∉ set us" "set us ∩ snd ` (set txs) = {}" "length us = length txs" "distinct us" using assms (*‹y ∈ var› ‹snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set)› ‹fst ` set txs ⊆ trm› ‹distinct (map snd txs)› ‹(s, y) ∈ set txs›*) unfolding us (*goals: 1. ‹set (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) ⊆ var› 2. ‹set (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) ∩ ⋃ (FvarsT ` fst ` set txs) = {}› 3. ‹y ∉ set (getFrN (map snd txs) (Var y # map fst txs) [] (length txs))› 4. ‹set (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) ∩ snd ` set txs = {}› 5. ‹length (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) = length txs› 6. ‹distinct (getFrN (map snd txs) (Var y # map fst txs) [] (length txs))›*) using getFrN_FvarsT[of "map snd txs" "Var y # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (Var y # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (Var y # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) ∩ FvarsT ?t = {}›*) getFrN_var[of "map snd txs" "Var y # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (Var y # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (Var y # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}›*) getFrN_length[of "map snd txs" "Var y # map fst txs" "[]" "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (Var y # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) = length txs›*) apply - (*top goal: ‹set (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) ⊆ var› and 5 goals remain*) subgoal for by auto subgoal for by auto subgoal for by force subgoal for by force (*goals: 1. ‹⟦y ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; distinct (map snd txs); (s, y) ∈ set txs; ⋀t. ⟦set (map snd txs) ⊆ var; set (Var y # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (Var y # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) ∩ FvarsT t = {}; ⋀t. ⟦set (map snd txs) ⊆ var; set (Var y # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (Var y # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}; ⟦set (map snd txs) ⊆ var; set (Var y # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) = length txs⟧ ⟹ length (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) = length txs› 2. ‹⟦y ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; distinct (map snd txs); (s, y) ∈ set txs; ⋀t. ⟦set (map snd txs) ⊆ var; set (Var y # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (Var y # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) ∩ FvarsT t = {}; ⋀t. ⟦set (map snd txs) ⊆ var; set (Var y # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (Var y # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}; ⟦set (map snd txs) ⊆ var; set (Var y # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) = length txs⟧ ⟹ distinct (getFrN (map snd txs) (Var y # map fst txs) [] (length txs))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . obtain i where i[simp]: "i < length txs" "txs!i = (s,y)" (*goal: ‹(⋀i. ⟦i < length txs; txs ! i = (s, y)⟧ ⟹ thesis) ⟹ thesis›*) using ‹(s,y) ∈ set txs› (*‹(s, y) ∈ set txs›*) by (metis in_set_conv_nth (*‹(?x ∈ set ?xs) = (∃i<length ?xs. ?xs ! i = ?x)›*)) hence 00[simp]: "⋀ j. j < length txs ⟹ txs ! j = txs ! i ⟹ j = i" using ‹distinct (map snd txs)› (*‹distinct (map snd (txs::('trm::type × 'var::type) list))›*) distinct_Ex1 (*‹⟦distinct ?xs; ?x ∈ set ?xs⟧ ⟹ ∃!i. i < length ?xs ∧ ?xs ! i = ?x›*) nth_mem (*‹?n < length ?xs ⟹ ?xs ! ?n ∈ set ?xs›*) by fastforce have 000[simp]: "⋀ j ia. j < length txs ⟹ ia < length txs ⟹ snd (txs ! j) ≠ us ! ia" using assms (*‹y ∈ var› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ trm› ‹distinct (map snd txs)› ‹(s, y) ∈ set txs›*) us_facts (*‹set us ⊆ var› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹y ∉ set us› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct us›*) by (metis IntI (*‹⟦(?c::?'a) ∈ (?A::?'a set); ?c ∈ (?B::?'a set)⟧ ⟹ ?c ∈ ?A ∩ ?B›*) empty_iff (*‹((?c::?'a) ∈ {}) = False›*) length_map (*‹length (map (?f::?'b ⇒ ?'a) (?xs::?'b list)) = length ?xs›*) list.set_map (*‹set (map (?f::?'a ⇒ ?'b) (?v::?'a list)) = ?f ` set ?v›*) nth_map (*‹(?n::nat) < length (?xs::?'a list) ⟹ map (?f::?'a ⇒ ?'b) ?xs ! ?n = ?f (?xs ! ?n)›*) nth_mem (*‹(?n::nat) < length (?xs::?'a list) ⟹ ?xs ! ?n ∈ set ?xs›*)) have [simp]: "⋀ii jj. ii < jj ⟹ jj < length txs ⟹ us ! ii ∈ var" using nth_mem (*‹?n < length ?xs ⟹ ?xs ! ?n ∈ set ?xs›*) us_facts(1) (*‹set us ⊆ var›*) us_facts(5) (*‹length us = length txs›*) by auto have [simp]: "⋀i j. i < j ⟹ j < length txs ⟹ us ! j ∉ FvarsT (fst (txs ! i))" using us_facts(2,5) (*‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹length us = length txs›*) by (auto simp: Int_def (*‹?A ∩ ?B = {x ∈ ?A. x ∈ ?B}›*)) have 0: "rawpsubstT (Var y) (zip (map Var us) (map snd txs)) = Var (us!i)" using assms (*‹y ∈ var› ‹snd ` set txs ⊆ var› ‹fst ` set (txs::('trm × 'var) list) ⊆ (trm::'trm set)› ‹distinct (map snd txs)› ‹(s::'trm, y::'var) ∈ set (txs::('trm × 'var) list)›*) us_facts (*‹set us ⊆ var› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹y ∉ set us› ‹set (us::'var list) ∩ snd ` set (txs::('trm × 'var) list) = {}› ‹length us = length txs› ‹distinct us›*) apply (intro rawpsubstT_Var_in (*‹⟦snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm; distinct (map snd ?txs); (?s, ?y) ∈ set ?txs; ⋀i j. ⟦i < j; j < length ?txs⟧ ⟹ snd (?txs ! j) ∉ FvarsT (fst (?txs ! i))⟧ ⟹ rawpsubstT (Var ?y) ?txs = ?s›*)) (*goals: 1. ‹⟦y ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; distinct (map snd txs); (s, y) ∈ set txs; set us ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; y ∉ set us; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ snd ` set (zip (map Var us) (map snd txs)) ⊆ var› 2. ‹⟦y ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; distinct (map snd txs); (s, y) ∈ set txs; set us ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; y ∉ set us; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ fst ` set (zip (map Var us) (map snd txs)) ⊆ trm› 3. ‹⟦y ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; distinct (map snd txs); (s, y) ∈ set txs; set us ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; y ∉ set us; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ distinct (map snd (zip (map Var us) (map snd txs)))› 4. ‹⟦y ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; distinct (map snd txs); (s, y) ∈ set txs; set us ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; y ∉ set us; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ (Var (us ! i), y) ∈ set (zip (map Var us) (map snd txs))› 5. ‹⋀i j. ⟦y ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; distinct (map snd txs); (s, y) ∈ set txs; set us ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; y ∉ set us; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; i < j; j < length (zip (map Var us) (map snd txs))⟧ ⟹ snd (zip (map Var us) (map snd txs) ! j) ∉ FvarsT (fst (zip (map Var us) (map snd txs) ! i))› discuss goal 1*) apply ((auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: in_set_conv_nth (*‹(?x ∈ set ?xs) = (∃i<length ?xs. ?xs ! i = ?x)›*) intro!: exI[of _ i] (*‹?P i ⟹ ∃x. ?P x›*))[1]) (*discuss goal 2*) apply ((auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: in_set_conv_nth (*‹(?x ∈ set ?xs) = (∃i<length ?xs. ?xs ! i = ?x)›*) intro!: exI[of _ i] (*‹?P i ⟹ ∃x. ?P x›*))[1]) (*discuss goal 3*) apply ((auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: in_set_conv_nth (*‹(?x ∈ set ?xs) = (∃i<length ?xs. ?xs ! i = ?x)›*) intro!: exI[of _ i] (*‹?P i ⟹ ∃x. ?P x›*))[1]) (*discuss goal 4*) apply ((auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: in_set_conv_nth (*‹(?x ∈ set ?xs) = (∃i<length ?xs. ?xs ! i = ?x)›*) intro!: exI[of _ i] (*‹?P i ⟹ ∃x. ?P x›*))[1]) (*discuss goal 5*) apply ((auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: in_set_conv_nth (*‹(?x ∈ set ?xs) = (∃i<length ?xs. ?xs ! i = ?x)›*) intro!: exI[of _ i] (*‹?P i ⟹ ∃x. ?P x›*))[1]) (*proven 5 subgoals*) . have "rawpsubstT (rawpsubstT (Var y) (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = s" unfolding "0" (*goal: ‹rawpsubstT (Var (us ! i)) (zip (map fst txs) us) = s›*) using assms (*‹y ∈ var› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ trm› ‹distinct (map snd txs)› ‹(s, y) ∈ set txs›*) us_facts (*‹set (us::'var::type list) ⊆ (var::'var::type set)› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹y ∉ set us› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct us›*) apply (intro rawpsubstT_Var_in (*‹⟦snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm; distinct (map snd ?txs); (?s, ?y) ∈ set ?txs; ⋀i j. ⟦i < j; j < length ?txs⟧ ⟹ snd (?txs ! j) ∉ FvarsT (fst (?txs ! i))⟧ ⟹ rawpsubstT (Var ?y) ?txs = ?s›*)) (*goals: 1. ‹⟦y ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; distinct (map snd txs); (s, y) ∈ set txs; set us ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; y ∉ set us; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ snd ` set (zip (map fst txs) us) ⊆ var› 2. ‹⟦y ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; distinct (map snd txs); (s, y) ∈ set txs; set us ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; y ∉ set us; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ fst ` set (zip (map fst txs) us) ⊆ trm› 3. ‹⟦y ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; distinct (map snd txs); (s, y) ∈ set txs; set us ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; y ∉ set us; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ distinct (map snd (zip (map fst txs) us))› 4. ‹⟦y ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; distinct (map snd txs); (s, y) ∈ set txs; set us ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; y ∉ set us; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ (s, us ! i) ∈ set (zip (map fst txs) us)› 5. ‹⋀i j. ⟦y ∈ var; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; distinct (map snd txs); (s, y) ∈ set txs; set us ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; y ∉ set us; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; i < j; j < length (zip (map fst txs) us)⟧ ⟹ snd (zip (map fst txs) us ! j) ∉ FvarsT (fst (zip (map fst txs) us ! i))› discuss goal 1*) apply ((auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: in_set_conv_nth (*‹(?x ∈ set ?xs) = (∃i<length ?xs. ?xs ! i = ?x)›*) intro!: exI[of _ i] (*‹?P i ⟹ ∃x. ?P x›*))[1]) (*discuss goal 2*) apply ((auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: in_set_conv_nth (*‹(?x ∈ set ?xs) = (∃i<length ?xs. ?xs ! i = ?x)›*) intro!: exI[of _ i] (*‹?P i ⟹ ∃x. ?P x›*))[1]) (*discuss goal 3*) apply ((auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: in_set_conv_nth (*‹(?x ∈ set ?xs) = (∃i<length ?xs. ?xs ! i = ?x)›*) intro!: exI[of _ i] (*‹?P i ⟹ ∃x. ?P x›*))[1]) (*discuss goal 4*) apply ((auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: in_set_conv_nth (*‹(?x ∈ set ?xs) = (∃i<length ?xs. ?xs ! i = ?x)›*) intro!: exI[of _ i] (*‹?P i ⟹ ∃x. ?P x›*))[1]) (*discuss goal 5*) apply ((auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: in_set_conv_nth (*‹(?x ∈ set ?xs) = (∃i<length ?xs. ?xs ! i = ?x)›*) intro!: exI[of _ i] (*‹?P i ⟹ ∃x. ?P x›*))[1]) (*proven 5 subgoals*) . thus "?thesis" (*goal: ‹psubstT ((Var::'var ⇒ 'trm) (y::'var)) (txs::('trm × 'var) list) = (s::'trm)›*) unfolding psubstT_def (*goal: ‹(let xs = map snd txs; ts = map fst txs; us = getFrN xs (Var y # ts) [] (length xs) in rawpsubstT (rawpsubstT (Var y) (zip (map Var us) xs)) (zip ts us)) = s›*) by (simp add: Let_def (*‹Let ?s ?f ≡ ?f ?s›*) us[symmetric] (*‹getFrN (map snd txs) (Var y # map fst txs) [] (length txs) ≡ us›*)) qed lemma psubstT_Var_Cons_aux: assumes "y ∈ var" "x ∈ var" "t ∈ atrm" "snd ` set txs ⊆ var" "fst ` set txs ⊆ atrm" "x ∉ snd ` set txs" "distinct (map snd txs)" "y ≠ x" shows "psubstT (Var y) ((t, x) # txs) = psubstT (Var y) txs" proof (-) (*goal: ‹psubstT (Var y) ((t, x) # txs) = psubstT (Var y) txs›*) have txs_trm: "t ∈ trm" "fst ` set txs ⊆ trm" using assms (*‹y ∈ var› ‹(x::'var::type) ∈ (var::'var::type set)› ‹t ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set (txs::('trm × 'var) list) ⊆ atrm› ‹x ∉ snd ` set txs› ‹distinct (map snd txs)› ‹y ≠ x›*) apply - (*goals: 1. ‹⟦y ∈ var; x ∈ var; t ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x⟧ ⟹ t ∈ trm› 2. ‹⟦y ∈ var; x ∈ var; t ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x⟧ ⟹ fst ` set txs ⊆ trm› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . note assms1 = assms(1,2) (*‹y ∈ var› ‹x ∈ var›*) assms(4) (*‹snd ` set txs ⊆ var›*) assms(6-8) (*‹x ∉ snd ` set txs› ‹distinct (map snd (txs::('trm × 'var) list))› ‹y ≠ x›*) txs_trm (*‹t ∈ trm› ‹fst ` set txs ⊆ trm›*) note fvt = getFrN_FvarsT[of "x # map snd txs" "Var y # t # map fst txs" "[]" _ "Suc (length txs)"] (*‹⟦set (x # map snd txs) ⊆ var; set (Var y # t # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (Var y # t # map fst txs)⟧ ⟹ set (getFrN (x # map snd txs) (Var y # t # map fst txs) [] (Suc (length txs))) ∩ FvarsT ?t = {}›*) and var = getFrN_var[of "x # map snd txs" "Var y # t # map fst txs" "[]" _ "Suc (length txs)"] (*‹⟦set ((x::'var) # map snd (txs::('trm × 'var) list)) ⊆ (var::'var set); set ((Var::'var ⇒ 'trm) (y::'var) # (t::'trm) # map fst txs) ⊆ (trm::'trm set); set [] ⊆ (fmla::'fmla set); (?t::'trm) ∈ set (Var y # t # map fst txs)⟧ ⟹ set (getFrN (x # map snd txs) (Var y # t # map fst txs) [] (Suc (length txs))) ∩ set (x # map snd txs) = {}›*) and l = getFrN_length[of "x # map snd txs" "Var y # t # map fst txs" "[]" "Suc (length txs)"] (*‹⟦set (x # map snd txs) ⊆ var; set (Var y # t # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (x # map snd txs) (Var y # t # map fst txs) [] (Suc (length txs))) = Suc (length txs)›*) define uus where uus: "uus ≡ getFrN (x # map snd txs) (Var y # t # map fst txs) [] (Suc (length txs))" have uus_facts: "set uus ⊆ var" "set uus ∩ ⋃ (FvarsT ` (fst ` (set txs))) = {}" "set uus ∩ snd ` (set txs) = {}" "set uus ∩ FvarsT t = {}" "x ∉ set uus" "y ∉ set uus" "length uus = Suc (length txs)" "distinct uus" using assms1 (*‹(y::'var) ∈ (var::'var set)› ‹x ∈ var› ‹snd ` set txs ⊆ var› ‹x ∉ snd ` set txs› ‹distinct (map snd txs)› ‹y ≠ x› ‹(t::'trm::type) ∈ (trm::'trm::type set)› ‹fst ` set txs ⊆ trm›*) unfolding uus (*goals: 1. ‹set (getFrN (x # map snd txs) (Var y # t # map fst txs) [] (Suc (length txs))) ⊆ var› 2. ‹set (getFrN (x # map snd txs) (Var y # t # map fst txs) [] (Suc (length txs))) ∩ ⋃ (FvarsT ` fst ` set txs) = {}› 3. ‹set (getFrN (x # map snd txs) (Var y # t # map fst txs) [] (Suc (length txs))) ∩ snd ` set txs = {}› 4. ‹set (getFrN (x # map snd txs) (Var y # t # map fst txs) [] (Suc (length txs))) ∩ FvarsT t = {}› 5. ‹x ∉ set (getFrN (x # map snd txs) (Var y # t # map fst txs) [] (Suc (length txs)))› 6. ‹y ∉ set (getFrN (x # map snd txs) (Var y # t # map fst txs) [] (Suc (length txs)))› 7. ‹length (getFrN (x # map snd txs) (Var y # t # map fst txs) [] (Suc (length txs))) = Suc (length txs)› 8. ‹distinct (getFrN (x # map snd txs) (Var y # t # map fst txs) [] (Suc (length txs)))›*) apply - (*top goal: ‹set (getFrN (x # map snd txs) (Var y # t # map fst txs) [] (Suc (length txs))) ⊆ var› and 7 goals remain*) subgoal for by auto subgoal for using fvt (*‹⟦set (x # map snd txs) ⊆ var; set (Var y # t # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (Var y # t # map fst txs)⟧ ⟹ set (getFrN (x # map snd txs) (Var y # t # map fst txs) [] (Suc (length txs))) ∩ FvarsT ?t = {}›*) apply (simp add: in_fst_image (*‹(?a ∈ fst ` ?AB) = (∃b. (?a, b) ∈ ?AB)›*) Int_def (*‹?A ∩ ?B = {x ∈ ?A. x ∈ ?B}›*)) (*goal: ‹⟦y ∈ var; x ∈ var; snd ` set txs ⊆ var; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x; t ∈ trm; fst ` set txs ⊆ trm⟧ ⟹ set (getFrN (x # map snd txs) (Var y # t # map fst txs) [] (Suc (length txs))) ∩ ⋃ (FvarsT ` fst ` set txs) = {}›*) by (metis prod.collapse (*‹(fst ?prod, snd ?prod) = ?prod›*)) subgoal for using var (*‹⟦set ((x::'var) # map snd (txs::('trm × 'var) list)) ⊆ (var::'var set); set ((Var::'var ⇒ 'trm) (y::'var) # (t::'trm) # map fst txs) ⊆ (trm::'trm set); set [] ⊆ (fmla::'fmla set); (?t::'trm) ∈ set (Var y # t # map fst txs)⟧ ⟹ set (getFrN (x # map snd txs) (Var y # t # map fst txs) [] (Suc (length txs))) ∩ set (x # map snd txs) = {}›*) by (force simp add: in_fst_image (*‹(?a ∈ fst ` ?AB) = (∃b. (?a, b) ∈ ?AB)›*) Int_def (*‹?A ∩ ?B = {x ∈ ?A. x ∈ ?B}›*)) subgoal for using fvt (*‹⟦set (x # map snd txs) ⊆ var; set (Var y # t # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (Var y # t # map fst txs)⟧ ⟹ set (getFrN (x # map snd txs) (Var y # t # map fst txs) [] (Suc (length txs))) ∩ FvarsT ?t = {}›*) by auto subgoal for using var (*‹⟦set ((x::'var) # map snd (txs::('trm × 'var) list)) ⊆ (var::'var set); set ((Var::'var ⇒ 'trm) (y::'var) # (t::'trm) # map fst txs) ⊆ (trm::'trm set); set [] ⊆ (fmla::'fmla set); (?t::'trm) ∈ set (Var y # t # map fst txs)⟧ ⟹ set (getFrN (x # map snd txs) (Var y # t # map fst txs) [] (Suc (length txs))) ∩ set (x # map snd txs) = {}›*) by (fastforce simp: in_fst_image (*‹(?a ∈ fst ` ?AB) = (∃b. (?a, b) ∈ ?AB)›*) Int_def (*‹?A ∩ ?B = {x ∈ ?A. x ∈ ?B}›*)) subgoal for using fvt (*‹⟦set (x # map snd txs) ⊆ var; set (Var y # t # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (Var y # t # map fst txs)⟧ ⟹ set (getFrN (x # map snd txs) (Var y # t # map fst txs) [] (Suc (length txs))) ∩ FvarsT ?t = {}›*) by (force simp: in_fst_image (*‹(?a ∈ fst ` ?AB) = (∃b. (?a, b) ∈ ?AB)›*) Int_def (*‹?A ∩ ?B = {x ∈ ?A. x ∈ ?B}›*)) subgoal for using l (*‹⟦set (x # map snd txs) ⊆ var; set (Var y # t # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (x # map snd txs) (Var y # t # map fst txs) [] (Suc (length txs))) = Suc (length txs)›*) by auto subgoal for by auto . obtain u and us where uus_us[simp]: "uus = u # us" (*goal: ‹(⋀u us. uus = u # us ⟹ thesis) ⟹ thesis›*) using uus_facts (*‹set uus ⊆ var› ‹set uus ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set uus ∩ snd ` set txs = {}› ‹set (uus::'var::type list) ∩ (FvarsT::'trm::type ⇒ 'var::type set) (t::'trm::type) = {}› ‹x ∉ set uus› ‹y ∉ set uus› ‹length uus = Suc (length txs)› ‹distinct uus›*) apply (cases uus) (*goals: 1. ‹⟦⋀u us. uus = u # us ⟹ thesis; set uus ⊆ var; set uus ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set uus ∩ snd ` set txs = {}; set uus ∩ FvarsT t = {}; x ∉ set uus; y ∉ set uus; length uus = Suc (length txs); distinct uus; uus = []⟧ ⟹ thesis› 2. ‹⋀a list. ⟦⋀u us. uus = u # us ⟹ thesis; set uus ⊆ var; set uus ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set uus ∩ snd ` set txs = {}; set uus ∩ FvarsT t = {}; x ∉ set uus; y ∉ set uus; length uus = Suc (length txs); distinct uus; uus = a # list⟧ ⟹ thesis› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have us_facts: "set us ⊆ var" "set us ∩ ⋃ (FvarsT ` (fst ` (set txs))) = {}" "set us ∩ snd ` (set txs) = {}" "set us ∩ FvarsT t = {}" "x ∉ set us" "y ∉ set us" "length us = length txs" "distinct us" and u_facts: "u ∈ var" "u ∉ ⋃ (FvarsT ` (fst ` (set txs)))" "u ∉ snd ` (set txs)" "u ∉FvarsT t" "u ≠ x" "u ≠ y" "u ∉ set us" using uus_facts (*‹set uus ⊆ var› ‹set uus ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set (uus::'var list) ∩ snd ` set (txs::('trm × 'var) list) = {}› ‹set uus ∩ FvarsT t = {}› ‹(x::'var) ∉ set (uus::'var list)› ‹y ∉ set uus› ‹length uus = Suc (length txs)› ‹distinct uus›*) apply - (*goals: 1. ‹⟦set uus ⊆ var; set uus ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set uus ∩ snd ` set txs = {}; set uus ∩ FvarsT t = {}; x ∉ set uus; y ∉ set uus; length uus = Suc (length txs); distinct uus⟧ ⟹ set us ⊆ var› 2. ‹⟦set uus ⊆ var; set uus ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set uus ∩ snd ` set txs = {}; set uus ∩ FvarsT t = {}; x ∉ set uus; y ∉ set uus; length uus = Suc (length txs); distinct uus⟧ ⟹ set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› 3. ‹⟦set uus ⊆ var; set uus ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set uus ∩ snd ` set txs = {}; set uus ∩ FvarsT t = {}; x ∉ set uus; y ∉ set uus; length uus = Suc (length txs); distinct uus⟧ ⟹ set us ∩ snd ` set txs = {}› 4. ‹⟦set uus ⊆ var; set uus ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set uus ∩ snd ` set txs = {}; set uus ∩ FvarsT t = {}; x ∉ set uus; y ∉ set uus; length uus = Suc (length txs); distinct uus⟧ ⟹ set us ∩ FvarsT t = {}› 5. ‹⟦set uus ⊆ var; set uus ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set uus ∩ snd ` set txs = {}; set uus ∩ FvarsT t = {}; x ∉ set uus; y ∉ set uus; length uus = Suc (length txs); distinct uus⟧ ⟹ x ∉ set us› 6. ‹⟦set uus ⊆ var; set uus ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set uus ∩ snd ` set txs = {}; set uus ∩ FvarsT t = {}; x ∉ set uus; y ∉ set uus; length uus = Suc (length txs); distinct uus⟧ ⟹ y ∉ set us› 7. ‹⟦set uus ⊆ var; set uus ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set uus ∩ snd ` set txs = {}; set uus ∩ FvarsT t = {}; x ∉ set uus; y ∉ set uus; length uus = Suc (length txs); distinct uus⟧ ⟹ length us = length txs› 8. ‹⟦set uus ⊆ var; set uus ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set uus ∩ snd ` set txs = {}; set uus ∩ FvarsT t = {}; x ∉ set uus; y ∉ set uus; length uus = Suc (length txs); distinct uus⟧ ⟹ distinct us› 9. ‹⟦set uus ⊆ var; set uus ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set uus ∩ snd ` set txs = {}; set uus ∩ FvarsT t = {}; x ∉ set uus; y ∉ set uus; length uus = Suc (length txs); distinct uus⟧ ⟹ u ∈ var› 10. ‹⟦set uus ⊆ var; set uus ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set uus ∩ snd ` set txs = {}; set uus ∩ FvarsT t = {}; x ∉ set uus; y ∉ set uus; length uus = Suc (length txs); distinct uus⟧ ⟹ u ∉ ⋃ (FvarsT ` fst ` set txs)› 11. ‹⟦set uus ⊆ var; set uus ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set uus ∩ snd ` set txs = {}; set uus ∩ FvarsT t = {}; x ∉ set uus; y ∉ set uus; length uus = Suc (length txs); distinct uus⟧ ⟹ u ∉ snd ` set txs› 12. ‹⟦set uus ⊆ var; set uus ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set uus ∩ snd ` set txs = {}; set uus ∩ FvarsT t = {}; x ∉ set uus; y ∉ set uus; length uus = Suc (length txs); distinct uus⟧ ⟹ u ∉ FvarsT t› 13. ‹⟦set uus ⊆ var; set uus ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set uus ∩ snd ` set txs = {}; set uus ∩ FvarsT t = {}; x ∉ set uus; y ∉ set uus; length uus = Suc (length txs); distinct uus⟧ ⟹ u ≠ x› 14. ‹⟦set uus ⊆ var; set uus ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set uus ∩ snd ` set txs = {}; set uus ∩ FvarsT t = {}; x ∉ set uus; y ∉ set uus; length uus = Suc (length txs); distinct uus⟧ ⟹ u ≠ y› 15. ‹⟦set uus ⊆ var; set uus ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set uus ∩ snd ` set txs = {}; set uus ∩ FvarsT t = {}; x ∉ set uus; y ∉ set uus; length uus = Suc (length txs); distinct uus⟧ ⟹ u ∉ set us› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*discuss goal 9*) apply ((auto)[1]) (*discuss goal 10*) apply ((auto)[1]) (*discuss goal 11*) apply ((auto)[1]) (*discuss goal 12*) apply ((auto)[1]) (*discuss goal 13*) apply ((auto)[1]) (*discuss goal 14*) apply ((auto)[1]) (*discuss goal 15*) apply ((auto)[1]) (*proven 15 subgoals*) . note fvt = getFrN_FvarsT[of "map snd txs" "Var y # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (Var y # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (Var y # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) ∩ FvarsT ?t = {}›*) and var = getFrN_var[of "map snd txs" "Var y # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (Var y # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (Var y # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}›*) and l = getFrN_length[of "map snd txs" "Var y # map fst txs" "[]" "length txs"] (*‹⟦set (map snd (txs::('trm::type × 'var::type) list)) ⊆ (var::'var::type set); set ((Var::'var::type ⇒ 'trm::type) (y::'var::type) # map fst txs) ⊆ (trm::'trm::type set); set [] ⊆ (fmla::'fmla::type set)⟧ ⟹ length (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) = length txs›*) define vs where vs: "vs ≡ getFrN (map snd txs) (Var y # map fst txs) [] (length txs)" have vs_facts: "set vs ⊆ var" "set vs ∩ ⋃ (FvarsT ` (fst ` (set txs))) = {}" "y ∉ set vs" "set vs ∩ snd ` (set txs) = {}" "length vs = length txs" "distinct vs" using assms1 (*‹y ∈ var› ‹x ∈ var› ‹snd ` set txs ⊆ var› ‹x ∉ snd ` set txs› ‹distinct (map snd (txs::('trm × 'var) list))› ‹y ≠ x› ‹t ∈ trm› ‹fst ` set txs ⊆ trm›*) unfolding vs (*goals: 1. ‹set (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) ⊆ var› 2. ‹set (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) ∩ ⋃ (FvarsT ` fst ` set txs) = {}› 3. ‹y ∉ set (getFrN (map snd txs) (Var y # map fst txs) [] (length txs))› 4. ‹set (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) ∩ snd ` set txs = {}› 5. ‹length (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) = length txs› 6. ‹distinct (getFrN (map snd txs) (Var y # map fst txs) [] (length txs))›*) apply - (*top goal: ‹set (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) ⊆ var› and 5 goals remain*) subgoal for by auto subgoal for using fvt (*‹⟦set (map snd txs) ⊆ var; set (Var y # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (Var y # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) ∩ FvarsT ?t = {}›*) apply (simp add: in_fst_image (*‹((?a::?'a) ∈ fst ` (?AB::(?'a × ?'b) set)) = (∃b::?'b. (?a, b) ∈ ?AB)›*) Int_def (*‹(?A::?'a set) ∩ (?B::?'a set) = {x::?'a ∈ ?A. x ∈ ?B}›*)) (*goal: ‹⟦y ∈ var; x ∈ var; snd ` set txs ⊆ var; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x; t ∈ trm; fst ` set txs ⊆ trm⟧ ⟹ set (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) ∩ ⋃ (FvarsT ` fst ` set txs) = {}›*) by (metis prod.collapse (*‹(fst (?prod::?'a × ?'b), snd ?prod) = ?prod›*)) subgoal for using fvt (*‹⟦set (map snd txs) ⊆ var; set (Var y # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (Var y # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) ∩ FvarsT ?t = {}›*) l (*‹⟦set (map snd txs) ⊆ var; set (Var y # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) = length txs›*) by fastforce subgoal for using var (*‹⟦set (map snd txs) ⊆ var; set (Var y # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (Var y # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}›*) by (force simp: Int_def (*‹?A ∩ ?B = {x ∈ ?A. x ∈ ?B}›*) in_fst_image (*‹(?a ∈ fst ` ?AB) = (∃b. (?a, b) ∈ ?AB)›*)) subgoal for using l (*‹⟦set (map snd txs) ⊆ var; set (Var y # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (Var y # map fst txs) [] (length txs)) = length txs›*) by auto subgoal for by auto . have 0: "substT (Var y) (Var u) x = Var y" using assms (*‹y ∈ var› ‹x ∈ var› ‹t ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹(x::'var) ∉ snd ` set (txs::('trm × 'var) list)› ‹distinct (map snd txs)› ‹y ≠ x›*) u_facts (*‹(u::'var) ∈ (var::'var set)› ‹u ∉ ⋃ (FvarsT ` fst ` set txs)› ‹u ∉ snd ` set txs› ‹(u::'var) ∉ (FvarsT::'trm ⇒ 'var set) (t::'trm)› ‹(u::'var) ≠ (x::'var)› ‹(u::'var) ≠ (y::'var)› ‹u ∉ set us›*) by auto have 1: "substT (rawpsubstT (Var y) (zip (map Var us) (map snd txs))) t u = rawpsubstT (Var y) (zip (map Var us) (map snd txs))" using assms (*‹y ∈ var› ‹x ∈ var› ‹(t::'trm) ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set (txs::('trm::type × 'var::type) list) ⊆ atrm› ‹x ∉ snd ` set txs› ‹distinct (map snd txs)› ‹y ≠ x›*) u_facts (*‹u ∈ var› ‹u ∉ ⋃ (FvarsT ` fst ` set txs)› ‹u ∉ snd ` set txs› ‹u ∉ FvarsT t› ‹u ≠ x› ‹u ≠ y› ‹(u::'var) ∉ set (us::'var list)›*) us_facts (*‹set us ⊆ var› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹set us ∩ FvarsT t = {}› ‹x ∉ set us› ‹y ∉ set us› ‹length us = length txs› ‹distinct (us::'var list)›*) apply (intro substT_notIn (*‹⟦?x ∈ var; ?t1.0 ∈ trm; ?t2.0 ∈ trm; ?x ∉ FvarsT ?t1.0⟧ ⟹ substT ?t1.0 ?t2.0 ?x = ?t1.0›*)) (*goals: 1. ‹⟦(y::'var::type) ∈ (var::'var::type set); (x::'var::type) ∈ var; (t::'trm::type) ∈ atrm; snd ` set (txs::('trm::type × 'var::type) list) ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x; (u::'var::type) ∈ var; u ∉ ⋃ ((FvarsT::'trm::type ⇒ 'var::type set) ` fst ` set txs); u ∉ snd ` set txs; u ∉ FvarsT t; u ≠ x; u ≠ y; u ∉ set (us::'var::type list); set us ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; set us ∩ FvarsT t = {}; x ∉ set us; y ∉ set us; length us = length txs; distinct us⟧ ⟹ u ∈ var› 2. ‹⟦(y::'var::type) ∈ (var::'var::type set); (x::'var::type) ∈ var; (t::'trm::type) ∈ atrm; snd ` set (txs::('trm::type × 'var::type) list) ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x; (u::'var::type) ∈ var; u ∉ ⋃ ((FvarsT::'trm::type ⇒ 'var::type set) ` fst ` set txs); u ∉ snd ` set txs; u ∉ FvarsT t; u ≠ x; u ≠ y; u ∉ set (us::'var::type list); set us ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; set us ∩ FvarsT t = {}; x ∉ set us; y ∉ set us; length us = length txs; distinct us⟧ ⟹ rawpsubstT ((Var::'var::type ⇒ 'trm::type) y) (zip (map Var us) (map snd txs)) ∈ (trm::'trm::type set)› 3. ‹⟦(y::'var::type) ∈ (var::'var::type set); (x::'var::type) ∈ var; (t::'trm::type) ∈ atrm; snd ` set (txs::('trm::type × 'var::type) list) ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x; (u::'var::type) ∈ var; u ∉ ⋃ ((FvarsT::'trm::type ⇒ 'var::type set) ` fst ` set txs); u ∉ snd ` set txs; u ∉ FvarsT t; u ≠ x; u ≠ y; u ∉ set (us::'var::type list); set us ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; set us ∩ FvarsT t = {}; x ∉ set us; y ∉ set us; length us = length txs; distinct us⟧ ⟹ t ∈ (trm::'trm::type set)› 4. ‹⟦(y::'var::type) ∈ (var::'var::type set); (x::'var::type) ∈ var; (t::'trm::type) ∈ atrm; snd ` set (txs::('trm::type × 'var::type) list) ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x; (u::'var::type) ∈ var; u ∉ ⋃ ((FvarsT::'trm::type ⇒ 'var::type set) ` fst ` set txs); u ∉ snd ` set txs; u ∉ FvarsT t; u ≠ x; u ≠ y; u ∉ set (us::'var::type list); set us ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; set us ∩ FvarsT t = {}; x ∉ set us; y ∉ set us; length us = length txs; distinct us⟧ ⟹ u ∉ FvarsT (rawpsubstT ((Var::'var::type ⇒ 'trm::type) y) (zip (map Var us) (map snd txs)))› discuss goal 1*) apply ((auto 0 3 intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) in_FvarsT_rawpsubstT_imp (*‹⟦?y ∈ FvarsT (rawpsubstT ?r ?txs); ?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ ?y ∈ FvarsT ?r - snd ` set ?txs ∨ ?y ∈ ⋃ {uu_. ∃t x. uu_ = FvarsT t ∧ (t, x) ∈ set ?txs}›*) FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*))[1]) (*discuss goal 2*) apply ((auto 0 3 intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) in_FvarsT_rawpsubstT_imp (*‹⟦?y ∈ FvarsT (rawpsubstT ?r ?txs); ?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ ?y ∈ FvarsT ?r - snd ` set ?txs ∨ ?y ∈ ⋃ {uu_. ∃t x. uu_ = FvarsT t ∧ (t, x) ∈ set ?txs}›*) FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*))[1]) (*discuss goal 3*) apply ((auto 0 3 intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) in_FvarsT_rawpsubstT_imp (*‹⟦?y ∈ FvarsT (rawpsubstT ?r ?txs); ?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm⟧ ⟹ ?y ∈ FvarsT ?r - snd ` set ?txs ∨ ?y ∈ ⋃ {uu_. ∃t x. uu_ = FvarsT t ∧ (t, x) ∈ set ?txs}›*) FvarsT_VarD (*‹⟦?x ∈ FvarsT (Var ?y); ?y ∈ var⟧ ⟹ ?x = ?y›*))[1]) (*discuss goal 4*) apply ((auto 0 3 intro!: rawpsubstT (*‹⟦(?t::'trm) ∈ (trm::'trm set); snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) dest!: set_zip_D (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) in_FvarsT_rawpsubstT_imp (*‹⟦(?y::'var) ∈ (FvarsT::'trm ⇒ 'var set) (rawpsubstT (?r::'trm) (?txs::('trm × 'var) list)); ?r ∈ atrm; snd ` set ?txs ⊆ (var::'var set); fst ` set ?txs ⊆ atrm⟧ ⟹ ?y ∈ FvarsT ?r - snd ` set ?txs ∨ ?y ∈ ⋃ {uu_::'var set. ∃(t::'trm) x::'var. uu_ = FvarsT t ∧ (t, x) ∈ set ?txs}›*) FvarsT_VarD (*‹⟦(?x::'var) ∈ (FvarsT::'trm ⇒ 'var set) ((Var::'var ⇒ 'trm) (?y::'var)); ?y ∈ (var::'var set)⟧ ⟹ ?x = ?y›*))[1]) (*proven 4 subgoals*) . have "rawpsubstT (rawpsubstT (Var y) (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT (rawpsubstT (Var y) (zip (map Var vs) (map snd txs))) (zip (map fst txs) vs)" using assms (*‹y ∈ var› ‹x ∈ var› ‹(t::'trm) ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹x ∉ snd ` set txs› ‹distinct (map snd txs)› ‹(y::'var::type) ≠ (x::'var::type)›*) vs_facts (*‹set vs ⊆ var› ‹set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹y ∉ set vs› ‹set vs ∩ snd ` set txs = {}› ‹length vs = length txs› ‹distinct vs›*) us_facts (*‹set (us::'var list) ⊆ (var::'var set)› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹set us ∩ FvarsT t = {}› ‹x ∉ set us› ‹y ∉ set us› ‹length us = length txs› ‹distinct us›*) apply (intro rawpsubstT_compose_freshVar2 (*‹⟦?r ∈ atrm; set ?ts ⊆ atrm; set ?xs ⊆ var; distinct ?xs; set ?us ⊆ var; distinct ?us; set ?us ∩ FvarsT ?r = {}; set ?us ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?us ∩ set ?xs = {}; set ?vs ⊆ var; distinct ?vs; set ?vs ∩ FvarsT ?r = {}; set ?vs ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?vs ∩ set ?xs = {}; length ?us = length ?xs; length ?vs = length ?xs; length ?ts = length ?xs⟧ ⟹ rawpsubstT (rawpsubstT ?r (zip (map Var ?us) ?xs)) (zip ?ts ?us) = rawpsubstT (rawpsubstT ?r (zip (map Var ?vs) ?xs)) (zip ?ts ?vs)›*)) (*goals: 1. ‹⟦(y::'var) ∈ (var::'var set); (x::'var) ∈ var; (t::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x; set (vs::'var list) ⊆ var; set vs ∩ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set txs) = {}; y ∉ set vs; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs; set (us::'var list) ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; set us ∩ FvarsT t = {}; x ∉ set us; y ∉ set us; length us = length txs; distinct us⟧ ⟹ (Var::'var ⇒ 'trm) y ∈ atrm› 2. ‹⟦(y::'var) ∈ (var::'var set); (x::'var) ∈ var; (t::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x; set (vs::'var list) ⊆ var; set vs ∩ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set txs) = {}; y ∉ set vs; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs; set (us::'var list) ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; set us ∩ FvarsT t = {}; x ∉ set us; y ∉ set us; length us = length txs; distinct us⟧ ⟹ set (map fst txs) ⊆ atrm› 3. ‹⟦(y::'var) ∈ (var::'var set); (x::'var) ∈ var; (t::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x; set (vs::'var list) ⊆ var; set vs ∩ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set txs) = {}; y ∉ set vs; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs; set (us::'var list) ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; set us ∩ FvarsT t = {}; x ∉ set us; y ∉ set us; length us = length txs; distinct us⟧ ⟹ set (map snd txs) ⊆ var› 4. ‹⟦(y::'var) ∈ (var::'var set); (x::'var) ∈ var; (t::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x; set (vs::'var list) ⊆ var; set vs ∩ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set txs) = {}; y ∉ set vs; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs; set (us::'var list) ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; set us ∩ FvarsT t = {}; x ∉ set us; y ∉ set us; length us = length txs; distinct us⟧ ⟹ distinct (map snd txs)› 5. ‹⟦(y::'var) ∈ (var::'var set); (x::'var) ∈ var; (t::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x; set (vs::'var list) ⊆ var; set vs ∩ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set txs) = {}; y ∉ set vs; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs; set (us::'var list) ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; set us ∩ FvarsT t = {}; x ∉ set us; y ∉ set us; length us = length txs; distinct us⟧ ⟹ set us ⊆ var› 6. ‹⟦(y::'var) ∈ (var::'var set); (x::'var) ∈ var; (t::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x; set (vs::'var list) ⊆ var; set vs ∩ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set txs) = {}; y ∉ set vs; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs; set (us::'var list) ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; set us ∩ FvarsT t = {}; x ∉ set us; y ∉ set us; length us = length txs; distinct us⟧ ⟹ distinct us› 7. ‹⟦(y::'var) ∈ (var::'var set); (x::'var) ∈ var; (t::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x; set (vs::'var list) ⊆ var; set vs ∩ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set txs) = {}; y ∉ set vs; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs; set (us::'var list) ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; set us ∩ FvarsT t = {}; x ∉ set us; y ∉ set us; length us = length txs; distinct us⟧ ⟹ set us ∩ FvarsT ((Var::'var ⇒ 'trm) y) = {}› 8. ‹⟦(y::'var) ∈ (var::'var set); (x::'var) ∈ var; (t::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x; set (vs::'var list) ⊆ var; set vs ∩ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set txs) = {}; y ∉ set vs; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs; set (us::'var list) ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; set us ∩ FvarsT t = {}; x ∉ set us; y ∉ set us; length us = length txs; distinct us⟧ ⟹ set us ∩ ⋃ (FvarsT ` set (map fst txs)) = {}› 9. ‹⟦(y::'var) ∈ (var::'var set); (x::'var) ∈ var; (t::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x; set (vs::'var list) ⊆ var; set vs ∩ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set txs) = {}; y ∉ set vs; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs; set (us::'var list) ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; set us ∩ FvarsT t = {}; x ∉ set us; y ∉ set us; length us = length txs; distinct us⟧ ⟹ set us ∩ set (map snd txs) = {}› 10. ‹⟦(y::'var) ∈ (var::'var set); (x::'var) ∈ var; (t::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x; set (vs::'var list) ⊆ var; set vs ∩ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set txs) = {}; y ∉ set vs; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs; set (us::'var list) ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; set us ∩ FvarsT t = {}; x ∉ set us; y ∉ set us; length us = length txs; distinct us⟧ ⟹ set vs ⊆ var› 11. ‹⟦(y::'var) ∈ (var::'var set); (x::'var) ∈ var; (t::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x; set (vs::'var list) ⊆ var; set vs ∩ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set txs) = {}; y ∉ set vs; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs; set (us::'var list) ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; set us ∩ FvarsT t = {}; x ∉ set us; y ∉ set us; length us = length txs; distinct us⟧ ⟹ distinct vs› 12. ‹⟦(y::'var) ∈ (var::'var set); (x::'var) ∈ var; (t::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x; set (vs::'var list) ⊆ var; set vs ∩ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set txs) = {}; y ∉ set vs; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs; set (us::'var list) ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; set us ∩ FvarsT t = {}; x ∉ set us; y ∉ set us; length us = length txs; distinct us⟧ ⟹ set vs ∩ FvarsT ((Var::'var ⇒ 'trm) y) = {}› 13. ‹⟦(y::'var) ∈ (var::'var set); (x::'var) ∈ var; (t::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x; set (vs::'var list) ⊆ var; set vs ∩ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set txs) = {}; y ∉ set vs; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs; set (us::'var list) ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; set us ∩ FvarsT t = {}; x ∉ set us; y ∉ set us; length us = length txs; distinct us⟧ ⟹ set vs ∩ ⋃ (FvarsT ` set (map fst txs)) = {}› 14. ‹⟦(y::'var) ∈ (var::'var set); (x::'var) ∈ var; (t::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x; set (vs::'var list) ⊆ var; set vs ∩ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set txs) = {}; y ∉ set vs; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs; set (us::'var list) ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; set us ∩ FvarsT t = {}; x ∉ set us; y ∉ set us; length us = length txs; distinct us⟧ ⟹ set vs ∩ set (map snd txs) = {}› 15. ‹⟦(y::'var) ∈ (var::'var set); (x::'var) ∈ var; (t::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x; set (vs::'var list) ⊆ var; set vs ∩ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set txs) = {}; y ∉ set vs; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs; set (us::'var list) ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; set us ∩ FvarsT t = {}; x ∉ set us; y ∉ set us; length us = length txs; distinct us⟧ ⟹ length us = length (map snd txs)› 16. ‹⟦(y::'var) ∈ (var::'var set); (x::'var) ∈ var; (t::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x; set (vs::'var list) ⊆ var; set vs ∩ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set txs) = {}; y ∉ set vs; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs; set (us::'var list) ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; set us ∩ FvarsT t = {}; x ∉ set us; y ∉ set us; length us = length txs; distinct us⟧ ⟹ length vs = length (map snd txs)› 17. ‹⟦(y::'var) ∈ (var::'var set); (x::'var) ∈ var; (t::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ var; fst ` set txs ⊆ atrm; x ∉ snd ` set txs; distinct (map snd txs); y ≠ x; set (vs::'var list) ⊆ var; set vs ∩ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set txs) = {}; y ∉ set vs; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs; set (us::'var list) ⊆ var; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; set us ∩ FvarsT t = {}; x ∉ set us; y ∉ set us; length us = length txs; distinct us⟧ ⟹ length (map fst txs) = length (map snd txs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*discuss goal 9*) apply ((auto)[1]) (*discuss goal 10*) apply ((auto)[1]) (*discuss goal 11*) apply ((auto)[1]) (*discuss goal 12*) apply ((auto)[1]) (*discuss goal 13*) apply ((auto)[1]) (*discuss goal 14*) apply ((auto)[1]) (*discuss goal 15*) apply ((auto)[1]) (*discuss goal 16*) apply ((auto)[1]) (*discuss goal 17*) apply ((auto)[1]) (*proven 17 subgoals*) . thus "?thesis" (*goal: ‹psubstT (Var y) ((t, x) # txs) = psubstT (Var y) txs›*) unfolding psubstT_def (*goal: ‹(let xs::'var list = map snd ((t::'trm, x::'var) # (txs::('trm × 'var) list)); ts::'trm list = map fst ((t, x) # txs); us::'var list = getFrN xs ((Var::'var ⇒ 'trm) (y::'var) # ts) [] (length xs) in rawpsubstT (rawpsubstT (Var y) (zip (map Var us) xs)) (zip ts us)) = (let xs::'var list = map snd txs; ts::'trm list = map fst txs; us::'var list = getFrN xs (Var y # ts) [] (length xs) in rawpsubstT (rawpsubstT (Var y) (zip (map Var us) xs)) (zip ts us))›*) by (simp add: Let_def (*‹Let (?s::?'a) (?f::?'a ⇒ ?'b) ≡ ?f ?s›*) uus[symmetric] (*‹getFrN ((x::'var) # map snd (txs::('trm × 'var) list)) ((Var::'var ⇒ 'trm) (y::'var) # (t::'trm) # map fst txs) [] (Suc (length txs)) ≡ uus::'var list›*) vs[symmetric] (*‹getFrN (map snd (txs::('trm × 'var) list)) ((Var::'var ⇒ 'trm) (y::'var) # map fst txs) [] (length txs) ≡ vs::'var list›*) 0 (*‹(substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) ((Var::'var ⇒ 'trm) (y::'var)) (Var (u::'var)) (x::'var) = Var y›*) 1 (*‹(substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) (rawpsubstT ((Var::'var ⇒ 'trm) (y::'var)) (zip (map Var (us::'var list)) (map snd (txs::('trm × 'var) list)))) (t::'trm) (u::'var) = rawpsubstT (Var y) (zip (map Var us) (map snd txs))›*)) qed text ‹Simplification rules for parallel substitution:› lemma psubstT_Var_Cons[simp]: "y ∈ var ⟹ x ∈ var ⟹ t ∈ atrm ⟹ snd ` set txs ⊆ var ⟹ fst ` set txs ⊆ atrm ⟹ distinct (map snd txs) ⟹ x ∉ snd ` set txs ⟹ psubstT (Var y) ((t,x) # txs) = (if y = x then t else psubstT (Var y) txs)" apply (cases "y = x") (*goal: ‹⟦y ∈ var; x ∈ var; t ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); x ∉ snd ` set txs⟧ ⟹ psubstT (Var y) ((t, x) # txs) = (if y = x then t else psubstT (Var y) txs)›*) subgoal for apply (rule psubstT_Var_in (*‹⟦?y ∈ var; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm; distinct (map snd ?txs); (?s, ?y) ∈ set ?txs⟧ ⟹ psubstT (Var ?y) ?txs = ?s›*)) (*goals: 1. ‹⟦y ∈ var; x ∈ var; t ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); x ∉ snd ` set txs; y = x⟧ ⟹ y ∈ var› 2. ‹⟦y ∈ var; x ∈ var; t ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); x ∉ snd ` set txs; y = x⟧ ⟹ snd ` set ((t, x) # txs) ⊆ var› 3. ‹⟦y ∈ var; x ∈ var; t ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); x ∉ snd ` set txs; y = x⟧ ⟹ fst ` set ((t, x) # txs) ⊆ trm› 4. ‹⟦y ∈ var; x ∈ var; t ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); x ∉ snd ` set txs; y = x⟧ ⟹ distinct (map snd ((t, x) # txs))› 5. ‹⟦y ∈ var; x ∈ var; t ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); x ∉ snd ` set txs; y = x⟧ ⟹ (if y = x then t else psubstT (Var y) txs, y) ∈ set ((t, x) # txs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . subgoal for by (auto intro!: psubstT_Var_Cons_aux (*‹⟦?y ∈ var; ?x ∈ var; ?t ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; ?x ∉ snd ` set ?txs; distinct (map snd ?txs); ?y ≠ ?x⟧ ⟹ psubstT (Var ?y) ((?t, ?x) # ?txs) = psubstT (Var ?y) ?txs›*)) . lemma psubstT_zer[simp]: assumes "snd ` (set txs) ⊆ var" and "fst ` (set txs) ⊆ trm" shows "psubstT zer txs = zer" using assms (*‹snd ` set txs ⊆ var› ‹fst ` set (txs::('trm × 'var) list) ⊆ (trm::'trm set)›*) apply (intro psubstT_num (*‹⟦snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm; ?n ∈ num⟧ ⟹ psubstT ?n ?txs = ?n›*)) (*goals: 1. ‹⟦snd ` set txs ⊆ var; fst ` set txs ⊆ trm⟧ ⟹ snd ` set txs ⊆ var› 2. ‹⟦snd ` set txs ⊆ var; fst ` set txs ⊆ trm⟧ ⟹ fst ` set txs ⊆ trm› 3. ‹⟦snd ` set txs ⊆ var; fst ` set txs ⊆ trm⟧ ⟹ zer ∈ num› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . lemma rawpsubstT_suc: assumes "r ∈ trm" and "snd ` (set txs) ⊆ var" and "fst ` (set txs) ⊆ trm" shows "rawpsubstT (suc r) txs = suc (rawpsubstT r txs)" using assms (*‹r ∈ trm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ trm›*) apply (induct txs arbitrary: r) (*goal: ‹rawpsubstT ((suc::'trm ⇒ 'trm) (r::'trm)) (txs::('trm × 'var) list) = suc (rawpsubstT r txs)›*) subgoal for by simp subgoal for tx and txs and r apply (cases tx) (*goal: ‹⟦⋀r. ⟦r ∈ trm; snd ` set txs ⊆ var; fst ` set txs ⊆ trm⟧ ⟹ rawpsubstT (suc r) txs = suc (rawpsubstT r txs); r ∈ trm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ trm⟧ ⟹ rawpsubstT (suc r) (tx # txs) = suc (rawpsubstT r (tx # txs))›*) by auto . lemma psubstT_suc[simp]: assumes "r ∈ atrm" and "snd ` (set txs) ⊆ var" and "fst ` (set txs) ⊆ atrm" and "distinct (map snd txs)" shows "psubstT (suc r) txs = suc (psubstT r txs)" proof (-) (*goal: ‹psubstT (suc r) txs = suc (psubstT r txs)›*) have 000: "r ∈ trm" "fst ` (set txs) ⊆ trm" using assms (*‹r ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹distinct (map snd txs)›*) apply - (*goals: 1. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs)⟧ ⟹ r ∈ trm› 2. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs)⟧ ⟹ fst ` set txs ⊆ trm› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . define us where us: "us ≡ getFrN (map snd txs) (suc r # map fst txs) [] (length txs)" have us_facts: "set us ⊆ var" "set us ∩ FvarsT r = {}" "set us ∩ ⋃ (FvarsT ` (fst ` (set txs))) = {}" "set us ∩ snd ` (set txs) = {}" "length us = length txs" "distinct us" using assms(2) (*‹snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set)›*) "000" (*‹r ∈ trm› ‹fst ` set (txs::('trm × 'var) list) ⊆ (trm::'trm set)›*) unfolding us (*goals: 1. ‹set (getFrN (map snd (txs::('trm::type × 'var::type) list)) ((suc::'trm::type ⇒ 'trm::type) (r::'trm::type) # map fst txs) [] (length txs)) ⊆ (var::'var::type set)› 2. ‹set (getFrN (map snd (txs::('trm::type × 'var::type) list)) ((suc::'trm::type ⇒ 'trm::type) (r::'trm::type) # map fst txs) [] (length txs)) ∩ (FvarsT::'trm::type ⇒ 'var::type set) r = {}› 3. ‹set (getFrN (map snd (txs::('trm::type × 'var::type) list)) ((suc::'trm::type ⇒ 'trm::type) (r::'trm::type) # map fst txs) [] (length txs)) ∩ ⋃ ((FvarsT::'trm::type ⇒ 'var::type set) ` fst ` set txs) = {}› 4. ‹set (getFrN (map snd (txs::('trm::type × 'var::type) list)) ((suc::'trm::type ⇒ 'trm::type) (r::'trm::type) # map fst txs) [] (length txs)) ∩ snd ` set txs = {}› 5. ‹length (getFrN (map snd (txs::('trm::type × 'var::type) list)) ((suc::'trm::type ⇒ 'trm::type) (r::'trm::type) # map fst txs) [] (length txs)) = length txs› 6. ‹distinct (getFrN (map snd (txs::('trm::type × 'var::type) list)) ((suc::'trm::type ⇒ 'trm::type) (r::'trm::type) # map fst txs) [] (length txs))›*) using getFrN_FvarsT[of "map snd txs" "suc r # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (suc r # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (suc r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (suc r # map fst txs) [] (length txs)) ∩ FvarsT ?t = {}›*) getFrN_Fvars[of "map snd txs" "suc r # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (suc r # map fst txs) ⊆ trm; set [] ⊆ fmla; ?φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (suc r # map fst txs) [] (length txs)) ∩ Fvars ?φ = {}›*) getFrN_var[of "map snd txs" "suc r # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (suc r # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (suc r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (suc r # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}›*) getFrN_length[of "map snd txs" "suc r # map fst txs" "[]" "length txs"] (*‹⟦set (map snd (txs::('trm::type × 'var::type) list)) ⊆ (var::'var::type set); set ((suc::'trm::type ⇒ 'trm::type) (r::'trm::type) # map fst txs) ⊆ (trm::'trm::type set); set [] ⊆ (fmla::'fmla::type set)⟧ ⟹ length (getFrN (map snd txs) (suc r # map fst txs) [] (length txs)) = length txs›*) getFrN_length[of "map snd txs" "suc r # map fst txs" "[]" "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (suc r # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (suc r # map fst txs) [] (length txs)) = length txs›*) apply - (*top goal: ‹set (getFrN (map snd txs) (suc r # map fst txs) [] (length txs)) ⊆ var› and 5 goals remain*) subgoal for by auto subgoal for by force subgoal for by auto subgoal for by force (*goals: 1. ‹⟦snd ` set txs ⊆ var; r ∈ trm; fst ` set txs ⊆ trm; ⋀t. ⟦set (map snd txs) ⊆ var; set (suc r # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (suc r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (suc r # map fst txs) [] (length txs)) ∩ FvarsT t = {}; ⋀φ. ⟦set (map snd txs) ⊆ var; set (suc r # map fst txs) ⊆ trm; set [] ⊆ fmla; φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (suc r # map fst txs) [] (length txs)) ∩ Fvars φ = {}; ⋀t. ⟦set (map snd txs) ⊆ var; set (suc r # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (suc r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (suc r # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}; ⟦set (map snd txs) ⊆ var; set (suc r # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (suc r # map fst txs) [] (length txs)) = length txs; ⟦set (map snd txs) ⊆ var; set (suc r # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (suc r # map fst txs) [] (length txs)) = length txs⟧ ⟹ length (getFrN (map snd txs) (suc r # map fst txs) [] (length txs)) = length txs› 2. ‹⟦snd ` set txs ⊆ var; r ∈ trm; fst ` set txs ⊆ trm; ⋀t. ⟦set (map snd txs) ⊆ var; set (suc r # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (suc r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (suc r # map fst txs) [] (length txs)) ∩ FvarsT t = {}; ⋀φ. ⟦set (map snd txs) ⊆ var; set (suc r # map fst txs) ⊆ trm; set [] ⊆ fmla; φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (suc r # map fst txs) [] (length txs)) ∩ Fvars φ = {}; ⋀t. ⟦set (map snd txs) ⊆ var; set (suc r # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (suc r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (suc r # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}; ⟦set (map snd txs) ⊆ var; set (suc r # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (suc r # map fst txs) [] (length txs)) = length txs; ⟦set (map snd txs) ⊆ var; set (suc r # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (suc r # map fst txs) [] (length txs)) = length txs⟧ ⟹ distinct (getFrN (map snd txs) (suc r # map fst txs) [] (length txs))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . define vs where vs: "vs ≡ getFrN (map snd txs) (r # map fst txs) [] (length txs)" have vs_facts: "set vs ⊆ var" "set vs ∩ FvarsT r = {}" "set vs ∩ ⋃ (FvarsT ` (fst ` (set txs))) = {}" "set vs ∩ snd ` (set txs) = {}" "length vs = length txs" "distinct vs" using assms(2) (*‹snd ` set txs ⊆ var›*) "000" (*‹(r::'trm) ∈ (trm::'trm set)› ‹fst ` set txs ⊆ trm›*) unfolding vs (*goals: 1. ‹set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ⊆ var› 2. ‹set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ FvarsT r = {}› 3. ‹set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ ⋃ (FvarsT ` fst ` set txs) = {}› 4. ‹set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ snd ` set txs = {}› 5. ‹length (getFrN (map snd txs) (r # map fst txs) [] (length txs)) = length txs› 6. ‹distinct (getFrN (map snd txs) (r # map fst txs) [] (length txs))›*) using getFrN_FvarsT[of "map snd txs" "r # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ FvarsT ?t = {}›*) getFrN_Fvars[of "map snd txs" "r # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd (txs::('trm × 'var) list)) ⊆ (var::'var set); set ((r::'trm) # map fst txs) ⊆ (trm::'trm set); set [] ⊆ (fmla::'fmla set); (?φ::'fmla) ∈ set []⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ (Fvars::'fmla ⇒ 'var set) ?φ = {}›*) getFrN_var[of "map snd txs" "r # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}›*) getFrN_length[of "map snd txs" "r # map fst txs" "[]" "length txs"] (*‹⟦set (map snd (txs::('trm × 'var) list)) ⊆ (var::'var set); set ((r::'trm) # map fst txs) ⊆ (trm::'trm set); set [] ⊆ (fmla::'fmla set)⟧ ⟹ length (getFrN (map snd txs) (r # map fst txs) [] (length txs)) = length txs›*) getFrN_length[of "map snd txs" "r # map fst txs" "[]" "length txs"] (*‹⟦set (map snd (txs::('trm × 'var) list)) ⊆ (var::'var set); set ((r::'trm) # map fst txs) ⊆ (trm::'trm set); set [] ⊆ (fmla::'fmla set)⟧ ⟹ length (getFrN (map snd txs) (r # map fst txs) [] (length txs)) = length txs›*) apply - (*top goal: ‹set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ⊆ var› and 5 goals remain*) subgoal for by auto subgoal for by auto subgoal for by auto subgoal for by force (*goals: 1. ‹⟦snd ` set txs ⊆ var; r ∈ trm; fst ` set txs ⊆ trm; ⋀t. ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ FvarsT t = {}; ⋀φ. ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ Fvars φ = {}; ⋀t. ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}; ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r # map fst txs) [] (length txs)) = length txs; ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r # map fst txs) [] (length txs)) = length txs⟧ ⟹ length (getFrN (map snd txs) (r # map fst txs) [] (length txs)) = length txs› 2. ‹⟦snd ` set txs ⊆ var; r ∈ trm; fst ` set txs ⊆ trm; ⋀t. ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ FvarsT t = {}; ⋀φ. ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ Fvars φ = {}; ⋀t. ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (r # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}; ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r # map fst txs) [] (length txs)) = length txs; ⟦set (map snd txs) ⊆ var; set (r # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r # map fst txs) [] (length txs)) = length txs⟧ ⟹ distinct (getFrN (map snd txs) (r # map fst txs) [] (length txs))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have 0: "rawpsubstT (suc r) (zip (map Var vs) (map snd txs)) = suc (rawpsubstT r (zip (map Var vs) (map snd txs)))" using assms (*‹r ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set (txs::('trm × 'var) list) ⊆ atrm› ‹distinct (map snd txs)›*) vs_facts (*‹set (vs::'var::type list) ⊆ (var::'var::type set)› ‹set vs ∩ FvarsT r = {}› ‹set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set vs ∩ snd ` set txs = {}› ‹length vs = length txs› ‹distinct vs›*) apply (intro rawpsubstT_suc (*‹⟦?r ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT (suc ?r) ?txs = suc (rawpsubstT ?r ?txs)›*)) (*goals: 1. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set vs ⊆ var; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs⟧ ⟹ r ∈ trm› 2. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set vs ⊆ var; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs⟧ ⟹ snd ` set (zip (map Var vs) (map snd txs)) ⊆ var› 3. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set vs ⊆ var; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs⟧ ⟹ fst ` set (zip (map Var vs) (map snd txs)) ⊆ trm› discuss goal 1*) apply ((auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 2*) apply ((auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 3*) apply ((auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*proven 3 subgoals*) . have "rawpsubstT (rawpsubstT (suc r) (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT (rawpsubstT (suc r) (zip (map Var vs) (map snd txs))) (zip (map fst txs) vs)" using assms (*‹r ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹distinct (map snd txs)›*) us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT r = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct (us::'var list)›*) vs_facts (*‹set vs ⊆ var› ‹set vs ∩ FvarsT r = {}› ‹set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set vs ∩ snd ` set txs = {}› ‹length vs = length txs› ‹distinct vs›*) apply (intro rawpsubstT_compose_freshVar2 (*‹⟦?r ∈ atrm; set ?ts ⊆ atrm; set ?xs ⊆ var; distinct ?xs; set ?us ⊆ var; distinct ?us; set ?us ∩ FvarsT ?r = {}; set ?us ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?us ∩ set ?xs = {}; set ?vs ⊆ var; distinct ?vs; set ?vs ∩ FvarsT ?r = {}; set ?vs ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?vs ∩ set ?xs = {}; length ?us = length ?xs; length ?vs = length ?xs; length ?ts = length ?xs⟧ ⟹ rawpsubstT (rawpsubstT ?r (zip (map Var ?us) ?xs)) (zip ?ts ?us) = rawpsubstT (rawpsubstT ?r (zip (map Var ?vs) ?xs)) (zip ?ts ?vs)›*)) (*goals: 1. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs ⊆ var; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs⟧ ⟹ suc r ∈ atrm› 2. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs ⊆ var; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs⟧ ⟹ set (map fst txs) ⊆ atrm› 3. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs ⊆ var; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs⟧ ⟹ set (map snd txs) ⊆ var› 4. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs ⊆ var; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs⟧ ⟹ distinct (map snd txs)› 5. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs ⊆ var; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs⟧ ⟹ set us ⊆ var› 6. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs ⊆ var; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs⟧ ⟹ distinct us› 7. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs ⊆ var; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs⟧ ⟹ set us ∩ FvarsT (suc r) = {}› 8. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs ⊆ var; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs⟧ ⟹ set us ∩ ⋃ (FvarsT ` set (map fst txs)) = {}› 9. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs ⊆ var; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs⟧ ⟹ set us ∩ set (map snd txs) = {}› 10. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs ⊆ var; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs⟧ ⟹ set vs ⊆ var› 11. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs ⊆ var; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs⟧ ⟹ distinct vs› 12. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs ⊆ var; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs⟧ ⟹ set vs ∩ FvarsT (suc r) = {}› 13. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs ⊆ var; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs⟧ ⟹ set vs ∩ ⋃ (FvarsT ` set (map fst txs)) = {}› 14. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs ⊆ var; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs⟧ ⟹ set vs ∩ set (map snd txs) = {}› 15. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs ⊆ var; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs⟧ ⟹ length us = length (map snd txs)› 16. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs ⊆ var; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs⟧ ⟹ length vs = length (map snd txs)› 17. ‹⟦r ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs ⊆ var; set vs ∩ FvarsT r = {}; set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs ∩ snd ` set txs = {}; length vs = length txs; distinct vs⟧ ⟹ length (map fst txs) = length (map snd txs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*discuss goal 9*) apply ((auto)[1]) (*discuss goal 10*) apply ((auto)[1]) (*discuss goal 11*) apply ((auto)[1]) (*discuss goal 12*) apply ((auto)[1]) (*discuss goal 13*) apply ((auto)[1]) (*discuss goal 14*) apply ((auto)[1]) (*discuss goal 15*) apply ((auto)[1]) (*discuss goal 16*) apply ((auto)[1]) (*discuss goal 17*) apply ((auto)[1]) (*proven 17 subgoals*) . also (*calculation: ‹rawpsubstT (rawpsubstT (suc r) (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT (rawpsubstT (suc r) (zip (map Var vs) (map snd txs))) (zip (map fst txs) vs)›*) have "… = suc (rawpsubstT (rawpsubstT r (zip (map Var vs) (map snd txs))) (zip (map fst txs) vs))" unfolding "0" (*goal: ‹rawpsubstT (suc (rawpsubstT r (zip (map Var vs) (map snd txs)))) (zip (map fst txs) vs) = suc (rawpsubstT (rawpsubstT r (zip (map Var vs) (map snd txs))) (zip (map fst txs) vs))›*) using assms (*‹r ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹distinct (map snd txs)›*) vs_facts (*‹set vs ⊆ var› ‹set vs ∩ FvarsT r = {}› ‹set vs ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set vs ∩ snd ` set txs = {}› ‹length vs = length txs› ‹distinct vs›*) apply (intro rawpsubstT_suc (*‹⟦(?r::'trm) ∈ (trm::'trm set); snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ((suc::'trm ⇒ 'trm) ?r) ?txs = suc (rawpsubstT ?r ?txs)›*)) (*goal: ‹rawpsubstT (suc (rawpsubstT r (zip (map Var vs) (map snd txs)))) (zip (map fst txs) vs) = suc (rawpsubstT (rawpsubstT r (zip (map Var vs) (map snd txs))) (zip (map fst txs) vs))›*) subgoal for by (auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*)) subgoal for by (auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*)) subgoal for by (fastforce dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) simp: Int_def (*‹?A ∩ ?B = {x ∈ ?A. x ∈ ?B}›*)) . finally (*calculation: ‹rawpsubstT (rawpsubstT (suc r) (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = suc (rawpsubstT (rawpsubstT r (zip (map Var vs) (map snd txs))) (zip (map fst txs) vs))›*) show "?thesis" (*goal: ‹psubstT ((suc::'trm ⇒ 'trm) (r::'trm)) (txs::('trm × 'var) list) = suc (psubstT r txs)›*) by (simp add: Let_def (*‹Let (?s::?'a::type) (?f::?'a::type ⇒ ?'b::type) ≡ ?f ?s›*) us[symmetric] (*‹getFrN (map snd (txs::('trm::type × 'var::type) list)) ((suc::'trm::type ⇒ 'trm::type) (r::'trm::type) # map fst txs) [] (length txs) ≡ us::'var::type list›*) vs[symmetric] (*‹getFrN (map snd (txs::('trm::type × 'var::type) list)) ((r::'trm::type) # map fst txs) [] (length txs) ≡ vs::'var::type list›*) psubstT_def (*‹psubstT (?t::'trm::type) (?txs::('trm::type × 'var::type) list) = (let xs::'var::type list = map snd ?txs; ts::'trm::type list = map fst ?txs; us::'var::type list = getFrN xs (?t # ts) [] (length xs) in rawpsubstT (rawpsubstT ?t (zip (map (Var::'var::type ⇒ 'trm::type) us) xs)) (zip ts us))›*)) qed lemma rawpsubstT_pls: assumes "r1 ∈ trm" "r2 ∈ trm" and "snd ` (set txs) ⊆ var" and "fst ` (set txs) ⊆ trm" shows "rawpsubstT (pls r1 r2) txs = pls (rawpsubstT r1 txs) (rawpsubstT r2 txs)" using assms (*‹r1 ∈ trm› ‹r2 ∈ trm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ trm›*) apply (induct txs arbitrary: r1 r2) (*goal: ‹rawpsubstT (pls r1 r2) txs = pls (rawpsubstT r1 txs) (rawpsubstT r2 txs)›*) subgoal for by simp subgoal for tx and txs and r apply (cases tx) (*goal: ‹⟦⋀r1 r2. ⟦r1 ∈ trm; r2 ∈ trm; snd ` set txs ⊆ var; fst ` set txs ⊆ trm⟧ ⟹ rawpsubstT (pls r1 r2) txs = pls (rawpsubstT r1 txs) (rawpsubstT r2 txs); r ∈ trm; r2_ ∈ trm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ trm⟧ ⟹ rawpsubstT (pls r r2_) (tx # txs) = pls (rawpsubstT r (tx # txs)) (rawpsubstT r2_ (tx # txs))›*) by auto . lemma psubstT_pls[simp]: assumes "r1 ∈ atrm" "r2 ∈ atrm" and "snd ` (set txs) ⊆ var" and "fst ` (set txs) ⊆ atrm" and "distinct (map snd txs)" shows "psubstT (pls r1 r2) txs = pls (psubstT r1 txs) (psubstT r2 txs)" proof (-) (*goal: ‹psubstT (pls r1 r2) txs = pls (psubstT r1 txs) (psubstT r2 txs)›*) have 000: "fst ` (set txs) ⊆ trm" using assms (*‹r1 ∈ atrm› ‹r2 ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹distinct (map snd txs)›*) by auto define us where us: "us ≡ getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)" have us_facts: "set us ⊆ var" "set us ∩ FvarsT r1 = {}" "set us ∩ FvarsT r2 = {}" "set us ∩ ⋃ (FvarsT ` (fst ` (set txs))) = {}" "set us ∩ snd ` (set txs) = {}" "length us = length txs" "distinct us" using assms(1-3) (*‹(r1::'trm::type) ∈ atrm› ‹r2 ∈ atrm› ‹snd ` set txs ⊆ var›*) "000" (*‹fst ` set txs ⊆ trm›*) unfolding us (*goals: 1. ‹set (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)) ⊆ var› 2. ‹set (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)) ∩ FvarsT r1 = {}› 3. ‹set (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)) ∩ FvarsT r2 = {}› 4. ‹set (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)) ∩ ⋃ (FvarsT ` fst ` set txs) = {}› 5. ‹set (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)) ∩ snd ` set txs = {}› 6. ‹length (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)) = length txs› 7. ‹distinct (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs))›*) using getFrN_FvarsT[of "map snd txs" "pls r1 r2 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (pls r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (pls r1 r2 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)) ∩ FvarsT ?t = {}›*) getFrN_Fvars[of "map snd txs" "pls r1 r2 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (pls r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; ?φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)) ∩ Fvars ?φ = {}›*) getFrN_var[of "map snd txs" "pls r1 r2 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (pls r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (pls r1 r2 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}›*) getFrN_length[of "map snd txs" "pls r1 r2 # map fst txs" "[]" "length txs"] (*‹⟦set (map snd (txs::('trm::type × 'var::type) list)) ⊆ (var::'var::type set); set ((pls::'trm::type ⇒ 'trm::type ⇒ 'trm::type) (r1::'trm::type) (r2::'trm::type) # map fst txs) ⊆ (trm::'trm::type set); set [] ⊆ (fmla::'fmla::type set)⟧ ⟹ length (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)) = length txs›*) getFrN_length[of "map snd txs" "pls r1 r2 # map fst txs" "[]" "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (pls r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)) = length txs›*) apply - (*top goal: ‹set (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)) ⊆ var› and 6 goals remain*) subgoal for by auto subgoal for by force subgoal for by force subgoal for by auto subgoal for by force (*goals: 1. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; ⋀t. ⟦set (map snd txs) ⊆ var; set (pls r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (pls r1 r2 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)) ∩ FvarsT t = {}; ⋀φ. ⟦set (map snd txs) ⊆ var; set (pls r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)) ∩ Fvars φ = {}; ⋀t. ⟦set (map snd txs) ⊆ var; set (pls r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (pls r1 r2 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}; ⟦set (map snd txs) ⊆ var; set (pls r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)) = length txs; ⟦set (map snd txs) ⊆ var; set (pls r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)) = length txs⟧ ⟹ length (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)) = length txs› 2. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; ⋀t. ⟦set (map snd txs) ⊆ var; set (pls r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (pls r1 r2 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)) ∩ FvarsT t = {}; ⋀φ. ⟦set (map snd txs) ⊆ var; set (pls r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)) ∩ Fvars φ = {}; ⋀t. ⟦set (map snd txs) ⊆ var; set (pls r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (pls r1 r2 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}; ⟦set (map snd txs) ⊆ var; set (pls r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)) = length txs; ⟦set (map snd txs) ⊆ var; set (pls r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs)) = length txs⟧ ⟹ distinct (getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . define vs1 where vs1: "vs1 ≡ getFrN (map snd txs) (r1 # map fst txs) [] (length txs)" have vs1_facts: "set vs1 ⊆ var" "set vs1 ∩ FvarsT r1 = {}" "set vs1 ∩ ⋃ (FvarsT ` (fst ` (set txs))) = {}" "set vs1 ∩ snd ` (set txs) = {}" "length vs1 = length txs" "distinct vs1" using assms(1-3) (*‹(r1::'trm::type) ∈ atrm› ‹r2 ∈ atrm› ‹snd ` set txs ⊆ var›*) "000" (*‹fst ` set txs ⊆ trm›*) unfolding vs1 (*goals: 1. ‹set (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) ⊆ var› 2. ‹set (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) ∩ FvarsT r1 = {}› 3. ‹set (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) ∩ ⋃ (FvarsT ` fst ` set txs) = {}› 4. ‹set (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) ∩ snd ` set txs = {}› 5. ‹length (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) = length txs› 6. ‹distinct (getFrN (map snd txs) (r1 # map fst txs) [] (length txs))›*) using getFrN_FvarsT[of "map snd txs" "r1 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r1 # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (r1 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) ∩ FvarsT ?t = {}›*) getFrN_Fvars[of "map snd txs" "r1 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r1 # map fst txs) ⊆ trm; set [] ⊆ fmla; ?φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) ∩ Fvars ?φ = {}›*) getFrN_var[of "map snd txs" "r1 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd (txs::('trm × 'var) list)) ⊆ (var::'var set); set ((r1::'trm) # map fst txs) ⊆ (trm::'trm set); set [] ⊆ (fmla::'fmla set); (?t::'trm) ∈ set (r1 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}›*) getFrN_length[of "map snd txs" "r1 # map fst txs" "[]" "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r1 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) = length txs›*) getFrN_length[of "map snd txs" "r1 # map fst txs" "[]" "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r1 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) = length txs›*) apply - (*top goal: ‹set (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) ⊆ var› and 5 goals remain*) subgoal for by auto subgoal for by auto subgoal for by auto subgoal for by force (*goals: 1. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; ⋀t. ⟦set (map snd txs) ⊆ var; set (r1 # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (r1 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) ∩ FvarsT t = {}; ⋀φ. ⟦set (map snd txs) ⊆ var; set (r1 # map fst txs) ⊆ trm; set [] ⊆ fmla; φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) ∩ Fvars φ = {}; ⋀t. ⟦set (map snd txs) ⊆ var; set (r1 # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (r1 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}; ⟦set (map snd txs) ⊆ var; set (r1 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) = length txs; ⟦set (map snd txs) ⊆ var; set (r1 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) = length txs⟧ ⟹ length (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) = length txs› 2. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; ⋀t. ⟦set (map snd txs) ⊆ var; set (r1 # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (r1 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) ∩ FvarsT t = {}; ⋀φ. ⟦set (map snd txs) ⊆ var; set (r1 # map fst txs) ⊆ trm; set [] ⊆ fmla; φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) ∩ Fvars φ = {}; ⋀t. ⟦set (map snd txs) ⊆ var; set (r1 # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (r1 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}; ⟦set (map snd txs) ⊆ var; set (r1 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) = length txs; ⟦set (map snd txs) ⊆ var; set (r1 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) = length txs⟧ ⟹ distinct (getFrN (map snd txs) (r1 # map fst txs) [] (length txs))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . define vs2 where vs2: "vs2 ≡ getFrN (map snd txs) (r2 # map fst txs) [] (length txs)" have vs2_facts: "set vs2 ⊆ var" "set vs2 ∩ FvarsT r2 = {}" "set vs2 ∩ ⋃ (FvarsT ` (fst ` (set txs))) = {}" "set vs2 ∩ snd ` (set txs) = {}" "length vs2 = length txs" "distinct vs2" using assms(1-3) (*‹r1 ∈ atrm› ‹r2 ∈ atrm› ‹snd ` set txs ⊆ var›*) "000" (*‹fst ` set (txs::('trm × 'var) list) ⊆ (trm::'trm set)›*) unfolding vs2 (*goals: 1. ‹set (getFrN (map snd (txs::('trm::type × 'var::type) list)) ((r2::'trm::type) # map fst txs) [] (length txs)) ⊆ (var::'var::type set)› 2. ‹set (getFrN (map snd (txs::('trm::type × 'var::type) list)) ((r2::'trm::type) # map fst txs) [] (length txs)) ∩ (FvarsT::'trm::type ⇒ 'var::type set) r2 = {}› 3. ‹set (getFrN (map snd (txs::('trm::type × 'var::type) list)) ((r2::'trm::type) # map fst txs) [] (length txs)) ∩ ⋃ ((FvarsT::'trm::type ⇒ 'var::type set) ` fst ` set txs) = {}› 4. ‹set (getFrN (map snd (txs::('trm::type × 'var::type) list)) ((r2::'trm::type) # map fst txs) [] (length txs)) ∩ snd ` set txs = {}› 5. ‹length (getFrN (map snd (txs::('trm::type × 'var::type) list)) ((r2::'trm::type) # map fst txs) [] (length txs)) = length txs› 6. ‹distinct (getFrN (map snd (txs::('trm::type × 'var::type) list)) ((r2::'trm::type) # map fst txs) [] (length txs))›*) using getFrN_FvarsT[of "map snd txs" "r2 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (r2 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) ∩ FvarsT ?t = {}›*) getFrN_Fvars[of "map snd txs" "r2 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd (txs::('trm × 'var) list)) ⊆ (var::'var set); set ((r2::'trm) # map fst txs) ⊆ (trm::'trm set); set [] ⊆ (fmla::'fmla set); (?φ::'fmla) ∈ set []⟧ ⟹ set (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) ∩ (Fvars::'fmla ⇒ 'var set) ?φ = {}›*) getFrN_var[of "map snd txs" "r2 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (r2 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}›*) getFrN_length[of "map snd txs" "r2 # map fst txs" "[]" "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r2 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) = length txs›*) getFrN_length[of "map snd txs" "r2 # map fst txs" "[]" "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r2 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) = length txs›*) apply - (*top goal: ‹set (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) ⊆ var› and 5 goals remain*) subgoal for by auto subgoal for by auto subgoal for by auto subgoal for by force (*goals: 1. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; ⋀t. ⟦set (map snd txs) ⊆ var; set (r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (r2 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) ∩ FvarsT t = {}; ⋀φ. ⟦set (map snd txs) ⊆ var; set (r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) ∩ Fvars φ = {}; ⋀t. ⟦set (map snd txs) ⊆ var; set (r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (r2 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}; ⟦set (map snd txs) ⊆ var; set (r2 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) = length txs; ⟦set (map snd txs) ⊆ var; set (r2 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) = length txs⟧ ⟹ length (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) = length txs› 2. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ trm; ⋀t. ⟦set (map snd txs) ⊆ var; set (r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (r2 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) ∩ FvarsT t = {}; ⋀φ. ⟦set (map snd txs) ⊆ var; set (r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) ∩ Fvars φ = {}; ⋀t. ⟦set (map snd txs) ⊆ var; set (r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (r2 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}; ⟦set (map snd txs) ⊆ var; set (r2 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) = length txs; ⟦set (map snd txs) ⊆ var; set (r2 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) = length txs⟧ ⟹ distinct (getFrN (map snd txs) (r2 # map fst txs) [] (length txs))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have 0: "rawpsubstT (pls r1 r2) (zip (map Var us) (map snd txs)) = pls (rawpsubstT r1 (zip (map Var us) (map snd txs))) (rawpsubstT r2 (zip (map Var us) (map snd txs)))" using assms (*‹r1 ∈ atrm› ‹r2 ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹distinct (map snd txs)›*) us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT r1 = {}› ‹set (us::'var list) ∩ (FvarsT::'trm ⇒ 'var set) (r2::'trm) = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹length (us::'var list) = length (txs::('trm × 'var) list)› ‹distinct us›*) apply (intro rawpsubstT_pls (*‹⟦?r1.0 ∈ trm; ?r2.0 ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT (pls ?r1.0 ?r2.0) ?txs = pls (rawpsubstT ?r1.0 ?txs) (rawpsubstT ?r2.0 ?txs)›*)) (*goals: 1. ‹⟦(r1::'trm) ∈ atrm; (r2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ r1 ∈ (trm::'trm set)› 2. ‹⟦(r1::'trm) ∈ atrm; (r2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ r2 ∈ (trm::'trm set)› 3. ‹⟦(r1::'trm) ∈ atrm; (r2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ snd ` set (zip (map (Var::'var ⇒ 'trm) us) (map snd txs)) ⊆ var› 4. ‹⟦(r1::'trm) ∈ atrm; (r2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ atrm; distinct (map snd txs); set (us::'var list) ⊆ var; set us ∩ (FvarsT::'trm ⇒ 'var set) r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ fst ` set (zip (map (Var::'var ⇒ 'trm) us) (map snd txs)) ⊆ (trm::'trm set)› discuss goal 1*) apply ((auto dest!: set_zip_D (*‹(?x::?'a::type, ?y::?'b::type) ∈ set (zip (?xs::?'a::type list) (?ys::?'b::type list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 2*) apply ((auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 3*) apply ((auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 4*) apply ((auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*proven 4 subgoals*) . have 1: "rawpsubstT (rawpsubstT r1 (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT (rawpsubstT r1 (zip (map Var vs1) (map snd txs))) (zip (map fst txs) vs1)" using assms (*‹r1 ∈ atrm› ‹(r2::'trm) ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹distinct (map snd (txs::('trm::type × 'var::type) list))›*) us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT r1 = {}› ‹set us ∩ FvarsT r2 = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set (us::'var::type list) ∩ snd ` set (txs::('trm::type × 'var::type) list) = {}› ‹length us = length txs› ‹distinct (us::'var::type list)›*) vs1_facts (*‹set vs1 ⊆ var› ‹set vs1 ∩ FvarsT r1 = {}› ‹set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set vs1 ∩ snd ` set txs = {}› ‹length vs1 = length txs› ‹distinct vs1›*) apply (intro rawpsubstT_compose_freshVar2 (*‹⟦(?r::'trm) ∈ atrm; set (?ts::'trm list) ⊆ atrm; set (?xs::'var list) ⊆ (var::'var set); distinct ?xs; set (?us::'var list) ⊆ var; distinct ?us; set ?us ∩ (FvarsT::'trm ⇒ 'var set) ?r = {}; set ?us ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?us ∩ set ?xs = {}; set (?vs::'var list) ⊆ var; distinct ?vs; set ?vs ∩ FvarsT ?r = {}; set ?vs ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?vs ∩ set ?xs = {}; length ?us = length ?xs; length ?vs = length ?xs; length ?ts = length ?xs⟧ ⟹ rawpsubstT (rawpsubstT ?r (zip (map (Var::'var ⇒ 'trm) ?us) ?xs)) (zip ?ts ?us) = rawpsubstT (rawpsubstT ?r (zip (map Var ?vs) ?xs)) (zip ?ts ?vs)›*)) (*goals: 1. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ r1 ∈ atrm› 2. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set (map fst txs) ⊆ atrm› 3. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set (map snd txs) ⊆ var› 4. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ distinct (map snd txs)› 5. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set us ⊆ var› 6. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ distinct us› 7. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set us ∩ FvarsT r1 = {}› 8. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set us ∩ ⋃ (FvarsT ` set (map fst txs)) = {}› 9. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set us ∩ set (map snd txs) = {}› 10. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set vs1 ⊆ var› 11. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ distinct vs1› 12. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set vs1 ∩ FvarsT r1 = {}› 13. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set vs1 ∩ ⋃ (FvarsT ` set (map fst txs)) = {}› 14. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set vs1 ∩ set (map snd txs) = {}› 15. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ length us = length (map snd txs)› 16. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ length vs1 = length (map snd txs)› 17. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ length (map fst txs) = length (map snd txs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*discuss goal 9*) apply ((auto)[1]) (*discuss goal 10*) apply ((auto)[1]) (*discuss goal 11*) apply ((auto)[1]) (*discuss goal 12*) apply ((auto)[1]) (*discuss goal 13*) apply ((auto)[1]) (*discuss goal 14*) apply ((auto)[1]) (*discuss goal 15*) apply ((auto)[1]) (*discuss goal 16*) apply ((auto)[1]) (*discuss goal 17*) apply ((auto)[1]) (*proven 17 subgoals*) . have 2: "rawpsubstT (rawpsubstT r2 (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT (rawpsubstT r2 (zip (map Var vs2) (map snd txs))) (zip (map fst txs) vs2)" using assms (*‹r1 ∈ atrm› ‹r2 ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹distinct (map snd txs)›*) us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT r1 = {}› ‹set us ∩ FvarsT r2 = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct us›*) vs2_facts (*‹set vs2 ⊆ var› ‹set vs2 ∩ FvarsT r2 = {}› ‹set (vs2::'var::type list) ∩ ⋃ ((FvarsT::'trm::type ⇒ 'var::type set) ` fst ` set (txs::('trm::type × 'var::type) list)) = {}› ‹set vs2 ∩ snd ` set txs = {}› ‹length vs2 = length txs› ‹distinct vs2›*) apply (intro rawpsubstT_compose_freshVar2 (*‹⟦?r ∈ atrm; set ?ts ⊆ atrm; set ?xs ⊆ var; distinct ?xs; set ?us ⊆ var; distinct ?us; set ?us ∩ FvarsT ?r = {}; set ?us ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?us ∩ set ?xs = {}; set ?vs ⊆ var; distinct ?vs; set ?vs ∩ FvarsT ?r = {}; set ?vs ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?vs ∩ set ?xs = {}; length ?us = length ?xs; length ?vs = length ?xs; length ?ts = length ?xs⟧ ⟹ rawpsubstT (rawpsubstT ?r (zip (map Var ?us) ?xs)) (zip ?ts ?us) = rawpsubstT (rawpsubstT ?r (zip (map Var ?vs) ?xs)) (zip ?ts ?vs)›*)) (*goals: 1. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ r2 ∈ atrm› 2. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set (map fst txs) ⊆ atrm› 3. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set (map snd txs) ⊆ var› 4. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ distinct (map snd txs)› 5. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set us ⊆ var› 6. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ distinct us› 7. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set us ∩ FvarsT r2 = {}› 8. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set us ∩ ⋃ (FvarsT ` set (map fst txs)) = {}› 9. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set us ∩ set (map snd txs) = {}› 10. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set vs2 ⊆ var› 11. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ distinct vs2› 12. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set vs2 ∩ FvarsT r2 = {}› 13. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set vs2 ∩ ⋃ (FvarsT ` set (map fst txs)) = {}› 14. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set vs2 ∩ set (map snd txs) = {}› 15. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ length us = length (map snd txs)› 16. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ length vs2 = length (map snd txs)› 17. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ length (map fst txs) = length (map snd txs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*discuss goal 9*) apply ((auto)[1]) (*discuss goal 10*) apply ((auto)[1]) (*discuss goal 11*) apply ((auto)[1]) (*discuss goal 12*) apply ((auto)[1]) (*discuss goal 13*) apply ((auto)[1]) (*discuss goal 14*) apply ((auto)[1]) (*discuss goal 15*) apply ((auto)[1]) (*discuss goal 16*) apply ((auto)[1]) (*discuss goal 17*) apply ((auto)[1]) (*proven 17 subgoals*) . have 3: "rawpsubstT (rawpsubstT (pls r1 r2) (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = pls (rawpsubstT (rawpsubstT r1 (zip (map Var us) (map snd txs))) (zip (map fst txs) us)) (rawpsubstT (rawpsubstT r2 (zip (map Var us) (map snd txs))) (zip (map fst txs) us))" unfolding "0" (*goal: ‹rawpsubstT (pls (rawpsubstT r1 (zip (map Var us) (map snd txs))) (rawpsubstT r2 (zip (map Var us) (map snd txs)))) (zip (map fst txs) us) = pls (rawpsubstT (rawpsubstT r1 (zip (map Var us) (map snd txs))) (zip (map fst txs) us)) (rawpsubstT (rawpsubstT r2 (zip (map Var us) (map snd txs))) (zip (map fst txs) us))›*) using assms (*‹(r1::'trm::type) ∈ atrm› ‹r2 ∈ atrm› ‹snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set)› ‹fst ` set (txs::('trm × 'var) list) ⊆ atrm› ‹distinct (map snd txs)›*) us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT r1 = {}› ‹set us ∩ FvarsT r2 = {}› ‹set (us::'var list) ∩ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set (txs::('trm × 'var) list)) = {}› ‹set (us::'var list) ∩ snd ` set (txs::('trm × 'var) list) = {}› ‹length (us::'var list) = length (txs::('trm × 'var) list)› ‹distinct us›*) apply (intro rawpsubstT_pls (*‹⟦?r1.0 ∈ trm; ?r2.0 ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT (pls ?r1.0 ?r2.0) ?txs = pls (rawpsubstT ?r1.0 ?txs) (rawpsubstT ?r2.0 ?txs)›*)) (*goal: ‹rawpsubstT (pls (rawpsubstT r1 (zip (map Var us) (map snd txs))) (rawpsubstT r2 (zip (map Var us) (map snd txs)))) (zip (map fst txs) us) = pls (rawpsubstT (rawpsubstT r1 (zip (map Var us) (map snd txs))) (zip (map fst txs) us)) (rawpsubstT (rawpsubstT r2 (zip (map Var us) (map snd txs))) (zip (map fst txs) us))›*) subgoal for by (auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*)) subgoal for by (force dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) simp: Int_def (*‹?A ∩ ?B = {x ∈ ?A. x ∈ ?B}›*)) subgoal for by (auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*)) subgoal for by (fastforce dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) simp: Int_def (*‹?A ∩ ?B = {x ∈ ?A. x ∈ ?B}›*)) . show "?thesis" (*goal: ‹psubstT (pls r1 r2) txs = pls (psubstT r1 txs) (psubstT r2 txs)›*) unfolding psubstT_def (*goal: ‹(let xs = map snd txs; ts = map fst txs; us = getFrN xs (pls r1 r2 # ts) [] (length xs) in rawpsubstT (rawpsubstT (pls r1 r2) (zip (map Var us) xs)) (zip ts us)) = pls (let xs = map snd txs; ts = map fst txs; us = getFrN xs (r1 # ts) [] (length xs) in rawpsubstT (rawpsubstT r1 (zip (map Var us) xs)) (zip ts us)) (let xs = map snd txs; ts = map fst txs; us = getFrN xs (r2 # ts) [] (length xs) in rawpsubstT (rawpsubstT r2 (zip (map Var us) xs)) (zip ts us))›*) by (simp add: Let_def (*‹Let ?s ?f ≡ ?f ?s›*) us[symmetric] (*‹getFrN (map snd txs) (pls r1 r2 # map fst txs) [] (length txs) ≡ us›*) vs1[symmetric] (*‹getFrN (map snd txs) (r1 # map fst txs) [] (length txs) ≡ vs1›*) vs2[symmetric] (*‹getFrN (map snd txs) (r2 # map fst txs) [] (length txs) ≡ vs2›*) 1 (*‹rawpsubstT (rawpsubstT r1 (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT (rawpsubstT r1 (zip (map Var vs1) (map snd txs))) (zip (map fst txs) vs1)›*) 2 (*‹rawpsubstT (rawpsubstT r2 (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT (rawpsubstT r2 (zip (map Var vs2) (map snd txs))) (zip (map fst txs) vs2)›*) 3 (*‹rawpsubstT (rawpsubstT (pls r1 r2) (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = pls (rawpsubstT (rawpsubstT r1 (zip (map Var us) (map snd txs))) (zip (map fst txs) us)) (rawpsubstT (rawpsubstT r2 (zip (map Var us) (map snd txs))) (zip (map fst txs) us))›*)) qed lemma rawpsubstT_tms: assumes "r1 ∈ trm" "r2 ∈ trm" and "snd ` (set txs) ⊆ var" and "fst ` (set txs) ⊆ trm" shows "rawpsubstT (tms r1 r2) txs = tms (rawpsubstT r1 txs) (rawpsubstT r2 txs)" using assms (*‹(r1::'trm::type) ∈ (trm::'trm::type set)› ‹r2 ∈ trm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ trm›*) apply (induct txs arbitrary: r1 r2) (*goal: ‹rawpsubstT ((tms::'trm ⇒ 'trm ⇒ 'trm) (r1::'trm) (r2::'trm)) (txs::('trm × 'var) list) = tms (rawpsubstT r1 txs) (rawpsubstT r2 txs)›*) subgoal for by simp subgoal for tx and txs and r apply (cases tx) (*goal: ‹⟦⋀r1 r2. ⟦r1 ∈ trm; r2 ∈ trm; snd ` set txs ⊆ var; fst ` set txs ⊆ trm⟧ ⟹ rawpsubstT (tms r1 r2) txs = tms (rawpsubstT r1 txs) (rawpsubstT r2 txs); r ∈ trm; r2_ ∈ trm; snd ` set (tx # txs) ⊆ var; fst ` set (tx # txs) ⊆ trm⟧ ⟹ rawpsubstT (tms r r2_) (tx # txs) = tms (rawpsubstT r (tx # txs)) (rawpsubstT r2_ (tx # txs))›*) by auto . lemma psubstT_tms[simp]: assumes "r1 ∈ atrm" "r2 ∈ atrm" and "snd ` (set txs) ⊆ var" and "fst ` (set txs) ⊆ atrm" and "distinct (map snd txs)" shows "psubstT (tms r1 r2) txs = tms (psubstT r1 txs) (psubstT r2 txs)" proof (-) (*goal: ‹psubstT (tms r1 r2) txs = tms (psubstT r1 txs) (psubstT r2 txs)›*) have 000: "fst ` (set txs) ⊆ trm" using assms (*‹r1 ∈ atrm› ‹r2 ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹distinct (map snd txs)›*) by auto define us where us: "us ≡ getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)" have us_facts: "set us ⊆ var" "set us ∩ FvarsT r1 = {}" "set us ∩ FvarsT r2 = {}" "set us ∩ ⋃ (FvarsT ` (fst ` (set txs))) = {}" "set us ∩ snd ` (set txs) = {}" "length us = length txs" "distinct us" using assms(1-3) (*‹r1 ∈ atrm› ‹r2 ∈ atrm› ‹snd ` set txs ⊆ var›*) "000" (*‹fst ` set (txs::('trm::type × 'var::type) list) ⊆ (trm::'trm::type set)›*) unfolding us (*goals: 1. ‹set (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)) ⊆ var› 2. ‹set (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)) ∩ FvarsT r1 = {}› 3. ‹set (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)) ∩ FvarsT r2 = {}› 4. ‹set (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)) ∩ ⋃ (FvarsT ` fst ` set txs) = {}› 5. ‹set (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)) ∩ snd ` set txs = {}› 6. ‹length (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)) = length txs› 7. ‹distinct (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs))›*) using getFrN_FvarsT[of "map snd txs" "tms r1 r2 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (tms r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (tms r1 r2 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)) ∩ FvarsT ?t = {}›*) getFrN_Fvars[of "map snd txs" "tms r1 r2 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (tms r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; ?φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)) ∩ Fvars ?φ = {}›*) getFrN_var[of "map snd txs" "tms r1 r2 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd (txs::('trm × 'var) list)) ⊆ (var::'var set); set ((tms::'trm ⇒ 'trm ⇒ 'trm) (r1::'trm) (r2::'trm) # map fst txs) ⊆ (trm::'trm set); set [] ⊆ (fmla::'fmla set); (?t::'trm) ∈ set (tms r1 r2 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}›*) getFrN_length[of "map snd txs" "tms r1 r2 # map fst txs" "[]" "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (tms r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)) = length txs›*) getFrN_length[of "map snd txs" "tms r1 r2 # map fst txs" "[]" "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (tms r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)) = length txs›*) apply - (*top goal: ‹set (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)) ⊆ var› and 6 goals remain*) subgoal for by auto subgoal for by force subgoal for by force subgoal for by auto subgoal for by force (*goals: 1. ‹⟦(r1::'trm) ∈ atrm; (r2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ (trm::'trm set); ⋀t::'trm. ⟦set (map snd txs) ⊆ var; set ((tms::'trm ⇒ 'trm ⇒ 'trm) r1 r2 # map fst txs) ⊆ trm; set [] ⊆ (fmla::'fmla set); t ∈ set (tms r1 r2 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)) ∩ (FvarsT::'trm ⇒ 'var set) t = {}; ⋀φ::'fmla. ⟦set (map snd txs) ⊆ var; set (tms r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)) ∩ (Fvars::'fmla ⇒ 'var set) φ = {}; ⋀t::'trm. ⟦set (map snd txs) ⊆ var; set (tms r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (tms r1 r2 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}; ⟦set (map snd txs) ⊆ var; set (tms r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)) = length txs; ⟦set (map snd txs) ⊆ var; set (tms r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)) = length txs⟧ ⟹ length (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)) = length txs› 2. ‹⟦(r1::'trm) ∈ atrm; (r2::'trm) ∈ atrm; snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set txs ⊆ (trm::'trm set); ⋀t::'trm. ⟦set (map snd txs) ⊆ var; set ((tms::'trm ⇒ 'trm ⇒ 'trm) r1 r2 # map fst txs) ⊆ trm; set [] ⊆ (fmla::'fmla set); t ∈ set (tms r1 r2 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)) ∩ (FvarsT::'trm ⇒ 'var set) t = {}; ⋀φ::'fmla. ⟦set (map snd txs) ⊆ var; set (tms r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)) ∩ (Fvars::'fmla ⇒ 'var set) φ = {}; ⋀t::'trm. ⟦set (map snd txs) ⊆ var; set (tms r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; t ∈ set (tms r1 r2 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}; ⟦set (map snd txs) ⊆ var; set (tms r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)) = length txs; ⟦set (map snd txs) ⊆ var; set (tms r1 r2 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs)) = length txs⟧ ⟹ distinct (getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . define vs1 where vs1: "vs1 ≡ getFrN (map snd txs) (r1 # map fst txs) [] (length txs)" have vs1_facts: "set vs1 ⊆ var" "set vs1 ∩ FvarsT r1 = {}" "set vs1 ∩ ⋃ (FvarsT ` (fst ` (set txs))) = {}" "set vs1 ∩ snd ` (set txs) = {}" "length vs1 = length txs" "distinct vs1" using assms(1-3) (*‹(r1::'trm) ∈ atrm› ‹r2 ∈ atrm› ‹snd ` set (txs::('trm × 'var) list) ⊆ (var::'var set)›*) "000" (*‹fst ` set txs ⊆ trm›*) unfolding vs1 (*goals: 1. ‹set (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) ⊆ var› 2. ‹set (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) ∩ FvarsT r1 = {}› 3. ‹set (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) ∩ ⋃ (FvarsT ` fst ` set txs) = {}› 4. ‹set (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) ∩ snd ` set txs = {}› 5. ‹length (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) = length txs› 6. ‹distinct (getFrN (map snd txs) (r1 # map fst txs) [] (length txs))›*) using getFrN_FvarsT[of "map snd txs" "r1 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r1 # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (r1 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) ∩ FvarsT ?t = {}›*) getFrN_Fvars[of "map snd txs" "r1 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r1 # map fst txs) ⊆ trm; set [] ⊆ fmla; ?φ ∈ set []⟧ ⟹ set (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) ∩ Fvars ?φ = {}›*) getFrN_var[of "map snd txs" "r1 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r1 # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (r1 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}›*) getFrN_length[of "map snd txs" "r1 # map fst txs" "[]" "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r1 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) = length txs›*) getFrN_length[of "map snd txs" "r1 # map fst txs" "[]" "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r1 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) = length txs›*) apply - (*top goal: ‹set (getFrN (map snd txs) (r1 # map fst txs) [] (length txs)) ⊆ var› and 5 goals remain*) subgoal for by auto subgoal for by force subgoal for by auto subgoal for by force subgoal for by force by auto define vs2 where vs2: "vs2 ≡ getFrN (map snd txs) (r2 # map fst txs) [] (length txs)" have vs2_facts: "set vs2 ⊆ var" "set vs2 ∩ FvarsT r2 = {}" "set vs2 ∩ ⋃ (FvarsT ` (fst ` (set txs))) = {}" "set vs2 ∩ snd ` (set txs) = {}" "length vs2 = length txs" "distinct vs2" using assms(1-3) (*‹r1 ∈ atrm› ‹r2 ∈ atrm› ‹snd ` set txs ⊆ var›*) "000" (*‹fst ` set (txs::('trm × 'var) list) ⊆ (trm::'trm set)›*) unfolding vs2 (*goals: 1. ‹set (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) ⊆ var› 2. ‹set (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) ∩ FvarsT r2 = {}› 3. ‹set (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) ∩ ⋃ (FvarsT ` fst ` set txs) = {}› 4. ‹set (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) ∩ snd ` set txs = {}› 5. ‹length (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) = length txs› 6. ‹distinct (getFrN (map snd txs) (r2 # map fst txs) [] (length txs))›*) using getFrN_FvarsT[of "map snd txs" "r2 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (r2 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) ∩ FvarsT ?t = {}›*) getFrN_Fvars[of "map snd txs" "r2 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd (txs::('trm × 'var) list)) ⊆ (var::'var set); set ((r2::'trm) # map fst txs) ⊆ (trm::'trm set); set [] ⊆ (fmla::'fmla set); (?φ::'fmla) ∈ set []⟧ ⟹ set (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) ∩ (Fvars::'fmla ⇒ 'var set) ?φ = {}›*) getFrN_var[of "map snd txs" "r2 # map fst txs" "[]" _ "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r2 # map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set (r2 # map fst txs)⟧ ⟹ set (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) ∩ set (map snd txs) = {}›*) getFrN_length[of "map snd txs" "r2 # map fst txs" "[]" "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r2 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) = length txs›*) getFrN_length[of "map snd txs" "r2 # map fst txs" "[]" "length txs"] (*‹⟦set (map snd txs) ⊆ var; set (r2 # map fst txs) ⊆ trm; set [] ⊆ fmla⟧ ⟹ length (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) = length txs›*) apply - (*top goal: ‹set (getFrN (map snd txs) (r2 # map fst txs) [] (length txs)) ⊆ var› and 5 goals remain*) subgoal for by auto subgoal for by force subgoal for by auto subgoal for by force subgoal for by force by auto have 0: "rawpsubstT (tms r1 r2) (zip (map Var us) (map snd txs)) = tms (rawpsubstT r1 (zip (map Var us) (map snd txs))) (rawpsubstT r2 (zip (map Var us) (map snd txs)))" using assms (*‹r1 ∈ atrm› ‹r2 ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹distinct (map snd txs)›*) us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT r1 = {}› ‹set (us::'var list) ∩ (FvarsT::'trm ⇒ 'var set) (r2::'trm) = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹length (us::'var list) = length (txs::('trm × 'var) list)› ‹distinct us›*) apply (intro rawpsubstT_tms (*‹⟦?r1.0 ∈ trm; ?r2.0 ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT (tms ?r1.0 ?r2.0) ?txs = tms (rawpsubstT ?r1.0 ?txs) (rawpsubstT ?r2.0 ?txs)›*)) (*goals: 1. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ r1 ∈ trm› 2. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ r2 ∈ trm› 3. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ snd ` set (zip (map Var us) (map snd txs)) ⊆ var› 4. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us⟧ ⟹ fst ` set (zip (map Var us) (map snd txs)) ⊆ trm› discuss goal 1*) apply ((auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 2*) apply ((auto dest!: set_zip_D (*‹(?x::?'a::type, ?y::?'b::type) ∈ set (zip (?xs::?'a::type list) (?ys::?'b::type list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 3*) apply ((auto dest!: set_zip_D (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*discuss goal 4*) apply ((auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*))[1]) (*proven 4 subgoals*) . have 1: "rawpsubstT (rawpsubstT r1 (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT (rawpsubstT r1 (zip (map Var vs1) (map snd txs))) (zip (map fst txs) vs1)" using assms (*‹r1 ∈ atrm› ‹r2 ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set (txs::('trm × 'var) list) ⊆ atrm› ‹distinct (map snd txs)›*) us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT r1 = {}› ‹set us ∩ FvarsT r2 = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct us›*) vs1_facts (*‹set (vs1::'var list) ⊆ (var::'var set)› ‹set vs1 ∩ FvarsT r1 = {}› ‹set (vs1::'var::type list) ∩ ⋃ ((FvarsT::'trm::type ⇒ 'var::type set) ` fst ` set (txs::('trm::type × 'var::type) list)) = {}› ‹set vs1 ∩ snd ` set txs = {}› ‹length vs1 = length txs› ‹distinct (vs1::'var list)›*) apply (intro rawpsubstT_compose_freshVar2 (*‹⟦?r ∈ atrm; set ?ts ⊆ atrm; set ?xs ⊆ var; distinct ?xs; set ?us ⊆ var; distinct ?us; set ?us ∩ FvarsT ?r = {}; set ?us ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?us ∩ set ?xs = {}; set ?vs ⊆ var; distinct ?vs; set ?vs ∩ FvarsT ?r = {}; set ?vs ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?vs ∩ set ?xs = {}; length ?us = length ?xs; length ?vs = length ?xs; length ?ts = length ?xs⟧ ⟹ rawpsubstT (rawpsubstT ?r (zip (map Var ?us) ?xs)) (zip ?ts ?us) = rawpsubstT (rawpsubstT ?r (zip (map Var ?vs) ?xs)) (zip ?ts ?vs)›*)) (*goals: 1. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ r1 ∈ atrm› 2. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set (map fst txs) ⊆ atrm› 3. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set (map snd txs) ⊆ var› 4. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ distinct (map snd txs)› 5. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set us ⊆ var› 6. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ distinct us› 7. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set us ∩ FvarsT r1 = {}› 8. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set us ∩ ⋃ (FvarsT ` set (map fst txs)) = {}› 9. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set us ∩ set (map snd txs) = {}› 10. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set vs1 ⊆ var› 11. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ distinct vs1› 12. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set vs1 ∩ FvarsT r1 = {}› 13. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set vs1 ∩ ⋃ (FvarsT ` set (map fst txs)) = {}› 14. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ set vs1 ∩ set (map snd txs) = {}› 15. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ length us = length (map snd txs)› 16. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ length vs1 = length (map snd txs)› 17. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs1 ⊆ var; set vs1 ∩ FvarsT r1 = {}; set vs1 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs1 ∩ snd ` set txs = {}; length vs1 = length txs; distinct vs1⟧ ⟹ length (map fst txs) = length (map snd txs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*discuss goal 9*) apply ((auto)[1]) (*discuss goal 10*) apply ((auto)[1]) (*discuss goal 11*) apply ((auto)[1]) (*discuss goal 12*) apply ((auto)[1]) (*discuss goal 13*) apply ((auto)[1]) (*discuss goal 14*) apply ((auto)[1]) (*discuss goal 15*) apply ((auto)[1]) (*discuss goal 16*) apply ((auto)[1]) (*discuss goal 17*) apply ((auto)[1]) (*proven 17 subgoals*) . have 2: "rawpsubstT (rawpsubstT r2 (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT (rawpsubstT r2 (zip (map Var vs2) (map snd txs))) (zip (map fst txs) vs2)" using assms (*‹r1 ∈ atrm› ‹r2 ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set (txs::('trm × 'var) list) ⊆ atrm› ‹distinct (map snd (txs::('trm × 'var) list))›*) us_facts (*‹set us ⊆ var› ‹set us ∩ FvarsT r1 = {}› ‹set us ∩ FvarsT r2 = {}› ‹set (us::'var list) ∩ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set (txs::('trm × 'var) list)) = {}› ‹set us ∩ snd ` set txs = {}› ‹length us = length txs› ‹distinct us›*) vs2_facts (*‹set vs2 ⊆ var› ‹set vs2 ∩ FvarsT r2 = {}› ‹set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set (vs2::'var list) ∩ snd ` set (txs::('trm × 'var) list) = {}› ‹length vs2 = length txs› ‹distinct vs2›*) apply (intro rawpsubstT_compose_freshVar2 (*‹⟦(?r::'trm) ∈ atrm; set (?ts::'trm list) ⊆ atrm; set (?xs::'var list) ⊆ (var::'var set); distinct ?xs; set (?us::'var list) ⊆ var; distinct ?us; set ?us ∩ (FvarsT::'trm ⇒ 'var set) ?r = {}; set ?us ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?us ∩ set ?xs = {}; set (?vs::'var list) ⊆ var; distinct ?vs; set ?vs ∩ FvarsT ?r = {}; set ?vs ∩ ⋃ (FvarsT ` set ?ts) = {}; set ?vs ∩ set ?xs = {}; length ?us = length ?xs; length ?vs = length ?xs; length ?ts = length ?xs⟧ ⟹ rawpsubstT (rawpsubstT ?r (zip (map (Var::'var ⇒ 'trm) ?us) ?xs)) (zip ?ts ?us) = rawpsubstT (rawpsubstT ?r (zip (map Var ?vs) ?xs)) (zip ?ts ?vs)›*)) (*goals: 1. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ r2 ∈ atrm› 2. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set (map fst txs) ⊆ atrm› 3. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set (map snd txs) ⊆ var› 4. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ distinct (map snd txs)› 5. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set us ⊆ var› 6. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ distinct us› 7. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set us ∩ FvarsT r2 = {}› 8. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set us ∩ ⋃ (FvarsT ` set (map fst txs)) = {}› 9. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set us ∩ set (map snd txs) = {}› 10. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set vs2 ⊆ var› 11. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ distinct vs2› 12. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set vs2 ∩ FvarsT r2 = {}› 13. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set vs2 ∩ ⋃ (FvarsT ` set (map fst txs)) = {}› 14. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ set vs2 ∩ set (map snd txs) = {}› 15. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ length us = length (map snd txs)› 16. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ length vs2 = length (map snd txs)› 17. ‹⟦r1 ∈ atrm; r2 ∈ atrm; snd ` set txs ⊆ var; fst ` set txs ⊆ atrm; distinct (map snd txs); set us ⊆ var; set us ∩ FvarsT r1 = {}; set us ∩ FvarsT r2 = {}; set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set us ∩ snd ` set txs = {}; length us = length txs; distinct us; set vs2 ⊆ var; set vs2 ∩ FvarsT r2 = {}; set vs2 ∩ ⋃ (FvarsT ` fst ` set txs) = {}; set vs2 ∩ snd ` set txs = {}; length vs2 = length txs; distinct vs2⟧ ⟹ length (map fst txs) = length (map snd txs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*discuss goal 9*) apply ((auto)[1]) (*discuss goal 10*) apply ((auto)[1]) (*discuss goal 11*) apply ((auto)[1]) (*discuss goal 12*) apply ((auto)[1]) (*discuss goal 13*) apply ((auto)[1]) (*discuss goal 14*) apply ((auto)[1]) (*discuss goal 15*) apply ((auto)[1]) (*discuss goal 16*) apply ((auto)[1]) (*discuss goal 17*) apply ((auto)[1]) (*proven 17 subgoals*) . have 3: "rawpsubstT (rawpsubstT (tms r1 r2) (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = tms (rawpsubstT (rawpsubstT r1 (zip (map Var us) (map snd txs))) (zip (map fst txs) us)) (rawpsubstT (rawpsubstT r2 (zip (map Var us) (map snd txs))) (zip (map fst txs) us))" unfolding "0" (*goal: ‹rawpsubstT ((tms::'trm ⇒ 'trm ⇒ 'trm) (rawpsubstT (r1::'trm) (zip (map (Var::'var ⇒ 'trm) (us::'var list)) (map snd (txs::('trm × 'var) list)))) (rawpsubstT (r2::'trm) (zip (map Var us) (map snd txs)))) (zip (map fst txs) us) = tms (rawpsubstT (rawpsubstT r1 (zip (map Var us) (map snd txs))) (zip (map fst txs) us)) (rawpsubstT (rawpsubstT r2 (zip (map Var us) (map snd txs))) (zip (map fst txs) us))›*) using assms (*‹r1 ∈ atrm› ‹r2 ∈ atrm› ‹snd ` set txs ⊆ var› ‹fst ` set txs ⊆ atrm› ‹distinct (map snd txs)›*) us_facts (*‹set us ⊆ var› ‹set (us::'var list) ∩ (FvarsT::'trm ⇒ 'var set) (r1::'trm) = {}› ‹set us ∩ FvarsT r2 = {}› ‹set us ∩ ⋃ (FvarsT ` fst ` set txs) = {}› ‹set us ∩ snd ` set txs = {}› ‹length (us::'var::type list) = length (txs::('trm::type × 'var::type) list)› ‹distinct us›*) apply (intro rawpsubstT_tms (*‹⟦?r1.0 ∈ trm; ?r2.0 ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT (tms ?r1.0 ?r2.0) ?txs = tms (rawpsubstT ?r1.0 ?txs) (rawpsubstT ?r2.0 ?txs)›*)) (*goal: ‹rawpsubstT (tms (rawpsubstT r1 (zip (map Var us) (map snd txs))) (rawpsubstT r2 (zip (map Var us) (map snd txs)))) (zip (map fst txs) us) = tms (rawpsubstT (rawpsubstT r1 (zip (map Var us) (map snd txs))) (zip (map fst txs) us)) (rawpsubstT (rawpsubstT r2 (zip (map Var us) (map snd txs))) (zip (map fst txs) us))›*) subgoal for by (auto dest!: set_zip_D (*‹(?x::?'a::type, ?y::?'b::type) ∈ set (zip (?xs::?'a::type list) (?ys::?'b::type list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) intro!: rawpsubstT (*‹⟦(?t::'trm::type) ∈ (trm::'trm::type set); snd ` set (?txs::('trm::type × 'var::type) list) ⊆ (var::'var::type set); fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*)) subgoal for by (force dest!: set_zip_D (*‹(?x::?'a, ?y::?'b) ∈ set (zip (?xs::?'a list) (?ys::?'b list)) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) intro!: rawpsubstT (*‹⟦(?t::'trm) ∈ (trm::'trm set); snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) simp: Int_def (*‹(?A::?'a set) ∩ (?B::?'a set) = {x::?'a ∈ ?A. x ∈ ?B}›*)) subgoal for by (auto dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*)) subgoal for by (fastforce dest!: set_zip_D (*‹(?x, ?y) ∈ set (zip ?xs ?ys) ⟹ ?x ∈ set ?xs ∧ ?y ∈ set ?ys›*) intro!: rawpsubstT (*‹⟦?t ∈ trm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm⟧ ⟹ rawpsubstT ?t ?txs ∈ trm›*) simp: Int_def (*‹?A ∩ ?B = {x ∈ ?A. x ∈ ?B}›*)) . show "?thesis" (*goal: ‹psubstT (tms r1 r2) txs = tms (psubstT r1 txs) (psubstT r2 txs)›*) unfolding psubstT_def (*goal: ‹(let xs = map snd txs; ts = map fst txs; us = getFrN xs (tms r1 r2 # ts) [] (length xs) in rawpsubstT (rawpsubstT (tms r1 r2) (zip (map Var us) xs)) (zip ts us)) = tms (let xs = map snd txs; ts = map fst txs; us = getFrN xs (r1 # ts) [] (length xs) in rawpsubstT (rawpsubstT r1 (zip (map Var us) xs)) (zip ts us)) (let xs = map snd txs; ts = map fst txs; us = getFrN xs (r2 # ts) [] (length xs) in rawpsubstT (rawpsubstT r2 (zip (map Var us) xs)) (zip ts us))›*) by (simp add: Let_def (*‹Let ?s ?f ≡ ?f ?s›*) us[symmetric] (*‹getFrN (map snd txs) (tms r1 r2 # map fst txs) [] (length txs) ≡ us›*) vs1[symmetric] (*‹getFrN (map snd txs) (r1 # map fst txs) [] (length txs) ≡ vs1›*) vs2[symmetric] (*‹getFrN (map snd txs) (r2 # map fst txs) [] (length txs) ≡ vs2›*) 1 (*‹rawpsubstT (rawpsubstT r1 (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT (rawpsubstT r1 (zip (map Var vs1) (map snd txs))) (zip (map fst txs) vs1)›*) 2 (*‹rawpsubstT (rawpsubstT r2 (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = rawpsubstT (rawpsubstT r2 (zip (map Var vs2) (map snd txs))) (zip (map fst txs) vs2)›*) 3 (*‹rawpsubstT (rawpsubstT (tms r1 r2) (zip (map Var us) (map snd txs))) (zip (map fst txs) us) = tms (rawpsubstT (rawpsubstT r1 (zip (map Var us) (map snd txs))) (zip (map fst txs) us)) (rawpsubstT (rawpsubstT r2 (zip (map Var us) (map snd txs))) (zip (map fst txs) us))›*)) qed section ‹The (Nonstrict and Strict) Order Relations› text ‹Lq (less than or equal to) is a formula with free vars xx and yy. NB: Out of the two possible ways, adding zz to the left or to the right, we choose the former, since this seems to enable Q (Robinson arithmetic) to prove as many useful properties as possible.› definition Lq :: "'fmla" where "Lq ≡ exi zz (eql (Var yy) (pls (Var zz) (Var xx)))" text ‹Alternative, more flexible definition , for any non-capturing bound variable:› lemma Lq_def2: "z ∈ var ⟹ z ≠ yy ⟹ z ≠ xx ⟹ Lq = exi z (eql (Var yy) (pls (Var z) (Var xx)))" unfolding Lq_def (*goal: ‹⟦z ∈ var; z ≠ yy; z ≠ xx⟧ ⟹ exi zz (eql (Var yy) (pls (Var zz) (Var xx))) = exi z (eql (Var yy) (pls (Var z) (Var xx)))›*) using exi_rename[of "eql (Var yy) (pls (Var zz) (Var xx))" zz z] (*‹⟦eql (Var yy) (pls (Var zz) (Var xx)) ∈ fmla; zz ∈ var; z ∈ var; z ∉ Fvars (eql (Var yy) (pls (Var zz) (Var xx)))⟧ ⟹ exi zz (eql (Var yy) (pls (Var zz) (Var xx))) = exi z (subst (eql (Var yy) (pls (Var zz) (Var xx))) (Var z) zz)›*) by auto lemma Lq[simp,intro!]: "Lq ∈ fmla" unfolding Lq_def (*goal: ‹exi zz (eql (Var yy) (pls (Var zz) (Var xx))) ∈ fmla›*) by auto lemma Fvars_Lq[simp]: "Fvars Lq = {xx,yy}" unfolding Lq_def (*goal: ‹Fvars (exi zz (eql (Var yy) (pls (Var zz) (Var xx)))) = {xx, yy}›*) by auto text ‹As usual, we also define a predicate version:› definition LLq where "LLq ≡ λ t1 t2. psubst Lq [(t1,xx), (t2,yy)]" lemma LLq[simp,intro]: assumes "t1 ∈ trm" "t2 ∈ trm" shows "LLq t1 t2 ∈ fmla" using assms (*‹t1 ∈ trm› ‹(t2::'trm) ∈ (trm::'trm set)›*) unfolding LLq_def (*goal: ‹psubst Lq [(t1, xx), (t2, yy)] ∈ fmla›*) by auto lemma LLq2[simp,intro!]: "n ∈ num ⟹ LLq n (Var yy') ∈ fmla" by auto lemma Fvars_LLq[simp]: "t1 ∈ trm ⟹ t2 ∈ trm ⟹ Fvars (LLq t1 t2) = FvarsT t1 ∪ FvarsT t2" unfolding LLq_def (*goal: ‹⟦(t1::'trm::type) ∈ (trm::'trm::type set); (t2::'trm::type) ∈ trm⟧ ⟹ (Fvars::'fmla::type ⇒ 'var::type set) (psubst Lq [(t1, xx), (t2, yy)]) = (FvarsT::'trm::type ⇒ 'var::type set) t1 ∪ FvarsT t2›*) apply (subst Fvars_psubst (*‹⟦(?φ::'fmla) ∈ (fmla::'fmla set); snd ` set (?txs::('trm × 'var) list) ⊆ (var::'var set); fst ` set ?txs ⊆ (trm::'trm set); distinct (map snd ?txs)⟧ ⟹ (Fvars::'fmla ⇒ 'var set) (psubst ?φ ?txs) = Fvars ?φ - snd ` set ?txs ∪ ⋃ {if x ∈ Fvars ?φ then (FvarsT::'trm ⇒ 'var set) t else {} |(t::'trm) x::'var. (t, x) ∈ set ?txs}›*)) (*goal: ‹⟦t1 ∈ trm; t2 ∈ trm⟧ ⟹ Fvars (psubst Lq [(t1, xx), (t2, yy)]) = FvarsT t1 ∪ FvarsT t2›*) subgoal for by auto subgoal for by auto subgoal for by auto subgoal for by auto subgoal for apply safe (*goal: ‹⟦t1 ∈ trm; t2 ∈ trm⟧ ⟹ Fvars Lq - snd ` set [(t1, xx), (t2, yy)] ∪ ⋃ {if x ∈ Fvars Lq then FvarsT t else {} |t x. (t, x) ∈ set [(t1, xx), (t2, yy)]} = FvarsT t1 ∪ FvarsT t2›*) subgoal for by auto subgoal for by auto subgoal for by force subgoal for by force subgoal for by force subgoal for by force . . text ‹This lemma will be the working definition of LLq:› lemma LLq_pls: assumes [simp]: "t1 ∈ atrm" "t2 ∈ atrm" "z ∈ var" "z ∉ FvarsT t1" "z ∉ FvarsT t2" shows "LLq t1 t2 = exi z (eql t2 (pls (Var z) t1))" proof (-) (*goal: ‹LLq t1 t2 = exi z (eql t2 (pls (Var z) t1))›*) define z' where "z' ≡ getFr [xx,yy,z] [t1,t2] []" have z_facts[simp]: "z' ∈ var" "z' ≠ yy" "z' ≠ xx" "z' ≠ z" "z ≠ z'" "z' ∉ FvarsT t1" "z' ∉ FvarsT t2" using getFr_FvarsT_Fvars[of "[xx,yy,z]" "[t1,t2]" "[]"] (*‹⟦set [xx, yy, z::'var] ⊆ (var::'var set); set [t1::'trm, t2::'trm] ⊆ (trm::'trm set); set [] ⊆ (fmla::'fmla set)⟧ ⟹ getFr [xx, yy, z] [t1, t2] [] ∈ var ∧ getFr [xx, yy, z] [t1, t2] [] ∉ set [xx, yy, z] ∧ ((?t::'trm) ∈ set [t1, t2] ⟶ getFr [xx, yy, z] [t1, t2] [] ∉ (FvarsT::'trm ⇒ 'var set) ?t) ∧ ((?φ::'fmla) ∈ set [] ⟶ getFr [xx, yy, z] [t1, t2] [] ∉ (Fvars::'fmla ⇒ 'var set) ?φ)›*) unfolding z'_def (*goals: 1. ‹getFr [xx, yy, z] [t1, t2] [] ∈ var› 2. ‹getFr [xx, yy, z] [t1, t2] [] ≠ yy› 3. ‹getFr [xx, yy, z] [t1, t2] [] ≠ xx› 4. ‹getFr [xx, yy, z] [t1, t2] [] ≠ z› 5. ‹z ≠ getFr [xx, yy, z] [t1, t2] []› 6. ‹getFr [xx, yy, z] [t1, t2] [] ∉ FvarsT t1› 7. ‹getFr [xx, yy, z] [t1, t2] [] ∉ FvarsT t2›*) apply - (*goals: 1. ‹(⋀t φ. ⟦set [xx, yy, z] ⊆ var; set [t1, t2] ⊆ trm; set [] ⊆ fmla⟧ ⟹ getFr [xx, yy, z] [t1, t2] [] ∈ var ∧ getFr [xx, yy, z] [t1, t2] [] ∉ set [xx, yy, z] ∧ (t ∈ set [t1, t2] ⟶ getFr [xx, yy, z] [t1, t2] [] ∉ FvarsT t) ∧ (φ ∈ set [] ⟶ getFr [xx, yy, z] [t1, t2] [] ∉ Fvars φ)) ⟹ getFr [xx, yy, z] [t1, t2] [] ∈ var› 2. ‹(⋀t φ. ⟦set [xx, yy, z] ⊆ var; set [t1, t2] ⊆ trm; set [] ⊆ fmla⟧ ⟹ getFr [xx, yy, z] [t1, t2] [] ∈ var ∧ getFr [xx, yy, z] [t1, t2] [] ∉ set [xx, yy, z] ∧ (t ∈ set [t1, t2] ⟶ getFr [xx, yy, z] [t1, t2] [] ∉ FvarsT t) ∧ (φ ∈ set [] ⟶ getFr [xx, yy, z] [t1, t2] [] ∉ Fvars φ)) ⟹ getFr [xx, yy, z] [t1, t2] [] ≠ yy› 3. ‹(⋀t φ. ⟦set [xx, yy, z] ⊆ var; set [t1, t2] ⊆ trm; set [] ⊆ fmla⟧ ⟹ getFr [xx, yy, z] [t1, t2] [] ∈ var ∧ getFr [xx, yy, z] [t1, t2] [] ∉ set [xx, yy, z] ∧ (t ∈ set [t1, t2] ⟶ getFr [xx, yy, z] [t1, t2] [] ∉ FvarsT t) ∧ (φ ∈ set [] ⟶ getFr [xx, yy, z] [t1, t2] [] ∉ Fvars φ)) ⟹ getFr [xx, yy, z] [t1, t2] [] ≠ xx› 4. ‹(⋀t φ. ⟦set [xx, yy, z] ⊆ var; set [t1, t2] ⊆ trm; set [] ⊆ fmla⟧ ⟹ getFr [xx, yy, z] [t1, t2] [] ∈ var ∧ getFr [xx, yy, z] [t1, t2] [] ∉ set [xx, yy, z] ∧ (t ∈ set [t1, t2] ⟶ getFr [xx, yy, z] [t1, t2] [] ∉ FvarsT t) ∧ (φ ∈ set [] ⟶ getFr [xx, yy, z] [t1, t2] [] ∉ Fvars φ)) ⟹ getFr [xx, yy, z] [t1, t2] [] ≠ z› 5. ‹(⋀t φ. ⟦set [xx, yy, z] ⊆ var; set [t1, t2] ⊆ trm; set [] ⊆ fmla⟧ ⟹ getFr [xx, yy, z] [t1, t2] [] ∈ var ∧ getFr [xx, yy, z] [t1, t2] [] ∉ set [xx, yy, z] ∧ (t ∈ set [t1, t2] ⟶ getFr [xx, yy, z] [t1, t2] [] ∉ FvarsT t) ∧ (φ ∈ set [] ⟶ getFr [xx, yy, z] [t1, t2] [] ∉ Fvars φ)) ⟹ z ≠ getFr [xx, yy, z] [t1, t2] []› 6. ‹(⋀t φ. ⟦set [xx, yy, z] ⊆ var; set [t1, t2] ⊆ trm; set [] ⊆ fmla⟧ ⟹ getFr [xx, yy, z] [t1, t2] [] ∈ var ∧ getFr [xx, yy, z] [t1, t2] [] ∉ set [xx, yy, z] ∧ (t ∈ set [t1, t2] ⟶ getFr [xx, yy, z] [t1, t2] [] ∉ FvarsT t) ∧ (φ ∈ set [] ⟶ getFr [xx, yy, z] [t1, t2] [] ∉ Fvars φ)) ⟹ getFr [xx, yy, z] [t1, t2] [] ∉ FvarsT t1› 7. ‹(⋀t φ. ⟦set [xx, yy, z] ⊆ var; set [t1, t2] ⊆ trm; set [] ⊆ fmla⟧ ⟹ getFr [xx, yy, z] [t1, t2] [] ∈ var ∧ getFr [xx, yy, z] [t1, t2] [] ∉ set [xx, yy, z] ∧ (t ∈ set [t1, t2] ⟶ getFr [xx, yy, z] [t1, t2] [] ∉ FvarsT t) ∧ (φ ∈ set [] ⟶ getFr [xx, yy, z] [t1, t2] [] ∉ Fvars φ)) ⟹ getFr [xx, yy, z] [t1, t2] [] ∉ FvarsT t2› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*proven 7 subgoals*) . have "LLq t1 t2 = exi z' (eql t2 (pls (Var z') t1))" by (simp add: LLq_def (*‹LLq ≡ λt1 t2. psubst Lq [(t1, xx), (t2, yy)]›*) Lq_def2[of z'] (*‹⟦z' ∈ var; z' ≠ yy; z' ≠ xx⟧ ⟹ Lq = exi z' (eql (Var yy) (pls (Var z') (Var xx)))›*)) also (*calculation: ‹LLq t1 t2 = exi z' (eql t2 (pls (Var z') t1))›*) have "… = exi z (eql t2 (pls (Var z) t1))" using exi_rename[of "eql t2 (pls (Var z') t1)" z' z, simplified] (*‹exi z' (eql t2 (pls (Var z') t1)) = exi z (eql t2 (pls (Var z) t1))›*) . finally (*calculation: ‹LLq (t1::'trm) (t2::'trm) = (exi::'var ⇒ 'fmla ⇒ 'fmla) (z::'var) ((eql::'trm ⇒ 'trm ⇒ 'fmla) t2 ((pls::'trm ⇒ 'trm ⇒ 'trm) ((Var::'var ⇒ 'trm) z) t1))›*) show "?thesis" (*goal: ‹LLq t1 t2 = exi z (eql t2 (pls (Var z) t1))›*) . qed lemma LLq_pls_zz: assumes "t1 ∈ atrm" "t2 ∈ atrm" "zz ∉ FvarsT t1" "zz ∉ FvarsT t2" shows "LLq t1 t2 = exi zz (eql t2 (pls (Var zz) t1))" using assms (*‹t1 ∈ atrm› ‹t2 ∈ atrm› ‹zz ∉ FvarsT t1› ‹zz ∉ FvarsT t2›*) apply (intro LLq_pls (*‹⟦(?t1.0::'trm) ∈ atrm; (?t2.0::'trm) ∈ atrm; (?z::'var) ∈ (var::'var set); ?z ∉ (FvarsT::'trm ⇒ 'var set) ?t1.0; ?z ∉ FvarsT ?t2.0⟧ ⟹ LLq ?t1.0 ?t2.0 = (exi::'var ⇒ 'fmla ⇒ 'fmla) ?z ((eql::'trm ⇒ 'trm ⇒ 'fmla) ?t2.0 ((pls::'trm ⇒ 'trm ⇒ 'trm) ((Var::'var ⇒ 'trm) ?z) ?t1.0))›*)) (*goals: 1. ‹⟦t1 ∈ atrm; t2 ∈ atrm; zz ∉ FvarsT t1; zz ∉ FvarsT t2⟧ ⟹ t1 ∈ atrm› 2. ‹⟦t1 ∈ atrm; t2 ∈ atrm; zz ∉ FvarsT t1; zz ∉ FvarsT t2⟧ ⟹ t2 ∈ atrm› 3. ‹⟦t1 ∈ atrm; t2 ∈ atrm; zz ∉ FvarsT t1; zz ∉ FvarsT t2⟧ ⟹ zz ∈ var› 4. ‹⟦t1 ∈ atrm; t2 ∈ atrm; zz ∉ FvarsT t1; zz ∉ FvarsT t2⟧ ⟹ zz ∉ FvarsT t1› 5. ‹⟦t1 ∈ atrm; t2 ∈ atrm; zz ∉ FvarsT t1; zz ∉ FvarsT t2⟧ ⟹ zz ∉ FvarsT t2› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . text ‹If we restrict attention to arithmetic terms, we can prove a uniform substitution property for LLq:› lemma subst_LLq[simp]: assumes [simp]: "t1 ∈ atrm" "t2 ∈ atrm" "s ∈ atrm" "x ∈ var" shows "subst (LLq t1 t2) s x = LLq (substT t1 s x) (substT t2 s x)" proof (-) (*goal: ‹(subst::'fmla ⇒ 'trm ⇒ 'var ⇒ 'fmla) (LLq (t1::'trm) (t2::'trm)) (s::'trm) (x::'var) = LLq ((substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) t1 s x) (substT t2 s x)›*) define z where "z ≡ getFr [xx,yy,x] [t1,t2,s] []" have z_facts[simp]: "z ∈ var" "z ≠ xx" "z ≠ yy" "z ≠ x" "z ∉ FvarsT t1" "z ∉ FvarsT t2" "z ∉ FvarsT s" using getFr_FvarsT_Fvars[of "[xx,yy,x]" "[t1,t2,s]" "[]"] (*‹⟦set [xx, yy, x] ⊆ var; set [t1, t2, s] ⊆ trm; set [] ⊆ fmla⟧ ⟹ getFr [xx, yy, x] [t1, t2, s] [] ∈ var ∧ getFr [xx, yy, x] [t1, t2, s] [] ∉ set [xx, yy, x] ∧ (?t ∈ set [t1, t2, s] ⟶ getFr [xx, yy, x] [t1, t2, s] [] ∉ FvarsT ?t) ∧ (?φ ∈ set [] ⟶ getFr [xx, yy, x] [t1, t2, s] [] ∉ Fvars ?φ)›*) unfolding z_def (*goals: 1. ‹getFr [xx, yy, x::'var] [t1::'trm, t2::'trm, s::'trm] [] ∈ (var::'var set)› 2. ‹getFr [xx, yy, x::'var] [t1::'trm, t2::'trm, s::'trm] [] ≠ xx› 3. ‹getFr [xx, yy, x::'var] [t1::'trm, t2::'trm, s::'trm] [] ≠ yy› 4. ‹getFr [xx, yy, x::'var] [t1::'trm, t2::'trm, s::'trm] [] ≠ x› 5. ‹getFr [xx, yy, x::'var] [t1::'trm, t2::'trm, s::'trm] [] ∉ (FvarsT::'trm ⇒ 'var set) t1› 6. ‹getFr [xx, yy, x::'var] [t1::'trm, t2::'trm, s::'trm] [] ∉ (FvarsT::'trm ⇒ 'var set) t2› 7. ‹getFr [xx, yy, x::'var] [t1::'trm, t2::'trm, s::'trm] [] ∉ (FvarsT::'trm ⇒ 'var set) s›*) apply - (*goals: 1. ‹(⋀t φ. ⟦set [xx, yy, x] ⊆ var; set [t1, t2, s] ⊆ trm; set [] ⊆ fmla⟧ ⟹ getFr [xx, yy, x] [t1, t2, s] [] ∈ var ∧ getFr [xx, yy, x] [t1, t2, s] [] ∉ set [xx, yy, x] ∧ (t ∈ set [t1, t2, s] ⟶ getFr [xx, yy, x] [t1, t2, s] [] ∉ FvarsT t) ∧ (φ ∈ set [] ⟶ getFr [xx, yy, x] [t1, t2, s] [] ∉ Fvars φ)) ⟹ getFr [xx, yy, x] [t1, t2, s] [] ∈ var› 2. ‹(⋀t φ. ⟦set [xx, yy, x] ⊆ var; set [t1, t2, s] ⊆ trm; set [] ⊆ fmla⟧ ⟹ getFr [xx, yy, x] [t1, t2, s] [] ∈ var ∧ getFr [xx, yy, x] [t1, t2, s] [] ∉ set [xx, yy, x] ∧ (t ∈ set [t1, t2, s] ⟶ getFr [xx, yy, x] [t1, t2, s] [] ∉ FvarsT t) ∧ (φ ∈ set [] ⟶ getFr [xx, yy, x] [t1, t2, s] [] ∉ Fvars φ)) ⟹ getFr [xx, yy, x] [t1, t2, s] [] ≠ xx› 3. ‹(⋀t φ. ⟦set [xx, yy, x] ⊆ var; set [t1, t2, s] ⊆ trm; set [] ⊆ fmla⟧ ⟹ getFr [xx, yy, x] [t1, t2, s] [] ∈ var ∧ getFr [xx, yy, x] [t1, t2, s] [] ∉ set [xx, yy, x] ∧ (t ∈ set [t1, t2, s] ⟶ getFr [xx, yy, x] [t1, t2, s] [] ∉ FvarsT t) ∧ (φ ∈ set [] ⟶ getFr [xx, yy, x] [t1, t2, s] [] ∉ Fvars φ)) ⟹ getFr [xx, yy, x] [t1, t2, s] [] ≠ yy› 4. ‹(⋀t φ. ⟦set [xx, yy, x] ⊆ var; set [t1, t2, s] ⊆ trm; set [] ⊆ fmla⟧ ⟹ getFr [xx, yy, x] [t1, t2, s] [] ∈ var ∧ getFr [xx, yy, x] [t1, t2, s] [] ∉ set [xx, yy, x] ∧ (t ∈ set [t1, t2, s] ⟶ getFr [xx, yy, x] [t1, t2, s] [] ∉ FvarsT t) ∧ (φ ∈ set [] ⟶ getFr [xx, yy, x] [t1, t2, s] [] ∉ Fvars φ)) ⟹ getFr [xx, yy, x] [t1, t2, s] [] ≠ x› 5. ‹(⋀t φ. ⟦set [xx, yy, x] ⊆ var; set [t1, t2, s] ⊆ trm; set [] ⊆ fmla⟧ ⟹ getFr [xx, yy, x] [t1, t2, s] [] ∈ var ∧ getFr [xx, yy, x] [t1, t2, s] [] ∉ set [xx, yy, x] ∧ (t ∈ set [t1, t2, s] ⟶ getFr [xx, yy, x] [t1, t2, s] [] ∉ FvarsT t) ∧ (φ ∈ set [] ⟶ getFr [xx, yy, x] [t1, t2, s] [] ∉ Fvars φ)) ⟹ getFr [xx, yy, x] [t1, t2, s] [] ∉ FvarsT t1› 6. ‹(⋀t φ. ⟦set [xx, yy, x] ⊆ var; set [t1, t2, s] ⊆ trm; set [] ⊆ fmla⟧ ⟹ getFr [xx, yy, x] [t1, t2, s] [] ∈ var ∧ getFr [xx, yy, x] [t1, t2, s] [] ∉ set [xx, yy, x] ∧ (t ∈ set [t1, t2, s] ⟶ getFr [xx, yy, x] [t1, t2, s] [] ∉ FvarsT t) ∧ (φ ∈ set [] ⟶ getFr [xx, yy, x] [t1, t2, s] [] ∉ Fvars φ)) ⟹ getFr [xx, yy, x] [t1, t2, s] [] ∉ FvarsT t2› 7. ‹(⋀t φ. ⟦set [xx, yy, x] ⊆ var; set [t1, t2, s] ⊆ trm; set [] ⊆ fmla⟧ ⟹ getFr [xx, yy, x] [t1, t2, s] [] ∈ var ∧ getFr [xx, yy, x] [t1, t2, s] [] ∉ set [xx, yy, x] ∧ (t ∈ set [t1, t2, s] ⟶ getFr [xx, yy, x] [t1, t2, s] [] ∉ FvarsT t) ∧ (φ ∈ set [] ⟶ getFr [xx, yy, x] [t1, t2, s] [] ∉ Fvars φ)) ⟹ getFr [xx, yy, x] [t1, t2, s] [] ∉ FvarsT s› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*proven 7 subgoals*) . show "?thesis" (*goal: ‹subst (LLq t1 t2) s x = LLq (substT t1 s x) (substT t2 s x)›*) by (simp add: FvarsT_substT (*‹⟦?s ∈ atrm; ?t ∈ trm; ?x ∈ var⟧ ⟹ FvarsT (substT ?s ?t ?x) = FvarsT ?s - {?x} ∪ (if ?x ∈ FvarsT ?s then FvarsT ?t else {})›*) LLq_pls[of _ _ z] (*‹⟦?t1.0 ∈ atrm; ?t2.0 ∈ atrm; z ∈ var; z ∉ FvarsT ?t1.0; z ∉ FvarsT ?t2.0⟧ ⟹ LLq ?t1.0 ?t2.0 = exi z (eql ?t2.0 (pls (Var z) ?t1.0))›*) subst2_fresh_switch (*‹⟦?φ ∈ fmla; ?t ∈ trm; ?s ∈ trm; ?x ∈ var; ?y ∈ var; ?x ≠ ?y; ?x ∉ FvarsT ?s; ?y ∉ FvarsT ?t⟧ ⟹ subst (subst ?φ ?s ?y) ?t ?x = subst (subst ?φ ?t ?x) ?s ?y›*) Lq_def (*‹Lq ≡ exi zz (eql (Var yy) (pls (Var zz) (Var xx)))›*)) qed lemma psubst_LLq[simp]: assumes 1: "t1 ∈ atrm" "t2 ∈ atrm" "fst ` set txs ⊆ atrm" and 2: "snd ` set txs ⊆ var" and 3: "distinct (map snd txs)" shows "psubst (LLq t1 t2) txs = LLq (psubstT t1 txs) (psubstT t2 txs)" proof (-) (*goal: ‹psubst (LLq (t1::'trm::type) (t2::'trm::type)) (txs::('trm::type × 'var::type) list) = LLq (psubstT t1 txs) (psubstT t2 txs)›*) have 0: "t1 ∈ trm" "t2 ∈ trm" "fst ` set txs ⊆ trm" using "1" (*‹t1 ∈ atrm› ‹(t2::'trm::type) ∈ atrm› ‹fst ` set txs ⊆ atrm›*) apply - (*goals: 1. ‹⟦t1 ∈ atrm; t2 ∈ atrm; fst ` set txs ⊆ atrm⟧ ⟹ t1 ∈ trm› 2. ‹⟦t1 ∈ atrm; t2 ∈ atrm; fst ` set txs ⊆ atrm⟧ ⟹ t2 ∈ trm› 3. ‹⟦t1 ∈ atrm; t2 ∈ atrm; fst ` set txs ⊆ atrm⟧ ⟹ fst ` set txs ⊆ trm› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . define z where z: "z ≡ getFr ([xx,yy] @ map snd txs) ([t1,t2] @ map fst txs) []" have us_facts: "z ∈ var" "z ≠ xx" "z ≠ yy" "z ∉ FvarsT t1" "z ∉ FvarsT t2" "z ∉ ⋃ (FvarsT ` (fst ` (set txs)))" "z ∉ snd ` (set txs)" using "0" (*‹t1 ∈ trm› ‹t2 ∈ trm› ‹fst ` set txs ⊆ trm›*) "2" (*‹snd ` set txs ⊆ var›*) unfolding z (*goals: 1. ‹getFr ([xx, yy] @ map snd txs) ([t1, t2] @ map fst txs) [] ∈ var› 2. ‹getFr ([xx, yy] @ map snd txs) ([t1, t2] @ map fst txs) [] ≠ xx› 3. ‹getFr ([xx, yy] @ map snd txs) ([t1, t2] @ map fst txs) [] ≠ yy› 4. ‹getFr ([xx, yy] @ map snd txs) ([t1, t2] @ map fst txs) [] ∉ FvarsT t1› 5. ‹getFr ([xx, yy] @ map snd txs) ([t1, t2] @ map fst txs) [] ∉ FvarsT t2› 6. ‹getFr ([xx, yy] @ map snd txs) ([t1, t2] @ map fst txs) [] ∉ ⋃ (FvarsT ` fst ` set txs)› 7. ‹getFr ([xx, yy] @ map snd txs) ([t1, t2] @ map fst txs) [] ∉ snd ` set txs›*) using getFr_FvarsT[of "[xx,yy] @ map snd txs" "[t1,t2] @ map fst txs" "[]"] (*‹⟦set ([xx, yy] @ map snd txs) ⊆ var; set ([t1, t2] @ map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set ([t1, t2] @ map fst txs)⟧ ⟹ getFr ([xx, yy] @ map snd txs) ([t1, t2] @ map fst txs) [] ∉ FvarsT ?t›*) getFr_Fvars[of "[xx,yy] @ map snd txs" "[t1,t2] @ map fst txs" "[]"] (*‹⟦set ([xx, yy] @ map snd txs) ⊆ var; set ([t1, t2] @ map fst txs) ⊆ trm; set [] ⊆ fmla; ?φ ∈ set []⟧ ⟹ getFr ([xx, yy] @ map snd txs) ([t1, t2] @ map fst txs) [] ∉ Fvars ?φ›*) getFr_var[of "[xx,yy] @ map snd txs" "[t1,t2] @ map fst txs" "[]"] (*‹⟦set ([xx, yy] @ map snd txs) ⊆ var; set ([t1, t2] @ map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set ([t1, t2] @ map fst txs)⟧ ⟹ getFr ([xx, yy] @ map snd txs) ([t1, t2] @ map fst txs) [] ∉ set ([xx, yy] @ map snd txs)›*) apply - (*top goal: ‹getFr ([xx, yy] @ map snd (txs::('trm × 'var) list)) ([t1::'trm, t2::'trm] @ map fst txs) [] ∈ (var::'var set)› and 6 goals remain*) subgoal for by auto subgoal for by force subgoal for by force subgoal for by force subgoal for by force subgoal for by auto subgoal for by (force simp: image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*)) . note in_FvarsT_psubstTD[dest !] (*‹⟦?y ∈ FvarsT (psubstT ?r ?txs); ?r ∈ atrm; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ atrm; distinct (map snd ?txs)⟧ ⟹ ?y ∈ FvarsT ?r - snd ` set ?txs ∪ ⋃ {if x ∈ FvarsT ?r then FvarsT t else {} |t x. (t, x) ∈ set ?txs}›*) note if_splits[split] (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) show "?thesis" (*goal: ‹psubst (LLq (t1::'trm) (t2::'trm)) (txs::('trm × 'var) list) = LLq (psubstT t1 txs) (psubstT t2 txs)›*) using assms (*‹t1 ∈ atrm› ‹t2 ∈ atrm› ‹fst ` set txs ⊆ atrm› ‹snd ` set txs ⊆ var› ‹distinct (map snd txs)›*) "0" (*‹t1 ∈ trm› ‹(t2::'trm) ∈ (trm::'trm set)› ‹fst ` set txs ⊆ trm›*) us_facts (*‹z ∈ var› ‹z ≠ xx› ‹z ≠ yy› ‹z ∉ FvarsT t1› ‹z ∉ FvarsT t2› ‹z ∉ ⋃ (FvarsT ` fst ` set txs)› ‹z ∉ snd ` set txs›*) apply (subst LLq_pls[of _ _ z] (*‹⟦(?t1.0::'trm) ∈ atrm; (?t2.0::'trm) ∈ atrm; (z::'var) ∈ (var::'var set); z ∉ (FvarsT::'trm ⇒ 'var set) ?t1.0; z ∉ FvarsT ?t2.0⟧ ⟹ LLq ?t1.0 ?t2.0 = (exi::'var ⇒ 'fmla ⇒ 'fmla) z ((eql::'trm ⇒ 'trm ⇒ 'fmla) ?t2.0 ((pls::'trm ⇒ 'trm ⇒ 'trm) ((Var::'var ⇒ 'trm) z) ?t1.0))›*)) (*goal: ‹psubst (LLq (t1::'trm) (t2::'trm)) (txs::('trm × 'var) list) = LLq (psubstT t1 txs) (psubstT t2 txs)›*) subgoal for by auto subgoal for by auto subgoal for by auto subgoal for by auto subgoal for by auto subgoal for apply (subst LLq_pls[of _ _ z] (*‹⟦?t1.0 ∈ atrm; ?t2.0 ∈ atrm; z ∈ var; z ∉ FvarsT ?t1.0; z ∉ FvarsT ?t2.0⟧ ⟹ LLq ?t1.0 ?t2.0 = exi z (eql ?t2.0 (pls (Var z) ?t1.0))›*)) (*goals: 1. ‹⟦t1 ∈ atrm; t2 ∈ atrm; fst ` set txs ⊆ atrm; snd ` set txs ⊆ var; distinct (map snd txs); t1 ∈ trm; t2 ∈ trm; fst ` set txs ⊆ trm; z ∈ var; z ≠ xx; z ≠ yy; z ∉ FvarsT t1; z ∉ FvarsT t2; z ∉ ⋃ (FvarsT ` fst ` set txs); z ∉ snd ` set txs⟧ ⟹ psubstT t1 txs ∈ atrm› 2. ‹⟦t1 ∈ atrm; t2 ∈ atrm; fst ` set txs ⊆ atrm; snd ` set txs ⊆ var; distinct (map snd txs); t1 ∈ trm; t2 ∈ trm; fst ` set txs ⊆ trm; z ∈ var; z ≠ xx; z ≠ yy; z ∉ FvarsT t1; z ∉ FvarsT t2; z ∉ ⋃ (FvarsT ` fst ` set txs); z ∉ snd ` set txs⟧ ⟹ psubstT t2 txs ∈ atrm› 3. ‹⟦t1 ∈ atrm; t2 ∈ atrm; fst ` set txs ⊆ atrm; snd ` set txs ⊆ var; distinct (map snd txs); t1 ∈ trm; t2 ∈ trm; fst ` set txs ⊆ trm; z ∈ var; z ≠ xx; z ≠ yy; z ∉ FvarsT t1; z ∉ FvarsT t2; z ∉ ⋃ (FvarsT ` fst ` set txs); z ∉ snd ` set txs⟧ ⟹ z ∈ var› 4. ‹⟦t1 ∈ atrm; t2 ∈ atrm; fst ` set txs ⊆ atrm; snd ` set txs ⊆ var; distinct (map snd txs); t1 ∈ trm; t2 ∈ trm; fst ` set txs ⊆ trm; z ∈ var; z ≠ xx; z ≠ yy; z ∉ FvarsT t1; z ∉ FvarsT t2; z ∉ ⋃ (FvarsT ` fst ` set txs); z ∉ snd ` set txs⟧ ⟹ z ∉ FvarsT (psubstT t1 txs)› 5. ‹⟦t1 ∈ atrm; t2 ∈ atrm; fst ` set txs ⊆ atrm; snd ` set txs ⊆ var; distinct (map snd txs); t1 ∈ trm; t2 ∈ trm; fst ` set txs ⊆ trm; z ∈ var; z ≠ xx; z ≠ yy; z ∉ FvarsT t1; z ∉ FvarsT t2; z ∉ ⋃ (FvarsT ` fst ` set txs); z ∉ snd ` set txs⟧ ⟹ z ∉ FvarsT (psubstT t2 txs)› 6. ‹⟦t1 ∈ atrm; t2 ∈ atrm; fst ` set txs ⊆ atrm; snd ` set txs ⊆ var; distinct (map snd txs); t1 ∈ trm; t2 ∈ trm; fst ` set txs ⊆ trm; z ∈ var; z ≠ xx; z ≠ yy; z ∉ FvarsT t1; z ∉ FvarsT t2; z ∉ ⋃ (FvarsT ` fst ` set txs); z ∉ snd ` set txs⟧ ⟹ psubst (exi z (eql t2 (pls (Var z) t1))) txs = exi z (eql (psubstT t2 txs) (pls (Var z) (psubstT t1 txs)))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*proven 6 subgoals*) . . qed text ‹Lq less than) is the strict version of the order relation. We prove similar facts as for Lq› definition Ls :: "'fmla" where "Ls ≡ cnj Lq (neg (eql (Var xx) (Var yy)))" lemma Ls[simp,intro!]: "Ls ∈ fmla" unfolding Ls_def (*goal: ‹(cnj::'fmla ⇒ 'fmla ⇒ 'fmla) Lq (neg ((eql::'trm ⇒ 'trm ⇒ 'fmla) ((Var::'var ⇒ 'trm) xx) (Var yy))) ∈ (fmla::'fmla set)›*) by auto lemma Fvars_Ls[simp]: "Fvars Ls = {xx,yy}" unfolding Ls_def (*goal: ‹(Fvars::'fmla ⇒ 'var set) ((cnj::'fmla ⇒ 'fmla ⇒ 'fmla) Lq (neg ((eql::'trm ⇒ 'trm ⇒ 'fmla) ((Var::'var ⇒ 'trm) xx) (Var yy)))) = {xx, yy}›*) by auto definition LLs where "LLs ≡ λ t1 t2. psubst Ls [(t1,xx), (t2,yy)]" lemma LLs[simp,intro]: assumes "t1 ∈ trm" "t2 ∈ trm" shows "LLs t1 t2 ∈ fmla" using assms (*‹(t1::'trm) ∈ (trm::'trm set)› ‹(t2::'trm) ∈ (trm::'trm set)›*) unfolding LLs_def (*goal: ‹psubst Ls [(t1, xx), (t2, yy)] ∈ fmla›*) by auto lemma LLs2[simp,intro!]: "n ∈ num ⟹ LLs n (Var yy') ∈ fmla" by auto lemma Fvars_LLs[simp]: "t1 ∈ trm ⟹ t2 ∈ trm ⟹ Fvars (LLs t1 t2) = FvarsT t1 ∪ FvarsT t2" unfolding LLs_def (*goal: ‹⟦t1 ∈ trm; t2 ∈ trm⟧ ⟹ Fvars (psubst Ls [(t1, xx), (t2, yy)]) = FvarsT t1 ∪ FvarsT t2›*) apply (subst Fvars_psubst (*‹⟦?φ ∈ fmla; snd ` set ?txs ⊆ var; fst ` set ?txs ⊆ trm; distinct (map snd ?txs)⟧ ⟹ Fvars (psubst ?φ ?txs) = Fvars ?φ - snd ` set ?txs ∪ ⋃ {if x ∈ Fvars ?φ then FvarsT t else {} |t x. (t, x) ∈ set ?txs}›*)) (*goal: ‹⟦t1 ∈ trm; t2 ∈ trm⟧ ⟹ Fvars (psubst Ls [(t1, xx), (t2, yy)]) = FvarsT t1 ∪ FvarsT t2›*) subgoal for by auto subgoal for by auto subgoal for by auto subgoal for by auto subgoal for apply safe (*goal: ‹⟦(t1::'trm) ∈ (trm::'trm set); (t2::'trm) ∈ trm⟧ ⟹ (Fvars::'fmla ⇒ 'var set) Ls - snd ` set [(t1, xx), (t2, yy)] ∪ ⋃ {if x ∈ Fvars Ls then (FvarsT::'trm ⇒ 'var set) t else {} |(t::'trm) x::'var. (t, x) ∈ set [(t1, xx), (t2, yy)]} = FvarsT t1 ∪ FvarsT t2›*) subgoal for by auto subgoal for by auto subgoal for by force subgoal for by force subgoal for by force subgoal for by force . . text ‹The working definition of LLs:› lemma LLs_LLq: "t1 ∈ atrm ⟹ t2 ∈ atrm ⟹ LLs t1 t2 = cnj (LLq t1 t2) (neg (eql t1 t2))" by (simp add: LLs_def (*‹LLs ≡ λt1 t2. psubst Ls [(t1, xx), (t2, yy)]›*) Ls_def (*‹Ls ≡ cnj Lq (neg (eql (Var xx) (Var yy)))›*) LLq_def (*‹LLq ≡ λt1 t2. psubst Lq [(t1, xx), (t2, yy)]›*)) lemma subst_LLs[simp]: assumes [simp]: "t1 ∈ atrm" "t2 ∈ atrm" "s ∈ atrm" "x ∈ var" shows "subst (LLs t1 t2) s x = LLs (substT t1 s x) (substT t2 s x)" by (simp add: LLs_LLq (*‹⟦?t1.0 ∈ atrm; ?t2.0 ∈ atrm⟧ ⟹ LLs ?t1.0 ?t2.0 = cnj (LLq ?t1.0 ?t2.0) (neg (eql ?t1.0 ?t2.0))›*) subst2_fresh_switch (*‹⟦?φ ∈ fmla; ?t ∈ trm; ?s ∈ trm; ?x ∈ var; ?y ∈ var; ?x ≠ ?y; ?x ∉ FvarsT ?s; ?y ∉ FvarsT ?t⟧ ⟹ subst (subst ?φ ?s ?y) ?t ?x = subst (subst ?φ ?t ?x) ?s ?y›*) Ls_def (*‹Ls ≡ cnj Lq (neg (eql (Var xx) (Var yy)))›*)) lemma psubst_LLs[simp]: assumes 1: "t1 ∈ atrm" "t2 ∈ atrm" "fst ` set txs ⊆ atrm" and 2: "snd ` set txs ⊆ var" and 3: "distinct (map snd txs)" shows "psubst (LLs t1 t2) txs = LLs (psubstT t1 txs) (psubstT t2 txs)" proof (-) (*goal: ‹psubst (LLs t1 t2) txs = LLs (psubstT t1 txs) (psubstT t2 txs)›*) have 0: "t1 ∈ trm" "t2 ∈ trm" "fst ` set txs ⊆ trm" using "1" (*‹t1 ∈ atrm› ‹t2 ∈ atrm› ‹fst ` set (txs::('trm × 'var) list) ⊆ atrm›*) apply - (*goals: 1. ‹⟦t1 ∈ atrm; t2 ∈ atrm; fst ` set txs ⊆ atrm⟧ ⟹ t1 ∈ trm› 2. ‹⟦t1 ∈ atrm; t2 ∈ atrm; fst ` set txs ⊆ atrm⟧ ⟹ t2 ∈ trm› 3. ‹⟦t1 ∈ atrm; t2 ∈ atrm; fst ` set txs ⊆ atrm⟧ ⟹ fst ` set txs ⊆ trm› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . define z where z: "z ≡ getFr ([xx,yy] @ map snd txs) ([t1,t2] @ map fst txs) []" have us_facts: "z ∈ var" "z ≠ xx" "z ≠ yy" "z ∉ FvarsT t1" "z ∉ FvarsT t2" "z ∉ ⋃ (FvarsT ` (fst ` (set txs)))" "z ∉ snd ` (set txs)" using "0" (*‹(t1::'trm) ∈ (trm::'trm set)› ‹t2 ∈ trm› ‹fst ` set txs ⊆ trm›*) "2" (*‹snd ` set txs ⊆ var›*) unfolding z (*goals: 1. ‹getFr ([xx, yy] @ map snd (txs::('trm × 'var) list)) ([t1::'trm, t2::'trm] @ map fst txs) [] ∈ (var::'var set)› 2. ‹getFr ([xx, yy] @ map snd (txs::('trm × 'var) list)) ([t1::'trm, t2::'trm] @ map fst txs) [] ≠ xx› 3. ‹getFr ([xx, yy] @ map snd (txs::('trm × 'var) list)) ([t1::'trm, t2::'trm] @ map fst txs) [] ≠ yy› 4. ‹getFr ([xx, yy] @ map snd (txs::('trm × 'var) list)) ([t1::'trm, t2::'trm] @ map fst txs) [] ∉ (FvarsT::'trm ⇒ 'var set) t1› 5. ‹getFr ([xx, yy] @ map snd (txs::('trm × 'var) list)) ([t1::'trm, t2::'trm] @ map fst txs) [] ∉ (FvarsT::'trm ⇒ 'var set) t2› 6. ‹getFr ([xx, yy] @ map snd (txs::('trm × 'var) list)) ([t1::'trm, t2::'trm] @ map fst txs) [] ∉ ⋃ ((FvarsT::'trm ⇒ 'var set) ` fst ` set txs)› 7. ‹getFr ([xx, yy] @ map snd (txs::('trm × 'var) list)) ([t1::'trm, t2::'trm] @ map fst txs) [] ∉ snd ` set txs›*) using getFr_FvarsT[of "[xx,yy] @ map snd txs" "[t1,t2] @ map fst txs" "[]"] (*‹⟦set ([xx, yy] @ map snd (txs::('trm × 'var) list)) ⊆ (var::'var set); set ([t1::'trm, t2::'trm] @ map fst txs) ⊆ (trm::'trm set); set [] ⊆ (fmla::'fmla set); (?t::'trm) ∈ set ([t1, t2] @ map fst txs)⟧ ⟹ getFr ([xx, yy] @ map snd txs) ([t1, t2] @ map fst txs) [] ∉ (FvarsT::'trm ⇒ 'var set) ?t›*) getFr_Fvars[of "[xx,yy] @ map snd txs" "[t1,t2] @ map fst txs" "[]"] (*‹⟦set ([xx, yy] @ map snd txs) ⊆ var; set ([t1, t2] @ map fst txs) ⊆ trm; set [] ⊆ fmla; ?φ ∈ set []⟧ ⟹ getFr ([xx, yy] @ map snd txs) ([t1, t2] @ map fst txs) [] ∉ Fvars ?φ›*) getFr_var[of "[xx,yy] @ map snd txs" "[t1,t2] @ map fst txs" "[]"] (*‹⟦set ([xx, yy] @ map snd txs) ⊆ var; set ([t1, t2] @ map fst txs) ⊆ trm; set [] ⊆ fmla; ?t ∈ set ([t1, t2] @ map fst txs)⟧ ⟹ getFr ([xx, yy] @ map snd txs) ([t1, t2] @ map fst txs) [] ∉ set ([xx, yy] @ map snd txs)›*) apply - (*top goal: ‹getFr ([xx, yy] @ map snd (txs::('trm × 'var) list)) ([t1::'trm, t2::'trm] @ map fst txs) [] ∈ (var::'var set)› and 6 goals remain*) subgoal for by auto subgoal for by force subgoal for by force subgoal for by force subgoal for by force subgoal for by auto subgoal for by (force simp: image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*)) . show "?thesis" (*goal: ‹psubst (LLs (t1::'trm) (t2::'trm)) (txs::('trm × 'var) list) = LLs (psubstT t1 txs) (psubstT t2 txs)›*) using assms (*‹t1 ∈ atrm› ‹t2 ∈ atrm› ‹fst ` set txs ⊆ atrm› ‹snd ` set txs ⊆ var› ‹distinct (map snd txs)›*) "0" (*‹(t1::'trm) ∈ (trm::'trm set)› ‹t2 ∈ trm› ‹fst ` set txs ⊆ trm›*) us_facts (*‹z ∈ var› ‹z ≠ xx› ‹z ≠ yy› ‹(z::'var::type) ∉ (FvarsT::'trm::type ⇒ 'var::type set) (t1::'trm::type)› ‹(z::'var) ∉ (FvarsT::'trm ⇒ 'var set) (t2::'trm)› ‹z ∉ ⋃ (FvarsT ` fst ` set txs)› ‹(z::'var) ∉ snd ` set (txs::('trm × 'var) list)›*) by (simp add: LLs_LLq (*‹⟦?t1.0 ∈ atrm; ?t2.0 ∈ atrm⟧ ⟹ LLs ?t1.0 ?t2.0 = cnj (LLq ?t1.0 ?t2.0) (neg (eql ?t1.0 ?t2.0))›*)) qed section ‹Bounded Quantification› text ‹Bounded forall› definition ball :: "'var ⇒ 'trm ⇒ 'fmla ⇒ 'fmla" where "ball x t φ ≡ all x (imp (LLq (Var x) t) φ)" lemma ball[simp, intro]: "x ∈ var ⟹ t ∈ trm ⟹ φ ∈ fmla ⟹ ball x t φ ∈ fmla" unfolding ball_def (*goal: ‹⟦x ∈ var; t ∈ trm; φ ∈ fmla⟧ ⟹ all x (imp (LLq (Var x) t) φ) ∈ fmla›*) by auto lemma Fvars_ball[simp]: "x ∈ var ⟹ φ ∈ fmla ⟹ t ∈ trm ⟹ Fvars (ball x t φ) = (Fvars φ ∪ FvarsT t) - {x}" unfolding ball_def (*goal: ‹⟦x ∈ var; φ ∈ fmla; t ∈ trm⟧ ⟹ Fvars (all x (imp (LLq (Var x) t) φ)) = Fvars φ ∪ FvarsT t - {x}›*) by auto lemma subst_ball: "φ ∈ fmla ⟹ t ∈ atrm ⟹ t1 ∈ atrm ⟹ x ∈ var ⟹ y ∈ var ⟹ x ≠ y ⟹ x ∉ FvarsT t1 ⟹ subst (ball x t φ) t1 y = ball x (substT t t1 y) (subst φ t1 y)" unfolding ball_def (*goal: ‹⟦φ ∈ fmla; t ∈ atrm; t1 ∈ atrm; x ∈ var; y ∈ var; x ≠ y; x ∉ FvarsT t1⟧ ⟹ subst (all x (imp (LLq (Var x) t) φ)) t1 y = all x (imp (LLq (Var x) (substT t t1 y)) (subst φ t1 y))›*) by simp lemma psubst_ball: "φ ∈ fmla ⟹ y ∈ var ⟹ snd ` set txs ⊆ var ⟹ t ∈ atrm ⟹ fst ` set txs ⊆ trm ⟹ fst ` set txs ⊆ atrm ⟹ y ∉ snd ` set txs ⟹ y ∉ (⋃t ∈ fst ` set txs. FvarsT t) ⟹ distinct (map snd txs) ⟹ psubst (ball y t φ) txs = ball y (psubstT t txs) (psubst φ txs)" unfolding ball_def (*goal: ‹⟦φ ∈ fmla; y ∈ var; snd ` set txs ⊆ var; t ∈ atrm; fst ` set txs ⊆ trm; fst ` set txs ⊆ atrm; y ∉ snd ` set txs; y ∉ ⋃ (FvarsT ` fst ` set txs); distinct (map snd txs)⟧ ⟹ psubst (all y (imp (LLq (Var y) t) φ)) txs = all y (imp (LLq (Var y) (psubstT t txs)) (psubst φ txs))›*) by simp text ‹Bounded exists› definition bexi :: "'var ⇒ 'trm ⇒ 'fmla ⇒ 'fmla" where "bexi x t φ ≡ exi x (cnj (LLq (Var x) t) φ)" lemma bexi[simp, intro]: "x ∈ var ⟹ t ∈ trm ⟹ φ ∈ fmla ⟹ bexi x t φ ∈ fmla" unfolding bexi_def (*goal: ‹⟦x ∈ var; t ∈ trm; φ ∈ fmla⟧ ⟹ exi x (cnj (LLq (Var x) t) φ) ∈ fmla›*) by auto lemma Fvars_bexi[simp]: "x ∈ var ⟹ φ ∈ fmla ⟹ t ∈ trm ⟹ Fvars (bexi x t φ) = (Fvars φ ∪ FvarsT t) - {x}" unfolding bexi_def (*goal: ‹⟦(x::'var) ∈ (var::'var set); (φ::'fmla) ∈ (fmla::'fmla set); (t::'trm) ∈ (trm::'trm set)⟧ ⟹ (Fvars::'fmla ⇒ 'var set) ((exi::'var ⇒ 'fmla ⇒ 'fmla) x ((cnj::'fmla ⇒ 'fmla ⇒ 'fmla) (LLq ((Var::'var ⇒ 'trm) x) t) φ)) = Fvars φ ∪ (FvarsT::'trm ⇒ 'var set) t - {x}›*) by auto lemma subst_bexi: "φ ∈ fmla ⟹ t ∈ atrm ⟹ t1 ∈ atrm ⟹ x ∈ var ⟹ y ∈ var ⟹ x ≠ y ⟹ x ∉ FvarsT t1 ⟹ subst (bexi x t φ) t1 y = bexi x (substT t t1 y) (subst φ t1 y)" unfolding bexi_def (*goal: ‹⟦(φ::'fmla) ∈ (fmla::'fmla set); (t::'trm) ∈ atrm; (t1::'trm) ∈ atrm; (x::'var) ∈ (var::'var set); (y::'var) ∈ var; x ≠ y; x ∉ (FvarsT::'trm ⇒ 'var set) t1⟧ ⟹ (subst::'fmla ⇒ 'trm ⇒ 'var ⇒ 'fmla) ((exi::'var ⇒ 'fmla ⇒ 'fmla) x ((cnj::'fmla ⇒ 'fmla ⇒ 'fmla) (LLq ((Var::'var ⇒ 'trm) x) t) φ)) t1 y = exi x (cnj (LLq (Var x) ((substT::'trm ⇒ 'trm ⇒ 'var ⇒ 'trm) t t1 y)) (subst φ t1 y))›*) by simp lemma psubst_bexi: "φ ∈ fmla ⟹ y ∈ var ⟹ snd ` set txs ⊆ var ⟹ t ∈ atrm ⟹ fst ` set txs ⊆ trm ⟹ fst ` set txs ⊆ atrm ⟹ y ∉ snd ` set txs ⟹ y ∉ (⋃t ∈ fst ` set txs. FvarsT t) ⟹ distinct (map snd txs) ⟹ psubst (bexi y t φ) txs = bexi y (psubstT t txs) (psubst φ txs)" unfolding bexi_def (*goal: ‹⟦φ ∈ fmla; y ∈ var; snd ` set txs ⊆ var; t ∈ atrm; fst ` set txs ⊆ trm; fst ` set txs ⊆ atrm; y ∉ snd ` set txs; y ∉ ⋃ (FvarsT ` fst ` set txs); distinct (map snd txs)⟧ ⟹ psubst (exi y (cnj (LLq (Var y) t) φ)) txs = exi y (cnj (LLq (Var y) (psubstT t txs)) (psubst φ txs))›*) by simp end ― ‹context @{locale Syntax_Arith}› (*<*) end (*>*)
{ "path": "afp-2025-02-12/thys/Syntax_Independent_Logic/Syntax_Arith.thy", "repo": "afp-2025-02-12", "sha": "cae8e04558d2c0fb7cd88ace539d0d963d235512e237b7cfad4448e4525884e6" }
section ‹Partial and total correctness› theory Quantum_Hoare imports Quantum_Program begin context state_sig begin definition density_states :: "state set" where "density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}" lemma denote_density_states: "ρ ∈ density_states ⟹ well_com S ⟹ denote S ρ ∈ density_states" by (simp add: denote_dim_pdo (*‹⟦well_com ?S; ?ρ ∈ carrier_mat d d; partial_density_operator ?ρ⟧ ⟹ denote ?S ?ρ ∈ carrier_mat d d ∧ partial_density_operator (denote ?S ?ρ)›*) density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*)) definition is_quantum_predicate :: "complex mat ⇒ bool" where "is_quantum_predicate P ⟷ P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d" lemma trace_measurement2: assumes m: "measurement n 2 M" and dA: "A ∈ carrier_mat n n" shows "trace ((M 0) * A * adjoint (M 0)) + trace ((M 1) * A * adjoint (M 1)) = trace A" proof (-) (*goal: ‹trace (M 0 * A * adjoint (M 0)) + trace (M 1 * A * adjoint (M 1)) = trace A›*) from m (*‹measurement n 2 M›*) have dM0: "M 0 ∈ carrier_mat n n" and dM1: "M 1 ∈ carrier_mat n n" and id: "adjoint (M 0) * (M 0) + adjoint (M 1) * (M 1) = 1⇩m n" using measurement_def (*‹measurement ?d ?n ?M = ((∀j<?n. ?M j ∈ carrier_mat ?d ?d) ∧ matrix_sum ?d (λj. adjoint (?M j) * ?M j) ?n = 1⇩m ?d)›*) measurement_id2 (*‹measurement ?d 2 ?M ⟹ adjoint (?M 0) * ?M 0 + adjoint (?M 1) * ?M 1 = 1⇩m ?d›*) apply - (*goals: 1. ‹⟦measurement (n::nat) (2::nat) (M::nat ⇒ complex mat); ⋀(d::nat) (n::nat) M::nat ⇒ complex mat. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj::nat. adjoint (M j) * M j) n = 1⇩m d); ⋀(d::nat) M::nat ⇒ complex mat. measurement d (2::nat) M ⟹ adjoint (M (0::nat)) * M (0::nat) + adjoint (M (1::nat)) * M (1::nat) = 1⇩m d⟧ ⟹ M (0::nat) ∈ carrier_mat n n› 2. ‹⟦measurement (n::nat) (2::nat) (M::nat ⇒ complex mat); ⋀(d::nat) (n::nat) M::nat ⇒ complex mat. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj::nat. adjoint (M j) * M j) n = 1⇩m d); ⋀(d::nat) M::nat ⇒ complex mat. measurement d (2::nat) M ⟹ adjoint (M (0::nat)) * M (0::nat) + adjoint (M (1::nat)) * M (1::nat) = 1⇩m d⟧ ⟹ M (1::nat) ∈ carrier_mat n n› 3. ‹⟦measurement (n::nat) (2::nat) (M::nat ⇒ complex mat); ⋀(d::nat) (n::nat) M::nat ⇒ complex mat. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj::nat. adjoint (M j) * M j) n = 1⇩m d); ⋀(d::nat) M::nat ⇒ complex mat. measurement d (2::nat) M ⟹ adjoint (M (0::nat)) * M (0::nat) + adjoint (M (1::nat)) * M (1::nat) = 1⇩m d⟧ ⟹ adjoint (M (0::nat)) * M (0::nat) + adjoint (M (1::nat)) * M (1::nat) = 1⇩m n› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . have "trace (M 1 * A * adjoint (M 1)) + trace (M 0 * A * adjoint (M 0)) = trace ((adjoint (M 0) * M 0 + adjoint (M 1) * M 1) * A)" using dM0 (*‹M 0 ∈ carrier_mat n n›*) dM1 (*‹M 1 ∈ carrier_mat n n›*) dA (*‹A ∈ carrier_mat n n›*) by (mat_assoc n) also (*calculation: ‹trace ((M::nat ⇒ complex mat) (1::nat) * (A::complex mat) * adjoint (M (1::nat))) + trace (M (0::nat) * A * adjoint (M (0::nat))) = trace ((adjoint (M (0::nat)) * M (0::nat) + adjoint (M (1::nat)) * M (1::nat)) * A)›*) have "… = trace (1⇩m n * A)" using id (*‹adjoint (M 0) * M 0 + adjoint (M 1) * M 1 = 1⇩m n›*) by auto also (*calculation: ‹trace (M 1 * A * adjoint (M 1)) + trace (M 0 * A * adjoint (M 0)) = trace (1⇩m n * A)›*) have "… = trace A" using dA (*‹A ∈ carrier_mat n n›*) by auto finally (*calculation: ‹trace (M 1 * A * adjoint (M 1)) + trace (M 0 * A * adjoint (M 0)) = trace A›*) show "?thesis" (*goal: ‹trace (M 0 * A * adjoint (M 0)) + trace (M 1 * A * adjoint (M 1)) = trace A›*) using dA (*‹(A::complex mat) ∈ carrier_mat (n::nat) n›*) dM0 (*‹M 0 ∈ carrier_mat n n›*) dM1 (*‹(M::nat ⇒ complex mat) (1::nat) ∈ carrier_mat (n::nat) n›*) local.id (*‹adjoint (M 0) * M 0 + adjoint (M 1) * M 1 = 1⇩m n›*) state_sig.trace_measure2_id (*‹⟦?M0.0 ∈ carrier_mat ?n ?n; ?M1.0 ∈ carrier_mat ?n ?n; adjoint ?M0.0 * ?M0.0 + adjoint ?M1.0 * ?M1.0 = 1⇩m ?n; ?A ∈ carrier_mat ?n ?n⟧ ⟹ trace (?M0.0 * ?A * adjoint ?M0.0) + trace (?M1.0 * ?A * adjoint ?M1.0) = trace ?A›*) by blast qed lemma qp_close_under_unitary_operator: fixes U P :: "complex mat" assumes dU: "U ∈ carrier_mat d d" and u: "unitary U" and qp: "is_quantum_predicate P" shows "is_quantum_predicate (adjoint U * P * U)" unfolding is_quantum_predicate_def (*goal: ‹adjoint U * P * U ∈ carrier_mat d d ∧ positive (adjoint U * P * U) ∧ adjoint U * P * U ≤⇩L 1⇩m d›*) proof (auto) (*goals: 1. ‹adjoint (U::complex mat) * (P::complex mat) * U ∈ carrier_mat d d› 2. ‹positive (adjoint (U::complex mat) * (P::complex mat) * U)› 3. ‹adjoint (U::complex mat) * (P::complex mat) * U ≤⇩L 1⇩m d›*) have dP: "P ∈ carrier_mat d d" using qp (*‹is_quantum_predicate P›*) is_quantum_predicate_def (*‹is_quantum_predicate (?P::complex mat) = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto show "adjoint U * P * U ∈ carrier_mat d d" using dU (*‹U ∈ carrier_mat d d›*) dP (*‹P ∈ carrier_mat d d›*) by fastforce have "positive P" using qp (*‹is_quantum_predicate P›*) is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto then show "positive (adjoint U * P * U)" using positive_close_under_left_right_mult_adjoint[OF adjoint_dim [ OF dU ] dP, simplified adjoint_adjoint] (*‹positive (P::complex mat) ⟹ positive (adjoint (U::complex mat) * P * U)›*) by fastforce have "adjoint U * U = 1⇩m d" apply (subgoal_tac "inverts_mat (adjoint U) U") (*goal: ‹adjoint U * U = 1⇩m d›*) subgoal for unfolding inverts_mat_def (*goal: ‹adjoint U * U = 1⇩m (dim_row (adjoint U)) ⟹ adjoint U * U = 1⇩m d›*) using dU (*‹U ∈ carrier_mat d d›*) by auto using u (*‹unitary U›*) unfolding unitary_def (*goal: ‹inverts_mat (adjoint U) U›*) using inverts_mat_symm[OF dU adjoint_dim [ OF dU ]] (*‹inverts_mat (U::complex mat) (adjoint U) ⟹ inverts_mat (adjoint U) U›*) by auto then have u': "adjoint U * 1⇩m d * U = 1⇩m d" using dU (*‹U ∈ carrier_mat d d›*) by auto have le: "P ≤⇩L 1⇩m d" using qp (*‹is_quantum_predicate P›*) is_quantum_predicate_def (*‹is_quantum_predicate (?P::complex mat) = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto show "adjoint U * P * U ≤⇩L 1⇩m d" using lowner_le_keep_under_measurement[OF dU dP one_carrier_mat le] (*‹adjoint U * P * U ≤⇩L adjoint U * 1⇩m d * U›*) u' (*‹adjoint U * 1⇩m d * U = 1⇩m d›*) by auto qed lemma qps_after_measure_is_qp: assumes m: "measurement d n M " and qpk: "⋀k. k < n ⟹ is_quantum_predicate (P k)" shows "is_quantum_predicate (matrix_sum d (λk. adjoint (M k) * P k * M k) n)" unfolding is_quantum_predicate_def (*goal: ‹matrix_sum d (λk. adjoint (M k) * P k * M k) n ∈ carrier_mat d d ∧ positive (matrix_sum d (λk. adjoint (M k) * P k * M k) n) ∧ matrix_sum d (λk. adjoint (M k) * P k * M k) n ≤⇩L 1⇩m d›*) proof (auto) (*goals: 1. ‹matrix_sum d (λk::nat. adjoint ((M::nat ⇒ complex mat) k) * (P::nat ⇒ complex mat) k * M k) (n::nat) ∈ carrier_mat d d› 2. ‹positive (matrix_sum d (λk::nat. adjoint ((M::nat ⇒ complex mat) k) * (P::nat ⇒ complex mat) k * M k) (n::nat))› 3. ‹matrix_sum d (λk::nat. adjoint ((M::nat ⇒ complex mat) k) * (P::nat ⇒ complex mat) k * M k) (n::nat) ≤⇩L 1⇩m d›*) have dMk: "k < n ⟹ M k ∈ carrier_mat d d" for k using m (*‹measurement d n M›*) measurement_def (*‹measurement ?d ?n ?M = ((∀j<?n. ?M j ∈ carrier_mat ?d ?d) ∧ matrix_sum ?d (λj. adjoint (?M j) * ?M j) ?n = 1⇩m ?d)›*) by auto moreover have dPk: "k < n ⟹ P k ∈ carrier_mat d d" for k using qpk (*‹(?k::nat) < (n::nat) ⟹ is_quantum_predicate ((P::nat ⇒ complex mat) ?k)›*) is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto ultimately have dk: "k < n ⟹ adjoint (M k) * P k * M k ∈ carrier_mat d d" for k by fastforce then show d: "matrix_sum d (λk. adjoint (M k) * P k * M k) n ∈ carrier_mat d d" using matrix_sum_dim[of n "λk. adjoint (M k) * P k * M k"] (*‹(⋀k. k < n ⟹ adjoint (M k) * P k * M k ∈ carrier_mat ?d ?d) ⟹ matrix_sum ?d (λk. adjoint (M k) * P k * M k) n ∈ carrier_mat ?d ?d›*) by auto have "k < n ⟹ positive (P k)" for k using qpk (*‹?k < n ⟹ is_quantum_predicate (P ?k)›*) is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto then have "k < n ⟹ positive (adjoint (M k) * P k * M k)" for k using positive_close_under_left_right_mult_adjoint[OF adjoint_dim [ OF dMk ] dPk, simplified adjoint_adjoint] (*‹⟦?k3 < n; ?k1 < n; positive (P ?k1)⟧ ⟹ positive (adjoint (M ?k3) * P ?k1 * M ?k3)›*) by fastforce then show "positive (matrix_sum d (λk. adjoint (M k) * P k * M k) n)" using matrix_sum_positive (*‹⟦⋀k. k < ?n ⟹ ?f k ∈ carrier_mat ?d ?d; ⋀k. k < ?n ⟹ positive (?f k)⟧ ⟹ positive (matrix_sum ?d ?f ?n)›*) dk (*‹?k < n ⟹ adjoint (M ?k) * P ?k * M ?k ∈ carrier_mat d d›*) by auto have "k < n ⟹ P k ≤⇩L 1⇩m d" for k using qpk (*‹?k < n ⟹ is_quantum_predicate (P ?k)›*) is_quantum_predicate_def (*‹is_quantum_predicate (?P::complex mat) = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto then have "k < n ⟹ positive (1⇩m d - P k)" for k using lowner_le_def (*‹(?A ≤⇩L ?B) = (dim_row ?A = dim_row ?B ∧ dim_col ?A = dim_col ?B ∧ positive (?B - ?A))›*) by auto then have p: "k < n ⟹ positive (adjoint (M k) * (1⇩m d - P k) * M k)" for k using positive_close_under_left_right_mult_adjoint[OF adjoint_dim [ OF dMk ], simplified adjoint_adjoint, of _ "1⇩m d - P k"] (*‹⟦?k2 < n; 1⇩m d - P k ∈ carrier_mat d d; positive (1⇩m d - P k)⟧ ⟹ positive (adjoint (M ?k2) * (1⇩m d - P k) * M ?k2)›*) dPk (*‹?k < n ⟹ P ?k ∈ carrier_mat d d›*) by fastforce { fix k assume k: "k < n" (*‹(k::nat) < (n::nat)›*) have "adjoint (M k) * (1⇩m d - P k) * M k = adjoint (M k) * M k - adjoint (M k) * P k * M k" apply (mat_assoc d) (*goal: ‹adjoint (M k) * (1⇩m d - P k) * M k = adjoint (M k) * M k - adjoint (M k) * P k * M k›*) using dMk (*‹(?k::nat) < (n::nat) ⟹ (M::nat ⇒ complex mat) ?k ∈ carrier_mat d d›*) dPk (*‹?k < n ⟹ P ?k ∈ carrier_mat d d›*) k (*‹k < n›*) apply - (*goals: 1. ‹⟦⋀k. k < n ⟹ M k ∈ carrier_mat d d; ⋀k. k < n ⟹ P k ∈ carrier_mat d d; k < n⟧ ⟹ P k ∈ carrier_mat d d› 2. ‹⟦⋀k. k < n ⟹ M k ∈ carrier_mat d d; ⋀k. k < n ⟹ P k ∈ carrier_mat d d; k < n⟧ ⟹ M k ∈ carrier_mat d d› 3. ‹⟦⋀k. k < n ⟹ M k ∈ carrier_mat d d; ⋀k. k < n ⟹ P k ∈ carrier_mat d d; k < n⟧ ⟹ 1⇩m d ∈ carrier_mat d d› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . } note split = this (*‹?k2 < n ⟹ adjoint (M ?k2) * (1⇩m d - P ?k2) * M ?k2 = adjoint (M ?k2) * M ?k2 - adjoint (M ?k2) * P ?k2 * M ?k2›*) have dk': "k < n ⟹ adjoint (M k) * M k - adjoint (M k) * P k * M k ∈ carrier_mat d d" for k using dMk (*‹?k < n ⟹ M ?k ∈ carrier_mat d d›*) dPk (*‹(?k::nat) < (n::nat) ⟹ (P::nat ⇒ complex mat) ?k ∈ carrier_mat d d›*) by fastforce have "k < n ⟹ positive (adjoint (M k) * M k - adjoint (M k) * P k * M k)" for k using p (*‹?k < n ⟹ positive (adjoint (M ?k) * (1⇩m d - P ?k) * M ?k)›*) split (*‹?k2 < n ⟹ adjoint (M ?k2) * (1⇩m d - P ?k2) * M ?k2 = adjoint (M ?k2) * M ?k2 - adjoint (M ?k2) * P ?k2 * M ?k2›*) by auto then have p': "positive (matrix_sum d (λk. adjoint (M k) * M k - adjoint (M k) * P k * M k) n)" using matrix_sum_positive[OF dk', of n id, simplified] (*‹(⋀k::nat. k < (n::nat) ⟹ positive (adjoint ((M::nat ⇒ complex mat) k) * M k - adjoint (M k) * (P::nat ⇒ complex mat) k * M k)) ⟹ positive (matrix_sum d (λk::nat. adjoint (M k) * M k - adjoint (M k) * P k * M k) n)›*) by auto have daMMk: "k < n ⟹ adjoint (M k) * M k ∈ carrier_mat d d" for k using dMk (*‹(?k::nat) < (n::nat) ⟹ (M::nat ⇒ complex mat) ?k ∈ carrier_mat d d›*) by fastforce have daMPMk: "k < n ⟹ adjoint (M k) * P k * M k ∈ carrier_mat d d" for k using dMk (*‹?k < n ⟹ M ?k ∈ carrier_mat d d›*) dPk (*‹(?k::nat) < (n::nat) ⟹ (P::nat ⇒ complex mat) ?k ∈ carrier_mat d d›*) by fastforce have "matrix_sum d (λk. adjoint (M k) * M k - adjoint (M k) * P k * M k) n = matrix_sum d (λk. adjoint (M k) * M k) n - matrix_sum d (λk. adjoint (M k) * P k * M k) n" using matrix_sum_minus_distrib[OF daMMk daMPMk] (*‹⟦⋀k. k < ?n ⟹ ?k2 k < n; ⋀k. k < ?n ⟹ ?k1 k < n⟧ ⟹ matrix_sum d (λk. adjoint (M (?k2 k)) * M (?k2 k) - adjoint (M (?k1 k)) * P (?k1 k) * M (?k1 k)) ?n = matrix_sum d (λk. adjoint (M (?k2 k)) * M (?k2 k)) ?n - matrix_sum d (λk. adjoint (M (?k1 k)) * P (?k1 k) * M (?k1 k)) ?n›*) by auto also (*calculation: ‹matrix_sum d (λk. adjoint (M k) * M k - adjoint (M k) * P k * M k) n = matrix_sum d (λk. adjoint (M k) * M k) n - matrix_sum d (λk. adjoint (M k) * P k * M k) n›*) have "… = 1⇩m d - matrix_sum d (λk. adjoint (M k) * P k * M k) n" using m (*‹measurement d n M›*) measurement_def (*‹measurement (?d::nat) (?n::nat) (?M::nat ⇒ complex mat) = ((∀j<?n. ?M j ∈ carrier_mat ?d ?d) ∧ matrix_sum ?d (λj::nat. adjoint (?M j) * ?M j) ?n = 1⇩m ?d)›*) by auto finally (*calculation: ‹matrix_sum d (λk. adjoint (M k) * M k - adjoint (M k) * P k * M k) n = 1⇩m d - matrix_sum d (λk. adjoint (M k) * P k * M k) n›*) have "positive (1⇩m d - matrix_sum d (λk. adjoint (M k) * P k * M k) n)" using p' (*‹positive (matrix_sum d (λk. adjoint (M k) * M k - adjoint (M k) * P k * M k) n)›*) by auto then show "matrix_sum d (λk. adjoint (M k) * P k * M k) n ≤⇩L 1⇩m d" using lowner_le_def (*‹(?A ≤⇩L ?B) = (dim_row ?A = dim_row ?B ∧ dim_col ?A = dim_col ?B ∧ positive (?B - ?A))›*) d (*‹matrix_sum d (λk. adjoint (M k) * P k * M k) n ∈ carrier_mat d d›*) by auto qed definition hoare_total_correct :: "complex mat ⇒ com ⇒ complex mat ⇒ bool" ("⊨⇩t {(1_)}/ (_)/ {(1_)}" 50) where "⊨⇩t {P} S {Q} ⟷ (∀ρ∈density_states. trace (P * ρ) ≤ trace (Q * denote S ρ))" definition hoare_partial_correct :: "complex mat ⇒ com ⇒ complex mat ⇒ bool" ("⊨⇩p {(1_)}/ (_)/ {(1_)}" 50) where "⊨⇩p {P} S {Q} ⟷ (∀ρ∈density_states. trace (P * ρ) ≤ trace (Q * denote S ρ) + (trace ρ - trace (denote S ρ)))" (* Proposition 6.1 (1) *) lemma total_implies_partial: assumes S: "well_com S" and total: "⊨⇩t {P} S {Q}" shows "⊨⇩p {P} S {Q}" proof (-) (*goal: ‹⊨⇩p {P} S {Q}›*) have "trace (P * ρ) ≤ trace (Q * denote S ρ) + (trace ρ - trace (denote S ρ))" if "ρ": "ρ ∈ density_states" for ρ proof (-) (*goal: ‹trace (P * ρ) ≤ trace (Q * denote S ρ) + (trace ρ - trace (denote S ρ))›*) have "trace (P * ρ) ≤ trace (Q * denote S ρ)" using total (*‹⊨⇩t {P} S {Q}›*) hoare_total_correct_def (*‹(⊨⇩t {?P::complex mat} ?S::com {?Q::complex mat}) = (∀ρ::complex mat∈density_states. trace (?P * ρ) ≤ trace (?Q * denote ?S ρ))›*) "ρ" (*‹ρ ∈ density_states›*) by auto moreover have "trace (denote S ρ) ≤ trace ρ" using denote_trace[OF S] (*‹⟦(?ρ::complex mat) ∈ carrier_mat d d; partial_density_operator ?ρ⟧ ⟹ trace (denote (S::com) ?ρ) ≤ trace ?ρ›*) "ρ" (*‹(ρ::complex mat) ∈ density_states›*) density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) by auto ultimately show "?thesis" (*goal: ‹trace (P * ρ) ≤ trace (Q * denote S ρ) + (trace ρ - trace (denote S ρ))›*) by (auto simp: less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) qed then show "?thesis" (*goal: ‹⊨⇩p {P::complex mat} S::com {Q::complex mat}›*) using hoare_partial_correct_def (*‹(⊨⇩p {?P::complex mat} ?S::com {?Q::complex mat}) = (∀ρ::complex mat∈density_states. trace (?P * ρ) ≤ trace (?Q * denote ?S ρ) + (trace ρ - trace (denote ?S ρ)))›*) by auto qed lemma predicate_prob_positive: assumes "0⇩m d d ≤⇩L P" and "ρ ∈ density_states" shows "0 ≤ trace (P * ρ)" proof (-) (*goal: ‹0 ≤ trace (P * ρ)›*) have "trace (0⇩m d d * ρ) ≤ trace (P * ρ)" apply (rule lowner_le_traceD (*‹⟦?A ∈ carrier_mat ?n ?n; ?B ∈ carrier_mat ?n ?n; ?ρ ∈ carrier_mat ?n ?n; ?A ≤⇩L ?B; partial_density_operator ?ρ⟧ ⟹ trace (?A * ?ρ) ≤ trace (?B * ?ρ)›*)) (*goal: ‹trace (0⇩m d d * (ρ::complex mat)) ≤ trace ((P::complex mat) * ρ)›*) using assms (*‹0⇩m d d ≤⇩L P› ‹ρ ∈ density_states›*) unfolding lowner_le_def density_states_def (*goals: 1. ‹0⇩m d d ∈ carrier_mat ?n ?n› 2. ‹P ∈ carrier_mat ?n ?n› 3. ‹ρ ∈ carrier_mat ?n ?n› 4. ‹dim_row (0⇩m d d) = dim_row P ∧ dim_col (0⇩m d d) = dim_col P ∧ positive (P - 0⇩m d d)› 5. ‹partial_density_operator ρ›*) apply - (*goals: 1. ‹⟦dim_row (0⇩m d d) = dim_row P ∧ dim_col (0⇩m d d) = dim_col P ∧ positive (P - 0⇩m d d); ρ ∈ {ρ ∈ carrier_mat d d. partial_density_operator ρ}⟧ ⟹ 0⇩m d d ∈ carrier_mat ?n ?n› 2. ‹⟦dim_row (0⇩m d d) = dim_row P ∧ dim_col (0⇩m d d) = dim_col P ∧ positive (P - 0⇩m d d); ρ ∈ {ρ ∈ carrier_mat d d. partial_density_operator ρ}⟧ ⟹ P ∈ carrier_mat ?n ?n› 3. ‹⟦dim_row (0⇩m d d) = dim_row P ∧ dim_col (0⇩m d d) = dim_col P ∧ positive (P - 0⇩m d d); ρ ∈ {ρ ∈ carrier_mat d d. partial_density_operator ρ}⟧ ⟹ ρ ∈ carrier_mat ?n ?n› 4. ‹⟦dim_row (0⇩m d d) = dim_row P ∧ dim_col (0⇩m d d) = dim_col P ∧ positive (P - 0⇩m d d); ρ ∈ {ρ ∈ carrier_mat d d. partial_density_operator ρ}⟧ ⟹ dim_row (0⇩m d d) = dim_row P ∧ dim_col (0⇩m d d) = dim_col P ∧ positive (P - 0⇩m d d)› 5. ‹⟦dim_row (0⇩m d d) = dim_row P ∧ dim_col (0⇩m d d) = dim_col P ∧ positive (P - 0⇩m d d); ρ ∈ {ρ ∈ carrier_mat d d. partial_density_operator ρ}⟧ ⟹ partial_density_operator ρ› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . then show "?thesis" (*goal: ‹0 ≤ trace (P * ρ)›*) using assms(2) (*‹ρ ∈ density_states›*) density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) by auto qed (* Proposition 6.1 (2a) *) lemma total_pre_zero: assumes S: "well_com S" and Q: "is_quantum_predicate Q" shows "⊨⇩t {0⇩m d d} S {Q}" proof (-) (*goal: ‹⊨⇩t {0⇩m d d} S {Q}›*) have "trace (0⇩m d d * ρ) ≤ trace (Q * denote S ρ)" if "ρ": "ρ ∈ density_states" for ρ proof (-) (*goal: ‹trace (0⇩m d d * (ρ::complex mat)) ≤ trace ((Q::complex mat) * denote (S::com) ρ)›*) have 1: "trace (0⇩m d d * ρ) = 0" using "ρ" (*‹(ρ::complex mat) ∈ density_states›*) unfolding density_states_def (*goal: ‹trace (0⇩m d d * ρ) = 0›*) by auto show "?thesis" (*goal: ‹trace (0⇩m d d * ρ) ≤ trace (Q * denote S ρ)›*) apply (subst 1 (*‹trace (0⇩m d d * ρ) = 0›*)) (*goal: ‹trace (0⇩m d d * ρ) ≤ trace (Q * denote S ρ)›*) apply (rule predicate_prob_positive (*‹⟦0⇩m d d ≤⇩L (?P::complex mat); (?ρ::complex mat) ∈ density_states⟧ ⟹ (0::complex) ≤ trace (?P * ?ρ)›*)) (*goal: ‹(0::complex) ≤ trace ((Q::complex mat) * denote (S::com) (ρ::complex mat))›*) subgoal for apply (simp add: lowner_le_def (*‹(?A ≤⇩L ?B) = (dim_row ?A = dim_row ?B ∧ dim_col ?A = dim_col ?B ∧ positive (?B - ?A))›*), subgoal_tac "Q - 0⇩m d d = Q") (*goal: ‹0⇩m d d ≤⇩L Q›*) using Q (*‹is_quantum_predicate Q›*) is_quantum_predicate_def[of Q] (*‹is_quantum_predicate Q = (Q ∈ carrier_mat d d ∧ positive Q ∧ Q ≤⇩L 1⇩m d)›*) apply - (*goals: 1. ‹⟦Q - 0⇩m d d = Q; is_quantum_predicate Q; is_quantum_predicate Q = (Q ∈ carrier_mat d d ∧ positive Q ∧ Q ≤⇩L 1⇩m d)⟧ ⟹ d = dim_row Q ∧ d = dim_col Q ∧ positive (Q - 0⇩m d d)› 2. ‹⟦is_quantum_predicate Q; is_quantum_predicate Q = (Q ∈ carrier_mat d d ∧ positive Q ∧ Q ≤⇩L 1⇩m d)⟧ ⟹ Q - 0⇩m d d = Q› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . subgoal for using denote_density_states (*‹⟦?ρ ∈ density_states; well_com ?S⟧ ⟹ denote ?S ?ρ ∈ density_states›*) "ρ" (*‹(ρ::complex mat) ∈ density_states›*) S (*‹well_com (S::com)›*) by auto . qed then show "?thesis" (*goal: ‹⊨⇩t {0⇩m d d} S {Q}›*) using hoare_total_correct_def (*‹(⊨⇩t {?P} ?S {?Q}) = (∀ρ∈density_states. trace (?P * ρ) ≤ trace (?Q * denote ?S ρ))›*) by auto qed (* Proposition 6.1 (2b) *) lemma partial_post_identity: assumes S: "well_com S" and P: "is_quantum_predicate P" shows "⊨⇩p {P} S {1⇩m d}" proof (-) (*goal: ‹⊨⇩p {P} S {1⇩m d}›*) have "trace (P * ρ) ≤ trace (1⇩m d * denote S ρ) + (trace ρ - trace (denote S ρ))" if "ρ": "ρ ∈ density_states" for ρ proof (-) (*goal: ‹trace (P * ρ) ≤ trace (1⇩m d * denote S ρ) + (trace ρ - trace (denote S ρ))›*) have "denote S ρ ∈ carrier_mat d d" using S (*‹well_com S›*) denote_dim (*‹⟦well_com (?S::com); (?ρ::complex mat) ∈ carrier_mat d d; partial_density_operator ?ρ⟧ ⟹ denote ?S ?ρ ∈ carrier_mat d d›*) "ρ" (*‹(ρ::complex mat) ∈ density_states›*) density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) by auto then have "trace (1⇩m d * denote S ρ) = trace (denote S ρ)" by auto moreover have "trace (P * ρ) ≤ trace (1⇩m d * ρ)" apply (rule lowner_le_traceD (*‹⟦?A ∈ carrier_mat ?n ?n; ?B ∈ carrier_mat ?n ?n; ?ρ ∈ carrier_mat ?n ?n; ?A ≤⇩L ?B; partial_density_operator ?ρ⟧ ⟹ trace (?A * ?ρ) ≤ trace (?B * ?ρ)›*)) (*goal: ‹trace (P * ρ) ≤ trace (1⇩m d * ρ)›*) using "ρ" (*‹ρ ∈ density_states›*) unfolding density_states_def (*goals: 1. ‹P ∈ carrier_mat ?n ?n› 2. ‹1⇩m d ∈ carrier_mat ?n ?n› 3. ‹ρ ∈ carrier_mat ?n ?n› 4. ‹P ≤⇩L 1⇩m d› 5. ‹partial_density_operator ρ›*) apply auto (*top goal: ‹P ∈ carrier_mat ?n ?n› and 4 goals remain*) using P (*‹is_quantum_predicate P›*) is_quantum_predicate_def (*‹is_quantum_predicate (?P::complex mat) = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) apply - (*goals: 1. ‹⟦ρ ∈ carrier_mat d d; partial_density_operator ρ; is_quantum_predicate P; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ P ∈ carrier_mat d d› 2. ‹⟦ρ ∈ carrier_mat d d; partial_density_operator ρ; is_quantum_predicate P; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ P ≤⇩L 1⇩m d› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . ultimately show "?thesis" (*goal: ‹trace (P * ρ) ≤ trace (1⇩m d * denote S ρ) + (trace ρ - trace (denote S ρ))›*) using density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) that (*‹ρ ∈ density_states›*) by auto qed then show "?thesis" (*goal: ‹⊨⇩p {P} S {1⇩m d}›*) using hoare_partial_correct_def (*‹(⊨⇩p {?P::complex mat} ?S::com {?Q::complex mat}) = (∀ρ::complex mat∈density_states. trace (?P * ρ) ≤ trace (?Q * denote ?S ρ) + (trace ρ - trace (denote ?S ρ)))›*) by auto qed subsection ‹Weakest liberal preconditions› definition is_weakest_liberal_precondition :: "complex mat ⇒ com ⇒ complex mat ⇒ bool" where "is_weakest_liberal_precondition W S P ⟷ is_quantum_predicate W ∧ ⊨⇩p {W} S {P} ∧ (∀Q. is_quantum_predicate Q ⟶ ⊨⇩p {Q} S {P} ⟶ Q ≤⇩L W)" definition wlp_measure :: "nat ⇒ (nat ⇒ complex mat) ⇒ ((complex mat ⇒ complex mat) list) ⇒ complex mat ⇒ complex mat" where "wlp_measure n M WS P = matrix_sum d (λk. adjoint (M k) * ((WS!k) P) * (M k)) n" fun wlp_while_n :: "complex mat ⇒ complex mat ⇒ (complex mat ⇒ complex mat) ⇒ nat ⇒ complex mat ⇒ complex mat" where "wlp_while_n M0 M1 WS 0 P = 1⇩m d" | "wlp_while_n M0 M1 WS (Suc n) P = adjoint M0 * P * M0 + adjoint M1 * (WS (wlp_while_n M0 M1 WS n P)) * M1" lemma measurement2_leq_one_mat: assumes dP: "P ∈ carrier_mat d d" and dQ: "Q ∈ carrier_mat d d" and leP: "P ≤⇩L 1⇩m d" and leQ: "Q ≤⇩L 1⇩m d" and m: "measurement d 2 M" shows "(adjoint (M 0) * P * (M 0) + adjoint (M 1) * Q * (M 1)) ≤⇩L 1⇩m d" proof (-) (*goal: ‹adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1 ≤⇩L 1⇩m d›*) define M0 where "M0 = M 0" define M1 where "M1 = M 1" have dM0: "M0 ∈ carrier_mat d d" and dM1: "M1 ∈ carrier_mat d d" using m (*‹measurement d 2 M›*) M0_def (*‹M0 = M 0›*) M1_def (*‹(M1::complex mat) = (M::nat ⇒ complex mat) (1::nat)›*) measurement_def (*‹measurement (?d::nat) (?n::nat) (?M::nat ⇒ complex mat) = ((∀j<?n. ?M j ∈ carrier_mat ?d ?d) ∧ matrix_sum ?d (λj::nat. adjoint (?M j) * ?M j) ?n = 1⇩m ?d)›*) apply - (*goals: 1. ‹⟦measurement d 2 M; M0 = M 0; M1 = M 1; ⋀d n M. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj. adjoint (M j) * M j) n = 1⇩m d)⟧ ⟹ M0 ∈ carrier_mat d d› 2. ‹⟦measurement d 2 M; M0 = M 0; M1 = M 1; ⋀d n M. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj. adjoint (M j) * M j) n = 1⇩m d)⟧ ⟹ M1 ∈ carrier_mat d d› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have "adjoint M1 * Q * M1 ≤⇩L adjoint M1 * 1⇩m d * M1" using lowner_le_keep_under_measurement[OF dM1 dQ _ leQ] (*‹1⇩m d ∈ carrier_mat d d ⟹ adjoint M1 * Q * M1 ≤⇩L adjoint M1 * 1⇩m d * M1›*) by auto then have le1: "adjoint M1 * Q * M1 ≤⇩L adjoint M1 * M1" using dM1 (*‹M1 ∈ carrier_mat d d›*) dQ (*‹Q ∈ carrier_mat d d›*) by fastforce have "adjoint M0 * P * M0 ≤⇩L adjoint M0 * 1⇩m d * M0" using lowner_le_keep_under_measurement[OF dM0 dP _ leP] (*‹1⇩m d ∈ carrier_mat d d ⟹ adjoint (M0::complex mat) * (P::complex mat) * M0 ≤⇩L adjoint M0 * 1⇩m d * M0›*) by auto then have le0: "adjoint M0 * P * M0 ≤⇩L adjoint M0 * M0" using dM0 (*‹M0 ∈ carrier_mat d d›*) dP (*‹(P::complex mat) ∈ carrier_mat d d›*) by fastforce have "adjoint M0 * P * M0 + adjoint M1 * Q * M1 ≤⇩L adjoint M0 * M0 + adjoint M1 * M1" apply (rule lowner_le_add[of "adjoint M0 * P * M0" d "adjoint M0 * M0" "adjoint M1 * Q * M1" "adjoint M1 * M1"] (*‹⟦adjoint M0 * P * M0 ∈ carrier_mat d d; adjoint M0 * M0 ∈ carrier_mat d d; adjoint M1 * Q * M1 ∈ carrier_mat d d; adjoint M1 * M1 ∈ carrier_mat d d; adjoint M0 * P * M0 ≤⇩L adjoint M0 * M0; adjoint M1 * Q * M1 ≤⇩L adjoint M1 * M1⟧ ⟹ adjoint M0 * P * M0 + adjoint M1 * Q * M1 ≤⇩L adjoint M0 * M0 + adjoint M1 * M1›*)) (*goal: ‹adjoint M0 * P * M0 + adjoint M1 * Q * M1 ≤⇩L adjoint M0 * M0 + adjoint M1 * M1›*) using dM0 (*‹M0 ∈ carrier_mat d d›*) dP (*‹P ∈ carrier_mat d d›*) dM1 (*‹M1 ∈ carrier_mat d d›*) dQ (*‹(Q::complex mat) ∈ carrier_mat d d›*) le0 (*‹adjoint (M0::complex mat) * (P::complex mat) * M0 ≤⇩L adjoint M0 * M0›*) le1 (*‹adjoint M1 * Q * M1 ≤⇩L adjoint M1 * M1›*) apply - (*goals: 1. ‹⟦M0 ∈ carrier_mat d d; P ∈ carrier_mat d d; M1 ∈ carrier_mat d d; Q ∈ carrier_mat d d; adjoint M0 * P * M0 ≤⇩L adjoint M0 * M0; adjoint M1 * Q * M1 ≤⇩L adjoint M1 * M1⟧ ⟹ adjoint M0 * P * M0 ∈ carrier_mat d d› 2. ‹⟦M0 ∈ carrier_mat d d; P ∈ carrier_mat d d; M1 ∈ carrier_mat d d; Q ∈ carrier_mat d d; adjoint M0 * P * M0 ≤⇩L adjoint M0 * M0; adjoint M1 * Q * M1 ≤⇩L adjoint M1 * M1⟧ ⟹ adjoint M0 * M0 ∈ carrier_mat d d› 3. ‹⟦M0 ∈ carrier_mat d d; P ∈ carrier_mat d d; M1 ∈ carrier_mat d d; Q ∈ carrier_mat d d; adjoint M0 * P * M0 ≤⇩L adjoint M0 * M0; adjoint M1 * Q * M1 ≤⇩L adjoint M1 * M1⟧ ⟹ adjoint M1 * Q * M1 ∈ carrier_mat d d› 4. ‹⟦M0 ∈ carrier_mat d d; P ∈ carrier_mat d d; M1 ∈ carrier_mat d d; Q ∈ carrier_mat d d; adjoint M0 * P * M0 ≤⇩L adjoint M0 * M0; adjoint M1 * Q * M1 ≤⇩L adjoint M1 * M1⟧ ⟹ adjoint M1 * M1 ∈ carrier_mat d d› 5. ‹⟦M0 ∈ carrier_mat d d; P ∈ carrier_mat d d; M1 ∈ carrier_mat d d; Q ∈ carrier_mat d d; adjoint M0 * P * M0 ≤⇩L adjoint M0 * M0; adjoint M1 * Q * M1 ≤⇩L adjoint M1 * M1⟧ ⟹ adjoint M0 * P * M0 ≤⇩L adjoint M0 * M0› 6. ‹⟦M0 ∈ carrier_mat d d; P ∈ carrier_mat d d; M1 ∈ carrier_mat d d; Q ∈ carrier_mat d d; adjoint M0 * P * M0 ≤⇩L adjoint M0 * M0; adjoint M1 * Q * M1 ≤⇩L adjoint M1 * M1⟧ ⟹ adjoint M1 * Q * M1 ≤⇩L adjoint M1 * M1› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*proven 6 subgoals*) . also (*calculation: ‹adjoint M0 * P * M0 + adjoint M1 * Q * M1 ≤⇩L adjoint M0 * M0 + adjoint M1 * M1›*) have "… = 1⇩m d" using m (*‹measurement d 2 M›*) M0_def (*‹M0 = M 0›*) M1_def (*‹M1 = M 1›*) measurement_id2 (*‹measurement (?d::nat) (2::nat) (?M::nat ⇒ complex mat) ⟹ adjoint (?M (0::nat)) * ?M (0::nat) + adjoint (?M (1::nat)) * ?M (1::nat) = 1⇩m ?d›*) by auto finally (*calculation: ‹adjoint M0 * P * M0 + adjoint M1 * Q * M1 ≤⇩L 1⇩m d›*) show "adjoint M0 * P * M0 + adjoint M1 * Q * M1 ≤⇩L 1⇩m d" . qed lemma wlp_while_n_close: assumes close: "⋀P. is_quantum_predicate P ⟹ is_quantum_predicate (WS P)" and m: "measurement d 2 M" and qpP: "is_quantum_predicate P" shows "is_quantum_predicate (wlp_while_n (M 0) (M 1) WS k P)" proof (induct k) (*goals: 1. ‹is_quantum_predicate (wlp_while_n (M 0) (M 1) WS 0 P)› 2. ‹⋀k. is_quantum_predicate (wlp_while_n (M 0) (M 1) WS k P) ⟹ is_quantum_predicate (wlp_while_n (M 0) (M 1) WS (Suc k) P)›*) case 0 (*no hyothesis introduced yet*) then show "?case" (*goal: ‹is_quantum_predicate (wlp_while_n (M 0) (M 1) WS 0 P)›*) unfolding wlp_while_n.simps is_quantum_predicate_def (*goal: ‹1⇩m d ∈ carrier_mat d d ∧ positive (1⇩m d) ∧ 1⇩m d ≤⇩L 1⇩m d›*) using positive_one[of d] (*‹positive (1⇩m d)›*) lowner_le_refl[of "1⇩m d"] (*‹1⇩m d ∈ carrier_mat ?n ?n ⟹ 1⇩m d ≤⇩L 1⇩m d›*) by fastforce next (*goal: ‹⋀k::nat. is_quantum_predicate (wlp_while_n ((M::nat ⇒ complex mat) (0::nat)) (M (1::nat)) (WS::complex mat ⇒ complex mat) k (P::complex mat)) ⟹ is_quantum_predicate (wlp_while_n (M (0::nat)) (M (1::nat)) WS (Suc k) P)›*) case (Suc k) (*‹is_quantum_predicate (wlp_while_n (M 0) (M 1) WS k P)›*) define M0 where "M0 = M 0" define M1 where "M1 = M 1" define W where "W k = wlp_while_n M0 M1 WS k P" for k show "?case" (*goal: ‹is_quantum_predicate (wlp_while_n (M 0) (M 1) WS (Suc k) P)›*) unfolding wlp_while_n.simps is_quantum_predicate_def (*goal: ‹adjoint (M 0) * P * M 0 + adjoint (M 1) * WS (wlp_while_n (M 0) (M 1) WS k P) * M 1 ∈ carrier_mat d d ∧ positive (adjoint (M 0) * P * M 0 + adjoint (M 1) * WS (wlp_while_n (M 0) (M 1) WS k P) * M 1) ∧ adjoint (M 0) * P * M 0 + adjoint (M 1) * WS (wlp_while_n (M 0) (M 1) WS k P) * M 1 ≤⇩L 1⇩m d›*) proof (fold M0_def M1_def, fold W_def, auto) (*goals: 1. ‹adjoint M0 * P * M0 + adjoint M1 * WS (W k) * M1 ∈ carrier_mat d d› 2. ‹positive (adjoint M0 * P * M0 + adjoint M1 * WS (W k) * M1)› 3. ‹adjoint M0 * P * M0 + adjoint M1 * WS (W k) * M1 ≤⇩L 1⇩m d›*) have dM0: "M0 ∈ carrier_mat d d" and dM1: "M1 ∈ carrier_mat d d" using m (*‹measurement d 2 M›*) M0_def (*‹M0 = M 0›*) M1_def (*‹M1 = M 1›*) measurement_def (*‹measurement (?d::nat) (?n::nat) (?M::nat ⇒ complex mat) = ((∀j<?n. ?M j ∈ carrier_mat ?d ?d) ∧ matrix_sum ?d (λj::nat. adjoint (?M j) * ?M j) ?n = 1⇩m ?d)›*) apply - (*goals: 1. ‹⟦measurement d 2 M; M0 = M 0; M1 = M 1; ⋀d n M. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj. adjoint (M j) * M j) n = 1⇩m d)⟧ ⟹ M0 ∈ carrier_mat d d› 2. ‹⟦measurement d 2 M; M0 = M 0; M1 = M 1; ⋀d n M. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj. adjoint (M j) * M j) n = 1⇩m d)⟧ ⟹ M1 ∈ carrier_mat d d› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have dP: "P ∈ carrier_mat d d" using qpP (*‹is_quantum_predicate (P::complex mat)›*) is_quantum_predicate_def (*‹is_quantum_predicate (?P::complex mat) = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto have qpWk: "is_quantum_predicate (W k)" using Suc (*‹is_quantum_predicate (wlp_while_n (M 0) (M 1) WS k P)›*) M0_def (*‹M0 = M 0›*) M1_def (*‹(M1::complex mat) = (M::nat ⇒ complex mat) (1::nat)›*) W_def (*‹W ?k = wlp_while_n M0 M1 WS ?k P›*) by auto then have qpWWk: "is_quantum_predicate (WS (W k))" using close (*‹is_quantum_predicate ?P ⟹ is_quantum_predicate (WS ?P)›*) by auto from qpWk (*‹is_quantum_predicate (W k)›*) have dWk: "W k ∈ carrier_mat d d" using is_quantum_predicate_def (*‹is_quantum_predicate (?P::complex mat) = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto from qpWWk (*‹is_quantum_predicate ((WS::complex mat ⇒ complex mat) ((W::nat ⇒ complex mat) (k::nat)))›*) have dWWk: "WS (W k) ∈ carrier_mat d d" using is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto show "adjoint M0 * P * M0 + adjoint M1 * WS (W k) * M1 ∈ carrier_mat d d" using dM0 (*‹M0 ∈ carrier_mat d d›*) dP (*‹P ∈ carrier_mat d d›*) dM1 (*‹M1 ∈ carrier_mat d d›*) dWWk (*‹(WS::complex mat ⇒ complex mat) ((W::nat ⇒ complex mat) (k::nat)) ∈ carrier_mat d d›*) by auto have pP: "positive P" using qpP (*‹is_quantum_predicate (P::complex mat)›*) is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto then have pM0P: "positive (adjoint M0 * P * M0)" using positive_close_under_left_right_mult_adjoint[OF adjoint_dim [ OF dM0 ]] (*‹⟦?A ∈ carrier_mat d d; positive ?A⟧ ⟹ positive (adjoint M0 * ?A * adjoint (adjoint M0))›*) dM0 (*‹M0 ∈ carrier_mat d d›*) dP (*‹P ∈ carrier_mat d d›*) adjoint_adjoint[of M0] (*‹adjoint (adjoint M0) = M0›*) by auto have pWWk: "positive (WS (W k))" using qpWWk (*‹is_quantum_predicate (WS (W k))›*) is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto then have pM1WWk: "positive (adjoint M1 * WS (W k) * M1)" using positive_close_under_left_right_mult_adjoint[OF adjoint_dim [ OF dM1 ]] (*‹⟦?A ∈ carrier_mat d d; positive ?A⟧ ⟹ positive (adjoint M1 * ?A * adjoint (adjoint M1))›*) dM1 (*‹M1 ∈ carrier_mat d d›*) dWWk (*‹WS (W k) ∈ carrier_mat d d›*) adjoint_adjoint[of M1] (*‹adjoint (adjoint M1) = M1›*) by auto then show "positive (adjoint M0 * P * M0 + adjoint M1 * WS (W k) * M1)" using positive_add[OF pM0P pM1WWk] (*‹⟦adjoint M0 * P * M0 ∈ carrier_mat ?n ?n; adjoint M1 * WS (W k) * M1 ∈ carrier_mat ?n ?n⟧ ⟹ positive (adjoint M0 * P * M0 + adjoint M1 * WS (W k) * M1)›*) dM0 (*‹M0 ∈ carrier_mat d d›*) dP (*‹(P::complex mat) ∈ carrier_mat d d›*) dM1 (*‹M1 ∈ carrier_mat d d›*) dWWk (*‹(WS::complex mat ⇒ complex mat) ((W::nat ⇒ complex mat) (k::nat)) ∈ carrier_mat d d›*) by fastforce have leWWk: "WS (W k) ≤⇩L 1⇩m d" using qpWWk (*‹is_quantum_predicate (WS (W k))›*) is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto have leP: "P ≤⇩L 1⇩m d" using qpP (*‹is_quantum_predicate (P::complex mat)›*) is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto show "(adjoint M0 * P * M0 + adjoint M1 * WS (W k) * M1) ≤⇩L 1⇩m d " using measurement2_leq_one_mat[OF dP dWWk leP leWWk m] (*‹adjoint (M 0) * P * M 0 + adjoint (M 1) * WS (W k) * M 1 ≤⇩L 1⇩m d›*) M0_def (*‹M0 = M 0›*) M1_def (*‹M1 = M 1›*) by auto qed qed lemma wlp_while_n_mono: assumes "⋀P. is_quantum_predicate P ⟹ is_quantum_predicate (WS P)" and "⋀P Q. is_quantum_predicate P ⟹ is_quantum_predicate Q ⟹ P ≤⇩L Q ⟹ WS P ≤⇩L WS Q" and "measurement d 2 M" and "is_quantum_predicate P" and "is_quantum_predicate Q" and "P ≤⇩L Q" shows "(wlp_while_n (M 0) (M 1) WS k P) ≤⇩L (wlp_while_n (M 0) (M 1) WS k Q)" proof (induct k) (*goals: 1. ‹wlp_while_n (M 0) (M 1) WS 0 P ≤⇩L wlp_while_n (M 0) (M 1) WS 0 Q› 2. ‹⋀k. wlp_while_n (M 0) (M 1) WS k P ≤⇩L wlp_while_n (M 0) (M 1) WS k Q ⟹ wlp_while_n (M 0) (M 1) WS (Suc k) P ≤⇩L wlp_while_n (M 0) (M 1) WS (Suc k) Q›*) case 0 (*no hyothesis introduced yet*) then show "?case" (*goal: ‹wlp_while_n (M 0) (M 1) WS 0 P ≤⇩L wlp_while_n (M 0) (M 1) WS 0 Q›*) unfolding wlp_while_n.simps (*goal: ‹1⇩m d ≤⇩L 1⇩m d›*) using lowner_le_refl[of "1⇩m d"] (*‹1⇩m d ∈ carrier_mat (?n::nat) ?n ⟹ 1⇩m d ≤⇩L 1⇩m d›*) by fastforce next (*goal: ‹⋀k::nat. wlp_while_n ((M::nat ⇒ complex mat) (0::nat)) (M (1::nat)) (WS::complex mat ⇒ complex mat) k (P::complex mat) ≤⇩L wlp_while_n (M (0::nat)) (M (1::nat)) WS k (Q::complex mat) ⟹ wlp_while_n (M (0::nat)) (M (1::nat)) WS (Suc k) P ≤⇩L wlp_while_n (M (0::nat)) (M (1::nat)) WS (Suc k) Q›*) case (Suc k) (*‹wlp_while_n (M 0) (M 1) WS k P ≤⇩L wlp_while_n (M 0) (M 1) WS k Q›*) define M0 where "M0 = M 0" define M1 where "M1 = M 1" have dM0: "M0 ∈ carrier_mat d d" and dM1: "M1 ∈ carrier_mat d d" using assms (*‹is_quantum_predicate ?P ⟹ is_quantum_predicate (WS ?P)› ‹⟦is_quantum_predicate ?P; is_quantum_predicate ?Q; ?P ≤⇩L ?Q⟧ ⟹ WS ?P ≤⇩L WS ?Q› ‹measurement d 2 M› ‹is_quantum_predicate P› ‹is_quantum_predicate (Q::complex mat)› ‹P ≤⇩L Q›*) M0_def (*‹M0 = M 0›*) M1_def (*‹M1 = M 1›*) measurement_def (*‹measurement ?d ?n ?M = ((∀j<?n. ?M j ∈ carrier_mat ?d ?d) ∧ matrix_sum ?d (λj. adjoint (?M j) * ?M j) ?n = 1⇩m ?d)›*) apply - (*goals: 1. ‹⟦⋀P::complex mat. is_quantum_predicate P ⟹ is_quantum_predicate ((WS::complex mat ⇒ complex mat) P); ⋀(P::complex mat) Q::complex mat. ⟦is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ WS P ≤⇩L WS Q; measurement d (2::nat) (M::nat ⇒ complex mat); is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); P ≤⇩L Q; (M0::complex mat) = M (0::nat); (M1::complex mat) = M (1::nat); ⋀(d::nat) (n::nat) M::nat ⇒ complex mat. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj::nat. adjoint (M j) * M j) n = 1⇩m d)⟧ ⟹ M0 ∈ carrier_mat d d› 2. ‹⟦⋀P::complex mat. is_quantum_predicate P ⟹ is_quantum_predicate ((WS::complex mat ⇒ complex mat) P); ⋀(P::complex mat) Q::complex mat. ⟦is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ WS P ≤⇩L WS Q; measurement d (2::nat) (M::nat ⇒ complex mat); is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); P ≤⇩L Q; (M0::complex mat) = M (0::nat); (M1::complex mat) = M (1::nat); ⋀(d::nat) (n::nat) M::nat ⇒ complex mat. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj::nat. adjoint (M j) * M j) n = 1⇩m d)⟧ ⟹ M1 ∈ carrier_mat d d› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . define W where "W P k = wlp_while_n M0 M1 WS k P" for k and P have dP: "P ∈ carrier_mat d d" and dQ: "Q ∈ carrier_mat d d" using assms (*‹is_quantum_predicate (?P::complex mat) ⟹ is_quantum_predicate ((WS::complex mat ⇒ complex mat) ?P)› ‹⟦is_quantum_predicate ?P; is_quantum_predicate ?Q; ?P ≤⇩L ?Q⟧ ⟹ WS ?P ≤⇩L WS ?Q› ‹measurement d 2 M› ‹is_quantum_predicate P› ‹is_quantum_predicate Q› ‹P ≤⇩L Q›*) is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) apply - (*goals: 1. ‹⟦⋀P. is_quantum_predicate P ⟹ is_quantum_predicate (WS P); ⋀P Q. ⟦is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ WS P ≤⇩L WS Q; measurement d 2 M; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ P ∈ carrier_mat d d› 2. ‹⟦⋀P. is_quantum_predicate P ⟹ is_quantum_predicate (WS P); ⋀P Q. ⟦is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ WS P ≤⇩L WS Q; measurement d 2 M; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ Q ∈ carrier_mat d d› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have eq1: "W P (Suc k) = adjoint M0 * P * M0 + adjoint M1 * (WS (W P k)) * M1" unfolding W_def wlp_while_n.simps (*goal: ‹adjoint M0 * P * M0 + adjoint M1 * WS (wlp_while_n M0 M1 WS k P) * M1 = adjoint M0 * P * M0 + adjoint M1 * WS (wlp_while_n M0 M1 WS k P) * M1›*) by auto have eq2: "W Q (Suc k) = adjoint M0 * Q * M0 + adjoint M1 * (WS (W Q k)) * M1" unfolding W_def wlp_while_n.simps (*goal: ‹adjoint M0 * Q * M0 + adjoint M1 * WS (wlp_while_n M0 M1 WS k Q) * M1 = adjoint M0 * Q * M0 + adjoint M1 * WS (wlp_while_n M0 M1 WS k Q) * M1›*) by auto have le1: "adjoint M0 * P * M0 ≤⇩L adjoint M0 * Q * M0" using lowner_le_keep_under_measurement (*‹⟦?M ∈ carrier_mat ?n ?n; ?A ∈ carrier_mat ?n ?n; ?B ∈ carrier_mat ?n ?n; ?A ≤⇩L ?B⟧ ⟹ adjoint ?M * ?A * ?M ≤⇩L adjoint ?M * ?B * ?M›*) dM0 (*‹M0 ∈ carrier_mat d d›*) dP (*‹P ∈ carrier_mat d d›*) dQ (*‹Q ∈ carrier_mat d d›*) assms (*‹is_quantum_predicate ?P ⟹ is_quantum_predicate (WS ?P)› ‹⟦is_quantum_predicate ?P; is_quantum_predicate ?Q; ?P ≤⇩L ?Q⟧ ⟹ WS ?P ≤⇩L WS ?Q› ‹measurement d 2 M› ‹is_quantum_predicate P› ‹is_quantum_predicate Q› ‹P ≤⇩L Q›*) by auto have leWk: "(W P k) ≤⇩L (W Q k)" unfolding W_def M0_def M1_def (*goal: ‹wlp_while_n (M 0) (M 1) WS k P ≤⇩L wlp_while_n (M 0) (M 1) WS k Q›*) using Suc (*‹wlp_while_n (M 0) (M 1) WS k P ≤⇩L wlp_while_n (M 0) (M 1) WS k Q›*) by auto have qpWPk: "is_quantum_predicate (W P k)" unfolding W_def M0_def M1_def (*goal: ‹is_quantum_predicate (wlp_while_n (M 0) (M 1) WS k P)›*) using wlp_while_n_close (*‹⟦⋀P. is_quantum_predicate P ⟹ is_quantum_predicate (?WS P); measurement d 2 ?M; is_quantum_predicate ?P⟧ ⟹ is_quantum_predicate (wlp_while_n (?M 0) (?M 1) ?WS ?k ?P)›*) assms (*‹is_quantum_predicate ?P ⟹ is_quantum_predicate (WS ?P)› ‹⟦is_quantum_predicate ?P; is_quantum_predicate ?Q; ?P ≤⇩L ?Q⟧ ⟹ WS ?P ≤⇩L WS ?Q› ‹measurement d 2 M› ‹is_quantum_predicate (P::complex mat)› ‹is_quantum_predicate Q› ‹(P::complex mat) ≤⇩L (Q::complex mat)›*) by auto then have "is_quantum_predicate (WS (W P k))" unfolding W_def M0_def M1_def (*goal: ‹is_quantum_predicate (WS (wlp_while_n (M 0) (M 1) WS k P))›*) using assms (*‹is_quantum_predicate ?P ⟹ is_quantum_predicate (WS ?P)› ‹⟦is_quantum_predicate ?P; is_quantum_predicate ?Q; ?P ≤⇩L ?Q⟧ ⟹ WS ?P ≤⇩L WS ?Q› ‹measurement d (2::nat) (M::nat ⇒ complex mat)› ‹is_quantum_predicate P› ‹is_quantum_predicate Q› ‹P ≤⇩L Q›*) by auto then have dWWPk: "(WS (W P k)) ∈ carrier_mat d d" using is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto have qpWQk: "is_quantum_predicate (W Q k)" unfolding W_def M0_def M1_def (*goal: ‹is_quantum_predicate (wlp_while_n (M 0) (M 1) WS k Q)›*) using wlp_while_n_close (*‹⟦⋀P. is_quantum_predicate P ⟹ is_quantum_predicate (?WS P); measurement d 2 ?M; is_quantum_predicate ?P⟧ ⟹ is_quantum_predicate (wlp_while_n (?M 0) (?M 1) ?WS ?k ?P)›*) assms (*‹is_quantum_predicate (?P::complex mat) ⟹ is_quantum_predicate ((WS::complex mat ⇒ complex mat) ?P)› ‹⟦is_quantum_predicate (?P::complex mat); is_quantum_predicate (?Q::complex mat); ?P ≤⇩L ?Q⟧ ⟹ (WS::complex mat ⇒ complex mat) ?P ≤⇩L WS ?Q› ‹measurement d (2::nat) (M::nat ⇒ complex mat)› ‹is_quantum_predicate P› ‹is_quantum_predicate Q› ‹P ≤⇩L Q›*) by auto then have "is_quantum_predicate (WS (W Q k))" unfolding W_def M0_def M1_def (*goal: ‹is_quantum_predicate (WS (wlp_while_n (M 0) (M 1) WS k Q))›*) using assms (*‹is_quantum_predicate ?P ⟹ is_quantum_predicate (WS ?P)› ‹⟦is_quantum_predicate ?P; is_quantum_predicate ?Q; ?P ≤⇩L ?Q⟧ ⟹ WS ?P ≤⇩L WS ?Q› ‹measurement d 2 M› ‹is_quantum_predicate P› ‹is_quantum_predicate (Q::complex mat)› ‹(P::complex mat) ≤⇩L (Q::complex mat)›*) by auto then have dWWQk: "(WS (W Q k)) ∈ carrier_mat d d" using is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto have "(WS (W P k)) ≤⇩L (WS (W Q k))" using qpWPk (*‹is_quantum_predicate (W P k)›*) qpWQk (*‹is_quantum_predicate (W Q k)›*) leWk (*‹W P k ≤⇩L W Q k›*) assms (*‹is_quantum_predicate ?P ⟹ is_quantum_predicate (WS ?P)› ‹⟦is_quantum_predicate ?P; is_quantum_predicate ?Q; ?P ≤⇩L ?Q⟧ ⟹ WS ?P ≤⇩L WS ?Q› ‹measurement d 2 M› ‹is_quantum_predicate P› ‹is_quantum_predicate (Q::complex mat)› ‹P ≤⇩L Q›*) by auto then have le2: "adjoint M1 * (WS (W P k)) * M1 ≤⇩L adjoint M1 * (WS (W Q k)) * M1" using lowner_le_keep_under_measurement (*‹⟦?M ∈ carrier_mat ?n ?n; ?A ∈ carrier_mat ?n ?n; ?B ∈ carrier_mat ?n ?n; ?A ≤⇩L ?B⟧ ⟹ adjoint ?M * ?A * ?M ≤⇩L adjoint ?M * ?B * ?M›*) dM1 (*‹M1 ∈ carrier_mat d d›*) dWWPk (*‹WS (W P k) ∈ carrier_mat d d›*) dWWQk (*‹WS (W Q k) ∈ carrier_mat d d›*) by auto have "(adjoint M0 * P * M0 + adjoint M1 * (WS (W P k)) * M1) ≤⇩L (adjoint M0 * Q * M0 + adjoint M1 * (WS (W Q k)) * M1)" using lowner_le_add[OF _ _ _ _ le1 le2] (*‹⟦adjoint M0 * P * M0 ∈ carrier_mat ?n ?n; adjoint M0 * Q * M0 ∈ carrier_mat ?n ?n; adjoint M1 * WS (W P k) * M1 ∈ carrier_mat ?n ?n; adjoint M1 * WS (W Q k) * M1 ∈ carrier_mat ?n ?n⟧ ⟹ adjoint M0 * P * M0 + adjoint M1 * WS (W P k) * M1 ≤⇩L adjoint M0 * Q * M0 + adjoint M1 * WS (W Q k) * M1›*) dM0 (*‹M0 ∈ carrier_mat d d›*) dP (*‹P ∈ carrier_mat d d›*) dM1 (*‹M1 ∈ carrier_mat d d›*) dQ (*‹Q ∈ carrier_mat d d›*) dWWPk (*‹WS (W P k) ∈ carrier_mat d d›*) dWWQk (*‹(WS::complex mat ⇒ complex mat) ((W::complex mat ⇒ nat ⇒ complex mat) (Q::complex mat) (k::nat)) ∈ carrier_mat d d›*) le1 (*‹adjoint M0 * P * M0 ≤⇩L adjoint M0 * Q * M0›*) le2 (*‹adjoint M1 * WS (W P k) * M1 ≤⇩L adjoint M1 * WS (W Q k) * M1›*) by fastforce then have "W P (Suc k) ≤⇩L W Q (Suc k)" using eq1 (*‹W P (Suc k) = adjoint M0 * P * M0 + adjoint M1 * WS (W P k) * M1›*) eq2 (*‹(W::complex mat ⇒ nat ⇒ complex mat) (Q::complex mat) (Suc (k::nat)) = adjoint (M0::complex mat) * Q * M0 + adjoint (M1::complex mat) * (WS::complex mat ⇒ complex mat) (W Q k) * M1›*) by auto then show "?case" (*goal: ‹wlp_while_n (M 0) (M 1) WS (Suc k) P ≤⇩L wlp_while_n (M 0) (M 1) WS (Suc k) Q›*) unfolding W_def M0_def M1_def (*goal: ‹wlp_while_n (M 0) (M 1) WS (Suc k) P ≤⇩L wlp_while_n (M 0) (M 1) WS (Suc k) Q›*) by auto qed definition wlp_while :: "complex mat ⇒ complex mat ⇒ (complex mat ⇒ complex mat) ⇒ complex mat ⇒ complex mat" where "wlp_while M0 M1 WS P = (THE Q. limit_mat (λn. wlp_while_n M0 M1 WS n P) Q d)" lemma wlp_while_exists: assumes "⋀P. is_quantum_predicate P ⟹ is_quantum_predicate (WS P)" and "⋀P Q. is_quantum_predicate P ⟹ is_quantum_predicate Q ⟹ P ≤⇩L Q ⟹ WS P ≤⇩L WS Q" and m: "measurement d 2 M" and qpP: "is_quantum_predicate P" shows "is_quantum_predicate (wlp_while (M 0) (M 1) WS P) ∧ (∀n. (wlp_while (M 0) (M 1) WS P) ≤⇩L (wlp_while_n (M 0) (M 1) WS n P)) ∧ (∀W'. (∀n. W' ≤⇩L (wlp_while_n (M 0) (M 1) WS n P)) ⟶ W' ≤⇩L (wlp_while (M 0) (M 1) WS P)) ∧ limit_mat (λn. wlp_while_n (M 0) (M 1) WS n P) (wlp_while (M 0) (M 1) WS P) d" sorry lemma wlp_while_mono: assumes "⋀P. is_quantum_predicate P ⟹ is_quantum_predicate (WS P)" and "⋀P Q. is_quantum_predicate P ⟹ is_quantum_predicate Q ⟹ P ≤⇩L Q ⟹ WS P ≤⇩L WS Q" and "measurement d 2 M" and "is_quantum_predicate P" and "is_quantum_predicate Q" and "P ≤⇩L Q" shows "wlp_while (M 0) (M 1) WS P ≤⇩L wlp_while (M 0) (M 1) WS Q" sorry fun wlp :: "com ⇒ complex mat ⇒ complex mat" where "wlp SKIP P = P" | "wlp (Utrans U) P = adjoint U * P * U" | "wlp (Seq S1 S2) P = wlp S1 (wlp S2 P)" | "wlp (Measure n M S) P = wlp_measure n M (map wlp S) P" | "wlp (While M S) P = wlp_while (M 0) (M 1) (wlp S) P" lemma wlp_measure_expand_m: assumes m: "m ≤ n" and wc: "well_com (Measure n M S)" shows "wlp (Measure m M S) P = matrix_sum d (λk. adjoint (M k) * (wlp (S!k) P) * (M k)) m" unfolding wlp.simps wlp_measure_def (*goal: ‹matrix_sum d (λk. adjoint (M k) * (map wlp S ! k) P * M k) m = matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) m›*) proof (-) (*goal: ‹matrix_sum d (λk. adjoint (M k) * (map wlp S ! k) P * M k) m = matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) m›*) have "k < m ⟹ map wlp S ! k = wlp (S!k)" for k using wc (*‹well_com (Measure (n::nat) (M::nat ⇒ complex mat) (S::com list))›*) m (*‹m ≤ n›*) by auto then have "k < m ⟹ (map wlp S ! k) P = wlp (S!k) P" for k by auto then show "matrix_sum d (λk. adjoint (M k) * ((map wlp S ! k) P) * (M k)) m = matrix_sum d (λk. adjoint (M k) * (wlp (S!k) P) * (M k)) m" using matrix_sum_cong[of m "λk. adjoint (M k) * ((map wlp S ! k) P) * (M k)" "λk. adjoint (M k) * (wlp (S!k) P) * (M k)"] (*‹(⋀k. k < m ⟹ adjoint (M k) * (map wlp S ! k) P * M k = adjoint (M k) * wlp (S ! k) P * M k) ⟹ matrix_sum ?d (λk. adjoint (M k) * (map wlp S ! k) P * M k) m = matrix_sum ?d (λk. adjoint (M k) * wlp (S ! k) P * M k) m›*) by auto qed lemma wlp_measure_expand: assumes wc: "well_com (Measure n M S)" shows "wlp (Measure n M S) P = matrix_sum d (λk. adjoint (M k) * (wlp (S!k) P) * (M k)) n" using wlp_measure_expand_m[OF Nat.le_refl [ of n ]] (*‹well_com (Measure n ?M ?S) ⟹ wlp (Measure n ?M ?S) ?P = matrix_sum d (λk. adjoint (?M k) * wlp (?S ! k) ?P * ?M k) n›*) wc (*‹well_com (Measure n M S)›*) by auto lemma wlp_mono_and_close: shows "well_com S ⟹ is_quantum_predicate P ⟹ is_quantum_predicate Q ⟹ P ≤⇩L Q ⟹ is_quantum_predicate (wlp S P) ∧ wlp S P ≤⇩L wlp S Q" proof (induct S arbitrary: P Q) (*goals: 1. ‹⋀P Q. ⟦well_com SKIP; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp SKIP P) ∧ wlp SKIP P ≤⇩L wlp SKIP Q› 2. ‹⋀x P Q. ⟦well_com (Utrans x); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp (Utrans x) P) ∧ wlp (Utrans x) P ≤⇩L wlp (Utrans x) Q› 3. ‹⋀S1 S2 P Q. ⟦⋀P Q. ⟦well_com S1; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S1 P) ∧ wlp S1 P ≤⇩L wlp S1 Q; ⋀P Q. ⟦well_com S2; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S2 P) ∧ wlp S2 P ≤⇩L wlp S2 Q; well_com (S1;; S2); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp (S1;; S2) P) ∧ wlp (S1;; S2) P ≤⇩L wlp (S1;; S2) Q› 4. ‹⋀x1 x2a x3 P Q. ⟦⋀x3a P Q. ⟦x3a ∈ set x3; well_com x3a; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp x3a P) ∧ wlp x3a P ≤⇩L wlp x3a Q; well_com (Measure x1 x2a x3); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp (Measure x1 x2a x3) P) ∧ wlp (Measure x1 x2a x3) P ≤⇩L wlp (Measure x1 x2a x3) Q› 5. ‹⋀x1 S P Q. ⟦⋀P Q. ⟦well_com S; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S P) ∧ wlp S P ≤⇩L wlp S Q; well_com (While x1 S); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp (While x1 S) P) ∧ wlp (While x1 S) P ≤⇩L wlp (While x1 S) Q›*) case SKIP (*‹well_com SKIP› ‹is_quantum_predicate P› ‹is_quantum_predicate (Q::complex mat)› ‹P ≤⇩L Q›*) then show "?case" (*goal: ‹is_quantum_predicate (wlp SKIP P) ∧ wlp SKIP P ≤⇩L wlp SKIP Q›*) by auto next (*goals: 1. ‹⋀x P Q. ⟦well_com (Utrans x); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp (Utrans x) P) ∧ wlp (Utrans x) P ≤⇩L wlp (Utrans x) Q› 2. ‹⋀S1 S2 P Q. ⟦⋀P Q. ⟦well_com S1; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S1 P) ∧ wlp S1 P ≤⇩L wlp S1 Q; ⋀P Q. ⟦well_com S2; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S2 P) ∧ wlp S2 P ≤⇩L wlp S2 Q; well_com (S1;; S2); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp (S1;; S2) P) ∧ wlp (S1;; S2) P ≤⇩L wlp (S1;; S2) Q› 3. ‹⋀x1 x2a x3 P Q. ⟦⋀x3a P Q. ⟦x3a ∈ set x3; well_com x3a; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp x3a P) ∧ wlp x3a P ≤⇩L wlp x3a Q; well_com (Measure x1 x2a x3); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp (Measure x1 x2a x3) P) ∧ wlp (Measure x1 x2a x3) P ≤⇩L wlp (Measure x1 x2a x3) Q› 4. ‹⋀x1 S P Q. ⟦⋀P Q. ⟦well_com S; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S P) ∧ wlp S P ≤⇩L wlp S Q; well_com (While x1 S); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp (While x1 S) P) ∧ wlp (While x1 S) P ≤⇩L wlp (While x1 S) Q›*) case (Utrans U) (*‹well_com (Utrans U)› ‹is_quantum_predicate (P::complex mat)› ‹is_quantum_predicate (Q::complex mat)› ‹(P::complex mat) ≤⇩L (Q::complex mat)›*) then have dU: "U ∈ carrier_mat d d" and u: "unitary U" and qp: "is_quantum_predicate P" and le: "P ≤⇩L Q" and dP: "P ∈ carrier_mat d d" and dQ: "Q ∈ carrier_mat d d" using is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) apply - (*goals: 1. ‹⟦well_com (Utrans (U::complex mat)); is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); P ≤⇩L Q; ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ U ∈ carrier_mat d d› 2. ‹⟦well_com (Utrans (U::complex mat)); is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); P ≤⇩L Q; ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ unitary U› 3. ‹⟦well_com (Utrans (U::complex mat)); is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); P ≤⇩L Q; ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ is_quantum_predicate P› 4. ‹⟦well_com (Utrans (U::complex mat)); is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); P ≤⇩L Q; ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ P ≤⇩L Q› 5. ‹⟦well_com (Utrans (U::complex mat)); is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); P ≤⇩L Q; ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ P ∈ carrier_mat d d› 6. ‹⟦well_com (Utrans (U::complex mat)); is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); P ≤⇩L Q; ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ Q ∈ carrier_mat d d› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*proven 6 subgoals*) . then have qp': "is_quantum_predicate (wlp (Utrans U) P)" using qp_close_under_unitary_operator (*‹⟦?U ∈ carrier_mat d d; unitary ?U; is_quantum_predicate ?P⟧ ⟹ is_quantum_predicate (adjoint ?U * ?P * ?U)›*) by auto moreover have "adjoint U * P * U ≤⇩L adjoint U * Q * U" using lowner_le_keep_under_measurement[OF dU dP dQ le] (*‹adjoint U * P * U ≤⇩L adjoint U * Q * U›*) by auto ultimately show "?case" (*goal: ‹is_quantum_predicate (wlp (Utrans U) P) ∧ wlp (Utrans U) P ≤⇩L wlp (Utrans U) Q›*) by auto next (*goals: 1. ‹⋀S1 S2 P Q. ⟦⋀P Q. ⟦well_com S1; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S1 P) ∧ wlp S1 P ≤⇩L wlp S1 Q; ⋀P Q. ⟦well_com S2; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S2 P) ∧ wlp S2 P ≤⇩L wlp S2 Q; well_com (S1;; S2); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp (S1;; S2) P) ∧ wlp (S1;; S2) P ≤⇩L wlp (S1;; S2) Q› 2. ‹⋀x1 x2a x3 P Q. ⟦⋀x3a P Q. ⟦x3a ∈ set x3; well_com x3a; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp x3a P) ∧ wlp x3a P ≤⇩L wlp x3a Q; well_com (Measure x1 x2a x3); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp (Measure x1 x2a x3) P) ∧ wlp (Measure x1 x2a x3) P ≤⇩L wlp (Measure x1 x2a x3) Q› 3. ‹⋀x1 S P Q. ⟦⋀P Q. ⟦well_com S; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S P) ∧ wlp S P ≤⇩L wlp S Q; well_com (While x1 S); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp (While x1 S) P) ∧ wlp (While x1 S) P ≤⇩L wlp (While x1 S) Q›*) case (Seq S1 S2) (*‹⟦well_com S1; is_quantum_predicate ?P; is_quantum_predicate ?Q; ?P ≤⇩L ?Q⟧ ⟹ is_quantum_predicate (wlp S1 ?P) ∧ wlp S1 ?P ≤⇩L wlp S1 ?Q› ‹⟦well_com S2; is_quantum_predicate ?P; is_quantum_predicate ?Q; ?P ≤⇩L ?Q⟧ ⟹ is_quantum_predicate (wlp S2 ?P) ∧ wlp S2 ?P ≤⇩L wlp S2 ?Q› ‹well_com (S1;; S2)› ‹is_quantum_predicate (P::complex mat)› ‹is_quantum_predicate Q› ‹(P::complex mat) ≤⇩L (Q::complex mat)›*) then have qpP: "is_quantum_predicate P" and qpQ: "is_quantum_predicate Q" and wc1: "well_com S1" and wc2: "well_com S2" and dP: "P ∈ carrier_mat d d" and dQ: "Q ∈ carrier_mat d d" and le: "P ≤⇩L Q" using is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) apply - (*goals: 1. ‹⟦⋀P Q. ⟦well_com S1; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S1 P) ∧ wlp S1 P ≤⇩L wlp S1 Q; ⋀P Q. ⟦well_com S2; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S2 P) ∧ wlp S2 P ≤⇩L wlp S2 Q; well_com (S1;; S2); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ is_quantum_predicate P› 2. ‹⟦⋀P Q. ⟦well_com S1; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S1 P) ∧ wlp S1 P ≤⇩L wlp S1 Q; ⋀P Q. ⟦well_com S2; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S2 P) ∧ wlp S2 P ≤⇩L wlp S2 Q; well_com (S1;; S2); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ is_quantum_predicate Q› 3. ‹⟦⋀P Q. ⟦well_com S1; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S1 P) ∧ wlp S1 P ≤⇩L wlp S1 Q; ⋀P Q. ⟦well_com S2; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S2 P) ∧ wlp S2 P ≤⇩L wlp S2 Q; well_com (S1;; S2); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ well_com S1› 4. ‹⟦⋀P Q. ⟦well_com S1; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S1 P) ∧ wlp S1 P ≤⇩L wlp S1 Q; ⋀P Q. ⟦well_com S2; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S2 P) ∧ wlp S2 P ≤⇩L wlp S2 Q; well_com (S1;; S2); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ well_com S2› 5. ‹⟦⋀P Q. ⟦well_com S1; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S1 P) ∧ wlp S1 P ≤⇩L wlp S1 Q; ⋀P Q. ⟦well_com S2; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S2 P) ∧ wlp S2 P ≤⇩L wlp S2 Q; well_com (S1;; S2); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ P ∈ carrier_mat d d› 6. ‹⟦⋀P Q. ⟦well_com S1; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S1 P) ∧ wlp S1 P ≤⇩L wlp S1 Q; ⋀P Q. ⟦well_com S2; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S2 P) ∧ wlp S2 P ≤⇩L wlp S2 Q; well_com (S1;; S2); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ Q ∈ carrier_mat d d› 7. ‹⟦⋀P Q. ⟦well_com S1; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S1 P) ∧ wlp S1 P ≤⇩L wlp S1 Q; ⋀P Q. ⟦well_com S2; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S2 P) ∧ wlp S2 P ≤⇩L wlp S2 Q; well_com (S1;; S2); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ P ≤⇩L Q› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*proven 7 subgoals*) . have qpP2: "is_quantum_predicate (wlp S2 P)" using Seq (*‹⟦well_com S1; is_quantum_predicate ?P; is_quantum_predicate ?Q; ?P ≤⇩L ?Q⟧ ⟹ is_quantum_predicate (wlp S1 ?P) ∧ wlp S1 ?P ≤⇩L wlp S1 ?Q› ‹⟦well_com S2; is_quantum_predicate ?P; is_quantum_predicate ?Q; ?P ≤⇩L ?Q⟧ ⟹ is_quantum_predicate (wlp S2 ?P) ∧ wlp S2 ?P ≤⇩L wlp S2 ?Q› ‹well_com (S1;; S2)› ‹is_quantum_predicate P› ‹is_quantum_predicate Q› ‹P ≤⇩L Q›*) qpP (*‹is_quantum_predicate P›*) wc2 (*‹well_com S2›*) by auto have qpQ2: "is_quantum_predicate (wlp S2 Q)" using Seq(2)[OF wc2 qpQ qpQ] (*‹Q ≤⇩L Q ⟹ is_quantum_predicate (wlp S2 Q) ∧ wlp S2 Q ≤⇩L wlp S2 Q›*) lowner_le_refl (*‹?A ∈ carrier_mat ?n ?n ⟹ ?A ≤⇩L ?A›*) dQ (*‹(Q::complex mat) ∈ carrier_mat d d›*) by blast have qpP1: "is_quantum_predicate (wlp S1 (wlp S2 P))" using Seq(1)[OF wc1 qpP2 qpP2] (*‹wlp (S2::com) (P::complex mat) ≤⇩L wlp S2 P ⟹ is_quantum_predicate (wlp (S1::com) (wlp S2 P)) ∧ wlp S1 (wlp S2 P) ≤⇩L wlp S1 (wlp S2 P)›*) qpP2 (*‹is_quantum_predicate (wlp S2 P)›*) is_quantum_predicate_def[of "wlp S2 P"] (*‹is_quantum_predicate (wlp S2 P) = (wlp S2 P ∈ carrier_mat d d ∧ positive (wlp S2 P) ∧ wlp S2 P ≤⇩L 1⇩m d)›*) lowner_le_refl (*‹(?A::complex mat) ∈ carrier_mat (?n::nat) ?n ⟹ ?A ≤⇩L ?A›*) by auto have "wlp S2 P ≤⇩L wlp S2 Q" using Seq(2) (*‹⟦well_com S2; is_quantum_predicate ?P; is_quantum_predicate ?Q; ?P ≤⇩L ?Q⟧ ⟹ is_quantum_predicate (wlp S2 ?P) ∧ wlp S2 ?P ≤⇩L wlp S2 ?Q›*) wc2 (*‹well_com S2›*) qpP (*‹is_quantum_predicate P›*) qpQ (*‹is_quantum_predicate (Q::complex mat)›*) le (*‹P ≤⇩L Q›*) by auto then have "wlp S1 (wlp S2 P) ≤⇩L wlp S1 (wlp S2 Q)" using Seq(1) (*‹⟦well_com S1; is_quantum_predicate ?P; is_quantum_predicate ?Q; ?P ≤⇩L ?Q⟧ ⟹ is_quantum_predicate (wlp S1 ?P) ∧ wlp S1 ?P ≤⇩L wlp S1 ?Q›*) wc1 (*‹well_com (S1::com)›*) qpP2 (*‹is_quantum_predicate (wlp S2 P)›*) qpQ2 (*‹is_quantum_predicate (wlp S2 Q)›*) by auto then show "?case" (*goal: ‹is_quantum_predicate (wlp (S1;; S2) P) ∧ wlp (S1;; S2) P ≤⇩L wlp (S1;; S2) Q›*) using qpP1 (*‹is_quantum_predicate (wlp S1 (wlp S2 P))›*) by auto next (*goals: 1. ‹⋀x1 x2a x3 P Q. ⟦⋀x3a P Q. ⟦x3a ∈ set x3; well_com x3a; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp x3a P) ∧ wlp x3a P ≤⇩L wlp x3a Q; well_com (Measure x1 x2a x3); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp (Measure x1 x2a x3) P) ∧ wlp (Measure x1 x2a x3) P ≤⇩L wlp (Measure x1 x2a x3) Q› 2. ‹⋀x1 S P Q. ⟦⋀P Q. ⟦well_com S; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S P) ∧ wlp S P ≤⇩L wlp S Q; well_com (While x1 S); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp (While x1 S) P) ∧ wlp (While x1 S) P ≤⇩L wlp (While x1 S) Q›*) case (Measure n M S) (*‹⟦?x3a ∈ set S; well_com ?x3a; is_quantum_predicate ?P; is_quantum_predicate ?Q; ?P ≤⇩L ?Q⟧ ⟹ is_quantum_predicate (wlp ?x3a ?P) ∧ wlp ?x3a ?P ≤⇩L wlp ?x3a ?Q› ‹well_com (Measure n M S)› ‹is_quantum_predicate P› ‹is_quantum_predicate Q› ‹(P::complex mat) ≤⇩L (Q::complex mat)›*) then have wc: "well_com (Measure n M S)" and wck: "k < n ⟹ well_com (S!k)" and l: "length S = n" and m: "measurement d n M" and le: "P ≤⇩L Q" and qpP: "is_quantum_predicate P" and dP: "P ∈ carrier_mat d d" and qpQ: "is_quantum_predicate Q" and dQ: "Q ∈ carrier_mat d d" for k using measure_well_com (*‹⟦well_com (Measure (?n::nat) (?M::nat ⇒ complex mat) (?S::com list)); (?k::nat) < ?n⟧ ⟹ well_com (?S ! ?k)›*) is_quantum_predicate_def (*‹is_quantum_predicate (?P::complex mat) = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) apply - (*goals: 1. ‹⟦⋀(x3a::com) (P::complex mat) Q::complex mat. ⟦x3a ∈ set (S::com list); well_com x3a; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp x3a P) ∧ wlp x3a P ≤⇩L wlp x3a Q; well_com (Measure (n::nat) (M::nat ⇒ complex mat) S); is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); P ≤⇩L Q; ⋀(n::nat) (M::nat ⇒ complex mat) (S::com list) k::nat. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ well_com (Measure n M S)› 2. ‹⟦(k::nat) < (n::nat); ⋀(x3a::com) (P::complex mat) Q::complex mat. ⟦x3a ∈ set (S::com list); well_com x3a; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp x3a P) ∧ wlp x3a P ≤⇩L wlp x3a Q; well_com (Measure n (M::nat ⇒ complex mat) S); is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); P ≤⇩L Q; ⋀(n::nat) (M::nat ⇒ complex mat) (S::com list) k::nat. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ well_com (S ! k)› 3. ‹⟦⋀(x3a::com) (P::complex mat) Q::complex mat. ⟦x3a ∈ set (S::com list); well_com x3a; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp x3a P) ∧ wlp x3a P ≤⇩L wlp x3a Q; well_com (Measure (n::nat) (M::nat ⇒ complex mat) S); is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); P ≤⇩L Q; ⋀(n::nat) (M::nat ⇒ complex mat) (S::com list) k::nat. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ length S = n› 4. ‹⟦⋀(x3a::com) (P::complex mat) Q::complex mat. ⟦x3a ∈ set (S::com list); well_com x3a; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp x3a P) ∧ wlp x3a P ≤⇩L wlp x3a Q; well_com (Measure (n::nat) (M::nat ⇒ complex mat) S); is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); P ≤⇩L Q; ⋀(n::nat) (M::nat ⇒ complex mat) (S::com list) k::nat. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ measurement d n M› 5. ‹⟦⋀(x3a::com) (P::complex mat) Q::complex mat. ⟦x3a ∈ set (S::com list); well_com x3a; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp x3a P) ∧ wlp x3a P ≤⇩L wlp x3a Q; well_com (Measure (n::nat) (M::nat ⇒ complex mat) S); is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); P ≤⇩L Q; ⋀(n::nat) (M::nat ⇒ complex mat) (S::com list) k::nat. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ P ≤⇩L Q› 6. ‹⟦⋀(x3a::com) (P::complex mat) Q::complex mat. ⟦x3a ∈ set (S::com list); well_com x3a; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp x3a P) ∧ wlp x3a P ≤⇩L wlp x3a Q; well_com (Measure (n::nat) (M::nat ⇒ complex mat) S); is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); P ≤⇩L Q; ⋀(n::nat) (M::nat ⇒ complex mat) (S::com list) k::nat. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ is_quantum_predicate P› 7. ‹⟦⋀(x3a::com) (P::complex mat) Q::complex mat. ⟦x3a ∈ set (S::com list); well_com x3a; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp x3a P) ∧ wlp x3a P ≤⇩L wlp x3a Q; well_com (Measure (n::nat) (M::nat ⇒ complex mat) S); is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); P ≤⇩L Q; ⋀(n::nat) (M::nat ⇒ complex mat) (S::com list) k::nat. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ P ∈ carrier_mat d d› 8. ‹⟦⋀(x3a::com) (P::complex mat) Q::complex mat. ⟦x3a ∈ set (S::com list); well_com x3a; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp x3a P) ∧ wlp x3a P ≤⇩L wlp x3a Q; well_com (Measure (n::nat) (M::nat ⇒ complex mat) S); is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); P ≤⇩L Q; ⋀(n::nat) (M::nat ⇒ complex mat) (S::com list) k::nat. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ is_quantum_predicate Q› 9. ‹⟦⋀(x3a::com) (P::complex mat) Q::complex mat. ⟦x3a ∈ set (S::com list); well_com x3a; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp x3a P) ∧ wlp x3a P ≤⇩L wlp x3a Q; well_com (Measure (n::nat) (M::nat ⇒ complex mat) S); is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); P ≤⇩L Q; ⋀(n::nat) (M::nat ⇒ complex mat) (S::com list) k::nat. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ Q ∈ carrier_mat d d› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*discuss goal 9*) apply ((auto)[1]) (*proven 9 subgoals*) . have dMk: "k < n ⟹ M k ∈ carrier_mat d d" for k using m (*‹measurement d n M›*) measurement_def (*‹measurement (?d::nat) (?n::nat) (?M::nat ⇒ complex mat) = ((∀j<?n. ?M j ∈ carrier_mat ?d ?d) ∧ matrix_sum ?d (λj::nat. adjoint (?M j) * ?M j) ?n = 1⇩m ?d)›*) by auto have set: "k < n ⟹ S!k ∈ set S" for k using l (*‹length S = n›*) by auto have qpk: "k < n ⟹ is_quantum_predicate (wlp (S!k) P)" for k using Measure(1)[OF set wck qpP qpP] (*‹⟦?k1 < n; ?k1 < n; P ≤⇩L P⟧ ⟹ is_quantum_predicate (wlp (S ! ?k1) P) ∧ wlp (S ! ?k1) P ≤⇩L wlp (S ! ?k1) P›*) lowner_le_refl[of P] (*‹P ∈ carrier_mat ?n ?n ⟹ P ≤⇩L P›*) dP (*‹P ∈ carrier_mat d d›*) by auto then have dWkP: "k < n ⟹ wlp (S!k) P ∈ carrier_mat d d" for k using is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto then have dMkP: "k < n ⟹ adjoint (M k) * (wlp (S!k) P) * (M k) ∈ carrier_mat d d" for k using dMk (*‹?k < n ⟹ M ?k ∈ carrier_mat d d›*) by fastforce have "k < n ⟹ is_quantum_predicate (wlp (S!k) Q)" for k using Measure(1)[OF set wck qpQ qpQ] (*‹⟦?k1 < n; ?k1 < n; Q ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp (S ! ?k1) Q) ∧ wlp (S ! ?k1) Q ≤⇩L wlp (S ! ?k1) Q›*) lowner_le_refl[of Q] (*‹Q ∈ carrier_mat ?n ?n ⟹ Q ≤⇩L Q›*) dQ (*‹(Q::complex mat) ∈ carrier_mat d d›*) by auto then have dWkQ: "k < n ⟹ wlp (S!k) Q ∈ carrier_mat d d" for k using is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto then have dMkQ: "k < n ⟹ adjoint (M k) * (wlp (S!k) Q) * (M k) ∈ carrier_mat d d" for k using dMk (*‹?k < n ⟹ M ?k ∈ carrier_mat d d›*) by fastforce have "k < n ⟹ wlp (S!k) P ≤⇩L wlp (S!k) Q" for k using Measure(1)[OF set wck qpP qpQ le] (*‹⟦?k1 < n; ?k1 < n⟧ ⟹ is_quantum_predicate (wlp (S ! ?k1) P) ∧ wlp (S ! ?k1) P ≤⇩L wlp (S ! ?k1) Q›*) by auto then have "k < n ⟹ adjoint (M k) * (wlp (S!k) P) * (M k) ≤⇩L adjoint (M k) * (wlp (S!k) Q) * (M k)" for k using lowner_le_keep_under_measurement[OF dMk dWkP dWkQ] (*‹⟦(?k3::nat) < (n::nat); (?k2::nat) < n; (?k1::nat) < n; wlp ((S::com list) ! ?k2) (P::complex mat) ≤⇩L wlp (S ! ?k1) (Q::complex mat)⟧ ⟹ adjoint ((M::nat ⇒ complex mat) ?k3) * wlp (S ! ?k2) P * M ?k3 ≤⇩L adjoint (M ?k3) * wlp (S ! ?k1) Q * M ?k3›*) by auto then have le': "wlp (Measure n M S) P ≤⇩L wlp (Measure n M S) Q" unfolding wlp_measure_expand[OF wc] (*goal: ‹matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) n ≤⇩L matrix_sum d (λk. adjoint (M k) * wlp (S ! k) Q * M k) n›*) using lowner_le_matrix_sum (*‹⟦⋀k. k < ?n ⟹ ?f k ∈ carrier_mat ?d ?d; ⋀k. k < ?n ⟹ ?g k ∈ carrier_mat ?d ?d; ⋀k. k < ?n ⟹ ?f k ≤⇩L ?g k⟧ ⟹ matrix_sum ?d ?f ?n ≤⇩L matrix_sum ?d ?g ?n›*) dMkP (*‹?k < n ⟹ adjoint (M ?k) * wlp (S ! ?k) P * M ?k ∈ carrier_mat d d›*) dMkQ (*‹?k < n ⟹ adjoint (M ?k) * wlp (S ! ?k) Q * M ?k ∈ carrier_mat d d›*) by auto have qp': "is_quantum_predicate (wlp (Measure n M S) P)" unfolding wlp_measure_expand[OF wc] (*goal: ‹is_quantum_predicate (matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) n)›*) using qps_after_measure_is_qp[OF m] (*‹(⋀k::nat. k < (n::nat) ⟹ is_quantum_predicate ((?P::nat ⇒ complex mat) k)) ⟹ is_quantum_predicate (matrix_sum d (λk::nat. adjoint ((M::nat ⇒ complex mat) k) * ?P k * M k) n)›*) qpk (*‹?k < n ⟹ is_quantum_predicate (wlp (S ! ?k) P)›*) by auto show "?case" (*goal: ‹is_quantum_predicate (wlp (Measure (n::nat) (M::nat ⇒ complex mat) (S::com list)) (P::complex mat)) ∧ wlp (Measure n M S) P ≤⇩L wlp (Measure n M S) (Q::complex mat)›*) using le' (*‹wlp (Measure n M S) P ≤⇩L wlp (Measure n M S) Q›*) qp' (*‹is_quantum_predicate (wlp (Measure n M S) P)›*) by auto next (*goal: ‹⋀(x1::nat ⇒ complex mat) (S::com) (P::complex mat) Q::complex mat. ⟦⋀(P::complex mat) Q::complex mat. ⟦well_com S; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S P) ∧ wlp S P ≤⇩L wlp S Q; well_com (While x1 S); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp (While x1 S) P) ∧ wlp (While x1 S) P ≤⇩L wlp (While x1 S) Q›*) case (While M S) (*‹⟦well_com S; is_quantum_predicate ?P; is_quantum_predicate ?Q; ?P ≤⇩L ?Q⟧ ⟹ is_quantum_predicate (wlp S ?P) ∧ wlp S ?P ≤⇩L wlp S ?Q› ‹well_com (While M S)› ‹is_quantum_predicate P› ‹is_quantum_predicate Q› ‹P ≤⇩L Q›*) then have m: "measurement d 2 M" and wcs: "well_com S" and qpP: "is_quantum_predicate P" apply - (*goals: 1. ‹⟦⋀P Q. ⟦well_com S; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S P) ∧ wlp S P ≤⇩L wlp S Q; well_com (While M S); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ measurement d 2 M› 2. ‹⟦⋀P Q. ⟦well_com S; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S P) ∧ wlp S P ≤⇩L wlp S Q; well_com (While M S); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ well_com S› 3. ‹⟦⋀P Q. ⟦well_com S; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate (wlp S P) ∧ wlp S P ≤⇩L wlp S Q; well_com (While M S); is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ is_quantum_predicate P› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . have closeWS: "is_quantum_predicate P ⟹ is_quantum_predicate (wlp S P)" for P proof (-) (*goal: ‹is_quantum_predicate P ⟹ is_quantum_predicate (wlp S P)›*) assume asm: "is_quantum_predicate P" (*‹is_quantum_predicate (P::complex mat)›*) then have dP: "P ∈ carrier_mat d d" using is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto then show "is_quantum_predicate (wlp S P)" using While(1)[OF wcs asm asm lowner_le_refl] (*‹P ∈ carrier_mat ?n1 ?n1 ⟹ is_quantum_predicate (wlp S P) ∧ wlp S P ≤⇩L wlp S P›*) dP (*‹(P::complex mat) ∈ carrier_mat d d›*) by auto qed have monoWS: "is_quantum_predicate P ⟹ is_quantum_predicate Q ⟹ P ≤⇩L Q ⟹ wlp S P ≤⇩L wlp S Q" for P and Q using While(1)[OF wcs] (*‹⟦is_quantum_predicate (?P::complex mat); is_quantum_predicate (?Q::complex mat); ?P ≤⇩L ?Q⟧ ⟹ is_quantum_predicate (wlp (S::com) ?P) ∧ wlp S ?P ≤⇩L wlp S ?Q›*) by auto have "is_quantum_predicate (wlp (While M S) P)" using wlp_while_exists[of "wlp S" M P] (*‹⟦⋀P. is_quantum_predicate P ⟹ is_quantum_predicate (wlp S P); ⋀P Q. ⟦is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ wlp S P ≤⇩L wlp S Q; measurement d 2 M; is_quantum_predicate P⟧ ⟹ is_quantum_predicate (wlp_while (M 0) (M 1) (wlp S) P) ∧ (∀n. wlp_while (M 0) (M 1) (wlp S) P ≤⇩L wlp_while_n (M 0) (M 1) (wlp S) n P) ∧ (∀W'. (∀n. W' ≤⇩L wlp_while_n (M 0) (M 1) (wlp S) n P) ⟶ W' ≤⇩L wlp_while (M 0) (M 1) (wlp S) P) ∧ limit_mat (λn. wlp_while_n (M 0) (M 1) (wlp S) n P) (wlp_while (M 0) (M 1) (wlp S) P) d›*) closeWS (*‹is_quantum_predicate (?P::complex mat) ⟹ is_quantum_predicate (wlp (S::com) ?P)›*) monoWS (*‹⟦is_quantum_predicate ?P; is_quantum_predicate ?Q; ?P ≤⇩L ?Q⟧ ⟹ wlp S ?P ≤⇩L wlp S ?Q›*) m (*‹measurement d 2 M›*) qpP (*‹is_quantum_predicate P›*) by auto moreover have "wlp (While M S) P ≤⇩L wlp (While M S) Q" using wlp_while_mono[of "wlp S" M P Q] (*‹⟦⋀P. is_quantum_predicate P ⟹ is_quantum_predicate (wlp S P); ⋀P Q. ⟦is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ wlp S P ≤⇩L wlp S Q; measurement d 2 M; is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ wlp_while (M 0) (M 1) (wlp S) P ≤⇩L wlp_while (M 0) (M 1) (wlp S) Q›*) closeWS (*‹is_quantum_predicate ?P ⟹ is_quantum_predicate (wlp S ?P)›*) monoWS (*‹⟦is_quantum_predicate ?P; is_quantum_predicate ?Q; ?P ≤⇩L ?Q⟧ ⟹ wlp S ?P ≤⇩L wlp S ?Q›*) m (*‹measurement d (2::nat) (M::nat ⇒ complex mat)›*) While (*‹⟦well_com S; is_quantum_predicate ?P; is_quantum_predicate ?Q; ?P ≤⇩L ?Q⟧ ⟹ is_quantum_predicate (wlp S ?P) ∧ wlp S ?P ≤⇩L wlp S ?Q› ‹well_com (While M S)› ‹is_quantum_predicate (P::complex mat)› ‹is_quantum_predicate Q› ‹P ≤⇩L Q›*) by auto ultimately show "?case" (*goal: ‹is_quantum_predicate (wlp (While M S) P) ∧ wlp (While M S) P ≤⇩L wlp (While M S) Q›*) by auto qed lemma wlp_close: assumes wc: "well_com S" and qp: "is_quantum_predicate P" shows "is_quantum_predicate (wlp S P)" using wlp_mono_and_close[OF wc qp qp] (*‹P ≤⇩L P ⟹ is_quantum_predicate (wlp S P) ∧ wlp S P ≤⇩L wlp S P›*) is_quantum_predicate_def[of P] (*‹is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)›*) qp (*‹is_quantum_predicate (P::complex mat)›*) lowner_le_refl (*‹?A ∈ carrier_mat ?n ?n ⟹ ?A ≤⇩L ?A›*) by auto lemma wlp_soundness: "well_com S ⟹ (⋀P. (is_quantum_predicate P ⟹ (∀ρ ∈ density_states. trace (wlp S P * ρ) = trace (P * (denote S ρ)) + trace ρ - trace (denote S ρ))))" proof (induct S) (*goals: 1. ‹⋀P. ⟦well_com SKIP; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp SKIP P * ρ) = trace (P * denote SKIP ρ) + trace ρ - trace (denote SKIP ρ)› 2. ‹⋀x P. ⟦well_com (Utrans x); is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp (Utrans x) P * ρ) = trace (P * denote (Utrans x) ρ) + trace ρ - trace (denote (Utrans x) ρ)› 3. ‹⋀S1 S2 P. ⟦⋀P. ⟦well_com S1; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp S1 P * ρ) = trace (P * denote S1 ρ) + trace ρ - trace (denote S1 ρ); ⋀P. ⟦well_com S2; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp S2 P * ρ) = trace (P * denote S2 ρ) + trace ρ - trace (denote S2 ρ); well_com (S1;; S2); is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp (S1;; S2) P * ρ) = trace (P * denote (S1;; S2) ρ) + trace ρ - trace (denote (S1;; S2) ρ)› 4. ‹⋀x1 x2a x3 P. ⟦⋀x3a P. ⟦x3a ∈ set x3; well_com x3a; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp x3a P * ρ) = trace (P * denote x3a ρ) + trace ρ - trace (denote x3a ρ); well_com (Measure x1 x2a x3); is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp (Measure x1 x2a x3) P * ρ) = trace (P * denote (Measure x1 x2a x3) ρ) + trace ρ - trace (denote (Measure x1 x2a x3) ρ)› 5. ‹⋀x1 S P. ⟦⋀P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp S P * ρ) = trace (P * denote S ρ) + trace ρ - trace (denote S ρ); well_com (While x1 S); is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp (While x1 S) P * ρ) = trace (P * denote (While x1 S) ρ) + trace ρ - trace (denote (While x1 S) ρ)›*) case SKIP (*‹well_com SKIP› ‹is_quantum_predicate P›*) then show "?case" (*goal: ‹∀ρ∈density_states. trace (wlp SKIP P * ρ) = trace (P * denote SKIP ρ) + trace ρ - trace (denote SKIP ρ)›*) by auto next (*goals: 1. ‹⋀(x::complex mat) P::complex mat. ⟦well_com (Utrans x); is_quantum_predicate P⟧ ⟹ ∀ρ::complex mat∈density_states. trace (wlp (Utrans x) P * ρ) = trace (P * denote (Utrans x) ρ) + trace ρ - trace (denote (Utrans x) ρ)› 2. ‹⋀(S1::com) (S2::com) P::complex mat. ⟦⋀P::complex mat. ⟦well_com S1; is_quantum_predicate P⟧ ⟹ ∀ρ::complex mat∈density_states. trace (wlp S1 P * ρ) = trace (P * denote S1 ρ) + trace ρ - trace (denote S1 ρ); ⋀P::complex mat. ⟦well_com S2; is_quantum_predicate P⟧ ⟹ ∀ρ::complex mat∈density_states. trace (wlp S2 P * ρ) = trace (P * denote S2 ρ) + trace ρ - trace (denote S2 ρ); well_com (S1;; S2); is_quantum_predicate P⟧ ⟹ ∀ρ::complex mat∈density_states. trace (wlp (S1;; S2) P * ρ) = trace (P * denote (S1;; S2) ρ) + trace ρ - trace (denote (S1;; S2) ρ)› 3. ‹⋀(x1::nat) (x2a::nat ⇒ complex mat) (x3::com list) P::complex mat. ⟦⋀(x3a::com) P::complex mat. ⟦x3a ∈ set x3; well_com x3a; is_quantum_predicate P⟧ ⟹ ∀ρ::complex mat∈density_states. trace (wlp x3a P * ρ) = trace (P * denote x3a ρ) + trace ρ - trace (denote x3a ρ); well_com (Measure x1 x2a x3); is_quantum_predicate P⟧ ⟹ ∀ρ::complex mat∈density_states. trace (wlp (Measure x1 x2a x3) P * ρ) = trace (P * denote (Measure x1 x2a x3) ρ) + trace ρ - trace (denote (Measure x1 x2a x3) ρ)› 4. ‹⋀(x1::nat ⇒ complex mat) (S::com) P::complex mat. ⟦⋀P::complex mat. ⟦well_com S; is_quantum_predicate P⟧ ⟹ ∀ρ::complex mat∈density_states. trace (wlp S P * ρ) = trace (P * denote S ρ) + trace ρ - trace (denote S ρ); well_com (While x1 S); is_quantum_predicate P⟧ ⟹ ∀ρ::complex mat∈density_states. trace (wlp (While x1 S) P * ρ) = trace (P * denote (While x1 S) ρ) + trace ρ - trace (denote (While x1 S) ρ)›*) case (Utrans U) (*‹well_com (Utrans U)› ‹is_quantum_predicate P›*) then have dU: "U ∈ carrier_mat d d" and u: "unitary U" and wc: "well_com (Utrans U)" and qp: "is_quantum_predicate P" and dP: "P ∈ carrier_mat d d" using is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) apply - (*goals: 1. ‹⟦well_com (Utrans U); is_quantum_predicate P; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ U ∈ carrier_mat d d› 2. ‹⟦well_com (Utrans U); is_quantum_predicate P; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ unitary U› 3. ‹⟦well_com (Utrans U); is_quantum_predicate P; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ well_com (Utrans U)› 4. ‹⟦well_com (Utrans U); is_quantum_predicate P; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ is_quantum_predicate P› 5. ‹⟦well_com (Utrans U); is_quantum_predicate P; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ P ∈ carrier_mat d d› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . have qp': "is_quantum_predicate (wlp (Utrans U) P)" using wlp_close[OF wc qp] (*‹is_quantum_predicate (wlp (Utrans (U::complex mat)) (P::complex mat))›*) by auto have eq1: "trace (adjoint U * P * U * ρ) = trace (P * (U * ρ * adjoint U))" if dr: "ρ ∈ carrier_mat d d" for ρ using dr (*‹ρ ∈ carrier_mat d d›*) dP (*‹P ∈ carrier_mat d d›*) apply (mat_assoc d) (*goal: ‹trace (adjoint U * P * U * ρ) = trace (P * (U * ρ * adjoint U))›*) using wc (*‹well_com (Utrans U)›*) by auto have eq2: "trace (U * ρ * adjoint U) = trace ρ" if dr: "ρ ∈ carrier_mat d d" for ρ using unitary_operator_keep_trace[OF adjoint_dim [ OF dU ] dr unitary_adjoint [ OF dU u ]] (*‹trace (ρ::complex mat) = trace (adjoint (adjoint (U::complex mat)) * ρ * adjoint U)›*) adjoint_adjoint[of U] (*‹adjoint (adjoint U) = U›*) by auto show "?case" (*goal: ‹∀ρ∈density_states. trace (wlp (Utrans U) P * ρ) = trace (P * denote (Utrans U) ρ) + trace ρ - trace (denote (Utrans U) ρ)›*) using qp' (*‹is_quantum_predicate (wlp (Utrans U) P)›*) eq1 (*‹?ρ ∈ carrier_mat d d ⟹ trace (adjoint U * P * U * ?ρ) = trace (P * (U * ?ρ * adjoint U))›*) eq2 (*‹?ρ ∈ carrier_mat d d ⟹ trace (U * ?ρ * adjoint U) = trace ?ρ›*) density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) by auto next (*goals: 1. ‹⋀S1 S2 P. ⟦⋀P. ⟦well_com S1; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp S1 P * ρ) = trace (P * denote S1 ρ) + trace ρ - trace (denote S1 ρ); ⋀P. ⟦well_com S2; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp S2 P * ρ) = trace (P * denote S2 ρ) + trace ρ - trace (denote S2 ρ); well_com (S1;; S2); is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp (S1;; S2) P * ρ) = trace (P * denote (S1;; S2) ρ) + trace ρ - trace (denote (S1;; S2) ρ)› 2. ‹⋀x1 x2a x3 P. ⟦⋀x3a P. ⟦x3a ∈ set x3; well_com x3a; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp x3a P * ρ) = trace (P * denote x3a ρ) + trace ρ - trace (denote x3a ρ); well_com (Measure x1 x2a x3); is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp (Measure x1 x2a x3) P * ρ) = trace (P * denote (Measure x1 x2a x3) ρ) + trace ρ - trace (denote (Measure x1 x2a x3) ρ)› 3. ‹⋀x1 S P. ⟦⋀P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp S P * ρ) = trace (P * denote S ρ) + trace ρ - trace (denote S ρ); well_com (While x1 S); is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp (While x1 S) P * ρ) = trace (P * denote (While x1 S) ρ) + trace ρ - trace (denote (While x1 S) ρ)›*) case (Seq S1 S2) (*‹⟦well_com S1; is_quantum_predicate ?P⟧ ⟹ ∀ρ∈density_states. trace (wlp S1 ?P * ρ) = trace (?P * denote S1 ρ) + trace ρ - trace (denote S1 ρ)› ‹⟦well_com S2; is_quantum_predicate ?P⟧ ⟹ ∀ρ∈density_states. trace (wlp S2 ?P * ρ) = trace (?P * denote S2 ρ) + trace ρ - trace (denote S2 ρ)› ‹well_com (S1;; S2)› ‹is_quantum_predicate P›*) then have qp: "is_quantum_predicate P" and wc1: "well_com S1" and wc2: "well_com S2" apply - (*goals: 1. ‹⟦⋀P. ⟦well_com S1; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp S1 P * ρ) = trace (P * denote S1 ρ) + trace ρ - trace (denote S1 ρ); ⋀P. ⟦well_com S2; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp S2 P * ρ) = trace (P * denote S2 ρ) + trace ρ - trace (denote S2 ρ); well_com (S1;; S2); is_quantum_predicate P⟧ ⟹ is_quantum_predicate P› 2. ‹⟦⋀P. ⟦well_com S1; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp S1 P * ρ) = trace (P * denote S1 ρ) + trace ρ - trace (denote S1 ρ); ⋀P. ⟦well_com S2; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp S2 P * ρ) = trace (P * denote S2 ρ) + trace ρ - trace (denote S2 ρ); well_com (S1;; S2); is_quantum_predicate P⟧ ⟹ well_com S1› 3. ‹⟦⋀P. ⟦well_com S1; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp S1 P * ρ) = trace (P * denote S1 ρ) + trace ρ - trace (denote S1 ρ); ⋀P. ⟦well_com S2; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp S2 P * ρ) = trace (P * denote S2 ρ) + trace ρ - trace (denote S2 ρ); well_com (S1;; S2); is_quantum_predicate P⟧ ⟹ well_com S2› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . then have qp2: "is_quantum_predicate (wlp S2 P)" using wlp_close (*‹⟦well_com ?S; is_quantum_predicate ?P⟧ ⟹ is_quantum_predicate (wlp ?S ?P)›*) by auto then have qp1: "is_quantum_predicate (wlp S1 (wlp S2 P))" using wlp_close (*‹⟦well_com ?S; is_quantum_predicate ?P⟧ ⟹ is_quantum_predicate (wlp ?S ?P)›*) wc1 (*‹well_com S1›*) by auto have eq1: "trace (wlp S2 P * ρ) = trace (P * denote S2 ρ) + trace ρ - trace (denote S2 ρ)" if ds: "ρ ∈ density_states" for ρ using Seq(2) (*‹⟦well_com S2; is_quantum_predicate ?P⟧ ⟹ ∀ρ∈density_states. trace (wlp S2 ?P * ρ) = trace (?P * denote S2 ρ) + trace ρ - trace (denote S2 ρ)›*) wc2 (*‹well_com S2›*) qp (*‹is_quantum_predicate (P::complex mat)›*) ds (*‹ρ ∈ density_states›*) by auto have eq2: "trace (wlp S1 (wlp S2 P) * ρ) = trace ((wlp S2 P) * denote S1 ρ) + trace ρ - trace (denote S1 ρ)" if ds: "ρ ∈ density_states" for ρ using Seq(1) (*‹⟦well_com S1; is_quantum_predicate ?P⟧ ⟹ ∀ρ∈density_states. trace (wlp S1 ?P * ρ) = trace (?P * denote S1 ρ) + trace ρ - trace (denote S1 ρ)›*) wc1 (*‹well_com S1›*) qp2 (*‹is_quantum_predicate (wlp S2 P)›*) ds (*‹ρ ∈ density_states›*) by auto have eq3: "trace (wlp S1 (wlp S2 P) * ρ) = trace (P * (denote S2 (denote S1 ρ))) + trace ρ - trace (denote S2 (denote S1 ρ))" if ds: "ρ ∈ density_states" for ρ proof (-) (*goal: ‹trace (wlp S1 (wlp S2 P) * ρ) = trace (P * denote S2 (denote S1 ρ)) + trace ρ - trace (denote S2 (denote S1 ρ))›*) have "denote S1 ρ ∈ density_states" using ds (*‹(ρ::complex mat) ∈ density_states›*) denote_density_states (*‹⟦?ρ ∈ density_states; well_com ?S⟧ ⟹ denote ?S ?ρ ∈ density_states›*) wc1 (*‹well_com S1›*) by auto then have "trace ((wlp S2 P) * denote S1 ρ) = trace (P * denote S2 (denote S1 ρ)) + trace (denote S1 ρ) - trace (denote S2 (denote S1 ρ))" using eq1 (*‹?ρ ∈ density_states ⟹ trace (wlp S2 P * ?ρ) = trace (P * denote S2 ?ρ) + trace ?ρ - trace (denote S2 ?ρ)›*) by auto then show "trace (wlp S1 (wlp S2 P) * ρ) = trace (P * (denote S2 (denote S1 ρ))) + trace ρ - trace (denote S2 (denote S1 ρ))" using eq2 (*‹?ρ ∈ density_states ⟹ trace (wlp S1 (wlp S2 P) * ?ρ) = trace (wlp S2 P * denote S1 ?ρ) + trace ?ρ - trace (denote S1 ?ρ)›*) ds (*‹ρ ∈ density_states›*) by auto qed then show "?case" (*goal: ‹∀ρ∈density_states. trace (wlp (S1;; S2) P * ρ) = trace (P * denote (S1;; S2) ρ) + trace ρ - trace (denote (S1;; S2) ρ)›*) using qp1 (*‹is_quantum_predicate (wlp S1 (wlp S2 P))›*) by auto next (*goals: 1. ‹⋀x1 x2a x3 P. ⟦⋀x3a P. ⟦x3a ∈ set x3; well_com x3a; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp x3a P * ρ) = trace (P * denote x3a ρ) + trace ρ - trace (denote x3a ρ); well_com (Measure x1 x2a x3); is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp (Measure x1 x2a x3) P * ρ) = trace (P * denote (Measure x1 x2a x3) ρ) + trace ρ - trace (denote (Measure x1 x2a x3) ρ)› 2. ‹⋀x1 S P. ⟦⋀P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp S P * ρ) = trace (P * denote S ρ) + trace ρ - trace (denote S ρ); well_com (While x1 S); is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp (While x1 S) P * ρ) = trace (P * denote (While x1 S) ρ) + trace ρ - trace (denote (While x1 S) ρ)›*) case (Measure n M S) (*‹⟦?x3a ∈ set S; well_com ?x3a; is_quantum_predicate ?P⟧ ⟹ ∀ρ∈density_states. trace (wlp ?x3a ?P * ρ) = trace (?P * denote ?x3a ρ) + trace ρ - trace (denote ?x3a ρ)› ‹well_com (Measure n M S)› ‹is_quantum_predicate (P::complex mat)›*) then have wc: "well_com (Measure n M S)" and wck: "k < n ⟹ well_com (S!k)" and qpP: "is_quantum_predicate P" and dP: "P ∈ carrier_mat d d" and qpWk: "k < n ⟹ is_quantum_predicate (wlp (S!k) P)" and dWk: "k < n ⟹ (wlp (S!k) P) ∈ carrier_mat d d" and c: "k < n ⟹ ρ ∈ density_states ⟹ trace (wlp (S!k) P * ρ) = trace (P * denote (S!k) ρ) + trace ρ - trace (denote (S!k) ρ)" and m: "measurement d n M" and aMMkleq: "k < n ⟹ adjoint (M k) * M k ≤⇩L 1⇩m d" and dMk: "k < n ⟹ M k ∈ carrier_mat d d" for k and ρ using is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) measurement_def (*‹measurement ?d ?n ?M = ((∀j<?n. ?M j ∈ carrier_mat ?d ?d) ∧ matrix_sum ?d (λj. adjoint (?M j) * ?M j) ?n = 1⇩m ?d)›*) measure_well_com (*‹⟦well_com (Measure (?n::nat) (?M::nat ⇒ complex mat) (?S::com list)); (?k::nat) < ?n⟧ ⟹ well_com (?S ! ?k)›*) measurement_le_one_mat (*‹⟦measurement ?d ?n ?f; ?j < ?n⟧ ⟹ adjoint (?f ?j) * ?f ?j ≤⇩L 1⇩m ?d›*) wlp_close (*‹⟦well_com (?S::com); is_quantum_predicate (?P::complex mat)⟧ ⟹ is_quantum_predicate (wlp ?S ?P)›*) apply - (*goals: 1. ‹⟦⋀x3a P. ⟦x3a ∈ set S; well_com x3a; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp x3a P * ρ) = trace (P * denote x3a ρ) + trace ρ - trace (denote x3a ρ); well_com (Measure n M S); is_quantum_predicate P; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); ⋀d n M. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj. adjoint (M j) * M j) n = 1⇩m d); ⋀n M S k. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀d n f j. ⟦measurement d n f; j < n⟧ ⟹ adjoint (f j) * f j ≤⇩L 1⇩m d; ⋀S P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ is_quantum_predicate (wlp S P)⟧ ⟹ well_com (Measure n M S)› 2. ‹⟦k < n; ⋀x3a P. ⟦x3a ∈ set S; well_com x3a; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp x3a P * ρ) = trace (P * denote x3a ρ) + trace ρ - trace (denote x3a ρ); well_com (Measure n M S); is_quantum_predicate P; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); ⋀d n M. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj. adjoint (M j) * M j) n = 1⇩m d); ⋀n M S k. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀d n f j. ⟦measurement d n f; j < n⟧ ⟹ adjoint (f j) * f j ≤⇩L 1⇩m d; ⋀S P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ is_quantum_predicate (wlp S P)⟧ ⟹ well_com (S ! k)› 3. ‹⟦⋀x3a P. ⟦x3a ∈ set S; well_com x3a; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp x3a P * ρ) = trace (P * denote x3a ρ) + trace ρ - trace (denote x3a ρ); well_com (Measure n M S); is_quantum_predicate P; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); ⋀d n M. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj. adjoint (M j) * M j) n = 1⇩m d); ⋀n M S k. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀d n f j. ⟦measurement d n f; j < n⟧ ⟹ adjoint (f j) * f j ≤⇩L 1⇩m d; ⋀S P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ is_quantum_predicate (wlp S P)⟧ ⟹ is_quantum_predicate P› 4. ‹⟦⋀x3a P. ⟦x3a ∈ set S; well_com x3a; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp x3a P * ρ) = trace (P * denote x3a ρ) + trace ρ - trace (denote x3a ρ); well_com (Measure n M S); is_quantum_predicate P; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); ⋀d n M. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj. adjoint (M j) * M j) n = 1⇩m d); ⋀n M S k. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀d n f j. ⟦measurement d n f; j < n⟧ ⟹ adjoint (f j) * f j ≤⇩L 1⇩m d; ⋀S P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ is_quantum_predicate (wlp S P)⟧ ⟹ P ∈ carrier_mat d d› 5. ‹⟦k < n; ⋀x3a P. ⟦x3a ∈ set S; well_com x3a; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp x3a P * ρ) = trace (P * denote x3a ρ) + trace ρ - trace (denote x3a ρ); well_com (Measure n M S); is_quantum_predicate P; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); ⋀d n M. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj. adjoint (M j) * M j) n = 1⇩m d); ⋀n M S k. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀d n f j. ⟦measurement d n f; j < n⟧ ⟹ adjoint (f j) * f j ≤⇩L 1⇩m d; ⋀S P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ is_quantum_predicate (wlp S P)⟧ ⟹ is_quantum_predicate (wlp (S ! k) P)› 6. ‹⟦k < n; ⋀x3a P. ⟦x3a ∈ set S; well_com x3a; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp x3a P * ρ) = trace (P * denote x3a ρ) + trace ρ - trace (denote x3a ρ); well_com (Measure n M S); is_quantum_predicate P; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); ⋀d n M. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj. adjoint (M j) * M j) n = 1⇩m d); ⋀n M S k. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀d n f j. ⟦measurement d n f; j < n⟧ ⟹ adjoint (f j) * f j ≤⇩L 1⇩m d; ⋀S P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ is_quantum_predicate (wlp S P)⟧ ⟹ wlp (S ! k) P ∈ carrier_mat d d› 7. ‹⟦k < n; ρ ∈ density_states; ⋀x3a P. ⟦x3a ∈ set S; well_com x3a; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp x3a P * ρ) = trace (P * denote x3a ρ) + trace ρ - trace (denote x3a ρ); well_com (Measure n M S); is_quantum_predicate P; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); ⋀d n M. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj. adjoint (M j) * M j) n = 1⇩m d); ⋀n M S k. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀d n f j. ⟦measurement d n f; j < n⟧ ⟹ adjoint (f j) * f j ≤⇩L 1⇩m d; ⋀S P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ is_quantum_predicate (wlp S P)⟧ ⟹ trace (wlp (S ! k) P * ρ) = trace (P * denote (S ! k) ρ) + trace ρ - trace (denote (S ! k) ρ)› 8. ‹⟦⋀x3a P. ⟦x3a ∈ set S; well_com x3a; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp x3a P * ρ) = trace (P * denote x3a ρ) + trace ρ - trace (denote x3a ρ); well_com (Measure n M S); is_quantum_predicate P; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); ⋀d n M. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj. adjoint (M j) * M j) n = 1⇩m d); ⋀n M S k. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀d n f j. ⟦measurement d n f; j < n⟧ ⟹ adjoint (f j) * f j ≤⇩L 1⇩m d; ⋀S P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ is_quantum_predicate (wlp S P)⟧ ⟹ measurement d n M› 9. ‹⟦k < n; ⋀x3a P. ⟦x3a ∈ set S; well_com x3a; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp x3a P * ρ) = trace (P * denote x3a ρ) + trace ρ - trace (denote x3a ρ); well_com (Measure n M S); is_quantum_predicate P; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); ⋀d n M. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj. adjoint (M j) * M j) n = 1⇩m d); ⋀n M S k. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀d n f j. ⟦measurement d n f; j < n⟧ ⟹ adjoint (f j) * f j ≤⇩L 1⇩m d; ⋀S P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ is_quantum_predicate (wlp S P)⟧ ⟹ adjoint (M k) * M k ≤⇩L 1⇩m d› 10. ‹⟦k < n; ⋀x3a P. ⟦x3a ∈ set S; well_com x3a; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp x3a P * ρ) = trace (P * denote x3a ρ) + trace ρ - trace (denote x3a ρ); well_com (Measure n M S); is_quantum_predicate P; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); ⋀d n M. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj. adjoint (M j) * M j) n = 1⇩m d); ⋀n M S k. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀d n f j. ⟦measurement d n f; j < n⟧ ⟹ adjoint (f j) * f j ≤⇩L 1⇩m d; ⋀S P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ is_quantum_predicate (wlp S P)⟧ ⟹ M k ∈ carrier_mat d d› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*discuss goal 9*) apply ((auto)[1]) (*discuss goal 10*) apply ((auto)[1]) (*proven 10 subgoals*) . { fix ρ assume "ρ": "ρ ∈ density_states" (*‹(ρ::complex mat) ∈ density_states›*) then have dr: "ρ ∈ carrier_mat d d" and pdor: "partial_density_operator ρ" using density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) apply - (*goals: 1. ‹⟦(ρ::complex mat) ∈ density_states; density_states = {ρ::complex mat ∈ carrier_mat d d. partial_density_operator ρ}⟧ ⟹ ρ ∈ carrier_mat d d› 2. ‹⟦(ρ::complex mat) ∈ density_states; density_states = {ρ::complex mat ∈ carrier_mat d d. partial_density_operator ρ}⟧ ⟹ partial_density_operator ρ› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have dsr: "k < n ⟹ (M k) * ρ * adjoint (M k) ∈ density_states" for k unfolding density_states_def (*goal: ‹k < n ⟹ M k * ρ * adjoint (M k) ∈ {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) using dMk (*‹?k < n ⟹ M ?k ∈ carrier_mat d d›*) pdo_close_under_measurement[OF dMk dr pdor aMMkleq] (*‹⟦?k1 < n; ?k1 < n⟧ ⟹ partial_density_operator (M ?k1 * ρ * adjoint (M ?k1))›*) dr (*‹ρ ∈ carrier_mat d d›*) by fastforce then have leqk: "k < n ⟹ trace (wlp (S!k) P * ((M k) * ρ * adjoint (M k))) = trace (P * (denote (S!k) ((M k) * ρ * adjoint (M k)))) + (trace ((M k) * ρ * adjoint (M k)) - trace (denote (S ! k) ((M k) * ρ * adjoint (M k))))" for k using c (*‹⟦?k < n; ?ρ ∈ density_states⟧ ⟹ trace (wlp (S ! ?k) P * ?ρ) = trace (P * denote (S ! ?k) ?ρ) + trace ?ρ - trace (denote (S ! ?k) ?ρ)›*) by auto have "k < n ⟹ M k * ρ * adjoint (M k) ∈ carrier_mat d d" for k using dMk (*‹?k < n ⟹ M ?k ∈ carrier_mat d d›*) dr (*‹ρ ∈ carrier_mat d d›*) by fastforce then have dsMrk: "k < n ⟹ matrix_sum d (λk. (M k * ρ * adjoint (M k))) k ∈ carrier_mat d d" for k using matrix_sum_dim[of k "λk. (M k * ρ * adjoint (M k))" d] (*‹(⋀ka. ka < k ⟹ M ka * ρ * adjoint (M ka) ∈ carrier_mat d d) ⟹ matrix_sum d (λk. M k * ρ * adjoint (M k)) k ∈ carrier_mat d d›*) by fastforce have "k < n ⟹ adjoint (M k) * (wlp (S!k) P) * M k ∈ carrier_mat d d" for k using dMk (*‹?k < n ⟹ M ?k ∈ carrier_mat d d›*) by fastforce then have dsMW: "k < n ⟹ matrix_sum d (λk. adjoint (M k) * (wlp (S!k) P) * M k) k ∈ carrier_mat d d" for k using matrix_sum_dim[of k "λk. adjoint (M k) * (wlp (S!k) P) * M k" d] (*‹(⋀ka::nat. ka < (k::nat) ⟹ adjoint ((M::nat ⇒ complex mat) ka) * wlp ((S::com list) ! ka) (P::complex mat) * M ka ∈ carrier_mat d d) ⟹ matrix_sum d (λk::nat. adjoint (M k) * wlp (S ! k) P * M k) k ∈ carrier_mat d d›*) by fastforce have dSMrk: "k < n ⟹ denote (S ! k) (M k * ρ * adjoint (M k)) ∈ carrier_mat d d" for k using denote_dim[OF wck, of k "M k * ρ * adjoint (M k)"] (*‹⟦k < n; M k * ρ * adjoint (M k) ∈ carrier_mat d d; partial_density_operator (M k * ρ * adjoint (M k))⟧ ⟹ denote (S ! k) (M k * ρ * adjoint (M k)) ∈ carrier_mat d d›*) dsr (*‹?k < n ⟹ M ?k * ρ * adjoint (M ?k) ∈ density_states›*) density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) by fastforce have dsSMrk: "k < n ⟹ matrix_sum d (λk. denote (S!k) (M k * ρ * adjoint (M k))) k ∈ carrier_mat d d" for k using matrix_sum_dim[of k "λk. denote (S ! k) (M k * ρ * adjoint (M k))" d, OF dSMrk] (*‹(⋀ka. ka < k ⟹ ka < n) ⟹ matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k ∈ carrier_mat d d›*) by fastforce have "k ≤ n ⟹ trace (matrix_sum d (λk. adjoint (M k) * (wlp (S!k) P) * M k) k * ρ) = trace (P * (denote (Measure k M S) ρ)) + (trace (matrix_sum d (λk. (M k) * ρ * adjoint (M k)) k) - trace (denote (Measure k M S) ρ))" for k unfolding denote_measure_expand[OF _ wc] (*goal: ‹k ≤ n ⟹ trace (matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) k * ρ) = trace (P * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) k) - trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k))›*) proof (induct k) (*goals: 1. ‹0 ≤ n ⟹ trace (matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) 0 * ρ) = trace (P * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) 0) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) 0) - trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) 0))› 2. ‹⋀k. ⟦k ≤ n ⟹ trace (matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) k * ρ) = trace (P * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) k) - trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k)); Suc k ≤ n⟧ ⟹ trace (matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) (Suc k) * ρ) = trace (P * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) (Suc k)) - trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) (Suc k)))›*) case 0 (*‹(0::nat) ≤ (n::nat)›*) then show "?case" (*goal: ‹trace (matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) 0 * ρ) = trace (P * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) 0) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) 0) - trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) 0))›*) unfolding matrix_sum.simps (*goal: ‹trace (0⇩m d d * ρ) = trace (P * 0⇩m d d) + (trace (0⇩m d d) - trace (0⇩m d d))›*) using dP (*‹P ∈ carrier_mat d d›*) dr (*‹ρ ∈ carrier_mat d d›*) by auto next (*goal: ‹⋀k. ⟦k ≤ n ⟹ trace (matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) k * ρ) = trace (P * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) k) - trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k)); Suc k ≤ n⟧ ⟹ trace (matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) (Suc k) * ρ) = trace (P * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) (Suc k)) - trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) (Suc k)))›*) case (Suc k) (*‹k ≤ n ⟹ trace (matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) k * ρ) = trace (P * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) k) - trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k))› ‹Suc k ≤ n›*) then have k: "k < n" by auto have eq1: "trace (matrix_sum d (λk. adjoint (M k) * (wlp (S!k) P) * M k) (Suc k) * ρ) = trace (adjoint (M k) * (wlp (S!k) P) * M k * ρ) + trace (matrix_sum d (λk. adjoint (M k) * (wlp (S!k) P) * M k) k * ρ)" unfolding matrix_sum.simps (*goal: ‹trace ((adjoint (M k) * wlp (S ! k) P * M k + matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) k) * ρ) = trace (adjoint (M k) * wlp (S ! k) P * M k * ρ) + trace (matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) k * ρ)›*) using dMk[OF k] (*‹(M::nat ⇒ complex mat) (k::nat) ∈ carrier_mat d d›*) dWk[OF k] (*‹wlp ((S::com list) ! (k::nat)) (P::complex mat) ∈ carrier_mat d d›*) dr (*‹ρ ∈ carrier_mat d d›*) dsMW[OF k] (*‹matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) k ∈ carrier_mat d d›*) by (mat_assoc d) have "trace (adjoint (M k) * (wlp (S!k) P) * M k * ρ) = trace ((wlp (S!k) P) * (M k * ρ * adjoint (M k)))" using dMk[OF k] (*‹M k ∈ carrier_mat d d›*) dWk[OF k] (*‹wlp (S ! k) P ∈ carrier_mat d d›*) dr (*‹ρ ∈ carrier_mat d d›*) by (mat_assoc d) also (*calculation: ‹trace (adjoint (M k) * wlp (S ! k) P * M k * ρ) = trace (wlp (S ! k) P * (M k * ρ * adjoint (M k)))›*) have "… = trace (P * (denote (S!k) ((M k) * ρ * adjoint (M k)))) + (trace ((M k) * ρ * adjoint (M k)) - trace (denote (S ! k) ((M k) * ρ * adjoint (M k))))" using leqk (*‹(?k::nat) < (n::nat) ⟹ trace (wlp ((S::com list) ! ?k) (P::complex mat) * ((M::nat ⇒ complex mat) ?k * (ρ::complex mat) * adjoint (M ?k))) = trace (P * denote (S ! ?k) (M ?k * ρ * adjoint (M ?k))) + (trace (M ?k * ρ * adjoint (M ?k)) - trace (denote (S ! ?k) (M ?k * ρ * adjoint (M ?k))))›*) k (*‹k < n›*) by auto finally (*calculation: ‹trace (adjoint (M k) * wlp (S ! k) P * M k * ρ) = trace (P * denote (S ! k) (M k * ρ * adjoint (M k))) + (trace (M k * ρ * adjoint (M k)) - trace (denote (S ! k) (M k * ρ * adjoint (M k))))›*) have eq2: "trace (adjoint (M k) * (wlp (S!k) P) * M k * ρ) = trace (P * (denote (S!k) ((M k) * ρ * adjoint (M k)))) + (trace ((M k) * ρ * adjoint (M k)) - trace (denote (S ! k) ((M k) * ρ * adjoint (M k))))" . have eq3: "trace (P * matrix_sum d (λk. denote (S!k) (M k * ρ * adjoint (M k))) (Suc k)) = trace (P * (denote (S!k) (M k * ρ * adjoint (M k)))) + trace (P * matrix_sum d (λk. denote (S!k) (M k * ρ * adjoint (M k))) k)" unfolding matrix_sum.simps (*goal: ‹trace (P * (denote (S ! k) (M k * ρ * adjoint (M k)) + matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k)) = trace (P * denote (S ! k) (M k * ρ * adjoint (M k))) + trace (P * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k)›*) using dP (*‹P ∈ carrier_mat d d›*) dSMrk[OF k] (*‹denote (S ! k) (M k * ρ * adjoint (M k)) ∈ carrier_mat d d›*) dsSMrk[OF k] (*‹matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k ∈ carrier_mat d d›*) by (mat_assoc d) have eq4: "trace (denote (S ! k) (M k * ρ * adjoint (M k)) + matrix_sum d (λk. denote (S!k) (M k * ρ * adjoint (M k))) k) = trace (denote (S ! k) (M k * ρ * adjoint (M k))) + trace (matrix_sum d (λk. denote (S!k) (M k * ρ * adjoint (M k))) k)" using dSMrk[OF k] (*‹denote (S ! k) (M k * ρ * adjoint (M k)) ∈ carrier_mat d d›*) dsSMrk[OF k] (*‹matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k ∈ carrier_mat d d›*) by (mat_assoc d) show "?case" (*goal: ‹trace (matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) (Suc k) * ρ) = trace (P * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) (Suc k)) - trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) (Suc k)))›*) apply (subst eq1 (*‹trace (matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) (Suc k) * ρ) = trace (adjoint (M k) * wlp (S ! k) P * M k * ρ) + trace (matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) k * ρ)›*)) (*goal: ‹trace (matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) (Suc k) * ρ) = trace (P * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) (Suc k)) - trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) (Suc k)))›*) apply (subst eq3 (*‹trace ((P::complex mat) * matrix_sum d (λk::nat. denote ((S::com list) ! k) ((M::nat ⇒ complex mat) k * (ρ::complex mat) * adjoint (M k))) (Suc (k::nat))) = trace (P * denote (S ! k) (M k * ρ * adjoint (M k))) + trace (P * matrix_sum d (λk::nat. denote (S ! k) (M k * ρ * adjoint (M k))) k)›*)) (*goal: ‹trace (adjoint (M k) * wlp (S ! k) P * M k * ρ) + trace (matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) k * ρ) = trace (P * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) (Suc k)) - trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) (Suc k)))›*) apply (simp del: less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) (*goal: ‹trace (adjoint ((M::nat ⇒ complex mat) (k::nat)) * wlp ((S::com list) ! k) (P::complex mat) * M k * (ρ::complex mat)) + trace (matrix_sum d (λk::nat. adjoint (M k) * wlp (S ! k) P * M k) k * ρ) = trace (P * denote (S ! k) (M k * ρ * adjoint (M k))) + trace (P * matrix_sum d (λk::nat. denote (S ! k) (M k * ρ * adjoint (M k))) k) + (trace (matrix_sum d (λk::nat. M k * ρ * adjoint (M k)) (Suc k)) - trace (matrix_sum d (λk::nat. denote (S ! k) (M k * ρ * adjoint (M k))) (Suc k)))›*) apply (subst trace_add_linear[of "M k * ρ * adjoint (M k)" d "matrix_sum d (λk. M k * ρ * adjoint (M k)) k"] (*‹⟦M k * ρ * adjoint (M k) ∈ carrier_mat d d; matrix_sum d (λk. M k * ρ * adjoint (M k)) k ∈ carrier_mat d d⟧ ⟹ trace (M k * ρ * adjoint (M k) + matrix_sum d (λk. M k * ρ * adjoint (M k)) k) = trace (M k * ρ * adjoint (M k)) + trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) k)›*)) (*goals: 1. ‹M k * ρ * adjoint (M k) ∈ carrier_mat d d› 2. ‹matrix_sum d (λk. M k * ρ * adjoint (M k)) k ∈ carrier_mat d d› 3. ‹trace (adjoint (M k) * wlp (S ! k) P * M k * ρ) + trace (matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) k * ρ) = trace (P * denote (S ! k) (M k * ρ * adjoint (M k))) + trace (P * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k) + (trace (M k * ρ * adjoint (M k)) + trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) k) - trace (denote (S ! k) (M k * ρ * adjoint (M k)) + matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k))› discuss goal 1*) apply (simp add: dMk (*‹?k < n ⟹ M ?k ∈ carrier_mat d d›*) adjoint_dim[OF dMk] (*‹?k1 < n ⟹ adjoint (M ?k1) ∈ carrier_mat d d›*) dr (*‹ρ ∈ carrier_mat d d›*) mult_carrier_mat[of _ d d _ d] (*‹⟦?A ∈ carrier_mat d d; ?B ∈ carrier_mat d d⟧ ⟹ ?A * ?B ∈ carrier_mat d d›*) k (*‹k < n›*)) (*discuss goal 2*) apply (simp add: dsMrk (*‹?k < n ⟹ matrix_sum d (λk. M k * ρ * adjoint (M k)) ?k ∈ carrier_mat d d›*) k (*‹k < n›*)) (*discuss goal 3*) apply (subst eq4 (*‹trace (denote ((S::com list) ! (k::nat)) ((M::nat ⇒ complex mat) k * (ρ::complex mat) * adjoint (M k)) + matrix_sum d (λk::nat. denote (S ! k) (M k * ρ * adjoint (M k))) k) = trace (denote (S ! k) (M k * ρ * adjoint (M k))) + trace (matrix_sum d (λk::nat. denote (S ! k) (M k * ρ * adjoint (M k))) k)›*)) (*goal: ‹trace (adjoint ((M::nat ⇒ complex mat) (k::nat)) * wlp ((S::com list) ! k) (P::complex mat) * M k * (ρ::complex mat)) + trace (matrix_sum d (λk::nat. adjoint (M k) * wlp (S ! k) P * M k) k * ρ) = trace (P * denote (S ! k) (M k * ρ * adjoint (M k))) + trace (P * matrix_sum d (λk::nat. denote (S ! k) (M k * ρ * adjoint (M k))) k) + (trace (M k * ρ * adjoint (M k)) + trace (matrix_sum d (λk::nat. M k * ρ * adjoint (M k)) k) - trace (denote (S ! k) (M k * ρ * adjoint (M k)) + matrix_sum d (λk::nat. denote (S ! k) (M k * ρ * adjoint (M k))) k))›*) apply (insert eq2 (*‹trace (adjoint (M k) * wlp (S ! k) P * M k * ρ) = trace (P * denote (S ! k) (M k * ρ * adjoint (M k))) + (trace (M k * ρ * adjoint (M k)) - trace (denote (S ! k) (M k * ρ * adjoint (M k))))›*) Suc( (*‹k ≤ n ⟹ trace (matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) k * ρ) = trace (P * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) k) - trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k))›*) 1) k (*‹k < n›*)) (*goal: ‹trace (adjoint (M k) * wlp (S ! k) P * M k * ρ) + trace (matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) k * ρ) = trace (P * denote (S ! k) (M k * ρ * adjoint (M k))) + trace (P * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k) + (trace (M k * ρ * adjoint (M k)) + trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) k) - (trace (denote (S ! k) (M k * ρ * adjoint (M k))) + trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k)))›*) apply fastforce (*proven 3 subgoals*) . qed then have leq: "trace (matrix_sum d (λk. adjoint (M k) * (wlp (S!k) P) * M k) n * ρ) = trace (P * denote (Measure n M S) ρ) + (trace (matrix_sum d (λk. (M k) * ρ * adjoint (M k)) n) - trace (denote (Measure n M S) ρ))" by auto have "trace (matrix_sum d (λk. (M k) * ρ * adjoint (M k)) n) = trace ρ" using trace_measurement (*‹⟦measurement (?d::nat) (?n::nat) (?M::nat ⇒ complex mat); (?A::complex mat) ∈ carrier_mat ?d ?d⟧ ⟹ trace (matrix_sum ?d (λk::nat. ?M k * ?A * adjoint (?M k)) ?n) = trace ?A›*) m (*‹measurement d n M›*) dr (*‹ρ ∈ carrier_mat d d›*) by auto with leq (*‹trace (matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) n * ρ) = trace (P * denote (Measure n M S) ρ) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) n) - trace (denote (Measure n M S) ρ))›*) have "trace (matrix_sum d (λk. adjoint (M k) * (wlp (S!k) P) * M k) n * ρ) = trace (P * denote (Measure n M S) ρ) + (trace ρ - trace (denote (Measure n M S) ρ))" unfolding denote_measure_def (*goal: ‹trace (matrix_sum d (λk::nat. adjoint ((M::nat ⇒ complex mat) k) * wlp ((S::com list) ! k) (P::complex mat) * M k) (n::nat) * (ρ::complex mat)) = trace (P * denote (Measure n M S) ρ) + (trace ρ - trace (denote (Measure n M S) ρ))›*) by auto } then show "?case" (*goal: ‹∀ρ∈density_states. trace (wlp (Measure n M S) P * ρ) = trace (P * denote (Measure n M S) ρ) + trace ρ - trace (denote (Measure n M S) ρ)›*) unfolding wlp_measure_expand[OF wc] (*goal: ‹∀ρ::complex mat∈density_states. trace (matrix_sum d (λk::nat. adjoint ((M::nat ⇒ complex mat) k) * wlp ((S::com list) ! k) (P::complex mat) * M k) (n::nat) * ρ) = trace (P * denote (Measure n M S) ρ) + trace ρ - trace (denote (Measure n M S) ρ)›*) by auto next (*goal: ‹⋀(x1::nat ⇒ complex mat) (S::com) P::complex mat. ⟦⋀P::complex mat. ⟦well_com S; is_quantum_predicate P⟧ ⟹ ∀ρ::complex mat∈density_states. trace (wlp S P * ρ) = trace (P * denote S ρ) + trace ρ - trace (denote S ρ); well_com (While x1 S); is_quantum_predicate P⟧ ⟹ ∀ρ::complex mat∈density_states. trace (wlp (While x1 S) P * ρ) = trace (P * denote (While x1 S) ρ) + trace ρ - trace (denote (While x1 S) ρ)›*) case (While M S) (*‹⟦well_com S; is_quantum_predicate ?P⟧ ⟹ ∀ρ∈density_states. trace (wlp S ?P * ρ) = trace (?P * denote S ρ) + trace ρ - trace (denote S ρ)› ‹well_com (While (M::nat ⇒ complex mat) (S::com))› ‹is_quantum_predicate (P::complex mat)›*) then have qpP: "is_quantum_predicate P" and dP: "P ∈ carrier_mat d d" and wcS: "well_com S" and m: "measurement d 2 M" and wc: "well_com (While M S)" using is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) apply - (*goals: 1. ‹⟦⋀P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp S P * ρ) = trace (P * denote S ρ) + trace ρ - trace (denote S ρ); well_com (While M S); is_quantum_predicate P; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ is_quantum_predicate P› 2. ‹⟦⋀P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp S P * ρ) = trace (P * denote S ρ) + trace ρ - trace (denote S ρ); well_com (While M S); is_quantum_predicate P; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ P ∈ carrier_mat d d› 3. ‹⟦⋀P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp S P * ρ) = trace (P * denote S ρ) + trace ρ - trace (denote S ρ); well_com (While M S); is_quantum_predicate P; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ well_com S› 4. ‹⟦⋀P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp S P * ρ) = trace (P * denote S ρ) + trace ρ - trace (denote S ρ); well_com (While M S); is_quantum_predicate P; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ measurement d 2 M› 5. ‹⟦⋀P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ ∀ρ∈density_states. trace (wlp S P * ρ) = trace (P * denote S ρ) + trace ρ - trace (denote S ρ); well_com (While M S); is_quantum_predicate P; ⋀P. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ well_com (While M S)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . define M0 where "M0 = M 0" define M1 where "M1 = M 1" have dM0: "M0 ∈ carrier_mat d d" and dM1: "M1 ∈ carrier_mat d d" using m (*‹measurement d 2 M›*) measurement_def (*‹measurement ?d ?n ?M = ((∀j<?n. ?M j ∈ carrier_mat ?d ?d) ∧ matrix_sum ?d (λj. adjoint (?M j) * ?M j) ?n = 1⇩m ?d)›*) M0_def (*‹(M0::complex mat) = (M::nat ⇒ complex mat) (0::nat)›*) M1_def (*‹M1 = M 1›*) apply - (*goals: 1. ‹⟦measurement d 2 M; ⋀d n M. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj. adjoint (M j) * M j) n = 1⇩m d); M0 = M 0; M1 = M 1⟧ ⟹ M0 ∈ carrier_mat d d› 2. ‹⟦measurement d 2 M; ⋀d n M. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj. adjoint (M j) * M j) n = 1⇩m d); M0 = M 0; M1 = M 1⟧ ⟹ M1 ∈ carrier_mat d d› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have leM1: "adjoint M1 * M1 ≤⇩L 1⇩m d" using measurement_le_one_mat (*‹⟦measurement ?d ?n ?f; ?j < ?n⟧ ⟹ adjoint (?f ?j) * ?f ?j ≤⇩L 1⇩m ?d›*) m (*‹measurement d 2 M›*) M1_def (*‹M1 = M 1›*) by auto define W where "W k = wlp_while_n M0 M1 (wlp S) k P" for k define DS where "DS = denote S" define D0 where "D0 = denote_while_n M0 M1 DS" define D1 where "D1 = denote_while_n_comp M0 M1 DS" define D where "D = denote_while_n_iter M0 M1 DS" have eqk: "ρ ∈ density_states ⟹ trace ((W k) * ρ) = (∑k=0..<k. trace (P * (D0 k ρ))) + trace ρ - (∑k=0..<k. trace (D0 k ρ))" for k and ρ proof (induct k arbitrary: ρ) (*goals: 1. ‹⋀ρ. ρ ∈ density_states ⟹ trace (W 0 * ρ) = (∑k = 0..<0. trace (P * D0 k ρ)) + trace ρ - (∑k = 0..<0. trace (D0 k ρ))› 2. ‹⋀k ρ. ⟦⋀ρ. ρ ∈ density_states ⟹ trace (W k * ρ) = (∑k = 0..<k. trace (P * D0 k ρ)) + trace ρ - (∑k = 0..<k. trace (D0 k ρ)); ρ ∈ density_states⟧ ⟹ trace (W (Suc k) * ρ) = (∑k = 0..<Suc k. trace (P * D0 k ρ)) + trace ρ - (∑k = 0..<Suc k. trace (D0 k ρ))›*) case 0 (*‹(ρ::complex mat) ∈ density_states›*) then have dsr: "ρ ∈ density_states" by auto show "?case" (*goal: ‹trace (W 0 * ρ) = (∑k = 0..<0. trace (P * D0 k ρ)) + trace ρ - (∑k = 0..<0. trace (D0 k ρ))›*) unfolding W_def wlp_while_n.simps (*goal: ‹trace (1⇩m d * ρ) = (∑k = 0..<0. trace (P * D0 k ρ)) + trace ρ - (∑k = 0..<0. trace (D0 k ρ))›*) using dsr (*‹(ρ::complex mat) ∈ density_states›*) density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) by auto next (*goal: ‹⋀(k::nat) ρ::complex mat. ⟦⋀ρ::complex mat. ρ ∈ density_states ⟹ trace ((W::nat ⇒ complex mat) k * ρ) = (∑k::nat = 0::nat..<k. trace ((P::complex mat) * (D0::nat ⇒ complex mat ⇒ complex mat) k ρ)) + trace ρ - (∑k::nat = 0::nat..<k. trace (D0 k ρ)); ρ ∈ density_states⟧ ⟹ trace (W (Suc k) * ρ) = (∑k::nat = 0::nat..<Suc k. trace (P * D0 k ρ)) + trace ρ - (∑k::nat = 0::nat..<Suc k. trace (D0 k ρ))›*) case (Suc k) (*‹?ρ ∈ density_states ⟹ trace (W k * ?ρ) = (∑k = 0..<k. trace (P * D0 k ?ρ)) + trace ?ρ - (∑k = 0..<k. trace (D0 k ?ρ))› ‹(ρ::complex mat) ∈ density_states›*) then have dsr: "ρ ∈ density_states" and dr: "ρ ∈ carrier_mat d d" and pdor: "partial_density_operator ρ" using density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) apply - (*goals: 1. ‹⟦⋀ρ. ρ ∈ density_states ⟹ trace (W k * ρ) = (∑k = 0..<k. trace (P * D0 k ρ)) + trace ρ - (∑k = 0..<k. trace (D0 k ρ)); ρ ∈ density_states; density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}⟧ ⟹ ρ ∈ density_states› 2. ‹⟦⋀ρ. ρ ∈ density_states ⟹ trace (W k * ρ) = (∑k = 0..<k. trace (P * D0 k ρ)) + trace ρ - (∑k = 0..<k. trace (D0 k ρ)); ρ ∈ density_states; density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}⟧ ⟹ ρ ∈ carrier_mat d d› 3. ‹⟦⋀ρ. ρ ∈ density_states ⟹ trace (W k * ρ) = (∑k = 0..<k. trace (P * D0 k ρ)) + trace ρ - (∑k = 0..<k. trace (D0 k ρ)); ρ ∈ density_states; density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}⟧ ⟹ partial_density_operator ρ› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . then have dsM1r: "M1 * ρ * adjoint M1 ∈ density_states" unfolding density_states_def (*goal: ‹(M1::complex mat) * (ρ::complex mat) * adjoint M1 ∈ {ρ::complex mat ∈ carrier_mat d d. partial_density_operator ρ}›*) using pdo_close_under_measurement[OF dM1 dr pdor leM1] (*‹partial_density_operator (M1 * ρ * adjoint M1)›*) dr (*‹ρ ∈ carrier_mat d d›*) dM1 (*‹(M1::complex mat) ∈ carrier_mat d d›*) by auto then have dsDSM1r: "(DS (M1 * ρ * adjoint M1)) ∈ density_states" unfolding density_states_def DS_def (*goal: ‹denote S (M1 * ρ * adjoint M1) ∈ {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) using denote_dim[OF wcS] (*‹⟦?ρ ∈ carrier_mat d d; partial_density_operator ?ρ⟧ ⟹ denote S ?ρ ∈ carrier_mat d d›*) denote_partial_density_operator[OF wcS] (*‹⟦partial_density_operator ?ρ; ?ρ ∈ carrier_mat d d⟧ ⟹ partial_density_operator (denote S ?ρ)›*) dsM1r (*‹M1 * ρ * adjoint M1 ∈ density_states›*) by auto have qpWk: "is_quantum_predicate (W k)" using wlp_while_n_close[OF _ m qpP, folded M0_def M1_def, of "wlp S", folded W_def] (*‹(⋀P::complex mat. is_quantum_predicate P ⟹ is_quantum_predicate (wlp (S::com) P)) ⟹ is_quantum_predicate ((W::nat ⇒ complex mat) (?k::nat))›*) wlp_close[OF wcS] (*‹is_quantum_predicate ?P ⟹ is_quantum_predicate (wlp S ?P)›*) by auto then have "is_quantum_predicate (wlp S (W k))" using wlp_close[OF wcS] (*‹is_quantum_predicate ?P ⟹ is_quantum_predicate (wlp S ?P)›*) by auto then have dWWk: "wlp S (W k) ∈ carrier_mat d d" using is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto have "trace (P * (M0 * ρ * adjoint M0)) + (∑k=0..<k. trace (P * (D0 k (DS (M1 * ρ * adjoint M1))))) = trace (P * (D0 0 ρ)) + (∑k=0..<k. trace (P * (D0 (Suc k) ρ)))" unfolding D0_def (*goal: ‹trace (P * (M0 * ρ * adjoint M0)) + (∑k = 0..<k. trace (P * denote_while_n M0 M1 DS k (DS (M1 * ρ * adjoint M1)))) = trace (P * denote_while_n M0 M1 DS 0 ρ) + (∑k = 0..<k. trace (P * denote_while_n M0 M1 DS (Suc k) ρ))›*) by auto also (*calculation: ‹trace ((P::complex mat) * ((M0::complex mat) * (ρ::complex mat) * adjoint M0)) + (∑k::nat = 0::nat..<k::nat. trace (P * (D0::nat ⇒ complex mat ⇒ complex mat) k ((DS::complex mat ⇒ complex mat) ((M1::complex mat) * ρ * adjoint M1)))) = trace (P * D0 (0::nat) ρ) + (∑k::nat = 0::nat..<k. trace (P * D0 (Suc k) ρ))›*) have "… = trace (P * (D0 0 ρ)) + (∑k=1..<(Suc k). trace (P * (D0 k ρ)))" using sum.shift_bounds_Suc_ivl[symmetric, of "λk. trace (P * (D0 k ρ))"] (*‹(∑i = ?m..<?n. trace (P * D0 (Suc i) ρ)) = (∑k = Suc ?m..<Suc ?n. trace (P * D0 k ρ))›*) by auto also (*calculation: ‹trace (P * (M0 * ρ * adjoint M0)) + (∑k = 0..<k. trace (P * D0 k (DS (M1 * ρ * adjoint M1)))) = trace (P * D0 0 ρ) + (∑k = 1..<Suc k. trace (P * D0 k ρ))›*) have "… = (∑k=0..<(Suc k). trace (P * (D0 k ρ)))" using sum.atLeast_Suc_lessThan[of 0 "Suc k" "λk. trace (P * (D0 k ρ))"] (*‹0 < Suc k ⟹ (∑k = 0..<Suc k. trace (P * D0 k ρ)) = trace (P * D0 0 ρ) + (∑k = Suc 0..<Suc k. trace (P * D0 k ρ))›*) by auto finally (*calculation: ‹trace (P * (M0 * ρ * adjoint M0)) + (∑k = 0..<k. trace (P * D0 k (DS (M1 * ρ * adjoint M1)))) = (∑k = 0..<Suc k. trace (P * D0 k ρ))›*) have eq1: "trace (P * (M0 * ρ * adjoint M0)) + (∑k=0..<k. trace (P * (D0 k (DS (M1 * ρ * adjoint M1))))) = (∑k=0..<(Suc k). trace (P * (D0 k ρ)))" . have eq2: "trace (M1 * ρ * adjoint M1) = trace ρ - trace (M0 * ρ * adjoint M0)" unfolding M0_def M1_def (*goal: ‹trace (M 1 * ρ * adjoint (M 1)) = trace ρ - trace (M 0 * ρ * adjoint (M 0))›*) using m (*‹measurement d 2 M›*) trace_measurement2[OF m dr] (*‹trace ((M::nat ⇒ complex mat) (0::nat) * (ρ::complex mat) * adjoint (M (0::nat))) + trace (M (1::nat) * ρ * adjoint (M (1::nat))) = trace ρ›*) dr (*‹ρ ∈ carrier_mat d d›*) by (simp add: algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 23 facts*)) have "trace (M0 * ρ * adjoint M0) + (∑k=0..<k. trace (D0 k (DS (M1 * ρ * adjoint M1)))) = trace (D0 0 ρ) + (∑k=0..<k. trace (D0 (Suc k) ρ))" unfolding D0_def (*goal: ‹trace ((M0::complex mat) * (ρ::complex mat) * adjoint M0) + (∑k::nat = 0::nat..<k::nat. trace (denote_while_n M0 (M1::complex mat) (DS::complex mat ⇒ complex mat) k (DS (M1 * ρ * adjoint M1)))) = trace (denote_while_n M0 M1 DS (0::nat) ρ) + (∑k::nat = 0::nat..<k. trace (denote_while_n M0 M1 DS (Suc k) ρ))›*) by auto also (*calculation: ‹trace ((M0::complex mat) * (ρ::complex mat) * adjoint M0) + (∑k::nat = 0::nat..<k::nat. trace ((D0::nat ⇒ complex mat ⇒ complex mat) k ((DS::complex mat ⇒ complex mat) ((M1::complex mat) * ρ * adjoint M1)))) = trace (D0 (0::nat) ρ) + (∑k::nat = 0::nat..<k. trace (D0 (Suc k) ρ))›*) have "… = trace (D0 0 ρ) + (∑k=1..<(Suc k). trace (D0 k ρ))" using sum.shift_bounds_Suc_ivl[symmetric, of "λk. trace (D0 k ρ)"] (*‹(∑i = ?m..<?n. trace (D0 (Suc i) ρ)) = (∑k = Suc ?m..<Suc ?n. trace (D0 k ρ))›*) by auto also (*calculation: ‹trace (M0 * ρ * adjoint M0) + (∑k = 0..<k. trace (D0 k (DS (M1 * ρ * adjoint M1)))) = trace (D0 0 ρ) + (∑k = 1..<Suc k. trace (D0 k ρ))›*) have "… = (∑k=0..<(Suc k). trace (D0 k ρ))" using sum.atLeast_Suc_lessThan[of 0 "Suc k" "λk. trace (D0 k ρ)"] (*‹0 < Suc k ⟹ (∑k = 0..<Suc k. trace (D0 k ρ)) = trace (D0 0 ρ) + (∑k = Suc 0..<Suc k. trace (D0 k ρ))›*) by auto finally (*calculation: ‹trace (M0 * ρ * adjoint M0) + (∑k = 0..<k. trace (D0 k (DS (M1 * ρ * adjoint M1)))) = (∑k = 0..<Suc k. trace (D0 k ρ))›*) have eq3: "trace (M0 * ρ * adjoint M0) + (∑k=0..<k. trace (D0 k (DS (M1 * ρ * adjoint M1)))) = (∑k=0..<(Suc k). trace (D0 k ρ))" . then have "trace (M1 * ρ * adjoint M1) - (∑k=0..<k. trace (D0 k (DS (M1 * ρ * adjoint M1)))) = trace ρ - (trace (M0 * ρ * adjoint M0) + (∑k=0..<k. trace (D0 k (DS (M1 * ρ * adjoint M1)))))" by (simp add: algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 23 facts*) eq2 (*‹trace (M1 * ρ * adjoint M1) = trace ρ - trace (M0 * ρ * adjoint M0)›*)) then have eq4: "trace (M1 * ρ * adjoint M1) - (∑k=0..<k. trace (D0 k (DS (M1 * ρ * adjoint M1)))) = trace ρ - (∑k=0..<(Suc k). trace (D0 k ρ))" by (simp add: eq3 (*‹trace (M0 * ρ * adjoint M0) + (∑k = 0..<k. trace (D0 k (DS (M1 * ρ * adjoint M1)))) = (∑k = 0..<Suc k. trace (D0 k ρ))›*)) have "trace ((W (Suc k)) * ρ) = trace (P * (M0 * ρ * adjoint M0)) + trace ((wlp S (W k)) * (M1 * ρ * adjoint M1))" unfolding W_def wlp_while_n.simps (*goal: ‹trace ((adjoint (M0::complex mat) * (P::complex mat) * M0 + adjoint (M1::complex mat) * wlp (S::com) (wlp_while_n M0 M1 (wlp S) (k::nat) P) * M1) * (ρ::complex mat)) = trace (P * (M0 * ρ * adjoint M0)) + trace (wlp S (wlp_while_n M0 M1 (wlp S) k P) * (M1 * ρ * adjoint M1))›*) apply (fold W_def) (*goal: ‹trace ((adjoint M0 * P * M0 + adjoint M1 * wlp S (wlp_while_n M0 M1 (wlp S) k P) * M1) * ρ) = trace (P * (M0 * ρ * adjoint M0)) + trace (wlp S (wlp_while_n M0 M1 (wlp S) k P) * (M1 * ρ * adjoint M1))›*) using dM0 (*‹M0 ∈ carrier_mat d d›*) dP (*‹P ∈ carrier_mat d d›*) dM1 (*‹M1 ∈ carrier_mat d d›*) dWWk (*‹wlp (S::com) ((W::nat ⇒ complex mat) (k::nat)) ∈ carrier_mat d d›*) dr (*‹ρ ∈ carrier_mat d d›*) by (mat_assoc d) also (*calculation: ‹trace (W (Suc k) * ρ) = trace (P * (M0 * ρ * adjoint M0)) + trace (wlp S (W k) * (M1 * ρ * adjoint M1))›*) have "… = trace (P * (M0 * ρ * adjoint M0)) + trace ((W k) * (DS (M1 * ρ * adjoint M1))) + trace (M1 * ρ * adjoint M1) - trace (DS (M1 * ρ * adjoint M1))" using While(1)[OF wcS, of "W k"] (*‹is_quantum_predicate (W k) ⟹ ∀ρ∈density_states. trace (wlp S (W k) * ρ) = trace (W k * denote S ρ) + trace ρ - trace (denote S ρ)›*) qpWk (*‹is_quantum_predicate ((W::nat ⇒ complex mat) (k::nat))›*) dsM1r (*‹M1 * ρ * adjoint M1 ∈ density_states›*) DS_def (*‹DS = denote S›*) by auto also (*calculation: ‹trace (W (Suc k) * ρ) = trace (P * (M0 * ρ * adjoint M0)) + trace (W k * DS (M1 * ρ * adjoint M1)) + trace (M1 * ρ * adjoint M1) - trace (DS (M1 * ρ * adjoint M1))›*) have "… = trace (P * (M0 * ρ * adjoint M0)) + (∑k=0..<k. trace (P * (D0 k (DS (M1 * ρ * adjoint M1))))) + trace (DS (M1 * ρ * adjoint M1)) - (∑k=0..<k. trace (D0 k (DS (M1 * ρ * adjoint M1)))) + trace (M1 * ρ * adjoint M1) - trace (DS (M1 * ρ * adjoint M1))" using Suc(1)[OF dsDSM1r] (*‹trace (W k * DS (M1 * ρ * adjoint M1)) = (∑k = 0..<k. trace (P * D0 k (DS (M1 * ρ * adjoint M1)))) + trace (DS (M1 * ρ * adjoint M1)) - (∑k = 0..<k. trace (D0 k (DS (M1 * ρ * adjoint M1))))›*) by auto also (*calculation: ‹trace (W (Suc k) * ρ) = trace (P * (M0 * ρ * adjoint M0)) + (∑k = 0..<k. trace (P * D0 k (DS (M1 * ρ * adjoint M1)))) + trace (DS (M1 * ρ * adjoint M1)) - (∑k = 0..<k. trace (D0 k (DS (M1 * ρ * adjoint M1)))) + trace (M1 * ρ * adjoint M1) - trace (DS (M1 * ρ * adjoint M1))›*) have "… = trace (P * (M0 * ρ * adjoint M0)) + (∑k=0..<k. trace (P * (D0 k (DS (M1 * ρ * adjoint M1))))) + trace (M1 * ρ * adjoint M1) - (∑k=0..<k. trace (D0 k (DS (M1 * ρ * adjoint M1))))" by auto also (*calculation: ‹trace ((W::nat ⇒ complex mat) (Suc (k::nat)) * (ρ::complex mat)) = trace ((P::complex mat) * ((M0::complex mat) * ρ * adjoint M0)) + (∑k::nat = 0::nat..<k. trace (P * (D0::nat ⇒ complex mat ⇒ complex mat) k ((DS::complex mat ⇒ complex mat) ((M1::complex mat) * ρ * adjoint M1)))) + trace (M1 * ρ * adjoint M1) - (∑k::nat = 0::nat..<k. trace (D0 k (DS (M1 * ρ * adjoint M1))))›*) have "… = (∑k=0..<(Suc k). trace (P * (D0 k ρ))) + trace ρ - (∑k=0..<(Suc k). trace (D0 k ρ))" by (simp add: eq1 (*‹trace (P * (M0 * ρ * adjoint M0)) + (∑k = 0..<k. trace (P * D0 k (DS (M1 * ρ * adjoint M1)))) = (∑k = 0..<Suc k. trace (P * D0 k ρ))›*) eq4 (*‹trace (M1 * ρ * adjoint M1) - (∑k = 0..<k. trace (D0 k (DS (M1 * ρ * adjoint M1)))) = trace ρ - (∑k = 0..<Suc k. trace (D0 k ρ))›*)) finally (*calculation: ‹trace (W (Suc k) * ρ) = (∑k = 0..<Suc k. trace (P * D0 k ρ)) + trace ρ - (∑k = 0..<Suc k. trace (D0 k ρ))›*) show "?case" (*goal: ‹trace (W (Suc k) * ρ) = (∑k = 0..<Suc k. trace (P * D0 k ρ)) + trace ρ - (∑k = 0..<Suc k. trace (D0 k ρ))›*) . qed { fix ρ assume dsr: "ρ ∈ density_states" (*‹(ρ::complex mat) ∈ density_states›*) then have dr: "ρ ∈ carrier_mat d d" and pdor: "partial_density_operator ρ" using density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) apply - (*goals: 1. ‹⟦ρ ∈ density_states; density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}⟧ ⟹ ρ ∈ carrier_mat d d› 2. ‹⟦ρ ∈ density_states; density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}⟧ ⟹ partial_density_operator ρ› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have limDW: "limit_mat (λn. matrix_sum d (λk. D0 k ρ) (n)) (denote (While M S) ρ) d" using limit_mat_denote_while_n[OF wc dr pdor] (*‹limit_mat (matrix_sum d (λk::nat. denote_while_n ((M::nat ⇒ complex mat) (0::nat)) (M (1::nat)) (denote (S::com)) k (ρ::complex mat))) (denote (While M S) ρ) d›*) unfolding D0_def M0_def M1_def DS_def (*goal: ‹limit_mat (matrix_sum d (λk. denote_while_n (M 0) (M 1) (denote S) k ρ)) (denote (While M S) ρ) d›*) by auto then have "limit_mat (λn. (P * (matrix_sum d (λk. D0 k ρ) (n)))) (P * (denote (While M S) ρ)) d" using mat_mult_limit[OF dP] (*‹limit_mat (?X::nat ⇒ complex mat) (?A::complex mat) d ⟹ limit_mat (mat_mult_seq (P::complex mat) ?X) (P * ?A) d›*) unfolding mat_mult_seq_def (*goal: ‹limit_mat (λn. P * matrix_sum d (λk. D0 k ρ) n) (P * denote (While M S) ρ) d›*) by auto then have limtrPm: "(λn. trace (P * (matrix_sum d (λk. D0 k ρ) (n)))) ⇢ trace (P * (denote (While M S) ρ))" using mat_trace_limit (*‹limit_mat (?g::nat ⇒ complex mat) (?A::complex mat) (?d::nat) ⟹ (λn::nat. trace (?g n)) ⇢ trace ?A›*) by auto with limDW (*‹limit_mat (matrix_sum d (λk. D0 k ρ)) (denote (While M S) ρ) d›*) have limtrDW: "(λn. trace (matrix_sum d (λk. D0 k ρ) (n))) ⇢ trace (denote (While M S) ρ)" using mat_trace_limit (*‹limit_mat ?g ?A ?d ⟹ (λn. trace (?g n)) ⇢ trace ?A›*) by auto have limm: "(λn. trace (matrix_sum d (λk. D0 k ρ) (n))) ⇢ trace (denote (While M S) ρ)" using mat_trace_limit (*‹limit_mat ?g ?A ?d ⟹ (λn. trace (?g n)) ⇢ trace ?A›*) limDW (*‹limit_mat (matrix_sum d (λk. D0 k ρ)) (denote (While M S) ρ) d›*) by auto have closeWS: "is_quantum_predicate P ⟹ is_quantum_predicate (wlp S P)" for P proof (-) (*goal: ‹is_quantum_predicate P ⟹ is_quantum_predicate (wlp S P)›*) assume asm: "is_quantum_predicate P" (*‹is_quantum_predicate (P::complex mat)›*) then have dP: "P ∈ carrier_mat d d" using is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto then show "is_quantum_predicate (wlp S P)" using wlp_mono_and_close[OF wcS asm asm] (*‹P ≤⇩L P ⟹ is_quantum_predicate (wlp S P) ∧ wlp S P ≤⇩L wlp S P›*) lowner_le_refl (*‹?A ∈ carrier_mat ?n ?n ⟹ ?A ≤⇩L ?A›*) by auto qed have monoWS: "is_quantum_predicate P ⟹ is_quantum_predicate Q ⟹ P ≤⇩L Q ⟹ wlp S P ≤⇩L wlp S Q" for P and Q using wlp_mono_and_close[OF wcS] (*‹⟦is_quantum_predicate (?P::complex mat); is_quantum_predicate (?Q::complex mat); ?P ≤⇩L ?Q⟧ ⟹ is_quantum_predicate (wlp (S::com) ?P) ∧ wlp S ?P ≤⇩L wlp S ?Q›*) by auto have "is_quantum_predicate (wlp (While M S) P)" using wlp_while_exists[of "wlp S" M P] (*‹⟦⋀P. is_quantum_predicate P ⟹ is_quantum_predicate (wlp S P); ⋀P Q. ⟦is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ wlp S P ≤⇩L wlp S Q; measurement d 2 M; is_quantum_predicate P⟧ ⟹ is_quantum_predicate (wlp_while (M 0) (M 1) (wlp S) P) ∧ (∀n. wlp_while (M 0) (M 1) (wlp S) P ≤⇩L wlp_while_n (M 0) (M 1) (wlp S) n P) ∧ (∀W'. (∀n. W' ≤⇩L wlp_while_n (M 0) (M 1) (wlp S) n P) ⟶ W' ≤⇩L wlp_while (M 0) (M 1) (wlp S) P) ∧ limit_mat (λn. wlp_while_n (M 0) (M 1) (wlp S) n P) (wlp_while (M 0) (M 1) (wlp S) P) d›*) closeWS (*‹is_quantum_predicate (?P::complex mat) ⟹ is_quantum_predicate (wlp (S::com) ?P)›*) monoWS (*‹⟦is_quantum_predicate ?P; is_quantum_predicate ?Q; ?P ≤⇩L ?Q⟧ ⟹ wlp S ?P ≤⇩L wlp S ?Q›*) m (*‹measurement d (2::nat) (M::nat ⇒ complex mat)›*) qpP (*‹is_quantum_predicate P›*) by auto have "limit_mat W (wlp_while M0 M1 (wlp S) P) d" unfolding W_def M0_def M1_def (*goal: ‹limit_mat (λk. wlp_while_n (M 0) (M 1) (wlp S) k P) (wlp_while (M 0) (M 1) (wlp S) P) d›*) using wlp_while_exists[of "wlp S" M P] (*‹⟦⋀P. is_quantum_predicate P ⟹ is_quantum_predicate (wlp S P); ⋀P Q. ⟦is_quantum_predicate P; is_quantum_predicate Q; P ≤⇩L Q⟧ ⟹ wlp S P ≤⇩L wlp S Q; measurement d 2 M; is_quantum_predicate P⟧ ⟹ is_quantum_predicate (wlp_while (M 0) (M 1) (wlp S) P) ∧ (∀n. wlp_while (M 0) (M 1) (wlp S) P ≤⇩L wlp_while_n (M 0) (M 1) (wlp S) n P) ∧ (∀W'. (∀n. W' ≤⇩L wlp_while_n (M 0) (M 1) (wlp S) n P) ⟶ W' ≤⇩L wlp_while (M 0) (M 1) (wlp S) P) ∧ limit_mat (λn. wlp_while_n (M 0) (M 1) (wlp S) n P) (wlp_while (M 0) (M 1) (wlp S) P) d›*) closeWS (*‹is_quantum_predicate (?P::complex mat) ⟹ is_quantum_predicate (wlp (S::com) ?P)›*) monoWS (*‹⟦is_quantum_predicate ?P; is_quantum_predicate ?Q; ?P ≤⇩L ?Q⟧ ⟹ wlp S ?P ≤⇩L wlp S ?Q›*) m (*‹measurement d (2::nat) (M::nat ⇒ complex mat)›*) qpP (*‹is_quantum_predicate (P::complex mat)›*) by auto then have "limit_mat (λk. (W k) * ρ) ((wlp_while M0 M1 (wlp S) P) * ρ) d" using mult_mat_limit (*‹⟦?B ∈ carrier_mat ?m ?m; limit_mat ?X ?A ?m⟧ ⟹ limit_mat (λk. ?X k * ?B) (?A * ?B) ?m›*) dr (*‹ρ ∈ carrier_mat d d›*) by auto then have lim1: "(λk. trace ((W k) * ρ)) ⇢ trace ((wlp_while M0 M1 (wlp S) P) * ρ)" using mat_trace_limit (*‹limit_mat ?g ?A ?d ⟹ (λn. trace (?g n)) ⇢ trace ?A›*) by auto have dD0kr: "D0 k ρ ∈ carrier_mat d d" for k unfolding D0_def (*goal: ‹denote_while_n M0 M1 DS k ρ ∈ carrier_mat d d›*) using denote_while_n_dim[OF dr dM0 dM1 pdor] (*‹(⋀ρ'::complex mat. ⟦ρ' ∈ carrier_mat d d; partial_density_operator ρ'⟧ ⟹ positive ((?DS::complex mat ⇒ complex mat) ρ') ∧ trace (?DS ρ') ≤ trace ρ' ∧ ?DS ρ' ∈ carrier_mat d d) ⟹ denote_while_n (M0::complex mat) (M1::complex mat) ?DS (?n::nat) (ρ::complex mat) ∈ carrier_mat d d›*) denote_positive_trace_dim[OF wcS, folded DS_def] (*‹⟦(?ρ::complex mat) ∈ carrier_mat d d; partial_density_operator ?ρ⟧ ⟹ positive ((DS::complex mat ⇒ complex mat) ?ρ) ∧ trace (DS ?ρ) ≤ trace ?ρ ∧ DS ?ρ ∈ carrier_mat d d›*) by auto then have "(P * (matrix_sum d (λk. D0 k ρ) (n))) = matrix_sum d (λk. P * (D0 k ρ)) n" for n using matrix_sum_distrib_left[OF dP] (*‹(⋀k. k < ?n ⟹ ?f k ∈ carrier_mat d d) ⟹ matrix_sum d (λk. P * ?f k) ?n = P * matrix_sum d ?f ?n›*) by auto moreover have "trace (matrix_sum d (λk. P * (D0 k ρ)) n) = (∑k=0..<n. trace (P * (D0 k ρ)))" for n using trace_matrix_sum_linear (*‹(⋀k. k < ?n ⟹ ?f k ∈ carrier_mat ?d ?d) ⟹ trace (matrix_sum ?d ?f ?n) = (∑k = 0..<?n. trace (?f k))›*) dD0kr (*‹D0 ?k ρ ∈ carrier_mat d d›*) dP (*‹P ∈ carrier_mat d d›*) by auto ultimately have eqPsD0kr: "trace (P * (matrix_sum d (λk. D0 k ρ) (n))) = (∑k=0..<n. trace (P * (D0 k ρ)))" for n by auto with limtrPm (*‹(λn. trace (P * matrix_sum d (λk. D0 k ρ) n)) ⇢ trace (P * denote (While M S) ρ)›*) have lim2: "(λk. (∑k=0..<k. trace (P * (D0 k ρ)))) ⇢ trace (P * (denote (While M S) ρ))" by auto have "trace (matrix_sum d (λk. D0 k ρ) (n)) = (∑k=0..<n. trace (D0 k ρ))" for n using trace_matrix_sum_linear (*‹(⋀k. k < ?n ⟹ ?f k ∈ carrier_mat ?d ?d) ⟹ trace (matrix_sum ?d ?f ?n) = (∑k = 0..<?n. trace (?f k))›*) dD0kr (*‹D0 ?k ρ ∈ carrier_mat d d›*) by auto with limtrDW (*‹(λn. trace (matrix_sum d (λk. D0 k ρ) n)) ⇢ trace (denote (While M S) ρ)›*) have lim3: "(λk. (∑k=0..<k. trace (D0 k ρ))) ⇢ trace (denote (While M S) ρ)" by auto have "(λk. (∑k=0..<k. trace (P * (D0 k ρ))) + trace ρ) ⇢ trace (P * (denote (While M S) ρ)) + trace ρ" using tendsto_add[of "λk. (∑k=0..<k. trace (P * (D0 k ρ)))"] (*‹⟦((λk. ∑k = 0..<k. trace (P * D0 k ρ)) ⤏ ?a) ?F; (?g ⤏ ?b) ?F⟧ ⟹ ((λx. (∑k = 0..<x. trace (P * D0 k ρ)) + ?g x) ⤏ ?a + ?b) ?F›*) lim2 (*‹(λk. ∑k = 0..<k. trace (P * D0 k ρ)) ⇢ trace (P * denote (While M S) ρ)›*) by auto then have "(λk. (∑k=0..<k. trace (P * (D0 k ρ))) + trace ρ - (∑k=0..<k. trace (D0 k ρ))) ⇢ trace (P * (denote (While M S) ρ)) + trace ρ - trace (denote (While M S) ρ)" using tendsto_diff[of _ _ _ "λk. (∑k=0..<k. trace (D0 k ρ))"] (*‹⟦(?f ⤏ ?a) ?F; ((λk. ∑k = 0..<k. trace (D0 k ρ)) ⤏ ?b) ?F⟧ ⟹ ((λx. ?f x - (∑k = 0..<x. trace (D0 k ρ))) ⤏ ?a - ?b) ?F›*) lim3 (*‹(λk. ∑k = 0..<k. trace (D0 k ρ)) ⇢ trace (denote (While M S) ρ)›*) by auto then have lim4: "(λk. trace ((W k) * ρ)) ⇢ trace (P * (denote (While M S) ρ)) + trace ρ - trace (denote (While M S) ρ)" using eqk[OF dsr] (*‹trace (W ?k * ρ) = (∑k = 0..<?k. trace (P * D0 k ρ)) + trace ρ - (∑k = 0..<?k. trace (D0 k ρ))›*) by auto then have "trace ((wlp_while M0 M1 (wlp S) P) * ρ) = trace (P * (denote (While M S) ρ)) + trace ρ - trace (denote (While M S) ρ)" using eqk[OF dsr] (*‹trace (W ?k * ρ) = (∑k = 0..<?k. trace (P * D0 k ρ)) + trace ρ - (∑k = 0..<?k. trace (D0 k ρ))›*) tendsto_unique[OF _ lim1 lim4] (*‹sequentially ≠ bot ⟹ trace (wlp_while (M0::complex mat) (M1::complex mat) (wlp (S::com)) (P::complex mat) * (ρ::complex mat)) = trace (P * denote (While (M::nat ⇒ complex mat) S) ρ) + trace ρ - trace (denote (While M S) ρ)›*) by auto } then show "?case" (*goal: ‹∀ρ∈density_states. trace (wlp (While M S) P * ρ) = trace (P * denote (While M S) ρ) + trace ρ - trace (denote (While M S) ρ)›*) unfolding M0_def M1_def DS_def wlp.simps (*goal: ‹∀ρ::complex mat∈density_states. trace (wlp_while ((M::nat ⇒ complex mat) (0::nat)) (M (1::nat)) (wlp (S::com)) (P::complex mat) * ρ) = trace (P * denote (While M S) ρ) + trace ρ - trace (denote (While M S) ρ)›*) by auto qed lemma denote_while_split: assumes wc: "well_com (While M S)" and dsr: "ρ ∈ density_states" shows "denote (While M S) ρ = (M 0) * ρ * adjoint (M 0) + denote (While M S) (denote S (M 1 * ρ * adjoint (M 1)))" proof (-) (*goal: ‹denote (While M S) ρ = M 0 * ρ * adjoint (M 0) + denote (While M S) (denote S (M 1 * ρ * adjoint (M 1)))›*) have m: "measurement d 2 M" using wc (*‹well_com (While M S)›*) by auto have wcs: "well_com S" using wc (*‹well_com (While (M::nat ⇒ complex mat) (S::com))›*) by auto define M0 where "M0 = M 0" define M1 where "M1 = M 1" have dM0: "M0 ∈ carrier_mat d d" and dM1: "M1 ∈ carrier_mat d d" using m (*‹measurement d 2 M›*) measurement_def (*‹measurement (?d::nat) (?n::nat) (?M::nat ⇒ complex mat) = ((∀j<?n. ?M j ∈ carrier_mat ?d ?d) ∧ matrix_sum ?d (λj::nat. adjoint (?M j) * ?M j) ?n = 1⇩m ?d)›*) M0_def (*‹M0 = M 0›*) M1_def (*‹M1 = M 1›*) apply - (*goals: 1. ‹⟦measurement d 2 M; ⋀d n M. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj. adjoint (M j) * M j) n = 1⇩m d); M0 = M 0; M1 = M 1⟧ ⟹ M0 ∈ carrier_mat d d› 2. ‹⟦measurement d 2 M; ⋀d n M. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj. adjoint (M j) * M j) n = 1⇩m d); M0 = M 0; M1 = M 1⟧ ⟹ M1 ∈ carrier_mat d d› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have M1leq: "adjoint M1 * M1 ≤⇩L 1⇩m d" using measurement_le_one_mat (*‹⟦measurement ?d ?n ?f; ?j < ?n⟧ ⟹ adjoint (?f ?j) * ?f ?j ≤⇩L 1⇩m ?d›*) m (*‹measurement d 2 M›*) M1_def (*‹(M1::complex mat) = (M::nat ⇒ complex mat) (1::nat)›*) by auto define DS where "DS = denote S" define D0 where "D0 = denote_while_n M0 M1 DS" define D1 where "D1 = denote_while_n_comp M0 M1 DS" define D where "D = denote_while_n_iter M0 M1 DS" define DW where "DW ρ = denote (While M S) ρ" for ρ { fix ρ assume dsr: "ρ ∈ density_states" (*‹(ρ::complex mat) ∈ density_states›*) then have dr: "ρ ∈ carrier_mat d d" and pdor: "partial_density_operator ρ" using density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) apply - (*goals: 1. ‹⟦ρ ∈ density_states; density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}⟧ ⟹ ρ ∈ carrier_mat d d› 2. ‹⟦ρ ∈ density_states; density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}⟧ ⟹ partial_density_operator ρ› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have pdoDkr: "⋀k. partial_density_operator (D k ρ)" unfolding D_def (*goal: ‹⋀k::nat. partial_density_operator (denote_while_n_iter (M0::complex mat) (M1::complex mat) (DS::complex mat ⇒ complex mat) k (ρ::complex mat))›*) using pdo_denote_while_n_iter[OF dr pdor dM1 M1leq] (*‹⟦⋀ρ. ρ ∈ carrier_mat d d ∧ partial_density_operator ρ ⟹ partial_density_operator (?DS ρ); ⋀ρ. ρ ∈ carrier_mat d d ∧ partial_density_operator ρ ⟹ ?DS ρ ∈ carrier_mat d d⟧ ⟹ partial_density_operator (denote_while_n_iter ?M0.0 M1 ?DS ?n ρ)›*) denote_partial_density_operator[OF wcs] (*‹⟦partial_density_operator ?ρ; ?ρ ∈ carrier_mat d d⟧ ⟹ partial_density_operator (denote S ?ρ)›*) denote_dim[OF wcs, folded DS_def] (*‹⟦(?ρ::complex mat) ∈ carrier_mat d d; partial_density_operator ?ρ⟧ ⟹ (DS::complex mat ⇒ complex mat) ?ρ ∈ carrier_mat d d›*) apply (fold DS_def) (*goal: ‹⋀k. partial_density_operator (denote_while_n_iter M0 M1 DS k ρ)›*) by auto then have pDkr: "⋀k. positive (D k ρ)" unfolding partial_density_operator_def (*goal: ‹⋀k. positive (D k ρ)›*) by auto have dDkr: "⋀k. D k ρ ∈ carrier_mat d d" using denote_while_n_iter_dim[OF dr pdor dM1 M1leq denote_dim_pdo [ OF wcs , folded DS_def ], of id M0, simplified, folded D_def] (*‹(D::nat ⇒ complex mat ⇒ complex mat) (?n::nat) (ρ::complex mat) ∈ carrier_mat d d ∧ partial_density_operator (D ?n ρ)›*) by auto then have dD0kr: "⋀k. D0 k ρ ∈ carrier_mat d d" unfolding D0_def denote_while_n.simps (*goal: ‹⋀k. M0 * denote_while_n_iter M0 M1 DS k ρ * adjoint M0 ∈ carrier_mat d d›*) apply (fold D_def) (*goal: ‹⋀k. M0 * denote_while_n_iter M0 M1 DS k ρ * adjoint M0 ∈ carrier_mat d d›*) using dM0 (*‹M0 ∈ carrier_mat d d›*) by auto } note dD0k = this (*‹?ρ'3 ∈ density_states ⟹ D0 ?k ?ρ'3 ∈ carrier_mat d d›*) have "matrix_sum d (λk. D0 k ρ) k ∈ carrier_mat d d" if dsr: "ρ ∈ density_states" for ρ and k using matrix_sum_dim[OF dD0k, of _ "λk. ρ" id, OF dsr] (*‹matrix_sum d (λk::nat. (D0::nat ⇒ complex mat ⇒ complex mat) (id k) (ρ::complex mat)) (?n::nat) ∈ carrier_mat d d›*) dsr (*‹(ρ::complex mat) ∈ density_states›*) by auto { fix k have "matrix_sum d (λk. D0 k ρ) (Suc k) = (D0 0 ρ) + matrix_sum d (λk. D0 (Suc k) ρ) k" using matrix_sum_shift_Suc[of _ "λk. D0 k ρ"] (*‹(⋀k. k < Suc ?n ⟹ D0 k ρ ∈ carrier_mat ?d ?d) ⟹ matrix_sum ?d (λk. D0 k ρ) (Suc ?n) = D0 0 ρ + matrix_sum ?d (λk. D0 (Suc k) ρ) ?n›*) dD0k[OF dsr] (*‹D0 ?k ρ ∈ carrier_mat d d›*) by fastforce also (*calculation: ‹matrix_sum d (λk. D0 k ρ) (Suc k) = D0 0 ρ + matrix_sum d (λk. D0 (Suc k) ρ) k›*) have "… = M0 * ρ * adjoint M0 + matrix_sum d (λk. D0 k (DS (M1 * ρ * adjoint M1))) k" unfolding D0_def (*goal: ‹denote_while_n M0 M1 DS 0 ρ + matrix_sum d (λk. denote_while_n M0 M1 DS (Suc k) ρ) k = M0 * ρ * adjoint M0 + matrix_sum d (λk. denote_while_n M0 M1 DS k (DS (M1 * ρ * adjoint M1))) k›*) by auto finally (*calculation: ‹matrix_sum d (λk. D0 k ρ) (Suc k) = M0 * ρ * adjoint M0 + matrix_sum d (λk. D0 k (DS (M1 * ρ * adjoint M1))) k›*) have "matrix_sum d (λk. D0 k ρ) (Suc k) = M0 * ρ * adjoint M0 + matrix_sum d (λk. D0 k (DS (M1 * ρ * adjoint M1))) k" . } note eqk = this (*‹matrix_sum d (λk. D0 k ρ) (Suc ?k2) = M0 * ρ * adjoint M0 + matrix_sum d (λk. D0 k (DS (M1 * ρ * adjoint M1))) ?k2›*) have dr: "ρ ∈ carrier_mat d d" and pdor: "partial_density_operator ρ" using density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) dsr (*‹ρ ∈ density_states›*) apply - (*goals: 1. ‹⟦density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}; ρ ∈ density_states⟧ ⟹ ρ ∈ carrier_mat d d› 2. ‹⟦density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}; ρ ∈ density_states⟧ ⟹ partial_density_operator ρ› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . then have "M1 * ρ * adjoint M1 ∈ carrier_mat d d" and "partial_density_operator (M1 * ρ * adjoint M1)" using dM1 (*‹M1 ∈ carrier_mat d d›*) dr (*‹ρ ∈ carrier_mat d d›*) pdo_close_under_measurement[OF dM1 dr pdor M1leq] (*‹partial_density_operator (M1 * ρ * adjoint M1)›*) apply - (*goals: 1. ‹⟦ρ ∈ carrier_mat d d; partial_density_operator ρ; M1 ∈ carrier_mat d d; ρ ∈ carrier_mat d d; partial_density_operator (M1 * ρ * adjoint M1)⟧ ⟹ M1 * ρ * adjoint M1 ∈ carrier_mat d d› 2. ‹⟦ρ ∈ carrier_mat d d; partial_density_operator ρ; M1 ∈ carrier_mat d d; ρ ∈ carrier_mat d d; partial_density_operator (M1 * ρ * adjoint M1)⟧ ⟹ partial_density_operator (M1 * ρ * adjoint M1)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . then have dSM1r: "(DS (M1 * ρ * adjoint M1)) ∈ carrier_mat d d" and pdoSM1r: "partial_density_operator (DS (M1 * ρ * adjoint M1))" unfolding DS_def (*goals: 1. ‹denote S (M1 * ρ * adjoint M1) ∈ carrier_mat d d› 2. ‹partial_density_operator (denote S (M1 * ρ * adjoint M1))›*) using denote_dim_pdo[OF wcs] (*‹⟦?ρ ∈ carrier_mat d d; partial_density_operator ?ρ⟧ ⟹ denote S ?ρ ∈ carrier_mat d d ∧ partial_density_operator (denote S ?ρ)›*) apply - (*goals: 1. ‹⟦M1 * ρ * adjoint M1 ∈ carrier_mat d d; partial_density_operator (M1 * ρ * adjoint M1); ⋀ρ. ⟦ρ ∈ carrier_mat d d; partial_density_operator ρ⟧ ⟹ denote S ρ ∈ carrier_mat d d ∧ partial_density_operator (denote S ρ)⟧ ⟹ denote S (M1 * ρ * adjoint M1) ∈ carrier_mat d d› 2. ‹⟦M1 * ρ * adjoint M1 ∈ carrier_mat d d; partial_density_operator (M1 * ρ * adjoint M1); ⋀ρ. ⟦ρ ∈ carrier_mat d d; partial_density_operator ρ⟧ ⟹ denote S ρ ∈ carrier_mat d d ∧ partial_density_operator (denote S ρ)⟧ ⟹ partial_density_operator (denote S (M1 * ρ * adjoint M1))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have "limit_mat (matrix_sum d (λk. D0 k ρ)) (DW ρ) d" unfolding M0_def M1_def D0_def DS_def DW_def (*goal: ‹limit_mat (matrix_sum d (λk. denote_while_n (M 0) (M 1) (denote S) k ρ)) (denote (While M S) ρ) d›*) using limit_mat_denote_while_n[OF wc dr pdor] (*‹limit_mat (matrix_sum d (λk. denote_while_n (M 0) (M 1) (denote S) k ρ)) (denote (While M S) ρ) d›*) by auto then have liml: "limit_mat (λk. matrix_sum d (λk. D0 k ρ) (Suc k)) (DW ρ) d" using limit_mat_ignore_initial_segment[of "matrix_sum d (λk. D0 k ρ)" "DW ρ" d 1] (*‹limit_mat (matrix_sum d (λk. D0 k ρ)) (DW ρ) d ⟹ limit_mat (λn. matrix_sum d (λk. D0 k ρ) (n + 1)) (DW ρ) d›*) by auto have dM0r: "M0 * ρ * adjoint M0 ∈ carrier_mat d d" using dM0 (*‹M0 ∈ carrier_mat d d›*) dr (*‹ρ ∈ carrier_mat d d›*) by fastforce have "limit_mat (matrix_sum d (λk. D0 k (DS (M1 * ρ * adjoint M1)))) (DW (DS (M1 * ρ * adjoint M1))) d" using limit_mat_denote_while_n[OF wc dSM1r pdoSM1r] (*‹limit_mat (matrix_sum d (λk::nat. denote_while_n ((M::nat ⇒ complex mat) (0::nat)) (M (1::nat)) (denote (S::com)) k ((DS::complex mat ⇒ complex mat) ((M1::complex mat) * (ρ::complex mat) * adjoint M1)))) (denote (While M S) (DS (M1 * ρ * adjoint M1))) d›*) unfolding M0_def M1_def D0_def DS_def DW_def (*goal: ‹limit_mat (matrix_sum d (λk. denote_while_n (M 0) (M 1) (denote S) k (denote S (M 1 * ρ * adjoint (M 1))))) (denote (While M S) (denote S (M 1 * ρ * adjoint (M 1)))) d›*) by auto then have limr: "limit_mat (mat_add_seq (M0 * ρ * adjoint M0) (matrix_sum d (λk. D0 k (DS (M1 * ρ * adjoint M1))))) (M0 * ρ * adjoint M0 + (DW (DS (M1 * ρ * adjoint M1)))) d" using mat_add_limit[OF dM0r] (*‹limit_mat ?X ?A d ⟹ limit_mat (mat_add_seq (M0 * ρ * adjoint M0) ?X) (M0 * ρ * adjoint M0 + ?A) d›*) by auto moreover have "(λk. matrix_sum d (λk. D0 k ρ) (Suc k)) = (mat_add_seq (M0 * ρ * adjoint M0) (matrix_sum d (λk. D0 k (DS (M1 * ρ * adjoint M1)))))" using eqk (*‹matrix_sum d (λk. D0 k ρ) (Suc ?k2) = M0 * ρ * adjoint M0 + matrix_sum d (λk. D0 k (DS (M1 * ρ * adjoint M1))) ?k2›*) mat_add_seq_def (*‹mat_add_seq ?A ?X = (λn. ?A + ?X n)›*) by auto ultimately have "limit_mat (λk. matrix_sum d (λk. D0 k ρ) (Suc k)) (M0 * ρ * adjoint M0 + (DW (DS (M1 * ρ * adjoint M1)))) d" by auto with liml (*‹limit_mat (λk. matrix_sum d (λk. D0 k ρ) (Suc k)) (DW ρ) d›*) limit_mat_unique (*‹⟦limit_mat ?X ?A ?m; limit_mat ?X ?B ?m⟧ ⟹ ?A = ?B›*) have "DW ρ = (M0 * ρ * adjoint M0 + (DW (DS (M1 * ρ * adjoint M1))))" by auto then show "?thesis" (*goal: ‹denote (While M S) ρ = M 0 * ρ * adjoint (M 0) + denote (While M S) (denote S (M 1 * ρ * adjoint (M 1)))›*) unfolding DW_def M0_def M1_def DS_def (*goal: ‹denote (While M S) ρ = M 0 * ρ * adjoint (M 0) + denote (While M S) (denote S (M 1 * ρ * adjoint (M 1)))›*) by auto qed lemma wlp_while_split: assumes wc: "well_com (While M S)" and qpP: "is_quantum_predicate P" shows "wlp (While M S) P = adjoint (M 0) * P * (M 0) + adjoint (M 1) * (wlp S (wlp (While M S) P)) * (M 1)" proof (-) (*goal: ‹wlp (While M S) P = adjoint (M 0) * P * M 0 + adjoint (M 1) * wlp S (wlp (While M S) P) * M 1›*) have m: "measurement d 2 M" using wc (*‹well_com (While M S)›*) by auto have wcs: "well_com S" using wc (*‹well_com (While M S)›*) by auto define M0 where "M0 = M 0" define M1 where "M1 = M 1" have dM0: "M0 ∈ carrier_mat d d" and dM1: "M1 ∈ carrier_mat d d" using m (*‹measurement d 2 M›*) measurement_def (*‹measurement ?d ?n ?M = ((∀j<?n. ?M j ∈ carrier_mat ?d ?d) ∧ matrix_sum ?d (λj. adjoint (?M j) * ?M j) ?n = 1⇩m ?d)›*) M0_def (*‹M0 = M 0›*) M1_def (*‹M1 = M 1›*) apply - (*goals: 1. ‹⟦measurement d 2 M; ⋀d n M. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj. adjoint (M j) * M j) n = 1⇩m d); M0 = M 0; M1 = M 1⟧ ⟹ M0 ∈ carrier_mat d d› 2. ‹⟦measurement d 2 M; ⋀d n M. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj. adjoint (M j) * M j) n = 1⇩m d); M0 = M 0; M1 = M 1⟧ ⟹ M1 ∈ carrier_mat d d› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have M1leq: "adjoint M1 * M1 ≤⇩L 1⇩m d" using measurement_le_one_mat (*‹⟦measurement (?d::nat) (?n::nat) (?f::nat ⇒ complex mat); (?j::nat) < ?n⟧ ⟹ adjoint (?f ?j) * ?f ?j ≤⇩L 1⇩m ?d›*) m (*‹measurement d 2 M›*) M1_def (*‹M1 = M 1›*) by auto define DS where "DS = denote S" define D0 where "D0 = denote_while_n M0 M1 DS" define D1 where "D1 = denote_while_n_comp M0 M1 DS" define D where "D = denote_while_n_iter M0 M1 DS" define DW where "DW ρ = denote (While M S) ρ" for ρ have dP: "P ∈ carrier_mat d d" using qpP (*‹is_quantum_predicate P›*) is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto have qpWP: "is_quantum_predicate (wlp (While M S) P)" using qpP (*‹is_quantum_predicate P›*) wc (*‹well_com (While (M::nat ⇒ complex mat) (S::com))›*) wlp_close[OF wc qpP] (*‹is_quantum_predicate (wlp (While (M::nat ⇒ complex mat) (S::com)) (P::complex mat))›*) by auto then have "is_quantum_predicate (wlp S (wlp (While M S) P))" using wc (*‹well_com (While (M::nat ⇒ complex mat) (S::com))›*) wlp_close[OF wcs] (*‹is_quantum_predicate ?P ⟹ is_quantum_predicate (wlp S ?P)›*) by auto then have dWWP: "(wlp S (wlp (While M S) P)) ∈ carrier_mat d d" using is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto have dWP: "(wlp (While M S) P) ∈ carrier_mat d d" using qpWP (*‹is_quantum_predicate (wlp (While M S) P)›*) is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto { fix ρ assume dsr: "ρ ∈ density_states" (*‹(ρ::complex mat) ∈ density_states›*) then have dr: "ρ ∈ carrier_mat d d" and pdor: "partial_density_operator ρ" using density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) apply - (*goals: 1. ‹⟦ρ ∈ density_states; density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}⟧ ⟹ ρ ∈ carrier_mat d d› 2. ‹⟦ρ ∈ density_states; density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}⟧ ⟹ partial_density_operator ρ› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have dsM1r: "M1 * ρ * adjoint M1 ∈ density_states" unfolding density_states_def (*goal: ‹M1 * ρ * adjoint M1 ∈ {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) using pdo_close_under_measurement[OF dM1 dr pdor] (*‹adjoint (M1::complex mat) * M1 ≤⇩L 1⇩m d ⟹ partial_density_operator (M1 * (ρ::complex mat) * adjoint M1)›*) M1leq (*‹adjoint M1 * M1 ≤⇩L 1⇩m d›*) dM1 (*‹M1 ∈ carrier_mat d d›*) dr (*‹ρ ∈ carrier_mat d d›*) by fastforce then have dsDSM1r: "DS (M1 * ρ * adjoint M1) ∈ density_states" unfolding density_states_def DS_def (*goal: ‹denote S (M1 * ρ * adjoint M1) ∈ {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) using denote_dim_pdo[OF wcs] (*‹⟦(?ρ::complex mat) ∈ carrier_mat d d; partial_density_operator ?ρ⟧ ⟹ denote (S::com) ?ρ ∈ carrier_mat d d ∧ partial_density_operator (denote S ?ρ)›*) by auto have dM0r: "M0 * ρ * adjoint M0 ∈ carrier_mat d d" using dM0 (*‹M0 ∈ carrier_mat d d›*) dr (*‹ρ ∈ carrier_mat d d›*) by fastforce have dDWDSM1r: "DW (DS (M1 * ρ * adjoint M1)) ∈ carrier_mat d d" unfolding DW_def (*goal: ‹denote (While M S) (DS (M1 * ρ * adjoint M1)) ∈ carrier_mat d d›*) using denote_dim[OF wc] (*‹⟦?ρ ∈ carrier_mat d d; partial_density_operator ?ρ⟧ ⟹ denote (While M S) ?ρ ∈ carrier_mat d d›*) dsDSM1r (*‹DS (M1 * ρ * adjoint M1) ∈ density_states›*) density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) by auto have eq2: "trace ((wlp (While M S) P) * DS (M1 * ρ * adjoint M1)) = trace (P * (DW (DS (M1 * ρ * adjoint M1)))) + trace (DS (M1 * ρ * adjoint M1)) - trace (DW (DS (M1 * ρ * adjoint M1)))" unfolding DW_def (*goal: ‹trace (wlp (While M S) P * DS (M1 * ρ * adjoint M1)) = trace (P * denote (While M S) (DS (M1 * ρ * adjoint M1))) + trace (DS (M1 * ρ * adjoint M1)) - trace (denote (While M S) (DS (M1 * ρ * adjoint M1)))›*) using wlp_soundness[OF wc qpP] (*‹∀ρ∈density_states. trace (wlp (While M S) P * ρ) = trace (P * denote (While M S) ρ) + trace ρ - trace (denote (While M S) ρ)›*) dsDSM1r (*‹DS (M1 * ρ * adjoint M1) ∈ density_states›*) by auto have eq3: "trace (M1 * ρ * adjoint M1) = trace ρ - trace (M0 * ρ * adjoint M0)" unfolding M0_def M1_def (*goal: ‹trace (M 1 * ρ * adjoint (M 1)) = trace ρ - trace (M 0 * ρ * adjoint (M 0))›*) using m (*‹measurement d (2::nat) (M::nat ⇒ complex mat)›*) trace_measurement2[OF m dr] (*‹trace (M 0 * ρ * adjoint (M 0)) + trace (M 1 * ρ * adjoint (M 1)) = trace ρ›*) dr (*‹ρ ∈ carrier_mat d d›*) by (simp add: algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 23 facts*)) have "trace (adjoint M1 * (wlp S (wlp (While M S) P)) * M1 * ρ) = trace ((wlp S (wlp (While M S) P)) * (M1 * ρ * adjoint M1))" using dWWP (*‹wlp S (wlp (While M S) P) ∈ carrier_mat d d›*) dM1 (*‹M1 ∈ carrier_mat d d›*) dr (*‹ρ ∈ carrier_mat d d›*) by (mat_assoc d) also (*calculation: ‹trace (adjoint M1 * wlp S (wlp (While M S) P) * M1 * ρ) = trace (wlp S (wlp (While M S) P) * (M1 * ρ * adjoint M1))›*) have "… = trace ((wlp (While M S) P) * DS (M1 * ρ * adjoint M1)) + trace (M1 * ρ * adjoint M1) - trace (DS (M1 * ρ * adjoint M1))" unfolding DS_def (*goal: ‹trace (wlp S (wlp (While M S) P) * (M1 * ρ * adjoint M1)) = trace (wlp (While M S) P * denote S (M1 * ρ * adjoint M1)) + trace (M1 * ρ * adjoint M1) - trace (denote S (M1 * ρ * adjoint M1))›*) using wlp_soundness[OF wcs qpWP] (*‹∀ρ∈density_states. trace (wlp S (wlp (While M S) P) * ρ) = trace (wlp (While M S) P * denote S ρ) + trace ρ - trace (denote S ρ)›*) dsM1r (*‹M1 * ρ * adjoint M1 ∈ density_states›*) by auto also (*calculation: ‹trace (adjoint M1 * wlp S (wlp (While M S) P) * M1 * ρ) = trace (wlp (While M S) P * DS (M1 * ρ * adjoint M1)) + trace (M1 * ρ * adjoint M1) - trace (DS (M1 * ρ * adjoint M1))›*) have "… = trace (P * (DW (DS (M1 * ρ * adjoint M1)))) + trace (M1 * ρ * adjoint M1) - trace (DW (DS (M1 * ρ * adjoint M1)))" using eq2 (*‹trace (wlp (While M S) P * DS (M1 * ρ * adjoint M1)) = trace (P * DW (DS (M1 * ρ * adjoint M1))) + trace (DS (M1 * ρ * adjoint M1)) - trace (DW (DS (M1 * ρ * adjoint M1)))›*) by auto also (*calculation: ‹trace (adjoint M1 * wlp S (wlp (While M S) P) * M1 * ρ) = trace (P * DW (DS (M1 * ρ * adjoint M1))) + trace (M1 * ρ * adjoint M1) - trace (DW (DS (M1 * ρ * adjoint M1)))›*) have "… = trace (P * (DW (DS (M1 * ρ * adjoint M1)))) + trace ρ - (trace (M0 * ρ * adjoint M0) + trace (DW (DS (M1 * ρ * adjoint M1))))" using eq3 (*‹trace ((M1::complex mat) * (ρ::complex mat) * adjoint M1) = trace ρ - trace ((M0::complex mat) * ρ * adjoint M0)›*) by auto finally (*calculation: ‹trace (adjoint M1 * wlp S (wlp (While M S) P) * M1 * ρ) = trace (P * DW (DS (M1 * ρ * adjoint M1))) + trace ρ - (trace (M0 * ρ * adjoint M0) + trace (DW (DS (M1 * ρ * adjoint M1))))›*) have eq4: "trace (adjoint M1 * (wlp S (wlp (While M S) P)) * M1 * ρ) = trace (P * (DW (DS (M1 * ρ * adjoint M1)))) + trace ρ - (trace (M0 * ρ * adjoint M0) + trace (DW (DS (M1 * ρ * adjoint M1))))" . have "trace (adjoint M0 * P * M0 * ρ) + trace (P * (DW (DS (M1 * ρ * adjoint M1)))) = trace (P * ((M0 * ρ * adjoint M0) + (DW (DS (M1 * ρ * adjoint M1)))))" using dP (*‹P ∈ carrier_mat d d›*) dr (*‹ρ ∈ carrier_mat d d›*) dM0 (*‹M0 ∈ carrier_mat d d›*) dDWDSM1r (*‹DW (DS (M1 * ρ * adjoint M1)) ∈ carrier_mat d d›*) by (mat_assoc d) also (*calculation: ‹trace (adjoint M0 * P * M0 * ρ) + trace (P * DW (DS (M1 * ρ * adjoint M1))) = trace (P * (M0 * ρ * adjoint M0 + DW (DS (M1 * ρ * adjoint M1))))›*) have "… = trace (P * (DW ρ))" unfolding DW_def M0_def M1_def DS_def (*goal: ‹trace (P * (M 0 * ρ * adjoint (M 0) + denote (While M S) (denote S (M 1 * ρ * adjoint (M 1))))) = trace (P * denote (While M S) ρ)›*) using denote_while_split[OF wc dsr] (*‹denote (While M S) ρ = M 0 * ρ * adjoint (M 0) + denote (While M S) (denote S (M 1 * ρ * adjoint (M 1)))›*) by auto finally (*calculation: ‹trace (adjoint M0 * P * M0 * ρ) + trace (P * DW (DS (M1 * ρ * adjoint M1))) = trace (P * DW ρ)›*) have eq5: "trace (adjoint M0 * P * M0 * ρ) + trace (P * (DW (DS (M1 * ρ * adjoint M1)))) = trace (P * (DW ρ))" . have "trace (M0 * ρ * adjoint M0) + trace (DW (DS (M1 * ρ * adjoint M1))) = trace (M0 * ρ * adjoint M0 + (DW (DS (M1 * ρ * adjoint M1))))" using dr (*‹(ρ::complex mat) ∈ carrier_mat d d›*) dM0 (*‹(M0::complex mat) ∈ carrier_mat d d›*) dDWDSM1r (*‹(DW::complex mat ⇒ complex mat) ((DS::complex mat ⇒ complex mat) ((M1::complex mat) * (ρ::complex mat) * adjoint M1)) ∈ carrier_mat d d›*) by (mat_assoc d) also (*calculation: ‹trace ((M0::complex mat) * (ρ::complex mat) * adjoint M0) + trace ((DW::complex mat ⇒ complex mat) ((DS::complex mat ⇒ complex mat) ((M1::complex mat) * ρ * adjoint M1))) = trace (M0 * ρ * adjoint M0 + DW (DS (M1 * ρ * adjoint M1)))›*) have "… = trace (DW ρ)" unfolding DW_def DS_def M0_def M1_def denote_while_split[OF wc dsr] (*goal: ‹trace (M 0 * ρ * adjoint (M 0) + denote (While M S) (denote S (M 1 * ρ * adjoint (M 1)))) = trace (M 0 * ρ * adjoint (M 0) + denote (While M S) (denote S (M 1 * ρ * adjoint (M 1))))›*) by auto finally (*calculation: ‹trace ((M0::complex mat) * (ρ::complex mat) * adjoint M0) + trace ((DW::complex mat ⇒ complex mat) ((DS::complex mat ⇒ complex mat) ((M1::complex mat) * ρ * adjoint M1))) = trace (DW ρ)›*) have eq6: "trace (M0 * ρ * adjoint M0) + trace (DW (DS (M1 * ρ * adjoint M1))) = trace (DW ρ)" . from eq5 (*‹trace (adjoint M0 * P * M0 * ρ) + trace (P * DW (DS (M1 * ρ * adjoint M1))) = trace (P * DW ρ)›*) eq4 (*‹trace (adjoint M1 * wlp S (wlp (While M S) P) * M1 * ρ) = trace (P * DW (DS (M1 * ρ * adjoint M1))) + trace ρ - (trace (M0 * ρ * adjoint M0) + trace (DW (DS (M1 * ρ * adjoint M1))))›*) eq6 (*‹trace (M0 * ρ * adjoint M0) + trace (DW (DS (M1 * ρ * adjoint M1))) = trace (DW ρ)›*) have eq7: "trace (adjoint M0 * P * M0 * ρ) + trace (adjoint M1 * wlp S (wlp (While M S) P) * M1 * ρ) = trace (P * DW ρ) + trace ρ - trace (DW ρ)" by auto have eq8: "trace (adjoint M0 * P * M0 * ρ) + trace (adjoint M1 * wlp S (wlp (While M S) P) * M1 * ρ) = trace ((adjoint M0 * P * M0 + adjoint M1 * wlp S (wlp (While M S) P) * M1) * ρ)" using dM0 (*‹M0 ∈ carrier_mat d d›*) dM1 (*‹(M1::complex mat) ∈ carrier_mat d d›*) dr (*‹(ρ::complex mat) ∈ carrier_mat d d›*) dP (*‹P ∈ carrier_mat d d›*) dWWP (*‹wlp S (wlp (While M S) P) ∈ carrier_mat d d›*) by (mat_assoc d) from eq7 (*‹trace (adjoint M0 * P * M0 * ρ) + trace (adjoint M1 * wlp S (wlp (While M S) P) * M1 * ρ) = trace (P * DW ρ) + trace ρ - trace (DW ρ)›*) eq8 (*‹trace (adjoint M0 * P * M0 * ρ) + trace (adjoint M1 * wlp S (wlp (While M S) P) * M1 * ρ) = trace ((adjoint M0 * P * M0 + adjoint M1 * wlp S (wlp (While M S) P) * M1) * ρ)›*) have eq9: "trace ((adjoint M0 * P * M0 + adjoint M1 * wlp S (wlp (While M S) P) * M1) * ρ) = trace (P * DW ρ) + trace ρ - trace (DW ρ)" by auto have eq10: "trace ((wlp (While M S) P) * ρ) = trace (P * DW ρ) + trace ρ - trace (DW ρ)" unfolding DW_def (*goal: ‹trace (wlp (While (M::nat ⇒ complex mat) (S::com)) (P::complex mat) * (ρ::complex mat)) = trace (P * denote (While M S) ρ) + trace ρ - trace (denote (While M S) ρ)›*) using wlp_soundness[OF wc qpP] (*‹∀ρ∈density_states. trace (wlp (While M S) P * ρ) = trace (P * denote (While M S) ρ) + trace ρ - trace (denote (While M S) ρ)›*) dsr (*‹ρ ∈ density_states›*) by auto with eq9 (*‹trace ((adjoint M0 * P * M0 + adjoint M1 * wlp S (wlp (While M S) P) * M1) * ρ) = trace (P * DW ρ) + trace ρ - trace (DW ρ)›*) have "trace ((wlp (While M S) P) * ρ) = trace ((adjoint M0 * P * M0 + adjoint M1 * wlp S (wlp (While M S) P) * M1) * ρ)" by auto } then have "(wlp (While M S) P) = (adjoint M0 * P * M0 + adjoint M1 * wlp S (wlp (While M S) P) * M1)" using trace_pdo_eq_imp_eq[OF dWP, of "adjoint M0 * P * M0 + adjoint M1 * wlp S (wlp (While M S) P) * M1"] (*‹⟦adjoint M0 * P * M0 + adjoint M1 * wlp S (wlp (While M S) P) * M1 ∈ carrier_mat d d; ⋀ρ. ⟦ρ ∈ carrier_mat d d; partial_density_operator ρ⟧ ⟹ trace (wlp (While M S) P * ρ) = trace ((adjoint M0 * P * M0 + adjoint M1 * wlp S (wlp (While M S) P) * M1) * ρ)⟧ ⟹ wlp (While M S) P = adjoint M0 * P * M0 + adjoint M1 * wlp S (wlp (While M S) P) * M1›*) dM0 (*‹M0 ∈ carrier_mat d d›*) dP (*‹P ∈ carrier_mat d d›*) dM1 (*‹M1 ∈ carrier_mat d d›*) dWWP (*‹wlp S (wlp (While M S) P) ∈ carrier_mat d d›*) density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) by fastforce then show "?thesis" (*goal: ‹wlp (While M S) P = adjoint (M 0) * P * M 0 + adjoint (M 1) * wlp S (wlp (While M S) P) * M 1›*) using M0_def (*‹(M0::complex mat) = (M::nat ⇒ complex mat) (0::nat)›*) M1_def (*‹M1 = M 1›*) by auto qed lemma wlp_is_weakest_liberal_precondition: assumes "well_com S" and "is_quantum_predicate P" shows "is_weakest_liberal_precondition (wlp S P) S P" unfolding is_weakest_liberal_precondition_def (*goal: ‹is_quantum_predicate (wlp S P) ∧ ⊨⇩p {wlp S P} S {P} ∧ (∀Q. is_quantum_predicate Q ⟶ ⊨⇩p {Q} S {P} ⟶ Q ≤⇩L wlp S P)›*) proof (auto) (*goals: 1. ‹is_quantum_predicate (wlp S P)› 2. ‹⊨⇩p {wlp S P} S {P}› 3. ‹⋀Q. ⟦is_quantum_predicate Q; ⊨⇩p {Q} S {P}⟧ ⟹ Q ≤⇩L wlp S P›*) show qpWP: "is_quantum_predicate (wlp S P)" using wlp_close (*‹⟦well_com ?S; is_quantum_predicate ?P⟧ ⟹ is_quantum_predicate (wlp ?S ?P)›*) assms (*‹well_com S› ‹is_quantum_predicate P›*) by auto have eq: "trace (wlp S P * ρ) = trace (P * (denote S ρ)) + trace ρ - trace (denote S ρ)" if dsr: "ρ ∈ density_states" for ρ using wlp_soundness (*‹⟦well_com ?S; is_quantum_predicate ?P⟧ ⟹ ∀ρ∈density_states. trace (wlp ?S ?P * ρ) = trace (?P * denote ?S ρ) + trace ρ - trace (denote ?S ρ)›*) assms (*‹well_com (S::com)› ‹is_quantum_predicate P›*) dsr (*‹ρ ∈ density_states›*) by auto then show "⊨⇩p {wlp S P} S {P}" unfolding hoare_partial_correct_def (*goal: ‹∀ρ∈density_states. trace (wlp S P * ρ) ≤ trace (P * denote S ρ) + (trace ρ - trace (denote S ρ))›*) by auto fix Q assume qpQ: "is_quantum_predicate Q" and p: "⊨⇩p {Q} S {P}" (*‹is_quantum_predicate (Q::complex mat)› ‹⊨⇩p {Q::complex mat} S::com {P::complex mat}›*) { fix ρ assume dsr: "ρ ∈ density_states" (*‹(ρ::complex mat) ∈ density_states›*) then have "trace (Q * ρ) ≤ trace (P * (denote S ρ)) + trace ρ - trace (denote S ρ)" using hoare_partial_correct_def (*‹(⊨⇩p {?P} ?S {?Q}) = (∀ρ∈density_states. trace (?P * ρ) ≤ trace (?Q * denote ?S ρ) + (trace ρ - trace (denote ?S ρ)))›*) p (*‹⊨⇩p {Q} S {P}›*) by (auto simp: less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) then have "trace (Q * ρ) ≤ trace (wlp S P * ρ)" using eq[symmetric] (*‹?ρ ∈ density_states ⟹ trace (P * denote S ?ρ) + trace ?ρ - trace (denote S ?ρ) = trace (wlp S P * ?ρ)›*) dsr (*‹(ρ::complex mat) ∈ density_states›*) by auto } then show "Q ≤⇩L wlp S P" using lowner_le_trace (*‹⟦?A ∈ carrier_mat ?n ?n; ?B ∈ carrier_mat ?n ?n⟧ ⟹ (?A ≤⇩L ?B) = (∀ρ∈carrier_mat ?n ?n. partial_density_operator ρ ⟶ trace (?A * ρ) ≤ trace (?B * ρ))›*) density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) qpQ (*‹is_quantum_predicate Q›*) qpWP (*‹is_quantum_predicate (wlp S P)›*) is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto qed subsection ‹Hoare triples for partial correctness› inductive hoare_partial :: "complex mat ⇒ com ⇒ complex mat ⇒ bool" ("⊢⇩p ({(1_)}/ (_)/ {(1_)})" 50) where "is_quantum_predicate P ⟹ ⊢⇩p {P} SKIP {P}" | "is_quantum_predicate P ⟹ ⊢⇩p {adjoint U * P * U} Utrans U {P}" | "is_quantum_predicate P ⟹ is_quantum_predicate Q ⟹ is_quantum_predicate R ⟹ ⊢⇩p {P} S1 {Q} ⟹ ⊢⇩p {Q} S2 {R} ⟹ ⊢⇩p {P} Seq S1 S2 {R}" | "(⋀k. k < n ⟹ is_quantum_predicate (P k)) ⟹ is_quantum_predicate Q ⟹ (⋀k. k < n ⟹ ⊢⇩p {P k} S ! k {Q}) ⟹ ⊢⇩p {matrix_sum d (λk. adjoint (M k) * P k * M k) n} Measure n M S {Q}" | "is_quantum_predicate P ⟹ is_quantum_predicate Q ⟹ ⊢⇩p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} ⟹ ⊢⇩p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}" | "is_quantum_predicate P ⟹ is_quantum_predicate Q ⟹ is_quantum_predicate P' ⟹ is_quantum_predicate Q' ⟹ P ≤⇩L P' ⟹ ⊢⇩p {P'} S {Q'} ⟹ Q' ≤⇩L Q ⟹ ⊢⇩p {P} S {Q}" theorem hoare_partial_sound: "⊢⇩p {P} S {Q} ⟹ well_com S ⟹ ⊨⇩p {P} S {Q}" proof (induction rule: hoare_partial.induct (*‹⟦⊢⇩p {?x1.0::complex mat} ?x2.0::com {?x3.0::complex mat}; ⋀P::complex mat. is_quantum_predicate P ⟹ (?P::complex mat ⇒ com ⇒ complex mat ⇒ bool) P SKIP P; ⋀(P::complex mat) U::complex mat. is_quantum_predicate P ⟹ ?P (adjoint U * P * U) (Utrans U) P; ⋀(P::complex mat) (Q::complex mat) (R::complex mat) (S1::com) S2::com. ⟦is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate R; ⊢⇩p {P} S1 {Q}; ?P P S1 Q; ⊢⇩p {Q} S2 {R}; ?P Q S2 R⟧ ⟹ ?P P (S1;; S2) R; ⋀(n::nat) (P::nat ⇒ complex mat) (Q::complex mat) (S::com list) M::nat ⇒ complex mat. ⟦⋀k::nat. k < n ⟹ is_quantum_predicate (P k); is_quantum_predicate Q; ⋀k::nat. k < n ⟹ ⊢⇩p {P k} S ! k {Q}; ⋀k::nat. k < n ⟹ ?P (P k) (S ! k) Q⟧ ⟹ ?P (matrix_sum d (λk::nat. adjoint (M k) * P k * M k) n) (Measure n M S) Q; ⋀(P::complex mat) (Q::complex mat) (S::com) M::nat ⇒ complex mat. ⟦is_quantum_predicate P; is_quantum_predicate Q; ⊢⇩p {Q} S {adjoint (M (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)}; ?P Q S (adjoint (M (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat))⟧ ⟹ ?P (adjoint (M (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)) (While M S) P; ⋀(P::complex mat) (Q::complex mat) (P'::complex mat) (Q'::complex mat) S::com. ⟦is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P ≤⇩L P'; ⊢⇩p {P'} S {Q'}; ?P P' S Q'; Q' ≤⇩L Q⟧ ⟹ ?P P S Q⟧ ⟹ ?P ?x1.0 ?x2.0 ?x3.0›*)) (*goals: 1. ‹⋀P. ⟦is_quantum_predicate P; well_com SKIP⟧ ⟹ ⊨⇩p {P} SKIP {P}› 2. ‹⋀P U. ⟦is_quantum_predicate P; well_com (Utrans U)⟧ ⟹ ⊨⇩p {adjoint U * P * U} Utrans U {P}› 3. ‹⋀P Q R S1 S2. ⟦is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate R; ⊢⇩p {P} S1 {Q}; well_com S1 ⟹ ⊨⇩p {P} S1 {Q}; ⊢⇩p {Q} S2 {R}; well_com S2 ⟹ ⊨⇩p {Q} S2 {R}; well_com (S1;; S2)⟧ ⟹ ⊨⇩p {P} S1;; S2 {R}› 4. ‹⋀n P Q S M. ⟦⋀k. k < n ⟹ is_quantum_predicate (P k); is_quantum_predicate Q; ⋀k. k < n ⟹ ⊢⇩p {P k} S ! k {Q}; ⋀k. ⟦k < n; well_com (S ! k)⟧ ⟹ ⊨⇩p {P k} S ! k {Q}; well_com (Measure n M S)⟧ ⟹ ⊨⇩p {matrix_sum d (λk. adjoint (M k) * P k * M k) n} Measure n M S {Q}› 5. ‹⋀P Q S M. ⟦is_quantum_predicate P; is_quantum_predicate Q; ⊢⇩p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S ⟹ ⊨⇩p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)⟧ ⟹ ⊨⇩p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}› 6. ‹⋀P Q P' Q' S. ⟦is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P ≤⇩L P'; ⊢⇩p {P'} S {Q'}; well_com S ⟹ ⊨⇩p {P'} S {Q'}; Q' ≤⇩L Q; well_com S⟧ ⟹ ⊨⇩p {P} S {Q}›*) case (1 P) (*‹is_quantum_predicate P› ‹well_com SKIP›*) then show "?case" (*goal: ‹⊨⇩p {P} SKIP {P}›*) unfolding hoare_partial_correct_def (*goal: ‹∀ρ∈density_states. trace (P * ρ) ≤ trace (P * denote SKIP ρ) + (trace ρ - trace (denote SKIP ρ))›*) by auto next (*goals: 1. ‹⋀P U. ⟦is_quantum_predicate P; well_com (Utrans U)⟧ ⟹ ⊨⇩p {adjoint U * P * U} Utrans U {P}› 2. ‹⋀P Q R S1 S2. ⟦is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate R; ⊢⇩p {P} S1 {Q}; well_com S1 ⟹ ⊨⇩p {P} S1 {Q}; ⊢⇩p {Q} S2 {R}; well_com S2 ⟹ ⊨⇩p {Q} S2 {R}; well_com (S1;; S2)⟧ ⟹ ⊨⇩p {P} S1;; S2 {R}› 3. ‹⋀n P Q S M. ⟦⋀k. k < n ⟹ is_quantum_predicate (P k); is_quantum_predicate Q; ⋀k. k < n ⟹ ⊢⇩p {P k} S ! k {Q}; ⋀k. ⟦k < n; well_com (S ! k)⟧ ⟹ ⊨⇩p {P k} S ! k {Q}; well_com (Measure n M S)⟧ ⟹ ⊨⇩p {matrix_sum d (λk. adjoint (M k) * P k * M k) n} Measure n M S {Q}› 4. ‹⋀P Q S M. ⟦is_quantum_predicate P; is_quantum_predicate Q; ⊢⇩p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S ⟹ ⊨⇩p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)⟧ ⟹ ⊨⇩p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}› 5. ‹⋀P Q P' Q' S. ⟦is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P ≤⇩L P'; ⊢⇩p {P'} S {Q'}; well_com S ⟹ ⊨⇩p {P'} S {Q'}; Q' ≤⇩L Q; well_com S⟧ ⟹ ⊨⇩p {P} S {Q}›*) case (2 P U) (*‹is_quantum_predicate P› ‹well_com (Utrans U)›*) then have dU: "U ∈ carrier_mat d d" and "unitary U" and dP: "P ∈ carrier_mat d d" using is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) apply - (*goals: 1. ‹⟦is_quantum_predicate (P::complex mat); well_com (Utrans (U::complex mat)); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ U ∈ carrier_mat d d› 2. ‹⟦is_quantum_predicate (P::complex mat); well_com (Utrans (U::complex mat)); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ unitary U› 3. ‹⟦is_quantum_predicate (P::complex mat); well_com (Utrans (U::complex mat)); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ P ∈ carrier_mat d d› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . then have uU: "adjoint U * U = 1⇩m d" using unitary_def (*‹unitary ?A = (?A ∈ carrier_mat (dim_row ?A) (dim_row ?A) ∧ inverts_mat ?A (adjoint ?A))›*) by auto show "?case" (*goal: ‹⊨⇩p {adjoint U * P * U} Utrans U {P}›*) unfolding hoare_partial_correct_def denote.simps(2) (*goal: ‹∀ρ∈density_states. trace (adjoint U * P * U * ρ) ≤ trace (P * (U * ρ * adjoint U)) + (trace ρ - trace (U * ρ * adjoint U))›*) proof (standard) (*goal: ‹⋀ρ. ρ ∈ density_states ⟹ trace (adjoint U * P * U * ρ) ≤ trace (P * (U * ρ * adjoint U)) + (trace ρ - trace (U * ρ * adjoint U))›*) fix ρ assume "ρ ∈ density_states" (*‹(ρ::complex mat) ∈ density_states›*) then have dr: "ρ ∈ carrier_mat d d" using density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) by auto have e1: "trace (U * ρ * adjoint U) = trace ((adjoint U * U) * ρ)" using dr (*‹ρ ∈ carrier_mat d d›*) dU (*‹U ∈ carrier_mat d d›*) by (mat_assoc d) also (*calculation: ‹trace (U * ρ * adjoint U) = trace (adjoint U * U * ρ)›*) have "… = trace ρ" using uU (*‹adjoint (U::complex mat) * U = 1⇩m d›*) dr (*‹ρ ∈ carrier_mat d d›*) by auto finally (*calculation: ‹trace (U * ρ * adjoint U) = trace ρ›*) have e1: "trace (U * ρ * adjoint U) = trace ρ" . have e2: "trace (P * (U * ρ * adjoint U)) = trace (adjoint U * P * U * ρ)" using dU (*‹U ∈ carrier_mat d d›*) dP (*‹P ∈ carrier_mat d d›*) dr (*‹ρ ∈ carrier_mat d d›*) by (mat_assoc d) with e1 (*‹trace (U * ρ * adjoint U) = trace ρ›*) have "trace (P * (U * ρ * adjoint U)) + (trace ρ - trace (U * ρ * adjoint U)) = trace (adjoint U * P * U * ρ)" using e1 (*‹trace (U * ρ * adjoint U) = trace ρ›*) by auto then show "trace (adjoint U * P * U * ρ) ≤ trace (P * (U * ρ * adjoint U)) + (trace ρ - trace (U * ρ * adjoint U))" by auto qed next (*goals: 1. ‹⋀(P::complex mat) (Q::complex mat) (R::complex mat) (S1::com) S2::com. ⟦is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate R; ⊢⇩p {P} S1 {Q}; well_com S1 ⟹ ⊨⇩p {P} S1 {Q}; ⊢⇩p {Q} S2 {R}; well_com S2 ⟹ ⊨⇩p {Q} S2 {R}; well_com (S1;; S2)⟧ ⟹ ⊨⇩p {P} S1;; S2 {R}› 2. ‹⋀(n::nat) (P::nat ⇒ complex mat) (Q::complex mat) (S::com list) M::nat ⇒ complex mat. ⟦⋀k::nat. k < n ⟹ is_quantum_predicate (P k); is_quantum_predicate Q; ⋀k::nat. k < n ⟹ ⊢⇩p {P k} S ! k {Q}; ⋀k::nat. ⟦k < n; well_com (S ! k)⟧ ⟹ ⊨⇩p {P k} S ! k {Q}; well_com (Measure n M S)⟧ ⟹ ⊨⇩p {matrix_sum d (λk::nat. adjoint (M k) * P k * M k) n} Measure n M S {Q}› 3. ‹⋀(P::complex mat) (Q::complex mat) (S::com) M::nat ⇒ complex mat. ⟦is_quantum_predicate P; is_quantum_predicate Q; ⊢⇩p {Q} S {adjoint (M (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)}; well_com S ⟹ ⊨⇩p {Q} S {adjoint (M (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)}; well_com (While M S)⟧ ⟹ ⊨⇩p {adjoint (M (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)} While M S {P}› 4. ‹⋀(P::complex mat) (Q::complex mat) (P'::complex mat) (Q'::complex mat) S::com. ⟦is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P ≤⇩L P'; ⊢⇩p {P'} S {Q'}; well_com S ⟹ ⊨⇩p {P'} S {Q'}; Q' ≤⇩L Q; well_com S⟧ ⟹ ⊨⇩p {P} S {Q}›*) case (3 P Q R S1 S2) (*‹is_quantum_predicate P› ‹is_quantum_predicate (Q::complex mat)› ‹is_quantum_predicate (R::complex mat)› ‹⊢⇩p {P} S1 {Q}› ‹⊢⇩p {Q} S2 {R}› ‹well_com S1 ⟹ ⊨⇩p {P} S1 {Q}› ‹well_com S2 ⟹ ⊨⇩p {Q} S2 {R}› ‹well_com (S1;; S2)›*) then have wc1: "⊨⇩p {P} S1 {Q}" and wc2: "⊨⇩p {Q} S2 {R}" apply - (*goals: 1. ‹⟦is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate R; ⊢⇩p {P} S1 {Q}; ⊢⇩p {Q} S2 {R}; well_com S1 ⟹ ⊨⇩p {P} S1 {Q}; well_com S2 ⟹ ⊨⇩p {Q} S2 {R}; well_com (S1;; S2)⟧ ⟹ ⊨⇩p {P} S1 {Q}› 2. ‹⟦is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate R; ⊢⇩p {P} S1 {Q}; ⊢⇩p {Q} S2 {R}; well_com S1 ⟹ ⊨⇩p {P} S1 {Q}; well_com S2 ⟹ ⊨⇩p {Q} S2 {R}; well_com (S1;; S2)⟧ ⟹ ⊨⇩p {Q} S2 {R}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . show "?case" (*goal: ‹⊨⇩p {P} S1;; S2 {R}›*) unfolding hoare_partial_correct_def denote.simps(3) (*goal: ‹∀ρ::complex mat∈density_states. trace ((P::complex mat) * ρ) ≤ trace ((R::complex mat) * denote (S2::com) (denote (S1::com) ρ)) + (trace ρ - trace (denote S2 (denote S1 ρ)))›*) proof (clarify) (*goal: ‹⋀ρ. ρ ∈ density_states ⟹ trace (P * ρ) ≤ trace (R * denote S2 (denote S1 ρ)) + (trace ρ - trace (denote S2 (denote S1 ρ)))›*) fix ρ assume "ρ": "ρ ∈ density_states" (*‹(ρ::complex mat) ∈ density_states›*) have 1: "trace (P * ρ) ≤ trace (Q * denote S1 ρ) + (trace ρ - trace (denote S1 ρ))" using wc1 (*‹⊨⇩p {P} S1 {Q}›*) hoare_partial_correct_def (*‹(⊨⇩p {?P::complex mat} ?S::com {?Q::complex mat}) = (∀ρ::complex mat∈density_states. trace (?P * ρ) ≤ trace (?Q * denote ?S ρ) + (trace ρ - trace (denote ?S ρ)))›*) "ρ" (*‹(ρ::complex mat) ∈ density_states›*) by auto have "ρ'": "denote S1 ρ ∈ density_states" using "3"(8) (*‹well_com (S1;; S2)›*) denote_density_states (*‹⟦?ρ ∈ density_states; well_com ?S⟧ ⟹ denote ?S ?ρ ∈ density_states›*) "ρ" (*‹ρ ∈ density_states›*) by auto have 2: "trace (Q * denote S1 ρ) ≤ trace (R * denote S2 (denote S1 ρ)) + (trace (denote S1 ρ) - trace (denote S2 (denote S1 ρ)))" using wc2 (*‹⊨⇩p {Q::complex mat} S2::com {R::complex mat}›*) hoare_partial_correct_def (*‹(⊨⇩p {?P} ?S {?Q}) = (∀ρ∈density_states. trace (?P * ρ) ≤ trace (?Q * denote ?S ρ) + (trace ρ - trace (denote ?S ρ)))›*) "ρ'" (*‹denote S1 ρ ∈ density_states›*) by auto show "trace (P * ρ) ≤ trace (R * denote S2 (denote S1 ρ)) + (trace ρ - trace (denote S2 (denote S1 ρ)))" using "1" (*‹trace (P * ρ) ≤ trace (Q * denote S1 ρ) + (trace ρ - trace (denote S1 ρ))›*) "2" (*‹trace (Q * denote S1 ρ) ≤ trace (R * denote S2 (denote S1 ρ)) + (trace (denote S1 ρ) - trace (denote S2 (denote S1 ρ)))›*) by (auto simp: less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) qed next (*goals: 1. ‹⋀n P Q S M. ⟦⋀k. k < n ⟹ is_quantum_predicate (P k); is_quantum_predicate Q; ⋀k. k < n ⟹ ⊢⇩p {P k} S ! k {Q}; ⋀k. ⟦k < n; well_com (S ! k)⟧ ⟹ ⊨⇩p {P k} S ! k {Q}; well_com (Measure n M S)⟧ ⟹ ⊨⇩p {matrix_sum d (λk. adjoint (M k) * P k * M k) n} Measure n M S {Q}› 2. ‹⋀P Q S M. ⟦is_quantum_predicate P; is_quantum_predicate Q; ⊢⇩p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S ⟹ ⊨⇩p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)⟧ ⟹ ⊨⇩p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}› 3. ‹⋀P Q P' Q' S. ⟦is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P ≤⇩L P'; ⊢⇩p {P'} S {Q'}; well_com S ⟹ ⊨⇩p {P'} S {Q'}; Q' ≤⇩L Q; well_com S⟧ ⟹ ⊨⇩p {P} S {Q}›*) case (4 n P Q S M) (*‹?k < n ⟹ is_quantum_predicate (P ?k)› ‹is_quantum_predicate Q› ‹?k < n ⟹ ⊢⇩p {P ?k} S ! ?k {Q}› ‹⟦?k < n; well_com (S ! ?k)⟧ ⟹ ⊨⇩p {P ?k} S ! ?k {Q}› ‹well_com (Measure n M S)›*) then have wc: "k < n ⟹ well_com (S!k)" and c: "k < n ⟹ ⊨⇩p {P k} (S!k) {Q}" and m: "measurement d n M" and dMk: "k < n ⟹ M k ∈ carrier_mat d d" and aMMkleq: "k < n ⟹ adjoint (M k) * M k ≤⇩L 1⇩m d" and dPk: "k < n ⟹ P k ∈ carrier_mat d d" and dQ: "Q ∈ carrier_mat d d" for k using is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) measurement_def (*‹measurement ?d ?n ?M = ((∀j<?n. ?M j ∈ carrier_mat ?d ?d) ∧ matrix_sum ?d (λj. adjoint (?M j) * ?M j) ?n = 1⇩m ?d)›*) measure_well_com (*‹⟦well_com (Measure ?n ?M ?S); ?k < ?n⟧ ⟹ well_com (?S ! ?k)›*) measurement_le_one_mat (*‹⟦measurement ?d ?n ?f; ?j < ?n⟧ ⟹ adjoint (?f ?j) * ?f ?j ≤⇩L 1⇩m ?d›*) apply - (*goals: 1. ‹⟦(k::nat) < (n::nat); ⋀k::nat. k < n ⟹ is_quantum_predicate ((P::nat ⇒ complex mat) k); is_quantum_predicate (Q::complex mat); ⋀k::nat. k < n ⟹ ⊢⇩p {P k} (S::com list) ! k {Q}; ⋀k::nat. ⟦k < n; well_com (S ! k)⟧ ⟹ ⊨⇩p {P k} S ! k {Q}; well_com (Measure n (M::nat ⇒ complex mat) S); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); ⋀(d::nat) (n::nat) M::nat ⇒ complex mat. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj::nat. adjoint (M j) * M j) n = 1⇩m d); ⋀(n::nat) (M::nat ⇒ complex mat) (S::com list) k::nat. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀(d::nat) (n::nat) (f::nat ⇒ complex mat) j::nat. ⟦measurement d n f; j < n⟧ ⟹ adjoint (f j) * f j ≤⇩L 1⇩m d⟧ ⟹ well_com (S ! k)› 2. ‹⟦(k::nat) < (n::nat); ⋀k::nat. k < n ⟹ is_quantum_predicate ((P::nat ⇒ complex mat) k); is_quantum_predicate (Q::complex mat); ⋀k::nat. k < n ⟹ ⊢⇩p {P k} (S::com list) ! k {Q}; ⋀k::nat. ⟦k < n; well_com (S ! k)⟧ ⟹ ⊨⇩p {P k} S ! k {Q}; well_com (Measure n (M::nat ⇒ complex mat) S); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); ⋀(d::nat) (n::nat) M::nat ⇒ complex mat. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj::nat. adjoint (M j) * M j) n = 1⇩m d); ⋀(n::nat) (M::nat ⇒ complex mat) (S::com list) k::nat. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀(d::nat) (n::nat) (f::nat ⇒ complex mat) j::nat. ⟦measurement d n f; j < n⟧ ⟹ adjoint (f j) * f j ≤⇩L 1⇩m d⟧ ⟹ ⊨⇩p {P k} S ! k {Q}› 3. ‹⟦⋀k::nat. k < (n::nat) ⟹ is_quantum_predicate ((P::nat ⇒ complex mat) k); is_quantum_predicate (Q::complex mat); ⋀k::nat. k < n ⟹ ⊢⇩p {P k} (S::com list) ! k {Q}; ⋀k::nat. ⟦k < n; well_com (S ! k)⟧ ⟹ ⊨⇩p {P k} S ! k {Q}; well_com (Measure n (M::nat ⇒ complex mat) S); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); ⋀(d::nat) (n::nat) M::nat ⇒ complex mat. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj::nat. adjoint (M j) * M j) n = 1⇩m d); ⋀(n::nat) (M::nat ⇒ complex mat) (S::com list) k::nat. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀(d::nat) (n::nat) (f::nat ⇒ complex mat) j::nat. ⟦measurement d n f; j < n⟧ ⟹ adjoint (f j) * f j ≤⇩L 1⇩m d⟧ ⟹ measurement d n M› 4. ‹⟦(k::nat) < (n::nat); ⋀k::nat. k < n ⟹ is_quantum_predicate ((P::nat ⇒ complex mat) k); is_quantum_predicate (Q::complex mat); ⋀k::nat. k < n ⟹ ⊢⇩p {P k} (S::com list) ! k {Q}; ⋀k::nat. ⟦k < n; well_com (S ! k)⟧ ⟹ ⊨⇩p {P k} S ! k {Q}; well_com (Measure n (M::nat ⇒ complex mat) S); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); ⋀(d::nat) (n::nat) M::nat ⇒ complex mat. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj::nat. adjoint (M j) * M j) n = 1⇩m d); ⋀(n::nat) (M::nat ⇒ complex mat) (S::com list) k::nat. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀(d::nat) (n::nat) (f::nat ⇒ complex mat) j::nat. ⟦measurement d n f; j < n⟧ ⟹ adjoint (f j) * f j ≤⇩L 1⇩m d⟧ ⟹ M k ∈ carrier_mat d d› 5. ‹⟦(k::nat) < (n::nat); ⋀k::nat. k < n ⟹ is_quantum_predicate ((P::nat ⇒ complex mat) k); is_quantum_predicate (Q::complex mat); ⋀k::nat. k < n ⟹ ⊢⇩p {P k} (S::com list) ! k {Q}; ⋀k::nat. ⟦k < n; well_com (S ! k)⟧ ⟹ ⊨⇩p {P k} S ! k {Q}; well_com (Measure n (M::nat ⇒ complex mat) S); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); ⋀(d::nat) (n::nat) M::nat ⇒ complex mat. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj::nat. adjoint (M j) * M j) n = 1⇩m d); ⋀(n::nat) (M::nat ⇒ complex mat) (S::com list) k::nat. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀(d::nat) (n::nat) (f::nat ⇒ complex mat) j::nat. ⟦measurement d n f; j < n⟧ ⟹ adjoint (f j) * f j ≤⇩L 1⇩m d⟧ ⟹ adjoint (M k) * M k ≤⇩L 1⇩m d› 6. ‹⟦(k::nat) < (n::nat); ⋀k::nat. k < n ⟹ is_quantum_predicate ((P::nat ⇒ complex mat) k); is_quantum_predicate (Q::complex mat); ⋀k::nat. k < n ⟹ ⊢⇩p {P k} (S::com list) ! k {Q}; ⋀k::nat. ⟦k < n; well_com (S ! k)⟧ ⟹ ⊨⇩p {P k} S ! k {Q}; well_com (Measure n (M::nat ⇒ complex mat) S); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); ⋀(d::nat) (n::nat) M::nat ⇒ complex mat. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj::nat. adjoint (M j) * M j) n = 1⇩m d); ⋀(n::nat) (M::nat ⇒ complex mat) (S::com list) k::nat. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀(d::nat) (n::nat) (f::nat ⇒ complex mat) j::nat. ⟦measurement d n f; j < n⟧ ⟹ adjoint (f j) * f j ≤⇩L 1⇩m d⟧ ⟹ P k ∈ carrier_mat d d› 7. ‹⟦⋀k::nat. k < (n::nat) ⟹ is_quantum_predicate ((P::nat ⇒ complex mat) k); is_quantum_predicate (Q::complex mat); ⋀k::nat. k < n ⟹ ⊢⇩p {P k} (S::com list) ! k {Q}; ⋀k::nat. ⟦k < n; well_com (S ! k)⟧ ⟹ ⊨⇩p {P k} S ! k {Q}; well_com (Measure n (M::nat ⇒ complex mat) S); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); ⋀(d::nat) (n::nat) M::nat ⇒ complex mat. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj::nat. adjoint (M j) * M j) n = 1⇩m d); ⋀(n::nat) (M::nat ⇒ complex mat) (S::com list) k::nat. ⟦well_com (Measure n M S); k < n⟧ ⟹ well_com (S ! k); ⋀(d::nat) (n::nat) (f::nat ⇒ complex mat) j::nat. ⟦measurement d n f; j < n⟧ ⟹ adjoint (f j) * f j ≤⇩L 1⇩m d⟧ ⟹ Q ∈ carrier_mat d d› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*proven 7 subgoals*) . { fix ρ assume "ρ": "ρ ∈ density_states" (*‹(ρ::complex mat) ∈ density_states›*) then have dr: "ρ ∈ carrier_mat d d" and pdor: "partial_density_operator ρ" using density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) apply - (*goals: 1. ‹⟦ρ ∈ density_states; density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}⟧ ⟹ ρ ∈ carrier_mat d d› 2. ‹⟦ρ ∈ density_states; density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}⟧ ⟹ partial_density_operator ρ› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have dsr: "k < n ⟹ (M k) * ρ * adjoint (M k) ∈ density_states" for k unfolding density_states_def (*goal: ‹k < n ⟹ M k * ρ * adjoint (M k) ∈ {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) using dMk (*‹?k < n ⟹ M ?k ∈ carrier_mat d d›*) pdo_close_under_measurement[OF dMk dr pdor aMMkleq] (*‹⟦?k1 < n; ?k1 < n⟧ ⟹ partial_density_operator (M ?k1 * ρ * adjoint (M ?k1))›*) dr (*‹ρ ∈ carrier_mat d d›*) by fastforce then have leqk: "k < n ⟹ trace ((P k) * ((M k) * ρ * adjoint (M k))) ≤ trace (Q * (denote (S!k) ((M k) * ρ * adjoint (M k)))) + (trace ((M k) * ρ * adjoint (M k)) - trace (denote (S ! k) ((M k) * ρ * adjoint (M k))))" for k using c (*‹?k < n ⟹ ⊨⇩p {P ?k} S ! ?k {Q}›*) unfolding hoare_partial_correct_def (*goal: ‹k < n ⟹ trace (P k * (M k * ρ * adjoint (M k))) ≤ trace (Q * denote (S ! k) (M k * ρ * adjoint (M k))) + (trace (M k * ρ * adjoint (M k)) - trace (denote (S ! k) (M k * ρ * adjoint (M k))))›*) by auto have "k < n ⟹ M k * ρ * adjoint (M k) ∈ carrier_mat d d" for k using dMk (*‹?k < n ⟹ M ?k ∈ carrier_mat d d›*) dr (*‹ρ ∈ carrier_mat d d›*) by fastforce then have dsMrk: "k < n ⟹ matrix_sum d (λk. (M k * ρ * adjoint (M k))) k ∈ carrier_mat d d" for k using matrix_sum_dim[of k "λk. (M k * ρ * adjoint (M k))" d] (*‹(⋀ka. ka < k ⟹ M ka * ρ * adjoint (M ka) ∈ carrier_mat d d) ⟹ matrix_sum d (λk. M k * ρ * adjoint (M k)) k ∈ carrier_mat d d›*) by fastforce have "k < n ⟹ adjoint (M k) * P k * M k ∈ carrier_mat d d" for k using dMk (*‹?k < n ⟹ M ?k ∈ carrier_mat d d›*) dPk (*‹?k < n ⟹ P ?k ∈ carrier_mat d d›*) by fastforce then have dsMP: "k < n ⟹ matrix_sum d (λk. adjoint (M k) * P k * M k) k ∈ carrier_mat d d" for k using matrix_sum_dim[of k "λk. adjoint (M k) * P k * M k" d] (*‹(⋀ka. ka < k ⟹ adjoint (M ka) * P ka * M ka ∈ carrier_mat d d) ⟹ matrix_sum d (λk. adjoint (M k) * P k * M k) k ∈ carrier_mat d d›*) by fastforce have dSMrk: "k < n ⟹ denote (S ! k) (M k * ρ * adjoint (M k)) ∈ carrier_mat d d" for k using denote_dim[OF wc, of k "M k * ρ * adjoint (M k)"] (*‹⟦k < n; M k * ρ * adjoint (M k) ∈ carrier_mat d d; partial_density_operator (M k * ρ * adjoint (M k))⟧ ⟹ denote (S ! k) (M k * ρ * adjoint (M k)) ∈ carrier_mat d d›*) dsr (*‹?k < n ⟹ M ?k * ρ * adjoint (M ?k) ∈ density_states›*) density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) by fastforce have dsSMrk: "k < n ⟹ matrix_sum d (λk. denote (S!k) (M k * ρ * adjoint (M k))) k ∈ carrier_mat d d" for k using matrix_sum_dim[of k "λk. denote (S ! k) (M k * ρ * adjoint (M k))" d, OF dSMrk] (*‹(⋀ka::nat. ka < (k::nat) ⟹ ka < (n::nat)) ⟹ matrix_sum d (λk::nat. denote ((S::com list) ! k) ((M::nat ⇒ complex mat) k * (ρ::complex mat) * adjoint (M k))) k ∈ carrier_mat d d›*) by fastforce have "k ≤ n ⟹ trace (matrix_sum d (λk. adjoint (M k) * P k * M k) k * ρ) ≤ trace (Q * (denote (Measure k M S) ρ)) + (trace (matrix_sum d (λk. (M k) * ρ * adjoint (M k)) k) - trace (denote (Measure k M S) ρ))" for k unfolding denote_measure_expand[OF _ 4 ( 5 )] (*goal: ‹(k::nat) ≤ (n::nat) ⟹ trace (matrix_sum d (λk::nat. adjoint ((M::nat ⇒ complex mat) k) * (P::nat ⇒ complex mat) k * M k) k * (ρ::complex mat)) ≤ trace ((Q::complex mat) * matrix_sum d (λk::nat. denote ((S::com list) ! k) (M k * ρ * adjoint (M k))) k) + (trace (matrix_sum d (λk::nat. M k * ρ * adjoint (M k)) k) - trace (matrix_sum d (λk::nat. denote (S ! k) (M k * ρ * adjoint (M k))) k))›*) proof (induct k) (*goals: 1. ‹0 ≤ n ⟹ trace (matrix_sum d (λk. adjoint (M k) * P k * M k) 0 * ρ) ≤ trace (Q * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) 0) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) 0) - trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) 0))› 2. ‹⋀k. ⟦k ≤ n ⟹ trace (matrix_sum d (λk. adjoint (M k) * P k * M k) k * ρ) ≤ trace (Q * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) k) - trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k)); Suc k ≤ n⟧ ⟹ trace (matrix_sum d (λk. adjoint (M k) * P k * M k) (Suc k) * ρ) ≤ trace (Q * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) (Suc k)) - trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) (Suc k)))›*) case 0 (*‹0 ≤ n›*) then show "?case" (*goal: ‹trace (matrix_sum d (λk. adjoint (M k) * P k * M k) 0 * ρ) ≤ trace (Q * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) 0) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) 0) - trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) 0))›*) using dQ (*‹(Q::complex mat) ∈ carrier_mat d d›*) dr (*‹ρ ∈ carrier_mat d d›*) pdor (*‹partial_density_operator ρ›*) partial_density_operator_def (*‹partial_density_operator ?A = (positive ?A ∧ trace ?A ≤ 1)›*) positive_trace (*‹⟦?A ∈ carrier_mat ?n ?n; positive ?A⟧ ⟹ 0 ≤ trace ?A›*) by auto next (*goal: ‹⋀k. ⟦k ≤ n ⟹ trace (matrix_sum d (λk. adjoint (M k) * P k * M k) k * ρ) ≤ trace (Q * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) k) - trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k)); Suc k ≤ n⟧ ⟹ trace (matrix_sum d (λk. adjoint (M k) * P k * M k) (Suc k) * ρ) ≤ trace (Q * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) (Suc k)) - trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) (Suc k)))›*) case (Suc k) (*‹k ≤ n ⟹ trace (matrix_sum d (λk. adjoint (M k) * P k * M k) k * ρ) ≤ trace (Q * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) k) - trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k))› ‹Suc (k::nat) ≤ (n::nat)›*) then have k: "k < n" by auto have eq1: "trace (matrix_sum d (λk. adjoint (M k) * P k * M k) (Suc k) * ρ) = trace (adjoint (M k) * P k * M k * ρ) + trace (matrix_sum d (λk. adjoint (M k) * P k * M k) k * ρ)" unfolding matrix_sum.simps (*goal: ‹trace ((adjoint (M k) * P k * M k + matrix_sum d (λk. adjoint (M k) * P k * M k) k) * ρ) = trace (adjoint (M k) * P k * M k * ρ) + trace (matrix_sum d (λk. adjoint (M k) * P k * M k) k * ρ)›*) using dMk[OF k] (*‹M k ∈ carrier_mat d d›*) dPk[OF k] (*‹P k ∈ carrier_mat d d›*) dr (*‹ρ ∈ carrier_mat d d›*) dsMP[OF k] (*‹matrix_sum d (λk. adjoint (M k) * P k * M k) k ∈ carrier_mat d d›*) by (mat_assoc d) have "trace (adjoint (M k) * P k * M k * ρ) = trace (P k * (M k * ρ * adjoint (M k)))" using dMk[OF k] (*‹(M::nat ⇒ complex mat) (k::nat) ∈ carrier_mat d d›*) dPk[OF k] (*‹(P::nat ⇒ complex mat) (k::nat) ∈ carrier_mat d d›*) dr (*‹ρ ∈ carrier_mat d d›*) by (mat_assoc d) also (*calculation: ‹trace (adjoint ((M::nat ⇒ complex mat) (k::nat)) * (P::nat ⇒ complex mat) k * M k * (ρ::complex mat)) = trace (P k * (M k * ρ * adjoint (M k)))›*) have "… ≤ trace (Q * (denote (S!k) ((M k) * ρ * adjoint (M k)))) + (trace ((M k) * ρ * adjoint (M k)) - trace (denote (S ! k) ((M k) * ρ * adjoint (M k))))" using leqk (*‹?k < n ⟹ trace (P ?k * (M ?k * ρ * adjoint (M ?k))) ≤ trace (Q * denote (S ! ?k) (M ?k * ρ * adjoint (M ?k))) + (trace (M ?k * ρ * adjoint (M ?k)) - trace (denote (S ! ?k) (M ?k * ρ * adjoint (M ?k))))›*) k (*‹k < n›*) by auto finally (*calculation: ‹trace (adjoint (M k) * P k * M k * ρ) ≤ trace (Q * denote (S ! k) (M k * ρ * adjoint (M k))) + (trace (M k * ρ * adjoint (M k)) - trace (denote (S ! k) (M k * ρ * adjoint (M k))))›*) have eq2: "trace (adjoint (M k) * P k * M k * ρ) ≤ trace (Q * (denote (S!k) ((M k) * ρ * adjoint (M k)))) + (trace ((M k) * ρ * adjoint (M k)) - trace (denote (S ! k) ((M k) * ρ * adjoint (M k))))" . have eq3: "trace (Q * matrix_sum d (λk. denote (S!k) (M k * ρ * adjoint (M k))) (Suc k)) = trace (Q * (denote (S!k) (M k * ρ * adjoint (M k)))) + trace (Q * matrix_sum d (λk. denote (S!k) (M k * ρ * adjoint (M k))) k)" unfolding matrix_sum.simps (*goal: ‹trace (Q * (denote (S ! k) (M k * ρ * adjoint (M k)) + matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k)) = trace (Q * denote (S ! k) (M k * ρ * adjoint (M k))) + trace (Q * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k)›*) using dQ (*‹(Q::complex mat) ∈ carrier_mat d d›*) dSMrk[OF k] (*‹denote (S ! k) (M k * ρ * adjoint (M k)) ∈ carrier_mat d d›*) dsSMrk[OF k] (*‹matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k ∈ carrier_mat d d›*) by (mat_assoc d) have eq4: "trace (denote (S ! k) (M k * ρ * adjoint (M k)) + matrix_sum d (λk. denote (S!k) (M k * ρ * adjoint (M k))) k) = trace (denote (S ! k) (M k * ρ * adjoint (M k))) + trace (matrix_sum d (λk. denote (S!k) (M k * ρ * adjoint (M k))) k)" using dSMrk[OF k] (*‹denote (S ! k) (M k * ρ * adjoint (M k)) ∈ carrier_mat d d›*) dsSMrk[OF k] (*‹matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k ∈ carrier_mat d d›*) by (mat_assoc d) show "?case" (*goal: ‹trace (matrix_sum d (λk::nat. adjoint ((M::nat ⇒ complex mat) k) * (P::nat ⇒ complex mat) k * M k) (Suc (k::nat)) * (ρ::complex mat)) ≤ trace ((Q::complex mat) * matrix_sum d (λk::nat. denote ((S::com list) ! k) (M k * ρ * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (λk::nat. M k * ρ * adjoint (M k)) (Suc k)) - trace (matrix_sum d (λk::nat. denote (S ! k) (M k * ρ * adjoint (M k))) (Suc k)))›*) apply (subst eq1 (*‹trace (matrix_sum d (λk. adjoint (M k) * P k * M k) (Suc k) * ρ) = trace (adjoint (M k) * P k * M k * ρ) + trace (matrix_sum d (λk. adjoint (M k) * P k * M k) k * ρ)›*)) (*goal: ‹trace (matrix_sum d (λk. adjoint (M k) * P k * M k) (Suc k) * ρ) ≤ trace (Q * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) (Suc k)) - trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) (Suc k)))›*) apply (subst eq3 (*‹trace ((Q::complex mat) * matrix_sum d (λk::nat. denote ((S::com list) ! k) ((M::nat ⇒ complex mat) k * (ρ::complex mat) * adjoint (M k))) (Suc (k::nat))) = trace (Q * denote (S ! k) (M k * ρ * adjoint (M k))) + trace (Q * matrix_sum d (λk::nat. denote (S ! k) (M k * ρ * adjoint (M k))) k)›*)) (*goal: ‹trace (adjoint (M k) * P k * M k * ρ) + trace (matrix_sum d (λk. adjoint (M k) * P k * M k) k * ρ) ≤ trace (Q * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) (Suc k)) - trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) (Suc k)))›*) apply (simp del: less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) (*goal: ‹trace (adjoint (M k) * P k * M k * ρ) + trace (matrix_sum d (λk. adjoint (M k) * P k * M k) k * ρ) ≤ trace (Q * denote (S ! k) (M k * ρ * adjoint (M k))) + trace (Q * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) (Suc k)) - trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) (Suc k)))›*) apply (subst trace_add_linear[of "M k * ρ * adjoint (M k)" d "matrix_sum d (λk. M k * ρ * adjoint (M k)) k"] (*‹⟦(M::nat ⇒ complex mat) (k::nat) * (ρ::complex mat) * adjoint (M k) ∈ carrier_mat d d; matrix_sum d (λk::nat. M k * ρ * adjoint (M k)) k ∈ carrier_mat d d⟧ ⟹ trace (M k * ρ * adjoint (M k) + matrix_sum d (λk::nat. M k * ρ * adjoint (M k)) k) = trace (M k * ρ * adjoint (M k)) + trace (matrix_sum d (λk::nat. M k * ρ * adjoint (M k)) k)›*)) (*goals: 1. ‹M k * ρ * adjoint (M k) ∈ carrier_mat d d› 2. ‹matrix_sum d (λk. M k * ρ * adjoint (M k)) k ∈ carrier_mat d d› 3. ‹trace (adjoint (M k) * P k * M k * ρ) + trace (matrix_sum d (λk. adjoint (M k) * P k * M k) k * ρ) ≤ trace (Q * denote (S ! k) (M k * ρ * adjoint (M k))) + trace (Q * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k) + (trace (M k * ρ * adjoint (M k)) + trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) k) - trace (denote (S ! k) (M k * ρ * adjoint (M k)) + matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k))› discuss goal 1*) apply (simp add: dMk (*‹?k < n ⟹ M ?k ∈ carrier_mat d d›*) adjoint_dim[OF dMk] (*‹?k1 < n ⟹ adjoint (M ?k1) ∈ carrier_mat d d›*) dr (*‹ρ ∈ carrier_mat d d›*) mult_carrier_mat[of _ d d _ d] (*‹⟦?A ∈ carrier_mat d d; ?B ∈ carrier_mat d d⟧ ⟹ ?A * ?B ∈ carrier_mat d d›*) k (*‹k < n›*)) (*discuss goal 2*) apply (simp add: dsMrk (*‹?k < n ⟹ matrix_sum d (λk. M k * ρ * adjoint (M k)) ?k ∈ carrier_mat d d›*) k (*‹k < n›*)) (*discuss goal 3*) apply (subst eq4 (*‹trace (denote (S ! k) (M k * ρ * adjoint (M k)) + matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k) = trace (denote (S ! k) (M k * ρ * adjoint (M k))) + trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k)›*)) (*goal: ‹trace (adjoint (M k) * P k * M k * ρ) + trace (matrix_sum d (λk. adjoint (M k) * P k * M k) k * ρ) ≤ trace (Q * denote (S ! k) (M k * ρ * adjoint (M k))) + trace (Q * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k) + (trace (M k * ρ * adjoint (M k)) + trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) k) - trace (denote (S ! k) (M k * ρ * adjoint (M k)) + matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k))›*) apply (insert eq2 (*‹trace (adjoint (M k) * P k * M k * ρ) ≤ trace (Q * denote (S ! k) (M k * ρ * adjoint (M k))) + (trace (M k * ρ * adjoint (M k)) - trace (denote (S ! k) (M k * ρ * adjoint (M k))))›*) Suc( (*‹k ≤ n ⟹ trace (matrix_sum d (λk. adjoint (M k) * P k * M k) k * ρ) ≤ trace (Q * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) k) - trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k))›*) 1) k (*‹k < n›*)) (*goal: ‹trace (adjoint (M k) * P k * M k * ρ) + trace (matrix_sum d (λk. adjoint (M k) * P k * M k) k * ρ) ≤ trace (Q * denote (S ! k) (M k * ρ * adjoint (M k))) + trace (Q * matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k) + (trace (M k * ρ * adjoint (M k)) + trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) k) - (trace (denote (S ! k) (M k * ρ * adjoint (M k))) + trace (matrix_sum d (λk. denote (S ! k) (M k * ρ * adjoint (M k))) k)))›*) apply (fastforce simp: less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) (*proven 3 subgoals*) . qed then have leq: "trace (matrix_sum d (λk. adjoint (M k) * P k * M k) n * ρ) ≤ trace (Q * denote (Measure n M S) ρ) + (trace (matrix_sum d (λk. (M k) * ρ * adjoint (M k)) n) - trace (denote (Measure n M S) ρ))" by auto have "trace (matrix_sum d (λk. (M k) * ρ * adjoint (M k)) n) = trace ρ" using trace_measurement (*‹⟦measurement (?d::nat) (?n::nat) (?M::nat ⇒ complex mat); (?A::complex mat) ∈ carrier_mat ?d ?d⟧ ⟹ trace (matrix_sum ?d (λk::nat. ?M k * ?A * adjoint (?M k)) ?n) = trace ?A›*) m (*‹measurement d n M›*) dr (*‹ρ ∈ carrier_mat d d›*) by auto with leq (*‹trace (matrix_sum d (λk. adjoint (M k) * P k * M k) n * ρ) ≤ trace (Q * denote (Measure n M S) ρ) + (trace (matrix_sum d (λk. M k * ρ * adjoint (M k)) n) - trace (denote (Measure n M S) ρ))›*) have "trace (matrix_sum d (λk. adjoint (M k) * P k * M k) n * ρ) ≤ trace (Q * denote (Measure n M S) ρ) + (trace ρ - trace (denote (Measure n M S) ρ))" unfolding denote_measure_def (*goal: ‹trace (matrix_sum d (λk. adjoint (M k) * P k * M k) n * ρ) ≤ trace (Q * denote (Measure n M S) ρ) + (trace ρ - trace (denote (Measure n M S) ρ))›*) by auto } then show "?case" (*goal: ‹⊨⇩p {matrix_sum d (λk::nat. adjoint ((M::nat ⇒ complex mat) k) * (P::nat ⇒ complex mat) k * M k) (n::nat)} Measure n M (S::com list) {Q::complex mat}›*) unfolding hoare_partial_correct_def (*goal: ‹∀ρ∈density_states. trace (matrix_sum d (λk. adjoint (M k) * P k * M k) n * ρ) ≤ trace (Q * denote (Measure n M S) ρ) + (trace ρ - trace (denote (Measure n M S) ρ))›*) by auto next (*goals: 1. ‹⋀P Q S M. ⟦is_quantum_predicate P; is_quantum_predicate Q; ⊢⇩p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S ⟹ ⊨⇩p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)⟧ ⟹ ⊨⇩p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}› 2. ‹⋀P Q P' Q' S. ⟦is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P ≤⇩L P'; ⊢⇩p {P'} S {Q'}; well_com S ⟹ ⊨⇩p {P'} S {Q'}; Q' ≤⇩L Q; well_com S⟧ ⟹ ⊨⇩p {P} S {Q}›*) case (5 P Q S M) (*‹is_quantum_predicate (P::complex mat)› ‹is_quantum_predicate Q› ‹⊢⇩p {Q::complex mat} S::com {adjoint ((M::nat ⇒ complex mat) (0::nat)) * (P::complex mat) * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)}› ‹well_com S ⟹ ⊨⇩p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}› ‹well_com (While (M::nat ⇒ complex mat) (S::com))›*) define M0 where "M0 = M 0" define M1 where "M1 = M 1" from "5" (*‹is_quantum_predicate P› ‹is_quantum_predicate Q› ‹⊢⇩p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}› ‹well_com S ⟹ ⊨⇩p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}› ‹well_com (While (M::nat ⇒ complex mat) (S::com))›*) have wcs: "well_com S" and c: "⊨⇩p {Q} S {adjoint M0 * P * M0 + adjoint M1 * Q * M1}" and m: "measurement d 2 M" and dM0: "M0 ∈ carrier_mat d d" and dM1: "M1 ∈ carrier_mat d d" and dP: "P ∈ carrier_mat d d" and dQ: "Q ∈ carrier_mat d d" and qpQ: "is_quantum_predicate Q" and wc: "well_com (While M S)" using measurement_def (*‹measurement ?d ?n ?M = ((∀j<?n. ?M j ∈ carrier_mat ?d ?d) ∧ matrix_sum ?d (λj. adjoint (?M j) * ?M j) ?n = 1⇩m ?d)›*) is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) M0_def (*‹M0 = M 0›*) M1_def (*‹(M1::complex mat) = (M::nat ⇒ complex mat) (1::nat)›*) apply - (*goals: 1. ‹⟦is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); ⊢⇩p {Q} S::com {adjoint ((M::nat ⇒ complex mat) (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)}; well_com S ⟹ ⊨⇩p {Q} S {adjoint (M (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)}; well_com (While M S); ⋀(d::nat) (n::nat) M::nat ⇒ complex mat. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj::nat. adjoint (M j) * M j) n = 1⇩m d); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); (M0::complex mat) = M (0::nat); (M1::complex mat) = M (1::nat)⟧ ⟹ well_com S› 2. ‹⟦is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); ⊢⇩p {Q} S::com {adjoint ((M::nat ⇒ complex mat) (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)}; well_com S ⟹ ⊨⇩p {Q} S {adjoint (M (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)}; well_com (While M S); ⋀(d::nat) (n::nat) M::nat ⇒ complex mat. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj::nat. adjoint (M j) * M j) n = 1⇩m d); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); (M0::complex mat) = M (0::nat); (M1::complex mat) = M (1::nat)⟧ ⟹ ⊨⇩p {Q} S {adjoint M0 * P * M0 + adjoint M1 * Q * M1}› 3. ‹⟦is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); ⊢⇩p {Q} S::com {adjoint ((M::nat ⇒ complex mat) (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)}; well_com S ⟹ ⊨⇩p {Q} S {adjoint (M (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)}; well_com (While M S); ⋀(d::nat) (n::nat) M::nat ⇒ complex mat. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj::nat. adjoint (M j) * M j) n = 1⇩m d); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); (M0::complex mat) = M (0::nat); (M1::complex mat) = M (1::nat)⟧ ⟹ measurement d (2::nat) M› 4. ‹⟦is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); ⊢⇩p {Q} S::com {adjoint ((M::nat ⇒ complex mat) (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)}; well_com S ⟹ ⊨⇩p {Q} S {adjoint (M (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)}; well_com (While M S); ⋀(d::nat) (n::nat) M::nat ⇒ complex mat. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj::nat. adjoint (M j) * M j) n = 1⇩m d); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); (M0::complex mat) = M (0::nat); (M1::complex mat) = M (1::nat)⟧ ⟹ M0 ∈ carrier_mat d d› 5. ‹⟦is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); ⊢⇩p {Q} S::com {adjoint ((M::nat ⇒ complex mat) (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)}; well_com S ⟹ ⊨⇩p {Q} S {adjoint (M (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)}; well_com (While M S); ⋀(d::nat) (n::nat) M::nat ⇒ complex mat. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj::nat. adjoint (M j) * M j) n = 1⇩m d); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); (M0::complex mat) = M (0::nat); (M1::complex mat) = M (1::nat)⟧ ⟹ M1 ∈ carrier_mat d d› 6. ‹⟦is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); ⊢⇩p {Q} S::com {adjoint ((M::nat ⇒ complex mat) (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)}; well_com S ⟹ ⊨⇩p {Q} S {adjoint (M (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)}; well_com (While M S); ⋀(d::nat) (n::nat) M::nat ⇒ complex mat. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj::nat. adjoint (M j) * M j) n = 1⇩m d); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); (M0::complex mat) = M (0::nat); (M1::complex mat) = M (1::nat)⟧ ⟹ P ∈ carrier_mat d d› 7. ‹⟦is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); ⊢⇩p {Q} S::com {adjoint ((M::nat ⇒ complex mat) (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)}; well_com S ⟹ ⊨⇩p {Q} S {adjoint (M (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)}; well_com (While M S); ⋀(d::nat) (n::nat) M::nat ⇒ complex mat. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj::nat. adjoint (M j) * M j) n = 1⇩m d); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); (M0::complex mat) = M (0::nat); (M1::complex mat) = M (1::nat)⟧ ⟹ Q ∈ carrier_mat d d› 8. ‹⟦is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); ⊢⇩p {Q} S::com {adjoint ((M::nat ⇒ complex mat) (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)}; well_com S ⟹ ⊨⇩p {Q} S {adjoint (M (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)}; well_com (While M S); ⋀(d::nat) (n::nat) M::nat ⇒ complex mat. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj::nat. adjoint (M j) * M j) n = 1⇩m d); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); (M0::complex mat) = M (0::nat); (M1::complex mat) = M (1::nat)⟧ ⟹ is_quantum_predicate Q› 9. ‹⟦is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); ⊢⇩p {Q} S::com {adjoint ((M::nat ⇒ complex mat) (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)}; well_com S ⟹ ⊨⇩p {Q} S {adjoint (M (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * Q * M (1::nat)}; well_com (While M S); ⋀(d::nat) (n::nat) M::nat ⇒ complex mat. measurement d n M = ((∀j<n. M j ∈ carrier_mat d d) ∧ matrix_sum d (λj::nat. adjoint (M j) * M j) n = 1⇩m d); ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d); (M0::complex mat) = M (0::nat); (M1::complex mat) = M (1::nat)⟧ ⟹ well_com (While M S)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*discuss goal 9*) apply ((auto)[1]) (*proven 9 subgoals*) . then have M0leq: "adjoint M0 * M0 ≤⇩L 1⇩m d" and M1leq: "adjoint M1 * M1 ≤⇩L 1⇩m d" using measurement_le_one_mat[OF m] (*‹?j < 2 ⟹ adjoint (M ?j) * M ?j ≤⇩L 1⇩m d›*) M0_def (*‹M0 = M 0›*) M1_def (*‹M1 = M 1›*) apply - (*goals: 1. ‹⟦well_com S; ⊨⇩p {Q} S {adjoint M0 * P * M0 + adjoint M1 * Q * M1}; measurement d 2 M; M0 ∈ carrier_mat d d; M1 ∈ carrier_mat d d; P ∈ carrier_mat d d; Q ∈ carrier_mat d d; is_quantum_predicate Q; well_com (While M S); ⋀j. j < 2 ⟹ adjoint (M j) * M j ≤⇩L 1⇩m d; M0 = M 0; M1 = M 1⟧ ⟹ adjoint M0 * M0 ≤⇩L 1⇩m d› 2. ‹⟦well_com S; ⊨⇩p {Q} S {adjoint M0 * P * M0 + adjoint M1 * Q * M1}; measurement d 2 M; M0 ∈ carrier_mat d d; M1 ∈ carrier_mat d d; P ∈ carrier_mat d d; Q ∈ carrier_mat d d; is_quantum_predicate Q; well_com (While M S); ⋀j. j < 2 ⟹ adjoint (M j) * M j ≤⇩L 1⇩m d; M0 = M 0; M1 = M 1⟧ ⟹ adjoint M1 * M1 ≤⇩L 1⇩m d› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . define DS where "DS = denote S" have "∀ρ ∈ density_states. trace (Q * ρ) ≤ trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * DS ρ) + trace ρ - trace (DS ρ)" using hoare_partial_correct_def[of Q S "adjoint M0 * P * M0 + adjoint M1 * Q * M1"] (*‹(⊨⇩p {Q} S {adjoint M0 * P * M0 + adjoint M1 * Q * M1}) = (∀ρ∈density_states. trace (Q * ρ) ≤ trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * denote S ρ) + (trace ρ - trace (denote S ρ)))›*) c (*‹⊨⇩p {Q} S {adjoint M0 * P * M0 + adjoint M1 * Q * M1}›*) DS_def (*‹DS = denote S›*) by (auto simp: less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) define D0 where "D0 = denote_while_n M0 M1 DS" define D1 where "D1 = denote_while_n_comp M0 M1 DS" define D where "D = denote_while_n_iter M0 M1 DS" { fix ρ assume dsr: "ρ ∈ density_states" (*‹(ρ::complex mat) ∈ density_states›*) then have dr: "ρ ∈ carrier_mat d d" and pr: "positive ρ" and pdor: "partial_density_operator ρ" using density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) partial_density_operator_def (*‹partial_density_operator ?A = (positive ?A ∧ trace ?A ≤ 1)›*) apply - (*goals: 1. ‹⟦ρ ∈ density_states; density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}; ⋀A. partial_density_operator A = (positive A ∧ trace A ≤ 1)⟧ ⟹ ρ ∈ carrier_mat d d› 2. ‹⟦ρ ∈ density_states; density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}; ⋀A. partial_density_operator A = (positive A ∧ trace A ≤ 1)⟧ ⟹ positive ρ› 3. ‹⟦ρ ∈ density_states; density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}; ⋀A. partial_density_operator A = (positive A ∧ trace A ≤ 1)⟧ ⟹ partial_density_operator ρ› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . have pdoDkr: "⋀k. partial_density_operator (D k ρ)" unfolding D_def (*goal: ‹⋀k. partial_density_operator (denote_while_n_iter M0 M1 DS k ρ)›*) using pdo_denote_while_n_iter[OF dr pdor dM1 M1leq] (*‹⟦⋀ρ. ρ ∈ carrier_mat d d ∧ partial_density_operator ρ ⟹ partial_density_operator (?DS ρ); ⋀ρ. ρ ∈ carrier_mat d d ∧ partial_density_operator ρ ⟹ ?DS ρ ∈ carrier_mat d d⟧ ⟹ partial_density_operator (denote_while_n_iter ?M0.0 M1 ?DS ?n ρ)›*) denote_partial_density_operator[OF wcs] (*‹⟦partial_density_operator ?ρ; ?ρ ∈ carrier_mat d d⟧ ⟹ partial_density_operator (denote S ?ρ)›*) denote_dim[OF wcs, folded DS_def] (*‹⟦?ρ ∈ carrier_mat d d; partial_density_operator ?ρ⟧ ⟹ DS ?ρ ∈ carrier_mat d d›*) apply (fold DS_def) (*goal: ‹⋀k. partial_density_operator (denote_while_n_iter M0 M1 DS k ρ)›*) by auto then have pDkr: "⋀k. positive (D k ρ)" unfolding partial_density_operator_def (*goal: ‹⋀k. positive (D k ρ)›*) by auto have dDkr: "⋀k. D k ρ ∈ carrier_mat d d" using denote_while_n_iter_dim[OF dr pdor dM1 M1leq denote_dim_pdo [ OF wcs , folded DS_def ], of id M0, simplified, folded D_def] (*‹D ?n ρ ∈ carrier_mat d d ∧ partial_density_operator (D ?n ρ)›*) by auto then have dD0kr: "⋀k. D0 k ρ ∈ carrier_mat d d" unfolding D0_def denote_while_n.simps (*goal: ‹⋀k::nat. (M0::complex mat) * denote_while_n_iter M0 (M1::complex mat) (DS::complex mat ⇒ complex mat) k (ρ::complex mat) * adjoint M0 ∈ carrier_mat d d›*) apply (fold D_def) (*goal: ‹⋀k::nat. (M0::complex mat) * denote_while_n_iter M0 (M1::complex mat) (DS::complex mat ⇒ complex mat) k (ρ::complex mat) * adjoint M0 ∈ carrier_mat d d›*) using dM0 (*‹M0 ∈ carrier_mat d d›*) by auto then have dPD0kr: "⋀k. P * (D0 k ρ) ∈ carrier_mat d d" using dP (*‹P ∈ carrier_mat d d›*) by auto have "⋀k. positive (D0 k ρ)" unfolding D0_def denote_while_n.simps (*goal: ‹⋀k. positive (M0 * denote_while_n_iter M0 M1 DS k ρ * adjoint M0)›*) apply (fold D_def) (*goal: ‹⋀k. positive (M0 * denote_while_n_iter M0 M1 DS k ρ * adjoint M0)›*) by (rule positive_close_under_left_right_mult_adjoint[OF dM0 dDkr pDkr] (*‹positive (M0 * D ?k1 ρ * adjoint M0)›*)) then have trge0: "⋀k. trace (D0 k ρ) ≥ 0" using positive_trace (*‹⟦?A ∈ carrier_mat ?n ?n; positive ?A⟧ ⟹ 0 ≤ trace ?A›*) dD0kr (*‹D0 ?k ρ ∈ carrier_mat d d›*) by blast have DSr: "ρ ∈ density_states ⟹ DS ρ ∈ density_states" for ρ unfolding DS_def density_states_def (*goal: ‹(ρ::complex mat) ∈ {ρ::complex mat ∈ carrier_mat d d. partial_density_operator ρ} ⟹ denote (S::com) ρ ∈ {ρ::complex mat ∈ carrier_mat d d. partial_density_operator ρ}›*) using denote_partial_density_operator (*‹⟦well_com (?S::com); partial_density_operator (?ρ::complex mat); ?ρ ∈ carrier_mat d d⟧ ⟹ partial_density_operator (denote ?S ?ρ)›*) denote_dim (*‹⟦well_com ?S; ?ρ ∈ carrier_mat d d; partial_density_operator ?ρ⟧ ⟹ denote ?S ?ρ ∈ carrier_mat d d›*) wcs (*‹well_com S›*) by auto have dsD1nr: "D1 n ρ ∈ density_states" for n unfolding D1_def denote_while_n_comp.simps (*goal: ‹M1 * denote_while_n_iter M0 M1 DS n ρ * adjoint M1 ∈ density_states›*) apply (fold D_def) (*goal: ‹M1 * denote_while_n_iter M0 M1 DS n ρ * adjoint M1 ∈ density_states›*) unfolding density_states_def (*goal: ‹M1 * D n ρ * adjoint M1 ∈ {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) apply auto (*goals: 1. ‹(M1::complex mat) * (D::nat ⇒ complex mat ⇒ complex mat) (n::nat) (ρ::complex mat) * adjoint M1 ∈ carrier_mat d d› 2. ‹partial_density_operator ((M1::complex mat) * (D::nat ⇒ complex mat ⇒ complex mat) (n::nat) (ρ::complex mat) * adjoint M1)› discuss goal 1*) apply ((insert dDkr (*‹D ?k ρ ∈ carrier_mat d d›*) dM1 (*‹M1 ∈ carrier_mat d d›*) adjoint_dim[OF dM1] (*‹adjoint M1 ∈ carrier_mat d d›*))[1]) (*top goal: ‹M1 * D n ρ * adjoint M1 ∈ carrier_mat d d› and 1 goal remains*) apply auto (*discuss goal 2*) apply ((insert dDkr (*‹(D::nat ⇒ complex mat ⇒ complex mat) (?k::nat) (ρ::complex mat) ∈ carrier_mat d d›*) dM1 (*‹(M1::complex mat) ∈ carrier_mat d d›*) adjoint_dim[OF dM1] (*‹adjoint (M1::complex mat) ∈ carrier_mat d d›*))[1]) (*goal: ‹partial_density_operator (M1 * D n ρ * adjoint M1)›*) apply (rule pdo_close_under_measurement[OF dM1 spec[OF allI[OF dDkr], of "λx. n"] spec[OF allI[OF pdoDkr], of "λx. n"] M1leq] (*‹partial_density_operator (M1 * D n ρ * adjoint M1)›*)) (*proven 2 subgoals*) . have leQn: "trace (Q * D1 n ρ) ≤ trace (P * D0 (Suc n) ρ) + trace (Q * D1 (Suc n) ρ) + trace (D1 n ρ) - trace (D (Suc n) ρ)" for n proof (-) (*goal: ‹trace (Q * D1 n ρ) ≤ trace (P * D0 (Suc n) ρ) + trace (Q * D1 (Suc n) ρ) + trace (D1 n ρ) - trace (D (Suc n) ρ)›*) have "(∀ρ∈density_states. trace (Q * ρ) ≤ trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * denote S ρ) + (trace ρ - trace (denote S ρ)))" using c (*‹⊨⇩p {Q} S {adjoint M0 * P * M0 + adjoint M1 * Q * M1}›*) hoare_partial_correct_def (*‹(⊨⇩p {?P} ?S {?Q}) = (∀ρ∈density_states. trace (?P * ρ) ≤ trace (?Q * denote ?S ρ) + (trace ρ - trace (denote ?S ρ)))›*) by auto then have leQn': "trace (Q * (D1 n ρ)) ≤ trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * (DS (D1 n ρ))) + (trace (D1 n ρ) - trace (DS (D1 n ρ)))" using dsD1nr[of n] (*‹D1 n ρ ∈ density_states›*) DS_def (*‹DS = denote S›*) by auto have "(DS (D1 n ρ)) ∈ carrier_mat d d" unfolding DS_def (*goal: ‹denote S (D1 n ρ) ∈ carrier_mat d d›*) using denote_dim[OF wcs] (*‹⟦?ρ ∈ carrier_mat d d; partial_density_operator ?ρ⟧ ⟹ denote S ?ρ ∈ carrier_mat d d›*) dsD1nr (*‹D1 ?n ρ ∈ density_states›*) density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) by auto then have "trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * (DS (D1 n ρ))) = trace (P * (M0 * (DS (D1 n ρ)) * adjoint M0)) + trace (Q * (M1 * (DS (D1 n ρ)) * adjoint M1))" using dP (*‹P ∈ carrier_mat d d›*) dQ (*‹Q ∈ carrier_mat d d›*) dM0 (*‹M0 ∈ carrier_mat d d›*) dM1 (*‹(M1::complex mat) ∈ carrier_mat d d›*) by (mat_assoc d) moreover have "trace (P * (M0 * (DS (D1 n ρ)) * adjoint M0)) = trace (P * D0 (Suc n) ρ)" unfolding D0_def denote_while_n.simps (*goal: ‹trace (P * (M0 * DS (D1 n ρ) * adjoint M0)) = trace (P * (M0 * denote_while_n_iter M0 M1 DS (Suc n) ρ * adjoint M0))›*) apply (subst denote_while_n_iter_assoc (*‹denote_while_n_iter ?M0.0 ?M1.0 ?DS (Suc ?n) ?ρ = ?DS (?M1.0 * denote_while_n_iter ?M0.0 ?M1.0 ?DS ?n ?ρ * adjoint ?M1.0)›*)) (*goal: ‹trace (P * (M0 * DS (D1 n ρ) * adjoint M0)) = trace (P * (M0 * denote_while_n_iter M0 M1 DS (Suc n) ρ * adjoint M0))›*) apply (fold denote_while_n_comp.simps D1_def) (*goal: ‹trace (P * (M0 * DS (D1 n ρ) * adjoint M0)) = trace (P * (M0 * DS (M1 * denote_while_n_iter M0 M1 DS n ρ * adjoint M1) * adjoint M0))›*) by auto moreover have "trace (Q * (M1 * (DS (D1 n ρ)) * adjoint M1)) = trace (Q * D1 (Suc n) ρ)" apply (subst (2) D1_def (*‹D1 = denote_while_n_comp M0 M1 DS›*)) (*goal: ‹trace (Q * (M1 * DS (D1 n ρ) * adjoint M1)) = trace (Q * D1 (Suc n) ρ)›*) unfolding denote_while_n_comp.simps (*goal: ‹trace (Q * (M1 * DS (D1 n ρ) * adjoint M1)) = trace (Q * (M1 * denote_while_n_iter M0 M1 DS (Suc n) ρ * adjoint M1))›*) apply (subst denote_while_n_iter_assoc (*‹denote_while_n_iter ?M0.0 ?M1.0 ?DS (Suc ?n) ?ρ = ?DS (?M1.0 * denote_while_n_iter ?M0.0 ?M1.0 ?DS ?n ?ρ * adjoint ?M1.0)›*)) (*goal: ‹trace (Q * (M1 * DS (D1 n ρ) * adjoint M1)) = trace (Q * (M1 * denote_while_n_iter M0 M1 DS (Suc n) ρ * adjoint M1))›*) apply (fold denote_while_n_comp.simps D1_def) (*goal: ‹trace ((Q::complex mat) * ((M1::complex mat) * (DS::complex mat ⇒ complex mat) ((D1::nat ⇒ complex mat ⇒ complex mat) (n::nat) (ρ::complex mat)) * adjoint M1)) = trace (Q * (M1 * DS (M1 * denote_while_n_iter (M0::complex mat) M1 DS n ρ * adjoint M1) * adjoint M1))›*) by auto ultimately have "trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * (DS (D1 n ρ))) = trace (P * D0 (Suc n) ρ) + trace (Q * D1 (Suc n) ρ)" by auto moreover have "trace (DS (D1 n ρ)) = trace (D (Suc n) ρ)" unfolding D_def (*goal: ‹trace (DS (D1 n ρ)) = trace (denote_while_n_iter M0 M1 DS (Suc n) ρ)›*) apply (subst denote_while_n_iter_assoc (*‹denote_while_n_iter ?M0.0 ?M1.0 ?DS (Suc ?n) ?ρ = ?DS (?M1.0 * denote_while_n_iter ?M0.0 ?M1.0 ?DS ?n ?ρ * adjoint ?M1.0)›*)) (*goal: ‹trace (DS (D1 n ρ)) = trace (denote_while_n_iter M0 M1 DS (Suc n) ρ)›*) apply (fold denote_while_n_comp.simps D1_def) (*goal: ‹trace ((DS::complex mat ⇒ complex mat) ((D1::nat ⇒ complex mat ⇒ complex mat) (n::nat) (ρ::complex mat))) = trace (DS ((M1::complex mat) * denote_while_n_iter (M0::complex mat) M1 DS n ρ * adjoint M1))›*) by auto ultimately show "?thesis" (*goal: ‹trace (Q * D1 n ρ) ≤ trace (P * D0 (Suc n) ρ) + trace (Q * D1 (Suc n) ρ) + trace (D1 n ρ) - trace (D (Suc n) ρ)›*) using leQn' (*‹trace (Q * D1 n ρ) ≤ trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * DS (D1 n ρ)) + (trace (D1 n ρ) - trace (DS (D1 n ρ)))›*) by (auto simp: less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) qed have 12: "trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ (∑k=0..<(n+2). trace (P * (D0 k ρ))) + trace (Q * (D1 (n+1) ρ)) + (∑k=0..<(n+1). trace (D1 k ρ) - trace (D (k+1) ρ))" for n proof (induct n) (*goals: 1. ‹trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ (∑k = 0..<0 + 2. trace (P * D0 k ρ)) + trace (Q * D1 (0 + 1) ρ) + (∑k = 0..<0 + 1. trace (D1 k ρ) - trace (D (k + 1) ρ))› 2. ‹⋀n. trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ (∑k = 0..<n + 2. trace (P * D0 k ρ)) + trace (Q * D1 (n + 1) ρ) + (∑k = 0..<n + 1. trace (D1 k ρ) - trace (D (k + 1) ρ)) ⟹ trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ (∑k = 0..<Suc n + 2. trace (P * D0 k ρ)) + trace (Q * D1 (Suc n + 1) ρ) + (∑k = 0..<Suc n + 1. trace (D1 k ρ) - trace (D (k + 1) ρ))›*) case 0 (*no hyothesis introduced yet*) show "?case" (*goal: ‹trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ (∑k = 0..<0 + 2. trace (P * D0 k ρ)) + trace (Q * D1 (0 + 1) ρ) + (∑k = 0..<0 + 1. trace (D1 k ρ) - trace (D (k + 1) ρ))›*) apply (simp del: less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) (*goal: ‹trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ (∑k = 0..<0 + 2. trace (P * D0 k ρ)) + trace (Q * D1 (0 + 1) ρ) + (∑k = 0..<0 + 1. trace (D1 k ρ) - trace (D (k + 1) ρ))›*) unfolding D0_def D1_def D_def denote_while_n_comp.simps denote_while_n.simps denote_while_n_iter.simps (*goal: ‹trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ trace (P * (M0 * ρ * adjoint M0)) + trace (P * (M0 * DS (M1 * ρ * adjoint M1) * adjoint M0)) + trace (Q * (M1 * DS (M1 * ρ * adjoint M1) * adjoint M1)) + (trace (M1 * ρ * adjoint M1) - trace (DS (M1 * ρ * adjoint M1)))›*) using leQn[of 0] (*‹trace (Q * D1 0 ρ) ≤ trace (P * D0 (Suc 0) ρ) + trace (Q * D1 (Suc 0) ρ) + trace (D1 0 ρ) - trace (D (Suc 0) ρ)›*) unfolding D1_def D0_def D_def denote_while_n.simps denote_while_n_comp.simps denote_while_n_iter.simps (*goal: ‹trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ trace (P * (M0 * ρ * adjoint M0)) + trace (P * (M0 * DS (M1 * ρ * adjoint M1) * adjoint M0)) + trace (Q * (M1 * DS (M1 * ρ * adjoint M1) * adjoint M1)) + (trace (M1 * ρ * adjoint M1) - trace (DS (M1 * ρ * adjoint M1)))›*) by (auto simp: less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) next (*goal: ‹⋀n. trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ (∑k = 0..<n + 2. trace (P * D0 k ρ)) + trace (Q * D1 (n + 1) ρ) + (∑k = 0..<n + 1. trace (D1 k ρ) - trace (D (k + 1) ρ)) ⟹ trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ (∑k = 0..<Suc n + 2. trace (P * D0 k ρ)) + trace (Q * D1 (Suc n + 1) ρ) + (∑k = 0..<Suc n + 1. trace (D1 k ρ) - trace (D (k + 1) ρ))›*) case (Suc n) (*‹trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ (∑k = 0..<n + 2. trace (P * D0 k ρ)) + trace (Q * D1 (n + 1) ρ) + (∑k = 0..<n + 1. trace (D1 k ρ) - trace (D (k + 1) ρ))›*) have "trace (Q * D1 (n + 1) ρ) ≤ trace (P * D0 (Suc (Suc n)) ρ) + trace (Q * D1 (Suc (Suc n)) ρ) + trace (D1 (Suc n) ρ) - trace (D (Suc (Suc n)) ρ)" using leQn[of "n + 1"] (*‹trace (Q * D1 (n + 1) ρ) ≤ trace (P * D0 (Suc (n + 1)) ρ) + trace (Q * D1 (Suc (n + 1)) ρ) + trace (D1 (n + 1) ρ) - trace (D (Suc (n + 1)) ρ)›*) by auto with Suc (*‹trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ (∑k = 0..<n + 2. trace (P * D0 k ρ)) + trace (Q * D1 (n + 1) ρ) + (∑k = 0..<n + 1. trace (D1 k ρ) - trace (D (k + 1) ρ))›*) show "?case" (*goal: ‹trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ (∑k = 0..<Suc n + 2. trace (P * D0 k ρ)) + trace (Q * D1 (Suc n + 1) ρ) + (∑k = 0..<Suc n + 1. trace (D1 k ρ) - trace (D (k + 1) ρ))›*) apply (simp del: less_eq_complex_def (*‹((?x::complex) ≤ (?y::complex)) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) (*goal: ‹trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ (∑k = 0..<Suc n + 2. trace (P * D0 k ρ)) + trace (Q * D1 (Suc n + 1) ρ) + (∑k = 0..<Suc n + 1. trace (D1 k ρ) - trace (D (k + 1) ρ))›*) by (auto simp: less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) qed have tr_measurement: "ρ ∈ carrier_mat d d ⟹ trace (M0 * ρ * adjoint M0) + trace (M1 * ρ * adjoint M1) = trace ρ" for ρ using trace_measurement2[OF m, folded M0_def M1_def] (*‹(?A::complex mat) ∈ carrier_mat d d ⟹ trace ((M0::complex mat) * ?A * adjoint M0) + trace ((M1::complex mat) * ?A * adjoint M1) = trace ?A›*) by auto have 14: "(∑k=0..<(n+1). trace (D1 k ρ) - trace (D (k+1) ρ)) = trace ρ - trace (D (n+1) ρ) - (∑k=0..<(n+1). trace (D0 k ρ))" for n proof (induct n) (*goals: 1. ‹(∑k = 0..<0 + 1. trace (D1 k ρ) - trace (D (k + 1) ρ)) = trace ρ - trace (D (0 + 1) ρ) - (∑k = 0..<0 + 1. trace (D0 k ρ))› 2. ‹⋀n. (∑k = 0..<n + 1. trace (D1 k ρ) - trace (D (k + 1) ρ)) = trace ρ - trace (D (n + 1) ρ) - (∑k = 0..<n + 1. trace (D0 k ρ)) ⟹ (∑k = 0..<Suc n + 1. trace (D1 k ρ) - trace (D (k + 1) ρ)) = trace ρ - trace (D (Suc n + 1) ρ) - (∑k = 0..<Suc n + 1. trace (D0 k ρ))›*) case 0 (*no hyothesis introduced yet*) show "?case" (*goal: ‹(∑k = 0..<0 + 1. trace (D1 k ρ) - trace (D (k + 1) ρ)) = trace ρ - trace (D (0 + 1) ρ) - (∑k = 0..<0 + 1. trace (D0 k ρ))›*) apply simp (*goal: ‹(∑k = 0..<0 + 1. trace (D1 k ρ) - trace (D (k + 1) ρ)) = trace ρ - trace (D (0 + 1) ρ) - (∑k = 0..<0 + 1. trace (D0 k ρ))›*) unfolding D1_def D0_def denote_while_n_comp.simps denote_while_n.simps denote_while_n_iter.simps (*goal: ‹trace (M1 * ρ * adjoint M1) = trace ρ - trace (M0 * ρ * adjoint M0)›*) using tr_measurement[OF dr] (*‹trace (M0 * ρ * adjoint M0) + trace (M1 * ρ * adjoint M1) = trace ρ›*) by (auto simp add: algebra_simps (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)› ‹(?a::?'a) * (?b::?'a) * (?c::?'a) = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)› ‹(?a::?'a) - (?b::?'a) - (?c::?'a) = ?a - (?b + ?c)› ‹(?a::?'a) + ((?b::?'a) - (?c::?'a)) = ?a + ?b - ?c› ‹((?a::?'a) - (?b::?'a) = (?c::?'a)) = (?a = ?c + ?b)› ‹((?a::?'a) = (?c::?'a) - (?b::?'a)) = (?a + ?b = ?c)› ‹(?a::?'a) - ((?b::?'a) - (?c::?'a)) = ?a + ?c - ?b› ‹(?a::?'a) - (?b::?'a) + (?c::?'a) = ?a + ?c - ?b› and more 23 facts*)) next (*goal: ‹⋀n. (∑k = 0..<n + 1. trace (D1 k ρ) - trace (D (k + 1) ρ)) = trace ρ - trace (D (n + 1) ρ) - (∑k = 0..<n + 1. trace (D0 k ρ)) ⟹ (∑k = 0..<Suc n + 1. trace (D1 k ρ) - trace (D (k + 1) ρ)) = trace ρ - trace (D (Suc n + 1) ρ) - (∑k = 0..<Suc n + 1. trace (D0 k ρ))›*) case (Suc n) (*‹(∑k = 0..<n + 1. trace (D1 k ρ) - trace (D (k + 1) ρ)) = trace ρ - trace (D (n + 1) ρ) - (∑k = 0..<n + 1. trace (D0 k ρ))›*) have "trace (D0 (Suc n) ρ) + trace (D1 (Suc n) ρ) = trace (D (Suc n) ρ)" unfolding D0_def D1_def denote_while_n.simps denote_while_n_comp.simps (*goal: ‹trace (M0 * denote_while_n_iter M0 M1 DS (Suc n) ρ * adjoint M0) + trace (M1 * denote_while_n_iter M0 M1 DS (Suc n) ρ * adjoint M1) = trace (D (Suc n) ρ)›*) apply (fold D_def) (*goal: ‹trace ((M0::complex mat) * denote_while_n_iter M0 (M1::complex mat) (DS::complex mat ⇒ complex mat) (Suc (n::nat)) (ρ::complex mat) * adjoint M0) + trace (M1 * denote_while_n_iter M0 M1 DS (Suc n) ρ * adjoint M1) = trace ((D::nat ⇒ complex mat ⇒ complex mat) (Suc n) ρ)›*) using tr_measurement (*‹?ρ ∈ carrier_mat d d ⟹ trace (M0 * ?ρ * adjoint M0) + trace (M1 * ?ρ * adjoint M1) = trace ?ρ›*) dDkr (*‹D ?k ρ ∈ carrier_mat d d›*) by auto then have "trace (D1 (Suc n) ρ) = trace (D (Suc n) ρ) - trace (D0 (Suc n) ρ)" by (auto simp add: algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 23 facts*)) then show "?case" (*goal: ‹(∑k::nat = 0::nat..<Suc (n::nat) + (1::nat). trace ((D1::nat ⇒ complex mat ⇒ complex mat) k (ρ::complex mat)) - trace ((D::nat ⇒ complex mat ⇒ complex mat) (k + (1::nat)) ρ)) = trace ρ - trace (D (Suc n + (1::nat)) ρ) - (∑k::nat = 0::nat..<Suc n + (1::nat). trace ((D0::nat ⇒ complex mat ⇒ complex mat) k ρ))›*) using Suc (*‹(∑k = 0..<n + 1. trace (D1 k ρ) - trace (D (k + 1) ρ)) = trace ρ - trace (D (n + 1) ρ) - (∑k = 0..<n + 1. trace (D0 k ρ))›*) by simp qed have 15: "trace (Q * (D1 n ρ)) ≤ trace (D n ρ) - trace (D0 n ρ)" for n proof (-) (*goal: ‹trace (Q * D1 n ρ) ≤ trace (D n ρ) - trace (D0 n ρ)›*) have QleId: "Q ≤⇩L 1⇩m d" using is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) qpQ (*‹is_quantum_predicate Q›*) by auto then have "trace (Q * (D1 n ρ)) ≤ trace (1⇩m d * (D1 n ρ))" using dsD1nr[of n] (*‹D1 n ρ ∈ density_states›*) unfolding density_states_def lowner_le_trace[OF dQ one_carrier_mat] (*goal: ‹trace (Q * D1 n ρ) ≤ trace (1⇩m d * D1 n ρ)›*) by auto also (*calculation: ‹trace (Q * D1 n ρ) ≤ trace (1⇩m d * D1 n ρ)›*) have "… = trace (D1 n ρ)" using dsD1nr[of n] (*‹D1 n ρ ∈ density_states›*) unfolding density_states_def (*goal: ‹trace (1⇩m d * D1 n ρ) = trace (D1 n ρ)›*) by auto also (*calculation: ‹trace (Q * D1 n ρ) ≤ trace (D1 n ρ)›*) have "… = trace (M1 * (D n ρ) * adjoint M1)" unfolding D1_def denote_while_n_comp.simps D_def (*goal: ‹trace (M1 * denote_while_n_iter M0 M1 DS n ρ * adjoint M1) = trace (M1 * denote_while_n_iter M0 M1 DS n ρ * adjoint M1)›*) by auto also (*calculation: ‹trace (Q * D1 n ρ) ≤ trace (M1 * D n ρ * adjoint M1)›*) have "… = trace (D n ρ) - trace (M0 * (D n ρ) * adjoint M0)" using tr_measurement[OF dDkr [ of n ]] (*‹trace ((M0::complex mat) * (D::nat ⇒ complex mat ⇒ complex mat) (n::nat) (ρ::complex mat) * adjoint M0) + trace ((M1::complex mat) * D n ρ * adjoint M1) = trace (D n ρ)›*) by (simp add: algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 23 facts*)) also (*calculation: ‹trace (Q * D1 n ρ) ≤ trace (D n ρ) - trace (M0 * D n ρ * adjoint M0)›*) have "… = trace (D n ρ) - trace (D0 n ρ)" unfolding D0_def denote_while_n.simps (*goal: ‹trace (D n ρ) - trace (M0 * D n ρ * adjoint M0) = trace (D n ρ) - trace (M0 * denote_while_n_iter M0 M1 DS n ρ * adjoint M0)›*) apply (fold D_def) (*goal: ‹trace (D n ρ) - trace (M0 * D n ρ * adjoint M0) = trace (D n ρ) - trace (M0 * denote_while_n_iter M0 M1 DS n ρ * adjoint M0)›*) by auto finally (*calculation: ‹trace (Q * D1 n ρ) ≤ trace (D n ρ) - trace (D0 n ρ)›*) show "?thesis" (*goal: ‹trace (Q * D1 n ρ) ≤ trace (D n ρ) - trace (D0 n ρ)›*) . qed have tmp: "⋀a b c. 0 ≤ a ⟹ b ≤ c - a ⟹ b ≤ (c::complex)" by (simp add: less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) then have 151: "⋀n. trace (Q * (D1 n ρ)) ≤ trace (D n ρ)" by (auto simp add: tmp[OF trge0 15] (*‹trace (Q * D1 ?n1 ρ) ≤ trace (D ?n1 ρ)›*) simp del: less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) have main_leq: "⋀n. trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ trace (P * (matrix_sum d (λk. D0 k ρ) (n+2))) + trace ρ - trace (matrix_sum d (λk. D0 k ρ) (n+2))" proof (-) (*goal: ‹⋀n. trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ trace (P * matrix_sum d (λk. D0 k ρ) (n + 2)) + trace ρ - trace (matrix_sum d (λk. D0 k ρ) (n + 2))›*) fix n have "(∑k=0..<(n+2). trace (P * (D0 k ρ))) + trace (Q * (D1 (n+1) ρ)) + (∑k=0..<(n+1). trace (D1 k ρ) - trace (D (k+1) ρ)) ≤ (∑k=0..<(n+2). trace (P * (D0 k ρ))) + trace (Q * (D1 (n+1) ρ)) + trace ρ - trace (D (n+1) ρ) - (∑k=0..<(n+1). trace (D0 k ρ))" apply (subst 14 (*‹(∑k::nat = 0::nat..<(?n::nat) + (1::nat). trace ((D1::nat ⇒ complex mat ⇒ complex mat) k (ρ::complex mat)) - trace ((D::nat ⇒ complex mat ⇒ complex mat) (k + (1::nat)) ρ)) = trace ρ - trace (D (?n + (1::nat)) ρ) - (∑k::nat = 0::nat..<?n + (1::nat). trace ((D0::nat ⇒ complex mat ⇒ complex mat) k ρ))›*)) (*goal: ‹(∑k = 0..<n + 2. trace (P * D0 k ρ)) + trace (Q * D1 (n + 1) ρ) + (∑k = 0..<n + 1. trace (D1 k ρ) - trace (D (k + 1) ρ)) ≤ (∑k = 0..<n + 2. trace (P * D0 k ρ)) + trace (Q * D1 (n + 1) ρ) + trace ρ - trace (D (n + 1) ρ) - (∑k = 0..<n + 1. trace (D0 k ρ))›*) by auto also (*calculation: ‹(∑k::nat = 0::nat..<(n::nat) + (2::nat). trace ((P::complex mat) * (D0::nat ⇒ complex mat ⇒ complex mat) k (ρ::complex mat))) + trace ((Q::complex mat) * (D1::nat ⇒ complex mat ⇒ complex mat) (n + (1::nat)) ρ) + (∑k::nat = 0::nat..<n + (1::nat). trace (D1 k ρ) - trace ((D::nat ⇒ complex mat ⇒ complex mat) (k + (1::nat)) ρ)) ≤ (∑k::nat = 0::nat..<n + (2::nat). trace (P * D0 k ρ)) + trace (Q * D1 (n + (1::nat)) ρ) + trace ρ - trace (D (n + (1::nat)) ρ) - (∑k::nat = 0::nat..<n + (1::nat). trace (D0 k ρ))›*) have "… ≤ (∑k=0..<(n+2). trace (P * (D0 k ρ))) + trace (D (n+1) ρ) - trace (D0 (n+1) ρ) + trace ρ - trace (D (n+1) ρ) - (∑k=0..<(n+1). trace (D0 k ρ))" using "15"[of "n+1"] (*‹trace (Q * D1 (n + 1) ρ) ≤ trace (D (n + 1) ρ) - trace (D0 (n + 1) ρ)›*) by (auto simp: less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) also (*calculation: ‹(∑k = 0..<n + 2. trace (P * D0 k ρ)) + trace (Q * D1 (n + 1) ρ) + (∑k = 0..<n + 1. trace (D1 k ρ) - trace (D (k + 1) ρ)) ≤ (∑k = 0..<n + 2. trace (P * D0 k ρ)) + trace (D (n + 1) ρ) - trace (D0 (n + 1) ρ) + trace ρ - trace (D (n + 1) ρ) - (∑k = 0..<n + 1. trace (D0 k ρ))›*) have "… = (∑k=0..<(n+2). trace (P * (D0 k ρ))) + trace ρ - (∑k=0..<(n+2). trace (D0 k ρ))" by auto also (*calculation: ‹(∑k = 0..<n + 2. trace (P * D0 k ρ)) + trace (Q * D1 (n + 1) ρ) + (∑k = 0..<n + 1. trace (D1 k ρ) - trace (D (k + 1) ρ)) ≤ (∑k = 0..<n + 2. trace (P * D0 k ρ)) + trace ρ - (∑k = 0..<n + 2. trace (D0 k ρ))›*) have "… = trace (matrix_sum d (λk. (P * (D0 k ρ))) (n+2)) + trace ρ - (∑k=0..<(n+2). trace (D0 k ρ))" using trace_matrix_sum_linear[of "n+2" "λk. (P * (D0 k ρ))" d, symmetric] (*‹(⋀k. k < n + 2 ⟹ P * D0 k ρ ∈ carrier_mat d d) ⟹ (∑k = 0..<n + 2. trace (P * D0 k ρ)) = trace (matrix_sum d (λk. P * D0 k ρ) (n + 2))›*) dPD0kr (*‹P * D0 ?k ρ ∈ carrier_mat d d›*) by auto also (*calculation: ‹(∑k = 0..<n + 2. trace (P * D0 k ρ)) + trace (Q * D1 (n + 1) ρ) + (∑k = 0..<n + 1. trace (D1 k ρ) - trace (D (k + 1) ρ)) ≤ trace (matrix_sum d (λk. P * D0 k ρ) (n + 2)) + trace ρ - (∑k = 0..<n + 2. trace (D0 k ρ))›*) have "… = trace (matrix_sum d (λk. (P * (D0 k ρ))) (n+2)) + trace ρ - trace (matrix_sum d (λk. D0 k ρ) (n+2))" using trace_matrix_sum_linear[of "n+2" "λk. D0 k ρ" d, symmetric] (*‹(⋀k. k < n + 2 ⟹ D0 k ρ ∈ carrier_mat d d) ⟹ (∑k = 0..<n + 2. trace (D0 k ρ)) = trace (matrix_sum d (λk. D0 k ρ) (n + 2))›*) dD0kr (*‹D0 ?k ρ ∈ carrier_mat d d›*) by auto also (*calculation: ‹(∑k = 0..<n + 2. trace (P * D0 k ρ)) + trace (Q * D1 (n + 1) ρ) + (∑k = 0..<n + 1. trace (D1 k ρ) - trace (D (k + 1) ρ)) ≤ trace (matrix_sum d (λk. P * D0 k ρ) (n + 2)) + trace ρ - trace (matrix_sum d (λk. D0 k ρ) (n + 2))›*) have "… = trace (P * (matrix_sum d (λk. D0 k ρ) (n+2))) + trace ρ - trace (matrix_sum d (λk. D0 k ρ) (n+2))" using matrix_sum_distrib_left[OF dP dD0kr, of id "n+2"] (*‹matrix_sum d (λk::nat. (P::complex mat) * (D0::nat ⇒ complex mat ⇒ complex mat) (id k) (ρ::complex mat)) ((n::nat) + (2::nat)) = P * matrix_sum d (λk::nat. D0 (id k) ρ) (n + (2::nat))›*) by auto finally (*calculation: ‹(∑k = 0..<n + 2. trace (P * D0 k ρ)) + trace (Q * D1 (n + 1) ρ) + (∑k = 0..<n + 1. trace (D1 k ρ) - trace (D (k + 1) ρ)) ≤ trace (P * matrix_sum d (λk. D0 k ρ) (n + 2)) + trace ρ - trace (matrix_sum d (λk. D0 k ρ) (n + 2))›*) have "(∑k=0..<(n+2). trace (P * (D0 k ρ))) + trace (Q * (D1 (n+1) ρ)) + (∑k=0..<(n+1). trace (D1 k ρ) - trace (D (k+1) ρ)) ≤ trace (P * (matrix_sum d (λk. D0 k ρ) (n+2))) + trace ρ - trace (matrix_sum d (λk. D0 k ρ) (n+2))" . then show "trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ trace (P * (matrix_sum d (λk. D0 k ρ) (n+2))) + trace ρ - trace (matrix_sum d (λk. D0 k ρ) (n+2))" using "12"[of n] (*‹trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ (∑k = 0..<n + 2. trace (P * D0 k ρ)) + trace (Q * D1 (n + 1) ρ) + (∑k = 0..<n + 1. trace (D1 k ρ) - trace (D (k + 1) ρ))›*) by auto qed have "limit_mat (λn. matrix_sum d (λk. D0 k ρ) (n)) (denote (While M S) ρ) d" using limit_mat_denote_while_n[OF wc dr pdor] (*‹limit_mat (matrix_sum d (λk::nat. denote_while_n ((M::nat ⇒ complex mat) (0::nat)) (M (1::nat)) (denote (S::com)) k (ρ::complex mat))) (denote (While M S) ρ) d›*) unfolding D0_def M0_def M1_def DS_def (*goal: ‹limit_mat (matrix_sum d (λk. denote_while_n (M 0) (M 1) (denote S) k ρ)) (denote (While M S) ρ) d›*) by auto then have limp2: "limit_mat (λn. matrix_sum d (λk. D0 k ρ) (n + 2)) (denote (While M S) ρ) d" using limit_mat_ignore_initial_segment[of "λn. matrix_sum d (λk. D0 k ρ) (n)" "(denote (While M S) ρ)" d 2] (*‹limit_mat (matrix_sum d (λk::nat. (D0::nat ⇒ complex mat ⇒ complex mat) k (ρ::complex mat))) (denote (While (M::nat ⇒ complex mat) (S::com)) ρ) d ⟹ limit_mat (λn::nat. matrix_sum d (λk::nat. D0 k ρ) (n + (2::nat))) (denote (While M S) ρ) d›*) by auto then have "limit_mat (λn. (P * (matrix_sum d (λk. D0 k ρ) (n+2)))) (P * (denote (While M S) ρ)) d" using mat_mult_limit[OF dP] (*‹limit_mat ?X ?A d ⟹ limit_mat (mat_mult_seq P ?X) (P * ?A) d›*) unfolding mat_mult_seq_def (*goal: ‹limit_mat (λn. P * matrix_sum d (λk. D0 k ρ) (n + 2)) (P * denote (While M S) ρ) d›*) by auto then have limPm: "(λn. trace (P * (matrix_sum d (λk. D0 k ρ) (n+2)))) ⇢ trace (P * (denote (While M S) ρ))" using mat_trace_limit (*‹limit_mat ?g ?A ?d ⟹ (λn. trace (?g n)) ⇢ trace ?A›*) by auto have limm: "(λn. trace (matrix_sum d (λk. D0 k ρ) (n+2))) ⇢ trace (denote (While M S) ρ)" using mat_trace_limit (*‹limit_mat ?g ?A ?d ⟹ (λn. trace (?g n)) ⇢ trace ?A›*) limp2 (*‹limit_mat (λn. matrix_sum d (λk. D0 k ρ) (n + 2)) (denote (While M S) ρ) d›*) by auto have leq_lim: "trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ trace (P * (denote (While M S) ρ)) + trace ρ - trace (denote (While M S) ρ)" (is "?lhs ≤ ?rhs") using main_leq (*‹trace ((P::complex mat) * ((M0::complex mat) * (ρ::complex mat) * adjoint M0)) + trace ((Q::complex mat) * ((M1::complex mat) * ρ * adjoint M1)) ≤ trace (P * matrix_sum d (λk::nat. (D0::nat ⇒ complex mat ⇒ complex mat) k ρ) ((?n::nat) + (2::nat))) + trace ρ - trace (matrix_sum d (λk::nat. D0 k ρ) (?n + (2::nat)))›*) proof (-) (*goal: ‹(⋀n. trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ trace (P * matrix_sum d (λk. D0 k ρ) (n + 2)) + trace ρ - trace (matrix_sum d (λk. D0 k ρ) (n + 2))) ⟹ trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ trace (P * denote (While M S) ρ) + trace ρ - trace (denote (While M S) ρ)›*) define seq where "seq n = trace (P * matrix_sum d (λk. D0 k ρ) (n + 2)) - trace (matrix_sum d (λk. D0 k ρ) (n + 2)) " for n define seqlim where "seqlim = trace (P * (denote (While M S) ρ)) - trace (denote (While M S) ρ)" have main_leq': "?lhs ≤ trace ρ + seq n" for n unfolding seq_def (*goal: ‹trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ trace ρ + (trace (P * matrix_sum d (λk. D0 k ρ) (n + 2)) - trace (matrix_sum d (λk. D0 k ρ) (n + 2)))›*) using main_leq (*‹trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ trace (P * matrix_sum d (λk. D0 k ρ) (?n + 2)) + trace ρ - trace (matrix_sum d (λk. D0 k ρ) (?n + 2))›*) by (simp add: algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 23 facts*)) have limseq: "seq ⇢ seqlim" unfolding seq_def seqlim_def (*goal: ‹(λn. trace (P * matrix_sum d (λk. D0 k ρ) (n + 2)) - trace (matrix_sum d (λk. D0 k ρ) (n + 2))) ⇢ trace (P * denote (While M S) ρ) - trace (denote (While M S) ρ)›*) using tendsto_diff[OF limPm limm] (*‹(λx::nat. trace ((P::complex mat) * matrix_sum d (λk::nat. (D0::nat ⇒ complex mat ⇒ complex mat) k (ρ::complex mat)) (x + (2::nat))) - trace (matrix_sum d (λk::nat. D0 k ρ) (x + (2::nat)))) ⇢ trace (P * denote (While (M::nat ⇒ complex mat) (S::com)) ρ) - trace (denote (While M S) ρ)›*) by auto have limrs: "(λn. trace ρ + seq n) ⇢ (trace ρ + seqlim)" using tendsto_add[OF _ limseq] (*‹?f ⇢ ?a ⟹ (λx. ?f x + seq x) ⇢ ?a + seqlim›*) by auto have limrsRe: "(λn. Re (trace ρ + seq n)) ⇢ Re (trace ρ + seqlim)" using tendsto_Re[OF limrs] (*‹(λx. Re (trace ρ + seq x)) ⇢ Re (trace ρ + seqlim)›*) by auto have main_leq_Re: "Re ?lhs ≤ Re (trace ρ + seq n)" for n using main_leq' (*‹trace ((P::complex mat) * ((M0::complex mat) * (ρ::complex mat) * adjoint M0)) + trace ((Q::complex mat) * ((M1::complex mat) * ρ * adjoint M1)) ≤ trace ρ + (seq::nat ⇒ complex) (?n::nat)›*) by (auto simp: less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) have Re: "Re ?lhs ≤ Re (trace ρ + seqlim)" using Lim_bounded2[OF limrsRe] (*‹∀n≥?N. ?C ≤ Re (trace ρ + seq n) ⟹ ?C ≤ Re (trace ρ + seqlim)›*) main_leq_Re (*‹Re (trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1))) ≤ Re (trace ρ + seq ?n)›*) by (auto simp: less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) have limrsIm: "(λn. Im (trace ρ + seq n)) ⇢ Im (trace ρ + seqlim)" using tendsto_Im[OF limrs] (*‹(λx. Im (trace ρ + seq x)) ⇢ Im (trace ρ + seqlim)›*) by auto have main_leq_Im: "Im ?lhs = Im (trace ρ + seq n)" for n using main_leq' (*‹trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ trace ρ + seq ?n›*) unfolding less_eq_complex_def (*goal: ‹Im (trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1))) = Im (trace ρ + seq n)›*) by auto then have limIm: "(λn. Im (trace ρ + seq n)) ⇢ Im ?lhs" using tendsto_intros(1) (*‹((λx. x) ⤏ ?a) (at ?a within ?s)›*) by auto have Im: "Im ?lhs = Im (trace ρ + seqlim)" using tendsto_unique[OF _ limIm limrsIm] (*‹sequentially ≠ bot ⟹ Im (trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1))) = Im (trace ρ + seqlim)›*) by auto have "?lhs ≤ trace ρ + seqlim" using Re (*‹Re (trace ((P::complex mat) * ((M0::complex mat) * (ρ::complex mat) * adjoint M0)) + trace ((Q::complex mat) * ((M1::complex mat) * ρ * adjoint M1))) ≤ Re (trace ρ + (seqlim::complex))›*) Im (*‹Im (trace ((P::complex mat) * ((M0::complex mat) * (ρ::complex mat) * adjoint M0)) + trace ((Q::complex mat) * ((M1::complex mat) * ρ * adjoint M1))) = Im (trace ρ + (seqlim::complex))›*) by (auto simp: less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) then show "?lhs ≤ ?rhs" unfolding seqlim_def (*goal: ‹trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ trace (P * denote (While M S) ρ) + trace ρ - trace (denote (While M S) ρ)›*) by (auto simp: less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) qed have "trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * ρ) = trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1))" using dr (*‹ρ ∈ carrier_mat d d›*) dM0 (*‹M0 ∈ carrier_mat d d›*) dM1 (*‹M1 ∈ carrier_mat d d›*) dP (*‹(P::complex mat) ∈ carrier_mat d d›*) dQ (*‹Q ∈ carrier_mat d d›*) by (mat_assoc d) then have "trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * ρ) ≤ trace (P * (denote (While M S) ρ)) + (trace ρ - trace (denote (While M S) ρ))" using leq_lim (*‹trace (P * (M0 * ρ * adjoint M0)) + trace (Q * (M1 * ρ * adjoint M1)) ≤ trace (P * denote (While M S) ρ) + trace ρ - trace (denote (While M S) ρ)›*) by (auto simp: less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) } then show "?case" (*goal: ‹⊨⇩p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}›*) unfolding hoare_partial_correct_def denote.simps(5) (*goal: ‹∀ρ∈density_states. trace ((adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1) * ρ) ≤ trace (P * denote_while (M 0) (M 1) (denote S) ρ) + (trace ρ - trace (denote_while (M 0) (M 1) (denote S) ρ))›*) apply (fold M0_def M1_def DS_def D0_def D1_def) (*goal: ‹∀ρ∈density_states. trace ((adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1) * ρ) ≤ trace (P * denote_while (M 0) (M 1) (denote S) ρ) + (trace ρ - trace (denote_while (M 0) (M 1) (denote S) ρ))›*) by auto next (*goal: ‹⋀P Q P' Q' S. ⟦is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P ≤⇩L P'; ⊢⇩p {P'} S {Q'}; well_com S ⟹ ⊨⇩p {P'} S {Q'}; Q' ≤⇩L Q; well_com S⟧ ⟹ ⊨⇩p {P} S {Q}›*) case (6 P Q P' Q' S) (*‹is_quantum_predicate (P::complex mat)› ‹is_quantum_predicate Q› ‹is_quantum_predicate P'› ‹is_quantum_predicate Q'› ‹P ≤⇩L P'› ‹⊢⇩p {P'} S {Q'}› ‹Q' ≤⇩L Q› ‹well_com (S::com) ⟹ ⊨⇩p {P'::complex mat} S {Q'::complex mat}› ‹well_com S›*) then have wcs: "well_com S" and c: "⊨⇩p {P'} S {Q'}" and dP: "P ∈ carrier_mat d d" and dQ: "Q ∈ carrier_mat d d" and dP': "P' ∈ carrier_mat d d" and dQ': "Q' ∈ carrier_mat d d" using is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) apply - (*goals: 1. ‹⟦is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); is_quantum_predicate (P'::complex mat); is_quantum_predicate (Q'::complex mat); P ≤⇩L P'; ⊢⇩p {P'} S::com {Q'}; Q' ≤⇩L Q; well_com S ⟹ ⊨⇩p {P'} S {Q'}; well_com S; ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ well_com S› 2. ‹⟦is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); is_quantum_predicate (P'::complex mat); is_quantum_predicate (Q'::complex mat); P ≤⇩L P'; ⊢⇩p {P'} S::com {Q'}; Q' ≤⇩L Q; well_com S ⟹ ⊨⇩p {P'} S {Q'}; well_com S; ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ ⊨⇩p {P'} S {Q'}› 3. ‹⟦is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); is_quantum_predicate (P'::complex mat); is_quantum_predicate (Q'::complex mat); P ≤⇩L P'; ⊢⇩p {P'} S::com {Q'}; Q' ≤⇩L Q; well_com S ⟹ ⊨⇩p {P'} S {Q'}; well_com S; ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ P ∈ carrier_mat d d› 4. ‹⟦is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); is_quantum_predicate (P'::complex mat); is_quantum_predicate (Q'::complex mat); P ≤⇩L P'; ⊢⇩p {P'} S::com {Q'}; Q' ≤⇩L Q; well_com S ⟹ ⊨⇩p {P'} S {Q'}; well_com S; ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ Q ∈ carrier_mat d d› 5. ‹⟦is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); is_quantum_predicate (P'::complex mat); is_quantum_predicate (Q'::complex mat); P ≤⇩L P'; ⊢⇩p {P'} S::com {Q'}; Q' ≤⇩L Q; well_com S ⟹ ⊨⇩p {P'} S {Q'}; well_com S; ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ P' ∈ carrier_mat d d› 6. ‹⟦is_quantum_predicate (P::complex mat); is_quantum_predicate (Q::complex mat); is_quantum_predicate (P'::complex mat); is_quantum_predicate (Q'::complex mat); P ≤⇩L P'; ⊢⇩p {P'} S::com {Q'}; Q' ≤⇩L Q; well_com S ⟹ ⊨⇩p {P'} S {Q'}; well_com S; ⋀P::complex mat. is_quantum_predicate P = (P ∈ carrier_mat d d ∧ positive P ∧ P ≤⇩L 1⇩m d)⟧ ⟹ Q' ∈ carrier_mat d d› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*proven 6 subgoals*) . show "?case" (*goal: ‹⊨⇩p {P} S {Q}›*) unfolding hoare_partial_correct_def (*goal: ‹∀ρ∈density_states. trace (P * ρ) ≤ trace (Q * denote S ρ) + (trace ρ - trace (denote S ρ))›*) proof (standard) (*goal: ‹⋀ρ. ρ ∈ density_states ⟹ trace (P * ρ) ≤ trace (Q * denote S ρ) + (trace ρ - trace (denote S ρ))›*) fix ρ assume pds: "ρ ∈ density_states" (*‹(ρ::complex mat) ∈ density_states›*) then have pdor: "partial_density_operator ρ" and dr: "ρ ∈ carrier_mat d d" using density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) apply - (*goals: 1. ‹⟦ρ ∈ density_states; density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}⟧ ⟹ partial_density_operator ρ› 2. ‹⟦ρ ∈ density_states; density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}⟧ ⟹ ρ ∈ carrier_mat d d› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have pdoSr: "partial_density_operator (denote S ρ)" using denote_partial_density_operator (*‹⟦well_com (?S::com); partial_density_operator (?ρ::complex mat); ?ρ ∈ carrier_mat d d⟧ ⟹ partial_density_operator (denote ?S ?ρ)›*) pdor (*‹partial_density_operator ρ›*) dr (*‹ρ ∈ carrier_mat d d›*) wcs (*‹well_com S›*) by auto have dSr: "denote S ρ ∈ carrier_mat d d" using denote_dim (*‹⟦well_com ?S; ?ρ ∈ carrier_mat d d; partial_density_operator ?ρ⟧ ⟹ denote ?S ?ρ ∈ carrier_mat d d›*) pdor (*‹partial_density_operator ρ›*) dr (*‹ρ ∈ carrier_mat d d›*) wcs (*‹well_com S›*) by auto have "trace (P * ρ) ≤ trace (P' * ρ)" using lowner_le_trace[OF dP dP'] (*‹((P::complex mat) ≤⇩L (P'::complex mat)) = (∀ρ::complex mat∈carrier_mat d d. partial_density_operator ρ ⟶ trace (P * ρ) ≤ trace (P' * ρ))›*) "6" (*‹is_quantum_predicate P› ‹is_quantum_predicate Q› ‹is_quantum_predicate (P'::complex mat)› ‹is_quantum_predicate Q'› ‹P ≤⇩L P'› ‹⊢⇩p {P'} S {Q'}› ‹Q' ≤⇩L Q› ‹well_com S ⟹ ⊨⇩p {P'} S {Q'}› ‹well_com S›*) dr (*‹(ρ::complex mat) ∈ carrier_mat d d›*) pdor (*‹partial_density_operator ρ›*) by auto also (*calculation: ‹trace ((P::complex mat) * (ρ::complex mat)) ≤ trace ((P'::complex mat) * ρ)›*) have "… ≤ trace (Q' * denote S ρ) + (trace ρ - trace (denote S ρ))" using c (*‹⊨⇩p {P'} S {Q'}›*) unfolding hoare_partial_correct_def (*goal: ‹trace (P' * ρ) ≤ trace (Q' * denote S ρ) + (trace ρ - trace (denote S ρ))›*) using pds (*‹ρ ∈ density_states›*) by auto also (*calculation: ‹trace (P * ρ) ≤ trace (Q' * denote S ρ) + (trace ρ - trace (denote S ρ))›*) have "… ≤ trace (Q * denote S ρ) + (trace ρ - trace (denote S ρ))" using lowner_le_trace[OF dQ' dQ] (*‹(Q' ≤⇩L Q) = (∀ρ∈carrier_mat d d. partial_density_operator ρ ⟶ trace (Q' * ρ) ≤ trace (Q * ρ))›*) "6" (*‹is_quantum_predicate (P::complex mat)› ‹is_quantum_predicate Q› ‹is_quantum_predicate P'› ‹is_quantum_predicate (Q'::complex mat)› ‹P ≤⇩L P'› ‹⊢⇩p {P'} S {Q'}› ‹Q' ≤⇩L Q› ‹well_com (S::com) ⟹ ⊨⇩p {P'::complex mat} S {Q'::complex mat}› ‹well_com S›*) dSr (*‹denote (S::com) (ρ::complex mat) ∈ carrier_mat d d›*) pdoSr (*‹partial_density_operator (denote S ρ)›*) by auto finally (*calculation: ‹trace (P * ρ) ≤ trace (Q * denote S ρ) + (trace ρ - trace (denote S ρ))›*) show "trace (P * ρ) ≤ trace (Q * denote S ρ) + (trace ρ - trace (denote S ρ)) " . qed qed lemma wlp_complete: "well_com S ⟹ is_quantum_predicate P ⟹ ⊢⇩p {wlp S P} S {P}" proof (induct S arbitrary: P) (*goals: 1. ‹⋀P::complex mat. ⟦well_com SKIP; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp SKIP P} SKIP {P}› 2. ‹⋀(x::complex mat) P::complex mat. ⟦well_com (Utrans x); is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp (Utrans x) P} Utrans x {P}› 3. ‹⋀(S1::com) (S2::com) P::complex mat. ⟦⋀P::complex mat. ⟦well_com S1; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp S1 P} S1 {P}; ⋀P::complex mat. ⟦well_com S2; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp S2 P} S2 {P}; well_com (S1;; S2); is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp (S1;; S2) P} S1;; S2 {P}› 4. ‹⋀(x1::nat) (x2a::nat ⇒ complex mat) (x3::com list) P::complex mat. ⟦⋀(x3a::com) P::complex mat. ⟦x3a ∈ set x3; well_com x3a; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp x3a P} x3a {P}; well_com (Measure x1 x2a x3); is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp (Measure x1 x2a x3) P} Measure x1 x2a x3 {P}› 5. ‹⋀(x1::nat ⇒ complex mat) (S::com) P::complex mat. ⟦⋀P::complex mat. ⟦well_com S; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp S P} S {P}; well_com (While x1 S); is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp (While x1 S) P} While x1 S {P}›*) case SKIP (*‹well_com SKIP› ‹is_quantum_predicate P›*) then show "?case" (*goal: ‹⊢⇩p {wlp SKIP (P::complex mat)} SKIP {P}›*) unfolding wlp.simps (*goal: ‹⊢⇩p {P::complex mat} SKIP {P}›*) using hoare_partial.intros (*‹is_quantum_predicate ?P ⟹ ⊢⇩p {?P} SKIP {?P}› ‹is_quantum_predicate ?P ⟹ ⊢⇩p {adjoint ?U * ?P * ?U} Utrans ?U {?P}› ‹⟦is_quantum_predicate (?P::complex mat); is_quantum_predicate (?Q::complex mat); is_quantum_predicate (?R::complex mat); ⊢⇩p {?P} ?S1.0::com {?Q}; ⊢⇩p {?Q} ?S2.0::com {?R}⟧ ⟹ ⊢⇩p {?P} ?S1.0;; ?S2.0 {?R}› ‹⟦⋀k. k < ?n ⟹ is_quantum_predicate (?P k); is_quantum_predicate ?Q; ⋀k. k < ?n ⟹ ⊢⇩p {?P k} ?S ! k {?Q}⟧ ⟹ ⊢⇩p {matrix_sum d (λk. adjoint (?M k) * ?P k * ?M k) ?n} Measure ?n ?M ?S {?Q}› ‹⟦is_quantum_predicate ?P; is_quantum_predicate ?Q; ⊢⇩p {?Q} ?S {adjoint (?M 0) * ?P * ?M 0 + adjoint (?M 1) * ?Q * ?M 1}⟧ ⟹ ⊢⇩p {adjoint (?M 0) * ?P * ?M 0 + adjoint (?M 1) * ?Q * ?M 1} While ?M ?S {?P}› ‹⟦is_quantum_predicate ?P; is_quantum_predicate ?Q; is_quantum_predicate ?P'; is_quantum_predicate ?Q'; ?P ≤⇩L ?P'; ⊢⇩p {?P'} ?S {?Q'}; ?Q' ≤⇩L ?Q⟧ ⟹ ⊢⇩p {?P} ?S {?Q}›*) by auto next (*goals: 1. ‹⋀x P. ⟦well_com (Utrans x); is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp (Utrans x) P} Utrans x {P}› 2. ‹⋀S1 S2 P. ⟦⋀P. ⟦well_com S1; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp S1 P} S1 {P}; ⋀P. ⟦well_com S2; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp S2 P} S2 {P}; well_com (S1;; S2); is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp (S1;; S2) P} S1;; S2 {P}› 3. ‹⋀x1 x2a x3 P. ⟦⋀x3a P. ⟦x3a ∈ set x3; well_com x3a; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp x3a P} x3a {P}; well_com (Measure x1 x2a x3); is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp (Measure x1 x2a x3) P} Measure x1 x2a x3 {P}› 4. ‹⋀x1 S P. ⟦⋀P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp S P} S {P}; well_com (While x1 S); is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp (While x1 S) P} While x1 S {P}›*) case (Utrans U) (*‹well_com (Utrans U)› ‹is_quantum_predicate P›*) then show "?case" (*goal: ‹⊢⇩p {wlp (Utrans (U::complex mat)) (P::complex mat)} Utrans U {P}›*) unfolding wlp.simps (*goal: ‹⊢⇩p {adjoint U * P * U} Utrans U {P}›*) using hoare_partial.intros (*‹is_quantum_predicate ?P ⟹ ⊢⇩p {?P} SKIP {?P}› ‹is_quantum_predicate ?P ⟹ ⊢⇩p {adjoint ?U * ?P * ?U} Utrans ?U {?P}› ‹⟦is_quantum_predicate ?P; is_quantum_predicate ?Q; is_quantum_predicate ?R; ⊢⇩p {?P} ?S1.0 {?Q}; ⊢⇩p {?Q} ?S2.0 {?R}⟧ ⟹ ⊢⇩p {?P} ?S1.0;; ?S2.0 {?R}› ‹⟦⋀k. k < ?n ⟹ is_quantum_predicate (?P k); is_quantum_predicate ?Q; ⋀k. k < ?n ⟹ ⊢⇩p {?P k} ?S ! k {?Q}⟧ ⟹ ⊢⇩p {matrix_sum d (λk. adjoint (?M k) * ?P k * ?M k) ?n} Measure ?n ?M ?S {?Q}› ‹⟦is_quantum_predicate ?P; is_quantum_predicate ?Q; ⊢⇩p {?Q} ?S {adjoint (?M 0) * ?P * ?M 0 + adjoint (?M 1) * ?Q * ?M 1}⟧ ⟹ ⊢⇩p {adjoint (?M 0) * ?P * ?M 0 + adjoint (?M 1) * ?Q * ?M 1} While ?M ?S {?P}› ‹⟦is_quantum_predicate ?P; is_quantum_predicate ?Q; is_quantum_predicate ?P'; is_quantum_predicate ?Q'; ?P ≤⇩L ?P'; ⊢⇩p {?P'} ?S {?Q'}; ?Q' ≤⇩L ?Q⟧ ⟹ ⊢⇩p {?P} ?S {?Q}›*) by auto next (*goals: 1. ‹⋀S1 S2 P. ⟦⋀P. ⟦well_com S1; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp S1 P} S1 {P}; ⋀P. ⟦well_com S2; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp S2 P} S2 {P}; well_com (S1;; S2); is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp (S1;; S2) P} S1;; S2 {P}› 2. ‹⋀x1 x2a x3 P. ⟦⋀x3a P. ⟦x3a ∈ set x3; well_com x3a; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp x3a P} x3a {P}; well_com (Measure x1 x2a x3); is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp (Measure x1 x2a x3) P} Measure x1 x2a x3 {P}› 3. ‹⋀x1 S P. ⟦⋀P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp S P} S {P}; well_com (While x1 S); is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp (While x1 S) P} While x1 S {P}›*) case (Seq S1 S2) (*‹⟦well_com S1; is_quantum_predicate ?P⟧ ⟹ ⊢⇩p {wlp S1 ?P} S1 {?P}› ‹⟦well_com S2; is_quantum_predicate ?P⟧ ⟹ ⊢⇩p {wlp S2 ?P} S2 {?P}› ‹well_com (S1;; S2)› ‹is_quantum_predicate P›*) then have wc1: "well_com S1" and wc2: "well_com S2" and qpP: "is_quantum_predicate P" and p2: "⊢⇩p {wlp S2 P} S2 {P}" apply - (*goals: 1. ‹⟦⋀P. ⟦well_com S1; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp S1 P} S1 {P}; ⋀P. ⟦well_com S2; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp S2 P} S2 {P}; well_com (S1;; S2); is_quantum_predicate P⟧ ⟹ well_com S1› 2. ‹⟦⋀P. ⟦well_com S1; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp S1 P} S1 {P}; ⋀P. ⟦well_com S2; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp S2 P} S2 {P}; well_com (S1;; S2); is_quantum_predicate P⟧ ⟹ well_com S2› 3. ‹⟦⋀P. ⟦well_com S1; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp S1 P} S1 {P}; ⋀P. ⟦well_com S2; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp S2 P} S2 {P}; well_com (S1;; S2); is_quantum_predicate P⟧ ⟹ is_quantum_predicate P› 4. ‹⟦⋀P. ⟦well_com S1; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp S1 P} S1 {P}; ⋀P. ⟦well_com S2; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp S2 P} S2 {P}; well_com (S1;; S2); is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp S2 P} S2 {P}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . have qpW2P: "is_quantum_predicate (wlp S2 P)" using wlp_close[OF wc2 qpP] (*‹is_quantum_predicate (wlp S2 P)›*) by auto then have p1: "⊢⇩p {wlp S1 (wlp S2 P)} S1 {wlp S2 P}" using Seq (*‹⟦well_com S1; is_quantum_predicate ?P⟧ ⟹ ⊢⇩p {wlp S1 ?P} S1 {?P}› ‹⟦well_com (S2::com); is_quantum_predicate (?P::complex mat)⟧ ⟹ ⊢⇩p {wlp S2 ?P} S2 {?P}› ‹well_com (S1;; S2)› ‹is_quantum_predicate P›*) by auto have qpW1W2P: "is_quantum_predicate (wlp S1 (wlp S2 P))" using wlp_close[OF wc1 qpW2P] (*‹is_quantum_predicate (wlp S1 (wlp S2 P))›*) by auto then show "?case" (*goal: ‹⊢⇩p {wlp (S1;; S2) P} S1;; S2 {P}›*) unfolding wlp.simps (*goal: ‹⊢⇩p {wlp (S1::com) (wlp (S2::com) (P::complex mat))} S1;; S2 {P}›*) using hoare_partial.intros (*‹is_quantum_predicate ?P ⟹ ⊢⇩p {?P} SKIP {?P}› ‹is_quantum_predicate ?P ⟹ ⊢⇩p {adjoint ?U * ?P * ?U} Utrans ?U {?P}› ‹⟦is_quantum_predicate ?P; is_quantum_predicate ?Q; is_quantum_predicate ?R; ⊢⇩p {?P} ?S1.0 {?Q}; ⊢⇩p {?Q} ?S2.0 {?R}⟧ ⟹ ⊢⇩p {?P} ?S1.0;; ?S2.0 {?R}› ‹⟦⋀k. k < ?n ⟹ is_quantum_predicate (?P k); is_quantum_predicate ?Q; ⋀k. k < ?n ⟹ ⊢⇩p {?P k} ?S ! k {?Q}⟧ ⟹ ⊢⇩p {matrix_sum d (λk. adjoint (?M k) * ?P k * ?M k) ?n} Measure ?n ?M ?S {?Q}› ‹⟦is_quantum_predicate ?P; is_quantum_predicate ?Q; ⊢⇩p {?Q} ?S {adjoint (?M 0) * ?P * ?M 0 + adjoint (?M 1) * ?Q * ?M 1}⟧ ⟹ ⊢⇩p {adjoint (?M 0) * ?P * ?M 0 + adjoint (?M 1) * ?Q * ?M 1} While ?M ?S {?P}› ‹⟦is_quantum_predicate ?P; is_quantum_predicate ?Q; is_quantum_predicate ?P'; is_quantum_predicate ?Q'; ?P ≤⇩L ?P'; ⊢⇩p {?P'} ?S {?Q'}; ?Q' ≤⇩L ?Q⟧ ⟹ ⊢⇩p {?P} ?S {?Q}›*) qpW1W2P (*‹is_quantum_predicate (wlp S1 (wlp S2 P))›*) qpW2P (*‹is_quantum_predicate (wlp S2 P)›*) qpP (*‹is_quantum_predicate (P::complex mat)›*) p1 (*‹⊢⇩p {wlp (S1::com) (wlp (S2::com) (P::complex mat))} S1 {wlp S2 P}›*) p2 (*‹⊢⇩p {wlp S2 P} S2 {P}›*) by auto next (*goals: 1. ‹⋀x1 x2a x3 P. ⟦⋀x3a P. ⟦x3a ∈ set x3; well_com x3a; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp x3a P} x3a {P}; well_com (Measure x1 x2a x3); is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp (Measure x1 x2a x3) P} Measure x1 x2a x3 {P}› 2. ‹⋀x1 S P. ⟦⋀P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp S P} S {P}; well_com (While x1 S); is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp (While x1 S) P} While x1 S {P}›*) case (Measure n M S) (*‹⟦?x3a ∈ set S; well_com ?x3a; is_quantum_predicate ?P⟧ ⟹ ⊢⇩p {wlp ?x3a ?P} ?x3a {?P}› ‹well_com (Measure n M S)› ‹is_quantum_predicate P›*) then have wc: "well_com (Measure n M S)" and qpP: "is_quantum_predicate P" apply - (*goals: 1. ‹⟦⋀x3a P. ⟦x3a ∈ set S; well_com x3a; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp x3a P} x3a {P}; well_com (Measure n M S); is_quantum_predicate P⟧ ⟹ well_com (Measure n M S)› 2. ‹⟦⋀x3a P. ⟦x3a ∈ set S; well_com x3a; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp x3a P} x3a {P}; well_com (Measure n M S); is_quantum_predicate P⟧ ⟹ is_quantum_predicate P› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have set: "k < n ⟹ (S!k) ∈ set S" for k using wc (*‹well_com (Measure (n::nat) (M::nat ⇒ complex mat) (S::com list))›*) by auto have wck: "k < n ⟹ well_com (S!k)" for k using wc (*‹well_com (Measure (n::nat) (M::nat ⇒ complex mat) (S::com list))›*) measure_well_com (*‹⟦well_com (Measure ?n ?M ?S); ?k < ?n⟧ ⟹ well_com (?S ! ?k)›*) by auto then have qpWkP: "k < n ⟹ is_quantum_predicate (wlp (S!k) P)" for k using wlp_close (*‹⟦well_com ?S; is_quantum_predicate ?P⟧ ⟹ is_quantum_predicate (wlp ?S ?P)›*) qpP (*‹is_quantum_predicate P›*) by auto have pk: "k < n ⟹ ⊢⇩p {(wlp (S!k) P)} (S!k) {P}" for k using Measure(1) (*‹⟦(?x3a::com) ∈ set (S::com list); well_com ?x3a; is_quantum_predicate (?P::complex mat)⟧ ⟹ ⊢⇩p {wlp ?x3a ?P} ?x3a {?P}›*) set (*‹?k < n ⟹ S ! ?k ∈ set S›*) wck (*‹?k < n ⟹ well_com (S ! ?k)›*) qpP (*‹is_quantum_predicate (P::complex mat)›*) by auto show "?case" (*goal: ‹⊢⇩p {wlp (Measure n M S) P} Measure n M S {P}›*) unfolding wlp_measure_expand[OF wc] (*goal: ‹⊢⇩p {matrix_sum d (λk. adjoint (M k) * wlp (S ! k) P * M k) n} Measure n M S {P}›*) using hoare_partial.intros (*‹is_quantum_predicate ?P ⟹ ⊢⇩p {?P} SKIP {?P}› ‹is_quantum_predicate (?P::complex mat) ⟹ ⊢⇩p {adjoint (?U::complex mat) * ?P * ?U} Utrans ?U {?P}› ‹⟦is_quantum_predicate ?P; is_quantum_predicate ?Q; is_quantum_predicate ?R; ⊢⇩p {?P} ?S1.0 {?Q}; ⊢⇩p {?Q} ?S2.0 {?R}⟧ ⟹ ⊢⇩p {?P} ?S1.0;; ?S2.0 {?R}› ‹⟦⋀k. k < ?n ⟹ is_quantum_predicate (?P k); is_quantum_predicate ?Q; ⋀k. k < ?n ⟹ ⊢⇩p {?P k} ?S ! k {?Q}⟧ ⟹ ⊢⇩p {matrix_sum d (λk. adjoint (?M k) * ?P k * ?M k) ?n} Measure ?n ?M ?S {?Q}› ‹⟦is_quantum_predicate (?P::complex mat); is_quantum_predicate (?Q::complex mat); ⊢⇩p {?Q} ?S::com {adjoint ((?M::nat ⇒ complex mat) (0::nat)) * ?P * ?M (0::nat) + adjoint (?M (1::nat)) * ?Q * ?M (1::nat)}⟧ ⟹ ⊢⇩p {adjoint (?M (0::nat)) * ?P * ?M (0::nat) + adjoint (?M (1::nat)) * ?Q * ?M (1::nat)} While ?M ?S {?P}› ‹⟦is_quantum_predicate (?P::complex mat); is_quantum_predicate (?Q::complex mat); is_quantum_predicate (?P'::complex mat); is_quantum_predicate (?Q'::complex mat); ?P ≤⇩L ?P'; ⊢⇩p {?P'} ?S::com {?Q'}; ?Q' ≤⇩L ?Q⟧ ⟹ ⊢⇩p {?P} ?S {?Q}›*) qpWkP (*‹?k < n ⟹ is_quantum_predicate (wlp (S ! ?k) P)›*) qpP (*‹is_quantum_predicate P›*) pk (*‹(?k::nat) < (n::nat) ⟹ ⊢⇩p {wlp ((S::com list) ! ?k) (P::complex mat)} S ! ?k {P}›*) by auto next (*goal: ‹⋀x1 S P. ⟦⋀P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp S P} S {P}; well_com (While x1 S); is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp (While x1 S) P} While x1 S {P}›*) case (While M S) (*‹⟦well_com (S::com); is_quantum_predicate (?P::complex mat)⟧ ⟹ ⊢⇩p {wlp S ?P} S {?P}› ‹well_com (While (M::nat ⇒ complex mat) (S::com))› ‹is_quantum_predicate P›*) then have wc: "well_com (While M S)" and wcS: "well_com S" and qpP: "is_quantum_predicate P " apply - (*goals: 1. ‹⟦⋀P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp S P} S {P}; well_com (While M S); is_quantum_predicate P⟧ ⟹ well_com (While M S)› 2. ‹⟦⋀P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp S P} S {P}; well_com (While M S); is_quantum_predicate P⟧ ⟹ well_com S› 3. ‹⟦⋀P. ⟦well_com S; is_quantum_predicate P⟧ ⟹ ⊢⇩p {wlp S P} S {P}; well_com (While M S); is_quantum_predicate P⟧ ⟹ is_quantum_predicate P› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . have qpWP: "is_quantum_predicate (wlp (While M S) P)" using wlp_close[OF wc qpP] (*‹is_quantum_predicate (wlp (While M S) P)›*) by auto then have qpWWP: "is_quantum_predicate (wlp S (wlp (While M S) P))" using wlp_close (*‹⟦well_com ?S; is_quantum_predicate ?P⟧ ⟹ is_quantum_predicate (wlp ?S ?P)›*) wcS (*‹well_com (S::com)›*) by auto have "⊢⇩p {wlp S (wlp (While M S) P)} S {wlp (While M S) P}" using While(1) (*‹⟦well_com S; is_quantum_predicate ?P⟧ ⟹ ⊢⇩p {wlp S ?P} S {?P}›*) wcS (*‹well_com S›*) qpWP (*‹is_quantum_predicate (wlp (While M S) P)›*) by auto moreover have eq: "wlp (While M S) P = adjoint (M 0) * P * M 0 + adjoint (M 1) * wlp S (wlp (While M S) P) * M 1" using wlp_while_split (*‹⟦well_com (While ?M ?S); is_quantum_predicate ?P⟧ ⟹ wlp (While ?M ?S) ?P = adjoint (?M 0) * ?P * ?M 0 + adjoint (?M 1) * wlp ?S (wlp (While ?M ?S) ?P) * ?M 1›*) wc (*‹well_com (While M S)›*) qpP (*‹is_quantum_predicate P›*) by auto ultimately have p: "⊢⇩p {wlp S (wlp (While M S) P)} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * wlp S (wlp (While M S) P) * M 1}" by auto then show "?case" (*goal: ‹⊢⇩p {wlp (While M S) P} While M S {P}›*) using hoare_partial.intros(5)[OF qpP qpWWP p] (*‹⊢⇩p {adjoint (M 0) * P * M 0 + adjoint (M 1) * wlp S (wlp (While M S) P) * M 1} While M S {P}›*) eq (*‹wlp (While (M::nat ⇒ complex mat) (S::com)) (P::complex mat) = adjoint (M (0::nat)) * P * M (0::nat) + adjoint (M (1::nat)) * wlp S (wlp (While M S) P) * M (1::nat)›*) by auto qed theorem hoare_partial_complete: "⊨⇩p {P} S {Q} ⟹ well_com S ⟹ is_quantum_predicate P ⟹ is_quantum_predicate Q ⟹ ⊢⇩p {P} S {Q}" proof (-) (*goal: ‹⟦⊨⇩p {P::complex mat} S::com {Q::complex mat}; well_com S; is_quantum_predicate P; is_quantum_predicate Q⟧ ⟹ ⊢⇩p {P} S {Q}›*) assume p: "⊨⇩p {P} S {Q}" and wc: "well_com S" and qpP: "is_quantum_predicate P" and qpQ: "is_quantum_predicate Q" (*‹⊨⇩p {P::complex mat} S::com {Q::complex mat}› ‹well_com (S::com)› ‹is_quantum_predicate (P::complex mat)› ‹is_quantum_predicate (Q::complex mat)›*) then have dQ: "Q ∈ carrier_mat d d" using is_quantum_predicate_def (*‹is_quantum_predicate (?P::complex mat) = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto have qpWP: "is_quantum_predicate (wlp S Q)" using wlp_close (*‹⟦well_com ?S; is_quantum_predicate ?P⟧ ⟹ is_quantum_predicate (wlp ?S ?P)›*) wc (*‹well_com S›*) qpQ (*‹is_quantum_predicate Q›*) by auto then have dWP: "wlp S Q ∈ carrier_mat d d" using is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto have eq: "trace (wlp S Q * ρ) = trace (Q * (denote S ρ)) + trace ρ - trace (denote S ρ)" if dsr: "ρ ∈ density_states" for ρ using wlp_soundness (*‹⟦well_com ?S; is_quantum_predicate ?P⟧ ⟹ ∀ρ∈density_states. trace (wlp ?S ?P * ρ) = trace (?P * denote ?S ρ) + trace ρ - trace (denote ?S ρ)›*) wc (*‹well_com S›*) qpQ (*‹is_quantum_predicate Q›*) dsr (*‹ρ ∈ density_states›*) by auto then have "⊨⇩p {wlp S Q} S {Q}" unfolding hoare_partial_correct_def (*goal: ‹∀ρ∈density_states. trace (wlp S Q * ρ) ≤ trace (Q * denote S ρ) + (trace ρ - trace (denote S ρ))›*) by auto { fix ρ assume dsr: "ρ ∈ density_states" (*‹(ρ::complex mat) ∈ density_states›*) then have "trace (P * ρ) ≤ trace (Q * (denote S ρ)) + trace ρ - trace (denote S ρ)" using hoare_partial_correct_def (*‹(⊨⇩p {?P} ?S {?Q}) = (∀ρ∈density_states. trace (?P * ρ) ≤ trace (?Q * denote ?S ρ) + (trace ρ - trace (denote ?S ρ)))›*) p (*‹⊨⇩p {P} S {Q}›*) by (auto simp: less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) then have "trace (P * ρ) ≤ trace (wlp S Q * ρ)" using eq[symmetric] (*‹?ρ ∈ density_states ⟹ trace (Q * denote S ?ρ) + trace ?ρ - trace (denote S ?ρ) = trace (wlp S Q * ?ρ)›*) dsr (*‹(ρ::complex mat) ∈ density_states›*) by auto } then have le: "P ≤⇩L wlp S Q" using lowner_le_trace (*‹⟦(?A::complex mat) ∈ carrier_mat (?n::nat) ?n; (?B::complex mat) ∈ carrier_mat ?n ?n⟧ ⟹ (?A ≤⇩L ?B) = (∀ρ::complex mat∈carrier_mat ?n ?n. partial_density_operator ρ ⟶ trace (?A * ρ) ≤ trace (?B * ρ))›*) density_states_def (*‹density_states = {ρ ∈ carrier_mat d d. partial_density_operator ρ}›*) qpP (*‹is_quantum_predicate P›*) qpWP (*‹is_quantum_predicate (wlp S Q)›*) is_quantum_predicate_def (*‹is_quantum_predicate ?P = (?P ∈ carrier_mat d d ∧ positive ?P ∧ ?P ≤⇩L 1⇩m d)›*) by auto moreover have wlp: "⊢⇩p {wlp S Q} S {Q}" using wlp_complete (*‹⟦well_com (?S::com); is_quantum_predicate (?P::complex mat)⟧ ⟹ ⊢⇩p {wlp ?S ?P} ?S {?P}›*) wc (*‹well_com S›*) qpQ (*‹is_quantum_predicate Q›*) by auto ultimately show "⊢⇩p {P} S {Q}" using hoare_partial.intros(6)[OF qpP qpQ qpWP qpQ] (*‹⟦P ≤⇩L wlp S Q; ⊢⇩p {wlp S Q} ?S {Q}; Q ≤⇩L Q⟧ ⟹ ⊢⇩p {P} ?S {Q}›*) lowner_le_refl[OF dQ] (*‹Q ≤⇩L Q›*) by auto qed subsection ‹Consequences of completeness› lemma hoare_patial_seq_assoc_sem: shows "⊨⇩p {A} (S1 ;; S2) ;; S3 {B} ⟷ ⊨⇩p {A} S1 ;; (S2 ;; S3) {B}" unfolding hoare_partial_correct_def denote.simps (*goal: ‹(∀ρ::complex mat∈density_states. trace ((A::complex mat) * ρ) ≤ trace ((B::complex mat) * denote (S3::com) (denote (S2::com) (denote (S1::com) ρ))) + (trace ρ - trace (denote S3 (denote S2 (denote S1 ρ))))) = (∀ρ::complex mat∈density_states. trace (A * ρ) ≤ trace (B * denote S3 (denote S2 (denote S1 ρ))) + (trace ρ - trace (denote S3 (denote S2 (denote S1 ρ)))))›*) by auto lemma hoare_patial_seq_assoc: assumes "well_com S1" and "well_com S2" and "well_com S3" and "is_quantum_predicate A" and "is_quantum_predicate B" shows "⊢⇩p {A} (S1 ;; S2) ;; S3 {B} ⟷ ⊢⇩p {A} S1 ;; (S2 ;; S3) {B}" proof (standard) (*goals: 1. ‹⊢⇩p {A::complex mat} (S1::com);; (S2::com);; (S3::com) {B::complex mat} ⟹ ⊢⇩p {A} S1;; (S2;; S3) {B}› 2. ‹⊢⇩p {A::complex mat} (S1::com);; ((S2::com);; (S3::com)) {B::complex mat} ⟹ ⊢⇩p {A} S1;; S2;; S3 {B}›*) assume "⊢⇩p {A} S1;; S2;; S3 {B}" (*‹⊢⇩p {A::complex mat} (S1::com);; (S2::com);; (S3::com) {B::complex mat}›*) then have "⊨⇩p {A} (S1 ;; S2) ;; S3 {B}" using hoare_partial_sound (*‹⟦⊢⇩p {?P::complex mat} ?S::com {?Q::complex mat}; well_com ?S⟧ ⟹ ⊨⇩p {?P} ?S {?Q}›*) assms (*‹well_com S1› ‹well_com S2› ‹well_com S3› ‹is_quantum_predicate A› ‹is_quantum_predicate (B::complex mat)›*) by auto then have "⊨⇩p {A} S1 ;; (S2 ;; S3) {B}" using hoare_patial_seq_assoc_sem (*‹(⊨⇩p {?A} ?S1.0;; ?S2.0;; ?S3.0 {?B}) = (⊨⇩p {?A} ?S1.0;; (?S2.0;; ?S3.0) {?B})›*) by auto then show "⊢⇩p {A} S1 ;; (S2 ;; S3) {B}" using hoare_partial_complete (*‹⟦⊨⇩p {?P::complex mat} ?S::com {?Q::complex mat}; well_com ?S; is_quantum_predicate ?P; is_quantum_predicate ?Q⟧ ⟹ ⊢⇩p {?P} ?S {?Q}›*) assms (*‹well_com S1› ‹well_com S2› ‹well_com S3› ‹is_quantum_predicate (A::complex mat)› ‹is_quantum_predicate B›*) by auto next (*goal: ‹⊢⇩p {A} S1;; (S2;; S3) {B} ⟹ ⊢⇩p {A} S1;; S2;; S3 {B}›*) assume "⊢⇩p {A} S1;; (S2;; S3) {B}" (*‹⊢⇩p {A::complex mat} (S1::com);; ((S2::com);; (S3::com)) {B::complex mat}›*) then have "⊨⇩p {A} S1;; (S2;; S3) {B}" using hoare_partial_sound (*‹⟦⊢⇩p {?P} ?S {?Q}; well_com ?S⟧ ⟹ ⊨⇩p {?P} ?S {?Q}›*) assms (*‹well_com S1› ‹well_com S2› ‹well_com S3› ‹is_quantum_predicate (A::complex mat)› ‹is_quantum_predicate B›*) by auto then have "⊨⇩p {A} S1;; S2;; S3 {B}" using hoare_patial_seq_assoc_sem (*‹(⊨⇩p {?A} ?S1.0;; ?S2.0;; ?S3.0 {?B}) = (⊨⇩p {?A} ?S1.0;; (?S2.0;; ?S3.0) {?B})›*) by auto then show "⊢⇩p {A} S1;; S2;; S3 {B}" using hoare_partial_complete (*‹⟦⊨⇩p {?P} ?S {?Q}; well_com ?S; is_quantum_predicate ?P; is_quantum_predicate ?Q⟧ ⟹ ⊢⇩p {?P} ?S {?Q}›*) assms (*‹well_com S1› ‹well_com S2› ‹well_com (S3::com)› ‹is_quantum_predicate A› ‹is_quantum_predicate (B::complex mat)›*) by auto qed end end
{ "path": "afp-2025-02-12/thys/QHLProver/Quantum_Hoare.thy", "repo": "afp-2025-02-12", "sha": "78603246b6f024f4f13129280b404b0dc828d1c3c605819023715021e2481e17" }
theory Variable_Substitution imports Abstract_Substitution.Substitution "HOL-Library.FSet" "HOL-Library.Multiset" begin locale finite_set = fixes set :: "'b ⇒ 'a set" assumes finite_set [simp]: "⋀b. finite (set b)" begin abbreviation finite_set :: "'b ⇒ 'a fset" where "finite_set b ≡ Abs_fset (set b)" lemma finite_set': "set b ∈ {A. finite A}" by simp lemma fset_finite_set [simp]: "fset (finite_set b) = set b" using Abs_fset_inverse[OF finite_set'] (*‹fset (local.finite_set (?b1::'b)) = (set::'b ⇒ 'a set) ?b1›*) . end locale variable_substitution = substitution _ _ subst "λa. vars a = {}" for subst :: "'expression ⇒ ('variable ⇒ 'base_expression) ⇒ 'expression" (infixl "⋅" 70) and vars :: "'expression ⇒ 'variable set" + assumes subst_eq: "⋀a σ τ. (⋀x. x ∈ (vars a) ⟹ σ x = τ x) ⟹ a ⋅ σ = a ⋅ τ" begin abbreviation is_ground where "is_ground a ≡ vars a = {}" definition vars_set :: "'expression set ⇒ 'variable set" where "vars_set expressions ≡ ⋃expression ∈ expressions. vars expression" lemma subst_reduntant_upd [simp]: assumes "var ∉ vars a" shows "a ⋅ σ(var := update) = a ⋅ σ" using assms (*‹var ∉ vars a›*) subst_eq (*‹(⋀x. x ∈ vars ?a ⟹ ?σ x = ?τ x) ⟹ ?a ⋅ ?σ = ?a ⋅ ?τ›*) by fastforce lemma subst_reduntant_if [simp]: assumes "vars a ⊆ vars'" shows "a ⋅ (λvar. if var ∈ vars' then σ var else σ' var) = a ⋅ σ" using assms (*‹vars a ⊆ vars'›*) by (smt (verit, best) subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*) subst_eq (*‹(⋀x. x ∈ vars ?a ⟹ ?σ x = ?τ x) ⟹ ?a ⋅ ?σ = ?a ⋅ ?τ›*)) lemma subst_reduntant_if' [simp]: assumes "vars a ∩ vars' = {}" shows "a ⋅ (λvar. if var ∈ vars' then σ' var else σ var) = a ⋅ σ" using assms (*‹vars a ∩ vars' = {}›*) subst_eq (*‹(⋀x. x ∈ vars ?a ⟹ ?σ x = ?τ x) ⟹ ?a ⋅ ?σ = ?a ⋅ ?τ›*) unfolding disjoint_iff (*goal: ‹a ⋅ (λvar. if var ∈ vars' then σ' var else σ var) = a ⋅ σ›*) by presburger lemma subst_cannot_unground: assumes "¬is_ground (a ⋅ σ)" shows "¬is_ground a" using assms (*‹vars (a ⋅ σ) ≠ {}›*) by force end locale finite_variables = finite_set vars for vars :: "'expression ⇒ 'variable set" begin lemmas finite_vars = finite_set finite_set' lemmas fset_finite_vars = fset_finite_set abbreviation "finite_vars ≡ finite_set" end locale all_subst_ident_iff_ground = fixes is_ground :: "'expression ⇒ bool" and subst assumes all_subst_ident_iff_ground: "⋀a. is_ground a ⟷ (∀σ. subst a σ = a)" and exists_non_ident_subst: "⋀a s. finite s ⟹ ¬is_ground a ⟹ ∃σ. subst a σ ≠ a ∧ subst a σ ∉ s" locale grounding = variable_substitution where vars = vars for vars :: "'a ⇒ 'var set" + fixes to_ground :: "'a ⇒ 'g" and from_ground :: "'g ⇒ 'a" assumes range_from_ground_iff_is_ground: "{f. is_ground f} = range from_ground" and from_ground_inverse [simp]: "⋀g. to_ground (from_ground g) = g" begin definition groundings ::"'a ⇒ 'g set" where "groundings a = { to_ground (a ⋅ γ) | γ. is_ground (a ⋅ γ) }" lemma to_ground_from_ground_id: "to_ground ∘ from_ground = id" using from_ground_inverse (*‹to_ground (from_ground ?g) = ?g›*) by auto lemma surj_to_ground: "surj to_ground" using from_ground_inverse (*‹to_ground (from_ground ?g) = ?g›*) by (metis surj_def (*‹surj ?f = (∀y. ∃x. y = ?f x)›*)) lemma inj_from_ground: "inj_on from_ground domain⇩G" by (metis from_ground_inverse (*‹to_ground (from_ground ?g) = ?g›*) inj_on_inverseI (*‹(⋀x. x ∈ ?A ⟹ ?g (?f x) = x) ⟹ inj_on ?f ?A›*)) lemma inj_on_to_ground: "inj_on to_ground (from_ground ` domain⇩G)" unfolding inj_on_def (*goal: ‹∀x∈from_ground ` domain⇩G. ∀y∈from_ground ` domain⇩G. to_ground x = to_ground y ⟶ x = y›*) by simp lemma bij_betw_to_ground: "bij_betw to_ground (from_ground ` domain⇩G) domain⇩G" by (smt (verit, best) bij_betwI' (*‹⟦⋀x y. ⟦x ∈ ?X; y ∈ ?X⟧ ⟹ (?f x = ?f y) = (x = y); ⋀x. x ∈ ?X ⟹ ?f x ∈ ?Y; ⋀y. y ∈ ?Y ⟹ ∃x∈?X. y = ?f x⟧ ⟹ bij_betw ?f ?X ?Y›*) from_ground_inverse (*‹to_ground (from_ground ?g) = ?g›*) image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*)) lemma bij_betw_from_ground: "bij_betw from_ground domain⇩G (from_ground ` domain⇩G)" by (simp add: bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*) inj_from_ground (*‹inj_on from_ground ?domain⇩G›*)) lemma ground_is_ground [simp, intro]: "is_ground (from_ground g)" using range_from_ground_iff_is_ground (*‹{f. is_ground f} = range from_ground›*) by blast lemma is_ground_iff_range_from_ground: "is_ground f ⟷ f ∈ range from_ground" using range_from_ground_iff_is_ground (*‹{f::'a::type. is_ground f} = range (from_ground::'g::type ⇒ 'a::type)›*) by auto lemma to_ground_inverse [simp]: assumes "is_ground f" shows "from_ground (to_ground f) = f" using inj_on_to_ground (*‹inj_on to_ground (from_ground ` ?domain⇩G)›*) from_ground_inverse (*‹to_ground (from_ground ?g) = ?g›*) is_ground_iff_range_from_ground (*‹is_ground ?f = (?f ∈ range from_ground)›*) assms (*‹is_ground f›*) unfolding inj_on_def (*goal: ‹from_ground (to_ground f) = f›*) by blast corollary obtain_grounding: assumes "is_ground f" obtains g where "from_ground g = f" using to_ground_inverse (*‹is_ground ?f ⟹ from_ground (to_ground ?f) = ?f›*) assms (*‹is_ground f›*) by blast end locale base_variable_substitution = variable_substitution where subst = subst for subst :: "'expression ⇒ ('variable ⇒ 'expression) ⇒ 'expression" (infixl "⋅" 70) + assumes is_grounding_iff_vars_grounded: "⋀exp. is_ground (exp ⋅ γ) ⟷ (∀x ∈ vars exp. is_ground (γ x))" and ground_exists: "∃exp. is_ground exp" begin lemma obtain_ground_subst: obtains γ where "is_ground_subst γ" proof (-) (*goal: ‹(⋀γ. is_ground_subst γ ⟹ thesis) ⟹ thesis›*) obtain g where "is_ground g" (*goal: ‹(⋀g::'expression. is_ground g ⟹ thesis::bool) ⟹ thesis›*) using ground_exists (*‹∃exp. is_ground exp›*) by blast then have "is_ground_subst (λ_. g)" by (simp add: is_grounding_iff_vars_grounded (*‹is_ground (?exp ⋅ ?γ) = (∀x∈vars ?exp. is_ground (?γ x))›*) is_ground_subst_def (*‹is_ground_subst ?γ = (∀x. is_ground (x ⋅ ?γ))›*)) then show "?thesis" (*goal: ‹thesis›*) using that (*‹is_ground_subst ?γ1 ⟹ thesis›*) by simp qed lemma ground_subst_extension: assumes "is_ground (exp ⋅ γ)" obtains γ' where "exp ⋅ γ = exp ⋅ γ'" and "is_ground_subst γ'" proof (-) (*goal: ‹(⋀γ'. ⟦exp ⋅ γ = exp ⋅ γ'; is_ground_subst γ'⟧ ⟹ thesis) ⟹ thesis›*) obtain γ'' where "γ''": "is_ground_subst γ''" (*goal: ‹(⋀γ''. is_ground_subst γ'' ⟹ thesis) ⟹ thesis›*) using obtain_ground_subst (*‹(⋀γ. is_ground_subst γ ⟹ ?thesis) ⟹ ?thesis›*) by blast define γ' where "γ'": "γ' = (λvar. if var ∈ vars exp then γ var else γ'' var)" have "is_ground_subst γ'" using assms (*‹is_ground (exp ⋅ γ)›*) "γ''" (*‹is_ground_subst γ''›*) is_grounding_iff_vars_grounded (*‹is_ground (?exp ⋅ ?γ) = (∀x∈vars ?exp. is_ground (?γ x))›*) unfolding "γ'" is_ground_subst_def (*goal: ‹∀x. is_ground (x ⋅ (λvar. if var ∈ vars exp then γ var else γ'' var))›*) by simp moreover have "exp ⋅ γ = exp ⋅ γ'" unfolding "γ'" (*goal: ‹exp ⋅ γ = exp ⋅ (λvar. if var ∈ vars exp then γ var else γ'' var)›*) using subst_eq (*‹(⋀x. x ∈ vars ?a ⟹ ?σ x = ?τ x) ⟹ ?a ⋅ ?σ = ?a ⋅ ?τ›*) by presburger ultimately show "?thesis" (*goal: ‹thesis›*) using that (*‹⟦exp ⋅ γ = exp ⋅ ?γ'1; is_ground_subst ?γ'1⟧ ⟹ thesis›*) by blast qed lemma ground_subst_upd [simp]: assumes "is_ground update" "is_ground (exp ⋅ γ)" shows "is_ground (exp ⋅ γ(var := update))" using assms (*‹is_ground update› ‹is_ground (exp ⋅ γ)›*) is_grounding_iff_vars_grounded (*‹is_ground (?exp ⋅ ?γ) = (∀x∈vars ?exp. is_ground (?γ x))›*) by auto lemma variable_grounding: assumes "is_ground (t ⋅ γ)" "x ∈ vars t" shows "is_ground (γ x)" using assms (*‹is_ground (t ⋅ γ)› ‹x ∈ vars t›*) is_grounding_iff_vars_grounded (*‹is_ground (?exp ⋅ ?γ) = (∀x∈vars ?exp. is_ground (?γ x))›*) by blast end locale based_variable_substitution = base: base_variable_substitution where subst = base_subst and vars = base_vars + variable_substitution for base_subst base_vars + assumes ground_subst_iff_base_ground_subst [simp]: "is_ground_subst γ ⟷ base.is_ground_subst γ" and is_grounding_iff_vars_grounded: "⋀exp. is_ground (exp ⋅ γ) ⟷ (∀x ∈ vars exp. base.is_ground (γ x))" begin lemma obtain_ground_subst: obtains γ where "is_ground_subst γ" using base.obtain_ground_subst (*‹(⋀γ. base.is_ground_subst γ ⟹ ?thesis) ⟹ ?thesis›*) by auto lemma ground_subst_extension: assumes "is_ground (exp ⋅ γ)" obtains γ' where "exp ⋅ γ = exp ⋅ γ'" and "is_ground_subst γ'" using obtain_ground_subst (*‹(⋀γ. is_ground_subst γ ⟹ ?thesis) ⟹ ?thesis›*) assms (*‹is_ground (exp ⋅ γ)›*) by (metis all_subst_ident_if_ground (*‹is_ground ?x ⟹ ∀σ. ?x ⋅ σ = ?x›*) is_ground_subst_comp_right (*‹is_ground_subst ?τ ⟹ is_ground_subst (?σ ⊙ ?τ)›*) subst_comp_subst (*‹?x ⋅ (?a ⊙ ?b) = ?x ⋅ ?a ⋅ ?b›*)) lemma ground_subst_extension': assumes "is_ground (exp ⋅ γ)" obtains γ' where "exp ⋅ γ = exp ⋅ γ'" and "base.is_ground_subst γ'" using ground_subst_extension (*‹⟦is_ground (?exp ⋅ ?γ); ⋀γ'. ⟦?exp ⋅ ?γ = ?exp ⋅ γ'; is_ground_subst γ'⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) assms (*‹is_ground (exp ⋅ γ)›*) by auto lemma ground_subst_upd [simp]: assumes "base.is_ground update" "is_ground (exp ⋅ γ)" shows "is_ground (exp ⋅ γ(var := update))" using base.ground_subst_upd (*‹⟦base.is_ground ?update; base.is_ground (base_subst ?exp ?γ)⟧ ⟹ base.is_ground (base_subst ?exp (?γ(?var := ?update)))›*) assms (*‹base.is_ground update› ‹is_ground (exp ⋅ γ)›*) is_grounding_iff_vars_grounded (*‹is_ground (?exp ⋅ ?γ) = (∀x∈vars ?exp. base.is_ground (?γ x))›*) by simp lemma ground_exists: "∃exp. is_ground exp" using base.ground_exists (*‹∃exp. base.is_ground exp›*) by (meson is_grounding_iff_vars_grounded (*‹is_ground (?exp ⋅ ?γ) = (∀x∈vars ?exp. base.is_ground (?γ x))›*)) lemma variable_grounding: assumes "is_ground (t ⋅ γ)" "x ∈ vars t" shows "base.is_ground (γ x)" using assms (*‹is_ground (t ⋅ γ)› ‹x ∈ vars t›*) is_grounding_iff_vars_grounded (*‹is_ground (?exp ⋅ ?γ) = (∀x∈vars ?exp. base.is_ground (?γ x))›*) by blast end section ‹Liftings› locale variable_substitution_lifting = sub: variable_substitution where subst = sub_subst and vars = sub_vars for sub_vars :: "'sub_expression ⇒ 'variable set" and sub_subst :: "'sub_expression ⇒ ('variable ⇒ 'base_expression) ⇒ 'sub_expression" + fixes map :: "('sub_expression ⇒ 'sub_expression) ⇒ 'expression ⇒ 'expression" and to_set :: "'expression ⇒ 'sub_expression set" assumes map_comp: "⋀d f g. map f (map g d) = map (f ∘ g) d" and map_id: "map id d = d" and map_cong: "⋀d f g. (⋀c. c ∈ to_set d ⟹ f c = g c) ⟹ map f d = map g d" and to_set_map: "⋀d f. to_set (map f d) = f ` to_set d" and exists_expression: "⋀c. ∃d. c ∈ to_set d" begin definition vars :: "'expression ⇒ 'variable set" where "vars d ≡ ⋃ (sub_vars ` to_set d)" definition subst :: "'expression ⇒ ('variable ⇒ 'base_expression) ⇒ 'expression" where "subst d σ ≡ map (λc. sub_subst c σ) d" lemma map_id_cong: assumes "⋀c. c ∈ to_set d ⟹ f c = c" shows "map f d = d" using map_cong (*‹(⋀c. c ∈ to_set ?d ⟹ ?f c = ?g c) ⟹ map ?f ?d = map ?g ?d›*) map_id (*‹map id ?d = ?d›*) assms (*‹(?c1::'sub_expression) ∈ (to_set::'expression ⇒ 'sub_expression set) (d::'expression) ⟹ (f::'sub_expression ⇒ 'sub_expression) ?c1 = ?c1›*) unfolding id_def (*goal: ‹map f d = d›*) by metis lemma to_set_map_not_ident: assumes "c ∈ to_set d" "f c ∉ to_set d" shows "map f d ≠ d" using assms (*‹c ∈ to_set d› ‹(f::'sub_expression ⇒ 'sub_expression) (c::'sub_expression) ∉ (to_set::'expression ⇒ 'sub_expression set) (d::'expression)›*) by (metis rev_image_eqI (*‹⟦?x ∈ ?A; ?b = ?f ?x⟧ ⟹ ?b ∈ ?f ` ?A›*) to_set_map (*‹to_set (map ?f ?d) = ?f ` to_set ?d›*)) lemma subst_in_to_set_subst: assumes "c ∈ to_set d" shows "sub_subst c σ ∈ to_set (subst d σ)" unfolding subst_def (*goal: ‹sub_subst c σ ∈ to_set (map (λc. sub_subst c σ) d)›*) using assms (*‹c ∈ to_set d›*) to_set_map (*‹(to_set::'expression ⇒ 'sub_expression set) ((map::('sub_expression ⇒ 'sub_expression) ⇒ 'expression ⇒ 'expression) (?f::'sub_expression ⇒ 'sub_expression) (?d::'expression)) = ?f ` to_set ?d›*) by auto sublocale variable_substitution where subst = subst and vars = vars proof (unfold_locales) (*goals: 1. ‹⋀x a b. subst x (a ⊙ b) = subst (subst x a) b› 2. ‹⋀x. subst x id_subst = x› 3. ‹⋀x. vars x = {} ⟹ ∀σ. subst x σ = x› 4. ‹⋀a σ τ. (⋀x. x ∈ vars a ⟹ σ x = τ x) ⟹ subst a σ = subst a τ›*) show "⋀x a b. subst x (comp_subst a b) = subst (subst x a) b" using sub.subst_comp_subst (*‹sub_subst ?x (?a ⊙ ?b) = sub_subst (sub_subst ?x ?a) ?b›*) unfolding subst_def map_comp comp_apply (*goal: ‹⋀x a b. map (λc. sub_subst c (a ⊙ b)) x = map (λx. sub_subst (sub_subst x a) b) x›*) by presburger next (*goals: 1. ‹⋀x. subst x id_subst = x› 2. ‹⋀x. vars x = {} ⟹ ∀σ. subst x σ = x› 3. ‹⋀a σ τ. (⋀x. x ∈ vars a ⟹ σ x = τ x) ⟹ subst a σ = subst a τ›*) show "⋀x. subst x id_subst = x" using map_id (*‹map id ?d = ?d›*) unfolding subst_def sub.subst_id_subst id_def (*goal: ‹⋀x. map (λc. c) x = x›*) . next (*goals: 1. ‹⋀x. vars x = {} ⟹ ∀σ. subst x σ = x› 2. ‹⋀a σ τ. (⋀x. x ∈ vars a ⟹ σ x = τ x) ⟹ subst a σ = subst a τ›*) show "⋀x. vars x = {} ⟹ ∀σ. subst x σ = x" unfolding vars_def subst_def (*goal: ‹⋀x::'expression::type. ⋃ ((sub_vars::'sub_expression::type ⇒ 'variable::type set) ` (to_set::'expression::type ⇒ 'sub_expression::type set) x) = {} ⟹ ∀σ::'variable::type ⇒ 'base_expression::type. (map::('sub_expression::type ⇒ 'sub_expression::type) ⇒ 'expression::type ⇒ 'expression::type) (λc::'sub_expression::type. (sub_subst::'sub_expression::type ⇒ ('variable::type ⇒ 'base_expression::type) ⇒ 'sub_expression::type) c σ) x = x›*) using map_id_cong (*‹(⋀c::'sub_expression. c ∈ (to_set::'expression ⇒ 'sub_expression set) (?d::'expression) ⟹ (?f::'sub_expression ⇒ 'sub_expression) c = c) ⟹ (map::('sub_expression ⇒ 'sub_expression) ⇒ 'expression ⇒ 'expression) ?f ?d = ?d›*) by simp next (*goal: ‹⋀a σ τ. (⋀x. x ∈ vars a ⟹ σ x = τ x) ⟹ subst a σ = subst a τ›*) show "⋀a σ τ. (⋀x. x ∈ vars a ⟹ σ x = τ x) ⟹ subst a σ = subst a τ " unfolding vars_def subst_def (*goal: ‹⋀a σ τ. (⋀x. x ∈ ⋃ (sub_vars ` to_set a) ⟹ σ x = τ x) ⟹ map (λc. sub_subst c σ) a = map (λc. sub_subst c τ) a›*) using map_cong (*‹(⋀c. c ∈ to_set ?d ⟹ ?f c = ?g c) ⟹ map ?f ?d = map ?g ?d›*) sub.subst_eq (*‹(⋀x. x ∈ sub_vars ?a ⟹ ?σ x = ?τ x) ⟹ sub_subst ?a ?σ = sub_subst ?a ?τ›*) by (meson UN_I (*‹⟦(?a::?'a::type) ∈ (?A::?'a::type set); (?b::?'b::type) ∈ (?B::?'a::type ⇒ ?'b::type set) ?a⟧ ⟹ ?b ∈ ⋃ (?B ` ?A)›*)) qed lemma ground_subst_iff_sub_ground_subst [simp]: "is_ground_subst γ ⟷ sub.is_ground_subst γ" proof (unfold is_ground_subst_def (*‹is_ground_subst ?γ = (∀x. vars (subst x ?γ) = {})›*) sub.is_ground_subst_def (*‹sub.is_ground_subst ?γ = (∀x. sub.is_ground (sub_subst x ?γ))›*), intro iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*) allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*)) (*goals: 1. ‹⋀x::'sub_expression. ∀x::'expression. vars (subst x (γ::'variable ⇒ 'base_expression)) = {} ⟹ sub.is_ground ((sub_subst::'sub_expression ⇒ ('variable ⇒ 'base_expression) ⇒ 'sub_expression) x γ)› 2. ‹⋀x::'expression. ∀x::'sub_expression. sub.is_ground ((sub_subst::'sub_expression ⇒ ('variable ⇒ 'base_expression) ⇒ 'sub_expression) x (γ::'variable ⇒ 'base_expression)) ⟹ vars (subst x γ) = {}›*) fix c assume all_d_ground: "∀d. is_ground (subst d γ)" (*‹∀d::'expression. vars (subst d (γ::'variable ⇒ 'base_expression)) = {}›*) show "sub.is_ground (sub_subst c γ)" proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹sub_vars (sub_subst c γ) ≠ {} ⟹ False›*) assume c_not_ground: "¬sub.is_ground (sub_subst c γ)" (*‹(sub_vars::'sub_expression ⇒ 'variable set) ((sub_subst::'sub_expression ⇒ ('variable ⇒ 'base_expression) ⇒ 'sub_expression) (c::'sub_expression) (γ::'variable ⇒ 'base_expression)) ≠ {}›*) then obtain d where "c ∈ to_set d" (*goal: ‹(⋀d. c ∈ to_set d ⟹ thesis) ⟹ thesis›*) using exists_expression (*‹∃d. ?c ∈ to_set d›*) by auto then have "¬is_ground (subst d γ)" using c_not_ground (*‹sub_vars (sub_subst c γ) ≠ {}›*) to_set_map (*‹(to_set::'expression ⇒ 'sub_expression set) ((map::('sub_expression ⇒ 'sub_expression) ⇒ 'expression ⇒ 'expression) (?f::'sub_expression ⇒ 'sub_expression) (?d::'expression)) = ?f ` to_set ?d›*) unfolding subst_def vars_def (*goal: ‹⋃ (sub_vars ` to_set (map (λc. sub_subst c γ) d)) ≠ {}›*) by auto then show False using all_d_ground (*‹∀d. vars (subst d γ) = {}›*) by blast qed next (*goal: ‹⋀x. ∀x. sub.is_ground (sub_subst x γ) ⟹ vars (subst x γ) = {}›*) fix d assume all_c_ground: "∀c. sub.is_ground (sub_subst c γ)" (*‹∀c::'sub_expression. sub.is_ground ((sub_subst::'sub_expression ⇒ ('variable ⇒ 'base_expression) ⇒ 'sub_expression) c (γ::'variable ⇒ 'base_expression))›*) then show "is_ground (subst d γ)" unfolding vars_def subst_def (*goal: ‹⋃ (sub_vars ` to_set (map (λc. sub_subst c γ) d)) = {}›*) using to_set_map (*‹to_set (map ?f ?d) = ?f ` to_set ?d›*) by simp qed lemma to_set_is_ground [intro]: assumes "sub ∈ to_set expr" "is_ground expr" shows "sub.is_ground sub" using assms (*‹sub ∈ to_set expr› ‹vars expr = {}›*) by (simp add: vars_def (*‹vars ?d ≡ ⋃ (sub_vars ` to_set ?d)›*)) lemma to_set_is_ground_subst: assumes "sub ∈ to_set expr" "is_ground (subst expr γ)" shows "sub.is_ground (sub_subst sub γ)" using assms (*‹sub ∈ to_set expr› ‹vars (subst expr γ) = {}›*) by (meson subst_in_to_set_subst (*‹?c ∈ to_set ?d ⟹ sub_subst ?c ?σ ∈ to_set (subst ?d ?σ)›*) to_set_is_ground (*‹⟦?sub ∈ to_set ?expr; vars ?expr = {}⟧ ⟹ sub.is_ground ?sub›*)) lemma subst_empty: assumes "to_set expr' = {}" shows "subst expr σ = expr' ⟷ expr = expr'" using assms (*‹to_set expr' = {}›*) map_id_cong (*‹(⋀c::'sub_expression. c ∈ (to_set::'expression ⇒ 'sub_expression set) (?d::'expression) ⟹ (?f::'sub_expression ⇒ 'sub_expression) c = c) ⟹ (map::('sub_expression ⇒ 'sub_expression) ⇒ 'expression ⇒ 'expression) ?f ?d = ?d›*) subst_def (*‹subst (?d::'expression) (?σ::'variable ⇒ 'base_expression) ≡ (map::('sub_expression ⇒ 'sub_expression) ⇒ 'expression ⇒ 'expression) (λc::'sub_expression. (sub_subst::'sub_expression ⇒ ('variable ⇒ 'base_expression) ⇒ 'sub_expression) c ?σ) ?d›*) to_set_map (*‹to_set (map ?f ?d) = ?f ` to_set ?d›*) by fastforce lemma empty_is_ground: assumes "to_set expr = {}" shows "is_ground expr" using assms (*‹to_set expr = {}›*) by (simp add: vars_def (*‹vars ?d ≡ ⋃ (sub_vars ` to_set ?d)›*)) end locale based_variable_substitution_lifting = variable_substitution_lifting + base: base_variable_substitution where subst = base_subst and vars = base_vars for base_subst base_vars + assumes sub_is_grounding_iff_vars_grounded: "⋀exp γ. sub.is_ground (sub_subst exp γ) ⟷ (∀x ∈ sub_vars exp. base.is_ground (γ x))" and sub_ground_subst_iff_base_ground_subst: "⋀γ. sub.is_ground_subst γ ⟷ base.is_ground_subst γ" begin lemma is_grounding_iff_vars_grounded: "is_ground (subst exp γ) ⟷ (∀x ∈ vars exp. base.is_ground (γ x))" using sub_is_grounding_iff_vars_grounded (*‹sub.is_ground (sub_subst ?exp ?γ) = (∀x∈sub_vars ?exp. base.is_ground (?γ x))›*) subst_def (*‹subst (?d::'d::type) (?σ::'a::type ⇒ 'b::type) ≡ (map::('c::type ⇒ 'c::type) ⇒ 'd::type ⇒ 'd::type) (λc::'c::type. (sub_subst::'c::type ⇒ ('a::type ⇒ 'b::type) ⇒ 'c::type) c ?σ) ?d›*) to_set_map (*‹(to_set::'d ⇒ 'c set) ((map::('c ⇒ 'c) ⇒ 'd ⇒ 'd) (?f::'c ⇒ 'c) (?d::'d)) = ?f ` to_set ?d›*) vars_def (*‹vars ?d ≡ ⋃ (sub_vars ` to_set ?d)›*) by auto lemma ground_subst_iff_base_ground_subst [simp]: "⋀γ. is_ground_subst γ ⟷ base.is_ground_subst γ" using sub_ground_subst_iff_base_ground_subst (*‹sub.is_ground_subst ?γ = base.is_ground_subst ?γ›*) ground_subst_iff_sub_ground_subst (*‹is_ground_subst ?γ = sub.is_ground_subst ?γ›*) by blast lemma obtain_ground_subst: obtains γ where "is_ground_subst γ" using base.obtain_ground_subst (*‹(⋀γ. base.is_ground_subst γ ⟹ ?thesis) ⟹ ?thesis›*) by (meson base.ground_exists (*‹∃exp. base.is_ground exp›*) is_grounding_iff_vars_grounded (*‹(vars (subst ?exp ?γ) = {}) = (∀x∈vars ?exp. base.is_ground (?γ x))›*) is_ground_subst_def (*‹is_ground_subst ?γ = (∀x. vars (subst x ?γ) = {})›*) that (*‹is_ground_subst ?γ1 ⟹ thesis›*)) lemma ground_subst_extension: assumes "is_ground (subst exp γ)" obtains γ' where "subst exp γ = subst exp γ'" and "is_ground_subst γ'" by (metis all_subst_ident_if_ground (*‹vars ?x = {} ⟹ ∀σ. subst ?x σ = ?x›*) assms (*‹vars (subst exp γ) = {}›*) comp_subst.left.monoid_action_compatibility (*‹subst ?x (?b ⊙ ?a) = subst (subst ?x ?b) ?a›*) is_ground_subst_comp_right (*‹is_ground_subst ?τ ⟹ is_ground_subst (?σ ⊙ ?τ)›*) obtain_ground_subst (*‹(⋀γ. is_ground_subst γ ⟹ ?thesis) ⟹ ?thesis›*)) lemma ground_subst_extension': assumes "is_ground (subst exp γ)" obtains γ' where "subst exp γ = subst exp γ'" and "base.is_ground_subst γ'" by (metis all_subst_ident_if_ground (*‹vars (?x::'d) = {} ⟹ ∀σ::'a ⇒ 'b. subst ?x σ = ?x›*) assms (*‹vars (subst (exp::'d) (γ::'a ⇒ 'b)) = {}›*) base.is_ground_subst_comp_right (*‹base.is_ground_subst (?τ::'a ⇒ 'b) ⟹ base.is_ground_subst ((?σ::'a ⇒ 'b) ⊙ ?τ)›*) base.obtain_ground_subst (*‹(⋀γ::'a ⇒ 'b. base.is_ground_subst γ ⟹ ?thesis::bool) ⟹ ?thesis›*) subst_comp_subst (*‹subst (?x::'d) ((?a::'a ⇒ 'b) ⊙ (?b::'a ⇒ 'b)) = subst (subst ?x ?a) ?b›*)) lemma ground_subst_upd [simp]: assumes "base.is_ground update" "is_ground (subst exp γ)" shows "is_ground (subst exp (γ(var := update)))" using assms(1) (*‹base.is_ground update›*) assms(2) (*‹vars (subst exp γ) = {}›*) is_grounding_iff_vars_grounded (*‹(vars (subst ?exp ?γ) = {}) = (∀x∈vars ?exp. base.is_ground (?γ x))›*) by auto lemma ground_exists: "∃exp. is_ground exp" using base.ground_exists (*‹∃exp. base.is_ground exp›*) by (meson is_grounding_iff_vars_grounded (*‹(vars (subst (?exp::'d::type) (?γ::'a::type ⇒ 'b::type)) = {}) = (∀x::'a::type∈vars ?exp. base.is_ground (?γ x))›*)) lemma variable_grounding: assumes "is_ground (subst t γ)" "x ∈ vars t" shows "base.is_ground (γ x)" using assms (*‹vars (subst t γ) = {}› ‹x ∈ vars t›*) is_grounding_iff_vars_grounded (*‹(vars (subst ?exp ?γ) = {}) = (∀x∈vars ?exp. base.is_ground (?γ x))›*) by blast end locale finite_variables_lifting = variable_substitution_lifting + sub: finite_variables where vars = sub_vars + to_set: finite_set where set = to_set begin abbreviation to_fset :: "'d ⇒ 'c fset" where "to_fset ≡ to_set.finite_set" lemmas finite_to_set = to_set.finite_set to_set.finite_set' lemmas fset_to_fset = to_set.fset_finite_set sublocale finite_variables where vars = vars apply unfold_locales (*goal: ‹finite_variables vars›*) by (simp add: vars_def (*‹vars ?d ≡ ⋃ (sub_vars ` to_set ?d)›*)) end locale grounding_lifting = variable_substitution_lifting where sub_vars = sub_vars and sub_subst = sub_subst and map = map + sub: grounding where vars = sub_vars and subst = sub_subst and to_ground = sub_to_ground and from_ground = sub_from_ground for sub_to_ground :: "'sub ⇒ 'ground_sub" and sub_from_ground :: "'ground_sub ⇒ 'sub" and sub_vars :: "'sub ⇒ 'variable set" and sub_subst :: "'sub ⇒ ('variable ⇒ 'base) ⇒ 'sub" and map :: "('sub ⇒ 'sub) ⇒ 'expr ⇒ 'expr" + fixes to_ground_map :: "('sub ⇒ 'ground_sub) ⇒ 'expr ⇒ 'ground_expr" and from_ground_map :: "('ground_sub ⇒ 'sub) ⇒ 'ground_expr ⇒ 'expr" and ground_map :: "('ground_sub ⇒ 'ground_sub) ⇒ 'ground_expr ⇒ 'ground_expr" and to_set_ground :: "'ground_expr ⇒ 'ground_sub set" assumes to_set_from_ground_map: "⋀d f. to_set (from_ground_map f d) = f ` to_set_ground d" and map_comp': "⋀d f g. from_ground_map f (to_ground_map g d) = map (f ∘ g) d" and ground_map_comp: "⋀d f g. to_ground_map f (from_ground_map g d) = ground_map (f ∘ g) d" and ground_map_id: "ground_map id g = g" begin definition to_ground where "to_ground expr ≡ to_ground_map sub_to_ground expr" definition from_ground where "from_ground expr ≡ from_ground_map sub_from_ground expr" sublocale grounding where vars = vars and subst = subst and to_ground = to_ground and from_ground = from_ground proof (unfold_locales) (*goals: 1. ‹{f. vars f = {}} = range from_ground› 2. ‹⋀g. to_ground (from_ground g) = g›*) have "⋀expr. vars expr = {} ⟹ expr ∈ range from_ground" proof (-) (*goal: ‹⋀expr. vars expr = {} ⟹ expr ∈ range from_ground›*) fix expr assume "vars expr = {}" (*‹vars (expr::'expr) = {}›*) then have "∀sub∈to_set expr. sub ∈ range sub_from_ground" by (simp add: sub.is_ground_iff_range_from_ground (*‹sub.is_ground ?f = (?f ∈ range sub_from_ground)›*) vars_def (*‹vars ?d ≡ ⋃ (sub_vars ` to_set ?d)›*)) then have "∀sub∈to_set expr. ∃sub_ground. sub_from_ground sub_ground = sub" by fast then have "∃ground_expr. from_ground ground_expr = expr" using map_comp'[symmetric] (*‹map (?f ∘ ?g) ?d = from_ground_map ?f (to_ground_map ?g ?d)›*) map_id_cong (*‹(⋀c. c ∈ to_set ?d ⟹ ?f c = c) ⟹ map ?f ?d = ?d›*) unfolding from_ground_def comp_def (*goal: ‹∃ground_expr::'ground_expr. (from_ground_map::('ground_sub ⇒ 'sub) ⇒ 'ground_expr ⇒ 'expr) (sub_from_ground::'ground_sub ⇒ 'sub) ground_expr = (expr::'expr)›*) by metis then show "expr ∈ range from_ground" unfolding from_ground_def (*goal: ‹expr ∈ range (from_ground_map sub_from_ground)›*) by blast qed moreover have "⋀expr x. x ∈ vars (from_ground expr) ⟹ False" proof (-) (*goal: ‹⋀expr x. x ∈ vars (from_ground expr) ⟹ False›*) fix expr and x assume "x ∈ vars (from_ground expr)" (*‹(x::'variable) ∈ vars (from_ground (expr::'ground_expr))›*) then show False unfolding vars_def from_ground_def (*goal: ‹False›*) using sub.ground_is_ground (*‹sub.is_ground (sub_from_ground ?g)›*) to_set_from_ground_map (*‹to_set (from_ground_map ?f ?d) = ?f ` to_set_ground ?d›*) by auto qed ultimately show "{f. vars f = {}} = range from_ground" by blast next (*goal: ‹⋀g. to_ground (from_ground g) = g›*) show "⋀g. to_ground (from_ground g) = g" using ground_map_id (*‹ground_map id ?g = ?g›*) unfolding to_ground_def from_ground_def ground_map_comp sub.to_ground_from_ground_id (*goal: ‹⋀g. ground_map id g = g›*) . qed lemma to_set_from_ground: "to_set (from_ground expr) = sub_from_ground ` (to_set_ground expr)" unfolding from_ground_def (*goal: ‹to_set (from_ground_map sub_from_ground expr) = sub_from_ground ` to_set_ground expr›*) by (simp add: to_set_from_ground_map (*‹to_set (from_ground_map ?f ?d) = ?f ` to_set_ground ?d›*)) lemma sub_in_ground_is_ground: assumes "sub ∈ to_set (from_ground expr)" shows "sub.is_ground sub" using assms (*‹sub ∈ to_set (from_ground expr)›*) by (simp add: to_set_is_ground (*‹⟦?sub ∈ to_set ?expr; vars ?expr = {}⟧ ⟹ sub.is_ground ?sub›*)) lemma ground_sub_in_ground: "sub ∈ to_set_ground expr ⟷ sub_from_ground sub ∈ to_set (from_ground expr)" by (simp add: inj_image_mem_iff (*‹inj ?f ⟹ (?f ?a ∈ ?f ` ?A) = (?a ∈ ?A)›*) sub.inj_from_ground (*‹inj_on sub_from_ground ?domain⇩G›*) to_set_from_ground (*‹to_set (from_ground ?expr) = sub_from_ground ` to_set_ground ?expr›*)) lemma ground_sub: "(∀sub ∈ to_set (from_ground expr⇩G). P sub) ⟷ (∀sub⇩G ∈ to_set_ground expr⇩G. P (sub_from_ground sub⇩G))" by (simp add: to_set_from_ground (*‹to_set (from_ground ?expr) = sub_from_ground ` to_set_ground ?expr›*)) end locale all_subst_ident_iff_ground_lifting = finite_variables_lifting + sub: all_subst_ident_iff_ground where subst = sub_subst and is_ground = sub.is_ground begin sublocale all_subst_ident_iff_ground where subst = subst and is_ground = is_ground proof (unfold_locales) (*goals: 1. ‹⋀a. (vars a = {}) = (∀σ. subst a σ = a)› 2. ‹⋀a s. ⟦finite s; vars a ≠ {}⟧ ⟹ ∃σ. subst a σ ≠ a ∧ subst a σ ∉ s›*) show "⋀x. is_ground x = (∀σ. subst x σ = x)" proof (rule iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*) allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*)) (*goals: 1. ‹⋀x. vars x = {} ⟹ ∀σ. subst x σ = x› 2. ‹⋀x. ∀σ. subst x σ = x ⟹ vars x = {}›*) show "⋀x. is_ground x ⟹ ∀σ. subst x σ = x" by simp next (*goal: ‹⋀x. ∀σ. subst x σ = x ⟹ vars x = {}›*) fix d and x assume all_subst_ident: "∀σ. subst d σ = d" (*‹∀σ::'a ⇒ 'b. subst (d::'d) σ = d›*) show "is_ground d" proof (rule ccontr (*‹(¬ (?P::bool) ⟹ False) ⟹ ?P›*)) (*goal: ‹vars d ≠ {} ⟹ False›*) assume "¬is_ground d" (*‹vars (d::'d) ≠ {}›*) then obtain c where c_in_d: "c ∈ to_set d" and c_not_ground: "¬sub.is_ground c" (*goal: ‹(⋀c. ⟦c ∈ to_set d; sub_vars c ≠ {}⟧ ⟹ thesis) ⟹ thesis›*) unfolding vars_def (*goal: ‹(⋀c. ⟦c ∈ to_set d; sub_vars c ≠ {}⟧ ⟹ thesis) ⟹ thesis›*) by blast then obtain σ where "sub_subst c σ ≠ c" and "sub_subst c σ ∉ to_set d" (*goal: ‹(⋀σ. ⟦sub_subst c σ ≠ c; sub_subst c σ ∉ to_set d⟧ ⟹ thesis) ⟹ thesis›*) using sub.exists_non_ident_subst (*‹⟦finite (?s::'c::type set); (sub_vars::'c::type ⇒ 'a::type set) (?a::'c::type) ≠ {}⟧ ⟹ ∃σ::'a::type ⇒ 'b::type. (sub_subst::'c::type ⇒ ('a::type ⇒ 'b::type) ⇒ 'c::type) ?a σ ≠ ?a ∧ sub_subst ?a σ ∉ ?s›*) finite_to_set (*‹finite (to_set ?b)› ‹to_set ?b ∈ {A. finite A}›*) by blast then show False using all_subst_ident (*‹∀σ. subst d σ = d›*) c_in_d (*‹(c::'c) ∈ (to_set::'d ⇒ 'c set) (d::'d)›*) to_set_map (*‹(to_set::'d::type ⇒ 'c::type set) ((map::('c::type ⇒ 'c::type) ⇒ 'd::type ⇒ 'd::type) (?f::'c::type ⇒ 'c::type) (?d::'d::type)) = ?f ` to_set ?d›*) unfolding subst_def (*goal: ‹False›*) by (metis image_eqI (*‹⟦?b = ?f ?x; ?x ∈ ?A⟧ ⟹ ?b ∈ ?f ` ?A›*)) qed qed next (*goal: ‹⋀a s. ⟦finite s; vars a ≠ {}⟧ ⟹ ∃σ. subst a σ ≠ a ∧ subst a σ ∉ s›*) fix d :: 'd and ds :: "'d set" assume finite_ds: "finite ds" and d_not_ground: "¬is_ground d" (*‹finite (ds::'d set)› ‹vars (d::'d) ≠ {}›*) then have finite_cs: "finite (⋃(to_set ` insert d ds))" using finite_to_set (*‹finite (to_set ?b)› ‹to_set ?b ∈ {A. finite A}›*) by blast obtain c where c_in_d: "c ∈ to_set d" and c_not_ground: "¬sub.is_ground c" (*goal: ‹(⋀c. ⟦c ∈ to_set d; sub_vars c ≠ {}⟧ ⟹ thesis) ⟹ thesis›*) using d_not_ground (*‹vars d ≠ {}›*) unfolding vars_def (*goal: ‹(⋀c::'c::type. ⟦c ∈ (to_set::'d::type ⇒ 'c::type set) (d::'d::type); (sub_vars::'c::type ⇒ 'a::type set) c ≠ {}⟧ ⟹ thesis::bool) ⟹ thesis›*) by blast obtain σ where "σ_not_ident": "sub_subst c σ ≠ c" "sub_subst c σ ∉ ⋃ (to_set ` insert d ds)" (*goal: ‹(⋀σ. ⟦sub_subst c σ ≠ c; sub_subst c σ ∉ ⋃ (to_set ` insert d ds)⟧ ⟹ thesis) ⟹ thesis›*) using sub.exists_non_ident_subst[OF finite_cs c_not_ground] (*‹∃σ. sub_subst c σ ≠ c ∧ sub_subst c σ ∉ ⋃ (to_set ` insert d ds)›*) by blast then have "subst d σ ≠ d" using c_in_d (*‹(c::'c) ∈ (to_set::'d ⇒ 'c set) (d::'d)›*) unfolding subst_def (*goal: ‹map (λc. sub_subst c σ) d ≠ d›*) by (simp add: to_set_map_not_ident (*‹⟦?c ∈ to_set ?d; ?f ?c ∉ to_set ?d⟧ ⟹ map ?f ?d ≠ ?d›*)) moreover have "subst d σ ∉ ds" using "σ_not_ident"(2) (*‹sub_subst c σ ∉ ⋃ (to_set ` insert d ds)›*) c_in_d (*‹c ∈ to_set d›*) to_set_map (*‹to_set (map ?f ?d) = ?f ` to_set ?d›*) unfolding subst_def (*goal: ‹map (λc. sub_subst c σ) d ∉ ds›*) by auto ultimately show "∃σ. subst d σ ≠ d ∧ subst d σ ∉ ds" by blast qed end end
{ "path": "afp-2025-02-12/thys/Superposition_Calculus/Variable_Substitution.thy", "repo": "afp-2025-02-12", "sha": "f3c144ce197fbdc2ea9ed1a4e6fb70e01e70cba4ad6a219f7e865acc862877be" }
(* Title: HOL/Partial_Function.thy Author: Alexander Krauss, TU Muenchen *) section ‹Partial Function Definitions› theory Partial_Function imports Complete_Partial_Order Option keywords "partial_function" :: thy_defn begin named_theorems partial_function_mono "monotonicity rules for partial function definitions" ML_file ‹Tools/Function/partial_function.ML› lemma (in ccpo) in_chain_finite: assumes "Complete_Partial_Order.chain (≤) A" "finite A" "A ≠ {}" shows "⨆A ∈ A" using assms(2,1,3) (*‹finite A› ‹chain (≤) A› ‹(A::'a set) ≠ {}›*) proof (induction) (*goals: 1. ‹⟦chain (≤) {}; {} ≠ {}⟧ ⟹ ⨆ {} ∈ {}› 2. ‹⋀x F. ⟦finite F; x ∉ F; ⟦chain (≤) F; F ≠ {}⟧ ⟹ ⨆ F ∈ F; chain (≤) (insert x F); insert x F ≠ {}⟧ ⟹ ⨆ insert x F ∈ insert x F›*) case empty (*‹chain (≤) {}› ‹{} ≠ {}›*) thus "?case" (*goal: ‹⨆ {} ∈ {}›*) by simp next (*goal: ‹⋀x F. ⟦finite F; x ∉ F; ⟦chain (≤) F; F ≠ {}⟧ ⟹ ⨆ F ∈ F; chain (≤) (insert x F); insert x F ≠ {}⟧ ⟹ ⨆ insert x F ∈ insert x F›*) case (insert x A) (*‹finite A› ‹(x::'a::type) ∉ (A::'a::type set)› ‹⟦chain (≤) A; A ≠ {}⟧ ⟹ ⨆ A ∈ A› ‹chain (≤) (insert x A)› ‹insert (x::'a) (A::'a set) ≠ {}›*) note chain = ‹Complete_Partial_Order.chain (≤) (insert x A)› (*‹chain (≤) (insert x A)›*) show "?case" (*goal: ‹⨆ insert x A ∈ insert x A›*) proof (cases "A = {}") (*goals: 1. ‹A = {} ⟹ ⨆ insert x A ∈ insert x A› 2. ‹A ≠ {} ⟹ ⨆ insert x A ∈ insert x A›*) case True (*‹A = {}›*) thus "?thesis" (*goal: ‹⨆ insert x A ∈ insert x A›*) by simp next (*goal: ‹(A::'a::type set) ≠ {} ⟹ ⨆ insert (x::'a::type) A ∈ insert x A›*) case False (*‹A ≠ {}›*) from chain (*‹chain (≤) (insert x A)›*) have chain': "Complete_Partial_Order.chain (≤) A" apply (rule chain_subset (*‹⟦chain ?ord ?A; ?B ⊆ ?A⟧ ⟹ chain ?ord ?B›*)) (*goal: ‹chain (≤) A›*) by blast hence "⨆A ∈ A" using False (*‹(A::'a set) ≠ {}›*) by (rule insert.IH (*‹⟦chain (≤) A; A ≠ {}⟧ ⟹ ⨆ A ∈ A›*)) show "?thesis" (*goal: ‹⨆ insert x A ∈ insert x A›*) proof (cases "x ≤ ⨆A") (*goals: 1. ‹x ≤ ⨆ A ⟹ ⨆ insert x A ∈ insert x A› 2. ‹¬ x ≤ ⨆ A ⟹ ⨆ insert x A ∈ insert x A›*) case True (*‹x ≤ ⨆ A›*) have "⨆(insert x A) ≤ ⨆A" using chain (*‹chain (≤) (insert x A)›*) apply (rule ccpo_Sup_least (*‹⟦chain (≤) ?A; ⋀x. x ∈ ?A ⟹ x ≤ ?z⟧ ⟹ ⨆ ?A ≤ ?z›*)) (*goal: ‹⨆ insert x A ≤ ⨆ A›*) by (auto simp add: True (*‹(x::'a) ≤ ⨆ (A::'a set)›*) intro: ccpo_Sup_upper[OF chain'] (*‹(?x::'a) ∈ (A::'a set) ⟹ ?x ≤ ⨆ A›*)) hence "⨆(insert x A) = ⨆A" apply (rule order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) (*goal: ‹⨆ insert x A = ⨆ A›*) by (blast intro: ccpo_Sup_upper[OF chain] (*‹?x ∈ insert x A ⟹ ?x ≤ ⨆ insert x A›*) ccpo_Sup_least[OF chain'] (*‹(⋀x. x ∈ A ⟹ x ≤ ?z) ⟹ ⨆ A ≤ ?z›*)) with ‹⨆A ∈ A› (*‹⨆ (A::'a set) ∈ A›*) show "?thesis" (*goal: ‹⨆ insert x A ∈ insert x A›*) by simp next (*goal: ‹¬ (x::'a) ≤ ⨆ (A::'a set) ⟹ ⨆ insert x A ∈ insert x A›*) case False (*‹¬ x ≤ ⨆ A›*) with chainD[OF chain, of x "⨆A"] (*‹⟦x ∈ insert x A; ⨆ A ∈ insert x A⟧ ⟹ x ≤ ⨆ A ∨ ⨆ A ≤ x›*) ‹⨆A ∈ A› (*‹⨆ A ∈ A›*) have "⨆(insert x A) = x" by (auto intro: order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*) ccpo_Sup_least[OF chain] (*‹(⋀xa. xa ∈ insert x A ⟹ xa ≤ ?z) ⟹ ⨆ insert x A ≤ ?z›*) order_trans[OF ccpo_Sup_upper[OF chain']] (*‹⟦?x ∈ A; ⨆ A ≤ ?z⟧ ⟹ ?x ≤ ?z›*) ccpo_Sup_upper[OF chain] (*‹?x ∈ insert x A ⟹ ?x ≤ ⨆ insert x A›*)) thus "?thesis" (*goal: ‹⨆ insert (x::'a) (A::'a set) ∈ insert x A›*) by simp qed qed qed lemma (in ccpo) admissible_chfin: "(∀S. Complete_Partial_Order.chain (≤) S ⟶ finite S) ⟹ ccpo.admissible Sup (≤) P" using in_chain_finite (*‹⟦chain (≤) ?A; finite ?A; ?A ≠ {}⟧ ⟹ ⨆ ?A ∈ ?A›*) by (blast intro: ccpo.admissibleI (*‹(⋀A. ⟦chain ?ord A; A ≠ {}; ∀x∈A. ?P x⟧ ⟹ ?P (?lub A)) ⟹ ccpo.admissible ?lub ?ord ?P›*)) subsection ‹Axiomatic setup› text ‹This techical locale constains the requirements for function definitions with ccpo fixed points.› definition "fun_ord ord f g ⟷ (∀x. ord (f x) (g x))" definition "fun_lub L A = (λx. L {y. ∃f∈A. y = f x})" definition "img_ord f ord = (λx y. ord (f x) (f y))" definition "img_lub f g Lub = (λA. g (Lub (f ` A)))" lemma chain_fun: assumes A: "chain (fun_ord ord) A" shows "chain ord {y. ∃f∈A. y = f a}" (is "chain ord ?C") proof (rule chainI (*‹(⋀x y. ⟦x ∈ ?S; y ∈ ?S⟧ ⟹ ?ord x y ∨ ?ord y x) ⟹ chain ?ord ?S›*)) (*goal: ‹⋀x y. ⟦x ∈ {y. ∃f∈A. y = f a}; y ∈ {y. ∃f∈A. y = f a}⟧ ⟹ ord x y ∨ ord y x›*) fix x and y assume "x ∈ ?C" "y ∈ ?C" (*‹(x::'b) ∈ {y::'b. ∃f::'a ⇒ 'b∈A::('a ⇒ 'b) set. y = f (a::'a)}› ‹(y::'b) ∈ {y::'b. ∃f::'a ⇒ 'b∈A::('a ⇒ 'b) set. y = f (a::'a)}›*) then obtain f and g where fg: "f ∈ A" "g ∈ A" and [simp]: "x = f a" "y = g a" (*goal: ‹(⋀f g. ⟦f ∈ A; g ∈ A; x = f a; y = g a⟧ ⟹ thesis) ⟹ thesis›*) by blast from chainD[OF A fg] (*‹fun_ord (ord::'b ⇒ 'b ⇒ bool) (f::'a ⇒ 'b) (g::'a ⇒ 'b) ∨ fun_ord ord g f›*) show "ord x y ∨ ord y x" unfolding fun_ord_def (*goal: ‹ord x y ∨ ord y x›*) by auto qed lemma call_mono[partial_function_mono]: "monotone (fun_ord ord) ord (λf. f t)" apply (rule monotoneI (*‹(⋀x y. ?orda x y ⟹ ?ordb (?f x) (?f y)) ⟹ monotone ?orda ?ordb ?f›*)) (*goal: ‹monotone (fun_ord ord) ord (λf. f t)›*) by (auto simp: fun_ord_def (*‹fun_ord ?ord ?f ?g = (∀x. ?ord (?f x) (?g x))›*)) lemma let_mono[partial_function_mono]: "(⋀x. monotone orda ordb (λf. b f x)) ⟹ monotone orda ordb (λf. Let t (b f))" by (simp add: Let_def (*‹Let ?s ?f ≡ ?f ?s›*)) lemma if_mono[partial_function_mono]: "monotone orda ordb F ⟹ monotone orda ordb G ⟹ monotone orda ordb (λf. if c then F f else G f)" unfolding monotone_def (*goal: ‹⟦∀x y. orda x y ⟶ ordb (F x) (F y); ∀x y. orda x y ⟶ ordb (G x) (G y)⟧ ⟹ ∀x y. orda x y ⟶ ordb (if c then F x else G x) (if c then F y else G y)›*) by simp definition "mk_less R = (λx y. R x y ∧ ¬ R y x)" locale partial_function_definitions = fixes leq :: "'a ⇒ 'a ⇒ bool" fixes lub :: "'a set ⇒ 'a" assumes leq_refl: "leq x x" assumes leq_trans: "leq x y ⟹ leq y z ⟹ leq x z" assumes leq_antisym: "leq x y ⟹ leq y x ⟹ x = y" assumes lub_upper: "chain leq A ⟹ x ∈ A ⟹ leq x (lub A)" assumes lub_least: "chain leq A ⟹ (⋀x. x ∈ A ⟹ leq x z) ⟹ leq (lub A) z" lemma partial_function_lift: assumes "partial_function_definitions ord lb" shows "partial_function_definitions (fun_ord ord) (fun_lub lb)" (is "partial_function_definitions ?ordf ?lubf") proof (-) (*goal: ‹partial_function_definitions (fun_ord ord) (fun_lub lb)›*) interpret partial_function_definitions ord lb by fact show "?thesis" (*goal: ‹partial_function_definitions (fun_ord ord) (fun_lub lb)›*) proof (standard) (*goals: 1. ‹⋀x. fun_ord ord x x› 2. ‹⋀x y z. ⟦fun_ord ord x y; fun_ord ord y z⟧ ⟹ fun_ord ord x z› 3. ‹⋀x y. ⟦fun_ord ord x y; fun_ord ord y x⟧ ⟹ x = y› 4. ‹⋀A x. ⟦chain (fun_ord ord) A; x ∈ A⟧ ⟹ fun_ord ord x (fun_lub lb A)› 5. ‹⋀A z. ⟦chain (fun_ord ord) A; ⋀x. x ∈ A ⟹ fun_ord ord x z⟧ ⟹ fun_ord ord (fun_lub lb A) z›*) fix x show "?ordf x x" unfolding fun_ord_def (*goal: ‹∀xa. ord (x xa) (x xa)›*) by (auto simp: leq_refl (*‹ord ?x ?x›*)) next (*goals: 1. ‹⋀x y z. ⟦fun_ord ord x y; fun_ord ord y z⟧ ⟹ fun_ord ord x z› 2. ‹⋀x y. ⟦fun_ord ord x y; fun_ord ord y x⟧ ⟹ x = y› 3. ‹⋀A x. ⟦chain (fun_ord ord) A; x ∈ A⟧ ⟹ fun_ord ord x (fun_lub lb A)› 4. ‹⋀A z. ⟦chain (fun_ord ord) A; ⋀x. x ∈ A ⟹ fun_ord ord x z⟧ ⟹ fun_ord ord (fun_lub lb A) z›*) fix x and y and z assume "?ordf x y" "?ordf y z" (*‹fun_ord (ord::'a ⇒ 'a ⇒ bool) (x::'b ⇒ 'a) (y::'b ⇒ 'a)› ‹fun_ord (ord::'a ⇒ 'a ⇒ bool) (y::'b ⇒ 'a) (z::'b ⇒ 'a)›*) thus "?ordf x z" unfolding fun_ord_def (*goal: ‹∀xa. ord (x xa) (z xa)›*) by (force dest: leq_trans (*‹⟦(ord::'a::type ⇒ 'a::type ⇒ bool) (?x::'a::type) (?y::'a::type); ord ?y (?z::'a::type)⟧ ⟹ ord ?x ?z›*)) next (*goals: 1. ‹⋀x y. ⟦fun_ord ord x y; fun_ord ord y x⟧ ⟹ x = y› 2. ‹⋀A x. ⟦chain (fun_ord ord) A; x ∈ A⟧ ⟹ fun_ord ord x (fun_lub lb A)› 3. ‹⋀A z. ⟦chain (fun_ord ord) A; ⋀x. x ∈ A ⟹ fun_ord ord x z⟧ ⟹ fun_ord ord (fun_lub lb A) z›*) fix x and y assume "?ordf x y" "?ordf y x" (*‹fun_ord (ord::'a ⇒ 'a ⇒ bool) (x::'b ⇒ 'a) (y::'b ⇒ 'a)› ‹fun_ord (ord::'a ⇒ 'a ⇒ bool) (y::'b ⇒ 'a) (x::'b ⇒ 'a)›*) thus "x = y" unfolding fun_ord_def (*goal: ‹x = y›*) by (force intro!: dest: leq_antisym (*‹⟦ord ?x ?y; ord ?y ?x⟧ ⟹ ?x = ?y›*)) next (*goals: 1. ‹⋀(A::('b ⇒ 'a) set) x::'b ⇒ 'a. ⟦chain (fun_ord (ord::'a ⇒ 'a ⇒ bool)) A; x ∈ A⟧ ⟹ fun_ord ord x (fun_lub (lb::'a set ⇒ 'a) A)› 2. ‹⋀(A::('b ⇒ 'a) set) z::'b ⇒ 'a. ⟦chain (fun_ord (ord::'a ⇒ 'a ⇒ bool)) A; ⋀x::'b ⇒ 'a. x ∈ A ⟹ fun_ord ord x z⟧ ⟹ fun_ord ord (fun_lub (lb::'a set ⇒ 'a) A) z›*) fix A and f assume f: "f ∈ A" and A: "chain ?ordf A" (*‹(f::'b ⇒ 'a) ∈ (A::('b ⇒ 'a) set)› ‹chain (fun_ord (ord::'a ⇒ 'a ⇒ bool)) (A::('b ⇒ 'a) set)›*) thus "?ordf f (?lubf A)" unfolding fun_lub_def fun_ord_def (*goal: ‹∀x::'b. (ord::'a ⇒ 'a ⇒ bool) ((f::'b ⇒ 'a) x) ((lb::'a set ⇒ 'a) {y::'a. ∃f::'b ⇒ 'a∈A::('b ⇒ 'a) set. y = f x})›*) by (blast intro: lub_upper (*‹⟦chain ord ?A; ?x ∈ ?A⟧ ⟹ ord ?x (lb ?A)›*) chain_fun[OF A] (*‹chain ord {y. ∃f∈A. y = f ?a}›*) f (*‹f ∈ A›*)) next (*goal: ‹⋀A z. ⟦chain (fun_ord ord) A; ⋀x. x ∈ A ⟹ fun_ord ord x z⟧ ⟹ fun_ord ord (fun_lub lb A) z›*) fix A :: "('b ⇒ 'a) set" and g :: "'b ⇒ 'a" assume A: "chain ?ordf A" and g: "⋀f. f ∈ A ⟹ ?ordf f g" (*‹chain (fun_ord (ord::'a ⇒ 'a ⇒ bool)) (A::('b ⇒ 'a) set)› ‹(?f::'b ⇒ 'a) ∈ (A::('b ⇒ 'a) set) ⟹ fun_ord (ord::'a ⇒ 'a ⇒ bool) ?f (g::'b ⇒ 'a)›*) show "?ordf (?lubf A) g" unfolding fun_lub_def fun_ord_def (*goal: ‹∀x::'b. (ord::'a ⇒ 'a ⇒ bool) ((lb::'a set ⇒ 'a) {y::'a. ∃f::'b ⇒ 'a∈A::('b ⇒ 'a) set. y = f x}) ((g::'b ⇒ 'a) x)›*) by (blast intro: lub_least (*‹⟦chain ord ?A; ⋀x. x ∈ ?A ⟹ ord x ?z⟧ ⟹ ord (lb ?A) ?z›*) chain_fun[OF A] (*‹chain ord {y. ∃f∈A. y = f ?a}›*) dest: g[unfolded fun_ord_def] (*‹?f ∈ A ⟹ ∀x. ord (?f x) (g x)›*)) qed qed lemma ccpo: assumes "partial_function_definitions ord lb" shows "class.ccpo lb ord (mk_less ord)" using assms (*‹partial_function_definitions ord lb›*) unfolding partial_function_definitions_def mk_less_def (*goal: ‹class.ccpo lb ord (λx y. ord x y ∧ ¬ ord y x)›*) apply unfold_locales (*goals: 1. ‹⋀x y. ((∀x. ord x x) ∧ (∀x y z. ord x y ⟶ ord y z ⟶ ord x z)) ∧ (∀x y. ord x y ⟶ ord y x ⟶ x = y) ∧ (∀A x. chain ord A ⟶ x ∈ A ⟶ ord x (lb A)) ∧ (∀A z. chain ord A ⟶ (∀x. x ∈ A ⟶ ord x z) ⟶ ord (lb A) z) ⟹ (ord x y ∧ ¬ ord y x) = (ord x y ∧ ¬ ord y x)› 2. ‹⋀x. ((∀x. ord x x) ∧ (∀x y z. ord x y ⟶ ord y z ⟶ ord x z)) ∧ (∀x y. ord x y ⟶ ord y x ⟶ x = y) ∧ (∀A x. chain ord A ⟶ x ∈ A ⟶ ord x (lb A)) ∧ (∀A z. chain ord A ⟶ (∀x. x ∈ A ⟶ ord x z) ⟶ ord (lb A) z) ⟹ ord x x› 3. ‹⋀x y z. ⟦((∀x. ord x x) ∧ (∀x y z. ord x y ⟶ ord y z ⟶ ord x z)) ∧ (∀x y. ord x y ⟶ ord y x ⟶ x = y) ∧ (∀A x. chain ord A ⟶ x ∈ A ⟶ ord x (lb A)) ∧ (∀A z. chain ord A ⟶ (∀x. x ∈ A ⟶ ord x z) ⟶ ord (lb A) z); ord x y; ord y z⟧ ⟹ ord x z› 4. ‹⋀x y. ⟦((∀x. ord x x) ∧ (∀x y z. ord x y ⟶ ord y z ⟶ ord x z)) ∧ (∀x y. ord x y ⟶ ord y x ⟶ x = y) ∧ (∀A x. chain ord A ⟶ x ∈ A ⟶ ord x (lb A)) ∧ (∀A z. chain ord A ⟶ (∀x. x ∈ A ⟶ ord x z) ⟶ ord (lb A) z); ord x y; ord y x⟧ ⟹ x = y› 5. ‹⋀A x. ⟦((∀x. ord x x) ∧ (∀x y z. ord x y ⟶ ord y z ⟶ ord x z)) ∧ (∀x y. ord x y ⟶ ord y x ⟶ x = y) ∧ (∀A x. chain ord A ⟶ x ∈ A ⟶ ord x (lb A)) ∧ (∀A z. chain ord A ⟶ (∀x. x ∈ A ⟶ ord x z) ⟶ ord (lb A) z); chain ord A; x ∈ A⟧ ⟹ ord x (lb A)› 6. ‹⋀A z. ⟦((∀x. ord x x) ∧ (∀x y z. ord x y ⟶ ord y z ⟶ ord x z)) ∧ (∀x y. ord x y ⟶ ord y x ⟶ x = y) ∧ (∀A x. chain ord A ⟶ x ∈ A ⟶ ord x (lb A)) ∧ (∀A z. chain ord A ⟶ (∀x. x ∈ A ⟶ ord x z) ⟶ ord (lb A) z); chain ord A; ⋀x. x ∈ A ⟹ ord x z⟧ ⟹ ord (lb A) z› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*discuss goal 3*) apply blast (*discuss goal 4*) apply blast (*discuss goal 5*) apply blast (*discuss goal 6*) apply blast (*proven 6 subgoals*) . lemma partial_function_image: assumes "partial_function_definitions ord Lub" assumes inj: "⋀x y. f x = f y ⟹ x = y" assumes inv: "⋀x. f (g x) = x" shows "partial_function_definitions (img_ord f ord) (img_lub f g Lub)" proof (-) (*goal: ‹partial_function_definitions (img_ord f ord) (img_lub f g Lub)›*) let ?iord = "img_ord f ord" let ?ilub = "img_lub f g Lub" interpret partial_function_definitions ord Lub by fact show "?thesis" (*goal: ‹partial_function_definitions (img_ord f ord) (img_lub f g Lub)›*) proof (standard) (*goals: 1. ‹⋀x. img_ord f ord x x› 2. ‹⋀x y z. ⟦img_ord f ord x y; img_ord f ord y z⟧ ⟹ img_ord f ord x z› 3. ‹⋀x y. ⟦img_ord f ord x y; img_ord f ord y x⟧ ⟹ x = y› 4. ‹⋀A x. ⟦chain (img_ord f ord) A; x ∈ A⟧ ⟹ img_ord f ord x (img_lub f g Lub A)› 5. ‹⋀A z. ⟦chain (img_ord f ord) A; ⋀x. x ∈ A ⟹ img_ord f ord x z⟧ ⟹ img_ord f ord (img_lub f g Lub A) z›*) fix A and x assume "chain ?iord A" "x ∈ A" (*‹chain (img_ord (f::'b ⇒ 'a) (ord::'a ⇒ 'a ⇒ bool)) (A::'b set)› ‹(x::'b) ∈ (A::'b set)›*) then have "chain ord (f ` A)" "f x ∈ f ` A" apply - (*goals: 1. ‹⟦chain (img_ord f ord) A; x ∈ A⟧ ⟹ chain ord (f ` A)› 2. ‹⟦chain (img_ord f ord) A; x ∈ A⟧ ⟹ f x ∈ f ` A› discuss goal 1*) apply ((auto simp: img_ord_def (*‹img_ord ?f ?ord = (λx y. ?ord (?f x) (?f y))›*) intro: chainI (*‹(⋀x y. ⟦x ∈ ?S; y ∈ ?S⟧ ⟹ ?ord x y ∨ ?ord y x) ⟹ chain ?ord ?S›*) dest: chainD (*‹⟦chain ?ord ?S; ?x ∈ ?S; ?y ∈ ?S⟧ ⟹ ?ord ?x ?y ∨ ?ord ?y ?x›*))[1]) (*discuss goal 2*) apply ((auto simp: img_ord_def (*‹img_ord ?f ?ord = (λx y. ?ord (?f x) (?f y))›*) intro: chainI (*‹(⋀x y. ⟦x ∈ ?S; y ∈ ?S⟧ ⟹ ?ord x y ∨ ?ord y x) ⟹ chain ?ord ?S›*) dest: chainD (*‹⟦chain ?ord ?S; ?x ∈ ?S; ?y ∈ ?S⟧ ⟹ ?ord ?x ?y ∨ ?ord ?y ?x›*))[1]) (*proven 2 subgoals*) . thus "?iord x (?ilub A)" unfolding inv img_lub_def img_ord_def (*goal: ‹ord (f x) (Lub (f ` A))›*) by (rule lub_upper (*‹⟦chain ord ?A; ?x ∈ ?A⟧ ⟹ ord ?x (Lub ?A)›*)) next (*goals: 1. ‹⋀x. img_ord f ord x x› 2. ‹⋀x y z. ⟦img_ord f ord x y; img_ord f ord y z⟧ ⟹ img_ord f ord x z› 3. ‹⋀x y. ⟦img_ord f ord x y; img_ord f ord y x⟧ ⟹ x = y› 4. ‹⋀A z. ⟦chain (img_ord f ord) A; ⋀x. x ∈ A ⟹ img_ord f ord x z⟧ ⟹ img_ord f ord (img_lub f g Lub A) z›*) fix A and x assume "chain ?iord A" and 1: "⋀z. z ∈ A ⟹ ?iord z x" (*‹chain (img_ord (f::'b ⇒ 'a) (ord::'a ⇒ 'a ⇒ bool)) (A::'b set)› ‹(?z::'b) ∈ (A::'b set) ⟹ img_ord (f::'b ⇒ 'a) (ord::'a ⇒ 'a ⇒ bool) ?z (x::'b)›*) then have "chain ord (f ` A)" by (auto simp: img_ord_def (*‹img_ord (?f::?'a ⇒ ?'c) (?ord::?'c ⇒ ?'c ⇒ ?'b) = (λ(x::?'a) y::?'a. ?ord (?f x) (?f y))›*) intro: chainI (*‹(⋀(x::?'a) y::?'a. ⟦x ∈ (?S::?'a set); y ∈ ?S⟧ ⟹ (?ord::?'a ⇒ ?'a ⇒ bool) x y ∨ ?ord y x) ⟹ chain ?ord ?S›*) dest: chainD (*‹⟦chain (?ord::?'a ⇒ ?'a ⇒ bool) (?S::?'a set); (?x::?'a) ∈ ?S; (?y::?'a) ∈ ?S⟧ ⟹ ?ord ?x ?y ∨ ?ord ?y ?x›*)) thus "?iord (?ilub A) x" unfolding inv img_lub_def img_ord_def (*goal: ‹ord (Lub (f ` A)) (f x)›*) apply (rule lub_least (*‹⟦chain ord ?A; ⋀x. x ∈ ?A ⟹ ord x ?z⟧ ⟹ ord (Lub ?A) ?z›*)) (*goal: ‹(ord::'a::type ⇒ 'a::type ⇒ bool) ((Lub::'a::type set ⇒ 'a::type) ((f::'b::type ⇒ 'a::type) ` (A::'b::type set))) (f (x::'b::type))›*) by (auto dest: 1[unfolded img_ord_def] (*‹?z ∈ A ⟹ ord (f ?z) (f x)›*)) qed (auto simp: img_ord_def (*‹img_ord (?f::?'a::type ⇒ ?'c::type) (?ord::?'c::type ⇒ ?'c::type ⇒ ?'b::type) = (λ(x::?'a::type) y::?'a::type. ?ord (?f x) (?f y))›*) intro: leq_refl (*‹(ord::'a::type ⇒ 'a::type ⇒ bool) (?x::'a::type) ?x›*) dest: leq_trans (*‹⟦(ord::'a::type ⇒ 'a::type ⇒ bool) (?x::'a::type) (?y::'a::type); ord ?y (?z::'a::type)⟧ ⟹ ord ?x ?z›*) leq_antisym (*‹⟦(ord::'a::type ⇒ 'a::type ⇒ bool) (?x::'a::type) (?y::'a::type); ord ?y ?x⟧ ⟹ ?x = ?y›*) inj (*‹(f::'b::type ⇒ 'a::type) (?x::'b::type) = f (?y::'b::type) ⟹ ?x = ?y›*)) (*solves the remaining goals: 1. ‹⋀x. img_ord f ord x x› 2. ‹⋀x y z. ⟦img_ord f ord x y; img_ord f ord y z⟧ ⟹ img_ord f ord x z› 3. ‹⋀x y. ⟦img_ord f ord x y; img_ord f ord y x⟧ ⟹ x = y›*) qed context partial_function_definitions begin abbreviation "le_fun ≡ fun_ord leq" abbreviation "lub_fun ≡ fun_lub lub" abbreviation "fixp_fun ≡ ccpo.fixp lub_fun le_fun" abbreviation "mono_body ≡ monotone le_fun leq" abbreviation "admissible ≡ ccpo.admissible lub_fun le_fun" text ‹Interpret manually, to avoid flooding everything with facts about orders› lemma ccpo: "class.ccpo lub_fun le_fun (mk_less le_fun)" apply (rule ccpo (*‹partial_function_definitions (?ord::?'a ⇒ ?'a ⇒ bool) (?lb::?'a set ⇒ ?'a) ⟹ class.ccpo ?lb ?ord (mk_less ?ord)›*)) (*goal: ‹class.ccpo lub_fun le_fun (mk_less le_fun)›*) apply (rule partial_function_lift (*‹partial_function_definitions ?ord ?lb ⟹ partial_function_definitions (fun_ord ?ord) (fun_lub ?lb)›*)) (*goal: ‹partial_function_definitions le_fun lub_fun›*) by (rule partial_function_definitions_axioms (*‹partial_function_definitions leq lub›*)) text ‹The crucial fixed-point theorem› lemma mono_body_fixp: "(⋀x. mono_body (λf. F f x)) ⟹ fixp_fun F = F (fixp_fun F)" apply (rule ccpo.fixp_unfold[OF ccpo] (*‹monotone le_fun le_fun ?f ⟹ fixp_fun ?f = ?f (fixp_fun ?f)›*)) (*goal: ‹(⋀x. monotone le_fun leq (λf. F f x)) ⟹ fixp_fun F = F (fixp_fun F)›*) by (auto simp: monotone_def (*‹monotone (?orda::?'a ⇒ ?'a ⇒ bool) (?ordb::?'b ⇒ ?'b ⇒ bool) (?f::?'a ⇒ ?'b) = (∀(x::?'a) y::?'a. ?orda x y ⟶ ?ordb (?f x) (?f y))›*) fun_ord_def (*‹fun_ord (?ord::?'a ⇒ ?'b ⇒ bool) (?f::?'c ⇒ ?'a) (?g::?'c ⇒ ?'b) = (∀x::?'c. ?ord (?f x) (?g x))›*)) text ‹Version with curry/uncurry combinators, to be used by package› lemma fixp_rule_uc: fixes F :: "'c ⇒ 'c" and U :: "'c ⇒ 'b ⇒ 'a" and C :: "('b ⇒ 'a) ⇒ 'c" assumes mono: "⋀x. mono_body (λf. U (F (C f)) x)" assumes eq: "f ≡ C (fixp_fun (λf. U (F (C f))))" assumes inverse: "⋀f. C (U f) = f" shows "f = F f" proof (-) (*goal: ‹f = F f›*) have "f = C (fixp_fun (λf. U (F (C f))))" by (simp add: eq (*‹f ≡ C (fixp_fun (λf. U (F (C f))))›*)) also (*calculation: ‹f = C (fixp_fun (λf. U (F (C f))))›*) have "... = C (U (F (C (fixp_fun (λf. U (F (C f)))))))" apply (subst mono_body_fixp[of "%f. U (F (C f))", OF mono] (*‹fixp_fun (λf. U (F (C f))) = U (F (C (fixp_fun (λf. U (F (C f))))))›*)) (*goal: ‹C (fixp_fun (λf. U (F (C f)))) = C (U (F (C (fixp_fun (λf. U (F (C f)))))))›*) by (rule refl (*‹(?t::?'a) = ?t›*)) also (*calculation: ‹f = C (U (F (C (fixp_fun (λf. U (F (C f)))))))›*) have "... = F (C (fixp_fun (λf. U (F (C f)))))" by (rule inverse (*‹(C::('b ⇒ 'a) ⇒ 'c) ((U::'c ⇒ 'b ⇒ 'a) (?f5::'c)) = ?f5›*)) also (*calculation: ‹f = F (C (fixp_fun (λf. U (F (C f)))))›*) have "... = F f" by (simp add: eq (*‹f ≡ C (fixp_fun (λf. U (F (C f))))›*)) finally (*calculation: ‹(f::'c) = (F::'c ⇒ 'c) f›*) show "f = F f" . qed text ‹Fixpoint induction rule› lemma fixp_induct_uc: fixes F :: "'c ⇒ 'c" and U :: "'c ⇒ 'b ⇒ 'a" and C :: "('b ⇒ 'a) ⇒ 'c" and P :: "('b ⇒ 'a) ⇒ bool" assumes mono: "⋀x. mono_body (λf. U (F (C f)) x)" and eq: "f ≡ C (fixp_fun (λf. U (F (C f))))" and inverse: "⋀f. U (C f) = f" and adm: "ccpo.admissible lub_fun le_fun P" and bot: "P (λ_. lub {})" and step: "⋀f. P (U f) ⟹ P (U (F f))" shows "P (U f)" unfolding eq inverse (*goal: ‹P (fixp_fun (λf. U (F (C f))))›*) proof (rule ccpo.fixp_induct[OF ccpo adm] (*‹⟦monotone le_fun le_fun ?f; P (lub_fun {}); ⋀x. P x ⟹ P (?f x)⟧ ⟹ P (fixp_fun ?f)›*)) (*goals: 1. ‹monotone le_fun le_fun (λf::'b ⇒ 'a. (U::'c ⇒ 'b ⇒ 'a) ((F::'c ⇒ 'c) ((C::('b ⇒ 'a) ⇒ 'c) f)))› 2. ‹(P::('b ⇒ 'a) ⇒ bool) (lub_fun {})› 3. ‹⋀x::'b ⇒ 'a. (P::('b ⇒ 'a) ⇒ bool) x ⟹ P ((U::'c ⇒ 'b ⇒ 'a) ((F::'c ⇒ 'c) ((C::('b ⇒ 'a) ⇒ 'c) x)))›*) show "monotone le_fun le_fun (λf. U (F (C f)))" using mono (*‹monotone le_fun leq (λf. U (F (C f)) ?x5)›*) by (auto simp: monotone_def (*‹monotone ?orda ?ordb ?f = (∀x y. ?orda x y ⟶ ?ordb (?f x) (?f y))›*) fun_ord_def (*‹fun_ord ?ord ?f ?g = (∀x. ?ord (?f x) (?g x))›*)) next (*goals: 1. ‹(P::('b::type ⇒ 'a::type) ⇒ bool) (lub_fun {})› 2. ‹⋀x::'b::type ⇒ 'a::type. (P::('b::type ⇒ 'a::type) ⇒ bool) x ⟹ P ((U::'c::type ⇒ 'b::type ⇒ 'a::type) ((F::'c::type ⇒ 'c::type) ((C::('b::type ⇒ 'a::type) ⇒ 'c::type) x)))›*) show "P (lub_fun {})" by (auto simp: bot (*‹P (λ_. lub {})›*) fun_lub_def (*‹fun_lub ?L ?A = (λx. ?L {y. ∃f∈?A. y = f x})›*)) next (*goal: ‹⋀x. P x ⟹ P (U (F (C x)))›*) fix x assume "P x" (*‹(P::('b ⇒ 'a) ⇒ bool) (x::'b ⇒ 'a)›*) then show "P (U (F (C x)))" using step[of "C x"] (*‹(P::('b ⇒ 'a) ⇒ bool) ((U::'c ⇒ 'b ⇒ 'a) ((C::('b ⇒ 'a) ⇒ 'c) (x::'b ⇒ 'a))) ⟹ P (U ((F::'c ⇒ 'c) (C x)))›*) by (simp add: inverse (*‹U (C ?f5) = ?f5›*)) qed text ‹Rules for \<^term>‹mono_body›:› lemma const_mono[partial_function_mono]: "monotone ord leq (λf. c)" apply (rule monotoneI (*‹(⋀(x::?'a) y::?'a. (?orda::?'a ⇒ ?'a ⇒ bool) x y ⟹ (?ordb::?'b ⇒ ?'b ⇒ bool) ((?f::?'a ⇒ ?'b) x) (?f y)) ⟹ monotone ?orda ?ordb ?f›*)) (*goal: ‹monotone (ord::'b ⇒ 'b ⇒ bool) (leq::'a ⇒ 'a ⇒ bool) (λf::'b. c::'a)›*) by (rule leq_refl (*‹leq ?x ?x›*)) end subsection ‹Flat interpretation: tailrec and option› definition "flat_ord b x y ⟷ x = b ∨ x = y" definition "flat_lub b A = (if A ⊆ {b} then b else (THE x. x ∈ A - {b}))" lemma flat_interpretation: "partial_function_definitions (flat_ord b) (flat_lub b)" proof (standard) (*goals: 1. ‹⋀x. flat_ord b x x› 2. ‹⋀x y z. ⟦flat_ord b x y; flat_ord b y z⟧ ⟹ flat_ord b x z› 3. ‹⋀x y. ⟦flat_ord b x y; flat_ord b y x⟧ ⟹ x = y› 4. ‹⋀A x. ⟦chain (flat_ord b) A; x ∈ A⟧ ⟹ flat_ord b x (flat_lub b A)› 5. ‹⋀A z. ⟦chain (flat_ord b) A; ⋀x. x ∈ A ⟹ flat_ord b x z⟧ ⟹ flat_ord b (flat_lub b A) z›*) fix A and x assume 1: "chain (flat_ord b) A" "x ∈ A" (*‹chain (flat_ord (b::'a)) (A::'a set)› ‹(x::'a) ∈ (A::'a set)›*) show "flat_ord b x (flat_lub b A)" proof (cases) (*goals: 1. ‹?P ⟹ flat_ord b x (flat_lub b A)› 2. ‹¬ ?P ⟹ flat_ord b x (flat_lub b A)›*) assume "x = b" (*‹(x::'a) = (b::'a)›*) thus "?thesis" (*goal: ‹flat_ord b x (flat_lub b A)›*) by (simp add: flat_ord_def (*‹flat_ord ?b ?x ?y = (?x = ?b ∨ ?x = ?y)›*)) next (*goal: ‹x ≠ b ⟹ flat_ord b x (flat_lub b A)›*) assume "x ≠ b" (*‹(x::'a) ≠ (b::'a)›*) with "1" (*‹chain (flat_ord b) A› ‹x ∈ A›*) have "A - {b} = {x}" by (auto elim: chainE (*‹⟦chain ?ord ?S; ?x ∈ ?S; ?y ∈ ?S; ?ord ?x ?y ⟹ ?thesis; ?ord ?y ?x ⟹ ?thesis⟧ ⟹ ?thesis›*) simp: flat_ord_def (*‹flat_ord ?b ?x ?y = (?x = ?b ∨ ?x = ?y)›*)) then have "flat_lub b A = x" by (auto simp: flat_lub_def (*‹flat_lub ?b ?A = (if ?A ⊆ {?b} then ?b else THE x. x ∈ ?A - {?b})›*)) thus "?thesis" (*goal: ‹flat_ord (b::'a) (x::'a) (flat_lub b (A::'a set))›*) by (auto simp: flat_ord_def (*‹flat_ord ?b ?x ?y = (?x = ?b ∨ ?x = ?y)›*)) qed next (*goals: 1. ‹⋀x::'a. flat_ord (b::'a) x x› 2. ‹⋀(x::'a) (y::'a) z::'a. ⟦flat_ord (b::'a) x y; flat_ord b y z⟧ ⟹ flat_ord b x z› 3. ‹⋀(x::'a) y::'a. ⟦flat_ord (b::'a) x y; flat_ord b y x⟧ ⟹ x = y› 4. ‹⋀(A::'a set) z::'a. ⟦chain (flat_ord (b::'a)) A; ⋀x::'a. x ∈ A ⟹ flat_ord b x z⟧ ⟹ flat_ord b (flat_lub b A) z›*) fix A and z assume A: "chain (flat_ord b) A" and z: "⋀x. x ∈ A ⟹ flat_ord b x z" (*‹chain (flat_ord (b::'a)) (A::'a set)› ‹(?x::'a) ∈ (A::'a set) ⟹ flat_ord (b::'a) ?x (z::'a)›*) show "flat_ord b (flat_lub b A) z" proof (cases) (*goals: 1. ‹?P ⟹ flat_ord b (flat_lub b A) z› 2. ‹¬ ?P ⟹ flat_ord b (flat_lub b A) z›*) assume "A ⊆ {b}" (*‹(A::'a set) ⊆ {b::'a}›*) thus "?thesis" (*goal: ‹flat_ord b (flat_lub b A) z›*) by (auto simp: flat_lub_def (*‹flat_lub ?b ?A = (if ?A ⊆ {?b} then ?b else THE x. x ∈ ?A - {?b})›*) flat_ord_def (*‹flat_ord ?b ?x ?y = (?x = ?b ∨ ?x = ?y)›*)) next (*goal: ‹¬ A ⊆ {b} ⟹ flat_ord b (flat_lub b A) z›*) assume nb: "¬ A ⊆ {b}" (*‹¬ (A::'a set) ⊆ {b::'a}›*) then obtain y where y: "y ∈ A" "y ≠ b" (*goal: ‹(⋀y::'a. ⟦y ∈ (A::'a set); y ≠ (b::'a)⟧ ⟹ thesis::bool) ⟹ thesis›*) by auto with A (*‹chain (flat_ord b) A›*) have "A - {b} = {y}" by (auto elim: chainE (*‹⟦chain ?ord ?S; ?x ∈ ?S; ?y ∈ ?S; ?ord ?x ?y ⟹ ?thesis; ?ord ?y ?x ⟹ ?thesis⟧ ⟹ ?thesis›*) simp: flat_ord_def (*‹flat_ord ?b ?x ?y = (?x = ?b ∨ ?x = ?y)›*)) with nb (*‹¬ A ⊆ {b}›*) have "flat_lub b A = y" by (auto simp: flat_lub_def (*‹flat_lub (?b::?'a) (?A::?'a set) = (if ?A ⊆ {?b} then ?b else THE x::?'a. x ∈ ?A - {?b})›*)) with z (*‹?x ∈ A ⟹ flat_ord b ?x z›*) y (*‹y ∈ A› ‹y ≠ b›*) show "?thesis" (*goal: ‹flat_ord b (flat_lub b A) z›*) by auto qed qed (auto simp: flat_ord_def (*‹flat_ord (?b::?'a) (?x::?'a) (?y::?'a) = (?x = ?b ∨ ?x = ?y)›*)) (*solves the remaining goals: 1. ‹⋀x. flat_ord b x x› 2. ‹⋀x y z. ⟦flat_ord b x y; flat_ord b y z⟧ ⟹ flat_ord b x z› 3. ‹⋀x y. ⟦flat_ord b x y; flat_ord b y x⟧ ⟹ x = y›*) lemma flat_ordI: "(x ≠ a ⟹ x = y) ⟹ flat_ord a x y" by (auto simp add: flat_ord_def (*‹flat_ord ?b ?x ?y = (?x = ?b ∨ ?x = ?y)›*)) lemma flat_ord_antisym: "⟦ flat_ord a x y; flat_ord a y x ⟧ ⟹ x = y" by (auto simp add: flat_ord_def (*‹flat_ord ?b ?x ?y = (?x = ?b ∨ ?x = ?y)›*)) lemma antisymp_flat_ord: "antisymp (flat_ord a)" apply (rule antisympI (*‹(⋀x y. ⟦?R x y; ?R y x⟧ ⟹ x = y) ⟹ antisymp ?R›*)) (*goal: ‹antisymp (flat_ord a)›*) by (auto dest: flat_ord_antisym (*‹⟦flat_ord ?a ?x ?y; flat_ord ?a ?y ?x⟧ ⟹ ?x = ?y›*)) interpretation tailrec: partial_function_definitions "flat_ord undefined" "flat_lub undefined" rewrites "flat_lub undefined {} ≡ undefined" (*goals: 1. ‹partial_function_definitions (flat_ord undefined) (flat_lub undefined)› 2. ‹flat_lub undefined {} ≡ undefined› discuss goal 1*) apply (rule flat_interpretation (*‹partial_function_definitions (flat_ord ?b) (flat_lub ?b)›*)) (*discuss goal 2*) apply (simp add: flat_lub_def (*‹flat_lub (?b::?'a) (?A::?'a set) = (if ?A ⊆ {?b} then ?b else THE x::?'a. x ∈ ?A - {?b})›*)) (*proven 2 subgoals*) . interpretation option: partial_function_definitions "flat_ord None" "flat_lub None" rewrites "flat_lub None {} ≡ None" (*goals: 1. ‹partial_function_definitions (flat_ord None) (flat_lub None)› 2. ‹flat_lub None {} ≡ None› discuss goal 1*) apply (rule flat_interpretation (*‹partial_function_definitions (flat_ord ?b) (flat_lub ?b)›*)) (*discuss goal 2*) apply (simp add: flat_lub_def (*‹flat_lub ?b ?A = (if ?A ⊆ {?b} then ?b else THE x. x ∈ ?A - {?b})›*)) (*proven 2 subgoals*) . abbreviation "tailrec_ord ≡ flat_ord undefined" abbreviation "mono_tailrec ≡ monotone (fun_ord tailrec_ord) tailrec_ord" lemma tailrec_admissible: "ccpo.admissible (fun_lub (flat_lub c)) (fun_ord (flat_ord c)) (λa. ∀x. a x ≠ c ⟶ P x (a x))" proof (intro ccpo.admissibleI (*‹(⋀A. ⟦chain ?ord A; A ≠ {}; ∀x∈A. ?P x⟧ ⟹ ?P (?lub A)) ⟹ ccpo.admissible ?lub ?ord ?P›*) strip (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q› ‹(⋀x. ?P x) ⟹ ∀x. ?P x› ‹(⋀x. x ∈ ?A ⟹ ?P x) ⟹ ∀x∈?A. ?P x›*)) (*goal: ‹⋀A x. ⟦chain (fun_ord (flat_ord c)) A; A ≠ {}; ∀x∈A. ∀xa. x xa ≠ c ⟶ P xa (x xa); fun_lub (flat_lub c) A x ≠ c⟧ ⟹ P x (fun_lub (flat_lub c) A x)›*) fix A and x assume chain: "Complete_Partial_Order.chain (fun_ord (flat_ord c)) A" and P[rule_format]: "∀f∈A. ∀x. f x ≠ c ⟶ P x (f x)" and defined: "fun_lub (flat_lub c) A x ≠ c" (*‹chain (fun_ord (flat_ord (c::'b))) (A::('a ⇒ 'b) set)› ‹⟦(?f::'a ⇒ 'b) ∈ (A::('a ⇒ 'b) set); ?f (?x::'a) ≠ (c::'b)⟧ ⟹ (P::'a ⇒ 'b ⇒ bool) ?x (?f ?x)› ‹fun_lub (flat_lub (c::'b)) (A::('a ⇒ 'b) set) (x::'a) ≠ c›*) from defined (*‹fun_lub (flat_lub (c::'b::type)) (A::('a::type ⇒ 'b::type) set) (x::'a::type) ≠ c›*) obtain f where f: "f ∈ A" "f x ≠ c" (*goal: ‹(⋀f. ⟦f ∈ A; f x ≠ c⟧ ⟹ thesis) ⟹ thesis›*) by (auto simp add: fun_lub_def (*‹fun_lub ?L ?A = (λx. ?L {y. ∃f∈?A. y = f x})›*) flat_lub_def (*‹flat_lub ?b ?A = (if ?A ⊆ {?b} then ?b else THE x. x ∈ ?A - {?b})›*) split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) hence "P x (f x)" by (rule P (*‹⟦?f ∈ A; ?f ?x ≠ c⟧ ⟹ P ?x (?f ?x)›*)) moreover from chain (*‹chain (fun_ord (flat_ord c)) A›*) f (*‹f ∈ A› ‹f x ≠ c›*) have "∀f' ∈ A. f' x = c ∨ f' x = f x" by (auto 4 4 simp add: Complete_Partial_Order.chain_def (*‹chain ?ord ?S = (∀x∈?S. ∀y∈?S. ?ord x y ∨ ?ord y x)›*) flat_ord_def (*‹flat_ord ?b ?x ?y = (?x = ?b ∨ ?x = ?y)›*) fun_ord_def (*‹fun_ord ?ord ?f ?g = (∀x. ?ord (?f x) (?g x))›*)) hence "fun_lub (flat_lub c) A x = f x" using f (*‹f ∈ A› ‹f x ≠ c›*) by (auto simp add: fun_lub_def (*‹fun_lub (?L::?'c::type set ⇒ ?'b::type) (?A::(?'a::type ⇒ ?'c::type) set) = (λx::?'a::type. ?L {y::?'c::type. ∃f::?'a::type ⇒ ?'c::type∈?A. y = f x})›*) flat_lub_def (*‹flat_lub (?b::?'a::type) (?A::?'a::type set) = (if ?A ⊆ {?b} then ?b else THE x::?'a::type. x ∈ ?A - {?b})›*)) ultimately show "P x (fun_lub (flat_lub c) A x)" by simp qed lemma fixp_induct_tailrec: fixes F :: "'c ⇒ 'c" and U :: "'c ⇒ 'b ⇒ 'a" and C :: "('b ⇒ 'a) ⇒ 'c" and P :: "'b ⇒ 'a ⇒ bool" and x :: "'b" assumes mono: "⋀x. monotone (fun_ord (flat_ord c)) (flat_ord c) (λf. U (F (C f)) x)" assumes eq: "f ≡ C (ccpo.fixp (fun_lub (flat_lub c)) (fun_ord (flat_ord c)) (λf. U (F (C f))))" assumes inverse2: "⋀f. U (C f) = f" assumes step: "⋀f x y. (⋀x y. U f x = y ⟹ y ≠ c ⟹ P x y) ⟹ U (F f) x = y ⟹ y ≠ c ⟹ P x y" assumes result: "U f x = y" assumes defined: "y ≠ c" shows "P x y" proof (-) (*goal: ‹P x y›*) have "∀x y. U f x = y ⟶ y ≠ c ⟶ P x y" apply (rule partial_function_definitions.fixp_induct_uc[OF flat_interpretation, of _ U F C, OF mono eq inverse2] (*‹⟦ccpo.admissible (fun_lub (flat_lub c)) (fun_ord (flat_ord c)) ?P; ?P (λ_. flat_lub c {}); ⋀f. ?P (U f) ⟹ ?P (U (F f))⟧ ⟹ ?P (U f)›*)) (*goals: 1. ‹ccpo.admissible (fun_lub (flat_lub c)) (fun_ord (flat_ord c)) (λa. ∀x y. a x = y ⟶ y ≠ c ⟶ P x y)› 2. ‹∀x y. flat_lub c {} = y ⟶ y ≠ c ⟶ P x y› 3. ‹⋀f. ∀x y. U f x = y ⟶ y ≠ c ⟶ P x y ⟹ ∀x y. U (F f) x = y ⟶ y ≠ c ⟶ P x y› discuss goal 1*) apply ((auto intro: step (*‹⟦⋀x y. ⟦U ?f x = y; y ≠ c⟧ ⟹ P x y; U (F ?f) ?x = ?y; ?y ≠ c⟧ ⟹ P ?x ?y›*) tailrec_admissible (*‹ccpo.admissible (fun_lub (flat_lub ?c)) (fun_ord (flat_ord ?c)) (λa. ∀x. a x ≠ ?c ⟶ ?P x (a x))›*) simp add: fun_lub_def (*‹fun_lub ?L ?A = (λx. ?L {y. ∃f∈?A. y = f x})›*) flat_lub_def (*‹flat_lub ?b ?A = (if ?A ⊆ {?b} then ?b else THE x. x ∈ ?A - {?b})›*))[1]) (*discuss goal 2*) apply ((auto intro: step (*‹⟦⋀x y. ⟦U ?f x = y; y ≠ c⟧ ⟹ P x y; U (F ?f) ?x = ?y; ?y ≠ c⟧ ⟹ P ?x ?y›*) tailrec_admissible (*‹ccpo.admissible (fun_lub (flat_lub ?c)) (fun_ord (flat_ord ?c)) (λa. ∀x. a x ≠ ?c ⟶ ?P x (a x))›*) simp add: fun_lub_def (*‹fun_lub ?L ?A = (λx. ?L {y. ∃f∈?A. y = f x})›*) flat_lub_def (*‹flat_lub ?b ?A = (if ?A ⊆ {?b} then ?b else THE x. x ∈ ?A - {?b})›*))[1]) (*discuss goal 3*) apply ((auto intro: step (*‹⟦⋀x y. ⟦U ?f x = y; y ≠ c⟧ ⟹ P x y; U (F ?f) ?x = ?y; ?y ≠ c⟧ ⟹ P ?x ?y›*) tailrec_admissible (*‹ccpo.admissible (fun_lub (flat_lub ?c)) (fun_ord (flat_ord ?c)) (λa. ∀x. a x ≠ ?c ⟶ ?P x (a x))›*) simp add: fun_lub_def (*‹fun_lub ?L ?A = (λx. ?L {y. ∃f∈?A. y = f x})›*) flat_lub_def (*‹flat_lub ?b ?A = (if ?A ⊆ {?b} then ?b else THE x. x ∈ ?A - {?b})›*))[1]) (*proven 3 subgoals*) . thus "?thesis" (*goal: ‹P x y›*) using result (*‹U f x = y›*) defined (*‹(y::'a) ≠ (c::'a)›*) by blast qed lemma admissible_image: assumes pfun: "partial_function_definitions le lub" assumes adm: "ccpo.admissible lub le (P ∘ g)" assumes inj: "⋀x y. f x = f y ⟹ x = y" assumes inv: "⋀x. f (g x) = x" shows "ccpo.admissible (img_lub f g lub) (img_ord f le) P" proof (rule ccpo.admissibleI (*‹(⋀A::?'a::type set. ⟦chain (?ord::?'a::type ⇒ ?'a::type ⇒ bool) A; A ≠ {}; ∀x::?'a::type∈A. (?P::?'a::type ⇒ bool) x⟧ ⟹ ?P ((?lub::?'a::type set ⇒ ?'a::type) A)) ⟹ ccpo.admissible ?lub ?ord ?P›*)) (*goal: ‹⋀A. ⟦chain (img_ord f le) A; A ≠ {}; ∀x∈A. P x⟧ ⟹ P (img_lub f g lub A)›*) fix A assume "chain (img_ord f le) A" (*‹chain (img_ord (f::'b ⇒ 'a) (le::'a ⇒ 'a ⇒ bool)) (A::'b set)›*) then have ch': "chain le (f ` A)" by (auto simp: img_ord_def (*‹img_ord (?f::?'a ⇒ ?'c) (?ord::?'c ⇒ ?'c ⇒ ?'b) = (λ(x::?'a) y::?'a. ?ord (?f x) (?f y))›*) intro: chainI (*‹(⋀(x::?'a) y::?'a. ⟦x ∈ (?S::?'a set); y ∈ ?S⟧ ⟹ (?ord::?'a ⇒ ?'a ⇒ bool) x y ∨ ?ord y x) ⟹ chain ?ord ?S›*) dest: chainD (*‹⟦chain (?ord::?'a ⇒ ?'a ⇒ bool) (?S::?'a set); (?x::?'a) ∈ ?S; (?y::?'a) ∈ ?S⟧ ⟹ ?ord ?x ?y ∨ ?ord ?y ?x›*)) assume "A ≠ {}" (*‹(A::'b set) ≠ {}›*) assume P_A: "∀x∈A. P x" (*‹∀x::'b∈A::'b set. (P::'b ⇒ bool) x›*) have "(P ∘ g) (lub (f ` A))" using adm (*‹ccpo.admissible lub le (P ∘ g)›*) ch' (*‹chain le (f ` A)›*) proof (rule ccpo.admissibleD (*‹⟦ccpo.admissible (?lub::?'a::type set ⇒ ?'a::type) (?ord::?'a::type ⇒ ?'a::type ⇒ bool) (?P::?'a::type ⇒ bool); chain ?ord (?A::?'a::type set); ?A ≠ {}; ⋀x::?'a::type. x ∈ ?A ⟹ ?P x⟧ ⟹ ?P (?lub ?A)›*)) (*goals: 1. ‹f ` A ≠ {}› 2. ‹⋀x. x ∈ f ` A ⟹ (P ∘ g) x›*) fix x assume "x ∈ f ` A" (*‹(x::'a) ∈ (f::'b ⇒ 'a) ` (A::'b set)›*) with P_A (*‹∀x::'b∈A::'b set. (P::'b ⇒ bool) x›*) show "(P ∘ g) x" by (auto simp: inj[OF inv] (*‹g (f ?y) = ?y›*)) qed (simp add: ‹A ≠ {}›) (*solved the remaining goal: ‹f ` A ≠ {}›*) thus "P (img_lub f g lub A)" unfolding img_lub_def (*goal: ‹P (g (lub (f ` A)))›*) by simp qed lemma admissible_fun: assumes pfun: "partial_function_definitions le lub" assumes adm: "⋀x. ccpo.admissible lub le (Q x)" shows "ccpo.admissible (fun_lub lub) (fun_ord le) (λf. ∀x. Q x (f x))" proof (rule ccpo.admissibleI (*‹(⋀A. ⟦chain ?ord A; A ≠ {}; ∀x∈A. ?P x⟧ ⟹ ?P (?lub A)) ⟹ ccpo.admissible ?lub ?ord ?P›*)) (*goal: ‹⋀A. ⟦chain (fun_ord le) A; A ≠ {}; ∀x∈A. ∀xa. Q xa (x xa)⟧ ⟹ ∀x. Q x (fun_lub lub A x)›*) fix A :: "('b ⇒ 'a) set" assume Q: "∀f∈A. ∀x. Q x (f x)" (*‹∀f::'b ⇒ 'a∈A::('b ⇒ 'a) set. ∀x::'b. (Q::'b ⇒ 'a ⇒ bool) x (f x)›*) assume ch: "chain (fun_ord le) A" (*‹chain (fun_ord (le::'a ⇒ 'a ⇒ bool)) (A::('b ⇒ 'a) set)›*) assume "A ≠ {}" (*‹(A::('b ⇒ 'a) set) ≠ {}›*) hence non_empty: "⋀a. {y. ∃f∈A. y = f a} ≠ {}" by auto show "∀x. Q x (fun_lub lub A x)" unfolding fun_lub_def (*goal: ‹∀x. Q x (lub {y. ∃f∈A. y = f x})›*) apply (rule allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*)) (*goal: ‹∀x. Q x (lub {y. ∃f∈A. y = f x})›*) apply (rule ccpo.admissibleD[OF adm chain_fun[OF ch] non_empty] (*‹(⋀x::'a. x ∈ {y::'a. ∃f::'b ⇒ 'a∈A::('b ⇒ 'a) set. y = f (?a1::'b)} ⟹ (Q::'b ⇒ 'a ⇒ bool) (?x3::'b) x) ⟹ Q ?x3 ((lub::'a set ⇒ 'a) {y::'a. ∃f::'b ⇒ 'a∈A. y = f ?a1})›*)) (*goal: ‹⋀x. Q x (lub {y. ∃f∈A. y = f x})›*) by (auto simp: Q (*‹∀f∈A. ∀x. Q x (f x)›*)) qed abbreviation "option_ord ≡ flat_ord None" abbreviation "mono_option ≡ monotone (fun_ord option_ord) option_ord" lemma bind_mono[partial_function_mono]: assumes mf: "mono_option B" and mg: "⋀y. mono_option (λf. C y f)" shows "mono_option (λf. Option.bind (B f) (λy. C y f))" proof (rule monotoneI) fix f g :: "'a ⇒ 'b option" assume fg: "fun_ord option_ord f g" with mf have "option_ord (B f) (B g)" by (rule monotoneD[of _ _ _ f g]) then have "option_ord (Option.bind (B f) (λy. C y f)) (Option.bind (B g) (λy. C y f))" unfolding flat_ord_def by auto also from mg have "⋀y'. option_ord (C y' f) (C y' g)" by (rule monotoneD) (rule fg) then have "option_ord (Option.bind (B g) (λy'. C y' f)) (Option.bind (B g) (λy'. C y' g))" unfolding flat_ord_def by (cases "B g") auto finally (option.leq_trans) show "option_ord (Option.bind (B f) (λy. C y f)) (Option.bind (B g) (λy'. C y' g))" . qed lemma flat_lub_in_chain: assumes ch: "chain (flat_ord b) A " assumes lub: "flat_lub b A = a" shows "a = b ∨ a ∈ A" proof (cases "A ⊆ {b}") (*goals: 1. ‹A ⊆ {b} ⟹ a = b ∨ a ∈ A› 2. ‹¬ A ⊆ {b} ⟹ a = b ∨ a ∈ A›*) case True (*‹A ⊆ {b}›*) then have "flat_lub b A = b" unfolding flat_lub_def (*goal: ‹(if A ⊆ {b} then b else THE x. x ∈ A - {b}) = b›*) by simp with lub (*‹flat_lub b A = a›*) show "?thesis" (*goal: ‹a = b ∨ a ∈ A›*) by simp next (*goal: ‹¬ A ⊆ {b} ⟹ a = b ∨ a ∈ A›*) case False (*‹¬ A ⊆ {b}›*) then obtain c where "c ∈ A" and "c ≠ b" (*goal: ‹(⋀c. ⟦c ∈ A; c ≠ b⟧ ⟹ thesis) ⟹ thesis›*) by auto { fix z assume "z ∈ A" (*‹(z::'a) ∈ (A::'a set)›*) from chainD[OF ch ‹c ∈ A› this] (*‹flat_ord b c z ∨ flat_ord b z c›*) have "z = c ∨ z = b" unfolding flat_ord_def (*goal: ‹z = c ∨ z = b›*) using ‹c ≠ b› (*‹c ≠ b›*) by auto } with False (*‹¬ A ⊆ {b}›*) have "A - {b} = {c}" by auto with False (*‹¬ A ⊆ {b}›*) have "flat_lub b A = c" by (auto simp: flat_lub_def (*‹flat_lub ?b ?A = (if ?A ⊆ {?b} then ?b else THE x. x ∈ ?A - {?b})›*)) with ‹c ∈ A› (*‹(c::'a::type) ∈ (A::'a::type set)›*) lub (*‹flat_lub b A = a›*) show "?thesis" (*goal: ‹a = b ∨ a ∈ A›*) by simp qed lemma option_admissible: "option.admissible (%(f::'a ⇒ 'b option). (∀x y. f x = Some y ⟶ P x y))" proof (rule ccpo.admissibleI (*‹(⋀A. ⟦chain ?ord A; A ≠ {}; ∀x∈A. ?P x⟧ ⟹ ?P (?lub A)) ⟹ ccpo.admissible ?lub ?ord ?P›*)) (*goal: ‹⋀A::('a ⇒ 'b option) set. ⟦chain option.le_fun A; A ≠ {}; ∀x::'a ⇒ 'b option∈A. ∀(xa::'a) y::'b. x xa = Some y ⟶ (P::'a ⇒ 'b ⇒ bool) xa y⟧ ⟹ ∀(x::'a) y::'b. option.lub_fun A x = Some y ⟶ P x y›*) fix A :: "('a ⇒ 'b option) set" assume ch: "chain option.le_fun A" and IH: "∀f∈A. ∀x y. f x = Some y ⟶ P x y" (*‹chain option.le_fun (A::('a ⇒ 'b option) set)› ‹∀f::'a ⇒ 'b option∈A::('a ⇒ 'b option) set. ∀(x::'a) y::'b. f x = Some y ⟶ (P::'a ⇒ 'b ⇒ bool) x y›*) from ch (*‹chain option.le_fun A›*) have ch': "⋀x. chain option_ord {y. ∃f∈A. y = f x}" by (rule chain_fun (*‹chain (fun_ord ?ord) ?A ⟹ chain ?ord {y. ∃f∈?A. y = f ?a}›*)) show "∀x y. option.lub_fun A x = Some y ⟶ P x y" proof (intro allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*) impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goal: ‹⋀x y. option.lub_fun A x = Some y ⟹ P x y›*) fix x and y assume "option.lub_fun A x = Some y" (*‹option.lub_fun (A::('a ⇒ 'b option) set) (x::'a) = Some (y::'b)›*) from flat_lub_in_chain[OF ch' this [ unfolded fun_lub_def ]] (*‹Some y = None ∨ Some y ∈ {y. ∃f∈A. y = f x}›*) have "Some y ∈ {y. ∃f∈A. y = f x}" by simp then have "∃f∈A. f x = Some y" by auto with IH (*‹∀f∈A. ∀x y. f x = Some y ⟶ P x y›*) show "P x y" by auto qed qed lemma fixp_induct_option: fixes F :: "'c ⇒ 'c" and U :: "'c ⇒ 'b ⇒ 'a option" and C :: "('b ⇒ 'a option) ⇒ 'c" and P :: "'b ⇒ 'a ⇒ bool" assumes mono: "⋀x. mono_option (λf. U (F (C f)) x)" assumes eq: "f ≡ C (ccpo.fixp (fun_lub (flat_lub None)) (fun_ord option_ord) (λf. U (F (C f))))" assumes inverse2: "⋀f. U (C f) = f" assumes step: "⋀f x y. (⋀x y. U f x = Some y ⟹ P x y) ⟹ U (F f) x = Some y ⟹ P x y" assumes defined: "U f x = Some y" shows "P x y" using step (*‹⟦⋀x y. U ?f x = Some y ⟹ P x y; U (F ?f) ?x = Some ?y⟧ ⟹ P ?x ?y›*) defined (*‹U f x = Some y›*) option.fixp_induct_uc[of U F C, OF mono eq inverse2 option_admissible] (*‹⟦∀x y. None = Some y ⟶ ?P1 x y; ⋀f. ∀x y. U f x = Some y ⟶ ?P1 x y ⟹ ∀x y. U (F f) x = Some y ⟶ ?P1 x y⟧ ⟹ ∀x y. U f x = Some y ⟶ ?P1 x y›*) unfolding fun_lub_def flat_lub_def (*goal: ‹P x y›*) by (auto 9 2) declaration ‹Partial_Function.init "tailrec" \<^term>‹tailrec.fixp_fun› \<^term>‹tailrec.mono_body› @{thm tailrec.fixp_rule_uc} @{thm tailrec.fixp_induct_uc} (SOME @{thm fixp_induct_tailrec[where c = undefined]})› declaration ‹Partial_Function.init "option" \<^term>‹option.fixp_fun› \<^term>‹option.mono_body› @{thm option.fixp_rule_uc} @{thm option.fixp_induct_uc} (SOME @{thm fixp_induct_option})› hide_const (open) chain end
{ "path": "Isabelle2024/src/HOL/Partial_Function.thy", "repo": "Isabelle2024", "sha": "43cc017289a69f030ac623bb2ebfc5ef62c1bd936fd8f2cea7d9b1ecabf44701" }
(* Title: Sturm-Tarski Theorem Author: Wenda Li <wl302@cam.ac.uk / liwenda1990@hotmail.com> *) section "Sturm--Tarski Theorem" theory Sturm_Tarski imports Complex_Main PolyMisc "HOL-Computational_Algebra.Field_as_Ring" begin subsection‹Misc› lemma eventually_at_right: fixes x::"'a::{archimedean_field,linorder_topology}" shows "eventually P (at_right x) ⟷ (∃b>x. ∀y>x. y < b ⟶ P y)" proof (-) (*goal: ‹eventually (P::'a::{archimedean_field,linorder_topology} ⇒ bool) (at_right (x::'a::{archimedean_field,linorder_topology})) = (∃b>x. ∀y>x. y < b ⟶ P y)›*) obtain y where "y>x" (*goal: ‹(⋀y. x < y ⟹ thesis) ⟹ thesis›*) using ex_less_of_int (*‹∃z. ?x < of_int z›*) by auto thus "?thesis" (*goal: ‹eventually P (at_right x) = (∃b>x. ∀y>x. y < b ⟶ P y)›*) using eventually_at_right[OF ‹y>x›] (*‹eventually (?P::'a ⇒ bool) (at_right (x::'a)) = (∃b>x. ∀y>x. y < b ⟶ ?P y)›*) by auto qed lemma eventually_at_left: fixes x::"'a::{archimedean_field,linorder_topology}" shows "eventually P (at_left x) ⟷ (∃b<x. ∀y>b. y < x ⟶ P y)" proof (-) (*goal: ‹eventually (P::'a ⇒ bool) (at_left (x::'a)) = (∃b<x. ∀y>b. y < x ⟶ P y)›*) obtain y where "y<x" (*goal: ‹(⋀y::'a. y < (x::'a) ⟹ thesis::bool) ⟹ thesis›*) using linordered_field_no_lb (*‹∀x. ∃y. y < x›*) by auto thus "?thesis" (*goal: ‹eventually P (at_left x) = (∃b<x. ∀y>b. y < x ⟶ P y)›*) using eventually_at_left[OF ‹y<x›] (*‹eventually ?P (at_left x) = (∃b<x. ∀y>b. y < x ⟶ ?P y)›*) by auto qed lemma eventually_neg: assumes "F≠bot" and eve:"eventually (λx. P x) F" shows "¬ eventually (λx. ¬ P x) F" proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹¬ ¬ (∀⇩F x in F. ¬ P x) ⟹ False›*) assume "¬ ¬ eventually (λx. ¬ P x) F" (*‹¬ ¬ (∀⇩F x::'a in F::'a filter. ¬ (P::'a ⇒ bool) x)›*) hence "eventually (λx. ¬ P x) F" by auto hence "eventually (λx. False) F" using eventually_conj[OF eve, of "(λx. ¬ P x)"] (*‹∀⇩F x in F. ¬ P x ⟹ ∀⇩F x in F. P x ∧ ¬ P x›*) by auto thus False using ‹F≠bot› (*‹(F::'a::type filter) ≠ bot›*) eventually_False (*‹(∀⇩F x in ?F. False) = (?F = bot)›*) by auto qed lemma poly_tendsto[simp]: "(poly p ⤏ poly p x) (at (x::real))" "(poly p ⤏ poly p x) (at_left (x::real))" "(poly p ⤏ poly p x) (at_right (x::real))" using isCont_def[where f = "poly p"] (*‹isCont (poly p) ?a = poly p ─?a→ poly p ?a›*) apply - (*goals: 1. ‹(⋀a. isCont (poly p) a = poly p ─a→ poly p a) ⟹ poly p ─x→ poly p x› 2. ‹(⋀a. isCont (poly p) a = poly p ─a→ poly p a) ⟹ (poly p ⤏ poly p x) (at_left x)› 3. ‹(⋀a. isCont (poly p) a = poly p ─a→ poly p a) ⟹ (poly p ⤏ poly p x) (at_right x)› discuss goal 1*) apply ((auto simp add:filterlim_at_split (*‹filterlim ?f ?F (at ?x) = (filterlim ?f ?F (at_left ?x) ∧ filterlim ?f ?F (at_right ?x))›*))[1]) (*discuss goal 2*) apply ((auto simp add:filterlim_at_split (*‹filterlim ?f ?F (at ?x) = (filterlim ?f ?F (at_left ?x) ∧ filterlim ?f ?F (at_right ?x))›*))[1]) (*discuss goal 3*) apply ((auto simp add:filterlim_at_split (*‹filterlim ?f ?F (at ?x) = (filterlim ?f ?F (at_left ?x) ∧ filterlim ?f ?F (at_right ?x))›*))[1]) (*proven 3 subgoals*) . lemma not_eq_pos_or_neg_iff_1: fixes p::"real poly" shows "(∀z. lb<z∧z≤ub⟶poly p z≠0) ⟷ (∀z. lb<z∧z≤ub⟶poly p z>0)∨(∀z. lb<z∧z≤ub⟶poly p z<0)" (is "?Q ⟷ ?P") proof (rule, rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goals: 1. ‹⟦∀z. lb < z ∧ z ≤ ub ⟶ poly p z ≠ 0; ¬ ((∀z. lb < z ∧ z ≤ ub ⟶ 0 < poly p z) ∨ (∀z. lb < z ∧ z ≤ ub ⟶ poly p z < 0))⟧ ⟹ False› 2. ‹(∀z. lb < z ∧ z ≤ ub ⟶ 0 < poly p z) ∨ (∀z. lb < z ∧ z ≤ ub ⟶ poly p z < 0) ⟹ ∀z. lb < z ∧ z ≤ ub ⟶ poly p z ≠ 0›*) assume "?Q" "¬?P" (*‹∀z::real. (lb::real) < z ∧ z ≤ (ub::real) ⟶ poly (p::real poly) z ≠ (0::real)› ‹¬ ((∀z::real. (lb::real) < z ∧ z ≤ (ub::real) ⟶ (0::real) < poly (p::real poly) z) ∨ (∀z::real. lb < z ∧ z ≤ ub ⟶ poly p z < (0::real)))›*) then obtain z1 and z2 where z1: "lb<z1" "z1≤ub" "poly p z1≤0" and z2: "lb<z2" "z2≤ub" "poly p z2≥0" (*goal: ‹(⋀z1 z2. ⟦lb < z1; z1 ≤ ub; poly p z1 ≤ 0; lb < z2; z2 ≤ ub; 0 ≤ poly p z2⟧ ⟹ thesis) ⟹ thesis›*) by auto hence "∃z. lb<z∧z≤ub∧poly p z=0" proof (cases "poly p z1 = 0 ∨ poly p z2 =0 ∨ z1=z2") (*goals: 1. ‹⟦lb < z1; z1 ≤ ub; poly p z1 ≤ 0; lb < z2; z2 ≤ ub; 0 ≤ poly p z2; poly p z1 = 0 ∨ poly p z2 = 0 ∨ z1 = z2⟧ ⟹ ∃z>lb. z ≤ ub ∧ poly p z = 0› 2. ‹⟦lb < z1; z1 ≤ ub; poly p z1 ≤ 0; lb < z2; z2 ≤ ub; 0 ≤ poly p z2; ¬ (poly p z1 = 0 ∨ poly p z2 = 0 ∨ z1 = z2)⟧ ⟹ ∃z>lb. z ≤ ub ∧ poly p z = 0›*) case True (*‹poly p z1 = 0 ∨ poly p z2 = 0 ∨ z1 = z2›*) thus "?thesis" (*goal: ‹∃z>lb. z ≤ ub ∧ poly p z = 0›*) using z1 (*‹lb < z1› ‹(z1::real) ≤ (ub::real)› ‹poly p z1 ≤ 0›*) z2 (*‹lb < z2› ‹z2 ≤ ub› ‹0 ≤ poly p z2›*) by auto next (*goal: ‹⟦(lb::real) < (z1::real); z1 ≤ (ub::real); poly (p::real poly) z1 ≤ (0::real); lb < (z2::real); z2 ≤ ub; (0::real) ≤ poly p z2; ¬ (poly p z1 = (0::real) ∨ poly p z2 = (0::real) ∨ z1 = z2)⟧ ⟹ ∃z>lb. z ≤ ub ∧ poly p z = (0::real)›*) case False (*‹¬ (poly (p::real poly) (z1::real) = (0::real) ∨ poly p (z2::real) = (0::real) ∨ z1 = z2)›*) hence "poly p z1<0" and "poly p z2>0" and "z1≠z2" using z1(3) (*‹poly p z1 ≤ 0›*) z2(3) (*‹0 ≤ poly p z2›*) apply - (*goals: 1. ‹⟦¬ (poly p z1 = 0 ∨ poly p z2 = 0 ∨ z1 = z2); poly p z1 ≤ 0; 0 ≤ poly p z2⟧ ⟹ poly p z1 < 0› 2. ‹⟦¬ (poly p z1 = 0 ∨ poly p z2 = 0 ∨ z1 = z2); poly p z1 ≤ 0; 0 ≤ poly p z2⟧ ⟹ 0 < poly p z2› 3. ‹⟦¬ (poly p z1 = 0 ∨ poly p z2 = 0 ∨ z1 = z2); poly p z1 ≤ 0; 0 ≤ poly p z2⟧ ⟹ z1 ≠ z2› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . hence "(∃z>z1. z < z2 ∧ poly p z = 0) ∨ (∃z>z2. z < z1 ∧ poly p z = 0)" using poly_IVT_neg (*‹⟦?a < ?b; 0 < poly ?p ?a; poly ?p ?b < 0⟧ ⟹ ∃x>?a. x < ?b ∧ poly ?p x = 0›*) poly_IVT_pos (*‹⟦?a < ?b; poly ?p ?a < 0; 0 < poly ?p ?b⟧ ⟹ ∃x>?a. x < ?b ∧ poly ?p x = 0›*) apply (subst (asm) linorder_class.neq_iff (*‹(?x ≠ ?y) = (?x < ?y ∨ ?y < ?x)›*)) (*goal: ‹(∃z>z1::real. z < (z2::real) ∧ poly (p::real poly) z = (0::real)) ∨ (∃z>z2. z < z1 ∧ poly p z = (0::real))›*) by auto thus "?thesis" (*goal: ‹∃z>lb. z ≤ ub ∧ poly p z = 0›*) using z1(1,2) (*‹lb < z1› ‹z1 ≤ ub›*) z2(1,2) (*‹lb < z2› ‹z2 ≤ ub›*) by (metis less_eq_real_def (*‹(?x ≤ ?y) = (?x < ?y ∨ ?x = ?y)›*) order.strict_trans2 (*‹⟦?a < ?b; ?b ≤ ?c⟧ ⟹ ?a < ?c›*)) qed thus False using ‹?Q› (*‹∀z. lb < z ∧ z ≤ ub ⟶ poly p z ≠ 0›*) by auto next (*goal: ‹(∀z. lb < z ∧ z ≤ ub ⟶ 0 < poly p z) ∨ (∀z. lb < z ∧ z ≤ ub ⟶ poly p z < 0) ⟹ ∀z. lb < z ∧ z ≤ ub ⟶ poly p z ≠ 0›*) assume "?P" (*‹(∀z::real. (lb::real) < z ∧ z ≤ (ub::real) ⟶ (0::real) < poly (p::real poly) z) ∨ (∀z::real. lb < z ∧ z ≤ ub ⟶ poly p z < (0::real))›*) thus "?Q" by auto qed lemma not_eq_pos_or_neg_iff_2: fixes p::"real poly" shows "(∀z. lb≤z∧z<ub⟶poly p z≠0) ⟷(∀z. lb≤z∧z<ub⟶poly p z>0)∨(∀z. lb≤z∧z<ub⟶poly p z<0)" (is "?Q⟷?P") proof (rule, rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goals: 1. ‹⟦∀z. lb ≤ z ∧ z < ub ⟶ poly p z ≠ 0; ¬ ((∀z. lb ≤ z ∧ z < ub ⟶ 0 < poly p z) ∨ (∀z. lb ≤ z ∧ z < ub ⟶ poly p z < 0))⟧ ⟹ False› 2. ‹(∀z. lb ≤ z ∧ z < ub ⟶ 0 < poly p z) ∨ (∀z. lb ≤ z ∧ z < ub ⟶ poly p z < 0) ⟹ ∀z. lb ≤ z ∧ z < ub ⟶ poly p z ≠ 0›*) assume "?Q" "¬?P" (*‹∀z::real. (lb::real) ≤ z ∧ z < (ub::real) ⟶ poly (p::real poly) z ≠ (0::real)› ‹¬ ((∀z::real. (lb::real) ≤ z ∧ z < (ub::real) ⟶ (0::real) < poly (p::real poly) z) ∨ (∀z::real. lb ≤ z ∧ z < ub ⟶ poly p z < (0::real)))›*) then obtain z1 and z2 where z1: "lb≤z1" "z1<ub" "poly p z1≤0" and z2: "lb≤z2" "z2<ub" "poly p z2≥0" (*goal: ‹(⋀z1 z2. ⟦lb ≤ z1; z1 < ub; poly p z1 ≤ 0; lb ≤ z2; z2 < ub; 0 ≤ poly p z2⟧ ⟹ thesis) ⟹ thesis›*) by auto hence "∃z. lb≤z∧z<ub∧poly p z=0" proof (cases "poly p z1 = 0 ∨ poly p z2 =0 ∨ z1=z2") (*goals: 1. ‹⟦lb ≤ z1; z1 < ub; poly p z1 ≤ 0; lb ≤ z2; z2 < ub; 0 ≤ poly p z2; poly p z1 = 0 ∨ poly p z2 = 0 ∨ z1 = z2⟧ ⟹ ∃z≥lb. z < ub ∧ poly p z = 0› 2. ‹⟦lb ≤ z1; z1 < ub; poly p z1 ≤ 0; lb ≤ z2; z2 < ub; 0 ≤ poly p z2; ¬ (poly p z1 = 0 ∨ poly p z2 = 0 ∨ z1 = z2)⟧ ⟹ ∃z≥lb. z < ub ∧ poly p z = 0›*) case True (*‹poly p z1 = 0 ∨ poly p z2 = 0 ∨ z1 = z2›*) thus "?thesis" (*goal: ‹∃z≥lb. z < ub ∧ poly p z = 0›*) using z1 (*‹lb ≤ z1› ‹z1 < ub› ‹poly (p::real poly) (z1::real) ≤ (0::real)›*) z2 (*‹lb ≤ z2› ‹z2 < ub› ‹0 ≤ poly p z2›*) by auto next (*goal: ‹⟦lb ≤ z1; z1 < ub; poly p z1 ≤ 0; lb ≤ z2; z2 < ub; 0 ≤ poly p z2; ¬ (poly p z1 = 0 ∨ poly p z2 = 0 ∨ z1 = z2)⟧ ⟹ ∃z≥lb. z < ub ∧ poly p z = 0›*) case False (*‹¬ (poly p z1 = 0 ∨ poly p z2 = 0 ∨ z1 = z2)›*) hence "poly p z1<0" and "poly p z2>0" and "z1≠z2" using z1(3) (*‹poly p z1 ≤ 0›*) z2(3) (*‹0 ≤ poly p z2›*) apply - (*goals: 1. ‹⟦¬ (poly p z1 = 0 ∨ poly p z2 = 0 ∨ z1 = z2); poly p z1 ≤ 0; 0 ≤ poly p z2⟧ ⟹ poly p z1 < 0› 2. ‹⟦¬ (poly p z1 = 0 ∨ poly p z2 = 0 ∨ z1 = z2); poly p z1 ≤ 0; 0 ≤ poly p z2⟧ ⟹ 0 < poly p z2› 3. ‹⟦¬ (poly p z1 = 0 ∨ poly p z2 = 0 ∨ z1 = z2); poly p z1 ≤ 0; 0 ≤ poly p z2⟧ ⟹ z1 ≠ z2› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . hence "(∃z>z1. z < z2 ∧ poly p z = 0) ∨ (∃z>z2. z < z1 ∧ poly p z = 0)" using poly_IVT_neg (*‹⟦?a < ?b; 0 < poly ?p ?a; poly ?p ?b < 0⟧ ⟹ ∃x>?a. x < ?b ∧ poly ?p x = 0›*) poly_IVT_pos (*‹⟦?a < ?b; poly ?p ?a < 0; 0 < poly ?p ?b⟧ ⟹ ∃x>?a. x < ?b ∧ poly ?p x = 0›*) apply (subst (asm) linorder_class.neq_iff (*‹((?x::?'a) ≠ (?y::?'a)) = (?x < ?y ∨ ?y < ?x)›*)) (*goal: ‹(∃z>z1. z < z2 ∧ poly p z = 0) ∨ (∃z>z2. z < z1 ∧ poly p z = 0)›*) by auto thus "?thesis" (*goal: ‹∃z≥lb. z < ub ∧ poly p z = 0›*) using z1(1,2) (*‹lb ≤ z1› ‹z1 < ub›*) z2(1,2) (*‹lb ≤ z2› ‹z2 < ub›*) by (meson dual_order.strict_trans (*‹⟦?b < ?a; ?c < ?b⟧ ⟹ ?c < ?a›*) not_le (*‹(¬ ?x ≤ ?y) = (?y < ?x)›*)) qed thus False using ‹?Q› (*‹∀z. lb ≤ z ∧ z < ub ⟶ poly p z ≠ 0›*) by auto next (*goal: ‹(∀z. lb ≤ z ∧ z < ub ⟶ 0 < poly p z) ∨ (∀z. lb ≤ z ∧ z < ub ⟶ poly p z < 0) ⟹ ∀z. lb ≤ z ∧ z < ub ⟶ poly p z ≠ 0›*) assume "?P" (*‹(∀z::real. (lb::real) ≤ z ∧ z < (ub::real) ⟶ (0::real) < poly (p::real poly) z) ∨ (∀z::real. lb ≤ z ∧ z < ub ⟶ poly p z < (0::real))›*) thus "?Q" by auto qed lemma next_non_root_interval: fixes p::"real poly" assumes "p≠0" obtains ub where "ub>lb" and "(∀z. lb<z∧z≤ub⟶poly p z≠0)" proof (cases "(∃ r. poly p r=0 ∧ r>lb)") (*goals: 1. ‹⟦⋀ub::real. ⟦(lb::real) < ub; ∀z::real. lb < z ∧ z ≤ ub ⟶ poly (p::real poly) z ≠ (0::real)⟧ ⟹ thesis::bool; ∃r::real. poly p r = (0::real) ∧ lb < r⟧ ⟹ thesis› 2. ‹⟦⋀ub::real. ⟦(lb::real) < ub; ∀z::real. lb < z ∧ z ≤ ub ⟶ poly (p::real poly) z ≠ (0::real)⟧ ⟹ thesis::bool; ∄r::real. poly p r = (0::real) ∧ lb < r⟧ ⟹ thesis›*) case False (*‹∄r. poly p r = 0 ∧ lb < r›*) thus "?thesis" (*goal: ‹thesis::bool›*) apply (intro that[of "lb+1"] (*‹⟦lb < lb + 1; ∀z. lb < z ∧ z ≤ lb + 1 ⟶ poly p z ≠ 0⟧ ⟹ thesis›*)) (*goals: 1. ‹∄r. poly p r = 0 ∧ lb < r ⟹ lb < lb + 1› 2. ‹∄r. poly p r = 0 ∧ lb < r ⟹ ∀z. lb < z ∧ z ≤ lb + 1 ⟶ poly p z ≠ 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . next (*goal: ‹⟦⋀ub. ⟦lb < ub; ∀z. lb < z ∧ z ≤ ub ⟶ poly p z ≠ 0⟧ ⟹ thesis; ∃r. poly p r = 0 ∧ lb < r⟧ ⟹ thesis›*) case True (*‹∃r. poly p r = 0 ∧ lb < r›*) define lr where "lr≡Min {r . poly p r=0 ∧ r>lb}" have "∀z. lb<z∧z<lr⟶poly p z≠0" and "lr>lb" using True (*‹∃r. poly p r = 0 ∧ lb < r›*) lr_def (*‹lr::real ≡ Min {r::real. poly (p::real poly) r = (0::real) ∧ (lb::real) < r}›*) poly_roots_finite[OF ‹p≠0›] (*‹finite {x::real. poly (p::real poly) x = (0::real)}›*) apply - (*goals: 1. ‹⟦∃r. poly p r = 0 ∧ lb < r; lr ≡ Min {r. poly p r = 0 ∧ lb < r}; finite {x. poly p x = 0}⟧ ⟹ ∀z. lb < z ∧ z < lr ⟶ poly p z ≠ 0› 2. ‹⟦∃r. poly p r = 0 ∧ lb < r; lr ≡ Min {r. poly p r = 0 ∧ lb < r}; finite {x. poly p x = 0}⟧ ⟹ lb < lr› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . thus "?thesis" (*goal: ‹thesis::bool›*) using that[of "(lb+lr)/2"] (*‹⟦lb < (lb + lr) / 2; ∀z. lb < z ∧ z ≤ (lb + lr) / 2 ⟶ poly p z ≠ 0⟧ ⟹ thesis›*) by auto qed lemma last_non_root_interval: fixes p::"real poly" assumes "p≠0" obtains lb where "lb<ub" and "(∀z. lb≤z∧z<ub⟶poly p z≠0)" proof (cases "(∃ r. poly p r=0 ∧ r<ub)") (*goals: 1. ‹⟦⋀lb. ⟦lb < ub; ∀z. lb ≤ z ∧ z < ub ⟶ poly p z ≠ 0⟧ ⟹ thesis; ∃r. poly p r = 0 ∧ r < ub⟧ ⟹ thesis› 2. ‹⟦⋀lb. ⟦lb < ub; ∀z. lb ≤ z ∧ z < ub ⟶ poly p z ≠ 0⟧ ⟹ thesis; ∄r. poly p r = 0 ∧ r < ub⟧ ⟹ thesis›*) case False (*‹∄r. poly p r = 0 ∧ r < ub›*) thus "?thesis" (*goal: ‹thesis›*) apply (intro that[of "ub - 1"] (*‹⟦ub - 1 < ub; ∀z. ub - 1 ≤ z ∧ z < ub ⟶ poly p z ≠ 0⟧ ⟹ thesis›*)) (*goals: 1. ‹∄r. poly p r = 0 ∧ r < ub ⟹ ub - 1 < ub› 2. ‹∄r. poly p r = 0 ∧ r < ub ⟹ ∀z. ub - 1 ≤ z ∧ z < ub ⟶ poly p z ≠ 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . next (*goal: ‹⟦⋀lb. ⟦lb < ub; ∀z. lb ≤ z ∧ z < ub ⟶ poly p z ≠ 0⟧ ⟹ thesis; ∃r. poly p r = 0 ∧ r < ub⟧ ⟹ thesis›*) case True (*‹∃r. poly p r = 0 ∧ r < ub›*) define mr where "mr≡Max {r . poly p r=0 ∧ r<ub}" have "∀z. mr<z∧z<ub⟶poly p z≠0" and "mr<ub" using True (*‹∃r. poly p r = 0 ∧ r < ub›*) mr_def (*‹mr ≡ Max {r. poly p r = 0 ∧ r < ub}›*) poly_roots_finite[OF ‹p≠0›] (*‹finite {x. poly p x = 0}›*) apply - (*goals: 1. ‹⟦∃r. poly p r = 0 ∧ r < ub; mr ≡ Max {r. poly p r = 0 ∧ r < ub}; finite {x. poly p x = 0}⟧ ⟹ ∀z. mr < z ∧ z < ub ⟶ poly p z ≠ 0› 2. ‹⟦∃r. poly p r = 0 ∧ r < ub; mr ≡ Max {r. poly p r = 0 ∧ r < ub}; finite {x. poly p x = 0}⟧ ⟹ mr < ub› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . thus "?thesis" (*goal: ‹thesis›*) using that[of "(mr+ub)/2"] (*‹⟦(mr + ub) / 2 < ub; ∀z. (mr + ub) / 2 ≤ z ∧ z < ub ⟶ poly p z ≠ 0⟧ ⟹ thesis›*) ‹mr<ub› (*‹mr < ub›*) by auto qed subsection‹Sign› definition sign:: "'a::{zero,linorder} ⇒ int" where "sign x≡(if x>0 then 1 else if x=0 then 0 else -1)" lemma sign_simps[simp]: "x>0 ⟹ sign x=1" "x=0 ⟹ sign x=0" "x<0 ⟹ sign x=-1" unfolding sign_def (*goals: 1. ‹(0::'a) < (x::'a) ⟹ (if (0::'a) < x then 1::int else if x = (0::'a) then 0::int else - (1::int)) = (1::int)› 2. ‹(x::'a) = (0::'a) ⟹ (if (0::'a) < x then 1::int else if x = (0::'a) then 0::int else - (1::int)) = (0::int)› 3. ‹(x::'a) < (0::'a) ⟹ (if (0::'a) < x then 1::int else if x = (0::'a) then 0::int else - (1::int)) = - (1::int)›*) (*goals: 1. ‹0 < x ⟹ (if 0 < x then 1 else if x = 0 then 0 else - 1) = 1› 2. ‹x = 0 ⟹ (if 0 < x then 1 else if x = 0 then 0 else - 1) = 0› 3. ‹x < 0 ⟹ (if 0 < x then 1 else if x = 0 then 0 else - 1) = - 1› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . lemma sign_cases [case_names neg zero pos]: "(sign x = -1 ⟹ P) ⟹ (sign x = 0 ⟹ P) ⟹ (sign x =1 ⟹ P) ⟹ P" unfolding Sturm_Tarski.sign_def (*goal: ‹⟦(if 0 < x then 1 else if x = 0 then 0 else - 1) = - 1 ⟹ P; (if 0 < x then 1 else if x = 0 then 0 else - 1) = 0 ⟹ P; (if 0 < x then 1 else if x = 0 then 0 else - 1) = 1 ⟹ P⟧ ⟹ P›*) by argo lemma sign_times: fixes x::"'a::linordered_ring_strict" shows "sign (x*y) = sign x * sign y" unfolding Sturm_Tarski.sign_def (*goal: ‹(if 0 < x * y then 1 else if x * y = 0 then 0 else - 1) = (if 0 < x then 1 else if x = 0 then 0 else - 1) * (if 0 < y then 1 else if y = 0 then 0 else - 1)›*) by (auto simp add:zero_less_mult_iff (*‹(0 < ?a * ?b) = (0 < ?a ∧ 0 < ?b ∨ ?a < 0 ∧ ?b < 0)›*)) lemma sign_power: fixes x::"'a::linordered_idom" shows "sign (x^n) = (if n=0 then 1 else if even n then ¦sign x¦ else sign x)" by (simp add: Sturm_Tarski.sign_def (*‹sign ?x ≡ if 0 < ?x then 1 else if ?x = 0 then 0 else - 1›*) zero_less_power_eq (*‹(0 < ?a ^ ?n) = (?n = 0 ∨ even ?n ∧ ?a ≠ 0 ∨ odd ?n ∧ 0 < ?a)›*)) (* lemma sgn_sign_eq: fixes x::"'a::{linordered_idom}" shows "sgn x = of_int (sign x)" unfolding sgn_if by auto *) lemma sgn_sign_eq:"sgn = sign" unfolding sign_def sgn_if (*goal: ‹(λx. if x = 0 then 0 else if 0 < x then 1 else - 1) = (λx. if 0 < x then 1 else if x = 0 then 0 else - 1)›*) by auto lemma sign_sgn[simp]: "sign (sgn x) = sign (x::'b::linordered_idom)" by (simp add: sign_def (*‹sign ?x ≡ if 0 < ?x then 1 else if ?x = 0 then 0 else - 1›*)) lemma sign_uminus[simp]:"sign (- x) = - sign (x::'b::linordered_idom)" by (simp add: sign_def (*‹sign ?x ≡ if 0 < ?x then 1 else if ?x = 0 then 0 else - 1›*)) subsection‹Bound of polynomials› definition sgn_pos_inf :: "('a ::linordered_idom) poly ⇒ 'a" where "sgn_pos_inf p ≡ sgn (lead_coeff p)" definition sgn_neg_inf :: "('a ::linordered_idom) poly ⇒ 'a" where "sgn_neg_inf p ≡ if even (degree p) then sgn (lead_coeff p) else -sgn (lead_coeff p)" lemma sgn_inf_sym: fixes p::"real poly" shows "sgn_pos_inf (pcompose p [:0,-1:]) = sgn_neg_inf p" (is "?L=?R") proof (-) (*goal: ‹sgn_pos_inf (p ∘⇩p [:0, - 1:]) = sgn_neg_inf p›*) have "?L= sgn (lead_coeff p * (- 1) ^ degree p)" unfolding sgn_pos_inf_def (*goal: ‹sgn (lead_coeff (p ∘⇩p [:0, - 1:])) = sgn (lead_coeff p * (- 1) ^ degree p)›*) apply (subst lead_coeff_comp (*‹0 < degree ?q ⟹ lead_coeff (?p ∘⇩p ?q) = lead_coeff ?p * lead_coeff ?q ^ degree ?p›*)) (*goals: 1. ‹0 < degree [:0, - 1:]› 2. ‹sgn (lead_coeff p * lead_coeff [:0, - 1:] ^ degree p) = sgn (lead_coeff p * (- 1) ^ degree p)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . thus "?thesis" (*goal: ‹sgn_pos_inf (p ∘⇩p [:0, - 1:]) = sgn_neg_inf p›*) unfolding sgn_neg_inf_def (*goal: ‹sgn_pos_inf (p ∘⇩p [:0, - 1:]) = (if even (degree p) then sgn (lead_coeff p) else - sgn (lead_coeff p))›*) by (metis mult.right_neutral (*‹?a * 1 = ?a›*) mult_minus1_right (*‹?z * - 1 = - ?z›*) neg_one_even_power (*‹even ?n ⟹ (- 1) ^ ?n = 1›*) neg_one_odd_power (*‹odd ?n ⟹ (- 1) ^ ?n = - 1›*) sgn_minus (*‹sgn (- ?x) = - sgn ?x›*)) qed lemma poly_pinfty_gt_lc: fixes p:: "real poly" assumes "lead_coeff p > 0" shows "∃ n. ∀ x ≥ n. poly p x ≥ lead_coeff p" using assms (*‹0 < lead_coeff p›*) proof (induct p) (*goals: 1. ‹(0::real) < lead_coeff (0::real poly) ⟹ ∃n::real. ∀x≥n. lead_coeff (0::real poly) ≤ poly (0::real poly) x› 2. ‹⋀(a::real) p::real poly. ⟦a ≠ (0::real) ∨ p ≠ (0::real poly); (0::real) < lead_coeff p ⟹ ∃n::real. ∀x≥n. lead_coeff p ≤ poly p x; (0::real) < lead_coeff (pCons a p)⟧ ⟹ ∃n::real. ∀x≥n. lead_coeff (pCons a p) ≤ poly (pCons a p) x›*) case 0 (*‹(0::real) < lead_coeff (0::real poly)›*) thus "?case" (*goal: ‹∃n. ∀x≥n. lead_coeff 0 ≤ poly 0 x›*) by auto next (*goal: ‹⋀(a::real) p::real poly. ⟦a ≠ (0::real) ∨ p ≠ (0::real poly); (0::real) < lead_coeff p ⟹ ∃n::real. ∀x≥n. lead_coeff p ≤ poly p x; (0::real) < lead_coeff (pCons a p)⟧ ⟹ ∃n::real. ∀x≥n. lead_coeff (pCons a p) ≤ poly (pCons a p) x›*) case (pCons a p) (*‹a ≠ 0 ∨ p ≠ 0› ‹0 < lead_coeff p ⟹ ∃n. ∀x≥n. lead_coeff p ≤ poly p x› ‹0 < lead_coeff (pCons a p)›*) have "⟦a≠0;p=0⟧ ⟹ ?case" by auto moreover have "p≠0 ⟹ ?case" proof (-) (*goal: ‹p ≠ 0 ⟹ ∃n. ∀x≥n. lead_coeff (pCons a p) ≤ poly (pCons a p) x›*) assume "p≠0" (*‹(p::real poly) ≠ (0::real poly)›*) then obtain n1 where gte_lcoeff: "∀x≥n1. lead_coeff p ≤ poly p x" (*goal: ‹(⋀n1. ∀x≥n1. lead_coeff p ≤ poly p x ⟹ thesis) ⟹ thesis›*) using that (*‹∀x≥?n1.0. lead_coeff p ≤ poly p x ⟹ thesis›*) pCons (*‹a ≠ 0 ∨ p ≠ 0› ‹0 < lead_coeff p ⟹ ∃n. ∀x≥n. lead_coeff p ≤ poly p x› ‹(0::real) < lead_coeff (pCons (a::real) (p::real poly))›*) by auto have gt_0: "lead_coeff p >0" using pCons(3) (*‹(0::real) < lead_coeff (pCons (a::real) (p::real poly))›*) ‹p≠0› (*‹p ≠ 0›*) by auto define n where "n≡max n1 (1+ ¦a¦/(lead_coeff p))" show "?thesis" (*goal: ‹∃n. ∀x≥n. lead_coeff (pCons a p) ≤ poly (pCons a p) x›*) apply (rule_tac x=n in exI (*‹(?P::?'a ⇒ bool) (?x::?'a) ⟹ ∃x::?'a. ?P x›*)) (*goal: ‹∃n. ∀x≥n. lead_coeff (pCons a p) ≤ poly (pCons a p) x›*) apply rule (*goal: ‹∀x≥n::real. lead_coeff (pCons (a::real) (p::real poly)) ≤ poly (pCons a p) x›*) proof (rule) (*goal: ‹⋀x. n ≤ x ⟹ lead_coeff (pCons a p) ≤ poly (pCons a p) x›*) fix x assume "n ≤ x" (*‹(n::real) ≤ (x::real)›*) hence "lead_coeff p ≤ poly p x" using gte_lcoeff (*‹∀x≥n1::real. lead_coeff (p::real poly) ≤ poly p x›*) unfolding n_def (*goal: ‹lead_coeff p ≤ poly p x›*) by auto hence " ¦a¦/(lead_coeff p) ≥ ¦a¦/(poly p x)" and "poly p x>0" using gt_0 (*‹0 < lead_coeff p›*) apply - (*goals: 1. ‹⟦lead_coeff p ≤ poly p x; 0 < lead_coeff p⟧ ⟹ ¦a¦ / poly p x ≤ ¦a¦ / lead_coeff p› 2. ‹⟦lead_coeff p ≤ poly p x; 0 < lead_coeff p⟧ ⟹ 0 < poly p x› discuss goal 1*) apply (intro frac_le (*‹⟦0 ≤ ?y; ?x ≤ ?y; 0 < ?w; ?w ≤ ?z⟧ ⟹ ?x / ?z ≤ ?y / ?w›*)) (*goals: 1. ‹⟦lead_coeff (p::real poly) ≤ poly p (x::real); (0::real) < lead_coeff p⟧ ⟹ (0::real) ≤ ¦a::real¦› 2. ‹⟦lead_coeff (p::real poly) ≤ poly p (x::real); (0::real) < lead_coeff p⟧ ⟹ ¦a::real¦ ≤ ¦a¦› 3. ‹⟦lead_coeff (p::real poly) ≤ poly p (x::real); (0::real) < lead_coeff p⟧ ⟹ (0::real) < lead_coeff p› 4. ‹⟦lead_coeff (p::real poly) ≤ poly p (x::real); (0::real) < lead_coeff p⟧ ⟹ lead_coeff p ≤ poly p x› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . hence "x≥1+ ¦a¦/(poly p x)" using ‹n≤x›[unfolded n_def] (*‹max (n1::real) ((1::real) + ¦a::real¦ / lead_coeff (p::real poly)) ≤ (x::real)›*) by auto thus "lead_coeff (pCons a p) ≤ poly (pCons a p) x" using ‹lead_coeff p ≤ poly p x› (*‹lead_coeff (p::real poly) ≤ poly p (x::real)›*) ‹poly p x>0› (*‹0 < poly p x›*) ‹p≠0› (*‹(p::real poly) ≠ (0::real poly)›*) by (auto simp add:field_simps (*‹(?a::?'a::semigroup_add) + (?b::?'a::semigroup_add) + (?c::?'a::semigroup_add) = ?a + (?b + ?c)› ‹(?a::?'a::ab_semigroup_add) + (?b::?'a::ab_semigroup_add) = ?b + ?a› ‹(?b::?'a::ab_semigroup_add) + ((?a::?'a::ab_semigroup_add) + (?c::?'a::ab_semigroup_add)) = ?a + (?b + ?c)› ‹(?a::?'a::semigroup_mult) * (?b::?'a::semigroup_mult) * (?c::?'a::semigroup_mult) = ?a * (?b * ?c)› ‹(?a::?'a::ab_semigroup_mult) * (?b::?'a::ab_semigroup_mult) = ?b * ?a› ‹(?b::?'a::ab_semigroup_mult) * ((?a::?'a::ab_semigroup_mult) * (?c::?'a::ab_semigroup_mult)) = ?a * (?b * ?c)› ‹(?a::?'a::cancel_ab_semigroup_add) - (?b::?'a::cancel_ab_semigroup_add) - (?c::?'a::cancel_ab_semigroup_add) = ?a - (?b + ?c)› ‹(?a::?'a::group_add) + ((?b::?'a::group_add) - (?c::?'a::group_add)) = ?a + ?b - ?c› ‹((?a::?'a::group_add) - (?b::?'a::group_add) = (?c::?'a::group_add)) = (?a = ?c + ?b)› ‹((?a::?'a::group_add) = (?c::?'a::group_add) - (?b::?'a::group_add)) = (?a + ?b = ?c)› ‹(?a::?'a::group_add) - ((?b::?'a::group_add) - (?c::?'a::group_add)) = ?a + ?c - ?b› ‹(?a::?'a::ab_group_add) - (?b::?'a::ab_group_add) + (?c::?'a::ab_group_add) = ?a + ?c - ?b› and more 69 facts*)) qed qed ultimately show "?case" (*goal: ‹∃n. ∀x≥n. lead_coeff (pCons a p) ≤ poly (pCons a p) x›*) by fastforce qed lemma poly_sgn_eventually_at_top: fixes p::"real poly" shows "eventually (λx. sgn (poly p x) = sgn_pos_inf p) at_top" proof (cases "p=0") (*goals: 1. ‹p = 0 ⟹ ∀⇩F x in at_top. sgn (poly p x) = sgn_pos_inf p› 2. ‹p ≠ 0 ⟹ ∀⇩F x in at_top. sgn (poly p x) = sgn_pos_inf p›*) case True (*‹p = 0›*) thus "?thesis" (*goal: ‹∀⇩F x in at_top. sgn (poly p x) = sgn_pos_inf p›*) unfolding sgn_pos_inf_def (*goal: ‹∀⇩F x in at_top. sgn (poly p x) = sgn (lead_coeff p)›*) by auto next (*goal: ‹p ≠ 0 ⟹ ∀⇩F x in at_top. sgn (poly p x) = sgn_pos_inf p›*) case False (*‹p ≠ 0›*) obtain ub where ub: "∀x≥ub. sgn (poly p x) = sgn_pos_inf p" (*goal: ‹(⋀ub. ∀x≥ub. sgn (poly p x) = sgn_pos_inf p ⟹ thesis) ⟹ thesis›*) proof (cases "lead_coeff p>0") (*goals: 1. ‹⟦⋀ub::real. ∀x≥ub. sgn (poly (p::real poly) x) = sgn_pos_inf p ⟹ thesis::bool; (0::real) < lead_coeff p⟧ ⟹ thesis› 2. ‹⟦⋀ub::real. ∀x≥ub. sgn (poly (p::real poly) x) = sgn_pos_inf p ⟹ thesis::bool; ¬ (0::real) < lead_coeff p⟧ ⟹ thesis›*) case True (*‹0 < lead_coeff p›*) thus "?thesis" (*goal: ‹thesis::bool›*) using that (*‹∀x≥?ub. sgn (poly p x) = sgn_pos_inf p ⟹ thesis›*) poly_pinfty_gt_lc[of p] (*‹0 < lead_coeff p ⟹ ∃n. ∀x≥n. lead_coeff p ≤ poly p x›*) unfolding sgn_pos_inf_def (*goal: ‹thesis›*) by fastforce next (*goal: ‹⟦⋀ub. ∀x≥ub. sgn (poly p x) = sgn_pos_inf p ⟹ thesis; ¬ 0 < lead_coeff p⟧ ⟹ thesis›*) case False (*‹¬ (0::real) < lead_coeff (p::real poly)›*) hence "lead_coeff (-p) > 0" and "lead_coeff p < 0" unfolding lead_coeff_minus (*goals: 1. ‹0 < - lead_coeff p› 2. ‹lead_coeff p < 0›*) using leading_coeff_neq_0[OF ‹p≠0›] (*‹lead_coeff (p::real poly) ≠ (0::real)›*) apply - (*goals: 1. ‹⟦¬ 0 < lead_coeff p; lead_coeff p ≠ 0⟧ ⟹ 0 < - lead_coeff p› 2. ‹⟦¬ 0 < lead_coeff p; lead_coeff p ≠ 0⟧ ⟹ lead_coeff p < 0› discuss goal 1*) apply ((auto simp add:not_less_iff_gr_or_eq (*‹(¬ ?x < ?y) = (?y < ?x ∨ ?x = ?y)›*))[1]) (*discuss goal 2*) apply ((auto simp add:not_less_iff_gr_or_eq (*‹(¬ ?x < ?y) = (?y < ?x ∨ ?x = ?y)›*))[1]) (*proven 2 subgoals*) . then obtain n where "∀x≥n. lead_coeff p ≥ poly p x" (*goal: ‹(⋀n::real. ∀x≥n. poly (p::real poly) x ≤ lead_coeff p ⟹ thesis::bool) ⟹ thesis›*) using poly_pinfty_gt_lc[of "-p"] (*‹0 < lead_coeff (- p) ⟹ ∃n. ∀x≥n. lead_coeff (- p) ≤ poly (- p) x›*) unfolding lead_coeff_minus (*goal: ‹(⋀n. ∀x≥n. poly p x ≤ lead_coeff p ⟹ thesis) ⟹ thesis›*) by auto thus "?thesis" (*goal: ‹thesis›*) using ‹lead_coeff p<0› (*‹lead_coeff p < 0›*) that[of n] (*‹∀x≥n. sgn (poly p x) = sgn_pos_inf p ⟹ thesis›*) unfolding sgn_pos_inf_def (*goal: ‹thesis::bool›*) by fastforce qed thus "?thesis" (*goal: ‹∀⇩F x in at_top. sgn (poly p x) = sgn_pos_inf p›*) unfolding eventually_at_top_linorder (*goal: ‹∃N. ∀n≥N. sgn (poly p n) = sgn_pos_inf p›*) by auto qed lemma poly_sgn_eventually_at_bot: fixes p::"real poly" shows "eventually (λx. sgn (poly p x) = sgn_neg_inf p) at_bot" using poly_sgn_eventually_at_top[of "pcompose p [:0,-1:]", unfolded poly_pcompose sgn_inf_sym, simplified] (*‹∀⇩F x in at_top. sgn (poly p (- x)) = sgn_neg_inf p›*) eventually_filtermap[of _ uminus "at_bot::real filter", folded at_top_mirror] (*‹eventually (?P::real ⇒ bool) at_top = (∀⇩F x::real in at_bot. ?P (- x))›*) by auto lemma root_ub: fixes p:: "real poly" assumes "p≠0" obtains ub where "∀x. poly p x=0 ⟶ x<ub" and "∀x≥ub. sgn (poly p x) = sgn_pos_inf p" proof (-) (*goal: ‹(⋀ub. ⟦∀x. poly p x = 0 ⟶ x < ub; ∀x≥ub. sgn (poly p x) = sgn_pos_inf p⟧ ⟹ thesis) ⟹ thesis›*) obtain ub1 where ub1: "∀x. poly p x=0 ⟶ x<ub1" (*goal: ‹(⋀ub1. ∀x. poly p x = 0 ⟶ x < ub1 ⟹ thesis) ⟹ thesis›*) proof (cases "∃ r. poly p r=0") (*goals: 1. ‹⟦⋀ub1. ∀x. poly p x = 0 ⟶ x < ub1 ⟹ thesis; ∃r. poly p r = 0⟧ ⟹ thesis› 2. ‹⟦⋀ub1. ∀x. poly p x = 0 ⟶ x < ub1 ⟹ thesis; ∄r. poly p r = 0⟧ ⟹ thesis›*) case False (*‹∄r. poly p r = 0›*) thus "?thesis" (*goal: ‹thesis›*) using that (*‹∀x::real. poly (p::real poly) x = (0::real) ⟶ x < (?ub1.0::real) ⟹ thesis::bool›*) by auto next (*goal: ‹⟦⋀ub1. ∀x. poly p x = 0 ⟶ x < ub1 ⟹ thesis; ∃r. poly p r = 0⟧ ⟹ thesis›*) case True (*‹∃r. poly p r = 0›*) define max_r where "max_r≡Max {x . poly p x=0}" hence "∀x. poly p x=0 ⟶ x≤max_r" using poly_roots_finite[OF ‹p≠0›] (*‹finite {x::real. poly (p::real poly) x = (0::real)}›*) True (*‹∃r. poly p r = 0›*) by auto thus "?thesis" (*goal: ‹thesis::bool›*) using that[of "max_r+1"] (*‹∀x. poly p x = 0 ⟶ x < max_r + 1 ⟹ thesis›*) by (metis add.commute (*‹?a + ?b = ?b + ?a›*) add_strict_increasing (*‹⟦0 < ?a; ?b ≤ ?c⟧ ⟹ ?b < ?a + ?c›*) zero_less_one (*‹0 < 1›*)) qed obtain ub2 where ub2: "∀x≥ub2. sgn (poly p x) = sgn_pos_inf p" (*goal: ‹(⋀ub2. ∀x≥ub2. sgn (poly p x) = sgn_pos_inf p ⟹ thesis) ⟹ thesis›*) using poly_sgn_eventually_at_top[unfolded eventually_at_top_linorder] (*‹∃N::real. ∀n≥N. sgn (poly (?p::real poly) n) = sgn_pos_inf ?p›*) by auto define ub where "ub≡max ub1 ub2" have "∀x. poly p x=0 ⟶ x<ub" using ub1 (*‹∀x. poly p x = 0 ⟶ x < ub1›*) ub_def (*‹ub ≡ max ub1 ub2›*) by (metis eq_iff (*‹(?a = ?b) = (?a ≤ ?b ∧ ?b ≤ ?a)›*) less_eq_real_def (*‹(?x ≤ ?y) = (?x < ?y ∨ ?x = ?y)›*) less_linear (*‹?x < ?y ∨ ?x = ?y ∨ ?y < ?x›*) max.bounded_iff (*‹(max ?b ?c ≤ ?a) = (?b ≤ ?a ∧ ?c ≤ ?a)›*)) thus "?thesis" (*goal: ‹thesis::bool›*) using that[of ub] (*‹⟦∀x. poly p x = 0 ⟶ x < ub; ∀x≥ub. sgn (poly p x) = sgn_pos_inf p⟧ ⟹ thesis›*) ub2 (*‹∀x≥ub2::real. sgn (poly (p::real poly) x) = sgn_pos_inf p›*) ub_def (*‹ub ≡ max ub1 ub2›*) by auto qed lemma root_lb: fixes p:: "real poly" assumes "p≠0" obtains lb where "∀x. poly p x=0 ⟶ x>lb" and "∀x≤lb. sgn (poly p x) = sgn_neg_inf p" proof (-) (*goal: ‹(⋀lb. ⟦∀x. poly p x = 0 ⟶ lb < x; ∀x≤lb. sgn (poly p x) = sgn_neg_inf p⟧ ⟹ thesis) ⟹ thesis›*) obtain lb1 where lb1: "∀x. poly p x=0 ⟶ x>lb1" (*goal: ‹(⋀lb1. ∀x. poly p x = 0 ⟶ lb1 < x ⟹ thesis) ⟹ thesis›*) proof (cases "∃ r. poly p r=0") (*goals: 1. ‹⟦⋀lb1::real. ∀x::real. poly (p::real poly) x = (0::real) ⟶ lb1 < x ⟹ thesis::bool; ∃r::real. poly p r = (0::real)⟧ ⟹ thesis› 2. ‹⟦⋀lb1::real. ∀x::real. poly (p::real poly) x = (0::real) ⟶ lb1 < x ⟹ thesis::bool; ∄r::real. poly p r = (0::real)⟧ ⟹ thesis›*) case False (*‹∄r. poly p r = 0›*) thus "?thesis" (*goal: ‹thesis›*) using that (*‹∀x. poly p x = 0 ⟶ ?lb1.0 < x ⟹ thesis›*) by auto next (*goal: ‹⟦⋀lb1::real. ∀x::real. poly (p::real poly) x = (0::real) ⟶ lb1 < x ⟹ thesis::bool; ∃r::real. poly p r = (0::real)⟧ ⟹ thesis›*) case True (*‹∃r. poly p r = 0›*) define min_r where "min_r≡Min {x . poly p x=0}" hence "∀x. poly p x=0 ⟶ x≥min_r" using poly_roots_finite[OF ‹p≠0›] (*‹finite {x. poly p x = 0}›*) True (*‹∃r. poly p r = 0›*) by auto thus "?thesis" (*goal: ‹thesis›*) using that[of "min_r - 1"] (*‹∀x. poly p x = 0 ⟶ min_r - 1 < x ⟹ thesis›*) by (metis lt_ex (*‹∃y. y < ?x›*) order.strict_trans2 (*‹⟦?a < ?b; ?b ≤ ?c⟧ ⟹ ?a < ?c›*) that (*‹∀x. poly p x = 0 ⟶ ?lb1.0 < x ⟹ thesis›*)) qed obtain lb2 where lb2: "∀x≤lb2. sgn (poly p x) = sgn_neg_inf p" (*goal: ‹(⋀lb2. ∀x≤lb2. sgn (poly p x) = sgn_neg_inf p ⟹ thesis) ⟹ thesis›*) using poly_sgn_eventually_at_bot[unfolded eventually_at_bot_linorder] (*‹∃N. ∀n≤N. sgn (poly ?p n) = sgn_neg_inf ?p›*) by auto define lb where "lb≡min lb1 lb2" have "∀x. poly p x=0 ⟶ x>lb" using lb1 (*‹∀x. poly p x = 0 ⟶ lb1 < x›*) lb_def (*‹lb ≡ min lb1 lb2›*) by (metis (poly_guards_query) less_not_sym (*‹?x < ?y ⟹ ¬ ?y < ?x›*) min_less_iff_conj (*‹(?z < min ?x ?y) = (?z < ?x ∧ ?z < ?y)›*) neq_iff (*‹(?x ≠ ?y) = (?x < ?y ∨ ?y < ?x)›*)) thus "?thesis" (*goal: ‹thesis›*) using that[of lb] (*‹⟦∀x. poly p x = 0 ⟶ lb < x; ∀x≤lb. sgn (poly p x) = sgn_neg_inf p⟧ ⟹ thesis›*) lb2 (*‹∀x≤lb2::real. sgn (poly (p::real poly) x) = sgn_neg_inf p›*) lb_def (*‹lb ≡ min lb1 lb2›*) by auto qed subsection ‹Variation and cross› definition variation :: "real ⇒ real ⇒ int" where "variation x y=(if x*y≥0 then 0 else if x<y then 1 else -1)" definition cross :: "real poly ⇒ real ⇒ real ⇒ int" where "cross p a b=variation (poly p a) (poly p b)" lemma variation_0[simp]: "variation 0 y=0" "variation x 0=0" unfolding variation_def (*goals: 1. ‹(if 0 ≤ 0 * y then 0 else if 0 < y then 1 else - 1) = 0› 2. ‹(if 0 ≤ x * 0 then 0 else if x < 0 then 1 else - 1) = 0›*) (*goals: 1. ‹(if (0::real) ≤ (0::real) * (y::real) then 0::int else if (0::real) < y then 1::int else - (1::int)) = (0::int)› 2. ‹(if (0::real) ≤ (x::real) * (0::real) then 0::int else if x < (0::real) then 1::int else - (1::int)) = (0::int)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma variation_comm: "variation x y= - variation y x" unfolding variation_def (*goal: ‹(if 0 ≤ x * y then 0 else if x < y then 1 else - 1) = - (if 0 ≤ y * x then 0 else if y < x then 1 else - 1)›*) by (auto simp add: mult.commute (*‹?a * ?b = ?b * ?a›*)) lemma cross_0[simp]: "cross 0 a b=0" sorry lemma variation_cases: "⟦x>0;y>0⟧⟹variation x y = 0" "⟦x>0;y<0⟧⟹variation x y = -1" "⟦x<0;y>0⟧⟹variation x y = 1" "⟦x<0;y<0⟧⟹variation x y = 0" proof (-) (*goals: 1. ‹⟦0 < x; 0 < y⟧ ⟹ variation x y = 0› 2. ‹⟦0 < x; y < 0⟧ ⟹ variation x y = - 1› 3. ‹⟦x < 0; 0 < y⟧ ⟹ variation x y = 1› 4. ‹⟦x < 0; y < 0⟧ ⟹ variation x y = 0›*) show "⟦x>0;y>0⟧⟹variation x y = 0" unfolding variation_def (*goal: ‹⟦0 < x; 0 < y⟧ ⟹ (if 0 ≤ x * y then 0 else if x < y then 1 else - 1) = 0›*) by auto show "⟦x>0;y<0⟧⟹variation x y = -1" unfolding variation_def (*goal: ‹⟦0 < x; y < 0⟧ ⟹ (if 0 ≤ x * y then 0 else if x < y then 1 else - 1) = - 1›*) using mult_pos_neg (*‹⟦0 < ?a; ?b < 0⟧ ⟹ ?a * ?b < 0›*) by fastforce show "⟦x<0;y>0⟧⟹variation x y = 1" unfolding variation_def (*goal: ‹⟦x < 0; 0 < y⟧ ⟹ (if 0 ≤ x * y then 0 else if x < y then 1 else - 1) = 1›*) using mult_neg_pos (*‹⟦?a < 0; 0 < ?b⟧ ⟹ ?a * ?b < 0›*) by fastforce show "⟦x<0;y<0⟧⟹variation x y = 0" unfolding variation_def (*goal: ‹⟦x < 0; y < 0⟧ ⟹ (if 0 ≤ x * y then 0 else if x < y then 1 else - 1) = 0›*) using mult_neg_neg (*‹⟦?a < 0; ?b < 0⟧ ⟹ 0 < ?a * ?b›*) by fastforce qed lemma variation_congr: assumes "sgn x=sgn x'" "sgn y=sgn y'" shows "variation x y=variation x' y'" using assms (*‹sgn x = sgn x'› ‹sgn (y::real) = sgn (y'::real)›*) proof (-) (*goal: ‹⟦sgn (x::real) = sgn (x'::real); sgn (y::real) = sgn (y'::real)⟧ ⟹ variation x y = variation x' y'›*) have " 0 ≤ x * y = (0≤ x' * y')" using assms (*‹sgn x = sgn x'› ‹sgn y = sgn y'›*) by (metis Real_Vector_Spaces.sgn_mult (*‹sgn (?x * ?y) = sgn ?x * sgn ?y›*) zero_le_sgn_iff (*‹(0 ≤ sgn ?x) = (0 ≤ ?x)›*)) moreover hence "¬ 0≤x * y ⟹ x < y = (x' < y')" using assms (*‹sgn (x::real) = sgn (x'::real)› ‹sgn y = sgn y'›*) by (metis less_eq_real_def (*‹(?x ≤ ?y) = (?x < ?y ∨ ?x = ?y)›*) mult_nonneg_nonneg (*‹⟦0 ≤ ?a; 0 ≤ ?b⟧ ⟹ 0 ≤ ?a * ?b›*) mult_nonpos_nonpos (*‹⟦?a ≤ 0; ?b ≤ 0⟧ ⟹ 0 ≤ ?a * ?b›*) not_le (*‹(¬ ?x ≤ ?y) = (?y < ?x)›*) order.strict_trans2 (*‹⟦?a < ?b; ?b ≤ ?c⟧ ⟹ ?a < ?c›*) zero_le_sgn_iff (*‹(0 ≤ sgn ?x) = (0 ≤ ?x)›*)) ultimately show "?thesis" (*goal: ‹variation x y = variation x' y'›*) unfolding variation_def (*goal: ‹(if (0::real) ≤ (x::real) * (y::real) then 0::int else if x < y then 1::int else - (1::int)) = (if (0::real) ≤ (x'::real) * (y'::real) then 0::int else if x' < y' then 1::int else - (1::int))›*) by auto qed lemma variation_mult_pos: assumes "c>0" shows "variation (c*x) y =variation x y" and "variation x (c*y) =variation x y" proof (-) (*goals: 1. ‹variation (c * x) y = variation x y› 2. ‹variation x (c * y) = variation x y›*) have "sgn (c*x) = sgn x" using ‹c>0› (*‹(0::real) < (c::real)›*) by (simp add: Real_Vector_Spaces.sgn_mult (*‹sgn (?x * ?y) = sgn ?x * sgn ?y›*)) thus "variation (c*x) y =variation x y" using variation_congr (*‹⟦sgn ?x = sgn ?x'; sgn ?y = sgn ?y'⟧ ⟹ variation ?x ?y = variation ?x' ?y'›*) by blast next (*goal: ‹variation (x::real) ((c::real) * (y::real)) = variation x y›*) have "sgn (c*y) = sgn y" using ‹c>0› (*‹0 < c›*) by (simp add: Real_Vector_Spaces.sgn_mult (*‹sgn ((?x::?'a) * (?y::?'a)) = sgn ?x * sgn ?y›*)) thus "variation x (c*y) =variation x y" using variation_congr (*‹⟦sgn ?x = sgn ?x'; sgn ?y = sgn ?y'⟧ ⟹ variation ?x ?y = variation ?x' ?y'›*) by blast qed lemma variation_mult_neg_1: assumes "c<0" shows "variation (c*x) y =variation x y + (if y=0 then 0 else sign x)" apply (cases x rule:linorder_cases[of 0] (*‹⟦0 < ?y ⟹ ?P; 0 = ?y ⟹ ?P; ?y < 0 ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹0 < x ⟹ variation (c * x) y = variation x y + (if y = 0 then 0 else sign x)› 2. ‹0 = x ⟹ variation (c * x) y = variation x y + (if y = 0 then 0 else sign x)› 3. ‹x < 0 ⟹ variation (c * x) y = variation x y + (if y = 0 then 0 else sign x)› discuss goal 1*) apply (cases y rule:linorder_cases[of 0] (*‹⟦0 < ?y ⟹ ?P; 0 = ?y ⟹ ?P; ?y < 0 ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹⟦0 < x; 0 < y⟧ ⟹ variation (c * x) y = variation x y + (if y = 0 then 0 else sign x)› 2. ‹⟦0 < x; 0 = y⟧ ⟹ variation (c * x) y = variation x y + (if y = 0 then 0 else sign x)› 3. ‹⟦0 < x; y < 0⟧ ⟹ variation (c * x) y = variation x y + (if y = 0 then 0 else sign x)› discuss goal 1*) apply ((auto simp add: variation_cases (*‹⟦0 < ?x; 0 < ?y⟧ ⟹ variation ?x ?y = 0› ‹⟦0 < ?x; ?y < 0⟧ ⟹ variation ?x ?y = - 1› ‹⟦?x < 0; 0 < ?y⟧ ⟹ variation ?x ?y = 1› ‹⟦?x < 0; ?y < 0⟧ ⟹ variation ?x ?y = 0›*) mult_neg_pos[OF ‹c<0›,of x] (*‹0 < x ⟹ c * x < 0›*) mult_neg_neg[OF ‹c<0›,of x] (*‹x < 0 ⟹ 0 < c * x›*))[1]) (*discuss goal 2*) apply ((auto simp add: variation_cases (*‹⟦0 < ?x; 0 < ?y⟧ ⟹ variation ?x ?y = 0› ‹⟦0 < ?x; ?y < 0⟧ ⟹ variation ?x ?y = - 1› ‹⟦?x < 0; 0 < ?y⟧ ⟹ variation ?x ?y = 1› ‹⟦?x < 0; ?y < 0⟧ ⟹ variation ?x ?y = 0›*) mult_neg_pos[OF ‹c<0›,of x] (*‹0 < x ⟹ c * x < 0›*) mult_neg_neg[OF ‹c<0›,of x] (*‹x < 0 ⟹ 0 < c * x›*))[1]) (*discuss goal 3*) apply ((auto simp add: variation_cases (*‹⟦0 < ?x; 0 < ?y⟧ ⟹ variation ?x ?y = 0› ‹⟦0 < ?x; ?y < 0⟧ ⟹ variation ?x ?y = - 1› ‹⟦?x < 0; 0 < ?y⟧ ⟹ variation ?x ?y = 1› ‹⟦?x < 0; ?y < 0⟧ ⟹ variation ?x ?y = 0›*) mult_neg_pos[OF ‹c<0›,of x] (*‹0 < x ⟹ c * x < 0›*) mult_neg_neg[OF ‹c<0›,of x] (*‹x < 0 ⟹ 0 < c * x›*))[1]) (*proven 3 subgoals*) (*discuss goal 2*) apply ((auto simp add: variation_cases (*‹⟦0 < ?x; 0 < ?y⟧ ⟹ variation ?x ?y = 0› ‹⟦0 < ?x; ?y < 0⟧ ⟹ variation ?x ?y = - 1› ‹⟦?x < 0; 0 < ?y⟧ ⟹ variation ?x ?y = 1› ‹⟦?x < 0; ?y < 0⟧ ⟹ variation ?x ?y = 0›*) mult_neg_pos[OF ‹c<0›,of x] (*‹0 < x ⟹ c * x < 0›*) mult_neg_neg[OF ‹c<0›,of x] (*‹x < 0 ⟹ 0 < c * x›*))[1]) (*discuss goal 3*) apply ((auto simp add: variation_cases (*‹⟦0 < ?x; 0 < ?y⟧ ⟹ variation ?x ?y = 0› ‹⟦0 < ?x; ?y < 0⟧ ⟹ variation ?x ?y = - 1› ‹⟦?x < 0; 0 < ?y⟧ ⟹ variation ?x ?y = 1› ‹⟦?x < 0; ?y < 0⟧ ⟹ variation ?x ?y = 0›*) mult_neg_pos[OF ‹c<0›,of x] (*‹0 < x ⟹ c * x < 0›*) mult_neg_neg[OF ‹c<0›,of x] (*‹x < 0 ⟹ 0 < c * x›*))[1]) (*goal: ‹(x::real) < (0::real) ⟹ variation ((c::real) * x) (y::real) = variation x y + (if y = (0::real) then 0::int else sign x)›*) apply (cases y rule:linorder_cases[of 0] (*‹⟦0 < ?y ⟹ ?P; 0 = ?y ⟹ ?P; ?y < 0 ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹⟦x < 0; y ≠ 0; 0 < y⟧ ⟹ variation (c * x) y = variation x y - 1› 2. ‹⟦x < 0; y ≠ 0; 0 = y⟧ ⟹ variation (c * x) y = variation x y - 1› 3. ‹⟦x < 0; y ≠ 0; y < 0⟧ ⟹ variation (c * x) y = variation x y - 1› discuss goal 1*) apply ((auto simp add: variation_cases (*‹⟦0 < ?x; 0 < ?y⟧ ⟹ variation ?x ?y = 0› ‹⟦0 < ?x; ?y < 0⟧ ⟹ variation ?x ?y = - 1› ‹⟦?x < 0; 0 < ?y⟧ ⟹ variation ?x ?y = 1› ‹⟦?x < 0; ?y < 0⟧ ⟹ variation ?x ?y = 0›*) mult_neg_pos[OF ‹c<0›,of x] (*‹0 < x ⟹ c * x < 0›*) mult_neg_neg[OF ‹c<0›,of x] (*‹x < 0 ⟹ 0 < c * x›*))[1]) (*discuss goal 2*) apply ((auto simp add: variation_cases (*‹⟦0 < ?x; 0 < ?y⟧ ⟹ variation ?x ?y = 0› ‹⟦0 < ?x; ?y < 0⟧ ⟹ variation ?x ?y = - 1› ‹⟦?x < 0; 0 < ?y⟧ ⟹ variation ?x ?y = 1› ‹⟦?x < 0; ?y < 0⟧ ⟹ variation ?x ?y = 0›*) mult_neg_pos[OF ‹c<0›,of x] (*‹0 < x ⟹ c * x < 0›*) mult_neg_neg[OF ‹c<0›,of x] (*‹x < 0 ⟹ 0 < c * x›*))[1]) (*discuss goal 3*) apply ((auto simp add: variation_cases (*‹⟦0 < ?x; 0 < ?y⟧ ⟹ variation ?x ?y = 0› ‹⟦0 < ?x; ?y < 0⟧ ⟹ variation ?x ?y = - 1› ‹⟦?x < 0; 0 < ?y⟧ ⟹ variation ?x ?y = 1› ‹⟦?x < 0; ?y < 0⟧ ⟹ variation ?x ?y = 0›*) mult_neg_pos[OF ‹c<0›,of x] (*‹0 < x ⟹ c * x < 0›*) mult_neg_neg[OF ‹c<0›,of x] (*‹x < 0 ⟹ 0 < c * x›*))[1]) (*proven 3 subgoals*) (*proven 3 subgoals*) . lemma variation_mult_neg_2: assumes "c<0" shows "variation x (c*y) = variation x y + (if x=0 then 0 else - sign y)" unfolding variation_comm[of x "c*y", unfolded variation_mult_neg_1 [ OF ‹c<0› , of y x ]] (*goal: ‹- (variation y x + (if x = 0 then 0 else sign y)) = variation x y + (if x = 0 then 0 else - sign y)›*) apply auto (*goal: ‹- (variation y x + (if x = 0 then 0 else sign y)) = variation x y + (if x = 0 then 0 else - sign y)›*) apply (subst variation_comm (*‹variation ?x ?y = - variation ?y ?x›*)) (*goal: ‹x ≠ 0 ⟹ - variation y x = variation x y›*) by simp lemma cross_no_root: assumes "a<b" and no_root:"∀x. a<x∧x<b ⟶ poly p x≠0" shows "cross p a b=0" proof (-) (*goal: ‹cross p a b = 0›*) have "⟦poly p a>0;poly p b<0⟧ ⟹ False" using poly_IVT_neg[OF ‹a<b›] (*‹⟦0 < poly ?p a; poly ?p b < 0⟧ ⟹ ∃x>a. x < b ∧ poly ?p x = 0›*) no_root (*‹∀x. a < x ∧ x < b ⟶ poly p x ≠ 0›*) by auto moreover have "⟦poly p a<0;poly p b>0⟧ ⟹ False" using poly_IVT_pos[OF ‹a<b›] (*‹⟦poly ?p a < 0; 0 < poly ?p b⟧ ⟹ ∃x>a. x < b ∧ poly ?p x = 0›*) no_root (*‹∀x. a < x ∧ x < b ⟶ poly p x ≠ 0›*) by auto ultimately have "0 ≤ poly p a * poly p b" by (metis less_eq_real_def (*‹((?x::real) ≤ (?y::real)) = (?x < ?y ∨ ?x = ?y)›*) linorder_neqE_linordered_idom (*‹⟦(?x::?'a::linordered_idom) ≠ (?y::?'a::linordered_idom); ?x < ?y ⟹ ?thesis::bool; ?y < ?x ⟹ ?thesis⟧ ⟹ ?thesis›*) mult_less_0_iff (*‹((?a::?'a::linordered_ring_strict) * (?b::?'a::linordered_ring_strict) < (0::?'a::linordered_ring_strict)) = ((0::?'a::linordered_ring_strict) < ?a ∧ ?b < (0::?'a::linordered_ring_strict) ∨ ?a < (0::?'a::linordered_ring_strict) ∧ (0::?'a::linordered_ring_strict) < ?b)›*)) thus "?thesis" (*goal: ‹cross p a b = 0›*) unfolding cross_def variation_def (*goal: ‹(if (0::real) ≤ poly (p::real poly) (a::real) * poly p (b::real) then 0::int else if poly p a < poly p b then 1::int else - (1::int)) = (0::int)›*) by simp qed subsection ‹Tarski query› definition taq :: "'a::linordered_idom set ⇒ 'a poly ⇒ int" where "taq s q ≡ ∑x∈s. sign (poly q x)" subsection ‹Sign at the right› definition sign_r_pos :: "real poly ⇒ real ⇒ bool " where "sign_r_pos p x≡ (eventually (λx. poly p x>0) (at_right x))" lemma sign_r_pos_rec: fixes p:: "real poly" assumes "p≠0" shows "sign_r_pos p x= (if poly p x=0 then sign_r_pos (pderiv p) x else poly p x>0 )" proof (cases "poly p x=0") (*goals: 1. ‹poly p x = 0 ⟹ sign_r_pos p x = (if poly p x = 0 then sign_r_pos (pderiv p) x else 0 < poly p x)› 2. ‹poly p x ≠ 0 ⟹ sign_r_pos p x = (if poly p x = 0 then sign_r_pos (pderiv p) x else 0 < poly p x)›*) case True (*‹poly p x = 0›*) have "sign_r_pos (pderiv p) x ⟹ sign_r_pos p x" proof (rule ccontr (*‹(¬ (?P::bool) ⟹ False) ⟹ ?P›*)) (*goal: ‹⟦sign_r_pos (pderiv p) x; ¬ sign_r_pos p x⟧ ⟹ False›*) assume "sign_r_pos (pderiv p) x" "¬ sign_r_pos p x" (*‹sign_r_pos (pderiv (p::real poly)) (x::real)› ‹¬ sign_r_pos (p::real poly) (x::real)›*) obtain b where "b>x" and b: "∀z. x < z ∧ z < b ⟶ 0 < poly (pderiv p) z" (*goal: ‹(⋀b. ⟦x < b; ∀z. x < z ∧ z < b ⟶ 0 < poly (pderiv p) z⟧ ⟹ thesis) ⟹ thesis›*) using ‹sign_r_pos (pderiv p) x› (*‹sign_r_pos (pderiv (p::real poly)) (x::real)›*) unfolding sign_r_pos_def eventually_at_right (*goal: ‹(⋀b. ⟦x < b; ∀z. x < z ∧ z < b ⟶ 0 < poly (pderiv p) z⟧ ⟹ thesis) ⟹ thesis›*) by auto have "∀b>x. ∃z>x. z < b ∧ ¬ 0 < poly p z" using ‹¬ sign_r_pos p x› (*‹¬ sign_r_pos p x›*) unfolding sign_r_pos_def eventually_at_right (*goal: ‹∀b>x. ∃z>x. z < b ∧ ¬ 0 < poly p z›*) by auto then obtain z where "z>x" and "z<b" and "poly p z≤0" (*goal: ‹(⋀z. ⟦x < z; z < b; poly p z ≤ 0⟧ ⟹ thesis) ⟹ thesis›*) using ‹b>x› (*‹x < b›*) b (*‹∀z. x < z ∧ z < b ⟶ 0 < poly (pderiv p) z›*) by auto hence "∃z'>x. z' < z ∧ poly p z = (z - x) * poly (pderiv p) z'" using poly_MVT[OF ‹z>x›] (*‹∃xa>x. xa < z ∧ poly ?p z - poly ?p x = (z - x) * poly (pderiv ?p) xa›*) True (*‹poly p x = 0›*) by (metis diff_0_right (*‹(?a::?'a) - (0::?'a) = ?a›*)) hence "∃z'>x. z' < z ∧ poly (pderiv p) z' ≤0" using ‹poly p z≤0› (*‹poly (p::real poly) (z::real) ≤ (0::real)›*) ‹z>x› (*‹x < z›*) by (metis leD (*‹?y ≤ ?x ⟹ ¬ ?x < ?y›*) le_iff_diff_le_0 (*‹(?a ≤ ?b) = (?a - ?b ≤ 0)›*) mult_le_0_iff (*‹(?a * ?b ≤ 0) = (0 ≤ ?a ∧ ?b ≤ 0 ∨ ?a ≤ 0 ∧ 0 ≤ ?b)›*)) thus False using b (*‹∀z::real. (x::real) < z ∧ z < (b::real) ⟶ (0::real) < poly (pderiv (p::real poly)) z›*) by (metis ‹z < b› dual_order.strict_trans (*‹⟦?b < ?a; ?c < ?b⟧ ⟹ ?c < ?a›*) not_le (*‹(¬ ?x ≤ ?y) = (?y < ?x)›*)) qed moreover have "sign_r_pos p x ⟹ sign_r_pos (pderiv p) x" proof (-) (*goal: ‹sign_r_pos p x ⟹ sign_r_pos (pderiv p) x›*) assume "sign_r_pos p x" (*‹sign_r_pos (p::real poly) (x::real)›*) have "pderiv p≠0" using ‹poly p x=0› (*‹poly p x = 0›*) ‹p≠0› (*‹p ≠ 0›*) by (metis monoid_add_class.add.right_neutral (*‹?a + 0 = ?a›*) monom_0 (*‹monom ?a 0 = [:?a:]›*) monom_eq_0 (*‹monom 0 ?n = 0›*) mult_zero_right (*‹?a * 0 = 0›*) pderiv_iszero (*‹pderiv ?p = 0 ⟹ ∃h. ?p = [:h:]›*) poly_0 (*‹poly 0 ?x = 0›*) poly_pCons (*‹poly (pCons ?a ?p) ?x = ?a + ?x * poly ?p ?x›*)) obtain ub where "ub>x" and ub: "(∀z. x<z∧z<ub⟶poly (pderiv p) z>0) ∨ (∀z. x<z∧z<ub⟶poly (pderiv p) z<0)" (*goal: ‹(⋀ub::real. ⟦(x::real) < ub; (∀z::real. x < z ∧ z < ub ⟶ (0::real) < poly (pderiv (p::real poly)) z) ∨ (∀z::real. x < z ∧ z < ub ⟶ poly (pderiv p) z < (0::real))⟧ ⟹ thesis::bool) ⟹ thesis›*) using next_non_root_interval[OF ‹pderiv p≠0›, of x, unfolded not_eq_pos_or_neg_iff_1] (*‹(⋀ub. ⟦x < ub; (∀z. x < z ∧ z ≤ ub ⟶ 0 < poly (pderiv p) z) ∨ (∀z. x < z ∧ z ≤ ub ⟶ poly (pderiv p) z < 0)⟧ ⟹ ?thesis) ⟹ ?thesis›*) by (metis order.strict_implies_order (*‹?a < ?b ⟹ ?a ≤ ?b›*)) have "∀z. x<z∧z<ub⟶poly (pderiv p) z<0 ⟹ False" proof (-) (*goal: ‹∀z. x < z ∧ z < ub ⟶ poly (pderiv p) z < 0 ⟹ False›*) assume assm: "∀z. x<z∧z<ub⟶poly (pderiv p) z<0" (*‹∀z::real. (x::real) < z ∧ z < (ub::real) ⟶ poly (pderiv (p::real poly)) z < (0::real)›*) obtain ub' where "ub'>x" and ub': "∀z. x < z ∧ z < ub' ⟶ 0 < poly p z" (*goal: ‹(⋀ub'. ⟦x < ub'; ∀z. x < z ∧ z < ub' ⟶ 0 < poly p z⟧ ⟹ thesis) ⟹ thesis›*) using ‹sign_r_pos p x› (*‹sign_r_pos p x›*) unfolding sign_r_pos_def eventually_at_right (*goal: ‹(⋀ub'. ⟦x < ub'; ∀z. x < z ∧ z < ub' ⟶ 0 < poly p z⟧ ⟹ thesis) ⟹ thesis›*) by auto obtain z' where "x<z'" and "z' < (x+(min ub' ub))/2" and z': "poly p ((x+min ub' ub)/2) = ((x+min ub' ub)/2 - x) * poly (pderiv p) z'" (*goal: ‹(⋀z'. ⟦x < z'; z' < (x + min ub' ub) / 2; poly p ((x + min ub' ub) / 2) = ((x + min ub' ub) / 2 - x) * poly (pderiv p) z'⟧ ⟹ thesis) ⟹ thesis›*) using poly_MVT[of x "(x+min ub' ub)/2" p] (*‹x < (x + min ub' ub) / 2 ⟹ ∃xa>x. xa < (x + min ub' ub) / 2 ∧ poly p ((x + min ub' ub) / 2) - poly p x = ((x + min ub' ub) / 2 - x) * poly (pderiv p) xa›*) ‹ub'>x› (*‹x < ub'›*) ‹ub>x› (*‹x < ub›*) True (*‹poly p x = 0›*) by auto moreover have "0 < poly p ((x+min ub' ub)/2)" using ub'[THEN HOL.spec, of "(x+(min ub' ub))/2"] (*‹x < (x + min ub' ub) / 2 ∧ (x + min ub' ub) / 2 < ub' ⟶ 0 < poly p ((x + min ub' ub) / 2)›*) ‹z' < (x+min ub' ub)/2› (*‹z' < (x + min ub' ub) / 2›*) ‹x<z'› (*‹x < z'›*) by auto moreover have "(x+min ub' ub)/2 - x>0" using ‹ub'>x› (*‹x < ub'›*) ‹ub>x› (*‹x < ub›*) by auto ultimately have "poly (pderiv p) z'>0" by (metis zero_less_mult_pos (*‹⟦0 < ?a * ?b; 0 < ?a⟧ ⟹ 0 < ?b›*)) thus False using assm[THEN spec, of z'] (*‹x < z' ∧ z' < ub ⟶ poly (pderiv p) z' < 0›*) ‹x<z'› (*‹x < z'›*) ‹z' < (x+(min ub' ub))/2› (*‹z' < (x + min ub' ub) / 2›*) by auto qed hence "∀z. x<z∧z<ub⟶poly (pderiv p) z>0" using ub (*‹(∀z. x < z ∧ z < ub ⟶ 0 < poly (pderiv p) z) ∨ (∀z. x < z ∧ z < ub ⟶ poly (pderiv p) z < 0)›*) by auto thus "sign_r_pos (pderiv p) x" unfolding sign_r_pos_def eventually_at_right (*goal: ‹∃b>x. ∀y>x. y < b ⟶ 0 < poly (pderiv p) y›*) using ‹ub>x› (*‹x < ub›*) by auto qed ultimately show "?thesis" (*goal: ‹sign_r_pos p x = (if poly p x = 0 then sign_r_pos (pderiv p) x else 0 < poly p x)›*) using True (*‹poly p x = 0›*) by auto next (*goal: ‹poly p x ≠ 0 ⟹ sign_r_pos p x = (if poly p x = 0 then sign_r_pos (pderiv p) x else 0 < poly p x)›*) case False (*‹poly p x ≠ 0›*) have "sign_r_pos p x ⟹ poly p x>0" proof (rule ccontr (*‹(¬ (?P::bool) ⟹ False) ⟹ ?P›*)) (*goal: ‹⟦sign_r_pos p x; ¬ 0 < poly p x⟧ ⟹ False›*) assume "sign_r_pos p x" "¬ 0 < poly p x" (*‹sign_r_pos (p::real poly) (x::real)› ‹¬ (0::real) < poly (p::real poly) (x::real)›*) then obtain ub where "ub>x" and ub: "∀z. x < z ∧ z < ub ⟶ 0 < poly p z" (*goal: ‹(⋀ub. ⟦x < ub; ∀z. x < z ∧ z < ub ⟶ 0 < poly p z⟧ ⟹ thesis) ⟹ thesis›*) unfolding sign_r_pos_def eventually_at_right (*goal: ‹(⋀ub. ⟦x < ub; ∀z. x < z ∧ z < ub ⟶ 0 < poly p z⟧ ⟹ thesis) ⟹ thesis›*) by auto hence "poly p ((ub+x)/2) > 0" by auto moreover have "poly p x<0" using ‹¬ 0 < poly p x› (*‹¬ 0 < poly p x›*) False (*‹poly p x ≠ 0›*) by auto ultimately have "∃z>x. z < (ub + x) / 2 ∧ poly p z = 0" using poly_IVT_pos[of x "((ub + x) / 2)" p] (*‹⟦x < (ub + x) / 2; poly p x < 0; 0 < poly p ((ub + x) / 2)⟧ ⟹ ∃xa>x. xa < (ub + x) / 2 ∧ poly p xa = 0›*) ‹ub>x› (*‹x < ub›*) by auto thus False using ub (*‹∀z. x < z ∧ z < ub ⟶ 0 < poly p z›*) by auto qed moreover have "poly p x>0 ⟹ sign_r_pos p x" unfolding sign_r_pos_def (*goal: ‹0 < poly p x ⟹ ∀⇩F x in at_right x. 0 < poly p x›*) using order_tendstoD(1)[OF poly_tendsto ( 1 ), of 0 p x] (*‹0 < poly p x ⟹ ∀⇩F x in at x. 0 < poly p x›*) eventually_at_split (*‹eventually ?P (at ?x) = (eventually ?P (at_left ?x) ∧ eventually ?P (at_right ?x))›*) by auto ultimately show "?thesis" (*goal: ‹sign_r_pos p x = (if poly p x = 0 then sign_r_pos (pderiv p) x else 0 < poly p x)›*) using False (*‹poly p x ≠ 0›*) by auto qed lemma sign_r_pos_0[simp]:"¬ sign_r_pos 0 (x::real)" using eventually_False[of "at_right x"] (*‹(∀⇩F x in at_right x. False) = (at_right x = bot)›*) unfolding sign_r_pos_def (*goal: ‹¬ (∀⇩F x in at_right x. 0 < poly 0 x)›*) by auto lemma sign_r_pos_minus: fixes p:: "real poly" assumes "p≠0" shows "sign_r_pos p x = (¬ sign_r_pos (-p) x)" sorry lemma sign_r_pos_smult: fixes p :: "real poly" assumes "c≠0" "p≠0" shows "sign_r_pos (smult c p) x= (if c>0 then sign_r_pos p x else ¬ sign_r_pos p x)" (is "?L=?R") proof (cases "c>0") (*goals: 1. ‹(0::real) < (c::real) ⟹ sign_r_pos (smult c (p::real poly)) (x::real) = (if (0::real) < c then sign_r_pos p x else ¬ sign_r_pos p x)› 2. ‹¬ (0::real) < (c::real) ⟹ sign_r_pos (smult c (p::real poly)) (x::real) = (if (0::real) < c then sign_r_pos p x else ¬ sign_r_pos p x)›*) assume "c>0" (*‹(0::real) < (c::real)›*) hence "∀x. (0 < poly (smult c p) x) = (0 < poly p x)" apply (subst poly_smult (*‹poly (smult ?a ?p) ?x = ?a * poly ?p ?x›*)) (*goal: ‹∀x. (0 < poly (smult c p) x) = (0 < poly p x)›*) by (metis mult_pos_pos (*‹⟦0 < ?a; 0 < ?b⟧ ⟹ 0 < ?a * ?b›*) zero_less_mult_pos (*‹⟦0 < ?a * ?b; 0 < ?a⟧ ⟹ 0 < ?b›*)) thus "?thesis" (*goal: ‹sign_r_pos (smult (c::real) (p::real poly)) (x::real) = (if (0::real) < c then sign_r_pos p x else ¬ sign_r_pos p x)›*) unfolding sign_r_pos_def (*goal: ‹(∀⇩F x in at_right x. 0 < poly (smult c p) x) = (if 0 < c then ∀⇩F x in at_right x. 0 < poly p x else ¬ (∀⇩F x in at_right x. 0 < poly p x))›*) using ‹c>0› (*‹0 < c›*) by auto next (*goal: ‹¬ 0 < c ⟹ sign_r_pos (smult c p) x = (if 0 < c then sign_r_pos p x else ¬ sign_r_pos p x)›*) assume "¬(c>0)" (*‹¬ (0::real) < (c::real)›*) hence "∀x. (0 < poly (smult c p) x) = (0 < poly (-p) x)" apply (subst poly_smult (*‹poly (smult ?a ?p) ?x = ?a * poly ?p ?x›*)) (*goal: ‹∀x. (0 < poly (smult c p) x) = (0 < poly (- p) x)›*) by (metis assms( (*‹c ≠ 0›*) 1) linorder_neqE_linordered_idom (*‹⟦?x ≠ ?y; ?x < ?y ⟹ ?thesis; ?y < ?x ⟹ ?thesis⟧ ⟹ ?thesis›*) mult_neg_neg (*‹⟦?a < 0; ?b < 0⟧ ⟹ 0 < ?a * ?b›*) mult_zero_right (*‹?a * 0 = 0›*) neg_0_less_iff_less (*‹(0 < - ?a) = (?a < 0)›*) poly_minus (*‹poly (- ?p) ?x = - poly ?p ?x›*) zero_less_mult_pos2 (*‹⟦0 < ?b * ?a; 0 < ?a⟧ ⟹ 0 < ?b›*)) hence "sign_r_pos (smult c p) x=sign_r_pos (-p) x" unfolding sign_r_pos_def (*goal: ‹(∀⇩F x::real in at_right (x::real). (0::real) < poly (smult (c::real) (p::real poly)) x) = (∀⇩F x::real in at_right x. (0::real) < poly (- p) x)›*) using ‹¬ c>0› (*‹¬ 0 < c›*) by auto thus "?thesis" (*goal: ‹sign_r_pos (smult c p) x = (if 0 < c then sign_r_pos p x else ¬ sign_r_pos p x)›*) using sign_r_pos_minus[OF ‹p≠0›, of x] (*‹sign_r_pos p x = (¬ sign_r_pos (- p) x)›*) ‹¬ c>0› (*‹¬ 0 < c›*) by auto qed lemma sign_r_pos_mult: fixes p q :: "real poly" assumes "p≠0" "q≠0" shows "sign_r_pos (p*q) x= (sign_r_pos p x ⟷ sign_r_pos q x)" proof (-) (*goal: ‹sign_r_pos (p * q) x = (sign_r_pos p x = sign_r_pos q x)›*) obtain ub where "ub>x" and ub: "(∀z. x < z ∧ z < ub ⟶ 0 < poly p z) ∨ (∀z. x < z ∧ z < ub ⟶ poly p z < 0)" (*goal: ‹(⋀ub. ⟦x < ub; (∀z. x < z ∧ z < ub ⟶ 0 < poly p z) ∨ (∀z. x < z ∧ z < ub ⟶ poly p z < 0)⟧ ⟹ thesis) ⟹ thesis›*) using next_non_root_interval[OF ‹p≠0›, of x, unfolded not_eq_pos_or_neg_iff_1] (*‹(⋀ub. ⟦x < ub; (∀z. x < z ∧ z ≤ ub ⟶ 0 < poly p z) ∨ (∀z. x < z ∧ z ≤ ub ⟶ poly p z < 0)⟧ ⟹ ?thesis) ⟹ ?thesis›*) by (metis order.strict_implies_order (*‹?a < ?b ⟹ ?a ≤ ?b›*)) obtain ub' where "ub'>x" and ub': "(∀z. x < z ∧ z < ub' ⟶ 0 < poly q z) ∨ (∀z. x < z ∧ z < ub' ⟶ poly q z < 0)" (*goal: ‹(⋀ub'. ⟦x < ub'; (∀z. x < z ∧ z < ub' ⟶ 0 < poly q z) ∨ (∀z. x < z ∧ z < ub' ⟶ poly q z < 0)⟧ ⟹ thesis) ⟹ thesis›*) using next_non_root_interval[OF ‹q≠0›, unfolded not_eq_pos_or_neg_iff_1] (*‹(⋀ub. ⟦?lb < ub; (∀z. ?lb < z ∧ z ≤ ub ⟶ 0 < poly q z) ∨ (∀z. ?lb < z ∧ z ≤ ub ⟶ poly q z < 0)⟧ ⟹ ?thesis) ⟹ ?thesis›*) by (metis order.strict_implies_order (*‹?a < ?b ⟹ ?a ≤ ?b›*)) have "(∀z. x < z ∧ z < ub ⟶ 0 < poly p z) ⟹ (∀z. x < z ∧ z < ub' ⟶ 0 < poly q z) ⟹ ?thesis" proof (-) (*goal: ‹⟦∀z. x < z ∧ z < ub ⟶ 0 < poly p z; ∀z. x < z ∧ z < ub' ⟶ 0 < poly q z⟧ ⟹ sign_r_pos (p * q) x = (sign_r_pos p x = sign_r_pos q x)›*) assume "(∀z. x < z ∧ z < ub ⟶ 0 < poly p z)" "(∀z. x < z ∧ z < ub' ⟶ 0 < poly q z)" (*‹∀z::real. (x::real) < z ∧ z < (ub::real) ⟶ (0::real) < poly (p::real poly) z› ‹∀z::real. (x::real) < z ∧ z < (ub'::real) ⟶ (0::real) < poly (q::real poly) z›*) hence "sign_r_pos p x" and "sign_r_pos q x" unfolding sign_r_pos_def eventually_at_right (*goals: 1. ‹∃b>x::real. ∀y>x. y < b ⟶ (0::real) < poly (p::real poly) y› 2. ‹∃b>x::real. ∀y>x. y < b ⟶ (0::real) < poly (q::real poly) y›*) using ‹ub>x› (*‹x < ub›*) ‹ub'>x› (*‹(x::real) < (ub'::real)›*) apply - (*goals: 1. ‹⟦∀z. x < z ∧ z < ub ⟶ 0 < poly p z; ∀z. x < z ∧ z < ub' ⟶ 0 < poly q z; x < ub; x < ub'⟧ ⟹ ∃b>x. ∀y>x. y < b ⟶ 0 < poly p y› 2. ‹⟦∀z. x < z ∧ z < ub ⟶ 0 < poly p z; ∀z. x < z ∧ z < ub' ⟶ 0 < poly q z; x < ub; x < ub'⟧ ⟹ ∃b>x. ∀y>x. y < b ⟶ 0 < poly q y› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . moreover hence "eventually (λz. poly p z>0 ∧ poly q z>0) (at_right x)" unfolding sign_r_pos_def (*goal: ‹∀⇩F z in at_right x. 0 < poly p z ∧ 0 < poly q z›*) using eventually_conj_iff[of _ _ "at_right x"] (*‹(∀⇩F x in at_right x. ?P x ∧ ?Q x) = (eventually ?P (at_right x) ∧ eventually ?Q (at_right x))›*) by auto hence "sign_r_pos (p*q) x" unfolding sign_r_pos_def poly_mult (*goal: ‹∀⇩F x::real in at_right (x::real). (0::real) < poly (p::real poly) x * poly (q::real poly) x›*) by (metis (lifting, mono_tags) eventually_mono (*‹⟦eventually (?P::?'a ⇒ bool) (?F::?'a filter); ⋀x::?'a. ?P x ⟹ (?Q::?'a ⇒ bool) x⟧ ⟹ eventually ?Q ?F›*) mult_pos_pos (*‹⟦(0::?'a) < (?a::?'a); (0::?'a) < (?b::?'a)⟧ ⟹ (0::?'a) < ?a * ?b›*)) ultimately show "?thesis" (*goal: ‹sign_r_pos (p * q) x = (sign_r_pos p x = sign_r_pos q x)›*) by auto qed moreover have "(∀z. x < z ∧ z < ub ⟶ 0 > poly p z) ⟹ (∀z. x < z ∧ z < ub' ⟶ 0 < poly q z) ⟹ ?thesis" proof (-) (*goal: ‹⟦∀z::real. (x::real) < z ∧ z < (ub::real) ⟶ poly (p::real poly) z < (0::real); ∀z::real. x < z ∧ z < (ub'::real) ⟶ (0::real) < poly (q::real poly) z⟧ ⟹ sign_r_pos (p * q) x = (sign_r_pos p x = sign_r_pos q x)›*) assume "(∀z. x < z ∧ z < ub ⟶ 0 > poly p z)" "(∀z. x < z ∧ z < ub' ⟶ 0 < poly q z)" (*‹∀z::real. (x::real) < z ∧ z < (ub::real) ⟶ poly (p::real poly) z < (0::real)› ‹∀z::real. (x::real) < z ∧ z < (ub'::real) ⟶ (0::real) < poly (q::real poly) z›*) hence "sign_r_pos (-p) x" and "sign_r_pos q x" unfolding sign_r_pos_def eventually_at_right (*goals: 1. ‹∃b>x. ∀y>x. y < b ⟶ 0 < poly (- p) y› 2. ‹∃b>x. ∀y>x. y < b ⟶ 0 < poly q y›*) using ‹ub>x› (*‹x < ub›*) ‹ub'>x› (*‹x < ub'›*) apply - (*goals: 1. ‹⟦∀z. x < z ∧ z < ub ⟶ poly p z < 0; ∀z. x < z ∧ z < ub' ⟶ 0 < poly q z; x < ub; x < ub'⟧ ⟹ ∃b>x. ∀y>x. y < b ⟶ 0 < poly (- p) y› 2. ‹⟦∀z. x < z ∧ z < ub ⟶ poly p z < 0; ∀z. x < z ∧ z < ub' ⟶ 0 < poly q z; x < ub; x < ub'⟧ ⟹ ∃b>x. ∀y>x. y < b ⟶ 0 < poly q y› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . moreover hence "eventually (λz. poly (-p) z>0 ∧ poly q z>0) (at_right x)" unfolding sign_r_pos_def (*goal: ‹∀⇩F z in at_right x. 0 < poly (- p) z ∧ 0 < poly q z›*) using eventually_conj_iff[of _ _ "at_right x"] (*‹(∀⇩F x in at_right x. ?P x ∧ ?Q x) = (eventually ?P (at_right x) ∧ eventually ?Q (at_right x))›*) by auto hence "sign_r_pos (- p*q) x" unfolding sign_r_pos_def poly_mult (*goal: ‹∀⇩F x in at_right x. 0 < poly (- p) x * poly q x›*) by (metis (lifting, mono_tags) eventually_mono (*‹⟦eventually (?P::?'a::type ⇒ bool) (?F::?'a::type filter); ⋀x::?'a::type. ?P x ⟹ (?Q::?'a::type ⇒ bool) x⟧ ⟹ eventually ?Q ?F›*) mult_pos_pos (*‹⟦(0::?'a::linordered_semiring_strict) < (?a::?'a::linordered_semiring_strict); (0::?'a::linordered_semiring_strict) < (?b::?'a::linordered_semiring_strict)⟧ ⟹ (0::?'a::linordered_semiring_strict) < ?a * ?b›*)) ultimately show "?thesis" (*goal: ‹sign_r_pos (p * q) x = (sign_r_pos p x = sign_r_pos q x)›*) using sign_r_pos_minus (*‹?p ≠ 0 ⟹ sign_r_pos ?p ?x = (¬ sign_r_pos (- ?p) ?x)›*) ‹p≠0› (*‹p ≠ 0›*) ‹q≠0› (*‹q ≠ 0›*) by (metis minus_mult_left (*‹- (?a * ?b) = - ?a * ?b›*) no_zero_divisors (*‹⟦?a ≠ 0; ?b ≠ 0⟧ ⟹ ?a * ?b ≠ 0›*)) qed moreover have "(∀z. x < z ∧ z < ub ⟶ 0 < poly p z) ⟹ (∀z. x < z ∧ z < ub' ⟶ 0 > poly q z) ⟹ ?thesis" proof (-) (*goal: ‹⟦∀z. x < z ∧ z < ub ⟶ 0 < poly p z; ∀z. x < z ∧ z < ub' ⟶ poly q z < 0⟧ ⟹ sign_r_pos (p * q) x = (sign_r_pos p x = sign_r_pos q x)›*) assume "(∀z. x < z ∧ z < ub ⟶ 0 < poly p z)" "(∀z. x < z ∧ z < ub' ⟶ 0 > poly q z)" (*‹∀z::real. (x::real) < z ∧ z < (ub::real) ⟶ (0::real) < poly (p::real poly) z› ‹∀z::real. (x::real) < z ∧ z < (ub'::real) ⟶ poly (q::real poly) z < (0::real)›*) hence "sign_r_pos p x" and "sign_r_pos (-q) x" unfolding sign_r_pos_def eventually_at_right (*goals: 1. ‹∃b>x. ∀y>x. y < b ⟶ 0 < poly p y› 2. ‹∃b>x. ∀y>x. y < b ⟶ 0 < poly (- q) y›*) using ‹ub>x› (*‹x < ub›*) ‹ub'>x› (*‹x < ub'›*) apply - (*goals: 1. ‹⟦∀z::real. (x::real) < z ∧ z < (ub::real) ⟶ (0::real) < poly (p::real poly) z; ∀z::real. x < z ∧ z < (ub'::real) ⟶ poly (q::real poly) z < (0::real); x < ub; x < ub'⟧ ⟹ ∃b>x. ∀y>x. y < b ⟶ (0::real) < poly p y› 2. ‹⟦∀z::real. (x::real) < z ∧ z < (ub::real) ⟶ (0::real) < poly (p::real poly) z; ∀z::real. x < z ∧ z < (ub'::real) ⟶ poly (q::real poly) z < (0::real); x < ub; x < ub'⟧ ⟹ ∃b>x. ∀y>x. y < b ⟶ (0::real) < poly (- q) y› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . moreover hence "eventually (λz. poly p z>0 ∧ poly (-q) z>0) (at_right x)" unfolding sign_r_pos_def (*goal: ‹∀⇩F z in at_right x. 0 < poly p z ∧ 0 < poly (- q) z›*) using eventually_conj_iff[of _ _ "at_right x"] (*‹(∀⇩F x in at_right x. ?P x ∧ ?Q x) = (eventually ?P (at_right x) ∧ eventually ?Q (at_right x))›*) by auto hence "sign_r_pos ( p * (- q)) x" unfolding sign_r_pos_def poly_mult (*goal: ‹∀⇩F x in at_right x. 0 < poly p x * poly (- q) x›*) by (metis (lifting, mono_tags) eventually_mono (*‹⟦eventually ?P ?F; ⋀x. ?P x ⟹ ?Q x⟧ ⟹ eventually ?Q ?F›*) mult_pos_pos (*‹⟦0 < ?a; 0 < ?b⟧ ⟹ 0 < ?a * ?b›*)) ultimately show "?thesis" (*goal: ‹sign_r_pos ((p::real poly) * (q::real poly)) (x::real) = (sign_r_pos p x = sign_r_pos q x)›*) using sign_r_pos_minus (*‹?p ≠ 0 ⟹ sign_r_pos ?p ?x = (¬ sign_r_pos (- ?p) ?x)›*) ‹p≠0› (*‹p ≠ 0›*) ‹q≠0› (*‹(q::real poly) ≠ (0::real poly)›*) by (metis minus_mult_right (*‹- (?a * ?b) = ?a * - ?b›*) no_zero_divisors (*‹⟦?a ≠ 0; ?b ≠ 0⟧ ⟹ ?a * ?b ≠ 0›*)) qed moreover have "(∀z. x < z ∧ z < ub ⟶ 0 > poly p z) ⟹ (∀z. x < z ∧ z < ub' ⟶ 0 > poly q z) ⟹ ?thesis" proof (-) (*goal: ‹⟦∀z. x < z ∧ z < ub ⟶ poly p z < 0; ∀z. x < z ∧ z < ub' ⟶ poly q z < 0⟧ ⟹ sign_r_pos (p * q) x = (sign_r_pos p x = sign_r_pos q x)›*) assume "(∀z. x < z ∧ z < ub ⟶ 0 > poly p z)" "(∀z. x < z ∧ z < ub' ⟶ 0 > poly q z)" (*‹∀z::real. (x::real) < z ∧ z < (ub::real) ⟶ poly (p::real poly) z < (0::real)› ‹∀z::real. (x::real) < z ∧ z < (ub'::real) ⟶ poly (q::real poly) z < (0::real)›*) hence "sign_r_pos (-p) x" and "sign_r_pos (-q) x" unfolding sign_r_pos_def eventually_at_right (*goals: 1. ‹∃b>x::real. ∀y>x. y < b ⟶ (0::real) < poly (- (p::real poly)) y› 2. ‹∃b>x::real. ∀y>x. y < b ⟶ (0::real) < poly (- (q::real poly)) y›*) using ‹ub>x› (*‹x < ub›*) ‹ub'>x› (*‹x < ub'›*) apply - (*goals: 1. ‹⟦∀z. x < z ∧ z < ub ⟶ poly p z < 0; ∀z. x < z ∧ z < ub' ⟶ poly q z < 0; x < ub; x < ub'⟧ ⟹ ∃b>x. ∀y>x. y < b ⟶ 0 < poly (- p) y› 2. ‹⟦∀z. x < z ∧ z < ub ⟶ poly p z < 0; ∀z. x < z ∧ z < ub' ⟶ poly q z < 0; x < ub; x < ub'⟧ ⟹ ∃b>x. ∀y>x. y < b ⟶ 0 < poly (- q) y› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . moreover hence "eventually (λz. poly (-p) z>0 ∧ poly (-q) z>0) (at_right x)" unfolding sign_r_pos_def (*goal: ‹∀⇩F z in at_right x. 0 < poly (- p) z ∧ 0 < poly (- q) z›*) using eventually_conj_iff[of _ _ "at_right x"] (*‹(∀⇩F x in at_right x. ?P x ∧ ?Q x) = (eventually ?P (at_right x) ∧ eventually ?Q (at_right x))›*) by auto hence "sign_r_pos (p * q) x" unfolding sign_r_pos_def poly_mult poly_minus (*goal: ‹∀⇩F x in at_right x. 0 < poly p x * poly q x›*) apply (elim eventually_mono[of _ "at_right x"] (*‹⟦eventually (?P::real ⇒ bool) (at_right (x::real)); ⋀x::real. ?P x ⟹ (?Q::real ⇒ bool) x⟧ ⟹ eventually ?Q (at_right x)›*)) (*goal: ‹∀⇩F x in at_right x. 0 < poly p x * poly q x›*) by (auto intro:mult_neg_neg (*‹⟦(?a::?'a) < (0::?'a); (?b::?'a) < (0::?'a)⟧ ⟹ (0::?'a) < ?a * ?b›*)) ultimately show "?thesis" (*goal: ‹sign_r_pos (p * q) x = (sign_r_pos p x = sign_r_pos q x)›*) using sign_r_pos_minus (*‹?p ≠ 0 ⟹ sign_r_pos ?p ?x = (¬ sign_r_pos (- ?p) ?x)›*) ‹p≠0› (*‹p ≠ 0›*) ‹q≠0› (*‹q ≠ 0›*) by metis qed ultimately show "?thesis" (*goal: ‹sign_r_pos ((p::real poly) * (q::real poly)) (x::real) = (sign_r_pos p x = sign_r_pos q x)›*) using ub (*‹(∀z. x < z ∧ z < ub ⟶ 0 < poly p z) ∨ (∀z. x < z ∧ z < ub ⟶ poly p z < 0)›*) ub' (*‹(∀z. x < z ∧ z < ub' ⟶ 0 < poly q z) ∨ (∀z. x < z ∧ z < ub' ⟶ poly q z < 0)›*) by auto qed lemma sign_r_pos_add: fixes p q :: "real poly" assumes "poly p x=0" "poly q x≠0" shows "sign_r_pos (p+q) x=sign_r_pos q x" proof (cases "poly (p+q) x=0") (*goals: 1. ‹poly ((p::real poly) + (q::real poly)) (x::real) = (0::real) ⟹ sign_r_pos (p + q) x = sign_r_pos q x› 2. ‹poly ((p::real poly) + (q::real poly)) (x::real) ≠ (0::real) ⟹ sign_r_pos (p + q) x = sign_r_pos q x›*) case False (*‹poly (p + q) x ≠ 0›*) hence "p+q≠0" by (metis poly_0 (*‹poly (0::?'a poly) (?x::?'a) = (0::?'a)›*)) have "sign_r_pos (p+q) x = (poly q x > 0)" using sign_r_pos_rec[OF ‹p+q≠0›] (*‹sign_r_pos (p + q) ?x = (if poly (p + q) ?x = 0 then sign_r_pos (pderiv (p + q)) ?x else 0 < poly (p + q) ?x)›*) False (*‹poly (p + q) x ≠ 0›*) poly_add (*‹poly ((?p::?'a::comm_semiring_0 poly) + (?q::?'a::comm_semiring_0 poly)) (?x::?'a::comm_semiring_0) = poly ?p ?x + poly ?q ?x›*) ‹poly p x=0› (*‹poly (p::real poly) (x::real) = (0::real)›*) by auto moreover have "sign_r_pos q x=(poly q x > 0)" using sign_r_pos_rec[of q x] (*‹q ≠ 0 ⟹ sign_r_pos q x = (if poly q x = 0 then sign_r_pos (pderiv q) x else 0 < poly q x)›*) ‹poly q x≠0› (*‹poly q x ≠ 0›*) poly_0 (*‹poly 0 ?x = 0›*) by force ultimately show "?thesis" (*goal: ‹sign_r_pos (p + q) x = sign_r_pos q x›*) by auto next (*goal: ‹poly (p + q) x = 0 ⟹ sign_r_pos (p + q) x = sign_r_pos q x›*) case True (*‹poly (p + q) x = 0›*) hence False using ‹poly p x=0› (*‹poly p x = 0›*) ‹poly q x≠0› (*‹poly q x ≠ 0›*) poly_add (*‹poly (?p + ?q) ?x = poly ?p ?x + poly ?q ?x›*) by auto thus "?thesis" (*goal: ‹sign_r_pos (p + q) x = sign_r_pos q x›*) by auto qed lemma sign_r_pos_mod: fixes p q :: "real poly" assumes "poly p x=0" "poly q x≠0" shows "sign_r_pos (q mod p) x=sign_r_pos q x" proof (-) (*goal: ‹sign_r_pos ((q::real poly) mod (p::real poly)) (x::real) = sign_r_pos q x›*) have "poly (q div p * p) x=0" using ‹poly p x=0› (*‹poly p x = 0›*) poly_mult (*‹poly ((?p::?'a poly) * (?q::?'a poly)) (?x::?'a) = poly ?p ?x * poly ?q ?x›*) by auto moreover hence "poly (q mod p) x ≠ 0" using ‹poly q x≠0› (*‹poly q x ≠ 0›*) by (simp add: assms( (*‹poly (p::real poly) (x::real) = (0::real)›*) 1) poly_mod (*‹poly (?q::?'a::field poly) (?x::?'a::field) = (0::?'a::field) ⟹ poly ((?p::?'a::field poly) mod ?q) ?x = poly ?p ?x›*)) ultimately show "?thesis" (*goal: ‹sign_r_pos (q mod p) x = sign_r_pos q x›*) by (metis div_mult_mod_eq (*‹?a div ?b * ?b + ?a mod ?b = ?a›*) sign_r_pos_add (*‹⟦poly ?p ?x = 0; poly ?q ?x ≠ 0⟧ ⟹ sign_r_pos (?p + ?q) ?x = sign_r_pos ?q ?x›*)) qed lemma sign_r_pos_pderiv: fixes p:: "real poly" assumes "poly p x=0" "p≠0" shows "sign_r_pos (pderiv p * p) x" proof (-) (*goal: ‹sign_r_pos (pderiv p * p) x›*) have "pderiv p ≠0" by (metis assms( (*‹poly p x = 0›*) 1) assms( (*‹p ≠ 0›*) 2) monoid_add_class.add.right_neutral (*‹?a + 0 = ?a›*) mult_zero_right (*‹?a * 0 = 0›*) pCons_0_0 (*‹[:0:] = 0›*) pderiv_iszero (*‹pderiv ?p = 0 ⟹ ∃h. ?p = [:h:]›*) poly_0 (*‹poly 0 ?x = 0›*) poly_pCons (*‹poly (pCons ?a ?p) ?x = ?a + ?x * poly ?p ?x›*)) have "?thesis = (sign_r_pos (pderiv p) x ⟷ sign_r_pos p x)" using sign_r_pos_mult[OF ‹pderiv p ≠ 0› ‹p≠0›] (*‹sign_r_pos (pderiv p * p) ?x = (sign_r_pos (pderiv p) ?x = sign_r_pos p ?x)›*) by auto also (*calculation: ‹sign_r_pos (pderiv p * p) x = (sign_r_pos (pderiv p) x = sign_r_pos p x)›*) have "...=((sign_r_pos (pderiv p) x ⟷ sign_r_pos (pderiv p) x))" using sign_r_pos_rec[OF ‹p≠0›] (*‹sign_r_pos p ?x = (if poly p ?x = 0 then sign_r_pos (pderiv p) ?x else 0 < poly p ?x)›*) ‹poly p x=0› (*‹poly (p::real poly) (x::real) = (0::real)›*) by auto finally (*calculation: ‹sign_r_pos (pderiv p * p) x = (sign_r_pos (pderiv p) x = sign_r_pos (pderiv p) x)›*) show "?thesis" (*goal: ‹sign_r_pos (pderiv p * p) x›*) by auto qed lemma sign_r_pos_power: fixes p:: "real poly" and a::real shows "sign_r_pos ([:-a,1:]^n) a" proof (induct n) (*goals: 1. ‹sign_r_pos ([:- (a::real), 1::real:] ^ (0::nat)) a› 2. ‹⋀n::nat. sign_r_pos ([:- (a::real), 1::real:] ^ n) a ⟹ sign_r_pos ([:- a, 1::real:] ^ Suc n) a›*) case 0 (*no hyothesis introduced yet*) thus "?case" (*goal: ‹sign_r_pos ([:- (a::real), 1::real:] ^ (0::nat)) a›*) unfolding sign_r_pos_def eventually_at_right (*goal: ‹∃b>a::real. ∀y>a. y < b ⟶ (0::real) < poly ([:- a, 1::real:] ^ (0::nat)) y›*) apply simp (*goal: ‹∃b>a. ∀y>a. y < b ⟶ 0 < poly ([:- a, 1:] ^ 0) y›*) by (metis gt_ex (*‹∃y. ?x < y›*)) next (*goal: ‹⋀n. sign_r_pos ([:- a, 1:] ^ n) a ⟹ sign_r_pos ([:- a, 1:] ^ Suc n) a›*) case (Suc n) (*‹sign_r_pos ([:- a, 1:] ^ n) a›*) have "pderiv ([:-a,1:]^Suc n) = smult (Suc n) ([:-a,1:]^n)" proof (-) (*goal: ‹pderiv ([:- a, 1:] ^ Suc n) = smult (real (Suc n)) ([:- a, 1:] ^ n)›*) have "pderiv [:- a, 1::real:] = 1" by (simp add: pderiv.simps (*‹pderiv (pCons (?a::?'a) (?p::?'a poly)) = (if ?p = (0::?'a poly) then 0::?'a poly else ?p + pCons (0::?'a) (pderiv ?p))›*)) thus "?thesis" (*goal: ‹pderiv ([:- a, 1:] ^ Suc n) = smult (real (Suc n)) ([:- a, 1:] ^ n)›*) unfolding pderiv_power_Suc (*goal: ‹smult (real (Suc n)) ([:- a, 1:] ^ n) * pderiv [:- a, 1:] = smult (real (Suc n)) ([:- a, 1:] ^ n)›*) by (metis mult_cancel_left1 (*‹((?c::?'a) = ?c * (?b::?'a)) = (?c = (0::?'a) ∨ ?b = (1::?'a))›*)) qed moreover have " poly ([:- a, 1:] ^ Suc n) a=0" by (metis old.nat.distinct( (*‹Suc (?nat'1::nat) ≠ (0::nat)›*) 2) poly_power_n_eq (*‹(?n::nat) ≠ (0::nat) ⟹ (poly ([:- (?a::?'a), 1::?'a:] ^ ?n) (?x::?'a) = (0::?'a)) = (?x = ?a)›*)) hence "sign_r_pos ([:- a, 1:] ^ Suc n) a = sign_r_pos (smult (Suc n) ([:-a,1:]^n)) a" using sign_r_pos_rec (*‹?p ≠ 0 ⟹ sign_r_pos ?p ?x = (if poly ?p ?x = 0 then sign_r_pos (pderiv ?p) ?x else 0 < poly ?p ?x)›*) by (metis (erased, opaque_lifting) calculation (*‹pderiv ([:- (a::real), 1::real:] ^ Suc (n::nat)) = smult (real (Suc n)) ([:- a, 1::real:] ^ n)›*) pderiv_0 (*‹pderiv (0::?'a poly) = (0::?'a poly)›*)) hence "sign_r_pos ([:- a, 1:] ^ Suc n) a = sign_r_pos ([:-a,1:]^n) a" using sign_r_pos_smult (*‹⟦?c ≠ 0; ?p ≠ 0⟧ ⟹ sign_r_pos (smult ?c ?p) ?x = (if 0 < ?c then sign_r_pos ?p ?x else ¬ sign_r_pos ?p ?x)›*) by auto ultimately show "?case" (*goal: ‹sign_r_pos ([:- a, 1:] ^ Suc n) a›*) using Suc.hyps (*‹sign_r_pos ([:- a, 1:] ^ n) a›*) by auto qed subsection‹Jump› definition jump_poly :: "real poly ⇒ real poly ⇒real ⇒ int" where " jump_poly q p x≡ (if p≠0 ∧ q≠0 ∧ odd((order x p) - (order x q) ) then if sign_r_pos (q*p) x then 1 else -1 else 0 )" lemma jump_poly_not_root:"poly p x≠0⟹ jump_poly q p x=0" unfolding jump_poly_def (*goal: ‹poly p x ≠ 0 ⟹ (if p ≠ 0 ∧ q ≠ 0 ∧ odd (order x p - order x q) then if sign_r_pos (q * p) x then 1 else - 1 else 0) = 0›*) by (metis even_zero (*‹even 0›*) order_root (*‹(poly ?p ?a = 0) = (?p = 0 ∨ order ?a ?p ≠ 0)›*) zero_diff (*‹0 - ?a = 0›*)) lemma jump_poly0[simp]: "jump_poly 0 p x = 0" "jump_poly q 0 x = 0" unfolding jump_poly_def (*goals: 1. ‹(if p ≠ 0 ∧ 0 ≠ 0 ∧ odd (order x p - order x 0) then if sign_r_pos (0 * p) x then 1 else - 1 else 0) = 0› 2. ‹(if 0 ≠ 0 ∧ q ≠ 0 ∧ odd (order x 0 - order x q) then if sign_r_pos (q * 0) x then 1 else - 1 else 0) = 0›*) (*goals: 1. ‹(if (p::real poly) ≠ (0::real poly) ∧ (0::real poly) ≠ (0::real poly) ∧ odd (order (x::real) p - order x (0::real poly)) then if sign_r_pos ((0::real poly) * p) x then 1::int else - (1::int) else (0::int)) = (0::int)› 2. ‹(if (0::real poly) ≠ (0::real poly) ∧ (q::real poly) ≠ (0::real poly) ∧ odd (order (x::real) (0::real poly) - order x q) then if sign_r_pos (q * (0::real poly)) x then 1::int else - (1::int) else (0::int)) = (0::int)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma jump_poly_smult_1: fixes p q::"real poly" and c::real shows "jump_poly (smult c q) p x= sign c * jump_poly q p x" (is "?L=?R") proof (cases "c=0∨ q=0") (*goals: 1. ‹c = 0 ∨ q = 0 ⟹ jump_poly (smult c q) p x = sign c * jump_poly q p x› 2. ‹¬ (c = 0 ∨ q = 0) ⟹ jump_poly (smult c q) p x = sign c * jump_poly q p x›*) case True (*‹c = 0 ∨ q = 0›*) thus "?thesis" (*goal: ‹jump_poly (smult c q) p x = sign c * jump_poly q p x›*) unfolding jump_poly_def (*goal: ‹(if p ≠ 0 ∧ smult c q ≠ 0 ∧ odd (order x p - order x (smult c q)) then if sign_r_pos (smult c q * p) x then 1 else - 1 else 0) = sign c * (if p ≠ 0 ∧ q ≠ 0 ∧ odd (order x p - order x q) then if sign_r_pos (q * p) x then 1 else - 1 else 0)›*) by auto next (*goal: ‹¬ (c = 0 ∨ q = 0) ⟹ jump_poly (smult c q) p x = sign c * jump_poly q p x›*) case False (*‹¬ (c = 0 ∨ q = 0)›*) hence "c≠0" and "q≠0" apply - (*goals: 1. ‹¬ (c = 0 ∨ q = 0) ⟹ c ≠ 0› 2. ‹¬ (c = 0 ∨ q = 0) ⟹ q ≠ 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . thus "?thesis" (*goal: ‹jump_poly (smult c q) p x = sign c * jump_poly q p x›*) unfolding jump_poly_def (*goal: ‹(if p ≠ 0 ∧ smult c q ≠ 0 ∧ odd (order x p - order x (smult c q)) then if sign_r_pos (smult c q * p) x then 1 else - 1 else 0) = sign c * (if p ≠ 0 ∧ q ≠ 0 ∧ odd (order x p - order x q) then if sign_r_pos (q * p) x then 1 else - 1 else 0)›*) using order_smult[OF ‹c≠0›] (*‹order ?x (smult c ?p) = order ?x ?p›*) sign_r_pos_smult[OF ‹c≠0›, of "q*p" x] (*‹q * p ≠ 0 ⟹ sign_r_pos (smult c (q * p)) x = (if 0 < c then sign_r_pos (q * p) x else ¬ sign_r_pos (q * p) x)›*) ‹q≠0› (*‹q ≠ 0›*) by auto qed lemma jump_poly_mult: fixes p q p'::"real poly" assumes "p'≠0" shows "jump_poly (p'*q) (p'*p) x= jump_poly q p x" proof (cases "q=0 ∨ p=0") (*goals: 1. ‹q = 0 ∨ p = 0 ⟹ jump_poly (p' * q) (p' * p) x = jump_poly q p x› 2. ‹¬ (q = 0 ∨ p = 0) ⟹ jump_poly (p' * q) (p' * p) x = jump_poly q p x›*) case True (*‹q = 0 ∨ p = 0›*) thus "?thesis" (*goal: ‹jump_poly (p' * q) (p' * p) x = jump_poly q p x›*) unfolding jump_poly_def (*goal: ‹(if p' * p ≠ 0 ∧ p' * q ≠ 0 ∧ odd (order x (p' * p) - order x (p' * q)) then if sign_r_pos (p' * q * (p' * p)) x then 1 else - 1 else 0) = (if p ≠ 0 ∧ q ≠ 0 ∧ odd (order x p - order x q) then if sign_r_pos (q * p) x then 1 else - 1 else 0)›*) by fastforce next (*goal: ‹¬ (q = 0 ∨ p = 0) ⟹ jump_poly (p' * q) (p' * p) x = jump_poly q p x›*) case False (*‹¬ (q = 0 ∨ p = 0)›*) then have "q≠0" "p≠0" apply - (*goals: 1. ‹¬ (q = 0 ∨ p = 0) ⟹ q ≠ 0› 2. ‹¬ (q = 0 ∨ p = 0) ⟹ p ≠ 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have "sign_r_pos (p' * q * (p' * p)) x=sign_r_pos (q * p) x" apply (unfold sign_r_pos_def (*‹sign_r_pos ?p ?x ≡ ∀⇩F x in at_right ?x. 0 < poly ?p x›*)) (*goal: ‹sign_r_pos (p' * q * (p' * p)) x = sign_r_pos (q * p) x›*) apply (rule eventually_subst (*‹∀⇩F n in ?F. ?P n = ?Q n ⟹ eventually ?P ?F = eventually ?Q ?F›*)) (*goal: ‹(∀⇩F x in at_right x. 0 < poly (p' * q * (p' * p)) x) = (∀⇩F x in at_right x. 0 < poly (q * p) x)›*) proof (unfold eventually_at_right (*‹eventually ?P (at_right ?x) = (∃b>?x. ∀y>?x. y < b ⟶ ?P y)›*)) (*goal: ‹∃b>x. ∀y>x. y < b ⟶ (0 < poly (p' * q * (p' * p)) y) = (0 < poly (q * p) y)›*) obtain b where "b>x" and b: "∀z. x < z ∧ z < b ⟶ poly (p' * p') z >0" (*goal: ‹(⋀b. ⟦x < b; ∀z. x < z ∧ z < b ⟶ 0 < poly (p' * p') z⟧ ⟹ thesis) ⟹ thesis›*) proof (cases "∃z. poly p' z=0 ∧ z>x") (*goals: 1. ‹⟦⋀b. ⟦x < b; ∀z. x < z ∧ z < b ⟶ 0 < poly (p' * p') z⟧ ⟹ thesis; ∃z. poly p' z = 0 ∧ x < z⟧ ⟹ thesis› 2. ‹⟦⋀b. ⟦x < b; ∀z. x < z ∧ z < b ⟶ 0 < poly (p' * p') z⟧ ⟹ thesis; ∄z. poly p' z = 0 ∧ x < z⟧ ⟹ thesis›*) case True (*‹∃z. poly p' z = 0 ∧ x < z›*) define lr where "lr≡Min {r . poly p' r=0 ∧ r>x}" have "∀z. x<z∧z<lr⟶poly p' z≠0" and "lr>x" using True (*‹∃z::real. poly (p'::real poly) z = (0::real) ∧ (x::real) < z›*) lr_def (*‹lr ≡ Min {r. poly p' r = 0 ∧ x < r}›*) poly_roots_finite[OF ‹p'≠0›] (*‹finite {x. poly p' x = 0}›*) apply - (*goals: 1. ‹⟦∃z. poly p' z = 0 ∧ x < z; lr ≡ Min {r. poly p' r = 0 ∧ x < r}; finite {x. poly p' x = 0}⟧ ⟹ ∀z. x < z ∧ z < lr ⟶ poly p' z ≠ 0› 2. ‹⟦∃z. poly p' z = 0 ∧ x < z; lr ≡ Min {r. poly p' r = 0 ∧ x < r}; finite {x. poly p' x = 0}⟧ ⟹ x < lr› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . hence "∀z. x < z ∧ z < lr ⟶ 0 < poly (p' * p') z" by (metis not_real_square_gt_zero (*‹(¬ 0 < ?x * ?x) = (?x = 0)›*) poly_mult (*‹poly (?p * ?q) ?x = poly ?p ?x * poly ?q ?x›*)) thus "?thesis" (*goal: ‹thesis›*) using that[OF ‹lr>x›] (*‹∀z. x < z ∧ z < lr ⟶ 0 < poly (p' * p') z ⟹ thesis›*) by auto next (*goal: ‹⟦⋀b. ⟦x < b; ∀z. x < z ∧ z < b ⟶ 0 < poly (p' * p') z⟧ ⟹ thesis; ∄z. poly p' z = 0 ∧ x < z⟧ ⟹ thesis›*) case False (*‹∄z. poly p' z = 0 ∧ x < z›*) have "∀z. x<z∧z<x+1⟶poly p' z≠0" and "x+1>x" using False (*‹∄z. poly p' z = 0 ∧ x < z›*) poly_roots_finite[OF ‹p'≠0›] (*‹finite {x. poly p' x = 0}›*) apply - (*goals: 1. ‹⟦∄z. poly p' z = 0 ∧ x < z; finite {x. poly p' x = 0}⟧ ⟹ ∀z. x < z ∧ z < x + 1 ⟶ poly p' z ≠ 0› 2. ‹⟦∄z. poly p' z = 0 ∧ x < z; finite {x. poly p' x = 0}⟧ ⟹ x < x + 1› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . hence "∀z. x < z ∧ z < x+1 ⟶ 0 < poly (p' * p') z" by (metis not_real_square_gt_zero (*‹(¬ 0 < ?x * ?x) = (?x = 0)›*) poly_mult (*‹poly (?p * ?q) ?x = poly ?p ?x * poly ?q ?x›*)) thus "?thesis" (*goal: ‹thesis›*) using that[OF ‹x+1>x›] (*‹∀z. x < z ∧ z < x + 1 ⟶ 0 < poly (p' * p') z ⟹ thesis›*) by auto qed show "∃b>x. ∀z>x. z < b ⟶ (0 < poly (p' * q * (p' * p)) z) = (0 < poly (q * p) z)" apply (rule_tac x="b" in exI (*‹?P ?x ⟹ ∃x. ?P x›*)) (*goal: ‹∃b>x. ∀z>x. z < b ⟶ (0 < poly (p' * q * (p' * p)) z) = (0 < poly (q * p) z)›*) apply (rule conjI[OF ‹b>x›] (*‹?Q ⟹ x < b ∧ ?Q›*)) (*goal: ‹x < b ∧ (∀z>x. z < b ⟶ (0 < poly (p' * q * (p' * p)) z) = (0 < poly (q * p) z))›*) apply (rule allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*)) (*goal: ‹∀z>x. z < b ⟶ (0 < poly (p' * q * (p' * p)) z) = (0 < poly (q * p) z)›*) apply (rule impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goal: ‹⋀z. x < z ⟶ z < b ⟶ (0 < poly (p' * q * (p' * p)) z) = (0 < poly (q * p) z)›*) proof (rule impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goal: ‹⋀z::real. ⟦(x::real) < z; z < (b::real)⟧ ⟹ ((0::real) < poly ((p'::real poly) * (q::real poly) * (p' * (p::real poly))) z) = ((0::real) < poly (q * p) z)›*) fix z assume "x < z" "z < b" (*‹(x::real) < (z::real)› ‹(z::real) < (b::real)›*) hence "0<poly (p'*p') z" using b (*‹∀z::real. (x::real) < z ∧ z < (b::real) ⟶ (0::real) < poly ((p'::real poly) * p') z›*) by auto have " (0 < poly (p' * q * (p' * p)) z)=(0<poly (p'*p') z * poly (q*p) z)" by (simp add: mult.commute (*‹?a * ?b = ?b * ?a›*) mult.left_commute (*‹?b * (?a * ?c) = ?a * (?b * ?c)›*)) also (*calculation: ‹(0 < poly (p' * q * (p' * p)) z) = (0 < poly (p' * p') z * poly (q * p) z)›*) have "...=(0<poly (q*p) z)" using ‹0<poly (p'*p') z› (*‹0 < poly (p' * p') z›*) by (metis mult_pos_pos (*‹⟦0 < ?a; 0 < ?b⟧ ⟹ 0 < ?a * ?b›*) zero_less_mult_pos (*‹⟦0 < ?a * ?b; 0 < ?a⟧ ⟹ 0 < ?b›*)) finally (*calculation: ‹(0 < poly (p' * q * (p' * p)) z) = (0 < poly (q * p) z)›*) show "(0 < poly (p' * q * (p' * p)) z) = (0 < poly (q * p) z)" . qed qed moreover have " odd (order x (p' * p) - order x (p' * q)) = odd (order x p - order x q)" using False (*‹¬ (q = 0 ∨ p = 0)›*) ‹p'≠0› (*‹p' ≠ 0›*) ‹p≠0› (*‹p ≠ 0›*) mult_eq_0_iff (*‹(?a * ?b = 0) = (?a = 0 ∨ ?b = 0)›*) order_mult (*‹?p * ?q ≠ 0 ⟹ order ?a (?p * ?q) = order ?a ?p + order ?a ?q›*) by (metis add_diff_cancel_left (*‹?c + ?a - (?c + ?b) = ?a - ?b›*)) moreover have " p' * q ≠ 0 ⟷ q ≠ 0" by (metis ‹p'≠0› mult_eq_0_iff (*‹(?a * ?b = 0) = (?a = 0 ∨ ?b = 0)›*)) ultimately show "jump_poly (p' * q) (p' * p) x = jump_poly q p x" unfolding jump_poly_def (*goal: ‹(if p' * p ≠ 0 ∧ p' * q ≠ 0 ∧ odd (order x (p' * p) - order x (p' * q)) then if sign_r_pos (p' * q * (p' * p)) x then 1 else - 1 else 0) = (if p ≠ 0 ∧ q ≠ 0 ∧ odd (order x p - order x q) then if sign_r_pos (q * p) x then 1 else - 1 else 0)›*) by auto qed lemma jump_poly_1_mult: fixes p1 p2::"real poly" assumes "poly p1 x≠0 ∨ poly p2 x≠0" shows "jump_poly 1 (p1*p2) x= sign (poly p2 x) * jump_poly 1 p1 x + sign (poly p1 x) * jump_poly 1 p2 x" (is "?L=?R") proof (cases "p1=0 ∨ p2 =0") (*goals: 1. ‹p1 = 0 ∨ p2 = 0 ⟹ jump_poly 1 (p1 * p2) x = sign (poly p2 x) * jump_poly 1 p1 x + sign (poly p1 x) * jump_poly 1 p2 x› 2. ‹¬ (p1 = 0 ∨ p2 = 0) ⟹ jump_poly 1 (p1 * p2) x = sign (poly p2 x) * jump_poly 1 p1 x + sign (poly p1 x) * jump_poly 1 p2 x›*) case True (*‹p1 = 0 ∨ p2 = 0›*) then show "?thesis" (*goal: ‹jump_poly 1 (p1 * p2) x = sign (poly p2 x) * jump_poly 1 p1 x + sign (poly p1 x) * jump_poly 1 p2 x›*) by auto next (*goal: ‹¬ (p1 = 0 ∨ p2 = 0) ⟹ jump_poly 1 (p1 * p2) x = sign (poly p2 x) * jump_poly 1 p1 x + sign (poly p1 x) * jump_poly 1 p2 x›*) case False (*‹¬ ((p1::real poly) = (0::real poly) ∨ (p2::real poly) = (0::real poly))›*) then have "p1≠0" "p2≠0" "p1*p2≠0" apply - (*goals: 1. ‹¬ (p1 = 0 ∨ p2 = 0) ⟹ p1 ≠ 0› 2. ‹¬ (p1 = 0 ∨ p2 = 0) ⟹ p2 ≠ 0› 3. ‹¬ (p1 = 0 ∨ p2 = 0) ⟹ p1 * p2 ≠ 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . have "?thesis" if "poly p1 x≠0" proof (-) (*goal: ‹jump_poly 1 (p1 * p2) x = sign (poly p2 x) * jump_poly 1 p1 x + sign (poly p1 x) * jump_poly 1 p2 x›*) have [simp]: "order x p1 = 0" using that (*‹poly p1 x ≠ 0›*) order_root (*‹(poly ?p ?a = 0) = (?p = 0 ∨ order ?a ?p ≠ 0)›*) by blast define simpL where "simpL≡(if p2≠0 ∧ odd (order x p2) then if (poly p1 x>0) ⟷ sign_r_pos p2 x then 1::int else -1 else 0)" have "?L=simpL" unfolding simpL_def jump_poly_def (*goal: ‹(if p1 * p2 ≠ 0 ∧ 1 ≠ 0 ∧ odd (order x (p1 * p2) - order x 1) then if sign_r_pos (1 * (p1 * p2)) x then 1 else - 1 else 0) = (if p2 ≠ 0 ∧ odd (order x p2) then if (0 < poly p1 x) = sign_r_pos p2 x then 1 else - 1 else 0)›*) using order_mult[OF ‹p1*p2≠0›] (*‹order ?a (p1 * p2) = order ?a p1 + order ?a p2›*) sign_r_pos_mult[OF ‹p1≠0› ‹p2≠0›] (*‹sign_r_pos (p1 * p2) ?x = (sign_r_pos p1 ?x = sign_r_pos p2 ?x)›*) sign_r_pos_rec[OF ‹p1≠0›] (*‹sign_r_pos p1 ?x = (if poly p1 ?x = 0 then sign_r_pos (pderiv p1) ?x else 0 < poly p1 ?x)›*) ‹poly p1 x≠0› (*‹poly p1 x ≠ 0›*) by auto moreover have "poly p1 x>0 ⟹ simpL =?R" unfolding simpL_def jump_poly_def (*goal: ‹0 < poly p1 x ⟹ (if p2 ≠ 0 ∧ odd (order x p2) then if (0 < poly p1 x) = sign_r_pos p2 x then 1 else - 1 else 0) = sign (poly p2 x) * (if p1 ≠ 0 ∧ 1 ≠ 0 ∧ odd (order x p1 - order x 1) then if sign_r_pos (1 * p1) x then 1 else - 1 else 0) + sign (poly p1 x) * (if p2 ≠ 0 ∧ 1 ≠ 0 ∧ odd (order x p2 - order x 1) then if sign_r_pos (1 * p2) x then 1 else - 1 else 0)›*) using jump_poly_not_root[OF ‹poly p1 x≠0›] (*‹jump_poly ?q p1 x = 0›*) by auto moreover have "poly p1 x<0 ⟹ simpL =?R" unfolding simpL_def jump_poly_def (*goal: ‹poly (p1::real poly) (x::real) < (0::real) ⟹ (if (p2::real poly) ≠ (0::real poly) ∧ odd (order x p2) then if ((0::real) < poly p1 x) = sign_r_pos p2 x then 1::int else - (1::int) else (0::int)) = sign (poly p2 x) * (if p1 ≠ (0::real poly) ∧ (1::real poly) ≠ (0::real poly) ∧ odd (order x p1 - order x (1::real poly)) then if sign_r_pos ((1::real poly) * p1) x then 1::int else - (1::int) else (0::int)) + sign (poly p1 x) * (if p2 ≠ (0::real poly) ∧ (1::real poly) ≠ (0::real poly) ∧ odd (order x p2 - order x (1::real poly)) then if sign_r_pos ((1::real poly) * p2) x then 1::int else - (1::int) else (0::int))›*) using jump_poly_not_root[OF ‹poly p1 x≠0›] (*‹jump_poly ?q p1 x = 0›*) by auto ultimately show "?L=?R" using ‹poly p1 x≠0› (*‹poly p1 x ≠ 0›*) by (metis linorder_neqE_linordered_idom (*‹⟦(?x::?'a) ≠ (?y::?'a); ?x < ?y ⟹ ?thesis::bool; ?y < ?x ⟹ ?thesis⟧ ⟹ ?thesis›*)) qed moreover have "?thesis" if "poly p2 x≠0" proof (-) (*goal: ‹jump_poly 1 (p1 * p2) x = sign (poly p2 x) * jump_poly 1 p1 x + sign (poly p1 x) * jump_poly 1 p2 x›*) have [simp]: "order x p2 = 0" using that (*‹poly p2 x ≠ 0›*) order_root (*‹(poly ?p ?a = 0) = (?p = 0 ∨ order ?a ?p ≠ 0)›*) by blast define simpL where "simpL≡(if p1≠0 ∧ odd (order x p1) then if (poly p2 x>0) ⟷ sign_r_pos p1 x then 1::int else -1 else 0)" have "?L=simpL" unfolding simpL_def jump_poly_def (*goal: ‹(if p1 * p2 ≠ 0 ∧ 1 ≠ 0 ∧ odd (order x (p1 * p2) - order x 1) then if sign_r_pos (1 * (p1 * p2)) x then 1 else - 1 else 0) = (if p1 ≠ 0 ∧ odd (order x p1) then if (0 < poly p2 x) = sign_r_pos p1 x then 1 else - 1 else 0)›*) using order_mult[OF ‹p1*p2≠0›] (*‹order ?a (p1 * p2) = order ?a p1 + order ?a p2›*) sign_r_pos_mult[OF ‹p1≠0› ‹p2≠0›] (*‹sign_r_pos (p1 * p2) ?x = (sign_r_pos p1 ?x = sign_r_pos p2 ?x)›*) sign_r_pos_rec[OF ‹p2≠0›] (*‹sign_r_pos p2 ?x = (if poly p2 ?x = 0 then sign_r_pos (pderiv p2) ?x else 0 < poly p2 ?x)›*) ‹poly p2 x≠0› (*‹poly p2 x ≠ 0›*) by auto moreover have "poly p2 x>0 ⟹ simpL =?R" unfolding simpL_def jump_poly_def (*goal: ‹0 < poly p2 x ⟹ (if p1 ≠ 0 ∧ odd (order x p1) then if (0 < poly p2 x) = sign_r_pos p1 x then 1 else - 1 else 0) = sign (poly p2 x) * (if p1 ≠ 0 ∧ 1 ≠ 0 ∧ odd (order x p1 - order x 1) then if sign_r_pos (1 * p1) x then 1 else - 1 else 0) + sign (poly p1 x) * (if p2 ≠ 0 ∧ 1 ≠ 0 ∧ odd (order x p2 - order x 1) then if sign_r_pos (1 * p2) x then 1 else - 1 else 0)›*) using jump_poly_not_root[OF ‹poly p2 x≠0›] (*‹jump_poly ?q p2 x = 0›*) by auto moreover have "poly p2 x<0 ⟹ simpL =?R" unfolding simpL_def jump_poly_def (*goal: ‹poly p2 x < 0 ⟹ (if p1 ≠ 0 ∧ odd (order x p1) then if (0 < poly p2 x) = sign_r_pos p1 x then 1 else - 1 else 0) = sign (poly p2 x) * (if p1 ≠ 0 ∧ 1 ≠ 0 ∧ odd (order x p1 - order x 1) then if sign_r_pos (1 * p1) x then 1 else - 1 else 0) + sign (poly p1 x) * (if p2 ≠ 0 ∧ 1 ≠ 0 ∧ odd (order x p2 - order x 1) then if sign_r_pos (1 * p2) x then 1 else - 1 else 0)›*) using jump_poly_not_root[OF ‹poly p2 x≠0›] (*‹jump_poly (?q::real poly) (p2::real poly) (x::real) = (0::int)›*) by auto ultimately show "?L=?R" using ‹poly p2 x≠0› (*‹poly (p2::real poly) (x::real) ≠ (0::real)›*) by (metis linorder_neqE_linordered_idom (*‹⟦?x ≠ ?y; ?x < ?y ⟹ ?thesis; ?y < ?x ⟹ ?thesis⟧ ⟹ ?thesis›*)) qed ultimately show "?thesis" (*goal: ‹jump_poly 1 (p1 * p2) x = sign (poly p2 x) * jump_poly 1 p1 x + sign (poly p1 x) * jump_poly 1 p2 x›*) using assms (*‹poly p1 x ≠ 0 ∨ poly p2 x ≠ 0›*) by auto qed lemma jump_poly_mod: fixes p q::"real poly" shows "jump_poly q p x= jump_poly (q mod p) p x" proof (cases "q=0 ∨ p=0") (*goals: 1. ‹q = 0 ∨ p = 0 ⟹ jump_poly q p x = jump_poly (q mod p) p x› 2. ‹¬ (q = 0 ∨ p = 0) ⟹ jump_poly q p x = jump_poly (q mod p) p x›*) case True (*‹q = 0 ∨ p = 0›*) thus "?thesis" (*goal: ‹jump_poly q p x = jump_poly (q mod p) p x›*) by fastforce next (*goal: ‹¬ (q = 0 ∨ p = 0) ⟹ jump_poly q p x = jump_poly (q mod p) p x›*) case False (*‹¬ (q = 0 ∨ p = 0)›*) then have "p≠0" "q≠0" apply - (*goals: 1. ‹¬ (q = 0 ∨ p = 0) ⟹ p ≠ 0› 2. ‹¬ (q = 0 ∨ p = 0) ⟹ q ≠ 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . define n where "n≡min (order x q) (order x p)" obtain q' where q': "q=[:-x,1:]^n * q'" (*goal: ‹(⋀q'. q = [:- x, 1:] ^ n * q' ⟹ thesis) ⟹ thesis›*) using n_def (*‹n ≡ min (order x q) (order x p)›*) power_le_dvd[OF order_1 [ of x q ], of n] (*‹n ≤ order x q ⟹ [:- x, 1:] ^ n dvd q›*) by (metis dvdE (*‹⟦?b dvd ?a; ⋀k. ?a = ?b * k ⟹ ?P⟧ ⟹ ?P›*) min.cobounded2 (*‹min ?a ?b ≤ ?b›*) min.commute (*‹min ?a ?b = min ?b ?a›*)) obtain p' where p': "p=[:-x,1:]^n * p'" (*goal: ‹(⋀p'. p = [:- x, 1:] ^ n * p' ⟹ thesis) ⟹ thesis›*) using n_def (*‹n ≡ min (order x q) (order x p)›*) power_le_dvd[OF order_1 [ of x p ], of n] (*‹n ≤ order x p ⟹ [:- x, 1:] ^ n dvd p›*) by (metis dvdE (*‹⟦?b dvd ?a; ⋀k. ?a = ?b * k ⟹ ?P⟧ ⟹ ?P›*) min.cobounded2 (*‹min ?a ?b ≤ ?b›*)) have "q'≠0" and "p'≠0" using q' (*‹q = [:- x, 1:] ^ n * q'›*) p' (*‹(p::real poly) = [:- (x::real), 1::real:] ^ (n::nat) * (p'::real poly)›*) ‹p≠0› (*‹(p::real poly) ≠ (0::real poly)›*) ‹q≠0› (*‹q ≠ 0›*) apply - (*goals: 1. ‹⟦(q::real poly) = [:- (x::real), 1::real:] ^ (n::nat) * (q'::real poly); (p::real poly) = [:- x, 1::real:] ^ n * (p'::real poly); p ≠ (0::real poly); q ≠ (0::real poly)⟧ ⟹ q' ≠ (0::real poly)› 2. ‹⟦(q::real poly) = [:- (x::real), 1::real:] ^ (n::nat) * (q'::real poly); (p::real poly) = [:- x, 1::real:] ^ n * (p'::real poly); p ≠ (0::real poly); q ≠ (0::real poly)⟧ ⟹ p' ≠ (0::real poly)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have "order x q'=0 ∨ order x p'=0" proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹¬ (order x q' = 0 ∨ order x p' = 0) ⟹ False›*) assume "¬ (order x q' = 0 ∨ order x p' = 0)" (*‹¬ (order (x::real) (q'::real poly) = (0::nat) ∨ order x (p'::real poly) = (0::nat))›*) hence "order x q' > 0" and "order x p' > 0" apply - (*goals: 1. ‹¬ (order x q' = 0 ∨ order x p' = 0) ⟹ 0 < order x q'› 2. ‹¬ (order x q' = 0 ∨ order x p' = 0) ⟹ 0 < order x p'› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . hence "order x q>n" and "order x p>n" unfolding q' p' (*goals: 1. ‹(n::nat) < order (x::real) ([:- x, 1::real:] ^ n * (q'::real poly))› 2. ‹(n::nat) < order (x::real) ([:- x, 1::real:] ^ n * (p'::real poly))›*) using order_mult[OF ‹q≠0› [ unfolded q' ], of x] (*‹order (x::real) ([:- x, 1::real:] ^ (n::nat) * (q'::real poly)) = order x ([:- x, 1::real:] ^ n) + order x q'›*) order_mult[OF ‹p≠0› [ unfolded p' ], of x] (*‹order (x::real) ([:- x, 1::real:] ^ (n::nat) * (p'::real poly)) = order x ([:- x, 1::real:] ^ n) + order x p'›*) order_power_n_n[of x n] (*‹order x ([:- x, 1:] ^ n) = n›*) apply - (*goals: 1. ‹⟦(0::nat) < order (x::real) (q'::real poly); (0::nat) < order x (p'::real poly); order x ([:- x, 1::real:] ^ (n::nat) * q') = order x ([:- x, 1::real:] ^ n) + order x q'; order x ([:- x, 1::real:] ^ n * p') = order x ([:- x, 1::real:] ^ n) + order x p'; order x ([:- x, 1::real:] ^ n) = n⟧ ⟹ n < order x ([:- x, 1::real:] ^ n * q')› 2. ‹⟦(0::nat) < order (x::real) (q'::real poly); (0::nat) < order x (p'::real poly); order x ([:- x, 1::real:] ^ (n::nat) * q') = order x ([:- x, 1::real:] ^ n) + order x q'; order x ([:- x, 1::real:] ^ n * p') = order x ([:- x, 1::real:] ^ n) + order x p'; order x ([:- x, 1::real:] ^ n) = n⟧ ⟹ n < order x ([:- x, 1::real:] ^ n * p')› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . thus False using n_def (*‹n ≡ min (order x q) (order x p)›*) by auto qed have cond: "q' ≠ 0 ∧ odd (order x p' - order x q') = (q' mod p' ≠0 ∧ odd(order x p' - order x (q' mod p')))" proof (cases "order x p'=0") (*goals: 1. ‹order x p' = 0 ⟹ q' ≠ 0 ∧ odd (order x p' - order x q') = (q' mod p' ≠ 0 ∧ odd (order x p' - order x (q' mod p')))› 2. ‹order x p' ≠ 0 ⟹ q' ≠ 0 ∧ odd (order x p' - order x q') = (q' mod p' ≠ 0 ∧ odd (order x p' - order x (q' mod p')))›*) case True (*‹order x p' = 0›*) thus "?thesis" (*goal: ‹(q'::real poly) ≠ (0::real poly) ∧ odd (order (x::real) (p'::real poly) - order x q') = (q' mod p' ≠ (0::real poly) ∧ odd (order x p' - order x (q' mod p')))›*) by (metis ‹q' ≠ 0› even_zero (*‹even 0›*) zero_diff (*‹0 - ?a = 0›*)) next (*goal: ‹order (x::real) (p'::real poly) ≠ (0::nat) ⟹ (q'::real poly) ≠ (0::real poly) ∧ odd (order x p' - order x q') = (q' mod p' ≠ (0::real poly) ∧ odd (order x p' - order x (q' mod p')))›*) case False (*‹order (x::real) (p'::real poly) ≠ (0::nat)›*) hence "order x q'=0" using ‹order x q'=0 ∨ order x p'=0› (*‹order x q' = 0 ∨ order x p' = 0›*) by auto hence "¬ [:-x,1:] dvd q'" by (metis ‹q' ≠ 0› order_root (*‹(poly ?p ?a = 0) = (?p = 0 ∨ order ?a ?p ≠ 0)›*) poly_eq_0_iff_dvd (*‹(poly ?p ?c = 0) = ([:- ?c, 1:] dvd ?p)›*)) moreover have "[:-x,1:] dvd p'" using False (*‹order x p' ≠ 0›*) by (metis order_root (*‹(poly ?p ?a = 0) = (?p = 0 ∨ order ?a ?p ≠ 0)›*) poly_eq_0_iff_dvd (*‹(poly ?p ?c = 0) = ([:- ?c, 1:] dvd ?p)›*)) ultimately have "¬ [:-x,1:] dvd (q' mod p')" by (metis dvd_mod_iff (*‹?c dvd ?b ⟹ (?c dvd ?a mod ?b) = (?c dvd ?a)›*)) hence "order x (q' mod p') = 0" and "q' mod p' ≠0" (*goals: 1. ‹order x (q' mod p') = 0› 2. ‹q' mod p' ≠ 0› discuss goal 1*) apply (metis order_root (*‹(poly (?p::?'a poly) (?a::?'a) = (0::?'a)) = (?p = (0::?'a poly) ∨ order ?a ?p ≠ (0::nat))›*) poly_eq_0_iff_dvd (*‹(poly (?p::?'a poly) (?c::?'a) = (0::?'a)) = ([:- ?c, 1::?'a:] dvd ?p)›*)) (*discuss goal 2*) apply (metis ‹¬ [:- x, 1:] dvd q' mod p'› dvd_0_right (*‹?a dvd 0›*)) (*proven 2 subgoals*) . thus "?thesis" (*goal: ‹q' ≠ 0 ∧ odd (order x p' - order x q') = (q' mod p' ≠ 0 ∧ odd (order x p' - order x (q' mod p')))›*) using ‹order x q'=0› (*‹order x q' = 0›*) by auto qed moreover have "q' mod p'≠0 ⟹ poly p' x = 0 ⟹ sign_r_pos (q' * p') x= sign_r_pos (q' mod p' * p') x" proof (-) (*goal: ‹⟦q' mod p' ≠ 0; poly p' x = 0⟧ ⟹ sign_r_pos (q' * p') x = sign_r_pos (q' mod p' * p') x›*) assume "q' mod p'≠0" "poly p' x = 0" (*‹(q'::real poly) mod (p'::real poly) ≠ (0::real poly)› ‹poly (p'::real poly) (x::real) = (0::real)›*) hence "poly q' x≠0" using ‹order x q'=0 ∨ order x p'=0› (*‹order x q' = 0 ∨ order x p' = 0›*) by (metis ‹p' ≠ 0› ‹q' ≠ 0› order_root (*‹(poly (?p::?'a poly) (?a::?'a) = (0::?'a)) = (?p = (0::?'a poly) ∨ order ?a ?p ≠ (0::nat))›*)) hence "sign_r_pos q' x= sign_r_pos (q' mod p') x" using sign_r_pos_mod[OF ‹poly p' x=0›] (*‹poly ?q x ≠ 0 ⟹ sign_r_pos (?q mod p') x = sign_r_pos ?q x›*) by auto thus "?thesis" (*goal: ‹sign_r_pos (q' * p') x = sign_r_pos (q' mod p' * p') x›*) unfolding sign_r_pos_mult[OF ‹q'≠0› ‹p'≠0›] sign_r_pos_mult[OF ‹q' mod p'≠0› ‹p'≠0›] (*goal: ‹(sign_r_pos q' x = sign_r_pos p' x) = (sign_r_pos (q' mod p') x = sign_r_pos p' x)›*) by auto qed moreover have "q' mod p' = 0 ∨ poly p' x ≠ 0 ⟹ jump_poly q' p' x = jump_poly (q' mod p') p' x" proof (-) (*goal: ‹q' mod p' = 0 ∨ poly p' x ≠ 0 ⟹ jump_poly q' p' x = jump_poly (q' mod p') p' x›*) assume assm: "q' mod p' = 0 ∨ poly p' x ≠ 0" (*‹(q'::real poly) mod (p'::real poly) = (0::real poly) ∨ poly p' (x::real) ≠ (0::real)›*) have "q' mod p' = 0 ⟹ ?thesis" unfolding jump_poly_def (*goal: ‹q' mod p' = 0 ⟹ (if p' ≠ 0 ∧ q' ≠ 0 ∧ odd (order x p' - order x q') then if sign_r_pos (q' * p') x then 1 else - 1 else 0) = (if p' ≠ 0 ∧ q' mod p' ≠ 0 ∧ odd (order x p' - order x (q' mod p')) then if sign_r_pos (q' mod p' * p') x then 1 else - 1 else 0)›*) using cond (*‹q' ≠ 0 ∧ odd (order x p' - order x q') = (q' mod p' ≠ 0 ∧ odd (order x p' - order x (q' mod p')))›*) by auto moreover have "poly p' x ≠ 0 ⟹ ¬ odd (order x p' - order x q') ∧ ¬ odd(order x p' - order x (q' mod p'))" by (metis even_zero (*‹even 0›*) order_root (*‹(poly ?p ?a = 0) = (?p = 0 ∨ order ?a ?p ≠ 0)›*) zero_diff (*‹0 - ?a = 0›*)) hence "poly p' x ≠ 0 ⟹ ?thesis" unfolding jump_poly_def (*goal: ‹poly p' x ≠ 0 ⟹ (if p' ≠ 0 ∧ q' ≠ 0 ∧ odd (order x p' - order x q') then if sign_r_pos (q' * p') x then 1 else - 1 else 0) = (if p' ≠ 0 ∧ q' mod p' ≠ 0 ∧ odd (order x p' - order x (q' mod p')) then if sign_r_pos (q' mod p' * p') x then 1 else - 1 else 0)›*) by auto ultimately show "?thesis" (*goal: ‹jump_poly q' p' x = jump_poly (q' mod p') p' x›*) using assm (*‹q' mod p' = 0 ∨ poly p' x ≠ 0›*) by auto qed ultimately have " jump_poly q' p' x = jump_poly (q' mod p') p' x" unfolding jump_poly_def (*goal: ‹(if p' ≠ 0 ∧ q' ≠ 0 ∧ odd (order x p' - order x q') then if sign_r_pos (q' * p') x then 1 else - 1 else 0) = (if p' ≠ 0 ∧ q' mod p' ≠ 0 ∧ odd (order x p' - order x (q' mod p')) then if sign_r_pos (q' mod p' * p') x then 1 else - 1 else 0)›*) by force thus "?thesis" (*goal: ‹jump_poly (q::real poly) (p::real poly) (x::real) = jump_poly (q mod p) p x›*) using p' (*‹(p::real poly) = [:- (x::real), 1::real:] ^ (n::nat) * (p'::real poly)›*) q' (*‹q = [:- x, 1:] ^ n * q'›*) jump_poly_mult (*‹?p' ≠ 0 ⟹ jump_poly (?p' * ?q) (?p' * ?p) ?x = jump_poly ?q ?p ?x›*) by auto qed lemma jump_poly_coprime: fixes p q:: "real poly" assumes "poly p x=0" "coprime p q" shows "jump_poly q p x= jump_poly 1 (q*p) x" proof (cases "p=0 ∨ q=0") (*goals: 1. ‹p = 0 ∨ q = 0 ⟹ jump_poly q p x = jump_poly 1 (q * p) x› 2. ‹¬ (p = 0 ∨ q = 0) ⟹ jump_poly q p x = jump_poly 1 (q * p) x›*) case True (*‹p = 0 ∨ q = 0›*) then show "?thesis" (*goal: ‹jump_poly (q::real poly) (p::real poly) (x::real) = jump_poly (1::real poly) (q * p) x›*) by auto next (*goal: ‹¬ (p = 0 ∨ q = 0) ⟹ jump_poly q p x = jump_poly 1 (q * p) x›*) case False (*‹¬ (p = 0 ∨ q = 0)›*) then have "p≠0" "q≠0" apply - (*goals: 1. ‹¬ (p = 0 ∨ q = 0) ⟹ p ≠ 0› 2. ‹¬ (p = 0 ∨ q = 0) ⟹ q ≠ 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . then have "poly p x≠0 ∨ poly q x≠0" using coprime_poly_0[OF ‹coprime p q›] (*‹poly p ?x ≠ 0 ∨ poly q ?x ≠ 0›*) by auto then have "poly q x≠0" using ‹poly p x=0› (*‹poly (p::real poly) (x::real) = (0::real)›*) by auto then have "order x q=0" using order_root (*‹(poly (?p::?'a::idom poly) (?a::?'a::idom) = (0::?'a::idom)) = (?p = (0::?'a::idom poly) ∨ order ?a ?p ≠ (0::nat))›*) by blast then have "order x p - order x q = order x (q * p)" using ‹p≠0› (*‹p ≠ 0›*) ‹q≠0› (*‹q ≠ 0›*) order_mult[of q p x] (*‹(q::real poly) * (p::real poly) ≠ (0::real poly) ⟹ order (x::real) (q * p) = order x q + order x p›*) by auto then show "?thesis" (*goal: ‹jump_poly q p x = jump_poly 1 (q * p) x›*) unfolding jump_poly_def (*goal: ‹(if p ≠ 0 ∧ q ≠ 0 ∧ odd (order x p - order x q) then if sign_r_pos (q * p) x then 1 else - 1 else 0) = (if q * p ≠ 0 ∧ 1 ≠ 0 ∧ odd (order x (q * p) - order x 1) then if sign_r_pos (1 * (q * p)) x then 1 else - 1 else 0)›*) using ‹q≠0› (*‹q ≠ 0›*) by auto qed lemma jump_poly_sgn: fixes p q:: "real poly" assumes "p≠0" "poly p x=0" shows "jump_poly (pderiv p * q) p x = sign (poly q x)" proof (cases "q=0") (*goals: 1. ‹q = 0 ⟹ jump_poly (pderiv p * q) p x = sign (poly q x)› 2. ‹q ≠ 0 ⟹ jump_poly (pderiv p * q) p x = sign (poly q x)›*) case True (*‹q = 0›*) thus "?thesis" (*goal: ‹jump_poly (pderiv p * q) p x = sign (poly q x)›*) by auto next (*goal: ‹(q::real poly) ≠ (0::real poly) ⟹ jump_poly (pderiv (p::real poly) * q) p (x::real) = sign (poly q x)›*) case False (*‹q ≠ 0›*) have "pderiv p≠0" using ‹p≠0› (*‹p ≠ 0›*) ‹poly p x=0› (*‹poly (p::real poly) (x::real) = (0::real)›*) by (metis mult_poly_0_left (*‹0 * ?q = 0›*) sign_r_pos_0 (*‹¬ sign_r_pos 0 ?x›*) sign_r_pos_pderiv (*‹⟦poly ?p ?x = 0; ?p ≠ 0⟧ ⟹ sign_r_pos (pderiv ?p * ?p) ?x›*)) have elim_p_order: "order x p - order x (pderiv p * q)=1 - order x q" proof (-) (*goal: ‹order x p - order x (pderiv p * q) = 1 - order x q›*) have "order x p - order x (pderiv p * q) = order x p - order x (pderiv p) - order x q" using order_mult (*‹?p * ?q ≠ 0 ⟹ order ?a (?p * ?q) = order ?a ?p + order ?a ?q›*) ‹pderiv p≠0› (*‹pderiv p ≠ 0›*) False (*‹q ≠ 0›*) by (metis diff_diff_left (*‹?i - ?j - ?k = ?i - (?j + ?k)›*) mult_eq_0_iff (*‹(?a * ?b = 0) = (?a = 0 ∨ ?b = 0)›*)) moreover have "order x p - order x (pderiv p) = 1" using order_pderiv[OF ‹pderiv p≠0›, of x] (*‹order x p ≠ 0 ⟹ order x p = Suc (order x (pderiv p))›*) ‹poly p x=0› (*‹poly p x = 0›*) order_root[of p x] (*‹(poly p x = 0) = (p = 0 ∨ order x p ≠ 0)›*) ‹p≠0› (*‹p ≠ 0›*) by auto ultimately show "?thesis" (*goal: ‹order x p - order x (pderiv p * q) = 1 - order x q›*) by auto qed have elim_p_sign_r_pos: "sign_r_pos (pderiv p * q * p) x=sign_r_pos q x" proof (-) (*goal: ‹sign_r_pos (pderiv (p::real poly) * (q::real poly) * p) (x::real) = sign_r_pos q x›*) have "sign_r_pos (pderiv p * q * p) x = (sign_r_pos (pderiv p* p) x ⟷ sign_r_pos q x)" by (metis ‹q ≠ 0› ‹pderiv p ≠ 0› assms( (*‹p ≠ 0›*) 1) no_zero_divisors (*‹⟦?a ≠ 0; ?b ≠ 0⟧ ⟹ ?a * ?b ≠ 0›*) sign_r_pos_mult (*‹⟦?p ≠ 0; ?q ≠ 0⟧ ⟹ sign_r_pos (?p * ?q) ?x = (sign_r_pos ?p ?x = sign_r_pos ?q ?x)›*)) thus "?thesis" (*goal: ‹sign_r_pos (pderiv p * q * p) x = sign_r_pos q x›*) using sign_r_pos_pderiv[OF ‹poly p x=0› ‹p≠0›] (*‹sign_r_pos (pderiv p * p) x›*) by auto qed define simpleL where "simpleL≡if pderiv p * q ≠ 0 ∧ odd (1 - order x q) then if sign_r_pos q x then 1::int else - 1 else 0" have " jump_poly (pderiv p * q) p x =simpleL" unfolding simpleL_def jump_poly_def (*goal: ‹(if p ≠ 0 ∧ pderiv p * q ≠ 0 ∧ odd (order x p - order x (pderiv p * q)) then if sign_r_pos (pderiv p * q * p) x then 1 else - 1 else 0) = (if pderiv p * q ≠ 0 ∧ odd (1 - order x q) then if sign_r_pos q x then 1 else - 1 else 0)›*) apply (subst elim_p_order (*‹order x p - order x (pderiv p * q) = 1 - order x q›*)) (*goal: ‹(if (p::real poly) ≠ (0::real poly) ∧ pderiv p * (q::real poly) ≠ (0::real poly) ∧ odd (order (x::real) p - order x (pderiv p * q)) then if sign_r_pos (pderiv p * q * p) x then 1::int else - (1::int) else (0::int)) = (if pderiv p * q ≠ (0::real poly) ∧ odd ((1::nat) - order x q) then if sign_r_pos q x then 1::int else - (1::int) else (0::int))›*) apply (subst elim_p_sign_r_pos (*‹sign_r_pos (pderiv p * q * p) x = sign_r_pos q x›*)) (*goal: ‹(if p ≠ 0 ∧ pderiv p * q ≠ 0 ∧ odd (1 - order x q) then if sign_r_pos (pderiv p * q * p) x then 1 else - 1 else 0) = (if pderiv p * q ≠ 0 ∧ odd (1 - order x q) then if sign_r_pos q x then 1 else - 1 else 0)›*) by simp moreover have "poly q x=0 ⟹ simpleL=sign (poly q x)" proof (-) (*goal: ‹poly q x = 0 ⟹ simpleL = sign (poly q x)›*) assume "poly q x=0" (*‹poly (q::real poly) (x::real) = (0::real)›*) hence "1-order x q = 0" using ‹q≠0› (*‹q ≠ 0›*) by (metis less_one (*‹(?n < 1) = (?n = 0)›*) not_gr0 (*‹(¬ 0 < ?n) = (?n = 0)›*) order_root (*‹(poly ?p ?a = 0) = (?p = 0 ∨ order ?a ?p ≠ 0)›*) zero_less_diff (*‹(0 < ?n - ?m) = (?m < ?n)›*)) hence "simpleL=0" unfolding simpleL_def (*goal: ‹(if pderiv p * q ≠ 0 ∧ odd (1 - order x q) then if sign_r_pos q x then 1 else - 1 else 0) = 0›*) by auto moreover have "sign (poly q x)=0" using ‹poly q x=0› (*‹poly q x = 0›*) by auto ultimately show "?thesis" (*goal: ‹simpleL = sign (poly q x)›*) by auto qed moreover have "poly q x≠0⟹ simpleL=sign (poly q x)" proof (-) (*goal: ‹poly q x ≠ 0 ⟹ simpleL = sign (poly q x)›*) assume "poly q x≠0" (*‹poly (q::real poly) (x::real) ≠ (0::real)›*) hence "odd (1 - order x q)" by (simp add: order_root (*‹(poly ?p ?a = 0) = (?p = 0 ∨ order ?a ?p ≠ 0)›*)) moreover have "pderiv p * q ≠ 0" by (metis False (*‹q ≠ 0›*) ‹pderiv p ≠ 0› no_zero_divisors (*‹⟦?a ≠ 0; ?b ≠ 0⟧ ⟹ ?a * ?b ≠ 0›*)) moreover have "sign_r_pos q x = (poly q x > 0)" using sign_r_pos_rec[OF False] (*‹sign_r_pos q ?x = (if poly q ?x = 0 then sign_r_pos (pderiv q) ?x else 0 < poly q ?x)›*) ‹poly q x≠0› (*‹poly q x ≠ 0›*) by auto ultimately have "simpleL=(if poly q x>0 then 1 else - 1)" unfolding simpleL_def (*goal: ‹(if pderiv p * q ≠ 0 ∧ odd (1 - order x q) then if sign_r_pos q x then 1 else - 1 else 0) = (if 0 < poly q x then 1 else - 1)›*) by auto thus "?thesis" (*goal: ‹simpleL = sign (poly q x)›*) using ‹poly q x≠0› (*‹poly q x ≠ 0›*) by auto qed ultimately show "?thesis" (*goal: ‹jump_poly (pderiv p * q) p x = sign (poly q x)›*) by force qed subsection ‹Cauchy index› definition cindex_poly:: "real ⇒ real ⇒ real poly ⇒ real poly ⇒ int" where "cindex_poly a b q p≡ (∑x∈{x. poly p x=0 ∧ a< x∧ x< b}. jump_poly q p x)" lemma cindex_poly_0[simp]: "cindex_poly a b 0 p = 0" "cindex_poly a b q 0 = 0" unfolding cindex_poly_def (*goals: 1. ‹(∑x | poly p x = 0 ∧ a < x ∧ x < b. jump_poly 0 p x) = 0› 2. ‹(∑x | poly 0 x = 0 ∧ a < x ∧ x < b. jump_poly q 0 x) = 0›*) (*goals: 1. ‹(∑x | poly p x = 0 ∧ a < x ∧ x < b. jump_poly 0 p x) = 0› 2. ‹(∑x | poly 0 x = 0 ∧ a < x ∧ x < b. jump_poly q 0 x) = 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma cindex_poly_cross: fixes p::"real poly" and a b::real assumes "a<b" "poly p a≠0" "poly p b≠0" shows "cindex_poly a b 1 p = cross p a b" using ‹poly p a≠0› (*‹poly p a ≠ 0›*) ‹poly p b≠0› (*‹poly (p::real poly) (b::real) ≠ (0::real)›*) proof (cases "{x. poly p x=0 ∧ a< x∧ x< b}≠{}", induct "degree p" arbitrary:p rule:nat_less_induct) (*goals: 1. ‹⋀p. ⟦∀m<degree p. ∀x. m = degree x ⟶ poly x a ≠ 0 ⟶ poly x b ≠ 0 ⟶ {xa. poly x xa = 0 ∧ a < xa ∧ xa < b} ≠ {} ⟶ poly x a ≠ 0 ⟶ poly x b ≠ 0 ⟶ cindex_poly a b 1 x = cross x a b; poly p a ≠ 0; poly p b ≠ 0; {x. poly p x = 0 ∧ a < x ∧ x < b} ≠ {}; poly p a ≠ 0; poly p b ≠ 0⟧ ⟹ cindex_poly a b 1 p = cross p a b› 2. ‹⟦poly p a ≠ 0; poly p b ≠ 0; ¬ {x. poly p x = 0 ∧ a < x ∧ x < b} ≠ {}⟧ ⟹ cindex_poly a b 1 p = cross p a b›*) case 1 (*‹∀m<degree p. ∀x. m = degree x ⟶ poly x a ≠ 0 ⟶ poly x b ≠ 0 ⟶ {xa. poly x xa = 0 ∧ a < xa ∧ xa < b} ≠ {} ⟶ poly x a ≠ 0 ⟶ poly x b ≠ 0 ⟶ cindex_poly a b 1 x = cross x a b› ‹poly (p::real poly) (a::real) ≠ (0::real)› ‹poly (p::real poly) (b::real) ≠ (0::real)› ‹{x. poly p x = 0 ∧ a < x ∧ x < b} ≠ {}› ‹poly (p::real poly) (a::real) ≠ (0::real)› ‹poly (p::real poly) (b::real) ≠ (0::real)›*) then have "p≠0" by force define roots where "roots≡{x. poly p x=0 ∧ a< x∧ x< b}" have "finite roots" unfolding roots_def (*goal: ‹finite {x::real. poly (p::real poly) x = (0::real) ∧ (a::real) < x ∧ x < (b::real)}›*) using poly_roots_finite[OF ‹p≠0›] (*‹finite {x::real. poly (p::real poly) x = (0::real)}›*) by auto define max_r where "max_r≡Max roots" hence "poly p max_r=0" and "a<max_r" and "max_r<b" using Max_in[OF ‹finite roots›] (*‹roots ≠ {} ⟹ Max roots ∈ roots›*) "1.prems" (*‹poly (p::real poly) (a::real) ≠ (0::real)› ‹poly p b ≠ 0› ‹{x. poly p x = 0 ∧ a < x ∧ x < b} ≠ {}› ‹poly p a ≠ 0› ‹poly p b ≠ 0›*) unfolding roots_def (*goals: 1. ‹poly p max_r = 0› 2. ‹a < max_r› 3. ‹max_r < b›*) apply - (*goals: 1. ‹⟦max_r ≡ Max {x. poly p x = 0 ∧ a < x ∧ x < b}; {x. poly p x = 0 ∧ a < x ∧ x < b} ≠ {} ⟹ Max {x. poly p x = 0 ∧ a < x ∧ x < b} ∈ {x. poly p x = 0 ∧ a < x ∧ x < b}; poly p a ≠ 0; poly p b ≠ 0; {x. poly p x = 0 ∧ a < x ∧ x < b} ≠ {}; poly p a ≠ 0; poly p b ≠ 0⟧ ⟹ poly p max_r = 0› 2. ‹⟦max_r ≡ Max {x. poly p x = 0 ∧ a < x ∧ x < b}; {x. poly p x = 0 ∧ a < x ∧ x < b} ≠ {} ⟹ Max {x. poly p x = 0 ∧ a < x ∧ x < b} ∈ {x. poly p x = 0 ∧ a < x ∧ x < b}; poly p a ≠ 0; poly p b ≠ 0; {x. poly p x = 0 ∧ a < x ∧ x < b} ≠ {}; poly p a ≠ 0; poly p b ≠ 0⟧ ⟹ a < max_r› 3. ‹⟦max_r ≡ Max {x. poly p x = 0 ∧ a < x ∧ x < b}; {x. poly p x = 0 ∧ a < x ∧ x < b} ≠ {} ⟹ Max {x. poly p x = 0 ∧ a < x ∧ x < b} ∈ {x. poly p x = 0 ∧ a < x ∧ x < b}; poly p a ≠ 0; poly p b ≠ 0; {x. poly p x = 0 ∧ a < x ∧ x < b} ≠ {}; poly p a ≠ 0; poly p b ≠ 0⟧ ⟹ max_r < b› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . define max_rp where "max_rp≡[:-max_r,1:]^order max_r p" then obtain p' where p': "p=p'*max_rp" and not_dvd: "¬ [:-max_r,1:] dvd p'" (*goal: ‹(⋀p'. ⟦p = p' * max_rp; ¬ [:- max_r, 1:] dvd p'⟧ ⟹ thesis) ⟹ thesis›*) by (metis ‹p≠0› mult.commute (*‹?a * ?b = ?b * ?a›*) order_decomp (*‹?p ≠ 0 ⟹ ∃q. ?p = [:- ?a, 1:] ^ order ?a ?p * q ∧ ¬ [:- ?a, 1:] dvd q›*)) hence "p'≠0" and "max_rp≠0" and "poly p' a≠0" and "poly p' b≠0" and "poly max_rp a≠0" and "poly max_rp b≠0" using ‹p≠0› (*‹p ≠ 0›*) ‹poly p a≠0› (*‹poly p a ≠ 0›*) ‹poly p b≠0› (*‹poly (p::real poly) (b::real) ≠ (0::real)›*) apply - (*goals: 1. ‹⟦p = p' * max_rp; ¬ [:- max_r, 1:] dvd p'; p ≠ 0; poly p a ≠ 0; poly p b ≠ 0⟧ ⟹ p' ≠ 0› 2. ‹⟦p = p' * max_rp; ¬ [:- max_r, 1:] dvd p'; p ≠ 0; poly p a ≠ 0; poly p b ≠ 0⟧ ⟹ max_rp ≠ 0› 3. ‹⟦p = p' * max_rp; ¬ [:- max_r, 1:] dvd p'; p ≠ 0; poly p a ≠ 0; poly p b ≠ 0⟧ ⟹ poly p' a ≠ 0› 4. ‹⟦p = p' * max_rp; ¬ [:- max_r, 1:] dvd p'; p ≠ 0; poly p a ≠ 0; poly p b ≠ 0⟧ ⟹ poly p' b ≠ 0› 5. ‹⟦p = p' * max_rp; ¬ [:- max_r, 1:] dvd p'; p ≠ 0; poly p a ≠ 0; poly p b ≠ 0⟧ ⟹ poly max_rp a ≠ 0› 6. ‹⟦p = p' * max_rp; ¬ [:- max_r, 1:] dvd p'; p ≠ 0; poly p a ≠ 0; poly p b ≠ 0⟧ ⟹ poly max_rp b ≠ 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*proven 6 subgoals*) . define max_r_sign where "max_r_sign≡if odd(order max_r p) then -1 else 1::int" define roots' where "roots'≡{x. a< x∧ x< b ∧ poly p' x=0}" have "(∑x∈roots. jump_poly 1 p x)= (∑x∈roots'. jump_poly 1 p x)+ jump_poly 1 p max_r" proof (-) (*goal: ‹sum (jump_poly 1 p) roots = sum (jump_poly 1 p) roots' + jump_poly 1 p max_r›*) have "roots=roots' ∪ {x. a< x∧ x< b ∧ poly max_rp x=0 }" unfolding roots_def roots'_def p' (*goal: ‹{x. poly (p' * max_rp) x = 0 ∧ a < x ∧ x < b} = {x. a < x ∧ x < b ∧ poly p' x = 0} ∪ {x. a < x ∧ x < b ∧ poly max_rp x = 0}›*) by auto moreover have "{x. a < x ∧ x < b ∧ poly max_rp x = 0 }={max_r}" unfolding max_rp_def (*goal: ‹{x::real. (a::real) < x ∧ x < (b::real) ∧ poly ([:- (max_r::real), 1::real:] ^ order max_r (p::real poly)) x = (0::real)} = {max_r}›*) using ‹poly p max_r=0› (*‹poly (p::real poly) (max_r::real) = (0::real)›*) apply (auto simp add: ‹a<max_r› ‹max_r<b›) (*goal: ‹{x. a < x ∧ x < b ∧ poly ([:- max_r, 1:] ^ order max_r p) x = 0} = {max_r}›*) by (metis "1.prems" (*‹poly p a ≠ 0›*) (1) neq0_conv (*‹(?n ≠ 0) = (0 < ?n)›*) order_root (*‹(poly ?p ?a = 0) = (?p = 0 ∨ order ?a ?p ≠ 0)›*)) moreover hence "roots' ∩ {x. a< x∧ x< b ∧ poly max_rp x=0} ={}" unfolding roots'_def (*goal: ‹{x. a < x ∧ x < b ∧ poly p' x = 0} ∩ {x. a < x ∧ x < b ∧ poly max_rp x = 0} = {}›*) using ‹¬ [:-max_r,1:] dvd p'› (*‹¬ [:- max_r, 1:] dvd p'›*) by (metis (mono_tags) Int_insert_right_if0 (*‹?a ∉ ?A ⟹ ?A ∩ insert ?a ?B = ?A ∩ ?B›*) inf_bot_right (*‹inf ?x bot = bot›*) mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*) poly_eq_0_iff_dvd (*‹(poly ?p ?c = 0) = ([:- ?c, 1:] dvd ?p)›*)) moreover have "finite roots'" using p' (*‹p = p' * max_rp›*) ‹p≠0› (*‹p ≠ 0›*) by (metis ‹finite roots› calculation( (*‹roots = roots' ∪ {x. a < x ∧ x < b ∧ poly max_rp x = 0}›*) 1) calculation( (*‹{x. a < x ∧ x < b ∧ poly max_rp x = 0} = {max_r}›*) 2) finite_Un (*‹finite (?F ∪ ?G) = (finite ?F ∧ finite ?G)›*)) ultimately show "?thesis" (*goal: ‹sum (jump_poly 1 p) roots = sum (jump_poly 1 p) roots' + jump_poly 1 p max_r›*) using sum.union_disjoint (*‹⟦finite ?A; finite ?B; ?A ∩ ?B = {}⟧ ⟹ sum ?g (?A ∪ ?B) = sum ?g ?A + sum ?g ?B›*) by auto qed moreover have "(∑x∈roots'. jump_poly 1 p x) = max_r_sign * cross p' a b" proof (-) (*goal: ‹sum (jump_poly 1 p) roots' = max_r_sign * cross p' a b›*) have "(∑x∈roots'. jump_poly 1 p x) = (∑x∈roots'. max_r_sign * jump_poly 1 p' x)" proof (rule sum.cong (*‹⟦?A = ?B; ⋀x. x ∈ ?B ⟹ ?g x = ?h x⟧ ⟹ sum ?g ?A = sum ?h ?B›*), rule refl (*‹(?t::?'a) = ?t›*)) (*goal: ‹⋀x. x ∈ roots' ⟹ jump_poly 1 p x = max_r_sign * jump_poly 1 p' x›*) fix x assume "x ∈ roots'" (*‹(x::real) ∈ (roots'::real set)›*) hence "x≠max_r" using not_dvd (*‹¬ [:- (max_r::real), 1::real:] dvd (p'::real poly)›*) unfolding roots'_def (*goal: ‹x ≠ max_r›*) by (metis (mono_tags, lifting) mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*) poly_eq_0_iff_dvd (*‹(poly ?p ?c = 0) = ([:- ?c, 1:] dvd ?p)›*)) hence "poly max_rp x≠0" using poly_power_n_eq (*‹(?n::nat) ≠ (0::nat) ⟹ (poly ([:- (?a::?'a), 1::?'a:] ^ ?n) (?x::?'a) = (0::?'a)) = (?x = ?a)›*) unfolding max_rp_def (*goal: ‹poly ([:- (max_r::real), 1::real:] ^ order max_r (p::real poly)) (x::real) ≠ (0::real)›*) by auto hence "order x max_rp=0" by (metis order_root (*‹(poly (?p::?'a poly) (?a::?'a) = (0::?'a)) = (?p = (0::?'a poly) ∨ order ?a ?p ≠ (0::nat))›*)) moreover have "jump_poly 1 max_rp x=0" using ‹poly max_rp x≠0› (*‹poly (max_rp::real poly) (x::real) ≠ (0::real)›*) by (metis jump_poly_not_root (*‹poly ?p ?x ≠ 0 ⟹ jump_poly ?q ?p ?x = 0›*)) moreover have "x∈roots" using ‹x ∈ roots'› (*‹x ∈ roots'›*) unfolding roots_def roots'_def p' (*goal: ‹x ∈ {x. poly (p' * max_rp) x = 0 ∧ a < x ∧ x < b}›*) by auto hence "x<max_r" using Max_ge[OF ‹finite roots›, of x] (*‹x ∈ roots ⟹ x ≤ Max roots›*) ‹x≠max_r› (*‹(x::real) ≠ (max_r::real)›*) apply (fold max_r_def) (*goal: ‹x < max_r›*) by auto hence "sign (poly max_rp x) = max_r_sign" using ‹poly max_rp x ≠ 0› (*‹poly max_rp x ≠ 0›*) unfolding max_r_sign_def max_rp_def sign_def (*goal: ‹(if 0 < poly ([:- max_r, 1:] ^ order max_r p) x then 1 else if poly ([:- max_r, 1:] ^ order max_r p) x = 0 then 0 else - 1) = (if odd (order max_r p) then - 1 else 1)›*) apply (subst poly_power (*‹poly (?p ^ ?n) ?x = poly ?p ?x ^ ?n›*)) (*goal: ‹(if 0 < poly ([:- max_r, 1:] ^ order max_r p) x then 1 else if poly ([:- max_r, 1:] ^ order max_r p) x = 0 then 0 else - 1) = (if odd (order max_r p) then - 1 else 1)›*) by (simp add:linorder_class.not_less (*‹(¬ ?x < ?y) = (?y ≤ ?x)›*) zero_less_power_eq (*‹(0 < ?a ^ ?n) = (?n = 0 ∨ even ?n ∧ ?a ≠ 0 ∨ odd ?n ∧ 0 < ?a)›*)) ultimately show "jump_poly 1 p x = max_r_sign * jump_poly 1 p' x" using jump_poly_1_mult[of p' x max_rp] (*‹poly p' x ≠ 0 ∨ poly max_rp x ≠ 0 ⟹ jump_poly 1 (p' * max_rp) x = sign (poly max_rp x) * jump_poly 1 p' x + sign (poly p' x) * jump_poly 1 max_rp x›*) unfolding p' (*goal: ‹jump_poly 1 (p' * max_rp) x = max_r_sign * jump_poly 1 p' x›*) by (simp add: ‹poly max_rp x ≠ 0›) qed also (*calculation: ‹sum (jump_poly (1::real poly) (p::real poly)) (roots'::real set) = (∑x::real∈roots'. (max_r_sign::int) * jump_poly (1::real poly) (p'::real poly) x)›*) have "... = max_r_sign * (∑x∈roots'. jump_poly 1 p' x)" by (simp add: sum_distrib_left (*‹?r * sum ?f ?A = (∑n∈?A. ?r * ?f n)›*)) also (*calculation: ‹sum (jump_poly 1 p) roots' = max_r_sign * sum (jump_poly 1 p') roots'›*) have "... = max_r_sign * cross p' a b" proof (cases "roots'={}") (*goals: 1. ‹roots' = {} ⟹ max_r_sign * sum (jump_poly 1 p') roots' = max_r_sign * cross p' a b› 2. ‹roots' ≠ {} ⟹ max_r_sign * sum (jump_poly 1 p') roots' = max_r_sign * cross p' a b›*) case True (*‹(roots'::real set) = {}›*) hence "cross p' a b=0" unfolding roots'_def (*goal: ‹cross p' a b = 0›*) using cross_no_root[OF ‹a<b›] (*‹∀x::real. (a::real) < x ∧ x < (b::real) ⟶ poly (?p::real poly) x ≠ (0::real) ⟹ cross ?p a b = (0::int)›*) by auto thus "?thesis" (*goal: ‹max_r_sign * sum (jump_poly 1 p') roots' = max_r_sign * cross p' a b›*) using True (*‹roots' = {}›*) by simp next (*goal: ‹roots' ≠ {} ⟹ max_r_sign * sum (jump_poly 1 p') roots' = max_r_sign * cross p' a b›*) case False (*‹roots' ≠ {}›*) moreover have "degree max_rp≠0" unfolding max_rp_def degree_linear_power (*goal: ‹order max_r p ≠ 0›*) by (metis "1.prems" (*‹poly p a ≠ 0›*) (1) ‹poly p max_r = 0› order_root (*‹(poly ?p ?a = 0) = (?p = 0 ∨ order ?a ?p ≠ 0)›*)) hence "degree p' < degree p" unfolding p' degree_mult_eq[OF ‹p'≠0› ‹max_rp≠0›] (*goal: ‹degree p' < degree p' + degree max_rp›*) by auto ultimately have "cindex_poly a b 1 p' = cross p' a b" unfolding roots'_def (*goal: ‹cindex_poly a b 1 p' = cross p' a b›*) using "1.hyps"[rule_format, of "degree p'" p'] (*‹⟦degree p' < degree p; degree p' = degree p'; poly p' a ≠ 0; poly p' b ≠ 0; {x. poly p' x = 0 ∧ a < x ∧ x < b} ≠ {}; poly p' a ≠ 0; poly p' b ≠ 0⟧ ⟹ cindex_poly a b 1 p' = cross p' a b›*) ‹p'≠0› (*‹p' ≠ 0›*) ‹poly p' a≠0› (*‹poly p' a ≠ 0›*) ‹poly p' b≠0› (*‹poly p' b ≠ 0›*) by auto moreover have "cindex_poly a b 1 p' = sum (jump_poly 1 p') roots'" unfolding cindex_poly_def roots'_def (*goal: ‹(∑x | poly p' x = 0 ∧ a < x ∧ x < b. jump_poly 1 p' x) = sum (jump_poly 1 p') {x. a < x ∧ x < b ∧ poly p' x = 0}›*) apply simp (*goal: ‹(∑x | poly p' x = 0 ∧ a < x ∧ x < b. jump_poly 1 p' x) = sum (jump_poly 1 p') {x. a < x ∧ x < b ∧ poly p' x = 0}›*) by (metis (no_types, lifting)) ultimately show "?thesis" (*goal: ‹max_r_sign * sum (jump_poly 1 p') roots' = max_r_sign * cross p' a b›*) by auto qed finally (*calculation: ‹sum (jump_poly 1 p) roots' = max_r_sign * cross p' a b›*) show "?thesis" (*goal: ‹sum (jump_poly 1 p) roots' = max_r_sign * cross p' a b›*) . qed moreover have "max_r_sign * cross p' a b + jump_poly 1 p max_r = cross p a b" (is "?L=?R") proof (cases "odd (order max_r p)") (*goals: 1. ‹odd (order max_r p) ⟹ max_r_sign * cross p' a b + jump_poly 1 p max_r = cross p a b› 2. ‹¬ odd (order max_r p) ⟹ max_r_sign * cross p' a b + jump_poly 1 p max_r = cross p a b›*) case True (*‹odd (order (max_r::real) (p::real poly))›*) have "poly max_rp a < 0" using poly_power_n_odd[OF True, of max_r a] (*‹(0 < poly ([:- max_r, 1:] ^ order max_r p) a) = (max_r < a)›*) ‹poly max_rp a≠0› (*‹poly (max_rp::real poly) (a::real) ≠ (0::real)›*) ‹max_r>a› (*‹(a::real) < (max_r::real)›*) unfolding max_rp_def (*goal: ‹poly ([:- max_r, 1:] ^ order max_r p) a < 0›*) by linarith moreover have "poly max_rp b>0 " using poly_power_n_odd[OF True, of max_r b] (*‹(0 < poly ([:- max_r, 1:] ^ order max_r p) b) = (max_r < b)›*) ‹max_r<b› (*‹(max_r::real) < (b::real)›*) unfolding max_rp_def (*goal: ‹0 < poly ([:- max_r, 1:] ^ order max_r p) b›*) by linarith ultimately have "?R=cross p' a b + sign (poly p' a)" unfolding p' cross_def poly_mult (*goal: ‹variation (poly p' a * poly max_rp a) (poly p' b * poly max_rp b) = variation (poly p' a) (poly p' b) + sign (poly p' a)›*) using variation_mult_neg_1[of "poly max_rp a", simplified mult.commute] (*‹poly max_rp a < 0 ⟹ variation (?x * poly max_rp a) ?y = variation ?x ?y + (if ?y = 0 then 0 else sign ?x)›*) variation_mult_pos(2)[of "poly max_rp b", simplified mult.commute] (*‹0 < poly max_rp b ⟹ variation ?x (?y * poly max_rp b) = variation ?x ?y›*) ‹poly p' b≠0› (*‹poly (p'::real poly) (b::real) ≠ (0::real)›*) by auto moreover have "?L=- cross p' a b + sign (poly p' b)" proof (-) (*goal: ‹max_r_sign * cross p' a b + jump_poly 1 p max_r = - cross p' a b + sign (poly p' b)›*) have " sign_r_pos p' max_r = (poly p' max_r >0)" using sign_r_pos_rec[OF ‹p'≠0›] (*‹sign_r_pos p' ?x = (if poly p' ?x = 0 then sign_r_pos (pderiv p') ?x else 0 < poly p' ?x)›*) not_dvd (*‹¬ [:- max_r, 1:] dvd p'›*) by (metis poly_eq_0_iff_dvd (*‹(poly ?p ?c = 0) = ([:- ?c, 1:] dvd ?p)›*)) moreover have "(poly p' max_r>0) = (poly p' b>0)" proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹(0 < poly p' max_r) ≠ (0 < poly p' b) ⟹ False›*) assume "(0 < poly p' max_r) ≠ (0 < poly p' b)" (*‹((0::real) < poly (p'::real poly) (max_r::real)) ≠ ((0::real) < poly p' (b::real))›*) hence "poly p' max_r * poly p' b <0" using ‹poly p' b≠0› (*‹poly p' b ≠ 0›*) not_dvd[folded poly_eq_0_iff_dvd] (*‹poly p' max_r ≠ 0›*) by (metis (poly_guards_query) linorder_neqE_linordered_idom (*‹⟦?x ≠ ?y; ?x < ?y ⟹ ?thesis; ?y < ?x ⟹ ?thesis⟧ ⟹ ?thesis›*) mult_less_0_iff (*‹(?a * ?b < 0) = (0 < ?a ∧ ?b < 0 ∨ ?a < 0 ∧ 0 < ?b)›*)) then obtain r where "r>max_r" and "r<b" and "poly p' r=0" (*goal: ‹(⋀r. ⟦max_r < r; r < b; poly p' r = 0⟧ ⟹ thesis) ⟹ thesis›*) using poly_IVT[OF ‹max_r<b›] (*‹poly ?p max_r * poly ?p b < 0 ⟹ ∃x>max_r. x < b ∧ poly ?p x = 0›*) by auto hence "r∈roots" unfolding roots_def p' (*goal: ‹r ∈ {x. poly (p' * max_rp) x = 0 ∧ a < x ∧ x < b}›*) using ‹max_r>a› (*‹a < max_r›*) by auto thus False using ‹r>max_r› (*‹max_r < r›*) Max_ge[OF ‹finite roots›, of r] (*‹r ∈ roots ⟹ r ≤ Max roots›*) unfolding max_r_def (*goal: ‹False›*) by auto qed moreover have "sign_r_pos max_rp max_r" using sign_r_pos_power (*‹sign_r_pos ([:- ?a, 1:] ^ ?n) ?a›*) unfolding max_rp_def (*goal: ‹sign_r_pos ([:- max_r, 1:] ^ order max_r p) max_r›*) by auto ultimately show "?thesis" (*goal: ‹(max_r_sign::int) * cross (p'::real poly) (a::real) (b::real) + jump_poly (1::real poly) (p::real poly) (max_r::real) = - cross p' a b + sign (poly p' b)›*) using True (*‹odd (order (max_r::real) (p::real poly))›*) ‹poly p' b≠0› (*‹poly p' b ≠ 0›*) ‹max_rp≠0› (*‹max_rp ≠ 0›*) ‹p'≠0› (*‹(p'::real poly) ≠ (0::real poly)›*) sign_r_pos_mult[OF ‹p'≠0› ‹max_rp≠0›] (*‹sign_r_pos (p' * max_rp) ?x = (sign_r_pos p' ?x = sign_r_pos max_rp ?x)›*) unfolding max_r_sign_def p' jump_poly_def (*goal: ‹(if odd (order max_r (p' * max_rp)) then - 1 else 1) * cross p' a b + (if p' * max_rp ≠ 0 ∧ 1 ≠ 0 ∧ odd (order max_r (p' * max_rp) - order max_r 1) then if sign_r_pos (1 * (p' * max_rp)) max_r then 1 else - 1 else 0) = - cross p' a b + sign (poly p' b)›*) by simp qed moreover have "variation (poly p' a) (poly p' b) + sign (poly p' a) = - variation (poly p' a) (poly p' b) + sign (poly p' b)" unfolding cross_def (*goal: ‹variation (poly p' a) (poly p' b) + sign (poly p' a) = - variation (poly p' a) (poly p' b) + sign (poly p' b)›*) apply (cases "poly p' b" rule:linorder_cases[of 0] (*‹⟦0 < ?y ⟹ ?P; 0 = ?y ⟹ ?P; ?y < 0 ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹(0::real) < poly (p'::real poly) (b::real) ⟹ variation (poly p' (a::real)) (poly p' b) + sign (poly p' a) = - variation (poly p' a) (poly p' b) + sign (poly p' b)› 2. ‹(0::real) = poly (p'::real poly) (b::real) ⟹ variation (poly p' (a::real)) (poly p' b) + sign (poly p' a) = - variation (poly p' a) (poly p' b) + sign (poly p' b)› 3. ‹poly (p'::real poly) (b::real) < (0::real) ⟹ variation (poly p' (a::real)) (poly p' b) + sign (poly p' a) = - variation (poly p' a) (poly p' b) + sign (poly p' b)› discuss goal 1*) apply (cases "poly p' a" rule:linorder_cases[of 0] (*‹⟦0 < ?y ⟹ ?P; 0 = ?y ⟹ ?P; ?y < 0 ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹⟦0 < poly p' b; 0 < poly p' a⟧ ⟹ variation (poly p' a) (poly p' b) + sign (poly p' a) = - variation (poly p' a) (poly p' b) + sign (poly p' b)› 2. ‹⟦0 < poly p' b; 0 = poly p' a⟧ ⟹ variation (poly p' a) (poly p' b) + sign (poly p' a) = - variation (poly p' a) (poly p' b) + sign (poly p' b)› 3. ‹⟦0 < poly p' b; poly p' a < 0⟧ ⟹ variation (poly p' a) (poly p' b) + sign (poly p' a) = - variation (poly p' a) (poly p' b) + sign (poly p' b)› discuss goal 1*) apply ((auto simp add:variation_cases (*‹⟦0 < ?x; 0 < ?y⟧ ⟹ variation ?x ?y = 0› ‹⟦0 < ?x; ?y < 0⟧ ⟹ variation ?x ?y = - 1› ‹⟦?x < 0; 0 < ?y⟧ ⟹ variation ?x ?y = 1› ‹⟦?x < 0; ?y < 0⟧ ⟹ variation ?x ?y = 0›*) ‹poly p' a ≠ 0› ‹poly p' b ≠ 0›)[1]) (*discuss goal 2*) apply ((auto simp add:variation_cases (*‹⟦0 < ?x; 0 < ?y⟧ ⟹ variation ?x ?y = 0› ‹⟦0 < ?x; ?y < 0⟧ ⟹ variation ?x ?y = - 1› ‹⟦?x < 0; 0 < ?y⟧ ⟹ variation ?x ?y = 1› ‹⟦?x < 0; ?y < 0⟧ ⟹ variation ?x ?y = 0›*) ‹poly p' a ≠ 0› ‹poly p' b ≠ 0›)[1]) (*discuss goal 3*) apply ((auto simp add:variation_cases (*‹⟦0 < ?x; 0 < ?y⟧ ⟹ variation ?x ?y = 0› ‹⟦0 < ?x; ?y < 0⟧ ⟹ variation ?x ?y = - 1› ‹⟦?x < 0; 0 < ?y⟧ ⟹ variation ?x ?y = 1› ‹⟦?x < 0; ?y < 0⟧ ⟹ variation ?x ?y = 0›*) ‹poly p' a ≠ 0› ‹poly p' b ≠ 0›)[1]) (*proven 3 subgoals*) (*discuss goal 2*) apply ((auto simp add:variation_cases (*‹⟦0 < ?x; 0 < ?y⟧ ⟹ variation ?x ?y = 0› ‹⟦0 < ?x; ?y < 0⟧ ⟹ variation ?x ?y = - 1› ‹⟦?x < 0; 0 < ?y⟧ ⟹ variation ?x ?y = 1› ‹⟦?x < 0; ?y < 0⟧ ⟹ variation ?x ?y = 0›*) ‹poly p' a ≠ 0› ‹poly p' b ≠ 0›)[1]) (*discuss goal 3*) apply ((auto simp add:variation_cases (*‹⟦(0::real) < (?x::real); (0::real) < (?y::real)⟧ ⟹ variation ?x ?y = (0::int)› ‹⟦(0::real) < (?x::real); (?y::real) < (0::real)⟧ ⟹ variation ?x ?y = - (1::int)› ‹⟦(?x::real) < (0::real); (0::real) < (?y::real)⟧ ⟹ variation ?x ?y = (1::int)› ‹⟦(?x::real) < (0::real); (?y::real) < (0::real)⟧ ⟹ variation ?x ?y = (0::int)›*) ‹poly p' a ≠ 0› ‹poly p' b ≠ 0›)[1]) (*goal: ‹poly p' b < 0 ⟹ variation (poly p' a) (poly p' b) + sign (poly p' a) = - variation (poly p' a) (poly p' b) + sign (poly p' b)›*) apply (cases "poly p' a" rule:linorder_cases[of 0] (*‹⟦0 < ?y ⟹ ?P; 0 = ?y ⟹ ?P; ?y < 0 ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹⟦poly p' b < 0; 0 < poly p' a⟧ ⟹ 2 * variation (poly p' a) (poly p' b) + sign (poly p' a) = - 1› 2. ‹⟦poly p' b < 0; 0 = poly p' a⟧ ⟹ 2 * variation (poly p' a) (poly p' b) + sign (poly p' a) = - 1› 3. ‹⟦poly p' b < 0; poly p' a < 0⟧ ⟹ 2 * variation (poly p' a) (poly p' b) + sign (poly p' a) = - 1› discuss goal 1*) apply ((auto simp add:variation_cases (*‹⟦0 < ?x; 0 < ?y⟧ ⟹ variation ?x ?y = 0› ‹⟦0 < ?x; ?y < 0⟧ ⟹ variation ?x ?y = - 1› ‹⟦?x < 0; 0 < ?y⟧ ⟹ variation ?x ?y = 1› ‹⟦?x < 0; ?y < 0⟧ ⟹ variation ?x ?y = 0›*) ‹poly p' a ≠ 0› ‹poly p' b ≠ 0›)[1]) (*discuss goal 2*) apply ((auto simp add:variation_cases (*‹⟦(0::real) < (?x::real); (0::real) < (?y::real)⟧ ⟹ variation ?x ?y = (0::int)› ‹⟦(0::real) < (?x::real); (?y::real) < (0::real)⟧ ⟹ variation ?x ?y = - (1::int)› ‹⟦(?x::real) < (0::real); (0::real) < (?y::real)⟧ ⟹ variation ?x ?y = (1::int)› ‹⟦(?x::real) < (0::real); (?y::real) < (0::real)⟧ ⟹ variation ?x ?y = (0::int)›*) ‹poly p' a ≠ 0› ‹poly p' b ≠ 0›)[1]) (*discuss goal 3*) apply ((auto simp add:variation_cases (*‹⟦0 < ?x; 0 < ?y⟧ ⟹ variation ?x ?y = 0› ‹⟦0 < ?x; ?y < 0⟧ ⟹ variation ?x ?y = - 1› ‹⟦?x < 0; 0 < ?y⟧ ⟹ variation ?x ?y = 1› ‹⟦?x < 0; ?y < 0⟧ ⟹ variation ?x ?y = 0›*) ‹poly p' a ≠ 0› ‹poly p' b ≠ 0›)[1]) (*proven 3 subgoals*) (*proven 3 subgoals*) . ultimately show "?thesis" (*goal: ‹max_r_sign * cross p' a b + jump_poly 1 p max_r = cross p a b›*) unfolding cross_def (*goal: ‹max_r_sign * variation (poly p' a) (poly p' b) + jump_poly 1 p max_r = variation (poly p a) (poly p b)›*) by auto next (*goal: ‹¬ odd (order (max_r::real) (p::real poly)) ⟹ (max_r_sign::int) * cross (p'::real poly) (a::real) (b::real) + jump_poly (1::real poly) p max_r = cross p a b›*) case False (*‹¬ odd (order (max_r::real) (p::real poly))›*) hence "poly max_rp a > 0" and "poly max_rp b > 0" unfolding max_rp_def poly_power (*goals: 1. ‹0 < poly [:- max_r, 1:] a ^ order max_r p› 2. ‹0 < poly [:- max_r, 1:] b ^ order max_r p›*) using ‹poly max_rp a≠0› (*‹poly max_rp a ≠ 0›*) ‹poly max_rp b ≠ 0› (*‹poly max_rp b ≠ 0›*) "1.prems"(1-2) (*‹poly p a ≠ 0› ‹poly p b ≠ 0›*) ‹poly p max_r = 0› (*‹poly p max_r = 0›*) apply - (*goals: 1. ‹⟦¬ odd (order max_r p); poly max_rp a ≠ 0; poly max_rp b ≠ 0; poly p a ≠ 0; poly p b ≠ 0; poly p max_r = 0⟧ ⟹ 0 < poly [:- max_r, 1:] a ^ order max_r p› 2. ‹⟦¬ odd (order max_r p); poly max_rp a ≠ 0; poly max_rp b ≠ 0; poly p a ≠ 0; poly p b ≠ 0; poly p max_r = 0⟧ ⟹ 0 < poly [:- max_r, 1:] b ^ order max_r p› discuss goal 1*) apply ((unfold zero_less_power_eq (*‹(0 < ?a ^ ?n) = (?n = 0 ∨ even ?n ∧ ?a ≠ 0 ∨ odd ?n ∧ 0 < ?a)›*))[1]) (*top goal: ‹⟦¬ odd (order max_r p); poly max_rp a ≠ 0; poly max_rp b ≠ 0; poly p a ≠ 0; poly p b ≠ 0; poly p max_r = 0⟧ ⟹ 0 < poly [:- max_r, 1:] a ^ order max_r p› and 1 goal remains*) apply ((auto)[1]) (*discuss goal 2*) apply ((unfold zero_less_power_eq (*‹(0 < ?a ^ ?n) = (?n = 0 ∨ even ?n ∧ ?a ≠ 0 ∨ odd ?n ∧ 0 < ?a)›*))[1]) (*goal: ‹⟦¬ odd (order (max_r::real) (p::real poly)); poly (max_rp::real poly) (a::real) ≠ (0::real); poly max_rp (b::real) ≠ (0::real); poly p a ≠ (0::real); poly p b ≠ (0::real); poly p max_r = (0::real)⟧ ⟹ (0::real) < poly [:- max_r, 1::real:] b ^ order max_r p›*) apply ((auto)[1]) (*proven 2 subgoals*) . moreover have "poly max_rp b > 0" unfolding max_rp_def poly_power (*goal: ‹0 < poly [:- max_r, 1:] b ^ order max_r p›*) using ‹poly max_rp b ≠ 0› (*‹poly max_rp b ≠ 0›*) False (*‹¬ odd (order max_r p)›*) max_rp_def (*‹max_rp ≡ [:- max_r, 1:] ^ order max_r p›*) poly_power (*‹poly (?p ^ ?n) ?x = poly ?p ?x ^ ?n›*) zero_le_even_power[of "order max_r p" "b - max_r"] (*‹even (order (max_r::real) (p::real poly)) ⟹ (0::real) ≤ ((b::real) - max_r) ^ order max_r p›*) by (auto simp add: le_less (*‹(?x ≤ ?y) = (?x < ?y ∨ ?x = ?y)›*)) ultimately have "?R=cross p' a b" apply (simp only: p' (*‹p = p' * max_rp›*) mult.commute (*‹?a * ?b = ?b * ?a›*) cross_def (*‹cross ?p ?a ?b = variation (poly ?p ?a) (poly ?p ?b)›*)) (*goal: ‹cross p a b = cross p' a b›*) using variation_mult_pos (*‹(0::real) < (?c::real) ⟹ variation (?c * (?x::real)) (?y::real) = variation ?x ?y› ‹0 < ?c ⟹ variation ?x (?c * ?y) = variation ?x ?y›*) by auto thus "?thesis" (*goal: ‹max_r_sign * cross p' a b + jump_poly 1 p max_r = cross p a b›*) unfolding max_r_sign_def jump_poly_def (*goal: ‹(if odd (order max_r p) then - 1 else 1) * cross p' a b + (if p ≠ 0 ∧ 1 ≠ 0 ∧ odd (order max_r p - order max_r 1) then if sign_r_pos (1 * p) max_r then 1 else - 1 else 0) = cross p a b›*) using False (*‹¬ odd (order max_r p)›*) by auto qed ultimately have "sum (jump_poly 1 p) roots = cross p a b " by auto then show "?case" (*goal: ‹cindex_poly a b 1 p = cross p a b›*) unfolding roots_def cindex_poly_def (*goal: ‹(∑x::real | poly p x = (0::real) ∧ (a::real) < x ∧ x < (b::real). jump_poly (1::real poly) (p::real poly) x) = cross p a b›*) by simp next (*goal: ‹⟦poly (p::real poly) (a::real) ≠ (0::real); poly p (b::real) ≠ (0::real); ¬ {x::real. poly p x = (0::real) ∧ a < x ∧ x < b} ≠ {}⟧ ⟹ cindex_poly a b (1::real poly) p = cross p a b›*) case False (*‹¬ {x. poly p x = 0 ∧ a < x ∧ x < b} ≠ {}›*) hence "cross p a b=0" using cross_no_root[OF ‹a<b›] (*‹∀x. a < x ∧ x < b ⟶ poly ?p x ≠ 0 ⟹ cross ?p a b = 0›*) by auto thus "?thesis" (*goal: ‹cindex_poly a b 1 p = cross p a b›*) using False (*‹¬ {x::real. poly (p::real poly) x = (0::real) ∧ (a::real) < x ∧ x < (b::real)} ≠ {}›*) unfolding cindex_poly_def (*goal: ‹(∑x | poly p x = 0 ∧ a < x ∧ x < b. jump_poly 1 p x) = cross p a b›*) by (metis sum.empty (*‹sum ?g {} = 0›*)) qed lemma cindex_poly_mult: fixes p q p'::"real poly" assumes "p'≠ 0" shows "cindex_poly a b (p' * q ) (p' * p) = cindex_poly a b q p" proof (cases "p=0") (*goals: 1. ‹(p::real poly) = (0::real poly) ⟹ cindex_poly (a::real) (b::real) ((p'::real poly) * (q::real poly)) (p' * p) = cindex_poly a b q p› 2. ‹(p::real poly) ≠ (0::real poly) ⟹ cindex_poly (a::real) (b::real) ((p'::real poly) * (q::real poly)) (p' * p) = cindex_poly a b q p›*) case True (*‹p = 0›*) then show "?thesis" (*goal: ‹cindex_poly a b (p' * q) (p' * p) = cindex_poly a b q p›*) by auto next (*goal: ‹p ≠ 0 ⟹ cindex_poly a b (p' * q) (p' * p) = cindex_poly a b q p›*) case False (*‹p ≠ 0›*) show "?thesis" (*goal: ‹cindex_poly a b (p' * q) (p' * p) = cindex_poly a b q p›*) unfolding cindex_poly_def (*goal: ‹(∑x | poly (p' * p) x = 0 ∧ a < x ∧ x < b. jump_poly (p' * q) (p' * p) x) = (∑x | poly p x = 0 ∧ a < x ∧ x < b. jump_poly q p x)›*) apply (rule sum.mono_neutral_cong_right (*‹⟦finite ?T; ?S ⊆ ?T; ∀i∈?T - ?S. ?g i = 0; ⋀x. x ∈ ?S ⟹ ?g x = ?h x⟧ ⟹ sum ?g ?T = sum ?h ?S›*)) (*goal: ‹(∑x::real | poly (p' * p) x = (0::real) ∧ (a::real) < x ∧ x < (b::real). jump_poly ((p'::real poly) * (q::real poly)) (p' * (p::real poly)) x) = (∑x::real | poly p x = (0::real) ∧ a < x ∧ x < b. jump_poly q p x)›*) subgoal for using ‹p≠0› (*‹p ≠ 0›*) ‹p'≠0› (*‹p' ≠ 0›*) by (simp add: poly_roots_finite (*‹?p ≠ 0 ⟹ finite {x. poly ?p x = 0}›*)) subgoal for by auto subgoal for using jump_poly_mult (*‹?p' ≠ 0 ⟹ jump_poly (?p' * ?q) (?p' * ?p) ?x = jump_poly ?q ?p ?x›*) jump_poly_not_root (*‹poly (?p::real poly) (?x::real) ≠ (0::real) ⟹ jump_poly (?q::real poly) ?p ?x = (0::int)›*) assms (*‹(p'::real poly) ≠ (0::real poly)›*) by fastforce subgoal for x using jump_poly_mult[OF ‹p'≠0›] (*‹jump_poly (p' * ?q) (p' * ?p) ?x = jump_poly ?q ?p ?x›*) by auto . qed lemma cindex_poly_smult_1: fixes p q::"real poly" and c::real shows "cindex_poly a b (smult c q) p = (sign c) * cindex_poly a b q p" unfolding cindex_poly_def (*goal: ‹(∑x::real | poly p x = (0::real) ∧ (a::real) < x ∧ x < (b::real). jump_poly (smult (c::real) (q::real poly)) (p::real poly) x) = sign c * (∑x::real | poly p x = (0::real) ∧ a < x ∧ x < b. jump_poly q p x)›*) using sum_distrib_left[THEN sym, of "sign c" "λx. jump_poly q p x" "{x. poly p x = (0::real) ∧ a < x ∧ x < b}"] (*‹(∑n∈{x. poly p x = 0 ∧ a < x ∧ x < b}. sign c * jump_poly q p n) = sign c * (∑x | poly p x = 0 ∧ a < x ∧ x < b. jump_poly q p x)›*) jump_poly_smult_1 (*‹jump_poly (smult ?c ?q) ?p ?x = sign ?c * jump_poly ?q ?p ?x›*) by auto lemma cindex_poly_mod: fixes p q::"real poly" shows "cindex_poly a b q p = cindex_poly a b (q mod p) p" unfolding cindex_poly_def (*goal: ‹(∑x | poly p x = 0 ∧ a < x ∧ x < b. jump_poly q p x) = (∑x | poly p x = 0 ∧ a < x ∧ x < b. jump_poly (q mod p) p x)›*) using jump_poly_mod (*‹jump_poly ?q ?p ?x = jump_poly (?q mod ?p) ?p ?x›*) by auto lemma cindex_poly_inverse_add: fixes p q::"real poly" assumes "coprime p q" shows "cindex_poly a b q p + cindex_poly a b p q=cindex_poly a b 1 (q*p)" (is "?L=?R") proof (cases "p=0 ∨ q=0") (*goals: 1. ‹p = 0 ∨ q = 0 ⟹ cindex_poly a b q p + cindex_poly a b p q = cindex_poly a b 1 (q * p)› 2. ‹¬ (p = 0 ∨ q = 0) ⟹ cindex_poly a b q p + cindex_poly a b p q = cindex_poly a b 1 (q * p)›*) case True (*‹p = 0 ∨ q = 0›*) then show "?thesis" (*goal: ‹cindex_poly a b q p + cindex_poly a b p q = cindex_poly a b 1 (q * p)›*) by auto next (*goal: ‹¬ ((p::real poly) = (0::real poly) ∨ (q::real poly) = (0::real poly)) ⟹ cindex_poly (a::real) (b::real) q p + cindex_poly a b p q = cindex_poly a b (1::real poly) (q * p)›*) case False (*‹¬ (p = 0 ∨ q = 0)›*) then have "p≠0" "q≠0" apply - (*goals: 1. ‹¬ (p = 0 ∨ q = 0) ⟹ p ≠ 0› 2. ‹¬ (p = 0 ∨ q = 0) ⟹ q ≠ 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . define A where "A≡{x. poly p x = 0 ∧ a < x ∧ x < b}" define B where "B≡{x. poly q x = 0 ∧ a < x ∧ x < b}" have "?L = sum (λx. jump_poly 1 (q*p) x) A + sum (λx. jump_poly 1 (q*p) x) B" proof (-) (*goal: ‹cindex_poly a b q p + cindex_poly a b p q = sum (jump_poly 1 (q * p)) A + sum (jump_poly 1 (q * p)) B›*) have "cindex_poly a b q p = sum (λx. jump_poly 1 (q*p) x) A" unfolding A_def cindex_poly_def (*goal: ‹(∑x | poly p x = 0 ∧ a < x ∧ x < b. jump_poly q p x) = (∑x | poly p x = 0 ∧ a < x ∧ x < b. jump_poly 1 (q * p) x)›*) using jump_poly_coprime[OF _ ‹coprime p q›] (*‹poly p ?x = 0 ⟹ jump_poly q p ?x = jump_poly 1 (q * p) ?x›*) by auto moreover have "coprime q p" using ‹coprime p q› (*‹coprime (p::real poly) (q::real poly)›*) by (simp add: ac_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹((?a ∧ ?b) ∧ ?c) = (?a ∧ ?b ∧ ?c)› ‹(?a ∧ ?b) = (?b ∧ ?a)› ‹(?b ∧ ?a ∧ ?c) = (?a ∧ ?b ∧ ?c)› ‹((?a ∨ ?b) ∨ ?c) = (?a ∨ ?b ∨ ?c)› ‹(?a ∨ ?b) = (?b ∨ ?a)› ‹(?b ∨ ?a ∨ ?c) = (?a ∨ ?b ∨ ?c)› and more 36 facts*)) hence "cindex_poly a b p q = sum (λx. jump_poly 1 (q*p) x) B" unfolding B_def cindex_poly_def (*goal: ‹(∑x | poly q x = 0 ∧ a < x ∧ x < b. jump_poly p q x) = (∑x | poly q x = 0 ∧ a < x ∧ x < b. jump_poly 1 (q * p) x)›*) using jump_poly_coprime[of q _ p] (*‹⟦poly q ?x = 0; coprime q p⟧ ⟹ jump_poly p q ?x = jump_poly 1 (p * q) ?x›*) by (auto simp add: ac_simps (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)› ‹(?a::?'a) * (?b::?'a) * (?c::?'a) = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)› ‹(((?a::bool) ∧ (?b::bool)) ∧ (?c::bool)) = (?a ∧ ?b ∧ ?c)› ‹((?a::bool) ∧ (?b::bool)) = (?b ∧ ?a)› ‹((?b::bool) ∧ (?a::bool) ∧ (?c::bool)) = (?a ∧ ?b ∧ ?c)› ‹(((?a::bool) ∨ (?b::bool)) ∨ (?c::bool)) = (?a ∨ ?b ∨ ?c)› ‹((?a::bool) ∨ (?b::bool)) = (?b ∨ ?a)› ‹((?b::bool) ∨ (?a::bool) ∨ (?c::bool)) = (?a ∨ ?b ∨ ?c)› and more 36 facts*)) ultimately show "?thesis" (*goal: ‹cindex_poly a b q p + cindex_poly a b p q = sum (jump_poly 1 (q * p)) A + sum (jump_poly 1 (q * p)) B›*) by auto qed moreover have "A ∪ B= {x. poly (q*p) x=0 ∧ a<x ∧ x<b }" unfolding poly_mult A_def B_def (*goal: ‹{x::real. poly (p::real poly) x = (0::real) ∧ (a::real) < x ∧ x < (b::real)} ∪ {x::real. poly (q::real poly) x = (0::real) ∧ a < x ∧ x < b} = {x::real. poly q x * poly p x = (0::real) ∧ a < x ∧ x < b}›*) by auto moreover have "A ∩ B={}" proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹(A::real set) ∩ (B::real set) ≠ {} ⟹ False›*) assume "A ∩ B≠{}" (*‹(A::real set) ∩ (B::real set) ≠ {}›*) then obtain x where "x∈A" and "x∈B" (*goal: ‹(⋀x. ⟦x ∈ A; x ∈ B⟧ ⟹ thesis) ⟹ thesis›*) by auto hence "poly p x=0" and "poly q x=0" unfolding A_def B_def (*goals: 1. ‹poly (p::real poly) (x::real) = (0::real)› 2. ‹poly (q::real poly) (x::real) = (0::real)›*) apply - (*goals: 1. ‹⟦x ∈ {x. poly p x = 0 ∧ a < x ∧ x < b}; x ∈ {x. poly q x = 0 ∧ a < x ∧ x < b}⟧ ⟹ poly p x = 0› 2. ‹⟦x ∈ {x. poly p x = 0 ∧ a < x ∧ x < b}; x ∈ {x. poly q x = 0 ∧ a < x ∧ x < b}⟧ ⟹ poly q x = 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . hence "gcd p q≠1" by (metis poly_1 (*‹poly 1 ?x = 1›*) poly_eq_0_iff_dvd (*‹(poly ?p ?c = 0) = ([:- ?c, 1:] dvd ?p)›*) gcd_greatest (*‹⟦?c dvd ?a; ?c dvd ?b⟧ ⟹ ?c dvd gcd ?a ?b›*) zero_neq_one (*‹0 ≠ 1›*)) thus False using ‹coprime p q› (*‹coprime p q›*) by auto qed moreover have "finite A" and "finite B" unfolding A_def B_def (*goals: 1. ‹finite {x. poly p x = 0 ∧ a < x ∧ x < b}› 2. ‹finite {x. poly q x = 0 ∧ a < x ∧ x < b}›*) using poly_roots_finite (*‹?p ≠ 0 ⟹ finite {x. poly ?p x = 0}›*) ‹p≠0› (*‹p ≠ 0›*) ‹q≠0› (*‹q ≠ 0›*) apply - (*goals: 1. ‹⟦⋀p. p ≠ 0 ⟹ finite {x. poly p x = 0}; p ≠ 0; q ≠ 0⟧ ⟹ finite {x. poly p x = 0 ∧ a < x ∧ x < b}› 2. ‹⟦⋀p. p ≠ 0 ⟹ finite {x. poly p x = 0}; p ≠ 0; q ≠ 0⟧ ⟹ finite {x. poly q x = 0 ∧ a < x ∧ x < b}› discuss goal 1*) apply fast (*discuss goal 2*) apply fast (*proven 2 subgoals*) . ultimately have "cindex_poly a b q p + cindex_poly a b p q = sum (jump_poly 1 (q * p)) {x. poly (q*p) x=0 ∧ a<x ∧ x<b}" using sum.union_disjoint (*‹⟦finite ?A; finite ?B; ?A ∩ ?B = {}⟧ ⟹ sum ?g (?A ∪ ?B) = sum ?g ?A + sum ?g ?B›*) by metis then show "?thesis" (*goal: ‹cindex_poly a b q p + cindex_poly a b p q = cindex_poly a b 1 (q * p)›*) unfolding cindex_poly_def (*goal: ‹(∑x | poly p x = 0 ∧ a < x ∧ x < b. jump_poly q p x) + (∑x | poly q x = 0 ∧ a < x ∧ x < b. jump_poly p q x) = (∑x | poly (q * p) x = 0 ∧ a < x ∧ x < b. jump_poly 1 (q * p) x)›*) by auto qed lemma cindex_poly_inverse_add_cross: fixes p q::"real poly" assumes "a < b" "poly (p * q) a ≠0" "poly (p * q) b ≠0" shows "cindex_poly a b q p + cindex_poly a b p q = cross (p * q) a b" (is "?L=?R") proof (-) (*goal: ‹cindex_poly a b q p + cindex_poly a b p q = cross (p * q) a b›*) have "p≠0" and "q≠0" using ‹poly (p * q) a ≠0› (*‹poly (p * q) a ≠ 0›*) apply - (*goals: 1. ‹poly (p * q) a ≠ 0 ⟹ p ≠ 0› 2. ‹poly (p * q) a ≠ 0 ⟹ q ≠ 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . define g where "g≡gcd p q" obtain p' and q' where p': "p= p'*g" and q': "q=q'*g" (*goal: ‹(⋀p' q'. ⟦p = p' * g; q = q' * g⟧ ⟹ thesis) ⟹ thesis›*) using gcd_dvd1 (*‹gcd ?a ?b dvd ?a›*) gcd_dvd2 (*‹gcd (?a::?'a) (?b::?'a) dvd ?b›*) dvd_def[of "gcd p q", simplified mult.commute] (*‹(gcd p q dvd ?a) = (∃k. ?a = k * gcd p q)›*) g_def (*‹g ≡ gcd p q›*) by metis hence "coprime p' q'" using gcd_coprime (*‹⟦gcd (?a::?'a::semiring_gcd) (?b::?'a::semiring_gcd) ≠ (0::?'a::semiring_gcd); ?a = (?a'::?'a::semiring_gcd) * gcd ?a ?b; ?b = (?b'::?'a::semiring_gcd) * gcd ?a ?b⟧ ⟹ coprime ?a' ?b'›*) ‹p≠0› (*‹(p::real poly) ≠ (0::real poly)›*) unfolding g_def (*goal: ‹coprime p' q'›*) by auto have "p'≠0" "q'≠0" "g ≠0" using p' (*‹p = p' * g›*) q' (*‹q = q' * g›*) ‹p≠0› (*‹p ≠ 0›*) ‹q≠0› (*‹(q::real poly) ≠ (0::real poly)›*) apply - (*goals: 1. ‹⟦(p::real poly) = (p'::real poly) * (g::real poly); (q::real poly) = (q'::real poly) * g; p ≠ (0::real poly); q ≠ (0::real poly)⟧ ⟹ p' ≠ (0::real poly)› 2. ‹⟦(p::real poly) = (p'::real poly) * (g::real poly); (q::real poly) = (q'::real poly) * g; p ≠ (0::real poly); q ≠ (0::real poly)⟧ ⟹ q' ≠ (0::real poly)› 3. ‹⟦(p::real poly) = (p'::real poly) * (g::real poly); (q::real poly) = (q'::real poly) * g; p ≠ (0::real poly); q ≠ (0::real poly)⟧ ⟹ g ≠ (0::real poly)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . have "?L=cindex_poly a b q' p' + cindex_poly a b p' q'" apply (simp only: p' (*‹p = p' * g›*) q' (*‹q = q' * g›*) mult.commute (*‹?a * ?b = ?b * ?a›*)) (*goal: ‹cindex_poly a b q p + cindex_poly a b p q = cindex_poly a b q' p' + cindex_poly a b p' q'›*) using cindex_poly_mult[OF ‹g≠0›] (*‹cindex_poly ?a ?b (g * ?q) (g * ?p) = cindex_poly ?a ?b ?q ?p›*) cindex_poly_mult[OF ‹g≠0›] (*‹cindex_poly ?a ?b (g * ?q) (g * ?p) = cindex_poly ?a ?b ?q ?p›*) by auto also (*calculation: ‹cindex_poly a b q p + cindex_poly a b p q = cindex_poly a b q' p' + cindex_poly a b p' q'›*) have "... = cindex_poly a b 1 (q' * p')" using cindex_poly_inverse_add[OF ‹coprime p' q'›, of a b] (*‹cindex_poly a b q' p' + cindex_poly a b p' q' = cindex_poly a b 1 (q' * p')›*) . also (*calculation: ‹cindex_poly a b q p + cindex_poly a b p q = cindex_poly a b 1 (q' * p')›*) have "... = cross (p' * q') a b" using cindex_poly_cross[OF ‹a<b›, of "q'*p'"] (*‹⟦poly (q' * p') a ≠ 0; poly (q' * p') b ≠ 0⟧ ⟹ cindex_poly a b 1 (q' * p') = cross (q' * p') a b›*) ‹p'≠0› (*‹(p'::real poly) ≠ (0::real poly)›*) ‹q'≠0› (*‹q' ≠ 0›*) ‹poly (p * q) a ≠0› (*‹poly ((p::real poly) * (q::real poly)) (a::real) ≠ (0::real)›*) ‹poly (p * q) b ≠0› (*‹poly (p * q) b ≠ 0›*) unfolding p' q' (*goal: ‹cindex_poly (a::real) (b::real) (1::real poly) ((q'::real poly) * (p'::real poly)) = cross (p' * q') a b›*) apply (subst (2) mult.commute (*‹?a * ?b = ?b * ?a›*)) (*goal: ‹cindex_poly a b 1 (q' * p') = cross (p' * q') a b›*) by auto also (*calculation: ‹cindex_poly a b q p + cindex_poly a b p q = cross (p' * q') a b›*) have "... = ?R" proof (-) (*goal: ‹cross (p' * q') a b = cross (p * q) a b›*) have "poly (p * q) a = poly (g*g) a * poly (p' * q') a" and "poly (p * q) b = poly (g*g) b * poly (p' * q') b" unfolding p' q' (*goals: 1. ‹poly ((p'::real poly) * (g::real poly) * ((q'::real poly) * g)) (a::real) = poly (g * g) a * poly (p' * q') a› 2. ‹poly ((p'::real poly) * (g::real poly) * ((q'::real poly) * g)) (b::real) = poly (g * g) b * poly (p' * q') b›*) (*goals: 1. ‹poly (p' * g * (q' * g)) a = poly (g * g) a * poly (p' * q') a› 2. ‹poly (p' * g * (q' * g)) b = poly (g * g) b * poly (p' * q') b› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . moreover have "poly g a≠0" using ‹poly (p * q) a ≠0› (*‹poly ((p::real poly) * (q::real poly)) (a::real) ≠ (0::real)›*) unfolding p' (*goal: ‹poly g a ≠ 0›*) by auto hence "poly (g*g) a>0" by (metis (poly_guards_query) not_real_square_gt_zero (*‹(¬ 0 < ?x * ?x) = (?x = 0)›*) poly_mult (*‹poly (?p * ?q) ?x = poly ?p ?x * poly ?q ?x›*)) moreover have "poly g b≠0" using ‹poly (p * q) b ≠0› (*‹poly ((p::real poly) * (q::real poly)) (b::real) ≠ (0::real)›*) unfolding p' (*goal: ‹poly g b ≠ 0›*) by auto hence "poly (g*g) b>0" by (metis (poly_guards_query) not_real_square_gt_zero (*‹(¬ (0::real) < (?x::real) * ?x) = (?x = (0::real))›*) poly_mult (*‹poly ((?p::?'a::comm_semiring_0 poly) * (?q::?'a::comm_semiring_0 poly)) (?x::?'a::comm_semiring_0) = poly ?p ?x * poly ?q ?x›*)) ultimately show "?thesis" (*goal: ‹cross ((p'::real poly) * (q'::real poly)) (a::real) (b::real) = cross ((p::real poly) * (q::real poly)) a b›*) unfolding cross_def (*goal: ‹variation (poly (p' * q') a) (poly (p' * q') b) = variation (poly (p * q) a) (poly (p * q) b)›*) using variation_mult_pos (*‹0 < ?c ⟹ variation (?c * ?x) ?y = variation ?x ?y› ‹0 < ?c ⟹ variation ?x (?c * ?y) = variation ?x ?y›*) by auto qed finally (*calculation: ‹cindex_poly (a::real) (b::real) (q::real poly) (p::real poly) + cindex_poly a b p q = cross (p * q) a b›*) show "?L = ?R" . qed lemma cindex_poly_rec: fixes p q::"real poly" assumes "a < b" "poly (p * q) a ≠0" "poly (p * q) b ≠0" shows "cindex_poly a b q p = cross (p * q) a b + cindex_poly a b (- (p mod q)) q" (is "?L=?R") proof (-) (*goal: ‹cindex_poly a b q p = cross (p * q) a b + cindex_poly a b (- (p mod q)) q›*) have "q≠0" using ‹poly (p * q) a ≠0› (*‹poly (p * q) a ≠ 0›*) by auto note cindex_poly_inverse_add_cross[OF assms] (*‹cindex_poly a b q p + cindex_poly a b p q = cross (p * q) a b›*) moreover have "- cindex_poly a b p q = cindex_poly a b (- (p mod q)) q" using cindex_poly_mod (*‹cindex_poly ?a ?b ?q ?p = cindex_poly ?a ?b (?q mod ?p) ?p›*) cindex_poly_smult_1[of a b "-1"] (*‹cindex_poly a b (smult (- 1) ?q) ?p = sign (- 1) * cindex_poly a b ?q ?p›*) by auto ultimately show "?thesis" (*goal: ‹cindex_poly (a::real) (b::real) (q::real poly) (p::real poly) = cross (p * q) a b + cindex_poly a b (- (p mod q)) q›*) by auto qed lemma cindex_poly_congr: fixes p q:: "real poly" assumes "a<a'" "a'<b'" "b'<b" assumes "∀x. ((a<x∧x≤a') ∨ (b'≤x ∧ x<b)) ⟶ poly p x ≠0" shows "cindex_poly a b q p=cindex_poly a' b' q p" proof (cases "p=0") (*goals: 1. ‹p = 0 ⟹ cindex_poly a b q p = cindex_poly a' b' q p› 2. ‹p ≠ 0 ⟹ cindex_poly a b q p = cindex_poly a' b' q p›*) case True (*‹p = 0›*) then show "?thesis" (*goal: ‹cindex_poly a b q p = cindex_poly a' b' q p›*) by auto next (*goal: ‹p ≠ 0 ⟹ cindex_poly a b q p = cindex_poly a' b' q p›*) case False (*‹p ≠ 0›*) show "?thesis" (*goal: ‹cindex_poly a b q p = cindex_poly a' b' q p›*) unfolding cindex_poly_def (*goal: ‹(∑x | poly p x = 0 ∧ a < x ∧ x < b. jump_poly q p x) = (∑x | poly p x = 0 ∧ a' < x ∧ x < b'. jump_poly q p x)›*) apply (rule sum.mono_neutral_right (*‹⟦finite ?T; ?S ⊆ ?T; ∀i∈?T - ?S. ?g i = 0⟧ ⟹ sum ?g ?T = sum ?g ?S›*)) (*goal: ‹(∑x::real | poly p x = (0::real) ∧ (a::real) < x ∧ x < (b::real). jump_poly (q::real poly) (p::real poly) x) = (∑x::real | poly p x = (0::real) ∧ (a'::real) < x ∧ x < (b'::real). jump_poly q p x)›*) subgoal for using poly_roots_finite[OF ‹p≠0›] (*‹finite {x::real. poly (p::real poly) x = (0::real)}›*) by auto subgoal for using assms (*‹a < a'› ‹a' < b'› ‹b' < b› ‹∀x::real. (a::real) < x ∧ x ≤ (a'::real) ∨ (b'::real) ≤ x ∧ x < (b::real) ⟶ poly (p::real poly) x ≠ (0::real)›*) by auto subgoal for using assms(4) (*‹∀x. a < x ∧ x ≤ a' ∨ b' ≤ x ∧ x < b ⟶ poly p x ≠ 0›*) by fastforce . qed lemma greaterThanLessThan_unfold:"{a<..<b} = {x. a<x ∧ x<b}" by fastforce lemma cindex_poly_taq: fixes p q::"real poly" shows "taq {x. poly p x = 0 ∧ a < x ∧ x < b} q=cindex_poly a b (pderiv p * q) p" proof (cases "p=0") (*goals: 1. ‹p = 0 ⟹ taq {x. poly p x = 0 ∧ a < x ∧ x < b} q = cindex_poly a b (pderiv p * q) p› 2. ‹p ≠ 0 ⟹ taq {x. poly p x = 0 ∧ a < x ∧ x < b} q = cindex_poly a b (pderiv p * q) p›*) case True (*‹p = 0›*) define S where "S={x. poly p x = 0 ∧ a < x ∧ x < b}" have "?thesis" if "a≥b" proof (-) (*goal: ‹taq {x. poly p x = 0 ∧ a < x ∧ x < b} q = cindex_poly a b (pderiv p * q) p›*) have "S = {}" using that (*‹b ≤ a›*) unfolding S_def (*goal: ‹{x. poly p x = 0 ∧ a < x ∧ x < b} = {}›*) by auto then show "?thesis" (*goal: ‹taq {x. poly p x = 0 ∧ a < x ∧ x < b} q = cindex_poly a b (pderiv p * q) p›*) using True (*‹p = 0›*) unfolding taq_def (*goal: ‹(∑x | poly p x = 0 ∧ a < x ∧ x < b. sign (poly q x)) = cindex_poly a b (pderiv p * q) p›*) apply (fold S_def) (*goal: ‹(∑x | poly p x = 0 ∧ a < x ∧ x < b. sign (poly q x)) = cindex_poly a b (pderiv p * q) p›*) by simp qed moreover have "?thesis" if "a<b" proof (-) (*goal: ‹taq {x. poly p x = 0 ∧ a < x ∧ x < b} q = cindex_poly a b (pderiv p * q) p›*) have "infinite {x. a<x ∧ x<b}" using infinite_Ioo[OF ‹a<b›] (*‹infinite {a::real<..<b::real}›*) unfolding greaterThanLessThan_unfold (*goal: ‹infinite {x. a < x ∧ x < b}›*) by simp then have "infinite S" unfolding S_def (*goal: ‹infinite {x. poly p x = 0 ∧ a < x ∧ x < b}›*) using True (*‹(p::real poly) = (0::real poly)›*) by auto then show "?thesis" (*goal: ‹taq {x. poly p x = 0 ∧ a < x ∧ x < b} q = cindex_poly a b (pderiv p * q) p›*) using True (*‹p = 0›*) unfolding taq_def (*goal: ‹(∑x::real | poly (p::real poly) x = (0::real) ∧ (a::real) < x ∧ x < (b::real). sign (poly (q::real poly) x)) = cindex_poly a b (pderiv p * q) p›*) apply (fold S_def) (*goal: ‹(∑x | poly p x = 0 ∧ a < x ∧ x < b. sign (poly q x)) = cindex_poly a b (pderiv p * q) p›*) by simp qed ultimately show "?thesis" (*goal: ‹taq {x::real. poly (p::real poly) x = (0::real) ∧ (a::real) < x ∧ x < (b::real)} (q::real poly) = cindex_poly a b (pderiv p * q) p›*) by fastforce next (*goal: ‹p ≠ 0 ⟹ taq {x. poly p x = 0 ∧ a < x ∧ x < b} q = cindex_poly a b (pderiv p * q) p›*) case False (*‹p ≠ 0›*) show "?thesis" (*goal: ‹taq {x::real. poly (p::real poly) x = (0::real) ∧ (a::real) < x ∧ x < (b::real)} (q::real poly) = cindex_poly a b (pderiv p * q) p›*) unfolding cindex_poly_def taq_def (*goal: ‹(∑x::real | poly (p::real poly) x = (0::real) ∧ (a::real) < x ∧ x < (b::real). sign (poly (q::real poly) x)) = (∑x::real | poly p x = (0::real) ∧ a < x ∧ x < b. jump_poly (pderiv p * q) p x)›*) apply (rule sum.cong (*‹⟦?A = ?B; ⋀x. x ∈ ?B ⟹ ?g x = ?h x⟧ ⟹ sum ?g ?A = sum ?h ?B›*)) (*goals: 1. ‹{x. poly p x = 0 ∧ a < x ∧ x < b} = {x. poly p x = 0 ∧ a < x ∧ x < b}› 2. ‹⋀x. x ∈ {x. poly p x = 0 ∧ a < x ∧ x < b} ⟹ sign (poly q x) = jump_poly (pderiv p * q) p x› discuss goal 1*) apply ((auto simp add:jump_poly_sgn[OF ‹p≠0›] (*‹poly p ?x = 0 ⟹ jump_poly (pderiv p * ?q) p ?x = sign (poly ?q ?x)›*))[1]) (*discuss goal 2*) apply ((auto simp add:jump_poly_sgn[OF ‹p≠0›] (*‹poly p ?x = 0 ⟹ jump_poly (pderiv p * ?q) p ?x = sign (poly ?q ?x)›*))[1]) (*proven 2 subgoals*) . qed subsection‹Signed remainder sequence› function smods:: "real poly ⇒ real poly ⇒ (real poly) list" where "smods p q= (if p=0 then [] else Cons p (smods q (-(p mod q))))" by auto termination apply (relation "measure (λ(p,q).if p=0 then 0 else if q=0 then 1 else 2+degree q)") apply simp_all apply (metis degree_mod_less) done lemma smods_nil_eq:"smods p q = [] ⟷ (p=0)" by auto lemma smods_singleton:"[x] = smods p q ⟹ (p≠0 ∧ q=0 ∧ x=p)" by (metis list.discI (*‹?list = ?x21.0 # ?x22.0 ⟹ ?list ≠ []›*) list.inject (*‹(?x21.0 # ?x22.0 = ?y21.0 # ?y22.0) = (?x21.0 = ?y21.0 ∧ ?x22.0 = ?y22.0)›*) smods.elims (*‹⟦smods ?x ?xa = ?y; ⋀p q. ⟦?x = p; ?xa = q; ?y = (if p = 0 then [] else p # smods q (- (p mod q)))⟧ ⟹ ?P⟧ ⟹ ?P›*)) lemma smods_0[simp]: "smods 0 q = []" "smods p 0 = (if p=0 then [] else [p])" (*goals: 1. ‹smods (0::real poly) (q::real poly) = []› 2. ‹smods (p::real poly) (0::real poly) = (if p = (0::real poly) then [] else [p])› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma no_0_in_smods: "0∉set (smods p q)" apply (induct "smods p q" arbitrary:p q) (*goals: 1. ‹⋀p q. [] = smods p q ⟹ 0 ∉ set (smods p q)› 2. ‹⋀a x p q. ⟦⋀p q. x = smods p q ⟹ 0 ∉ set (smods p q); a # x = smods p q⟧ ⟹ 0 ∉ set (smods p q)› discuss goal 1*) apply simp (*discuss goal 2*) apply (metis list.inject (*‹(?x21.0 # ?x22.0 = ?y21.0 # ?y22.0) = (?x21.0 = ?y21.0 ∧ ?x22.0 = ?y22.0)›*) neq_Nil_conv (*‹(?xs ≠ []) = (∃y ys. ?xs = y # ys)›*) set_ConsD (*‹?y ∈ set (?x # ?xs) ⟹ ?y = ?x ∨ ?y ∈ set ?xs›*) smods.elims (*‹⟦smods ?x ?xa = ?y; ⋀p q. ⟦?x = p; ?xa = q; ?y = (if p = 0 then [] else p # smods q (- (p mod q)))⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*proven 2 subgoals*) . fun changes:: "('a ::linordered_idom) list ⇒ int" where "changes [] = 0"| "changes [_] = 0" | "changes (x1#x2#xs) = (if x1*x2<0 then 1+changes (x2#xs) else if x2=0 then changes (x1#xs) else changes (x2#xs))" lemma changes_map_sgn_eq: "changes xs = changes (map sgn xs)" proof (induct xs rule:changes.induct (*‹⟦?P []; ⋀uu_. ?P [uu_]; ⋀x1 x2 xs. ⟦x1 * x2 < 0 ⟹ ?P (x2 # xs); ⟦¬ x1 * x2 < 0; x2 = 0⟧ ⟹ ?P (x1 # xs); ⟦¬ x1 * x2 < 0; x2 ≠ 0⟧ ⟹ ?P (x2 # xs)⟧ ⟹ ?P (x1 # x2 # xs)⟧ ⟹ ?P ?a0.0›*)) (*goals: 1. ‹changes [] = changes (map sgn [])› 2. ‹⋀uu_. changes [uu_] = changes (map sgn [uu_])› 3. ‹⋀x1 x2 xs. ⟦x1 * x2 < 0 ⟹ changes (x2 # xs) = changes (map sgn (x2 # xs)); ⟦¬ x1 * x2 < 0; x2 = 0⟧ ⟹ changes (x1 # xs) = changes (map sgn (x1 # xs)); ⟦¬ x1 * x2 < 0; x2 ≠ 0⟧ ⟹ changes (x2 # xs) = changes (map sgn (x2 # xs))⟧ ⟹ changes (x1 # x2 # xs) = changes (map sgn (x1 # x2 # xs))›*) case (3 x1 x2 xs) (*‹x1 * x2 < 0 ⟹ changes (x2 # xs) = changes (map sgn (x2 # xs))› ‹⟦¬ x1 * x2 < 0; x2 = 0⟧ ⟹ changes (x1 # xs) = changes (map sgn (x1 # xs))› ‹⟦¬ x1 * x2 < 0; x2 ≠ 0⟧ ⟹ changes (x2 # xs) = changes (map sgn (x2 # xs))›*) moreover have "x1*x2<0 ⟷ sgn x1 * sgn x2 < 0" apply (unfold mult_less_0_iff (*‹((?a::?'a) * (?b::?'a) < (0::?'a)) = ((0::?'a) < ?a ∧ ?b < (0::?'a) ∨ ?a < (0::?'a) ∧ (0::?'a) < ?b)›*) sgn_less (*‹(sgn (?a::?'a) < (0::?'a)) = (?a < (0::?'a))›*) sgn_greater (*‹((0::?'a) < sgn (?a::?'a)) = ((0::?'a) < ?a)›*)) (*goal: ‹(x1 * x2 < 0) = (sgn x1 * sgn x2 < 0)›*) by simp moreover have "x2=0 ⟷ sgn x2 =0" by (rule sgn_0_0[symmetric] (*‹(?a = 0) = (sgn ?a = 0)›*)) ultimately show "?case" (*goal: ‹changes (x1 # x2 # xs) = changes (map sgn (x1 # x2 # xs))›*) by auto qed (simp_all) (*solves the remaining goals: 1. ‹changes [] = changes (map sgn [])› 2. ‹⋀uu_. changes [uu_] = changes (map sgn [uu_])›*) lemma changes_map_sign_eq: "changes xs = changes (map sign xs)" proof (induct xs rule:changes.induct (*‹⟦?P []; ⋀uu_. ?P [uu_]; ⋀x1 x2 xs. ⟦x1 * x2 < 0 ⟹ ?P (x2 # xs); ⟦¬ x1 * x2 < 0; x2 = 0⟧ ⟹ ?P (x1 # xs); ⟦¬ x1 * x2 < 0; x2 ≠ 0⟧ ⟹ ?P (x2 # xs)⟧ ⟹ ?P (x1 # x2 # xs)⟧ ⟹ ?P ?a0.0›*)) (*goals: 1. ‹changes [] = changes (map sign [])› 2. ‹⋀uu_. changes [uu_] = changes (map sign [uu_])› 3. ‹⋀x1 x2 xs. ⟦x1 * x2 < 0 ⟹ changes (x2 # xs) = changes (map sign (x2 # xs)); ⟦¬ x1 * x2 < 0; x2 = 0⟧ ⟹ changes (x1 # xs) = changes (map sign (x1 # xs)); ⟦¬ x1 * x2 < 0; x2 ≠ 0⟧ ⟹ changes (x2 # xs) = changes (map sign (x2 # xs))⟧ ⟹ changes (x1 # x2 # xs) = changes (map sign (x1 # x2 # xs))›*) case (3 x1 x2 xs) (*‹x1 * x2 < 0 ⟹ changes (x2 # xs) = changes (map sign (x2 # xs))› ‹⟦¬ x1 * x2 < 0; x2 = 0⟧ ⟹ changes (x1 # xs) = changes (map sign (x1 # xs))› ‹⟦¬ x1 * x2 < 0; x2 ≠ 0⟧ ⟹ changes (x2 # xs) = changes (map sign (x2 # xs))›*) moreover have "x1*x2<0 ⟷ sign x1 * sign x2 < 0" by (simp add: mult_less_0_iff (*‹((?a::?'a::linordered_ring_strict) * (?b::?'a::linordered_ring_strict) < (0::?'a::linordered_ring_strict)) = ((0::?'a::linordered_ring_strict) < ?a ∧ ?b < (0::?'a::linordered_ring_strict) ∨ ?a < (0::?'a::linordered_ring_strict) ∧ (0::?'a::linordered_ring_strict) < ?b)›*) sign_def (*‹sign (?x::?'a::{zero,linorder}) ≡ if (0::?'a::{zero,linorder}) < ?x then 1::int else if ?x = (0::?'a::{zero,linorder}) then 0::int else - (1::int)›*)) moreover have "x2=0 ⟷ sign x2 =0" by (simp add: sign_def (*‹sign (?x::?'a) ≡ if (0::?'a) < ?x then 1::int else if ?x = (0::?'a) then 0::int else - (1::int)›*)) ultimately show "?case" (*goal: ‹changes (x1 # x2 # xs) = changes (map sign (x1 # x2 # xs))›*) by auto qed (simp_all) (*solves the remaining goals: 1. ‹changes [] = changes (map sign [])› 2. ‹⋀uu_. changes [uu_] = changes (map sign [uu_])›*) lemma changes_map_sign_of_int_eq: "changes xs = changes (map ((of_int::_⇒'c::{ring_1,linordered_idom}) o sign) xs)" proof (induct xs rule:changes.induct (*‹⟦?P []; ⋀uu_. ?P [uu_]; ⋀x1 x2 xs. ⟦x1 * x2 < 0 ⟹ ?P (x2 # xs); ⟦¬ x1 * x2 < 0; x2 = 0⟧ ⟹ ?P (x1 # xs); ⟦¬ x1 * x2 < 0; x2 ≠ 0⟧ ⟹ ?P (x2 # xs)⟧ ⟹ ?P (x1 # x2 # xs)⟧ ⟹ ?P ?a0.0›*)) (*goals: 1. ‹changes [] = changes (map (of_int ∘ sign) [])› 2. ‹⋀uu_. changes [uu_] = changes (map (of_int ∘ sign) [uu_])› 3. ‹⋀x1 x2 xs. ⟦x1 * x2 < 0 ⟹ changes (x2 # xs) = changes (map (of_int ∘ sign) (x2 # xs)); ⟦¬ x1 * x2 < 0; x2 = 0⟧ ⟹ changes (x1 # xs) = changes (map (of_int ∘ sign) (x1 # xs)); ⟦¬ x1 * x2 < 0; x2 ≠ 0⟧ ⟹ changes (x2 # xs) = changes (map (of_int ∘ sign) (x2 # xs))⟧ ⟹ changes (x1 # x2 # xs) = changes (map (of_int ∘ sign) (x1 # x2 # xs))›*) case (3 x1 x2 xs) (*‹(x1::'a::linordered_idom) * (x2::'a::linordered_idom) < (0::'a::linordered_idom) ⟹ changes (x2 # (xs::'a::linordered_idom list)) = changes (map (of_int ∘ sign) (x2 # xs))› ‹⟦¬ (x1::'a) * (x2::'a) < (0::'a); x2 = (0::'a)⟧ ⟹ changes (x1 # (xs::'a list)) = changes (map (of_int ∘ sign) (x1 # xs))› ‹⟦¬ x1 * x2 < 0; x2 ≠ 0⟧ ⟹ changes (x2 # xs) = changes (map (of_int ∘ sign) (x2 # xs))›*) moreover have "x1*x2<0 ⟷ ((of_int::_⇒'c::{ring_1,linordered_idom}) o sign) x1 * ((of_int::_⇒'c::{ring_1,linordered_idom}) o sign) x2 < 0" by (simp add: mult_less_0_iff (*‹((?a::?'a) * (?b::?'a) < (0::?'a)) = ((0::?'a) < ?a ∧ ?b < (0::?'a) ∨ ?a < (0::?'a) ∧ (0::?'a) < ?b)›*) sign_def (*‹sign (?x::?'a) ≡ if (0::?'a) < ?x then 1::int else if ?x = (0::?'a) then 0::int else - (1::int)›*)) moreover have "x2=0 ⟷ (of_int o sign) x2 =0" by (simp add: sign_def (*‹sign ?x ≡ if 0 < ?x then 1 else if ?x = 0 then 0 else - 1›*)) ultimately show "?case" (*goal: ‹changes (x1 # x2 # xs) = changes (map (of_int ∘ sign) (x1 # x2 # xs))›*) by auto qed (simp_all) (*solves the remaining goals: 1. ‹changes [] = changes (map (of_int ∘ sign) [])› 2. ‹⋀uu_::'a. changes [uu_] = changes (map (of_int ∘ sign) [uu_])›*) definition changes_poly_at::"('a ::linordered_idom) poly list ⇒ 'a ⇒ int" where "changes_poly_at ps a= changes (map (λp. poly p a) ps)" definition changes_poly_pos_inf:: "('a ::linordered_idom) poly list ⇒ int" where "changes_poly_pos_inf ps = changes (map sgn_pos_inf ps)" definition changes_poly_neg_inf:: "('a ::linordered_idom) poly list ⇒ int" where "changes_poly_neg_inf ps = changes (map sgn_neg_inf ps)" lemma changes_poly_at_0[simp]: "changes_poly_at [] a =0" "changes_poly_at [p] a=0" unfolding changes_poly_at_def (*goals: 1. ‹changes (map (λp. poly p a) []) = 0› 2. ‹changes (map (λp. poly p a) [p]) = 0›*) (*goals: 1. ‹changes (map (λp. poly p a) []) = 0› 2. ‹changes (map (λp. poly p a) [p]) = 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . definition changes_itv_smods:: "real ⇒ real ⇒real poly ⇒ real poly ⇒ int" where "changes_itv_smods a b p q= (let ps= smods p q in changes_poly_at ps a - changes_poly_at ps b)" definition changes_gt_smods:: "real ⇒real poly ⇒ real poly ⇒ int" where "changes_gt_smods a p q= (let ps= smods p q in changes_poly_at ps a - changes_poly_pos_inf ps)" definition changes_le_smods:: "real ⇒real poly ⇒ real poly ⇒ int" where "changes_le_smods b p q= (let ps= smods p q in changes_poly_neg_inf ps - changes_poly_at ps b)" definition changes_R_smods:: "real poly ⇒ real poly ⇒ int" where "changes_R_smods p q= (let ps= smods p q in changes_poly_neg_inf ps - changes_poly_pos_inf ps)" lemma changes_R_smods_0[simp]: "changes_R_smods 0 q = 0" "changes_R_smods p 0 = 0" unfolding changes_R_smods_def changes_poly_neg_inf_def changes_poly_pos_inf_def (*goals: 1. ‹(let ps = smods 0 q in changes (map sgn_neg_inf ps) - changes (map sgn_pos_inf ps)) = 0› 2. ‹(let ps = smods p 0 in changes (map sgn_neg_inf ps) - changes (map sgn_pos_inf ps)) = 0›*) (*goals: 1. ‹(let ps = smods 0 q in changes (map sgn_neg_inf ps) - changes (map sgn_pos_inf ps)) = 0› 2. ‹(let ps = smods p 0 in changes (map sgn_neg_inf ps) - changes (map sgn_pos_inf ps)) = 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma changes_itv_smods_0[simp]: "changes_itv_smods a b 0 q = 0" "changes_itv_smods a b p 0 = 0" unfolding changes_itv_smods_def (*goals: 1. ‹(let ps = smods 0 q in changes_poly_at ps a - changes_poly_at ps b) = 0› 2. ‹(let ps = smods p 0 in changes_poly_at ps a - changes_poly_at ps b) = 0›*) (*goals: 1. ‹(let ps = smods 0 q in changes_poly_at ps a - changes_poly_at ps b) = 0› 2. ‹(let ps = smods p 0 in changes_poly_at ps a - changes_poly_at ps b) = 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma changes_itv_smods_rec: assumes "a<b" "poly (p*q) a≠0" "poly (p*q) b≠0" shows "changes_itv_smods a b p q = cross (p*q) a b + changes_itv_smods a b q (-(p mod q))" proof (cases "p=0 ∨ q=0 ∨ p mod q = 0") (*goals: 1. ‹(p::real poly) = (0::real poly) ∨ (q::real poly) = (0::real poly) ∨ p mod q = (0::real poly) ⟹ changes_itv_smods (a::real) (b::real) p q = cross (p * q) a b + changes_itv_smods a b q (- (p mod q))› 2. ‹¬ ((p::real poly) = (0::real poly) ∨ (q::real poly) = (0::real poly) ∨ p mod q = (0::real poly)) ⟹ changes_itv_smods (a::real) (b::real) p q = cross (p * q) a b + changes_itv_smods a b q (- (p mod q))›*) case True (*‹(p::real poly) = (0::real poly) ∨ (q::real poly) = (0::real poly) ∨ p mod q = (0::real poly)›*) moreover have "p=0 ∨ q=0 ⟹ ?thesis" unfolding changes_itv_smods_def changes_poly_at_def (*goal: ‹(p::real poly) = (0::real poly) ∨ (q::real poly) = (0::real poly) ⟹ (let ps::real poly list = smods p q in changes (map (λp::real poly. poly p (a::real)) ps) - changes (map (λp::real poly. poly p (b::real)) ps)) = cross (p * q) a b + (let ps::real poly list = smods q (- (p mod q)) in changes (map (λp::real poly. poly p a) ps) - changes (map (λp::real poly. poly p b) ps))›*) apply (erule HOL.disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹(p::real poly) = (0::real poly) ⟹ (let ps::real poly list = smods p (q::real poly) in changes (map (λp::real poly. poly p (a::real)) ps) - changes (map (λp::real poly. poly p (b::real)) ps)) = cross (p * q) a b + (let ps::real poly list = smods q (- (p mod q)) in changes (map (λp::real poly. poly p a) ps) - changes (map (λp::real poly. poly p b) ps))› 2. ‹(q::real poly) = (0::real poly) ⟹ (let ps::real poly list = smods (p::real poly) q in changes (map (λp::real poly. poly p (a::real)) ps) - changes (map (λp::real poly. poly p (b::real)) ps)) = cross (p * q) a b + (let ps::real poly list = smods q (- (p mod q)) in changes (map (λp::real poly. poly p a) ps) - changes (map (λp::real poly. poly p b) ps))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . moreover have "p mod q = 0 ⟹ ?thesis" unfolding changes_itv_smods_def changes_poly_at_def cross_def (*goal: ‹p mod q = 0 ⟹ (let ps = smods p q in changes (map (λp. poly p a) ps) - changes (map (λp. poly p b) ps)) = variation (poly (p * q) a) (poly (p * q) b) + (let ps = smods q (- (p mod q)) in changes (map (λp. poly p a) ps) - changes (map (λp. poly p b) ps))›*) apply (insert assms( (*‹poly (p * q) a ≠ 0› ‹poly (p * q) b ≠ 0›*) 2,3)) (*goal: ‹(p::real poly) mod (q::real poly) = (0::real poly) ⟹ (let ps::real poly list = smods p q in changes (map (λp::real poly. poly p (a::real)) ps) - changes (map (λp::real poly. poly p (b::real)) ps)) = variation (poly (p * q) a) (poly (p * q) b) + (let ps::real poly list = smods q (- (p mod q)) in changes (map (λp::real poly. poly p a) ps) - changes (map (λp::real poly. poly p b) ps))›*) apply (subst (asm) (1 2) neq_iff (*‹(?x ≠ ?y) = (?x < ?y ∨ ?y < ?x)›*)) (*goal: ‹⟦(p::real poly) mod (q::real poly) = (0::real poly); poly (p * q) (a::real) ≠ (0::real); poly (p * q) (b::real) ≠ (0::real)⟧ ⟹ (let ps::real poly list = smods p q in changes (map (λp::real poly. poly p a) ps) - changes (map (λp::real poly. poly p b) ps)) = variation (poly (p * q) a) (poly (p * q) b) + (let ps::real poly list = smods q (- (p mod q)) in changes (map (λp::real poly. poly p a) ps) - changes (map (λp::real poly. poly p b) ps))›*) by (auto simp add: variation_cases (*‹⟦0 < ?x; 0 < ?y⟧ ⟹ variation ?x ?y = 0› ‹⟦0 < ?x; ?y < 0⟧ ⟹ variation ?x ?y = - 1› ‹⟦?x < 0; 0 < ?y⟧ ⟹ variation ?x ?y = 1› ‹⟦?x < 0; ?y < 0⟧ ⟹ variation ?x ?y = 0›*)) ultimately show "?thesis" (*goal: ‹changes_itv_smods a b p q = cross (p * q) a b + changes_itv_smods a b q (- (p mod q))›*) by auto next (*goal: ‹¬ (p = 0 ∨ q = 0 ∨ p mod q = 0) ⟹ changes_itv_smods a b p q = cross (p * q) a b + changes_itv_smods a b q (- (p mod q))›*) case False (*‹¬ (p = 0 ∨ q = 0 ∨ p mod q = 0)›*) hence "p≠0" "q≠0" "p mod q≠0" apply - (*goals: 1. ‹¬ ((p::real poly) = (0::real poly) ∨ (q::real poly) = (0::real poly) ∨ p mod q = (0::real poly)) ⟹ p ≠ (0::real poly)› 2. ‹¬ ((p::real poly) = (0::real poly) ∨ (q::real poly) = (0::real poly) ∨ p mod q = (0::real poly)) ⟹ q ≠ (0::real poly)› 3. ‹¬ ((p::real poly) = (0::real poly) ∨ (q::real poly) = (0::real poly) ∨ p mod q = (0::real poly)) ⟹ p mod q ≠ (0::real poly)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . then obtain ps where ps: "smods p q=p#q#-(p mod q)#ps" "smods q (-(p mod q)) = q#-(p mod q)#ps" (*goal: ‹(⋀ps::real poly list. ⟦smods (p::real poly) (q::real poly) = p # q # - (p mod q) # ps; smods q (- (p mod q)) = q # - (p mod q) # ps⟧ ⟹ thesis::bool) ⟹ thesis›*) by auto define changes_diff where "changes_diff≡λx. changes_poly_at (p#q#-(p mod q)#ps) x - changes_poly_at (q#-(p mod q)#ps) x" have "⋀x. poly p x*poly q x<0 ⟹ changes_diff x=1" unfolding changes_diff_def changes_poly_at_def (*goal: ‹⋀x. poly p x * poly q x < 0 ⟹ changes (map (λp. poly p x) (p # q # - (p mod q) # ps)) - changes (map (λp. poly p x) (q # - (p mod q) # ps)) = 1›*) by auto moreover have "⋀x. poly p x*poly q x>0 ⟹ changes_diff x=0" unfolding changes_diff_def changes_poly_at_def (*goal: ‹⋀x. 0 < poly p x * poly q x ⟹ changes (map (λp. poly p x) (p # q # - (p mod q) # ps)) - changes (map (λp. poly p x) (q # - (p mod q) # ps)) = 0›*) by auto ultimately have "changes_diff a - changes_diff b=cross (p*q) a b" unfolding cross_def (*goal: ‹changes_diff a - changes_diff b = variation (poly (p * q) a) (poly (p * q) b)›*) apply (cases rule:neqE[OF ‹poly (p*q) a≠0›] (*‹⟦poly (p * q) a < 0 ⟹ ?R; 0 < poly (p * q) a ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹⟦⋀x. poly p x * poly q x < 0 ⟹ changes_diff x = 1; ⋀x. 0 < poly p x * poly q x ⟹ changes_diff x = 0; poly (p * q) a < 0⟧ ⟹ changes_diff a - changes_diff b = variation (poly (p * q) a) (poly (p * q) b)› 2. ‹⟦⋀x. poly p x * poly q x < 0 ⟹ changes_diff x = 1; ⋀x. 0 < poly p x * poly q x ⟹ changes_diff x = 0; 0 < poly (p * q) a⟧ ⟹ changes_diff a - changes_diff b = variation (poly (p * q) a) (poly (p * q) b)› discuss goal 1*) apply (cases rule:neqE[OF ‹poly (p*q) b≠0›] (*‹⟦poly ((p::real poly) * (q::real poly)) (b::real) < (0::real) ⟹ ?R::bool; (0::real) < poly (p * q) b ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹⟦⋀x. poly p x * poly q x < 0 ⟹ changes_diff x = 1; ⋀x. 0 < poly p x * poly q x ⟹ changes_diff x = 0; poly (p * q) a < 0; poly (p * q) b < 0⟧ ⟹ changes_diff a - changes_diff b = variation (poly (p * q) a) (poly (p * q) b)› 2. ‹⟦⋀x. poly p x * poly q x < 0 ⟹ changes_diff x = 1; ⋀x. 0 < poly p x * poly q x ⟹ changes_diff x = 0; poly (p * q) a < 0; 0 < poly (p * q) b⟧ ⟹ changes_diff a - changes_diff b = variation (poly (p * q) a) (poly (p * q) b)› discuss goal 1*) apply ((auto simp add:variation_cases (*‹⟦0 < ?x; 0 < ?y⟧ ⟹ variation ?x ?y = 0› ‹⟦0 < ?x; ?y < 0⟧ ⟹ variation ?x ?y = - 1› ‹⟦?x < 0; 0 < ?y⟧ ⟹ variation ?x ?y = 1› ‹⟦?x < 0; ?y < 0⟧ ⟹ variation ?x ?y = 0›*))[1]) (*discuss goal 2*) apply ((auto simp add:variation_cases (*‹⟦0 < ?x; 0 < ?y⟧ ⟹ variation ?x ?y = 0› ‹⟦0 < ?x; ?y < 0⟧ ⟹ variation ?x ?y = - 1› ‹⟦?x < 0; 0 < ?y⟧ ⟹ variation ?x ?y = 1› ‹⟦?x < 0; ?y < 0⟧ ⟹ variation ?x ?y = 0›*))[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply ((auto simp add:variation_cases (*‹⟦(0::real) < (?x::real); (0::real) < (?y::real)⟧ ⟹ variation ?x ?y = (0::int)› ‹⟦(0::real) < (?x::real); (?y::real) < (0::real)⟧ ⟹ variation ?x ?y = - (1::int)› ‹⟦(?x::real) < (0::real); (0::real) < (?y::real)⟧ ⟹ variation ?x ?y = (1::int)› ‹⟦(?x::real) < (0::real); (?y::real) < (0::real)⟧ ⟹ variation ?x ?y = (0::int)›*))[1]) (*goal: ‹⟦⋀x::real. poly (p::real poly) x * poly (q::real poly) x < (0::real) ⟹ (changes_diff::real ⇒ int) x = (1::int); ⋀x::real. (0::real) < poly p x * poly q x ⟹ changes_diff x = (0::int); (0::real) < poly (p * q) (a::real)⟧ ⟹ changes_diff a - changes_diff (b::real) = variation (poly (p * q) a) (poly (p * q) b)›*) apply (cases rule:neqE[OF ‹poly (p*q) b≠0›] (*‹⟦poly ((p::real poly) * (q::real poly)) (b::real) < (0::real) ⟹ ?R::bool; (0::real) < poly (p * q) b ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹⟦⋀x::real. poly (p::real poly) x * poly (q::real poly) x < (0::real) ⟹ (changes_diff::real ⇒ int) x = (1::int); ⋀x::real. (0::real) < poly p x * poly q x ⟹ changes_diff x = (0::int); (0::real) < poly p (a::real) * poly q a; poly (p * q) (b::real) < (0::real)⟧ ⟹ - changes_diff b = variation (poly p a * poly q a) (poly p b * poly q b)› 2. ‹⟦⋀x::real. poly (p::real poly) x * poly (q::real poly) x < (0::real) ⟹ (changes_diff::real ⇒ int) x = (1::int); ⋀x::real. (0::real) < poly p x * poly q x ⟹ changes_diff x = (0::int); (0::real) < poly p (a::real) * poly q a; (0::real) < poly (p * q) (b::real)⟧ ⟹ - changes_diff b = variation (poly p a * poly q a) (poly p b * poly q b)› discuss goal 1*) apply ((auto simp add:variation_cases (*‹⟦0 < ?x; 0 < ?y⟧ ⟹ variation ?x ?y = 0› ‹⟦0 < ?x; ?y < 0⟧ ⟹ variation ?x ?y = - 1› ‹⟦?x < 0; 0 < ?y⟧ ⟹ variation ?x ?y = 1› ‹⟦?x < 0; ?y < 0⟧ ⟹ variation ?x ?y = 0›*))[1]) (*discuss goal 2*) apply ((auto simp add:variation_cases (*‹⟦0 < ?x; 0 < ?y⟧ ⟹ variation ?x ?y = 0› ‹⟦0 < ?x; ?y < 0⟧ ⟹ variation ?x ?y = - 1› ‹⟦?x < 0; 0 < ?y⟧ ⟹ variation ?x ?y = 1› ‹⟦?x < 0; ?y < 0⟧ ⟹ variation ?x ?y = 0›*))[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) . thus "?thesis" (*goal: ‹changes_itv_smods a b p q = cross (p * q) a b + changes_itv_smods a b q (- (p mod q))›*) unfolding changes_itv_smods_def changes_diff_def changes_poly_at_def (*goal: ‹(let ps = smods p q in changes (map (λp. poly p a) ps) - changes (map (λp. poly p b) ps)) = cross (p * q) a b + (let ps = smods q (- (p mod q)) in changes (map (λp. poly p a) ps) - changes (map (λp. poly p b) ps))›*) using ps (*‹smods p q = p # q # - (p mod q) # ps› ‹smods q (- (p mod q)) = q # - (p mod q) # ps›*) by auto qed lemma changes_smods_congr: fixes p q:: "real poly" assumes "a≠a'" "poly p a≠0" assumes "∀p∈set (smods p q). ∀x. ((a<x∧x≤a') ∨ (a'≤x ∧ x<a)) ⟶ poly p x ≠0" shows "changes_poly_at (smods p q) a = changes_poly_at (smods p q) a'" using assms(2-3) (*‹poly (p::real poly) (a::real) ≠ (0::real)› ‹∀p::real poly∈set (smods (p::real poly) (q::real poly)). ∀x::real. (a::real) < x ∧ x ≤ (a'::real) ∨ a' ≤ x ∧ x < a ⟶ poly p x ≠ (0::real)›*) proof (induct "smods p q" arbitrary:p q rule:length_induct) (*goal: ‹⋀p q. ⟦∀ys. length ys < length (smods p q) ⟶ (∀x xa. ys = smods x xa ⟶ poly x a ≠ 0 ⟶ (∀p∈set (smods x xa). ∀x. a < x ∧ x ≤ a' ∨ a' ≤ x ∧ x < a ⟶ poly p x ≠ 0) ⟶ changes_poly_at (smods x xa) a = changes_poly_at (smods x xa) a'); poly p a ≠ 0; ∀p∈set (smods p q). ∀x. a < x ∧ x ≤ a' ∨ a' ≤ x ∧ x < a ⟶ poly p x ≠ 0⟧ ⟹ changes_poly_at (smods p q) a = changes_poly_at (smods p q) a'›*) case 1 (*‹∀ys. length ys < length (smods p q) ⟶ (∀x xa. ys = smods x xa ⟶ poly x a ≠ 0 ⟶ (∀p∈set (smods x xa). ∀x. a < x ∧ x ≤ a' ∨ a' ≤ x ∧ x < a ⟶ poly p x ≠ 0) ⟶ changes_poly_at (smods x xa) a = changes_poly_at (smods x xa) a')› ‹poly p a ≠ 0› ‹∀p∈set (smods p q). ∀x. a < x ∧ x ≤ a' ∨ a' ≤ x ∧ x < a ⟶ poly p x ≠ 0›*) have "p≠0" using ‹poly p a ≠0› (*‹poly (p::real poly) (a::real) ≠ (0::real)›*) by auto define r1 where "r1≡- (p mod q)" have a_a'_rel: "∀pp∈set (smods p q). poly pp a * poly pp a' ≥0" proof (rule ccontr (*‹(¬ (?P::bool) ⟹ False) ⟹ ?P›*)) (*goal: ‹¬ (∀pp∈set (smods p q). 0 ≤ poly pp a * poly pp a') ⟹ False›*) assume "¬ (∀pp∈set (smods p q). 0 ≤ poly pp a * poly pp a')" (*‹¬ (∀pp::real poly∈set (smods (p::real poly) (q::real poly)). (0::real) ≤ poly pp (a::real) * poly pp (a'::real))›*) then obtain pp where pp: "pp∈set (smods p q)" " poly pp a * poly pp a'<0" (*goal: ‹(⋀pp. ⟦pp ∈ set (smods p q); poly pp a * poly pp a' < 0⟧ ⟹ thesis) ⟹ thesis›*) using ‹p≠0› (*‹p ≠ 0›*) by (metis less_eq_real_def (*‹(?x ≤ ?y) = (?x < ?y ∨ ?x = ?y)›*) linorder_neqE_linordered_idom (*‹⟦?x ≠ ?y; ?x < ?y ⟹ ?thesis; ?y < ?x ⟹ ?thesis⟧ ⟹ ?thesis›*)) hence "a<a' ⟹ False" using "1.prems"(2) (*‹∀p∈set (smods p q). ∀x. a < x ∧ x ≤ a' ∨ a' ≤ x ∧ x < a ⟶ poly p x ≠ 0›*) poly_IVT[of a a' pp] (*‹⟦a < a'; poly pp a * poly pp a' < 0⟧ ⟹ ∃x>a. x < a' ∧ poly pp x = 0›*) by auto moreover have "a'<a⟹False" using pp[unfolded mult.commute [ of "poly pp a" ]] (*‹(pp::real poly) ∈ set (smods (p::real poly) (q::real poly))› ‹poly pp a' * poly pp a < 0›*) "1.prems"(2) (*‹∀p∈set (smods p q). ∀x. a < x ∧ x ≤ a' ∨ a' ≤ x ∧ x < a ⟶ poly p x ≠ 0›*) poly_IVT[of a' a pp] (*‹⟦(a'::real) < (a::real); poly (pp::real poly) a' * poly pp a < (0::real)⟧ ⟹ ∃x>a'. x < a ∧ poly pp x = (0::real)›*) by auto ultimately show False using ‹a≠a'› (*‹a ≠ a'›*) by force qed have "q=0 ⟹ ?case" by auto moreover have "⟦q≠0;poly q a=0⟧ ⟹ ?case" proof (-) (*goal: ‹⟦q ≠ 0; poly q a = 0⟧ ⟹ changes_poly_at (smods p q) a = changes_poly_at (smods p q) a'›*) assume "q≠0" "poly q a=0" (*‹(q::real poly) ≠ (0::real poly)› ‹poly (q::real poly) (a::real) = (0::real)›*) define r2 where "r2≡- (q mod r1)" have "- poly r1 a = poly p a " by (metis ‹poly q a = 0› add.inverse_inverse (*‹- (- (?a::?'a)) = ?a›*) add.left_neutral (*‹(0::?'a) + (?a::?'a) = ?a›*) div_mult_mod_eq (*‹(?a::?'a) div (?b::?'a) * ?b + ?a mod ?b = ?a›*) mult_zero_right (*‹(?a::?'a) * (0::?'a) = (0::?'a)›*) poly_add (*‹poly ((?p::?'a poly) + (?q::?'a poly)) (?x::?'a) = poly ?p ?x + poly ?q ?x›*) poly_minus (*‹poly (- (?p::?'a poly)) (?x::?'a) = - poly ?p ?x›*) poly_mult (*‹poly ((?p::?'a poly) * (?q::?'a poly)) (?x::?'a) = poly ?p ?x * poly ?q ?x›*) r1_def (*‹r1::real poly ≡ - ((p::real poly) mod (q::real poly))›*)) hence "r1≠0" and "poly r1 a≠0" and "poly p a*poly r1 a<0" using ‹poly p a≠0› (*‹poly p a ≠ 0›*) apply auto (*top goal: ‹r1 ≠ 0› and 2 goals remain*) using mult_less_0_iff (*‹(?a * ?b < 0) = (0 < ?a ∧ ?b < 0 ∨ ?a < 0 ∧ 0 < ?b)›*) by fastforce then obtain ps where ps: "smods p q=p#q#r1#ps" "smods r1 r2=r1#ps" (*goal: ‹(⋀ps. ⟦smods p q = p # q # r1 # ps; smods r1 r2 = r1 # ps⟧ ⟹ thesis) ⟹ thesis›*) by (metis ‹p≠0› ‹q ≠ 0› r1_def (*‹r1::real poly ≡ - ((p::real poly) mod (q::real poly))›*) r2_def (*‹r2::real poly ≡ - ((q::real poly) mod (r1::real poly))›*) smods.simps (*‹smods (?p::real poly) (?q::real poly) = (if ?p = (0::real poly) then [] else ?p # smods ?q (- (?p mod ?q)))›*)) hence "length (smods r1 r2)<length (smods p q)" by auto moreover have "(∀p∈set (smods r1 r2). ∀x. a < x ∧ x ≤ a' ∨ a' ≤ x ∧ x < a ⟶ poly p x ≠ 0)" using "1.prems"(2) (*‹∀p∈set (smods p q). ∀x. a < x ∧ x ≤ a' ∨ a' ≤ x ∧ x < a ⟶ poly p x ≠ 0›*) unfolding ps (*goal: ‹∀p∈set (r1 # ps). ∀x. a < x ∧ x ≤ a' ∨ a' ≤ x ∧ x < a ⟶ poly p x ≠ 0›*) by auto ultimately have "changes_poly_at (smods r1 r2) a = changes_poly_at (smods r1 r2) a'" using "1.hyps" (*‹∀ys. length ys < length (smods p q) ⟶ (∀x xa. ys = smods x xa ⟶ poly x a ≠ 0 ⟶ (∀p∈set (smods x xa). ∀x. a < x ∧ x ≤ a' ∨ a' ≤ x ∧ x < a ⟶ poly p x ≠ 0) ⟶ changes_poly_at (smods x xa) a = changes_poly_at (smods x xa) a')›*) ‹r1≠0› (*‹r1 ≠ 0›*) ‹poly r1 a≠0› (*‹poly r1 a ≠ 0›*) by metis moreover have "changes_poly_at (smods p q) a = 1+changes_poly_at (smods r1 r2) a" unfolding ps changes_poly_at_def (*goal: ‹changes (map (λp. poly p a) (p # q # r1 # ps)) = 1 + changes (map (λp. poly p a) (r1 # ps))›*) using ‹poly q a=0› (*‹poly q a = 0›*) ‹poly p a*poly r1 a<0› (*‹poly p a * poly r1 a < 0›*) by auto moreover have "changes_poly_at (smods p q) a' = 1+changes_poly_at (smods r1 r2) a'" proof (-) (*goal: ‹changes_poly_at (smods p q) a' = 1 + changes_poly_at (smods r1 r2) a'›*) have "poly p a * poly p a' ≥0" and "poly r1 a*poly r1 a'≥0" using a_a'_rel (*‹∀pp∈set (smods p q). 0 ≤ poly pp a * poly pp a'›*) unfolding ps (*goals: 1. ‹0 ≤ poly p a * poly p a'› 2. ‹0 ≤ poly r1 a * poly r1 a'›*) apply - (*goals: 1. ‹∀pp∈set (p # q # r1 # ps). 0 ≤ poly pp a * poly pp a' ⟹ 0 ≤ poly p a * poly p a'› 2. ‹∀pp∈set (p # q # r1 # ps). 0 ≤ poly pp a * poly pp a' ⟹ 0 ≤ poly r1 a * poly r1 a'› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . moreover have "poly p a'≠0" and "poly q a'≠0" and "poly r1 a'≠0" using "1.prems"(2)[unfolded ps] (*‹∀p∈set (p # q # r1 # ps). ∀x. a < x ∧ x ≤ a' ∨ a' ≤ x ∧ x < a ⟶ poly p x ≠ 0›*) ‹a≠a'› (*‹(a::real) ≠ (a'::real)›*) apply - (*goals: 1. ‹⟦∀p∈set (p # q # r1 # ps). ∀x. a < x ∧ x ≤ a' ∨ a' ≤ x ∧ x < a ⟶ poly p x ≠ 0; a ≠ a'⟧ ⟹ poly p a' ≠ 0› 2. ‹⟦∀p∈set (p # q # r1 # ps). ∀x. a < x ∧ x ≤ a' ∨ a' ≤ x ∧ x < a ⟶ poly p x ≠ 0; a ≠ a'⟧ ⟹ poly q a' ≠ 0› 3. ‹⟦∀p∈set (p # q # r1 # ps). ∀x. a < x ∧ x ≤ a' ∨ a' ≤ x ∧ x < a ⟶ poly p x ≠ 0; a ≠ a'⟧ ⟹ poly r1 a' ≠ 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . ultimately show "?thesis" (*goal: ‹changes_poly_at (smods p q) a' = 1 + changes_poly_at (smods r1 r2) a'›*) using ‹poly p a*poly r1 a<0› (*‹poly p a * poly r1 a < 0›*) unfolding ps changes_poly_at_def (*goal: ‹changes (map (λp. poly p a') (p # q # r1 # ps)) = 1 + changes (map (λp. poly p a') (r1 # ps))›*) apply (auto simp add: zero_le_mult_iff (*‹(0 ≤ ?a * ?b) = (0 ≤ ?a ∧ 0 ≤ ?b ∨ ?a ≤ 0 ∧ ?b ≤ 0)›*)) (*goals: 1. ‹⟦poly p a' ≠ 0; poly q a' ≠ 0; poly r1 a' ≠ 0; poly p a * poly r1 a < 0; 0 ≤ poly p a; 0 ≤ poly p a'; 0 ≤ poly r1 a; 0 ≤ poly r1 a'; poly q a' * poly r1 a' < 0; poly p a' * poly q a' < 0⟧ ⟹ False› 2. ‹⟦poly p a' ≠ 0; poly q a' ≠ 0; poly r1 a' ≠ 0; poly p a * poly r1 a < 0; 0 ≤ poly p a; 0 ≤ poly p a'; 0 ≤ poly r1 a; 0 ≤ poly r1 a'; ¬ poly q a' * poly r1 a' < 0⟧ ⟹ poly p a' * poly q a' < 0› 3. ‹⟦poly p a' ≠ 0; poly q a' ≠ 0; poly r1 a' ≠ 0; poly p a * poly r1 a < 0; 0 ≤ poly p a; 0 ≤ poly p a'; poly r1 a ≤ 0; poly r1 a' ≤ 0; poly q a' * poly r1 a' < 0; poly p a' * poly q a' < 0⟧ ⟹ False› 4. ‹⟦poly p a' ≠ 0; poly q a' ≠ 0; poly r1 a' ≠ 0; poly p a * poly r1 a < 0; 0 ≤ poly p a; 0 ≤ poly p a'; poly r1 a ≤ 0; poly r1 a' ≤ 0; ¬ poly q a' * poly r1 a' < 0⟧ ⟹ poly p a' * poly q a' < 0› 5. ‹⟦poly p a' ≠ 0; poly q a' ≠ 0; poly r1 a' ≠ 0; poly p a * poly r1 a < 0; poly p a ≤ 0; poly p a' ≤ 0; 0 ≤ poly r1 a; 0 ≤ poly r1 a'; poly q a' * poly r1 a' < 0; poly p a' * poly q a' < 0⟧ ⟹ False› 6. ‹⟦poly p a' ≠ 0; poly q a' ≠ 0; poly r1 a' ≠ 0; poly p a * poly r1 a < 0; poly p a ≤ 0; poly p a' ≤ 0; 0 ≤ poly r1 a; 0 ≤ poly r1 a'; ¬ poly q a' * poly r1 a' < 0⟧ ⟹ poly p a' * poly q a' < 0› 7. ‹⟦poly p a' ≠ 0; poly q a' ≠ 0; poly r1 a' ≠ 0; poly p a * poly r1 a < 0; poly p a ≤ 0; poly p a' ≤ 0; poly r1 a ≤ 0; poly r1 a' ≤ 0; poly q a' * poly r1 a' < 0; poly p a' * poly q a' < 0⟧ ⟹ False› 8. ‹⟦poly p a' ≠ 0; poly q a' ≠ 0; poly r1 a' ≠ 0; poly p a * poly r1 a < 0; poly p a ≤ 0; poly p a' ≤ 0; poly r1 a ≤ 0; poly r1 a' ≤ 0; ¬ poly q a' * poly r1 a' < 0⟧ ⟹ poly p a' * poly q a' < 0› discuss goal 1*) apply ((auto simp add: mult_less_0_iff (*‹(?a * ?b < 0) = (0 < ?a ∧ ?b < 0 ∨ ?a < 0 ∧ 0 < ?b)›*))[1]) (*discuss goal 2*) apply ((auto simp add: mult_less_0_iff (*‹(?a * ?b < 0) = (0 < ?a ∧ ?b < 0 ∨ ?a < 0 ∧ 0 < ?b)›*))[1]) (*discuss goal 3*) apply ((auto simp add: mult_less_0_iff (*‹((?a::?'a) * (?b::?'a) < (0::?'a)) = ((0::?'a) < ?a ∧ ?b < (0::?'a) ∨ ?a < (0::?'a) ∧ (0::?'a) < ?b)›*))[1]) (*discuss goal 4*) apply ((auto simp add: mult_less_0_iff (*‹(?a * ?b < 0) = (0 < ?a ∧ ?b < 0 ∨ ?a < 0 ∧ 0 < ?b)›*))[1]) (*discuss goal 5*) apply ((auto simp add: mult_less_0_iff (*‹(?a * ?b < 0) = (0 < ?a ∧ ?b < 0 ∨ ?a < 0 ∧ 0 < ?b)›*))[1]) (*discuss goal 6*) apply ((auto simp add: mult_less_0_iff (*‹(?a * ?b < 0) = (0 < ?a ∧ ?b < 0 ∨ ?a < 0 ∧ 0 < ?b)›*))[1]) (*discuss goal 7*) apply ((auto simp add: mult_less_0_iff (*‹(?a * ?b < 0) = (0 < ?a ∧ ?b < 0 ∨ ?a < 0 ∧ 0 < ?b)›*))[1]) (*discuss goal 8*) apply ((auto simp add: mult_less_0_iff (*‹(?a * ?b < 0) = (0 < ?a ∧ ?b < 0 ∨ ?a < 0 ∧ 0 < ?b)›*))[1]) (*proven 8 subgoals*) . qed ultimately show "?thesis" (*goal: ‹changes_poly_at (smods p q) a = changes_poly_at (smods p q) a'›*) by simp qed moreover have "⟦q≠0;poly q a≠0⟧ ⟹ ?case" proof (-) (*goal: ‹⟦q ≠ 0; poly q a ≠ 0⟧ ⟹ changes_poly_at (smods p q) a = changes_poly_at (smods p q) a'›*) assume "q≠0" "poly q a≠0" (*‹(q::real poly) ≠ (0::real poly)› ‹poly (q::real poly) (a::real) ≠ (0::real)›*) then obtain ps where ps: "smods p q=p#q#ps" "smods q r1=q#ps" (*goal: ‹(⋀ps. ⟦smods p q = p # q # ps; smods q r1 = q # ps⟧ ⟹ thesis) ⟹ thesis›*) by (metis ‹p≠0› r1_def (*‹r1 ≡ - (p mod q)›*) smods.simps (*‹smods ?p ?q = (if ?p = 0 then [] else ?p # smods ?q (- (?p mod ?q)))›*)) hence "length (smods q r1) < length (smods p q)" by auto moreover have "(∀p∈set (smods q r1). ∀x. a < x ∧ x ≤ a' ∨ a' ≤ x ∧ x < a ⟶ poly p x ≠ 0)" using "1.prems"(2) (*‹∀p∈set (smods p q). ∀x. a < x ∧ x ≤ a' ∨ a' ≤ x ∧ x < a ⟶ poly p x ≠ 0›*) unfolding ps (*goal: ‹∀p∈set (q # ps). ∀x. a < x ∧ x ≤ a' ∨ a' ≤ x ∧ x < a ⟶ poly p x ≠ 0›*) by auto ultimately have "changes_poly_at (smods q r1) a = changes_poly_at (smods q r1) a'" using "1.hyps" (*‹∀ys. length ys < length (smods p q) ⟶ (∀x xa. ys = smods x xa ⟶ poly x a ≠ 0 ⟶ (∀p∈set (smods x xa). ∀x. a < x ∧ x ≤ a' ∨ a' ≤ x ∧ x < a ⟶ poly p x ≠ 0) ⟶ changes_poly_at (smods x xa) a = changes_poly_at (smods x xa) a')›*) ‹q≠0› (*‹q ≠ 0›*) ‹poly q a≠0› (*‹poly q a ≠ 0›*) by metis moreover have "poly p a'≠0" and "poly q a'≠0" using "1.prems"(2)[unfolded ps] (*‹∀p::real poly∈set ((p::real poly) # (q::real poly) # (ps::real poly list)). ∀x::real. (a::real) < x ∧ x ≤ (a'::real) ∨ a' ≤ x ∧ x < a ⟶ poly p x ≠ (0::real)›*) ‹a≠a'› (*‹a ≠ a'›*) apply - (*goals: 1. ‹⟦∀p∈set (p # q # ps). ∀x. a < x ∧ x ≤ a' ∨ a' ≤ x ∧ x < a ⟶ poly p x ≠ 0; a ≠ a'⟧ ⟹ poly p a' ≠ 0› 2. ‹⟦∀p∈set (p # q # ps). ∀x. a < x ∧ x ≤ a' ∨ a' ≤ x ∧ x < a ⟶ poly p x ≠ 0; a ≠ a'⟧ ⟹ poly q a' ≠ 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . moreover have "poly p a * poly p a' ≥0" and "poly q a*poly q a'≥0" using a_a'_rel (*‹∀pp::real poly∈set (smods (p::real poly) (q::real poly)). (0::real) ≤ poly pp (a::real) * poly pp (a'::real)›*) unfolding ps (*goals: 1. ‹(0::real) ≤ poly (p::real poly) (a::real) * poly p (a'::real)› 2. ‹(0::real) ≤ poly (q::real poly) (a::real) * poly q (a'::real)›*) apply - (*goals: 1. ‹∀pp∈set (p # q # ps). 0 ≤ poly pp a * poly pp a' ⟹ 0 ≤ poly p a * poly p a'› 2. ‹∀pp∈set (p # q # ps). 0 ≤ poly pp a * poly pp a' ⟹ 0 ≤ poly q a * poly q a'› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . ultimately show "?thesis" (*goal: ‹changes_poly_at (smods (p::real poly) (q::real poly)) (a::real) = changes_poly_at (smods p q) (a'::real)›*) unfolding ps changes_poly_at_def (*goal: ‹changes (map (λp. poly p a) (p # q # ps)) = changes (map (λp. poly p a') (p # q # ps))›*) using ‹poly q a≠0› (*‹poly (q::real poly) (a::real) ≠ (0::real)›*) ‹poly p a≠0› (*‹poly p a ≠ 0›*) apply (auto simp add: zero_le_mult_iff (*‹(0 ≤ ?a * ?b) = (0 ≤ ?a ∧ 0 ≤ ?b ∨ ?a ≤ 0 ∧ ?b ≤ 0)›*)) (*goals: 1. ‹⟦changes (poly (q::real poly) (a::real) # map (λp::real poly. poly p a) (ps::real poly list)) = changes (poly q (a'::real) # map (λp::real poly. poly p a') ps); poly (p::real poly) a' ≠ (0::real); poly q a' ≠ (0::real); poly q a ≠ (0::real); poly p a ≠ (0::real); (0::real) ≤ poly p a; (0::real) ≤ poly p a'; (0::real) ≤ poly q a; (0::real) ≤ poly q a'; poly p a * poly q a < (0::real)⟧ ⟹ poly p a' * poly q a' < (0::real)› 2. ‹⟦changes (poly (q::real poly) (a::real) # map (λp::real poly. poly p a) (ps::real poly list)) = changes (poly q (a'::real) # map (λp::real poly. poly p a') ps); poly (p::real poly) a' ≠ (0::real); poly q a' ≠ (0::real); poly q a ≠ (0::real); poly p a ≠ (0::real); (0::real) ≤ poly p a; (0::real) ≤ poly p a'; (0::real) ≤ poly q a; (0::real) ≤ poly q a'; ¬ poly p a * poly q a < (0::real); poly p a' * poly q a' < (0::real)⟧ ⟹ False› 3. ‹⟦changes (poly (q::real poly) (a::real) # map (λp::real poly. poly p a) (ps::real poly list)) = changes (poly q (a'::real) # map (λp::real poly. poly p a') ps); poly (p::real poly) a' ≠ (0::real); poly q a' ≠ (0::real); poly q a ≠ (0::real); poly p a ≠ (0::real); (0::real) ≤ poly p a; (0::real) ≤ poly p a'; poly q a ≤ (0::real); poly q a' ≤ (0::real); poly p a * poly q a < (0::real)⟧ ⟹ poly p a' * poly q a' < (0::real)› 4. ‹⟦changes (poly (q::real poly) (a::real) # map (λp::real poly. poly p a) (ps::real poly list)) = changes (poly q (a'::real) # map (λp::real poly. poly p a') ps); poly (p::real poly) a' ≠ (0::real); poly q a' ≠ (0::real); poly q a ≠ (0::real); poly p a ≠ (0::real); (0::real) ≤ poly p a; (0::real) ≤ poly p a'; poly q a ≤ (0::real); poly q a' ≤ (0::real); ¬ poly p a * poly q a < (0::real); poly p a' * poly q a' < (0::real)⟧ ⟹ False› 5. ‹⟦changes (poly (q::real poly) (a::real) # map (λp::real poly. poly p a) (ps::real poly list)) = changes (poly q (a'::real) # map (λp::real poly. poly p a') ps); poly (p::real poly) a' ≠ (0::real); poly q a' ≠ (0::real); poly q a ≠ (0::real); poly p a ≠ (0::real); poly p a ≤ (0::real); poly p a' ≤ (0::real); (0::real) ≤ poly q a; (0::real) ≤ poly q a'; poly p a * poly q a < (0::real)⟧ ⟹ poly p a' * poly q a' < (0::real)› 6. ‹⟦changes (poly (q::real poly) (a::real) # map (λp::real poly. poly p a) (ps::real poly list)) = changes (poly q (a'::real) # map (λp::real poly. poly p a') ps); poly (p::real poly) a' ≠ (0::real); poly q a' ≠ (0::real); poly q a ≠ (0::real); poly p a ≠ (0::real); poly p a ≤ (0::real); poly p a' ≤ (0::real); (0::real) ≤ poly q a; (0::real) ≤ poly q a'; ¬ poly p a * poly q a < (0::real); poly p a' * poly q a' < (0::real)⟧ ⟹ False› 7. ‹⟦changes (poly (q::real poly) (a::real) # map (λp::real poly. poly p a) (ps::real poly list)) = changes (poly q (a'::real) # map (λp::real poly. poly p a') ps); poly (p::real poly) a' ≠ (0::real); poly q a' ≠ (0::real); poly q a ≠ (0::real); poly p a ≠ (0::real); poly p a ≤ (0::real); poly p a' ≤ (0::real); poly q a ≤ (0::real); poly q a' ≤ (0::real); poly p a * poly q a < (0::real)⟧ ⟹ poly p a' * poly q a' < (0::real)› 8. ‹⟦changes (poly (q::real poly) (a::real) # map (λp::real poly. poly p a) (ps::real poly list)) = changes (poly q (a'::real) # map (λp::real poly. poly p a') ps); poly (p::real poly) a' ≠ (0::real); poly q a' ≠ (0::real); poly q a ≠ (0::real); poly p a ≠ (0::real); poly p a ≤ (0::real); poly p a' ≤ (0::real); poly q a ≤ (0::real); poly q a' ≤ (0::real); ¬ poly p a * poly q a < (0::real); poly p a' * poly q a' < (0::real)⟧ ⟹ False› discuss goal 1*) apply ((auto simp add: mult_less_0_iff (*‹(?a * ?b < 0) = (0 < ?a ∧ ?b < 0 ∨ ?a < 0 ∧ 0 < ?b)›*))[1]) (*discuss goal 2*) apply ((auto simp add: mult_less_0_iff (*‹(?a * ?b < 0) = (0 < ?a ∧ ?b < 0 ∨ ?a < 0 ∧ 0 < ?b)›*))[1]) (*discuss goal 3*) apply ((auto simp add: mult_less_0_iff (*‹((?a::?'a::linordered_ring_strict) * (?b::?'a::linordered_ring_strict) < (0::?'a::linordered_ring_strict)) = ((0::?'a::linordered_ring_strict) < ?a ∧ ?b < (0::?'a::linordered_ring_strict) ∨ ?a < (0::?'a::linordered_ring_strict) ∧ (0::?'a::linordered_ring_strict) < ?b)›*))[1]) (*discuss goal 4*) apply ((auto simp add: mult_less_0_iff (*‹(?a * ?b < 0) = (0 < ?a ∧ ?b < 0 ∨ ?a < 0 ∧ 0 < ?b)›*))[1]) (*discuss goal 5*) apply ((auto simp add: mult_less_0_iff (*‹((?a::?'a::linordered_ring_strict) * (?b::?'a::linordered_ring_strict) < (0::?'a::linordered_ring_strict)) = ((0::?'a::linordered_ring_strict) < ?a ∧ ?b < (0::?'a::linordered_ring_strict) ∨ ?a < (0::?'a::linordered_ring_strict) ∧ (0::?'a::linordered_ring_strict) < ?b)›*))[1]) (*discuss goal 6*) apply ((auto simp add: mult_less_0_iff (*‹(?a * ?b < 0) = (0 < ?a ∧ ?b < 0 ∨ ?a < 0 ∧ 0 < ?b)›*))[1]) (*discuss goal 7*) apply ((auto simp add: mult_less_0_iff (*‹(?a * ?b < 0) = (0 < ?a ∧ ?b < 0 ∨ ?a < 0 ∧ 0 < ?b)›*))[1]) (*discuss goal 8*) apply ((auto simp add: mult_less_0_iff (*‹(?a * ?b < 0) = (0 < ?a ∧ ?b < 0 ∨ ?a < 0 ∧ 0 < ?b)›*))[1]) (*proven 8 subgoals*) . qed ultimately show "?case" (*goal: ‹changes_poly_at (smods p q) a = changes_poly_at (smods p q) a'›*) by blast qed lemma changes_itv_smods_congr: fixes p q:: "real poly" assumes "a<a'" "a'<b'" "b'<b" "poly p a≠0" "poly p b≠0" assumes no_root:"∀p∈set (smods p q). ∀x. ((a<x∧x≤a') ∨ (b'≤x ∧ x<b)) ⟶ poly p x ≠0" shows "changes_itv_smods a b p q=changes_itv_smods a' b' p q" proof (-) (*goal: ‹changes_itv_smods a b p q = changes_itv_smods a' b' p q›*) have "changes_poly_at (smods p q) a = changes_poly_at (smods p q) a'" apply (rule changes_smods_congr[OF order.strict_implies_not_eq[OF ‹a<a'›] ‹poly p a≠0›] (*‹∀p∈set (smods p ?q). ∀x. a < x ∧ x ≤ a' ∨ a' ≤ x ∧ x < a ⟶ poly p x ≠ 0 ⟹ changes_poly_at (smods p ?q) a = changes_poly_at (smods p ?q) a'›*)) (*goal: ‹changes_poly_at (smods (p::real poly) (q::real poly)) (a::real) = changes_poly_at (smods p q) (a'::real)›*) by (metis assms( (*‹a < a'›*) 1) less_eq_real_def (*‹(?x ≤ ?y) = (?x < ?y ∨ ?x = ?y)›*) less_irrefl (*‹¬ ?x < ?x›*) less_trans (*‹⟦?x < ?y; ?y < ?z⟧ ⟹ ?x < ?z›*) no_root (*‹∀p∈set (smods p q). ∀x. a < x ∧ x ≤ a' ∨ b' ≤ x ∧ x < b ⟶ poly p x ≠ 0›*)) moreover have "changes_poly_at (smods p q) b = changes_poly_at (smods p q) b'" apply (rule changes_smods_congr[OF order.strict_implies_not_eq[OF ‹b'<b›, symmetric] ‹poly p b≠0›] (*‹∀p∈set (smods p ?q). ∀x. b < x ∧ x ≤ b' ∨ b' ≤ x ∧ x < b ⟶ poly p x ≠ 0 ⟹ changes_poly_at (smods p ?q) b = changes_poly_at (smods p ?q) b'›*)) (*goal: ‹changes_poly_at (smods p q) b = changes_poly_at (smods p q) b'›*) by (metis assms( (*‹b' < b›*) 3) less_eq_real_def (*‹(?x ≤ ?y) = (?x < ?y ∨ ?x = ?y)›*) less_trans (*‹⟦?x < ?y; ?y < ?z⟧ ⟹ ?x < ?z›*) no_root (*‹∀p∈set (smods p q). ∀x. a < x ∧ x ≤ a' ∨ b' ≤ x ∧ x < b ⟶ poly p x ≠ 0›*)) ultimately show "?thesis" (*goal: ‹changes_itv_smods a b p q = changes_itv_smods a' b' p q›*) unfolding changes_itv_smods_def Let_def (*goal: ‹changes_poly_at (smods p q) a - changes_poly_at (smods p q) b = changes_poly_at (smods p q) a' - changes_poly_at (smods p q) b'›*) by auto qed lemma cindex_poly_changes_itv_mods: assumes "a<b" "poly p a≠0" "poly p b≠0" shows "cindex_poly a b q p = changes_itv_smods a b p q" using assms (*‹a < b› ‹poly p a ≠ 0› ‹poly p b ≠ 0›*) proof (induct "smods p q" arbitrary:p q a b) (*goals: 1. ‹⋀p q a b. ⟦[] = smods p q; a < b; poly p a ≠ 0; poly p b ≠ 0⟧ ⟹ cindex_poly a b q p = changes_itv_smods a b p q› 2. ‹⋀a x p q aa b. ⟦⋀p q a b. ⟦x = smods p q; a < b; poly p a ≠ 0; poly p b ≠ 0⟧ ⟹ cindex_poly a b q p = changes_itv_smods a b p q; a # x = smods p q; aa < b; poly p aa ≠ 0; poly p b ≠ 0⟧ ⟹ cindex_poly aa b q p = changes_itv_smods aa b p q›*) case Nil (*‹[] = smods p q› ‹(a::real) < (b::real)› ‹poly p a ≠ 0› ‹poly p b ≠ 0›*) hence "p=0" by (metis smods_nil_eq (*‹(smods (?p::real poly) (?q::real poly) = []) = (?p = (0::real poly))›*)) thus "?case" (*goal: ‹cindex_poly a b q p = changes_itv_smods a b p q›*) using ‹poly p a ≠ 0› (*‹poly p a ≠ 0›*) by simp next (*goal: ‹⋀a x p q aa b. ⟦⋀p q a b. ⟦x = smods p q; a < b; poly p a ≠ 0; poly p b ≠ 0⟧ ⟹ cindex_poly a b q p = changes_itv_smods a b p q; a # x = smods p q; aa < b; poly p aa ≠ 0; poly p b ≠ 0⟧ ⟹ cindex_poly aa b q p = changes_itv_smods aa b p q›*) case (Cons x1 xs) (*‹⟦(xs::real poly list) = smods (?p::real poly) (?q::real poly); (?a::real) < (?b::real); poly ?p ?a ≠ (0::real); poly ?p ?b ≠ (0::real)⟧ ⟹ cindex_poly ?a ?b ?q ?p = changes_itv_smods ?a ?b ?p ?q› ‹x1 # xs = smods p q› ‹(a::real) < (b::real)› ‹poly (p::real poly) (a::real) ≠ (0::real)› ‹poly p b ≠ 0›*) have "p≠0" using ‹poly p a ≠ 0› (*‹poly p a ≠ 0›*) by auto obtain a' and b' where "a<a'" "a'<b'" "b'<b" and no_root: "∀p∈set (smods p q). ∀x. ((a<x∧x≤a') ∨ (b'≤x ∧ x<b)) ⟶ poly p x ≠0" (*goal: ‹(⋀a' b'. ⟦a < a'; a' < b'; b' < b; ∀p∈set (smods p q). ∀x. a < x ∧ x ≤ a' ∨ b' ≤ x ∧ x < b ⟶ poly p x ≠ 0⟧ ⟹ thesis) ⟹ thesis›*) proof (induct "smods p q" arbitrary:p q thesis) (*goals: 1. ‹⋀(p::real poly) (q::real poly) thesis::bool. ⟦[] = smods p q; ⋀(a'::real) b'::real. ⟦(a::real) < a'; a' < b'; b' < (b::real); ∀p::real poly∈set (smods p q). ∀x::real. a < x ∧ x ≤ a' ∨ b' ≤ x ∧ x < b ⟶ poly p x ≠ (0::real)⟧ ⟹ thesis⟧ ⟹ thesis› 2. ‹⋀(a::real poly) (x::real poly list) (p::real poly) (q::real poly) thesis::bool. ⟦⋀(p::real poly) (q::real poly) thesis::bool. ⟦x = smods p q; ⋀(a'::real) b'::real. ⟦(a::real) < a'; a' < b'; b' < (b::real); ∀p::real poly∈set (smods p q). ∀x::real. a < x ∧ x ≤ a' ∨ b' ≤ x ∧ x < b ⟶ poly p x ≠ (0::real)⟧ ⟹ thesis⟧ ⟹ thesis; a # x = smods p q; ⋀(a'::real) b'::real. ⟦a < a'; a' < b'; b' < b; ∀p::real poly∈set (smods p q). ∀x::real. a < x ∧ x ≤ a' ∨ b' ≤ x ∧ x < b ⟶ poly p x ≠ (0::real)⟧ ⟹ thesis⟧ ⟹ thesis›*) case Nil (*‹[] = smods p q› ‹⟦a < ?a'; ?a' < ?b'; ?b' < b; ∀p∈set (smods p q). ∀x. a < x ∧ x ≤ ?a' ∨ ?b' ≤ x ∧ x < b ⟶ poly p x ≠ 0⟧ ⟹ thesis›*) define a' and b' where "a'≡2/3 * a + 1/3 * b" and "b'≡1/3*a + 2/3*b" have "a < a'" and "a' < b'" and "b' < b" unfolding a'_def b'_def (*goals: 1. ‹a < 2 / 3 * a + 1 / 3 * b› 2. ‹2 / 3 * a + 1 / 3 * b < 1 / 3 * a + 2 / 3 * b› 3. ‹1 / 3 * a + 2 / 3 * b < b›*) using ‹a<b› (*‹a < b›*) apply - (*goals: 1. ‹(a::real) < (b::real) ⟹ a < (2::real) / (3::real) * a + (1::real) / (3::real) * b› 2. ‹(a::real) < (b::real) ⟹ (2::real) / (3::real) * a + (1::real) / (3::real) * b < (1::real) / (3::real) * a + (2::real) / (3::real) * b› 3. ‹(a::real) < (b::real) ⟹ (1::real) / (3::real) * a + (2::real) / (3::real) * b < b› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . moreover have "∀p∈set (smods p q). ∀x. a < x ∧ x ≤ a' ∨ b' ≤ x ∧ x < b ⟶ poly p x ≠ 0" unfolding ‹[] = smods p q›[symmetric] (*goal: ‹∀p∈set []. ∀x. a < x ∧ x ≤ a' ∨ b' ≤ x ∧ x < b ⟶ poly p x ≠ 0›*) by auto ultimately show "?case" (*goal: ‹thesis::bool›*) using Nil (*‹[] = smods (p::real poly) (q::real poly)› ‹⟦a < ?a'; ?a' < ?b'; ?b' < b; ∀p∈set (smods p q). ∀x. a < x ∧ x ≤ ?a' ∨ ?b' ≤ x ∧ x < b ⟶ poly p x ≠ 0⟧ ⟹ thesis›*) by auto next (*goal: ‹⋀a x p q thesis. ⟦⋀p q thesis. ⟦x = smods p q; ⋀a' b'. ⟦a < a'; a' < b'; b' < b; ∀p∈set (smods p q). ∀x. a < x ∧ x ≤ a' ∨ b' ≤ x ∧ x < b ⟶ poly p x ≠ 0⟧ ⟹ thesis⟧ ⟹ thesis; a # x = smods p q; ⋀a' b'. ⟦a < a'; a' < b'; b' < b; ∀p∈set (smods p q). ∀x. a < x ∧ x ≤ a' ∨ b' ≤ x ∧ x < b ⟶ poly p x ≠ 0⟧ ⟹ thesis⟧ ⟹ thesis›*) case (Cons x1 xs) (*‹⟦xs = smods ?p ?q; ⋀a' b'. ⟦a < a'; a' < b'; b' < b; ∀p∈set (smods ?p ?q). ∀x. a < x ∧ x ≤ a' ∨ b' ≤ x ∧ x < b ⟶ poly p x ≠ 0⟧ ⟹ ?thesis⟧ ⟹ ?thesis› ‹x1 # xs = smods p q› ‹⟦(a::real) < (?a'::real); ?a' < (?b'::real); ?b' < (b::real); ∀p::real poly∈set (smods (p::real poly) (q::real poly)). ∀x::real. a < x ∧ x ≤ ?a' ∨ ?b' ≤ x ∧ x < b ⟶ poly p x ≠ (0::real)⟧ ⟹ thesis::bool›*) define r where "r≡- (p mod q)" then have "smods p q = p # xs" and "smods q r = xs" and "p ≠ 0" using ‹x1 # xs = smods p q› (*‹x1 # xs = smods p q›*) apply - (*goals: 1. ‹⟦r ≡ - (p mod q); x1 # xs = smods p q⟧ ⟹ smods p q = p # xs› 2. ‹⟦r ≡ - (p mod q); x1 # xs = smods p q⟧ ⟹ smods q r = xs› 3. ‹⟦r ≡ - (p mod q); x1 # xs = smods p q⟧ ⟹ p ≠ 0› discuss goal 1*) apply ((auto simp del: smods.simps (*‹smods ?p ?q = (if ?p = 0 then [] else ?p # smods ?q (- (?p mod ?q)))›*) simp add: smods.simps [of p q] (*‹smods p q = (if p = 0 then [] else p # smods q (- (p mod q)))›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto simp del: smods.simps (*‹smods (?p::real poly) (?q::real poly) = (if ?p = (0::real poly) then [] else ?p # smods ?q (- (?p mod ?q)))›*) simp add: smods.simps [of p q] (*‹smods (p::real poly) (q::real poly) = (if p = (0::real poly) then [] else p # smods q (- (p mod q)))›*) split: if_splits (*‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 3*) apply ((auto simp del: smods.simps (*‹smods ?p ?q = (if ?p = 0 then [] else ?p # smods ?q (- (?p mod ?q)))›*) simp add: smods.simps [of p q] (*‹smods p q = (if p = 0 then [] else p # smods q (- (p mod q)))›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 3 subgoals*) . obtain a1 and b1 where "a < a1" "a1 < b1" "b1 < b" and a1_b1_no_root: "∀p∈set xs. ∀x. a < x ∧ x ≤ a1 ∨ b1 ≤ x ∧ x < b ⟶ poly p x ≠ 0" (*goal: ‹(⋀a1 b1. ⟦a < a1; a1 < b1; b1 < b; ∀p∈set xs. ∀x. a < x ∧ x ≤ a1 ∨ b1 ≤ x ∧ x < b ⟶ poly p x ≠ 0⟧ ⟹ thesis) ⟹ thesis›*) using Cons(1)[OF ‹smods q r=xs› [ symmetric ]] (*‹(⋀(a'::real) b'::real. ⟦(a::real) < a'; a' < b'; b' < (b::real); ∀p::real poly∈set (smods (q::real poly) (r::real poly)). ∀x::real. a < x ∧ x ≤ a' ∨ b' ≤ x ∧ x < b ⟶ poly p x ≠ (0::real)⟧ ⟹ ?thesis::bool) ⟹ ?thesis›*) ‹smods q r=xs› (*‹smods q r = xs›*) by auto obtain a2 and b2 where "a<a2" and a2: "∀x. a<x ∧ x≤a2 ⟶ poly p x ≠ 0" "b2<b" and b2: "∀x. b2≤x ∧ x<b ⟶ poly p x ≠ 0" (*goal: ‹(⋀(a2::real) b2::real. ⟦(a::real) < a2; ∀x::real. a < x ∧ x ≤ a2 ⟶ poly (p::real poly) x ≠ (0::real); b2 < (b::real); ∀x::real. b2 ≤ x ∧ x < b ⟶ poly p x ≠ (0::real)⟧ ⟹ thesis::bool) ⟹ thesis›*) using next_non_root_interval[OF ‹p≠0›] (*‹(⋀ub. ⟦?lb < ub; ∀z. ?lb < z ∧ z ≤ ub ⟶ poly p z ≠ 0⟧ ⟹ ?thesis) ⟹ ?thesis›*) last_non_root_interval[OF ‹p≠0›] (*‹(⋀lb. ⟦lb < ?ub; ∀z. lb ≤ z ∧ z < ?ub ⟶ poly p z ≠ 0⟧ ⟹ ?thesis) ⟹ ?thesis›*) by (metis less_numeral_extra( (*‹¬ 0 < 0›*) 3)) define a' and b' where "a'≡ if b2>a then Min{a1, b2, a2} else min a1 a2" and "b'≡if a2 <b then Max{ b1, a2, b2} else max b1 b2" have "a < a'" "a' < b'" "b' < b" unfolding a'_def b'_def (*goals: 1. ‹a < (if a < b2 then Min {a1, b2, a2} else min a1 a2)› 2. ‹(if a < b2 then Min {a1, b2, a2} else min a1 a2) < (if a2 < b then Max {b1, a2, b2} else max b1 b2)› 3. ‹(if a2 < b then Max {b1, a2, b2} else max b1 b2) < b›*) using ‹a < a1› (*‹a < a1›*) ‹a1 < b1› (*‹a1 < b1›*) ‹b1 < b› (*‹b1 < b›*) ‹a<a2› (*‹a < a2›*) ‹b2<b› (*‹b2 < b›*) ‹a<b› (*‹a < b›*) apply - (*goals: 1. ‹⟦a < a1; a1 < b1; b1 < b; a < a2; b2 < b; a < b⟧ ⟹ a < (if a < b2 then Min {a1, b2, a2} else min a1 a2)› 2. ‹⟦a < a1; a1 < b1; b1 < b; a < a2; b2 < b; a < b⟧ ⟹ (if a < b2 then Min {a1, b2, a2} else min a1 a2) < (if a2 < b then Max {b1, a2, b2} else max b1 b2)› 3. ‹⟦a < a1; a1 < b1; b1 < b; a < a2; b2 < b; a < b⟧ ⟹ (if a2 < b then Max {b1, a2, b2} else max b1 b2) < b› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . moreover have "∀p∈set xs. ∀x. a < x ∧ x ≤ a' ∨ b' ≤ x ∧ x < b ⟶ poly p x ≠ 0" using a1_b1_no_root (*‹∀p::real poly∈set (xs::real poly list). ∀x::real. (a::real) < x ∧ x ≤ (a1::real) ∨ (b1::real) ≤ x ∧ x < (b::real) ⟶ poly p x ≠ (0::real)›*) unfolding a'_def b'_def (*goal: ‹∀p∈set xs. ∀x. a < x ∧ x ≤ (if a < b2 then Min {a1, b2, a2} else min a1 a2) ∨ (if a2 < b then Max {b1, a2, b2} else max b1 b2) ≤ x ∧ x < b ⟶ poly p x ≠ 0›*) by auto moreover have "∀x. a < x ∧ x ≤ a' ∨ b' ≤ x ∧ x < b ⟶ poly p x ≠ 0" using a2 (*‹∀x. a < x ∧ x ≤ a2 ⟶ poly p x ≠ 0› ‹b2 < b›*) b2 (*‹∀x::real. (b2::real) ≤ x ∧ x < (b::real) ⟶ poly (p::real poly) x ≠ (0::real)›*) unfolding a'_def b'_def (*goal: ‹∀x. a < x ∧ x ≤ (if a < b2 then Min {a1, b2, a2} else min a1 a2) ∨ (if a2 < b then Max {b1, a2, b2} else max b1 b2) ≤ x ∧ x < b ⟶ poly p x ≠ 0›*) by auto ultimately show "?case" (*goal: ‹thesis›*) using Cons(3)[unfolded ‹smods p q=p#xs›] (*‹⟦(a::real) < (?a'::real); ?a' < (?b'::real); ?b' < (b::real); ∀p::real poly∈set ((p::real poly) # (xs::real poly list)). ∀x::real. a < x ∧ x ≤ ?a' ∨ ?b' ≤ x ∧ x < b ⟶ poly p x ≠ (0::real)⟧ ⟹ thesis::bool›*) by auto qed have "q=0 ⟹ ?case" by simp moreover have "q≠0 ⟹ ?case" proof (-) (*goal: ‹q ≠ 0 ⟹ cindex_poly a b q p = changes_itv_smods a b p q›*) assume "q≠0" (*‹(q::real poly) ≠ (0::real poly)›*) define r where "r≡- (p mod q)" obtain ps where ps: "smods p q=p#q#ps" "smods q r=q#ps" and "xs=q#ps" (*goal: ‹(⋀ps. ⟦smods p q = p # q # ps; smods q r = q # ps; xs = q # ps⟧ ⟹ thesis) ⟹ thesis›*) unfolding r_def (*goal: ‹(⋀ps. ⟦smods p q = p # q # ps; smods q (- (p mod q)) = q # ps; xs = q # ps⟧ ⟹ thesis) ⟹ thesis›*) using ‹q≠0› (*‹q ≠ 0›*) ‹p≠0› (*‹p ≠ 0›*) ‹x1 # xs = smods p q› (*‹(x1::real poly) # (xs::real poly list) = smods (p::real poly) (q::real poly)›*) by (metis list.inject (*‹(?x21.0 # ?x22.0 = ?y21.0 # ?y22.0) = (?x21.0 = ?y21.0 ∧ ?x22.0 = ?y22.0)›*) smods.simps (*‹smods ?p ?q = (if ?p = 0 then [] else ?p # smods ?q (- (?p mod ?q)))›*)) have "poly p a' ≠ 0" "poly p b' ≠ 0" "poly q a' ≠ 0" "poly q b' ≠ 0" using no_root[unfolded ps] (*‹∀p∈set (p # q # ps). ∀x. a < x ∧ x ≤ a' ∨ b' ≤ x ∧ x < b ⟶ poly p x ≠ 0›*) ‹a'>a› (*‹a < a'›*) ‹b'<b› (*‹b' < b›*) apply - (*goals: 1. ‹⟦∀p∈set (p # q # ps). ∀x. a < x ∧ x ≤ a' ∨ b' ≤ x ∧ x < b ⟶ poly p x ≠ 0; a < a'; b' < b⟧ ⟹ poly p a' ≠ 0› 2. ‹⟦∀p∈set (p # q # ps). ∀x. a < x ∧ x ≤ a' ∨ b' ≤ x ∧ x < b ⟶ poly p x ≠ 0; a < a'; b' < b⟧ ⟹ poly p b' ≠ 0› 3. ‹⟦∀p∈set (p # q # ps). ∀x. a < x ∧ x ≤ a' ∨ b' ≤ x ∧ x < b ⟶ poly p x ≠ 0; a < a'; b' < b⟧ ⟹ poly q a' ≠ 0› 4. ‹⟦∀p∈set (p # q # ps). ∀x. a < x ∧ x ≤ a' ∨ b' ≤ x ∧ x < b ⟶ poly p x ≠ 0; a < a'; b' < b⟧ ⟹ poly q b' ≠ 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . moreover hence "changes_itv_smods a' b' p q = cross (p * q) a' b' + changes_itv_smods a' b' q r" "cindex_poly a' b' q p = cross (p * q) a' b' + cindex_poly a' b' r q" using changes_itv_smods_rec[OF ‹a'<b'›, of p q, folded r_def] (*‹⟦poly (p * q) a' ≠ 0; poly (p * q) b' ≠ 0⟧ ⟹ changes_itv_smods a' b' p q = cross (p * q) a' b' + changes_itv_smods a' b' q r›*) cindex_poly_rec[OF ‹a'<b'›, of p q, folded r_def] (*‹⟦poly (p * q) a' ≠ 0; poly (p * q) b' ≠ 0⟧ ⟹ cindex_poly a' b' q p = cross (p * q) a' b' + cindex_poly a' b' r q›*) apply - (*goals: 1. ‹⟦poly p a' ≠ 0; poly p b' ≠ 0; poly q a' ≠ 0; poly q b' ≠ 0; ⟦poly (p * q) a' ≠ 0; poly (p * q) b' ≠ 0⟧ ⟹ changes_itv_smods a' b' p q = cross (p * q) a' b' + changes_itv_smods a' b' q r; ⟦poly (p * q) a' ≠ 0; poly (p * q) b' ≠ 0⟧ ⟹ cindex_poly a' b' q p = cross (p * q) a' b' + cindex_poly a' b' r q⟧ ⟹ changes_itv_smods a' b' p q = cross (p * q) a' b' + changes_itv_smods a' b' q r› 2. ‹⟦poly p a' ≠ 0; poly p b' ≠ 0; poly q a' ≠ 0; poly q b' ≠ 0; ⟦poly (p * q) a' ≠ 0; poly (p * q) b' ≠ 0⟧ ⟹ changes_itv_smods a' b' p q = cross (p * q) a' b' + changes_itv_smods a' b' q r; ⟦poly (p * q) a' ≠ 0; poly (p * q) b' ≠ 0⟧ ⟹ cindex_poly a' b' q p = cross (p * q) a' b' + cindex_poly a' b' r q⟧ ⟹ cindex_poly a' b' q p = cross (p * q) a' b' + cindex_poly a' b' r q› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . moreover have "changes_itv_smods a' b' q r = cindex_poly a' b' r q" using Cons.hyps(1)[of q r a' b'] (*‹⟦xs = smods q r; a' < b'; poly q a' ≠ 0; poly q b' ≠ 0⟧ ⟹ cindex_poly a' b' r q = changes_itv_smods a' b' q r›*) ‹a' < b'› (*‹(a'::real) < (b'::real)›*) ‹q ≠ 0› (*‹q ≠ 0›*) ‹xs = q # ps› (*‹xs = q # ps›*) ps(2) (*‹smods q r = q # ps›*) ‹poly q a' ≠ 0› (*‹poly (q::real poly) (a'::real) ≠ (0::real)›*) ‹poly q b' ≠ 0› (*‹poly q b' ≠ 0›*) by simp ultimately have "changes_itv_smods a' b' p q = cindex_poly a' b' q p" by auto thus "?thesis" (*goal: ‹cindex_poly a b q p = changes_itv_smods a b p q›*) using changes_itv_smods_congr[OF ‹a<a'› ‹a'<b'› ‹b'<b› Cons ( 4 , 5 ), of q] (*‹∀p∈set (smods p q). ∀x. a < x ∧ x ≤ a' ∨ b' ≤ x ∧ x < b ⟶ poly p x ≠ 0 ⟹ changes_itv_smods a b p q = changes_itv_smods a' b' p q›*) no_root (*‹∀p∈set (smods p q). ∀x. a < x ∧ x ≤ a' ∨ b' ≤ x ∧ x < b ⟶ poly p x ≠ 0›*) cindex_poly_congr[OF ‹a<a'› ‹a'<b'› ‹b'<b›] (*‹∀x. a < x ∧ x ≤ a' ∨ b' ≤ x ∧ x < b ⟶ poly ?p x ≠ 0 ⟹ cindex_poly a b ?q ?p = cindex_poly a' b' ?q ?p›*) ps (*‹smods p q = p # q # ps› ‹smods q r = q # ps›*) by (metis insert_iff (*‹(?a ∈ insert ?b ?A) = (?a = ?b ∨ ?a ∈ ?A)›*) list.set( (*‹set (?x21.0 # ?x22.0) = insert ?x21.0 (set ?x22.0)›*) 2)) qed ultimately show "?case" (*goal: ‹cindex_poly (a::real) (b::real) (q::real poly) (p::real poly) = changes_itv_smods a b p q›*) by metis qed lemma root_list_ub: fixes ps:: "(real poly) list" and a::real assumes "0∉set ps" obtains ub where "∀p∈set ps. ∀x. poly p x=0 ⟶ x<ub" and "∀x≥ub. ∀p∈set ps. sgn (poly p x) = sgn_pos_inf p" and "ub>a" using assms (*‹0 ∉ set ps›*) proof (induct ps arbitrary:thesis) (*goals: 1. ‹⋀thesis. ⟦⋀ub. ⟦∀p∈set []. ∀x. poly p x = 0 ⟶ x < ub; ∀x≥ub. ∀p∈set []. sgn (poly p x) = sgn_pos_inf p; a < ub⟧ ⟹ thesis; 0 ∉ set []⟧ ⟹ thesis› 2. ‹⋀aa ps thesis. ⟦⋀thesis. ⟦⋀ub. ⟦∀p∈set ps. ∀x. poly p x = 0 ⟶ x < ub; ∀x≥ub. ∀p∈set ps. sgn (poly p x) = sgn_pos_inf p; a < ub⟧ ⟹ thesis; 0 ∉ set ps⟧ ⟹ thesis; ⋀ub. ⟦∀p∈set (aa # ps). ∀x. poly p x = 0 ⟶ x < ub; ∀x≥ub. ∀p∈set (aa # ps). sgn (poly p x) = sgn_pos_inf p; a < ub⟧ ⟹ thesis; 0 ∉ set (aa # ps)⟧ ⟹ thesis›*) case Nil (*‹⟦∀p∈set []. ∀x. poly p x = 0 ⟶ x < ?ub; ∀x≥?ub. ∀p∈set []. sgn (poly p x) = sgn_pos_inf p; a < ?ub⟧ ⟹ thesis› ‹0 ∉ set []›*) show "?case" (*goal: ‹thesis›*) using Nil(1)[of "a+1"] (*‹⟦∀p∈set []. ∀x. poly p x = 0 ⟶ x < a + 1; ∀x≥a + 1. ∀p∈set []. sgn (poly p x) = sgn_pos_inf p; a < a + 1⟧ ⟹ thesis›*) by auto next (*goal: ‹⋀(aa::real poly) (ps::real poly list) thesis::bool. ⟦⋀thesis::bool. ⟦⋀ub::real. ⟦∀p::real poly∈set ps. ∀x::real. poly p x = (0::real) ⟶ x < ub; ∀x≥ub. ∀p::real poly∈set ps. sgn (poly p x) = sgn_pos_inf p; (a::real) < ub⟧ ⟹ thesis; (0::real poly) ∉ set ps⟧ ⟹ thesis; ⋀ub::real. ⟦∀p::real poly∈set (aa # ps). ∀x::real. poly p x = (0::real) ⟶ x < ub; ∀x≥ub. ∀p::real poly∈set (aa # ps). sgn (poly p x) = sgn_pos_inf p; a < ub⟧ ⟹ thesis; (0::real poly) ∉ set (aa # ps)⟧ ⟹ thesis›*) case (Cons p ps) (*‹⟦⋀ub. ⟦∀p∈set ps. ∀x. poly p x = 0 ⟶ x < ub; ∀x≥ub. ∀p∈set ps. sgn (poly p x) = sgn_pos_inf p; a < ub⟧ ⟹ ?thesis; 0 ∉ set ps⟧ ⟹ ?thesis› ‹⟦∀p∈set (p # ps). ∀x. poly p x = 0 ⟶ x < ?ub; ∀x≥?ub. ∀p∈set (p # ps). sgn (poly p x) = sgn_pos_inf p; a < ?ub⟧ ⟹ thesis› ‹0 ∉ set (p # ps)›*) hence "p≠0" and "0∉set ps" apply - (*goals: 1. ‹⟦⋀thesis. ⟦⋀ub. ⟦∀p∈set ps. ∀x. poly p x = 0 ⟶ x < ub; ∀x≥ub. ∀p∈set ps. sgn (poly p x) = sgn_pos_inf p; a < ub⟧ ⟹ thesis; 0 ∉ set ps⟧ ⟹ thesis; ⋀ub. ⟦∀p∈set (p # ps). ∀x. poly p x = 0 ⟶ x < ub; ∀x≥ub. ∀p∈set (p # ps). sgn (poly p x) = sgn_pos_inf p; a < ub⟧ ⟹ thesis; 0 ∉ set (p # ps)⟧ ⟹ p ≠ 0› 2. ‹⟦⋀thesis. ⟦⋀ub. ⟦∀p∈set ps. ∀x. poly p x = 0 ⟶ x < ub; ∀x≥ub. ∀p∈set ps. sgn (poly p x) = sgn_pos_inf p; a < ub⟧ ⟹ thesis; 0 ∉ set ps⟧ ⟹ thesis; ⋀ub. ⟦∀p∈set (p # ps). ∀x. poly p x = 0 ⟶ x < ub; ∀x≥ub. ∀p∈set (p # ps). sgn (poly p x) = sgn_pos_inf p; a < ub⟧ ⟹ thesis; 0 ∉ set (p # ps)⟧ ⟹ 0 ∉ set ps› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . then obtain ub1 where ub1: "∀p∈set ps. ∀x. poly p x = 0 ⟶ x < ub1" and ub1_sgn: "∀x≥ub1. ∀p∈set ps. sgn (poly p x) = sgn_pos_inf p" and "ub1>a" (*goal: ‹(⋀ub1. ⟦∀p∈set ps. ∀x. poly p x = 0 ⟶ x < ub1; ∀x≥ub1. ∀p∈set ps. sgn (poly p x) = sgn_pos_inf p; a < ub1⟧ ⟹ thesis) ⟹ thesis›*) using Cons.hyps (*‹⟦⋀ub. ⟦∀p∈set ps. ∀x. poly p x = 0 ⟶ x < ub; ∀x≥ub. ∀p∈set ps. sgn (poly p x) = sgn_pos_inf p; a < ub⟧ ⟹ ?thesis; 0 ∉ set ps⟧ ⟹ ?thesis›*) by auto obtain ub2 where ub2: "∀x. poly p x = 0 ⟶ x < ub2" and ub2_sgn: "∀x≥ub2. sgn (poly p x) = sgn_pos_inf p" (*goal: ‹(⋀ub2. ⟦∀x. poly p x = 0 ⟶ x < ub2; ∀x≥ub2. sgn (poly p x) = sgn_pos_inf p⟧ ⟹ thesis) ⟹ thesis›*) using root_ub[OF ‹p≠0›] (*‹(⋀ub. ⟦∀x. poly p x = 0 ⟶ x < ub; ∀x≥ub. sgn (poly p x) = sgn_pos_inf p⟧ ⟹ ?thesis) ⟹ ?thesis›*) by auto define ub where "ub≡max ub1 ub2" have "∀p∈set (p # ps). ∀x. poly p x = 0 ⟶ x < ub" using ub1 (*‹∀p∈set ps. ∀x. poly p x = 0 ⟶ x < ub1›*) ub2 (*‹∀x. poly p x = 0 ⟶ x < ub2›*) ub_def (*‹ub ≡ max ub1 ub2›*) by force moreover have "∀x≥ub. ∀p∈set (p # ps). sgn (poly p x) = sgn_pos_inf p" using ub1_sgn (*‹∀x≥ub1. ∀p∈set ps. sgn (poly p x) = sgn_pos_inf p›*) ub2_sgn (*‹∀x≥ub2::real. sgn (poly (p::real poly) x) = sgn_pos_inf p›*) ub_def (*‹ub::real ≡ max (ub1::real) (ub2::real)›*) by auto ultimately show "?case" (*goal: ‹thesis›*) using Cons(2)[of ub] (*‹⟦∀p∈set (p # ps). ∀x. poly p x = 0 ⟶ x < ub; ∀x≥ub. ∀p∈set (p # ps). sgn (poly p x) = sgn_pos_inf p; a < ub⟧ ⟹ thesis›*) ‹ub1>a› (*‹a < ub1›*) ub_def (*‹ub::real ≡ max (ub1::real) (ub2::real)›*) by auto qed lemma root_list_lb: fixes ps:: "(real poly) list" and b::real assumes "0∉set ps" obtains lb where "∀p∈set ps. ∀x. poly p x=0 ⟶ x>lb" and "∀x≤lb. ∀p∈set ps. sgn (poly p x) = sgn_neg_inf p" and "lb<b" using assms (*‹(0::real poly) ∉ set (ps::real poly list)›*) proof (induct ps arbitrary:thesis) (*goals: 1. ‹⋀thesis. ⟦⋀lb. ⟦∀p∈set []. ∀x. poly p x = 0 ⟶ lb < x; ∀x≤lb. ∀p∈set []. sgn (poly p x) = sgn_neg_inf p; lb < b⟧ ⟹ thesis; 0 ∉ set []⟧ ⟹ thesis› 2. ‹⋀a ps thesis. ⟦⋀thesis. ⟦⋀lb. ⟦∀p∈set ps. ∀x. poly p x = 0 ⟶ lb < x; ∀x≤lb. ∀p∈set ps. sgn (poly p x) = sgn_neg_inf p; lb < b⟧ ⟹ thesis; 0 ∉ set ps⟧ ⟹ thesis; ⋀lb. ⟦∀p∈set (a # ps). ∀x. poly p x = 0 ⟶ lb < x; ∀x≤lb. ∀p∈set (a # ps). sgn (poly p x) = sgn_neg_inf p; lb < b⟧ ⟹ thesis; 0 ∉ set (a # ps)⟧ ⟹ thesis›*) case Nil (*‹⟦∀p∈set []. ∀x. poly p x = 0 ⟶ ?lb < x; ∀x≤?lb. ∀p∈set []. sgn (poly p x) = sgn_neg_inf p; ?lb < b⟧ ⟹ thesis› ‹0 ∉ set []›*) show "?case" (*goal: ‹thesis›*) using Nil(1)[of "b - 1"] (*‹⟦∀p∈set []. ∀x. poly p x = 0 ⟶ b - 1 < x; ∀x≤b - 1. ∀p∈set []. sgn (poly p x) = sgn_neg_inf p; b - 1 < b⟧ ⟹ thesis›*) by auto next (*goal: ‹⋀(a::real poly) (ps::real poly list) thesis::bool. ⟦⋀thesis::bool. ⟦⋀lb::real. ⟦∀p::real poly∈set ps. ∀x::real. poly p x = (0::real) ⟶ lb < x; ∀x≤lb. ∀p::real poly∈set ps. sgn (poly p x) = sgn_neg_inf p; lb < (b::real)⟧ ⟹ thesis; (0::real poly) ∉ set ps⟧ ⟹ thesis; ⋀lb::real. ⟦∀p::real poly∈set (a # ps). ∀x::real. poly p x = (0::real) ⟶ lb < x; ∀x≤lb. ∀p::real poly∈set (a # ps). sgn (poly p x) = sgn_neg_inf p; lb < b⟧ ⟹ thesis; (0::real poly) ∉ set (a # ps)⟧ ⟹ thesis›*) case (Cons p ps) (*‹⟦⋀lb. ⟦∀p∈set ps. ∀x. poly p x = 0 ⟶ lb < x; ∀x≤lb. ∀p∈set ps. sgn (poly p x) = sgn_neg_inf p; lb < b⟧ ⟹ ?thesis; 0 ∉ set ps⟧ ⟹ ?thesis› ‹⟦∀p∈set (p # ps). ∀x. poly p x = 0 ⟶ ?lb < x; ∀x≤?lb. ∀p∈set (p # ps). sgn (poly p x) = sgn_neg_inf p; ?lb < b⟧ ⟹ thesis› ‹0 ∉ set (p # ps)›*) hence "p≠0" and "0∉set ps" apply - (*goals: 1. ‹⟦⋀thesis. ⟦⋀lb. ⟦∀p∈set ps. ∀x. poly p x = 0 ⟶ lb < x; ∀x≤lb. ∀p∈set ps. sgn (poly p x) = sgn_neg_inf p; lb < b⟧ ⟹ thesis; 0 ∉ set ps⟧ ⟹ thesis; ⋀lb. ⟦∀p∈set (p # ps). ∀x. poly p x = 0 ⟶ lb < x; ∀x≤lb. ∀p∈set (p # ps). sgn (poly p x) = sgn_neg_inf p; lb < b⟧ ⟹ thesis; 0 ∉ set (p # ps)⟧ ⟹ p ≠ 0› 2. ‹⟦⋀thesis. ⟦⋀lb. ⟦∀p∈set ps. ∀x. poly p x = 0 ⟶ lb < x; ∀x≤lb. ∀p∈set ps. sgn (poly p x) = sgn_neg_inf p; lb < b⟧ ⟹ thesis; 0 ∉ set ps⟧ ⟹ thesis; ⋀lb. ⟦∀p∈set (p # ps). ∀x. poly p x = 0 ⟶ lb < x; ∀x≤lb. ∀p∈set (p # ps). sgn (poly p x) = sgn_neg_inf p; lb < b⟧ ⟹ thesis; 0 ∉ set (p # ps)⟧ ⟹ 0 ∉ set ps› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . then obtain lb1 where lb1: "∀p∈set ps. ∀x. poly p x = 0 ⟶ x > lb1" and lb1_sgn: "∀x≤lb1. ∀p∈set ps. sgn (poly p x) = sgn_neg_inf p" and "lb1<b" (*goal: ‹(⋀lb1::real. ⟦∀p::real poly∈set (ps::real poly list). ∀x::real. poly p x = (0::real) ⟶ lb1 < x; ∀x≤lb1. ∀p::real poly∈set ps. sgn (poly p x) = sgn_neg_inf p; lb1 < (b::real)⟧ ⟹ thesis::bool) ⟹ thesis›*) using Cons.hyps (*‹⟦⋀lb. ⟦∀p∈set ps. ∀x. poly p x = 0 ⟶ lb < x; ∀x≤lb. ∀p∈set ps. sgn (poly p x) = sgn_neg_inf p; lb < b⟧ ⟹ ?thesis; 0 ∉ set ps⟧ ⟹ ?thesis›*) by auto obtain lb2 where lb2: "∀x. poly p x = 0 ⟶ x > lb2" and lb2_sgn: "∀x≤lb2. sgn (poly p x) = sgn_neg_inf p" (*goal: ‹(⋀lb2::real. ⟦∀x::real. poly (p::real poly) x = (0::real) ⟶ lb2 < x; ∀x≤lb2. sgn (poly p x) = sgn_neg_inf p⟧ ⟹ thesis::bool) ⟹ thesis›*) using root_lb[OF ‹p≠0›] (*‹(⋀lb. ⟦∀x. poly p x = 0 ⟶ lb < x; ∀x≤lb. sgn (poly p x) = sgn_neg_inf p⟧ ⟹ ?thesis) ⟹ ?thesis›*) by auto define lb where "lb≡min lb1 lb2" have "∀p∈set (p # ps). ∀x. poly p x = 0 ⟶ x > lb" using lb1 (*‹∀p∈set ps. ∀x. poly p x = 0 ⟶ lb1 < x›*) lb2 (*‹∀x. poly p x = 0 ⟶ lb2 < x›*) lb_def (*‹lb ≡ min lb1 lb2›*) by force moreover have "∀x≤lb. ∀p∈set (p # ps). sgn (poly p x) = sgn_neg_inf p" using lb1_sgn (*‹∀x≤lb1. ∀p∈set ps. sgn (poly p x) = sgn_neg_inf p›*) lb2_sgn (*‹∀x≤lb2. sgn (poly p x) = sgn_neg_inf p›*) lb_def (*‹lb ≡ min lb1 lb2›*) by auto ultimately show "?case" (*goal: ‹thesis›*) using Cons(2)[of lb] (*‹⟦∀p∈set (p # ps). ∀x. poly p x = 0 ⟶ lb < x; ∀x≤lb. ∀p∈set (p # ps). sgn (poly p x) = sgn_neg_inf p; lb < b⟧ ⟹ thesis›*) ‹lb1<b› (*‹(lb1::real) < (b::real)›*) lb_def (*‹lb ≡ min lb1 lb2›*) by auto qed theorem sturm_tarski_interval: assumes "a<b" "poly p a≠0" "poly p b≠0" shows "taq {x. poly p x=0 ∧ a<x ∧ x<b} q = changes_itv_smods a b p (pderiv p * q)" proof (-) (*goal: ‹taq {x. poly p x = 0 ∧ a < x ∧ x < b} q = changes_itv_smods a b p (pderiv p * q)›*) have "p≠0" using ‹poly p a≠0› (*‹poly p a ≠ 0›*) by auto thus "?thesis" (*goal: ‹taq {x. poly p x = 0 ∧ a < x ∧ x < b} q = changes_itv_smods a b p (pderiv p * q)›*) using cindex_poly_taq (*‹taq {x. poly ?p x = 0 ∧ ?a < x ∧ x < ?b} ?q = cindex_poly ?a ?b (pderiv ?p * ?q) ?p›*) cindex_poly_changes_itv_mods[OF assms] (*‹cindex_poly a b ?q p = changes_itv_smods a b p ?q›*) by auto qed theorem sturm_tarski_above: assumes "poly p a≠0" shows "taq {x. poly p x=0 ∧ a<x} q = changes_gt_smods a p (pderiv p * q)" proof (-) (*goal: ‹taq {x. poly p x = 0 ∧ a < x} q = changes_gt_smods a p (pderiv p * q)›*) define ps where "ps≡smods p (pderiv p * q)" have "p≠0" and "p∈set ps" using ‹poly p a≠0› (*‹poly p a ≠ 0›*) ps_def (*‹ps::real poly list ≡ smods (p::real poly) (pderiv p * (q::real poly))›*) apply - (*goals: 1. ‹⟦poly (p::real poly) (a::real) ≠ (0::real); ps::real poly list ≡ smods p (pderiv p * (q::real poly))⟧ ⟹ p ≠ (0::real poly)› 2. ‹⟦poly (p::real poly) (a::real) ≠ (0::real); ps::real poly list ≡ smods p (pderiv p * (q::real poly))⟧ ⟹ p ∈ set ps› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . obtain ub where ub: "∀p∈set ps. ∀x. poly p x=0 ⟶ x<ub" and ub_sgn: "∀x≥ub. ∀p∈set ps. sgn (poly p x) = sgn_pos_inf p" and "ub>a" (*goal: ‹(⋀ub. ⟦∀p∈set ps. ∀x. poly p x = 0 ⟶ x < ub; ∀x≥ub. ∀p∈set ps. sgn (poly p x) = sgn_pos_inf p; a < ub⟧ ⟹ thesis) ⟹ thesis›*) using root_list_ub[OF no_0_in_smods, of p "pderiv p * q", folded ps_def] (*‹(⋀ub. ⟦∀p∈set ps. ∀x. poly p x = 0 ⟶ x < ub; ∀x≥ub. ∀p∈set ps. sgn (poly p x) = sgn_pos_inf p; ?a < ub⟧ ⟹ ?thesis) ⟹ ?thesis›*) by auto have "taq {x. poly p x=0 ∧ a<x} q = taq {x. poly p x=0 ∧ a<x ∧ x<ub} q" unfolding taq_def (*goal: ‹(∑x | poly p x = 0 ∧ a < x. sign (poly q x)) = (∑x | poly p x = 0 ∧ a < x ∧ x < ub. sign (poly q x))›*) apply (rule sum.cong (*‹⟦?A = ?B; ⋀x. x ∈ ?B ⟹ ?g x = ?h x⟧ ⟹ sum ?g ?A = sum ?h ?B›*)) (*goals: 1. ‹{x. poly p x = 0 ∧ a < x} = {x. poly p x = 0 ∧ a < x ∧ x < ub}› 2. ‹⋀x. x ∈ {x. poly p x = 0 ∧ a < x ∧ x < ub} ⟹ sign (poly q x) = sign (poly q x)› discuss goal 1*) apply ((insert ub (*‹∀p∈set ps. ∀x. poly p x = 0 ⟶ x < ub›*) ‹p∈set ps›)[1]) (*top goal: ‹{x. poly p x = 0 ∧ a < x} = {x. poly p x = 0 ∧ a < x ∧ x < ub}› and 1 goal remains*) apply ((auto)[1]) (*discuss goal 2*) apply ((insert ub (*‹∀p∈set ps. ∀x. poly p x = 0 ⟶ x < ub›*) ‹p∈set ps›)[1]) (*goal: ‹⋀x::real. x ∈ {x::real. poly (p::real poly) x = (0::real) ∧ (a::real) < x ∧ x < (ub::real)} ⟹ sign (poly (q::real poly) x) = sign (poly q x)›*) apply ((auto)[1]) (*proven 2 subgoals*) . moreover have "changes_gt_smods a p (pderiv p * q) = changes_itv_smods a ub p (pderiv p * q)" proof (-) (*goal: ‹changes_gt_smods a p (pderiv p * q) = changes_itv_smods a ub p (pderiv p * q)›*) have "map (sgn ∘ (λp. poly p ub)) ps = map sgn_pos_inf ps" using ub_sgn[THEN spec, of ub, simplified] (*‹∀p∈set ps. sgn (poly p ub) = sgn_pos_inf p›*) by (metis (mono_tags, lifting) comp_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*) list.map_cong0 (*‹(⋀z. z ∈ set ?x ⟹ ?f z = ?g z) ⟹ map ?f ?x = map ?g ?x›*)) hence "changes_poly_at ps ub=changes_poly_pos_inf ps" unfolding changes_poly_pos_inf_def changes_poly_at_def (*goal: ‹changes (map (λp. poly p ub) ps) = changes (map sgn_pos_inf ps)›*) apply (subst changes_map_sgn_eq (*‹changes ?xs = changes (map sgn ?xs)›*)) (*goal: ‹changes (map (λp::real poly. poly p (ub::real)) (ps::real poly list)) = changes (map sgn_pos_inf ps)›*) by (metis map_map (*‹map ?f (map ?g ?xs) = map (?f ∘ ?g) ?xs›*)) thus "?thesis" (*goal: ‹changes_gt_smods a p (pderiv p * q) = changes_itv_smods a ub p (pderiv p * q)›*) unfolding changes_gt_smods_def changes_itv_smods_def ps_def (*goal: ‹(let ps = smods p (pderiv p * q) in changes_poly_at ps a - changes_poly_pos_inf ps) = (let ps = smods p (pderiv p * q) in changes_poly_at ps a - changes_poly_at ps ub)›*) by metis qed moreover have "poly p ub≠0" using ub (*‹∀p∈set ps. ∀x. poly p x = 0 ⟶ x < ub›*) ‹p∈set ps› (*‹p ∈ set ps›*) by auto ultimately show "?thesis" (*goal: ‹taq {x. poly p x = 0 ∧ a < x} q = changes_gt_smods a p (pderiv p * q)›*) using sturm_tarski_interval[OF ‹ub>a› assms] (*‹poly p ub ≠ 0 ⟹ taq {x. poly p x = 0 ∧ a < x ∧ x < ub} ?q = changes_itv_smods a ub p (pderiv p * ?q)›*) by auto qed theorem sturm_tarski_below: assumes "poly p b≠0" shows "taq {x. poly p x=0 ∧ x<b} q = changes_le_smods b p (pderiv p * q)" proof (-) (*goal: ‹taq {x. poly p x = 0 ∧ x < b} q = changes_le_smods b p (pderiv p * q)›*) define ps where "ps≡smods p (pderiv p * q)" have "p≠0" and "p∈set ps" using ‹poly p b≠0› (*‹poly p b ≠ 0›*) ps_def (*‹ps ≡ smods p (pderiv p * q)›*) apply - (*goals: 1. ‹⟦poly (p::real poly) (b::real) ≠ (0::real); ps::real poly list ≡ smods p (pderiv p * (q::real poly))⟧ ⟹ p ≠ (0::real poly)› 2. ‹⟦poly (p::real poly) (b::real) ≠ (0::real); ps::real poly list ≡ smods p (pderiv p * (q::real poly))⟧ ⟹ p ∈ set ps› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . obtain lb where lb: "∀p∈set ps. ∀x. poly p x=0 ⟶ x>lb" and lb_sgn: "∀x≤lb. ∀p∈set ps. sgn (poly p x) = sgn_neg_inf p" and "lb<b" (*goal: ‹(⋀lb::real. ⟦∀p::real poly∈set (ps::real poly list). ∀x::real. poly p x = (0::real) ⟶ lb < x; ∀x≤lb. ∀p::real poly∈set ps. sgn (poly p x) = sgn_neg_inf p; lb < (b::real)⟧ ⟹ thesis::bool) ⟹ thesis›*) using root_list_lb[OF no_0_in_smods, of p "pderiv p * q", folded ps_def] (*‹(⋀lb::real. ⟦∀p::real poly∈set (ps::real poly list). ∀x::real. poly p x = (0::real) ⟶ lb < x; ∀x≤lb. ∀p::real poly∈set ps. sgn (poly p x) = sgn_neg_inf p; lb < (?b::real)⟧ ⟹ ?thesis::bool) ⟹ ?thesis›*) by auto have "taq {x. poly p x=0 ∧ x<b} q = taq {x. poly p x=0 ∧ lb<x ∧ x<b} q" unfolding taq_def (*goal: ‹(∑x::real | poly (p::real poly) x = (0::real) ∧ x < (b::real). sign (poly (q::real poly) x)) = (∑x::real | poly p x = (0::real) ∧ (lb::real) < x ∧ x < b. sign (poly q x))›*) apply (rule sum.cong (*‹⟦?A = ?B; ⋀x. x ∈ ?B ⟹ ?g x = ?h x⟧ ⟹ sum ?g ?A = sum ?h ?B›*)) (*goals: 1. ‹{x. poly p x = 0 ∧ x < b} = {x. poly p x = 0 ∧ lb < x ∧ x < b}› 2. ‹⋀x. x ∈ {x. poly p x = 0 ∧ lb < x ∧ x < b} ⟹ sign (poly q x) = sign (poly q x)› discuss goal 1*) apply ((insert lb (*‹∀p∈set ps. ∀x. poly p x = 0 ⟶ lb < x›*) ‹p∈set ps›)[1]) (*top goal: ‹{x. poly p x = 0 ∧ x < b} = {x. poly p x = 0 ∧ lb < x ∧ x < b}› and 1 goal remains*) apply ((auto)[1]) (*discuss goal 2*) apply ((insert lb (*‹∀p::real poly∈set (ps::real poly list). ∀x::real. poly p x = (0::real) ⟶ (lb::real) < x›*) ‹p∈set ps›)[1]) (*goal: ‹⋀x. x ∈ {x. poly p x = 0 ∧ lb < x ∧ x < b} ⟹ sign (poly q x) = sign (poly q x)›*) apply ((auto)[1]) (*proven 2 subgoals*) . moreover have "changes_le_smods b p (pderiv p * q) = changes_itv_smods lb b p (pderiv p * q)" proof (-) (*goal: ‹changes_le_smods (b::real) (p::real poly) (pderiv p * (q::real poly)) = changes_itv_smods (lb::real) b p (pderiv p * q)›*) have "map (sgn ∘ (λp. poly p lb)) ps = map sgn_neg_inf ps" using lb_sgn[THEN spec, of lb, simplified] (*‹∀p::real poly∈set (ps::real poly list). sgn (poly p (lb::real)) = sgn_neg_inf p›*) by (metis (mono_tags, lifting) comp_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*) list.map_cong0 (*‹(⋀z. z ∈ set ?x ⟹ ?f z = ?g z) ⟹ map ?f ?x = map ?g ?x›*)) hence "changes_poly_at ps lb=changes_poly_neg_inf ps" unfolding changes_poly_neg_inf_def changes_poly_at_def (*goal: ‹changes (map (λp. poly p lb) ps) = changes (map sgn_neg_inf ps)›*) apply (subst changes_map_sgn_eq (*‹changes ?xs = changes (map sgn ?xs)›*)) (*goal: ‹changes (map (λp. poly p lb) ps) = changes (map sgn_neg_inf ps)›*) by (metis map_map (*‹map ?f (map ?g ?xs) = map (?f ∘ ?g) ?xs›*)) thus "?thesis" (*goal: ‹changes_le_smods b p (pderiv p * q) = changes_itv_smods lb b p (pderiv p * q)›*) unfolding changes_le_smods_def changes_itv_smods_def ps_def (*goal: ‹(let ps::real poly list = smods (p::real poly) (pderiv p * (q::real poly)) in changes_poly_neg_inf ps - changes_poly_at ps (b::real)) = (let ps::real poly list = smods p (pderiv p * q) in changes_poly_at ps (lb::real) - changes_poly_at ps b)›*) by metis qed moreover have "poly p lb≠0" using lb (*‹∀p∈set ps. ∀x. poly p x = 0 ⟶ lb < x›*) ‹p∈set ps› (*‹(p::real poly) ∈ set (ps::real poly list)›*) by auto ultimately show "?thesis" (*goal: ‹taq {x. poly p x = 0 ∧ x < b} q = changes_le_smods b p (pderiv p * q)›*) using sturm_tarski_interval[OF ‹lb<b› _ assms] (*‹poly p lb ≠ 0 ⟹ taq {x. poly p x = 0 ∧ lb < x ∧ x < b} ?q = changes_itv_smods lb b p (pderiv p * ?q)›*) by auto qed theorem sturm_tarski_R: shows "taq {x. poly p x=0} q = changes_R_smods p (pderiv p * q)" proof (cases "p=0") (*goals: 1. ‹p = 0 ⟹ taq {x. poly p x = 0} q = changes_R_smods p (pderiv p * q)› 2. ‹p ≠ 0 ⟹ taq {x. poly p x = 0} q = changes_R_smods p (pderiv p * q)›*) case True (*‹(p::real poly) = (0::real poly)›*) then show "?thesis" (*goal: ‹taq {x. poly p x = 0} q = changes_R_smods p (pderiv p * q)›*) unfolding taq_def (*goal: ‹(∑x::real | poly (p::real poly) x = (0::real). sign (poly (q::real poly) x)) = changes_R_smods p (pderiv p * q)›*) using infinite_UNIV_char_0 (*‹infinite UNIV›*) by (auto intro!:sum.infinite (*‹infinite ?A ⟹ sum ?g ?A = 0›*)) next (*goal: ‹p ≠ 0 ⟹ taq {x. poly p x = 0} q = changes_R_smods p (pderiv p * q)›*) case False (*‹(p::real poly) ≠ (0::real poly)›*) define ps where "ps≡smods p (pderiv p * q)" have "p∈set ps" using ps_def (*‹ps ≡ smods p (pderiv p * q)›*) ‹p≠0› (*‹(p::real poly) ≠ (0::real poly)›*) by auto obtain lb where lb: "∀p∈set ps. ∀x. poly p x=0 ⟶ x>lb" and lb_sgn: "∀x≤lb. ∀p∈set ps. sgn (poly p x) = sgn_neg_inf p" and "lb<0" (*goal: ‹(⋀lb. ⟦∀p∈set ps. ∀x. poly p x = 0 ⟶ lb < x; ∀x≤lb. ∀p∈set ps. sgn (poly p x) = sgn_neg_inf p; lb < 0⟧ ⟹ thesis) ⟹ thesis›*) using root_list_lb[OF no_0_in_smods, of p "pderiv p * q", folded ps_def] (*‹(⋀lb. ⟦∀p∈set ps. ∀x. poly p x = 0 ⟶ lb < x; ∀x≤lb. ∀p∈set ps. sgn (poly p x) = sgn_neg_inf p; lb < ?b⟧ ⟹ ?thesis) ⟹ ?thesis›*) by auto obtain ub where ub: "∀p∈set ps. ∀x. poly p x=0 ⟶ x<ub" and ub_sgn: "∀x≥ub. ∀p∈set ps. sgn (poly p x) = sgn_pos_inf p" and "ub>0" (*goal: ‹(⋀ub. ⟦∀p∈set ps. ∀x. poly p x = 0 ⟶ x < ub; ∀x≥ub. ∀p∈set ps. sgn (poly p x) = sgn_pos_inf p; 0 < ub⟧ ⟹ thesis) ⟹ thesis›*) using root_list_ub[OF no_0_in_smods, of p "pderiv p * q", folded ps_def] (*‹(⋀ub::real. ⟦∀p::real poly∈set (ps::real poly list). ∀x::real. poly p x = (0::real) ⟶ x < ub; ∀x≥ub. ∀p::real poly∈set ps. sgn (poly p x) = sgn_pos_inf p; (?a::real) < ub⟧ ⟹ ?thesis::bool) ⟹ ?thesis›*) by auto have "taq {x. poly p x=0} q = taq {x. poly p x=0 ∧ lb<x ∧ x<ub} q" unfolding taq_def (*goal: ‹(∑x | poly p x = 0. sign (poly q x)) = (∑x | poly p x = 0 ∧ lb < x ∧ x < ub. sign (poly q x))›*) apply (rule sum.cong (*‹⟦?A = ?B; ⋀x. x ∈ ?B ⟹ ?g x = ?h x⟧ ⟹ sum ?g ?A = sum ?h ?B›*)) (*goals: 1. ‹{x. poly p x = 0} = {x. poly p x = 0 ∧ lb < x ∧ x < ub}› 2. ‹⋀x. x ∈ {x. poly p x = 0 ∧ lb < x ∧ x < ub} ⟹ sign (poly q x) = sign (poly q x)› discuss goal 1*) apply ((insert lb (*‹∀p∈set ps. ∀x. poly p x = 0 ⟶ lb < x›*) ub (*‹∀p∈set ps. ∀x. poly p x = 0 ⟶ x < ub›*) ‹p∈set ps›)[1]) (*top goal: ‹{x. poly p x = 0} = {x. poly p x = 0 ∧ lb < x ∧ x < ub}› and 1 goal remains*) apply ((auto)[1]) (*discuss goal 2*) apply ((insert lb (*‹∀p∈set ps. ∀x. poly p x = 0 ⟶ lb < x›*) ub (*‹∀p∈set ps. ∀x. poly p x = 0 ⟶ x < ub›*) ‹p∈set ps›)[1]) (*goal: ‹⋀x. x ∈ {x. poly p x = 0 ∧ lb < x ∧ x < ub} ⟹ sign (poly q x) = sign (poly q x)›*) apply ((auto)[1]) (*proven 2 subgoals*) . moreover have "changes_R_smods p (pderiv p * q) = changes_itv_smods lb ub p (pderiv p * q)" proof (-) (*goal: ‹changes_R_smods p (pderiv p * q) = changes_itv_smods lb ub p (pderiv p * q)›*) have "map (sgn ∘ (λp. poly p lb)) ps = map sgn_neg_inf ps" and "map (sgn ∘ (λp. poly p ub)) ps = map sgn_pos_inf ps" using lb_sgn[THEN spec, of lb, simplified] (*‹∀p∈set ps. sgn (poly p lb) = sgn_neg_inf p›*) ub_sgn[THEN spec, of ub, simplified] (*‹∀p∈set ps. sgn (poly p ub) = sgn_pos_inf p›*) apply - (*goals: 1. ‹⟦∀p∈set ps. sgn (poly p lb) = sgn_neg_inf p; ∀p∈set ps. sgn (poly p ub) = sgn_pos_inf p⟧ ⟹ map (sgn ∘ (λp. poly p lb)) ps = map sgn_neg_inf ps› 2. ‹⟦∀p∈set ps. sgn (poly p lb) = sgn_neg_inf p; ∀p∈set ps. sgn (poly p ub) = sgn_pos_inf p⟧ ⟹ map (sgn ∘ (λp. poly p ub)) ps = map sgn_pos_inf ps› discuss goal 1*) apply (metis (mono_tags, lifting) comp_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*) list.map_cong0 (*‹(⋀z. z ∈ set ?x ⟹ ?f z = ?g z) ⟹ map ?f ?x = map ?g ?x›*)) (*discuss goal 2*) apply (metis (mono_tags, lifting) comp_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*) list.map_cong0 (*‹(⋀z. z ∈ set ?x ⟹ ?f z = ?g z) ⟹ map ?f ?x = map ?g ?x›*)) (*proven 2 subgoals*) . hence "changes_poly_at ps lb=changes_poly_neg_inf ps ∧ changes_poly_at ps ub=changes_poly_pos_inf ps" unfolding changes_poly_neg_inf_def changes_poly_at_def changes_poly_pos_inf_def (*goal: ‹changes (map (λp::real poly. poly p (lb::real)) (ps::real poly list)) = changes (map sgn_neg_inf ps) ∧ changes (map (λp::real poly. poly p (ub::real)) ps) = changes (map sgn_pos_inf ps)›*) apply (subst (1 3) changes_map_sgn_eq (*‹changes ?xs = changes (map sgn ?xs)›*)) (*goal: ‹changes (map (λp. poly p lb) ps) = changes (map sgn_neg_inf ps) ∧ changes (map (λp. poly p ub) ps) = changes (map sgn_pos_inf ps)›*) by (metis map_map (*‹map (?f::?'b ⇒ ?'a) (map (?g::?'c ⇒ ?'b) (?xs::?'c list)) = map (?f ∘ ?g) ?xs›*)) thus "?thesis" (*goal: ‹changes_R_smods p (pderiv p * q) = changes_itv_smods lb ub p (pderiv p * q)›*) unfolding changes_R_smods_def changes_itv_smods_def ps_def (*goal: ‹(let ps = smods p (pderiv p * q) in changes_poly_neg_inf ps - changes_poly_pos_inf ps) = (let ps = smods p (pderiv p * q) in changes_poly_at ps lb - changes_poly_at ps ub)›*) by metis qed moreover have "poly p lb≠0" and "poly p ub≠0" using lb (*‹∀p∈set ps. ∀x. poly p x = 0 ⟶ lb < x›*) ub (*‹∀p∈set ps. ∀x. poly p x = 0 ⟶ x < ub›*) ‹p∈set ps› (*‹(p::real poly) ∈ set (ps::real poly list)›*) apply - (*goals: 1. ‹⟦∀p∈set ps. ∀x. poly p x = 0 ⟶ lb < x; ∀p∈set ps. ∀x. poly p x = 0 ⟶ x < ub; p ∈ set ps⟧ ⟹ poly p lb ≠ 0› 2. ‹⟦∀p∈set ps. ∀x. poly p x = 0 ⟶ lb < x; ∀p∈set ps. ∀x. poly p x = 0 ⟶ x < ub; p ∈ set ps⟧ ⟹ poly p ub ≠ 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . moreover have "lb<ub" using ‹lb<0› (*‹(lb::real) < (0::real)›*) ‹0<ub› (*‹0 < ub›*) by auto ultimately show "?thesis" (*goal: ‹taq {x. poly p x = 0} q = changes_R_smods p (pderiv p * q)›*) using sturm_tarski_interval (*‹⟦?a < ?b; poly ?p ?a ≠ 0; poly ?p ?b ≠ 0⟧ ⟹ taq {x. poly ?p x = 0 ∧ ?a < x ∧ x < ?b} ?q = changes_itv_smods ?a ?b ?p (pderiv ?p * ?q)›*) by auto qed theorem sturm_interval: assumes "a < b" "poly p a ≠ 0" "poly p b ≠ 0" shows "card {x. poly p x = 0 ∧ a < x ∧ x < b} = changes_itv_smods a b p (pderiv p)" using sturm_tarski_interval[OF assms, unfolded taq_def, of 1] (*‹(∑x | poly p x = 0 ∧ a < x ∧ x < b. sign (poly 1 x)) = changes_itv_smods a b p (pderiv p * 1)›*) by force theorem sturm_above: assumes "poly p a ≠ 0" shows "card {x. poly p x = 0 ∧ a < x} = changes_gt_smods a p (pderiv p)" using sturm_tarski_above[OF assms, unfolded taq_def, of 1] (*‹(∑x::real | poly (p::real poly) x = (0::real) ∧ (a::real) < x. sign (poly (1::real poly) x)) = changes_gt_smods a p (pderiv p * (1::real poly))›*) by force theorem sturm_below: assumes "poly p b ≠ 0" shows "card {x. poly p x = 0 ∧ x < b} = changes_le_smods b p (pderiv p)" using sturm_tarski_below[OF assms, unfolded taq_def, of 1] (*‹(∑x::real | poly (p::real poly) x = (0::real) ∧ x < (b::real). sign (poly (1::real poly) x)) = changes_le_smods b p (pderiv p * (1::real poly))›*) by force theorem sturm_R: shows "card {x. poly p x=0} = changes_R_smods p (pderiv p)" using sturm_tarski_R[of _ 1, unfolded taq_def] (*‹(∑x | poly ?p x = 0. sign (poly 1 x)) = changes_R_smods ?p (pderiv ?p * 1)›*) by force end
{ "path": "afp-2025-02-12/thys/Sturm_Tarski/Sturm_Tarski.thy", "repo": "afp-2025-02-12", "sha": "79318959df16a28f3bf45740f94d85ee9ea28a06da08d77975fbccce9fa52556" }
(* Author: L C Paulson, University of Cambridge Author: Amine Chaieb, University of Cambridge Author: Robert Himmelmann, TU Muenchen Author: Brian Huffman, Portland State University *) chapter ‹Topology› theory Elementary_Topology imports "HOL-Library.Set_Idioms" "HOL-Library.Disjoint_Sets" Product_Vector begin section ‹Elementary Topology› subsubsection✐‹tag unimportant› ‹Affine transformations of intervals› lemma real_affinity_le: "0 < m ⟹ m * x + c ≤ y ⟷ x ≤ inverse m * y + - (c / m)" for m :: "'a::linordered_field" by (simp add: field_simps (*‹(?a::?'a::semigroup_add) + (?b::?'a::semigroup_add) + (?c::?'a::semigroup_add) = ?a + (?b + ?c)› ‹(?a::?'a::ab_semigroup_add) + (?b::?'a::ab_semigroup_add) = ?b + ?a› ‹(?b::?'a::ab_semigroup_add) + ((?a::?'a::ab_semigroup_add) + (?c::?'a::ab_semigroup_add)) = ?a + (?b + ?c)› ‹(?a::?'a::semigroup_mult) * (?b::?'a::semigroup_mult) * (?c::?'a::semigroup_mult) = ?a * (?b * ?c)› ‹(?a::?'a::ab_semigroup_mult) * (?b::?'a::ab_semigroup_mult) = ?b * ?a› ‹(?b::?'a::ab_semigroup_mult) * ((?a::?'a::ab_semigroup_mult) * (?c::?'a::ab_semigroup_mult)) = ?a * (?b * ?c)› ‹(?a::?'a::cancel_ab_semigroup_add) - (?b::?'a::cancel_ab_semigroup_add) - (?c::?'a::cancel_ab_semigroup_add) = ?a - (?b + ?c)› ‹(?a::?'a::group_add) + ((?b::?'a::group_add) - (?c::?'a::group_add)) = ?a + ?b - ?c› ‹((?a::?'a::group_add) - (?b::?'a::group_add) = (?c::?'a::group_add)) = (?a = ?c + ?b)› ‹((?a::?'a::group_add) = (?c::?'a::group_add) - (?b::?'a::group_add)) = (?a + ?b = ?c)› ‹(?a::?'a::group_add) - ((?b::?'a::group_add) - (?c::?'a::group_add)) = ?a + ?c - ?b› ‹(?a::?'a::ab_group_add) - (?b::?'a::ab_group_add) + (?c::?'a::ab_group_add) = ?a + ?c - ?b› and more 69 facts*)) lemma real_le_affinity: "0 < m ⟹ y ≤ m * x + c ⟷ inverse m * y + - (c / m) ≤ x" for m :: "'a::linordered_field" by (simp add: field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 69 facts*)) lemma real_affinity_lt: "0 < m ⟹ m * x + c < y ⟷ x < inverse m * y + - (c / m)" for m :: "'a::linordered_field" by (simp add: field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 69 facts*)) lemma real_lt_affinity: "0 < m ⟹ y < m * x + c ⟷ inverse m * y + - (c / m) < x" for m :: "'a::linordered_field" by (simp add: field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 69 facts*)) lemma real_affinity_eq: "m ≠ 0 ⟹ m * x + c = y ⟷ x = inverse m * y + - (c / m)" for m :: "'a::linordered_field" by (simp add: field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 69 facts*)) lemma real_eq_affinity: "m ≠ 0 ⟹ y = m * x + c ⟷ inverse m * y + - (c / m) = x" for m :: "'a::linordered_field" by (simp add: field_simps (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)› ‹(?a::?'a) * (?b::?'a) * (?c::?'a) = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)› ‹(?a::?'a) - (?b::?'a) - (?c::?'a) = ?a - (?b + ?c)› ‹(?a::?'a) + ((?b::?'a) - (?c::?'a)) = ?a + ?b - ?c› ‹((?a::?'a) - (?b::?'a) = (?c::?'a)) = (?a = ?c + ?b)› ‹((?a::?'a) = (?c::?'a) - (?b::?'a)) = (?a + ?b = ?c)› ‹(?a::?'a) - ((?b::?'a) - (?c::?'a)) = ?a + ?c - ?b› ‹(?a::?'a) - (?b::?'a) + (?c::?'a) = ?a + ?c - ?b› and more 69 facts*)) subsection ‹Topological Basis› context topological_space begin definition✐‹tag important› "topological_basis B ⟷ (∀b∈B. open b) ∧ (∀x. open x ⟶ (∃B'. B' ⊆ B ∧ ⋃B' = x))" lemma topological_basis: "topological_basis B ⟷ (∀x. open x ⟷ (∃B'. B' ⊆ B ∧ ⋃B' = x))" (is "?lhs = ?rhs") proof (standard) (*goals: 1. ‹topological_basis B ⟹ ∀x. open x = (∃B'⊆B. ⋃ B' = x)› 2. ‹∀x. open x = (∃B'⊆B. ⋃ B' = x) ⟹ topological_basis B›*) show "?lhs ⟹ ?rhs" by (meson local.open_Union (*‹Ball ?K open ⟹ open (⋃ ?K)›*) subsetD (*‹⟦?A ⊆ ?B; ?c ∈ ?A⟧ ⟹ ?c ∈ ?B›*) topological_basis_def (*‹topological_basis ?B = (Ball ?B open ∧ (∀x. open x ⟶ (∃B'⊆?B. ⋃ B' = x)))›*)) show "?rhs ⟹ ?lhs" unfolding topological_basis_def (*goal: ‹∀x. open x = (∃B'⊆B. ⋃ B' = x) ⟹ Ball B open ∧ (∀x. open x ⟶ (∃B'⊆B. ⋃ B' = x))›*) by (metis cSup_singleton (*‹Sup {?x} = ?x›*) empty_subsetI (*‹{} ⊆ ?A›*) insert_subset (*‹(insert ?x ?A ⊆ ?B) = (?x ∈ ?B ∧ ?A ⊆ ?B)›*)) qed lemma topological_basis_iff: assumes "⋀B'. B' ∈ B ⟹ open B'" shows "topological_basis B ⟷ (∀O'. open O' ⟶ (∀x∈O'. ∃B'∈B. x ∈ B' ∧ B' ⊆ O'))" (is "_ ⟷ ?rhs") proof (safe) (*goals: 1. ‹⋀O' x. ⟦topological_basis B; open O'; x ∈ O'⟧ ⟹ ∃B'∈B. x ∈ B' ∧ B' ⊆ O'› 2. ‹∀O'. open O' ⟶ (∀x∈O'. ∃B'∈B. x ∈ B' ∧ B' ⊆ O') ⟹ topological_basis B›*) fix O' and x :: 'a assume H: "topological_basis B" "open O'" "x ∈ O'" (*‹topological_basis (B::'a set set)› ‹open (O'::'a set)› ‹(x::'a) ∈ (O'::'a set)›*) then have "(∃B'⊆B. ⋃B' = O')" by (simp add: topological_basis_def (*‹topological_basis ?B = (Ball ?B open ∧ (∀x. open x ⟶ (∃B'⊆?B. ⋃ B' = x)))›*)) then obtain B' where "B' ⊆ B" "O' = ⋃B'" (*goal: ‹(⋀B'. ⟦B' ⊆ B; O' = ⋃ B'⟧ ⟹ thesis) ⟹ thesis›*) by auto then show "∃B'∈B. x ∈ B' ∧ B' ⊆ O'" using H (*‹topological_basis B› ‹open O'› ‹x ∈ O'›*) by auto next (*goal: ‹∀O'::'a::type set. open O' ⟶ (∀x::'a::type∈O'. ∃B'::'a::type set∈B::'a::type set set. x ∈ B' ∧ B' ⊆ O') ⟹ topological_basis B›*) assume H: "?rhs" (*‹∀O'::'a set. open O' ⟶ (∀x::'a∈O'. ∃B'::'a set∈B::'a set set. x ∈ B' ∧ B' ⊆ O')›*) show "topological_basis B" using assms (*‹?B' ∈ B ⟹ open ?B'›*) unfolding topological_basis_def (*goal: ‹Ball B open ∧ (∀x. open x ⟶ (∃B'⊆B. ⋃ B' = x))›*) proof (safe) (*goals: 1. ‹⋀x. ⟦⋀B'. B' ∈ B ⟹ open B'; x ∈ B⟧ ⟹ open x› 2. ‹⋀x. ⟦⋀B'. B' ∈ B ⟹ open B'; open x⟧ ⟹ ∃B'⊆B. ⋃ B' = x›*) fix O' :: "'a set" assume "open O'" (*‹open (O'::'a set)›*) with H (*‹∀O'. open O' ⟶ (∀x∈O'. ∃B'∈B. x ∈ B' ∧ B' ⊆ O')›*) obtain f where "∀x∈O'. f x ∈ B ∧ x ∈ f x ∧ f x ⊆ O'" (*goal: ‹(⋀f. ∀x∈O'. f x ∈ B ∧ x ∈ f x ∧ f x ⊆ O' ⟹ thesis) ⟹ thesis›*) by (force intro: bchoice (*‹∀x∈?S. ∃y. ?Q x y ⟹ ∃f. ∀x∈?S. ?Q x (f x)›*) simp: Bex_def (*‹Bex ?A ?P = (∃x. x ∈ ?A ∧ ?P x)›*)) then show "∃B'⊆B. ⋃B' = O'" by (auto intro: exI[where x="{f x |x. x ∈ O'}"] (*‹?P {f x |x. x ∈ O'} ⟹ ∃x. ?P x›*)) qed qed lemma topological_basisI: assumes "⋀B'. B' ∈ B ⟹ open B'" and "⋀O' x. open O' ⟹ x ∈ O' ⟹ ∃B'∈B. x ∈ B' ∧ B' ⊆ O'" shows "topological_basis B" by (simp add: assms (*‹?B' ∈ B ⟹ open ?B'› ‹⟦open ?O'; ?x ∈ ?O'⟧ ⟹ ∃B'∈B. ?x ∈ B' ∧ B' ⊆ ?O'›*) topological_basis_iff (*‹(⋀B'. B' ∈ ?B ⟹ open B') ⟹ topological_basis ?B = (∀O'. open O' ⟶ (∀x∈O'. ∃B'∈?B. x ∈ B' ∧ B' ⊆ O'))›*)) lemma topological_basisE: fixes O' assumes "topological_basis B" and "open O'" and "x ∈ O'" obtains B' where "B' ∈ B" "x ∈ B'" "B' ⊆ O'" by (metis assms (*‹topological_basis B› ‹open O'› ‹x ∈ O'›*) topological_basis_def (*‹topological_basis ?B = (Ball ?B open ∧ (∀x. open x ⟶ (∃B'⊆?B. ⋃ B' = x)))›*) topological_basis_iff (*‹(⋀B'. B' ∈ ?B ⟹ open B') ⟹ topological_basis ?B = (∀O'. open O' ⟶ (∀x∈O'. ∃B'∈?B. x ∈ B' ∧ B' ⊆ O'))›*)) lemma topological_basis_open: assumes "topological_basis B" and "X ∈ B" shows "open X" using assms (*‹topological_basis B› ‹(X::'a::type set) ∈ (B::'a::type set set)›*) by (simp add: topological_basis_def (*‹topological_basis (?B::'a set set) = (Ball ?B open ∧ (∀x::'a set. open x ⟶ (∃B'⊆?B. ⋃ B' = x)))›*)) lemma topological_basis_imp_subbasis: assumes B: "topological_basis B" shows "open = generate_topology B" proof (intro ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*) iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*)) (*goals: 1. ‹⋀x. open x ⟹ generate_topology B x› 2. ‹⋀x. generate_topology B x ⟹ open x›*) fix S :: "'a set" assume "open S" (*‹open (S::'a set)›*) with B (*‹topological_basis B›*) obtain B' where "B' ⊆ B" "S = ⋃B'" (*goal: ‹(⋀B'. ⟦B' ⊆ B; S = ⋃ B'⟧ ⟹ thesis) ⟹ thesis›*) unfolding topological_basis_def (*goal: ‹(⋀B'. ⟦B' ⊆ B; S = ⋃ B'⟧ ⟹ thesis) ⟹ thesis›*) by blast then show "generate_topology B S" by (auto intro: generate_topology.intros (*‹generate_topology ?S UNIV› ‹⟦generate_topology ?S ?a; generate_topology ?S ?b⟧ ⟹ generate_topology ?S (?a ∩ ?b)› ‹(⋀k. k ∈ ?K ⟹ generate_topology ?S k) ⟹ generate_topology ?S (⋃ ?K)› ‹?s ∈ ?S ⟹ generate_topology ?S ?s›*) dest: topological_basis_open (*‹⟦topological_basis ?B; ?X ∈ ?B⟧ ⟹ open ?X›*)) next (*goal: ‹⋀x. generate_topology B x ⟹ open x›*) fix S :: "'a set" assume "generate_topology B S" (*‹generate_topology (B::'a set set) (S::'a set)›*) then show "open S" apply induct (*goals: 1. ‹open UNIV› 2. ‹⋀(a::'a::type set) b::'a::type set. ⟦generate_topology (B::'a::type set set) a; open a; generate_topology B b; open b⟧ ⟹ open (a ∩ b)› 3. ‹⋀K::'a::type set set. ⟦⋀k::'a::type set. k ∈ K ⟹ generate_topology (B::'a::type set set) k; ⋀k::'a::type set. k ∈ K ⟹ open k⟧ ⟹ open (⋃ K)› 4. ‹⋀s::'a::type set. s ∈ (B::'a::type set set) ⟹ open s› discuss goal 1*) apply ((auto dest: topological_basis_open[OF B] (*‹?X ∈ B ⟹ open ?X›*))[1]) (*discuss goal 2*) apply ((auto dest: topological_basis_open[OF B] (*‹?X ∈ B ⟹ open ?X›*))[1]) (*discuss goal 3*) apply ((auto dest: topological_basis_open[OF B] (*‹(?X::'a set) ∈ (B::'a set set) ⟹ open ?X›*))[1]) (*discuss goal 4*) apply ((auto dest: topological_basis_open[OF B] (*‹?X ∈ B ⟹ open ?X›*))[1]) (*proven 4 subgoals*) . qed lemma basis_dense: fixes B :: "'a set set" and f :: "'a set ⇒ 'a" assumes "topological_basis B" and "⋀B'. B' ≠ {} ⟹ f B' ∈ B'" shows "∀X. open X ⟶ X ≠ {} ⟶ (∃B' ∈ B. f B' ∈ X)" by (metis assms (*‹topological_basis B› ‹?B' ≠ {} ⟹ f ?B' ∈ ?B'›*) equals0D (*‹?A = {} ⟹ ?a ∉ ?A›*) in_mono (*‹?A ⊆ ?B ⟹ ?x ∈ ?A ⟶ ?x ∈ ?B›*) topological_basisE (*‹⟦topological_basis ?B; open ?O'; ?x ∈ ?O'; ⋀B'. ⟦B' ∈ ?B; ?x ∈ B'; B' ⊆ ?O'⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) end lemma topological_basis_prod: assumes A: "topological_basis A" and B: "topological_basis B" shows "topological_basis ((λ(a, b). a × b) ` (A × B))" proof (-) (*goal: ‹topological_basis ((λ(a, b). a × b) ` (A × B))›*) have "∃X⊆A × B. (⋃(a,b)∈X. a × b) = S" if "open S" for S proof (-) (*goal: ‹∃X⊆A × B. (⋃(a, b)∈X. a × b) = S›*) have "(x, y) ∈ (⋃(a, b)∈{X ∈ A × B. fst X × snd X ⊆ S}. a × b)" if xy: "(x, y) ∈ S" for x and y proof (-) (*goal: ‹(x, y) ∈ (⋃(a, b)∈{X ∈ A × B. fst X × snd X ⊆ S}. a × b)›*) obtain a and b where a: "open a" "x ∈ a" and b: "open b" "y ∈ b" and "a × b ⊆ S" (*goal: ‹(⋀a b. ⟦open a; x ∈ a; open b; y ∈ b; a × b ⊆ S⟧ ⟹ thesis) ⟹ thesis›*) by (metis open_prod_elim[OF ‹open S›] (*‹⟦?x ∈ S; ⋀A B. ⟦open A; open B; ?x ∈ A × B; A × B ⊆ S⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) xy (*‹(x, y) ∈ S›*) mem_Sigma_iff (*‹((?a, ?b) ∈ Sigma ?A ?B) = (?a ∈ ?A ∧ ?b ∈ ?B ?a)›*)) moreover obtain A0 where "A0 ∈ A" "x ∈ A0" "A0 ⊆ a" (*goal: ‹(⋀A0. ⟦A0 ∈ A; x ∈ A0; A0 ⊆ a⟧ ⟹ thesis) ⟹ thesis›*) using A (*‹topological_basis A›*) a (*‹open (a::'a set)› ‹x ∈ a›*) b (*‹open b› ‹y ∈ b›*) topological_basisE (*‹⟦topological_basis ?B; open ?O'; ?x ∈ ?O'; ⋀B'. ⟦B' ∈ ?B; ?x ∈ B'; B' ⊆ ?O'⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) by blast moreover from B (*‹topological_basis B›*) b (*‹open b› ‹y ∈ b›*) obtain B0 where "B0 ∈ B" "y ∈ B0" "B0 ⊆ b" (*goal: ‹(⋀B0. ⟦B0 ∈ B; y ∈ B0; B0 ⊆ b⟧ ⟹ thesis) ⟹ thesis›*) by (rule topological_basisE (*‹⟦topological_basis ?B; open ?O'; ?x ∈ ?O'; ⋀B'. ⟦B' ∈ ?B; ?x ∈ B'; B' ⊆ ?O'⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) ultimately show "?thesis" (*goal: ‹(x, y) ∈ (⋃(a, b)∈{X ∈ A × B. fst X × snd X ⊆ S}. a × b)›*) apply (intro UN_I[of "(A0, B0)"] (*‹⟦(A0, B0) ∈ ?A; ?b ∈ ?B (A0, B0)⟧ ⟹ ?b ∈ ⋃ (?B ` ?A)›*)) (*goals: 1. ‹⟦open a; x ∈ a; open b; y ∈ b; a × b ⊆ S; A0 ∈ A; x ∈ A0; A0 ⊆ a; B0 ∈ B; y ∈ B0; B0 ⊆ b⟧ ⟹ (A0, B0) ∈ {X ∈ A × B. fst X × snd X ⊆ S}› 2. ‹⟦open a; x ∈ a; open b; y ∈ b; a × b ⊆ S; A0 ∈ A; x ∈ A0; A0 ⊆ a; B0 ∈ B; y ∈ B0; B0 ⊆ b⟧ ⟹ (x, y) ∈ (case (A0, B0) of (a, b) ⇒ a × b)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed then have "(⋃(a, b)∈{x ∈ A × B. fst x × snd x ⊆ S}. a × b) = S" by force then show "?thesis" (*goal: ‹∃X⊆A × B. (⋃(a, b)∈X. a × b) = S›*) using subset_eq (*‹((?A::?'a set) ⊆ (?B::?'a set)) = (∀x::?'a∈?A. x ∈ ?B)›*) by force qed with A (*‹topological_basis A›*) B (*‹topological_basis B›*) show "?thesis" (*goal: ‹topological_basis ((λ(a, b). a × b) ` (A × B))›*) unfolding topological_basis_def (*goal: ‹Ball ((λ(a, b). a × b) ` (A × B)) open ∧ (∀x. open x ⟶ (∃B'⊆(λ(a, b). a × b) ` (A × B). ⋃ B' = x))›*) by (smt (verit) SigmaE (*‹⟦?c ∈ Sigma ?A ?B; ⋀x y. ⟦x ∈ ?A; y ∈ ?B x; ?c = (x, y)⟧ ⟹ ?P⟧ ⟹ ?P›*) imageE (*‹⟦?b ∈ ?f ` ?A; ⋀x. ⟦?b = ?f x; x ∈ ?A⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) image_mono (*‹?A ⊆ ?B ⟹ ?f ` ?A ⊆ ?f ` ?B›*) open_Times (*‹⟦open ?S; open ?T⟧ ⟹ open (?S × ?T)›*) case_prod_conv (*‹(case (?a, ?b) of (c, d) ⇒ ?f c d) = ?f ?a ?b›*)) qed subsection ‹Countable Basis› locale✐‹tag important› countable_basis = topological_space p for p::"'a set ⇒ bool" + fixes B :: "'a set set" assumes is_basis: "topological_basis B" and countable_basis: "countable B" begin lemma open_countable_basis_ex: assumes "p X" shows "∃B' ⊆ B. X = ⋃B'" using assms (*‹p X›*) countable_basis (*‹countable B›*) is_basis (*‹local.topological_basis B›*) unfolding topological_basis_def (*goal: ‹∃B'⊆B. X = ⋃ B'›*) by blast lemma open_countable_basisE: assumes "p X" obtains B' where "B' ⊆ B" "X = ⋃B'" using assms (*‹p X›*) open_countable_basis_ex (*‹p ?X ⟹ ∃B'⊆B. ?X = ⋃ B'›*) by auto lemma countable_dense_exists: "∃D::'a set. countable D ∧ (∀X. p X ⟶ X ≠ {} ⟶ (∃d ∈ D. d ∈ X))" proof (-) (*goal: ‹∃D. countable D ∧ (∀X. p X ⟶ X ≠ {} ⟶ (∃d∈D. d ∈ X))›*) let ?f = "(λB'. SOME x. x ∈ B')" have "countable (?f ` B)" using countable_basis (*‹countable B›*) by simp with basis_dense[OF is_basis, of ?f] (*‹(⋀B'::'a set. B' ≠ {} ⟹ (SOME x::'a. x ∈ B') ∈ B') ⟹ ∀X::'a set. (p::'a set ⇒ bool) X ⟶ X ≠ {} ⟶ (∃B'::'a set∈B::'a set set. (SOME x::'a. x ∈ B') ∈ X)›*) show "?thesis" (*goal: ‹∃D. countable D ∧ (∀X. p X ⟶ X ≠ {} ⟶ (∃d∈D. d ∈ X))›*) apply (intro exI[where x="?f ` B"] (*‹?P ((λB'. SOME x. x ∈ B') ` B) ⟹ ∃x. ?P x›*)) (*goal: ‹∃D. countable D ∧ (∀X. p X ⟶ X ≠ {} ⟶ (∃d∈D. d ∈ X))›*) by (metis (mono_tags) all_not_in_conv (*‹(∀x. x ∉ ?A) = (?A = {})›*) imageI (*‹?x ∈ ?A ⟹ ?f ?x ∈ ?f ` ?A›*) someI (*‹?P ?x ⟹ ?P (Eps ?P)›*)) qed lemma countable_dense_setE: obtains D :: "'a set" where "countable D" "⋀X. p X ⟹ X ≠ {} ⟹ ∃d ∈ D. d ∈ X" using countable_dense_exists (*‹∃D. countable D ∧ (∀X. p X ⟶ X ≠ {} ⟶ (∃d∈D. d ∈ X))›*) by blast end lemma countable_basis_openI: "countable_basis open B" if "countable B" "topological_basis B" using that (*‹countable B› ‹topological_basis B›*) apply unfold_locales (*goals: 1. ‹⟦countable B; topological_basis B⟧ ⟹ topological_space.topological_basis open B› 2. ‹⟦countable B; topological_basis B⟧ ⟹ countable B› discuss goal 1*) apply (simp add: topological_basis (*‹topological_basis ?B = (∀x. open x = (∃B'⊆?B. ⋃ B' = x))›*) topological_space.topological_basis (*‹class.topological_space ?open ⟹ topological_space.topological_basis ?open ?B = (∀x. ?open x = (∃B'⊆?B. ⋃ B' = x))›*) topological_space_axioms (*‹class.topological_space open›*)) (*discuss goal 2*) apply (simp add: topological_basis (*‹topological_basis (?B::?'a::topological_space set set) = (∀x::?'a::topological_space set. open x = (∃B'⊆?B. ⋃ B' = x))›*) topological_space.topological_basis (*‹class.topological_space (?open::?'a::type set ⇒ bool) ⟹ topological_space.topological_basis ?open (?B::?'a::type set set) = (∀x::?'a::type set. ?open x = (∃B'⊆?B. ⋃ B' = x))›*) topological_space_axioms (*‹class.topological_space open›*)) (*proven 2 subgoals*) . lemma (in first_countable_topology) first_countable_basisE: fixes x :: 'a obtains 𝒜 where "countable 𝒜" "⋀A. A ∈ 𝒜 ⟹ x ∈ A" "⋀A. A ∈ 𝒜 ⟹ open A" "⋀S. open S ⟹ x ∈ S ⟹ (∃A∈𝒜. A ⊆ S)" proof (-) (*goal: ‹(⋀𝒜. ⟦countable 𝒜; ⋀A. A ∈ 𝒜 ⟹ x ∈ A; ⋀A. A ∈ 𝒜 ⟹ open A; ⋀S. ⟦open S; x ∈ S⟧ ⟹ ∃A∈𝒜. A ⊆ S⟧ ⟹ thesis) ⟹ thesis›*) obtain 𝒜 where "𝒜": "(∀i::nat. x ∈ 𝒜 i ∧ open (𝒜 i))" "(∀S. open S ∧ x ∈ S ⟶ (∃i. 𝒜 i ⊆ S))" (*goal: ‹(⋀𝒜. ⟦∀i. x ∈ 𝒜 i ∧ open (𝒜 i); ∀S. open S ∧ x ∈ S ⟶ (∃i. 𝒜 i ⊆ S)⟧ ⟹ thesis) ⟹ thesis›*) using first_countable_basis[of x] (*‹∃A. (∀i. x ∈ A i ∧ open (A i)) ∧ (∀S. open S ∧ x ∈ S ⟶ (∃i. A i ⊆ S))›*) by metis moreover have "countable (range 𝒜)" by simp ultimately show thesis by (smt (verit, best) imageE (*‹⟦?b ∈ ?f ` ?A; ⋀x. ⟦?b = ?f x; x ∈ ?A⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) rangeI (*‹?f ?x ∈ range ?f›*) that (*‹⟦countable ?𝒜; ⋀A. A ∈ ?𝒜 ⟹ x ∈ A; ⋀A. A ∈ ?𝒜 ⟹ open A; ⋀S. ⟦open S; x ∈ S⟧ ⟹ ∃A∈?𝒜. A ⊆ S⟧ ⟹ thesis›*)) qed lemma (in first_countable_topology) first_countable_basis_Int_stableE: obtains 𝒜 where "countable 𝒜" "⋀A. A ∈ 𝒜 ⟹ x ∈ A" "⋀A. A ∈ 𝒜 ⟹ open A" "⋀S. open S ⟹ x ∈ S ⟹ (∃A∈𝒜. A ⊆ S)" "⋀A B. A ∈ 𝒜 ⟹ B ∈ 𝒜 ⟹ A ∩ B ∈ 𝒜" proof (atomize_elim) (*goal: ‹∃𝒜. countable 𝒜 ∧ (∀A. A ∈ 𝒜 ⟶ x ∈ A) ∧ (∀A. A ∈ 𝒜 ⟶ open A) ∧ (∀S. open S ⟶ x ∈ S ⟶ (∃A∈𝒜. A ⊆ S)) ∧ (∀A B. A ∈ 𝒜 ⟶ B ∈ 𝒜 ⟶ A ∩ B ∈ 𝒜)›*) obtain ℬ where "ℬ": "countable ℬ" "⋀B. B ∈ ℬ ⟹ x ∈ B" "⋀B. B ∈ ℬ ⟹ open B" "⋀S. open S ⟹ x ∈ S ⟹ ∃B∈ℬ. B ⊆ S" (*goal: ‹(⋀ℬ. ⟦countable ℬ; ⋀B. B ∈ ℬ ⟹ x ∈ B; ⋀B. B ∈ ℬ ⟹ open B; ⋀S. ⟦open S; x ∈ S⟧ ⟹ ∃B∈ℬ. B ⊆ S⟧ ⟹ thesis) ⟹ thesis›*) apply (rule first_countable_basisE (*‹(⋀𝒜. ⟦countable 𝒜; ⋀A. A ∈ 𝒜 ⟹ ?x ∈ A; ⋀A. A ∈ 𝒜 ⟹ open A; ⋀S. ⟦open S; ?x ∈ S⟧ ⟹ ∃A∈𝒜. A ⊆ S⟧ ⟹ ?thesis) ⟹ ?thesis›*)) (*goal: ‹(⋀ℬ. ⟦countable ℬ; ⋀B. B ∈ ℬ ⟹ x ∈ B; ⋀B. B ∈ ℬ ⟹ open B; ⋀S. ⟦open S; x ∈ S⟧ ⟹ ∃B∈ℬ. B ⊆ S⟧ ⟹ thesis) ⟹ thesis›*) by blast define 𝒜 where [abs_def]: "𝒜 = (λN. ⋂((λn. from_nat_into ℬ n) ` N)) ` (Collect finite::nat set set)" then show "∃𝒜. countable 𝒜 ∧ (∀A. A ∈ 𝒜 ⟶ x ∈ A) ∧ (∀A. A ∈ 𝒜 ⟶ open A) ∧ (∀S. open S ⟶ x ∈ S ⟶ (∃A∈𝒜. A ⊆ S)) ∧ (∀A B. A ∈ 𝒜 ⟶ B ∈ 𝒜 ⟶ A ∩ B ∈ 𝒜)" proof (safe intro!: exI[where x=𝒜] (*‹?P 𝒜 ⟹ ∃x. ?P x›*)) (*goals: 1. ‹𝒜::'a set set ≡ (λN::nat set. ⋂ (from_nat_into (ℬ::'a set set) ` N)) ` Collect finite ⟹ countable 𝒜› 2. ‹⋀A::'a set. ⟦𝒜::'a set set ≡ (λN::nat set. ⋂ (from_nat_into (ℬ::'a set set) ` N)) ` Collect finite; A ∈ 𝒜⟧ ⟹ (x::'a) ∈ A› 3. ‹⋀A::'a set. ⟦𝒜::'a set set ≡ (λN::nat set. ⋂ (from_nat_into (ℬ::'a set set) ` N)) ` Collect finite; A ∈ 𝒜⟧ ⟹ open A› 4. ‹⋀S::'a set. ⟦𝒜::'a set set ≡ (λN::nat set. ⋂ (from_nat_into (ℬ::'a set set) ` N)) ` Collect finite; open S; (x::'a) ∈ S⟧ ⟹ ∃A::'a set∈𝒜. A ⊆ S› 5. ‹⋀(A::'a set) B::'a set. ⟦𝒜::'a set set ≡ (λN::nat set. ⋂ (from_nat_into (ℬ::'a set set) ` N)) ` Collect finite; A ∈ 𝒜; B ∈ 𝒜⟧ ⟹ A ∩ B ∈ 𝒜›*) show "countable 𝒜" unfolding "𝒜_def" (*goal: ‹countable ((λN. ⋂ (from_nat_into ℬ ` N)) ` Collect finite)›*) by (intro countable_image (*‹countable ?A ⟹ countable (?f ` ?A)›*) countable_Collect_finite (*‹countable (Collect finite)›*)) fix A assume "A ∈ 𝒜" (*‹(A::'a set) ∈ (𝒜::'a set set)›*) then show "x ∈ A" "open A" using "ℬ"(4)[OF open_UNIV] (*‹x ∈ UNIV ⟹ ∃B∈ℬ. B ⊆ UNIV›*) apply - (*goals: 1. ‹⟦A ∈ 𝒜; x ∈ UNIV ⟹ ∃B∈ℬ. B ⊆ UNIV⟧ ⟹ x ∈ A› 2. ‹⟦A ∈ 𝒜; x ∈ UNIV ⟹ ∃B∈ℬ. B ⊆ UNIV⟧ ⟹ open A› discuss goal 1*) apply ((auto simp: 𝒜_def (*‹𝒜 ≡ (λN. ⋂ (from_nat_into ℬ ` N)) ` Collect finite›*) intro: ℬ (*‹countable ℬ› ‹?B ∈ ℬ ⟹ x ∈ ?B› ‹?B ∈ ℬ ⟹ open ?B› ‹⟦open ?S; x ∈ ?S⟧ ⟹ ∃B∈ℬ. B ⊆ ?S›*) from_nat_into (*‹?A ≠ {} ⟹ from_nat_into ?A ?n ∈ ?A›*))[1]) (*discuss goal 2*) apply ((auto simp: 𝒜_def (*‹𝒜 ≡ (λN. ⋂ (from_nat_into ℬ ` N)) ` Collect finite›*) intro: ℬ (*‹countable ℬ› ‹?B ∈ ℬ ⟹ x ∈ ?B› ‹?B ∈ ℬ ⟹ open ?B› ‹⟦open ?S; x ∈ ?S⟧ ⟹ ∃B∈ℬ. B ⊆ ?S›*) from_nat_into (*‹?A ≠ {} ⟹ from_nat_into ?A ?n ∈ ?A›*))[1]) (*proven 2 subgoals*) . next (*goals: 1. ‹⋀S. ⟦𝒜 ≡ (λN. ⋂ (from_nat_into ℬ ` N)) ` Collect finite; open S; x ∈ S⟧ ⟹ ∃A∈𝒜. A ⊆ S› 2. ‹⋀A B. ⟦𝒜 ≡ (λN. ⋂ (from_nat_into ℬ ` N)) ` Collect finite; A ∈ 𝒜; B ∈ 𝒜⟧ ⟹ A ∩ B ∈ 𝒜›*) let ?int = "λN. ⋂(from_nat_into ℬ ` N)" fix A and B assume "A ∈ 𝒜" "B ∈ 𝒜" (*‹(A::'a set) ∈ (𝒜::'a set set)› ‹(B::'a set) ∈ (𝒜::'a set set)›*) then obtain N and M where "A = ?int N" "B = ?int M" "finite (N ∪ M)" (*goal: ‹(⋀N M. ⟦A = ⋂ (from_nat_into ℬ ` N); B = ⋂ (from_nat_into ℬ ` M); finite (N ∪ M)⟧ ⟹ thesis) ⟹ thesis›*) by (auto simp: 𝒜_def (*‹𝒜::'a set set ≡ (λN::nat set. ⋂ (from_nat_into (ℬ::'a set set) ` N)) ` Collect finite›*)) then show "A ∩ B ∈ 𝒜" by (auto simp: 𝒜_def (*‹𝒜 ≡ (λN. ⋂ (from_nat_into ℬ ` N)) ` Collect finite›*) intro!: image_eqI[where x="N ∪ M"] (*‹⟦?b = ?f (N ∪ M); N ∪ M ∈ ?A⟧ ⟹ ?b ∈ ?f ` ?A›*)) next (*goal: ‹⋀S. ⟦𝒜 ≡ (λN. ⋂ (from_nat_into ℬ ` N)) ` Collect finite; open S; x ∈ S⟧ ⟹ ∃A∈𝒜. A ⊆ S›*) fix S assume "open S" "x ∈ S" (*‹open (S::'a set)› ‹(x::'a) ∈ (S::'a set)›*) then obtain a where a: "a∈ℬ" "a ⊆ S" (*goal: ‹(⋀a. ⟦a ∈ ℬ; a ⊆ S⟧ ⟹ thesis) ⟹ thesis›*) using "ℬ" (*‹countable (ℬ::'a::type set set)› ‹?B ∈ ℬ ⟹ x ∈ ?B› ‹?B ∈ ℬ ⟹ open ?B› ‹⟦open ?S; x ∈ ?S⟧ ⟹ ∃B∈ℬ. B ⊆ ?S›*) by blast moreover have "a∈𝒜" unfolding "𝒜_def" (*goal: ‹a ∈ (λN. ⋂ (from_nat_into ℬ ` N)) ` Collect finite›*) proof (rule image_eqI (*‹⟦?b = ?f ?x; ?x ∈ ?A⟧ ⟹ ?b ∈ ?f ` ?A›*)) (*goals: 1. ‹a = ⋂ (from_nat_into ℬ ` ?x)› 2. ‹?x ∈ Collect finite›*) show "a = ⋂ (from_nat_into ℬ ` {to_nat_on ℬ a})" by (simp add: ℬ (*‹countable (ℬ::'a set set)› ‹(?B::'a set) ∈ (ℬ::'a set set) ⟹ (x::'a) ∈ ?B› ‹(?B::'a set) ∈ (ℬ::'a set set) ⟹ open ?B› ‹⟦open (?S::'a set); (x::'a) ∈ ?S⟧ ⟹ ∃B::'a set∈ℬ::'a set set. B ⊆ ?S›*) a (*‹(a::'a set) ∈ (ℬ::'a set set)› ‹(a::'a set) ⊆ (S::'a set)›*)) qed (auto) (*solved the remaining goal: ‹{to_nat_on ℬ a} ∈ Collect finite›*) ultimately show "∃a∈𝒜. a ⊆ S" by blast qed qed lemma (in topological_space) first_countableI: assumes "countable 𝒜" and 1: "⋀A. A ∈ 𝒜 ⟹ x ∈ A" "⋀A. A ∈ 𝒜 ⟹ open A" and 2: "⋀S. open S ⟹ x ∈ S ⟹ ∃A∈𝒜. A ⊆ S" shows "∃𝒜::nat ⇒ 'a set. (∀i. x ∈ 𝒜 i ∧ open (𝒜 i)) ∧ (∀S. open S ∧ x ∈ S ⟶ (∃i. 𝒜 i ⊆ S))" proof (safe intro!: exI[of _ "from_nat_into 𝒜"] (*‹?P (from_nat_into 𝒜) ⟹ ∃x. ?P x›*)) (*goals: 1. ‹⋀i. x ∈ from_nat_into 𝒜 i› 2. ‹⋀i. open (from_nat_into 𝒜 i)› 3. ‹⋀S. ⟦open S; x ∈ S⟧ ⟹ ∃i. from_nat_into 𝒜 i ⊆ S›*) fix i have "𝒜 ≠ {}" using "2"[of UNIV] (*‹⟦open UNIV; x ∈ UNIV⟧ ⟹ ∃A∈𝒜. A ⊆ UNIV›*) by auto show "x ∈ from_nat_into 𝒜 i" "open (from_nat_into 𝒜 i)" using range_from_nat_into_subset[OF ‹𝒜 ≠ {}›] (*‹range (from_nat_into (𝒜::'a::type set set)) ⊆ 𝒜›*) "1" (*‹?A ∈ 𝒜 ⟹ x ∈ ?A› ‹?A ∈ 𝒜 ⟹ open ?A›*) apply - (*goals: 1. ‹⟦range (from_nat_into 𝒜) ⊆ 𝒜; ⋀A. A ∈ 𝒜 ⟹ x ∈ A; ⋀A. A ∈ 𝒜 ⟹ open A⟧ ⟹ x ∈ from_nat_into 𝒜 i› 2. ‹⟦range (from_nat_into 𝒜) ⊆ 𝒜; ⋀A. A ∈ 𝒜 ⟹ x ∈ A; ⋀A. A ∈ 𝒜 ⟹ open A⟧ ⟹ open (from_nat_into 𝒜 i)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . next (*goal: ‹⋀S::'a::type set. ⟦open S; (x::'a::type) ∈ S⟧ ⟹ ∃i::nat. from_nat_into (𝒜::'a::type set set) i ⊆ S›*) fix S assume "open S" "x∈S" (*‹open (S::'a set)› ‹(x::'a) ∈ (S::'a set)›*) then show "∃i. from_nat_into 𝒜 i ⊆ S" by (metis "2" (*‹⟦open ?S; x ∈ ?S⟧ ⟹ ∃A∈𝒜. A ⊆ ?S›*) ‹countable 𝒜› from_nat_into_surj (*‹⟦countable ?A; ?a ∈ ?A⟧ ⟹ ∃n. from_nat_into ?A n = ?a›*)) qed instance prod :: (first_countable_topology, first_countable_topology) first_countable_topology proof fix x :: "'a × 'b" obtain 𝒜 where 𝒜: "countable 𝒜" "⋀a. a ∈ 𝒜 ⟹ fst x ∈ a" "⋀a. a ∈ 𝒜 ⟹ open a" "⋀S. open S ⟹ fst x ∈ S ⟹ ∃a∈𝒜. a ⊆ S" by (rule first_countable_basisE[of "fst x"]) blast obtain B where B: "countable B" "⋀a. a ∈ B ⟹ snd x ∈ a" "⋀a. a ∈ B ⟹ open a" "⋀S. open S ⟹ snd x ∈ S ⟹ ∃a∈B. a ⊆ S" by (rule first_countable_basisE[of "snd x"]) blast show "∃𝒜::nat ⇒ ('a × 'b) set. (∀i. x ∈ 𝒜 i ∧ open (𝒜 i)) ∧ (∀S. open S ∧ x ∈ S ⟶ (∃i. 𝒜 i ⊆ S))" proof (rule first_countableI[of "(λ(a, b). a × b) ` (𝒜 × B)"], safe) fix a b assume x: "a ∈ 𝒜" "b ∈ B" show "x ∈ a × b" by (simp add: 𝒜(2) B(2) mem_Times_iff x) show "open (a × b)" by (simp add: 𝒜(3) B(3) open_Times x) next fix S assume "open S" "x ∈ S" then obtain a' b' where a'b': "open a'" "open b'" "x ∈ a' × b'" "a' × b' ⊆ S" by (rule open_prod_elim) moreover obtain a b where "a ∈ 𝒜" "a ⊆ a'" "b ∈ B" "b ⊆ b'" by (meson B(4) 𝒜(4) a'b' mem_Times_iff) ultimately show "∃a∈(λ(a, b). a × b) ` (𝒜 × B). a ⊆ S" by (auto intro!: bexI[of _ "a × b"] bexI[of _ a] bexI[of _ b]) qed (simp add: 𝒜 B) qed class second_countable_topology = topological_space + assumes ex_countable_subbasis: "∃B::'a set set. countable B ∧ open = generate_topology B" begin lemma ex_countable_basis: "∃B::'a set set. countable B ∧ topological_basis B" proof (-) (*goal: ‹∃B. countable B ∧ topological_basis B›*) from ex_countable_subbasis (*‹∃B. countable B ∧ open = generate_topology B›*) obtain B where B: "countable B" "open = generate_topology B" (*goal: ‹(⋀B. ⟦countable B; open = generate_topology B⟧ ⟹ thesis) ⟹ thesis›*) by blast let ?B = "Inter ` {b. finite b ∧ b ⊆ B }" show "?thesis" (*goal: ‹∃B::'a set set. countable B ∧ topological_basis B›*) proof (intro exI (*‹?P ?x ⟹ ∃x. ?P x›*) conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹countable ?B› 2. ‹topological_basis ?B›*) show "countable ?B" by (intro countable_image (*‹countable (?A::?'a::type set) ⟹ countable ((?f::?'a::type ⇒ ?'b::type) ` ?A)›*) countable_Collect_finite_subset (*‹countable (?T::?'a::type set) ⟹ countable {A::?'a::type set. finite A ∧ A ⊆ ?T}›*) B (*‹countable (B::'a::type set set)› ‹open = generate_topology (B::'a::type set set)›*)) { fix S assume "open S" (*‹open (S::'a set)›*) then have "∃B'⊆{b. finite b ∧ b ⊆ B}. (⋃b∈B'. ⋂b) = S" unfolding B (*goal: ‹∃B'⊆{b. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = S›*) proof (induct) (*goals: 1. ‹∃B'⊆{b::'a set set. finite b ∧ b ⊆ (B::'a set set)}. ⋃ (⋂ ` B') = UNIV› 2. ‹⋀(a::'a set) b::'a set. ⟦generate_topology (B::'a set set) a; ∃B'⊆{b::'a set set. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = a; generate_topology B b; ∃B'⊆{b::'a set set. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = b⟧ ⟹ ∃B'⊆{b::'a set set. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = a ∩ b› 3. ‹⋀K::'a set set. ⟦⋀k::'a set. k ∈ K ⟹ generate_topology (B::'a set set) k; ⋀k::'a set. k ∈ K ⟹ ∃B'⊆{b::'a set set. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = k⟧ ⟹ ∃B'⊆{b::'a set set. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = ⋃ K› 4. ‹⋀s::'a set. s ∈ (B::'a set set) ⟹ ∃B'⊆{b::'a set set. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = s›*) case UNIV (*no hyothesis introduced yet*) show "?case" (*goal: ‹∃B'⊆{b::'a set set. finite b ∧ b ⊆ (B::'a set set)}. ⋃ (⋂ ` B') = UNIV›*) apply (intro exI[of _ "{{}}"] (*‹?P {{}} ⟹ ∃x. ?P x›*)) (*goal: ‹∃B'⊆{b. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = UNIV›*) by simp next (*goals: 1. ‹⋀a b. ⟦generate_topology B a; ∃B'⊆{b. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = a; generate_topology B b; ∃B'⊆{b. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = b⟧ ⟹ ∃B'⊆{b. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = a ∩ b› 2. ‹⋀K. ⟦⋀k. k ∈ K ⟹ generate_topology B k; ⋀k. k ∈ K ⟹ ∃B'⊆{b. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = k⟧ ⟹ ∃B'⊆{b. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = ⋃ K› 3. ‹⋀s. s ∈ B ⟹ ∃B'⊆{b. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = s›*) case (Int a b) (*‹generate_topology (B::'a set set) (a::'a set)› ‹∃B'⊆{b. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = a› ‹generate_topology B b› ‹∃B'⊆{b::'a set set. finite b ∧ b ⊆ (B::'a set set)}. ⋃ (⋂ ` B') = (b::'a set)›*) then obtain x and y where x: "a = ⋃(Inter ` x)" "⋀i. i ∈ x ⟹ finite i ∧ i ⊆ B" and y: "b = ⋃(Inter ` y)" "⋀i. i ∈ y ⟹ finite i ∧ i ⊆ B" (*goal: ‹(⋀x y. ⟦a = ⋃ (⋂ ` x); ⋀i. i ∈ x ⟹ finite i ∧ i ⊆ B; b = ⋃ (⋂ ` y); ⋀i. i ∈ y ⟹ finite i ∧ i ⊆ B⟧ ⟹ thesis) ⟹ thesis›*) by blast show "?case" (*goal: ‹∃B'⊆{b. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = a ∩ b›*) unfolding x y Int_UN_distrib2 (*goal: ‹∃B'⊆{b. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = (⋃i∈x. ⋃j∈y. ⋂ i ∩ ⋂ j)›*) apply (intro exI[of _ "{i ∪ j| i j. i ∈ x ∧ j ∈ y}"] (*‹?P {i ∪ j |i j. i ∈ x ∧ j ∈ y} ⟹ ∃x. ?P x›*)) (*goal: ‹∃B'⊆{b::'a::type set set. finite b ∧ b ⊆ (B::'a::type set set)}. ⋃ (⋂ ` B') = (⋃i::'a::type set set∈x::'a::type set set set. ⋃j::'a::type set set∈y::'a::type set set set. ⋂ i ∩ ⋂ j)›*) by (auto dest: x( (*‹(?i::'a set set) ∈ (x::'a set set set) ⟹ finite ?i ∧ ?i ⊆ (B::'a set set)›*) 2) y( (*‹(?i::'a set set) ∈ (y::'a set set set) ⟹ finite ?i ∧ ?i ⊆ (B::'a set set)›*) 2)) next (*goals: 1. ‹⋀K. ⟦⋀k. k ∈ K ⟹ generate_topology B k; ⋀k. k ∈ K ⟹ ∃B'⊆{b. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = k⟧ ⟹ ∃B'⊆{b. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = ⋃ K› 2. ‹⋀s. s ∈ B ⟹ ∃B'⊆{b. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = s›*) case (UN K) (*‹?k ∈ K ⟹ generate_topology B ?k› ‹?k ∈ K ⟹ ∃B'⊆{b. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = ?k›*) then have "∀k∈K. ∃B'⊆{b. finite b ∧ b ⊆ B}. ⋃ (Inter ` B') = k" by auto then obtain k where "∀ka∈K. k ka ⊆ {b. finite b ∧ b ⊆ B} ∧ ⋃(Inter ` (k ka)) = ka" (*goal: ‹(⋀k. ∀ka∈K. k ka ⊆ {b. finite b ∧ b ⊆ B} ∧ ⋃ (⋂ ` k ka) = ka ⟹ thesis) ⟹ thesis›*) unfolding bchoice_iff (*goal: ‹(⋀k::'a set ⇒ 'a set set set. ∀ka::'a set∈K::'a set set. k ka ⊆ {b::'a set set. finite b ∧ b ⊆ (B::'a set set)} ∧ ⋃ (⋂ ` k ka) = ka ⟹ thesis::bool) ⟹ thesis›*) by standard then show "∃B'⊆{b. finite b ∧ b ⊆ B}. ⋃ (Inter ` B') = ⋃K" apply (intro exI[of _ "⋃(k ` K)"] (*‹?P (⋃ (k ` K)) ⟹ ∃x. ?P x›*)) (*goal: ‹∃B'⊆{b. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = ⋃ K›*) by auto next (*goal: ‹⋀s. s ∈ B ⟹ ∃B'⊆{b. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = s›*) case (Basis S) (*‹S ∈ B›*) then show "?case" (*goal: ‹∃B'⊆{b. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = S›*) apply (intro exI[of _ "{{S}}"] (*‹?P {{S}} ⟹ ∃x. ?P x›*)) (*goal: ‹∃B'⊆{b. finite b ∧ b ⊆ B}. ⋃ (⋂ ` B') = S›*) by auto qed then have "(∃B'⊆Inter ` {b. finite b ∧ b ⊆ B}. ⋃B' = S)" unfolding subset_image_iff (*goal: ‹∃B'. (∃AA⊆{b. finite b ∧ b ⊆ B}. B' = ⋂ ` AA) ∧ ⋃ B' = S›*) by blast } then show "topological_basis ?B" unfolding topological_basis_def (*goal: ‹Ball (⋂ ` {b. finite b ∧ b ⊆ B}) open ∧ (∀x. open x ⟶ (∃B'⊆⋂ ` {b. finite b ∧ b ⊆ B}. ⋃ B' = x))›*) apply (safe intro!: open_Inter (*‹⟦finite ?S; Ball ?S open⟧ ⟹ open (⋂ ?S)›*)) (*goals: 1. ‹⋀x xa T. ⟦⋀S. open S ⟹ ∃B'⊆⋂ ` {b. finite b ∧ b ⊆ B}. ⋃ B' = S; finite xa; xa ⊆ B; T ∈ xa⟧ ⟹ open T› 2. ‹⋀x. ⟦⋀S. open S ⟹ ∃B'⊆⋂ ` {b. finite b ∧ b ⊆ B}. ⋃ B' = S; open x⟧ ⟹ ∃B'⊆⋂ ` {b. finite b ∧ b ⊆ B}. ⋃ B' = x› discuss goal 1*) apply (simp add: B (*‹countable B› ‹open = generate_topology B›*) generate_topology.Basis (*‹?s ∈ ?S ⟹ generate_topology ?S ?s›*) subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*)) (*discuss goal 2*) apply (simp add: B (*‹countable B› ‹open = generate_topology B›*) generate_topology.Basis (*‹?s ∈ ?S ⟹ generate_topology ?S ?s›*) subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*)) (*proven 2 subgoals*) . qed qed end lemma univ_second_countable: obtains ℬ :: "'a::second_countable_topology set set" where "countable ℬ" "⋀C. C ∈ ℬ ⟹ open C" "⋀S. open S ⟹ ∃U. U ⊆ ℬ ∧ S = ⋃U" by (metis ex_countable_basis (*‹∃B. countable B ∧ topological_basis B›*) topological_basis_def (*‹topological_basis ?B = ((∀b∈?B. open b) ∧ (∀x. open x ⟶ (∃B'⊆?B. ⋃ B' = x)))›*)) proposition Lindelof: fixes ℱ :: "'a::second_countable_topology set set" assumes ℱ: "⋀S. S ∈ ℱ ⟹ open S" obtains ℱ' where "ℱ' ⊆ ℱ" "countable ℱ'" "⋃ℱ' = ⋃ℱ" proof (-) (*goal: ‹(⋀ℱ'. ⟦ℱ' ⊆ ℱ; countable ℱ'; ⋃ ℱ' = ⋃ ℱ⟧ ⟹ thesis) ⟹ thesis›*) obtain ℬ :: "'a set set" where "countable ℬ" "⋀C. C ∈ ℬ ⟹ open C" and "ℬ": "⋀S. open S ⟹ ∃U. U ⊆ ℬ ∧ S = ⋃U" (*goal: ‹(⋀ℬ::'a::second_countable_topology set set. ⟦countable ℬ; ⋀C::'a::second_countable_topology set. C ∈ ℬ ⟹ open C; ⋀S::'a::second_countable_topology set. open S ⟹ ∃U⊆ℬ. S = ⋃ U⟧ ⟹ thesis::bool) ⟹ thesis›*) using univ_second_countable (*‹(⋀ℬ. ⟦countable ℬ; ⋀C. C ∈ ℬ ⟹ open C; ⋀S. open S ⟹ ∃U⊆ℬ. S = ⋃ U⟧ ⟹ ?thesis) ⟹ ?thesis›*) by blast define 𝒟 where "𝒟 ≡ {S. S ∈ ℬ ∧ (∃U. U ∈ ℱ ∧ S ⊆ U)}" have "countable 𝒟" by (simp add: 𝒟_def (*‹𝒟::'a set set ≡ {S::'a set ∈ ℬ::'a set set. ∃U::'a set. U ∈ (ℱ::'a set set) ∧ S ⊆ U}›*) ‹countable ℬ›) have "⋀S. ∃U. S ∈ 𝒟 ⟶ U ∈ ℱ ∧ S ⊆ U" by (simp add: 𝒟_def (*‹𝒟 ≡ {S ∈ ℬ. ∃U. U ∈ ℱ ∧ S ⊆ U}›*)) then obtain G where G: "⋀S. S ∈ 𝒟 ⟶ G S ∈ ℱ ∧ S ⊆ G S" (*goal: ‹(⋀G. (⋀S. S ∈ 𝒟 ⟶ G S ∈ ℱ ∧ S ⊆ G S) ⟹ thesis) ⟹ thesis›*) by metis have "⋃ℱ ⊆ ⋃𝒟" unfolding "𝒟_def" (*goal: ‹⋃ ℱ ⊆ ⋃ {S ∈ ℬ. ∃U. U ∈ ℱ ∧ S ⊆ U}›*) by (blast dest: ℱ (*‹?S ∈ ℱ ⟹ open ?S›*) ℬ (*‹open ?S ⟹ ∃U⊆ℬ. ?S = ⋃ U›*)) moreover have "⋃𝒟 ⊆ ⋃ℱ" using "𝒟_def" (*‹𝒟 ≡ {S ∈ ℬ. ∃U. U ∈ ℱ ∧ S ⊆ U}›*) by blast ultimately have eq1: "⋃ℱ = ⋃𝒟" by standard moreover have "⋃𝒟 = ⋃ (G ` 𝒟)" using G (*‹?S ∈ 𝒟 ⟶ G ?S ∈ ℱ ∧ ?S ⊆ G ?S›*) eq1 (*‹⋃ ℱ = ⋃ 𝒟›*) by auto ultimately show "?thesis" (*goal: ‹thesis::bool›*) by (metis G (*‹?S ∈ 𝒟 ⟶ G ?S ∈ ℱ ∧ ?S ⊆ G ?S›*) ‹countable 𝒟› countable_image (*‹countable ?A ⟹ countable (?f ` ?A)›*) image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*) that (*‹⟦?ℱ' ⊆ ℱ; countable ?ℱ'; ⋃ ?ℱ' = ⋃ ℱ⟧ ⟹ thesis›*)) qed lemma countable_disjoint_open_subsets: fixes ℱ :: "'a::second_countable_topology set set" assumes "⋀S. S ∈ ℱ ⟹ open S" and pw: "pairwise disjnt ℱ" shows "countable ℱ" proof (-) (*goal: ‹countable ℱ›*) obtain ℱ' where "ℱ' ⊆ ℱ" "countable ℱ'" "⋃ℱ' = ⋃ℱ" (*goal: ‹(⋀ℱ'. ⟦ℱ' ⊆ ℱ; countable ℱ'; ⋃ ℱ' = ⋃ ℱ⟧ ⟹ thesis) ⟹ thesis›*) by (meson assms (*‹?S ∈ ℱ ⟹ open ?S› ‹disjoint ℱ›*) Lindelof (*‹⟦⋀S. S ∈ ?ℱ ⟹ open S; ⋀ℱ'. ⟦ℱ' ⊆ ?ℱ; countable ℱ'; ⋃ ℱ' = ⋃ ?ℱ⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) with pw (*‹disjoint ℱ›*) have "ℱ ⊆ insert {} ℱ'" by (fastforce simp add: pairwise_def (*‹pairwise (?R::?'a ⇒ ?'a ⇒ bool) (?S::?'a set) = (∀x::?'a∈?S. ∀y::?'a∈?S. x ≠ y ⟶ ?R x y)›*) disjnt_iff (*‹disjnt (?A::?'a set) (?B::?'a set) = (∀x::?'a. ¬ (x ∈ ?A ∧ x ∈ ?B))›*)) then show "?thesis" (*goal: ‹countable ℱ›*) by (simp add: ‹countable ℱ'› countable_subset (*‹⟦?A ⊆ ?B; countable ?B⟧ ⟹ countable ?A›*)) qed sublocale second_countable_topology < countable_basis "open" "SOME B. countable B ∧ topological_basis B" using someI_ex[OF ex_countable_basis] (*‹countable (SOME x::'a::type set set. countable x ∧ topological_basis x) ∧ topological_basis (SOME x::'a::type set set. countable x ∧ topological_basis x)›*) apply unfold_locales (*goals: 1. ‹countable (SOME x. countable x ∧ topological_basis x) ∧ topological_basis (SOME x. countable x ∧ topological_basis x) ⟹ topological_basis (SOME B. countable B ∧ topological_basis B)› 2. ‹countable (SOME x. countable x ∧ topological_basis x) ∧ topological_basis (SOME x. countable x ∧ topological_basis x) ⟹ countable (SOME B. countable B ∧ topological_basis B)› discuss goal 1*) apply ((safe)[1]) (*discuss goal 2*) apply ((safe)[1]) (*proven 2 subgoals*) . instance prod :: (second_countable_topology, second_countable_topology) second_countable_topology proof obtain A :: "'a set set" where "countable A" "topological_basis A" using ex_countable_basis by auto moreover obtain B :: "'b set set" where "countable B" "topological_basis B" using ex_countable_basis by auto ultimately show "∃B::('a × 'b) set set. countable B ∧ open = generate_topology B" by (auto intro!: exI[of _ "(λ(a, b). a × b) ` (A × B)"] topological_basis_prod topological_basis_imp_subbasis) qed instance second_countable_topology ⊆ first_countable_topology proof fix x :: 'a define B :: "'a set set" where "B = (SOME B. countable B ∧ topological_basis B)" then have B: "countable B" "topological_basis B" using countable_basis is_basis by (auto simp: countable_basis is_basis) then show "∃A::nat ⇒ 'a set. (∀i. x ∈ A i ∧ open (A i)) ∧ (∀S. open S ∧ x ∈ S ⟶ (∃i. A i ⊆ S))" by (intro first_countableI[of "{b∈B. x ∈ b}"]) (fastforce simp: topological_space_class.topological_basis_def)+ qed instance nat :: second_countable_topology proof show "∃B::nat set set. countable B ∧ open = generate_topology B" by (intro exI[of _ "range lessThan ∪ range greaterThan"]) (auto simp: open_nat_def) qed lemma countable_separating_set_linorder1: shows "∃B::('a::{linorder_topology, second_countable_topology} set). countable B ∧ (∀x y. x < y ⟶ (∃b ∈ B. x < b ∧ b ≤ y))" proof (-) (*goal: ‹∃B. countable B ∧ (∀x y. x < y ⟶ (∃b∈B. x < b ∧ b ≤ y))›*) obtain A :: "'a set set" where "countable A" "topological_basis A" (*goal: ‹(⋀A. ⟦countable A; topological_basis A⟧ ⟹ thesis) ⟹ thesis›*) using ex_countable_basis (*‹∃B. countable B ∧ topological_basis B›*) by auto define B1 where "B1 = {(LEAST x. x ∈ U)| U. U ∈ A}" then have "countable B1" using ‹countable A› (*‹countable A›*) by (simp add: Setcompr_eq_image (*‹{?f x |x. x ∈ ?A} = ?f ` ?A›*)) define B2 where "B2 = {(SOME x. x ∈ U)| U. U ∈ A}" then have "countable B2" using ‹countable A› (*‹countable A›*) by (simp add: Setcompr_eq_image (*‹{(?f::?'b ⇒ ?'a) x |x::?'b. x ∈ (?A::?'b set)} = ?f ` ?A›*)) have "∃b ∈ B1 ∪ B2. x < b ∧ b ≤ y" if "x < y" for x and y proof (cases) (*goals: 1. ‹?P ⟹ ∃b∈B1 ∪ B2. x < b ∧ b ≤ y› 2. ‹¬ ?P ⟹ ∃b∈B1 ∪ B2. x < b ∧ b ≤ y›*) assume "∃z. x < z ∧ z < y" (*‹∃z>x::'a. z < (y::'a)›*) then obtain z where z: "x < z ∧ z < y" (*goal: ‹(⋀z. x < z ∧ z < y ⟹ thesis) ⟹ thesis›*) by auto define U where "U = {x<..<y}" then have "open U" by simp moreover have "z ∈ U" using z (*‹x < z ∧ z < y›*) U_def (*‹U = {x<..<y}›*) by simp ultimately obtain V where "V ∈ A" "z ∈ V" "V ⊆ U" (*goal: ‹(⋀V::'a set. ⟦V ∈ (A::'a set set); (z::'a) ∈ V; V ⊆ (U::'a set)⟧ ⟹ thesis::bool) ⟹ thesis›*) using topological_basisE[OF ‹topological_basis A›] (*‹⟦open ?O'; ?x ∈ ?O'; ⋀B'. ⟦B' ∈ A; ?x ∈ B'; B' ⊆ ?O'⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) by auto define w where "w = (SOME x. x ∈ V)" then have "w ∈ V" using ‹z ∈ V› (*‹z ∈ V›*) by (metis someI2 (*‹⟦?P ?a; ⋀x. ?P x ⟹ ?Q x⟧ ⟹ ?Q (SOME x. ?P x)›*)) then have "x < w ∧ w ≤ y" using ‹w ∈ V› (*‹w ∈ V›*) ‹V ⊆ U› (*‹V ⊆ U›*) U_def (*‹U = {x<..<y}›*) by fastforce moreover have "w ∈ B1 ∪ B2" using w_def (*‹(w::'a) = (SOME x::'a. x ∈ (V::'a set))›*) B2_def (*‹B2 = {SOME x. x ∈ U |U. U ∈ A}›*) ‹V ∈ A› (*‹V ∈ A›*) by auto ultimately show "?thesis" (*goal: ‹∃b::'a∈(B1::'a set) ∪ (B2::'a set). (x::'a) < b ∧ b ≤ (y::'a)›*) by auto next (*goal: ‹¬ (∃z>x. z < y) ⟹ ∃b∈B1 ∪ B2. x < b ∧ b ≤ y›*) assume "¬(∃z. x < z ∧ z < y)" (*‹¬ (∃z>x::'a. z < (y::'a))›*) then have "*": "⋀z. z > x ⟹ z ≥ y" by auto define U where "U = {x<..}" then have "open U" by simp moreover have "y ∈ U" using ‹x < y› (*‹x < y›*) U_def (*‹(U::'a::{second_countable_topology,linorder_topology} set) = {x::'a::{second_countable_topology,linorder_topology}<..}›*) by simp ultimately obtain V where "V ∈ A" "y ∈ V" "V ⊆ U" (*goal: ‹(⋀V. ⟦V ∈ A; y ∈ V; V ⊆ U⟧ ⟹ thesis) ⟹ thesis›*) using topological_basisE[OF ‹topological_basis A›] (*‹⟦open ?O'; ?x ∈ ?O'; ⋀B'. ⟦B' ∈ A; ?x ∈ B'; B' ⊆ ?O'⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) by auto have "U = {y..}" unfolding U_def (*goal: ‹{x<..} = {y..}›*) using "*" (*‹x < ?z ⟹ y ≤ ?z›*) ‹x < y› (*‹x < y›*) by auto then have "V ⊆ {y..}" using ‹V ⊆ U› (*‹V ⊆ U›*) by simp then have "(LEAST w. w ∈ V) = y" using ‹y ∈ V› (*‹y ∈ V›*) by (meson Least_equality (*‹⟦?P ?x; ⋀y. ?P y ⟹ ?x ≤ y⟧ ⟹ Least ?P = ?x›*) atLeast_iff (*‹(?i ∈ {?k..}) = (?k ≤ ?i)›*) subsetCE (*‹⟦?A ⊆ ?B; ?c ∉ ?A ⟹ ?P; ?c ∈ ?B ⟹ ?P⟧ ⟹ ?P›*)) then have "y ∈ B1 ∪ B2" using ‹V ∈ A› (*‹V ∈ A›*) B1_def (*‹B1 = {LEAST x. x ∈ U |U. U ∈ A}›*) by auto moreover have "x < y ∧ y ≤ y" using ‹x < y› (*‹x < y›*) by simp ultimately show "?thesis" (*goal: ‹∃b∈B1 ∪ B2. x < b ∧ b ≤ y›*) by auto qed moreover have "countable (B1 ∪ B2)" using ‹countable B1› (*‹countable B1›*) ‹countable B2› (*‹countable (B2::'a::{second_countable_topology,linorder_topology} set)›*) by simp ultimately show "?thesis" (*goal: ‹∃B. countable B ∧ (∀x y. x < y ⟶ (∃b∈B. x < b ∧ b ≤ y))›*) by auto qed lemma countable_separating_set_linorder2: shows "∃B::('a::{linorder_topology, second_countable_topology} set). countable B ∧ (∀x y. x < y ⟶ (∃b ∈ B. x ≤ b ∧ b < y))" proof (-) (*goal: ‹∃B. countable B ∧ (∀x y. x < y ⟶ (∃b∈B. x ≤ b ∧ b < y))›*) obtain A :: "'a set set" where "countable A" "topological_basis A" (*goal: ‹(⋀A::'a::{second_countable_topology,linorder_topology} set set. ⟦countable A; topological_basis A⟧ ⟹ thesis::bool) ⟹ thesis›*) using ex_countable_basis (*‹∃B. countable B ∧ topological_basis B›*) by auto define B1 where "B1 = {(GREATEST x. x ∈ U) | U. U ∈ A}" then have "countable B1" using ‹countable A› (*‹countable A›*) by (simp add: Setcompr_eq_image (*‹{?f x |x. x ∈ ?A} = ?f ` ?A›*)) define B2 where "B2 = {(SOME x. x ∈ U)| U. U ∈ A}" then have "countable B2" using ‹countable A› (*‹countable (A::'a set set)›*) by (simp add: Setcompr_eq_image (*‹{?f x |x. x ∈ ?A} = ?f ` ?A›*)) have "∃b ∈ B1 ∪ B2. x ≤ b ∧ b < y" if "x < y" for x and y proof (cases) (*goals: 1. ‹?P ⟹ ∃b∈B1 ∪ B2. x ≤ b ∧ b < y› 2. ‹¬ ?P ⟹ ∃b∈B1 ∪ B2. x ≤ b ∧ b < y›*) assume "∃z. x < z ∧ z < y" (*‹∃z>x::'a. z < (y::'a)›*) then obtain z where z: "x < z ∧ z < y" (*goal: ‹(⋀z. x < z ∧ z < y ⟹ thesis) ⟹ thesis›*) by auto define U where "U = {x<..<y}" then have "open U" by simp moreover have "z ∈ U" using z (*‹x < z ∧ z < y›*) U_def (*‹U = {x<..<y}›*) by simp ultimately obtain V where "V ∈ A" "z ∈ V" "V ⊆ U" (*goal: ‹(⋀V. ⟦V ∈ A; z ∈ V; V ⊆ U⟧ ⟹ thesis) ⟹ thesis›*) using topological_basisE[OF ‹topological_basis A›] (*‹⟦open (?O'::'a set); (?x::'a) ∈ ?O'; ⋀B'::'a set. ⟦B' ∈ (A::'a set set); ?x ∈ B'; B' ⊆ ?O'⟧ ⟹ ?thesis::bool⟧ ⟹ ?thesis›*) by auto define w where "w = (SOME x. x ∈ V)" then have "w ∈ V" using ‹z ∈ V› (*‹z ∈ V›*) by (metis someI2 (*‹⟦?P ?a; ⋀x. ?P x ⟹ ?Q x⟧ ⟹ ?Q (SOME x. ?P x)›*)) then have "x ≤ w ∧ w < y" using ‹w ∈ V› (*‹w ∈ V›*) ‹V ⊆ U› (*‹V ⊆ U›*) U_def (*‹U = {x<..<y}›*) by fastforce moreover have "w ∈ B1 ∪ B2" using w_def (*‹(w::'a) = (SOME x::'a. x ∈ (V::'a set))›*) B2_def (*‹B2 = {SOME x. x ∈ U |U. U ∈ A}›*) ‹V ∈ A› (*‹V ∈ A›*) by auto ultimately show "?thesis" (*goal: ‹∃b∈B1 ∪ B2. x ≤ b ∧ b < y›*) by auto next (*goal: ‹¬ (∃z>x. z < y) ⟹ ∃b∈B1 ∪ B2. x ≤ b ∧ b < y›*) assume "¬(∃z. x < z ∧ z < y)" (*‹¬ (∃z>x::'a. z < (y::'a))›*) then have "*": "⋀z. z < y ⟹ z ≤ x" using leI (*‹¬ ?x < ?y ⟹ ?y ≤ ?x›*) by blast define U where "U = {..<y}" then have "open U" by simp moreover have "x ∈ U" using ‹x < y› (*‹x < y›*) U_def (*‹(U::'a set) = {..<y::'a}›*) by simp ultimately obtain V where "V ∈ A" "x ∈ V" "V ⊆ U" (*goal: ‹(⋀V. ⟦V ∈ A; x ∈ V; V ⊆ U⟧ ⟹ thesis) ⟹ thesis›*) using topological_basisE[OF ‹topological_basis A›] (*‹⟦open ?O'; ?x ∈ ?O'; ⋀B'. ⟦B' ∈ A; ?x ∈ B'; B' ⊆ ?O'⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) by auto have "U = {..x}" unfolding U_def (*goal: ‹{..<y} = {..x}›*) using "*" (*‹?z < y ⟹ ?z ≤ x›*) ‹x < y› (*‹x < y›*) by auto then have "V ⊆ {..x}" using ‹V ⊆ U› (*‹(V::'a::{second_countable_topology,linorder_topology} set) ⊆ (U::'a::{second_countable_topology,linorder_topology} set)›*) by simp then have "(GREATEST x. x ∈ V) = x" using ‹x ∈ V› (*‹(x::'a) ∈ (V::'a set)›*) by (meson Greatest_equality (*‹⟦?P ?x; ⋀y. ?P y ⟹ y ≤ ?x⟧ ⟹ Greatest ?P = ?x›*) atMost_iff (*‹(?i ∈ {..?k}) = (?i ≤ ?k)›*) subsetCE (*‹⟦?A ⊆ ?B; ?c ∉ ?A ⟹ ?P; ?c ∈ ?B ⟹ ?P⟧ ⟹ ?P›*)) then have "x ∈ B1 ∪ B2" using ‹V ∈ A› (*‹V ∈ A›*) B1_def (*‹(B1::'a::{second_countable_topology,linorder_topology} set) = {GREATEST x::'a::{second_countable_topology,linorder_topology}. x ∈ U |U::'a::{second_countable_topology,linorder_topology} set. U ∈ (A::'a::{second_countable_topology,linorder_topology} set set)}›*) by auto moreover have "x ≤ x ∧ x < y" using ‹x < y› (*‹x < y›*) by simp ultimately show "?thesis" (*goal: ‹∃b∈B1 ∪ B2. x ≤ b ∧ b < y›*) by auto qed moreover have "countable (B1 ∪ B2)" using ‹countable B1› (*‹countable B1›*) ‹countable B2› (*‹countable B2›*) by simp ultimately show "?thesis" (*goal: ‹∃B. countable B ∧ (∀x y. x < y ⟶ (∃b∈B. x ≤ b ∧ b < y))›*) by auto qed lemma countable_separating_set_dense_linorder: shows "∃B::('a::{linorder_topology, dense_linorder, second_countable_topology} set). countable B ∧ (∀x y. x < y ⟶ (∃b ∈ B. x < b ∧ b < y))" proof (-) (*goal: ‹∃B. countable B ∧ (∀x y. x < y ⟶ (∃b∈B. x < b ∧ b < y))›*) obtain B :: "'a set" where B: "countable B" "⋀x y. x < y ⟹ (∃b ∈ B. x < b ∧ b ≤ y)" (*goal: ‹(⋀B. ⟦countable B; ⋀x y. x < y ⟹ ∃b∈B. x < b ∧ b ≤ y⟧ ⟹ thesis) ⟹ thesis›*) using countable_separating_set_linorder1 (*‹∃B. countable B ∧ (∀x y. x < y ⟶ (∃b∈B. x < b ∧ b ≤ y))›*) by auto have "∃b ∈ B. x < b ∧ b < y" if "x < y" for x and y proof (-) (*goal: ‹∃b::'a∈B::'a set. (x::'a) < b ∧ b < (y::'a)›*) obtain z where "x < z" "z < y" (*goal: ‹(⋀z. ⟦x < z; z < y⟧ ⟹ thesis) ⟹ thesis›*) using ‹x < y› (*‹x < y›*) dense (*‹?x < ?y ⟹ ∃z>?x. z < ?y›*) by blast then obtain b where "b ∈ B" "x < b ∧ b ≤ z" (*goal: ‹(⋀b. ⟦b ∈ B; x < b ∧ b ≤ z⟧ ⟹ thesis) ⟹ thesis›*) using B(2) (*‹(?x::'a) < (?y::'a) ⟹ ∃b::'a∈B::'a set. ?x < b ∧ b ≤ ?y›*) by auto then have "x < b ∧ b < y" using ‹z < y› (*‹z < y›*) by auto then show "?thesis" (*goal: ‹∃b∈B. x < b ∧ b < y›*) using ‹b ∈ B› (*‹(b::'a::{second_countable_topology,dense_linorder,linorder_topology}) ∈ (B::'a::{second_countable_topology,dense_linorder,linorder_topology} set)›*) by auto qed then show "?thesis" (*goal: ‹∃B. countable B ∧ (∀x y. x < y ⟶ (∃b∈B. x < b ∧ b < y))›*) using B(1) (*‹countable B›*) by auto qed subsection ‹Polish spaces› text ‹Textbooks define Polish spaces as completely metrizable. We assume the topology to be complete for a given metric.› class polish_space = complete_space + second_countable_topology subsection ‹Limit Points› definition✐‹tag important› (in topological_space) islimpt:: "'a ⇒ 'a set ⇒ bool" (infixr "islimpt" 60) where "x islimpt S ⟷ (∀T. x∈T ⟶ open T ⟶ (∃y∈S. y∈T ∧ y≠x))" lemma islimptI: assumes "⋀T. x ∈ T ⟹ open T ⟹ ∃y∈S. y ∈ T ∧ y ≠ x" shows "x islimpt S" using assms (*‹⟦x ∈ ?T; open ?T⟧ ⟹ ∃y∈S. y ∈ ?T ∧ y ≠ x›*) unfolding islimpt_def (*goal: ‹∀T. x ∈ T ⟶ open T ⟶ (∃y∈S. y ∈ T ∧ y ≠ x)›*) by auto lemma islimptE: assumes "x islimpt S" and "x ∈ T" and "open T" obtains y where "y ∈ S" and "y ∈ T" and "y ≠ x" using assms (*‹x islimpt S› ‹x ∈ T› ‹open (T::'a set)›*) unfolding islimpt_def (*goal: ‹(⋀y. ⟦y ∈ S; y ∈ T; y ≠ x⟧ ⟹ thesis) ⟹ thesis›*) by auto lemma islimpt_iff_eventually: "x islimpt S ⟷ ¬ eventually (λy. y ∉ S) (at x)" unfolding islimpt_def eventually_at_topological (*goal: ‹(∀T. x ∈ T ⟶ open T ⟶ (∃y∈S. y ∈ T ∧ y ≠ x)) = (∄Sa. open Sa ∧ x ∈ Sa ∧ (∀xa∈Sa. xa ≠ x ⟶ xa ∈ UNIV ⟶ xa ∉ S))›*) by auto lemma islimpt_subset: "x islimpt S ⟹ S ⊆ T ⟹ x islimpt T" unfolding islimpt_def (*goal: ‹⟦∀T::'a::topological_space set. (x::'a::topological_space) ∈ T ⟶ open T ⟶ (∃y::'a::topological_space∈S::'a::topological_space set. y ∈ T ∧ y ≠ x); S ⊆ (T::'a::topological_space set)⟧ ⟹ ∀Ta::'a::topological_space set. x ∈ Ta ⟶ open Ta ⟶ (∃y::'a::topological_space∈T. y ∈ Ta ∧ y ≠ x)›*) by fast lemma islimpt_UNIV_iff: "x islimpt UNIV ⟷ ¬ open {x}" unfolding islimpt_def (*goal: ‹(∀T::'a::topological_space set. (x::'a::topological_space) ∈ T ⟶ open T ⟶ (∃y::'a::topological_space∈UNIV. y ∈ T ∧ y ≠ x)) = (¬ open {x})›*) apply safe (*goals: 1. ‹⟦∀T. x ∈ T ⟶ open T ⟶ (∃y∈UNIV. y ∈ T ∧ y ≠ x); open {x}⟧ ⟹ False› 2. ‹⋀T. ⟦¬ open {x}; x ∈ T; open T⟧ ⟹ ∃y∈UNIV. y ∈ T ∧ y ≠ x› discuss goal 1*) apply fast (*discuss goal 2*) apply (case_tac "T = {x}") (*goals: 1. ‹⋀T. ⟦¬ open {x}; x ∈ T; open T; T = {x}⟧ ⟹ ∃y∈UNIV. y ∈ T ∧ y ≠ x› 2. ‹⋀T. ⟦¬ open {x}; x ∈ T; open T; T ≠ {x}⟧ ⟹ ∃y∈UNIV. y ∈ T ∧ y ≠ x› discuss goal 1*) apply fast (*discuss goal 2*) apply fast (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma islimpt_punctured: "x islimpt S = x islimpt (S-{x})" unfolding islimpt_def (*goal: ‹(∀T. x ∈ T ⟶ open T ⟶ (∃y∈S. y ∈ T ∧ y ≠ x)) = (∀T. x ∈ T ⟶ open T ⟶ (∃y∈S - {x}. y ∈ T ∧ y ≠ x))›*) by blast text ‹A perfect space has no isolated points.› lemma islimpt_UNIV [simp, intro]: "x islimpt UNIV" for x :: "'a::perfect_space" unfolding islimpt_UNIV_iff (*goal: ‹¬ open {x}›*) by (rule not_open_singleton (*‹¬ open {?x}›*)) lemma closed_limpt: "closed S ⟷ (∀x. x islimpt S ⟶ x ∈ S)" unfolding closed_def open_subopen[of "-S"] (*goal: ‹(∀x∈- S. ∃T. open T ∧ x ∈ T ∧ T ⊆ - S) = (∀x. x islimpt S ⟶ x ∈ S)›*) by (metis Compl_iff (*‹(?c ∈ - ?A) = (?c ∉ ?A)›*) islimptE (*‹⟦?x islimpt ?S; ?x ∈ ?T; open ?T; ⋀y. ⟦y ∈ ?S; y ∈ ?T; y ≠ ?x⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) islimptI (*‹(⋀T. ⟦?x ∈ T; open T⟧ ⟹ ∃y∈?S. y ∈ T ∧ y ≠ ?x) ⟹ ?x islimpt ?S›*) open_subopen (*‹open ?S = (∀x∈?S. ∃T. open T ∧ x ∈ T ∧ T ⊆ ?S)›*) subsetI (*‹(⋀x. x ∈ ?A ⟹ x ∈ ?B) ⟹ ?A ⊆ ?B›*)) lemma islimpt_EMPTY[simp]: "¬ x islimpt {}" by (auto simp: islimpt_def (*‹(?x::?'a) islimpt (?S::?'a set) = (∀T::?'a set. ?x ∈ T ⟶ open T ⟶ (∃y::?'a∈?S. y ∈ T ∧ y ≠ ?x))›*)) lemma islimpt_Un: "x islimpt (S ∪ T) ⟷ x islimpt S ∨ x islimpt T" by (simp add: islimpt_iff_eventually (*‹?x islimpt ?S = (¬ (∀⇩F y in at ?x. y ∉ ?S))›*) eventually_conj_iff (*‹(∀⇩F x in ?F. ?P x ∧ ?Q x) = (eventually ?P ?F ∧ eventually ?Q ?F)›*)) lemma islimpt_finite_union_iff: assumes "finite A" shows "z islimpt (⋃x∈A. B x) ⟷ (∃x∈A. z islimpt B x)" using assms (*‹finite (A::'a set)›*) apply (induction rule: finite_induct (*‹⟦finite (?F::?'a set); (?P::?'a set ⇒ bool) {}; ⋀(x::?'a) F::?'a set. ⟦finite F; x ∉ F; ?P F⟧ ⟹ ?P (insert x F)⟧ ⟹ ?P ?F›*)) (*goals: 1. ‹(z::'b) islimpt ⋃ ((B::'a ⇒ 'b set) ` {}) = (∃x::'a∈{}. z islimpt B x)› 2. ‹⋀(x::'a) F::'a set. ⟦finite F; x ∉ F; (z::'b) islimpt ⋃ ((B::'a ⇒ 'b set) ` F) = (∃x::'a∈F. z islimpt B x)⟧ ⟹ z islimpt ⋃ (B ` insert x F) = (∃x::'a∈insert x F. z islimpt B x)› discuss goal 1*) apply (simp add: islimpt_Un (*‹?x islimpt ?S ∪ ?T = (?x islimpt ?S ∨ ?x islimpt ?T)›*)) (*discuss goal 2*) apply (simp add: islimpt_Un (*‹(?x::?'a) islimpt (?S::?'a set) ∪ (?T::?'a set) = (?x islimpt ?S ∨ ?x islimpt ?T)›*)) (*proven 2 subgoals*) . lemma islimpt_insert: fixes x :: "'a::t1_space" shows "x islimpt (insert a S) ⟷ x islimpt S" proof (standard) (*goals: 1. ‹x islimpt insert a S ⟹ x islimpt S› 2. ‹x islimpt S ⟹ x islimpt insert a S›*) assume "x islimpt (insert a S)" (*‹(x::'a) islimpt insert (a::'a) (S::'a set)›*) then show "x islimpt S" by (metis closed_limpt (*‹closed ?S = (∀x. x islimpt ?S ⟶ x ∈ ?S)›*) closed_singleton (*‹closed {?a}›*) empty_iff (*‹(?c ∈ {}) = False›*) insert_iff (*‹(?a ∈ insert ?b ?A) = (?a = ?b ∨ ?a ∈ ?A)›*) insert_is_Un (*‹insert ?a ?A = {?a} ∪ ?A›*) islimpt_Un (*‹?x islimpt ?S ∪ ?T = (?x islimpt ?S ∨ ?x islimpt ?T)›*) islimpt_def (*‹?x islimpt ?S = (∀T. ?x ∈ T ⟶ open T ⟶ (∃y∈?S. y ∈ T ∧ y ≠ ?x))›*)) next (*goal: ‹(x::'a) islimpt (S::'a set) ⟹ x islimpt insert (a::'a) S›*) assume "x islimpt S" (*‹(x::'a) islimpt (S::'a set)›*) then show "x islimpt (insert a S)" apply (rule islimpt_subset (*‹⟦?x islimpt ?S; ?S ⊆ ?T⟧ ⟹ ?x islimpt ?T›*)) (*goal: ‹(x::'a::t1_space) islimpt insert (a::'a::t1_space) (S::'a::t1_space set)›*) by auto qed lemma islimpt_finite: fixes x :: "'a::t1_space" shows "finite S ⟹ ¬ x islimpt S" apply (induct set: finite) (*goals: 1. ‹¬ x islimpt {}› 2. ‹⋀xa F. ⟦finite F; xa ∉ F; ¬ x islimpt F⟧ ⟹ ¬ x islimpt insert xa F› discuss goal 1*) apply (simp add: islimpt_insert (*‹?x islimpt insert ?a ?S = ?x islimpt ?S›*)) (*discuss goal 2*) apply (simp add: islimpt_insert (*‹?x islimpt insert ?a ?S = ?x islimpt ?S›*)) (*proven 2 subgoals*) . lemma islimpt_Un_finite: fixes x :: "'a::t1_space" shows "finite S ⟹ x islimpt (S ∪ T) ⟷ x islimpt T" by (simp add: islimpt_Un (*‹(?x::?'a) islimpt (?S::?'a set) ∪ (?T::?'a set) = (?x islimpt ?S ∨ ?x islimpt ?T)›*) islimpt_finite (*‹finite (?S::?'a set) ⟹ ¬ (?x::?'a) islimpt ?S›*)) lemma islimpt_eq_acc_point: fixes l :: "'a :: t1_space" shows "l islimpt S ⟷ (∀U. l∈U ⟶ open U ⟶ infinite (U ∩ S))" proof (safe intro!: islimptI (*‹(⋀T. ⟦?x ∈ T; open T⟧ ⟹ ∃y∈?S. y ∈ T ∧ y ≠ ?x) ⟹ ?x islimpt ?S›*)) (*goals: 1. ‹⋀U. ⟦l islimpt S; l ∈ U; open U; finite (U ∩ S)⟧ ⟹ False› 2. ‹⋀T. ⟦∀U. l ∈ U ⟶ open U ⟶ infinite (U ∩ S); l ∈ T; open T⟧ ⟹ ∃y∈S. y ∈ T ∧ y ≠ l›*) fix U assume "l islimpt S" "l ∈ U" "open U" "finite (U ∩ S)" (*‹(l::'a) islimpt (S::'a set)› ‹(l::'a) ∈ (U::'a set)› ‹open (U::'a set)› ‹finite ((U::'a set) ∩ (S::'a set))›*) then have "l islimpt S" "l ∈ (U - (U ∩ S - {l}))" "open (U - (U ∩ S - {l}))" apply - (*goals: 1. ‹⟦l islimpt S; l ∈ U; open U; finite (U ∩ S)⟧ ⟹ l islimpt S› 2. ‹⟦l islimpt S; l ∈ U; open U; finite (U ∩ S)⟧ ⟹ l ∈ U - (U ∩ S - {l})› 3. ‹⟦l islimpt S; l ∈ U; open U; finite (U ∩ S)⟧ ⟹ open (U - (U ∩ S - {l}))› discuss goal 1*) apply ((auto intro: finite_imp_closed (*‹finite ?S ⟹ closed ?S›*))[1]) (*discuss goal 2*) apply ((auto intro: finite_imp_closed (*‹finite ?S ⟹ closed ?S›*))[1]) (*discuss goal 3*) apply ((auto intro: finite_imp_closed (*‹finite ?S ⟹ closed ?S›*))[1]) (*proven 3 subgoals*) . then show False apply (rule islimptE (*‹⟦?x islimpt ?S; ?x ∈ ?T; open ?T; ⋀y. ⟦y ∈ ?S; y ∈ ?T; y ≠ ?x⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) (*goal: ‹False›*) by auto next (*goal: ‹⋀T. ⟦∀U. l ∈ U ⟶ open U ⟶ infinite (U ∩ S); l ∈ T; open T⟧ ⟹ ∃y∈S. y ∈ T ∧ y ≠ l›*) fix T assume "*": "∀U. l∈U ⟶ open U ⟶ infinite (U ∩ S)" "l ∈ T" "open T" (*‹∀U::'a set. (l::'a) ∈ U ⟶ open U ⟶ infinite (U ∩ (S::'a set))› ‹(l::'a) ∈ (T::'a set)› ‹open (T::'a set)›*) then have "∃x. x ∈ (T ∩ S - {l})" by (metis ex_in_conv (*‹(∃x. x ∈ ?A) = (?A ≠ {})›*) finite.emptyI (*‹finite {}›*) infinite_remove (*‹infinite ?S ⟹ infinite (?S - {?a})›*)) then show "∃y∈S. y ∈ T ∧ y ≠ l" by auto qed lemma acc_point_range_imp_convergent_subsequence: fixes l :: "'a :: first_countable_topology" assumes l: "∀U. l∈U ⟶ open U ⟶ infinite (U ∩ range f)" shows "∃r::nat⇒nat. strict_mono r ∧ (f ∘ r) ⇢ l" proof (-) (*goal: ‹∃r. strict_mono r ∧ (f ∘ r) ⇢ l›*) from countable_basis_at_decseq[of l] (*‹(⋀A. ⟦⋀i. open (A i); ⋀i. l ∈ A i; ⋀S. ⟦open S; l ∈ S⟧ ⟹ ∀⇩F i in sequentially. A i ⊆ S⟧ ⟹ ?thesis) ⟹ ?thesis›*) obtain A where A: "⋀i. open (A i)" "⋀i. l ∈ A i" "⋀S. open S ⟹ l ∈ S ⟹ eventually (λi. A i ⊆ S) sequentially" (*goal: ‹(⋀A. ⟦⋀i. open (A i); ⋀i. l ∈ A i; ⋀S. ⟦open S; l ∈ S⟧ ⟹ ∀⇩F i in sequentially. A i ⊆ S⟧ ⟹ thesis) ⟹ thesis›*) by blast define s where "s n i = (SOME j. i < j ∧ f j ∈ A (Suc n))" for n and i { fix n and i have "infinite (A (Suc n) ∩ range f - f`{.. i})" using l (*‹∀U. l ∈ U ⟶ open U ⟶ infinite (U ∩ range f)›*) A (*‹open (A ?i)› ‹l ∈ A ?i› ‹⟦open ?S; l ∈ ?S⟧ ⟹ ∀⇩F i in sequentially. A i ⊆ ?S›*) by auto then have "∃x. x ∈ A (Suc n) ∩ range f - f`{.. i}" by (metis all_not_in_conv (*‹(∀x. x ∉ ?A) = (?A = {})›*) finite.emptyI (*‹finite {}›*)) then have "∃a. i < a ∧ f a ∈ A (Suc n)" by (force simp: linorder_not_le (*‹(¬ (?x::?'a::linorder) ≤ (?y::?'a::linorder)) = (?y < ?x)›*)) then have "i < s n i" "f (s n i) ∈ A (Suc n)" unfolding s_def (*goals: 1. ‹i < (SOME j. i < j ∧ f j ∈ A (Suc n))› 2. ‹f (SOME j. i < j ∧ f j ∈ A (Suc n)) ∈ A (Suc n)›*) apply - (*goals: 1. ‹∃a>i. f a ∈ A (Suc n) ⟹ i < (SOME j. i < j ∧ f j ∈ A (Suc n))› 2. ‹∃a>i. f a ∈ A (Suc n) ⟹ f (SOME j. i < j ∧ f j ∈ A (Suc n)) ∈ A (Suc n)› discuss goal 1*) apply ((auto intro: someI2_ex (*‹⟦∃a::?'a::type. (?P::?'a::type ⇒ bool) a; ⋀x::?'a::type. ?P x ⟹ (?Q::?'a::type ⇒ bool) x⟧ ⟹ ?Q (SOME x::?'a::type. ?P x)›*))[1]) (*discuss goal 2*) apply ((auto intro: someI2_ex (*‹⟦∃a. ?P a; ⋀x. ?P x ⟹ ?Q x⟧ ⟹ ?Q (SOME x. ?P x)›*))[1]) (*proven 2 subgoals*) . } note s = this (*‹(?i2::nat) < (s::nat ⇒ nat ⇒ nat) (?n2::nat) ?i2› ‹f (s ?n2 ?i2) ∈ A (Suc ?n2)›*) define r where "r = rec_nat (s 0 0) s" have "strict_mono r" by (auto simp: r_def (*‹r = rec_nat (s 0 0) s›*) s (*‹?i2 < s ?n2 ?i2› ‹f (s ?n2 ?i2) ∈ A (Suc ?n2)›*) strict_mono_Suc_iff (*‹strict_mono ?f = (∀n. ?f n < ?f (Suc n))›*)) moreover have "(λn. f (r n)) ⇢ l" proof (rule topological_tendstoI (*‹(⋀S. ⟦open S; ?l ∈ S⟧ ⟹ ∀⇩F x in ?F. ?f x ∈ S) ⟹ (?f ⤏ ?l) ?F›*)) (*goal: ‹⋀S. ⟦open S; l ∈ S⟧ ⟹ ∀⇩F x in sequentially. f (r x) ∈ S›*) fix S assume "open S" "l ∈ S" (*‹open (S::'a set)› ‹(l::'a) ∈ (S::'a set)›*) with A(3) (*‹⟦open ?S; l ∈ ?S⟧ ⟹ ∀⇩F i in sequentially. A i ⊆ ?S›*) have "eventually (λi. A i ⊆ S) sequentially" by auto moreover { fix i assume "Suc 0 ≤ i" (*‹Suc (0::nat) ≤ (i::nat)›*) then have "f (r i) ∈ A i" apply (cases i) (*goals: 1. ‹⟦Suc 0 ≤ i; i = 0⟧ ⟹ f (r i) ∈ A i› 2. ‹⋀nat. ⟦Suc 0 ≤ i; i = Suc nat⟧ ⟹ f (r i) ∈ A i› discuss goal 1*) apply (simp add: r_def (*‹r = rec_nat (s 0 0) s›*) s (*‹?i2 < s ?n2 ?i2› ‹f (s ?n2 ?i2) ∈ A (Suc ?n2)›*)) (*discuss goal 2*) apply (simp add: r_def (*‹r = rec_nat (s 0 0) s›*) s (*‹?i2 < s ?n2 ?i2› ‹f (s ?n2 ?i2) ∈ A (Suc ?n2)›*)) (*proven 2 subgoals*) . } then have "eventually (λi. f (r i) ∈ A i) sequentially" by (auto simp: eventually_sequentially (*‹eventually (?P::nat ⇒ bool) sequentially = (∃N::nat. ∀n≥N. ?P n)›*)) ultimately show "eventually (λi. f (r i) ∈ S) sequentially" apply eventually_elim (*goal: ‹∀⇩F i in sequentially. f (r i) ∈ S›*) by auto qed ultimately show "∃r::nat⇒nat. strict_mono r ∧ (f ∘ r) ⇢ l" by (auto simp: convergent_def (*‹convergent (?X::nat ⇒ ?'a) = (∃L::?'a. ?X ⇢ L)›*) comp_def (*‹(?f::?'b ⇒ ?'c) ∘ (?g::?'a ⇒ ?'b) = (λx::?'a. ?f (?g x))›*)) qed lemma islimpt_range_imp_convergent_subsequence: fixes l :: "'a :: {t1_space, first_countable_topology}" assumes l: "l islimpt (range f)" shows "∃r::nat⇒nat. strict_mono r ∧ (f ∘ r) ⇢ l" using l (*‹(l::'a::{first_countable_topology,t1_space}) islimpt range (f::nat ⇒ 'a::{first_countable_topology,t1_space})›*) unfolding islimpt_eq_acc_point (*goal: ‹∃r. strict_mono r ∧ (f ∘ r) ⇢ l›*) by (rule acc_point_range_imp_convergent_subsequence (*‹∀U::?'a::first_countable_topology set. (?l::?'a::first_countable_topology) ∈ U ⟶ open U ⟶ infinite (U ∩ range (?f::nat ⇒ ?'a::first_countable_topology)) ⟹ ∃r::nat ⇒ nat. strict_mono r ∧ (?f ∘ r) ⇢ ?l›*)) lemma sequence_unique_limpt: fixes f :: "nat ⇒ 'a::t2_space" assumes f: "(f ⤏ l) sequentially" and "l' islimpt (range f)" shows "l' = l" proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹l' ≠ l ⟹ False›*) assume "l' ≠ l" (*‹(l'::'a) ≠ (l::'a)›*) obtain s and t where "open s" "open t" "l' ∈ s" "l ∈ t" "s ∩ t = {}" (*goal: ‹(⋀(s::'a::t2_space set) t::'a::t2_space set. ⟦open s; open t; (l'::'a::t2_space) ∈ s; (l::'a::t2_space) ∈ t; s ∩ t = {}⟧ ⟹ thesis::bool) ⟹ thesis›*) using hausdorff[OF ‹l' ≠ l›] (*‹∃U V. open U ∧ open V ∧ l' ∈ U ∧ l ∈ V ∧ U ∩ V = {}›*) by auto then obtain N where "∀n≥N. f n ∈ t" (*goal: ‹(⋀N. ∀n≥N. f n ∈ t ⟹ thesis) ⟹ thesis›*) by (meson f (*‹f ⇢ l›*) lim_explicit (*‹?f ⇢ ?f0.0 = (∀S. open S ⟶ ?f0.0 ∈ S ⟶ (∃N. ∀n≥N. ?f n ∈ S))›*)) have "UNIV = {..<N} ∪ {N..}" by auto then have "l' islimpt (f ` ({..<N} ∪ {N..}))" using assms(2) (*‹l' islimpt range f›*) by simp then have "l' islimpt (f ` {..<N} ∪ f ` {N..})" by (simp add: image_Un (*‹(?f::?'b::type ⇒ ?'a::type) ` ((?A::?'b::type set) ∪ (?B::?'b::type set)) = ?f ` ?A ∪ ?f ` ?B›*)) then have "l' islimpt (f ` {N..})" by (simp add: islimpt_Un_finite (*‹finite ?S ⟹ ?x islimpt ?S ∪ ?T = ?x islimpt ?T›*)) then obtain y where "y ∈ f ` {N..}" "y ∈ s" "y ≠ l'" (*goal: ‹(⋀y. ⟦y ∈ f ` {N..}; y ∈ s; y ≠ l'⟧ ⟹ thesis) ⟹ thesis›*) using ‹l' ∈ s› (*‹l' ∈ s›*) ‹open s› (*‹open (s::'a set)›*) by (rule islimptE (*‹⟦(?x::?'a::topological_space) islimpt (?S::?'a::topological_space set); ?x ∈ (?T::?'a::topological_space set); open ?T; ⋀y::?'a::topological_space. ⟦y ∈ ?S; y ∈ ?T; y ≠ ?x⟧ ⟹ ?thesis::bool⟧ ⟹ ?thesis›*)) then obtain n where "N ≤ n" "f n ∈ s" "f n ≠ l'" (*goal: ‹(⋀n. ⟦N ≤ n; f n ∈ s; f n ≠ l'⟧ ⟹ thesis) ⟹ thesis›*) by auto with ‹∀n≥N. f n ∈ t› (*‹∀n≥N. f n ∈ t›*) ‹s ∩ t = {}› (*‹s ∩ t = {}›*) show False by blast qed (*could prove directly from islimpt_sequential_inj, but only for metric spaces*) lemma islimpt_sequential: fixes x :: "'a::first_countable_topology" shows "x islimpt S ⟷ (∃f. (∀n::nat. f n ∈ S - {x}) ∧ (f ⤏ x) sequentially)" (is "?lhs = ?rhs") proof (standard) (*goals: 1. ‹x islimpt S ⟹ ∃f. (∀n. f n ∈ S - {x}) ∧ f ⇢ x› 2. ‹∃f. (∀n. f n ∈ S - {x}) ∧ f ⇢ x ⟹ x islimpt S›*) assume "?lhs" (*‹(x::'a) islimpt (S::'a set)›*) from countable_basis_at_decseq[of x] (*‹(⋀A::nat ⇒ 'a set. ⟦⋀i::nat. open (A i); ⋀i::nat. (x::'a) ∈ A i; ⋀S::'a set. ⟦open S; x ∈ S⟧ ⟹ ∀⇩F i::nat in sequentially. A i ⊆ S⟧ ⟹ ?thesis::bool) ⟹ ?thesis›*) obtain A where A: "⋀i. open (A i)" "⋀i. x ∈ A i" "⋀S. open S ⟹ x ∈ S ⟹ eventually (λi. A i ⊆ S) sequentially" (*goal: ‹(⋀A::nat ⇒ 'a::first_countable_topology set. ⟦⋀i::nat. open (A i); ⋀i::nat. (x::'a::first_countable_topology) ∈ A i; ⋀S::'a::first_countable_topology set. ⟦open S; x ∈ S⟧ ⟹ ∀⇩F i::nat in sequentially. A i ⊆ S⟧ ⟹ thesis::bool) ⟹ thesis›*) by blast define f where "f n = (SOME y. y ∈ S ∧ y ∈ A n ∧ x ≠ y)" for n { fix n from ‹?lhs› (*‹(x::'a) islimpt (S::'a set)›*) have "∃y. y ∈ S ∧ y ∈ A n ∧ x ≠ y" unfolding islimpt_def (*goal: ‹∃y::'a. y ∈ (S::'a set) ∧ y ∈ (A::nat ⇒ 'a set) (n::nat) ∧ (x::'a) ≠ y›*) using A(1,2)[of n] (*‹open (A n)› ‹x ∈ A n›*) by auto then have "f n ∈ S ∧ f n ∈ A n ∧ x ≠ f n" unfolding f_def (*goal: ‹(SOME y. y ∈ S ∧ y ∈ A n ∧ x ≠ y) ∈ S ∧ (SOME y. y ∈ S ∧ y ∈ A n ∧ x ≠ y) ∈ A n ∧ x ≠ (SOME y. y ∈ S ∧ y ∈ A n ∧ x ≠ y)›*) by (rule someI_ex (*‹∃x. ?P x ⟹ ?P (SOME x. ?P x)›*)) then have "f n ∈ S" "f n ∈ A n" "x ≠ f n" apply - (*goals: 1. ‹f n ∈ S ∧ f n ∈ A n ∧ x ≠ f n ⟹ f n ∈ S› 2. ‹f n ∈ S ∧ f n ∈ A n ∧ x ≠ f n ⟹ f n ∈ A n› 3. ‹f n ∈ S ∧ f n ∈ A n ∧ x ≠ f n ⟹ x ≠ f n› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . } then have "∀n. f n ∈ S - {x}" by auto moreover have "(λn. f n) ⇢ x" proof (rule topological_tendstoI (*‹(⋀S. ⟦open S; ?l ∈ S⟧ ⟹ ∀⇩F x in ?F. ?f x ∈ S) ⟹ (?f ⤏ ?l) ?F›*)) (*goal: ‹⋀S. ⟦open S; x ∈ S⟧ ⟹ ∀⇩F x in sequentially. f x ∈ S›*) fix S assume "open S" "x ∈ S" (*‹open (S::'a set)› ‹(x::'a) ∈ (S::'a set)›*) from A(3)[OF this] (*‹∀⇩F i in sequentially. A i ⊆ S›*) ‹⋀n. f n ∈ A n› (*‹f ?n ∈ A ?n›*) show "eventually (λx. f x ∈ S) sequentially" by (auto elim!: eventually_mono (*‹⟦eventually (?P::?'a ⇒ bool) (?F::?'a filter); ⋀x::?'a. ?P x ⟹ (?Q::?'a ⇒ bool) x⟧ ⟹ eventually ?Q ?F›*)) qed ultimately show "?rhs" by fast next (*goal: ‹∃f. (∀n. f n ∈ S - {x}) ∧ f ⇢ x ⟹ x islimpt S›*) assume "?rhs" (*‹∃f::nat ⇒ 'a. (∀n::nat. f n ∈ (S::'a set) - {x::'a}) ∧ f ⇢ x›*) then obtain f :: "nat ⇒ 'a" where f: "⋀n. f n ∈ S - {x}" and lim: "f ⇢ x" (*goal: ‹(⋀f. ⟦⋀n. f n ∈ S - {x}; f ⇢ x⟧ ⟹ thesis) ⟹ thesis›*) by auto show "?lhs" unfolding islimpt_def (*goal: ‹∀T. x ∈ T ⟶ open T ⟶ (∃y∈S. y ∈ T ∧ y ≠ x)›*) proof (safe) (*goal: ‹⋀T::'a::first_countable_topology set. ⟦(x::'a::first_countable_topology) ∈ T; open T⟧ ⟹ ∃y::'a::first_countable_topology∈S::'a::first_countable_topology set. y ∈ T ∧ y ≠ x›*) fix T assume "open T" "x ∈ T" (*‹open (T::'a set)› ‹(x::'a) ∈ (T::'a set)›*) from lim[THEN topological_tendstoD, OF this] (*‹∀⇩F x in sequentially. f x ∈ T›*) f (*‹f ?n ∈ S - {x}›*) show "∃y∈S. y ∈ T ∧ y ≠ x" unfolding eventually_sequentially (*goal: ‹∃y∈S. y ∈ T ∧ y ≠ x›*) by auto qed qed lemma islimpt_isCont_image: fixes f :: "'a :: {first_countable_topology, t2_space} ⇒ 'b :: {first_countable_topology, t2_space}" assumes "x islimpt A" and "isCont f x" and ev: "eventually (λy. f y ≠ f x) (at x)" shows "f x islimpt f ` A" proof (-) (*goal: ‹(f::'a::{first_countable_topology,t2_space} ⇒ 'b::{first_countable_topology,t2_space}) (x::'a::{first_countable_topology,t2_space}) islimpt f ` (A::'a::{first_countable_topology,t2_space} set)›*) from assms(1) (*‹x islimpt A›*) obtain g where g: "g ⇢ x" "range g ⊆ A - {x}" (*goal: ‹(⋀g. ⟦g ⇢ x; range g ⊆ A - {x}⟧ ⟹ thesis) ⟹ thesis›*) unfolding islimpt_sequential (*goal: ‹(⋀g. ⟦g ⇢ x; range g ⊆ A - {x}⟧ ⟹ thesis) ⟹ thesis›*) by blast have "filterlim g (at x) sequentially" using g (*‹g ⇢ x› ‹range g ⊆ A - {x}›*) by (auto simp: filterlim_at (*‹filterlim ?f (at ?b within ?s) ?F = ((∀⇩F x in ?F. ?f x ∈ ?s ∧ ?f x ≠ ?b) ∧ (?f ⤏ ?b) ?F)›*) intro!: always_eventually (*‹∀x. ?P x ⟹ eventually ?P ?F›*)) then obtain N where N: "⋀n. n ≥ N ⟹ f (g n) ≠ f x" (*goal: ‹(⋀N. (⋀n. N ≤ n ⟹ f (g n) ≠ f x) ⟹ thesis) ⟹ thesis›*) by (metis (mono_tags, lifting) ev (*‹∀⇩F y::'a in at x. (f::'a ⇒ 'b) y ≠ f (x::'a)›*) eventually_at_top_linorder (*‹eventually (?P::?'a ⇒ bool) at_top = (∃N::?'a. ∀n≥N. ?P n)›*) filterlim_iff (*‹filterlim (?f::?'a ⇒ ?'b) (?F2.0::?'b filter) (?F1.0::?'a filter) = (∀P::?'b ⇒ bool. eventually P ?F2.0 ⟶ (∀⇩F x::?'a in ?F1.0. P (?f x)))›*)) have "(λx. g (x + N)) ⇢ x" using g(1) (*‹g ⇢ x›*) by (rule LIMSEQ_ignore_initial_segment (*‹?f ⇢ ?a ⟹ (λn. ?f (n + ?k)) ⇢ ?a›*)) hence "(λx. f (g (x + N))) ⇢ f x" using assms(2) (*‹isCont f x›*) isCont_tendsto_compose (*‹⟦isCont ?g ?l; (?f ⤏ ?l) ?F⟧ ⟹ ((λx. ?g (?f x)) ⤏ ?g ?l) ?F›*) by blast moreover have "range (λx. f (g (x + N))) ⊆ f ` A - {f x}" using g(2) (*‹range g ⊆ A - {x}›*) N (*‹(N::nat) ≤ (?n::nat) ⟹ (f::'a ⇒ 'b) ((g::nat ⇒ 'a) ?n) ≠ f (x::'a)›*) by auto ultimately show "?thesis" (*goal: ‹f x islimpt f ` A›*) unfolding islimpt_sequential (*goal: ‹∃fa. (∀n. fa n ∈ f ` A - {f x}) ∧ fa ⇢ f x›*) apply (intro exI[of _ "λx. f (g (x + N))"] (*‹(?P::(nat ⇒ 'b) ⇒ bool) (λx::nat. (f::'a ⇒ 'b) ((g::nat ⇒ 'a) (x + (N::nat)))) ⟹ ∃x::nat ⇒ 'b. ?P x›*)) (*goal: ‹∃fa::nat ⇒ 'b::{first_countable_topology,t2_space}. (∀n::nat. fa n ∈ (f::'a::{first_countable_topology,t2_space} ⇒ 'b::{first_countable_topology,t2_space}) ` (A::'a::{first_countable_topology,t2_space} set) - {f (x::'a::{first_countable_topology,t2_space})}) ∧ fa ⇢ f x›*) by auto qed lemma islimpt_image: assumes "z islimpt g -` A ∩ B" "g z ∉ A" "z ∈ B" "continuous_on B g" shows "g z islimpt A" by (smt (verit, best) IntD1 (*‹?c ∈ ?A ∩ ?B ⟹ ?c ∈ ?A›*) assms (*‹z islimpt g -` A ∩ B› ‹g z ∉ A› ‹z ∈ B› ‹continuous_on B g›*) continuous_on_topological (*‹continuous_on ?s ?f = (∀x∈?s. ∀B. open B ⟶ ?f x ∈ B ⟶ (∃A. open A ∧ x ∈ A ∧ (∀y∈?s. y ∈ A ⟶ ?f y ∈ B)))›*) inf_le2 (*‹inf ?x ?y ≤ ?y›*) islimpt_def (*‹?x islimpt ?S = (∀T. ?x ∈ T ⟶ open T ⟶ (∃y∈?S. y ∈ T ∧ y ≠ ?x))›*) subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*) vimageE (*‹⟦?a ∈ ?f -` ?B; ⋀x. ⟦?f ?a = x; x ∈ ?B⟧ ⟹ ?P⟧ ⟹ ?P›*)) subsection ‹Interior of a Set› definition✐‹tag important› interior :: "('a::topological_space) set ⇒ 'a set" where "interior S = ⋃{T. open T ∧ T ⊆ S}" lemma interiorI [intro?]: assumes "open T" and "x ∈ T" and "T ⊆ S" shows "x ∈ interior S" using assms (*‹open T› ‹(x::'a::topological_space) ∈ (T::'a::topological_space set)› ‹T ⊆ S›*) unfolding interior_def (*goal: ‹x ∈ ⋃ {T. open T ∧ T ⊆ S}›*) by fast lemma interiorE [elim?]: assumes "x ∈ interior S" obtains T where "open T" and "x ∈ T" and "T ⊆ S" using assms (*‹x ∈ interior S›*) unfolding interior_def (*goal: ‹(⋀T::'a set. ⟦open T; (x::'a) ∈ T; T ⊆ (S::'a set)⟧ ⟹ thesis::bool) ⟹ thesis›*) by fast lemma open_interior [simp, intro]: "open (interior S)" by (simp add: interior_def (*‹interior ?S = ⋃ {T. open T ∧ T ⊆ ?S}›*) open_Union (*‹∀S∈?K. open S ⟹ open (⋃ ?K)›*)) lemma interior_subset: "interior S ⊆ S" by (auto simp: interior_def (*‹interior ?S = ⋃ {T. open T ∧ T ⊆ ?S}›*)) lemma interior_maximal: "T ⊆ S ⟹ open T ⟹ T ⊆ interior S" by (auto simp: interior_def (*‹interior ?S = ⋃ {T. open T ∧ T ⊆ ?S}›*)) lemma interior_open: "open S ⟹ interior S = S" by (intro equalityI (*‹⟦?A ⊆ ?B; ?B ⊆ ?A⟧ ⟹ ?A = ?B›*) interior_subset (*‹interior ?S ⊆ ?S›*) interior_maximal (*‹⟦?T ⊆ ?S; open ?T⟧ ⟹ ?T ⊆ interior ?S›*) subset_refl (*‹?A ⊆ ?A›*)) lemma interior_eq: "interior S = S ⟷ open S" by (metis open_interior (*‹open (interior ?S)›*) interior_open (*‹open ?S ⟹ interior ?S = ?S›*)) lemma open_subset_interior: "open S ⟹ S ⊆ interior T ⟷ S ⊆ T" by (metis interior_maximal (*‹⟦?T ⊆ ?S; open ?T⟧ ⟹ ?T ⊆ interior ?S›*) interior_subset (*‹interior ?S ⊆ ?S›*) subset_trans (*‹⟦?A ⊆ ?B; ?B ⊆ ?C⟧ ⟹ ?A ⊆ ?C›*)) lemma interior_empty [simp]: "interior {} = {}" using open_empty (*‹open {}›*) by (rule interior_open (*‹open ?S ⟹ interior ?S = ?S›*)) lemma interior_UNIV [simp]: "interior UNIV = UNIV" using open_UNIV (*‹open UNIV›*) by (rule interior_open (*‹open (?S::?'a set) ⟹ interior ?S = ?S›*)) lemma interior_interior [simp]: "interior (interior S) = interior S" using open_interior (*‹open (interior ?S)›*) by (rule interior_open (*‹open ?S ⟹ interior ?S = ?S›*)) lemma interior_mono: "S ⊆ T ⟹ interior S ⊆ interior T" by (auto simp: interior_def (*‹interior ?S = ⋃ {T. open T ∧ T ⊆ ?S}›*)) lemma interior_unique: assumes "T ⊆ S" and "open T" assumes "⋀T'. T' ⊆ S ⟹ open T' ⟹ T' ⊆ T" shows "interior S = T" by (intro equalityI (*‹⟦?A ⊆ ?B; ?B ⊆ ?A⟧ ⟹ ?A = ?B›*) assms (*‹T ⊆ S› ‹open T› ‹⟦?T' ⊆ S; open ?T'⟧ ⟹ ?T' ⊆ T›*) interior_subset (*‹interior ?S ⊆ ?S›*) open_interior (*‹open (interior ?S)›*) interior_maximal (*‹⟦?T ⊆ ?S; open ?T⟧ ⟹ ?T ⊆ interior ?S›*)) lemma interior_singleton [simp]: "interior {a} = {}" for a :: "'a::perfect_space" by (meson interior_eq (*‹(interior ?S = ?S) = open ?S›*) interior_subset (*‹interior ?S ⊆ ?S›*) not_open_singleton (*‹¬ open {?x}›*) subset_singletonD (*‹?A ⊆ {?x} ⟹ ?A = {} ∨ ?A = {?x}›*)) lemma interior_Int [simp]: "interior (S ∩ T) = interior S ∩ interior T" by (meson Int_mono (*‹⟦?A ⊆ ?C; ?B ⊆ ?D⟧ ⟹ ?A ∩ ?B ⊆ ?C ∩ ?D›*) Int_subset_iff (*‹(?C ⊆ ?A ∩ ?B) = (?C ⊆ ?A ∧ ?C ⊆ ?B)›*) antisym_conv (*‹?y ≤ ?x ⟹ (?x ≤ ?y) = (?x = ?y)›*) interior_maximal (*‹⟦?T ⊆ ?S; open ?T⟧ ⟹ ?T ⊆ interior ?S›*) interior_subset (*‹interior ?S ⊆ ?S›*) open_Int (*‹⟦open ?S; open ?T⟧ ⟹ open (?S ∩ ?T)›*) open_interior (*‹open (interior ?S)›*)) lemma eventually_nhds_in_nhd: "x ∈ interior s ⟹ eventually (λy. y ∈ s) (nhds x)" using interior_subset[of s] (*‹interior s ⊆ s›*) apply (subst eventually_nhds (*‹eventually (?P::?'a::topological_space ⇒ bool) (nhds (?a::?'a::topological_space)) = (∃S::?'a::topological_space set. open S ∧ ?a ∈ S ∧ (∀x::?'a::topological_space∈S. ?P x))›*)) (*goal: ‹x ∈ interior s ⟹ ∀⇩F y in nhds x. y ∈ s›*) by blast lemma interior_limit_point [intro]: fixes x :: "'a::perfect_space" assumes x: "x ∈ interior S" shows "x islimpt S" proof (-) (*goal: ‹x islimpt S›*) obtain T where "x ∈ T" "T ⊆ S" "open T" (*goal: ‹(⋀T. ⟦x ∈ T; T ⊆ S; open T⟧ ⟹ thesis) ⟹ thesis›*) using interior_subset (*‹interior ?S ⊆ ?S›*) x (*‹x ∈ interior S›*) by blast with x (*‹x ∈ interior S›*) islimpt_UNIV[of x] (*‹x islimpt UNIV›*) show "?thesis" (*goal: ‹x islimpt S›*) unfolding islimpt_def (*goal: ‹∀T. x ∈ T ⟶ open T ⟶ (∃y∈S. y ∈ T ∧ y ≠ x)›*) by (metis (full_types) Int_iff (*‹(?c ∈ ?A ∩ ?B) = (?c ∈ ?A ∧ ?c ∈ ?B)›*) open_Int (*‹⟦open ?S; open ?T⟧ ⟹ open (?S ∩ ?T)›*) subsetD (*‹⟦?A ⊆ ?B; ?c ∈ ?A⟧ ⟹ ?c ∈ ?B›*)) qed lemma open_imp_islimpt: fixes x::"'a:: perfect_space" assumes "open S" "x∈S" shows "x islimpt S" using assms (*‹open (S::'a set)› ‹x ∈ S›*) interior_eq (*‹(interior (?S::?'a::topological_space set) = ?S) = open ?S›*) interior_limit_point (*‹?x ∈ interior ?S ⟹ ?x islimpt ?S›*) by auto lemma islimpt_Int_eventually: assumes "x islimpt A" "eventually (λy. y ∈ B) (at x)" shows "x islimpt A ∩ B" using assms (*‹x islimpt A› ‹∀⇩F y in at x. y ∈ B›*) unfolding islimpt_def eventually_at_filter eventually_nhds (*goal: ‹∀T. x ∈ T ⟶ open T ⟶ (∃y∈A ∩ B. y ∈ T ∧ y ≠ x)›*) by (metis Int_iff (*‹(?c ∈ ?A ∩ ?B) = (?c ∈ ?A ∧ ?c ∈ ?B)›*) UNIV_I (*‹?x ∈ UNIV›*) open_Int (*‹⟦open ?S; open ?T⟧ ⟹ open (?S ∩ ?T)›*)) lemma islimpt_conv_frequently_at: "x islimpt A ⟷ frequently (λy. y ∈ A) (at x)" by (simp add: frequently_def (*‹frequently ?P ?F = (¬ (∀⇩F x in ?F. ¬ ?P x))›*) islimpt_iff_eventually (*‹?x islimpt ?S = (¬ (∀⇩F y in at ?x. y ∉ ?S))›*)) lemma frequently_at_imp_islimpt: assumes "frequently (λy. y ∈ A) (at x)" shows "x islimpt A" by (simp add: assms (*‹∃⇩F y::'a in at (x::'a). y ∈ (A::'a set)›*) islimpt_conv_frequently_at (*‹(?x::?'a) islimpt (?A::?'a set) = (∃⇩F y::?'a in at ?x. y ∈ ?A)›*)) lemma interior_closed_Un_empty_interior: assumes cS: "closed S" and iT: "interior T = {}" shows "interior (S ∪ T) = interior S" proof (standard) (*goals: 1. ‹interior (S ∪ T) ⊆ interior S› 2. ‹interior S ⊆ interior (S ∪ T)›*) show "interior S ⊆ interior (S ∪ T)" apply (rule interior_mono (*‹?S ⊆ ?T ⟹ interior ?S ⊆ interior ?T›*)) (*goal: ‹interior S ⊆ interior (S ∪ T)›*) by (rule Un_upper1 (*‹(?A::?'a::type set) ⊆ ?A ∪ (?B::?'a::type set)›*)) show "interior (S ∪ T) ⊆ interior S" proof (standard) (*goal: ‹⋀x::'a. x ∈ interior ((S::'a set) ∪ (T::'a set)) ⟹ x ∈ interior S›*) fix x assume "x ∈ interior (S ∪ T)" (*‹(x::'a) ∈ interior ((S::'a set) ∪ (T::'a set))›*) then obtain R where "open R" "x ∈ R" "R ⊆ S ∪ T" (*goal: ‹(⋀R. ⟦open R; x ∈ R; R ⊆ S ∪ T⟧ ⟹ thesis) ⟹ thesis›*) by standard show "x ∈ interior S" proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹x ∉ interior S ⟹ False›*) assume "x ∉ interior S" (*‹(x::'a) ∉ interior (S::'a set)›*) with ‹x ∈ R› (*‹(x::'a::topological_space) ∈ (R::'a::topological_space set)›*) ‹open R› (*‹open R›*) obtain y where "y ∈ R - S" (*goal: ‹(⋀y. y ∈ R - S ⟹ thesis) ⟹ thesis›*) unfolding interior_def (*goal: ‹(⋀y. y ∈ R - S ⟹ thesis) ⟹ thesis›*) by fast then show False by (metis Diff_subset_conv (*‹((?A::?'a::type set) - (?B::?'a::type set) ⊆ (?C::?'a::type set)) = (?A ⊆ ?B ∪ ?C)›*) ‹R ⊆ S ∪ T› ‹open R› cS (*‹closed (S::'a::topological_space set)›*) empty_iff (*‹((?c::?'a::type) ∈ {}) = False›*) iT (*‹interior (T::'a::topological_space set) = {}›*) interiorI (*‹⟦open (?T::?'a::topological_space set); (?x::?'a::topological_space) ∈ ?T; ?T ⊆ (?S::?'a::topological_space set)⟧ ⟹ ?x ∈ interior ?S›*) open_Diff (*‹⟦open (?S::?'a::topological_space set); closed (?T::?'a::topological_space set)⟧ ⟹ open (?S - ?T)›*)) qed qed qed lemma interior_Times: "interior (A × B) = interior A × interior B" proof (rule interior_unique (*‹⟦(?T::?'a set) ⊆ (?S::?'a set); open ?T; ⋀T'::?'a set. ⟦T' ⊆ ?S; open T'⟧ ⟹ T' ⊆ ?T⟧ ⟹ interior ?S = ?T›*)) (*goals: 1. ‹interior A × interior B ⊆ A × B› 2. ‹open (interior A × interior B)› 3. ‹⋀T'. ⟦T' ⊆ A × B; open T'⟧ ⟹ T' ⊆ interior A × interior B›*) show "interior A × interior B ⊆ A × B" by (intro Sigma_mono (*‹⟦?A ⊆ ?C; ⋀x. x ∈ ?A ⟹ ?B x ⊆ ?D x⟧ ⟹ Sigma ?A ?B ⊆ Sigma ?C ?D›*) interior_subset (*‹interior ?S ⊆ ?S›*)) show "open (interior A × interior B)" by (intro open_Times (*‹⟦open (?S::?'a set); open (?T::?'b set)⟧ ⟹ open (?S × ?T)›*) open_interior (*‹open (interior (?S::?'a set))›*)) fix T assume "T ⊆ A × B" and "open T" (*‹(T::('a × 'b) set) ⊆ (A::'a set) × (B::'b set)› ‹open (T::('a × 'b) set)›*) then show "T ⊆ interior A × interior B" proof (safe) (*goals: 1. ‹⋀a b. ⟦T ⊆ A × B; open T; (a, b) ∈ T⟧ ⟹ a ∈ interior A› 2. ‹⋀a b. ⟦T ⊆ A × B; open T; (a, b) ∈ T⟧ ⟹ b ∈ interior B›*) fix x and y assume "(x, y) ∈ T" (*‹(x::'a, y::'b) ∈ (T::('a × 'b) set)›*) then obtain C and D where "open C" "open D" "C × D ⊆ T" "x ∈ C" "y ∈ D" (*goal: ‹(⋀C D. ⟦open C; open D; C × D ⊆ T; x ∈ C; y ∈ D⟧ ⟹ thesis) ⟹ thesis›*) using ‹open T› (*‹open T›*) unfolding open_prod_def (*goal: ‹(⋀C D. ⟦open C; open D; C × D ⊆ T; x ∈ C; y ∈ D⟧ ⟹ thesis) ⟹ thesis›*) by fast then have "open C" "open D" "C ⊆ A" "D ⊆ B" "x ∈ C" "y ∈ D" using ‹T ⊆ A × B› (*‹T ⊆ A × B›*) apply - (*goals: 1. ‹⟦open C; open D; C × D ⊆ T; x ∈ C; y ∈ D; T ⊆ A × B⟧ ⟹ open C› 2. ‹⟦open C; open D; C × D ⊆ T; x ∈ C; y ∈ D; T ⊆ A × B⟧ ⟹ open D› 3. ‹⟦open C; open D; C × D ⊆ T; x ∈ C; y ∈ D; T ⊆ A × B⟧ ⟹ C ⊆ A› 4. ‹⟦open C; open D; C × D ⊆ T; x ∈ C; y ∈ D; T ⊆ A × B⟧ ⟹ D ⊆ B› 5. ‹⟦open C; open D; C × D ⊆ T; x ∈ C; y ∈ D; T ⊆ A × B⟧ ⟹ x ∈ C› 6. ‹⟦open C; open D; C × D ⊆ T; x ∈ C; y ∈ D; T ⊆ A × B⟧ ⟹ y ∈ D› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*proven 6 subgoals*) . then show "x ∈ interior A" and "y ∈ interior B" apply - (*goals: 1. ‹⟦open C; open D; C ⊆ A; D ⊆ B; x ∈ C; y ∈ D⟧ ⟹ x ∈ interior A› 2. ‹⟦open C; open D; C ⊆ A; D ⊆ B; x ∈ C; y ∈ D⟧ ⟹ y ∈ interior B› discuss goal 1*) apply ((auto intro: interiorI (*‹⟦open ?T; ?x ∈ ?T; ?T ⊆ ?S⟧ ⟹ ?x ∈ interior ?S›*))[1]) (*discuss goal 2*) apply ((auto intro: interiorI (*‹⟦open ?T; ?x ∈ ?T; ?T ⊆ ?S⟧ ⟹ ?x ∈ interior ?S›*))[1]) (*proven 2 subgoals*) . qed qed lemma interior_Ici: fixes x :: "'a :: {dense_linorder,linorder_topology}" assumes "b < x" shows "interior {x ..} = {x <..}" proof (rule interior_unique (*‹⟦(?T::?'a::topological_space set) ⊆ (?S::?'a::topological_space set); open ?T; ⋀T'::?'a::topological_space set. ⟦T' ⊆ ?S; open T'⟧ ⟹ T' ⊆ ?T⟧ ⟹ interior ?S = ?T›*)) (*goals: 1. ‹{x<..} ⊆ {x..}› 2. ‹open {x<..}› 3. ‹⋀T'. ⟦T' ⊆ {x..}; open T'⟧ ⟹ T' ⊆ {x<..}›*) fix T assume "T ⊆ {x ..}" "open T" (*‹(T::'a set) ⊆ {x::'a..}› ‹open (T::'a set)›*) moreover have "x ∉ T" proof (standard) (*goal: ‹x ∈ T ⟹ False›*) assume "x ∈ T" (*‹(x::'a) ∈ (T::'a set)›*) obtain y where "y < x" "{y <.. x} ⊆ T" (*goal: ‹(⋀y. ⟦y < x; {y<..x} ⊆ T⟧ ⟹ thesis) ⟹ thesis›*) using open_left[OF ‹open T› ‹x ∈ T› ‹b < x›] (*‹∃b<x. {b<..x} ⊆ T›*) by auto with dense[OF ‹y < x›] (*‹∃z>y::'a. z < (x::'a)›*) obtain z where "z ∈ T" "z < x" (*goal: ‹(⋀z::'a::{dense_linorder,linorder_topology}. ⟦z ∈ (T::'a::{dense_linorder,linorder_topology} set); z < (x::'a::{dense_linorder,linorder_topology})⟧ ⟹ thesis::bool) ⟹ thesis›*) by (auto simp: subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*) Ball_def (*‹Ball ?A ?P = (∀x. x ∈ ?A ⟶ ?P x)›*)) with ‹T ⊆ {x ..}› (*‹(T::'a::{dense_linorder,linorder_topology} set) ⊆ {x::'a::{dense_linorder,linorder_topology}..}›*) show False by auto qed ultimately show "T ⊆ {x <..}" by (auto simp: subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*) less_le (*‹(?x < ?y) = (?x ≤ ?y ∧ ?x ≠ ?y)›*)) qed (auto) (*solves the remaining goals: 1. ‹{x<..} ⊆ {x..}› 2. ‹open {x<..}›*) lemma interior_Iic: fixes x :: "'a ::{dense_linorder,linorder_topology}" assumes "x < b" shows "interior {.. x} = {..< x}" proof (rule interior_unique (*‹⟦?T ⊆ ?S; open ?T; ⋀T'. ⟦T' ⊆ ?S; open T'⟧ ⟹ T' ⊆ ?T⟧ ⟹ interior ?S = ?T›*)) (*goals: 1. ‹{..<x} ⊆ {..x}› 2. ‹open {..<x}› 3. ‹⋀T'. ⟦T' ⊆ {..x}; open T'⟧ ⟹ T' ⊆ {..<x}›*) fix T assume "T ⊆ {.. x}" "open T" (*‹(T::'a set) ⊆ {..x::'a}› ‹open (T::'a set)›*) moreover have "x ∉ T" proof (standard) (*goal: ‹x ∈ T ⟹ False›*) assume "x ∈ T" (*‹(x::'a) ∈ (T::'a set)›*) obtain y where "x < y" "{x ..< y} ⊆ T" (*goal: ‹(⋀y::'a::{dense_linorder,linorder_topology}. ⟦(x::'a::{dense_linorder,linorder_topology}) < y; {x..<y} ⊆ (T::'a::{dense_linorder,linorder_topology} set)⟧ ⟹ thesis::bool) ⟹ thesis›*) using open_right[OF ‹open T› ‹x ∈ T› ‹x < b›] (*‹∃b>x. {x..<b} ⊆ T›*) by auto with dense[OF ‹x < y›] (*‹∃z>x. z < y›*) obtain z where "z ∈ T" "x < z" (*goal: ‹(⋀z. ⟦z ∈ T; x < z⟧ ⟹ thesis) ⟹ thesis›*) by (auto simp: subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*) Ball_def (*‹Ball ?A ?P = (∀x. x ∈ ?A ⟶ ?P x)›*) less_le (*‹(?x < ?y) = (?x ≤ ?y ∧ ?x ≠ ?y)›*)) with ‹T ⊆ {.. x}› (*‹T ⊆ {..x}›*) show False by auto qed ultimately show "T ⊆ {..< x}" by (auto simp: subset_eq (*‹((?A::?'a set) ⊆ (?B::?'a set)) = (∀x::?'a∈?A. x ∈ ?B)›*) less_le (*‹((?x::?'a) < (?y::?'a)) = (?x ≤ ?y ∧ ?x ≠ ?y)›*)) qed (auto) (*solves the remaining goals: 1. ‹{..<x::'a} ⊆ {..x}› 2. ‹open {..<x::'a}›*) lemma countable_disjoint_nonempty_interior_subsets: fixes ℱ :: "'a::second_countable_topology set set" assumes pw: "pairwise disjnt ℱ" and int: "⋀S. ⟦S ∈ ℱ; interior S = {}⟧ ⟹ S = {}" shows "countable ℱ" proof (rule countable_image_inj_on (*‹⟦countable (?f ` ?A); inj_on ?f ?A⟧ ⟹ countable ?A›*)) (*goals: 1. ‹countable (?f ` ℱ)› 2. ‹inj_on ?f ℱ›*) have "disjoint (interior ` ℱ)" using pw (*‹disjoint (ℱ::'a set set)›*) by (simp add: disjoint_image_subset (*‹⟦disjoint ?𝒜; ⋀X. X ∈ ?𝒜 ⟹ ?f X ⊆ X⟧ ⟹ disjoint (?f ` ?𝒜)›*) interior_subset (*‹interior ?S ⊆ ?S›*)) then show "countable (interior ` ℱ)" by (auto intro: countable_disjoint_open_subsets (*‹⟦⋀S. S ∈ ?ℱ ⟹ open S; disjoint ?ℱ⟧ ⟹ countable ?ℱ›*)) show "inj_on interior ℱ" using pw (*‹disjoint ℱ›*) apply (clarsimp simp: inj_on_def (*‹inj_on ?f ?A = (∀x∈?A. ∀y∈?A. ?f x = ?f y ⟶ x = y)›*) pairwise_def (*‹pairwise ?R ?S = (∀x∈?S. ∀y∈?S. x ≠ y ⟶ ?R x y)›*)) (*goal: ‹inj_on interior ℱ›*) by (metis disjnt_def (*‹disjnt ?A ?B = (?A ∩ ?B = {})›*) disjnt_subset1 (*‹⟦disjnt ?X ?Y; ?Z ⊆ ?X⟧ ⟹ disjnt ?Z ?Y›*) inf.orderE (*‹⟦?a ≤ ?b; ?a = inf ?a ?b ⟹ ?thesis⟧ ⟹ ?thesis›*) int (*‹⟦?S ∈ ℱ; interior ?S = {}⟧ ⟹ ?S = {}›*) interior_subset (*‹interior ?S ⊆ ?S›*)) qed subsection ‹Closure of a Set› definition✐‹tag important› closure :: "('a::topological_space) set ⇒ 'a set" where "closure S = S ∪ {x . x islimpt S}" lemma interior_closure: "interior S = - (closure (- S))" by (auto simp: interior_def (*‹interior ?S = ⋃ {T. open T ∧ T ⊆ ?S}›*) closure_def (*‹closure ?S = ?S ∪ {x. x islimpt ?S}›*) islimpt_def (*‹?x islimpt ?S = (∀T. ?x ∈ T ⟶ open T ⟶ (∃y∈?S. y ∈ T ∧ y ≠ ?x))›*)) lemma closure_interior: "closure S = - interior (- S)" by (simp add: interior_closure (*‹interior ?S = - closure (- ?S)›*)) lemma closed_closure[simp, intro]: "closed (closure S)" by (simp add: closure_interior (*‹closure ?S = - interior (- ?S)›*) closed_Compl (*‹open ?S ⟹ closed (- ?S)›*)) lemma closure_subset: "S ⊆ closure S" by (simp add: closure_def (*‹closure ?S = ?S ∪ {x. x islimpt ?S}›*)) lemma closure_hull: "closure S = closed hull S" by (auto simp: hull_def (*‹?S hull ?s = ⋂ {t. ?S t ∧ ?s ⊆ t}›*) closure_interior (*‹closure ?S = - interior (- ?S)›*) interior_def (*‹interior ?S = ⋃ {T. open T ∧ T ⊆ ?S}›*)) lemma closure_eq: "closure S = S ⟷ closed S" unfolding closure_hull (*goal: ‹(closed hull (S::'a set) = S) = closed S›*) using closed_Inter (*‹∀S∈?K. closed S ⟹ closed (⋂ ?K)›*) by (rule hull_eq (*‹(⋀T. Ball T ?S ⟹ ?S (⋂ T)) ⟹ (?S hull ?s = ?s) = ?S ?s›*)) lemma closure_closed [simp]: "closed S ⟹ closure S = S" by (simp only: closure_eq (*‹(closure ?S = ?S) = closed ?S›*)) lemma closure_closure [simp]: "closure (closure S) = closure S" unfolding closure_hull (*goal: ‹closed hull (closed hull (S::'a set)) = closed hull S›*) by (rule hull_hull (*‹?S hull (?S hull ?s) = ?S hull ?s›*)) lemma closure_mono: "S ⊆ T ⟹ closure S ⊆ closure T" unfolding closure_hull (*goal: ‹S ⊆ T ⟹ closed hull S ⊆ closed hull T›*) by (rule hull_mono (*‹?s ⊆ ?t ⟹ ?S hull ?s ⊆ ?S hull ?t›*)) lemma closure_minimal: "S ⊆ T ⟹ closed T ⟹ closure S ⊆ T" unfolding closure_hull (*goal: ‹⟦S ⊆ T; closed T⟧ ⟹ closed hull S ⊆ T›*) apply (rule hull_minimal (*‹⟦?s ⊆ ?t; ?S ?t⟧ ⟹ ?S hull ?s ⊆ ?t›*)) (*goals: 1. ‹⟦S ⊆ T; closed T⟧ ⟹ S ⊆ T› 2. ‹⟦S ⊆ T; closed T⟧ ⟹ closed T› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) lemma closure_unique: assumes "S ⊆ T" and "closed T" and "⋀T'. S ⊆ T' ⟹ closed T' ⟹ T ⊆ T'" shows "closure S = T" using assms (*‹S ⊆ T› ‹closed T› ‹⟦S ⊆ ?T'; closed ?T'⟧ ⟹ T ⊆ ?T'›*) unfolding closure_hull (*goal: ‹closed hull S = T›*) apply (rule hull_unique (*‹⟦?s ⊆ ?t; ?S ?t; ⋀t'. ⟦?s ⊆ t'; ?S t'⟧ ⟹ ?t ⊆ t'⟧ ⟹ ?S hull ?s = ?t›*)) (*goals: 1. ‹⋀t'. ⟦S ⊆ t'; closed t'⟧ ⟹ S ⊆ t'› 2. ‹⋀t'. ⟦S ⊆ t'; closed t'⟧ ⟹ closed t'› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) lemma closure_empty [simp]: "closure {} = {}" using closed_empty (*‹closed {}›*) by (rule closure_closed (*‹closed ?S ⟹ closure ?S = ?S›*)) lemma closure_UNIV [simp]: "closure UNIV = UNIV" using closed_UNIV (*‹closed UNIV›*) by (rule closure_closed (*‹closed (?S::?'a set) ⟹ closure ?S = ?S›*)) lemma closure_Un [simp]: "closure (S ∪ T) = closure S ∪ closure T" by (simp add: closure_interior (*‹closure ?S = - interior (- ?S)›*)) lemma closure_eq_empty [iff]: "closure S = {} ⟷ S = {}" using closure_empty (*‹closure {} = {}›*) closure_subset[of S] (*‹S ⊆ closure S›*) by blast lemma closure_subset_eq: "closure S ⊆ S ⟷ closed S" using closure_eq[of S] (*‹(closure S = S) = closed S›*) closure_subset[of S] (*‹S ⊆ closure S›*) by simp lemma open_Int_closure_eq_empty: "open S ⟹ (S ∩ closure T) = {} ⟷ S ∩ T = {}" using open_subset_interior[of S "- T"] (*‹open S ⟹ (S ⊆ interior (- T)) = (S ⊆ - T)›*) using interior_subset[of "- T"] (*‹interior (- (T::'a set)) ⊆ - T›*) by (auto simp: closure_interior (*‹closure ?S = - interior (- ?S)›*)) lemma open_Int_closure_subset: "open S ⟹ S ∩ closure T ⊆ closure (S ∩ T)" proof (standard) (*goal: ‹⋀x. ⟦open S; x ∈ S ∩ closure T⟧ ⟹ x ∈ closure (S ∩ T)›*) fix x assume "*": "open S" "x ∈ S ∩ closure T" (*‹open (S::'a set)› ‹(x::'a) ∈ (S::'a set) ∩ closure (T::'a set)›*) then have "x islimpt (S ∩ T)" if "x islimpt T" by (metis IntD1 (*‹?c ∈ ?A ∩ ?B ⟹ ?c ∈ ?A›*) eventually_at_in_open' (*‹⟦open ?A; ?x ∈ ?A⟧ ⟹ ∀⇩F y in at ?x. y ∈ ?A›*) inf_commute (*‹inf ?x ?y = inf ?y ?x›*) islimpt_Int_eventually (*‹⟦?x islimpt ?A; ∀⇩F y in at ?x. y ∈ ?B⟧ ⟹ ?x islimpt ?A ∩ ?B›*) that (*‹x islimpt T›*)) with "*" (*‹open S› ‹(x::'a::topological_space) ∈ (S::'a::topological_space set) ∩ closure (T::'a::topological_space set)›*) show "x ∈ closure (S ∩ T)" unfolding closure_def (*goal: ‹x ∈ S ∩ T ∪ {x. x islimpt S ∩ T}›*) by blast qed lemma closure_complement: "closure (- S) = - interior S" by (simp add: closure_interior (*‹closure ?S = - interior (- ?S)›*)) lemma interior_complement: "interior (- S) = - closure S" by (simp add: closure_interior (*‹closure ?S = - interior (- ?S)›*)) lemma interior_diff: "interior(S - T) = interior S - closure T" by (simp add: Diff_eq (*‹?A - ?B = ?A ∩ - ?B›*) interior_complement (*‹interior (- ?S) = - closure ?S›*)) lemma closure_Times: "closure (A × B) = closure A × closure B" proof (rule closure_unique (*‹⟦(?S::?'a set) ⊆ (?T::?'a set); closed ?T; ⋀T'::?'a set. ⟦?S ⊆ T'; closed T'⟧ ⟹ ?T ⊆ T'⟧ ⟹ closure ?S = ?T›*)) (*goals: 1. ‹A × B ⊆ closure A × closure B› 2. ‹closed (closure A × closure B)› 3. ‹⋀T'. ⟦A × B ⊆ T'; closed T'⟧ ⟹ closure A × closure B ⊆ T'›*) show "A × B ⊆ closure A × closure B" by (intro Sigma_mono (*‹⟦?A ⊆ ?C; ⋀x. x ∈ ?A ⟹ ?B x ⊆ ?D x⟧ ⟹ Sigma ?A ?B ⊆ Sigma ?C ?D›*) closure_subset (*‹?S ⊆ closure ?S›*)) show "closed (closure A × closure B)" by (intro closed_Times (*‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S × ?T)›*) closed_closure (*‹closed (closure ?S)›*)) fix T assume "A × B ⊆ T" and "closed T" (*‹(A::'a set) × (B::'b set) ⊆ (T::('a × 'b) set)› ‹closed (T::('a × 'b) set)›*) then show "closure A × closure B ⊆ T" apply (simp add: closed_def (*‹closed (?S::?'a set) = open (- ?S)›*) open_prod_def (*‹open (?S::(?'a × ?'b) set) = (∀x::?'a × ?'b∈?S. ∃(A::?'a set) B::?'b set. open A ∧ open B ∧ x ∈ A × B ∧ A × B ⊆ ?S)›*)) (*goal: ‹closure A × closure B ⊆ T›*) apply clarify (*goal: ‹⟦A × B ⊆ T; ∀x∈- T. ∃A. open A ∧ (∃B. open B ∧ x ∈ A × B ∧ A × B ⊆ - T)⟧ ⟹ closure A × closure B ⊆ T›*) apply (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹⋀a b. ⟦A × B ⊆ T; ∀x∈- T. ∃A. open A ∧ (∃B. open B ∧ x ∈ A × B ∧ A × B ⊆ - T); a ∈ closure A; b ∈ closure B⟧ ⟹ (a, b) ∈ T›*) apply (drule_tac x="(a, b)" in bspec (*‹⟦∀x∈?A. ?P x; ?x ∈ ?A⟧ ⟹ ?P ?x›*)) (*goals: 1. ‹⋀a b. ⟦A × B ⊆ T; a ∈ closure A; b ∈ closure B; (a, b) ∉ T⟧ ⟹ (a, b) ∈ - T› 2. ‹⋀a b. ⟦A × B ⊆ T; a ∈ closure A; b ∈ closure B; (a, b) ∉ T; ∃A. open A ∧ (∃B. open B ∧ (a, b) ∈ A × B ∧ A × B ⊆ - T)⟧ ⟹ False› discuss goal 1*) apply simp (*discuss goal 2*) apply clarify (*goal: ‹⋀a b. ⟦A × B ⊆ T; a ∈ closure A; b ∈ closure B; (a, b) ∉ T; ∃A. open A ∧ (∃B. open B ∧ (a, b) ∈ A × B ∧ A × B ⊆ - T)⟧ ⟹ False›*) apply (rename_tac C D) (*goal: ‹⋀(a::'a::topological_space) (b::'b::topological_space) (Aa::'a::topological_space set) Ba::'b::topological_space set. ⟦(A::'a::topological_space set) × (B::'b::topological_space set) ⊆ (T::('a::topological_space × 'b::topological_space) set); a ∈ closure A; b ∈ closure B; (a, b) ∉ T; open Aa; open Ba; Aa × Ba ⊆ - T; a ∈ Aa; b ∈ Ba⟧ ⟹ False›*) apply (simp add: closure_interior (*‹closure ?S = - interior (- ?S)›*) interior_def (*‹interior ?S = ⋃ {T. open T ∧ T ⊆ ?S}›*)) (*goal: ‹⋀a b C D. ⟦A × B ⊆ T; a ∈ closure A; b ∈ closure B; (a, b) ∉ T; open C; open D; C × D ⊆ - T; a ∈ C; b ∈ D⟧ ⟹ False›*) apply (drule_tac x=C in spec (*‹∀x. ?P x ⟹ ?P ?x›*)) (*goal: ‹⋀(a::'a) (b::'b) (C::'a set) D::'b set. ⟦(A::'a set) × (B::'b set) ⊆ (T::('a × 'b) set); ∀x⊆- A. open x ⟶ a ∉ x; ∀x⊆- B. open x ⟶ b ∉ x; (a, b) ∉ T; open C; open D; C × D ⊆ - T; a ∈ C; b ∈ D⟧ ⟹ False›*) apply (drule_tac x=D in spec (*‹∀x::?'a. (?P::?'a ⇒ bool) x ⟹ ?P (?x::?'a)›*)) (*goal: ‹⋀a b C D. ⟦A × B ⊆ T; ∀x⊆- B. open x ⟶ b ∉ x; (a, b) ∉ T; open C; open D; C × D ⊆ - T; a ∈ C; b ∈ D; C ⊆ - A ⟶ open C ⟶ a ∉ C⟧ ⟹ False›*) apply auto (*proven 2 subgoals*) . qed lemma closure_open_Int_superset: assumes "open S" "S ⊆ closure T" shows "closure(S ∩ T) = closure S" by (metis Int_Un_distrib (*‹(?A::?'a set) ∩ ((?B::?'a set) ∪ (?C::?'a set)) = ?A ∩ ?B ∪ ?A ∩ ?C›*) Un_Int_eq( (*‹(?T::?'a set) ∩ ((?S::?'a set) ∪ ?T) = ?T›*) 4) assms (*‹open (S::'a set)› ‹(S::'a set) ⊆ closure (T::'a set)›*) closure_Un (*‹closure ((?S::?'a set) ∪ (?T::?'a set)) = closure ?S ∪ closure ?T›*) closure_closure (*‹closure (closure (?S::?'a set)) = closure ?S›*) open_Int_closure_subset (*‹open (?S::?'a set) ⟹ ?S ∩ closure (?T::?'a set) ⊆ closure (?S ∩ ?T)›*) sup.orderE (*‹⟦(?b::?'a) ≤ (?a::?'a); ?a = sup ?a ?b ⟹ ?thesis::bool⟧ ⟹ ?thesis›*)) lemma closure_Int: "closure (⋂I) ⊆ ⋂{closure S |S. S ∈ I}" by (simp add: INF_greatest (*‹(⋀i. i ∈ ?A ⟹ ?u ≤ ?f i) ⟹ ?u ≤ Inf (?f ` ?A)›*) Inter_lower (*‹?B ∈ ?A ⟹ ⋂ ?A ⊆ ?B›*) Setcompr_eq_image (*‹{?f x |x. x ∈ ?A} = ?f ` ?A›*) closure_mono (*‹?S ⊆ ?T ⟹ closure ?S ⊆ closure ?T›*)) lemma islimpt_in_closure: "(x islimpt S) = (x∈closure(S-{x}))" unfolding closure_def (*goal: ‹x islimpt S = (x ∈ S - {x} ∪ {xa. xa islimpt S - {x}})›*) using islimpt_punctured (*‹?x islimpt ?S = ?x islimpt ?S - {?x}›*) by blast lemma connected_imp_connected_closure: "connected S ⟹ connected (closure S)" apply (rule connectedI (*‹(⋀A B. ⟦open A; open B; A ∩ ?U ≠ {}; B ∩ ?U ≠ {}; A ∩ B ∩ ?U = {}; ?U ⊆ A ∪ B⟧ ⟹ False) ⟹ connected ?U›*)) (*goal: ‹connected S ⟹ connected (closure S)›*) by (meson closure_subset (*‹?S ⊆ closure ?S›*) open_Int (*‹⟦open ?S; open ?T⟧ ⟹ open (?S ∩ ?T)›*) open_Int_closure_eq_empty (*‹open ?S ⟹ (?S ∩ closure ?T = {}) = (?S ∩ ?T = {})›*) subset_trans (*‹⟦?A ⊆ ?B; ?B ⊆ ?C⟧ ⟹ ?A ⊆ ?C›*) connectedD (*‹⟦connected ?A; open ?U; open ?V; ?U ∩ ?V ∩ ?A = {}; ?A ⊆ ?U ∪ ?V⟧ ⟹ ?U ∩ ?A = {} ∨ ?V ∩ ?A = {}›*)) lemma bdd_below_closure: fixes A :: "real set" assumes "bdd_below A" shows "bdd_below (closure A)" proof (-) (*goal: ‹bdd_below (closure A)›*) from assms (*‹bdd_below A›*) obtain m where "⋀x. x ∈ A ⟹ m ≤ x" (*goal: ‹(⋀m. (⋀x. x ∈ A ⟹ m ≤ x) ⟹ thesis) ⟹ thesis›*) by (auto simp: bdd_below_def (*‹bdd_below ?A = (∃M. ∀x∈?A. M ≤ x)›*)) then have "A ⊆ {m..}" by auto then have "closure A ⊆ {m..}" using closed_real_atLeast (*‹closed {?a..}›*) by (rule closure_minimal (*‹⟦(?S::?'a set) ⊆ (?T::?'a set); closed ?T⟧ ⟹ closure ?S ⊆ ?T›*)) then show "?thesis" (*goal: ‹bdd_below (closure (A::real set))›*) by (auto simp: bdd_below_def (*‹bdd_below ?A = (∃M. ∀x∈?A. M ≤ x)›*)) qed subsection ‹Frontier (also known as boundary)› definition✐‹tag important› frontier :: "('a::topological_space) set ⇒ 'a set" where "frontier S = closure S - interior S" lemma frontier_closed [iff]: "closed (frontier S)" by (simp add: frontier_def (*‹frontier ?S = closure ?S - interior ?S›*) closed_Diff (*‹⟦closed ?S; open ?T⟧ ⟹ closed (?S - ?T)›*)) lemma frontier_closures: "frontier S = closure S ∩ closure (- S)" by (auto simp: frontier_def (*‹frontier (?S::?'a set) = closure ?S - interior ?S›*) interior_closure (*‹interior (?S::?'a set) = - closure (- ?S)›*)) lemma frontier_Int: "frontier(S ∩ T) = closure(S ∩ T) ∩ (frontier S ∪ frontier T)" proof (-) (*goal: ‹frontier ((S::'a set) ∩ (T::'a set)) = closure (S ∩ T) ∩ (frontier S ∪ frontier T)›*) have "closure (S ∩ T) ⊆ closure S" "closure (S ∩ T) ⊆ closure T" (*goals: 1. ‹closure (S ∩ T) ⊆ closure S› 2. ‹closure (S ∩ T) ⊆ closure T› discuss goal 1*) apply (simp add: closure_mono (*‹?S ⊆ ?T ⟹ closure ?S ⊆ closure ?T›*)) (*discuss goal 2*) apply (simp add: closure_mono (*‹?S ⊆ ?T ⟹ closure ?S ⊆ closure ?T›*)) (*proven 2 subgoals*) . then show "?thesis" (*goal: ‹frontier (S ∩ T) = closure (S ∩ T) ∩ (frontier S ∪ frontier T)›*) by (auto simp: frontier_closures (*‹frontier ?S = closure ?S ∩ closure (- ?S)›*)) qed lemma frontier_Int_subset: "frontier(S ∩ T) ⊆ frontier S ∪ frontier T" by (auto simp: frontier_Int (*‹frontier (?S ∩ ?T) = closure (?S ∩ ?T) ∩ (frontier ?S ∪ frontier ?T)›*)) lemma frontier_Int_closed: assumes "closed S" "closed T" shows "frontier(S ∩ T) = (frontier S ∩ T) ∪ (S ∩ frontier T)" by (smt (verit, best) Diff_Int (*‹?A - ?B ∩ ?C = ?A - ?B ∪ (?A - ?C)›*) Int_Diff (*‹?A ∩ ?B - ?C = ?A ∩ (?B - ?C)›*) assms (*‹closed S› ‹closed T›*) closed_Int (*‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)›*) closure_eq (*‹(closure ?S = ?S) = closed ?S›*) frontier_def (*‹frontier ?S = closure ?S - interior ?S›*) inf_commute (*‹inf ?x ?y = inf ?y ?x›*) interior_Int (*‹interior (?S ∩ ?T) = interior ?S ∩ interior ?T›*)) lemma frontier_subset_closed: "closed S ⟹ frontier S ⊆ S" by (metis frontier_def (*‹frontier ?S = closure ?S - interior ?S›*) closure_closed (*‹closed ?S ⟹ closure ?S = ?S›*) Diff_subset (*‹?A - ?B ⊆ ?A›*)) lemma frontier_empty [simp]: "frontier {} = {}" by (simp add: frontier_def (*‹frontier ?S = closure ?S - interior ?S›*)) lemma frontier_subset_eq: "frontier S ⊆ S ⟷ closed S" by (metis Diff_subset_conv (*‹((?A::?'a set) - (?B::?'a set) ⊆ (?C::?'a set)) = (?A ⊆ ?B ∪ ?C)›*) closure_subset_eq (*‹(closure (?S::?'a set) ⊆ ?S) = closed ?S›*) frontier_def (*‹frontier (?S::?'a set) = closure ?S - interior ?S›*) interior_subset (*‹interior (?S::?'a set) ⊆ ?S›*) subset_Un_eq (*‹((?A::?'a set) ⊆ (?B::?'a set)) = (?A ∪ ?B = ?B)›*)) lemma frontier_complement [simp]: "frontier (- S) = frontier S" by (auto simp: frontier_def (*‹frontier ?S = closure ?S - interior ?S›*) closure_complement (*‹closure (- ?S) = - interior ?S›*) interior_complement (*‹interior (- ?S) = - closure ?S›*)) lemma frontier_Un_subset: "frontier(S ∪ T) ⊆ frontier S ∪ frontier T" by (metis compl_sup (*‹- sup ?x ?y = inf (- ?x) (- ?y)›*) frontier_Int_subset (*‹frontier (?S ∩ ?T) ⊆ frontier ?S ∪ frontier ?T›*) frontier_complement (*‹frontier (- ?S) = frontier ?S›*)) lemma frontier_disjoint_eq: "frontier S ∩ S = {} ⟷ open S" using frontier_complement (*‹frontier (- (?S::?'a::topological_space set)) = frontier ?S›*) frontier_subset_eq[of "- S"] (*‹(frontier (- S) ⊆ - S) = closed (- S)›*) unfolding open_closed (*goal: ‹(frontier S ∩ S = {}) = closed (- S)›*) by auto lemma frontier_UNIV [simp]: "frontier UNIV = {}" using frontier_complement (*‹frontier (- ?S) = frontier ?S›*) frontier_empty (*‹frontier {} = {}›*) by fastforce lemma frontier_interiors: "frontier s = - interior(s) - interior(-s)" by (simp add: Int_commute (*‹?A ∩ ?B = ?B ∩ ?A›*) frontier_def (*‹frontier ?S = closure ?S - interior ?S›*) interior_closure (*‹interior ?S = - closure (- ?S)›*)) lemma frontier_interior_subset: "frontier(interior S) ⊆ frontier S" by (simp add: Diff_mono (*‹⟦?A ⊆ ?C; ?D ⊆ ?B⟧ ⟹ ?A - ?B ⊆ ?C - ?D›*) frontier_interiors (*‹frontier ?s = - interior ?s - interior (- ?s)›*) interior_mono (*‹?S ⊆ ?T ⟹ interior ?S ⊆ interior ?T›*) interior_subset (*‹interior ?S ⊆ ?S›*)) lemma closure_Un_frontier: "closure S = S ∪ frontier S" by (simp add: closure_def (*‹closure (?S::?'a set) = ?S ∪ {x::?'a. x islimpt ?S}›*) frontier_closures (*‹frontier (?S::?'a set) = closure ?S ∩ closure (- ?S)›*) sup_inf_distrib1 (*‹sup (?x::?'a) (inf (?y::?'a) (?z::?'a)) = inf (sup ?x ?y) (sup ?x ?z)›*)) subsection✐‹tag unimportant› ‹Filters and the ``eventually true'' quantifier› text ‹Identify Trivial limits, where we can't approach arbitrarily closely.› lemma trivial_limit_within: "trivial_limit (at a within S) ⟷ ¬ a islimpt S" unfolding trivial_limit_def eventually_at_topological islimpt_def (*goal: ‹(∃Sa::'a set. open Sa ∧ (a::'a) ∈ Sa ∧ (∀x::'a∈Sa. x ≠ a ⟶ x ∈ (S::'a set) ⟶ False)) = (¬ (∀T::'a set. a ∈ T ⟶ open T ⟶ (∃y::'a∈S. y ∈ T ∧ y ≠ a)))›*) by blast lemma trivial_limit_at_iff: "trivial_limit (at a) ⟷ ¬ a islimpt UNIV" using trivial_limit_within[of a UNIV] (*‹(at a = bot) = (¬ a islimpt UNIV)›*) by simp lemma trivial_limit_at: "¬ trivial_limit (at a)" for a :: "'a::perfect_space" by (rule at_neq_bot (*‹at ?a ≠ bot›*)) lemma not_trivial_limit_within: "¬ trivial_limit (at x within S) = (x ∈ closure (S - {x}))" using islimpt_in_closure (*‹?x islimpt ?S = (?x ∈ closure (?S - {?x}))›*) by (metis trivial_limit_within (*‹(at ?a within ?S = bot) = (¬ ?a islimpt ?S)›*)) lemma not_in_closure_trivial_limitI: "x ∉ closure S ⟹ trivial_limit (at x within S)" using not_trivial_limit_within[of x S] (*‹(at x within S = bot) ≠ (x ∈ closure (S - {x}))›*) apply safe (*goal: ‹x ∉ closure S ⟹ at x within S = bot›*) by (metis Diff_empty (*‹?A - {} = ?A›*) Diff_insert0 (*‹?x ∉ ?A ⟹ ?A - insert ?x ?B = ?A - ?B›*) closure_subset (*‹?S ⊆ closure ?S›*) contra_subsetD (*‹⟦?A ⊆ ?B; ?c ∉ ?B⟧ ⟹ ?c ∉ ?A›*)) lemma filterlim_at_within_closure_implies_filterlim: "filterlim f l (at x within S)" if "x ∈ closure S ⟹ filterlim f l (at x within S)" by (metis bot.extremum (*‹bot ≤ (?a::?'a)›*) filterlim_iff_le_filtercomap (*‹filterlim (?f::?'a ⇒ ?'b) (?F::?'b filter) (?G::?'a filter) = (?G ≤ filtercomap ?f ?F)›*) not_in_closure_trivial_limitI (*‹(?x::?'a) ∉ closure (?S::?'a set) ⟹ at ?x within ?S = bot›*) that (*‹(x::'a) ∈ closure (S::'a set) ⟹ filterlim (f::'a ⇒ 'b) (l::'b filter) (at x within S)›*)) lemma at_within_eq_bot_iff: "at c within A = bot ⟷ c ∉ closure (A - {c})" using not_trivial_limit_within[of c A] (*‹(at c within A = bot) ≠ (c ∈ closure (A - {c}))›*) by blast subsection ‹Limits› text ‹The expected monotonicity property.› lemma Lim_Un: assumes "(f ⤏ l) (at x within S)" "(f ⤏ l) (at x within T)" shows "(f ⤏ l) (at x within (S ∪ T))" using assms (*‹(f ⤏ l) (at x within S)› ‹(f ⤏ l) (at x within T)›*) unfolding at_within_union (*goal: ‹(f ⤏ l) (sup (at x within S) (at x within T))›*) by (rule filterlim_sup (*‹⟦filterlim (?f::?'a ⇒ ?'b) (?F::?'b filter) (?F1.0::?'a filter); filterlim ?f ?F (?F2.0::?'a filter)⟧ ⟹ filterlim ?f ?F (sup ?F1.0 ?F2.0)›*)) lemma Lim_Un_univ: "(f ⤏ l) (at x within S) ⟹ (f ⤏ l) (at x within T) ⟹ S ∪ T = UNIV ⟹ (f ⤏ l) (at x)" by (metis Lim_Un (*‹⟦(?f ⤏ ?l) (at ?x within ?S); (?f ⤏ ?l) (at ?x within ?T)⟧ ⟹ (?f ⤏ ?l) (at ?x within ?S ∪ ?T)›*)) text ‹Interrelations between restricted and unrestricted limits.› lemma Lim_at_imp_Lim_at_within: "(f ⤏ l) (at x) ⟹ (f ⤏ l) (at x within S)" by (metis order_refl (*‹(?x::?'a) ≤ ?x›*) filterlim_mono (*‹⟦filterlim (?f::?'a ⇒ ?'b) (?F2.0::?'b filter) (?F1.0::?'a filter); ?F2.0 ≤ (?F2'::?'b filter); (?F1'::?'a filter) ≤ ?F1.0⟧ ⟹ filterlim ?f ?F2' ?F1'›*) subset_UNIV (*‹(?A::?'a set) ⊆ UNIV›*) at_le (*‹(?s::?'a set) ⊆ (?t::?'a set) ⟹ at (?x::?'a) within ?s ≤ at ?x within ?t›*)) lemma eventually_within_interior: assumes "x ∈ interior S" shows "eventually P (at x within S) ⟷ eventually P (at x)" by (metis assms (*‹x ∈ interior S›*) at_within_open_subset (*‹⟦?a ∈ ?S; open ?S; ?S ⊆ ?T⟧ ⟹ at ?a within ?T = at ?a›*) interior_subset (*‹interior ?S ⊆ ?S›*) open_interior (*‹open (interior ?S)›*)) lemma at_within_interior: "x ∈ interior S ⟹ at x within S = at x" unfolding filter_eq_iff (*goal: ‹x ∈ interior S ⟹ ∀P. eventually P (at x within S) = eventually P (at x)›*) by (intro allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*) eventually_within_interior (*‹?x ∈ interior ?S ⟹ eventually ?P (at ?x within ?S) = eventually ?P (at ?x)›*)) lemma Lim_within_LIMSEQ: fixes a :: "'a::first_countable_topology" assumes "∀S. (∀n. S n ≠ a ∧ S n ∈ T) ∧ S ⇢ a ⟶ (λn. X (S n)) ⇢ L" shows "(X ⤏ L) (at a within T)" using assms (*‹∀S. (∀n. S n ≠ a ∧ S n ∈ T) ∧ S ⇢ a ⟶ (λn. X (S n)) ⇢ L›*) unfolding tendsto_def[where l = L] (*goal: ‹∀S. open S ⟶ L ∈ S ⟶ (∀⇩F x in at a within T. X x ∈ S)›*) by (simp add: sequentially_imp_eventually_within (*‹∀f. (∀n. f n ∈ ?s ∧ f n ≠ ?a) ∧ f ⇢ ?a ⟶ (∀⇩F n in sequentially. ?P (f n)) ⟹ eventually ?P (at ?a within ?s)›*)) lemma Lim_right_bound: fixes f :: "'a :: {linorder_topology, conditionally_complete_linorder, no_top} ⇒ 'b::{linorder_topology, conditionally_complete_linorder}" assumes mono: "⋀a b. a ∈ I ⟹ b ∈ I ⟹ x < a ⟹ a ≤ b ⟹ f a ≤ f b" and bnd: "⋀a. a ∈ I ⟹ x < a ⟹ K ≤ f a" shows "(f ⤏ Inf (f ` ({x<..} ∩ I))) (at x within ({x<..} ∩ I))" proof (cases "{x<..} ∩ I = {}") (*goals: 1. ‹{x<..} ∩ I = {} ⟹ (f ⤏ Inf (f ` ({x<..} ∩ I))) (at x within {x<..} ∩ I)› 2. ‹{x<..} ∩ I ≠ {} ⟹ (f ⤏ Inf (f ` ({x<..} ∩ I))) (at x within {x<..} ∩ I)›*) case True (*‹{x<..} ∩ I = {}›*) then show "?thesis" (*goal: ‹((f::'a ⇒ 'b) ⤏ Inf (f ` ({x::'a<..} ∩ (I::'a set)))) (at x within {x<..} ∩ I)›*) by simp next (*goal: ‹{x<..} ∩ I ≠ {} ⟹ (f ⤏ Inf (f ` ({x<..} ∩ I))) (at x within {x<..} ∩ I)›*) case False (*‹{x<..} ∩ I ≠ {}›*) show "?thesis" (*goal: ‹(f ⤏ Inf (f ` ({x<..} ∩ I))) (at x within {x<..} ∩ I)›*) proof (rule order_tendstoI (*‹⟦⋀a. a < ?y ⟹ ∀⇩F x in ?F. a < ?f x; ⋀a. ?y < a ⟹ ∀⇩F x in ?F. ?f x < a⟧ ⟹ (?f ⤏ ?y) ?F›*)) (*goals: 1. ‹⋀a::'b. a < Inf ((f::'a ⇒ 'b) ` ({x::'a<..} ∩ (I::'a set))) ⟹ ∀⇩F x::'a in at x within {x<..} ∩ I. a < f x› 2. ‹⋀a::'b. Inf ((f::'a ⇒ 'b) ` ({x::'a<..} ∩ (I::'a set))) < a ⟹ ∀⇩F x::'a in at x within {x<..} ∩ I. f x < a›*) fix a assume a: "a < Inf (f ` ({x<..} ∩ I))" (*‹(a::'b) < Inf ((f::'a ⇒ 'b) ` ({x::'a<..} ∩ (I::'a set)))›*) { fix y assume "y ∈ {x<..} ∩ I" (*‹(y::'a) ∈ {x::'a<..} ∩ (I::'a set)›*) with False (*‹{x<..} ∩ I ≠ {}›*) bnd (*‹⟦?a ∈ I; x < ?a⟧ ⟹ K ≤ f ?a›*) have "Inf (f ` ({x<..} ∩ I)) ≤ f y" by (auto intro!: cInf_lower (*‹⟦?x ∈ ?X; bdd_below ?X⟧ ⟹ Inf ?X ≤ ?x›*) bdd_belowI2 (*‹(⋀x. x ∈ ?A ⟹ ?m ≤ ?f x) ⟹ bdd_below (?f ` ?A)›*)) with a (*‹a < Inf (f ` ({x<..} ∩ I))›*) have "a < f y" by (blast intro: less_le_trans (*‹⟦?x < ?y; ?y ≤ ?z⟧ ⟹ ?x < ?z›*)) } then show "eventually (λx. a < f x) (at x within ({x<..} ∩ I))" by (auto simp: eventually_at_filter (*‹eventually ?P (at ?a within ?s) = (∀⇩F x in nhds ?a. x ≠ ?a ⟶ x ∈ ?s ⟶ ?P x)›*) intro: exI[of _ 1] (*‹?P 1 ⟹ ∃x. ?P x›*) zero_less_one (*‹0 < 1›*)) next (*goal: ‹⋀a. Inf (f ` ({x<..} ∩ I)) < a ⟹ ∀⇩F x in at x within {x<..} ∩ I. f x < a›*) fix a assume "Inf (f ` ({x<..} ∩ I)) < a" (*‹Inf ((f::'a ⇒ 'b) ` ({x::'a<..} ∩ (I::'a set))) < (a::'b)›*) from cInf_lessD[OF _ this] (*‹(f::'a ⇒ 'b) ` ({x::'a<..} ∩ (I::'a set)) ≠ {} ⟹ ∃x::'b∈f ` ({x<..} ∩ I). x < (a::'b)›*) False (*‹{x::'a::{conditionally_complete_linorder,no_top,linorder_topology}<..} ∩ (I::'a::{conditionally_complete_linorder,no_top,linorder_topology} set) ≠ {}›*) obtain y where y: "x < y" "y ∈ I" "f y < a" (*goal: ‹(⋀y. ⟦x < y; y ∈ I; f y < a⟧ ⟹ thesis) ⟹ thesis›*) by auto then have "eventually (λx. x ∈ I ⟶ f x < a) (at_right x)" unfolding eventually_at_right[OF ‹x < y›] (*goal: ‹∃b>x. ∀y>x. y < b ⟶ y ∈ I ⟶ f y < a›*) by (metis less_imp_le (*‹?x < ?y ⟹ ?x ≤ ?y›*) le_less_trans (*‹⟦?x ≤ ?y; ?y < ?z⟧ ⟹ ?x < ?z›*) mono (*‹⟦?a ∈ I; ?b ∈ I; x < ?a; ?a ≤ ?b⟧ ⟹ f ?a ≤ f ?b›*)) then show "eventually (λx. f x < a) (at x within ({x<..} ∩ I))" unfolding eventually_at_filter (*goal: ‹∀⇩F xa in nhds x. xa ≠ x ⟶ xa ∈ {x<..} ∩ I ⟶ f xa < a›*) apply eventually_elim (*goal: ‹∀⇩F xa in nhds x. xa ≠ x ⟶ xa ∈ {x<..} ∩ I ⟶ f xa < a›*) by simp qed qed text‹These are special for limits out of the same topological space.› lemma Lim_within_id: "(id ⤏ a) (at a within s)" unfolding id_def (*goal: ‹((λx::'a. x) ⤏ (a::'a)) (at a within (s::'a set))›*) by (rule tendsto_ident_at (*‹((λx::?'a. x) ⤏ (?a::?'a)) (at ?a within (?s::?'a set))›*)) lemma Lim_at_id: "(id ⤏ a) (at a)" unfolding id_def (*goal: ‹(λx. x) ─a→ a›*) by (rule tendsto_ident_at (*‹((λx. x) ⤏ ?a) (at ?a within ?s)›*)) text‹It's also sometimes useful to extract the limit point from the filter.› abbreviation netlimit :: "'a::t2_space filter ⇒ 'a" where "netlimit F ≡ Lim F (λx. x)" lemma netlimit_at [simp]: fixes a :: "'a::{perfect_space,t2_space}" shows "netlimit (at a) = a" using Lim_ident_at[of a UNIV] (*‹at a ≠ bot ⟹ netlimit (at a) = a›*) by simp lemma lim_within_interior: "x ∈ interior S ⟹ (f ⤏ l) (at x within S) ⟷ (f ⤏ l) (at x)" by (metis at_within_interior (*‹?x ∈ interior ?S ⟹ at ?x within ?S = at ?x›*)) lemma netlimit_within_interior: fixes x :: "'a::{t2_space,perfect_space}" assumes "x ∈ interior S" shows "netlimit (at x within S) = x" using assms (*‹(x::'a) ∈ interior (S::'a set)›*) by (metis at_within_interior (*‹?x ∈ interior ?S ⟹ at ?x within ?S = at ?x›*) netlimit_at (*‹netlimit (at ?a) = ?a›*)) text‹Useful lemmas on closure and set of possible sequential limits.› lemma closure_sequential: fixes l :: "'a::first_countable_topology" shows "l ∈ closure S ⟷ (∃x. (∀n. x n ∈ S) ∧ (x ⤏ l) sequentially)" by (metis Diff_empty (*‹(?A::?'a set) - {} = ?A›*) Diff_insert0 (*‹(?x::?'a) ∉ (?A::?'a set) ⟹ ?A - insert ?x (?B::?'a set) = ?A - ?B›*) Un_iff (*‹((?c::?'a) ∈ (?A::?'a set) ∪ (?B::?'a set)) = (?c ∈ ?A ∨ ?c ∈ ?B)›*) closure_def (*‹closure (?S::?'a set) = ?S ∪ {x::?'a. x islimpt ?S}›*) islimpt_sequential (*‹(?x::?'a) islimpt (?S::?'a set) = (∃f::nat ⇒ ?'a. (∀n::nat. f n ∈ ?S - {?x}) ∧ f ⇢ ?x)›*) mem_Collect_eq (*‹((?a::?'a) ∈ Collect (?P::?'a ⇒ bool)) = ?P ?a›*) tendsto_const (*‹((λx::?'b. ?k::?'a) ⤏ ?k) (?F::?'b filter)›*)) lemma closed_sequential_limits: fixes S :: "'a::first_countable_topology set" shows "closed S ⟷ (∀x l. (∀n. x n ∈ S) ∧ (x ⤏ l) sequentially ⟶ l ∈ S)" by (metis closure_sequential (*‹(?l ∈ closure ?S) = (∃x. (∀n. x n ∈ ?S) ∧ x ⇢ ?l)›*) closure_subset_eq (*‹(closure ?S ⊆ ?S) = closed ?S›*) subset_iff (*‹(?A ⊆ ?B) = (∀t. t ∈ ?A ⟶ t ∈ ?B)›*)) lemma tendsto_If_within_closures: assumes f: "x ∈ S ∪ (closure S ∩ closure T) ⟹ (f ⤏ l x) (at x within S ∪ (closure S ∩ closure T))" assumes g: "x ∈ T ∪ (closure S ∩ closure T) ⟹ (g ⤏ l x) (at x within T ∪ (closure S ∩ closure T))" assumes "x ∈ S ∪ T" shows "((λx. if x ∈ S then f x else g x) ⤏ l x) (at x within S ∪ T)" proof (-) (*goal: ‹((λx::'a::topological_space. if x ∈ (S::'a::topological_space set) then (f::'a::topological_space ⇒ 'b::topological_space) x else (g::'a::topological_space ⇒ 'b::topological_space) x) ⤏ (l::'a::topological_space ⇒ 'b::topological_space) (x::'a::topological_space)) (at x within S ∪ (T::'a::topological_space set))›*) have "*": "(S ∪ T) ∩ {x. x ∈ S} = S" "(S ∪ T) ∩ {x. x ∉ S} = T - S" (*goals: 1. ‹((S::'a::topological_space set) ∪ (T::'a::topological_space set)) ∩ {x::'a::topological_space. x ∈ S} = S› 2. ‹((S::'a::topological_space set) ∪ (T::'a::topological_space set)) ∩ {x::'a::topological_space. x ∉ S} = T - S› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have "(f ⤏ l x) (at x within S)" apply (rule filterlim_at_within_closure_implies_filterlim (*‹(?x ∈ closure ?S ⟹ filterlim ?f ?l (at ?x within ?S)) ⟹ filterlim ?f ?l (at ?x within ?S)›*)) (*goal: ‹(f ⤏ l x) (at x within S)›*) by (use ‹x ∈ _› in ‹auto simp: inf_commute closure_def intro: tendsto_within_subset[OF f]›) moreover have "(g ⤏ l x) (at x within T - S)" apply (rule filterlim_at_within_closure_implies_filterlim (*‹((?x::?'a) ∈ closure (?S::?'a set) ⟹ filterlim (?f::?'a ⇒ ?'b) (?l::?'b filter) (at ?x within ?S)) ⟹ filterlim ?f ?l (at ?x within ?S)›*)) (*goal: ‹(g ⤏ l x) (at x within T - S)›*) by (use ‹x ∈ _› in ‹auto intro!: tendsto_within_subset[OF g] simp: closure_def intro: islimpt_subset›) ultimately show "?thesis" (*goal: ‹((λx. if x ∈ S then f x else g x) ⤏ l x) (at x within S ∪ T)›*) apply (intro filterlim_at_within_If (*‹⟦filterlim ?f ?G (at ?x within ?A ∩ {x. ?P x}); filterlim ?g ?G (at ?x within ?A ∩ {x. ¬ ?P x})⟧ ⟹ LIM x at ?x within ?A. if ?P x then ?f x else ?g x :> ?G›*)) (*goals: 1. ‹⟦(f ⤏ l x) (at x within S); (g ⤏ l x) (at x within T - S)⟧ ⟹ (f ⤏ l x) (at x within (S ∪ T) ∩ {x. x ∈ S})› 2. ‹⟦(f ⤏ l x) (at x within S); (g ⤏ l x) (at x within T - S)⟧ ⟹ (g ⤏ l x) (at x within (S ∪ T) ∩ {x. x ∉ S})› discuss goal 1*) apply (simp only: * (*‹(S ∪ T) ∩ {x. x ∈ S} = S› ‹(S ∪ T) ∩ {x. x ∉ S} = T - S›*)) (*discuss goal 2*) apply (simp only: * (*‹(S ∪ T) ∩ {x. x ∈ S} = S› ‹(S ∪ T) ∩ {x. x ∉ S} = T - S›*)) (*proven 2 subgoals*) . qed subsection ‹Compactness› lemma brouwer_compactness_lemma: fixes f :: "'a::topological_space ⇒ 'b::real_normed_vector" assumes "compact S" and "continuous_on S f" and "¬ (∃x∈S. f x = 0)" obtains d where "0 < d" and "∀x∈S. d ≤ norm (f x)" proof (cases "S = {}") (*goals: 1. ‹⟦⋀d. ⟦0 < d; ∀x∈S. d ≤ norm (f x)⟧ ⟹ thesis; S = {}⟧ ⟹ thesis› 2. ‹⟦⋀d. ⟦0 < d; ∀x∈S. d ≤ norm (f x)⟧ ⟹ thesis; S ≠ {}⟧ ⟹ thesis›*) case True (*‹S = {}›*) show thesis apply (rule that [of 1] (*‹⟦0 < 1; ∀x∈S. 1 ≤ norm (f x)⟧ ⟹ thesis›*)) (*goals: 1. ‹0 < 1› 2. ‹∀x∈S. 1 ≤ norm (f x)› discuss goal 1*) apply ((auto simp: True (*‹S = {}›*))[1]) (*discuss goal 2*) apply ((auto simp: True (*‹S = {}›*))[1]) (*proven 2 subgoals*) . next (*goal: ‹⟦⋀d::real. ⟦(0::real) < d; ∀x::'a::topological_space∈S::'a::topological_space set. d ≤ norm ((f::'a::topological_space ⇒ 'b::real_normed_vector) x)⟧ ⟹ thesis::bool; S ≠ {}⟧ ⟹ thesis›*) case False (*‹S ≠ {}›*) have "continuous_on S (norm ∘ f)" apply (rule continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 139 facts*) continuous_on_norm (*‹continuous_on ?s ?f ⟹ continuous_on ?s (λx. norm (?f x))›*) assms( (*‹continuous_on S f›*) 2)) (*goals: 1. ‹continuous_on S f› 2. ‹continuous_on (f ` S) norm› discuss goal 1*) apply (rule continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 139 facts*) continuous_on_norm (*‹continuous_on ?s ?f ⟹ continuous_on ?s (λx. norm (?f x))›*) assms( (*‹continuous_on S f›*) 2)) (*discuss goal 2*) apply (rule continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 139 facts*) continuous_on_norm (*‹continuous_on ?s ?f ⟹ continuous_on ?s (λx. norm (?f x))›*) assms( (*‹continuous_on S f›*) 2)) (*goal: ‹continuous_on ((f::'a ⇒ 'b) ` (S::'a set)) norm›*) apply (rule continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 139 facts*) continuous_on_norm (*‹continuous_on ?s ?f ⟹ continuous_on ?s (λx. norm (?f x))›*) assms( (*‹continuous_on S f›*) 2)) (*proven 2 subgoals*) . with False (*‹S ≠ {}›*) obtain x where x: "x ∈ S" "∀y∈S. (norm ∘ f) x ≤ (norm ∘ f) y" (*goal: ‹(⋀x. ⟦x ∈ S; ∀y∈S. (norm ∘ f) x ≤ (norm ∘ f) y⟧ ⟹ thesis) ⟹ thesis›*) using continuous_attains_inf[OF assms ( 1 ), of "norm ∘ f"] (*‹⟦(S::'a set) ≠ {}; continuous_on S (norm ∘ (f::'a ⇒ 'b))⟧ ⟹ ∃x::'a∈S. ∀y::'a∈S. (norm ∘ f) x ≤ (norm ∘ f) y›*) unfolding o_def (*goal: ‹(⋀x::'a::topological_space. ⟦x ∈ (S::'a::topological_space set); ∀y::'a::topological_space∈S. norm ((f::'a::topological_space ⇒ 'b::real_normed_vector) x) ≤ norm (f y)⟧ ⟹ thesis::bool) ⟹ thesis›*) by auto then show "?thesis" (*goal: ‹thesis›*) by (metis assms( (*‹¬ (∃x::'a∈S::'a set. (f::'a ⇒ 'b) x = (0::'b))›*) 3) that (*‹⟦(0::real) < (?d::real); ∀x::'a∈S::'a set. ?d ≤ norm ((f::'a ⇒ 'b) x)⟧ ⟹ thesis::bool›*) comp_apply (*‹((?f::?'b ⇒ ?'a) ∘ (?g::?'c ⇒ ?'b)) (?x::?'c) = ?f (?g ?x)›*) zero_less_norm_iff (*‹((0::real) < norm (?x::?'a)) = (?x ≠ (0::?'a))›*)) qed subsubsection ‹Bolzano-Weierstrass property› proposition Heine_Borel_imp_Bolzano_Weierstrass: assumes "compact S" and "infinite T" and "T ⊆ S" shows "∃x ∈ S. x islimpt T" proof (rule ccontr (*‹(¬ (?P::bool) ⟹ False) ⟹ ?P›*)) (*goal: ‹¬ (∃x∈S. x islimpt T) ⟹ False›*) assume "¬ (∃x ∈ S. x islimpt T)" (*‹¬ (∃x::'a∈S::'a set. x islimpt (T::'a set))›*) then obtain f where f: "∀x∈S. x ∈ f x ∧ open (f x) ∧ (∀y∈T. y ∈ f x ⟶ y = x)" (*goal: ‹(⋀f. ∀x∈S. x ∈ f x ∧ open (f x) ∧ (∀y∈T. y ∈ f x ⟶ y = x) ⟹ thesis) ⟹ thesis›*) unfolding islimpt_def (*goal: ‹(⋀f::'a ⇒ 'a set. ∀x::'a∈S::'a set. x ∈ f x ∧ open (f x) ∧ (∀y::'a∈T::'a set. y ∈ f x ⟶ y = x) ⟹ thesis::bool) ⟹ thesis›*) by metis obtain g where g: "g ⊆ {T. ∃x. x ∈ S ∧ T = f x}" "finite g" "S ⊆ ⋃g" (*goal: ‹(⋀g. ⟦g ⊆ {T. ∃x. x ∈ S ∧ T = f x}; finite g; S ⊆ ⋃ g⟧ ⟹ thesis) ⟹ thesis›*) using assms(1)[unfolded compact_eq_Heine_Borel, THEN spec [ where x = "{T. ∃x. x∈S ∧ T = f x}" ]] (*‹Ball {T. ∃x. x ∈ S ∧ T = f x} open ∧ S ⊆ ⋃ {T. ∃x. x ∈ S ∧ T = f x} ⟶ (∃D⊆{T. ∃x. x ∈ S ∧ T = f x}. finite D ∧ S ⊆ ⋃ D)›*) using f (*‹∀x::'a::topological_space∈S::'a::topological_space set. x ∈ (f::'a::topological_space ⇒ 'a::topological_space set) x ∧ open (f x) ∧ (∀y::'a::topological_space∈T::'a::topological_space set. y ∈ f x ⟶ y = x)›*) by auto then have g': "∀x∈g. ∃y ∈ S. x = f y" by auto have "inj_on f T" by (smt (verit, best) assms( (*‹T ⊆ S›*) 3) f (*‹∀x∈S. x ∈ f x ∧ open (f x) ∧ (∀y∈T. y ∈ f x ⟶ y = x)›*) inj_onI (*‹(⋀x y. ⟦x ∈ ?A; y ∈ ?A; ?f x = ?f y⟧ ⟹ x = y) ⟹ inj_on ?f ?A›*) subsetD (*‹⟦?A ⊆ ?B; ?c ∈ ?A⟧ ⟹ ?c ∈ ?B›*)) then have "infinite (f ` T)" using assms(2) (*‹infinite T›*) using finite_imageD (*‹⟦finite (?f ` ?A); inj_on ?f ?A⟧ ⟹ finite ?A›*) by auto moreover have False if "x ∈ T" "f x ∉ g" for x by (smt (verit) UnionE (*‹⟦?A ∈ ⋃ ?C; ⋀X. ⟦?A ∈ X; X ∈ ?C⟧ ⟹ ?R⟧ ⟹ ?R›*) assms( (*‹T ⊆ S›*) 3) f (*‹∀x∈S. x ∈ f x ∧ open (f x) ∧ (∀y∈T. y ∈ f x ⟶ y = x)›*) g' (*‹∀x∈g. ∃y∈S. x = f y›*) g( (*‹S ⊆ ⋃ g›*) 3) subsetD (*‹⟦?A ⊆ ?B; ?c ∈ ?A⟧ ⟹ ?c ∈ ?B›*) that (*‹x ∈ T› ‹f x ∉ g›*)) then have "f ` T ⊆ g" by auto ultimately show False using g(2) (*‹finite g›*) using finite_subset (*‹⟦?A ⊆ ?B; finite ?B⟧ ⟹ finite ?A›*) by auto qed lemma sequence_infinite_lemma: fixes f :: "nat ⇒ 'a::t1_space" assumes "∀n. f n ≠ l" and "(f ⤏ l) sequentially" shows "infinite (range f)" proof (standard) (*goal: ‹finite (range f) ⟹ False›*) assume "finite (range f)" (*‹finite (range (f::nat ⇒ 'a))›*) then have "l ∉ range f ∧ closed (range f)" using ‹finite (range f)› (*‹finite (range f)›*) assms(1) (*‹∀n. f n ≠ l›*) finite_imp_closed (*‹finite (?S::?'a set) ⟹ closed ?S›*) by blast then have "eventually (λn. f n ∈ - range f) sequentially" by (metis Compl_iff (*‹(?c ∈ - ?A) = (?c ∉ ?A)›*) assms( (*‹f ⇢ l›*) 2) open_Compl (*‹closed ?S ⟹ open (- ?S)›*) topological_tendstoD (*‹⟦(?f ⤏ ?l) ?F; open ?S; ?l ∈ ?S⟧ ⟹ ∀⇩F x in ?F. ?f x ∈ ?S›*)) then show False unfolding eventually_sequentially (*goal: ‹False›*) by auto qed lemma Bolzano_Weierstrass_imp_closed: fixes S :: "'a::{first_countable_topology,t2_space} set" assumes "∀T. infinite T ∧ T ⊆ S --> (∃x ∈ S. x islimpt T)" shows "closed S" proof (-) (*goal: ‹closed S›*) { fix x and l assume as: "∀n::nat. x n ∈ S" "(x ⤏ l) sequentially" (*‹∀n::nat. (x::nat ⇒ 'a) n ∈ (S::'a set)› ‹(x::nat ⇒ 'a) ⇢ (l::'a)›*) have "l ∈ S" proof (cases "∀n. x n ≠ l") (*goals: 1. ‹∀n. x n ≠ l ⟹ l ∈ S› 2. ‹¬ (∀n. x n ≠ l) ⟹ l ∈ S›*) case False (*‹¬ (∀n. x n ≠ l)›*) then show "l∈S" using as(1) (*‹∀n::nat. (x::nat ⇒ 'a) n ∈ (S::'a set)›*) by auto next (*goal: ‹∀n. x n ≠ l ⟹ l ∈ S›*) case True (*‹∀n. x n ≠ l›*) with as(2) (*‹x ⇢ l›*) have "infinite (range x)" using sequence_infinite_lemma[of x l] (*‹⟦∀n. x n ≠ l; x ⇢ l⟧ ⟹ infinite (range x)›*) by auto then obtain l' where "l'∈S" "l' islimpt (range x)" (*goal: ‹(⋀l'. ⟦l' ∈ S; l' islimpt range x⟧ ⟹ thesis) ⟹ thesis›*) using as(1) (*‹∀n. x n ∈ S›*) assms (*‹∀T. infinite T ∧ T ⊆ S ⟶ (∃x∈S. x islimpt T)›*) by auto then show "l∈S" using sequence_unique_limpt (*‹⟦?f ⇢ ?l; ?l' islimpt range ?f⟧ ⟹ ?l' = ?l›*) as (*‹∀n. x n ∈ S› ‹x ⇢ l›*) True (*‹∀n. x n ≠ l›*) by auto qed } then show "?thesis" (*goal: ‹closed S›*) unfolding closed_sequential_limits (*goal: ‹∀x l. (∀n. x n ∈ S) ∧ x ⇢ l ⟶ l ∈ S›*) by fast qed lemma closure_insert: fixes x :: "'a::t1_space" shows "closure (insert x S) = insert x (closure S)" by (metis closed_singleton (*‹closed {?a}›*) closure_Un (*‹closure (?S ∪ ?T) = closure ?S ∪ closure ?T›*) closure_closed (*‹closed ?S ⟹ closure ?S = ?S›*) insert_is_Un (*‹insert ?a ?A = {?a} ∪ ?A›*)) lemma finite_not_islimpt_in_compact: assumes "compact A" "⋀z. z ∈ A ⟹ ¬z islimpt B" shows "finite (A ∩ B)" by (meson Heine_Borel_imp_Bolzano_Weierstrass (*‹⟦compact ?S; infinite ?T; ?T ⊆ ?S⟧ ⟹ ∃x∈?S. x islimpt ?T›*) assms (*‹compact A› ‹?z ∈ A ⟹ ¬ ?z islimpt B›*) inf_le1 (*‹inf ?x ?y ≤ ?x›*) inf_le2 (*‹inf ?x ?y ≤ ?y›*) islimpt_subset (*‹⟦?x islimpt ?S; ?S ⊆ ?T⟧ ⟹ ?x islimpt ?T›*)) text‹In particular, some common special cases.› lemma compact_Un [intro]: assumes "compact S" and "compact T" shows " compact (S ∪ T)" proof (rule compactI (*‹(⋀C. ⟦∀t∈C. open t; ?s ⊆ ⋃ C⟧ ⟹ ∃C'⊆C. finite C' ∧ ?s ⊆ ⋃ C') ⟹ compact ?s›*)) (*goal: ‹⋀C. ⟦∀t∈C. open t; S ∪ T ⊆ ⋃ C⟧ ⟹ ∃C'⊆C. finite C' ∧ S ∪ T ⊆ ⋃ C'›*) fix f assume "*": "Ball f open" "S ∪ T ⊆ ⋃f" (*‹Ball (f::'a set set) open› ‹(S::'a set) ∪ (T::'a set) ⊆ ⋃ (f::'a set set)›*) from "*" (*‹Ball (f::'a::topological_space set set) open› ‹S ∪ T ⊆ ⋃ f›*) ‹compact S› (*‹compact S›*) obtain s' where "s' ⊆ f ∧ finite s' ∧ S ⊆ ⋃s'" (*goal: ‹(⋀s'. s' ⊆ f ∧ finite s' ∧ S ⊆ ⋃ s' ⟹ thesis) ⟹ thesis›*) unfolding compact_eq_Heine_Borel (*goal: ‹(⋀s'. s' ⊆ f ∧ finite s' ∧ S ⊆ ⋃ s' ⟹ thesis) ⟹ thesis›*) by (auto elim!: allE[of _ f] (*‹⟦∀x. ?P x; ?P f ⟹ ?R⟧ ⟹ ?R›*)) moreover from "*" (*‹Ball f open› ‹S ∪ T ⊆ ⋃ f›*) ‹compact T› (*‹compact T›*) obtain t' where "t' ⊆ f ∧ finite t' ∧ T ⊆ ⋃t'" (*goal: ‹(⋀t'. t' ⊆ f ∧ finite t' ∧ T ⊆ ⋃ t' ⟹ thesis) ⟹ thesis›*) unfolding compact_eq_Heine_Borel (*goal: ‹(⋀t'. t' ⊆ f ∧ finite t' ∧ T ⊆ ⋃ t' ⟹ thesis) ⟹ thesis›*) by (auto elim!: allE[of _ f] (*‹⟦∀x. ?P x; ?P f ⟹ ?R⟧ ⟹ ?R›*)) ultimately show "∃f'⊆f. finite f' ∧ S ∪ T ⊆ ⋃f'" by (auto intro!: exI[of _ "s' ∪ t'"] (*‹?P (s' ∪ t') ⟹ ∃x. ?P x›*)) qed lemma compact_Union [intro]: "finite S ⟹ (⋀T. T ∈ S ⟹ compact T) ⟹ compact (⋃S)" apply (induct set: finite) (*goals: 1. ‹(⋀T. T ∈ {} ⟹ compact T) ⟹ compact (⋃ {})› 2. ‹⋀x F. ⟦finite F; x ∉ F; (⋀T. T ∈ F ⟹ compact T) ⟹ compact (⋃ F); ⋀T. T ∈ insert x F ⟹ compact T⟧ ⟹ compact (⋃ (insert x F))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma compact_UN [intro]: "finite A ⟹ (⋀x. x ∈ A ⟹ compact (B x)) ⟹ compact (⋃x∈A. B x)" by blast lemma closed_Int_compact [intro]: assumes "closed S" and "compact T" shows "compact (S ∩ T)" using compact_Int_closed[of T S] (*‹⟦compact T; closed S⟧ ⟹ compact (T ∩ S)›*) assms (*‹closed S› ‹compact T›*) by (simp add: Int_commute (*‹?A ∩ ?B = ?B ∩ ?A›*)) lemma compact_Int [intro]: fixes S T :: "'a :: t2_space set" assumes "compact S" and "compact T" shows "compact (S ∩ T)" using assms (*‹compact S› ‹compact T›*) apply (intro compact_Int_closed (*‹⟦compact ?S; closed ?T⟧ ⟹ compact (?S ∩ ?T)›*) compact_imp_closed (*‹compact ?s ⟹ closed ?s›*)) (*goals: 1. ‹⟦compact S; compact T⟧ ⟹ compact S› 2. ‹⟦compact S; compact T⟧ ⟹ compact T› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) lemma compact_sing [simp]: "compact {a}" unfolding compact_eq_Heine_Borel (*goal: ‹∀C. Ball C open ∧ {a} ⊆ ⋃ C ⟶ (∃D⊆C. finite D ∧ {a} ⊆ ⋃ D)›*) by auto lemma compact_insert [simp]: assumes "compact S" shows "compact (insert x S)" by (metis assms (*‹compact S›*) compact_Un (*‹⟦compact ?S; compact ?T⟧ ⟹ compact (?S ∪ ?T)›*) compact_sing (*‹compact {?a}›*) insert_is_Un (*‹insert ?a ?A = {?a} ∪ ?A›*)) lemma finite_imp_compact: "finite S ⟹ compact S" apply (induct set: finite) (*goals: 1. ‹compact {}› 2. ‹⋀x F. ⟦finite F; x ∉ F; compact F⟧ ⟹ compact (insert x F)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma open_delete: fixes S :: "'a::t1_space set" shows "open S ⟹ open (S - {x})" by (simp add: open_Diff (*‹⟦open ?S; closed ?T⟧ ⟹ open (?S - ?T)›*)) text‹Compactness expressed with filters› lemma closure_iff_nhds_not_empty: "x ∈ closure X ⟷ (∀A. ∀S⊆A. open S ⟶ x ∈ S ⟶ X ∩ A ≠ {})" proof (safe) (*goals: 1. ‹⋀(A::'a set) S::'a set. ⟦(x::'a) ∈ closure (X::'a set); S ⊆ A; open S; x ∈ S; X ∩ A = {}⟧ ⟹ False› 2. ‹∀(A::'a set) S::'a set. S ⊆ A ⟶ open S ⟶ (x::'a) ∈ S ⟶ (X::'a set) ∩ A ≠ {} ⟹ x ∈ closure X›*) assume x: "x ∈ closure X" (*‹(x::'a) ∈ closure (X::'a set)›*) fix S and A assume "§": "open S" "x ∈ S" "X ∩ A = {}" "S ⊆ A" (*‹open (S::'a set)› ‹(x::'a) ∈ (S::'a set)› ‹(X::'a set) ∩ (A::'a set) = {}› ‹(S::'a set) ⊆ (A::'a set)›*) then have "x ∉ closure (-S)" by (simp add: closed_open (*‹closed ?S = open (- ?S)›*)) with x (*‹x ∈ closure X›*) have "x ∈ closure X - closure (-S)" by auto with "§" (*‹open (S::'a::topological_space set)› ‹x ∈ S› ‹X ∩ A = {}› ‹S ⊆ A›*) show False by (metis Compl_iff (*‹((?c::?'a) ∈ - (?A::?'a set)) = (?c ∉ ?A)›*) Diff_iff (*‹((?c::?'a) ∈ (?A::?'a set) - (?B::?'a set)) = (?c ∈ ?A ∧ ?c ∉ ?B)›*) closure_mono (*‹(?S::?'a set) ⊆ (?T::?'a set) ⟹ closure ?S ⊆ closure ?T›*) disjoint_iff (*‹((?A::?'a set) ∩ (?B::?'a set) = {}) = (∀x::?'a. x ∈ ?A ⟶ x ∉ ?B)›*) subsetD (*‹⟦(?A::?'a set) ⊆ (?B::?'a set); (?c::?'a) ∈ ?A⟧ ⟹ ?c ∈ ?B›*) subsetI (*‹(⋀x::?'a. x ∈ (?A::?'a set) ⟹ x ∈ (?B::?'a set)) ⟹ ?A ⊆ ?B›*)) next (*goal: ‹∀A S. S ⊆ A ⟶ open S ⟶ x ∈ S ⟶ X ∩ A ≠ {} ⟹ x ∈ closure X›*) assume "∀A S. S ⊆ A ⟶ open S ⟶ x ∈ S ⟶ X ∩ A ≠ {}" (*‹∀(A::'a set) S::'a set. S ⊆ A ⟶ open S ⟶ (x::'a) ∈ S ⟶ (X::'a set) ∩ A ≠ {}›*) then show "x ∈ closure X" by (metis ComplI (*‹(?c ∈ ?A ⟹ False) ⟹ ?c ∈ - ?A›*) Compl_disjoint (*‹?A ∩ - ?A = {}›*) closure_interior (*‹closure ?S = - interior (- ?S)›*) interior_subset (*‹interior ?S ⊆ ?S›*) open_interior (*‹open (interior ?S)›*)) qed lemma compact_filter: "compact U ⟷ (∀F. F ≠ bot ⟶ eventually (λx. x ∈ U) F ⟶ (∃x∈U. inf (nhds x) F ≠ bot))" proof (intro allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*) iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*) impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*) compact_fip[THEN iffD2] (*‹∀A. (∀a∈A. closed a) ⟶ (∀B⊆A. finite B ⟶ ?U1 ∩ ⋂ B ≠ {}) ⟶ ?U1 ∩ ⋂ A ≠ {} ⟹ compact ?U1›*) notI (*‹(?P ⟹ False) ⟹ ¬ ?P›*)) (*goals: 1. ‹⋀F. ⟦compact U; F ≠ bot; ∀⇩F x in F. x ∈ U⟧ ⟹ ∃x∈U. inf (nhds x) F ≠ bot› 2. ‹⋀A. ⟦∀F. F ≠ bot ⟶ (∀⇩F x in F. x ∈ U) ⟶ (∃x∈U. inf (nhds x) F ≠ bot); ∀a∈A. closed a; ∀B⊆A. finite B ⟶ U ∩ ⋂ B ≠ {}; U ∩ ⋂ A = {}⟧ ⟹ False›*) fix F assume "compact U" (*‹compact (U::'a set)›*) assume F: "F ≠ bot" "eventually (λx. x ∈ U) F" (*‹(F::'a filter) ≠ bot› ‹∀⇩F x::'a in F::'a filter. x ∈ (U::'a set)›*) then have "U ≠ {}" by (auto simp: eventually_False (*‹(∀⇩F x in ?F. False) = (?F = bot)›*)) define Z where "Z = closure ` {A. eventually (λx. x ∈ A) F}" then have "∀z∈Z. closed z" by auto moreover have ev_Z: "⋀z. z ∈ Z ⟹ eventually (λx. x ∈ z) F" unfolding Z_def (*goal: ‹⋀z. z ∈ closure ` {A. ∀⇩F x in F. x ∈ A} ⟹ ∀⇩F x in F. x ∈ z›*) by (auto elim: eventually_mono (*‹⟦eventually ?P ?F; ⋀x. ?P x ⟹ ?Q x⟧ ⟹ eventually ?Q ?F›*) intro: subsetD[OF closure_subset] (*‹?c ∈ ?A ⟹ ?c ∈ closure ?A›*)) have "(∀B ⊆ Z. finite B ⟶ U ∩ ⋂B ≠ {})" proof (intro allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*) impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goal: ‹⋀B::'a set set. ⟦B ⊆ (Z::'a set set); finite B⟧ ⟹ (U::'a set) ∩ ⋂ B ≠ {}›*) fix B assume "finite B" "B ⊆ Z" (*‹finite (B::'a set set)› ‹(B::'a set set) ⊆ (Z::'a set set)›*) with ‹finite B› (*‹finite B›*) ev_Z (*‹?z ∈ Z ⟹ ∀⇩F x in F. x ∈ ?z›*) F(2) (*‹∀⇩F x::'a in F::'a filter. x ∈ (U::'a set)›*) have "eventually (λx. x ∈ U ∩ (⋂B)) F" by (auto simp: eventually_ball_finite_distrib (*‹finite ?A ⟹ (∀⇩F x in ?net. ∀y∈?A. ?P x y) = (∀y∈?A. ∀⇩F x in ?net. ?P x y)›*) eventually_conj_iff (*‹(∀⇩F x in ?F. ?P x ∧ ?Q x) = (eventually ?P ?F ∧ eventually ?Q ?F)›*)) with F (*‹F ≠ bot› ‹∀⇩F x in F. x ∈ U›*) show "U ∩ ⋂B ≠ {}" apply (intro notI (*‹(?P::bool ⟹ False) ⟹ ¬ ?P›*)) (*goal: ‹U ∩ ⋂ B ≠ {}›*) by (simp add: eventually_False (*‹(∀⇩F x in ?F. False) = (?F = bot)›*)) qed ultimately have "U ∩ ⋂Z ≠ {}" using ‹compact U› (*‹compact U›*) unfolding compact_fip (*goal: ‹(U::'a set) ∩ ⋂ (Z::'a set set) ≠ {}›*) by blast then obtain x where "x ∈ U" and x: "⋀z. z ∈ Z ⟹ x ∈ z" (*goal: ‹(⋀x. ⟦x ∈ U; ⋀z. z ∈ Z ⟹ x ∈ z⟧ ⟹ thesis) ⟹ thesis›*) by auto have "⋀P. eventually P (inf (nhds x) F) ⟹ P ≠ bot" unfolding eventually_inf eventually_nhds (*goal: ‹⋀P. ∃Q R. (∃S. open S ∧ x ∈ S ∧ Ball S Q) ∧ eventually R F ∧ (∀x. Q x ∧ R x ⟶ P x) ⟹ P ≠ bot›*) proof (safe) (*goal: ‹⋀P Q R S. ⟦eventually R F; ∀x. Q x ∧ R x ⟶ bot x; open S; x ∈ S; Ball S Q⟧ ⟹ False›*) fix P and Q and R and S assume "eventually R F" "open S" "x ∈ S" (*‹eventually (R::'a ⇒ bool) (F::'a filter)› ‹open (S::'a set)› ‹(x::'a) ∈ (S::'a set)›*) with open_Int_closure_eq_empty[of S "{x. R x}"] (*‹open S ⟹ (S ∩ closure {x. R x} = {}) = (S ∩ {x. R x} = {})›*) x (*‹?z ∈ Z ⟹ x ∈ ?z›*) have "S ∩ {x. R x} ≠ {}" by (auto simp: Z_def (*‹(Z::'a set set) = closure ` {A::'a set. ∀⇩F x::'a in F::'a filter. x ∈ A}›*)) moreover assume "Ball S Q" "∀x. Q x ∧ R x ⟶ bot x" (*‹Ball (S::'a set) (Q::'a ⇒ bool)› ‹∀x::'a. (Q::'a ⇒ bool) x ∧ (R::'a ⇒ bool) x ⟶ bot x›*) ultimately show False by (auto simp: set_eq_iff (*‹(?A = ?B) = (∀x. (x ∈ ?A) = (x ∈ ?B))›*)) qed with ‹x ∈ U› (*‹x ∈ U›*) show "∃x∈U. inf (nhds x) F ≠ bot" by (metis eventually_bot (*‹eventually ?P bot›*)) next (*goal: ‹⋀A. ⟦∀F. F ≠ bot ⟶ (∀⇩F x in F. x ∈ U) ⟶ (∃x∈U. inf (nhds x) F ≠ bot); ∀a∈A. closed a; ∀B⊆A. finite B ⟶ U ∩ ⋂ B ≠ {}; U ∩ ⋂ A = {}⟧ ⟹ False›*) fix A assume A: "∀a∈A. closed a" "∀B⊆A. finite B ⟶ U ∩ ⋂B ≠ {}" "U ∩ ⋂A = {}" (*‹∀a::'a set∈A::'a set set. closed a› ‹∀B⊆A::'a set set. finite B ⟶ (U::'a set) ∩ ⋂ B ≠ {}› ‹(U::'a set) ∩ ⋂ (A::'a set set) = {}›*) define F where "F = (INF a∈insert U A. principal a)" have "F ≠ bot" unfolding F_def (*goal: ‹Inf (principal ` insert U A) ≠ bot›*) proof (rule INF_filter_not_bot (*‹(⋀X::?'i set. ⟦X ⊆ (?B::?'i set); finite X⟧ ⟹ Inf ((?F::?'i ⇒ ?'a filter) ` X) ≠ bot) ⟹ Inf (?F ` ?B) ≠ bot›*)) (*goal: ‹⋀X::'a::topological_space set set. ⟦X ⊆ insert (U::'a::topological_space set) (A::'a::topological_space set set); finite X⟧ ⟹ Inf (principal ` X) ≠ bot›*) fix X assume X: "X ⊆ insert U A" "finite X" (*‹(X::'a set set) ⊆ insert (U::'a set) (A::'a set set)› ‹finite (X::'a set set)›*) with A(2)[THEN spec, of "X - {U}"] (*‹X - {U} ⊆ A ⟶ finite (X - {U}) ⟶ U ∩ ⋂ (X - {U}) ≠ {}›*) have "U ∩ ⋂(X - {U}) ≠ {}" by auto with X (*‹X ⊆ insert U A› ‹finite X›*) show "(INF a∈X. principal a) ≠ bot" by (auto simp: INF_principal_finite (*‹finite (?X::?'a set) ⟹ (INF x::?'a∈?X. principal ((?f::?'a ⇒ ?'b set) x)) = principal (⋂ (?f ` ?X))›*) principal_eq_bot_iff (*‹(principal (?X::?'a set) = bot) = (?X = {})›*)) qed moreover have "F ≤ principal U" unfolding F_def (*goal: ‹Inf (principal ` insert U A) ≤ principal U›*) by auto then have "eventually (λx. x ∈ U) F" by (auto simp: le_filter_def (*‹((?F::?'a filter) ≤ (?F'::?'a filter)) = (∀P::?'a ⇒ bool. eventually P ?F' ⟶ eventually P ?F)›*) eventually_principal (*‹eventually (?P::?'a ⇒ bool) (principal (?S::?'a set)) = (∀x::?'a∈?S. ?P x)›*)) moreover assume "∀F. F ≠ bot ⟶ eventually (λx. x ∈ U) F ⟶ (∃x∈U. inf (nhds x) F ≠ bot)" (*‹∀F::'a filter. F ≠ bot ⟶ (∀⇩F x::'a in F. x ∈ (U::'a set)) ⟶ (∃x::'a∈U. inf (nhds x) F ≠ bot)›*) ultimately obtain x where "x ∈ U" and x: "inf (nhds x) F ≠ bot" (*goal: ‹(⋀x. ⟦x ∈ U; inf (nhds x) F ≠ bot⟧ ⟹ thesis) ⟹ thesis›*) by auto { fix V assume "V ∈ A" (*‹(V::'a set) ∈ (A::'a set set)›*) then have "F ≤ principal V" unfolding F_def (*goal: ‹Inf (principal ` insert (U::'a set) (A::'a set set)) ≤ principal (V::'a set)›*) apply (intro INF_lower2[of V] (*‹⟦V ∈ ?A; ?f V ≤ ?u⟧ ⟹ Inf (?f ` ?A) ≤ ?u›*)) (*goals: 1. ‹V ∈ A ⟹ V ∈ insert U A› 2. ‹V ∈ A ⟹ principal V ≤ principal V› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . then have V: "eventually (λx. x ∈ V) F" by (auto simp: le_filter_def (*‹(?F ≤ ?F') = (∀P. eventually P ?F' ⟶ eventually P ?F)›*) eventually_principal (*‹eventually ?P (principal ?S) = (∀x∈?S. ?P x)›*)) have "x ∈ closure V" unfolding closure_iff_nhds_not_empty (*goal: ‹∀(A::'a set) S::'a set. S ⊆ A ⟶ open S ⟶ (x::'a) ∈ S ⟶ (V::'a set) ∩ A ≠ {}›*) proof (intro impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*) allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*)) (*goal: ‹⋀A S. ⟦S ⊆ A; open S; x ∈ S⟧ ⟹ V ∩ A ≠ {}›*) fix S and A assume "open S" "x ∈ S" "S ⊆ A" (*‹open (S::'a set)› ‹(x::'a) ∈ (S::'a set)› ‹(S::'a set) ⊆ (A::'a set)›*) then have "eventually (λx. x ∈ A) (nhds x)" by (auto simp: eventually_nhds (*‹eventually ?P (nhds ?a) = (∃S. open S ∧ ?a ∈ S ∧ (∀x∈S. ?P x))›*)) with V (*‹∀⇩F x::'a in F::'a filter. x ∈ (V::'a set)›*) have "eventually (λx. x ∈ V ∩ A) (inf (nhds x) F)" by (auto simp: eventually_inf (*‹eventually ?P (inf ?F ?F') = (∃Q R. eventually Q ?F ∧ eventually R ?F' ∧ (∀x. Q x ∧ R x ⟶ ?P x))›*)) with x (*‹inf (nhds x) F ≠ bot›*) show "V ∩ A ≠ {}" by (auto simp del: Int_iff (*‹((?c::?'a::type) ∈ (?A::?'a::type set) ∩ (?B::?'a::type set)) = (?c ∈ ?A ∧ ?c ∈ ?B)›*) simp add: trivial_limit_def (*‹((?F::?'a::type filter) = bot) = (∀⇩F x::?'a::type in ?F. False)›*)) qed then have "x ∈ V" using ‹V ∈ A› (*‹V ∈ A›*) A(1) (*‹∀a∈A. closed a›*) by simp } with ‹x∈U› (*‹x ∈ U›*) have "x ∈ U ∩ ⋂A" by auto with ‹U ∩ ⋂A = {}› (*‹(U::'a set) ∩ ⋂ (A::'a set set) = {}›*) show False by auto qed definition✐‹tag important› countably_compact :: "('a::topological_space) set ⇒ bool" where "countably_compact U ⟷ (∀A. countable A ⟶ (∀a∈A. open a) ⟶ U ⊆ ⋃A ⟶ (∃T⊆A. finite T ∧ U ⊆ ⋃T))" lemma countably_compactE: assumes "countably_compact s" and "∀t∈C. open t" and "s ⊆ ⋃C" "countable C" obtains C' where "C' ⊆ C" and "finite C'" and "s ⊆ ⋃C'" using assms (*‹countably_compact s› ‹∀t∈C. open t› ‹(s::'a set) ⊆ ⋃ (C::'a set set)› ‹countable C›*) unfolding countably_compact_def (*goal: ‹(⋀C'. ⟦C' ⊆ C; finite C'; s ⊆ ⋃ C'⟧ ⟹ thesis) ⟹ thesis›*) by metis lemma countably_compactI: assumes "⋀C. ∀t∈C. open t ⟹ s ⊆ ⋃C ⟹ countable C ⟹ (∃C'⊆C. finite C' ∧ s ⊆ ⋃C')" shows "countably_compact s" using assms (*‹⟦∀t∈?C. open t; s ⊆ ⋃ ?C; countable ?C⟧ ⟹ ∃C'⊆?C. finite C' ∧ s ⊆ ⋃ C'›*) unfolding countably_compact_def (*goal: ‹∀A. countable A ⟶ Ball A open ⟶ s ⊆ ⋃ A ⟶ (∃T⊆A. finite T ∧ s ⊆ ⋃ T)›*) by metis lemma compact_imp_countably_compact: "compact U ⟹ countably_compact U" by (auto simp: compact_eq_Heine_Borel (*‹compact ?S = (∀C. (∀c∈C. open c) ∧ ?S ⊆ ⋃ C ⟶ (∃D⊆C. finite D ∧ ?S ⊆ ⋃ D))›*) countably_compact_def (*‹countably_compact ?U = (∀A. countable A ⟶ (∀a∈A. open a) ⟶ ?U ⊆ ⋃ A ⟶ (∃T⊆A. finite T ∧ ?U ⊆ ⋃ T))›*)) lemma countably_compact_imp_compact: assumes "countably_compact U" and ccover: "countable B" "∀b∈B. open b" and basis: "⋀T x. open T ⟹ x ∈ T ⟹ x ∈ U ⟹ ∃b∈B. x ∈ b ∧ b ∩ U ⊆ T" shows "compact U" using ‹countably_compact U› (*‹countably_compact U›*) unfolding compact_eq_Heine_Borel countably_compact_def (*goal: ‹∀C. Ball C open ∧ U ⊆ ⋃ C ⟶ (∃D⊆C. finite D ∧ U ⊆ ⋃ D)›*) proof (safe) (*goal: ‹⋀C. ⟦∀A. countable A ⟶ Ball A open ⟶ U ⊆ ⋃ A ⟶ (∃T⊆A. finite T ∧ U ⊆ ⋃ T); Ball C open; U ⊆ ⋃ C⟧ ⟹ ∃D⊆C. finite D ∧ U ⊆ ⋃ D›*) fix A assume A: "∀a∈A. open a" "U ⊆ ⋃A" (*‹∀a::'a set∈A::'a set set. open a› ‹(U::'a set) ⊆ ⋃ (A::'a set set)›*) assume "*": "∀A. countable A ⟶ (∀a∈A. open a) ⟶ U ⊆ ⋃A ⟶ (∃T⊆A. finite T ∧ U ⊆ ⋃T)" (*‹∀A::'a set set. countable A ⟶ (∀a::'a set∈A. open a) ⟶ (U::'a set) ⊆ ⋃ A ⟶ (∃T⊆A. finite T ∧ U ⊆ ⋃ T)›*) moreover define C where "C = {b∈B. ∃a∈A. b ∩ U ⊆ a}" ultimately have "countable C" "∀a∈C. open a" unfolding C_def (*goals: 1. ‹countable {b ∈ B. Bex A ((⊆) (b ∩ U))}› 2. ‹∀a∈{b ∈ B. Bex A ((⊆) (b ∩ U))}. open a›*) using ccover (*‹countable B› ‹∀b∈B. open b›*) apply - (*goals: 1. ‹⟦∀A. countable A ⟶ (∀a∈A. open a) ⟶ U ⊆ ⋃ A ⟶ (∃T⊆A. finite T ∧ U ⊆ ⋃ T); {b ∈ B. Bex A ((⊆) (b ∩ U))} = {b ∈ B. ∃a∈A. b ∩ U ⊆ a}; countable B; ∀b∈B. open b⟧ ⟹ countable {b ∈ B. Bex A ((⊆) (b ∩ U))}› 2. ‹⟦∀A. countable A ⟶ (∀a∈A. open a) ⟶ U ⊆ ⋃ A ⟶ (∃T⊆A. finite T ∧ U ⊆ ⋃ T); {b ∈ B. Bex A ((⊆) (b ∩ U))} = {b ∈ B. ∃a∈A. b ∩ U ⊆ a}; countable B; ∀b∈B. open b⟧ ⟹ ∀a∈{b ∈ B. Bex A ((⊆) (b ∩ U))}. open a› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . moreover have "⋃A ∩ U ⊆ ⋃C" proof (safe) (*goal: ‹⋀(x::'a::topological_space) X::'a::topological_space set. ⟦x ∈ (U::'a::topological_space set); x ∈ X; X ∈ (A::'a::topological_space set set)⟧ ⟹ x ∈ ⋃ (C::'a::topological_space set set)›*) fix x and a assume "x ∈ U" "x ∈ a" "a ∈ A" (*‹(x::'a) ∈ (U::'a set)› ‹(x::'a) ∈ (a::'a set)› ‹(a::'a set) ∈ (A::'a set set)›*) with basis[of a x] (*‹⟦open a; x ∈ a; x ∈ U⟧ ⟹ ∃b∈B. x ∈ b ∧ b ∩ U ⊆ a›*) A (*‹∀a∈A. open a› ‹U ⊆ ⋃ A›*) obtain b where "b ∈ B" "x ∈ b" "b ∩ U ⊆ a" (*goal: ‹(⋀b. ⟦b ∈ B; x ∈ b; b ∩ U ⊆ a⟧ ⟹ thesis) ⟹ thesis›*) by blast with ‹a ∈ A› (*‹(a::'a set) ∈ (A::'a set set)›*) show "x ∈ ⋃C" unfolding C_def (*goal: ‹x ∈ ⋃ {b ∈ B. Bex A ((⊆) (b ∩ U))}›*) by auto qed then have "U ⊆ ⋃C" using ‹U ⊆ ⋃A› (*‹U ⊆ ⋃ A›*) by auto ultimately obtain T where T: "T⊆C" "finite T" "U ⊆ ⋃T" (*goal: ‹(⋀T::'a set set. ⟦T ⊆ (C::'a set set); finite T; (U::'a set) ⊆ ⋃ T⟧ ⟹ thesis::bool) ⟹ thesis›*) using "*" (*‹∀A::'a set set. countable A ⟶ (∀a::'a set∈A. open a) ⟶ (U::'a set) ⊆ ⋃ A ⟶ (∃T⊆A. finite T ∧ U ⊆ ⋃ T)›*) by metis then have "∀t∈T. ∃a∈A. t ∩ U ⊆ a" by (auto simp: C_def (*‹C = {b ∈ B. ∃a∈A. b ∩ U ⊆ a}›*)) then obtain f where "∀t∈T. f t ∈ A ∧ t ∩ U ⊆ f t" (*goal: ‹(⋀f. ∀t∈T. f t ∈ A ∧ t ∩ U ⊆ f t ⟹ thesis) ⟹ thesis›*) unfolding bchoice_iff Bex_def (*goal: ‹(⋀f::'a set ⇒ 'a set. ∀t::'a set∈T::'a set set. f t ∈ (A::'a set set) ∧ t ∩ (U::'a set) ⊆ f t ⟹ thesis::bool) ⟹ thesis›*) by standard with T (*‹T ⊆ C› ‹finite T› ‹U ⊆ ⋃ T›*) show "∃T⊆A. finite T ∧ U ⊆ ⋃T" unfolding C_def (*goal: ‹∃T⊆A. finite T ∧ U ⊆ ⋃ T›*) apply (intro exI[of _ "f`T"] (*‹?P (f ` T) ⟹ ∃x. ?P x›*)) (*goal: ‹∃T⊆A. finite T ∧ U ⊆ ⋃ T›*) by fastforce qed proposition countably_compact_imp_compact_second_countable: "countably_compact U ⟹ compact (U :: 'a :: second_countable_topology set)" proof (rule countably_compact_imp_compact (*‹⟦countably_compact ?U; countable ?B; ∀b∈?B. open b; ⋀T x. ⟦open T; x ∈ T; x ∈ ?U⟧ ⟹ ∃b∈?B. x ∈ b ∧ b ∩ ?U ⊆ T⟧ ⟹ compact ?U›*)) (*goals: 1. ‹countably_compact (U::'a set) ⟹ countably_compact U› 2. ‹countably_compact (U::'a set) ⟹ countable (?B::'a set set)› 3. ‹countably_compact (U::'a set) ⟹ ∀b::'a set∈?B::'a set set. open b› 4. ‹⋀(T::'a set) x::'a. ⟦countably_compact (U::'a set); open T; x ∈ T; x ∈ U⟧ ⟹ ∃b::'a set∈?B::'a set set. x ∈ b ∧ b ∩ U ⊆ T›*) fix T and x :: 'a assume "open T" "x ∈ T" (*‹open (T::'a set)› ‹(x::'a) ∈ (T::'a set)›*) from topological_basisE[OF is_basis this] (*‹(⋀B'. ⟦B' ∈ (SOME B. countable B ∧ topological_basis B); x ∈ B'; B' ⊆ T⟧ ⟹ ?thesis) ⟹ ?thesis›*) obtain b where "b ∈ (SOME B. countable B ∧ topological_basis B)" "x ∈ b" "b ⊆ T" (*goal: ‹(⋀b. ⟦b ∈ (SOME B. countable B ∧ topological_basis B); x ∈ b; b ⊆ T⟧ ⟹ thesis) ⟹ thesis›*) . then show "∃b∈SOME B. countable B ∧ topological_basis B. x ∈ b ∧ b ∩ U ⊆ T" by blast qed (insert countable_basis (*‹countable (SOME B. countable B ∧ topological_basis B)›*) topological_basis_open[OF is_basis] (*‹?X ∈ (SOME B. countable B ∧ topological_basis B) ⟹ open ?X›*), auto) (*solves the remaining goals: 1. ‹countably_compact U ⟹ countably_compact U› 2. ‹countably_compact U ⟹ countable (SOME B. countable B ∧ topological_basis B)› 3. ‹countably_compact U ⟹ ∀b∈SOME B. countable B ∧ topological_basis B. open b›*) lemma countably_compact_eq_compact: "countably_compact U ⟷ compact (U :: 'a :: second_countable_topology set)" using countably_compact_imp_compact_second_countable (*‹countably_compact ?U ⟹ compact ?U›*) compact_imp_countably_compact (*‹compact ?U ⟹ countably_compact ?U›*) by blast subsubsection‹Sequential compactness› definition✐‹tag important› seq_compact :: "'a::topological_space set ⇒ bool" where "seq_compact S ⟷ (∀f. (∀n. f n ∈ S) ⟶ (∃l∈S. ∃r::nat⇒nat. strict_mono r ∧ (f ∘ r) ⇢ l))" lemma seq_compactI: assumes "⋀f. ∀n. f n ∈ S ⟹ ∃l∈S. ∃r::nat⇒nat. strict_mono r ∧ (f ∘ r) ⇢ l" shows "seq_compact S" unfolding seq_compact_def (*goal: ‹∀f. (∀n. f n ∈ S) ⟶ (∃l∈S. ∃r. strict_mono r ∧ (f ∘ r) ⇢ l)›*) using assms (*‹∀n::nat. (?f::nat ⇒ 'a::topological_space) n ∈ (S::'a::topological_space set) ⟹ ∃l::'a::topological_space∈S. ∃r::nat ⇒ nat. strict_mono r ∧ (?f ∘ r) ⇢ l›*) by fast lemma seq_compactE: assumes "seq_compact S" "∀n. f n ∈ S" obtains l r where "l ∈ S" "strict_mono (r :: nat ⇒ nat)" "(f ∘ r) ⇢ l" using assms (*‹seq_compact S› ‹∀n. f n ∈ S›*) unfolding seq_compact_def (*goal: ‹(⋀l r. ⟦l ∈ S; strict_mono r; (f ∘ r) ⇢ l⟧ ⟹ thesis) ⟹ thesis›*) by fast lemma seq_compact_Int_closed: assumes "seq_compact S" and "closed T" shows "seq_compact (S ∩ T)" proof (rule seq_compactI (*‹(⋀f. ∀n. f n ∈ ?S ⟹ ∃l∈?S. ∃r. strict_mono r ∧ (f ∘ r) ⇢ l) ⟹ seq_compact ?S›*)) (*goal: ‹⋀f. ∀n. f n ∈ S ∩ T ⟹ ∃l∈S ∩ T. ∃r. strict_mono r ∧ (f ∘ r) ⇢ l›*) fix f assume "∀n::nat. f n ∈ S ∩ T" (*‹∀n::nat. (f::nat ⇒ 'a) n ∈ (S::'a set) ∩ (T::'a set)›*) hence "∀n. f n ∈ S" and "∀n. f n ∈ T" apply - (*goals: 1. ‹∀n::nat. (f::nat ⇒ 'a::topological_space) n ∈ (S::'a::topological_space set) ∩ (T::'a::topological_space set) ⟹ ∀n::nat. f n ∈ S› 2. ‹∀n::nat. (f::nat ⇒ 'a::topological_space) n ∈ (S::'a::topological_space set) ∩ (T::'a::topological_space set) ⟹ ∀n::nat. f n ∈ T› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . from ‹seq_compact S› (*‹seq_compact S›*) ‹∀n. f n ∈ S› (*‹∀n. f n ∈ S›*) obtain l and r where "l ∈ S" and r: "strict_mono r" and l: "(f ∘ r) ⇢ l" (*goal: ‹(⋀(l::'a) r::nat ⇒ nat. ⟦l ∈ (S::'a set); strict_mono r; ((f::nat ⇒ 'a) ∘ r) ⇢ l⟧ ⟹ thesis::bool) ⟹ thesis›*) by (rule seq_compactE (*‹⟦seq_compact ?S; ∀n. ?f n ∈ ?S; ⋀l r. ⟦l ∈ ?S; strict_mono r; (?f ∘ r) ⇢ l⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) from ‹∀n. f n ∈ T› (*‹∀n. f n ∈ T›*) have "∀n. (f ∘ r) n ∈ T" by simp with ‹l ∈ S› (*‹l ∈ S›*) r (*‹strict_mono r›*) l (*‹(f ∘ r) ⇢ l›*) show "∃l∈S ∩ T. ∃r. strict_mono r ∧ (f ∘ r) ⇢ l" by (metis Int_iff (*‹(?c ∈ ?A ∩ ?B) = (?c ∈ ?A ∧ ?c ∈ ?B)›*) ‹closed T› closed_sequentially (*‹⟦closed ?S; ⋀n. ?f n ∈ ?S; ?f ⇢ ?l⟧ ⟹ ?l ∈ ?S›*)) qed lemma seq_compact_closed_subset: assumes "closed S" and "S ⊆ T" and "seq_compact T" shows "seq_compact S" using assms (*‹closed S› ‹S ⊆ T› ‹seq_compact T›*) seq_compact_Int_closed[of T S] (*‹⟦seq_compact T; closed S⟧ ⟹ seq_compact (T ∩ S)›*) by (simp add: Int_absorb1 (*‹?B ⊆ ?A ⟹ ?A ∩ ?B = ?B›*)) lemma seq_compact_imp_countably_compact: fixes U :: "'a :: first_countable_topology set" assumes "seq_compact U" shows "countably_compact U" proof (safe intro!: countably_compactI (*‹(⋀C::?'a set set. ⟦∀t::?'a set∈C. open t; (?s::?'a set) ⊆ ⋃ C; countable C⟧ ⟹ ∃C'⊆C. finite C' ∧ ?s ⊆ ⋃ C') ⟹ countably_compact ?s›*)) (*goal: ‹⋀C. ⟦∀t∈C. open t; U ⊆ ⋃ C; countable C⟧ ⟹ ∃C'⊆C. finite C' ∧ U ⊆ ⋃ C'›*) fix A assume A: "∀a∈A. open a" "U ⊆ ⋃A" "countable A" (*‹∀a::'a set∈A::'a set set. open a› ‹(U::'a set) ⊆ ⋃ (A::'a set set)› ‹countable (A::'a set set)›*) have subseq: "⋀X. range X ⊆ U ⟹ ∃r x. x ∈ U ∧ strict_mono (r :: nat ⇒ nat) ∧ (X ∘ r) ⇢ x" using ‹seq_compact U› (*‹seq_compact U›*) by (fastforce simp: seq_compact_def (*‹seq_compact ?S = (∀f. (∀n. f n ∈ ?S) ⟶ (∃l∈?S. ∃r. strict_mono r ∧ (f ∘ r) ⇢ l))›*) subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*)) show "∃T⊆A. finite T ∧ U ⊆ ⋃T" proof (cases) (*goals: 1. ‹?P ⟹ ∃T⊆A. finite T ∧ U ⊆ ⋃ T› 2. ‹¬ ?P ⟹ ∃T⊆A. finite T ∧ U ⊆ ⋃ T›*) assume "finite A" (*‹finite (A::'a set set)›*) with A (*‹∀a∈A. open a› ‹U ⊆ ⋃ A› ‹countable A›*) show "?thesis" (*goal: ‹∃T⊆A. finite T ∧ U ⊆ ⋃ T›*) by auto next (*goal: ‹infinite A ⟹ ∃T⊆A. finite T ∧ U ⊆ ⋃ T›*) assume "infinite A" (*‹infinite (A::'a set set)›*) then have "A ≠ {}" by auto show "?thesis" (*goal: ‹∃T⊆A. finite T ∧ U ⊆ ⋃ T›*) proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹¬ (∃T⊆A. finite T ∧ U ⊆ ⋃ T) ⟹ False›*) assume "¬ (∃T⊆A. finite T ∧ U ⊆ ⋃T)" (*‹¬ (∃T⊆A::'a set set. finite T ∧ (U::'a set) ⊆ ⋃ T)›*) then have "∀T. ∃x. T ⊆ A ∧ finite T ⟶ (x ∈ U - ⋃T)" by auto then obtain X' where T: "⋀T. T ⊆ A ⟹ finite T ⟹ X' T ∈ U - ⋃T" (*goal: ‹(⋀X'::'a::first_countable_topology set set ⇒ 'a::first_countable_topology. (⋀T::'a::first_countable_topology set set. ⟦T ⊆ (A::'a::first_countable_topology set set); finite T⟧ ⟹ X' T ∈ (U::'a::first_countable_topology set) - ⋃ T) ⟹ thesis::bool) ⟹ thesis›*) by metis define X where "X n = X' (from_nat_into A ` {.. n})" for n have X: "⋀n. X n ∈ U - (⋃i≤n. from_nat_into A i)" using ‹A ≠ {}› (*‹A ≠ {}›*) unfolding X_def (*goal: ‹⋀n. X' (from_nat_into A ` {..n}) ∈ U - ⋃ (from_nat_into A ` {..n})›*) apply (intro T (*‹⟦?T ⊆ A; finite ?T⟧ ⟹ X' ?T ∈ U - ⋃ ?T›*)) (*goals: 1. ‹⋀n. A ≠ {} ⟹ from_nat_into A ` {..n} ⊆ A› 2. ‹⋀n. A ≠ {} ⟹ finite (from_nat_into A ` {..n})› discuss goal 1*) apply ((auto intro: from_nat_into (*‹?A ≠ {} ⟹ from_nat_into ?A ?n ∈ ?A›*))[1]) (*discuss goal 2*) apply ((auto intro: from_nat_into (*‹?A ≠ {} ⟹ from_nat_into ?A ?n ∈ ?A›*))[1]) (*proven 2 subgoals*) . then have "range X ⊆ U" by auto with subseq[of X] (*‹range X ⊆ U ⟹ ∃r x. x ∈ U ∧ strict_mono r ∧ (X ∘ r) ⇢ x›*) obtain r and x where "x ∈ U" and r: "strict_mono r" "(X ∘ r) ⇢ x" (*goal: ‹(⋀x r. ⟦x ∈ U; strict_mono r; (X ∘ r) ⇢ x⟧ ⟹ thesis) ⟹ thesis›*) by auto from ‹x∈U› (*‹x ∈ U›*) ‹U ⊆ ⋃A› (*‹U ⊆ ⋃ A›*) from_nat_into_surj[OF ‹countable A›] (*‹(?a::'a set) ∈ (A::'a set set) ⟹ ∃n::nat. from_nat_into A n = ?a›*) obtain n where "x ∈ from_nat_into A n" (*goal: ‹(⋀n. x ∈ from_nat_into A n ⟹ thesis) ⟹ thesis›*) by auto with r(2) (*‹(X ∘ r) ⇢ x›*) A(1) (*‹∀a∈A. open a›*) from_nat_into[OF ‹A ≠ {}›] (*‹from_nat_into (A::'a set set) (?n::nat) ∈ A›*) have "eventually (λi. X (r i) ∈ from_nat_into A n) sequentially" unfolding tendsto_def (*goal: ‹∀⇩F i in sequentially. X (r i) ∈ from_nat_into A n›*) by fastforce then obtain N where "⋀i. N ≤ i ⟹ X (r i) ∈ from_nat_into A n" (*goal: ‹(⋀N. (⋀i. N ≤ i ⟹ X (r i) ∈ from_nat_into A n) ⟹ thesis) ⟹ thesis›*) by (auto simp: eventually_sequentially (*‹eventually ?P sequentially = (∃N. ∀n≥N. ?P n)›*)) moreover from X (*‹(X::nat ⇒ 'a::first_countable_topology) (?n::nat) ∈ (U::'a::first_countable_topology set) - ⋃ (from_nat_into (A::'a::first_countable_topology set set) ` {..?n})›*) have "⋀i. n ≤ r i ⟹ X (r i) ∉ from_nat_into A n" by auto moreover from ‹strict_mono r›[THEN seq_suble, of "max n N"] (*‹max n N ≤ r (max n N)›*) have "∃i. n ≤ r i ∧ N ≤ i" by (auto intro!: exI[of _ "max n N"] (*‹?P (max n N) ⟹ ∃x. ?P x›*)) ultimately show False by auto qed qed qed lemma compact_imp_seq_compact: fixes U :: "'a :: first_countable_topology set" assumes "compact U" shows "seq_compact U" unfolding seq_compact_def (*goal: ‹∀f. (∀n. f n ∈ U) ⟶ (∃l∈U. ∃r. strict_mono r ∧ (f ∘ r) ⇢ l)›*) proof (safe) (*goal: ‹⋀f. ∀n. f n ∈ U ⟹ ∃l∈U. ∃r. strict_mono r ∧ (f ∘ r) ⇢ l›*) fix X :: "nat ⇒ 'a" assume "∀n. X n ∈ U" (*‹∀n::nat. (X::nat ⇒ 'a) n ∈ (U::'a set)›*) then have "eventually (λx. x ∈ U) (filtermap X sequentially)" by (auto simp: eventually_filtermap (*‹eventually ?P (filtermap ?f ?F) = (∀⇩F x in ?F. ?P (?f x))›*)) moreover have "filtermap X sequentially ≠ bot" by (simp add: trivial_limit_def (*‹((?F::?'a filter) = bot) = (∀⇩F x::?'a in ?F. False)›*) eventually_filtermap (*‹eventually (?P::?'a ⇒ bool) (filtermap (?f::?'b ⇒ ?'a) (?F::?'b filter)) = (∀⇩F x::?'b in ?F. ?P (?f x))›*)) ultimately obtain x where "x ∈ U" and x: "inf (nhds x) (filtermap X sequentially) ≠ bot" (is "?F ≠ _") (*goal: ‹(⋀x. ⟦x ∈ U; inf (nhds x) (filtermap X sequentially) ≠ bot⟧ ⟹ thesis) ⟹ thesis›*) using ‹compact U› (*‹compact U›*) by (auto simp: compact_filter (*‹compact ?U = (∀F. F ≠ bot ⟶ (∀⇩F x in F. x ∈ ?U) ⟶ (∃x∈?U. inf (nhds x) F ≠ bot))›*)) from countable_basis_at_decseq[of x] (*‹(⋀A. ⟦⋀i. open (A i); ⋀i. x ∈ A i; ⋀S. ⟦open S; x ∈ S⟧ ⟹ ∀⇩F i in sequentially. A i ⊆ S⟧ ⟹ ?thesis) ⟹ ?thesis›*) obtain A where A: "⋀i. open (A i)" "⋀i. x ∈ A i" "⋀S. open S ⟹ x ∈ S ⟹ eventually (λi. A i ⊆ S) sequentially" (*goal: ‹(⋀A. ⟦⋀i. open (A i); ⋀i. x ∈ A i; ⋀S. ⟦open S; x ∈ S⟧ ⟹ ∀⇩F i in sequentially. A i ⊆ S⟧ ⟹ thesis) ⟹ thesis›*) by blast define s where "s n i = (SOME j. i < j ∧ X j ∈ A (Suc n))" for n and i { fix n and i have "∃a. i < a ∧ X a ∈ A (Suc n)" proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹¬ (∃a>i::nat. (X::nat ⇒ 'a) a ∈ (A::nat ⇒ 'a set) (Suc (n::nat))) ⟹ False›*) assume "¬ (∃a>i. X a ∈ A (Suc n))" (*‹¬ (∃a>i::nat. (X::nat ⇒ 'a) a ∈ (A::nat ⇒ 'a set) (Suc (n::nat)))›*) then have "⋀a. Suc i ≤ a ⟹ X a ∉ A (Suc n)" by auto then have "eventually (λx. x ∉ A (Suc n)) (filtermap X sequentially)" by (auto simp: eventually_filtermap (*‹eventually ?P (filtermap ?f ?F) = (∀⇩F x in ?F. ?P (?f x))›*) eventually_sequentially (*‹eventually ?P sequentially = (∃N. ∀n≥N. ?P n)›*)) moreover have "eventually (λx. x ∈ A (Suc n)) (nhds x)" using A(1,2)[of "Suc n"] (*‹open (A (Suc n))› ‹x ∈ A (Suc n)›*) by (auto simp: eventually_nhds (*‹eventually ?P (nhds ?a) = (∃S. open S ∧ ?a ∈ S ∧ (∀x∈S. ?P x))›*)) ultimately have "eventually (λx. False) ?F" by (auto simp: eventually_inf (*‹eventually ?P (inf ?F ?F') = (∃Q R. eventually Q ?F ∧ eventually R ?F' ∧ (∀x. Q x ∧ R x ⟶ ?P x))›*)) with x (*‹inf (nhds (x::'a)) (filtermap (X::nat ⇒ 'a) sequentially) ≠ bot›*) show False by (simp add: eventually_False (*‹(∀⇩F x::?'a in ?F::?'a filter. False) = (?F = bot)›*)) qed then have "i < s n i" "X (s n i) ∈ A (Suc n)" unfolding s_def (*goals: 1. ‹i < (SOME j. i < j ∧ X j ∈ A (Suc n))› 2. ‹X (SOME j. i < j ∧ X j ∈ A (Suc n)) ∈ A (Suc n)›*) apply - (*goals: 1. ‹∃a>i::nat. (X::nat ⇒ 'a) a ∈ (A::nat ⇒ 'a set) (Suc (n::nat)) ⟹ i < (SOME j::nat. i < j ∧ X j ∈ A (Suc n))› 2. ‹∃a>i::nat. (X::nat ⇒ 'a) a ∈ (A::nat ⇒ 'a set) (Suc (n::nat)) ⟹ X (SOME j::nat. i < j ∧ X j ∈ A (Suc n)) ∈ A (Suc n)› discuss goal 1*) apply ((auto intro: someI2_ex (*‹⟦∃a. ?P a; ⋀x. ?P x ⟹ ?Q x⟧ ⟹ ?Q (SOME x. ?P x)›*))[1]) (*discuss goal 2*) apply ((auto intro: someI2_ex (*‹⟦∃a::?'a::type. (?P::?'a::type ⇒ bool) a; ⋀x::?'a::type. ?P x ⟹ (?Q::?'a::type ⇒ bool) x⟧ ⟹ ?Q (SOME x::?'a::type. ?P x)›*))[1]) (*proven 2 subgoals*) . } note s = this (*‹?i2 < s ?n2 ?i2› ‹X (s ?n2 ?i2) ∈ A (Suc ?n2)›*) define r where "r = rec_nat (s 0 0) s" have "strict_mono r" by (auto simp: r_def (*‹r = rec_nat (s 0 0) s›*) s (*‹?i2 < s ?n2 ?i2› ‹X (s ?n2 ?i2) ∈ A (Suc ?n2)›*) strict_mono_Suc_iff (*‹strict_mono ?f = (∀n. ?f n < ?f (Suc n))›*)) moreover have "(λn. X (r n)) ⇢ x" proof (rule topological_tendstoI (*‹(⋀S. ⟦open S; ?l ∈ S⟧ ⟹ ∀⇩F x in ?F. ?f x ∈ S) ⟹ (?f ⤏ ?l) ?F›*)) (*goal: ‹⋀S. ⟦open S; x ∈ S⟧ ⟹ ∀⇩F x in sequentially. X (r x) ∈ S›*) fix S assume "open S" "x ∈ S" (*‹open (S::'a set)› ‹(x::'a) ∈ (S::'a set)›*) with A(3) (*‹⟦open ?S; x ∈ ?S⟧ ⟹ ∀⇩F i in sequentially. A i ⊆ ?S›*) have "eventually (λi. A i ⊆ S) sequentially" by auto moreover { fix i assume "Suc 0 ≤ i" (*‹Suc (0::nat) ≤ (i::nat)›*) then have "X (r i) ∈ A i" apply (cases i) (*goals: 1. ‹⟦Suc 0 ≤ i; i = 0⟧ ⟹ X (r i) ∈ A i› 2. ‹⋀nat. ⟦Suc 0 ≤ i; i = Suc nat⟧ ⟹ X (r i) ∈ A i› discuss goal 1*) apply (simp add: r_def (*‹r = rec_nat (s 0 0) s›*) s (*‹?i2 < s ?n2 ?i2› ‹X (s ?n2 ?i2) ∈ A (Suc ?n2)›*)) (*discuss goal 2*) apply (simp add: r_def (*‹r = rec_nat (s 0 0) s›*) s (*‹?i2 < s ?n2 ?i2› ‹X (s ?n2 ?i2) ∈ A (Suc ?n2)›*)) (*proven 2 subgoals*) . } then have "eventually (λi. X (r i) ∈ A i) sequentially" by (auto simp: eventually_sequentially (*‹eventually ?P sequentially = (∃N. ∀n≥N. ?P n)›*)) ultimately show "eventually (λi. X (r i) ∈ S) sequentially" apply eventually_elim (*goal: ‹∀⇩F i in sequentially. X (r i) ∈ S›*) by auto qed ultimately show "∃x ∈ U. ∃r. strict_mono r ∧ (X ∘ r) ⇢ x" using ‹x ∈ U› (*‹x ∈ U›*) by (auto simp: convergent_def (*‹convergent (?X::nat ⇒ ?'a) = (∃L::?'a. ?X ⇢ L)›*) comp_def (*‹(?f::?'b ⇒ ?'c) ∘ (?g::?'a ⇒ ?'b) = (λx::?'a. ?f (?g x))›*)) qed lemma countably_compact_imp_acc_point: assumes "countably_compact S" and "countable T" and "infinite T" and "T ⊆ S" shows "∃x∈S. ∀U. x∈U ∧ open U ⟶ infinite (U ∩ T)" proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹¬ (∃x∈S. ∀U. x ∈ U ∧ open U ⟶ infinite (U ∩ T)) ⟹ False›*) define C where "C = (λF. interior (F ∪ (- T))) ` {F. finite F ∧ F ⊆ T }" note ‹countably_compact S› (*‹countably_compact S›*) moreover have "∀T∈C. open T" by (auto simp: C_def (*‹C = (λF. interior (F ∪ - T)) ` {F. finite F ∧ F ⊆ T}›*)) moreover assume "¬ (∃x∈S. ∀U. x∈U ∧ open U ⟶ infinite (U ∩ T))" (*‹¬ (∃x::'a∈S::'a set. ∀U::'a set. x ∈ U ∧ open U ⟶ infinite (U ∩ (T::'a set)))›*) then have S: "⋀x. x ∈ S ⟹ ∃U. x∈U ∧ open U ∧ finite (U ∩ T)" by metis have "S ⊆ ⋃C" using ‹T ⊆ S› (*‹T ⊆ S›*) unfolding C_def (*goal: ‹S ⊆ (⋃F∈{F. finite F ∧ F ⊆ T}. interior (F ∪ - T))›*) apply (safe dest!: S (*‹?x ∈ S ⟹ ∃U. ?x ∈ U ∧ open U ∧ finite (U ∩ T)›*)) (*goal: ‹(S::'a set) ⊆ (⋃F::'a set∈{F::'a set. finite F ∧ F ⊆ T}. interior (F ∪ - (T::'a set)))›*) apply (rule_tac a="U ∩ T" in UN_I (*‹⟦?a ∈ ?A; ?b ∈ ?B ?a⟧ ⟹ ?b ∈ ⋃ (?B ` ?A)›*)) (*goals: 1. ‹⋀(x::'a) U::'a set. ⟦(T::'a set) ⊆ (S::'a set); x ∈ U; open U; finite (U ∩ T)⟧ ⟹ U ∩ T ∈ {F::'a set. finite F ∧ F ⊆ T}› 2. ‹⋀(x::'a) U::'a set. ⟦(T::'a set) ⊆ (S::'a set); x ∈ U; open U; finite (U ∩ T)⟧ ⟹ x ∈ interior (U ∩ T ∪ - T)› discuss goal 1*) apply ((auto intro!: interiorI (*‹⟦open (?T::?'a set); (?x::?'a) ∈ ?T; ?T ⊆ (?S::?'a set)⟧ ⟹ ?x ∈ interior ?S›*) simp add: finite_subset (*‹⟦(?A::?'a set) ⊆ (?B::?'a set); finite ?B⟧ ⟹ finite ?A›*))[1]) (*discuss goal 2*) apply ((auto intro!: interiorI (*‹⟦open ?T; ?x ∈ ?T; ?T ⊆ ?S⟧ ⟹ ?x ∈ interior ?S›*) simp add: finite_subset (*‹⟦?A ⊆ ?B; finite ?B⟧ ⟹ finite ?A›*))[1]) (*proven 2 subgoals*) . moreover from ‹countable T› (*‹countable (T::'a::topological_space set)›*) have "countable C" unfolding C_def (*goal: ‹countable ((λF. interior (F ∪ - T)) ` {F. finite F ∧ F ⊆ T})›*) by (auto intro: countable_Collect_finite_subset (*‹countable ?T ⟹ countable {A. finite A ∧ A ⊆ ?T}›*)) ultimately obtain D where "D ⊆ C" "finite D" "S ⊆ ⋃D" (*goal: ‹(⋀D. ⟦D ⊆ C; finite D; S ⊆ ⋃ D⟧ ⟹ thesis) ⟹ thesis›*) by (rule countably_compactE (*‹⟦countably_compact ?s; ∀t∈?C. open t; ?s ⊆ ⋃ ?C; countable ?C; ⋀C'. ⟦C' ⊆ ?C; finite C'; ?s ⊆ ⋃ C'⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) then obtain E where E: "E ⊆ {F. finite F ∧ F ⊆ T }" "finite E" and S: "S ⊆ (⋃F∈E. interior (F ∪ (- T)))" (*goal: ‹(⋀E. ⟦E ⊆ {F. finite F ∧ F ⊆ T}; finite E; S ⊆ (⋃F∈E. interior (F ∪ - T))⟧ ⟹ thesis) ⟹ thesis›*) by (metis (lifting) finite_subset_image (*‹⟦finite ?B; ?B ⊆ ?f ` ?A⟧ ⟹ ∃C⊆?A. finite C ∧ ?B = ?f ` C›*) C_def (*‹C = (λF. interior (F ∪ - T)) ` {F. finite F ∧ F ⊆ T}›*)) from S (*‹(S::'a::topological_space set) ⊆ (⋃F::'a::topological_space set∈E::'a::topological_space set set. interior (F ∪ - (T::'a::topological_space set)))›*) ‹T ⊆ S› (*‹T ⊆ S›*) have "T ⊆ ⋃E" using interior_subset (*‹interior (?S::?'a set) ⊆ ?S›*) by blast moreover have "finite (⋃E)" using E (*‹E ⊆ {F. finite F ∧ F ⊆ T}› ‹finite (E::'a set set)›*) by auto ultimately show False using ‹infinite T› (*‹infinite T›*) by (auto simp: finite_subset (*‹⟦(?A::?'a set) ⊆ (?B::?'a set); finite ?B⟧ ⟹ finite ?A›*)) qed lemma countable_acc_point_imp_seq_compact: fixes S :: "'a::first_countable_topology set" assumes "⋀T. ⟦infinite T; countable T; T ⊆ S⟧ ⟹ ∃x∈S. ∀U. x∈U ∧ open U ⟶ infinite (U ∩ T)" shows "seq_compact S" unfolding seq_compact_def (*goal: ‹∀f. (∀n. f n ∈ S) ⟶ (∃l∈S. ∃r. strict_mono r ∧ (f ∘ r) ⇢ l)›*) proof (intro strip (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q› ‹(⋀x. ?P x) ⟹ ∀x. ?P x› ‹(⋀x. x ∈ ?A ⟹ ?P x) ⟹ ∀x∈?A. ?P x›*)) (*goal: ‹⋀f. ∀n. f n ∈ S ⟹ ∃l∈S. ∃r. strict_mono r ∧ (f ∘ r) ⇢ l›*) fix f :: "nat ⇒ 'a" assume f: "∀n. f n ∈ S" (*‹∀n::nat. (f::nat ⇒ 'a) n ∈ (S::'a set)›*) show "∃l∈S. ∃r. strict_mono r ∧ ((f ∘ r) ⤏ l) sequentially" proof (cases "finite (range f)") (*goals: 1. ‹finite (range f) ⟹ ∃l∈S. ∃r. strict_mono r ∧ (f ∘ r) ⇢ l› 2. ‹infinite (range f) ⟹ ∃l∈S. ∃r. strict_mono r ∧ (f ∘ r) ⇢ l›*) case True (*‹finite (range f)›*) obtain l where "infinite {n. f n = f l}" (*goal: ‹(⋀l. infinite {n. f n = f l} ⟹ thesis) ⟹ thesis›*) using pigeonhole_infinite[OF _ True] (*‹infinite UNIV ⟹ ∃a0∈UNIV. infinite {a ∈ UNIV. f a = f a0}›*) by auto then obtain r :: "nat ⇒ nat" where "strict_mono r" and fr: "∀n. f (r n) = f l" (*goal: ‹(⋀r::nat ⇒ nat. ⟦strict_mono r; ∀n::nat. (f::nat ⇒ 'a) (r n) = f (l::nat)⟧ ⟹ thesis::bool) ⟹ thesis›*) using infinite_enumerate (*‹infinite ?S ⟹ ∃r. strict_mono r ∧ (∀n. r n ∈ ?S)›*) by blast then have "strict_mono r ∧ (f ∘ r) ⇢ f l" by (simp add: fr (*‹∀n. f (r n) = f l›*) o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*)) with f (*‹∀n. f n ∈ S›*) show "∃l∈S. ∃r. strict_mono r ∧ (f ∘ r) ⇢ l" by auto next (*goal: ‹infinite (range f) ⟹ ∃l∈S. ∃r. strict_mono r ∧ (f ∘ r) ⇢ l›*) case False (*‹infinite (range f)›*) with f (*‹∀n. f n ∈ S›*) assms (*‹⟦infinite ?T; countable ?T; ?T ⊆ S⟧ ⟹ ∃x∈S. ∀U. x ∈ U ∧ open U ⟶ infinite (U ∩ ?T)›*) obtain l where "l ∈ S" "∀U. l∈U ∧ open U ⟶ infinite (U ∩ range f)" (*goal: ‹(⋀l. ⟦l ∈ S; ∀U. l ∈ U ∧ open U ⟶ infinite (U ∩ range f)⟧ ⟹ thesis) ⟹ thesis›*) by (metis image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*) uncountable_def (*‹uncountable ?A = (?A ≠ {} ∧ (∄f. range f = ?A))›*)) with ‹l ∈ S› (*‹(l::'a) ∈ (S::'a set)›*) show "∃l∈S. ∃r. strict_mono r ∧ ((f ∘ r) ⤏ l) sequentially" by (meson acc_point_range_imp_convergent_subsequence (*‹∀U. ?l ∈ U ⟶ open U ⟶ infinite (U ∩ range ?f) ⟹ ∃r. strict_mono r ∧ (?f ∘ r) ⇢ ?l›*)) qed qed lemma seq_compact_eq_countably_compact: fixes U :: "'a :: first_countable_topology set" shows "seq_compact U ⟷ countably_compact U" by (metis countable_acc_point_imp_seq_compact (*‹(⋀T. ⟦infinite T; countable T; T ⊆ ?S⟧ ⟹ ∃x∈?S. ∀U. x ∈ U ∧ open U ⟶ infinite (U ∩ T)) ⟹ seq_compact ?S›*) countably_compact_imp_acc_point (*‹⟦countably_compact ?S; countable ?T; infinite ?T; ?T ⊆ ?S⟧ ⟹ ∃x∈?S. ∀U. x ∈ U ∧ open U ⟶ infinite (U ∩ ?T)›*) seq_compact_imp_countably_compact (*‹seq_compact ?U ⟹ countably_compact ?U›*)) lemma seq_compact_eq_acc_point: fixes S :: "'a :: first_countable_topology set" shows "seq_compact S ⟷ (∀T. infinite T ∧ countable T ∧ T ⊆ S --> (∃x∈S. ∀U. x∈U ∧ open U ⟶ infinite (U ∩ T)))" by (metis countable_acc_point_imp_seq_compact (*‹(⋀T. ⟦infinite T; countable T; T ⊆ ?S⟧ ⟹ ∃x∈?S. ∀U. x ∈ U ∧ open U ⟶ infinite (U ∩ T)) ⟹ seq_compact ?S›*) countably_compact_imp_acc_point (*‹⟦countably_compact ?S; countable ?T; infinite ?T; ?T ⊆ ?S⟧ ⟹ ∃x∈?S. ∀U. x ∈ U ∧ open U ⟶ infinite (U ∩ ?T)›*) seq_compact_imp_countably_compact (*‹seq_compact ?U ⟹ countably_compact ?U›*)) lemma seq_compact_eq_compact: fixes U :: "'a :: second_countable_topology set" shows "seq_compact U ⟷ compact U" using seq_compact_eq_countably_compact (*‹seq_compact ?U = countably_compact ?U›*) countably_compact_eq_compact (*‹countably_compact ?U = compact ?U›*) by blast proposition Bolzano_Weierstrass_imp_seq_compact: fixes S :: "'a::{t1_space, first_countable_topology} set" shows "(⋀T. ⟦infinite T; T ⊆ S⟧ ⟹∃x ∈ S. x islimpt T) ⟹ seq_compact S" apply (rule countable_acc_point_imp_seq_compact (*‹(⋀T. ⟦infinite T; countable T; T ⊆ ?S⟧ ⟹ ∃x∈?S. ∀U. x ∈ U ∧ open U ⟶ infinite (U ∩ T)) ⟹ seq_compact ?S›*)) (*goal: ‹(⋀T. ⟦infinite T; T ⊆ S⟧ ⟹ ∃x∈S. x islimpt T) ⟹ seq_compact S›*) by (metis islimpt_eq_acc_point (*‹?l islimpt ?S = (∀U. ?l ∈ U ⟶ open U ⟶ infinite (U ∩ ?S))›*)) subsection✐‹tag unimportant› ‹Cartesian products› lemma seq_compact_Times: assumes "seq_compact S" "seq_compact T" shows "seq_compact (S × T)" unfolding seq_compact_def (*goal: ‹∀f::nat ⇒ 'a × 'b. (∀n::nat. f n ∈ (S::'a set) × (T::'b set)) ⟶ (∃l::'a × 'b∈S × T. ∃r::nat ⇒ nat. strict_mono r ∧ (f ∘ r) ⇢ l)›*) proof (clarify) (*goal: ‹⋀f::nat ⇒ 'a × 'b. ∀n::nat. f n ∈ (S::'a set) × (T::'b set) ⟹ ∃l::'a × 'b∈S × T. ∃r::nat ⇒ nat. strict_mono r ∧ (f ∘ r) ⇢ l›*) fix h :: "nat ⇒ 'a × 'b" assume "∀n. h n ∈ S × T" (*‹∀n::nat. (h::nat ⇒ 'a × 'b) n ∈ (S::'a set) × (T::'b set)›*) then have "*": "⋀n. (fst ∘ h) n ∈ S" "⋀n. (snd ∘ h) n ∈ T" apply - (*goals: 1. ‹⋀n. ∀n. h n ∈ S × T ⟹ (fst ∘ h) n ∈ S› 2. ‹⋀n. ∀n. h n ∈ S × T ⟹ (snd ∘ h) n ∈ T› discuss goal 1*) apply (simp add: mem_Times_iff (*‹(?x ∈ ?A × ?B) = (fst ?x ∈ ?A ∧ snd ?x ∈ ?B)›*)) (*discuss goal 2*) apply (simp add: mem_Times_iff (*‹(?x ∈ ?A × ?B) = (fst ?x ∈ ?A ∧ snd ?x ∈ ?B)›*)) (*proven 2 subgoals*) . then obtain lS and rS :: "nat⇒nat" where "lS∈S" "strict_mono rS" and lS: "(fst ∘ h ∘ rS) ⇢ lS" (*goal: ‹(⋀(lS::'a::topological_space) rS::nat ⇒ nat. ⟦lS ∈ (S::'a::topological_space set); strict_mono rS; (fst ∘ (h::nat ⇒ 'a::topological_space × 'b::topological_space) ∘ rS) ⇢ lS⟧ ⟹ thesis::bool) ⟹ thesis›*) using assms (*‹seq_compact S› ‹seq_compact T›*) seq_compact_def (*‹seq_compact (?S::?'a set) = (∀f::nat ⇒ ?'a. (∀n::nat. f n ∈ ?S) ⟶ (∃l::?'a∈?S. ∃r::nat ⇒ nat. strict_mono r ∧ (f ∘ r) ⇢ l))›*) by metis then obtain lT and rT :: "nat⇒nat" where "lT∈T" "strict_mono rT" and lT: "(snd ∘ h ∘ rS ∘ rT) ⇢ lT" (*goal: ‹(⋀lT rT. ⟦lT ∈ T; strict_mono rT; (snd ∘ h ∘ rS ∘ rT) ⇢ lT⟧ ⟹ thesis) ⟹ thesis›*) using assms (*‹seq_compact S› ‹seq_compact (T::'b set)›*) seq_compact_def (*‹seq_compact ?S = (∀f. (∀n. f n ∈ ?S) ⟶ (∃l∈?S. ∃r. strict_mono r ∧ (f ∘ r) ⇢ l))›*) "*" (*‹(fst ∘ (h::nat ⇒ 'a × 'b)) (?n::nat) ∈ (S::'a set)› ‹(snd ∘ h) ?n ∈ T›*) by (metis (mono_tags, lifting) comp_apply (*‹(?f ∘ ?g) ?x = ?f (?g ?x)›*)) have "strict_mono (rS ∘ rT)" by (simp add: ‹strict_mono rS› ‹strict_mono rT› strict_mono_o (*‹⟦strict_mono ?r; strict_mono ?s⟧ ⟹ strict_mono (?r ∘ ?s)›*)) moreover have "(h ∘ (rS ∘ rT)) ⇢ (lS,lT)" using tendsto_Pair[OF LIMSEQ_subseq_LIMSEQ [ OF lS ‹strict_mono rT› ] lT] (*‹(λx::nat. ((fst ∘ (h::nat ⇒ 'a × 'b) ∘ (rS::nat ⇒ nat) ∘ (rT::nat ⇒ nat)) x, (snd ∘ h ∘ rS ∘ rT) x)) ⇢ (lS::'a, lT::'b)›*) by (simp add: o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*)) ultimately show "∃l∈S × T. ∃r. strict_mono r ∧ (h ∘ r) ⇢ l" using ‹lS ∈ S› (*‹lS ∈ S›*) ‹lT ∈ T› (*‹(lT::'b::topological_space) ∈ (T::'b::topological_space set)›*) by blast qed lemma compact_Times: assumes "compact S" "compact T" shows "compact (S × T)" proof (rule compactI (*‹(⋀C. ⟦∀t∈C. open t; ?s ⊆ ⋃ C⟧ ⟹ ∃C'⊆C. finite C' ∧ ?s ⊆ ⋃ C') ⟹ compact ?s›*)) (*goal: ‹⋀C. ⟦∀t∈C. open t; S × T ⊆ ⋃ C⟧ ⟹ ∃C'⊆C. finite C' ∧ S × T ⊆ ⋃ C'›*) fix 𝒞 assume C: "∀T∈𝒞. open T" "S × T ⊆ ⋃𝒞" (*‹∀T::('a × 'b) set∈𝒞::('a × 'b) set set. open T› ‹(S::'a set) × (T::'b set) ⊆ ⋃ (𝒞::('a × 'b) set set)›*) have "∀x∈S. ∃A. open A ∧ x ∈ A ∧ (∃D⊆𝒞. finite D ∧ A × T ⊆ ⋃D)" proof (standard) (*goal: ‹⋀x. x ∈ S ⟹ ∃A. open A ∧ x ∈ A ∧ (∃D⊆𝒞. finite D ∧ A × T ⊆ ⋃ D)›*) fix x assume "x ∈ S" (*‹(x::'a) ∈ (S::'a set)›*) have "∀y∈T. ∃A B C. C ∈ 𝒞 ∧ open A ∧ open B ∧ x ∈ A ∧ y ∈ B ∧ A × B ⊆ C" by (smt (verit, ccfv_threshold) C (*‹∀T::('a × 'b) set∈𝒞::('a × 'b) set set. open T› ‹(S::'a set) × (T::'b set) ⊆ ⋃ (𝒞::('a × 'b) set set)›*) UnionE (*‹⟦(?A::?'a) ∈ ⋃ (?C::?'a set set); ⋀X::?'a set. ⟦?A ∈ X; X ∈ ?C⟧ ⟹ ?R::bool⟧ ⟹ ?R›*) ‹x ∈ S› mem_Sigma_iff (*‹((?a::?'a, ?b::?'b) ∈ Sigma (?A::?'a set) (?B::?'a ⇒ ?'b set)) = (?a ∈ ?A ∧ ?b ∈ ?B ?a)›*) open_prod_def (*‹open (?S::(?'a × ?'b) set) = (∀x::?'a × ?'b∈?S. ∃(A::?'a set) B::?'b set. open A ∧ open B ∧ x ∈ A × B ∧ A × B ⊆ ?S)›*) subsetD (*‹⟦(?A::?'a set) ⊆ (?B::?'a set); (?c::?'a) ∈ ?A⟧ ⟹ ?c ∈ ?B›*)) then obtain a and b and c where b: "⋀y. y ∈ T ⟹ open (b y)" and c: "⋀y. y ∈ T ⟹ c y ∈ 𝒞 ∧ open (a y) ∧ open (b y) ∧ x ∈ a y ∧ y ∈ b y ∧ a y × b y ⊆ c y" (*goal: ‹(⋀b c a. ⟦⋀y. y ∈ T ⟹ open (b y); ⋀y. y ∈ T ⟹ c y ∈ 𝒞 ∧ open (a y) ∧ open (b y) ∧ x ∈ a y ∧ y ∈ b y ∧ a y × b y ⊆ c y⟧ ⟹ thesis) ⟹ thesis›*) by metis then have "∀y∈T. open (b y)" "T ⊆ (⋃y∈T. b y)" apply - (*goals: 1. ‹⟦⋀y::'b. y ∈ (T::'b set) ⟹ open ((b::'b ⇒ 'b set) y); ⋀y::'b. y ∈ T ⟹ (c::'b ⇒ ('a × 'b) set) y ∈ (𝒞::('a × 'b) set set) ∧ open ((a::'b ⇒ 'a set) y) ∧ open (b y) ∧ (x::'a) ∈ a y ∧ y ∈ b y ∧ a y × b y ⊆ c y⟧ ⟹ ∀y::'b∈T. open (b y)› 2. ‹⟦⋀y::'b. y ∈ (T::'b set) ⟹ open ((b::'b ⇒ 'b set) y); ⋀y::'b. y ∈ T ⟹ (c::'b ⇒ ('a × 'b) set) y ∈ (𝒞::('a × 'b) set set) ∧ open ((a::'b ⇒ 'a set) y) ∧ open (b y) ∧ (x::'a) ∈ a y ∧ y ∈ b y ∧ a y × b y ⊆ c y⟧ ⟹ T ⊆ ⋃ (b ` T)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . with compactE_image[OF ‹compact T›] (*‹⟦⋀T. T ∈ ?C ⟹ open (?f T); T ⊆ ⋃ (?f ` ?C); ⋀C'. ⟦C' ⊆ ?C; finite C'; T ⊆ ⋃ (?f ` C')⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) obtain D where D: "D ⊆ T" "finite D" "T ⊆ (⋃y∈D. b y)" (*goal: ‹(⋀D. ⟦D ⊆ T; finite D; T ⊆ ⋃ (b ` D)⟧ ⟹ thesis) ⟹ thesis›*) by metis moreover from D (*‹(D::'b set) ⊆ (T::'b set)› ‹finite D› ‹T ⊆ ⋃ (b ` D)›*) c (*‹(?y::'b::topological_space) ∈ (T::'b::topological_space set) ⟹ (c::'b::topological_space ⇒ ('a::topological_space × 'b::topological_space) set) ?y ∈ (𝒞::('a::topological_space × 'b::topological_space) set set) ∧ open ((a::'b::topological_space ⇒ 'a::topological_space set) ?y) ∧ open ((b::'b::topological_space ⇒ 'b::topological_space set) ?y) ∧ (x::'a::topological_space) ∈ a ?y ∧ ?y ∈ b ?y ∧ a ?y × b ?y ⊆ c ?y›*) have "(⋂y∈D. a y) × T ⊆ (⋃y∈D. c y)" by (fastforce simp: subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*)) ultimately show "∃a. open a ∧ x ∈ a ∧ (∃d⊆𝒞. finite d ∧ a × T ⊆ ⋃d)" using c (*‹(?y::'b::topological_space) ∈ (T::'b::topological_space set) ⟹ (c::'b::topological_space ⇒ ('a::topological_space × 'b::topological_space) set) ?y ∈ (𝒞::('a::topological_space × 'b::topological_space) set set) ∧ open ((a::'b::topological_space ⇒ 'a::topological_space set) ?y) ∧ open ((b::'b::topological_space ⇒ 'b::topological_space set) ?y) ∧ (x::'a::topological_space) ∈ a ?y ∧ ?y ∈ b ?y ∧ a ?y × b ?y ⊆ c ?y›*) apply (intro exI[of _ "c`D"] (*‹?P (c ` D) ⟹ ∃x. ?P x›*) exI[of _ "⋂(a`D)"] (*‹?P (⋂ (a ` D)) ⟹ ∃x. ?P x›*) conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹⟦D ⊆ T; finite D; T ⊆ ⋃ (b ` D); ⋂ (a ` D) × T ⊆ ⋃ (c ` D); ⋀y. y ∈ T ⟹ c y ∈ 𝒞 ∧ open (a y) ∧ open (b y) ∧ x ∈ a y ∧ y ∈ b y ∧ a y × b y ⊆ c y⟧ ⟹ open (⋂ (a ` D))› 2. ‹⟦D ⊆ T; finite D; T ⊆ ⋃ (b ` D); ⋂ (a ` D) × T ⊆ ⋃ (c ` D); ⋀y. y ∈ T ⟹ c y ∈ 𝒞 ∧ open (a y) ∧ open (b y) ∧ x ∈ a y ∧ y ∈ b y ∧ a y × b y ⊆ c y⟧ ⟹ x ∈ ⋂ (a ` D)› 3. ‹⟦D ⊆ T; finite D; T ⊆ ⋃ (b ` D); ⋂ (a ` D) × T ⊆ ⋃ (c ` D); ⋀y. y ∈ T ⟹ c y ∈ 𝒞 ∧ open (a y) ∧ open (b y) ∧ x ∈ a y ∧ y ∈ b y ∧ a y × b y ⊆ c y⟧ ⟹ c ` D ⊆ 𝒞› 4. ‹⟦D ⊆ T; finite D; T ⊆ ⋃ (b ` D); ⋂ (a ` D) × T ⊆ ⋃ (c ` D); ⋀y. y ∈ T ⟹ c y ∈ 𝒞 ∧ open (a y) ∧ open (b y) ∧ x ∈ a y ∧ y ∈ b y ∧ a y × b y ⊆ c y⟧ ⟹ finite (c ` D)› 5. ‹⟦D ⊆ T; finite D; T ⊆ ⋃ (b ` D); ⋂ (a ` D) × T ⊆ ⋃ (c ` D); ⋀y. y ∈ T ⟹ c y ∈ 𝒞 ∧ open (a y) ∧ open (b y) ∧ x ∈ a y ∧ y ∈ b y ∧ a y × b y ⊆ c y⟧ ⟹ ⋂ (a ` D) × T ⊆ ⋃ (c ` D)› discuss goal 1*) apply ((auto intro!: open_INT (*‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))›*))[1]) (*discuss goal 2*) apply ((auto intro!: open_INT (*‹⟦finite (?A::?'b set); ∀x::?'b∈?A. open ((?B::?'b ⇒ ?'a set) x)⟧ ⟹ open (⋂ (?B ` ?A))›*))[1]) (*discuss goal 3*) apply ((auto intro!: open_INT (*‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))›*))[1]) (*discuss goal 4*) apply ((auto intro!: open_INT (*‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))›*))[1]) (*discuss goal 5*) apply ((auto intro!: open_INT (*‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))›*))[1]) (*proven 5 subgoals*) . qed then obtain a and d where a: "⋀x. x∈S ⟹ open (a x)" "S ⊆ (⋃x∈S. a x)" and d: "⋀x. x ∈ S ⟹ d x ⊆ 𝒞 ∧ finite (d x) ∧ a x × T ⊆ ⋃(d x)" (*goal: ‹(⋀(a::'a::topological_space ⇒ 'a::topological_space set) d::'a::topological_space ⇒ ('a::topological_space × 'b::topological_space) set set. ⟦⋀x::'a::topological_space. x ∈ (S::'a::topological_space set) ⟹ open (a x); S ⊆ ⋃ (a ` S); ⋀x::'a::topological_space. x ∈ S ⟹ d x ⊆ (𝒞::('a::topological_space × 'b::topological_space) set set) ∧ finite (d x) ∧ a x × (T::'b::topological_space set) ⊆ ⋃ (d x)⟧ ⟹ thesis::bool) ⟹ thesis›*) unfolding subset_eq UN_iff (*goal: ‹(⋀a d. ⟦⋀x. x ∈ S ⟹ open (a x); ∀x∈S. ∃xa∈S. x ∈ a xa; ⋀x. x ∈ S ⟹ (∀x∈d x. x ∈ 𝒞) ∧ finite (d x) ∧ (∀xa∈a x × T. xa ∈ ⋃ (d x))⟧ ⟹ thesis) ⟹ thesis›*) by metis moreover from compactE_image[OF ‹compact S› a] (*‹⟦⋀T. T ∈ S ⟹ T ∈ S; ⋀C'. ⟦C' ⊆ S; finite C'; S ⊆ ⋃ (a ` C')⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) obtain e where e: "e ⊆ S" "finite e" and S: "S ⊆ (⋃x∈e. a x)" (*goal: ‹(⋀e. ⟦e ⊆ S; finite e; S ⊆ ⋃ (a ` e)⟧ ⟹ thesis) ⟹ thesis›*) by auto moreover have "S × T ⊆ (⋃x∈e. ⋃(d x))" by (smt (verit, del_insts) S (*‹S ⊆ ⋃ (a ` e)›*) SigmaE (*‹⟦?c ∈ Sigma ?A ?B; ⋀x y. ⟦x ∈ ?A; y ∈ ?B x; ?c = (x, y)⟧ ⟹ ?P⟧ ⟹ ?P›*) UN_iff (*‹(?b ∈ ⋃ (?B ` ?A)) = (∃x∈?A. ?b ∈ ?B x)›*) d (*‹?x ∈ S ⟹ d ?x ⊆ 𝒞 ∧ finite (d ?x) ∧ a ?x × T ⊆ ⋃ (d ?x)›*) e( (*‹e ⊆ S›*) 1) mem_Sigma_iff (*‹((?a, ?b) ∈ Sigma ?A ?B) = (?a ∈ ?A ∧ ?b ∈ ?B ?a)›*) subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*)) ultimately show "∃C'⊆𝒞. finite C' ∧ S × T ⊆ ⋃C'" apply (intro exI[of _ "(⋃x∈e. d x)"] (*‹?P (⋃ (d ` e)) ⟹ ∃x. ?P x›*)) (*goal: ‹∃C'⊆𝒞. finite C' ∧ S × T ⊆ ⋃ C'›*) by (auto simp: subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*)) qed lemma tube_lemma: assumes "compact K" assumes "open W" assumes "{x0} × K ⊆ W" shows "∃X0. x0 ∈ X0 ∧ open X0 ∧ X0 × K ⊆ W" proof (-) (*goal: ‹∃X0. x0 ∈ X0 ∧ open X0 ∧ X0 × K ⊆ W›*) { fix y assume "y ∈ K" (*‹(y::'a) ∈ (K::'a set)›*) then have "(x0, y) ∈ W" using assms (*‹compact K› ‹open (W::('b::topological_space × 'a::topological_space) set)› ‹{x0} × K ⊆ W›*) by auto with ‹open W› (*‹open (W::('b × 'a) set)›*) have "∃X0 Y. open X0 ∧ open Y ∧ x0 ∈ X0 ∧ y ∈ Y ∧ X0 × Y ⊆ W" apply (rule open_prod_elim (*‹⟦open ?S; ?x ∈ ?S; ⋀A B. ⟦open A; open B; ?x ∈ A × B; A × B ⊆ ?S⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) (*goal: ‹∃(X0::'b set) Y::'a set. open X0 ∧ open Y ∧ (x0::'b) ∈ X0 ∧ (y::'a) ∈ Y ∧ X0 × Y ⊆ (W::('b × 'a) set)›*) by blast } then obtain X0 and Y where "*": "∀y ∈ K. open (X0 y) ∧ open (Y y) ∧ x0 ∈ X0 y ∧ y ∈ Y y ∧ X0 y × Y y ⊆ W" (*goal: ‹(⋀X0 Y. ∀y∈K. open (X0 y) ∧ open (Y y) ∧ x0 ∈ X0 y ∧ y ∈ Y y ∧ X0 y × Y y ⊆ W ⟹ thesis) ⟹ thesis›*) by metis from "*" (*‹∀y∈K. open (X0 y) ∧ open (Y y) ∧ x0 ∈ X0 y ∧ y ∈ Y y ∧ X0 y × Y y ⊆ W›*) have "∀t∈Y ` K. open t" "K ⊆ ⋃(Y ` K)" apply - (*goals: 1. ‹∀y∈K. open (X0 y) ∧ open (Y y) ∧ x0 ∈ X0 y ∧ y ∈ Y y ∧ X0 y × Y y ⊆ W ⟹ ∀t∈Y ` K. open t› 2. ‹∀y∈K. open (X0 y) ∧ open (Y y) ∧ x0 ∈ X0 y ∧ y ∈ Y y ∧ X0 y × Y y ⊆ W ⟹ K ⊆ ⋃ (Y ` K)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . with ‹compact K› (*‹compact (K::'a set)›*) obtain CC where CC: "CC ⊆ Y ` K" "finite CC" "K ⊆ ⋃CC" (*goal: ‹(⋀CC::'a set set. ⟦CC ⊆ (Y::'a ⇒ 'a set) ` (K::'a set); finite CC; K ⊆ ⋃ CC⟧ ⟹ thesis::bool) ⟹ thesis›*) by (meson compactE (*‹⟦compact ?S; ?S ⊆ ⋃ ?𝒯; ⋀B. B ∈ ?𝒯 ⟹ open B; ⋀𝒯'. ⟦𝒯' ⊆ ?𝒯; finite 𝒯'; ?S ⊆ ⋃ 𝒯'⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) then obtain c where c: "⋀C. C ∈ CC ⟹ c C ∈ K ∧ C = Y (c C)" (*goal: ‹(⋀c. (⋀C. C ∈ CC ⟹ c C ∈ K ∧ C = Y (c C)) ⟹ thesis) ⟹ thesis›*) by (force intro!: choice (*‹∀x. ∃y. ?Q x y ⟹ ∃f. ∀x. ?Q x (f x)›*)) with "*" (*‹∀y∈K. open (X0 y) ∧ open (Y y) ∧ x0 ∈ X0 y ∧ y ∈ Y y ∧ X0 y × Y y ⊆ W›*) CC (*‹CC ⊆ Y ` K› ‹finite (CC::'a set set)› ‹K ⊆ ⋃ CC›*) show "?thesis" (*goal: ‹∃X0. x0 ∈ X0 ∧ open X0 ∧ X0 × K ⊆ W›*) by (force intro!: exI[where x="⋂C∈CC. X0 (c C)"] (*‹?P (⋂C∈CC. X0 (c C)) ⟹ ∃x. ?P x›*)) qed lemma continuous_on_prod_compactE: fixes fx::"'a::topological_space × 'b::topological_space ⇒ 'c::metric_space" and e::real assumes cont_fx: "continuous_on (U × C) fx" assumes "compact C" assumes [intro]: "x0 ∈ U" notes [continuous_intros] = continuous_on_compose2[OF cont_fx] assumes "e > 0" obtains X0 where "x0 ∈ X0" "open X0" "∀x∈X0 ∩ U. ∀t ∈ C. dist (fx (x, t)) (fx (x0, t)) ≤ e" proof (-) (*goal: ‹(⋀X0. ⟦x0 ∈ X0; open X0; ∀x∈X0 ∩ U. ∀t∈C. dist (fx (x, t)) (fx (x0, t)) ≤ e⟧ ⟹ thesis) ⟹ thesis›*) define psi where "psi = (λ(x, t). dist (fx (x, t)) (fx (x0, t)))" define W0 where "W0 = {(x, t) ∈ U × C. psi (x, t) < e}" have W0_eq: "W0 = psi -` {..<e} ∩ U × C" by (auto simp: vimage_def (*‹?f -` ?B ≡ {x. ?f x ∈ ?B}›*) W0_def (*‹W0 = {(x, t). (x, t) ∈ U × C ∧ psi (x, t) < e}›*)) have "open {..<e}" by simp have "continuous_on (U × C) psi" by (auto intro!: continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 140 facts*) simp: psi_def (*‹psi = (λ(x, t). dist (fx (x, t)) (fx (x0, t)))›*) split_beta' (*‹(λ(x, y). ?f x y) = (λx. ?f (fst x) (snd x))›*)) then obtain W where W: "open W" "W ∩ U × C = W0 ∩ U × C" (*goal: ‹(⋀W. ⟦open W; W ∩ U × C = W0 ∩ U × C⟧ ⟹ thesis) ⟹ thesis›*) unfolding W0_eq (*goal: ‹(⋀W. ⟦open W; W ∩ U × C = psi -` {..<e} ∩ U × C ∩ U × C⟧ ⟹ thesis) ⟹ thesis›*) by (metis ‹open {..<e}› continuous_on_open_invariant (*‹continuous_on ?s ?f = (∀B. open B ⟶ (∃A. open A ∧ A ∩ ?s = ?f -` B ∩ ?s))›*) inf_right_idem (*‹inf (inf ?x ?y) ?y = inf ?x ?y›*)) have "{x0} × C ⊆ W ∩ U × C" unfolding W (*goal: ‹{x0::'a::topological_space} × (C::'b::topological_space set) ⊆ (W0::('a::topological_space × 'b::topological_space) set) ∩ (U::'a::topological_space set) × C›*) by (auto simp: W0_def (*‹W0 = {(x, t). (x, t) ∈ U × C ∧ psi (x, t) < e}›*) psi_def (*‹psi = (λ(x, t). dist (fx (x, t)) (fx (x0, t)))›*) ‹0 < e›) then have "{x0} × C ⊆ W" by blast from tube_lemma[OF ‹compact C› ‹open W› this] (*‹∃X0::'a set. (x0::'a) ∈ X0 ∧ open X0 ∧ X0 × (C::'b set) ⊆ (W::('a × 'b) set)›*) obtain X0 where X0: "x0 ∈ X0" "open X0" "X0 × C ⊆ W" (*goal: ‹(⋀X0. ⟦x0 ∈ X0; open X0; X0 × C ⊆ W⟧ ⟹ thesis) ⟹ thesis›*) by blast have "∀x∈X0 ∩ U. ∀t ∈ C. dist (fx (x, t)) (fx (x0, t)) ≤ e" proof (safe) (*goal: ‹⋀(x::'a) t::'b. ⟦x ∈ (X0::'a set); x ∈ (U::'a set); t ∈ (C::'b set)⟧ ⟹ dist ((fx::'a × 'b ⇒ 'c) (x, t)) (fx (x0::'a, t)) ≤ (e::real)›*) fix x assume x: "x ∈ X0" "x ∈ U" (*‹(x::'a) ∈ (X0::'a set)› ‹(x::'a) ∈ (U::'a set)›*) fix t assume t: "t ∈ C" (*‹(t::'b) ∈ (C::'b set)›*) have "dist (fx (x, t)) (fx (x0, t)) = psi (x, t)" by (auto simp: psi_def (*‹psi = (λ(x, t). dist (fx (x, t)) (fx (x0, t)))›*)) also (*calculation: ‹dist (fx (x, t)) (fx (x0, t)) = psi (x, t)›*) have "psi (x, t) < e" using W(2) (*‹(W::('a × 'b) set) ∩ (U::'a set) × (C::'b set) = (W0::('a × 'b) set) ∩ U × C›*) W0_def (*‹W0 = {(x, t). (x, t) ∈ U × C ∧ psi (x, t) < e}›*) X0(3) (*‹X0 × C ⊆ W›*) t (*‹t ∈ C›*) x (*‹x ∈ X0› ‹x ∈ U›*) by fastforce finally (*calculation: ‹dist (fx (x, t)) (fx (x0, t)) < e›*) show "dist (fx (x,t)) (fx (x0,t)) ≤ e" by simp qed from X0(1,2) (*‹x0 ∈ X0› ‹open (X0::'a set)›*) this (*‹∀x∈X0 ∩ U. ∀t∈C. dist (fx (x, t)) (fx (x0, t)) ≤ e›*) show "?thesis" (*goal: ‹thesis::bool›*) by standard qed subsection ‹Continuity› lemma continuous_at_imp_continuous_within: "continuous (at x) f ⟹ continuous (at x within s) f" unfolding continuous_within continuous_at (*goal: ‹f ─x→ f x ⟹ (f ⤏ f x) (at x within s)›*) using Lim_at_imp_Lim_at_within (*‹(?f::?'a::topological_space ⇒ ?'b::topological_space) ─?x::?'a::topological_space→ (?l::?'b::topological_space) ⟹ (?f ⤏ ?l) (at ?x within (?S::?'a::topological_space set))›*) by auto lemma Lim_trivial_limit: "trivial_limit net ⟹ (f ⤏ l) net" by simp lemmas continuous_on = continuous_on_def ― ‹legacy theorem name› lemma continuous_within_subset: "continuous (at x within S) f ⟹ t ⊆ S ⟹ continuous (at x within t) f" unfolding continuous_within (*goal: ‹⟦(f ⤏ f x) (at x within S); t ⊆ S⟧ ⟹ (f ⤏ f x) (at x within t)›*) by (metis tendsto_within_subset (*‹⟦filterlim ?f ?l (at ?x within ?S); ?T ⊆ ?S⟧ ⟹ filterlim ?f ?l (at ?x within ?T)›*)) lemma continuous_on_interior: "continuous_on S f ⟹ x ∈ interior S ⟹ continuous (at x) f" by (metis continuous_on_eq_continuous_at (*‹open (?s::?'a::t2_space set) ⟹ continuous_on ?s (?f::?'a::t2_space ⇒ ?'b::topological_space) = (∀x::?'a::t2_space∈?s. isCont ?f x)›*) continuous_on_subset (*‹⟦continuous_on (?s::?'a::topological_space set) (?f::?'a::topological_space ⇒ ?'b::topological_space); (?t::?'a::topological_space set) ⊆ ?s⟧ ⟹ continuous_on ?t ?f›*) interiorE (*‹⟦(?x::?'a::topological_space) ∈ interior (?S::?'a::topological_space set); ⋀T::?'a::topological_space set. ⟦open T; ?x ∈ T; T ⊆ ?S⟧ ⟹ ?thesis::bool⟧ ⟹ ?thesis›*)) lemma continuous_on_eq: "⟦continuous_on S f; ⋀x. x ∈ S ⟹ f x = g x⟧ ⟹ continuous_on S g" unfolding continuous_on_def tendsto_def eventually_at_topological (*goal: ‹⟦∀x::'a∈S::'a set. ∀Sa::'b set. open Sa ⟶ (f::'a ⇒ 'b) x ∈ Sa ⟶ (∃Sb::'a set. open Sb ∧ x ∈ Sb ∧ (∀xa::'a∈Sb. xa ≠ x ⟶ xa ∈ S ⟶ f xa ∈ Sa)); ⋀x::'a. x ∈ S ⟹ f x = (g::'a ⇒ 'b) x⟧ ⟹ ∀x::'a∈S. ∀Sa::'b set. open Sa ⟶ g x ∈ Sa ⟶ (∃Sb::'a set. open Sb ∧ x ∈ Sb ∧ (∀xa::'a∈Sb. xa ≠ x ⟶ xa ∈ S ⟶ g xa ∈ Sa))›*) by simp text ‹Characterization of various kinds of continuity in terms of sequences.› lemma continuous_within_sequentiallyI: fixes f :: "'a::{first_countable_topology, t2_space} ⇒ 'b::topological_space" assumes "⋀u::nat ⇒ 'a. u ⇢ a ⟹ (∀n. u n ∈ S) ⟹ (λn. f (u n)) ⇢ f a" shows "continuous (at a within S) f" using assms (*‹⟦?u ⇢ a; ∀n. ?u n ∈ S⟧ ⟹ (λn. f (?u n)) ⇢ f a›*) unfolding continuous_within tendsto_def[where l = "f a"] (*goal: ‹∀Sa. open Sa ⟶ f a ∈ Sa ⟶ (∀⇩F x in at a within S. f x ∈ Sa)›*) by (auto intro!: sequentially_imp_eventually_within (*‹∀f. (∀n. f n ∈ ?s ∧ f n ≠ ?a) ∧ f ⇢ ?a ⟶ (∀⇩F n in sequentially. ?P (f n)) ⟹ eventually ?P (at ?a within ?s)›*)) lemma continuous_within_tendsto_compose: fixes f::"'a::t2_space ⇒ 'b::topological_space" assumes f: "continuous (at a within S) f" and "eventually (λn. x n ∈ S) F" "(x ⤏ a) F " shows "((λn. f (x n)) ⤏ f a) F" proof (-) (*goal: ‹((λn. f (x n)) ⤏ f a) F›*) have "*": "filterlim x (inf (nhds a) (principal S)) F" by (simp add: assms (*‹continuous (at a within S) f› ‹∀⇩F n in F. x n ∈ S› ‹(x ⤏ a) F›*) filterlim_inf (*‹filterlim ?f (inf ?F2.0 ?F3.0) ?F1.0 = (filterlim ?f ?F2.0 ?F1.0 ∧ filterlim ?f ?F3.0 ?F1.0)›*) filterlim_principal (*‹filterlim ?f (principal ?S) ?F = (∀⇩F x in ?F. ?f x ∈ ?S)›*)) show "?thesis" (*goal: ‹((λn. f (x n)) ⤏ f a) F›*) using "*" (*‹filterlim x (inf (nhds a) (principal S)) F›*) f (*‹continuous (at a within S) f›*) continuous_within (*‹continuous (at ?x within ?s) ?f = (?f ⤏ ?f ?x) (at ?x within ?s)›*) filterlim_compose (*‹⟦filterlim ?g ?F3.0 ?F2.0; filterlim ?f ?F2.0 ?F1.0⟧ ⟹ LIM x ?F1.0. ?g (?f x) :> ?F3.0›*) tendsto_at_within_iff_tendsto_nhds (*‹(?g ⤏ ?g ?l) (at ?l within ?S) = (?g ⤏ ?g ?l) (inf (nhds ?l) (principal ?S))›*) by blast qed lemma continuous_within_tendsto_compose': fixes f::"'a::t2_space ⇒ 'b::topological_space" assumes "continuous (at a within S) f" "⋀n. x n ∈ S" "(x ⤏ a) F " shows "((λn. f (x n)) ⤏ f a) F" using always_eventually (*‹∀x. ?P x ⟹ eventually ?P ?F›*) assms (*‹continuous (at a within S) f› ‹(x::'c ⇒ 'a) (?n::'c) ∈ (S::'a set)› ‹(x ⤏ a) F›*) continuous_within_tendsto_compose (*‹⟦continuous (at (?a::?'a) within (?S::?'a set)) (?f::?'a ⇒ ?'b); ∀⇩F n::?'c in ?F::?'c filter. (?x::?'c ⇒ ?'a) n ∈ ?S; (?x ⤏ ?a) ?F⟧ ⟹ ((λn::?'c. ?f (?x n)) ⤏ ?f ?a) ?F›*) by blast lemma continuous_within_sequentially: fixes f :: "'a::{first_countable_topology, t2_space} ⇒ 'b::topological_space" shows "continuous (at a within S) f ⟷ (∀x. (∀n::nat. x n ∈ S) ∧ (x ⤏ a) sequentially ⟶ ((f ∘ x) ⤏ f a) sequentially)" using continuous_within_tendsto_compose'[of a S f _ sequentially] (*‹⟦continuous (at a within S) f; ⋀n. ?x n ∈ S; ?x ⇢ a⟧ ⟹ (λn. f (?x n)) ⇢ f a›*) continuous_within_sequentiallyI[of a S f] (*‹(⋀u::nat ⇒ 'a. ⟦u ⇢ (a::'a); ∀n::nat. u n ∈ (S::'a set)⟧ ⟹ (λn::nat. (f::'a ⇒ 'b) (u n)) ⇢ f a) ⟹ continuous (at a within S) f›*) by (auto simp: o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*)) lemma continuous_at_sequentiallyI: fixes f :: "'a::{first_countable_topology, t2_space} ⇒ 'b::topological_space" assumes "⋀u. u ⇢ a ⟹ (λn. f (u n)) ⇢ f a" shows "continuous (at a) f" using continuous_within_sequentiallyI[of a UNIV f] (*‹(⋀u. ⟦u ⇢ a; ∀n. u n ∈ UNIV⟧ ⟹ (λn. f (u n)) ⇢ f a) ⟹ isCont f a›*) assms (*‹?u ⇢ a ⟹ (λn. f (?u n)) ⇢ f a›*) by auto lemma continuous_at_sequentially: fixes f :: "'a::metric_space ⇒ 'b::topological_space" shows "continuous (at a) f ⟷ (∀x. (x ⤏ a) sequentially --> ((f ∘ x) ⤏ f a) sequentially)" using continuous_within_sequentially[of a UNIV f] (*‹isCont f a = (∀x. (∀n. x n ∈ UNIV) ∧ x ⇢ a ⟶ (f ∘ x) ⇢ f a)›*) by simp lemma continuous_on_sequentiallyI: fixes f :: "'a::{first_countable_topology, t2_space} ⇒ 'b::topological_space" assumes "⋀u a. (∀n. u n ∈ S) ⟹ a ∈ S ⟹ u ⇢ a ⟹ (λn. f (u n)) ⇢ f a" shows "continuous_on S f" using assms (*‹⟦∀n. ?u n ∈ S; ?a ∈ S; ?u ⇢ ?a⟧ ⟹ (λn. f (?u n)) ⇢ f ?a›*) unfolding continuous_on_eq_continuous_within (*goal: ‹∀x∈S. continuous (at x within S) f›*) using continuous_within_sequentiallyI[of _ S f] (*‹(⋀u::nat ⇒ 'a. ⟦u ⇢ (?a::'a); ∀n::nat. u n ∈ (S::'a set)⟧ ⟹ (λn::nat. (f::'a ⇒ 'b) (u n)) ⇢ f ?a) ⟹ continuous (at ?a within S) f›*) by auto lemma continuous_on_sequentially: fixes f :: "'a::{first_countable_topology, t2_space} ⇒ 'b::topological_space" shows "continuous_on S f ⟷ (∀x. ∀a ∈ S. (∀n. x(n) ∈ S) ∧ (x ⤏ a) sequentially ⟶ ((f ∘ x) ⤏ f a) sequentially)" by (meson continuous_on_eq_continuous_within (*‹continuous_on (?s::?'a::t2_space set) (?f::?'a::t2_space ⇒ ?'b::topological_space) = (∀x::?'a::t2_space∈?s. continuous (at x within ?s) ?f)›*) continuous_within_sequentially (*‹continuous (at (?a::?'a::{first_countable_topology,t2_space}) within (?S::?'a::{first_countable_topology,t2_space} set)) (?f::?'a::{first_countable_topology,t2_space} ⇒ ?'b::topological_space) = (∀x::nat ⇒ ?'a::{first_countable_topology,t2_space}. (∀n::nat. x n ∈ ?S) ∧ x ⇢ ?a ⟶ (?f ∘ x) ⇢ ?f ?a)›*)) text ‹Continuity in terms of open preimages.› lemma continuous_at_open: "continuous (at x) f ⟷ (∀t. open t ∧ f x ∈ t ⟶ (∃S. open S ∧ x ∈ S ∧ (∀x' ∈ S. (f x') ∈ t)))" by (metis UNIV_I (*‹?x ∈ UNIV›*) continuous_within_topological (*‹continuous (at ?x within ?s) ?f = (∀B. open B ⟶ ?f ?x ∈ B ⟶ (∃A. open A ∧ ?x ∈ A ∧ (∀y∈?s. y ∈ A ⟶ ?f y ∈ B)))›*)) lemma continuous_imp_tendsto: assumes "continuous (at x0) f" and "x ⇢ x0" shows "(f ∘ x) ⇢ (f x0)" proof (rule topological_tendstoI (*‹(⋀S. ⟦open S; ?l ∈ S⟧ ⟹ ∀⇩F x in ?F. ?f x ∈ S) ⟹ (?f ⤏ ?l) ?F›*)) (*goal: ‹⋀S. ⟦open S; f x0 ∈ S⟧ ⟹ ∀⇩F xa in sequentially. (f ∘ x) xa ∈ S›*) fix S assume "open S" "f x0 ∈ S" (*‹open (S::'b set)› ‹(f::'a ⇒ 'b) (x0::'a) ∈ (S::'b set)›*) then obtain T where T_def: "open T" "x0 ∈ T" "∀x∈T. f x ∈ S" (*goal: ‹(⋀T. ⟦open T; x0 ∈ T; ∀x∈T. f x ∈ S⟧ ⟹ thesis) ⟹ thesis›*) using assms (*‹isCont f x0› ‹x ⇢ x0›*) continuous_at_open (*‹isCont ?f ?x = (∀t. open t ∧ ?f ?x ∈ t ⟶ (∃S. open S ∧ ?x ∈ S ∧ (∀x'∈S. ?f x' ∈ t)))›*) by metis then have "eventually (λn. x n ∈ T) sequentially" using assms (*‹isCont f x0› ‹x ⇢ x0›*) T_def (*‹open (T::'a set)› ‹x0 ∈ T› ‹∀x∈T. f x ∈ S›*) by (auto simp: tendsto_def (*‹(?f ⤏ ?l) ?F = (∀S. open S ⟶ ?l ∈ S ⟶ (∀⇩F x in ?F. ?f x ∈ S))›*)) then show "eventually (λn. (f ∘ x) n ∈ S) sequentially" using T_def (*‹open T› ‹x0 ∈ T› ‹∀x∈T. f x ∈ S›*) by (auto elim!: eventually_mono (*‹⟦eventually ?P ?F; ⋀x. ?P x ⟹ ?Q x⟧ ⟹ eventually ?Q ?F›*)) qed subsection ‹Homeomorphisms› definition✐‹tag important› "homeomorphism S T f g ⟷ (∀x∈S. (g(f x) = x)) ∧ (f ` S = T) ∧ continuous_on S f ∧ (∀y∈T. (f(g y) = y)) ∧ (g ` T = S) ∧ continuous_on T g" lemma homeomorphismI [intro?]: assumes "continuous_on S f" "continuous_on T g" "f ` S ⊆ T" "g ` T ⊆ S" "⋀x. x ∈ S ⟹ g(f x) = x" "⋀y. y ∈ T ⟹ f(g y) = y" shows "homeomorphism S T f g" using assms (*‹continuous_on S f› ‹continuous_on T g› ‹f ` S ⊆ T› ‹g ` T ⊆ S› ‹?x ∈ S ⟹ g (f ?x) = ?x› ‹(?y::'b::topological_space) ∈ (T::'b::topological_space set) ⟹ (f::'a::topological_space ⇒ 'b::topological_space) ((g::'b::topological_space ⇒ 'a::topological_space) ?y) = ?y›*) by (force simp: homeomorphism_def (*‹homeomorphism ?S ?T ?f ?g = ((∀x∈?S. ?g (?f x) = x) ∧ ?f ` ?S = ?T ∧ continuous_on ?S ?f ∧ (∀y∈?T. ?f (?g y) = y) ∧ ?g ` ?T = ?S ∧ continuous_on ?T ?g)›*)) lemma homeomorphism_translation: fixes a :: "'a :: real_normed_vector" shows "homeomorphism ((+) a ` S) S ((+) (- a)) ((+) a)" unfolding homeomorphism_def (*goal: ‹(∀x∈(+) a ` S. a + (- a + x) = x) ∧ (+) (- a) ` (+) a ` S = S ∧ continuous_on ((+) a ` S) ((+) (- a)) ∧ (∀y∈S. - a + (a + y) = y) ∧ (+) a ` S = (+) a ` S ∧ continuous_on S ((+) a)›*) by (auto simp: algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 15 facts*) continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 139 facts*)) lemma homeomorphism_ident: "homeomorphism T T (λa. a) (λa. a)" apply (rule homeomorphismI (*‹⟦continuous_on ?S ?f; continuous_on ?T ?g; ?f ` ?S ⊆ ?T; ?g ` ?T ⊆ ?S; ⋀x. x ∈ ?S ⟹ ?g (?f x) = x; ⋀y. y ∈ ?T ⟹ ?f (?g y) = y⟧ ⟹ homeomorphism ?S ?T ?f ?g›*)) (*goals: 1. ‹continuous_on T (λa. a)› 2. ‹continuous_on T (λa. a)› 3. ‹(λa. a) ` T ⊆ T› 4. ‹(λa. a) ` T ⊆ T› 5. ‹⋀x. x ∈ T ⟹ x = x› 6. ‹⋀y. y ∈ T ⟹ y = y› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*proven 6 subgoals*) . lemma homeomorphism_compose: assumes "homeomorphism S T f g" "homeomorphism T U h k" shows "homeomorphism S U (h o f) (g o k)" using assms (*‹homeomorphism (S::'a set) (T::'b set) (f::'a ⇒ 'b) (g::'b ⇒ 'a)› ‹homeomorphism T U h k›*) unfolding homeomorphism_def (*goal: ‹(∀x∈S. (g ∘ k) ((h ∘ f) x) = x) ∧ (h ∘ f) ` S = U ∧ continuous_on S (h ∘ f) ∧ (∀y∈U. (h ∘ f) ((g ∘ k) y) = y) ∧ (g ∘ k) ` U = S ∧ continuous_on U (g ∘ k)›*) apply (intro conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*) ballI (*‹(⋀x. x ∈ ?A ⟹ ?P x) ⟹ ∀x∈?A. ?P x›*) continuous_on_compose (*‹⟦continuous_on ?s ?f; continuous_on (?f ` ?s) ?g⟧ ⟹ continuous_on ?s (?g ∘ ?f)›*)) (*goals: 1. ‹⋀x. ⟦(∀x∈S. g (f x) = x) ∧ f ` S = T ∧ continuous_on S f ∧ (∀y∈T. f (g y) = y) ∧ g ` T = S ∧ continuous_on T g; (∀x∈T. k (h x) = x) ∧ h ` T = U ∧ continuous_on T h ∧ (∀y∈U. h (k y) = y) ∧ k ` U = T ∧ continuous_on U k; x ∈ S⟧ ⟹ (g ∘ k) ((h ∘ f) x) = x› 2. ‹⟦(∀x∈S. g (f x) = x) ∧ f ` S = T ∧ continuous_on S f ∧ (∀y∈T. f (g y) = y) ∧ g ` T = S ∧ continuous_on T g; (∀x∈T. k (h x) = x) ∧ h ` T = U ∧ continuous_on T h ∧ (∀y∈U. h (k y) = y) ∧ k ` U = T ∧ continuous_on U k⟧ ⟹ (h ∘ f) ` S = U› 3. ‹⟦(∀x∈S. g (f x) = x) ∧ f ` S = T ∧ continuous_on S f ∧ (∀y∈T. f (g y) = y) ∧ g ` T = S ∧ continuous_on T g; (∀x∈T. k (h x) = x) ∧ h ` T = U ∧ continuous_on T h ∧ (∀y∈U. h (k y) = y) ∧ k ` U = T ∧ continuous_on U k⟧ ⟹ continuous_on S f› 4. ‹⟦(∀x∈S. g (f x) = x) ∧ f ` S = T ∧ continuous_on S f ∧ (∀y∈T. f (g y) = y) ∧ g ` T = S ∧ continuous_on T g; (∀x∈T. k (h x) = x) ∧ h ` T = U ∧ continuous_on T h ∧ (∀y∈U. h (k y) = y) ∧ k ` U = T ∧ continuous_on U k⟧ ⟹ continuous_on (f ` S) h› 5. ‹⋀y. ⟦(∀x∈S. g (f x) = x) ∧ f ` S = T ∧ continuous_on S f ∧ (∀y∈T. f (g y) = y) ∧ g ` T = S ∧ continuous_on T g; (∀x∈T. k (h x) = x) ∧ h ` T = U ∧ continuous_on T h ∧ (∀y∈U. h (k y) = y) ∧ k ` U = T ∧ continuous_on U k; y ∈ U⟧ ⟹ (h ∘ f) ((g ∘ k) y) = y› 6. ‹⟦(∀x∈S. g (f x) = x) ∧ f ` S = T ∧ continuous_on S f ∧ (∀y∈T. f (g y) = y) ∧ g ` T = S ∧ continuous_on T g; (∀x∈T. k (h x) = x) ∧ h ` T = U ∧ continuous_on T h ∧ (∀y∈U. h (k y) = y) ∧ k ` U = T ∧ continuous_on U k⟧ ⟹ (g ∘ k) ` U = S› 7. ‹⟦(∀x∈S. g (f x) = x) ∧ f ` S = T ∧ continuous_on S f ∧ (∀y∈T. f (g y) = y) ∧ g ` T = S ∧ continuous_on T g; (∀x∈T. k (h x) = x) ∧ h ` T = U ∧ continuous_on T h ∧ (∀y∈U. h (k y) = y) ∧ k ` U = T ∧ continuous_on U k⟧ ⟹ continuous_on U k› 8. ‹⟦(∀x∈S. g (f x) = x) ∧ f ` S = T ∧ continuous_on S f ∧ (∀y∈T. f (g y) = y) ∧ g ` T = S ∧ continuous_on T g; (∀x∈T. k (h x) = x) ∧ h ` T = U ∧ continuous_on T h ∧ (∀y∈U. h (k y) = y) ∧ k ` U = T ∧ continuous_on U k⟧ ⟹ continuous_on (k ` U) g› discuss goal 1*) apply ((auto simp: image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*))[1]) (*discuss goal 2*) apply ((auto simp: image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*))[1]) (*discuss goal 3*) apply ((auto simp: image_iff (*‹((?z::?'a) ∈ (?f::?'b ⇒ ?'a) ` (?A::?'b set)) = (∃x::?'b∈?A. ?z = ?f x)›*))[1]) (*discuss goal 4*) apply ((auto simp: image_iff (*‹((?z::?'a) ∈ (?f::?'b ⇒ ?'a) ` (?A::?'b set)) = (∃x::?'b∈?A. ?z = ?f x)›*))[1]) (*discuss goal 5*) apply ((auto simp: image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*))[1]) (*discuss goal 6*) apply ((auto simp: image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*))[1]) (*discuss goal 7*) apply ((auto simp: image_iff (*‹((?z::?'a::type) ∈ (?f::?'b::type ⇒ ?'a::type) ` (?A::?'b::type set)) = (∃x::?'b::type∈?A. ?z = ?f x)›*))[1]) (*discuss goal 8*) apply ((auto simp: image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*))[1]) (*proven 8 subgoals*) . lemma homeomorphism_cong: "homeomorphism X' Y' f' g'" if "homeomorphism X Y f g" "X' = X" "Y' = Y" "⋀x. x ∈ X ⟹ f' x = f x" "⋀y. y ∈ Y ⟹ g' y = g y" using that (*‹homeomorphism X Y f g› ‹X' = X› ‹Y' = Y› ‹?x ∈ X ⟹ f' ?x = f ?x› ‹?y ∈ Y ⟹ g' ?y = g ?y›*) by (auto simp add: homeomorphism_def (*‹homeomorphism ?S ?T ?f ?g = ((∀x∈?S. ?g (?f x) = x) ∧ ?f ` ?S = ?T ∧ continuous_on ?S ?f ∧ (∀y∈?T. ?f (?g y) = y) ∧ ?g ` ?T = ?S ∧ continuous_on ?T ?g)›*)) lemma homeomorphism_empty [simp]: "homeomorphism {} {} f g" unfolding homeomorphism_def (*goal: ‹(∀x::'a::topological_space∈{}. (g::'b::topological_space ⇒ 'a::topological_space) ((f::'a::topological_space ⇒ 'b::topological_space) x) = x) ∧ f ` {} = {} ∧ continuous_on {} f ∧ (∀y::'b::topological_space∈{}. f (g y) = y) ∧ g ` {} = {} ∧ continuous_on {} g›*) by auto lemma homeomorphism_symD: "homeomorphism S t f g ⟹ homeomorphism t S g f" by (simp add: homeomorphism_def (*‹homeomorphism ?S ?T ?f ?g = ((∀x∈?S. ?g (?f x) = x) ∧ ?f ` ?S = ?T ∧ continuous_on ?S ?f ∧ (∀y∈?T. ?f (?g y) = y) ∧ ?g ` ?T = ?S ∧ continuous_on ?T ?g)›*)) lemma homeomorphism_sym: "homeomorphism S t f g = homeomorphism t S g f" by (force simp: homeomorphism_def (*‹homeomorphism ?S ?T ?f ?g = ((∀x∈?S. ?g (?f x) = x) ∧ ?f ` ?S = ?T ∧ continuous_on ?S ?f ∧ (∀y∈?T. ?f (?g y) = y) ∧ ?g ` ?T = ?S ∧ continuous_on ?T ?g)›*)) lemma continuous_on_translation_eq: fixes g :: "'a :: real_normed_vector ⇒ 'b :: real_normed_vector" shows "continuous_on A ((+) a ∘ g) = continuous_on A g" proof (-) (*goal: ‹continuous_on A ((+) a ∘ g) = continuous_on A g›*) have g: "g = (λx. -a + x) ∘ ((λx. a + x) ∘ g)" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹g = (+) (- a) ∘ ((+) a ∘ g)›*) by simp show "?thesis" (*goal: ‹continuous_on A ((+) a ∘ g) = continuous_on A g›*) by (metis (no_types, opaque_lifting) g (*‹g = (+) (- a) ∘ ((+) a ∘ g)›*) continuous_on_compose (*‹⟦continuous_on ?s ?f; continuous_on (?f ` ?s) ?g⟧ ⟹ continuous_on ?s (?g ∘ ?f)›*) homeomorphism_def (*‹homeomorphism ?S ?T ?f ?g = ((∀x∈?S. ?g (?f x) = x) ∧ ?f ` ?S = ?T ∧ continuous_on ?S ?f ∧ (∀y∈?T. ?f (?g y) = y) ∧ ?g ` ?T = ?S ∧ continuous_on ?T ?g)›*) homeomorphism_translation (*‹homeomorphism ((+) ?a ` ?S) ?S ((+) (- ?a)) ((+) ?a)›*)) qed definition✐‹tag important› homeomorphic :: "'a::topological_space set ⇒ 'b::topological_space set ⇒ bool" (infixr "homeomorphic" 60) where "s homeomorphic t ≡ (∃f g. homeomorphism s t f g)" lemma homeomorphic_empty [iff]: "S homeomorphic {} ⟷ S = {}" "{} homeomorphic S ⟷ S = {}" (*goals: 1. ‹S homeomorphic {} = (S = {})› 2. ‹{} homeomorphic S = (S = {})› discuss goal 1*) apply ((auto simp: homeomorphic_def (*‹?s homeomorphic ?t ≡ ∃f g. homeomorphism ?s ?t f g›*) homeomorphism_def (*‹homeomorphism ?S ?T ?f ?g = ((∀x∈?S. ?g (?f x) = x) ∧ ?f ` ?S = ?T ∧ continuous_on ?S ?f ∧ (∀y∈?T. ?f (?g y) = y) ∧ ?g ` ?T = ?S ∧ continuous_on ?T ?g)›*))[1]) (*discuss goal 2*) apply ((auto simp: homeomorphic_def (*‹?s homeomorphic ?t ≡ ∃f g. homeomorphism ?s ?t f g›*) homeomorphism_def (*‹homeomorphism ?S ?T ?f ?g = ((∀x∈?S. ?g (?f x) = x) ∧ ?f ` ?S = ?T ∧ continuous_on ?S ?f ∧ (∀y∈?T. ?f (?g y) = y) ∧ ?g ` ?T = ?S ∧ continuous_on ?T ?g)›*))[1]) (*proven 2 subgoals*) . lemma homeomorphic_refl: "S homeomorphic S" using homeomorphic_def (*‹?s homeomorphic ?t ≡ ∃f g. homeomorphism ?s ?t f g›*) homeomorphism_ident (*‹homeomorphism ?T ?T (λa. a) (λa. a)›*) by fastforce lemma homeomorphic_sym: "S homeomorphic T ⟷ T homeomorphic S" unfolding homeomorphic_def homeomorphism_def (*goal: ‹(∃(f::'a ⇒ 'b) g::'b ⇒ 'a. (∀x::'a∈S::'a set. g (f x) = x) ∧ f ` S = (T::'b set) ∧ continuous_on S f ∧ (∀y::'b∈T. f (g y) = y) ∧ g ` T = S ∧ continuous_on T g) = (∃(f::'b ⇒ 'a) g::'a ⇒ 'b. (∀x::'b∈T. g (f x) = x) ∧ f ` T = S ∧ continuous_on T f ∧ (∀y::'a∈S. f (g y) = y) ∧ g ` S = T ∧ continuous_on S g)›*) by blast lemma homeomorphic_trans [trans]: assumes "S homeomorphic T" and "T homeomorphic U" shows "S homeomorphic U" using assms (*‹S homeomorphic T› ‹T homeomorphic U›*) unfolding homeomorphic_def (*goal: ‹∃f g. homeomorphism S U f g›*) by (metis homeomorphism_compose (*‹⟦homeomorphism ?S ?T ?f ?g; homeomorphism ?T ?U ?h ?k⟧ ⟹ homeomorphism ?S ?U (?h ∘ ?f) (?g ∘ ?k)›*)) lemma homeomorphic_minimal: "S homeomorphic T ⟷ (∃f g. (∀x∈S. f(x) ∈ T ∧ (g(f(x)) = x)) ∧ (∀y∈T. g(y) ∈ S ∧ (f(g(y)) = y)) ∧ continuous_on S f ∧ continuous_on T g)" by (smt (verit, ccfv_threshold) homeomorphic_def (*‹(?s::?'a set) homeomorphic (?t::?'b set) ≡ ∃(f::?'a ⇒ ?'b) g::?'b ⇒ ?'a. homeomorphism ?s ?t f g›*) homeomorphismI (*‹⟦continuous_on (?S::?'a set) (?f::?'a ⇒ ?'b); continuous_on (?T::?'b set) (?g::?'b ⇒ ?'a); ?f ` ?S ⊆ ?T; ?g ` ?T ⊆ ?S; ⋀x::?'a. x ∈ ?S ⟹ ?g (?f x) = x; ⋀y::?'b. y ∈ ?T ⟹ ?f (?g y) = y⟧ ⟹ homeomorphism ?S ?T ?f ?g›*) homeomorphism_def (*‹homeomorphism (?S::?'a set) (?T::?'b set) (?f::?'a ⇒ ?'b) (?g::?'b ⇒ ?'a) = ((∀x::?'a∈?S. ?g (?f x) = x) ∧ ?f ` ?S = ?T ∧ continuous_on ?S ?f ∧ (∀y::?'b∈?T. ?f (?g y) = y) ∧ ?g ` ?T = ?S ∧ continuous_on ?T ?g)›*) image_eqI (*‹⟦(?b::?'a) = (?f::?'b ⇒ ?'a) (?x::?'b); ?x ∈ (?A::?'b set)⟧ ⟹ ?b ∈ ?f ` ?A›*) image_subset_iff (*‹((?f::?'b ⇒ ?'a) ` (?A::?'b set) ⊆ (?B::?'a set)) = (∀x::?'b∈?A. ?f x ∈ ?B)›*)) lemma homeomorphicI [intro?]: "⟦f ` S = T; g ` T = S; continuous_on S f; continuous_on T g; ⋀x. x ∈ S ⟹ g(f(x)) = x; ⋀y. y ∈ T ⟹ f(g(y)) = y⟧ ⟹ S homeomorphic T" unfolding homeomorphic_def homeomorphism_def (*goal: ‹⟦f ` S = T; g ` T = S; continuous_on S f; continuous_on T g; ⋀x. x ∈ S ⟹ g (f x) = x; ⋀y. y ∈ T ⟹ f (g y) = y⟧ ⟹ ∃f g. (∀x∈S. g (f x) = x) ∧ f ` S = T ∧ continuous_on S f ∧ (∀y∈T. f (g y) = y) ∧ g ` T = S ∧ continuous_on T g›*) by metis lemma homeomorphism_of_subsets: "⟦homeomorphism S T f g; S' ⊆ S; T'' ⊆ T; f ` S' = T'⟧ ⟹ homeomorphism S' T' f g" by (smt (verit, del_insts) continuous_on_subset (*‹⟦continuous_on ?s ?f; ?t ⊆ ?s⟧ ⟹ continuous_on ?t ?f›*) homeomorphismI (*‹⟦continuous_on ?S ?f; continuous_on ?T ?g; ?f ` ?S ⊆ ?T; ?g ` ?T ⊆ ?S; ⋀x. x ∈ ?S ⟹ ?g (?f x) = x; ⋀y. y ∈ ?T ⟹ ?f (?g y) = y⟧ ⟹ homeomorphism ?S ?T ?f ?g›*) homeomorphism_def (*‹homeomorphism ?S ?T ?f ?g = ((∀x∈?S. ?g (?f x) = x) ∧ ?f ` ?S = ?T ∧ continuous_on ?S ?f ∧ (∀y∈?T. ?f (?g y) = y) ∧ ?g ` ?T = ?S ∧ continuous_on ?T ?g)›*) imageE (*‹⟦?b ∈ ?f ` ?A; ⋀x. ⟦?b = ?f x; x ∈ ?A⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*)) lemma homeomorphism_apply1: "⟦homeomorphism S T f g; x ∈ S⟧ ⟹ g(f x) = x" by (simp add: homeomorphism_def (*‹homeomorphism (?S::?'a set) (?T::?'b set) (?f::?'a ⇒ ?'b) (?g::?'b ⇒ ?'a) = ((∀x::?'a∈?S. ?g (?f x) = x) ∧ ?f ` ?S = ?T ∧ continuous_on ?S ?f ∧ (∀y::?'b∈?T. ?f (?g y) = y) ∧ ?g ` ?T = ?S ∧ continuous_on ?T ?g)›*)) lemma homeomorphism_apply2: "⟦homeomorphism S T f g; x ∈ T⟧ ⟹ f(g x) = x" by (simp add: homeomorphism_def (*‹homeomorphism ?S ?T ?f ?g = ((∀x∈?S. ?g (?f x) = x) ∧ ?f ` ?S = ?T ∧ continuous_on ?S ?f ∧ (∀y∈?T. ?f (?g y) = y) ∧ ?g ` ?T = ?S ∧ continuous_on ?T ?g)›*)) lemma homeomorphism_image1: "homeomorphism S T f g ⟹ f ` S = T" by (simp add: homeomorphism_def (*‹homeomorphism ?S ?T ?f ?g = ((∀x∈?S. ?g (?f x) = x) ∧ ?f ` ?S = ?T ∧ continuous_on ?S ?f ∧ (∀y∈?T. ?f (?g y) = y) ∧ ?g ` ?T = ?S ∧ continuous_on ?T ?g)›*)) lemma homeomorphism_image2: "homeomorphism S T f g ⟹ g ` T = S" by (simp add: homeomorphism_def (*‹homeomorphism ?S ?T ?f ?g = ((∀x∈?S. ?g (?f x) = x) ∧ ?f ` ?S = ?T ∧ continuous_on ?S ?f ∧ (∀y∈?T. ?f (?g y) = y) ∧ ?g ` ?T = ?S ∧ continuous_on ?T ?g)›*)) lemma homeomorphism_cont1: "homeomorphism S T f g ⟹ continuous_on S f" by (simp add: homeomorphism_def (*‹homeomorphism (?S::?'a set) (?T::?'b set) (?f::?'a ⇒ ?'b) (?g::?'b ⇒ ?'a) = ((∀x::?'a∈?S. ?g (?f x) = x) ∧ ?f ` ?S = ?T ∧ continuous_on ?S ?f ∧ (∀y::?'b∈?T. ?f (?g y) = y) ∧ ?g ` ?T = ?S ∧ continuous_on ?T ?g)›*)) lemma homeomorphism_cont2: "homeomorphism S T f g ⟹ continuous_on T g" by (simp add: homeomorphism_def (*‹homeomorphism ?S ?T ?f ?g = ((∀x∈?S. ?g (?f x) = x) ∧ ?f ` ?S = ?T ∧ continuous_on ?S ?f ∧ (∀y∈?T. ?f (?g y) = y) ∧ ?g ` ?T = ?S ∧ continuous_on ?T ?g)›*)) lemma continuous_on_no_limpt: "(⋀x. ¬ x islimpt S) ⟹ continuous_on S f" unfolding continuous_on_def (*goal: ‹(⋀x. ¬ x islimpt S) ⟹ ∀x∈S. (f ⤏ f x) (at x within S)›*) by (metis UNIV_I (*‹?x ∈ UNIV›*) empty_iff (*‹(?c ∈ {}) = False›*) eventually_at_topological (*‹eventually ?P (at ?a within ?s) = (∃S. open S ∧ ?a ∈ S ∧ (∀x∈S. x ≠ ?a ⟶ x ∈ ?s ⟶ ?P x))›*) islimptE (*‹⟦?x islimpt ?S; ?x ∈ ?T; open ?T; ⋀y. ⟦y ∈ ?S; y ∈ ?T; y ≠ ?x⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) open_UNIV (*‹open UNIV›*) tendsto_def (*‹(?f ⤏ ?l) ?F = (∀S. open S ⟶ ?l ∈ S ⟶ (∀⇩F x in ?F. ?f x ∈ S))›*) trivial_limit_within (*‹(at ?a within ?S = bot) = (¬ ?a islimpt ?S)›*)) lemma continuous_on_finite: fixes S :: "'a::t1_space set" shows "finite S ⟹ continuous_on S f" by (metis continuous_on_no_limpt (*‹(⋀x. ¬ x islimpt ?S) ⟹ continuous_on ?S ?f›*) islimpt_finite (*‹finite ?S ⟹ ¬ ?x islimpt ?S›*)) lemma homeomorphic_finite: fixes S :: "'a::t1_space set" and T :: "'b::t1_space set" assumes "finite T" shows "S homeomorphic T ⟷ finite S ∧ finite T ∧ card S = card T" (is "?lhs = ?rhs") proof (standard) (*goals: 1. ‹S homeomorphic T ⟹ finite S ∧ finite T ∧ card S = card T› 2. ‹finite S ∧ finite T ∧ card S = card T ⟹ S homeomorphic T›*) assume "S homeomorphic T" (*‹(S::'a set) homeomorphic (T::'b set)›*) with assms (*‹finite T›*) show "?rhs" by (metis (full_types) card_image_le (*‹finite (?A::?'a set) ⟹ card ((?f::?'a ⇒ ?'b) ` ?A) ≤ card ?A›*) finite_imageI (*‹finite (?F::?'a set) ⟹ finite ((?h::?'a ⇒ ?'b) ` ?F)›*) homeomorphic_def (*‹(?s::?'a set) homeomorphic (?t::?'b set) ≡ ∃(f::?'a ⇒ ?'b) g::?'b ⇒ ?'a. homeomorphism ?s ?t f g›*) homeomorphism_def (*‹homeomorphism (?S::?'a set) (?T::?'b set) (?f::?'a ⇒ ?'b) (?g::?'b ⇒ ?'a) = ((∀x::?'a∈?S. ?g (?f x) = x) ∧ ?f ` ?S = ?T ∧ continuous_on ?S ?f ∧ (∀y::?'b∈?T. ?f (?g y) = y) ∧ ?g ` ?T = ?S ∧ continuous_on ?T ?g)›*) le_antisym (*‹⟦(?m::nat) ≤ (?n::nat); ?n ≤ ?m⟧ ⟹ ?m = ?n›*)) next (*goal: ‹finite S ∧ finite T ∧ card S = card T ⟹ S homeomorphic T›*) assume R: "?rhs" (*‹finite (S::'a set) ∧ finite (T::'b set) ∧ card S = card T›*) with finite_same_card_bij (*‹⟦finite ?A; finite ?B; card ?A = card ?B⟧ ⟹ ∃h. bij_betw h ?A ?B›*) obtain h where "bij_betw h S T" (*goal: ‹(⋀h. bij_betw h S T ⟹ thesis) ⟹ thesis›*) by auto with R (*‹finite S ∧ finite T ∧ card S = card T›*) show "?lhs" apply (simp only: homeomorphic_def (*‹?s homeomorphic ?t ≡ ∃f g. homeomorphism ?s ?t f g›*) homeomorphism_def (*‹homeomorphism ?S ?T ?f ?g = ((∀x∈?S. ?g (?f x) = x) ∧ ?f ` ?S = ?T ∧ continuous_on ?S ?f ∧ (∀y∈?T. ?f (?g y) = y) ∧ ?g ` ?T = ?S ∧ continuous_on ?T ?g)›*) continuous_on_finite (*‹finite ?S ⟹ continuous_on ?S ?f›*)) (*goal: ‹S homeomorphic T›*) by (smt (verit, ccfv_SIG) bij_betw_imp_surj_on (*‹bij_betw ?f ?A ?B ⟹ ?f ` ?A = ?B›*) bij_betw_inv_into (*‹bij_betw ?f ?A ?B ⟹ bij_betw (inv_into ?A ?f) ?B ?A›*) bij_betw_inv_into_left (*‹⟦bij_betw ?f ?A ?A'; ?a ∈ ?A⟧ ⟹ inv_into ?A ?f (?f ?a) = ?a›*) bij_betw_inv_into_right (*‹⟦bij_betw ?f ?A ?A'; ?a' ∈ ?A'⟧ ⟹ ?f (inv_into ?A ?f ?a') = ?a'›*)) qed text ‹Relatively weak hypotheses if a set is compact.› lemma homeomorphism_compact: fixes f :: "'a::topological_space ⇒ 'b::t2_space" assumes "compact S" "continuous_on S f" "f ` S = T" "inj_on f S" shows "∃g. homeomorphism S T f g" proof (-) (*goal: ‹∃g. homeomorphism S T f g›*) obtain g where g: "∀x∈S. g (f x) = x" "∀x∈T. f (g x) = x" "g ` T = S" (*goal: ‹(⋀g. ⟦∀x∈S. g (f x) = x; ∀x∈T. f (g x) = x; g ` T = S⟧ ⟹ thesis) ⟹ thesis›*) using assms (*‹compact (S::'a set)› ‹continuous_on S f› ‹f ` S = T› ‹inj_on f S›*) the_inv_into_f_f (*‹⟦inj_on ?f ?A; ?x ∈ ?A⟧ ⟹ the_inv_into ?A ?f (?f ?x) = ?x›*) by fastforce with assms (*‹compact S› ‹continuous_on S f› ‹f ` S = T› ‹inj_on (f::'a ⇒ 'b) (S::'a set)›*) show "?thesis" (*goal: ‹∃g::'b ⇒ 'a. homeomorphism (S::'a set) (T::'b set) (f::'a ⇒ 'b) g›*) unfolding homeomorphism_def homeomorphic_def (*goal: ‹∃g. (∀x∈S. g (f x) = x) ∧ f ` S = T ∧ continuous_on S f ∧ (∀y∈T. f (g y) = y) ∧ g ` T = S ∧ continuous_on T g›*) by (metis continuous_on_inv (*‹⟦continuous_on ?s ?f; compact ?s; ∀x∈?s. ?g (?f x) = x⟧ ⟹ continuous_on (?f ` ?s) ?g›*)) qed lemma homeomorphic_compact: fixes f :: "'a::topological_space ⇒ 'b::t2_space" shows "compact S ⟹ continuous_on S f ⟹ (f ` S = T) ⟹ inj_on f S ⟹ S homeomorphic T" unfolding homeomorphic_def (*goal: ‹⟦compact (S::'a::topological_space set); continuous_on S (f::'a::topological_space ⇒ 'b::t2_space); f ` S = (T::'b::t2_space set); inj_on f S⟧ ⟹ ∃(f::'a::topological_space ⇒ 'b::t2_space) g::'b::t2_space ⇒ 'a::topological_space. homeomorphism S T f g›*) by (metis homeomorphism_compact (*‹⟦compact ?S; continuous_on ?S ?f; ?f ` ?S = ?T; inj_on ?f ?S⟧ ⟹ ∃g. homeomorphism ?S ?T ?f g›*)) text‹Preservation of topological properties.› lemma homeomorphic_compactness: "S homeomorphic T ⟹ (compact S ⟷ compact T)" unfolding homeomorphic_def homeomorphism_def (*goal: ‹∃f g. (∀x∈S. g (f x) = x) ∧ f ` S = T ∧ continuous_on S f ∧ (∀y∈T. f (g y) = y) ∧ g ` T = S ∧ continuous_on T g ⟹ compact S = compact T›*) by (metis compact_continuous_image (*‹⟦continuous_on (?s::?'a set) (?f::?'a ⇒ ?'b); compact ?s⟧ ⟹ compact (?f ` ?s)›*)) subsection✐‹tag unimportant› ‹On Linorder Topologies› lemma islimpt_greaterThanLessThan1: fixes a b::"'a::{linorder_topology, dense_order}" assumes "a < b" shows "a islimpt {a<..<b}" proof (rule islimptI (*‹(⋀T. ⟦?x ∈ T; open T⟧ ⟹ ∃y∈?S. y ∈ T ∧ y ≠ ?x) ⟹ ?x islimpt ?S›*)) (*goal: ‹⋀T. ⟦a ∈ T; open T⟧ ⟹ ∃y∈{a<..<b}. y ∈ T ∧ y ≠ a›*) fix T assume "open T" "a ∈ T" (*‹open (T::'a set)› ‹(a::'a) ∈ (T::'a set)›*) then obtain c where c: "a < c" "{a..<c} ⊆ T" (*goal: ‹(⋀c. ⟦a < c; {a..<c} ⊆ T⟧ ⟹ thesis) ⟹ thesis›*) by (meson assms (*‹a < b›*) open_right (*‹⟦open ?S; ?x ∈ ?S; ?x < ?y⟧ ⟹ ∃b>?x. {?x..<b} ⊆ ?S›*)) with assms (*‹a < b›*) dense[of a "min c b"] (*‹a < min c b ⟹ ∃z>a. z < min c b›*) show "∃y∈{a<..<b}. y ∈ T ∧ y ≠ a" by (metis atLeastLessThan_iff (*‹((?i::?'a) ∈ {?l::?'a..<?u::?'a}) = (?l ≤ ?i ∧ ?i < ?u)›*) greaterThanLessThan_iff (*‹((?i::?'a) ∈ {?l::?'a<..<?u::?'a}) = (?l < ?i ∧ ?i < ?u)›*) min_less_iff_conj (*‹((?z::?'a) < min (?x::?'a) (?y::?'a)) = (?z < ?x ∧ ?z < ?y)›*) not_le (*‹(¬ (?x::?'a) ≤ (?y::?'a)) = (?y < ?x)›*) order.strict_implies_order (*‹(?a::?'a) < (?b::?'a) ⟹ ?a ≤ ?b›*) subset_eq (*‹((?A::?'a set) ⊆ (?B::?'a set)) = (∀x::?'a∈?A. x ∈ ?B)›*)) qed lemma islimpt_greaterThanLessThan2: fixes a b::"'a::{linorder_topology, dense_order}" assumes "a < b" shows "b islimpt {a<..<b}" proof (rule islimptI (*‹(⋀T. ⟦?x ∈ T; open T⟧ ⟹ ∃y∈?S. y ∈ T ∧ y ≠ ?x) ⟹ ?x islimpt ?S›*)) (*goal: ‹⋀T. ⟦b ∈ T; open T⟧ ⟹ ∃y∈{a<..<b}. y ∈ T ∧ y ≠ b›*) fix T assume "open T" "b ∈ T" (*‹open (T::'a set)› ‹(b::'a) ∈ (T::'a set)›*) from open_left[OF this ‹a < b›] (*‹∃ba<b::'a. {ba<..b} ⊆ (T::'a set)›*) obtain c where c: "c < b" "{c<..b} ⊆ T" (*goal: ‹(⋀c. ⟦c < b; {c<..b} ⊆ T⟧ ⟹ thesis) ⟹ thesis›*) by auto with assms (*‹a < b›*) dense[of "max a c" b] (*‹max a c < b ⟹ ∃z>max a c. z < b›*) show "∃y∈{a<..<b}. y ∈ T ∧ y ≠ b" by (metis greaterThanAtMost_iff (*‹((?i::?'a::ord) ∈ {?l::?'a::ord<..?u::?'a::ord}) = (?l < ?i ∧ ?i ≤ ?u)›*) greaterThanLessThan_iff (*‹((?i::?'a::ord) ∈ {?l::?'a::ord<..<?u::?'a::ord}) = (?l < ?i ∧ ?i < ?u)›*) max_less_iff_conj (*‹(max (?x::?'a::linorder) (?y::?'a::linorder) < (?z::?'a::linorder)) = (?x < ?z ∧ ?y < ?z)›*) not_le (*‹(¬ (?x::?'a::linorder) ≤ (?y::?'a::linorder)) = (?y < ?x)›*) order.strict_implies_order (*‹(?a::?'a::preorder) < (?b::?'a::preorder) ⟹ ?a ≤ ?b›*) subset_eq (*‹((?A::?'a::type set) ⊆ (?B::?'a::type set)) = (∀x::?'a::type∈?A. x ∈ ?B)›*)) qed lemma closure_greaterThanLessThan[simp]: fixes a b::"'a::{linorder_topology, dense_order}" shows "a < b ⟹ closure {a <..< b} = {a .. b}" (is "_ ⟹ ?l = ?r") proof (standard) (*goals: 1. ‹a < b ⟹ closure {a<..<b} ⊆ {a..b}› 2. ‹a < b ⟹ {a..b} ⊆ closure {a<..<b}›*) have "?l ⊆ closure ?r" apply (rule closure_mono (*‹?S ⊆ ?T ⟹ closure ?S ⊆ closure ?T›*)) (*goal: ‹closure {a<..<b} ⊆ closure {a..b}›*) by auto thus "closure {a<..<b} ⊆ {a..b}" by simp qed (auto simp: closure_def (*‹closure ?S = ?S ∪ {x. x islimpt ?S}›*) order.order_iff_strict (*‹(?a ≤ ?b) = (?a < ?b ∨ ?a = ?b)›*) islimpt_greaterThanLessThan1 (*‹?a < ?b ⟹ ?a islimpt {?a<..<?b}›*) islimpt_greaterThanLessThan2 (*‹?a < ?b ⟹ ?b islimpt {?a<..<?b}›*)) (*solved the remaining goal: ‹a < b ⟹ {a..b} ⊆ closure {a<..<b}›*) lemma closure_greaterThan[simp]: fixes a b::"'a::{no_top, linorder_topology, dense_order}" shows "closure {a<..} = {a..}" proof (-) (*goal: ‹closure {a<..} = {a..}›*) from gt_ex (*‹∃y. ?x < y›*) obtain b where "a < b" (*goal: ‹(⋀b. a < b ⟹ thesis) ⟹ thesis›*) by auto hence "{a<..} = {a<..<b} ∪ {b..}" by auto also (*calculation: ‹{a<..} = {a<..<b} ∪ {b..}›*) have "closure … = {a..}" using ‹a < b› (*‹(a::'a) < (b::'a)›*) unfolding closure_Un (*goal: ‹closure {a<..<b} ∪ closure {b..} = {a..}›*) by auto finally (*calculation: ‹closure {a<..} = {a..}›*) show "?thesis" (*goal: ‹closure {a<..} = {a..}›*) . qed lemma closure_lessThan[simp]: fixes b::"'a::{no_bot, linorder_topology, dense_order}" shows "closure {..<b} = {..b}" proof (-) (*goal: ‹closure {..<b} = {..b}›*) from lt_ex (*‹∃y. y < ?x›*) obtain a where "a < b" (*goal: ‹(⋀a::'a. a < (b::'a) ⟹ thesis::bool) ⟹ thesis›*) by auto hence "{..<b} = {a<..<b} ∪ {..a}" by auto also (*calculation: ‹{..<b} = {a<..<b} ∪ {..a}›*) have "closure … = {..b}" using ‹a < b› (*‹a < b›*) unfolding closure_Un (*goal: ‹closure {a<..<b} ∪ closure {..a} = {..b}›*) by auto finally (*calculation: ‹closure {..<b} = {..b}›*) show "?thesis" (*goal: ‹closure {..<b} = {..b}›*) . qed lemma closure_atLeastLessThan[simp]: fixes a b::"'a::{linorder_topology, dense_order}" assumes "a < b" shows "closure {a ..< b} = {a .. b}" proof (-) (*goal: ‹closure {a..<b} = {a..b}›*) from assms (*‹a < b›*) have "{a ..< b} = {a} ∪ {a <..< b}" by auto also (*calculation: ‹{a..<b} = {a} ∪ {a<..<b}›*) have "closure … = {a .. b}" unfolding closure_Un (*goal: ‹closure {a} ∪ closure {a<..<b} = {a..b}›*) by (auto simp: assms (*‹a < b›*) less_imp_le (*‹?x < ?y ⟹ ?x ≤ ?y›*)) finally (*calculation: ‹closure {a..<b} = {a..b}›*) show "?thesis" (*goal: ‹closure {a..<b} = {a..b}›*) . qed lemma closure_greaterThanAtMost[simp]: fixes a b::"'a::{linorder_topology, dense_order}" assumes "a < b" shows "closure {a <.. b} = {a .. b}" proof (-) (*goal: ‹closure {a<..b} = {a..b}›*) from assms (*‹a < b›*) have "{a <.. b} = {b} ∪ {a <..< b}" by auto also (*calculation: ‹{a::'a<..b::'a} = {b} ∪ {a<..<b}›*) have "closure … = {a .. b}" unfolding closure_Un (*goal: ‹closure {b} ∪ closure {a<..<b} = {a..b}›*) by (auto simp: assms (*‹a < b›*) less_imp_le (*‹?x < ?y ⟹ ?x ≤ ?y›*)) finally (*calculation: ‹closure {a<..b} = {a..b}›*) show "?thesis" (*goal: ‹closure {a<..b} = {a..b}›*) . qed end
{ "path": "Isabelle2024/src/HOL/Analysis/Elementary_Topology.thy", "repo": "Isabelle2024", "sha": "cf0598090caa5e200f9f3f5750d4818b493800ae900bfa1a40b2d6423429e39d" }
(******************************************************************************* Project: IsaNet Author: Tobias Klenze, ETH Zurich <tobias.klenze@inf.ethz.ch> Christoph Sprenger, ETH Zurich <sprenger@inf.ethz.ch> Version: JCSPaper.1.0 Isabelle Version: Isabelle2021-1 Copyright (c) 2022 Tobias Klenze, Christoph Sprenger Licence: Mozilla Public License 2.0 (MPL) / BSD-3-Clause (dual license) *******************************************************************************) chapter‹Abstract, and Concrete Parametrized Models› text‹This is the core of our verification -- the abstract and parametrized models that cover a wide range of protocols.› section‹Network model› theory Network_Model imports "infrastructure/Agents" "infrastructure/Tools" "infrastructure/Take_While" begin text‹@{term "as"} is already defined as a type synonym for nat.› type_synonym ifs = nat text‹The authenticated hop information consists of the interface identifiers UpIF, DownIF and an identifier of the AS to which the hop information belongs. Furthermore, this record is extensible and can include additional authenticated hop information (aahi).› record ahi = UpIF :: "ifs option" DownIF :: "ifs option" ASID :: as type_synonym 'aahi ahis = "'aahi ahi_scheme" locale network_model = compromised + fixes auth_seg0 :: "('ainfo × 'aahi ahi_scheme list) set" and tgtas :: "as ⇒ ifs ⇒ as option" and tgtif :: "as ⇒ ifs ⇒ ifs option" begin subsection ‹Interface check› (******************************************************************************) text ‹Check if the interfaces of two adjacent hop fields match. If both hops are compromised we also interpret the link as valid.› fun if_valid :: "'aahi ahis option ⇒ 'aahi ahis => 'aahi ahis option ⇒ bool" where "if_valid None hf _ ― ‹this is the case for the leaf AS› = True" | "if_valid (Some hf1) (hf2) _ = ((∃downif . DownIF hf2 = Some downif ∧ tgtas (ASID hf2) downif = Some (ASID hf1) ∧ tgtif (ASID hf2) downif = UpIF hf1) ∨ ASID hf1 ∈ bad ∧ ASID hf2 ∈ bad)" text ‹makes sure that: the segment is terminated, i.e. the first AS's HF has Eo = None› fun terminated :: "'aahi ahis list ⇒ bool" where "terminated (hf#xs) ⟷ DownIF hf = None ∨ ASID hf ∈ bad" | "terminated [] = True" (* we allow this as a special case*) text ‹makes sure that: the segment is rooted, i.e. the last HF has UpIF = None› fun rooted :: "'aahi ahis list ⇒ bool" where "rooted [hf] ⟷ UpIF hf = None ∨ ASID hf ∈ bad" | "rooted (hf#xs) = rooted xs" | "rooted [] = True" (* we allow this as a special case*) abbreviation ifs_valid where "ifs_valid pre l nxt ≡ TW.holds if_valid pre l nxt" abbreviation ifs_valid_prefix where "ifs_valid_prefix pre l nxt ≡ TW.takeW if_valid pre l nxt" abbreviation ifs_valid_None where "ifs_valid_None l ≡ ifs_valid None l None" abbreviation ifs_valid_None_prefix where "ifs_valid_None_prefix l ≡ ifs_valid_prefix None l None" lemma strip_ifs_valid_prefix: "pfragment ainfo l auth_seg0 ⟹ pfragment ainfo (ifs_valid_prefix pre l nxt) auth_seg0" by (auto elim: pfragment_prefix' (*‹⟦pfragment (?ainf::?'a) (?ys::?'b list) (?St::(?'a × ?'b list) set); prefix (?xs::?'b list) ?ys⟧ ⟹ pfragment ?ainf ?xs ?St›*) intro: TW.takeW_prefix (*‹prefix (TW.takeW (?P::?'a option ⇒ ?'a ⇒ ?'a option ⇒ bool) (?pre::?'a option) (?l::?'a list) (?nxt::?'a option)) ?l›*)) text‹Given the AS and an interface identifier of a channel, obtain the AS and interface at the other end of the same channel.› abbreviation rev_link :: "as ⇒ ifs ⇒ as option × ifs option" where "rev_link a1 i1 ≡ (tgtas a1 i1, tgtif a1 i1)" end end
{ "path": "afp-2025-02-12/thys/IsaNet/Network_Model.thy", "repo": "afp-2025-02-12", "sha": "fe90bbaa9b4f5c83f9fa61ae8bf636da2fe3e9574f00d4d34d4abb3b7b60de85" }
(* Title: Rtrancl_On.thy Author: Lars Noschinski, TU München Author: René Neumann, TU München *) theory Rtrancl_On imports Main begin section ‹Reflexive-Transitive Closure on a Domain› text ‹ In this section we introduce a variant of the reflexive-transitive closure of a relation which is useful to formalize the reachability relation on digraphs. › inductive_set rtrancl_on :: "'a set ⇒ 'a rel ⇒ 'a rel" for F :: "'a set" and r :: "'a rel" where rtrancl_on_refl [intro!, Pure.intro!, simp]: "a ∈ F ⟹ (a, a) ∈ rtrancl_on F r" | rtrancl_on_into_rtrancl_on [Pure.intro]: "(a, b) ∈ rtrancl_on F r ⟹ (b, c) ∈ r ⟹ c ∈ F ⟹ (a, c) ∈ rtrancl_on F r" definition symcl :: "'a rel ⇒ 'a rel" ("(_⇧s)" [1000] 999) where "symcl R = R ∪ (λ(a,b). (b,a)) ` R" lemma in_rtrancl_on_in_F: assumes "(a,b) ∈ rtrancl_on F r" shows "a ∈ F" "b ∈ F" using assms (*‹(a, b) ∈ rtrancl_on F r›*) apply induct (*goals: 1. ‹⋀a. a ∈ F ⟹ a ∈ F› 2. ‹⋀a. a ∈ F ⟹ a ∈ F› 3. ‹⋀a b c. ⟦(a, b) ∈ rtrancl_on F r; a ∈ F; b ∈ F; (b, c) ∈ r; c ∈ F⟧ ⟹ a ∈ F› 4. ‹⋀a b c. ⟦(a, b) ∈ rtrancl_on F r; a ∈ F; b ∈ F; (b, c) ∈ r; c ∈ F⟧ ⟹ c ∈ F› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . lemma rtrancl_on_induct[consumes 1, case_names base step, induct set: rtrancl_on]: assumes "(a, b) ∈ rtrancl_on F r" and "a ∈ F ⟹ P a" "⋀y z. ⟦(a, y) ∈ rtrancl_on F r; (y,z) ∈ r; y ∈ F; z ∈ F; P y⟧ ⟹ P z" shows "P b" using assms (*‹(a, b) ∈ rtrancl_on F r› ‹a ∈ F ⟹ P a› ‹⟦(a, ?y) ∈ rtrancl_on F r; (?y, ?z) ∈ r; ?y ∈ F; ?z ∈ F; P ?y⟧ ⟹ P ?z›*) apply (induct a b) (*goals: 1. ‹⋀a. ⟦a ∈ F; a ∈ F ⟹ P a; ⋀y z. ⟦(a, y) ∈ rtrancl_on F r; (y, z) ∈ r; y ∈ F; z ∈ F; P y⟧ ⟹ P z⟧ ⟹ P a› 2. ‹⋀a b c. ⟦(a, b) ∈ rtrancl_on F r; ⟦a ∈ F ⟹ P a; ⋀y z. ⟦(a, y) ∈ rtrancl_on F r; (y, z) ∈ r; y ∈ F; z ∈ F; P y⟧ ⟹ P z⟧ ⟹ P b; (b, c) ∈ r; c ∈ F; a ∈ F ⟹ P a; ⋀y z. ⟦(a, y) ∈ rtrancl_on F r; (y, z) ∈ r; y ∈ F; z ∈ F; P y⟧ ⟹ P z⟧ ⟹ P c› discuss goal 1*) apply ((auto dest: in_rtrancl_on_in_F (*‹(?a, ?b) ∈ rtrancl_on ?F ?r ⟹ ?a ∈ ?F› ‹(?a, ?b) ∈ rtrancl_on ?F ?r ⟹ ?b ∈ ?F›*))[1]) (*discuss goal 2*) apply ((auto dest: in_rtrancl_on_in_F (*‹(?a::?'a, ?b::?'a) ∈ rtrancl_on (?F::?'a set) (?r::(?'a × ?'a) set) ⟹ ?a ∈ ?F› ‹(?a::?'a, ?b::?'a) ∈ rtrancl_on (?F::?'a set) (?r::(?'a × ?'a) set) ⟹ ?b ∈ ?F›*))[1]) (*proven 2 subgoals*) . lemma rtrancl_on_trans: assumes "(a,b) ∈ rtrancl_on F r" "(b,c) ∈ rtrancl_on F r" shows "(a,c) ∈ rtrancl_on F r" using assms(2,1) (*‹(b, c) ∈ rtrancl_on F r› ‹(a, b) ∈ rtrancl_on F r›*) apply induct (*goals: 1. ‹⟦b ∈ F; (a, b) ∈ rtrancl_on F r⟧ ⟹ (a, b) ∈ rtrancl_on F r› 2. ‹⋀y z. ⟦(b, y) ∈ rtrancl_on F r; (y, z) ∈ r; y ∈ F; z ∈ F; (a, b) ∈ rtrancl_on F r ⟹ (a, y) ∈ rtrancl_on F r; (a, b) ∈ rtrancl_on F r⟧ ⟹ (a, z) ∈ rtrancl_on F r› discuss goal 1*) apply ((auto intro: rtrancl_on_into_rtrancl_on (*‹⟦(?a, ?b) ∈ rtrancl_on ?F ?r; (?b, ?c) ∈ ?r; ?c ∈ ?F⟧ ⟹ (?a, ?c) ∈ rtrancl_on ?F ?r›*))[1]) (*discuss goal 2*) apply ((auto intro: rtrancl_on_into_rtrancl_on (*‹⟦(?a, ?b) ∈ rtrancl_on ?F ?r; (?b, ?c) ∈ ?r; ?c ∈ ?F⟧ ⟹ (?a, ?c) ∈ rtrancl_on ?F ?r›*))[1]) (*proven 2 subgoals*) . lemma converse_rtrancl_on_into_rtrancl_on: assumes "(a,b) ∈ r" "(b, c) ∈ rtrancl_on F r" "a ∈ F" shows "(a, c) ∈ rtrancl_on F r" proof (-) (*goal: ‹(a, c) ∈ rtrancl_on F r›*) have "b ∈ F" using ‹(b,c) ∈ _› (*‹(b, c) ∈ rtrancl_on F r›*) by (rule in_rtrancl_on_in_F (*‹(?a, ?b) ∈ rtrancl_on ?F ?r ⟹ ?a ∈ ?F› ‹(?a, ?b) ∈ rtrancl_on ?F ?r ⟹ ?b ∈ ?F›*)) show "?thesis" (*goal: ‹(a, c) ∈ rtrancl_on F r›*) apply (rule rtrancl_on_trans (*‹⟦(?a, ?b) ∈ rtrancl_on ?F ?r; (?b, ?c) ∈ rtrancl_on ?F ?r⟧ ⟹ (?a, ?c) ∈ rtrancl_on ?F ?r›*)) (*goals: 1. ‹(a, ?b) ∈ rtrancl_on F r› 2. ‹(?b, c) ∈ rtrancl_on F r› discuss goal 1*) apply (rule rtrancl_on_into_rtrancl_on (*‹⟦(?a::?'a, ?b::?'a) ∈ rtrancl_on (?F::?'a set) (?r::(?'a × ?'a) set); (?b, ?c::?'a) ∈ ?r; ?c ∈ ?F⟧ ⟹ (?a, ?c) ∈ rtrancl_on ?F ?r›*)) (*goals: 1. ‹(a, ?b3) ∈ rtrancl_on F r› 2. ‹(?b3, ?b) ∈ r› 3. ‹?b ∈ F› discuss goal 1*) apply (rule rtrancl_on_refl (*‹?a ∈ ?F ⟹ (?a, ?a) ∈ rtrancl_on ?F ?r›*)) (*top goal: ‹(a, ?b3) ∈ rtrancl_on F r› and 3 goals remain*) apply fact (*discuss goal 2*) apply fact (*discuss goal 3*) apply fact (*proven 3 subgoals*) (*discuss goal 2*) apply fact (*proven 2 subgoals*) . qed lemma rtrancl_on_converseI: assumes "(y, x) ∈ rtrancl_on F r" shows "(x, y) ∈ rtrancl_on F (r¯)" using assms (*‹(y, x) ∈ rtrancl_on F r›*) proof (induct) (*goals: 1. ‹y ∈ F ⟹ (y, y) ∈ rtrancl_on F (r¯)› 2. ‹⋀ya z. ⟦(y, ya) ∈ rtrancl_on F r; (ya, z) ∈ r; ya ∈ F; z ∈ F; (ya, y) ∈ rtrancl_on F (r¯)⟧ ⟹ (z, y) ∈ rtrancl_on F (r¯)›*) case (step a b) (*‹(y, a) ∈ rtrancl_on F r› ‹(a, b) ∈ r› ‹a ∈ F› ‹b ∈ F› ‹(a, y) ∈ rtrancl_on F (r¯)›*) then have "(b,b) ∈ rtrancl_on F (r¯)" "(b,a) ∈ r¯" apply - (*goals: 1. ‹⟦(y, a) ∈ rtrancl_on F r; (a, b) ∈ r; a ∈ F; b ∈ F; (a, y) ∈ rtrancl_on F (r¯)⟧ ⟹ (b, b) ∈ rtrancl_on F (r¯)› 2. ‹⟦(y, a) ∈ rtrancl_on F r; (a, b) ∈ r; a ∈ F; b ∈ F; (a, y) ∈ rtrancl_on F (r¯)⟧ ⟹ (b, a) ∈ r¯› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . then show "?case" (*goal: ‹(b, y) ∈ rtrancl_on F (r¯)›*) using step (*‹(y, a) ∈ rtrancl_on F r› ‹(a, b) ∈ r› ‹(a::'a) ∈ (F::'a set)› ‹b ∈ F› ‹(a, y) ∈ rtrancl_on F (r¯)›*) by (metis rtrancl_on_trans (*‹⟦(?a::?'a, ?b::?'a) ∈ rtrancl_on (?F::?'a set) (?r::(?'a × ?'a) set); (?b, ?c::?'a) ∈ rtrancl_on ?F ?r⟧ ⟹ (?a, ?c) ∈ rtrancl_on ?F ?r›*) rtrancl_on_into_rtrancl_on (*‹⟦(?a::?'a, ?b::?'a) ∈ rtrancl_on (?F::?'a set) (?r::(?'a × ?'a) set); (?b, ?c::?'a) ∈ ?r; ?c ∈ ?F⟧ ⟹ (?a, ?c) ∈ rtrancl_on ?F ?r›*)) qed (auto) (*solved the remaining goal: ‹y ∈ F ⟹ (y, y) ∈ rtrancl_on F (r¯)›*) theorem rtrancl_on_converseD: assumes "(y, x) ∈ rtrancl_on F (r¯)" shows "(x, y) ∈ rtrancl_on F r" using assms (*‹(y, x) ∈ rtrancl_on F (r¯)›*) apply - (*goal: ‹(x, y) ∈ rtrancl_on F r›*) apply (drule rtrancl_on_converseI (*‹(?y::?'a, ?x::?'a) ∈ rtrancl_on (?F::?'a set) (?r::(?'a × ?'a) set) ⟹ (?x, ?y) ∈ rtrancl_on ?F (?r¯)›*)) (*goal: ‹(y::'a, x::'a) ∈ rtrancl_on (F::'a set) ((r::('a × 'a) set)¯) ⟹ (x, y) ∈ rtrancl_on F r›*) by simp lemma converse_rtrancl_on_induct[consumes 1, case_names base step, induct set: rtrancl_on]: assumes major: "(a, b) ∈ rtrancl_on F r" and cases: "b ∈ F ⟹ P b" "⋀x y. ⟦(x,y) ∈ r; (y,b) ∈ rtrancl_on F r; x ∈ F; y ∈ F; P y⟧ ⟹ P x" shows "P a" using rtrancl_on_converseI[OF major] (*‹(b::'a, a::'a) ∈ rtrancl_on (F::'a set) ((r::('a × 'a) set)¯)›*) cases (*‹(b::'a) ∈ (F::'a set) ⟹ (P::'a ⇒ bool) b› ‹⟦(?x, ?y) ∈ r; (?y, b) ∈ rtrancl_on F r; ?x ∈ F; ?y ∈ F; P ?y⟧ ⟹ P ?x›*) apply induct (*goals: 1. ‹⟦b ∈ F; b ∈ F ⟹ P b; ⋀x y. ⟦(x, y) ∈ r; (y, b) ∈ rtrancl_on F r; x ∈ F; y ∈ F; P y⟧ ⟹ P x⟧ ⟹ P b› 2. ‹⋀y z. ⟦(b, y) ∈ rtrancl_on F (r¯); (y, z) ∈ r¯; y ∈ F; z ∈ F; ⟦b ∈ F ⟹ P b; ⋀x y. ⟦(x, y) ∈ r; (y, b) ∈ rtrancl_on F r; x ∈ F; y ∈ F; P y⟧ ⟹ P x⟧ ⟹ P y; b ∈ F ⟹ P b; ⋀x y. ⟦(x, y) ∈ r; (y, b) ∈ rtrancl_on F r; x ∈ F; y ∈ F; P y⟧ ⟹ P x⟧ ⟹ P z› discuss goal 1*) apply ((auto intro: rtrancl_on_converseD (*‹(?y, ?x) ∈ rtrancl_on ?F (?r¯) ⟹ (?x, ?y) ∈ rtrancl_on ?F ?r›*))[1]) (*discuss goal 2*) apply ((auto intro: rtrancl_on_converseD (*‹(?y::?'a, ?x::?'a) ∈ rtrancl_on (?F::?'a set) ((?r::(?'a × ?'a) set)¯) ⟹ (?x, ?y) ∈ rtrancl_on ?F ?r›*))[1]) (*proven 2 subgoals*) . lemma converse_rtrancl_on_cases: assumes "(a, b) ∈ rtrancl_on F r" obtains (base) "a = b" "b ∈ F" | (step) c where "(a,c) ∈ r" "(c,b) ∈ rtrancl_on F r" using assms (*‹(a::'a, b::'a) ∈ rtrancl_on (F::'a set) (r::('a × 'a) set)›*) apply induct (*goals: 1. ‹⟦b ∈ F; ⟦b = b; b ∈ F⟧ ⟹ thesis; ⋀c. ⟦(b, c) ∈ r; (c, b) ∈ rtrancl_on F r⟧ ⟹ thesis⟧ ⟹ thesis› 2. ‹⋀x y. ⟦(x, y) ∈ r; (y, b) ∈ rtrancl_on F r; x ∈ F; y ∈ F; ⟦⟦y = b; b ∈ F⟧ ⟹ thesis; ⋀c. ⟦(y, c) ∈ r; (c, b) ∈ rtrancl_on F r⟧ ⟹ thesis⟧ ⟹ thesis; ⟦x = b; b ∈ F⟧ ⟹ thesis; ⋀c. ⟦(x, c) ∈ r; (c, b) ∈ rtrancl_on F r⟧ ⟹ thesis⟧ ⟹ thesis› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma rtrancl_on_sym: assumes "sym r" shows "sym (rtrancl_on F r)" using assms (*‹sym r›*) by (auto simp: sym_conv_converse_eq (*‹sym ?r = (?r¯ = ?r)›*) intro: symI (*‹(⋀x y. (x, y) ∈ ?r ⟹ (y, x) ∈ ?r) ⟹ sym ?r›*) dest: rtrancl_on_converseI (*‹(?y, ?x) ∈ rtrancl_on ?F ?r ⟹ (?x, ?y) ∈ rtrancl_on ?F (?r¯)›*)) lemma rtrancl_on_mono: assumes "s ⊆ r" "F ⊆ G" "(a,b) ∈ rtrancl_on F s" shows "(a,b) ∈ rtrancl_on G r" using assms(3,1,2) (*‹(a, b) ∈ rtrancl_on F s› ‹s ⊆ r› ‹F ⊆ G›*) proof (induct) (*goals: 1. ‹⟦b ∈ F; s ⊆ r; F ⊆ G⟧ ⟹ (b, b) ∈ rtrancl_on G r› 2. ‹⋀x y. ⟦(x, y) ∈ s; (y, b) ∈ rtrancl_on F s; x ∈ F; y ∈ F; ⟦s ⊆ r; F ⊆ G⟧ ⟹ (y, b) ∈ rtrancl_on G r; s ⊆ r; F ⊆ G⟧ ⟹ (x, b) ∈ rtrancl_on G r›*) case (step x y) (*‹(x, y) ∈ s› ‹(y::'a::type, b::'a::type) ∈ rtrancl_on (F::'a::type set) (s::('a::type × 'a::type) set)› ‹x ∈ F› ‹y ∈ F› ‹⟦s ⊆ r; F ⊆ G⟧ ⟹ (y, b) ∈ rtrancl_on G r› ‹s ⊆ r› ‹F ⊆ G›*) show "?case" (*goal: ‹(x, b) ∈ rtrancl_on G r›*) using step (*‹(x, y) ∈ s› ‹(y::'a::type, b::'a::type) ∈ rtrancl_on (F::'a::type set) (s::('a::type × 'a::type) set)› ‹(x::'a) ∈ (F::'a set)› ‹y ∈ F› ‹⟦s ⊆ r; F ⊆ G⟧ ⟹ (y, b) ∈ rtrancl_on G r› ‹(s::('a × 'a) set) ⊆ (r::('a × 'a) set)› ‹F ⊆ G›*) assms (*‹(s::('a × 'a) set) ⊆ (r::('a × 'a) set)› ‹(F::'a::type set) ⊆ (G::'a::type set)› ‹(a, b) ∈ rtrancl_on F s›*) apply (intro converse_rtrancl_on_into_rtrancl_on[OF _ step(5)] (*‹⟦(?a, y) ∈ r; s ⊆ r; F ⊆ G; ?a ∈ G⟧ ⟹ (?a, b) ∈ rtrancl_on G r›*)) (*goals: 1. ‹⟦(x, y) ∈ s; (y, b) ∈ rtrancl_on F s; x ∈ F; y ∈ F; ⟦s ⊆ r; F ⊆ G⟧ ⟹ (y, b) ∈ rtrancl_on G r; s ⊆ r; F ⊆ G; s ⊆ r; F ⊆ G; (a, b) ∈ rtrancl_on F s⟧ ⟹ (x, y) ∈ r› 2. ‹⟦(x, y) ∈ s; (y, b) ∈ rtrancl_on F s; x ∈ F; y ∈ F; ⟦s ⊆ r; F ⊆ G⟧ ⟹ (y, b) ∈ rtrancl_on G r; s ⊆ r; F ⊆ G; s ⊆ r; F ⊆ G; (a, b) ∈ rtrancl_on F s⟧ ⟹ s ⊆ r› 3. ‹⟦(x, y) ∈ s; (y, b) ∈ rtrancl_on F s; x ∈ F; y ∈ F; ⟦s ⊆ r; F ⊆ G⟧ ⟹ (y, b) ∈ rtrancl_on G r; s ⊆ r; F ⊆ G; s ⊆ r; F ⊆ G; (a, b) ∈ rtrancl_on F s⟧ ⟹ F ⊆ G› 4. ‹⟦(x, y) ∈ s; (y, b) ∈ rtrancl_on F s; x ∈ F; y ∈ F; ⟦s ⊆ r; F ⊆ G⟧ ⟹ (y, b) ∈ rtrancl_on G r; s ⊆ r; F ⊆ G; s ⊆ r; F ⊆ G; (a, b) ∈ rtrancl_on F s⟧ ⟹ x ∈ G› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . qed (auto) (*solved the remaining goal: ‹⟦b ∈ F; s ⊆ r; F ⊆ G⟧ ⟹ (b, b) ∈ rtrancl_on G r›*) lemma rtrancl_consistent_rtrancl_on: assumes "(a,b) ∈ r⇧*" and "a ∈ F" "b ∈ F" and consistent: "⋀a b. ⟦ a ∈ F; (a,b) ∈ r ⟧ ⟹ b ∈ F" shows "(a,b) ∈ rtrancl_on F r" using assms(1-3) (*‹(a, b) ∈ r⇧*› ‹a ∈ F› ‹b ∈ F›*) proof (induction rule: converse_rtrancl_induct (*‹⟦(?a, ?b) ∈ ?r⇧*; ?P ?b; ⋀y z. ⟦(y, z) ∈ ?r; (z, ?b) ∈ ?r⇧*; ?P z⟧ ⟹ ?P y⟧ ⟹ ?P ?a›*)) (*goals: 1. ‹⟦(b::'a) ∈ (F::'a set); b ∈ F⟧ ⟹ (b, b) ∈ rtrancl_on F (r::('a × 'a) set)› 2. ‹⋀(y::'a) z::'a. ⟦(y, z) ∈ (r::('a × 'a) set); (z, b::'a) ∈ r⇧*; ⟦z ∈ (F::'a set); b ∈ F⟧ ⟹ (z, b) ∈ rtrancl_on F r; y ∈ F; b ∈ F⟧ ⟹ (y, b) ∈ rtrancl_on F r›*) case (step y z) (*‹(y, z) ∈ r› ‹(z, b) ∈ r⇧*› ‹⟦z ∈ F; b ∈ F⟧ ⟹ (z, b) ∈ rtrancl_on F r› ‹y ∈ F› ‹b ∈ F›*) then have "z ∈ F" apply (rule_tac consistent (*‹⟦?a ∈ F; (?a, ?b) ∈ r⟧ ⟹ ?b ∈ F›*)) (*goals: 1. ‹⟦(y, z) ∈ r; (z, b) ∈ r⇧*; ⟦z ∈ F; b ∈ F⟧ ⟹ (z, b) ∈ rtrancl_on F r; y ∈ F; b ∈ F⟧ ⟹ ?a5 ∈ F› 2. ‹⟦(y, z) ∈ r; (z, b) ∈ r⇧*; ⟦z ∈ F; b ∈ F⟧ ⟹ (z, b) ∈ rtrancl_on F r; y ∈ F; b ∈ F⟧ ⟹ (?a5, z) ∈ r› discuss goal 1*) apply simp (*discuss goal 2*) . (*proven 2 subgoals*) with step (*‹(y, z) ∈ r› ‹(z, b) ∈ r⇧*› ‹⟦z ∈ F; b ∈ F⟧ ⟹ (z, b) ∈ rtrancl_on F r› ‹y ∈ F› ‹b ∈ F›*) have "(z,b) ∈ rtrancl_on F r" by simp with step.prems (*‹y ∈ F› ‹b ∈ F›*) ‹(y,z) ∈ r› (*‹(y, z) ∈ r›*) ‹z ∈ F› (*‹z ∈ F›*) show "?case" (*goal: ‹(y, b) ∈ rtrancl_on F r›*) using converse_rtrancl_on_into_rtrancl_on (*‹⟦(?a, ?b) ∈ ?r; (?b, ?c) ∈ rtrancl_on ?F ?r; ?a ∈ ?F⟧ ⟹ (?a, ?c) ∈ rtrancl_on ?F ?r›*) by metis qed (simp) (*solved the remaining goal: ‹⟦b ∈ F; b ∈ F⟧ ⟹ (b, b) ∈ rtrancl_on F r›*) lemma rtrancl_on_rtranclI: "(a,b) ∈ rtrancl_on F r ⟹ (a,b) ∈ r⇧*" apply (induct rule: rtrancl_on_induct (*‹⟦(?a, ?b) ∈ rtrancl_on ?F ?r; ?a ∈ ?F ⟹ ?P ?a; ⋀y z. ⟦(?a, y) ∈ rtrancl_on ?F ?r; (y, z) ∈ ?r; y ∈ ?F; z ∈ ?F; ?P y⟧ ⟹ ?P z⟧ ⟹ ?P ?b›*)) (*goals: 1. ‹a ∈ F ⟹ (a, a) ∈ r⇧*› 2. ‹⋀y z. ⟦(a, y) ∈ rtrancl_on F r; (y, z) ∈ r; y ∈ F; z ∈ F; (a, y) ∈ r⇧*⟧ ⟹ (a, z) ∈ r⇧*› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma rtrancl_on_sub_rtrancl: "rtrancl_on F r ⊆ r^*" using rtrancl_on_rtranclI (*‹(?a, ?b) ∈ rtrancl_on ?F ?r ⟹ (?a, ?b) ∈ ?r⇧*›*) by auto end
{ "path": "afp-2025-02-12/thys/Graph_Theory/Rtrancl_On.thy", "repo": "afp-2025-02-12", "sha": "e4b20bfc6a16e6043cf17779dfea1ec152893192e2490230a68fda2b21fb7e3b" }
theory MutableRefProps imports MutableRef begin inductive_cases vfun_le_inv[elim!]: "VFun t1 ⊑ VFun t2" and le_fun_nat_inv[elim!]: "VFun t2 ⊑ VNat x1" and le_any_nat_inv[elim!]: "v ⊑ VNat n" and le_nat_any_inv[elim!]: "VNat n ⊑ v" and le_fun_any_inv[elim!]: "VFun t ⊑ v" and le_any_fun_inv[elim!]: "v ⊑ VFun t" and le_pair_any_inv[elim!]: "VPair v1 v2 ⊑ v" and le_any_pair_inv[elim!]: "v ⊑ VPair v1 v2" and le_addr_any_inv[elim!]: "VAddr a ⊑ v" and le_any_addr_inv[elim!]: "v ⊑ VAddr a" and le_wrong_any_inv[elim!]: "Wrong ⊑ v" and le_any_wrong_inv[elim!]: "v ⊑ Wrong" proposition val_le_refl: "v ⊑ v" apply (induction v) (*goals: 1. ‹⋀x. VNat x ⊑ VNat x› 2. ‹⋀x. ⟦⋀xa xa1. ⟦xa |∈| x; xa1 ∈ Basic_BNFs.fsts xa⟧ ⟹ xa1 ⊑ xa1; ⋀xa xa2. ⟦xa |∈| x; xa2 ∈ Basic_BNFs.snds xa⟧ ⟹ xa2 ⊑ xa2⟧ ⟹ VFun x ⊑ VFun x› 3. ‹⋀v1 v2. ⟦v1 ⊑ v1; v2 ⊑ v2⟧ ⟹ VPair v1 v2 ⊑ VPair v1 v2› 4. ‹⋀x. VAddr x ⊑ VAddr x› 5. ‹Wrong ⊑ Wrong› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . proposition val_le_trans: "⟦ v1 ⊑ v2; v2 ⊑ v3 ⟧ ⟹ v1 ⊑ v3" apply (induction v2 arbitrary: v1 v3) (*goals: 1. ‹⋀(x::nat) (v1::val) v3::val. ⟦v1 ⊑ VNat x; VNat x ⊑ v3⟧ ⟹ v1 ⊑ v3› 2. ‹⋀(x::(val × val) fset) (v1::val) v3::val. ⟦⋀(xa::val × val) (xa1::val) (v1::val) v3::val. ⟦xa |∈| x; xa1 ∈ Basic_BNFs.fsts xa; v1 ⊑ xa1; xa1 ⊑ v3⟧ ⟹ v1 ⊑ v3; ⋀(xa::val × val) (xa2::val) (v1::val) v3::val. ⟦xa |∈| x; xa2 ∈ Basic_BNFs.snds xa; v1 ⊑ xa2; xa2 ⊑ v3⟧ ⟹ v1 ⊑ v3; v1 ⊑ VFun x; VFun x ⊑ v3⟧ ⟹ v1 ⊑ v3› 3. ‹⋀(v21::val) (v22::val) (v1::val) v3::val. ⟦⋀(v1::val) v3::val. ⟦v1 ⊑ v21; v21 ⊑ v3⟧ ⟹ v1 ⊑ v3; ⋀(v1::val) v3::val. ⟦v1 ⊑ v22; v22 ⊑ v3⟧ ⟹ v1 ⊑ v3; v1 ⊑ VPair v21 v22; VPair v21 v22 ⊑ v3⟧ ⟹ v1 ⊑ v3› 4. ‹⋀(x::nat) (v1::val) v3::val. ⟦v1 ⊑ VAddr x; VAddr x ⊑ v3⟧ ⟹ v1 ⊑ v3› 5. ‹⋀(v1::val) v3::val. ⟦v1 ⊑ Wrong; Wrong ⊑ v3⟧ ⟹ v1 ⊑ v3› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*discuss goal 3*) apply blast (*discuss goal 4*) apply blast (*discuss goal 5*) apply blast (*proven 5 subgoals*) . proposition val_le_antisymm: "⟦ v1 ⊑ v2; v2 ⊑ v1 ⟧ ⟹ v1 = v2" apply (induction v1 arbitrary: v2) (*goals: 1. ‹⋀x v2. ⟦VNat x ⊑ v2; v2 ⊑ VNat x⟧ ⟹ VNat x = v2› 2. ‹⋀x v2. ⟦⋀xa xa1 v2. ⟦xa |∈| x; xa1 ∈ Basic_BNFs.fsts xa; xa1 ⊑ v2; v2 ⊑ xa1⟧ ⟹ xa1 = v2; ⋀xa xa2 v2. ⟦xa |∈| x; xa2 ∈ Basic_BNFs.snds xa; xa2 ⊑ v2; v2 ⊑ xa2⟧ ⟹ xa2 = v2; VFun x ⊑ v2; v2 ⊑ VFun x⟧ ⟹ VFun x = v2› 3. ‹⋀v11 v12 v2. ⟦⋀v2. ⟦v11 ⊑ v2; v2 ⊑ v11⟧ ⟹ v11 = v2; ⋀v2. ⟦v12 ⊑ v2; v2 ⊑ v12⟧ ⟹ v12 = v2; VPair v11 v12 ⊑ v2; v2 ⊑ VPair v11 v12⟧ ⟹ VPair v11 v12 = v2› 4. ‹⋀x v2. ⟦VAddr x ⊑ v2; v2 ⊑ VAddr x⟧ ⟹ VAddr x = v2› 5. ‹⋀v2. ⟦Wrong ⊑ v2; v2 ⊑ Wrong⟧ ⟹ Wrong = v2› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*discuss goal 3*) apply blast (*discuss goal 4*) apply blast (*discuss goal 5*) apply blast (*proven 5 subgoals*) . end
{ "path": "afp-2025-02-12/thys/Decl_Sem_Fun_PL/MutableRefProps.thy", "repo": "afp-2025-02-12", "sha": "b43e9f8027708f98fe18de7fdb733097d126ebaeb22008b77c94be6c7c3ab7ee" }
(* Title: Isabelle Collections Library Author: Peter Lammich <peter dot lammich at uni-muenster.de> Maintainer: Peter Lammich <peter dot lammich at uni-muenster.de> *) (* Changes since submission on 2009-11-26: 2009-12-10: OrderedMap, algorithms for iterators, min, max, to_sorted_list *) section ‹\isaheader{Generic Algorithms for Maps}› theory MapGA imports SetIteratorCollectionsGA begin text_raw ‹\label{thy:MapGA}› record ('k,'v,'s) map_basic_ops = bmap_op_α :: "('k,'v,'s) map_α" bmap_op_invar :: "('k,'v,'s) map_invar" bmap_op_empty :: "('k,'v,'s) map_empty" bmap_op_lookup :: "('k,'v,'s) map_lookup" bmap_op_update :: "('k,'v,'s) map_update" bmap_op_update_dj :: "('k,'v,'s) map_update_dj" bmap_op_delete :: "('k,'v,'s) map_delete" bmap_op_list_it :: "('k,'v,'s) map_list_it" record ('k,'v,'s) omap_basic_ops = "('k,'v,'s) map_basic_ops" + bmap_op_ordered_list_it :: "'s ⇒ ('k,'v,('k×'v) list) map_iterator" bmap_op_rev_list_it :: "'s ⇒ ('k,'v,('k×'v) list) map_iterator" locale StdBasicMapDefs = poly_map_iteratei_defs "bmap_op_list_it ops" for ops :: "('k,'v,'s,'more) map_basic_ops_scheme" begin abbreviation α where "α == bmap_op_α ops" abbreviation invar where "invar == bmap_op_invar ops" abbreviation empty where "empty == bmap_op_empty ops" abbreviation lookup where "lookup == bmap_op_lookup ops" abbreviation update where "update == bmap_op_update ops" abbreviation update_dj where "update_dj == bmap_op_update_dj ops" abbreviation delete where "delete == bmap_op_delete ops" abbreviation list_it where "list_it == bmap_op_list_it ops" end locale StdBasicOMapDefs = StdBasicMapDefs ops + poly_map_iterateoi_defs "bmap_op_ordered_list_it ops" + poly_map_rev_iterateoi_defs "bmap_op_rev_list_it ops" for ops :: "('k::linorder,'v,'s,'more) omap_basic_ops_scheme" begin abbreviation ordered_list_it where "ordered_list_it ≡ bmap_op_ordered_list_it ops" abbreviation rev_list_it where "rev_list_it ≡ bmap_op_rev_list_it ops" end locale StdBasicMap = StdBasicMapDefs ops + map α invar + map_empty α invar empty + map_lookup α invar lookup + map_update α invar update + map_update_dj α invar update_dj + map_delete α invar delete + poly_map_iteratei α invar list_it for ops :: "('k,'v,'s,'more) map_basic_ops_scheme" begin lemmas correct[simp] = empty_correct lookup_correct update_correct update_dj_correct delete_correct end locale StdBasicOMap = StdBasicOMapDefs ops + StdBasicMap ops + poly_map_iterateoi α invar ordered_list_it + poly_map_rev_iterateoi α invar rev_list_it for ops :: "('k::linorder,'v,'s,'more) omap_basic_ops_scheme" begin end context StdBasicMapDefs begin definition "g_sng k v ≡ update k v (empty ())" definition "g_add m1 m2 ≡ iterate m2 (λ(k,v) σ. update k v σ) m1" definition "g_sel m P ≡ iteratei m (λσ. σ = None) (λx σ. if P x then Some x else None) None" definition "g_bex m P ≡ iteratei m (λx. ¬x) (λkv σ. P kv) False" definition "g_ball m P ≡ iteratei m id (λkv σ. P kv) True" definition "g_size m ≡ iterate m (λ_. Suc) (0::nat)" definition "g_size_abort b m ≡ iteratei m (λs. s<b) (λ_. Suc) (0::nat)" definition "g_isEmpty m ≡ g_size_abort 1 m = 0" definition "g_isSng m ≡ g_size_abort 2 m = 1" definition "g_to_list m ≡ iterate m (#) []" definition "g_list_to_map l ≡ foldl (λm (k,v). update k v m) (empty ()) (rev l)" definition "g_add_dj m1 m2 ≡ iterate m2 (λ(k,v) σ. update_dj k v σ) m1" definition "g_restrict P m ≡ iterate m (λ(k,v) σ. if P (k,v) then update_dj k v σ else σ) (empty ())" definition dflt_ops :: "('k,'v,'s) map_ops" where [icf_rec_def]: "dflt_ops ≡ ⦇ map_op_α = α, map_op_invar = invar, map_op_empty = empty, map_op_lookup = lookup, map_op_update = update, map_op_update_dj = update_dj, map_op_delete = delete, map_op_list_it = list_it, map_op_sng = g_sng, map_op_restrict = g_restrict, map_op_add = g_add, map_op_add_dj = g_add_dj, map_op_isEmpty = g_isEmpty, map_op_isSng = g_isSng, map_op_ball = g_ball, map_op_bex = g_bex, map_op_size = g_size, map_op_size_abort = g_size_abort, map_op_sel = g_sel, map_op_to_list = g_to_list, map_op_to_map = g_list_to_map ⦈" local_setup ‹Locale_Code.lc_decl_del @{term dflt_ops}› end lemma update_dj_by_update: assumes "map_update α invar update" shows "map_update_dj α invar update" proof (-) (*goal: ‹map_update_dj α invar update›*) interpret map_update "α" invar update by fact show "?thesis" (*goal: ‹map_update_dj (α::'a ⇒ 'b ⇒ 'c option) (invar::'a ⇒ bool) (update::'b ⇒ 'c ⇒ 'a ⇒ 'a)›*) apply unfold_locales (*goals: 1. ‹⋀m k v. ⟦invar m; k ∉ dom (α m)⟧ ⟹ α (update k v m) = (α m)(k ↦ v)› 2. ‹⋀m k v. ⟦invar m; k ∉ dom (α m)⟧ ⟹ invar (update k v m)› discuss goal 1*) apply ((auto simp add: update_correct (*‹(invar::'a ⇒ bool) (?m::'a) ⟹ (α::'a ⇒ 'b ⇒ 'c option) ((update::'b ⇒ 'c ⇒ 'a ⇒ 'a) (?k::'b) (?v::'c) ?m) = (α ?m)(?k ↦ ?v)› ‹(invar::'a ⇒ bool) (?m::'a) ⟹ invar ((update::'b ⇒ 'c ⇒ 'a ⇒ 'a) (?k::'b) (?v::'c) ?m)›*))[1]) (*discuss goal 2*) apply ((auto simp add: update_correct (*‹invar ?m ⟹ α (update ?k ?v ?m) = (α ?m)(?k ↦ ?v)› ‹invar ?m ⟹ invar (update ?k ?v ?m)›*))[1]) (*proven 2 subgoals*) . qed lemma map_iterator_linord_is_it: "map_iterator_linord m it ⟹ map_iterator m it" unfolding set_iterator_def set_iterator_map_linord_def (*goal: ‹map_iterator_genord m it (λ(k, uu_) (k', uu_). k ≤ k') ⟹ map_iterator_genord m it (λ_ _. True)›*) apply (erule set_iterator_genord.set_iterator_weaken_R (*‹⟦set_iterator_genord ?iti ?S0.0 ?R; ⋀x y. ⟦x ∈ ?S0.0; y ∈ ?S0.0; ?R x y⟧ ⟹ ?R' x y⟧ ⟹ set_iterator_genord ?iti ?S0.0 ?R'›*)) (*goal: ‹map_iterator_genord m it (λ(k, uu_) (k', uu_). k ≤ k') ⟹ map_iterator_genord m it (λ_ _. True)›*) by standard lemma map_rev_iterator_linord_is_it: "map_iterator_rev_linord m it ⟹ map_iterator m it" sorry context StdBasicMap begin lemma g_sng_impl: "map_sng α invar g_sng" sorry lemma g_add_impl: "map_add α invar g_add" proof (standard) (*goals: 1. ‹⋀m1 m2. ⟦invar m1; invar m2⟧ ⟹ α (g_add m1 m2) = α m1 ++ α m2› 2. ‹⋀m1 m2. ⟦invar m1; invar m2⟧ ⟹ invar (g_add m1 m2)›*) fix m1 and m2 assume "invar m1" "invar m2" (*‹invar (m1::'s)› ‹invar (m2::'s)›*) have A: "g_add m1 m2 = iterate_add_to_map m1 update (iteratei m2)" unfolding g_add_def iterate_add_to_map_def (*goal: ‹iterate m2 (λ(x, y). update x y) m1 = iterate m2 (λ(x, y). update x y) m1›*) by simp have "α (g_add m1 m2) = α m1 ++ α m2 ∧ invar (g_add m1 m2)" unfolding A (*goal: ‹α (iterate_add_to_map (m1::'s::type) update (iteratei (m2::'s::type))) = α m1 ++ α m2 ∧ invar (iterate_add_to_map m1 update (iteratei m2))›*) apply (rule iterate_add_to_map_correct[of α invar update m1 "iteratei m2" "α m2"] (*‹⟦map_update α invar update; invar m1; map_iterator (iteratei m2) (α m2)⟧ ⟹ α (iterate_add_to_map m1 update (iteratei m2)) = α m1 ++ α m2 ∧ invar (iterate_add_to_map m1 update (iteratei m2))›*)) (*goals: 1. ‹map_update α invar update› 2. ‹invar m1› 3. ‹map_iterator (iteratei m2) (α m2)› discuss goal 1*) apply unfold_locales (*discuss goal 2*) apply fact (*discuss goal 3*) apply (rule iteratei_correct (*‹invar ?S ⟹ map_iterator (iteratei ?S) (α ?S)›*)) (*goal: ‹map_iterator (iteratei (m2::'s::type)) (α m2)›*) apply fact (*proven 3 subgoals*) . thus "α (g_add m1 m2) = α m1 ++ α m2" "invar (g_add m1 m2)" apply - (*goals: 1. ‹α (g_add m1 m2) = α m1 ++ α m2 ∧ invar (g_add m1 m2) ⟹ α (g_add m1 m2) = α m1 ++ α m2› 2. ‹α (g_add m1 m2) = α m1 ++ α m2 ∧ invar (g_add m1 m2) ⟹ invar (g_add m1 m2)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed lemma g_sel_impl: "map_sel' α invar g_sel" proof (-) (*goal: ‹map_sel' α invar g_sel›*) have A: "⋀m P. g_sel m P = iterate_sel_no_map (iteratei m) P" unfolding g_sel_def iterate_sel_no_map_def iterate_sel_def (*goal: ‹⋀m P. iteratei m (λσ. σ = None) (λx σ. if P x then Some x else None) None = iteratei m (λσ. σ = None) (λx σ. if P x then Some x else None) None›*) by simp { fix m and P assume I: "invar m" (*‹invar (m::'s)›*) note iterate_sel_no_map_correct[OF iteratei_correct [ OF I ], of P] (*‹(iterate_sel_no_map (iteratei (m::'s)) (P::'k × 'v ⇒ bool) = None) = (∀x::'k × 'v∈map_to_set (α m). ¬ P x)› ‹iterate_sel_no_map (iteratei m) P = Some ?x ⟹ ?x ∈ map_to_set (α m) ∧ P ?x›*) } thus "?thesis" (*goal: ‹map_sel' α invar g_sel›*) apply unfold_locales (*goal: ‹map_sel' α invar g_sel›*) unfolding A (*goals: 1. ‹⋀(m::'s) (u::'k) (v::'v) (P::'k × 'v ⇒ bool) Q::bool. ⟦⋀(m::'s) P::'k × 'v ⇒ bool. invar m ⟹ (iterate_sel_no_map (iteratei m) P = None) = (∀x::'k × 'v∈map_to_set (α m). ¬ P x); ⋀(m::'s) (P::'k × 'v ⇒ bool) x::'k × 'v. ⟦invar m; iterate_sel_no_map (iteratei m) P = Some x⟧ ⟹ x ∈ map_to_set (α m) ∧ P x; invar m; α m u = Some v; P (u, v); ⋀(u::'k) v::'v. ⟦iterate_sel_no_map (iteratei m) P = Some (u, v); α m u = Some v; P (u, v)⟧ ⟹ Q⟧ ⟹ Q› 2. ‹⋀(m::'s) P::'k × 'v ⇒ bool. ⟦⋀(m::'s) P::'k × 'v ⇒ bool. invar m ⟹ (iterate_sel_no_map (iteratei m) P = None) = (∀x::'k × 'v∈map_to_set (α m). ¬ P x); ⋀(m::'s) (P::'k × 'v ⇒ bool) x::'k × 'v. ⟦invar m; iterate_sel_no_map (iteratei m) P = Some x⟧ ⟹ x ∈ map_to_set (α m) ∧ P x; invar m; ∀(u::'k) v::'v. α m u = Some v ⟶ ¬ P (u, v)⟧ ⟹ iterate_sel_no_map (iteratei m) P = None›*) (*goals: 1. ‹⋀m u v P Q. ⟦⋀m P. invar m ⟹ (iterate_sel_no_map (iteratei m) P = None) = (∀x∈map_to_set (α m). ¬ P x); ⋀m P x. ⟦invar m; iterate_sel_no_map (iteratei m) P = Some x⟧ ⟹ x ∈ map_to_set (α m) ∧ P x; invar m; α m u = Some v; P (u, v); ⋀u v. ⟦iterate_sel_no_map (iteratei m) P = Some (u, v); α m u = Some v; P (u, v)⟧ ⟹ Q⟧ ⟹ Q› 2. ‹⋀m P. ⟦⋀m P. invar m ⟹ (iterate_sel_no_map (iteratei m) P = None) = (∀x∈map_to_set (α m). ¬ P x); ⋀m P x. ⟦invar m; iterate_sel_no_map (iteratei m) P = Some x⟧ ⟹ x ∈ map_to_set (α m) ∧ P x; invar m; ∀u v. α m u = Some v ⟶ ¬ P (u, v)⟧ ⟹ iterate_sel_no_map (iteratei m) P = None› discuss goal 1*) apply (simp add: Bex_def (*‹Bex ?A ?P = (∃x. x ∈ ?A ∧ ?P x)›*) Ball_def (*‹Ball ?A ?P = (∀x. x ∈ ?A ⟶ ?P x)›*) image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*) map_to_set_def (*‹map_to_set ?m = {(k, v). ?m k = Some v}›*)) (*top goal: ‹⋀m u v P Q. ⟦⋀m P. invar m ⟹ (iterate_sel_no_map (iteratei m) P = None) = (∀x∈map_to_set (α m). ¬ P x); ⋀m P x. ⟦invar m; iterate_sel_no_map (iteratei m) P = Some x⟧ ⟹ x ∈ map_to_set (α m) ∧ P x; invar m; α m u = Some v; P (u, v); ⋀u v. ⟦iterate_sel_no_map (iteratei m) P = Some (u, v); α m u = Some v; P (u, v)⟧ ⟹ Q⟧ ⟹ Q› and 1 goal remains*) apply clarify (*top goal: ‹⋀m u v P Q. ⟦⋀m P. invar m ⟹ (iterate_sel_no_map (iteratei m) P = None) = (∀a b. α m a = Some b ⟶ ¬ P (a, b)); ⋀m P x. ⟦invar m; iterate_sel_no_map (iteratei m) P = Some x⟧ ⟹ (case x of (k, v) ⇒ α m k = Some v) ∧ P x; invar m; α m u = Some v; P (u, v); ⋀u v. ⟦iterate_sel_no_map (iteratei m) P = Some (u, v); α m u = Some v; P (u, v)⟧ ⟹ Q⟧ ⟹ Q› and 1 goal remains*) apply (metis option.exhaust (*‹⟦(?y::?'a option) = None ⟹ ?P::bool; ⋀x2::?'a. ?y = Some x2 ⟹ ?P⟧ ⟹ ?P›*) prod.exhaust (*‹(⋀(x1::?'a) x2::?'b. (?y::?'a × ?'b) = (x1, x2) ⟹ ?P::bool) ⟹ ?P›*)) (*discuss goal 2*) apply (simp add: Bex_def (*‹Bex ?A ?P = (∃x. x ∈ ?A ∧ ?P x)›*) Ball_def (*‹Ball ?A ?P = (∀x. x ∈ ?A ⟶ ?P x)›*) image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*) map_to_set_def (*‹map_to_set ?m = {(k, v). ?m k = Some v}›*)) (*proven 2 subgoals*) . qed lemma g_bex_impl: "map_bex α invar g_bex" apply unfold_locales (*goal: ‹map_bex α invar g_bex›*) unfolding g_bex_def (*goal: ‹⋀m P. invar m ⟹ iteratei m Not (λkv σ. P kv) False = (∃u v. α m u = Some v ∧ P (u, v))›*) apply (rule_tac I="λit σ. σ ⟷ (∃kv∈it. P kv)" in iteratei_rule_insert_P (*‹⟦invar ?m; ?I {} ?σ0.0; ⋀k v it σ. ⟦?c σ; (k, v) ∈ map_to_set (α ?m) - it; it ⊆ map_to_set (α ?m); ?I it σ⟧ ⟹ ?I (insert (k, v) it) (?f (k, v) σ); ⋀σ. ?I (map_to_set (α ?m)) σ ⟹ ?P σ; ⋀σ it. ⟦it ⊆ map_to_set (α ?m); it ≠ map_to_set (α ?m); ¬ ?c σ; ?I it σ⟧ ⟹ ?P σ⟧ ⟹ ?P (iteratei ?m ?c ?f ?σ0.0)›*)) (*goals: 1. ‹⋀(m::'s::type) P::'k::type × 'v::type ⇒ bool. invar m ⟹ invar m› 2. ‹⋀(m::'s::type) P::'k::type × 'v::type ⇒ bool. invar m ⟹ False = (∃kv::'k::type × 'v::type∈{}. P kv)› 3. ‹⋀(m::'s::type) (P::'k::type × 'v::type ⇒ bool) (k::'k::type) (v::'v::type) (it::('k::type × 'v::type) set) σ::bool. ⟦invar m; ¬ σ; (k, v) ∈ map_to_set (α m) - it; it ⊆ map_to_set (α m); σ = (∃kv::'k::type × 'v::type∈it. P kv)⟧ ⟹ P (k, v) = (∃kv::'k::type × 'v::type∈insert (k, v) it. P kv)› 4. ‹⋀(m::'s::type) (P::'k::type × 'v::type ⇒ bool) σ::bool. ⟦invar m; σ = (∃kv::'k::type × 'v::type∈map_to_set (α m). P kv)⟧ ⟹ σ = (∃(u::'k::type) v::'v::type. α m u = Some v ∧ P (u, v))› 5. ‹⋀(m::'s::type) (P::'k::type × 'v::type ⇒ bool) (σ::bool) it::('k::type × 'v::type) set. ⟦invar m; it ⊆ map_to_set (α m); it ≠ map_to_set (α m); ¬ ¬ σ; σ = (∃kv::'k::type × 'v::type∈it. P kv)⟧ ⟹ σ = (∃(u::'k::type) v::'v::type. α m u = Some v ∧ P (u, v))› discuss goal 1*) apply ((auto simp: map_to_set_def (*‹map_to_set ?m = {(k, v). ?m k = Some v}›*))[1]) (*discuss goal 2*) apply ((auto simp: map_to_set_def (*‹map_to_set ?m = {(k, v). ?m k = Some v}›*))[1]) (*discuss goal 3*) apply ((auto simp: map_to_set_def (*‹map_to_set ?m = {(k, v). ?m k = Some v}›*))[1]) (*discuss goal 4*) apply ((auto simp: map_to_set_def (*‹map_to_set ?m = {(k, v). ?m k = Some v}›*))[1]) (*discuss goal 5*) apply ((auto simp: map_to_set_def (*‹map_to_set ?m = {(k, v). ?m k = Some v}›*))[1]) (*proven 5 subgoals*) . lemma g_ball_impl: "map_ball α invar g_ball" apply unfold_locales (*goal: ‹map_ball α invar g_ball›*) unfolding g_ball_def (*goal: ‹⋀m P. invar m ⟹ iteratei m id (λkv σ. P kv) True = (∀u v. α m u = Some v ⟶ P (u, v))›*) apply (rule_tac I="λit σ. σ ⟷ (∀kv∈it. P kv)" in iteratei_rule_insert_P (*‹⟦invar ?m; ?I {} ?σ0.0; ⋀k v it σ. ⟦?c σ; (k, v) ∈ map_to_set (α ?m) - it; it ⊆ map_to_set (α ?m); ?I it σ⟧ ⟹ ?I (insert (k, v) it) (?f (k, v) σ); ⋀σ. ?I (map_to_set (α ?m)) σ ⟹ ?P σ; ⋀σ it. ⟦it ⊆ map_to_set (α ?m); it ≠ map_to_set (α ?m); ¬ ?c σ; ?I it σ⟧ ⟹ ?P σ⟧ ⟹ ?P (iteratei ?m ?c ?f ?σ0.0)›*)) (*goals: 1. ‹⋀m P. invar m ⟹ invar m› 2. ‹⋀m P. invar m ⟹ True = (∀kv∈{}. P kv)› 3. ‹⋀m P k v it σ. ⟦invar m; id σ; (k, v) ∈ map_to_set (α m) - it; it ⊆ map_to_set (α m); σ = (∀kv∈it. P kv)⟧ ⟹ P (k, v) = (∀kv∈insert (k, v) it. P kv)› 4. ‹⋀m P σ. ⟦invar m; σ = (∀kv∈map_to_set (α m). P kv)⟧ ⟹ σ = (∀u v. α m u = Some v ⟶ P (u, v))› 5. ‹⋀m P σ it. ⟦invar m; it ⊆ map_to_set (α m); it ≠ map_to_set (α m); ¬ id σ; σ = (∀kv∈it. P kv)⟧ ⟹ σ = (∀u v. α m u = Some v ⟶ P (u, v))› discuss goal 1*) apply ((auto simp: map_to_set_def (*‹map_to_set (?m::?'a ⇒ ?'b option) = {(k::?'a, v::?'b). ?m k = Some v}›*))[1]) (*discuss goal 2*) apply ((auto simp: map_to_set_def (*‹map_to_set ?m = {(k, v). ?m k = Some v}›*))[1]) (*discuss goal 3*) apply ((auto simp: map_to_set_def (*‹map_to_set ?m = {(k, v). ?m k = Some v}›*))[1]) (*discuss goal 4*) apply ((auto simp: map_to_set_def (*‹map_to_set ?m = {(k, v). ?m k = Some v}›*))[1]) (*discuss goal 5*) apply ((auto simp: map_to_set_def (*‹map_to_set (?m::?'a ⇒ ?'b option) = {(k::?'a, v::?'b). ?m k = Some v}›*))[1]) (*proven 5 subgoals*) . lemma g_size_impl: "map_size α invar g_size" proof (standard) (*goal: ‹⋀s. invar s ⟹ g_size s = card (dom (α s))›*) fix m assume I: "invar m" (*‹invar (m::'s)›*) have A: "g_size m ≡ iterate_size (iteratei m)" unfolding g_size_def iterate_size_def (*goal: ‹iterate m (λ_. Suc) 0 ≡ iterate m (λx. Suc) 0›*) by simp from iterate_size_correct[OF iteratei_correct [ OF I ]] (*‹iterate_size (iteratei m) = card (map_to_set (α m)) ∧ finite (map_to_set (α m))›*) show "g_size m = card (dom (α m))" unfolding A (*goal: ‹iterate_size (iteratei m) = card (dom (α m))›*) by (simp add: card_map_to_set (*‹card (map_to_set ?m) = card (dom ?m)›*)) qed lemma g_size_abort_impl: "map_size_abort α invar g_size_abort" proof (standard) (*goal: ‹⋀s m. invar s ⟹ g_size_abort m s = min m (card (dom (α s)))›*) fix s and m assume I: "invar m" (*‹invar (m::'s)›*) have A: "g_size_abort s m ≡ iterate_size_abort (iteratei m) s" unfolding g_size_abort_def iterate_size_abort_def (*goal: ‹iteratei m (λsa. sa < s) (λ_. Suc) 0 ≡ iteratei m (λσ. σ < s) (λx. Suc) 0›*) by simp from iterate_size_abort_correct[OF iteratei_correct [ OF I ]] (*‹iterate_size_abort (iteratei (m::'s::type)) (?n::nat) = min ?n (card (map_to_set (α m))) ∧ finite (map_to_set (α m))›*) show "g_size_abort s m = min s (card (dom (α m)))" unfolding A (*goal: ‹iterate_size_abort (iteratei m) s = min s (card (dom (α m)))›*) by (simp add: card_map_to_set (*‹card (map_to_set ?m) = card (dom ?m)›*)) qed lemma g_isEmpty_impl: "map_isEmpty α invar g_isEmpty" proof (standard) (*goal: ‹⋀m. invar m ⟹ g_isEmpty m = (α m = (λx. None))›*) fix m assume I: "invar m" (*‹invar (m::'s)›*) interpret map_size_abort "α" invar g_size_abort by (rule g_size_abort_impl (*‹map_size_abort α invar g_size_abort›*)) from size_abort_correct[OF I] (*‹g_size_abort ?m m = min ?m (card (dom (α m)))›*) have "g_size_abort 1 m = min 1 (card (dom (α m)))" . thus "g_isEmpty m = (α m = Map.empty)" unfolding g_isEmpty_def (*goal: ‹(g_size_abort 1 m = 0) = (α m = (λx. None))›*) by (auto simp: min_def (*‹min ?a ?b = (if ?a ≤ ?b then ?a else ?b)›*) card_0_eq[OF finite] (*‹invar ?m1 ⟹ (card (dom (α ?m1)) = 0) = (dom (α ?m1) = {})›*) I (*‹invar m›*)) qed lemma g_isSng_impl: "map_isSng α invar g_isSng" proof (standard) (*goal: ‹⋀s. invar s ⟹ g_isSng s = (∃k v. α s = [k ↦ v])›*) fix m assume I: "invar m" (*‹invar (m::'s)›*) interpret map_size_abort "α" invar g_size_abort by (rule g_size_abort_impl (*‹map_size_abort α invar g_size_abort›*)) from size_abort_correct[OF I] (*‹g_size_abort (?m::nat) (m::'s::type) = min ?m (card (dom (α m)))›*) have "g_size_abort 2 m = min 2 (card (dom (α m)))" . thus "g_isSng m = (∃k v. α m = [k ↦ v])" unfolding g_isSng_def (*goal: ‹(g_size_abort 2 m = 1) = (∃k v. α m = [k ↦ v])›*) by (auto simp: min_def (*‹min ?a ?b = (if ?a ≤ ?b then ?a else ?b)›*) I (*‹invar m›*) card_Suc_eq (*‹(card ?A = Suc ?k) = (∃b B. ?A = insert b B ∧ b ∉ B ∧ card B = ?k ∧ (?k = 0 ⟶ B = {}))›*) dom_eq_singleton_conv (*‹(dom ?f = {?x}) = (∃v. ?f = [?x ↦ v])›*)) qed lemma g_to_list_impl: "map_to_list α invar g_to_list" proof (standard) (*goals: 1. ‹⋀m. invar m ⟹ map_of (g_to_list m) = α m› 2. ‹⋀m. invar m ⟹ distinct (map fst (g_to_list m))›*) fix m assume I: "invar m" (*‹invar (m::'s)›*) have A: "g_to_list m = iterate_to_list (iteratei m)" unfolding g_to_list_def iterate_to_list_def (*goal: ‹iterate m (#) [] = iterate m (#) []›*) by simp from iterate_to_list_correct[OF iteratei_correct [ OF I ]] (*‹set (iterate_to_list (iteratei m)) = map_to_set (α m) ∧ distinct (iterate_to_list (iteratei m))›*) have set_l_eq: "set (g_to_list m) = map_to_set (α m)" and dist_l: "distinct (g_to_list m)" unfolding A (*goals: 1. ‹set (iterate_to_list (iteratei m)) = map_to_set (α m)› 2. ‹distinct (iterate_to_list (iteratei m))›*) apply - (*goals: 1. ‹set (iterate_to_list (iteratei m)) = map_to_set (α m) ∧ distinct (iterate_to_list (iteratei m)) ⟹ set (iterate_to_list (iteratei m)) = map_to_set (α m)› 2. ‹set (iterate_to_list (iteratei m)) = map_to_set (α m) ∧ distinct (iterate_to_list (iteratei m)) ⟹ distinct (iterate_to_list (iteratei m))› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . from dist_l (*‹distinct (g_to_list m)›*) show dist_fst_l: "distinct (map fst (g_to_list m))" by (simp add: distinct_map (*‹distinct (map ?f ?xs) = (distinct ?xs ∧ inj_on ?f (set ?xs))›*) set_l_eq (*‹set (g_to_list m) = map_to_set (α m)›*) map_to_set_def (*‹map_to_set ?m = {(k, v). ?m k = Some v}›*) inj_on_def (*‹inj_on ?f ?A = (∀x∈?A. ∀y∈?A. ?f x = ?f y ⟶ x = y)›*)) from map_of_map_to_set[of "(g_to_list m)" "α m", OF dist_fst_l] (*‹(map_of (g_to_list m) = α m) = (set (g_to_list m) = map_to_set (α m))›*) set_l_eq (*‹set (g_to_list (m::'s)) = map_to_set (α m)›*) show "map_of (g_to_list m) = α m" by simp qed lemma g_list_to_map_impl: "list_to_map α invar g_list_to_map" proof (-) (*goal: ‹list_to_map α invar g_list_to_map›*) { fix m0 and l assume "invar m0" (*‹invar (m0::'s)›*) hence "invar (foldl (λs (k,v). update k v s) m0 l) ∧ α (foldl (λs (k,v). update k v s) m0 l) = α m0 ++ map_of (rev l)" proof (induction l arbitrary: m0) (*goals: 1. ‹⋀m0. invar m0 ⟹ invar (foldl (λs (k, v). update k v s) m0 []) ∧ α (foldl (λs (k, v). update k v s) m0 []) = α m0 ++ map_of (rev [])› 2. ‹⋀a l m0. ⟦⋀m0. invar m0 ⟹ invar (foldl (λs (k, v). update k v s) m0 l) ∧ α (foldl (λs (k, v). update k v s) m0 l) = α m0 ++ map_of (rev l); invar m0⟧ ⟹ invar (foldl (λs (k, v). update k v s) m0 (a # l)) ∧ α (foldl (λs (k, v). update k v s) m0 (a # l)) = α m0 ++ map_of (rev (a # l))›*) case Nil (*‹invar m0›*) thus "?case" (*goal: ‹invar (foldl (λs a. case a of (k, v) ⇒ update k v s) m0 []) ∧ α (foldl (λs a. case a of (k, v) ⇒ update k v s) m0 []) = α m0 ++ map_of (rev [])›*) by simp next (*goal: ‹⋀a l m0. ⟦⋀m0. invar m0 ⟹ invar (foldl (λs (k, v). update k v s) m0 l) ∧ α (foldl (λs (k, v). update k v s) m0 l) = α m0 ++ map_of (rev l); invar m0⟧ ⟹ invar (foldl (λs (k, v). update k v s) m0 (a # l)) ∧ α (foldl (λs (k, v). update k v s) m0 (a # l)) = α m0 ++ map_of (rev (a # l))›*) case (Cons kv l) (*‹invar ?m0.2 ⟹ invar (foldl (λs a. case a of (k, v) ⇒ update k v s) ?m0.2 l) ∧ α (foldl (λs a. case a of (k, v) ⇒ update k v s) ?m0.2 l) = α ?m0.2 ++ map_of (rev l)› ‹invar m0›*) obtain k and v where [simp]: "kv=(k,v)" (*goal: ‹(⋀k v. kv = (k, v) ⟹ thesis) ⟹ thesis›*) apply (cases kv) (*goal: ‹(⋀(k::'k) v::'v. (kv::'k × 'v) = (k, v) ⟹ thesis::bool) ⟹ thesis›*) by auto have "invar (foldl (λs (k, v). update k v s) m0 (kv # l))" apply simp (*goal: ‹invar (foldl (λs (k, v). update k v s) m0 (kv # l))›*) apply (rule conjunct1[OF Cons.IH] (*‹invar (?m0.3::'s::type) ⟹ invar (foldl (λ(s::'s::type) a::'k::type × 'v::type. case a of (k::'k::type, v::'v::type) ⇒ update k v s) ?m0.3 (l::('k::type × 'v::type) list))›*)) (*goal: ‹invar (foldl (λs (k, v). update k v s) (update k v m0) l)›*) by (simp add: update_correct (*‹invar ?m ⟹ α (update ?k ?v ?m) = (α ?m)(?k ↦ ?v)› ‹invar ?m ⟹ invar (update ?k ?v ?m)›*) Cons.prems (*‹invar m0›*)) moreover have "α (foldl (λs (k, v). update k v s) m0 (kv # l)) = α m0 ++ map_of (rev (kv # l))" apply simp (*goal: ‹α (foldl (λ(s::'s::type) (k::'k::type, v::'v::type). update k v s) (m0::'s::type) ((kv::'k::type × 'v::type) # (l::('k::type × 'v::type) list))) = α m0 ++ map_of (rev (kv # l))›*) apply (rule trans[OF conjunct2[OF Cons.IH]] (*‹⟦invar ?m0.4; α ?m0.4 ++ map_of (rev l) = ?t⟧ ⟹ α (foldl (λs a. case a of (k, v) ⇒ update k v s) ?m0.4 l) = ?t›*)) (*goals: 1. ‹invar (update k v m0)› 2. ‹α (update k v m0) ++ map_of (rev l) = (α m0)(k ↦ v) ++ map_of (rev l)› discuss goal 1*) apply ((auto simp: update_correct (*‹invar (?m::'s) ⟹ α (update (?k::'k) (?v::'v) ?m) = (α ?m)(?k ↦ ?v)› ‹invar (?m::'s) ⟹ invar (update (?k::'k) (?v::'v) ?m)›*) Cons.prems (*‹invar (m0::'s)›*) Map.map_add_def[abs_def] (*‹(++) ≡ λ(m1::?'a ⇒ ?'b option) (m2::?'a ⇒ ?'b option) x::?'a. case m2 x of None ⇒ m1 x | Some (x::?'b) ⇒ Some x›*) split: option.split (*‹(?P::?'b ⇒ bool) (case ?option::?'a option of None ⇒ ?f1.0::?'b | Some (x::?'a) ⇒ (?f2.0::?'a ⇒ ?'b) x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2::?'a. ?option = Some x2 ⟶ ?P (?f2.0 x2)))›*))[1]) (*discuss goal 2*) apply ((auto simp: update_correct (*‹invar ?m ⟹ α (update ?k ?v ?m) = (α ?m)(?k ↦ ?v)› ‹invar ?m ⟹ invar (update ?k ?v ?m)›*) Cons.prems (*‹invar m0›*) Map.map_add_def[abs_def] (*‹(++) ≡ λm1 m2 x. case m2 x of None ⇒ m1 x | Some x ⇒ Some x›*) split: option.split (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))›*))[1]) (*proven 2 subgoals*) . ultimately show "?case" (*goal: ‹invar (foldl (λ(s::'s) a::'k × 'v. case a of (k::'k, v::'v) ⇒ update k v s) (m0::'s) ((kv::'k × 'v) # (l::('k × 'v) list))) ∧ α (foldl (λ(s::'s) a::'k × 'v. case a of (k::'k, v::'v) ⇒ update k v s) m0 (kv # l)) = α m0 ++ map_of (rev (kv # l))›*) by simp qed } thus "?thesis" (*goal: ‹list_to_map α invar g_list_to_map›*) apply unfold_locales (*goal: ‹list_to_map α invar g_list_to_map›*) unfolding g_list_to_map_def (*goals: 1. ‹⋀l::('k × 'v) list. (⋀(m0::'s) l::('k × 'v) list. invar m0 ⟹ invar (foldl (λ(s::'s) (k::'k, v::'v). update k v s) m0 l) ∧ α (foldl (λ(s::'s) (k::'k, v::'v). update k v s) m0 l) = α m0 ++ map_of (rev l)) ⟹ α (foldl (λ(m::'s) (k::'k, v::'v). update k v m) (local.empty ()) (rev l)) = map_of l› 2. ‹⋀l::('k × 'v) list. (⋀(m0::'s) l::('k × 'v) list. invar m0 ⟹ invar (foldl (λ(s::'s) (k::'k, v::'v). update k v s) m0 l) ∧ α (foldl (λ(s::'s) (k::'k, v::'v). update k v s) m0 l) = α m0 ++ map_of (rev l)) ⟹ invar (foldl (λ(m::'s) (k::'k, v::'v). update k v m) (local.empty ()) (rev l))›*) (*goals: 1. ‹⋀l. (⋀m0 l. invar m0 ⟹ invar (foldl (λs (k, v). update k v s) m0 l) ∧ α (foldl (λs (k, v). update k v s) m0 l) = α m0 ++ map_of (rev l)) ⟹ α (foldl (λm (k, v). update k v m) (local.empty ()) (rev l)) = map_of l› 2. ‹⋀l. (⋀m0 l. invar m0 ⟹ invar (foldl (λs (k, v). update k v s) m0 l) ∧ α (foldl (λs (k, v). update k v s) m0 l) = α m0 ++ map_of (rev l)) ⟹ invar (foldl (λm (k, v). update k v m) (local.empty ()) (rev l))› discuss goal 1*) apply ((auto simp: empty_correct (*‹α (local.empty ()) = (λx. None)› ‹invar (local.empty ())›*))[1]) (*discuss goal 2*) apply ((auto simp: empty_correct (*‹α (local.empty ()) = (λx::'k. None)› ‹invar (local.empty ())›*))[1]) (*proven 2 subgoals*) . qed lemma g_add_dj_impl: "map_add_dj α invar g_add_dj" proof (standard) (*goals: 1. ‹⋀m1 m2. ⟦invar m1; invar m2; dom (α m1) ∩ dom (α m2) = {}⟧ ⟹ α (g_add_dj m1 m2) = α m1 ++ α m2› 2. ‹⋀m1 m2. ⟦invar m1; invar m2; dom (α m1) ∩ dom (α m2) = {}⟧ ⟹ invar (g_add_dj m1 m2)›*) fix m1 and m2 assume "invar m1" "invar m2" and DJ: "dom (α m1) ∩ dom (α m2) = {}" (*‹invar (m1::'s)› ‹invar (m2::'s)› ‹dom (α (m1::'s)) ∩ dom (α (m2::'s)) = {}›*) have A: "g_add_dj m1 m2 = iterate_add_to_map m1 update_dj (iteratei m2)" unfolding g_add_dj_def iterate_add_to_map_def (*goal: ‹iterate m2 (λ(x, y). update_dj x y) m1 = iterate m2 (λ(x, y). update_dj x y) m1›*) by simp have "α (g_add_dj m1 m2) = α m1 ++ α m2 ∧ invar (g_add_dj m1 m2)" unfolding A (*goal: ‹α (iterate_add_to_map m1 update_dj (iteratei m2)) = α m1 ++ α m2 ∧ invar (iterate_add_to_map m1 update_dj (iteratei m2))›*) apply (rule iterate_add_to_map_dj_correct[ of α invar update_dj m1 "iteratei m2" "α m2"] (*‹⟦map_update_dj α invar update_dj; invar m1; map_iterator (iteratei m2) (α m2); dom (α m2) ∩ dom (α m1) = {}⟧ ⟹ α (iterate_add_to_map m1 update_dj (iteratei m2)) = α m1 ++ α m2 ∧ invar (iterate_add_to_map m1 update_dj (iteratei m2))›*)) (*goal: ‹α (iterate_add_to_map m1 update_dj (iteratei m2)) = α m1 ++ α m2 ∧ invar (iterate_add_to_map m1 update_dj (iteratei m2))›*) apply ((unfold_locales)[1]) (*top goal: ‹map_update_dj α invar update_dj› and 3 goals remain*) apply fact (*top goal: ‹invar m1› and 2 goals remain*) apply (rule iteratei_correct (*‹invar ?S ⟹ map_iterator (iteratei ?S) (α ?S)›*), fact) (*top goal: ‹map_iterator (iteratei m2) (α m2)› and 1 goal remains*) using DJ (*‹dom (α (m1::'s::type)) ∩ dom (α (m2::'s::type)) = {}›*) by (simp add: Int_ac (*‹?A ∩ ?B ∩ ?C = ?A ∩ (?B ∩ ?C)› ‹?A ∩ (?A ∩ ?B) = ?A ∩ ?B› ‹?A ∩ ?B = ?B ∩ ?A› ‹?A ∩ (?B ∩ ?C) = ?B ∩ (?A ∩ ?C)›*)) thus "α (g_add_dj m1 m2) = α m1 ++ α m2" "invar (g_add_dj m1 m2)" apply - (*goals: 1. ‹α (g_add_dj m1 m2) = α m1 ++ α m2 ∧ invar (g_add_dj m1 m2) ⟹ α (g_add_dj m1 m2) = α m1 ++ α m2› 2. ‹α (g_add_dj m1 m2) = α m1 ++ α m2 ∧ invar (g_add_dj m1 m2) ⟹ invar (g_add_dj m1 m2)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed lemma g_restrict_impl: "map_restrict α invar α invar g_restrict" proof (standard) (*goals: 1. ‹⋀m P. invar m ⟹ α (g_restrict P m) = α m |` {k. ∃v. α m k = Some v ∧ P (k, v)}› 2. ‹⋀m P. invar m ⟹ invar (g_restrict P m)›*) fix m and P assume I: "invar m" (*‹invar (m::'s)›*) have AUX: "⋀k v it σ. ⟦it ⊆ {(k, v). α m k = Some v}; α m k = Some v; (k, v) ∉ it; {(k, v). α σ k = Some v} = it ∩ Collect P⟧ ⟹ k ∉ dom (α σ)" apply (rule ccontr (*‹(¬ (?P::bool) ⟹ False) ⟹ ?P›*)) (*goal: ‹⋀k v it σ. ⟦it ⊆ {(k, v). α m k = Some v}; α m k = Some v; (k, v) ∉ it; {(k, v). α σ k = Some v} = it ∩ Collect P⟧ ⟹ k ∉ dom (α σ)›*) proof (simp) (*goal: ‹⋀k v it σ. ⟦it ⊆ {(k, v). α m k = Some v}; α m k = Some v; (k, v) ∉ it; {(k, v). α σ k = Some v} = it ∩ Collect P; k ∈ dom (α σ)⟧ ⟹ False›*) fix k and v and it and σ assume "k∈dom (α σ)" (*‹(k::'k) ∈ dom (α (σ::'s))›*) then obtain v' where "α σ k = Some v'" (*goal: ‹(⋀v'. α σ k = Some v' ⟹ thesis) ⟹ thesis›*) by auto moreover assume "{(k, v). α σ k = Some v} = it ∩ Collect P" (*‹{(k::'k, v::'v). α (σ::'s) k = Some v} = (it::('k × 'v) set) ∩ Collect (P::'k × 'v ⇒ bool)›*) ultimately have MEM: "(k,v')∈it" by auto moreover assume "it ⊆ {(k, v). α m k = Some v}" and "α m k = Some v" (*‹(it::('k × 'v) set) ⊆ {(k::'k, v::'v). α (m::'s) k = Some v}› ‹α (m::'s) (k::'k) = Some (v::'v)›*) ultimately have "v'=v" by auto moreover assume "(k,v)∉it" (*‹(k::'k, v::'v) ∉ (it::('k × 'v) set)›*) moreover note MEM (*‹(k, v') ∈ it›*) ultimately show False by simp qed have "α (g_restrict P m) = α m |` {k. ∃v. α m k = Some v ∧ P (k, v)} ∧ invar (g_restrict P m)" unfolding g_restrict_def (*goal: ‹α (iterate m (λ(k, v) σ. if P (k, v) then update_dj k v σ else σ) (local.empty ())) = α m |` {k. ∃v. α m k = Some v ∧ P (k, v)} ∧ invar (iterate m (λ(k, v) σ. if P (k, v) then update_dj k v σ else σ) (local.empty ()))›*) apply (rule_tac I="λit σ. invar σ ∧ map_to_set (α σ) = it ∩ Collect P" in iterate_rule_insert_P (*‹⟦invar ?m; ?I {} ?σ0.0; ⋀k v it σ. ⟦(k, v) ∈ map_to_set (α ?m) - it; it ⊆ map_to_set (α ?m); ?I it σ⟧ ⟹ ?I (insert (k, v) it) (?f (k, v) σ); ⋀σ. ?I (map_to_set (α ?m)) σ ⟹ ?P σ⟧ ⟹ ?P (iterate ?m ?f ?σ0.0)›*)) (*goals: 1. ‹invar m› 2. ‹invar (local.empty ()) ∧ map_to_set (α (local.empty ())) = {} ∩ Collect P› 3. ‹⋀k v it σ. ⟦(k, v) ∈ map_to_set (α m) - it; it ⊆ map_to_set (α m); invar σ ∧ map_to_set (α σ) = it ∩ Collect P⟧ ⟹ invar ((case (k, v) of (k, v) ⇒ λσ. if P (k, v) then update_dj k v σ else σ) σ) ∧ map_to_set (α ((case (k, v) of (k, v) ⇒ λσ. if P (k, v) then update_dj k v σ else σ) σ)) = insert (k, v) it ∩ Collect P› 4. ‹⋀σ. invar σ ∧ map_to_set (α σ) = map_to_set (α m) ∩ Collect P ⟹ α σ = α m |` {k. ∃v. α m k = Some v ∧ P (k, v)} ∧ invar σ› discuss goal 1*) apply ((auto simp: I (*‹invar m›*) empty_correct (*‹α (local.empty ()) = (λx. None)› ‹invar (local.empty ())›*) update_dj_correct (*‹⟦invar ?m; ?k ∉ dom (α ?m)⟧ ⟹ α (update_dj ?k ?v ?m) = (α ?m)(?k ↦ ?v)› ‹⟦invar ?m; ?k ∉ dom (α ?m)⟧ ⟹ invar (update_dj ?k ?v ?m)›*) map_to_set_def (*‹map_to_set ?m = {(k, v). ?m k = Some v}›*) AUX (*‹⟦?it2 ⊆ {(k, v). α m k = Some v}; α m ?k2 = Some ?v2; (?k2, ?v2) ∉ ?it2; {(k, v). α ?σ2 k = Some v} = ?it2 ∩ Collect P⟧ ⟹ ?k2 ∉ dom (α ?σ2)›*))[1]) (*discuss goal 2*) apply ((auto simp: I (*‹invar m›*) empty_correct (*‹α (local.empty ()) = (λx. None)› ‹invar (local.empty ())›*) update_dj_correct (*‹⟦invar ?m; ?k ∉ dom (α ?m)⟧ ⟹ α (update_dj ?k ?v ?m) = (α ?m)(?k ↦ ?v)› ‹⟦invar ?m; ?k ∉ dom (α ?m)⟧ ⟹ invar (update_dj ?k ?v ?m)›*) map_to_set_def (*‹map_to_set ?m = {(k, v). ?m k = Some v}›*) AUX (*‹⟦?it2 ⊆ {(k, v). α m k = Some v}; α m ?k2 = Some ?v2; (?k2, ?v2) ∉ ?it2; {(k, v). α ?σ2 k = Some v} = ?it2 ∩ Collect P⟧ ⟹ ?k2 ∉ dom (α ?σ2)›*))[1]) (*discuss goal 3*) apply ((auto simp: I (*‹invar m›*) empty_correct (*‹α (local.empty ()) = (λx. None)› ‹invar (local.empty ())›*) update_dj_correct (*‹⟦invar ?m; ?k ∉ dom (α ?m)⟧ ⟹ α (update_dj ?k ?v ?m) = (α ?m)(?k ↦ ?v)› ‹⟦invar ?m; ?k ∉ dom (α ?m)⟧ ⟹ invar (update_dj ?k ?v ?m)›*) map_to_set_def (*‹map_to_set ?m = {(k, v). ?m k = Some v}›*) AUX (*‹⟦?it2 ⊆ {(k, v). α m k = Some v}; α m ?k2 = Some ?v2; (?k2, ?v2) ∉ ?it2; {(k, v). α ?σ2 k = Some v} = ?it2 ∩ Collect P⟧ ⟹ ?k2 ∉ dom (α ?σ2)›*))[1]) (*goals: 1. ‹⋀k v it σ a b. ⟦it ⊆ {(k, v). α m k = Some v}; α m k = Some v; (k, v) ∉ it; invar σ; {(k, v). α σ k = Some v} = it ∩ Collect P; P (k, v); (if a = k then Some v else α σ a) = Some b; (a, b) ∉ it⟧ ⟹ b = v› 2. ‹⋀k v it σ a b. ⟦it ⊆ {(k, v). α m k = Some v}; α m k = Some v; (k, v) ∉ it; invar σ; {(k, v). α σ k = Some v} = it ∩ Collect P; P (k, v); (if a = k then Some v else α σ a) = Some b; ¬ P (a, b)⟧ ⟹ b = v› 3. ‹⋀k v it σ b. ⟦it ⊆ {(k, v). α m k = Some v}; α m k = Some v; (k, v) ∉ it; invar σ; {(k, v). α σ k = Some v} = it ∩ Collect P; P (k, v); (k, b) ∈ it; P (k, b)⟧ ⟹ v = b› 4. ‹⋀k v it σ a b. ⟦it ⊆ {(k, v). α m k = Some v}; α m k = Some v; (k, v) ∉ it; invar σ; {(k, v). α σ k = Some v} = it ∩ Collect P; P (k, v); (a, b) ∈ it; P (a, b); a ≠ k⟧ ⟹ α σ a = Some b› discuss goal 1*) apply ((auto split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 3*) apply ((auto split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 4*) apply ((auto split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 4 subgoals*) (*discuss goal 4*) apply ((auto simp: I (*‹invar (m::'s::type)›*) empty_correct (*‹α (local.empty ()) = (λx::'k::type. None)› ‹invar (local.empty ())›*) update_dj_correct (*‹⟦invar (?m::'s::type); (?k::'k::type) ∉ dom (α ?m)⟧ ⟹ α (update_dj ?k (?v::'v::type) ?m) = (α ?m)(?k ↦ ?v)› ‹⟦invar (?m::'s::type); (?k::'k::type) ∉ dom (α ?m)⟧ ⟹ invar (update_dj ?k (?v::'v::type) ?m)›*) map_to_set_def (*‹map_to_set (?m::?'a::type ⇒ ?'b::type option) = {(k::?'a::type, v::?'b::type). ?m k = Some v}›*) AUX (*‹⟦(?it2::('k::type × 'v::type) set) ⊆ {(k::'k::type, v::'v::type). α (m::'s::type) k = Some v}; α m (?k2::'k::type) = Some (?v2::'v::type); (?k2, ?v2) ∉ ?it2; {(k::'k::type, v::'v::type). α (?σ2::'s::type) k = Some v} = ?it2 ∩ Collect (P::'k::type × 'v::type ⇒ bool)⟧ ⟹ ?k2 ∉ dom (α ?σ2)›*))[1]) (*goal: ‹⋀σ::'s. invar σ ∧ map_to_set (α σ) = map_to_set (α (m::'s)) ∩ Collect (P::'k × 'v ⇒ bool) ⟹ α σ = α m |` {k::'k. ∃v::'v. α m k = Some v ∧ P (k, v)} ∧ invar σ›*) apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹⋀σ. ⟦invar σ; {(k, v). α σ k = Some v} = {(k, v). α m k = Some v} ∩ Collect P⟧ ⟹ α σ = α m |` {k. ∃v. α m k = Some v ∧ P (k, v)}›*) apply (auto simp: Map.restrict_map_def (*‹?m |` ?A = (λx. if x ∈ ?A then ?m x else None)›*)) (*goals: 1. ‹⋀(σ::'s) (x::'k) v::'v. ⟦invar σ; {(k::'k, v::'v). α σ k = Some v} = {(k::'k, v::'v). α (m::'s) k = Some v} ∩ Collect (P::'k × 'v ⇒ bool); α m x = Some v; P (x, v)⟧ ⟹ α σ x = Some v› 2. ‹⋀(σ::'s) x::'k. ⟦invar σ; {(k::'k, v::'v). α σ k = Some v} = {(k::'k, v::'v). α (m::'s) k = Some v} ∩ Collect (P::'k × 'v ⇒ bool); ∀v::'v. α m x = Some v ⟶ ¬ P (x, v)⟧ ⟹ α σ x = None› discuss goal 1*) apply force (*discuss goal 2*) apply (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹⋀(σ::'s) x::'k. ⟦invar σ; {(k::'k, v::'v). α σ k = Some v} = {(k::'k, v::'v). α (m::'s) k = Some v} ∩ Collect (P::'k × 'v ⇒ bool); ∀v::'v. α m x = Some v ⟶ ¬ P (x, v)⟧ ⟹ α σ x = None›*) apply force (*proven 2 subgoals*) (*proven 4 subgoals*) . thus "α (g_restrict P m) = α m |` {k. ∃v. α m k = Some v ∧ P (k, v)}" "invar (g_restrict P m)" apply - (*goals: 1. ‹α (g_restrict P m) = α m |` {k. ∃v. α m k = Some v ∧ P (k, v)} ∧ invar (g_restrict P m) ⟹ α (g_restrict P m) = α m |` {k. ∃v. α m k = Some v ∧ P (k, v)}› 2. ‹α (g_restrict P m) = α m |` {k. ∃v. α m k = Some v ∧ P (k, v)} ∧ invar (g_restrict P m) ⟹ invar (g_restrict P m)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed lemma dflt_ops_impl: "StdMap dflt_ops" sorry end context StdBasicOMapDefs begin definition "g_min m P ≡ iterateoi m (λσ. σ = None) (λx σ. if P x then Some x else None) None" definition "g_max m P ≡ rev_iterateoi m (λσ. σ = None) (λx σ. if P x then Some x else None) None" definition "g_to_sorted_list m ≡ rev_iterateo m (#) []" definition "g_to_rev_list m ≡ iterateo m (#) []" definition dflt_oops :: "('k,'v,'s) omap_ops" where [icf_rec_def]: "dflt_oops ≡ map_ops.extend dflt_ops ⦇ map_op_ordered_list_it = ordered_list_it, map_op_rev_list_it = rev_list_it, map_op_min = g_min, map_op_max = g_max, map_op_to_sorted_list = g_to_sorted_list, map_op_to_rev_list = g_to_rev_list ⦈" local_setup ‹Locale_Code.lc_decl_del @{term dflt_oops}› end context StdBasicOMap begin lemma g_min_impl: "map_min α invar g_min" proof (standard) (*goals: 1. ‹⋀(s::'s::type) P::'k::linorder × 'v::type ⇒ bool. ⟦invar s; rel_of (α s) P ≠ {}⟧ ⟹ g_min s P ∈ Some ` rel_of (α s) P› 2. ‹⋀(s::'s::type) (k::'k::linorder) (v::'v::type) P::'k::linorder × 'v::type ⇒ bool. ⟦invar s; (k, v) ∈ rel_of (α s) P⟧ ⟹ fst (the (g_min s P)) ≤ k› 3. ‹⋀(s::'s::type) P::'k::linorder × 'v::type ⇒ bool. ⟦invar s; rel_of (α s) P = {}⟧ ⟹ g_min s P = None›*) fix m and P assume I: "invar m" (*‹invar (m::'s)›*) from iterateoi_correct[OF I] (*‹map_iterator_linord (iterateoi m) (α m)›*) have iti': "map_iterator_linord (iterateoi m) (α m)" by simp note sel_correct = iterate_sel_no_map_map_linord_correct[OF iti', of P] (*‹(iterate_sel_no_map (iterateoi m) P = None) = (∀k v. α m k = Some v ⟶ ¬ P (k, v))› ‹iterate_sel_no_map (iterateoi m) P = Some (?k, ?v) ⟹ α m ?k = Some ?v ∧ P (?k, ?v) ∧ (∀k' v'. α m k' = Some v' ∧ P (k', v') ⟶ ?k ≤ k')›*) have A: "g_min m P = iterate_sel_no_map (iterateoi m) P" unfolding g_min_def iterate_sel_no_map_def iterate_sel_def (*goal: ‹iterateoi m (λσ. σ = None) (λx σ. if P x then Some x else None) None = iterateoi m (λσ. σ = None) (λx σ. if P x then Some x else None) None›*) by simp { assume "rel_of (α m) P ≠ {}" (*‹rel_of (α (m::'s)) (P::'k × 'v ⇒ bool) ≠ {}›*) with sel_correct (*‹(iterate_sel_no_map (iterateoi m) P = None) = (∀k v. α m k = Some v ⟶ ¬ P (k, v))› ‹iterate_sel_no_map (iterateoi (m::'s)) (P::'k × 'v ⇒ bool) = Some (?k::'k, ?v::'v) ⟹ α m ?k = Some ?v ∧ P (?k, ?v) ∧ (∀(k'::'k) v'::'v. α m k' = Some v' ∧ P (k', v') ⟶ ?k ≤ k')›*) show "g_min m P ∈ Some ` rel_of (α m) P" unfolding A (*goal: ‹iterate_sel_no_map (iterateoi m) P ∈ Some ` rel_of (α m) P›*) by (auto simp add: image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*) rel_of_def (*‹rel_of ?m ?P ≡ {(k, v). ?m k = Some v ∧ ?P (k, v)}›*)) } { assume "rel_of (α m) P = {}" (*‹rel_of (α (m::'s)) (P::'k × 'v ⇒ bool) = {}›*) with sel_correct (*‹(iterate_sel_no_map (iterateoi (m::'s)) (P::'k × 'v ⇒ bool) = None) = (∀(k::'k) v::'v. α m k = Some v ⟶ ¬ P (k, v))› ‹iterate_sel_no_map (iterateoi m) P = Some (?k, ?v) ⟹ α m ?k = Some ?v ∧ P (?k, ?v) ∧ (∀k' v'. α m k' = Some v' ∧ P (k', v') ⟶ ?k ≤ k')›*) show "g_min m P = None" unfolding A (*goal: ‹iterate_sel_no_map (iterateoi m) P = None›*) by (auto simp add: image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*) rel_of_def (*‹rel_of ?m ?P ≡ {(k, v). ?m k = Some v ∧ ?P (k, v)}›*)) } { fix k and v assume "(k, v) ∈ rel_of (α m) P" (*‹(k::'k, v::'v) ∈ rel_of (α (m::'s)) (P::'k × 'v ⇒ bool)›*) with sel_correct (*‹(iterate_sel_no_map (iterateoi m) P = None) = (∀k v. α m k = Some v ⟶ ¬ P (k, v))› ‹iterate_sel_no_map (iterateoi (m::'s::type)) (P::'k::linorder × 'v::type ⇒ bool) = Some (?k::'k::linorder, ?v::'v::type) ⟹ α m ?k = Some ?v ∧ P (?k, ?v) ∧ (∀(k'::'k::linorder) v'::'v::type. α m k' = Some v' ∧ P (k', v') ⟶ ?k ≤ k')›*) show "fst (the (g_min m P)) ≤ k" unfolding A (*goal: ‹fst (the (iterate_sel_no_map (iterateoi m) P)) ≤ k›*) by (auto simp add: image_iff (*‹((?z::?'a) ∈ (?f::?'b ⇒ ?'a) ` (?A::?'b set)) = (∃x::?'b∈?A. ?z = ?f x)›*) rel_of_def (*‹rel_of (?m::?'a ⇒ ?'b option) (?P::?'a × ?'b ⇒ bool) ≡ {(k::?'a, v::?'b). ?m k = Some v ∧ ?P (k, v)}›*)) } qed lemma g_max_impl: "map_max α invar g_max" proof (standard) (*goals: 1. ‹⋀s P. ⟦invar s; rel_of (α s) P ≠ {}⟧ ⟹ g_max s P ∈ Some ` rel_of (α s) P› 2. ‹⋀s k v P. ⟦invar s; (k, v) ∈ rel_of (α s) P⟧ ⟹ k ≤ fst (the (g_max s P))› 3. ‹⋀s P. ⟦invar s; rel_of (α s) P = {}⟧ ⟹ g_max s P = None›*) fix m and P assume I: "invar m" (*‹invar (m::'s)›*) from rev_iterateoi_correct[OF I] (*‹map_iterator_rev_linord (reverse_iterateoi (m::'s)) (α m)›*) have iti': "map_iterator_rev_linord (rev_iterateoi m) (α m)" by simp note sel_correct = iterate_sel_no_map_map_rev_linord_correct[OF iti', of P] (*‹(iterate_sel_no_map (reverse_iterateoi m) P = None) = (∀k v. α m k = Some v ⟶ ¬ P (k, v))› ‹iterate_sel_no_map (reverse_iterateoi m) P = Some (?k, ?v) ⟹ α m ?k = Some ?v ∧ P (?k, ?v) ∧ (∀k' v'. α m k' = Some v' ∧ P (k', v') ⟶ k' ≤ ?k)›*) have A: "g_max m P = iterate_sel_no_map (rev_iterateoi m) P" unfolding g_max_def iterate_sel_no_map_def iterate_sel_def (*goal: ‹reverse_iterateoi m (λσ. σ = None) (λx σ. if P x then Some x else None) None = reverse_iterateoi m (λσ. σ = None) (λx σ. if P x then Some x else None) None›*) by simp { assume "rel_of (α m) P ≠ {}" (*‹rel_of (α (m::'s)) (P::'k × 'v ⇒ bool) ≠ {}›*) with sel_correct (*‹(iterate_sel_no_map (reverse_iterateoi (m::'s::type)) (P::'k::linorder × 'v::type ⇒ bool) = None) = (∀(k::'k::linorder) v::'v::type. α m k = Some v ⟶ ¬ P (k, v))› ‹iterate_sel_no_map (reverse_iterateoi m) P = Some (?k, ?v) ⟹ α m ?k = Some ?v ∧ P (?k, ?v) ∧ (∀k' v'. α m k' = Some v' ∧ P (k', v') ⟶ k' ≤ ?k)›*) show "g_max m P ∈ Some ` rel_of (α m) P" unfolding A (*goal: ‹iterate_sel_no_map (reverse_iterateoi m) P ∈ Some ` rel_of (α m) P›*) by (auto simp add: image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*) rel_of_def (*‹rel_of ?m ?P ≡ {(k, v). ?m k = Some v ∧ ?P (k, v)}›*)) } { assume "rel_of (α m) P = {}" (*‹rel_of (α (m::'s)) (P::'k × 'v ⇒ bool) = {}›*) with sel_correct (*‹(iterate_sel_no_map (reverse_iterateoi m) P = None) = (∀k v. α m k = Some v ⟶ ¬ P (k, v))› ‹iterate_sel_no_map (reverse_iterateoi (m::'s::type)) (P::'k::linorder × 'v::type ⇒ bool) = Some (?k::'k::linorder, ?v::'v::type) ⟹ α m ?k = Some ?v ∧ P (?k, ?v) ∧ (∀(k'::'k::linorder) v'::'v::type. α m k' = Some v' ∧ P (k', v') ⟶ k' ≤ ?k)›*) show "g_max m P = None" unfolding A (*goal: ‹iterate_sel_no_map (reverse_iterateoi (m::'s)) (P::'k × 'v ⇒ bool) = None›*) by (auto simp add: image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*) rel_of_def (*‹rel_of ?m ?P ≡ {(k, v). ?m k = Some v ∧ ?P (k, v)}›*)) } { fix k and v assume "(k, v) ∈ rel_of (α m) P" (*‹(k::'k, v::'v) ∈ rel_of (α (m::'s)) (P::'k × 'v ⇒ bool)›*) with sel_correct (*‹(iterate_sel_no_map (reverse_iterateoi m) P = None) = (∀k v. α m k = Some v ⟶ ¬ P (k, v))› ‹iterate_sel_no_map (reverse_iterateoi (m::'s)) (P::'k × 'v ⇒ bool) = Some (?k::'k, ?v::'v) ⟹ α m ?k = Some ?v ∧ P (?k, ?v) ∧ (∀(k'::'k) v'::'v. α m k' = Some v' ∧ P (k', v') ⟶ k' ≤ ?k)›*) show "fst (the (g_max m P)) ≥ k" unfolding A (*goal: ‹k ≤ fst (the (iterate_sel_no_map (reverse_iterateoi m) P))›*) by (auto simp add: image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*) rel_of_def (*‹rel_of ?m ?P ≡ {(k, v). ?m k = Some v ∧ ?P (k, v)}›*)) } qed lemma g_to_sorted_list_impl: "map_to_sorted_list α invar g_to_sorted_list" proof (standard) (*goals: 1. ‹⋀m. invar m ⟹ map_of (g_to_sorted_list m) = α m› 2. ‹⋀m. invar m ⟹ distinct (map fst (g_to_sorted_list m))› 3. ‹⋀m. invar m ⟹ sorted (map fst (g_to_sorted_list m))›*) fix m assume I: "invar m" (*‹invar (m::'s)›*) note iti = rev_iterateoi_correct[OF I] (*‹map_iterator_rev_linord (reverse_iterateoi m) (α m)›*) from iterate_to_list_map_rev_linord_correct[OF iti] (*‹map_of (iterate_to_list (reverse_iterateoi (m::'s))) = α m ∧ distinct (map fst (iterate_to_list (reverse_iterateoi m))) ∧ sorted (map fst (iterate_to_list (reverse_iterateoi m)))›*) show "sorted (map fst (g_to_sorted_list m))" "distinct (map fst (g_to_sorted_list m))" "map_of (g_to_sorted_list m) = α m" unfolding g_to_sorted_list_def iterate_to_list_def (*goals: 1. ‹sorted (map fst (reverse_iterateo m (#) []))› 2. ‹distinct (map fst (reverse_iterateo m (#) []))› 3. ‹map_of (reverse_iterateo m (#) []) = α m›*) apply - (*goals: 1. ‹map_of (reverse_iterateo m (#) []) = α m ∧ distinct (map fst (reverse_iterateo m (#) [])) ∧ sorted (map fst (reverse_iterateo m (#) [])) ⟹ sorted (map fst (reverse_iterateo m (#) []))› 2. ‹map_of (reverse_iterateo m (#) []) = α m ∧ distinct (map fst (reverse_iterateo m (#) [])) ∧ sorted (map fst (reverse_iterateo m (#) [])) ⟹ distinct (map fst (reverse_iterateo m (#) []))› 3. ‹map_of (reverse_iterateo m (#) []) = α m ∧ distinct (map fst (reverse_iterateo m (#) [])) ∧ sorted (map fst (reverse_iterateo m (#) [])) ⟹ map_of (reverse_iterateo m (#) []) = α m› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) . qed lemma g_to_rev_list_impl: "map_to_rev_list α invar g_to_rev_list" proof (standard) (*goals: 1. ‹⋀m::'s. invar m ⟹ map_of (g_to_rev_list m) = α m› 2. ‹⋀m::'s. invar m ⟹ distinct (map fst (g_to_rev_list m))› 3. ‹⋀m::'s. invar m ⟹ sorted (rev (map fst (g_to_rev_list m)))›*) fix m assume I: "invar m" (*‹invar (m::'s)›*) note iti = iterateoi_correct[OF I] (*‹map_iterator_linord (iterateoi m) (α m)›*) from iterate_to_list_map_linord_correct[OF iti] (*‹map_of (iterate_to_list (iterateoi (m::'s))) = α m ∧ distinct (map fst (iterate_to_list (iterateoi m))) ∧ sorted (map fst (rev (iterate_to_list (iterateoi m))))›*) show "sorted (rev (map fst (g_to_rev_list m)))" "distinct (map fst (g_to_rev_list m))" "map_of (g_to_rev_list m) = α m" unfolding g_to_rev_list_def iterate_to_list_def (*goals: 1. ‹sorted (rev (map fst (iterateo m (#) [])))› 2. ‹distinct (map fst (iterateo m (#) []))› 3. ‹map_of (iterateo m (#) []) = α m›*) apply - (*goals: 1. ‹map_of (iterateo m (#) []) = α m ∧ distinct (map fst (iterateo m (#) [])) ∧ sorted (map fst (rev (iterateo m (#) []))) ⟹ sorted (rev (map fst (iterateo m (#) [])))› 2. ‹map_of (iterateo m (#) []) = α m ∧ distinct (map fst (iterateo m (#) [])) ∧ sorted (map fst (rev (iterateo m (#) []))) ⟹ distinct (map fst (iterateo m (#) []))› 3. ‹map_of (iterateo m (#) []) = α m ∧ distinct (map fst (iterateo m (#) [])) ∧ sorted (map fst (rev (iterateo m (#) []))) ⟹ map_of (iterateo m (#) []) = α m› discuss goal 1*) apply (simp add: rev_map (*‹rev (map (?f::?'b ⇒ ?'a) (?xs::?'b list)) = map ?f (rev ?xs)›*)) (*discuss goal 2*) apply (simp add: rev_map (*‹rev (map ?f ?xs) = map ?f (rev ?xs)›*)) (*discuss goal 3*) apply (simp add: rev_map (*‹rev (map ?f ?xs) = map ?f (rev ?xs)›*)) (*proven 3 subgoals*) . qed lemma dflt_oops_impl: "StdOMap dflt_oops" proof (-) (*goal: ‹StdOMap dflt_oops›*) interpret aux: StdMap dflt_ops by (rule dflt_ops_impl (*‹StdMap dflt_ops›*)) show "?thesis" (*goal: ‹StdOMap dflt_oops›*) apply (rule StdOMap_intro (*‹⟦map_empty (map_op_α (?ops::(?'k, ?'v, ?'s, ?'more) omap_ops_scheme)) (map_op_invar ?ops) (map_op_empty ?ops); map_lookup (map_op_α ?ops) (map_op_invar ?ops) (map_op_lookup ?ops); map_update (map_op_α ?ops) (map_op_invar ?ops) (map_op_update ?ops); map_update_dj (map_op_α ?ops) (map_op_invar ?ops) (map_op_update_dj ?ops); map_delete (map_op_α ?ops) (map_op_invar ?ops) (map_op_delete ?ops); poly_map_iteratei (map_op_α ?ops) (map_op_invar ?ops) (map_op_list_it ?ops); map_sng (map_op_α ?ops) (map_op_invar ?ops) (map_op_sng ?ops); map_restrict (map_op_α ?ops) (map_op_invar ?ops) (map_op_α ?ops) (map_op_invar ?ops) (map_op_restrict ?ops); MapSpec.map_add (map_op_α ?ops) (map_op_invar ?ops) (map_op_add ?ops); map_add_dj (map_op_α ?ops) (map_op_invar ?ops) (map_op_add_dj ?ops); map_isEmpty (map_op_α ?ops) (map_op_invar ?ops) (map_op_isEmpty ?ops); map_isSng (map_op_α ?ops) (map_op_invar ?ops) (map_op_isSng ?ops); map_ball (map_op_α ?ops) (map_op_invar ?ops) (map_op_ball ?ops); map_bex (map_op_α ?ops) (map_op_invar ?ops) (map_op_bex ?ops); map_size (map_op_α ?ops) (map_op_invar ?ops) (map_op_size ?ops); map_size_abort (map_op_α ?ops) (map_op_invar ?ops) (map_op_size_abort ?ops); map_sel' (map_op_α ?ops) (map_op_invar ?ops) (map_op_sel ?ops); map_to_list (map_op_α ?ops) (map_op_invar ?ops) (map_op_to_list ?ops); list_to_map (map_op_α ?ops) (map_op_invar ?ops) (map_op_to_map ?ops); poly_map_iterateoi (map_op_α ?ops) (map_op_invar ?ops) (map_op_ordered_list_it ?ops); poly_map_rev_iterateoi (map_op_α ?ops) (map_op_invar ?ops) (map_op_rev_list_it ?ops); map_min (map_op_α ?ops) (map_op_invar ?ops) (map_op_min ?ops); map_max (map_op_α ?ops) (map_op_invar ?ops) (map_op_max ?ops); MapSpec.map_to_sorted_list (map_op_α ?ops) (map_op_invar ?ops) (map_op_to_sorted_list ?ops); map_to_rev_list (map_op_α ?ops) (map_op_invar ?ops) (map_op_to_rev_list ?ops)⟧ ⟹ StdOMap ?ops›*)) (*goals: 1. ‹map_empty (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_empty dflt_oops)› 2. ‹map_lookup (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_lookup dflt_oops)› 3. ‹map_update (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_update dflt_oops)› 4. ‹map_update_dj (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_update_dj dflt_oops)› 5. ‹map_delete (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_delete dflt_oops)› 6. ‹poly_map_iteratei (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_list_it dflt_oops)› 7. ‹map_sng (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_sng dflt_oops)› 8. ‹map_restrict (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_restrict dflt_oops)› 9. ‹MapSpec.map_add (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_add dflt_oops)› 10. ‹map_add_dj (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_add_dj dflt_oops)› 11. ‹map_isEmpty (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_isEmpty dflt_oops)› 12. ‹map_isSng (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_isSng dflt_oops)› 13. ‹map_ball (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_ball dflt_oops)› 14. ‹map_bex (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_bex dflt_oops)› 15. ‹map_size (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_size dflt_oops)› 16. ‹map_size_abort (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_size_abort dflt_oops)› 17. ‹map_sel' (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_sel dflt_oops)› 18. ‹map_to_list (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_to_list dflt_oops)› 19. ‹list_to_map (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_to_map dflt_oops)› 20. ‹poly_map_iterateoi (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_ordered_list_it dflt_oops)› 21. ‹poly_map_rev_iterateoi (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_rev_list_it dflt_oops)› 22. ‹map_min (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_min dflt_oops)› 23. ‹map_max (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_max dflt_oops)› 24. ‹MapSpec.map_to_sorted_list (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_to_sorted_list dflt_oops)› 25. ‹map_to_rev_list (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_to_rev_list dflt_oops)› discuss goal 1*) apply ((icf_locales)[1]) (*discuss goal 2*) apply ((icf_locales)[1]) (*discuss goal 3*) apply ((icf_locales)[1]) (*discuss goal 4*) apply ((icf_locales)[1]) (*discuss goal 5*) apply ((icf_locales)[1]) (*discuss goal 6*) apply ((icf_locales)[1]) (*discuss goal 7*) apply ((icf_locales)[1]) (*discuss goal 8*) apply ((icf_locales)[1]) (*discuss goal 9*) apply ((icf_locales)[1]) (*discuss goal 10*) apply ((icf_locales)[1]) (*discuss goal 11*) apply ((icf_locales)[1]) (*discuss goal 12*) apply ((icf_locales)[1]) (*discuss goal 13*) apply ((icf_locales)[1]) (*discuss goal 14*) apply ((icf_locales)[1]) (*discuss goal 15*) apply ((icf_locales)[1]) (*discuss goal 16*) apply ((icf_locales)[1]) (*discuss goal 17*) apply ((icf_locales)[1]) (*discuss goal 18*) apply ((icf_locales)[1]) (*discuss goal 19*) apply ((icf_locales)[1]) (*discuss goal 20*) apply ((icf_locales)[1]) (*discuss goal 21*) apply ((icf_locales)[1]) (*discuss goal 22*) apply ((icf_locales)[1]) (*top goal: ‹map_min (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_min dflt_oops)› and 3 goals remain*) apply (simp add: icf_rec_unf (*‹map_op_ordered_list_it dflt_oops ≡ ordered_list_it› ‹map_op_to_sorted_list dflt_oops ≡ g_to_sorted_list› ‹map_op_to_rev_list dflt_oops ≡ g_to_rev_list› ‹map_op_rev_list_it dflt_oops ≡ rev_list_it› ‹map_op_size_abort dflt_oops ≡ g_size_abort› ‹aux.size_abort ≡ g_size_abort› ‹map_op_update_dj dflt_oops ≡ update_dj› ‹aux.update_dj ≡ update_dj› ‹map_op_restrict dflt_oops ≡ g_restrict› ‹aux.restrict ≡ g_restrict› ‹map_op_α dflt_oops ≡ α› ‹aux.α ≡ α› and more 39 facts*)) (*top goal: ‹map_min (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_min dflt_oops)› and 3 goals remain*) apply (rule g_min_impl (*‹map_min α invar g_min›*)) (*discuss goal 23*) apply ((icf_locales)[1]) (*top goal: ‹map_max (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_max dflt_oops)› and 2 goals remain*) apply (simp add: icf_rec_unf (*‹map_op_ordered_list_it dflt_oops ≡ ordered_list_it› ‹map_op_to_sorted_list dflt_oops ≡ g_to_sorted_list› ‹map_op_to_rev_list dflt_oops ≡ g_to_rev_list› ‹map_op_rev_list_it dflt_oops ≡ rev_list_it› ‹map_op_size_abort dflt_oops ≡ g_size_abort› ‹aux.size_abort ≡ g_size_abort› ‹map_op_update_dj dflt_oops ≡ update_dj› ‹aux.update_dj ≡ update_dj› ‹map_op_restrict dflt_oops ≡ g_restrict› ‹aux.restrict ≡ g_restrict› ‹map_op_α dflt_oops ≡ α› ‹aux.α ≡ α› and more 39 facts*)) (*top goal: ‹map_max (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_max dflt_oops)› and 2 goals remain*) apply (rule g_max_impl (*‹map_max α invar g_max›*)) (*discuss goal 24*) apply ((icf_locales)[1]) (*top goal: ‹MapSpec.map_to_sorted_list (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_to_sorted_list dflt_oops)› and 1 goal remains*) apply (simp add: icf_rec_unf (*‹map_op_ordered_list_it dflt_oops ≡ ordered_list_it› ‹map_op_to_sorted_list dflt_oops ≡ g_to_sorted_list› ‹map_op_to_rev_list dflt_oops ≡ g_to_rev_list› ‹map_op_rev_list_it dflt_oops ≡ rev_list_it› ‹map_op_size_abort dflt_oops ≡ g_size_abort› ‹aux.size_abort ≡ g_size_abort› ‹map_op_update_dj dflt_oops ≡ update_dj› ‹aux.update_dj ≡ update_dj› ‹map_op_restrict dflt_oops ≡ g_restrict› ‹aux.restrict ≡ g_restrict› ‹map_op_α dflt_oops ≡ α› ‹aux.α ≡ α› and more 39 facts*)) (*top goal: ‹MapSpec.map_to_sorted_list (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_to_sorted_list dflt_oops)› and 1 goal remains*) apply (rule g_to_sorted_list_impl (*‹MapSpec.map_to_sorted_list α invar g_to_sorted_list›*)) (*discuss goal 25*) apply ((icf_locales)[1]) (*goal: ‹map_to_rev_list (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_to_rev_list dflt_oops)›*) apply (simp add: icf_rec_unf (*‹map_op_ordered_list_it dflt_oops ≡ ordered_list_it› ‹map_op_to_sorted_list dflt_oops ≡ g_to_sorted_list› ‹map_op_to_rev_list dflt_oops ≡ g_to_rev_list› ‹map_op_rev_list_it dflt_oops ≡ rev_list_it› ‹map_op_size_abort dflt_oops ≡ g_size_abort› ‹aux.size_abort ≡ g_size_abort› ‹map_op_update_dj dflt_oops ≡ update_dj› ‹aux.update_dj ≡ update_dj› ‹map_op_restrict dflt_oops ≡ g_restrict› ‹aux.restrict ≡ g_restrict› ‹map_op_α dflt_oops ≡ α› ‹aux.α ≡ α› and more 39 facts*)) (*goal: ‹map_to_rev_list (map_op_α dflt_oops) (map_op_invar dflt_oops) (map_op_to_rev_list dflt_oops)›*) apply (rule g_to_rev_list_impl (*‹map_to_rev_list α invar g_to_rev_list›*)) (*proven 25 subgoals*) . qed end locale g_image_filter_defs_loc = m1: StdMapDefs ops1 + m2: StdMapDefs ops2 for ops1 :: "('k1,'v1,'s1,'m1) map_ops_scheme" and ops2 :: "('k2,'v2,'s2,'m2) map_ops_scheme" begin definition "g_image_filter f m1 ≡ m1.iterate m1 (λkv σ. case f kv of None => σ | Some (k',v') => m2.update_dj k' v' σ ) (m2.empty ())" end locale g_image_filter_loc = g_image_filter_defs_loc ops1 ops2 + m1: StdMap ops1 + m2: StdMap ops2 for ops1 :: "('k1,'v1,'s1,'m1) map_ops_scheme" and ops2 :: "('k2,'v2,'s2,'m2) map_ops_scheme" begin lemma g_image_filter_impl: "map_image_filter m1.α m1.invar m2.α m2.invar g_image_filter" proof (standard) (*goal: ‹⋀(m::'s1::type) (f::'k1::type × 'v1::type ⇒ ('k2::type × 'v2::type) option) (k'::'k2::type) v'::'v2::type. ⟦m1.invar m; transforms_to_unique_keys (m1.α m) f⟧ ⟹ m2.invar (g_image_filter f m) ∧ (m2.α (g_image_filter f m) k' = Some v') = (∃(k::'k1::type) v::'v1::type. m1.α m k = Some v ∧ f (k, v) = Some (k', v'))›*) fix m and k' and v' and f :: "('k1 × 'v1) ⇒ ('k2 × 'v2) option" assume invar_m: "m1.invar m" and unique_f: "transforms_to_unique_keys (m1.α m) f" (*‹m1.invar (m::'s1)› ‹transforms_to_unique_keys (m1.α (m::'s1)) (f::'k1 × 'v1 ⇒ ('k2 × 'v2) option)›*) have A: "g_image_filter f m = iterate_to_map m2.empty m2.update_dj ( set_iterator_image_filter f (m1.iteratei m))" unfolding g_image_filter_def iterate_to_map_alt_def set_iterator_image_filter_def case_prod_beta (*goal: ‹m1.iterate m (λkv σ. case f kv of None ⇒ σ | Some a ⇒ m2.update_dj (fst a) (snd a) σ) (m2.empty ()) = m1.iterate m (λx σ. case f x of None ⇒ σ | Some x' ⇒ m2.update_dj (fst x') (snd x') σ) (m2.empty ())›*) by simp from m1.iteratei_correct[OF invar_m] (*‹map_iterator (m1.iteratei m) (m1.α m)›*) have iti_m: "map_iterator (m1.iteratei m) (m1.α m)" by simp from unique_f (*‹transforms_to_unique_keys (m1.α (m::'s1::type)) (f::'k1::type × 'v1::type ⇒ ('k2::type × 'v2::type) option)›*) have inj_on_f: "inj_on f (map_to_set (m1.α m) ∩ dom f)" unfolding transforms_to_unique_keys_def inj_on_def Ball_def map_to_set_def (*goal: ‹∀x. x ∈ {(k, v). m1.α m k = Some v} ∩ dom f ⟶ (∀xa. xa ∈ {(k, v). m1.α m k = Some v} ∩ dom f ⟶ f x = f xa ⟶ x = xa)›*) apply auto (*goal: ‹∀x::'k1 × 'v1. x ∈ {(k::'k1, v::'v1). m1.α (m::'s1) k = Some v} ∩ dom (f::'k1 × 'v1 ⇒ ('k2 × 'v2) option) ⟶ (∀xa::'k1 × 'v1. xa ∈ {(k::'k1, v::'v1). m1.α m k = Some v} ∩ dom f ⟶ f x = f xa ⟶ x = xa)›*) by (metis option.inject (*‹(Some ?x2.0 = Some ?y2.0) = (?x2.0 = ?y2.0)›*)) define vP where "vP k v ⟷ (∃k' v'. m1.α m k' = Some v' ∧ f (k', v') = Some (k, v))" for k and v have vP_intro: "⋀k v. (∃k' v'. m1.α m k' = Some v' ∧ f (k', v') = Some (k, v)) ⟷ vP k v" unfolding vP_def (*goal: ‹⋀(k::'k2) v::'v2. (∃(k'::'k1) v'::'v1. m1.α (m::'s1) k' = Some v' ∧ (f::'k1 × 'v1 ⇒ ('k2 × 'v2) option) (k', v') = Some (k, v)) = (∃(k'::'k1) v'::'v1. m1.α m k' = Some v' ∧ f (k', v') = Some (k, v))›*) by simp { fix k and v have "Eps_Opt (vP k) = Some v ⟷ vP k v" using unique_f (*‹transforms_to_unique_keys (m1.α (m::'s1::type)) (f::'k1::type × 'v1::type ⇒ ('k2::type × 'v2::type) option)›*) unfolding vP_def transforms_to_unique_keys_def (*goal: ‹(Eps_Opt (λv. ∃k' v'. m1.α m k' = Some v' ∧ f (k', v') = Some (k, v)) = Some v) = (∃k' v'. m1.α m k' = Some v' ∧ f (k', v') = Some (k, v))›*) apply (rule_tac Eps_Opt_eq_Some (*‹(⋀x'. ⟦?P ?x; ?P x'⟧ ⟹ x' = ?x) ⟹ (Eps_Opt ?P = Some ?x) = ?P ?x›*)) (*goal: ‹(Eps_Opt (λv::'v2. ∃(k'::'k1) v'::'v1. m1.α (m::'s1) k' = Some v' ∧ (f::'k1 × 'v1 ⇒ ('k2 × 'v2) option) (k', v') = Some (k::'k2, v)) = Some (v::'v2)) = (∃(k'::'k1) v'::'v1. m1.α m k' = Some v' ∧ f (k', v') = Some (k, v))›*) by (metis prod.inject (*‹((?x1.0, ?x2.0) = (?y1.0, ?y2.0)) = (?x1.0 = ?y1.0 ∧ ?x2.0 = ?y2.0)›*) option.inject (*‹(Some ?x2.0 = Some ?y2.0) = (?x2.0 = ?y2.0)›*)) } note Eps_vP_elim[simp] = this (*‹(Eps_Opt (vP ?k5) = Some ?v5) = vP ?k5 ?v5›*) have map_intro: "{y. ∃x. x ∈ map_to_set (m1.α m) ∧ f x = Some y} = map_to_set (λk. Eps_Opt (vP k))" by (simp add: map_to_set_def (*‹map_to_set ?m = {(k, v). ?m k = Some v}›*) vP_intro (*‹(∃k' v'. m1.α m k' = Some v' ∧ f (k', v') = Some (?k3, ?v3)) = vP ?k3 ?v3›*) set_eq_iff (*‹(?A = ?B) = (∀x. (x ∈ ?A) = (x ∈ ?B))›*) split: prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*)) from set_iterator_image_filter_correct[OF iti_m, OF inj_on_f, unfolded map_intro] (*‹map_iterator (set_iterator_image_filter f (m1.iteratei m)) (λk. Eps_Opt (vP k))›*) have iti_filter: "map_iterator (set_iterator_image_filter f (m1.iteratei m)) (λk. Eps_Opt (vP k))" by auto have upd: "map_update_dj m2.α m2.invar m2.update_dj" by unfold_locales have emp: "map_empty m2.α m2.invar m2.empty" by unfold_locales from iterate_to_map_correct[OF upd emp iti_filter] (*‹m2.α (iterate_to_map m2.empty m2.update_dj (set_iterator_image_filter (f::'k1 × 'v1 ⇒ ('k2 × 'v2) option) (m1.iteratei (m::'s1)))) = (λk::'k2. Eps_Opt ((vP::'k2 ⇒ 'v2 ⇒ bool) k)) ∧ m2.invar (iterate_to_map m2.empty m2.update_dj (set_iterator_image_filter f (m1.iteratei m)))›*) show "map_op_invar ops2 (g_image_filter f m) ∧ (map_op_α ops2 (g_image_filter f m) k' = Some v') = (∃k v. map_op_α ops1 m k = Some v ∧ f (k, v) = Some (k', v'))" unfolding A vP_def[symmetric] (*goal: ‹m2.invar (iterate_to_map m2.empty m2.update_dj (set_iterator_image_filter f (m1.iteratei m))) ∧ (m2.α (iterate_to_map m2.empty m2.update_dj (set_iterator_image_filter f (m1.iteratei m))) k' = Some v') = vP k' v'›*) by (simp add: vP_intro (*‹(∃k' v'. m1.α m k' = Some v' ∧ f (k', v') = Some (?k3, ?v3)) = vP ?k3 ?v3›*)) qed end sublocale g_image_filter_loc < map_image_filter m1.α m1.invar m2.α m2.invar g_image_filter by (rule g_image_filter_impl (*‹map_image_filter m1.α m1.invar m2.α m2.invar g_image_filter›*)) locale g_value_image_filter_defs_loc = m1: StdMapDefs ops1 + m2: StdMapDefs ops2 for ops1 :: "('k,'v1,'s1,'m1) map_ops_scheme" and ops2 :: "('k,'v2,'s2,'m2) map_ops_scheme" begin definition "g_value_image_filter f m1 ≡ m1.iterate m1 (λ(k,v) σ. case f k v of None => σ | Some v' => m2.update_dj k v' σ ) (m2.empty ())" end (* TODO: Move to Misc *) lemma restrict_map_dom_subset: "⟦ dom m ⊆ R⟧ ⟹ m|`R = m" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹dom m ⊆ R ⟹ m |` R = m›*) apply (auto simp: restrict_map_def (*‹?m |` ?A = (λx. if x ∈ ?A then ?m x else None)›*)) (*goal: ‹⋀x. dom m ⊆ R ⟹ (m |` R) x = m x›*) apply (case_tac "m x") (*goals: 1. ‹⋀x. ⟦dom m ⊆ R; x ∉ R; m x = None⟧ ⟹ None = m x› 2. ‹⋀x a. ⟦dom m ⊆ R; x ∉ R; m x = Some a⟧ ⟹ None = m x› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . locale g_value_image_filter_loc = g_value_image_filter_defs_loc ops1 ops2 + m1: StdMap ops1 + m2: StdMap ops2 for ops1 :: "('k,'v1,'s1,'m1) map_ops_scheme" and ops2 :: "('k,'v2,'s2,'m2) map_ops_scheme" begin lemma g_value_image_filter_impl: "map_value_image_filter m1.α m1.invar m2.α m2.invar g_value_image_filter" apply unfold_locales (*goal: ‹map_value_image_filter m1.α m1.invar m2.α m2.invar g_value_image_filter›*) unfolding g_value_image_filter_def (*goal: ‹⋀m f. m1.invar m ⟹ m2.invar (m1.iterate m (λ(k, v) σ. case f k v of None ⇒ σ | Some v' ⇒ m2.update_dj k v' σ) (m2.empty ())) ∧ m2.α (m1.iterate m (λ(k, v) σ. case f k v of None ⇒ σ | Some v' ⇒ m2.update_dj k v' σ) (m2.empty ())) = (λk. m1.α m k ⤜ f k)›*) apply ((rule_tac I="λit σ. m2.invar σ ∧ m2.α σ = (λk. Option.bind (map_op_α ops1 m k) (f k)) |` it" in m1.old_iterate_rule_insert_P (*‹⟦m1.invar ?m; ?I {} ?σ0.0; ⋀k v it σ. ⟦k ∈ dom (m1.α ?m) - it; m1.α ?m k = Some v; it ⊆ dom (m1.α ?m); ?I it σ⟧ ⟹ ?I (insert k it) (?f (k, v) σ); ⋀σ. ?I (dom (m1.α ?m)) σ ⟹ ?P σ⟧ ⟹ ?P (m1.iterate ?m ?f ?σ0.0)›*))[1]) (*goals: 1. ‹⋀m f. m1.invar m ⟹ m1.invar m› 2. ‹⋀m f. m1.invar m ⟹ m2.invar (m2.empty ()) ∧ m2.α (m2.empty ()) = (λk. m1.α m k ⤜ f k) |` {}› 3. ‹⋀m f k v it σ. ⟦m1.invar m; k ∈ dom (m1.α m) - it; m1.α m k = Some v; it ⊆ dom (m1.α m); m2.invar σ ∧ m2.α σ = (λk. m1.α m k ⤜ f k) |` it⟧ ⟹ m2.invar ((case (k, v) of (k, v) ⇒ λσ. case f k v of None ⇒ σ | Some v' ⇒ m2.update_dj k v' σ) σ) ∧ m2.α ((case (k, v) of (k, v) ⇒ λσ. case f k v of None ⇒ σ | Some v' ⇒ m2.update_dj k v' σ) σ) = (λk. m1.α m k ⤜ f k) |` insert k it› 4. ‹⋀m f σ. ⟦m1.invar m; m2.invar σ ∧ m2.α σ = (λk. m1.α m k ⤜ f k) |` dom (m1.α m)⟧ ⟹ m2.invar σ ∧ m2.α σ = (λk. m1.α m k ⤜ f k)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto simp: m2.empty_correct (*‹m2.α (m2.empty ()) = (λx. None)› ‹m2.invar (m2.empty ())›*))[1]) (*discuss goal 3*) apply ((auto split: option.split (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))›*) simp: m2.update_dj_correct (*‹⟦m2.invar ?m; ?k ∉ dom (m2.α ?m)⟧ ⟹ m2.α (m2.update_dj ?k ?v ?m) = (m2.α ?m)(?k ↦ ?v)› ‹⟦m2.invar ?m; ?k ∉ dom (m2.α ?m)⟧ ⟹ m2.invar (m2.update_dj ?k ?v ?m)›*) intro!: ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*))[1]) (*goals: 1. ‹⋀m f k v it σ x. ⟦m1.invar m; it ⊆ dom (m1.α m); k ∉ it; m1.α m k = Some v; m2.invar σ; m2.α σ = (λk. m1.α m k ⤜ f k) |` it; f k v = None⟧ ⟹ ((λk. m1.α m k ⤜ f k) |` it) x = ((λk. m1.α m k ⤜ f k) |` insert k it) x› 2. ‹⋀m f k v it σ x2 x. ⟦m1.invar m; it ⊆ dom (m1.α m); k ∉ it; m1.α m k = Some v; m2.invar σ; m2.α σ = (λk. m1.α m k ⤜ f k) |` it; f k v = Some x2; x ≠ k⟧ ⟹ ((λk. m1.α m k ⤜ f k) |` it) x = ((λk. m1.α m k ⤜ f k) |` insert k it) x› discuss goal 1*) apply ((auto simp: restrict_map_def (*‹?m |` ?A = (λx. if x ∈ ?A then ?m x else None)›*))[1]) (*discuss goal 2*) apply ((auto simp: restrict_map_def (*‹(?m::?'a::type ⇒ ?'b::type option) |` (?A::?'a::type set) = (λx::?'a::type. if x ∈ ?A then ?m x else None)›*))[1]) (*proven 2 subgoals*) (*discuss goal 4*) apply simp (*goal: ‹⋀m f σ. ⟦m1.invar m; m2.invar σ ∧ m2.α σ = (λk. m1.α m k ⤜ f k) |` dom (m1.α m)⟧ ⟹ m2.invar σ ∧ m2.α σ = (λk. m1.α m k ⤜ f k)›*) apply (rule restrict_map_dom_subset (*‹dom ?m ⊆ ?R ⟹ ?m |` ?R = ?m›*)) (*goal: ‹⋀m f σ. ⟦m1.invar m; m2.invar σ ∧ m2.α σ = (λk. m1.α m k ⤜ f k) |` dom (m1.α m)⟧ ⟹ (λk. m1.α m k ⤜ f k) |` dom (m1.α m) = (λk. m1.α m k ⤜ f k)›*) apply ((auto)[1]) (*goal: ‹⋀(m::'s1) (f::'k ⇒ 'v1 ⇒ 'v2 option) σ::'s2. ⟦m1.invar m; m2.invar σ ∧ m2.α σ = (λk::'k. m1.α m k ⤜ f k) |` dom (m1.α m)⟧ ⟹ dom (λk::'k. m1.α m k ⤜ f k) ⊆ dom (m1.α m)›*) apply ((case_tac "m1.α m x")[1]) (*goals: 1. ‹⋀m f σ x y. ⟦m1.invar m; m1.α m x ⤜ f x = Some y; m2.invar σ; m2.α σ = (λk. m1.α m k ⤜ f k) |` dom (m1.α m); m1.α m x = None⟧ ⟹ ∃y. m1.α m x = Some y› 2. ‹⋀m f σ x y a. ⟦m1.invar m; m1.α m x ⤜ f x = Some y; m2.invar σ; m2.α σ = (λk. m1.α m k ⤜ f k) |` dom (m1.α m); m1.α m x = Some a⟧ ⟹ ∃y. m1.α m x = Some y› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*proven 4 subgoals*) . end sublocale g_value_image_filter_loc < map_value_image_filter m1.α m1.invar m2.α m2.invar g_value_image_filter by (rule g_value_image_filter_impl (*‹map_value_image_filter m1.α m1.invar m2.α m2.invar g_value_image_filter›*)) end
{ "path": "afp-2025-02-12/thys/Collections/ICF/gen_algo/MapGA.thy", "repo": "afp-2025-02-12", "sha": "71229f869d22a88fde30dd542f2684b50146fe7b906b1a98d0f113e82766d8ca" }
(***************************************************************************** * Featherweight-OCL --- A Formal Semantics for UML-OCL Version OCL 2.5 * for the OMG Standard. * http://www.brucker.ch/projects/hol-testgen/ * * Design_UML.thy --- OCL Contracts and an Example. * This file is part of HOL-TestGen. * * Copyright (c) 2012-2015 Université Paris-Saclay, Univ. Paris-Sud, France * 2013-2015 IRT SystemX, France * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * * Neither the name of the copyright holders nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************) chapter‹Example: The Employee Design Model› (* UML part *) theory Design_UML imports "../../../UML_Main" begin text ‹\label{ex:employee-design:uml}› section‹Introduction› text‹ For certain concepts like classes and class-types, only a generic definition for its resulting semantics can be given. Generic means, there is a function outside HOL that ``compiles'' a concrete, closed-world class diagram into a ``theory'' of this data model, consisting of a bunch of definitions for classes, accessors, method, casts, and tests for actual types, as well as proofs for the fundamental properties of these operations in this concrete data model.› text‹Such generic function or ``compiler'' can be implemented in Isabelle on the ML level. This has been done, for a semantics following the open-world assumption, for UML 2.0 in~\<^cite>‹"brucker.ea:extensible:2008-b" and "brucker:interactive:2007"›. In this paper, we follow another approach for UML 2.4: we define the concepts of the compilation informally, and present a concrete example which is verified in Isabelle/HOL.› subsection‹Outlining the Example› text‹We are presenting here a ``design-model'' of the (slightly modified) example Figure 7.3, page 20 of the OCL standard~\<^cite>‹"omg:ocl:2012"›. To be precise, this theory contains the formalization of the data-part covered by the UML class model (see \autoref{fig:person}):› text‹ \begin{figure} \centering\scalebox{.3}{\includegraphics{figures/person.png}}% \caption{A simple UML class model drawn from Figure 7.3, page 20 of~\<^cite>‹"omg:ocl:2012"›. \label{fig:person}} \end{figure} › text‹This means that the association (attached to the association class \inlineocl{EmployeeRanking}) with the association ends \inlineocl+boss+ and \inlineocl+employees+ is implemented by the attribute \inlineocl+boss+ and the operation \inlineocl+employees+ (to be discussed in the OCL part captured by the subsequent theory). › section‹Example Data-Universe and its Infrastructure› text‹Ideally, the following is generated automatically from a UML class model.› text‹Our data universe consists in the concrete class diagram just of node's, and implicitly of the class object. Each class implies the existence of a class type defined for the corresponding object representations as follows:› datatype type⇩P⇩e⇩r⇩s⇩o⇩n = mk⇩P⇩e⇩r⇩s⇩o⇩n oid (* the oid to the person itself *) "int option" (* the attribute "salary" or null *) "oid option" (* the attribute "boss" or null *) datatype type⇩O⇩c⇩l⇩A⇩n⇩y = mk⇩O⇩c⇩l⇩A⇩n⇩y oid (* the oid to the oclany itself *) "(int option × oid option) option" (* the extensions to "person"; used to denote objects of actual type "person" casted to "oclany"; in case of existence of several subclasses of oclany, sums of extensions have to be provided. *) text‹Now, we construct a concrete ``universe of OclAny types'' by injection into a sum type containing the class types. This type of OclAny will be used as instance for all respective type-variables.› datatype 𝔄 = in⇩P⇩e⇩r⇩s⇩o⇩n type⇩P⇩e⇩r⇩s⇩o⇩n | in⇩O⇩c⇩l⇩A⇩n⇩y type⇩O⇩c⇩l⇩A⇩n⇩y text‹Having fixed the object universe, we can introduce type synonyms that exactly correspond to OCL types. Again, we exploit that our representation of OCL is a ``shallow embedding'' with a one-to-one correspondance of OCL-types to types of the meta-language HOL.› type_synonym Boolean = " 𝔄 Boolean" type_synonym Integer = " 𝔄 Integer" type_synonym Void = " 𝔄 Void" type_synonym OclAny = "(𝔄, type⇩O⇩c⇩l⇩A⇩n⇩y option option) val" type_synonym Person = "(𝔄, type⇩P⇩e⇩r⇩s⇩o⇩n option option) val" type_synonym Set_Integer = "(𝔄, int option option) Set" type_synonym Set_Person = "(𝔄, type⇩P⇩e⇩r⇩s⇩o⇩n option option) Set" text‹Just a little check:› typ "Boolean" text‹To reuse key-elements of the library like referential equality, we have to show that the object universe belongs to the type class ``oclany,'' \ie, each class type has to provide a function @{term oid_of} yielding the object id (oid) of the object.› instantiation type⇩P⇩e⇩r⇩s⇩o⇩n :: object begin definition oid_of_type⇩P⇩e⇩r⇩s⇩o⇩n_def: "oid_of x = (case x of mk⇩P⇩e⇩r⇩s⇩o⇩n oid _ _ ⇒ oid)" instance .. end instantiation type⇩O⇩c⇩l⇩A⇩n⇩y :: object begin definition oid_of_type⇩O⇩c⇩l⇩A⇩n⇩y_def: "oid_of x = (case x of mk⇩O⇩c⇩l⇩A⇩n⇩y oid _ ⇒ oid)" instance .. end instantiation 𝔄 :: object begin definition oid_of_𝔄_def: "oid_of x = (case x of in⇩P⇩e⇩r⇩s⇩o⇩n person ⇒ oid_of person | in⇩O⇩c⇩l⇩A⇩n⇩y oclany ⇒ oid_of oclany)" instance .. end section‹Instantiation of the Generic Strict Equality› text‹We instantiate the referential equality on ‹Person› and ‹OclAny›› overloading StrictRefEq ≡ "StrictRefEq :: [Person,Person] ⇒ Boolean" begin definition StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t_⇩P⇩e⇩r⇩s⇩o⇩n : "(x::Person) ≐ y ≡ StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t x y" end overloading StrictRefEq ≡ "StrictRefEq :: [OclAny,OclAny] ⇒ Boolean" begin definition StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t_⇩O⇩c⇩l⇩A⇩n⇩y : "(x::OclAny) ≐ y ≡ StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t x y" end lemmas cps23 = cp_StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t[of "x::Person" "y::Person" "τ", simplified StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t_⇩P⇩e⇩r⇩s⇩o⇩n[symmetric]] cp_intro(9) [of "P::Person ⇒Person""Q::Person ⇒Person", simplified StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t_⇩P⇩e⇩r⇩s⇩o⇩n[symmetric] ] StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t_def [of "x::Person" "y::Person", simplified StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t_⇩P⇩e⇩r⇩s⇩o⇩n[symmetric]] StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t_defargs [of _ "x::Person" "y::Person", simplified StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t_⇩P⇩e⇩r⇩s⇩o⇩n[symmetric]] StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t_strict1 [of "x::Person", simplified StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t_⇩P⇩e⇩r⇩s⇩o⇩n[symmetric]] StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t_strict2 [of "x::Person", simplified StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t_⇩P⇩e⇩r⇩s⇩o⇩n[symmetric]] for x y τ P Q text‹For each Class \emph{C}, we will have a casting operation \inlineocl{.oclAsType($C$)}, a test on the actual type \inlineocl{.oclIsTypeOf($C$)} as well as its relaxed form \inlineocl{.oclIsKindOf($C$)} (corresponding exactly to Java's \verb+instanceof+-operator. › text‹Thus, since we have two class-types in our concrete class hierarchy, we have two operations to declare and to provide two overloading definitions for the two static types. › section‹OclAsType› subsection‹Definition› consts OclAsType⇩O⇩c⇩l⇩A⇩n⇩y :: "'α ⇒ OclAny" ("(_) .oclAsType'(OclAny')") consts OclAsType⇩P⇩e⇩r⇩s⇩o⇩n :: "'α ⇒ Person" ("(_) .oclAsType'(Person')") definition "OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 = (λu. ⌊case u of in⇩O⇩c⇩l⇩A⇩n⇩y a ⇒ a | in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b) ⇒ mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a,b)⌋⌋)" lemma OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄_some: "OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 x ≠ None" by (simp add: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄_def (*‹OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 = (λu. ⌊case u of in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b) ⇒ mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y a ⇒ a⌋)›*)) overloading OclAsType⇩O⇩c⇩l⇩A⇩n⇩y ≡ "OclAsType⇩O⇩c⇩l⇩A⇩n⇩y :: OclAny ⇒ OclAny" begin definition OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_OclAny: "(X::OclAny) .oclAsType(OclAny) ≡ X" end overloading OclAsType⇩O⇩c⇩l⇩A⇩n⇩y ≡ "OclAsType⇩O⇩c⇩l⇩A⇩n⇩y :: Person ⇒ OclAny" begin definition OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_Person: "(X::Person) .oclAsType(OclAny) ≡ (λτ. case X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b ⌋⌋ ⇒ ⌊⌊ (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a,b)⌋) ⌋⌋)" end definition "OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 = (λu. case u of in⇩P⇩e⇩r⇩s⇩o⇩n p ⇒ ⌊p⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a,b)⌋) ⇒ ⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋ | _ ⇒ None)" overloading OclAsType⇩P⇩e⇩r⇩s⇩o⇩n ≡ "OclAsType⇩P⇩e⇩r⇩s⇩o⇩n :: OclAny ⇒ Person" begin definition OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_OclAny: "(X::OclAny) .oclAsType(Person) ≡ (λτ. case X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥ ⌋⌋ ⇒ invalid τ ― ‹down-cast exception› | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a,b)⌋ ⌋⌋ ⇒ ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b ⌋⌋)" end overloading OclAsType⇩P⇩e⇩r⇩s⇩o⇩n ≡ "OclAsType⇩P⇩e⇩r⇩s⇩o⇩n :: Person ⇒ Person" begin definition OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_Person: "(X::Person) .oclAsType(Person) ≡ X " (* to avoid identity for null ? *) end text_raw‹\isatagafp› lemmas [simp] = OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_OclAny OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_Person subsection‹Context Passing› lemma cp_OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_Person_Person: "cp P ⟹ cp(λX. (P (X::Person)::Person) .oclAsType(OclAny))" apply (rule cpI1 (*‹⟦∀X τ. ?f X τ = ?f (λ_. X τ) τ; cp ?P⟧ ⟹ cp (λX. ?f (?P X))›*), simp_all add: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_Person) (*goal: ‹cp P ⟹ cp (λX. P X .oclAsType(OclAny))›*) by (msorry) lemma cp_OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_OclAny_OclAny: "cp P ⟹ cp(λX. (P (X::OclAny)::OclAny) .oclAsType(OclAny))" apply (rule cpI1 (*‹⟦∀X τ. ?f X τ = ?f (λ_. X τ) τ; cp ?P⟧ ⟹ cp (λX. ?f (?P X))›*)) (*goals: 1. ‹cp (P::(𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥) ⇒ 𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥) ⟹ ∀(X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥) τ::𝔄 state × 𝔄 state. X τ = X τ› 2. ‹cp (P::(𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥) ⇒ 𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥) ⟹ cp (λa::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥. P a .oclAsType(OclAny))› discuss goal 1*) apply (simp add: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_OclAny (*‹?X .oclAsType(OclAny) ≡ ?X›*)) (*discuss goal 2*) apply (simp add: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_OclAny (*‹?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥ .oclAsType(OclAny) ≡ ?X›*)) (*proven 2 subgoals*) . lemma cp_OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_Person_Person: "cp P ⟹ cp(λX. (P (X::Person)::Person) .oclAsType(Person))" apply (rule cpI1 (*‹⟦∀X τ. ?f X τ = ?f (λ_. X τ) τ; cp ?P⟧ ⟹ cp (λX. ?f (?P X))›*)) (*goals: 1. ‹cp P ⟹ ∀X τ. X τ = X τ› 2. ‹cp P ⟹ cp (λa. P a .oclAsType(Person))› discuss goal 1*) apply (simp add: OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_Person (*‹?X .oclAsType(Person) ≡ ?X›*)) (*discuss goal 2*) apply (simp add: OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_Person (*‹?X .oclAsType(Person) ≡ ?X›*)) (*proven 2 subgoals*) . lemma cp_OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_OclAny_OclAny: "cp P ⟹ cp(λX. (P (X::OclAny)::OclAny) .oclAsType(Person))" apply (rule cpI1 (*‹⟦∀X τ. ?f X τ = ?f (λ_. X τ) τ; cp ?P⟧ ⟹ cp (λX. ?f (?P X))›*), simp_all add: OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_OclAny) (*goal: ‹cp P ⟹ cp (λX. P X .oclAsType(Person))›*) by (msorry) lemma cp_OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_Person_OclAny: "cp P ⟹ cp(λX. (P (X::Person)::OclAny) .oclAsType(OclAny))" apply (rule cpI1 (*‹⟦∀X τ. ?f X τ = ?f (λ_. X τ) τ; cp ?P⟧ ⟹ cp (λX. ?f (?P X))›*)) (*goals: 1. ‹cp (P::(𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥) ⇒ 𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥) ⟹ ∀(X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥) τ::𝔄 state × 𝔄 state. X τ = X τ› 2. ‹cp (P::(𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥) ⇒ 𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥) ⟹ cp (λa::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥. P a .oclAsType(OclAny))› discuss goal 1*) apply (simp add: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_OclAny (*‹?X .oclAsType(OclAny) ≡ ?X›*)) (*discuss goal 2*) apply (simp add: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_OclAny (*‹?X .oclAsType(OclAny) ≡ ?X›*)) (*proven 2 subgoals*) . lemma cp_OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_OclAny_Person: "cp P ⟹ cp(λX. (P (X::OclAny)::Person) .oclAsType(OclAny))" apply (rule cpI1 (*‹⟦∀(X::?'a state × ?'a state ⇒ ?'b::type) τ::?'a state × ?'a state. (?f::(?'a state × ?'a state ⇒ ?'b::type) ⇒ ?'a state × ?'a state ⇒ ?'c::type) X τ = ?f (λ_::?'a state × ?'a state. X τ) τ; cp (?P::(?'a state × ?'a state ⇒ ?'d::type) ⇒ ?'a state × ?'a state ⇒ ?'b::type)⟧ ⟹ cp (λX::?'a state × ?'a state ⇒ ?'d::type. ?f (?P X))›*), simp_all add: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_Person) (*goal: ‹cp P ⟹ cp (λX. P X .oclAsType(OclAny))›*) by (msorry) lemma cp_OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_Person_OclAny: "cp P ⟹ cp(λX. (P (X::Person)::OclAny) .oclAsType(Person))" apply (rule cpI1 (*‹⟦∀X τ. ?f X τ = ?f (λ_. X τ) τ; cp ?P⟧ ⟹ cp (λX. ?f (?P X))›*), simp_all add: OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_OclAny) (*goal: ‹cp P ⟹ cp (λX. P X .oclAsType(Person))›*) by (msorry) lemma cp_OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_OclAny_Person: "cp P ⟹ cp(λX. (P (X::OclAny)::Person) .oclAsType(Person))" apply (rule cpI1 (*‹⟦∀X τ. ?f X τ = ?f (λ_. X τ) τ; cp ?P⟧ ⟹ cp (λX. ?f (?P X))›*)) (*goals: 1. ‹cp P ⟹ ∀X τ. X τ = X τ› 2. ‹cp P ⟹ cp (λa. P a .oclAsType(Person))› discuss goal 1*) apply (simp add: OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_Person (*‹?X .oclAsType(Person) ≡ ?X›*)) (*discuss goal 2*) apply (simp add: OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_Person (*‹?X .oclAsType(Person) ≡ ?X›*)) (*proven 2 subgoals*) . lemmas [simp] = cp_OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_Person_Person cp_OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_OclAny_OclAny cp_OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_Person_Person cp_OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_OclAny_OclAny cp_OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_Person_OclAny cp_OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_OclAny_Person cp_OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_Person_OclAny cp_OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_OclAny_Person text_raw‹\endisatagafp› subsection‹Execution with Invalid or Null as Argument› lemma OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_OclAny_strict : "(invalid::OclAny) .oclAsType(OclAny) = invalid" by simp lemma OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_OclAny_nullstrict : "(null::OclAny) .oclAsType(OclAny) = null" by simp lemma OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_Person_strict[simp] : "(invalid::Person) .oclAsType(OclAny) = invalid" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹invalid .oclAsType(OclAny) = invalid›*) by (simp add: bot_option_def (*‹⊥ ≡ ⊥›*) invalid_def (*‹invalid ≡ λτ. ⊥›*) OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_Person (*‹?X .oclAsType(OclAny) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋›*)) lemma OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_Person_nullstrict[simp] : "(null::Person) .oclAsType(OclAny) = null" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹null .oclAsType(OclAny) = null›*) by (simp add: null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_Person (*‹?X .oclAsType(OclAny) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋›*)) lemma OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_OclAny_strict[simp] : "(invalid::OclAny) .oclAsType(Person) = invalid" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹invalid .oclAsType(Person) = invalid›*) by (simp add: bot_option_def (*‹⊥ ≡ ⊥›*) invalid_def (*‹invalid ≡ λτ. ⊥›*) OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_OclAny (*‹?X .oclAsType(Person) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥⌋⌋ ⇒ invalid τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋ ⇒ ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋›*)) lemma OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_OclAny_nullstrict[simp] : "(null::OclAny) .oclAsType(Person) = null" apply (rule ext (*‹(⋀x::?'a. (?f::?'a ⇒ ?'b) x = (?g::?'a ⇒ ?'b) x) ⟹ ?f = ?g›*)) (*goal: ‹null .oclAsType(Person) = null›*) by (simp add: null_fun_def (*‹null ≡ λx::?'a. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_OclAny (*‹?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥ .oclAsType(Person) ≡ λτ::𝔄 state × 𝔄 state. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⊥⌋⌋ ⇒ invalid τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⌊(a::⟨int⟩⇩⊥, b::⟨nat⟩⇩⊥)⌋⌋⌋ ⇒ ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋›*)) lemma OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_Person_strict : "(invalid::Person) .oclAsType(Person) = invalid" by simp lemma OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_Person_nullstrict : "(null::Person) .oclAsType(Person) = null" by simp section‹OclIsTypeOf› subsection‹Definition› consts OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y :: "'α ⇒ Boolean" ("(_).oclIsTypeOf'(OclAny')") consts OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n :: "'α ⇒ Boolean" ("(_).oclIsTypeOf'(Person')") overloading OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y ≡ "OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y :: OclAny ⇒ Boolean" begin definition OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny: "(X::OclAny) .oclIsTypeOf(OclAny) ≡ (λτ. case X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ true τ ― ‹invalid ??› | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥ ⌋⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊_⌋ ⌋⌋ ⇒ false τ)" end lemma OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny': "(X::OclAny) .oclIsTypeOf(OclAny) = (λ τ. if τ ⊨ υ X then (case X τ of ⌊⊥⌋ ⇒ true τ ― ‹invalid ??› | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥ ⌋⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊_⌋ ⌋⌋ ⇒ false τ) else invalid τ)" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹X.oclIsTypeOf(OclAny) = (λτ. if τ ⊨ υ X then case X τ of ⌊⊥⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥⌋⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊x⌋⌋⌋ ⇒ false τ else invalid τ)›*) apply (simp add: OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny (*‹?X.oclIsTypeOf(OclAny) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥⌋⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊x⌋⌋⌋ ⇒ false τ›*)) (*goal: ‹⋀τ::𝔄 state × 𝔄 state. X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥.oclIsTypeOf(OclAny) τ = (if τ ⊨ υ X then case X τ of ⌊⊥⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⊥⌋⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⌊x::⟨int⟩⇩⊥ × ⟨nat⟩⇩⊥⌋⌋⌋ ⇒ false τ else invalid τ)›*) apply (case_tac "τ ⊨ υ X") (*goals: 1. ‹⋀τ::𝔄 state × 𝔄 state. τ ⊨ υ (X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥) ⟹ (τ ⊨ υ X ⟶ (case X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⊥⌋⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⌊xa::⟨int⟩⇩⊥ × ⟨nat⟩⇩⊥⌋⌋⌋ ⇒ false τ) = (case X τ of ⌊⊥⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⊥⌋⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⌊x::⟨int⟩⇩⊥ × ⟨nat⟩⇩⊥⌋⌋⌋ ⇒ false τ)) ∧ (τ |≠ υ X ⟶ (case X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⊥⌋⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⌊xa::⟨int⟩⇩⊥ × ⟨nat⟩⇩⊥⌋⌋⌋ ⇒ false τ) = invalid τ)› 2. ‹⋀τ::𝔄 state × 𝔄 state. τ |≠ υ (X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥) ⟹ (τ ⊨ υ X ⟶ (case X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⊥⌋⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⌊xa::⟨int⟩⇩⊥ × ⟨nat⟩⇩⊥⌋⌋⌋ ⇒ false τ) = (case X τ of ⌊⊥⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⊥⌋⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⌊x::⟨int⟩⇩⊥ × ⟨nat⟩⇩⊥⌋⌋⌋ ⇒ false τ)) ∧ (τ |≠ υ X ⟶ (case X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⊥⌋⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⌊xa::⟨int⟩⇩⊥ × ⟨nat⟩⇩⊥⌋⌋⌋ ⇒ false τ) = invalid τ)› discuss goal 1*) apply ((auto simp: foundation18' (*‹(?τ ⊨ υ ?X) = (?X ?τ ≠ ⊥)›*) bot_option_def (*‹⊥ ≡ ⊥›*))[1]) (*discuss goal 2*) apply ((auto simp: foundation18' (*‹(?τ::?'a state × ?'a state ⊨ υ (?X::?'a state × ?'a state ⇒ ?'b)) = (?X ?τ ≠ ⊥)›*) bot_option_def (*‹⊥ ≡ ⊥›*))[1]) (*proven 2 subgoals*) . interpretation OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny : profile_mono_schemeV "OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y::OclAny ⇒ Boolean" "λ X. (case X of ⌊None⌋ ⇒ ⌊⌊True⌋⌋ ― ‹invalid ??› | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid None ⌋⌋ ⇒ ⌊⌊True⌋⌋ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊_⌋ ⌋⌋ ⇒ ⌊⌊False⌋⌋)" apply unfold_locales (*goal: ‹profile_mono_schemeV OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y (λX. case X of ⌊⊥⌋ ⇒ ⌊⌊True⌋⌋ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥⌋⌋ ⇒ ⌊⌊True⌋⌋ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊x⌋⌋⌋ ⇒ ⌊⌊False⌋⌋)›*) apply (simp add: atomize_eq (*‹(?x::?'a ≡ ?y::?'a) ≡ ?x = ?y›*)) (*goal: ‹⋀x. x.oclIsTypeOf(OclAny) ≡ λτ. if (υ x) τ = true τ then case x τ of ⌊⊥⌋ ⇒ ⌊⌊True⌋⌋ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥⌋⌋ ⇒ ⌊⌊True⌋⌋ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊x⌋⌋⌋ ⇒ ⌊⌊False⌋⌋ else invalid τ›*) apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹⋀x::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥. x.oclIsTypeOf(OclAny) = (λτ::𝔄 state × 𝔄 state. if (υ x) τ = true τ then case x τ of ⌊⊥⌋ ⇒ ⌊⌊True⌋⌋ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⊥⌋⌋ ⇒ ⌊⌊True⌋⌋ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⌊xa::⟨int⟩⇩⊥ × ⟨nat⟩⇩⊥⌋⌋⌋ ⇒ ⌊⌊False⌋⌋ else invalid τ)›*) by (auto simp: OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny' (*‹?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥.oclIsTypeOf(OclAny) = (λτ::𝔄 state × 𝔄 state. if τ ⊨ υ ?X then case ?X τ of ⌊⊥⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⊥⌋⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⌊x::⟨int⟩⇩⊥ × ⟨nat⟩⇩⊥⌋⌋⌋ ⇒ false τ else invalid τ)›*) OclValid_def (*‹?τ::?'𝔄 state × ?'𝔄 state ⊨ ?P::?'𝔄 state × ?'𝔄 state ⇒ ⟨⟨bool⟩⇩⊥⟩⇩⊥ ≡ ?P ?τ = true ?τ›*) true_def (*‹true ≡ λτ::?'𝔄 state × ?'𝔄 state. ⌊⌊True⌋⌋›*) false_def (*‹false ≡ λτ::?'𝔄 state × ?'𝔄 state. ⌊⌊False⌋⌋›*) split: option.split (*‹(?P::?'b::type ⇒ bool) (case ?option::⟨?'a::type⟩⇩⊥ of ⊥ ⇒ ?f1.0::?'b::type | ⌊x::?'a::type⌋ ⇒ (?f2.0::?'a::type ⇒ ?'b::type) x) = ((?option = ⊥ ⟶ ?P ?f1.0) ∧ (∀x2::?'a::type. ?option = ⌊x2⌋ ⟶ ?P (?f2.0 x2)))›*) type⇩O⇩c⇩l⇩A⇩n⇩y.split (*‹(?P::?'a::type ⇒ bool) (case ?type⇩O⇩c⇩l⇩A⇩n⇩y::type⇩O⇩c⇩l⇩A⇩n⇩y of mk⇩O⇩c⇩l⇩A⇩n⇩y (x::nat) (xa::⟨⟨int⟩⇩⊥ × ⟨nat⟩⇩⊥⟩⇩⊥) ⇒ (?f::nat ⇒ ⟨⟨int⟩⇩⊥ × ⟨nat⟩⇩⊥⟩⇩⊥ ⇒ ?'a::type) x xa) = (∀(x1::nat) x2::⟨⟨int⟩⇩⊥ × ⟨nat⟩⇩⊥⟩⇩⊥. ?type⇩O⇩c⇩l⇩A⇩n⇩y = mk⇩O⇩c⇩l⇩A⇩n⇩y x1 x2 ⟶ ?P (?f x1 x2))›*)) overloading OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y ≡ "OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y :: Person ⇒ Boolean" begin definition OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_Person: "(X::Person) .oclIsTypeOf(OclAny) ≡ (λτ. case X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ true τ ― ‹invalid ??› | ⌊⌊ _ ⌋⌋ ⇒ false τ) ― ‹must have actual type ‹Person› otherwise›" end overloading OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n ≡ "OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n :: OclAny ⇒ Boolean" begin definition OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny: "(X::OclAny) .oclIsTypeOf(Person) ≡ (λτ. case X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥ ⌋⌋ ⇒ false τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊_⌋ ⌋⌋ ⇒ true τ)" end overloading OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n ≡ "OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n :: Person ⇒ Boolean" begin definition OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_Person: "(X::Person) .oclIsTypeOf(Person) ≡ (λτ. case X τ of ⊥ ⇒ invalid τ | _ ⇒ true τ)" (* for (* ⌊⌊ _ ⌋⌋ ⇒ true τ *) : must have actual type Node otherwise *) end text_raw‹\isatagafp› subsection‹Context Passing› lemma cp_OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_Person_Person: "cp P ⟹ cp(λX.(P(X::Person)::Person).oclIsTypeOf(OclAny))" apply (rule cpI1 (*‹⟦∀X τ. ?f X τ = ?f (λ_. X τ) τ; cp ?P⟧ ⟹ cp (λX. ?f (?P X))›*), simp_all add: OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_Person) (*goal: ‹cp P ⟹ cp (λX. P X.oclIsTypeOf(OclAny))›*) by (msorry) lemma cp_OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny_OclAny: "cp P ⟹ cp(λX.(P(X::OclAny)::OclAny).oclIsTypeOf(OclAny))" apply (rule cpI1 (*‹⟦∀(X::?'a state × ?'a state ⇒ ?'b) τ::?'a state × ?'a state. (?f::(?'a state × ?'a state ⇒ ?'b) ⇒ ?'a state × ?'a state ⇒ ?'c) X τ = ?f (λ_::?'a state × ?'a state. X τ) τ; cp (?P::(?'a state × ?'a state ⇒ ?'d) ⇒ ?'a state × ?'a state ⇒ ?'b)⟧ ⟹ cp (λX::?'a state × ?'a state ⇒ ?'d. ?f (?P X))›*), simp_all add: OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny) (*goal: ‹cp P ⟹ cp (λX. P X.oclIsTypeOf(OclAny))›*) by (msorry) lemma cp_OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_Person_Person: "cp P ⟹ cp(λX.(P(X::Person)::Person).oclIsTypeOf(Person))" apply (rule cpI1 (*‹⟦∀X τ. ?f X τ = ?f (λ_. X τ) τ; cp ?P⟧ ⟹ cp (λX. ?f (?P X))›*), simp_all add: OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_Person) (*goal: ‹cp P ⟹ cp (λX. P X.oclIsTypeOf(Person))›*) by (msorry) lemma cp_OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny_OclAny: "cp P ⟹ cp(λX.(P(X::OclAny)::OclAny).oclIsTypeOf(Person))" apply (rule cpI1 (*‹⟦∀X τ. ?f X τ = ?f (λ_. X τ) τ; cp ?P⟧ ⟹ cp (λX. ?f (?P X))›*), simp_all add: OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny) (*goal: ‹cp (P::(𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥) ⇒ 𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥) ⟹ cp (λX::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥. P X.oclIsTypeOf(Person))›*) by (msorry) lemma cp_OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_Person_OclAny: "cp P ⟹ cp(λX.(P(X::Person)::OclAny).oclIsTypeOf(OclAny))" apply (rule cpI1 (*‹⟦∀X τ. ?f X τ = ?f (λ_. X τ) τ; cp ?P⟧ ⟹ cp (λX. ?f (?P X))›*), simp_all add: OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny) (*goal: ‹cp (P::(𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥) ⇒ 𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥) ⟹ cp (λX::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥. P X.oclIsTypeOf(OclAny))›*) by (msorry) lemma cp_OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny_Person: "cp P ⟹ cp(λX.(P(X::OclAny)::Person).oclIsTypeOf(OclAny))" apply (rule cpI1 (*‹⟦∀X τ. ?f X τ = ?f (λ_. X τ) τ; cp ?P⟧ ⟹ cp (λX. ?f (?P X))›*), simp_all add: OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_Person) (*goal: ‹cp P ⟹ cp (λX. P X.oclIsTypeOf(OclAny))›*) by (msorry) lemma cp_OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_Person_OclAny: "cp P ⟹ cp(λX.(P(X::Person)::OclAny).oclIsTypeOf(Person))" apply (rule cpI1 (*‹⟦∀X τ. ?f X τ = ?f (λ_. X τ) τ; cp ?P⟧ ⟹ cp (λX. ?f (?P X))›*), simp_all add: OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny) (*goal: ‹cp P ⟹ cp (λX. P X.oclIsTypeOf(Person))›*) by (msorry) lemma cp_OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny_Person: "cp P ⟹ cp(λX.(P(X::OclAny)::Person).oclIsTypeOf(Person))" apply (rule cpI1 (*‹⟦∀X τ. ?f X τ = ?f (λ_. X τ) τ; cp ?P⟧ ⟹ cp (λX. ?f (?P X))›*), simp_all add: OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_Person) (*goal: ‹cp (P::(𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥) ⇒ 𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥) ⟹ cp (λX::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥. P X.oclIsTypeOf(Person))›*) by (msorry) lemmas [simp] = cp_OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_Person_Person cp_OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny_OclAny cp_OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_Person_Person cp_OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny_OclAny cp_OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_Person_OclAny cp_OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny_Person cp_OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_Person_OclAny cp_OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny_Person text_raw‹\endisatagafp› subsection‹Execution with Invalid or Null as Argument› lemma OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny_strict1[simp]: "(invalid::OclAny) .oclIsTypeOf(OclAny) = invalid" apply (rule ext (*‹(⋀x::?'a. (?f::?'a ⇒ ?'b) x = (?g::?'a ⇒ ?'b) x) ⟹ ?f = ?g›*)) (*goal: ‹invalid.oclIsTypeOf(OclAny) = invalid›*) by (simp add: null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null ?xs = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ. ⊥›*) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny (*‹?X.oclIsTypeOf(OclAny) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥⌋⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊x⌋⌋⌋ ⇒ false τ›*)) lemma OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny_strict2[simp]: "(null::OclAny) .oclIsTypeOf(OclAny) = true" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹null.oclIsTypeOf(OclAny) = true›*) by (simp add: null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null ?xs = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ. ⊥›*) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny (*‹?X.oclIsTypeOf(OclAny) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥⌋⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊x⌋⌋⌋ ⇒ false τ›*)) lemma OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_Person_strict1[simp]: "(invalid::Person) .oclIsTypeOf(OclAny) = invalid" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹invalid.oclIsTypeOf(OclAny) = invalid›*) by (simp add: null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null ?xs = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ. ⊥›*) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_Person (*‹?X.oclIsTypeOf(OclAny) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ true τ | ⌊⌊x⌋⌋ ⇒ false τ›*)) lemma OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_Person_strict2[simp]: "(null::Person) .oclIsTypeOf(OclAny) = true" apply (rule ext (*‹(⋀x::?'a. (?f::?'a ⇒ ?'b) x = (?g::?'a ⇒ ?'b) x) ⟹ ?f = ?g›*)) (*goal: ‹null.oclIsTypeOf(OclAny) = true›*) by (simp add: null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null ?xs = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ. ⊥›*) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_Person (*‹?X.oclIsTypeOf(OclAny) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ true τ | ⌊⌊x⌋⌋ ⇒ false τ›*)) lemma OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny_strict1[simp]: "(invalid::OclAny) .oclIsTypeOf(Person) = invalid" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹invalid.oclIsTypeOf(Person) = invalid›*) by (simp add: null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null ?xs = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ. ⊥›*) OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny (*‹?X.oclIsTypeOf(Person) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥⌋⌋ ⇒ false τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊x⌋⌋⌋ ⇒ true τ›*)) lemma OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny_strict2[simp]: "(null::OclAny) .oclIsTypeOf(Person) = true" apply (rule ext (*‹(⋀x::?'a. (?f::?'a ⇒ ?'b) x = (?g::?'a ⇒ ?'b) x) ⟹ ?f = ?g›*)) (*goal: ‹null.oclIsTypeOf(Person) = true›*) by (simp add: null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null ?xs = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ. ⊥›*) OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny (*‹?X.oclIsTypeOf(Person) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥⌋⌋ ⇒ false τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊x⌋⌋⌋ ⇒ true τ›*)) lemma OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_Person_strict1[simp]: "(invalid::Person) .oclIsTypeOf(Person) = invalid" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹invalid.oclIsTypeOf(Person) = invalid›*) by (simp add: null_fun_def (*‹null ≡ λx::?'a::type. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null (?xs::?'a::type list) = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ::?'𝔄 state × ?'𝔄 state. ⊥›*) OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_Person (*‹?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.oclIsTypeOf(Person) ≡ λτ::𝔄 state × 𝔄 state. case ?X τ of ⊥ ⇒ invalid τ | ⌊a::⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⌋ ⇒ true τ›*)) lemma OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_Person_strict2[simp]: "(null::Person) .oclIsTypeOf(Person) = true" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹null.oclIsTypeOf(Person) = true›*) by (simp add: null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null ?xs = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ. ⊥›*) OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_Person (*‹?X.oclIsTypeOf(Person) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊a⌋ ⇒ true τ›*)) subsection‹Up Down Casting› lemma actualType_larger_staticType: assumes isdef: "τ ⊨ (δ X)" shows "τ ⊨ (X::Person) .oclIsTypeOf(OclAny) ≜ false" using isdef (*‹τ ⊨ δ X›*) by (auto simp : null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_Person (*‹?X.oclIsTypeOf(OclAny) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ true τ | ⌊⌊x⌋⌋ ⇒ false τ›*) foundation22 (*‹(?τ ⊨ ?X ≜ ?Y) = (?X ?τ = ?Y ?τ)›*) foundation16 (*‹(?τ ⊨ δ ?X) = (?X ?τ ≠ ⊥ ∧ ?X ?τ ≠ null)›*)) lemma down_cast_type: assumes isOclAny: "τ ⊨ (X::OclAny) .oclIsTypeOf(OclAny)" and non_null: "τ ⊨ (δ X)" shows "τ ⊨ (X .oclAsType(Person)) ≜ invalid" using isOclAny (*‹τ::𝔄 state × 𝔄 state ⊨ X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥.oclIsTypeOf(OclAny)›*) non_null (*‹τ ⊨ δ X›*) apply (auto simp : bot_fun_def (*‹⊥ ≡ λx::?'a. ⊥›*) null_fun_def (*‹null ≡ λx::?'a. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null (?xs::?'a list) = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ::?'𝔄 state × ?'𝔄 state. ⊥›*) OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_Person (*‹?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥ .oclAsType(OclAny) ≡ λτ::𝔄 state × 𝔄 state. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n (oid::nat) (a::⟨int⟩⇩⊥) (b::⟨nat⟩⇩⊥)⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋›*) OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_OclAny (*‹?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥ .oclAsType(Person) ≡ λτ::𝔄 state × 𝔄 state. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⊥⌋⌋ ⇒ invalid τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⌊(a::⟨int⟩⇩⊥, b::⟨nat⟩⇩⊥)⌋⌋⌋ ⇒ ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋›*) foundation22 (*‹(?τ::?'a state × ?'a state ⊨ (?X::?'a state × ?'a state ⇒ ?'b) ≜ (?Y::?'a state × ?'a state ⇒ ?'b)) = (?X ?τ = ?Y ?τ)›*) foundation16 (*‹(?τ::?'a state × ?'a state ⊨ δ (?X::?'a state × ?'a state ⇒ ?'b)) = (?X ?τ ≠ ⊥ ∧ ?X ?τ ≠ null)›*) split: option.split (*‹(?P::?'b ⇒ bool) (case ?option::⟨?'a⟩⇩⊥ of ⊥ ⇒ ?f1.0::?'b | ⌊x::?'a⌋ ⇒ (?f2.0::?'a ⇒ ?'b) x) = ((?option = ⊥ ⟶ ?P ?f1.0) ∧ (∀x2::?'a. ?option = ⌊x2⌋ ⟶ ?P (?f2.0 x2)))›*) type⇩O⇩c⇩l⇩A⇩n⇩y.split (*‹(?P::?'a ⇒ bool) (case ?type⇩O⇩c⇩l⇩A⇩n⇩y::type⇩O⇩c⇩l⇩A⇩n⇩y of mk⇩O⇩c⇩l⇩A⇩n⇩y (x::nat) (xa::⟨⟨int⟩⇩⊥ × ⟨nat⟩⇩⊥⟩⇩⊥) ⇒ (?f::nat ⇒ ⟨⟨int⟩⇩⊥ × ⟨nat⟩⇩⊥⟩⇩⊥ ⇒ ?'a) x xa) = (∀(x1::nat) x2::⟨⟨int⟩⇩⊥ × ⟨nat⟩⇩⊥⟩⇩⊥. ?type⇩O⇩c⇩l⇩A⇩n⇩y = mk⇩O⇩c⇩l⇩A⇩n⇩y x1 x2 ⟶ ?P (?f x1 x2))›*) type⇩P⇩e⇩r⇩s⇩o⇩n.split (*‹(?P::?'a ⇒ bool) (case ?type⇩P⇩e⇩r⇩s⇩o⇩n::type⇩P⇩e⇩r⇩s⇩o⇩n of mk⇩P⇩e⇩r⇩s⇩o⇩n (x::nat) (xa::⟨int⟩⇩⊥) (xb::⟨nat⟩⇩⊥) ⇒ (?f::nat ⇒ ⟨int⟩⇩⊥ ⇒ ⟨nat⟩⇩⊥ ⇒ ?'a) x xa xb) = (∀(x1::nat) (x2::⟨int⟩⇩⊥) x3::⟨nat⟩⇩⊥. ?type⇩P⇩e⇩r⇩s⇩o⇩n = mk⇩P⇩e⇩r⇩s⇩o⇩n x1 x2 x3 ⟶ ?P (?f x1 x2 x3))›*)) (*goal: ‹τ::𝔄 state × 𝔄 state ⊨ X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥ .oclAsType(Person) ≜ invalid›*) by (simp add: OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny (*‹?X.oclIsTypeOf(OclAny) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥⌋⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊x⌋⌋⌋ ⇒ false τ›*) OclValid_def (*‹?τ ⊨ ?P ≡ ?P ?τ = true ?τ›*) false_def (*‹false ≡ λτ. ⌊⌊False⌋⌋›*) true_def (*‹true ≡ λτ. ⌊⌊True⌋⌋›*)) lemma down_cast_type': assumes isOclAny: "τ ⊨ (X::OclAny) .oclIsTypeOf(OclAny)" and non_null: "τ ⊨ (δ X)" shows "τ ⊨ not (υ (X .oclAsType(Person)))" apply (rule foundation15[THEN iffD1] (*‹?τ1 ⊨ ?A1 ≜ invalid ⟹ ?τ1 ⊨ not (υ ?A1)›*)) (*goal: ‹τ ⊨ not (υ X .oclAsType(Person))›*) by (simp add: down_cast_type[OF assms] (*‹τ ⊨ X .oclAsType(Person) ≜ invalid›*)) lemma up_down_cast : assumes isdef: "τ ⊨ (δ X)" shows "τ ⊨ ((X::Person) .oclAsType(OclAny) .oclAsType(Person) ≜ X)" using isdef (*‹τ::𝔄 state × 𝔄 state ⊨ δ (X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥)›*) by (auto simp : null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null ?xs = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ. ⊥›*) OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_Person (*‹?X .oclAsType(OclAny) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋›*) OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_OclAny (*‹?X .oclAsType(Person) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥⌋⌋ ⇒ invalid τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋ ⇒ ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋›*) foundation22 (*‹(?τ ⊨ ?X ≜ ?Y) = (?X ?τ = ?Y ?τ)›*) foundation16 (*‹(?τ ⊨ δ ?X) = (?X ?τ ≠ ⊥ ∧ ?X ?τ ≠ null)›*) split: option.split (*‹?P (case ?option of ⊥ ⇒ ?f1.0 | ⌊x⌋ ⇒ ?f2.0 x) = ((?option = ⊥ ⟶ ?P ?f1.0) ∧ (∀x2. ?option = ⌊x2⌋ ⟶ ?P (?f2.0 x2)))›*) type⇩P⇩e⇩r⇩s⇩o⇩n.split (*‹?P (case ?type⇩P⇩e⇩r⇩s⇩o⇩n of mk⇩P⇩e⇩r⇩s⇩o⇩n x xa xb ⇒ ?f x xa xb) = (∀x1 x2 x3. ?type⇩P⇩e⇩r⇩s⇩o⇩n = mk⇩P⇩e⇩r⇩s⇩o⇩n x1 x2 x3 ⟶ ?P (?f x1 x2 x3))›*)) lemma up_down_cast_Person_OclAny_Person [simp]: shows "((X::Person) .oclAsType(OclAny) .oclAsType(Person) = X)" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹X .oclAsType(OclAny) .oclAsType(Person) = X›*) apply (rename_tac τ) (*goal: ‹⋀x. X .oclAsType(OclAny) .oclAsType(Person) x = X x›*) apply (rule foundation22[THEN iffD1] (*‹?τ1::?'a1 state × ?'a1 state ⊨ (?X1::?'a1 state × ?'a1 state ⇒ ?'b1) ≜ (?Y1::?'a1 state × ?'a1 state ⇒ ?'b1) ⟹ ?X1 ?τ1 = ?Y1 ?τ1›*)) (*goal: ‹⋀τ::𝔄 state × 𝔄 state. X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥ .oclAsType(OclAny) .oclAsType(Person) τ = X τ›*) apply (case_tac "τ ⊨ (δ X)") (*goals: 1. ‹⋀τ. τ ⊨ δ X ⟹ τ ⊨ X .oclAsType(OclAny) .oclAsType(Person) ≜ X› 2. ‹⋀τ. τ |≠ δ X ⟹ τ ⊨ X .oclAsType(OclAny) .oclAsType(Person) ≜ X› discuss goal 1*) apply (simp add: up_down_cast (*‹?τ ⊨ δ ?X ⟹ ?τ ⊨ ?X .oclAsType(OclAny) .oclAsType(Person) ≜ ?X›*)) (*discuss goal 2*) apply (simp add: defined_split (*‹(?τ ⊨ δ ?x) = (?τ |≠ ?x ≜ invalid ∧ ?τ |≠ ?x ≜ null)›*)) (*goal: ‹⋀τ::𝔄 state × 𝔄 state. τ |≠ δ (X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥) ⟹ τ ⊨ X .oclAsType(OclAny) .oclAsType(Person) ≜ X›*) apply (elim disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹⋀τ::𝔄 state × 𝔄 state. τ ⊨ (X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥) ≜ invalid ⟹ τ ⊨ X .oclAsType(OclAny) .oclAsType(Person) ≜ X› 2. ‹⋀τ::𝔄 state × 𝔄 state. τ ⊨ (X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥) ≜ null ⟹ τ ⊨ X .oclAsType(OclAny) .oclAsType(Person) ≜ X› discuss goal 1*) apply (erule StrongEq_L_subst2_rev (*‹⟦?τ ⊨ ?y ≜ ?x; cp ?P; ?τ ⊨ ?P ?x⟧ ⟹ ?τ ⊨ ?P ?y›*)) (*goals: 1. ‹⋀τ. cp (λa. a .oclAsType(OclAny) .oclAsType(Person) ≜ a)› 2. ‹⋀τ. τ ⊨ invalid .oclAsType(OclAny) .oclAsType(Person) ≜ invalid› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (erule StrongEq_L_subst2_rev (*‹⟦?τ ⊨ ?y ≜ ?x; cp ?P; ?τ ⊨ ?P ?x⟧ ⟹ ?τ ⊨ ?P ?y›*)) (*goals: 1. ‹⋀τ. cp (λa. a .oclAsType(OclAny) .oclAsType(Person) ≜ a)› 2. ‹⋀τ. τ ⊨ null .oclAsType(OclAny) .oclAsType(Person) ≜ null› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma up_down_cast_Person_OclAny_Person': assumes "τ ⊨ υ X" shows "τ ⊨ (((X :: Person) .oclAsType(OclAny) .oclAsType(Person)) ≐ X)" apply (simp only: up_down_cast_Person_OclAny_Person (*‹?X .oclAsType(OclAny) .oclAsType(Person) = ?X›*) StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t_⇩P⇩e⇩r⇩s⇩o⇩n (*‹?x ≐ ?y ≡ StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t ?x ?y›*)) (*goal: ‹τ ⊨ X .oclAsType(OclAny) .oclAsType(Person) ≐ X›*) apply (rule StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t_sym (*‹?τ ⊨ υ ?x ⟹ ?τ ⊨ StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t ?x ?x›*)) (*goal: ‹τ ⊨ StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t X X›*) by (simp add: assms (*‹τ ⊨ υ X›*)) lemma up_down_cast_Person_OclAny_Person'': assumes "τ ⊨ υ (X :: Person)" shows "τ ⊨ (X .oclIsTypeOf(Person) implies (X .oclAsType(OclAny) .oclAsType(Person)) ≐ X)" apply (simp add: OclValid_def (*‹?τ ⊨ ?P ≡ ?P ?τ = true ?τ›*)) (*goal: ‹τ ⊨ X.oclIsTypeOf(Person) implies X .oclAsType(OclAny) .oclAsType(Person) ≐ X›*) apply (subst cp_OclImplies (*‹((?X::?'a state × ?'a state ⇒ ⟨⟨bool⟩⇩⊥⟩⇩⊥) implies (?Y::?'a state × ?'a state ⇒ ⟨⟨bool⟩⇩⊥⟩⇩⊥)) (?τ::?'a state × ?'a state) = ((λ_::?'a state × ?'a state. ?X ?τ) implies (λ_::?'a state × ?'a state. ?Y ?τ)) ?τ›*)) (*goal: ‹(X.oclIsTypeOf(Person) implies X ≐ X) τ = true τ›*) apply (simp add: StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t_⇩P⇩e⇩r⇩s⇩o⇩n (*‹?x ≐ ?y ≡ StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t ?x ?y›*) StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t_sym[OF assms, simplified OclValid_def] (*‹StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t X X τ = true τ›*)) (*goal: ‹((λ_. X.oclIsTypeOf(Person) τ) implies (λ_. (X ≐ X) τ)) τ = true τ›*) apply (subst cp_OclImplies[symmetric] (*‹((λ_. ?X ?τ) implies (λ_. ?Y ?τ)) ?τ = (?X implies ?Y) ?τ›*)) (*goal: ‹((λ_. X.oclIsTypeOf(Person) τ) implies (λ_. true τ)) τ = true τ›*) by simp section‹OclIsKindOf› subsection‹Definition› consts OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y :: "'α ⇒ Boolean" ("(_).oclIsKindOf'(OclAny')") consts OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n :: "'α ⇒ Boolean" ("(_).oclIsKindOf'(Person')") overloading OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y ≡ "OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y :: OclAny ⇒ Boolean" begin definition OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny: "(X::OclAny) .oclIsKindOf(OclAny) ≡ (λτ. case X τ of ⊥ ⇒ invalid τ | _ ⇒ true τ)" end overloading OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y ≡ "OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y :: Person ⇒ Boolean" begin definition OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_Person: "(X::Person) .oclIsKindOf(OclAny) ≡ (λτ. case X τ of ⊥ ⇒ invalid τ | _⇒ true τ)" (* for (* ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n e oid _ ⌋⌋ ⇒ true τ *) : must have actual type Person otherwise *) end overloading OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n ≡ "OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n :: OclAny ⇒ Boolean" begin definition OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny: "(X::OclAny) .oclIsKindOf(Person) ≡ (λτ. case X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥ ⌋⌋ ⇒ false τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊_⌋ ⌋⌋ ⇒ true τ)" end overloading OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n ≡ "OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n :: Person ⇒ Boolean" begin definition OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_Person: "(X::Person) .oclIsKindOf(Person) ≡ (λτ. case X τ of ⊥ ⇒ invalid τ | _ ⇒ true τ)" end text_raw‹\isatagafp› subsection‹Context Passing› lemma cp_OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_Person_Person: "cp P ⟹ cp(λX.(P(X::Person)::Person).oclIsKindOf(OclAny))" apply (rule cpI1 (*‹⟦∀X τ. ?f X τ = ?f (λ_. X τ) τ; cp ?P⟧ ⟹ cp (λX. ?f (?P X))›*), simp_all add: OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_Person) (*goal: ‹cp (P::(𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥) ⇒ 𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥) ⟹ cp (λX::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥. P X.oclIsKindOf(OclAny))›*) by (msorry) lemma cp_OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny_OclAny: "cp P ⟹ cp(λX.(P(X::OclAny)::OclAny).oclIsKindOf(OclAny))" apply (rule cpI1 (*‹⟦∀X τ. ?f X τ = ?f (λ_. X τ) τ; cp ?P⟧ ⟹ cp (λX. ?f (?P X))›*), simp_all add: OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny) (*goal: ‹cp P ⟹ cp (λX. P X.oclIsKindOf(OclAny))›*) by (msorry) lemma cp_OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_Person_Person: "cp P ⟹ cp(λX.(P(X::Person)::Person).oclIsKindOf(Person))" apply (rule cpI1 (*‹⟦∀(X::?'a state × ?'a state ⇒ ?'b) τ::?'a state × ?'a state. (?f::(?'a state × ?'a state ⇒ ?'b) ⇒ ?'a state × ?'a state ⇒ ?'c) X τ = ?f (λ_::?'a state × ?'a state. X τ) τ; cp (?P::(?'a state × ?'a state ⇒ ?'d) ⇒ ?'a state × ?'a state ⇒ ?'b)⟧ ⟹ cp (λX::?'a state × ?'a state ⇒ ?'d. ?f (?P X))›*), simp_all add: OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_Person) (*goal: ‹cp (P::(𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥) ⇒ 𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥) ⟹ cp (λX::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥. P X.oclIsKindOf(Person))›*) by (msorry) lemma cp_OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny_OclAny: "cp P ⟹ cp(λX.(P(X::OclAny)::OclAny).oclIsKindOf(Person))" apply (rule cpI1 (*‹⟦∀X τ. ?f X τ = ?f (λ_. X τ) τ; cp ?P⟧ ⟹ cp (λX. ?f (?P X))›*), simp_all add: OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny) (*goal: ‹cp P ⟹ cp (λX. P X.oclIsKindOf(Person))›*) by (msorry) lemma cp_OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_Person_OclAny: "cp P ⟹ cp(λX.(P(X::Person)::OclAny).oclIsKindOf(OclAny))" apply (rule cpI1 (*‹⟦∀X τ. ?f X τ = ?f (λ_. X τ) τ; cp ?P⟧ ⟹ cp (λX. ?f (?P X))›*), simp_all add: OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny) (*goal: ‹cp (P::(𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥) ⇒ 𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥) ⟹ cp (λX::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥. P X.oclIsKindOf(OclAny))›*) by (msorry) lemma cp_OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny_Person: "cp P ⟹ cp(λX.(P(X::OclAny)::Person).oclIsKindOf(OclAny))" apply (rule cpI1 (*‹⟦∀X τ. ?f X τ = ?f (λ_. X τ) τ; cp ?P⟧ ⟹ cp (λX. ?f (?P X))›*), simp_all add: OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_Person) (*goal: ‹cp P ⟹ cp (λX. P X.oclIsKindOf(OclAny))›*) by (msorry) lemma cp_OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_Person_OclAny: "cp P ⟹ cp(λX.(P(X::Person)::OclAny).oclIsKindOf(Person))" apply (rule cpI1 (*‹⟦∀X τ. ?f X τ = ?f (λ_. X τ) τ; cp ?P⟧ ⟹ cp (λX. ?f (?P X))›*), simp_all add: OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny) (*goal: ‹cp P ⟹ cp (λX. P X.oclIsKindOf(Person))›*) by (msorry) lemma cp_OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny_Person: "cp P ⟹ cp(λX.(P(X::OclAny)::Person).oclIsKindOf(Person))" apply (rule cpI1 (*‹⟦∀X τ. ?f X τ = ?f (λ_. X τ) τ; cp ?P⟧ ⟹ cp (λX. ?f (?P X))›*), simp_all add: OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_Person) (*goal: ‹cp (P::(𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥) ⇒ 𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥) ⟹ cp (λX::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥. P X.oclIsKindOf(Person))›*) by (msorry) lemmas [simp] = cp_OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_Person_Person cp_OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny_OclAny cp_OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_Person_Person cp_OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny_OclAny cp_OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_Person_OclAny cp_OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny_Person cp_OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_Person_OclAny cp_OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny_Person text_raw‹\endisatagafp› subsection‹Execution with Invalid or Null as Argument› lemma OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny_strict1[simp] : "(invalid::OclAny) .oclIsKindOf(OclAny) = invalid" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹invalid.oclIsKindOf(OclAny) = invalid›*) by (simp add: invalid_def (*‹invalid ≡ λτ. ⊥›*) bot_option_def (*‹⊥ ≡ ⊥›*) OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny (*‹?X.oclIsKindOf(OclAny) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊a⌋ ⇒ true τ›*)) lemma OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny_strict2[simp] : "(null::OclAny) .oclIsKindOf(OclAny) = true" apply (rule ext (*‹(⋀x::?'a. (?f::?'a ⇒ ?'b) x = (?g::?'a ⇒ ?'b) x) ⟹ ?f = ?g›*)) (*goal: ‹null.oclIsKindOf(OclAny) = true›*) by (simp add: null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny (*‹?X.oclIsKindOf(OclAny) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊a⌋ ⇒ true τ›*)) lemma OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_Person_strict1[simp] : "(invalid::Person) .oclIsKindOf(OclAny) = invalid" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹invalid.oclIsKindOf(OclAny) = invalid›*) by (simp add: bot_option_def (*‹⊥ ≡ ⊥›*) invalid_def (*‹invalid ≡ λτ::?'𝔄 state × ?'𝔄 state. ⊥›*) OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_Person (*‹?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.oclIsKindOf(OclAny) ≡ λτ::𝔄 state × 𝔄 state. case ?X τ of ⊥ ⇒ invalid τ | ⌊a::⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⌋ ⇒ true τ›*)) lemma OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_Person_strict2[simp] : "(null::Person) .oclIsKindOf(OclAny) = true" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹null.oclIsKindOf(OclAny) = true›*) by (simp add: null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_Person (*‹?X.oclIsKindOf(OclAny) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊a⌋ ⇒ true τ›*)) lemma OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny_strict1[simp]: "(invalid::OclAny) .oclIsKindOf(Person) = invalid" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹invalid.oclIsKindOf(Person) = invalid›*) by (simp add: null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null ?xs = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ. ⊥›*) OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny (*‹?X.oclIsKindOf(Person) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥⌋⌋ ⇒ false τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊x⌋⌋⌋ ⇒ true τ›*)) lemma OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny_strict2[simp]: "(null::OclAny) .oclIsKindOf(Person) = true" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹null.oclIsKindOf(Person) = true›*) by (simp add: null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null ?xs = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ. ⊥›*) OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny (*‹?X.oclIsKindOf(Person) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥⌋⌋ ⇒ false τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊x⌋⌋⌋ ⇒ true τ›*)) lemma OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_Person_strict1[simp]: "(invalid::Person) .oclIsKindOf(Person) = invalid" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹invalid.oclIsKindOf(Person) = invalid›*) by (simp add: null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null ?xs = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ. ⊥›*) OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_Person (*‹?X.oclIsKindOf(Person) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊a⌋ ⇒ true τ›*)) lemma OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_Person_strict2[simp]: "(null::Person) .oclIsKindOf(Person) = true" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹null.oclIsKindOf(Person) = true›*) by (simp add: null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null ?xs = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ. ⊥›*) OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_Person (*‹?X.oclIsKindOf(Person) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊a⌋ ⇒ true τ›*)) subsection‹Up Down Casting› lemma actualKind_larger_staticKind: assumes isdef: "τ ⊨ (δ X)" shows "τ ⊨ ((X::Person) .oclIsKindOf(OclAny) ≜ true)" using isdef (*‹τ ⊨ δ X›*) by (auto simp : bot_option_def (*‹⊥ ≡ ⊥›*) OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_Person (*‹?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.oclIsKindOf(OclAny) ≡ λτ::𝔄 state × 𝔄 state. case ?X τ of ⊥ ⇒ invalid τ | ⌊a::⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⌋ ⇒ true τ›*) foundation22 (*‹(?τ::?'a state × ?'a state ⊨ (?X::?'a state × ?'a state ⇒ ?'b) ≜ (?Y::?'a state × ?'a state ⇒ ?'b)) = (?X ?τ = ?Y ?τ)›*) foundation16 (*‹(?τ::?'a state × ?'a state ⊨ δ (?X::?'a state × ?'a state ⇒ ?'b)) = (?X ?τ ≠ ⊥ ∧ ?X ?τ ≠ null)›*)) lemma down_cast_kind: assumes isOclAny: "¬ (τ ⊨ ((X::OclAny).oclIsKindOf(Person)))" and non_null: "τ ⊨ (δ X)" shows "τ ⊨ ((X .oclAsType(Person)) ≜ invalid)" using isOclAny (*‹τ |≠ X.oclIsKindOf(Person)›*) non_null (*‹τ ⊨ δ X›*) apply (auto simp : bot_fun_def (*‹⊥ ≡ λx. ⊥›*) null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null ?xs = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ. ⊥›*) OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_Person (*‹?X .oclAsType(OclAny) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋›*) OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_OclAny (*‹?X .oclAsType(Person) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥⌋⌋ ⇒ invalid τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋ ⇒ ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋›*) foundation22 (*‹(?τ ⊨ ?X ≜ ?Y) = (?X ?τ = ?Y ?τ)›*) foundation16 (*‹(?τ ⊨ δ ?X) = (?X ?τ ≠ ⊥ ∧ ?X ?τ ≠ null)›*) split: option.split (*‹?P (case ?option of ⊥ ⇒ ?f1.0 | ⌊x⌋ ⇒ ?f2.0 x) = ((?option = ⊥ ⟶ ?P ?f1.0) ∧ (∀x2. ?option = ⌊x2⌋ ⟶ ?P (?f2.0 x2)))›*) type⇩O⇩c⇩l⇩A⇩n⇩y.split (*‹?P (case ?type⇩O⇩c⇩l⇩A⇩n⇩y of mk⇩O⇩c⇩l⇩A⇩n⇩y x xa ⇒ ?f x xa) = (∀x1 x2. ?type⇩O⇩c⇩l⇩A⇩n⇩y = mk⇩O⇩c⇩l⇩A⇩n⇩y x1 x2 ⟶ ?P (?f x1 x2))›*) type⇩P⇩e⇩r⇩s⇩o⇩n.split (*‹?P (case ?type⇩P⇩e⇩r⇩s⇩o⇩n of mk⇩P⇩e⇩r⇩s⇩o⇩n x xa xb ⇒ ?f x xa xb) = (∀x1 x2 x3. ?type⇩P⇩e⇩r⇩s⇩o⇩n = mk⇩P⇩e⇩r⇩s⇩o⇩n x1 x2 x3 ⟶ ?P (?f x1 x2 x3))›*)) (*goal: ‹τ ⊨ X .oclAsType(Person) ≜ invalid›*) by (simp add: OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny (*‹?X.oclIsKindOf(Person) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥⌋⌋ ⇒ false τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊x⌋⌋⌋ ⇒ true τ›*) OclValid_def (*‹?τ ⊨ ?P ≡ ?P ?τ = true ?τ›*) false_def (*‹false ≡ λτ. ⌊⌊False⌋⌋›*) true_def (*‹true ≡ λτ. ⌊⌊True⌋⌋›*)) section‹OclAllInstances› text‹To denote OCL-types occurring in OCL expressions syntactically---as, for example, as ``argument'' of \inlineisar{oclAllInstances()}---we use the inverses of the injection functions into the object universes; we show that this is sufficient ``characterization.''› definition "Person ≡ OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄" definition "OclAny ≡ OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄" lemmas [simp] = Person_def OclAny_def lemma OclAllInstances_generic⇩O⇩c⇩l⇩A⇩n⇩y_exec: "OclAllInstances_generic pre_post OclAny = (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊ Some ` OclAny ` ran (heap (pre_post τ)) ⌋⌋)" proof (-) (*goal: ‹OclAllInstances_generic pre_post OclAny = (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` OclAny ` ran (heap (pre_post τ))⌋⌋)›*) let ?S1 = "λτ. OclAny ` ran (heap (pre_post τ))" let ?S2 = "λτ. ?S1 τ - {None}" have B: "⋀τ. ?S2 τ ⊆ ?S1 τ" by auto have C: "⋀τ. ?S1 τ ⊆ ?S2 τ" by (auto simp: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄_some (*‹OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 ?x ≠ ⊥›*)) show "?thesis" (*goal: ‹OclAllInstances_generic pre_post OclAny = (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` OclAny ` ran (heap (pre_post τ))⌋⌋)›*) apply (insert equalityI[OF B C] (*‹OclAny ` ran (heap (pre_post ?τ1)) - {⊥} = OclAny ` ran (heap (pre_post ?τ1))›*)) (*goal: ‹OclAllInstances_generic pre_post OclAny = (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` OclAny ` ran (heap (pre_post τ))⌋⌋)›*) by simp qed lemma OclAllInstances_at_post⇩O⇩c⇩l⇩A⇩n⇩y_exec: "OclAny .allInstances() = (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊ Some ` OclAny ` ran (heap (snd τ)) ⌋⌋)" unfolding OclAllInstances_at_post_def (*goal: ‹OclAllInstances_generic snd OclAny = (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` OclAny ` ran (heap (snd τ))⌋⌋)›*) by (rule OclAllInstances_generic⇩O⇩c⇩l⇩A⇩n⇩y_exec (*‹OclAllInstances_generic ?pre_post OclAny = (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` OclAny ` ran (heap (?pre_post τ))⌋⌋)›*)) lemma OclAllInstances_at_pre⇩O⇩c⇩l⇩A⇩n⇩y_exec: "OclAny .allInstances@pre() = (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊ Some ` OclAny ` ran (heap (fst τ)) ⌋⌋) " unfolding OclAllInstances_at_pre_def (*goal: ‹OclAllInstances_generic fst OclAny = (λτ::𝔄 state × 𝔄 state. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` OclAny ` ran (heap (fst τ))⌋⌋)›*) by (rule OclAllInstances_generic⇩O⇩c⇩l⇩A⇩n⇩y_exec (*‹OclAllInstances_generic (?pre_post::𝔄 state × 𝔄 state ⇒ 𝔄 state) OclAny = (λτ::𝔄 state × 𝔄 state. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` OclAny ` ran (heap (?pre_post τ))⌋⌋)›*)) subsection‹OclIsTypeOf› lemma OclAny_allInstances_generic_oclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y1: assumes [simp]: "⋀x. pre_post (x, x) = x" shows "∃τ. (τ ⊨ ((OclAllInstances_generic pre_post OclAny)->forAll⇩S⇩e⇩t(X|X .oclIsTypeOf(OclAny))))" apply (rule_tac x = τ₀ in exI (*‹?P ?x ⟹ ∃x. ?P x›*)) (*goal: ‹∃τ. τ ⊨ UML_Set.OclForall (OclAllInstances_generic pre_post OclAny) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y›*) apply (simp add: τ₀_def (*‹τ₀ ≡ (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈)›*) OclValid_def (*‹?τ::?'𝔄 state × ?'𝔄 state ⊨ ?P::?'𝔄 state × ?'𝔄 state ⇒ ⟨⟨bool⟩⇩⊥⟩⇩⊥ ≡ ?P ?τ = true ?τ›*) del: OclAllInstances_generic_def (*‹OclAllInstances_generic (?fst_snd::?'𝔄 state × ?'𝔄 state ⇒ ?'𝔄 state) (?H::?'𝔄 ⇒ ⟨?'α⟩⇩⊥) = (λτ::?'𝔄 state × ?'𝔄 state. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` (?H ` ran (heap (?fst_snd τ)) - {⊥})⌋⌋)›*)) (*goal: ‹τ₀ ⊨ UML_Set.OclForall (OclAllInstances_generic pre_post OclAny) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y›*) apply (simp only: assms (*‹pre_post (?x, ?x) = ?x›*) UML_Set.OclForall_def (*‹UML_Set.OclForall ?S ?P = (λτ. if (δ ?S) τ = true τ then if ∃x∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S τ)⌉⌉. ?P (λ_. x) τ = false τ then false τ else if ∃x∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S τ)⌉⌉. ?P (λ_. x) τ = invalid τ then invalid τ else if ∃x∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S τ)⌉⌉. ?P (λ_. x) τ = null τ then null τ else true τ else ⊥)›*) refl (*‹?t = ?t›*) if_True (*‹(if True then ?x else ?y) = ?x›*) OclAllInstances_generic_defined[simplified OclValid_def] (*‹(δ OclAllInstances_generic ?pre_post ?H) ?τ = true ?τ›*)) (*goal: ‹UML_Set.OclForall (OclAllInstances_generic pre_post OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y (⦇heap = λx. ⊥, assocs = λx. ⊥⦈, ⦇heap = λx. ⊥, assocs = λx. ⊥⦈) = ⌊⌊True⌋⌋›*) apply (simp only: OclAllInstances_generic_def (*‹OclAllInstances_generic ?fst_snd ?H = (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` (?H ` ran (heap (?fst_snd τ)) - {⊥})⌋⌋)›*)) (*goal: ‹(if ∃x::⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (OclAllInstances_generic (pre_post::𝔄 state × 𝔄 state ⇒ 𝔄 state) OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈))⌉⌉. λ_::𝔄 state × 𝔄 state. x.oclIsTypeOf(OclAny) (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈) = false (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈) then false (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈) else if ∃x::⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (OclAllInstances_generic pre_post OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈))⌉⌉. λ_::𝔄 state × 𝔄 state. x.oclIsTypeOf(OclAny) (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈) = invalid (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈) then invalid (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈) else if ∃x::⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (OclAllInstances_generic pre_post OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈))⌉⌉. λ_::𝔄 state × 𝔄 state. x.oclIsTypeOf(OclAny) (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈) = null (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈) then null (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈) else true (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈)) = ⌊⌊True⌋⌋›*) apply (subst (1 2 3) Abs_Set⇩b⇩a⇩s⇩e_inverse (*‹?y ∈ {X. X = ⊥ ∨ X = null ∨ (∀x∈⌈⌈X⌉⌉. x ≠ ⊥)} ⟹ Rep_Set⇩b⇩a⇩s⇩e (Abs_Set⇩b⇩a⇩s⇩e ?y) = ?y›*)) (*goals: 1. ‹⌊⌊Some ` (OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 ` ran (heap ((pre_post::𝔄 state × 𝔄 state ⇒ 𝔄 state) (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈))) - {⊥})⌋⌋ ∈ {X::⟨⟨⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥ set⟩⇩⊥⟩⇩⊥. X = ⊥ ∨ X = null ∨ (∀x::⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥∈⌈⌈X⌉⌉. x ≠ ⊥)}› 2. ‹(if ∃x::⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥∈⌈⌈⌊⌊Some ` (OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 ` ran (heap ((pre_post::𝔄 state × 𝔄 state ⇒ 𝔄 state) (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈))) - {⊥})⌋⌋⌉⌉. λ_::𝔄 state × 𝔄 state. x.oclIsTypeOf(OclAny) (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈) = false (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈) then false (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈) else if ∃x::⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥∈⌈⌈⌊⌊Some ` (OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 ` ran (heap (pre_post (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈))) - {⊥})⌋⌋⌉⌉. λ_::𝔄 state × 𝔄 state. x.oclIsTypeOf(OclAny) (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈) = invalid (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈) then invalid (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈) else if ∃x::⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥∈⌈⌈⌊⌊Some ` (OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 ` ran (heap (pre_post (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈))) - {⊥})⌋⌋⌉⌉. λ_::𝔄 state × 𝔄 state. x.oclIsTypeOf(OclAny) (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈) = null (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈) then null (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈) else true (⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈, ⦇heap = λx::nat. ⊥, assocs = λx::nat. ⊥⦈)) = ⌊⌊True⌋⌋› discuss goal 1*) apply (simp add: bot_option_def (*‹⊥ ≡ ⊥›*)) (*discuss goal 2*) apply (simp add: OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny (*‹?X.oclIsTypeOf(OclAny) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥⌋⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊x⌋⌋⌋ ⇒ false τ›*)) (*proven 2 subgoals*) . lemma OclAny_allInstances_at_post_oclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y1: "∃τ. (τ ⊨ (OclAny .allInstances()->forAll⇩S⇩e⇩t(X|X .oclIsTypeOf(OclAny))))" unfolding OclAllInstances_at_post_def (*goal: ‹∃τ::𝔄 state × 𝔄 state. τ ⊨ UML_Set.OclForall (OclAllInstances_generic snd OclAny) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y›*) apply (rule OclAny_allInstances_generic_oclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y1 (*‹(⋀x::𝔄 state. (?pre_post::𝔄 state × 𝔄 state ⇒ 𝔄 state) (x, x) = x) ⟹ ∃τ::𝔄 state × 𝔄 state. τ ⊨ UML_Set.OclForall (OclAllInstances_generic ?pre_post OclAny) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y›*)) (*goal: ‹∃τ. τ ⊨ UML_Set.OclForall (OclAllInstances_generic snd OclAny) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y›*) by simp lemma OclAny_allInstances_at_pre_oclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y1: "∃τ. (τ ⊨ (OclAny .allInstances@pre()->forAll⇩S⇩e⇩t(X|X .oclIsTypeOf(OclAny))))" unfolding OclAllInstances_at_pre_def (*goal: ‹∃τ. τ ⊨ UML_Set.OclForall (OclAllInstances_generic fst OclAny) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y›*) apply (rule OclAny_allInstances_generic_oclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y1 (*‹(⋀x::𝔄 state. (?pre_post::𝔄 state × 𝔄 state ⇒ 𝔄 state) (x, x) = x) ⟹ ∃τ::𝔄 state × 𝔄 state. τ ⊨ UML_Set.OclForall (OclAllInstances_generic ?pre_post OclAny) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y›*)) (*goal: ‹∃τ. τ ⊨ UML_Set.OclForall (OclAllInstances_generic fst OclAny) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y›*) by simp lemma OclAny_allInstances_generic_oclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y2: assumes [simp]: "⋀x. pre_post (x, x) = x" shows "∃τ. (τ ⊨ not ((OclAllInstances_generic pre_post OclAny)->forAll⇩S⇩e⇩t(X|X .oclIsTypeOf(OclAny))))" proof (-) (*goal: ‹∃τ. τ ⊨ not (UML_Set.OclForall (OclAllInstances_generic pre_post OclAny) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y)›*) fix oid and a let ?t0 = "⦇heap = Map.empty(oid ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊a⌋)), assocs = Map.empty⦈" show "?thesis" (*goal: ‹∃τ. τ ⊨ not (UML_Set.OclForall (OclAllInstances_generic pre_post OclAny) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y)›*) apply (rule_tac x = "(?t0, ?t0)" in exI (*‹(?P::?'a ⇒ bool) (?x::?'a) ⟹ ∃x::?'a. ?P x›*)) (*goal: ‹∃τ. τ ⊨ not (UML_Set.OclForall (OclAllInstances_generic pre_post OclAny) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y)›*) apply (simp add: OclValid_def (*‹?τ::?'𝔄 state × ?'𝔄 state ⊨ ?P::?'𝔄 state × ?'𝔄 state ⇒ ⟨⟨bool⟩⇩⊥⟩⇩⊥ ≡ ?P ?τ = true ?τ›*) del: OclAllInstances_generic_def (*‹OclAllInstances_generic (?fst_snd::?'𝔄 state × ?'𝔄 state ⇒ ?'𝔄 state) (?H::?'𝔄 ⇒ ⟨?'α⟩⇩⊥) = (λτ::?'𝔄 state × ?'𝔄 state. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` (?H ` ran (heap (?fst_snd τ)) - {⊥})⌋⌋)›*)) (*goal: ‹(⦇heap = [oid ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊a⌋)], assocs = λx. ⊥⦈, ⦇heap = [oid ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊a⌋)], assocs = λx. ⊥⦈) ⊨ not (UML_Set.OclForall (OclAllInstances_generic pre_post OclAny) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y)›*) apply (simp only: UML_Set.OclForall_def (*‹UML_Set.OclForall (?S::?'𝔄 state × ?'𝔄 state ⇒ Set(?'α)) (?P::(?'𝔄 state × ?'𝔄 state ⇒ ?'α) ⇒ ?'𝔄 state × ?'𝔄 state ⇒ ⟨⟨bool⟩⇩⊥⟩⇩⊥) = (λτ::?'𝔄 state × ?'𝔄 state. if (δ ?S) τ = true τ then if ∃x::?'α∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S τ)⌉⌉. ?P (λ_::?'𝔄 state × ?'𝔄 state. x) τ = false τ then false τ else if ∃x::?'α∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S τ)⌉⌉. ?P (λ_::?'𝔄 state × ?'𝔄 state. x) τ = invalid τ then invalid τ else if ∃x::?'α∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S τ)⌉⌉. ?P (λ_::?'𝔄 state × ?'𝔄 state. x) τ = null τ then null τ else true τ else ⊥)›*) refl (*‹(?t::?'a) = ?t›*) if_True (*‹(if True then ?x::?'a else (?y::?'a)) = ?x›*) OclAllInstances_generic_defined[simplified OclValid_def] (*‹(δ OclAllInstances_generic (?pre_post::?'a state × ?'a state ⇒ ?'a state) (?H::?'a ⇒ ⟨?'b⟩⇩⊥)) (?τ::?'a state × ?'a state) = true ?τ›*)) (*goal: ‹not (UML_Set.OclForall (OclAllInstances_generic pre_post OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y) (⦇heap = [oid ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊a⌋)], assocs = λx. ⊥⦈, ⦇heap = [oid ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊a⌋)], assocs = λx. ⊥⦈) = ⌊⌊True⌋⌋›*) apply (simp only: OclAllInstances_generic_def (*‹OclAllInstances_generic ?fst_snd ?H = (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` (?H ` ran (heap (?fst_snd τ)) - {⊥})⌋⌋)›*) OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄_def (*‹OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 = (λu. ⌊case u of in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b) ⇒ mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y a ⇒ a⌋)›*)) (*goal: ‹not (λτ::𝔄 state × 𝔄 state. if ∃x::⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (OclAllInstances_generic (pre_post::𝔄 state × 𝔄 state ⇒ 𝔄 state) OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 τ)⌉⌉. λ_::𝔄 state × 𝔄 state. x.oclIsTypeOf(OclAny) τ = false τ then false τ else if ∃x::⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (OclAllInstances_generic pre_post OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 τ)⌉⌉. λ_::𝔄 state × 𝔄 state. x.oclIsTypeOf(OclAny) τ = invalid τ then invalid τ else if ∃x::⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (OclAllInstances_generic pre_post OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 τ)⌉⌉. λ_::𝔄 state × 𝔄 state. x.oclIsTypeOf(OclAny) τ = null τ then null τ else true τ) (⦇heap = [oid::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊a::⟨int⟩⇩⊥ × ⟨nat⟩⇩⊥⌋)], assocs = λx::nat. ⊥⦈, ⦇heap = [oid ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊a⌋)], assocs = λx::nat. ⊥⦈) = ⌊⌊True⌋⌋›*) apply (subst (1 2 3) Abs_Set⇩b⇩a⇩s⇩e_inverse (*‹?y ∈ {X. X = ⊥ ∨ X = null ∨ (∀x∈⌈⌈X⌉⌉. x ≠ ⊥)} ⟹ Rep_Set⇩b⇩a⇩s⇩e (Abs_Set⇩b⇩a⇩s⇩e ?y) = ?y›*)) (*goals: 1. ‹⋀τ. ⌊⌊Some ` ((λu. ⌊case u of in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b) ⇒ mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y a ⇒ a⌋) ` ran (heap (pre_post τ)) - {⊥})⌋⌋ ∈ {X. X = ⊥ ∨ X = null ∨ (∀x∈⌈⌈X⌉⌉. x ≠ ⊥)}› 2. ‹not (λτ. if ∃x∈⌈⌈⌊⌊Some ` ((λu. ⌊case u of in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b) ⇒ mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y a ⇒ a⌋) ` ran (heap (pre_post τ)) - {⊥})⌋⌋⌉⌉. λ_. x.oclIsTypeOf(OclAny) τ = false τ then false τ else if ∃x∈⌈⌈⌊⌊Some ` ((λu. ⌊case u of in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b) ⇒ mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y a ⇒ a⌋) ` ran (heap (pre_post τ)) - {⊥})⌋⌋⌉⌉. λ_. x.oclIsTypeOf(OclAny) τ = invalid τ then invalid τ else if ∃x∈⌈⌈⌊⌊Some ` ((λu. ⌊case u of in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b) ⇒ mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y a ⇒ a⌋) ` ran (heap (pre_post τ)) - {⊥})⌋⌋⌉⌉. λ_. x.oclIsTypeOf(OclAny) τ = null τ then null τ else true τ) (⦇heap = [oid ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊a⌋)], assocs = λx. ⊥⦈, ⦇heap = [oid ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊a⌋)], assocs = λx. ⊥⦈) = ⌊⌊True⌋⌋› discuss goal 1*) apply (simp add: bot_option_def (*‹⊥ ≡ ⊥›*)) (*discuss goal 2*) apply (simp add: OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny (*‹?X.oclIsTypeOf(OclAny) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥⌋⌋ ⇒ true τ | ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊x⌋⌋⌋ ⇒ false τ›*) OclNot_def (*‹not ?X ≡ λτ. case ?X τ of ⊥ ⇒ ⊥ | ⌊⊥⌋ ⇒ ⌊⊥⌋ | ⌊⌊x⌋⌋ ⇒ ⌊⌊¬ x⌋⌋›*) OclAny_def (*‹OclAny ≡ OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄›*)) (*proven 2 subgoals*) . qed lemma OclAny_allInstances_at_post_oclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y2: "∃τ. (τ ⊨ not (OclAny .allInstances()->forAll⇩S⇩e⇩t(X|X .oclIsTypeOf(OclAny))))" unfolding OclAllInstances_at_post_def (*goal: ‹∃τ. τ ⊨ not (UML_Set.OclForall (OclAllInstances_generic snd OclAny) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y)›*) apply (rule OclAny_allInstances_generic_oclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y2 (*‹(⋀x::𝔄 state. (?pre_post::𝔄 state × 𝔄 state ⇒ 𝔄 state) (x, x) = x) ⟹ ∃τ::𝔄 state × 𝔄 state. τ ⊨ not (UML_Set.OclForall (OclAllInstances_generic ?pre_post OclAny) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y)›*)) (*goal: ‹∃τ. τ ⊨ not (UML_Set.OclForall (OclAllInstances_generic snd OclAny) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y)›*) by simp lemma OclAny_allInstances_at_pre_oclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y2: "∃τ. (τ ⊨ not (OclAny .allInstances@pre()->forAll⇩S⇩e⇩t(X|X .oclIsTypeOf(OclAny))))" unfolding OclAllInstances_at_pre_def (*goal: ‹∃τ::𝔄 state × 𝔄 state. τ ⊨ not (UML_Set.OclForall (OclAllInstances_generic fst OclAny) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y)›*) apply (rule OclAny_allInstances_generic_oclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y2 (*‹(⋀x. ?pre_post (x, x) = x) ⟹ ∃τ. τ ⊨ not (UML_Set.OclForall (OclAllInstances_generic ?pre_post OclAny) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y)›*)) (*goal: ‹∃τ::𝔄 state × 𝔄 state. τ ⊨ not (UML_Set.OclForall (OclAllInstances_generic fst OclAny) OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y)›*) by simp lemma Person_allInstances_generic_oclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n: "τ ⊨ ((OclAllInstances_generic pre_post Person)->forAll⇩S⇩e⇩t(X|X .oclIsTypeOf(Person)))" apply (simp add: OclValid_def (*‹?τ ⊨ ?P ≡ ?P ?τ = true ?τ›*) del: OclAllInstances_generic_def (*‹OclAllInstances_generic ?fst_snd ?H = (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` (?H ` ran (heap (?fst_snd τ)) - {⊥})⌋⌋)›*)) (*goal: ‹τ ⊨ UML_Set.OclForall (OclAllInstances_generic pre_post Person) OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n›*) apply (simp only: UML_Set.OclForall_def (*‹UML_Set.OclForall (?S::?'𝔄 state × ?'𝔄 state ⇒ Set(?'α::null)) (?P::(?'𝔄 state × ?'𝔄 state ⇒ ?'α::null) ⇒ ?'𝔄 state × ?'𝔄 state ⇒ ⟨⟨bool⟩⇩⊥⟩⇩⊥) = (λτ::?'𝔄 state × ?'𝔄 state. if (δ ?S) τ = true τ then if ∃x::?'α::null∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S τ)⌉⌉. ?P (λ_::?'𝔄 state × ?'𝔄 state. x) τ = false τ then false τ else if ∃x::?'α::null∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S τ)⌉⌉. ?P (λ_::?'𝔄 state × ?'𝔄 state. x) τ = invalid τ then invalid τ else if ∃x::?'α::null∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S τ)⌉⌉. ?P (λ_::?'𝔄 state × ?'𝔄 state. x) τ = null τ then null τ else true τ else ⊥)›*) refl (*‹(?t::?'a::type) = ?t›*) if_True (*‹(if True then ?x::?'a::type else (?y::?'a::type)) = ?x›*) OclAllInstances_generic_defined[simplified OclValid_def] (*‹(δ OclAllInstances_generic (?pre_post::?'a state × ?'a state ⇒ ?'a state) (?H::?'a::object ⇒ ⟨?'b::type⟩⇩⊥)) (?τ::?'a state × ?'a state) = true ?τ›*)) (*goal: ‹UML_Set.OclForall (OclAllInstances_generic pre_post OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄) OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n τ = true τ›*) apply (simp only: OclAllInstances_generic_def (*‹OclAllInstances_generic ?fst_snd ?H = (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` (?H ` ran (heap (?fst_snd τ)) - {⊥})⌋⌋)›*)) (*goal: ‹(if ∃x∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (OclAllInstances_generic pre_post OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 τ)⌉⌉. λ_. x.oclIsTypeOf(Person) τ = false τ then false τ else if ∃x∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (OclAllInstances_generic pre_post OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 τ)⌉⌉. λ_. x.oclIsTypeOf(Person) τ = invalid τ then invalid τ else if ∃x∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (OclAllInstances_generic pre_post OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 τ)⌉⌉. λ_. x.oclIsTypeOf(Person) τ = null τ then null τ else true τ) = true τ›*) apply (subst (1 2 3) Abs_Set⇩b⇩a⇩s⇩e_inverse (*‹?y ∈ {X. X = ⊥ ∨ X = null ∨ (∀x∈⌈⌈X⌉⌉. x ≠ ⊥)} ⟹ Rep_Set⇩b⇩a⇩s⇩e (Abs_Set⇩b⇩a⇩s⇩e ?y) = ?y›*)) (*goals: 1. ‹⌊⌊Some ` (OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 ` ran (heap (pre_post τ)) - {⊥})⌋⌋ ∈ {X. X = ⊥ ∨ X = null ∨ (∀x∈⌈⌈X⌉⌉. x ≠ ⊥)}› 2. ‹(if ∃x∈⌈⌈⌊⌊Some ` (OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 ` ran (heap (pre_post τ)) - {⊥})⌋⌋⌉⌉. λ_. x.oclIsTypeOf(Person) τ = false τ then false τ else if ∃x∈⌈⌈⌊⌊Some ` (OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 ` ran (heap (pre_post τ)) - {⊥})⌋⌋⌉⌉. λ_. x.oclIsTypeOf(Person) τ = invalid τ then invalid τ else if ∃x∈⌈⌈⌊⌊Some ` (OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 ` ran (heap (pre_post τ)) - {⊥})⌋⌋⌉⌉. λ_. x.oclIsTypeOf(Person) τ = null τ then null τ else true τ) = true τ› discuss goal 1*) apply (simp add: bot_option_def (*‹⊥ ≡ ⊥›*)) (*discuss goal 2*) apply (simp add: OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_Person (*‹?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.oclIsTypeOf(Person) ≡ λτ::𝔄 state × 𝔄 state. case ?X τ of ⊥ ⇒ invalid τ | ⌊a::⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⌋ ⇒ true τ›*)) (*proven 2 subgoals*) . lemma Person_allInstances_at_post_oclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n: "τ ⊨ (Person .allInstances()->forAll⇩S⇩e⇩t(X|X .oclIsTypeOf(Person)))" unfolding OclAllInstances_at_post_def (*goal: ‹τ ⊨ UML_Set.OclForall (OclAllInstances_generic snd Person) OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n›*) by (rule Person_allInstances_generic_oclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n (*‹?τ ⊨ UML_Set.OclForall (OclAllInstances_generic ?pre_post Person) OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n›*)) lemma Person_allInstances_at_pre_oclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n: "τ ⊨ (Person .allInstances@pre()->forAll⇩S⇩e⇩t(X|X .oclIsTypeOf(Person)))" unfolding OclAllInstances_at_pre_def (*goal: ‹τ ⊨ UML_Set.OclForall (OclAllInstances_generic fst Person) OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n›*) by (rule Person_allInstances_generic_oclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n (*‹?τ ⊨ UML_Set.OclForall (OclAllInstances_generic ?pre_post Person) OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n›*)) subsection‹OclIsKindOf› lemma OclAny_allInstances_generic_oclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y: "τ ⊨ ((OclAllInstances_generic pre_post OclAny)->forAll⇩S⇩e⇩t(X|X .oclIsKindOf(OclAny)))" apply (simp add: OclValid_def (*‹?τ ⊨ ?P ≡ ?P ?τ = true ?τ›*) del: OclAllInstances_generic_def (*‹OclAllInstances_generic ?fst_snd ?H = (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` (?H ` ran (heap (?fst_snd τ)) - {⊥})⌋⌋)›*)) (*goal: ‹τ::𝔄 state × 𝔄 state ⊨ UML_Set.OclForall (OclAllInstances_generic (pre_post::𝔄 state × 𝔄 state ⇒ 𝔄 state) OclAny) OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y›*) apply (simp only: UML_Set.OclForall_def (*‹UML_Set.OclForall ?S ?P = (λτ. if (δ ?S) τ = true τ then if ∃x∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S τ)⌉⌉. ?P (λ_. x) τ = false τ then false τ else if ∃x∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S τ)⌉⌉. ?P (λ_. x) τ = invalid τ then invalid τ else if ∃x∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S τ)⌉⌉. ?P (λ_. x) τ = null τ then null τ else true τ else ⊥)›*) refl (*‹?t = ?t›*) if_True (*‹(if True then ?x else ?y) = ?x›*) OclAllInstances_generic_defined[simplified OclValid_def] (*‹(δ OclAllInstances_generic ?pre_post ?H) ?τ = true ?τ›*)) (*goal: ‹UML_Set.OclForall (OclAllInstances_generic pre_post OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄) OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y τ = true τ›*) apply (simp only: OclAllInstances_generic_def (*‹OclAllInstances_generic ?fst_snd ?H = (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` (?H ` ran (heap (?fst_snd τ)) - {⊥})⌋⌋)›*)) (*goal: ‹(if ∃x∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (OclAllInstances_generic pre_post OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 τ)⌉⌉. λ_. x.oclIsKindOf(OclAny) τ = false τ then false τ else if ∃x∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (OclAllInstances_generic pre_post OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 τ)⌉⌉. λ_. x.oclIsKindOf(OclAny) τ = invalid τ then invalid τ else if ∃x∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (OclAllInstances_generic pre_post OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 τ)⌉⌉. λ_. x.oclIsKindOf(OclAny) τ = null τ then null τ else true τ) = true τ›*) apply (subst (1 2 3) Abs_Set⇩b⇩a⇩s⇩e_inverse (*‹(?y::⟨⟨?'α set⟩⇩⊥⟩⇩⊥) ∈ {X::⟨⟨?'α set⟩⇩⊥⟩⇩⊥. X = ⊥ ∨ X = null ∨ (∀x::?'α∈⌈⌈X⌉⌉. x ≠ ⊥)} ⟹ Rep_Set⇩b⇩a⇩s⇩e (Abs_Set⇩b⇩a⇩s⇩e ?y) = ?y›*)) (*goals: 1. ‹⌊⌊Some ` (OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 ` ran (heap (pre_post τ)) - {⊥})⌋⌋ ∈ {X. X = ⊥ ∨ X = null ∨ (∀x∈⌈⌈X⌉⌉. x ≠ ⊥)}› 2. ‹(if ∃x∈⌈⌈⌊⌊Some ` (OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 ` ran (heap (pre_post τ)) - {⊥})⌋⌋⌉⌉. λ_. x.oclIsKindOf(OclAny) τ = false τ then false τ else if ∃x∈⌈⌈⌊⌊Some ` (OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 ` ran (heap (pre_post τ)) - {⊥})⌋⌋⌉⌉. λ_. x.oclIsKindOf(OclAny) τ = invalid τ then invalid τ else if ∃x∈⌈⌈⌊⌊Some ` (OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 ` ran (heap (pre_post τ)) - {⊥})⌋⌋⌉⌉. λ_. x.oclIsKindOf(OclAny) τ = null τ then null τ else true τ) = true τ› discuss goal 1*) apply (simp add: bot_option_def (*‹⊥ ≡ ⊥›*)) (*discuss goal 2*) apply (simp add: OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny (*‹?X.oclIsKindOf(OclAny) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊a⌋ ⇒ true τ›*)) (*proven 2 subgoals*) . lemma OclAny_allInstances_at_post_oclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y: "τ ⊨ (OclAny .allInstances()->forAll⇩S⇩e⇩t(X|X .oclIsKindOf(OclAny)))" unfolding OclAllInstances_at_post_def (*goal: ‹τ ⊨ UML_Set.OclForall (OclAllInstances_generic snd OclAny) OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y›*) by (rule OclAny_allInstances_generic_oclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y (*‹?τ ⊨ UML_Set.OclForall (OclAllInstances_generic ?pre_post OclAny) OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y›*)) lemma OclAny_allInstances_at_pre_oclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y: "τ ⊨ (OclAny .allInstances@pre()->forAll⇩S⇩e⇩t(X|X .oclIsKindOf(OclAny)))" unfolding OclAllInstances_at_pre_def (*goal: ‹τ ⊨ UML_Set.OclForall (OclAllInstances_generic fst OclAny) OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y›*) by (rule OclAny_allInstances_generic_oclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y (*‹?τ ⊨ UML_Set.OclForall (OclAllInstances_generic ?pre_post OclAny) OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y›*)) lemma Person_allInstances_generic_oclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y: "τ ⊨ ((OclAllInstances_generic pre_post Person)->forAll⇩S⇩e⇩t(X|X .oclIsKindOf(OclAny)))" apply (simp add: OclValid_def (*‹?τ ⊨ ?P ≡ ?P ?τ = true ?τ›*) del: OclAllInstances_generic_def (*‹OclAllInstances_generic ?fst_snd ?H = (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` (?H ` ran (heap (?fst_snd τ)) - {⊥})⌋⌋)›*)) (*goal: ‹τ ⊨ UML_Set.OclForall (OclAllInstances_generic pre_post Person) OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y›*) apply (simp only: UML_Set.OclForall_def (*‹UML_Set.OclForall ?S ?P = (λτ. if (δ ?S) τ = true τ then if ∃x∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S τ)⌉⌉. ?P (λ_. x) τ = false τ then false τ else if ∃x∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S τ)⌉⌉. ?P (λ_. x) τ = invalid τ then invalid τ else if ∃x∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S τ)⌉⌉. ?P (λ_. x) τ = null τ then null τ else true τ else ⊥)›*) refl (*‹?t = ?t›*) if_True (*‹(if True then ?x else ?y) = ?x›*) OclAllInstances_generic_defined[simplified OclValid_def] (*‹(δ OclAllInstances_generic ?pre_post ?H) ?τ = true ?τ›*)) (*goal: ‹UML_Set.OclForall (OclAllInstances_generic pre_post OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄) OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y τ = true τ›*) apply (simp only: OclAllInstances_generic_def (*‹OclAllInstances_generic (?fst_snd::?'𝔄 state × ?'𝔄 state ⇒ ?'𝔄 state) (?H::?'𝔄 ⇒ ⟨?'α⟩⇩⊥) = (λτ::?'𝔄 state × ?'𝔄 state. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` (?H ` ran (heap (?fst_snd τ)) - {⊥})⌋⌋)›*)) (*goal: ‹(if ∃x::⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (OclAllInstances_generic (pre_post::𝔄 state × 𝔄 state ⇒ 𝔄 state) OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 (τ::𝔄 state × 𝔄 state))⌉⌉. λ_::𝔄 state × 𝔄 state. x.oclIsKindOf(OclAny) τ = false τ then false τ else if ∃x::⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (OclAllInstances_generic pre_post OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 τ)⌉⌉. λ_::𝔄 state × 𝔄 state. x.oclIsKindOf(OclAny) τ = invalid τ then invalid τ else if ∃x::⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (OclAllInstances_generic pre_post OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 τ)⌉⌉. λ_::𝔄 state × 𝔄 state. x.oclIsKindOf(OclAny) τ = null τ then null τ else true τ) = true τ›*) apply (subst (1 2 3) Abs_Set⇩b⇩a⇩s⇩e_inverse (*‹(?y::⟨⟨?'α set⟩⇩⊥⟩⇩⊥) ∈ {X::⟨⟨?'α set⟩⇩⊥⟩⇩⊥. X = ⊥ ∨ X = null ∨ (∀x::?'α∈⌈⌈X⌉⌉. x ≠ ⊥)} ⟹ Rep_Set⇩b⇩a⇩s⇩e (Abs_Set⇩b⇩a⇩s⇩e ?y) = ?y›*)) (*goals: 1. ‹⌊⌊Some ` (OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 ` ran (heap ((pre_post::𝔄 state × 𝔄 state ⇒ 𝔄 state) (τ::𝔄 state × 𝔄 state))) - {⊥})⌋⌋ ∈ {X::⟨⟨⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥ set⟩⇩⊥⟩⇩⊥. X = ⊥ ∨ X = null ∨ (∀x::⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥∈⌈⌈X⌉⌉. x ≠ ⊥)}› 2. ‹(if ∃x::⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥∈⌈⌈⌊⌊Some ` (OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 ` ran (heap ((pre_post::𝔄 state × 𝔄 state ⇒ 𝔄 state) (τ::𝔄 state × 𝔄 state))) - {⊥})⌋⌋⌉⌉. λ_::𝔄 state × 𝔄 state. x.oclIsKindOf(OclAny) τ = false τ then false τ else if ∃x::⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥∈⌈⌈⌊⌊Some ` (OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 ` ran (heap (pre_post τ)) - {⊥})⌋⌋⌉⌉. λ_::𝔄 state × 𝔄 state. x.oclIsKindOf(OclAny) τ = invalid τ then invalid τ else if ∃x::⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥∈⌈⌈⌊⌊Some ` (OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 ` ran (heap (pre_post τ)) - {⊥})⌋⌋⌉⌉. λ_::𝔄 state × 𝔄 state. x.oclIsKindOf(OclAny) τ = null τ then null τ else true τ) = true τ› discuss goal 1*) apply (simp add: bot_option_def (*‹⊥ ≡ ⊥›*)) (*discuss goal 2*) apply (simp add: OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_Person (*‹?X.oclIsKindOf(OclAny) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊a⌋ ⇒ true τ›*)) (*proven 2 subgoals*) . lemma Person_allInstances_at_post_oclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y: "τ ⊨ (Person .allInstances()->forAll⇩S⇩e⇩t(X|X .oclIsKindOf(OclAny)))" unfolding OclAllInstances_at_post_def (*goal: ‹τ ⊨ UML_Set.OclForall (OclAllInstances_generic snd Person) OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y›*) by (rule Person_allInstances_generic_oclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y (*‹?τ ⊨ UML_Set.OclForall (OclAllInstances_generic ?pre_post Person) OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y›*)) lemma Person_allInstances_at_pre_oclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y: "τ ⊨ (Person .allInstances@pre()->forAll⇩S⇩e⇩t(X|X .oclIsKindOf(OclAny)))" unfolding OclAllInstances_at_pre_def (*goal: ‹τ::𝔄 state × 𝔄 state ⊨ UML_Set.OclForall (OclAllInstances_generic fst Person) OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y›*) by (rule Person_allInstances_generic_oclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y (*‹?τ ⊨ UML_Set.OclForall (OclAllInstances_generic ?pre_post Person) OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y›*)) lemma Person_allInstances_generic_oclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n: "τ ⊨ ((OclAllInstances_generic pre_post Person)->forAll⇩S⇩e⇩t(X|X .oclIsKindOf(Person)))" apply (simp add: OclValid_def (*‹?τ ⊨ ?P ≡ ?P ?τ = true ?τ›*) del: OclAllInstances_generic_def (*‹OclAllInstances_generic ?fst_snd ?H = (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` (?H ` ran (heap (?fst_snd τ)) - {⊥})⌋⌋)›*)) (*goal: ‹τ ⊨ UML_Set.OclForall (OclAllInstances_generic pre_post Person) OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n›*) apply (simp only: UML_Set.OclForall_def (*‹UML_Set.OclForall (?S::?'𝔄 state × ?'𝔄 state ⇒ Set(?'α)) (?P::(?'𝔄 state × ?'𝔄 state ⇒ ?'α) ⇒ ?'𝔄 state × ?'𝔄 state ⇒ ⟨⟨bool⟩⇩⊥⟩⇩⊥) = (λτ::?'𝔄 state × ?'𝔄 state. if (δ ?S) τ = true τ then if ∃x::?'α∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S τ)⌉⌉. ?P (λ_::?'𝔄 state × ?'𝔄 state. x) τ = false τ then false τ else if ∃x::?'α∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S τ)⌉⌉. ?P (λ_::?'𝔄 state × ?'𝔄 state. x) τ = invalid τ then invalid τ else if ∃x::?'α∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S τ)⌉⌉. ?P (λ_::?'𝔄 state × ?'𝔄 state. x) τ = null τ then null τ else true τ else ⊥)›*) refl (*‹(?t::?'a) = ?t›*) if_True (*‹(if True then ?x::?'a else (?y::?'a)) = ?x›*) OclAllInstances_generic_defined[simplified OclValid_def] (*‹(δ OclAllInstances_generic (?pre_post::?'a state × ?'a state ⇒ ?'a state) (?H::?'a ⇒ ⟨?'b⟩⇩⊥)) (?τ::?'a state × ?'a state) = true ?τ›*)) (*goal: ‹UML_Set.OclForall (OclAllInstances_generic (pre_post::𝔄 state × 𝔄 state ⇒ 𝔄 state) OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄) OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n (τ::𝔄 state × 𝔄 state) = true τ›*) apply (simp only: OclAllInstances_generic_def (*‹OclAllInstances_generic ?fst_snd ?H = (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` (?H ` ran (heap (?fst_snd τ)) - {⊥})⌋⌋)›*)) (*goal: ‹(if ∃x∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (OclAllInstances_generic pre_post OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 τ)⌉⌉. λ_. x.oclIsKindOf(Person) τ = false τ then false τ else if ∃x∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (OclAllInstances_generic pre_post OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 τ)⌉⌉. λ_. x.oclIsKindOf(Person) τ = invalid τ then invalid τ else if ∃x∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (OclAllInstances_generic pre_post OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 τ)⌉⌉. λ_. x.oclIsKindOf(Person) τ = null τ then null τ else true τ) = true τ›*) apply (subst (1 2 3) Abs_Set⇩b⇩a⇩s⇩e_inverse (*‹?y ∈ {X. X = ⊥ ∨ X = null ∨ (∀x∈⌈⌈X⌉⌉. x ≠ ⊥)} ⟹ Rep_Set⇩b⇩a⇩s⇩e (Abs_Set⇩b⇩a⇩s⇩e ?y) = ?y›*)) (*goals: 1. ‹⌊⌊Some ` (OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 ` ran (heap (pre_post τ)) - {⊥})⌋⌋ ∈ {X. X = ⊥ ∨ X = null ∨ (∀x∈⌈⌈X⌉⌉. x ≠ ⊥)}› 2. ‹(if ∃x∈⌈⌈⌊⌊Some ` (OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 ` ran (heap (pre_post τ)) - {⊥})⌋⌋⌉⌉. λ_. x.oclIsKindOf(Person) τ = false τ then false τ else if ∃x∈⌈⌈⌊⌊Some ` (OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 ` ran (heap (pre_post τ)) - {⊥})⌋⌋⌉⌉. λ_. x.oclIsKindOf(Person) τ = invalid τ then invalid τ else if ∃x∈⌈⌈⌊⌊Some ` (OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 ` ran (heap (pre_post τ)) - {⊥})⌋⌋⌉⌉. λ_. x.oclIsKindOf(Person) τ = null τ then null τ else true τ) = true τ› discuss goal 1*) apply (simp add: bot_option_def (*‹⊥ ≡ ⊥›*)) (*discuss goal 2*) apply (simp add: OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_Person (*‹?X.oclIsKindOf(Person) ≡ λτ. case ?X τ of ⊥ ⇒ invalid τ | ⌊a⌋ ⇒ true τ›*)) (*proven 2 subgoals*) . lemma Person_allInstances_at_post_oclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n: "τ ⊨ (Person .allInstances()->forAll⇩S⇩e⇩t(X|X .oclIsKindOf(Person)))" unfolding OclAllInstances_at_post_def (*goal: ‹τ ⊨ UML_Set.OclForall (OclAllInstances_generic snd Person) OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n›*) by (rule Person_allInstances_generic_oclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n (*‹?τ ⊨ UML_Set.OclForall (OclAllInstances_generic ?pre_post Person) OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n›*)) lemma Person_allInstances_at_pre_oclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n: "τ ⊨ (Person .allInstances@pre()->forAll⇩S⇩e⇩t(X|X .oclIsKindOf(Person)))" unfolding OclAllInstances_at_pre_def (*goal: ‹τ ⊨ UML_Set.OclForall (OclAllInstances_generic fst Person) OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n›*) by (rule Person_allInstances_generic_oclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n (*‹?τ ⊨ UML_Set.OclForall (OclAllInstances_generic ?pre_post Person) OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n›*)) section‹The Accessors (any, boss, salary)› text‹\label{sec:edm-accessors}› text‹Should be generated entirely from a class-diagram.› subsection‹Definition› definition eval_extract :: "('𝔄,('a::object) option option) val ⇒ (oid ⇒ ('𝔄,'c::null) val) ⇒ ('𝔄,'c::null) val" where "eval_extract X f = (λ τ. case X τ of ⊥ ⇒ invalid τ ― ‹exception propagation› | ⌊ ⊥ ⌋ ⇒ invalid τ ― ‹dereferencing null pointer› | ⌊⌊ obj ⌋⌋ ⇒ f (oid_of obj) τ)" definition deref_oid⇩P⇩e⇩r⇩s⇩o⇩n :: "(𝔄 state × 𝔄 state ⇒ 𝔄 state) ⇒ (type⇩P⇩e⇩r⇩s⇩o⇩n ⇒ (𝔄, 'c::null)val) ⇒ oid ⇒ (𝔄, 'c::null)val" where "deref_oid⇩P⇩e⇩r⇩s⇩o⇩n fst_snd f oid = (λτ. case (heap (fst_snd τ)) oid of ⌊ in⇩P⇩e⇩r⇩s⇩o⇩n obj ⌋ ⇒ f obj τ | _ ⇒ invalid τ)" definition deref_oid⇩O⇩c⇩l⇩A⇩n⇩y :: "(𝔄 state × 𝔄 state ⇒ 𝔄 state) ⇒ (type⇩O⇩c⇩l⇩A⇩n⇩y ⇒ (𝔄, 'c::null)val) ⇒ oid ⇒ (𝔄, 'c::null)val" where "deref_oid⇩O⇩c⇩l⇩A⇩n⇩y fst_snd f oid = (λτ. case (heap (fst_snd τ)) oid of ⌊ in⇩O⇩c⇩l⇩A⇩n⇩y obj ⌋ ⇒ f obj τ | _ ⇒ invalid τ)" text‹pointer undefined in state or not referencing a type conform object representation› definition "select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 f = (λ X. case X of (mk⇩O⇩c⇩l⇩A⇩n⇩y _ ⊥) ⇒ null | (mk⇩O⇩c⇩l⇩A⇩n⇩y _ ⌊any⌋) ⇒ f (λx _. ⌊⌊x⌋⌋) any)" definition "select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 f = (λ X. case X of (mk⇩P⇩e⇩r⇩s⇩o⇩n _ _ ⊥) ⇒ null ― ‹object contains null pointer› | (mk⇩P⇩e⇩r⇩s⇩o⇩n _ _ ⌊boss⌋) ⇒ f (λx _. ⌊⌊x⌋⌋) boss)" definition "select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 f = (λ X. case X of (mk⇩P⇩e⇩r⇩s⇩o⇩n _ ⊥ _) ⇒ null | (mk⇩P⇩e⇩r⇩s⇩o⇩n _ ⌊salary⌋ _) ⇒ f (λx _. ⌊⌊x⌋⌋) salary)" definition "in_pre_state = fst" definition "in_post_state = snd" definition "reconst_basetype = (λ convert x. convert x)" definition dot⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 :: "OclAny ⇒ _" ("(1(_).any)" 50) where "(X).any = eval_extract X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_post_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))" definition dot⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 :: "Person ⇒ Person" ("(1(_).boss)" 50) where "(X).boss = eval_extract X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state)))" definition dot⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 :: "Person ⇒ Integer" ("(1(_).salary)" 50) where "(X).salary = eval_extract X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))" definition dot⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴_at_pre :: "OclAny ⇒ _" ("(1(_).any@pre)" 50) where "(X).any@pre = eval_extract X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_pre_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))" definition dot⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮_at_pre:: "Person ⇒ Person" ("(1(_).boss@pre)" 50) where "(X).boss@pre = eval_extract X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state)))" definition dot⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴_at_pre:: "Person ⇒ Integer" ("(1(_).salary@pre)" 50) where "(X).salary@pre = eval_extract X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))" lemmas dot_accessor = dot⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴_def dot⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮_def dot⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴_def dot⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴_at_pre_def dot⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮_at_pre_def dot⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴_at_pre_def subsection‹Context Passing› lemmas [simp] = eval_extract_def lemma cp_dot⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴: "((X).any) τ = ((λ_. X τ).any) τ" by (simp add: dot_accessor (*‹(?X.any) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_post_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state)))› ‹(?X.salary) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))› ‹(?X.any@pre) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_pre_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state)))› ‹(?X.salary@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))›*)) lemma cp_dot⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮: "((X).boss) τ = ((λ_. X τ).boss) τ" by (simp add: dot_accessor (*‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥.any) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_post_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.boss) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state)))› ‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.salary) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))› ‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥.any@pre) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_pre_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.boss@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state)))› ‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.salary@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))›*)) lemma cp_dot⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴: "((X).salary) τ = ((λ_. X τ).salary) τ" by (simp add: dot_accessor (*‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥.any) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_post_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.boss) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state)))› ‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.salary) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))› ‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥.any@pre) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_pre_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.boss@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state)))› ‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.salary@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))›*)) lemma cp_dot⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴_at_pre: "((X).any@pre) τ = ((λ_. X τ).any@pre) τ" by (simp add: dot_accessor (*‹(?X.any) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_post_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state)))› ‹(?X.salary) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))› ‹(?X.any@pre) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_pre_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state)))› ‹(?X.salary@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))›*)) lemma cp_dot⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮_at_pre: "((X).boss@pre) τ = ((λ_. X τ).boss@pre) τ" by (simp add: dot_accessor (*‹(?X.any) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_post_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state)))› ‹(?X.salary) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))› ‹(?X.any@pre) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_pre_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state)))› ‹(?X.salary@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))›*)) lemma cp_dot⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴_at_pre: "((X).salary@pre) τ = ((λ_. X τ).salary@pre) τ" by (simp add: dot_accessor (*‹(?X.any) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_post_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state)))› ‹(?X.salary) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))› ‹(?X.any@pre) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_pre_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state)))› ‹(?X.salary@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))›*)) lemmas cp_dot⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴_I [simp, intro!]= cp_dot⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴[THEN allI[THEN allI], of "λ X _. X" "λ _ τ. τ", THEN cpI1] lemmas cp_dot⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴_at_pre_I [simp, intro!]= cp_dot⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴_at_pre[THEN allI[THEN allI], of "λ X _. X" "λ _ τ. τ", THEN cpI1] lemmas cp_dot⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮_I [simp, intro!]= cp_dot⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮[THEN allI[THEN allI], of "λ X _. X" "λ _ τ. τ", THEN cpI1] lemmas cp_dot⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮_at_pre_I [simp, intro!]= cp_dot⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮_at_pre[THEN allI[THEN allI], of "λ X _. X" "λ _ τ. τ", THEN cpI1] lemmas cp_dot⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴_I [simp, intro!]= cp_dot⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴[THEN allI[THEN allI], of "λ X _. X" "λ _ τ. τ", THEN cpI1] lemmas cp_dot⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴_at_pre_I [simp, intro!]= cp_dot⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴_at_pre[THEN allI[THEN allI], of "λ X _. X" "λ _ τ. τ", THEN cpI1] subsection‹Execution with Invalid or Null as Argument› lemma dot⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴_nullstrict [simp]: "(null).any = invalid" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹(null.any) = invalid›*) by (simp add: dot_accessor (*‹(?X.any) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_post_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state)))› ‹(?X.salary) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))› ‹(?X.any@pre) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_pre_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state)))› ‹(?X.salary@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))›*) null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null ?xs = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ. ⊥›*)) lemma dot⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴_at_pre_nullstrict [simp] : "(null).any@pre = invalid" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹(null.any@pre) = invalid›*) by (simp add: dot_accessor (*‹(?X.any) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_post_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state)))› ‹(?X.salary) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))› ‹(?X.any@pre) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_pre_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state)))› ‹(?X.salary@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))›*) null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null ?xs = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ. ⊥›*)) lemma dot⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴_strict [simp] : "(invalid).any = invalid" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹(invalid.any) = invalid›*) by (simp add: dot_accessor (*‹(?X.any) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_post_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state)))› ‹(?X.salary) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))› ‹(?X.any@pre) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_pre_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state)))› ‹(?X.salary@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))›*) null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null ?xs = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ. ⊥›*)) lemma dot⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴_at_pre_strict [simp] : "(invalid).any@pre = invalid" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹(invalid.any@pre) = invalid›*) by (simp add: dot_accessor (*‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥.any) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_post_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.boss) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state)))› ‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.salary) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))› ‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥.any@pre) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_pre_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.boss@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state)))› ‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.salary@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))›*) null_fun_def (*‹null ≡ λx::?'a. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null (?xs::?'a list) = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ::?'𝔄 state × ?'𝔄 state. ⊥›*)) lemma dot⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮_nullstrict [simp]: "(null).boss = invalid" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹(null.boss) = invalid›*) by (simp add: dot_accessor (*‹(?X.any) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_post_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state)))› ‹(?X.salary) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))› ‹(?X.any@pre) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_pre_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state)))› ‹(?X.salary@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))›*) null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null ?xs = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ. ⊥›*)) lemma dot⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮_at_pre_nullstrict [simp] : "(null).boss@pre = invalid" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹(null.boss@pre) = invalid›*) by (simp add: dot_accessor (*‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥.any) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_post_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.boss) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state)))› ‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.salary) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))› ‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥.any@pre) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_pre_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.boss@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state)))› ‹(?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.salary@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))›*) null_fun_def (*‹null ≡ λx::?'a. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null (?xs::?'a list) = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ::?'𝔄 state × ?'𝔄 state. ⊥›*)) lemma dot⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮_strict [simp] : "(invalid).boss = invalid" sorry lemma dot⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮_at_pre_strict [simp] : "(invalid).boss@pre = invalid" apply (rule ext (*‹(⋀x::?'a. (?f::?'a ⇒ ?'b) x = (?g::?'a ⇒ ?'b) x) ⟹ ?f = ?g›*)) (*goal: ‹(invalid.boss@pre) = invalid›*) by (simp add: dot_accessor (*‹(?X.any) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_post_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state)))› ‹(?X.salary) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))› ‹(?X.any@pre) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_pre_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state)))› ‹(?X.salary@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))›*) null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null ?xs = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ. ⊥›*)) lemma dot⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴_nullstrict [simp]: "(null).salary = invalid" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹(null.salary) = invalid›*) by (simp add: dot_accessor (*‹(?X.any) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_post_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state)))› ‹(?X.salary) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))› ‹(?X.any@pre) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_pre_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state)))› ‹(?X.salary@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))›*) null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null ?xs = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ. ⊥›*)) lemma dot⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴_at_pre_nullstrict [simp] : "(null).salary@pre = invalid" apply (rule ext (*‹(⋀x::?'a. (?f::?'a ⇒ ?'b) x = (?g::?'a ⇒ ?'b) x) ⟹ ?f = ?g›*)) (*goal: ‹(null.salary@pre) = invalid›*) by (simp add: dot_accessor (*‹(?X.any) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_post_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state)))› ‹(?X.salary) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))› ‹(?X.any@pre) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_pre_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state)))› ‹(?X.salary@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))›*) null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null ?xs = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ. ⊥›*)) lemma dot⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴_strict [simp] : "(invalid).salary = invalid" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹(invalid.salary) = invalid›*) by (simp add: dot_accessor (*‹(?X.any) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_post_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state)))› ‹(?X.salary) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_post_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))› ‹(?X.any@pre) = eval_extract ?X (deref_oid⇩O⇩c⇩l⇩A⇩n⇩y in_pre_state (select⇩O⇩c⇩l⇩A⇩n⇩y𝒜𝒩𝒴 reconst_basetype))› ‹(?X.boss@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮 (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state)))› ‹(?X.salary@pre) = eval_extract ?X (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n in_pre_state (select⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴 reconst_basetype))›*) null_fun_def (*‹null ≡ λx. null›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_def (*‹List.null ?xs = (?xs = [])›*) invalid_def (*‹invalid ≡ λτ. ⊥›*)) lemma dot⇩P⇩e⇩r⇩s⇩o⇩n𝒮𝒜ℒ𝒜ℛ𝒴_at_pre_strict [simp] : "(invalid).salary@pre = invalid" sorry subsection‹Representation in States› lemma dot⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮_def_mono:"τ ⊨ δ(X .boss) ⟹ τ ⊨ δ(X)" apply (case_tac "τ ⊨ (X ≜ invalid)") (*goals: 1. ‹⟦τ::𝔄 state × 𝔄 state ⊨ δ (X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.boss); τ ⊨ X ≜ invalid⟧ ⟹ τ ⊨ δ X› 2. ‹⟦τ::𝔄 state × 𝔄 state ⊨ δ (X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.boss); τ |≠ X ≜ invalid⟧ ⟹ τ ⊨ δ X› discuss goal 1*) apply ((insert StrongEq_L_subst2[where P = "(λx. (δ (x .boss)))" and τ = "τ" and x = "X" and y = "invalid"] (*‹⟦cp (λx. δ (x.boss)); τ ⊨ X ≜ invalid; τ ⊨ δ (X.boss)⟧ ⟹ τ ⊨ δ (invalid.boss)›*))[1]) (*top goal: ‹⟦τ ⊨ δ (X.boss); τ ⊨ X ≜ invalid⟧ ⟹ τ ⊨ δ X› and 1 goal remains*) apply (simp add: foundation16' (*‹(?τ::?'a state × ?'a state ⊨ δ (?X::?'a state × ?'a state ⇒ ?'b)) = (?X ?τ ≠ invalid ?τ ∧ ?X ?τ ≠ null ?τ)›*)) (*discuss goal 2*) apply ((insert StrongEq_L_subst2[where P = "(λx. (δ (x .boss)))" and τ = "τ" and x = "X" and y = "invalid"] (*‹⟦cp (λx::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥. δ (x.boss)); τ::𝔄 state × 𝔄 state ⊨ (X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥) ≜ invalid; τ ⊨ δ (X.boss)⟧ ⟹ τ ⊨ δ (invalid.boss)›*))[1]) (*goal: ‹⟦τ::𝔄 state × 𝔄 state ⊨ δ (X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.boss); τ |≠ X ≜ invalid⟧ ⟹ τ ⊨ δ X›*) apply (case_tac "τ ⊨ (X ≜ null)") (*goals: 1. ‹⟦τ ⊨ δ (X.boss); τ |≠ X ≜ invalid; ⟦cp (λx. δ (x.boss)); τ ⊨ X ≜ invalid; τ ⊨ δ (X.boss)⟧ ⟹ τ ⊨ δ (invalid.boss); τ ⊨ X ≜ null⟧ ⟹ τ ⊨ δ X› 2. ‹⟦τ ⊨ δ (X.boss); τ |≠ X ≜ invalid; ⟦cp (λx. δ (x.boss)); τ ⊨ X ≜ invalid; τ ⊨ δ (X.boss)⟧ ⟹ τ ⊨ δ (invalid.boss); τ |≠ X ≜ null⟧ ⟹ τ ⊨ δ X› discuss goal 1*) apply ((insert StrongEq_L_subst2[where P = "(λx. (δ (x .boss)))" and τ = "τ" and x = "X" and y = "null"] (*‹⟦cp (λx. δ (x.boss)); τ ⊨ X ≜ null; τ ⊨ δ (X.boss)⟧ ⟹ τ ⊨ δ (null.boss)›*))[1]) (*top goal: ‹⟦τ ⊨ δ (X.boss); τ |≠ X ≜ invalid; ⟦cp (λx. δ (x.boss)); τ ⊨ X ≜ invalid; τ ⊨ δ (X.boss)⟧ ⟹ τ ⊨ δ (invalid.boss); τ ⊨ X ≜ null⟧ ⟹ τ ⊨ δ X› and 1 goal remains*) apply (simp add: foundation16' (*‹(?τ ⊨ δ ?X) = (?X ?τ ≠ invalid ?τ ∧ ?X ?τ ≠ null ?τ)›*)) (*discuss goal 2*) apply ((insert StrongEq_L_subst2[where P = "(λx. (δ (x .boss)))" and τ = "τ" and x = "X" and y = "null"] (*‹⟦cp (λx. δ (x.boss)); τ ⊨ X ≜ null; τ ⊨ δ (X.boss)⟧ ⟹ τ ⊨ δ (null.boss)›*))[1]) (*goal: ‹⟦τ::𝔄 state × 𝔄 state ⊨ δ (X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.boss); τ |≠ X ≜ invalid; ⟦cp (λx::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥. δ (x.boss)); τ ⊨ X ≜ invalid; τ ⊨ δ (X.boss)⟧ ⟹ τ ⊨ δ (invalid.boss); τ |≠ X ≜ null⟧ ⟹ τ ⊨ δ X›*) apply (simp add: defined_split (*‹(?τ ⊨ δ ?x) = (?τ |≠ ?x ≜ invalid ∧ ?τ |≠ ?x ≜ null)›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma repr_boss: assumes A : "τ ⊨ δ(x .boss)" shows "is_represented_in_state in_post_state (x .boss) Person τ" apply (insert A[simplified foundation16] (*‹(x.boss) τ ≠ ⊥ ∧ (x.boss) τ ≠ null›*) A[THEN dot⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮_def_mono, simplified foundation16] (*‹x τ ≠ ⊥ ∧ x τ ≠ null›*)) (*goal: ‹is_represented_in_state in_post_state (x.boss) Person τ›*) unfolding is_represented_in_state_def "dot⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮_def" eval_extract_def "select⇩P⇩e⇩r⇩s⇩o⇩nℬ𝒪𝒮𝒮_def" in_post_state_def (*goal: ‹⟦(case x τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ invalid τ | ⌊⌊obj⌋⌋ ⇒ deref_oid⇩P⇩e⇩r⇩s⇩o⇩n snd (case_type⇩P⇩e⇩r⇩s⇩o⇩n (λx xa. case_option null (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n snd (λx _. ⌊⌊x⌋⌋)))) (oid_of obj) τ) ≠ ⊥ ∧ (case x τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ invalid τ | ⌊⌊obj⌋⌋ ⇒ deref_oid⇩P⇩e⇩r⇩s⇩o⇩n snd (case_type⇩P⇩e⇩r⇩s⇩o⇩n (λx xa. case_option null (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n snd (λx _. ⌊⌊x⌋⌋)))) (oid_of obj) τ) ≠ null; x τ ≠ ⊥ ∧ x τ ≠ null⟧ ⟹ (case x τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ invalid τ | ⌊⌊obj⌋⌋ ⇒ deref_oid⇩P⇩e⇩r⇩s⇩o⇩n snd (case_type⇩P⇩e⇩r⇩s⇩o⇩n (λx xa. case_option null (deref_oid⇩P⇩e⇩r⇩s⇩o⇩n snd (λx _. ⌊⌊x⌋⌋)))) (oid_of obj) τ) ∈ (Some ∘ Person) ` ran (heap (snd τ))›*) by (auto simp: deref_oid⇩P⇩e⇩r⇩s⇩o⇩n_def (*‹deref_oid⇩P⇩e⇩r⇩s⇩o⇩n ?fst_snd ?f ?oid = (λτ. case heap (?fst_snd τ) ?oid of ⊥ ⇒ invalid τ | ⌊in⇩P⇩e⇩r⇩s⇩o⇩n obj⌋ ⇒ ?f obj τ | ⌊in⇩O⇩c⇩l⇩A⇩n⇩y type⇩O⇩c⇩l⇩A⇩n⇩y⌋ ⇒ invalid τ)›*) bot_fun_def (*‹⊥ ≡ λx. ⊥›*) bot_option_def (*‹⊥ ≡ ⊥›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) null_fun_def (*‹null ≡ λx. null›*) invalid_def (*‹invalid ≡ λτ. ⊥›*) OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄_def (*‹OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 = (λu. case u of in⇩P⇩e⇩r⇩s⇩o⇩n p ⇒ ⌊p⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥) ⇒ ⊥ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋) ⇒ ⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋)›*) image_def (*‹?f ` ?A = {y. ∃x∈?A. y = ?f x}›*) ran_def (*‹ran ?m = {b. ∃a. ?m a = ⌊b⌋}›*) split: type⇩P⇩e⇩r⇩s⇩o⇩n.split (*‹?P (case ?type⇩P⇩e⇩r⇩s⇩o⇩n of mk⇩P⇩e⇩r⇩s⇩o⇩n x xa xb ⇒ ?f x xa xb) = (∀x1 x2 x3. ?type⇩P⇩e⇩r⇩s⇩o⇩n = mk⇩P⇩e⇩r⇩s⇩o⇩n x1 x2 x3 ⟶ ?P (?f x1 x2 x3))›*) option.split (*‹?P (case ?option of ⊥ ⇒ ?f1.0 | ⌊x⌋ ⇒ ?f2.0 x) = ((?option = ⊥ ⟶ ?P ?f1.0) ∧ (∀x2. ?option = ⌊x2⌋ ⟶ ?P (?f2.0 x2)))›*) 𝔄.split (*‹?P (case ?𝔄 of in⇩P⇩e⇩r⇩s⇩o⇩n x ⇒ ?f1.0 x | in⇩O⇩c⇩l⇩A⇩n⇩y x ⇒ ?f2.0 x) = ((∀x1. ?𝔄 = in⇩P⇩e⇩r⇩s⇩o⇩n x1 ⟶ ?P (?f1.0 x1)) ∧ (∀x2. ?𝔄 = in⇩O⇩c⇩l⇩A⇩n⇩y x2 ⟶ ?P (?f2.0 x2)))›*)) lemma repr_bossX : assumes A: "τ ⊨ δ(x .boss)" shows "τ ⊨ ((Person .allInstances()) ->includes⇩S⇩e⇩t(x .boss))" proof (-) (*goal: ‹τ ⊨ Person .allInstances()->includes⇩S⇩e⇩t(x.boss)›*) have B: "⋀S f. (x .boss) τ ∈ (Some ` f ` S) ⟹ (x .boss) τ ∈ (Some ` (f ` S - {None}))" apply (auto simp: image_def (*‹?f ` ?A = {y. ∃x∈?A. y = ?f x}›*) ran_def (*‹ran ?m = {b. ∃a. ?m a = ⌊b⌋}›*)) (*goals: 1. ‹⋀S f xa. ⟦(x.boss) τ = ⌊f xa⌋; xa ∈ S⟧ ⟹ ∃x∈S. f xa = f x› 2. ‹⋀S f xa. ⟦(x.boss) τ = ⌊f xa⌋; xa ∈ S⟧ ⟹ ∃y. f xa = ⌊y⌋› discuss goal 1*) apply metis (*discuss goal 2*) apply (insert A[simplified foundation16] (*‹(x.boss) τ ≠ ⊥ ∧ (x.boss) τ ≠ null›*)) (*goal: ‹⋀S f xa. ⟦(x.boss) τ = ⌊f xa⌋; xa ∈ S⟧ ⟹ ∃y. f xa = ⌊y⌋›*) apply (simp add: null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*)) (*proven 2 subgoals*) . show "?thesis" (*goal: ‹τ::𝔄 state × 𝔄 state ⊨ Person .allInstances()->includes⇩S⇩e⇩t(x::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.boss)›*) apply (insert repr_boss[OF A] (*‹is_represented_in_state in_post_state (x.boss) Person τ›*) OclAllInstances_at_post_defined[where H = Person and τ = τ] (*‹τ ⊨ δ Person .allInstances()›*)) (*goal: ‹τ::𝔄 state × 𝔄 state ⊨ Person .allInstances()->includes⇩S⇩e⇩t(x::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥.boss)›*) unfolding is_represented_in_state_def OclValid_def OclAllInstances_at_post_def OclAllInstances_generic_def OclIncludes_def in_post_state_def (*goal: ‹⟦(x.boss) τ ∈ (Some ∘ Person) ` ran (heap (snd τ)); (δ (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` (Person ` ran (heap (snd τ)) - {⊥})⌋⌋)) τ = true τ⟧ ⟹ (if (δ (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` (Person ` ran (heap (snd τ)) - {⊥})⌋⌋)) τ = true τ ∧ (υ (x.boss)) τ = true τ then ⌊⌊(x.boss) τ ∈ ⌈⌈Rep_Set⇩b⇩a⇩s⇩e (Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` (Person ` ran (heap (snd τ)) - {⊥})⌋⌋)⌉⌉⌋⌋ else ⊥) = true τ›*) apply (simp add: A[THEN foundation20, simplified OclValid_def] (*‹(υ (x.boss)) τ = true τ›*)) (*goal: ‹⟦(x.boss) τ ∈ (Some ∘ Person) ` ran (heap (snd τ)); (δ (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` (Person ` ran (heap (snd τ)) - {⊥})⌋⌋)) τ = true τ⟧ ⟹ (if (δ (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` (Person ` ran (heap (snd τ)) - {⊥})⌋⌋)) τ = true τ ∧ (υ (x.boss)) τ = true τ then ⌊⌊(x.boss) τ ∈ ⌈⌈Rep_Set⇩b⇩a⇩s⇩e (Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` (Person ` ran (heap (snd τ)) - {⊥})⌋⌋)⌉⌉⌋⌋ else ⊥) = true τ›*) apply (subst Abs_Set⇩b⇩a⇩s⇩e_inverse (*‹?y ∈ {X. X = ⊥ ∨ X = null ∨ (∀x∈⌈⌈X⌉⌉. x ≠ ⊥)} ⟹ Rep_Set⇩b⇩a⇩s⇩e (Abs_Set⇩b⇩a⇩s⇩e ?y) = ?y›*)) (*goals: 1. ‹⟦(x.boss) τ ∈ (λx. ⌊OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 x⌋) ` ran (heap (snd τ)); (δ (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` (OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 ` ran (heap (snd τ)) - {⊥})⌋⌋)) τ = true τ⟧ ⟹ ⌊⌊Some ` (OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 ` ran (heap (snd τ)) - {⊥})⌋⌋ ∈ {X. X = ⊥ ∨ X = null ∨ (∀x∈⌈⌈X⌉⌉. x ≠ ⊥)}› 2. ‹⟦(x.boss) τ ∈ (λx. ⌊OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 x⌋) ` ran (heap (snd τ)); (δ (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` (OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 ` ran (heap (snd τ)) - {⊥})⌋⌋)) τ = true τ⟧ ⟹ ⌊⌊(x.boss) τ ∈ ⌈⌈⌊⌊Some ` (OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 ` ran (heap (snd τ)) - {⊥})⌋⌋⌉⌉⌋⌋ = true τ› discuss goal 1*) apply simp (*top goal: ‹⟦(x.boss) τ ∈ (λx. ⌊OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 x⌋) ` ran (heap (snd τ)); (δ (λτ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊Some ` (OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 ` ran (heap (snd τ)) - {⊥})⌋⌋)) τ = true τ⟧ ⟹ ⌊⌊Some ` (OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 ` ran (heap (snd τ)) - {⊥})⌋⌋ ∈ {X. X = ⊥ ∨ X = null ∨ (∀x∈⌈⌈X⌉⌉. x ≠ ⊥)}› and 1 goal remains*) apply (metis bot_option_def (*‹⊥ ≡ ⊥›*) option.distinct( (*‹⊥ ≠ ⌊?x2.0⌋›*) 1)) (*discuss goal 2*) apply (simp add: image_comp (*‹?f ` ?g ` ?r = (?f ∘ ?g) ` ?r›*) B (*‹(x.boss) τ ∈ Some ` ?f ` ?S ⟹ (x.boss) τ ∈ Some ` (?f ` ?S - {⊥})›*) true_def (*‹true ≡ λτ. ⌊⌊True⌋⌋›*)) (*proven 2 subgoals*) . qed section‹A Little Infra-structure on Example States› text‹ The example we are defining in this section comes from the figure~\ref{fig:edm1_system-states}. \begin{figure} \includegraphics[width=\textwidth]{figures/pre-post.pdf} \caption{(a) pre-state $\sigma_1$ and (b) post-state $\sigma_1'$.} \label{fig:edm1_system-states} \end{figure} › text_raw‹\isatagafp› definition OclInt1000 ("𝟭𝟬𝟬𝟬") where "OclInt1000 = (λ _ . ⌊⌊1000⌋⌋)" definition OclInt1200 ("𝟭𝟮𝟬𝟬") where "OclInt1200 = (λ _ . ⌊⌊1200⌋⌋)" definition OclInt1300 ("𝟭𝟯𝟬𝟬") where "OclInt1300 = (λ _ . ⌊⌊1300⌋⌋)" definition OclInt1800 ("𝟭𝟴𝟬𝟬") where "OclInt1800 = (λ _ . ⌊⌊1800⌋⌋)" definition OclInt2600 ("𝟮𝟲𝟬𝟬") where "OclInt2600 = (λ _ . ⌊⌊2600⌋⌋)" definition OclInt2900 ("𝟮𝟵𝟬𝟬") where "OclInt2900 = (λ _ . ⌊⌊2900⌋⌋)" definition OclInt3200 ("𝟯𝟮𝟬𝟬") where "OclInt3200 = (λ _ . ⌊⌊3200⌋⌋)" definition OclInt3500 ("𝟯𝟱𝟬𝟬") where "OclInt3500 = (λ _ . ⌊⌊3500⌋⌋)" definition "oid0 ≡ 0" definition "oid1 ≡ 1" definition "oid2 ≡ 2" definition "oid3 ≡ 3" definition "oid4 ≡ 4" definition "oid5 ≡ 5" definition "oid6 ≡ 6" definition "oid7 ≡ 7" definition "oid8 ≡ 8" definition "person1 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1300⌋ ⌊oid1⌋" definition "person2 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1800⌋ ⌊oid1⌋" definition "person3 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid2 None None" definition "person4 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2900⌋ None" definition "person5 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid4 ⌊3500⌋ None" definition "person6 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2500⌋ ⌊oid6⌋" definition "person7 ≡ mk⇩O⇩c⇩l⇩A⇩n⇩y oid6 ⌊(⌊3200⌋, ⌊oid6⌋)⌋" definition "person8 ≡ mk⇩O⇩c⇩l⇩A⇩n⇩y oid7 None" definition "person9 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid8 ⌊0⌋ None" definition "σ₁ ≡ ⦇ heap = Map.empty(oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1000⌋ ⌊oid1⌋), oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1200⌋ None), ⌦‹oid2› oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2600⌋ ⌊oid4⌋), oid4 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person5, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2300⌋ ⌊oid3⌋), ⌦‹oid6› ⌦‹oid7› oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9), assocs = Map.empty ⦈" definition "σ₁' ≡ ⦇ heap = Map.empty(oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, oid2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, ⌦‹oid4› oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, oid6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, oid7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9), assocs = Map.empty ⦈" definition "σ₀ ≡ ⦇ heap = Map.empty, assocs = Map.empty ⦈" lemma basic_τ_wff: "WFF(σ₁,σ₁')" by (auto simp: WFF_def (*‹WFF ?τ = ((∀x∈ran (heap (fst ?τ)). ⌈heap (fst ?τ) (oid_of x)⌉ = x) ∧ (∀x∈ran (heap (snd ?τ)). ⌈heap (snd ?τ) (oid_of x)⌉ = x))›*) σ₁_def (*‹σ₁ ≡ ⦇heap = [oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1000⌋ ⌊oid1⌋), oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1200⌋ ⊥), oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2600⌋ ⌊oid4⌋), oid4 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person5, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2300⌋ ⌊oid3⌋), oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9], assocs = λx. ⊥⦈›*) σ₁'_def (*‹σ₁' ≡ ⦇heap = [oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, oid2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, oid6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, oid7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9], assocs = λx. ⊥⦈›*) oid0_def (*‹oid0 ≡ 0›*) oid1_def (*‹oid1 ≡ 1›*) oid2_def (*‹oid2 ≡ 2›*) oid3_def (*‹oid3 ≡ 3›*) oid4_def (*‹oid4 ≡ 4›*) oid5_def (*‹oid5 ≡ 5›*) oid6_def (*‹oid6 ≡ 6›*) oid7_def (*‹oid7 ≡ 7›*) oid8_def (*‹oid8 ≡ 8›*) oid_of_𝔄_def (*‹oid_of ?x = (case ?x of in⇩P⇩e⇩r⇩s⇩o⇩n person ⇒ oid_of person | in⇩O⇩c⇩l⇩A⇩n⇩y oclany ⇒ oid_of oclany)›*) oid_of_type⇩P⇩e⇩r⇩s⇩o⇩n_def (*‹oid_of ?x = (case ?x of mk⇩P⇩e⇩r⇩s⇩o⇩n oid x xa ⇒ oid)›*) oid_of_type⇩O⇩c⇩l⇩A⇩n⇩y_def (*‹oid_of ?x = (case ?x of mk⇩O⇩c⇩l⇩A⇩n⇩y oid x ⇒ oid)›*) person1_def (*‹person1 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1300⌋ ⌊oid1⌋›*) person2_def (*‹person2 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1800⌋ ⌊oid1⌋›*) person3_def (*‹person3 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid2 ⊥ ⊥›*) person4_def (*‹person4 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2900⌋ ⊥›*) person5_def (*‹person5 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid4 ⌊3500⌋ ⊥›*) person6_def (*‹person6 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2500⌋ ⌊oid6⌋›*) person7_def (*‹person7 ≡ mk⇩O⇩c⇩l⇩A⇩n⇩y oid6 ⌊(⌊3200⌋, ⌊oid6⌋)⌋›*) person8_def (*‹person8 ≡ mk⇩O⇩c⇩l⇩A⇩n⇩y oid7 ⊥›*) person9_def (*‹person9 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid8 ⌊0⌋ ⊥›*)) lemma [simp,code_unfold]: "dom (heap σ₁) = {oid0,oid1⌦‹,oid2›,oid3,oid4,oid5⌦‹,oid6,oid7›,oid8}" by (auto simp: σ₁_def (*‹σ₁ ≡ ⦇heap = [oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1000⌋ ⌊oid1⌋), oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1200⌋ ⊥), oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2600⌋ ⌊oid4⌋), oid4 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person5, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2300⌋ ⌊oid3⌋), oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9], assocs = λx. ⊥⦈›*)) lemma [simp,code_unfold]: "dom (heap σ₁') = {oid0,oid1,oid2,oid3⌦‹,oid4›,oid5,oid6,oid7,oid8}" by (auto simp: σ₁'_def (*‹σ₁' ≡ ⦇heap = [oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, oid2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, oid6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, oid7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9], assocs = λx. ⊥⦈›*)) text_raw‹\isatagafp› definition "X⇩P⇩e⇩r⇩s⇩o⇩n1 :: Person ≡ λ _ .⌊⌊ person1 ⌋⌋" definition "X⇩P⇩e⇩r⇩s⇩o⇩n2 :: Person ≡ λ _ .⌊⌊ person2 ⌋⌋" definition "X⇩P⇩e⇩r⇩s⇩o⇩n3 :: Person ≡ λ _ .⌊⌊ person3 ⌋⌋" definition "X⇩P⇩e⇩r⇩s⇩o⇩n4 :: Person ≡ λ _ .⌊⌊ person4 ⌋⌋" definition "X⇩P⇩e⇩r⇩s⇩o⇩n5 :: Person ≡ λ _ .⌊⌊ person5 ⌋⌋" definition "X⇩P⇩e⇩r⇩s⇩o⇩n6 :: Person ≡ λ _ .⌊⌊ person6 ⌋⌋" definition "X⇩P⇩e⇩r⇩s⇩o⇩n7 :: OclAny ≡ λ _ .⌊⌊ person7 ⌋⌋" definition "X⇩P⇩e⇩r⇩s⇩o⇩n8 :: OclAny ≡ λ _ .⌊⌊ person8 ⌋⌋" definition "X⇩P⇩e⇩r⇩s⇩o⇩n9 :: Person ≡ λ _ .⌊⌊ person9 ⌋⌋" lemma [code_unfold]: "((x::Person) ≐ y) = StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t x y" by (simp only: StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t_⇩P⇩e⇩r⇩s⇩o⇩n (*‹?x ≐ ?y ≡ StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t ?x ?y›*)) lemma [code_unfold]: "((x::OclAny) ≐ y) = StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t x y" by (simp only: StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t_⇩O⇩c⇩l⇩A⇩n⇩y (*‹?x ≐ ?y ≡ StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t ?x ?y›*)) lemmas [simp,code_unfold] = OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_OclAny OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_Person OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_OclAny OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_Person OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny OclIsTypeOf⇩O⇩c⇩l⇩A⇩n⇩y_Person OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny OclIsTypeOf⇩P⇩e⇩r⇩s⇩o⇩n_Person OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_OclAny OclIsKindOf⇩O⇩c⇩l⇩A⇩n⇩y_Person OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_OclAny OclIsKindOf⇩P⇩e⇩r⇩s⇩o⇩n_Person text_raw‹\endisatagafp› Assert "⋀s⇩p⇩r⇩e . (s⇩p⇩r⇩e,σ₁') ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n1 .salary <> 𝟭𝟬𝟬𝟬)" Assert "⋀s⇩p⇩r⇩e . (s⇩p⇩r⇩e,σ₁') ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n1 .salary ≐ 𝟭𝟯𝟬𝟬)" Assert "⋀ s⇩p⇩o⇩s⇩t. (σ₁,s⇩p⇩o⇩s⇩t) ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n1 .salary@pre ≐ 𝟭𝟬𝟬𝟬)" Assert "⋀ s⇩p⇩o⇩s⇩t. (σ₁,s⇩p⇩o⇩s⇩t) ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n1 .salary@pre <> 𝟭𝟯𝟬𝟬)" Assert "⋀s⇩p⇩r⇩e . (s⇩p⇩r⇩e,σ₁') ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n1 .boss <> X⇩P⇩e⇩r⇩s⇩o⇩n1)" Assert "⋀s⇩p⇩r⇩e . (s⇩p⇩r⇩e,σ₁') ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n1 .boss .salary ≐ 𝟭𝟴𝟬𝟬)" Assert "⋀s⇩p⇩r⇩e . (s⇩p⇩r⇩e,σ₁') ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n1 .boss .boss <> X⇩P⇩e⇩r⇩s⇩o⇩n1)" Assert "⋀s⇩p⇩r⇩e . (s⇩p⇩r⇩e,σ₁') ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n1 .boss .boss ≐ X⇩P⇩e⇩r⇩s⇩o⇩n2)" Assert " (σ₁,σ₁') ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n1 .boss@pre .salary ≐ 𝟭𝟴𝟬𝟬)" Assert "⋀ s⇩p⇩o⇩s⇩t. (σ₁,s⇩p⇩o⇩s⇩t) ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n1 .boss@pre .salary@pre ≐ 𝟭𝟮𝟬𝟬)" Assert "⋀ s⇩p⇩o⇩s⇩t. (σ₁,s⇩p⇩o⇩s⇩t) ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n1 .boss@pre .salary@pre <> 𝟭𝟴𝟬𝟬)" Assert "⋀ s⇩p⇩o⇩s⇩t. (σ₁,s⇩p⇩o⇩s⇩t) ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n1 .boss@pre ≐ X⇩P⇩e⇩r⇩s⇩o⇩n2)" Assert " (σ₁,σ₁') ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n1 .boss@pre .boss ≐ X⇩P⇩e⇩r⇩s⇩o⇩n2)" Assert "⋀ s⇩p⇩o⇩s⇩t. (σ₁,s⇩p⇩o⇩s⇩t) ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n1 .boss@pre .boss@pre ≐ null)" Assert "⋀ s⇩p⇩o⇩s⇩t. (σ₁,s⇩p⇩o⇩s⇩t) ⊨ not(υ(X⇩P⇩e⇩r⇩s⇩o⇩n1 .boss@pre .boss@pre .boss@pre))" lemma " (σ₁,σ₁') ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n1 .oclIsMaintained())" by (simp add: OclValid_def (*‹?τ ⊨ ?P ≡ ?P ?τ = true ?τ›*) OclIsMaintained_def (*‹?X.oclIsMaintained() ≡ λτ. if (δ ?X) τ = true τ then ⌊⌊oid_of (?X τ) ∈ dom (heap (fst τ)) ∧ oid_of (?X τ) ∈ dom (heap (snd τ))⌋⌋ else invalid τ›*) σ₁_def (*‹σ₁ ≡ ⦇heap = [oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1000⌋ ⌊oid1⌋), oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1200⌋ ⊥), oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2600⌋ ⌊oid4⌋), oid4 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person5, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2300⌋ ⌊oid3⌋), oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9], assocs = λx. ⊥⦈›*) σ₁'_def (*‹σ₁' ≡ ⦇heap = [oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, oid2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, oid6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, oid7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9], assocs = λx. ⊥⦈›*) X⇩P⇩e⇩r⇩s⇩o⇩n1_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n1 ≡ λ_. ⌊⌊person1⌋⌋›*) person1_def (*‹person1 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1300⌋ ⌊oid1⌋›*) oid0_def (*‹oid0 ≡ 0›*) oid1_def (*‹oid1 ≡ 1›*) oid2_def (*‹oid2 ≡ 2›*) oid3_def (*‹oid3 ≡ 3›*) oid4_def (*‹oid4 ≡ 4›*) oid5_def (*‹oid5 ≡ 5›*) oid6_def (*‹oid6 ≡ 6›*) oid_of_option_def (*‹oid_of ?x = oid_of (the ?x)›*) oid_of_type⇩P⇩e⇩r⇩s⇩o⇩n_def (*‹oid_of ?x = (case ?x of mk⇩P⇩e⇩r⇩s⇩o⇩n oid x xa ⇒ oid)›*)) lemma "⋀s⇩p⇩r⇩e s⇩p⇩o⇩s⇩t. (s⇩p⇩r⇩e,s⇩p⇩o⇩s⇩t) ⊨ ((X⇩P⇩e⇩r⇩s⇩o⇩n1 .oclAsType(OclAny) .oclAsType(Person)) ≐ X⇩P⇩e⇩r⇩s⇩o⇩n1)" apply (rule up_down_cast_Person_OclAny_Person' (*‹?τ ⊨ υ ?X ⟹ ?τ ⊨ ?X .oclAsType(OclAny) .oclAsType(Person) ≐ ?X›*)) (*goal: ‹⋀s⇩p⇩r⇩e s⇩p⇩o⇩s⇩t. (s⇩p⇩r⇩e, s⇩p⇩o⇩s⇩t) ⊨ X⇩P⇩e⇩r⇩s⇩o⇩n1 .oclAsType(OclAny) .oclAsType(Person) ≐ X⇩P⇩e⇩r⇩s⇩o⇩n1›*) by (simp add: X⇩P⇩e⇩r⇩s⇩o⇩n1_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n1 ≡ λ_. ⌊⌊person1⌋⌋›*)) Assert "⋀s⇩p⇩r⇩e s⇩p⇩o⇩s⇩t. (s⇩p⇩r⇩e,s⇩p⇩o⇩s⇩t) ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n1 .oclIsTypeOf(Person))" Assert "⋀s⇩p⇩r⇩e s⇩p⇩o⇩s⇩t. (s⇩p⇩r⇩e,s⇩p⇩o⇩s⇩t) ⊨ not(X⇩P⇩e⇩r⇩s⇩o⇩n1 .oclIsTypeOf(OclAny))" Assert "⋀s⇩p⇩r⇩e s⇩p⇩o⇩s⇩t. (s⇩p⇩r⇩e,s⇩p⇩o⇩s⇩t) ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n1 .oclIsKindOf(Person))" Assert "⋀s⇩p⇩r⇩e s⇩p⇩o⇩s⇩t. (s⇩p⇩r⇩e,s⇩p⇩o⇩s⇩t) ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n1 .oclIsKindOf(OclAny))" Assert "⋀s⇩p⇩r⇩e s⇩p⇩o⇩s⇩t. (s⇩p⇩r⇩e,s⇩p⇩o⇩s⇩t) ⊨ not(X⇩P⇩e⇩r⇩s⇩o⇩n1 .oclAsType(OclAny) .oclIsTypeOf(OclAny))" Assert "⋀s⇩p⇩r⇩e . (s⇩p⇩r⇩e,σ₁') ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n2 .salary ≐ 𝟭𝟴𝟬𝟬)" Assert "⋀ s⇩p⇩o⇩s⇩t. (σ₁,s⇩p⇩o⇩s⇩t) ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n2 .salary@pre ≐ 𝟭𝟮𝟬𝟬)" Assert "⋀s⇩p⇩r⇩e . (s⇩p⇩r⇩e,σ₁') ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n2 .boss ≐ X⇩P⇩e⇩r⇩s⇩o⇩n2)" Assert " (σ₁,σ₁') ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n2 .boss .salary@pre ≐ 𝟭𝟮𝟬𝟬)" Assert " (σ₁,σ₁') ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n2 .boss .boss@pre ≐ null)" Assert "⋀ s⇩p⇩o⇩s⇩t. (σ₁,s⇩p⇩o⇩s⇩t) ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n2 .boss@pre ≐ null)" Assert "⋀ s⇩p⇩o⇩s⇩t. (σ₁,s⇩p⇩o⇩s⇩t) ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n2 .boss@pre <> X⇩P⇩e⇩r⇩s⇩o⇩n2)" Assert " (σ₁,σ₁') ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n2 .boss@pre <> (X⇩P⇩e⇩r⇩s⇩o⇩n2 .boss))" Assert "⋀ s⇩p⇩o⇩s⇩t. (σ₁,s⇩p⇩o⇩s⇩t) ⊨ not(υ(X⇩P⇩e⇩r⇩s⇩o⇩n2 .boss@pre .boss))" Assert "⋀ s⇩p⇩o⇩s⇩t. (σ₁,s⇩p⇩o⇩s⇩t) ⊨ not(υ(X⇩P⇩e⇩r⇩s⇩o⇩n2 .boss@pre .salary@pre))" lemma " (σ₁,σ₁') ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n2 .oclIsMaintained())" sorry Assert "⋀s⇩p⇩r⇩e . (s⇩p⇩r⇩e,σ₁') ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n3 .salary ≐ null)" Assert "⋀ s⇩p⇩o⇩s⇩t. (σ₁,s⇩p⇩o⇩s⇩t) ⊨ not(υ(X⇩P⇩e⇩r⇩s⇩o⇩n3 .salary@pre))" Assert "⋀s⇩p⇩r⇩e . (s⇩p⇩r⇩e,σ₁') ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n3 .boss ≐ null)" Assert "⋀s⇩p⇩r⇩e . (s⇩p⇩r⇩e,σ₁') ⊨ not(υ(X⇩P⇩e⇩r⇩s⇩o⇩n3 .boss .salary))" Assert "⋀ s⇩p⇩o⇩s⇩t. (σ₁,s⇩p⇩o⇩s⇩t) ⊨ not(υ(X⇩P⇩e⇩r⇩s⇩o⇩n3 .boss@pre))" lemma " (σ₁,σ₁') ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n3 .oclIsNew())" by (simp add: OclValid_def (*‹?τ ⊨ ?P ≡ ?P ?τ = true ?τ›*) OclIsNew_def (*‹?X.oclIsNew() ≡ λτ. if (δ ?X) τ = true τ then ⌊⌊oid_of (?X τ) ∉ dom (heap (fst τ)) ∧ oid_of (?X τ) ∈ dom (heap (snd τ))⌋⌋ else invalid τ›*) σ₁_def (*‹σ₁ ≡ ⦇heap = [oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1000⌋ ⌊oid1⌋), oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1200⌋ ⊥), oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2600⌋ ⌊oid4⌋), oid4 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person5, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2300⌋ ⌊oid3⌋), oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9], assocs = λx. ⊥⦈›*) σ₁'_def (*‹σ₁' ≡ ⦇heap = [oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, oid2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, oid6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, oid7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9], assocs = λx. ⊥⦈›*) X⇩P⇩e⇩r⇩s⇩o⇩n3_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n3 ≡ λ_. ⌊⌊person3⌋⌋›*) person3_def (*‹person3 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid2 ⊥ ⊥›*) oid0_def (*‹oid0 ≡ 0›*) oid1_def (*‹oid1 ≡ 1›*) oid2_def (*‹oid2 ≡ 2›*) oid3_def (*‹oid3 ≡ 3›*) oid4_def (*‹oid4 ≡ 4›*) oid5_def (*‹oid5 ≡ 5›*) oid6_def (*‹oid6 ≡ 6›*) oid8_def (*‹oid8 ≡ 8›*) oid_of_option_def (*‹oid_of ?x = oid_of (the ?x)›*) oid_of_type⇩P⇩e⇩r⇩s⇩o⇩n_def (*‹oid_of ?x = (case ?x of mk⇩P⇩e⇩r⇩s⇩o⇩n oid x xa ⇒ oid)›*)) Assert "⋀ s⇩p⇩o⇩s⇩t. (σ₁,s⇩p⇩o⇩s⇩t) ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n4 .boss@pre ≐ X⇩P⇩e⇩r⇩s⇩o⇩n5)" Assert " (σ₁,σ₁') ⊨ not(υ(X⇩P⇩e⇩r⇩s⇩o⇩n4 .boss@pre .salary))" Assert "⋀ s⇩p⇩o⇩s⇩t. (σ₁,s⇩p⇩o⇩s⇩t) ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n4 .boss@pre .salary@pre ≐ 𝟯𝟱𝟬𝟬)" lemma " (σ₁,σ₁') ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n4 .oclIsMaintained())" by (simp add: OclValid_def (*‹?τ ⊨ ?P ≡ ?P ?τ = true ?τ›*) OclIsMaintained_def (*‹?X.oclIsMaintained() ≡ λτ. if (δ ?X) τ = true τ then ⌊⌊oid_of (?X τ) ∈ dom (heap (fst τ)) ∧ oid_of (?X τ) ∈ dom (heap (snd τ))⌋⌋ else invalid τ›*) σ₁_def (*‹σ₁ ≡ ⦇heap = [oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1000⌋ ⌊oid1⌋), oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1200⌋ ⊥), oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2600⌋ ⌊oid4⌋), oid4 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person5, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2300⌋ ⌊oid3⌋), oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9], assocs = λx. ⊥⦈›*) σ₁'_def (*‹σ₁' ≡ ⦇heap = [oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, oid2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, oid6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, oid7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9], assocs = λx. ⊥⦈›*) X⇩P⇩e⇩r⇩s⇩o⇩n4_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n4 ≡ λ_. ⌊⌊person4⌋⌋›*) person4_def (*‹person4 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2900⌋ ⊥›*) oid0_def (*‹oid0 ≡ 0›*) oid1_def (*‹oid1 ≡ 1›*) oid2_def (*‹oid2 ≡ 2›*) oid3_def (*‹oid3 ≡ 3›*) oid4_def (*‹oid4 ≡ 4›*) oid5_def (*‹oid5 ≡ 5›*) oid6_def (*‹oid6 ≡ 6›*) oid_of_option_def (*‹oid_of ?x = oid_of (the ?x)›*) oid_of_type⇩P⇩e⇩r⇩s⇩o⇩n_def (*‹oid_of ?x = (case ?x of mk⇩P⇩e⇩r⇩s⇩o⇩n oid x xa ⇒ oid)›*)) Assert "⋀s⇩p⇩r⇩e . (s⇩p⇩r⇩e,σ₁') ⊨ not(υ(X⇩P⇩e⇩r⇩s⇩o⇩n5 .salary))" Assert "⋀ s⇩p⇩o⇩s⇩t. (σ₁,s⇩p⇩o⇩s⇩t) ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n5 .salary@pre ≐ 𝟯𝟱𝟬𝟬)" Assert "⋀s⇩p⇩r⇩e . (s⇩p⇩r⇩e,σ₁') ⊨ not(υ(X⇩P⇩e⇩r⇩s⇩o⇩n5 .boss))" lemma " (σ₁,σ₁') ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n5 .oclIsDeleted())" by (simp add: OclNot_def (*‹not ?X ≡ λτ. case ?X τ of ⊥ ⇒ ⊥ | ⌊⊥⌋ ⇒ ⌊⊥⌋ | ⌊⌊x⌋⌋ ⇒ ⌊⌊¬ x⌋⌋›*) OclValid_def (*‹?τ ⊨ ?P ≡ ?P ?τ = true ?τ›*) OclIsDeleted_def (*‹?X.oclIsDeleted() ≡ λτ. if (δ ?X) τ = true τ then ⌊⌊oid_of (?X τ) ∈ dom (heap (fst τ)) ∧ oid_of (?X τ) ∉ dom (heap (snd τ))⌋⌋ else invalid τ›*) σ₁_def (*‹σ₁ ≡ ⦇heap = [oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1000⌋ ⌊oid1⌋), oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1200⌋ ⊥), oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2600⌋ ⌊oid4⌋), oid4 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person5, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2300⌋ ⌊oid3⌋), oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9], assocs = λx. ⊥⦈›*) σ₁'_def (*‹σ₁' ≡ ⦇heap = [oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, oid2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, oid6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, oid7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9], assocs = λx. ⊥⦈›*) X⇩P⇩e⇩r⇩s⇩o⇩n5_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n5 ≡ λ_. ⌊⌊person5⌋⌋›*) person5_def (*‹person5 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid4 ⌊3500⌋ ⊥›*) oid0_def (*‹oid0 ≡ 0›*) oid1_def (*‹oid1 ≡ 1›*) oid2_def (*‹oid2 ≡ 2›*) oid3_def (*‹oid3 ≡ 3›*) oid4_def (*‹oid4 ≡ 4›*) oid5_def (*‹oid5 ≡ 5›*) oid6_def (*‹oid6 ≡ 6›*) oid7_def (*‹oid7 ≡ 7›*) oid8_def (*‹oid8 ≡ 8›*) oid_of_option_def (*‹oid_of ?x = oid_of (the ?x)›*) oid_of_type⇩P⇩e⇩r⇩s⇩o⇩n_def (*‹oid_of ?x = (case ?x of mk⇩P⇩e⇩r⇩s⇩o⇩n oid x xa ⇒ oid)›*)) (* (* access to an oclany object not yet supported *) Assert " (σ₁,σ₁') ⊨ ((X⇩P⇩e⇩r⇩s⇩o⇩n6 .boss .salary) ≐ 𝟯𝟮𝟬𝟬 )"*) Assert "⋀s⇩p⇩r⇩e . (s⇩p⇩r⇩e,σ₁') ⊨ not(υ(X⇩P⇩e⇩r⇩s⇩o⇩n6 .boss .salary@pre))" Assert "⋀ s⇩p⇩o⇩s⇩t. (σ₁,s⇩p⇩o⇩s⇩t) ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n6 .boss@pre ≐ X⇩P⇩e⇩r⇩s⇩o⇩n4)" Assert " (σ₁,σ₁') ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n6 .boss@pre .salary ≐ 𝟮𝟵𝟬𝟬)" Assert "⋀ s⇩p⇩o⇩s⇩t. (σ₁,s⇩p⇩o⇩s⇩t) ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n6 .boss@pre .salary@pre ≐ 𝟮𝟲𝟬𝟬)" Assert "⋀ s⇩p⇩o⇩s⇩t. (σ₁,s⇩p⇩o⇩s⇩t) ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n6 .boss@pre .boss@pre ≐ X⇩P⇩e⇩r⇩s⇩o⇩n5)" lemma " (σ₁,σ₁') ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n6 .oclIsMaintained())" by (simp add: OclValid_def (*‹?τ::?'𝔄 state × ?'𝔄 state ⊨ ?P::?'𝔄 state × ?'𝔄 state ⇒ ⟨⟨bool⟩⇩⊥⟩⇩⊥ ≡ ?P ?τ = true ?τ›*) OclIsMaintained_def (*‹?X::?'𝔄 state × ?'𝔄 state ⇒ ?'α::{null,object}.oclIsMaintained() ≡ λτ::?'𝔄 state × ?'𝔄 state. if (δ ?X) τ = true τ then ⌊⌊oid_of (?X τ) ∈ dom (heap (fst τ)) ∧ oid_of (?X τ) ∈ dom (heap (snd τ))⌋⌋ else invalid τ›*) σ₁_def (*‹σ₁ ≡ ⦇heap = [oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1000::int⌋ ⌊oid1⌋), oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1200::int⌋ ⊥), oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2600::int⌋ ⌊oid4⌋), oid4 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person5, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2300::int⌋ ⌊oid3⌋), oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9], assocs = λx::nat. ⊥⦈›*) σ₁'_def (*‹σ₁' ≡ ⦇heap = [oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, oid2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, oid6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, oid7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9], assocs = λx::nat. ⊥⦈›*) X⇩P⇩e⇩r⇩s⇩o⇩n6_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n6 ≡ λ_::𝔄 state × 𝔄 state. ⌊⌊person6⌋⌋›*) person6_def (*‹person6 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2500::int⌋ ⌊oid6⌋›*) oid0_def (*‹oid0 ≡ 0::?'a::zero›*) oid1_def (*‹oid1 ≡ 1::?'a::one›*) oid2_def (*‹oid2 ≡ 2::?'a::numeral›*) oid3_def (*‹oid3 ≡ 3::?'a::numeral›*) oid4_def (*‹oid4 ≡ 4::?'a::numeral›*) oid5_def (*‹oid5 ≡ 5::?'a::numeral›*) oid6_def (*‹oid6 ≡ 6::?'a::numeral›*) oid_of_option_def (*‹oid_of (?x::⟨?'a::object⟩⇩⊥) = oid_of (the ?x)›*) oid_of_type⇩P⇩e⇩r⇩s⇩o⇩n_def (*‹oid_of (?x::type⇩P⇩e⇩r⇩s⇩o⇩n) = (case ?x of mk⇩P⇩e⇩r⇩s⇩o⇩n (oid::nat) (x::⟨int⟩⇩⊥) (xa::⟨nat⟩⇩⊥) ⇒ oid)›*)) (* (* access to an oclany object not yet supported *) Assert " (σ₁,σ₁') ⊨ ((X⇩P⇩e⇩r⇩s⇩o⇩n7 .oclAsType(Person) ≐ (X⇩P⇩e⇩r⇩s⇩o⇩n6 .boss)))" *) (* (* access to an oclany object not yet supported *) Assert " (σ₁,σ₁') ⊨ ((X⇩P⇩e⇩r⇩s⇩o⇩n7 .oclAsType(Person) .boss) ≐ (X⇩P⇩e⇩r⇩s⇩o⇩n7 .oclAsType(Person)) )" *) (* (* access to an oclany object not yet supported *) Assert " (σ₁,σ₁') ⊨ ((X⇩P⇩e⇩r⇩s⇩o⇩n7 .oclAsType(Person) .boss .salary) ≐ 𝟯𝟮𝟬𝟬 )" *) Assert "⋀s⇩p⇩r⇩e s⇩p⇩o⇩s⇩t. (s⇩p⇩r⇩e,s⇩p⇩o⇩s⇩t) ⊨ υ(X⇩P⇩e⇩r⇩s⇩o⇩n7 .oclAsType(Person))" Assert "⋀ s⇩p⇩o⇩s⇩t. (σ₁,s⇩p⇩o⇩s⇩t) ⊨ not(υ(X⇩P⇩e⇩r⇩s⇩o⇩n7 .oclAsType(Person) .boss@pre))" lemma "⋀s⇩p⇩r⇩e s⇩p⇩o⇩s⇩t. (s⇩p⇩r⇩e,s⇩p⇩o⇩s⇩t) ⊨ ((X⇩P⇩e⇩r⇩s⇩o⇩n7 .oclAsType(Person) .oclAsType(OclAny) .oclAsType(Person)) ≐ (X⇩P⇩e⇩r⇩s⇩o⇩n7 .oclAsType(Person)))" apply (rule up_down_cast_Person_OclAny_Person' (*‹?τ ⊨ υ ?X ⟹ ?τ ⊨ ?X .oclAsType(OclAny) .oclAsType(Person) ≐ ?X›*)) (*goal: ‹⋀s⇩p⇩r⇩e s⇩p⇩o⇩s⇩t. (s⇩p⇩r⇩e, s⇩p⇩o⇩s⇩t) ⊨ X⇩P⇩e⇩r⇩s⇩o⇩n7 .oclAsType(Person) .oclAsType(OclAny) .oclAsType(Person) ≐ X⇩P⇩e⇩r⇩s⇩o⇩n7 .oclAsType(Person)›*) by (simp add: X⇩P⇩e⇩r⇩s⇩o⇩n7_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n7 ≡ λ_. ⌊⌊person7⌋⌋›*) OclValid_def (*‹?τ ⊨ ?P ≡ ?P ?τ = true ?τ›*) valid_def (*‹υ ?X ≡ λτ. if ?X τ = ⊥ τ then false τ else true τ›*) person7_def (*‹person7 ≡ mk⇩O⇩c⇩l⇩A⇩n⇩y oid6 ⌊(⌊3200⌋, ⌊oid6⌋)⌋›*)) lemma " (σ₁,σ₁') ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n7 .oclIsNew())" by (simp add: OclValid_def (*‹?τ ⊨ ?P ≡ ?P ?τ = true ?τ›*) OclIsNew_def (*‹?X.oclIsNew() ≡ λτ. if (δ ?X) τ = true τ then ⌊⌊oid_of (?X τ) ∉ dom (heap (fst τ)) ∧ oid_of (?X τ) ∈ dom (heap (snd τ))⌋⌋ else invalid τ›*) σ₁_def (*‹σ₁ ≡ ⦇heap = [oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1000⌋ ⌊oid1⌋), oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1200⌋ ⊥), oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2600⌋ ⌊oid4⌋), oid4 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person5, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2300⌋ ⌊oid3⌋), oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9], assocs = λx. ⊥⦈›*) σ₁'_def (*‹σ₁' ≡ ⦇heap = [oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, oid2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, oid6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, oid7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9], assocs = λx. ⊥⦈›*) X⇩P⇩e⇩r⇩s⇩o⇩n7_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n7 ≡ λ_. ⌊⌊person7⌋⌋›*) person7_def (*‹person7 ≡ mk⇩O⇩c⇩l⇩A⇩n⇩y oid6 ⌊(⌊3200⌋, ⌊oid6⌋)⌋›*) oid0_def (*‹oid0 ≡ 0›*) oid1_def (*‹oid1 ≡ 1›*) oid2_def (*‹oid2 ≡ 2›*) oid3_def (*‹oid3 ≡ 3›*) oid4_def (*‹oid4 ≡ 4›*) oid5_def (*‹oid5 ≡ 5›*) oid6_def (*‹oid6 ≡ 6›*) oid8_def (*‹oid8 ≡ 8›*) oid_of_option_def (*‹oid_of ?x = oid_of (the ?x)›*) oid_of_type⇩O⇩c⇩l⇩A⇩n⇩y_def (*‹oid_of ?x = (case ?x of mk⇩O⇩c⇩l⇩A⇩n⇩y oid x ⇒ oid)›*)) Assert "⋀s⇩p⇩r⇩e s⇩p⇩o⇩s⇩t. (s⇩p⇩r⇩e,s⇩p⇩o⇩s⇩t) ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n8 <> X⇩P⇩e⇩r⇩s⇩o⇩n7)" Assert "⋀s⇩p⇩r⇩e s⇩p⇩o⇩s⇩t. (s⇩p⇩r⇩e,s⇩p⇩o⇩s⇩t) ⊨ not(υ(X⇩P⇩e⇩r⇩s⇩o⇩n8 .oclAsType(Person)))" Assert "⋀s⇩p⇩r⇩e s⇩p⇩o⇩s⇩t. (s⇩p⇩r⇩e,s⇩p⇩o⇩s⇩t) ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n8 .oclIsTypeOf(OclAny))" Assert "⋀s⇩p⇩r⇩e s⇩p⇩o⇩s⇩t. (s⇩p⇩r⇩e,s⇩p⇩o⇩s⇩t) ⊨ not(X⇩P⇩e⇩r⇩s⇩o⇩n8 .oclIsTypeOf(Person))" Assert "⋀s⇩p⇩r⇩e s⇩p⇩o⇩s⇩t. (s⇩p⇩r⇩e,s⇩p⇩o⇩s⇩t) ⊨ not(X⇩P⇩e⇩r⇩s⇩o⇩n8 .oclIsKindOf(Person))" Assert "⋀s⇩p⇩r⇩e s⇩p⇩o⇩s⇩t. (s⇩p⇩r⇩e,s⇩p⇩o⇩s⇩t) ⊨ (X⇩P⇩e⇩r⇩s⇩o⇩n8 .oclIsKindOf(OclAny))" lemma σ_modifiedonly: "(σ₁,σ₁') ⊨ (Set{ X⇩P⇩e⇩r⇩s⇩o⇩n1 .oclAsType(OclAny) , X⇩P⇩e⇩r⇩s⇩o⇩n2 .oclAsType(OclAny) ⌦‹, X⇩P⇩e⇩r⇩s⇩o⇩n3 .oclAsType(OclAny)› , X⇩P⇩e⇩r⇩s⇩o⇩n4 .oclAsType(OclAny) ⌦‹, X⇩P⇩e⇩r⇩s⇩o⇩n5 .oclAsType(OclAny)› , X⇩P⇩e⇩r⇩s⇩o⇩n6 .oclAsType(OclAny) ⌦‹, X⇩P⇩e⇩r⇩s⇩o⇩n7 .oclAsType(OclAny)› ⌦‹, X⇩P⇩e⇩r⇩s⇩o⇩n8 .oclAsType(OclAny)› ⌦‹, X⇩P⇩e⇩r⇩s⇩o⇩n9 .oclAsType(OclAny)›}->oclIsModifiedOnly())" apply (simp add: OclIsModifiedOnly_def (*‹?X->oclIsModifiedOnly() ≡ λ(σ, σ'). let X' = oid_of ` ⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?X (σ, σ'))⌉⌉; S = dom (heap σ) ∩ dom (heap σ') - X' in if (δ ?X) (σ, σ') = true (σ, σ') ∧ (∀x∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?X (σ, σ'))⌉⌉. x ≠ null) then ⌊⌊∀x∈S. heap σ x = heap σ' x⌋⌋ else invalid (σ, σ')›*) OclValid_def (*‹?τ ⊨ ?P ≡ ?P ?τ = true ?τ›*) oid0_def (*‹oid0 ≡ 0›*) oid1_def (*‹oid1 ≡ 1›*) oid2_def (*‹oid2 ≡ 2›*) oid3_def (*‹oid3 ≡ 3›*) oid4_def (*‹oid4 ≡ 4›*) oid5_def (*‹oid5 ≡ 5›*) oid6_def (*‹oid6 ≡ 6›*) oid7_def (*‹oid7 ≡ 7›*) oid8_def (*‹oid8 ≡ 8›*) X⇩P⇩e⇩r⇩s⇩o⇩n1_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n1 ≡ λ_. ⌊⌊person1⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n2_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n2 ≡ λ_. ⌊⌊person2⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n3_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n3 ≡ λ_. ⌊⌊person3⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n4_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n4 ≡ λ_. ⌊⌊person4⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n5_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n5 ≡ λ_. ⌊⌊person5⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n6_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n6 ≡ λ_. ⌊⌊person6⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n7_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n7 ≡ λ_. ⌊⌊person7⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n8_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n8 ≡ λ_. ⌊⌊person8⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n9_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n9 ≡ λ_. ⌊⌊person9⌋⌋›*) person1_def (*‹person1 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1300⌋ ⌊oid1⌋›*) person2_def (*‹person2 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1800⌋ ⌊oid1⌋›*) person3_def (*‹person3 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid2 ⊥ ⊥›*) person4_def (*‹person4 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2900⌋ ⊥›*) person5_def (*‹person5 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid4 ⌊3500⌋ ⊥›*) person6_def (*‹person6 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2500⌋ ⌊oid6⌋›*) person7_def (*‹person7 ≡ mk⇩O⇩c⇩l⇩A⇩n⇩y oid6 ⌊(⌊3200⌋, ⌊oid6⌋)⌋›*) person8_def (*‹person8 ≡ mk⇩O⇩c⇩l⇩A⇩n⇩y oid7 ⊥›*) person9_def (*‹person9 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid8 ⌊0⌋ ⊥›*) image_def (*‹?f ` ?A = {y. ∃x∈?A. y = ?f x}›*)) (*goal: ‹(σ₁, σ₁') ⊨ Set{X⇩P⇩e⇩r⇩s⇩o⇩n1 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n2 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n4 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n6 .oclAsType(OclAny)}->oclIsModifiedOnly()›*) apply (simp add: OclIncluding_rep_set (*‹?τ ⊨ δ ?S ⟹ ⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S->including⇩S⇩e⇩t(λ_. ⌊⌊?x⌋⌋) ?τ)⌉⌉ = insert ⌊⌊?x⌋⌋ ⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S ?τ)⌉⌉›*) mtSet_rep_set (*‹⌈⌈Rep_Set⇩b⇩a⇩s⇩e (Set{} ?τ)⌉⌉ = {}›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*)) (*goal: ‹((∀x∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (Set{λτ. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 5 ⌊(⌊2500⌋, ⌊6⌋)⌋⌋⌋, λτ. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 3 ⌊(⌊2900⌋, ⊥)⌋⌋⌋, λτ. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (Suc 0) ⌊(⌊1800⌋, ⌊Suc 0⌋)⌋⌋⌋, λτ. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 0 ⌊(⌊1300⌋, ⌊Suc 0⌋)⌋⌋⌋} (σ₁, σ₁'))⌉⌉. x ≠ null) ⟶ (∀x∈{0, Suc 0, 3, 5, 8} - {y. ∃x∈⌈⌈Rep_Set⇩b⇩a⇩s⇩e (Set{λτ. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 5 ⌊(⌊2500⌋, ⌊6⌋)⌋⌋⌋, λτ. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 3 ⌊(⌊2900⌋, ⊥)⌋⌋⌋, λτ. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (Suc 0) ⌊(⌊1800⌋, ⌊Suc 0⌋)⌋⌋⌋, λτ. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 0 ⌊(⌊1300⌋, ⌊Suc 0⌋)⌋⌋⌋} (σ₁, σ₁'))⌉⌉. y = oid_of x}. heap σ₁ x = heap σ₁' x)) ∧ (null ∈ ⌈⌈Rep_Set⇩b⇩a⇩s⇩e (Set{λτ. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 5 ⌊(⌊2500⌋, ⌊6⌋)⌋⌋⌋, λτ. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 3 ⌊(⌊2900⌋, ⊥)⌋⌋⌋, λτ. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (Suc 0) ⌊(⌊1800⌋, ⌊Suc 0⌋)⌋⌋⌋, λτ. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 0 ⌊(⌊1300⌋, ⌊Suc 0⌋)⌋⌋⌋} (σ₁, σ₁'))⌉⌉ ⟶ invalid (σ₁, σ₁') = ⌊⌊True⌋⌋)›*) apply (simp add: oid_of_option_def (*‹oid_of ?x = oid_of (the ?x)›*) oid_of_type⇩O⇩c⇩l⇩A⇩n⇩y_def (*‹oid_of ?x = (case ?x of mk⇩O⇩c⇩l⇩A⇩n⇩y oid x ⇒ oid)›*)) (*goal: ‹∀x::nat∈{0::nat, Suc (0::nat), 3::nat, 5::nat, 8::nat} - {y::nat. y = oid_of ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (5::nat) ⌊(⌊2500::int⌋, ⌊6::nat⌋)⌋⌋⌋ ∨ y = oid_of ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (3::nat) ⌊(⌊2900::int⌋, ⊥)⌋⌋⌋ ∨ y = oid_of ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (Suc (0::nat)) ⌊(⌊1800::int⌋, ⌊Suc (0::nat)⌋)⌋⌋⌋ ∨ y = oid_of ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (0::nat) ⌊(⌊1300::int⌋, ⌊Suc (0::nat)⌋)⌋⌋⌋}. heap σ₁ x = heap σ₁' x›*) apply clarsimp (*goal: ‹∀x∈{8} - {y. y = 5 ∨ y = 3 ∨ y = Suc 0 ∨ y = 0}. heap σ₁ x = heap σ₁' x›*) by (simp add: σ₁_def (*‹σ₁ ≡ ⦇heap = [oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1000⌋ ⌊oid1⌋), oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1200⌋ ⊥), oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2600⌋ ⌊oid4⌋), oid4 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person5, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2300⌋ ⌊oid3⌋), oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9], assocs = λx. ⊥⦈›*) σ₁'_def (*‹σ₁' ≡ ⦇heap = [oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, oid2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, oid6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, oid7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9], assocs = λx. ⊥⦈›*) oid0_def (*‹oid0 ≡ 0›*) oid1_def (*‹oid1 ≡ 1›*) oid2_def (*‹oid2 ≡ 2›*) oid3_def (*‹oid3 ≡ 3›*) oid4_def (*‹oid4 ≡ 4›*) oid5_def (*‹oid5 ≡ 5›*) oid6_def (*‹oid6 ≡ 6›*) oid7_def (*‹oid7 ≡ 7›*) oid8_def (*‹oid8 ≡ 8›*)) lemma "(σ₁,σ₁') ⊨ ((X⇩P⇩e⇩r⇩s⇩o⇩n9 @pre (λx. ⌊OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 x⌋)) ≜ X⇩P⇩e⇩r⇩s⇩o⇩n9)" by (simp add: OclSelf_at_pre_def (*‹?x@pre?H = OclSelf ?x ?H fst›*) σ₁_def (*‹σ₁ ≡ ⦇heap = [oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1000⌋ ⌊oid1⌋), oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1200⌋ ⊥), oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2600⌋ ⌊oid4⌋), oid4 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person5, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2300⌋ ⌊oid3⌋), oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9], assocs = λx. ⊥⦈›*) oid_of_option_def (*‹oid_of ?x = oid_of (the ?x)›*) oid_of_type⇩P⇩e⇩r⇩s⇩o⇩n_def (*‹oid_of ?x = (case ?x of mk⇩P⇩e⇩r⇩s⇩o⇩n oid x xa ⇒ oid)›*) X⇩P⇩e⇩r⇩s⇩o⇩n9_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n9 ≡ λ_. ⌊⌊person9⌋⌋›*) person9_def (*‹person9 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid8 ⌊0⌋ ⊥›*) oid8_def (*‹oid8 ≡ 8›*) OclValid_def (*‹?τ ⊨ ?P ≡ ?P ?τ = true ?τ›*) StrongEq_def (*‹?X ≜ ?Y ≡ λτ. ⌊⌊?X τ = ?Y τ⌋⌋›*) OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄_def (*‹OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 = (λu. case u of in⇩P⇩e⇩r⇩s⇩o⇩n p ⇒ ⌊p⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥) ⇒ ⊥ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋) ⇒ ⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋)›*)) lemma "(σ₁,σ₁') ⊨ ((X⇩P⇩e⇩r⇩s⇩o⇩n9 @post (λx. ⌊OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 x⌋)) ≜ X⇩P⇩e⇩r⇩s⇩o⇩n9)" by (simp add: OclSelf_at_post_def (*‹?x@post?H = OclSelf ?x ?H snd›*) σ₁'_def (*‹σ₁' ≡ ⦇heap = [oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, oid2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, oid6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, oid7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9], assocs = λx. ⊥⦈›*) oid_of_option_def (*‹oid_of ?x = oid_of (the ?x)›*) oid_of_type⇩P⇩e⇩r⇩s⇩o⇩n_def (*‹oid_of ?x = (case ?x of mk⇩P⇩e⇩r⇩s⇩o⇩n oid x xa ⇒ oid)›*) X⇩P⇩e⇩r⇩s⇩o⇩n9_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n9 ≡ λ_. ⌊⌊person9⌋⌋›*) person9_def (*‹person9 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid8 ⌊0⌋ ⊥›*) oid8_def (*‹oid8 ≡ 8›*) OclValid_def (*‹?τ ⊨ ?P ≡ ?P ?τ = true ?τ›*) StrongEq_def (*‹?X ≜ ?Y ≡ λτ. ⌊⌊?X τ = ?Y τ⌋⌋›*) OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄_def (*‹OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 = (λu. case u of in⇩P⇩e⇩r⇩s⇩o⇩n p ⇒ ⌊p⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥) ⇒ ⊥ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋) ⇒ ⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋)›*)) lemma "(σ₁,σ₁') ⊨ (((X⇩P⇩e⇩r⇩s⇩o⇩n9 .oclAsType(OclAny)) @pre (λx. ⌊OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 x⌋)) ≜ ((X⇩P⇩e⇩r⇩s⇩o⇩n9 .oclAsType(OclAny)) @post (λx. ⌊OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 x⌋)))" proof (-) (*goal: ‹(σ₁, σ₁') ⊨ X⇩P⇩e⇩r⇩s⇩o⇩n9 .oclAsType(OclAny)@preλx. ⌊OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 x⌋ ≜ X⇩P⇩e⇩r⇩s⇩o⇩n9 .oclAsType(OclAny)@postλx. ⌊OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 x⌋›*) have including4: "⋀a b c d τ. Set{λτ. ⌊⌊a⌋⌋, λτ. ⌊⌊b⌋⌋, λτ. ⌊⌊c⌋⌋, λτ. ⌊⌊d⌋⌋} τ = Abs_Set⇩b⇩a⇩s⇩e ⌊⌊ {⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋} ⌋⌋" apply (subst abs_rep_simp'[symmetric] (*‹?τ ⊨ δ ?S ⟹ ?S ?τ = Abs_Set⇩b⇩a⇩s⇩e ⌊⌊⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S ?τ)⌉⌉⌋⌋›*)) (*goals: 1. ‹⋀a b c d τ. τ ⊨ δ Set{λτ. ⌊⌊a⌋⌋, λτ. ⌊⌊b⌋⌋, λτ. ⌊⌊c⌋⌋, λτ. ⌊⌊d⌋⌋}› 2. ‹⋀a b c d τ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊⌈⌈Rep_Set⇩b⇩a⇩s⇩e (Set{λτ. ⌊⌊a⌋⌋, λτ. ⌊⌊b⌋⌋, λτ. ⌊⌊c⌋⌋, λτ. ⌊⌊d⌋⌋} τ)⌉⌉⌋⌋ = Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: OclIncluding_rep_set (*‹?τ::?'a state × ?'a state ⊨ δ (?S::?'a state × ?'a state ⇒ Set(⟨⟨?'b⟩⇩⊥⟩⇩⊥)) ⟹ ⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S->including⇩S⇩e⇩t(λ_::?'a state × ?'a state. ⌊⌊?x::?'b⌋⌋) ?τ)⌉⌉ = insert ⌊⌊?x⌋⌋ ⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S ?τ)⌉⌉›*) mtSet_rep_set (*‹⌈⌈Rep_Set⇩b⇩a⇩s⇩e (Set{} (?τ::?'b state × ?'b state))⌉⌉ = {}›*)) (*goal: ‹⋀a b c d τ. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊⌈⌈Rep_Set⇩b⇩a⇩s⇩e (Set{λτ. ⌊⌊a⌋⌋, λτ. ⌊⌊b⌋⌋, λτ. ⌊⌊c⌋⌋, λτ. ⌊⌊d⌋⌋} τ)⌉⌉⌋⌋ = Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋›*) apply (rule arg_cong[of _ _ "λx. (Abs_Set⇩b⇩a⇩s⇩e(⌊⌊ x ⌋⌋))"] (*‹(?x::?'c1 set) = (?y::?'c1 set) ⟹ Abs_Set⇩b⇩a⇩s⇩e ⌊⌊?x⌋⌋ = Abs_Set⇩b⇩a⇩s⇩e ⌊⌊?y⌋⌋›*)) (*goal: ‹⋀(a::'a) (b::'a) (c::'a) d::'a. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊d⌋⌋, ⌊⌊c⌋⌋, ⌊⌊b⌋⌋, ⌊⌊a⌋⌋}⌋⌋ = Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋›*) apply auto (*proven 2 subgoals*) . have excluding1: "⋀S a b c d e τ. (λ_. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊ {⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋} ⌋⌋)->excluding⇩S⇩e⇩t(λτ. ⌊⌊e⌋⌋) τ = Abs_Set⇩b⇩a⇩s⇩e ⌊⌊ {⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋} - {⌊⌊e⌋⌋} ⌋⌋" apply (simp add: UML_Set.OclExcluding_def (*‹?x->excluding⇩S⇩e⇩t(?y) = (λτ. if (δ ?x) τ = true τ ∧ (υ ?y) τ = true τ then Abs_Set⇩b⇩a⇩s⇩e ⌊⌊⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?x τ)⌉⌉ - {?y τ}⌋⌋ else ⊥)›*)) (*goal: ‹⋀S a b c d e τ. λ_. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋->excluding⇩S⇩e⇩t(λτ. ⌊⌊e⌋⌋) τ = Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋} - {⌊⌊e⌋⌋}⌋⌋›*) apply (simp add: defined_def (*‹δ (?X::?'𝔄 state × ?'𝔄 state ⇒ ?'a) ≡ λτ::?'𝔄 state × ?'𝔄 state. if ?X τ = ⊥ τ ∨ ?X τ = null τ then false τ else true τ›*) OclValid_def (*‹?τ::?'𝔄 state × ?'𝔄 state ⊨ ?P::?'𝔄 state × ?'𝔄 state ⇒ ⟨⟨bool⟩⇩⊥⟩⇩⊥ ≡ ?P ?τ = true ?τ›*) false_def (*‹false ≡ λτ::?'𝔄 state × ?'𝔄 state. ⌊⌊False⌋⌋›*) true_def (*‹true ≡ λτ::?'𝔄 state × ?'𝔄 state. ⌊⌊True⌋⌋›*) bot_fun_def (*‹⊥ ≡ λx::?'a. ⊥›*) bot_Set⇩b⇩a⇩s⇩e_def (*‹⊥ ≡ Abs_Set⇩b⇩a⇩s⇩e ⊥›*) null_fun_def (*‹null ≡ λx::?'a. null›*) null_Set⇩b⇩a⇩s⇩e_def (*‹null ≡ Abs_Set⇩b⇩a⇩s⇩e ⌊⊥⌋›*)) (*goal: ‹⋀(a::'b) (b::'b) (c::'b) (d::'b) (e::'b) τ::'c state × 'c state. ((δ (λ_::'c state × 'c state. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋)) τ = true τ ⟶ Abs_Set⇩b⇩a⇩s⇩e ⌊⌊⌈⌈Rep_Set⇩b⇩a⇩s⇩e (Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋)⌉⌉ - {⌊⌊e⌋⌋}⌋⌋ = Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋} - {⌊⌊e⌋⌋}⌋⌋) ∧ ((δ (λ_::'c state × 'c state. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋)) τ ≠ true τ ⟶ ⊥ = Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋} - {⌊⌊e⌋⌋}⌋⌋)›*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹⋀a b c d e. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋ = Abs_Set⇩b⇩a⇩s⇩e ⊥ ⟶ Abs_Set⇩b⇩a⇩s⇩e ⊥ = Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋} - {⌊⌊e⌋⌋}⌋⌋› 2. ‹⋀a b c d e. (Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋ = Abs_Set⇩b⇩a⇩s⇩e ⌊⊥⌋ ⟶ Abs_Set⇩b⇩a⇩s⇩e ⊥ = Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋} - {⌊⌊e⌋⌋}⌋⌋) ∧ (Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋ ≠ Abs_Set⇩b⇩a⇩s⇩e ⊥ ∧ Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋ ≠ Abs_Set⇩b⇩a⇩s⇩e ⌊⊥⌋ ⟶ Abs_Set⇩b⇩a⇩s⇩e ⌊⌊⌈⌈Rep_Set⇩b⇩a⇩s⇩e (Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋)⌉⌉ - {⌊⌊e⌋⌋}⌋⌋ = Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋} - {⌊⌊e⌋⌋}⌋⌋)› discuss goal 1*) apply (rule impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*top goal: ‹⋀a b c d e. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋ = Abs_Set⇩b⇩a⇩s⇩e ⊥ ⟶ Abs_Set⇩b⇩a⇩s⇩e ⊥ = Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋} - {⌊⌊e⌋⌋}⌋⌋› and 1 goal remains*) apply (subst (asm) Abs_Set⇩b⇩a⇩s⇩e_inject (*‹⟦?x ∈ {X. X = ⊥ ∨ X = null ∨ (∀x∈⌈⌈X⌉⌉. x ≠ ⊥)}; ?y ∈ {X. X = ⊥ ∨ X = null ∨ (∀x∈⌈⌈X⌉⌉. x ≠ ⊥)}⟧ ⟹ (Abs_Set⇩b⇩a⇩s⇩e ?x = Abs_Set⇩b⇩a⇩s⇩e ?y) = (?x = ?y)›*)) (*goals: 1. ‹⋀(a::'b) (b::'b) (c::'b) (d::'b) e::'b. ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋ ∈ {X::⟨⟨⟨⟨'b⟩⇩⊥⟩⇩⊥ set⟩⇩⊥⟩⇩⊥. X = ⊥ ∨ X = null ∨ (∀x::⟨⟨'b⟩⇩⊥⟩⇩⊥∈⌈⌈X⌉⌉. x ≠ ⊥)}› 2. ‹⋀(a::'b) (b::'b) (c::'b) (d::'b) e::'b. ⊥ ∈ {X::⟨⟨⟨⟨'b⟩⇩⊥⟩⇩⊥ set⟩⇩⊥⟩⇩⊥. X = ⊥ ∨ X = null ∨ (∀x::⟨⟨'b⟩⇩⊥⟩⇩⊥∈⌈⌈X⌉⌉. x ≠ ⊥)}› 3. ‹⋀(a::'b) (b::'b) (c::'b) (d::'b) e::'b. ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋ = ⊥ ⟹ Abs_Set⇩b⇩a⇩s⇩e ⊥ = Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋} - {⌊⌊e⌋⌋}⌋⌋› discuss goal 1*) apply (simp add: bot_option_def (*‹⊥ ≡ ⊥›*)) (*discuss goal 2*) apply (simp add: bot_option_def (*‹⊥ ≡ ⊥›*)) (*discuss goal 3*) apply (simp add: bot_option_def (*‹⊥ ≡ ⊥›*)) (*proven 3 subgoals*) (*discuss goal 2*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹⋀a b c d e. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋ = Abs_Set⇩b⇩a⇩s⇩e ⌊⊥⌋ ⟶ Abs_Set⇩b⇩a⇩s⇩e ⊥ = Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋} - {⌊⌊e⌋⌋}⌋⌋› 2. ‹⋀a b c d e. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋ ≠ Abs_Set⇩b⇩a⇩s⇩e ⊥ ∧ Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋ ≠ Abs_Set⇩b⇩a⇩s⇩e ⌊⊥⌋ ⟶ Abs_Set⇩b⇩a⇩s⇩e ⌊⌊⌈⌈Rep_Set⇩b⇩a⇩s⇩e (Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋)⌉⌉ - {⌊⌊e⌋⌋}⌋⌋ = Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋} - {⌊⌊e⌋⌋}⌋⌋› discuss goal 1*) apply (rule impI (*‹(?P::bool ⟹ ?Q::bool) ⟹ ?P ⟶ ?Q›*)) (*top goal: ‹⋀a b c d e. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋ = Abs_Set⇩b⇩a⇩s⇩e ⌊⊥⌋ ⟶ Abs_Set⇩b⇩a⇩s⇩e ⊥ = Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋} - {⌊⌊e⌋⌋}⌋⌋› and 1 goal remains*) apply (subst (asm) Abs_Set⇩b⇩a⇩s⇩e_inject (*‹⟦?x ∈ {X. X = ⊥ ∨ X = null ∨ (∀x∈⌈⌈X⌉⌉. x ≠ ⊥)}; ?y ∈ {X. X = ⊥ ∨ X = null ∨ (∀x∈⌈⌈X⌉⌉. x ≠ ⊥)}⟧ ⟹ (Abs_Set⇩b⇩a⇩s⇩e ?x = Abs_Set⇩b⇩a⇩s⇩e ?y) = (?x = ?y)›*)) (*goals: 1. ‹⋀a b c d e. ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋ ∈ {X. X = ⊥ ∨ X = null ∨ (∀x∈⌈⌈X⌉⌉. x ≠ ⊥)}› 2. ‹⋀a b c d e. ⌊⊥⌋ ∈ {X. X = ⊥ ∨ X = null ∨ (∀x∈⌈⌈X⌉⌉. x ≠ ⊥)}› 3. ‹⋀a b c d e. ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋ = ⌊⊥⌋ ⟹ Abs_Set⇩b⇩a⇩s⇩e ⊥ = Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋} - {⌊⌊e⌋⌋}⌋⌋› discuss goal 1*) apply (simp add: bot_option_def (*‹⊥ ≡ ⊥›*) null_option_def (*‹null ≡ ⌊⊥⌋›*)) (*discuss goal 2*) apply (simp add: bot_option_def (*‹⊥ ≡ ⊥›*) null_option_def (*‹null ≡ ⌊⊥⌋›*)) (*discuss goal 3*) apply (simp add: bot_option_def (*‹⊥ ≡ ⊥›*) null_option_def (*‹null ≡ ⌊⊥⌋›*)) (*proven 3 subgoals*) (*discuss goal 2*) apply (subst Abs_Set⇩b⇩a⇩s⇩e_inverse (*‹?y ∈ {X. X = ⊥ ∨ X = null ∨ (∀x∈⌈⌈X⌉⌉. x ≠ ⊥)} ⟹ Rep_Set⇩b⇩a⇩s⇩e (Abs_Set⇩b⇩a⇩s⇩e ?y) = ?y›*)) (*goals: 1. ‹⋀a b c d e. ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋ ∈ {X. X = ⊥ ∨ X = null ∨ (∀x∈⌈⌈X⌉⌉. x ≠ ⊥)}› 2. ‹⋀a b c d e. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋ ≠ Abs_Set⇩b⇩a⇩s⇩e ⊥ ∧ Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋ ≠ Abs_Set⇩b⇩a⇩s⇩e ⌊⊥⌋ ⟶ Abs_Set⇩b⇩a⇩s⇩e ⌊⌊⌈⌈⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋}⌋⌋⌉⌉ - {⌊⌊e⌋⌋}⌋⌋ = Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊a⌋⌋, ⌊⌊b⌋⌋, ⌊⌊c⌋⌋, ⌊⌊d⌋⌋} - {⌊⌊e⌋⌋}⌋⌋› discuss goal 1*) apply (simp add: bot_option_def (*‹⊥ ≡ ⊥›*)) (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . show "?thesis" (*goal: ‹(σ₁, σ₁') ⊨ X⇩P⇩e⇩r⇩s⇩o⇩n9 .oclAsType(OclAny)@preλx. ⌊OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 x⌋ ≜ X⇩P⇩e⇩r⇩s⇩o⇩n9 .oclAsType(OclAny)@postλx. ⌊OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 x⌋›*) apply (rule framing[where X = "Set{ X⇩P⇩e⇩r⇩s⇩o⇩n1 .oclAsType(OclAny) , X⇩P⇩e⇩r⇩s⇩o⇩n2 .oclAsType(OclAny) ⌦‹, X⇩P⇩e⇩r⇩s⇩o⇩n3 .oclAsType(OclAny)› , X⇩P⇩e⇩r⇩s⇩o⇩n4 .oclAsType(OclAny) ⌦‹, X⇩P⇩e⇩r⇩s⇩o⇩n5 .oclAsType(OclAny)› , X⇩P⇩e⇩r⇩s⇩o⇩n6 .oclAsType(OclAny) ⌦‹, X⇩P⇩e⇩r⇩s⇩o⇩n7 .oclAsType(OclAny)› ⌦‹, X⇩P⇩e⇩r⇩s⇩o⇩n8 .oclAsType(OclAny)› ⌦‹, X⇩P⇩e⇩r⇩s⇩o⇩n9 .oclAsType(OclAny)›}" ] (*‹⟦?τ::𝔄 state × 𝔄 state ⊨ Set{X⇩P⇩e⇩r⇩s⇩o⇩n1 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n2 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n4 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n6 .oclAsType(OclAny)}->excluding⇩S⇩e⇩t(?x::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥)->oclIsModifiedOnly(); ?τ ⊨ Set{X⇩P⇩e⇩r⇩s⇩o⇩n1 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n2 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n4 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n6 .oclAsType(OclAny)}->forAll⇩S⇩e⇩t((a::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥)|not (StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t ?x a))⟧ ⟹ ?τ ⊨ ?x@pre?P::𝔄 ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥ ≜ ?x@post?P›*)) (*goals: 1. ‹(σ₁, σ₁') ⊨ Set{X⇩P⇩e⇩r⇩s⇩o⇩n1 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n2 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n4 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n6 .oclAsType(OclAny)}->excluding⇩S⇩e⇩t(X⇩P⇩e⇩r⇩s⇩o⇩n9 .oclAsType(OclAny))->oclIsModifiedOnly()› 2. ‹(σ₁, σ₁') ⊨ Set{X⇩P⇩e⇩r⇩s⇩o⇩n1 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n2 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n4 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n6 .oclAsType(OclAny)}->forAll⇩S⇩e⇩t((a::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥)|not (StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t X⇩P⇩e⇩r⇩s⇩o⇩n9 .oclAsType(OclAny) a))› discuss goal 1*) apply (cut_tac σ_modifiedonly (*‹(σ₁, σ₁') ⊨ Set{X⇩P⇩e⇩r⇩s⇩o⇩n1 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n2 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n4 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n6 .oclAsType(OclAny)}->oclIsModifiedOnly()›*)) (*top goal: ‹(σ₁, σ₁') ⊨ Set{X⇩P⇩e⇩r⇩s⇩o⇩n1 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n2 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n4 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n6 .oclAsType(OclAny)}->excluding⇩S⇩e⇩t(X⇩P⇩e⇩r⇩s⇩o⇩n9 .oclAsType(OclAny))->oclIsModifiedOnly()› and 1 goal remains*) apply (simp only: OclValid_def (*‹?τ::?'𝔄 state × ?'𝔄 state ⊨ ?P::?'𝔄 state × ?'𝔄 state ⇒ ⟨⟨bool⟩⇩⊥⟩⇩⊥ ≡ ?P ?τ = true ?τ›*) X⇩P⇩e⇩r⇩s⇩o⇩n1_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n1 ≡ λ_::𝔄 state × 𝔄 state. ⌊⌊person1⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n2_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n2 ≡ λ_::𝔄 state × 𝔄 state. ⌊⌊person2⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n3_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n3 ≡ λ_::𝔄 state × 𝔄 state. ⌊⌊person3⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n4_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n4 ≡ λ_::𝔄 state × 𝔄 state. ⌊⌊person4⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n5_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n5 ≡ λ_::𝔄 state × 𝔄 state. ⌊⌊person5⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n6_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n6 ≡ λ_::𝔄 state × 𝔄 state. ⌊⌊person6⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n7_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n7 ≡ λ_::𝔄 state × 𝔄 state. ⌊⌊person7⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n8_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n8 ≡ λ_::𝔄 state × 𝔄 state. ⌊⌊person8⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n9_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n9 ≡ λ_::𝔄 state × 𝔄 state. ⌊⌊person9⌋⌋›*) person1_def (*‹person1 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1300::int⌋ ⌊oid1⌋›*) person2_def (*‹person2 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1800::int⌋ ⌊oid1⌋›*) person3_def (*‹person3 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid2 ⊥ ⊥›*) person4_def (*‹person4 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2900::int⌋ ⊥›*) person5_def (*‹person5 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid4 ⌊3500::int⌋ ⊥›*) person6_def (*‹person6 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2500::int⌋ ⌊oid6⌋›*) person7_def (*‹person7 ≡ mk⇩O⇩c⇩l⇩A⇩n⇩y oid6 ⌊(⌊3200::int⌋, ⌊oid6⌋)⌋›*) person8_def (*‹person8 ≡ mk⇩O⇩c⇩l⇩A⇩n⇩y oid7 ⊥›*) person9_def (*‹person9 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid8 ⌊0::int⌋ ⊥›*) OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_Person (*‹?X::𝔄 state × 𝔄 state ⇒ ⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥ .oclAsType(OclAny) ≡ λτ::𝔄 state × 𝔄 state. case ?X τ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n (oid::nat) (a::⟨int⟩⇩⊥) (b::⟨nat⟩⇩⊥)⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋›*)) (*top goal: ‹(σ₁, σ₁') ⊨ Set{X⇩P⇩e⇩r⇩s⇩o⇩n1 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n2 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n4 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n6 .oclAsType(OclAny)}->oclIsModifiedOnly() ⟹ (σ₁, σ₁') ⊨ Set{X⇩P⇩e⇩r⇩s⇩o⇩n1 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n2 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n4 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n6 .oclAsType(OclAny)}->excluding⇩S⇩e⇩t(X⇩P⇩e⇩r⇩s⇩o⇩n9 .oclAsType(OclAny))->oclIsModifiedOnly()› and 1 goal remains*) apply (subst cp_OclIsModifiedOnly (*‹?X->oclIsModifiedOnly() ?τ = λ_. ?X ?τ->oclIsModifiedOnly() ?τ›*)) (*top goal: ‹Set{λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1300⌋ ⌊oid1⌋⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋, λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1800⌋ ⌊oid1⌋⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋, λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2900⌋ ⊥⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋, λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2500⌋ ⌊oid6⌋⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋}->oclIsModifiedOnly() (σ₁, σ₁') = true (σ₁, σ₁') ⟹ Set{λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1300⌋ ⌊oid1⌋⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋, λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1800⌋ ⌊oid1⌋⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋, λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2900⌋ ⊥⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋, λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2500⌋ ⌊oid6⌋⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋}->excluding⇩S⇩e⇩t(λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid8 ⌊0⌋ ⊥⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋)->oclIsModifiedOnly() (σ₁, σ₁') = true (σ₁, σ₁')› and 1 goal remains*) apply (subst UML_Set.OclExcluding.cp0 (*‹?X->excluding⇩S⇩e⇩t(?Y) ?τ = λ_. ?X ?τ->excluding⇩S⇩e⇩t(λ_. ?Y ?τ) ?τ›*)) (*top goal: ‹Set{λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1300⌋ ⌊oid1⌋⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋, λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1800⌋ ⌊oid1⌋⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋, λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2900⌋ ⊥⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋, λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2500⌋ ⌊oid6⌋⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋}->oclIsModifiedOnly() (σ₁, σ₁') = true (σ₁, σ₁') ⟹ λ_. Set{λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1300⌋ ⌊oid1⌋⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋, λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1800⌋ ⌊oid1⌋⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋, λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2900⌋ ⊥⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋, λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2500⌋ ⌊oid6⌋⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋}->excluding⇩S⇩e⇩t(λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid8 ⌊0⌋ ⊥⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋) (σ₁, σ₁')->oclIsModifiedOnly() (σ₁, σ₁') = true (σ₁, σ₁')› and 1 goal remains*) apply (subst (asm) cp_OclIsModifiedOnly (*‹?X->oclIsModifiedOnly() ?τ = λ_. ?X ?τ->oclIsModifiedOnly() ?τ›*)) (*top goal: ‹Set{λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1300⌋ ⌊oid1⌋⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋, λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1800⌋ ⌊oid1⌋⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋, λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2900⌋ ⊥⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋, λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2500⌋ ⌊oid6⌋⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋}->oclIsModifiedOnly() (σ₁, σ₁') = true (σ₁, σ₁') ⟹ λ_. λ_. Set{λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1300⌋ ⌊oid1⌋⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋, λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1800⌋ ⌊oid1⌋⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋, λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2900⌋ ⊥⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋, λτ. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2500⌋ ⌊oid6⌋⌋⌋ of ⊥ ⇒ invalid τ | ⌊⊥⌋ ⇒ null τ | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋} (σ₁, σ₁')->excluding⇩S⇩e⇩t(λ_. case ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid8 ⌊0⌋ ⊥⌋⌋ of ⊥ ⇒ invalid (σ₁, σ₁') | ⌊⊥⌋ ⇒ null (σ₁, σ₁') | ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋⌋ ⇒ ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋⌋⌋) (σ₁, σ₁')->oclIsModifiedOnly() (σ₁, σ₁') = true (σ₁, σ₁')› and 1 goal remains*) apply (simp add: including4 (*‹Set{λτ. ⌊⌊?a⌋⌋, λτ. ⌊⌊?b⌋⌋, λτ. ⌊⌊?c⌋⌋, λτ. ⌊⌊?d⌋⌋} ?τ = Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊?a⌋⌋, ⌊⌊?b⌋⌋, ⌊⌊?c⌋⌋, ⌊⌊?d⌋⌋}⌋⌋›*) excluding1 (*‹λ_. Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊?a1⌋⌋, ⌊⌊?b1⌋⌋, ⌊⌊?c1⌋⌋, ⌊⌊?d1⌋⌋}⌋⌋->excluding⇩S⇩e⇩t(λτ. ⌊⌊?e1⌋⌋) ?τ1 = Abs_Set⇩b⇩a⇩s⇩e ⌊⌊{⌊⌊?a1⌋⌋, ⌊⌊?b1⌋⌋, ⌊⌊?c1⌋⌋, ⌊⌊?d1⌋⌋} - {⌊⌊?e1⌋⌋}⌋⌋›*)) (*discuss goal 2*) apply (simp only: X⇩P⇩e⇩r⇩s⇩o⇩n1_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n1 ≡ λ_. ⌊⌊person1⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n2_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n2 ≡ λ_. ⌊⌊person2⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n3_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n3 ≡ λ_. ⌊⌊person3⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n4_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n4 ≡ λ_. ⌊⌊person4⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n5_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n5 ≡ λ_. ⌊⌊person5⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n6_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n6 ≡ λ_. ⌊⌊person6⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n7_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n7 ≡ λ_. ⌊⌊person7⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n8_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n8 ≡ λ_. ⌊⌊person8⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n9_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n9 ≡ λ_. ⌊⌊person9⌋⌋›*) person1_def (*‹person1 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1300⌋ ⌊oid1⌋›*) person2_def (*‹person2 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1800⌋ ⌊oid1⌋›*) person3_def (*‹person3 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid2 ⊥ ⊥›*) person4_def (*‹person4 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2900⌋ ⊥›*) person5_def (*‹person5 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid4 ⌊3500⌋ ⊥›*) person6_def (*‹person6 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2500⌋ ⌊oid6⌋›*) person7_def (*‹person7 ≡ mk⇩O⇩c⇩l⇩A⇩n⇩y oid6 ⌊(⌊3200⌋, ⌊oid6⌋)⌋›*) person8_def (*‹person8 ≡ mk⇩O⇩c⇩l⇩A⇩n⇩y oid7 ⊥›*) person9_def (*‹person9 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid8 ⌊0⌋ ⊥›*)) (*goal: ‹(σ₁, σ₁') ⊨ Set{X⇩P⇩e⇩r⇩s⇩o⇩n1 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n2 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n4 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n6 .oclAsType(OclAny)}->forAll⇩S⇩e⇩t(a|not (StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t X⇩P⇩e⇩r⇩s⇩o⇩n9 .oclAsType(OclAny) a))›*) apply (simp add: OclIncluding_rep_set (*‹?τ ⊨ δ ?S ⟹ ⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S->including⇩S⇩e⇩t(λ_. ⌊⌊?x⌋⌋) ?τ)⌉⌉ = insert ⌊⌊?x⌋⌋ ⌈⌈Rep_Set⇩b⇩a⇩s⇩e (?S ?τ)⌉⌉›*) mtSet_rep_set (*‹⌈⌈Rep_Set⇩b⇩a⇩s⇩e (Set{} ?τ)⌉⌉ = {}›*) oid0_def (*‹oid0 ≡ 0›*) oid1_def (*‹oid1 ≡ 1›*) oid2_def (*‹oid2 ≡ 2›*) oid3_def (*‹oid3 ≡ 3›*) oid4_def (*‹oid4 ≡ 4›*) oid5_def (*‹oid5 ≡ 5›*) oid6_def (*‹oid6 ≡ 6›*) oid7_def (*‹oid7 ≡ 7›*) oid8_def (*‹oid8 ≡ 8›*)) (*goal: ‹(σ₁, σ₁') ⊨ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1300⌋ ⌊oid1⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1800⌋ ⌊oid1⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2900⌋ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2500⌋ ⌊oid6⌋⌋⌋ .oclAsType(OclAny)}->forAll⇩S⇩e⇩t(a|not (StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny) a))›*) apply (simp add: StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t_def (*‹StrictRefEq⇩O⇩b⇩j⇩e⇩c⇩t (?x::?'𝔄 state × ?'𝔄 state ⇒ ?'a::{null,object}) (?y::?'𝔄 state × ?'𝔄 state ⇒ ?'a::{null,object}) ≡ λτ::?'𝔄 state × ?'𝔄 state. if (υ ?x) τ = true τ ∧ (υ ?y) τ = true τ then if ?x τ = null ∨ ?y τ = null then ⌊⌊?x τ = null ∧ ?y τ = null⌋⌋ else ⌊⌊oid_of (?x τ) = oid_of (?y τ)⌋⌋ else invalid τ›*) oid_of_option_def (*‹oid_of (?x::⟨?'a::object⟩⇩⊥) = oid_of (the ?x)›*) oid_of_type⇩O⇩c⇩l⇩A⇩n⇩y_def (*‹oid_of (?x::type⇩O⇩c⇩l⇩A⇩n⇩y) = (case ?x of mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) (x::⟨⟨int⟩⇩⊥ × ⟨nat⟩⇩⊥⟩⇩⊥) ⇒ oid)›*) OclNot_def (*‹not (?X::?'𝔄 state × ?'𝔄 state ⇒ ⟨⟨bool⟩⇩⊥⟩⇩⊥) ≡ λτ::?'𝔄 state × ?'𝔄 state. case ?X τ of ⊥ ⇒ ⊥ | ⌊⊥⌋ ⇒ ⌊⊥⌋ | ⌊⌊x::bool⌋⌋ ⇒ ⌊⌊¬ x⌋⌋›*) OclValid_def (*‹?τ::?'𝔄 state × ?'𝔄 state ⊨ ?P::?'𝔄 state × ?'𝔄 state ⇒ ⟨⟨bool⟩⇩⊥⟩⇩⊥ ≡ ?P ?τ = true ?τ›*) null_option_def (*‹null ≡ ⌊⊥⌋›*) bot_option_def (*‹⊥ ≡ ⊥›*)) (*proven 2 subgoals*) . qed lemma perm_σ₁' : "σ₁' = ⦇ heap = Map.empty (oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, oid7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, oid6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, ⌦‹oid4› oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, oid2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1) , assocs = assocs σ₁' ⦈" proof (-) (*goal: ‹σ₁' = ⦇heap = [oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, oid7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, oid6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, oid2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1], assocs = assocs σ₁'⦈›*) note P = fun_upd_twist (*‹?a ≠ ?c ⟹ ?m(?a := ?b, ?c := ?d) = ?m(?c := ?d, ?a := ?b)›*) show "?thesis" (*goal: ‹σ₁' = ⦇heap = [oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, oid7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, oid6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, oid2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1], assocs = assocs σ₁'⦈›*) apply (simp add: σ₁'_def (*‹σ₁' ≡ ⦇heap = [oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, oid2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, oid6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, oid7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9], assocs = λx::nat. ⊥⦈›*) oid0_def (*‹oid0 ≡ 0::?'a::zero›*) oid1_def (*‹oid1 ≡ 1::?'a::one›*) oid2_def (*‹oid2 ≡ 2::?'a::numeral›*) oid3_def (*‹oid3 ≡ 3::?'a::numeral›*) oid4_def (*‹oid4 ≡ 4::?'a::numeral›*) oid5_def (*‹oid5 ≡ 5::?'a::numeral›*) oid6_def (*‹oid6 ≡ 6::?'a::numeral›*) oid7_def (*‹oid7 ≡ 7::?'a::numeral›*) oid8_def (*‹oid8 ≡ 8::?'a::numeral›*)) (*goal: ‹σ₁' = ⦇heap = [oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, oid7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, oid6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, oid2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1], assocs = assocs σ₁'⦈›*) apply (subst (1) P (*‹?a ≠ ?c ⟹ ?m(?a := ?b, ?c := ?d) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹0 ≠ Suc 0› 2. ‹[Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9] = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (2) P (*‹(?a::?'a) ≠ (?c::?'a) ⟹ (?m::?'a ⇒ ?'b)(?a := ?b::?'b, ?c := ?d::?'b) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹0 ≠ 2› 2. ‹[Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9] = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (1) P (*‹?a ≠ ?c ⟹ ?m(?a := ?b, ?c := ?d) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹Suc 0 ≠ 2› 2. ‹[2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9] = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (3) P (*‹?a ≠ ?c ⟹ ?m(?a := ?b, ?c := ?d) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹(0::nat) ≠ (3::nat)› 2. ‹[2::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc (0::nat) ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 3::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 0::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, 5::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 6::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9] = [8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc (0::nat) ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (2) P (*‹(?a::?'a::type) ≠ (?c::?'a::type) ⟹ (?m::?'a::type ⇒ ?'b::type)(?a := ?b::?'b::type, ?c := ?d::?'b::type) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹Suc 0 ≠ 3› 2. ‹[2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9] = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (1) P (*‹?a ≠ ?c ⟹ ?m(?a := ?b, ?c := ?d) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹2 ≠ 3› 2. ‹[3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9] = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (4) P (*‹?a ≠ ?c ⟹ ?m(?a := ?b, ?c := ?d) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹0 ≠ 5› 2. ‹[3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9] = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (3) P (*‹?a ≠ ?c ⟹ ?m(?a := ?b, ?c := ?d) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹Suc 0 ≠ 5› 2. ‹[3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9] = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (2) P (*‹(?a::?'a) ≠ (?c::?'a) ⟹ (?m::?'a ⇒ ?'b)(?a := ?b::?'b, ?c := ?d::?'b) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹(2::nat) ≠ (5::nat)› 2. ‹[3::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 5::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 2::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc (0::nat) ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, 6::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9] = [8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc (0::nat) ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (1) P (*‹(?a::?'a::type) ≠ (?c::?'a::type) ⟹ (?m::?'a::type ⇒ ?'b::type)(?a := ?b::?'b::type, ?c := ?d::?'b::type) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹3 ≠ 5› 2. ‹[5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9] = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (5) P (*‹?a ≠ ?c ⟹ ?m(?a := ?b, ?c := ?d) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹0 ≠ 6› 2. ‹[5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9] = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (4) P (*‹?a ≠ ?c ⟹ ?m(?a := ?b, ?c := ?d) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹Suc (0::nat) ≠ (6::nat)› 2. ‹[5::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, 6::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, Suc (0::nat) ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9] = [8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc (0::nat) ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (3) P (*‹?a ≠ ?c ⟹ ?m(?a := ?b, ?c := ?d) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹2 ≠ 6› 2. ‹[5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9] = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (2) P (*‹?a ≠ ?c ⟹ ?m(?a := ?b, ?c := ?d) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹3 ≠ 6› 2. ‹[5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9] = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (1) P (*‹?a ≠ ?c ⟹ ?m(?a := ?b, ?c := ?d) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹5 ≠ 6› 2. ‹[6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9] = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (6) P (*‹?a ≠ ?c ⟹ ?m(?a := ?b, ?c := ?d) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹(0::nat) ≠ (7::nat)› 2. ‹[6::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc (0::nat) ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 0::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, 8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9] = [8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc (0::nat) ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (5) P (*‹?a ≠ ?c ⟹ ?m(?a := ?b, ?c := ?d) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹Suc 0 ≠ 7› 2. ‹[6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, 8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9] = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (4) P (*‹?a ≠ ?c ⟹ ?m(?a := ?b, ?c := ?d) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹2 ≠ 7› 2. ‹[6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, 8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9] = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (3) P (*‹?a ≠ ?c ⟹ ?m(?a := ?b, ?c := ?d) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹(3::nat) ≠ (7::nat)› 2. ‹[6::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 3::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc (0::nat) ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, 8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9] = [8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc (0::nat) ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (2) P (*‹?a ≠ ?c ⟹ ?m(?a := ?b, ?c := ?d) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹5 ≠ 7› 2. ‹[6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, 8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9] = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (1) P (*‹(?a::?'a) ≠ (?c::?'a) ⟹ (?m::?'a ⇒ ?'b)(?a := ?b::?'b, ?c := ?d::?'b) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹6 ≠ 7› 2. ‹[7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1, 8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9] = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (7) P (*‹?a ≠ ?c ⟹ ?m(?a := ?b, ?c := ?d) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹0 ≠ 8› 2. ‹[7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1] = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (6) P (*‹?a ≠ ?c ⟹ ?m(?a := ?b, ?c := ?d) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹Suc 0 ≠ 8› 2. ‹[7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, 8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1] = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (5) P (*‹?a ≠ ?c ⟹ ?m(?a := ?b, ?c := ?d) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹2 ≠ 8› 2. ‹[7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1] = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (4) P (*‹?a ≠ ?c ⟹ ?m(?a := ?b, ?c := ?d) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹3 ≠ 8› 2. ‹[7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1] = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (3) P (*‹(?a::?'a) ≠ (?c::?'a) ⟹ (?m::?'a ⇒ ?'b)(?a := ?b::?'b, ?c := ?d::?'b) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹(5::nat) ≠ (8::nat)› 2. ‹[7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 5::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc (0::nat) ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1] = [8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc (0::nat) ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (2) P (*‹?a ≠ ?c ⟹ ?m(?a := ?b, ?c := ?d) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹6 ≠ 8› 2. ‹[7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1] = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst (1) P (*‹?a ≠ ?c ⟹ ?m(?a := ?b, ?c := ?d) = ?m(?c := ?d, ?a := ?b)›*)) (*goals: 1. ‹7 ≠ 8› 2. ‹[8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1] = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, Suc 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, 0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1]› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . qed declare const_ss [simp] lemma "⋀σ₁. (σ₁,σ₁') ⊨ (Person .allInstances() ≐ Set{ X⇩P⇩e⇩r⇩s⇩o⇩n1, X⇩P⇩e⇩r⇩s⇩o⇩n2, X⇩P⇩e⇩r⇩s⇩o⇩n3, X⇩P⇩e⇩r⇩s⇩o⇩n4⌦‹, X⇩P⇩e⇩r⇩s⇩o⇩n5›, X⇩P⇩e⇩r⇩s⇩o⇩n6, X⇩P⇩e⇩r⇩s⇩o⇩n7 .oclAsType(Person)⌦‹, X⇩P⇩e⇩r⇩s⇩o⇩n8›, X⇩P⇩e⇩r⇩s⇩o⇩n9 })" apply (subst perm_σ₁' (*‹σ₁' = ⦇heap = [oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, oid7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, oid6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, oid2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1], assocs = assocs σ₁'⦈›*)) (*goal: ‹⋀σ₁. (σ₁, σ₁') ⊨ Person .allInstances() ≐ Set{X⇩P⇩e⇩r⇩s⇩o⇩n1, X⇩P⇩e⇩r⇩s⇩o⇩n2, X⇩P⇩e⇩r⇩s⇩o⇩n3, X⇩P⇩e⇩r⇩s⇩o⇩n4, X⇩P⇩e⇩r⇩s⇩o⇩n6, X⇩P⇩e⇩r⇩s⇩o⇩n7 .oclAsType(Person), X⇩P⇩e⇩r⇩s⇩o⇩n9}›*) apply (simp only: oid0_def (*‹oid0 ≡ 0›*) oid1_def (*‹oid1 ≡ 1›*) oid2_def (*‹oid2 ≡ 2›*) oid3_def (*‹oid3 ≡ 3›*) oid4_def (*‹oid4 ≡ 4›*) oid5_def (*‹oid5 ≡ 5›*) oid6_def (*‹oid6 ≡ 6›*) oid7_def (*‹oid7 ≡ 7›*) oid8_def (*‹oid8 ≡ 8›*) X⇩P⇩e⇩r⇩s⇩o⇩n1_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n1 ≡ λ_. ⌊⌊person1⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n2_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n2 ≡ λ_. ⌊⌊person2⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n3_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n3 ≡ λ_. ⌊⌊person3⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n4_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n4 ≡ λ_. ⌊⌊person4⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n5_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n5 ≡ λ_. ⌊⌊person5⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n6_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n6 ≡ λ_. ⌊⌊person6⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n7_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n7 ≡ λ_. ⌊⌊person7⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n8_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n8 ≡ λ_. ⌊⌊person8⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n9_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n9 ≡ λ_. ⌊⌊person9⌋⌋›*) person7_def (*‹person7 ≡ mk⇩O⇩c⇩l⇩A⇩n⇩y oid6 ⌊(⌊3200⌋, ⌊oid6⌋)⌋›*)) (*goal: ‹⋀σ₁. (σ₁, ⦇heap = [oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, oid7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, oid6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, oid2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1], assocs = assocs σ₁'⦈) ⊨ Person .allInstances() ≐ Set{X⇩P⇩e⇩r⇩s⇩o⇩n1, X⇩P⇩e⇩r⇩s⇩o⇩n2, X⇩P⇩e⇩r⇩s⇩o⇩n3, X⇩P⇩e⇩r⇩s⇩o⇩n4, X⇩P⇩e⇩r⇩s⇩o⇩n6, X⇩P⇩e⇩r⇩s⇩o⇩n7 .oclAsType(Person), X⇩P⇩e⇩r⇩s⇩o⇩n9}›*) apply (subst state_update_vs_allInstances_at_post_tc (*‹⟦?oid ∉ dom ?σ'; ?Type ?Object ≠ ⊥; cp ?P; ⋀X. const X ⟹ const (?P X)⟧ ⟹ ((?σ, ⦇heap = ?σ'(?oid ↦ ?Object), assocs = ?A⦈) ⊨ ?P ?Type .allInstances()) = ((?σ, ⦇heap = ?σ', assocs = ?A⦈) ⊨ ?P ?Type .allInstances()->including⇩S⇩e⇩t(λ_. ⌊?Type ?Object⌋))›*)) (*goals: 1. ‹⋀σ₁::𝔄 state. (0::nat) ∉ dom [8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y (6::nat) ⌊(⌊3200::int⌋, ⌊6::nat⌋)⌋), 5::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, 1::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2]› 2. ‹⋀σ₁::𝔄 state. Person (in⇩P⇩e⇩r⇩s⇩o⇩n person1) ≠ ⊥› 3. ‹⋀σ₁::𝔄 state. cp (λa::𝔄 state × 𝔄 state ⇒ Set(⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥). a ≐ Set{λ_::𝔄 state × 𝔄 state. ⌊⌊person1⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊person2⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊person3⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊person4⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊person6⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (6::nat) ⌊(⌊3200::int⌋, ⌊6::nat⌋)⌋⌋⌋ .oclAsType(Person), λ_::𝔄 state × 𝔄 state. ⌊⌊person9⌋⌋})› 4. ‹⋀(σ₁::𝔄 state) X::𝔄 state × 𝔄 state ⇒ Set(⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥). const X ⟹ const (X ≐ Set{λ_::𝔄 state × 𝔄 state. ⌊⌊person1⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊person2⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊person3⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊person4⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊person6⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (6::nat) ⌊(⌊3200::int⌋, ⌊6::nat⌋)⌋⌋⌋ .oclAsType(Person), λ_::𝔄 state × 𝔄 state. ⌊⌊person9⌋⌋})› 5. ‹⋀σ₁::𝔄 state. (σ₁, ⦇heap = [8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y (6::nat) ⌊(⌊3200::int⌋, ⌊6::nat⌋)⌋), 5::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, 1::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2], assocs = assocs σ₁'⦈) ⊨ Person .allInstances()->including⇩S⇩e⇩t(λ_::𝔄 state × 𝔄 state. ⌊Person (in⇩P⇩e⇩r⇩s⇩o⇩n person1)⌋) ≐ Set{λ_::𝔄 state × 𝔄 state. ⌊⌊person1⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊person2⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊person3⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊person4⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊person6⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (6::nat) ⌊(⌊3200::int⌋, ⌊6::nat⌋)⌋⌋⌋ .oclAsType(Person), λ_::𝔄 state × 𝔄 state. ⌊⌊person9⌋⌋}› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄_def (*‹OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 = (λu::𝔄. case u of in⇩P⇩e⇩r⇩s⇩o⇩n (p::type⇩P⇩e⇩r⇩s⇩o⇩n) ⇒ ⌊p⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⊥) ⇒ ⊥ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⌊(a::⟨int⟩⇩⊥, b::⟨nat⟩⇩⊥)⌋) ⇒ ⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋)›*)) (*discuss goal 3*) apply simp (*discuss goal 4*) apply (rule const_StrictRefEq⇩S⇩e⇩t_including (*‹⟦const ?a; const ?S; const ?X⟧ ⟹ const (?X ≐ ?S->including⇩S⇩e⇩t(?a))›*)) (*goals: 1. ‹⋀σ₁ X. const X ⟹ const (λ_. ⌊⌊person1⌋⌋)› 2. ‹⋀σ₁ X. const X ⟹ const Set{λ_. ⌊⌊person2⌋⌋, λ_. ⌊⌊person3⌋⌋, λ_. ⌊⌊person4⌋⌋, λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋}› 3. ‹⋀σ₁ X. const X ⟹ const X› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) (*discuss goal 5*) apply (rule OclIncluding_cong (*‹⟦?τ ⊨ δ ?t; ?τ ⊨ υ ?y; ?τ ⊨ ?s ≐ ?t; ?x = ?y⟧ ⟹ ?τ ⊨ ?s->including⇩S⇩e⇩t(?x) ≐ ?t->including⇩S⇩e⇩t(?y)›*)) (*goals: 1. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋), 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, 1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2], assocs = assocs σ₁'⦈) ⊨ δ Set{λ_. ⌊⌊person2⌋⌋, λ_. ⌊⌊person3⌋⌋, λ_. ⌊⌊person4⌋⌋, λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋}› 2. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋), 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, 1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2], assocs = assocs σ₁'⦈) ⊨ υ (λ_. ⌊⌊person1⌋⌋)› 3. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋), 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, 1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2], assocs = assocs σ₁'⦈) ⊨ Person .allInstances() ≐ Set{λ_. ⌊⌊person2⌋⌋, λ_. ⌊⌊person3⌋⌋, λ_. ⌊⌊person4⌋⌋, λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋}› 4. ‹⋀σ₁. (λ_. ⌊Person (in⇩P⇩e⇩r⇩s⇩o⇩n person1)⌋) = (λ_. ⌊⌊person1⌋⌋)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (subst state_update_vs_allInstances_at_post_tc (*‹⟦?oid ∉ dom ?σ'; ?Type ?Object ≠ ⊥; cp ?P; ⋀X. const X ⟹ const (?P X)⟧ ⟹ ((?σ, ⦇heap = ?σ'(?oid ↦ ?Object), assocs = ?A⦈) ⊨ ?P ?Type .allInstances()) = ((?σ, ⦇heap = ?σ', assocs = ?A⦈) ⊨ ?P ?Type .allInstances()->including⇩S⇩e⇩t(λ_. ⌊?Type ?Object⌋))›*)) (*goals: 1. ‹⋀σ₁. 1 ∉ dom [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋), 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3]› 2. ‹⋀σ₁. Person (in⇩P⇩e⇩r⇩s⇩o⇩n person2) ≠ ⊥› 3. ‹⋀σ₁. cp (λa. a ≐ Set{λ_. ⌊⌊person2⌋⌋, λ_. ⌊⌊person3⌋⌋, λ_. ⌊⌊person4⌋⌋, λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋})› 4. ‹⋀σ₁ X. const X ⟹ const (X ≐ Set{λ_. ⌊⌊person2⌋⌋, λ_. ⌊⌊person3⌋⌋, λ_. ⌊⌊person4⌋⌋, λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋})› 5. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋), 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3], assocs = assocs σ₁'⦈) ⊨ Person .allInstances()->including⇩S⇩e⇩t(λ_. ⌊Person (in⇩P⇩e⇩r⇩s⇩o⇩n person2)⌋) ≐ Set{λ_. ⌊⌊person2⌋⌋, λ_. ⌊⌊person3⌋⌋, λ_. ⌊⌊person4⌋⌋, λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋}› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄_def (*‹OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 = (λu::𝔄. case u of in⇩P⇩e⇩r⇩s⇩o⇩n (p::type⇩P⇩e⇩r⇩s⇩o⇩n) ⇒ ⌊p⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⊥) ⇒ ⊥ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⌊(a::⟨int⟩⇩⊥, b::⟨nat⟩⇩⊥)⌋) ⇒ ⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋)›*)) (*discuss goal 3*) apply simp (*discuss goal 4*) apply (rule const_StrictRefEq⇩S⇩e⇩t_including (*‹⟦const ?a; const ?S; const ?X⟧ ⟹ const (?X ≐ ?S->including⇩S⇩e⇩t(?a))›*)) (*goals: 1. ‹⋀σ₁ X. const X ⟹ const (λ_. ⌊⌊person2⌋⌋)› 2. ‹⋀σ₁ X. const X ⟹ const Set{λ_. ⌊⌊person3⌋⌋, λ_. ⌊⌊person4⌋⌋, λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋}› 3. ‹⋀σ₁ X. const X ⟹ const X› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) (*discuss goal 5*) apply (rule OclIncluding_cong (*‹⟦?τ ⊨ δ ?t; ?τ ⊨ υ ?y; ?τ ⊨ ?s ≐ ?t; ?x = ?y⟧ ⟹ ?τ ⊨ ?s->including⇩S⇩e⇩t(?x) ≐ ?t->including⇩S⇩e⇩t(?y)›*)) (*goals: 1. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋), 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3], assocs = assocs σ₁'⦈) ⊨ δ Set{λ_. ⌊⌊person3⌋⌋, λ_. ⌊⌊person4⌋⌋, λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋}› 2. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋), 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3], assocs = assocs σ₁'⦈) ⊨ υ (λ_. ⌊⌊person2⌋⌋)› 3. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋), 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3], assocs = assocs σ₁'⦈) ⊨ Person .allInstances() ≐ Set{λ_. ⌊⌊person3⌋⌋, λ_. ⌊⌊person4⌋⌋, λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋}› 4. ‹⋀σ₁. (λ_. ⌊Person (in⇩P⇩e⇩r⇩s⇩o⇩n person2)⌋) = (λ_. ⌊⌊person2⌋⌋)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (subst state_update_vs_allInstances_at_post_tc (*‹⟦?oid ∉ dom ?σ'; ?Type ?Object ≠ ⊥; cp ?P; ⋀X. const X ⟹ const (?P X)⟧ ⟹ ((?σ, ⦇heap = ?σ'(?oid ↦ ?Object), assocs = ?A⦈) ⊨ ?P ?Type .allInstances()) = ((?σ, ⦇heap = ?σ', assocs = ?A⦈) ⊨ ?P ?Type .allInstances()->including⇩S⇩e⇩t(λ_. ⌊?Type ?Object⌋))›*)) (*goals: 1. ‹⋀σ₁. 2 ∉ dom [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋), 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4]› 2. ‹⋀σ₁. Person (in⇩P⇩e⇩r⇩s⇩o⇩n person3) ≠ ⊥› 3. ‹⋀σ₁. cp (λa. a ≐ Set{λ_. ⌊⌊person3⌋⌋, λ_. ⌊⌊person4⌋⌋, λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋})› 4. ‹⋀σ₁ X. const X ⟹ const (X ≐ Set{λ_. ⌊⌊person3⌋⌋, λ_. ⌊⌊person4⌋⌋, λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋})› 5. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋), 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4], assocs = assocs σ₁'⦈) ⊨ Person .allInstances()->including⇩S⇩e⇩t(λ_. ⌊Person (in⇩P⇩e⇩r⇩s⇩o⇩n person3)⌋) ≐ Set{λ_. ⌊⌊person3⌋⌋, λ_. ⌊⌊person4⌋⌋, λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋}› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄_def (*‹OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 = (λu::𝔄. case u of in⇩P⇩e⇩r⇩s⇩o⇩n (p::type⇩P⇩e⇩r⇩s⇩o⇩n) ⇒ ⌊p⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⊥) ⇒ ⊥ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⌊(a::⟨int⟩⇩⊥, b::⟨nat⟩⇩⊥)⌋) ⇒ ⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋)›*)) (*discuss goal 3*) apply simp (*discuss goal 4*) apply (rule const_StrictRefEq⇩S⇩e⇩t_including (*‹⟦const (?a::?'a state × ?'a state ⇒ ?'b::null); const (?S::?'a state × ?'a state ⇒ Set(?'b::null)); const (?X::?'a state × ?'a state ⇒ Set(?'b::null))⟧ ⟹ const (?X ≐ ?S->including⇩S⇩e⇩t(?a))›*)) (*goals: 1. ‹⋀σ₁ X. const X ⟹ const (λ_. ⌊⌊person3⌋⌋)› 2. ‹⋀σ₁ X. const X ⟹ const Set{λ_. ⌊⌊person4⌋⌋, λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋}› 3. ‹⋀σ₁ X. const X ⟹ const X› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) (*discuss goal 5*) apply (rule OclIncluding_cong (*‹⟦?τ ⊨ δ ?t; ?τ ⊨ υ ?y; ?τ ⊨ ?s ≐ ?t; ?x = ?y⟧ ⟹ ?τ ⊨ ?s->including⇩S⇩e⇩t(?x) ≐ ?t->including⇩S⇩e⇩t(?y)›*)) (*goals: 1. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋), 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4], assocs = assocs σ₁'⦈) ⊨ δ Set{λ_. ⌊⌊person4⌋⌋, λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋}› 2. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋), 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4], assocs = assocs σ₁'⦈) ⊨ υ (λ_. ⌊⌊person3⌋⌋)› 3. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋), 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4], assocs = assocs σ₁'⦈) ⊨ Person .allInstances() ≐ Set{λ_. ⌊⌊person4⌋⌋, λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋}› 4. ‹⋀σ₁. (λ_. ⌊Person (in⇩P⇩e⇩r⇩s⇩o⇩n person3)⌋) = (λ_. ⌊⌊person3⌋⌋)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (subst state_update_vs_allInstances_at_post_tc (*‹⟦?oid ∉ dom ?σ'; ?Type ?Object ≠ ⊥; cp ?P; ⋀X. const X ⟹ const (?P X)⟧ ⟹ ((?σ, ⦇heap = ?σ'(?oid ↦ ?Object), assocs = ?A⦈) ⊨ ?P ?Type .allInstances()) = ((?σ, ⦇heap = ?σ', assocs = ?A⦈) ⊨ ?P ?Type .allInstances()->including⇩S⇩e⇩t(λ_. ⌊?Type ?Object⌋))›*)) (*goals: 1. ‹⋀σ₁. 3 ∉ dom [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋), 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6]› 2. ‹⋀σ₁. Person (in⇩P⇩e⇩r⇩s⇩o⇩n person4) ≠ ⊥› 3. ‹⋀σ₁. cp (λa. a ≐ Set{λ_. ⌊⌊person4⌋⌋, λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋})› 4. ‹⋀σ₁ X. const X ⟹ const (X ≐ Set{λ_. ⌊⌊person4⌋⌋, λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋})› 5. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋), 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6], assocs = assocs σ₁'⦈) ⊨ Person .allInstances()->including⇩S⇩e⇩t(λ_. ⌊Person (in⇩P⇩e⇩r⇩s⇩o⇩n person4)⌋) ≐ Set{λ_. ⌊⌊person4⌋⌋, λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋}› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄_def (*‹OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 = (λu. case u of in⇩P⇩e⇩r⇩s⇩o⇩n p ⇒ ⌊p⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥) ⇒ ⊥ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋) ⇒ ⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋)›*)) (*discuss goal 3*) apply simp (*discuss goal 4*) apply (rule const_StrictRefEq⇩S⇩e⇩t_including (*‹⟦const ?a; const ?S; const ?X⟧ ⟹ const (?X ≐ ?S->including⇩S⇩e⇩t(?a))›*)) (*goals: 1. ‹⋀σ₁ X. const X ⟹ const (λ_. ⌊⌊person4⌋⌋)› 2. ‹⋀σ₁ X. const X ⟹ const Set{λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋}› 3. ‹⋀σ₁ X. const X ⟹ const X› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) (*discuss goal 5*) apply (rule OclIncluding_cong (*‹⟦?τ ⊨ δ ?t; ?τ ⊨ υ ?y; ?τ ⊨ ?s ≐ ?t; ?x = ?y⟧ ⟹ ?τ ⊨ ?s->including⇩S⇩e⇩t(?x) ≐ ?t->including⇩S⇩e⇩t(?y)›*)) (*goals: 1. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋), 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6], assocs = assocs σ₁'⦈) ⊨ δ Set{λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋}› 2. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋), 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6], assocs = assocs σ₁'⦈) ⊨ υ (λ_. ⌊⌊person4⌋⌋)› 3. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋), 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6], assocs = assocs σ₁'⦈) ⊨ Person .allInstances() ≐ Set{λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋}› 4. ‹⋀σ₁. (λ_. ⌊Person (in⇩P⇩e⇩r⇩s⇩o⇩n person4)⌋) = (λ_. ⌊⌊person4⌋⌋)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (subst state_update_vs_allInstances_at_post_tc (*‹⟦?oid ∉ dom ?σ'; ?Type ?Object ≠ ⊥; cp ?P; ⋀X. const X ⟹ const (?P X)⟧ ⟹ ((?σ, ⦇heap = ?σ'(?oid ↦ ?Object), assocs = ?A⦈) ⊨ ?P ?Type .allInstances()) = ((?σ, ⦇heap = ?σ', assocs = ?A⦈) ⊨ ?P ?Type .allInstances()->including⇩S⇩e⇩t(λ_. ⌊?Type ?Object⌋))›*)) (*goals: 1. ‹⋀σ₁. 5 ∉ dom [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋)]› 2. ‹⋀σ₁. Person (in⇩P⇩e⇩r⇩s⇩o⇩n person6) ≠ ⊥› 3. ‹⋀σ₁. cp (λa. a ≐ Set{λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋})› 4. ‹⋀σ₁ X. const X ⟹ const (X ≐ Set{λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋})› 5. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋)], assocs = assocs σ₁'⦈) ⊨ Person .allInstances()->including⇩S⇩e⇩t(λ_. ⌊Person (in⇩P⇩e⇩r⇩s⇩o⇩n person6)⌋) ≐ Set{λ_. ⌊⌊person6⌋⌋, λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋}› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄_def (*‹OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 = (λu. case u of in⇩P⇩e⇩r⇩s⇩o⇩n p ⇒ ⌊p⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥) ⇒ ⊥ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋) ⇒ ⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋)›*)) (*discuss goal 3*) apply simp (*discuss goal 4*) apply (rule const_StrictRefEq⇩S⇩e⇩t_including (*‹⟦const ?a; const ?S; const ?X⟧ ⟹ const (?X ≐ ?S->including⇩S⇩e⇩t(?a))›*)) (*goals: 1. ‹⋀σ₁ X. const X ⟹ const (λ_. ⌊⌊person6⌋⌋)› 2. ‹⋀σ₁ X. const X ⟹ const Set{λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋}› 3. ‹⋀σ₁ X. const X ⟹ const X› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) (*discuss goal 5*) apply (rule OclIncluding_cong (*‹⟦?τ ⊨ δ ?t; ?τ ⊨ υ ?y; ?τ ⊨ ?s ≐ ?t; ?x = ?y⟧ ⟹ ?τ ⊨ ?s->including⇩S⇩e⇩t(?x) ≐ ?t->including⇩S⇩e⇩t(?y)›*)) (*goals: 1. ‹⋀σ₁::𝔄 state. (σ₁, ⦇heap = [8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y (6::nat) ⌊(⌊3200::int⌋, ⌊6::nat⌋)⌋)], assocs = assocs σ₁'⦈) ⊨ δ Set{λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (6::nat) ⌊(⌊3200::int⌋, ⌊6::nat⌋)⌋⌋⌋ .oclAsType(Person), λ_::𝔄 state × 𝔄 state. ⌊⌊person9⌋⌋}› 2. ‹⋀σ₁::𝔄 state. (σ₁, ⦇heap = [8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y (6::nat) ⌊(⌊3200::int⌋, ⌊6::nat⌋)⌋)], assocs = assocs σ₁'⦈) ⊨ υ (λ_::𝔄 state × 𝔄 state. ⌊⌊person6⌋⌋)› 3. ‹⋀σ₁::𝔄 state. (σ₁, ⦇heap = [8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y (6::nat) ⌊(⌊3200::int⌋, ⌊6::nat⌋)⌋)], assocs = assocs σ₁'⦈) ⊨ Person .allInstances() ≐ Set{λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (6::nat) ⌊(⌊3200::int⌋, ⌊6::nat⌋)⌋⌋⌋ .oclAsType(Person), λ_::𝔄 state × 𝔄 state. ⌊⌊person9⌋⌋}› 4. ‹⋀σ₁::𝔄 state. (λ_::𝔄 state × 𝔄 state. ⌊Person (in⇩P⇩e⇩r⇩s⇩o⇩n person6)⌋) = (λ_::𝔄 state × 𝔄 state. ⌊⌊person6⌋⌋)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (subst state_update_vs_allInstances_at_post_tc (*‹⟦(?oid::nat) ∉ dom (?σ'::nat ⇒ ⟨?'a⟩⇩⊥); (?Type::?'a ⇒ ⟨?'b⟩⇩⊥) (?Object::?'a) ≠ ⊥; cp (?P::(?'a state × ?'a state ⇒ Set(⟨⟨?'b⟩⇩⊥⟩⇩⊥)) ⇒ ?'a state × ?'a state ⇒ ⟨⟨bool⟩⇩⊥⟩⇩⊥); ⋀X::?'a state × ?'a state ⇒ Set(⟨⟨?'b⟩⇩⊥⟩⇩⊥). const X ⟹ const (?P X)⟧ ⟹ ((?σ::?'a state, ⦇heap = ?σ'(?oid ↦ ?Object), assocs = ?A::nat ⇒ ⟨nat list list list⟩⇩⊥⦈) ⊨ ?P ?Type .allInstances()) = ((?σ, ⦇heap = ?σ', assocs = ?A⦈) ⊨ ?P ?Type .allInstances()->including⇩S⇩e⇩t(λ_::?'a state × ?'a state. ⌊?Type ?Object⌋))›*)) (*goals: 1. ‹⋀σ₁. 6 ∉ dom [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8]› 2. ‹⋀σ₁. Person (in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋)) ≠ ⊥› 3. ‹⋀σ₁. cp (λa. a ≐ Set{λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋})› 4. ‹⋀σ₁ X. const X ⟹ const (X ≐ Set{λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋})› 5. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8], assocs = assocs σ₁'⦈) ⊨ Person .allInstances()->including⇩S⇩e⇩t(λ_. ⌊Person (in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋))⌋) ≐ Set{λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person), λ_. ⌊⌊person9⌋⌋}› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄_def (*‹OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 = (λu. case u of in⇩P⇩e⇩r⇩s⇩o⇩n p ⇒ ⌊p⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥) ⇒ ⊥ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋) ⇒ ⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋)›*)) (*discuss goal 3*) apply simp (*discuss goal 4*) apply (rule const_StrictRefEq⇩S⇩e⇩t_including (*‹⟦const ?a; const ?S; const ?X⟧ ⟹ const (?X ≐ ?S->including⇩S⇩e⇩t(?a))›*)) (*goals: 1. ‹⋀σ₁ X. const X ⟹ const λ_. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y 6 ⌊(⌊3200⌋, ⌊6⌋)⌋⌋⌋ .oclAsType(Person)› 2. ‹⋀σ₁ X. const X ⟹ const Set{λ_. ⌊⌊person9⌋⌋}› 3. ‹⋀σ₁ X. const X ⟹ const X› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) (*discuss goal 5*) apply (rule OclIncluding_cong (*‹⟦?τ ⊨ δ ?t; ?τ ⊨ υ ?y; ?τ ⊨ ?s ≐ ?t; ?x = ?y⟧ ⟹ ?τ ⊨ ?s->including⇩S⇩e⇩t(?x) ≐ ?t->including⇩S⇩e⇩t(?y)›*)) (*goals: 1. ‹⋀σ₁::𝔄 state. (σ₁, ⦇heap = [8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8], assocs = assocs σ₁'⦈) ⊨ δ Set{λ_::𝔄 state × 𝔄 state. ⌊⌊person9⌋⌋}› 2. ‹⋀σ₁::𝔄 state. (σ₁, ⦇heap = [8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8], assocs = assocs σ₁'⦈) ⊨ υ λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (6::nat) ⌊(⌊3200::int⌋, ⌊6::nat⌋)⌋⌋⌋ .oclAsType(Person)› 3. ‹⋀σ₁::𝔄 state. (σ₁, ⦇heap = [8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8], assocs = assocs σ₁'⦈) ⊨ Person .allInstances() ≐ Set{λ_::𝔄 state × 𝔄 state. ⌊⌊person9⌋⌋}› 4. ‹⋀σ₁::𝔄 state. (λ_::𝔄 state × 𝔄 state. ⌊Person (in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y (6::nat) ⌊(⌊3200::int⌋, ⌊6::nat⌋)⌋))⌋) = λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩O⇩c⇩l⇩A⇩n⇩y (6::nat) ⌊(⌊3200::int⌋, ⌊6::nat⌋)⌋⌋⌋ .oclAsType(Person)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (subst state_update_vs_allInstances_at_post_ntc (*‹⟦(?oid::nat) ∉ dom (?σ'::nat ⇒ ⟨?'a⟩⇩⊥); (?Type::?'a ⇒ ⟨?'b⟩⇩⊥) (?Object::?'a) = ⊥; cp (?P::(?'a state × ?'a state ⇒ Set(⟨⟨?'b⟩⇩⊥⟩⇩⊥)) ⇒ ?'a state × ?'a state ⇒ ⟨⟨bool⟩⇩⊥⟩⇩⊥); ⋀X::?'a state × ?'a state ⇒ Set(⟨⟨?'b⟩⇩⊥⟩⇩⊥). const X ⟹ const (?P X)⟧ ⟹ ((?σ::?'a state, ⦇heap = ?σ'(?oid ↦ ?Object), assocs = ?A::nat ⇒ ⟨nat list list list⟩⇩⊥⦈) ⊨ ?P ?Type .allInstances()) = ((?σ, ⦇heap = ?σ', assocs = ?A⦈) ⊨ ?P ?Type .allInstances())›*)) (*goals: 1. ‹⋀σ₁. 7 ∉ dom [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9]› 2. ‹⋀σ₁. Person (in⇩O⇩c⇩l⇩A⇩n⇩y person8) = ⊥› 3. ‹⋀σ₁. cp (λa. a ≐ Set{λ_. ⌊⌊person9⌋⌋})› 4. ‹⋀σ₁ X. const X ⟹ const (X ≐ Set{λ_. ⌊⌊person9⌋⌋})› 5. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9], assocs = assocs σ₁'⦈) ⊨ Person .allInstances() ≐ Set{λ_. ⌊⌊person9⌋⌋}› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄_def (*‹OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 = (λu::𝔄. case u of in⇩P⇩e⇩r⇩s⇩o⇩n (p::type⇩P⇩e⇩r⇩s⇩o⇩n) ⇒ ⌊p⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⊥) ⇒ ⊥ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⌊(a::⟨int⟩⇩⊥, b::⟨nat⟩⇩⊥)⌋) ⇒ ⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋)›*) person8_def (*‹person8 ≡ mk⇩O⇩c⇩l⇩A⇩n⇩y oid7 ⊥›*)) (*discuss goal 3*) apply simp (*discuss goal 4*) apply (rule const_StrictRefEq⇩S⇩e⇩t_including (*‹⟦const ?a; const ?S; const ?X⟧ ⟹ const (?X ≐ ?S->including⇩S⇩e⇩t(?a))›*)) (*goals: 1. ‹⋀σ₁ X. const X ⟹ const (λ_. ⌊⌊person9⌋⌋)› 2. ‹⋀σ₁ X. const X ⟹ const Set{}› 3. ‹⋀σ₁ X. const X ⟹ const X› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) (*discuss goal 5*) apply (subst state_update_vs_allInstances_at_post_tc (*‹⟦?oid ∉ dom ?σ'; ?Type ?Object ≠ ⊥; cp ?P; ⋀X. const X ⟹ const (?P X)⟧ ⟹ ((?σ, ⦇heap = ?σ'(?oid ↦ ?Object), assocs = ?A⦈) ⊨ ?P ?Type .allInstances()) = ((?σ, ⦇heap = ?σ', assocs = ?A⦈) ⊨ ?P ?Type .allInstances()->including⇩S⇩e⇩t(λ_. ⌊?Type ?Object⌋))›*)) (*goals: 1. ‹⋀σ₁::𝔄 state. (8::nat) ∉ dom (λa::nat. ⊥)› 2. ‹⋀σ₁::𝔄 state. Person (in⇩P⇩e⇩r⇩s⇩o⇩n person9) ≠ ⊥› 3. ‹⋀σ₁::𝔄 state. cp (λa::𝔄 state × 𝔄 state ⇒ Set(⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥). a ≐ Set{λ_::𝔄 state × 𝔄 state. ⌊⌊person9⌋⌋})› 4. ‹⋀(σ₁::𝔄 state) X::𝔄 state × 𝔄 state ⇒ Set(⟨⟨type⇩P⇩e⇩r⇩s⇩o⇩n⟩⇩⊥⟩⇩⊥). const X ⟹ const (X ≐ Set{λ_::𝔄 state × 𝔄 state. ⌊⌊person9⌋⌋})› 5. ‹⋀σ₁::𝔄 state. (σ₁, ⦇heap = λa::nat. ⊥, assocs = assocs σ₁'⦈) ⊨ Person .allInstances()->including⇩S⇩e⇩t(λ_::𝔄 state × 𝔄 state. ⌊Person (in⇩P⇩e⇩r⇩s⇩o⇩n person9)⌋) ≐ Set{λ_::𝔄 state × 𝔄 state. ⌊⌊person9⌋⌋}› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄_def (*‹OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 = (λu. case u of in⇩P⇩e⇩r⇩s⇩o⇩n p ⇒ ⌊p⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥) ⇒ ⊥ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋) ⇒ ⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋)›*)) (*discuss goal 3*) apply simp (*discuss goal 4*) apply (rule const_StrictRefEq⇩S⇩e⇩t_including (*‹⟦const ?a; const ?S; const ?X⟧ ⟹ const (?X ≐ ?S->including⇩S⇩e⇩t(?a))›*)) (*goals: 1. ‹⋀σ₁ X. const X ⟹ const (λ_. ⌊⌊person9⌋⌋)› 2. ‹⋀σ₁ X. const X ⟹ const Set{}› 3. ‹⋀σ₁ X. const X ⟹ const X› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) (*discuss goal 5*) apply (rule OclIncluding_cong (*‹⟦?τ ⊨ δ ?t; ?τ ⊨ υ ?y; ?τ ⊨ ?s ≐ ?t; ?x = ?y⟧ ⟹ ?τ ⊨ ?s->including⇩S⇩e⇩t(?x) ≐ ?t->including⇩S⇩e⇩t(?y)›*)) (*goals: 1. ‹⋀σ₁. (σ₁, ⦇heap = λa. ⊥, assocs = assocs σ₁'⦈) ⊨ δ Set{}› 2. ‹⋀σ₁. (σ₁, ⦇heap = λa. ⊥, assocs = assocs σ₁'⦈) ⊨ υ (λ_. ⌊⌊person9⌋⌋)› 3. ‹⋀σ₁. (σ₁, ⦇heap = λa. ⊥, assocs = assocs σ₁'⦈) ⊨ Person .allInstances() ≐ Set{}› 4. ‹⋀σ₁. (λ_. ⌊Person (in⇩P⇩e⇩r⇩s⇩o⇩n person9)⌋) = (λ_. ⌊⌊person9⌋⌋)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (rule state_update_vs_allInstances_at_post_empty (*‹(?σ::?'a state, ⦇heap = λx::nat. ⊥, assocs = ?A::nat ⇒ ⟨nat list list list⟩⇩⊥⦈) ⊨ ?Type::?'a::object ⇒ ⟨?'b::type⟩⇩⊥ .allInstances() ≐ Set{}›*)) (*discuss goal 4*) apply (simp add: OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄_def (*‹OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 = (λu::𝔄. case u of in⇩P⇩e⇩r⇩s⇩o⇩n (p::type⇩P⇩e⇩r⇩s⇩o⇩n) ⇒ ⌊p⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⊥) ⇒ ⊥ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⌊(a::⟨int⟩⇩⊥, b::⟨nat⟩⇩⊥)⌋) ⇒ ⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋)›*)) (*proven 4 subgoals*) (*proven 5 subgoals*) (*proven 5 subgoals*) (*discuss goal 4*) apply (simp add: OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄_def (*‹OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 = (λu. case u of in⇩P⇩e⇩r⇩s⇩o⇩n p ⇒ ⌊p⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥) ⇒ ⊥ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋) ⇒ ⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋)›*)) (*proven 4 subgoals*) (*proven 5 subgoals*) (*discuss goal 4*) apply (simp add: OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄_def (*‹OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 = (λu. case u of in⇩P⇩e⇩r⇩s⇩o⇩n p ⇒ ⌊p⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥) ⇒ ⊥ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋) ⇒ ⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋)›*)) (*proven 4 subgoals*) (*proven 5 subgoals*) (*discuss goal 4*) apply (simp add: OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄_def (*‹OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 = (λu. case u of in⇩P⇩e⇩r⇩s⇩o⇩n p ⇒ ⌊p⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥) ⇒ ⊥ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋) ⇒ ⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋)›*)) (*proven 4 subgoals*) (*proven 5 subgoals*) (*discuss goal 4*) apply (simp add: OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄_def (*‹OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 = (λu::𝔄. case u of in⇩P⇩e⇩r⇩s⇩o⇩n (p::type⇩P⇩e⇩r⇩s⇩o⇩n) ⇒ ⌊p⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⊥) ⇒ ⊥ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⌊(a::⟨int⟩⇩⊥, b::⟨nat⟩⇩⊥)⌋) ⇒ ⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋)›*)) (*proven 4 subgoals*) (*proven 5 subgoals*) (*discuss goal 4*) apply (simp add: OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄_def (*‹OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 = (λu. case u of in⇩P⇩e⇩r⇩s⇩o⇩n p ⇒ ⌊p⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⊥) ⇒ ⊥ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋) ⇒ ⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋)›*)) (*proven 4 subgoals*) (*proven 5 subgoals*) (*discuss goal 4*) apply (simp add: OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄_def (*‹OclAsType⇩P⇩e⇩r⇩s⇩o⇩n_𝔄 = (λu::𝔄. case u of in⇩P⇩e⇩r⇩s⇩o⇩n (p::type⇩P⇩e⇩r⇩s⇩o⇩n) ⇒ ⌊p⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⊥) ⇒ ⊥ | in⇩O⇩c⇩l⇩A⇩n⇩y (mk⇩O⇩c⇩l⇩A⇩n⇩y (oid::nat) ⌊(a::⟨int⟩⇩⊥, b::⟨nat⟩⇩⊥)⌋) ⇒ ⌊mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b⌋)›*)) (*proven 4 subgoals*) (*proven 5 subgoals*) . lemma "⋀σ₁. (σ₁,σ₁') ⊨ (OclAny .allInstances() ≐ Set{ X⇩P⇩e⇩r⇩s⇩o⇩n1 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n2 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n3 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n4 .oclAsType(OclAny) ⌦‹, X⇩P⇩e⇩r⇩s⇩o⇩n5›, X⇩P⇩e⇩r⇩s⇩o⇩n6 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n7, X⇩P⇩e⇩r⇩s⇩o⇩n8, X⇩P⇩e⇩r⇩s⇩o⇩n9 .oclAsType(OclAny) })" apply (subst perm_σ₁' (*‹σ₁' = ⦇heap = [oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, oid7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, oid6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, oid2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1], assocs = assocs σ₁'⦈›*)) (*goal: ‹⋀σ₁. (σ₁, σ₁') ⊨ OclAny .allInstances() ≐ Set{X⇩P⇩e⇩r⇩s⇩o⇩n1 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n2 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n3 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n4 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n6 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n7, X⇩P⇩e⇩r⇩s⇩o⇩n8, X⇩P⇩e⇩r⇩s⇩o⇩n9 .oclAsType(OclAny)}›*) apply (simp only: oid0_def (*‹oid0 ≡ 0::?'a›*) oid1_def (*‹oid1 ≡ 1::?'a›*) oid2_def (*‹oid2 ≡ 2::?'a›*) oid3_def (*‹oid3 ≡ 3::?'a›*) oid4_def (*‹oid4 ≡ 4::?'a›*) oid5_def (*‹oid5 ≡ 5::?'a›*) oid6_def (*‹oid6 ≡ 6::?'a›*) oid7_def (*‹oid7 ≡ 7::?'a›*) oid8_def (*‹oid8 ≡ 8::?'a›*) X⇩P⇩e⇩r⇩s⇩o⇩n1_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n1 ≡ λ_::𝔄 state × 𝔄 state. ⌊⌊person1⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n2_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n2 ≡ λ_::𝔄 state × 𝔄 state. ⌊⌊person2⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n3_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n3 ≡ λ_::𝔄 state × 𝔄 state. ⌊⌊person3⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n4_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n4 ≡ λ_::𝔄 state × 𝔄 state. ⌊⌊person4⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n5_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n5 ≡ λ_::𝔄 state × 𝔄 state. ⌊⌊person5⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n6_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n6 ≡ λ_::𝔄 state × 𝔄 state. ⌊⌊person6⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n7_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n7 ≡ λ_::𝔄 state × 𝔄 state. ⌊⌊person7⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n8_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n8 ≡ λ_::𝔄 state × 𝔄 state. ⌊⌊person8⌋⌋›*) X⇩P⇩e⇩r⇩s⇩o⇩n9_def (*‹X⇩P⇩e⇩r⇩s⇩o⇩n9 ≡ λ_::𝔄 state × 𝔄 state. ⌊⌊person9⌋⌋›*) person1_def (*‹person1 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid0 ⌊1300::int⌋ ⌊oid1⌋›*) person2_def (*‹person2 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid1 ⌊1800::int⌋ ⌊oid1⌋›*) person3_def (*‹person3 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid2 ⊥ ⊥›*) person4_def (*‹person4 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid3 ⌊2900::int⌋ ⊥›*) person5_def (*‹person5 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid4 ⌊3500::int⌋ ⊥›*) person6_def (*‹person6 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid5 ⌊2500::int⌋ ⌊oid6⌋›*) person9_def (*‹person9 ≡ mk⇩P⇩e⇩r⇩s⇩o⇩n oid8 ⌊0::int⌋ ⊥›*)) (*goal: ‹⋀σ₁. (σ₁, ⦇heap = [oid8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person9, oid7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, oid6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, oid5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person6, oid3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person4, oid2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person3, oid1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person2, oid0 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n person1], assocs = assocs σ₁'⦈) ⊨ OclAny .allInstances() ≐ Set{X⇩P⇩e⇩r⇩s⇩o⇩n1 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n2 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n3 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n4 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n6 .oclAsType(OclAny), X⇩P⇩e⇩r⇩s⇩o⇩n7, X⇩P⇩e⇩r⇩s⇩o⇩n8, X⇩P⇩e⇩r⇩s⇩o⇩n9 .oclAsType(OclAny)}›*) apply (subst state_update_vs_allInstances_at_post_tc (*‹⟦?oid ∉ dom ?σ'; ?Type ?Object ≠ ⊥; cp ?P; ⋀X. const X ⟹ const (?P X)⟧ ⟹ ((?σ, ⦇heap = ?σ'(?oid ↦ ?Object), assocs = ?A⦈) ⊨ ?P ?Type .allInstances()) = ((?σ, ⦇heap = ?σ', assocs = ?A⦈) ⊨ ?P ?Type .allInstances()->including⇩S⇩e⇩t(λ_. ⌊?Type ?Object⌋))›*)) (*goals: 1. ‹⋀σ₁. 0 ∉ dom [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋), 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥), 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥), 1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 1 ⌊1800⌋ ⌊1⌋)]› 2. ‹⋀σ₁. OclAny (in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 0 ⌊1300⌋ ⌊1⌋)) ≠ ⊥› 3. ‹⋀σ₁. cp (λa. a ≐ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 0 ⌊1300⌋ ⌊1⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 1 ⌊1800⌋ ⌊1⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)})› 4. ‹⋀σ₁ X. const X ⟹ const (X ≐ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 0 ⌊1300⌋ ⌊1⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 1 ⌊1800⌋ ⌊1⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)})› 5. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋), 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥), 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥), 1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 1 ⌊1800⌋ ⌊1⌋)], assocs = assocs σ₁'⦈) ⊨ OclAny .allInstances()->including⇩S⇩e⇩t(λ_. ⌊OclAny (in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 0 ⌊1300⌋ ⌊1⌋))⌋) ≐ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 0 ⌊1300⌋ ⌊1⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 1 ⌊1800⌋ ⌊1⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄_def (*‹OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 = (λu. ⌊case u of in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b) ⇒ mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y a ⇒ a⌋)›*)) (*discuss goal 3*) apply simp (*discuss goal 4*) apply (rule const_StrictRefEq⇩S⇩e⇩t_including (*‹⟦const ?a; const ?S; const ?X⟧ ⟹ const (?X ≐ ?S->including⇩S⇩e⇩t(?a))›*)) (*goals: 1. ‹⋀σ₁ X. const X ⟹ const λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 0 ⌊1300⌋ ⌊1⌋⌋⌋ .oclAsType(OclAny)› 2. ‹⋀σ₁ X. const X ⟹ const Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 1 ⌊1800⌋ ⌊1⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› 3. ‹⋀σ₁ X. const X ⟹ const X› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) (*discuss goal 5*) apply (rule OclIncluding_cong (*‹⟦?τ ⊨ δ ?t; ?τ ⊨ υ ?y; ?τ ⊨ ?s ≐ ?t; ?x = ?y⟧ ⟹ ?τ ⊨ ?s->including⇩S⇩e⇩t(?x) ≐ ?t->including⇩S⇩e⇩t(?y)›*)) (*goals: 1. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋), 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥), 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥), 1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 1 ⌊1800⌋ ⌊1⌋)], assocs = assocs σ₁'⦈) ⊨ δ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 1 ⌊1800⌋ ⌊1⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› 2. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋), 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥), 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥), 1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 1 ⌊1800⌋ ⌊1⌋)], assocs = assocs σ₁'⦈) ⊨ υ λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 0 ⌊1300⌋ ⌊1⌋⌋⌋ .oclAsType(OclAny)› 3. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋), 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥), 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥), 1 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 1 ⌊1800⌋ ⌊1⌋)], assocs = assocs σ₁'⦈) ⊨ OclAny .allInstances() ≐ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 1 ⌊1800⌋ ⌊1⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› 4. ‹⋀σ₁. (λ_. ⌊OclAny (in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 0 ⌊1300⌋ ⌊1⌋))⌋) = λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 0 ⌊1300⌋ ⌊1⌋⌋⌋ .oclAsType(OclAny)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (subst state_update_vs_allInstances_at_post_tc (*‹⟦?oid ∉ dom ?σ'; ?Type ?Object ≠ ⊥; cp ?P; ⋀X. const X ⟹ const (?P X)⟧ ⟹ ((?σ, ⦇heap = ?σ'(?oid ↦ ?Object), assocs = ?A⦈) ⊨ ?P ?Type .allInstances()) = ((?σ, ⦇heap = ?σ', assocs = ?A⦈) ⊨ ?P ?Type .allInstances()->including⇩S⇩e⇩t(λ_. ⌊?Type ?Object⌋))›*)) (*goals: 1. ‹⋀σ₁. 1 ∉ dom [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋), 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥), 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥)]› 2. ‹⋀σ₁. OclAny (in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 1 ⌊1800⌋ ⌊1⌋)) ≠ ⊥› 3. ‹⋀σ₁. cp (λa. a ≐ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 1 ⌊1800⌋ ⌊1⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)})› 4. ‹⋀σ₁ X. const X ⟹ const (X ≐ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 1 ⌊1800⌋ ⌊1⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)})› 5. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋), 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥), 2 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥)], assocs = assocs σ₁'⦈) ⊨ OclAny .allInstances()->including⇩S⇩e⇩t(λ_. ⌊OclAny (in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 1 ⌊1800⌋ ⌊1⌋))⌋) ≐ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 1 ⌊1800⌋ ⌊1⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄_def (*‹OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 = (λu::𝔄. ⌊case u of in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n (oid::nat) (a::⟨int⟩⇩⊥) (b::⟨nat⟩⇩⊥)) ⇒ mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y (a::type⇩O⇩c⇩l⇩A⇩n⇩y) ⇒ a⌋)›*)) (*discuss goal 3*) apply simp (*discuss goal 4*) apply (rule const_StrictRefEq⇩S⇩e⇩t_including (*‹⟦const (?a::?'a state × ?'a state ⇒ ?'b); const (?S::?'a state × ?'a state ⇒ Set(?'b)); const (?X::?'a state × ?'a state ⇒ Set(?'b))⟧ ⟹ const (?X ≐ ?S->including⇩S⇩e⇩t(?a))›*)) (*goals: 1. ‹⋀σ₁ X. const X ⟹ const λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 1 ⌊1800⌋ ⌊1⌋⌋⌋ .oclAsType(OclAny)› 2. ‹⋀σ₁ X. const X ⟹ const Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› 3. ‹⋀σ₁ X. const X ⟹ const X› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) (*discuss goal 5*) apply (rule OclIncluding_cong (*‹⟦?τ ⊨ δ ?t; ?τ ⊨ υ ?y; ?τ ⊨ ?s ≐ ?t; ?x = ?y⟧ ⟹ ?τ ⊨ ?s->including⇩S⇩e⇩t(?x) ≐ ?t->including⇩S⇩e⇩t(?y)›*)) (*goals: 1. ‹⋀σ₁::𝔄 state. (σ₁, ⦇heap = [8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n (8::nat) ⌊0::int⌋ ⊥), 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n (5::nat) ⌊2500::int⌋ ⌊6::nat⌋), 3::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n (3::nat) ⌊2900::int⌋ ⊥), 2::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n (2::nat) ⊥ ⊥)], assocs = assocs σ₁'⦈) ⊨ δ Set{λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n (2::nat) ⊥ ⊥⌋⌋ .oclAsType(OclAny), λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n (3::nat) ⌊2900::int⌋ ⊥⌋⌋ .oclAsType(OclAny), λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n (5::nat) ⌊2500::int⌋ ⌊6::nat⌋⌋⌋ .oclAsType(OclAny), λ_::𝔄 state × 𝔄 state. ⌊⌊person7⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊person8⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n (8::nat) ⌊0::int⌋ ⊥⌋⌋ .oclAsType(OclAny)}› 2. ‹⋀σ₁::𝔄 state. (σ₁, ⦇heap = [8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n (8::nat) ⌊0::int⌋ ⊥), 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n (5::nat) ⌊2500::int⌋ ⌊6::nat⌋), 3::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n (3::nat) ⌊2900::int⌋ ⊥), 2::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n (2::nat) ⊥ ⊥)], assocs = assocs σ₁'⦈) ⊨ υ λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n (1::nat) ⌊1800::int⌋ ⌊1::nat⌋⌋⌋ .oclAsType(OclAny)› 3. ‹⋀σ₁::𝔄 state. (σ₁, ⦇heap = [8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n (8::nat) ⌊0::int⌋ ⊥), 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n (5::nat) ⌊2500::int⌋ ⌊6::nat⌋), 3::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n (3::nat) ⌊2900::int⌋ ⊥), 2::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n (2::nat) ⊥ ⊥)], assocs = assocs σ₁'⦈) ⊨ OclAny .allInstances() ≐ Set{λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n (2::nat) ⊥ ⊥⌋⌋ .oclAsType(OclAny), λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n (3::nat) ⌊2900::int⌋ ⊥⌋⌋ .oclAsType(OclAny), λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n (5::nat) ⌊2500::int⌋ ⌊6::nat⌋⌋⌋ .oclAsType(OclAny), λ_::𝔄 state × 𝔄 state. ⌊⌊person7⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊person8⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n (8::nat) ⌊0::int⌋ ⊥⌋⌋ .oclAsType(OclAny)}› 4. ‹⋀σ₁::𝔄 state. (λ_::𝔄 state × 𝔄 state. ⌊OclAny (in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n (1::nat) ⌊1800::int⌋ ⌊1::nat⌋))⌋) = λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n (1::nat) ⌊1800::int⌋ ⌊1::nat⌋⌋⌋ .oclAsType(OclAny)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (subst state_update_vs_allInstances_at_post_tc (*‹⟦?oid ∉ dom ?σ'; ?Type ?Object ≠ ⊥; cp ?P; ⋀X. const X ⟹ const (?P X)⟧ ⟹ ((?σ, ⦇heap = ?σ'(?oid ↦ ?Object), assocs = ?A⦈) ⊨ ?P ?Type .allInstances()) = ((?σ, ⦇heap = ?σ', assocs = ?A⦈) ⊨ ?P ?Type .allInstances()->including⇩S⇩e⇩t(λ_. ⌊?Type ?Object⌋))›*)) (*goals: 1. ‹⋀σ₁. 2 ∉ dom [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋), 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥)]› 2. ‹⋀σ₁. OclAny (in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥)) ≠ ⊥› 3. ‹⋀σ₁. cp (λa. a ≐ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)})› 4. ‹⋀σ₁ X. const X ⟹ const (X ≐ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)})› 5. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋), 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥)], assocs = assocs σ₁'⦈) ⊨ OclAny .allInstances()->including⇩S⇩e⇩t(λ_. ⌊OclAny (in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥))⌋) ≐ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄_def (*‹OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 = (λu::𝔄. ⌊case u of in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n (oid::nat) (a::⟨int⟩⇩⊥) (b::⟨nat⟩⇩⊥)) ⇒ mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y (a::type⇩O⇩c⇩l⇩A⇩n⇩y) ⇒ a⌋)›*)) (*discuss goal 3*) apply simp (*discuss goal 4*) apply (rule const_StrictRefEq⇩S⇩e⇩t_including (*‹⟦const ?a; const ?S; const ?X⟧ ⟹ const (?X ≐ ?S->including⇩S⇩e⇩t(?a))›*)) (*goals: 1. ‹⋀σ₁ X. const X ⟹ const λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥⌋⌋ .oclAsType(OclAny)› 2. ‹⋀σ₁ X. const X ⟹ const Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› 3. ‹⋀σ₁ X. const X ⟹ const X› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) (*discuss goal 5*) apply (rule OclIncluding_cong (*‹⟦?τ ⊨ δ ?t; ?τ ⊨ υ ?y; ?τ ⊨ ?s ≐ ?t; ?x = ?y⟧ ⟹ ?τ ⊨ ?s->including⇩S⇩e⇩t(?x) ≐ ?t->including⇩S⇩e⇩t(?y)›*)) (*goals: 1. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋), 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥)], assocs = assocs σ₁'⦈) ⊨ δ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› 2. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋), 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥)], assocs = assocs σ₁'⦈) ⊨ υ λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥⌋⌋ .oclAsType(OclAny)› 3. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋), 3 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥)], assocs = assocs σ₁'⦈) ⊨ OclAny .allInstances() ≐ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› 4. ‹⋀σ₁. (λ_. ⌊OclAny (in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥))⌋) = λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 2 ⊥ ⊥⌋⌋ .oclAsType(OclAny)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (subst state_update_vs_allInstances_at_post_tc (*‹⟦?oid ∉ dom ?σ'; ?Type ?Object ≠ ⊥; cp ?P; ⋀X. const X ⟹ const (?P X)⟧ ⟹ ((?σ, ⦇heap = ?σ'(?oid ↦ ?Object), assocs = ?A⦈) ⊨ ?P ?Type .allInstances()) = ((?σ, ⦇heap = ?σ', assocs = ?A⦈) ⊨ ?P ?Type .allInstances()->including⇩S⇩e⇩t(λ_. ⌊?Type ?Object⌋))›*)) (*goals: 1. ‹⋀σ₁::𝔄 state. (3::nat) ∉ dom [8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n (8::nat) ⌊0::int⌋ ⊥), 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n (5::nat) ⌊2500::int⌋ ⌊6::nat⌋)]› 2. ‹⋀σ₁::𝔄 state. OclAny (in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n (3::nat) ⌊2900::int⌋ ⊥)) ≠ ⊥› 3. ‹⋀σ₁::𝔄 state. cp (λa::𝔄 state × 𝔄 state ⇒ Set(⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥). a ≐ Set{λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n (3::nat) ⌊2900::int⌋ ⊥⌋⌋ .oclAsType(OclAny), λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n (5::nat) ⌊2500::int⌋ ⌊6::nat⌋⌋⌋ .oclAsType(OclAny), λ_::𝔄 state × 𝔄 state. ⌊⌊person7⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊person8⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n (8::nat) ⌊0::int⌋ ⊥⌋⌋ .oclAsType(OclAny)})› 4. ‹⋀(σ₁::𝔄 state) X::𝔄 state × 𝔄 state ⇒ Set(⟨⟨type⇩O⇩c⇩l⇩A⇩n⇩y⟩⇩⊥⟩⇩⊥). const X ⟹ const (X ≐ Set{λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n (3::nat) ⌊2900::int⌋ ⊥⌋⌋ .oclAsType(OclAny), λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n (5::nat) ⌊2500::int⌋ ⌊6::nat⌋⌋⌋ .oclAsType(OclAny), λ_::𝔄 state × 𝔄 state. ⌊⌊person7⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊person8⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n (8::nat) ⌊0::int⌋ ⊥⌋⌋ .oclAsType(OclAny)})› 5. ‹⋀σ₁::𝔄 state. (σ₁, ⦇heap = [8::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n (8::nat) ⌊0::int⌋ ⊥), 7::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6::nat ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5::nat ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n (5::nat) ⌊2500::int⌋ ⌊6::nat⌋)], assocs = assocs σ₁'⦈) ⊨ OclAny .allInstances()->including⇩S⇩e⇩t(λ_::𝔄 state × 𝔄 state. ⌊OclAny (in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n (3::nat) ⌊2900::int⌋ ⊥))⌋) ≐ Set{λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n (3::nat) ⌊2900::int⌋ ⊥⌋⌋ .oclAsType(OclAny), λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n (5::nat) ⌊2500::int⌋ ⌊6::nat⌋⌋⌋ .oclAsType(OclAny), λ_::𝔄 state × 𝔄 state. ⌊⌊person7⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊person8⌋⌋, λ_::𝔄 state × 𝔄 state. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n (8::nat) ⌊0::int⌋ ⊥⌋⌋ .oclAsType(OclAny)}› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄_def (*‹OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 = (λu. ⌊case u of in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b) ⇒ mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y a ⇒ a⌋)›*)) (*discuss goal 3*) apply simp (*discuss goal 4*) apply (rule const_StrictRefEq⇩S⇩e⇩t_including (*‹⟦const ?a; const ?S; const ?X⟧ ⟹ const (?X ≐ ?S->including⇩S⇩e⇩t(?a))›*)) (*goals: 1. ‹⋀σ₁ X. const X ⟹ const λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥⌋⌋ .oclAsType(OclAny)› 2. ‹⋀σ₁ X. const X ⟹ const Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› 3. ‹⋀σ₁ X. const X ⟹ const X› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) (*discuss goal 5*) apply (rule OclIncluding_cong (*‹⟦?τ ⊨ δ ?t; ?τ ⊨ υ ?y; ?τ ⊨ ?s ≐ ?t; ?x = ?y⟧ ⟹ ?τ ⊨ ?s->including⇩S⇩e⇩t(?x) ≐ ?t->including⇩S⇩e⇩t(?y)›*)) (*goals: 1. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋)], assocs = assocs σ₁'⦈) ⊨ δ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› 2. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋)], assocs = assocs σ₁'⦈) ⊨ υ λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥⌋⌋ .oclAsType(OclAny)› 3. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7, 5 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋)], assocs = assocs σ₁'⦈) ⊨ OclAny .allInstances() ≐ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› 4. ‹⋀σ₁. (λ_. ⌊OclAny (in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥))⌋) = λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 3 ⌊2900⌋ ⊥⌋⌋ .oclAsType(OclAny)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (subst state_update_vs_allInstances_at_post_tc (*‹⟦?oid ∉ dom ?σ'; ?Type ?Object ≠ ⊥; cp ?P; ⋀X. const X ⟹ const (?P X)⟧ ⟹ ((?σ, ⦇heap = ?σ'(?oid ↦ ?Object), assocs = ?A⦈) ⊨ ?P ?Type .allInstances()) = ((?σ, ⦇heap = ?σ', assocs = ?A⦈) ⊨ ?P ?Type .allInstances()->including⇩S⇩e⇩t(λ_. ⌊?Type ?Object⌋))›*)) (*goals: 1. ‹⋀σ₁. 5 ∉ dom [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7]› 2. ‹⋀σ₁. OclAny (in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋)) ≠ ⊥› 3. ‹⋀σ₁. cp (λa. a ≐ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)})› 4. ‹⋀σ₁ X. const X ⟹ const (X ≐ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)})› 5. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7], assocs = assocs σ₁'⦈) ⊨ OclAny .allInstances()->including⇩S⇩e⇩t(λ_. ⌊OclAny (in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋))⌋) ≐ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny), λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄_def (*‹OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 = (λu. ⌊case u of in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b) ⇒ mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y a ⇒ a⌋)›*)) (*discuss goal 3*) apply simp (*discuss goal 4*) apply (rule const_StrictRefEq⇩S⇩e⇩t_including (*‹⟦const ?a; const ?S; const ?X⟧ ⟹ const (?X ≐ ?S->including⇩S⇩e⇩t(?a))›*)) (*goals: 1. ‹⋀σ₁ X. const X ⟹ const λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny)› 2. ‹⋀σ₁ X. const X ⟹ const Set{λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› 3. ‹⋀σ₁ X. const X ⟹ const X› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) (*discuss goal 5*) apply (rule OclIncluding_cong (*‹⟦?τ ⊨ δ ?t; ?τ ⊨ υ ?y; ?τ ⊨ ?s ≐ ?t; ?x = ?y⟧ ⟹ ?τ ⊨ ?s->including⇩S⇩e⇩t(?x) ≐ ?t->including⇩S⇩e⇩t(?y)›*)) (*goals: 1. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7], assocs = assocs σ₁'⦈) ⊨ δ Set{λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› 2. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7], assocs = assocs σ₁'⦈) ⊨ υ λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny)› 3. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8, 6 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person7], assocs = assocs σ₁'⦈) ⊨ OclAny .allInstances() ≐ Set{λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› 4. ‹⋀σ₁. (λ_. ⌊OclAny (in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋))⌋) = λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 5 ⌊2500⌋ ⌊6⌋⌋⌋ .oclAsType(OclAny)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (subst state_update_vs_allInstances_at_post_tc (*‹⟦?oid ∉ dom ?σ'; ?Type ?Object ≠ ⊥; cp ?P; ⋀X. const X ⟹ const (?P X)⟧ ⟹ ((?σ, ⦇heap = ?σ'(?oid ↦ ?Object), assocs = ?A⦈) ⊨ ?P ?Type .allInstances()) = ((?σ, ⦇heap = ?σ', assocs = ?A⦈) ⊨ ?P ?Type .allInstances()->including⇩S⇩e⇩t(λ_. ⌊?Type ?Object⌋))›*)) (*goals: 1. ‹⋀σ₁. 6 ∉ dom [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8]› 2. ‹⋀σ₁. OclAny (in⇩O⇩c⇩l⇩A⇩n⇩y person7) ≠ ⊥› 3. ‹⋀σ₁. cp (λa. a ≐ Set{λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)})› 4. ‹⋀σ₁ X. const X ⟹ const (X ≐ Set{λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)})› 5. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8], assocs = assocs σ₁'⦈) ⊨ OclAny .allInstances()->including⇩S⇩e⇩t(λ_. ⌊OclAny (in⇩O⇩c⇩l⇩A⇩n⇩y person7)⌋) ≐ Set{λ_. ⌊⌊person7⌋⌋, λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄_def (*‹OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 = (λu. ⌊case u of in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b) ⇒ mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y a ⇒ a⌋)›*)) (*discuss goal 3*) apply simp (*discuss goal 4*) apply (rule const_StrictRefEq⇩S⇩e⇩t_including (*‹⟦const (?a::?'a state × ?'a state ⇒ ?'b); const (?S::?'a state × ?'a state ⇒ Set(?'b)); const (?X::?'a state × ?'a state ⇒ Set(?'b))⟧ ⟹ const (?X ≐ ?S->including⇩S⇩e⇩t(?a))›*)) (*goals: 1. ‹⋀σ₁ X. const X ⟹ const (λ_. ⌊⌊person7⌋⌋)› 2. ‹⋀σ₁ X. const X ⟹ const Set{λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› 3. ‹⋀σ₁ X. const X ⟹ const X› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) (*discuss goal 5*) apply (rule OclIncluding_cong (*‹⟦?τ ⊨ δ ?t; ?τ ⊨ υ ?y; ?τ ⊨ ?s ≐ ?t; ?x = ?y⟧ ⟹ ?τ ⊨ ?s->including⇩S⇩e⇩t(?x) ≐ ?t->including⇩S⇩e⇩t(?y)›*)) (*goals: 1. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8], assocs = assocs σ₁'⦈) ⊨ δ Set{λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› 2. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8], assocs = assocs σ₁'⦈) ⊨ υ (λ_. ⌊⌊person7⌋⌋)› 3. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥), 7 ↦ in⇩O⇩c⇩l⇩A⇩n⇩y person8], assocs = assocs σ₁'⦈) ⊨ OclAny .allInstances() ≐ Set{λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› 4. ‹⋀σ₁. (λ_. ⌊OclAny (in⇩O⇩c⇩l⇩A⇩n⇩y person7)⌋) = (λ_. ⌊⌊person7⌋⌋)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (subst state_update_vs_allInstances_at_post_tc (*‹⟦?oid ∉ dom ?σ'; ?Type ?Object ≠ ⊥; cp ?P; ⋀X. const X ⟹ const (?P X)⟧ ⟹ ((?σ, ⦇heap = ?σ'(?oid ↦ ?Object), assocs = ?A⦈) ⊨ ?P ?Type .allInstances()) = ((?σ, ⦇heap = ?σ', assocs = ?A⦈) ⊨ ?P ?Type .allInstances()->including⇩S⇩e⇩t(λ_. ⌊?Type ?Object⌋))›*)) (*goals: 1. ‹⋀σ₁. 7 ∉ dom [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥)]› 2. ‹⋀σ₁. OclAny (in⇩O⇩c⇩l⇩A⇩n⇩y person8) ≠ ⊥› 3. ‹⋀σ₁. cp (λa. a ≐ Set{λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)})› 4. ‹⋀σ₁ X. const X ⟹ const (X ≐ Set{λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)})› 5. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥)], assocs = assocs σ₁'⦈) ⊨ OclAny .allInstances()->including⇩S⇩e⇩t(λ_. ⌊OclAny (in⇩O⇩c⇩l⇩A⇩n⇩y person8)⌋) ≐ Set{λ_. ⌊⌊person8⌋⌋, λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄_def (*‹OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 = (λu. ⌊case u of in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b) ⇒ mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y a ⇒ a⌋)›*)) (*discuss goal 3*) apply simp (*discuss goal 4*) apply (rule const_StrictRefEq⇩S⇩e⇩t_including (*‹⟦const ?a; const ?S; const ?X⟧ ⟹ const (?X ≐ ?S->including⇩S⇩e⇩t(?a))›*)) (*goals: 1. ‹⋀σ₁ X. const X ⟹ const (λ_. ⌊⌊person8⌋⌋)› 2. ‹⋀σ₁ X. const X ⟹ const Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› 3. ‹⋀σ₁ X. const X ⟹ const X› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) (*discuss goal 5*) apply (rule OclIncluding_cong (*‹⟦?τ ⊨ δ ?t; ?τ ⊨ υ ?y; ?τ ⊨ ?s ≐ ?t; ?x = ?y⟧ ⟹ ?τ ⊨ ?s->including⇩S⇩e⇩t(?x) ≐ ?t->including⇩S⇩e⇩t(?y)›*)) (*goals: 1. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥)], assocs = assocs σ₁'⦈) ⊨ δ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› 2. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥)], assocs = assocs σ₁'⦈) ⊨ υ (λ_. ⌊⌊person8⌋⌋)› 3. ‹⋀σ₁. (σ₁, ⦇heap = [8 ↦ in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥)], assocs = assocs σ₁'⦈) ⊨ OclAny .allInstances() ≐ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› 4. ‹⋀σ₁. (λ_. ⌊OclAny (in⇩O⇩c⇩l⇩A⇩n⇩y person8)⌋) = (λ_. ⌊⌊person8⌋⌋)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (subst state_update_vs_allInstances_at_post_tc (*‹⟦?oid ∉ dom ?σ'; ?Type ?Object ≠ ⊥; cp ?P; ⋀X. const X ⟹ const (?P X)⟧ ⟹ ((?σ, ⦇heap = ?σ'(?oid ↦ ?Object), assocs = ?A⦈) ⊨ ?P ?Type .allInstances()) = ((?σ, ⦇heap = ?σ', assocs = ?A⦈) ⊨ ?P ?Type .allInstances()->including⇩S⇩e⇩t(λ_. ⌊?Type ?Object⌋))›*)) (*goals: 1. ‹⋀σ₁. 8 ∉ dom (λa. ⊥)› 2. ‹⋀σ₁. OclAny (in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥)) ≠ ⊥› 3. ‹⋀σ₁. cp (λa. a ≐ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)})› 4. ‹⋀σ₁ X. const X ⟹ const (X ≐ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)})› 5. ‹⋀σ₁. (σ₁, ⦇heap = λa. ⊥, assocs = assocs σ₁'⦈) ⊨ OclAny .allInstances()->including⇩S⇩e⇩t(λ_. ⌊OclAny (in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥))⌋) ≐ Set{λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)}› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄_def (*‹OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 = (λu. ⌊case u of in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b) ⇒ mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y a ⇒ a⌋)›*)) (*discuss goal 3*) apply simp (*discuss goal 4*) apply (rule const_StrictRefEq⇩S⇩e⇩t_including (*‹⟦const ?a; const ?S; const ?X⟧ ⟹ const (?X ≐ ?S->including⇩S⇩e⇩t(?a))›*)) (*goals: 1. ‹⋀σ₁ X. const X ⟹ const λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)› 2. ‹⋀σ₁ X. const X ⟹ const Set{}› 3. ‹⋀σ₁ X. const X ⟹ const X› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) (*discuss goal 5*) apply (rule OclIncluding_cong (*‹⟦?τ ⊨ δ ?t; ?τ ⊨ υ ?y; ?τ ⊨ ?s ≐ ?t; ?x = ?y⟧ ⟹ ?τ ⊨ ?s->including⇩S⇩e⇩t(?x) ≐ ?t->including⇩S⇩e⇩t(?y)›*)) (*goals: 1. ‹⋀σ₁. (σ₁, ⦇heap = λa. ⊥, assocs = assocs σ₁'⦈) ⊨ δ Set{}› 2. ‹⋀σ₁. (σ₁, ⦇heap = λa. ⊥, assocs = assocs σ₁'⦈) ⊨ υ λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)› 3. ‹⋀σ₁. (σ₁, ⦇heap = λa. ⊥, assocs = assocs σ₁'⦈) ⊨ OclAny .allInstances() ≐ Set{}› 4. ‹⋀σ₁. (λ_. ⌊OclAny (in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥))⌋) = λ_. ⌊⌊mk⇩P⇩e⇩r⇩s⇩o⇩n 8 ⌊0⌋ ⊥⌋⌋ .oclAsType(OclAny)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (rule state_update_vs_allInstances_at_post_empty (*‹(?σ, ⦇heap = λx. ⊥, assocs = ?A⦈) ⊨ ?Type .allInstances() ≐ Set{}›*)) (*discuss goal 4*) apply (simp add: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄_def (*‹OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 = (λu. ⌊case u of in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b) ⇒ mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y a ⇒ a⌋)›*)) (*proven 4 subgoals*) (*proven 5 subgoals*) (*discuss goal 4*) apply (simp add: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄_def (*‹OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 = (λu. ⌊case u of in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b) ⇒ mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y a ⇒ a⌋)›*)) (*proven 4 subgoals*) (*proven 5 subgoals*) (*discuss goal 4*) apply (simp add: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄_def (*‹OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 = (λu. ⌊case u of in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b) ⇒ mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y a ⇒ a⌋)›*)) (*proven 4 subgoals*) (*proven 5 subgoals*) (*discuss goal 4*) apply (simp add: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄_def (*‹OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 = (λu. ⌊case u of in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b) ⇒ mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y a ⇒ a⌋)›*)) (*proven 4 subgoals*) (*proven 5 subgoals*) (*discuss goal 4*) apply (simp add: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄_def (*‹OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 = (λu. ⌊case u of in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b) ⇒ mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y a ⇒ a⌋)›*)) (*proven 4 subgoals*) (*proven 5 subgoals*) (*discuss goal 4*) apply (simp add: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄_def (*‹OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 = (λu::𝔄. ⌊case u of in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n (oid::nat) (a::⟨int⟩⇩⊥) (b::⟨nat⟩⇩⊥)) ⇒ mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y (a::type⇩O⇩c⇩l⇩A⇩n⇩y) ⇒ a⌋)›*)) (*proven 4 subgoals*) (*proven 5 subgoals*) (*discuss goal 4*) apply (simp add: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄_def (*‹OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 = (λu. ⌊case u of in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b) ⇒ mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y a ⇒ a⌋)›*)) (*proven 4 subgoals*) (*proven 5 subgoals*) (*discuss goal 4*) apply (simp add: OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄_def (*‹OclAsType⇩O⇩c⇩l⇩A⇩n⇩y_𝔄 = (λu. ⌊case u of in⇩P⇩e⇩r⇩s⇩o⇩n (mk⇩P⇩e⇩r⇩s⇩o⇩n oid a b) ⇒ mk⇩O⇩c⇩l⇩A⇩n⇩y oid ⌊(a, b)⌋ | in⇩O⇩c⇩l⇩A⇩n⇩y a ⇒ a⌋)›*)) (*proven 4 subgoals*) (*proven 5 subgoals*) . end
{ "path": "afp-2025-02-12/thys/Featherweight_OCL/examples/Employee_Model/Design/Design_UML.thy", "repo": "afp-2025-02-12", "sha": "9c61cdf19226f004551b2f608d3b5d6d98b4b33253ce9ab4a536f73f31dabfaa" }
(* Title: HOL/Nonstandard_Analysis/CLim.thy Author: Jacques D. Fleuriot Copyright: 2001 University of Edinburgh Conversion to Isar and new proofs by Lawrence C Paulson, 2004 *) section ‹Limits, Continuity and Differentiation for Complex Functions› theory CLim imports CStar begin (*not in simpset?*) declare epsilon_not_zero [simp] (*??generalize*) lemma lemma_complex_mult_inverse_squared [simp]: "x ≠ 0 ⟹ x * (inverse x)² = inverse x" for x :: complex by (simp add: numeral_2_eq_2 (*‹2 = Suc (Suc 0)›*)) text ‹Changing the quantified variable. Install earlier?› lemma all_shift: "(∀x::'a::comm_ring_1. P x) ⟷ (∀x. P (x - a))" by (metis add_diff_cancel (*‹?a + ?b - ?b = ?a›*)) subsection ‹Limit of Complex to Complex Function› lemma NSLIM_Re: "f ─a→⇩N⇩S L ⟹ (λx. Re (f x)) ─a→⇩N⇩S Re L" by (simp add: NSLIM_def (*‹?f ─?a→⇩N⇩S ?L = (∀x. x ≠ star_of ?a ∧ x ≈ star_of ?a ⟶ (*f* ?f) x ≈ star_of ?L)›*) starfunC_approx_Re_Im_iff (*‹((*f* ?f) ?x ≈ ?z) = ((*f* (λx. Re (?f x))) ?x ≈ hRe ?z ∧ (*f* (λx. Im (?f x))) ?x ≈ hIm ?z)›*) hRe_hcomplex_of_complex (*‹hRe (hcomplex_of_complex ?z) = hypreal_of_real (Re ?z)›*)) lemma NSLIM_Im: "f ─a→⇩N⇩S L ⟹ (λx. Im (f x)) ─a→⇩N⇩S Im L" by (simp add: NSLIM_def (*‹?f ─?a→⇩N⇩S ?L = (∀x. x ≠ star_of ?a ∧ x ≈ star_of ?a ⟶ (*f* ?f) x ≈ star_of ?L)›*) starfunC_approx_Re_Im_iff (*‹((*f* ?f) ?x ≈ ?z) = ((*f* (λx. Re (?f x))) ?x ≈ hRe ?z ∧ (*f* (λx. Im (?f x))) ?x ≈ hIm ?z)›*) hIm_hcomplex_of_complex (*‹hIm (hcomplex_of_complex ?z) = hypreal_of_real (Im ?z)›*)) lemma LIM_Re: "f ─a→ L ⟹ (λx. Re (f x)) ─a→ Re L" for f :: "'a::real_normed_vector ⇒ complex" by (simp add: LIM_NSLIM_iff (*‹?f ─?x→ ?L = ?f ─?x→⇩N⇩S ?L›*) NSLIM_Re (*‹?f ─?a→⇩N⇩S ?L ⟹ (λx. Re (?f x)) ─?a→⇩N⇩S Re ?L›*)) lemma LIM_Im: "f ─a→ L ⟹ (λx. Im (f x)) ─a→ Im L" for f :: "'a::real_normed_vector ⇒ complex" by (simp add: LIM_NSLIM_iff (*‹?f ─?x→ ?L = ?f ─?x→⇩N⇩S ?L›*) NSLIM_Im (*‹?f ─?a→⇩N⇩S ?L ⟹ (λx. Im (?f x)) ─?a→⇩N⇩S Im ?L›*)) lemma LIM_cnj: "f ─a→ L ⟹ (λx. cnj (f x)) ─a→ cnj L" for f :: "'a::real_normed_vector ⇒ complex" by (simp add: LIM_eq (*‹?f ─?a→ ?L = (∀r>0. ∃s>0. ∀x. x ≠ ?a ∧ norm (x - ?a) < s ⟶ norm (?f x - ?L) < r)›*) complex_cnj_diff [symmetric] (*‹cnj ?x - cnj ?y = cnj (?x - ?y)›*) del: complex_cnj_diff (*‹cnj (?x - ?y) = cnj ?x - cnj ?y›*)) lemma LIM_cnj_iff: "((λx. cnj (f x)) ─a→ cnj L) ⟷ f ─a→ L" for f :: "'a::real_normed_vector ⇒ complex" by (simp add: LIM_eq (*‹?f ─?a→ ?L = (∀r>0. ∃s>0. ∀x. x ≠ ?a ∧ norm (x - ?a) < s ⟶ norm (?f x - ?L) < r)›*) complex_cnj_diff [symmetric] (*‹cnj ?x - cnj ?y = cnj (?x - ?y)›*) del: complex_cnj_diff (*‹cnj (?x - ?y) = cnj ?x - cnj ?y›*)) lemma starfun_norm: "( *f* (λx. norm (f x))) = (λx. hnorm (( *f* f) x))" apply transfer (*goal: ‹*f* (λx. norm (f x)) = (λx. hnorm ((*f* f) x))›*) by (rule refl (*‹?t = ?t›*)) lemma star_of_Re [simp]: "star_of (Re x) = hRe (star_of x)" apply transfer (*goal: ‹hypreal_of_real (Re x) = hRe (hcomplex_of_complex x)›*) by (rule refl (*‹?t = ?t›*)) lemma star_of_Im [simp]: "star_of (Im x) = hIm (star_of x)" apply transfer (*goal: ‹hypreal_of_real (Im x) = hIm (hcomplex_of_complex x)›*) by (rule refl (*‹?t = ?t›*)) text ‹Another equivalence result.› lemma NSCLIM_NSCRLIM_iff: "f ─x→⇩N⇩S L ⟷ (λy. cmod (f y - L)) ─x→⇩N⇩S 0" by (simp add: NSLIM_def (*‹?f ─?a→⇩N⇩S ?L = (∀x. x ≠ star_of ?a ∧ x ≈ star_of ?a ⟶ (*f* ?f) x ≈ star_of ?L)›*) starfun_norm (*‹*f* (λx. norm (?f x)) = (λx. hnorm ((*f* ?f) x))›*) approx_approx_zero_iff [symmetric] (*‹(hcmod ?x ≈ 0) = (?x ≈ 0)›*) approx_minus_iff [symmetric] (*‹(?x - ?y ≈ 0) = (?x ≈ ?y)›*)) text ‹Much, much easier standard proof.› lemma CLIM_CRLIM_iff: "f ─x→ L ⟷ (λy. cmod (f y - L)) ─x→ 0" for f :: "'a::real_normed_vector ⇒ complex" by (simp add: LIM_eq (*‹(?f::?'a ⇒ ?'b) ─?a::?'a→ (?L::?'b) = (∀r>0::real. ∃s>0::real. ∀x::?'a. x ≠ ?a ∧ norm (x - ?a) < s ⟶ norm (?f x - ?L) < r)›*)) text ‹So this is nicer nonstandard proof.› lemma NSCLIM_NSCRLIM_iff2: "f ─x→⇩N⇩S L ⟷ (λy. cmod (f y - L)) ─x→⇩N⇩S 0" by (simp add: LIM_NSLIM_iff [symmetric] (*‹?f ─?x→⇩N⇩S ?L = ?f ─?x→ ?L›*) CLIM_CRLIM_iff (*‹?f ─?x→ ?L = (λy. cmod (?f y - ?L)) ─?x→ 0›*)) lemma NSLIM_NSCRLIM_Re_Im_iff: "f ─a→⇩N⇩S L ⟷ (λx. Re (f x)) ─a→⇩N⇩S Re L ∧ (λx. Im (f x)) ─a→⇩N⇩S Im L" apply (auto intro: NSLIM_Re (*‹?f ─?a→⇩N⇩S ?L ⟹ (λx. Re (?f x)) ─?a→⇩N⇩S Re ?L›*) NSLIM_Im (*‹?f ─?a→⇩N⇩S ?L ⟹ (λx. Im (?f x)) ─?a→⇩N⇩S Im ?L›*)) (*goal: ‹f ─a→⇩N⇩S L = ((λx. Re (f x)) ─a→⇩N⇩S Re L ∧ (λx. Im (f x)) ─a→⇩N⇩S Im L)›*) apply (auto simp add: NSLIM_def (*‹?f ─?a→⇩N⇩S ?L = (∀x. x ≠ star_of ?a ∧ x ≈ star_of ?a ⟶ (*f* ?f) x ≈ star_of ?L)›*) starfun_Re (*‹*f* (λx. Re (?f x)) = (λx. hRe ((*f* ?f) x))›*) starfun_Im (*‹*f* (λx. Im (?f x)) = (λx. hIm ((*f* ?f) x))›*)) (*goal: ‹⟦(λx. Re (f x)) ─a→⇩N⇩S Re L; (λx. Im (f x)) ─a→⇩N⇩S Im L⟧ ⟹ f ─a→⇩N⇩S L›*) apply (auto dest!: spec (*‹∀x. ?P x ⟹ ?P ?x›*)) (*goal: ‹⋀x. ⟦∀x. x ≠ star_of a ∧ x ≈ star_of a ⟶ hRe ((*f* f) x) ≈ hRe (hcomplex_of_complex L); ∀x. x ≠ star_of a ∧ x ≈ star_of a ⟶ hIm ((*f* f) x) ≈ hIm (hcomplex_of_complex L); x ≠ star_of a; x ≈ star_of a⟧ ⟹ (*f* f) x ≈ hcomplex_of_complex L›*) by (simp add: hcomplex_approx_iff (*‹(?x ≈ ?y) = (hRe ?x ≈ hRe ?y ∧ hIm ?x ≈ hIm ?y)›*)) lemma LIM_CRLIM_Re_Im_iff: "f ─a→ L ⟷ (λx. Re (f x)) ─a→ Re L ∧ (λx. Im (f x)) ─a→ Im L" for f :: "'a::real_normed_vector ⇒ complex" by (simp add: LIM_NSLIM_iff (*‹?f ─?x→ ?L = ?f ─?x→⇩N⇩S ?L›*) NSLIM_NSCRLIM_Re_Im_iff (*‹?f ─?a→⇩N⇩S ?L = ((λx. Re (?f x)) ─?a→⇩N⇩S Re ?L ∧ (λx. Im (?f x)) ─?a→⇩N⇩S Im ?L)›*)) subsection ‹Continuity› lemma NSLIM_isContc_iff: "f ─a→⇩N⇩S f a ⟷ (λh. f (a + h)) ─0→⇩N⇩S f a" by (rule NSLIM_at0_iff (*‹?f ─?a→⇩N⇩S ?L = (λh. ?f (?a + h)) ─0→⇩N⇩S ?L›*)) subsection ‹Functions from Complex to Reals› lemma isNSContCR_cmod [simp]: "isNSCont cmod a" by (auto intro: approx_hnorm (*‹(?x::?'a star) ≈ (?y::?'a star) ⟹ hnorm ?x ≈ hnorm ?y›*) simp: starfunCR_cmod (*‹*f* cmod = hcmod›*) hcmod_hcomplex_of_complex [symmetric] (*‹hypreal_of_real (cmod (?x::complex)) = hcmod (hcomplex_of_complex ?x)›*) isNSCont_def (*‹isNSCont (?f::?'a ⇒ ?'b) (?a::?'a) = (∀y::?'a star. y ≈ star_of ?a ⟶ (*f* ?f) y ≈ star_of (?f ?a))›*)) lemma isContCR_cmod [simp]: "isCont cmod a" by (simp add: isNSCont_isCont_iff [symmetric] (*‹isCont (?f::?'a::real_normed_vector ⇒ ?'b::real_normed_vector) (?a::?'a::real_normed_vector) = isNSCont ?f ?a›*)) lemma isCont_Re: "isCont f a ⟹ isCont (λx. Re (f x)) a" for f :: "'a::real_normed_vector ⇒ complex" by (simp add: isCont_def (*‹isCont ?f ?a = ?f ─?a→ ?f ?a›*) LIM_Re (*‹?f ─?a→ ?L ⟹ (λx. Re (?f x)) ─?a→ Re ?L›*)) lemma isCont_Im: "isCont f a ⟹ isCont (λx. Im (f x)) a" for f :: "'a::real_normed_vector ⇒ complex" by (simp add: isCont_def (*‹isCont (?f::?'a ⇒ ?'b) (?a::?'a) = ?f ─?a→ ?f ?a›*) LIM_Im (*‹(?f::?'a ⇒ complex) ─?a::?'a→ (?L::complex) ⟹ (λx::?'a. Im (?f x)) ─?a→ Im ?L›*)) subsection ‹Differentiation of Natural Number Powers› lemma CDERIV_pow [simp]: "DERIV (λx. x ^ n) x :> complex_of_real (real n) * (x ^ (n - Suc 0))" apply (induct n) (*goal: ‹((λx::complex. x ^ (n::nat)) has_field_derivative complex_of_real (real n) * (x::complex) ^ (n - Suc (0::nat))) (at x)›*) apply (drule_tac [2] DERIV_ident [THEN DERIV_mult] (*‹(?g has_field_derivative ?Db) (at ?x within ?s) ⟹ ((λx. x * ?g x) has_field_derivative 1 * ?g ?x + ?Db * ?x) (at ?x within ?s)›*)) (*top goal: ‹((λx. x ^ 0) has_field_derivative complex_of_real (real 0) * x ^ (0 - Suc 0)) (at x)› and 1 goal remains*) apply (auto simp add: distrib_right (*‹((?a::?'a::semiring) + (?b::?'a::semiring)) * (?c::?'a::semiring) = ?a * ?c + ?b * ?c›*) of_nat_Suc (*‹of_nat (Suc (?m::nat)) = (1::?'a::semiring_1) + of_nat ?m›*)) (*top goal: ‹((λx. x ^ 0) has_field_derivative complex_of_real (real 0) * x ^ (0 - Suc 0)) (at x)› and 1 goal remains*) apply (case_tac "n") (*goal: ‹⋀n. ((λx. x * x ^ n) has_field_derivative x ^ n + complex_of_nat n * x ^ (n - Suc 0) * x) (at x) ⟹ ((λx. x * x ^ n) has_field_derivative x ^ n + complex_of_nat n * x ^ n) (at x)›*) by (auto simp add: ac_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹((?a ∧ ?b) ∧ ?c) = (?a ∧ ?b ∧ ?c)› ‹(?a ∧ ?b) = (?b ∧ ?a)› ‹(?b ∧ ?a ∧ ?c) = (?a ∧ ?b ∧ ?c)› ‹((?a ∨ ?b) ∨ ?c) = (?a ∨ ?b ∨ ?c)› ‹(?a ∨ ?b) = (?b ∨ ?a)› ‹(?b ∨ ?a ∨ ?c) = (?a ∨ ?b ∨ ?c)› and more 30 facts*)) text ‹Nonstandard version.› lemma NSCDERIV_pow: "NSDERIV (λx. x ^ n) x :> complex_of_real (real n) * (x ^ (n - 1))" by (metis CDERIV_pow (*‹((λx. x ^ ?n) has_field_derivative complex_of_real (real ?n) * ?x ^ (?n - Suc 0)) (at ?x)›*) NSDERIV_DERIV_iff (*‹NSDERIV ?f ?x :> ?D = (?f has_field_derivative ?D) (at ?x)›*) One_nat_def (*‹1 = Suc 0›*)) text ‹Can't relax the premise \<^term>‹x ≠ 0›: it isn't continuous at zero.› lemma NSCDERIV_inverse: "x ≠ 0 ⟹ NSDERIV (λx. inverse x) x :> - (inverse x)²" for x :: complex unfolding numeral_2_eq_2 (*goal: ‹x ≠ 0 ⟹ NSDERIV inverse x :> - (inverse x ^ Suc (Suc 0))›*) by (rule NSDERIV_inverse (*‹?x ≠ 0 ⟹ NSDERIV inverse ?x :> - (inverse ?x ^ Suc (Suc 0))›*)) lemma CDERIV_inverse: "x ≠ 0 ⟹ DERIV (λx. inverse x) x :> - (inverse x)²" for x :: complex unfolding numeral_2_eq_2 (*goal: ‹x ≠ 0 ⟹ (inverse has_field_derivative - (inverse x ^ Suc (Suc 0))) (at x)›*) by (rule DERIV_inverse (*‹(?x::?'a) ≠ (0::?'a) ⟹ (inverse has_field_derivative - (inverse ?x ^ Suc (Suc (0::nat)))) (at ?x within (?s::?'a set))›*)) subsection ‹Derivative of Reciprocals (Function \<^term>‹inverse›)› lemma CDERIV_inverse_fun: "DERIV f x :> d ⟹ f x ≠ 0 ⟹ DERIV (λx. inverse (f x)) x :> - (d * inverse ((f x)²))" for x :: complex unfolding numeral_2_eq_2 (*goal: ‹⟦((f::complex ⇒ complex) has_field_derivative (d::complex)) (at (x::complex)); f x ≠ (0::complex)⟧ ⟹ ((λx::complex. inverse (f x)) has_field_derivative - (d * inverse (f x ^ Suc (Suc (0::nat))))) (at x)›*) apply (rule DERIV_inverse_fun (*‹⟦(?f has_field_derivative ?d) (at ?x within ?s); ?f ?x ≠ 0⟧ ⟹ ((λx. inverse (?f x)) has_field_derivative - (?d * inverse (?f ?x ^ Suc (Suc 0)))) (at ?x within ?s)›*)) (*goals: 1. ‹⟦(f has_field_derivative d) (at x); f x ≠ 0⟧ ⟹ (f has_field_derivative d) (at x)› 2. ‹⟦(f has_field_derivative d) (at x); f x ≠ 0⟧ ⟹ f x ≠ 0› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) lemma NSCDERIV_inverse_fun: "NSDERIV f x :> d ⟹ f x ≠ 0 ⟹ NSDERIV (λx. inverse (f x)) x :> - (d * inverse ((f x)²))" for x :: complex unfolding numeral_2_eq_2 (*goal: ‹⟦NSDERIV (f::complex ⇒ complex) (x::complex) :> (d::complex); f x ≠ (0::complex)⟧ ⟹ NSDERIV (λx::complex. inverse (f x)) x :> - (d * inverse (f x ^ Suc (Suc (0::nat))))›*) apply (rule NSDERIV_inverse_fun (*‹⟦NSDERIV (?f::?'a ⇒ ?'a) (?x::?'a) :> (?d::?'a); ?f ?x ≠ (0::?'a)⟧ ⟹ NSDERIV (λx::?'a. inverse (?f x)) ?x :> - (?d * inverse (?f ?x ^ Suc (Suc (0::nat))))›*)) (*goals: 1. ‹⟦NSDERIV f x :> d; f x ≠ 0⟧ ⟹ NSDERIV f x :> d› 2. ‹⟦NSDERIV f x :> d; f x ≠ 0⟧ ⟹ f x ≠ 0› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) subsection ‹Derivative of Quotient› lemma CDERIV_quotient: "DERIV f x :> d ⟹ DERIV g x :> e ⟹ g(x) ≠ 0 ⟹ DERIV (λy. f y / g y) x :> (d * g x - (e * f x)) / (g x)²" for x :: complex unfolding numeral_2_eq_2 (*goal: ‹⟦(f has_field_derivative d) (at x); (g has_field_derivative e) (at x); g x ≠ 0⟧ ⟹ ((λy. f y / g y) has_field_derivative (d * g x - e * f x) / g x ^ Suc (Suc 0)) (at x)›*) apply (rule DERIV_quotient (*‹⟦((?f::?'a ⇒ ?'a) has_field_derivative (?d::?'a)) (at (?x::?'a) within (?s::?'a set)); ((?g::?'a ⇒ ?'a) has_field_derivative (?e::?'a)) (at ?x within ?s); ?g ?x ≠ (0::?'a)⟧ ⟹ ((λy::?'a. ?f y / ?g y) has_field_derivative (?d * ?g ?x - ?e * ?f ?x) / ?g ?x ^ Suc (Suc (0::nat))) (at ?x within ?s)›*)) (*goals: 1. ‹⟦(f has_field_derivative d) (at x); (g has_field_derivative e) (at x); g x ≠ 0⟧ ⟹ (f has_field_derivative d) (at x)› 2. ‹⟦(f has_field_derivative d) (at x); (g has_field_derivative e) (at x); g x ≠ 0⟧ ⟹ (g has_field_derivative e) (at x)› 3. ‹⟦(f has_field_derivative d) (at x); (g has_field_derivative e) (at x); g x ≠ 0⟧ ⟹ g x ≠ 0› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) apply ((assumption)[1]) (*discuss goal 3*) . (*proven 3 subgoals*) lemma NSCDERIV_quotient: "NSDERIV f x :> d ⟹ NSDERIV g x :> e ⟹ g x ≠ (0::complex) ⟹ NSDERIV (λy. f y / g y) x :> (d * g x - (e * f x)) / (g x)²" unfolding numeral_2_eq_2 (*goal: ‹⟦NSDERIV f x :> d; NSDERIV g x :> e; g x ≠ 0⟧ ⟹ NSDERIV (λy. f y / g y) x :> (d * g x - e * f x) / g x ^ Suc (Suc 0)›*) apply (rule NSDERIV_quotient (*‹⟦NSDERIV (?f::?'a::real_normed_field ⇒ ?'a::real_normed_field) (?x::?'a::real_normed_field) :> (?d::?'a::real_normed_field); NSDERIV (?g::?'a::real_normed_field ⇒ ?'a::real_normed_field) ?x :> (?e::?'a::real_normed_field); ?g ?x ≠ (0::?'a::real_normed_field)⟧ ⟹ NSDERIV (λy::?'a::real_normed_field. ?f y / ?g y) ?x :> (?d * ?g ?x - ?e * ?f ?x) / ?g ?x ^ Suc (Suc (0::nat))›*)) (*goals: 1. ‹⟦NSDERIV f x :> d; NSDERIV g x :> e; g x ≠ 0⟧ ⟹ NSDERIV f x :> d› 2. ‹⟦NSDERIV f x :> d; NSDERIV g x :> e; g x ≠ 0⟧ ⟹ NSDERIV g x :> e› 3. ‹⟦NSDERIV f x :> d; NSDERIV g x :> e; g x ≠ 0⟧ ⟹ g x ≠ 0› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) apply ((assumption)[1]) (*discuss goal 3*) . (*proven 3 subgoals*) subsection ‹Caratheodory Formulation of Derivative at a Point: Standard Proof› lemma CARAT_CDERIVD: "(∀z. f z - f x = g z * (z - x)) ∧ isNSCont g x ∧ g x = l ⟹ NSDERIV f x :> l" apply clarify (*goal: ‹(∀z::'a::real_normed_field. (f::'a::real_normed_field ⇒ 'a::real_normed_field) z - f (x::'a::real_normed_field) = (g::'a::real_normed_field ⇒ 'a::real_normed_field) z * (z - x)) ∧ isNSCont g x ∧ g x = (l::'a::real_normed_field) ⟹ NSDERIV f x :> l›*) apply (rule CARAT_DERIVD (*‹⟦∀z. ?f z - ?f ?x = ?g z * (z - ?x); isNSCont ?g ?x⟧ ⟹ NSDERIV ?f ?x :> ?g ?x›*)) (*goals: 1. ‹⟦∀z. f z - f x = g z * (z - x); isNSCont g x; l = g x⟧ ⟹ ∀z. f z - f x = g z * (z - x)› 2. ‹⟦∀z. f z - f x = g z * (z - x); isNSCont g x; l = g x⟧ ⟹ isNSCont g x› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) end
{ "path": "Isabelle2024/src/HOL/Nonstandard_Analysis/CLim.thy", "repo": "Isabelle2024", "sha": "d14d4c377245aa4514fd9f1e15b92c3fb93c049142bdc98a48ddabad4cdd02e4" }
(* Title: HOL/HOLCF/IOA/Deadlock.thy Author: Olaf Müller *) section ‹Deadlock freedom of I/O Automata› theory Deadlock imports RefCorrectness CompoScheds begin text ‹Input actions may always be added to a schedule.› lemma scheds_input_enabled: "Filter (λx. x ∈ act A) ⋅ sch ∈ schedules A ⟹ a ∈ inp A ⟹ input_enabled A ⟹ Finite sch ⟹ Filter (λx. x ∈ act A) ⋅ sch @@ a ↝ nil ∈ schedules A" apply (simp add: schedules_def (*‹schedules ?ioa = {sch. has_schedule ?ioa sch}›*) has_schedule_def (*‹has_schedule ?ioa ?sch = (∃ex∈executions ?ioa. ?sch = filter_act⋅(snd ex))›*)) (*goal: ‹⟦Filter (λx. x ∈ act A)⋅sch ∈ schedules A; a ∈ inp A; input_enabled A; Finite sch⟧ ⟹ Filter (λx. x ∈ act A)⋅sch @@ [a!] ∈ schedules A›*) apply auto (*goal: ‹⟦∃ex∈executions A. Filter (λx. x ∈ act A)⋅sch = filter_act⋅(snd ex); a ∈ inp A; input_enabled A; Finite sch⟧ ⟹ ∃ex∈executions A. Filter (λx. x ∈ act A)⋅sch @@ [a!] = filter_act⋅(snd ex)›*) apply (frule inp_is_act (*‹(?a::?'a) ∈ inputs (?S::?'a set × ?'a set × ?'a set) ⟹ ?a ∈ actions ?S›*)) (*goal: ‹⋀ex. ⟦a ∈ inp A; input_enabled A; Finite sch; ex ∈ executions A; Filter (λx. x ∈ act A)⋅sch = filter_act⋅(snd ex)⟧ ⟹ ∃exa∈executions A. filter_act⋅(snd ex) @@ [a!] = filter_act⋅(snd exa)›*) apply (simp add: executions_def (*‹executions ?ioa = {e. fst e ∈ starts_of ?ioa ∧ is_exec_frag ?ioa e}›*)) (*goal: ‹⋀ex. ⟦a ∈ inp A; input_enabled A; Finite sch; ex ∈ executions A; Filter (λx. x ∈ act A)⋅sch = filter_act⋅(snd ex); a ∈ act A⟧ ⟹ ∃exa∈executions A. filter_act⋅(snd ex) @@ [a!] = filter_act⋅(snd exa)›*) apply (pair ex) (*goal: ‹⋀ex. ⟦a ∈ inp A; input_enabled A; Finite sch; fst ex ∈ starts_of A ∧ is_exec_frag A ex; Filter (λx. x ∈ act A)⋅sch = filter_act⋅(snd ex); a ∈ act A⟧ ⟹ ∃exa. fst exa ∈ starts_of A ∧ is_exec_frag A exa ∧ filter_act⋅(snd ex) @@ [a!] = filter_act⋅(snd exa)›*) apply (rename_tac s ex) (*goal: ‹⋀x1 x2. ⟦a ∈ inp A; input_enabled A; Finite sch; x1 ∈ starts_of A ∧ is_exec_frag A (x1, x2); Filter (λx. x ∈ act A)⋅sch = filter_act⋅x2; a ∈ act A⟧ ⟹ ∃ex. fst ex ∈ starts_of A ∧ is_exec_frag A ex ∧ filter_act⋅x2 @@ [a!] = filter_act⋅(snd ex)›*) apply (subgoal_tac "Finite ex") (*goal: ‹⋀s ex. ⟦a ∈ inp A; input_enabled A; Finite sch; s ∈ starts_of A ∧ is_exec_frag A (s, ex); Filter (λx. x ∈ act A)⋅sch = filter_act⋅ex; a ∈ act A⟧ ⟹ ∃exa. fst exa ∈ starts_of A ∧ is_exec_frag A exa ∧ filter_act⋅ex @@ [a!] = filter_act⋅(snd exa)›*) prefer 2 (*top goal: ‹⋀s ex. ⟦a ∈ inp A; input_enabled A; Finite sch; s ∈ starts_of A ∧ is_exec_frag A (s, ex); Filter (λx. x ∈ act A)⋅sch = filter_act⋅ex; a ∈ act A⟧ ⟹ Finite ex› and 1 goal remains*) apply (simp add: filter_act_def (*‹filter_act = Map fst›*)) (*top goal: ‹⋀(s::'b::type) ex::('a::type × 'b::type) lift seq. ⟦(a::'a::type) ∈ inp (A::('a::type set × 'a::type set × 'a::type set) × 'b::type set × ('b::type × 'a::type × 'b::type) set × 'a::type set set × 'a::type set set); input_enabled A; Finite (sch::'a::type lift seq); s ∈ starts_of A ∧ is_exec_frag A (s, ex); Filter (λx::'a::type. x ∈ act A)⋅sch = filter_act⋅ex; a ∈ act A⟧ ⟹ Finite ex› and 1 goal remains*) defer 1 (*top goal: ‹⋀(s::'b) ex::('a × 'b) lift seq. ⟦(a::'a) ∈ inp (A::('a set × 'a set × 'a set) × 'b set × ('b × 'a × 'b) set × 'a set set × 'a set set); input_enabled A; Finite (sch::'a lift seq); s ∈ starts_of A ∧ is_exec_frag A (s, ex); Filter (λx::'a. x ∈ act A)⋅sch = filter_act⋅ex; a ∈ act A; Finite ex⟧ ⟹ ∃exa::'b × ('a × 'b) lift seq. fst exa ∈ starts_of A ∧ is_exec_frag A exa ∧ filter_act⋅ex @@ [a!] = filter_act⋅(snd exa)› and 1 goal remains*) apply (rule_tac [2] Map2Finite [THEN iffD1] (*‹Finite (Map ?f1⋅?s1) ⟹ Finite ?s1›*)) (*top goal: ‹⋀(s::'b) ex::('a × 'b) lift seq. ⟦(a::'a) ∈ inp (A::('a set × 'a set × 'a set) × 'b set × ('b × 'a × 'b) set × 'a set set × 'a set set); input_enabled A; Finite (sch::'a lift seq); s ∈ starts_of A ∧ is_exec_frag A (s, ex); Filter (λx::'a. x ∈ act A)⋅sch = filter_act⋅ex; a ∈ act A; Finite ex⟧ ⟹ ∃exa::'b × ('a × 'b) lift seq. fst exa ∈ starts_of A ∧ is_exec_frag A exa ∧ filter_act⋅ex @@ [a!] = filter_act⋅(snd exa)› and 1 goal remains*) apply (rule_tac [2] t = "Map fst ⋅ ex" in subst (*‹⟦(?s::?'a) = (?t::?'a); (?P::?'a ⇒ bool) ?s⟧ ⟹ ?P ?t›*)) (*top goal: ‹⋀s ex. ⟦a ∈ inp A; input_enabled A; Finite sch; s ∈ starts_of A ∧ is_exec_frag A (s, ex); Filter (λx. x ∈ act A)⋅sch = filter_act⋅ex; a ∈ act A; Finite ex⟧ ⟹ ∃exa. fst exa ∈ starts_of A ∧ is_exec_frag A exa ∧ filter_act⋅ex @@ [a!] = filter_act⋅(snd exa)› and 1 goal remains*) prefer 2 (*top goal: ‹⋀(s::'b) ex::('a × 'b) lift seq. ⟦(a::'a) ∈ inp (A::('a set × 'a set × 'a set) × 'b set × ('b × 'a × 'b) set × 'a set set × 'a set set); input_enabled A; Finite (sch::'a lift seq); s ∈ starts_of A ∧ is_exec_frag A (s, ex); Filter (λx::'a. x ∈ act A)⋅sch = Map fst⋅ex; a ∈ act A⟧ ⟹ (?s13::'b ⇒ ('a × 'b) lift seq ⇒ 'a lift seq) s ex = Map fst⋅ex› and 2 goals remain*) apply assumption (*top goal: ‹⋀s ex. ⟦a ∈ inp A; input_enabled A; Finite sch; s ∈ starts_of A ∧ is_exec_frag A (s, ex); Filter (λx. x ∈ act A)⋅sch = Map fst⋅ex; a ∈ act A⟧ ⟹ ?s13 s ex = Map fst⋅ex› and 2 goals remain*) apply (erule_tac [2] FiniteFilter (*‹Finite ?s ⟹ Finite (Filter ?P⋅?s)›*)) (*top goal: ‹⋀s ex. ⟦a ∈ inp A; input_enabled A; Finite sch; s ∈ starts_of A ∧ is_exec_frag A (s, ex); Filter (λx. x ∈ act A)⋅sch = filter_act⋅ex; a ∈ act A; Finite ex⟧ ⟹ ∃exa. fst exa ∈ starts_of A ∧ is_exec_frag A exa ∧ filter_act⋅ex @@ [a!] = filter_act⋅(snd exa)› and 1 goal remains*) text ‹subgoal 1› apply (frule exists_laststate (*‹Finite ?ex ⟹ ∀s. ∃u. laststate (s, ?ex) = u›*)) (*goal: ‹⋀(s::'b) ex::('a × 'b) lift seq. ⟦(a::'a) ∈ inp (A::('a set × 'a set × 'a set) × 'b set × ('b × 'a × 'b) set × 'a set set × 'a set set); input_enabled A; Finite (sch::'a lift seq); s ∈ starts_of A ∧ is_exec_frag A (s, ex); Filter (λx::'a. x ∈ act A)⋅sch = filter_act⋅ex; a ∈ act A; Finite ex⟧ ⟹ ∃exa::'b × ('a × 'b) lift seq. fst exa ∈ starts_of A ∧ is_exec_frag A exa ∧ filter_act⋅ex @@ [a!] = filter_act⋅(snd exa)›*) apply (erule allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*goal: ‹⋀s ex. ⟦a ∈ inp A; input_enabled A; Finite sch; s ∈ starts_of A ∧ is_exec_frag A (s, ex); Filter (λx. x ∈ act A)⋅sch = filter_act⋅ex; a ∈ act A; Finite ex; ∀s. ∃u. laststate (s, ex) = u⟧ ⟹ ∃exa. fst exa ∈ starts_of A ∧ is_exec_frag A exa ∧ filter_act⋅ex @@ [a!] = filter_act⋅(snd exa)›*) apply (erule exE (*‹⟦∃x. ?P x; ⋀x. ?P x ⟹ ?Q⟧ ⟹ ?Q›*)) (*goal: ‹⋀s ex. ⟦a ∈ inp A; input_enabled A; Finite sch; s ∈ starts_of A ∧ is_exec_frag A (s, ex); Filter (λx. x ∈ act A)⋅sch = filter_act⋅ex; a ∈ act A; Finite ex; ∃u. laststate (?s17 s ex, ex) = u⟧ ⟹ ∃exa. fst exa ∈ starts_of A ∧ is_exec_frag A exa ∧ filter_act⋅ex @@ [a!] = filter_act⋅(snd exa)›*) text ‹using input-enabledness› apply (simp add: input_enabled_def (*‹input_enabled ?A = (∀a. a ∈ inp ?A ⟶ (∀s1. ∃s2. s1 ─a─?A→ s2))›*)) (*goal: ‹⋀(s::'b::type) (ex::('a::type × 'b::type) lift seq) u::'b::type. ⟦(a::'a::type) ∈ inp (A::('a::type set × 'a::type set × 'a::type set) × 'b::type set × ('b::type × 'a::type × 'b::type) set × 'a::type set set × 'a::type set set); input_enabled A; Finite (sch::'a::type lift seq); s ∈ starts_of A ∧ is_exec_frag A (s, ex); Filter (λx::'a::type. x ∈ act A)⋅sch = filter_act⋅ex; a ∈ act A; Finite ex; laststate ((?s17::'b::type ⇒ ('a::type × 'b::type) lift seq ⇒ 'b::type) s ex, ex) = u⟧ ⟹ ∃exa::'b::type × ('a::type × 'b::type) lift seq. fst exa ∈ starts_of A ∧ is_exec_frag A exa ∧ filter_act⋅ex @@ [a!] = filter_act⋅(snd exa)›*) apply ((erule conjE (*‹⟦?P ∧ ?Q; ⟦?P; ?Q⟧ ⟹ ?R⟧ ⟹ ?R›*))+) (*goal: ‹⋀s ex u. ⟦a ∈ inp A; ∀a. a ∈ inp A ⟶ (∀s1. ∃s2. s1 ─a─A→ s2); Finite sch; s ∈ starts_of A ∧ is_exec_frag A (s, ex); Filter (λx. x ∈ act A)⋅sch = filter_act⋅ex; a ∈ act A; Finite ex; laststate (?s17 s ex, ex) = u⟧ ⟹ ∃exa. fst exa ∈ starts_of A ∧ is_exec_frag A exa ∧ filter_act⋅ex @@ [a!] = filter_act⋅(snd exa)›*) apply (erule_tac x = "a" in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*goal: ‹⋀(s::'b) (ex::('a × 'b) lift seq) u::'b. ⟦(a::'a) ∈ inp (A::('a set × 'a set × 'a set) × 'b set × ('b × 'a × 'b) set × 'a set set × 'a set set); ∀a::'a. a ∈ inp A ⟶ (∀s1::'b. ∃s2::'b. s1 ─a─A→ s2); Finite (sch::'a lift seq); Filter (λx::'a. x ∈ act A)⋅sch = filter_act⋅ex; a ∈ act A; Finite ex; laststate ((?s17::'b ⇒ ('a × 'b) lift seq ⇒ 'b) s ex, ex) = u; s ∈ starts_of A; is_exec_frag A (s, ex)⟧ ⟹ ∃exa::'b × ('a × 'b) lift seq. fst exa ∈ starts_of A ∧ is_exec_frag A exa ∧ filter_act⋅ex @@ [a!] = filter_act⋅(snd exa)›*) apply simp (*goal: ‹⋀s ex u. ⟦a ∈ inp A; Finite sch; Filter (λx. x ∈ act A)⋅sch = filter_act⋅ex; a ∈ act A; Finite ex; laststate (?s17 s ex, ex) = u; s ∈ starts_of A; is_exec_frag A (s, ex); a ∈ inp A ⟶ (∀s1. ∃s2. s1 ─a─A→ s2)⟧ ⟹ ∃exa. fst exa ∈ starts_of A ∧ is_exec_frag A exa ∧ filter_act⋅ex @@ [a!] = filter_act⋅(snd exa)›*) apply (erule_tac x = "u" in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*goal: ‹⋀(s::'b) (ex::('a × 'b) lift seq) u::'b. ⟦(a::'a) ∈ inp (A::('a set × 'a set × 'a set) × 'b set × ('b × 'a × 'b) set × 'a set set × 'a set set); Finite (sch::'a lift seq); Filter (λx::'a. x ∈ act A)⋅sch = filter_act⋅ex; a ∈ act A; Finite ex; laststate ((?s17::'b ⇒ ('a × 'b) lift seq ⇒ 'b) s ex, ex) = u; s ∈ starts_of A; is_exec_frag A (s, ex); ∀s1::'b. ∃s2::'b. s1 ─a─A→ s2⟧ ⟹ ∃exa::'b × ('a × 'b) lift seq. fst exa ∈ starts_of A ∧ is_exec_frag A exa ∧ filter_act⋅ex @@ [a!] = filter_act⋅(snd exa)›*) apply (erule exE (*‹⟦∃x. ?P x; ⋀x. ?P x ⟹ ?Q⟧ ⟹ ?Q›*)) (*goal: ‹⋀s ex u. ⟦a ∈ inp A; Finite sch; Filter (λx. x ∈ act A)⋅sch = filter_act⋅ex; a ∈ act A; Finite ex; laststate (?s17 s ex, ex) = u; s ∈ starts_of A; is_exec_frag A (s, ex); ∃s2. u ─a─A→ s2⟧ ⟹ ∃exa. fst exa ∈ starts_of A ∧ is_exec_frag A exa ∧ filter_act⋅ex @@ [a!] = filter_act⋅(snd exa)›*) text ‹instantiate execution› apply (rule_tac x = " (s, ex @@ (a, s2) ↝ nil) " in exI (*‹?P ?x ⟹ ∃x. ?P x›*)) (*goal: ‹⋀s ex u s2. ⟦a ∈ inp A; Finite sch; Filter (λx. x ∈ act A)⋅sch = filter_act⋅ex; a ∈ act A; Finite ex; laststate (?s17 s ex, ex) = u; s ∈ starts_of A; is_exec_frag A (s, ex); u ─a─A→ s2⟧ ⟹ ∃exa. fst exa ∈ starts_of A ∧ is_exec_frag A exa ∧ filter_act⋅ex @@ [a!] = filter_act⋅(snd exa)›*) apply (simp add: filter_act_def (*‹filter_act = Map fst›*) MapConc (*‹Map ?f⋅(?x @@ ?y) = Map ?f⋅?x @@ Map ?f⋅?y›*)) (*goal: ‹⋀s ex u s2. ⟦a ∈ inp A; Finite sch; Filter (λx. x ∈ act A)⋅sch = filter_act⋅ex; a ∈ act A; Finite ex; laststate (?s17 s ex, ex) = u; s ∈ starts_of A; is_exec_frag A (s, ex); u ─a─A→ s2⟧ ⟹ fst (s, ex @@ [(a, s2)!]) ∈ starts_of A ∧ is_exec_frag A (s, ex @@ [(a, s2)!]) ∧ filter_act⋅ex @@ [a!] = filter_act⋅(snd (s, ex @@ [(a, s2)!]))›*) apply (erule_tac t = "u" in lemma_2_1 (*‹⟦Finite ?xs; is_exec_frag ?A (?s, ?xs) ∧ is_exec_frag ?A (?t, ?ys) ∧ ?t = laststate (?s, ?xs)⟧ ⟹ is_exec_frag ?A (?s, ?xs @@ ?ys)›*)) (*goal: ‹⋀s ex u s2. ⟦a ∈ inp A; Finite sch; Filter (λx. x ∈ act A)⋅sch = Map fst⋅ex; a ∈ act A; Finite ex; laststate (?s17 s ex, ex) = u; s ∈ starts_of A; is_exec_frag A (s, ex); u ─a─A→ s2⟧ ⟹ is_exec_frag A (s, ex @@ [(a, s2)!])›*) apply simp (*goal: ‹⋀(s::'b) (ex::('a × 'b) lift seq) (u::'b) s2::'b. ⟦(a::'a) ∈ inp (A::('a set × 'a set × 'a set) × 'b set × ('b × 'a × 'b) set × 'a set set × 'a set set); Finite (sch::'a lift seq); Filter (λx::'a. x ∈ act A)⋅sch = Map fst⋅ex; a ∈ act A; laststate ((?s17::'b ⇒ ('a × 'b) lift seq ⇒ 'b) s ex, ex) = u; s ∈ starts_of A; is_exec_frag A (s, ex); u ─a─A→ s2⟧ ⟹ is_exec_frag A (s, ex) ∧ is_exec_frag A (u, [(a, s2)!]) ∧ u = laststate (s, ex)›*) apply (rule sym (*‹?s = ?t ⟹ ?t = ?s›*)) (*goal: ‹⋀s ex u s2. ⟦a ∈ inp A; Finite sch; Filter (λx. x ∈ act A)⋅sch = Map fst⋅ex; a ∈ act A; laststate (?s17 s ex, ex) = u; s ∈ starts_of A; is_exec_frag A (s, ex); u ─a─A→ s2⟧ ⟹ u = laststate (s, ex)›*) by assumption text ‹ Deadlock freedom: component B cannot block an out or int action of component A in every schedule. Needs compositionality on schedule level, input-enabledness, compatibility and distributivity of ‹is_exec_frag› over ‹@@›. › lemma IOA_deadlock_free: assumes "a ∈ local A" and "Finite sch" and "sch ∈ schedules (A ∥ B)" and "Filter (λx. x ∈ act A) ⋅ (sch @@ a ↝ nil) ∈ schedules A" and "compatible A B" and "input_enabled B" shows "(sch @@ a ↝ nil) ∈ schedules (A ∥ B)" supply if_split [split del] apply (insert assms) apply (simp add: compositionality_sch locals_def) apply (rule conjI) text ‹‹a ∈ act (A ∥ B)›› prefer 2 apply (simp add: actions_of_par) apply (blast dest: int_is_act out_is_act) text ‹‹Filter B (sch @@ [a]) ∈ schedules B›› apply (case_tac "a ∈ int A") apply (drule intA_is_not_actB) apply (assumption) (* ⟶ a ∉ act B *) apply simp text ‹case ‹a ∉ int A›, i.e. ‹a ∈ out A›› apply (case_tac "a ∉ act B") apply simp text ‹case ‹a ∈ act B›› apply simp apply (subgoal_tac "a ∈ out A") prefer 2 apply blast apply (drule outAactB_is_inpB) apply assumption apply assumption apply (rule scheds_input_enabled) apply simp apply assumption+ done end
{ "path": "Isabelle2024/src/HOL/HOLCF/IOA/Deadlock.thy", "repo": "Isabelle2024", "sha": "c71bd981102550e4b88f0b39380b6444365d7745f56a821ac4d014be9956f704" }
subsection‹‹Σ›-AND statements› theory Sigma_AND imports Sigma_Protocols Xor begin locale Σ_AND_base = Σ0: Σ_protocols_base init0 response0 check0 Rel0 S0_raw 𝒜ss0 "carrier L" valid_pub0 + Σ1: Σ_protocols_base init1 response1 check1 Rel1 S1_raw 𝒜ss1 "carrier L" valid_pub1 for init1 :: "'pub1 ⇒ 'witness1 ⇒ ('rand1 × 'msg1) spmf" and response1 :: "'rand1 ⇒ 'witness1 ⇒ 'bool ⇒ 'response1 spmf" and check1 :: "'pub1 ⇒ 'msg1 ⇒ 'bool ⇒ 'response1 ⇒ bool" and Rel1 :: "('pub1 × 'witness1) set" and S1_raw :: "'pub1 ⇒ 'bool ⇒ ('msg1 × 'response1) spmf" and 𝒜ss1 :: "'pub1 ⇒ 'msg1 × 'bool × 'response1 ⇒ 'msg1 × 'bool × 'response1 ⇒ 'witness1 spmf" and challenge_space1 :: "'bool set" and valid_pub1 :: "'pub1 set" and init0 :: "'pub0 ⇒ 'witness0 ⇒ ('rand0 × 'msg0) spmf" and response0 :: "'rand0 ⇒ 'witness0 ⇒ 'bool ⇒ 'response0 spmf" and check0 :: "'pub0 ⇒ 'msg0 ⇒ 'bool ⇒ 'response0 ⇒ bool" and Rel0 :: "('pub0 × 'witness0) set" and S0_raw :: "'pub0 ⇒ 'bool ⇒ ('msg0 × 'response0) spmf" and 𝒜ss0 :: "'pub0 ⇒ 'msg0 × 'bool × 'response0 ⇒ 'msg0 × 'bool × 'response0 ⇒ 'witness0 spmf" and challenge_space0 :: "'bool set" and valid_pub0 :: "'pub0 set" and G :: "(('pub0 × 'pub1) × ('witness0 × 'witness1)) spmf" and L :: "'bool boolean_algebra" (structure) + assumes Σ_prot1: "Σ1.Σ_protocol" and Σ_prot0: "Σ0.Σ_protocol" and lossless_init: "lossless_spmf (init0 h0 w0)" "lossless_spmf (init1 h1 w1)" and lossless_response: "lossless_spmf (response0 r0 w0 e0)" "lossless_spmf (response1 r1 w1 e1)" and lossless_S: "lossless_spmf (S0 h0 e0)" "lossless_spmf (S1 h1 e1)" and lossless_𝒜ss: "lossless_spmf (𝒜ss0 x0 (a0,e,z0) (a0,e',z0'))" "lossless_spmf (𝒜ss1 x1 (a1,e,z1) (a1,e',z1'))" and lossless_G: "lossless_spmf G" and set_spmf_G [simp]: "(h,w) ∈ set_spmf G ⟹ Rel h w" begin definition "challenge_space = carrier L" definition Rel_AND :: "(('pub0 × 'pub1) × 'witness0 × 'witness1) set" where "Rel_AND = {((x0,x1), (w0,w1)). ((x0,w0) ∈ Rel0 ∧ (x1,w1) ∈ Rel1)}" definition init_AND :: "('pub0 × 'pub1) ⇒ ('witness0 × 'witness1) ⇒ (('rand0 × 'rand1) × 'msg0 × 'msg1) spmf" where "init_AND X W = do { let (x0, x1) = X; let (w0,w1) = W; (r0, a0) ← init0 x0 w0; (r1, a1) ← init1 x1 w1; return_spmf ((r0,r1), (a0,a1))}" lemma lossless_init_AND: "lossless_spmf (init_AND X W)" by (simp add: lossless_init (*‹lossless_spmf (init0 ?h0.0 ?w0.0)› ‹lossless_spmf (init1 ?h1.0 ?w1.0)›*) init_AND_def (*‹init_AND ?X ?W = (let (x0, x1) = ?X; (w0, w1) = ?W in init0 x0 w0 ⤜ (λ(r0, a0). init1 x1 w1 ⤜ (λ(r1, a1). return_spmf ((r0, r1), a0, a1))))›*) split_def (*‹case_prod = (λc p. c (fst p) (snd p))›*)) definition response_AND :: "('rand0 × 'rand1) ⇒ ('witness0 × 'witness1) ⇒ 'bool ⇒ ('response0 × 'response1) spmf" where "response_AND R W s = do { let (r0,r1) = R; let (w0,w1) = W; z0 ← response0 r0 w0 s; z1 :: 'response1 ← response1 r1 w1 s; return_spmf (z0,z1)}" lemma lossless_response_AND: "lossless_spmf (response_AND R W s)" by (simp add: response_AND_def (*‹response_AND ?R ?W ?s = (let (r0, r1) = ?R; (w0, w1) = ?W in response0 r0 w0 ?s ⤜ (λz0. response1 r1 w1 ?s ⤜ (λz1. return_spmf (z0, z1))))›*) lossless_response (*‹lossless_spmf (response0 ?r0.0 ?w0.0 ?e0.0)› ‹lossless_spmf (response1 ?r1.0 ?w1.0 ?e1.0)›*) split_def (*‹case_prod = (λc p. c (fst p) (snd p))›*)) fun check_AND :: "('pub0 × 'pub1) ⇒ ('msg0 × 'msg1) ⇒ 'bool ⇒ ('response0 × 'response1) ⇒ bool" where "check_AND (x0,x1) (a0,a1) s (z0,z1) = (check0 x0 a0 s z0 ∧ check1 x1 a1 s z1)" definition S_AND :: "'pub0 × 'pub1 ⇒ 'bool ⇒ (('msg0 × 'msg1) × 'response0 × 'response1) spmf" where "S_AND X e = do { let (x0,x1) = X; (a0, z0) ← S0_raw x0 e; (a1, z1) ← S1_raw x1 e; return_spmf ((a0,a1),(z0,z1))}" fun 𝒜ss_AND :: "'pub0 × 'pub1 ⇒ ('msg0 × 'msg1) × 'bool × 'response0 × 'response1 ⇒ ('msg0 × 'msg1) × 'bool × 'response0 × 'response1 ⇒ ('witness0 × 'witness1) spmf" where "𝒜ss_AND (x0,x1) ((a0,a1), e, (z0,z1)) ((a0',a1'), e', (z0',z1')) = do { w0 :: 'witness0 ← 𝒜ss0 x0 (a0,e,z0) (a0',e',z0'); w1 ← 𝒜ss1 x1 (a1,e,z1) (a1',e',z1'); return_spmf (w0,w1)}" definition "valid_pub_AND = {(x0,x1). x0 ∈ valid_pub0 ∧ x1 ∈ valid_pub1}" sublocale Σ_AND: Σ_protocols_base init_AND response_AND check_AND Rel_AND S_AND 𝒜ss_AND challenge_space valid_pub_AND apply unfold_locales (*goal: ‹Σ_protocols_base Rel_AND valid_pub_AND›*) apply (simp add: Rel_AND_def (*‹Rel_AND = {((x0, x1), w0, w1). (x0, w0) ∈ Rel0 ∧ (x1, w1) ∈ Rel1}›*) valid_pub_AND_def (*‹valid_pub_AND = {(x0, x1). x0 ∈ valid_pub0 ∧ x1 ∈ valid_pub1}›*)) (*goal: ‹Domain Rel_AND ⊆ valid_pub_AND›*) using "Σ1.domain_subset_valid_pub" (*‹Domain Rel1 ⊆ valid_pub1›*) "Σ0.domain_subset_valid_pub" (*‹Domain Rel0 ⊆ valid_pub0›*) by blast end locale Σ_AND = Σ_AND_base + assumes set_spmf_G_L: "((x0, x1), w0, w1) ∈ set_spmf G ⟹ ((x0, x1), (w0,w1)) ∈ Rel_AND" begin lemma hvzk: assumes Rel_AND: "((x0,x1), (w0,w1)) ∈ Rel_AND" and "e ∈ challenge_space" shows "Σ_AND.R (x0,x1) (w0,w1) e = Σ_AND.S (x0,x1) e" including monad_normalisation proof (-) (*goal: ‹Σ_AND.R (x0, x1) (w0, w1) e = Σ_AND.S (x0, x1) e›*) have x_in_dom: "x0 ∈ Domain Rel0" and "x1 ∈ Domain Rel1" using Rel_AND (*‹((x0, x1), w0, w1) ∈ Rel_AND›*) Rel_AND_def (*‹Rel_AND = {((x0, x1), w0, w1). (x0, w0) ∈ Rel0 ∧ (x1, w1) ∈ Rel1}›*) apply - (*goals: 1. ‹⟦((x0, x1), w0, w1) ∈ Rel_AND; Rel_AND = {((x0, x1), w0, w1). (x0, w0) ∈ Rel0 ∧ (x1, w1) ∈ Rel1}⟧ ⟹ x0 ∈ Domain Rel0› 2. ‹⟦((x0, x1), w0, w1) ∈ Rel_AND; Rel_AND = {((x0, x1), w0, w1). (x0, w0) ∈ Rel0 ∧ (x1, w1) ∈ Rel1}⟧ ⟹ x1 ∈ Domain Rel1› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have "Σ_AND.R (x0,x1) (w0,w1) e = do { ((r0,r1),(a0,a1)) ← init_AND (x0,x1) (w0,w1); (z0,z1) ← response_AND (r0,r1) (w0,w1) e; return_spmf ((a0,a1),e,(z0,z1))}" by (simp add: Σ_AND.R_def (*‹Σ_AND.R (?h::'g × 'a) (?w::'h × 'b) (?e::'e) = init_AND ?h ?w ⤜ (λ(r::'i × 'c, a::'j × 'd). response_AND r ?w ?e ⤜ (λz::'k × 'f. return_spmf (a, ?e, z)))›*) split_def (*‹case_prod = (λ(c::?'a ⇒ ?'b ⇒ ?'c) p::?'a × ?'b. c (fst p) (snd p))›*)) also (*calculation: ‹Σ_AND.R (x0, x1) (w0, w1) e = init_AND (x0, x1) (w0, w1) ⤜ (λ((r0, r1), a0, a1). response_AND (r0, r1) (w0, w1) e ⤜ (λ(z0, z1). return_spmf ((a0, a1), e, z0, z1)))›*) have "... = do { (r0, a0) ← init0 x0 w0; z0 ← response0 r0 w0 e; (r1, a1) ← init1 x1 w1; z1 :: 'f ← response1 r1 w1 e; return_spmf ((a0,a1),e,(z0,z1))}" apply (simp add: init_AND_def (*‹init_AND ?X ?W = (let (x0, x1) = ?X; (w0, w1) = ?W in init0 x0 w0 ⤜ (λ(r0, a0). init1 x1 w1 ⤜ (λ(r1, a1). return_spmf ((r0, r1), a0, a1))))›*) response_AND_def (*‹response_AND ?R ?W ?s = (let (r0, r1) = ?R; (w0, w1) = ?W in response0 r0 w0 ?s ⤜ (λz0. response1 r1 w1 ?s ⤜ (λz1. return_spmf (z0, z1))))›*) split_def (*‹case_prod = (λc p. c (fst p) (snd p))›*)) (*goal: ‹init_AND (x0, x1) (w0, w1) ⤜ (λ((r0, r1), a0, a1). response_AND (r0, r1) (w0, w1) e ⤜ (λ(z0, z1). return_spmf ((a0, a1), e, z0, z1))) = init0 x0 w0 ⤜ (λ(r0, a0). response0 r0 w0 e ⤜ (λz0. init1 x1 w1 ⤜ (λ(r1, a1). response1 r1 w1 e ⤜ (λz1. return_spmf ((a0, a1), e, z0, z1)))))›*) apply (rewrite bind_commute_spmf[of "response0 _ w0 e"]) (*goal: ‹init1 x1 w1 ⤜ (λy. response1 (fst y) w1 e ⤜ (λya. init0 x0 w0 ⤜ (λyb. response0 (fst yb) w0 e ⤜ (λyc. return_spmf ((snd yb, snd y), e, yc, ya))))) = init0 x0 w0 ⤜ (λp. response0 (fst p) w0 e ⤜ (λz0. init1 x1 w1 ⤜ (λpa. response1 (fst pa) w1 e ⤜ (λz1. return_spmf ((snd p, snd pa), e, z0, z1)))))›*) by simp also (*calculation: ‹Σ_AND.R (x0, x1) (w0, w1) e = init0 x0 w0 ⤜ (λ(r0, a0). response0 r0 w0 e ⤜ (λz0. init1 x1 w1 ⤜ (λ(r1, a1). response1 r1 w1 e ⤜ (λz1. return_spmf ((a0, a1), e, z0, z1)))))›*) have "... = do { (a0, c0, z0) ← Σ0.R x0 w0 e; (a1, c1, z1) ← Σ1.R x1 w1 e; return_spmf ((a0,a1),e,(z0,z1))}" by (simp add: Σ0.R_def (*‹Σ0.R ?h ?w ?e = init0 ?h ?w ⤜ (λ(r, a). response0 r ?w ?e ⤜ (λz. return_spmf (a, ?e, z)))›*) Σ1.R_def (*‹Σ1.R ?h ?w ?e = init1 ?h ?w ⤜ (λ(r, a). response1 r ?w ?e ⤜ (λz. return_spmf (a, ?e, z)))›*) split_def (*‹case_prod = (λc p. c (fst p) (snd p))›*)) also (*calculation: ‹Σ_AND.R (x0, x1) (w0, w1) e = Σ0.R x0 w0 e ⤜ (λ(a0, c0, z0). Σ1.R x1 w1 e ⤜ (λ(a1, c1, z1). return_spmf ((a0, a1), e, z0, z1)))›*) have "... = do { (a0, c0, z0) ← Σ0.S x0 e; (a1, c1, z1) ← Σ1.S x1 e; return_spmf ((a0,a1),e,(z0,z1))}" using Rel_AND_def (*‹Rel_AND = {((x0, x1), w0, w1). (x0, w0) ∈ Rel0 ∧ (x1, w1) ∈ Rel1}›*) S_AND_def (*‹S_AND ?X ?e = (let (x0, x1) = ?X in S0_raw x0 ?e ⤜ (λ(a0, z0). S1_raw x1 ?e ⤜ (λ(a1, z1). return_spmf ((a0, a1), z0, z1))))›*) "Σ_prot1" (*‹Σ1.Σ_protocol›*) "Σ_prot0" (*‹Σ0.Σ_protocol›*) assms (*‹((x0::'g, x1::'a), w0::'h, w1::'b) ∈ Rel_AND› ‹(e::'e::type) ∈ challenge_space›*) "Σ0.HVZK_unfold1" (*‹Σ0.Σ_protocol ⟹ ∀h w e. (h, w) ∈ Rel0 ⟶ e ∈ carrier L ⟶ Σ0.R h w e = Σ0.S h e›*) "Σ1.HVZK_unfold1" (*‹Σ1.Σ_protocol ⟹ ∀h w e. (h, w) ∈ Rel1 ⟶ e ∈ carrier L ⟶ Σ1.R h w e = Σ1.S h e›*) valid_pub_AND_def (*‹valid_pub_AND = {(x0, x1). x0 ∈ valid_pub0 ∧ x1 ∈ valid_pub1}›*) split_def (*‹case_prod = (λc p. c (fst p) (snd p))›*) challenge_space_def (*‹challenge_space = carrier L›*) x_in_dom (*‹x0 ∈ Domain Rel0›*) by auto ultimately show "?thesis" (*goal: ‹Σ_AND.R (x0::'g, x1::'a) (w0::'h, w1::'b) (e::'e) = Σ_AND.S (x0, x1) e›*) by (simp add: Σ0.S_def (*‹Σ0.S ?h ?e = map_spmf (λ(a, z). (a, ?e, z)) (S0_raw ?h ?e)›*) Σ1.S_def (*‹Σ1.S ?h ?e = map_spmf (λ(a, z). (a, ?e, z)) (S1_raw ?h ?e)›*) bind_map_spmf (*‹map_spmf ?f ?p ⤜ ?g = ?p ⤜ ?g ∘ ?f›*) o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*) split_def (*‹case_prod = (λc p. c (fst p) (snd p))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) Σ_AND.S_def (*‹Σ_AND.S ?h ?e = map_spmf (λ(a, z). (a, ?e, z)) (S_AND ?h ?e)›*) map_spmf_conv_bind_spmf (*‹map_spmf ?f ?p = ?p ⤜ (λx. return_spmf (?f x))›*) S_AND_def (*‹S_AND ?X ?e = (let (x0, x1) = ?X in S0_raw x0 ?e ⤜ (λ(a0, z0). S1_raw x1 ?e ⤜ (λ(a1, z1). return_spmf ((a0, a1), z0, z1))))›*)) qed lemma HVZK: "Σ_AND.HVZK" using "Σ_AND.HVZK_def" (*‹Σ_AND.HVZK ≡ ∀e∈challenge_space. (∀(h, w)∈Rel_AND. Σ_AND.R h w e = Σ_AND.S h e) ∧ (∀h∈valid_pub_AND. ∀(a, z)∈set_spmf (S_AND h e). check_AND h a e z)›*) hvzk (*‹⟦((?x0.0, ?x1.0), ?w0.0, ?w1.0) ∈ Rel_AND; ?e ∈ challenge_space⟧ ⟹ Σ_AND.R (?x0.0, ?x1.0) (?w0.0, ?w1.0) ?e = Σ_AND.S (?x0.0, ?x1.0) ?e›*) challenge_space_def (*‹challenge_space = carrier L›*) apply (simp add: S_AND_def (*‹S_AND (?X::'g × 'a) (?e::'e) = (let (x0::'g, x1::'a) = ?X in (S0_raw::'g ⇒ 'e ⇒ ('j × 'k) spmf) x0 ?e ⤜ (λ(a0::'j, z0::'k). (S1_raw::'a ⇒ 'e ⇒ ('d × 'f) spmf) x1 ?e ⤜ (λ(a1::'d, z1::'f). return_spmf ((a0, a1), z0, z1))))›*) split_def (*‹case_prod = (λ(c::?'a ⇒ ?'b ⇒ ?'c) p::?'a × ?'b. c (fst p) (snd p))›*)) (*goal: ‹Σ_AND.HVZK›*) using "Σ_prot1" (*‹Σ1.Σ_protocol›*) "Σ_prot0" (*‹Σ0.Σ_protocol›*) "Σ0.HVZK_unfold2" (*‹Σ0.Σ_protocol ⟹ ∀h e out. e ∈ carrier L ⟶ h ∈ valid_pub0 ⟶ out ∈ set_spmf (S0_raw h e) ⟶ check0 h (fst out) e (snd out)›*) "Σ1.HVZK_unfold2" (*‹Σ1.Σ_protocol ⟹ ∀h e out. e ∈ carrier L ⟶ h ∈ valid_pub1 ⟶ out ∈ set_spmf (S1_raw h e) ⟶ check1 h (fst out) e (snd out)›*) valid_pub_AND_def (*‹valid_pub_AND = {(x0::'g, x1::'a). x0 ∈ (valid_pub0::'g set) ∧ x1 ∈ (valid_pub1::'a set)}›*) by auto lemma correct: assumes Rel_AND: "((x0,x1), (w0,w1)) ∈ Rel_AND" and "e ∈ challenge_space" shows "Σ_AND.completeness_game (x0,x1) (w0,w1) e = return_spmf True" including monad_normalisation proof (-) (*goal: ‹Σ_AND.completeness_game (x0::'g, x1::'a) (w0::'h, w1::'b) (e::'e) = return_spmf True›*) have "Σ_AND.completeness_game (x0,x1) (w0,w1) e = do { ((r0,r1),(a0,a1)) ← init_AND (x0,x1) (w0,w1); (z0,z1) ← response_AND (r0,r1) (w0,w1) e; return_spmf (check_AND (x0,x1) (a0,a1) e (z0,z1))}" by (simp add: Σ_AND.completeness_game_def (*‹Σ_AND.completeness_game ?h ?w ?e = init_AND ?h ?w ⤜ (λ(r, a). response_AND r ?w ?e ⤜ (λz. return_spmf (check_AND ?h a ?e z)))›*) split_def (*‹case_prod = (λc p. c (fst p) (snd p))›*) del: check_AND.simps (*‹check_AND (?x0.0, ?x1.0) (?a0.0, ?a1.0) ?s (?z0.0, ?z1.0) = (check0 ?x0.0 ?a0.0 ?s ?z0.0 ∧ check1 ?x1.0 ?a1.0 ?s ?z1.0)›*)) also (*calculation: ‹Σ_AND.completeness_game (x0, x1) (w0, w1) e = init_AND (x0, x1) (w0, w1) ⤜ (λ((r0, r1), a0, a1). response_AND (r0, r1) (w0, w1) e ⤜ (λ(z0, z1). return_spmf (check_AND (x0, x1) (a0, a1) e (z0, z1))))›*) have "... = do { (r0, a0) ← init0 x0 w0; z0 ← response0 r0 w0 e; (r1, a1) ← init1 x1 w1; z1 ← response1 r1 w1 e; return_spmf ((check0 x0 a0 e z0 ∧ check1 x1 a1 e z1))}" apply (simp add: init_AND_def (*‹init_AND ?X ?W = (let (x0, x1) = ?X; (w0, w1) = ?W in init0 x0 w0 ⤜ (λ(r0, a0). init1 x1 w1 ⤜ (λ(r1, a1). return_spmf ((r0, r1), a0, a1))))›*) response_AND_def (*‹response_AND ?R ?W ?s = (let (r0, r1) = ?R; (w0, w1) = ?W in response0 r0 w0 ?s ⤜ (λz0. response1 r1 w1 ?s ⤜ (λz1. return_spmf (z0, z1))))›*) split_def (*‹case_prod = (λc p. c (fst p) (snd p))›*)) (*goal: ‹init_AND (x0, x1) (w0, w1) ⤜ (λ((r0, r1), a0, a1). response_AND (r0, r1) (w0, w1) e ⤜ (λ(z0, z1). return_spmf (check_AND (x0, x1) (a0, a1) e (z0, z1)))) = init0 x0 w0 ⤜ (λ(r0, a0). response0 r0 w0 e ⤜ (λz0. init1 x1 w1 ⤜ (λ(r1, a1). response1 r1 w1 e ⤜ (λz1. return_spmf (check0 x0 a0 e z0 ∧ check1 x1 a1 e z1)))))›*) apply (rewrite bind_commute_spmf[of "response0 _ w0 e"]) (*goal: ‹(init1::'a ⇒ 'b ⇒ ('c × 'd) spmf) (x1::'a) (w1::'b) ⤜ (λy::'c × 'd. (response1::'c ⇒ 'b ⇒ 'e ⇒ 'f spmf) (fst y) w1 (e::'e) ⤜ (λya::'f. (init0::'g ⇒ 'h ⇒ ('i × 'j) spmf) (x0::'g) (w0::'h) ⤜ (λyb::'i × 'j. (response0::'i ⇒ 'h ⇒ 'e ⇒ 'k spmf) (fst yb) w0 e ⤜ (λyc::'k. return_spmf ((check0::'g ⇒ 'j ⇒ 'e ⇒ 'k ⇒ bool) x0 (snd yb) e yc ∧ (check1::'a ⇒ 'd ⇒ 'e ⇒ 'f ⇒ bool) x1 (snd y) e ya))))) = init0 x0 w0 ⤜ (λp::'i × 'j. response0 (fst p) w0 e ⤜ (λz0::'k. init1 x1 w1 ⤜ (λpa::'c × 'd. response1 (fst pa) w1 e ⤜ (λz1::'f. return_spmf (check0 x0 (snd p) e z0 ∧ check1 x1 (snd pa) e z1)))))›*) by simp ultimately show "?thesis" (*goal: ‹Σ_AND.completeness_game (x0, x1) (w0, w1) e = return_spmf True›*) using "Σ1.complete_game_return_true" (*‹⟦(?h, ?w) ∈ Rel1; Σ1.completeness; ∀h w. lossless_spmf (init1 h w); ∀r w e. lossless_spmf (response1 r w e); ?e ∈ carrier L⟧ ⟹ Σ1.completeness_game ?h ?w ?e = return_spmf True›*) "Σ_prot1" (*‹Σ1.Σ_protocol›*) "Σ1.Σ_protocol_def" (*‹Σ1.Σ_protocol ≡ Σ1.completeness ∧ Σ1.special_soundness ∧ Σ1.HVZK›*) "Σ1.completeness_game_def" (*‹Σ1.completeness_game ?h ?w ?e = init1 ?h ?w ⤜ (λ(r, a). response1 r ?w ?e ⤜ (λz. return_spmf (check1 ?h a ?e z)))›*) assms (*‹((x0, x1), w0, w1) ∈ Rel_AND› ‹e ∈ challenge_space›*) "Σ0.complete_game_return_true" (*‹⟦(?h, ?w) ∈ Rel0; Σ0.completeness; ∀h w. lossless_spmf (init0 h w); ∀r w e. lossless_spmf (response0 r w e); ?e ∈ carrier L⟧ ⟹ Σ0.completeness_game ?h ?w ?e = return_spmf True›*) "Σ_prot0" (*‹Σ0.Σ_protocol›*) "Σ0.Σ_protocol_def" (*‹Σ0.Σ_protocol ≡ Σ0.completeness ∧ Σ0.special_soundness ∧ Σ0.HVZK›*) "Σ0.completeness_game_def" (*‹Σ0.completeness_game (?h::'g) (?w::'h) (?e::'e) = (init0::'g ⇒ 'h ⇒ ('i × 'j) spmf) ?h ?w ⤜ (λ(r::'i, a::'j). (response0::'i ⇒ 'h ⇒ 'e ⇒ 'k spmf) r ?w ?e ⤜ (λz::'k. return_spmf ((check0::'g ⇒ 'j ⇒ 'e ⇒ 'k ⇒ bool) ?h a ?e z)))›*) challenge_space_def (*‹challenge_space = carrier L›*) apply (auto simp add: Let_def (*‹Let ?s ?f ≡ ?f ?s›*) split_def (*‹case_prod = (λc p. c (fst p) (snd p))›*) bind_eq_return_spmf (*‹(?p ⤜ ?f = return_spmf ?x) = ((∀y∈set_spmf ?p. ?f y = return_spmf ?x) ∧ lossless_spmf ?p)›*) lossless_init (*‹lossless_spmf (init0 ?h0.0 ?w0.0)› ‹lossless_spmf (init1 ?h1.0 ?w1.0)›*) lossless_response (*‹lossless_spmf (response0 ?r0.0 ?w0.0 ?e0.0)› ‹lossless_spmf (response1 ?r1.0 ?w1.0 ?e1.0)›*) Rel_AND_def (*‹Rel_AND = {((x0, x1), w0, w1). (x0, w0) ∈ Rel0 ∧ (x1, w1) ∈ Rel1}›*)) (*goals: 1. ‹⋀a b y aa ba ya. ⟦Σ_AND.completeness_game (x0, x1) (w0, w1) e = init0 x0 w0 ⤜ (λp. response0 (fst p) w0 e ⤜ (λz0. init1 x1 w1 ⤜ (λpa. response1 (fst pa) w1 e ⤜ (λz1. return_spmf (check0 x0 (snd p) e z0 ∧ check1 x1 (snd pa) e z1))))); init_AND (x0, x1) (w0, w1) ⤜ (λp. response_AND (fst p) (w0, w1) e ⤜ (λpa. return_spmf (check0 x0 (fst (snd p)) e (fst pa) ∧ check1 x1 (snd (snd p)) e (snd pa)))) = init0 x0 w0 ⤜ (λp. response0 (fst p) w0 e ⤜ (λz0. init1 x1 w1 ⤜ (λpa. response1 (fst pa) w1 e ⤜ (λz1. return_spmf (check0 x0 (snd p) e z0 ∧ check1 x1 (snd pa) e z1))))); ⋀h w e. ⟦(h, w) ∈ Rel1; e ∈ carrier L⟧ ⟹ ∀y∈set_spmf (init1 h w). ∀x∈set_spmf (response1 (fst y) w e). check1 h (snd y) e x; Σ1.Σ_protocol ≡ True; ⋀h w e. Σ1.completeness_game h w e = init1 h w ⤜ (λp. response1 (fst p) w e ⤜ (λz. return_spmf (check1 h (snd p) e z))); e ∈ carrier L; ⋀h w e. ⟦(h, w) ∈ Rel0; e ∈ carrier L⟧ ⟹ ∀y∈set_spmf (init0 h w). ∀x∈set_spmf (response0 (fst y) w e). check0 h (snd y) e x; Σ0.Σ_protocol ≡ True; ⋀h w e. Σ0.completeness_game h w e = init0 h w ⤜ (λp. response0 (fst p) w e ⤜ (λz. return_spmf (check0 h (snd p) e z))); challenge_space = carrier L; (a, b) ∈ set_spmf (init0 x0 w0); y ∈ set_spmf (response0 a w0 e); (aa, ba) ∈ set_spmf (init1 x1 w1); ya ∈ set_spmf (response1 aa w1 e); Σ1.completeness; (x0, w0) ∈ Rel0; (x1, w1) ∈ Rel1; Σ0.completeness; Σ1.special_soundness; Σ1.HVZK; Σ0.special_soundness; Σ0.HVZK⟧ ⟹ check0 x0 b e y› 2. ‹⋀a b y aa ba ya. ⟦Σ_AND.completeness_game (x0, x1) (w0, w1) e = init0 x0 w0 ⤜ (λp. response0 (fst p) w0 e ⤜ (λz0. init1 x1 w1 ⤜ (λpa. response1 (fst pa) w1 e ⤜ (λz1. return_spmf (check0 x0 (snd p) e z0 ∧ check1 x1 (snd pa) e z1))))); init_AND (x0, x1) (w0, w1) ⤜ (λp. response_AND (fst p) (w0, w1) e ⤜ (λpa. return_spmf (check0 x0 (fst (snd p)) e (fst pa) ∧ check1 x1 (snd (snd p)) e (snd pa)))) = init0 x0 w0 ⤜ (λp. response0 (fst p) w0 e ⤜ (λz0. init1 x1 w1 ⤜ (λpa. response1 (fst pa) w1 e ⤜ (λz1. return_spmf (check0 x0 (snd p) e z0 ∧ check1 x1 (snd pa) e z1))))); ⋀h w e. ⟦(h, w) ∈ Rel1; e ∈ carrier L⟧ ⟹ ∀y∈set_spmf (init1 h w). ∀x∈set_spmf (response1 (fst y) w e). check1 h (snd y) e x; Σ1.Σ_protocol ≡ True; ⋀h w e. Σ1.completeness_game h w e = init1 h w ⤜ (λp. response1 (fst p) w e ⤜ (λz. return_spmf (check1 h (snd p) e z))); e ∈ carrier L; ⋀h w e. ⟦(h, w) ∈ Rel0; e ∈ carrier L⟧ ⟹ ∀y∈set_spmf (init0 h w). ∀x∈set_spmf (response0 (fst y) w e). check0 h (snd y) e x; Σ0.Σ_protocol ≡ True; ⋀h w e. Σ0.completeness_game h w e = init0 h w ⤜ (λp. response0 (fst p) w e ⤜ (λz. return_spmf (check0 h (snd p) e z))); challenge_space = carrier L; (a, b) ∈ set_spmf (init0 x0 w0); y ∈ set_spmf (response0 a w0 e); (aa, ba) ∈ set_spmf (init1 x1 w1); ya ∈ set_spmf (response1 aa w1 e); Σ1.completeness; (x0, w0) ∈ Rel0; (x1, w1) ∈ Rel1; Σ0.completeness; Σ1.special_soundness; Σ1.HVZK; Σ0.special_soundness; Σ0.HVZK⟧ ⟹ check1 x1 ba e ya› discuss goal 1*) apply (metis (mono_tags, lifting) assms( (*‹e ∈ challenge_space›*) 2) fst_conv (*‹fst (?x1.0, ?x2.0) = ?x1.0›*) snd_conv (*‹snd (?x1.0, ?x2.0) = ?x2.0›*)) (*discuss goal 2*) apply (metis (mono_tags, lifting) assms( (*‹e ∈ challenge_space›*) 2) fst_conv (*‹fst (?x1.0, ?x2.0) = ?x1.0›*) snd_conv (*‹snd (?x1.0, ?x2.0) = ?x2.0›*)) (*proven 2 subgoals*) . qed lemma completeness: "Σ_AND.completeness" using "Σ_AND.completeness_def" (*‹Σ_AND.completeness ≡ ∀h w e. (h, w) ∈ Rel_AND ⟶ e ∈ challenge_space ⟶ spmf (Σ_AND.completeness_game h w e) True = 1›*) correct (*‹⟦((?x0.0, ?x1.0), ?w0.0, ?w1.0) ∈ Rel_AND; ?e ∈ challenge_space⟧ ⟹ Σ_AND.completeness_game (?x0.0, ?x1.0) (?w0.0, ?w1.0) ?e = return_spmf True›*) challenge_space_def (*‹challenge_space = carrier L›*) by force lemma ss: assumes e_neq_e': "s ≠ s'" and valid_pub: "(x0,x1) ∈ valid_pub_AND" and challenge_space: "s ∈ challenge_space" "s' ∈ challenge_space" and "check_AND (x0,x1) (a0,a1) s (z0,z1)" and "check_AND (x0,x1) (a0,a1) s' (z0',z1')" shows "lossless_spmf (𝒜ss_AND (x0,x1) ((a0,a1), s, (z0,z1)) ((a0,a1), s', (z0',z1'))) ∧ (∀w'∈set_spmf (𝒜ss_AND (x0,x1) ((a0,a1), s, (z0,z1)) ((a0,a1), s', (z0',z1'))). ((x0,x1), w') ∈ Rel_AND)" proof (-) (*goal: ‹lossless_spmf (𝒜ss_AND (x0, x1) ((a0, a1), s, z0, z1) ((a0, a1), s', z0', z1')) ∧ (∀w'∈set_spmf (𝒜ss_AND (x0, x1) ((a0, a1), s, z0, z1) ((a0, a1), s', z0', z1')). ((x0, x1), w') ∈ Rel_AND)›*) have x0_in_dom: "x0 ∈ valid_pub0" and x1_in_dom: "x1 ∈ valid_pub1" using valid_pub (*‹(x0::'g, x1::'a) ∈ valid_pub_AND›*) valid_pub_AND_def (*‹valid_pub_AND = {(x0::'g, x1::'a). x0 ∈ (valid_pub0::'g set) ∧ x1 ∈ (valid_pub1::'a set)}›*) apply - (*goals: 1. ‹⟦(x0, x1) ∈ valid_pub_AND; valid_pub_AND = {(x0, x1). x0 ∈ valid_pub0 ∧ x1 ∈ valid_pub1}⟧ ⟹ x0 ∈ valid_pub0› 2. ‹⟦(x0, x1) ∈ valid_pub_AND; valid_pub_AND = {(x0, x1). x0 ∈ valid_pub0 ∧ x1 ∈ valid_pub1}⟧ ⟹ x1 ∈ valid_pub1› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . moreover have 3: "check0 x0 a0 s z0" using assms (*‹s ≠ s'› ‹(x0, x1) ∈ valid_pub_AND› ‹(s::'e::type) ∈ challenge_space› ‹s' ∈ challenge_space› ‹check_AND (x0, x1) (a0, a1) s (z0, z1)› ‹check_AND (x0, x1) (a0, a1) s' (z0', z1')›*) by simp moreover have 4: "check1 x1 a1 s' z1'" using assms (*‹s ≠ s'› ‹(x0, x1) ∈ valid_pub_AND› ‹s ∈ challenge_space› ‹s' ∈ challenge_space› ‹check_AND (x0::'g, x1::'a) (a0::'j, a1::'d) (s::'e) (z0::'k, z1::'f)› ‹check_AND (x0, x1) (a0, a1) s' (z0', z1')›*) by simp moreover have "w0 ∈ set_spmf (𝒜ss0 x0 (a0, s, z0) (a0, s', z0')) ⟶ (x0,w0) ∈ Rel0" for w0 using "3" (*‹check0 x0 a0 s z0›*) "4" (*‹check1 x1 a1 s' z1'›*) "Σ0.special_soundness_def" (*‹Σ0.special_soundness ≡ ∀h e e' a z z'. h ∈ valid_pub0 ⟶ e ∈ carrier L ⟶ e' ∈ carrier L ⟶ e ≠ e' ⟶ check0 h a e z ⟶ check0 h a e' z' ⟶ lossless_spmf (𝒜ss0 h (a, e, z) (a, e', z')) ∧ (∀w'∈set_spmf (𝒜ss0 h (a, e, z) (a, e', z')). (h, w') ∈ Rel0)›*) "Σ_prot0" (*‹Σ0.Σ_protocol›*) "Σ0.Σ_protocol_def" (*‹Σ0.Σ_protocol ≡ Σ0.completeness ∧ Σ0.special_soundness ∧ Σ0.HVZK›*) x0_in_dom (*‹x0 ∈ valid_pub0›*) challenge_space_def (*‹challenge_space = carrier L›*) assms (*‹(s::'e) ≠ (s'::'e)› ‹(x0::'g, x1::'a) ∈ valid_pub_AND› ‹(s::'e::type) ∈ challenge_space› ‹s' ∈ challenge_space› ‹check_AND (x0, x1) (a0, a1) s (z0, z1)› ‹check_AND (x0, x1) (a0, a1) s' (z0', z1')›*) valid_pub_AND_def (*‹valid_pub_AND = {(x0, x1). x0 ∈ valid_pub0 ∧ x1 ∈ valid_pub1}›*) valid_pub (*‹(x0, x1) ∈ valid_pub_AND›*) by fastforce moreover have "w1 ∈ set_spmf (𝒜ss1 x1 (a1, s, z1) (a1, s', z1')) ⟶ (x1,w1) ∈ Rel1" for w1 using "3" (*‹check0 x0 a0 s z0›*) "4" (*‹check1 x1 a1 s' z1'›*) "Σ1.special_soundness_def" (*‹Σ1.special_soundness ≡ ∀h e e' a z z'. h ∈ valid_pub1 ⟶ e ∈ carrier L ⟶ e' ∈ carrier L ⟶ e ≠ e' ⟶ check1 h a e z ⟶ check1 h a e' z' ⟶ lossless_spmf (𝒜ss1 h (a, e, z) (a, e', z')) ∧ (∀w'∈set_spmf (𝒜ss1 h (a, e, z) (a, e', z')). (h, w') ∈ Rel1)›*) "Σ_prot1" (*‹Σ1.Σ_protocol›*) "Σ1.Σ_protocol_def" (*‹Σ1.Σ_protocol ≡ Σ1.completeness ∧ Σ1.special_soundness ∧ Σ1.HVZK›*) x1_in_dom (*‹x1 ∈ valid_pub1›*) challenge_space_def (*‹challenge_space = carrier L›*) assms (*‹s ≠ s'› ‹(x0, x1) ∈ valid_pub_AND› ‹s ∈ challenge_space› ‹s' ∈ challenge_space› ‹check_AND (x0::'g, x1::'a) (a0::'j, a1::'d) (s::'e) (z0::'k, z1::'f)› ‹check_AND (x0, x1) (a0, a1) s' (z0', z1')›*) valid_pub_AND_def (*‹valid_pub_AND = {(x0, x1). x0 ∈ valid_pub0 ∧ x1 ∈ valid_pub1}›*) valid_pub (*‹(x0, x1) ∈ valid_pub_AND›*) by fastforce ultimately show "?thesis" (*goal: ‹lossless_spmf (𝒜ss_AND (x0, x1) ((a0, a1), s, z0, z1) ((a0, a1), s', z0', z1')) ∧ (∀w'∈set_spmf (𝒜ss_AND (x0, x1) ((a0, a1), s, z0, z1) ((a0, a1), s', z0', z1')). ((x0, x1), w') ∈ Rel_AND)›*) by (auto simp add: lossless_𝒜ss (*‹lossless_spmf (𝒜ss0 ?x0.0 (?a0.0, ?e, ?z0.0) (?a0.0, ?e', ?z0'))› ‹lossless_spmf (𝒜ss1 ?x1.0 (?a1.0, ?e, ?z1.0) (?a1.0, ?e', ?z1'))›*) Rel_AND_def (*‹Rel_AND = {((x0, x1), w0, w1). (x0, w0) ∈ Rel0 ∧ (x1, w1) ∈ Rel1}›*)) qed lemma special_soundness: shows "Σ_AND.special_soundness" using "Σ_AND.special_soundness_def" (*‹Σ_AND.special_soundness ≡ ∀h e e' a z z'. h ∈ valid_pub_AND ⟶ e ∈ challenge_space ⟶ e' ∈ challenge_space ⟶ e ≠ e' ⟶ check_AND h a e z ⟶ check_AND h a e' z' ⟶ lossless_spmf (𝒜ss_AND h (a, e, z) (a, e', z')) ∧ (∀w'∈set_spmf (𝒜ss_AND h (a, e, z) (a, e', z')). (h, w') ∈ Rel_AND)›*) ss (*‹⟦?s ≠ ?s'; (?x0.0, ?x1.0) ∈ valid_pub_AND; ?s ∈ challenge_space; ?s' ∈ challenge_space; check_AND (?x0.0, ?x1.0) (?a0.0, ?a1.0) ?s (?z0.0, ?z1.0); check_AND (?x0.0, ?x1.0) (?a0.0, ?a1.0) ?s' (?z0', ?z1')⟧ ⟹ lossless_spmf (𝒜ss_AND (?x0.0, ?x1.0) ((?a0.0, ?a1.0), ?s, ?z0.0, ?z1.0) ((?a0.0, ?a1.0), ?s', ?z0', ?z1')) ∧ (∀w'∈set_spmf (𝒜ss_AND (?x0.0, ?x1.0) ((?a0.0, ?a1.0), ?s, ?z0.0, ?z1.0) ((?a0.0, ?a1.0), ?s', ?z0', ?z1')). ((?x0.0, ?x1.0), w') ∈ Rel_AND)›*) by fast theorem Σ_protocol: shows "Σ_AND.Σ_protocol" by (auto simp add: Σ_AND.Σ_protocol_def (*‹Σ_AND.Σ_protocol ≡ Σ_AND.completeness ∧ Σ_AND.special_soundness ∧ Σ_AND.HVZK›*) completeness (*‹Σ_AND.completeness›*) HVZK (*‹Σ_AND.HVZK›*) special_soundness (*‹Σ_AND.special_soundness›*)) sublocale AND_Σ_commit: Σ_protocols_to_commitments init_AND response_AND check_AND Rel_AND S_AND 𝒜ss_AND challenge_space valid_pub_AND G apply unfold_locales (*goals: 1. ‹Σ_AND.Σ_protocol› 2. ‹⋀h w. (h, w) ∈ set_spmf G ⟹ (h, w) ∈ Rel_AND› 3. ‹lossless_spmf G› 4. ‹⋀h w. lossless_spmf (init_AND h w)› 5. ‹⋀r w e. lossless_spmf (response_AND r w e)› discuss goal 1*) apply ((auto simp add: Σ_protocol (*‹Σ_AND.Σ_protocol›*) set_spmf_G_L (*‹((?x0.0, ?x1.0), ?w0.0, ?w1.0) ∈ set_spmf G ⟹ ((?x0.0, ?x1.0), ?w0.0, ?w1.0) ∈ Rel_AND›*) lossless_G (*‹lossless_spmf G›*) lossless_init_AND (*‹lossless_spmf (init_AND ?X ?W)›*) lossless_response_AND (*‹lossless_spmf (response_AND ?R ?W ?s)›*))[1]) (*discuss goal 2*) apply ((auto simp add: Σ_protocol (*‹Σ_AND.Σ_protocol›*) set_spmf_G_L (*‹((?x0.0, ?x1.0), ?w0.0, ?w1.0) ∈ set_spmf G ⟹ ((?x0.0, ?x1.0), ?w0.0, ?w1.0) ∈ Rel_AND›*) lossless_G (*‹lossless_spmf G›*) lossless_init_AND (*‹lossless_spmf (init_AND ?X ?W)›*) lossless_response_AND (*‹lossless_spmf (response_AND ?R ?W ?s)›*))[1]) (*discuss goal 3*) apply ((auto simp add: Σ_protocol (*‹Σ_AND.Σ_protocol›*) set_spmf_G_L (*‹((?x0.0, ?x1.0), ?w0.0, ?w1.0) ∈ set_spmf G ⟹ ((?x0.0, ?x1.0), ?w0.0, ?w1.0) ∈ Rel_AND›*) lossless_G (*‹lossless_spmf G›*) lossless_init_AND (*‹lossless_spmf (init_AND ?X ?W)›*) lossless_response_AND (*‹lossless_spmf (response_AND ?R ?W ?s)›*))[1]) (*discuss goal 4*) apply ((auto simp add: Σ_protocol (*‹Σ_AND.Σ_protocol›*) set_spmf_G_L (*‹((?x0.0::'g::type, ?x1.0::'a::type), ?w0.0::'h::type, ?w1.0::'b::type) ∈ set_spmf (G::(('g::type × 'a::type) × 'h::type × 'b::type) spmf) ⟹ ((?x0.0, ?x1.0), ?w0.0, ?w1.0) ∈ Rel_AND›*) lossless_G (*‹lossless_spmf (G::(('g::type × 'a::type) × 'h::type × 'b::type) spmf)›*) lossless_init_AND (*‹lossless_spmf (init_AND (?X::'g::type × 'a::type) (?W::'h::type × 'b::type))›*) lossless_response_AND (*‹lossless_spmf (response_AND (?R::'i::type × 'c::type) (?W::'h::type × 'b::type) (?s::'e::type))›*))[1]) (*discuss goal 5*) apply ((auto simp add: Σ_protocol (*‹Σ_AND.Σ_protocol›*) set_spmf_G_L (*‹((?x0.0::'g, ?x1.0::'a), ?w0.0::'h, ?w1.0::'b) ∈ set_spmf (G::(('g × 'a) × 'h × 'b) spmf) ⟹ ((?x0.0, ?x1.0), ?w0.0, ?w1.0) ∈ Rel_AND›*) lossless_G (*‹lossless_spmf (G::(('g × 'a) × 'h × 'b) spmf)›*) lossless_init_AND (*‹lossless_spmf (init_AND (?X::'g × 'a) (?W::'h × 'b))›*) lossless_response_AND (*‹lossless_spmf (response_AND (?R::'i × 'c) (?W::'h × 'b) (?s::'e))›*))[1]) (*proven 5 subgoals*) . lemma "AND_Σ_commit.abstract_com.correct" using "AND_Σ_commit.commit_correct" (*‹AND_Σ_commit.abstract_com.correct›*) by simp lemma "AND_Σ_commit.abstract_com.perfect_hiding_ind_cpa 𝒜" using "AND_Σ_commit.perfect_hiding" (*‹AND_Σ_commit.abstract_com.perfect_hiding_ind_cpa (?𝒜::(('g × 'a) × 'h × 'b ⇒ (('e × 'e) × ?'a) spmf) × ('j × 'd ⇒ ?'a ⇒ bool spmf))›*) by blast lemma bind_advantage_bound_dis_log: shows "AND_Σ_commit.abstract_com.bind_advantage 𝒜 ≤ AND_Σ_commit.rel_advantage (AND_Σ_commit.adversary 𝒜)" using "AND_Σ_commit.bind_advantage" (*‹AND_Σ_commit.abstract_com.bind_advantage ?𝒜 ≤ AND_Σ_commit.rel_advantage (AND_Σ_commit.adversary ?𝒜)›*) by simp end end
{ "path": "afp-2025-02-12/thys/Sigma_Commit_Crypto/Sigma_AND.thy", "repo": "afp-2025-02-12", "sha": "36a3ad238f71d32ce4d277c9487083ac6a70f0246609c50ef0fee4c6fbcdcb1f" }
(* Title: HOL/UNITY/Union.thy Author: Lawrence C Paulson, Cambridge University Computer Laboratory Copyright 1998 University of Cambridge Partly from Misra's Chapter 5: Asynchronous Compositions of Programs. *) section‹Unions of Programs› theory Union imports SubstAx FP begin (*FIXME: conjoin Init F ∩ Init G ≠ {} *) definition ok :: "['a program, 'a program] => bool" (infixl "ok" 65) where "F ok G == Acts F ⊆ AllowedActs G & Acts G ⊆ AllowedActs F" (*FIXME: conjoin (⋂i ∈ I. Init (F i)) ≠ {} *) definition OK :: "['a set, 'a => 'b program] => bool" where "OK I F = (∀i ∈ I. ∀j ∈ I-{i}. Acts (F i) ⊆ AllowedActs (F j))" definition JOIN :: "['a set, 'a => 'b program] => 'b program" where "JOIN I F = mk_program (⋂i ∈ I. Init (F i), ⋃i ∈ I. Acts (F i), ⋂i ∈ I. AllowedActs (F i))" definition Join :: "['a program, 'a program] => 'a program" (infixl "⊔" 65) where "F ⊔ G = mk_program (Init F ∩ Init G, Acts F ∪ Acts G, AllowedActs F ∩ AllowedActs G)" definition SKIP :: "'a program" ("⊥") where "⊥ = mk_program (UNIV, {}, UNIV)" (*Characterizes safety properties. Used with specifying Allowed*) definition safety_prop :: "'a program set => bool" where "safety_prop X ⟷ SKIP ∈ X ∧ (∀G. Acts G ⊆ ⋃(Acts ` X) ⟶ G ∈ X)" syntax "_JOIN1" :: "[pttrns, 'b set] => 'b set" ("(3⨆_./ _)" 10) "_JOIN" :: "[pttrn, 'a set, 'b set] => 'b set" ("(3⨆_∈_./ _)" 10) translations "⨆x ∈ A. B" == "CONST JOIN A (λx. B)" "⨆x y. B" == "⨆x. ⨆y. B" "⨆x. B" == "CONST JOIN (CONST UNIV) (λx. B)" subsection‹SKIP› lemma Init_SKIP [simp]: "Init SKIP = UNIV" by (simp add: SKIP_def (*‹⊥ = mk_program (UNIV, {}, UNIV)›*)) lemma Acts_SKIP [simp]: "Acts SKIP = {Id}" by (simp add: SKIP_def (*‹⊥ = mk_program (UNIV, {}, UNIV)›*)) lemma AllowedActs_SKIP [simp]: "AllowedActs SKIP = UNIV" by (auto simp add: SKIP_def (*‹⊥ = mk_program (UNIV, {}, UNIV)›*)) lemma reachable_SKIP [simp]: "reachable SKIP = UNIV" by (force elim: reachable.induct (*‹⟦(?x::?'a) ∈ reachable (?F::?'a program); ⋀s::?'a. s ∈ Init ?F ⟹ (?P::?'a ⇒ bool) s; ⋀(act::(?'a × ?'a) set) (s::?'a) s'::?'a. ⟦act ∈ Acts ?F; s ∈ reachable ?F; ?P s; (s, s') ∈ act⟧ ⟹ ?P s'⟧ ⟹ ?P ?x›*) intro: reachable.intros (*‹(?s::?'a) ∈ Init (?F::?'a program) ⟹ ?s ∈ reachable ?F› ‹⟦(?act::(?'a × ?'a) set) ∈ Acts (?F::?'a program); (?s::?'a) ∈ reachable ?F; (?s, ?s'::?'a) ∈ ?act⟧ ⟹ ?s' ∈ reachable ?F›*)) subsection‹SKIP and safety properties› lemma SKIP_in_constrains_iff [iff]: "(SKIP ∈ A co B) = (A ⊆ B)" apply (unfold constrains_def (*‹?A co ?B ≡ {F. ∀act∈Acts F. act `` ?A ⊆ ?B}›*)) (*goal: ‹(⊥ ∈ A co B) = (A ⊆ B)›*) by auto lemma SKIP_in_Constrains_iff [iff]: "(SKIP ∈ A Co B) = (A ⊆ B)" apply (unfold Constrains_def (*‹?A Co ?B ≡ {F. F ∈ reachable F ∩ ?A co ?B}›*)) (*goal: ‹(⊥ ∈ A Co B) = (A ⊆ B)›*) by auto lemma SKIP_in_stable [iff]: "SKIP ∈ stable A" apply (unfold stable_def (*‹UNITY.stable ?A ≡ ?A co ?A›*)) (*goal: ‹⊥ ∈ UNITY.stable A›*) by auto declare SKIP_in_stable [THEN stable_imp_Stable, iff] subsection‹Join› lemma Init_Join [simp]: "Init (F⊔G) = Init F ∩ Init G" by (simp add: Join_def (*‹?F ⊔ ?G = mk_program (Init ?F ∩ Init ?G, Acts ?F ∪ Acts ?G, AllowedActs ?F ∩ AllowedActs ?G)›*)) lemma Acts_Join [simp]: "Acts (F⊔G) = Acts F ∪ Acts G" by (auto simp add: Join_def (*‹(?F::?'a::type program) ⊔ (?G::?'a::type program) = mk_program (Init ?F ∩ Init ?G, Acts ?F ∪ Acts ?G, AllowedActs ?F ∩ AllowedActs ?G)›*)) lemma AllowedActs_Join [simp]: "AllowedActs (F⊔G) = AllowedActs F ∩ AllowedActs G" by (auto simp add: Join_def (*‹?F ⊔ ?G = mk_program (Init ?F ∩ Init ?G, Acts ?F ∪ Acts ?G, AllowedActs ?F ∩ AllowedActs ?G)›*)) subsection‹JN› lemma JN_empty [simp]: "(⨆i∈{}. F i) = SKIP" apply (unfold JOIN_def (*‹JOIN ?I ?F = mk_program (⋂i∈?I. Init (?F i), ⋃i∈?I. Acts (?F i), ⋂i∈?I. AllowedActs (?F i))›*) SKIP_def (*‹⊥ = mk_program (UNIV, {}, UNIV)›*)) (*goal: ‹JOIN {} F = ⊥›*) by auto lemma JN_insert [simp]: "(⨆i ∈ insert a I. F i) = (F a)⊔(⨆i ∈ I. F i)" apply (rule program_equalityI (*‹⟦Init ?F = Init ?G; Acts ?F = Acts ?G; AllowedActs ?F = AllowedActs ?G⟧ ⟹ ?F = ?G›*)) (*goals: 1. ‹Init (JOIN (insert a I) F) = Init (F a ⊔ JOIN I F)› 2. ‹Acts (JOIN (insert a I) F) = Acts (F a ⊔ JOIN I F)› 3. ‹AllowedActs (JOIN (insert a I) F) = AllowedActs (F a ⊔ JOIN I F)› discuss goal 1*) apply ((auto simp add: JOIN_def (*‹JOIN ?I ?F = mk_program (⋂i∈?I. Init (?F i), ⋃i∈?I. Acts (?F i), ⋂i∈?I. AllowedActs (?F i))›*) Join_def (*‹?F ⊔ ?G = mk_program (Init ?F ∩ Init ?G, Acts ?F ∪ Acts ?G, AllowedActs ?F ∩ AllowedActs ?G)›*))[1]) (*discuss goal 2*) apply ((auto simp add: JOIN_def (*‹JOIN ?I ?F = mk_program (⋂i∈?I. Init (?F i), ⋃i∈?I. Acts (?F i), ⋂i∈?I. AllowedActs (?F i))›*) Join_def (*‹?F ⊔ ?G = mk_program (Init ?F ∩ Init ?G, Acts ?F ∪ Acts ?G, AllowedActs ?F ∩ AllowedActs ?G)›*))[1]) (*discuss goal 3*) apply ((auto simp add: JOIN_def (*‹JOIN ?I ?F = mk_program (⋂i∈?I. Init (?F i), ⋃i∈?I. Acts (?F i), ⋂i∈?I. AllowedActs (?F i))›*) Join_def (*‹?F ⊔ ?G = mk_program (Init ?F ∩ Init ?G, Acts ?F ∪ Acts ?G, AllowedActs ?F ∩ AllowedActs ?G)›*))[1]) (*proven 3 subgoals*) . lemma Init_JN [simp]: "Init (⨆i ∈ I. F i) = (⋂i ∈ I. Init (F i))" by (simp add: JOIN_def (*‹JOIN ?I ?F = mk_program (⋂i∈?I. Init (?F i), ⋃i∈?I. Acts (?F i), ⋂i∈?I. AllowedActs (?F i))›*)) lemma Acts_JN [simp]: "Acts (⨆i ∈ I. F i) = insert Id (⋃i ∈ I. Acts (F i))" by (auto simp add: JOIN_def (*‹JOIN ?I ?F = mk_program (⋂i∈?I. Init (?F i), ⋃i∈?I. Acts (?F i), ⋂i∈?I. AllowedActs (?F i))›*)) lemma AllowedActs_JN [simp]: "AllowedActs (⨆i ∈ I. F i) = (⋂i ∈ I. AllowedActs (F i))" by (auto simp add: JOIN_def (*‹JOIN ?I ?F = mk_program (⋂i∈?I. Init (?F i), ⋃i∈?I. Acts (?F i), ⋂i∈?I. AllowedActs (?F i))›*)) lemma JN_cong [cong]: "[| I=J; !!i. i ∈ J ==> F i = G i |] ==> (⨆i ∈ I. F i) = (⨆i ∈ J. G i)" by (simp add: JOIN_def (*‹JOIN ?I ?F = mk_program (⋂i∈?I. Init (?F i), ⋃i∈?I. Acts (?F i), ⋂i∈?I. AllowedActs (?F i))›*)) subsection‹Algebraic laws› lemma Join_commute: "F⊔G = G⊔F" by (simp add: Join_def (*‹?F ⊔ ?G = mk_program (Init ?F ∩ Init ?G, Acts ?F ∪ Acts ?G, AllowedActs ?F ∩ AllowedActs ?G)›*) Un_commute (*‹?A ∪ ?B = ?B ∪ ?A›*) Int_commute (*‹?A ∩ ?B = ?B ∩ ?A›*)) lemma Join_assoc: "(F⊔G)⊔H = F⊔(G⊔H)" by (simp add: Un_ac (*‹?A ∪ ?B ∪ ?C = ?A ∪ (?B ∪ ?C)› ‹?A ∪ (?A ∪ ?B) = ?A ∪ ?B› ‹?A ∪ ?B = ?B ∪ ?A› ‹?A ∪ (?B ∪ ?C) = ?B ∪ (?A ∪ ?C)›*) Join_def (*‹?F ⊔ ?G = mk_program (Init ?F ∩ Init ?G, Acts ?F ∪ Acts ?G, AllowedActs ?F ∩ AllowedActs ?G)›*) Int_assoc (*‹?A ∩ ?B ∩ ?C = ?A ∩ (?B ∩ ?C)›*) insert_absorb (*‹?a ∈ ?A ⟹ insert ?a ?A = ?A›*)) lemma Join_left_commute: "A⊔(B⊔C) = B⊔(A⊔C)" by (simp add: Un_ac (*‹(?A::?'a set) ∪ (?B::?'a set) ∪ (?C::?'a set) = ?A ∪ (?B ∪ ?C)› ‹(?A::?'a set) ∪ (?A ∪ (?B::?'a set)) = ?A ∪ ?B› ‹(?A::?'a set) ∪ (?B::?'a set) = ?B ∪ ?A› ‹(?A::?'a set) ∪ ((?B::?'a set) ∪ (?C::?'a set)) = ?B ∪ (?A ∪ ?C)›*) Int_ac (*‹(?A::?'a set) ∩ (?B::?'a set) ∩ (?C::?'a set) = ?A ∩ (?B ∩ ?C)› ‹(?A::?'a set) ∩ (?A ∩ (?B::?'a set)) = ?A ∩ ?B› ‹(?A::?'a set) ∩ (?B::?'a set) = ?B ∩ ?A› ‹(?A::?'a set) ∩ ((?B::?'a set) ∩ (?C::?'a set)) = ?B ∩ (?A ∩ ?C)›*) Join_def (*‹(?F::?'a program) ⊔ (?G::?'a program) = mk_program (Init ?F ∩ Init ?G, Acts ?F ∪ Acts ?G, AllowedActs ?F ∩ AllowedActs ?G)›*) insert_absorb (*‹(?a::?'a) ∈ (?A::?'a set) ⟹ insert ?a ?A = ?A›*)) lemma Join_SKIP_left [simp]: "SKIP⊔F = F" apply (unfold Join_def (*‹?F ⊔ ?G = mk_program (Init ?F ∩ Init ?G, Acts ?F ∪ Acts ?G, AllowedActs ?F ∩ AllowedActs ?G)›*) SKIP_def (*‹⊥ = mk_program (UNIV, {}, UNIV)›*)) (*goal: ‹⊥ ⊔ F = F›*) apply (rule program_equalityI (*‹⟦Init ?F = Init ?G; Acts ?F = Acts ?G; AllowedActs ?F = AllowedActs ?G⟧ ⟹ ?F = ?G›*)) (*goals: 1. ‹Init (mk_program (Init (mk_program (UNIV, {}, UNIV)) ∩ Init F, Acts (mk_program (UNIV, {}, UNIV)) ∪ Acts F, AllowedActs (mk_program (UNIV, {}, UNIV)) ∩ AllowedActs F)) = Init F› 2. ‹Acts (mk_program (Init (mk_program (UNIV, {}, UNIV)) ∩ Init F, Acts (mk_program (UNIV, {}, UNIV)) ∪ Acts F, AllowedActs (mk_program (UNIV, {}, UNIV)) ∩ AllowedActs F)) = Acts F› 3. ‹AllowedActs (mk_program (Init (mk_program (UNIV, {}, UNIV)) ∩ Init F, Acts (mk_program (UNIV, {}, UNIV)) ∪ Acts F, AllowedActs (mk_program (UNIV, {}, UNIV)) ∩ AllowedActs F)) = AllowedActs F› discuss goal 1*) apply (simp (no_asm) add: insert_absorb (*‹?a ∈ ?A ⟹ insert ?a ?A = ?A›*)) (*discuss goal 2*) apply (simp (no_asm) add: insert_absorb (*‹?a ∈ ?A ⟹ insert ?a ?A = ?A›*)) (*discuss goal 3*) apply (simp (no_asm) add: insert_absorb (*‹?a ∈ ?A ⟹ insert ?a ?A = ?A›*)) (*proven 3 subgoals*) . lemma Join_SKIP_right [simp]: "F⊔SKIP = F" apply (unfold Join_def (*‹?F ⊔ ?G = mk_program (Init ?F ∩ Init ?G, Acts ?F ∪ Acts ?G, AllowedActs ?F ∩ AllowedActs ?G)›*) SKIP_def (*‹⊥ = mk_program (UNIV, {}, UNIV)›*)) (*goal: ‹F ⊔ ⊥ = F›*) apply (rule program_equalityI (*‹⟦Init ?F = Init ?G; Acts ?F = Acts ?G; AllowedActs ?F = AllowedActs ?G⟧ ⟹ ?F = ?G›*)) (*goals: 1. ‹Init (mk_program (Init F ∩ Init (mk_program (UNIV, {}, UNIV)), Acts F ∪ Acts (mk_program (UNIV, {}, UNIV)), AllowedActs F ∩ AllowedActs (mk_program (UNIV, {}, UNIV)))) = Init F› 2. ‹Acts (mk_program (Init F ∩ Init (mk_program (UNIV, {}, UNIV)), Acts F ∪ Acts (mk_program (UNIV, {}, UNIV)), AllowedActs F ∩ AllowedActs (mk_program (UNIV, {}, UNIV)))) = Acts F› 3. ‹AllowedActs (mk_program (Init F ∩ Init (mk_program (UNIV, {}, UNIV)), Acts F ∪ Acts (mk_program (UNIV, {}, UNIV)), AllowedActs F ∩ AllowedActs (mk_program (UNIV, {}, UNIV)))) = AllowedActs F› discuss goal 1*) apply (simp (no_asm) add: insert_absorb (*‹?a ∈ ?A ⟹ insert ?a ?A = ?A›*)) (*discuss goal 2*) apply (simp (no_asm) add: insert_absorb (*‹?a ∈ ?A ⟹ insert ?a ?A = ?A›*)) (*discuss goal 3*) apply (simp (no_asm) add: insert_absorb (*‹?a ∈ ?A ⟹ insert ?a ?A = ?A›*)) (*proven 3 subgoals*) . lemma Join_absorb [simp]: "F⊔F = F" apply (unfold Join_def (*‹?F ⊔ ?G = mk_program (Init ?F ∩ Init ?G, Acts ?F ∪ Acts ?G, AllowedActs ?F ∩ AllowedActs ?G)›*)) (*goal: ‹F ⊔ F = F›*) apply (rule program_equalityI (*‹⟦Init ?F = Init ?G; Acts ?F = Acts ?G; AllowedActs ?F = AllowedActs ?G⟧ ⟹ ?F = ?G›*)) (*goals: 1. ‹Init (mk_program (Init F ∩ Init F, Acts F ∪ Acts F, AllowedActs F ∩ AllowedActs F)) = Init F› 2. ‹Acts (mk_program (Init F ∩ Init F, Acts F ∪ Acts F, AllowedActs F ∩ AllowedActs F)) = Acts F› 3. ‹AllowedActs (mk_program (Init F ∩ Init F, Acts F ∪ Acts F, AllowedActs F ∩ AllowedActs F)) = AllowedActs F› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . lemma Join_left_absorb: "F⊔(F⊔G) = F⊔G" apply (unfold Join_def (*‹?F ⊔ ?G = mk_program (Init ?F ∩ Init ?G, Acts ?F ∪ Acts ?G, AllowedActs ?F ∩ AllowedActs ?G)›*)) (*goal: ‹F ⊔ (F ⊔ G) = F ⊔ G›*) apply (rule program_equalityI (*‹⟦Init ?F = Init ?G; Acts ?F = Acts ?G; AllowedActs ?F = AllowedActs ?G⟧ ⟹ ?F = ?G›*)) (*goals: 1. ‹Init (mk_program (Init F ∩ Init (mk_program (Init F ∩ Init G, Acts F ∪ Acts G, AllowedActs F ∩ AllowedActs G)), Acts F ∪ Acts (mk_program (Init F ∩ Init G, Acts F ∪ Acts G, AllowedActs F ∩ AllowedActs G)), AllowedActs F ∩ AllowedActs (mk_program (Init F ∩ Init G, Acts F ∪ Acts G, AllowedActs F ∩ AllowedActs G)))) = Init (mk_program (Init F ∩ Init G, Acts F ∪ Acts G, AllowedActs F ∩ AllowedActs G))› 2. ‹Acts (mk_program (Init F ∩ Init (mk_program (Init F ∩ Init G, Acts F ∪ Acts G, AllowedActs F ∩ AllowedActs G)), Acts F ∪ Acts (mk_program (Init F ∩ Init G, Acts F ∪ Acts G, AllowedActs F ∩ AllowedActs G)), AllowedActs F ∩ AllowedActs (mk_program (Init F ∩ Init G, Acts F ∪ Acts G, AllowedActs F ∩ AllowedActs G)))) = Acts (mk_program (Init F ∩ Init G, Acts F ∪ Acts G, AllowedActs F ∩ AllowedActs G))› 3. ‹AllowedActs (mk_program (Init F ∩ Init (mk_program (Init F ∩ Init G, Acts F ∪ Acts G, AllowedActs F ∩ AllowedActs G)), Acts F ∪ Acts (mk_program (Init F ∩ Init G, Acts F ∪ Acts G, AllowedActs F ∩ AllowedActs G)), AllowedActs F ∩ AllowedActs (mk_program (Init F ∩ Init G, Acts F ∪ Acts G, AllowedActs F ∩ AllowedActs G)))) = AllowedActs (mk_program (Init F ∩ Init G, Acts F ∪ Acts G, AllowedActs F ∩ AllowedActs G))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . (*Join is an AC-operator*) lemmas Join_ac = Join_assoc Join_left_absorb Join_commute Join_left_commute subsection‹Laws Governing ‹⨆›› (*Also follows by JN_insert and insert_absorb, but the proof is longer*) lemma JN_absorb: "k ∈ I ==> F k⊔(⨆i ∈ I. F i) = (⨆i ∈ I. F i)" by (auto intro!: program_equalityI (*‹⟦Init (?F::?'a program) = Init (?G::?'a program); Acts ?F = Acts ?G; AllowedActs ?F = AllowedActs ?G⟧ ⟹ ?F = ?G›*)) lemma JN_Un: "(⨆i ∈ I ∪ J. F i) = ((⨆i ∈ I. F i)⊔(⨆i ∈ J. F i))" by (auto intro!: program_equalityI (*‹⟦Init (?F::?'a program) = Init (?G::?'a program); Acts ?F = Acts ?G; AllowedActs ?F = AllowedActs ?G⟧ ⟹ ?F = ?G›*)) lemma JN_constant: "(⨆i ∈ I. c) = (if I={} then SKIP else c)" apply (rule program_equalityI (*‹⟦Init ?F = Init ?G; Acts ?F = Acts ?G; AllowedActs ?F = AllowedActs ?G⟧ ⟹ ?F = ?G›*)) (*goals: 1. ‹Init (⨆i::'b∈I::'b set. c::'a program) = Init (if I = {} then ⊥ else c)› 2. ‹Acts (⨆i::'b∈I::'b set. c::'a program) = Acts (if I = {} then ⊥ else c)› 3. ‹AllowedActs (⨆i::'b∈I::'b set. c::'a program) = AllowedActs (if I = {} then ⊥ else c)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . lemma JN_Join_distrib: "(⨆i ∈ I. F i⊔G i) = (⨆i ∈ I. F i) ⊔ (⨆i ∈ I. G i)" by (auto intro!: program_equalityI (*‹⟦Init ?F = Init ?G; Acts ?F = Acts ?G; AllowedActs ?F = AllowedActs ?G⟧ ⟹ ?F = ?G›*)) lemma JN_Join_miniscope: "i ∈ I ==> (⨆i ∈ I. F i⊔G) = ((⨆i ∈ I. F i)⊔G)" by (auto simp add: JN_Join_distrib (*‹(⨆i∈?I. ?F i ⊔ ?G i) = JOIN ?I ?F ⊔ JOIN ?I ?G›*) JN_constant (*‹(⨆i∈?I. ?c) = (if ?I = {} then ⊥ else ?c)›*)) (*Used to prove guarantees_JN_I*) lemma JN_Join_diff: "i ∈ I ==> F i⊔JOIN (I - {i}) F = JOIN I F" apply (unfold JOIN_def (*‹JOIN ?I ?F = mk_program (⋂i∈?I. Init (?F i), ⋃i∈?I. Acts (?F i), ⋂i∈?I. AllowedActs (?F i))›*) Join_def (*‹?F ⊔ ?G = mk_program (Init ?F ∩ Init ?G, Acts ?F ∪ Acts ?G, AllowedActs ?F ∩ AllowedActs ?G)›*)) (*goal: ‹i ∈ I ⟹ F i ⊔ JOIN (I - {i}) F = JOIN I F›*) apply (rule program_equalityI (*‹⟦Init ?F = Init ?G; Acts ?F = Acts ?G; AllowedActs ?F = AllowedActs ?G⟧ ⟹ ?F = ?G›*)) (*goals: 1. ‹i ∈ I ⟹ Init (mk_program (Init (F i) ∩ Init (mk_program (⋂i∈I - {i}. Init (F i), ⋃i∈I - {i}. Acts (F i), ⋂i∈I - {i}. AllowedActs (F i))), Acts (F i) ∪ Acts (mk_program (⋂i∈I - {i}. Init (F i), ⋃i∈I - {i}. Acts (F i), ⋂i∈I - {i}. AllowedActs (F i))), AllowedActs (F i) ∩ AllowedActs (mk_program (⋂i∈I - {i}. Init (F i), ⋃i∈I - {i}. Acts (F i), ⋂i∈I - {i}. AllowedActs (F i))))) = Init (mk_program (⋂i∈I. Init (F i), ⋃i∈I. Acts (F i), ⋂i∈I. AllowedActs (F i)))› 2. ‹i ∈ I ⟹ Acts (mk_program (Init (F i) ∩ Init (mk_program (⋂i∈I - {i}. Init (F i), ⋃i∈I - {i}. Acts (F i), ⋂i∈I - {i}. AllowedActs (F i))), Acts (F i) ∪ Acts (mk_program (⋂i∈I - {i}. Init (F i), ⋃i∈I - {i}. Acts (F i), ⋂i∈I - {i}. AllowedActs (F i))), AllowedActs (F i) ∩ AllowedActs (mk_program (⋂i∈I - {i}. Init (F i), ⋃i∈I - {i}. Acts (F i), ⋂i∈I - {i}. AllowedActs (F i))))) = Acts (mk_program (⋂i∈I. Init (F i), ⋃i∈I. Acts (F i), ⋂i∈I. AllowedActs (F i)))› 3. ‹i ∈ I ⟹ AllowedActs (mk_program (Init (F i) ∩ Init (mk_program (⋂i∈I - {i}. Init (F i), ⋃i∈I - {i}. Acts (F i), ⋂i∈I - {i}. AllowedActs (F i))), Acts (F i) ∪ Acts (mk_program (⋂i∈I - {i}. Init (F i), ⋃i∈I - {i}. Acts (F i), ⋂i∈I - {i}. AllowedActs (F i))), AllowedActs (F i) ∩ AllowedActs (mk_program (⋂i∈I - {i}. Init (F i), ⋃i∈I - {i}. Acts (F i), ⋂i∈I - {i}. AllowedActs (F i))))) = AllowedActs (mk_program (⋂i∈I. Init (F i), ⋃i∈I. Acts (F i), ⋂i∈I. AllowedActs (F i)))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . subsection‹Safety: co, stable, FP› (*Fails if I={} because it collapses to SKIP ∈ A co B, i.e. to A ⊆ B. So an alternative precondition is A ⊆ B, but most proofs using this rule require I to be nonempty for other reasons anyway.*) lemma JN_constrains: "i ∈ I ==> (⨆i ∈ I. F i) ∈ A co B = (∀i ∈ I. F i ∈ A co B)" apply (simp add: constrains_def (*‹?A co ?B ≡ {F. ∀act∈Acts F. act `` ?A ⊆ ?B}›*) JOIN_def (*‹JOIN ?I ?F = mk_program (⋂i∈?I. Init (?F i), ⋃i∈?I. Acts (?F i), ⋂i∈?I. AllowedActs (?F i))›*)) (*goal: ‹i ∈ I ⟹ (JOIN I F ∈ A co B) = (∀i∈I. F i ∈ A co B)›*) by blast lemma Join_constrains [simp]: "(F⊔G ∈ A co B) = (F ∈ A co B & G ∈ A co B)" by (auto simp add: constrains_def (*‹?A co ?B ≡ {F. ∀act∈Acts F. act `` ?A ⊆ ?B}›*) Join_def (*‹?F ⊔ ?G = mk_program (Init ?F ∩ Init ?G, Acts ?F ∪ Acts ?G, AllowedActs ?F ∩ AllowedActs ?G)›*)) lemma Join_unless [simp]: "(F⊔G ∈ A unless B) = (F ∈ A unless B & G ∈ A unless B)" by (simp add: unless_def (*‹(?A::?'a set) unless (?B::?'a set) ≡ ?A - ?B co ?A ∪ ?B›*)) (*Analogous weak versions FAIL; see Misra [1994] 5.4.1, Substitution Axiom. reachable (F⊔G) could be much bigger than reachable F, reachable G *) lemma Join_constrains_weaken: "[| F ∈ A co A'; G ∈ B co B' |] ==> F⊔G ∈ (A ∩ B) co (A' ∪ B')" apply simp (*goal: ‹⟦F ∈ A co A'; G ∈ B co B'⟧ ⟹ F ⊔ G ∈ A ∩ B co A' ∪ B'›*) by (blast intro: constrains_weaken (*‹⟦?F ∈ ?A co ?A'; ?B ⊆ ?A; ?A' ⊆ ?B'⟧ ⟹ ?F ∈ ?B co ?B'›*)) (*If I={}, it degenerates to SKIP ∈ UNIV co {}, which is false.*) lemma JN_constrains_weaken: "[| ∀i ∈ I. F i ∈ A i co A' i; i ∈ I |] ==> (⨆i ∈ I. F i) ∈ (⋂i ∈ I. A i) co (⋃i ∈ I. A' i)" apply (simp (no_asm_simp) add: JN_constrains (*‹?i ∈ ?I ⟹ (JOIN ?I ?F ∈ ?A co ?B) = (∀i∈?I. ?F i ∈ ?A co ?B)›*)) (*goal: ‹⟦∀i::'a::type∈I::'a::type set. (F::'a::type ⇒ 'b::type program) i ∈ (A::'a::type ⇒ 'b::type set) i co (A'::'a::type ⇒ 'b::type set) i; (i::'a::type) ∈ I⟧ ⟹ JOIN I F ∈ ⋂ (A ` I) co ⋃ (A' ` I)›*) by (blast intro: constrains_weaken (*‹⟦?F ∈ ?A co ?A'; ?B ⊆ ?A; ?A' ⊆ ?B'⟧ ⟹ ?F ∈ ?B co ?B'›*)) lemma JN_stable: "(⨆i ∈ I. F i) ∈ stable A = (∀i ∈ I. F i ∈ stable A)" by (simp add: stable_def (*‹UNITY.stable (?A::?'a set) ≡ ?A co ?A›*) constrains_def (*‹(?A::?'a set) co (?B::?'a set) ≡ {F::?'a program. ∀act::(?'a × ?'a) set∈Acts F. act `` ?A ⊆ ?B}›*) JOIN_def (*‹JOIN (?I::?'a set) (?F::?'a ⇒ ?'b program) = mk_program (⋂i::?'a∈?I. Init (?F i), ⋃i::?'a∈?I. Acts (?F i), ⋂i::?'a∈?I. AllowedActs (?F i))›*)) lemma invariant_JN_I: "[| !!i. i ∈ I ==> F i ∈ invariant A; i ∈ I |] ==> (⨆i ∈ I. F i) ∈ invariant A" apply (simp add: invariant_def (*‹invariant ?A ≡ {F. Init F ⊆ ?A} ∩ UNITY.stable ?A›*) JN_stable (*‹(JOIN ?I ?F ∈ UNITY.stable ?A) = (∀i∈?I. ?F i ∈ UNITY.stable ?A)›*)) (*goal: ‹⟦⋀i. i ∈ I ⟹ F i ∈ invariant A; i ∈ I⟧ ⟹ JOIN I F ∈ invariant A›*) by blast lemma Join_stable [simp]: "(F⊔G ∈ stable A) = (F ∈ stable A & G ∈ stable A)" by (simp add: stable_def (*‹UNITY.stable (?A::?'a set) ≡ ?A co ?A›*)) lemma Join_increasing [simp]: "(F⊔G ∈ increasing f) = (F ∈ increasing f & G ∈ increasing f)" by (auto simp add: increasing_def (*‹increasing (?f::?'a::type ⇒ ?'b::order) ≡ ⋂z::?'b::order. UNITY.stable {s::?'a::type. z ≤ ?f s}›*)) lemma invariant_JoinI: "[| F ∈ invariant A; G ∈ invariant A |] ==> F⊔G ∈ invariant A" by (auto simp add: invariant_def (*‹invariant ?A ≡ {F. Init F ⊆ ?A} ∩ UNITY.stable ?A›*)) lemma FP_JN: "FP (⨆i ∈ I. F i) = (⋂i ∈ I. FP (F i))" by (simp add: FP_def (*‹FP ?F ≡ {s. ?F ∈ UNITY.stable {s}}›*) JN_stable (*‹(JOIN ?I ?F ∈ UNITY.stable ?A) = (∀i∈?I. ?F i ∈ UNITY.stable ?A)›*) INTER_eq (*‹⋂ (?B ` ?A) = {y. ∀x∈?A. y ∈ ?B x}›*)) subsection‹Progress: transient, ensures› lemma JN_transient: "i ∈ I ==> (⨆i ∈ I. F i) ∈ transient A = (∃i ∈ I. F i ∈ transient A)" by (auto simp add: transient_def (*‹transient (?A::?'a::type set) ≡ {F::?'a::type program. ∃act::(?'a::type × ?'a::type) set∈Acts F. act `` ?A ⊆ - ?A}›*) JOIN_def (*‹JOIN (?I::?'a::type set) (?F::?'a::type ⇒ ?'b::type program) = mk_program (⋂i::?'a::type∈?I. Init (?F i), ⋃i::?'a::type∈?I. Acts (?F i), ⋂i::?'a::type∈?I. AllowedActs (?F i))›*)) lemma Join_transient [simp]: "F⊔G ∈ transient A = (F ∈ transient A | G ∈ transient A)" by (auto simp add: bex_Un (*‹(∃x∈?A ∪ ?B. ?P x) = ((∃x∈?A. ?P x) ∨ (∃x∈?B. ?P x))›*) transient_def (*‹transient ?A ≡ {F. ∃act∈Acts F. act `` ?A ⊆ - ?A}›*) Join_def (*‹?F ⊔ ?G = mk_program (Init ?F ∩ Init ?G, Acts ?F ∪ Acts ?G, AllowedActs ?F ∩ AllowedActs ?G)›*)) lemma Join_transient_I1: "F ∈ transient A ==> F⊔G ∈ transient A" by simp lemma Join_transient_I2: "G ∈ transient A ==> F⊔G ∈ transient A" by simp (*If I={} it degenerates to (SKIP ∈ A ensures B) = False, i.e. to ~(A ⊆ B) *) lemma JN_ensures: "i ∈ I ==> (⨆i ∈ I. F i) ∈ A ensures B = ((∀i ∈ I. F i ∈ (A-B) co (A ∪ B)) & (∃i ∈ I. F i ∈ A ensures B))" by (auto simp add: ensures_def (*‹?A ensures ?B ≡ (?A - ?B co ?A ∪ ?B) ∩ transient (?A - ?B)›*) JN_constrains (*‹?i ∈ ?I ⟹ (JOIN ?I ?F ∈ ?A co ?B) = (∀i∈?I. ?F i ∈ ?A co ?B)›*) JN_transient (*‹?i ∈ ?I ⟹ (JOIN ?I ?F ∈ transient ?A) = (∃i∈?I. ?F i ∈ transient ?A)›*)) lemma Join_ensures: "F⊔G ∈ A ensures B = (F ∈ (A-B) co (A ∪ B) & G ∈ (A-B) co (A ∪ B) & (F ∈ transient (A-B) | G ∈ transient (A-B)))" by (auto simp add: ensures_def (*‹(?A::?'a set) ensures (?B::?'a set) ≡ (?A - ?B co ?A ∪ ?B) ∩ transient (?A - ?B)›*)) lemma stable_Join_constrains: "[| F ∈ stable A; G ∈ A co A' |] ==> F⊔G ∈ A co A'" apply (unfold stable_def (*‹UNITY.stable ?A ≡ ?A co ?A›*) constrains_def (*‹?A co ?B ≡ {F. ∀act∈Acts F. act `` ?A ⊆ ?B}›*) Join_def (*‹?F ⊔ ?G = mk_program (Init ?F ∩ Init ?G, Acts ?F ∪ Acts ?G, AllowedActs ?F ∩ AllowedActs ?G)›*)) (*goal: ‹⟦F ∈ UNITY.stable A; G ∈ A co A'⟧ ⟹ F ⊔ G ∈ A co A'›*) apply (simp add: ball_Un (*‹(∀x∈?A ∪ ?B. ?P x) = ((∀x∈?A. ?P x) ∧ (∀x∈?B. ?P x))›*)) (*goal: ‹⟦F ∈ {F. ∀act∈Acts F. act `` A ⊆ A}; G ∈ {F. ∀act∈Acts F. act `` A ⊆ A'}⟧ ⟹ mk_program (Init F ∩ Init G, Acts F ∪ Acts G, AllowedActs F ∩ AllowedActs G) ∈ {F. ∀act∈Acts F. act `` A ⊆ A'}›*) by blast (*Premise for G cannot use Always because F ∈ Stable A is weaker than G ∈ stable A *) lemma stable_Join_Always1: "[| F ∈ stable A; G ∈ invariant A |] ==> F⊔G ∈ Always A" apply (simp (no_asm_use) add: Always_def (*‹Always ?A ≡ {F. Init F ⊆ ?A} ∩ Stable ?A›*) invariant_def (*‹invariant ?A ≡ {F. Init F ⊆ ?A} ∩ UNITY.stable ?A›*) Stable_eq_stable (*‹(?F ∈ Stable ?A) = (?F ∈ UNITY.stable (reachable ?F ∩ ?A))›*)) (*goal: ‹⟦F ∈ UNITY.stable A; G ∈ invariant A⟧ ⟹ F ⊔ G ∈ Always A›*) by (force intro: stable_Int (*‹⟦(?F::?'a::type program) ∈ UNITY.stable (?A::?'a::type set); ?F ∈ UNITY.stable (?A'::?'a::type set)⟧ ⟹ ?F ∈ UNITY.stable (?A ∩ ?A')›*)) (*As above, but exchanging the roles of F and G*) lemma stable_Join_Always2: "[| F ∈ invariant A; G ∈ stable A |] ==> F⊔G ∈ Always A" apply (subst Join_commute (*‹?F ⊔ ?G = ?G ⊔ ?F›*)) (*goal: ‹⟦F ∈ invariant A; G ∈ UNITY.stable A⟧ ⟹ F ⊔ G ∈ Always A›*) by (blast intro: stable_Join_Always1 (*‹⟦?F ∈ UNITY.stable ?A; ?G ∈ invariant ?A⟧ ⟹ ?F ⊔ ?G ∈ Always ?A›*)) lemma stable_Join_ensures1: "[| F ∈ stable A; G ∈ A ensures B |] ==> F⊔G ∈ A ensures B" apply (simp (no_asm_simp) add: Join_ensures (*‹(?F ⊔ ?G ∈ ?A ensures ?B) = (?F ∈ ?A - ?B co ?A ∪ ?B ∧ ?G ∈ ?A - ?B co ?A ∪ ?B ∧ (?F ∈ transient (?A - ?B) ∨ ?G ∈ transient (?A - ?B)))›*)) (*goal: ‹⟦F ∈ UNITY.stable A; G ∈ A ensures B⟧ ⟹ F ⊔ G ∈ A ensures B›*) apply (simp add: stable_def (*‹UNITY.stable ?A ≡ ?A co ?A›*) ensures_def (*‹?A ensures ?B ≡ (?A - ?B co ?A ∪ ?B) ∩ transient (?A - ?B)›*)) (*goal: ‹⟦F ∈ UNITY.stable A; G ∈ A ensures B⟧ ⟹ F ∈ A - B co A ∪ B ∧ G ∈ A - B co A ∪ B ∧ (F ∈ transient (A - B) ∨ G ∈ transient (A - B))›*) apply (erule constrains_weaken (*‹⟦(?F::?'a::type program) ∈ (?A::?'a::type set) co (?A'::?'a::type set); (?B::?'a::type set) ⊆ ?A; ?A' ⊆ (?B'::?'a::type set)⟧ ⟹ ?F ∈ ?B co ?B'›*)) (*goals: 1. ‹G ∈ A - B co A ∪ B ∧ G ∈ transient (A - B) ⟹ A - B ⊆ A› 2. ‹G ∈ A - B co A ∪ B ∧ G ∈ transient (A - B) ⟹ A ⊆ A ∪ B› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . (*As above, but exchanging the roles of F and G*) lemma stable_Join_ensures2: "[| F ∈ A ensures B; G ∈ stable A |] ==> F⊔G ∈ A ensures B" apply (subst Join_commute (*‹(?F::?'a program) ⊔ (?G::?'a program) = ?G ⊔ ?F›*)) (*goal: ‹⟦F ∈ A ensures B; G ∈ UNITY.stable A⟧ ⟹ F ⊔ G ∈ A ensures B›*) by (blast intro: stable_Join_ensures1 (*‹⟦?F ∈ UNITY.stable ?A; ?G ∈ ?A ensures ?B⟧ ⟹ ?F ⊔ ?G ∈ ?A ensures ?B›*)) subsection‹the ok and OK relations› lemma ok_SKIP1 [iff]: "SKIP ok F" by (simp add: ok_def (*‹?F ok ?G ≡ Acts ?F ⊆ AllowedActs ?G ∧ Acts ?G ⊆ AllowedActs ?F›*)) lemma ok_SKIP2 [iff]: "F ok SKIP" by (simp add: ok_def (*‹?F ok ?G ≡ Acts ?F ⊆ AllowedActs ?G ∧ Acts ?G ⊆ AllowedActs ?F›*)) lemma ok_Join_commute: "(F ok G & (F⊔G) ok H) = (G ok H & F ok (G⊔H))" by (auto simp add: ok_def (*‹?F ok ?G ≡ Acts ?F ⊆ AllowedActs ?G ∧ Acts ?G ⊆ AllowedActs ?F›*)) lemma ok_commute: "(F ok G) = (G ok F)" by (auto simp add: ok_def (*‹(?F::?'a program) ok (?G::?'a program) ≡ Acts ?F ⊆ AllowedActs ?G ∧ Acts ?G ⊆ AllowedActs ?F›*)) lemmas ok_sym = ok_commute [THEN iffD1] lemma ok_iff_OK: "OK {(0::int,F),(1,G),(2,H)} snd = (F ok G & (F⊔G) ok H)" apply (simp add: Ball_def (*‹Ball ?A ?P = (∀x. x ∈ ?A ⟶ ?P x)›*) conj_disj_distribR (*‹((?P ∨ ?Q) ∧ ?R) = (?P ∧ ?R ∨ ?Q ∧ ?R)›*) ok_def (*‹?F ok ?G ≡ Acts ?F ⊆ AllowedActs ?G ∧ Acts ?G ⊆ AllowedActs ?F›*) Join_def (*‹?F ⊔ ?G = mk_program (Init ?F ∩ Init ?G, Acts ?F ∪ Acts ?G, AllowedActs ?F ∩ AllowedActs ?G)›*) OK_def (*‹OK ?I ?F = (∀i∈?I. ∀j∈?I - {i}. Acts (?F i) ⊆ AllowedActs (?F j))›*) insert_absorb (*‹?a ∈ ?A ⟹ insert ?a ?A = ?A›*) all_conj_distrib (*‹(∀x. ?P x ∧ ?Q x) = ((∀x. ?P x) ∧ (∀x. ?Q x))›*)) (*goal: ‹OK {(0, F), (1, G), (2, H)} snd = (F ok G ∧ F ⊔ G ok H)›*) by blast lemma ok_Join_iff1 [iff]: "F ok (G⊔H) = (F ok G & F ok H)" by (auto simp add: ok_def (*‹?F ok ?G ≡ Acts ?F ⊆ AllowedActs ?G ∧ Acts ?G ⊆ AllowedActs ?F›*)) lemma ok_Join_iff2 [iff]: "(G⊔H) ok F = (G ok F & H ok F)" by (auto simp add: ok_def (*‹?F ok ?G ≡ Acts ?F ⊆ AllowedActs ?G ∧ Acts ?G ⊆ AllowedActs ?F›*)) (*useful? Not with the previous two around*) lemma ok_Join_commute_I: "[| F ok G; (F⊔G) ok H |] ==> F ok (G⊔H)" by (auto simp add: ok_def (*‹?F ok ?G ≡ Acts ?F ⊆ AllowedActs ?G ∧ Acts ?G ⊆ AllowedActs ?F›*)) lemma ok_JN_iff1 [iff]: "F ok (JOIN I G) = (∀i ∈ I. F ok G i)" by (auto simp add: ok_def (*‹(?F::?'a::type program) ok (?G::?'a::type program) ≡ Acts ?F ⊆ AllowedActs ?G ∧ Acts ?G ⊆ AllowedActs ?F›*)) lemma ok_JN_iff2 [iff]: "(JOIN I G) ok F = (∀i ∈ I. G i ok F)" by (auto simp add: ok_def (*‹?F ok ?G ≡ Acts ?F ⊆ AllowedActs ?G ∧ Acts ?G ⊆ AllowedActs ?F›*)) lemma OK_iff_ok: "OK I F = (∀i ∈ I. ∀j ∈ I-{i}. (F i) ok (F j))" by (auto simp add: ok_def (*‹?F ok ?G ≡ Acts ?F ⊆ AllowedActs ?G ∧ Acts ?G ⊆ AllowedActs ?F›*) OK_def (*‹OK ?I ?F = (∀i∈?I. ∀j∈?I - {i}. Acts (?F i) ⊆ AllowedActs (?F j))›*)) lemma OK_imp_ok: "[| OK I F; i ∈ I; j ∈ I; i ≠ j|] ==> (F i) ok (F j)" by (auto simp add: OK_iff_ok (*‹OK (?I::?'a set) (?F::?'a ⇒ ?'b program) = (∀i::?'a∈?I. ∀j::?'a∈?I - {i}. ?F i ok ?F j)›*)) subsection‹Allowed› lemma Allowed_SKIP [simp]: "Allowed SKIP = UNIV" by (auto simp add: Allowed_def (*‹Allowed ?F ≡ {G. Acts G ⊆ AllowedActs ?F}›*)) lemma Allowed_Join [simp]: "Allowed (F⊔G) = Allowed F ∩ Allowed G" by (auto simp add: Allowed_def (*‹Allowed ?F ≡ {G. Acts G ⊆ AllowedActs ?F}›*)) lemma Allowed_JN [simp]: "Allowed (JOIN I F) = (⋂i ∈ I. Allowed (F i))" by (auto simp add: Allowed_def (*‹Allowed ?F ≡ {G. Acts G ⊆ AllowedActs ?F}›*)) lemma ok_iff_Allowed: "F ok G = (F ∈ Allowed G & G ∈ Allowed F)" by (simp add: ok_def (*‹?F ok ?G ≡ Acts ?F ⊆ AllowedActs ?G ∧ Acts ?G ⊆ AllowedActs ?F›*) Allowed_def (*‹Allowed ?F ≡ {G. Acts G ⊆ AllowedActs ?F}›*)) lemma OK_iff_Allowed: "OK I F = (∀i ∈ I. ∀j ∈ I-{i}. F i ∈ Allowed(F j))" by (auto simp add: OK_iff_ok (*‹OK ?I ?F = (∀i∈?I. ∀j∈?I - {i}. ?F i ok ?F j)›*) ok_iff_Allowed (*‹?F ok ?G = (?F ∈ Allowed ?G ∧ ?G ∈ Allowed ?F)›*)) subsection‹\<^term>‹safety_prop›, for reasoning about given instances of "ok"› lemma safety_prop_Acts_iff: "safety_prop X ==> (Acts G ⊆ insert Id (⋃(Acts ` X))) = (G ∈ X)" by (auto simp add: safety_prop_def (*‹safety_prop ?X = (⊥ ∈ ?X ∧ (∀G. Acts G ⊆ ⋃ (Acts ` ?X) ⟶ G ∈ ?X))›*)) lemma safety_prop_AllowedActs_iff_Allowed: "safety_prop X ==> (⋃(Acts ` X) ⊆ AllowedActs F) = (X ⊆ Allowed F)" by (auto simp add: Allowed_def (*‹Allowed ?F ≡ {G. Acts G ⊆ AllowedActs ?F}›*) safety_prop_Acts_iff [symmetric] (*‹safety_prop ?X ⟹ (?G ∈ ?X) = (Acts ?G ⊆ insert Id (⋃ (Acts ` ?X)))›*)) lemma Allowed_eq: "safety_prop X ==> Allowed (mk_program (init, acts, ⋃(Acts ` X))) = X" by (simp add: Allowed_def (*‹Allowed (?F::?'a program) ≡ {G::?'a program. Acts G ⊆ AllowedActs ?F}›*) safety_prop_Acts_iff (*‹safety_prop (?X::?'a program set) ⟹ (Acts (?G::?'a program) ⊆ insert Id (⋃ (Acts ` ?X))) = (?G ∈ ?X)›*)) (*For safety_prop to hold, the property must be satisfiable!*) lemma safety_prop_constrains [iff]: "safety_prop (A co B) = (A ⊆ B)" apply (simp add: safety_prop_def (*‹safety_prop ?X = (⊥ ∈ ?X ∧ (∀G. Acts G ⊆ ⋃ (Acts ` ?X) ⟶ G ∈ ?X))›*) constrains_def (*‹?A co ?B ≡ {F. ∀act∈Acts F. act `` ?A ⊆ ?B}›*)) (*goal: ‹safety_prop (A co B) = (A ⊆ B)›*) by blast lemma safety_prop_stable [iff]: "safety_prop (stable A)" by (simp add: stable_def (*‹UNITY.stable (?A::?'a set) ≡ ?A co ?A›*)) lemma safety_prop_Int [simp]: "safety_prop X ⟹ safety_prop Y ⟹ safety_prop (X ∩ Y)" proof (clarsimp simp add: safety_prop_def (*‹safety_prop ?X = (⊥ ∈ ?X ∧ (∀G. Acts G ⊆ ⋃ (Acts ` ?X) ⟶ G ∈ ?X))›*)) (*goal: ‹⋀G. ⟦⊥ ∈ X; ∀G. Acts G ⊆ ⋃ (Acts ` X) ⟶ G ∈ X; ⊥ ∈ Y; ∀G. Acts G ⊆ ⋃ (Acts ` Y) ⟶ G ∈ Y; Acts G ⊆ ⋃ (Acts ` (X ∩ Y))⟧ ⟹ G ∈ X ∧ G ∈ Y›*) fix G assume "∀G. Acts G ⊆ (⋃x∈X. Acts x) ⟶ G ∈ X" (*‹∀G::'a program. Acts G ⊆ ⋃ (Acts ` (X::'a program set)) ⟶ G ∈ X›*) then have X: "Acts G ⊆ (⋃x∈X. Acts x) ⟹ G ∈ X" by blast assume "∀G. Acts G ⊆ (⋃x∈Y. Acts x) ⟶ G ∈ Y" (*‹∀G::'a program. Acts G ⊆ ⋃ (Acts ` (Y::'a program set)) ⟶ G ∈ Y›*) then have Y: "Acts G ⊆ (⋃x∈Y. Acts x) ⟹ G ∈ Y" by blast assume Acts: "Acts G ⊆ (⋃x∈X ∩ Y. Acts x)" (*‹Acts (G::'a program) ⊆ ⋃ (Acts ` ((X::'a program set) ∩ (Y::'a program set)))›*) with X (*‹Acts G ⊆ ⋃ (Acts ` X) ⟹ G ∈ X›*) Y (*‹Acts G ⊆ ⋃ (Acts ` Y) ⟹ G ∈ Y›*) show "G ∈ X ∧ G ∈ Y" by auto qed lemma safety_prop_INTER [simp]: "(⋀i. i ∈ I ⟹ safety_prop (X i)) ⟹ safety_prop (⋂i∈I. X i)" proof (clarsimp simp add: safety_prop_def (*‹safety_prop ?X = (⊥ ∈ ?X ∧ (∀G. Acts G ⊆ ⋃ (Acts ` ?X) ⟶ G ∈ ?X))›*)) (*goal: ‹⋀(G::'b program) x::'a. ⟦⋀i::'a. i ∈ (I::'a set) ⟹ ⊥ ∈ (X::'a ⇒ 'b program set) i ∧ (∀G::'b program. Acts G ⊆ ⋃ (Acts ` X i) ⟶ G ∈ X i); Acts G ⊆ ⋃ (Acts ` ⋂ (X ` I)); x ∈ I⟧ ⟹ G ∈ X x›*) fix G and i assume "⋀i. i ∈ I ⟹ ⊥ ∈ X i ∧ (∀G. Acts G ⊆ (⋃x∈X i. Acts x) ⟶ G ∈ X i)" (*‹(?i::'a) ∈ (I::'a set) ⟹ ⊥ ∈ (X::'a ⇒ 'b program set) ?i ∧ (∀G::'b program. Acts G ⊆ ⋃ (Acts ` X ?i) ⟶ G ∈ X ?i)›*) then have "*": "i ∈ I ⟹ Acts G ⊆ (⋃x∈X i. Acts x) ⟹ G ∈ X i" by blast assume "i ∈ I" (*‹(i::'a) ∈ (I::'a set)›*) moreover assume "Acts G ⊆ (⋃j∈⋂i∈I. X i. Acts j)" (*‹Acts (G::'b program) ⊆ ⋃ (Acts ` ⋂ ((X::'a ⇒ 'b program set) ` (I::'a set)))›*) ultimately have "Acts G ⊆ (⋃i∈X i. Acts i)" by auto with "*" (*‹⟦i ∈ I; Acts G ⊆ ⋃ (Acts ` X i)⟧ ⟹ G ∈ X i›*) ‹i ∈ I› (*‹i ∈ I›*) show "G ∈ X i" by blast qed lemma safety_prop_INTER1 [simp]: "(⋀i. safety_prop (X i)) ⟹ safety_prop (⋂i. X i)" apply (rule safety_prop_INTER (*‹(⋀i. i ∈ ?I ⟹ safety_prop (?X i)) ⟹ safety_prop (⋂ (?X ` ?I))›*)) (*goal: ‹(⋀i. safety_prop (X i)) ⟹ safety_prop (⋂ (range X))›*) by simp lemma def_prg_Allowed: "[| F == mk_program (init, acts, ⋃(Acts ` X)) ; safety_prop X |] ==> Allowed F = X" by (simp add: Allowed_eq (*‹safety_prop ?X ⟹ Allowed (mk_program (?init, ?acts, ⋃ (Acts ` ?X))) = ?X›*)) lemma Allowed_totalize [simp]: "Allowed (totalize F) = Allowed F" by (simp add: Allowed_def (*‹Allowed ?F ≡ {G. Acts G ⊆ AllowedActs ?F}›*)) lemma def_total_prg_Allowed: "[| F = mk_total_program (init, acts, ⋃(Acts ` X)) ; safety_prop X |] ==> Allowed F = X" by (simp add: mk_total_program_def (*‹mk_total_program ?args ≡ totalize (mk_program ?args)›*) def_prg_Allowed (*‹⟦?F ≡ mk_program (?init, ?acts, ⋃ (Acts ` ?X)); safety_prop ?X⟧ ⟹ Allowed ?F = ?X›*)) lemma def_UNION_ok_iff: "[| F = mk_program(init,acts,⋃(Acts ` X)); safety_prop X |] ==> F ok G = (G ∈ X & acts ⊆ AllowedActs G)" by (auto simp add: ok_def (*‹?F ok ?G ≡ Acts ?F ⊆ AllowedActs ?G ∧ Acts ?G ⊆ AllowedActs ?F›*) safety_prop_Acts_iff (*‹safety_prop ?X ⟹ (Acts ?G ⊆ insert Id (⋃ (Acts ` ?X))) = (?G ∈ ?X)›*)) text‹The union of two total programs is total.› lemma totalize_Join: "totalize F⊔totalize G = totalize (F⊔G)" by (simp add: program_equalityI (*‹⟦Init (?F::?'a::type program) = Init (?G::?'a::type program); Acts ?F = Acts ?G; AllowedActs ?F = AllowedActs ?G⟧ ⟹ ?F = ?G›*) totalize_def (*‹totalize (?F::?'a::type program) ≡ mk_program (Init ?F, totalize_act ` Acts ?F, AllowedActs ?F)›*) Join_def (*‹(?F::?'a::type program) ⊔ (?G::?'a::type program) = mk_program (Init ?F ∩ Init ?G, Acts ?F ∪ Acts ?G, AllowedActs ?F ∩ AllowedActs ?G)›*) image_Un (*‹(?f::?'b::type ⇒ ?'a::type) ` ((?A::?'b::type set) ∪ (?B::?'b::type set)) = ?f ` ?A ∪ ?f ` ?B›*)) lemma all_total_Join: "[|all_total F; all_total G|] ==> all_total (F⊔G)" apply (simp add: all_total_def (*‹all_total ?F ≡ ∀act∈Acts ?F. Domain act = UNIV›*)) (*goal: ‹⟦all_total F; all_total G⟧ ⟹ all_total (F ⊔ G)›*) by blast lemma totalize_JN: "(⨆i ∈ I. totalize (F i)) = totalize(⨆i ∈ I. F i)" by (simp add: program_equalityI (*‹⟦Init ?F = Init ?G; Acts ?F = Acts ?G; AllowedActs ?F = AllowedActs ?G⟧ ⟹ ?F = ?G›*) totalize_def (*‹totalize ?F ≡ mk_program (Init ?F, totalize_act ` Acts ?F, AllowedActs ?F)›*) JOIN_def (*‹JOIN ?I ?F = mk_program (⋂i∈?I. Init (?F i), ⋃i∈?I. Acts (?F i), ⋂i∈?I. AllowedActs (?F i))›*) image_UN (*‹?f ` ⋃ (?B ` ?A) = (⋃x∈?A. ?f ` ?B x)›*)) lemma all_total_JN: "(!!i. i∈I ==> all_total (F i)) ==> all_total(⨆i∈I. F i)" by (simp add: all_total_iff_totalize (*‹all_total ?F = (totalize ?F = ?F)›*) totalize_JN [symmetric] (*‹totalize (JOIN ?I ?F) = (⨆i∈?I. totalize (?F i))›*)) end
{ "path": "Isabelle2024/src/HOL/UNITY/Union.thy", "repo": "Isabelle2024", "sha": "ffbad27aa953ca15a4cfcd0d622b9cf683d3afb216e7b3e20d047b89194c38b5" }
section ‹Filtermap for Lazy Lists› theory List_Filtermap imports Main begin text ‹ This theory defines the filtermap operator for lazy lists, proves its basic properties, and proves coinductive criteria for the equqlity of two filtermapped lazy lsits. › subsection ‹ Preliminaries › (* Hiding the "filtermap" constant, which is the mapping operator for filters. *) hide_const filtermap (* Preliminaries *) abbreviation never :: "('a ⇒ bool) ⇒ 'a list ⇒ bool" where "never U ≡ list_all (λ a. ¬ U a)" lemma never_list_ex: "never pred xs ⟷ ¬ list_ex pred xs" apply (induction xs) (*goals: 1. ‹never pred [] = (¬ list_ex pred [])› 2. ‹⋀a xs. never pred xs = (¬ list_ex pred xs) ⟹ never pred (a # xs) = (¬ list_ex pred (a # xs))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . (* Right-Cons: *) abbreviation Rcons (infix "##" 70) where "xs ## x ≡ xs @ [x]" lemma two_singl_Rcons: "[a,b] = [a] ## b" by auto lemma length_gt_1_Cons_snoc: assumes "length ys > 1" obtains x1 xs x2 where "ys = x1 # xs ## x2" using assms (*‹(1::nat) < length (ys::'a list)›*) proof (cases ys) (*goals: 1. ‹⟦⋀x1 xs x2. ys = x1 # xs ## x2 ⟹ thesis; 1 < length ys; ys = []⟧ ⟹ thesis› 2. ‹⋀a list. ⟦⋀x1 xs x2. ys = x1 # xs ## x2 ⟹ thesis; 1 < length ys; ys = a # list⟧ ⟹ thesis›*) case (Cons x1 xs) (*‹ys = x1 # xs›*) with assms (*‹(1::nat) < length (ys::'a::type list)›*) obtain xs' and x2 where "xs = xs' ## x2" (*goal: ‹(⋀xs' x2. xs = xs' ## x2 ⟹ thesis) ⟹ thesis›*) apply (cases xs rule: rev_cases (*‹⟦?xs = [] ⟹ ?P; ⋀ys y. ?xs = ys ## y ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹⟦⋀xs' x2. xs = xs' ## x2 ⟹ thesis; 1 < length ys; ys = x1 # xs; xs = []⟧ ⟹ thesis› 2. ‹⋀ysa y. ⟦⋀xs' x2. xs = xs' ## x2 ⟹ thesis; 1 < length ys; ys = x1 # xs; xs = ysa ## y⟧ ⟹ thesis› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . with Cons (*‹ys = x1 # xs›*) show thesis apply (intro that (*‹(ys::'a list) = (?x1.0::'a) # (?xs::'a list) ## (?x2.0::'a) ⟹ thesis::bool›*)) (*goal: ‹thesis›*) by auto qed (auto) (*solved the remaining goal: ‹⟦⋀x1 xs x2. ys = x1 # xs ## x2 ⟹ thesis; 1 < length ys; ys = []⟧ ⟹ thesis›*) lemma right_cons_left[simp]: "i < length as ⟹ (as ## a)!i = as!i" by (metis butlast_snoc (*‹butlast (?xs ## ?x) = ?xs›*) nth_butlast (*‹?n < length (butlast ?xs) ⟹ butlast ?xs ! ?n = ?xs ! ?n›*)) subsection ‹ Filtermap › definition filtermap :: "('b ⇒ bool) ⇒ ('b ⇒ 'a) ⇒ 'b list ⇒ 'a list" where "filtermap pred func xs ≡ map func (filter pred xs)" lemma filtermap_Nil[simp]: "filtermap pred func [] = []" unfolding filtermap_def (*goal: ‹map func (filter pred []) = []›*) by auto lemma filtermap_Cons_not[simp]: "¬ pred x ⟹ filtermap pred func (x # xs) = filtermap pred func xs" unfolding filtermap_def (*goal: ‹¬ (pred::'a::type ⇒ bool) (x::'a::type) ⟹ map (func::'a::type ⇒ 'b::type) (filter pred (x # (xs::'a::type list))) = map func (filter pred xs)›*) by auto lemma filtermap_Cons[simp]: "pred x ⟹ filtermap pred func (x # xs) = func x # filtermap pred func xs" unfolding filtermap_def (*goal: ‹pred x ⟹ map func (filter pred (x # xs)) = func x # map func (filter pred xs)›*) by auto lemma filtermap_append: "filtermap pred func (xs @ xs1) = filtermap pred func xs @ filtermap pred func xs1" proof (induction xs arbitrary: xs1) (*goals: 1. ‹⋀xs1. filtermap pred func ([] @ xs1) = filtermap pred func [] @ filtermap pred func xs1› 2. ‹⋀a xs xs1. (⋀xs1. filtermap pred func (xs @ xs1) = filtermap pred func xs @ filtermap pred func xs1) ⟹ filtermap pred func ((a # xs) @ xs1) = filtermap pred func (a # xs) @ filtermap pred func xs1›*) case (Cons x xs) (*‹filtermap pred func (xs @ ?xs1.0) = filtermap pred func xs @ filtermap pred func ?xs1.0›*) thus "?case" (*goal: ‹filtermap (pred::'b ⇒ bool) (func::'b ⇒ 'a) (((x::'b) # (xs::'b list)) @ (xs1::'b list)) = filtermap pred func (x # xs) @ filtermap pred func xs1›*) apply (cases "pred x") (*goals: 1. ‹⟦⋀xs1. filtermap pred func (xs @ xs1) = filtermap pred func xs @ filtermap pred func xs1; pred x⟧ ⟹ filtermap pred func ((x # xs) @ xs1) = filtermap pred func (x # xs) @ filtermap pred func xs1› 2. ‹⟦⋀xs1. filtermap pred func (xs @ xs1) = filtermap pred func xs @ filtermap pred func xs1; ¬ pred x⟧ ⟹ filtermap pred func ((x # xs) @ xs1) = filtermap pred func (x # xs) @ filtermap pred func xs1› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed (auto) (*solved the remaining goal: ‹⋀xs1. filtermap pred func ([] @ xs1) = filtermap pred func [] @ filtermap pred func xs1›*) lemma filtermap_Nil_list_ex: "filtermap pred func xs = [] ⟷ ¬ list_ex pred xs" proof (induction xs) (*goals: 1. ‹(filtermap pred func [] = []) = (¬ list_ex pred [])› 2. ‹⋀a xs. (filtermap pred func xs = []) = (¬ list_ex pred xs) ⟹ (filtermap pred func (a # xs) = []) = (¬ list_ex pred (a # xs))›*) case (Cons x xs) (*‹(filtermap pred func xs = []) = (¬ list_ex pred xs)›*) thus "?case" (*goal: ‹(filtermap pred func (x # xs) = []) = (¬ list_ex pred (x # xs))›*) apply (cases "pred x") (*goals: 1. ‹⟦(filtermap pred func xs = []) = (¬ list_ex pred xs); pred x⟧ ⟹ (filtermap pred func (x # xs) = []) = (¬ list_ex pred (x # xs))› 2. ‹⟦(filtermap pred func xs = []) = (¬ list_ex pred xs); ¬ pred x⟧ ⟹ (filtermap pred func (x # xs) = []) = (¬ list_ex pred (x # xs))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed (auto) (*solved the remaining goal: ‹(filtermap pred func [] = []) = (¬ list_ex pred [])›*) lemma filtermap_Nil_never: "filtermap pred func xs = [] ⟷ never pred xs" proof (induction xs) (*goals: 1. ‹(filtermap pred func [] = []) = never pred []› 2. ‹⋀a xs. (filtermap pred func xs = []) = never pred xs ⟹ (filtermap pred func (a # xs) = []) = never pred (a # xs)›*) case (Cons x xs) (*‹(filtermap pred func xs = []) = never pred xs›*) thus "?case" (*goal: ‹(filtermap pred func (x # xs) = []) = never pred (x # xs)›*) apply (cases "pred x") (*goals: 1. ‹⟦(filtermap pred func xs = []) = never pred xs; pred x⟧ ⟹ (filtermap pred func (x # xs) = []) = never pred (x # xs)› 2. ‹⟦(filtermap pred func xs = []) = never pred xs; ¬ pred x⟧ ⟹ (filtermap pred func (x # xs) = []) = never pred (x # xs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed (auto) (*solved the remaining goal: ‹(filtermap pred func [] = []) = never pred []›*) lemma length_filtermap: "length (filtermap pred func xs) ≤ length xs" proof (induction xs) (*goals: 1. ‹length (filtermap (pred::'b ⇒ bool) (func::'b ⇒ 'a) []) ≤ length []› 2. ‹⋀(a::'b) xs::'b list. length (filtermap (pred::'b ⇒ bool) (func::'b ⇒ 'a) xs) ≤ length xs ⟹ length (filtermap pred func (a # xs)) ≤ length (a # xs)›*) case (Cons x xs) (*‹length (filtermap (pred::'b ⇒ bool) (func::'b ⇒ 'a) (xs::'b list)) ≤ length xs›*) thus "?case" (*goal: ‹length (filtermap (pred::'b ⇒ bool) (func::'b ⇒ 'a) ((x::'b) # (xs::'b list))) ≤ length (x # xs)›*) apply (cases "pred x") (*goals: 1. ‹⟦length (filtermap pred func xs) ≤ length xs; pred x⟧ ⟹ length (filtermap pred func (x # xs)) ≤ length (x # xs)› 2. ‹⟦length (filtermap pred func xs) ≤ length xs; ¬ pred x⟧ ⟹ length (filtermap pred func (x # xs)) ≤ length (x # xs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed (auto) (*solved the remaining goal: ‹length (filtermap pred func []) ≤ length []›*) lemma filtermap_list_all[simp]: "filtermap pred func xs = map func xs ⟷ list_all pred xs" proof (induction xs) (*goals: 1. ‹(filtermap (pred::'b ⇒ bool) (func::'b ⇒ 'a) [] = map func []) = list_all pred []› 2. ‹⋀(a::'b) xs::'b list. (filtermap (pred::'b ⇒ bool) (func::'b ⇒ 'a) xs = map func xs) = list_all pred xs ⟹ (filtermap pred func (a # xs) = map func (a # xs)) = list_all pred (a # xs)›*) case (Cons x xs) (*‹(filtermap pred func xs = map func xs) = list_all pred xs›*) thus "?case" (*goal: ‹(filtermap pred func (x # xs) = map func (x # xs)) = list_all pred (x # xs)›*) apply (cases "pred x") (*goals: 1. ‹⟦(filtermap pred func xs = map func xs) = list_all pred xs; pred x⟧ ⟹ (filtermap pred func (x # xs) = map func (x # xs)) = list_all pred (x # xs)› 2. ‹⟦(filtermap pred func xs = map func xs) = list_all pred xs; ¬ pred x⟧ ⟹ (filtermap pred func (x # xs) = map func (x # xs)) = list_all pred (x # xs)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*goal: ‹⟦(filtermap pred func xs = map func xs) = list_all pred xs; ¬ pred x⟧ ⟹ (filtermap pred func (x # xs) = map func (x # xs)) = list_all pred (x # xs)›*) apply (metis impossible_Cons (*‹length ?xs ≤ length ?ys ⟹ (?xs = ?x # ?ys) = False›*) length_filtermap (*‹length (filtermap ?pred ?func ?xs) ≤ length ?xs›*) length_map (*‹length (map ?f ?xs) = length ?xs›*)) (*proven 2 subgoals*) . qed (auto) (*solved the remaining goal: ‹(filtermap pred func [] = map func []) = list_all pred []›*) lemma filtermap_eq_Cons: assumes "filtermap pred func xs = a # al1" shows "∃ x xs2 xs1. xs = xs2 @ [x] @ xs1 ∧ never pred xs2 ∧ pred x ∧ func x = a ∧ filtermap pred func xs1 = al1" using assms (*‹filtermap pred func xs = a # al1›*) proof (induction xs arbitrary: a al1) (*goals: 1. ‹⋀(a::'a) al1::'a list. filtermap (pred::'b ⇒ bool) (func::'b ⇒ 'a) [] = a # al1 ⟹ ∃(x::'b) (xs2::'b list) xs1::'b list. [] = xs2 @ [x] @ xs1 ∧ never pred xs2 ∧ pred x ∧ func x = a ∧ filtermap pred func xs1 = al1› 2. ‹⋀(a::'b) (xs::'b list) (aa::'a) al1::'a list. ⟦⋀(a::'a) al1::'a list. filtermap (pred::'b ⇒ bool) (func::'b ⇒ 'a) xs = a # al1 ⟹ ∃(x::'b) (xs2::'b list) xs1::'b list. xs = xs2 @ [x] @ xs1 ∧ never pred xs2 ∧ pred x ∧ func x = a ∧ filtermap pred func xs1 = al1; filtermap pred func (a # xs) = aa # al1⟧ ⟹ ∃(x::'b) (xs2::'b list) xs1::'b list. a # xs = xs2 @ [x] @ xs1 ∧ never pred xs2 ∧ pred x ∧ func x = aa ∧ filtermap pred func xs1 = al1›*) case (Cons x xs a al1) (*‹filtermap pred func xs = ?a # ?al1.0 ⟹ ∃x xs2 xs1. xs = xs2 @ [x] @ xs1 ∧ never pred xs2 ∧ pred x ∧ func x = ?a ∧ filtermap pred func xs1 = ?al1.0› ‹filtermap pred func (x # xs) = a # al1›*) show "?case" (*goal: ‹∃xa xs2 xs1. x # xs = xs2 @ [xa] @ xs1 ∧ never pred xs2 ∧ pred xa ∧ func xa = a ∧ filtermap pred func xs1 = al1›*) proof (cases "pred x") (*goals: 1. ‹pred x ⟹ ∃xa xs2 xs1. x # xs = xs2 @ [xa] @ xs1 ∧ never pred xs2 ∧ pred xa ∧ func xa = a ∧ filtermap pred func xs1 = al1› 2. ‹¬ pred x ⟹ ∃xa xs2 xs1. x # xs = xs2 @ [xa] @ xs1 ∧ never pred xs2 ∧ pred xa ∧ func xa = a ∧ filtermap pred func xs1 = al1›*) case False (*‹¬ pred x›*) hence "filtermap pred func xs = a # al1" using Cons (*‹filtermap pred func xs = ?a # ?al1.0 ⟹ ∃x xs2 xs1. xs = xs2 @ [x] @ xs1 ∧ never pred xs2 ∧ pred x ∧ func x = ?a ∧ filtermap pred func xs1 = ?al1.0› ‹filtermap pred func (x # xs) = a # al1›*) by simp from Cons(1)[OF this] (*‹∃x xs2 xs1. xs = xs2 @ [x] @ xs1 ∧ never pred xs2 ∧ pred x ∧ func x = a ∧ filtermap pred func xs1 = al1›*) obtain xn and xs2 and xs1 where 1: "xs = xs2 @ [xn] @ xs1 ∧ never pred xs2 ∧ pred xn ∧ func xn = a ∧ filtermap pred func xs1 = al1" (*goal: ‹(⋀xs2 xn xs1. xs = xs2 @ [xn] @ xs1 ∧ never pred xs2 ∧ pred xn ∧ func xn = a ∧ filtermap pred func xs1 = al1 ⟹ thesis) ⟹ thesis›*) by blast show "?thesis" (*goal: ‹∃xa xs2 xs1. x # xs = xs2 @ [xa] @ xs1 ∧ never pred xs2 ∧ pred xa ∧ func xa = a ∧ filtermap pred func xs1 = al1›*) apply (rule exI[of _ xn] (*‹?P xn ⟹ ∃x. ?P x›*), rule exI[of _ "x # xs2"] (*‹?P (x # xs2) ⟹ ∃x. ?P x›*), rule exI[of _ xs1] (*‹?P xs1 ⟹ ∃x. ?P x›*)) (*goal: ‹∃xa xs2 xs1. x # xs = xs2 @ [xa] @ xs1 ∧ never pred xs2 ∧ pred xa ∧ func xa = a ∧ filtermap pred func xs1 = al1›*) using Cons(2) (*‹filtermap pred func (x # xs) = a # al1›*) "1" (*‹xs = xs2 @ [xn] @ xs1 ∧ never pred xs2 ∧ pred xn ∧ func xn = a ∧ filtermap pred func xs1 = al1›*) False (*‹¬ pred x›*) by simp next (*goal: ‹(pred::'b::type ⇒ bool) (x::'b::type) ⟹ ∃(xa::'b::type) (xs2::'b::type list) xs1::'b::type list. x # (xs::'b::type list) = xs2 @ [xa] @ xs1 ∧ never pred xs2 ∧ pred xa ∧ (func::'b::type ⇒ 'a::type) xa = (a::'a::type) ∧ filtermap pred func xs1 = (al1::'a::type list)›*) case True (*‹pred x›*) hence "filtermap pred func xs = al1" using Cons (*‹filtermap pred func xs = ?a # ?al1.0 ⟹ ∃x xs2 xs1. xs = xs2 @ [x] @ xs1 ∧ never pred xs2 ∧ pred x ∧ func x = ?a ∧ filtermap pred func xs1 = ?al1.0› ‹filtermap pred func (x # xs) = a # al1›*) by simp show "?thesis" (*goal: ‹∃(xa::'b) (xs2::'b list) xs1::'b list. (x::'b) # (xs::'b list) = xs2 @ [xa] @ xs1 ∧ never (pred::'b ⇒ bool) xs2 ∧ pred xa ∧ (func::'b ⇒ 'a) xa = (a::'a) ∧ filtermap pred func xs1 = (al1::'a list)›*) apply (rule exI[of _ x] (*‹?P x ⟹ ∃x. ?P x›*), rule exI[of _ "[]"] (*‹?P [] ⟹ ∃x. ?P x›*), rule exI[of _ xs] (*‹?P xs ⟹ ∃x. ?P x›*)) (*goal: ‹∃xa xs2 xs1. x # xs = xs2 @ [xa] @ xs1 ∧ never pred xs2 ∧ pred xa ∧ func xa = a ∧ filtermap pred func xs1 = al1›*) using Cons(2) (*‹filtermap pred func (x # xs) = a # al1›*) True (*‹pred x›*) by simp qed qed (auto) (*solved the remaining goal: ‹⋀a al1. filtermap pred func [] = a # al1 ⟹ ∃x xs2 xs1. [] = xs2 @ [x] @ xs1 ∧ never pred xs2 ∧ pred x ∧ func x = a ∧ filtermap pred func xs1 = al1›*) lemma filtermap_eq_append: assumes "filtermap pred func xs = al1 @ al2" shows "∃ xs1 xs2. xs = xs1 @ xs2 ∧ filtermap pred func xs1 = al1 ∧ filtermap pred func xs2 = al2" using assms (*‹filtermap pred func xs = al1 @ al2›*) proof (induction al1 arbitrary: xs) (*goals: 1. ‹⋀xs::'b list. filtermap (pred::'b ⇒ bool) (func::'b ⇒ 'a) xs = [] @ (al2::'a list) ⟹ ∃(xs1::'b list) xs2::'b list. xs = xs1 @ xs2 ∧ filtermap pred func xs1 = [] ∧ filtermap pred func xs2 = al2› 2. ‹⋀(a::'a) (al1::'a list) xs::'b list. ⟦⋀xs::'b list. filtermap (pred::'b ⇒ bool) (func::'b ⇒ 'a) xs = al1 @ (al2::'a list) ⟹ ∃(xs1::'b list) xs2::'b list. xs = xs1 @ xs2 ∧ filtermap pred func xs1 = al1 ∧ filtermap pred func xs2 = al2; filtermap pred func xs = (a # al1) @ al2⟧ ⟹ ∃(xs1::'b list) xs2::'b list. xs = xs1 @ xs2 ∧ filtermap pred func xs1 = a # al1 ∧ filtermap pred func xs2 = al2›*) case Nil (*‹filtermap (pred::'b::type ⇒ bool) (func::'b::type ⇒ 'a::type) (xs::'b::type list) = [] @ (al2::'a::type list)›*) show "?case" (*goal: ‹∃xs1 xs2. xs = xs1 @ xs2 ∧ filtermap pred func xs1 = [] ∧ filtermap pred func xs2 = al2›*) apply (rule exI[of _ "[]"] (*‹?P [] ⟹ ∃x. ?P x›*), rule exI[of _ xs] (*‹?P xs ⟹ ∃x. ?P x›*)) (*goal: ‹∃xs1 xs2. xs = xs1 @ xs2 ∧ filtermap pred func xs1 = [] ∧ filtermap pred func xs2 = al2›*) using Nil (*‹filtermap pred func xs = [] @ al2›*) by auto next (*goal: ‹⋀(a::'a::type) (al1::'a::type list) xs::'b::type list. ⟦⋀xs::'b::type list. filtermap (pred::'b::type ⇒ bool) (func::'b::type ⇒ 'a::type) xs = al1 @ (al2::'a::type list) ⟹ ∃(xs1::'b::type list) xs2::'b::type list. xs = xs1 @ xs2 ∧ filtermap pred func xs1 = al1 ∧ filtermap pred func xs2 = al2; filtermap pred func xs = (a # al1) @ al2⟧ ⟹ ∃(xs1::'b::type list) xs2::'b::type list. xs = xs1 @ xs2 ∧ filtermap pred func xs1 = a # al1 ∧ filtermap pred func xs2 = al2›*) case (Cons a al1 xs) (*‹filtermap (pred::'b ⇒ bool) (func::'b ⇒ 'a) (?xs::'b list) = (al1::'a list) @ (al2::'a list) ⟹ ∃(xs1::'b list) xs2::'b list. ?xs = xs1 @ xs2 ∧ filtermap pred func xs1 = al1 ∧ filtermap pred func xs2 = al2› ‹filtermap pred func xs = (a # al1) @ al2›*) hence "filtermap pred func xs = a # (al1 @ al2)" by simp from filtermap_eq_Cons[OF this] (*‹∃(x::'b::type) (xs2::'b::type list) xs1::'b::type list. (xs::'b::type list) = xs2 @ [x] @ xs1 ∧ never (pred::'b::type ⇒ bool) xs2 ∧ pred x ∧ (func::'b::type ⇒ 'a::type) x = (a::'a::type) ∧ filtermap pred func xs1 = (al1::'a::type list) @ (al2::'a::type list)›*) obtain x and xs2 and xs1 where xs: "xs = xs2 @ [x] @ xs1" and n: "never pred xs2 ∧ pred x ∧ func x = a" and f: "filtermap pred func xs1 = al1 @ al2" (*goal: ‹(⋀xs2 x xs1. ⟦xs = xs2 @ [x] @ xs1; never pred xs2 ∧ pred x ∧ func x = a; filtermap pred func xs1 = al1 @ al2⟧ ⟹ thesis) ⟹ thesis›*) by blast from Cons(1)[OF f] (*‹∃xs1a xs2. xs1 = xs1a @ xs2 ∧ filtermap pred func xs1a = al1 ∧ filtermap pred func xs2 = al2›*) obtain xs11 and xs22 where xs1: "xs1 = xs11 @ xs22" and f1: "filtermap pred func xs11 = al1" and f2: "filtermap pred func xs22 = al2" (*goal: ‹(⋀(xs11::'b::type list) xs22::'b::type list. ⟦(xs1::'b::type list) = xs11 @ xs22; filtermap (pred::'b::type ⇒ bool) (func::'b::type ⇒ 'a::type) xs11 = (al1::'a::type list); filtermap pred func xs22 = (al2::'a::type list)⟧ ⟹ thesis::bool) ⟹ thesis›*) by blast show "?case" (*goal: ‹∃xs1 xs2. xs = xs1 @ xs2 ∧ filtermap pred func xs1 = a # al1 ∧ filtermap pred func xs2 = al2›*) apply (rule exI[of _ "xs2 @ [x] @ xs11"] (*‹?P (xs2 @ [x] @ xs11) ⟹ ∃x. ?P x›*), rule exI[of _ xs22] (*‹?P xs22 ⟹ ∃x. ?P x›*)) (*goal: ‹∃xs1 xs2. xs = xs1 @ xs2 ∧ filtermap pred func xs1 = a # al1 ∧ filtermap pred func xs2 = al2›*) using n (*‹never pred xs2 ∧ pred x ∧ func x = a›*) filtermap_Nil_never (*‹(filtermap (?pred::?'b ⇒ bool) (?func::?'b ⇒ ?'a) (?xs::?'b list) = []) = never ?pred ?xs›*) f1 (*‹filtermap pred func xs11 = al1›*) f2 (*‹filtermap pred func xs22 = al2›*) unfolding xs xs1 filtermap_append (*goal: ‹(xs2::'b list) @ [x::'b] @ (xs11::'b list) @ (xs22::'b list) = (xs2 @ [x] @ xs11) @ xs22 ∧ filtermap (pred::'b ⇒ bool) (func::'b ⇒ 'a) xs2 @ filtermap pred func [x] @ filtermap pred func xs11 = (a::'a) # (al1::'a list) ∧ filtermap pred func xs22 = (al2::'a list)›*) by auto qed lemma holds_filtermap_RCons[simp]: "pred x ⟹ filtermap pred func (xs ## x) = filtermap pred func xs ## func x" proof (induction xs) (*goals: 1. ‹pred x ⟹ filtermap pred func ([] ## x) = filtermap pred func [] ## func x› 2. ‹⋀a xs. ⟦pred x ⟹ filtermap pred func (xs ## x) = filtermap pred func xs ## func x; pred x⟧ ⟹ filtermap pred func ((a # xs) ## x) = filtermap pred func (a # xs) ## func x›*) case (Cons x xs) (*‹(pred::'a ⇒ bool) (x::'a) ⟹ filtermap pred (func::'a ⇒ 'b) ((xs::'a list) ## x) = filtermap pred func xs ## func x› ‹pred x›*) thus "?case" (*goal: ‹filtermap pred func ((x # xs) ## x) = filtermap pred func (x # xs) ## func x›*) apply (cases "pred x") (*goals: 1. ‹⟦pred x ⟹ filtermap pred func (xs ## x) = filtermap pred func xs ## func x; pred x; pred x⟧ ⟹ filtermap pred func ((x # xs) ## x) = filtermap pred func (x # xs) ## func x› 2. ‹⟦pred x ⟹ filtermap pred func (xs ## x) = filtermap pred func xs ## func x; pred x; ¬ pred x⟧ ⟹ filtermap pred func ((x # xs) ## x) = filtermap pred func (x # xs) ## func x› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed (auto) (*solved the remaining goal: ‹pred x ⟹ filtermap pred func ([] ## x) = filtermap pred func [] ## func x›*) lemma not_holds_filtermap_RCons[simp]: "¬ pred x ⟹ filtermap pred func (xs ## x) = filtermap pred func xs" proof (induction xs) (*goals: 1. ‹¬ pred x ⟹ filtermap pred func ([] ## x) = filtermap pred func []› 2. ‹⋀a xs. ⟦¬ pred x ⟹ filtermap pred func (xs ## x) = filtermap pred func xs; ¬ pred x⟧ ⟹ filtermap pred func ((a # xs) ## x) = filtermap pred func (a # xs)›*) case (Cons x xs) (*‹¬ pred x ⟹ filtermap pred func (xs ## x) = filtermap pred func xs› ‹¬ pred x›*) thus "?case" (*goal: ‹filtermap pred func ((x # xs) ## x) = filtermap pred func (x # xs)›*) apply (cases "pred x") (*goals: 1. ‹⟦¬ pred x ⟹ filtermap pred func (xs ## x) = filtermap pred func xs; ¬ pred x; pred x⟧ ⟹ filtermap pred func ((x # xs) ## x) = filtermap pred func (x # xs)› 2. ‹⟦¬ pred x ⟹ filtermap pred func (xs ## x) = filtermap pred func xs; ¬ pred x; ¬ pred x⟧ ⟹ filtermap pred func ((x # xs) ## x) = filtermap pred func (x # xs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed (auto) (*solved the remaining goal: ‹¬ pred x ⟹ filtermap pred func ([] ## x) = filtermap pred func []›*) lemma filtermap_eq_RCons: assumes "filtermap pred func xs = al1 ## a" shows "∃ x xs1 xs2. xs = xs1 @ [x] @ xs2 ∧ never pred xs2 ∧ pred x ∧ func x = a ∧ filtermap pred func xs1 = al1" using assms (*‹filtermap pred func xs = al1 ## a›*) proof (induction xs arbitrary: a al1 rule: rev_induct) (*goals: 1. ‹⋀a al1. filtermap pred func [] = al1 ## a ⟹ ∃x xs1 xs2. [] = xs1 @ [x] @ xs2 ∧ never pred xs2 ∧ pred x ∧ func x = a ∧ filtermap pred func xs1 = al1› 2. ‹⋀x xs a al1. ⟦⋀a al1. filtermap pred func xs = al1 ## a ⟹ ∃x xs1 xs2. xs = xs1 @ [x] @ xs2 ∧ never pred xs2 ∧ pred x ∧ func x = a ∧ filtermap pred func xs1 = al1; filtermap pred func (xs ## x) = al1 ## a⟧ ⟹ ∃xa xs1 xs2. xs ## x = xs1 @ [xa] @ xs2 ∧ never pred xs2 ∧ pred xa ∧ func xa = a ∧ filtermap pred func xs1 = al1›*) case (snoc x xs a al1) (*‹filtermap pred func xs = ?al1.0 ## ?a ⟹ ∃x xs1 xs2. xs = xs1 @ [x] @ xs2 ∧ never pred xs2 ∧ pred x ∧ func x = ?a ∧ filtermap pred func xs1 = ?al1.0› ‹filtermap pred func (xs ## x) = al1 ## a›*) show "?case" (*goal: ‹∃(xa::'b::type) (xs1::'b::type list) xs2::'b::type list. (xs::'b::type list) ## (x::'b::type) = xs1 @ [xa] @ xs2 ∧ never (pred::'b::type ⇒ bool) xs2 ∧ pred xa ∧ (func::'b::type ⇒ 'a::type) xa = (a::'a::type) ∧ filtermap pred func xs1 = (al1::'a::type list)›*) proof (cases "pred x") (*goals: 1. ‹pred x ⟹ ∃xa xs1 xs2. xs ## x = xs1 @ [xa] @ xs2 ∧ never pred xs2 ∧ pred xa ∧ func xa = a ∧ filtermap pred func xs1 = al1› 2. ‹¬ pred x ⟹ ∃xa xs1 xs2. xs ## x = xs1 @ [xa] @ xs2 ∧ never pred xs2 ∧ pred xa ∧ func xa = a ∧ filtermap pred func xs1 = al1›*) case False (*‹¬ pred x›*) hence "filtermap pred func xs = al1 ## a" using snoc (*‹filtermap (pred::'b::type ⇒ bool) (func::'b::type ⇒ 'a::type) (xs::'b::type list) = (?al1.0::'a::type list) ## (?a::'a::type) ⟹ ∃(x::'b::type) (xs1::'b::type list) xs2::'b::type list. xs = xs1 @ [x] @ xs2 ∧ never pred xs2 ∧ pred x ∧ func x = ?a ∧ filtermap pred func xs1 = ?al1.0› ‹filtermap pred func (xs ## x) = al1 ## a›*) by simp from snoc(1)[OF this] (*‹∃x xs1 xs2. xs = xs1 @ [x] @ xs2 ∧ never pred xs2 ∧ pred x ∧ func x = a ∧ filtermap pred func xs1 = al1›*) obtain xn and xs2 and xs1 where 1: "xs = xs1 @ [xn] @ xs2 ∧ never pred xs2 ∧ pred xn ∧ func xn = a ∧ filtermap pred func xs1 = al1" (*goal: ‹(⋀(xs1::'b list) (xn::'b) xs2::'b list. (xs::'b list) = xs1 @ [xn] @ xs2 ∧ never (pred::'b ⇒ bool) xs2 ∧ pred xn ∧ (func::'b ⇒ 'a) xn = (a::'a) ∧ filtermap pred func xs1 = (al1::'a list) ⟹ thesis::bool) ⟹ thesis›*) by blast show "?thesis" (*goal: ‹∃xa xs1 xs2. xs ## x = xs1 @ [xa] @ xs2 ∧ never pred xs2 ∧ pred xa ∧ func xa = a ∧ filtermap pred func xs1 = al1›*) apply (rule exI[of _ xn] (*‹?P xn ⟹ ∃x. ?P x›*), rule exI[of _ xs1] (*‹?P xs1 ⟹ ∃x. ?P x›*), rule exI[of _ "xs2 ## x"] (*‹?P (xs2 ## x) ⟹ ∃x. ?P x›*)) (*goal: ‹∃xa xs1 xs2. xs ## x = xs1 @ [xa] @ xs2 ∧ never pred xs2 ∧ pred xa ∧ func xa = a ∧ filtermap pred func xs1 = al1›*) using snoc(2) (*‹filtermap pred func (xs ## x) = al1 ## a›*) "1" (*‹xs = xs1 @ [xn] @ xs2 ∧ never pred xs2 ∧ pred xn ∧ func xn = a ∧ filtermap pred func xs1 = al1›*) False (*‹¬ (pred::'b ⇒ bool) (x::'b)›*) by simp next (*goal: ‹pred x ⟹ ∃xa xs1 xs2. xs ## x = xs1 @ [xa] @ xs2 ∧ never pred xs2 ∧ pred xa ∧ func xa = a ∧ filtermap pred func xs1 = al1›*) case True (*‹pred x›*) hence "filtermap pred func xs = al1" using snoc (*‹filtermap pred func xs = ?al1.0 ## ?a ⟹ ∃x xs1 xs2. xs = xs1 @ [x] @ xs2 ∧ never pred xs2 ∧ pred x ∧ func x = ?a ∧ filtermap pred func xs1 = ?al1.0› ‹filtermap pred func (xs ## x) = al1 ## a›*) by simp show "?thesis" (*goal: ‹∃xa xs1 xs2. xs ## x = xs1 @ [xa] @ xs2 ∧ never pred xs2 ∧ pred xa ∧ func xa = a ∧ filtermap pred func xs1 = al1›*) apply (rule exI[of _ x] (*‹?P x ⟹ ∃x. ?P x›*), rule exI[of _ xs] (*‹?P xs ⟹ ∃x. ?P x›*), rule exI[of _ "[]"] (*‹?P [] ⟹ ∃x. ?P x›*)) (*goal: ‹∃xa xs1 xs2. xs ## x = xs1 @ [xa] @ xs2 ∧ never pred xs2 ∧ pred xa ∧ func xa = a ∧ filtermap pred func xs1 = al1›*) using snoc(2) (*‹filtermap pred func (xs ## x) = al1 ## a›*) True (*‹pred x›*) by simp qed qed (auto) (*solved the remaining goal: ‹⋀(a::'a) al1::'a list. filtermap (pred::'b ⇒ bool) (func::'b ⇒ 'a) [] = al1 ## a ⟹ ∃(x::'b) (xs1::'b list) xs2::'b list. [] = xs1 @ [x] @ xs2 ∧ never pred xs2 ∧ pred x ∧ func x = a ∧ filtermap pred func xs1 = al1›*) lemma filtermap_eq_Cons_RCons: assumes "filtermap pred func xs = a # al1 ## b" shows "∃ xsa xa xs1 xb xsb. xs = xsa @ [xa] @ xs1 @ [xb] @ xsb ∧ never pred xsa ∧ pred xa ∧ func xa = a ∧ filtermap pred func xs1 = al1 ∧ pred xb ∧ func xb = b ∧ never pred xsb" proof (-) (*goal: ‹∃xsa xa xs1 xb xsb. xs = xsa @ [xa] @ xs1 @ [xb] @ xsb ∧ never pred xsa ∧ pred xa ∧ func xa = a ∧ filtermap pred func xs1 = al1 ∧ pred xb ∧ func xb = b ∧ never pred xsb›*) from filtermap_eq_Cons[OF assms] (*‹∃(x::'b) (xs2::'b list) xs1::'b list. (xs::'b list) = xs2 @ [x] @ xs1 ∧ never (pred::'b ⇒ bool) xs2 ∧ pred x ∧ (func::'b ⇒ 'a) x = (a::'a) ∧ filtermap pred func xs1 = (al1::'a list) ## (b::'a)›*) obtain xa and xsa and xs2 where 0: "xs = xsa @ [xa] @ xs2 ∧ never pred xsa ∧ pred xa ∧ func xa = a" and 1: "filtermap pred func xs2 = al1 ## b" (*goal: ‹(⋀xsa xa xs2. ⟦xs = xsa @ [xa] @ xs2 ∧ never pred xsa ∧ pred xa ∧ func xa = a; filtermap pred func xs2 = al1 ## b⟧ ⟹ thesis) ⟹ thesis›*) by auto from filtermap_eq_RCons[OF 1] (*‹∃x xs1 xs2a. xs2 = xs1 @ [x] @ xs2a ∧ never pred xs2a ∧ pred x ∧ func x = b ∧ filtermap pred func xs1 = al1›*) obtain xb and xs1 and xsb where 2: "xs2 = xs1 @ [xb] @ xsb ∧ never pred xsb ∧ pred xb ∧ func xb = b ∧ filtermap pred func xs1 = al1" (*goal: ‹(⋀xs1 xb xsb. xs2 = xs1 @ [xb] @ xsb ∧ never pred xsb ∧ pred xb ∧ func xb = b ∧ filtermap pred func xs1 = al1 ⟹ thesis) ⟹ thesis›*) by blast show "?thesis" (*goal: ‹∃xsa xa xs1 xb xsb. xs = xsa @ [xa] @ xs1 @ [xb] @ xsb ∧ never pred xsa ∧ pred xa ∧ func xa = a ∧ filtermap pred func xs1 = al1 ∧ pred xb ∧ func xb = b ∧ never pred xsb›*) apply (rule exI[of _ xsa] (*‹?P xsa ⟹ ∃x. ?P x›*), rule exI[of _ xa] (*‹(?P::'b::type ⇒ bool) (xa::'b::type) ⟹ ∃x::'b::type. ?P x›*), rule exI[of _ xs1] (*‹?P xs1 ⟹ ∃x. ?P x›*), rule exI[of _ xb] (*‹?P xb ⟹ ∃x. ?P x›*), rule exI[of _ xsb] (*‹?P xsb ⟹ ∃x. ?P x›*)) (*goal: ‹∃xsa xa xs1 xb xsb. xs = xsa @ [xa] @ xs1 @ [xb] @ xsb ∧ never pred xsa ∧ pred xa ∧ func xa = a ∧ filtermap pred func xs1 = al1 ∧ pred xb ∧ func xb = b ∧ never pred xsb›*) using "2" (*‹xs2 = xs1 @ [xb] @ xsb ∧ never pred xsb ∧ pred xb ∧ func xb = b ∧ filtermap pred func xs1 = al1›*) "0" (*‹xs = xsa @ [xa] @ xs2 ∧ never pred xsa ∧ pred xa ∧ func xa = a›*) by auto qed lemma filter_Nil_never: "[] = filter pred xs ⟹ never pred xs" apply (induction xs) (*goals: 1. ‹[] = filter pred [] ⟹ never pred []› 2. ‹⋀a xs. ⟦[] = filter pred xs ⟹ never pred xs; [] = filter pred (a # xs)⟧ ⟹ never pred (a # xs)› discuss goal 1*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 2 subgoals*) . lemma never_Nil_filter: "never pred xs ⟷ [] = filter pred xs" apply (induction xs) (*goals: 1. ‹never pred [] = ([] = filter pred [])› 2. ‹⋀a xs. never pred xs = ([] = filter pred xs) ⟹ never pred (a # xs) = ([] = filter pred (a # xs))› discuss goal 1*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 2 subgoals*) . lemma set_filtermap: "set (filtermap pred func xs) ⊆ {func x | x . x ∈ set xs ∧ pred x}" proof (induction xs) (*goals: 1. ‹set (filtermap pred func []) ⊆ {func x |x. x ∈ set [] ∧ pred x}› 2. ‹⋀a xs. set (filtermap pred func xs) ⊆ {func x |x. x ∈ set xs ∧ pred x} ⟹ set (filtermap pred func (a # xs)) ⊆ {func x |x. x ∈ set (a # xs) ∧ pred x}›*) case (Cons x xs) (*‹set (filtermap pred func xs) ⊆ {func x |x. x ∈ set xs ∧ pred x}›*) thus "?case" (*goal: ‹set (filtermap pred func (x # xs)) ⊆ {func xa |xa. xa ∈ set (x # xs) ∧ pred xa}›*) apply (cases "pred x") (*goals: 1. ‹⟦set (filtermap (pred::'b::type ⇒ bool) (func::'b::type ⇒ 'a::type) (xs::'b::type list)) ⊆ {func x |x::'b::type. x ∈ set xs ∧ pred x}; pred (x::'b::type)⟧ ⟹ set (filtermap pred func (x # xs)) ⊆ {func xa |xa::'b::type. xa ∈ set (x # xs) ∧ pred xa}› 2. ‹⟦set (filtermap (pred::'b::type ⇒ bool) (func::'b::type ⇒ 'a::type) (xs::'b::type list)) ⊆ {func x |x::'b::type. x ∈ set xs ∧ pred x}; ¬ pred (x::'b::type)⟧ ⟹ set (filtermap pred func (x # xs)) ⊆ {func xa |xa::'b::type. xa ∈ set (x # xs) ∧ pred xa}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed (auto) (*solved the remaining goal: ‹set (filtermap (pred::'b ⇒ bool) (func::'b ⇒ 'a) []) ⊆ {func x |x::'b. x ∈ set [] ∧ pred x}›*) end
{ "path": "afp-2025-02-12/thys/More_LazyLists/List_Filtermap.thy", "repo": "afp-2025-02-12", "sha": "abf0b4e751a37da5eb72ffe6da749003563ae66e6565b8f5361cf2062a833463" }
(* Copyright (C) 2007--2010 Norbert Schirmer * All rights reserved, DFKI GmbH *) (* header {* Parallel - IMP *} *) subsection ‹PIMP› theory PIMP imports ReduceStoreBufferSimulation begin datatype expr = Const val | Mem bool addr | Tmp sop | Unop "val ⇒ val" expr | Binop "val ⇒ val ⇒ val" expr expr (* Hmm. addr's should be vals ? *) datatype stmt = Skip | Assign bool expr expr "tmps ⇒ owns" "tmps ⇒ owns" "tmps ⇒ owns" "tmps ⇒ owns" | CAS expr expr expr "tmps ⇒ owns" "tmps ⇒ owns" "tmps ⇒ owns" "tmps ⇒ owns" | Seq "stmt" "stmt" | Cond expr "stmt" "stmt" | While expr "stmt" | SGhost "tmps ⇒ owns" "tmps ⇒ owns" "tmps ⇒ owns" "tmps ⇒ owns" | SFence (* FIXME: Genralisation of Assignment and CAS (and SGhost) would be nice: * A L R W sets not just dependent on value of addr, but on tmps (beware of domain: thm program_step_tmps_mono) or some ghost state *) primrec used_tmps:: "expr ⇒ nat" ― ‹number of temporaries used› where "used_tmps (Const v) = 0" | "used_tmps (Mem volatile addr) = 1" | "used_tmps (Tmp sop) = 0" | "used_tmps (Unop f e) = used_tmps e" | "used_tmps (Binop f e₁ e₂) = used_tmps e₁ + used_tmps e₂" primrec issue_expr:: "tmp ⇒ expr ⇒ instr list" ― ‹load operations› where "issue_expr t (Const v) = []" |"issue_expr t (Mem volatile a) = [Read volatile a t]" |"issue_expr t (Tmp sop) = []" |"issue_expr t (Unop f e) = issue_expr t e" |"issue_expr t (Binop f e₁ e₂) = issue_expr t e₁ @ issue_expr (t + (used_tmps e₁)) e₂" primrec eval_expr:: "tmp ⇒ expr ⇒ sop" ― ‹calculate result› where "eval_expr t (Const v) = ({},λθ. v)" |"eval_expr t (Mem volatile a) = ({t},λθ. the (θ t))" |"eval_expr t (Tmp sop) = sop" (* "eval_expr t (Tmp sop) = ({i. i ∈ fst sop ∧ i < t}, λθ. snd sop (θ |`{i. i ∈ fst sop ∧ i < t}))"*) ― ‹trick to enforce sop to be sensible in the current context, without having to include wellformedness constraints› |"eval_expr t (Unop f e) = (let (D,f⇩e) = eval_expr t e in (D,λθ. f (f⇩e θ))) " |"eval_expr t (Binop f e₁ e₂) = (let (D₁,f₁) = eval_expr t e₁; (D₂,f₂) = eval_expr (t + (used_tmps e₁)) e₂ in (D₁ ∪ D₂,λθ. f (f₁ θ) (f₂ θ)))" primrec valid_sops_expr:: "nat ⇒ expr ⇒ bool" where "valid_sops_expr t (Const v) = True" |"valid_sops_expr t (Mem volatile a) = True" |"valid_sops_expr t (Tmp sop) = ((∀t' ∈ fst sop. t' < t) ∧ valid_sop sop)" |"valid_sops_expr t (Unop f e) = valid_sops_expr t e" |"valid_sops_expr t (Binop f e₁ e₂) = (valid_sops_expr t e₁ ∧ valid_sops_expr t e₂)" primrec valid_sops_stmt:: "nat ⇒ stmt ⇒ bool" where "valid_sops_stmt t Skip = True" |"valid_sops_stmt t (Assign volatile a e A L R W) = (valid_sops_expr t a ∧ valid_sops_expr t e)" |"valid_sops_stmt t (CAS a c⇩e s⇩e A L R W) = (valid_sops_expr t a ∧ valid_sops_expr t c⇩e ∧ valid_sops_expr t s⇩e)" |"valid_sops_stmt t (Seq s₁ s₂) = (valid_sops_stmt t s₁ ∧ valid_sops_stmt t s₂)" |"valid_sops_stmt t (Cond e s₁ s₂) = (valid_sops_expr t e ∧ valid_sops_stmt t s₁ ∧ valid_sops_stmt t s₂)" |"valid_sops_stmt t (While e s) = (valid_sops_expr t e ∧ valid_sops_stmt t s)" |"valid_sops_stmt t (SGhost A L R W) = True" |"valid_sops_stmt t SFence = True" type_synonym stmt_config = "stmt × nat" consts isTrue:: "val ⇒ bool" inductive stmt_step:: "tmps ⇒ stmt_config ⇒ stmt_config × instrs ⇒ bool" ("_⊢ _ →⇩s _" [60,60,60] 100) for θ where AssignAddr: "∀sop. a ≠ Tmp sop ⟹ θ⊢ (Assign volatile a e A L R W, t) →⇩s ((Assign volatile (Tmp (eval_expr t a)) e A L R W, t + used_tmps a), issue_expr t a)" | Assign: "D ⊆ dom θ ⟹ θ⊢ (Assign volatile (Tmp (D,a)) e A L R W, t) →⇩s ((Skip, t + used_tmps e), issue_expr t e@[Write volatile (a θ) (eval_expr t e) (A θ) (L θ) (R θ) (W θ)])" | CASAddr: "∀sop. a ≠ Tmp sop ⟹ θ⊢ (CAS a c⇩e s⇩e A L R W, t) →⇩s ((CAS (Tmp (eval_expr t a)) c⇩e s⇩e A L R W, t + used_tmps a), issue_expr t a)" | CASComp: "∀sop. c⇩e ≠ Tmp sop ⟹ θ⊢ (CAS (Tmp (D⇩a,a)) c⇩e s⇩e A L R W, t) →⇩s ((CAS (Tmp (D⇩a,a)) (Tmp (eval_expr t c⇩e)) s⇩e A L R W, t + used_tmps c⇩e), issue_expr t c⇩e)" | CAS: "⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D,f) ⟧ ⟹ θ⊢ (CAS (Tmp (D⇩a,a)) (Tmp (D⇩c,c)) s⇩e A L R W, t) →⇩s ((Skip, Suc (t + used_tmps s⇩e)), issue_expr t s⇩e@ [RMW (a θ) (t + used_tmps s⇩e) (D,f) (λθ. the (θ (t + used_tmps s⇩e)) = c θ) (λv₁ v₂. v₁) (A θ) (L θ) (R θ) (W θ) ])" | Seq: "θ⊢ (s₁, t) →⇩s ((s₁', t'), is) ⟹ θ⊢ (Seq s₁ s₂, t) →⇩s ((Seq s₁' s₂, t'),is)" | SeqSkip: "θ⊢ (Seq Skip s₂, t) →⇩s ((s₂, t), [])" | Cond: "∀sop. e ≠ Tmp sop ⟹ θ⊢ (Cond e s₁ s₂, t) →⇩s ((Cond (Tmp (eval_expr t e)) s₁ s₂, t + used_tmps e), issue_expr t e)" | CondTrue: "⟦D ⊆ dom θ; isTrue (e θ)⟧ ⟹ θ⊢ (Cond (Tmp (D,e)) s₁ s₂, t) →⇩s ((s₁, t),[])" | CondFalse: "⟦D ⊆ dom θ; ¬ isTrue (e θ)⟧ ⟹ θ⊢ (Cond (Tmp (D,e)) s₁ s₂, t) →⇩s ((s₂, t),[])" | While: "θ⊢ (While e s, t) →⇩s ((Cond e (Seq s (While e s)) Skip, t),[])" | SGhost: "θ⊢ (SGhost A L R W, t) →⇩s ((Skip, t),[Ghost (A θ) (L θ) (R θ) (W θ)])" | SFence: "θ⊢ (SFence, t) →⇩s ((Skip, t),[Fence])" inductive_cases stmt_step_cases [cases set]: "θ⊢ (Skip, t) →⇩s c" "θ⊢ (Assign volatile a e A L R W, t) →⇩s c" "θ⊢ (CAS a c⇩e s⇩e A L R W, t) →⇩s c" "θ⊢ (Seq s₁ s₂, t) →⇩s c" "θ⊢ (Cond e s₁ s₂, t) →⇩s c" "θ⊢ (While e s, t) →⇩s c" "θ⊢ (SGhost A L R W, t) →⇩s c" "θ⊢ (SFence, t) →⇩s c" lemma valid_sops_expr_mono: "⋀t t'. valid_sops_expr t e ⟹ t ≤ t' ⟹ valid_sops_expr t' e" apply (induct e) (*goals: 1. ‹⋀(x::nat) (t::nat) t'::nat. ⟦valid_sops_expr t (Const x); t ≤ t'⟧ ⟹ valid_sops_expr t' (Const x)› 2. ‹⋀(x1a::bool) (x2::nat) (t::nat) t'::nat. ⟦valid_sops_expr t (Mem x1a x2); t ≤ t'⟧ ⟹ valid_sops_expr t' (Mem x1a x2)› 3. ‹⋀(x::nat set × ((nat ⇒ nat option) ⇒ nat)) (t::nat) t'::nat. ⟦valid_sops_expr t (Tmp x); t ≤ t'⟧ ⟹ valid_sops_expr t' (Tmp x)› 4. ‹⋀(x1a::nat ⇒ nat) (e::expr) (t::nat) t'::nat. ⟦⋀(t::nat) t'::nat. ⟦valid_sops_expr t e; t ≤ t'⟧ ⟹ valid_sops_expr t' e; valid_sops_expr t (Unop x1a e); t ≤ t'⟧ ⟹ valid_sops_expr t' (Unop x1a e)› 5. ‹⋀(x1a::nat ⇒ nat ⇒ nat) (e1::expr) (e2::expr) (t::nat) t'::nat. ⟦⋀(t::nat) t'::nat. ⟦valid_sops_expr t e1; t ≤ t'⟧ ⟹ valid_sops_expr t' e1; ⋀(t::nat) t'::nat. ⟦valid_sops_expr t e2; t ≤ t'⟧ ⟹ valid_sops_expr t' e2; valid_sops_expr t (Binop x1a e1 e2); t ≤ t'⟧ ⟹ valid_sops_expr t' (Binop x1a e1 e2)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . lemma valid_sops_stmt_mono: "⋀t t'. valid_sops_stmt t s ⟹ t ≤ t' ⟹ valid_sops_stmt t' s" apply (induct s) (*goals: 1. ‹⋀t t'. ⟦valid_sops_stmt t Skip; t ≤ t'⟧ ⟹ valid_sops_stmt t' Skip› 2. ‹⋀x1 x2 x3 x4 x5 x6 x7 t t'. ⟦valid_sops_stmt t (Assign x1 x2 x3 x4 x5 x6 x7); t ≤ t'⟧ ⟹ valid_sops_stmt t' (Assign x1 x2 x3 x4 x5 x6 x7)› 3. ‹⋀x1 x2 x3 x4 x5 x6 x7 t t'. ⟦valid_sops_stmt t (CAS x1 x2 x3 x4 x5 x6 x7); t ≤ t'⟧ ⟹ valid_sops_stmt t' (CAS x1 x2 x3 x4 x5 x6 x7)› 4. ‹⋀s1 s2 t t'. ⟦⋀t t'. ⟦valid_sops_stmt t s1; t ≤ t'⟧ ⟹ valid_sops_stmt t' s1; ⋀t t'. ⟦valid_sops_stmt t s2; t ≤ t'⟧ ⟹ valid_sops_stmt t' s2; valid_sops_stmt t (Seq s1 s2); t ≤ t'⟧ ⟹ valid_sops_stmt t' (Seq s1 s2)› 5. ‹⋀x1 s1 s2 t t'. ⟦⋀t t'. ⟦valid_sops_stmt t s1; t ≤ t'⟧ ⟹ valid_sops_stmt t' s1; ⋀t t'. ⟦valid_sops_stmt t s2; t ≤ t'⟧ ⟹ valid_sops_stmt t' s2; valid_sops_stmt t (Cond x1 s1 s2); t ≤ t'⟧ ⟹ valid_sops_stmt t' (Cond x1 s1 s2)› 6. ‹⋀x1 s t t'. ⟦⋀t t'. ⟦valid_sops_stmt t s; t ≤ t'⟧ ⟹ valid_sops_stmt t' s; valid_sops_stmt t (While x1 s); t ≤ t'⟧ ⟹ valid_sops_stmt t' (While x1 s)› 7. ‹⋀x1 x2 x3 x4 t t'. ⟦valid_sops_stmt t (SGhost x1 x2 x3 x4); t ≤ t'⟧ ⟹ valid_sops_stmt t' (SGhost x1 x2 x3 x4)› 8. ‹⋀t t'. ⟦valid_sops_stmt t SFence; t ≤ t'⟧ ⟹ valid_sops_stmt t' SFence› discuss goal 1*) apply ((auto intro: valid_sops_expr_mono (*‹⟦valid_sops_expr ?t ?e; ?t ≤ ?t'⟧ ⟹ valid_sops_expr ?t' ?e›*))[1]) (*discuss goal 2*) apply ((auto intro: valid_sops_expr_mono (*‹⟦valid_sops_expr ?t ?e; ?t ≤ ?t'⟧ ⟹ valid_sops_expr ?t' ?e›*))[1]) (*discuss goal 3*) apply ((auto intro: valid_sops_expr_mono (*‹⟦valid_sops_expr (?t::nat) (?e::expr); ?t ≤ (?t'::nat)⟧ ⟹ valid_sops_expr ?t' ?e›*))[1]) (*discuss goal 4*) apply ((auto intro: valid_sops_expr_mono (*‹⟦valid_sops_expr ?t ?e; ?t ≤ ?t'⟧ ⟹ valid_sops_expr ?t' ?e›*))[1]) (*discuss goal 5*) apply ((auto intro: valid_sops_expr_mono (*‹⟦valid_sops_expr ?t ?e; ?t ≤ ?t'⟧ ⟹ valid_sops_expr ?t' ?e›*))[1]) (*discuss goal 6*) apply ((auto intro: valid_sops_expr_mono (*‹⟦valid_sops_expr ?t ?e; ?t ≤ ?t'⟧ ⟹ valid_sops_expr ?t' ?e›*))[1]) (*discuss goal 7*) apply ((auto intro: valid_sops_expr_mono (*‹⟦valid_sops_expr ?t ?e; ?t ≤ ?t'⟧ ⟹ valid_sops_expr ?t' ?e›*))[1]) (*discuss goal 8*) apply ((auto intro: valid_sops_expr_mono (*‹⟦valid_sops_expr ?t ?e; ?t ≤ ?t'⟧ ⟹ valid_sops_expr ?t' ?e›*))[1]) (*proven 8 subgoals*) . lemma valid_sops_expr_valid_sop: "⋀t. valid_sops_expr t e ⟹ valid_sop (eval_expr t e)" proof (induct e) (*goals: 1. ‹⋀x t. valid_sops_expr t (Const x) ⟹ valid_sop (eval_expr t (Const x))› 2. ‹⋀x1a x2 t. valid_sops_expr t (Mem x1a x2) ⟹ valid_sop (eval_expr t (Mem x1a x2))› 3. ‹⋀x t. valid_sops_expr t (Tmp x) ⟹ valid_sop (eval_expr t (Tmp x))› 4. ‹⋀x1a e t. ⟦⋀t. valid_sops_expr t e ⟹ valid_sop (eval_expr t e); valid_sops_expr t (Unop x1a e)⟧ ⟹ valid_sop (eval_expr t (Unop x1a e))› 5. ‹⋀x1a e1 e2 t. ⟦⋀t. valid_sops_expr t e1 ⟹ valid_sop (eval_expr t e1); ⋀t. valid_sops_expr t e2 ⟹ valid_sop (eval_expr t e2); valid_sops_expr t (Binop x1a e1 e2)⟧ ⟹ valid_sop (eval_expr t (Binop x1a e1 e2))›*) case (Unop f e) (*‹valid_sops_expr ?t e ⟹ valid_sop (eval_expr ?t e)› ‹valid_sops_expr (t::nat) (Unop (f::nat ⇒ nat) (e::expr))›*) then obtain "valid_sops_expr t e" (*goal: ‹(valid_sops_expr t e ⟹ thesis) ⟹ thesis›*) by simp from Unop.hyps[OF this] (*‹valid_sop (eval_expr t e)›*) have vs: "valid_sop (eval_expr t e)" by simp obtain D and g where eval_e: "eval_expr t e = (D,g)" (*goal: ‹(⋀(D::nat set) g::(nat ⇒ nat option) ⇒ nat. eval_expr (t::nat) (e::expr) = (D, g) ⟹ thesis::bool) ⟹ thesis›*) by (cases "eval_expr t e") interpret valid_sop "(D,g)" using vs (*‹valid_sop (eval_expr (t::nat) (e::expr))›*) eval_e (*‹eval_expr t e = (D, g)›*) by simp show "?case" (*goal: ‹valid_sop (eval_expr t (Unop f e))›*) apply (clarsimp simp add: Let_def (*‹Let ?s ?f ≡ ?f ?s›*) valid_sop_def (*‹valid_sop ?sop ≡ ∀D f θ. ?sop = (D, f) ⟶ D ⊆ dom θ ⟶ f θ = f (θ |` D)›*) eval_e (*‹eval_expr t e = (D, g)›*)) (*goal: ‹valid_sop (eval_expr t (Unop f e))›*) apply (drule valid_sop [OF refl] (*‹D ⊆ dom ?θ ⟹ g ?θ = g (?θ |` D)›*)) (*goal: ‹⋀θ. D ⊆ dom θ ⟹ f (g θ) = f (g (θ |` D))›*) by simp next (*goals: 1. ‹⋀x t. valid_sops_expr t (Const x) ⟹ valid_sop (eval_expr t (Const x))› 2. ‹⋀x1a x2 t. valid_sops_expr t (Mem x1a x2) ⟹ valid_sop (eval_expr t (Mem x1a x2))› 3. ‹⋀x t. valid_sops_expr t (Tmp x) ⟹ valid_sop (eval_expr t (Tmp x))› 4. ‹⋀x1a e1 e2 t. ⟦⋀t. valid_sops_expr t e1 ⟹ valid_sop (eval_expr t e1); ⋀t. valid_sops_expr t e2 ⟹ valid_sop (eval_expr t e2); valid_sops_expr t (Binop x1a e1 e2)⟧ ⟹ valid_sop (eval_expr t (Binop x1a e1 e2))›*) case (Binop f e₁ e₂) (*‹valid_sops_expr (?t::nat) (e₁::expr) ⟹ valid_sop (eval_expr ?t e₁)› ‹valid_sops_expr ?t e₂ ⟹ valid_sop (eval_expr ?t e₂)› ‹valid_sops_expr t (Binop f e₁ e₂)›*) then obtain v1: "valid_sops_expr t e₁" and v2: "valid_sops_expr t e₂" (*goal: ‹(⟦valid_sops_expr t e₁; valid_sops_expr t e₂⟧ ⟹ thesis) ⟹ thesis›*) by simp with Binop.hyps(1)[of t] (*‹valid_sops_expr t e₁ ⟹ valid_sop (eval_expr t e₁)›*) Binop.hyps(2)[of "(t + used_tmps e₁)"] (*‹valid_sops_expr (t + used_tmps e₁) e₂ ⟹ valid_sop (eval_expr (t + used_tmps e₁) e₂)›*) valid_sops_expr_mono[OF v2, of "(t + used_tmps e₁)"] (*‹t ≤ t + used_tmps e₁ ⟹ valid_sops_expr (t + used_tmps e₁) e₂›*) obtain vs1: "valid_sop (eval_expr t e₁)" and vs2: "valid_sop (eval_expr (t + used_tmps e₁) e₂)" (*goal: ‹(⟦valid_sop (eval_expr t e₁); valid_sop (eval_expr (t + used_tmps e₁) e₂)⟧ ⟹ thesis) ⟹ thesis›*) by auto obtain D₁ and g₁ where "eval_e₁": "eval_expr t e₁ = (D₁,g₁)" (*goal: ‹(⋀(D₁::nat set) g₁::(nat ⇒ nat option) ⇒ nat. eval_expr (t::nat) (e₁::expr) = (D₁, g₁) ⟹ thesis::bool) ⟹ thesis›*) by (cases "eval_expr t e₁") obtain D₂ and g₂ where "eval_e₂": "eval_expr (t + used_tmps e₁) e₂ = (D₂,g₂)" (*goal: ‹(⋀(D₂::nat set) g₂::(nat ⇒ nat option) ⇒ nat. eval_expr ((t::nat) + used_tmps (e₁::expr)) (e₂::expr) = (D₂, g₂) ⟹ thesis::bool) ⟹ thesis›*) by (cases "eval_expr (t + used_tmps e₁) e₂") interpret vs1: valid_sop "(D₁,g₁)" using vs1 (*‹valid_sop (eval_expr t e₁)›*) "eval_e₁" (*‹eval_expr t e₁ = (D₁, g₁)›*) by auto interpret vs2: valid_sop "(D₂,g₂)" using vs2 (*‹valid_sop (eval_expr (t + used_tmps e₁) e₂)›*) "eval_e₂" (*‹eval_expr (t + used_tmps e₁) e₂ = (D₂, g₂)›*) by auto { fix θ :: "nat⇒val option" assume D1: "D₁ ⊆ dom θ" (*‹(D₁::nat set) ⊆ dom (θ::nat ⇒ nat option)›*) assume D2: "D₂ ⊆ dom θ" (*‹(D₂::nat set) ⊆ dom (θ::nat ⇒ nat option)›*) have "f (g₁ θ) (g₂ θ) = f (g₁ (θ |` (D₁ ∪ D₂))) (g₂ (θ |` (D₁ ∪ D₂)))" proof (-) (*goal: ‹f (g₁ θ) (g₂ θ) = f (g₁ (θ |` (D₁ ∪ D₂))) (g₂ (θ |` (D₁ ∪ D₂)))›*) from vs1.valid_sop[OF refl D1] (*‹g₁ θ = g₁ (θ |` D₁)›*) have "g₁ θ = g₁ (θ |` D₁)" . also (*calculation: ‹g₁ θ = g₁ (θ |` D₁)›*) from D1 (*‹(D₁::nat set) ⊆ dom (θ::nat ⇒ nat option)›*) have D1': "D₁ ⊆ dom (θ |` (D₁ ∪ D₂))" by auto have "θ |` (D₁ ∪ D₂) |` D₁ = θ |` D₁" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹θ |` (D₁ ∪ D₂) |` D₁ = θ |` D₁›*) by (auto simp add: restrict_map_def (*‹?m |` ?A = (λx. if x ∈ ?A then ?m x else None)›*)) with vs1.valid_sop[OF refl D1'] (*‹(g₁::(nat ⇒ nat option) ⇒ nat) ((θ::nat ⇒ nat option) |` ((D₁::nat set) ∪ (D₂::nat set))) = g₁ (θ |` (D₁ ∪ D₂) |` D₁)›*) have "g₁ (θ |` D₁) = g₁ (θ |` (D₁ ∪ D₂))" by auto finally (*calculation: ‹g₁ θ = g₁ (θ |` (D₁ ∪ D₂))›*) have g1: "g₁ (θ |` (D₁ ∪ D₂)) = g₁ θ" by simp from vs2.valid_sop[OF refl D2] (*‹g₂ θ = g₂ (θ |` D₂)›*) have "g₂ θ = g₂ (θ |` D₂)" . also (*calculation: ‹(g₂::(nat ⇒ nat option) ⇒ nat) (θ::nat ⇒ nat option) = g₂ (θ |` (D₂::nat set))›*) from D2 (*‹D₂ ⊆ dom θ›*) have D2': "D₂ ⊆ dom (θ |` (D₁ ∪ D₂))" by auto have "θ |` (D₁ ∪ D₂) |` D₂ = θ |` D₂" apply (rule ext (*‹(⋀x::?'a::type. (?f::?'a::type ⇒ ?'b::type) x = (?g::?'a::type ⇒ ?'b::type) x) ⟹ ?f = ?g›*)) (*goal: ‹θ |` (D₁ ∪ D₂) |` D₂ = θ |` D₂›*) by (auto simp add: restrict_map_def (*‹?m |` ?A = (λx. if x ∈ ?A then ?m x else None)›*)) with vs2.valid_sop[OF refl D2'] (*‹g₂ (θ |` (D₁ ∪ D₂)) = g₂ (θ |` (D₁ ∪ D₂) |` D₂)›*) have "g₂ (θ |` D₂) = g₂ (θ |` (D₁ ∪ D₂))" by auto finally (*calculation: ‹g₂ θ = g₂ (θ |` (D₁ ∪ D₂))›*) have g2: "g₂ (θ |` (D₁ ∪ D₂)) = g₂ θ" by simp from g1 (*‹g₁ (θ |` (D₁ ∪ D₂)) = g₁ θ›*) g2 (*‹g₂ (θ |` (D₁ ∪ D₂)) = g₂ θ›*) show "?thesis" (*goal: ‹(f::nat ⇒ nat ⇒ nat) ((g₁::(nat ⇒ nat option) ⇒ nat) (θ::nat ⇒ nat option)) ((g₂::(nat ⇒ nat option) ⇒ nat) θ) = f (g₁ (θ |` ((D₁::nat set) ∪ (D₂::nat set)))) (g₂ (θ |` (D₁ ∪ D₂)))›*) by simp qed } note lem = this (*‹⟦(D₁::nat set) ⊆ dom (?θ2::nat ⇒ nat option); (D₂::nat set) ⊆ dom ?θ2⟧ ⟹ (f::nat ⇒ nat ⇒ nat) ((g₁::(nat ⇒ nat option) ⇒ nat) ?θ2) ((g₂::(nat ⇒ nat option) ⇒ nat) ?θ2) = f (g₁ (?θ2 |` (D₁ ∪ D₂))) (g₂ (?θ2 |` (D₁ ∪ D₂)))›*) show "?case" (*goal: ‹valid_sop (eval_expr t (Binop f e₁ e₂))›*) apply (clarsimp simp add: Let_def (*‹Let ?s ?f ≡ ?f ?s›*) valid_sop_def (*‹valid_sop ?sop ≡ ∀D f θ. ?sop = (D, f) ⟶ D ⊆ dom θ ⟶ f θ = f (θ |` D)›*) eval_e₁ (*‹eval_expr t e₁ = (D₁, g₁)›*) eval_e₂ (*‹eval_expr (t + used_tmps e₁) e₂ = (D₂, g₂)›*)) (*goal: ‹valid_sop (eval_expr (t::nat) (Binop (f::nat ⇒ nat ⇒ nat) (e₁::expr) (e₂::expr)))›*) apply (rule lem (*‹⟦D₁ ⊆ dom ?θ2; D₂ ⊆ dom ?θ2⟧ ⟹ f (g₁ ?θ2) (g₂ ?θ2) = f (g₁ (?θ2 |` (D₁ ∪ D₂))) (g₂ (?θ2 |` (D₁ ∪ D₂)))›*)) (*goals: 1. ‹⋀θ::nat ⇒ nat option. ⟦(D₁::nat set) ⊆ dom θ; (D₂::nat set) ⊆ dom θ⟧ ⟹ D₁ ⊆ dom θ› 2. ‹⋀θ::nat ⇒ nat option. ⟦(D₁::nat set) ⊆ dom θ; (D₂::nat set) ⊆ dom θ⟧ ⟹ D₂ ⊆ dom θ› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed (auto simp add: valid_sop_def (*‹valid_sop ?sop ≡ ∀D f θ. ?sop = (D, f) ⟶ D ⊆ dom θ ⟶ f θ = f (θ |` D)›*)) (*solves the remaining goals: 1. ‹⋀x t. valid_sops_expr t (Const x) ⟹ valid_sop (eval_expr t (Const x))› 2. ‹⋀x1a x2 t. valid_sops_expr t (Mem x1a x2) ⟹ valid_sop (eval_expr t (Mem x1a x2))› 3. ‹⋀x t. valid_sops_expr t (Tmp x) ⟹ valid_sop (eval_expr t (Tmp x))›*) lemma valid_sops_expr_eval_expr_in_range: "⋀t. valid_sops_expr t e ⟹ ∀t' ∈ fst (eval_expr t e). t' < t + used_tmps e" proof (induct e) (*goals: 1. ‹⋀x t. valid_sops_expr t (Const x) ⟹ ∀t'∈fst (eval_expr t (Const x)). t' < t + used_tmps (Const x)› 2. ‹⋀x1a x2 t. valid_sops_expr t (Mem x1a x2) ⟹ ∀t'∈fst (eval_expr t (Mem x1a x2)). t' < t + used_tmps (Mem x1a x2)› 3. ‹⋀x t. valid_sops_expr t (Tmp x) ⟹ ∀t'∈fst (eval_expr t (Tmp x)). t' < t + used_tmps (Tmp x)› 4. ‹⋀x1a e t. ⟦⋀t. valid_sops_expr t e ⟹ ∀t'∈fst (eval_expr t e). t' < t + used_tmps e; valid_sops_expr t (Unop x1a e)⟧ ⟹ ∀t'∈fst (eval_expr t (Unop x1a e)). t' < t + used_tmps (Unop x1a e)› 5. ‹⋀x1a e1 e2 t. ⟦⋀t. valid_sops_expr t e1 ⟹ ∀t'∈fst (eval_expr t e1). t' < t + used_tmps e1; ⋀t. valid_sops_expr t e2 ⟹ ∀t'∈fst (eval_expr t e2). t' < t + used_tmps e2; valid_sops_expr t (Binop x1a e1 e2)⟧ ⟹ ∀t'∈fst (eval_expr t (Binop x1a e1 e2)). t' < t + used_tmps (Binop x1a e1 e2)›*) case (Unop f e) (*‹valid_sops_expr ?t e ⟹ ∀t'∈fst (eval_expr ?t e). t' < ?t + used_tmps e› ‹valid_sops_expr t (Unop f e)›*) thus "?case" (*goal: ‹∀t'∈fst (eval_expr t (Unop f e)). t' < t + used_tmps (Unop f e)›*) apply (cases "eval_expr t e") (*goal: ‹∀t'∈fst (eval_expr t (Unop f e)). t' < t + used_tmps (Unop f e)›*) by auto next (*goals: 1. ‹⋀x t. valid_sops_expr t (Const x) ⟹ ∀t'∈fst (eval_expr t (Const x)). t' < t + used_tmps (Const x)› 2. ‹⋀x1a x2 t. valid_sops_expr t (Mem x1a x2) ⟹ ∀t'∈fst (eval_expr t (Mem x1a x2)). t' < t + used_tmps (Mem x1a x2)› 3. ‹⋀x t. valid_sops_expr t (Tmp x) ⟹ ∀t'∈fst (eval_expr t (Tmp x)). t' < t + used_tmps (Tmp x)› 4. ‹⋀x1a e1 e2 t. ⟦⋀t. valid_sops_expr t e1 ⟹ ∀t'∈fst (eval_expr t e1). t' < t + used_tmps e1; ⋀t. valid_sops_expr t e2 ⟹ ∀t'∈fst (eval_expr t e2). t' < t + used_tmps e2; valid_sops_expr t (Binop x1a e1 e2)⟧ ⟹ ∀t'∈fst (eval_expr t (Binop x1a e1 e2)). t' < t + used_tmps (Binop x1a e1 e2)›*) case (Binop f e₁ e₂) (*‹valid_sops_expr ?t e₁ ⟹ ∀t'∈fst (eval_expr ?t e₁). t' < ?t + used_tmps e₁› ‹valid_sops_expr ?t e₂ ⟹ ∀t'∈fst (eval_expr ?t e₂). t' < ?t + used_tmps e₂› ‹valid_sops_expr t (Binop f e₁ e₂)›*) then obtain v1: "valid_sops_expr t e₁" and v2: "valid_sops_expr t e₂" (*goal: ‹(⟦valid_sops_expr t e₁; valid_sops_expr t e₂⟧ ⟹ thesis) ⟹ thesis›*) by simp from valid_sops_expr_mono[OF v2] (*‹t ≤ ?t' ⟹ valid_sops_expr ?t' e₂›*) have v2': "valid_sops_expr (t + used_tmps e₁) e₂" by auto from Binop.hyps(1)[OF v1] (*‹∀t'∈fst (eval_expr t e₁). t' < t + used_tmps e₁›*) Binop.hyps(2)[OF v2'] (*‹∀t'∈fst (eval_expr (t + used_tmps e₁) e₂). t' < t + used_tmps e₁ + used_tmps e₂›*) show "?case" (*goal: ‹∀t'∈fst (eval_expr t (Binop f e₁ e₂)). t' < t + used_tmps (Binop f e₁ e₂)›*) apply (cases "eval_expr t e₁") (*goal: ‹∀t'∈fst (eval_expr t (Binop f e₁ e₂)). t' < t + used_tmps (Binop f e₁ e₂)›*) apply (cases "eval_expr (t + used_tmps e₁) e₂") (*goal: ‹⋀a b. ⟦∀t'∈fst (eval_expr t e₁). t' < t + used_tmps e₁; ∀t'∈fst (eval_expr (t + used_tmps e₁) e₂). t' < t + used_tmps e₁ + used_tmps e₂; eval_expr t e₁ = (a, b)⟧ ⟹ ∀t'∈fst (eval_expr t (Binop f e₁ e₂)). t' < t + used_tmps (Binop f e₁ e₂)›*) by auto qed (auto) (*solves the remaining goals: 1. ‹⋀x t. valid_sops_expr t (Const x) ⟹ ∀t'∈fst (eval_expr t (Const x)). t' < t + used_tmps (Const x)› 2. ‹⋀x1a x2 t. valid_sops_expr t (Mem x1a x2) ⟹ ∀t'∈fst (eval_expr t (Mem x1a x2)). t' < t + used_tmps (Mem x1a x2)› 3. ‹⋀x t. valid_sops_expr t (Tmp x) ⟹ ∀t'∈fst (eval_expr t (Tmp x)). t' < t + used_tmps (Tmp x)›*) lemma stmt_step_tmps_count_mono: assumes step: "θ⊢ (s,t) →⇩s ((s',t'),is)" shows "t ≤ t'" using step (*‹θ⊢ (s, t) →⇩s ((s', t'), is)›*) apply (induct x=="(s,t)" y=="((s',t'),is)" arbitrary: s t s' t' "is" rule: stmt_step.induct) (*goals: 1. ‹⋀a volatile e A L R W t. ∀sop. a ≠ Tmp sop ⟹ t ≤ t + used_tmps a› 2. ‹⋀D volatile a e A L R W t. D ⊆ dom θ ⟹ t ≤ t + used_tmps e› 3. ‹⋀a c⇩e s⇩e A L R W t. ∀sop. a ≠ Tmp sop ⟹ t ≤ t + used_tmps a› 4. ‹⋀c⇩e D⇩a a s⇩e A L R W t. ∀sop. c⇩e ≠ Tmp sop ⟹ t ≤ t + used_tmps c⇩e› 5. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f)⟧ ⟹ t ≤ Suc (t + used_tmps s⇩e)› 6. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); t ≤ t'⟧ ⟹ t ≤ t'› 7. ‹⋀s₂ t. t ≤ t› 8. ‹⋀e s₁ s₂ t. ∀sop. e ≠ Tmp sop ⟹ t ≤ t + used_tmps e› 9. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ)⟧ ⟹ t ≤ t› 10. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ)⟧ ⟹ t ≤ t› 11. ‹⋀e s t. t ≤ t› 12. ‹⋀A L R W t. t ≤ t› 13. ‹⋀t. t ≤ t› discuss goal 1*) apply force (*discuss goal 2*) apply force (*discuss goal 3*) apply force (*discuss goal 4*) apply force (*discuss goal 5*) apply force (*discuss goal 6*) apply force (*discuss goal 7*) apply force (*discuss goal 8*) apply force (*discuss goal 9*) apply force (*discuss goal 10*) apply force (*discuss goal 11*) apply force (*discuss goal 12*) apply force (*discuss goal 13*) apply force (*proven 13 subgoals*) . lemma valid_sops_stmt_invariant: assumes step: "θ⊢ (s,t) →⇩s ((s',t'),is)" shows "valid_sops_stmt t s ⟹ valid_sops_stmt t' s'" using step (*‹θ⊢ (s, t) →⇩s ((s', t'), is)›*) proof (induct x=="(s,t)" y=="((s',t'),is)" arbitrary: s t s' t' "is" rule: stmt_step.induct) (*goals: 1. ‹⋀a volatile e A L R W t. ⟦∀sop. a ≠ Tmp sop; valid_sops_stmt t (Assign volatile a e A L R W)⟧ ⟹ valid_sops_stmt (t + used_tmps a) (Assign volatile (Tmp (eval_expr t a)) e A L R W)› 2. ‹⋀D volatile a e A L R W t. ⟦D ⊆ dom θ; valid_sops_stmt t (Assign volatile (Tmp (D, a)) e A L R W)⟧ ⟹ valid_sops_stmt (t + used_tmps e) Skip› 3. ‹⋀a c⇩e s⇩e A L R W t. ⟦∀sop. a ≠ Tmp sop; valid_sops_stmt t (CAS a c⇩e s⇩e A L R W)⟧ ⟹ valid_sops_stmt (t + used_tmps a) (CAS (Tmp (eval_expr t a)) c⇩e s⇩e A L R W)› 4. ‹⋀c⇩e D⇩a a s⇩e A L R W t. ⟦∀sop. c⇩e ≠ Tmp sop; valid_sops_stmt t (CAS (Tmp (D⇩a, a)) c⇩e s⇩e A L R W)⟧ ⟹ valid_sops_stmt (t + used_tmps c⇩e) (CAS (Tmp (D⇩a, a)) (Tmp (eval_expr t c⇩e)) s⇩e A L R W)› 5. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f); valid_sops_stmt t (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W)⟧ ⟹ valid_sops_stmt (Suc (t + used_tmps s⇩e)) Skip› 6. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ valid_sops_stmt t' s₁'; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ valid_sops_stmt t' (Seq s₁' s₂)› 7. ‹⋀s₂ t. valid_sops_stmt t (Seq Skip s₂) ⟹ valid_sops_stmt t s₂› 8. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ valid_sops_stmt (t + used_tmps e) (Cond (Tmp (eval_expr t e)) s₁ s₂)› 9. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ valid_sops_stmt t s₁› 10. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ valid_sops_stmt t s₂› 11. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ valid_sops_stmt t (Cond e (Seq s (While e s)) Skip)› 12. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ valid_sops_stmt t Skip› 13. ‹⋀t. valid_sops_stmt t SFence ⟹ valid_sops_stmt t Skip›*) case AssignAddr (*‹∀sop. a_ ≠ Tmp sop› ‹valid_sops_stmt t_ (Assign volatile_ a_ e_ A_ L_ R_ W_)›*) thus "?case" (*goal: ‹valid_sops_stmt ((t_::nat) + used_tmps (a_::expr)) (Assign (volatile_::bool) (Tmp (eval_expr t_ a_)) (e_::expr) (A_::(nat ⇒ nat option) ⇒ nat set) (L_::(nat ⇒ nat option) ⇒ nat set) (R_::(nat ⇒ nat option) ⇒ nat set) (W_::(nat ⇒ nat option) ⇒ nat set))›*) by (force simp add: valid_sops_expr_valid_sop (*‹valid_sops_expr ?t ?e ⟹ valid_sop (eval_expr ?t ?e)›*) intro: valid_sops_stmt_mono (*‹⟦valid_sops_stmt ?t ?s; ?t ≤ ?t'⟧ ⟹ valid_sops_stmt ?t' ?s›*) valid_sops_expr_mono (*‹⟦valid_sops_expr ?t ?e; ?t ≤ ?t'⟧ ⟹ valid_sops_expr ?t' ?e›*) dest: valid_sops_expr_eval_expr_in_range (*‹valid_sops_expr ?t ?e ⟹ ∀t'∈fst (eval_expr ?t ?e). t' < ?t + used_tmps ?e›*)) next (*goals: 1. ‹⋀D volatile a e A L R W t. ⟦D ⊆ dom θ; valid_sops_stmt t (Assign volatile (Tmp (D, a)) e A L R W)⟧ ⟹ valid_sops_stmt (t + used_tmps e) Skip› 2. ‹⋀a c⇩e s⇩e A L R W t. ⟦∀sop. a ≠ Tmp sop; valid_sops_stmt t (CAS a c⇩e s⇩e A L R W)⟧ ⟹ valid_sops_stmt (t + used_tmps a) (CAS (Tmp (eval_expr t a)) c⇩e s⇩e A L R W)› 3. ‹⋀c⇩e D⇩a a s⇩e A L R W t. ⟦∀sop. c⇩e ≠ Tmp sop; valid_sops_stmt t (CAS (Tmp (D⇩a, a)) c⇩e s⇩e A L R W)⟧ ⟹ valid_sops_stmt (t + used_tmps c⇩e) (CAS (Tmp (D⇩a, a)) (Tmp (eval_expr t c⇩e)) s⇩e A L R W)› 4. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f); valid_sops_stmt t (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W)⟧ ⟹ valid_sops_stmt (Suc (t + used_tmps s⇩e)) Skip› 5. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ valid_sops_stmt t' s₁'; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ valid_sops_stmt t' (Seq s₁' s₂)› 6. ‹⋀s₂ t. valid_sops_stmt t (Seq Skip s₂) ⟹ valid_sops_stmt t s₂› 7. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ valid_sops_stmt (t + used_tmps e) (Cond (Tmp (eval_expr t e)) s₁ s₂)› 8. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ valid_sops_stmt t s₁› 9. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ valid_sops_stmt t s₂› 10. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ valid_sops_stmt t (Cond e (Seq s (While e s)) Skip)› 11. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ valid_sops_stmt t Skip› 12. ‹⋀t. valid_sops_stmt t SFence ⟹ valid_sops_stmt t Skip›*) case Assign (*‹D_ ⊆ dom θ› ‹valid_sops_stmt t_ (Assign volatile_ (Tmp (D_, a_)) e_ A_ L_ R_ W_)›*) thus "?case" (*goal: ‹valid_sops_stmt (t_ + used_tmps e_) Skip›*) by simp next (*goals: 1. ‹⋀a c⇩e s⇩e A L R W t. ⟦∀sop. a ≠ Tmp sop; valid_sops_stmt t (CAS a c⇩e s⇩e A L R W)⟧ ⟹ valid_sops_stmt (t + used_tmps a) (CAS (Tmp (eval_expr t a)) c⇩e s⇩e A L R W)› 2. ‹⋀c⇩e D⇩a a s⇩e A L R W t. ⟦∀sop. c⇩e ≠ Tmp sop; valid_sops_stmt t (CAS (Tmp (D⇩a, a)) c⇩e s⇩e A L R W)⟧ ⟹ valid_sops_stmt (t + used_tmps c⇩e) (CAS (Tmp (D⇩a, a)) (Tmp (eval_expr t c⇩e)) s⇩e A L R W)› 3. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f); valid_sops_stmt t (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W)⟧ ⟹ valid_sops_stmt (Suc (t + used_tmps s⇩e)) Skip› 4. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ valid_sops_stmt t' s₁'; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ valid_sops_stmt t' (Seq s₁' s₂)› 5. ‹⋀s₂ t. valid_sops_stmt t (Seq Skip s₂) ⟹ valid_sops_stmt t s₂› 6. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ valid_sops_stmt (t + used_tmps e) (Cond (Tmp (eval_expr t e)) s₁ s₂)› 7. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ valid_sops_stmt t s₁› 8. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ valid_sops_stmt t s₂› 9. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ valid_sops_stmt t (Cond e (Seq s (While e s)) Skip)› 10. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ valid_sops_stmt t Skip› 11. ‹⋀t. valid_sops_stmt t SFence ⟹ valid_sops_stmt t Skip›*) case CASAddr (*‹∀sop. a_ ≠ Tmp sop› ‹valid_sops_stmt (t_::nat) (CAS (a_::expr) (c⇩e_::expr) (s⇩e_::expr) (A_::(nat ⇒ nat option) ⇒ nat set) (L_::(nat ⇒ nat option) ⇒ nat set) (R_::(nat ⇒ nat option) ⇒ nat set) (W_::(nat ⇒ nat option) ⇒ nat set))›*) thus "?case" (*goal: ‹valid_sops_stmt (t_ + used_tmps a_) (CAS (Tmp (eval_expr t_ a_)) c⇩e_ s⇩e_ A_ L_ R_ W_)›*) by (force simp add: valid_sops_expr_valid_sop (*‹valid_sops_expr ?t ?e ⟹ valid_sop (eval_expr ?t ?e)›*) intro: valid_sops_stmt_mono (*‹⟦valid_sops_stmt ?t ?s; ?t ≤ ?t'⟧ ⟹ valid_sops_stmt ?t' ?s›*) valid_sops_expr_mono (*‹⟦valid_sops_expr ?t ?e; ?t ≤ ?t'⟧ ⟹ valid_sops_expr ?t' ?e›*) dest: valid_sops_expr_eval_expr_in_range (*‹valid_sops_expr ?t ?e ⟹ ∀t'∈fst (eval_expr ?t ?e). t' < ?t + used_tmps ?e›*)) next (*goals: 1. ‹⋀c⇩e D⇩a a s⇩e A L R W t. ⟦∀sop. c⇩e ≠ Tmp sop; valid_sops_stmt t (CAS (Tmp (D⇩a, a)) c⇩e s⇩e A L R W)⟧ ⟹ valid_sops_stmt (t + used_tmps c⇩e) (CAS (Tmp (D⇩a, a)) (Tmp (eval_expr t c⇩e)) s⇩e A L R W)› 2. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f); valid_sops_stmt t (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W)⟧ ⟹ valid_sops_stmt (Suc (t + used_tmps s⇩e)) Skip› 3. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ valid_sops_stmt t' s₁'; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ valid_sops_stmt t' (Seq s₁' s₂)› 4. ‹⋀s₂ t. valid_sops_stmt t (Seq Skip s₂) ⟹ valid_sops_stmt t s₂› 5. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ valid_sops_stmt (t + used_tmps e) (Cond (Tmp (eval_expr t e)) s₁ s₂)› 6. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ valid_sops_stmt t s₁› 7. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ valid_sops_stmt t s₂› 8. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ valid_sops_stmt t (Cond e (Seq s (While e s)) Skip)› 9. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ valid_sops_stmt t Skip› 10. ‹⋀t. valid_sops_stmt t SFence ⟹ valid_sops_stmt t Skip›*) case CASComp (*‹∀sop. c⇩e_ ≠ Tmp sop› ‹valid_sops_stmt (t_::nat) (CAS (Tmp (D⇩a_::nat set, a_::(nat ⇒ nat option) ⇒ nat)) (c⇩e_::expr) (s⇩e_::expr) (A_::(nat ⇒ nat option) ⇒ nat set) (L_::(nat ⇒ nat option) ⇒ nat set) (R_::(nat ⇒ nat option) ⇒ nat set) (W_::(nat ⇒ nat option) ⇒ nat set))›*) thus "?case" (*goal: ‹valid_sops_stmt (t_ + used_tmps c⇩e_) (CAS (Tmp (D⇩a_, a_)) (Tmp (eval_expr t_ c⇩e_)) s⇩e_ A_ L_ R_ W_)›*) by (force simp add: valid_sops_expr_valid_sop (*‹valid_sops_expr ?t ?e ⟹ valid_sop (eval_expr ?t ?e)›*) intro: valid_sops_stmt_mono (*‹⟦valid_sops_stmt ?t ?s; ?t ≤ ?t'⟧ ⟹ valid_sops_stmt ?t' ?s›*) valid_sops_expr_mono (*‹⟦valid_sops_expr ?t ?e; ?t ≤ ?t'⟧ ⟹ valid_sops_expr ?t' ?e›*) dest: valid_sops_expr_eval_expr_in_range (*‹valid_sops_expr ?t ?e ⟹ ∀t'∈fst (eval_expr ?t ?e). t' < ?t + used_tmps ?e›*)) next (*goals: 1. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f); valid_sops_stmt t (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W)⟧ ⟹ valid_sops_stmt (Suc (t + used_tmps s⇩e)) Skip› 2. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ valid_sops_stmt t' s₁'; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ valid_sops_stmt t' (Seq s₁' s₂)› 3. ‹⋀s₂ t. valid_sops_stmt t (Seq Skip s₂) ⟹ valid_sops_stmt t s₂› 4. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ valid_sops_stmt (t + used_tmps e) (Cond (Tmp (eval_expr t e)) s₁ s₂)› 5. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ valid_sops_stmt t s₁› 6. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ valid_sops_stmt t s₂› 7. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ valid_sops_stmt t (Cond e (Seq s (While e s)) Skip)› 8. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ valid_sops_stmt t Skip› 9. ‹⋀t. valid_sops_stmt t SFence ⟹ valid_sops_stmt t Skip›*) case CAS (*‹(D⇩a_::nat set) ⊆ dom (θ::nat ⇒ nat option)› ‹D⇩c_ ⊆ dom θ› ‹eval_expr t_ s⇩e_ = (D_, f_)› ‹valid_sops_stmt t_ (CAS (Tmp (D⇩a_, a_)) (Tmp (D⇩c_, c_)) s⇩e_ A_ L_ R_ W_)›*) thus "?case" (*goal: ‹valid_sops_stmt (Suc (t_ + used_tmps s⇩e_)) Skip›*) by simp next (*goals: 1. ‹⋀(s₁::stmt) (t::nat) (s₁'::stmt) (t'::nat) (is::instr list) s₂::stmt. ⟦(θ::nat ⇒ nat option)⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ valid_sops_stmt t' s₁'; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ valid_sops_stmt t' (Seq s₁' s₂)› 2. ‹⋀(s₂::stmt) t::nat. valid_sops_stmt t (Seq Skip s₂) ⟹ valid_sops_stmt t s₂› 3. ‹⋀(e::expr) (s₁::stmt) (s₂::stmt) t::nat. ⟦∀sop::nat set × ((nat ⇒ nat option) ⇒ nat). e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ valid_sops_stmt (t + used_tmps e) (Cond (Tmp (eval_expr t e)) s₁ s₂)› 4. ‹⋀(D::nat set) (e::(nat ⇒ nat option) ⇒ nat) (s₁::stmt) (s₂::stmt) t::nat. ⟦D ⊆ dom (θ::nat ⇒ nat option); isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ valid_sops_stmt t s₁› 5. ‹⋀(D::nat set) (e::(nat ⇒ nat option) ⇒ nat) (s₁::stmt) (s₂::stmt) t::nat. ⟦D ⊆ dom (θ::nat ⇒ nat option); ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ valid_sops_stmt t s₂› 6. ‹⋀(e::expr) (s::stmt) t::nat. valid_sops_stmt t (While e s) ⟹ valid_sops_stmt t (Cond e (Seq s (While e s)) Skip)› 7. ‹⋀(A::(nat ⇒ nat option) ⇒ nat set) (L::(nat ⇒ nat option) ⇒ nat set) (R::(nat ⇒ nat option) ⇒ nat set) (W::(nat ⇒ nat option) ⇒ nat set) t::nat. valid_sops_stmt t (SGhost A L R W) ⟹ valid_sops_stmt t Skip› 8. ‹⋀t::nat. valid_sops_stmt t SFence ⟹ valid_sops_stmt t Skip›*) case Seq (*‹θ⊢ (s₁_, t_) →⇩s ((s₁'_, t'_), is_)› ‹valid_sops_stmt t_ s₁_ ⟹ valid_sops_stmt t'_ s₁'_› ‹valid_sops_stmt t_ (Seq s₁_ s₂_)›*) thus "?case" (*goal: ‹valid_sops_stmt t'_ (Seq s₁'_ s₂_)›*) by (force intro: valid_sops_stmt_mono (*‹⟦valid_sops_stmt ?t ?s; ?t ≤ ?t'⟧ ⟹ valid_sops_stmt ?t' ?s›*) dest: stmt_step_tmps_count_mono (*‹?θ⊢ (?s, ?t) →⇩s ((?s', ?t'), ?is) ⟹ ?t ≤ ?t'›*)) next (*goals: 1. ‹⋀(s₂::stmt) t::nat. valid_sops_stmt t (Seq Skip s₂) ⟹ valid_sops_stmt t s₂› 2. ‹⋀(e::expr) (s₁::stmt) (s₂::stmt) t::nat. ⟦∀sop::nat set × ((nat ⇒ nat option) ⇒ nat). e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ valid_sops_stmt (t + used_tmps e) (Cond (Tmp (eval_expr t e)) s₁ s₂)› 3. ‹⋀(D::nat set) (e::(nat ⇒ nat option) ⇒ nat) (s₁::stmt) (s₂::stmt) t::nat. ⟦D ⊆ dom (θ::nat ⇒ nat option); isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ valid_sops_stmt t s₁› 4. ‹⋀(D::nat set) (e::(nat ⇒ nat option) ⇒ nat) (s₁::stmt) (s₂::stmt) t::nat. ⟦D ⊆ dom (θ::nat ⇒ nat option); ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ valid_sops_stmt t s₂› 5. ‹⋀(e::expr) (s::stmt) t::nat. valid_sops_stmt t (While e s) ⟹ valid_sops_stmt t (Cond e (Seq s (While e s)) Skip)› 6. ‹⋀(A::(nat ⇒ nat option) ⇒ nat set) (L::(nat ⇒ nat option) ⇒ nat set) (R::(nat ⇒ nat option) ⇒ nat set) (W::(nat ⇒ nat option) ⇒ nat set) t::nat. valid_sops_stmt t (SGhost A L R W) ⟹ valid_sops_stmt t Skip› 7. ‹⋀t::nat. valid_sops_stmt t SFence ⟹ valid_sops_stmt t Skip›*) case SeqSkip (*‹valid_sops_stmt t_ (Seq Skip s₂_)›*) thus "?case" (*goal: ‹valid_sops_stmt (t_::nat) (s₂_::stmt)›*) by auto next (*goals: 1. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ valid_sops_stmt (t + used_tmps e) (Cond (Tmp (eval_expr t e)) s₁ s₂)› 2. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ valid_sops_stmt t s₁› 3. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ valid_sops_stmt t s₂› 4. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ valid_sops_stmt t (Cond e (Seq s (While e s)) Skip)› 5. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ valid_sops_stmt t Skip› 6. ‹⋀t. valid_sops_stmt t SFence ⟹ valid_sops_stmt t Skip›*) case Cond (*‹∀sop. e_ ≠ Tmp sop› ‹valid_sops_stmt (t_::nat) (Cond (e_::expr) (s₁_::stmt) (s₂_::stmt))›*) thus "?case" (*goal: ‹valid_sops_stmt (t_ + used_tmps e_) (Cond (Tmp (eval_expr t_ e_)) s₁_ s₂_)›*) by (fastforce simp add: valid_sops_expr_valid_sop (*‹valid_sops_expr ?t ?e ⟹ valid_sop (eval_expr ?t ?e)›*) intro: valid_sops_stmt_mono (*‹⟦valid_sops_stmt ?t ?s; ?t ≤ ?t'⟧ ⟹ valid_sops_stmt ?t' ?s›*) dest: valid_sops_expr_eval_expr_in_range (*‹valid_sops_expr ?t ?e ⟹ ∀t'∈fst (eval_expr ?t ?e). t' < ?t + used_tmps ?e›*)) next (*goals: 1. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ valid_sops_stmt t s₁› 2. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ valid_sops_stmt t s₂› 3. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ valid_sops_stmt t (Cond e (Seq s (While e s)) Skip)› 4. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ valid_sops_stmt t Skip› 5. ‹⋀t. valid_sops_stmt t SFence ⟹ valid_sops_stmt t Skip›*) case CondTrue (*‹D_ ⊆ dom θ› ‹isTrue (e_ θ)› ‹valid_sops_stmt t_ (Cond (Tmp (D_, e_)) s₁_ s₂_)›*) thus "?case" (*goal: ‹valid_sops_stmt t_ s₁_›*) by force next (*goals: 1. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ valid_sops_stmt t s₂› 2. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ valid_sops_stmt t (Cond e (Seq s (While e s)) Skip)› 3. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ valid_sops_stmt t Skip› 4. ‹⋀t. valid_sops_stmt t SFence ⟹ valid_sops_stmt t Skip›*) case CondFalse (*‹(D_::nat set) ⊆ dom (θ::nat ⇒ nat option)› ‹¬ isTrue (e_ θ)› ‹valid_sops_stmt t_ (Cond (Tmp (D_, e_)) s₁_ s₂_)›*) thus "?case" (*goal: ‹valid_sops_stmt t_ s₂_›*) by force next (*goals: 1. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ valid_sops_stmt t (Cond e (Seq s (While e s)) Skip)› 2. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ valid_sops_stmt t Skip› 3. ‹⋀t. valid_sops_stmt t SFence ⟹ valid_sops_stmt t Skip›*) case While (*‹valid_sops_stmt t_ (While e_ s_)›*) thus "?case" (*goal: ‹valid_sops_stmt t_ (Cond e_ (Seq s_ (While e_ s_)) Skip)›*) by auto next (*goals: 1. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ valid_sops_stmt t Skip› 2. ‹⋀t. valid_sops_stmt t SFence ⟹ valid_sops_stmt t Skip›*) case SGhost (*‹valid_sops_stmt (t_::nat) (SGhost (A_::(nat ⇒ nat option) ⇒ nat set) (L_::(nat ⇒ nat option) ⇒ nat set) (R_::(nat ⇒ nat option) ⇒ nat set) (W_::(nat ⇒ nat option) ⇒ nat set))›*) thus "?case" (*goal: ‹valid_sops_stmt t_ Skip›*) by simp next (*goal: ‹⋀t. valid_sops_stmt t SFence ⟹ valid_sops_stmt t Skip›*) case SFence (*‹valid_sops_stmt (t_::nat) SFence›*) thus "?case" (*goal: ‹valid_sops_stmt (t_::nat) Skip›*) by simp qed lemma map_le_restrict_map_eq: "m₁ ⊆⇩m m₂ ⟹ D ⊆ dom m₁ ⟹ m₂ |` D = m₁ |` D" apply (rule ext (*‹(⋀x::?'a. (?f::?'a ⇒ ?'b) x = (?g::?'a ⇒ ?'b) x) ⟹ ?f = ?g›*)) (*goal: ‹⟦m₁ ⊆⇩m m₂; D ⊆ dom m₁⟧ ⟹ m₂ |` D = m₁ |` D›*) by (force simp add: restrict_map_def (*‹?m |` ?A = (λx. if x ∈ ?A then ?m x else None)›*) map_le_def (*‹(?m₁ ⊆⇩m ?m₂) = (∀a∈dom ?m₁. ?m₁ a = ?m₂ a)›*)) lemma sbh_step_preserves_load_tmps_bound: assumes step: "(is,𝒪,𝒟,θ,sb,𝒮,m) →⇩s⇩b⇩h (is',𝒪',𝒟',θ',sb',𝒮',m')" assumes less: "∀i ∈ load_tmps is. i < n" shows "∀i ∈ load_tmps is'. i < n" using step (*‹(is::instr list, 𝒪::nat ⇒ nat option, 𝒟::'a memref list, θ::nat ⇒ nat, sb::bool, 𝒮::nat set, m::(nat ⇒ bool option) × (nat ⇒ bool option)) →⇩s⇩b⇩h (is'::instr list, 𝒪'::nat ⇒ nat option, 𝒟'::'a memref list, θ'::nat ⇒ nat, sb'::bool, 𝒮'::nat set, m'::(nat ⇒ bool option) × (nat ⇒ bool option))›*) less (*‹∀i∈load_tmps is. i < n›*) apply cases (*goals: 1. ‹⋀a v volatile t ℛ 𝒮''. ⟦∀i∈load_tmps is. i < n; is = Read volatile a t # is'; m = (ℛ, 𝒮''); 𝒪' = 𝒪(t ↦ v); 𝒟' = 𝒟 @ [Read⇩s⇩b volatile a t v]; θ' = θ; sb' = sb; 𝒮' = 𝒮; m' = (ℛ, 𝒮''); buffered_val 𝒟 a = Some v⟧ ⟹ ∀i∈load_tmps is'. i < n› 2. ‹⋀a volatile t ℛ 𝒮''. ⟦∀i∈load_tmps is. i < n; is = Read volatile a t # is'; m = (ℛ, 𝒮''); 𝒪' = 𝒪(t ↦ θ a); 𝒟' = 𝒟 @ [Read⇩s⇩b volatile a t (θ a)]; θ' = θ; sb' = sb; 𝒮' = 𝒮; m' = (ℛ, 𝒮''); buffered_val 𝒟 a = None⟧ ⟹ ∀i∈load_tmps is'. i < n› 3. ‹⋀a D f A L R W ℛ 𝒮''. ⟦∀i∈load_tmps is. i < n; is = Write False a (D, f) A L R W # is'; m = (ℛ, 𝒮''); 𝒪' = 𝒪; 𝒟' = 𝒟 @ [Write⇩s⇩b False a (D, f) (f 𝒪) A L R W]; θ' = θ; sb' = sb; 𝒮' = 𝒮; m' = (ℛ, 𝒮'')⟧ ⟹ ∀i∈load_tmps is'. i < n› 4. ‹⋀a D f A L R W ℛ 𝒮''. ⟦∀i∈load_tmps is. i < n; is = Write True a (D, f) A L R W # is'; m = (ℛ, 𝒮''); 𝒪' = 𝒪; 𝒟' = 𝒟 @ [Write⇩s⇩b True a (D, f) (f 𝒪) A L R W]; θ' = θ; sb' = True; 𝒮' = 𝒮; m' = (ℛ, 𝒮'')⟧ ⟹ ∀i∈load_tmps is'. i < n› 5. ‹⋀ℛ 𝒮''. ⟦∀i∈load_tmps is. i < n; is = Fence # is'; 𝒟 = []; m = (ℛ, 𝒮''); 𝒪' = 𝒪; 𝒟' = []; θ' = θ; sb' = False; 𝒮' = 𝒮; m' = (λx. None, 𝒮'')⟧ ⟹ ∀i∈load_tmps is'. i < n› 6. ‹⋀cond t a D f ret A L R W ℛ 𝒮''. ⟦∀i∈load_tmps is. i < n; is = RMW a t (D, f) cond ret A L R W # is'; 𝒟 = []; m = (ℛ, 𝒮''); 𝒪' = 𝒪(t ↦ θ a); 𝒟' = []; θ' = θ; sb' = False; 𝒮' = 𝒮; m' = (λx. None, 𝒮''); ¬ cond (𝒪(t ↦ θ a))⟧ ⟹ ∀i∈load_tmps is'. i < n› 7. ‹⋀cond t a D f ret A L R W ℛ 𝒮''. ⟦∀i∈load_tmps is. i < n; is = RMW a t (D, f) cond ret A L R W # is'; 𝒟 = []; m = (ℛ, 𝒮''); 𝒪' = 𝒪(t ↦ ret (θ a) (f (𝒪(t ↦ θ a)))); 𝒟' = []; θ' = θ(a := f (𝒪(t ↦ θ a))); sb' = False; 𝒮' = 𝒮 ∪ A - R; m' = (λx. None, 𝒮'' ⊕⇘W⇙ R ⊖⇘A⇙ L); cond (𝒪(t ↦ θ a))⟧ ⟹ ∀i∈load_tmps is'. i < n› 8. ‹⋀A L R W ℛ 𝒮''. ⟦∀i∈load_tmps is. i < n; is = Ghost A L R W # is'; m = (ℛ, 𝒮''); 𝒪' = 𝒪; 𝒟' = 𝒟 @ [Ghost⇩s⇩b A L R W]; θ' = θ; sb' = sb; 𝒮' = 𝒮; m' = (ℛ, 𝒮'')⟧ ⟹ ∀i∈load_tmps is'. i < n› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*proven 8 subgoals*) . lemma sbh_step_preserves_read_tmps_bound: assumes step: "(is,θ,sb,m,𝒟,𝒪,𝒮) →⇩s⇩b⇩h (is',θ',sb',m',𝒟',𝒪',𝒮')" assumes less_is: "∀i ∈ load_tmps is. i < n" assumes less_sb: "∀i ∈ read_tmps sb. i < n" shows "∀i ∈ read_tmps sb'. i < n" using step (*‹(is, θ, sb, m, 𝒟, 𝒪, 𝒮) →⇩s⇩b⇩h (is', θ', sb', m', 𝒟', 𝒪', 𝒮')›*) less_is (*‹∀i∈load_tmps is. i < n›*) less_sb (*‹∀i∈read_tmps sb. i < n›*) apply cases (*goals: 1. ‹⋀a v volatile t ℛ 𝒮''. ⟦∀i∈load_tmps is. i < n; ∀i∈read_tmps sb. i < n; is = Read volatile a t # is'; 𝒮 = (ℛ, 𝒮''); θ' = θ(t ↦ v); sb' = sb @ [Read⇩s⇩b volatile a t v]; m' = m; 𝒟' = 𝒟; 𝒪' = 𝒪; 𝒮' = (ℛ, 𝒮''); buffered_val sb a = Some v⟧ ⟹ ∀i∈read_tmps sb'. i < n› 2. ‹⋀a volatile t ℛ 𝒮''. ⟦∀i∈load_tmps is. i < n; ∀i∈read_tmps sb. i < n; is = Read volatile a t # is'; 𝒮 = (ℛ, 𝒮''); θ' = θ(t ↦ m a); sb' = sb @ [Read⇩s⇩b volatile a t (m a)]; m' = m; 𝒟' = 𝒟; 𝒪' = 𝒪; 𝒮' = (ℛ, 𝒮''); buffered_val sb a = None⟧ ⟹ ∀i∈read_tmps sb'. i < n› 3. ‹⋀a D f A L R W ℛ 𝒮''. ⟦∀i∈load_tmps is. i < n; ∀i∈read_tmps sb. i < n; is = Write False a (D, f) A L R W # is'; 𝒮 = (ℛ, 𝒮''); θ' = θ; sb' = sb @ [Write⇩s⇩b False a (D, f) (f θ) A L R W]; m' = m; 𝒟' = 𝒟; 𝒪' = 𝒪; 𝒮' = (ℛ, 𝒮'')⟧ ⟹ ∀i∈read_tmps sb'. i < n› 4. ‹⋀a D f A L R W ℛ 𝒮''. ⟦∀i∈load_tmps is. i < n; ∀i∈read_tmps sb. i < n; is = Write True a (D, f) A L R W # is'; 𝒮 = (ℛ, 𝒮''); θ' = θ; sb' = sb @ [Write⇩s⇩b True a (D, f) (f θ) A L R W]; m' = m; 𝒟' = True; 𝒪' = 𝒪; 𝒮' = (ℛ, 𝒮'')⟧ ⟹ ∀i∈read_tmps sb'. i < n› 5. ‹⋀ℛ 𝒮''. ⟦∀i∈load_tmps is. i < n; ∀i∈read_tmps sb. i < n; is = Fence # is'; sb = []; 𝒮 = (ℛ, 𝒮''); θ' = θ; sb' = []; m' = m; 𝒟' = False; 𝒪' = 𝒪; 𝒮' = (λx. None, 𝒮'')⟧ ⟹ ∀i∈read_tmps sb'. i < n› 6. ‹⋀cond t a D f ret A L R W ℛ 𝒮''. ⟦∀i∈load_tmps is. i < n; ∀i∈read_tmps sb. i < n; is = RMW a t (D, f) cond ret A L R W # is'; sb = []; 𝒮 = (ℛ, 𝒮''); θ' = θ(t ↦ m a); sb' = []; m' = m; 𝒟' = False; 𝒪' = 𝒪; 𝒮' = (λx. None, 𝒮''); ¬ cond (θ(t ↦ m a))⟧ ⟹ ∀i∈read_tmps sb'. i < n› 7. ‹⋀cond t a D f ret A L R W ℛ 𝒮''. ⟦∀i∈load_tmps is. i < n; ∀i∈read_tmps sb. i < n; is = RMW a t (D, f) cond ret A L R W # is'; sb = []; 𝒮 = (ℛ, 𝒮''); θ' = θ(t ↦ ret (m a) (f (θ(t ↦ m a)))); sb' = []; m' = m(a := f (θ(t ↦ m a))); 𝒟' = False; 𝒪' = 𝒪 ∪ A - R; 𝒮' = (λx. None, 𝒮'' ⊕⇘W⇙ R ⊖⇘A⇙ L); cond (θ(t ↦ m a))⟧ ⟹ ∀i∈read_tmps sb'. i < n› 8. ‹⋀A L R W ℛ 𝒮''. ⟦∀i∈load_tmps is. i < n; ∀i∈read_tmps sb. i < n; is = Ghost A L R W # is'; 𝒮 = (ℛ, 𝒮''); θ' = θ; sb' = sb @ [Ghost⇩s⇩b A L R W]; m' = m; 𝒟' = 𝒟; 𝒪' = 𝒪; 𝒮' = (ℛ, 𝒮'')⟧ ⟹ ∀i∈read_tmps sb'. i < n› discuss goal 1*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 2*) apply ((auto simp add: read_tmps_append (*‹read_tmps ((?xs::?'a::type memref list) @ (?ys::?'a::type memref list)) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 3*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 4*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 5*) apply ((auto simp add: read_tmps_append (*‹read_tmps ((?xs::?'a memref list) @ (?ys::?'a memref list)) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 6*) apply ((auto simp add: read_tmps_append (*‹read_tmps ((?xs::?'a::type memref list) @ (?ys::?'a::type memref list)) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 7*) apply ((auto simp add: read_tmps_append (*‹read_tmps ((?xs::?'a memref list) @ (?ys::?'a memref list)) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 8*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*proven 8 subgoals*) . lemma sbh_step_preserves_tmps_bound: assumes step: "(is,θ,sb,m,𝒟,𝒪,𝒮) →⇩s⇩b⇩h (is',θ',sb',m',𝒟',𝒪',𝒮')" assumes less_dom: "∀i ∈ dom θ. i < n" assumes less_is: "∀i ∈ load_tmps is. i < n" shows "∀i ∈ dom θ'. i < n" using step (*‹(is::instr list, θ::nat ⇒ nat option, sb::'a::type memref list, m::nat ⇒ nat, 𝒟::bool, 𝒪::nat set, 𝒮::(nat ⇒ bool option) × (nat ⇒ bool option)) →⇩s⇩b⇩h (is'::instr list, θ'::nat ⇒ nat option, sb'::'a::type memref list, m'::nat ⇒ nat, 𝒟'::bool, 𝒪'::nat set, 𝒮'::(nat ⇒ bool option) × (nat ⇒ bool option))›*) less_dom (*‹∀i∈dom θ. i < n›*) less_is (*‹∀i::nat∈load_tmps (is::instr list). i < (n::nat)›*) apply cases (*goals: 1. ‹⋀a v volatile t ℛ 𝒮''. ⟦∀i∈dom θ. i < n; ∀i∈load_tmps is. i < n; is = Read volatile a t # is'; 𝒮 = (ℛ, 𝒮''); θ' = θ(t ↦ v); sb' = sb @ [Read⇩s⇩b volatile a t v]; m' = m; 𝒟' = 𝒟; 𝒪' = 𝒪; 𝒮' = (ℛ, 𝒮''); buffered_val sb a = Some v⟧ ⟹ ∀i∈dom θ'. i < n› 2. ‹⋀a volatile t ℛ 𝒮''. ⟦∀i∈dom θ. i < n; ∀i∈load_tmps is. i < n; is = Read volatile a t # is'; 𝒮 = (ℛ, 𝒮''); θ' = θ(t ↦ m a); sb' = sb @ [Read⇩s⇩b volatile a t (m a)]; m' = m; 𝒟' = 𝒟; 𝒪' = 𝒪; 𝒮' = (ℛ, 𝒮''); buffered_val sb a = None⟧ ⟹ ∀i∈dom θ'. i < n› 3. ‹⋀a D f A L R W ℛ 𝒮''. ⟦∀i∈dom θ. i < n; ∀i∈load_tmps is. i < n; is = Write False a (D, f) A L R W # is'; 𝒮 = (ℛ, 𝒮''); θ' = θ; sb' = sb @ [Write⇩s⇩b False a (D, f) (f θ) A L R W]; m' = m; 𝒟' = 𝒟; 𝒪' = 𝒪; 𝒮' = (ℛ, 𝒮'')⟧ ⟹ ∀i∈dom θ'. i < n› 4. ‹⋀a D f A L R W ℛ 𝒮''. ⟦∀i∈dom θ. i < n; ∀i∈load_tmps is. i < n; is = Write True a (D, f) A L R W # is'; 𝒮 = (ℛ, 𝒮''); θ' = θ; sb' = sb @ [Write⇩s⇩b True a (D, f) (f θ) A L R W]; m' = m; 𝒟' = True; 𝒪' = 𝒪; 𝒮' = (ℛ, 𝒮'')⟧ ⟹ ∀i∈dom θ'. i < n› 5. ‹⋀ℛ 𝒮''. ⟦∀i∈dom θ. i < n; ∀i∈load_tmps is. i < n; is = Fence # is'; sb = []; 𝒮 = (ℛ, 𝒮''); θ' = θ; sb' = []; m' = m; 𝒟' = False; 𝒪' = 𝒪; 𝒮' = (λx. None, 𝒮'')⟧ ⟹ ∀i∈dom θ'. i < n› 6. ‹⋀cond t a D f ret A L R W ℛ 𝒮''. ⟦∀i∈dom θ. i < n; ∀i∈load_tmps is. i < n; is = RMW a t (D, f) cond ret A L R W # is'; sb = []; 𝒮 = (ℛ, 𝒮''); θ' = θ(t ↦ m a); sb' = []; m' = m; 𝒟' = False; 𝒪' = 𝒪; 𝒮' = (λx. None, 𝒮''); ¬ cond (θ(t ↦ m a))⟧ ⟹ ∀i∈dom θ'. i < n› 7. ‹⋀cond t a D f ret A L R W ℛ 𝒮''. ⟦∀i∈dom θ. i < n; ∀i∈load_tmps is. i < n; is = RMW a t (D, f) cond ret A L R W # is'; sb = []; 𝒮 = (ℛ, 𝒮''); θ' = θ(t ↦ ret (m a) (f (θ(t ↦ m a)))); sb' = []; m' = m(a := f (θ(t ↦ m a))); 𝒟' = False; 𝒪' = 𝒪 ∪ A - R; 𝒮' = (λx. None, 𝒮'' ⊕⇘W⇙ R ⊖⇘A⇙ L); cond (θ(t ↦ m a))⟧ ⟹ ∀i∈dom θ'. i < n› 8. ‹⋀A L R W ℛ 𝒮''. ⟦∀i∈dom θ. i < n; ∀i∈load_tmps is. i < n; is = Ghost A L R W # is'; 𝒮 = (ℛ, 𝒮''); θ' = θ; sb' = sb @ [Ghost⇩s⇩b A L R W]; m' = m; 𝒟' = 𝒟; 𝒪' = 𝒪; 𝒮' = (ℛ, 𝒮'')⟧ ⟹ ∀i∈dom θ'. i < n› discuss goal 1*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 2*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 3*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 4*) apply ((auto simp add: read_tmps_append (*‹read_tmps ((?xs::?'a::type memref list) @ (?ys::?'a::type memref list)) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 5*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 6*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 7*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 8*) apply ((auto simp add: read_tmps_append (*‹read_tmps ((?xs::?'a memref list) @ (?ys::?'a memref list)) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*proven 8 subgoals*) . lemma flush_step_preserves_read_tmps: assumes step: "(m,sb,𝒪) →⇩f (m',sb',𝒪')" assumes less_sb: "∀i ∈ read_tmps sb. i < n" shows "∀i ∈ read_tmps sb'. i < n" using step (*‹(m, sb, 𝒪) →⇩f (m', sb', 𝒪')›*) less_sb (*‹∀i∈read_tmps sb. i < n›*) apply cases (*goals: 1. ‹⋀𝒪'' volatile 𝒪''' A R 𝒮' 𝒮 W L ℛ' ℛ a sop v. ⟦∀i∈read_tmps sb. i < n; sb = Write⇩s⇩b volatile a sop v A L R W # sb'; 𝒪 = (𝒪''', ℛ, 𝒮); m' = m(a := v); 𝒪' = (𝒪'', ℛ', 𝒮'); 𝒪'' = (if volatile then 𝒪''' ∪ A - R else 𝒪'''); 𝒮' = (if volatile then 𝒮 ⊕⇘W⇙ R ⊖⇘A⇙ L else 𝒮); ℛ' = (if volatile then λx. None else ℛ)⟧ ⟹ ∀i∈read_tmps sb'. i < n› 2. ‹⋀volatile a t v 𝒪'' ℛ 𝒮. ⟦∀i∈read_tmps sb. i < n; sb = Read⇩s⇩b volatile a t v # sb'; 𝒪 = (𝒪'', ℛ, 𝒮); m' = m; 𝒪' = (𝒪'', ℛ, 𝒮)⟧ ⟹ ∀i∈read_tmps sb'. i < n› 3. ‹⋀p p' is 𝒪'' ℛ 𝒮. ⟦∀i∈read_tmps sb. i < n; sb = Prog⇩s⇩b p p' is # sb'; 𝒪 = (𝒪'', ℛ, 𝒮); m' = m; 𝒪' = (𝒪'', ℛ, 𝒮)⟧ ⟹ ∀i∈read_tmps sb'. i < n› 4. ‹⋀A L R W 𝒪'' ℛ 𝒮. ⟦∀i∈read_tmps sb. i < n; sb = Ghost⇩s⇩b A L R W # sb'; 𝒪 = (𝒪'', ℛ, 𝒮); m' = m; 𝒪' = (𝒪'' ∪ A - R, augment_rels (dom 𝒮) R ℛ, 𝒮 ⊕⇘W⇙ R ⊖⇘A⇙ L)⟧ ⟹ ∀i∈read_tmps sb'. i < n› discuss goal 1*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 2*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 3*) apply ((auto simp add: read_tmps_append (*‹read_tmps ((?xs::?'a memref list) @ (?ys::?'a memref list)) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 4*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*proven 4 subgoals*) . lemma flush_step_preserves_write_sops: assumes step: "(m,sb,𝒪) →⇩f (m',sb',𝒪')" assumes less_sb: "∀i∈⋃(fst ` write_sops sb). i < t" shows "∀i∈⋃(fst ` write_sops sb'). i < t" using step (*‹(m::nat ⇒ nat, sb::'a memref list, 𝒪::nat set × (nat ⇒ bool option) × (nat ⇒ bool option)) →⇩f (m'::nat ⇒ nat, sb'::'a memref list, 𝒪'::nat set × (nat ⇒ bool option) × (nat ⇒ bool option))›*) less_sb (*‹∀i∈⋃ (fst ` write_sops sb). i < t›*) apply cases (*goals: 1. ‹⋀𝒪'' volatile 𝒪''' A R 𝒮' 𝒮 W L ℛ' ℛ a sop v. ⟦∀i∈⋃ (fst ` write_sops sb). i < t; sb = Write⇩s⇩b volatile a sop v A L R W # sb'; 𝒪 = (𝒪''', ℛ, 𝒮); m' = m(a := v); 𝒪' = (𝒪'', ℛ', 𝒮'); 𝒪'' = (if volatile then 𝒪''' ∪ A - R else 𝒪'''); 𝒮' = (if volatile then 𝒮 ⊕⇘W⇙ R ⊖⇘A⇙ L else 𝒮); ℛ' = (if volatile then λx. None else ℛ)⟧ ⟹ ∀i∈⋃ (fst ` write_sops sb'). i < t› 2. ‹⋀volatile a ta v 𝒪'' ℛ 𝒮. ⟦∀i∈⋃ (fst ` write_sops sb). i < t; sb = Read⇩s⇩b volatile a ta v # sb'; 𝒪 = (𝒪'', ℛ, 𝒮); m' = m; 𝒪' = (𝒪'', ℛ, 𝒮)⟧ ⟹ ∀i∈⋃ (fst ` write_sops sb'). i < t› 3. ‹⋀p p' is 𝒪'' ℛ 𝒮. ⟦∀i∈⋃ (fst ` write_sops sb). i < t; sb = Prog⇩s⇩b p p' is # sb'; 𝒪 = (𝒪'', ℛ, 𝒮); m' = m; 𝒪' = (𝒪'', ℛ, 𝒮)⟧ ⟹ ∀i∈⋃ (fst ` write_sops sb'). i < t› 4. ‹⋀A L R W 𝒪'' ℛ 𝒮. ⟦∀i∈⋃ (fst ` write_sops sb). i < t; sb = Ghost⇩s⇩b A L R W # sb'; 𝒪 = (𝒪'', ℛ, 𝒮); m' = m; 𝒪' = (𝒪'' ∪ A - R, augment_rels (dom 𝒮) R ℛ, 𝒮 ⊕⇘W⇙ R ⊖⇘A⇙ L)⟧ ⟹ ∀i∈⋃ (fst ` write_sops sb'). i < t› discuss goal 1*) apply ((auto simp add: read_tmps_append (*‹read_tmps ((?xs::?'a memref list) @ (?ys::?'a memref list)) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 2*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 3*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 4*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*proven 4 subgoals*) . lemma issue_expr_load_tmps_range': "⋀t. load_tmps (issue_expr t e) = {i. t ≤ i ∧ i < t + used_tmps e}" apply (induct e) (*goals: 1. ‹⋀x t. load_tmps (issue_expr t (Const x)) = {i. t ≤ i ∧ i < t + used_tmps (Const x)}› 2. ‹⋀x1a x2 t. load_tmps (issue_expr t (Mem x1a x2)) = {i. t ≤ i ∧ i < t + used_tmps (Mem x1a x2)}› 3. ‹⋀x t. load_tmps (issue_expr t (Tmp x)) = {i. t ≤ i ∧ i < t + used_tmps (Tmp x)}› 4. ‹⋀x1a e t. (⋀t. load_tmps (issue_expr t e) = {i. t ≤ i ∧ i < t + used_tmps e}) ⟹ load_tmps (issue_expr t (Unop x1a e)) = {i. t ≤ i ∧ i < t + used_tmps (Unop x1a e)}› 5. ‹⋀x1a e1 e2 t. ⟦⋀t. load_tmps (issue_expr t e1) = {i. t ≤ i ∧ i < t + used_tmps e1}; ⋀t. load_tmps (issue_expr t e2) = {i. t ≤ i ∧ i < t + used_tmps e2}⟧ ⟹ load_tmps (issue_expr t (Binop x1a e1 e2)) = {i. t ≤ i ∧ i < t + used_tmps (Binop x1a e1 e2)}› discuss goal 1*) apply (force simp add: load_tmps_append (*‹load_tmps (?xs @ ?ys) = load_tmps ?xs ∪ load_tmps ?ys›*)) (*discuss goal 2*) apply (force simp add: load_tmps_append (*‹load_tmps (?xs @ ?ys) = load_tmps ?xs ∪ load_tmps ?ys›*)) (*discuss goal 3*) apply (force simp add: load_tmps_append (*‹load_tmps ((?xs::instr list) @ (?ys::instr list)) = load_tmps ?xs ∪ load_tmps ?ys›*)) (*discuss goal 4*) apply (force simp add: load_tmps_append (*‹load_tmps (?xs @ ?ys) = load_tmps ?xs ∪ load_tmps ?ys›*)) (*discuss goal 5*) apply (force simp add: load_tmps_append (*‹load_tmps ((?xs::instr list) @ (?ys::instr list)) = load_tmps ?xs ∪ load_tmps ?ys›*)) (*proven 5 subgoals*) . lemma issue_expr_load_tmps_range: "⋀t. ∀i ∈ load_tmps (issue_expr t e). t ≤ i ∧ i < t + (used_tmps e)" by (auto simp add: issue_expr_load_tmps_range' (*‹load_tmps (issue_expr ?t ?e) = {i. ?t ≤ i ∧ i < ?t + used_tmps ?e}›*)) lemma stmt_step_load_tmps_range': assumes step: "θ⊢ (s, t) →⇩s ((s', t'),is)" shows "load_tmps is = {i. t ≤ i ∧ i < t'}" using step (*‹θ⊢ (s, t) →⇩s ((s', t'), is)›*) apply (induct x=="(s,t)" y=="((s',t'),is)" arbitrary: s t s' t' "is" rule: stmt_step.induct) (*goals: 1. ‹⋀a volatile e A L R W t. ∀sop. a ≠ Tmp sop ⟹ load_tmps (issue_expr t a) = {i. t ≤ i ∧ i < t + used_tmps a}› 2. ‹⋀D volatile a e A L R W t. D ⊆ dom θ ⟹ load_tmps (issue_expr t e @ [Write volatile (a θ) (eval_expr t e) (A θ) (L θ) (R θ) (W θ)]) = {i. t ≤ i ∧ i < t + used_tmps e}› 3. ‹⋀a c⇩e s⇩e A L R W t. ∀sop. a ≠ Tmp sop ⟹ load_tmps (issue_expr t a) = {i. t ≤ i ∧ i < t + used_tmps a}› 4. ‹⋀c⇩e D⇩a a s⇩e A L R W t. ∀sop. c⇩e ≠ Tmp sop ⟹ load_tmps (issue_expr t c⇩e) = {i. t ≤ i ∧ i < t + used_tmps c⇩e}› 5. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f)⟧ ⟹ load_tmps (issue_expr t s⇩e @ [RMW (a θ) (t + used_tmps s⇩e) (D, f) (λθ. the (θ (t + used_tmps s⇩e)) = c θ) (λv₁ v₂. v₁) (A θ) (L θ) (R θ) (W θ)]) = {i. t ≤ i ∧ i < Suc (t + used_tmps s⇩e)}› 6. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); load_tmps is = {i. t ≤ i ∧ i < t'}⟧ ⟹ load_tmps is = {i. t ≤ i ∧ i < t'}› 7. ‹⋀s₂ t. load_tmps [] = {i. t ≤ i ∧ i < t}› 8. ‹⋀e s₁ s₂ t. ∀sop. e ≠ Tmp sop ⟹ load_tmps (issue_expr t e) = {i. t ≤ i ∧ i < t + used_tmps e}› 9. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ)⟧ ⟹ load_tmps [] = {i. t ≤ i ∧ i < t}› 10. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ)⟧ ⟹ load_tmps [] = {i. t ≤ i ∧ i < t}› 11. ‹⋀e s t. load_tmps [] = {i. t ≤ i ∧ i < t}› 12. ‹⋀A L R W t. load_tmps [Ghost (A θ) (L θ) (R θ) (W θ)] = {i. t ≤ i ∧ i < t}› 13. ‹⋀t. load_tmps [Fence] = {i. t ≤ i ∧ i < t}› discuss goal 1*) apply (force simp add: load_tmps_append (*‹load_tmps (?xs @ ?ys) = load_tmps ?xs ∪ load_tmps ?ys›*) simp add: issue_expr_load_tmps_range' (*‹load_tmps (issue_expr ?t ?e) = {i. ?t ≤ i ∧ i < ?t + used_tmps ?e}›*)) (*discuss goal 2*) apply (force simp add: load_tmps_append (*‹load_tmps (?xs @ ?ys) = load_tmps ?xs ∪ load_tmps ?ys›*) simp add: issue_expr_load_tmps_range' (*‹load_tmps (issue_expr ?t ?e) = {i. ?t ≤ i ∧ i < ?t + used_tmps ?e}›*)) (*discuss goal 3*) apply (force simp add: load_tmps_append (*‹load_tmps (?xs @ ?ys) = load_tmps ?xs ∪ load_tmps ?ys›*) simp add: issue_expr_load_tmps_range' (*‹load_tmps (issue_expr ?t ?e) = {i. ?t ≤ i ∧ i < ?t + used_tmps ?e}›*)) (*discuss goal 4*) apply (force simp add: load_tmps_append (*‹load_tmps ((?xs::instr list) @ (?ys::instr list)) = load_tmps ?xs ∪ load_tmps ?ys›*) simp add: issue_expr_load_tmps_range' (*‹load_tmps (issue_expr (?t::nat) (?e::expr)) = {i::nat. ?t ≤ i ∧ i < ?t + used_tmps ?e}›*)) (*discuss goal 5*) apply (force simp add: load_tmps_append (*‹load_tmps (?xs @ ?ys) = load_tmps ?xs ∪ load_tmps ?ys›*) simp add: issue_expr_load_tmps_range' (*‹load_tmps (issue_expr ?t ?e) = {i. ?t ≤ i ∧ i < ?t + used_tmps ?e}›*)) (*discuss goal 6*) apply (force simp add: load_tmps_append (*‹load_tmps ((?xs::instr list) @ (?ys::instr list)) = load_tmps ?xs ∪ load_tmps ?ys›*) simp add: issue_expr_load_tmps_range' (*‹load_tmps (issue_expr (?t::nat) (?e::expr)) = {i::nat. ?t ≤ i ∧ i < ?t + used_tmps ?e}›*)) (*discuss goal 7*) apply (force simp add: load_tmps_append (*‹load_tmps (?xs @ ?ys) = load_tmps ?xs ∪ load_tmps ?ys›*) simp add: issue_expr_load_tmps_range' (*‹load_tmps (issue_expr ?t ?e) = {i. ?t ≤ i ∧ i < ?t + used_tmps ?e}›*)) (*discuss goal 8*) apply (force simp add: load_tmps_append (*‹load_tmps (?xs @ ?ys) = load_tmps ?xs ∪ load_tmps ?ys›*) simp add: issue_expr_load_tmps_range' (*‹load_tmps (issue_expr ?t ?e) = {i. ?t ≤ i ∧ i < ?t + used_tmps ?e}›*)) (*discuss goal 9*) apply (force simp add: load_tmps_append (*‹load_tmps (?xs @ ?ys) = load_tmps ?xs ∪ load_tmps ?ys›*) simp add: issue_expr_load_tmps_range' (*‹load_tmps (issue_expr ?t ?e) = {i. ?t ≤ i ∧ i < ?t + used_tmps ?e}›*)) (*discuss goal 10*) apply (force simp add: load_tmps_append (*‹load_tmps (?xs @ ?ys) = load_tmps ?xs ∪ load_tmps ?ys›*) simp add: issue_expr_load_tmps_range' (*‹load_tmps (issue_expr ?t ?e) = {i. ?t ≤ i ∧ i < ?t + used_tmps ?e}›*)) (*discuss goal 11*) apply (force simp add: load_tmps_append (*‹load_tmps ((?xs::instr list) @ (?ys::instr list)) = load_tmps ?xs ∪ load_tmps ?ys›*) simp add: issue_expr_load_tmps_range' (*‹load_tmps (issue_expr (?t::nat) (?e::expr)) = {i::nat. ?t ≤ i ∧ i < ?t + used_tmps ?e}›*)) (*discuss goal 12*) apply (force simp add: load_tmps_append (*‹load_tmps (?xs @ ?ys) = load_tmps ?xs ∪ load_tmps ?ys›*) simp add: issue_expr_load_tmps_range' (*‹load_tmps (issue_expr ?t ?e) = {i. ?t ≤ i ∧ i < ?t + used_tmps ?e}›*)) (*discuss goal 13*) apply (force simp add: load_tmps_append (*‹load_tmps (?xs @ ?ys) = load_tmps ?xs ∪ load_tmps ?ys›*) simp add: issue_expr_load_tmps_range' (*‹load_tmps (issue_expr ?t ?e) = {i. ?t ≤ i ∧ i < ?t + used_tmps ?e}›*)) (*proven 13 subgoals*) . lemma stmt_step_load_tmps_range: assumes step: "θ⊢ (s, t) →⇩s ((s', t'),is)" shows "∀i ∈ load_tmps is. t ≤ i ∧ i < t'" using stmt_step_load_tmps_range'[OF step] (*‹load_tmps is = {i. t ≤ i ∧ i < t'}›*) by auto lemma distinct_load_tmps_issue_expr: "⋀t. distinct_load_tmps (issue_expr t e)" apply (induct e) (*goals: 1. ‹⋀x t. distinct_load_tmps (issue_expr t (Const x))› 2. ‹⋀x1a x2 t. distinct_load_tmps (issue_expr t (Mem x1a x2))› 3. ‹⋀x t. distinct_load_tmps (issue_expr t (Tmp x))› 4. ‹⋀x1a e t. (⋀t. distinct_load_tmps (issue_expr t e)) ⟹ distinct_load_tmps (issue_expr t (Unop x1a e))› 5. ‹⋀x1a e1 e2 t. ⟦⋀t. distinct_load_tmps (issue_expr t e1); ⋀t. distinct_load_tmps (issue_expr t e2)⟧ ⟹ distinct_load_tmps (issue_expr t (Binop x1a e1 e2))› discuss goal 1*) apply ((auto simp add: distinct_load_tmps_append (*‹distinct_load_tmps (?xs @ ?ys) = (distinct_load_tmps ?xs ∧ distinct_load_tmps ?ys ∧ load_tmps ?xs ∩ load_tmps ?ys = {})›*) dest!: issue_expr_load_tmps_range [rule_format] (*‹?i ∈ load_tmps (issue_expr ?t ?e) ⟹ ?t ≤ ?i ∧ ?i < ?t + used_tmps ?e›*))[1]) (*discuss goal 2*) apply ((auto simp add: distinct_load_tmps_append (*‹distinct_load_tmps (?xs @ ?ys) = (distinct_load_tmps ?xs ∧ distinct_load_tmps ?ys ∧ load_tmps ?xs ∩ load_tmps ?ys = {})›*) dest!: issue_expr_load_tmps_range [rule_format] (*‹?i ∈ load_tmps (issue_expr ?t ?e) ⟹ ?t ≤ ?i ∧ ?i < ?t + used_tmps ?e›*))[1]) (*discuss goal 3*) apply ((auto simp add: distinct_load_tmps_append (*‹distinct_load_tmps (?xs @ ?ys) = (distinct_load_tmps ?xs ∧ distinct_load_tmps ?ys ∧ load_tmps ?xs ∩ load_tmps ?ys = {})›*) dest!: issue_expr_load_tmps_range [rule_format] (*‹?i ∈ load_tmps (issue_expr ?t ?e) ⟹ ?t ≤ ?i ∧ ?i < ?t + used_tmps ?e›*))[1]) (*discuss goal 4*) apply ((auto simp add: distinct_load_tmps_append (*‹distinct_load_tmps ((?xs::instr list) @ (?ys::instr list)) = (distinct_load_tmps ?xs ∧ distinct_load_tmps ?ys ∧ load_tmps ?xs ∩ load_tmps ?ys = {})›*) dest!: issue_expr_load_tmps_range [rule_format] (*‹(?i::nat) ∈ load_tmps (issue_expr (?t::nat) (?e::expr)) ⟹ ?t ≤ ?i ∧ ?i < ?t + used_tmps ?e›*))[1]) (*discuss goal 5*) apply ((auto simp add: distinct_load_tmps_append (*‹distinct_load_tmps (?xs @ ?ys) = (distinct_load_tmps ?xs ∧ distinct_load_tmps ?ys ∧ load_tmps ?xs ∩ load_tmps ?ys = {})›*) dest!: issue_expr_load_tmps_range [rule_format] (*‹?i ∈ load_tmps (issue_expr ?t ?e) ⟹ ?t ≤ ?i ∧ ?i < ?t + used_tmps ?e›*))[1]) (*proven 5 subgoals*) . lemma max_used_load_tmps: "t + used_tmps e ∉ load_tmps (issue_expr t e)" proof (-) (*goal: ‹t + used_tmps e ∉ load_tmps (issue_expr t e)›*) from issue_expr_load_tmps_range[rule_format, of "t+used_tmps e"] (*‹t + used_tmps e ∈ load_tmps (issue_expr ?t ?e) ⟹ ?t ≤ t + used_tmps e ∧ t + used_tmps e < ?t + used_tmps ?e›*) show "?thesis" (*goal: ‹t + used_tmps e ∉ load_tmps (issue_expr t e)›*) by auto qed lemma stmt_step_distinct_load_tmps: assumes step: "θ⊢ (s, t) →⇩s ((s', t'),is)" shows "distinct_load_tmps is" using step (*‹(θ::nat ⇒ nat option)⊢ (s::stmt, t::nat) →⇩s ((s'::stmt, t'::nat), is::instr list)›*) apply (induct x=="(s,t)" y=="((s',t'),is)" arbitrary: s t s' t' "is" rule: stmt_step.induct) (*goals: 1. ‹⋀a volatile e A L R W t. ∀sop. a ≠ Tmp sop ⟹ distinct_load_tmps (issue_expr t a)› 2. ‹⋀D volatile a e A L R W t. D ⊆ dom θ ⟹ distinct_load_tmps (issue_expr t e @ [Write volatile (a θ) (eval_expr t e) (A θ) (L θ) (R θ) (W θ)])› 3. ‹⋀a c⇩e s⇩e A L R W t. ∀sop. a ≠ Tmp sop ⟹ distinct_load_tmps (issue_expr t a)› 4. ‹⋀c⇩e D⇩a a s⇩e A L R W t. ∀sop. c⇩e ≠ Tmp sop ⟹ distinct_load_tmps (issue_expr t c⇩e)› 5. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f)⟧ ⟹ distinct_load_tmps (issue_expr t s⇩e @ [RMW (a θ) (t + used_tmps s⇩e) (D, f) (λθ. the (θ (t + used_tmps s⇩e)) = c θ) (λv₁ v₂. v₁) (A θ) (L θ) (R θ) (W θ)])› 6. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); distinct_load_tmps is⟧ ⟹ distinct_load_tmps is› 7. ‹⋀s₂ t. distinct_load_tmps []› 8. ‹⋀e s₁ s₂ t. ∀sop. e ≠ Tmp sop ⟹ distinct_load_tmps (issue_expr t e)› 9. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ)⟧ ⟹ distinct_load_tmps []› 10. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ)⟧ ⟹ distinct_load_tmps []› 11. ‹⋀e s t. distinct_load_tmps []› 12. ‹⋀A L R W t. distinct_load_tmps [Ghost (A θ) (L θ) (R θ) (W θ)]› 13. ‹⋀t. distinct_load_tmps [Fence]› discuss goal 1*) apply (force simp add: distinct_load_tmps_append (*‹distinct_load_tmps (?xs @ ?ys) = (distinct_load_tmps ?xs ∧ distinct_load_tmps ?ys ∧ load_tmps ?xs ∩ load_tmps ?ys = {})›*) distinct_load_tmps_issue_expr (*‹distinct_load_tmps (issue_expr ?t ?e)›*) max_used_load_tmps (*‹?t + used_tmps ?e ∉ load_tmps (issue_expr ?t ?e)›*)) (*discuss goal 2*) apply (force simp add: distinct_load_tmps_append (*‹distinct_load_tmps (?xs @ ?ys) = (distinct_load_tmps ?xs ∧ distinct_load_tmps ?ys ∧ load_tmps ?xs ∩ load_tmps ?ys = {})›*) distinct_load_tmps_issue_expr (*‹distinct_load_tmps (issue_expr ?t ?e)›*) max_used_load_tmps (*‹?t + used_tmps ?e ∉ load_tmps (issue_expr ?t ?e)›*)) (*discuss goal 3*) apply (force simp add: distinct_load_tmps_append (*‹distinct_load_tmps (?xs @ ?ys) = (distinct_load_tmps ?xs ∧ distinct_load_tmps ?ys ∧ load_tmps ?xs ∩ load_tmps ?ys = {})›*) distinct_load_tmps_issue_expr (*‹distinct_load_tmps (issue_expr ?t ?e)›*) max_used_load_tmps (*‹?t + used_tmps ?e ∉ load_tmps (issue_expr ?t ?e)›*)) (*discuss goal 4*) apply (force simp add: distinct_load_tmps_append (*‹distinct_load_tmps (?xs @ ?ys) = (distinct_load_tmps ?xs ∧ distinct_load_tmps ?ys ∧ load_tmps ?xs ∩ load_tmps ?ys = {})›*) distinct_load_tmps_issue_expr (*‹distinct_load_tmps (issue_expr ?t ?e)›*) max_used_load_tmps (*‹?t + used_tmps ?e ∉ load_tmps (issue_expr ?t ?e)›*)) (*discuss goal 5*) apply (force simp add: distinct_load_tmps_append (*‹distinct_load_tmps ((?xs::instr list) @ (?ys::instr list)) = (distinct_load_tmps ?xs ∧ distinct_load_tmps ?ys ∧ load_tmps ?xs ∩ load_tmps ?ys = {})›*) distinct_load_tmps_issue_expr (*‹distinct_load_tmps (issue_expr (?t::nat) (?e::expr))›*) max_used_load_tmps (*‹(?t::nat) + used_tmps (?e::expr) ∉ load_tmps (issue_expr ?t ?e)›*)) (*discuss goal 6*) apply (force simp add: distinct_load_tmps_append (*‹distinct_load_tmps (?xs @ ?ys) = (distinct_load_tmps ?xs ∧ distinct_load_tmps ?ys ∧ load_tmps ?xs ∩ load_tmps ?ys = {})›*) distinct_load_tmps_issue_expr (*‹distinct_load_tmps (issue_expr ?t ?e)›*) max_used_load_tmps (*‹?t + used_tmps ?e ∉ load_tmps (issue_expr ?t ?e)›*)) (*discuss goal 7*) apply (force simp add: distinct_load_tmps_append (*‹distinct_load_tmps (?xs @ ?ys) = (distinct_load_tmps ?xs ∧ distinct_load_tmps ?ys ∧ load_tmps ?xs ∩ load_tmps ?ys = {})›*) distinct_load_tmps_issue_expr (*‹distinct_load_tmps (issue_expr ?t ?e)›*) max_used_load_tmps (*‹?t + used_tmps ?e ∉ load_tmps (issue_expr ?t ?e)›*)) (*discuss goal 8*) apply (force simp add: distinct_load_tmps_append (*‹distinct_load_tmps ((?xs::instr list) @ (?ys::instr list)) = (distinct_load_tmps ?xs ∧ distinct_load_tmps ?ys ∧ load_tmps ?xs ∩ load_tmps ?ys = {})›*) distinct_load_tmps_issue_expr (*‹distinct_load_tmps (issue_expr (?t::nat) (?e::expr))›*) max_used_load_tmps (*‹(?t::nat) + used_tmps (?e::expr) ∉ load_tmps (issue_expr ?t ?e)›*)) (*discuss goal 9*) apply (force simp add: distinct_load_tmps_append (*‹distinct_load_tmps (?xs @ ?ys) = (distinct_load_tmps ?xs ∧ distinct_load_tmps ?ys ∧ load_tmps ?xs ∩ load_tmps ?ys = {})›*) distinct_load_tmps_issue_expr (*‹distinct_load_tmps (issue_expr ?t ?e)›*) max_used_load_tmps (*‹?t + used_tmps ?e ∉ load_tmps (issue_expr ?t ?e)›*)) (*discuss goal 10*) apply (force simp add: distinct_load_tmps_append (*‹distinct_load_tmps (?xs @ ?ys) = (distinct_load_tmps ?xs ∧ distinct_load_tmps ?ys ∧ load_tmps ?xs ∩ load_tmps ?ys = {})›*) distinct_load_tmps_issue_expr (*‹distinct_load_tmps (issue_expr ?t ?e)›*) max_used_load_tmps (*‹?t + used_tmps ?e ∉ load_tmps (issue_expr ?t ?e)›*)) (*discuss goal 11*) apply (force simp add: distinct_load_tmps_append (*‹distinct_load_tmps (?xs @ ?ys) = (distinct_load_tmps ?xs ∧ distinct_load_tmps ?ys ∧ load_tmps ?xs ∩ load_tmps ?ys = {})›*) distinct_load_tmps_issue_expr (*‹distinct_load_tmps (issue_expr ?t ?e)›*) max_used_load_tmps (*‹?t + used_tmps ?e ∉ load_tmps (issue_expr ?t ?e)›*)) (*discuss goal 12*) apply (force simp add: distinct_load_tmps_append (*‹distinct_load_tmps (?xs @ ?ys) = (distinct_load_tmps ?xs ∧ distinct_load_tmps ?ys ∧ load_tmps ?xs ∩ load_tmps ?ys = {})›*) distinct_load_tmps_issue_expr (*‹distinct_load_tmps (issue_expr ?t ?e)›*) max_used_load_tmps (*‹?t + used_tmps ?e ∉ load_tmps (issue_expr ?t ?e)›*)) (*discuss goal 13*) apply (force simp add: distinct_load_tmps_append (*‹distinct_load_tmps (?xs @ ?ys) = (distinct_load_tmps ?xs ∧ distinct_load_tmps ?ys ∧ load_tmps ?xs ∩ load_tmps ?ys = {})›*) distinct_load_tmps_issue_expr (*‹distinct_load_tmps (issue_expr ?t ?e)›*) max_used_load_tmps (*‹?t + used_tmps ?e ∉ load_tmps (issue_expr ?t ?e)›*)) (*proven 13 subgoals*) . lemma store_sops_issue_expr [simp]: "⋀t. store_sops (issue_expr t e) = {}" apply (induct e) (*goals: 1. ‹⋀x t. store_sops (issue_expr t (Const x)) = {}› 2. ‹⋀x1a x2 t. store_sops (issue_expr t (Mem x1a x2)) = {}› 3. ‹⋀x t. store_sops (issue_expr t (Tmp x)) = {}› 4. ‹⋀x1a e t. (⋀t. store_sops (issue_expr t e) = {}) ⟹ store_sops (issue_expr t (Unop x1a e)) = {}› 5. ‹⋀x1a e1 e2 t. ⟦⋀t. store_sops (issue_expr t e1) = {}; ⋀t. store_sops (issue_expr t e2) = {}⟧ ⟹ store_sops (issue_expr t (Binop x1a e1 e2)) = {}› discuss goal 1*) apply ((auto simp add: store_sops_append (*‹store_sops (?xs @ ?ys) = store_sops ?xs ∪ store_sops ?ys›*))[1]) (*discuss goal 2*) apply ((auto simp add: store_sops_append (*‹store_sops (?xs @ ?ys) = store_sops ?xs ∪ store_sops ?ys›*))[1]) (*discuss goal 3*) apply ((auto simp add: store_sops_append (*‹store_sops (?xs @ ?ys) = store_sops ?xs ∪ store_sops ?ys›*))[1]) (*discuss goal 4*) apply ((auto simp add: store_sops_append (*‹store_sops (?xs @ ?ys) = store_sops ?xs ∪ store_sops ?ys›*))[1]) (*discuss goal 5*) apply ((auto simp add: store_sops_append (*‹store_sops (?xs @ ?ys) = store_sops ?xs ∪ store_sops ?ys›*))[1]) (*proven 5 subgoals*) . lemma stmt_step_data_store_sops_range: assumes step: "θ⊢ (s, t) →⇩s ((s', t'),is)" assumes valid: "valid_sops_stmt t s" shows "∀(D,f) ∈ store_sops is. ∀i ∈ D. i < t'" using step (*‹(θ::nat ⇒ nat option)⊢ (s::stmt, t::nat) →⇩s ((s'::stmt, t'::nat), is::instr list)›*) valid (*‹valid_sops_stmt t s›*) proof (induct x=="(s,t)" y=="((s',t'),is)" arbitrary: s t s' t' "is" rule: stmt_step.induct) (*goals: 1. ‹⋀a volatile e A L R W t. ⟦∀sop. a ≠ Tmp sop; valid_sops_stmt t (Assign volatile a e A L R W)⟧ ⟹ ∀(D, f)∈store_sops (issue_expr t a). ∀i∈D. i < t + used_tmps a› 2. ‹⋀D volatile a e A L R W t. ⟦D ⊆ dom θ; valid_sops_stmt t (Assign volatile (Tmp (D, a)) e A L R W)⟧ ⟹ ∀(D, f)∈store_sops (issue_expr t e @ [Write volatile (a θ) (eval_expr t e) (A θ) (L θ) (R θ) (W θ)]). ∀i∈D. i < t + used_tmps e› 3. ‹⋀a c⇩e s⇩e A L R W t. ⟦∀sop. a ≠ Tmp sop; valid_sops_stmt t (CAS a c⇩e s⇩e A L R W)⟧ ⟹ ∀(D, f)∈store_sops (issue_expr t a). ∀i∈D. i < t + used_tmps a› 4. ‹⋀c⇩e D⇩a a s⇩e A L R W t. ⟦∀sop. c⇩e ≠ Tmp sop; valid_sops_stmt t (CAS (Tmp (D⇩a, a)) c⇩e s⇩e A L R W)⟧ ⟹ ∀(D, f)∈store_sops (issue_expr t c⇩e). ∀i∈D. i < t + used_tmps c⇩e› 5. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f); valid_sops_stmt t (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W)⟧ ⟹ ∀(D, f)∈store_sops (issue_expr t s⇩e @ [RMW (a θ) (t + used_tmps s⇩e) (D, f) (λθ. the (θ (t + used_tmps s⇩e)) = c θ) (λv₁ v₂. v₁) (A θ) (L θ) (R θ) (W θ)]). ∀i∈D. i < Suc (t + used_tmps s⇩e)› 6. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ ∀(D, f)∈store_sops is. ∀i∈D. i < t'; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops is. ∀i∈D. i < t'› 7. ‹⋀s₂ t. valid_sops_stmt t (Seq Skip s₂) ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 8. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops (issue_expr t e). ∀i∈D. i < t + used_tmps e› 9. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 10. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 11. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 12. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ ∀(D, f)∈store_sops [Ghost (A θ) (L θ) (R θ) (W θ)]. ∀i∈D. i < t› 13. ‹⋀t. valid_sops_stmt t SFence ⟹ ∀(D, f)∈store_sops [Fence]. ∀i∈D. i < t›*) case AssignAddr (*‹∀sop. a_ ≠ Tmp sop› ‹valid_sops_stmt (t_::nat) (Assign (volatile_::bool) (a_::expr) (e_::expr) (A_::(nat ⇒ nat option) ⇒ nat set) (L_::(nat ⇒ nat option) ⇒ nat set) (R_::(nat ⇒ nat option) ⇒ nat set) (W_::(nat ⇒ nat option) ⇒ nat set))›*) thus "?case" (*goal: ‹∀(D, f)∈store_sops (issue_expr t_ a_). ∀i∈D. i < t_ + used_tmps a_›*) by auto next (*goals: 1. ‹⋀D volatile a e A L R W t. ⟦D ⊆ dom θ; valid_sops_stmt t (Assign volatile (Tmp (D, a)) e A L R W)⟧ ⟹ ∀(D, f)∈store_sops (issue_expr t e @ [Write volatile (a θ) (eval_expr t e) (A θ) (L θ) (R θ) (W θ)]). ∀i∈D. i < t + used_tmps e› 2. ‹⋀a c⇩e s⇩e A L R W t. ⟦∀sop. a ≠ Tmp sop; valid_sops_stmt t (CAS a c⇩e s⇩e A L R W)⟧ ⟹ ∀(D, f)∈store_sops (issue_expr t a). ∀i∈D. i < t + used_tmps a› 3. ‹⋀c⇩e D⇩a a s⇩e A L R W t. ⟦∀sop. c⇩e ≠ Tmp sop; valid_sops_stmt t (CAS (Tmp (D⇩a, a)) c⇩e s⇩e A L R W)⟧ ⟹ ∀(D, f)∈store_sops (issue_expr t c⇩e). ∀i∈D. i < t + used_tmps c⇩e› 4. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f); valid_sops_stmt t (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W)⟧ ⟹ ∀(D, f)∈store_sops (issue_expr t s⇩e @ [RMW (a θ) (t + used_tmps s⇩e) (D, f) (λθ. the (θ (t + used_tmps s⇩e)) = c θ) (λv₁ v₂. v₁) (A θ) (L θ) (R θ) (W θ)]). ∀i∈D. i < Suc (t + used_tmps s⇩e)› 5. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ ∀(D, f)∈store_sops is. ∀i∈D. i < t'; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops is. ∀i∈D. i < t'› 6. ‹⋀s₂ t. valid_sops_stmt t (Seq Skip s₂) ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 7. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops (issue_expr t e). ∀i∈D. i < t + used_tmps e› 8. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 9. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 10. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 11. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ ∀(D, f)∈store_sops [Ghost (A θ) (L θ) (R θ) (W θ)]. ∀i∈D. i < t› 12. ‹⋀t. valid_sops_stmt t SFence ⟹ ∀(D, f)∈store_sops [Fence]. ∀i∈D. i < t›*) case (Assign D volatile a e) (*‹D ⊆ dom θ› ‹valid_sops_stmt t_ (Assign volatile (Tmp (D, a)) e A_ L_ R_ W_)›*) thus "?case" (*goal: ‹∀(D, f)∈store_sops (issue_expr t_ e @ [Write volatile (a θ) (eval_expr t_ e) (A_ θ) (L_ θ) (R_ θ) (W_ θ)]). ∀i∈D. i < t_ + used_tmps e›*) apply (cases "eval_expr t e") (*goal: ‹∀(D, f)∈store_sops (issue_expr t_ e @ [Write volatile (a θ) (eval_expr t_ e) (A_ θ) (L_ θ) (R_ θ) (W_ θ)]). ∀i∈D. i < t_ + used_tmps e›*) by (auto simp add: store_sops_append (*‹store_sops (?xs @ ?ys) = store_sops ?xs ∪ store_sops ?ys›*) intro: valid_sops_expr_eval_expr_in_range [rule_format] (*‹⟦valid_sops_expr ?t ?e; ?t' ∈ fst (eval_expr ?t ?e)⟧ ⟹ ?t' < ?t + used_tmps ?e›*)) next (*goals: 1. ‹⋀a c⇩e s⇩e A L R W t. ⟦∀sop. a ≠ Tmp sop; valid_sops_stmt t (CAS a c⇩e s⇩e A L R W)⟧ ⟹ ∀(D, f)∈store_sops (issue_expr t a). ∀i∈D. i < t + used_tmps a› 2. ‹⋀c⇩e D⇩a a s⇩e A L R W t. ⟦∀sop. c⇩e ≠ Tmp sop; valid_sops_stmt t (CAS (Tmp (D⇩a, a)) c⇩e s⇩e A L R W)⟧ ⟹ ∀(D, f)∈store_sops (issue_expr t c⇩e). ∀i∈D. i < t + used_tmps c⇩e› 3. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f); valid_sops_stmt t (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W)⟧ ⟹ ∀(D, f)∈store_sops (issue_expr t s⇩e @ [RMW (a θ) (t + used_tmps s⇩e) (D, f) (λθ. the (θ (t + used_tmps s⇩e)) = c θ) (λv₁ v₂. v₁) (A θ) (L θ) (R θ) (W θ)]). ∀i∈D. i < Suc (t + used_tmps s⇩e)› 4. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ ∀(D, f)∈store_sops is. ∀i∈D. i < t'; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops is. ∀i∈D. i < t'› 5. ‹⋀s₂ t. valid_sops_stmt t (Seq Skip s₂) ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 6. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops (issue_expr t e). ∀i∈D. i < t + used_tmps e› 7. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 8. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 9. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 10. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ ∀(D, f)∈store_sops [Ghost (A θ) (L θ) (R θ) (W θ)]. ∀i∈D. i < t› 11. ‹⋀t. valid_sops_stmt t SFence ⟹ ∀(D, f)∈store_sops [Fence]. ∀i∈D. i < t›*) case CASAddr (*‹∀sop::nat set × ((nat ⇒ nat option) ⇒ nat). (a_::expr) ≠ Tmp sop› ‹valid_sops_stmt t_ (CAS a_ c⇩e_ s⇩e_ A_ L_ R_ W_)›*) thus "?case" (*goal: ‹∀(D, f)∈store_sops (issue_expr t_ a_). ∀i∈D. i < t_ + used_tmps a_›*) by auto next (*goals: 1. ‹⋀c⇩e D⇩a a s⇩e A L R W t. ⟦∀sop. c⇩e ≠ Tmp sop; valid_sops_stmt t (CAS (Tmp (D⇩a, a)) c⇩e s⇩e A L R W)⟧ ⟹ ∀(D, f)∈store_sops (issue_expr t c⇩e). ∀i∈D. i < t + used_tmps c⇩e› 2. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f); valid_sops_stmt t (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W)⟧ ⟹ ∀(D, f)∈store_sops (issue_expr t s⇩e @ [RMW (a θ) (t + used_tmps s⇩e) (D, f) (λθ. the (θ (t + used_tmps s⇩e)) = c θ) (λv₁ v₂. v₁) (A θ) (L θ) (R θ) (W θ)]). ∀i∈D. i < Suc (t + used_tmps s⇩e)› 3. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ ∀(D, f)∈store_sops is. ∀i∈D. i < t'; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops is. ∀i∈D. i < t'› 4. ‹⋀s₂ t. valid_sops_stmt t (Seq Skip s₂) ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 5. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops (issue_expr t e). ∀i∈D. i < t + used_tmps e› 6. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 7. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 8. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 9. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ ∀(D, f)∈store_sops [Ghost (A θ) (L θ) (R θ) (W θ)]. ∀i∈D. i < t› 10. ‹⋀t. valid_sops_stmt t SFence ⟹ ∀(D, f)∈store_sops [Fence]. ∀i∈D. i < t›*) case CASComp (*‹∀sop. c⇩e_ ≠ Tmp sop› ‹valid_sops_stmt (t_::nat) (CAS (Tmp (D⇩a_::nat set, a_::(nat ⇒ nat option) ⇒ nat)) (c⇩e_::expr) (s⇩e_::expr) (A_::(nat ⇒ nat option) ⇒ nat set) (L_::(nat ⇒ nat option) ⇒ nat set) (R_::(nat ⇒ nat option) ⇒ nat set) (W_::(nat ⇒ nat option) ⇒ nat set))›*) thus "?case" (*goal: ‹∀(D, f)∈store_sops (issue_expr t_ c⇩e_). ∀i∈D. i < t_ + used_tmps c⇩e_›*) by auto next (*goals: 1. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f); valid_sops_stmt t (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W)⟧ ⟹ ∀(D, f)∈store_sops (issue_expr t s⇩e @ [RMW (a θ) (t + used_tmps s⇩e) (D, f) (λθ. the (θ (t + used_tmps s⇩e)) = c θ) (λv₁ v₂. v₁) (A θ) (L θ) (R θ) (W θ)]). ∀i∈D. i < Suc (t + used_tmps s⇩e)› 2. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ ∀(D, f)∈store_sops is. ∀i∈D. i < t'; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops is. ∀i∈D. i < t'› 3. ‹⋀s₂ t. valid_sops_stmt t (Seq Skip s₂) ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 4. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops (issue_expr t e). ∀i∈D. i < t + used_tmps e› 5. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 6. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 7. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 8. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ ∀(D, f)∈store_sops [Ghost (A θ) (L θ) (R θ) (W θ)]. ∀i∈D. i < t› 9. ‹⋀t. valid_sops_stmt t SFence ⟹ ∀(D, f)∈store_sops [Fence]. ∀i∈D. i < t›*) case (CAS__ D f a A L R) (*‹(D⇩a_::nat set) ⊆ dom (θ::nat ⇒ nat option)› ‹D⇩c_ ⊆ dom θ› ‹eval_expr (D::nat) (f::expr) = (a::nat set, A::(nat ⇒ nat option) ⇒ nat)› ‹valid_sops_stmt D (CAS (Tmp (D⇩a_, L)) (Tmp (D⇩c_, R)) f A_ L_ R_ W_)›*) thus "?case" (*goal: ‹∀(Da::nat set, fa::(nat ⇒ nat option) ⇒ nat)∈store_sops (issue_expr (D::nat) (f::expr) @ [RMW ((L::(nat ⇒ nat option) ⇒ nat) (θ::nat ⇒ nat option)) (D + used_tmps f) (a::nat set, A::(nat ⇒ nat option) ⇒ nat) (λθ::nat ⇒ nat option. the (θ (D + used_tmps f)) = (R::(nat ⇒ nat option) ⇒ nat) θ) (λ(v₁::nat) v₂::nat. v₁) ((A_::(nat ⇒ nat option) ⇒ nat set) θ) ((L_::(nat ⇒ nat option) ⇒ nat set) θ) ((R_::(nat ⇒ nat option) ⇒ nat set) θ) ((W_::(nat ⇒ nat option) ⇒ nat set) θ)]). ∀i::nat∈Da. i < Suc (D + used_tmps f)›*) by (fastforce simp add: store_sops_append (*‹store_sops (?xs @ ?ys) = store_sops ?xs ∪ store_sops ?ys›*) dest: valid_sops_expr_eval_expr_in_range [rule_format] (*‹⟦valid_sops_expr ?t ?e; ?t' ∈ fst (eval_expr ?t ?e)⟧ ⟹ ?t' < ?t + used_tmps ?e›*)) next (*goals: 1. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ ∀(D, f)∈store_sops is. ∀i∈D. i < t'; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops is. ∀i∈D. i < t'› 2. ‹⋀s₂ t. valid_sops_stmt t (Seq Skip s₂) ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 3. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops (issue_expr t e). ∀i∈D. i < t + used_tmps e› 4. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 5. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 6. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 7. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ ∀(D, f)∈store_sops [Ghost (A θ) (L θ) (R θ) (W θ)]. ∀i∈D. i < t› 8. ‹⋀t. valid_sops_stmt t SFence ⟹ ∀(D, f)∈store_sops [Fence]. ∀i∈D. i < t›*) case Seq (*‹θ⊢ (s₁_, t_) →⇩s ((s₁'_, t'_), is_)› ‹valid_sops_stmt t_ s₁_ ⟹ ∀(D, f)∈store_sops is_. ∀i∈D. i < t'_› ‹valid_sops_stmt t_ (Seq s₁_ s₂_)›*) thus "?case" (*goal: ‹∀(D, f)∈store_sops is_. ∀i∈D. i < t'_›*) by (force intro: valid_sops_stmt_mono (*‹⟦valid_sops_stmt ?t ?s; ?t ≤ ?t'⟧ ⟹ valid_sops_stmt ?t' ?s›*)) next (*goals: 1. ‹⋀s₂ t. valid_sops_stmt t (Seq Skip s₂) ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 2. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops (issue_expr t e). ∀i∈D. i < t + used_tmps e› 3. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 4. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 5. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 6. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ ∀(D, f)∈store_sops [Ghost (A θ) (L θ) (R θ) (W θ)]. ∀i∈D. i < t› 7. ‹⋀t. valid_sops_stmt t SFence ⟹ ∀(D, f)∈store_sops [Fence]. ∀i∈D. i < t›*) case SeqSkip (*‹valid_sops_stmt t_ (Seq Skip s₂_)›*) thus "?case" (*goal: ‹∀(D, f)∈store_sops []. ∀i∈D. i < t_›*) by simp next (*goals: 1. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops (issue_expr t e). ∀i∈D. i < t + used_tmps e› 2. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 3. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 4. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 5. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ ∀(D, f)∈store_sops [Ghost (A θ) (L θ) (R θ) (W θ)]. ∀i∈D. i < t› 6. ‹⋀t. valid_sops_stmt t SFence ⟹ ∀(D, f)∈store_sops [Fence]. ∀i∈D. i < t›*) case Cond (*‹∀sop. e_ ≠ Tmp sop› ‹valid_sops_stmt (t_::nat) (Cond (e_::expr) (s₁_::stmt) (s₂_::stmt))›*) thus "?case" (*goal: ‹∀(D, f)∈store_sops (issue_expr t_ e_). ∀i∈D. i < t_ + used_tmps e_›*) by auto next (*goals: 1. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 2. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 3. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 4. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ ∀(D, f)∈store_sops [Ghost (A θ) (L θ) (R θ) (W θ)]. ∀i∈D. i < t› 5. ‹⋀t. valid_sops_stmt t SFence ⟹ ∀(D, f)∈store_sops [Fence]. ∀i∈D. i < t›*) case CondTrue (*‹(D_::nat set) ⊆ dom (θ::nat ⇒ nat option)› ‹isTrue (e_ θ)› ‹valid_sops_stmt t_ (Cond (Tmp (D_, e_)) s₁_ s₂_)›*) thus "?case" (*goal: ‹∀(D, f)∈store_sops []. ∀i∈D. i < t_›*) by auto next (*goals: 1. ‹⋀(D::nat set) (e::(nat ⇒ nat option) ⇒ nat) (s₁::stmt) (s₂::stmt) t::nat. ⟦D ⊆ dom (θ::nat ⇒ nat option); ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ ∀(D::nat set, f::(nat ⇒ nat option) ⇒ nat)∈store_sops []. ∀i::nat∈D. i < t› 2. ‹⋀(e::expr) (s::stmt) t::nat. valid_sops_stmt t (While e s) ⟹ ∀(D::nat set, f::(nat ⇒ nat option) ⇒ nat)∈store_sops []. ∀i::nat∈D. i < t› 3. ‹⋀(A::(nat ⇒ nat option) ⇒ nat set) (L::(nat ⇒ nat option) ⇒ nat set) (R::(nat ⇒ nat option) ⇒ nat set) (W::(nat ⇒ nat option) ⇒ nat set) t::nat. valid_sops_stmt t (SGhost A L R W) ⟹ ∀(D::nat set, f::(nat ⇒ nat option) ⇒ nat)∈store_sops [Ghost (A (θ::nat ⇒ nat option)) (L θ) (R θ) (W θ)]. ∀i::nat∈D. i < t› 4. ‹⋀t::nat. valid_sops_stmt t SFence ⟹ ∀(D::nat set, f::(nat ⇒ nat option) ⇒ nat)∈store_sops [Fence]. ∀i::nat∈D. i < t›*) case CondFalse (*‹D_ ⊆ dom θ› ‹¬ isTrue (e_ θ)› ‹valid_sops_stmt t_ (Cond (Tmp (D_, e_)) s₁_ s₂_)›*) thus "?case" (*goal: ‹∀(D, f)∈store_sops []. ∀i∈D. i < t_›*) by auto next (*goals: 1. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ ∀(D, f)∈store_sops []. ∀i∈D. i < t› 2. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ ∀(D, f)∈store_sops [Ghost (A θ) (L θ) (R θ) (W θ)]. ∀i∈D. i < t› 3. ‹⋀t. valid_sops_stmt t SFence ⟹ ∀(D, f)∈store_sops [Fence]. ∀i∈D. i < t›*) case While (*‹valid_sops_stmt (t_::nat) (While (e_::expr) (s_::stmt))›*) thus "?case" (*goal: ‹∀(D, f)∈store_sops []. ∀i∈D. i < t_›*) by auto next (*goals: 1. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ ∀(D, f)∈store_sops [Ghost (A θ) (L θ) (R θ) (W θ)]. ∀i∈D. i < t› 2. ‹⋀t. valid_sops_stmt t SFence ⟹ ∀(D, f)∈store_sops [Fence]. ∀i∈D. i < t›*) case SGhost (*‹valid_sops_stmt (t_::nat) (SGhost (A_::(nat ⇒ nat option) ⇒ nat set) (L_::(nat ⇒ nat option) ⇒ nat set) (R_::(nat ⇒ nat option) ⇒ nat set) (W_::(nat ⇒ nat option) ⇒ nat set))›*) thus "?case" (*goal: ‹∀(D::nat set, f::(nat ⇒ nat option) ⇒ nat)∈store_sops [Ghost ((A_::(nat ⇒ nat option) ⇒ nat set) (θ::nat ⇒ nat option)) ((L_::(nat ⇒ nat option) ⇒ nat set) θ) ((R_::(nat ⇒ nat option) ⇒ nat set) θ) ((W_::(nat ⇒ nat option) ⇒ nat set) θ)]. ∀i::nat∈D. i < (t_::nat)›*) by auto next (*goal: ‹⋀t. valid_sops_stmt t SFence ⟹ ∀(D, f)∈store_sops [Fence]. ∀i∈D. i < t›*) case SFence (*‹valid_sops_stmt t_ SFence›*) thus "?case" (*goal: ‹∀(D, f)∈store_sops [Fence]. ∀i∈D. i < t_›*) by auto qed lemma sbh_step_distinct_load_tmps_prog_step: assumes step: "θ⊢(s,t) →⇩s ((s',t'),is')" assumes load_tmps_le: "∀i ∈ load_tmps is. i < t" assumes read_tmps_le: "∀i ∈ read_tmps sb. i < t" shows "distinct_load_tmps is' ∧ (load_tmps is' ∩ load_tmps is = {}) ∧ (load_tmps is' ∩ read_tmps sb) = {}" proof (-) (*goal: ‹distinct_load_tmps (is'::instr list) ∧ load_tmps is' ∩ load_tmps (is::instr list) = {} ∧ load_tmps is' ∩ read_tmps (sb::'a::type memref list) = {}›*) from stmt_step_load_tmps_range[OF step] (*‹∀i∈load_tmps is'. t ≤ i ∧ i < t'›*) stmt_step_distinct_load_tmps[OF step] (*‹distinct_load_tmps is'›*) load_tmps_le (*‹∀i∈load_tmps is. i < t›*) read_tmps_le (*‹∀i∈read_tmps sb. i < t›*) show "?thesis" (*goal: ‹distinct_load_tmps (is'::instr list) ∧ load_tmps is' ∩ load_tmps (is::instr list) = {} ∧ load_tmps is' ∩ read_tmps (sb::'a::type memref list) = {}›*) by force qed lemma data_dependency_consistent_instrs_issue_expr: "⋀t T. data_dependency_consistent_instrs T (issue_expr t e)" apply (induct e) (*goals: 1. ‹⋀x t T. data_dependency_consistent_instrs T (issue_expr t (Const x))› 2. ‹⋀x1a x2 t T. data_dependency_consistent_instrs T (issue_expr t (Mem x1a x2))› 3. ‹⋀x t T. data_dependency_consistent_instrs T (issue_expr t (Tmp x))› 4. ‹⋀x1a e t T. (⋀t T. data_dependency_consistent_instrs T (issue_expr t e)) ⟹ data_dependency_consistent_instrs T (issue_expr t (Unop x1a e))› 5. ‹⋀x1a e1 e2 t T. ⟦⋀t T. data_dependency_consistent_instrs T (issue_expr t e1); ⋀t T. data_dependency_consistent_instrs T (issue_expr t e2)⟧ ⟹ data_dependency_consistent_instrs T (issue_expr t (Binop x1a e1 e2))› discuss goal 1*) apply ((auto simp add: data_dependency_consistent_instrs_append (*‹data_dependency_consistent_instrs ?T (?xs @ ?ys) = (data_dependency_consistent_instrs ?T ?xs ∧ data_dependency_consistent_instrs (?T ∪ load_tmps ?xs) ?ys ∧ load_tmps ?ys ∩ ⋃ (fst ` store_sops ?xs) = {})›*) dest!: issue_expr_load_tmps_range [rule_format] (*‹?i ∈ load_tmps (issue_expr ?t ?e) ⟹ ?t ≤ ?i ∧ ?i < ?t + used_tmps ?e›*))[1]) (*discuss goal 2*) apply ((auto simp add: data_dependency_consistent_instrs_append (*‹data_dependency_consistent_instrs ?T (?xs @ ?ys) = (data_dependency_consistent_instrs ?T ?xs ∧ data_dependency_consistent_instrs (?T ∪ load_tmps ?xs) ?ys ∧ load_tmps ?ys ∩ ⋃ (fst ` store_sops ?xs) = {})›*) dest!: issue_expr_load_tmps_range [rule_format] (*‹?i ∈ load_tmps (issue_expr ?t ?e) ⟹ ?t ≤ ?i ∧ ?i < ?t + used_tmps ?e›*))[1]) (*discuss goal 3*) apply ((auto simp add: data_dependency_consistent_instrs_append (*‹data_dependency_consistent_instrs ?T (?xs @ ?ys) = (data_dependency_consistent_instrs ?T ?xs ∧ data_dependency_consistent_instrs (?T ∪ load_tmps ?xs) ?ys ∧ load_tmps ?ys ∩ ⋃ (fst ` store_sops ?xs) = {})›*) dest!: issue_expr_load_tmps_range [rule_format] (*‹?i ∈ load_tmps (issue_expr ?t ?e) ⟹ ?t ≤ ?i ∧ ?i < ?t + used_tmps ?e›*))[1]) (*discuss goal 4*) apply ((auto simp add: data_dependency_consistent_instrs_append (*‹data_dependency_consistent_instrs (?T::nat set) ((?xs::instr list) @ (?ys::instr list)) = (data_dependency_consistent_instrs ?T ?xs ∧ data_dependency_consistent_instrs (?T ∪ load_tmps ?xs) ?ys ∧ load_tmps ?ys ∩ ⋃ (fst ` store_sops ?xs) = {})›*) dest!: issue_expr_load_tmps_range [rule_format] (*‹(?i::nat) ∈ load_tmps (issue_expr (?t::nat) (?e::expr)) ⟹ ?t ≤ ?i ∧ ?i < ?t + used_tmps ?e›*))[1]) (*discuss goal 5*) apply ((auto simp add: data_dependency_consistent_instrs_append (*‹data_dependency_consistent_instrs ?T (?xs @ ?ys) = (data_dependency_consistent_instrs ?T ?xs ∧ data_dependency_consistent_instrs (?T ∪ load_tmps ?xs) ?ys ∧ load_tmps ?ys ∩ ⋃ (fst ` store_sops ?xs) = {})›*) dest!: issue_expr_load_tmps_range [rule_format] (*‹?i ∈ load_tmps (issue_expr ?t ?e) ⟹ ?t ≤ ?i ∧ ?i < ?t + used_tmps ?e›*))[1]) (*proven 5 subgoals*) . lemma dom_eval_expr: "⋀t. ⟦valid_sops_expr t e; x ∈ fst (eval_expr t e)⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t e)" proof (induct e) (*goals: 1. ‹⋀xa t. ⟦valid_sops_expr t (Const xa); x ∈ fst (eval_expr t (Const xa))⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t (Const xa))› 2. ‹⋀x1a x2 t. ⟦valid_sops_expr t (Mem x1a x2); x ∈ fst (eval_expr t (Mem x1a x2))⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t (Mem x1a x2))› 3. ‹⋀xa t. ⟦valid_sops_expr t (Tmp xa); x ∈ fst (eval_expr t (Tmp xa))⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t (Tmp xa))› 4. ‹⋀x1a e t. ⟦⋀t. ⟦valid_sops_expr t e; x ∈ fst (eval_expr t e)⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t e); valid_sops_expr t (Unop x1a e); x ∈ fst (eval_expr t (Unop x1a e))⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t (Unop x1a e))› 5. ‹⋀x1a e1 e2 t. ⟦⋀t. ⟦valid_sops_expr t e1; x ∈ fst (eval_expr t e1)⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t e1); ⋀t. ⟦valid_sops_expr t e2; x ∈ fst (eval_expr t e2)⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t e2); valid_sops_expr t (Binop x1a e1 e2); x ∈ fst (eval_expr t (Binop x1a e1 e2))⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t (Binop x1a e1 e2))›*) case Const (*‹valid_sops_expr t (Const x_)› ‹x ∈ fst (eval_expr t (Const x_))›*) thus "?case" (*goal: ‹x ∈ {i. i < t} ∪ load_tmps (issue_expr t (Const x_))›*) by simp next (*goals: 1. ‹⋀x1a x2 t. ⟦valid_sops_expr t (Mem x1a x2); x ∈ fst (eval_expr t (Mem x1a x2))⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t (Mem x1a x2))› 2. ‹⋀xa t. ⟦valid_sops_expr t (Tmp xa); x ∈ fst (eval_expr t (Tmp xa))⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t (Tmp xa))› 3. ‹⋀x1a e t. ⟦⋀t. ⟦valid_sops_expr t e; x ∈ fst (eval_expr t e)⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t e); valid_sops_expr t (Unop x1a e); x ∈ fst (eval_expr t (Unop x1a e))⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t (Unop x1a e))› 4. ‹⋀x1a e1 e2 t. ⟦⋀t. ⟦valid_sops_expr t e1; x ∈ fst (eval_expr t e1)⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t e1); ⋀t. ⟦valid_sops_expr t e2; x ∈ fst (eval_expr t e2)⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t e2); valid_sops_expr t (Binop x1a e1 e2); x ∈ fst (eval_expr t (Binop x1a e1 e2))⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t (Binop x1a e1 e2))›*) case Mem (*‹valid_sops_expr t (Mem x1a_ x2_)› ‹x ∈ fst (eval_expr t (Mem x1a_ x2_))›*) thus "?case" (*goal: ‹x ∈ {i. i < t} ∪ load_tmps (issue_expr t (Mem x1a_ x2_))›*) by simp next (*goals: 1. ‹⋀xa t. ⟦valid_sops_expr t (Tmp xa); x ∈ fst (eval_expr t (Tmp xa))⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t (Tmp xa))› 2. ‹⋀x1a e t. ⟦⋀t. ⟦valid_sops_expr t e; x ∈ fst (eval_expr t e)⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t e); valid_sops_expr t (Unop x1a e); x ∈ fst (eval_expr t (Unop x1a e))⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t (Unop x1a e))› 3. ‹⋀x1a e1 e2 t. ⟦⋀t. ⟦valid_sops_expr t e1; x ∈ fst (eval_expr t e1)⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t e1); ⋀t. ⟦valid_sops_expr t e2; x ∈ fst (eval_expr t e2)⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t e2); valid_sops_expr t (Binop x1a e1 e2); x ∈ fst (eval_expr t (Binop x1a e1 e2))⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t (Binop x1a e1 e2))›*) case Tmp (*‹valid_sops_expr t (Tmp x_)› ‹x ∈ fst (eval_expr t (Tmp x_))›*) thus "?case" (*goal: ‹x ∈ {i. i < t} ∪ load_tmps (issue_expr t (Tmp x_))›*) by simp next (*goals: 1. ‹⋀x1a e t. ⟦⋀t. ⟦valid_sops_expr t e; x ∈ fst (eval_expr t e)⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t e); valid_sops_expr t (Unop x1a e); x ∈ fst (eval_expr t (Unop x1a e))⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t (Unop x1a e))› 2. ‹⋀x1a e1 e2 t. ⟦⋀t. ⟦valid_sops_expr t e1; x ∈ fst (eval_expr t e1)⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t e1); ⋀t. ⟦valid_sops_expr t e2; x ∈ fst (eval_expr t e2)⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t e2); valid_sops_expr t (Binop x1a e1 e2); x ∈ fst (eval_expr t (Binop x1a e1 e2))⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t (Binop x1a e1 e2))›*) case (Unop f e) (*‹⟦valid_sops_expr (?t::nat) (e::expr); (x::nat) ∈ fst (eval_expr ?t e)⟧ ⟹ x ∈ {i::nat. i < ?t} ∪ load_tmps (issue_expr ?t e)› ‹valid_sops_expr t (Unop f e)› ‹x ∈ fst (eval_expr t (Unop f e))›*) thus "?case" (*goal: ‹(x::nat) ∈ {i::nat. i < (t::nat)} ∪ load_tmps (issue_expr t (Unop (f::nat ⇒ nat) (e::expr)))›*) apply (cases "eval_expr t e") (*goal: ‹x ∈ {i. i < t} ∪ load_tmps (issue_expr t (Unop f e))›*) by auto next (*goal: ‹⋀x1a e1 e2 t. ⟦⋀t. ⟦valid_sops_expr t e1; x ∈ fst (eval_expr t e1)⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t e1); ⋀t. ⟦valid_sops_expr t e2; x ∈ fst (eval_expr t e2)⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t e2); valid_sops_expr t (Binop x1a e1 e2); x ∈ fst (eval_expr t (Binop x1a e1 e2))⟧ ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t (Binop x1a e1 e2))›*) case (Binop f e1 e2) (*‹⟦valid_sops_expr ?t e1; x ∈ fst (eval_expr ?t e1)⟧ ⟹ x ∈ {i. i < ?t} ∪ load_tmps (issue_expr ?t e1)› ‹⟦valid_sops_expr ?t e2; x ∈ fst (eval_expr ?t e2)⟧ ⟹ x ∈ {i. i < ?t} ∪ load_tmps (issue_expr ?t e2)› ‹valid_sops_expr (t::nat) (Binop (f::nat ⇒ nat ⇒ nat) (e1::expr) (e2::expr))› ‹x ∈ fst (eval_expr t (Binop f e1 e2))›*) then obtain valid1: "valid_sops_expr t e1" and valid2: "valid_sops_expr t e2" (*goal: ‹(⟦valid_sops_expr t e1; valid_sops_expr t e2⟧ ⟹ thesis) ⟹ thesis›*) by auto from valid_sops_expr_mono[OF valid2] (*‹(t::nat) ≤ (?t'::nat) ⟹ valid_sops_expr ?t' (e2::expr)›*) have valid2': "valid_sops_expr (t+used_tmps e1) e2" by auto from Binop.hyps(1)[OF valid1] (*‹x ∈ fst (eval_expr t e1) ⟹ x ∈ {i. i < t} ∪ load_tmps (issue_expr t e1)›*) Binop.hyps(2)[OF valid2'] (*‹x ∈ fst (eval_expr (t + used_tmps e1) e2) ⟹ x ∈ {i. i < t + used_tmps e1} ∪ load_tmps (issue_expr (t + used_tmps e1) e2)›*) Binop.prems (*‹valid_sops_expr (t::nat) (Binop (f::nat ⇒ nat ⇒ nat) (e1::expr) (e2::expr))› ‹x ∈ fst (eval_expr t (Binop f e1 e2))›*) show "?case" (*goal: ‹x ∈ {i. i < t} ∪ load_tmps (issue_expr t (Binop f e1 e2))›*) apply (case_tac "eval_expr t e1") (*goal: ‹x ∈ {i. i < t} ∪ load_tmps (issue_expr t (Binop f e1 e2))›*) apply (case_tac "eval_expr (t+used_tmps e1) e2") (*goal: ‹⋀(a::nat set) b::(nat ⇒ nat option) ⇒ nat. ⟦(x::nat) ∈ fst (eval_expr (t::nat) (e1::expr)) ⟹ x ∈ {i::nat. i < t} ∪ load_tmps (issue_expr t e1); x ∈ fst (eval_expr (t + used_tmps e1) (e2::expr)) ⟹ x ∈ {i::nat. i < t + used_tmps e1} ∪ load_tmps (issue_expr (t + used_tmps e1) e2); valid_sops_expr t (Binop (f::nat ⇒ nat ⇒ nat) e1 e2); x ∈ fst (eval_expr t (Binop f e1 e2)); eval_expr t e1 = (a, b)⟧ ⟹ x ∈ {i::nat. i < t} ∪ load_tmps (issue_expr t (Binop f e1 e2))›*) by (auto simp add: load_tmps_append (*‹load_tmps (?xs @ ?ys) = load_tmps ?xs ∪ load_tmps ?ys›*) issue_expr_load_tmps_range' (*‹load_tmps (issue_expr ?t ?e) = {i. ?t ≤ i ∧ i < ?t + used_tmps ?e}›*)) qed lemma Cond_not_s₁: "s₁ ≠ Cond e s₁ s₂ " apply (induct s₁) (*goals: 1. ‹Skip ≠ Cond e Skip s₂› 2. ‹⋀x1 x2 x3 x4 x5 x6 x7. Assign x1 x2 x3 x4 x5 x6 x7 ≠ Cond e (Assign x1 x2 x3 x4 x5 x6 x7) s₂› 3. ‹⋀x1 x2 x3 x4 x5 x6 x7. CAS x1 x2 x3 x4 x5 x6 x7 ≠ Cond e (CAS x1 x2 x3 x4 x5 x6 x7) s₂› 4. ‹⋀s₁1 s₁2. ⟦s₁1 ≠ Cond e s₁1 s₂; s₁2 ≠ Cond e s₁2 s₂⟧ ⟹ Seq s₁1 s₁2 ≠ Cond e (Seq s₁1 s₁2) s₂› 5. ‹⋀x1 s₁1 s₁2. ⟦s₁1 ≠ Cond e s₁1 s₂; s₁2 ≠ Cond e s₁2 s₂⟧ ⟹ Cond x1 s₁1 s₁2 ≠ Cond e (Cond x1 s₁1 s₁2) s₂› 6. ‹⋀x1 s₁. s₁ ≠ Cond e s₁ s₂ ⟹ While x1 s₁ ≠ Cond e (While x1 s₁) s₂› 7. ‹⋀x1 x2 x3 x4. SGhost x1 x2 x3 x4 ≠ Cond e (SGhost x1 x2 x3 x4) s₂› 8. ‹SFence ≠ Cond e SFence s₂› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*proven 8 subgoals*) . lemma Cond_not_s₂: "s₂ ≠ Cond e s₁ s₂ " apply (induct s₂) (*goals: 1. ‹Skip ≠ Cond e s₁ Skip› 2. ‹⋀x1 x2 x3 x4 x5 x6 x7. Assign x1 x2 x3 x4 x5 x6 x7 ≠ Cond e s₁ (Assign x1 x2 x3 x4 x5 x6 x7)› 3. ‹⋀x1 x2 x3 x4 x5 x6 x7. CAS x1 x2 x3 x4 x5 x6 x7 ≠ Cond e s₁ (CAS x1 x2 x3 x4 x5 x6 x7)› 4. ‹⋀s₂1 s₂2. ⟦s₂1 ≠ Cond e s₁ s₂1; s₂2 ≠ Cond e s₁ s₂2⟧ ⟹ Seq s₂1 s₂2 ≠ Cond e s₁ (Seq s₂1 s₂2)› 5. ‹⋀x1 s₂1 s₂2. ⟦s₂1 ≠ Cond e s₁ s₂1; s₂2 ≠ Cond e s₁ s₂2⟧ ⟹ Cond x1 s₂1 s₂2 ≠ Cond e s₁ (Cond x1 s₂1 s₂2)› 6. ‹⋀x1 s₂. s₂ ≠ Cond e s₁ s₂ ⟹ While x1 s₂ ≠ Cond e s₁ (While x1 s₂)› 7. ‹⋀x1 x2 x3 x4. SGhost x1 x2 x3 x4 ≠ Cond e s₁ (SGhost x1 x2 x3 x4)› 8. ‹SFence ≠ Cond e s₁ SFence› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*proven 8 subgoals*) . lemma Seq_not_s₁: "s₁ ≠ Seq s₁ s₂" apply (induct s₁) (*goals: 1. ‹Skip ≠ Seq Skip s₂› 2. ‹⋀x1 x2 x3 x4 x5 x6 x7. Assign x1 x2 x3 x4 x5 x6 x7 ≠ Seq (Assign x1 x2 x3 x4 x5 x6 x7) s₂› 3. ‹⋀x1 x2 x3 x4 x5 x6 x7. CAS x1 x2 x3 x4 x5 x6 x7 ≠ Seq (CAS x1 x2 x3 x4 x5 x6 x7) s₂› 4. ‹⋀s₁1 s₁2. ⟦s₁1 ≠ Seq s₁1 s₂; s₁2 ≠ Seq s₁2 s₂⟧ ⟹ Seq s₁1 s₁2 ≠ Seq (Seq s₁1 s₁2) s₂› 5. ‹⋀x1 s₁1 s₁2. ⟦s₁1 ≠ Seq s₁1 s₂; s₁2 ≠ Seq s₁2 s₂⟧ ⟹ Cond x1 s₁1 s₁2 ≠ Seq (Cond x1 s₁1 s₁2) s₂› 6. ‹⋀x1 s₁. s₁ ≠ Seq s₁ s₂ ⟹ While x1 s₁ ≠ Seq (While x1 s₁) s₂› 7. ‹⋀x1 x2 x3 x4. SGhost x1 x2 x3 x4 ≠ Seq (SGhost x1 x2 x3 x4) s₂› 8. ‹SFence ≠ Seq SFence s₂› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*proven 8 subgoals*) . lemma Seq_not_s₂: "s₂ ≠ Seq s₁ s₂" apply (induct s₂) (*goals: 1. ‹Skip ≠ Seq (s₁::stmt) Skip› 2. ‹⋀(x1::bool) (x2::expr) (x3::expr) (x4::(nat ⇒ nat option) ⇒ nat set) (x5::(nat ⇒ nat option) ⇒ nat set) (x6::(nat ⇒ nat option) ⇒ nat set) x7::(nat ⇒ nat option) ⇒ nat set. Assign x1 x2 x3 x4 x5 x6 x7 ≠ Seq (s₁::stmt) (Assign x1 x2 x3 x4 x5 x6 x7)› 3. ‹⋀(x1::expr) (x2::expr) (x3::expr) (x4::(nat ⇒ nat option) ⇒ nat set) (x5::(nat ⇒ nat option) ⇒ nat set) (x6::(nat ⇒ nat option) ⇒ nat set) x7::(nat ⇒ nat option) ⇒ nat set. CAS x1 x2 x3 x4 x5 x6 x7 ≠ Seq (s₁::stmt) (CAS x1 x2 x3 x4 x5 x6 x7)› 4. ‹⋀(s₂1::stmt) s₂2::stmt. ⟦s₂1 ≠ Seq (s₁::stmt) s₂1; s₂2 ≠ Seq s₁ s₂2⟧ ⟹ Seq s₂1 s₂2 ≠ Seq s₁ (Seq s₂1 s₂2)› 5. ‹⋀(x1::expr) (s₂1::stmt) s₂2::stmt. ⟦s₂1 ≠ Seq (s₁::stmt) s₂1; s₂2 ≠ Seq s₁ s₂2⟧ ⟹ Cond x1 s₂1 s₂2 ≠ Seq s₁ (Cond x1 s₂1 s₂2)› 6. ‹⋀(x1::expr) s₂::stmt. s₂ ≠ Seq (s₁::stmt) s₂ ⟹ While x1 s₂ ≠ Seq s₁ (While x1 s₂)› 7. ‹⋀(x1::(nat ⇒ nat option) ⇒ nat set) (x2::(nat ⇒ nat option) ⇒ nat set) (x3::(nat ⇒ nat option) ⇒ nat set) x4::(nat ⇒ nat option) ⇒ nat set. SGhost x1 x2 x3 x4 ≠ Seq (s₁::stmt) (SGhost x1 x2 x3 x4)› 8. ‹SFence ≠ Seq (s₁::stmt) SFence› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*proven 8 subgoals*) . lemma prog_step_progress: assumes step: "θ⊢(s,t) →⇩s ((s',t'),is)" shows "(s',t') ≠ (s,t) ∨ is ≠ []" using step (*‹θ⊢ (s, t) →⇩s ((s', t'), is)›*) proof (induct x=="(s,t)" y=="((s',t'),is)" arbitrary: s t s' t' "is" rule: stmt_step.induct) (*goals: 1. ‹⋀a volatile e A L R W t. ∀sop. a ≠ Tmp sop ⟹ (Assign volatile (Tmp (eval_expr t a)) e A L R W, t + used_tmps a) ≠ (Assign volatile a e A L R W, t) ∨ issue_expr t a ≠ []› 2. ‹⋀D volatile a e A L R W t. D ⊆ dom θ ⟹ (Skip, t + used_tmps e) ≠ (Assign volatile (Tmp (D, a)) e A L R W, t) ∨ issue_expr t e @ [Write volatile (a θ) (eval_expr t e) (A θ) (L θ) (R θ) (W θ)] ≠ []› 3. ‹⋀a c⇩e s⇩e A L R W t. ∀sop. a ≠ Tmp sop ⟹ (CAS (Tmp (eval_expr t a)) c⇩e s⇩e A L R W, t + used_tmps a) ≠ (CAS a c⇩e s⇩e A L R W, t) ∨ issue_expr t a ≠ []› 4. ‹⋀c⇩e D⇩a a s⇩e A L R W t. ∀sop. c⇩e ≠ Tmp sop ⟹ (CAS (Tmp (D⇩a, a)) (Tmp (eval_expr t c⇩e)) s⇩e A L R W, t + used_tmps c⇩e) ≠ (CAS (Tmp (D⇩a, a)) c⇩e s⇩e A L R W, t) ∨ issue_expr t c⇩e ≠ []› 5. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f)⟧ ⟹ (Skip, Suc (t + used_tmps s⇩e)) ≠ (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W, t) ∨ issue_expr t s⇩e @ [RMW (a θ) (t + used_tmps s⇩e) (D, f) (λθ. the (θ (t + used_tmps s⇩e)) = c θ) (λv₁ v₂. v₁) (A θ) (L θ) (R θ) (W θ)] ≠ []› 6. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); (s₁', t') ≠ (s₁, t) ∨ is ≠ []⟧ ⟹ (Seq s₁' s₂, t') ≠ (Seq s₁ s₂, t) ∨ is ≠ []› 7. ‹⋀s₂ t. (s₂, t) ≠ (Seq Skip s₂, t) ∨ [] ≠ []› 8. ‹⋀e s₁ s₂ t. ∀sop. e ≠ Tmp sop ⟹ (Cond (Tmp (eval_expr t e)) s₁ s₂, t + used_tmps e) ≠ (Cond e s₁ s₂, t) ∨ issue_expr t e ≠ []› 9. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ)⟧ ⟹ (s₁, t) ≠ (Cond (Tmp (D, e)) s₁ s₂, t) ∨ [] ≠ []› 10. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ)⟧ ⟹ (s₂, t) ≠ (Cond (Tmp (D, e)) s₁ s₂, t) ∨ [] ≠ []› 11. ‹⋀e s t. (Cond e (Seq s (While e s)) Skip, t) ≠ (While e s, t) ∨ [] ≠ []› 12. ‹⋀A L R W t. (Skip, t) ≠ (SGhost A L R W, t) ∨ [Ghost (A θ) (L θ) (R θ) (W θ)] ≠ []› 13. ‹⋀t. (Skip, t) ≠ (SFence, t) ∨ [Fence] ≠ []›*) case (AssignAddr a______ t) (*‹∀sop. a ≠ Tmp sop›*) thus "?case" (*goal: ‹(Assign volatile_ (Tmp (eval_expr t a)) e_ A_ L_ R_ W_, t + used_tmps a) ≠ (Assign volatile_ a e_ A_ L_ R_ W_, t) ∨ issue_expr t a ≠ []›*) apply (cases "eval_expr t a") (*goal: ‹(Assign volatile_ (Tmp (eval_expr t a)) e_ A_ L_ R_ W_, t + used_tmps a) ≠ (Assign volatile_ a e_ A_ L_ R_ W_, t) ∨ issue_expr t a ≠ []›*) by auto next (*goals: 1. ‹⋀D volatile a e A L R W t. D ⊆ dom θ ⟹ (Skip, t + used_tmps e) ≠ (Assign volatile (Tmp (D, a)) e A L R W, t) ∨ issue_expr t e @ [Write volatile (a θ) (eval_expr t e) (A θ) (L θ) (R θ) (W θ)] ≠ []› 2. ‹⋀a c⇩e s⇩e A L R W t. ∀sop. a ≠ Tmp sop ⟹ (CAS (Tmp (eval_expr t a)) c⇩e s⇩e A L R W, t + used_tmps a) ≠ (CAS a c⇩e s⇩e A L R W, t) ∨ issue_expr t a ≠ []› 3. ‹⋀c⇩e D⇩a a s⇩e A L R W t. ∀sop. c⇩e ≠ Tmp sop ⟹ (CAS (Tmp (D⇩a, a)) (Tmp (eval_expr t c⇩e)) s⇩e A L R W, t + used_tmps c⇩e) ≠ (CAS (Tmp (D⇩a, a)) c⇩e s⇩e A L R W, t) ∨ issue_expr t c⇩e ≠ []› 4. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f)⟧ ⟹ (Skip, Suc (t + used_tmps s⇩e)) ≠ (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W, t) ∨ issue_expr t s⇩e @ [RMW (a θ) (t + used_tmps s⇩e) (D, f) (λθ. the (θ (t + used_tmps s⇩e)) = c θ) (λv₁ v₂. v₁) (A θ) (L θ) (R θ) (W θ)] ≠ []› 5. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); (s₁', t') ≠ (s₁, t) ∨ is ≠ []⟧ ⟹ (Seq s₁' s₂, t') ≠ (Seq s₁ s₂, t) ∨ is ≠ []› 6. ‹⋀s₂ t. (s₂, t) ≠ (Seq Skip s₂, t) ∨ [] ≠ []› 7. ‹⋀e s₁ s₂ t. ∀sop. e ≠ Tmp sop ⟹ (Cond (Tmp (eval_expr t e)) s₁ s₂, t + used_tmps e) ≠ (Cond e s₁ s₂, t) ∨ issue_expr t e ≠ []› 8. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ)⟧ ⟹ (s₁, t) ≠ (Cond (Tmp (D, e)) s₁ s₂, t) ∨ [] ≠ []› 9. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ)⟧ ⟹ (s₂, t) ≠ (Cond (Tmp (D, e)) s₁ s₂, t) ∨ [] ≠ []› 10. ‹⋀e s t. (Cond e (Seq s (While e s)) Skip, t) ≠ (While e s, t) ∨ [] ≠ []› 11. ‹⋀A L R W t. (Skip, t) ≠ (SGhost A L R W, t) ∨ [Ghost (A θ) (L θ) (R θ) (W θ)] ≠ []› 12. ‹⋀t. (Skip, t) ≠ (SFence, t) ∨ [Fence] ≠ []›*) case Assign (*‹D_ ⊆ dom θ›*) thus "?case" (*goal: ‹(Skip, t_ + used_tmps e_) ≠ (Assign volatile_ (Tmp (D_, a_)) e_ A_ L_ R_ W_, t_) ∨ issue_expr t_ e_ @ [Write volatile_ (a_ θ) (eval_expr t_ e_) (A_ θ) (L_ θ) (R_ θ) (W_ θ)] ≠ []›*) by auto next (*goals: 1. ‹⋀a c⇩e s⇩e A L R W t. ∀sop. a ≠ Tmp sop ⟹ (CAS (Tmp (eval_expr t a)) c⇩e s⇩e A L R W, t + used_tmps a) ≠ (CAS a c⇩e s⇩e A L R W, t) ∨ issue_expr t a ≠ []› 2. ‹⋀c⇩e D⇩a a s⇩e A L R W t. ∀sop. c⇩e ≠ Tmp sop ⟹ (CAS (Tmp (D⇩a, a)) (Tmp (eval_expr t c⇩e)) s⇩e A L R W, t + used_tmps c⇩e) ≠ (CAS (Tmp (D⇩a, a)) c⇩e s⇩e A L R W, t) ∨ issue_expr t c⇩e ≠ []› 3. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f)⟧ ⟹ (Skip, Suc (t + used_tmps s⇩e)) ≠ (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W, t) ∨ issue_expr t s⇩e @ [RMW (a θ) (t + used_tmps s⇩e) (D, f) (λθ. the (θ (t + used_tmps s⇩e)) = c θ) (λv₁ v₂. v₁) (A θ) (L θ) (R θ) (W θ)] ≠ []› 4. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); (s₁', t') ≠ (s₁, t) ∨ is ≠ []⟧ ⟹ (Seq s₁' s₂, t') ≠ (Seq s₁ s₂, t) ∨ is ≠ []› 5. ‹⋀s₂ t. (s₂, t) ≠ (Seq Skip s₂, t) ∨ [] ≠ []› 6. ‹⋀e s₁ s₂ t. ∀sop. e ≠ Tmp sop ⟹ (Cond (Tmp (eval_expr t e)) s₁ s₂, t + used_tmps e) ≠ (Cond e s₁ s₂, t) ∨ issue_expr t e ≠ []› 7. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ)⟧ ⟹ (s₁, t) ≠ (Cond (Tmp (D, e)) s₁ s₂, t) ∨ [] ≠ []› 8. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ)⟧ ⟹ (s₂, t) ≠ (Cond (Tmp (D, e)) s₁ s₂, t) ∨ [] ≠ []› 9. ‹⋀e s t. (Cond e (Seq s (While e s)) Skip, t) ≠ (While e s, t) ∨ [] ≠ []› 10. ‹⋀A L R W t. (Skip, t) ≠ (SGhost A L R W, t) ∨ [Ghost (A θ) (L θ) (R θ) (W θ)] ≠ []› 11. ‹⋀t. (Skip, t) ≠ (SFence, t) ∨ [Fence] ≠ []›*) case (CASAddr a______ t) (*‹∀sop. a ≠ Tmp sop›*) thus "?case" (*goal: ‹(CAS (Tmp (eval_expr t a)) c⇩e_ s⇩e_ A_ L_ R_ W_, t + used_tmps a) ≠ (CAS a c⇩e_ s⇩e_ A_ L_ R_ W_, t) ∨ issue_expr t a ≠ []›*) apply (cases "eval_expr t a") (*goal: ‹(CAS (Tmp (eval_expr (t::nat) (a::expr))) (c⇩e_::expr) (s⇩e_::expr) (A_::(nat ⇒ nat option) ⇒ nat set) (L_::(nat ⇒ nat option) ⇒ nat set) (R_::(nat ⇒ nat option) ⇒ nat set) (W_::(nat ⇒ nat option) ⇒ nat set), t + used_tmps a) ≠ (CAS a c⇩e_ s⇩e_ A_ L_ R_ W_, t) ∨ issue_expr t a ≠ []›*) by auto next (*goals: 1. ‹⋀c⇩e D⇩a a s⇩e A L R W t. ∀sop. c⇩e ≠ Tmp sop ⟹ (CAS (Tmp (D⇩a, a)) (Tmp (eval_expr t c⇩e)) s⇩e A L R W, t + used_tmps c⇩e) ≠ (CAS (Tmp (D⇩a, a)) c⇩e s⇩e A L R W, t) ∨ issue_expr t c⇩e ≠ []› 2. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f)⟧ ⟹ (Skip, Suc (t + used_tmps s⇩e)) ≠ (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W, t) ∨ issue_expr t s⇩e @ [RMW (a θ) (t + used_tmps s⇩e) (D, f) (λθ. the (θ (t + used_tmps s⇩e)) = c θ) (λv₁ v₂. v₁) (A θ) (L θ) (R θ) (W θ)] ≠ []› 3. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); (s₁', t') ≠ (s₁, t) ∨ is ≠ []⟧ ⟹ (Seq s₁' s₂, t') ≠ (Seq s₁ s₂, t) ∨ is ≠ []› 4. ‹⋀s₂ t. (s₂, t) ≠ (Seq Skip s₂, t) ∨ [] ≠ []› 5. ‹⋀e s₁ s₂ t. ∀sop. e ≠ Tmp sop ⟹ (Cond (Tmp (eval_expr t e)) s₁ s₂, t + used_tmps e) ≠ (Cond e s₁ s₂, t) ∨ issue_expr t e ≠ []› 6. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ)⟧ ⟹ (s₁, t) ≠ (Cond (Tmp (D, e)) s₁ s₂, t) ∨ [] ≠ []› 7. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ)⟧ ⟹ (s₂, t) ≠ (Cond (Tmp (D, e)) s₁ s₂, t) ∨ [] ≠ []› 8. ‹⋀e s t. (Cond e (Seq s (While e s)) Skip, t) ≠ (While e s, t) ∨ [] ≠ []› 9. ‹⋀A L R W t. (Skip, t) ≠ (SGhost A L R W, t) ∨ [Ghost (A θ) (L θ) (R θ) (W θ)] ≠ []› 10. ‹⋀t. (Skip, t) ≠ (SFence, t) ∨ [Fence] ≠ []›*) case (CASComp c⇩e_______ t) (*‹∀sop. c⇩e ≠ Tmp sop›*) thus "?case" (*goal: ‹(CAS (Tmp (D⇩a_, a_)) (Tmp (eval_expr t c⇩e)) s⇩e_ A_ L_ R_ W_, t + used_tmps c⇩e) ≠ (CAS (Tmp (D⇩a_, a_)) c⇩e s⇩e_ A_ L_ R_ W_, t) ∨ issue_expr t c⇩e ≠ []›*) apply (cases "eval_expr t c⇩e") (*goal: ‹(CAS (Tmp (D⇩a_::nat set, a_::(nat ⇒ nat option) ⇒ nat)) (Tmp (eval_expr (t::nat) (c⇩e::expr))) (s⇩e_::expr) (A_::(nat ⇒ nat option) ⇒ nat set) (L_::(nat ⇒ nat option) ⇒ nat set) (R_::(nat ⇒ nat option) ⇒ nat set) (W_::(nat ⇒ nat option) ⇒ nat set), t + used_tmps c⇩e) ≠ (CAS (Tmp (D⇩a_, a_)) c⇩e s⇩e_ A_ L_ R_ W_, t) ∨ issue_expr t c⇩e ≠ []›*) by auto next (*goals: 1. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f)⟧ ⟹ (Skip, Suc (t + used_tmps s⇩e)) ≠ (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W, t) ∨ issue_expr t s⇩e @ [RMW (a θ) (t + used_tmps s⇩e) (D, f) (λθ. the (θ (t + used_tmps s⇩e)) = c θ) (λv₁ v₂. v₁) (A θ) (L θ) (R θ) (W θ)] ≠ []› 2. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); (s₁', t') ≠ (s₁, t) ∨ is ≠ []⟧ ⟹ (Seq s₁' s₂, t') ≠ (Seq s₁ s₂, t) ∨ is ≠ []› 3. ‹⋀s₂ t. (s₂, t) ≠ (Seq Skip s₂, t) ∨ [] ≠ []› 4. ‹⋀e s₁ s₂ t. ∀sop. e ≠ Tmp sop ⟹ (Cond (Tmp (eval_expr t e)) s₁ s₂, t + used_tmps e) ≠ (Cond e s₁ s₂, t) ∨ issue_expr t e ≠ []› 5. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ)⟧ ⟹ (s₁, t) ≠ (Cond (Tmp (D, e)) s₁ s₂, t) ∨ [] ≠ []› 6. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ)⟧ ⟹ (s₂, t) ≠ (Cond (Tmp (D, e)) s₁ s₂, t) ∨ [] ≠ []› 7. ‹⋀e s t. (Cond e (Seq s (While e s)) Skip, t) ≠ (While e s, t) ∨ [] ≠ []› 8. ‹⋀A L R W t. (Skip, t) ≠ (SGhost A L R W, t) ∨ [Ghost (A θ) (L θ) (R θ) (W θ)] ≠ []› 9. ‹⋀t. (Skip, t) ≠ (SFence, t) ∨ [Fence] ≠ []›*) case CAS (*‹D⇩a_ ⊆ dom θ› ‹D⇩c_ ⊆ dom θ› ‹eval_expr t_ s⇩e_ = (D_, f_)›*) thus "?case" (*goal: ‹(Skip, Suc (t_ + used_tmps s⇩e_)) ≠ (CAS (Tmp (D⇩a_, a_)) (Tmp (D⇩c_, c_)) s⇩e_ A_ L_ R_ W_, t_) ∨ issue_expr t_ s⇩e_ @ [RMW (a_ θ) (t_ + used_tmps s⇩e_) (D_, f_) (λθ. the (θ (t_ + used_tmps s⇩e_)) = c_ θ) (λv₁ v₂. v₁) (A_ θ) (L_ θ) (R_ θ) (W_ θ)] ≠ []›*) by auto next (*goals: 1. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); (s₁', t') ≠ (s₁, t) ∨ is ≠ []⟧ ⟹ (Seq s₁' s₂, t') ≠ (Seq s₁ s₂, t) ∨ is ≠ []› 2. ‹⋀s₂ t. (s₂, t) ≠ (Seq Skip s₂, t) ∨ [] ≠ []› 3. ‹⋀e s₁ s₂ t. ∀sop. e ≠ Tmp sop ⟹ (Cond (Tmp (eval_expr t e)) s₁ s₂, t + used_tmps e) ≠ (Cond e s₁ s₂, t) ∨ issue_expr t e ≠ []› 4. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ)⟧ ⟹ (s₁, t) ≠ (Cond (Tmp (D, e)) s₁ s₂, t) ∨ [] ≠ []› 5. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ)⟧ ⟹ (s₂, t) ≠ (Cond (Tmp (D, e)) s₁ s₂, t) ∨ [] ≠ []› 6. ‹⋀e s t. (Cond e (Seq s (While e s)) Skip, t) ≠ (While e s, t) ∨ [] ≠ []› 7. ‹⋀A L R W t. (Skip, t) ≠ (SGhost A L R W, t) ∨ [Ghost (A θ) (L θ) (R θ) (W θ)] ≠ []› 8. ‹⋀t. (Skip, t) ≠ (SFence, t) ∨ [Fence] ≠ []›*) case (Cond e__ t) (*‹∀sop. e ≠ Tmp sop›*) thus "?case" (*goal: ‹(Cond (Tmp (eval_expr t e)) s₁_ s₂_, t + used_tmps e) ≠ (Cond e s₁_ s₂_, t) ∨ issue_expr t e ≠ []›*) apply (cases "eval_expr t e") (*goal: ‹(Cond (Tmp (eval_expr t e)) s₁_ s₂_, t + used_tmps e) ≠ (Cond e s₁_ s₂_, t) ∨ issue_expr t e ≠ []›*) by auto next (*goals: 1. ‹⋀(s₁::stmt) (t::nat) (s₁'::stmt) (t'::nat) (is::instr list) s₂::stmt. ⟦(θ::nat ⇒ nat option)⊢ (s₁, t) →⇩s ((s₁', t'), is); (s₁', t') ≠ (s₁, t) ∨ is ≠ []⟧ ⟹ (Seq s₁' s₂, t') ≠ (Seq s₁ s₂, t) ∨ is ≠ []› 2. ‹⋀(s₂::stmt) t::nat. (s₂, t) ≠ (Seq Skip s₂, t) ∨ [] ≠ []› 3. ‹⋀(D::nat set) (e::(nat ⇒ nat option) ⇒ nat) (s₁::stmt) (s₂::stmt) t::nat. ⟦D ⊆ dom (θ::nat ⇒ nat option); isTrue (e θ)⟧ ⟹ (s₁, t) ≠ (Cond (Tmp (D, e)) s₁ s₂, t) ∨ [] ≠ []› 4. ‹⋀(D::nat set) (e::(nat ⇒ nat option) ⇒ nat) (s₁::stmt) (s₂::stmt) t::nat. ⟦D ⊆ dom (θ::nat ⇒ nat option); ¬ isTrue (e θ)⟧ ⟹ (s₂, t) ≠ (Cond (Tmp (D, e)) s₁ s₂, t) ∨ [] ≠ []› 5. ‹⋀(e::expr) (s::stmt) t::nat. (Cond e (Seq s (While e s)) Skip, t) ≠ (While e s, t) ∨ [] ≠ []› 6. ‹⋀(A::(nat ⇒ nat option) ⇒ nat set) (L::(nat ⇒ nat option) ⇒ nat set) (R::(nat ⇒ nat option) ⇒ nat set) (W::(nat ⇒ nat option) ⇒ nat set) t::nat. (Skip, t) ≠ (SGhost A L R W, t) ∨ [Ghost (A (θ::nat ⇒ nat option)) (L θ) (R θ) (W θ)] ≠ []› 7. ‹⋀t::nat. (Skip, t) ≠ (SFence, t) ∨ [Fence] ≠ []›*) case CondTrue (*‹D_ ⊆ dom θ› ‹isTrue ((e_::(nat ⇒ nat option) ⇒ nat) (θ::nat ⇒ nat option))›*) thus "?case" (*goal: ‹(s₁_, t_) ≠ (Cond (Tmp (D_, e_)) s₁_ s₂_, t_) ∨ [] ≠ []›*) using "Cond_not_s₁" (*‹?s₁ ≠ Cond ?e ?s₁ ?s₂›*) by auto next (*goals: 1. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); (s₁', t') ≠ (s₁, t) ∨ is ≠ []⟧ ⟹ (Seq s₁' s₂, t') ≠ (Seq s₁ s₂, t) ∨ is ≠ []› 2. ‹⋀s₂ t. (s₂, t) ≠ (Seq Skip s₂, t) ∨ [] ≠ []› 3. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ)⟧ ⟹ (s₂, t) ≠ (Cond (Tmp (D, e)) s₁ s₂, t) ∨ [] ≠ []› 4. ‹⋀e s t. (Cond e (Seq s (While e s)) Skip, t) ≠ (While e s, t) ∨ [] ≠ []› 5. ‹⋀A L R W t. (Skip, t) ≠ (SGhost A L R W, t) ∨ [Ghost (A θ) (L θ) (R θ) (W θ)] ≠ []› 6. ‹⋀t. (Skip, t) ≠ (SFence, t) ∨ [Fence] ≠ []›*) case CondFalse (*‹D_ ⊆ dom θ› ‹¬ isTrue (e_ θ)›*) thus "?case" (*goal: ‹(s₂_, t_) ≠ (Cond (Tmp (D_, e_)) s₁_ s₂_, t_) ∨ [] ≠ []›*) using "Cond_not_s₂" (*‹?s₂ ≠ Cond ?e ?s₁ ?s₂›*) by auto next (*goals: 1. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); (s₁', t') ≠ (s₁, t) ∨ is ≠ []⟧ ⟹ (Seq s₁' s₂, t') ≠ (Seq s₁ s₂, t) ∨ is ≠ []› 2. ‹⋀s₂ t. (s₂, t) ≠ (Seq Skip s₂, t) ∨ [] ≠ []› 3. ‹⋀e s t. (Cond e (Seq s (While e s)) Skip, t) ≠ (While e s, t) ∨ [] ≠ []› 4. ‹⋀A L R W t. (Skip, t) ≠ (SGhost A L R W, t) ∨ [Ghost (A θ) (L θ) (R θ) (W θ)] ≠ []› 5. ‹⋀t. (Skip, t) ≠ (SFence, t) ∨ [Fence] ≠ []›*) case Seq (*‹θ⊢ (s₁_, t_) →⇩s ((s₁'_, t'_), is_)› ‹(s₁'_, t'_) ≠ (s₁_, t_) ∨ is_ ≠ []›*) thus "?case" (*goal: ‹(Seq s₁'_ s₂_, t'_) ≠ (Seq s₁_ s₂_, t_) ∨ is_ ≠ []›*) by force next (*goals: 1. ‹⋀s₂ t. (s₂, t) ≠ (Seq Skip s₂, t) ∨ [] ≠ []› 2. ‹⋀e s t. (Cond e (Seq s (While e s)) Skip, t) ≠ (While e s, t) ∨ [] ≠ []› 3. ‹⋀A L R W t. (Skip, t) ≠ (SGhost A L R W, t) ∨ [Ghost (A θ) (L θ) (R θ) (W θ)] ≠ []› 4. ‹⋀t. (Skip, t) ≠ (SFence, t) ∨ [Fence] ≠ []›*) case SeqSkip (*no hyothesis introduced yet*) thus "?case" (*goal: ‹(s₂_, t_) ≠ (Seq Skip s₂_, t_) ∨ [] ≠ []›*) using "Seq_not_s₂" (*‹?s₂ ≠ Seq ?s₁ ?s₂›*) by auto next (*goals: 1. ‹⋀e s t. (Cond e (Seq s (While e s)) Skip, t) ≠ (While e s, t) ∨ [] ≠ []› 2. ‹⋀A L R W t. (Skip, t) ≠ (SGhost A L R W, t) ∨ [Ghost (A θ) (L θ) (R θ) (W θ)] ≠ []› 3. ‹⋀t. (Skip, t) ≠ (SFence, t) ∨ [Fence] ≠ []›*) case While (*no hyothesis introduced yet*) thus "?case" (*goal: ‹(Cond (e_::expr) (Seq (s_::stmt) (While e_ s_)) Skip, t_::nat) ≠ (While e_ s_, t_) ∨ [] ≠ []›*) by auto next (*goals: 1. ‹⋀A L R W t. (Skip, t) ≠ (SGhost A L R W, t) ∨ [Ghost (A θ) (L θ) (R θ) (W θ)] ≠ []› 2. ‹⋀t. (Skip, t) ≠ (SFence, t) ∨ [Fence] ≠ []›*) case SGhost (*no hyothesis introduced yet*) thus "?case" (*goal: ‹(Skip, t_) ≠ (SGhost A_ L_ R_ W_, t_) ∨ [Ghost (A_ θ) (L_ θ) (R_ θ) (W_ θ)] ≠ []›*) by auto next (*goal: ‹⋀t::nat. (Skip, t) ≠ (SFence, t) ∨ [Fence] ≠ []›*) case SFence (*no hyothesis introduced yet*) thus "?case" (*goal: ‹(Skip, t_::nat) ≠ (SFence, t_) ∨ [Fence] ≠ []›*) by auto qed lemma stmt_step_data_dependency_consistent_instrs: assumes step: "θ⊢ (s, t) →⇩s ((s', t'),is)" assumes valid: "valid_sops_stmt t s" shows "data_dependency_consistent_instrs ({i. i < t}) is" using step (*‹θ⊢ (s, t) →⇩s ((s', t'), is)›*) valid (*‹valid_sops_stmt t s›*) proof (induct x=="(s,t)" y=="((s',t'),is)" arbitrary: s t s' t' "is" T rule: stmt_step.induct) (*goals: 1. ‹⋀(a::expr) (volatile::bool) (e::expr) (A::(nat ⇒ nat option) ⇒ nat set) (L::(nat ⇒ nat option) ⇒ nat set) (R::(nat ⇒ nat option) ⇒ nat set) (W::(nat ⇒ nat option) ⇒ nat set) t::nat. ⟦∀sop::nat set × ((nat ⇒ nat option) ⇒ nat). a ≠ Tmp sop; valid_sops_stmt t (Assign volatile a e A L R W)⟧ ⟹ data_dependency_consistent_instrs {i::nat. i < t} (issue_expr t a)› 2. ‹⋀(D::nat set) (volatile::bool) (a::(nat ⇒ nat option) ⇒ nat) (e::expr) (A::(nat ⇒ nat option) ⇒ nat set) (L::(nat ⇒ nat option) ⇒ nat set) (R::(nat ⇒ nat option) ⇒ nat set) (W::(nat ⇒ nat option) ⇒ nat set) t::nat. ⟦D ⊆ dom (θ::nat ⇒ nat option); valid_sops_stmt t (Assign volatile (Tmp (D, a)) e A L R W)⟧ ⟹ data_dependency_consistent_instrs {i::nat. i < t} (issue_expr t e @ [Write volatile (a θ) (eval_expr t e) (A θ) (L θ) (R θ) (W θ)])› 3. ‹⋀(a::expr) (c⇩e::expr) (s⇩e::expr) (A::(nat ⇒ nat option) ⇒ nat set) (L::(nat ⇒ nat option) ⇒ nat set) (R::(nat ⇒ nat option) ⇒ nat set) (W::(nat ⇒ nat option) ⇒ nat set) t::nat. ⟦∀sop::nat set × ((nat ⇒ nat option) ⇒ nat). a ≠ Tmp sop; valid_sops_stmt t (CAS a c⇩e s⇩e A L R W)⟧ ⟹ data_dependency_consistent_instrs {i::nat. i < t} (issue_expr t a)› 4. ‹⋀(c⇩e::expr) (D⇩a::nat set) (a::(nat ⇒ nat option) ⇒ nat) (s⇩e::expr) (A::(nat ⇒ nat option) ⇒ nat set) (L::(nat ⇒ nat option) ⇒ nat set) (R::(nat ⇒ nat option) ⇒ nat set) (W::(nat ⇒ nat option) ⇒ nat set) t::nat. ⟦∀sop::nat set × ((nat ⇒ nat option) ⇒ nat). c⇩e ≠ Tmp sop; valid_sops_stmt t (CAS (Tmp (D⇩a, a)) c⇩e s⇩e A L R W)⟧ ⟹ data_dependency_consistent_instrs {i::nat. i < t} (issue_expr t c⇩e)› 5. ‹⋀(D⇩a::nat set) (D⇩c::nat set) (t::nat) (s⇩e::expr) (D::nat set) (f::(nat ⇒ nat option) ⇒ nat) (a::(nat ⇒ nat option) ⇒ nat) (c::(nat ⇒ nat option) ⇒ nat) (A::(nat ⇒ nat option) ⇒ nat set) (L::(nat ⇒ nat option) ⇒ nat set) (R::(nat ⇒ nat option) ⇒ nat set) W::(nat ⇒ nat option) ⇒ nat set. ⟦D⇩a ⊆ dom (θ::nat ⇒ nat option); D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f); valid_sops_stmt t (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W)⟧ ⟹ data_dependency_consistent_instrs {i::nat. i < t} (issue_expr t s⇩e @ [RMW (a θ) (t + used_tmps s⇩e) (D, f) (λθ::nat ⇒ nat option. the (θ (t + used_tmps s⇩e)) = c θ) (λ(v₁::nat) v₂::nat. v₁) (A θ) (L θ) (R θ) (W θ)])› 6. ‹⋀(s₁::stmt) (t::nat) (s₁'::stmt) (t'::nat) (is::instr list) s₂::stmt. ⟦(θ::nat ⇒ nat option)⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ data_dependency_consistent_instrs {i::nat. i < t} is; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i::nat. i < t} is› 7. ‹⋀(s₂::stmt) t::nat. valid_sops_stmt t (Seq Skip s₂) ⟹ data_dependency_consistent_instrs {i::nat. i < t} []› 8. ‹⋀(e::expr) (s₁::stmt) (s₂::stmt) t::nat. ⟦∀sop::nat set × ((nat ⇒ nat option) ⇒ nat). e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i::nat. i < t} (issue_expr t e)› 9. ‹⋀(D::nat set) (e::(nat ⇒ nat option) ⇒ nat) (s₁::stmt) (s₂::stmt) t::nat. ⟦D ⊆ dom (θ::nat ⇒ nat option); isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i::nat. i < t} []› 10. ‹⋀(D::nat set) (e::(nat ⇒ nat option) ⇒ nat) (s₁::stmt) (s₂::stmt) t::nat. ⟦D ⊆ dom (θ::nat ⇒ nat option); ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i::nat. i < t} []› 11. ‹⋀(e::expr) (s::stmt) t::nat. valid_sops_stmt t (While e s) ⟹ data_dependency_consistent_instrs {i::nat. i < t} []› 12. ‹⋀(A::(nat ⇒ nat option) ⇒ nat set) (L::(nat ⇒ nat option) ⇒ nat set) (R::(nat ⇒ nat option) ⇒ nat set) (W::(nat ⇒ nat option) ⇒ nat set) t::nat. valid_sops_stmt t (SGhost A L R W) ⟹ data_dependency_consistent_instrs {i::nat. i < t} [Ghost (A (θ::nat ⇒ nat option)) (L θ) (R θ) (W θ)]› 13. ‹⋀t::nat. valid_sops_stmt t SFence ⟹ data_dependency_consistent_instrs {i::nat. i < t} [Fence]›*) case AssignAddr (*‹∀sop. a_ ≠ Tmp sop› ‹valid_sops_stmt t_ (Assign volatile_ a_ e_ A_ L_ R_ W_)›*) thus "?case" (*goal: ‹data_dependency_consistent_instrs {i. i < t_} (issue_expr t_ a_)›*) by (fastforce simp add: simp add: data_dependency_consistent_instrs_append (*‹data_dependency_consistent_instrs ?T (?xs @ ?ys) = (data_dependency_consistent_instrs ?T ?xs ∧ data_dependency_consistent_instrs (?T ∪ load_tmps ?xs) ?ys ∧ load_tmps ?ys ∩ ⋃ (fst ` store_sops ?xs) = {})›*) data_dependency_consistent_instrs_issue_expr (*‹data_dependency_consistent_instrs ?T (issue_expr ?t ?e)›*) load_tmps_append (*‹load_tmps (?xs @ ?ys) = load_tmps ?xs ∪ load_tmps ?ys›*) dest: dom_eval_expr (*‹⟦valid_sops_expr ?t ?e; ?x ∈ fst (eval_expr ?t ?e)⟧ ⟹ ?x ∈ {i. i < ?t} ∪ load_tmps (issue_expr ?t ?e)›*)) next (*goals: 1. ‹⋀D volatile a e A L R W t. ⟦D ⊆ dom θ; valid_sops_stmt t (Assign volatile (Tmp (D, a)) e A L R W)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} (issue_expr t e @ [Write volatile (a θ) (eval_expr t e) (A θ) (L θ) (R θ) (W θ)])› 2. ‹⋀a c⇩e s⇩e A L R W t. ⟦∀sop. a ≠ Tmp sop; valid_sops_stmt t (CAS a c⇩e s⇩e A L R W)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} (issue_expr t a)› 3. ‹⋀c⇩e D⇩a a s⇩e A L R W t. ⟦∀sop. c⇩e ≠ Tmp sop; valid_sops_stmt t (CAS (Tmp (D⇩a, a)) c⇩e s⇩e A L R W)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} (issue_expr t c⇩e)› 4. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f); valid_sops_stmt t (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} (issue_expr t s⇩e @ [RMW (a θ) (t + used_tmps s⇩e) (D, f) (λθ. the (θ (t + used_tmps s⇩e)) = c θ) (λv₁ v₂. v₁) (A θ) (L θ) (R θ) (W θ)])› 5. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ data_dependency_consistent_instrs {i. i < t} is; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} is› 6. ‹⋀s₂ t. valid_sops_stmt t (Seq Skip s₂) ⟹ data_dependency_consistent_instrs {i. i < t} []› 7. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} (issue_expr t e)› 8. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} []› 9. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} []› 10. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ data_dependency_consistent_instrs {i. i < t} []› 11. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ data_dependency_consistent_instrs {i. i < t} [Ghost (A θ) (L θ) (R θ) (W θ)]› 12. ‹⋀t. valid_sops_stmt t SFence ⟹ data_dependency_consistent_instrs {i. i < t} [Fence]›*) case Assign (*‹D_ ⊆ dom θ› ‹valid_sops_stmt t_ (Assign volatile_ (Tmp (D_, a_)) e_ A_ L_ R_ W_)›*) thus "?case" (*goal: ‹data_dependency_consistent_instrs {i. i < t_} (issue_expr t_ e_ @ [Write volatile_ (a_ θ) (eval_expr t_ e_) (A_ θ) (L_ θ) (R_ θ) (W_ θ)])›*) by (fastforce simp add: simp add: data_dependency_consistent_instrs_append (*‹data_dependency_consistent_instrs (?T::nat set) ((?xs::instr list) @ (?ys::instr list)) = (data_dependency_consistent_instrs ?T ?xs ∧ data_dependency_consistent_instrs (?T ∪ load_tmps ?xs) ?ys ∧ load_tmps ?ys ∩ ⋃ (fst ` store_sops ?xs) = {})›*) data_dependency_consistent_instrs_issue_expr (*‹data_dependency_consistent_instrs (?T::nat set) (issue_expr (?t::nat) (?e::expr))›*) load_tmps_append (*‹load_tmps ((?xs::instr list) @ (?ys::instr list)) = load_tmps ?xs ∪ load_tmps ?ys›*) dest: dom_eval_expr (*‹⟦valid_sops_expr (?t::nat) (?e::expr); (?x::nat) ∈ fst (eval_expr ?t ?e)⟧ ⟹ ?x ∈ {i::nat. i < ?t} ∪ load_tmps (issue_expr ?t ?e)›*)) next (*goals: 1. ‹⋀a c⇩e s⇩e A L R W t. ⟦∀sop. a ≠ Tmp sop; valid_sops_stmt t (CAS a c⇩e s⇩e A L R W)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} (issue_expr t a)› 2. ‹⋀c⇩e D⇩a a s⇩e A L R W t. ⟦∀sop. c⇩e ≠ Tmp sop; valid_sops_stmt t (CAS (Tmp (D⇩a, a)) c⇩e s⇩e A L R W)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} (issue_expr t c⇩e)› 3. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f); valid_sops_stmt t (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} (issue_expr t s⇩e @ [RMW (a θ) (t + used_tmps s⇩e) (D, f) (λθ. the (θ (t + used_tmps s⇩e)) = c θ) (λv₁ v₂. v₁) (A θ) (L θ) (R θ) (W θ)])› 4. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ data_dependency_consistent_instrs {i. i < t} is; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} is› 5. ‹⋀s₂ t. valid_sops_stmt t (Seq Skip s₂) ⟹ data_dependency_consistent_instrs {i. i < t} []› 6. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} (issue_expr t e)› 7. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} []› 8. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} []› 9. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ data_dependency_consistent_instrs {i. i < t} []› 10. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ data_dependency_consistent_instrs {i. i < t} [Ghost (A θ) (L θ) (R θ) (W θ)]› 11. ‹⋀t. valid_sops_stmt t SFence ⟹ data_dependency_consistent_instrs {i. i < t} [Fence]›*) case CASAddr (*‹∀sop. a_ ≠ Tmp sop› ‹valid_sops_stmt t_ (CAS a_ c⇩e_ s⇩e_ A_ L_ R_ W_)›*) thus "?case" (*goal: ‹data_dependency_consistent_instrs {i. i < t_} (issue_expr t_ a_)›*) by (fastforce simp add: simp add: data_dependency_consistent_instrs_append (*‹data_dependency_consistent_instrs ?T (?xs @ ?ys) = (data_dependency_consistent_instrs ?T ?xs ∧ data_dependency_consistent_instrs (?T ∪ load_tmps ?xs) ?ys ∧ load_tmps ?ys ∩ ⋃ (fst ` store_sops ?xs) = {})›*) data_dependency_consistent_instrs_issue_expr (*‹data_dependency_consistent_instrs ?T (issue_expr ?t ?e)›*) load_tmps_append (*‹load_tmps (?xs @ ?ys) = load_tmps ?xs ∪ load_tmps ?ys›*) dest: dom_eval_expr (*‹⟦valid_sops_expr ?t ?e; ?x ∈ fst (eval_expr ?t ?e)⟧ ⟹ ?x ∈ {i. i < ?t} ∪ load_tmps (issue_expr ?t ?e)›*)) next (*goals: 1. ‹⋀c⇩e D⇩a a s⇩e A L R W t. ⟦∀sop. c⇩e ≠ Tmp sop; valid_sops_stmt t (CAS (Tmp (D⇩a, a)) c⇩e s⇩e A L R W)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} (issue_expr t c⇩e)› 2. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f); valid_sops_stmt t (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} (issue_expr t s⇩e @ [RMW (a θ) (t + used_tmps s⇩e) (D, f) (λθ. the (θ (t + used_tmps s⇩e)) = c θ) (λv₁ v₂. v₁) (A θ) (L θ) (R θ) (W θ)])› 3. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ data_dependency_consistent_instrs {i. i < t} is; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} is› 4. ‹⋀s₂ t. valid_sops_stmt t (Seq Skip s₂) ⟹ data_dependency_consistent_instrs {i. i < t} []› 5. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} (issue_expr t e)› 6. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} []› 7. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} []› 8. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ data_dependency_consistent_instrs {i. i < t} []› 9. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ data_dependency_consistent_instrs {i. i < t} [Ghost (A θ) (L θ) (R θ) (W θ)]› 10. ‹⋀t. valid_sops_stmt t SFence ⟹ data_dependency_consistent_instrs {i. i < t} [Fence]›*) case CASComp (*‹∀sop. c⇩e_ ≠ Tmp sop› ‹valid_sops_stmt t_ (CAS (Tmp (D⇩a_, a_)) c⇩e_ s⇩e_ A_ L_ R_ W_)›*) thus "?case" (*goal: ‹data_dependency_consistent_instrs {i. i < t_} (issue_expr t_ c⇩e_)›*) by (fastforce simp add: simp add: data_dependency_consistent_instrs_append (*‹data_dependency_consistent_instrs (?T::nat set) ((?xs::instr list) @ (?ys::instr list)) = (data_dependency_consistent_instrs ?T ?xs ∧ data_dependency_consistent_instrs (?T ∪ load_tmps ?xs) ?ys ∧ load_tmps ?ys ∩ ⋃ (fst ` store_sops ?xs) = {})›*) data_dependency_consistent_instrs_issue_expr (*‹data_dependency_consistent_instrs (?T::nat set) (issue_expr (?t::nat) (?e::expr))›*) load_tmps_append (*‹load_tmps ((?xs::instr list) @ (?ys::instr list)) = load_tmps ?xs ∪ load_tmps ?ys›*) dest: dom_eval_expr (*‹⟦valid_sops_expr (?t::nat) (?e::expr); (?x::nat) ∈ fst (eval_expr ?t ?e)⟧ ⟹ ?x ∈ {i::nat. i < ?t} ∪ load_tmps (issue_expr ?t ?e)›*)) next (*goals: 1. ‹⋀(D⇩a::nat set) (D⇩c::nat set) (t::nat) (s⇩e::expr) (D::nat set) (f::(nat ⇒ nat option) ⇒ nat) (a::(nat ⇒ nat option) ⇒ nat) (c::(nat ⇒ nat option) ⇒ nat) (A::(nat ⇒ nat option) ⇒ nat set) (L::(nat ⇒ nat option) ⇒ nat set) (R::(nat ⇒ nat option) ⇒ nat set) W::(nat ⇒ nat option) ⇒ nat set. ⟦D⇩a ⊆ dom (θ::nat ⇒ nat option); D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f); valid_sops_stmt t (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W)⟧ ⟹ data_dependency_consistent_instrs {i::nat. i < t} (issue_expr t s⇩e @ [RMW (a θ) (t + used_tmps s⇩e) (D, f) (λθ::nat ⇒ nat option. the (θ (t + used_tmps s⇩e)) = c θ) (λ(v₁::nat) v₂::nat. v₁) (A θ) (L θ) (R θ) (W θ)])› 2. ‹⋀(s₁::stmt) (t::nat) (s₁'::stmt) (t'::nat) (is::instr list) s₂::stmt. ⟦(θ::nat ⇒ nat option)⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ data_dependency_consistent_instrs {i::nat. i < t} is; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i::nat. i < t} is› 3. ‹⋀(s₂::stmt) t::nat. valid_sops_stmt t (Seq Skip s₂) ⟹ data_dependency_consistent_instrs {i::nat. i < t} []› 4. ‹⋀(e::expr) (s₁::stmt) (s₂::stmt) t::nat. ⟦∀sop::nat set × ((nat ⇒ nat option) ⇒ nat). e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i::nat. i < t} (issue_expr t e)› 5. ‹⋀(D::nat set) (e::(nat ⇒ nat option) ⇒ nat) (s₁::stmt) (s₂::stmt) t::nat. ⟦D ⊆ dom (θ::nat ⇒ nat option); isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i::nat. i < t} []› 6. ‹⋀(D::nat set) (e::(nat ⇒ nat option) ⇒ nat) (s₁::stmt) (s₂::stmt) t::nat. ⟦D ⊆ dom (θ::nat ⇒ nat option); ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i::nat. i < t} []› 7. ‹⋀(e::expr) (s::stmt) t::nat. valid_sops_stmt t (While e s) ⟹ data_dependency_consistent_instrs {i::nat. i < t} []› 8. ‹⋀(A::(nat ⇒ nat option) ⇒ nat set) (L::(nat ⇒ nat option) ⇒ nat set) (R::(nat ⇒ nat option) ⇒ nat set) (W::(nat ⇒ nat option) ⇒ nat set) t::nat. valid_sops_stmt t (SGhost A L R W) ⟹ data_dependency_consistent_instrs {i::nat. i < t} [Ghost (A (θ::nat ⇒ nat option)) (L θ) (R θ) (W θ)]› 9. ‹⋀t::nat. valid_sops_stmt t SFence ⟹ data_dependency_consistent_instrs {i::nat. i < t} [Fence]›*) case CAS (*‹(D⇩a_::nat set) ⊆ dom (θ::nat ⇒ nat option)› ‹D⇩c_ ⊆ dom θ› ‹eval_expr t_ s⇩e_ = (D_, f_)› ‹valid_sops_stmt t_ (CAS (Tmp (D⇩a_, a_)) (Tmp (D⇩c_, c_)) s⇩e_ A_ L_ R_ W_)›*) thus "?case" (*goal: ‹data_dependency_consistent_instrs {i. i < t_} (issue_expr t_ s⇩e_ @ [RMW (a_ θ) (t_ + used_tmps s⇩e_) (D_, f_) (λθ. the (θ (t_ + used_tmps s⇩e_)) = c_ θ) (λv₁ v₂. v₁) (A_ θ) (L_ θ) (R_ θ) (W_ θ)])›*) by (fastforce simp add: simp add: data_dependency_consistent_instrs_append (*‹data_dependency_consistent_instrs (?T::nat set) ((?xs::instr list) @ (?ys::instr list)) = (data_dependency_consistent_instrs ?T ?xs ∧ data_dependency_consistent_instrs (?T ∪ load_tmps ?xs) ?ys ∧ load_tmps ?ys ∩ ⋃ (fst ` store_sops ?xs) = {})›*) data_dependency_consistent_instrs_issue_expr (*‹data_dependency_consistent_instrs (?T::nat set) (issue_expr (?t::nat) (?e::expr))›*) load_tmps_append (*‹load_tmps ((?xs::instr list) @ (?ys::instr list)) = load_tmps ?xs ∪ load_tmps ?ys›*) dest: dom_eval_expr (*‹⟦valid_sops_expr (?t::nat) (?e::expr); (?x::nat) ∈ fst (eval_expr ?t ?e)⟧ ⟹ ?x ∈ {i::nat. i < ?t} ∪ load_tmps (issue_expr ?t ?e)›*)) next (*goals: 1. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ data_dependency_consistent_instrs {i. i < t} is; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} is› 2. ‹⋀s₂ t. valid_sops_stmt t (Seq Skip s₂) ⟹ data_dependency_consistent_instrs {i. i < t} []› 3. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} (issue_expr t e)› 4. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} []› 5. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} []› 6. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ data_dependency_consistent_instrs {i. i < t} []› 7. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ data_dependency_consistent_instrs {i. i < t} [Ghost (A θ) (L θ) (R θ) (W θ)]› 8. ‹⋀t. valid_sops_stmt t SFence ⟹ data_dependency_consistent_instrs {i. i < t} [Fence]›*) case Seq (*‹(θ::nat ⇒ nat option)⊢ (s₁_::stmt, t_::nat) →⇩s ((s₁'_::stmt, t'_::nat), is_::instr list)› ‹valid_sops_stmt (t_::nat) (s₁_::stmt) ⟹ data_dependency_consistent_instrs {i::nat. i < t_} (is_::instr list)› ‹valid_sops_stmt t_ (Seq s₁_ s₂_)›*) thus "?case" (*goal: ‹data_dependency_consistent_instrs {i. i < t_} is_›*) by (fastforce simp add: simp add: data_dependency_consistent_instrs_append (*‹data_dependency_consistent_instrs (?T::nat set) ((?xs::instr list) @ (?ys::instr list)) = (data_dependency_consistent_instrs ?T ?xs ∧ data_dependency_consistent_instrs (?T ∪ load_tmps ?xs) ?ys ∧ load_tmps ?ys ∩ ⋃ (fst ` store_sops ?xs) = {})›*)) next (*goals: 1. ‹⋀s₂ t. valid_sops_stmt t (Seq Skip s₂) ⟹ data_dependency_consistent_instrs {i. i < t} []› 2. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} (issue_expr t e)› 3. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} []› 4. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} []› 5. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ data_dependency_consistent_instrs {i. i < t} []› 6. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ data_dependency_consistent_instrs {i. i < t} [Ghost (A θ) (L θ) (R θ) (W θ)]› 7. ‹⋀t. valid_sops_stmt t SFence ⟹ data_dependency_consistent_instrs {i. i < t} [Fence]›*) case SeqSkip (*‹valid_sops_stmt t_ (Seq Skip s₂_)›*) thus "?case" (*goal: ‹data_dependency_consistent_instrs {i. i < t_} []›*) by auto next (*goals: 1. ‹⋀(e::expr) (s₁::stmt) (s₂::stmt) t::nat. ⟦∀sop::nat set × ((nat ⇒ nat option) ⇒ nat). e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i::nat. i < t} (issue_expr t e)› 2. ‹⋀(D::nat set) (e::(nat ⇒ nat option) ⇒ nat) (s₁::stmt) (s₂::stmt) t::nat. ⟦D ⊆ dom (θ::nat ⇒ nat option); isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i::nat. i < t} []› 3. ‹⋀(D::nat set) (e::(nat ⇒ nat option) ⇒ nat) (s₁::stmt) (s₂::stmt) t::nat. ⟦D ⊆ dom (θ::nat ⇒ nat option); ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i::nat. i < t} []› 4. ‹⋀(e::expr) (s::stmt) t::nat. valid_sops_stmt t (While e s) ⟹ data_dependency_consistent_instrs {i::nat. i < t} []› 5. ‹⋀(A::(nat ⇒ nat option) ⇒ nat set) (L::(nat ⇒ nat option) ⇒ nat set) (R::(nat ⇒ nat option) ⇒ nat set) (W::(nat ⇒ nat option) ⇒ nat set) t::nat. valid_sops_stmt t (SGhost A L R W) ⟹ data_dependency_consistent_instrs {i::nat. i < t} [Ghost (A (θ::nat ⇒ nat option)) (L θ) (R θ) (W θ)]› 6. ‹⋀t::nat. valid_sops_stmt t SFence ⟹ data_dependency_consistent_instrs {i::nat. i < t} [Fence]›*) case Cond (*‹∀sop. e_ ≠ Tmp sop› ‹valid_sops_stmt t_ (Cond e_ s₁_ s₂_)›*) thus "?case" (*goal: ‹data_dependency_consistent_instrs {i. i < t_} (issue_expr t_ e_)›*) by (fastforce simp add: simp add: data_dependency_consistent_instrs_append (*‹data_dependency_consistent_instrs ?T (?xs @ ?ys) = (data_dependency_consistent_instrs ?T ?xs ∧ data_dependency_consistent_instrs (?T ∪ load_tmps ?xs) ?ys ∧ load_tmps ?ys ∩ ⋃ (fst ` store_sops ?xs) = {})›*) data_dependency_consistent_instrs_issue_expr (*‹data_dependency_consistent_instrs ?T (issue_expr ?t ?e)›*) load_tmps_append (*‹load_tmps (?xs @ ?ys) = load_tmps ?xs ∪ load_tmps ?ys›*) dest: dom_eval_expr (*‹⟦valid_sops_expr ?t ?e; ?x ∈ fst (eval_expr ?t ?e)⟧ ⟹ ?x ∈ {i. i < ?t} ∪ load_tmps (issue_expr ?t ?e)›*)) next (*goals: 1. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} []› 2. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} []› 3. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ data_dependency_consistent_instrs {i. i < t} []› 4. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ data_dependency_consistent_instrs {i. i < t} [Ghost (A θ) (L θ) (R θ) (W θ)]› 5. ‹⋀t. valid_sops_stmt t SFence ⟹ data_dependency_consistent_instrs {i. i < t} [Fence]›*) case CondTrue (*‹D_ ⊆ dom θ› ‹isTrue (e_ θ)› ‹valid_sops_stmt t_ (Cond (Tmp (D_, e_)) s₁_ s₂_)›*) thus "?case" (*goal: ‹data_dependency_consistent_instrs {i. i < t_} []›*) by auto next (*goals: 1. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ data_dependency_consistent_instrs {i. i < t} []› 2. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ data_dependency_consistent_instrs {i. i < t} []› 3. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ data_dependency_consistent_instrs {i. i < t} [Ghost (A θ) (L θ) (R θ) (W θ)]› 4. ‹⋀t. valid_sops_stmt t SFence ⟹ data_dependency_consistent_instrs {i. i < t} [Fence]›*) case CondFalse (*‹D_ ⊆ dom θ› ‹¬ isTrue (e_ θ)› ‹valid_sops_stmt t_ (Cond (Tmp (D_, e_)) s₁_ s₂_)›*) thus "?case" (*goal: ‹data_dependency_consistent_instrs {i. i < t_} []›*) by auto next (*goals: 1. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ data_dependency_consistent_instrs {i. i < t} []› 2. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ data_dependency_consistent_instrs {i. i < t} [Ghost (A θ) (L θ) (R θ) (W θ)]› 3. ‹⋀t. valid_sops_stmt t SFence ⟹ data_dependency_consistent_instrs {i. i < t} [Fence]›*) case While (*‹valid_sops_stmt t_ (While e_ s_)›*) thus "?case" (*goal: ‹data_dependency_consistent_instrs {i. i < t_} []›*) by auto next (*goals: 1. ‹⋀(A::(nat ⇒ nat option) ⇒ nat set) (L::(nat ⇒ nat option) ⇒ nat set) (R::(nat ⇒ nat option) ⇒ nat set) (W::(nat ⇒ nat option) ⇒ nat set) t::nat. valid_sops_stmt t (SGhost A L R W) ⟹ data_dependency_consistent_instrs {i::nat. i < t} [Ghost (A (θ::nat ⇒ nat option)) (L θ) (R θ) (W θ)]› 2. ‹⋀t::nat. valid_sops_stmt t SFence ⟹ data_dependency_consistent_instrs {i::nat. i < t} [Fence]›*) case SGhost (*‹valid_sops_stmt t_ (SGhost A_ L_ R_ W_)›*) thus "?case" (*goal: ‹data_dependency_consistent_instrs {i::nat. i < (t_::nat)} [Ghost ((A_::(nat ⇒ nat option) ⇒ nat set) (θ::nat ⇒ nat option)) ((L_::(nat ⇒ nat option) ⇒ nat set) θ) ((R_::(nat ⇒ nat option) ⇒ nat set) θ) ((W_::(nat ⇒ nat option) ⇒ nat set) θ)]›*) by auto next (*goal: ‹⋀t. valid_sops_stmt t SFence ⟹ data_dependency_consistent_instrs {i. i < t} [Fence]›*) case SFence (*‹valid_sops_stmt t_ SFence›*) thus "?case" (*goal: ‹data_dependency_consistent_instrs {i. i < t_} [Fence]›*) by auto qed lemma sbh_valid_data_dependency_prog_step: assumes step: "θ⊢(s,t) →⇩s ((s',t'),is')" assumes store_sops_le: "∀i ∈ ⋃(fst ` store_sops is). i < t" assumes write_sops_le: "∀i ∈ ⋃(fst ` write_sops sb). i < t" assumes valid: "valid_sops_stmt t s" shows "data_dependency_consistent_instrs ({i. i < t}) is' ∧ load_tmps is' ∩ ⋃(fst ` store_sops is) = {} ∧ load_tmps is' ∩ ⋃(fst ` write_sops sb) = {}" proof (-) (*goal: ‹data_dependency_consistent_instrs {i. i < t} is' ∧ load_tmps is' ∩ ⋃ (fst ` store_sops is) = {} ∧ load_tmps is' ∩ ⋃ (fst ` write_sops sb) = {}›*) from stmt_step_data_dependency_consistent_instrs[OF step valid] (*‹data_dependency_consistent_instrs {i. i < t} is'›*) stmt_step_load_tmps_range[OF step] (*‹∀i∈load_tmps is'. t ≤ i ∧ i < t'›*) store_sops_le (*‹∀i∈⋃ (fst ` store_sops is). i < t›*) write_sops_le (*‹∀i∈⋃ (fst ` write_sops sb). i < t›*) show "?thesis" (*goal: ‹data_dependency_consistent_instrs {i. i < t} is' ∧ load_tmps is' ∩ ⋃ (fst ` store_sops is) = {} ∧ load_tmps is' ∩ ⋃ (fst ` write_sops sb) = {}›*) by fastforce qed lemma sbh_load_tmps_fresh_prog_step: assumes step: "θ⊢(s,t) →⇩s ((s',t'),is')" assumes tmps_le: "∀i ∈ dom θ. i < t" shows "load_tmps is' ∩ dom θ = {}" sorry lemma sbh_valid_sops_prog_step: assumes step: "θ⊢(s,t) →⇩s ((s',t'),is)" assumes valid: "valid_sops_stmt t s" shows "∀sop∈store_sops is. valid_sop sop" using step (*‹θ⊢ (s, t) →⇩s ((s', t'), is)›*) valid (*‹valid_sops_stmt t s›*) proof (induct x=="(s,t)" y=="((s',t'),is)" arbitrary: s t s' t' "is" rule: stmt_step.induct) (*goals: 1. ‹⋀(a::expr) (volatile::bool) (e::expr) (A::(nat ⇒ nat option) ⇒ nat set) (L::(nat ⇒ nat option) ⇒ nat set) (R::(nat ⇒ nat option) ⇒ nat set) (W::(nat ⇒ nat option) ⇒ nat set) t::nat. ⟦∀sop::nat set × ((nat ⇒ nat option) ⇒ nat). a ≠ Tmp sop; valid_sops_stmt t (Assign volatile a e A L R W)⟧ ⟹ Ball (store_sops (issue_expr t a)) valid_sop› 2. ‹⋀(D::nat set) (volatile::bool) (a::(nat ⇒ nat option) ⇒ nat) (e::expr) (A::(nat ⇒ nat option) ⇒ nat set) (L::(nat ⇒ nat option) ⇒ nat set) (R::(nat ⇒ nat option) ⇒ nat set) (W::(nat ⇒ nat option) ⇒ nat set) t::nat. ⟦D ⊆ dom (θ::nat ⇒ nat option); valid_sops_stmt t (Assign volatile (Tmp (D, a)) e A L R W)⟧ ⟹ Ball (store_sops (issue_expr t e @ [Write volatile (a θ) (eval_expr t e) (A θ) (L θ) (R θ) (W θ)])) valid_sop› 3. ‹⋀(a::expr) (c⇩e::expr) (s⇩e::expr) (A::(nat ⇒ nat option) ⇒ nat set) (L::(nat ⇒ nat option) ⇒ nat set) (R::(nat ⇒ nat option) ⇒ nat set) (W::(nat ⇒ nat option) ⇒ nat set) t::nat. ⟦∀sop::nat set × ((nat ⇒ nat option) ⇒ nat). a ≠ Tmp sop; valid_sops_stmt t (CAS a c⇩e s⇩e A L R W)⟧ ⟹ Ball (store_sops (issue_expr t a)) valid_sop› 4. ‹⋀(c⇩e::expr) (D⇩a::nat set) (a::(nat ⇒ nat option) ⇒ nat) (s⇩e::expr) (A::(nat ⇒ nat option) ⇒ nat set) (L::(nat ⇒ nat option) ⇒ nat set) (R::(nat ⇒ nat option) ⇒ nat set) (W::(nat ⇒ nat option) ⇒ nat set) t::nat. ⟦∀sop::nat set × ((nat ⇒ nat option) ⇒ nat). c⇩e ≠ Tmp sop; valid_sops_stmt t (CAS (Tmp (D⇩a, a)) c⇩e s⇩e A L R W)⟧ ⟹ Ball (store_sops (issue_expr t c⇩e)) valid_sop› 5. ‹⋀(D⇩a::nat set) (D⇩c::nat set) (t::nat) (s⇩e::expr) (D::nat set) (f::(nat ⇒ nat option) ⇒ nat) (a::(nat ⇒ nat option) ⇒ nat) (c::(nat ⇒ nat option) ⇒ nat) (A::(nat ⇒ nat option) ⇒ nat set) (L::(nat ⇒ nat option) ⇒ nat set) (R::(nat ⇒ nat option) ⇒ nat set) W::(nat ⇒ nat option) ⇒ nat set. ⟦D⇩a ⊆ dom (θ::nat ⇒ nat option); D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f); valid_sops_stmt t (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W)⟧ ⟹ Ball (store_sops (issue_expr t s⇩e @ [RMW (a θ) (t + used_tmps s⇩e) (D, f) (λθ::nat ⇒ nat option. the (θ (t + used_tmps s⇩e)) = c θ) (λ(v₁::nat) v₂::nat. v₁) (A θ) (L θ) (R θ) (W θ)])) valid_sop› 6. ‹⋀(s₁::stmt) (t::nat) (s₁'::stmt) (t'::nat) (is::instr list) s₂::stmt. ⟦(θ::nat ⇒ nat option)⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ Ball (store_sops is) valid_sop; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ Ball (store_sops is) valid_sop› 7. ‹⋀(s₂::stmt) t::nat. valid_sops_stmt t (Seq Skip s₂) ⟹ Ball (store_sops []) valid_sop› 8. ‹⋀(e::expr) (s₁::stmt) (s₂::stmt) t::nat. ⟦∀sop::nat set × ((nat ⇒ nat option) ⇒ nat). e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ Ball (store_sops (issue_expr t e)) valid_sop› 9. ‹⋀(D::nat set) (e::(nat ⇒ nat option) ⇒ nat) (s₁::stmt) (s₂::stmt) t::nat. ⟦D ⊆ dom (θ::nat ⇒ nat option); isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ Ball (store_sops []) valid_sop› 10. ‹⋀(D::nat set) (e::(nat ⇒ nat option) ⇒ nat) (s₁::stmt) (s₂::stmt) t::nat. ⟦D ⊆ dom (θ::nat ⇒ nat option); ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ Ball (store_sops []) valid_sop› 11. ‹⋀(e::expr) (s::stmt) t::nat. valid_sops_stmt t (While e s) ⟹ Ball (store_sops []) valid_sop› 12. ‹⋀(A::(nat ⇒ nat option) ⇒ nat set) (L::(nat ⇒ nat option) ⇒ nat set) (R::(nat ⇒ nat option) ⇒ nat set) (W::(nat ⇒ nat option) ⇒ nat set) t::nat. valid_sops_stmt t (SGhost A L R W) ⟹ Ball (store_sops [Ghost (A (θ::nat ⇒ nat option)) (L θ) (R θ) (W θ)]) valid_sop› 13. ‹⋀t::nat. valid_sops_stmt t SFence ⟹ Ball (store_sops [Fence]) valid_sop›*) case AssignAddr (*‹∀sop. a_ ≠ Tmp sop› ‹valid_sops_stmt t_ (Assign volatile_ a_ e_ A_ L_ R_ W_)›*) thus "?case" (*goal: ‹Ball (store_sops (issue_expr t_ a_)) valid_sop›*) by auto next (*goals: 1. ‹⋀D volatile a e A L R W t. ⟦D ⊆ dom θ; valid_sops_stmt t (Assign volatile (Tmp (D, a)) e A L R W)⟧ ⟹ Ball (store_sops (issue_expr t e @ [Write volatile (a θ) (eval_expr t e) (A θ) (L θ) (R θ) (W θ)])) valid_sop› 2. ‹⋀a c⇩e s⇩e A L R W t. ⟦∀sop. a ≠ Tmp sop; valid_sops_stmt t (CAS a c⇩e s⇩e A L R W)⟧ ⟹ Ball (store_sops (issue_expr t a)) valid_sop› 3. ‹⋀c⇩e D⇩a a s⇩e A L R W t. ⟦∀sop. c⇩e ≠ Tmp sop; valid_sops_stmt t (CAS (Tmp (D⇩a, a)) c⇩e s⇩e A L R W)⟧ ⟹ Ball (store_sops (issue_expr t c⇩e)) valid_sop› 4. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f); valid_sops_stmt t (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W)⟧ ⟹ Ball (store_sops (issue_expr t s⇩e @ [RMW (a θ) (t + used_tmps s⇩e) (D, f) (λθ. the (θ (t + used_tmps s⇩e)) = c θ) (λv₁ v₂. v₁) (A θ) (L θ) (R θ) (W θ)])) valid_sop› 5. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ Ball (store_sops is) valid_sop; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ Ball (store_sops is) valid_sop› 6. ‹⋀s₂ t. valid_sops_stmt t (Seq Skip s₂) ⟹ Ball (store_sops []) valid_sop› 7. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ Ball (store_sops (issue_expr t e)) valid_sop› 8. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ Ball (store_sops []) valid_sop› 9. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ Ball (store_sops []) valid_sop› 10. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ Ball (store_sops []) valid_sop› 11. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ Ball (store_sops [Ghost (A θ) (L θ) (R θ) (W θ)]) valid_sop› 12. ‹⋀t. valid_sops_stmt t SFence ⟹ Ball (store_sops [Fence]) valid_sop›*) case Assign (*‹D_ ⊆ dom θ› ‹valid_sops_stmt t_ (Assign volatile_ (Tmp (D_, a_)) e_ A_ L_ R_ W_)›*) thus "?case" (*goal: ‹Ball (store_sops (issue_expr t_ e_ @ [Write volatile_ (a_ θ) (eval_expr t_ e_) (A_ θ) (L_ θ) (R_ θ) (W_ θ)])) valid_sop›*) by (auto simp add: store_sops_append (*‹store_sops (?xs @ ?ys) = store_sops ?xs ∪ store_sops ?ys›*) valid_sops_expr_valid_sop (*‹valid_sops_expr ?t ?e ⟹ valid_sop (eval_expr ?t ?e)›*)) next (*goals: 1. ‹⋀a c⇩e s⇩e A L R W t. ⟦∀sop. a ≠ Tmp sop; valid_sops_stmt t (CAS a c⇩e s⇩e A L R W)⟧ ⟹ Ball (store_sops (issue_expr t a)) valid_sop› 2. ‹⋀c⇩e D⇩a a s⇩e A L R W t. ⟦∀sop. c⇩e ≠ Tmp sop; valid_sops_stmt t (CAS (Tmp (D⇩a, a)) c⇩e s⇩e A L R W)⟧ ⟹ Ball (store_sops (issue_expr t c⇩e)) valid_sop› 3. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f); valid_sops_stmt t (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W)⟧ ⟹ Ball (store_sops (issue_expr t s⇩e @ [RMW (a θ) (t + used_tmps s⇩e) (D, f) (λθ. the (θ (t + used_tmps s⇩e)) = c θ) (λv₁ v₂. v₁) (A θ) (L θ) (R θ) (W θ)])) valid_sop› 4. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ Ball (store_sops is) valid_sop; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ Ball (store_sops is) valid_sop› 5. ‹⋀s₂ t. valid_sops_stmt t (Seq Skip s₂) ⟹ Ball (store_sops []) valid_sop› 6. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ Ball (store_sops (issue_expr t e)) valid_sop› 7. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ Ball (store_sops []) valid_sop› 8. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ Ball (store_sops []) valid_sop› 9. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ Ball (store_sops []) valid_sop› 10. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ Ball (store_sops [Ghost (A θ) (L θ) (R θ) (W θ)]) valid_sop› 11. ‹⋀t. valid_sops_stmt t SFence ⟹ Ball (store_sops [Fence]) valid_sop›*) case CASAddr (*‹∀sop. a_ ≠ Tmp sop› ‹valid_sops_stmt t_ (CAS a_ c⇩e_ s⇩e_ A_ L_ R_ W_)›*) thus "?case" (*goal: ‹Ball (store_sops (issue_expr t_ a_)) valid_sop›*) by auto next (*goals: 1. ‹⋀c⇩e D⇩a a s⇩e A L R W t. ⟦∀sop. c⇩e ≠ Tmp sop; valid_sops_stmt t (CAS (Tmp (D⇩a, a)) c⇩e s⇩e A L R W)⟧ ⟹ Ball (store_sops (issue_expr t c⇩e)) valid_sop› 2. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f); valid_sops_stmt t (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W)⟧ ⟹ Ball (store_sops (issue_expr t s⇩e @ [RMW (a θ) (t + used_tmps s⇩e) (D, f) (λθ. the (θ (t + used_tmps s⇩e)) = c θ) (λv₁ v₂. v₁) (A θ) (L θ) (R θ) (W θ)])) valid_sop› 3. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ Ball (store_sops is) valid_sop; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ Ball (store_sops is) valid_sop› 4. ‹⋀s₂ t. valid_sops_stmt t (Seq Skip s₂) ⟹ Ball (store_sops []) valid_sop› 5. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ Ball (store_sops (issue_expr t e)) valid_sop› 6. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ Ball (store_sops []) valid_sop› 7. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ Ball (store_sops []) valid_sop› 8. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ Ball (store_sops []) valid_sop› 9. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ Ball (store_sops [Ghost (A θ) (L θ) (R θ) (W θ)]) valid_sop› 10. ‹⋀t. valid_sops_stmt t SFence ⟹ Ball (store_sops [Fence]) valid_sop›*) case CASComp (*‹∀sop::nat set × ((nat ⇒ nat option) ⇒ nat). (c⇩e_::expr) ≠ Tmp sop› ‹valid_sops_stmt t_ (CAS (Tmp (D⇩a_, a_)) c⇩e_ s⇩e_ A_ L_ R_ W_)›*) thus "?case" (*goal: ‹Ball (store_sops (issue_expr t_ c⇩e_)) valid_sop›*) by auto next (*goals: 1. ‹⋀D⇩a D⇩c t s⇩e D f a c A L R W. ⟦D⇩a ⊆ dom θ; D⇩c ⊆ dom θ; eval_expr t s⇩e = (D, f); valid_sops_stmt t (CAS (Tmp (D⇩a, a)) (Tmp (D⇩c, c)) s⇩e A L R W)⟧ ⟹ Ball (store_sops (issue_expr t s⇩e @ [RMW (a θ) (t + used_tmps s⇩e) (D, f) (λθ. the (θ (t + used_tmps s⇩e)) = c θ) (λv₁ v₂. v₁) (A θ) (L θ) (R θ) (W θ)])) valid_sop› 2. ‹⋀s₁ t s₁' t' is s₂. ⟦θ⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ Ball (store_sops is) valid_sop; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ Ball (store_sops is) valid_sop› 3. ‹⋀s₂ t. valid_sops_stmt t (Seq Skip s₂) ⟹ Ball (store_sops []) valid_sop› 4. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ Ball (store_sops (issue_expr t e)) valid_sop› 5. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ Ball (store_sops []) valid_sop› 6. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ Ball (store_sops []) valid_sop› 7. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ Ball (store_sops []) valid_sop› 8. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ Ball (store_sops [Ghost (A θ) (L θ) (R θ) (W θ)]) valid_sop› 9. ‹⋀t. valid_sops_stmt t SFence ⟹ Ball (store_sops [Fence]) valid_sop›*) case CAS (*‹(D⇩a_::nat set) ⊆ dom (θ::nat ⇒ nat option)› ‹D⇩c_ ⊆ dom θ› ‹eval_expr t_ s⇩e_ = (D_, f_)› ‹valid_sops_stmt (t_::nat) (CAS (Tmp (D⇩a_::nat set, a_::(nat ⇒ nat option) ⇒ nat)) (Tmp (D⇩c_::nat set, c_::(nat ⇒ nat option) ⇒ nat)) (s⇩e_::expr) (A_::(nat ⇒ nat option) ⇒ nat set) (L_::(nat ⇒ nat option) ⇒ nat set) (R_::(nat ⇒ nat option) ⇒ nat set) (W_::(nat ⇒ nat option) ⇒ nat set))›*) thus "?case" (*goal: ‹Ball (store_sops (issue_expr t_ s⇩e_ @ [RMW (a_ θ) (t_ + used_tmps s⇩e_) (D_, f_) (λθ. the (θ (t_ + used_tmps s⇩e_)) = c_ θ) (λv₁ v₂. v₁) (A_ θ) (L_ θ) (R_ θ) (W_ θ)])) valid_sop›*) by (fastforce simp add: store_sops_append (*‹store_sops (?xs @ ?ys) = store_sops ?xs ∪ store_sops ?ys›*) dest: valid_sops_expr_valid_sop (*‹valid_sops_expr ?t ?e ⟹ valid_sop (eval_expr ?t ?e)›*)) next (*goals: 1. ‹⋀(s₁::stmt) (t::nat) (s₁'::stmt) (t'::nat) (is::instr list) s₂::stmt. ⟦(θ::nat ⇒ nat option)⊢ (s₁, t) →⇩s ((s₁', t'), is); valid_sops_stmt t s₁ ⟹ Ball (store_sops is) valid_sop; valid_sops_stmt t (Seq s₁ s₂)⟧ ⟹ Ball (store_sops is) valid_sop› 2. ‹⋀(s₂::stmt) t::nat. valid_sops_stmt t (Seq Skip s₂) ⟹ Ball (store_sops []) valid_sop› 3. ‹⋀(e::expr) (s₁::stmt) (s₂::stmt) t::nat. ⟦∀sop::nat set × ((nat ⇒ nat option) ⇒ nat). e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ Ball (store_sops (issue_expr t e)) valid_sop› 4. ‹⋀(D::nat set) (e::(nat ⇒ nat option) ⇒ nat) (s₁::stmt) (s₂::stmt) t::nat. ⟦D ⊆ dom (θ::nat ⇒ nat option); isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ Ball (store_sops []) valid_sop› 5. ‹⋀(D::nat set) (e::(nat ⇒ nat option) ⇒ nat) (s₁::stmt) (s₂::stmt) t::nat. ⟦D ⊆ dom (θ::nat ⇒ nat option); ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ Ball (store_sops []) valid_sop› 6. ‹⋀(e::expr) (s::stmt) t::nat. valid_sops_stmt t (While e s) ⟹ Ball (store_sops []) valid_sop› 7. ‹⋀(A::(nat ⇒ nat option) ⇒ nat set) (L::(nat ⇒ nat option) ⇒ nat set) (R::(nat ⇒ nat option) ⇒ nat set) (W::(nat ⇒ nat option) ⇒ nat set) t::nat. valid_sops_stmt t (SGhost A L R W) ⟹ Ball (store_sops [Ghost (A (θ::nat ⇒ nat option)) (L θ) (R θ) (W θ)]) valid_sop› 8. ‹⋀t::nat. valid_sops_stmt t SFence ⟹ Ball (store_sops [Fence]) valid_sop›*) case Seq (*‹(θ::nat ⇒ nat option)⊢ (s₁_::stmt, t_::nat) →⇩s ((s₁'_::stmt, t'_::nat), is_::instr list)› ‹valid_sops_stmt t_ s₁_ ⟹ Ball (store_sops is_) valid_sop› ‹valid_sops_stmt t_ (Seq s₁_ s₂_)›*) thus "?case" (*goal: ‹Ball (store_sops is_) valid_sop›*) by (force intro: valid_sops_stmt_mono (*‹⟦valid_sops_stmt ?t ?s; ?t ≤ ?t'⟧ ⟹ valid_sops_stmt ?t' ?s›*)) next (*goals: 1. ‹⋀s₂ t. valid_sops_stmt t (Seq Skip s₂) ⟹ Ball (store_sops []) valid_sop› 2. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ Ball (store_sops (issue_expr t e)) valid_sop› 3. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ Ball (store_sops []) valid_sop› 4. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ Ball (store_sops []) valid_sop› 5. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ Ball (store_sops []) valid_sop› 6. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ Ball (store_sops [Ghost (A θ) (L θ) (R θ) (W θ)]) valid_sop› 7. ‹⋀t. valid_sops_stmt t SFence ⟹ Ball (store_sops [Fence]) valid_sop›*) case SeqSkip (*‹valid_sops_stmt t_ (Seq Skip s₂_)›*) thus "?case" (*goal: ‹Ball (store_sops []) valid_sop›*) by simp next (*goals: 1. ‹⋀e s₁ s₂ t. ⟦∀sop. e ≠ Tmp sop; valid_sops_stmt t (Cond e s₁ s₂)⟧ ⟹ Ball (store_sops (issue_expr t e)) valid_sop› 2. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ Ball (store_sops []) valid_sop› 3. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ Ball (store_sops []) valid_sop› 4. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ Ball (store_sops []) valid_sop› 5. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ Ball (store_sops [Ghost (A θ) (L θ) (R θ) (W θ)]) valid_sop› 6. ‹⋀t. valid_sops_stmt t SFence ⟹ Ball (store_sops [Fence]) valid_sop›*) case Cond (*‹∀sop. e_ ≠ Tmp sop› ‹valid_sops_stmt t_ (Cond e_ s₁_ s₂_)›*) thus "?case" (*goal: ‹Ball (store_sops (issue_expr t_ e_)) valid_sop›*) by auto next (*goals: 1. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ Ball (store_sops []) valid_sop› 2. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ Ball (store_sops []) valid_sop› 3. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ Ball (store_sops []) valid_sop› 4. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ Ball (store_sops [Ghost (A θ) (L θ) (R θ) (W θ)]) valid_sop› 5. ‹⋀t. valid_sops_stmt t SFence ⟹ Ball (store_sops [Fence]) valid_sop›*) case CondTrue (*‹(D_::nat set) ⊆ dom (θ::nat ⇒ nat option)› ‹isTrue (e_ θ)› ‹valid_sops_stmt t_ (Cond (Tmp (D_, e_)) s₁_ s₂_)›*) thus "?case" (*goal: ‹Ball (store_sops []) valid_sop›*) by auto next (*goals: 1. ‹⋀D e s₁ s₂ t. ⟦D ⊆ dom θ; ¬ isTrue (e θ); valid_sops_stmt t (Cond (Tmp (D, e)) s₁ s₂)⟧ ⟹ Ball (store_sops []) valid_sop› 2. ‹⋀e s t. valid_sops_stmt t (While e s) ⟹ Ball (store_sops []) valid_sop› 3. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ Ball (store_sops [Ghost (A θ) (L θ) (R θ) (W θ)]) valid_sop› 4. ‹⋀t. valid_sops_stmt t SFence ⟹ Ball (store_sops [Fence]) valid_sop›*) case CondFalse (*‹D_ ⊆ dom θ› ‹¬ isTrue (e_ θ)› ‹valid_sops_stmt t_ (Cond (Tmp (D_, e_)) s₁_ s₂_)›*) thus "?case" (*goal: ‹Ball (store_sops []) valid_sop›*) by auto next (*goals: 1. ‹⋀(e::expr) (s::stmt) t::nat. valid_sops_stmt t (While e s) ⟹ Ball (store_sops []) valid_sop› 2. ‹⋀(A::(nat ⇒ nat option) ⇒ nat set) (L::(nat ⇒ nat option) ⇒ nat set) (R::(nat ⇒ nat option) ⇒ nat set) (W::(nat ⇒ nat option) ⇒ nat set) t::nat. valid_sops_stmt t (SGhost A L R W) ⟹ Ball (store_sops [Ghost (A (θ::nat ⇒ nat option)) (L θ) (R θ) (W θ)]) valid_sop› 3. ‹⋀t::nat. valid_sops_stmt t SFence ⟹ Ball (store_sops [Fence]) valid_sop›*) case While (*‹valid_sops_stmt (t_::nat) (While (e_::expr) (s_::stmt))›*) thus "?case" (*goal: ‹Ball (store_sops []) valid_sop›*) by auto next (*goals: 1. ‹⋀A L R W t. valid_sops_stmt t (SGhost A L R W) ⟹ Ball (store_sops [Ghost (A θ) (L θ) (R θ) (W θ)]) valid_sop› 2. ‹⋀t. valid_sops_stmt t SFence ⟹ Ball (store_sops [Fence]) valid_sop›*) case SGhost (*‹valid_sops_stmt (t_::nat) (SGhost (A_::(nat ⇒ nat option) ⇒ nat set) (L_::(nat ⇒ nat option) ⇒ nat set) (R_::(nat ⇒ nat option) ⇒ nat set) (W_::(nat ⇒ nat option) ⇒ nat set))›*) thus "?case" (*goal: ‹Ball (store_sops [Ghost (A_ θ) (L_ θ) (R_ θ) (W_ θ)]) valid_sop›*) by auto next (*goal: ‹⋀t::nat. valid_sops_stmt t SFence ⟹ Ball (store_sops [Fence]) valid_sop›*) case SFence (*‹valid_sops_stmt t_ SFence›*) thus "?case" (*goal: ‹Ball (store_sops [Fence]) valid_sop›*) by auto qed primrec prog_configs:: "'a memref list ⇒ 'a set" where "prog_configs [] = {}" |"prog_configs (x#xs) = (case x of Prog⇩s⇩b p p' is ⇒ {p,p'} ∪ prog_configs xs | _ ⇒ prog_configs xs)" lemma prog_configs_append: "⋀ys. prog_configs (xs@ys) = prog_configs xs ∪ prog_configs ys" apply (induct xs) (*goals: 1. ‹⋀ys::'a::type memref list. prog_configs ([] @ ys) = prog_configs [] ∪ prog_configs ys› 2. ‹⋀(a::'a::type memref) (xs::'a::type memref list) ys::'a::type memref list. (⋀ys::'a::type memref list. prog_configs (xs @ ys) = prog_configs xs ∪ prog_configs ys) ⟹ prog_configs ((a # xs) @ ys) = prog_configs (a # xs) ∪ prog_configs ys› discuss goal 1*) apply ((auto split: memref.splits (*‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = ((∀x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ⟶ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∧ (∀x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ⟶ ?P (?f2.0 x21 x22 x23 x24)) ∧ (∀x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ⟶ ?P (?f3.0 x31 x32 x33)) ∧ (∀x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ⟶ ?P (?f4.0 x41 x42 x43 x44)))› ‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = (¬ ((∃x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ∧ ¬ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∨ (∃x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ∧ ¬ ?P (?f2.0 x21 x22 x23 x24)) ∨ (∃x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ∧ ¬ ?P (?f3.0 x31 x32 x33)) ∨ (∃x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ∧ ¬ ?P (?f4.0 x41 x42 x43 x44))))›*))[1]) (*discuss goal 2*) apply ((auto split: memref.splits (*‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = ((∀x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ⟶ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∧ (∀x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ⟶ ?P (?f2.0 x21 x22 x23 x24)) ∧ (∀x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ⟶ ?P (?f3.0 x31 x32 x33)) ∧ (∀x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ⟶ ?P (?f4.0 x41 x42 x43 x44)))› ‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = (¬ ((∃x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ∧ ¬ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∨ (∃x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ∧ ¬ ?P (?f2.0 x21 x22 x23 x24)) ∨ (∃x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ∧ ¬ ?P (?f3.0 x31 x32 x33)) ∨ (∃x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ∧ ¬ ?P (?f4.0 x41 x42 x43 x44))))›*))[1]) (*proven 2 subgoals*) . lemma prog_configs_in1: "Prog⇩s⇩b p₁ p₂ is ∈ set xs ⟹ p₁ ∈ prog_configs xs" apply (induct xs) (*goals: 1. ‹Prog⇩s⇩b p₁ p₂ is ∈ set [] ⟹ p₁ ∈ prog_configs []› 2. ‹⋀a xs. ⟦Prog⇩s⇩b p₁ p₂ is ∈ set xs ⟹ p₁ ∈ prog_configs xs; Prog⇩s⇩b p₁ p₂ is ∈ set (a # xs)⟧ ⟹ p₁ ∈ prog_configs (a # xs)› discuss goal 1*) apply ((auto split: memref.splits (*‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = ((∀x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ⟶ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∧ (∀x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ⟶ ?P (?f2.0 x21 x22 x23 x24)) ∧ (∀x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ⟶ ?P (?f3.0 x31 x32 x33)) ∧ (∀x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ⟶ ?P (?f4.0 x41 x42 x43 x44)))› ‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = (¬ ((∃x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ∧ ¬ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∨ (∃x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ∧ ¬ ?P (?f2.0 x21 x22 x23 x24)) ∨ (∃x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ∧ ¬ ?P (?f3.0 x31 x32 x33)) ∨ (∃x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ∧ ¬ ?P (?f4.0 x41 x42 x43 x44))))›*))[1]) (*discuss goal 2*) apply ((auto split: memref.splits (*‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = ((∀x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ⟶ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∧ (∀x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ⟶ ?P (?f2.0 x21 x22 x23 x24)) ∧ (∀x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ⟶ ?P (?f3.0 x31 x32 x33)) ∧ (∀x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ⟶ ?P (?f4.0 x41 x42 x43 x44)))› ‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = (¬ ((∃x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ∧ ¬ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∨ (∃x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ∧ ¬ ?P (?f2.0 x21 x22 x23 x24)) ∨ (∃x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ∧ ¬ ?P (?f3.0 x31 x32 x33)) ∨ (∃x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ∧ ¬ ?P (?f4.0 x41 x42 x43 x44))))›*))[1]) (*proven 2 subgoals*) . lemma prog_configs_in2: "Prog⇩s⇩b p₁ p₂ is ∈ set xs ⟹ p₂ ∈ prog_configs xs" apply (induct xs) (*goals: 1. ‹Prog⇩s⇩b p₁ p₂ is ∈ set [] ⟹ p₂ ∈ prog_configs []› 2. ‹⋀a xs. ⟦Prog⇩s⇩b p₁ p₂ is ∈ set xs ⟹ p₂ ∈ prog_configs xs; Prog⇩s⇩b p₁ p₂ is ∈ set (a # xs)⟧ ⟹ p₂ ∈ prog_configs (a # xs)› discuss goal 1*) apply ((auto split: memref.splits (*‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = ((∀x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ⟶ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∧ (∀x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ⟶ ?P (?f2.0 x21 x22 x23 x24)) ∧ (∀x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ⟶ ?P (?f3.0 x31 x32 x33)) ∧ (∀x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ⟶ ?P (?f4.0 x41 x42 x43 x44)))› ‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = (¬ ((∃x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ∧ ¬ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∨ (∃x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ∧ ¬ ?P (?f2.0 x21 x22 x23 x24)) ∨ (∃x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ∧ ¬ ?P (?f3.0 x31 x32 x33)) ∨ (∃x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ∧ ¬ ?P (?f4.0 x41 x42 x43 x44))))›*))[1]) (*discuss goal 2*) apply ((auto split: memref.splits (*‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = ((∀x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ⟶ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∧ (∀x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ⟶ ?P (?f2.0 x21 x22 x23 x24)) ∧ (∀x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ⟶ ?P (?f3.0 x31 x32 x33)) ∧ (∀x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ⟶ ?P (?f4.0 x41 x42 x43 x44)))› ‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = (¬ ((∃x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ∧ ¬ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∨ (∃x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ∧ ¬ ?P (?f2.0 x21 x22 x23 x24)) ∨ (∃x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ∧ ¬ ?P (?f3.0 x31 x32 x33)) ∨ (∃x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ∧ ¬ ?P (?f4.0 x41 x42 x43 x44))))›*))[1]) (*proven 2 subgoals*) . lemma prog_configs_mono: "⋀ys. set xs ⊆ set ys ⟹ prog_configs xs ⊆ prog_configs ys" apply (induct xs) (*goals: 1. ‹⋀ys. set [] ⊆ set ys ⟹ prog_configs [] ⊆ prog_configs ys› 2. ‹⋀a xs ys. ⟦⋀ys. set xs ⊆ set ys ⟹ prog_configs xs ⊆ prog_configs ys; set (a # xs) ⊆ set ys⟧ ⟹ prog_configs (a # xs) ⊆ prog_configs ys› discuss goal 1*) apply ((auto split: memref.splits (*‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = ((∀x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ⟶ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∧ (∀x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ⟶ ?P (?f2.0 x21 x22 x23 x24)) ∧ (∀x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ⟶ ?P (?f3.0 x31 x32 x33)) ∧ (∀x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ⟶ ?P (?f4.0 x41 x42 x43 x44)))› ‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = (¬ ((∃x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ∧ ¬ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∨ (∃x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ∧ ¬ ?P (?f2.0 x21 x22 x23 x24)) ∨ (∃x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ∧ ¬ ?P (?f3.0 x31 x32 x33)) ∨ (∃x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ∧ ¬ ?P (?f4.0 x41 x42 x43 x44))))›*) simp add: prog_configs_append (*‹prog_configs (?xs @ ?ys) = prog_configs ?xs ∪ prog_configs ?ys›*) prog_configs_in1 (*‹Prog⇩s⇩b ?p₁ ?p₂ ?is ∈ set ?xs ⟹ ?p₁ ∈ prog_configs ?xs›*) prog_configs_in2 (*‹Prog⇩s⇩b ?p₁ ?p₂ ?is ∈ set ?xs ⟹ ?p₂ ∈ prog_configs ?xs›*))[1]) (*discuss goal 2*) apply ((auto split: memref.splits (*‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = ((∀x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ⟶ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∧ (∀x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ⟶ ?P (?f2.0 x21 x22 x23 x24)) ∧ (∀x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ⟶ ?P (?f3.0 x31 x32 x33)) ∧ (∀x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ⟶ ?P (?f4.0 x41 x42 x43 x44)))› ‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = (¬ ((∃x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ∧ ¬ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∨ (∃x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ∧ ¬ ?P (?f2.0 x21 x22 x23 x24)) ∨ (∃x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ∧ ¬ ?P (?f3.0 x31 x32 x33)) ∨ (∃x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ∧ ¬ ?P (?f4.0 x41 x42 x43 x44))))›*) simp add: prog_configs_append (*‹prog_configs (?xs @ ?ys) = prog_configs ?xs ∪ prog_configs ?ys›*) prog_configs_in1 (*‹Prog⇩s⇩b ?p₁ ?p₂ ?is ∈ set ?xs ⟹ ?p₁ ∈ prog_configs ?xs›*) prog_configs_in2 (*‹Prog⇩s⇩b ?p₁ ?p₂ ?is ∈ set ?xs ⟹ ?p₂ ∈ prog_configs ?xs›*))[1]) (*proven 2 subgoals*) . locale separated_tmps = fixes ts assumes valid_sops_stmt: "⟦i < length ts; ts!i = ((s,t),is,θ,sb,𝒟,𝒪)⟧ ⟹ valid_sops_stmt t s" assumes valid_sops_stmt_sb: "⟦i < length ts; ts!i = ((s,t),is,θ,sb,𝒟,𝒪); (s',t') ∈ prog_configs sb⟧ ⟹ valid_sops_stmt t' s'" assumes load_tmps_le: "⟦i < length ts; ts!i = ((s,t),is,θ,sb,𝒟,𝒪)⟧ ⟹ ∀i ∈ load_tmps is. i < t" assumes read_tmps_le: "⟦i < length ts; ts!i = ((s,t),is,θ,sb,𝒟,𝒪)⟧ ⟹ ∀i ∈ read_tmps sb. i < t" assumes store_sops_le: "⟦i < length ts; ts!i = ((s,t),is,θ,sb,𝒟,𝒪)⟧ ⟹ ∀i ∈ ⋃(fst ` store_sops is). i < t" assumes write_sops_le: "⟦i < length ts; ts!i = ((s,t),is,θ,sb,𝒟,𝒪)⟧ ⟹ ∀i ∈ ⋃(fst ` write_sops sb). i < t" assumes tmps_le: "⟦i < length ts; ts!i = ((s,t),is,θ,sb,𝒟,𝒪)⟧ ⟹ dom θ ∪ load_tmps is = {i. i < t}" lemma (in separated_tmps) tmps_le': assumes i_bound: "i < length ts" assumes ts_i: "ts!i = ((s,t),is,θ,sb,𝒟,𝒪)" shows "∀i ∈ dom θ. i < t" using tmps_le[OF i_bound ts_i] (*‹dom θ ∪ load_tmps is = {i. i < t}›*) by auto lemma (in separated_tmps) separated_tmps_nth_update: "⟦i < length ts; valid_sops_stmt t s; ∀(s',t') ∈ prog_configs sb. valid_sops_stmt t' s'; ∀i ∈ load_tmps is. i < t;∀i ∈ read_tmps sb. i < t; ∀i ∈ ⋃(fst ` store_sops is). i < t; ∀i ∈ ⋃(fst ` write_sops sb). i < t; dom θ ∪ load_tmps is = {i. i < t}⟧ ⟹ separated_tmps (ts[i:=((s,t),is,θ,sb,𝒟,𝒪)])" apply unfold_locales (*goals: 1. ‹⋀ia sa ta isa θ' sba 𝒟' 𝒪'. ⟦i < length ts; valid_sops_stmt t s; ∀(s', t')∈prog_configs sb. valid_sops_stmt t' s'; ∀i∈load_tmps is. i < t; ∀i∈read_tmps sb. i < t; ∀i∈⋃ (fst ` store_sops is). i < t; ∀i∈⋃ (fst ` write_sops sb). i < t; dom θ ∪ load_tmps is = {i. i < t}; ia < length (ts[i := ((s, t), is, θ, sb, 𝒟, 𝒪)]); ts[i := ((s, t), is, θ, sb, 𝒟, 𝒪)] ! ia = ((sa, ta), isa, θ', sba, 𝒟', 𝒪')⟧ ⟹ valid_sops_stmt ta sa› 2. ‹⋀ia sa ta isa θ' sba 𝒟' 𝒪' s' t'. ⟦i < length ts; valid_sops_stmt t s; ∀(s', t')∈prog_configs sb. valid_sops_stmt t' s'; ∀i∈load_tmps is. i < t; ∀i∈read_tmps sb. i < t; ∀i∈⋃ (fst ` store_sops is). i < t; ∀i∈⋃ (fst ` write_sops sb). i < t; dom θ ∪ load_tmps is = {i. i < t}; ia < length (ts[i := ((s, t), is, θ, sb, 𝒟, 𝒪)]); ts[i := ((s, t), is, θ, sb, 𝒟, 𝒪)] ! ia = ((sa, ta), isa, θ', sba, 𝒟', 𝒪'); (s', t') ∈ prog_configs sba⟧ ⟹ valid_sops_stmt t' s'› 3. ‹⋀ia sa ta isa θ' sba 𝒟' 𝒪'. ⟦i < length ts; valid_sops_stmt t s; ∀(s', t')∈prog_configs sb. valid_sops_stmt t' s'; ∀i∈load_tmps is. i < t; ∀i∈read_tmps sb. i < t; ∀i∈⋃ (fst ` store_sops is). i < t; ∀i∈⋃ (fst ` write_sops sb). i < t; dom θ ∪ load_tmps is = {i. i < t}; ia < length (ts[i := ((s, t), is, θ, sb, 𝒟, 𝒪)]); ts[i := ((s, t), is, θ, sb, 𝒟, 𝒪)] ! ia = ((sa, ta), isa, θ', sba, 𝒟', 𝒪')⟧ ⟹ ∀i∈load_tmps isa. i < ta› 4. ‹⋀ia sa ta isa θ' sba 𝒟' 𝒪'. ⟦i < length ts; valid_sops_stmt t s; ∀(s', t')∈prog_configs sb. valid_sops_stmt t' s'; ∀i∈load_tmps is. i < t; ∀i∈read_tmps sb. i < t; ∀i∈⋃ (fst ` store_sops is). i < t; ∀i∈⋃ (fst ` write_sops sb). i < t; dom θ ∪ load_tmps is = {i. i < t}; ia < length (ts[i := ((s, t), is, θ, sb, 𝒟, 𝒪)]); ts[i := ((s, t), is, θ, sb, 𝒟, 𝒪)] ! ia = ((sa, ta), isa, θ', sba, 𝒟', 𝒪')⟧ ⟹ ∀i∈read_tmps sba. i < ta› 5. ‹⋀ia sa ta isa θ' sba 𝒟' 𝒪'. ⟦i < length ts; valid_sops_stmt t s; ∀(s', t')∈prog_configs sb. valid_sops_stmt t' s'; ∀i∈load_tmps is. i < t; ∀i∈read_tmps sb. i < t; ∀i∈⋃ (fst ` store_sops is). i < t; ∀i∈⋃ (fst ` write_sops sb). i < t; dom θ ∪ load_tmps is = {i. i < t}; ia < length (ts[i := ((s, t), is, θ, sb, 𝒟, 𝒪)]); ts[i := ((s, t), is, θ, sb, 𝒟, 𝒪)] ! ia = ((sa, ta), isa, θ', sba, 𝒟', 𝒪')⟧ ⟹ ∀i∈⋃ (fst ` store_sops isa). i < ta› 6. ‹⋀ia sa ta isa θ' sba 𝒟' 𝒪'. ⟦i < length ts; valid_sops_stmt t s; ∀(s', t')∈prog_configs sb. valid_sops_stmt t' s'; ∀i∈load_tmps is. i < t; ∀i∈read_tmps sb. i < t; ∀i∈⋃ (fst ` store_sops is). i < t; ∀i∈⋃ (fst ` write_sops sb). i < t; dom θ ∪ load_tmps is = {i. i < t}; ia < length (ts[i := ((s, t), is, θ, sb, 𝒟, 𝒪)]); ts[i := ((s, t), is, θ, sb, 𝒟, 𝒪)] ! ia = ((sa, ta), isa, θ', sba, 𝒟', 𝒪')⟧ ⟹ ∀i∈⋃ (fst ` write_sops sba). i < ta› 7. ‹⋀ia sa ta isa θ' sba 𝒟' 𝒪'. ⟦i < length ts; valid_sops_stmt t s; ∀(s', t')∈prog_configs sb. valid_sops_stmt t' s'; ∀i∈load_tmps is. i < t; ∀i∈read_tmps sb. i < t; ∀i∈⋃ (fst ` store_sops is). i < t; ∀i∈⋃ (fst ` write_sops sb). i < t; dom θ ∪ load_tmps is = {i. i < t}; ia < length (ts[i := ((s, t), is, θ, sb, 𝒟, 𝒪)]); ts[i := ((s, t), is, θ, sb, 𝒟, 𝒪)] ! ia = ((sa, ta), isa, θ', sba, 𝒟', 𝒪')⟧ ⟹ dom θ' ∪ load_tmps isa = {i. i < ta}› discuss goal 1*) apply (force intro: valid_sops_stmt (*‹⟦(?i::nat) < length (ts::((stmt × nat) × instr list × (nat ⇒ 'a option) × (stmt × nat) memref list × 'b × 'c) list); ts ! ?i = ((?s::stmt, ?t::nat), ?is::instr list, ?θ::nat ⇒ 'a option, ?sb::(stmt × nat) memref list, ?𝒟::'b, ?𝒪::'c)⟧ ⟹ valid_sops_stmt ?t ?s›*) simp add: nth_list_update (*‹(?i::nat) < length (?xs::?'a list) ⟹ ?xs[?i := ?x::?'a] ! (?j::nat) = (if ?i = ?j then ?x else ?xs ! ?j)›*) split: if_split_asm (*‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) (*discuss goal 2*) apply (fastforce intro: valid_sops_stmt_sb (*‹⟦?i < length ts; ts ! ?i = ((?s, ?t), ?is, ?θ, ?sb, ?𝒟, ?𝒪); (?s', ?t') ∈ prog_configs ?sb⟧ ⟹ valid_sops_stmt ?t' ?s'›*) simp add: nth_list_update (*‹?i < length ?xs ⟹ ?xs[?i := ?x] ! ?j = (if ?i = ?j then ?x else ?xs ! ?j)›*) split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) (*discuss goal 3*) apply (fastforce intro: load_tmps_le [rule_format] (*‹⟦?i < length ts; ts ! ?i = ((?s, ?t), ?is, ?θ, ?sb, ?𝒟, ?𝒪); ?ia ∈ load_tmps ?is⟧ ⟹ ?ia < ?t›*) simp add: nth_list_update (*‹?i < length ?xs ⟹ ?xs[?i := ?x] ! ?j = (if ?i = ?j then ?x else ?xs ! ?j)›*) split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) (*discuss goal 4*) apply (fastforce intro: read_tmps_le [rule_format] (*‹⟦?i < length ts; ts ! ?i = ((?s, ?t), ?is, ?θ, ?sb, ?𝒟, ?𝒪); ?ia ∈ read_tmps ?sb⟧ ⟹ ?ia < ?t›*) simp add: nth_list_update (*‹?i < length ?xs ⟹ ?xs[?i := ?x] ! ?j = (if ?i = ?j then ?x else ?xs ! ?j)›*) split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) (*discuss goal 5*) apply (fastforce intro: store_sops_le [rule_format] (*‹⟦?i < length ts; ts ! ?i = ((?s, ?t), ?is, ?θ, ?sb, ?𝒟, ?𝒪); ?ia ∈ ⋃ (fst ` store_sops ?is)⟧ ⟹ ?ia < ?t›*) simp add: nth_list_update (*‹?i < length ?xs ⟹ ?xs[?i := ?x] ! ?j = (if ?i = ?j then ?x else ?xs ! ?j)›*) split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) (*discuss goal 6*) apply (fastforce intro: write_sops_le [rule_format] (*‹⟦(?i::nat) < length (ts::((stmt × nat) × instr list × (nat ⇒ 'a::type option) × (stmt × nat) memref list × 'b::type × 'c::type) list); ts ! ?i = ((?s::stmt, ?t::nat), ?is::instr list, ?θ::nat ⇒ 'a::type option, ?sb::(stmt × nat) memref list, ?𝒟::'b::type, ?𝒪::'c::type); (?ia::nat) ∈ ⋃ (fst ` write_sops ?sb)⟧ ⟹ ?ia < ?t›*) simp add: nth_list_update (*‹(?i::nat) < length (?xs::?'a::type list) ⟹ ?xs[?i := ?x::?'a::type] ! (?j::nat) = (if ?i = ?j then ?x else ?xs ! ?j)›*) split: if_split_asm (*‹(?P::?'a::type ⇒ bool) (if ?Q::bool then ?x::?'a::type else (?y::?'a::type)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) (*discuss goal 7*) apply (fastforce dest: tmps_le [rule_format] (*‹⟦?i < length ts; ts ! ?i = ((?s, ?t), ?is, ?θ, ?sb, ?𝒟, ?𝒪)⟧ ⟹ dom ?θ ∪ load_tmps ?is = {i. i < ?t}›*) simp add: nth_list_update (*‹?i < length ?xs ⟹ ?xs[?i := ?x] ! ?j = (if ?i = ?j then ?x else ?xs ! ?j)›*) split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) (*proven 7 subgoals*) . lemma hd_prog_app_in_first: "⋀ys. Prog⇩s⇩b p p' is ∈ set xs ⟹ hd_prog q (xs @ ys) = hd_prog q xs" apply (induct xs) (*goals: 1. ‹⋀ys. Prog⇩s⇩b p p' is ∈ set [] ⟹ hd_prog q ([] @ ys) = hd_prog q []› 2. ‹⋀a xs ys. ⟦⋀ys. Prog⇩s⇩b p p' is ∈ set xs ⟹ hd_prog q (xs @ ys) = hd_prog q xs; Prog⇩s⇩b p p' is ∈ set (a # xs)⟧ ⟹ hd_prog q ((a # xs) @ ys) = hd_prog q (a # xs)› discuss goal 1*) apply ((auto split: memref.splits (*‹(?P::?'a::type ⇒ bool) (case ?memref::?'p::type memref of Write⇩s⇩b (x::bool) (xa::nat) (xb::nat set × ((nat ⇒ nat option) ⇒ nat)) (xc::nat) (xd::nat set) (xe::nat set) (xf::nat set) (xg::nat set) ⇒ (?f1.0::bool ⇒ nat ⇒ nat set × ((nat ⇒ nat option) ⇒ nat) ⇒ nat ⇒ nat set ⇒ nat set ⇒ nat set ⇒ nat set ⇒ ?'a::type) x xa xb xc xd xe xf xg | Read⇩s⇩b (x::bool) (xa::nat) (xb::nat) (xc::nat) ⇒ (?f2.0::bool ⇒ nat ⇒ nat ⇒ nat ⇒ ?'a::type) x xa xb xc | Prog⇩s⇩b (x::?'p::type) (xa::?'p::type) (xb::instr list) ⇒ (?f3.0::?'p::type ⇒ ?'p::type ⇒ instr list ⇒ ?'a::type) x xa xb | Ghost⇩s⇩b (x::nat set) (xa::nat set) (xb::nat set) (xc::nat set) ⇒ (?f4.0::nat set ⇒ nat set ⇒ nat set ⇒ nat set ⇒ ?'a::type) x xa xb xc) = ((∀(x11::bool) (x12::nat) (x13::nat set × ((nat ⇒ nat option) ⇒ nat)) (x14::nat) (x15::nat set) (x16::nat set) (x17::nat set) x18::nat set. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ⟶ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∧ (∀(x21::bool) (x22::nat) (x23::nat) x24::nat. ?memref = Read⇩s⇩b x21 x22 x23 x24 ⟶ ?P (?f2.0 x21 x22 x23 x24)) ∧ (∀(x31::?'p::type) (x32::?'p::type) x33::instr list. ?memref = Prog⇩s⇩b x31 x32 x33 ⟶ ?P (?f3.0 x31 x32 x33)) ∧ (∀(x41::nat set) (x42::nat set) (x43::nat set) x44::nat set. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ⟶ ?P (?f4.0 x41 x42 x43 x44)))› ‹(?P::?'a::type ⇒ bool) (case ?memref::?'p::type memref of Write⇩s⇩b (x::bool) (xa::nat) (xb::nat set × ((nat ⇒ nat option) ⇒ nat)) (xc::nat) (xd::nat set) (xe::nat set) (xf::nat set) (xg::nat set) ⇒ (?f1.0::bool ⇒ nat ⇒ nat set × ((nat ⇒ nat option) ⇒ nat) ⇒ nat ⇒ nat set ⇒ nat set ⇒ nat set ⇒ nat set ⇒ ?'a::type) x xa xb xc xd xe xf xg | Read⇩s⇩b (x::bool) (xa::nat) (xb::nat) (xc::nat) ⇒ (?f2.0::bool ⇒ nat ⇒ nat ⇒ nat ⇒ ?'a::type) x xa xb xc | Prog⇩s⇩b (x::?'p::type) (xa::?'p::type) (xb::instr list) ⇒ (?f3.0::?'p::type ⇒ ?'p::type ⇒ instr list ⇒ ?'a::type) x xa xb | Ghost⇩s⇩b (x::nat set) (xa::nat set) (xb::nat set) (xc::nat set) ⇒ (?f4.0::nat set ⇒ nat set ⇒ nat set ⇒ nat set ⇒ ?'a::type) x xa xb xc) = (¬ ((∃(x11::bool) (x12::nat) (x13::nat set × ((nat ⇒ nat option) ⇒ nat)) (x14::nat) (x15::nat set) (x16::nat set) (x17::nat set) x18::nat set. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ∧ ¬ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∨ (∃(x21::bool) (x22::nat) (x23::nat) x24::nat. ?memref = Read⇩s⇩b x21 x22 x23 x24 ∧ ¬ ?P (?f2.0 x21 x22 x23 x24)) ∨ (∃(x31::?'p::type) (x32::?'p::type) x33::instr list. ?memref = Prog⇩s⇩b x31 x32 x33 ∧ ¬ ?P (?f3.0 x31 x32 x33)) ∨ (∃(x41::nat set) (x42::nat set) (x43::nat set) x44::nat set. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ∧ ¬ ?P (?f4.0 x41 x42 x43 x44))))›*))[1]) (*discuss goal 2*) apply ((auto split: memref.splits (*‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = ((∀x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ⟶ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∧ (∀x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ⟶ ?P (?f2.0 x21 x22 x23 x24)) ∧ (∀x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ⟶ ?P (?f3.0 x31 x32 x33)) ∧ (∀x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ⟶ ?P (?f4.0 x41 x42 x43 x44)))› ‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = (¬ ((∃x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ∧ ¬ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∨ (∃x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ∧ ¬ ?P (?f2.0 x21 x22 x23 x24)) ∨ (∃x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ∧ ¬ ?P (?f3.0 x31 x32 x33)) ∨ (∃x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ∧ ¬ ?P (?f4.0 x41 x42 x43 x44))))›*))[1]) (*proven 2 subgoals*) . lemma hd_prog_app_in_eq: "⋀ys. Prog⇩s⇩b p p' is ∈ set xs ⟹ hd_prog q xs = hd_prog x xs" apply (induct xs) (*goals: 1. ‹⋀ys::'a. Prog⇩s⇩b (p::'b) (p'::'b) (is::instr list) ∈ set [] ⟹ hd_prog (q::'b) [] = hd_prog (x::'b) []› 2. ‹⋀(a::'b memref) (xs::'b memref list) ys::'a. ⟦⋀ys::'a. Prog⇩s⇩b (p::'b) (p'::'b) (is::instr list) ∈ set xs ⟹ hd_prog (q::'b) xs = hd_prog (x::'b) xs; Prog⇩s⇩b p p' is ∈ set (a # xs)⟧ ⟹ hd_prog q (a # xs) = hd_prog x (a # xs)› discuss goal 1*) apply ((auto split: memref.splits (*‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = ((∀x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ⟶ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∧ (∀x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ⟶ ?P (?f2.0 x21 x22 x23 x24)) ∧ (∀x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ⟶ ?P (?f3.0 x31 x32 x33)) ∧ (∀x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ⟶ ?P (?f4.0 x41 x42 x43 x44)))› ‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = (¬ ((∃x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ∧ ¬ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∨ (∃x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ∧ ¬ ?P (?f2.0 x21 x22 x23 x24)) ∨ (∃x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ∧ ¬ ?P (?f3.0 x31 x32 x33)) ∨ (∃x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ∧ ¬ ?P (?f4.0 x41 x42 x43 x44))))›*))[1]) (*discuss goal 2*) apply ((auto split: memref.splits (*‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = ((∀x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ⟶ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∧ (∀x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ⟶ ?P (?f2.0 x21 x22 x23 x24)) ∧ (∀x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ⟶ ?P (?f3.0 x31 x32 x33)) ∧ (∀x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ⟶ ?P (?f4.0 x41 x42 x43 x44)))› ‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = (¬ ((∃x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ∧ ¬ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∨ (∃x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ∧ ¬ ?P (?f2.0 x21 x22 x23 x24)) ∨ (∃x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ∧ ¬ ?P (?f3.0 x31 x32 x33)) ∨ (∃x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ∧ ¬ ?P (?f4.0 x41 x42 x43 x44))))›*))[1]) (*proven 2 subgoals*) . lemma hd_prog_app_notin_first: "⋀ys. ∀p p' is. Prog⇩s⇩b p p' is ∉ set xs ⟹ hd_prog q (xs @ ys) = hd_prog q ys" apply (induct xs) (*goals: 1. ‹⋀ys. ∀p p' is. Prog⇩s⇩b p p' is ∉ set [] ⟹ hd_prog q ([] @ ys) = hd_prog q ys› 2. ‹⋀a xs ys. ⟦⋀ys. ∀p p' is. Prog⇩s⇩b p p' is ∉ set xs ⟹ hd_prog q (xs @ ys) = hd_prog q ys; ∀p p' is. Prog⇩s⇩b p p' is ∉ set (a # xs)⟧ ⟹ hd_prog q ((a # xs) @ ys) = hd_prog q ys› discuss goal 1*) apply ((auto split: memref.splits (*‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = ((∀x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ⟶ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∧ (∀x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ⟶ ?P (?f2.0 x21 x22 x23 x24)) ∧ (∀x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ⟶ ?P (?f3.0 x31 x32 x33)) ∧ (∀x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ⟶ ?P (?f4.0 x41 x42 x43 x44)))› ‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = (¬ ((∃x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ∧ ¬ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∨ (∃x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ∧ ¬ ?P (?f2.0 x21 x22 x23 x24)) ∨ (∃x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ∧ ¬ ?P (?f3.0 x31 x32 x33)) ∨ (∃x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ∧ ¬ ?P (?f4.0 x41 x42 x43 x44))))›*))[1]) (*discuss goal 2*) apply ((auto split: memref.splits (*‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = ((∀x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ⟶ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∧ (∀x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ⟶ ?P (?f2.0 x21 x22 x23 x24)) ∧ (∀x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ⟶ ?P (?f3.0 x31 x32 x33)) ∧ (∀x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ⟶ ?P (?f4.0 x41 x42 x43 x44)))› ‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = (¬ ((∃x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ∧ ¬ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∨ (∃x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ∧ ¬ ?P (?f2.0 x21 x22 x23 x24)) ∨ (∃x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ∧ ¬ ?P (?f3.0 x31 x32 x33)) ∨ (∃x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ∧ ¬ ?P (?f4.0 x41 x42 x43 x44))))›*))[1]) (*proven 2 subgoals*) . lemma union_eq_subsetD: "A ∪ B = C ⟹ A ∪ B ⊆ C ∧ C ⊆ A ∪ B" by auto lemma prog_step_preserves_separated_tmps: assumes i_bound: "i < length ts" assumes ts_i: "ts!i = (p,is,θ,sb,𝒟,𝒪)" assumes prog_step: "θ⊢ p →⇩s (p', is')" assumes sep: "separated_tmps ts" shows "separated_tmps (ts [i:=(p',is@is',θ,sb@[Prog⇩s⇩b p p' is'],𝒟,𝒪)])" proof (-) (*goal: ‹separated_tmps (ts[i := (p', is @ is', θ, sb @ [Prog⇩s⇩b p p' is'], 𝒟, 𝒪)])›*) obtain s and t where p: "p=(s,t)" (*goal: ‹(⋀(s::stmt) t::nat. (p::stmt × nat) = (s, t) ⟹ thesis::bool) ⟹ thesis›*) by (cases p) obtain s' and t' where p': "p'=(s',t')" (*goal: ‹(⋀s' t'. p' = (s', t') ⟹ thesis) ⟹ thesis›*) by (cases p') note ts_i = ts_i[simplified p] (*‹(ts::((stmt × nat) × instr list × (nat ⇒ nat option) × (stmt × nat) memref list × 'a × 'b) list) ! (i::nat) = ((s::stmt, t::nat), is::instr list, θ::nat ⇒ nat option, sb::(stmt × nat) memref list, 𝒟::'a, 𝒪::'b)›*) note step = prog_step[simplified p p'] (*‹θ⊢ (s, t) →⇩s ((s', t'), is')›*) interpret separated_tmps ts by fact have "separated_tmps (ts[i := ((s',t'), is @ is', θ, sb @ [Prog⇩s⇩b (s,t) (s',t') is'], 𝒟,𝒪)])" proof (rule separated_tmps_nth_update [OF i_bound] (*‹⟦valid_sops_stmt ?t ?s; ∀(s', t')∈prog_configs ?sb. valid_sops_stmt t' s'; ∀i∈load_tmps ?is. i < ?t; ∀i∈read_tmps ?sb. i < ?t; ∀i∈⋃ (fst ` store_sops ?is). i < ?t; ∀i∈⋃ (fst ` write_sops ?sb). i < ?t; dom ?θ ∪ load_tmps ?is = {i. i < ?t}⟧ ⟹ separated_tmps (ts[i := ((?s, ?t), ?is, ?θ, ?sb, ?𝒟, ?𝒪)])›*)) (*goals: 1. ‹valid_sops_stmt (t'::nat) (s'::stmt)› 2. ‹∀(s'::stmt, t'::nat)∈prog_configs ((sb::(stmt × nat) memref list) @ [Prog⇩s⇩b (s::stmt, t::nat) (s'::stmt, t'::nat) (is'::instr list)]). valid_sops_stmt t' s'› 3. ‹∀i::nat∈load_tmps ((is::instr list) @ (is'::instr list)). i < (t'::nat)› 4. ‹∀i::nat∈read_tmps ((sb::(stmt × nat) memref list) @ [Prog⇩s⇩b (s::stmt, t::nat) (s'::stmt, t'::nat) (is'::instr list)]). i < t'› 5. ‹∀i::nat∈⋃ (fst ` store_sops ((is::instr list) @ (is'::instr list))). i < (t'::nat)› 6. ‹∀i::nat∈⋃ (fst ` write_sops ((sb::(stmt × nat) memref list) @ [Prog⇩s⇩b (s::stmt, t::nat) (s'::stmt, t'::nat) (is'::instr list)])). i < t'› 7. ‹dom (θ::nat ⇒ nat option) ∪ load_tmps ((is::instr list) @ (is'::instr list)) = {i::nat. i < (t'::nat)}›*) from stmt_step_load_tmps_range[OF step] (*‹∀i::nat∈load_tmps (is'::instr list). (t::nat) ≤ i ∧ i < (t'::nat)›*) load_tmps_le[OF i_bound ts_i] (*‹∀i∈load_tmps is. i < t›*) stmt_step_tmps_count_mono[OF step] (*‹t ≤ t'›*) show "∀i∈load_tmps (is @ is'). i < t'" by (auto simp add: load_tmps_append (*‹load_tmps (?xs @ ?ys) = load_tmps ?xs ∪ load_tmps ?ys›*)) next (*goals: 1. ‹valid_sops_stmt t' s'› 2. ‹∀(s', t')∈prog_configs (sb @ [Prog⇩s⇩b (s, t) (s', t') is']). valid_sops_stmt t' s'› 3. ‹∀i∈read_tmps (sb @ [Prog⇩s⇩b (s, t) (s', t') is']). i < t'› 4. ‹∀i∈⋃ (fst ` store_sops (is @ is')). i < t'› 5. ‹∀i∈⋃ (fst ` write_sops (sb @ [Prog⇩s⇩b (s, t) (s', t') is'])). i < t'› 6. ‹dom θ ∪ load_tmps (is @ is') = {i. i < t'}›*) from read_tmps_le[OF i_bound ts_i] (*‹∀i∈read_tmps sb. i < t›*) stmt_step_tmps_count_mono[OF step] (*‹(t::nat) ≤ (t'::nat)›*) show "∀i∈read_tmps (sb @ [Prog⇩s⇩b (s, t) (s', t') is']). i < t'" by (auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*)) next (*goals: 1. ‹valid_sops_stmt t' s'› 2. ‹∀(s', t')∈prog_configs (sb @ [Prog⇩s⇩b (s, t) (s', t') is']). valid_sops_stmt t' s'› 3. ‹∀i∈⋃ (fst ` store_sops (is @ is')). i < t'› 4. ‹∀i∈⋃ (fst ` write_sops (sb @ [Prog⇩s⇩b (s, t) (s', t') is'])). i < t'› 5. ‹dom θ ∪ load_tmps (is @ is') = {i. i < t'}›*) from stmt_step_data_store_sops_range[OF step] (*‹valid_sops_stmt t s ⟹ ∀(D, f)∈store_sops is'. ∀i∈D. i < t'›*) stmt_step_tmps_count_mono[OF step] (*‹t ≤ t'›*) store_sops_le[OF i_bound ts_i] (*‹∀i∈⋃ (fst ` store_sops is). i < t›*) valid_sops_stmt[OF i_bound ts_i] (*‹valid_sops_stmt (t::nat) (s::stmt)›*) show "∀i∈⋃(fst ` store_sops (is @ is')). i < t'" by (fastforce simp add: store_sops_append (*‹store_sops (?xs @ ?ys) = store_sops ?xs ∪ store_sops ?ys›*)) next (*goals: 1. ‹valid_sops_stmt t' s'› 2. ‹∀(s', t')∈prog_configs (sb @ [Prog⇩s⇩b (s, t) (s', t') is']). valid_sops_stmt t' s'› 3. ‹∀i∈⋃ (fst ` write_sops (sb @ [Prog⇩s⇩b (s, t) (s', t') is'])). i < t'› 4. ‹dom θ ∪ load_tmps (is @ is') = {i. i < t'}›*) from stmt_step_tmps_count_mono[OF step] (*‹t ≤ t'›*) write_sops_le[OF i_bound ts_i] (*‹∀i::nat∈⋃ (fst ` write_sops (sb::(stmt × nat) memref list)). i < (t::nat)›*) show "∀i∈⋃(fst ` write_sops (sb @ [Prog⇩s⇩b (s, t) (s', t') is'])). i < t'" by (fastforce simp add: write_sops_append (*‹write_sops (?xs @ ?ys) = write_sops ?xs ∪ write_sops ?ys›*)) next (*goals: 1. ‹valid_sops_stmt t' s'› 2. ‹∀(s', t')∈prog_configs (sb @ [Prog⇩s⇩b (s, t) (s', t') is']). valid_sops_stmt t' s'› 3. ‹dom θ ∪ load_tmps (is @ is') = {i. i < t'}›*) from tmps_le[OF i_bound ts_i] (*‹dom θ ∪ load_tmps is = {i. i < t}›*) have "dom θ ∪ load_tmps is = {i. i < t}" by simp with stmt_step_load_tmps_range'[OF step] (*‹load_tmps (is'::instr list) = {i::nat. (t::nat) ≤ i ∧ i < (t'::nat)}›*) stmt_step_tmps_count_mono[OF step] (*‹(t::nat) ≤ (t'::nat)›*) show "dom θ ∪ load_tmps (is @ is') = {i. i < t'}" apply (clarsimp simp add: load_tmps_append (*‹load_tmps (?xs @ ?ys) = load_tmps ?xs ∪ load_tmps ?ys›*)) (*goal: ‹dom θ ∪ load_tmps (is @ is') = {i. i < t'}›*) apply rule (*goal: ‹⟦load_tmps is' = {i. t ≤ i ∧ i < t'}; t ≤ t'; dom θ ∪ load_tmps is = {i. i < t}⟧ ⟹ dom θ ∪ (load_tmps is ∪ {i. t ≤ i ∧ i < t'}) = {i. i < t'}›*) apply (drule union_eq_subsetD (*‹?A ∪ ?B = ?C ⟹ ?A ∪ ?B ⊆ ?C ∧ ?C ⊆ ?A ∪ ?B›*)) (*top goal: ‹⟦load_tmps is' = {i. t ≤ i ∧ i < t'}; t ≤ t'; dom θ ∪ load_tmps is = {i. i < t}⟧ ⟹ dom θ ∪ (load_tmps is ∪ {i. t ≤ i ∧ i < t'}) ⊆ {i. i < t'}› and 1 goal remains*) apply fastforce (*top goal: ‹⟦load_tmps is' = {i. t ≤ i ∧ i < t'}; t ≤ t'; dom θ ∪ load_tmps is ⊆ {i. i < t} ∧ {i. i < t} ⊆ dom θ ∪ load_tmps is⟧ ⟹ dom θ ∪ (load_tmps is ∪ {i. t ≤ i ∧ i < t'}) ⊆ {i. i < t'}› and 1 goal remains*) apply clarsimp (*goal: ‹⟦load_tmps is' = {i. t ≤ i ∧ i < t'}; t ≤ t'; dom θ ∪ load_tmps is = {i. i < t}⟧ ⟹ {i. i < t'} ⊆ dom θ ∪ (load_tmps is ∪ {i. t ≤ i ∧ i < t'})›*) subgoal for x apply (case_tac "t ≤ x") (*goals: 1. ‹⟦load_tmps is' = {i. t ≤ i ∧ i < t'}; t ≤ t'; dom θ ∪ load_tmps is = {i. i < t}; x ∉ dom θ; x < t'; x ∉ load_tmps is; t ≤ x⟧ ⟹ t ≤ x› 2. ‹⟦load_tmps is' = {i. t ≤ i ∧ i < t'}; t ≤ t'; dom θ ∪ load_tmps is = {i. i < t}; x ∉ dom θ; x < t'; x ∉ load_tmps is; ¬ t ≤ x⟧ ⟹ t ≤ x› discuss goal 1*) apply simp (*discuss goal 2*) apply (subgoal_tac "x < t") (*goals: 1. ‹⟦load_tmps is' = {i. t ≤ i ∧ i < t'}; t ≤ t'; dom θ ∪ load_tmps is = {i. i < t}; x ∉ dom θ; x < t'; x ∉ load_tmps is; ¬ t ≤ x; x < t⟧ ⟹ t ≤ x› 2. ‹⟦load_tmps is' = {i. t ≤ i ∧ i < t'}; t ≤ t'; dom θ ∪ load_tmps is = {i. i < t}; x ∉ dom θ; x < t'; x ∉ load_tmps is; ¬ t ≤ x⟧ ⟹ x < t› discuss goal 1*) apply fastforce (*discuss goal 2*) apply fastforce (*proven 2 subgoals*) (*proven 2 subgoals*) . . next (*goals: 1. ‹valid_sops_stmt (t'::nat) (s'::stmt)› 2. ‹∀(s'::stmt, t'::nat)∈prog_configs ((sb::(stmt × nat) memref list) @ [Prog⇩s⇩b (s::stmt, t::nat) (s'::stmt, t'::nat) (is'::instr list)]). valid_sops_stmt t' s'›*) from valid_sops_stmt_invariant[OF prog_step [ simplified p p' ] valid_sops_stmt [ OF i_bound ts_i ]] (*‹valid_sops_stmt t' s'›*) show "valid_sops_stmt t' s'" . next (*goal: ‹∀(s', t')∈prog_configs (sb @ [Prog⇩s⇩b (s, t) (s', t') is']). valid_sops_stmt t' s'›*) show "∀(s', t')∈prog_configs (sb @ [Prog⇩s⇩b (s, t) (s', t') is']). valid_sops_stmt t' s'" proof (-) (*goal: ‹∀(s', t')∈prog_configs (sb @ [Prog⇩s⇩b (s, t) (s', t') is']). valid_sops_stmt t' s'›*) { fix s₁ and t₁ assume cfgs: "(s₁,t₁) ∈ prog_configs (sb @ [Prog⇩s⇩b (s, t) (s', t') is'])" (*‹(s₁::stmt, t₁::nat) ∈ prog_configs ((sb::(stmt × nat) memref list) @ [Prog⇩s⇩b (s::stmt, t::nat) (s'::stmt, t'::nat) (is'::instr list)])›*) have "valid_sops_stmt t₁ s₁" proof (-) (*goal: ‹valid_sops_stmt t₁ s₁›*) from valid_sops_stmt[OF i_bound ts_i] (*‹valid_sops_stmt t s›*) have "valid_sops_stmt t s" . moreover from valid_sops_stmt_invariant[OF prog_step [ simplified p p' ] valid_sops_stmt [ OF i_bound ts_i ]] (*‹valid_sops_stmt (t'::nat) (s'::stmt)›*) have "valid_sops_stmt t' s'" . moreover note valid_sops_stmt_sb[OF i_bound ts_i] (*‹(?s', ?t') ∈ prog_configs sb ⟹ valid_sops_stmt ?t' ?s'›*) ultimately show "?thesis" (*goal: ‹valid_sops_stmt t₁ s₁›*) using cfgs (*‹(s₁, t₁) ∈ prog_configs (sb @ [Prog⇩s⇩b (s, t) (s', t') is'])›*) by (auto simp add: prog_configs_append (*‹prog_configs ((?xs::?'a::type memref list) @ (?ys::?'a::type memref list)) = prog_configs ?xs ∪ prog_configs ?ys›*)) qed } thus "?thesis" (*goal: ‹∀(s', t')∈prog_configs (sb @ [Prog⇩s⇩b (s, t) (s', t') is']). valid_sops_stmt t' s'›*) by auto qed qed then show "?thesis" (*goal: ‹separated_tmps (ts[i := (p', is @ is', θ, sb @ [Prog⇩s⇩b p p' is'], 𝒟, 𝒪)])›*) by (simp add: p (*‹p = (s, t)›*) p' (*‹p' = (s', t')›*)) qed lemma flush_step_sb_subset: assumes step: "(m,sb,𝒪) →⇩f (m', sb',𝒪')" shows "set sb' ⊆ set sb" using step (*‹(m, sb, 𝒪) →⇩f (m', sb', 𝒪')›*) apply (induct c1=="(m,sb,𝒪)" c2=="(m',sb',𝒪')" arbitrary: m sb 𝒪 acq m' sb' 𝒪' acq rule: flush_step.induct) (*goals: 1. ‹⋀𝒪' volatile 𝒪 A R 𝒮' 𝒮 W L ℛ' ℛ m a sop v rs. ⟦𝒪' = (if volatile then 𝒪 ∪ A - R else 𝒪); 𝒮' = (if volatile then 𝒮 ⊕⇘W⇙ R ⊖⇘A⇙ L else 𝒮); ℛ' = (if volatile then λx. None else ℛ)⟧ ⟹ set rs ⊆ set (Write⇩s⇩b volatile a sop v A L R W # rs)› 2. ‹⋀m volatile a t v rs 𝒪 ℛ 𝒮. set rs ⊆ set (Read⇩s⇩b volatile a t v # rs)› 3. ‹⋀m p p' is rs 𝒪 ℛ 𝒮. set rs ⊆ set (Prog⇩s⇩b p p' is # rs)› 4. ‹⋀m A L R W rs 𝒪 ℛ 𝒮. set rs ⊆ set (Ghost⇩s⇩b A L R W # rs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . lemma flush_step_preserves_separated_tmps: assumes i_bound: "i < length ts" assumes ts_i: "ts!i = (p,is,θ,sb,𝒟,𝒪,ℛ)" assumes flush_step: "(m,sb,𝒪,ℛ,𝒮) →⇩f (m', sb',𝒪',ℛ',𝒮')" assumes sep: "separated_tmps ts" shows "separated_tmps (ts [i:=(p,is,θ,sb',𝒟,𝒪',ℛ')])" proof (-) (*goal: ‹separated_tmps (ts[i := (p, is, θ, sb', 𝒟, 𝒪', ℛ')])›*) obtain s and t where p: "p=(s,t)" (*goal: ‹(⋀s t. p = (s, t) ⟹ thesis) ⟹ thesis›*) by (cases p) note ts_i = ts_i[simplified p] (*‹(ts::((stmt × nat) × instr list × (nat ⇒ 'a option) × (stmt × nat) memref list × 'b × nat set × (nat ⇒ bool option)) list) ! (i::nat) = ((s::stmt, t::nat), is::instr list, θ::nat ⇒ 'a option, sb::(stmt × nat) memref list, 𝒟::'b, 𝒪::nat set, ℛ::nat ⇒ bool option)›*) interpret separated_tmps ts by fact have "separated_tmps (ts [i:=((s,t),is,θ,sb',𝒟,𝒪',ℛ')])" proof (rule separated_tmps_nth_update [OF i_bound] (*‹⟦valid_sops_stmt ?t ?s; ∀(s', t')∈prog_configs ?sb. valid_sops_stmt t' s'; ∀i∈load_tmps ?is. i < ?t; ∀i∈read_tmps ?sb. i < ?t; ∀i∈⋃ (fst ` store_sops ?is). i < ?t; ∀i∈⋃ (fst ` write_sops ?sb). i < ?t; dom ?θ ∪ load_tmps ?is = {i. i < ?t}⟧ ⟹ separated_tmps (ts[i := ((?s, ?t), ?is, ?θ, ?sb, ?𝒟, ?𝒪)])›*)) (*goals: 1. ‹valid_sops_stmt (t::nat) (s::stmt)› 2. ‹∀(s'::stmt, t'::nat)∈prog_configs (sb'::(stmt × nat) memref list). valid_sops_stmt t' s'› 3. ‹∀i::nat∈load_tmps (is::instr list). i < (t::nat)› 4. ‹∀i::nat∈read_tmps (sb'::(stmt × nat) memref list). i < (t::nat)› 5. ‹∀i::nat∈⋃ (fst ` store_sops (is::instr list)). i < (t::nat)› 6. ‹∀i::nat∈⋃ (fst ` write_sops (sb'::(stmt × nat) memref list)). i < (t::nat)› 7. ‹dom (θ::nat ⇒ 'a option) ∪ load_tmps (is::instr list) = {i::nat. i < (t::nat)}›*) from load_tmps_le[OF i_bound ts_i] (*‹∀i∈load_tmps is. i < t›*) show "∀i∈load_tmps is. i < t" . next (*goals: 1. ‹valid_sops_stmt t s› 2. ‹∀(s', t')∈prog_configs sb'. valid_sops_stmt t' s'› 3. ‹∀i∈read_tmps sb'. i < t› 4. ‹∀i∈⋃ (fst ` store_sops is). i < t› 5. ‹∀i∈⋃ (fst ` write_sops sb'). i < t› 6. ‹dom θ ∪ load_tmps is = {i. i < t}›*) from flush_step_preserves_read_tmps[OF flush_step read_tmps_le [ OF i_bound ts_i ]] (*‹∀i∈read_tmps sb'. i < t›*) show "∀i∈read_tmps sb'. i < t" . next (*goals: 1. ‹valid_sops_stmt t s› 2. ‹∀(s', t')∈prog_configs sb'. valid_sops_stmt t' s'› 3. ‹∀i∈⋃ (fst ` store_sops is). i < t› 4. ‹∀i∈⋃ (fst ` write_sops sb'). i < t› 5. ‹dom θ ∪ load_tmps is = {i. i < t}›*) from store_sops_le[OF i_bound ts_i] (*‹∀i∈⋃ (fst ` store_sops is). i < t›*) show "∀i∈⋃(fst ` store_sops is). i < t" . next (*goals: 1. ‹valid_sops_stmt t s› 2. ‹∀(s', t')∈prog_configs sb'. valid_sops_stmt t' s'› 3. ‹∀i∈⋃ (fst ` write_sops sb'). i < t› 4. ‹dom θ ∪ load_tmps is = {i. i < t}›*) from flush_step_preserves_write_sops[OF flush_step write_sops_le [ OF i_bound ts_i ]] (*‹∀i∈⋃ (fst ` write_sops sb'). i < t›*) show "∀i∈⋃(fst ` write_sops sb'). i < t" . next (*goals: 1. ‹valid_sops_stmt t s› 2. ‹∀(s', t')∈prog_configs sb'. valid_sops_stmt t' s'› 3. ‹dom θ ∪ load_tmps is = {i. i < t}›*) from tmps_le[OF i_bound ts_i] (*‹dom θ ∪ load_tmps is = {i. i < t}›*) show "dom θ ∪ load_tmps is = {i. i < t}" by auto next (*goals: 1. ‹valid_sops_stmt t s› 2. ‹∀(s', t')∈prog_configs sb'. valid_sops_stmt t' s'›*) from valid_sops_stmt[OF i_bound ts_i] (*‹valid_sops_stmt t s›*) show "valid_sops_stmt t s" . next (*goal: ‹∀(s', t')∈prog_configs sb'. valid_sops_stmt t' s'›*) from valid_sops_stmt_sb[OF i_bound ts_i] (*‹(?s', ?t') ∈ prog_configs sb ⟹ valid_sops_stmt ?t' ?s'›*) flush_step_sb_subset[OF flush_step] (*‹set sb' ⊆ set sb›*) show "∀(s', t')∈prog_configs sb'. valid_sops_stmt t' s'" by (auto dest!: prog_configs_mono (*‹set ?xs ⊆ set ?ys ⟹ prog_configs ?xs ⊆ prog_configs ?ys›*)) qed then show "?thesis" (*goal: ‹separated_tmps ((ts::((stmt × nat) × instr list × (nat ⇒ 'a option) × (stmt × nat) memref list × 'b × nat set × (nat ⇒ bool option)) list)[i::nat := (p::stmt × nat, is::instr list, θ::nat ⇒ 'a option, sb'::(stmt × nat) memref list, 𝒟::'b, 𝒪'::nat set, ℛ'::nat ⇒ bool option)])›*) by (simp add: p (*‹p = (s, t)›*)) qed lemma sbh_step_preserves_store_sops_bound: assumes step: "(is,θ,sb,m,𝒟,𝒪,ℛ,𝒮) →⇩s⇩b⇩h (is',θ',sb',m',𝒟',𝒪',ℛ',𝒮')" assumes store_sops_le: "∀i∈⋃(fst ` store_sops is). i < t" shows "∀i∈⋃(fst ` store_sops is'). i < t" using step (*‹(is::instr list, θ::nat ⇒ nat option, sb::'a memref list, m::nat ⇒ nat, 𝒟::bool, 𝒪::nat set, ℛ::nat ⇒ bool option, 𝒮::nat ⇒ bool option) →⇩s⇩b⇩h (is'::instr list, θ'::nat ⇒ nat option, sb'::'a memref list, m'::nat ⇒ nat, 𝒟'::bool, 𝒪'::nat set, ℛ'::nat ⇒ bool option, 𝒮'::nat ⇒ bool option)›*) store_sops_le (*‹∀i∈⋃ (fst ` store_sops is). i < t›*) apply cases (*goals: 1. ‹⋀a v volatile ta. ⟦∀i∈⋃ (fst ` store_sops is). i < t; is = Read volatile a ta # is'; θ' = θ(ta ↦ v); sb' = sb @ [Read⇩s⇩b volatile a ta v]; m' = m; 𝒟' = 𝒟; 𝒪' = 𝒪; ℛ' = ℛ; 𝒮' = 𝒮; buffered_val sb a = Some v⟧ ⟹ ∀i∈⋃ (fst ` store_sops is'). i < t› 2. ‹⋀a volatile ta. ⟦∀i∈⋃ (fst ` store_sops is). i < t; is = Read volatile a ta # is'; θ' = θ(ta ↦ m a); sb' = sb @ [Read⇩s⇩b volatile a ta (m a)]; m' = m; 𝒟' = 𝒟; 𝒪' = 𝒪; ℛ' = ℛ; 𝒮' = 𝒮; buffered_val sb a = None⟧ ⟹ ∀i∈⋃ (fst ` store_sops is'). i < t› 3. ‹⋀a D f A L R W. ⟦∀i∈⋃ (fst ` store_sops is). i < t; is = Write False a (D, f) A L R W # is'; θ' = θ; sb' = sb @ [Write⇩s⇩b False a (D, f) (f θ) A L R W]; m' = m; 𝒟' = 𝒟; 𝒪' = 𝒪; ℛ' = ℛ; 𝒮' = 𝒮⟧ ⟹ ∀i∈⋃ (fst ` store_sops is'). i < t› 4. ‹⋀a D f A L R W. ⟦∀i∈⋃ (fst ` store_sops is). i < t; is = Write True a (D, f) A L R W # is'; θ' = θ; sb' = sb @ [Write⇩s⇩b True a (D, f) (f θ) A L R W]; m' = m; 𝒟' = True; 𝒪' = 𝒪; ℛ' = ℛ; 𝒮' = 𝒮⟧ ⟹ ∀i∈⋃ (fst ` store_sops is'). i < t› 5. ‹⟦∀i∈⋃ (fst ` store_sops is). i < t; is = Fence # is'; sb = []; θ' = θ; sb' = []; m' = m; 𝒟' = False; 𝒪' = 𝒪; ℛ' = (λx. None); 𝒮' = 𝒮⟧ ⟹ ∀i∈⋃ (fst ` store_sops is'). i < t› 6. ‹⋀cond ta a D f ret A L R W. ⟦∀i∈⋃ (fst ` store_sops is). i < t; is = RMW a ta (D, f) cond ret A L R W # is'; sb = []; θ' = θ(ta ↦ m a); sb' = []; m' = m; 𝒟' = False; 𝒪' = 𝒪; ℛ' = (λx. None); 𝒮' = 𝒮; ¬ cond (θ(ta ↦ m a))⟧ ⟹ ∀i∈⋃ (fst ` store_sops is'). i < t› 7. ‹⋀cond ta a D f ret A L R W. ⟦∀i∈⋃ (fst ` store_sops is). i < t; is = RMW a ta (D, f) cond ret A L R W # is'; sb = []; θ' = θ(ta ↦ ret (m a) (f (θ(ta ↦ m a)))); sb' = []; m' = m(a := f (θ(ta ↦ m a))); 𝒟' = False; 𝒪' = 𝒪 ∪ A - R; ℛ' = (λx. None); 𝒮' = 𝒮 ⊕⇘W⇙ R ⊖⇘A⇙ L; cond (θ(ta ↦ m a))⟧ ⟹ ∀i∈⋃ (fst ` store_sops is'). i < t› 8. ‹⋀A L R W. ⟦∀i∈⋃ (fst ` store_sops is). i < t; is = Ghost A L R W # is'; θ' = θ; sb' = sb @ [Ghost⇩s⇩b A L R W]; m' = m; 𝒟' = 𝒟; 𝒪' = 𝒪; ℛ' = ℛ; 𝒮' = 𝒮⟧ ⟹ ∀i∈⋃ (fst ` store_sops is'). i < t› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*proven 8 subgoals*) . lemma sbh_step_preserves_write_sops_bound: assumes step: "(is,θ,sb,m,𝒟,𝒪,ℛ,𝒮) →⇩s⇩b⇩h (is',θ',sb',m',𝒟',𝒪',ℛ',𝒮')" assumes store_sops_le: "∀i∈⋃(fst ` store_sops is). i < t" assumes write_sops_le: "∀i∈⋃(fst ` write_sops sb). i < t" shows "∀i∈⋃(fst ` write_sops sb'). i < t" using step (*‹(is, θ, sb, m, 𝒟, 𝒪, ℛ, 𝒮) →⇩s⇩b⇩h (is', θ', sb', m', 𝒟', 𝒪', ℛ', 𝒮')›*) store_sops_le (*‹∀i∈⋃ (fst ` store_sops is). i < t›*) write_sops_le (*‹∀i∈⋃ (fst ` write_sops sb). i < t›*) apply cases (*goals: 1. ‹⋀a v volatile ta. ⟦∀i∈⋃ (fst ` store_sops is). i < t; ∀i∈⋃ (fst ` write_sops sb). i < t; is = Read volatile a ta # is'; θ' = θ(ta ↦ v); sb' = sb @ [Read⇩s⇩b volatile a ta v]; m' = m; 𝒟' = 𝒟; 𝒪' = 𝒪; ℛ' = ℛ; 𝒮' = 𝒮; buffered_val sb a = Some v⟧ ⟹ ∀i∈⋃ (fst ` write_sops sb'). i < t› 2. ‹⋀a volatile ta. ⟦∀i∈⋃ (fst ` store_sops is). i < t; ∀i∈⋃ (fst ` write_sops sb). i < t; is = Read volatile a ta # is'; θ' = θ(ta ↦ m a); sb' = sb @ [Read⇩s⇩b volatile a ta (m a)]; m' = m; 𝒟' = 𝒟; 𝒪' = 𝒪; ℛ' = ℛ; 𝒮' = 𝒮; buffered_val sb a = None⟧ ⟹ ∀i∈⋃ (fst ` write_sops sb'). i < t› 3. ‹⋀a D f A L R W. ⟦∀i∈⋃ (fst ` store_sops is). i < t; ∀i∈⋃ (fst ` write_sops sb). i < t; is = Write False a (D, f) A L R W # is'; θ' = θ; sb' = sb @ [Write⇩s⇩b False a (D, f) (f θ) A L R W]; m' = m; 𝒟' = 𝒟; 𝒪' = 𝒪; ℛ' = ℛ; 𝒮' = 𝒮⟧ ⟹ ∀i∈⋃ (fst ` write_sops sb'). i < t› 4. ‹⋀a D f A L R W. ⟦∀i∈⋃ (fst ` store_sops is). i < t; ∀i∈⋃ (fst ` write_sops sb). i < t; is = Write True a (D, f) A L R W # is'; θ' = θ; sb' = sb @ [Write⇩s⇩b True a (D, f) (f θ) A L R W]; m' = m; 𝒟' = True; 𝒪' = 𝒪; ℛ' = ℛ; 𝒮' = 𝒮⟧ ⟹ ∀i∈⋃ (fst ` write_sops sb'). i < t› 5. ‹⟦∀i∈⋃ (fst ` store_sops is). i < t; ∀i∈⋃ (fst ` write_sops sb). i < t; is = Fence # is'; sb = []; θ' = θ; sb' = []; m' = m; 𝒟' = False; 𝒪' = 𝒪; ℛ' = (λx. None); 𝒮' = 𝒮⟧ ⟹ ∀i∈⋃ (fst ` write_sops sb'). i < t› 6. ‹⋀cond ta a D f ret A L R W. ⟦∀i∈⋃ (fst ` store_sops is). i < t; ∀i∈⋃ (fst ` write_sops sb). i < t; is = RMW a ta (D, f) cond ret A L R W # is'; sb = []; θ' = θ(ta ↦ m a); sb' = []; m' = m; 𝒟' = False; 𝒪' = 𝒪; ℛ' = (λx. None); 𝒮' = 𝒮; ¬ cond (θ(ta ↦ m a))⟧ ⟹ ∀i∈⋃ (fst ` write_sops sb'). i < t› 7. ‹⋀cond ta a D f ret A L R W. ⟦∀i∈⋃ (fst ` store_sops is). i < t; ∀i∈⋃ (fst ` write_sops sb). i < t; is = RMW a ta (D, f) cond ret A L R W # is'; sb = []; θ' = θ(ta ↦ ret (m a) (f (θ(ta ↦ m a)))); sb' = []; m' = m(a := f (θ(ta ↦ m a))); 𝒟' = False; 𝒪' = 𝒪 ∪ A - R; ℛ' = (λx. None); 𝒮' = 𝒮 ⊕⇘W⇙ R ⊖⇘A⇙ L; cond (θ(ta ↦ m a))⟧ ⟹ ∀i∈⋃ (fst ` write_sops sb'). i < t› 8. ‹⋀A L R W. ⟦∀i∈⋃ (fst ` store_sops is). i < t; ∀i∈⋃ (fst ` write_sops sb). i < t; is = Ghost A L R W # is'; θ' = θ; sb' = sb @ [Ghost⇩s⇩b A L R W]; m' = m; 𝒟' = 𝒟; 𝒪' = 𝒪; ℛ' = ℛ; 𝒮' = 𝒮⟧ ⟹ ∀i∈⋃ (fst ` write_sops sb'). i < t› discuss goal 1*) apply ((auto simp add: write_sops_append (*‹write_sops ((?xs::?'a memref list) @ (?ys::?'a memref list)) = write_sops ?xs ∪ write_sops ?ys›*))[1]) (*discuss goal 2*) apply ((auto simp add: write_sops_append (*‹write_sops ((?xs::?'a::type memref list) @ (?ys::?'a::type memref list)) = write_sops ?xs ∪ write_sops ?ys›*))[1]) (*discuss goal 3*) apply ((auto simp add: write_sops_append (*‹write_sops (?xs @ ?ys) = write_sops ?xs ∪ write_sops ?ys›*))[1]) (*discuss goal 4*) apply ((auto simp add: write_sops_append (*‹write_sops (?xs @ ?ys) = write_sops ?xs ∪ write_sops ?ys›*))[1]) (*discuss goal 5*) apply ((auto simp add: write_sops_append (*‹write_sops (?xs @ ?ys) = write_sops ?xs ∪ write_sops ?ys›*))[1]) (*discuss goal 6*) apply ((auto simp add: write_sops_append (*‹write_sops ((?xs::?'a memref list) @ (?ys::?'a memref list)) = write_sops ?xs ∪ write_sops ?ys›*))[1]) (*discuss goal 7*) apply ((auto simp add: write_sops_append (*‹write_sops (?xs @ ?ys) = write_sops ?xs ∪ write_sops ?ys›*))[1]) (*discuss goal 8*) apply ((auto simp add: write_sops_append (*‹write_sops ((?xs::?'a memref list) @ (?ys::?'a memref list)) = write_sops ?xs ∪ write_sops ?ys›*))[1]) (*proven 8 subgoals*) . lemma sbh_step_prog_configs_eq: assumes step: "(is,θ,sb,m,𝒟,𝒪,ℛ,𝒮) →⇩s⇩b⇩h (is',θ',sb',m',𝒟',𝒪',ℛ',𝒮')" shows "prog_configs sb' = prog_configs sb" using step (*‹(is::instr list, θ::nat ⇒ nat option, sb::'a::type memref list, m::nat ⇒ nat, 𝒟::bool, 𝒪::nat set, ℛ::nat ⇒ bool option, 𝒮::nat ⇒ bool option) →⇩s⇩b⇩h (is'::instr list, θ'::nat ⇒ nat option, sb'::'a::type memref list, m'::nat ⇒ nat, 𝒟'::bool, 𝒪'::nat set, ℛ'::nat ⇒ bool option, 𝒮'::nat ⇒ bool option)›*) apply cases (*goals: 1. ‹⋀a v volatile t. ⟦is = Read volatile a t # is'; θ' = θ(t ↦ v); sb' = sb @ [Read⇩s⇩b volatile a t v]; m' = m; 𝒟' = 𝒟; 𝒪' = 𝒪; ℛ' = ℛ; 𝒮' = 𝒮; buffered_val sb a = Some v⟧ ⟹ prog_configs sb' = prog_configs sb› 2. ‹⋀a volatile t. ⟦is = Read volatile a t # is'; θ' = θ(t ↦ m a); sb' = sb @ [Read⇩s⇩b volatile a t (m a)]; m' = m; 𝒟' = 𝒟; 𝒪' = 𝒪; ℛ' = ℛ; 𝒮' = 𝒮; buffered_val sb a = None⟧ ⟹ prog_configs sb' = prog_configs sb› 3. ‹⋀a D f A L R W. ⟦is = Write False a (D, f) A L R W # is'; θ' = θ; sb' = sb @ [Write⇩s⇩b False a (D, f) (f θ) A L R W]; m' = m; 𝒟' = 𝒟; 𝒪' = 𝒪; ℛ' = ℛ; 𝒮' = 𝒮⟧ ⟹ prog_configs sb' = prog_configs sb› 4. ‹⋀a D f A L R W. ⟦is = Write True a (D, f) A L R W # is'; θ' = θ; sb' = sb @ [Write⇩s⇩b True a (D, f) (f θ) A L R W]; m' = m; 𝒟' = True; 𝒪' = 𝒪; ℛ' = ℛ; 𝒮' = 𝒮⟧ ⟹ prog_configs sb' = prog_configs sb› 5. ‹⟦is = Fence # is'; sb = []; θ' = θ; sb' = []; m' = m; 𝒟' = False; 𝒪' = 𝒪; ℛ' = (λx. None); 𝒮' = 𝒮⟧ ⟹ prog_configs sb' = prog_configs sb› 6. ‹⋀cond t a D f ret A L R W. ⟦is = RMW a t (D, f) cond ret A L R W # is'; sb = []; θ' = θ(t ↦ m a); sb' = []; m' = m; 𝒟' = False; 𝒪' = 𝒪; ℛ' = (λx. None); 𝒮' = 𝒮; ¬ cond (θ(t ↦ m a))⟧ ⟹ prog_configs sb' = prog_configs sb› 7. ‹⋀cond t a D f ret A L R W. ⟦is = RMW a t (D, f) cond ret A L R W # is'; sb = []; θ' = θ(t ↦ ret (m a) (f (θ(t ↦ m a)))); sb' = []; m' = m(a := f (θ(t ↦ m a))); 𝒟' = False; 𝒪' = 𝒪 ∪ A - R; ℛ' = (λx. None); 𝒮' = 𝒮 ⊕⇘W⇙ R ⊖⇘A⇙ L; cond (θ(t ↦ m a))⟧ ⟹ prog_configs sb' = prog_configs sb› 8. ‹⋀A L R W. ⟦is = Ghost A L R W # is'; θ' = θ; sb' = sb @ [Ghost⇩s⇩b A L R W]; m' = m; 𝒟' = 𝒟; 𝒪' = 𝒪; ℛ' = ℛ; 𝒮' = 𝒮⟧ ⟹ prog_configs sb' = prog_configs sb› discuss goal 1*) apply ((auto simp add: prog_configs_append (*‹prog_configs (?xs @ ?ys) = prog_configs ?xs ∪ prog_configs ?ys›*))[1]) (*discuss goal 2*) apply ((auto simp add: prog_configs_append (*‹prog_configs ((?xs::?'a memref list) @ (?ys::?'a memref list)) = prog_configs ?xs ∪ prog_configs ?ys›*))[1]) (*discuss goal 3*) apply ((auto simp add: prog_configs_append (*‹prog_configs (?xs @ ?ys) = prog_configs ?xs ∪ prog_configs ?ys›*))[1]) (*discuss goal 4*) apply ((auto simp add: prog_configs_append (*‹prog_configs (?xs @ ?ys) = prog_configs ?xs ∪ prog_configs ?ys›*))[1]) (*discuss goal 5*) apply ((auto simp add: prog_configs_append (*‹prog_configs (?xs @ ?ys) = prog_configs ?xs ∪ prog_configs ?ys›*))[1]) (*discuss goal 6*) apply ((auto simp add: prog_configs_append (*‹prog_configs (?xs @ ?ys) = prog_configs ?xs ∪ prog_configs ?ys›*))[1]) (*discuss goal 7*) apply ((auto simp add: prog_configs_append (*‹prog_configs (?xs @ ?ys) = prog_configs ?xs ∪ prog_configs ?ys›*))[1]) (*discuss goal 8*) apply ((auto simp add: prog_configs_append (*‹prog_configs (?xs @ ?ys) = prog_configs ?xs ∪ prog_configs ?ys›*))[1]) (*proven 8 subgoals*) . lemma sbh_step_preserves_tmps_bound': assumes step: "(is,θ,sb,m,𝒟,𝒪,ℛ,𝒮) →⇩s⇩b⇩h (is',θ',sb',m',𝒟',𝒪',ℛ',𝒮')" shows "dom θ ∪ load_tmps is = dom θ' ∪ load_tmps is'" using step (*‹(is, θ, sb, m, 𝒟, 𝒪, ℛ, 𝒮) →⇩s⇩b⇩h (is', θ', sb', m', 𝒟', 𝒪', ℛ', 𝒮')›*) apply cases (*goals: 1. ‹⋀(a::nat) (v::nat) (volatile::bool) t::nat. ⟦(is::instr list) = Read volatile a t # (is'::instr list); (θ'::nat ⇒ nat option) = (θ::nat ⇒ nat option)(t ↦ v); (sb'::'a memref list) = (sb::'a memref list) @ [Read⇩s⇩b volatile a t v]; (m'::nat ⇒ nat) = (m::nat ⇒ nat); (𝒟'::bool) = (𝒟::bool); (𝒪'::nat set) = (𝒪::nat set); (ℛ'::nat ⇒ bool option) = (ℛ::nat ⇒ bool option); (𝒮'::nat ⇒ bool option) = (𝒮::nat ⇒ bool option); buffered_val sb a = Some v⟧ ⟹ dom θ ∪ load_tmps is = dom θ' ∪ load_tmps is'› 2. ‹⋀(a::nat) (volatile::bool) t::nat. ⟦(is::instr list) = Read volatile a t # (is'::instr list); (θ'::nat ⇒ nat option) = (θ::nat ⇒ nat option)(t ↦ (m::nat ⇒ nat) a); (sb'::'a memref list) = (sb::'a memref list) @ [Read⇩s⇩b volatile a t (m a)]; (m'::nat ⇒ nat) = m; (𝒟'::bool) = (𝒟::bool); (𝒪'::nat set) = (𝒪::nat set); (ℛ'::nat ⇒ bool option) = (ℛ::nat ⇒ bool option); (𝒮'::nat ⇒ bool option) = (𝒮::nat ⇒ bool option); buffered_val sb a = None⟧ ⟹ dom θ ∪ load_tmps is = dom θ' ∪ load_tmps is'› 3. ‹⋀(a::nat) (D::nat set) (f::(nat ⇒ nat option) ⇒ nat) (A::nat set) (L::nat set) (R::nat set) W::nat set. ⟦(is::instr list) = Write False a (D, f) A L R W # (is'::instr list); (θ'::nat ⇒ nat option) = (θ::nat ⇒ nat option); (sb'::'a memref list) = (sb::'a memref list) @ [Write⇩s⇩b False a (D, f) (f θ) A L R W]; (m'::nat ⇒ nat) = (m::nat ⇒ nat); (𝒟'::bool) = (𝒟::bool); (𝒪'::nat set) = (𝒪::nat set); (ℛ'::nat ⇒ bool option) = (ℛ::nat ⇒ bool option); (𝒮'::nat ⇒ bool option) = (𝒮::nat ⇒ bool option)⟧ ⟹ dom θ ∪ load_tmps is = dom θ' ∪ load_tmps is'› 4. ‹⋀(a::nat) (D::nat set) (f::(nat ⇒ nat option) ⇒ nat) (A::nat set) (L::nat set) (R::nat set) W::nat set. ⟦(is::instr list) = Write True a (D, f) A L R W # (is'::instr list); (θ'::nat ⇒ nat option) = (θ::nat ⇒ nat option); (sb'::'a memref list) = (sb::'a memref list) @ [Write⇩s⇩b True a (D, f) (f θ) A L R W]; (m'::nat ⇒ nat) = (m::nat ⇒ nat); (𝒟'::bool) = True; (𝒪'::nat set) = (𝒪::nat set); (ℛ'::nat ⇒ bool option) = (ℛ::nat ⇒ bool option); (𝒮'::nat ⇒ bool option) = (𝒮::nat ⇒ bool option)⟧ ⟹ dom θ ∪ load_tmps is = dom θ' ∪ load_tmps is'› 5. ‹⟦(is::instr list) = Fence # (is'::instr list); (sb::'a memref list) = []; (θ'::nat ⇒ nat option) = (θ::nat ⇒ nat option); (sb'::'a memref list) = []; (m'::nat ⇒ nat) = (m::nat ⇒ nat); (𝒟'::bool) = False; (𝒪'::nat set) = (𝒪::nat set); (ℛ'::nat ⇒ bool option) = (λx::nat. None); (𝒮'::nat ⇒ bool option) = (𝒮::nat ⇒ bool option)⟧ ⟹ dom θ ∪ load_tmps is = dom θ' ∪ load_tmps is'› 6. ‹⋀(cond::(nat ⇒ nat option) ⇒ bool) (t::nat) (a::nat) (D::nat set) (f::(nat ⇒ nat option) ⇒ nat) (ret::nat ⇒ nat ⇒ nat) (A::nat set) (L::nat set) (R::nat set) W::nat set. ⟦(is::instr list) = RMW a t (D, f) cond ret A L R W # (is'::instr list); (sb::'a memref list) = []; (θ'::nat ⇒ nat option) = (θ::nat ⇒ nat option)(t ↦ (m::nat ⇒ nat) a); (sb'::'a memref list) = []; (m'::nat ⇒ nat) = m; (𝒟'::bool) = False; (𝒪'::nat set) = (𝒪::nat set); (ℛ'::nat ⇒ bool option) = (λx::nat. None); (𝒮'::nat ⇒ bool option) = (𝒮::nat ⇒ bool option); ¬ cond (θ(t ↦ m a))⟧ ⟹ dom θ ∪ load_tmps is = dom θ' ∪ load_tmps is'› 7. ‹⋀(cond::(nat ⇒ nat option) ⇒ bool) (t::nat) (a::nat) (D::nat set) (f::(nat ⇒ nat option) ⇒ nat) (ret::nat ⇒ nat ⇒ nat) (A::nat set) (L::nat set) (R::nat set) W::nat set. ⟦(is::instr list) = RMW a t (D, f) cond ret A L R W # (is'::instr list); (sb::'a memref list) = []; (θ'::nat ⇒ nat option) = (θ::nat ⇒ nat option)(t ↦ ret ((m::nat ⇒ nat) a) (f (θ(t ↦ m a)))); (sb'::'a memref list) = []; (m'::nat ⇒ nat) = m(a := f (θ(t ↦ m a))); (𝒟'::bool) = False; (𝒪'::nat set) = (𝒪::nat set) ∪ A - R; (ℛ'::nat ⇒ bool option) = (λx::nat. None); (𝒮'::nat ⇒ bool option) = (𝒮::nat ⇒ bool option) ⊕⇘W⇙ R ⊖⇘A⇙ L; cond (θ(t ↦ m a))⟧ ⟹ dom θ ∪ load_tmps is = dom θ' ∪ load_tmps is'› 8. ‹⋀(A::nat set) (L::nat set) (R::nat set) W::nat set. ⟦(is::instr list) = Ghost A L R W # (is'::instr list); (θ'::nat ⇒ nat option) = (θ::nat ⇒ nat option); (sb'::'a memref list) = (sb::'a memref list) @ [Ghost⇩s⇩b A L R W]; (m'::nat ⇒ nat) = (m::nat ⇒ nat); (𝒟'::bool) = (𝒟::bool); (𝒪'::nat set) = (𝒪::nat set); (ℛ'::nat ⇒ bool option) = (ℛ::nat ⇒ bool option); (𝒮'::nat ⇒ bool option) = (𝒮::nat ⇒ bool option)⟧ ⟹ dom θ ∪ load_tmps is = dom θ' ∪ load_tmps is'› discuss goal 1*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 2*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 3*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 4*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 5*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 6*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 7*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*discuss goal 8*) apply ((auto simp add: read_tmps_append (*‹read_tmps (?xs @ ?ys) = read_tmps ?xs ∪ read_tmps ?ys›*))[1]) (*proven 8 subgoals*) . lemma sbh_step_preserves_separated_tmps: assumes i_bound: "i < length ts" assumes ts_i: "ts!i = (p,is,θ,sb,𝒟,𝒪,ℛ)" assumes memop_step: "(is, θ, sb, m,𝒟, 𝒪, ℛ,𝒮) →⇩s⇩b⇩h (is', θ', sb', m',𝒟', 𝒪', ℛ',𝒮')" assumes instr: "separated_tmps ts" shows "separated_tmps (ts [i:=(p,is',θ',sb',𝒟',𝒪',ℛ')])" proof (-) (*goal: ‹separated_tmps (ts[i := (p, is', θ', sb', 𝒟', 𝒪', ℛ')])›*) obtain s and t where p: "p=(s,t)" (*goal: ‹(⋀s t. p = (s, t) ⟹ thesis) ⟹ thesis›*) by (cases p) note ts_i = ts_i[simplified p] (*‹ts ! i = ((s, t), is, θ, sb, 𝒟, 𝒪, ℛ)›*) interpret separated_tmps ts by fact have "separated_tmps (ts [i:=((s,t),is',θ',sb',𝒟',𝒪',ℛ')])" proof (rule separated_tmps_nth_update [OF i_bound] (*‹⟦valid_sops_stmt ?t ?s; ∀(s', t')∈prog_configs ?sb. valid_sops_stmt t' s'; ∀i∈load_tmps ?is. i < ?t; ∀i∈read_tmps ?sb. i < ?t; ∀i∈⋃ (fst ` store_sops ?is). i < ?t; ∀i∈⋃ (fst ` write_sops ?sb). i < ?t; dom ?θ ∪ load_tmps ?is = {i. i < ?t}⟧ ⟹ separated_tmps (ts[i := ((?s, ?t), ?is, ?θ, ?sb, ?𝒟, ?𝒪)])›*)) (*goals: 1. ‹valid_sops_stmt t s› 2. ‹∀(s', t')∈prog_configs sb'. valid_sops_stmt t' s'› 3. ‹∀i∈load_tmps is'. i < t› 4. ‹∀i∈read_tmps sb'. i < t› 5. ‹∀i∈⋃ (fst ` store_sops is'). i < t› 6. ‹∀i∈⋃ (fst ` write_sops sb'). i < t› 7. ‹dom θ' ∪ load_tmps is' = {i. i < t}›*) from sbh_step_preserves_load_tmps_bound[OF memop_step load_tmps_le [ OF i_bound ts_i ]] (*‹∀i∈load_tmps is'. i < t›*) show "∀i∈load_tmps is'. i < t" . next (*goals: 1. ‹valid_sops_stmt (t::nat) (s::stmt)› 2. ‹∀(s'::stmt, t'::nat)∈prog_configs (sb'::(stmt × nat) memref list). valid_sops_stmt t' s'› 3. ‹∀i::nat∈read_tmps (sb'::(stmt × nat) memref list). i < (t::nat)› 4. ‹∀i::nat∈⋃ (fst ` store_sops (is'::instr list)). i < (t::nat)› 5. ‹∀i::nat∈⋃ (fst ` write_sops (sb'::(stmt × nat) memref list)). i < (t::nat)› 6. ‹dom (θ'::nat ⇒ nat option) ∪ load_tmps (is'::instr list) = {i::nat. i < (t::nat)}›*) from sbh_step_preserves_read_tmps_bound[OF memop_step load_tmps_le [ OF i_bound ts_i ] read_tmps_le [ OF i_bound ts_i ]] (*‹∀i∈read_tmps sb'. i < t›*) show "∀i∈read_tmps sb'. i < t" . next (*goals: 1. ‹valid_sops_stmt (t::nat) (s::stmt)› 2. ‹∀(s'::stmt, t'::nat)∈prog_configs (sb'::(stmt × nat) memref list). valid_sops_stmt t' s'› 3. ‹∀i::nat∈⋃ (fst ` store_sops (is'::instr list)). i < (t::nat)› 4. ‹∀i::nat∈⋃ (fst ` write_sops (sb'::(stmt × nat) memref list)). i < (t::nat)› 5. ‹dom (θ'::nat ⇒ nat option) ∪ load_tmps (is'::instr list) = {i::nat. i < (t::nat)}›*) from sbh_step_preserves_store_sops_bound[OF memop_step store_sops_le [ OF i_bound ts_i ]] (*‹∀i∈⋃ (fst ` store_sops is'). i < t›*) show "∀i∈⋃(fst ` store_sops is'). i < t" . next (*goals: 1. ‹valid_sops_stmt (t::nat) (s::stmt)› 2. ‹∀(s'::stmt, t'::nat)∈prog_configs (sb'::(stmt × nat) memref list). valid_sops_stmt t' s'› 3. ‹∀i::nat∈⋃ (fst ` write_sops (sb'::(stmt × nat) memref list)). i < (t::nat)› 4. ‹dom (θ'::nat ⇒ nat option) ∪ load_tmps (is'::instr list) = {i::nat. i < (t::nat)}›*) from sbh_step_preserves_write_sops_bound[OF memop_step store_sops_le [ OF i_bound ts_i ] write_sops_le [ OF i_bound ts_i ]] (*‹∀i∈⋃ (fst ` write_sops sb'). i < t›*) show "∀i∈⋃(fst ` write_sops sb'). i < t" . next (*goals: 1. ‹valid_sops_stmt t s› 2. ‹∀(s', t')∈prog_configs sb'. valid_sops_stmt t' s'› 3. ‹dom θ' ∪ load_tmps is' = {i. i < t}›*) from sbh_step_preserves_tmps_bound'[OF memop_step] (*‹dom θ ∪ load_tmps is = dom θ' ∪ load_tmps is'›*) tmps_le[OF i_bound ts_i] (*‹dom θ ∪ load_tmps is = {i. i < t}›*) show "dom θ' ∪ load_tmps is' = {i. i < t}" by auto next (*goals: 1. ‹valid_sops_stmt t s› 2. ‹∀(s', t')∈prog_configs sb'. valid_sops_stmt t' s'›*) from valid_sops_stmt[OF i_bound ts_i] (*‹valid_sops_stmt t s›*) show "valid_sops_stmt t s" . next (*goal: ‹∀(s', t')∈prog_configs sb'. valid_sops_stmt t' s'›*) from valid_sops_stmt_sb[OF i_bound ts_i] (*‹(?s', ?t') ∈ prog_configs sb ⟹ valid_sops_stmt ?t' ?s'›*) sbh_step_prog_configs_eq[OF memop_step] (*‹prog_configs sb' = prog_configs sb›*) show "∀(s', t')∈prog_configs sb'. valid_sops_stmt t' s'" by auto qed then show "?thesis" (*goal: ‹separated_tmps (ts[i := (p, is', θ', sb', 𝒟', 𝒪', ℛ')])›*) by (simp add: p (*‹p = (s, t)›*)) qed definition "valid_pimp ts ≡ separated_tmps ts" lemma prog_step_preserves_valid: assumes i_bound: "i < length ts" assumes ts_i: "ts!i = (p,is,θ,sb::stmt_config store_buffer,𝒟,𝒪,ℛ)" assumes prog_step: "θ⊢ p →⇩s (p', is')" assumes valid: "valid_pimp ts" shows "valid_pimp (ts [i:=(p',is@is',θ,sb@[Prog⇩s⇩b p p' is'],𝒟,𝒪,ℛ)])" using prog_step_preserves_separated_tmps[OF i_bound ts_i prog_step] (*‹separated_tmps ts ⟹ separated_tmps (ts[i := (p', is @ is', θ, sb @ [Prog⇩s⇩b p p' is'], 𝒟, 𝒪, ℛ)])›*) valid (*‹valid_pimp (ts::((stmt × nat) × instr list × (nat ⇒ nat option) × (stmt × nat) memref list × 'a × 'b × 'c) list)›*) by (auto simp add: valid_pimp_def (*‹valid_pimp ?ts ≡ separated_tmps ?ts›*)) lemma flush_step_preserves_valid: assumes i_bound: "i < length ts" assumes ts_i: "ts!i = (p,is,θ,sb::stmt_config store_buffer,𝒟,𝒪,ℛ)" assumes flush_step: "(m,sb,𝒪,ℛ,𝒮) →⇩f (m', sb',𝒪',ℛ',𝒮')" assumes valid: "valid_pimp ts" shows "valid_pimp (ts [i:=(p,is,θ,sb',𝒟,𝒪',ℛ')])" using flush_step_preserves_separated_tmps[OF i_bound ts_i flush_step] (*‹separated_tmps ts ⟹ separated_tmps (ts[i := (p, is, θ, sb', 𝒟, 𝒪', ℛ')])›*) valid (*‹valid_pimp ts›*) by (auto simp add: valid_pimp_def (*‹valid_pimp ?ts ≡ separated_tmps ?ts›*)) lemma sbh_step_preserves_valid: assumes i_bound: "i < length ts" assumes ts_i: "ts!i = (p,is,θ,sb::stmt_config store_buffer,𝒟,𝒪,ℛ)" assumes memop_step: "(is, θ, sb, m,𝒟, 𝒪, ℛ,𝒮) →⇩s⇩b⇩h (is', θ', sb', m',𝒟', 𝒪', ℛ', 𝒮')" assumes valid: "valid_pimp ts" shows "valid_pimp (ts [i:=(p,is',θ',sb',𝒟',𝒪',ℛ')])" using sbh_step_preserves_separated_tmps[OF i_bound ts_i memop_step] (*‹separated_tmps ts ⟹ separated_tmps (ts[i := (p, is', θ', sb', 𝒟', 𝒪', ℛ')])›*) valid (*‹valid_pimp ts›*) by (auto simp add: valid_pimp_def (*‹valid_pimp ?ts ≡ separated_tmps ?ts›*)) lemma hd_prog_prog_configs: "hd_prog p sb = p ∨ hd_prog p sb ∈ prog_configs sb" apply (induct sb) (*goals: 1. ‹hd_prog (p::'a) [] = p ∨ hd_prog p [] ∈ prog_configs []› 2. ‹⋀(a::'a memref) sb::'a memref list. hd_prog (p::'a) sb = p ∨ hd_prog p sb ∈ prog_configs sb ⟹ hd_prog p (a # sb) = p ∨ hd_prog p (a # sb) ∈ prog_configs (a # sb)› discuss goal 1*) apply ((auto split:memref.splits (*‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = ((∀x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ⟶ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∧ (∀x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ⟶ ?P (?f2.0 x21 x22 x23 x24)) ∧ (∀x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ⟶ ?P (?f3.0 x31 x32 x33)) ∧ (∀x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ⟶ ?P (?f4.0 x41 x42 x43 x44)))› ‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = (¬ ((∃x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ∧ ¬ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∨ (∃x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ∧ ¬ ?P (?f2.0 x21 x22 x23 x24)) ∨ (∃x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ∧ ¬ ?P (?f3.0 x31 x32 x33)) ∨ (∃x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ∧ ¬ ?P (?f4.0 x41 x42 x43 x44))))›*))[1]) (*discuss goal 2*) apply ((auto split:memref.splits (*‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = ((∀x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ⟶ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∧ (∀x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ⟶ ?P (?f2.0 x21 x22 x23 x24)) ∧ (∀x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ⟶ ?P (?f3.0 x31 x32 x33)) ∧ (∀x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ⟶ ?P (?f4.0 x41 x42 x43 x44)))› ‹?P (case ?memref of Write⇩s⇩b x xa xb xc xd xe xf xg ⇒ ?f1.0 x xa xb xc xd xe xf xg | Read⇩s⇩b x xa xb xc ⇒ ?f2.0 x xa xb xc | Prog⇩s⇩b x xa xb ⇒ ?f3.0 x xa xb | Ghost⇩s⇩b x xa xb xc ⇒ ?f4.0 x xa xb xc) = (¬ ((∃x11 x12 x13 x14 x15 x16 x17 x18. ?memref = Write⇩s⇩b x11 x12 x13 x14 x15 x16 x17 x18 ∧ ¬ ?P (?f1.0 x11 x12 x13 x14 x15 x16 x17 x18)) ∨ (∃x21 x22 x23 x24. ?memref = Read⇩s⇩b x21 x22 x23 x24 ∧ ¬ ?P (?f2.0 x21 x22 x23 x24)) ∨ (∃x31 x32 x33. ?memref = Prog⇩s⇩b x31 x32 x33 ∧ ¬ ?P (?f3.0 x31 x32 x33)) ∨ (∃x41 x42 x43 x44. ?memref = Ghost⇩s⇩b x41 x42 x43 x44 ∧ ¬ ?P (?f4.0 x41 x42 x43 x44))))›*))[1]) (*proven 2 subgoals*) . interpretation PIMP: xvalid_program_progress stmt_step "λ(s,t). valid_sops_stmt t s" valid_pimp proof (standard) (*goals: 1. ‹⋀θ p p' is'. θ⊢ p →⇩s (p', is') ⟹ p' ≠ p ∨ is' ≠ []› 2. ‹⋀θ p p' is'. ⟦θ⊢ p →⇩s (p', is'); case p of (s, t) ⇒ valid_sops_stmt t s⟧ ⟹ case p' of (s, t) ⇒ valid_sops_stmt t s› 3. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); valid_pimp ts⟧ ⟹ case p of (s, t) ⇒ valid_sops_stmt t s› 4. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); valid_pimp ts⟧ ⟹ case hd_prog p sb of (s, t) ⇒ valid_sops_stmt t s› 5. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ distinct_load_tmps is' ∧ load_tmps is' ∩ load_tmps is = {} ∧ load_tmps is' ∩ read_tmps sb = {}› 6. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ data_dependency_consistent_instrs (dom θ ∪ load_tmps is) is' ∧ load_tmps is' ∩ ⋃ (fst ` store_sops is) = {} ∧ load_tmps is' ∩ ⋃ (fst ` write_sops sb) = {}› 7. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ load_tmps is' ∩ dom θ = {}› 8. ‹⋀θ p p' is'. ⟦θ⊢ p →⇩s (p', is'); case p of (s, t) ⇒ valid_sops_stmt t s⟧ ⟹ ∀sop∈store_sops is'. valid_sop sop› 9. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p', is @ is', θ, sb @ [Prog⇩s⇩b p p' is'], 𝒟, 𝒪, ℛ)])› 10. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ m 𝒮 m' sb' 𝒪' ℛ' 𝒮'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); (m, sb, 𝒪, ℛ, 𝒮) →⇩f (m', sb', 𝒪', ℛ', 𝒮'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p, is, θ, sb', 𝒟, 𝒪', ℛ')])› 11. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ m 𝒮 is' θ' sb' m' 𝒟' 𝒪' ℛ' 𝒮'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); (is, θ, sb, m, 𝒟, 𝒪, ℛ, 𝒮) →⇩s⇩b⇩h (is', θ', sb', m', 𝒟', 𝒪', ℛ', 𝒮'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p, is', θ', sb', 𝒟', 𝒪', ℛ')])›*) fix θ and p and p' and is' assume step: "θ⊢ p →⇩s (p', is')" (*‹(θ::nat ⇒ nat option)⊢ (p::stmt × nat) →⇩s (p'::stmt × nat, is'::instr list)›*) obtain s and t where p: "p = (s,t)" (*goal: ‹(⋀s t. p = (s, t) ⟹ thesis) ⟹ thesis›*) by (cases p) obtain s' and t' where p': "p' = (s',t')" (*goal: ‹(⋀s' t'. p' = (s', t') ⟹ thesis) ⟹ thesis›*) by (cases p') from prog_step_progress[OF step [ simplified p p' ]] (*‹(s'::stmt, t'::nat) ≠ (s::stmt, t::nat) ∨ (is'::instr list) ≠ []›*) show "p' ≠ p ∨ is' ≠ []" by (simp add: p (*‹p = (s, t)›*) p' (*‹p' = (s', t')›*)) next (*goals: 1. ‹⋀θ p p' is'. ⟦θ⊢ p →⇩s (p', is'); case p of (s, t) ⇒ valid_sops_stmt t s⟧ ⟹ case p' of (s, t) ⇒ valid_sops_stmt t s› 2. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); valid_pimp ts⟧ ⟹ case p of (s, t) ⇒ valid_sops_stmt t s› 3. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); valid_pimp ts⟧ ⟹ case hd_prog p sb of (s, t) ⇒ valid_sops_stmt t s› 4. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ distinct_load_tmps is' ∧ load_tmps is' ∩ load_tmps is = {} ∧ load_tmps is' ∩ read_tmps sb = {}› 5. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ data_dependency_consistent_instrs (dom θ ∪ load_tmps is) is' ∧ load_tmps is' ∩ ⋃ (fst ` store_sops is) = {} ∧ load_tmps is' ∩ ⋃ (fst ` write_sops sb) = {}› 6. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ load_tmps is' ∩ dom θ = {}› 7. ‹⋀θ p p' is'. ⟦θ⊢ p →⇩s (p', is'); case p of (s, t) ⇒ valid_sops_stmt t s⟧ ⟹ ∀sop∈store_sops is'. valid_sop sop› 8. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p', is @ is', θ, sb @ [Prog⇩s⇩b p p' is'], 𝒟, 𝒪, ℛ)])› 9. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ m 𝒮 m' sb' 𝒪' ℛ' 𝒮'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); (m, sb, 𝒪, ℛ, 𝒮) →⇩f (m', sb', 𝒪', ℛ', 𝒮'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p, is, θ, sb', 𝒟, 𝒪', ℛ')])› 10. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ m 𝒮 is' θ' sb' m' 𝒟' 𝒪' ℛ' 𝒮'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); (is, θ, sb, m, 𝒟, 𝒪, ℛ, 𝒮) →⇩s⇩b⇩h (is', θ', sb', m', 𝒟', 𝒪', ℛ', 𝒮'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p, is', θ', sb', 𝒟', 𝒪', ℛ')])›*) fix θ and p and p' and is' assume step: "θ⊢ p →⇩s (p', is')" and valid_stmt: "(λ(s, t). valid_sops_stmt t s) p" (*‹(θ::nat ⇒ nat option)⊢ (p::stmt × nat) →⇩s (p'::stmt × nat, is'::instr list)› ‹case p::stmt × nat of (s::stmt, t::nat) ⇒ valid_sops_stmt t s›*) obtain s and t where p: "p = (s,t)" (*goal: ‹(⋀s t. p = (s, t) ⟹ thesis) ⟹ thesis›*) by (cases p) obtain s' and t' where p': "p' = (s',t')" (*goal: ‹(⋀(s'::stmt) t'::nat. (p'::stmt × nat) = (s', t') ⟹ thesis::bool) ⟹ thesis›*) by (cases p') from valid_sops_stmt_invariant[OF step [ simplified p p' ] valid_stmt [ simplified p , simplified ]] (*‹valid_sops_stmt t' s'›*) have "valid_sops_stmt t' s'" . then show "(λ(s, t). valid_sops_stmt t s) p'" by (simp add: p' (*‹p' = (s', t')›*)) next (*goals: 1. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); valid_pimp ts⟧ ⟹ case p of (s, t) ⇒ valid_sops_stmt t s› 2. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); valid_pimp ts⟧ ⟹ case hd_prog p sb of (s, t) ⇒ valid_sops_stmt t s› 3. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ distinct_load_tmps is' ∧ load_tmps is' ∩ load_tmps is = {} ∧ load_tmps is' ∩ read_tmps sb = {}› 4. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ data_dependency_consistent_instrs (dom θ ∪ load_tmps is) is' ∧ load_tmps is' ∩ ⋃ (fst ` store_sops is) = {} ∧ load_tmps is' ∩ ⋃ (fst ` write_sops sb) = {}› 5. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ load_tmps is' ∩ dom θ = {}› 6. ‹⋀θ p p' is'. ⟦θ⊢ p →⇩s (p', is'); case p of (s, t) ⇒ valid_sops_stmt t s⟧ ⟹ ∀sop∈store_sops is'. valid_sop sop› 7. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p', is @ is', θ, sb @ [Prog⇩s⇩b p p' is'], 𝒟, 𝒪, ℛ)])› 8. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ m 𝒮 m' sb' 𝒪' ℛ' 𝒮'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); (m, sb, 𝒪, ℛ, 𝒮) →⇩f (m', sb', 𝒪', ℛ', 𝒮'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p, is, θ, sb', 𝒟, 𝒪', ℛ')])› 9. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ m 𝒮 is' θ' sb' m' 𝒟' 𝒪' ℛ' 𝒮'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); (is, θ, sb, m, 𝒟, 𝒪, ℛ, 𝒮) →⇩s⇩b⇩h (is', θ', sb', m', 𝒟', 𝒪', ℛ', 𝒮'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p, is', θ', sb', 𝒟', 𝒪', ℛ')])›*) fix i and ts and p and is and 𝒪 and ℛ and 𝒟 and θ and sb assume i_bound: "i < length ts" and ts_i: "ts ! i = (p, is, θ, sb::(stmt × nat) memref list, 𝒟, 𝒪,ℛ)" and valid: "valid_pimp ts" (*‹(i::nat) < length (ts::((stmt × nat) × instr list × (nat ⇒ 'a option) × (stmt × nat) memref list × 'b × 'c × 'd) list)› ‹(ts::((stmt × nat) × instr list × (nat ⇒ 'a option) × (stmt × nat) memref list × 'b × 'c × 'd) list) ! (i::nat) = (p::stmt × nat, is::instr list, θ::nat ⇒ 'a option, sb::(stmt × nat) memref list, 𝒟::'b, 𝒪::'c, ℛ::'d)› ‹valid_pimp (ts::((stmt × nat) × instr list × (nat ⇒ 'a option) × (stmt × nat) memref list × 'b × 'c × 'd) list)›*) from valid (*‹valid_pimp ts›*) have "separated_tmps ts" by (simp add: valid_pimp_def (*‹valid_pimp ?ts ≡ separated_tmps ?ts›*)) then interpret separated_tmps ts . obtain s and t where p: "p = (s,t)" (*goal: ‹(⋀s t. p = (s, t) ⟹ thesis) ⟹ thesis›*) by (cases p) from valid_sops_stmt[OF i_bound ts_i [ simplified p ]] (*‹valid_sops_stmt t s›*) show "(λ(s, t). valid_sops_stmt t s) p" by (auto simp add: p (*‹p = (s, t)›*)) next (*goals: 1. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); valid_pimp ts⟧ ⟹ case hd_prog p sb of (s, t) ⇒ valid_sops_stmt t s› 2. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ distinct_load_tmps is' ∧ load_tmps is' ∩ load_tmps is = {} ∧ load_tmps is' ∩ read_tmps sb = {}› 3. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ data_dependency_consistent_instrs (dom θ ∪ load_tmps is) is' ∧ load_tmps is' ∩ ⋃ (fst ` store_sops is) = {} ∧ load_tmps is' ∩ ⋃ (fst ` write_sops sb) = {}› 4. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ load_tmps is' ∩ dom θ = {}› 5. ‹⋀θ p p' is'. ⟦θ⊢ p →⇩s (p', is'); case p of (s, t) ⇒ valid_sops_stmt t s⟧ ⟹ ∀sop∈store_sops is'. valid_sop sop› 6. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p', is @ is', θ, sb @ [Prog⇩s⇩b p p' is'], 𝒟, 𝒪, ℛ)])› 7. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ m 𝒮 m' sb' 𝒪' ℛ' 𝒮'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); (m, sb, 𝒪, ℛ, 𝒮) →⇩f (m', sb', 𝒪', ℛ', 𝒮'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p, is, θ, sb', 𝒟, 𝒪', ℛ')])› 8. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ m 𝒮 is' θ' sb' m' 𝒟' 𝒪' ℛ' 𝒮'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); (is, θ, sb, m, 𝒟, 𝒪, ℛ, 𝒮) →⇩s⇩b⇩h (is', θ', sb', m', 𝒟', 𝒪', ℛ', 𝒮'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p, is', θ', sb', 𝒟', 𝒪', ℛ')])›*) fix i and ts and p and is and 𝒪 and ℛ and 𝒟 and θ and sb assume i_bound: "i < length ts" and ts_i: "ts ! i = (p, is, θ, sb::(stmt × nat) memref list, 𝒟, 𝒪,ℛ)" and valid: "valid_pimp ts" (*‹(i::nat) < length (ts::((stmt × nat) × instr list × (nat ⇒ 'a option) × (stmt × nat) memref list × 'b × 'c × 'd) list)› ‹(ts::((stmt × nat) × instr list × (nat ⇒ 'a option) × (stmt × nat) memref list × 'b × 'c × 'd) list) ! (i::nat) = (p::stmt × nat, is::instr list, θ::nat ⇒ 'a option, sb::(stmt × nat) memref list, 𝒟::'b, 𝒪::'c, ℛ::'d)› ‹valid_pimp (ts::((stmt × nat) × instr list × (nat ⇒ 'a option) × (stmt × nat) memref list × 'b × 'c × 'd) list)›*) from valid (*‹valid_pimp ts›*) have "separated_tmps ts" by (simp add: valid_pimp_def (*‹valid_pimp ?ts ≡ separated_tmps ?ts›*)) then interpret separated_tmps ts . obtain s and t where p: "p = (s,t)" (*goal: ‹(⋀s t. p = (s, t) ⟹ thesis) ⟹ thesis›*) by (cases p) from hd_prog_prog_configs[of p sb] (*‹hd_prog (p::stmt × nat) (sb::(stmt × nat) memref list) = p ∨ hd_prog p sb ∈ prog_configs sb›*) valid_sops_stmt[OF i_bound ts_i [ simplified p ]] (*‹valid_sops_stmt t s›*) valid_sops_stmt_sb[OF i_bound ts_i [ simplified p ]] (*‹(?s', ?t') ∈ prog_configs sb ⟹ valid_sops_stmt ?t' ?s'›*) show "(λ(s, t). valid_sops_stmt t s) (hd_prog p sb)" by (auto simp add: p (*‹(p::stmt × nat) = (s::stmt, t::nat)›*)) next (*goals: 1. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ distinct_load_tmps is' ∧ load_tmps is' ∩ load_tmps is = {} ∧ load_tmps is' ∩ read_tmps sb = {}› 2. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ data_dependency_consistent_instrs (dom θ ∪ load_tmps is) is' ∧ load_tmps is' ∩ ⋃ (fst ` store_sops is) = {} ∧ load_tmps is' ∩ ⋃ (fst ` write_sops sb) = {}› 3. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ load_tmps is' ∩ dom θ = {}› 4. ‹⋀θ p p' is'. ⟦θ⊢ p →⇩s (p', is'); case p of (s, t) ⇒ valid_sops_stmt t s⟧ ⟹ ∀sop∈store_sops is'. valid_sop sop› 5. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p', is @ is', θ, sb @ [Prog⇩s⇩b p p' is'], 𝒟, 𝒪, ℛ)])› 6. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ m 𝒮 m' sb' 𝒪' ℛ' 𝒮'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); (m, sb, 𝒪, ℛ, 𝒮) →⇩f (m', sb', 𝒪', ℛ', 𝒮'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p, is, θ, sb', 𝒟, 𝒪', ℛ')])› 7. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ m 𝒮 is' θ' sb' m' 𝒟' 𝒪' ℛ' 𝒮'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); (is, θ, sb, m, 𝒟, 𝒪, ℛ, 𝒮) →⇩s⇩b⇩h (is', θ', sb', m', 𝒟', 𝒪', ℛ', 𝒮'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p, is', θ', sb', 𝒟', 𝒪', ℛ')])›*) fix i and ts and p and is and 𝒪 and ℛ and 𝒟 and θ and sb and p' and is' assume i_bound: "i < length ts" and ts_i: "ts ! i = (p, is, θ, sb, 𝒟, 𝒪,ℛ)" and step: "θ⊢ p →⇩s (p', is')" and valid: "valid_pimp ts" (*‹(i::nat) < length (ts::((stmt × nat) × instr list × (nat ⇒ nat option) × (stmt × nat) memref list × 'a × 'b × 'c) list)› ‹(ts::((stmt × nat) × instr list × (nat ⇒ nat option) × (stmt × nat) memref list × 'a × 'b × 'c) list) ! (i::nat) = (p::stmt × nat, is::instr list, θ::nat ⇒ nat option, sb::(stmt × nat) memref list, 𝒟::'a, 𝒪::'b, ℛ::'c)› ‹(θ::nat ⇒ nat option)⊢ (p::stmt × nat) →⇩s (p'::stmt × nat, is'::instr list)› ‹valid_pimp (ts::((stmt × nat) × instr list × (nat ⇒ nat option) × (stmt × nat) memref list × 'a × 'b × 'c) list)›*) show "distinct_load_tmps is' ∧ load_tmps is' ∩ load_tmps is = {} ∧ load_tmps is' ∩ read_tmps sb = {}" proof (-) (*goal: ‹distinct_load_tmps (is'::instr list) ∧ load_tmps is' ∩ load_tmps (is::instr list) = {} ∧ load_tmps is' ∩ read_tmps (sb::(stmt × nat) memref list) = {}›*) obtain s and t where p: "p=(s,t)" (*goal: ‹(⋀s t. p = (s, t) ⟹ thesis) ⟹ thesis›*) by (cases p) obtain s' and t' where p': "p'=(s',t')" (*goal: ‹(⋀s' t'. p' = (s', t') ⟹ thesis) ⟹ thesis›*) by (cases p') note ts_i = ts_i[simplified p] (*‹(ts::((stmt × nat) × instr list × (nat ⇒ nat option) × (stmt × nat) memref list × 'a::type × 'b::type × 'c::type) list) ! (i::nat) = ((s::stmt, t::nat), is::instr list, θ::nat ⇒ nat option, sb::(stmt × nat) memref list, 𝒟::'a::type, 𝒪::'b::type, ℛ::'c::type)›*) note step = step[simplified p p'] (*‹θ⊢ (s, t) →⇩s ((s', t'), is')›*) from valid (*‹valid_pimp ts›*) interpret separated_tmps ts by (simp add: valid_pimp_def (*‹valid_pimp ?ts ≡ separated_tmps ?ts›*)) from sbh_step_distinct_load_tmps_prog_step[OF step load_tmps_le [ OF i_bound ts_i ] read_tmps_le [ OF i_bound ts_i ]] (*‹distinct_load_tmps is' ∧ load_tmps is' ∩ load_tmps is = {} ∧ load_tmps is' ∩ read_tmps sb = {}›*) show "?thesis" (*goal: ‹distinct_load_tmps (is'::instr list) ∧ load_tmps is' ∩ load_tmps (is::instr list) = {} ∧ load_tmps is' ∩ read_tmps (sb::(stmt × nat) memref list) = {}›*) . qed next (*goals: 1. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ data_dependency_consistent_instrs (dom θ ∪ load_tmps is) is' ∧ load_tmps is' ∩ ⋃ (fst ` store_sops is) = {} ∧ load_tmps is' ∩ ⋃ (fst ` write_sops sb) = {}› 2. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ load_tmps is' ∩ dom θ = {}› 3. ‹⋀θ p p' is'. ⟦θ⊢ p →⇩s (p', is'); case p of (s, t) ⇒ valid_sops_stmt t s⟧ ⟹ ∀sop∈store_sops is'. valid_sop sop› 4. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p', is @ is', θ, sb @ [Prog⇩s⇩b p p' is'], 𝒟, 𝒪, ℛ)])› 5. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ m 𝒮 m' sb' 𝒪' ℛ' 𝒮'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); (m, sb, 𝒪, ℛ, 𝒮) →⇩f (m', sb', 𝒪', ℛ', 𝒮'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p, is, θ, sb', 𝒟, 𝒪', ℛ')])› 6. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ m 𝒮 is' θ' sb' m' 𝒟' 𝒪' ℛ' 𝒮'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); (is, θ, sb, m, 𝒟, 𝒪, ℛ, 𝒮) →⇩s⇩b⇩h (is', θ', sb', m', 𝒟', 𝒪', ℛ', 𝒮'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p, is', θ', sb', 𝒟', 𝒪', ℛ')])›*) fix i and ts and p and is and 𝒪 and ℛ and 𝒟 and θ and sb and p' and is' assume i_bound: "i < length ts" and ts_i: "ts ! i = (p, is, θ, sb, 𝒟, 𝒪,ℛ)" and step: "θ⊢ p →⇩s (p', is')" and valid: "valid_pimp ts" (*‹(i::nat) < length (ts::((stmt × nat) × instr list × (nat ⇒ nat option) × (stmt × nat) memref list × 'a × 'b × 'c) list)› ‹(ts::((stmt × nat) × instr list × (nat ⇒ nat option) × (stmt × nat) memref list × 'a × 'b × 'c) list) ! (i::nat) = (p::stmt × nat, is::instr list, θ::nat ⇒ nat option, sb::(stmt × nat) memref list, 𝒟::'a, 𝒪::'b, ℛ::'c)› ‹(θ::nat ⇒ nat option)⊢ (p::stmt × nat) →⇩s (p'::stmt × nat, is'::instr list)› ‹valid_pimp (ts::((stmt × nat) × instr list × (nat ⇒ nat option) × (stmt × nat) memref list × 'a × 'b × 'c) list)›*) show "data_dependency_consistent_instrs (dom θ ∪ load_tmps is) is' ∧ load_tmps is' ∩ ⋃(fst ` store_sops is) = {} ∧ load_tmps is' ∩ ⋃(fst ` write_sops sb) = {}" proof (-) (*goal: ‹data_dependency_consistent_instrs (dom θ ∪ load_tmps is) is' ∧ load_tmps is' ∩ ⋃ (fst ` store_sops is) = {} ∧ load_tmps is' ∩ ⋃ (fst ` write_sops sb) = {}›*) obtain s and t where p: "p=(s,t)" (*goal: ‹(⋀s t. p = (s, t) ⟹ thesis) ⟹ thesis›*) by (cases p) obtain s' and t' where p': "p'=(s',t')" (*goal: ‹(⋀(s'::stmt) t'::nat. (p'::stmt × nat) = (s', t') ⟹ thesis::bool) ⟹ thesis›*) by (cases p') note ts_i = ts_i[simplified p] (*‹ts ! i = ((s, t), is, θ, sb, 𝒟, 𝒪, ℛ)›*) note step = step[simplified p p'] (*‹θ⊢ (s, t) →⇩s ((s', t'), is')›*) from valid (*‹valid_pimp ts›*) interpret separated_tmps ts by (simp add: valid_pimp_def (*‹valid_pimp ?ts ≡ separated_tmps ?ts›*)) from sbh_valid_data_dependency_prog_step[OF step store_sops_le [ OF i_bound ts_i ] write_sops_le [ OF i_bound ts_i ] valid_sops_stmt [ OF i_bound ts_i ]] (*‹data_dependency_consistent_instrs {i. i < t} is' ∧ load_tmps is' ∩ ⋃ (fst ` store_sops is) = {} ∧ load_tmps is' ∩ ⋃ (fst ` write_sops sb) = {}›*) tmps_le[OF i_bound ts_i] (*‹dom θ ∪ load_tmps is = {i. i < t}›*) show "?thesis" (*goal: ‹data_dependency_consistent_instrs (dom θ ∪ load_tmps is) is' ∧ load_tmps is' ∩ ⋃ (fst ` store_sops is) = {} ∧ load_tmps is' ∩ ⋃ (fst ` write_sops sb) = {}›*) by auto qed next (*goals: 1. ‹⋀(i::nat) (ts::((stmt × nat) × instr list × (nat ⇒ nat option) × (stmt × nat) memref list × bool × nat set × (nat ⇒ bool option)) list) (p::stmt × nat) (is::instr list) (θ::nat ⇒ nat option) (sb::(stmt × nat) memref list) (𝒟::bool) (𝒪::nat set) (ℛ::nat ⇒ bool option) (p'::stmt × nat) is'::instr list. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ load_tmps is' ∩ dom θ = {}› 2. ‹⋀(θ::nat ⇒ nat option) (p::stmt × nat) (p'::stmt × nat) is'::instr list. ⟦θ⊢ p →⇩s (p', is'); case p of (s::stmt, t::nat) ⇒ valid_sops_stmt t s⟧ ⟹ ∀sop::nat set × ((nat ⇒ nat option) ⇒ nat)∈store_sops is'. valid_sop sop› 3. ‹⋀(i::nat) (ts::((stmt × nat) × instr list × (nat ⇒ nat option) × (stmt × nat) memref list × bool × nat set × (nat ⇒ bool option)) list) (p::stmt × nat) (is::instr list) (θ::nat ⇒ nat option) (sb::(stmt × nat) memref list) (𝒟::bool) (𝒪::nat set) (ℛ::nat ⇒ bool option) (p'::stmt × nat) is'::instr list. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p', is @ is', θ, sb @ [Prog⇩s⇩b p p' is'], 𝒟, 𝒪, ℛ)])› 4. ‹⋀(i::nat) (ts::((stmt × nat) × instr list × (nat ⇒ nat option) × (stmt × nat) memref list × bool × nat set × (nat ⇒ bool option)) list) (p::stmt × nat) (is::instr list) (θ::nat ⇒ nat option) (sb::(stmt × nat) memref list) (𝒟::bool) (𝒪::nat set) (ℛ::nat ⇒ bool option) (m::nat ⇒ nat) (𝒮::nat ⇒ bool option) (m'::nat ⇒ nat) (sb'::(stmt × nat) memref list) (𝒪'::nat set) (ℛ'::nat ⇒ bool option) 𝒮'::nat ⇒ bool option. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); (m, sb, 𝒪, ℛ, 𝒮) →⇩f (m', sb', 𝒪', ℛ', 𝒮'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p, is, θ, sb', 𝒟, 𝒪', ℛ')])› 5. ‹⋀(i::nat) (ts::((stmt × nat) × instr list × (nat ⇒ nat option) × (stmt × nat) memref list × bool × nat set × (nat ⇒ bool option)) list) (p::stmt × nat) (is::instr list) (θ::nat ⇒ nat option) (sb::(stmt × nat) memref list) (𝒟::bool) (𝒪::nat set) (ℛ::nat ⇒ bool option) (m::nat ⇒ nat) (𝒮::nat ⇒ bool option) (is'::instr list) (θ'::nat ⇒ nat option) (sb'::(stmt × nat) memref list) (m'::nat ⇒ nat) (𝒟'::bool) (𝒪'::nat set) (ℛ'::nat ⇒ bool option) 𝒮'::nat ⇒ bool option. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); (is, θ, sb, m, 𝒟, 𝒪, ℛ, 𝒮) →⇩s⇩b⇩h (is', θ', sb', m', 𝒟', 𝒪', ℛ', 𝒮'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p, is', θ', sb', 𝒟', 𝒪', ℛ')])›*) fix i and ts and p and is and 𝒪 and ℛ and 𝒟 and θ and sb and p' and is' assume i_bound: "i < length ts" and ts_i: "ts ! i = (p, is, θ, sb, 𝒟, 𝒪,ℛ)" and step: "θ⊢ p →⇩s (p', is')" and valid: "valid_pimp ts" (*‹(i::nat) < length (ts::((stmt × nat) × instr list × (nat ⇒ nat option) × (stmt × nat) memref list × 'a × 'b × 'c) list)› ‹(ts::((stmt × nat) × instr list × (nat ⇒ nat option) × (stmt × nat) memref list × 'a × 'b × 'c) list) ! (i::nat) = (p::stmt × nat, is::instr list, θ::nat ⇒ nat option, sb::(stmt × nat) memref list, 𝒟::'a, 𝒪::'b, ℛ::'c)› ‹(θ::nat ⇒ nat option)⊢ (p::stmt × nat) →⇩s (p'::stmt × nat, is'::instr list)› ‹valid_pimp (ts::((stmt × nat) × instr list × (nat ⇒ nat option) × (stmt × nat) memref list × 'a × 'b × 'c) list)›*) show "load_tmps is' ∩ dom θ = {}" proof (-) (*goal: ‹load_tmps is' ∩ dom θ = {}›*) obtain s and t where p: "p=(s,t)" (*goal: ‹(⋀(s::stmt) t::nat. (p::stmt × nat) = (s, t) ⟹ thesis::bool) ⟹ thesis›*) by (cases p) obtain s' and t' where p': "p'=(s',t')" (*goal: ‹(⋀s' t'. p' = (s', t') ⟹ thesis) ⟹ thesis›*) by (cases p') note ts_i = ts_i[simplified p] (*‹ts ! i = ((s, t), is, θ, sb, 𝒟, 𝒪, ℛ)›*) note step = step[simplified p p'] (*‹(θ::nat ⇒ nat option)⊢ (s::stmt, t::nat) →⇩s ((s'::stmt, t'::nat), is'::instr list)›*) from valid (*‹valid_pimp ts›*) interpret separated_tmps ts by (simp add: valid_pimp_def (*‹valid_pimp ?ts ≡ separated_tmps ?ts›*)) from sbh_load_tmps_fresh_prog_step[OF step tmps_le' [ OF i_bound ts_i ]] (*‹load_tmps is' ∩ dom θ = {}›*) show "?thesis" (*goal: ‹load_tmps is' ∩ dom θ = {}›*) . qed next (*goals: 1. ‹⋀θ p p' is'. ⟦θ⊢ p →⇩s (p', is'); case p of (s, t) ⇒ valid_sops_stmt t s⟧ ⟹ ∀sop∈store_sops is'. valid_sop sop› 2. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p', is @ is', θ, sb @ [Prog⇩s⇩b p p' is'], 𝒟, 𝒪, ℛ)])› 3. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ m 𝒮 m' sb' 𝒪' ℛ' 𝒮'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); (m, sb, 𝒪, ℛ, 𝒮) →⇩f (m', sb', 𝒪', ℛ', 𝒮'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p, is, θ, sb', 𝒟, 𝒪', ℛ')])› 4. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ m 𝒮 is' θ' sb' m' 𝒟' 𝒪' ℛ' 𝒮'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); (is, θ, sb, m, 𝒟, 𝒪, ℛ, 𝒮) →⇩s⇩b⇩h (is', θ', sb', m', 𝒟', 𝒪', ℛ', 𝒮'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p, is', θ', sb', 𝒟', 𝒪', ℛ')])›*) fix θ and p and p' and is assume step: "θ⊢ p →⇩s (p', is)" and valid: "(λ(s, t). valid_sops_stmt t s) p" (*‹(θ::nat ⇒ nat option)⊢ (p::stmt × nat) →⇩s (p'::stmt × nat, is::instr list)› ‹case p::stmt × nat of (s::stmt, t::nat) ⇒ valid_sops_stmt t s›*) show "∀sop∈store_sops is. valid_sop sop" proof (-) (*goal: ‹∀sop∈store_sops is. valid_sop sop›*) obtain s and t where p: "p=(s,t)" (*goal: ‹(⋀s t. p = (s, t) ⟹ thesis) ⟹ thesis›*) by (cases p) obtain s' and t' where p': "p'=(s',t')" (*goal: ‹(⋀s' t'. p' = (s', t') ⟹ thesis) ⟹ thesis›*) by (cases p') note step = step[simplified p p'] (*‹(θ::nat ⇒ nat option)⊢ (s::stmt, t::nat) →⇩s ((s'::stmt, t'::nat), is::instr list)›*) from sbh_valid_sops_prog_step[OF step valid [ simplified p , simplified ]] (*‹∀sop::nat set × ((nat ⇒ nat option) ⇒ nat)∈store_sops (is::instr list). valid_sop sop›*) show "?thesis" (*goal: ‹∀sop∈store_sops is. valid_sop sop›*) . qed next (*goals: 1. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ p' is'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); θ⊢ p →⇩s (p', is'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p', is @ is', θ, sb @ [Prog⇩s⇩b p p' is'], 𝒟, 𝒪, ℛ)])› 2. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ m 𝒮 m' sb' 𝒪' ℛ' 𝒮'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); (m, sb, 𝒪, ℛ, 𝒮) →⇩f (m', sb', 𝒪', ℛ', 𝒮'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p, is, θ, sb', 𝒟, 𝒪', ℛ')])› 3. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ m 𝒮 is' θ' sb' m' 𝒟' 𝒪' ℛ' 𝒮'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); (is, θ, sb, m, 𝒟, 𝒪, ℛ, 𝒮) →⇩s⇩b⇩h (is', θ', sb', m', 𝒟', 𝒪', ℛ', 𝒮'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p, is', θ', sb', 𝒟', 𝒪', ℛ')])›*) fix i and ts and p and is and 𝒪 and ℛ and 𝒟 and θ and sb and p' and is' assume i_bound: "i < length ts" and ts_i: "ts ! i = (p, is, θ, sb::stmt_config store_buffer, 𝒟, 𝒪,ℛ)" and step: "θ⊢ p →⇩s (p', is')" and valid: "valid_pimp ts" (*‹(i::nat) < length (ts::((stmt × nat) × instr list × (nat ⇒ nat option) × (stmt × nat) memref list × 'a × 'b × 'c) list)› ‹(ts::((stmt × nat) × instr list × (nat ⇒ nat option) × (stmt × nat) memref list × 'a × 'b × 'c) list) ! (i::nat) = (p::stmt × nat, is::instr list, θ::nat ⇒ nat option, sb::(stmt × nat) memref list, 𝒟::'a, 𝒪::'b, ℛ::'c)› ‹(θ::nat ⇒ nat option)⊢ (p::stmt × nat) →⇩s (p'::stmt × nat, is'::instr list)› ‹valid_pimp (ts::((stmt × nat) × instr list × (nat ⇒ nat option) × (stmt × nat) memref list × 'a × 'b × 'c) list)›*) from prog_step_preserves_valid[OF i_bound ts_i step valid] (*‹valid_pimp (ts[i := (p', is @ is', θ, sb @ [Prog⇩s⇩b p p' is'], 𝒟, 𝒪, ℛ)])›*) show "valid_pimp (ts[i := (p', is @ is', θ, sb @ [Prog⇩s⇩b p p' is'], 𝒟, 𝒪,ℛ)])" . next (*goals: 1. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ m 𝒮 m' sb' 𝒪' ℛ' 𝒮'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); (m, sb, 𝒪, ℛ, 𝒮) →⇩f (m', sb', 𝒪', ℛ', 𝒮'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p, is, θ, sb', 𝒟, 𝒪', ℛ')])› 2. ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ m 𝒮 is' θ' sb' m' 𝒟' 𝒪' ℛ' 𝒮'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); (is, θ, sb, m, 𝒟, 𝒪, ℛ, 𝒮) →⇩s⇩b⇩h (is', θ', sb', m', 𝒟', 𝒪', ℛ', 𝒮'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p, is', θ', sb', 𝒟', 𝒪', ℛ')])›*) fix i and ts and p and is and 𝒪 and ℛ and 𝒟 and θ and sb and 𝒮 and m and m' and sb' and 𝒪' and ℛ' and 𝒮' assume i_bound: "i < length ts" and ts_i: "ts ! i = (p, is, θ, sb::stmt_config store_buffer, 𝒟, 𝒪,ℛ)" and step: "(m, sb, 𝒪, ℛ,𝒮) →⇩f (m', sb',𝒪',ℛ',𝒮')" and valid: "valid_pimp ts" (*‹(i::nat) < length (ts::((stmt × nat) × instr list × (nat ⇒ 'a option) × (stmt × nat) memref list × 'b × nat set × (nat ⇒ bool option)) list)› ‹(ts::((stmt × nat) × instr list × (nat ⇒ 'a option) × (stmt × nat) memref list × 'b × nat set × (nat ⇒ bool option)) list) ! (i::nat) = (p::stmt × nat, is::instr list, θ::nat ⇒ 'a option, sb::(stmt × nat) memref list, 𝒟::'b, 𝒪::nat set, ℛ::nat ⇒ bool option)› ‹(m::nat ⇒ nat, sb::(stmt × nat) memref list, 𝒪::nat set, ℛ::nat ⇒ bool option, 𝒮::nat ⇒ bool option) →⇩f (m'::nat ⇒ nat, sb'::(stmt × nat) memref list, 𝒪'::nat set, ℛ'::nat ⇒ bool option, 𝒮'::nat ⇒ bool option)› ‹valid_pimp (ts::((stmt × nat) × instr list × (nat ⇒ 'a option) × (stmt × nat) memref list × 'b × nat set × (nat ⇒ bool option)) list)›*) thm flush_step_preserves_valid [OF ] from flush_step_preserves_valid[OF i_bound ts_i step valid] (*‹valid_pimp (ts[i := (p, is, θ, sb', 𝒟, 𝒪', ℛ')])›*) show "valid_pimp (ts[i := (p, is, θ, sb', 𝒟, 𝒪',ℛ')])" . next (*goal: ‹⋀i ts p is θ sb 𝒟 𝒪 ℛ m 𝒮 is' θ' sb' m' 𝒟' 𝒪' ℛ' 𝒮'. ⟦i < length ts; ts ! i = (p, is, θ, sb, 𝒟, 𝒪, ℛ); (is, θ, sb, m, 𝒟, 𝒪, ℛ, 𝒮) →⇩s⇩b⇩h (is', θ', sb', m', 𝒟', 𝒪', ℛ', 𝒮'); valid_pimp ts⟧ ⟹ valid_pimp (ts[i := (p, is', θ', sb', 𝒟', 𝒪', ℛ')])›*) fix i and ts and p and is and 𝒪 and ℛ and 𝒟 and θ and sb and 𝒮 and m and is' and 𝒪' and ℛ' and 𝒟' and θ' and sb' and 𝒮' and m' assume i_bound: "i < length ts" and ts_i: "ts ! i = (p, is, θ, sb::stmt_config store_buffer, 𝒟, 𝒪,ℛ)" and step: "(is, θ, sb, m, 𝒟, 𝒪, ℛ, 𝒮) →⇩s⇩b⇩h (is', θ', sb', m',𝒟', 𝒪', ℛ',𝒮')" and valid: "valid_pimp ts" (*‹(i::nat) < length (ts::((stmt × nat) × instr list × (nat ⇒ nat option) × (stmt × nat) memref list × bool × nat set × (nat ⇒ bool option)) list)› ‹(ts::((stmt × nat) × instr list × (nat ⇒ nat option) × (stmt × nat) memref list × bool × nat set × (nat ⇒ bool option)) list) ! (i::nat) = (p::stmt × nat, is::instr list, θ::nat ⇒ nat option, sb::(stmt × nat) memref list, 𝒟::bool, 𝒪::nat set, ℛ::nat ⇒ bool option)› ‹(is::instr list, θ::nat ⇒ nat option, sb::(stmt × nat) memref list, m::nat ⇒ nat, 𝒟::bool, 𝒪::nat set, ℛ::nat ⇒ bool option, 𝒮::nat ⇒ bool option) →⇩s⇩b⇩h (is'::instr list, θ'::nat ⇒ nat option, sb'::(stmt × nat) memref list, m'::nat ⇒ nat, 𝒟'::bool, 𝒪'::nat set, ℛ'::nat ⇒ bool option, 𝒮'::nat ⇒ bool option)› ‹valid_pimp (ts::((stmt × nat) × instr list × (nat ⇒ nat option) × (stmt × nat) memref list × bool × nat set × (nat ⇒ bool option)) list)›*) from sbh_step_preserves_valid[OF i_bound ts_i step valid] (*‹valid_pimp ((ts::((stmt × nat) × instr list × (nat ⇒ nat option) × (stmt × nat) memref list × bool × nat set × (nat ⇒ bool option)) list)[i::nat := (p::stmt × nat, is'::instr list, θ'::nat ⇒ nat option, sb'::(stmt × nat) memref list, 𝒟'::bool, 𝒪'::nat set, ℛ'::nat ⇒ bool option)])›*) show "valid_pimp (ts[i := (p, is', θ', sb', 𝒟', 𝒪',ℛ')])" . qed thm PIMP.concurrent_direct_steps_simulates_store_buffer_history_step thm PIMP.concurrent_direct_steps_simulates_store_buffer_history_steps thm PIMP.concurrent_direct_steps_simulates_store_buffer_step text ‹We can instantiate PIMP with the various memory models.› (* FIXME: note I used () instead of sb , because simplifier rewrites sb::unit to sb. Make this consistent with interpretations/theorems in ReduceStoreBuffer *) interpretation direct: computation direct_memop_step empty_storebuffer_step stmt_step "λp p' is sb. ()". interpretation virtual: computation virtual_memop_step empty_storebuffer_step stmt_step "λp p' is sb. ()". interpretation store_buffer: computation sb_memop_step store_buffer_step stmt_step "λp p' is sb. sb" . interpretation store_buffer_history: computation sbh_memop_step flush_step stmt_step "λp p' is sb. sb @ [Prog⇩s⇩b p p' is]". abbreviation direct_pimp_step:: "(stmt_config,unit,bool,owns,rels,shared) global_config ⇒ (stmt_config,unit,bool,owns,rels,shared) global_config ⇒ bool" ("_ ⇒⇩d⇩p _" [60,60] 100) where "c ⇒⇩d⇩p d ≡ direct.concurrent_step c d" abbreviation direct_pimp_steps:: "(stmt_config,unit,bool,owns,rels,shared) global_config ⇒ (stmt_config,unit,bool,owns,rels,shared) global_config ⇒ bool" ("_ ⇒⇩d⇩p⇧* _" [60,60] 100) where "direct_pimp_steps == direct_pimp_step^**" text ‹Execution examples› lemma Assign_Const_ex: "([((Assign True (Tmp ({},λθ. a)) (Const c) (λθ. A) (λθ. L) (λθ. R) (λθ. W),t),[],θ,(),𝒟,𝒪,ℛ)],m,𝒮) ⇒⇩d⇩p⇧* ([((Skip,t),[],θ,(),True,𝒪 ∪ A - R,Map.empty)],m(a := c),𝒮 ⊕⇘W⇙ R ⊖⇘A⇙ L)" apply (rule converse_rtranclp_into_rtranclp (*‹⟦?r ?a ?b; ?r⇧*⇧* ?b ?c⟧ ⟹ ?r⇧*⇧* ?a ?c›*)) (*goals: 1. ‹([((Assign True (Tmp ({}, λθ. a)) (Const c) (λθ. A) (λθ. L) (λθ. R) (λθ. W), t), [], θ, (), 𝒟, 𝒪, ℛ)], m, 𝒮) ⇒⇩d⇩p ?b› 2. ‹?b ⇒⇩d⇩p⇧* ([((Skip, t), [], θ, (), True, 𝒪 ∪ A - R, λx. None)], m(a := c), 𝒮 ⊕⇘W⇙ R ⊖⇘A⇙ L)› discuss goal 1*) apply (rule direct.Program [where i=0] (*‹⟦0 < length ?ts; ?ts ! 0 = (?p, ?is, ?θ, ?sb, ?𝒟, ?𝒪, ?ℛ); ?θ⊢ ?p →⇩s (?p', ?is')⟧ ⟹ (?ts, ?m, ?𝒮) ⇒⇩d⇩p (?ts[0 := (?p', ?is @ ?is', ?θ, (), ?𝒟, ?𝒪, ?ℛ)], ?m, ?𝒮)›*)) (*goals: 1. ‹0 < length [((Assign True (Tmp ({}, λθ. a)) (Const c) (λθ. A) (λθ. L) (λθ. R) (λθ. W), t), [], θ, (), 𝒟, 𝒪, ℛ)]› 2. ‹[((Assign True (Tmp ({}, λθ. a)) (Const c) (λθ. A) (λθ. L) (λθ. R) (λθ. W), t), [], θ, (), 𝒟, 𝒪, ℛ)] ! 0 = (?p3, ?is3, ?θ3, ?sb3, ?𝒟3, ?𝒪3, ?ℛ3)› 3. ‹?θ3⊢ ?p3 →⇩s (?p'3, ?is'3)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (rule Assign (*‹?D ⊆ dom ?θ ⟹ ?θ⊢ (Assign ?volatile (Tmp (?D, ?a)) ?e ?A ?L ?R ?W, ?t) →⇩s ((Skip, ?t + used_tmps ?e), issue_expr ?t ?e @ [Write ?volatile (?a ?θ) (eval_expr ?t ?e) (?A ?θ) (?L ?θ) (?R ?θ) (?W ?θ)])›*)) (*top goal: ‹θ⊢ (Assign True (Tmp ({}, λθ. a)) (Const c) (λθ. A) (λθ. L) (λθ. R) (λθ. W), t) →⇩s (?p'3, ?is'3)› and 1 goal remains*) apply simp (*proven 3 subgoals*) (*discuss goal 2*) apply (rule converse_rtranclp_into_rtranclp (*‹⟦?r ?a ?b; ?r⇧*⇧* ?b ?c⟧ ⟹ ?r⇧*⇧* ?a ?c›*)) (*goals: 1. ‹([((Assign True (Tmp ({}, λθ::nat ⇒ nat option. a::nat)) (Const (c::nat)) (λθ::nat ⇒ nat option. A::nat set) (λθ::nat ⇒ nat option. L::nat set) (λθ::nat ⇒ nat option. R::nat set) (λθ::nat ⇒ nat option. W::nat set), t::nat), [], θ::nat ⇒ nat option, (), 𝒟::bool, 𝒪::nat set, ℛ::nat ⇒ bool option)][0::nat := ((Skip, t + used_tmps (Const c)), [] @ issue_expr t (Const c) @ [Write True a (eval_expr t (Const c)) A L R W], θ, (), 𝒟, 𝒪, ℛ)], m::nat ⇒ nat, 𝒮::nat ⇒ bool option) ⇒⇩d⇩p (?b20::((stmt × nat) × instr list × (nat ⇒ nat option) × unit × bool × nat set × (nat ⇒ bool option)) list × (nat ⇒ nat) × (nat ⇒ bool option))› 2. ‹(?b20::((stmt × nat) × instr list × (nat ⇒ nat option) × unit × bool × nat set × (nat ⇒ bool option)) list × (nat ⇒ nat) × (nat ⇒ bool option)) ⇒⇩d⇩p⇧* ([((Skip, t::nat), [], θ::nat ⇒ nat option, (), True, (𝒪::nat set) ∪ (A::nat set) - (R::nat set), λx::nat. None)], (m::nat ⇒ nat)(a::nat := c::nat), (𝒮::nat ⇒ bool option) ⊕⇘(W::nat set)⇙ R ⊖⇘A⇙ (L::nat set))› discuss goal 1*) apply (rule direct.Memop [where i=0] (*‹⟦0 < length ?ts; ?ts ! 0 = (?p, ?is, ?θ, ?sb, ?𝒟, ?𝒪, ?ℛ); (?is, ?θ, ?sb, ?m, ?𝒟, ?𝒪, ?ℛ, ?𝒮) → (?is', ?θ', ?sb', ?m', ?𝒟', ?𝒪', ?ℛ', ?𝒮')⟧ ⟹ (?ts, ?m, ?𝒮) ⇒⇩d⇩p (?ts[0 := (?p, ?is', ?θ', ?sb', ?𝒟', ?𝒪', ?ℛ')], ?m', ?𝒮')›*)) (*goals: 1. ‹0 < length ([((Assign True (Tmp ({}, λθ. a)) (Const c) (λθ. A) (λθ. L) (λθ. R) (λθ. W), t), [], θ, (), 𝒟, 𝒪, ℛ)][0 := ((Skip, t + used_tmps (Const c)), [] @ issue_expr t (Const c) @ [Write True a (eval_expr t (Const c)) A L R W], θ, (), 𝒟, 𝒪, ℛ)])› 2. ‹[((Assign True (Tmp ({}, λθ. a)) (Const c) (λθ. A) (λθ. L) (λθ. R) (λθ. W), t), [], θ, (), 𝒟, 𝒪, ℛ)][0 := ((Skip, t + used_tmps (Const c)), [] @ issue_expr t (Const c) @ [Write True a (eval_expr t (Const c)) A L R W], θ, (), 𝒟, 𝒪, ℛ)] ! 0 = (?p23, ?is23, ?θ23, ?sb23, ?𝒟23, ?𝒪23, ?ℛ23)› 3. ‹(?is23, ?θ23, ?sb23, m, ?𝒟23, ?𝒪23, ?ℛ23, 𝒮) → (?is'23, ?θ'23, ?sb'23, ?m'23, ?𝒟'23, ?𝒪'23, ?ℛ'23, ?𝒮'23)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (rule direct_memop_step.WriteVolatile (*‹(Write True (?a::nat) (?D::nat set, ?f::(nat ⇒ nat option) ⇒ nat) (?A::nat set) (?L::nat set) (?R::nat set) (?W::nat set) # (?is::instr list), ?θ::nat ⇒ nat option, ?x::unit, ?m::nat ⇒ nat, ?𝒟::bool, ?𝒪::nat set, ?ℛ::nat ⇒ bool option, ?𝒮::nat ⇒ bool option) → (?is, ?θ, ?x, ?m(?a := ?f ?θ), True, ?𝒪 ∪ ?A - ?R, λx::nat. None, ?𝒮 ⊕⇘?W⇙ ?R ⊖⇘?A⇙ ?L)›*)) (*proven 3 subgoals*) (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma " ([((Assign True (Tmp ({},λθ. a)) (Binop (+) (Mem True x) (Mem True y)) (λθ. A) (λθ. L) (λθ. R) (λθ. W),t),[],θ,(),𝒟,𝒪,ℛ)],m,S) ⇒⇩d⇩p⇧* ([((Skip,t + 2),[],θ(t↦m x, t + 1 ↦m y),(),True,𝒪 ∪ A - R,Map.empty)],m(a := m x + m y),S ⊕⇘W⇙ R ⊖⇘A⇙ L)" apply (rule converse_rtranclp_into_rtranclp (*‹⟦?r ?a ?b; ?r⇧*⇧* ?b ?c⟧ ⟹ ?r⇧*⇧* ?a ?c›*)) (*goals: 1. ‹([((Assign True (Tmp ({}, λθ::nat ⇒ nat option. a::nat)) (Binop (+) (Mem True (x::nat)) (Mem True (y::nat))) (λθ::nat ⇒ nat option. A::nat set) (λθ::nat ⇒ nat option. L::nat set) (λθ::nat ⇒ nat option. R::nat set) (λθ::nat ⇒ nat option. W::nat set), t::nat), [], θ::nat ⇒ nat option, (), 𝒟::bool, 𝒪::nat set, ℛ::nat ⇒ bool option)], m::nat ⇒ nat, S::nat ⇒ bool option) ⇒⇩d⇩p (?b::((stmt × nat) × instr list × (nat ⇒ nat option) × unit × bool × nat set × (nat ⇒ bool option)) list × (nat ⇒ nat) × (nat ⇒ bool option))› 2. ‹(?b::((stmt × nat) × instr list × (nat ⇒ nat option) × unit × bool × nat set × (nat ⇒ bool option)) list × (nat ⇒ nat) × (nat ⇒ bool option)) ⇒⇩d⇩p⇧* ([((Skip, (t::nat) + (2::nat)), [], (θ::nat ⇒ nat option)(t ↦ (m::nat ⇒ nat) (x::nat), t + (1::nat) ↦ m (y::nat)), (), True, (𝒪::nat set) ∪ (A::nat set) - (R::nat set), λx::nat. None)], m(a::nat := m x + m y), (S::nat ⇒ bool option) ⊕⇘(W::nat set)⇙ R ⊖⇘A⇙ (L::nat set))› discuss goal 1*) apply (rule direct.Program [where i=0] (*‹⟦0 < length ?ts; ?ts ! 0 = (?p, ?is, ?θ, ?sb, ?𝒟, ?𝒪, ?ℛ); ?θ⊢ ?p →⇩s (?p', ?is')⟧ ⟹ (?ts, ?m, ?𝒮) ⇒⇩d⇩p (?ts[0 := (?p', ?is @ ?is', ?θ, (), ?𝒟, ?𝒪, ?ℛ)], ?m, ?𝒮)›*)) (*goals: 1. ‹0 < length [((Assign True (Tmp ({}, λθ. a)) (Binop (+) (Mem True x) (Mem True y)) (λθ. A) (λθ. L) (λθ. R) (λθ. W), t), [], θ, (), 𝒟, 𝒪, ℛ)]› 2. ‹[((Assign True (Tmp ({}, λθ. a)) (Binop (+) (Mem True x) (Mem True y)) (λθ. A) (λθ. L) (λθ. R) (λθ. W), t), [], θ, (), 𝒟, 𝒪, ℛ)] ! 0 = (?p3, ?is3, ?θ3, ?sb3, ?𝒟3, ?𝒪3, ?ℛ3)› 3. ‹?θ3⊢ ?p3 →⇩s (?p'3, ?is'3)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (rule Assign (*‹?D ⊆ dom ?θ ⟹ ?θ⊢ (Assign ?volatile (Tmp (?D, ?a)) ?e ?A ?L ?R ?W, ?t) →⇩s ((Skip, ?t + used_tmps ?e), issue_expr ?t ?e @ [Write ?volatile (?a ?θ) (eval_expr ?t ?e) (?A ?θ) (?L ?θ) (?R ?θ) (?W ?θ)])›*)) (*top goal: ‹θ⊢ (Assign True (Tmp ({}, λθ. a)) (Binop (+) (Mem True x) (Mem True y)) (λθ. A) (λθ. L) (λθ. R) (λθ. W), t) →⇩s (?p'3, ?is'3)› and 1 goal remains*) apply simp (*proven 3 subgoals*) (*discuss goal 2*) apply (rule converse_rtranclp_into_rtranclp (*‹⟦?r ?a ?b; ?r⇧*⇧* ?b ?c⟧ ⟹ ?r⇧*⇧* ?a ?c›*)) (*goals: 1. ‹([((Assign True (Tmp ({}, λθ. a)) (Binop (+) (Mem True x) (Mem True y)) (λθ. A) (λθ. L) (λθ. R) (λθ. W), t), [], θ, (), 𝒟, 𝒪, ℛ)][0 := ((Skip, t + used_tmps (Binop (+) (Mem True x) (Mem True y))), [] @ issue_expr t (Binop (+) (Mem True x) (Mem True y)) @ [Write True a (eval_expr t (Binop (+) (Mem True x) (Mem True y))) A L R W], θ, (), 𝒟, 𝒪, ℛ)], m, S) ⇒⇩d⇩p ?b20› 2. ‹?b20 ⇒⇩d⇩p⇧* ([((Skip, t + 2), [], θ(t ↦ m x, t + 1 ↦ m y), (), True, 𝒪 ∪ A - R, λx. None)], m(a := m x + m y), S ⊕⇘W⇙ R ⊖⇘A⇙ L)› discuss goal 1*) apply (rule direct.Memop (*‹⟦?i < length ?ts; ?ts ! ?i = (?p, ?is, ?θ, ?sb, ?𝒟, ?𝒪, ?ℛ); (?is, ?θ, ?sb, ?m, ?𝒟, ?𝒪, ?ℛ, ?𝒮) → (?is', ?θ', ?sb', ?m', ?𝒟', ?𝒪', ?ℛ', ?𝒮')⟧ ⟹ (?ts, ?m, ?𝒮) ⇒⇩d⇩p (?ts[?i := (?p, ?is', ?θ', ?sb', ?𝒟', ?𝒪', ?ℛ')], ?m', ?𝒮')›*)) (*goals: 1. ‹?i23 < length ([((Assign True (Tmp ({}, λθ. a)) (Binop (+) (Mem True x) (Mem True y)) (λθ. A) (λθ. L) (λθ. R) (λθ. W), t), [], θ, (), 𝒟, 𝒪, ℛ)][0 := ((Skip, t + used_tmps (Binop (+) (Mem True x) (Mem True y))), [] @ issue_expr t (Binop (+) (Mem True x) (Mem True y)) @ [Write True a (eval_expr t (Binop (+) (Mem True x) (Mem True y))) A L R W], θ, (), 𝒟, 𝒪, ℛ)])› 2. ‹[((Assign True (Tmp ({}, λθ. a)) (Binop (+) (Mem True x) (Mem True y)) (λθ. A) (λθ. L) (λθ. R) (λθ. W), t), [], θ, (), 𝒟, 𝒪, ℛ)][0 := ((Skip, t + used_tmps (Binop (+) (Mem True x) (Mem True y))), [] @ issue_expr t (Binop (+) (Mem True x) (Mem True y)) @ [Write True a (eval_expr t (Binop (+) (Mem True x) (Mem True y))) A L R W], θ, (), 𝒟, 𝒪, ℛ)] ! ?i23 = (?p23, ?is23, ?θ23, ?sb23, ?𝒟23, ?𝒪23, ?ℛ23)› 3. ‹(?is23, ?θ23, ?sb23, m, ?𝒟23, ?𝒪23, ?ℛ23, S) → (?is'23, ?θ'23, ?sb'23, ?m'23, ?𝒟'23, ?𝒪'23, ?ℛ'23, ?𝒮'23)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (rule direct_memop_step.Read (*‹(Read ?volatile ?a ?t # ?is, ?θ, ?x, ?m, ?𝒟, ?𝒪, ?ℛ, ?𝒮) → (?is, ?θ(?t ↦ ?m ?a), ?x, ?m, ?𝒟, ?𝒪, ?ℛ, ?𝒮)›*)) (*proven 3 subgoals*) (*discuss goal 2*) apply simp (*goal: ‹([((Assign True (Tmp ({}, λθ. a)) (Binop (+) (Mem True x) (Mem True y)) (λθ. A) (λθ. L) (λθ. R) (λθ. W), t), [], θ, (), 𝒟, 𝒪, ℛ)][0 := ((Skip, t + used_tmps (Binop (+) (Mem True x) (Mem True y))), [] @ issue_expr t (Binop (+) (Mem True x) (Mem True y)) @ [Write True a (eval_expr t (Binop (+) (Mem True x) (Mem True y))) A L R W], θ, (), 𝒟, 𝒪, ℛ), 0 := ((Skip, Suc (Suc t)), [Read True y (Suc t), Write True a ({Suc t, t}, λθ. the (θ t) + the (θ (Suc t))) A L R W], θ(t ↦ m x), ?sb23, 𝒟, 𝒪, ℛ)], m, S) ⇒⇩d⇩p⇧* ([((Skip, t + 2), [], θ(t ↦ m x, t + 1 ↦ m y), (), True, 𝒪 ∪ A - R, λx. None)], m(a := m x + m y), S ⊕⇘W⇙ R ⊖⇘A⇙ L)›*) apply (rule converse_rtranclp_into_rtranclp (*‹⟦?r ?a ?b; ?r⇧*⇧* ?b ?c⟧ ⟹ ?r⇧*⇧* ?a ?c›*)) (*goals: 1. ‹([((Skip, Suc (Suc t)), [Read True y (Suc t), Write True a ({Suc t, t}, λθ. the (θ t) + the (θ (Suc t))) A L R W], θ(t ↦ m x), (), 𝒟, 𝒪, ℛ)], m, S) ⇒⇩d⇩p ?b40› 2. ‹?b40 ⇒⇩d⇩p⇧* ([((Skip, Suc (Suc t)), [], θ(t ↦ m x, Suc t ↦ m y), (), True, 𝒪 ∪ A - R, λx. None)], m(a := m x + m y), S ⊕⇘W⇙ R ⊖⇘A⇙ L)› discuss goal 1*) apply (rule direct.Memop (*‹⟦?i < length ?ts; ?ts ! ?i = (?p, ?is, ?θ, ?sb, ?𝒟, ?𝒪, ?ℛ); (?is, ?θ, ?sb, ?m, ?𝒟, ?𝒪, ?ℛ, ?𝒮) → (?is', ?θ', ?sb', ?m', ?𝒟', ?𝒪', ?ℛ', ?𝒮')⟧ ⟹ (?ts, ?m, ?𝒮) ⇒⇩d⇩p (?ts[?i := (?p, ?is', ?θ', ?sb', ?𝒟', ?𝒪', ?ℛ')], ?m', ?𝒮')›*)) (*goals: 1. ‹?i43 < length [((Skip, Suc (Suc t)), [Read True y (Suc t), Write True a ({Suc t, t}, λθ. the (θ t) + the (θ (Suc t))) A L R W], θ(t ↦ m x), (), 𝒟, 𝒪, ℛ)]› 2. ‹[((Skip, Suc (Suc t)), [Read True y (Suc t), Write True a ({Suc t, t}, λθ. the (θ t) + the (θ (Suc t))) A L R W], θ(t ↦ m x), (), 𝒟, 𝒪, ℛ)] ! ?i43 = (?p43, ?is43, ?θ43, ?sb43, ?𝒟43, ?𝒪43, ?ℛ43)› 3. ‹(?is43, ?θ43, ?sb43, m, ?𝒟43, ?𝒪43, ?ℛ43, S) → (?is'43, ?θ'43, ?sb'43, ?m'43, ?𝒟'43, ?𝒪'43, ?ℛ'43, ?𝒮'43)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (rule direct_memop_step.Read (*‹(Read ?volatile ?a ?t # ?is, ?θ, ?x, ?m, ?𝒟, ?𝒪, ?ℛ, ?𝒮) → (?is, ?θ(?t ↦ ?m ?a), ?x, ?m, ?𝒟, ?𝒪, ?ℛ, ?𝒮)›*)) (*proven 3 subgoals*) (*discuss goal 2*) apply simp (*goal: ‹([((Skip, Suc (Suc (t::nat))), [Read True (y::nat) (Suc t), Write True (a::nat) ({Suc t, t}, λθ::nat ⇒ nat option. the (θ t) + the (θ (Suc t))) (A::nat set) (L::nat set) (R::nat set) (W::nat set)], (θ::nat ⇒ nat option)(t ↦ (m::nat ⇒ nat) (x::nat)), (), 𝒟::bool, 𝒪::nat set, ℛ::nat ⇒ bool option)][0::nat := ((Skip, Suc (Suc t)), [Write True a ({Suc t, t}, λθ::nat ⇒ nat option. the (θ t) + the (θ (Suc t))) A L R W], θ(t ↦ m x, Suc t ↦ m y), ?sb43::unit, 𝒟, 𝒪, ℛ)], m, S::nat ⇒ bool option) ⇒⇩d⇩p⇧* ([((Skip, Suc (Suc t)), [], θ(t ↦ m x, Suc t ↦ m y), (), True, 𝒪 ∪ A - R, λx::nat. None)], m(a := m x + m y), S ⊕⇘W⇙ R ⊖⇘A⇙ L)›*) apply (rule converse_rtranclp_into_rtranclp (*‹⟦?r ?a ?b; ?r⇧*⇧* ?b ?c⟧ ⟹ ?r⇧*⇧* ?a ?c›*)) (*goals: 1. ‹([((Skip, Suc (Suc (t::nat))), [Write True (a::nat) ({Suc t, t}, λθ::nat ⇒ nat option. the (θ t) + the (θ (Suc t))) (A::nat set) (L::nat set) (R::nat set) (W::nat set)], (θ::nat ⇒ nat option)(t ↦ (m::nat ⇒ nat) (x::nat), Suc t ↦ m (y::nat)), (), 𝒟::bool, 𝒪::nat set, ℛ::nat ⇒ bool option)], m, S::nat ⇒ bool option) ⇒⇩d⇩p (?b60::((stmt × nat) × instr list × (nat ⇒ nat option) × unit × bool × nat set × (nat ⇒ bool option)) list × (nat ⇒ nat) × (nat ⇒ bool option))› 2. ‹(?b60::((stmt × nat) × instr list × (nat ⇒ nat option) × unit × bool × nat set × (nat ⇒ bool option)) list × (nat ⇒ nat) × (nat ⇒ bool option)) ⇒⇩d⇩p⇧* ([((Skip, Suc (Suc (t::nat))), [], (θ::nat ⇒ nat option)(t ↦ (m::nat ⇒ nat) (x::nat), Suc t ↦ m (y::nat)), (), True, (𝒪::nat set) ∪ (A::nat set) - (R::nat set), λx::nat. None)], m(a::nat := m x + m y), (S::nat ⇒ bool option) ⊕⇘(W::nat set)⇙ R ⊖⇘A⇙ (L::nat set))› discuss goal 1*) apply (rule direct.Memop (*‹⟦?i < length ?ts; ?ts ! ?i = (?p, ?is, ?θ, ?sb, ?𝒟, ?𝒪, ?ℛ); (?is, ?θ, ?sb, ?m, ?𝒟, ?𝒪, ?ℛ, ?𝒮) → (?is', ?θ', ?sb', ?m', ?𝒟', ?𝒪', ?ℛ', ?𝒮')⟧ ⟹ (?ts, ?m, ?𝒮) ⇒⇩d⇩p (?ts[?i := (?p, ?is', ?θ', ?sb', ?𝒟', ?𝒪', ?ℛ')], ?m', ?𝒮')›*)) (*goals: 1. ‹?i63 < length [((Skip, Suc (Suc t)), [Write True a ({Suc t, t}, λθ. the (θ t) + the (θ (Suc t))) A L R W], θ(t ↦ m x, Suc t ↦ m y), (), 𝒟, 𝒪, ℛ)]› 2. ‹[((Skip, Suc (Suc t)), [Write True a ({Suc t, t}, λθ. the (θ t) + the (θ (Suc t))) A L R W], θ(t ↦ m x, Suc t ↦ m y), (), 𝒟, 𝒪, ℛ)] ! ?i63 = (?p63, ?is63, ?θ63, ?sb63, ?𝒟63, ?𝒪63, ?ℛ63)› 3. ‹(?is63, ?θ63, ?sb63, m, ?𝒟63, ?𝒪63, ?ℛ63, S) → (?is'63, ?θ'63, ?sb'63, ?m'63, ?𝒟'63, ?𝒪'63, ?ℛ'63, ?𝒮'63)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (rule direct_memop_step.WriteVolatile (*‹(Write True ?a (?D, ?f) ?A ?L ?R ?W # ?is, ?θ, ?x, ?m, ?𝒟, ?𝒪, ?ℛ, ?𝒮) → (?is, ?θ, ?x, ?m(?a := ?f ?θ), True, ?𝒪 ∪ ?A - ?R, λx. None, ?𝒮 ⊕⇘?W⇙ ?R ⊖⇘?A⇙ ?L)›*)) (*proven 3 subgoals*) (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma assumes isTrue: "isTrue c" shows "([((Cond (Const c) (Assign True (Tmp ({},λθ. a)) (Const c) (λθ. A) (λθ. L) (λθ. R) (λθ. W)) Skip,t) ,[],θ,(),𝒟,𝒪,ℛ)],m,𝒮) ⇒⇩d⇩p⇧* ([((Skip,t),[],θ,(),True,𝒪 ∪ A - R,Map.empty)],m(a := c),𝒮 ⊕⇘W⇙ R ⊖⇘A⇙ L)" apply (rule converse_rtranclp_into_rtranclp (*‹⟦?r ?a ?b; ?r⇧*⇧* ?b ?c⟧ ⟹ ?r⇧*⇧* ?a ?c›*)) (*goals: 1. ‹([((Cond (Const c) (Assign True (Tmp ({}, λθ. a)) (Const c) (λθ. A) (λθ. L) (λθ. R) (λθ. W)) Skip, t), [], θ, (), 𝒟, 𝒪, ℛ)], m, 𝒮) ⇒⇩d⇩p ?b› 2. ‹?b ⇒⇩d⇩p⇧* ([((Skip, t), [], θ, (), True, 𝒪 ∪ A - R, λx. None)], m(a := c), 𝒮 ⊕⇘W⇙ R ⊖⇘A⇙ L)› discuss goal 1*) apply (rule direct.Program [where i=0] (*‹⟦0 < length ?ts; ?ts ! 0 = (?p, ?is, ?θ, ?sb, ?𝒟, ?𝒪, ?ℛ); ?θ⊢ ?p →⇩s (?p', ?is')⟧ ⟹ (?ts, ?m, ?𝒮) ⇒⇩d⇩p (?ts[0 := (?p', ?is @ ?is', ?θ, (), ?𝒟, ?𝒪, ?ℛ)], ?m, ?𝒮)›*)) (*goals: 1. ‹0 < length [((Cond (Const c) (Assign True (Tmp ({}, λθ. a)) (Const c) (λθ. A) (λθ. L) (λθ. R) (λθ. W)) Skip, t), [], θ, (), 𝒟, 𝒪, ℛ)]› 2. ‹[((Cond (Const c) (Assign True (Tmp ({}, λθ. a)) (Const c) (λθ. A) (λθ. L) (λθ. R) (λθ. W)) Skip, t), [], θ, (), 𝒟, 𝒪, ℛ)] ! 0 = (?p3, ?is3, ?θ3, ?sb3, ?𝒟3, ?𝒪3, ?ℛ3)› 3. ‹?θ3⊢ ?p3 →⇩s (?p'3, ?is'3)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (rule Cond (*‹∀sop. ?e ≠ Tmp sop ⟹ ?θ⊢ (Cond ?e ?s₁ ?s₂, ?t) →⇩s ((Cond (Tmp (eval_expr ?t ?e)) ?s₁ ?s₂, ?t + used_tmps ?e), issue_expr ?t ?e)›*)) (*top goal: ‹θ⊢ (Cond (Const c) (Assign True (Tmp ({}, λθ. a)) (Const c) (λθ. A) (λθ. L) (λθ. R) (λθ. W)) Skip, t) →⇩s (?p'3, ?is'3)› and 1 goal remains*) apply simp (*proven 3 subgoals*) (*discuss goal 2*) apply simp (*goal: ‹([((Cond (Const c) (Assign True (Tmp ({}, λθ. a)) (Const c) (λθ. A) (λθ. L) (λθ. R) (λθ. W)) Skip, t), [], θ, (), 𝒟, 𝒪, ℛ)][0 := ((Cond (Tmp (eval_expr t (Const c))) (Assign True (Tmp ({}, λθ. a)) (Const c) (λθ. A) (λθ. L) (λθ. R) (λθ. W)) Skip, t + used_tmps (Const c)), [] @ issue_expr t (Const c), θ, (), 𝒟, 𝒪, ℛ)], m, 𝒮) ⇒⇩d⇩p⇧* ([((Skip, t), [], θ, (), True, 𝒪 ∪ A - R, λx. None)], m(a := c), 𝒮 ⊕⇘W⇙ R ⊖⇘A⇙ L)›*) apply (rule converse_rtranclp_into_rtranclp (*‹⟦?r ?a ?b; ?r⇧*⇧* ?b ?c⟧ ⟹ ?r⇧*⇧* ?a ?c›*)) (*goals: 1. ‹([((Cond (Tmp ({}, λθ::nat ⇒ nat option. c::nat)) (Assign True (Tmp ({}, λθ::nat ⇒ nat option. a::nat)) (Const c) (λθ::nat ⇒ nat option. A::nat set) (λθ::nat ⇒ nat option. L::nat set) (λθ::nat ⇒ nat option. R::nat set) (λθ::nat ⇒ nat option. W::nat set)) Skip, t::nat), [], θ::nat ⇒ nat option, (), 𝒟::bool, 𝒪::nat set, ℛ::nat ⇒ bool option)], m::nat ⇒ nat, 𝒮::nat ⇒ bool option) ⇒⇩d⇩p (?b20::((stmt × nat) × instr list × (nat ⇒ nat option) × unit × bool × nat set × (nat ⇒ bool option)) list × (nat ⇒ nat) × (nat ⇒ bool option))› 2. ‹(?b20::((stmt × nat) × instr list × (nat ⇒ nat option) × unit × bool × nat set × (nat ⇒ bool option)) list × (nat ⇒ nat) × (nat ⇒ bool option)) ⇒⇩d⇩p⇧* ([((Skip, t::nat), [], θ::nat ⇒ nat option, (), True, (𝒪::nat set) ∪ (A::nat set) - (R::nat set), λx::nat. None)], (m::nat ⇒ nat)(a::nat := c::nat), (𝒮::nat ⇒ bool option) ⊕⇘(W::nat set)⇙ R ⊖⇘A⇙ (L::nat set))› discuss goal 1*) apply (rule direct.Program [where i=0] (*‹⟦0 < length ?ts; ?ts ! 0 = (?p, ?is, ?θ, ?sb, ?𝒟, ?𝒪, ?ℛ); ?θ⊢ ?p →⇩s (?p', ?is')⟧ ⟹ (?ts, ?m, ?𝒮) ⇒⇩d⇩p (?ts[0 := (?p', ?is @ ?is', ?θ, (), ?𝒟, ?𝒪, ?ℛ)], ?m, ?𝒮)›*)) (*goals: 1. ‹0 < length [((Cond (Tmp ({}, λθ. c)) (Assign True (Tmp ({}, λθ. a)) (Const c) (λθ. A) (λθ. L) (λθ. R) (λθ. W)) Skip, t), [], θ, (), 𝒟, 𝒪, ℛ)]› 2. ‹[((Cond (Tmp ({}, λθ. c)) (Assign True (Tmp ({}, λθ. a)) (Const c) (λθ. A) (λθ. L) (λθ. R) (λθ. W)) Skip, t), [], θ, (), 𝒟, 𝒪, ℛ)] ! 0 = (?p23, ?is23, ?θ23, ?sb23, ?𝒟23, ?𝒪23, ?ℛ23)› 3. ‹?θ23⊢ ?p23 →⇩s (?p'23, ?is'23)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (rule CondTrue (*‹⟦?D ⊆ dom ?θ; isTrue (?e ?θ)⟧ ⟹ ?θ⊢ (Cond (Tmp (?D, ?e)) ?s₁ ?s₂, ?t) →⇩s ((?s₁, ?t), [])›*)) (*goals: 1. ‹{} ⊆ dom (θ::nat ⇒ nat option)› 2. ‹isTrue (c::nat)› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: isTrue (*‹isTrue c›*)) (*proven 2 subgoals*) (*proven 3 subgoals*) (*discuss goal 2*) apply simp (*goal: ‹([((Cond (Tmp ({}, λθ. c)) (Assign True (Tmp ({}, λθ. a)) (Const c) (λθ. A) (λθ. L) (λθ. R) (λθ. W)) Skip, t), [], θ, (), 𝒟, 𝒪, ℛ)][0 := ((Assign True (Tmp ({}, λθ. a)) (Const c) (λθ. A) (λθ. L) (λθ. R) (λθ. W), t), [] @ [], θ, (), 𝒟, 𝒪, ℛ)], m, 𝒮) ⇒⇩d⇩p⇧* ([((Skip, t), [], θ, (), True, 𝒪 ∪ A - R, λx. None)], m(a := c), 𝒮 ⊕⇘W⇙ R ⊖⇘A⇙ L)›*) apply (rule Assign_Const_ex (*‹([((Assign True (Tmp ({}, λθ. ?a)) (Const ?c) (λθ. ?A) (λθ. ?L) (λθ. ?R) (λθ. ?W), ?t), [], ?θ, (), ?𝒟, ?𝒪, ?ℛ)], ?m, ?𝒮) ⇒⇩d⇩p⇧* ([((Skip, ?t), [], ?θ, (), True, ?𝒪 ∪ ?A - ?R, λx. None)], ?m(?a := ?c), ?𝒮 ⊕⇘?W⇙ ?R ⊖⇘?A⇙ ?L)›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) . end
{ "path": "afp-2025-02-12/thys/Store_Buffer_Reduction/PIMP.thy", "repo": "afp-2025-02-12", "sha": "269b572c9bed25ecdc3e4f477507c963c2b7e2719549b28228bf75fc8f10eb88" }
theory Partially_Filled_Array imports "Refine_Imperative_HOL.IICF_Array_List" Array_SBlit begin section "Partially Filled Arrays" text ‹An array that is only partially filled. The number of actual elements contained is kept in a second element. This represents a weakened version of the array\_list from IICF.› type_synonym 'a pfarray = "'a array_list" subsection "Operations on Partly Filled Arrays" definition is_pfa where "is_pfa c l ≡ λ(a,n). ∃⇩A l'. a ↦⇩a l' * ↑(c = length l' ∧ n ≤ c ∧ l = (take n l'))" abbreviation "len :: 'a pfarray ⇒ nat ≡ snd" abbreviation "arr :: 'a pfarray ⇒ 'a array ≡ fst" lemma is_pfa_prec[safe_constraint_rules]: "precise (is_pfa c)" unfolding is_pfa_def[abs_def] (*goal: ‹precise (λl (a, n). ∃⇩Al'. a ↦⇩a l' * ↑ (c = length l' ∧ n ≤ c ∧ l = take n l'))›*) apply (rule preciseI (*‹(⋀a a' h p F F'. h ⊨ ?R a p * F ∧⇩A ?R a' p * F' ⟹ a = a') ⟹ precise ?R›*)) (*goal: ‹precise (λ(l::'a list) (a::'a array, n::nat). ∃⇩Al'::'a list. a ↦⇩a l' * ↑ ((c::nat) = length l' ∧ n ≤ c ∧ l = take n l'))›*) apply (simp split: prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*)) (*goal: ‹⋀a a' h p F F'. h ⊨ (case p of (aa, n) ⇒ ∃⇩Al'. aa ↦⇩a l' * ↑ (c = length l' ∧ n ≤ c ∧ a = take n l')) * F ∧⇩A (case p of (a, n) ⇒ ∃⇩Al'. a ↦⇩a l' * ↑ (c = length l' ∧ n ≤ c ∧ a' = take n l')) * F' ⟹ a = a'›*) using preciseD (*‹⟦precise ?R; ?h ⊨ ?R ?a ?p * ?F ∧⇩A ?R ?a' ?p * ?F'⟧ ⟹ ?a = ?a'›*) snga_prec (*‹precise (λx p. p ↦⇩a x)›*) by fastforce definition pfa_init where "pfa_init cap v n ≡ do { a ← Array.new cap v; return (a,n) }" lemma pfa_init_rule[sep_heap_rules]: "n ≤ N ⟹ < emp > pfa_init N x n <is_pfa N (replicate n x)>" by (sep_auto simp: pfa_init_def is_pfa_def) definition pfa_empty where "pfa_empty cap ≡ pfa_init cap default 0" lemma pfa_empty_rule[sep_heap_rules]: "< emp > pfa_empty N <is_pfa N []>" by (sep_auto simp: pfa_empty_def is_pfa_def) definition "pfa_length ≡ arl_length" lemma pfa_length_rule[sep_heap_rules]: " <is_pfa c l a> pfa_length a <λr. is_pfa c l a * ↑(r=length l)>" by (sep_auto simp: pfa_length_def arl_length_def is_pfa_def) definition "pfa_capacity ≡ λ(a,n). Array.len a " lemma pfa_capacity_rule[sep_heap_rules]: " <is_pfa c l a> pfa_capacity a <λr. is_pfa c l a * ↑(c=r)>" by (sep_auto simp: pfa_capacity_def arl_length_def is_pfa_def) definition "pfa_is_empty ≡ arl_is_empty" lemma pfa_is_empty_rule[sep_heap_rules]: " <is_pfa c l a> pfa_is_empty a <λr. is_pfa c l a * ↑(r⟷(l=[]))>" by (sep_auto simp: pfa_is_empty_def arl_is_empty_def is_pfa_def) definition "pfa_append ≡ λ(a,n) x. do { Array.upd n x a; return (a,n+1) }" lemma pfa_append_rule[sep_heap_rules]: "len a < c ⟹ <is_pfa c l a> pfa_append a x <λ(a',n'). is_pfa c (l@[x]) (a',n') * ↑(a' = arr a ∧ n' = (len a)+1) >" by (sep_auto simp: pfa_append_def arl_append_def is_pfa_def take_update_last neq_Nil_conv split: prod.splits nat.split) definition "pfa_last ≡ arl_last" lemma pfa_last_rule[sep_heap_rules]: " l≠[] ⟹ <is_pfa c l a> pfa_last a <λr. is_pfa c l a * ↑(r=last l)>" by (sep_auto simp: pfa_last_def arl_last_def is_pfa_def last_take_nth_conv) definition pfa_butlast :: "'a::heap pfarray ⇒ 'a pfarray Heap" where "pfa_butlast ≡ λ(a,n). return (a,n-1) " lemma pfa_butlast_rule[sep_heap_rules]: " <is_pfa c l a> pfa_butlast a <λ(a',n'). is_pfa c (butlast l) (a',n') * ↑(a' = arr a)>" by (sep_auto split: prod.splits simp: pfa_butlast_def is_pfa_def butlast_take) definition "pfa_get ≡ arl_get" lemma pfa_get_rule[sep_heap_rules]: " i < length l ⟹ < is_pfa c l a> pfa_get a i <λr. is_pfa c l a * ↑((l!i) = r)>" by (sep_auto simp: is_pfa_def pfa_get_def arl_get_def split: prod.split) definition "pfa_set ≡ arl_set" lemma pfa_set_rule[sep_heap_rules]: " i<length l ⟹ <is_pfa c l a> pfa_set a i x <λa'. is_pfa c (l[i:=x]) a' * ↑(a' = a)>" by (sep_auto simp: pfa_set_def arl_set_def is_pfa_def split: prod.split) definition pfa_shrink :: "nat ⇒ 'a::heap pfarray ⇒ 'a pfarray Heap" where "pfa_shrink k ≡ λ(a,n). return (a,k) " lemma pfa_shrink_rule[sep_heap_rules]: " k ≤ length xs ⟹ < is_pfa c xs a > pfa_shrink k a <λ(a',n'). is_pfa c (take k xs) (a',n') * ↑(n' = k ∧ a'=arr a) >" by (sep_auto simp: pfa_shrink_def is_pfa_def min.absorb1 split: prod.splits nat.split) definition pfa_shrink_cap :: "nat ⇒ 'a::heap pfarray ⇒ 'a pfarray Heap" where "pfa_shrink_cap k ≡ λ(a,n). do { a' ← array_shrink a k; return (a',min k n) } " lemma pfa_shrink_cap_rule_preserve[sep_heap_rules]: " ⟦len a ≤ k; k ≤ c⟧ ⟹ < is_pfa c l a > pfa_shrink_cap k a <λa'. is_pfa k l a' >⇩t" by (sep_auto simp: pfa_shrink_cap_def is_pfa_def min.absorb1 min.absorb2 split: prod.splits nat.split) lemma pfa_shrink_cap_rule: " ⟦k ≤ c⟧ ⟹ < is_pfa c l a > pfa_shrink_cap k a <λa'. is_pfa k (take k l) a' >⇩t" by (sep_auto simp: pfa_shrink_cap_def is_pfa_def min.absorb1 min.absorb2 split: prod.splits nat.split dest: mod_starD) definition "array_ensure a s x ≡ do { l←Array.len a; if l≥s then return a else do { a'←Array.new s x; blit a 0 a' 0 l; return a' } }" lemma array_ensure_rule[sep_heap_rules]: shows " < a↦⇩ala > array_ensure a s x <λa'. a'↦⇩a (la @ replicate (s-length la) x)>⇩t" unfolding array_ensure_def (*goal: ‹<(a::'a array) ↦⇩a (la::'a list)> Array.len a ⤜ (λl::nat. if (s::nat) ≤ l then return a else Array.new s (x::'a) ⤜ (λa'::'a array. blit a (0::nat) a' (0::nat) l ⤜ (λ_::unit. return a'))) <λr::'a array. r ↦⇩a (la @ replicate (s - length la) x)>⇩t›*) by sep_auto (* Ensure a certain capacity *) definition pfa_ensure :: "'a::{heap,default} pfarray ⇒ nat ⇒ 'a pfarray Heap" where "pfa_ensure ≡ λ(a,n) k. do { a' ← array_ensure a k default; return (a',n) } " lemma pfa_ensure_rule[sep_heap_rules]: " < is_pfa c l a > pfa_ensure a k <λ(a',n'). is_pfa (max c k) l (a',n') * ↑(n' = len a ∧ c ≥ len a)>⇩t" by (sep_auto simp: pfa_ensure_def is_pfa_def split!: prod.splits) definition "pfa_copy ≡ arl_copy" lemma pfa_copy_rule[sep_heap_rules]: "< is_pfa c l a > pfa_copy a <λr. is_pfa c l a * is_pfa c l r>⇩t" by (sep_auto simp: pfa_copy_def arl_copy_def is_pfa_def) definition pfa_blit :: "'a::heap pfarray ⇒ nat ⇒ 'a::heap pfarray ⇒ nat ⇒ nat ⇒ unit Heap" where "pfa_blit ≡ λ(src,sn) si (dst,dn) di l. blit src si dst di l" lemma min_nat: "min a (a+b) = (a::nat)" by auto lemma pfa_blit_rule[sep_heap_rules]: assumes LEN: "si+l ≤ sn" "di ≤ dn" "di+l ≤ dc" shows "< is_pfa sc src (srci,sn) * is_pfa dc dst (dsti,dn) > pfa_blit (srci,sn) si (dsti,dn) di l <λ_. is_pfa sc src (srci,sn) * is_pfa dc (take di dst @ take l (drop si src) @ drop (di+l) dst) (dsti,max (di+l) dn) >" using LEN (*‹si + l ≤ sn› ‹(di::nat) ≤ (dn::nat)› ‹(di::nat) + (l::nat) ≤ (dc::nat)›*) apply (sep_auto simp add: min_nat is_pfa_def pfa_blit_def min.commute min.absorb1 heap: blit_rule) (*goals: 1. ‹⋀l' l'a a b. ⟦si + l ≤ sn; di ≤ dn; di + l ≤ length l'; sc = length l'a; sn ≤ length l'a; src = take sn l'a; dc = length l'; dn ≤ length l'; dst = take dn l'; (a, b) ⊨ srci ↦⇩a l'a * dsti ↦⇩a (take di l' @ take l (drop si l'a) @ drop (di + l) l')⟧ ⟹ take l (drop si (take sn l'a)) = take l (drop si l'a)› 2. ‹⋀l' l'a a b. ⟦si + l ≤ sn; di ≤ dn; di + l ≤ length l'; sc = length l'a; sn ≤ length l'a; src = take sn l'a; dc = length l'; dn ≤ length l'; dst = take dn l'; (a, b) ⊨ srci ↦⇩a l'a * dsti ↦⇩a (take di l' @ take l (drop si l'a) @ drop (di + l) l')⟧ ⟹ drop (di + l) (take dn l') = take (max (di + l) dn - (di + l)) (drop (di + l) l')› discuss goal 1*) apply (simp add: min.absorb1 (*‹?a ≤ ?b ⟹ min ?a ?b = ?a›*) take_drop (*‹take ?n (drop ?m ?xs) = drop ?m (take (?n + ?m) ?xs)›*)) (*discuss goal 2*) apply (simp add: drop_take (*‹drop ?n (take ?m ?xs) = take (?m - ?n) (drop ?n ?xs)›*) max_def (*‹max ?a ?b = (if ?a ≤ ?b then ?b else ?a)›*)) (*proven 2 subgoals*) . definition pfa_drop :: "('a::heap) pfarray ⇒ nat ⇒ 'a pfarray ⇒ 'a pfarray Heap" where "pfa_drop ≡ λ(src,sn) si (dst,dn). do { blit src si dst 0 (sn-si); return (dst,(sn-si)) } " lemma pfa_drop_rule_pair[sep_heap_rules]: assumes LEN: "k ≤ sn" "(sn-k) ≤ dc" shows "< is_pfa sc src (srci,sn) * is_pfa dc dst (dsti,dn) > pfa_drop (srci,sn) k (dsti,dn) <λ(dsti',dn'). is_pfa sc src (srci,sn) * is_pfa dc (drop k src) (dsti',dn') * ↑(dsti' = dsti) >" using LEN (*‹(k::nat) ≤ (sn::nat)› ‹sn - k ≤ dc›*) by (sep_auto simp add: drop_take is_pfa_def pfa_drop_def dest!: mod_starD heap: pfa_blit_rule) lemma pfa_drop_rule[sep_heap_rules]: assumes LEN: "k ≤ len srci" "(len srci-k) ≤ dc" shows "< is_pfa sc src srci * is_pfa dc dst dsti > pfa_drop srci k dsti <λ(dsti',dn'). is_pfa sc src srci * is_pfa dc (drop k src) (dsti',dn') * ↑(dsti' = arr dsti) >" using LEN (*‹k ≤ len srci› ‹len (srci::'a::heap array × nat) - (k::nat) ≤ (dc::nat)›*) by (sep_auto simp add: drop_take is_pfa_def pfa_drop_def dest!: mod_starD heap: pfa_blit_rule split!: prod.splits) definition "pfa_append_grow ≡ λ(a,n) x. do { l ← pfa_capacity (a,n); a' ← if l = n then array_grow a (l+1) x else Array.upd n x a; return (a',n+1) }" lemma pfa_append_grow_full_rule[sep_heap_rules]: "n = c ⟹ <is_pfa c l (a,n)> array_grow a (c+1) x <λa'. is_pfa (c+1) (l@[x]) (a',n+1)>⇩t" apply (sep_auto simp add: is_pfa_def heap del: array_grow_rule) (*goal: ‹n = c ⟹ <is_pfa c l (a, n)> array_grow a (c + 1) x <λr. is_pfa (c + 1) (l @ [x]) (r, n + 1)>⇩t›*) apply (vcg heap del: array_grow_rule heap add: array_grow_rule[of l "(Suc (length l))" a x]) (*goals: 1. ‹⟦n = length l; c = length l⟧ ⟹ length l ≤ Suc (length l)› 2. ‹⋀xa. ⟦n = length l; c = length l⟧ ⟹ xa ↦⇩a (l @ replicate (Suc (length l) - length l) x) * true ⟹⇩A ∃⇩Al'. xa ↦⇩a l' * true * ↑ (Suc (length l) = length l' ∧ l @ [x] = take (Suc (length l)) l')› discuss goal 1*) apply simp (*discuss goal 2*) apply (rule ent_ex_postI[where ?x="l@[x]"] (*‹(?P::assn) ⟹⇩A (?Q::'a list ⇒ assn) ((l::'a list) @ [x::'a]) ⟹ ?P ⟹⇩A ∃⇩Ax::'a list. ?Q x›*)) (*goal: ‹⋀xa. ⟦n = length l; c = length l⟧ ⟹ xa ↦⇩a (l @ replicate (Suc (length l) - length l) x) * true ⟹⇩A ∃⇩Al'. xa ↦⇩a l' * true * ↑ (Suc (length l) = length l' ∧ l @ [x] = take (Suc (length l)) l')›*) apply sep_auto (*proven 2 subgoals*) . lemma pfa_append_grow_less_rule: "n < c ⟹ <is_pfa c l (a,n)> Array.upd n x a <λa'. is_pfa c (l@[x]) (a',n+1)>⇩t" by (sep_auto simp add: is_pfa_def take_update_last) lemma pfa_append_grow_rule[sep_heap_rules]: " <is_pfa c l (a,n)> pfa_append_grow (a,n) x <λ(a',n'). is_pfa (if c = n then c+1 else c) (l@[x]) (a',n') * ↑(n'=n+1 ∧ c ≥ n)>⇩t" apply (subst pfa_append_grow_def (*‹pfa_append_grow ≡ λ(a, n) x. pfa_capacity (a, n) ⤜ (λl. (if l = n then array_grow a (l + 1) x else Array.upd n x a) ⤜ (λa'. return (a', n + 1)))›*)) (*goal: ‹<is_pfa c l (a, n)> pfa_append_grow (a, n) x <λr. case r of (a', n') ⇒ is_pfa (if c = n then c + 1 else c) (l @ [x]) (a', n') * ↑ (n' = n + 1 ∧ n ≤ c)>⇩t›*) apply (rule hoare_triple_preI (*‹(⋀h::heap × nat set. h ⊨ (?P::assn) ⟹ <?P> ?c::?'a Heap <?Q::?'a ⇒ assn>) ⟹ <?P> ?c <?Q>›*)) (*goal: ‹<is_pfa c l (a, n)> (case (a, n) of (a, n) ⇒ λx. pfa_capacity (a, n) ⤜ (λl. (if l = n then array_grow a (l + 1) x else Array.upd n x a) ⤜ (λa'. return (a', n + 1)))) x <λr. case r of (a', n') ⇒ is_pfa (if c = n then c + 1 else c) (l @ [x]) (a', n') * ↑ (n' = n + 1 ∧ n ≤ c)>⇩t›*) apply (sep_auto heap add: pfa_append_grow_full_rule pfa_append_grow_less_rule) (*goals: 1. ‹⋀aa b. ⟦(aa, b) ⊨ is_pfa c l (a, n); c ≠ n⟧ ⟹ n < c› 2. ‹⋀aa b xa xaa. ⟦(aa, b) ⊨ is_pfa xa l (a, n); xa ≠ n; c = xa⟧ ⟹ <is_pfa xa (l @ [x]) (xaa, n + 1) * true> return (xaa, Suc n) <λr. case r of (a', n') ⇒ is_pfa xa (l @ [x]) (a', n') * ↑ (n' = Suc n ∧ n ≤ xa)>⇩t› discuss goal 1*) apply (sep_auto simp add: is_pfa_def) (*discuss goal 2*) apply (sep_auto simp add: is_pfa_def) (*proven 2 subgoals*) . (* This definition has only one access to the array length *) definition "pfa_append_grow' ≡ λ(a,n) x. do { a' ← pfa_ensure (a,n) (n+1); a'' ← pfa_append a' x; return a'' }" lemma pfa_append_grow'_rule[sep_heap_rules]: " <is_pfa c l (a,n)> pfa_append_grow' (a,n) x <λ(a',n'). is_pfa (max (n+1) c) (l@[x]) (a',n') * ↑(n'=n+1 ∧ c ≥ n)>⇩t" unfolding pfa_append_grow'_def (*goal: ‹<is_pfa c l (a, n)> (case (a, n) of (a, n) ⇒ λx. pfa_ensure (a, n) (n + 1) ⤜ (λa'. pfa_append a' x ⤜ return)) x <λr. case r of (a', n') ⇒ is_pfa (max (n + 1) c) (l @ [x]) (a', n') * ↑ (n' = n + 1 ∧ n ≤ c)>⇩t›*) by (sep_auto simp add: max_def) definition "pfa_insert ≡ λ(a,n) i x. do { a' ← array_shr a i 1; a'' ← Array.upd i x a; return (a'',n+1) }" lemma list_update_last: "length ls = Suc i ⟹ ls[i:=x] = (take i ls)@[x]" by (metis append_eq_conv_conj (*‹(?xs @ ?ys = ?zs) = (?xs = take (length ?xs) ?zs ∧ ?ys = drop (length ?xs) ?zs)›*) length_Suc_rev_conv (*‹(length ?xs = Suc ?n) = (∃ys y. ?xs = ys @ [y] ∧ length ys = ?n)›*) list_update_length (*‹(?xs @ ?x # ?ys)[length ?xs := ?y] = ?xs @ ?y # ?ys›*)) lemma pfa_insert_rule[sep_heap_rules]: "⟦i ≤ n; n < c⟧ ⟹ <is_pfa c l (a,n)> pfa_insert (a,n) i x <λ(a',n'). is_pfa c (take i l@x#drop i l) (a',n') * ↑(n' = n+1 ∧ a=a')>" unfolding pfa_insert_def is_pfa_def (*goal: ‹⟦i ≤ n; n < c⟧ ⟹ <case (a, n) of (a, n) ⇒ ∃⇩Al'. a ↦⇩a l' * ↑ (c = length l' ∧ n ≤ c ∧ l = take n l')> (case (a, n) of (a, n) ⇒ λi x. array_shr a i 1 ⤜ (λa'. Array.upd i x a ⤜ (λa''. return (a'', n + 1)))) i x <λ(a', n'). (case (a', n') of (a, n) ⇒ ∃⇩Al'. a ↦⇩a l' * ↑ (c = length l' ∧ n ≤ c ∧ take i l @ x # drop i l = take n l')) * ↑ (n' = n + 1 ∧ a = a')>›*) by (sep_auto simp add: list_update_append1 list_update_last Suc_diff_le drop_take min_def) definition pfa_insert_grow :: "'a::{heap,default} pfarray ⇒ nat ⇒ 'a ⇒ 'a pfarray Heap" where "pfa_insert_grow ≡ λ(a,n) i x. do { a' ← pfa_ensure (a,n) (n+1); a'' ← pfa_insert a' i x; return a'' }" lemma pfa_insert_grow_rule[sep_heap_rules]: "i ≤ n ⟹ <is_pfa c l (a,n)> pfa_insert_grow (a,n) i x <λ(a',n'). is_pfa (max c (n+1)) (take i l@x#drop i l) (a',n') * ↑(n'=n+1 ∧ c ≥ n)>⇩t" unfolding pfa_insert_grow_def (*goal: ‹i ≤ n ⟹ <is_pfa c l (a, n)> (case (a, n) of (a, n) ⇒ λi x. pfa_ensure (a, n) (n + 1) ⤜ (λa'. pfa_insert a' i x ⤜ return)) i x <λr. case r of (a', n') ⇒ is_pfa (max c (n + 1)) (take i l @ x # drop i l) (a', n') * ↑ (n' = n + 1 ∧ n ≤ c)>⇩t›*) by (sep_auto heap add: pfa_insert_rule[of i n "max c (Suc n)"]) definition pfa_extend where "pfa_extend ≡ λ (a,n) (b,m). do{ blit b 0 a n m; return (a,n+m) }" lemma pfa_extend_rule[sep_heap_rules]: "n+m ≤ c ⟹ <is_pfa c l1 (a,n) * is_pfa d l2 (b,m)> pfa_extend (a,n) (b,m) <λ(a',n'). is_pfa c (l1@l2) (a',n') * ↑(a' = a ∧ n'=n+m) * is_pfa d l2 (b,m)>⇩t" unfolding pfa_extend_def (*goal: ‹n + m ≤ c ⟹ <is_pfa c l1 (a, n) * is_pfa d l2 (b, m)> (case (a, n) of (a, n) ⇒ λ(b, m). blit b 0 a n m ⤜ (λ_. return (a, n + m))) (b, m) <λr. case r of (a', n') ⇒ is_pfa c (l1 @ l2) (a', n') * ↑ (a' = a ∧ n' = n + m) * is_pfa d l2 (b, m)>⇩t›*) by (sep_auto simp add: is_pfa_def min.absorb1 min.absorb2 heap add: blit_rule) definition pfa_extend_grow where "pfa_extend_grow ≡ λ (a,n) (b,m). do{ a' ← array_ensure a (n+m) default; blit b 0 a' n m; return (a',n+m) }" lemma pfa_extend_grow_rule[sep_heap_rules]: "<is_pfa c l1 (a,n) * is_pfa d l2 (b,m)> pfa_extend_grow (a,n) (b,m) <λ(a',n'). is_pfa (max c (n+m)) (l1@l2) (a',n') * ↑(n'=n+m ∧ c ≥ n) * is_pfa d l2 (b,m)>⇩t" unfolding pfa_extend_grow_def (*goal: ‹<is_pfa c l1 (a, n) * is_pfa d l2 (b, m)> (case (a, n) of (a, n) ⇒ λ(b, m). array_ensure a (n + m) default ⤜ (λa'. blit b 0 a' n m ⤜ (λ_. return (a', n + m)))) (b, m) <λr. case r of (a', n') ⇒ is_pfa (max c (n + m)) (l1 @ l2) (a', n') * ↑ (n' = n + m ∧ n ≤ c) * is_pfa d l2 (b, m)>⇩t›*) by (sep_auto simp add: is_pfa_def min.absorb1 min.absorb2 heap add: blit_rule) definition pfa_append_extend_grow where "pfa_append_extend_grow ≡ λ (a,n) x (b,m). do{ a' ← array_ensure a (n+m+1) default; a'' ← Array.upd n x a'; blit b 0 a'' (n+1) m; return (a'',n+m+1) }" lemma pfa_append_extend_grow_rule[sep_heap_rules]: "<is_pfa c l1 (a,n) * is_pfa d l2 (b,m)> pfa_append_extend_grow (a,n) x (b,m) <λ(a',n'). is_pfa (max c (n+m+1)) (l1@x#l2) (a',n') * ↑(n'=n+m+1 ∧ c ≥ n) * is_pfa d l2 (b,m)>⇩t" unfolding pfa_append_extend_grow_def (*goal: ‹<is_pfa c l1 (a, n) * is_pfa d l2 (b, m)> (case (a, n) of (a, n) ⇒ λx (b, m). array_ensure a (n + m + 1) default ⤜ (λa'. Array.upd n x a' ⤜ (λa''. blit b 0 a'' (n + 1) m ⤜ (λ_. return (a'', n + m + 1))))) x (b, m) <λr. case r of (a', n') ⇒ is_pfa (max c (n + m + 1)) (l1 @ x # l2) (a', n') * ↑ (n' = n + m + 1 ∧ n ≤ c) * is_pfa d l2 (b, m)>⇩t›*) by (sep_auto simp add: list_update_last is_pfa_def min.absorb1 min.absorb2 heap add: blit_rule) definition "pfa_delete ≡ λ(a,n) i. do { array_shl a (i+1) 1; return (a,n-1) }" lemma pfa_delete_rule[sep_heap_rules]: "i < n ⟹ <is_pfa c l (a,n)> pfa_delete (a,n) i <λ(a',n'). is_pfa c (take i l@drop (i+1) l) (a',n') * ↑(n' = n-1 ∧ a=a')>" unfolding pfa_delete_def is_pfa_def (*goal: ‹i < n ⟹ <case (a, n) of (a, n) ⇒ ∃⇩Al'. a ↦⇩a l' * ↑ (c = length l' ∧ n ≤ c ∧ l = take n l')> (case (a, n) of (a, n) ⇒ λi. array_shl a (i + 1) 1 ⤜ (λ_. return (a, n - 1))) i <λ(a', n'). (case (a', n') of (a, n) ⇒ ∃⇩Al'. a ↦⇩a l' * ↑ (c = length l' ∧ n ≤ c ∧ take i l @ drop (i + 1) l = take n l')) * ↑ (n' = n - 1 ∧ a = a')>›*) apply (sep_auto simp add: drop_take min_def) (*goal: ‹i < n ⟹ <case (a, n) of (a, n) ⇒ ∃⇩Al'. a ↦⇩a l' * ↑ (c = length l' ∧ n ≤ c ∧ l = take n l')> (case (a, n) of (a, n) ⇒ λi. array_shl a (i + 1) 1 ⤜ (λ_. return (a, n - 1))) i <λ(a', n'). (case (a', n') of (a, n) ⇒ ∃⇩Al'. a ↦⇩a l' * ↑ (c = length l' ∧ n ≤ c ∧ take i l @ drop (i + 1) l = take n l')) * ↑ (n' = n - 1 ∧ a = a')>›*) by (metis Suc_diff_Suc (*‹(?n::nat) < (?m::nat) ⟹ Suc (?m - Suc ?n) = ?m - ?n›*) diff_zero (*‹(?a::?'a::cancel_comm_monoid_add) - (0::?'a::cancel_comm_monoid_add) = ?a›*) dual_order.strict_trans2 (*‹⟦(?b::?'a::preorder) < (?a::?'a::preorder); (?c::?'a::preorder) ≤ ?b⟧ ⟹ ?c < ?a›*) le_less_Suc_eq (*‹(?m::nat) ≤ (?n::nat) ⟹ (?n < Suc ?m) = (?n = ?m)›*) zero_le (*‹(0::?'a::canonically_ordered_monoid_add) ≤ (?x::?'a::canonically_ordered_monoid_add)›*)) end
{ "path": "afp-2025-02-12/thys/BTree/Partially_Filled_Array.thy", "repo": "afp-2025-02-12", "sha": "59cb8bdf298762efbafb1dc277ddc0721fdf08536a49967006b58dc9f049aa33" }
(* File: Solovay_Strassen.thy Authors: Daniel Stüwe, Manuel Eberl The Solovay--Strassen primality test. *) section ‹The Solovay--Strassen Test› theory Solovay_Strassen_Test imports Generalized_Primality_Test Euler_Witness begin definition solovay_strassen_witness :: "nat ⇒ nat ⇒ bool" where "solovay_strassen_witness n a = (let x = Jacobi (int a) (int n) in x ≠ 0 ∧ [x = int a ^ ((n - 1) div 2)] (mod n))" definition solovay_strassen :: "nat ⇒ bool pmf" where "solovay_strassen = primality_test solovay_strassen_witness" lemma prime_imp_solovay_strassen_witness: assumes "prime p" "odd p" "a ∈ {2..<p}" shows "solovay_strassen_witness p a" proof (-) (*goal: ‹solovay_strassen_witness p a›*) have eq: "Jacobi a p = Legendre a p" using prime_p_Jacobi_eq_Legendre (*‹prime ?p ⟹ Jacobi ?a ?p = Legendre ?a ?p›*) assms (*‹prime p› ‹odd p› ‹a ∈ {2..<p}›*) by simp from ‹prime p› (*‹prime p›*) have "coprime p a" apply (rule prime_imp_coprime (*‹⟦prime ?p; ¬ ?p dvd ?n⟧ ⟹ coprime ?p ?n›*)) (*goal: ‹coprime (p::nat) (a::nat)›*) by (use assms in auto) show "?thesis" (*goal: ‹solovay_strassen_witness (p::nat) (a::nat)›*) unfolding solovay_strassen_witness_def Let_def eq (*goal: ‹Legendre (int (a::nat)) (int (p::nat)) ≠ (0::int) ∧ [Legendre (int a) (int p) = int a ^ ((p - (1::nat)) div (2::nat))] (mod int p)›*) proof (standard) (*goals: 1. ‹Legendre (int a) (int p) ≠ 0› 2. ‹[Legendre (int a) (int p) = int a ^ ((p - 1) div 2)] (mod int p)›*) from ‹coprime p a› (*‹coprime (p::nat) (a::nat)›*) ‹prime p› (*‹prime p›*) show "Legendre (int a) (int p) ≠ 0" by (auto simp: coprime_commute (*‹coprime ?b ?a = coprime ?a ?b›*)) next (*goal: ‹[Legendre (int a) (int p) = int a ^ ((p - 1) div 2)] (mod int p)›*) show "[Legendre (int a) (int p) = int a ^ ((p - 1) div 2)] (mod int p)" using assms (*‹prime p› ‹odd p› ‹a ∈ {2..<p}›*) apply (intro euler_criterion (*‹⟦prime ?p; 2 < ?p⟧ ⟹ [Legendre ?a (int ?p) = ?a ^ ((?p - 1) div 2)] (mod int ?p)›*)) (*goals: 1. ‹⟦prime (p::nat); odd p; (a::nat) ∈ {2::nat..<p}⟧ ⟹ prime p› 2. ‹⟦prime (p::nat); odd p; (a::nat) ∈ {2::nat..<p}⟧ ⟹ (2::nat) < p› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed qed lemma card_solovay_strassen_liars_composite: fixes n :: nat assumes "¬prime n" "n > 2" "odd n" shows "card {a ∈ {2..<n}. solovay_strassen_witness n a} < (n - 2) div 2" (is "card ?A < _") proof (-) (*goal: ‹card {a::nat ∈ {2::nat..<n::nat}. solovay_strassen_witness n a} < (n - (2::nat)) div (2::nat)›*) interpret euler_witness_context n using assms (*‹¬ prime (n::nat)› ‹2 < n› ‹odd n›*) unfolding euler_witness_context_def (*goal: ‹1 < n ∧ odd n›*) by simp have "card H < (n - 1) div 2" by (intro card_euler_liars_cosets_limit( (*‹⟦¬ prime n; 2 < n⟧ ⟹ card H < (n - 1) div 2›*) 2) assms (*‹¬ prime n› ‹2 < n› ‹odd n›*)) also (*calculation: ‹card H < ((n::nat) - (1::nat)) div (2::nat)›*) from assms (*‹¬ prime n› ‹2 < n› ‹odd (n::nat)›*) have "H = insert 1 ?A" by (auto simp: solovay_strassen_witness_def (*‹solovay_strassen_witness ?n ?a = (let x = Jacobi (int ?a) (int ?n) in x ≠ 0 ∧ [x = int ?a ^ ((?n - 1) div 2)] (mod int ?n))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) euler_witness_def (*‹euler_witness ?a ?p = [Jacobi ?a (int ?p) ≠ ?a ^ ((?p - 1) div 2)] (mod int ?p)›*) H_def (*‹H = {x. coprime x n ∧ euler_liar (int x) n ∧ x ∈ {1..<n}}›*) Jacobi_eq_0_iff_not_coprime (*‹⟦?p ≠ 0; ?p ≠ 1⟧ ⟹ (Jacobi ?n ?p = 0) = (¬ coprime ?n ?p)›*)) also (*calculation: ‹card (insert 1 {a ∈ {2..<n}. solovay_strassen_witness n a}) < (n - 1) div 2›*) have "card … = card ?A + 1" apply (subst card.insert (*‹⟦finite ?A; ?x ∉ ?A⟧ ⟹ card (insert ?x ?A) = Suc (card ?A)›*)) (*goals: 1. ‹finite {a ∈ {2..<n}. solovay_strassen_witness n a}› 2. ‹1 ∉ {a ∈ {2..<n}. solovay_strassen_witness n a}› 3. ‹Suc (card {a ∈ {2..<n}. solovay_strassen_witness n a}) = card {a ∈ {2..<n}. solovay_strassen_witness n a} + 1› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . finally (*calculation: ‹card {a ∈ {2..<n}. solovay_strassen_witness n a} + 1 < (n - 1) div 2›*) show "card ?A < (n - 2) div 2" by linarith qed interpretation solovay_strassen: good_prob_primality_test solovay_strassen_witness n "1 / 2" rewrites "primality_test solovay_strassen_witness = solovay_strassen" proof (-) (*goals: 1. ‹good_prob_primality_test solovay_strassen_witness n (1 / 2)› 2. ‹primality_test solovay_strassen_witness = solovay_strassen›*) show "good_prob_primality_test solovay_strassen_witness n (1 / 2)" proof (standard) (*goals: 1. ‹⋀a. ⟦odd n; 2 ≤ a; a < n; prime n⟧ ⟹ solovay_strassen_witness n a› 2. ‹0 < 1 / 2› 3. ‹⟦¬ prime n; 2 < n; odd n⟧ ⟹ real (card {a. 2 ≤ a ∧ a < n ∧ solovay_strassen_witness n a}) < 1 / 2 * real (n - 2)›*) fix n :: nat assume "¬prime n" "n > 2" "odd n" (*‹¬ prime (n::nat)› ‹(2::nat) < (n::nat)› ‹odd (n::nat)›*) thus "real (card {a. 2 ≤ a ∧ a < n ∧ solovay_strassen_witness n a}) < (1 / 2) * real (n - 2)" using card_solovay_strassen_liars_composite[of n] (*‹⟦¬ prime n; 2 < n; odd n⟧ ⟹ card {a ∈ {2..<n}. solovay_strassen_witness n a} < (n - 2) div 2›*) by auto qed (use prime_imp_solovay_strassen_witness in auto) (*solves the remaining goals: 1. ‹⋀a. ⟦odd n; 2 ≤ a; a < n; prime n⟧ ⟹ solovay_strassen_witness n a› 2. ‹0 < 1 / 2›*) qed (simp_all add: solovay_strassen_def) (*solved the remaining goal: ‹primality_test solovay_strassen_witness = solovay_strassen›*) end
{ "path": "afp-2025-02-12/thys/Probabilistic_Prime_Tests/Solovay_Strassen_Test.thy", "repo": "afp-2025-02-12", "sha": "85f42f910798b23188aaf4a6ae9cce409efa0df8c4ae22dd2a1a9e2aca8eb3ca" }
theory Canton_Transaction_Tree imports Inclusion_Proof_Construction begin section ‹Canton's hierarchical transaction trees› typedecl view_data typedecl view_metadata typedecl common_metadata typedecl participant_metadata datatype view = View view_metadata view_data (subviews: "view list") datatype transaction = Transaction common_metadata participant_metadata (views: "view list") subsection ‹Views as authenticated data structures› type_synonym view_metadata⇩h = "view_metadata blindable⇩h" type_synonym view_data⇩h = "view_data blindable⇩h" datatype view⇩h = View⇩h "((view_metadata⇩h ×⇩h view_data⇩h) ×⇩h view⇩h list⇩h) blindable⇩h" type_synonym view_metadata⇩m = "(view_metadata, view_metadata) blindable⇩m" type_synonym view_data⇩m = "(view_data, view_data) blindable⇩m" datatype view⇩m = View⇩m "((view_metadata⇩m ×⇩m view_data⇩m) ×⇩m view⇩m list⇩m, (view_metadata⇩h ×⇩h view_data⇩h) ×⇩h view⇩h list⇩h) blindable⇩m" abbreviation (input) hash_view_data :: "(view_data⇩m, view_data⇩h) hash" where "hash_view_data ≡ hash_blindable id" abbreviation (input) blinding_of_view_data :: "view_data⇩m blinding_of" where "blinding_of_view_data ≡ blinding_of_blindable id (=)" abbreviation (input) merge_view_data :: "view_data⇩m merge" where "merge_view_data ≡ merge_blindable id merge_discrete" lemma merkle_view_data: "merkle_interface hash_view_data blinding_of_view_data merge_view_data" by unfold_locales abbreviation (input) hash_view_metadata :: "(view_metadata⇩m, view_metadata⇩h) hash" where "hash_view_metadata ≡ hash_blindable id" abbreviation (input) blinding_of_view_metadata :: "view_metadata⇩m blinding_of" where "blinding_of_view_metadata ≡ blinding_of_blindable id (=)" abbreviation (input) merge_view_metadata :: "view_metadata⇩m merge" where "merge_view_metadata ≡ merge_blindable id merge_discrete" lemma merkle_view_metadata: "merkle_interface hash_view_metadata blinding_of_view_metadata merge_view_metadata" by unfold_locales type_synonym view_content = "view_metadata × view_data" type_synonym view_content⇩h = "view_metadata⇩h ×⇩h view_data⇩h" type_synonym view_content⇩m = "view_metadata⇩m ×⇩m view_data⇩m" locale view_merkle begin type_synonym view⇩h' = "view_content⇩h rose_tree⇩h" primrec from_view⇩h :: "view⇩h ⇒ view⇩h'" where "from_view⇩h (View⇩h x) = Tree⇩h (map_blindable⇩h (map_prod id (map from_view⇩h)) x)" primrec to_view⇩h :: "view⇩h' ⇒ view⇩h" where "to_view⇩h (Tree⇩h x) = View⇩h (map_blindable⇩h (map_prod id (map to_view⇩h)) x)" lemma from_to_view⇩h [simp]: "from_view⇩h (to_view⇩h x) = x" apply (induction x) (*goal: ‹from_view⇩h (to_view⇩h x) = x›*) apply (simp add: blindable⇩h.map_comp (*‹map_blindable⇩h (?g::?'b::type ⇒ ?'c::type) (map_blindable⇩h (?f::?'a::type ⇒ ?'b::type) (?v::?'a::type blindable⇩h)) = map_blindable⇩h (?g ∘ ?f) ?v›*) o_def (*‹(?f::?'b::type ⇒ ?'c::type) ∘ (?g::?'a::type ⇒ ?'b::type) = (λx::?'a::type. ?f (?g x))›*) prod.map_comp (*‹map_prod (?g1.0::?'c::type ⇒ ?'e::type) (?g2.0::?'d::type ⇒ ?'f::type) (map_prod (?f1.0::?'a::type ⇒ ?'c::type) (?f2.0::?'b::type ⇒ ?'d::type) (?v::?'a::type × ?'b::type)) = map_prod (?g1.0 ∘ ?f1.0) (?g2.0 ∘ ?f2.0) ?v›*)) (*goal: ‹⋀xa::((view_metadata blindable⇩h × view_data blindable⇩h) × (view_metadata blindable⇩h × view_data blindable⇩h) rose_tree⇩h list) blindable⇩h. (⋀(xaa::(view_metadata blindable⇩h × view_data blindable⇩h) × (view_metadata blindable⇩h × view_data blindable⇩h) rose_tree⇩h list) (xaaa::(view_metadata blindable⇩h × view_data blindable⇩h) rose_tree⇩h list) xaaaa::(view_metadata blindable⇩h × view_data blindable⇩h) rose_tree⇩h. ⟦xaa ∈ set_blindable⇩h xa; xaaa ∈ snds xaa; xaaaa ∈ set xaaa⟧ ⟹ from_view⇩h (to_view⇩h xaaaa) = xaaaa) ⟹ from_view⇩h (to_view⇩h (Tree⇩h xa)) = Tree⇩h xa›*) by (simp cong: blindable⇩h.map_cong (*‹⟦?x = ?ya; ⋀z. z ∈ set_blindable⇩h ?ya ⟹ ?f z = ?g z⟧ ⟹ map_blindable⇩h ?f ?x = map_blindable⇩h ?g ?ya›*) prod.map_cong (*‹⟦?x = ?ya; ⋀z1. z1 ∈ fsts ?ya ⟹ ?f1.0 z1 = ?g1.0 z1; ⋀z2. z2 ∈ snds ?ya ⟹ ?f2.0 z2 = ?g2.0 z2⟧ ⟹ map_prod ?f1.0 ?f2.0 ?x = map_prod ?g1.0 ?g2.0 ?ya›*) list.map_cong (*‹⟦?x = ?ya; ⋀z. z ∈ set ?ya ⟹ ?f z = ?g z⟧ ⟹ map ?f ?x = map ?g ?ya›*) add: blindable⇩h.map_id[unfolded id_def] (*‹map_blindable⇩h (λx. x) ?t = ?t›*)) lemma to_from_view⇩h [simp]: "to_view⇩h (from_view⇩h x) = x" apply (induction x) (*goal: ‹to_view⇩h (from_view⇩h (x::view⇩h)) = x›*) apply (simp add: blindable⇩h.map_comp (*‹map_blindable⇩h ?g (map_blindable⇩h ?f ?v) = map_blindable⇩h (?g ∘ ?f) ?v›*) o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*) prod.map_comp (*‹map_prod ?g1.0 ?g2.0 (map_prod ?f1.0 ?f2.0 ?v) = map_prod (?g1.0 ∘ ?f1.0) (?g2.0 ∘ ?f2.0) ?v›*)) (*goal: ‹⋀xa::((view_metadata blindable⇩h × view_data blindable⇩h) × view⇩h list) blindable⇩h. (⋀(xaa::(view_metadata blindable⇩h × view_data blindable⇩h) × view⇩h list) (xaaa::view⇩h list) xaaaa::view⇩h. ⟦xaa ∈ set_blindable⇩h xa; xaaa ∈ snds xaa; xaaaa ∈ set xaaa⟧ ⟹ to_view⇩h (from_view⇩h xaaaa) = xaaaa) ⟹ to_view⇩h (from_view⇩h (View⇩h xa)) = View⇩h xa›*) by (simp cong: blindable⇩h.map_cong (*‹⟦?x = ?ya; ⋀z. z ∈ set_blindable⇩h ?ya ⟹ ?f z = ?g z⟧ ⟹ map_blindable⇩h ?f ?x = map_blindable⇩h ?g ?ya›*) prod.map_cong (*‹⟦?x = ?ya; ⋀z1. z1 ∈ fsts ?ya ⟹ ?f1.0 z1 = ?g1.0 z1; ⋀z2. z2 ∈ snds ?ya ⟹ ?f2.0 z2 = ?g2.0 z2⟧ ⟹ map_prod ?f1.0 ?f2.0 ?x = map_prod ?g1.0 ?g2.0 ?ya›*) list.map_cong (*‹⟦?x = ?ya; ⋀z. z ∈ set ?ya ⟹ ?f z = ?g z⟧ ⟹ map ?f ?x = map ?g ?ya›*) add: blindable⇩h.map_id[unfolded id_def] (*‹map_blindable⇩h (λx. x) ?t = ?t›*)) lemma iso_view⇩h: "type_definition from_view⇩h to_view⇩h UNIV" apply unfold_locales (*goals: 1. ‹⋀x. from_view⇩h x ∈ UNIV› 2. ‹⋀x. to_view⇩h (from_view⇩h x) = x› 3. ‹⋀y. y ∈ UNIV ⟹ from_view⇩h (to_view⇩h y) = y› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) . setup_lifting iso_view⇩h lemma cr_view⇩h_Grp: "cr_view⇩h = Grp UNIV to_view⇩h" apply (simp add: cr_view⇩h_def (*‹cr_view⇩h ≡ λx y. x = from_view⇩h y›*) Grp_def (*‹Grp ?A ?f = (λa b. b = ?f a ∧ a ∈ ?A)›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*)) (*goal: ‹cr_view⇩h = Grp UNIV to_view⇩h›*) apply transfer (*goal: ‹∀(x::(view_metadata blindable⇩h × view_data blindable⇩h) rose_tree⇩h) xa::view⇩h. (x = from_view⇩h xa) = (xa = to_view⇩h x)›*) by auto lemma View⇩h_transfer [transfer_rule]: includes lifting_syntax shows "(rel_blindable⇩h (rel_prod (=) (list_all2 pcr_view⇩h)) ===> pcr_view⇩h) Tree⇩h View⇩h" apply (simp add: rel_fun_def (*‹?A ===> ?B = (λf g. ∀x y. ?A x y ⟶ ?B (f x) (g y))›*) view⇩h.pcr_cr_eq (*‹pcr_view⇩h = cr_view⇩h›*) cr_view⇩h_Grp (*‹cr_view⇩h = Grp UNIV to_view⇩h›*) list.rel_Grp (*‹list_all2 (Grp ?A ?f) = Grp {x. set x ⊆ ?A} (map ?f)›*) eq_alt (*‹(=) = Grp UNIV id›*) prod.rel_Grp (*‹rel_prod (Grp ?A1.0 ?f1.0) (Grp ?A2.0 ?f2.0) = Grp {x. fsts x ⊆ ?A1.0 ∧ snds x ⊆ ?A2.0} (map_prod ?f1.0 ?f2.0)›*) blindable⇩h.rel_Grp (*‹rel_blindable⇩h (Grp ?A ?f) = Grp {x. set_blindable⇩h x ⊆ ?A} (map_blindable⇩h ?f)›*)) (*goal: ‹(rel_blindable⇩h (rel_prod (=) (list_all2 pcr_view⇩h)) ===> pcr_view⇩h) Tree⇩h View⇩h›*) by (simp add: Grp_def (*‹Grp (?A::?'a set) (?f::?'a ⇒ ?'b) = (λ(a::?'a) b::?'b. b = ?f a ∧ a ∈ ?A)›*)) type_synonym view⇩m' = "(view_content⇩m, view_content⇩h) rose_tree⇩m" primrec from_view⇩m :: "view⇩m ⇒ view⇩m'" where "from_view⇩m (View⇩m x) = Tree⇩m (map_blindable⇩m (map_prod id (map from_view⇩m)) (map_prod id (map from_view⇩h)) x)" primrec to_view⇩m :: "view⇩m' ⇒ view⇩m" where "to_view⇩m (Tree⇩m x) = View⇩m (map_blindable⇩m (map_prod id (map to_view⇩m)) (map_prod id (map to_view⇩h)) x)" lemma from_to_view⇩m [simp]: "from_view⇩m (to_view⇩m x) = x" apply (induction x) (*goal: ‹from_view⇩m (to_view⇩m (x::((view_metadata, view_metadata) blindable⇩m × (view_data, view_data) blindable⇩m, view_metadata blindable⇩h × view_data blindable⇩h) rose_tree⇩m)) = x›*) apply (simp add: blindable⇩m.map_comp (*‹map_blindable⇩m ?g1.0 ?g2.0 (map_blindable⇩m ?f1.0 ?f2.0 ?v) = map_blindable⇩m (?g1.0 ∘ ?f1.0) (?g2.0 ∘ ?f2.0) ?v›*) o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*) prod.map_comp (*‹map_prod ?g1.0 ?g2.0 (map_prod ?f1.0 ?f2.0 ?v) = map_prod (?g1.0 ∘ ?f1.0) (?g2.0 ∘ ?f2.0) ?v›*)) (*goal: ‹⋀xa. (⋀xaa xaaa xaaaa. ⟦xaa ∈ set1_blindable⇩m xa; xaaa ∈ snds xaa; xaaaa ∈ set xaaa⟧ ⟹ from_view⇩m (to_view⇩m xaaaa) = xaaaa) ⟹ from_view⇩m (to_view⇩m (Tree⇩m xa)) = Tree⇩m xa›*) by (simp cong: blindable⇩m.map_cong (*‹⟦?x = ?ya; ⋀z1. z1 ∈ set1_blindable⇩m ?ya ⟹ ?f1.0 z1 = ?g1.0 z1; ⋀z2. z2 ∈ set2_blindable⇩m ?ya ⟹ ?f2.0 z2 = ?g2.0 z2⟧ ⟹ map_blindable⇩m ?f1.0 ?f2.0 ?x = map_blindable⇩m ?g1.0 ?g2.0 ?ya›*) prod.map_cong (*‹⟦?x = ?ya; ⋀z1. z1 ∈ fsts ?ya ⟹ ?f1.0 z1 = ?g1.0 z1; ⋀z2. z2 ∈ snds ?ya ⟹ ?f2.0 z2 = ?g2.0 z2⟧ ⟹ map_prod ?f1.0 ?f2.0 ?x = map_prod ?g1.0 ?g2.0 ?ya›*) list.map_cong (*‹⟦?x = ?ya; ⋀z. z ∈ set ?ya ⟹ ?f z = ?g z⟧ ⟹ map ?f ?x = map ?g ?ya›*) add: blindable⇩m.map_id[unfolded id_def] (*‹map_blindable⇩m (λx. x) (λx. x) ?t = ?t›*)) lemma to_from_view⇩m [simp]: "to_view⇩m (from_view⇩m x) = x" apply (induction x) (*goal: ‹to_view⇩m (from_view⇩m (x::view⇩m)) = x›*) apply (simp add: blindable⇩m.map_comp (*‹map_blindable⇩m ?g1.0 ?g2.0 (map_blindable⇩m ?f1.0 ?f2.0 ?v) = map_blindable⇩m (?g1.0 ∘ ?f1.0) (?g2.0 ∘ ?f2.0) ?v›*) o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*) prod.map_comp (*‹map_prod ?g1.0 ?g2.0 (map_prod ?f1.0 ?f2.0 ?v) = map_prod (?g1.0 ∘ ?f1.0) (?g2.0 ∘ ?f2.0) ?v›*)) (*goal: ‹⋀xa. (⋀xaa xaaa xaaaa. ⟦xaa ∈ set1_blindable⇩m xa; xaaa ∈ snds xaa; xaaaa ∈ set xaaa⟧ ⟹ to_view⇩m (from_view⇩m xaaaa) = xaaaa) ⟹ to_view⇩m (from_view⇩m (View⇩m xa)) = View⇩m xa›*) by (simp cong: blindable⇩m.map_cong (*‹⟦?x = ?ya; ⋀z1. z1 ∈ set1_blindable⇩m ?ya ⟹ ?f1.0 z1 = ?g1.0 z1; ⋀z2. z2 ∈ set2_blindable⇩m ?ya ⟹ ?f2.0 z2 = ?g2.0 z2⟧ ⟹ map_blindable⇩m ?f1.0 ?f2.0 ?x = map_blindable⇩m ?g1.0 ?g2.0 ?ya›*) prod.map_cong (*‹⟦?x = ?ya; ⋀z1. z1 ∈ fsts ?ya ⟹ ?f1.0 z1 = ?g1.0 z1; ⋀z2. z2 ∈ snds ?ya ⟹ ?f2.0 z2 = ?g2.0 z2⟧ ⟹ map_prod ?f1.0 ?f2.0 ?x = map_prod ?g1.0 ?g2.0 ?ya›*) list.map_cong (*‹⟦?x = ?ya; ⋀z. z ∈ set ?ya ⟹ ?f z = ?g z⟧ ⟹ map ?f ?x = map ?g ?ya›*) add: blindable⇩m.map_id[unfolded id_def] (*‹map_blindable⇩m (λx. x) (λx. x) ?t = ?t›*)) lemma iso_view⇩m: "type_definition from_view⇩m to_view⇩m UNIV" apply unfold_locales (*goals: 1. ‹⋀x. from_view⇩m x ∈ UNIV› 2. ‹⋀x. to_view⇩m (from_view⇩m x) = x› 3. ‹⋀y. y ∈ UNIV ⟹ from_view⇩m (to_view⇩m y) = y› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) . setup_lifting iso_view⇩m lemma cr_view⇩m_Grp: "cr_view⇩m = Grp UNIV to_view⇩m" apply (simp add: cr_view⇩m_def (*‹cr_view⇩m ≡ λx y. x = from_view⇩m y›*) Grp_def (*‹Grp ?A ?f = (λa b. b = ?f a ∧ a ∈ ?A)›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*)) (*goal: ‹cr_view⇩m = Grp UNIV to_view⇩m›*) apply transfer (*goal: ‹∀x xa. (x = from_view⇩m xa) = (xa = to_view⇩m x)›*) by auto lemma View⇩m_transfer [transfer_rule]: includes lifting_syntax shows "(rel_blindable⇩m (rel_prod (=) (list_all2 pcr_view⇩m)) (rel_prod (=) (list_all2 pcr_view⇩h)) ===> pcr_view⇩m) Tree⇩m View⇩m" apply (simp add: rel_fun_def (*‹?A ===> ?B = (λf g. ∀x y. ?A x y ⟶ ?B (f x) (g y))›*) view⇩h.pcr_cr_eq (*‹pcr_view⇩h = cr_view⇩h›*) view⇩m.pcr_cr_eq (*‹pcr_view⇩m = cr_view⇩m›*) cr_view⇩h_Grp (*‹cr_view⇩h = Grp UNIV to_view⇩h›*) cr_view⇩m_Grp (*‹cr_view⇩m = Grp UNIV to_view⇩m›*) list.rel_Grp (*‹list_all2 (Grp ?A ?f) = Grp {x. set x ⊆ ?A} (map ?f)›*) eq_alt (*‹(=) = Grp UNIV id›*) prod.rel_Grp (*‹rel_prod (Grp ?A1.0 ?f1.0) (Grp ?A2.0 ?f2.0) = Grp {x. fsts x ⊆ ?A1.0 ∧ snds x ⊆ ?A2.0} (map_prod ?f1.0 ?f2.0)›*) blindable⇩m.rel_Grp (*‹rel_blindable⇩m (Grp ?A1.0 ?f1.0) (Grp ?A2.0 ?f2.0) = Grp {x. set1_blindable⇩m x ⊆ ?A1.0 ∧ set2_blindable⇩m x ⊆ ?A2.0} (map_blindable⇩m ?f1.0 ?f2.0)›*)) (*goal: ‹(rel_blindable⇩m (rel_prod (=) (list_all2 pcr_view⇩m)) (rel_prod (=) (list_all2 pcr_view⇩h)) ===> pcr_view⇩m) Tree⇩m View⇩m›*) by (simp add: Grp_def (*‹Grp ?A ?f = (λa b. b = ?f a ∧ a ∈ ?A)›*)) end code_datatype View⇩h code_datatype View⇩m context begin interpretation view_merkle . abbreviation (input) hash_view_content :: "(view_content⇩m, view_content⇩h) hash" where "hash_view_content ≡ hash_prod hash_view_metadata hash_view_data" abbreviation (input) blinding_of_view_content :: "view_content⇩m blinding_of" where "blinding_of_view_content ≡ blinding_of_prod blinding_of_view_metadata blinding_of_view_data" abbreviation (input) merge_view_content :: "view_content⇩m merge" where "merge_view_content ≡ merge_prod merge_view_metadata merge_view_data" lift_definition hash_view :: "(view⇩m, view⇩h) hash" is "hash_tree hash_view_content" . lift_definition blinding_of_view :: "view⇩m blinding_of" is "blinding_of_tree hash_view_content blinding_of_view_content" . lift_definition merge_view :: "view⇩m merge" is "merge_tree hash_view_content merge_view_content" . lemma merkle_view [locale_witness]: "merkle_interface hash_view blinding_of_view merge_view" apply transfer (*goal: ‹merkle_interface hash_view blinding_of_view merge_view›*) by unfold_locales lemma hash_view_simps [simp]: "hash_view (View⇩m x) = View⇩h (hash_blindable (hash_prod hash_view_content (hash_list hash_view)) x)" apply transfer (*goal: ‹hash_view (View⇩m x) = View⇩h (hash_blindable (map_prod (map_prod (hash_blindable id) (hash_blindable id)) (map hash_view)) x)›*) by (simp add: hash_rt_F⇩m_def (*‹hash_rt_F⇩m (?h::?'a⇩m ⇒ ?'a⇩h) (?rhm::?'b⇩m ⇒ ?'b⇩h) ≡ hash_blindable id ∘ map_blindable⇩m (map_prod ?h (map ?rhm)) id›*) prod.map_comp (*‹map_prod (?g1.0::?'c ⇒ ?'e) (?g2.0::?'d ⇒ ?'f) (map_prod (?f1.0::?'a ⇒ ?'c) (?f2.0::?'b ⇒ ?'d) (?v::?'a × ?'b)) = map_prod (?g1.0 ∘ ?f1.0) (?g2.0 ∘ ?f2.0) ?v›*) hash_blindable_def (*‹hash_blindable (?h::?'a⇩m ⇒ ?'a⇩h) = hash_blindable' ∘ map_blindable⇩m ?h id›*) blindable⇩m.map_id (*‹map_blindable⇩m id id (?t::(?'a, ?'b) blindable⇩m) = ?t›*)) lemma blinding_of_view_iff [simp]: "blinding_of_view (View⇩m x) (View⇩m y) ⟷ blinding_of_blindable (hash_prod hash_view_content (hash_list hash_view)) (blinding_of_prod blinding_of_view_content (blinding_of_list blinding_of_view)) x y" apply transfer (*goal: ‹blinding_of_view (View⇩m x) (View⇩m y) = blinding_of_blindable (map_prod (map_prod (hash_blindable id) (hash_blindable id)) (map hash_view)) (rel_prod (rel_prod (blinding_of_blindable id (=)) (blinding_of_blindable id (=))) (list_all2 blinding_of_view)) x y›*) by simp lemma blinding_of_view_induct [consumes 1, induct pred: blinding_of_view]: assumes "blinding_of_view x y" and "⋀x y. blinding_of_blindable (hash_prod hash_view_content (hash_list hash_view)) (blinding_of_prod blinding_of_view_content (blinding_of_list (λx y. blinding_of_view x y ∧ P x y))) x y ⟹ P (View⇩m x) (View⇩m y)" shows "P x y" using assms (*‹blinding_of_view (x::view⇩m) (y::view⇩m)› ‹blinding_of_blindable (map_prod (map_prod (hash_blindable id) (hash_blindable id)) (map hash_view)) (rel_prod (rel_prod (blinding_of_blindable id (=)) (blinding_of_blindable id (=))) (list_all2 (λx y. blinding_of_view x y ∧ P x y))) ?x ?y ⟹ P (View⇩m ?x) (View⇩m ?y)›*) apply transfer (*goal: ‹P x y›*) apply (rule blinding_of_tree.induct (*‹⟦blinding_of_tree ?h ?bo ?x1.0 ?x2.0; ⋀t1 t2. blinding_of_blindable (map_prod ?h (map (hash_tree ?h))) (rel_prod ?bo (list_all2 (λx1 x2. blinding_of_tree ?h ?bo x1 x2 ∧ ?P x1 x2))) t1 t2 ⟹ ?P (Tree⇩m t1) (Tree⇩m t2)⟧ ⟹ ?P ?x1.0 ?x2.0›*)) (*goals: 1. ‹⋀x y P. ⟦blinding_of_tree (map_prod (hash_blindable id) (hash_blindable id)) (rel_prod (blinding_of_blindable id (=)) (blinding_of_blindable id (=))) x y; ⋀x y. blinding_of_blindable (map_prod (map_prod (hash_blindable id) (hash_blindable id)) (map (hash_tree (map_prod (hash_blindable id) (hash_blindable id))))) (rel_prod (rel_prod (blinding_of_blindable id (=)) (blinding_of_blindable id (=))) (list_all2 (λx y. blinding_of_tree (map_prod (hash_blindable id) (hash_blindable id)) (rel_prod (blinding_of_blindable id (=)) (blinding_of_blindable id (=))) x y ∧ P x y))) x y ⟹ P (Tree⇩m x) (Tree⇩m y)⟧ ⟹ blinding_of_tree (?h245 x y P) (?bo245 x y P) x y› 2. ‹⋀x y P t1 t2. ⟦blinding_of_tree (map_prod (hash_blindable id) (hash_blindable id)) (rel_prod (blinding_of_blindable id (=)) (blinding_of_blindable id (=))) x y; ⋀x y. blinding_of_blindable (map_prod (map_prod (hash_blindable id) (hash_blindable id)) (map (hash_tree (map_prod (hash_blindable id) (hash_blindable id))))) (rel_prod (rel_prod (blinding_of_blindable id (=)) (blinding_of_blindable id (=))) (list_all2 (λx y. blinding_of_tree (map_prod (hash_blindable id) (hash_blindable id)) (rel_prod (blinding_of_blindable id (=)) (blinding_of_blindable id (=))) x y ∧ P x y))) x y ⟹ P (Tree⇩m x) (Tree⇩m y); blinding_of_blindable (map_prod (?h245 x y P) (map (hash_tree (?h245 x y P)))) (rel_prod (?bo245 x y P) (list_all2 (λx1 x2. blinding_of_tree (?h245 x y P) (?bo245 x y P) x1 x2 ∧ P x1 x2))) t1 t2⟧ ⟹ P (Tree⇩m t1) (Tree⇩m t2)› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) lemma merge_view_simps [simp]: "merge_view (View⇩m x) (View⇩m y) = map_option View⇩m (merge_rt_F⇩m hash_view_content merge_view_content hash_view merge_view x y)" apply transfer (*goal: ‹merge_view (View⇩m (x::(((view_metadata, view_metadata) blindable⇩m × (view_data, view_data) blindable⇩m) × view⇩m list, (view_metadata blindable⇩h × view_data blindable⇩h) × view⇩h list) blindable⇩m)) (View⇩m (y::(((view_metadata, view_metadata) blindable⇩m × (view_data, view_data) blindable⇩m) × view⇩m list, (view_metadata blindable⇩h × view_data blindable⇩h) × view⇩h list) blindable⇩m)) = map_option View⇩m (merge_rt_F⇩m (map_prod (hash_blindable id) (hash_blindable id)) (merge_prod (merge_blindable id merge_discrete) (merge_blindable id merge_discrete)) hash_view merge_view x y)›*) by simp end subsection ‹Transaction trees as authenticated data structures› type_synonym common_metadata⇩h = "common_metadata blindable⇩h" type_synonym common_metadata⇩m = "(common_metadata, common_metadata) blindable⇩m" type_synonym participant_metadata⇩h = "participant_metadata blindable⇩h" type_synonym participant_metadata⇩m = "(participant_metadata, participant_metadata) blindable⇩m" datatype transaction⇩h = Transaction⇩h (the_Transaction⇩h: "((common_metadata⇩h ×⇩h participant_metadata⇩h) ×⇩h view⇩h list⇩h) blindable⇩h") datatype transaction⇩m = Transaction⇩m (the_Transaction⇩m: "((common_metadata⇩m ×⇩m participant_metadata⇩m) ×⇩m view⇩m list⇩m, (common_metadata⇩h ×⇩h participant_metadata⇩h) ×⇩h view⇩h list⇩h) blindable⇩m") abbreviation (input) hash_common_metadata :: "(common_metadata⇩m, common_metadata⇩h) hash" where "hash_common_metadata ≡ hash_blindable id" abbreviation (input) blinding_of_common_metadata :: "common_metadata⇩m blinding_of" where "blinding_of_common_metadata ≡ blinding_of_blindable id (=)" abbreviation (input) merge_common_metadata :: "common_metadata⇩m merge" where "merge_common_metadata ≡ merge_blindable id merge_discrete" abbreviation (input) hash_participant_metadata :: "(participant_metadata⇩m, participant_metadata⇩h) hash" where "hash_participant_metadata ≡ hash_blindable id" abbreviation (input) blinding_of_participant_metadata :: "participant_metadata⇩m blinding_of" where "blinding_of_participant_metadata ≡ blinding_of_blindable id (=)" abbreviation (input) merge_participant_metadata :: "participant_metadata⇩m merge" where "merge_participant_metadata ≡ merge_blindable id merge_discrete" locale transaction_merkle begin lemma iso_transaction⇩h: "type_definition the_Transaction⇩h Transaction⇩h UNIV" apply unfold_locales (*goals: 1. ‹⋀x. the_Transaction⇩h x ∈ UNIV› 2. ‹⋀x. Transaction⇩h (the_Transaction⇩h x) = x› 3. ‹⋀y. y ∈ UNIV ⟹ the_Transaction⇩h (Transaction⇩h y) = y› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) . setup_lifting iso_transaction⇩h lemma Transaction⇩h_transfer [transfer_rule]: includes lifting_syntax shows "((=) ===> pcr_transaction⇩h) id Transaction⇩h" by (simp add: transaction⇩h.pcr_cr_eq (*‹pcr_transaction⇩h = cr_transaction⇩h›*) cr_transaction⇩h_def (*‹cr_transaction⇩h ≡ λ(x::((common_metadata blindable⇩h × participant_metadata blindable⇩h) × view⇩h list) blindable⇩h) y::transaction⇩h. x = the_Transaction⇩h y›*) rel_fun_def (*‹(?A::?'a::type ⇒ ?'c::type ⇒ bool) ===> (?B::?'b::type ⇒ ?'d::type ⇒ bool) = (λ(f::?'a::type ⇒ ?'b::type) g::?'c::type ⇒ ?'d::type. ∀(x::?'a::type) y::?'c::type. ?A x y ⟶ ?B (f x) (g y))›*)) lemma iso_transaction⇩m: "type_definition the_Transaction⇩m Transaction⇩m UNIV" apply unfold_locales (*goals: 1. ‹⋀x::transaction⇩m. the_Transaction⇩m x ∈ UNIV› 2. ‹⋀x::transaction⇩m. Transaction⇩m (the_Transaction⇩m x) = x› 3. ‹⋀y::(((common_metadata, common_metadata) blindable⇩m × (participant_metadata, participant_metadata) blindable⇩m) × view⇩m list, (common_metadata blindable⇩h × participant_metadata blindable⇩h) × view⇩h list) blindable⇩m. y ∈ UNIV ⟹ the_Transaction⇩m (Transaction⇩m y) = y› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) . setup_lifting iso_transaction⇩m lemma Transaction⇩m_transfer [transfer_rule]: includes lifting_syntax shows "((=) ===> pcr_transaction⇩m) id Transaction⇩m" by (simp add: transaction⇩m.pcr_cr_eq (*‹pcr_transaction⇩m = cr_transaction⇩m›*) cr_transaction⇩m_def (*‹cr_transaction⇩m ≡ λx y. x = the_Transaction⇩m y›*) rel_fun_def (*‹?A ===> ?B = (λf g. ∀x y. ?A x y ⟶ ?B (f x) (g y))›*)) end code_datatype Transaction⇩h code_datatype Transaction⇩m context begin interpretation transaction_merkle . lift_definition hash_transaction :: "(transaction⇩m, transaction⇩h) hash" is "hash_blindable (hash_prod (hash_prod hash_common_metadata hash_participant_metadata) (hash_list hash_view))" . lift_definition blinding_of_transaction :: "transaction⇩m blinding_of" is "blinding_of_blindable (hash_prod (hash_prod hash_common_metadata hash_participant_metadata) (hash_list hash_view)) (blinding_of_prod (blinding_of_prod blinding_of_common_metadata blinding_of_participant_metadata) (blinding_of_list blinding_of_view))" . lift_definition merge_transaction :: "transaction⇩m merge" is "merge_blindable (hash_prod (hash_prod hash_common_metadata hash_participant_metadata) (hash_list hash_view)) (merge_prod (merge_prod merge_common_metadata merge_participant_metadata) (merge_list merge_view))" . lemma merkle_transaction [locale_witness]: "merkle_interface hash_transaction blinding_of_transaction merge_transaction" apply transfer (*goal: ‹merkle_interface hash_transaction blinding_of_transaction merge_transaction›*) by unfold_locales lemmas hash_transaction_simps [simp] = hash_transaction.abs_eq lemmas blinding_of_transaction_iff [simp] = blinding_of_transaction.abs_eq lemmas merge_transaction_simps [simp] = merge_transaction.abs_eq end interpretation transaction: merkle_interface hash_transaction blinding_of_transaction merge_transaction by (rule merkle_transaction (*‹merkle_interface hash_transaction blinding_of_transaction merge_transaction›*)) subsection ‹ Constructing authenticated data structures for views › context view_merkle begin type_synonym view' = "(view_metadata × view_data) rose_tree" primrec from_view :: "view ⇒ view'" where "from_view (View vm vd vs) = Tree ((vm, vd), map from_view vs)" primrec to_view :: "view' ⇒ view" where "to_view (Tree x) = View (fst (fst x)) (snd (fst x)) (snd (map_prod id (map to_view) x))" lemma from_to_view [simp]: "from_view (to_view x) = x" apply (induction x) (*goal: ‹from_view (to_view (x::(view_metadata × view_data) rose_tree)) = x›*) by (clarsimp cong: map_cong (*‹⟦?xs = ?ys; ⋀x. x ∈ set ?ys ⟹ ?f x = ?g x⟧ ⟹ map ?f ?xs = map ?g ?ys›*)) lemma to_from_view [simp]: "to_view (from_view x) = x" apply (induction x) (*goal: ‹to_view (from_view x) = x›*) by (clarsimp cong: map_cong (*‹⟦?xs = ?ys; ⋀x. x ∈ set ?ys ⟹ ?f x = ?g x⟧ ⟹ map ?f ?xs = map ?g ?ys›*)) lemma iso_view: "type_definition from_view to_view UNIV" apply unfold_locales (*goals: 1. ‹⋀x. from_view x ∈ UNIV› 2. ‹⋀x. to_view (from_view x) = x› 3. ‹⋀y. y ∈ UNIV ⟹ from_view (to_view y) = y› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) . setup_lifting iso_view definition View' :: "(view_metadata × view_data) × view list ⇒ view" where "View' = (λ((vm, vd), vs). View vm vd vs)" lemma View_View': "View = (λvm vd vs. View' ((vm, vd), vs))" by (simp add: View'_def (*‹View' = (λ((vm, vd), vs). View vm vd vs)›*)) lemma cr_view_Grp: "cr_view = Grp UNIV to_view" apply (simp add: cr_view_def (*‹cr_view ≡ λx y. x = from_view y›*) Grp_def (*‹Grp ?A ?f = (λa b. b = ?f a ∧ a ∈ ?A)›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*)) (*goal: ‹cr_view = Grp UNIV to_view›*) apply transfer (*goal: ‹∀x xa. (x = from_view xa) = (xa = to_view x)›*) by auto lemma View'_transfer [transfer_rule]: includes lifting_syntax shows "(rel_prod (=) (list_all2 pcr_view) ===> pcr_view) Tree View'" apply (simp add: view.pcr_cr_eq (*‹pcr_view = cr_view›*) cr_view_Grp (*‹cr_view = Grp UNIV to_view›*) eq_alt (*‹(=) = Grp UNIV id›*) prod.rel_Grp (*‹rel_prod (Grp ?A1.0 ?f1.0) (Grp ?A2.0 ?f2.0) = Grp {x. fsts x ⊆ ?A1.0 ∧ snds x ⊆ ?A2.0} (map_prod ?f1.0 ?f2.0)›*) rose_tree.rel_Grp (*‹rel_rose_tree (Grp ?A ?f) = Grp {x. set_rose_tree x ⊆ ?A} (map_rose_tree ?f)›*) list.rel_Grp (*‹list_all2 (Grp ?A ?f) = Grp {x. set x ⊆ ?A} (map ?f)›*)) (*goal: ‹(rel_prod (=) (list_all2 pcr_view) ===> pcr_view) Tree View'›*) by (auto simp add: Grp_def (*‹Grp ?A ?f = (λa b. b = ?f a ∧ a ∈ ?A)›*) View'_def (*‹View' = (λ((vm, vd), vs). View vm vd vs)›*)) end code_datatype View context begin interpretation view_merkle . abbreviation embed_view_content :: "view_metadata × view_data ⇒ view_metadata⇩m × view_data⇩m" where "embed_view_content ≡ map_prod Unblinded Unblinded" lift_definition embed_view :: "view ⇒ view⇩m" is "embed_source_tree embed_view_content" . lemma embed_view_simps [simp]: "embed_view (View vm vd vs) = View⇩m (Unblinded ((Unblinded vm, Unblinded vd), map embed_view vs))" unfolding View_View' (*goal: ‹embed_view (View' ((vm::view_metadata, vd::view_data), vs::view list)) = View⇩m (Unblinded ((Unblinded vm, Unblinded vd), map embed_view vs))›*) apply transfer (*goal: ‹embed_view (View' ((vm, vd), vs)) = View⇩m (Unblinded ((Unblinded vm, Unblinded vd), map embed_view vs))›*) by simp end context transaction_merkle begin primrec the_Transaction :: "transaction ⇒ (common_metadata × participant_metadata) × view list" where "the_Transaction (Transaction cm pm views) = ((cm, pm), views)" for views definition Transaction' :: "(common_metadata × participant_metadata) × view list ⇒ transaction" where "Transaction' = (λ((cm, pm), views). Transaction cm pm views)" lemma Transaction_Transaction': "Transaction = (λcm pm views. Transaction' ((cm, pm), views))" by (simp add: Transaction'_def (*‹Transaction' = (λ((cm, pm), views). Transaction cm pm views)›*)) lemma the_Transaction_inverse [simp]: "Transaction' (the_Transaction x) = x" apply (cases x) (*goal: ‹Transaction' (the_Transaction x) = x›*) by (simp add: Transaction'_def (*‹Transaction' = (λ((cm::common_metadata, pm::participant_metadata), views::view list). Transaction cm pm views)›*)) lemma Transaction'_inverse [simp]: "the_Transaction (Transaction' x) = x" by (simp add: Transaction'_def (*‹Transaction' = (λ((cm::common_metadata, pm::participant_metadata), views::view list). Transaction cm pm views)›*) split_def (*‹case_prod = (λ(c::?'a ⇒ ?'b ⇒ ?'c) p::?'a × ?'b. c (fst p) (snd p))›*)) lemma iso_transaction: "type_definition the_Transaction Transaction' UNIV" apply unfold_locales (*goals: 1. ‹⋀x. the_Transaction x ∈ UNIV› 2. ‹⋀x. Transaction' (the_Transaction x) = x› 3. ‹⋀y. y ∈ UNIV ⟹ the_Transaction (Transaction' y) = y› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) . setup_lifting iso_transaction lemma Transaction'_transfer [transfer_rule]: includes lifting_syntax shows "((=) ===> pcr_transaction) id Transaction'" by (simp add: transaction.pcr_cr_eq (*‹pcr_transaction = cr_transaction›*) cr_transaction_def (*‹cr_transaction ≡ λx y. x = the_Transaction y›*) rel_fun_def (*‹?A ===> ?B = (λf g. ∀x y. ?A x y ⟶ ?B (f x) (g y))›*)) end code_datatype Transaction context begin interpretation transaction_merkle . lift_definition embed_transaction :: "transaction ⇒ transaction⇩m" is "Unblinded ∘ map_prod (map_prod Unblinded Unblinded) (map embed_view)" . lemma embed_transaction_simps [simp]: "embed_transaction (Transaction cm pm views) = Transaction⇩m (Unblinded ((Unblinded cm, Unblinded pm), map embed_view views))" for views unfolding Transaction_Transaction' (*goal: ‹embed_transaction (Transaction' ((cm, pm), views)) = Transaction⇩m (Unblinded ((Unblinded cm, Unblinded pm), map embed_view views))›*) apply transfer (*goal: ‹embed_transaction (Transaction' ((cm, pm), views)) = Transaction⇩m (Unblinded ((Unblinded cm, Unblinded pm), map embed_view views))›*) apply simp (*top goal: ‹⋀cm pm. ?ab27 (λviews. (Unblinded ∘ map_prod (map_prod Unblinded Unblinded) (map embed_view)) (?ae27 ((cm, pm), views)) = ?ah27 (Unblinded ((Unblinded cm, Unblinded pm), map (embed_source_tree embed_view_content) views)))› and 3 goals remain*) by (msorry) end subsubsection ‹Inclusion proof for the mediator› primrec mediator_view :: "view ⇒ view⇩m" where "mediator_view (View vm vd vs) = View⇩m (Unblinded ((Unblinded vm, Blinded (Content vd)), map mediator_view vs))" primrec mediator_transaction_tree :: "transaction ⇒ transaction⇩m" where "mediator_transaction_tree (Transaction cm pm views) = Transaction⇩m (Unblinded ((Unblinded cm, Blinded (Content pm)), map mediator_view views))" for views lemma blinding_of_mediator_view [simp]: "blinding_of_view (mediator_view view) (embed_view view)" apply (induction view) (*goal: ‹blinding_of_view (mediator_view view) (embed_view view)›*) by (auto simp add: list.rel_map (*‹list_all2 ?Sb (map ?i ?x) ?y = list_all2 (λx. ?Sb (?i x)) ?x ?y› ‹list_all2 ?Sa ?x (map ?g ?y) = list_all2 (λx y. ?Sa x (?g y)) ?x ?y›*) intro!: list.rel_refl_strong (*‹(⋀z. z ∈ set ?x ⟹ ?Ra z z) ⟹ list_all2 ?Ra ?x ?x›*)) lemma blinding_of_mediator_transaction_tree: "blinding_of_transaction (mediator_transaction_tree tt) (embed_transaction tt)" apply (cases tt) (*goal: ‹blinding_of_transaction (mediator_transaction_tree tt) (embed_transaction tt)›*) by (auto simp add: list.rel_map (*‹list_all2 ?Sb (map ?i ?x) ?y = list_all2 (λx. ?Sb (?i x)) ?x ?y› ‹list_all2 ?Sa ?x (map ?g ?y) = list_all2 (λx y. ?Sa x (?g y)) ?x ?y›*) intro: list.rel_refl_strong (*‹(⋀z. z ∈ set ?x ⟹ ?Ra z z) ⟹ list_all2 ?Ra ?x ?x›*)) subsubsection ‹Inclusion proofs for participants› text ‹Next, we define a function for producing all transaction views from a given view, and prove its properties.› type_synonym view_path_elem = "(view_metadata × view_data) blindable × view list × view list" type_synonym view_path = "view_path_elem list" type_synonym view_zipper = "view_path × view" type_synonym view_path_elem⇩m = "(view_metadata⇩m ×⇩m view_data⇩m) × view⇩m list⇩m × view⇩m list⇩m" type_synonym view_path⇩m = "view_path_elem⇩m list" type_synonym view_zipper⇩m = "view_path⇩m × view⇩m" context begin interpretation view_merkle . lift_definition zipper_of_view :: "view ⇒ view_zipper" is zipper_of_tree . lift_definition view_of_zipper :: "view_zipper ⇒ view" is tree_of_zipper . lift_definition zipper_of_view⇩m :: "view⇩m ⇒ view_zipper⇩m" is zipper_of_tree⇩m . lift_definition view_of_zipper⇩m :: "view_zipper⇩m ⇒ view⇩m" is tree_of_zipper⇩m . lemma view_of_zipper⇩m_Nil [simp]: "view_of_zipper⇩m ([], t) = t" apply transfer (*goal: ‹view_of_zipper⇩m ([], t) = t›*) by simp lift_definition blind_view_path_elem :: "view_path_elem ⇒ view_path_elem⇩m" is "blind_path_elem embed_view_content hash_view_content" . lift_definition blind_view_path :: "view_path ⇒ view_path⇩m" is "blind_path embed_view_content hash_view_content" . lift_definition embed_view_path_elem :: "view_path_elem ⇒ view_path_elem⇩m" is "embed_path_elem embed_view_content" . lift_definition embed_view_path :: "view_path ⇒ view_path⇩m" is "embed_path embed_view_content" . lift_definition hash_view_path_elem :: "view_path_elem⇩m ⇒ (view_content⇩h × view⇩h list × view⇩h list)" is "hash_path_elem hash_view_content" . lift_definition zippers_view :: "view_zipper ⇒ view_zipper⇩m list" is "zippers_rose_tree embed_view_content hash_view_content" . lemma embed_view_path_Nil [simp]: "embed_view_path [] = []" apply transfer (*goal: ‹embed_view_path [] = []›*) by (simp add: embed_path_def (*‹embed_path ?embed_elem ≡ map (embed_path_elem ?embed_elem)›*)) lemma zippers_view_same_hash: assumes "z ∈ set (zippers_view (p, t))" shows "hash_view (view_of_zipper⇩m z) = hash_view (view_of_zipper⇩m (embed_view_path p, embed_view t))" using assms (*‹z ∈ set (zippers_view (p, t))›*) apply transfer (*goal: ‹hash_view (view_of_zipper⇩m z) = hash_view (view_of_zipper⇩m (embed_view_path p, embed_view t))›*) by (rule zippers_rose_tree_same_hash' (*‹?z ∈ set (zippers_rose_tree ?e ?h (?p, ?t)) ⟹ hash_tree ?h (tree_of_zipper⇩m ?z) = hash_tree ?h (tree_of_zipper⇩m (embed_path ?e ?p, embed_source_tree ?e ?t))›*)) lemma zippers_view_blinding_of: assumes "z ∈ set (zippers_view (p, t))" shows "blinding_of_view (view_of_zipper⇩m z) (view_of_zipper⇩m (blind_view_path p, embed_view t))" using assms (*‹z ∈ set (zippers_view (p, t))›*) apply transfer (*goal: ‹blinding_of_view (view_of_zipper⇩m (z::(((view_metadata, view_metadata) blindable⇩m × (view_data, view_data) blindable⇩m) × view⇩m list × view⇩m list) list × view⇩m)) (view_of_zipper⇩m (blind_view_path (p::((view_metadata × view_data) × view list × view list) list), embed_view (t::view)))›*) apply (rule zippers_rose_tree_blinding_of (*‹⟦blinding_of_on UNIV (?h::?'a ⇒ ?'b) (?bo::?'a ⇒ ?'a ⇒ bool); (?z::(?'a × (?'a, ?'b) rose_tree⇩m list × (?'a, ?'b) rose_tree⇩m list) list × (?'a, ?'b) rose_tree⇩m) ∈ set (zippers_rose_tree (?e::?'c ⇒ ?'a) ?h (?p::(?'c × ?'c rose_tree list × ?'c rose_tree list) list, ?t::?'c rose_tree))⟧ ⟹ blinding_of_tree ?h ?bo (tree_of_zipper⇩m ?z) (tree_of_zipper⇩m (blind_path ?e ?h ?p, embed_source_tree ?e ?t))›*)) (*goals: 1. ‹⋀z p t. z ∈ set (zippers_rose_tree embed_view_content (map_prod (hash_blindable id) (hash_blindable id)) (p, t)) ⟹ blinding_of_on UNIV (map_prod (hash_blindable id) (hash_blindable id)) (rel_prod (blinding_of_blindable id (=)) (blinding_of_blindable id (=)))› 2. ‹⋀z p t. z ∈ set (zippers_rose_tree embed_view_content (map_prod (hash_blindable id) (hash_blindable id)) (p, t)) ⟹ z ∈ set (zippers_rose_tree embed_view_content (map_prod (hash_blindable id) (hash_blindable id)) (p, t))› discuss goal 1*) apply unfold_locales (*discuss goal 2*) . (*proven 2 subgoals*) end primrec blind_view :: "view ⇒ view⇩m" where "blind_view (View vm vd subviews) = View⇩m (Blinded (Content ((Content vm, Content vd), map (hash_view ∘ embed_view) subviews)))" for subviews lemma hash_blind_view: "hash_view (blind_view view) = hash_view (embed_view view)" apply (cases view) (*goal: ‹hash_view (blind_view view) = hash_view (embed_view view)›*) by simp primrec blind_transaction :: "transaction ⇒ transaction⇩m" where "blind_transaction (Transaction cm pm views) = Transaction⇩m (Blinded (Content ((Content cm, Content pm), map (hash_view ∘ blind_view) views)))" for views lemma hash_blind_transaction: "hash_transaction (blind_transaction transaction) = hash_transaction (embed_transaction transaction)" apply (cases transaction) (*goal: ‹hash_transaction (blind_transaction transaction) = hash_transaction (embed_transaction transaction)›*) by (simp add: hash_blind_view (*‹hash_view (blind_view (?view::view)) = hash_view (embed_view ?view)›*)) typedecl participant consts recipients :: "view_metadata ⇒ participant list" fun view_recipients :: "view⇩m ⇒ participant set" where "view_recipients (View⇩m (Unblinded ((Unblinded vm, vd), subviews))) = set (recipients vm)" for subviews | "view_recipients _ = {}" ― ‹Sane default case› context fixes participant :: participant begin definition view_trees_for :: "view ⇒ view⇩m list" where "view_trees_for view = map view_of_zipper⇩m (filter (λ(_, t). participant ∈ view_recipients t) (zippers_view ([], view)))" primrec transaction_views_for :: "transaction ⇒ transaction⇩m list" where "transaction_views_for (Transaction cm pm views) = map (λview⇩m. Transaction⇩m (Unblinded ((Unblinded cm, Unblinded pm), view⇩m))) (concat (map (λ(l, v, r). map (λv⇩m. map blind_view l @ [v⇩m] @ map blind_view r) (view_trees_for v)) (splits views)))" for views lemma view_trees_for_same_hash: "vt ∈ set (view_trees_for view) ⟹ hash_view vt = hash_view (embed_view view)" by (auto simp add: view_trees_for_def (*‹local.view_trees_for ?view = map view_of_zipper⇩m (filter (λ(uu_, t). participant ∈ view_recipients t) (zippers_view ([], ?view)))›*) dest: zippers_view_same_hash (*‹?z ∈ set (zippers_view (?p, ?t)) ⟹ hash_view (view_of_zipper⇩m ?z) = hash_view (view_of_zipper⇩m (embed_view_path ?p, embed_view ?t))›*)) lemma transaction_views_for_same_hash: "t⇩m ∈ set (transaction_views_for t) ⟹ hash_transaction t⇩m = hash_transaction (embed_transaction t)" apply (cases t) (*goal: ‹(t⇩m::transaction⇩m) ∈ set (local.transaction_views_for (t::transaction)) ⟹ hash_transaction t⇩m = hash_transaction (embed_transaction t)›*) by (clarsimp simp add: splits_iff (*‹((?l, ?a, ?r) ∈ set (splits ?ll)) = (?ll = ?l @ ?a # ?r)›*) hash_blind_view (*‹hash_view (blind_view ?view) = hash_view (embed_view ?view)›*) view_trees_for_same_hash (*‹?vt ∈ set (local.view_trees_for ?view) ⟹ hash_view ?vt = hash_view (embed_view ?view)›*)) definition transaction_projection_for :: "transaction ⇒ transaction⇩m" where "transaction_projection_for t = (let tvs = transaction_views_for t in if tvs = [] then blind_transaction t else the (transaction.Merge (set tvs)))" lemma transaction_projection_for_same_hash: "hash_transaction (transaction_projection_for t) = hash_transaction (embed_transaction t)" proof (cases "transaction_views_for t = []") (*goals: 1. ‹local.transaction_views_for t = [] ⟹ hash_transaction (local.transaction_projection_for t) = hash_transaction (embed_transaction t)› 2. ‹local.transaction_views_for t ≠ [] ⟹ hash_transaction (local.transaction_projection_for t) = hash_transaction (embed_transaction t)›*) case True (*‹local.transaction_views_for t = []›*) thus "?thesis" (*goal: ‹hash_transaction (local.transaction_projection_for t) = hash_transaction (embed_transaction t)›*) by (simp add: transaction_projection_for_def (*‹local.transaction_projection_for (?t::transaction) = (let tvs::transaction⇩m list = local.transaction_views_for ?t in if tvs = [] then blind_transaction ?t else the (transaction.Merge (set tvs)))›*) Let_def (*‹Let (?s::?'a) (?f::?'a ⇒ ?'b) ≡ ?f ?s›*) hash_blind_transaction (*‹hash_transaction (blind_transaction (?transaction::transaction)) = hash_transaction (embed_transaction ?transaction)›*)) next (*goal: ‹local.transaction_views_for t ≠ [] ⟹ hash_transaction (local.transaction_projection_for t) = hash_transaction (embed_transaction t)›*) case False (*‹local.transaction_views_for t ≠ []›*) then have "transaction.Merge (set (transaction_views_for t)) ≠ None" apply (intro transaction.Merge_defined (*‹⟦finite ?A; ?A ≠ {}; ∀a∈?A. ∀b∈?A. hash_transaction a = hash_transaction b⟧ ⟹ transaction.Merge ?A ≠ None›*)) (*goals: 1. ‹local.transaction_views_for (t::transaction) ≠ [] ⟹ finite (set (local.transaction_views_for t))› 2. ‹local.transaction_views_for (t::transaction) ≠ [] ⟹ set (local.transaction_views_for t) ≠ {}› 3. ‹local.transaction_views_for (t::transaction) ≠ [] ⟹ ∀a::transaction⇩m∈set (local.transaction_views_for t). ∀b::transaction⇩m∈set (local.transaction_views_for t). hash_transaction a = hash_transaction b› discuss goal 1*) apply ((auto simp add: transaction_views_for_same_hash (*‹?t⇩m ∈ set (local.transaction_views_for ?t) ⟹ hash_transaction ?t⇩m = hash_transaction (embed_transaction ?t)›*))[1]) (*discuss goal 2*) apply ((auto simp add: transaction_views_for_same_hash (*‹?t⇩m ∈ set (local.transaction_views_for ?t) ⟹ hash_transaction ?t⇩m = hash_transaction (embed_transaction ?t)›*))[1]) (*discuss goal 3*) apply ((auto simp add: transaction_views_for_same_hash (*‹?t⇩m ∈ set (local.transaction_views_for ?t) ⟹ hash_transaction ?t⇩m = hash_transaction (embed_transaction ?t)›*))[1]) (*proven 3 subgoals*) . with False (*‹local.transaction_views_for t ≠ []›*) show "?thesis" (*goal: ‹hash_transaction (local.transaction_projection_for (t::transaction)) = hash_transaction (embed_transaction t)›*) apply (clarsimp simp add: transaction_projection_for_def (*‹local.transaction_projection_for (?t::transaction) = (let tvs::transaction⇩m list = local.transaction_views_for ?t in if tvs = [] then blind_transaction ?t else the (transaction.Merge (set tvs)))›*) neq_Nil_conv (*‹((?xs::?'a::type list) ≠ []) = (∃(y::?'a::type) ys::?'a::type list. ?xs = y # ys)›*) simp del: transaction.Merge_insert (*‹transaction.Merge (insert (?x::transaction⇩m) (?A::transaction⇩m set)) = (if ?A = {} then Some ?x else transaction.Merge ?A ⤜ merge_transaction ?x)›*)) (*goal: ‹hash_transaction (local.transaction_projection_for t) = hash_transaction (embed_transaction t)›*) apply (drule transaction.Merge_hash[symmetric] (*‹⟦transaction.Merge ?A = Some ?x; ?a ∈ ?A⟧ ⟹ hash_transaction ?x = hash_transaction ?a›*)) (*goals: 1. ‹⋀y ya ys. local.transaction_views_for t = y # ys ⟹ ?a5 y ya ys ∈ insert y (set ys)› 2. ‹⋀y ya ys. ⟦local.transaction_views_for t = y # ys; hash_transaction ya = hash_transaction (?a5 y ya ys)⟧ ⟹ hash_transaction ya = hash_transaction (embed_transaction t)› discuss goal 1*) apply blast (*discuss goal 2*) apply (auto intro: transaction_views_for_same_hash (*‹(?t⇩m::transaction⇩m) ∈ set (local.transaction_views_for (?t::transaction)) ⟹ hash_transaction ?t⇩m = hash_transaction (embed_transaction ?t)›*)) (*proven 2 subgoals*) . qed lemma transaction_projection_for_upper: assumes "t⇩m ∈ set (transaction_views_for t)" shows "blinding_of_transaction t⇩m (transaction_projection_for t)" proof (-) (*goal: ‹blinding_of_transaction t⇩m (local.transaction_projection_for t)›*) from assms (*‹t⇩m ∈ set (local.transaction_views_for t)›*) have "transaction.Merge (set (transaction_views_for t)) ≠ None" apply (intro transaction.Merge_defined (*‹⟦finite ?A; ?A ≠ {}; ∀a∈?A. ∀b∈?A. hash_transaction a = hash_transaction b⟧ ⟹ transaction.Merge ?A ≠ None›*)) (*goals: 1. ‹(t⇩m::transaction⇩m) ∈ set (local.transaction_views_for (t::transaction)) ⟹ finite (set (local.transaction_views_for t))› 2. ‹(t⇩m::transaction⇩m) ∈ set (local.transaction_views_for (t::transaction)) ⟹ set (local.transaction_views_for t) ≠ {}› 3. ‹(t⇩m::transaction⇩m) ∈ set (local.transaction_views_for (t::transaction)) ⟹ ∀a::transaction⇩m∈set (local.transaction_views_for t). ∀b::transaction⇩m∈set (local.transaction_views_for t). hash_transaction a = hash_transaction b› discuss goal 1*) apply ((auto simp add: transaction_views_for_same_hash (*‹?t⇩m ∈ set (local.transaction_views_for ?t) ⟹ hash_transaction ?t⇩m = hash_transaction (embed_transaction ?t)›*))[1]) (*discuss goal 2*) apply ((auto simp add: transaction_views_for_same_hash (*‹?t⇩m ∈ set (local.transaction_views_for ?t) ⟹ hash_transaction ?t⇩m = hash_transaction (embed_transaction ?t)›*))[1]) (*discuss goal 3*) apply ((auto simp add: transaction_views_for_same_hash (*‹?t⇩m ∈ set (local.transaction_views_for ?t) ⟹ hash_transaction ?t⇩m = hash_transaction (embed_transaction ?t)›*))[1]) (*proven 3 subgoals*) . with assms (*‹t⇩m ∈ set (local.transaction_views_for t)›*) show "?thesis" (*goal: ‹blinding_of_transaction (t⇩m::transaction⇩m) (local.transaction_projection_for (t::transaction))›*) by (auto simp add: transaction_projection_for_def (*‹local.transaction_projection_for ?t = (let tvs = local.transaction_views_for ?t in if tvs = [] then blind_transaction ?t else the (transaction.Merge (set tvs)))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) dest: transaction.Merge_upper (*‹⟦transaction.Merge ?A = Some ?x; ?y ∈ ?A⟧ ⟹ blinding_of_transaction ?y ?x›*)) qed end end
{ "path": "afp-2025-02-12/thys/ADS_Functor/Canton_Transaction_Tree.thy", "repo": "afp-2025-02-12", "sha": "77fc73202aed09c1f0c347b67304eec260d8e448298f579afb37f6bbb7538284" }
(* Author: Xingyuan Zhang, Chunhan Wu, Christian Urban *) theory Folds imports "Regular-Sets.Regular_Exp" begin section ‹``Summation'' for regular expressions› text ‹ To obtain equational system out of finite set of equivalence classes, a fold operation on finite sets ‹folds› is defined. The use of ‹SOME› makes ‹folds› more robust than the ‹fold› in the Isabelle library. The expression ‹folds f› makes sense when ‹f› is not ‹associative› and ‹commutitive›, while ‹fold f› does not. › definition folds :: "('a ⇒ 'b ⇒ 'b) ⇒ 'b ⇒ 'a set ⇒ 'b" where "folds f z S ≡ SOME x. fold_graph f z S x" text ‹Plus-combination for a set of regular expressions› abbreviation Setalt :: "'a rexp set ⇒ 'a rexp" ("⨄_" [1000] 999) where "⨄A ≡ folds Plus Zero A" text ‹ For finite sets, @{term Setalt} is preserved under @{term lang}. › lemma folds_plus_simp [simp]: fixes rs::"('a rexp) set" assumes a: "finite rs" shows "lang (⨄rs) = ⋃ (lang ` rs)" unfolding folds_def (*goal: ‹lang (SOME x::'a::type rexp. fold_graph Plus Zero (rs::'a::type rexp set) x) = ⋃ (lang ` rs)›*) apply (rule set_eqI (*‹(⋀x. (x ∈ ?A) = (x ∈ ?B)) ⟹ ?A = ?B›*)) (*goal: ‹lang (SOME x::'a rexp. fold_graph Plus Zero (rs::'a rexp set) x) = ⋃ (lang ` rs)›*) apply (rule someI2_ex (*‹⟦∃a::?'a. (?P::?'a ⇒ bool) a; ⋀x::?'a. ?P x ⟹ (?Q::?'a ⇒ bool) x⟧ ⟹ ?Q (SOME x::?'a. ?P x)›*)) (*goals: 1. ‹⋀x::'a list. ∃a::'a rexp. fold_graph Plus Zero (rs::'a rexp set) a› 2. ‹⋀(x::'a list) xa::'a rexp. fold_graph Plus Zero (rs::'a rexp set) xa ⟹ (x ∈ lang xa) = (x ∈ ⋃ (lang ` rs))› discuss goal 1*) apply (rule_tac finite_imp_fold_graph[OF a] (*‹∃x. fold_graph ?f ?z rs x›*)) (*discuss goal 2*) apply (erule fold_graph.induct (*‹⟦fold_graph ?f ?z ?x1.0 ?x2.0; ?P {} ?z; ⋀x A y. ⟦x ∉ A; fold_graph ?f ?z A y; ?P A y⟧ ⟹ ?P (insert x A) (?f x y)⟧ ⟹ ?P ?x1.0 ?x2.0›*)) (*goals: 1. ‹⋀x xa. (x ∈ lang Zero) = (x ∈ ⋃ (lang ` {}))› 2. ‹⋀x xa xb A y. ⟦xb ∉ A; fold_graph Plus Zero A y; (x ∈ lang y) = (x ∈ ⋃ (lang ` A))⟧ ⟹ (x ∈ lang (Plus xb y)) = (x ∈ ⋃ (lang ` insert xb A))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) . end
{ "path": "afp-2025-02-12/thys/Myhill-Nerode/Folds.thy", "repo": "afp-2025-02-12", "sha": "21c5436f8c60593dd180097bb3f2408059032cae269d6428acc96c80614a1ffc" }
(* Title: HOL/MicroJava/BV/Opt.thy Author: Tobias Nipkow Copyright 2000 TUM More about options. *) section ‹More about Options› theory Opt imports Err begin definition le :: "'a ord ⇒ 'a option ord" where "le r o₁ o₂ = (case o₂ of None ⇒ o₁=None | Some y ⇒ (case o₁ of None ⇒ True | Some x ⇒ x ⊑⇩r y))" definition opt :: "'a set ⇒ 'a option set" where "opt A = insert None {Some y |y. y ∈ A}" definition sup :: "'a ebinop ⇒ 'a option ebinop" where "sup f o₁ o₂ = (case o₁ of None ⇒ OK o₂ | Some x ⇒ (case o₂ of None ⇒ OK o₁ | Some y ⇒ (case f x y of Err ⇒ Err | OK z ⇒ OK (Some z))))" definition esl :: "'a esl ⇒ 'a option esl" where "esl = (λ(A,r,f). (opt A, le r, sup f))" lemma unfold_le_opt: "o₁ ⊑⇘le r⇙ o₂ = (case o₂ of None ⇒ o₁=None | Some y ⇒ (case o₁ of None ⇒ True | Some x ⇒ x ⊑⇩r y))" (*<*) apply (unfold lesub_def (*‹(?x ⊑⇘?r⇙ ?y) = ?r ?x ?y›*) le_def (*‹Opt.le ?r ?o₁ ?o₂ = (case ?o₂ of None ⇒ ?o₁ = None | Some y ⇒ case ?o₁ of None ⇒ True | Some x ⇒ x ⊑⇘?r⇙ y)›*)) (*goal: ‹(o₁ ⊑⇘Opt.le r⇙ o₂) = (case o₂ of None ⇒ o₁ = None | Some y ⇒ case o₁ of None ⇒ True | Some x ⇒ x ⊑⇘r⇙ y)›*) by (rule refl (*‹?t = ?t›*)) (*>*) lemma le_opt_refl: "order r ⟹ x ⊑⇘le r⇙ x" (*<*) by (simp add: unfold_le_opt (*‹(?o₁ ⊑⇘Opt.le ?r⇙ ?o₂) = (case ?o₂ of None ⇒ ?o₁ = None | Some y ⇒ case ?o₁ of None ⇒ True | Some x ⇒ x ⊑⇘?r⇙ y)›*) split: option.split (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))›*)) (*<*) lemma le_opt_trans [rule_format]: "order r ⟹ x ⊑⇘le r⇙ y ⟶ y ⊑⇘le r⇙ z ⟶ x ⊑⇘le r⇙ z" (*<*) apply (simp add: unfold_le_opt (*‹(?o₁ ⊑⇘Opt.le ?r⇙ ?o₂) = (case ?o₂ of None ⇒ ?o₁ = None | Some y ⇒ case ?o₁ of None ⇒ True | Some x ⇒ x ⊑⇘?r⇙ y)›*) split: option.split (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))›*)) (*goal: ‹order r ⟹ x ⊑⇘Opt.le r⇙ y ⟶ y ⊑⇘Opt.le r⇙ z ⟶ x ⊑⇘Opt.le r⇙ z›*) by (blast intro: order_trans (*‹⟦order ?r; ?x ⊑⇘?r⇙ ?y; ?y ⊑⇘?r⇙ ?z⟧ ⟹ ?x ⊑⇘?r⇙ ?z›*)) (*>*) lemma le_opt_antisym [rule_format]: "order r ⟹ x ⊑⇘le r⇙ y ⟶ y ⊑⇘le r⇙ x ⟶ x=y" (*<*) apply (simp add: unfold_le_opt (*‹(?o₁ ⊑⇘Opt.le ?r⇙ ?o₂) = (case ?o₂ of None ⇒ ?o₁ = None | Some y ⇒ case ?o₁ of None ⇒ True | Some x ⇒ x ⊑⇘?r⇙ y)›*) split: option.split (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))›*)) (*goal: ‹order r ⟹ x ⊑⇘Opt.le r⇙ y ⟶ y ⊑⇘Opt.le r⇙ x ⟶ x = y›*) by (blast intro: order_antisym (*‹⟦order ?r; ?x ⊑⇘?r⇙ ?y; ?y ⊑⇘?r⇙ ?x⟧ ⟹ ?x = ?y›*)) (*>*) lemma order_le_opt [intro!,simp]: "order r ⟹ order(le r)" (*<*) apply (subst order_def (*‹order ?r = ((∀x. x ⊑⇘?r⇙ x) ∧ (∀x y. x ⊑⇘?r⇙ y ∧ y ⊑⇘?r⇙ x ⟶ x = y) ∧ (∀x y z. x ⊑⇘?r⇙ y ∧ y ⊑⇘?r⇙ z ⟶ x ⊑⇘?r⇙ z))›*)) (*goal: ‹order r ⟹ order (Opt.le r)›*) by (blast intro: le_opt_refl (*‹order ?r ⟹ ?x ⊑⇘Opt.le ?r⇙ ?x›*) le_opt_trans (*‹⟦order ?r; ?x ⊑⇘Opt.le ?r⇙ ?y; ?y ⊑⇘Opt.le ?r⇙ ?z⟧ ⟹ ?x ⊑⇘Opt.le ?r⇙ ?z›*) le_opt_antisym (*‹⟦order ?r; ?x ⊑⇘Opt.le ?r⇙ ?y; ?y ⊑⇘Opt.le ?r⇙ ?x⟧ ⟹ ?x = ?y›*)) (*>*) lemma None_bot [iff]: "None ⊑⇘le r⇙ ox" (*<*) apply (unfold lesub_def (*‹((?x::?'a) ⊑⇘?r::?'a ⇒ ?'a ⇒ bool⇙ (?y::?'a)) = ?r ?x ?y›*) le_def (*‹Opt.le (?r::?'a ⇒ ?'a ⇒ bool) (?o₁::?'a option) (?o₂::?'a option) = (case ?o₂ of None ⇒ ?o₁ = None | Some (y::?'a) ⇒ case ?o₁ of None ⇒ True | Some (x::?'a) ⇒ x ⊑⇘?r⇙ y)›*)) (*goal: ‹None ⊑⇘Opt.le r⇙ ox›*) by (simp split: option.split (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))›*)) (*>*) lemma Some_le [iff]: "(Some x ⊑⇘le r⇙ z) = (∃y. z = Some y ∧ x ⊑⇩r y)" (*<*) apply (unfold lesub_def (*‹(?x ⊑⇘?r⇙ ?y) = ?r ?x ?y›*) le_def (*‹Opt.le ?r ?o₁ ?o₂ = (case ?o₂ of None ⇒ ?o₁ = None | Some y ⇒ case ?o₁ of None ⇒ True | Some x ⇒ x ⊑⇘?r⇙ y)›*)) (*goal: ‹(Some (x::'a) ⊑⇘Opt.le (r::'a ⇒ 'a ⇒ bool)⇙ (z::'a option)) = (∃y::'a. z = Some y ∧ x ⊑⇘r⇙ y)›*) by (simp split: option.split (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))›*)) (*>*) lemma le_None [iff]: "(x ⊑⇘le r⇙ None) = (x = None)" (*<*) apply (unfold lesub_def (*‹((?x::?'a) ⊑⇘?r::?'a ⇒ ?'a ⇒ bool⇙ (?y::?'a)) = ?r ?x ?y›*) le_def (*‹Opt.le (?r::?'a ⇒ ?'a ⇒ bool) (?o₁::?'a option) (?o₂::?'a option) = (case ?o₂ of None ⇒ ?o₁ = None | Some (y::?'a) ⇒ case ?o₁ of None ⇒ True | Some (x::?'a) ⇒ x ⊑⇘?r⇙ y)›*)) (*goal: ‹(x ⊑⇘Opt.le r⇙ None) = (x = None)›*) by (simp split: option.split (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))›*)) (*>*) lemma OK_None_bot [iff]: "OK None ⊑⇘Err.le (le r)⇙ x" (*<*) by (simp add: lesub_def (*‹(?x ⊑⇘?r⇙ ?y) = ?r ?x ?y›*) Err.le_def (*‹Err.le ?r ?e₁ ?e₂ = (case ?e₂ of Err ⇒ True | OK y ⇒ case ?e₁ of Err ⇒ False | OK x ⇒ x ⊑⇘?r⇙ y)›*) le_def (*‹Opt.le ?r ?o₁ ?o₂ = (case ?o₂ of None ⇒ ?o₁ = None | Some y ⇒ case ?o₁ of None ⇒ True | Some x ⇒ x ⊑⇘?r⇙ y)›*) split: option.split (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))›*) err.split (*‹?P (case ?err of Err ⇒ ?f1.0 | OK x ⇒ ?f2.0 x) = ((?err = Err ⟶ ?P ?f1.0) ∧ (∀x2. ?err = OK x2 ⟶ ?P (?f2.0 x2)))›*)) (*>*) lemma sup_None1 [iff]: "x ⊔⇘sup f⇙ None = OK x" (*<*) by (simp add: plussub_def (*‹(?x::?'a) ⊔⇘?f::?'a ⇒ ?'b ⇒ ?'c⇙ (?y::?'b) = ?f ?x ?y›*) sup_def (*‹Opt.sup (?f::?'a ⇒ ?'a ⇒ ?'a err) (?o₁::?'a option) (?o₂::?'a option) = (case ?o₁ of None ⇒ OK ?o₂ | Some (x::?'a) ⇒ case ?o₂ of None ⇒ OK ?o₁ | Some (y::?'a) ⇒ case ?f x y of Err ⇒ Err | OK (z::?'a) ⇒ OK (Some z))›*) split: option.split (*‹(?P::?'b ⇒ bool) (case ?option::?'a option of None ⇒ ?f1.0::?'b | Some (x::?'a) ⇒ (?f2.0::?'a ⇒ ?'b) x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2::?'a. ?option = Some x2 ⟶ ?P (?f2.0 x2)))›*)) (*>*) lemma sup_None2 [iff]: "None ⊔⇘sup f⇙ x = OK x" (*<*) by (simp add: plussub_def (*‹?x ⊔⇘?f⇙ ?y = ?f ?x ?y›*) sup_def (*‹Opt.sup ?f ?o₁ ?o₂ = (case ?o₁ of None ⇒ OK ?o₂ | Some x ⇒ case ?o₂ of None ⇒ OK ?o₁ | Some y ⇒ case ?f x y of Err ⇒ Err | OK z ⇒ OK (Some z))›*) split: option.split (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))›*)) (*>*) lemma None_in_opt [iff]: "None ∈ opt A" (*<*) by (simp add: opt_def (*‹opt ?A = insert None {Some y |y. y ∈ ?A}›*)) (*>*) lemma Some_in_opt [iff]: "(Some x ∈ opt A) = (x ∈ A)" (*<*) apply (unfold opt_def (*‹opt ?A = insert None {Some y |y. y ∈ ?A}›*)) (*goal: ‹(Some x ∈ opt A) = (x ∈ A)›*) by auto (*>*) lemma semilat_opt [intro, simp]: "err_semilat L ⟹ err_semilat (Opt.esl L)" (*<*) proof (-) (*goal: ‹err_semilat (L::'a::type set × ('a::type ⇒ 'a::type ⇒ bool) × ('a::type ⇒ 'a::type ⇒ 'a::type err)) ⟹ err_semilat (Opt.esl L)›*) assume s: "err_semilat L" (*‹err_semilat (L::'a set × ('a ⇒ 'a ⇒ bool) × ('a ⇒ 'a ⇒ 'a err))›*) obtain A and r and f where [simp]: "L = (A,r,f)" (*goal: ‹(⋀A r f. L = (A, r, f) ⟹ thesis) ⟹ thesis›*) by (cases L) let ?A0 = "err A" and ?r0 = "Err.le r" and ?f0 = "lift2 f" from s (*‹err_semilat L›*) obtain ord: "order ?r0" and clo: "closed ?A0 ?f0" and ub1: "∀x∈?A0. ∀y∈?A0. x ⊑⇘?r0⇙ x ⊔⇘?f0⇙ y" and ub2: "∀x∈?A0. ∀y∈?A0. y ⊑⇘?r0⇙ x ⊔⇘?f0⇙ y" and lub: "∀x∈?A0. ∀y∈?A0. ∀z∈?A0. x ⊑⇘?r0⇙ z ∧ y ⊑⇘?r0⇙ z ⟶ x ⊔⇘?f0⇙ y ⊑⇘?r0⇙ z" (*goal: ‹(⟦order (Err.le r); closed (err A) (lift2 f); ∀x∈err A. ∀y∈err A. x ⊑⇘Err.le r⇙ x ⊔⇘lift2 f⇙ y; ∀x∈err A. ∀y∈err A. y ⊑⇘Err.le r⇙ x ⊔⇘lift2 f⇙ y; ∀x∈err A. ∀y∈err A. ∀z∈err A. x ⊑⇘Err.le r⇙ z ∧ y ⊑⇘Err.le r⇙ z ⟶ x ⊔⇘lift2 f⇙ y ⊑⇘Err.le r⇙ z⟧ ⟹ thesis) ⟹ thesis›*) apply (unfold semilat_def (*‹semilat = (λ(A::?'a set, r::?'a ⇒ ?'a ⇒ bool, f::?'a ⇒ ?'a ⇒ ?'a). order r ∧ closed A f ∧ (∀x::?'a∈A. ∀y::?'a∈A. x ⊑⇘r⇙ x ⊔⇘f⇙ y) ∧ (∀x::?'a∈A. ∀y::?'a∈A. y ⊑⇘r⇙ x ⊔⇘f⇙ y) ∧ (∀x::?'a∈A. ∀y::?'a∈A. ∀z::?'a∈A. x ⊑⇘r⇙ z ∧ y ⊑⇘r⇙ z ⟶ x ⊔⇘f⇙ y ⊑⇘r⇙ z))›*) sl_def (*‹sl = (λ(A::?'a set, r::?'a ⇒ ?'a ⇒ bool, f::?'a ⇒ ?'a ⇒ ?'a err). (err A, Err.le r, lift2 f))›*)) (*goal: ‹(⟦order (Err.le r); closed (err A) (lift2 f); ∀x∈err A. ∀y∈err A. x ⊑⇘Err.le r⇙ x ⊔⇘lift2 f⇙ y; ∀x∈err A. ∀y∈err A. y ⊑⇘Err.le r⇙ x ⊔⇘lift2 f⇙ y; ∀x∈err A. ∀y∈err A. ∀z∈err A. x ⊑⇘Err.le r⇙ z ∧ y ⊑⇘Err.le r⇙ z ⟶ x ⊔⇘lift2 f⇙ y ⊑⇘Err.le r⇙ z⟧ ⟹ thesis) ⟹ thesis›*) by simp let ?A = "err (opt A)" and ?r = "Err.le (Opt.le r)" and ?f = "lift2 (Opt.sup f)" from ord (*‹order (Err.le r)›*) have "order ?r" by simp moreover have "closed ?A ?f" apply (unfold closed_def (*‹closed ?A ?f = (∀x∈?A. ∀y∈?A. x ⊔⇘?f⇙ y ∈ ?A)›*)) (*goal: ‹closed (err (opt A)) (lift2 (Opt.sup f))›*) proof (intro strip (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q› ‹(⋀x. ?P x) ⟹ ∀x. ?P x› ‹(⋀x. x ∈ ?A ⟹ ?P x) ⟹ ∀x∈?A. ?P x›*)) (*goal: ‹⋀x y. ⟦x ∈ err (opt A); y ∈ err (opt A)⟧ ⟹ x ⊔⇘lift2 (Opt.sup f)⇙ y ∈ err (opt A)›*) fix x and y assume x: "x ∈ ?A" and y: "y ∈ ?A" (*‹(x::'a option err) ∈ err (opt (A::'a set))› ‹(y::'a option err) ∈ err (opt (A::'a set))›*) { fix a and b assume ab: "x = OK a" "y = OK b" (*‹(x::'a option err) = OK (a::'a option)› ‹(y::'a option err) = OK (b::'a option)›*) with x (*‹x ∈ err (opt A)›*) have a: "⋀c. a = Some c ⟹ c ∈ A" by (clarsimp simp add: opt_def (*‹opt ?A = insert None {Some y |y. y ∈ ?A}›*)) from ab (*‹(x::'a option err) = OK (a::'a option)› ‹y = OK b›*) y (*‹y ∈ err (opt A)›*) have b: "⋀d. b = Some d ⟹ d ∈ A" by (clarsimp simp add: opt_def (*‹opt ?A = insert None {Some y |y. y ∈ ?A}›*)) { fix c and d assume "a = Some c" "b = Some d" (*‹(a::'a option) = Some (c::'a)› ‹(b::'a option) = Some (d::'a)›*) with ab (*‹x = OK a› ‹y = OK b›*) x (*‹x ∈ err (opt A)›*) y (*‹(y::'a option err) ∈ err (opt (A::'a set))›*) have "c ∈ A & d ∈ A" by (simp add: err_def (*‹err (?A::?'a set) = insert Err {OK x |x::?'a. x ∈ ?A}›*) opt_def (*‹opt (?A::?'a set) = insert None {Some y |y::?'a. y ∈ ?A}›*) Bex_def (*‹Bex (?A::?'a set) (?P::?'a ⇒ bool) = (∃x::?'a. x ∈ ?A ∧ ?P x)›*)) with clo (*‹closed (err A) (lift2 f)›*) have "f c d ∈ err A" by (simp add: closed_def (*‹closed ?A ?f = (∀x∈?A. ∀y∈?A. x ⊔⇘?f⇙ y ∈ ?A)›*) plussub_def (*‹?x ⊔⇘?f⇙ ?y = ?f ?x ?y›*) err_def' (*‹err ?A = insert Err {x. ∃y∈?A. x = OK y}›*) lift2_def (*‹lift2 ?f ?e₁ ?e₂ = (case ?e₁ of Err ⇒ Err | OK x ⇒ case ?e₂ of Err ⇒ Err | OK y ⇒ ?f x y)›*)) moreover fix z assume "f c d = OK z" (*‹(f::'a ⇒ 'a ⇒ 'a err) (c::'a) (d::'a) = OK (z::'a)›*) ultimately have "z ∈ A" by simp } note f_closed = this (*‹⟦a = Some ?c2; b = Some ?d2; f ?c2 ?d2 = OK ?z2⟧ ⟹ ?z2 ∈ A›*) have "sup f a b ∈ ?A" proof (cases a) (*goals: 1. ‹a = None ⟹ Opt.sup f a b ∈ err (opt A)› 2. ‹⋀aa. a = Some aa ⟹ Opt.sup f a b ∈ err (opt A)›*) case None (*‹a = None›*) thus "?thesis" (*goal: ‹Opt.sup f a b ∈ err (opt A)›*) apply (simp add: sup_def (*‹Opt.sup (?f::?'a ⇒ ?'a ⇒ ?'a err) (?o₁::?'a option) (?o₂::?'a option) = (case ?o₁ of None ⇒ OK ?o₂ | Some (x::?'a) ⇒ case ?o₂ of None ⇒ OK ?o₁ | Some (y::?'a) ⇒ case ?f x y of Err ⇒ Err | OK (z::?'a) ⇒ OK (Some z))›*) opt_def (*‹opt (?A::?'a set) = insert None {Some y |y::?'a. y ∈ ?A}›*)) (*goal: ‹Opt.sup f a b ∈ err (opt A)›*) apply (cases b) (*goals: 1. ‹⟦a = None; b = None⟧ ⟹ b = None ∨ (∃y. b = Some y ∧ y ∈ A)› 2. ‹⋀aa. ⟦a = None; b = Some aa⟧ ⟹ b = None ∨ (∃y. b = Some y ∧ y ∈ A)› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add: b (*‹b = Some ?d ⟹ ?d ∈ A›*) Bex_def (*‹Bex ?A ?P = (∃x. x ∈ ?A ∧ ?P x)›*)) (*proven 2 subgoals*) . next (*goal: ‹⋀aa. a = Some aa ⟹ Opt.sup f a b ∈ err (opt A)›*) case Some (*‹a = Some a_›*) thus "?thesis" (*goal: ‹Opt.sup f a b ∈ err (opt A)›*) by (auto simp add: sup_def (*‹Opt.sup ?f ?o₁ ?o₂ = (case ?o₁ of None ⇒ OK ?o₂ | Some x ⇒ case ?o₂ of None ⇒ OK ?o₁ | Some y ⇒ case ?f x y of Err ⇒ Err | OK z ⇒ OK (Some z))›*) opt_def (*‹opt ?A = insert None {Some y |y. y ∈ ?A}›*) Bex_def (*‹Bex ?A ?P = (∃x. x ∈ ?A ∧ ?P x)›*) a (*‹a = Some ?c ⟹ ?c ∈ A›*) b (*‹b = Some ?d ⟹ ?d ∈ A›*) f_closed (*‹⟦a = Some ?c2; b = Some ?d2; f ?c2 ?d2 = OK ?z2⟧ ⟹ ?z2 ∈ A›*) split: err.split (*‹?P (case ?err of Err ⇒ ?f1.0 | OK x ⇒ ?f2.0 x) = ((?err = Err ⟶ ?P ?f1.0) ∧ (∀x2. ?err = OK x2 ⟶ ?P (?f2.0 x2)))›*) option.split (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))›*)) qed } thus "x ⊔⇘?f⇙ y ∈ ?A" by (simp add: plussub_def (*‹?x ⊔⇘?f⇙ ?y = ?f ?x ?y›*) lift2_def (*‹lift2 ?f ?e₁ ?e₂ = (case ?e₁ of Err ⇒ Err | OK x ⇒ case ?e₂ of Err ⇒ Err | OK y ⇒ ?f x y)›*) split: err.split (*‹?P (case ?err of Err ⇒ ?f1.0 | OK x ⇒ ?f2.0 x) = ((?err = Err ⟶ ?P ?f1.0) ∧ (∀x2. ?err = OK x2 ⟶ ?P (?f2.0 x2)))›*)) qed moreover { fix a and b and c assume "a ∈ opt A" and "b ∈ opt A" and "a ⊔⇘sup f⇙ b = OK c" (*‹(a::'a option) ∈ opt (A::'a set)› ‹(b::'a option) ∈ opt (A::'a set)› ‹(a::'a option) ⊔⇘Opt.sup (f::'a ⇒ 'a ⇒ 'a err)⇙ (b::'a option) = OK (c::'a option)›*) moreover from ord (*‹order (Err.le r)›*) have "order r" by simp moreover { fix x and y and z assume "x ∈ A" and "y ∈ A" (*‹(x::'a) ∈ (A::'a set)› ‹(y::'a) ∈ (A::'a set)›*) hence "OK x ∈ err A ∧ OK y ∈ err A" by simp with ub1 (*‹∀x::'a err∈err (A::'a set). ∀y::'a err∈err A. x ⊑⇘Err.le (r::'a ⇒ 'a ⇒ bool)⇙ x ⊔⇘lift2 (f::'a ⇒ 'a ⇒ 'a err)⇙ y›*) ub2 (*‹∀x::'a err∈err (A::'a set). ∀y::'a err∈err A. y ⊑⇘Err.le (r::'a ⇒ 'a ⇒ bool)⇙ x ⊔⇘lift2 (f::'a ⇒ 'a ⇒ 'a err)⇙ y›*) have "(OK x) ⊑⇘Err.le r⇙ (OK x) ⊔⇘lift2 f⇙ (OK y) ∧ (OK y) ⊑⇘Err.le r⇙ (OK x) ⊔⇘lift2 f⇙ (OK y)" by blast moreover assume "x ⊔⇩f y = OK z" (*‹(x::'a) ⊔⇘f::'a ⇒ 'a ⇒ 'a err⇙ (y::'a) = OK (z::'a)›*) ultimately have "x ⊑⇩r z ∧ y ⊑⇩r z" by (auto simp add: plussub_def (*‹(?x::?'a) ⊔⇘?f::?'a ⇒ ?'b ⇒ ?'c⇙ (?y::?'b) = ?f ?x ?y›*) lift2_def (*‹lift2 (?f::?'a ⇒ ?'b ⇒ ?'c err) (?e₁::?'a err) (?e₂::?'b err) = (case ?e₁ of Err ⇒ Err | OK (x::?'a) ⇒ case ?e₂ of Err ⇒ Err | OK (y::?'b) ⇒ ?f x y)›*) Err.le_def (*‹Err.le (?r::?'a ⇒ ?'a ⇒ bool) (?e₁::?'a err) (?e₂::?'a err) = (case ?e₂ of Err ⇒ True | OK (y::?'a) ⇒ case ?e₁ of Err ⇒ False | OK (x::?'a) ⇒ x ⊑⇘?r⇙ y)›*) lesub_def (*‹((?x::?'a) ⊑⇘?r::?'a ⇒ ?'a ⇒ bool⇙ (?y::?'a)) = ?r ?x ?y›*)) } ultimately have "a ⊑⇘le r⇙ c ∧ b ⊑⇘le r⇙ c" by (auto simp add: sup_def (*‹Opt.sup (?f::?'a ⇒ ?'a ⇒ ?'a err) (?o₁::?'a option) (?o₂::?'a option) = (case ?o₁ of None ⇒ OK ?o₂ | Some (x::?'a) ⇒ case ?o₂ of None ⇒ OK ?o₁ | Some (y::?'a) ⇒ case ?f x y of Err ⇒ Err | OK (z::?'a) ⇒ OK (Some z))›*) le_def (*‹Opt.le (?r::?'a ⇒ ?'a ⇒ bool) (?o₁::?'a option) (?o₂::?'a option) = (case ?o₂ of None ⇒ ?o₁ = None | Some (y::?'a) ⇒ case ?o₁ of None ⇒ True | Some (x::?'a) ⇒ x ⊑⇘?r⇙ y)›*) lesub_def (*‹((?x::?'a) ⊑⇘?r::?'a ⇒ ?'a ⇒ bool⇙ (?y::?'a)) = ?r ?x ?y›*) plussub_def (*‹(?x::?'a) ⊔⇘?f::?'a ⇒ ?'b ⇒ ?'c⇙ (?y::?'b) = ?f ?x ?y›*) dest: order_refl (*‹order (?r::?'a ⇒ ?'a ⇒ bool) ⟹ (?x::?'a) ⊑⇘?r⇙ ?x›*) split: option.splits (*‹(?P::?'b ⇒ bool) (case ?option::?'a option of None ⇒ ?f1.0::?'b | Some (x::?'a) ⇒ (?f2.0::?'a ⇒ ?'b) x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2::?'a. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹(?P::?'b ⇒ bool) (case ?option::?'a option of None ⇒ ?f1.0::?'b | Some (x::?'a) ⇒ (?f2.0::?'a ⇒ ?'b) x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2::?'a. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) err.splits (*‹(?P::?'b ⇒ bool) (case ?err::?'a err of Err ⇒ ?f1.0::?'b | OK (x::?'a) ⇒ (?f2.0::?'a ⇒ ?'b) x) = ((?err = Err ⟶ ?P ?f1.0) ∧ (∀x2::?'a. ?err = OK x2 ⟶ ?P (?f2.0 x2)))› ‹(?P::?'b ⇒ bool) (case ?err::?'a err of Err ⇒ ?f1.0::?'b | OK (x::?'a) ⇒ (?f2.0::?'a ⇒ ?'b) x) = (¬ (?err = Err ∧ ¬ ?P ?f1.0 ∨ (∃x2::?'a. ?err = OK x2 ∧ ¬ ?P (?f2.0 x2))))›*)) } hence "(∀x∈?A. ∀y∈?A. x ⊑⇘?r⇙ x ⊔⇘?f⇙ y) ∧ (∀x∈?A. ∀y∈?A. y ⊑⇘?r⇙ x ⊔⇘?f⇙ y)" by (auto simp add: lesub_def (*‹(?x ⊑⇘?r⇙ ?y) = ?r ?x ?y›*) plussub_def (*‹?x ⊔⇘?f⇙ ?y = ?f ?x ?y›*) Err.le_def (*‹Err.le ?r ?e₁ ?e₂ = (case ?e₂ of Err ⇒ True | OK y ⇒ case ?e₁ of Err ⇒ False | OK x ⇒ x ⊑⇘?r⇙ y)›*) lift2_def (*‹lift2 ?f ?e₁ ?e₂ = (case ?e₁ of Err ⇒ Err | OK x ⇒ case ?e₂ of Err ⇒ Err | OK y ⇒ ?f x y)›*) split: err.split (*‹?P (case ?err of Err ⇒ ?f1.0 | OK x ⇒ ?f2.0 x) = ((?err = Err ⟶ ?P ?f1.0) ∧ (∀x2. ?err = OK x2 ⟶ ?P (?f2.0 x2)))›*)) moreover have "∀x∈?A. ∀y∈?A. ∀z∈?A. x ⊑⇘?r⇙ z ∧ y ⊑⇘?r⇙ z ⟶ x ⊔⇘?f⇙ y ⊑⇘?r⇙ z" apply (intro strip (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q› ‹(⋀x. ?P x) ⟹ ∀x. ?P x› ‹(⋀x. x ∈ ?A ⟹ ?P x) ⟹ ∀x∈?A. ?P x›*)) (*goal: ‹∀x::'a option err∈err (opt (A::'a set)). ∀y::'a option err∈err (opt A). ∀z::'a option err∈err (opt A). x ⊑⇘Err.le (Opt.le (r::'a ⇒ 'a ⇒ bool))⇙ z ∧ y ⊑⇘Err.le (Opt.le r)⇙ z ⟶ x ⊔⇘lift2 (Opt.sup (f::'a ⇒ 'a ⇒ 'a err))⇙ y ⊑⇘Err.le (Opt.le r)⇙ z›*) proof (elim conjE (*‹⟦?P ∧ ?Q; ⟦?P; ?Q⟧ ⟹ ?R⟧ ⟹ ?R›*)) (*goal: ‹⋀(x::'a::type option err) (y::'a::type option err) z::'a::type option err. ⟦x ∈ err (opt (A::'a::type set)); y ∈ err (opt A); z ∈ err (opt A); x ⊑⇘Err.le (Opt.le (r::'a::type ⇒ 'a::type ⇒ bool))⇙ z; y ⊑⇘Err.le (Opt.le r)⇙ z⟧ ⟹ x ⊔⇘lift2 (Opt.sup (f::'a::type ⇒ 'a::type ⇒ 'a::type err))⇙ y ⊑⇘Err.le (Opt.le r)⇙ z›*) fix x and y and z assume xyz: "x ∈ ?A" "y ∈ ?A" "z ∈ ?A" (*‹(x::'a option err) ∈ err (opt (A::'a set))› ‹(y::'a option err) ∈ err (opt (A::'a set))› ‹(z::'a option err) ∈ err (opt (A::'a set))›*) assume xz: "x ⊑⇘?r⇙ z" and yz: "y ⊑⇘?r⇙ z" (*‹(x::'a option err) ⊑⇘Err.le (Opt.le (r::'a ⇒ 'a ⇒ bool))⇙ (z::'a option err)› ‹(y::'a option err) ⊑⇘Err.le (Opt.le (r::'a ⇒ 'a ⇒ bool))⇙ (z::'a option err)›*) { fix a and b and c assume ok: "x = OK a" "y = OK b" "z = OK c" (*‹(x::'a option err) = OK (a::'a option)› ‹(y::'a option err) = OK (b::'a option)› ‹(z::'a option err) = OK (c::'a option)›*) { fix d and e and g assume some: "a = Some d" "b = Some e" "c = Some g" (*‹(a::'a option) = Some (d::'a)› ‹(b::'a option) = Some (e::'a)› ‹(c::'a option) = Some (g::'a)›*) with ok (*‹x = OK a› ‹y = OK b› ‹z = OK c›*) xyz (*‹x ∈ err (opt A)› ‹(y::'a option err) ∈ err (opt (A::'a set))› ‹z ∈ err (opt A)›*) obtain "OK d:err A" "OK e:err A" "OK g:err A" (*goal: ‹(⟦OK d ∈ err A; OK e ∈ err A; OK g ∈ err A⟧ ⟹ thesis) ⟹ thesis›*) by simp with lub (*‹∀x::'a::type err∈err (A::'a::type set). ∀y::'a::type err∈err A. ∀z::'a::type err∈err A. x ⊑⇘Err.le (r::'a::type ⇒ 'a::type ⇒ bool)⇙ z ∧ y ⊑⇘Err.le r⇙ z ⟶ x ⊔⇘lift2 (f::'a::type ⇒ 'a::type ⇒ 'a::type err)⇙ y ⊑⇘Err.le r⇙ z›*) have "⟦ OK d ⊑⇘Err.le r⇙ OK g; OK e ⊑⇘Err.le r⇙ OK g ⟧ ⟹ OK d ⊔⇘lift2 f⇙ OK e ⊑⇘Err.le r⇙ OK g" by blast hence "⟦ d ⊑⇩r g; e ⊑⇩r g ⟧ ⟹ ∃y. d ⊔⇩f e = OK y ∧ y ⊑⇩r g" by simp with ok (*‹x = OK a› ‹(y::'a::type option err) = OK (b::'a::type option)› ‹(z::'a option err) = OK (c::'a option)›*) some (*‹a = Some d› ‹(b::'a option) = Some (e::'a)› ‹c = Some g›*) xyz (*‹x ∈ err (opt A)› ‹y ∈ err (opt A)› ‹z ∈ err (opt A)›*) xz (*‹(x::'a option err) ⊑⇘Err.le (Opt.le (r::'a ⇒ 'a ⇒ bool))⇙ (z::'a option err)›*) yz (*‹y ⊑⇘Err.le (Opt.le r)⇙ z›*) have "x ⊔⇘?f⇙ y ⊑⇘?r⇙ z" by (auto simp add: sup_def (*‹Opt.sup ?f ?o₁ ?o₂ = (case ?o₁ of None ⇒ OK ?o₂ | Some x ⇒ case ?o₂ of None ⇒ OK ?o₁ | Some y ⇒ case ?f x y of Err ⇒ Err | OK z ⇒ OK (Some z))›*) le_def (*‹Opt.le ?r ?o₁ ?o₂ = (case ?o₂ of None ⇒ ?o₁ = None | Some y ⇒ case ?o₁ of None ⇒ True | Some x ⇒ x ⊑⇘?r⇙ y)›*) lesub_def (*‹(?x ⊑⇘?r⇙ ?y) = ?r ?x ?y›*) lift2_def (*‹lift2 ?f ?e₁ ?e₂ = (case ?e₁ of Err ⇒ Err | OK x ⇒ case ?e₂ of Err ⇒ Err | OK y ⇒ ?f x y)›*) plussub_def (*‹?x ⊔⇘?f⇙ ?y = ?f ?x ?y›*) Err.le_def (*‹Err.le ?r ?e₁ ?e₂ = (case ?e₂ of Err ⇒ True | OK y ⇒ case ?e₁ of Err ⇒ False | OK x ⇒ x ⊑⇘?r⇙ y)›*)) } note this[intro !] (*‹⟦a = Some ?d2; b = Some ?e2; c = Some ?g2⟧ ⟹ x ⊔⇘lift2 (Opt.sup f)⇙ y ⊑⇘Err.le (Opt.le r)⇙ z›*) from ok (*‹(x::'a option err) = OK (a::'a option)› ‹(y::'a option err) = OK (b::'a option)› ‹z = OK c›*) xyz (*‹x ∈ err (opt A)› ‹(y::'a::type option err) ∈ err (opt (A::'a::type set))› ‹z ∈ err (opt A)›*) xz (*‹x ⊑⇘Err.le (Opt.le r)⇙ z›*) yz (*‹y ⊑⇘Err.le (Opt.le r)⇙ z›*) have "x ⊔⇘?f⇙ y ⊑⇘?r⇙ z" apply - (*goal: ‹(x::'a option err) ⊔⇘lift2 (Opt.sup (f::'a ⇒ 'a ⇒ 'a err))⇙ (y::'a option err) ⊑⇘Err.le (Opt.le (r::'a ⇒ 'a ⇒ bool))⇙ (z::'a option err)›*) apply (cases a) (*goals: 1. ‹⟦x = OK a; y = OK b; z = OK c; x ∈ err (opt A); y ∈ err (opt A); z ∈ err (opt A); x ⊑⇘Err.le (Opt.le r)⇙ z; y ⊑⇘Err.le (Opt.le r)⇙ z; a = None⟧ ⟹ x ⊔⇘lift2 (Opt.sup f)⇙ y ⊑⇘Err.le (Opt.le r)⇙ z› 2. ‹⋀aa. ⟦x = OK a; y = OK b; z = OK c; x ∈ err (opt A); y ∈ err (opt A); z ∈ err (opt A); x ⊑⇘Err.le (Opt.le r)⇙ z; y ⊑⇘Err.le (Opt.le r)⇙ z; a = Some aa⟧ ⟹ x ⊔⇘lift2 (Opt.sup f)⇙ y ⊑⇘Err.le (Opt.le r)⇙ z› discuss goal 1*) apply simp (*discuss goal 2*) apply (cases b) (*goals: 1. ‹⋀aa::'a. ⟦(x::'a option err) = OK (a::'a option); (y::'a option err) = OK (b::'a option); (z::'a option err) = OK (c::'a option); x ∈ err (opt (A::'a set)); y ∈ err (opt A); z ∈ err (opt A); x ⊑⇘Err.le (Opt.le (r::'a ⇒ 'a ⇒ bool))⇙ z; y ⊑⇘Err.le (Opt.le r)⇙ z; a = Some aa; b = None⟧ ⟹ x ⊔⇘lift2 (Opt.sup (f::'a ⇒ 'a ⇒ 'a err))⇙ y ⊑⇘Err.le (Opt.le r)⇙ z› 2. ‹⋀(aa::'a) aaa::'a. ⟦(x::'a option err) = OK (a::'a option); (y::'a option err) = OK (b::'a option); (z::'a option err) = OK (c::'a option); x ∈ err (opt (A::'a set)); y ∈ err (opt A); z ∈ err (opt A); x ⊑⇘Err.le (Opt.le (r::'a ⇒ 'a ⇒ bool))⇙ z; y ⊑⇘Err.le (Opt.le r)⇙ z; a = Some aa; b = Some aaa⟧ ⟹ x ⊔⇘lift2 (Opt.sup (f::'a ⇒ 'a ⇒ 'a err))⇙ y ⊑⇘Err.le (Opt.le r)⇙ z› discuss goal 1*) apply simp (*discuss goal 2*) apply (cases c) (*goals: 1. ‹⋀aa aaa. ⟦x = OK a; y = OK b; z = OK c; x ∈ err (opt A); y ∈ err (opt A); z ∈ err (opt A); x ⊑⇘Err.le (Opt.le r)⇙ z; y ⊑⇘Err.le (Opt.le r)⇙ z; a = Some aa; b = Some aaa; c = None⟧ ⟹ x ⊔⇘lift2 (Opt.sup f)⇙ y ⊑⇘Err.le (Opt.le r)⇙ z› 2. ‹⋀aa aaa ab. ⟦x = OK a; y = OK b; z = OK c; x ∈ err (opt A); y ∈ err (opt A); z ∈ err (opt A); x ⊑⇘Err.le (Opt.le r)⇙ z; y ⊑⇘Err.le (Opt.le r)⇙ z; a = Some aa; b = Some aaa; c = Some ab⟧ ⟹ x ⊔⇘lift2 (Opt.sup f)⇙ y ⊑⇘Err.le (Opt.le r)⇙ z› discuss goal 1*) apply simp (*discuss goal 2*) apply blast (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . } with xyz (*‹x ∈ err (opt A)› ‹y ∈ err (opt A)› ‹z ∈ err (opt A)›*) xz (*‹x ⊑⇘Err.le (Opt.le r)⇙ z›*) yz (*‹y ⊑⇘Err.le (Opt.le r)⇙ z›*) show "x ⊔⇘?f⇙ y ⊑⇘?r⇙ z" apply - (*goal: ‹x ⊔⇘lift2 (Opt.sup f)⇙ y ⊑⇘Err.le (Opt.le r)⇙ z›*) apply (cases x) (*goals: 1. ‹⟦x ∈ err (opt A); y ∈ err (opt A); z ∈ err (opt A); x ⊑⇘Err.le (Opt.le r)⇙ z; y ⊑⇘Err.le (Opt.le r)⇙ z; ⋀a b c. ⟦x = OK a; y = OK b; z = OK c⟧ ⟹ x ⊔⇘lift2 (Opt.sup f)⇙ y ⊑⇘Err.le (Opt.le r)⇙ z; x = Err⟧ ⟹ x ⊔⇘lift2 (Opt.sup f)⇙ y ⊑⇘Err.le (Opt.le r)⇙ z› 2. ‹⋀x2. ⟦x ∈ err (opt A); y ∈ err (opt A); z ∈ err (opt A); x ⊑⇘Err.le (Opt.le r)⇙ z; y ⊑⇘Err.le (Opt.le r)⇙ z; ⋀a b c. ⟦x = OK a; y = OK b; z = OK c⟧ ⟹ x ⊔⇘lift2 (Opt.sup f)⇙ y ⊑⇘Err.le (Opt.le r)⇙ z; x = OK x2⟧ ⟹ x ⊔⇘lift2 (Opt.sup f)⇙ y ⊑⇘Err.le (Opt.le r)⇙ z› discuss goal 1*) apply simp (*discuss goal 2*) apply (cases y) (*goals: 1. ‹⋀x2::'a::type option. ⟦(x::'a::type option err) ∈ err (opt (A::'a::type set)); (y::'a::type option err) ∈ err (opt A); (z::'a::type option err) ∈ err (opt A); x ⊑⇘Err.le (Opt.le (r::'a::type ⇒ 'a::type ⇒ bool))⇙ z; y ⊑⇘Err.le (Opt.le r)⇙ z; ⋀(a::'a::type option) (b::'a::type option) c::'a::type option. ⟦x = OK a; y = OK b; z = OK c⟧ ⟹ x ⊔⇘lift2 (Opt.sup (f::'a::type ⇒ 'a::type ⇒ 'a::type err))⇙ y ⊑⇘Err.le (Opt.le r)⇙ z; x = OK x2; y = Err⟧ ⟹ x ⊔⇘lift2 (Opt.sup f)⇙ y ⊑⇘Err.le (Opt.le r)⇙ z› 2. ‹⋀(x2::'a::type option) x2a::'a::type option. ⟦(x::'a::type option err) ∈ err (opt (A::'a::type set)); (y::'a::type option err) ∈ err (opt A); (z::'a::type option err) ∈ err (opt A); x ⊑⇘Err.le (Opt.le (r::'a::type ⇒ 'a::type ⇒ bool))⇙ z; y ⊑⇘Err.le (Opt.le r)⇙ z; ⋀(a::'a::type option) (b::'a::type option) c::'a::type option. ⟦x = OK a; y = OK b; z = OK c⟧ ⟹ x ⊔⇘lift2 (Opt.sup (f::'a::type ⇒ 'a::type ⇒ 'a::type err))⇙ y ⊑⇘Err.le (Opt.le r)⇙ z; x = OK x2; y = OK x2a⟧ ⟹ x ⊔⇘lift2 (Opt.sup f)⇙ y ⊑⇘Err.le (Opt.le r)⇙ z› discuss goal 1*) apply simp (*discuss goal 2*) apply (cases z) (*goals: 1. ‹⋀(x2::'a option) x2a::'a option. ⟦(x::'a option err) ∈ err (opt (A::'a set)); (y::'a option err) ∈ err (opt A); (z::'a option err) ∈ err (opt A); x ⊑⇘Err.le (Opt.le (r::'a ⇒ 'a ⇒ bool))⇙ z; y ⊑⇘Err.le (Opt.le r)⇙ z; ⋀(a::'a option) (b::'a option) c::'a option. ⟦x = OK a; y = OK b; z = OK c⟧ ⟹ x ⊔⇘lift2 (Opt.sup (f::'a ⇒ 'a ⇒ 'a err))⇙ y ⊑⇘Err.le (Opt.le r)⇙ z; x = OK x2; y = OK x2a; z = Err⟧ ⟹ x ⊔⇘lift2 (Opt.sup f)⇙ y ⊑⇘Err.le (Opt.le r)⇙ z› 2. ‹⋀(x2::'a option) (x2a::'a option) x2b::'a option. ⟦(x::'a option err) ∈ err (opt (A::'a set)); (y::'a option err) ∈ err (opt A); (z::'a option err) ∈ err (opt A); x ⊑⇘Err.le (Opt.le (r::'a ⇒ 'a ⇒ bool))⇙ z; y ⊑⇘Err.le (Opt.le r)⇙ z; ⋀(a::'a option) (b::'a option) c::'a option. ⟦x = OK a; y = OK b; z = OK c⟧ ⟹ x ⊔⇘lift2 (Opt.sup (f::'a ⇒ 'a ⇒ 'a err))⇙ y ⊑⇘Err.le (Opt.le r)⇙ z; x = OK x2; y = OK x2a; z = OK x2b⟧ ⟹ x ⊔⇘lift2 (Opt.sup f)⇙ y ⊑⇘Err.le (Opt.le r)⇙ z› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . qed ultimately show "err_semilat (Opt.esl L)" apply (unfold semilat_def (*‹semilat = (λ(A::?'a set, r::?'a ⇒ ?'a ⇒ bool, f::?'a ⇒ ?'a ⇒ ?'a). order r ∧ closed A f ∧ (∀x::?'a∈A. ∀y::?'a∈A. x ⊑⇘r⇙ x ⊔⇘f⇙ y) ∧ (∀x::?'a∈A. ∀y::?'a∈A. y ⊑⇘r⇙ x ⊔⇘f⇙ y) ∧ (∀x::?'a∈A. ∀y::?'a∈A. ∀z::?'a∈A. x ⊑⇘r⇙ z ∧ y ⊑⇘r⇙ z ⟶ x ⊔⇘f⇙ y ⊑⇘r⇙ z))›*) esl_def (*‹Opt.esl = (λ(A::?'a set, r::?'a ⇒ ?'a ⇒ bool, f::?'a ⇒ ?'a ⇒ ?'a err). (opt A, Opt.le r, Opt.sup f))›*) sl_def (*‹sl = (λ(A::?'a set, r::?'a ⇒ ?'a ⇒ bool, f::?'a ⇒ ?'a ⇒ ?'a err). (err A, Err.le r, lift2 f))›*)) (*goal: ‹err_semilat (Opt.esl L)›*) by simp qed (*>*) lemma top_le_opt_Some [iff]: "top (le r) (Some T) = top r T" (*<*) apply (unfold top_def (*‹Semilat.top ?r ?T = (∀x. x ⊑⇘?r⇙ ?T)›*)) (*goal: ‹Semilat.top (Opt.le r) (Some T) = Semilat.top r T›*) apply (rule iffI (*‹⟦?P::bool ⟹ ?Q::bool; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*)) (*goals: 1. ‹∀x. x ⊑⇘Opt.le r⇙ Some T ⟹ ∀x. x ⊑⇘r⇙ T› 2. ‹∀x. x ⊑⇘r⇙ T ⟹ ∀x. x ⊑⇘Opt.le r⇙ Some T› discuss goal 1*) apply blast (*discuss goal 2*) apply (rule allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*)) (*goal: ‹∀x::'a. x ⊑⇘r::'a ⇒ 'a ⇒ bool⇙ (T::'a) ⟹ ∀x::'a option. x ⊑⇘Opt.le r⇙ Some T›*) apply (case_tac "x") (*goals: 1. ‹⋀x. ⟦∀x. x ⊑⇘r⇙ T; x = None⟧ ⟹ x ⊑⇘Opt.le r⇙ Some T› 2. ‹⋀x a. ⟦∀x. x ⊑⇘r⇙ T; x = Some a⟧ ⟹ x ⊑⇘Opt.le r⇙ Some T› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) . (*>*) lemma Top_le_conv: "⟦ order r; top r T ⟧ ⟹ (T ⊑⇩r x) = (x = T)" (*<*) apply (unfold top_def (*‹Semilat.top ?r ?T = (∀x. x ⊑⇘?r⇙ ?T)›*)) (*goal: ‹⟦order (r::'a::type ⇒ 'a::type ⇒ bool); Semilat.top r (T::'a::type)⟧ ⟹ (T ⊑⇘r⇙ (x::'a::type)) = (x = T)›*) by (blast intro: order_antisym (*‹⟦order ?r; ?x ⊑⇘?r⇙ ?y; ?y ⊑⇘?r⇙ ?x⟧ ⟹ ?x = ?y›*)) (*>*) lemma acc_le_optI [intro!]: "acc A r ⟹ acc (opt A) (le r)" (*<*) apply (unfold acc_def (*‹acc ?A ?r = wf {(y, x). x ∈ ?A ∧ y ∈ ?A ∧ x ⊏⇘?r⇙ y}›*) lesub_def (*‹(?x ⊑⇘?r⇙ ?y) = ?r ?x ?y›*) le_def (*‹Opt.le ?r ?o₁ ?o₂ = (case ?o₂ of None ⇒ ?o₁ = None | Some y ⇒ case ?o₁ of None ⇒ True | Some x ⇒ x ⊑⇘?r⇙ y)›*) lesssub_def (*‹(?x ⊏⇘?r⇙ ?y) = (?x ⊑⇘?r⇙ ?y ∧ ?x ≠ ?y)›*)) (*goal: ‹acc A r ⟹ acc (opt A) (Opt.le r)›*) apply (simp add: wf_eq_minimal (*‹wf (?r::(?'a × ?'a) set) = (∀(Q::?'a set) x::?'a. x ∈ Q ⟶ (∃z::?'a∈Q. ∀y::?'a. (y, z) ∈ ?r ⟶ y ∉ Q))›*) split: option.split (*‹(?P::?'b ⇒ bool) (case ?option::?'a option of None ⇒ ?f1.0::?'b | Some (x::?'a) ⇒ (?f2.0::?'a ⇒ ?'b) x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2::?'a. ?option = Some x2 ⟶ ?P (?f2.0 x2)))›*)) (*goal: ‹wf {(y::'a, x::'a). x ∈ (A::'a set) ∧ y ∈ A ∧ (r::'a ⇒ 'a ⇒ bool) x y ∧ x ≠ y} ⟹ wf {(y::'a option, x::'a option). x ∈ opt A ∧ y ∈ opt A ∧ (case y of None ⇒ x = None | Some (y::'a) ⇒ case x of None ⇒ True | Some (x::'a) ⇒ r x y) ∧ x ≠ y}›*) apply clarify (*goal: ‹∀Q. (∃x. x ∈ Q) ⟶ (∃z∈Q. ∀y. z ∈ A ∧ y ∈ A ∧ r z y ∧ z ≠ y ⟶ y ∉ Q) ⟹ ∀Q. (∃x. x ∈ Q) ⟶ (∃z∈Q. ∀y. (y = None ⟶ z ∈ opt A ∧ z = None ∧ (∃y. z = Some y) ⟶ None ∉ Q) ∧ (∀x2. (z = None ⟶ y = Some x2 ⟶ x2 ∈ A ⟶ Some x2 ∉ Q) ∧ (∀x2a. z = Some x2a ⟶ y = Some x2 ⟶ x2a ∈ A ∧ x2 ∈ A ∧ r x2a x2 ∧ x2a ≠ x2 ⟶ Some x2 ∉ Q)))›*) apply (case_tac "∃a. Some a ∈ Q") (*goals: 1. ‹⋀Q x. ⟦∀Q. (∃x. x ∈ Q) ⟶ (∃z∈Q. ∀y. z ∈ A ∧ y ∈ A ∧ r z y ∧ z ≠ y ⟶ y ∉ Q); x ∈ Q; ∃a. Some a ∈ Q⟧ ⟹ ∃z∈Q. ∀y. (y = None ⟶ z ∈ opt A ∧ z = None ∧ (∃y. z = Some y) ⟶ None ∉ Q) ∧ (∀x2. (z = None ⟶ y = Some x2 ⟶ x2 ∈ A ⟶ Some x2 ∉ Q) ∧ (∀x2a. z = Some x2a ⟶ y = Some x2 ⟶ x2a ∈ A ∧ x2 ∈ A ∧ r x2a x2 ∧ x2a ≠ x2 ⟶ Some x2 ∉ Q))› 2. ‹⋀Q x. ⟦∀Q. (∃x. x ∈ Q) ⟶ (∃z∈Q. ∀y. z ∈ A ∧ y ∈ A ∧ r z y ∧ z ≠ y ⟶ y ∉ Q); x ∈ Q; ∄a. Some a ∈ Q⟧ ⟹ ∃z∈Q. ∀y. (y = None ⟶ z ∈ opt A ∧ z = None ∧ (∃y. z = Some y) ⟶ None ∉ Q) ∧ (∀x2. (z = None ⟶ y = Some x2 ⟶ x2 ∈ A ⟶ Some x2 ∉ Q) ∧ (∀x2a. z = Some x2a ⟶ y = Some x2 ⟶ x2a ∈ A ∧ x2 ∈ A ∧ r x2a x2 ∧ x2a ≠ x2 ⟶ Some x2 ∉ Q))› discuss goal 1*) apply (erule_tac x = "{a . Some a ∈ Q}" in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀Q x. ⟦∀Q. (∃x. x ∈ Q) ⟶ (∃z∈Q. ∀y. z ∈ A ∧ y ∈ A ∧ r z y ∧ z ≠ y ⟶ y ∉ Q); x ∈ Q; ∃a. Some a ∈ Q⟧ ⟹ ∃z∈Q. ∀y. (y = None ⟶ z ∈ opt A ∧ z = None ∧ (∃y. z = Some y) ⟶ None ∉ Q) ∧ (∀x2. (z = None ⟶ y = Some x2 ⟶ x2 ∈ A ⟶ Some x2 ∉ Q) ∧ (∀x2a. z = Some x2a ⟶ y = Some x2 ⟶ x2a ∈ A ∧ x2 ∈ A ∧ r x2a x2 ∧ x2a ≠ x2 ⟶ Some x2 ∉ Q))› and 1 goal remains*) apply blast (*discuss goal 2*) apply (case_tac "x") (*goals: 1. ‹⋀Q x. ⟦∀Q. (∃x. x ∈ Q) ⟶ (∃z∈Q. ∀y. z ∈ A ∧ y ∈ A ∧ r z y ∧ z ≠ y ⟶ y ∉ Q); x ∈ Q; ∄a. Some a ∈ Q; x = None⟧ ⟹ ∃z∈Q. ∀y. (y = None ⟶ z ∈ opt A ∧ z = None ∧ (∃y. z = Some y) ⟶ None ∉ Q) ∧ (∀x2. (z = None ⟶ y = Some x2 ⟶ x2 ∈ A ⟶ Some x2 ∉ Q) ∧ (∀x2a. z = Some x2a ⟶ y = Some x2 ⟶ x2a ∈ A ∧ x2 ∈ A ∧ r x2a x2 ∧ x2a ≠ x2 ⟶ Some x2 ∉ Q))› 2. ‹⋀Q x a. ⟦∀Q. (∃x. x ∈ Q) ⟶ (∃z∈Q. ∀y. z ∈ A ∧ y ∈ A ∧ r z y ∧ z ≠ y ⟶ y ∉ Q); x ∈ Q; ∄a. Some a ∈ Q; x = Some a⟧ ⟹ ∃z∈Q. ∀y. (y = None ⟶ z ∈ opt A ∧ z = None ∧ (∃y. z = Some y) ⟶ None ∉ Q) ∧ (∀x2. (z = None ⟶ y = Some x2 ⟶ x2 ∈ A ⟶ Some x2 ∉ Q) ∧ (∀x2a. z = Some x2a ⟶ y = Some x2 ⟶ x2a ∈ A ∧ x2 ∈ A ∧ r x2a x2 ∧ x2a ≠ x2 ⟶ Some x2 ∉ Q))› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) (*proven 2 subgoals*) . (*>*) lemma map_option_in_optionI: "⟦ ox ∈ opt S; ∀x∈S. ox = Some x ⟶ f x ∈ S ⟧ ⟹ map_option f ox ∈ opt S" (*<*) apply (unfold map_option_case (*‹map_option ?f ?y = (case ?y of None ⇒ None | Some x ⇒ Some (?f x))›*)) (*goal: ‹⟦ox ∈ opt S; ∀x∈S. ox = Some x ⟶ f x ∈ S⟧ ⟹ map_option f ox ∈ opt S›*) apply (simp split: option.split (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))›*)) (*goal: ‹⟦ox ∈ opt S; ∀x∈S. ox = Some x ⟶ f x ∈ S⟧ ⟹ (case ox of None ⇒ None | Some x ⇒ Some (f x)) ∈ opt S›*) by blast (*>*) end
{ "path": "afp-2025-02-12/thys/JinjaThreads/DFA/Opt.thy", "repo": "afp-2025-02-12", "sha": "3775bae001b432a4c328fd29bf392419280139d1d37237c207dc1edac2a7c32a" }
theory Girth_Chromatic_Misc imports Main "HOL-Library.Extended_Real" begin section ‹Auxilliary lemmas and setup› text ‹ This section contains facts about general concepts which are not directly connected to the proof of the Chromatic-Girth theorem. At some point in time, most of them could be moved to the Isabelle base library. Also, a little bit of setup happens. › subsection ‹Numbers› lemma enat_in_Inf: fixes S :: "enat set" assumes "Inf S ≠ top" shows "Inf S ∈ S" using assms (*‹Inf S ≠ top›*) wellorder_InfI (*‹?k ∈ ?A ⟹ Inf ?A ∈ ?A›*) by auto lemma enat_in_INF: fixes f :: "'a ⇒ enat" assumes "(INF x∈S. f x) ≠ top" obtains x where "x ∈ S" and "(INF x∈S. f x) = f x" by (meson assms (*‹Inf (f ` S) ≠ top›*) enat_in_Inf (*‹Inf ?S ≠ top ⟹ Inf ?S ∈ ?S›*) imageE (*‹⟦?b ∈ ?f ` ?A; ⋀x. ⟦?b = ?f x; x ∈ ?A⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) lemma enat_less_INF_I: fixes f :: "'a ⇒ enat" assumes not_inf: "x ≠ ∞" and less: "⋀y. y ∈ S ⟹ x < f y" shows "x < (INF y∈S. f y)" using assms (*‹x ≠ ∞› ‹?y ∈ S ⟹ x < f ?y›*) by (auto simp: Suc_ile_eq[symmetric] (*‹(enat ?m < ?n) = (enat (Suc ?m) ≤ ?n)›*) INF_greatest (*‹(⋀i. i ∈ ?A ⟹ ?u ≤ ?f i) ⟹ ?u ≤ Inf (?f ` ?A)›*)) lemma enat_le_Sup_iff: "enat k ≤ Sup M ⟷ k = 0 ∨ (∃m ∈ M. enat k ≤ m)" (is "?L ⟷ ?R") proof (cases) (*goals: 1. ‹?P ⟹ (enat k ≤ Sup M) = (k = 0 ∨ (∃m∈M. enat k ≤ m))› 2. ‹¬ ?P ⟹ (enat k ≤ Sup M) = (k = 0 ∨ (∃m∈M. enat k ≤ m))›*) assume "k = 0" (*‹(k::nat) = (0::nat)›*) then show "?thesis" (*goal: ‹(enat k ≤ Sup M) = (k = 0 ∨ (∃m∈M. enat k ≤ m))›*) by (auto simp: enat_0 (*‹enat (0::nat) = (0::enat)›*)) next (*goal: ‹k ≠ 0 ⟹ (enat k ≤ Sup M) = (k = 0 ∨ (∃m∈M. enat k ≤ m))›*) assume "k ≠ 0" (*‹(k::nat) ≠ (0::nat)›*) show "?thesis" (*goal: ‹(enat k ≤ Sup M) = (k = 0 ∨ (∃m∈M. enat k ≤ m))›*) proof (standard) (*goals: 1. ‹enat (k::nat) ≤ Sup (M::enat set) ⟹ k = (0::nat) ∨ (∃m::enat∈M. enat k ≤ m)› 2. ‹(k::nat) = (0::nat) ∨ (∃m::enat∈M::enat set. enat k ≤ m) ⟹ enat k ≤ Sup M›*) assume "?L" (*‹enat (k::nat) ≤ Sup (M::enat set)›*) then have "⟦enat k ≤ (if finite M then Max M else ∞); M ≠ {}⟧ ⟹ ∃m∈M. enat k ≤ m" by (metis Max_in (*‹⟦finite ?A; ?A ≠ {}⟧ ⟹ Max ?A ∈ ?A›*) Sup_enat_def (*‹Sup ?A = (if ?A = {} then 0 else if finite ?A then Max ?A else ∞)›*) finite_enat_bounded (*‹(⋀y. y ∈ ?A ⟹ y ≤ enat ?n) ⟹ finite ?A›*) linorder_linear (*‹?x ≤ ?y ∨ ?y ≤ ?x›*)) with ‹k ≠ 0› (*‹k ≠ 0›*) ‹?L› (*‹enat k ≤ Sup M›*) show "?R" unfolding Sup_enat_def (*goal: ‹k = 0 ∨ (∃m∈M. enat k ≤ m)›*) apply (cases "M={}") (*goals: 1. ‹⟦k ≠ 0; enat k ≤ (if M = {} then 0 else if finite M then Max M else ∞); ⟦enat k ≤ (if finite M then Max M else ∞); M ≠ {}⟧ ⟹ ∃m∈M. enat k ≤ m; M = {}⟧ ⟹ k = 0 ∨ (∃m∈M. enat k ≤ m)› 2. ‹⟦k ≠ 0; enat k ≤ (if M = {} then 0 else if finite M then Max M else ∞); ⟦enat k ≤ (if finite M then Max M else ∞); M ≠ {}⟧ ⟹ ∃m∈M. enat k ≤ m; M ≠ {}⟧ ⟹ k = 0 ∨ (∃m∈M. enat k ≤ m)› discuss goal 1*) apply ((auto simp add: enat_0[symmetric] (*‹0 = enat 0›*))[1]) (*discuss goal 2*) apply ((auto simp add: enat_0[symmetric] (*‹0 = enat 0›*))[1]) (*proven 2 subgoals*) . next (*goal: ‹k = 0 ∨ (∃m∈M. enat k ≤ m) ⟹ enat k ≤ Sup M›*) assume "?R" (*‹(k::nat) = (0::nat) ∨ (∃m::enat∈M::enat set. enat k ≤ m)›*) then show "?L" by (auto simp: enat_0 (*‹enat (0::nat) = (0::enat)›*) intro: complete_lattice_class.Sup_upper2 (*‹⟦(?u::?'a) ∈ (?A::?'a set); (?v::?'a) ≤ ?u⟧ ⟹ ?v ≤ Sup ?A›*)) qed qed lemma enat_neq_zero_cancel_iff[simp]: "0 ≠ enat n ⟷ 0 ≠ n" "enat n ≠ 0 ⟷ n ≠ 0" (*goals: 1. ‹(0 ≠ enat n) = (0 ≠ n)› 2. ‹(enat n ≠ 0) = (n ≠ 0)› discuss goal 1*) apply ((auto simp: enat_0[symmetric] (*‹0 = enat 0›*))[1]) (*discuss goal 2*) apply ((auto simp: enat_0[symmetric] (*‹0 = enat 0›*))[1]) (*proven 2 subgoals*) . lemma natceiling_lessD: "nat(ceiling x) < n ⟹ x < real n" by linarith lemma le_natceiling_iff: fixes n :: nat and r :: real shows "n ≤ r ⟹ n ≤ nat(ceiling r)" by linarith lemma natceiling_le_iff: fixes n :: nat and r :: real shows "r ≤ n ⟹ nat(ceiling r) ≤ n" by linarith lemma dist_real_noabs_less: fixes a b c :: real assumes "dist a b < c" shows "a - b < c" using assms (*‹dist a b < c›*) by (simp add: dist_real_def (*‹dist ?x ?y = ¦?x - ?y¦›*)) subsection ‹Lists and Sets› lemma list_set_tl: "x ∈ set (tl xs) ⟹ x ∈ set xs" apply (cases xs) (*goals: 1. ‹⟦(x::'a::type) ∈ set (tl (xs::'a::type list)); xs = []⟧ ⟹ x ∈ set xs› 2. ‹⋀(a::'a::type) list::'a::type list. ⟦(x::'a::type) ∈ set (tl (xs::'a::type list)); xs = a # list⟧ ⟹ x ∈ set xs› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma list_exhaust3: obtains "xs = []" | x where "xs = [x]" | x y ys where "xs = x # y # ys" by (metis list.exhaust (*‹⟦?y = [] ⟹ ?P; ⋀x21 x22. ?y = x21 # x22 ⟹ ?P⟧ ⟹ ?P›*)) lemma card_Ex_subset: "k ≤ card M ⟹ ∃N. N ⊆ M ∧ card N = k" apply (induct rule: inc_induct (*‹⟦(?i::nat) ≤ (?j::nat); (?P::nat ⇒ bool) ?j; ⋀n::nat. ⟦?i ≤ n; n < ?j; ?P (Suc n)⟧ ⟹ ?P n⟧ ⟹ ?P ?i›*)) (*goals: 1. ‹∃N⊆M. card N = card M› 2. ‹⋀n. ⟦k ≤ n; n < card M; ∃N⊆M. card N = Suc n⟧ ⟹ ∃N⊆M. card N = n› discuss goal 1*) apply ((auto simp: card_Suc_eq (*‹(card ?A = Suc ?k) = (∃b B. ?A = insert b B ∧ b ∉ B ∧ card B = ?k ∧ (?k = 0 ⟶ B = {}))›*))[1]) (*discuss goal 2*) apply ((auto simp: card_Suc_eq (*‹(card ?A = Suc ?k) = (∃b B. ?A = insert b B ∧ b ∉ B ∧ card B = ?k ∧ (?k = 0 ⟶ B = {}))›*))[1]) (*proven 2 subgoals*) . subsection ‹Limits and eventually› text ‹ We employ filters and the @{term eventually} predicate to deal with the @{term "∃N. ∀n≥N. P n"} cases. To make this more convenient, introduce a shorter syntax. › abbreviation evseq :: "(nat ⇒ bool) ⇒ bool" (binder "∀⇧∞" 10) where "evseq P ≡ eventually P sequentially" lemma LIMSEQ_neg_powr: assumes s: "s < 0" shows "(%x. (real x) powr s) ⇢ 0" by (simp add: filterlim_real_sequentially (*‹filterlim real at_top sequentially›*) s (*‹(s::real) < (0::real)›*) tendsto_neg_powr (*‹⟦(?s::real) < (0::real); filterlim (?f::?'a ⇒ real) at_top (?F::?'a filter)⟧ ⟹ ((λx::?'a. ?f x powr ?s) ⤏ (0::real)) ?F›*)) lemma LIMSEQ_inv_powr: assumes "0 < c" "0 < d" shows "(λn :: nat. (c / n) powr d) ⇢ 0" proof (rule tendsto_zero_powrI (*‹⟦((?f::?'a ⇒ real) ⤏ (0::real)) (?F::?'a filter); ((?g::?'a ⇒ real) ⤏ (?b::real)) ?F; ∀⇩F x::?'a in ?F. (0::real) ≤ ?f x; (0::real) < ?b⟧ ⟹ ((λx::?'a. ?f x powr ?g x) ⤏ (0::real)) ?F›*)) (*goals: 1. ‹(λx::nat. (c::real) / real x) ⇢ (0::real)› 2. ‹(λx::nat. d::real) ⇢ (?b::real)› 3. ‹∀⇧∞n::nat. (0::real) ≤ (c::real) / real n› 4. ‹(0::real) < (?b::real)›*) from ‹0 < c› (*‹0 < c›*) have "⋀x. 0 < x ⟹ 0 < c / x" by simp then show "∀⇧∞n. 0 ≤ c / real n" using assms(1) (*‹0 < c›*) by auto show "(λx. c / real x) ⇢ 0" by (simp add: lim_const_over_n (*‹(λn. ?a / of_nat n) ⇢ 0›*)) qed ((use assms in force)+) (*solves the remaining goals: 1. ‹(λx. d) ⇢ ?b› 2. ‹0 < ?b›*) end
{ "path": "afp-2025-02-12/thys/Girth_Chromatic/Girth_Chromatic_Misc.thy", "repo": "afp-2025-02-12", "sha": "281c86ec8dd279a4d42f76efebb3381137680f715fd815f515e3ca0cdd584577" }
(* * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230) * Copyright (c) 2022 Apple Inc. All rights reserved. * * SPDX-License-Identifier: BSD-2-Clause *) (* * Strengthen functions into simpler monads. * * Each block of lifting lemmas converts functions in the "L2" monadic * framework (an exception framework) into its own framework. *) theory TypeStrengthen imports Refines_Spec begin (* Set up the database and ts_rule attribute. *) ML_file "monad_types.ML" lemma gets_the_ogets_return_conv [fun_ptr_simps]: "gets_the (ogets (λ_. f)) = return f" apply (rule spec_monad_eqI (*‹(⋀P s. (?f ∙ s ⦃ P ⦄) = (?g ∙ s ⦃ P ⦄)) ⟹ ?f = ?g›*)) (*goal: ‹gets_the (ogets (λ_. f)) = return f›*) by (auto simp add: runs_to_iff (*‹(get_state ∙ ?s ⦃ ?Q ⦄) = ?Q (Result ?s) ?s› ‹(set_state ?t ∙ ?s ⦃ ?Q ⦄) = ?Q (Result ()) ?t› ‹(select ?S ∙ ?s ⦃ ?Q ⦄) = (∀x∈?S. ?Q (Result x) ?s)› ‹(unknown ∙ ?s ⦃ ?Q ⦄) = (∀x. ?Q (Result x) ?s)› ‹(Spec_Monad.lift_state ?R ?f ∙ ?s ⦃ ?Q ⦄) = (∀s'. ?R ?s s' ⟶ ?f ∙ s' ⦃ λr t'. ∀t. ?R t t' ⟶ ?Q r t ⦄)› ‹(exec_concrete ?st ?f ∙ ?s ⦃ ?Q ⦄) = (∀t. ?s = ?st t ⟶ ?f ∙ t ⦃ λr t. ?Q r (?st t) ⦄)› ‹(exec_abstract ?st ?f ∙ ?s ⦃ ?Q ⦄) = (?f ∙ (?st ?s) ⦃ λr t. ∀s'. t = ?st s' ⟶ ?Q r s' ⦄)› ‹(bind_exception_or_result ?f ?g ∙ ?s ⦃ ?Q ⦄) = (?f ∙ ?s ⦃ λr t. ?g r ∙ t ⦃ ?Q ⦄ ⦄)› ‹(bind_handle ?f ?g ?h ∙ ?s ⦃ ?Q ⦄) = (?f ∙ ?s ⦃ λr t. (∀v. r = Result v ⟶ ?g v ∙ t ⦃ ?Q ⦄) ∧ (∀e. r = Exception e ⟶ e ≠ default ⟶ ?h e ∙ t ⦃ ?Q ⦄) ⦄)› ‹((?f >>= ?g) ∙ ?s ⦃ ?Q ⦄) = (?f ∙ ?s ⦃ λr t. (∀v. r = Result v ⟶ ?g v ∙ t ⦃ ?Q ⦄) ∧ (∀e. r = Exception e ⟶ e ≠ default ⟶ ?Q (Exception e) t) ⦄)› ‹(assume_outcome ?f ∙ ?s ⦃ ?Q ⦄) = (∀(r, t)∈?f ?s. ?Q r t)› ‹(assume_result_and_state ?f ∙ ?s ⦃ ?Q ⦄) = (∀(v, t)∈?f ?s. ?Q (Result v) t)› and more 20 facts*) ogets_def (*‹ogets ?f ≡ λs. Some (?f s)›*)) lemma gets_the_ogets_gets_conv [fun_ptr_simps]: "gets_the (ogets f) = gets f" apply (rule spec_monad_eqI (*‹(⋀P s. (?f ∙ s ⦃ P ⦄) = (?g ∙ s ⦃ P ⦄)) ⟹ ?f = ?g›*)) (*goal: ‹gets_the (ogets f) = gets f›*) by (auto simp add: runs_to_iff (*‹(get_state ∙ (?s::?'b) ⦃ ?Q::(?'a, ?'b) exception_or_result ⇒ ?'b ⇒ bool ⦄) = ?Q (Result ?s) ?s› ‹(set_state (?t::?'b) ∙ (?s::?'b) ⦃ ?Q::(?'a, unit) exception_or_result ⇒ ?'b ⇒ bool ⦄) = ?Q (Result ()) ?t› ‹(select (?S::?'b set) ∙ (?s::?'c) ⦃ ?Q::(?'a, ?'b) exception_or_result ⇒ ?'c ⇒ bool ⦄) = (∀x::?'b∈?S. ?Q (Result x) ?s)› ‹(unknown ∙ (?s::?'c) ⦃ ?Q::(?'a, ?'b) exception_or_result ⇒ ?'c ⇒ bool ⦄) = (∀x::?'b. ?Q (Result x) ?s)› ‹(Spec_Monad.lift_state (?R::?'c ⇒ ?'d ⇒ bool) (?f::(?'a, ?'b, ?'d) spec_monad) ∙ (?s::?'c) ⦃ ?Q::(?'a, ?'b) exception_or_result ⇒ ?'c ⇒ bool ⦄) = (∀s'::?'d. ?R ?s s' ⟶ ?f ∙ s' ⦃ λ(r::(?'a, ?'b) exception_or_result) t'::?'d. ∀t::?'c. ?R t t' ⟶ ?Q r t ⦄)› ‹(exec_concrete (?st::?'d ⇒ ?'c) (?f::(?'a, ?'b, ?'d) spec_monad) ∙ (?s::?'c) ⦃ ?Q::(?'a, ?'b) exception_or_result ⇒ ?'c ⇒ bool ⦄) = (∀t::?'d. ?s = ?st t ⟶ ?f ∙ t ⦃ λ(r::(?'a, ?'b) exception_or_result) t::?'d. ?Q r (?st t) ⦄)› ‹(exec_abstract (?st::?'c ⇒ ?'d) (?f::(?'a, ?'b, ?'d) spec_monad) ∙ (?s::?'c) ⦃ ?Q::(?'a, ?'b) exception_or_result ⇒ ?'c ⇒ bool ⦄) = (?f ∙ (?st ?s) ⦃ λ(r::(?'a, ?'b) exception_or_result) t::?'d. ∀s'::?'c. t = ?st s' ⟶ ?Q r s' ⦄)› ‹(bind_exception_or_result (?f::(?'d, ?'e, ?'c) spec_monad) (?g::(?'d, ?'e) exception_or_result ⇒ (?'a, ?'b, ?'c) spec_monad) ∙ (?s::?'c) ⦃ ?Q::(?'a, ?'b) exception_or_result ⇒ ?'c ⇒ bool ⦄) = (?f ∙ ?s ⦃ λ(r::(?'d, ?'e) exception_or_result) t::?'c. ?g r ∙ t ⦃ ?Q ⦄ ⦄)› ‹(bind_handle (?f::(?'d, ?'e, ?'c) spec_monad) (?g::?'e ⇒ (?'a, ?'b, ?'c) spec_monad) (?h::?'d ⇒ (?'a, ?'b, ?'c) spec_monad) ∙ (?s::?'c) ⦃ ?Q::(?'a, ?'b) exception_or_result ⇒ ?'c ⇒ bool ⦄) = (?f ∙ ?s ⦃ λ(r::(?'d, ?'e) exception_or_result) t::?'c. (∀v::?'e. r = Result v ⟶ ?g v ∙ t ⦃ ?Q ⦄) ∧ (∀e::?'d. r = Exception e ⟶ e ≠ default ⟶ ?h e ∙ t ⦃ ?Q ⦄) ⦄)› ‹(((?f::(?'a, ?'d, ?'c) spec_monad) >>= (?g::?'d ⇒ (?'a, ?'b, ?'c) spec_monad)) ∙ (?s::?'c) ⦃ ?Q::(?'a, ?'b) exception_or_result ⇒ ?'c ⇒ bool ⦄) = (?f ∙ ?s ⦃ λ(r::(?'a, ?'d) exception_or_result) t::?'c. (∀v::?'d. r = Result v ⟶ ?g v ∙ t ⦃ ?Q ⦄) ∧ (∀e::?'a. r = Exception e ⟶ e ≠ default ⟶ ?Q (Exception e) t) ⦄)› ‹(assume_outcome (?f::?'c ⇒ ((?'a, ?'b) exception_or_result × ?'c) set) ∙ (?s::?'c) ⦃ ?Q::(?'a, ?'b) exception_or_result ⇒ ?'c ⇒ bool ⦄) = (∀(r::(?'a, ?'b) exception_or_result, t::?'c)∈?f ?s. ?Q r t)› ‹(assume_result_and_state (?f::?'c ⇒ (?'b × ?'c) set) ∙ (?s::?'c) ⦃ ?Q::(?'a, ?'b) exception_or_result ⇒ ?'c ⇒ bool ⦄) = (∀(v::?'b, t::?'c)∈?f ?s. ?Q (Result v) t)› and more 20 facts*) ogets_def (*‹ogets (?f::?'a ⇒ ?'b) ≡ λs::?'a. Some (?f s)›*)) lemma gets_the_ogets: "gets_the (ogets f) = gets f" apply (simp add: gets_the_def (*‹gets_the ?f = gets ?f >>= assert_opt›*) assert_opt_def[abs_def] (*‹assert_opt ≡ λv. case v of None ⇒ fail | Some v ⇒ return v›*) ogets_def (*‹ogets ?f ≡ λs. Some (?f s)›*) gets_def (*‹gets ?f = do { s ← get_state; return (?f s) }›*)) (*goal: ‹gets_the (ogets f) = gets f›*) apply (rule spec_monad_eqI (*‹(⋀P s. (?f ∙ s ⦃ P ⦄) = (?g ∙ s ⦃ P ⦄)) ⟹ ?f = ?g›*)) (*goal: ‹do { v ← do { s ← get_state; return (Some (f s)) }; case v of None ⇒ fail | Some v ⇒ return v } = do { s ← get_state; return (f s) }›*) by (auto simp add: runs_to_iff (*‹(get_state ∙ ?s ⦃ ?Q ⦄) = ?Q (Result ?s) ?s› ‹(set_state ?t ∙ ?s ⦃ ?Q ⦄) = ?Q (Result ()) ?t› ‹(select ?S ∙ ?s ⦃ ?Q ⦄) = (∀x∈?S. ?Q (Result x) ?s)› ‹(unknown ∙ ?s ⦃ ?Q ⦄) = (∀x. ?Q (Result x) ?s)› ‹(Spec_Monad.lift_state ?R ?f ∙ ?s ⦃ ?Q ⦄) = (∀s'. ?R ?s s' ⟶ ?f ∙ s' ⦃ λr t'. ∀t. ?R t t' ⟶ ?Q r t ⦄)› ‹(exec_concrete ?st ?f ∙ ?s ⦃ ?Q ⦄) = (∀t. ?s = ?st t ⟶ ?f ∙ t ⦃ λr t. ?Q r (?st t) ⦄)› ‹(exec_abstract ?st ?f ∙ ?s ⦃ ?Q ⦄) = (?f ∙ (?st ?s) ⦃ λr t. ∀s'. t = ?st s' ⟶ ?Q r s' ⦄)› ‹(bind_exception_or_result ?f ?g ∙ ?s ⦃ ?Q ⦄) = (?f ∙ ?s ⦃ λr t. ?g r ∙ t ⦃ ?Q ⦄ ⦄)› ‹(bind_handle ?f ?g ?h ∙ ?s ⦃ ?Q ⦄) = (?f ∙ ?s ⦃ λr t. (∀v. r = Result v ⟶ ?g v ∙ t ⦃ ?Q ⦄) ∧ (∀e. r = Exception e ⟶ e ≠ default ⟶ ?h e ∙ t ⦃ ?Q ⦄) ⦄)› ‹((?f >>= ?g) ∙ ?s ⦃ ?Q ⦄) = (?f ∙ ?s ⦃ λr t. (∀v. r = Result v ⟶ ?g v ∙ t ⦃ ?Q ⦄) ∧ (∀e. r = Exception e ⟶ e ≠ default ⟶ ?Q (Exception e) t) ⦄)› ‹(assume_outcome ?f ∙ ?s ⦃ ?Q ⦄) = (∀(r, t)∈?f ?s. ?Q r t)› ‹(assume_result_and_state ?f ∙ ?s ⦃ ?Q ⦄) = (∀(v, t)∈?f ?s. ?Q (Result v) t)› and more 20 facts*)) lemma gets_the_obind: "gets_the (f |>> g) = gets_the f >>= (λx. gets_the (g x))" apply (simp add: obind_def (*‹?f >>= ?g ≡ λs. case ?f s of None ⇒ None | Some x ⇒ ?g x s›*)) (*goal: ‹gets_the (f >>= g) = do { x ← gets_the f; gets_the (g x) }›*) apply (rule spec_monad_eqI (*‹(⋀P s. (?f ∙ s ⦃ P ⦄) = (?g ∙ s ⦃ P ⦄)) ⟹ ?f = ?g›*)) (*goal: ‹gets_the (λs. case f s of None ⇒ None | Some x ⇒ g x s) = do { x ← gets_the f; gets_the (g x) }›*) apply (clarsimp simp add: runs_to_iff (*‹(get_state ∙ ?s ⦃ ?Q ⦄) = ?Q (Result ?s) ?s› ‹(set_state ?t ∙ ?s ⦃ ?Q ⦄) = ?Q (Result ()) ?t› ‹(select ?S ∙ ?s ⦃ ?Q ⦄) = (∀x∈?S. ?Q (Result x) ?s)› ‹(unknown ∙ ?s ⦃ ?Q ⦄) = (∀x. ?Q (Result x) ?s)› ‹(Spec_Monad.lift_state ?R ?f ∙ ?s ⦃ ?Q ⦄) = (∀s'. ?R ?s s' ⟶ ?f ∙ s' ⦃ λr t'. ∀t. ?R t t' ⟶ ?Q r t ⦄)› ‹(exec_concrete ?st ?f ∙ ?s ⦃ ?Q ⦄) = (∀t. ?s = ?st t ⟶ ?f ∙ t ⦃ λr t. ?Q r (?st t) ⦄)› ‹(exec_abstract ?st ?f ∙ ?s ⦃ ?Q ⦄) = (?f ∙ (?st ?s) ⦃ λr t. ∀s'. t = ?st s' ⟶ ?Q r s' ⦄)› ‹(bind_exception_or_result ?f ?g ∙ ?s ⦃ ?Q ⦄) = (?f ∙ ?s ⦃ λr t. ?g r ∙ t ⦃ ?Q ⦄ ⦄)› ‹(bind_handle ?f ?g ?h ∙ ?s ⦃ ?Q ⦄) = (?f ∙ ?s ⦃ λr t. (∀v. r = Result v ⟶ ?g v ∙ t ⦃ ?Q ⦄) ∧ (∀e. r = Exception e ⟶ e ≠ default ⟶ ?h e ∙ t ⦃ ?Q ⦄) ⦄)› ‹((?f >>= ?g) ∙ ?s ⦃ ?Q ⦄) = (?f ∙ ?s ⦃ λr t. (∀v. r = Result v ⟶ ?g v ∙ t ⦃ ?Q ⦄) ∧ (∀e. r = Exception e ⟶ e ≠ default ⟶ ?Q (Exception e) t) ⦄)› ‹(assume_outcome ?f ∙ ?s ⦃ ?Q ⦄) = (∀(r, t)∈?f ?s. ?Q r t)› ‹(assume_result_and_state ?f ∙ ?s ⦃ ?Q ⦄) = (∀(v, t)∈?f ?s. ?Q (Result v) t)› and more 20 facts*)) (*goal: ‹⋀P s. (gets_the (λs. case f s of None ⇒ None | Some x ⇒ g x s) ∙ s ⦃ P ⦄) = (do { x ← gets_the f; gets_the (g x) } ∙ s ⦃ P ⦄)›*) by (auto split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) lemma gets_the_oguard: "gets_the (oguard P) = guard P" apply (simp add: oguard_def (*‹oguard ?G ≡ λs. if ?G s then Some () else None›*)) (*goal: ‹gets_the (oguard P) = guard P›*) apply (rule spec_monad_eqI (*‹(⋀P s. (?f ∙ s ⦃ P ⦄) = (?g ∙ s ⦃ P ⦄)) ⟹ ?f = ?g›*)) (*goal: ‹gets_the (λs. if P s then Some () else None) = guard P›*) by (auto simp add: runs_to_iff (*‹(get_state ∙ ?s ⦃ ?Q ⦄) = ?Q (Result ?s) ?s› ‹(set_state ?t ∙ ?s ⦃ ?Q ⦄) = ?Q (Result ()) ?t› ‹(select ?S ∙ ?s ⦃ ?Q ⦄) = (∀x∈?S. ?Q (Result x) ?s)› ‹(unknown ∙ ?s ⦃ ?Q ⦄) = (∀x. ?Q (Result x) ?s)› ‹(Spec_Monad.lift_state ?R ?f ∙ ?s ⦃ ?Q ⦄) = (∀s'. ?R ?s s' ⟶ ?f ∙ s' ⦃ λr t'. ∀t. ?R t t' ⟶ ?Q r t ⦄)› ‹(exec_concrete ?st ?f ∙ ?s ⦃ ?Q ⦄) = (∀t. ?s = ?st t ⟶ ?f ∙ t ⦃ λr t. ?Q r (?st t) ⦄)› ‹(exec_abstract ?st ?f ∙ ?s ⦃ ?Q ⦄) = (?f ∙ (?st ?s) ⦃ λr t. ∀s'. t = ?st s' ⟶ ?Q r s' ⦄)› ‹(bind_exception_or_result ?f ?g ∙ ?s ⦃ ?Q ⦄) = (?f ∙ ?s ⦃ λr t. ?g r ∙ t ⦃ ?Q ⦄ ⦄)› ‹(bind_handle ?f ?g ?h ∙ ?s ⦃ ?Q ⦄) = (?f ∙ ?s ⦃ λr t. (∀v. r = Result v ⟶ ?g v ∙ t ⦃ ?Q ⦄) ∧ (∀e. r = Exception e ⟶ e ≠ default ⟶ ?h e ∙ t ⦃ ?Q ⦄) ⦄)› ‹((?f >>= ?g) ∙ ?s ⦃ ?Q ⦄) = (?f ∙ ?s ⦃ λr t. (∀v. r = Result v ⟶ ?g v ∙ t ⦃ ?Q ⦄) ∧ (∀e. r = Exception e ⟶ e ≠ default ⟶ ?Q (Exception e) t) ⦄)› ‹(assume_outcome ?f ∙ ?s ⦃ ?Q ⦄) = (∀(r, t)∈?f ?s. ?Q r t)› ‹(assume_result_and_state ?f ∙ ?s ⦃ ?Q ⦄) = (∀(v, t)∈?f ?s. ?Q (Result v) t)› and more 20 facts*)) lemma gets_the_ocondition: "gets_the (ocondition P f g) = condition P (gets_the f) (gets_the g)" apply (simp add: ocondition_def (*‹ocondition ?c ?L ?R ≡ λs. if ?c s then ?L s else ?R s›*)) (*goal: ‹gets_the (ocondition P f g) = condition P (gets_the f) (gets_the g)›*) apply (rule spec_monad_eqI (*‹(⋀P s. (?f ∙ s ⦃ P ⦄) = (?g ∙ s ⦃ P ⦄)) ⟹ ?f = ?g›*)) (*goal: ‹gets_the (λs. if P s then f s else g s) = condition P (gets_the f) (gets_the g)›*) by (auto simp add: runs_to_iff (*‹(get_state ∙ ?s ⦃ ?Q ⦄) = ?Q (Result ?s) ?s› ‹(set_state ?t ∙ ?s ⦃ ?Q ⦄) = ?Q (Result ()) ?t› ‹(select ?S ∙ ?s ⦃ ?Q ⦄) = (∀x∈?S. ?Q (Result x) ?s)› ‹(unknown ∙ ?s ⦃ ?Q ⦄) = (∀x. ?Q (Result x) ?s)› ‹(Spec_Monad.lift_state ?R ?f ∙ ?s ⦃ ?Q ⦄) = (∀s'. ?R ?s s' ⟶ ?f ∙ s' ⦃ λr t'. ∀t. ?R t t' ⟶ ?Q r t ⦄)› ‹(exec_concrete ?st ?f ∙ ?s ⦃ ?Q ⦄) = (∀t. ?s = ?st t ⟶ ?f ∙ t ⦃ λr t. ?Q r (?st t) ⦄)› ‹(exec_abstract ?st ?f ∙ ?s ⦃ ?Q ⦄) = (?f ∙ (?st ?s) ⦃ λr t. ∀s'. t = ?st s' ⟶ ?Q r s' ⦄)› ‹(bind_exception_or_result ?f ?g ∙ ?s ⦃ ?Q ⦄) = (?f ∙ ?s ⦃ λr t. ?g r ∙ t ⦃ ?Q ⦄ ⦄)› ‹(bind_handle ?f ?g ?h ∙ ?s ⦃ ?Q ⦄) = (?f ∙ ?s ⦃ λr t. (∀v. r = Result v ⟶ ?g v ∙ t ⦃ ?Q ⦄) ∧ (∀e. r = Exception e ⟶ e ≠ default ⟶ ?h e ∙ t ⦃ ?Q ⦄) ⦄)› ‹((?f >>= ?g) ∙ ?s ⦃ ?Q ⦄) = (?f ∙ ?s ⦃ λr t. (∀v. r = Result v ⟶ ?g v ∙ t ⦃ ?Q ⦄) ∧ (∀e. r = Exception e ⟶ e ≠ default ⟶ ?Q (Exception e) t) ⦄)› ‹(assume_outcome ?f ∙ ?s ⦃ ?Q ⦄) = (∀(r, t)∈?f ?s. ?Q r t)› ‹(assume_result_and_state ?f ∙ ?s ⦃ ?Q ⦄) = (∀(v, t)∈?f ?s. ?Q (Result v) t)› and more 20 facts*)) (* FIXME: move to AutoCorresInfrastructure? *) (* FIXME: update description *) text ‹ A best-effort approach to determine the simplest possible 'monad' for the final definition is implemented. We first try to define a function into the most restrictive monad and if that fails successively try more expressive monads until we finally hit the most expressive monad. In the original autocorres version this phase was based on equations and not on on a simulation relation as all the other autocorres phases. With the switch to model recursive functions with a CCPO @{command fixed_point} instead of @{command function} with an explicit measure parameter this did no longer work, as equations are not @{const ccpo.admissible}. Fortunately simulation is admissible, so we changed this phase to @{const refines}, cf: 🗏‹Refines_Spec.thy›. So the main purpose of this theory is to set up the available target monads by applying some meta information: 🗏‹monad_types.ML›. The correspondence equations have the format: (*) @{term "p = L2_call_lift p'"} where @{term "L2_call_lift"} depends on the (simpler) target monad and lifts the program @{term p'} from that simpler monad to the fully fledged monad we start with: The program @{term p} is the definition we have from the last layer of autocorres (WA). The final definition will refer to @{term p'}. For the code to work @{term "L2_call_lift"} has to be a distinct constant, as some matching is performed on that assumption. That is why some new definitions are introduced below. Note that the final (most expressive) monad is characterised by the lifting function is @{const lift_exit_status} which merely removes the exception handling artefact from SIMPL by extracting the exception value @{typ 'a} from @{typ "'a c_exntype"}. So it should be sufficiently expressive for any input C program. When the proof for a certain monad fails it can either have a good reason (as the input function is just not expressible in that particular monad) or it can fail because the implementation is missing some rules. Note some peculiarities on the current state of affairs: ▪ When a guard remains (e.g. bounds for an integer) you end up at least in the option monad (to model the possible failure). ▪ As recursive functions are currently implemented with @{command fixed_point} they are at least in the option monad. › (* * Lifting into pure functional Isabelle. *) setup ‹ Monad_Types.new_monad_type "pure" "Pure function" "" (* unused ccpo_name for recursive definitions *) 100 #resT (fn _ => fn _ => error "monad_type pure: there is no previous monad to lift from") {rules_name = @{synthesize_rules_name pure}, relator = @{term "rel_liftE::('a, 'b) xval ⇒ 'b val ⇒ bool"}, relator_from_c_exntype = NONE, lift = @{term "return"}, dest_lift = (fn @{term_pat "return ?x"} => SOME x | _ => NONE), lift_prev = []} |> Context.theory_map › (* * Lifting into pure functional Isabelle with state. *) setup ‹ Monad_Types.new_monad_type "gets" (* reader monad *) "Read-only function" "" (* unused ccpo_name for recursive definitions *) 80 (fn {stateT, resT, exT} => stateT --> resT) (fn _ => fn stateT => let fun lift t = Abs ("_", stateT, t) in Utils.lift_result_with_arity 0 lift end) {rules_name = @{synthesize_rules_name reader}, relator = @{term "rel_liftE::('a, 'b) xval ⇒ 'b val ⇒ bool"}, relator_from_c_exntype = NONE, lift = @{term gets}, dest_lift = (fn @{term_pat "gets ?x"} => SOME x | _ => NONE), lift_prev = @{thms refines_lift_pure_reader}} |> Context.theory_map › (* * Lifting into option monad. *) lemma monotone_L2_VARS [partial_function_mono]: "monotone R X a ⟹ monotone R X (λf. L2_VARS (a f) ns)" by (simp add: L2_VARS_def (*‹L2_VARS ?f ?names ≡ ?f›*)) lemma monotone_ocondition [partial_function_mono]: assumes mono_X: "monotone R (fun_ord Q) X" assumes mono_Y: "monotone R (fun_ord Q) Y" shows "monotone R (fun_ord Q) (λf. (ocondition C (X f) (Y f)))" using mono_X (*‹monotone (R::'a::type ⇒ 'a::type ⇒ bool) (fun_ord (Q::'c::type ⇒ 'c::type ⇒ bool)) (X::'a::type ⇒ 'b::type ⇒ 'c::type)›*) mono_Y (*‹monotone (R::'a ⇒ 'a ⇒ bool) (fun_ord (Q::'c ⇒ 'c ⇒ bool)) (Y::'a ⇒ 'b ⇒ 'c)›*) unfolding ocondition_def monotone_def fun_ord_def (*goal: ‹∀x y. R x y ⟶ (∀xa. Q (if C xa then X x xa else Y x xa) (if C xa then X y xa else Y y xa))›*) by auto declare Complete_Partial_Order2.option.preorder [partial_function_mono] (* lemma monotone_ocondition_option_le_fun [partial_function_mono]: assumes mono_X: "monotone R option.le_fun X" assumes mono_Y: "monotone R option.le_fun Y" shows "monotone R option.le_fun (λf. (ocondition C (X f) (Y f)))" using mono_X mono_Y unfolding ocondition_def monotone_def by (auto simp add: flat_ord_def fun_ord_def split: option.splits) *) lemma monotone_obind[partial_function_mono]: "monotone R option.le_fun a ⟹ (⋀x. monotone R option.le_fun (λf. b f x)) ⟹ monotone R option.le_fun (λf. obind (a f) (b f))" unfolding monotone_def obind_def (*goal: ‹⟦∀x y. R x y ⟶ option.le_fun (a x) (a y); ⋀x. ∀xa y. R xa y ⟶ option.le_fun (b xa x) (b y x)⟧ ⟹ ∀x y. R x y ⟶ option.le_fun (λs. case a x s of None ⇒ None | Some xa ⇒ b x xa s) (λs. case a y s of None ⇒ None | Some x ⇒ b y x s)›*) apply (clarsimp simp add: flat_ord_def (*‹flat_ord ?b ?x ?y = (?x = ?b ∨ ?x = ?y)›*) fun_ord_def (*‹fun_ord ?ord ?f ?g = (∀x. ?ord (?f x) (?g x))›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) (*goal: ‹⟦∀x y. R x y ⟶ option.le_fun (a x) (a y); ⋀x. ∀xa y. R xa y ⟶ option.le_fun (b xa x) (b y x)⟧ ⟹ ∀x y. R x y ⟶ option.le_fun (λs. case a x s of None ⇒ None | Some xa ⇒ b x xa s) (λs. case a y s of None ⇒ None | Some x ⇒ b y x s)›*) by (metis option.sel (*‹the (Some (?x2.0::?'a)) = ?x2.0›*) option.simps( (*‹Some (?x2.0::?'a) ≠ None›*) 3)) lemma monotone_option_fun_const [partial_function_mono]: "monotone R option.le_fun (λf. c)" by (auto simp add: monotone_def (*‹monotone ?orda ?ordb ?f = (∀x y. ?orda x y ⟶ ?ordb (?f x) (?f y))›*) flat_ord_def (*‹flat_ord ?b ?x ?y = (?x = ?b ∨ ?x = ?y)›*) fun_ord_def (*‹fun_ord ?ord ?f ?g = (∀x. ?ord (?f x) (?g x))›*)) lemma option_while_eq_Some: "option_while C B I = Some F ⟷ (Some I, Some F) ∈ option_while' C B" using option_while'_THE (*‹(Some ?r, ?sr') ∈ option_while' ?C ?B ⟹ (THE s. (Some ?r, s) ∈ option_while' ?C ?B) = ?sr'›*) by (force simp: option_while_def (*‹option_while ?C ?B ?r ≡ if ∃s. (Some ?r, s) ∈ option_while' ?C ?B then THE s. (Some ?r, s) ∈ option_while' ?C ?B else None›*)) lemma option_while'_monotone: assumes B: "⋀r. flat_ord None (B r) (B' r)" assumes b: "(a, b) ∈ option_while' C B" "b ≠ None" shows "(a, b) ∈ option_while' C B'" using b (*‹(a, b) ∈ option_while' C B› ‹b ≠ None›*) proof (induction) (*goals: 1. ‹⋀r::'a. ⟦¬ (C::'a ⇒ bool) r; Some r ≠ None⟧ ⟹ (Some r, Some r) ∈ option_while' C (B'::'a ⇒ 'a option)› 2. ‹⋀r::'a. ⟦(C::'a ⇒ bool) r; (B::'a ⇒ 'a option) r = None; None ≠ None⟧ ⟹ (Some r, None) ∈ option_while' C (B'::'a ⇒ 'a option)› 3. ‹⋀(r::'a) (r'::'a) sr''::'a option. ⟦(C::'a ⇒ bool) r; (B::'a ⇒ 'a option) r = Some r'; (Some r', sr'') ∈ option_while' C B; sr'' ≠ None ⟹ (Some r', sr'') ∈ option_while' C (B'::'a ⇒ 'a option); sr'' ≠ None⟧ ⟹ (Some r, sr'') ∈ option_while' C B'›*) case (step r1 r2 s) (*‹C r1› ‹B r1 = Some r2› ‹(Some r2, s) ∈ option_while' C B› ‹s ≠ None ⟹ (Some r2, s) ∈ option_while' C B'› ‹(s::'a::type option) ≠ None›*) then show "?case" (*goal: ‹(Some r1, s) ∈ option_while' C B'›*) by (metis B (*‹option_ord (B ?r) (B' ?r)›*) flat_ord_def (*‹flat_ord ?b ?x ?y = (?x = ?b ∨ ?x = ?y)›*) option.simps( (*‹None ≠ Some ?x2.0›*) 2) option_while'.intros( (*‹⟦?C ?r; ?B ?r = Some ?r'; (Some ?r', ?sr'') ∈ option_while' ?C ?B⟧ ⟹ (Some ?r, ?sr'') ∈ option_while' ?C ?B›*) 3)) qed (auto intro: option_while'.intros (*‹¬ ?C ?r ⟹ (Some ?r, Some ?r) ∈ option_while' ?C ?B› ‹⟦?C ?r; ?B ?r = None⟧ ⟹ (Some ?r, None) ∈ option_while' ?C ?B› ‹⟦?C ?r; ?B ?r = Some ?r'; (Some ?r', ?sr'') ∈ option_while' ?C ?B⟧ ⟹ (Some ?r, ?sr'') ∈ option_while' ?C ?B›*)) (*solves the remaining goals: 1. ‹⋀r. ⟦¬ C r; Some r ≠ None⟧ ⟹ (Some r, Some r) ∈ option_while' C B'› 2. ‹⋀r. ⟦C r; B r = None; None ≠ None⟧ ⟹ (Some r, None) ∈ option_while' C B'›*) lemma monotone_option_while[partial_function_mono]: assumes B: "⋀a. monotone R (flat_ord None) (λf. B f a)" shows "monotone R (flat_ord None) (λf. option_while C (B f) I)" proof (standard) (*goal: ‹⋀x y. R x y ⟹ option_ord (option_while C (B x) I) (option_while C (B y) I)›*) fix x and y assume "R x y" (*‹(R::'b ⇒ 'b ⇒ bool) (x::'b) (y::'b)›*) show "option_ord (option_while C (B x) I) (option_while C (B y) I)" unfolding flat_ord_def (*goal: ‹option_while C (B x) I = None ∨ option_while C (B x) I = option_while C (B y) I›*) proof (intro disjCI2 (*‹(¬ ?P ⟹ ?Q) ⟹ ?P ∨ ?Q›*)) (*goal: ‹option_while C (B x) I ≠ None ⟹ option_while C (B x) I = option_while C (B y) I›*) assume "option_while C (B x) I ≠ None" (*‹option_while (C::'a ⇒ bool) ((B::'b ⇒ 'a ⇒ 'a option) (x::'b)) (I::'a) ≠ None›*) then obtain F where "option_while C (B x) I = Some F" (*goal: ‹(⋀F. option_while C (B x) I = Some F ⟹ thesis) ⟹ thesis›*) by auto then have x: "(Some I, Some F) ∈ option_while' C (B x)" by (auto simp: option_while_eq_Some (*‹(option_while ?C ?B ?I = Some ?F) = ((Some ?I, Some ?F) ∈ option_while' ?C ?B)›*)) have "(Some I, Some F) ∈ option_while' C (B y)" using B (*‹monotone R option_ord (λf. B f ?a)›*) ‹R x y› (*‹R x y›*) apply (intro option_while'_monotone[OF _ x] (*‹⟦⋀r. option_ord (B x r) (?B' r); Some F ≠ None⟧ ⟹ (Some I, Some F) ∈ option_while' C ?B'›*)) (*goals: 1. ‹⋀r. ⟦⋀a. monotone R option_ord (λf. B f a); R x y⟧ ⟹ option_ord (B x r) (B y r)› 2. ‹⟦⋀a. monotone R option_ord (λf. B f a); R x y⟧ ⟹ Some F ≠ None› discuss goal 1*) apply ((auto simp: monotone_def (*‹monotone ?orda ?ordb ?f = (∀x y. ?orda x y ⟶ ?ordb (?f x) (?f y))›*))[1]) (*discuss goal 2*) apply ((auto simp: monotone_def (*‹monotone (?orda::?'a ⇒ ?'a ⇒ bool) (?ordb::?'b ⇒ ?'b ⇒ bool) (?f::?'a ⇒ ?'b) = (∀(x::?'a) y::?'a. ?orda x y ⟶ ?ordb (?f x) (?f y))›*))[1]) (*proven 2 subgoals*) . with x (*‹(Some I, Some F) ∈ option_while' C (B x)›*) show "option_while C (B x) I = option_while C (B y) I" unfolding option_while_eq_Some[symmetric] (*goal: ‹option_while (C::'a ⇒ bool) ((B::'b ⇒ 'a ⇒ 'a option) (x::'b)) (I::'a) = option_while C (B (y::'b)) I›*) by simp qed qed lemma monotone_owhile[partial_function_mono]: "(⋀a. monotone R option.le_fun (λf. B f a)) ⟹ monotone R option.le_fun (λf. owhile C (B f) I)" unfolding owhile_def monotone_fun_ord_apply (*goal: ‹(⋀a. ∀x. monotone R option_ord (λy. B y a x)) ⟹ ∀x. monotone R option_ord (λy. option_while (λa. C a x) (λa. B y a x) I)›*) apply (intro allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*) monotone_option_while (*‹(⋀a. monotone ?R option_ord (λf. ?B f a)) ⟹ monotone ?R option_ord (λf. option_while ?C (?B f) ?I)›*)) (*goal: ‹(⋀a. ∀x. monotone R option_ord (λy. B y a x)) ⟹ ∀x. monotone R option_ord (λy. option_while (λa. C a x) (λa. B y a x) I)›*) by simp setup ‹ let open Mutual_CCPO_Rec in add_ccpo "option_state_monad" (fn ctxt => fn T => let val oT = range_type T in synth_fun ctxt (domain_type T) (synth_option ctxt oT) end) |> Context.theory_map end › lemma refines_lift_pure_option: assumes f: "refines f (return f') s s (rel_prod rel_liftE (=))" shows "refines f (gets_the (oreturn f')) s s (rel_prod rel_liftE (=))" using f (*‹refines f (return f') s s (rel_prod rel_liftE (=))›*) by (auto simp add: refines_def_old (*‹refines (?f::(?'a, ?'b, ?'c) spec_monad) (?g::(?'d, ?'e, ?'f) spec_monad) (?s::?'c) (?t::?'f) (?R::(?'a, ?'b) exception_or_result × ?'c ⇒ (?'d, ?'e) exception_or_result × ?'f ⇒ bool) = (succeeds ?g ?t ⟶ succeeds ?f ?s ∧ (∀(r::(?'a, ?'b) exception_or_result) s'::?'c. reaches ?f ?s r s' ⟶ (∃(x::(?'d, ?'e) exception_or_result) t'::?'f. reaches ?g ?t x t' ∧ ?R (r, s') (x, t'))))›*)) setup ‹ Monad_Types.new_monad_type "option" "Option monad" "option_state_monad" 60 (fn {stateT, resT, exT} => stateT --> Term.map_atyps (fn T => if T = @{typ "'a"} then resT else T) @{typ "'a option"}) (fn ctxt => fn _ => let fun lift t = \<^infer_instantiate>‹t = t in term ‹ogets t›› ctxt in Utils.lift_result_with_arity 1 lift end) {rules_name = @{synthesize_rules_name option}, relator = @{term "rel_liftE::('a, 'b) xval ⇒ 'b val ⇒ bool"}, relator_from_c_exntype = NONE, lift = @{term gets_the}, dest_lift = (fn @{term_pat "gets_the ?x"} => SOME x | _ => NONE), lift_prev = @{thms refines_lift_pure_option refines_lift_reader_option}} |> Context.theory_map › (* * Lifting into the nondeterministic state monad. * All L2 terms can be lifted into it. *) setup ‹ Monad_Types.new_monad_type "nondet" "Nondeterministic state monad" "spec_monad_gfp" 20 (fn {stateT, resT, exT} => Term.map_atyps (fn T => if T = @{typ "'a"} then resT else if T = @{typ "'s"} then stateT else T) @{typ "('a, 's) res_monad"}) (fn ctxt => fn _ => let fun lift t = \<^infer_instantiate>‹t = t in term ‹gets_the t::('a, 's) res_monad›› ctxt in Utils.lift_result_with_arity 1 lift end) {rules_name = @{synthesize_rules_name nondet}, relator = @{term "rel_liftE::('a, 'b) xval ⇒ 'b val ⇒ bool"}, relator_from_c_exntype = NONE, lift = @{term ‹λx. x›}, dest_lift = (fn _ => NONE), lift_prev = []} |> Context.theory_map › setup ‹ Monad_Types.new_monad_type "exit" "Nondeterministic state monad with exit (default)" "spec_monad_gfp" 10 (fn {stateT, resT, exT} => Term.map_atyps (fn T => if T = @{typ "'a"} then resT else if T = @{typ "'s"} then stateT else if T = @{typ "'e"} then HP_TermsTypes.strip_c_exntype exT else T) @{typ "('e, 'a, 's) exn_monad"}) (fn ctxt => fn _ => let fun lift t = \<^infer_instantiate>‹t = t in term ‹liftE t:: (exit_status, 'a, 's) exn_monad›› ctxt in Utils.lift_result_with_arity 0 lift end) {rules_name = @{synthesize_rules_name exit}, relator = @{term ‹rel_xval (=) (=)›}, relator_from_c_exntype = SOME @{term ‹rel_xval rel_Nonlocal (=)›}, lift = @{term ‹λx. x›}, dest_lift = (fn _ => NONE), lift_prev = []} |> Context.theory_map › lemma id_comps: "id o f = f" "((λs. s) o f) = f" (*goals: 1. ‹id ∘ (f::'a ⇒ 'b) = f› 2. ‹(λs::'b. s) ∘ (f::'a ⇒ 'b) = f› discuss goal 1*) apply (simp add: comp_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*)) (*discuss goal 2*) apply (simp add: comp_def (*‹(?f::?'b::type ⇒ ?'c::type) ∘ (?g::?'a::type ⇒ ?'b::type) = (λx::?'a::type. ?f (?g x))›*)) (*proven 2 subgoals*) . lemma gets_bind_ign: "gets f >>= (λx. m) = m" apply (rule spec_monad_eqI (*‹(⋀(P::(?'a, ?'b) exception_or_result ⇒ ?'c ⇒ bool) s::?'c. ((?f::(?'a, ?'b, ?'c) spec_monad) ∙ s ⦃ P ⦄) = ((?g::(?'a, ?'b, ?'c) spec_monad) ∙ s ⦃ P ⦄)) ⟹ ?f = ?g›*)) (*goal: ‹do { x ← gets f; m } = m›*) by (auto simp add: runs_to_iff (*‹(get_state ∙ ?s ⦃ ?Q ⦄) = ?Q (Result ?s) ?s› ‹(set_state ?t ∙ ?s ⦃ ?Q ⦄) = ?Q (Result ()) ?t› ‹(select ?S ∙ ?s ⦃ ?Q ⦄) = (∀x∈?S. ?Q (Result x) ?s)› ‹(unknown ∙ ?s ⦃ ?Q ⦄) = (∀x. ?Q (Result x) ?s)› ‹(Spec_Monad.lift_state ?R ?f ∙ ?s ⦃ ?Q ⦄) = (∀s'. ?R ?s s' ⟶ ?f ∙ s' ⦃ λr t'. ∀t. ?R t t' ⟶ ?Q r t ⦄)› ‹(exec_concrete ?st ?f ∙ ?s ⦃ ?Q ⦄) = (∀t. ?s = ?st t ⟶ ?f ∙ t ⦃ λr t. ?Q r (?st t) ⦄)› ‹(exec_abstract ?st ?f ∙ ?s ⦃ ?Q ⦄) = (?f ∙ (?st ?s) ⦃ λr t. ∀s'. t = ?st s' ⟶ ?Q r s' ⦄)› ‹(bind_exception_or_result ?f ?g ∙ ?s ⦃ ?Q ⦄) = (?f ∙ ?s ⦃ λr t. ?g r ∙ t ⦃ ?Q ⦄ ⦄)› ‹(bind_handle ?f ?g ?h ∙ ?s ⦃ ?Q ⦄) = (?f ∙ ?s ⦃ λr t. (∀v. r = Result v ⟶ ?g v ∙ t ⦃ ?Q ⦄) ∧ (∀e. r = Exception e ⟶ e ≠ default ⟶ ?h e ∙ t ⦃ ?Q ⦄) ⦄)› ‹((?f >>= ?g) ∙ ?s ⦃ ?Q ⦄) = (?f ∙ ?s ⦃ λr t. (∀v. r = Result v ⟶ ?g v ∙ t ⦃ ?Q ⦄) ∧ (∀e. r = Exception e ⟶ e ≠ default ⟶ ?Q (Exception e) t) ⦄)› ‹(assume_outcome ?f ∙ ?s ⦃ ?Q ⦄) = (∀(r, t)∈?f ?s. ?Q r t)› ‹(assume_result_and_state ?f ∙ ?s ⦃ ?Q ⦄) = (∀(v, t)∈?f ?s. ?Q (Result v) t)› and more 20 facts*)) end
{ "path": "afp-2025-02-12/thys/AutoCorres2/TypeStrengthen.thy", "repo": "afp-2025-02-12", "sha": "0cc3a077be788b01f011459be69a0d97beab81d1a9d5e66ac0700b46fc755531" }
(* Title: Kleene Relation Algebras Author: Walter Guttmann Maintainer: Walter Guttmann <walter.guttmann at canterbury.ac.nz> *) section ‹Kleene Relation Algebras› text ‹ This theory combines Kleene algebras with Stone relation algebras. Relation algebras with transitive closure have been studied by \<^cite>‹"Ng1984"›. The weakening to Stone relation algebras allows us to talk about reachability in weighted graphs, for example. Many results in this theory are used in the correctness proof of Prim's minimum spanning tree algorithm. In particular, they are concerned with the exchange property, preservation of parts of the invariant and with establishing parts of the postcondition. › theory Kleene_Relation_Algebras imports Stone_Relation_Algebras.Relation_Algebras Kleene_Algebras begin text ‹ We first note that bounded distributive lattices can be expanded to Kleene algebras by reusing some of the operations. › sublocale bounded_distrib_lattice < comp_inf: bounded_kleene_algebra where star = "λx . top" and one = top and times = inf apply unfold_locales (*goals: 1. ‹⋀a b c. a ⊓ b ⊓ c = a ⊓ (b ⊓ c)› 2. ‹⋀a. top ⊓ a = a› 3. ‹⋀a. a ⊓ top = a› 4. ‹⋀x y z. x ⊓ y ⊔ x ⊓ z ≤ x ⊓ (y ⊔ z)› 5. ‹⋀x y z. (x ⊔ y) ⊓ z = x ⊓ z ⊔ y ⊓ z› 6. ‹⋀x. bot ⊓ x = bot› 7. ‹⋀x. x ≤ x ⊓ top› 8. ‹⋀y. top ⊔ y ⊓ top ≤ top› 9. ‹⋀z y x. z ⊔ y ⊓ x ≤ x ⟶ top ⊓ z ≤ x› 10. ‹⋀z x y. z ⊔ x ⊓ y ≤ x ⟶ z ⊓ top ≤ x› 11. ‹⋀x y z. x ⊓ (y ⊔ z) = x ⊓ y ⊔ x ⊓ z› 12. ‹⋀x. x ⊓ bot = bot› 13. ‹⋀x. x ⊔ top = top› 14. ‹⋀x y z. x ⊓ y ⊓ z ≤ x ⊓ (y ⊓ z)› discuss goal 1*) apply (simp add: inf.assoc (*‹(?a::'a) ⊓ (?b::'a) ⊓ (?c::'a) = ?a ⊓ (?b ⊓ ?c)›*)) (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*discuss goal 4*) apply (simp add: le_infI2 (*‹?b ≤ ?x ⟹ ?a ⊓ ?b ≤ ?x›*)) (*discuss goal 5*) apply (simp add: inf_sup_distrib2 (*‹((?y::'a) ⊔ (?z::'a)) ⊓ (?x::'a) = ?y ⊓ ?x ⊔ ?z ⊓ ?x›*)) (*discuss goal 6*) apply simp (*discuss goal 7*) apply simp (*discuss goal 8*) apply simp (*discuss goal 9*) apply simp (*discuss goal 10*) apply simp (*discuss goal 11*) apply (simp add: inf_sup_distrib1 (*‹?x ⊓ (?y ⊔ ?z) = ?x ⊓ ?y ⊔ ?x ⊓ ?z›*)) (*discuss goal 12*) apply simp (*discuss goal 13*) apply simp (*discuss goal 14*) apply (simp add: inf_assoc (*‹?x ⊓ ?y ⊓ ?z = ?x ⊓ (?y ⊓ ?z)›*)) (*proven 14 subgoals*) . text ‹ We add the Kleene star operation to each of bounded distributive allegories, pseudocomplemented distributive allegories and Stone relation algebras. We start with single-object bounded distributive allegories. › class bounded_distrib_kleene_allegory = bounded_distrib_allegory + kleene_algebra begin subclass bounded_kleene_algebra .. lemma conv_star_conv: "x⇧⋆ ≤ x⇧T⇧⋆⇧T" proof (-) (*goal: ‹x⇧⋆ ≤ x⇧T⇧⋆⇧T›*) have "x⇧T⇧⋆ * x⇧T ≤ x⇧T⇧⋆" by (simp add: star.right_plus_below_circ (*‹?x⇧⋆ * ?x ≤ ?x⇧⋆›*)) hence 1: "x * x⇧T⇧⋆⇧T ≤ x⇧T⇧⋆⇧T" using conv_dist_comp (*‹((?x::'a) * (?y::'a))⇧T = ?y⇧T * ?x⇧T›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) by fastforce have "1 ≤ x⇧T⇧⋆⇧T" by (simp add: reflexive_conv_closed (*‹reflexive ?x ⟹ reflexive (?x⇧T)›*) star.circ_reflexive (*‹reflexive (?x⇧⋆)›*)) hence "1 ⊔ x * x⇧T⇧⋆⇧T ≤ x⇧T⇧⋆⇧T" using "1" (*‹(x::'a) * x⇧T⇧⋆⇧T ≤ x⇧T⇧⋆⇧T›*) by simp thus "?thesis" (*goal: ‹x⇧⋆ ≤ x⇧T⇧⋆⇧T›*) using star_left_induct (*‹?z ⊔ ?y * ?x ≤ ?x ⟶ ?y⇧⋆ * ?z ≤ ?x›*) by fastforce qed text ‹ It follows that star and converse commute. › lemma conv_star_commute: "x⇧⋆⇧T = x⇧T⇧⋆" proof (rule order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹x⇧⋆⇧T ≤ x⇧T⇧⋆› 2. ‹x⇧T⇧⋆ ≤ x⇧⋆⇧T›*) show "x⇧⋆⇧T ≤ x⇧T⇧⋆" using conv_star_conv (*‹?x⇧⋆ ≤ ?x⇧T⇧⋆⇧T›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) by fastforce next (*goal: ‹x⇧T⇧⋆ ≤ x⇧⋆⇧T›*) show "x⇧T⇧⋆ ≤ x⇧⋆⇧T" by (metis conv_star_conv (*‹?x⇧⋆ ≤ ?x⇧T⇧⋆⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*)) qed lemma conv_plus_commute: "x⁺⇧T = x⇧T⁺" by (simp add: conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) star_plus (*‹?y⇧⋆ * ?y = ?y⁺›*)) text ‹Lemma ‹reflexive_inf_star› was contributed by Nicolas Robinson-O'Brien.› lemma reflexive_inf_star: assumes "reflexive y" shows "y ⊓ x⇧⋆ = 1 ⊔ (y ⊓ x⁺)" by (simp add: assms (*‹reflexive y›*) star_left_unfold_equal (*‹1 ⊔ ?x⁺ = ?x⇧⋆›*) sup.absorb2 (*‹?a ≤ ?b ⟹ ?a ⊔ ?b = ?b›*) sup_inf_distrib1 (*‹?x ⊔ ?y ⊓ ?z = (?x ⊔ ?y) ⊓ (?x ⊔ ?z)›*)) text ‹ The following results are variants of a separation lemma of Kleene algebras. › lemma cancel_separate_2: assumes "x * y ≤ 1" shows "((w ⊓ x) ⊔ (z ⊓ y))⇧⋆ = (z ⊓ y)⇧⋆ * (w ⊓ x)⇧⋆" proof (-) (*goal: ‹(w ⊓ x ⊔ z ⊓ y)⇧⋆ = (z ⊓ y)⇧⋆ * (w ⊓ x)⇧⋆›*) have "(w ⊓ x) * (z ⊓ y) ≤ 1" by (meson assms (*‹coreflexive (x * y)›*) comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) order.trans (*‹⟦?a ≤ ?b; ?b ≤ ?c⟧ ⟹ ?a ≤ ?c›*) inf.cobounded2 (*‹?a ⊓ ?b ≤ ?b›*)) thus "?thesis" (*goal: ‹(w ⊓ x ⊔ z ⊓ y)⇧⋆ = (z ⊓ y)⇧⋆ * (w ⊓ x)⇧⋆›*) using cancel_separate_1 (*‹coreflexive (?x * ?y) ⟹ (?x ⊔ ?y)⇧⋆ = ?y⇧⋆ * ?x⇧⋆›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*) by simp qed lemma cancel_separate_3: assumes "x * y ≤ 1" shows "(w ⊓ x)⇧⋆ * (z ⊓ y)⇧⋆ = (w ⊓ x)⇧⋆ ⊔ (z ⊓ y)⇧⋆" proof (-) (*goal: ‹(w ⊓ x)⇧⋆ * (z ⊓ y)⇧⋆ = (w ⊓ x)⇧⋆ ⊔ (z ⊓ y)⇧⋆›*) have "(w ⊓ x) * (z ⊓ y) ≤ 1" by (meson assms (*‹coreflexive (x * y)›*) comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) order.trans (*‹⟦?a ≤ ?b; ?b ≤ ?c⟧ ⟹ ?a ≤ ?c›*) inf.cobounded2 (*‹?a ⊓ ?b ≤ ?b›*)) thus "?thesis" (*goal: ‹(w ⊓ x)⇧⋆ * (z ⊓ y)⇧⋆ = (w ⊓ x)⇧⋆ ⊔ (z ⊓ y)⇧⋆›*) by (simp add: cancel_separate_eq (*‹coreflexive (?x * ?y) ⟹ ?x⇧⋆ * ?y⇧⋆ = ?x⇧⋆ ⊔ ?y⇧⋆›*)) qed lemma cancel_separate_4: assumes "z * y ≤ 1" and "w ≤ y ⊔ z" and "x ≤ y ⊔ z" shows "w⇧⋆ * x⇧⋆ = (w ⊓ y)⇧⋆ * ((w ⊓ z)⇧⋆ ⊔ (x ⊓ y)⇧⋆) * (x ⊓ z)⇧⋆" proof (-) (*goal: ‹w⇧⋆ * x⇧⋆ = (w ⊓ y)⇧⋆ * ((w ⊓ z)⇧⋆ ⊔ (x ⊓ y)⇧⋆) * (x ⊓ z)⇧⋆›*) have "w⇧⋆ * x⇧⋆ = ((w ⊓ y) ⊔ (w ⊓ z))⇧⋆ * ((x ⊓ y) ⊔ (x ⊓ z))⇧⋆" by (metis assms( (*‹(w::'a) ≤ (y::'a) ⊔ (z::'a)› ‹(x::'a) ≤ (y::'a) ⊔ (z::'a)›*) 2,3) inf.orderE (*‹⟦(?a::'a) ≤ (?b::'a); ?a = ?a ⊓ ?b ⟹ ?thesis::bool⟧ ⟹ ?thesis›*) inf_sup_distrib1 (*‹(?x::'a) ⊓ ((?y::'a) ⊔ (?z::'a)) = ?x ⊓ ?y ⊔ ?x ⊓ ?z›*)) also (*calculation: ‹w⇧⋆ * x⇧⋆ = (w ⊓ y ⊔ w ⊓ z)⇧⋆ * (x ⊓ y ⊔ x ⊓ z)⇧⋆›*) have "... = (w ⊓ y)⇧⋆ * ((w ⊓ z)⇧⋆ * (x ⊓ y)⇧⋆) * (x ⊓ z)⇧⋆" by (metis assms( (*‹coreflexive (z * y)›*) 1) cancel_separate_2 (*‹coreflexive (?x * ?y) ⟹ (?w ⊓ ?x ⊔ ?z ⊓ ?y)⇧⋆ = (?z ⊓ ?y)⇧⋆ * (?w ⊓ ?x)⇧⋆›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) finally (*calculation: ‹w⇧⋆ * x⇧⋆ = (w ⊓ y)⇧⋆ * ((w ⊓ z)⇧⋆ * (x ⊓ y)⇧⋆) * (x ⊓ z)⇧⋆›*) show "?thesis" (*goal: ‹w⇧⋆ * x⇧⋆ = (w ⊓ y)⇧⋆ * ((w ⊓ z)⇧⋆ ⊔ (x ⊓ y)⇧⋆) * (x ⊓ z)⇧⋆›*) by (simp add: assms( (*‹coreflexive ((z::'a::type) * (y::'a::type))›*) 1) cancel_separate_3 (*‹coreflexive ((?x::'a::type) * (?y::'a::type)) ⟹ ((?w::'a::type) ⊓ ?x)⇧⋆ * ((?z::'a::type) ⊓ ?y)⇧⋆ = (?w ⊓ ?x)⇧⋆ ⊔ (?z ⊓ ?y)⇧⋆›*)) qed lemma cancel_separate_5: assumes "w * z⇧T ≤ 1" shows "w ⊓ x * (y ⊓ z) ≤ y" proof (-) (*goal: ‹w ⊓ x * (y ⊓ z) ≤ y›*) have "w ⊓ x * (y ⊓ z) ≤ (x ⊓ w * (y ⊓ z)⇧T) * (y ⊓ z)" by (metis dedekind_2 (*‹?y * ?x ⊓ ?z ≤ (?y ⊓ ?z * ?x⇧T) * ?x›*) inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*)) also (*calculation: ‹w ⊓ x * (y ⊓ z) ≤ (x ⊓ w * (y ⊓ z)⇧T) * (y ⊓ z)›*) have "... ≤ w * z⇧T * (y ⊓ z)" by (simp add: conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) inf.coboundedI2 (*‹?b ≤ ?c ⟹ ?a ⊓ ?b ≤ ?c›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹(w::'a) ⊓ (x::'a) * ((y::'a) ⊓ (z::'a)) ≤ w * z⇧T * (y ⊓ z)›*) have "... ≤ y ⊓ z" by (metis assms (*‹coreflexive (w * z⇧T)›*) mult_1_left (*‹1 * ?a = ?a›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) finally (*calculation: ‹w ⊓ x * (y ⊓ z) ≤ y ⊓ z›*) show "?thesis" (*goal: ‹w ⊓ x * (y ⊓ z) ≤ y›*) by simp qed lemma cancel_separate_6: assumes "z * y ≤ 1" and "w ≤ y ⊔ z" and "x ≤ y ⊔ z" and "v * z⇧T ≤ 1" and "v ⊓ y⇧⋆ = bot" shows "v ⊓ w⇧⋆ * x⇧⋆ ≤ x ⊔ w" proof (-) (*goal: ‹v ⊓ w⇧⋆ * x⇧⋆ ≤ x ⊔ w›*) have "v ⊓ (w ⊓ y)⇧⋆ * (x ⊓ y)⇧⋆ ≤ v ⊓ y⇧⋆ * (x ⊓ y)⇧⋆" using comp_inf.mult_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊓ ?x ≤ ?z ⊓ ?y›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) by simp also (*calculation: ‹v ⊓ (w ⊓ y)⇧⋆ * (x ⊓ y)⇧⋆ ≤ v ⊓ y⇧⋆ * (x ⊓ y)⇧⋆›*) have "... ≤ v ⊓ y⇧⋆" by (simp add: inf.coboundedI2 (*‹?b ≤ ?c ⟹ ?a ⊓ ?b ≤ ?c›*) star.circ_increasing (*‹?x ≤ ?x⇧⋆›*) star.circ_mult_upper_bound (*‹⟦?x ≤ ?z⇧⋆; ?y ≤ ?z⇧⋆⟧ ⟹ ?x * ?y ≤ ?z⇧⋆›*) star_right_induct_mult (*‹?y * ?x ≤ ?y ⟹ ?y * ?x⇧⋆ ≤ ?y›*)) finally (*calculation: ‹v ⊓ (w ⊓ y)⇧⋆ * (x ⊓ y)⇧⋆ ≤ v ⊓ y⇧⋆›*) have 1: "v ⊓ (w ⊓ y)⇧⋆ * (x ⊓ y)⇧⋆ = bot" using assms(5) (*‹v ⊓ y⇧⋆ = bot›*) le_bot (*‹?a ≤ bot ⟹ ?a = bot›*) by simp have "v ⊓ w⇧⋆ * x⇧⋆ = v ⊓ (w ⊓ y)⇧⋆ * ((w ⊓ z)⇧⋆ ⊔ (x ⊓ y)⇧⋆) * (x ⊓ z)⇧⋆" using assms(1-3) (*‹coreflexive ((z::'a) * (y::'a))› ‹w ≤ y ⊔ z› ‹(x::'a::type) ≤ (y::'a::type) ⊔ (z::'a::type)›*) cancel_separate_4 (*‹⟦coreflexive ((?z::'a::type) * (?y::'a::type)); (?w::'a::type) ≤ ?y ⊔ ?z; (?x::'a::type) ≤ ?y ⊔ ?z⟧ ⟹ ?w⇧⋆ * ?x⇧⋆ = (?w ⊓ ?y)⇧⋆ * ((?w ⊓ ?z)⇧⋆ ⊔ (?x ⊓ ?y)⇧⋆) * (?x ⊓ ?z)⇧⋆›*) by simp also (*calculation: ‹v ⊓ w⇧⋆ * x⇧⋆ = v ⊓ (w ⊓ y)⇧⋆ * ((w ⊓ z)⇧⋆ ⊔ (x ⊓ y)⇧⋆) * (x ⊓ z)⇧⋆›*) have "... = (v ⊓ (w ⊓ y)⇧⋆ * ((w ⊓ z)⇧⋆ ⊔ (x ⊓ y)⇧⋆) * (x ⊓ z)⇧⋆ * (x ⊓ z)) ⊔ (v ⊓ (w ⊓ y)⇧⋆ * ((w ⊓ z)⇧⋆ ⊔ (x ⊓ y)⇧⋆))" by (metis inf_sup_distrib1 (*‹(?x::'a) ⊓ ((?y::'a) ⊔ (?z::'a)) = ?x ⊓ ?y ⊔ ?x ⊓ ?z›*) star.circ_back_loop_fixpoint (*‹(?z::'a) * (?y::'a)⇧⋆ * ?y ⊔ ?z = ?z * ?y⇧⋆›*)) also (*calculation: ‹v ⊓ w⇧⋆ * x⇧⋆ = v ⊓ (w ⊓ y)⇧⋆ * ((w ⊓ z)⇧⋆ ⊔ (x ⊓ y)⇧⋆) * (x ⊓ z)⇧⋆ * (x ⊓ z) ⊔ v ⊓ (w ⊓ y)⇧⋆ * ((w ⊓ z)⇧⋆ ⊔ (x ⊓ y)⇧⋆)›*) have "... ≤ x ⊔ (v ⊓ (w ⊓ y)⇧⋆ * ((w ⊓ z)⇧⋆ ⊔ (x ⊓ y)⇧⋆))" using assms(4) (*‹coreflexive ((v::'a) * (z::'a)⇧T)›*) cancel_separate_5 (*‹coreflexive ((?w::'a) * (?z::'a)⇧T) ⟹ ?w ⊓ (?x::'a) * ((?y::'a) ⊓ ?z) ≤ ?y›*) semiring.add_right_mono (*‹?a ≤ ?b ⟹ ?a ⊔ ?c ≤ ?b ⊔ ?c›*) by simp also (*calculation: ‹v ⊓ w⇧⋆ * x⇧⋆ ≤ x ⊔ v ⊓ (w ⊓ y)⇧⋆ * ((w ⊓ z)⇧⋆ ⊔ (x ⊓ y)⇧⋆)›*) have "... = x ⊔ (v ⊓ (w ⊓ y)⇧⋆ * (w ⊓ z)⇧⋆)" using "1" (*‹(v::'a) ⊓ ((w::'a) ⊓ (y::'a))⇧⋆ * ((x::'a) ⊓ y)⇧⋆ = bot›*) by (simp add: inf_sup_distrib1 (*‹?x ⊓ (?y ⊔ ?z) = ?x ⊓ ?y ⊔ ?x ⊓ ?z›*) mult_left_dist_sup (*‹?x * (?y ⊔ ?z) = ?x * ?y ⊔ ?x * ?z›*) sup_monoid.add_assoc (*‹?a ⊔ ?b ⊔ ?c = ?a ⊔ (?b ⊔ ?c)›*)) also (*calculation: ‹v ⊓ w⇧⋆ * x⇧⋆ ≤ x ⊔ v ⊓ (w ⊓ y)⇧⋆ * (w ⊓ z)⇧⋆›*) have "... = x ⊔ (v ⊓ (w ⊓ y)⇧⋆ * (w ⊓ z)⇧⋆ * (w ⊓ z)) ⊔ (v ⊓ (w ⊓ y)⇧⋆)" by (metis comp_inf.semiring.distrib_left (*‹?a ⊓ (?b ⊔ ?c) = ?a ⊓ ?b ⊔ ?a ⊓ ?c›*) star.circ_back_loop_fixpoint (*‹?z * ?y⇧⋆ * ?y ⊔ ?z = ?z * ?y⇧⋆›*) sup_assoc (*‹?x ⊔ ?y ⊔ ?z = ?x ⊔ (?y ⊔ ?z)›*)) also (*calculation: ‹v ⊓ w⇧⋆ * x⇧⋆ ≤ x ⊔ v ⊓ (w ⊓ y)⇧⋆ * (w ⊓ z)⇧⋆ * (w ⊓ z) ⊔ v ⊓ (w ⊓ y)⇧⋆›*) have "... ≤ x ⊔ w ⊔ (v ⊓ (w ⊓ y)⇧⋆)" using assms(4) (*‹coreflexive ((v::'a) * (z::'a)⇧T)›*) cancel_separate_5 (*‹coreflexive (?w * ?z⇧T) ⟹ ?w ⊓ ?x * (?y ⊓ ?z) ≤ ?y›*) sup_left_isotone (*‹?x ≤ ?y ⟹ ?x ⊔ ?z ≤ ?y ⊔ ?z›*) sup_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊔ ?x ≤ ?z ⊔ ?y›*) by simp also (*calculation: ‹v ⊓ w⇧⋆ * x⇧⋆ ≤ x ⊔ w ⊔ v ⊓ (w ⊓ y)⇧⋆›*) have "... ≤ x ⊔ w ⊔ (v ⊓ y⇧⋆)" using comp_inf.mult_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊓ ?x ≤ ?z ⊓ ?y›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) sup_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊔ ?x ≤ ?z ⊔ ?y›*) by simp finally (*calculation: ‹v ⊓ w⇧⋆ * x⇧⋆ ≤ x ⊔ w ⊔ v ⊓ y⇧⋆›*) show "?thesis" (*goal: ‹v ⊓ w⇧⋆ * x⇧⋆ ≤ x ⊔ w›*) using assms(5) (*‹v ⊓ y⇧⋆ = bot›*) le_bot (*‹(?a::'a) ≤ bot ⟹ ?a = bot›*) by simp qed text ‹ We show several results about the interaction of vectors and the Kleene star. › lemma vector_star_1: assumes "vector x" shows "x⇧T * (x * x⇧T)⇧⋆ ≤ x⇧T" proof (-) (*goal: ‹x⇧T * (x * x⇧T)⇧⋆ ≤ x⇧T›*) have "x⇧T * (x * x⇧T)⇧⋆ = (x⇧T * x)⇧⋆ * x⇧T" by (simp add: star_slide (*‹(?x * ?y)⇧⋆ * ?x = ?x * (?y * ?x)⇧⋆›*)) also (*calculation: ‹x⇧T * (x * x⇧T)⇧⋆ = (x⇧T * x)⇧⋆ * x⇧T›*) have "... ≤ top * x⇧T" by (simp add: mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) also (*calculation: ‹(x::'a::type)⇧T * (x * x⇧T)⇧⋆ ≤ top * x⇧T›*) have "... = x⇧T" using assms (*‹vector x›*) vector_conv_covector (*‹vector (?v::'a) = covector (?v⇧T)›*) by auto finally (*calculation: ‹x⇧T * (x * x⇧T)⇧⋆ ≤ x⇧T›*) show "?thesis" (*goal: ‹x⇧T * (x * x⇧T)⇧⋆ ≤ x⇧T›*) . qed lemma vector_star_2: "vector x ⟹ x⇧T * (x * x⇧T)⇧⋆ ≤ x⇧T * bot⇧⋆" by (simp add: star_absorb (*‹?x * ?y = bot ⟹ ?x * ?y⇧⋆ = ?x›*) vector_star_1 (*‹vector ?x ⟹ ?x⇧T * (?x * ?x⇧T)⇧⋆ ≤ ?x⇧T›*)) lemma vector_vector_star: "vector v ⟹ (v * v⇧T)⇧⋆ = 1 ⊔ v * v⇧T" by (simp add: transitive_star (*‹transitive ?x ⟹ ?x⇧⋆ = 1 ⊔ ?x›*) vv_transitive (*‹vector ?v ⟹ transitive (?v * ?v⇧T)›*)) lemma equivalence_star_closed: "equivalence x ⟹ equivalence (x⇧⋆)" by (simp add: conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) star.circ_reflexive (*‹reflexive (?x⇧⋆)›*) star.circ_transitive_equal (*‹idempotent (?x⇧⋆)›*)) lemma equivalence_plus_closed: "equivalence x ⟹ equivalence (x⁺)" by (simp add: conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) star.circ_reflexive (*‹reflexive (?x⇧⋆)›*) star.circ_sup_one_left_unfold (*‹reflexive ?x ⟹ ?x⁺ = ?x⇧⋆›*) star.circ_transitive_equal (*‹idempotent (?x⇧⋆)›*)) text ‹ The following equivalence relation characterises the component trees of a forest. This is a special case of undirected reachability in a directed graph. › abbreviation "forest_components f ≡ f⇧T⇧⋆ * f⇧⋆" lemma forest_components_equivalence: "injective x ⟹ equivalence (forest_components x)" apply (intro conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹injective (x::'a) ⟹ reflexive (forest_components x)› 2. ‹injective (x::'a) ⟹ transitive (forest_components x)› 3. ‹injective (x::'a) ⟹ symmetric (forest_components x)› discuss goal 1*) apply (simp add: reflexive_mult_closed (*‹⟦reflexive ?x; reflexive ?y⟧ ⟹ reflexive (?x * ?y)›*) star.circ_reflexive (*‹reflexive (?x⇧⋆)›*)) (*discuss goal 2*) apply (metis cancel_separate_1 (*‹coreflexive (?x * ?y) ⟹ (?x ⊔ ?y)⇧⋆ = ?y⇧⋆ * ?x⇧⋆›*) order.eq_iff (*‹(?a = ?b) = (?a ≤ ?b ∧ ?b ≤ ?a)›*) star.circ_transitive_equal (*‹idempotent (?x⇧⋆)›*)) (*discuss goal 3*) apply (simp add: conv_dist_comp (*‹((?x::'a) * (?y::'a))⇧T = ?y⇧T * ?x⇧T›*) conv_star_commute (*‹(?x::'a)⇧⋆⇧T = ?x⇧T⇧⋆›*)) (*proven 3 subgoals*) . lemma forest_components_increasing: "x ≤ forest_components x" by (metis order.trans (*‹⟦?a ≤ ?b; ?b ≤ ?c⟧ ⟹ ?a ≤ ?c›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_left_one (*‹1 * ?x = ?x›*) star.circ_increasing (*‹?x ≤ ?x⇧⋆›*) star.circ_reflexive (*‹reflexive (?x⇧⋆)›*)) lemma forest_components_isotone: "x ≤ y ⟹ forest_components x ≤ forest_components y" by (simp add: comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) lemma forest_components_idempotent: "injective x ⟹ forest_components (forest_components x) = forest_components x" by (metis forest_components_equivalence (*‹injective (?x::'a) ⟹ equivalence (forest_components ?x)›*) cancel_separate_1 (*‹coreflexive ((?x::'a) * (?y::'a)) ⟹ (?x ⊔ ?y)⇧⋆ = ?y⇧⋆ * ?x⇧⋆›*) star.circ_transitive_equal (*‹idempotent ((?x::'a)⇧⋆)›*) star_involutive (*‹(?x::'a)⇧⋆ = ?x⇧⋆⇧⋆›*)) lemma forest_components_star: "injective x ⟹ (forest_components x)⇧⋆ = forest_components x" using forest_components_equivalence (*‹injective ?x ⟹ equivalence (forest_components ?x)›*) forest_components_idempotent (*‹injective ?x ⟹ forest_components (forest_components ?x) = forest_components ?x›*) star.circ_transitive_equal (*‹idempotent (?x⇧⋆)›*) by simp text ‹ The following lemma shows that the nodes reachable in the graph can be reached by only using edges between reachable nodes. › lemma reachable_restrict: assumes "vector r" shows "r⇧T * g⇧⋆ = r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆" proof (-) (*goal: ‹(r::'a)⇧T * (g::'a)⇧⋆ = r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆›*) have 1: "r⇧T ≤ r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆" using mult_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*) mult_1_right (*‹(?a::'a) * (1::'a) = ?a›*) star.circ_reflexive (*‹reflexive (?x⇧⋆)›*) by fastforce have 2: "covector (r⇧T * g⇧⋆)" using assms (*‹vector (r::'a::type)›*) covector_mult_closed (*‹covector ?x ⟹ covector (?x * ?y)›*) vector_conv_covector (*‹vector (?v::'a::type) = covector (?v⇧T)›*) by auto have "r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆ * g ≤ r⇧T * g⇧⋆ * g" by (simp add: mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) also (*calculation: ‹(r::'a)⇧T * ((r⇧T * (g::'a)⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆ * g ≤ r⇧T * g⇧⋆ * g›*) have "... ≤ r⇧T * g⇧⋆" by (simp add: mult_assoc (*‹(?a::'a) * (?b::'a) * (?c::'a) = ?a * (?b * ?c)›*) mult_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*) star.left_plus_below_circ (*‹(?x::'a)⁺ ≤ ?x⇧⋆›*) star_plus (*‹(?y::'a)⇧⋆ * ?y = ?y⁺›*)) finally (*calculation: ‹(r::'a::type)⇧T * ((r⇧T * (g::'a::type)⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆ * g ≤ r⇧T * g⇧⋆›*) have "r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆ * g = r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆ * g ⊓ r⇧T * g⇧⋆" by (simp add: le_iff_inf (*‹(?x ≤ ?y) = (?x ⊓ ?y = ?x)›*)) also (*calculation: ‹r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆ * g = r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆ * g ⊓ r⇧T * g⇧⋆›*) have "... = r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆ * (g ⊓ r⇧T * g⇧⋆)" using assms (*‹vector r›*) covector_comp_inf (*‹covector (?z::'a) ⟹ (?x::'a) * ((?y::'a) ⊓ ?z) = ?x * ?y ⊓ ?z›*) covector_mult_closed (*‹covector ?x ⟹ covector (?x * ?y)›*) vector_conv_covector (*‹vector ?v = covector (?v⇧T)›*) by auto also (*calculation: ‹r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆ * g = r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆ * (g ⊓ r⇧T * g⇧⋆)›*) have "... = (r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆ ⊓ r⇧T * g⇧⋆) * (g ⊓ r⇧T * g⇧⋆)" by (simp add: inf.absorb2 (*‹?b ≤ ?a ⟹ ?a ⊓ ?b = ?b›*) inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) also (*calculation: ‹r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆ * g = (r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆ ⊓ r⇧T * g⇧⋆) * (g ⊓ r⇧T * g⇧⋆)›*) have "... = r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆ * (g ⊓ r⇧T * g⇧⋆ ⊓ (r⇧T * g⇧⋆)⇧T)" using "2" (*‹covector (r⇧T * g⇧⋆)›*) by (metis comp_inf_vector_1 (*‹((?x::'a) ⊓ top * (?y::'a)) * (?z::'a) = ?x * (?z ⊓ (top * ?y)⇧T)›*)) also (*calculation: ‹r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆ * g = r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆ * (g ⊓ r⇧T * g⇧⋆ ⊓ (r⇧T * g⇧⋆)⇧T)›*) have "... = r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆ * ((r⇧T * g⇧⋆)⇧T ⊓ r⇧T * g⇧⋆ ⊓ g)" using inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) inf_assoc (*‹?x ⊓ ?y ⊓ ?z = ?x ⊓ (?y ⊓ ?z)›*) by simp also (*calculation: ‹(r::'a)⇧T * ((r⇧T * (g::'a)⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆ * g = r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆ * ((r⇧T * g⇧⋆)⇧T ⊓ r⇧T * g⇧⋆ ⊓ g)›*) have "... = r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆ * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)" using "2" (*‹covector (r⇧T * g⇧⋆)›*) by (metis covector_conv_vector (*‹covector ?v = vector (?v⇧T)›*) inf_top.right_neutral (*‹?a ⊓ top = ?a›*) vector_inf_comp (*‹vector ?x ⟹ (?x ⊓ ?y) * ?z = ?x ⊓ ?y * ?z›*)) also (*calculation: ‹r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆ * g = r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆ * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)›*) have "... ≤ r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆" by (simp add: mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star.left_plus_below_circ (*‹?x⁺ ≤ ?x⇧⋆›*) star_plus (*‹?y⇧⋆ * ?y = ?y⁺›*)) finally (*calculation: ‹r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆ * g ≤ r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆›*) have "r⇧T * g⇧⋆ ≤ r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆" using "1" (*‹r⇧T ≤ r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆›*) star_right_induct (*‹?z ⊔ ?x * ?y ≤ ?x ⟶ ?z * ?y⇧⋆ ≤ ?x›*) by auto thus "?thesis" (*goal: ‹(r::'a)⇧T * (g::'a)⇧⋆ = r⇧T * ((r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g)⇧⋆›*) by (simp add: order.eq_iff (*‹(?a = ?b) = (?a ≤ ?b ∧ ?b ≤ ?a)›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) qed lemma kruskal_acyclic_inv_1: assumes "injective f" and "e * forest_components f * e = bot" shows "(f ⊓ top * e * f⇧T⇧⋆)⇧T * f⇧⋆ * e = bot" proof (-) (*goal: ‹(f ⊓ top * e * f⇧T⇧⋆)⇧T * f⇧⋆ * e = bot›*) let ?q = "top * e * f⇧T⇧⋆" let ?F = "forest_components f" have "(f ⊓ ?q)⇧T * f⇧⋆ * e = ?q⇧T ⊓ f⇧T * f⇧⋆ * e" by (metis (mono_tags) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) covector_conv_vector (*‹covector ?v = vector (?v⇧T)›*) inf_vector_comp (*‹(?x ⊓ ?y * top) * ?z = ?y * top ⊓ ?x * ?z›*) vector_top_closed (*‹surjective top›*)) also (*calculation: ‹(f ⊓ top * e * f⇧T⇧⋆)⇧T * f⇧⋆ * e = (top * e * f⇧T⇧⋆)⇧T ⊓ f⇧T * f⇧⋆ * e›*) have "... ≤ ?q⇧T ⊓ ?F * e" using comp_inf.mult_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊓ ?x ≤ ?z ⊓ ?y›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) star.circ_increasing (*‹?x ≤ ?x⇧⋆›*) by simp also (*calculation: ‹(f ⊓ top * e * f⇧T⇧⋆)⇧T * f⇧⋆ * e ≤ (top * e * f⇧T⇧⋆)⇧T ⊓ forest_components f * e›*) have "... = f⇧⋆ * e⇧T * top ⊓ ?F * e" by (simp add: conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹((f::'a) ⊓ top * (e::'a) * f⇧T⇧⋆)⇧T * f⇧⋆ * e ≤ f⇧⋆ * e⇧T * top ⊓ forest_components f * e›*) have "... ≤ ?F * e⇧T * top ⊓ ?F * e" by (metis conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) conv_top (*‹symmetric top›*) inf.sup_left_isotone (*‹?y ≤ ?x ⟹ ?y ⊓ ?z ≤ ?x ⊓ ?z›*) star.circ_right_top (*‹times_top_class.total (?x⇧⋆)›*) star_outer_increasing (*‹?x ≤ ?y⇧⋆ * ?x * ?y⇧⋆›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹(f ⊓ top * e * f⇧T⇧⋆)⇧T * f⇧⋆ * e ≤ forest_components f * e⇧T * top ⊓ forest_components f * e›*) have "... = ?F * (e⇧T * top ⊓ ?F * e)" by (metis assms( (*‹injective f›*) 1) forest_components_equivalence (*‹injective ?x ⟹ equivalence (forest_components ?x)›*) equivalence_comp_dist_inf (*‹equivalence ?x ⟹ ?x * ?y ⊓ ?x * ?z = ?x * (?y ⊓ ?x * ?z)›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹(f ⊓ top * e * f⇧T⇧⋆)⇧T * f⇧⋆ * e ≤ forest_components f * (e⇧T * top ⊓ forest_components f * e)›*) have "... = (?F ⊓ top * e) * ?F * e" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_inf_vector_1 (*‹(?x ⊓ top * ?y) * ?z = ?x * (?z ⊓ (top * ?y)⇧T)›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) inf_vector_comp (*‹(?x ⊓ ?y * top) * ?z = ?y * top ⊓ ?x * ?z›*)) also (*calculation: ‹(f ⊓ top * e * f⇧T⇧⋆)⇧T * f⇧⋆ * e ≤ (forest_components f ⊓ top * e) * forest_components f * e›*) have "... ≤ top * e * ?F * e" by (simp add: mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) also (*calculation: ‹(f ⊓ top * e * f⇧T⇧⋆)⇧T * f⇧⋆ * e ≤ top * e * forest_components f * e›*) have "... = bot" using assms(2) (*‹e * forest_components f * e = bot›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) by simp finally (*calculation: ‹(f ⊓ top * e * f⇧T⇧⋆)⇧T * f⇧⋆ * e ≤ bot›*) show "?thesis" (*goal: ‹(f ⊓ top * e * f⇧T⇧⋆)⇧T * f⇧⋆ * e = bot›*) by (simp add: bot_unique (*‹(?a ≤ bot) = (?a = bot)›*)) qed lemma kruskal_forest_components_inf_1: assumes "f ≤ w ⊔ w⇧T" and "injective w" and "f ≤ forest_components g" shows "f * forest_components (forest_components g ⊓ w) ≤ forest_components (forest_components g ⊓ w)" proof (-) (*goal: ‹f * forest_components (forest_components g ⊓ w) ≤ forest_components (forest_components g ⊓ w)›*) let ?f = "forest_components g" let ?w = "forest_components (?f ⊓ w)" have "f * ?w = (f ⊓ (w ⊔ w⇧T)) * ?w" by (simp add: assms( (*‹f ≤ w ⊔ w⇧T›*) 1) inf.absorb1 (*‹?a ≤ ?b ⟹ ?a ⊓ ?b = ?a›*)) also (*calculation: ‹f * forest_components (forest_components g ⊓ w) = (f ⊓ (w ⊔ w⇧T)) * forest_components (forest_components g ⊓ w)›*) have "... = (f ⊓ w) * ?w ⊔ (f ⊓ w⇧T) * ?w" by (simp add: inf_sup_distrib1 (*‹?x ⊓ (?y ⊔ ?z) = ?x ⊓ ?y ⊔ ?x ⊓ ?z›*) semiring.distrib_right (*‹(?a ⊔ ?b) * ?c = ?a * ?c ⊔ ?b * ?c›*)) also (*calculation: ‹(f::'a) * forest_components (forest_components (g::'a) ⊓ (w::'a)) = (f ⊓ w) * forest_components (forest_components g ⊓ w) ⊔ (f ⊓ w⇧T) * forest_components (forest_components g ⊓ w)›*) have "... ≤ (?f ⊓ w) * ?w ⊔ (f ⊓ w⇧T) * ?w" using assms(3) (*‹f ≤ forest_components g›*) inf.sup_left_isotone (*‹?y ≤ ?x ⟹ ?y ⊓ ?z ≤ ?x ⊓ ?z›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) sup_left_isotone (*‹?x ≤ ?y ⟹ ?x ⊔ ?z ≤ ?y ⊔ ?z›*) by simp also (*calculation: ‹f * forest_components (forest_components g ⊓ w) ≤ (forest_components g ⊓ w) * forest_components (forest_components g ⊓ w) ⊔ (f ⊓ w⇧T) * forest_components (forest_components g ⊓ w)›*) have "... ≤ (?f ⊓ w) * ?w ⊔ (?f ⊓ w⇧T) * ?w" using assms(3) (*‹(f::'a) ≤ forest_components (g::'a)›*) inf.sup_left_isotone (*‹?y ≤ ?x ⟹ ?y ⊓ ?z ≤ ?x ⊓ ?z›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) sup_right_isotone (*‹(?x::'a::type) ≤ (?y::'a::type) ⟹ (?z::'a::type) ⊔ ?x ≤ ?z ⊔ ?y›*) by simp also (*calculation: ‹(f::'a) * forest_components (forest_components (g::'a) ⊓ (w::'a)) ≤ (forest_components g ⊓ w) * forest_components (forest_components g ⊓ w) ⊔ (forest_components g ⊓ w⇧T) * forest_components (forest_components g ⊓ w)›*) have "... = (?f ⊓ w) * ?w ⊔ (?f ⊓ w)⇧T * ?w" by (simp add: conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*)) also (*calculation: ‹(f::'a) * forest_components (forest_components (g::'a) ⊓ (w::'a)) ≤ (forest_components g ⊓ w) * forest_components (forest_components g ⊓ w) ⊔ (forest_components g ⊓ w)⇧T * forest_components (forest_components g ⊓ w)›*) have "... ≤ (?f ⊓ w) * ?w ⊔ ?w" by (metis star.circ_loop_fixpoint (*‹(?y::'a) * (?y⇧⋆ * (?z::'a)) ⊔ ?z = ?y⇧⋆ * ?z›*) sup_ge1 (*‹(?x::'a) ≤ ?x ⊔ (?y::'a)›*) sup_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) ⊔ ?x ≤ ?z ⊔ ?y›*)) also (*calculation: ‹f * forest_components (forest_components g ⊓ w) ≤ (forest_components g ⊓ w) * forest_components (forest_components g ⊓ w) ⊔ forest_components (forest_components g ⊓ w)›*) have "... = ?w ⊔ (?f ⊓ w) * (?f ⊓ w)⇧⋆ ⊔ (?f ⊓ w) * (?f ⊓ w)⇧T⁺ * (?f ⊓ w)⇧⋆" by (metis comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) mult_left_dist_sup (*‹?x * (?y ⊔ ?z) = ?x * ?y ⊔ ?x * ?z›*) star.circ_loop_fixpoint (*‹?y * (?y⇧⋆ * ?z) ⊔ ?z = ?y⇧⋆ * ?z›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*) sup_assoc (*‹?x ⊔ ?y ⊔ ?z = ?x ⊔ (?y ⊔ ?z)›*)) also (*calculation: ‹f * forest_components (forest_components g ⊓ w) ≤ forest_components (forest_components g ⊓ w) ⊔ (forest_components g ⊓ w)⁺ ⊔ (forest_components g ⊓ w) * (forest_components g ⊓ w)⇧T⁺ * (forest_components g ⊓ w)⇧⋆›*) have "... ≤ ?w ⊔ (?f ⊓ w)⇧⋆ ⊔ (?f ⊓ w) * (?f ⊓ w)⇧T⁺ * (?f ⊓ w)⇧⋆" using star.left_plus_below_circ (*‹?x⁺ ≤ ?x⇧⋆›*) sup_left_isotone (*‹?x ≤ ?y ⟹ ?x ⊔ ?z ≤ ?y ⊔ ?z›*) sup_right_isotone (*‹(?x::'a::type) ≤ (?y::'a::type) ⟹ (?z::'a::type) ⊔ ?x ≤ ?z ⊔ ?y›*) by auto also (*calculation: ‹f * forest_components (forest_components g ⊓ w) ≤ forest_components (forest_components g ⊓ w) ⊔ (forest_components g ⊓ w)⇧⋆ ⊔ (forest_components g ⊓ w) * (forest_components g ⊓ w)⇧T⁺ * (forest_components g ⊓ w)⇧⋆›*) have "... = ?w ⊔ (?f ⊓ w) * (?f ⊓ w)⇧T⁺ * (?f ⊓ w)⇧⋆" by (metis star.circ_loop_fixpoint (*‹?y * (?y⇧⋆ * ?z) ⊔ ?z = ?y⇧⋆ * ?z›*) sup.right_idem (*‹?a ⊔ ?b ⊔ ?b = ?a ⊔ ?b›*)) also (*calculation: ‹f * forest_components (forest_components g ⊓ w) ≤ forest_components (forest_components g ⊓ w) ⊔ (forest_components g ⊓ w) * (forest_components g ⊓ w)⇧T⁺ * (forest_components g ⊓ w)⇧⋆›*) have "... ≤ ?w ⊔ w * w⇧T * ?w" using comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) mult_isotone (*‹⟦?w ≤ ?y; ?x ≤ ?z⟧ ⟹ ?w * ?x ≤ ?y * ?z›*) sup_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊔ ?x ≤ ?z ⊔ ?y›*) by simp also (*calculation: ‹f * forest_components (forest_components g ⊓ w) ≤ forest_components (forest_components g ⊓ w) ⊔ w * w⇧T * forest_components (forest_components g ⊓ w)›*) have "... = ?w" by (metis assms( (*‹injective (w::'a)›*) 2) coreflexive_comp_top_inf (*‹coreflexive (?x::'a) ⟹ ?x * top ⊓ (?y::'a) = ?x * ?y›*) inf.cobounded2 (*‹(?a::'a) ⊓ (?b::'a) ≤ ?b›*) sup.orderE (*‹⟦(?b::'a) ≤ (?a::'a); ?a = ?a ⊔ ?b ⟹ ?thesis::bool⟧ ⟹ ?thesis›*)) finally (*calculation: ‹f * forest_components (forest_components g ⊓ w) ≤ forest_components (forest_components g ⊓ w)›*) show "?thesis" (*goal: ‹f * forest_components (forest_components g ⊓ w) ≤ forest_components (forest_components g ⊓ w)›*) by simp qed lemma kruskal_forest_components_inf: assumes "f ≤ w ⊔ w⇧T" and "injective w" shows "forest_components f ≤ forest_components (forest_components f ⊓ w)" proof (-) (*goal: ‹forest_components (f::'a) ≤ forest_components (forest_components f ⊓ (w::'a))›*) let ?f = "forest_components f" let ?w = "forest_components (?f ⊓ w)" have 1: "1 ≤ ?w" by (simp add: reflexive_mult_closed (*‹⟦reflexive ?x; reflexive ?y⟧ ⟹ reflexive (?x * ?y)›*) star.circ_reflexive (*‹reflexive (?x⇧⋆)›*)) have "f * ?w ≤ ?w" using assms (*‹f ≤ w ⊔ w⇧T› ‹injective w›*) forest_components_increasing (*‹(?x::'a) ≤ forest_components ?x›*) kruskal_forest_components_inf_1 (*‹⟦(?f::'a) ≤ (?w::'a) ⊔ ?w⇧T; injective ?w; ?f ≤ forest_components (?g::'a)⟧ ⟹ ?f * forest_components (forest_components ?g ⊓ ?w) ≤ forest_components (forest_components ?g ⊓ ?w)›*) by simp hence 2: "f⇧⋆ ≤ ?w" using "1" (*‹reflexive (forest_components (forest_components f ⊓ w))›*) star_left_induct (*‹?z ⊔ ?y * ?x ≤ ?x ⟶ ?y⇧⋆ * ?z ≤ ?x›*) by fastforce have "f⇧T * ?w ≤ ?w" apply (rule kruskal_forest_components_inf_1 (*‹⟦?f ≤ ?w ⊔ ?w⇧T; injective ?w; ?f ≤ forest_components ?g⟧ ⟹ ?f * forest_components (forest_components ?g ⊓ ?w) ≤ forest_components (forest_components ?g ⊓ ?w)›*)) (*goals: 1. ‹f⇧T ≤ w ⊔ w⇧T› 2. ‹injective w› 3. ‹f⇧T ≤ forest_components f› discuss goal 1*) apply (metis assms( (*‹(f::'a::type) ≤ (w::'a::type) ⊔ w⇧T›*) 1) conv_dist_sup (*‹((?x::'a::type) ⊔ (?y::'a::type))⇧T = ?x⇧T ⊔ ?y⇧T›*) conv_involutive (*‹(?x::'a::type)⇧T⇧T = ?x›*) conv_isotone (*‹(?x::'a::type) ≤ (?y::'a::type) ⟹ ?x⇧T ≤ ?y⇧T›*) sup_commute (*‹(?x::'a::type) ⊔ (?y::'a::type) = ?y ⊔ ?x›*)) (*discuss goal 2*) apply (simp add: assms( (*‹injective w›*) 2)) (*discuss goal 3*) apply (metis le_supI2 (*‹?x ≤ ?b ⟹ ?x ≤ ?a ⊔ ?b›*) star.circ_back_loop_fixpoint (*‹?z * ?y⇧⋆ * ?y ⊔ ?z = ?z * ?y⇧⋆›*) star.circ_increasing (*‹?x ≤ ?x⇧⋆›*)) (*proven 3 subgoals*) . thus "?f ≤ ?w" using "2" (*‹(f::'a::type)⇧⋆ ≤ forest_components (forest_components f ⊓ (w::'a::type))›*) star_left_induct (*‹(?z::'a::type) ⊔ (?y::'a::type) * (?x::'a::type) ≤ ?x ⟶ ?y⇧⋆ * ?z ≤ ?x›*) by simp qed end text ‹ We next add the Kleene star to single-object pseudocomplemented distributive allegories. › class pd_kleene_allegory = pd_allegory + bounded_distrib_kleene_allegory begin text ‹ The following definitions and results concern acyclic graphs and forests. › abbreviation acyclic :: "'a ⇒ bool" where "acyclic x ≡ x⁺ ≤ -1" abbreviation forest :: "'a ⇒ bool" where "forest x ≡ injective x ∧ acyclic x" lemma forest_bot: "forest bot" by simp lemma acyclic_down_closed: "x ≤ y ⟹ acyclic y ⟹ acyclic x" using comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) by fastforce lemma forest_down_closed: "x ≤ y ⟹ forest y ⟹ forest x" using conv_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x⇧T ≤ ?y⇧T›*) mult_isotone (*‹⟦(?w::'a) ≤ (?y::'a); (?x::'a) ≤ (?z::'a)⟧ ⟹ ?w * ?x ≤ ?y * ?z›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) by fastforce lemma acyclic_star_below_complement: "acyclic w ⟷ w⇧T⇧⋆ ≤ -w" by (simp add: conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) schroeder_4_p (*‹(?x * ?y ≤ - ?z) = (?z * ?y⇧T ≤ - ?x)›*)) lemma acyclic_star_below_complement_1: "acyclic w ⟷ w⇧⋆ ⊓ w⇧T = bot" using pseudo_complement (*‹(?x ⊓ ?y = bot) = (?x ≤ - ?y)›*) schroeder_5_p (*‹(?x * ?y ≤ - ?z) = (?y * ?z⇧T ≤ - ?x⇧T)›*) by force lemma acyclic_star_inf_conv: assumes "acyclic w" shows "w⇧⋆ ⊓ w⇧T⇧⋆ = 1" proof (-) (*goal: ‹w⇧⋆ ⊓ w⇧T⇧⋆ = 1›*) have "w⁺ ⊓ w⇧T⇧⋆ ≤ (w ⊓ w⇧T⇧⋆) * w⇧⋆" by (metis conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) dedekind_2 (*‹?y * ?x ⊓ ?z ≤ (?y ⊓ ?z * ?x⇧T) * ?x›*) star.circ_transitive_equal (*‹idempotent (?x⇧⋆)›*)) also (*calculation: ‹w⁺ ⊓ w⇧T⇧⋆ ≤ (w ⊓ w⇧T⇧⋆) * w⇧⋆›*) have "... = bot" by (metis assms (*‹pd_kleene_allegory_class.acyclic w›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) p_antitone_iff (*‹(?x ≤ - ?y) = (?y ≤ - ?x)›*) pseudo_complement (*‹(?x ⊓ ?y = bot) = (?x ≤ - ?y)›*) schroeder_4_p (*‹(?x * ?y ≤ - ?z) = (?z * ?y⇧T ≤ - ?x)›*) semiring.mult_not_zero (*‹?a * ?b ≠ bot ⟹ ?a ≠ bot ∧ ?b ≠ bot›*) star.circ_circ_mult (*‹1⇧⋆ * ?x⇧⋆ = ?x⇧⋆⇧⋆›*) star_involutive (*‹?x⇧⋆ = ?x⇧⋆⇧⋆›*) star_one (*‹1⇧⋆ = 1›*)) finally (*calculation: ‹w⁺ ⊓ w⇧T⇧⋆ ≤ bot›*) have "w⇧⋆ ⊓ w⇧T⇧⋆ ≤ 1" by (metis order.eq_iff (*‹((?a::'a) = (?b::'a)) = (?a ≤ ?b ∧ ?b ≤ ?a)›*) le_bot (*‹(?a::'a) ≤ bot ⟹ ?a = bot›*) mult_left_zero (*‹bot * (?x::'a) = bot›*) star.circ_plus_one (*‹(?x::'a)⇧⋆ = (1::'a) ⊔ ?x⇧⋆›*) star.circ_zero (*‹bot⇧⋆ = (1::'a)›*) star_left_unfold_equal (*‹(1::'a) ⊔ (?x::'a)⁺ = ?x⇧⋆›*) sup_inf_distrib1 (*‹(?x::'a) ⊔ (?y::'a) ⊓ (?z::'a) = (?x ⊔ ?y) ⊓ (?x ⊔ ?z)›*)) thus "?thesis" (*goal: ‹(w::'a)⇧⋆ ⊓ w⇧T⇧⋆ = (1::'a)›*) by (simp add: order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*) star.circ_reflexive (*‹reflexive (?x⇧⋆)›*)) qed lemma acyclic_asymmetric: "acyclic w ⟹ asymmetric w" by (simp add: dual_order.trans (*‹⟦?b ≤ ?a; ?c ≤ ?b⟧ ⟹ ?c ≤ ?a›*) pseudo_complement (*‹(?x ⊓ ?y = bot) = (?x ≤ - ?y)›*) schroeder_5_p (*‹(?x * ?y ≤ - ?z) = (?y * ?z⇧T ≤ - ?x⇧T)›*) star.circ_increasing (*‹?x ≤ ?x⇧⋆›*)) lemma forest_separate: assumes "forest x" shows "x⇧⋆ * x⇧T⇧⋆ ⊓ x⇧T * x ≤ 1" proof (-) (*goal: ‹coreflexive (x⇧⋆ * x⇧T⇧⋆ ⊓ x⇧T * x)›*) have "x⇧⋆ * 1 ≤ -x⇧T" using assms (*‹forest x›*) schroeder_5_p (*‹(?x * ?y ≤ - ?z) = (?y * ?z⇧T ≤ - ?x⇧T)›*) by force hence 1: "x⇧⋆ ⊓ x⇧T = bot" by (simp add: pseudo_complement (*‹((?x::'a) ⊓ (?y::'a) = bot) = (?x ≤ - ?y)›*)) have "x⇧⋆ ⊓ x⇧T * x = (1 ⊔ x⇧⋆ * x) ⊓ x⇧T * x" using star.circ_right_unfold_1 (*‹Rf (?x⇧⋆) ?x = ?x⇧⋆›*) by simp also (*calculation: ‹(x::'a::type)⇧⋆ ⊓ x⇧T * x = Rf (x⇧⋆) x ⊓ x⇧T * x›*) have "... = (1 ⊓ x⇧T * x) ⊔ (x⇧⋆ * x ⊓ x⇧T * x)" by (simp add: inf_sup_distrib2 (*‹(?y ⊔ ?z) ⊓ ?x = ?y ⊓ ?x ⊔ ?z ⊓ ?x›*)) also (*calculation: ‹x⇧⋆ ⊓ x⇧T * x = 1 ⊓ x⇧T * x ⊔ x⇧⋆ * x ⊓ x⇧T * x›*) have "... ≤ 1 ⊔ (x⇧⋆ * x ⊓ x⇧T * x)" using sup_left_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x ⊔ (?z::'a) ≤ ?y ⊔ ?z›*) by simp also (*calculation: ‹x⇧⋆ ⊓ x⇧T * x ≤ 1 ⊔ x⇧⋆ * x ⊓ x⇧T * x›*) have "... = 1 ⊔ (x⇧⋆ ⊓ x⇧T) * x" by (simp add: assms (*‹forest x›*) injective_comp_right_dist_inf (*‹injective ?z ⟹ (?x ⊓ ?y) * ?z = ?x * ?z ⊓ ?y * ?z›*)) also (*calculation: ‹x⇧⋆ ⊓ x⇧T * x ≤ Rf (x⇧⋆ ⊓ x⇧T) x›*) have "... = 1" using "1" (*‹x⇧⋆ ⊓ x⇧T = bot›*) by simp finally (*calculation: ‹coreflexive (x⇧⋆ ⊓ x⇧T * x)›*) have 2: "x⇧⋆ ⊓ x⇧T * x ≤ 1" . hence 3: "x⇧T⇧⋆ ⊓ x⇧T * x ≤ 1" by (metis (mono_tags, lifting) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) coreflexive_symmetric (*‹coreflexive ?x ⟹ symmetric ?x›*)) have "x⇧⋆ * x⇧T⇧⋆ ⊓ x⇧T * x ≤ (x⇧⋆ ⊔ x⇧T⇧⋆) ⊓ x⇧T * x" using assms (*‹forest x›*) cancel_separate (*‹coreflexive (?x * ?y) ⟹ ?x⇧⋆ * ?y⇧⋆ ≤ ?x⇧⋆ ⊔ ?y⇧⋆›*) inf.sup_left_isotone (*‹?y ≤ ?x ⟹ ?y ⊓ ?z ≤ ?x ⊓ ?z›*) by simp also (*calculation: ‹(x::'a)⇧⋆ * x⇧T⇧⋆ ⊓ x⇧T * x ≤ (x⇧⋆ ⊔ x⇧T⇧⋆) ⊓ x⇧T * x›*) have "... ≤ 1" using "2" (*‹coreflexive (x⇧⋆ ⊓ x⇧T * x)›*) "3" (*‹coreflexive (x⇧T⇧⋆ ⊓ x⇧T * x)›*) by (simp add: inf_sup_distrib2 (*‹((?y::'a) ⊔ (?z::'a)) ⊓ (?x::'a) = ?y ⊓ ?x ⊔ ?z ⊓ ?x›*)) finally (*calculation: ‹coreflexive ((x::'a)⇧⋆ * x⇧T⇧⋆ ⊓ x⇧T * x)›*) show "?thesis" (*goal: ‹coreflexive (x⇧⋆ * x⇧T⇧⋆ ⊓ x⇧T * x)›*) . qed text ‹ The following definition captures the components of undirected weighted graphs. › abbreviation "components g ≡ (--g)⇧⋆" lemma components_equivalence: "symmetric x ⟹ equivalence (components x)" by (simp add: conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) star.circ_reflexive (*‹reflexive (?x⇧⋆)›*) star.circ_transitive_equal (*‹idempotent (?x⇧⋆)›*)) lemma components_increasing: "x ≤ components x" using order_trans (*‹⟦?x ≤ ?y; ?y ≤ ?z⟧ ⟹ ?x ≤ ?z›*) pp_increasing (*‹?x ≤ - - ?x›*) star.circ_increasing (*‹(?x::'a) ≤ ?x⇧⋆›*) by blast lemma components_isotone: "x ≤ y ⟹ components x ≤ components y" by (simp add: pp_isotone (*‹?x ≤ ?y ⟹ - - ?x ≤ - - ?y›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) lemma cut_reachable: assumes "v⇧T = r⇧T * t⇧⋆" and "t ≤ g" shows "v * -v⇧T ⊓ g ≤ (r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆)" proof (-) (*goal: ‹v * - v⇧T ⊓ g ≤ (r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆)›*) have "v * -v⇧T ⊓ g ≤ v * top ⊓ g" using inf.sup_left_isotone (*‹?y ≤ ?x ⟹ ?y ⊓ ?z ≤ ?x ⊓ ?z›*) mult_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*) top_greatest (*‹?x ≤ top›*) by blast also (*calculation: ‹(v::'a) * - v⇧T ⊓ (g::'a) ≤ v * top ⊓ g›*) have "... = (r⇧T * t⇧⋆)⇧T * top ⊓ g" by (metis assms( (*‹v⇧T = r⇧T * t⇧⋆›*) 1) conv_involutive (*‹?x⇧T⇧T = ?x›*)) also (*calculation: ‹v * - v⇧T ⊓ g ≤ (r⇧T * t⇧⋆)⇧T * top ⊓ g›*) have "... ≤ (r⇧T * g⇧⋆)⇧T * top ⊓ g" using assms(2) (*‹t ≤ g›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) inf.sup_left_isotone (*‹?y ≤ ?x ⟹ ?y ⊓ ?z ≤ ?x ⊓ ?z›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) by auto also (*calculation: ‹(v::'a::type) * - v⇧T ⊓ (g::'a::type) ≤ ((r::'a::type)⇧T * g⇧⋆)⇧T * top ⊓ g›*) have "... ≤ (r⇧T * g⇧⋆)⇧T * ((r⇧T * g⇧⋆) * g)" by (metis conv_involutive (*‹?x⇧T⇧T = ?x›*) dedekind_1 (*‹?x * ?y ⊓ ?z ≤ ?x * (?y ⊓ ?x⇧T * ?z)›*) inf_top.left_neutral (*‹top ⊓ ?a = ?a›*)) also (*calculation: ‹v * - v⇧T ⊓ g ≤ (r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆ * g)›*) have "... ≤ (r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆)" by (simp add: mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star.left_plus_below_circ (*‹?x⁺ ≤ ?x⇧⋆›*) star_plus (*‹?y⇧⋆ * ?y = ?y⁺›*)) finally (*calculation: ‹(v::'a) * - v⇧T ⊓ (g::'a) ≤ ((r::'a)⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆)›*) show "?thesis" (*goal: ‹v * - v⇧T ⊓ g ≤ (r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆)›*) . qed text ‹ The following lemma shows that the predecessors of visited nodes in the minimum spanning tree extending the current tree have all been visited. › lemma predecessors_reachable: assumes "vector r" and "injective r" and "v⇧T = r⇧T * t⇧⋆" and "forest w" and "t ≤ w" and "w ≤ (r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g" and "r⇧T * g⇧⋆ ≤ r⇧T * w⇧⋆" shows "w * v ≤ v" proof (-) (*goal: ‹w * v ≤ v›*) have "w * r ≤ (r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) * r" using assms(6) (*‹w ≤ (r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) by auto also (*calculation: ‹(w::'a) * (r::'a) ≤ (r⇧T * (g::'a)⇧⋆)⇧T * (r⇧T * g⇧⋆) * r›*) have "... ≤ (r⇧T * g⇧⋆)⇧T * top" by (simp add: mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹w * r ≤ (r⇧T * g⇧⋆)⇧T * top›*) have "... = (r⇧T * g⇧⋆)⇧T" by (simp add: assms( (*‹vector r›*) 1) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*)) also (*calculation: ‹w * r ≤ (r⇧T * g⇧⋆)⇧T›*) have "... ≤ (r⇧T * w⇧⋆)⇧T" by (simp add: assms( (*‹r⇧T * g⇧⋆ ≤ r⇧T * w⇧⋆›*) 7) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*)) also (*calculation: ‹w * r ≤ (r⇧T * w⇧⋆)⇧T›*) have "... = w⇧T⇧⋆ * r" by (simp add: conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*)) also (*calculation: ‹w * r ≤ w⇧T⇧⋆ * r›*) have "... ≤ -w * r" using assms(4) (*‹forest (w::'a::type)›*) by (simp add: mult_left_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x * (?z::'a) ≤ ?y * ?z›*) acyclic_star_below_complement (*‹pd_kleene_allegory_class.acyclic (?w::'a) = (?w⇧T⇧⋆ ≤ - ?w)›*)) also (*calculation: ‹w * r ≤ - w * r›*) have "... ≤ -(w * r)" by (simp add: assms( (*‹injective r›*) 2) comp_injective_below_complement (*‹injective ?y ⟹ - ?x * ?y ≤ - (?x * ?y)›*)) finally (*calculation: ‹(w::'a::type) * (r::'a::type) ≤ - (w * r)›*) have 1: "w * r = bot" by (simp add: le_iff_inf (*‹(?x ≤ ?y) = (?x ⊓ ?y = ?x)›*)) have "v = t⇧T⇧⋆ * r" by (metis assms( (*‹v⇧T = r⇧T * t⇧⋆›*) 3) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*)) also (*calculation: ‹v = t⇧T⇧⋆ * r›*) have "... = t⇧T * v ⊔ r" by (simp add: calculation (*‹(v::'a) = (t::'a)⇧T⇧⋆ * (r::'a)›*) star.circ_loop_fixpoint (*‹(?y::'a) * (?y⇧⋆ * (?z::'a)) ⊔ ?z = ?y⇧⋆ * ?z›*)) also (*calculation: ‹v = t⇧T * v ⊔ r›*) have "... ≤ w⇧T * v ⊔ r" using assms(5) (*‹t ≤ w›*) comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) semiring.add_right_mono (*‹?a ≤ ?b ⟹ ?a ⊔ ?c ≤ ?b ⊔ ?c›*) by auto finally (*calculation: ‹v ≤ w⇧T * v ⊔ r›*) have "w * v ≤ w * w⇧T * v ⊔ w * r" by (simp add: comp_left_dist_sup (*‹?x * ?y ⊔ ?x * ?z = ?x * (?y ⊔ ?z)›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹w * v ≤ w * w⇧T * v ⊔ w * r›*) have "... = w * w⇧T * v" using "1" (*‹w * r = bot›*) by simp also (*calculation: ‹w * v ≤ w * w⇧T * v›*) have "... ≤ v" using assms(4) (*‹forest w›*) by (simp add: star_left_induct_mult_iff (*‹(?x * ?y ≤ ?y) = (?x⇧⋆ * ?y ≤ ?y)›*) star_sub_one (*‹coreflexive ?x ⟹ ?x⇧⋆ = 1›*)) finally (*calculation: ‹(w::'a) * (v::'a) ≤ v›*) show "?thesis" (*goal: ‹w * v ≤ v›*) . qed subsection ‹Prim's Algorithm› text ‹ The following results are used for proving the correctness of Prim's minimum spanning tree algorithm. › subsubsection ‹Preservation of Invariant› text ‹ We first treat the preservation of the invariant. The following lemma shows that the while-loop preserves that ‹v› represents the nodes of the constructed tree. The remaining lemmas in this section show that ‹t› is a spanning tree. The exchange property is treated in the following two sections. › lemma reachable_inv: assumes "vector v" and "e ≤ v * -v⇧T" and "e * t = bot" and "v⇧T = r⇧T * t⇧⋆" shows "(v ⊔ e⇧T * top)⇧T = r⇧T * (t ⊔ e)⇧⋆" proof (-) (*goal: ‹(v ⊔ e⇧T * top)⇧T = r⇧T * (t ⊔ e)⇧⋆›*) have 1: "v⇧T ≤ r⇧T * (t ⊔ e)⇧⋆" by (simp add: assms( (*‹v⇧T = r⇧T * t⇧⋆›*) 4) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star.circ_sub_dist (*‹?x⇧⋆ ≤ (?x ⊔ ?y)⇧⋆›*)) have 2: "(e⇧T * top)⇧T = top * e" by (simp add: conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*)) also (*calculation: ‹(e⇧T * top)⇧T = top * e›*) have "... = top * (v * -v⇧T ⊓ e)" by (simp add: assms( (*‹(e::'a) ≤ (v::'a) * - v⇧T›*) 2) inf_absorb2 (*‹(?y::'a) ≤ (?x::'a) ⟹ ?x ⊓ ?y = ?y›*)) also (*calculation: ‹(e⇧T * top)⇧T = top * (v * - v⇧T ⊓ e)›*) have "... ≤ top * (v * top ⊓ e)" using inf.sup_left_isotone (*‹?y ≤ ?x ⟹ ?y ⊓ ?z ≤ ?x ⊓ ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) top_greatest (*‹?x ≤ top›*) by blast also (*calculation: ‹(e⇧T * top)⇧T ≤ top * (v * top ⊓ e)›*) have "... = top * v⇧T * e" by (simp add: comp_inf_vector (*‹?x * (?y ⊓ ?z * top) = (?x ⊓ top * ?z⇧T) * ?y›*) inf.sup_monoid.add_commute (*‹?a ⊓ ?b = ?b ⊓ ?a›*)) also (*calculation: ‹(e⇧T * top)⇧T ≤ top * v⇧T * e›*) have "... = v⇧T * e" using assms(1) (*‹vector v›*) vector_conv_covector (*‹vector ?v = covector (?v⇧T)›*) by auto also (*calculation: ‹(e⇧T * top)⇧T ≤ v⇧T * e›*) have "... ≤ r⇧T * (t ⊔ e)⇧⋆ * e" using "1" (*‹v⇧T ≤ r⇧T * (t ⊔ e)⇧⋆›*) by (simp add: mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) also (*calculation: ‹(e⇧T * top)⇧T ≤ r⇧T * (t ⊔ e)⇧⋆ * e›*) have "... ≤ r⇧T * (t ⊔ e)⇧⋆ * (t ⊔ e)" by (simp add: mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹((e::'a)⇧T * top)⇧T ≤ (r::'a)⇧T * ((t::'a) ⊔ e)⇧⋆ * (t ⊔ e)›*) have "... ≤ r⇧T * (t ⊔ e)⇧⋆" by (simp add: comp_associative (*‹(?x::'a::type) * (?y::'a::type) * (?z::'a::type) = ?x * (?y * ?z)›*) mult_right_isotone (*‹(?x::'a::type) ≤ (?y::'a::type) ⟹ (?z::'a::type) * ?x ≤ ?z * ?y›*) star.right_plus_below_circ (*‹(?x::'a::type)⇧⋆ * ?x ≤ ?x⇧⋆›*)) finally (*calculation: ‹(e⇧T * top)⇧T ≤ r⇧T * (t ⊔ e)⇧⋆›*) have 3: "(v ⊔ e⇧T * top)⇧T ≤ r⇧T * (t ⊔ e)⇧⋆" using "1" (*‹v⇧T ≤ r⇧T * (t ⊔ e)⇧⋆›*) by (simp add: conv_dist_sup (*‹(?x ⊔ ?y)⇧T = ?x⇧T ⊔ ?y⇧T›*)) have "r⇧T ≤ r⇧T * t⇧⋆" using sup.bounded_iff (*‹(?b ⊔ ?c ≤ ?a) = (?b ≤ ?a ∧ ?c ≤ ?a)›*) star.circ_back_loop_prefixpoint (*‹?z * ?y⇧⋆ * ?y ⊔ ?z ≤ ?z * ?y⇧⋆›*) by blast also (*calculation: ‹(r::'a)⇧T ≤ r⇧T * (t::'a)⇧⋆›*) have "... ≤ (v ⊔ e⇧T * top)⇧T" by (metis assms( (*‹v⇧T = r⇧T * t⇧⋆›*) 4) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) sup_ge1 (*‹?x ≤ ?x ⊔ ?y›*)) finally (*calculation: ‹(r::'a::type)⇧T ≤ ((v::'a::type) ⊔ (e::'a::type)⇧T * top)⇧T›*) have 4: "r⇧T ≤ (v ⊔ e⇧T * top)⇧T" . have "(v ⊔ e⇧T * top)⇧T * (t ⊔ e) = (v ⊔ e⇧T * top)⇧T * t ⊔ (v ⊔ e⇧T * top)⇧T * e" by (simp add: mult_left_dist_sup (*‹(?x::'a::type) * ((?y::'a::type) ⊔ (?z::'a::type)) = ?x * ?y ⊔ ?x * ?z›*)) also (*calculation: ‹(v ⊔ e⇧T * top)⇧T * (t ⊔ e) = (v ⊔ e⇧T * top)⇧T * t ⊔ (v ⊔ e⇧T * top)⇧T * e›*) have "... ≤ (v ⊔ e⇧T * top)⇧T * t ⊔ top * e" using comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) semiring.add_left_mono (*‹?a ≤ ?b ⟹ ?c ⊔ ?a ≤ ?c ⊔ ?b›*) by auto also (*calculation: ‹(v ⊔ e⇧T * top)⇧T * (t ⊔ e) ≤ (v ⊔ e⇧T * top)⇧T * t ⊔ top * e›*) have "... = v⇧T * t ⊔ top * e * t ⊔ top * e" using "2" (*‹(e⇧T * top)⇧T = top * e›*) by (simp add: conv_dist_sup (*‹(?x ⊔ ?y)⇧T = ?x⇧T ⊔ ?y⇧T›*) mult_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*)) also (*calculation: ‹(v ⊔ e⇧T * top)⇧T * (t ⊔ e) ≤ v⇧T * t ⊔ top * e * t ⊔ top * e›*) have "... = v⇧T * t ⊔ top * e" by (simp add: assms( (*‹(e::'a) * (t::'a) = bot›*) 3) comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*)) also (*calculation: ‹((v::'a) ⊔ (e::'a)⇧T * top)⇧T * ((t::'a) ⊔ e) ≤ v⇧T * t ⊔ top * e›*) have "... ≤ r⇧T * t⇧⋆ ⊔ top * e" by (metis assms( (*‹v⇧T = r⇧T * t⇧⋆›*) 4) star.circ_back_loop_fixpoint (*‹?z * ?y⇧⋆ * ?y ⊔ ?z = ?z * ?y⇧⋆›*) sup_ge1 (*‹?x ≤ ?x ⊔ ?y›*) sup_left_isotone (*‹?x ≤ ?y ⟹ ?x ⊔ ?z ≤ ?y ⊔ ?z›*)) also (*calculation: ‹((v::'a) ⊔ (e::'a)⇧T * top)⇧T * ((t::'a) ⊔ e) ≤ (r::'a)⇧T * t⇧⋆ ⊔ top * e›*) have "... = v⇧T ⊔ top * e" by (simp add: assms( (*‹v⇧T = r⇧T * t⇧⋆›*) 4)) finally (*calculation: ‹(v ⊔ e⇧T * top)⇧T * (t ⊔ e) ≤ v⇧T ⊔ top * e›*) have 5: "(v ⊔ e⇧T * top)⇧T * (t ⊔ e) ≤ (v ⊔ e⇧T * top)⇧T" using "2" (*‹(e⇧T * top)⇧T = top * e›*) by (simp add: conv_dist_sup (*‹(?x ⊔ ?y)⇧T = ?x⇧T ⊔ ?y⇧T›*)) have "r⇧T * (t ⊔ e)⇧⋆ ≤ (v ⊔ e⇧T * top)⇧T * (t ⊔ e)⇧⋆" using "4" (*‹r⇧T ≤ (v ⊔ e⇧T * top)⇧T›*) by (simp add: mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) also (*calculation: ‹(r::'a)⇧T * ((t::'a) ⊔ (e::'a))⇧⋆ ≤ ((v::'a) ⊔ e⇧T * top)⇧T * (t ⊔ e)⇧⋆›*) have "... ≤ (v ⊔ e⇧T * top)⇧T" using "5" (*‹(v ⊔ e⇧T * top)⇧T * (t ⊔ e) ≤ (v ⊔ e⇧T * top)⇧T›*) by (simp add: star_right_induct_mult (*‹?y * ?x ≤ ?y ⟹ ?y * ?x⇧⋆ ≤ ?y›*)) finally (*calculation: ‹r⇧T * (t ⊔ e)⇧⋆ ≤ (v ⊔ e⇧T * top)⇧T›*) show "?thesis" (*goal: ‹((v::'a::type) ⊔ (e::'a::type)⇧T * top)⇧T = (r::'a::type)⇧T * ((t::'a::type) ⊔ e)⇧⋆›*) using "3" (*‹(v ⊔ e⇧T * top)⇧T ≤ r⇧T * (t ⊔ e)⇧⋆›*) by (simp add: order.eq_iff (*‹(?a = ?b) = (?a ≤ ?b ∧ ?b ≤ ?a)›*)) qed text ‹ The next result is used to show that the while-loop preserves acyclicity of the constructed tree. › lemma acyclic_inv: assumes "acyclic t" and "vector v" and "e ≤ v * -v⇧T" and "t ≤ v * v⇧T" shows "acyclic (t ⊔ e)" proof (-) (*goal: ‹pd_kleene_allegory_class.acyclic (t ⊔ e)›*) have "t⁺ * e ≤ t⁺ * v * -v⇧T" by (simp add: assms( (*‹e ≤ v * - v⇧T›*) 3) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹t⁺ * e ≤ t⁺ * v * - v⇧T›*) have "... ≤ v * v⇧T * t⇧⋆ * v * -v⇧T" by (simp add: assms( (*‹t ≤ v * v⇧T›*) 4) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) also (*calculation: ‹t⁺ * e ≤ v * v⇧T * t⇧⋆ * v * - v⇧T›*) have "... ≤ v * top * -v⇧T" by (metis mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) top_greatest (*‹?x ≤ top›*)) also (*calculation: ‹t⁺ * e ≤ v * top * - v⇧T›*) have "... = v * -v⇧T" by (simp add: assms( (*‹vector v›*) 2)) also (*calculation: ‹t⁺ * e ≤ v * - v⇧T›*) have "... ≤ -1" by (simp add: pp_increasing (*‹(?x::'a::type) ≤ - - ?x›*) schroeder_3_p (*‹((?x::'a::type) * (?y::'a::type) ≤ - (?z::'a::type)) = (?x⇧T * ?z ≤ - ?y)›*)) finally (*calculation: ‹irreflexive (t⁺ * e)›*) have 1: "t⁺ * e ≤ -1" . have 2: "e * t⇧⋆ = e" using assms(2-4) (*‹vector v› ‹e ≤ v * - v⇧T› ‹(t::'a) ≤ (v::'a) * v⇧T›*) et(1) (*‹⟦vector ?v; ?e ≤ ?v * - ?v⇧T; ?t ≤ ?v * ?v⇧T⟧ ⟹ ?e * ?t = bot›*) star_absorb (*‹?x * ?y = bot ⟹ ?x * ?y⇧⋆ = ?x›*) by blast have "e⇧⋆ = 1 ⊔ e ⊔ e * e * e⇧⋆" by (metis star.circ_loop_fixpoint (*‹?y * (?y⇧⋆ * ?z) ⊔ ?z = ?y⇧⋆ * ?z›*) star_square_2 (*‹?x⇧⋆ = (?x * ?x)⇧⋆ * (?x ⊔ 1)›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*)) also (*calculation: ‹e⇧⋆ = 1 ⊔ e ⊔ e * e * e⇧⋆›*) have "... = 1 ⊔ e" using assms(2,3) (*‹vector v› ‹e ≤ v * - v⇧T›*) ee (*‹⟦vector ?v; ?e ≤ ?v * - ?v⇧T⟧ ⟹ ?e * ?e = bot›*) comp_left_zero (*‹bot * ?x = bot›*) bot_least (*‹bot ≤ ?a›*) sup_absorb1 (*‹?y ≤ ?x ⟹ ?x ⊔ ?y = ?x›*) by simp finally (*calculation: ‹e⇧⋆ = 1 ⊔ e›*) have 3: "e⇧⋆ = 1 ⊔ e" . have "e ≤ v * -v⇧T" by (simp add: assms( (*‹e ≤ v * - v⇧T›*) 3)) also (*calculation: ‹e ≤ v * - v⇧T›*) have "... ≤ -1" by (simp add: pp_increasing (*‹?x ≤ - - ?x›*) schroeder_3_p (*‹(?x * ?y ≤ - ?z) = (?x⇧T * ?z ≤ - ?y)›*)) finally (*calculation: ‹irreflexive e›*) have 4: "t⁺ * e ⊔ e ≤ -1" using "1" (*‹irreflexive (t⁺ * e)›*) by simp have "(t ⊔ e)⁺ = (t ⊔ e) * t⇧⋆ * (e * t⇧⋆)⇧⋆" using star_sup_1 (*‹(?x ⊔ ?y)⇧⋆ = ?x⇧⋆ * (?y * ?x⇧⋆)⇧⋆›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) by simp also (*calculation: ‹(t ⊔ e)⁺ = (t ⊔ e) * t⇧⋆ * (e * t⇧⋆)⇧⋆›*) have "... = (t ⊔ e) * t⇧⋆ * (1 ⊔ e)" using "2" (*‹e * t⇧⋆ = e›*) "3" (*‹e⇧⋆ = 1 ⊔ e›*) by simp also (*calculation: ‹(t ⊔ e)⁺ = (t ⊔ e) * t⇧⋆ * (1 ⊔ e)›*) have "... = t⁺ * (1 ⊔ e) ⊔ e * t⇧⋆ * (1 ⊔ e)" by (simp add: comp_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*)) also (*calculation: ‹(t ⊔ e)⁺ = t⁺ * (1 ⊔ e) ⊔ e * t⇧⋆ * (1 ⊔ e)›*) have "... = t⁺ * (1 ⊔ e) ⊔ e * (1 ⊔ e)" using "2" (*‹e * t⇧⋆ = e›*) by simp also (*calculation: ‹(t ⊔ e)⁺ = t⁺ * (1 ⊔ e) ⊔ e * (1 ⊔ e)›*) have "... = t⁺ * (1 ⊔ e) ⊔ e" using "3" (*‹e⇧⋆ = 1 ⊔ e›*) by (metis star_absorb (*‹?x * ?y = bot ⟹ ?x * ?y⇧⋆ = ?x›*) assms( (*‹vector v› ‹e ≤ v * - v⇧T›*) 2,3) ee (*‹⟦vector ?v; ?e ≤ ?v * - ?v⇧T⟧ ⟹ ?e * ?e = bot›*)) also (*calculation: ‹((t::'a) ⊔ (e::'a))⁺ = t⁺ * ((1::'a) ⊔ e) ⊔ e›*) have "... = t⁺ ⊔ t⁺ * e ⊔ e" by (simp add: mult_left_dist_sup (*‹?x * (?y ⊔ ?z) = ?x * ?y ⊔ ?x * ?z›*)) also (*calculation: ‹(t ⊔ e)⁺ = t⁺ ⊔ t⁺ * e ⊔ e›*) have "... ≤ -1" using "4" (*‹irreflexive (t⁺ * e ⊔ e)›*) by (metis assms( (*‹pd_kleene_allegory_class.acyclic t›*) 1) sup.absorb1 (*‹?b ≤ ?a ⟹ ?a ⊔ ?b = ?a›*) sup.orderI (*‹?a = ?a ⊔ ?b ⟹ ?b ≤ ?a›*) sup_assoc (*‹?x ⊔ ?y ⊔ ?z = ?x ⊔ (?y ⊔ ?z)›*)) finally (*calculation: ‹pd_kleene_allegory_class.acyclic (t ⊔ e)›*) show "?thesis" (*goal: ‹pd_kleene_allegory_class.acyclic ((t::'a) ⊔ (e::'a))›*) . qed text ‹ The following lemma shows that the extended tree is in the component reachable from the root. › lemma mst_subgraph_inv_2: assumes "regular (v * v⇧T)" and "t ≤ v * v⇧T ⊓ --g" and "v⇧T = r⇧T * t⇧⋆" and "e ≤ v * -v⇧T ⊓ --g" and "vector v" and "regular ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T)" shows "t ⊔ e ≤ (r⇧T * (--((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g))⇧⋆)⇧T * (r⇧T * (--((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g))⇧⋆)" proof (-) (*goal: ‹t ⊔ e ≤ (r⇧T * components ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g))⇧T * (r⇧T * components ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g))›*) let ?v = "v ⊔ e⇧T * top" let ?G = "?v * ?v⇧T ⊓ g" let ?c = "r⇧T * (--?G)⇧⋆" have "v⇧T ≤ r⇧T * (--(v * v⇧T ⊓ g))⇧⋆" using assms(1-3) (*‹regular (v * v⇧T)› ‹t ≤ v * v⇧T ⊓ - - g› ‹(v::'a)⇧T = (r::'a)⇧T * (t::'a)⇧⋆›*) inf_pp_commute (*‹- - (- - ?x ⊓ ?y) = - - ?x ⊓ - - ?y›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) by auto also (*calculation: ‹(v::'a::type)⇧T ≤ (r::'a::type)⇧T * components (v * v⇧T ⊓ (g::'a::type))›*) have "... ≤ ?c" using comp_inf.mult_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊓ ?x ≤ ?z ⊓ ?y›*) comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) inf.commute (*‹?a ⊓ ?b = ?b ⊓ ?a›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) pp_isotone (*‹?x ≤ ?y ⟹ - - ?x ≤ - - ?y›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) sup.cobounded1 (*‹?a ≤ ?a ⊔ ?b›*) by presburger finally (*calculation: ‹v⇧T ≤ r⇧T * components ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g)›*) have 2: "v⇧T ≤ ?c ∧ v ≤ ?c⇧T" by (metis conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*)) have "t ≤ v * v⇧T" using assms(2) (*‹t ≤ v * v⇧T ⊓ - - g›*) by auto hence 3: "t ≤ ?c⇧T * ?c" using "2" (*‹v⇧T ≤ r⇧T * components ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) ∧ v ≤ (r⇧T * components ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g))⇧T›*) order_trans (*‹⟦?x ≤ ?y; ?y ≤ ?z⟧ ⟹ ?x ≤ ?z›*) mult_isotone (*‹⟦?w ≤ ?y; ?x ≤ ?z⟧ ⟹ ?w * ?x ≤ ?y * ?z›*) by blast have "e ≤ v * top ⊓ --g" by (metis assms( (*‹(e::'a) ≤ (v::'a) * - v⇧T ⊓ - - (g::'a)› ‹vector (v::'a)›*) 4,5) inf.bounded_iff (*‹((?a::'a) ≤ (?b::'a) ⊓ (?c::'a)) = (?a ≤ ?b ∧ ?a ≤ ?c)›*) inf.sup_left_divisibility (*‹((?y::'a) ≤ (?x::'a)) = (∃z::'a. ?x ⊓ z = ?y)›*) mult_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*) top.extremum (*‹(?a::'a) ≤ top›*)) hence "e ≤ v * top ⊓ top * e ⊓ --g" by (simp add: top_left_mult_increasing (*‹?x ≤ top * ?x›*) inf.boundedI (*‹⟦?a ≤ ?b; ?a ≤ ?c⟧ ⟹ ?a ≤ ?b ⊓ ?c›*)) hence "e ≤ v * top * e ⊓ --g" by (metis comp_inf_covector (*‹?x * (?y ⊓ top * ?z) = ?x * ?y ⊓ top * ?z›*) inf.absorb2 (*‹?b ≤ ?a ⟹ ?a ⊓ ?b = ?b›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) top.extremum (*‹?a ≤ top›*)) hence "t ⊔ e ≤ (v * v⇧T ⊓ --g) ⊔ (v * top * e ⊓ --g)" using assms(2) (*‹t ≤ v * v⇧T ⊓ - - g›*) sup_mono (*‹⟦?a ≤ ?c; ?b ≤ ?d⟧ ⟹ ?a ⊔ ?b ≤ ?c ⊔ ?d›*) by blast also (*calculation: ‹(t::'a::type) ⊔ (e::'a::type) ≤ (v::'a::type) * v⇧T ⊓ - - (g::'a::type) ⊔ v * top * e ⊓ - - g›*) have "... = v * ?v⇧T ⊓ --g" by (simp add: inf_sup_distrib2 (*‹((?y::'a) ⊔ (?z::'a)) ⊓ (?x::'a) = ?y ⊓ ?x ⊔ ?z ⊓ ?x›*) mult_assoc (*‹(?a::'a) * (?b::'a) * (?c::'a) = ?a * (?b * ?c)›*) mult_left_dist_sup (*‹(?x::'a) * ((?y::'a) ⊔ (?z::'a)) = ?x * ?y ⊔ ?x * ?z›*) conv_dist_comp (*‹((?x::'a) * (?y::'a))⇧T = ?y⇧T * ?x⇧T›*) conv_dist_sup (*‹((?x::'a) ⊔ (?y::'a))⇧T = ?x⇧T ⊔ ?y⇧T›*)) also (*calculation: ‹(t::'a::type) ⊔ (e::'a::type) ≤ (v::'a::type) * (v ⊔ e⇧T * top)⇧T ⊓ - - (g::'a::type)›*) have "... ≤ --?G" using assms(6) (*‹regular (((v::'a) ⊔ (e::'a)⇧T * top) * (v ⊔ e⇧T * top)⇧T)›*) comp_left_increasing_sup (*‹?x * ?y ≤ (?x ⊔ ?z) * ?y›*) inf.sup_left_isotone (*‹?y ≤ ?x ⟹ ?y ⊓ ?z ≤ ?x ⊓ ?z›*) pp_dist_inf (*‹- - (?x ⊓ ?y) = - - ?x ⊓ - - ?y›*) by auto finally (*calculation: ‹t ⊔ e ≤ - - ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g)›*) have 4: "t ⊔ e ≤ --?G" . have "e ≤ e * e⇧T * e" by (simp add: ex231c (*‹?x ≤ ?x * ?x⇧T * ?x›*)) also (*calculation: ‹e ≤ e * e⇧T * e›*) have "... ≤ v * -v⇧T * -v * v⇧T * e" by (metis assms( (*‹e ≤ v * - v⇧T ⊓ - - g›*) 4) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_isotone (*‹⟦?w ≤ ?y; ?x ≤ ?z⟧ ⟹ ?w * ?x ≤ ?y * ?z›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) inf.boundedE (*‹⟦?a ≤ ?b ⊓ ?c; ⟦?a ≤ ?b; ?a ≤ ?c⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) also (*calculation: ‹e ≤ v * - v⇧T * - v * v⇧T * e›*) have "... ≤ v * top * v⇧T * e" by (metis mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) top.extremum (*‹?a ≤ top›*)) also (*calculation: ‹e ≤ v * top * v⇧T * e›*) have "... = v * r⇧T * t⇧⋆ * e" using assms(3,5) (*‹v⇧T = r⇧T * t⇧⋆› ‹vector v›*) by (simp add: mult_assoc (*‹(?a::'a::type) * (?b::'a::type) * (?c::'a::type) = ?a * (?b * ?c)›*)) also (*calculation: ‹e ≤ v * r⇧T * t⇧⋆ * e›*) have "... ≤ v * r⇧T * (t ⊔ e)⇧⋆" by (simp add: comp_associative (*‹(?x::'a::type) * (?y::'a::type) * (?z::'a::type) = ?x * (?y * ?z)›*) mult_right_isotone (*‹(?x::'a::type) ≤ (?y::'a::type) ⟹ (?z::'a::type) * ?x ≤ ?z * ?y›*) star.circ_mult_upper_bound (*‹⟦(?x::'a::type) ≤ (?z::'a::type)⇧⋆; (?y::'a::type) ≤ ?z⇧⋆⟧ ⟹ ?x * ?y ≤ ?z⇧⋆›*) star.circ_sub_dist_1 (*‹(?x::'a::type) ≤ (?x ⊔ (?y::'a::type))⇧⋆›*) star_isotone (*‹(?x::'a::type) ≤ (?y::'a::type) ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) sup_commute (*‹(?x::'a::type) ⊔ (?y::'a::type) = ?y ⊔ ?x›*)) also (*calculation: ‹e ≤ v * r⇧T * (t ⊔ e)⇧⋆›*) have "... ≤ v * ?c" using "4" (*‹t ⊔ e ≤ - - ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g)›*) by (simp add: mult_assoc (*‹(?a::'a) * (?b::'a) * (?c::'a) = ?a * (?b * ?c)›*) mult_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*) star_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) also (*calculation: ‹e ≤ v * (r⇧T * components ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g))›*) have "... ≤ ?c⇧T * ?c" using "2" (*‹v⇧T ≤ r⇧T * components ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) ∧ v ≤ (r⇧T * components ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g))⇧T›*) by (simp add: mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) finally (*calculation: ‹e ≤ (r⇧T * components ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g))⇧T * (r⇧T * components ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g))›*) show "?thesis" (*goal: ‹t ⊔ e ≤ (r⇧T * components ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g))⇧T * (r⇧T * components ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g))›*) using "3" (*‹t ≤ (r⇧T * components ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g))⇧T * (r⇧T * components ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g))›*) by simp qed lemma span_inv: assumes "e ≤ v * -v⇧T" and "vector v" and "arc e" and "t ≤ (v * v⇧T) ⊓ g" and "g⇧T = g" and "v⇧T = r⇧T * t⇧⋆" and "injective r" and "r⇧T ≤ v⇧T" and "r⇧T * ((v * v⇧T) ⊓ g)⇧⋆ ≤ r⇧T * t⇧⋆" shows "r⇧T * (((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T) ⊓ g)⇧⋆ ≤ r⇧T * (t ⊔ e)⇧⋆" proof (-) (*goal: ‹r⇧T * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g)⇧⋆ ≤ r⇧T * (t ⊔ e)⇧⋆›*) let ?d = "(v * v⇧T) ⊓ g" have 1: "(v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T = v * v⇧T ⊔ v * v⇧T * e ⊔ e⇧T * v * v⇧T ⊔ e⇧T * e" using assms(1-3) (*‹e ≤ v * - v⇧T› ‹vector v› ‹arc (e::'a)›*) ve_dist (*‹⟦?e ≤ ?v * - ?v⇧T; vector ?v; arc ?e⟧ ⟹ (?v ⊔ ?e⇧T * top) * (?v ⊔ ?e⇧T * top)⇧T = ?v * ?v⇧T ⊔ ?v * ?v⇧T * ?e ⊔ ?e⇧T * ?v * ?v⇧T ⊔ ?e⇧T * ?e›*) by simp have "t⇧T ≤ ?d⇧T" using assms(4) (*‹t ≤ v * v⇧T ⊓ g›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) by simp also (*calculation: ‹t⇧T ≤ (v * v⇧T ⊓ g)⇧T›*) have "... = (v * v⇧T) ⊓ g⇧T" by (simp add: conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*)) also (*calculation: ‹(t::'a)⇧T ≤ (v::'a) * v⇧T ⊓ (g::'a)⇧T›*) have "... = ?d" by (simp add: assms( (*‹symmetric (g::'a)›*) 5)) finally (*calculation: ‹t⇧T ≤ v * v⇧T ⊓ g›*) have 2: "t⇧T ≤ ?d" . have "v * v⇧T = (r⇧T * t⇧⋆)⇧T * (r⇧T * t⇧⋆)" by (metis assms( (*‹v⇧T = r⇧T * t⇧⋆›*) 6) conv_involutive (*‹?x⇧T⇧T = ?x›*)) also (*calculation: ‹v * v⇧T = (r⇧T * t⇧⋆)⇧T * (r⇧T * t⇧⋆)›*) have "... = t⇧T⇧⋆ * (r * r⇧T) * t⇧⋆" by (simp add: comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*) conv_dist_comp (*‹((?x::'a) * (?y::'a))⇧T = ?y⇧T * ?x⇧T›*) conv_star_commute (*‹(?x::'a)⇧⋆⇧T = ?x⇧T⇧⋆›*)) also (*calculation: ‹v * v⇧T = t⇧T⇧⋆ * (r * r⇧T) * t⇧⋆›*) have "... ≤ t⇧T⇧⋆ * 1 * t⇧⋆" by (simp add: assms( (*‹injective r›*) 7) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) star_right_induct_mult_iff (*‹(?y * ?x ≤ ?y) = (?y * ?x⇧⋆ ≤ ?y)›*) star_sub_one (*‹coreflexive ?x ⟹ ?x⇧⋆ = 1›*)) also (*calculation: ‹v * v⇧T ≤ t⇧T⇧⋆ * 1 * t⇧⋆›*) have "... = t⇧T⇧⋆ * t⇧⋆" by simp also (*calculation: ‹v * v⇧T ≤ forest_components t›*) have "... ≤ ?d⇧⋆ * t⇧⋆" using "2" (*‹t⇧T ≤ v * v⇧T ⊓ g›*) by (simp add: comp_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) star.circ_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) also (*calculation: ‹v * v⇧T ≤ (v * v⇧T ⊓ g)⇧⋆ * t⇧⋆›*) have "... ≤ ?d⇧⋆ * ?d⇧⋆" using assms(4) (*‹t ≤ v * v⇧T ⊓ g›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) by simp also (*calculation: ‹v * v⇧T ≤ (v * v⇧T ⊓ g)⇧⋆ * (v * v⇧T ⊓ g)⇧⋆›*) have 3: "... = ?d⇧⋆" by (simp add: star.circ_transitive_equal (*‹idempotent (?x⇧⋆)›*)) finally (*calculation: ‹(v::'a::type) * v⇧T ≤ (v * v⇧T ⊓ (g::'a::type))⇧⋆›*) have 4: "v * v⇧T ≤ ?d⇧⋆" . have 5: "r⇧T * ?d⇧⋆ * (v * v⇧T ⊓ g) ≤ r⇧T * ?d⇧⋆" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star.circ_plus_same (*‹?x⇧⋆ * ?x = ?x⁺›*) star.left_plus_below_circ (*‹?x⁺ ≤ ?x⇧⋆›*)) have "r⇧T * ?d⇧⋆ * (v * v⇧T * e ⊓ g) ≤ r⇧T * ?d⇧⋆ * v * v⇧T * e" by (simp add: comp_associative (*‹(?x::'a::type) * (?y::'a::type) * (?z::'a::type) = ?x * (?y * ?z)›*) comp_right_isotone (*‹(?x::'a::type) ≤ (?y::'a::type) ⟹ (?z::'a::type) * ?x ≤ ?z * ?y›*)) also (*calculation: ‹(r::'a::type)⇧T * ((v::'a::type) * v⇧T ⊓ (g::'a::type))⇧⋆ * (v * v⇧T * (e::'a::type) ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * v * v⇧T * e›*) have "... ≤ r⇧T * ?d⇧⋆ * e" using "3" (*‹idempotent ((v * v⇧T ⊓ g)⇧⋆)›*) "4" (*‹(v::'a) * v⇧T ≤ (v * v⇧T ⊓ (g::'a))⇧⋆›*) by (metis comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*) comp_isotone (*‹⟦(?x::'a) ≤ (?y::'a); (?w::'a) ≤ (?z::'a)⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) eq_refl (*‹(?x::'a) = (?y::'a) ⟹ ?x ≤ ?y›*)) finally (*calculation: ‹(r::'a)⇧T * ((v::'a) * v⇧T ⊓ (g::'a))⇧⋆ * (v * v⇧T * (e::'a) ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e›*) have 6: "r⇧T * ?d⇧⋆ * (v * v⇧T * e ⊓ g) ≤ r⇧T * ?d⇧⋆ * e" . have 7: "∀x . r⇧T * (1 ⊔ v * v⇧T) * e⇧T * x = bot" proof (standard) (*goal: ‹⋀x. r⇧T * Rf v (v⇧T) * e⇧T * x = bot›*) fix x have "r⇧T * (1 ⊔ v * v⇧T) * e⇧T * x ≤ r⇧T * (1 ⊔ v * v⇧T) * e⇧T * top" by (simp add: mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹r⇧T * Rf v (v⇧T) * e⇧T * x ≤ r⇧T * Rf v (v⇧T) * e⇧T * top›*) have "... = r⇧T * e⇧T * top ⊔ r⇧T * v * v⇧T * e⇧T * top" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) mult_left_dist_sup (*‹?x * (?y ⊔ ?z) = ?x * ?y ⊔ ?x * ?z›*) mult_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*)) also (*calculation: ‹r⇧T * Rf v (v⇧T) * e⇧T * x ≤ r⇧T * e⇧T * top ⊔ r⇧T * v * v⇧T * e⇧T * top›*) have "... = r⇧T * e⇧T * top" by (metis assms( (*‹e ≤ v * - v⇧T› ‹vector v›*) 1,2) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*) mult_right_zero (*‹?x * bot = bot›*) sup_bot_right (*‹?x ⊔ bot = ?x›*) vTeT (*‹⟦vector ?v; ?e ≤ ?v * - ?v⇧T⟧ ⟹ ?v⇧T * ?e⇧T = bot›*)) also (*calculation: ‹r⇧T * Rf v (v⇧T) * e⇧T * x ≤ r⇧T * e⇧T * top›*) have "... ≤ v⇧T * e⇧T * top" by (simp add: assms( (*‹(r::'a)⇧T ≤ (v::'a)⇧T›*) 8) comp_isotone (*‹⟦(?x::'a) ≤ (?y::'a); (?w::'a) ≤ (?z::'a)⟧ ⟹ ?x * ?w ≤ ?y * ?z›*)) also (*calculation: ‹r⇧T * Rf v (v⇧T) * e⇧T * x ≤ v⇧T * e⇧T * top›*) have "... = bot" using vTeT (*‹⟦vector ?v; ?e ≤ ?v * - ?v⇧T⟧ ⟹ ?v⇧T * ?e⇧T = bot›*) assms(1,2) (*‹e ≤ v * - v⇧T› ‹vector v›*) by simp finally (*calculation: ‹r⇧T * Rf v (v⇧T) * e⇧T * x ≤ bot›*) show "r⇧T * (1 ⊔ v * v⇧T) * e⇧T * x = bot" by (simp add: le_bot (*‹(?a::'a::type) ≤ bot ⟹ ?a = bot›*)) qed have "r⇧T * ?d⇧⋆ * (e⇧T * v * v⇧T ⊓ g) ≤ r⇧T * ?d⇧⋆ * e⇧T * v * v⇧T" by (simp add: comp_associative (*‹(?x::'a::type) * (?y::'a::type) * (?z::'a::type) = ?x * (?y * ?z)›*) comp_right_isotone (*‹(?x::'a::type) ≤ (?y::'a::type) ⟹ (?z::'a::type) * ?x ≤ ?z * ?y›*)) also (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (e⇧T * v * v⇧T ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e⇧T * v * v⇧T›*) have "... ≤ r⇧T * (1 ⊔ v * v⇧T) * e⇧T * v * v⇧T" by (metis assms( (*‹vector v›*) 2) star.circ_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) vector_vector_star (*‹vector ?v ⟹ (?v * ?v⇧T)⇧⋆ = Rf ?v (?v⇧T)›*) inf_le1 (*‹?x ⊓ ?y ≤ ?x›*) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) comp_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) also (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (e⇧T * v * v⇧T ⊓ g) ≤ r⇧T * Rf v (v⇧T) * e⇧T * v * v⇧T›*) have "... = bot" using "7" (*‹∀x. r⇧T * Rf v (v⇧T) * e⇧T * x = bot›*) by simp finally (*calculation: ‹(r::'a)⇧T * ((v::'a) * v⇧T ⊓ (g::'a))⇧⋆ * ((e::'a)⇧T * v * v⇧T ⊓ g) ≤ bot›*) have 8: "r⇧T * ?d⇧⋆ * (e⇧T * v * v⇧T ⊓ g) = bot" by (simp add: le_bot (*‹?a ≤ bot ⟹ ?a = bot›*)) have "r⇧T * ?d⇧⋆ * (e⇧T * e ⊓ g) ≤ r⇧T * ?d⇧⋆ * e⇧T * e" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (e⇧T * e ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e⇧T * e›*) have "... ≤ r⇧T * (1 ⊔ v * v⇧T) * e⇧T * e" by (metis assms( (*‹vector (v::'a)›*) 2) star.circ_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) vector_vector_star (*‹vector (?v::'a) ⟹ (?v * ?v⇧T)⇧⋆ = Rf ?v (?v⇧T)›*) inf_le1 (*‹(?x::'a) ⊓ (?y::'a) ≤ ?x›*) comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*) comp_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*) comp_left_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x * (?z::'a) ≤ ?y * ?z›*)) also (*calculation: ‹(r::'a::type)⇧T * ((v::'a::type) * v⇧T ⊓ (g::'a::type))⇧⋆ * ((e::'a::type)⇧T * e ⊓ g) ≤ r⇧T * Rf v (v⇧T) * e⇧T * e›*) have "... = bot" using "7" (*‹∀x. r⇧T * Rf v (v⇧T) * e⇧T * x = bot›*) by simp finally (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (e⇧T * e ⊓ g) ≤ bot›*) have 9: "r⇧T * ?d⇧⋆ * (e⇧T * e ⊓ g) = bot" by (simp add: le_bot (*‹?a ≤ bot ⟹ ?a = bot›*)) have "r⇧T * ?d⇧⋆ * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) = r⇧T * ?d⇧⋆ * ((v * v⇧T ⊔ v * v⇧T * e ⊔ e⇧T * v * v⇧T ⊔ e⇧T * e) ⊓ g)" using "1" (*‹(v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T = v * v⇧T ⊔ v * v⇧T * e ⊔ e⇧T * v * v⇧T ⊔ e⇧T * e›*) by simp also (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) = r⇧T * (v * v⇧T ⊓ g)⇧⋆ * ((v * v⇧T ⊔ v * v⇧T * e ⊔ e⇧T * v * v⇧T ⊔ e⇧T * e) ⊓ g)›*) have "... = r⇧T * ?d⇧⋆ * ((v * v⇧T ⊓ g) ⊔ (v * v⇧T * e ⊓ g) ⊔ (e⇧T * v * v⇧T ⊓ g) ⊔ (e⇧T * e ⊓ g))" by (simp add: inf_sup_distrib2 (*‹(?y ⊔ ?z) ⊓ ?x = ?y ⊓ ?x ⊔ ?z ⊓ ?x›*)) also (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) = r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (v * v⇧T ⊓ g ⊔ v * v⇧T * e ⊓ g ⊔ e⇧T * v * v⇧T ⊓ g ⊔ e⇧T * e ⊓ g)›*) have "... = r⇧T * ?d⇧⋆ * (v * v⇧T ⊓ g) ⊔ r⇧T * ?d⇧⋆ * (v * v⇧T * e ⊓ g) ⊔ r⇧T * ?d⇧⋆ * (e⇧T * v * v⇧T ⊓ g) ⊔ r⇧T * ?d⇧⋆ * (e⇧T * e ⊓ g)" by (simp add: comp_left_dist_sup (*‹?x * ?y ⊔ ?x * ?z = ?x * (?y ⊔ ?z)›*)) also (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) = r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (v * v⇧T ⊓ g) ⊔ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (v * v⇧T * e ⊓ g) ⊔ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (e⇧T * v * v⇧T ⊓ g) ⊔ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (e⇧T * e ⊓ g)›*) have "... = r⇧T * ?d⇧⋆ * (v * v⇧T ⊓ g) ⊔ r⇧T * ?d⇧⋆ * (v * v⇧T * e ⊓ g)" using "8" (*‹(r::'a)⇧T * ((v::'a) * v⇧T ⊓ (g::'a))⇧⋆ * ((e::'a)⇧T * v * v⇧T ⊓ g) = bot›*) "9" (*‹(r::'a)⇧T * ((v::'a) * v⇧T ⊓ (g::'a))⇧⋆ * ((e::'a)⇧T * e ⊓ g) = bot›*) by simp also (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) = r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (v * v⇧T ⊓ g) ⊔ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (v * v⇧T * e ⊓ g)›*) have "... ≤ r⇧T * ?d⇧⋆ ⊔ r⇧T * ?d⇧⋆ * e" using "5" (*‹(r::'a)⇧T * ((v::'a) * v⇧T ⊓ (g::'a))⇧⋆ * (v * v⇧T ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆›*) "6" (*‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (v * v⇧T * e ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e›*) sup.mono (*‹⟦?c ≤ ?a; ?d ≤ ?b⟧ ⟹ ?c ⊔ ?d ≤ ?a ⊔ ?b›*) by simp also (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ ⊔ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e›*) have "... = r⇧T * ?d⇧⋆ * (1 ⊔ e)" by (simp add: mult_left_dist_sup (*‹(?x::'a) * ((?y::'a) ⊔ (?z::'a)) = ?x * ?y ⊔ ?x * ?z›*)) finally (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (1 ⊔ e)›*) have 10: "r⇧T * ?d⇧⋆ * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) ≤ r⇧T * ?d⇧⋆ * (1 ⊔ e)" by simp have "r⇧T * ?d⇧⋆ * e * (v * v⇧T ⊓ g) ≤ r⇧T * ?d⇧⋆ * e * v * v⇧T" by (simp add: comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*) comp_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*)) also (*calculation: ‹(r::'a)⇧T * ((v::'a) * v⇧T ⊓ (g::'a))⇧⋆ * (e::'a) * (v * v⇧T ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * v * v⇧T›*) have "... = bot" by (metis assms( (*‹e ≤ v * - v⇧T› ‹vector v›*) 1,2) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_right_zero (*‹?x * bot = bot›*) ev (*‹⟦vector ?v; ?e ≤ ?v * - ?v⇧T⟧ ⟹ ?e * ?v = bot›*) comp_left_zero (*‹bot * ?x = bot›*)) finally (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * (v * v⇧T ⊓ g) ≤ bot›*) have 11: "r⇧T * ?d⇧⋆ * e * (v * v⇧T ⊓ g) = bot" by (simp add: le_bot (*‹?a ≤ bot ⟹ ?a = bot›*)) have "r⇧T * ?d⇧⋆ * e * (v * v⇧T * e ⊓ g) ≤ r⇧T * ?d⇧⋆ * e * v * v⇧T * e" by (simp add: comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*) comp_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*)) also (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * (v * v⇧T * e ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * v * v⇧T * e›*) have "... = bot" by (metis assms( (*‹e ≤ v * - v⇧T› ‹vector v›*) 1,2) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_right_zero (*‹?x * bot = bot›*) ev (*‹⟦vector ?v; ?e ≤ ?v * - ?v⇧T⟧ ⟹ ?e * ?v = bot›*) comp_left_zero (*‹bot * ?x = bot›*)) finally (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * (v * v⇧T * e ⊓ g) ≤ bot›*) have 12: "r⇧T * ?d⇧⋆ * e * (v * v⇧T * e ⊓ g) = bot" by (simp add: le_bot (*‹(?a::'a) ≤ bot ⟹ ?a = bot›*)) have "r⇧T * ?d⇧⋆ * e * (e⇧T * v * v⇧T ⊓ g) ≤ r⇧T * ?d⇧⋆ * e * e⇧T * v * v⇧T" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * (e⇧T * v * v⇧T ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * e⇧T * v * v⇧T›*) have "... ≤ r⇧T * ?d⇧⋆ * 1 * v * v⇧T" by (metis assms( (*‹arc e›*) 3) arc_injective (*‹arc ?x ⟹ injective ?x›*) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) comp_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹(r::'a)⇧T * ((v::'a) * v⇧T ⊓ (g::'a))⇧⋆ * (e::'a) * (e⇧T * v * v⇧T ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (1::'a) * v * v⇧T›*) have "... = r⇧T * ?d⇧⋆ * v * v⇧T" by simp also (*calculation: ‹(r::'a)⇧T * ((v::'a) * v⇧T ⊓ (g::'a))⇧⋆ * (e::'a) * (e⇧T * v * v⇧T ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * v * v⇧T›*) have "... ≤ r⇧T * ?d⇧⋆ * ?d⇧⋆" using "4" (*‹v * v⇧T ≤ (v * v⇧T ⊓ g)⇧⋆›*) by (simp add: mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹(r::'a::type)⇧T * ((v::'a::type) * v⇧T ⊓ (g::'a::type))⇧⋆ * (e::'a::type) * (e⇧T * v * v⇧T ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (v * v⇧T ⊓ g)⇧⋆›*) have "... = r⇧T * ?d⇧⋆" by (simp add: star.circ_transitive_equal (*‹idempotent (?x⇧⋆)›*) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*)) finally (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * (e⇧T * v * v⇧T ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆›*) have 13: "r⇧T * ?d⇧⋆ * e * (e⇧T * v * v⇧T ⊓ g) ≤ r⇧T * ?d⇧⋆" . have "r⇧T * ?d⇧⋆ * e * (e⇧T * e ⊓ g) ≤ r⇧T * ?d⇧⋆ * e * e⇧T * e" by (simp add: comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*) comp_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*)) also (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * (e⇧T * e ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * e⇧T * e›*) have "... ≤ r⇧T * ?d⇧⋆ * 1 * e" by (metis assms( (*‹arc (e::'a::type)›*) 3) arc_injective (*‹arc (?x::'a::type) ⟹ injective ?x›*) comp_associative (*‹(?x::'a::type) * (?y::'a::type) * (?z::'a::type) = ?x * (?y * ?z)›*) comp_left_isotone (*‹(?x::'a::type) ≤ (?y::'a::type) ⟹ ?x * (?z::'a::type) ≤ ?y * ?z›*) comp_right_isotone (*‹(?x::'a::type) ≤ (?y::'a::type) ⟹ (?z::'a::type) * ?x ≤ ?z * ?y›*)) also (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * (e⇧T * e ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * 1 * e›*) have "... = r⇧T * ?d⇧⋆ * e" by simp finally (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * (e⇧T * e ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e›*) have 14: "r⇧T * ?d⇧⋆ * e * (e⇧T * e ⊓ g) ≤ r⇧T * ?d⇧⋆ * e" . have "r⇧T * ?d⇧⋆ * e * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) = r⇧T * ?d⇧⋆ * e * ((v * v⇧T ⊔ v * v⇧T * e ⊔ e⇧T * v * v⇧T ⊔ e⇧T * e) ⊓ g)" using "1" (*‹(v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T = v * v⇧T ⊔ v * v⇧T * e ⊔ e⇧T * v * v⇧T ⊔ e⇧T * e›*) by simp also (*calculation: ‹(r::'a)⇧T * ((v::'a) * v⇧T ⊓ (g::'a))⇧⋆ * (e::'a) * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) = r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * ((v * v⇧T ⊔ v * v⇧T * e ⊔ e⇧T * v * v⇧T ⊔ e⇧T * e) ⊓ g)›*) have "... = r⇧T * ?d⇧⋆ * e * ((v * v⇧T ⊓ g) ⊔ (v * v⇧T * e ⊓ g) ⊔ (e⇧T * v * v⇧T ⊓ g) ⊔ (e⇧T * e ⊓ g))" by (simp add: inf_sup_distrib2 (*‹(?y ⊔ ?z) ⊓ ?x = ?y ⊓ ?x ⊔ ?z ⊓ ?x›*)) also (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) = r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * (v * v⇧T ⊓ g ⊔ v * v⇧T * e ⊓ g ⊔ e⇧T * v * v⇧T ⊓ g ⊔ e⇧T * e ⊓ g)›*) have "... = r⇧T * ?d⇧⋆ * e * (v * v⇧T ⊓ g) ⊔ r⇧T * ?d⇧⋆ * e * (v * v⇧T * e ⊓ g) ⊔ r⇧T * ?d⇧⋆ * e * (e⇧T * v * v⇧T ⊓ g) ⊔ r⇧T * ?d⇧⋆ * e * (e⇧T * e ⊓ g)" by (simp add: comp_left_dist_sup (*‹(?x::'a) * (?y::'a) ⊔ ?x * (?z::'a) = ?x * (?y ⊔ ?z)›*)) also (*calculation: ‹(r::'a)⇧T * ((v::'a) * v⇧T ⊓ (g::'a))⇧⋆ * (e::'a) * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) = r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * (v * v⇧T ⊓ g) ⊔ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * (v * v⇧T * e ⊓ g) ⊔ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * (e⇧T * v * v⇧T ⊓ g) ⊔ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * (e⇧T * e ⊓ g)›*) have "... = r⇧T * ?d⇧⋆ * e * (e⇧T * v * v⇧T ⊓ g) ⊔ r⇧T * ?d⇧⋆ * e * (e⇧T * e ⊓ g)" using "11" (*‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * (v * v⇧T ⊓ g) = bot›*) "12" (*‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * (v * v⇧T * e ⊓ g) = bot›*) by simp also (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) = r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * (e⇧T * v * v⇧T ⊓ g) ⊔ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * (e⇧T * e ⊓ g)›*) have "... ≤ r⇧T * ?d⇧⋆ ⊔ r⇧T * ?d⇧⋆ * e" using "13" (*‹(r::'a::type)⇧T * ((v::'a::type) * v⇧T ⊓ (g::'a::type))⇧⋆ * (e::'a::type) * (e⇧T * v * v⇧T ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆›*) "14" (*‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * (e⇧T * e ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e›*) sup_mono (*‹⟦?a ≤ ?c; ?b ≤ ?d⟧ ⟹ ?a ⊔ ?b ≤ ?c ⊔ ?d›*) by simp also (*calculation: ‹(r::'a)⇧T * ((v::'a) * v⇧T ⊓ (g::'a))⇧⋆ * (e::'a) * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ ⊔ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e›*) have "... = r⇧T * ?d⇧⋆ * (1 ⊔ e)" by (simp add: mult_left_dist_sup (*‹?x * (?y ⊔ ?z) = ?x * ?y ⊔ ?x * ?z›*)) finally (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (1 ⊔ e)›*) have 15: "r⇧T * ?d⇧⋆ * e * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) ≤ r⇧T * ?d⇧⋆ * (1 ⊔ e)" by simp have "r⇧T ≤ r⇧T * ?d⇧⋆" using mult_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*) star.circ_reflexive (*‹reflexive (?x⇧⋆)›*) by fastforce also (*calculation: ‹r⇧T ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆›*) have "... ≤ r⇧T * ?d⇧⋆ * (1 ⊔ e)" by (simp add: semiring.distrib_left (*‹(?a::'a::type) * ((?b::'a::type) ⊔ (?c::'a::type)) = ?a * ?b ⊔ ?a * ?c›*)) finally (*calculation: ‹r⇧T ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (1 ⊔ e)›*) have 16: "r⇧T ≤ r⇧T * ?d⇧⋆ * (1 ⊔ e)" . have "r⇧T * ?d⇧⋆ * (1 ⊔ e) * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) = r⇧T * ?d⇧⋆ * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) ⊔ r⇧T * ?d⇧⋆ * e * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g)" by (simp add: semiring.distrib_left (*‹?a * (?b ⊔ ?c) = ?a * ?b ⊔ ?a * ?c›*) semiring.distrib_right (*‹(?a ⊔ ?b) * ?c = ?a * ?c ⊔ ?b * ?c›*)) also (*calculation: ‹(r::'a)⇧T * ((v::'a) * v⇧T ⊓ (g::'a))⇧⋆ * ((1::'a) ⊔ (e::'a)) * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) = r⇧T * (v * v⇧T ⊓ g)⇧⋆ * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) ⊔ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g)›*) have "... ≤ r⇧T * ?d⇧⋆ * (1 ⊔ e)" using "10" (*‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (1 ⊔ e)›*) "15" (*‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * e * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (1 ⊔ e)›*) le_supI (*‹⟦?a ≤ ?x; ?b ≤ ?x⟧ ⟹ ?a ⊔ ?b ≤ ?x›*) by simp finally (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (1 ⊔ e) * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (1 ⊔ e)›*) have "r⇧T * ?d⇧⋆ * (1 ⊔ e) * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) ≤ r⇧T * ?d⇧⋆ * (1 ⊔ e)" . hence "r⇧T ⊔ r⇧T * ?d⇧⋆ * (1 ⊔ e) * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g) ≤ r⇧T * ?d⇧⋆ * (1 ⊔ e)" using "16" (*‹r⇧T ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (1 ⊔ e)›*) sup_least (*‹⟦?y ≤ ?x; ?z ≤ ?x⟧ ⟹ ?y ⊔ ?z ≤ ?x›*) by simp hence "r⇧T * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g)⇧⋆ ≤ r⇧T * ?d⇧⋆ * (1 ⊔ e)" by (simp add: star_right_induct (*‹?z ⊔ ?x * ?y ≤ ?x ⟶ ?z * ?y⇧⋆ ≤ ?x›*)) also (*calculation: ‹r⇧T * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g)⇧⋆ ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (1 ⊔ e)›*) have "... ≤ r⇧T * t⇧⋆ * (1 ⊔ e)" by (simp add: assms( (*‹(r::'a)⇧T * ((v::'a) * v⇧T ⊓ (g::'a))⇧⋆ ≤ r⇧T * (t::'a)⇧⋆›*) 9) mult_left_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x * (?z::'a) ≤ ?y * ?z›*)) also (*calculation: ‹r⇧T * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g)⇧⋆ ≤ r⇧T * t⇧⋆ * (1 ⊔ e)›*) have "... ≤ r⇧T * (t ⊔ e)⇧⋆" by (simp add: star_one_sup_below (*‹?x * ?y⇧⋆ * (1 ⊔ ?z) ≤ ?x * (?y ⊔ ?z)⇧⋆›*)) finally (*calculation: ‹(r::'a)⇧T * (((v::'a) ⊔ (e::'a)⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ (g::'a))⇧⋆ ≤ r⇧T * ((t::'a) ⊔ e)⇧⋆›*) show "?thesis" (*goal: ‹r⇧T * ((v ⊔ e⇧T * top) * (v ⊔ e⇧T * top)⇧T ⊓ g)⇧⋆ ≤ r⇧T * (t ⊔ e)⇧⋆›*) . qed subsubsection ‹Exchange gives Spanning Trees› text ‹ The following abbreviations are used in the spanning tree application using Prim's algorithm to construct the new tree for the exchange property. It is obtained by replacing an edge with one that has minimal weight and reversing the path connecting these edges. Here, w represents a weighted graph, v represents a set of nodes and e represents an edge. › abbreviation prim_E :: "'a ⇒ 'a ⇒ 'a ⇒ 'a" where "prim_E w v e ≡ w ⊓ --v * -v⇧T ⊓ top * e * w⇧T⇧⋆" abbreviation prim_P :: "'a ⇒ 'a ⇒ 'a ⇒ 'a" where "prim_P w v e ≡ w ⊓ -v * -v⇧T ⊓ top * e * w⇧T⇧⋆" abbreviation prim_EP :: "'a ⇒ 'a ⇒ 'a ⇒ 'a" where "prim_EP w v e ≡ w ⊓ -v⇧T ⊓ top * e * w⇧T⇧⋆" abbreviation prim_W :: "'a ⇒ 'a ⇒ 'a ⇒ 'a" where "prim_W w v e ≡ (w ⊓ -(prim_EP w v e)) ⊔ (prim_P w v e)⇧T ⊔ e" text ‹ The lemmas in this section are used to show that the relation after exchange represents a spanning tree. The results in the next section are used to show that it is a minimum spanning tree. › lemma exchange_injective_3: assumes "e ≤ v * -v⇧T" and "vector v" shows "(w ⊓ -(prim_EP w v e)) * e⇧T = bot" proof (-) (*goal: ‹(w ⊓ - prim_EP w v e) * e⇧T = bot›*) have 1: "top * e ≤ -v⇧T" by (simp add: assms (*‹e ≤ v * - v⇧T› ‹vector v›*) schroeder_4_p (*‹(?x * ?y ≤ - ?z) = (?z * ?y⇧T ≤ - ?x)›*) vTeT (*‹⟦vector ?v; ?e ≤ ?v * - ?v⇧T⟧ ⟹ ?v⇧T * ?e⇧T = bot›*)) have "top * e ≤ top * e * w⇧T⇧⋆" using sup_right_divisibility (*‹(?x ≤ ?y) = (∃z. z ⊔ ?x = ?y)›*) star.circ_back_loop_fixpoint (*‹(?z::'a) * (?y::'a)⇧⋆ * ?y ⊔ ?z = ?z * ?y⇧⋆›*) by blast hence "top * e ≤ -v⇧T ⊓ top * e * w⇧T⇧⋆" using "1" (*‹top * e ≤ - v⇧T›*) by simp hence "top * e ≤ -(w ⊓ -prim_EP w v e)" by (metis inf.assoc (*‹?a ⊓ ?b ⊓ ?c = ?a ⊓ (?b ⊓ ?c)›*) inf_import_p (*‹?x ⊓ - (?x ⊓ ?y) = ?x ⊓ - ?y›*) le_infI2 (*‹?b ≤ ?x ⟹ ?a ⊓ ?b ≤ ?x›*) p_antitone (*‹?x ≤ ?y ⟹ - ?y ≤ - ?x›*) p_antitone_iff (*‹(?x ≤ - ?y) = (?y ≤ - ?x)›*)) hence "(w ⊓ -(prim_EP w v e)) * e⇧T ≤ bot" using p_top (*‹dense top›*) schroeder_4_p (*‹(?x * ?y ≤ - ?z) = (?z * ?y⇧T ≤ - ?x)›*) by blast thus "?thesis" (*goal: ‹(w ⊓ - prim_EP w v e) * e⇧T = bot›*) using le_bot (*‹(?a::'a::type) ≤ bot ⟹ ?a = bot›*) by simp qed lemma exchange_injective_6: assumes "arc e" and "forest w" shows "(prim_P w v e)⇧T * e⇧T = bot" proof (-) (*goal: ‹prim_P w v e⇧T * e⇧T = bot›*) have "e⇧T * top * e ≤ --1" by (simp add: assms( (*‹arc e›*) 1) p_antitone (*‹?x ≤ ?y ⟹ - ?y ≤ - ?x›*) p_antitone_iff (*‹(?x ≤ - ?y) = (?y ≤ - ?x)›*) point_injective (*‹arc ?x ⟹ coreflexive (?x⇧T * top * ?x)›*)) hence 1: "e * -1 * e⇧T ≤ bot" by (metis conv_involutive (*‹(?x::'a)⇧T⇧T = ?x›*) p_top (*‹dense top›*) triple_schroeder_p (*‹((?x::'a) * (?y::'a) * (?z::'a) ≤ - (?w::'a)) = (?x⇧T * ?w * ?z⇧T ≤ - ?y)›*)) have "(prim_P w v e)⇧T * e⇧T ≤ (w ⊓ top * e * w⇧T⇧⋆)⇧T * e⇧T" using comp_inf.mult_left_isotone (*‹?x ≤ ?y ⟹ ?x ⊓ ?z ≤ ?y ⊓ ?z›*) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) by simp also (*calculation: ‹prim_P w v e⇧T * e⇧T ≤ (w ⊓ top * e * w⇧T⇧⋆)⇧T * e⇧T›*) have "... = (w⇧T ⊓ w⇧T⇧⋆⇧T * e⇧T * top) * e⇧T" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*)) also (*calculation: ‹prim_P w v e⇧T * e⇧T ≤ (w⇧T ⊓ w⇧T⇧⋆⇧T * e⇧T * top) * e⇧T›*) have "... = w⇧⋆ * e⇧T * top ⊓ w⇧T * e⇧T" by (simp add: conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) inf_vector_comp (*‹(?x ⊓ ?y * top) * ?z = ?y * top ⊓ ?x * ?z›*)) also (*calculation: ‹prim_P w v e⇧T * e⇧T ≤ w⇧⋆ * e⇧T * top ⊓ w⇧T * e⇧T›*) have "... ≤ (w⇧T ⊓ w⇧⋆ * e⇧T * top * e) * (e⇧T ⊓ w⁺ * e⇧T * top)" by (metis dedekind (*‹(?x::'a) * (?y::'a) ⊓ (?z::'a) ≤ (?x ⊓ ?z * ?y⇧T) * (?y ⊓ ?x⇧T * ?z)›*) mult_assoc (*‹(?a::'a) * (?b::'a) * (?c::'a) = ?a * (?b * ?c)›*) conv_involutive (*‹(?x::'a)⇧T⇧T = ?x›*) inf_commute (*‹(?x::'a) ⊓ (?y::'a) = ?y ⊓ ?x›*)) also (*calculation: ‹prim_P w v e⇧T * e⇧T ≤ (w⇧T ⊓ w⇧⋆ * e⇧T * top * e) * (e⇧T ⊓ w⁺ * e⇧T * top)›*) have "... ≤ (w⇧⋆ * e⇧T * top * e) * (w⁺ * e⇧T * top)" by (simp add: mult_isotone (*‹⟦?w ≤ ?y; ?x ≤ ?z⟧ ⟹ ?w * ?x ≤ ?y * ?z›*)) also (*calculation: ‹prim_P w v e⇧T * e⇧T ≤ w⇧⋆ * e⇧T * top * e * (w⁺ * e⇧T * top)›*) have "... ≤ (top * e) * (w⁺ * e⇧T * top)" by (simp add: mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) also (*calculation: ‹prim_P w v e⇧T * e⇧T ≤ top * e * (w⁺ * e⇧T * top)›*) have "... = top * e * w⁺ * e⇧T * top" using mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) by simp also (*calculation: ‹prim_P w v e⇧T * e⇧T ≤ top * e * w⁺ * e⇧T * top›*) have "... ≤ top * e * -1 * e⇧T * top" using assms(2) (*‹forest w›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) by simp also (*calculation: ‹prim_P w v e⇧T * e⇧T ≤ top * e * - 1 * e⇧T * top›*) have "... ≤ bot" using "1" (*‹(e::'a) * - (1::'a) * e⇧T ≤ bot›*) by (metis le_bot (*‹?a ≤ bot ⟹ ?a = bot›*) semiring.mult_not_zero (*‹?a * ?b ≠ bot ⟹ ?a ≠ bot ∧ ?b ≠ bot›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) finally (*calculation: ‹prim_P w v e⇧T * e⇧T ≤ bot›*) show "?thesis" (*goal: ‹prim_P w v e⇧T * e⇧T = bot›*) using le_bot (*‹?a ≤ bot ⟹ ?a = bot›*) by simp qed text ‹ The graph after exchanging is injective. › lemma exchange_injective: assumes "arc e" and "e ≤ v * -v⇧T" and "forest w" and "vector v" shows "injective (prim_W w v e)" proof (-) (*goal: ‹injective (prim_W w v e)›*) have 1: "(w ⊓ -(prim_EP w v e)) * (w ⊓ -(prim_EP w v e))⇧T ≤ 1" proof (-) (*goal: ‹injective ((w::'a) ⊓ - prim_EP w (v::'a) (e::'a))›*) have "(w ⊓ -(prim_EP w v e)) * (w ⊓ -(prim_EP w v e))⇧T ≤ w * w⇧T" by (simp add: comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*)) also (*calculation: ‹(w ⊓ - prim_EP w v e) * (w ⊓ - prim_EP w v e)⇧T ≤ w * w⇧T›*) have "... ≤ 1" by (simp add: assms( (*‹forest w›*) 3)) finally (*calculation: ‹injective (w ⊓ - prim_EP w v e)›*) show "?thesis" (*goal: ‹injective ((w::'a) ⊓ - prim_EP w (v::'a) (e::'a))›*) . qed have 2: "(w ⊓ -(prim_EP w v e)) * (prim_P w v e)⇧T⇧T ≤ 1" proof (-) (*goal: ‹coreflexive ((w ⊓ - prim_EP w v e) * prim_P w v e⇧T⇧T)›*) have "top * (prim_P w v e)⇧T = top * (w⇧T ⊓ -v * -v⇧T ⊓ w⇧T⇧⋆⇧T * e⇧T * top)" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*)) also (*calculation: ‹top * prim_P w v e⇧T = top * (w⇧T ⊓ - v * - v⇧T ⊓ w⇧T⇧⋆⇧T * e⇧T * top)›*) have "... = top * e * w⇧T⇧⋆ * (w⇧T ⊓ -v * -v⇧T)" by (metis comp_inf_vector (*‹?x * (?y ⊓ ?z * top) = (?x ⊓ top * ?z⇧T) * ?y›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) inf_top_left (*‹top ⊓ ?x = ?x›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹top * prim_P w v e⇧T = top * e * w⇧T⇧⋆ * (w⇧T ⊓ - v * - v⇧T)›*) have "... ≤ top * e * w⇧T⇧⋆ * (w⇧T ⊓ top * -v⇧T)" using comp_inf.mult_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊓ ?x ≤ ?z ⊓ ?y›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) by simp also (*calculation: ‹top * prim_P (w::'a) (v::'a) (e::'a)⇧T ≤ top * e * w⇧T⇧⋆ * (w⇧T ⊓ top * - v⇧T)›*) have "... = top * e * w⇧T⇧⋆ * w⇧T ⊓ -v⇧T" by (metis assms( (*‹vector v›*) 4) comp_inf_covector (*‹?x * (?y ⊓ top * ?z) = ?x * ?y ⊓ top * ?z›*) vector_conv_compl (*‹vector ?v ⟹ covector (- ?v⇧T)›*)) also (*calculation: ‹top * prim_P w v e⇧T ≤ top * e * w⇧T⇧⋆ * w⇧T ⊓ - v⇧T›*) have "... ≤ -v⇧T ⊓ top * e * w⇧T⇧⋆" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) inf.coboundedI1 (*‹?a ≤ ?c ⟹ ?a ⊓ ?b ≤ ?c›*) star.circ_plus_same (*‹?x⇧⋆ * ?x = ?x⁺›*) star.left_plus_below_circ (*‹?x⁺ ≤ ?x⇧⋆›*)) finally (*calculation: ‹top * prim_P w v e⇧T ≤ - v⇧T ⊓ top * e * w⇧T⇧⋆›*) have "top * (prim_P w v e)⇧T ≤ -(w ⊓ -prim_EP w v e)" by (metis inf.assoc (*‹?a ⊓ ?b ⊓ ?c = ?a ⊓ (?b ⊓ ?c)›*) inf_import_p (*‹?x ⊓ - (?x ⊓ ?y) = ?x ⊓ - ?y›*) le_infI2 (*‹?b ≤ ?x ⟹ ?a ⊓ ?b ≤ ?x›*) p_antitone (*‹?x ≤ ?y ⟹ - ?y ≤ - ?x›*) p_antitone_iff (*‹(?x ≤ - ?y) = (?y ≤ - ?x)›*)) hence "(w ⊓ -(prim_EP w v e)) * (prim_P w v e)⇧T⇧T ≤ bot" using p_top (*‹dense top›*) schroeder_4_p (*‹((?x::'a::type) * (?y::'a::type) ≤ - (?z::'a::type)) = (?z * ?y⇧T ≤ - ?x)›*) by blast thus "?thesis" (*goal: ‹coreflexive ((w ⊓ - prim_EP w v e) * prim_P w v e⇧T⇧T)›*) by (simp add: bot_unique (*‹(?a ≤ bot) = (?a = bot)›*)) qed have 3: "(w ⊓ -(prim_EP w v e)) * e⇧T ≤ 1" by (metis assms( (*‹e ≤ v * - v⇧T› ‹vector v›*) 2,4) exchange_injective_3 (*‹⟦?e ≤ ?v * - ?v⇧T; vector ?v⟧ ⟹ (?w ⊓ - prim_EP ?w ?v ?e) * ?e⇧T = bot›*) bot_least (*‹bot ≤ ?a›*)) have 4: "(prim_P w v e)⇧T * (w ⊓ -(prim_EP w v e))⇧T ≤ 1" using "2" (*‹coreflexive ((w ⊓ - prim_EP w v e) * prim_P w v e⇧T⇧T)›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) coreflexive_symmetric (*‹coreflexive (?x::'a) ⟹ symmetric ?x›*) by fastforce have 5: "(prim_P w v e)⇧T * (prim_P w v e)⇧T⇧T ≤ 1" proof (-) (*goal: ‹injective (prim_P w v e⇧T)›*) have "(prim_P w v e)⇧T * (prim_P w v e)⇧T⇧T ≤ (top * e * w⇧T⇧⋆)⇧T * (top * e * w⇧T⇧⋆)" by (simp add: conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) mult_isotone (*‹⟦?w ≤ ?y; ?x ≤ ?z⟧ ⟹ ?w * ?x ≤ ?y * ?z›*)) also (*calculation: ‹prim_P w v e⇧T * prim_P w v e⇧T⇧T ≤ (top * e * w⇧T⇧⋆)⇧T * (top * e * w⇧T⇧⋆)›*) have "... = w⇧⋆ * e⇧T * top * top * e * w⇧T⇧⋆" using conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹(?x::'a)⇧T⇧T = ?x›*) conv_top (*‹symmetric top›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) by presburger also (*calculation: ‹prim_P w v e⇧T * prim_P w v e⇧T⇧T ≤ w⇧⋆ * e⇧T * top * top * e * w⇧T⇧⋆›*) have "... = w⇧⋆ * e⇧T * top * e * w⇧T⇧⋆" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*)) also (*calculation: ‹prim_P w v e⇧T * prim_P w v e⇧T⇧T ≤ w⇧⋆ * e⇧T * top * e * w⇧T⇧⋆›*) have "... ≤ w⇧⋆ * 1 * w⇧T⇧⋆" by (metis comp_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) comp_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) assms( (*‹arc e›*) 1) point_injective (*‹arc ?x ⟹ coreflexive (?x⇧T * top * ?x)›*)) finally (*calculation: ‹prim_P w v e⇧T * prim_P w v e⇧T⇧T ≤ w⇧⋆ * 1 * w⇧T⇧⋆›*) have "(prim_P w v e)⇧T * (prim_P w v e)⇧T⇧T ≤ w⇧⋆ * w⇧T⇧⋆ ⊓ w⇧T * w" by (simp add: conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) inf.left_commute (*‹?b ⊓ (?a ⊓ ?c) = ?a ⊓ (?b ⊓ ?c)›*) inf.sup_monoid.add_commute (*‹?a ⊓ ?b = ?b ⊓ ?a›*) mult_isotone (*‹⟦?w ≤ ?y; ?x ≤ ?z⟧ ⟹ ?w * ?x ≤ ?y * ?z›*)) also (*calculation: ‹prim_P w v e⇧T * prim_P w v e⇧T⇧T ≤ w⇧⋆ * w⇧T⇧⋆ ⊓ w⇧T * w›*) have "... ≤ 1" by (simp add: assms( (*‹forest w›*) 3) forest_separate (*‹forest ?x ⟹ coreflexive (?x⇧⋆ * ?x⇧T⇧⋆ ⊓ ?x⇧T * ?x)›*)) finally (*calculation: ‹injective (prim_P w v e⇧T)›*) show "?thesis" (*goal: ‹injective (prim_P w v e⇧T)›*) . qed have 6: "(prim_P w v e)⇧T * e⇧T ≤ 1" using assms (*‹arc e› ‹(e::'a) ≤ (v::'a) * - v⇧T› ‹forest w› ‹vector v›*) exchange_injective_6 (*‹⟦arc (?e::'a); forest (?w::'a)⟧ ⟹ prim_P ?w (?v::'a) ?e⇧T * ?e⇧T = bot›*) bot_least (*‹bot ≤ ?a›*) by simp have 7: "e * (w ⊓ -(prim_EP w v e))⇧T ≤ 1" using "3" (*‹coreflexive ((w ⊓ - prim_EP w v e) * e⇧T)›*) by (metis conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) coreflexive_symmetric (*‹coreflexive ?x ⟹ symmetric ?x›*)) have 8: "e * (prim_P w v e)⇧T⇧T ≤ 1" using "6" (*‹coreflexive (prim_P (w::'a::type) (v::'a::type) (e::'a::type)⇧T * e⇧T)›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) coreflexive_symmetric (*‹coreflexive (?x::'a::type) ⟹ symmetric ?x›*) by fastforce have 9: "e * e⇧T ≤ 1" by (simp add: assms( (*‹arc (e::'a)›*) 1) arc_injective (*‹arc (?x::'a) ⟹ injective ?x›*)) have "(prim_W w v e) * (prim_W w v e)⇧T = (w ⊓ -(prim_EP w v e)) * (w ⊓ -(prim_EP w v e))⇧T ⊔ (w ⊓ -(prim_EP w v e)) * (prim_P w v e)⇧T⇧T ⊔ (w ⊓ -(prim_EP w v e)) * e⇧T ⊔ (prim_P w v e)⇧T * (w ⊓ -(prim_EP w v e))⇧T ⊔ (prim_P w v e)⇧T * (prim_P w v e)⇧T⇧T ⊔ (prim_P w v e)⇧T * e⇧T ⊔ e * (w ⊓ -(prim_EP w v e))⇧T ⊔ e * (prim_P w v e)⇧T⇧T ⊔ e * e⇧T" using comp_left_dist_sup (*‹(?x::'a) * (?y::'a) ⊔ ?x * (?z::'a) = ?x * (?y ⊔ ?z)›*) comp_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*) conv_dist_sup (*‹(?x ⊔ ?y)⇧T = ?x⇧T ⊔ ?y⇧T›*) sup.assoc (*‹?a ⊔ ?b ⊔ ?c = ?a ⊔ (?b ⊔ ?c)›*) by simp also (*calculation: ‹prim_W w v e * prim_W w v e⇧T = (w ⊓ - prim_EP w v e) * (w ⊓ - prim_EP w v e)⇧T ⊔ (w ⊓ - prim_EP w v e) * prim_P w v e⇧T⇧T ⊔ (w ⊓ - prim_EP w v e) * e⇧T ⊔ prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⇧T ⊔ prim_P w v e⇧T * prim_P w v e⇧T⇧T ⊔ prim_P w v e⇧T * e⇧T ⊔ e * (w ⊓ - prim_EP w v e)⇧T ⊔ e * prim_P w v e⇧T⇧T ⊔ e * e⇧T›*) have "... ≤ 1" using "1" (*‹injective (w ⊓ - prim_EP w v e)›*) "2" (*‹coreflexive ((w ⊓ - prim_EP w v e) * prim_P w v e⇧T⇧T)›*) "3" (*‹coreflexive ((w ⊓ - prim_EP w v e) * e⇧T)›*) "4" (*‹coreflexive (prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⇧T)›*) "5" (*‹injective (prim_P w v e⇧T)›*) "6" (*‹coreflexive (prim_P w v e⇧T * e⇧T)›*) "7" (*‹coreflexive (e * (w ⊓ - prim_EP w v e)⇧T)›*) "8" (*‹coreflexive ((e::'a::type) * prim_P (w::'a::type) (v::'a::type) e⇧T⇧T)›*) "9" (*‹injective e›*) by simp finally (*calculation: ‹injective (prim_W w v e)›*) show "?thesis" (*goal: ‹injective (prim_W w v e)›*) . qed lemma pv: assumes "vector v" shows "(prim_P w v e)⇧T * v = bot" proof (-) (*goal: ‹prim_P w v e⇧T * v = bot›*) have "(prim_P w v e)⇧T * v ≤ (-v * -v⇧T)⇧T * v" by (meson conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) inf_le1 (*‹?x ⊓ ?y ≤ ?x›*) inf_le2 (*‹?x ⊓ ?y ≤ ?y›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) order_trans (*‹⟦?x ≤ ?y; ?y ≤ ?z⟧ ⟹ ?x ≤ ?z›*)) also (*calculation: ‹prim_P (w::'a::type) (v::'a::type) (e::'a::type)⇧T * v ≤ (- v * - v⇧T)⇧T * v›*) have "... = -v * -v⇧T * v" by (simp add: conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*)) also (*calculation: ‹prim_P w v e⇧T * v ≤ - v * - v⇧T * v›*) have "... = bot" by (simp add: assms (*‹vector v›*) covector_vector_comp (*‹vector ?v ⟹ - ?v⇧T * ?v = bot›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) finally (*calculation: ‹prim_P w v e⇧T * v ≤ bot›*) show "?thesis" (*goal: ‹prim_P w v e⇧T * v = bot›*) by (simp add: order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) qed lemma vector_pred_inv: assumes "arc e" and "e ≤ v * -v⇧T" and "forest w" and "vector v" and "w * v ≤ v" shows "(prim_W w v e) * (v ⊔ e⇧T * top) ≤ v ⊔ e⇧T * top" proof (-) (*goal: ‹prim_W w v e * (v ⊔ e⇧T * top) ≤ v ⊔ e⇧T * top›*) have "(prim_W w v e) * e⇧T * top = (w ⊓ -(prim_EP w v e)) * e⇧T * top ⊔ (prim_P w v e)⇧T * e⇧T * top ⊔ e * e⇧T * top" by (simp add: mult_right_dist_sup (*‹((?x::'a) ⊔ (?y::'a)) * (?z::'a) = ?x * ?z ⊔ ?y * ?z›*)) also (*calculation: ‹prim_W w v e * e⇧T * top = (w ⊓ - prim_EP w v e) * e⇧T * top ⊔ prim_P w v e⇧T * e⇧T * top ⊔ e * e⇧T * top›*) have "... = e * e⇧T * top" using assms (*‹arc e› ‹e ≤ v * - v⇧T› ‹forest (w::'a)› ‹vector v› ‹w * v ≤ v›*) exchange_injective_3 (*‹⟦(?e::'a) ≤ (?v::'a) * - ?v⇧T; vector ?v⟧ ⟹ ((?w::'a) ⊓ - prim_EP ?w ?v ?e) * ?e⇧T = bot›*) exchange_injective_6 (*‹⟦arc ?e; forest ?w⟧ ⟹ prim_P ?w ?v ?e⇧T * ?e⇧T = bot›*) comp_left_zero (*‹bot * ?x = bot›*) by simp also (*calculation: ‹prim_W (w::'a) (v::'a) (e::'a) * e⇧T * top = e * e⇧T * top›*) have "... ≤ v * -v⇧T * e⇧T * top" by (simp add: assms( (*‹e ≤ v * - v⇧T›*) 2) comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*)) also (*calculation: ‹prim_W w v e * e⇧T * top ≤ v * - v⇧T * e⇧T * top›*) have "... ≤ v * top" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹prim_W w v e * e⇧T * top ≤ v * top›*) have "... = v" by (simp add: assms( (*‹vector v›*) 4)) finally (*calculation: ‹prim_W (w::'a::type) (v::'a::type) (e::'a::type) * e⇧T * top ≤ v›*) have 1: "(prim_W w v e) * e⇧T * top ≤ v" . have "(prim_W w v e) * v = (w ⊓ -(prim_EP w v e)) * v ⊔ (prim_P w v e)⇧T * v ⊔ e * v" by (simp add: mult_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*)) also (*calculation: ‹prim_W w v e * v = (w ⊓ - prim_EP w v e) * v ⊔ prim_P w v e⇧T * v ⊔ e * v›*) have "... = (w ⊓ -(prim_EP w v e)) * v" by (metis assms( (*‹e ≤ v * - v⇧T› ‹vector v›*) 2,4) pv (*‹vector ?v ⟹ prim_P ?w ?v ?e⇧T * ?v = bot›*) ev (*‹⟦vector ?v; ?e ≤ ?v * - ?v⇧T⟧ ⟹ ?e * ?v = bot›*) sup_bot_right (*‹?x ⊔ bot = ?x›*)) also (*calculation: ‹prim_W w v e * v = (w ⊓ - prim_EP w v e) * v›*) have "... ≤ w * v" by (simp add: mult_left_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x * (?z::'a) ≤ ?y * ?z›*)) finally (*calculation: ‹prim_W w v e * v ≤ w * v›*) have 2: "(prim_W w v e) * v ≤ v" using assms(5) (*‹w * v ≤ v›*) order_trans (*‹⟦?x ≤ ?y; ?y ≤ ?z⟧ ⟹ ?x ≤ ?z›*) by blast have "(prim_W w v e) * (v ⊔ e⇧T * top) = (prim_W w v e) * v ⊔ (prim_W w v e) * e⇧T * top" by (simp add: semiring.distrib_left (*‹?a * (?b ⊔ ?c) = ?a * ?b ⊔ ?a * ?c›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹prim_W (w::'a::type) (v::'a::type) (e::'a::type) * (v ⊔ e⇧T * top) = prim_W w v e * v ⊔ prim_W w v e * e⇧T * top›*) have "... ≤ v" using "1" (*‹prim_W (w::'a::type) (v::'a::type) (e::'a::type) * e⇧T * top ≤ v›*) "2" (*‹prim_W w v e * v ≤ v›*) by simp also (*calculation: ‹prim_W w v e * (v ⊔ e⇧T * top) ≤ v›*) have "... ≤ v ⊔ e⇧T * top" by simp finally (*calculation: ‹prim_W w v e * (v ⊔ e⇧T * top) ≤ v ⊔ e⇧T * top›*) show "?thesis" (*goal: ‹prim_W w v e * (v ⊔ e⇧T * top) ≤ v ⊔ e⇧T * top›*) . qed text ‹ The graph after exchanging is acyclic. › lemma exchange_acyclic: assumes "vector v" and "e ≤ v * -v⇧T" and "w * v ≤ v" and "acyclic w" shows "acyclic (prim_W w v e)" proof (-) (*goal: ‹pd_kleene_allegory_class.acyclic (prim_W w v e)›*) have 1: "(prim_P w v e)⇧T * e = bot" proof (-) (*goal: ‹prim_P w v e⇧T * e = bot›*) have "(prim_P w v e)⇧T * e ≤ (-v * -v⇧T)⇧T * e" by (meson conv_order (*‹(?x ≤ ?y) = (?x⇧T ≤ ?y⇧T)›*) dual_order.trans (*‹⟦?b ≤ ?a; ?c ≤ ?b⟧ ⟹ ?c ≤ ?a›*) inf.cobounded1 (*‹?a ⊓ ?b ≤ ?a›*) inf.cobounded2 (*‹?a ⊓ ?b ≤ ?b›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) also (*calculation: ‹prim_P w v e⇧T * e ≤ (- v * - v⇧T)⇧T * e›*) have "... = -v * -v⇧T * e" by (simp add: conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*)) also (*calculation: ‹prim_P w v e⇧T * e ≤ - v * - v⇧T * e›*) have "... ≤ -v * -v⇧T * v * -v⇧T" by (simp add: assms( (*‹(e::'a) ≤ (v::'a) * - v⇧T›*) 2) comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*) mult_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*)) also (*calculation: ‹prim_P w v e⇧T * e ≤ - v * - v⇧T * v * - v⇧T›*) have "... = bot" by (simp add: assms( (*‹vector (v::'a::type)›*) 1) covector_vector_comp (*‹vector (?v::'a::type) ⟹ - ?v⇧T * ?v = bot›*) mult_assoc (*‹(?a::'a::type) * (?b::'a::type) * (?c::'a::type) = ?a * (?b * ?c)›*)) finally (*calculation: ‹prim_P w v e⇧T * e ≤ bot›*) show "?thesis" (*goal: ‹prim_P (w::'a) (v::'a) (e::'a)⇧T * e = bot›*) by (simp add: bot_unique (*‹(?a ≤ bot) = (?a = bot)›*)) qed have 2: "e * e = bot" using assms(1,2) (*‹vector v› ‹e ≤ v * - v⇧T›*) ee (*‹⟦vector ?v; ?e ≤ ?v * - ?v⇧T⟧ ⟹ ?e * ?e = bot›*) by auto have 3: "(w ⊓ -(prim_EP w v e)) * (prim_P w v e)⇧T = bot" proof (-) (*goal: ‹((w::'a) ⊓ - prim_EP w (v::'a) (e::'a)) * prim_P w v e⇧T = bot›*) have "top * (prim_P w v e) ≤ top * (-v * -v⇧T ⊓ top * e * w⇧T⇧⋆)" using comp_inf.mult_semi_associative (*‹?x ⊓ ?y ⊓ ?z ≤ ?x ⊓ (?y ⊓ ?z)›*) mult_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*) by auto also (*calculation: ‹top * prim_P w v e ≤ top * (- v * - v⇧T ⊓ top * e * w⇧T⇧⋆)›*) have "... ≤ top * -v * -v⇧T ⊓ top * top * e * w⇧T⇧⋆" by (simp add: comp_inf_covector (*‹?x * (?y ⊓ top * ?z) = ?x * ?y ⊓ top * ?z›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹top * prim_P w v e ≤ top * - v * - v⇧T ⊓ top * top * e * w⇧T⇧⋆›*) have "... ≤ top * -v⇧T ⊓ top * e * w⇧T⇧⋆" using mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) top.extremum (*‹?a ≤ top›*) inf_mono (*‹⟦(?a::'a::type) ≤ (?c::'a::type); (?b::'a::type) ≤ (?d::'a::type)⟧ ⟹ ?a ⊓ ?b ≤ ?c ⊓ ?d›*) by presburger also (*calculation: ‹top * prim_P w v e ≤ top * - v⇧T ⊓ top * e * w⇧T⇧⋆›*) have "... = -v⇧T ⊓ top * e * w⇧T⇧⋆" by (simp add: assms( (*‹vector v›*) 1) vector_conv_compl (*‹vector ?v ⟹ covector (- ?v⇧T)›*)) finally (*calculation: ‹top * prim_P w v e ≤ - v⇧T ⊓ top * e * w⇧T⇧⋆›*) have "top * (prim_P w v e) ≤ -(w ⊓ -prim_EP w v e)" by (metis inf.assoc (*‹(?a::'a::type) ⊓ (?b::'a::type) ⊓ (?c::'a::type) = ?a ⊓ (?b ⊓ ?c)›*) inf_import_p (*‹(?x::'a::type) ⊓ - (?x ⊓ (?y::'a::type)) = ?x ⊓ - ?y›*) le_infI2 (*‹(?b::'a::type) ≤ (?x::'a::type) ⟹ (?a::'a::type) ⊓ ?b ≤ ?x›*) p_antitone (*‹(?x::'a::type) ≤ (?y::'a::type) ⟹ - ?y ≤ - ?x›*) p_antitone_iff (*‹((?x::'a::type) ≤ - (?y::'a::type)) = (?y ≤ - ?x)›*)) hence "(w ⊓ -(prim_EP w v e)) * (prim_P w v e)⇧T ≤ bot" using p_top (*‹dense top›*) schroeder_4_p (*‹(?x * ?y ≤ - ?z) = (?z * ?y⇧T ≤ - ?x)›*) by blast thus "?thesis" (*goal: ‹((w::'a) ⊓ - prim_EP w (v::'a) (e::'a)) * prim_P w v e⇧T = bot›*) using bot_unique (*‹(?a ≤ bot) = (?a = bot)›*) by blast qed hence 4: "(w ⊓ -(prim_EP w v e)) * (prim_P w v e)⇧T⇧⋆ = w ⊓ -(prim_EP w v e)" using star_absorb (*‹?x * ?y = bot ⟹ ?x * ?y⇧⋆ = ?x›*) by blast hence 5: "(w ⊓ -(prim_EP w v e))⁺ * (prim_P w v e)⇧T⇧⋆ = (w ⊓ -(prim_EP w v e))⁺" by (metis star_plus (*‹?y⇧⋆ * ?y = ?y⁺›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) hence 6: "(w ⊓ -(prim_EP w v e))⇧⋆ * (prim_P w v e)⇧T⇧⋆ = (w ⊓ -(prim_EP w v e))⁺ ⊔ (prim_P w v e)⇧T⇧⋆" by (metis star.circ_loop_fixpoint (*‹?y * (?y⇧⋆ * ?z) ⊔ ?z = ?y⇧⋆ * ?z›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) have 7: "(w ⊓ -(prim_EP w v e))⁺ * e ≤ v * top" proof (-) (*goal: ‹(w ⊓ - prim_EP w v e)⁺ * e ≤ v * top›*) have "e ≤ v * top" using assms(2) (*‹e ≤ v * - v⇧T›*) dual_order.trans (*‹⟦?b ≤ ?a; ?c ≤ ?b⟧ ⟹ ?c ≤ ?a›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) top_greatest (*‹?x ≤ top›*) by blast hence 8: "e ⊔ w * v * top ≤ v * top" by (simp add: assms( (*‹vector (v::'a::type)› ‹(w::'a::type) * (v::'a::type) ≤ v›*) 1,3) comp_associative (*‹(?x::'a::type) * (?y::'a::type) * (?z::'a::type) = ?x * (?y * ?z)›*)) have "(w ⊓ -(prim_EP w v e))⁺ * e ≤ w⁺ * e" by (simp add: comp_isotone (*‹⟦(?x::'a) ≤ (?y::'a); (?w::'a) ≤ (?z::'a)⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) star_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) also (*calculation: ‹(w ⊓ - prim_EP w v e)⁺ * e ≤ w⁺ * e›*) have "... ≤ w⇧⋆ * e" by (simp add: mult_left_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x * (?z::'a) ≤ ?y * ?z›*) star.left_plus_below_circ (*‹(?x::'a)⁺ ≤ ?x⇧⋆›*)) also (*calculation: ‹(w ⊓ - prim_EP w v e)⁺ * e ≤ w⇧⋆ * e›*) have "... ≤ v * top" using "8" (*‹(e::'a) ⊔ (w::'a) * (v::'a) * top ≤ v * top›*) by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) star_left_induct (*‹?z ⊔ ?y * ?x ≤ ?x ⟶ ?y⇧⋆ * ?z ≤ ?x›*)) finally (*calculation: ‹(w ⊓ - prim_EP w v e)⁺ * e ≤ v * top›*) show "?thesis" (*goal: ‹(w ⊓ - prim_EP w v e)⁺ * e ≤ v * top›*) . qed have 9: "(prim_P w v e)⇧T * (w ⊓ -(prim_EP w v e))⁺ * e = bot" proof (-) (*goal: ‹prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⁺ * e = bot›*) have "(prim_P w v e)⇧T * (w ⊓ -(prim_EP w v e))⁺ * e ≤ (prim_P w v e)⇧T * v * top" using "7" (*‹(w ⊓ - prim_EP w v e)⁺ * e ≤ v * top›*) by (simp add: mult_assoc (*‹(?a::'a::type) * (?b::'a::type) * (?c::'a::type) = ?a * (?b * ?c)›*) mult_right_isotone (*‹(?x::'a::type) ≤ (?y::'a::type) ⟹ (?z::'a::type) * ?x ≤ ?z * ?y›*)) also (*calculation: ‹prim_P (w::'a::type) (v::'a::type) (e::'a::type)⇧T * (w ⊓ - prim_EP w v e)⁺ * e ≤ prim_P w v e⇧T * v * top›*) have "... = bot" by (simp add: assms( (*‹vector (v::'a::type)›*) 1) pv (*‹vector (?v::'a::type) ⟹ prim_P (?w::'a::type) ?v (?e::'a::type)⇧T * ?v = bot›*)) finally (*calculation: ‹prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⁺ * e ≤ bot›*) show "?thesis" (*goal: ‹prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⁺ * e = bot›*) using bot_unique (*‹(?a ≤ bot) = (?a = bot)›*) by blast qed have 10: "e * (w ⊓ -(prim_EP w v e))⁺ * e = bot" proof (-) (*goal: ‹e * (w ⊓ - prim_EP w v e)⁺ * e = bot›*) have "e * (w ⊓ -(prim_EP w v e))⁺ * e ≤ e * v * top" using "7" (*‹(w ⊓ - prim_EP w v e)⁺ * e ≤ v * top›*) by (simp add: mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹e * (w ⊓ - prim_EP w v e)⁺ * e ≤ e * v * top›*) have "... ≤ v * -v⇧T * v * top" by (simp add: assms( (*‹(e::'a) ≤ (v::'a) * - v⇧T›*) 2) mult_left_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x * (?z::'a) ≤ ?y * ?z›*)) also (*calculation: ‹(e::'a::type) * ((w::'a::type) ⊓ - prim_EP w (v::'a::type) e)⁺ * e ≤ v * - v⇧T * v * top›*) have "... = bot" by (simp add: assms( (*‹vector v›*) 1) covector_vector_comp (*‹vector ?v ⟹ - ?v⇧T * ?v = bot›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) finally (*calculation: ‹e * (w ⊓ - prim_EP w v e)⁺ * e ≤ bot›*) show "?thesis" (*goal: ‹(e::'a) * ((w::'a) ⊓ - prim_EP w (v::'a) e)⁺ * e = bot›*) using bot_unique (*‹(?a ≤ bot) = (?a = bot)›*) by blast qed have 11: "e * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆ ≤ v * -v⇧T" proof (-) (*goal: ‹e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ ≤ v * - v⇧T›*) have 12: "-v⇧T * w ≤ -v⇧T" by (metis assms( (*‹w * v ≤ v›*) 3) conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) order_lesseq_imp (*‹(∀z≥?x. ?y ≤ z) = (?y ≤ ?x)›*) pp_increasing (*‹?x ≤ - - ?x›*) schroeder_6_p (*‹(?x * ?y ≤ - ?z) = (?z⇧T * ?x ≤ - ?y⇧T)›*)) have "v * -v⇧T * (w ⊓ -(prim_EP w v e)) ≤ v * -v⇧T * w" by (simp add: comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) also (*calculation: ‹v * - v⇧T * (w ⊓ - prim_EP w v e) ≤ v * - v⇧T * w›*) have "... ≤ v * -v⇧T" using "12" (*‹- (v::'a)⇧T * (w::'a) ≤ - v⇧T›*) by (simp add: comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*)) finally (*calculation: ‹v * - v⇧T * (w ⊓ - prim_EP w v e) ≤ v * - v⇧T›*) have 13: "v * -v⇧T * (w ⊓ -(prim_EP w v e)) ≤ v * -v⇧T" . have 14: "(prim_P w v e)⇧T ≤ -v * -v⇧T" by (metis conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_order (*‹(?x ≤ ?y) = (?x⇧T ≤ ?y⇧T)›*) inf_le1 (*‹?x ⊓ ?y ≤ ?x›*) inf_le2 (*‹?x ⊓ ?y ≤ ?y›*) order_trans (*‹⟦?x ≤ ?y; ?y ≤ ?z⟧ ⟹ ?x ≤ ?z›*)) have "e * (prim_P w v e)⇧T⇧⋆ ≤ v * -v⇧T * (prim_P w v e)⇧T⇧⋆" by (simp add: assms( (*‹e ≤ v * - v⇧T›*) 2) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) also (*calculation: ‹e * prim_P w v e⇧T⇧⋆ ≤ v * - v⇧T * prim_P w v e⇧T⇧⋆›*) have "... = v * -v⇧T ⊔ v * -v⇧T * (prim_P w v e)⇧T⁺" by (metis mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) star.circ_back_loop_fixpoint (*‹?z * ?y⇧⋆ * ?y ⊔ ?z = ?z * ?y⇧⋆›*) star_plus (*‹?y⇧⋆ * ?y = ?y⁺›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*)) also (*calculation: ‹(e::'a) * prim_P (w::'a) (v::'a) e⇧T⇧⋆ ≤ v * - v⇧T ⊔ v * - v⇧T * prim_P w v e⇧T⁺›*) have "... = v * -v⇧T ⊔ v * -v⇧T * (prim_P w v e)⇧T⇧⋆ * (prim_P w v e)⇧T" by (simp add: mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) star_plus (*‹?y⇧⋆ * ?y = ?y⁺›*)) also (*calculation: ‹e * prim_P w v e⇧T⇧⋆ ≤ v * - v⇧T ⊔ v * - v⇧T * prim_P w v e⇧T⇧⋆ * prim_P w v e⇧T›*) have "... ≤ v * -v⇧T ⊔ v * -v⇧T * (prim_P w v e)⇧T⇧⋆ * -v * -v⇧T" using "14" (*‹prim_P w v e⇧T ≤ - v * - v⇧T›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) sup_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊔ ?x ≤ ?z ⊔ ?y›*) by simp also (*calculation: ‹e * prim_P w v e⇧T⇧⋆ ≤ v * - v⇧T ⊔ v * - v⇧T * prim_P w v e⇧T⇧⋆ * - v * - v⇧T›*) have "... ≤ v * -v⇧T ⊔ v * top * -v⇧T" by (metis top_greatest (*‹?x ≤ top›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) sup_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊔ ?x ≤ ?z ⊔ ?y›*)) also (*calculation: ‹e * prim_P w v e⇧T⇧⋆ ≤ v * - v⇧T ⊔ v * top * - v⇧T›*) have "... = v * -v⇧T" by (simp add: assms( (*‹vector (v::'a)›*) 1)) finally (*calculation: ‹e * prim_P w v e⇧T⇧⋆ ≤ v * - v⇧T›*) have "e * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆ ≤ v * -v⇧T * (w ⊓ -(prim_EP w v e))⇧⋆" by (simp add: mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) also (*calculation: ‹e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ ≤ v * - v⇧T * (w ⊓ - prim_EP w v e)⇧⋆›*) have "... ≤ v * -v⇧T" using "13" (*‹v * - v⇧T * (w ⊓ - prim_EP w v e) ≤ v * - v⇧T›*) by (simp add: star_right_induct_mult (*‹?y * ?x ≤ ?y ⟹ ?y * ?x⇧⋆ ≤ ?y›*)) finally (*calculation: ‹(e::'a) * prim_P (w::'a) (v::'a) e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ ≤ v * - v⇧T›*) show "?thesis" (*goal: ‹e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ ≤ v * - v⇧T›*) . qed have 15: "(w ⊓ -(prim_EP w v e))⁺ * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆ ≤ -1" proof (-) (*goal: ‹irreflexive ((w ⊓ - prim_EP w v e)⁺ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) have "(w ⊓ -(prim_EP w v e))⁺ * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆ = (w ⊓ -(prim_EP w v e))⁺ * (w ⊓ -(prim_EP w v e))⇧⋆" using "5" (*‹(w ⊓ - prim_EP w v e)⁺ * prim_P w v e⇧T⇧⋆ = (w ⊓ - prim_EP w v e)⁺›*) by simp also (*calculation: ‹(w ⊓ - prim_EP w v e)⁺ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ = (w ⊓ - prim_EP w v e)⁺ * (w ⊓ - prim_EP w v e)⇧⋆›*) have "... = (w ⊓ -(prim_EP w v e))⁺" by (simp add: mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) star.circ_transitive_equal (*‹idempotent (?x⇧⋆)›*)) also (*calculation: ‹(w ⊓ - prim_EP w v e)⁺ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ = (w ⊓ - prim_EP w v e)⁺›*) have "... ≤ w⁺" by (simp add: comp_isotone (*‹⟦(?x::'a) ≤ (?y::'a); (?w::'a) ≤ (?z::'a)⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) star_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) finally (*calculation: ‹(w ⊓ - prim_EP w v e)⁺ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ ≤ w⁺›*) show "?thesis" (*goal: ‹irreflexive ((w ⊓ - prim_EP w v e)⁺ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) using assms(4) (*‹pd_kleene_allegory_class.acyclic w›*) by simp qed have 16: "(prim_P w v e)⇧T * (w ⊓ -(prim_EP w v e))⇧⋆ * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆ ≤ -1" proof (-) (*goal: ‹irreflexive (prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) have "(w ⊓ -(prim_EP w v e))⁺ * (prim_P w v e)⇧T⁺ ≤ (w ⊓ -(prim_EP w v e))⁺ * (prim_P w v e)⇧T⇧⋆" by (simp add: mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star.left_plus_below_circ (*‹?x⁺ ≤ ?x⇧⋆›*)) also (*calculation: ‹(w ⊓ - prim_EP w v e)⁺ * prim_P w v e⇧T⁺ ≤ (w ⊓ - prim_EP w v e)⁺ * prim_P w v e⇧T⇧⋆›*) have "... = (w ⊓ -(prim_EP w v e))⁺" using "5" (*‹((w::'a) ⊓ - prim_EP w (v::'a) (e::'a))⁺ * prim_P w v e⇧T⇧⋆ = (w ⊓ - prim_EP w v e)⁺›*) by simp also (*calculation: ‹((w::'a::type) ⊓ - prim_EP w (v::'a::type) (e::'a::type))⁺ * prim_P w v e⇧T⁺ ≤ (w ⊓ - prim_EP w v e)⁺›*) have "... ≤ w⁺" by (simp add: comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) finally (*calculation: ‹(w ⊓ - prim_EP w v e)⁺ * prim_P w v e⇧T⁺ ≤ w⁺›*) have "(w ⊓ -(prim_EP w v e))⁺ * (prim_P w v e)⇧T⁺ ≤ -1" using assms(4) (*‹pd_kleene_allegory_class.acyclic w›*) by simp hence 17: "(prim_P w v e)⇧T⁺ * (w ⊓ -(prim_EP w v e))⁺ ≤ -1" by (simp add: comp_commute_below_diversity (*‹irreflexive (?x * ?y) = irreflexive (?y * ?x)›*)) have "(prim_P w v e)⇧T⁺ ≤ w⇧T⁺" by (simp add: comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) inf.left_commute (*‹?b ⊓ (?a ⊓ ?c) = ?a ⊓ (?b ⊓ ?c)›*) inf.sup_monoid.add_commute (*‹?a ⊓ ?b = ?b ⊓ ?a›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) also (*calculation: ‹prim_P w v e⇧T⁺ ≤ w⇧T⁺›*) have "... = w⁺⇧T" by (simp add: conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) star_plus (*‹?y⇧⋆ * ?y = ?y⁺›*)) also (*calculation: ‹prim_P w v e⇧T⁺ ≤ w⁺⇧T›*) have "... ≤ -1" using assms(4) (*‹pd_kleene_allegory_class.acyclic w›*) conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) by force finally (*calculation: ‹pd_kleene_allegory_class.acyclic (prim_P w v e⇧T)›*) have 18: "(prim_P w v e)⇧T⁺ ≤ -1" . have "(prim_P w v e)⇧T * (w ⊓ -(prim_EP w v e))⇧⋆ * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆ = (prim_P w v e)⇧T * ((w ⊓ -(prim_EP w v e))⁺ ⊔ (prim_P w v e)⇧T⇧⋆) * (w ⊓ -(prim_EP w v e))⇧⋆" using "6" (*‹((w::'a::type) ⊓ - prim_EP w (v::'a::type) (e::'a::type))⇧⋆ * prim_P w v e⇧T⇧⋆ = (w ⊓ - prim_EP w v e)⁺ ⊔ prim_P w v e⇧T⇧⋆›*) by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*)) also (*calculation: ‹prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ = prim_P w v e⇧T * ((w ⊓ - prim_EP w v e)⁺ ⊔ prim_P w v e⇧T⇧⋆) * (w ⊓ - prim_EP w v e)⇧⋆›*) have "... = (prim_P w v e)⇧T * (w ⊓ -(prim_EP w v e))⁺ * (w ⊓ -(prim_EP w v e))⇧⋆ ⊔ (prim_P w v e)⇧T⁺ * (w ⊓ -(prim_EP w v e))⇧⋆" by (simp add: mult_left_dist_sup (*‹?x * (?y ⊔ ?z) = ?x * ?y ⊔ ?x * ?z›*) mult_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*)) also (*calculation: ‹prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ = prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⁺ * (w ⊓ - prim_EP w v e)⇧⋆ ⊔ prim_P w v e⇧T⁺ * (w ⊓ - prim_EP w v e)⇧⋆›*) have "... = (prim_P w v e)⇧T * (w ⊓ -(prim_EP w v e))⁺ ⊔ (prim_P w v e)⇧T⁺ * (w ⊓ -(prim_EP w v e))⇧⋆" by (simp add: mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) star.circ_transitive_equal (*‹idempotent (?x⇧⋆)›*)) also (*calculation: ‹prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ = prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⁺ ⊔ prim_P w v e⇧T⁺ * (w ⊓ - prim_EP w v e)⇧⋆›*) have "... = (prim_P w v e)⇧T * (w ⊓ -(prim_EP w v e))⁺ ⊔ (prim_P w v e)⇧T⁺ * (1 ⊔ (w ⊓ -(prim_EP w v e))⁺)" using star_left_unfold_equal (*‹1 ⊔ ?x⁺ = ?x⇧⋆›*) by simp also (*calculation: ‹prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ = prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⁺ ⊔ prim_P w v e⇧T⁺ * (1 ⊔ (w ⊓ - prim_EP w v e)⁺)›*) have "... = (prim_P w v e)⇧T * (w ⊓ -(prim_EP w v e))⁺ ⊔ (prim_P w v e)⇧T⁺ * (w ⊓ -(prim_EP w v e))⁺ ⊔ (prim_P w v e)⇧T⁺" by (simp add: mult_left_dist_sup (*‹?x * (?y ⊔ ?z) = ?x * ?y ⊔ ?x * ?z›*) sup.left_commute (*‹?b ⊔ (?a ⊔ ?c) = ?a ⊔ (?b ⊔ ?c)›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*)) also (*calculation: ‹prim_P (w::'a) (v::'a) (e::'a)⇧T * (w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ = prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⁺ ⊔ prim_P w v e⇧T⁺ * (w ⊓ - prim_EP w v e)⁺ ⊔ prim_P w v e⇧T⁺›*) have "... = ((prim_P w v e)⇧T ⊔ (prim_P w v e)⇧T⁺) * (w ⊓ -(prim_EP w v e))⁺ ⊔ (prim_P w v e)⇧T⁺" by (simp add: mult_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*)) also (*calculation: ‹prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ = (prim_P w v e⇧T ⊔ prim_P w v e⇧T⁺) * (w ⊓ - prim_EP w v e)⁺ ⊔ prim_P w v e⇧T⁺›*) have "... = (prim_P w v e)⇧T⁺ * (w ⊓ -(prim_EP w v e))⁺ ⊔ (prim_P w v e)⇧T⁺" using star.circ_mult_increasing (*‹?x ≤ ?x⁺›*) by (simp add: le_iff_sup (*‹(?x ≤ ?y) = (?x ⊔ ?y = ?y)›*)) also (*calculation: ‹prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ = prim_P w v e⇧T⁺ * (w ⊓ - prim_EP w v e)⁺ ⊔ prim_P w v e⇧T⁺›*) have "... ≤ -1" using "17" (*‹irreflexive (prim_P w v e⇧T⁺ * (w ⊓ - prim_EP w v e)⁺)›*) "18" (*‹pd_kleene_allegory_class.acyclic (prim_P w v e⇧T)›*) by simp finally (*calculation: ‹irreflexive (prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) show "?thesis" (*goal: ‹irreflexive (prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) . qed have 19: "e * (w ⊓ -(prim_EP w v e))⇧⋆ * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆ ≤ -1" proof (-) (*goal: ‹irreflexive (e * (w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) have "e * (w ⊓ -(prim_EP w v e))⇧⋆ * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆ = e * ((w ⊓ -(prim_EP w v e))⁺ ⊔ (prim_P w v e)⇧T⇧⋆) * (w ⊓ -(prim_EP w v e))⇧⋆" using "6" (*‹(w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ = (w ⊓ - prim_EP w v e)⁺ ⊔ prim_P w v e⇧T⇧⋆›*) by (simp add: mult_assoc (*‹(?a::'a::type) * (?b::'a::type) * (?c::'a::type) = ?a * (?b * ?c)›*)) also (*calculation: ‹e * (w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ = e * ((w ⊓ - prim_EP w v e)⁺ ⊔ prim_P w v e⇧T⇧⋆) * (w ⊓ - prim_EP w v e)⇧⋆›*) have "... = e * (w ⊓ -(prim_EP w v e))⁺ * (w ⊓ -(prim_EP w v e))⇧⋆ ⊔ e * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆" by (simp add: mult_left_dist_sup (*‹?x * (?y ⊔ ?z) = ?x * ?y ⊔ ?x * ?z›*) mult_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*)) also (*calculation: ‹e * (w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ = e * (w ⊓ - prim_EP w v e)⁺ * (w ⊓ - prim_EP w v e)⇧⋆ ⊔ e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆›*) have "... = e * (w ⊓ -(prim_EP w v e))⁺ ⊔ e * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆" by (simp add: mult_assoc (*‹(?a::'a) * (?b::'a) * (?c::'a) = ?a * (?b * ?c)›*) star.circ_transitive_equal (*‹idempotent ((?x::'a)⇧⋆)›*)) also (*calculation: ‹e * (w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ = e * (w ⊓ - prim_EP w v e)⁺ ⊔ e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆›*) have "... ≤ e * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⁺ ⊔ e * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆" by (metis mult_right_sub_dist_sup_right (*‹?y * ?z ≤ (?x ⊔ ?y) * ?z›*) semiring.add_right_mono (*‹?a ≤ ?b ⟹ ?a ⊔ ?c ≤ ?b ⊔ ?c›*) star.circ_back_loop_fixpoint (*‹?z * ?y⇧⋆ * ?y ⊔ ?z = ?z * ?y⇧⋆›*)) also (*calculation: ‹e * (w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ ≤ e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⁺ ⊔ e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆›*) have "... ≤ e * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆" using mult_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*) star.left_plus_below_circ (*‹(?x::'a)⁺ ≤ ?x⇧⋆›*) by auto also (*calculation: ‹e * (w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ ≤ e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆›*) have "... ≤ v * -v⇧T" using "11" (*‹(e::'a) * prim_P (w::'a) (v::'a) e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ ≤ v * - v⇧T›*) by simp also (*calculation: ‹(e::'a) * ((w::'a) ⊓ - prim_EP w (v::'a) e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ ≤ v * - v⇧T›*) have "... ≤ -1" by (simp add: pp_increasing (*‹?x ≤ - - ?x›*) schroeder_3_p (*‹(?x * ?y ≤ - ?z) = (?x⇧T * ?z ≤ - ?y)›*)) finally (*calculation: ‹irreflexive ((e::'a::type) * ((w::'a::type) ⊓ - prim_EP w (v::'a::type) e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) show "?thesis" (*goal: ‹irreflexive (e * (w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) . qed have 20: "(prim_W w v e) * (w ⊓ -(prim_EP w v e))⇧⋆ * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆ ≤ -1" using "15" (*‹irreflexive ((w ⊓ - prim_EP w v e)⁺ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) "16" (*‹irreflexive (prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) "19" (*‹irreflexive (e * (w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) by (simp add: comp_right_dist_sup (*‹((?x::'a::type) ⊔ (?y::'a::type)) * (?z::'a::type) = ?x * ?z ⊔ ?y * ?z›*)) have 21: "(w ⊓ -(prim_EP w v e))⁺ * e * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆ ≤ -1" proof (-) (*goal: ‹irreflexive ((w ⊓ - prim_EP w v e)⁺ * e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) have "(w ⊓ -(prim_EP w v e)) * v * -v⇧T ≤ w * v * -v⇧T" by (simp add: comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) also (*calculation: ‹(w ⊓ - prim_EP w v e) * v * - v⇧T ≤ w * v * - v⇧T›*) have "... ≤ v * -v⇧T" by (simp add: assms( (*‹w * v ≤ v›*) 3) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) finally (*calculation: ‹(w ⊓ - prim_EP w v e) * v * - v⇧T ≤ v * - v⇧T›*) have 22: "(w ⊓ -(prim_EP w v e)) * v * -v⇧T ≤ v * -v⇧T" . have "(w ⊓ -(prim_EP w v e))⁺ * e * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆ ≤ (w ⊓ -(prim_EP w v e))⁺ * v * -v⇧T" using "11" (*‹e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ ≤ v * - v⇧T›*) by (simp add: mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹(w ⊓ - prim_EP w v e)⁺ * e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ ≤ (w ⊓ - prim_EP w v e)⁺ * v * - v⇧T›*) have "... ≤ (w ⊓ -(prim_EP w v e))⇧⋆ * v * -v⇧T" using mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) star.left_plus_below_circ (*‹?x⁺ ≤ ?x⇧⋆›*) by blast also (*calculation: ‹(w ⊓ - prim_EP w v e)⁺ * e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ ≤ (w ⊓ - prim_EP w v e)⇧⋆ * v * - v⇧T›*) have "... ≤ v * -v⇧T" using "22" (*‹(w ⊓ - prim_EP w v e) * v * - v⇧T ≤ v * - v⇧T›*) by (simp add: star_left_induct_mult (*‹?x * ?y ≤ ?y ⟹ ?x⇧⋆ * ?y ≤ ?y›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹(w ⊓ - prim_EP w v e)⁺ * e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ ≤ v * - v⇧T›*) have "... ≤ -1" by (simp add: pp_increasing (*‹?x ≤ - - ?x›*) schroeder_3_p (*‹(?x * ?y ≤ - ?z) = (?x⇧T * ?z ≤ - ?y)›*)) finally (*calculation: ‹irreflexive ((w ⊓ - prim_EP w v e)⁺ * e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) show "?thesis" (*goal: ‹irreflexive ((w ⊓ - prim_EP w v e)⁺ * e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) . qed have 23: "(prim_P w v e)⇧T * (w ⊓ -(prim_EP w v e))⇧⋆ * e * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆ ≤ -1" proof (-) (*goal: ‹irreflexive (prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⇧⋆ * e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) have "(prim_P w v e)⇧T * (w ⊓ -(prim_EP w v e))⇧⋆ * e = (prim_P w v e)⇧T * e ⊔ (prim_P w v e)⇧T * (w ⊓ -(prim_EP w v e))⁺ * e" using comp_left_dist_sup (*‹?x * ?y ⊔ ?x * ?z = ?x * (?y ⊔ ?z)›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) star.circ_loop_fixpoint (*‹?y * (?y⇧⋆ * ?z) ⊔ ?z = ?y⇧⋆ * ?z›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*) by auto also (*calculation: ‹prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⇧⋆ * e = prim_P w v e⇧T * e ⊔ prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⁺ * e›*) have "... = bot" using "1" (*‹prim_P w v e⇧T * e = bot›*) "9" (*‹prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⁺ * e = bot›*) by simp finally (*calculation: ‹prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⇧⋆ * e = bot›*) show "?thesis" (*goal: ‹irreflexive (prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⇧⋆ * e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) by simp qed have 24: "e * (w ⊓ -(prim_EP w v e))⇧⋆ * e * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆ ≤ -1" proof (-) (*goal: ‹irreflexive (e * (w ⊓ - prim_EP w v e)⇧⋆ * e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) have "e * (w ⊓ -(prim_EP w v e))⇧⋆ * e = e * e ⊔ e * (w ⊓ -(prim_EP w v e))⁺ * e" using comp_left_dist_sup (*‹(?x::'a::type) * (?y::'a::type) ⊔ ?x * (?z::'a::type) = ?x * (?y ⊔ ?z)›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) star.circ_loop_fixpoint (*‹?y * (?y⇧⋆ * ?z) ⊔ ?z = ?y⇧⋆ * ?z›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*) by auto also (*calculation: ‹(e::'a) * ((w::'a) ⊓ - prim_EP w (v::'a) e)⇧⋆ * e = e * e ⊔ e * (w ⊓ - prim_EP w v e)⁺ * e›*) have "... = bot" using "2" (*‹(e::'a) * e = bot›*) "10" (*‹e * (w ⊓ - prim_EP w v e)⁺ * e = bot›*) by simp finally (*calculation: ‹e * (w ⊓ - prim_EP w v e)⇧⋆ * e = bot›*) show "?thesis" (*goal: ‹irreflexive ((e::'a::type) * ((w::'a::type) ⊓ - prim_EP w (v::'a::type) e)⇧⋆ * e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) by simp qed have 25: "(prim_W w v e) * (w ⊓ -(prim_EP w v e))⇧⋆ * e * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆ ≤ -1" using "21" (*‹irreflexive (((w::'a::type) ⊓ - prim_EP w (v::'a::type) (e::'a::type))⁺ * e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) "23" (*‹irreflexive (prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⇧⋆ * e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) "24" (*‹irreflexive (e * (w ⊓ - prim_EP w v e)⇧⋆ * e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) by (simp add: comp_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*)) have "(prim_W w v e)⇧⋆ = ((prim_P w v e)⇧T ⊔ e)⇧⋆ * ((w ⊓ -(prim_EP w v e)) * ((prim_P w v e)⇧T ⊔ e)⇧⋆)⇧⋆" by (metis star_sup_1 (*‹(?x ⊔ ?y)⇧⋆ = ?x⇧⋆ * (?y * ?x⇧⋆)⇧⋆›*) sup.left_commute (*‹?b ⊔ (?a ⊔ ?c) = ?a ⊔ (?b ⊔ ?c)›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*)) also (*calculation: ‹prim_W (w::'a) (v::'a) (e::'a)⇧⋆ = (prim_P w v e⇧T ⊔ e)⇧⋆ * ((w ⊓ - prim_EP w v e) * (prim_P w v e⇧T ⊔ e)⇧⋆)⇧⋆›*) have "... = ((prim_P w v e)⇧T⇧⋆ ⊔ e * (prim_P w v e)⇧T⇧⋆) * ((w ⊓ -(prim_EP w v e)) * ((prim_P w v e)⇧T⇧⋆ ⊔ e * (prim_P w v e)⇧T⇧⋆))⇧⋆" using "1" (*‹prim_P w v e⇧T * e = bot›*) "2" (*‹e * e = bot›*) star_separate (*‹⟦?x * ?y = bot; ?y * ?y = bot⟧ ⟹ (?x ⊔ ?y)⇧⋆ = ?x⇧⋆ ⊔ ?y * ?x⇧⋆›*) by auto also (*calculation: ‹prim_W (w::'a) (v::'a) (e::'a)⇧⋆ = (prim_P w v e⇧T⇧⋆ ⊔ e * prim_P w v e⇧T⇧⋆) * ((w ⊓ - prim_EP w v e) * (prim_P w v e⇧T⇧⋆ ⊔ e * prim_P w v e⇧T⇧⋆))⇧⋆›*) have "... = ((prim_P w v e)⇧T⇧⋆ ⊔ e * (prim_P w v e)⇧T⇧⋆) * ((w ⊓ -(prim_EP w v e)) * (1 ⊔ e * (prim_P w v e)⇧T⇧⋆))⇧⋆" using "4" (*‹(w ⊓ - prim_EP w v e) * prim_P w v e⇧T⇧⋆ = w ⊓ - prim_EP w v e›*) mult_left_dist_sup (*‹?x * (?y ⊔ ?z) = ?x * ?y ⊔ ?x * ?z›*) by auto also (*calculation: ‹prim_W w v e⇧⋆ = (prim_P w v e⇧T⇧⋆ ⊔ e * prim_P w v e⇧T⇧⋆) * ((w ⊓ - prim_EP w v e) * Rf e (prim_P w v e⇧T⇧⋆))⇧⋆›*) have "... = (w ⊓ -(prim_EP w v e))⇧⋆ * ((prim_P w v e)⇧T⇧⋆ ⊔ e * (prim_P w v e)⇧T⇧⋆) * (w ⊓ -(prim_EP w v e))⇧⋆" using "3" (*‹(w ⊓ - prim_EP w v e) * prim_P w v e⇧T = bot›*) "9" (*‹prim_P w v e⇧T * (w ⊓ - prim_EP w v e)⁺ * e = bot›*) "10" (*‹e * (w ⊓ - prim_EP w v e)⁺ * e = bot›*) star_separate_2 (*‹⟦?x * ?z⁺ * ?y = bot; ?y * ?z⁺ * ?y = bot; ?z * ?x = bot⟧ ⟹ (?x⇧⋆ ⊔ ?y * ?x⇧⋆) * (?z * Rf ?y (?x⇧⋆))⇧⋆ = ?z⇧⋆ * (?x⇧⋆ ⊔ ?y * ?x⇧⋆) * ?z⇧⋆›*) by blast also (*calculation: ‹prim_W w v e⇧⋆ = (w ⊓ - prim_EP w v e)⇧⋆ * (prim_P w v e⇧T⇧⋆ ⊔ e * prim_P w v e⇧T⇧⋆) * (w ⊓ - prim_EP w v e)⇧⋆›*) have "... = (w ⊓ -(prim_EP w v e))⇧⋆ * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆ ⊔ (w ⊓ -(prim_EP w v e))⇧⋆ * e * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆" by (simp add: semiring.distrib_left (*‹?a * (?b ⊔ ?c) = ?a * ?b ⊔ ?a * ?c›*) semiring.distrib_right (*‹(?a ⊔ ?b) * ?c = ?a * ?c ⊔ ?b * ?c›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) finally (*calculation: ‹prim_W (w::'a) (v::'a) (e::'a)⇧⋆ = (w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ ⊔ (w ⊓ - prim_EP w v e)⇧⋆ * e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆›*) have "(prim_W w v e)⁺ = (prim_W w v e) * ((w ⊓ -(prim_EP w v e))⇧⋆ * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆ ⊔ (w ⊓ -(prim_EP w v e))⇧⋆ * e * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆)" by simp also (*calculation: ‹prim_W w v e⁺ = prim_W w v e * ((w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ ⊔ (w ⊓ - prim_EP w v e)⇧⋆ * e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) have "... = (prim_W w v e) * (w ⊓ -(prim_EP w v e))⇧⋆ * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆ ⊔ (prim_W w v e) * (w ⊓ -(prim_EP w v e))⇧⋆ * e * (prim_P w v e)⇧T⇧⋆ * (w ⊓ -(prim_EP w v e))⇧⋆" by (simp add: comp_left_dist_sup (*‹(?x::'a::type) * (?y::'a::type) ⊔ ?x * (?z::'a::type) = ?x * (?y ⊔ ?z)›*) comp_associative (*‹(?x::'a::type) * (?y::'a::type) * (?z::'a::type) = ?x * (?y * ?z)›*)) also (*calculation: ‹prim_W w v e⁺ = prim_W w v e * (w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆ ⊔ prim_W w v e * (w ⊓ - prim_EP w v e)⇧⋆ * e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆›*) have "... ≤ -1" using "20" (*‹irreflexive (prim_W w v e * (w ⊓ - prim_EP w v e)⇧⋆ * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) "25" (*‹irreflexive (prim_W (w::'a) (v::'a) (e::'a) * (w ⊓ - prim_EP w v e)⇧⋆ * e * prim_P w v e⇧T⇧⋆ * (w ⊓ - prim_EP w v e)⇧⋆)›*) by simp finally (*calculation: ‹pd_kleene_allegory_class.acyclic (prim_W w v e)›*) show "?thesis" (*goal: ‹pd_kleene_allegory_class.acyclic (prim_W w v e)›*) . qed text ‹ The following lemma shows that an edge across the cut between visited nodes and unvisited nodes does not leave the component of visited nodes. › lemma mst_subgraph_inv: assumes "e ≤ v * -v⇧T ⊓ g" and "t ≤ g" and "v⇧T = r⇧T * t⇧⋆" shows "e ≤ (r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g" proof (-) (*goal: ‹e ≤ (r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g›*) have "e ≤ v * -v⇧T ⊓ g" by (rule assms( (*‹e ≤ v * - v⇧T ⊓ g›*) 1)) also (*calculation: ‹e ≤ v * - v⇧T ⊓ g›*) have "... ≤ v * (-v⇧T ⊓ v⇧T * g) ⊓ g" by (simp add: dedekind_1 (*‹?x * ?y ⊓ ?z ≤ ?x * (?y ⊓ ?x⇧T * ?z)›*)) also (*calculation: ‹(e::'a) ≤ (v::'a) * (- v⇧T ⊓ v⇧T * (g::'a)) ⊓ g›*) have "... ≤ v * v⇧T * g ⊓ g" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) le_infI2 (*‹?b ≤ ?x ⟹ ?a ⊓ ?b ≤ ?x›*)) also (*calculation: ‹e ≤ v * v⇧T * g ⊓ g›*) have "... = v * (r⇧T * t⇧⋆) * g ⊓ g" by (simp add: assms( (*‹(v::'a::type)⇧T = (r::'a::type)⇧T * (t::'a::type)⇧⋆›*) 3)) also (*calculation: ‹e ≤ v * (r⇧T * t⇧⋆) * g ⊓ g›*) have "... = (r⇧T * t⇧⋆)⇧T * (r⇧T * t⇧⋆) * g ⊓ g" by (metis assms( (*‹v⇧T = r⇧T * t⇧⋆›*) 3) conv_involutive (*‹?x⇧T⇧T = ?x›*)) also (*calculation: ‹(e::'a::type) ≤ ((r::'a::type)⇧T * (t::'a::type)⇧⋆)⇧T * (r⇧T * t⇧⋆) * (g::'a::type) ⊓ g›*) have "... ≤ (r⇧T * t⇧⋆)⇧T * (r⇧T * g⇧⋆) * g ⊓ g" using assms(2) (*‹t ≤ g›*) comp_inf.mult_left_isotone (*‹?x ≤ ?y ⟹ ?x ⊓ ?z ≤ ?y ⊓ ?z›*) comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) by auto also (*calculation: ‹e ≤ (r⇧T * t⇧⋆)⇧T * (r⇧T * g⇧⋆) * g ⊓ g›*) have "... ≤ (r⇧T * t⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g" using inf.sup_right_isotone (*‹?y ≤ ?x ⟹ ?z ⊓ ?y ≤ ?z ⊓ ?x›*) inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star.left_plus_below_circ (*‹?x⁺ ≤ ?x⇧⋆›*) star_plus (*‹?y⇧⋆ * ?y = ?y⁺›*) by presburger also (*calculation: ‹e ≤ (r⇧T * t⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g›*) have "... ≤ (r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g" using assms(2) (*‹(t::'a) ≤ (g::'a)›*) comp_inf.mult_left_isotone (*‹?x ≤ ?y ⟹ ?x ⊓ ?z ≤ ?y ⊓ ?z›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) by auto finally (*calculation: ‹e ≤ (r⇧T * g⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g›*) show "?thesis" (*goal: ‹(e::'a) ≤ ((r::'a)⇧T * (g::'a)⇧⋆)⇧T * (r⇧T * g⇧⋆) ⊓ g›*) . qed text ‹ The following lemmas show that the tree after exchanging contains the currently constructed and tree and its extension by the chosen edge. › lemma mst_extends_old_tree: assumes "t ≤ w" and "t ≤ v * v⇧T" and "vector v" shows "t ≤ prim_W w v e" proof (-) (*goal: ‹(t::'a) ≤ prim_W (w::'a) (v::'a) (e::'a)›*) have "t ⊓ prim_EP w v e ≤ t ⊓ -v⇧T" by (simp add: inf.coboundedI2 (*‹?b ≤ ?c ⟹ ?a ⊓ ?b ≤ ?c›*) inf.sup_monoid.add_assoc (*‹?a ⊓ ?b ⊓ ?c = ?a ⊓ (?b ⊓ ?c)›*)) also (*calculation: ‹t ⊓ prim_EP w v e ≤ t ⊓ - v⇧T›*) have "... ≤ v * v⇧T ⊓ -v⇧T" by (simp add: assms( (*‹(t::'a::type) ≤ (v::'a::type) * v⇧T›*) 2) inf.coboundedI1 (*‹(?a::'a::type) ≤ (?c::'a::type) ⟹ ?a ⊓ (?b::'a::type) ≤ ?c›*)) also (*calculation: ‹t ⊓ prim_EP w v e ≤ v * v⇧T ⊓ - v⇧T›*) have "... ≤ bot" by (simp add: assms( (*‹vector v›*) 3) covector_vector_comp (*‹vector ?v ⟹ - ?v⇧T * ?v = bot›*) eq_refl (*‹?x = ?y ⟹ ?x ≤ ?y›*) schroeder_2 (*‹(?x * ?y ⊓ ?z = bot) = (?z * ?y⇧T ⊓ ?x = bot)›*)) finally (*calculation: ‹t ⊓ prim_EP w v e ≤ bot›*) have "t ≤ -(prim_EP w v e)" using le_bot (*‹?a ≤ bot ⟹ ?a = bot›*) pseudo_complement (*‹(?x ⊓ ?y = bot) = (?x ≤ - ?y)›*) by blast hence "t ≤ w ⊓ -(prim_EP w v e)" using assms(1) (*‹(t::'a::type) ≤ (w::'a::type)›*) by simp thus "?thesis" (*goal: ‹t ≤ prim_W w v e›*) using le_supI1 (*‹?x ≤ ?a ⟹ ?x ≤ ?a ⊔ ?b›*) by blast qed lemma mst_extends_new_tree: "t ≤ w ⟹ t ≤ v * v⇧T ⟹ vector v ⟹ t ⊔ e ≤ prim_W w v e" using mst_extends_old_tree (*‹⟦(?t::'a) ≤ (?w::'a); ?t ≤ (?v::'a) * ?v⇧T; vector ?v⟧ ⟹ ?t ≤ prim_W ?w ?v (?e::'a)›*) by auto text ‹Lemmas ‹forests_bot_1›, ‹forests_bot_2›, ‹forests_bot_3› and ‹fc_comp_eq_fc› were contributed by Nicolas Robinson-O'Brien.› lemma forests_bot_1: assumes "equivalence e" and "forest f" shows "(-e ⊓ f) * (e ⊓ f)⇧T = bot" proof (-) (*goal: ‹(- e ⊓ f) * (e ⊓ f)⇧T = bot›*) have "f * f⇧T ≤ e" using assms (*‹equivalence e› ‹forest f›*) dual_order.trans (*‹⟦?b ≤ ?a; ?c ≤ ?b⟧ ⟹ ?c ≤ ?a›*) by blast hence "f * (e ⊓ f)⇧T ≤ e" by (metis conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) inf.boundedE (*‹⟦?a ≤ ?b ⊓ ?c; ⟦?a ≤ ?b; ?a ≤ ?c⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) inf.cobounded2 (*‹?a ⊓ ?b ≤ ?b›*) inf.orderE (*‹⟦?a ≤ ?b; ?a = ?a ⊓ ?b ⟹ ?thesis⟧ ⟹ ?thesis›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) hence "-e ⊓ f * (e ⊓ f)⇧T = bot" by (simp add: p_antitone (*‹?x ≤ ?y ⟹ - ?y ≤ - ?x›*) pseudo_complement (*‹(?x ⊓ ?y = bot) = (?x ≤ - ?y)›*)) thus "?thesis" (*goal: ‹(- e ⊓ f) * (e ⊓ f)⇧T = bot›*) by (metis assms( (*‹equivalence e›*) 1) comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) equivalence_comp_right_complement (*‹equivalence ?x ⟹ - ?x * ?x = - ?x›*) inf.boundedI (*‹⟦?a ≤ ?b; ?a ≤ ?c⟧ ⟹ ?a ≤ ?b ⊓ ?c›*) inf.cobounded1 (*‹?a ⊓ ?b ≤ ?a›*) inf.cobounded2 (*‹?a ⊓ ?b ≤ ?b›*) le_bot (*‹?a ≤ bot ⟹ ?a = bot›*)) qed lemma forests_bot_2: assumes "equivalence e" and "forest f" shows "(-e ⊓ f⇧T) * x ⊓ (e ⊓ f⇧T) * y = bot" proof (-) (*goal: ‹(- e ⊓ f⇧T) * x ⊓ (e ⊓ f⇧T) * y = bot›*) have "(-e ⊓ f) * (e ⊓ f⇧T) = bot" using assms (*‹equivalence e› ‹forest f›*) forests_bot_1 (*‹⟦equivalence ?e; forest ?f⟧ ⟹ (- ?e ⊓ ?f) * (?e ⊓ ?f)⇧T = bot›*) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) by simp thus "?thesis" (*goal: ‹(- e ⊓ f⇧T) * x ⊓ (e ⊓ f⇧T) * y = bot›*) by (smt assms( (*‹equivalence e›*) 1) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_inf.semiring.mult_not_zero (*‹?a ⊓ ?b ≠ bot ⟹ ?a ≠ bot ∧ ?b ≠ bot›*) conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) dedekind_1 (*‹?x * ?y ⊓ ?z ≤ ?x * (?y ⊓ ?x⇧T * ?z)›*) inf.cobounded2 (*‹?a ⊓ ?b ≤ ?b›*) inf.sup_monoid.add_commute (*‹?a ⊓ ?b = ?b ⊓ ?a›*) le_bot (*‹?a ≤ bot ⟹ ?a = bot›*) mult_right_zero (*‹?x * bot = bot›*) p_antitone_iff (*‹(?x ≤ - ?y) = (?y ≤ - ?x)›*) pseudo_complement (*‹(?x ⊓ ?y = bot) = (?x ≤ - ?y)›*) semiring.mult_not_zero (*‹?a * ?b ≠ bot ⟹ ?a ≠ bot ∧ ?b ≠ bot›*) symmetric_top_closed (*‹symmetric top›*) top.extremum (*‹?a ≤ top›*)) qed lemma forests_bot_3: assumes "equivalence e" and "forest f" shows "x * (-e ⊓ f) ⊓ y * (e ⊓ f) = bot" proof (-) (*goal: ‹x * (- e ⊓ f) ⊓ y * (e ⊓ f) = bot›*) have "(e ⊓ f) * (-e ⊓ f⇧T) = bot" using assms (*‹equivalence e› ‹forest f›*) forests_bot_1 (*‹⟦equivalence ?e; forest ?f⟧ ⟹ (- ?e ⊓ ?f) * (?e ⊓ ?f)⇧T = bot›*) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) by (smt conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_order (*‹(?x ≤ ?y) = (?x⇧T ≤ ?y⇧T)›*) coreflexive_bot_closed (*‹coreflexive bot›*) coreflexive_symmetric (*‹coreflexive ?x ⟹ symmetric ?x›*)) hence "y * (e ⊓ f) * (-e ⊓ f⇧T) = bot" by (simp add: comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*)) hence 1: "x ⊓ y * (e ⊓ f) * (-e ⊓ f⇧T) = bot" using comp_inf.semiring.mult_not_zero (*‹(?a::'a) ⊓ (?b::'a) ≠ bot ⟹ ?a ≠ bot ∧ ?b ≠ bot›*) by blast hence "(x ⊓ y * (e ⊓ f) * (-e ⊓ f⇧T)) * (-e ⊓ f) = bot" using semiring.mult_not_zero (*‹(?a::'a::type) * (?b::'a::type) ≠ bot ⟹ ?a ≠ bot ∧ ?b ≠ bot›*) by blast hence "x * (-e ⊓ f⇧T)⇧T ⊓ y * (e ⊓ f) = bot" using "1" (*‹(x::'a) ⊓ (y::'a) * ((e::'a) ⊓ (f::'a)) * (- e ⊓ f⇧T) = bot›*) dedekind_2 (*‹?y * ?x ⊓ ?z ≤ (?y ⊓ ?z * ?x⇧T) * ?x›*) inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) schroeder_2 (*‹(?x * ?y ⊓ ?z = bot) = (?z * ?y⇧T ⊓ ?x = bot)›*) by auto thus "?thesis" (*goal: ‹x * (- e ⊓ f) ⊓ y * (e ⊓ f) = bot›*) by (simp add: assms( (*‹equivalence e›*) 1) conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*)) qed lemma acyclic_plus: "acyclic x ⟹ acyclic (x⁺)" by (simp add: star.circ_transitive_equal (*‹idempotent (?x⇧⋆)›*) star.left_plus_circ (*‹?x⁺⇧⋆ = ?x⇧⋆›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) end text ‹ We finally add the Kleene star to Stone relation algebras. Kleene star and the relational operations are reasonably independent. The only additional axiom we need in the generalisation to Stone-Kleene relation algebras is that star distributes over double complement. › class stone_kleene_relation_algebra = stone_relation_algebra + pd_kleene_allegory + assumes pp_dist_star: "--(x⇧⋆) = (--x)⇧⋆" begin lemma reachable_without_loops: "x⇧⋆ = (x ⊓ -1)⇧⋆" proof (rule order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹x⇧⋆ ≤ (x ⊓ - 1)⇧⋆› 2. ‹(x ⊓ - 1)⇧⋆ ≤ x⇧⋆›*) have "x * (x ⊓ -1)⇧⋆ = (x ⊓ 1) * (x ⊓ -1)⇧⋆ ⊔ (x ⊓ -1) * (x ⊓ -1)⇧⋆" by (metis maddux_3_11_pp (*‹?x ⊓ - ?y ⊔ ?x ⊓ - - ?y = ?x›*) mult_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*) regular_one_closed (*‹regular 1›*)) also (*calculation: ‹x * (x ⊓ - 1)⇧⋆ = (x ⊓ 1) * (x ⊓ - 1)⇧⋆ ⊔ (x ⊓ - 1)⁺›*) have "... ≤ (x ⊓ -1)⇧⋆" by (metis inf.cobounded2 (*‹?a ⊓ ?b ≤ ?b›*) le_supI (*‹⟦?a ≤ ?x; ?b ≤ ?x⟧ ⟹ ?a ⊔ ?b ≤ ?x›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) star.circ_circ_mult (*‹1⇧⋆ * ?x⇧⋆ = ?x⇧⋆⇧⋆›*) star.left_plus_below_circ (*‹?x⁺ ≤ ?x⇧⋆›*) star_involutive (*‹?x⇧⋆ = ?x⇧⋆⇧⋆›*) star_one (*‹1⇧⋆ = 1›*)) finally (*calculation: ‹x * (x ⊓ - 1)⇧⋆ ≤ (x ⊓ - 1)⇧⋆›*) show "x⇧⋆ ≤ (x ⊓ -1)⇧⋆" by (metis inf.cobounded2 (*‹?a ⊓ ?b ≤ ?b›*) maddux_3_11_pp (*‹?x ⊓ - ?y ⊔ ?x ⊓ - - ?y = ?x›*) regular_one_closed (*‹regular 1›*) star.circ_circ_mult (*‹1⇧⋆ * ?x⇧⋆ = ?x⇧⋆⇧⋆›*) star.circ_sup_2 (*‹(?x ⊔ ?y)⇧⋆ ≤ (?x⇧⋆ * ?y⇧⋆)⇧⋆›*) star_involutive (*‹?x⇧⋆ = ?x⇧⋆⇧⋆›*) star_sub_one (*‹coreflexive ?x ⟹ ?x⇧⋆ = 1›*)) next (*goal: ‹(x ⊓ - 1)⇧⋆ ≤ x⇧⋆›*) show "(x ⊓ -1)⇧⋆ ≤ x⇧⋆" by (simp add: star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) qed lemma plus_reachable_without_loops: "x⁺ = (x ⊓ -1)⁺ ⊔ (x ⊓ 1)" by (metis comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) maddux_3_11_pp (*‹?x ⊓ - ?y ⊔ ?x ⊓ - - ?y = ?x›*) regular_one_closed (*‹regular 1›*) star.circ_back_loop_fixpoint (*‹?z * ?y⇧⋆ * ?y ⊔ ?z = ?z * ?y⇧⋆›*) star.circ_loop_fixpoint (*‹?y * (?y⇧⋆ * ?z) ⊔ ?z = ?y⇧⋆ * ?z›*) sup_assoc (*‹?x ⊔ ?y ⊔ ?z = ?x ⊔ (?y ⊔ ?z)›*) reachable_without_loops (*‹?x⇧⋆ = (?x ⊓ - 1)⇧⋆›*)) lemma star_plus_without_loops: "x⇧⋆ ⊓ -1 = x⁺ ⊓ -1" by (metis maddux_3_13 (*‹(?x ⊔ ?y) ⊓ - ?x = ?y ⊓ - ?x›*) star_left_unfold_equal (*‹1 ⊔ ?x⁺ = ?x⇧⋆›*)) lemma regular_closed_star: "regular x ⟹ regular (x⇧⋆)" by (simp add: pp_dist_star (*‹- - ?x⇧⋆ = components ?x›*)) lemma components_idempotent: "components (components x) = components x" using pp_dist_star (*‹- - ?x⇧⋆ = components ?x›*) star_involutive (*‹?x⇧⋆ = ?x⇧⋆⇧⋆›*) by auto lemma fc_comp_eq_fc: "-forest_components (--f) = -forest_components f" by (metis conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) p_comp_pp (*‹- (?x * - - ?y) = - (?x * ?y)›*) p_pp_comp (*‹- (- - ?x * ?y) = - (?x * ?y)›*) pp_dist_star (*‹- - ?x⇧⋆ = components ?x›*)) text ‹ The following lemma shows that the nodes reachable in the tree after exchange contain the nodes reachable in the tree before exchange. › lemma mst_reachable_inv: assumes "regular (prim_EP w v e)" and "vector r" and "e ≤ v * -v⇧T" and "vector v" and "v⇧T = r⇧T * t⇧⋆" and "t ≤ w" and "t ≤ v * v⇧T" and "w * v ≤ v" shows "r⇧T * w⇧⋆ ≤ r⇧T * (prim_W w v e)⇧⋆" proof (-) (*goal: ‹(r::'a)⇧T * (w::'a)⇧⋆ ≤ r⇧T * prim_W w (v::'a) (e::'a)⇧⋆›*) have 1: "r⇧T ≤ r⇧T * (prim_W w v e)⇧⋆" using sup.bounded_iff (*‹(?b ⊔ ?c ≤ ?a) = (?b ≤ ?a ∧ ?c ≤ ?a)›*) star.circ_back_loop_prefixpoint (*‹?z * ?y⇧⋆ * ?y ⊔ ?z ≤ ?z * ?y⇧⋆›*) by blast have "top * e * (w⇧T ⊓ -v⇧T)⇧⋆ * w⇧T ⊓ -v⇧T = top * e * (w⇧T ⊓ -v⇧T)⇧⋆ * (w⇧T ⊓ -v⇧T)" by (simp add: assms( (*‹vector v›*) 4) covector_comp_inf (*‹covector ?z ⟹ ?x * (?y ⊓ ?z) = ?x * ?y ⊓ ?z›*) vector_conv_compl (*‹vector ?v ⟹ covector (- ?v⇧T)›*)) also (*calculation: ‹top * e * (w⇧T ⊓ - v⇧T)⇧⋆ * w⇧T ⊓ - v⇧T = top * e * (w⇧T ⊓ - v⇧T)⇧⋆ * (w⇧T ⊓ - v⇧T)›*) have "... ≤ top * e * (w⇧T ⊓ -v⇧T)⇧⋆" by (simp add: comp_isotone (*‹⟦(?x::'a::type) ≤ (?y::'a::type); (?w::'a::type) ≤ (?z::'a::type)⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) mult_assoc (*‹(?a::'a::type) * (?b::'a::type) * (?c::'a::type) = ?a * (?b * ?c)›*) star.circ_plus_same (*‹(?x::'a::type)⇧⋆ * ?x = ?x⁺›*) star.left_plus_below_circ (*‹(?x::'a::type)⁺ ≤ ?x⇧⋆›*)) finally (*calculation: ‹top * e * (w⇧T ⊓ - v⇧T)⇧⋆ * w⇧T ⊓ - v⇧T ≤ top * e * (w⇧T ⊓ - v⇧T)⇧⋆›*) have 2: "top * e * (w⇧T ⊓ -v⇧T)⇧⋆ * w⇧T ≤ top * e * (w⇧T ⊓ -v⇧T)⇧⋆ ⊔ --v⇧T" by (simp add: shunting_var_p (*‹(?x ⊓ - ?y ≤ ?z) = (?x ≤ ?z ⊔ - - ?y)›*)) have 3: "--v⇧T * w⇧T ≤ top * e * (w⇧T ⊓ -v⇧T)⇧⋆ ⊔ --v⇧T" by (metis assms( (*‹(w::'a) * (v::'a) ≤ v›*) 8) conv_dist_comp (*‹((?x::'a) * (?y::'a))⇧T = ?y⇧T * ?x⇧T›*) conv_order (*‹((?x::'a) ≤ (?y::'a)) = (?x⇧T ≤ ?y⇧T)›*) mult_assoc (*‹(?a::'a) * (?b::'a) * (?c::'a) = ?a * (?b * ?c)›*) order.trans (*‹⟦(?a::'a) ≤ (?b::'a); ?b ≤ (?c::'a)⟧ ⟹ ?a ≤ ?c›*) pp_comp_semi_commute (*‹- - (?x::'a) * (?y::'a) ≤ - - (?x * ?y)›*) pp_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ - - ?x ≤ - - ?y›*) sup.coboundedI1 (*‹(?c::'a) ≤ (?a::'a) ⟹ ?c ≤ ?a ⊔ (?b::'a)›*) sup_commute (*‹(?x::'a) ⊔ (?y::'a) = ?y ⊔ ?x›*)) have 4: "top * e ≤ top * e * (w⇧T ⊓ -v⇧T)⇧⋆ ⊔ --v⇧T" using sup_right_divisibility (*‹(?x ≤ ?y) = (∃z. z ⊔ ?x = ?y)›*) star.circ_back_loop_fixpoint (*‹?z * ?y⇧⋆ * ?y ⊔ ?z = ?z * ?y⇧⋆›*) le_supI1 (*‹(?x::'a) ≤ (?a::'a) ⟹ ?x ≤ ?a ⊔ (?b::'a)›*) by blast have "(top * e * (w⇧T ⊓ -v⇧T)⇧⋆ ⊔ --v⇧T) * w⇧T = top * e * (w⇧T ⊓ -v⇧T)⇧⋆ * w⇧T ⊔ --v⇧T * w⇧T" by (simp add: comp_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*)) also (*calculation: ‹(top * e * (w⇧T ⊓ - v⇧T)⇧⋆ ⊔ - - v⇧T) * w⇧T = top * e * (w⇧T ⊓ - v⇧T)⇧⋆ * w⇧T ⊔ - - v⇧T * w⇧T›*) have "... ≤ top * e * (w⇧T ⊓ -v⇧T)⇧⋆ ⊔ --v⇧T" using "2" (*‹top * (e::'a) * ((w::'a)⇧T ⊓ - (v::'a)⇧T)⇧⋆ * w⇧T ≤ top * e * (w⇧T ⊓ - v⇧T)⇧⋆ ⊔ - - v⇧T›*) "3" (*‹- - v⇧T * w⇧T ≤ top * e * (w⇧T ⊓ - v⇧T)⇧⋆ ⊔ - - v⇧T›*) by simp finally (*calculation: ‹(top * e * (w⇧T ⊓ - v⇧T)⇧⋆ ⊔ - - v⇧T) * w⇧T ≤ top * e * (w⇧T ⊓ - v⇧T)⇧⋆ ⊔ - - v⇧T›*) have "top * e ⊔ (top * e * (w⇧T ⊓ -v⇧T)⇧⋆ ⊔ --v⇧T) * w⇧T ≤ top * e * (w⇧T ⊓ -v⇧T)⇧⋆ ⊔ --v⇧T" using "4" (*‹top * e ≤ top * e * (w⇧T ⊓ - v⇧T)⇧⋆ ⊔ - - v⇧T›*) by simp hence 5: "top * e * w⇧T⇧⋆ ≤ top * e * (w⇧T ⊓ -v⇧T)⇧⋆ ⊔ --v⇧T" by (simp add: star_right_induct (*‹?z ⊔ ?x * ?y ≤ ?x ⟶ ?z * ?y⇧⋆ ≤ ?x›*)) have 6: "top * e ≤ top * e * (w⇧T ⊓ -v * -v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆" using sup_right_divisibility (*‹(?x ≤ ?y) = (∃z. z ⊔ ?x = ?y)›*) star.circ_back_loop_fixpoint (*‹?z * ?y⇧⋆ * ?y ⊔ ?z = ?z * ?y⇧⋆›*) by blast have "(top * e * (w⇧T ⊓ -v * -v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆)⇧T ≤ (top * e * w⇧T⇧⋆)⇧T" by (simp add: star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) inf_assoc (*‹?x ⊓ ?y ⊓ ?z = ?x ⊓ (?y ⊓ ?z)›*)) also (*calculation: ‹(top * e * (w⇧T ⊓ - v * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆)⇧T ≤ (top * e * w⇧T⇧⋆)⇧T›*) have "... = w⇧⋆ * e⇧T * top" by (simp add: conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) finally (*calculation: ‹(top * e * (w⇧T ⊓ - v * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆)⇧T ≤ w⇧⋆ * e⇧T * top›*) have 7: "(top * e * (w⇧T ⊓ -v * -v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆)⇧T ≤ w⇧⋆ * e⇧T * top" . have "(top * e * (w⇧T ⊓ -v * -v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆)⇧T ≤ (top * e * (-v * -v⇧T)⇧⋆)⇧T" by (simp add: conv_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x⇧T ≤ ?y⇧T›*) inf_commute (*‹(?x::'a) ⊓ (?y::'a) = ?y ⊓ ?x›*) mult_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*) star_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) le_infI2 (*‹(?b::'a) ≤ (?x::'a) ⟹ (?a::'a) ⊓ ?b ≤ ?x›*)) also (*calculation: ‹(top * e * (w⇧T ⊓ - v * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆)⇧T ≤ (top * e * (- v * - v⇧T)⇧⋆)⇧T›*) have "... ≤ (top * v * -v⇧T * (-v * -v⇧T)⇧⋆)⇧T" by (metis assms( (*‹e ≤ v * - v⇧T›*) 3) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹(top * e * (w⇧T ⊓ - v * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆)⇧T ≤ (top * v * - v⇧T * (- v * - v⇧T)⇧⋆)⇧T›*) have "... = (top * v * (-v⇧T * -v)⇧⋆ * -v⇧T)⇧T" by (simp add: mult_assoc (*‹(?a::'a::type) * (?b::'a::type) * (?c::'a::type) = ?a * (?b * ?c)›*) star_slide (*‹((?x::'a::type) * (?y::'a::type))⇧⋆ * ?x = ?x * (?y * ?x)⇧⋆›*)) also (*calculation: ‹(top * (e::'a::type) * ((w::'a::type)⇧T ⊓ - (v::'a::type) * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆)⇧T ≤ (top * v * (- v⇧T * - v)⇧⋆ * - v⇧T)⇧T›*) have "... ≤ (top * -v⇧T)⇧T" using conv_order (*‹(?x ≤ ?y) = (?x⇧T ≤ ?y⇧T)›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) by auto also (*calculation: ‹(top * e * (w⇧T ⊓ - v * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆)⇧T ≤ (top * - v⇧T)⇧T›*) have "... = -v" by (simp add: assms( (*‹vector v›*) 4) conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) vector_conv_compl (*‹vector ?v ⟹ covector (- ?v⇧T)›*)) finally (*calculation: ‹(top * e * (w⇧T ⊓ - v * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆)⇧T ≤ - v›*) have 8: "(top * e * (w⇧T ⊓ -v * -v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆)⇧T ≤ w⇧⋆ * e⇧T * top ⊓ -v" using "7" (*‹(top * e * (w⇧T ⊓ - v * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆)⇧T ≤ w⇧⋆ * e⇧T * top›*) by simp have "covector (top * e * (w⇧T ⊓ -v * -v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆)" by (simp add: covector_mult_closed (*‹covector ?x ⟹ covector (?x * ?y)›*)) hence "top * e * (w⇧T ⊓ -v * -v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆ * (w⇧T ⊓ -v⇧T) = top * e * (w⇧T ⊓ -v * -v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆ * (w⇧T ⊓ -v⇧T ⊓ (top * e * (w⇧T ⊓ -v * -v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆)⇧T)" by (metis comp_inf_vector_1 (*‹(?x ⊓ top * ?y) * ?z = ?x * (?z ⊓ (top * ?y)⇧T)›*) inf.idem (*‹?a ⊓ ?a = ?a›*)) also (*calculation: ‹top * e * (w⇧T ⊓ - v * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆ * (w⇧T ⊓ - v⇧T) = top * e * (w⇧T ⊓ - v * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆ * (w⇧T ⊓ - v⇧T ⊓ (top * e * (w⇧T ⊓ - v * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆)⇧T)›*) have "... ≤ top * e * (w⇧T ⊓ -v * -v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆ * (w⇧T ⊓ -v⇧T ⊓ w⇧⋆ * e⇧T * top ⊓ -v)" using "8" (*‹(top * e * (w⇧T ⊓ - v * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆)⇧T ≤ w⇧⋆ * e⇧T * top ⊓ - v›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) inf.sup_right_isotone (*‹?y ≤ ?x ⟹ ?z ⊓ ?y ≤ ?z ⊓ ?x›*) inf_assoc (*‹?x ⊓ ?y ⊓ ?z = ?x ⊓ (?y ⊓ ?z)›*) by simp also (*calculation: ‹top * e * (w⇧T ⊓ - v * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆ * (w⇧T ⊓ - v⇧T) ≤ top * e * (w⇧T ⊓ - v * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆ * (w⇧T ⊓ - v⇧T ⊓ w⇧⋆ * e⇧T * top ⊓ - v)›*) have "... = top * e * (w⇧T ⊓ -v * -v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆ * (w⇧T ⊓ (-v ⊓ -v⇧T) ⊓ w⇧⋆ * e⇧T * top)" using inf_assoc (*‹(?x::'a) ⊓ (?y::'a) ⊓ (?z::'a) = ?x ⊓ (?y ⊓ ?z)›*) inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) by (simp add: inf_assoc (*‹(?x::'a) ⊓ (?y::'a) ⊓ (?z::'a) = ?x ⊓ (?y ⊓ ?z)›*)) also (*calculation: ‹top * e * (w⇧T ⊓ - v * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆ * (w⇧T ⊓ - v⇧T) ≤ top * e * (w⇧T ⊓ - v * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆ * (w⇧T ⊓ (- v ⊓ - v⇧T) ⊓ w⇧⋆ * e⇧T * top)›*) have "... = top * e * (w⇧T ⊓ -v * -v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆ * (w⇧T ⊓ -v * -v⇧T ⊓ w⇧⋆ * e⇧T * top)" using assms(4) (*‹vector v›*) conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) vector_complement_closed (*‹vector ?x ⟹ vector (- ?x)›*) vector_covector (*‹⟦vector ?v; vector ?w⟧ ⟹ ?v ⊓ ?w⇧T = ?v * ?w⇧T›*) by fastforce also (*calculation: ‹top * e * (w⇧T ⊓ - v * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆ * (w⇧T ⊓ - v⇧T) ≤ top * e * (w⇧T ⊓ - v * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆ * (w⇧T ⊓ - v * - v⇧T ⊓ w⇧⋆ * e⇧T * top)›*) have "... ≤ top * e * (w⇧T ⊓ -v * -v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) star.circ_plus_same (*‹?x⇧⋆ * ?x = ?x⁺›*) star.left_plus_below_circ (*‹?x⁺ ≤ ?x⇧⋆›*)) finally (*calculation: ‹top * (e::'a) * ((w::'a)⇧T ⊓ - (v::'a) * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆ * (w⇧T ⊓ - v⇧T) ≤ top * e * (w⇧T ⊓ - v * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆›*) have 9: "top * e ⊔ top * e * (w⇧T ⊓ -v * -v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆ * (w⇧T ⊓ -v⇧T) ≤ top * e * (w⇧T ⊓ -v * -v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆" using "6" (*‹top * (e::'a) ≤ top * e * ((w::'a)⇧T ⊓ - (v::'a) * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆›*) by simp have "prim_EP w v e ≤ -v⇧T ⊓ top * e * w⇧T⇧⋆" using inf.sup_left_isotone (*‹?y ≤ ?x ⟹ ?y ⊓ ?z ≤ ?x ⊓ ?z›*) by auto also (*calculation: ‹prim_EP w v e ≤ - v⇧T ⊓ top * e * w⇧T⇧⋆›*) have "... ≤ top * e * (w⇧T ⊓ -v⇧T)⇧⋆" using "5" (*‹top * e * w⇧T⇧⋆ ≤ top * e * (w⇧T ⊓ - v⇧T)⇧⋆ ⊔ - - v⇧T›*) by (metis inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) shunting_var_p (*‹(?x ⊓ - ?y ≤ ?z) = (?x ≤ ?z ⊔ - - ?y)›*)) also (*calculation: ‹prim_EP w v e ≤ top * e * (w⇧T ⊓ - v⇧T)⇧⋆›*) have "... ≤ top * e * (w⇧T ⊓ -v * -v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆" using "9" (*‹top * e ⊔ top * e * (w⇧T ⊓ - v * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆ * (w⇧T ⊓ - v⇧T) ≤ top * e * (w⇧T ⊓ - v * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆›*) by (simp add: star_right_induct (*‹?z ⊔ ?x * ?y ≤ ?x ⟶ ?z * ?y⇧⋆ ≤ ?x›*)) finally (*calculation: ‹prim_EP w v e ≤ top * e * (w⇧T ⊓ - v * - v⇧T ⊓ w⇧⋆ * e⇧T * top)⇧⋆›*) have 10: "prim_EP w v e ≤ top * e * (prim_P w v e)⇧T⇧⋆" by (simp add: conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) have "top * e = top * (v * -v⇧T ⊓ e)" by (simp add: assms( (*‹e ≤ v * - v⇧T›*) 3) inf.absorb2 (*‹?b ≤ ?a ⟹ ?a ⊓ ?b = ?b›*)) also (*calculation: ‹top * e = top * (v * - v⇧T ⊓ e)›*) have "... ≤ top * (v * top ⊓ e)" using inf.sup_right_isotone (*‹?y ≤ ?x ⟹ ?z ⊓ ?y ≤ ?z ⊓ ?x›*) inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) top_greatest (*‹(?x::'a::type) ≤ top›*) by presburger also (*calculation: ‹top * e ≤ top * (v * top ⊓ e)›*) have "... = (top ⊓ (v * top)⇧T) * e" using assms(4) (*‹vector v›*) covector_inf_comp_3 (*‹vector ?x ⟹ (?y ⊓ ?x⇧T) * ?z = ?y * (?x ⊓ ?z)›*) by presburger also (*calculation: ‹top * e ≤ (top ⊓ (v * top)⇧T) * e›*) have "... = top * v⇧T * e" by (simp add: conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*)) also (*calculation: ‹top * e ≤ top * v⇧T * e›*) have "... = top * r⇧T * t⇧⋆ * e" by (simp add: assms( (*‹v⇧T = r⇧T * t⇧⋆›*) 5) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*)) also (*calculation: ‹top * e ≤ top * r⇧T * t⇧⋆ * e›*) have "... ≤ top * r⇧T * (prim_W w v e)⇧⋆ * e" by (metis assms( (*‹vector v› ‹t ≤ w› ‹t ≤ v * v⇧T›*) 4,6,7) mst_extends_old_tree (*‹⟦?t ≤ ?w; ?t ≤ ?v * ?v⇧T; vector ?v⟧ ⟹ ?t ≤ prim_W ?w ?v ?e›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) finally (*calculation: ‹top * e ≤ top * r⇧T * prim_W w v e⇧⋆ * e›*) have 11: "top * e ≤ top * r⇧T * (prim_W w v e)⇧⋆ * e" . have "r⇧T * (prim_W w v e)⇧⋆ * (prim_EP w v e) ≤ r⇧T * (prim_W w v e)⇧⋆ * (top * e * (prim_P w v e)⇧T⇧⋆)" using "10" (*‹prim_EP w v e ≤ top * e * prim_P w v e⇧T⇧⋆›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) by blast also (*calculation: ‹r⇧T * prim_W w v e⇧⋆ * prim_EP w v e ≤ r⇧T * prim_W w v e⇧⋆ * (top * e * prim_P w v e⇧T⇧⋆)›*) have "... = r⇧T * (prim_W w v e)⇧⋆ * top * e * (prim_P w v e)⇧T⇧⋆" by (simp add: mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹r⇧T * prim_W w v e⇧⋆ * prim_EP w v e ≤ r⇧T * prim_W w v e⇧⋆ * top * e * prim_P w v e⇧T⇧⋆›*) have "... ≤ top * e * (prim_P w v e)⇧T⇧⋆" by (metis comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_inf_covector (*‹?x * (?y ⊓ top * ?z) = ?x * ?y ⊓ top * ?z›*) inf.idem (*‹?a ⊓ ?a = ?a›*) inf.sup_right_divisibility (*‹(?y ≤ ?x) = (∃z. z ⊓ ?x = ?y)›*)) also (*calculation: ‹(r::'a)⇧T * prim_W (w::'a) (v::'a) (e::'a)⇧⋆ * prim_EP w v e ≤ top * e * prim_P w v e⇧T⇧⋆›*) have "... ≤ top * r⇧T * (prim_W w v e)⇧⋆ * e * (prim_P w v e)⇧T⇧⋆" using "11" (*‹top * (e::'a::type) ≤ top * (r::'a::type)⇧T * prim_W (w::'a::type) (v::'a::type) e⇧⋆ * e›*) by (simp add: mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) also (*calculation: ‹r⇧T * prim_W w v e⇧⋆ * prim_EP w v e ≤ top * r⇧T * prim_W w v e⇧⋆ * e * prim_P w v e⇧T⇧⋆›*) have "... = r⇧T * (prim_W w v e)⇧⋆ * e * (prim_P w v e)⇧T⇧⋆" using assms(2) (*‹vector r›*) vector_conv_covector (*‹vector ?v = covector (?v⇧T)›*) by auto also (*calculation: ‹r⇧T * prim_W w v e⇧⋆ * prim_EP w v e ≤ r⇧T * prim_W w v e⇧⋆ * e * prim_P w v e⇧T⇧⋆›*) have "... ≤ r⇧T * (prim_W w v e)⇧⋆ * (prim_W w v e) * (prim_P w v e)⇧T⇧⋆" by (simp add: mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹r⇧T * prim_W w v e⇧⋆ * prim_EP w v e ≤ r⇧T * prim_W w v e⇧⋆ * prim_W w v e * prim_P w v e⇧T⇧⋆›*) have "... ≤ r⇧T * (prim_W w v e)⇧⋆ * (prim_W w v e) * (prim_W w v e)⇧⋆" by (meson dual_order.trans (*‹⟦(?b::'a) ≤ (?a::'a); (?c::'a) ≤ ?b⟧ ⟹ ?c ≤ ?a›*) mult_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*) star_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) sup_ge1 (*‹(?x::'a) ≤ ?x ⊔ (?y::'a)›*) sup_ge2 (*‹(?y::'a) ≤ (?x::'a) ⊔ ?y›*)) also (*calculation: ‹r⇧T * prim_W w v e⇧⋆ * prim_EP w v e ≤ r⇧T * prim_W w v e⇧⋆ * prim_W w v e * prim_W w v e⇧⋆›*) have "... ≤ r⇧T * (prim_W w v e)⇧⋆" by (metis mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star.circ_transitive_equal (*‹idempotent (?x⇧⋆)›*) star.left_plus_below_circ (*‹?x⁺ ≤ ?x⇧⋆›*)) finally (*calculation: ‹(r::'a)⇧T * prim_W (w::'a) (v::'a) (e::'a)⇧⋆ * prim_EP w v e ≤ r⇧T * prim_W w v e⇧⋆›*) have 12: "r⇧T * (prim_W w v e)⇧⋆ * (prim_EP w v e) ≤ r⇧T * (prim_W w v e)⇧⋆" . have "r⇧T * (prim_W w v e)⇧⋆ * w ≤ r⇧T * (prim_W w v e)⇧⋆ * (w ⊔ prim_EP w v e)" by (simp add: inf_assoc (*‹?x ⊓ ?y ⊓ ?z = ?x ⊓ (?y ⊓ ?z)›*)) also (*calculation: ‹r⇧T * prim_W w v e⇧⋆ * w ≤ r⇧T * prim_W w v e⇧⋆ * (w ⊔ prim_EP w v e)›*) have "... = r⇧T * (prim_W w v e)⇧⋆ * ((w ⊔ prim_EP w v e) ⊓ (-(prim_EP w v e) ⊔ prim_EP w v e))" by (metis assms( (*‹regular (prim_EP w v e)›*) 1) inf_top_right (*‹?x ⊓ top = ?x›*) stone (*‹- ?x ⊔ - - ?x = top›*)) also (*calculation: ‹r⇧T * prim_W w v e⇧⋆ * w ≤ r⇧T * prim_W w v e⇧⋆ * ((w ⊔ prim_EP w v e) ⊓ (- prim_EP w v e ⊔ prim_EP w v e))›*) have "... = r⇧T * (prim_W w v e)⇧⋆ * ((w ⊓ -(prim_EP w v e)) ⊔ prim_EP w v e)" by (simp add: sup_inf_distrib2 (*‹?y ⊓ ?z ⊔ ?x = (?y ⊔ ?x) ⊓ (?z ⊔ ?x)›*)) also (*calculation: ‹(r::'a)⇧T * prim_W (w::'a) (v::'a) (e::'a)⇧⋆ * w ≤ r⇧T * prim_W w v e⇧⋆ * (w ⊓ - prim_EP w v e ⊔ prim_EP w v e)›*) have "... = r⇧T * (prim_W w v e)⇧⋆ * (w ⊓ -(prim_EP w v e)) ⊔ r⇧T * (prim_W w v e)⇧⋆ * (prim_EP w v e)" by (simp add: comp_left_dist_sup (*‹?x * ?y ⊔ ?x * ?z = ?x * (?y ⊔ ?z)›*)) also (*calculation: ‹r⇧T * prim_W w v e⇧⋆ * w ≤ r⇧T * prim_W w v e⇧⋆ * (w ⊓ - prim_EP w v e) ⊔ r⇧T * prim_W w v e⇧⋆ * prim_EP w v e›*) have "... ≤ r⇧T * (prim_W w v e)⇧⋆ * (prim_W w v e) ⊔ r⇧T * (prim_W w v e)⇧⋆ * (prim_EP w v e)" using mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) sup_left_isotone (*‹?x ≤ ?y ⟹ ?x ⊔ ?z ≤ ?y ⊔ ?z›*) by auto also (*calculation: ‹(r::'a)⇧T * prim_W (w::'a) (v::'a) (e::'a)⇧⋆ * w ≤ r⇧T * prim_W w v e⇧⋆ * prim_W w v e ⊔ r⇧T * prim_W w v e⇧⋆ * prim_EP w v e›*) have "... ≤ r⇧T * (prim_W w v e)⇧⋆ ⊔ r⇧T * (prim_W w v e)⇧⋆ * (prim_EP w v e)" using mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star.circ_plus_same (*‹(?x::'a)⇧⋆ * ?x = ?x⁺›*) star.left_plus_below_circ (*‹(?x::'a)⁺ ≤ ?x⇧⋆›*) sup_left_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x ⊔ (?z::'a) ≤ ?y ⊔ ?z›*) by auto also (*calculation: ‹(r::'a::type)⇧T * prim_W (w::'a::type) (v::'a::type) (e::'a::type)⇧⋆ * w ≤ r⇧T * prim_W w v e⇧⋆ ⊔ r⇧T * prim_W w v e⇧⋆ * prim_EP w v e›*) have "... = r⇧T * (prim_W w v e)⇧⋆" using "12" (*‹r⇧T * prim_W w v e⇧⋆ * prim_EP w v e ≤ r⇧T * prim_W w v e⇧⋆›*) sup.absorb1 (*‹?b ≤ ?a ⟹ ?a ⊔ ?b = ?a›*) by blast finally (*calculation: ‹r⇧T * prim_W w v e⇧⋆ * w ≤ r⇧T * prim_W w v e⇧⋆›*) have "r⇧T ⊔ r⇧T * (prim_W w v e)⇧⋆ * w ≤ r⇧T * (prim_W w v e)⇧⋆" using "1" (*‹r⇧T ≤ r⇧T * prim_W w v e⇧⋆›*) by simp thus "?thesis" (*goal: ‹r⇧T * w⇧⋆ ≤ r⇧T * prim_W w v e⇧⋆›*) by (simp add: star_right_induct (*‹?z ⊔ ?x * ?y ≤ ?x ⟶ ?z * ?y⇧⋆ ≤ ?x›*)) qed text ‹ Some of the following lemmas already hold in pseudocomplemented distributive Kleene allegories. › subsubsection ‹Exchange gives Minimum Spanning Trees› text ‹ The lemmas in this section are used to show that the after exchange we obtain a minimum spanning tree. The following lemmas show various interactions between the three constituents of the tree after exchange. › lemma epm_1: "vector v ⟹ prim_E w v e ⊔ prim_P w v e = prim_EP w v e" by (metis inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) inf_sup_distrib1 (*‹?x ⊓ (?y ⊔ ?z) = ?x ⊓ ?y ⊔ ?x ⊓ ?z›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*) regular_closed_p (*‹regular (- ?x)›*) regular_complement_top (*‹regular ?x ⟹ ?x ⊔ - ?x = top›*) vector_conv_compl (*‹vector ?v ⟹ covector (- ?v⇧T)›*)) lemma epm_2: assumes "regular (prim_EP w v e)" and "vector v" shows "(w ⊓ -(prim_EP w v e)) ⊔ prim_P w v e ⊔ prim_E w v e = w" proof (-) (*goal: ‹(w::'a) ⊓ - prim_EP w (v::'a) (e::'a) ⊔ prim_P w v e ⊔ prim_E w v e = w›*) have "(w ⊓ -(prim_EP w v e)) ⊔ prim_P w v e ⊔ prim_E w v e = (w ⊓ -(prim_EP w v e)) ⊔ prim_EP w v e" using epm_1 (*‹vector ?v ⟹ prim_E ?w ?v ?e ⊔ prim_P ?w ?v ?e = prim_EP ?w ?v ?e›*) sup_assoc (*‹?x ⊔ ?y ⊔ ?z = ?x ⊔ (?y ⊔ ?z)›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*) assms(2) (*‹vector v›*) by (simp add: inf_sup_distrib1 (*‹(?x::'a::type) ⊓ ((?y::'a::type) ⊔ (?z::'a::type)) = ?x ⊓ ?y ⊔ ?x ⊓ ?z›*)) also (*calculation: ‹w ⊓ - prim_EP w v e ⊔ prim_P w v e ⊔ prim_E w v e = w ⊓ - prim_EP w v e ⊔ prim_EP w v e›*) have "... = w ⊔ prim_EP w v e" by (metis assms( (*‹regular (prim_EP (w::'a) (v::'a) (e::'a))›*) 1) inf_top.right_neutral (*‹(?a::'a) ⊓ top = ?a›*) regular_complement_top (*‹regular (?x::'a) ⟹ ?x ⊔ - ?x = top›*) sup_inf_distrib2 (*‹(?y::'a) ⊓ (?z::'a) ⊔ (?x::'a) = (?y ⊔ ?x) ⊓ (?z ⊔ ?x)›*)) also (*calculation: ‹w ⊓ - prim_EP w v e ⊔ prim_P w v e ⊔ prim_E w v e = w ⊔ prim_EP w v e›*) have "... = w" by (simp add: sup_inf_distrib1 (*‹?x ⊔ ?y ⊓ ?z = (?x ⊔ ?y) ⊓ (?x ⊔ ?z)›*)) finally (*calculation: ‹w ⊓ - prim_EP w v e ⊔ prim_P w v e ⊔ prim_E w v e = w›*) show "?thesis" (*goal: ‹w ⊓ - prim_EP w v e ⊔ prim_P w v e ⊔ prim_E w v e = w›*) . qed lemma epm_4: assumes "e ≤ w" and "injective w" and "w * v ≤ v" and "e ≤ v * -v⇧T" shows "top * e * w⇧T⁺ ≤ top * v⇧T" proof (-) (*goal: ‹top * (e::'a::type) * (w::'a::type)⇧T⁺ ≤ top * (v::'a::type)⇧T›*) have "w⇧⋆ * v ≤ v" by (simp add: assms( (*‹w * v ≤ v›*) 3) star_left_induct_mult (*‹?x * ?y ≤ ?y ⟹ ?x⇧⋆ * ?y ≤ ?y›*)) hence 1: "v⇧T * w⇧T⇧⋆ ≤ v⇧T" using conv_star_commute (*‹(?x::'a)⇧⋆⇧T = ?x⇧T⇧⋆›*) conv_dist_comp (*‹((?x::'a) * (?y::'a))⇧T = ?y⇧T * ?x⇧T›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) by fastforce have "e * w⇧T ≤ w * w⇧T ⊓ e * w⇧T" by (simp add: assms( (*‹e ≤ w›*) 1) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) also (*calculation: ‹e * w⇧T ≤ w * w⇧T ⊓ e * w⇧T›*) have "... ≤ 1 ⊓ e * w⇧T" using assms(2) (*‹injective (w::'a)›*) inf.sup_left_isotone (*‹?y ≤ ?x ⟹ ?y ⊓ ?z ≤ ?x ⊓ ?z›*) by auto also (*calculation: ‹e * w⇧T ≤ 1 ⊓ e * w⇧T›*) have "... = 1 ⊓ w * e⇧T" using calculation (*‹e * w⇧T ≤ 1 ⊓ e * w⇧T›*) conv_dist_comp (*‹((?x::'a) * (?y::'a))⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) coreflexive_symmetric (*‹coreflexive ?x ⟹ symmetric ?x›*) by fastforce also (*calculation: ‹e * w⇧T ≤ 1 ⊓ w * e⇧T›*) have "... ≤ w * e⇧T" by simp also (*calculation: ‹e * w⇧T ≤ w * e⇧T›*) have "... ≤ w * -v * v⇧T" by (metis assms( (*‹e ≤ v * - v⇧T›*) 4) conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_order (*‹(?x ≤ ?y) = (?x⇧T ≤ ?y⇧T)›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹e * w⇧T ≤ w * - v * v⇧T›*) have "... ≤ top * v⇧T" by (simp add: mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) finally (*calculation: ‹e * w⇧T ≤ top * v⇧T›*) have "top * e * w⇧T⁺ ≤ top * v⇧T * w⇧T⇧⋆" by (metis order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) dense_top_closed (*‹dense_rel top›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) transitive_top_closed (*‹transitive top›*)) also (*calculation: ‹top * e * w⇧T⁺ ≤ top * v⇧T * w⇧T⇧⋆›*) have "... ≤ top * v⇧T" using "1" (*‹v⇧T * w⇧T⇧⋆ ≤ v⇧T›*) by (simp add: mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) finally (*calculation: ‹top * e * w⇧T⁺ ≤ top * v⇧T›*) show "?thesis" (*goal: ‹top * e * w⇧T⁺ ≤ top * v⇧T›*) . qed lemma epm_5: assumes "e ≤ w" and "injective w" and "w * v ≤ v" and "e ≤ v * -v⇧T" and "vector v" shows "prim_P w v e = bot" proof (-) (*goal: ‹prim_P w v e = bot›*) have 1: "e = w ⊓ top * e" by (simp add: assms( (*‹e ≤ w› ‹injective w›*) 1,2) epm_3 (*‹⟦?e ≤ ?w; injective ?w⟧ ⟹ ?e = ?w ⊓ top * ?e›*)) have 2: "top * e * w⇧T⁺ ≤ top * v⇧T" by (simp add: assms( (*‹e ≤ w› ‹injective w› ‹w * v ≤ v› ‹e ≤ v * - v⇧T›*) 1-4) epm_4 (*‹⟦?e ≤ ?w; injective ?w; ?w * ?v ≤ ?v; ?e ≤ ?v * - ?v⇧T⟧ ⟹ top * ?e * ?w⇧T⁺ ≤ top * ?v⇧T›*)) have 3: "-v * -v⇧T ⊓ top * v⇧T = bot" by (simp add: assms( (*‹vector v›*) 5) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) covector_vector_comp (*‹vector ?v ⟹ - ?v⇧T * ?v = bot›*) inf.sup_monoid.add_commute (*‹?a ⊓ ?b = ?b ⊓ ?a›*) schroeder_2 (*‹(?x * ?y ⊓ ?z = bot) = (?z * ?y⇧T ⊓ ?x = bot)›*)) have "prim_P w v e = (w ⊓ -v * -v⇧T ⊓ top * e) ⊔ (w ⊓ -v * -v⇧T ⊓ top * e * w⇧T⁺)" by (metis inf_sup_distrib1 (*‹?x ⊓ (?y ⊔ ?z) = ?x ⊓ ?y ⊔ ?x ⊓ ?z›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) star.circ_back_loop_fixpoint (*‹?z * ?y⇧⋆ * ?y ⊔ ?z = ?z * ?y⇧⋆›*) star_plus (*‹?y⇧⋆ * ?y = ?y⁺›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*)) also (*calculation: ‹prim_P w v e = w ⊓ - v * - v⇧T ⊓ top * e ⊔ w ⊓ - v * - v⇧T ⊓ top * e * w⇧T⁺›*) have "... ≤ (e ⊓ -v * -v⇧T) ⊔ (w ⊓ -v * -v⇧T ⊓ top * e * w⇧T⁺)" using "1" (*‹e = w ⊓ top * e›*) by (metis comp_inf.mult_semi_associative (*‹(?x::'a) ⊓ (?y::'a) ⊓ (?z::'a) ≤ ?x ⊓ (?y ⊓ ?z)›*) inf.sup_monoid.add_commute (*‹(?a::'a) ⊓ (?b::'a) = ?b ⊓ ?a›*) semiring.add_right_mono (*‹(?a::'a) ≤ (?b::'a) ⟹ ?a ⊔ (?c::'a) ≤ ?b ⊔ ?c›*)) also (*calculation: ‹prim_P w v e ≤ e ⊓ - v * - v⇧T ⊔ w ⊓ - v * - v⇧T ⊓ top * e * w⇧T⁺›*) have "... ≤ (e ⊓ -v * -v⇧T) ⊔ (w ⊓ -v * -v⇧T ⊓ top * v⇧T)" using "2" (*‹top * (e::'a::type) * (w::'a::type)⇧T⁺ ≤ top * (v::'a::type)⇧T›*) by (metis sup_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊔ ?x ≤ ?z ⊔ ?y›*) inf.sup_right_isotone (*‹?y ≤ ?x ⟹ ?z ⊓ ?y ≤ ?z ⊓ ?x›*)) also (*calculation: ‹prim_P w v e ≤ e ⊓ - v * - v⇧T ⊔ w ⊓ - v * - v⇧T ⊓ top * v⇧T›*) have "... ≤ (e ⊓ -v * -v⇧T) ⊔ (-v * -v⇧T ⊓ top * v⇧T)" using inf.assoc (*‹?a ⊓ ?b ⊓ ?c = ?a ⊓ (?b ⊓ ?c)›*) le_infI2 (*‹?b ≤ ?x ⟹ ?a ⊓ ?b ≤ ?x›*) by auto also (*calculation: ‹prim_P w v e ≤ e ⊓ - v * - v⇧T ⊔ - v * - v⇧T ⊓ top * v⇧T›*) have "... ≤ v * -v⇧T ⊓ -v * -v⇧T" using "3" (*‹- v * - v⇧T ⊓ top * v⇧T = bot›*) assms(4) (*‹e ≤ v * - v⇧T›*) inf.sup_left_isotone (*‹?y ≤ ?x ⟹ ?y ⊓ ?z ≤ ?x ⊓ ?z›*) by auto also (*calculation: ‹prim_P w v e ≤ v * - v⇧T ⊓ - v * - v⇧T›*) have "... ≤ v * top ⊓ -v * top" using inf.sup_mono (*‹⟦?c ≤ ?a; ?d ≤ ?b⟧ ⟹ ?c ⊓ ?d ≤ ?a ⊓ ?b›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) top_greatest (*‹?x ≤ top›*) by blast also (*calculation: ‹prim_P w v e ≤ v * top ⊓ - v * top›*) have "... = bot" using assms(5) (*‹vector v›*) inf_compl_bot (*‹?x ⊓ - ?x = bot›*) vector_complement_closed (*‹vector ?x ⟹ vector (- ?x)›*) by auto finally (*calculation: ‹prim_P w v e ≤ bot›*) show "?thesis" (*goal: ‹prim_P w v e = bot›*) by (simp add: le_iff_inf (*‹((?x::'a) ≤ (?y::'a)) = (?x ⊓ ?y = ?x)›*)) qed lemma epm_6: assumes "e ≤ w" and "injective w" and "w * v ≤ v" and "e ≤ v * -v⇧T" and "vector v" shows "prim_E w v e = e" proof (-) (*goal: ‹prim_E w v e = e›*) have 1: "e ≤ --v * -v⇧T" using assms(4) (*‹e ≤ v * - v⇧T›*) mult_isotone (*‹⟦?w ≤ ?y; ?x ≤ ?z⟧ ⟹ ?w * ?x ≤ ?y * ?z›*) order_lesseq_imp (*‹(∀z≥?x. ?y ≤ z) = (?y ≤ ?x)›*) pp_increasing (*‹(?x::'a::type) ≤ - - ?x›*) by blast have 2: "top * e * w⇧T⁺ ≤ top * v⇧T" by (simp add: assms( (*‹(e::'a) ≤ (w::'a)› ‹injective (w::'a)› ‹(w::'a) * (v::'a) ≤ v› ‹(e::'a) ≤ (v::'a) * - v⇧T›*) 1-4) epm_4 (*‹⟦(?e::'a) ≤ (?w::'a); injective ?w; ?w * (?v::'a) ≤ ?v; ?e ≤ ?v * - ?v⇧T⟧ ⟹ top * ?e * ?w⇧T⁺ ≤ top * ?v⇧T›*)) have 3: "e = w ⊓ top * e" by (simp add: assms( (*‹e ≤ w› ‹injective w›*) 1,2) epm_3 (*‹⟦?e ≤ ?w; injective ?w⟧ ⟹ ?e = ?w ⊓ top * ?e›*)) hence "e ≤ top * e * w⇧T⇧⋆" by (metis le_infI2 (*‹?b ≤ ?x ⟹ ?a ⊓ ?b ≤ ?x›*) star.circ_back_loop_fixpoint (*‹?z * ?y⇧⋆ * ?y ⊔ ?z = ?z * ?y⇧⋆›*) sup.commute (*‹?a ⊔ ?b = ?b ⊔ ?a›*) sup_ge1 (*‹?x ≤ ?x ⊔ ?y›*)) hence 4: "e ≤ prim_E w v e" using "1" (*‹e ≤ - - v * - v⇧T›*) by (simp add: assms( (*‹(e::'a::type) ≤ (w::'a::type)›*) 1)) have 5: "--v * -v⇧T ⊓ top * v⇧T = bot" by (simp add: assms( (*‹vector (v::'a)›*) 5) comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*) covector_vector_comp (*‹vector (?v::'a) ⟹ - ?v⇧T * ?v = bot›*) inf.sup_monoid.add_commute (*‹(?a::'a) ⊓ (?b::'a) = ?b ⊓ ?a›*) schroeder_2 (*‹((?x::'a) * (?y::'a) ⊓ (?z::'a) = bot) = (?z * ?y⇧T ⊓ ?x = bot)›*)) have "prim_E w v e = (w ⊓ --v * -v⇧T ⊓ top * e) ⊔ (w ⊓ --v * -v⇧T ⊓ top * e * w⇧T⁺)" by (metis inf_sup_distrib1 (*‹(?x::'a) ⊓ ((?y::'a) ⊔ (?z::'a)) = ?x ⊓ ?y ⊔ ?x ⊓ ?z›*) mult_assoc (*‹(?a::'a) * (?b::'a) * (?c::'a) = ?a * (?b * ?c)›*) star.circ_back_loop_fixpoint (*‹(?z::'a) * (?y::'a)⇧⋆ * ?y ⊔ ?z = ?z * ?y⇧⋆›*) star_plus (*‹(?y::'a)⇧⋆ * ?y = ?y⁺›*) sup_commute (*‹(?x::'a) ⊔ (?y::'a) = ?y ⊔ ?x›*)) also (*calculation: ‹prim_E (w::'a) (v::'a) (e::'a) = w ⊓ - - v * - v⇧T ⊓ top * e ⊔ w ⊓ - - v * - v⇧T ⊓ top * e * w⇧T⁺›*) have "... ≤ (e ⊓ --v * -v⇧T) ⊔ (w ⊓ --v * -v⇧T ⊓ top * e * w⇧T⁺)" using "3" (*‹e = w ⊓ top * e›*) by (metis comp_inf.mult_semi_associative (*‹(?x::'a) ⊓ (?y::'a) ⊓ (?z::'a) ≤ ?x ⊓ (?y ⊓ ?z)›*) inf.sup_monoid.add_commute (*‹(?a::'a) ⊓ (?b::'a) = ?b ⊓ ?a›*) semiring.add_right_mono (*‹(?a::'a) ≤ (?b::'a) ⟹ ?a ⊔ (?c::'a) ≤ ?b ⊔ ?c›*)) also (*calculation: ‹prim_E w v e ≤ e ⊓ - - v * - v⇧T ⊔ w ⊓ - - v * - v⇧T ⊓ top * e * w⇧T⁺›*) have "... ≤ (e ⊓ --v * -v⇧T) ⊔ (w ⊓ --v * -v⇧T ⊓ top * v⇧T)" using "2" (*‹top * e * w⇧T⁺ ≤ top * v⇧T›*) by (metis sup_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊔ ?x ≤ ?z ⊔ ?y›*) inf.sup_right_isotone (*‹?y ≤ ?x ⟹ ?z ⊓ ?y ≤ ?z ⊓ ?x›*)) also (*calculation: ‹prim_E w v e ≤ e ⊓ - - v * - v⇧T ⊔ w ⊓ - - v * - v⇧T ⊓ top * v⇧T›*) have "... ≤ (e ⊓ --v * -v⇧T) ⊔ (--v * -v⇧T ⊓ top * v⇧T)" using inf.assoc (*‹?a ⊓ ?b ⊓ ?c = ?a ⊓ (?b ⊓ ?c)›*) le_infI2 (*‹?b ≤ ?x ⟹ ?a ⊓ ?b ≤ ?x›*) by auto also (*calculation: ‹prim_E (w::'a) (v::'a) (e::'a) ≤ e ⊓ - - v * - v⇧T ⊔ - - v * - v⇧T ⊓ top * v⇧T›*) have "... ≤ e" by (simp add: "5" (*‹- - v * - v⇧T ⊓ top * v⇧T = bot›*)) finally (*calculation: ‹prim_E w v e ≤ e›*) show "?thesis" (*goal: ‹prim_E w v e = e›*) using "4" (*‹(e::'a) ≤ prim_E (w::'a) (v::'a) e›*) by (simp add: order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) qed lemma epm_7: "regular (prim_EP w v e) ⟹ e ≤ w ⟹ injective w ⟹ w * v ≤ v ⟹ e ≤ v * -v⇧T ⟹ vector v ⟹ prim_W w v e = w" by (metis conv_bot (*‹symmetric bot›*) epm_2 (*‹⟦regular (prim_EP ?w ?v ?e); vector ?v⟧ ⟹ ?w ⊓ - prim_EP ?w ?v ?e ⊔ prim_P ?w ?v ?e ⊔ prim_E ?w ?v ?e = ?w›*) epm_5 (*‹⟦?e ≤ ?w; injective ?w; ?w * ?v ≤ ?v; ?e ≤ ?v * - ?v⇧T; vector ?v⟧ ⟹ prim_P ?w ?v ?e = bot›*) epm_6 (*‹⟦?e ≤ ?w; injective ?w; ?w * ?v ≤ ?v; ?e ≤ ?v * - ?v⇧T; vector ?v⟧ ⟹ prim_E ?w ?v ?e = ?e›*)) lemma epm_8: assumes "acyclic w" shows "(w ⊓ -(prim_EP w v e)) ⊓ (prim_P w v e)⇧T = bot" proof (-) (*goal: ‹w ⊓ - prim_EP w v e ⊓ prim_P w v e⇧T = bot›*) have "(w ⊓ -(prim_EP w v e)) ⊓ (prim_P w v e)⇧T ≤ w ⊓ w⇧T" by (meson conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) inf_le1 (*‹?x ⊓ ?y ≤ ?x›*) inf_mono (*‹⟦?a ≤ ?c; ?b ≤ ?d⟧ ⟹ ?a ⊓ ?b ≤ ?c ⊓ ?d›*) order_trans (*‹⟦?x ≤ ?y; ?y ≤ ?z⟧ ⟹ ?x ≤ ?z›*)) thus "?thesis" (*goal: ‹w ⊓ - prim_EP w v e ⊓ prim_P w v e⇧T = bot›*) by (metis assms (*‹pd_kleene_allegory_class.acyclic w›*) acyclic_asymmetric (*‹pd_kleene_allegory_class.acyclic ?w ⟹ asymmetric ?w›*) inf.commute (*‹?a ⊓ ?b = ?b ⊓ ?a›*) le_bot (*‹?a ≤ bot ⟹ ?a = bot›*)) qed lemma epm_9: assumes "e ≤ v * -v⇧T" and "vector v" shows "(w ⊓ -(prim_EP w v e)) ⊓ e = bot" proof (-) (*goal: ‹w ⊓ - prim_EP w v e ⊓ e = bot›*) have 1: "e ≤ -v⇧T" by (metis assms (*‹e ≤ v * - v⇧T› ‹vector v›*) complement_conv_sub (*‹- (?y * ?x) * ?x⇧T ≤ - ?y›*) vector_conv_covector (*‹vector ?v = covector (?v⇧T)›*) ev (*‹⟦vector ?v; ?e ≤ ?v * - ?v⇧T⟧ ⟹ ?e * ?v = bot›*) p_antitone_iff (*‹(?x ≤ - ?y) = (?y ≤ - ?x)›*) p_bot (*‹- bot = top›*)) have "(w ⊓ -(prim_EP w v e)) ⊓ e = (w ⊓ --v⇧T ⊓ e) ⊔ (w ⊓ -(top * e * w⇧T⇧⋆) ⊓ e)" by (simp add: inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) inf_sup_distrib1 (*‹?x ⊓ (?y ⊔ ?z) = ?x ⊓ ?y ⊔ ?x ⊓ ?z›*)) also (*calculation: ‹w ⊓ - prim_EP w v e ⊓ e = w ⊓ - - v⇧T ⊓ e ⊔ w ⊓ - (top * e * w⇧T⇧⋆) ⊓ e›*) have "... ≤ (--v⇧T ⊓ e) ⊔ (-(top * e * w⇧T⇧⋆) ⊓ e)" using comp_inf.mult_left_isotone (*‹?x ≤ ?y ⟹ ?x ⊓ ?z ≤ ?y ⊓ ?z›*) inf.cobounded2 (*‹?a ⊓ ?b ≤ ?b›*) semiring.add_mono (*‹⟦?a ≤ ?b; ?c ≤ ?d⟧ ⟹ ?a ⊔ ?c ≤ ?b ⊔ ?d›*) by blast also (*calculation: ‹w ⊓ - prim_EP w v e ⊓ e ≤ - - v⇧T ⊓ e ⊔ - (top * e * w⇧T⇧⋆) ⊓ e›*) have "... = -(top * e * w⇧T⇧⋆) ⊓ e" using "1" (*‹e ≤ - v⇧T›*) by (metis inf.sup_relative_same_increasing (*‹⟦(?y::'a) ≤ (?x::'a); ?x ⊓ (?z::'a) = ?x ⊓ (?w::'a)⟧ ⟹ ?y ⊓ ?z = ?y ⊓ ?w›*) inf_commute (*‹(?x::'a) ⊓ (?y::'a) = ?y ⊓ ?x›*) inf_sup_distrib1 (*‹(?x::'a) ⊓ ((?y::'a) ⊔ (?z::'a)) = ?x ⊓ ?y ⊔ ?x ⊓ ?z›*) maddux_3_13 (*‹((?x::'a) ⊔ (?y::'a)) ⊓ - ?x = ?y ⊓ - ?x›*) regular_closed_p (*‹regular (- (?x::'a))›*)) also (*calculation: ‹w ⊓ - prim_EP w v e ⊓ e ≤ - (top * e * w⇧T⇧⋆) ⊓ e›*) have "... = bot" by (metis inf.sup_relative_same_increasing (*‹⟦?y ≤ ?x; ?x ⊓ ?z = ?x ⊓ ?w⟧ ⟹ ?y ⊓ ?z = ?y ⊓ ?w›*) inf_bot_right (*‹?x ⊓ bot = bot›*) inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) inf_p (*‹?x ⊓ - ?x = bot›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) star_outer_increasing (*‹?x ≤ ?y⇧⋆ * ?x * ?y⇧⋆›*) top_greatest (*‹?x ≤ top›*)) finally (*calculation: ‹(w::'a) ⊓ - prim_EP w (v::'a) (e::'a) ⊓ e ≤ bot›*) show "?thesis" (*goal: ‹w ⊓ - prim_EP w v e ⊓ e = bot›*) by (simp add: le_iff_inf (*‹(?x ≤ ?y) = (?x ⊓ ?y = ?x)›*)) qed lemma epm_10: assumes "e ≤ v * -v⇧T" and "vector v" shows "(prim_P w v e)⇧T ⊓ e = bot" proof (-) (*goal: ‹prim_P w v e⇧T ⊓ e = bot›*) have "(prim_P w v e)⇧T ≤ -v * -v⇧T" by (simp add: conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) inf.absorb_iff1 (*‹(?a ≤ ?b) = (?a ⊓ ?b = ?a)›*) inf.left_commute (*‹?b ⊓ (?a ⊓ ?c) = ?a ⊓ (?b ⊓ ?c)›*) inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*)) hence "(prim_P w v e)⇧T ⊓ e ≤ -v * -v⇧T ⊓ v * -v⇧T" using assms(1) (*‹e ≤ v * - v⇧T›*) inf_mono (*‹⟦?a ≤ ?c; ?b ≤ ?d⟧ ⟹ ?a ⊓ ?b ≤ ?c ⊓ ?d›*) by blast also (*calculation: ‹prim_P w v e⇧T ⊓ e ≤ - v * - v⇧T ⊓ v * - v⇧T›*) have "... ≤ -v * top ⊓ v * top" using inf.sup_mono (*‹⟦?c ≤ ?a; ?d ≤ ?b⟧ ⟹ ?c ⊓ ?d ≤ ?a ⊓ ?b›*) mult_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*) top_greatest (*‹?x ≤ top›*) by blast also (*calculation: ‹prim_P w v e⇧T ⊓ e ≤ - v * top ⊓ v * top›*) have "... = bot" using assms(2) (*‹vector v›*) inf_compl_bot (*‹?x ⊓ - ?x = bot›*) vector_complement_closed (*‹vector ?x ⟹ vector (- ?x)›*) by auto finally (*calculation: ‹prim_P w v e⇧T ⊓ e ≤ bot›*) show "?thesis" (*goal: ‹prim_P (w::'a) (v::'a) (e::'a)⇧T ⊓ e = bot›*) by (simp add: le_iff_inf (*‹(?x ≤ ?y) = (?x ⊓ ?y = ?x)›*)) qed lemma epm_11: assumes "vector v" shows "(w ⊓ -(prim_EP w v e)) ⊓ prim_P w v e = bot" proof (-) (*goal: ‹w ⊓ - prim_EP w v e ⊓ prim_P w v e = bot›*) have "prim_P w v e ≤ prim_EP w v e" by (metis assms (*‹vector v›*) comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) inf.sup_left_isotone (*‹?y ≤ ?x ⟹ ?y ⊓ ?z ≤ ?x ⊓ ?z›*) inf.sup_right_isotone (*‹?y ≤ ?x ⟹ ?z ⊓ ?y ≤ ?z ⊓ ?x›*) order.refl (*‹?a ≤ ?a›*) top_greatest (*‹?x ≤ top›*) vector_conv_compl (*‹vector ?v ⟹ covector (- ?v⇧T)›*)) thus "?thesis" (*goal: ‹w ⊓ - prim_EP w v e ⊓ prim_P w v e = bot›*) using inf_le2 (*‹?x ⊓ ?y ≤ ?y›*) order_trans (*‹⟦?x ≤ ?y; ?y ≤ ?z⟧ ⟹ ?x ≤ ?z›*) p_antitone (*‹?x ≤ ?y ⟹ - ?y ≤ - ?x›*) pseudo_complement (*‹(?x ⊓ ?y = bot) = (?x ≤ - ?y)›*) by blast qed lemma epm_12: assumes "vector v" shows "(w ⊓ -(prim_EP w v e)) ⊓ prim_E w v e = bot" proof (-) (*goal: ‹w ⊓ - prim_EP w v e ⊓ prim_E w v e = bot›*) have "prim_E w v e ≤ prim_EP w v e" by (metis assms (*‹vector (v::'a)›*) comp_isotone (*‹⟦(?x::'a) ≤ (?y::'a); (?w::'a) ≤ (?z::'a)⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) inf.sup_left_isotone (*‹(?y::'a) ≤ (?x::'a) ⟹ ?y ⊓ (?z::'a) ≤ ?x ⊓ ?z›*) inf.sup_right_isotone (*‹(?y::'a) ≤ (?x::'a) ⟹ (?z::'a) ⊓ ?y ≤ ?z ⊓ ?x›*) order.refl (*‹(?a::'a) ≤ ?a›*) top_greatest (*‹(?x::'a) ≤ top›*) vector_conv_compl (*‹vector (?v::'a) ⟹ covector (- ?v⇧T)›*)) thus "?thesis" (*goal: ‹(w::'a::type) ⊓ - prim_EP w (v::'a::type) (e::'a::type) ⊓ prim_E w v e = bot›*) using inf_le2 (*‹?x ⊓ ?y ≤ ?y›*) order_trans (*‹⟦?x ≤ ?y; ?y ≤ ?z⟧ ⟹ ?x ≤ ?z›*) p_antitone (*‹?x ≤ ?y ⟹ - ?y ≤ - ?x›*) pseudo_complement (*‹(?x ⊓ ?y = bot) = (?x ≤ - ?y)›*) by blast qed lemma epm_13: assumes "vector v" shows "prim_P w v e ⊓ prim_E w v e = bot" proof (-) (*goal: ‹prim_P w v e ⊓ prim_E w v e = bot›*) have "prim_P w v e ⊓ prim_E w v e ≤ -v * -v⇧T ⊓ --v * -v⇧T" by (meson dual_order.trans (*‹⟦?b ≤ ?a; ?c ≤ ?b⟧ ⟹ ?c ≤ ?a›*) inf.cobounded1 (*‹?a ⊓ ?b ≤ ?a›*) inf.sup_mono (*‹⟦?c ≤ ?a; ?d ≤ ?b⟧ ⟹ ?c ⊓ ?d ≤ ?a ⊓ ?b›*) inf_le2 (*‹?x ⊓ ?y ≤ ?y›*)) also (*calculation: ‹prim_P w v e ⊓ prim_E w v e ≤ - v * - v⇧T ⊓ - - v * - v⇧T›*) have "... ≤ -v * top ⊓ --v * top" using inf.sup_mono (*‹⟦(?c::'a) ≤ (?a::'a); (?d::'a) ≤ (?b::'a)⟧ ⟹ ?c ⊓ ?d ≤ ?a ⊓ ?b›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) top_greatest (*‹?x ≤ top›*) by blast also (*calculation: ‹prim_P (w::'a::type) (v::'a::type) (e::'a::type) ⊓ prim_E w v e ≤ - v * top ⊓ - - v * top›*) have "... = bot" using assms (*‹vector v›*) inf_compl_bot (*‹(?x::?'a::boolean_algebra) ⊓ - ?x = bot›*) vector_complement_closed (*‹vector (?x::'a) ⟹ vector (- ?x)›*) by auto finally (*calculation: ‹prim_P w v e ⊓ prim_E w v e ≤ bot›*) show "?thesis" (*goal: ‹prim_P w v e ⊓ prim_E w v e = bot›*) by (simp add: le_iff_inf (*‹(?x ≤ ?y) = (?x ⊓ ?y = ?x)›*)) qed text ‹ The following lemmas show that the relation characterising the edge across the cut is an arc. › lemma arc_edge_1: assumes "e ≤ v * -v⇧T ⊓ g" and "vector v" and "v⇧T = r⇧T * t⇧⋆" and "t ≤ g" and "r⇧T * g⇧⋆ ≤ r⇧T * w⇧⋆" shows "top * e ≤ v⇧T * w⇧⋆" proof (-) (*goal: ‹top * e ≤ v⇧T * w⇧⋆›*) have "top * e ≤ top * (v * -v⇧T ⊓ g)" using assms(1) (*‹(e::'a::type) ≤ (v::'a::type) * - v⇧T ⊓ (g::'a::type)›*) mult_right_isotone (*‹(?x::'a::type) ≤ (?y::'a::type) ⟹ (?z::'a::type) * ?x ≤ ?z * ?y›*) by auto also (*calculation: ‹top * e ≤ top * (v * - v⇧T ⊓ g)›*) have "... ≤ top * (v * top ⊓ g)" using inf.sup_right_isotone (*‹?y ≤ ?x ⟹ ?z ⊓ ?y ≤ ?z ⊓ ?x›*) inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) top_greatest (*‹?x ≤ top›*) by presburger also (*calculation: ‹top * (e::'a) ≤ top * ((v::'a) * top ⊓ (g::'a))›*) have "... = v⇧T * g" by (metis assms( (*‹vector v›*) 2) covector_inf_comp_3 (*‹vector ?x ⟹ (?y ⊓ ?x⇧T) * ?z = ?y * (?x ⊓ ?z)›*) inf_top.left_neutral (*‹top ⊓ ?a = ?a›*)) also (*calculation: ‹top * (e::'a) ≤ (v::'a)⇧T * (g::'a)›*) have "... = r⇧T * t⇧⋆ * g" by (simp add: assms( (*‹v⇧T = r⇧T * t⇧⋆›*) 3)) also (*calculation: ‹top * e ≤ r⇧T * t⇧⋆ * g›*) have "... ≤ r⇧T * g⇧⋆ * g" by (simp add: assms( (*‹t ≤ g›*) 4) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) also (*calculation: ‹top * e ≤ r⇧T * g⇧⋆ * g›*) have "... ≤ r⇧T * g⇧⋆" by (simp add: mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star.right_plus_below_circ (*‹?x⇧⋆ * ?x ≤ ?x⇧⋆›*)) also (*calculation: ‹top * e ≤ r⇧T * g⇧⋆›*) have "... ≤ r⇧T * w⇧⋆" by (simp add: assms( (*‹r⇧T * g⇧⋆ ≤ r⇧T * w⇧⋆›*) 5)) also (*calculation: ‹top * e ≤ r⇧T * w⇧⋆›*) have "... ≤ v⇧T * w⇧⋆" by (metis assms( (*‹(v::'a)⇧T = (r::'a)⇧T * (t::'a)⇧⋆›*) 3) mult_left_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x * (?z::'a) ≤ ?y * ?z›*) mult_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*) mult_1_right (*‹(?a::'a) * (1::'a) = ?a›*) star.circ_reflexive (*‹reflexive ((?x::'a)⇧⋆)›*)) finally (*calculation: ‹top * e ≤ v⇧T * w⇧⋆›*) show "?thesis" (*goal: ‹top * e ≤ v⇧T * w⇧⋆›*) . qed lemma arc_edge_2: assumes "e ≤ v * -v⇧T ⊓ g" and "vector v" and "v⇧T = r⇧T * t⇧⋆" and "t ≤ g" and "r⇧T * g⇧⋆ ≤ r⇧T * w⇧⋆" and "w * v ≤ v" and "injective w" shows "top * e * w⇧T⇧⋆ ≤ v⇧T * w⇧⋆" proof (-) (*goal: ‹top * e * w⇧T⇧⋆ ≤ v⇧T * w⇧⋆›*) have 1: "top * e ≤ v⇧T * w⇧⋆" using assms(1-5) (*‹e ≤ v * - v⇧T ⊓ g› ‹vector v› ‹v⇧T = r⇧T * t⇧⋆› ‹(t::'a) ≤ (g::'a)› ‹r⇧T * g⇧⋆ ≤ r⇧T * w⇧⋆›*) arc_edge_1 (*‹⟦(?e::'a::type) ≤ (?v::'a::type) * - ?v⇧T ⊓ (?g::'a::type); vector ?v; ?v⇧T = (?r::'a::type)⇧T * (?t::'a::type)⇧⋆; ?t ≤ ?g; ?r⇧T * ?g⇧⋆ ≤ ?r⇧T * (?w::'a::type)⇧⋆⟧ ⟹ top * ?e ≤ ?v⇧T * ?w⇧⋆›*) by blast have "v⇧T * w⇧⋆ * w⇧T = v⇧T * w⇧T ⊔ v⇧T * w⁺ * w⇧T" by (metis mult_assoc (*‹(?a::'a) * (?b::'a) * (?c::'a) = ?a * (?b * ?c)›*) mult_left_dist_sup (*‹(?x::'a) * ((?y::'a) ⊔ (?z::'a)) = ?x * ?y ⊔ ?x * ?z›*) star.circ_loop_fixpoint (*‹(?y::'a) * (?y⇧⋆ * (?z::'a)) ⊔ ?z = ?y⇧⋆ * ?z›*) sup_commute (*‹(?x::'a) ⊔ (?y::'a) = ?y ⊔ ?x›*)) also (*calculation: ‹v⇧T * w⇧⋆ * w⇧T = v⇧T * w⇧T ⊔ v⇧T * w⁺ * w⇧T›*) have "... ≤ v⇧T ⊔ v⇧T * w⁺ * w⇧T" by (metis assms( (*‹w * v ≤ v›*) 6) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) sup_left_isotone (*‹?x ≤ ?y ⟹ ?x ⊔ ?z ≤ ?y ⊔ ?z›*)) also (*calculation: ‹v⇧T * w⇧⋆ * w⇧T ≤ v⇧T ⊔ v⇧T * w⁺ * w⇧T›*) have "... = v⇧T ⊔ v⇧T * w⇧⋆ * (w * w⇧T)" by (metis mult_assoc (*‹(?a::'a) * (?b::'a) * (?c::'a) = ?a * (?b * ?c)›*) star_plus (*‹(?y::'a)⇧⋆ * ?y = ?y⁺›*)) also (*calculation: ‹v⇧T * w⇧⋆ * w⇧T ≤ v⇧T ⊔ v⇧T * w⇧⋆ * (w * w⇧T)›*) have "... ≤ v⇧T ⊔ v⇧T * w⇧⋆" by (metis assms( (*‹injective (w::'a)›*) 7) mult_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*) mult_1_right (*‹(?a::'a) * (1::'a) = ?a›*) sup_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) ⊔ ?x ≤ ?z ⊔ ?y›*)) also (*calculation: ‹(v::'a::type)⇧T * (w::'a::type)⇧⋆ * w⇧T ≤ v⇧T ⊔ v⇧T * w⇧⋆›*) have "... = v⇧T * w⇧⋆" by (metis star.circ_back_loop_fixpoint (*‹?z * ?y⇧⋆ * ?y ⊔ ?z = ?z * ?y⇧⋆›*) sup_absorb2 (*‹?x ≤ ?y ⟹ ?x ⊔ ?y = ?y›*) sup_ge2 (*‹?y ≤ ?x ⊔ ?y›*)) finally (*calculation: ‹v⇧T * w⇧⋆ * w⇧T ≤ v⇧T * w⇧⋆›*) show "?thesis" (*goal: ‹top * e * w⇧T⇧⋆ ≤ v⇧T * w⇧⋆›*) using "1" (*‹top * e ≤ v⇧T * w⇧⋆›*) star_right_induct (*‹(?z::'a) ⊔ (?x::'a) * (?y::'a) ≤ ?x ⟶ ?z * ?y⇧⋆ ≤ ?x›*) by auto qed lemma arc_edge_3: assumes "e ≤ v * -v⇧T ⊓ g" and "vector v" and "v⇧T = r⇧T * t⇧⋆" and "t ≤ g" and "r⇧T * g⇧⋆ ≤ r⇧T * w⇧⋆" and "w * v ≤ v" and "injective w" and "prim_E w v e = bot" shows "e = bot" proof (-) (*goal: ‹e = bot›*) have "bot = prim_E w v e" by (simp add: assms( (*‹prim_E (w::'a) (v::'a) (e::'a) = bot›*) 8)) also (*calculation: ‹bot = prim_E w v e›*) have "... = w ⊓ --v * top ⊓ top * -v⇧T ⊓ top * e * w⇧T⇧⋆" by (metis assms( (*‹vector v›*) 2) comp_inf_covector (*‹?x * (?y ⊓ top * ?z) = ?x * ?y ⊓ top * ?z›*) inf.assoc (*‹?a ⊓ ?b ⊓ ?c = ?a ⊓ (?b ⊓ ?c)›*) inf_top.left_neutral (*‹top ⊓ ?a = ?a›*) vector_conv_compl (*‹vector ?v ⟹ covector (- ?v⇧T)›*)) also (*calculation: ‹bot = w ⊓ - - v * top ⊓ top * - v⇧T ⊓ top * e * w⇧T⇧⋆›*) have "... = w ⊓ top * e * w⇧T⇧⋆ ⊓ -v⇧T ⊓ --v" using assms(2) (*‹vector (v::'a)›*) inf.assoc (*‹?a ⊓ ?b ⊓ ?c = ?a ⊓ (?b ⊓ ?c)›*) inf.commute (*‹?a ⊓ ?b = ?b ⊓ ?a›*) vector_conv_compl (*‹vector ?v ⟹ covector (- ?v⇧T)›*) vector_complement_closed (*‹vector ?x ⟹ vector (- ?x)›*) by (simp add: inf_assoc (*‹?x ⊓ ?y ⊓ ?z = ?x ⊓ (?y ⊓ ?z)›*)) finally (*calculation: ‹bot = w ⊓ top * e * w⇧T⇧⋆ ⊓ - v⇧T ⊓ - - v›*) have 1: "w ⊓ top * e * w⇧T⇧⋆ ⊓ -v⇧T ≤ -v" using shunting_1_pp (*‹(?x ≤ - - ?y) = (?x ⊓ - ?y = bot)›*) by force have "w⇧⋆ * e⇧T * top = (top * e * w⇧T⇧⋆)⇧T" by (simp add: conv_star_commute (*‹(?x::'a)⇧⋆⇧T = ?x⇧T⇧⋆›*) comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*) conv_dist_comp (*‹((?x::'a) * (?y::'a))⇧T = ?y⇧T * ?x⇧T›*)) also (*calculation: ‹(w::'a::type)⇧⋆ * (e::'a::type)⇧T * top = (top * e * w⇧T⇧⋆)⇧T›*) have "... ≤ (v⇧T * w⇧⋆)⇧T" using assms(1-7) (*‹(e::'a::type) ≤ (v::'a::type) * - v⇧T ⊓ (g::'a::type)› ‹vector (v::'a)› ‹v⇧T = r⇧T * t⇧⋆› ‹t ≤ g› ‹r⇧T * g⇧⋆ ≤ r⇧T * w⇧⋆› ‹(w::'a) * (v::'a) ≤ v› ‹injective w›*) arc_edge_2 (*‹⟦?e ≤ ?v * - ?v⇧T ⊓ ?g; vector ?v; ?v⇧T = ?r⇧T * ?t⇧⋆; ?t ≤ ?g; ?r⇧T * ?g⇧⋆ ≤ ?r⇧T * ?w⇧⋆; ?w * ?v ≤ ?v; injective ?w⟧ ⟹ top * ?e * ?w⇧T⇧⋆ ≤ ?v⇧T * ?w⇧⋆›*) by (simp add: conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*)) also (*calculation: ‹w⇧⋆ * e⇧T * top ≤ (v⇧T * w⇧⋆)⇧T›*) have "... = w⇧T⇧⋆ * v" by (simp add: conv_star_commute (*‹(?x::'a)⇧⋆⇧T = ?x⇧T⇧⋆›*) conv_dist_comp (*‹((?x::'a) * (?y::'a))⇧T = ?y⇧T * ?x⇧T›*)) finally (*calculation: ‹w⇧⋆ * e⇧T * top ≤ w⇧T⇧⋆ * v›*) have 2: "w⇧⋆ * e⇧T * top ≤ w⇧T⇧⋆ * v" . have "(w⇧T ⊓ w⇧⋆ * e⇧T * top)⇧T * -v = (w ⊓ top * e * w⇧T⇧⋆) * -v" by (simp add: conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹(w⇧T ⊓ w⇧⋆ * e⇧T * top)⇧T * - v = (w ⊓ top * e * w⇧T⇧⋆) * - v›*) have "... = (w ⊓ top * e * w⇧T⇧⋆ ⊓ -v⇧T) * top" by (metis assms( (*‹vector v›*) 2) conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) covector_inf_comp_3 (*‹vector ?x ⟹ (?y ⊓ ?x⇧T) * ?z = ?y * (?x ⊓ ?z)›*) inf_top.right_neutral (*‹?a ⊓ top = ?a›*) vector_complement_closed (*‹vector ?x ⟹ vector (- ?x)›*)) also (*calculation: ‹(w⇧T ⊓ w⇧⋆ * e⇧T * top)⇧T * - v = (w ⊓ top * e * w⇧T⇧⋆ ⊓ - v⇧T) * top›*) have "... ≤ -v * top" using "1" (*‹w ⊓ top * e * w⇧T⇧⋆ ⊓ - v⇧T ≤ - v›*) by (simp add: comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*)) also (*calculation: ‹(w⇧T ⊓ w⇧⋆ * e⇧T * top)⇧T * - v ≤ - v * top›*) have "... = -v" using assms(2) (*‹vector v›*) vector_complement_closed (*‹vector ?x ⟹ vector (- ?x)›*) by auto finally (*calculation: ‹(w⇧T ⊓ w⇧⋆ * e⇧T * top)⇧T * - v ≤ - v›*) have "(w⇧T ⊓ w⇧⋆ * e⇧T * top) * --v ≤ --v" using p_antitone_iff (*‹(?x ≤ - ?y) = (?y ≤ - ?x)›*) schroeder_3_p (*‹(?x * ?y ≤ - ?z) = (?x⇧T * ?z ≤ - ?y)›*) by auto hence "w⇧⋆ * e⇧T * top ⊓ w⇧T * --v ≤ --v" by (simp add: inf_vector_comp (*‹((?x::'a) ⊓ (?y::'a) * top) * (?z::'a) = ?y * top ⊓ ?x * ?z›*)) hence 3: "w⇧T * --v ≤ --v ⊔ -(w⇧⋆ * e⇧T * top)" by (simp add: inf.commute (*‹(?a::'a) ⊓ (?b::'a) = ?b ⊓ ?a›*) shunting_p (*‹((?x::'a) ⊓ (?y::'a) ≤ - (?z::'a)) = (?x ≤ - ?z ⊔ - ?y)›*)) have "w⇧T * -(w⇧⋆ * e⇧T * top) ≤ -(w⇧⋆ * e⇧T * top)" by (metis mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) p_antitone (*‹?x ≤ ?y ⟹ - ?y ≤ - ?x›*) p_antitone_iff (*‹(?x ≤ - ?y) = (?y ≤ - ?x)›*) schroeder_3_p (*‹(?x * ?y ≤ - ?z) = (?x⇧T * ?z ≤ - ?y)›*) star.circ_loop_fixpoint (*‹?y * (?y⇧⋆ * ?z) ⊔ ?z = ?y⇧⋆ * ?z›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*) sup_right_divisibility (*‹(?x ≤ ?y) = (∃z. z ⊔ ?x = ?y)›*)) also (*calculation: ‹w⇧T * - (w⇧⋆ * e⇧T * top) ≤ - (w⇧⋆ * e⇧T * top)›*) have "... ≤ --v ⊔ -(w⇧⋆ * e⇧T * top)" by simp finally (*calculation: ‹(w::'a)⇧T * - (w⇧⋆ * (e::'a)⇧T * top) ≤ - - (v::'a) ⊔ - (w⇧⋆ * e⇧T * top)›*) have "w⇧T * (--v ⊔ -(w⇧⋆ * e⇧T * top)) ≤ --v ⊔ -(w⇧⋆ * e⇧T * top)" using "3" (*‹(w::'a::type)⇧T * - - (v::'a::type) ≤ - - v ⊔ - (w⇧⋆ * (e::'a::type)⇧T * top)›*) by (simp add: mult_left_dist_sup (*‹?x * (?y ⊔ ?z) = ?x * ?y ⊔ ?x * ?z›*)) hence "w⇧T⇧⋆ * (--v ⊔ -(w⇧⋆ * e⇧T * top)) ≤ --v ⊔ -(w⇧⋆ * e⇧T * top)" using star_left_induct_mult_iff (*‹(?x * ?y ≤ ?y) = (?x⇧⋆ * ?y ≤ ?y)›*) by blast hence "w⇧T⇧⋆ * --v ≤ --v ⊔ -(w⇧⋆ * e⇧T * top)" by (simp add: semiring.distrib_left (*‹?a * (?b ⊔ ?c) = ?a * ?b ⊔ ?a * ?c›*)) hence "w⇧⋆ * e⇧T * top ⊓ w⇧T⇧⋆ * --v ≤ --v" by (simp add: inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) shunting_p (*‹(?x ⊓ ?y ≤ - ?z) = (?x ≤ - ?z ⊔ - ?y)›*)) hence "w⇧⋆ * e⇧T * top ≤ --v" using "2" (*‹w⇧⋆ * e⇧T * top ≤ w⇧T⇧⋆ * v›*) by (metis inf.absorb1 (*‹?a ≤ ?b ⟹ ?a ⊓ ?b = ?a›*) p_antitone_iff (*‹(?x ≤ - ?y) = (?y ≤ - ?x)›*) p_comp_pp (*‹- (?x * - - ?y) = - (?x * ?y)›*) vector_export_comp (*‹(?x * top ⊓ ?y) * ?z = ?x * top ⊓ ?y * ?z›*)) hence 4: "e⇧T * top ≤ --v" by (metis mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) star.circ_loop_fixpoint (*‹?y * (?y⇧⋆ * ?z) ⊔ ?z = ?y⇧⋆ * ?z›*) sup.bounded_iff (*‹(?b ⊔ ?c ≤ ?a) = (?b ≤ ?a ∧ ?c ≤ ?a)›*)) have "e⇧T * top ≤ (v * -v⇧T)⇧T * top" using assms(1) (*‹e ≤ v * - v⇧T ⊓ g›*) comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) by auto also (*calculation: ‹e⇧T * top ≤ (v * - v⇧T)⇧T * top›*) have "... ≤ -v * top" by (simp add: conv_complement (*‹(- (?x::'a))⇧T = - ?x⇧T›*) conv_dist_comp (*‹((?x::'a) * (?y::'a))⇧T = ?y⇧T * ?x⇧T›*) mult_assoc (*‹(?a::'a) * (?b::'a) * (?c::'a) = ?a * (?b * ?c)›*) mult_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*)) also (*calculation: ‹(e::'a)⇧T * top ≤ - (v::'a) * top›*) have "... = -v" using assms(2) (*‹vector v›*) vector_complement_closed (*‹vector (?x::'a::type) ⟹ vector (- ?x)›*) by auto finally (*calculation: ‹(e::'a)⇧T * top ≤ - (v::'a)›*) have "e⇧T * top ≤ bot" using "4" (*‹e⇧T * top ≤ - - v›*) shunting_1_pp (*‹(?x ≤ - - ?y) = (?x ⊓ - ?y = bot)›*) by auto hence "e⇧T = bot" using order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*) bot_least (*‹bot ≤ ?a›*) top_right_mult_increasing (*‹?x ≤ ?x * top›*) by blast thus "?thesis" (*goal: ‹e = bot›*) using conv_bot (*‹symmetric bot›*) by fastforce qed lemma arc_edge_4: assumes "e ≤ v * -v⇧T ⊓ g" and "vector v" and "v⇧T = r⇧T * t⇧⋆" and "t ≤ g" and "r⇧T * g⇧⋆ ≤ r⇧T * w⇧⋆" and "arc e" shows "top * prim_E w v e * top = top" proof (-) (*goal: ‹times_top_class.total (top * prim_E w v e)›*) have "--v⇧T * w = (--v⇧T * w ⊓ -v⇧T) ⊔ (--v⇧T * w ⊓ --v⇧T)" by (simp add: maddux_3_11_pp (*‹?x ⊓ - ?y ⊔ ?x ⊓ - - ?y = ?x›*)) also (*calculation: ‹- - v⇧T * w = - - v⇧T * w ⊓ - v⇧T ⊔ - - v⇧T * w ⊓ - - v⇧T›*) have "... ≤ (--v⇧T * w ⊓ -v⇧T) ⊔ --v⇧T" using sup_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊔ ?x ≤ ?z ⊔ ?y›*) by auto also (*calculation: ‹- - v⇧T * w ≤ - - v⇧T * w ⊓ - v⇧T ⊔ - - v⇧T›*) have "... = --v⇧T * (w ⊓ -v⇧T) ⊔ --v⇧T" using assms(2) (*‹vector v›*) covector_comp_inf (*‹covector ?z ⟹ ?x * (?y ⊓ ?z) = ?x * ?y ⊓ ?z›*) covector_complement_closed (*‹covector ?x ⟹ covector (- ?x)›*) vector_conv_covector (*‹vector ?v = covector (?v⇧T)›*) by auto also (*calculation: ‹- - v⇧T * w ≤ - - v⇧T * (w ⊓ - v⇧T) ⊔ - - v⇧T›*) have "... ≤ --v⇧T * (w ⊓ -v⇧T) * w⇧⋆ ⊔ --v⇧T" by (metis star.circ_back_loop_fixpoint (*‹?z * ?y⇧⋆ * ?y ⊔ ?z = ?z * ?y⇧⋆›*) sup.cobounded2 (*‹?b ≤ ?a ⊔ ?b›*) sup_left_isotone (*‹?x ≤ ?y ⟹ ?x ⊔ ?z ≤ ?y ⊔ ?z›*)) finally (*calculation: ‹- - v⇧T * w ≤ - - v⇧T * (w ⊓ - v⇧T) * w⇧⋆ ⊔ - - v⇧T›*) have 1: "--v⇧T * w ≤ --v⇧T * (w ⊓ -v⇧T) * w⇧⋆ ⊔ --v⇧T" . have "--v⇧T * (w ⊓ -v⇧T) * w⇧⋆ * w ≤ --v⇧T * (w ⊓ -v⇧T) * w⇧⋆ ⊔ --v⇧T" by (simp add: le_supI1 (*‹?x ≤ ?a ⟹ ?x ≤ ?a ⊔ ?b›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star.circ_plus_same (*‹?x⇧⋆ * ?x = ?x⁺›*) star.left_plus_below_circ (*‹?x⁺ ≤ ?x⇧⋆›*)) hence 2: "(--v⇧T * (w ⊓ -v⇧T) * w⇧⋆ ⊔ --v⇧T) * w ≤ --v⇧T * (w ⊓ -v⇧T) * w⇧⋆ ⊔ --v⇧T" using "1" (*‹- - v⇧T * w ≤ - - v⇧T * (w ⊓ - v⇧T) * w⇧⋆ ⊔ - - v⇧T›*) by (simp add: inf.orderE (*‹⟦?a ≤ ?b; ?a = ?a ⊓ ?b ⟹ ?thesis⟧ ⟹ ?thesis›*) mult_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*)) have "v⇧T ≤ --v⇧T * (w ⊓ -v⇧T) * w⇧⋆ ⊔ --v⇧T" by (simp add: pp_increasing (*‹?x ≤ - - ?x›*) sup.coboundedI2 (*‹?c ≤ ?b ⟹ ?c ≤ ?a ⊔ ?b›*)) hence "v⇧T * w⇧⋆ ≤ --v⇧T * (w ⊓ -v⇧T) * w⇧⋆ ⊔ --v⇧T" using "2" (*‹(- - v⇧T * (w ⊓ - v⇧T) * w⇧⋆ ⊔ - - v⇧T) * w ≤ - - v⇧T * (w ⊓ - v⇧T) * w⇧⋆ ⊔ - - v⇧T›*) by (simp add: star_right_induct (*‹?z ⊔ ?x * ?y ≤ ?x ⟶ ?z * ?y⇧⋆ ≤ ?x›*)) hence 3: "-v⇧T ⊓ v⇧T * w⇧⋆ ≤ --v⇧T * (w ⊓ -v⇧T) * w⇧⋆" by (metis inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) shunting_var_p (*‹(?x ⊓ - ?y ≤ ?z) = (?x ≤ ?z ⊔ - - ?y)›*)) have "top * e = top * e ⊓ v⇧T * w⇧⋆" by (meson assms( (*‹e ≤ v * - v⇧T ⊓ g› ‹vector v› ‹v⇧T = r⇧T * t⇧⋆› ‹t ≤ g› ‹r⇧T * g⇧⋆ ≤ r⇧T * w⇧⋆›*) 1-5) arc_edge_1 (*‹⟦?e ≤ ?v * - ?v⇧T ⊓ ?g; vector ?v; ?v⇧T = ?r⇧T * ?t⇧⋆; ?t ≤ ?g; ?r⇧T * ?g⇧⋆ ≤ ?r⇧T * ?w⇧⋆⟧ ⟹ top * ?e ≤ ?v⇧T * ?w⇧⋆›*) inf.orderE (*‹⟦?a ≤ ?b; ?a = ?a ⊓ ?b ⟹ ?thesis⟧ ⟹ ?thesis›*)) also (*calculation: ‹top * e = top * e ⊓ v⇧T * w⇧⋆›*) have "... ≤ top * v * -v⇧T ⊓ v⇧T * w⇧⋆" using assms(1) (*‹e ≤ v * - v⇧T ⊓ g›*) inf.sup_left_isotone (*‹?y ≤ ?x ⟹ ?y ⊓ ?z ≤ ?x ⊓ ?z›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) by auto also (*calculation: ‹top * (e::'a) ≤ top * (v::'a) * - v⇧T ⊓ v⇧T * (w::'a)⇧⋆›*) have "... ≤ top * -v⇧T ⊓ v⇧T * w⇧⋆" using inf.sup_left_isotone (*‹?y ≤ ?x ⟹ ?y ⊓ ?z ≤ ?x ⊓ ?z›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) top_greatest (*‹?x ≤ top›*) by blast also (*calculation: ‹top * (e::'a::type) ≤ top * - (v::'a::type)⇧T ⊓ v⇧T * (w::'a::type)⇧⋆›*) have "... = -v⇧T ⊓ v⇧T * w⇧⋆" by (simp add: assms( (*‹vector (v::'a)›*) 2) vector_conv_compl (*‹vector (?v::'a) ⟹ covector (- ?v⇧T)›*)) also (*calculation: ‹top * e ≤ - v⇧T ⊓ v⇧T * w⇧⋆›*) have "... ≤ --v⇧T * (w ⊓ -v⇧T) * w⇧⋆" using "3" (*‹- (v::'a::type)⇧T ⊓ v⇧T * (w::'a::type)⇧⋆ ≤ - - v⇧T * (w ⊓ - v⇧T) * w⇧⋆›*) by simp also (*calculation: ‹top * e ≤ - - v⇧T * (w ⊓ - v⇧T) * w⇧⋆›*) have "... = (top ⊓ (--v)⇧T) * (w ⊓ -v⇧T) * w⇧⋆" by (simp add: conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*)) also (*calculation: ‹top * e ≤ (top ⊓ (- - v)⇧T) * (w ⊓ - v⇧T) * w⇧⋆›*) have "... = top * (w ⊓ --v ⊓ -v⇧T) * w⇧⋆" using assms(2) (*‹vector v›*) covector_inf_comp_3 (*‹vector ?x ⟹ (?y ⊓ ?x⇧T) * ?z = ?y * (?x ⊓ ?z)›*) inf_assoc (*‹?x ⊓ ?y ⊓ ?z = ?x ⊓ (?y ⊓ ?z)›*) inf_left_commute (*‹(?x::'a::type) ⊓ ((?y::'a::type) ⊓ (?z::'a::type)) = ?y ⊓ (?x ⊓ ?z)›*) vector_complement_closed (*‹vector (?x::'a) ⟹ vector (- ?x)›*) by presburger also (*calculation: ‹top * e ≤ top * (w ⊓ - - v ⊓ - v⇧T) * w⇧⋆›*) have "... = top * (w ⊓ --v * -v⇧T) * w⇧⋆" by (metis assms( (*‹vector v›*) 2) vector_complement_closed (*‹vector ?x ⟹ vector (- ?x)›*) conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) inf_assoc (*‹?x ⊓ ?y ⊓ ?z = ?x ⊓ (?y ⊓ ?z)›*) vector_covector (*‹⟦vector ?v; vector ?w⟧ ⟹ ?v ⊓ ?w⇧T = ?v * ?w⇧T›*)) finally (*calculation: ‹top * e ≤ top * (w ⊓ - - v * - v⇧T) * w⇧⋆›*) have "top * (e⇧T * top)⇧T ≤ top * (w ⊓ --v * -v⇧T) * w⇧⋆" by (metis conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_top (*‹symmetric top›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) top_mult_top (*‹surjective top›*)) hence "top ≤ top * (w ⊓ --v * -v⇧T) * w⇧⋆ * (e⇧T * top)" using assms(6) (*‹arc e›*) shunt_bijective (*‹bijective ?z ⟹ (?x ≤ ?y * ?z) = (?x * ?z⇧T ≤ ?y)›*) by blast also (*calculation: ‹top ≤ top * ((w::'a) ⊓ - - (v::'a) * - v⇧T) * w⇧⋆ * ((e::'a)⇧T * top)›*) have "... = top * (w ⊓ --v * -v⇧T) * (top * e * w⇧⋆⇧T)⇧T" by (simp add: conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹top ≤ top * (w ⊓ - - v * - v⇧T) * (top * e * w⇧⋆⇧T)⇧T›*) have "... = top * (w ⊓ --v * -v⇧T ⊓ top * e * w⇧⋆⇧T) * top" by (simp add: comp_inf_vector_1 (*‹(?x ⊓ top * ?y) * ?z = ?x * (?z ⊓ (top * ?y)⇧T)›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) finally (*calculation: ‹top ≤ top * (w ⊓ - - v * - v⇧T ⊓ top * e * w⇧⋆⇧T) * top›*) show "?thesis" (*goal: ‹times_top_class.total (top * prim_E w v e)›*) by (simp add: conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) top_le (*‹top ≤ ?a ⟹ ?a = top›*)) qed lemma arc_edge_5: assumes "vector v" and "w * v ≤ v" and "injective w" and "arc e" shows "(prim_E w v e)⇧T * top * prim_E w v e ≤ 1" proof (-) (*goal: ‹coreflexive (prim_E (w::'a) (v::'a) (e::'a)⇧T * top * prim_E w v e)›*) have 1: "e⇧T * top * e ≤ 1" by (simp add: assms( (*‹arc e›*) 4) point_injective (*‹arc ?x ⟹ coreflexive (?x⇧T * top * ?x)›*)) have "prim_E w v e ≤ --v * top" by (simp add: inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) le_infI2 (*‹?b ≤ ?x ⟹ ?a ⊓ ?b ≤ ?x›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) hence 2: "prim_E w v e ≤ --v" by (simp add: assms( (*‹vector v›*) 1) vector_complement_closed (*‹vector ?x ⟹ vector (- ?x)›*)) have 3: "w * --v ≤ --v" by (simp add: assms( (*‹w * v ≤ v›*) 2) p_antitone (*‹?x ≤ ?y ⟹ - ?y ≤ - ?x›*) p_antitone_iff (*‹(?x ≤ - ?y) = (?y ≤ - ?x)›*)) have "w ⊓ top * prim_E w v e ≤ w * (prim_E w v e)⇧T * prim_E w v e" by (metis dedekind_2 (*‹?y * ?x ⊓ ?z ≤ (?y ⊓ ?z * ?x⇧T) * ?x›*) inf.commute (*‹?a ⊓ ?b = ?b ⊓ ?a›*) inf_top.left_neutral (*‹top ⊓ ?a = ?a›*)) also (*calculation: ‹w ⊓ top * prim_E w v e ≤ w * prim_E w v e⇧T * prim_E w v e›*) have "... ≤ w * w⇧T * prim_E w v e" by (simp add: conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) le_infI1 (*‹?a ≤ ?x ⟹ ?a ⊓ ?b ≤ ?x›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹w ⊓ top * prim_E w v e ≤ w * w⇧T * prim_E w v e›*) have "... ≤ prim_E w v e" by (metis assms( (*‹injective w›*) 3) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_left_one (*‹1 * ?x = ?x›*)) finally (*calculation: ‹(w::'a::type) ⊓ top * prim_E w (v::'a::type) (e::'a::type) ≤ prim_E w v e›*) have 4: "w ⊓ top * prim_E w v e ≤ prim_E w v e" . have "w⁺ ⊓ top * prim_E w v e = w⇧⋆ * (w ⊓ top * prim_E w v e)" by (simp add: comp_inf_covector (*‹(?x::'a) * ((?y::'a) ⊓ top * (?z::'a)) = ?x * ?y ⊓ top * ?z›*) star_plus (*‹(?y::'a)⇧⋆ * ?y = ?y⁺›*)) also (*calculation: ‹w⁺ ⊓ top * prim_E w v e = w⇧⋆ * (w ⊓ top * prim_E w v e)›*) have "... ≤ w⇧⋆ * prim_E w v e" using "4" (*‹w ⊓ top * prim_E w v e ≤ prim_E w v e›*) by (simp add: mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹w⁺ ⊓ top * prim_E w v e ≤ w⇧⋆ * prim_E w v e›*) have "... ≤ --v" using "2" (*‹prim_E w v e ≤ - - v›*) "3" (*‹(w::'a) * - - (v::'a) ≤ - - v›*) star_left_induct (*‹(?z::'a) ⊔ (?y::'a) * (?x::'a) ≤ ?x ⟶ ?y⇧⋆ * ?z ≤ ?x›*) sup.bounded_iff (*‹(?b ⊔ ?c ≤ ?a) = (?b ≤ ?a ∧ ?c ≤ ?a)›*) by blast finally (*calculation: ‹w⁺ ⊓ top * prim_E w v e ≤ - - v›*) have 5: "w⁺ ⊓ top * prim_E w v e ⊓ -v = bot" using shunting_1_pp (*‹(?x ≤ - - ?y) = (?x ⊓ - ?y = bot)›*) by blast hence 6: "w⁺⇧T ⊓ (prim_E w v e)⇧T * top ⊓ -v⇧T = bot" using conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) conv_dist_comp (*‹((?x::'a) * (?y::'a))⇧T = ?y⇧T * ?x⇧T›*) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) conv_top (*‹symmetric top›*) conv_bot (*‹symmetric bot›*) by force have "(prim_E w v e)⇧T * top * prim_E w v e ≤ (top * e * w⇧T⇧⋆)⇧T * top * (top * e * w⇧T⇧⋆)" by (simp add: conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) mult_isotone (*‹⟦?w ≤ ?y; ?x ≤ ?z⟧ ⟹ ?w * ?x ≤ ?y * ?z›*)) also (*calculation: ‹prim_E w v e⇧T * top * prim_E w v e ≤ (top * e * w⇧T⇧⋆)⇧T * top * (top * e * w⇧T⇧⋆)›*) have "... = w⇧⋆ * e⇧T * top * e * w⇧T⇧⋆" by (metis conv_star_commute (*‹(?x::'a)⇧⋆⇧T = ?x⇧T⇧⋆›*) conv_dist_comp (*‹((?x::'a) * (?y::'a))⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹(?x::'a)⇧T⇧T = ?x›*) conv_top (*‹symmetric top›*) mult_assoc (*‹(?a::'a) * (?b::'a) * (?c::'a) = ?a * (?b * ?c)›*) top_mult_top (*‹surjective top›*)) also (*calculation: ‹prim_E w v e⇧T * top * prim_E w v e ≤ w⇧⋆ * e⇧T * top * e * w⇧T⇧⋆›*) have "... ≤ w⇧⋆ * w⇧T⇧⋆" using "1" (*‹coreflexive ((e::'a)⇧T * top * e)›*) by (metis mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_1_right (*‹?a * 1 = ?a›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) also (*calculation: ‹prim_E w v e⇧T * top * prim_E w v e ≤ w⇧⋆ * w⇧T⇧⋆›*) have "... = w⇧⋆ ⊔ w⇧T⇧⋆" by (metis assms( (*‹injective w›*) 3) cancel_separate (*‹coreflexive (?x * ?y) ⟹ ?x⇧⋆ * ?y⇧⋆ ≤ ?x⇧⋆ ⊔ ?y⇧⋆›*) order.eq_iff (*‹(?a = ?b) = (?a ≤ ?b ∧ ?b ≤ ?a)›*) star.circ_sup_sub_sup_one_1 (*‹?x ⊔ ?y ≤ ?x⇧⋆ * (1 ⊔ ?y)›*) star.circ_plus_one (*‹?x⇧⋆ = 1 ⊔ ?x⇧⋆›*) star_involutive (*‹?x⇧⋆ = ?x⇧⋆⇧⋆›*)) also (*calculation: ‹prim_E w v e⇧T * top * prim_E w v e ≤ w⇧⋆ ⊔ w⇧T⇧⋆›*) have "... = w⁺ ⊔ w⇧T⁺ ⊔ 1" by (metis star.circ_plus_one (*‹?x⇧⋆ = 1 ⊔ ?x⇧⋆›*) star_left_unfold_equal (*‹1 ⊔ ?x⁺ = ?x⇧⋆›*) sup.assoc (*‹?a ⊔ ?b ⊔ ?c = ?a ⊔ (?b ⊔ ?c)›*) sup.commute (*‹?a ⊔ ?b = ?b ⊔ ?a›*)) finally (*calculation: ‹prim_E w v e⇧T * top * prim_E w v e ≤ w⁺ ⊔ w⇧T⁺ ⊔ 1›*) have 7: "(prim_E w v e)⇧T * top * prim_E w v e ≤ w⁺ ⊔ w⇧T⁺ ⊔ 1" . have "prim_E w v e ≤ --v * -v⇧T" by (simp add: le_infI1 (*‹?a ≤ ?x ⟹ ?a ⊓ ?b ≤ ?x›*)) also (*calculation: ‹prim_E w v e ≤ - - v * - v⇧T›*) have "... ≤ top * -v⇧T" by (simp add: mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) also (*calculation: ‹prim_E (w::'a) (v::'a) (e::'a) ≤ top * - v⇧T›*) have "... = -v⇧T" by (simp add: assms( (*‹vector v›*) 1) vector_conv_compl (*‹vector ?v ⟹ covector (- ?v⇧T)›*)) finally (*calculation: ‹prim_E (w::'a) (v::'a) (e::'a) ≤ - v⇧T›*) have 8: "prim_E w v e ≤ -v⇧T" . hence 9: "(prim_E w v e)⇧T ≤ -v" by (metis conv_complement (*‹(- (?x::'a::type))⇧T = - ?x⇧T›*) conv_involutive (*‹(?x::'a::type)⇧T⇧T = ?x›*) conv_isotone (*‹(?x::'a::type) ≤ (?y::'a::type) ⟹ ?x⇧T ≤ ?y⇧T›*)) have "(prim_E w v e)⇧T * top * prim_E w v e = (w⁺ ⊔ w⇧T⁺ ⊔ 1) ⊓ (prim_E w v e)⇧T * top * prim_E w v e" using "7" (*‹prim_E (w::'a) (v::'a) (e::'a)⇧T * top * prim_E w v e ≤ w⁺ ⊔ w⇧T⁺ ⊔ (1::'a)›*) by (simp add: inf.absorb_iff2 (*‹(?b ≤ ?a) = (?a ⊓ ?b = ?b)›*)) also (*calculation: ‹prim_E (w::'a) (v::'a) (e::'a)⇧T * top * prim_E w v e = (w⁺ ⊔ w⇧T⁺ ⊔ (1::'a)) ⊓ prim_E w v e⇧T * top * prim_E w v e›*) have "... = (1 ⊓ (prim_E w v e)⇧T * top * prim_E w v e) ⊔ (w⁺ ⊓ (prim_E w v e)⇧T * top * prim_E w v e) ⊔ (w⇧T⁺ ⊓ (prim_E w v e)⇧T * top * prim_E w v e)" using comp_inf.mult_right_dist_sup (*‹((?x::'a::type) ⊔ (?y::'a::type)) ⊓ (?z::'a::type) = ?x ⊓ ?z ⊔ ?y ⊓ ?z›*) sup_assoc (*‹?x ⊔ ?y ⊔ ?z = ?x ⊔ (?y ⊔ ?z)›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*) by auto also (*calculation: ‹prim_E w v e⇧T * top * prim_E w v e = 1 ⊓ prim_E w v e⇧T * top * prim_E w v e ⊔ w⁺ ⊓ prim_E w v e⇧T * top * prim_E w v e ⊔ w⇧T⁺ ⊓ prim_E w v e⇧T * top * prim_E w v e›*) have "... ≤ 1 ⊔ (w⁺ ⊓ (prim_E w v e)⇧T * top * prim_E w v e) ⊔ (w⇧T⁺ ⊓ (prim_E w v e)⇧T * top * prim_E w v e)" using inf_le1 (*‹?x ⊓ ?y ≤ ?x›*) sup_left_isotone (*‹?x ≤ ?y ⟹ ?x ⊔ ?z ≤ ?y ⊔ ?z›*) by blast also (*calculation: ‹prim_E w v e⇧T * top * prim_E w v e ≤ 1 ⊔ w⁺ ⊓ prim_E w v e⇧T * top * prim_E w v e ⊔ w⇧T⁺ ⊓ prim_E w v e⇧T * top * prim_E w v e›*) have "... ≤ 1 ⊔ (w⁺ ⊓ (prim_E w v e)⇧T * top * prim_E w v e) ⊔ (w⇧T⁺ ⊓ (prim_E w v e)⇧T * top * -v⇧T)" using "8" (*‹prim_E w v e ≤ - v⇧T›*) inf.sup_right_isotone (*‹?y ≤ ?x ⟹ ?z ⊓ ?y ≤ ?z ⊓ ?x›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) sup_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊔ ?x ≤ ?z ⊔ ?y›*) by blast also (*calculation: ‹prim_E w v e⇧T * top * prim_E w v e ≤ 1 ⊔ w⁺ ⊓ prim_E w v e⇧T * top * prim_E w v e ⊔ w⇧T⁺ ⊓ prim_E w v e⇧T * top * - v⇧T›*) have "... ≤ 1 ⊔ (w⁺ ⊓ -v * top * prim_E w v e) ⊔ (w⇧T⁺ ⊓ (prim_E w v e)⇧T * top * -v⇧T)" using "9" (*‹prim_E w v e⇧T ≤ - v›*) by (metis inf.sup_right_isotone (*‹?y ≤ ?x ⟹ ?z ⊓ ?y ≤ ?z ⊓ ?x›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) sup.commute (*‹?a ⊔ ?b = ?b ⊔ ?a›*) sup_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊔ ?x ≤ ?z ⊔ ?y›*)) also (*calculation: ‹prim_E w v e⇧T * top * prim_E w v e ≤ 1 ⊔ w⁺ ⊓ - v * top * prim_E w v e ⊔ w⇧T⁺ ⊓ prim_E w v e⇧T * top * - v⇧T›*) have "... = 1 ⊔ (w⁺ ⊓ -v * top ⊓ top * prim_E w v e) ⊔ (w⇧T⁺ ⊓ (prim_E w v e)⇧T * top ⊓ top * -v⇧T)" by (metis (no_types) vector_export_comp (*‹(?x * top ⊓ ?y) * ?z = ?x * top ⊓ ?y * ?z›*) inf_top_right (*‹?x ⊓ top = ?x›*) inf_assoc (*‹?x ⊓ ?y ⊓ ?z = ?x ⊓ (?y ⊓ ?z)›*)) also (*calculation: ‹prim_E w v e⇧T * top * prim_E w v e ≤ 1 ⊔ w⁺ ⊓ - v * top ⊓ top * prim_E w v e ⊔ w⇧T⁺ ⊓ prim_E w v e⇧T * top ⊓ top * - v⇧T›*) have "... = 1 ⊔ (w⁺ ⊓ -v ⊓ top * prim_E w v e) ⊔ (w⇧T⁺ ⊓ (prim_E w v e)⇧T * top ⊓ -v⇧T)" using assms(1) (*‹vector (v::'a)›*) vector_complement_closed (*‹vector ?x ⟹ vector (- ?x)›*) vector_conv_compl (*‹vector ?v ⟹ covector (- ?v⇧T)›*) by auto also (*calculation: ‹prim_E w v e⇧T * top * prim_E w v e ≤ 1 ⊔ w⁺ ⊓ - v ⊓ top * prim_E w v e ⊔ w⇧T⁺ ⊓ prim_E w v e⇧T * top ⊓ - v⇧T›*) have "... = 1" using "5" (*‹w⁺ ⊓ top * prim_E w v e ⊓ - v = bot›*) "6" (*‹w⁺⇧T ⊓ prim_E w v e⇧T * top ⊓ - v⇧T = bot›*) by (simp add: conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) inf.commute (*‹?a ⊓ ?b = ?b ⊓ ?a›*) inf_assoc (*‹?x ⊓ ?y ⊓ ?z = ?x ⊓ (?y ⊓ ?z)›*) star.circ_plus_same (*‹?x⇧⋆ * ?x = ?x⁺›*)) finally (*calculation: ‹coreflexive (prim_E w v e⇧T * top * prim_E w v e)›*) show "?thesis" (*goal: ‹coreflexive (prim_E (w::'a) (v::'a) (e::'a)⇧T * top * prim_E w v e)›*) . qed lemma arc_edge_6: assumes "vector v" and "w * v ≤ v" and "injective w" and "arc e" shows "prim_E w v e * top * (prim_E w v e)⇧T ≤ 1" proof (-) (*goal: ‹coreflexive (prim_E w v e * top * prim_E w v e⇧T)›*) have "prim_E w v e * 1 * (prim_E w v e)⇧T ≤ w * w⇧T" using comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) conv_order (*‹(?x ≤ ?y) = (?x⇧T ≤ ?y⇧T)›*) inf.coboundedI1 (*‹?a ≤ ?c ⟹ ?a ⊓ ?b ≤ ?c›*) mult_one_associative (*‹?x * 1 * ?y = ?x * ?y›*) by auto also (*calculation: ‹prim_E w v e * 1 * prim_E w v e⇧T ≤ w * w⇧T›*) have "... ≤ 1" by (simp add: assms( (*‹injective w›*) 3)) finally (*calculation: ‹coreflexive (prim_E w v e * 1 * prim_E w v e⇧T)›*) have 1: "prim_E w v e * 1 * (prim_E w v e)⇧T ≤ 1" . have "(prim_E w v e)⇧T * top * prim_E w v e ≤ 1" by (simp add: assms (*‹vector (v::'a::type)› ‹(w::'a::type) * (v::'a::type) ≤ v› ‹injective (w::'a::type)› ‹arc (e::'a::type)›*) arc_edge_5 (*‹⟦vector (?v::'a::type); (?w::'a::type) * ?v ≤ ?v; injective ?w; arc (?e::'a::type)⟧ ⟹ coreflexive (prim_E ?w ?v ?e⇧T * top * prim_E ?w ?v ?e)›*)) also (*calculation: ‹coreflexive (prim_E (w::'a) (v::'a) (e::'a)⇧T * top * prim_E w v e)›*) have "... ≤ --1" by (simp add: pp_increasing (*‹?x ≤ - - ?x›*)) finally (*calculation: ‹prim_E (w::'a) (v::'a) (e::'a)⇧T * top * prim_E w v e ≤ - - (1::'a)›*) have 2: "prim_E w v e * -1 * (prim_E w v e)⇧T ≤ bot" by (metis conv_involutive (*‹?x⇧T⇧T = ?x›*) regular_closed_bot (*‹regular bot›*) regular_dense_top (*‹⟦regular ?x; dense ?x⟧ ⟹ ?x = top›*) triple_schroeder_p (*‹(?x * ?y * ?z ≤ - ?w) = (?x⇧T * ?w * ?z⇧T ≤ - ?y)›*)) have "prim_E w v e * top * (prim_E w v e)⇧T = prim_E w v e * 1 * (prim_E w v e)⇧T ⊔ prim_E w v e * -1 * (prim_E w v e)⇧T" by (metis mult_left_dist_sup (*‹?x * (?y ⊔ ?z) = ?x * ?y ⊔ ?x * ?z›*) mult_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*) regular_complement_top (*‹regular ?x ⟹ ?x ⊔ - ?x = top›*) regular_one_closed (*‹regular 1›*)) also (*calculation: ‹prim_E w v e * top * prim_E w v e⇧T = prim_E w v e * 1 * prim_E w v e⇧T ⊔ prim_E w v e * - 1 * prim_E w v e⇧T›*) have "... ≤ 1" using "1" (*‹coreflexive (prim_E w v e * 1 * prim_E w v e⇧T)›*) "2" (*‹prim_E w v e * - 1 * prim_E w v e⇧T ≤ bot›*) by (simp add: bot_unique (*‹(?a ≤ bot) = (?a = bot)›*)) finally (*calculation: ‹coreflexive (prim_E w v e * top * prim_E w v e⇧T)›*) show "?thesis" (*goal: ‹coreflexive (prim_E w v e * top * prim_E w v e⇧T)›*) . qed lemma arc_edge: assumes "e ≤ v * -v⇧T ⊓ g" and "vector v" and "v⇧T = r⇧T * t⇧⋆" and "t ≤ g" and "r⇧T * g⇧⋆ ≤ r⇧T * w⇧⋆" and "w * v ≤ v" and "injective w" and "arc e" shows "arc (prim_E w v e)" proof (intro conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹injective (prim_E (w::'a::type) (v::'a::type) (e::'a::type) * top)› 2. ‹surjective (prim_E (w::'a::type) (v::'a::type) (e::'a::type) * top)› 3. ‹injective (prim_E (w::'a::type) (v::'a::type) (e::'a::type)⇧T * top)› 4. ‹surjective (prim_E (w::'a::type) (v::'a::type) (e::'a::type)⇧T * top)›*) have "prim_E w v e * top * (prim_E w v e)⇧T ≤ 1" using assms(2,6-8) (*‹vector v› ‹w * v ≤ v› ‹injective (w::'a)› ‹arc e›*) arc_edge_6 (*‹⟦vector ?v; ?w * ?v ≤ ?v; injective ?w; arc ?e⟧ ⟹ coreflexive (prim_E ?w ?v ?e * top * prim_E ?w ?v ?e⇧T)›*) by simp thus "injective (prim_E w v e * top)" by (metis conv_dist_comp (*‹((?x::'a::type) * (?y::'a::type))⇧T = ?y⇧T * ?x⇧T›*) conv_top (*‹symmetric top›*) mult_assoc (*‹(?a::'a::type) * (?b::'a::type) * (?c::'a::type) = ?a * (?b * ?c)›*) top_mult_top (*‹surjective top›*)) next (*goals: 1. ‹surjective (prim_E w v e * top)› 2. ‹injective (prim_E w v e⇧T * top)› 3. ‹surjective (prim_E w v e⇧T * top)›*) show "surjective (prim_E w v e * top)" using assms(1-5,8) (*‹(e::'a) ≤ (v::'a) * - v⇧T ⊓ (g::'a)› ‹vector v› ‹v⇧T = r⇧T * t⇧⋆› ‹t ≤ g› ‹(r::'a::type)⇧T * (g::'a::type)⇧⋆ ≤ r⇧T * (w::'a::type)⇧⋆› ‹arc (e::'a)›*) arc_edge_4 (*‹⟦?e ≤ ?v * - ?v⇧T ⊓ ?g; vector ?v; ?v⇧T = ?r⇧T * ?t⇧⋆; ?t ≤ ?g; ?r⇧T * ?g⇧⋆ ≤ ?r⇧T * ?w⇧⋆; arc ?e⟧ ⟹ times_top_class.total (top * prim_E ?w ?v ?e)›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) by simp next (*goals: 1. ‹injective (prim_E (w::'a) (v::'a) (e::'a)⇧T * top)› 2. ‹surjective (prim_E (w::'a) (v::'a) (e::'a)⇧T * top)›*) have "(prim_E w v e)⇧T * top * prim_E w v e ≤ 1" using assms(2,6-8) (*‹vector v› ‹w * v ≤ v› ‹injective w› ‹arc (e::'a)›*) arc_edge_5 (*‹⟦vector ?v; ?w * ?v ≤ ?v; injective ?w; arc ?e⟧ ⟹ coreflexive (prim_E ?w ?v ?e⇧T * top * prim_E ?w ?v ?e)›*) by simp thus "injective ((prim_E w v e)⇧T * top)" by (metis conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_top (*‹symmetric top›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) top_mult_top (*‹surjective top›*)) next (*goal: ‹surjective (prim_E w v e⇧T * top)›*) have "top * prim_E w v e * top = top" using assms(1-5,8) (*‹(e::'a) ≤ (v::'a) * - v⇧T ⊓ (g::'a)› ‹vector v› ‹v⇧T = r⇧T * t⇧⋆› ‹t ≤ g› ‹r⇧T * g⇧⋆ ≤ r⇧T * w⇧⋆› ‹arc e›*) arc_edge_4 (*‹⟦(?e::'a) ≤ (?v::'a) * - ?v⇧T ⊓ (?g::'a); vector ?v; ?v⇧T = (?r::'a)⇧T * (?t::'a)⇧⋆; ?t ≤ ?g; ?r⇧T * ?g⇧⋆ ≤ ?r⇧T * (?w::'a)⇧⋆; arc ?e⟧ ⟹ times_top_class.total (top * prim_E ?w ?v ?e)›*) by simp thus "surjective ((prim_E w v e)⇧T * top)" by (metis mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_top (*‹symmetric top›*)) qed subsubsection ‹Invariant implies Postcondition› text ‹ The lemmas in this section are used to show that the invariant implies the postcondition at the end of the algorithm. The following lemma shows that the nodes reachable in the graph are the same as those reachable in the constructed tree. › lemma span_post: assumes "regular v" and "vector v" and "v⇧T = r⇧T * t⇧⋆" and "v * -v⇧T ⊓ g = bot" and "t ≤ v * v⇧T ⊓ g" and "r⇧T * (v * v⇧T ⊓ g)⇧⋆ ≤ r⇧T * t⇧⋆" shows "v⇧T = r⇧T * g⇧⋆" proof (-) (*goal: ‹v⇧T = r⇧T * g⇧⋆›*) let ?vv = "v * v⇧T ⊓ g" have 1: "r⇧T ≤ v⇧T" using assms(3) (*‹v⇧T = r⇧T * t⇧⋆›*) mult_right_isotone (*‹(?x::'a::type) ≤ (?y::'a::type) ⟹ (?z::'a::type) * ?x ≤ ?z * ?y›*) mult_1_right (*‹?a * 1 = ?a›*) star.circ_reflexive (*‹reflexive (?x⇧⋆)›*) by fastforce have "v * top ⊓ g = (v * v⇧T ⊔ v * -v⇧T) ⊓ g" by (metis assms( (*‹regular v›*) 1) conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) mult_left_dist_sup (*‹?x * (?y ⊔ ?z) = ?x * ?y ⊔ ?x * ?z›*) regular_complement_top (*‹regular ?x ⟹ ?x ⊔ - ?x = top›*)) also (*calculation: ‹(v::'a) * top ⊓ (g::'a) = (v * v⇧T ⊔ v * - v⇧T) ⊓ g›*) have "... = ?vv ⊔ (v * -v⇧T ⊓ g)" by (simp add: inf_sup_distrib2 (*‹((?y::'a) ⊔ (?z::'a)) ⊓ (?x::'a) = ?y ⊓ ?x ⊔ ?z ⊓ ?x›*)) also (*calculation: ‹v * top ⊓ g = v * v⇧T ⊓ g ⊔ v * - v⇧T ⊓ g›*) have "... = ?vv" by (simp add: assms( (*‹v * - v⇧T ⊓ g = bot›*) 4)) finally (*calculation: ‹v * top ⊓ g = v * v⇧T ⊓ g›*) have 2: "v * top ⊓ g = ?vv" by simp have "r⇧T * ?vv⇧⋆ ≤ v⇧T * ?vv⇧⋆" using "1" (*‹(r::'a)⇧T ≤ (v::'a)⇧T›*) by (simp add: comp_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) also (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ ≤ v⇧T * (v * v⇧T ⊓ g)⇧⋆›*) have "... ≤ v⇧T * (v * v⇧T)⇧⋆" by (simp add: comp_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star.circ_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) also (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ ≤ v⇧T * (v * v⇧T)⇧⋆›*) have "... ≤ v⇧T" by (simp add: assms( (*‹vector v›*) 2) vector_star_1 (*‹vector ?x ⟹ ?x⇧T * (?x * ?x⇧T)⇧⋆ ≤ ?x⇧T›*)) finally (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ ≤ v⇧T›*) have "r⇧T * ?vv⇧⋆ ≤ v⇧T" by simp hence "r⇧T * ?vv⇧⋆ * g = (r⇧T * ?vv⇧⋆ ⊓ v⇧T) * g" by (simp add: inf.absorb1 (*‹?a ≤ ?b ⟹ ?a ⊓ ?b = ?a›*)) also (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * g = (r⇧T * (v * v⇧T ⊓ g)⇧⋆ ⊓ v⇧T) * g›*) have "... = r⇧T * ?vv⇧⋆ * (v * top ⊓ g)" by (simp add: assms( (*‹vector (v::'a::type)›*) 2) covector_inf_comp_3 (*‹vector (?x::'a::type) ⟹ ((?y::'a::type) ⊓ ?x⇧T) * (?z::'a::type) = ?y * (?x ⊓ ?z)›*)) also (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * g = r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (v * top ⊓ g)›*) have "... = r⇧T * ?vv⇧⋆ * ?vv" using "2" (*‹v * top ⊓ g = v * v⇧T ⊓ g›*) by simp also (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * g = r⇧T * (v * v⇧T ⊓ g)⇧⋆ * (v * v⇧T ⊓ g)›*) have "... ≤ r⇧T * ?vv⇧⋆" by (simp add: comp_associative (*‹(?x::'a::type) * (?y::'a::type) * (?z::'a::type) = ?x * (?y * ?z)›*) comp_right_isotone (*‹(?x::'a::type) ≤ (?y::'a::type) ⟹ (?z::'a::type) * ?x ≤ ?z * ?y›*) star.left_plus_below_circ (*‹(?x::'a::type)⁺ ≤ ?x⇧⋆›*) star_plus (*‹(?y::'a::type)⇧⋆ * ?y = ?y⁺›*)) finally (*calculation: ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ * g ≤ r⇧T * (v * v⇧T ⊓ g)⇧⋆›*) have "r⇧T ⊔ r⇧T * ?vv⇧⋆ * g ≤ r⇧T * ?vv⇧⋆" using star.circ_back_loop_prefixpoint (*‹?z * ?y⇧⋆ * ?y ⊔ ?z ≤ ?z * ?y⇧⋆›*) by auto hence "r⇧T * g⇧⋆ ≤ r⇧T * ?vv⇧⋆" using star_right_induct (*‹?z ⊔ ?x * ?y ≤ ?x ⟶ ?z * ?y⇧⋆ ≤ ?x›*) by blast hence "r⇧T * g⇧⋆ = r⇧T * ?vv⇧⋆" by (simp add: order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) also (*calculation: ‹r⇧T * g⇧⋆ = r⇧T * (v * v⇧T ⊓ g)⇧⋆›*) have "... = r⇧T * t⇧⋆" using assms(5,6) (*‹t ≤ v * v⇧T ⊓ g› ‹r⇧T * (v * v⇧T ⊓ g)⇧⋆ ≤ r⇧T * t⇧⋆›*) order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) by auto also (*calculation: ‹r⇧T * g⇧⋆ = r⇧T * t⇧⋆›*) have "... = v⇧T" by (simp add: assms( (*‹v⇧T = r⇧T * t⇧⋆›*) 3)) finally (*calculation: ‹r⇧T * g⇧⋆ = v⇧T›*) show "?thesis" (*goal: ‹v⇧T = r⇧T * g⇧⋆›*) by simp qed text ‹ The following lemma shows that the minimum spanning tree extending a tree is the same as the tree at the end of the algorithm. › lemma mst_post: assumes "vector r" and "injective r" and "v⇧T = r⇧T * t⇧⋆" and "forest w" and "t ≤ w" and "w ≤ v * v⇧T" shows "w = t" proof (-) (*goal: ‹w = t›*) have 1: "vector v" using assms(1,3) (*‹vector r› ‹v⇧T = r⇧T * t⇧⋆›*) covector_mult_closed (*‹covector ?x ⟹ covector (?x * ?y)›*) vector_conv_covector (*‹vector ?v = covector (?v⇧T)›*) by auto have "w * v ≤ v * v⇧T * v" by (simp add: assms( (*‹w ≤ v * v⇧T›*) 6) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) also (*calculation: ‹w * v ≤ v * v⇧T * v›*) have "... ≤ v" using "1" (*‹vector v›*) by (metis mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) top_greatest (*‹?x ≤ top›*)) finally (*calculation: ‹w * v ≤ v›*) have 2: "w * v ≤ v" . have 3: "r ≤ v" by (metis assms( (*‹v⇧T = r⇧T * t⇧⋆›*) 3) conv_order (*‹(?x ≤ ?y) = (?x⇧T ≤ ?y⇧T)›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) mult_1_right (*‹?a * 1 = ?a›*) star.circ_reflexive (*‹reflexive (?x⇧⋆)›*)) have 4: "v ⊓ -r = t⇧T⇧⋆ * r ⊓ -r" by (metis assms( (*‹v⇧T = r⇧T * t⇧⋆›*) 3) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*)) also (*calculation: ‹v ⊓ - r = t⇧T⇧⋆ * r ⊓ - r›*) have "... = (r ⊔ t⇧T⁺ * r) ⊓ -r" using mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) star.circ_loop_fixpoint (*‹?y * (?y⇧⋆ * ?z) ⊔ ?z = ?y⇧⋆ * ?z›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*) by auto also (*calculation: ‹(v::'a) ⊓ - (r::'a) = (r ⊔ (t::'a)⇧T⁺ * r) ⊓ - r›*) have "... ≤ t⇧T⁺ * r" by (simp add: shunting (*‹(?x ⊓ ?y ≤ ?z) = (?x ≤ ?z ⊔ - ?y)›*)) also (*calculation: ‹v ⊓ - r ≤ t⇧T⁺ * r›*) have "... ≤ t⇧T * top" by (simp add: comp_isotone (*‹⟦(?x::'a::type) ≤ (?y::'a::type); (?w::'a::type) ≤ (?z::'a::type)⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) mult_assoc (*‹(?a::'a::type) * (?b::'a::type) * (?c::'a::type) = ?a * (?b * ?c)›*)) finally (*calculation: ‹v ⊓ - r ≤ t⇧T * top›*) have "1 ⊓ (v ⊓ -r) * (v ⊓ -r)⇧T ≤ 1 ⊓ t⇧T * top * (t⇧T * top)⇧T" using conv_order (*‹(?x ≤ ?y) = (?x⇧T ≤ ?y⇧T)›*) inf.sup_right_isotone (*‹?y ≤ ?x ⟹ ?z ⊓ ?y ≤ ?z ⊓ ?x›*) mult_isotone (*‹⟦?w ≤ ?y; ?x ≤ ?z⟧ ⟹ ?w * ?x ≤ ?y * ?z›*) by auto also (*calculation: ‹(1::'a) ⊓ ((v::'a) ⊓ - (r::'a)) * (v ⊓ - r)⇧T ≤ (1::'a) ⊓ (t::'a)⇧T * top * (t⇧T * top)⇧T›*) have "... = 1 ⊓ t⇧T * top * t" by (metis conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_top (*‹symmetric top›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) top_mult_top (*‹surjective top›*)) also (*calculation: ‹1 ⊓ (v ⊓ - r) * (v ⊓ - r)⇧T ≤ 1 ⊓ t⇧T * top * t›*) have "... ≤ t⇧T * (top * t ⊓ t * 1)" by (metis conv_involutive (*‹?x⇧T⇧T = ?x›*) dedekind_1 (*‹?x * ?y ⊓ ?z ≤ ?x * (?y ⊓ ?x⇧T * ?z)›*) inf.commute (*‹?a ⊓ ?b = ?b ⊓ ?a›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹1 ⊓ (v ⊓ - r) * (v ⊓ - r)⇧T ≤ t⇧T * (top * t ⊓ t * 1)›*) have "... ≤ t⇧T * t" by (simp add: mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) finally (*calculation: ‹1 ⊓ (v ⊓ - r) * (v ⊓ - r)⇧T ≤ t⇧T * t›*) have 5: "1 ⊓ (v ⊓ -r) * (v ⊓ -r)⇧T ≤ t⇧T * t" . have "w * w⁺ ≤ -1" by (metis assms( (*‹forest w›*) 4) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) order_trans (*‹⟦?x ≤ ?y; ?y ≤ ?z⟧ ⟹ ?x ≤ ?z›*) star.circ_increasing (*‹?x ≤ ?x⇧⋆›*) star.left_plus_circ (*‹?x⁺⇧⋆ = ?x⇧⋆›*)) hence 6: "w⇧T⁺ ≤ -w" by (metis conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_1_left (*‹1 * ?a = ?a›*) triple_schroeder_p (*‹(?x * ?y * ?z ≤ - ?w) = (?x⇧T * ?w * ?z⇧T ≤ - ?y)›*)) have "w * r ⊓ w⇧T⁺ * r = (w ⊓ w⇧T⁺) * r" using assms(2) (*‹injective r›*) by (simp add: injective_comp_right_dist_inf (*‹injective ?z ⟹ (?x ⊓ ?y) * ?z = ?x * ?z ⊓ ?y * ?z›*)) also (*calculation: ‹w * r ⊓ w⇧T⁺ * r = (w ⊓ w⇧T⁺) * r›*) have "... = bot" using "6" (*‹w⇧T⁺ ≤ - w›*) p_antitone (*‹?x ≤ ?y ⟹ - ?y ≤ - ?x›*) pseudo_complement_pp (*‹((?x::'a) ⊓ (?y::'a) = bot) = (- - ?x ≤ - ?y)›*) semiring.mult_not_zero (*‹?a * ?b ≠ bot ⟹ ?a ≠ bot ∧ ?b ≠ bot›*) by blast finally (*calculation: ‹w * r ⊓ w⇧T⁺ * r = bot›*) have 7: "w * r ⊓ w⇧T⁺ * r = bot" . have "-1 * r ≤ -r" using assms(2) (*‹injective r›*) dual_order.trans (*‹⟦?b ≤ ?a; ?c ≤ ?b⟧ ⟹ ?c ≤ ?a›*) pp_increasing (*‹?x ≤ - - ?x›*) schroeder_4_p (*‹((?x::'a::type) * (?y::'a::type) ≤ - (?z::'a::type)) = (?z * ?y⇧T ≤ - ?x)›*) by blast hence "-1 * r * top ≤ -r" by (simp add: assms( (*‹vector r›*) 1) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*)) hence 8: "r⇧T * -1 * r ≤ bot" by (simp add: mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) schroeder_6_p (*‹(?x * ?y ≤ - ?z) = (?z⇧T * ?x ≤ - ?y⇧T)›*)) have "r⇧T * w * r ≤ r⇧T * w⁺ * r" by (simp add: mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star.circ_mult_increasing (*‹?x ≤ ?x⁺›*)) also (*calculation: ‹(r::'a)⇧T * (w::'a) * r ≤ r⇧T * w⁺ * r›*) have "... ≤ r⇧T * -1 * r" by (simp add: assms( (*‹forest w›*) 4) comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*)) finally (*calculation: ‹r⇧T * w * r ≤ r⇧T * - 1 * r›*) have "r⇧T * w * r ≤ bot" using "8" (*‹r⇧T * - 1 * r ≤ bot›*) by simp hence "w * r * top ≤ -r" by (simp add: mult_assoc (*‹(?a::'a) * (?b::'a) * (?c::'a) = ?a * (?b * ?c)›*) schroeder_6_p (*‹((?x::'a) * (?y::'a) ≤ - (?z::'a)) = (?z⇧T * ?x ≤ - ?y⇧T)›*)) hence "w * r ≤ -r" by (simp add: assms( (*‹vector r›*) 1) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*)) hence "w * r ≤ -r ⊓ w * v" using "3" (*‹r ≤ v›*) by (simp add: mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹w * r ≤ - r ⊓ w * v›*) have "... ≤ -r ⊓ v" using "2" (*‹w * v ≤ v›*) by (simp add: le_infI2 (*‹?b ≤ ?x ⟹ ?a ⊓ ?b ≤ ?x›*)) also (*calculation: ‹w * r ≤ - r ⊓ v›*) have "... = -r ⊓ t⇧T⇧⋆ * r" using "4" (*‹v ⊓ - r = t⇧T⇧⋆ * r ⊓ - r›*) by (simp add: inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*)) also (*calculation: ‹w * r ≤ - r ⊓ t⇧T⇧⋆ * r›*) have "... ≤ -r ⊓ w⇧T⇧⋆ * r" using assms(5) (*‹(t::'a) ≤ (w::'a)›*) comp_inf.mult_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊓ ?x ≤ ?z ⊓ ?y›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) mult_left_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x * (?z::'a) ≤ ?y * ?z›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) by auto also (*calculation: ‹w * r ≤ - r ⊓ w⇧T⇧⋆ * r›*) have "... = -r ⊓ (r ⊔ w⇧T⁺ * r)" using mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) star.circ_loop_fixpoint (*‹?y * (?y⇧⋆ * ?z) ⊔ ?z = ?y⇧⋆ * ?z›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*) by auto also (*calculation: ‹w * r ≤ - r ⊓ (r ⊔ w⇧T⁺ * r)›*) have "... ≤ w⇧T⁺ * r" using inf.commute (*‹?a ⊓ ?b = ?b ⊓ ?a›*) maddux_3_13 (*‹(?x ⊔ ?y) ⊓ - ?x = ?y ⊓ - ?x›*) by auto finally (*calculation: ‹w * r ≤ w⇧T⁺ * r›*) have "w * r = bot" using "7" (*‹w * r ⊓ w⇧T⁺ * r = bot›*) by (simp add: le_iff_inf (*‹(?x ≤ ?y) = (?x ⊓ ?y = ?x)›*)) hence "w = w ⊓ top * -r⇧T" by (metis complement_conv_sub (*‹- (?y * ?x) * ?x⇧T ≤ - ?y›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_bot (*‹symmetric bot›*) inf.assoc (*‹?a ⊓ ?b ⊓ ?c = ?a ⊓ (?b ⊓ ?c)›*) inf.orderE (*‹⟦?a ≤ ?b; ?a = ?a ⊓ ?b ⟹ ?thesis⟧ ⟹ ?thesis›*) regular_closed_bot (*‹regular bot›*) regular_dense_top (*‹⟦regular ?x; dense ?x⟧ ⟹ ?x = top›*) top_left_mult_increasing (*‹?x ≤ top * ?x›*)) also (*calculation: ‹w = w ⊓ top * - r⇧T›*) have "... = w ⊓ v * v⇧T ⊓ top * -r⇧T" by (simp add: assms( (*‹w ≤ v * v⇧T›*) 6) inf_absorb1 (*‹?x ≤ ?y ⟹ ?x ⊓ ?y = ?x›*)) also (*calculation: ‹w = w ⊓ v * v⇧T ⊓ top * - r⇧T›*) have "... ≤ w ⊓ top * v⇧T ⊓ top * -r⇧T" using comp_inf.mult_left_isotone (*‹?x ≤ ?y ⟹ ?x ⊓ ?z ≤ ?y ⊓ ?z›*) comp_inf.mult_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊓ ?x ≤ ?z ⊓ ?y›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) by auto also (*calculation: ‹w ≤ w ⊓ top * v⇧T ⊓ top * - r⇧T›*) have "... = w ⊓ top * (v⇧T ⊓ -r⇧T)" using "1" (*‹vector v›*) assms(1) (*‹vector r›*) covector_inf_closed (*‹⟦covector ?x; covector ?y⟧ ⟹ covector (?x ⊓ ?y)›*) inf_assoc (*‹(?x::'a) ⊓ (?y::'a) ⊓ (?z::'a) = ?x ⊓ (?y ⊓ ?z)›*) vector_conv_compl (*‹vector ?v ⟹ covector (- ?v⇧T)›*) vector_conv_covector (*‹vector ?v = covector (?v⇧T)›*) by auto also (*calculation: ‹(w::'a::type) ≤ w ⊓ top * ((v::'a::type)⇧T ⊓ - (r::'a::type)⇧T)›*) have "... = w * (1 ⊓ (v ⊓ -r) * top)" by (simp add: comp_inf_vector (*‹?x * (?y ⊓ ?z * top) = (?x ⊓ top * ?z⇧T) * ?y›*) conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*)) also (*calculation: ‹(w::'a::type) ≤ w * ((1::'a::type) ⊓ ((v::'a::type) ⊓ - (r::'a::type)) * top)›*) have "... = w * (1 ⊓ (v ⊓ -r) * (v ⊓ -r)⇧T)" by (metis conv_top (*‹symmetric top›*) dedekind_eq (*‹(?x::'a) * (?y::'a) ⊓ (?z::'a) = (?x ⊓ ?z * ?y⇧T) * (?y ⊓ ?x⇧T * ?z) ⊓ ?z›*) inf_commute (*‹(?x::'a) ⊓ (?y::'a) = ?y ⊓ ?x›*) inf_top_left (*‹top ⊓ (?x::'a) = ?x›*) mult_1_left (*‹(1::'a) * (?a::'a) = ?a›*) mult_1_right (*‹(?a::'a) * (1::'a) = ?a›*)) also (*calculation: ‹w ≤ w * (1 ⊓ (v ⊓ - r) * (v ⊓ - r)⇧T)›*) have "... ≤ w * t⇧T * t" using "5" (*‹(1::'a::type) ⊓ ((v::'a::type) ⊓ - (r::'a::type)) * (v ⊓ - r)⇧T ≤ (t::'a::type)⇧T * t›*) by (simp add: comp_isotone (*‹⟦(?x::'a) ≤ (?y::'a); (?w::'a) ≤ (?z::'a)⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) mult_assoc (*‹(?a::'a) * (?b::'a) * (?c::'a) = ?a * (?b * ?c)›*)) also (*calculation: ‹w ≤ w * t⇧T * t›*) have "... ≤ w * w⇧T * t" by (simp add: assms( (*‹(t::'a) ≤ (w::'a)›*) 5) comp_isotone (*‹⟦(?x::'a) ≤ (?y::'a); (?w::'a) ≤ (?z::'a)⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) conv_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x⇧T ≤ ?y⇧T›*)) also (*calculation: ‹w ≤ w * w⇧T * t›*) have "... ≤ t" using assms(4) (*‹forest w›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_1_left (*‹1 * ?a = ?a›*) by fastforce finally (*calculation: ‹w ≤ t›*) show "?thesis" (*goal: ‹w = t›*) by (simp add: assms( (*‹(t::'a) ≤ (w::'a)›*) 5) order.antisym (*‹⟦(?a::'a) ≤ (?b::'a); ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) qed subsection ‹Kruskal's Algorithm› text ‹ The following results are used for proving the correctness of Kruskal's minimum spanning tree algorithm. › subsubsection ‹Preservation of Invariant› text ‹ We first treat the preservation of the invariant. The following lemmas show conditions necessary for preserving that ‹f› is a forest. › lemma kruskal_injective_inv_2: assumes "arc e" and "acyclic f" shows "top * e * f⇧T⇧⋆ * f⇧T ≤ -e" proof (-) (*goal: ‹top * e * f⇧T⇧⋆ * f⇧T ≤ - e›*) have "f ≤ -f⇧T⇧⋆" using assms(2) (*‹pd_kleene_allegory_class.acyclic f›*) acyclic_star_below_complement (*‹pd_kleene_allegory_class.acyclic ?w = (?w⇧T⇧⋆ ≤ - ?w)›*) p_antitone_iff (*‹(?x ≤ - ?y) = (?y ≤ - ?x)›*) by simp hence "e * f ≤ top * e * -f⇧T⇧⋆" by (simp add: comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) top_left_mult_increasing (*‹?x ≤ top * ?x›*)) also (*calculation: ‹(e::'a::type) * (f::'a::type) ≤ top * e * - f⇧T⇧⋆›*) have "... = -(top * e * f⇧T⇧⋆)" by (metis assms( (*‹arc e›*) 1) comp_mapping_complement (*‹mapping ?x ⟹ ?x * - ?y = - (?x * ?y)›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_top (*‹symmetric top›*)) finally (*calculation: ‹e * f ≤ - (top * e * f⇧T⇧⋆)›*) show "?thesis" (*goal: ‹top * e * f⇧T⇧⋆ * f⇧T ≤ - e›*) using schroeder_4_p (*‹((?x::'a) * (?y::'a) ≤ - (?z::'a)) = (?z * ?y⇧T ≤ - ?x)›*) by simp qed lemma kruskal_injective_inv_3: assumes "arc e" and "forest f" shows "(top * e * f⇧T⇧⋆)⇧T * (top * e * f⇧T⇧⋆) ⊓ f⇧T * f ≤ 1" proof (-) (*goal: ‹coreflexive ((top * e * f⇧T⇧⋆)⇧T * (top * e * f⇧T⇧⋆) ⊓ f⇧T * f)›*) have "(top * e * f⇧T⇧⋆)⇧T * (top * e * f⇧T⇧⋆) = f⇧⋆ * e⇧T * top * e * f⇧T⇧⋆" by (metis conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) conv_top (*‹symmetric top›*) vector_top_closed (*‹surjective top›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹(top * e * f⇧T⇧⋆)⇧T * (top * e * f⇧T⇧⋆) = f⇧⋆ * e⇧T * top * e * f⇧T⇧⋆›*) have "... ≤ f⇧⋆ * f⇧T⇧⋆" by (metis assms( (*‹arc (e::'a)›*) 1) arc_expanded (*‹arc (?x::'a) = (coreflexive (?x * top * ?x⇧T) ∧ coreflexive (?x⇧T * top * ?x) ∧ times_top_class.total (top * ?x))›*) mult_left_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x * (?z::'a) ≤ ?y * ?z›*) mult_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*) mult_1_left (*‹(1::'a) * (?a::'a) = ?a›*) mult_assoc (*‹(?a::'a) * (?b::'a) * (?c::'a) = ?a * (?b * ?c)›*)) finally (*calculation: ‹(top * e * f⇧T⇧⋆)⇧T * (top * e * f⇧T⇧⋆) ≤ f⇧⋆ * f⇧T⇧⋆›*) have "(top * e * f⇧T⇧⋆)⇧T * (top * e * f⇧T⇧⋆) ⊓ f⇧T * f ≤ f⇧⋆ * f⇧T⇧⋆ ⊓ f⇧T * f" using inf.sup_left_isotone (*‹?y ≤ ?x ⟹ ?y ⊓ ?z ≤ ?x ⊓ ?z›*) by simp also (*calculation: ‹(top * e * f⇧T⇧⋆)⇧T * (top * e * f⇧T⇧⋆) ⊓ f⇧T * f ≤ f⇧⋆ * f⇧T⇧⋆ ⊓ f⇧T * f›*) have "... ≤ 1" using assms(2) (*‹forest f›*) forest_separate (*‹forest ?x ⟹ coreflexive (?x⇧⋆ * ?x⇧T⇧⋆ ⊓ ?x⇧T * ?x)›*) by simp finally (*calculation: ‹coreflexive ((top * (e::'a::type) * (f::'a::type)⇧T⇧⋆)⇧T * (top * e * f⇧T⇧⋆) ⊓ f⇧T * f)›*) show "?thesis" (*goal: ‹coreflexive ((top * e * f⇧T⇧⋆)⇧T * (top * e * f⇧T⇧⋆) ⊓ f⇧T * f)›*) by simp qed lemma kruskal_acyclic_inv: assumes "acyclic f" and "covector q" and "(f ⊓ q)⇧T * f⇧⋆ * e = bot" and "e * f⇧⋆ * e = bot" and "f⇧T⇧⋆ * f⇧⋆ ≤ -e" shows "acyclic ((f ⊓ -q) ⊔ (f ⊓ q)⇧T ⊔ e)" proof (-) (*goal: ‹pd_kleene_allegory_class.acyclic (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)›*) have "(f ⊓ -q) * (f ⊓ q)⇧T = (f ⊓ -q) * (f⇧T ⊓ q⇧T)" by (simp add: conv_dist_inf (*‹((?x::'a::type) ⊓ (?y::'a::type))⇧T = ?x⇧T ⊓ ?y⇧T›*)) hence 1: "(f ⊓ -q) * (f ⊓ q)⇧T = bot" by (metis assms( (*‹covector q›*) 2) comp_inf.semiring.mult_zero_right (*‹?a ⊓ bot = bot›*) comp_inf_vector_1 (*‹(?x ⊓ top * ?y) * ?z = ?x * (?z ⊓ (top * ?y)⇧T)›*) conv_bot (*‹symmetric bot›*) covector_bot_closed (*‹covector bot›*) inf.sup_monoid.add_assoc (*‹?a ⊓ ?b ⊓ ?c = ?a ⊓ (?b ⊓ ?c)›*) p_inf (*‹- ?x ⊓ ?x = bot›*)) hence 2: "(f ⊓ -q)⇧⋆ * (f ⊓ q)⇧T = (f ⊓ q)⇧T" using mult_right_zero (*‹?x * bot = bot›*) star_absorb (*‹(?x::'a) * (?y::'a) = bot ⟹ ?x * ?y⇧⋆ = ?x›*) star_simulation_right_equal (*‹(?z::'a) * (?x::'a) = (?y::'a) * ?z ⟹ ?z * ?x⇧⋆ = ?y⇧⋆ * ?z›*) by fastforce hence 3: "((f ⊓ -q) ⊔ (f ⊓ q)⇧T)⁺ = (f ⊓ q)⇧T⇧⋆ * (f ⊓ -q)⁺ ⊔ (f ⊓ q)⇧T⁺" by (simp add: plus_sup (*‹(?x ⊔ ?y)⁺ = (?x⇧⋆ * ?y)⇧⋆ * ?x⁺ ⊔ (?x⇧⋆ * ?y)⁺›*)) have 4: "((f ⊓ -q) ⊔ (f ⊓ q)⇧T)⇧⋆ = (f ⊓ q)⇧T⇧⋆ * (f ⊓ -q)⇧⋆" using "2" (*‹(f ⊓ - q)⇧⋆ * (f ⊓ q)⇧T = (f ⊓ q)⇧T›*) by (simp add: star.circ_sup_9 (*‹(?x ⊔ ?y)⇧⋆ = (?x⇧⋆ * ?y)⇧⋆ * ?x⇧⋆›*)) have "(f ⊓ q)⇧T * (f ⊓ -q)⇧⋆ * e ≤ (f ⊓ q)⇧T * f⇧⋆ * e" by (simp add: mult_left_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x * (?z::'a) ≤ ?y * ?z›*) mult_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*) star_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) hence "(f ⊓ q)⇧T * (f ⊓ -q)⇧⋆ * e = bot" using assms(3) (*‹((f::'a) ⊓ (q::'a))⇧T * f⇧⋆ * (e::'a) = bot›*) le_bot (*‹?a ≤ bot ⟹ ?a = bot›*) by simp hence 5: "(f ⊓ q)⇧T⇧⋆ * (f ⊓ -q)⇧⋆ * e = (f ⊓ -q)⇧⋆ * e" by (metis comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) conv_bot (*‹symmetric bot›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) star_absorb (*‹?x * ?y = bot ⟹ ?x * ?y⇧⋆ = ?x›*)) have "e * (f ⊓ -q)⇧⋆ * e ≤ e * f⇧⋆ * e" by (simp add: mult_left_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x * (?z::'a) ≤ ?y * ?z›*) mult_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*) star_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) hence "e * (f ⊓ -q)⇧⋆ * e = bot" using assms(4) (*‹e * f⇧⋆ * e = bot›*) le_bot (*‹(?a::'a) ≤ bot ⟹ ?a = bot›*) by simp hence 6: "((f ⊓ -q)⇧⋆ * e)⁺ = (f ⊓ -q)⇧⋆ * e" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) star_absorb (*‹?x * ?y = bot ⟹ ?x * ?y⇧⋆ = ?x›*)) have "f⇧T⇧⋆ * 1 * f⇧T⇧⋆ * f⇧⋆ ≤ -e" by (simp add: assms( (*‹forest_components f ≤ - e›*) 5) star.circ_transitive_equal (*‹idempotent (?x⇧⋆)›*)) hence 7: "f⇧⋆ * e * f⇧T⇧⋆ * f⇧⋆ ≤ -1" by (metis comp_right_one (*‹?x * 1 = ?x›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_one (*‹symmetric 1›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) triple_schroeder_p (*‹(?x * ?y * ?z ≤ - ?w) = (?x⇧T * ?w * ?z⇧T ≤ - ?y)›*)) have "(f ⊓ -q)⁺ * (f ⊓ q)⇧T⁺ ≤ -1" using "1" (*‹((f::'a) ⊓ - (q::'a)) * (f ⊓ q)⇧T = bot›*) "2" (*‹(f ⊓ - q)⇧⋆ * (f ⊓ q)⇧T = (f ⊓ q)⇧T›*) by (metis forest_bot (*‹forest bot›*) mult_left_zero (*‹bot * ?x = bot›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) hence 8: "(f ⊓ q)⇧T⁺ * (f ⊓ -q)⁺ ≤ -1" using comp_commute_below_diversity (*‹irreflexive ((?x::'a) * (?y::'a)) = irreflexive (?y * ?x)›*) by simp have 9: "f⇧T⁺ ≤ -1" using assms(1) (*‹pd_kleene_allegory_class.acyclic f›*) acyclic_star_below_complement (*‹pd_kleene_allegory_class.acyclic ?w = (?w⇧T⇧⋆ ≤ - ?w)›*) schroeder_5_p (*‹((?x::'a::type) * (?y::'a::type) ≤ - (?z::'a::type)) = (?y * ?z⇧T ≤ - ?x⇧T)›*) by force have "((f ⊓ -q) ⊔ (f ⊓ q)⇧T ⊔ e)⁺ = (((f ⊓ -q) ⊔ (f ⊓ q)⇧T)⇧⋆ * e)⇧⋆ * ((f ⊓ -q) ⊔ (f ⊓ q)⇧T)⁺ ⊔ (((f ⊓ -q) ⊔ (f ⊓ q)⇧T)⇧⋆ * e)⁺" by (simp add: plus_sup (*‹(?x ⊔ ?y)⁺ = (?x⇧⋆ * ?y)⇧⋆ * ?x⁺ ⊔ (?x⇧⋆ * ?y)⁺›*)) also (*calculation: ‹(f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)⁺ = ((f ⊓ - q ⊔ (f ⊓ q)⇧T)⇧⋆ * e)⇧⋆ * (f ⊓ - q ⊔ (f ⊓ q)⇧T)⁺ ⊔ ((f ⊓ - q ⊔ (f ⊓ q)⇧T)⇧⋆ * e)⁺›*) have "... = ((f ⊓ q)⇧T⇧⋆ * (f ⊓ -q)⇧⋆ * e)⇧⋆ * ((f ⊓ q)⇧T⇧⋆ * (f ⊓ -q)⁺ ⊔ (f ⊓ q)⇧T⁺) ⊔ ((f ⊓ q)⇧T⇧⋆ * (f ⊓ -q)⇧⋆ * e)⁺" using "3" (*‹(f ⊓ - q ⊔ (f ⊓ q)⇧T)⁺ = (f ⊓ q)⇧T⇧⋆ * (f ⊓ - q)⁺ ⊔ (f ⊓ q)⇧T⁺›*) "4" (*‹(f ⊓ - q ⊔ (f ⊓ q)⇧T)⇧⋆ = (f ⊓ q)⇧T⇧⋆ * (f ⊓ - q)⇧⋆›*) by simp also (*calculation: ‹(f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)⁺ = ((f ⊓ q)⇧T⇧⋆ * (f ⊓ - q)⇧⋆ * e)⇧⋆ * ((f ⊓ q)⇧T⇧⋆ * (f ⊓ - q)⁺ ⊔ (f ⊓ q)⇧T⁺) ⊔ ((f ⊓ q)⇧T⇧⋆ * (f ⊓ - q)⇧⋆ * e)⁺›*) have "... = ((f ⊓ -q)⇧⋆ * e)⇧⋆ * ((f ⊓ q)⇧T⇧⋆ * (f ⊓ -q)⁺ ⊔ (f ⊓ q)⇧T⁺) ⊔ ((f ⊓ -q)⇧⋆ * e)⁺" using "5" (*‹(f ⊓ q)⇧T⇧⋆ * (f ⊓ - q)⇧⋆ * e = (f ⊓ - q)⇧⋆ * e›*) by simp also (*calculation: ‹(f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)⁺ = ((f ⊓ - q)⇧⋆ * e)⇧⋆ * ((f ⊓ q)⇧T⇧⋆ * (f ⊓ - q)⁺ ⊔ (f ⊓ q)⇧T⁺) ⊔ ((f ⊓ - q)⇧⋆ * e)⁺›*) have "... = ((f ⊓ -q)⇧⋆ * e ⊔ 1) * ((f ⊓ q)⇧T⇧⋆ * (f ⊓ -q)⁺ ⊔ (f ⊓ q)⇧T⁺) ⊔ (f ⊓ -q)⇧⋆ * e" using "6" (*‹(((f::'a) ⊓ - (q::'a))⇧⋆ * (e::'a))⁺ = (f ⊓ - q)⇧⋆ * e›*) by (metis star_left_unfold_equal (*‹1 ⊔ ?x⁺ = ?x⇧⋆›*) sup_monoid.add_commute (*‹?a ⊔ ?b = ?b ⊔ ?a›*)) also (*calculation: ‹(f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)⁺ = ((f ⊓ - q)⇧⋆ * e ⊔ 1) * ((f ⊓ q)⇧T⇧⋆ * (f ⊓ - q)⁺ ⊔ (f ⊓ q)⇧T⁺) ⊔ (f ⊓ - q)⇧⋆ * e›*) have "... = (f ⊓ -q)⇧⋆ * e ⊔ (f ⊓ -q)⇧⋆ * e * (f ⊓ q)⇧T⁺ ⊔ (f ⊓ -q)⇧⋆ * e * (f ⊓ q)⇧T⇧⋆ * (f ⊓ -q)⁺ ⊔ (f ⊓ q)⇧T⇧⋆ * (f ⊓ -q)⁺ ⊔ (f ⊓ q)⇧T⁺" using comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) mult_left_dist_sup (*‹(?x::'a) * ((?y::'a) ⊔ (?z::'a)) = ?x * ?y ⊔ ?x * ?z›*) mult_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*) sup_assoc (*‹(?x::'a::type) ⊔ (?y::'a::type) ⊔ (?z::'a::type) = ?x ⊔ (?y ⊔ ?z)›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*) by simp also (*calculation: ‹(f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)⁺ = (f ⊓ - q)⇧⋆ * e ⊔ (f ⊓ - q)⇧⋆ * e * (f ⊓ q)⇧T⁺ ⊔ (f ⊓ - q)⇧⋆ * e * (f ⊓ q)⇧T⇧⋆ * (f ⊓ - q)⁺ ⊔ (f ⊓ q)⇧T⇧⋆ * (f ⊓ - q)⁺ ⊔ (f ⊓ q)⇧T⁺›*) have "... = (f ⊓ -q)⇧⋆ * e * (f ⊓ q)⇧T⇧⋆ * (f ⊓ -q)⇧⋆ ⊔ (f ⊓ q)⇧T⇧⋆ * (f ⊓ -q)⁺ ⊔ (f ⊓ q)⇧T⁺" by (metis star.circ_back_loop_fixpoint (*‹?z * ?y⇧⋆ * ?y ⊔ ?z = ?z * ?y⇧⋆›*) star_plus (*‹?y⇧⋆ * ?y = ?y⁺›*) sup_monoid.add_commute (*‹?a ⊔ ?b = ?b ⊔ ?a›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹(f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)⁺ = (f ⊓ - q)⇧⋆ * e * (f ⊓ q)⇧T⇧⋆ * (f ⊓ - q)⇧⋆ ⊔ (f ⊓ q)⇧T⇧⋆ * (f ⊓ - q)⁺ ⊔ (f ⊓ q)⇧T⁺›*) have "... ≤ f⇧⋆ * e * f⇧T⇧⋆ * (f ⊓ -q)⇧⋆ ⊔ (f ⊓ q)⇧T⇧⋆ * (f ⊓ -q)⁺ ⊔ (f ⊓ q)⇧T⁺" using mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) sup_left_isotone (*‹(?x::'a::type) ≤ (?y::'a::type) ⟹ ?x ⊔ (?z::'a::type) ≤ ?y ⊔ ?z›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) order_trans (*‹⟦?x ≤ ?y; ?y ≤ ?z⟧ ⟹ ?x ≤ ?z›*) inf_le1 (*‹?x ⊓ ?y ≤ ?x›*) by meson also (*calculation: ‹(f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)⁺ ≤ f⇧⋆ * e * f⇧T⇧⋆ * (f ⊓ - q)⇧⋆ ⊔ (f ⊓ q)⇧T⇧⋆ * (f ⊓ - q)⁺ ⊔ (f ⊓ q)⇧T⁺›*) have "... ≤ f⇧⋆ * e * f⇧T⇧⋆ * f⇧⋆ ⊔ (f ⊓ q)⇧T⇧⋆ * (f ⊓ -q)⁺ ⊔ f⇧T⁺" using mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) sup_left_isotone (*‹?x ≤ ?y ⟹ ?x ⊔ ?z ≤ ?y ⊔ ?z›*) sup_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊔ ?x ≤ ?z ⊔ ?y›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) order_trans (*‹⟦?x ≤ ?y; ?y ≤ ?z⟧ ⟹ ?x ≤ ?z›*) inf_le1 (*‹?x ⊓ ?y ≤ ?x›*) by meson also (*calculation: ‹(f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)⁺ ≤ f⇧⋆ * e * f⇧T⇧⋆ * f⇧⋆ ⊔ (f ⊓ q)⇧T⇧⋆ * (f ⊓ - q)⁺ ⊔ f⇧T⁺›*) have "... = f⇧⋆ * e * f⇧T⇧⋆ * f⇧⋆ ⊔ (f ⊓ q)⇧T⁺ * (f ⊓ -q)⁺ ⊔ (f ⊓ -q)⁺ ⊔ f⇧T⁺" by (simp add: star.circ_loop_fixpoint (*‹?y * (?y⇧⋆ * ?z) ⊔ ?z = ?y⇧⋆ * ?z›*) sup_monoid.add_assoc (*‹?a ⊔ ?b ⊔ ?c = ?a ⊔ (?b ⊔ ?c)›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹(f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)⁺ ≤ f⇧⋆ * e * f⇧T⇧⋆ * f⇧⋆ ⊔ (f ⊓ q)⇧T⁺ * (f ⊓ - q)⁺ ⊔ (f ⊓ - q)⁺ ⊔ f⇧T⁺›*) have "... ≤ f⇧⋆ * e * f⇧T⇧⋆ * f⇧⋆ ⊔ (f ⊓ q)⇧T⁺ * (f ⊓ -q)⁺ ⊔ f⁺ ⊔ f⇧T⁺" using mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) sup_left_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x ⊔ (?z::'a) ≤ ?y ⊔ ?z›*) sup_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊔ ?x ≤ ?z ⊔ ?y›*) order_trans (*‹⟦?x ≤ ?y; ?y ≤ ?z⟧ ⟹ ?x ≤ ?z›*) inf_le1 (*‹?x ⊓ ?y ≤ ?x›*) by meson also (*calculation: ‹(f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)⁺ ≤ f⇧⋆ * e * f⇧T⇧⋆ * f⇧⋆ ⊔ (f ⊓ q)⇧T⁺ * (f ⊓ - q)⁺ ⊔ f⁺ ⊔ f⇧T⁺›*) have "... ≤ -1" using "7" (*‹irreflexive (f⇧⋆ * e * f⇧T⇧⋆ * f⇧⋆)›*) "8" (*‹irreflexive ((f ⊓ q)⇧T⁺ * (f ⊓ - q)⁺)›*) "9" (*‹pd_kleene_allegory_class.acyclic (f⇧T)›*) assms(1) (*‹pd_kleene_allegory_class.acyclic (f::'a)›*) by simp finally (*calculation: ‹pd_kleene_allegory_class.acyclic (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)›*) show "?thesis" (*goal: ‹pd_kleene_allegory_class.acyclic (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)›*) by simp qed lemma kruskal_exchange_acyclic_inv_1: assumes "acyclic f" and "covector q" shows "acyclic ((f ⊓ -q) ⊔ (f ⊓ q)⇧T)" using kruskal_acyclic_inv[where e = bot] (*‹⟦pd_kleene_allegory_class.acyclic ?f; covector ?q; (?f ⊓ ?q)⇧T * ?f⇧⋆ * bot = bot; bot * ?f⇧⋆ * bot = bot; forest_components ?f ≤ - bot⟧ ⟹ pd_kleene_allegory_class.acyclic (?f ⊓ - ?q ⊔ (?f ⊓ ?q)⇧T ⊔ bot)›*) by (simp add: assms (*‹pd_kleene_allegory_class.acyclic f› ‹covector q›*)) lemma kruskal_exchange_acyclic_inv_2: assumes "acyclic w" and "injective w" and "d ≤ w" and "bijective (d⇧T * top)" and "bijective (e * top)" and "d ≤ top * e⇧T * w⇧T⇧⋆" and "w * e⇧T * top = bot" shows "acyclic ((w ⊓ -d) ⊔ e)" proof (-) (*goal: ‹pd_kleene_allegory_class.acyclic ((w::'a) ⊓ - (d::'a) ⊔ (e::'a))›*) let ?v = "w ⊓ -d" let ?w = "?v ⊔ e" have "d⇧T * top ≤ w⇧⋆ * e * top" by (metis assms( (*‹(d::'a) ≤ top * (e::'a)⇧T * (w::'a)⇧T⇧⋆›*) 6) comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*) comp_inf.star.circ_decompose_9 (*‹top = top ⊓ top ⊓ top›*) comp_inf.star_star_absorb (*‹top ⊓ top ⊓ top = top ⊓ top›*) comp_isotone (*‹⟦(?x::'a) ≤ (?y::'a); (?w::'a) ≤ (?z::'a)⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) conv_dist_comp (*‹((?x::'a) * (?y::'a))⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹(?x::'a)⇧T⇧T = ?x›*) conv_order (*‹((?x::'a) ≤ (?y::'a)) = (?x⇧T ≤ ?y⇧T)›*) conv_star_commute (*‹(?x::'a)⇧⋆⇧T = ?x⇧T⇧⋆›*) conv_top (*‹symmetric top›*) inf.cobounded1 (*‹(?a::'a) ⊓ (?b::'a) ≤ ?a›*) vector_top_closed (*‹surjective top›*)) hence 1: "e * top ≤ w⇧T⇧⋆ * d⇧T * top" by (metis assms( (*‹bijective ((d::'a)⇧T * top)› ‹bijective ((e::'a) * top)›*) 4,5) bijective_reverse (*‹⟦bijective (?p::'a); bijective (?q::'a)⟧ ⟹ (?p ≤ (?r::'a) * ?q) = (?q ≤ ?r⇧T * ?p)›*) comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*) conv_star_commute (*‹(?x::'a)⇧⋆⇧T = ?x⇧T⇧⋆›*)) have 2: "?v * d⇧T * top = bot" by (simp add: assms( (*‹injective (w::'a)› ‹(d::'a) ≤ (w::'a)›*) 2,3) kruskal_exchange_acyclic_inv_3 (*‹⟦injective (?w::'a); (?d::'a) ≤ ?w⟧ ⟹ (?w ⊓ - ?d) * ?d⇧T * top = bot›*)) have "?v * w⇧T⁺ * d⇧T * top ≤ w * w⇧T⁺ * d⇧T * top" by (simp add: mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) also (*calculation: ‹(w ⊓ - d) * w⇧T⁺ * d⇧T * top ≤ w * w⇧T⁺ * d⇧T * top›*) have "... ≤ w⇧T⇧⋆ * d⇧T * top" by (metis assms( (*‹injective w›*) 2) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_1_left (*‹1 * ?a = ?a›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) finally (*calculation: ‹(w ⊓ - d) * w⇧T⁺ * d⇧T * top ≤ w⇧T⇧⋆ * d⇧T * top›*) have "?v * w⇧T⇧⋆ * d⇧T * top ≤ w⇧T⇧⋆ * d⇧T * top" using "2" (*‹(w ⊓ - d) * d⇧T * top = bot›*) by (metis bot_least (*‹bot ≤ ?a›*) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) mult_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*) star.circ_back_loop_fixpoint (*‹?z * ?y⇧⋆ * ?y ⊔ ?z = ?z * ?y⇧⋆›*) star.circ_plus_same (*‹?x⇧⋆ * ?x = ?x⁺›*) sup_least (*‹⟦?y ≤ ?x; ?z ≤ ?x⟧ ⟹ ?y ⊔ ?z ≤ ?x›*)) hence 3: "?v⇧⋆ * e * top ≤ w⇧T⇧⋆ * d⇧T * top" using "1" (*‹e * top ≤ w⇧T⇧⋆ * d⇧T * top›*) by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) star_left_induct (*‹?z ⊔ ?y * ?x ≤ ?x ⟶ ?y⇧⋆ * ?z ≤ ?x›*) sup_least (*‹⟦?y ≤ ?x; ?z ≤ ?x⟧ ⟹ ?y ⊔ ?z ≤ ?x›*)) have "d * e⇧T ≤ bot" by (metis assms( (*‹d ≤ w› ‹w * e⇧T * top = bot›*) 3,7) conv_bot (*‹symmetric bot›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_top (*‹symmetric top›*) order.trans (*‹⟦?a ≤ ?b; ?b ≤ ?c⟧ ⟹ ?a ≤ ?c›*) inf.absorb2 (*‹?b ≤ ?a ⟹ ?a ⊓ ?b = ?b›*) inf.cobounded2 (*‹?a ⊓ ?b ≤ ?b›*) inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) le_bot (*‹?a ≤ bot ⟹ ?a = bot›*) p_antitone_iff (*‹(?x ≤ - ?y) = (?y ≤ - ?x)›*) p_top (*‹dense top›*) schroeder_4_p (*‹(?x * ?y ≤ - ?z) = (?z * ?y⇧T ≤ - ?x)›*) top_left_mult_increasing (*‹?x ≤ top * ?x›*)) hence 4: "e⇧T * top ≤ -(d⇧T * top)" by (metis (no_types) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) inf.cobounded2 (*‹?a ⊓ ?b ≤ ?b›*) le_bot (*‹?a ≤ bot ⟹ ?a = bot›*) p_antitone_iff (*‹(?x ≤ - ?y) = (?y ≤ - ?x)›*) schroeder_3_p (*‹(?x * ?y ≤ - ?z) = (?x⇧T * ?z ≤ - ?y)›*) semiring.mult_zero_left (*‹bot * ?a = bot›*)) have "?v⇧T * -(d⇧T * top) ≤ -(d⇧T * top)" using schroeder_3_p (*‹(?x * ?y ≤ - ?z) = (?x⇧T * ?z ≤ - ?y)›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) "2" (*‹(w ⊓ - d) * d⇧T * top = bot›*) by simp hence "?v⇧T⇧⋆ * e⇧T * top ≤ -(d⇧T * top)" using "4" (*‹e⇧T * top ≤ - (d⇧T * top)›*) by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) star_left_induct (*‹?z ⊔ ?y * ?x ≤ ?x ⟶ ?y⇧⋆ * ?z ≤ ?x›*) sup_least (*‹⟦?y ≤ ?x; ?z ≤ ?x⟧ ⟹ ?y ⊔ ?z ≤ ?x›*)) hence 5: "d⇧T * top ≤ -(?v⇧T⇧⋆ * e⇧T * top)" by (simp add: p_antitone_iff (*‹(?x ≤ - ?y) = (?y ≤ - ?x)›*)) have "w * ?v⇧T⇧⋆ * e⇧T * top = w * e⇧T * top ⊔ w * ?v⇧T⁺ * e⇧T * top" by (metis star_left_unfold_equal (*‹1 ⊔ ?x⁺ = ?x⇧⋆›*) mult_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*) mult_left_dist_sup (*‹?x * (?y ⊔ ?z) = ?x * ?y ⊔ ?x * ?z›*) mult_1_right (*‹?a * 1 = ?a›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹w * (w ⊓ - d)⇧T⇧⋆ * e⇧T * top = w * e⇧T * top ⊔ w * (w ⊓ - d)⇧T⁺ * e⇧T * top›*) have "... = w * ?v⇧T⁺ * e⇧T * top" using assms(7) (*‹w * e⇧T * top = bot›*) by simp also (*calculation: ‹(w::'a) * (w ⊓ - (d::'a))⇧T⇧⋆ * (e::'a)⇧T * top = w * (w ⊓ - d)⇧T⁺ * e⇧T * top›*) have "... ≤ w * w⇧T * ?v⇧T⇧⋆ * e⇧T * top" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹w * (w ⊓ - d)⇧T⇧⋆ * e⇧T * top ≤ w * w⇧T * (w ⊓ - d)⇧T⇧⋆ * e⇧T * top›*) have "... ≤ ?v⇧T⇧⋆ * e⇧T * top" by (metis assms( (*‹injective w›*) 2) mult_1_left (*‹1 * ?a = ?a›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) finally (*calculation: ‹w * (w ⊓ - d)⇧T⇧⋆ * e⇧T * top ≤ (w ⊓ - d)⇧T⇧⋆ * e⇧T * top›*) have "w * ?v⇧T⇧⋆ * e⇧T * top ≤ --(?v⇧T⇧⋆ * e⇧T * top)" by (simp add: p_antitone (*‹?x ≤ ?y ⟹ - ?y ≤ - ?x›*) p_antitone_iff (*‹(?x ≤ - ?y) = (?y ≤ - ?x)›*)) hence "w⇧T * -(?v⇧T⇧⋆ * e⇧T * top) ≤ -(?v⇧T⇧⋆ * e⇧T * top)" using comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) schroeder_3_p (*‹(?x * ?y ≤ - ?z) = (?x⇧T * ?z ≤ - ?y)›*) by simp hence 6: "w⇧T⇧⋆ * d⇧T * top ≤ -(?v⇧T⇧⋆ * e⇧T * top)" using "5" (*‹(d::'a::type)⇧T * top ≤ - (((w::'a::type) ⊓ - d)⇧T⇧⋆ * (e::'a::type)⇧T * top)›*) by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) star_left_induct (*‹?z ⊔ ?y * ?x ≤ ?x ⟶ ?y⇧⋆ * ?z ≤ ?x›*) sup_least (*‹⟦?y ≤ ?x; ?z ≤ ?x⟧ ⟹ ?y ⊔ ?z ≤ ?x›*)) have "e * ?v⇧⋆ * e ≤ e * ?v⇧⋆ * e * top" by (simp add: top_right_mult_increasing (*‹?x ≤ ?x * top›*)) also (*calculation: ‹(e::'a) * ((w::'a) ⊓ - (d::'a))⇧⋆ * e ≤ e * (w ⊓ - d)⇧⋆ * e * top›*) have "... ≤ e * w⇧T⇧⋆ * d⇧T * top" using "3" (*‹(w ⊓ - d)⇧⋆ * e * top ≤ w⇧T⇧⋆ * d⇧T * top›*) by (simp add: comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*) mult_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*)) also (*calculation: ‹e * (w ⊓ - d)⇧⋆ * e ≤ e * w⇧T⇧⋆ * d⇧T * top›*) have "... ≤ e * -(?v⇧T⇧⋆ * e⇧T * top)" using "6" (*‹(w::'a)⇧T⇧⋆ * (d::'a)⇧T * top ≤ - ((w ⊓ - d)⇧T⇧⋆ * (e::'a)⇧T * top)›*) by (simp add: comp_associative (*‹(?x::'a::type) * (?y::'a::type) * (?z::'a::type) = ?x * (?y * ?z)›*) mult_right_isotone (*‹(?x::'a::type) ≤ (?y::'a::type) ⟹ (?z::'a::type) * ?x ≤ ?z * ?y›*)) also (*calculation: ‹e * (w ⊓ - d)⇧⋆ * e ≤ e * - ((w ⊓ - d)⇧T⇧⋆ * e⇧T * top)›*) have "... ≤ bot" by (metis conv_complement_sub_leq (*‹?x⇧T * - (?x * ?y) ≤ - ?y›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) le_bot (*‹?a ≤ bot ⟹ ?a = bot›*) mult_right_sub_dist_sup_right (*‹?y * ?z ≤ (?x ⊔ ?y) * ?z›*) p_bot (*‹- bot = top›*) regular_closed_bot (*‹regular bot›*) star.circ_back_loop_fixpoint (*‹?z * ?y⇧⋆ * ?y ⊔ ?z = ?z * ?y⇧⋆›*)) finally (*calculation: ‹e * (w ⊓ - d)⇧⋆ * e ≤ bot›*) have 7: "e * ?v⇧⋆ * e = bot" by (simp add: order.antisym (*‹⟦(?a::'a) ≤ (?b::'a); ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) hence "?v⇧⋆ * e ≤ -1" by (metis bot_least (*‹bot ≤ ?a›*) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_commute_below_diversity (*‹irreflexive (?x * ?y) = irreflexive (?y * ?x)›*) ex231d (*‹?x ≤ ?x * top * ?x›*) order_lesseq_imp (*‹(∀z≥?x. ?y ≤ z) = (?y ≤ ?x)›*) semiring.mult_zero_left (*‹bot * ?a = bot›*) star.circ_left_top (*‹surjective (?x⇧⋆)›*)) hence 8: "?v⇧⋆ * e * ?v⇧⋆ ≤ -1" by (metis comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*) comp_commute_below_diversity (*‹irreflexive ((?x::'a) * (?y::'a)) = irreflexive (?y * ?x)›*) star.circ_transitive_equal (*‹idempotent ((?x::'a)⇧⋆)›*)) have "1 ⊓ ?w⁺ = 1 ⊓ ?w * ?v⇧⋆ * (e * ?v⇧⋆)⇧⋆" by (simp add: star_sup_1 (*‹((?x::'a) ⊔ (?y::'a))⇧⋆ = ?x⇧⋆ * (?y * ?x⇧⋆)⇧⋆›*) mult_assoc (*‹(?a::'a) * (?b::'a) * (?c::'a) = ?a * (?b * ?c)›*)) also (*calculation: ‹(1::'a) ⊓ ((w::'a) ⊓ - (d::'a) ⊔ (e::'a))⁺ = (1::'a) ⊓ (w ⊓ - d ⊔ e) * (w ⊓ - d)⇧⋆ * (e * (w ⊓ - d)⇧⋆)⇧⋆›*) have "... = 1 ⊓ ?w * ?v⇧⋆ * (e * ?v⇧⋆ ⊔ 1)" using "7" (*‹e * (w ⊓ - d)⇧⋆ * e = bot›*) by (metis star.circ_mult_1 (*‹((?x::'a::type) * (?y::'a::type))⇧⋆ = Rf (?x * (?y * ?x)⇧⋆) ?y›*) star_absorb (*‹(?x::'a::type) * (?y::'a::type) = bot ⟹ ?x * ?y⇧⋆ = ?x›*) sup_monoid.add_commute (*‹(?a::'a::type) ⊔ (?b::'a::type) = ?b ⊔ ?a›*) mult_assoc (*‹(?a::'a::type) * (?b::'a::type) * (?c::'a::type) = ?a * (?b * ?c)›*)) also (*calculation: ‹1 ⊓ (w ⊓ - d ⊔ e)⁺ = 1 ⊓ (w ⊓ - d ⊔ e) * (w ⊓ - d)⇧⋆ * (e * (w ⊓ - d)⇧⋆ ⊔ 1)›*) have "... = 1 ⊓ (?v⁺ * e * ?v⇧⋆ ⊔ ?v⁺ ⊔ e * ?v⇧⋆ * e * ?v⇧⋆ ⊔ e * ?v⇧⋆)" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) mult_left_dist_sup (*‹?x * (?y ⊔ ?z) = ?x * ?y ⊔ ?x * ?z›*) mult_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*) sup_assoc (*‹?x ⊔ ?y ⊔ ?z = ?x ⊔ (?y ⊔ ?z)›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*) sup_left_commute (*‹?x ⊔ (?y ⊔ ?z) = ?y ⊔ (?x ⊔ ?z)›*)) also (*calculation: ‹1 ⊓ (w ⊓ - d ⊔ e)⁺ = 1 ⊓ ((w ⊓ - d)⁺ * e * (w ⊓ - d)⇧⋆ ⊔ (w ⊓ - d)⁺ ⊔ e * (w ⊓ - d)⇧⋆ * e * (w ⊓ - d)⇧⋆ ⊔ e * (w ⊓ - d)⇧⋆)›*) have "... = 1 ⊓ (?v⁺ * e * ?v⇧⋆ ⊔ ?v⁺ ⊔ e * ?v⇧⋆)" using "7" (*‹e * (w ⊓ - d)⇧⋆ * e = bot›*) by simp also (*calculation: ‹1 ⊓ (w ⊓ - d ⊔ e)⁺ = 1 ⊓ ((w ⊓ - d)⁺ * e * (w ⊓ - d)⇧⋆ ⊔ (w ⊓ - d)⁺ ⊔ e * (w ⊓ - d)⇧⋆)›*) have "... = 1 ⊓ (?v⇧⋆ * e * ?v⇧⋆ ⊔ ?v⁺)" by (metis (mono_tags, opaque_lifting) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) star.circ_loop_fixpoint (*‹?y * (?y⇧⋆ * ?z) ⊔ ?z = ?y⇧⋆ * ?z›*) sup_assoc (*‹?x ⊔ ?y ⊔ ?z = ?x ⊔ (?y ⊔ ?z)›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*)) also (*calculation: ‹1 ⊓ (w ⊓ - d ⊔ e)⁺ = 1 ⊓ ((w ⊓ - d)⇧⋆ * e * (w ⊓ - d)⇧⋆ ⊔ (w ⊓ - d)⁺)›*) have "... ≤ 1 ⊓ (?v⇧⋆ * e * ?v⇧⋆ ⊔ w⁺)" using comp_inf.mult_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊓ ?x ≤ ?z ⊓ ?y›*) comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) semiring.add_right_mono (*‹?a ≤ ?b ⟹ ?a ⊔ ?c ≤ ?b ⊔ ?c›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*) by simp also (*calculation: ‹1 ⊓ (w ⊓ - d ⊔ e)⁺ ≤ 1 ⊓ ((w ⊓ - d)⇧⋆ * e * (w ⊓ - d)⇧⋆ ⊔ w⁺)›*) have "... = (1 ⊓ ?v⇧⋆ * e * ?v⇧⋆) ⊔ (1 ⊓ w⁺)" by (simp add: inf_sup_distrib1 (*‹?x ⊓ (?y ⊔ ?z) = ?x ⊓ ?y ⊔ ?x ⊓ ?z›*)) also (*calculation: ‹1 ⊓ (w ⊓ - d ⊔ e)⁺ ≤ 1 ⊓ (w ⊓ - d)⇧⋆ * e * (w ⊓ - d)⇧⋆ ⊔ 1 ⊓ w⁺›*) have "... = 1 ⊓ ?v⇧⋆ * e * ?v⇧⋆" by (metis assms( (*‹pd_kleene_allegory_class.acyclic w›*) 1) inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) pseudo_complement (*‹(?x ⊓ ?y = bot) = (?x ≤ - ?y)›*) sup_bot_right (*‹?x ⊔ bot = ?x›*)) also (*calculation: ‹1 ⊓ (w ⊓ - d ⊔ e)⁺ ≤ 1 ⊓ (w ⊓ - d)⇧⋆ * e * (w ⊓ - d)⇧⋆›*) have "... = bot" using "8" (*‹irreflexive (((w::'a::type) ⊓ - (d::'a::type))⇧⋆ * (e::'a::type) * (w ⊓ - d)⇧⋆)›*) p_antitone_iff (*‹(?x ≤ - ?y) = (?y ≤ - ?x)›*) pseudo_complement (*‹(?x ⊓ ?y = bot) = (?x ≤ - ?y)›*) by simp finally (*calculation: ‹1 ⊓ (w ⊓ - d ⊔ e)⁺ ≤ bot›*) show "?thesis" (*goal: ‹pd_kleene_allegory_class.acyclic (w ⊓ - d ⊔ e)›*) using le_bot (*‹?a ≤ bot ⟹ ?a = bot›*) p_antitone_iff (*‹(?x ≤ - ?y) = (?y ≤ - ?x)›*) pseudo_complement (*‹(?x ⊓ ?y = bot) = (?x ≤ - ?y)›*) by auto qed subsubsection ‹Exchange gives Spanning Trees› text ‹ The lemmas in this section are used to show that the relation after exchange represents a spanning tree. › lemma inf_star_import: assumes "x ≤ z" and "univalent z" and "reflexive y" and "regular z" shows "x⇧⋆ * y ⊓ z⇧⋆ ≤ x⇧⋆ * (y ⊓ z⇧⋆)" proof (-) (*goal: ‹x⇧⋆ * y ⊓ z⇧⋆ ≤ x⇧⋆ * (y ⊓ z⇧⋆)›*) have 1: "y ≤ x⇧⋆ * (y ⊓ z⇧⋆) ⊔ -z⇧⋆" by (metis assms( (*‹regular z›*) 4) pp_dist_star (*‹- - ?x⇧⋆ = components ?x›*) shunting_var_p (*‹(?x ⊓ - ?y ≤ ?z) = (?x ≤ ?z ⊔ - - ?y)›*) star.circ_loop_fixpoint (*‹?y * (?y⇧⋆ * ?z) ⊔ ?z = ?y⇧⋆ * ?z›*) sup.cobounded2 (*‹?b ≤ ?a ⊔ ?b›*)) have "x * -z⇧⋆ ⊓ z⁺ ≤ x * (-z⇧⋆ ⊓ x⇧T * z⁺)" by (simp add: dedekind_1 (*‹?x * ?y ⊓ ?z ≤ ?x * (?y ⊓ ?x⇧T * ?z)›*)) also (*calculation: ‹x * - z⇧⋆ ⊓ z⁺ ≤ x * (- z⇧⋆ ⊓ x⇧T * z⁺)›*) have "... ≤ x * (-z⇧⋆ ⊓ z⇧T * z⁺)" using assms(1) (*‹x ≤ z›*) comp_inf.mult_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) ⊓ ?x ≤ ?z ⊓ ?y›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) by simp also (*calculation: ‹x * - z⇧⋆ ⊓ z⁺ ≤ x * (- z⇧⋆ ⊓ z⇧T * z⁺)›*) have "... ≤ x * (-z⇧⋆ ⊓ 1 * z⇧⋆)" by (metis assms( (*‹univalent z›*) 2) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_inf.mult_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊓ ?x ≤ ?z ⊓ ?y›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) finally (*calculation: ‹x * - z⇧⋆ ⊓ z⁺ ≤ x * (- z⇧⋆ ⊓ 1 * z⇧⋆)›*) have 2: "x * -z⇧⋆ ⊓ z⁺ = bot" by (simp add: order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) have "x * -z⇧⋆ ⊓ z⇧⋆ = (x * -z⇧⋆ ⊓ z⁺) ⊔ (x * -z⇧⋆ ⊓ 1)" by (metis comp_inf.semiring.distrib_left (*‹?a ⊓ (?b ⊔ ?c) = ?a ⊓ ?b ⊔ ?a ⊓ ?c›*) star_left_unfold_equal (*‹1 ⊔ ?x⁺ = ?x⇧⋆›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*)) also (*calculation: ‹x * - z⇧⋆ ⊓ z⇧⋆ = x * - z⇧⋆ ⊓ z⁺ ⊔ x * - z⇧⋆ ⊓ 1›*) have "... ≤ x⇧⋆ * (y ⊓ z⇧⋆)" using "2" (*‹x * - z⇧⋆ ⊓ z⁺ = bot›*) by (simp add: assms( (*‹reflexive (y::'a)›*) 3) inf.coboundedI2 (*‹(?b::'a) ≤ (?c::'a) ⟹ (?a::'a) ⊓ ?b ≤ ?c›*) reflexive_mult_closed (*‹⟦reflexive (?x::'a); reflexive (?y::'a)⟧ ⟹ reflexive (?x * ?y)›*) star.circ_reflexive (*‹reflexive ((?x::'a)⇧⋆)›*)) finally (*calculation: ‹x * - z⇧⋆ ⊓ z⇧⋆ ≤ x⇧⋆ * (y ⊓ z⇧⋆)›*) have "x * -z⇧⋆ ≤ x⇧⋆ * (y ⊓ z⇧⋆) ⊔ -z⇧⋆" by (metis assms( (*‹regular z›*) 4) pp_dist_star (*‹- - ?x⇧⋆ = components ?x›*) shunting_var_p (*‹(?x ⊓ - ?y ≤ ?z) = (?x ≤ ?z ⊔ - - ?y)›*)) hence "x * (x⇧⋆ * (y ⊓ z⇧⋆) ⊔ -z⇧⋆) ≤ x⇧⋆ * (y ⊓ z⇧⋆) ⊔ -z⇧⋆" by (metis le_supE (*‹⟦?a ⊔ ?b ≤ ?x; ⟦?a ≤ ?x; ?b ≤ ?x⟧ ⟹ ?P⟧ ⟹ ?P›*) le_supI (*‹⟦?a ≤ ?x; ?b ≤ ?x⟧ ⟹ ?a ⊔ ?b ≤ ?x›*) mult_left_dist_sup (*‹?x * (?y ⊔ ?z) = ?x * ?y ⊔ ?x * ?z›*) star.circ_loop_fixpoint (*‹?y * (?y⇧⋆ * ?z) ⊔ ?z = ?y⇧⋆ * ?z›*) sup.cobounded1 (*‹?a ≤ ?a ⊔ ?b›*)) hence "x⇧⋆ * y ≤ x⇧⋆ * (y ⊓ z⇧⋆) ⊔ -z⇧⋆" using "1" (*‹y ≤ x⇧⋆ * (y ⊓ z⇧⋆) ⊔ - z⇧⋆›*) by (simp add: star_left_induct (*‹?z ⊔ ?y * ?x ≤ ?x ⟶ ?y⇧⋆ * ?z ≤ ?x›*)) hence "x⇧⋆ * y ⊓ --z⇧⋆ ≤ x⇧⋆ * (y ⊓ z⇧⋆)" using shunting_var_p (*‹(?x ⊓ - ?y ≤ ?z) = (?x ≤ ?z ⊔ - - ?y)›*) by simp thus "?thesis" (*goal: ‹x⇧⋆ * y ⊓ z⇧⋆ ≤ x⇧⋆ * (y ⊓ z⇧⋆)›*) using order.trans (*‹⟦?a ≤ ?b; ?b ≤ ?c⟧ ⟹ ?a ≤ ?c›*) inf.sup_right_isotone (*‹(?y::'a) ≤ (?x::'a) ⟹ (?z::'a) ⊓ ?y ≤ ?z ⊓ ?x›*) pp_increasing (*‹?x ≤ - - ?x›*) by blast qed lemma kruskal_exchange_forest_components_inv: assumes "injective ((w ⊓ -d) ⊔ e)" and "regular d" and "e * top * e = e" and "d ≤ top * e⇧T * w⇧T⇧⋆" and "w * e⇧T * top = bot" and "injective w" and "d ≤ w" and "d ≤ (w ⊓ -d)⇧T⇧⋆ * e⇧T * top" shows "forest_components w ≤ forest_components ((w ⊓ -d) ⊔ e)" proof (-) (*goal: ‹forest_components w ≤ forest_components (w ⊓ - d ⊔ e)›*) let ?v = "w ⊓ -d" let ?w = "?v ⊔ e" let ?f = "forest_components ?w" have 1: "?v * d⇧T * top = bot" by (simp add: assms( (*‹injective (w::'a)› ‹(d::'a) ≤ (w::'a)›*) 6,7) kruskal_exchange_acyclic_inv_3 (*‹⟦injective (?w::'a); (?d::'a) ≤ ?w⟧ ⟹ (?w ⊓ - ?d) * ?d⇧T * top = bot›*)) have 2: "d * e⇧T ≤ bot" by (metis assms( (*‹w * e⇧T * top = bot› ‹d ≤ w›*) 5,7) conv_bot (*‹symmetric bot›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_top (*‹symmetric top›*) order.trans (*‹⟦?a ≤ ?b; ?b ≤ ?c⟧ ⟹ ?a ≤ ?c›*) inf.absorb2 (*‹?b ≤ ?a ⟹ ?a ⊓ ?b = ?b›*) inf.cobounded2 (*‹?a ⊓ ?b ≤ ?b›*) inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) le_bot (*‹?a ≤ bot ⟹ ?a = bot›*) p_antitone_iff (*‹(?x ≤ - ?y) = (?y ≤ - ?x)›*) p_top (*‹dense top›*) schroeder_4_p (*‹(?x * ?y ≤ - ?z) = (?z * ?y⇧T ≤ - ?x)›*) top_left_mult_increasing (*‹?x ≤ top * ?x›*)) have "w⇧⋆ * e⇧T * top = e⇧T * top" by (metis assms( (*‹(w::'a::type) * (e::'a::type)⇧T * top = bot›*) 5) conv_bot (*‹symmetric bot›*) conv_dist_comp (*‹((?x::'a::type) * (?y::'a::type))⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹(?x::'a::type)⇧T⇧T = ?x›*) conv_star_commute (*‹(?x::'a::type)⇧⋆⇧T = ?x⇧T⇧⋆›*) star.circ_top (*‹top⇧⋆ = top›*) star_absorb (*‹(?x::'a::type) * (?y::'a::type) = bot ⟹ ?x * ?y⇧⋆ = ?x›*)) hence "w⇧⋆ * e⇧T * top ≤ -(d⇧T * top)" using "2" (*‹d * e⇧T ≤ bot›*) by (metis (no_types) comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*) inf.cobounded2 (*‹(?a::'a) ⊓ (?b::'a) ≤ ?b›*) le_bot (*‹(?a::'a) ≤ bot ⟹ ?a = bot›*) p_antitone_iff (*‹((?x::'a) ≤ - (?y::'a)) = (?y ≤ - ?x)›*) schroeder_3_p (*‹((?x::'a) * (?y::'a) ≤ - (?z::'a)) = (?x⇧T * ?z ≤ - ?y)›*) semiring.mult_zero_left (*‹bot * (?a::'a) = bot›*)) hence 3: "e⇧T * top ≤ -(w⇧T⇧⋆ * d⇧T * top)" by (metis conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) p_antitone_iff (*‹(?x ≤ - ?y) = (?y ≤ - ?x)›*) schroeder_3_p (*‹(?x * ?y ≤ - ?z) = (?x⇧T * ?z ≤ - ?y)›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) have "?v * w⇧T⇧⋆ * d⇧T * top = ?v * d⇧T * top ⊔ ?v * w⇧T⁺ * d⇧T * top" by (metis comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) mult_left_dist_sup (*‹?x * (?y ⊔ ?z) = ?x * ?y ⊔ ?x * ?z›*) star.circ_loop_fixpoint (*‹?y * (?y⇧⋆ * ?z) ⊔ ?z = ?y⇧⋆ * ?z›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*)) also (*calculation: ‹(w ⊓ - d) * w⇧T⇧⋆ * d⇧T * top = (w ⊓ - d) * d⇧T * top ⊔ (w ⊓ - d) * w⇧T⁺ * d⇧T * top›*) have "... ≤ w * w⇧T⁺ * d⇧T * top" using "1" (*‹(w ⊓ - d) * d⇧T * top = bot›*) by (simp add: mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) also (*calculation: ‹((w::'a) ⊓ - (d::'a)) * w⇧T⇧⋆ * d⇧T * top ≤ w * w⇧T⁺ * d⇧T * top›*) have "... ≤ w⇧T⇧⋆ * d⇧T * top" by (metis assms( (*‹injective w›*) 6) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_1_left (*‹1 * ?a = ?a›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) finally (*calculation: ‹(w ⊓ - d) * w⇧T⇧⋆ * d⇧T * top ≤ w⇧T⇧⋆ * d⇧T * top›*) have "?v * w⇧T⇧⋆ * d⇧T * top ≤ --(w⇧T⇧⋆ * d⇧T * top)" using p_antitone (*‹?x ≤ ?y ⟹ - ?y ≤ - ?x›*) p_antitone_iff (*‹(?x ≤ - ?y) = (?y ≤ - ?x)›*) by auto hence 4: "?v⇧T * -(w⇧T⇧⋆ * d⇧T * top) ≤ -(w⇧T⇧⋆ * d⇧T * top)" using comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) schroeder_3_p (*‹(?x * ?y ≤ - ?z) = (?x⇧T * ?z ≤ - ?y)›*) by simp have 5: "injective ?v" using assms(1) (*‹injective (w ⊓ - d ⊔ e)›*) conv_dist_sup (*‹(?x ⊔ ?y)⇧T = ?x⇧T ⊔ ?y⇧T›*) mult_left_dist_sup (*‹?x * (?y ⊔ ?z) = ?x * ?y ⊔ ?x * ?z›*) mult_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*) by simp have "?v * ?v⇧T⇧⋆ * e⇧T * top = ?v * e⇧T * top ⊔ ?v * ?v⇧T⁺ * e⇧T * top" by (metis comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*) mult_left_dist_sup (*‹(?x::'a) * ((?y::'a) ⊔ (?z::'a)) = ?x * ?y ⊔ ?x * ?z›*) star.circ_loop_fixpoint (*‹(?y::'a) * (?y⇧⋆ * (?z::'a)) ⊔ ?z = ?y⇧⋆ * ?z›*) sup_commute (*‹(?x::'a) ⊔ (?y::'a) = ?y ⊔ ?x›*)) also (*calculation: ‹(w ⊓ - d) * (w ⊓ - d)⇧T⇧⋆ * e⇧T * top = (w ⊓ - d) * e⇧T * top ⊔ (w ⊓ - d) * (w ⊓ - d)⇧T⁺ * e⇧T * top›*) have "... ≤ w * e⇧T * top ⊔ ?v * ?v⇧T⁺ * e⇧T * top" using mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) sup_left_isotone (*‹?x ≤ ?y ⟹ ?x ⊔ ?z ≤ ?y ⊔ ?z›*) by simp also (*calculation: ‹(w ⊓ - d) * (w ⊓ - d)⇧T⇧⋆ * e⇧T * top ≤ w * e⇧T * top ⊔ (w ⊓ - d) * (w ⊓ - d)⇧T⁺ * e⇧T * top›*) have "... ≤ w * e⇧T * top ⊔ ?v⇧T⇧⋆ * e⇧T * top" using "5" (*‹injective (w ⊓ - d)›*) by (metis mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_1_left (*‹1 * ?a = ?a›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) sup_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊔ ?x ≤ ?z ⊔ ?y›*)) finally (*calculation: ‹(w ⊓ - d) * (w ⊓ - d)⇧T⇧⋆ * e⇧T * top ≤ w * e⇧T * top ⊔ (w ⊓ - d)⇧T⇧⋆ * e⇧T * top›*) have "?v * ?v⇧T⇧⋆ * e⇧T * top ≤ ?v⇧T⇧⋆ * e⇧T * top" by (simp add: assms( (*‹w * e⇧T * top = bot›*) 5)) hence "?v⇧⋆ * d * top ≤ ?v⇧T⇧⋆ * e⇧T * top" by (metis assms( (*‹d ≤ (w ⊓ - d)⇧T⇧⋆ * e⇧T * top›*) 8) star_left_induct (*‹?z ⊔ ?y * ?x ≤ ?x ⟶ ?y⇧⋆ * ?z ≤ ?x›*) sup_least (*‹⟦?y ≤ ?x; ?z ≤ ?x⟧ ⟹ ?y ⊔ ?z ≤ ?x›*) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) mult_right_sub_dist_sup_right (*‹?y * ?z ≤ (?x ⊔ ?y) * ?z›*) sup.orderE (*‹⟦?b ≤ ?a; ?a = ?a ⊔ ?b ⟹ ?thesis⟧ ⟹ ?thesis›*) vector_top_closed (*‹surjective top›*)) also (*calculation: ‹(w ⊓ - d)⇧⋆ * d * top ≤ (w ⊓ - d)⇧T⇧⋆ * e⇧T * top›*) have "... ≤ -(w⇧T⇧⋆ * d⇧T * top)" using "3" (*‹e⇧T * top ≤ - (w⇧T⇧⋆ * d⇧T * top)›*) "4" (*‹(w ⊓ - d)⇧T * - (w⇧T⇧⋆ * d⇧T * top) ≤ - (w⇧T⇧⋆ * d⇧T * top)›*) by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) star_left_induct (*‹?z ⊔ ?y * ?x ≤ ?x ⟶ ?y⇧⋆ * ?z ≤ ?x›*)) also (*calculation: ‹(w ⊓ - d)⇧⋆ * d * top ≤ - (w⇧T⇧⋆ * d⇧T * top)›*) have "... ≤ -(d⇧T * top)" by (metis p_antitone (*‹?x ≤ ?y ⟹ - ?y ≤ - ?x›*) star.circ_left_top (*‹surjective (?x⇧⋆)›*) star_outer_increasing (*‹?x ≤ ?y⇧⋆ * ?x * ?y⇧⋆›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) finally (*calculation: ‹(w ⊓ - d)⇧⋆ * d * top ≤ - (d⇧T * top)›*) have 6: "?v⇧⋆ * d * top ≤ -(d⇧T * top)" by simp have "d⇧T * top ≤ w⇧⋆ * e * top" by (metis assms( (*‹d ≤ top * e⇧T * w⇧T⇧⋆›*) 4) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_inf.star.circ_sup_2 (*‹top ≤ top›*) comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_order (*‹(?x ≤ ?y) = (?x⇧T ≤ ?y⇧T)›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) conv_top (*‹symmetric top›*) vector_top_closed (*‹surjective top›*)) also (*calculation: ‹d⇧T * top ≤ w⇧⋆ * e * top›*) have "... ≤ (?v ⊔ d)⇧⋆ * e * top" by (metis assms( (*‹regular d›*) 2) comp_inf.semiring.distrib_left (*‹?a ⊓ (?b ⊔ ?c) = ?a ⊓ ?b ⊔ ?a ⊓ ?c›*) maddux_3_11_pp (*‹?x ⊓ - ?y ⊔ ?x ⊓ - - ?y = ?x›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) sup.cobounded2 (*‹?b ≤ ?a ⊔ ?b›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*) sup_inf_distrib1 (*‹?x ⊔ ?y ⊓ ?z = (?x ⊔ ?y) ⊓ (?x ⊔ ?z)›*)) also (*calculation: ‹(d::'a)⇧T * top ≤ ((w::'a) ⊓ - d ⊔ d)⇧⋆ * (e::'a) * top›*) have "... = ?v⇧⋆ * (d * ?v⇧⋆)⇧⋆ * e * top" by (simp add: star_sup_1 (*‹((?x::'a) ⊔ (?y::'a))⇧⋆ = ?x⇧⋆ * (?y * ?x⇧⋆)⇧⋆›*)) also (*calculation: ‹d⇧T * top ≤ (w ⊓ - d)⇧⋆ * (d * (w ⊓ - d)⇧⋆)⇧⋆ * e * top›*) have "... = ?v⇧⋆ * e * top ⊔ ?v⇧⋆ * d * ?v⇧⋆ * (d * ?v⇧⋆)⇧⋆ * e * top" by (metis semiring.distrib_right (*‹(?a ⊔ ?b) * ?c = ?a * ?c ⊔ ?b * ?c›*) star.circ_unfold_sum (*‹(?x ⊔ ?y)⇧⋆ = ?x⇧⋆ ⊔ ?x⇧⋆ * ?y * (?x ⊔ ?y)⇧⋆›*) star_decompose_1 (*‹(?x ⊔ ?y)⇧⋆ = (?x⇧⋆ * ?y⇧⋆)⇧⋆›*) star_decompose_3 (*‹(?x⇧⋆ * ?y⇧⋆)⇧⋆ = ?x⇧⋆ * (?y * ?x⇧⋆)⇧⋆›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹d⇧T * top ≤ (w ⊓ - d)⇧⋆ * e * top ⊔ (w ⊓ - d)⇧⋆ * d * (w ⊓ - d)⇧⋆ * (d * (w ⊓ - d)⇧⋆)⇧⋆ * e * top›*) have "... ≤ ?v⇧⋆ * e * top ⊔ ?v⇧⋆ * d * top" by (metis comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) le_supI (*‹⟦?a ≤ ?x; ?b ≤ ?x⟧ ⟹ ?a ⊔ ?b ≤ ?x›*) mult_left_dist_sup (*‹?x * (?y ⊔ ?z) = ?x * ?y ⊔ ?x * ?z›*) mult_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star.circ_decompose_5 (*‹(?x⇧⋆ * ?y⇧⋆)⇧⋆ = (?y⇧⋆ * ?x⇧⋆)⇧⋆›*) star_decompose_3 (*‹(?x⇧⋆ * ?y⇧⋆)⇧⋆ = ?x⇧⋆ * (?y * ?x⇧⋆)⇧⋆›*) sup.cobounded1 (*‹?a ≤ ?a ⊔ ?b›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*) top.extremum (*‹?a ≤ top›*)) finally (*calculation: ‹(d::'a)⇧T * top ≤ ((w::'a) ⊓ - d)⇧⋆ * (e::'a) * top ⊔ (w ⊓ - d)⇧⋆ * d * top›*) have "d⇧T * top ≤ ?v⇧⋆ * e * top ⊔ (d⇧T * top ⊓ ?v⇧⋆ * d * top)" using sup_inf_distrib2 (*‹?y ⊓ ?z ⊔ ?x = (?y ⊔ ?x) ⊓ (?z ⊔ ?x)›*) sup_monoid.add_commute (*‹?a ⊔ ?b = ?b ⊔ ?a›*) by simp hence "d⇧T * top ≤ ?v⇧⋆ * e * top" using "6" (*‹((w::'a::type) ⊓ - (d::'a::type))⇧⋆ * d * top ≤ - (d⇧T * top)›*) by (metis inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) pseudo_complement (*‹(?x ⊓ ?y = bot) = (?x ≤ - ?y)›*) sup_monoid.add_0_right (*‹?a ⊔ bot = ?a›*)) hence 7: "d ≤ top * e⇧T * ?v⇧T⇧⋆" by (metis comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*) conv_dist_comp (*‹((?x::'a) * (?y::'a))⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹(?x::'a)⇧T⇧T = ?x›*) conv_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x⇧T ≤ ?y⇧T›*) conv_star_commute (*‹(?x::'a)⇧⋆⇧T = ?x⇧T⇧⋆›*) conv_top (*‹symmetric top›*) order.trans (*‹⟦(?a::'a) ≤ (?b::'a); ?b ≤ (?c::'a)⟧ ⟹ ?a ≤ ?c›*) top_right_mult_increasing (*‹(?x::'a) ≤ ?x * top›*)) have 8: "?v ≤ ?f" using forest_components_increasing (*‹?x ≤ forest_components ?x›*) le_supE (*‹⟦?a ⊔ ?b ≤ ?x; ⟦?a ≤ ?x; ?b ≤ ?x⟧ ⟹ ?P⟧ ⟹ ?P›*) by blast have "d ≤ ?v⇧T⇧⋆ * e⇧T * top ⊓ top * e⇧T * ?v⇧T⇧⋆" using "7" (*‹d ≤ top * e⇧T * (w ⊓ - d)⇧T⇧⋆›*) assms(8) (*‹(d::'a) ≤ ((w::'a) ⊓ - d)⇧T⇧⋆ * (e::'a)⇧T * top›*) by simp also (*calculation: ‹d ≤ (w ⊓ - d)⇧T⇧⋆ * e⇧T * top ⊓ top * e⇧T * (w ⊓ - d)⇧T⇧⋆›*) have "... = ?v⇧T⇧⋆ * e⇧T * top * e⇧T * ?v⇧T⇧⋆" by (metis inf_top_right (*‹?x ⊓ top = ?x›*) vector_inf_comp (*‹vector ?x ⟹ (?x ⊓ ?y) * ?z = ?x ⊓ ?y * ?z›*) vector_top_closed (*‹surjective top›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹d ≤ (w ⊓ - d)⇧T⇧⋆ * e⇧T * top * e⇧T * (w ⊓ - d)⇧T⇧⋆›*) have "... = ?v⇧T⇧⋆ * e⇧T * ?v⇧T⇧⋆" by (metis assms( (*‹e * top * e = e›*) 3) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_top (*‹symmetric top›*)) also (*calculation: ‹d ≤ (w ⊓ - d)⇧T⇧⋆ * e⇧T * (w ⊓ - d)⇧T⇧⋆›*) have "... ≤ ?v⇧T⇧⋆ * e⇧T * ?f" using "8" (*‹w ⊓ - d ≤ forest_components (w ⊓ - d ⊔ e)›*) by (metis assms( (*‹injective (w ⊓ - d ⊔ e)›*) 1) forest_components_equivalence (*‹injective ?x ⟹ equivalence (forest_components ?x)›*) cancel_separate_1 (*‹coreflexive (?x * ?y) ⟹ (?x ⊔ ?y)⇧⋆ = ?y⇧⋆ * ?x⇧⋆›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_order (*‹(?x ≤ ?y) = (?x⇧T ≤ ?y⇧T)›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) star_involutive (*‹?x⇧⋆ = ?x⇧⋆⇧⋆›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) also (*calculation: ‹d ≤ (w ⊓ - d)⇧T⇧⋆ * e⇧T * forest_components (w ⊓ - d ⊔ e)›*) have "... ≤ ?v⇧T⇧⋆ * ?f * ?f" by (metis assms( (*‹injective (w ⊓ - d ⊔ e)›*) 1) forest_components_equivalence (*‹injective ?x ⟹ equivalence (forest_components ?x)›*) forest_components_increasing (*‹?x ≤ forest_components ?x›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) le_supE (*‹⟦?a ⊔ ?b ≤ ?x; ⟦?a ≤ ?x; ?b ≤ ?x⟧ ⟹ ?P⟧ ⟹ ?P›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹d ≤ (w ⊓ - d)⇧T⇧⋆ * forest_components (w ⊓ - d ⊔ e) * forest_components (w ⊓ - d ⊔ e)›*) have "... ≤ ?f * ?f * ?f" by (metis comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*) comp_isotone (*‹⟦(?x::'a) ≤ (?y::'a); (?w::'a) ≤ (?z::'a)⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) conv_dist_sup (*‹((?x::'a) ⊔ (?y::'a))⇧T = ?x⇧T ⊔ ?y⇧T›*) star.circ_loop_fixpoint (*‹(?y::'a) * (?y⇧⋆ * (?z::'a)) ⊔ ?z = ?y⇧⋆ * ?z›*) star_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) sup.cobounded1 (*‹(?a::'a) ≤ ?a ⊔ (?b::'a)›*) sup.cobounded2 (*‹(?b::'a) ≤ (?a::'a) ⊔ ?b›*)) also (*calculation: ‹d ≤ forest_components (w ⊓ - d ⊔ e) * forest_components (w ⊓ - d ⊔ e) * forest_components (w ⊓ - d ⊔ e)›*) have "... = ?f" by (simp add: assms( (*‹injective (w ⊓ - d ⊔ e)›*) 1) forest_components_equivalence (*‹injective ?x ⟹ equivalence (forest_components ?x)›*) preorder_idempotent (*‹preorder ?x ⟹ idempotent ?x›*)) finally (*calculation: ‹(d::'a::type) ≤ forest_components ((w::'a::type) ⊓ - d ⊔ (e::'a::type))›*) have "w ≤ ?f" using "8" (*‹w ⊓ - d ≤ forest_components (w ⊓ - d ⊔ e)›*) by (metis assms( (*‹regular d›*) 2) shunting_var_p (*‹(?x ⊓ - ?y ≤ ?z) = (?x ≤ ?z ⊔ - - ?y)›*) sup.orderE (*‹⟦?b ≤ ?a; ?a = ?a ⊔ ?b ⟹ ?thesis⟧ ⟹ ?thesis›*)) thus "?thesis" (*goal: ‹forest_components (w::'a) ≤ forest_components (w ⊓ - (d::'a) ⊔ (e::'a))›*) using assms(1) (*‹injective (w ⊓ - d ⊔ e)›*) forest_components_idempotent (*‹injective ?x ⟹ forest_components (forest_components ?x) = forest_components ?x›*) forest_components_isotone (*‹?x ≤ ?y ⟹ forest_components ?x ≤ forest_components ?y›*) by fastforce qed lemma kruskal_spanning_inv: assumes "injective ((f ⊓ -q) ⊔ (f ⊓ q)⇧T ⊔ e)" and "regular q" and "regular e" and "(-h ⊓ --g)⇧⋆ ≤ forest_components f" shows "components (-(h ⊓ -e ⊓ -e⇧T) ⊓ g) ≤ forest_components ((f ⊓ -q) ⊔ (f ⊓ q)⇧T ⊔ e)" proof (-) (*goal: ‹components (- (h ⊓ - e ⊓ - e⇧T) ⊓ g) ≤ forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)›*) let ?f = "(f ⊓ -q) ⊔ (f ⊓ q)⇧T ⊔ e" let ?h = "h ⊓ -e ⊓ -e⇧T" let ?F = "forest_components f" let ?FF = "forest_components ?f" have 1: "equivalence ?FF" using assms(1) (*‹injective (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)›*) forest_components_equivalence (*‹injective ?x ⟹ equivalence (forest_components ?x)›*) by simp hence 2: "?f * ?FF ≤ ?FF" using order.trans (*‹⟦?a ≤ ?b; ?b ≤ ?c⟧ ⟹ ?a ≤ ?c›*) forest_components_increasing (*‹?x ≤ forest_components ?x›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) by blast have 3: "?f⇧T * ?FF ≤ ?FF" using "1" (*‹equivalence (forest_components ((f::'a) ⊓ - (q::'a) ⊔ (f ⊓ q)⇧T ⊔ (e::'a)))›*) by (metis forest_components_increasing (*‹?x ≤ forest_components ?x›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) preorder_idempotent (*‹preorder ?x ⟹ idempotent ?x›*)) have "(f ⊓ q) * ?FF ≤ ?f⇧T * ?FF" using conv_dist_sup (*‹((?x::'a::type) ⊔ (?y::'a::type))⇧T = ?x⇧T ⊔ ?y⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) sup_assoc (*‹?x ⊔ ?y ⊔ ?z = ?x ⊔ (?y ⊔ ?z)›*) sup_left_commute (*‹(?x::'a) ⊔ ((?y::'a) ⊔ (?z::'a)) = ?y ⊔ (?x ⊔ ?z)›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) by simp hence 4: "(f ⊓ q) * ?FF ≤ ?FF" using "3" (*‹(f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)⇧T * forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e) ≤ forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)›*) order.trans (*‹⟦?a ≤ ?b; ?b ≤ ?c⟧ ⟹ ?a ≤ ?c›*) by blast have "(f ⊓ -q) * ?FF ≤ ?f * ?FF" using le_supI1 (*‹?x ≤ ?a ⟹ ?x ≤ ?a ⊔ ?b›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) by simp hence "(f ⊓ -q) * ?FF ≤ ?FF" using "2" (*‹(f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e) * forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e) ≤ forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)›*) order.trans (*‹⟦?a ≤ ?b; ?b ≤ ?c⟧ ⟹ ?a ≤ ?c›*) by blast hence "((f ⊓ q) ⊔ (f ⊓ -q)) * ?FF ≤ ?FF" using "4" (*‹(f ⊓ q) * forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e) ≤ forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)›*) mult_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*) by simp hence "f * ?FF ≤ ?FF" by (metis assms( (*‹regular q›*) 2) maddux_3_11_pp (*‹?x ⊓ - ?y ⊔ ?x ⊓ - - ?y = ?x›*)) hence 5: "f⇧⋆ * ?FF ≤ ?FF" using star_left_induct_mult_iff (*‹(?x * ?y ≤ ?y) = (?x⇧⋆ * ?y ≤ ?y)›*) by simp have "(f ⊓ -q)⇧T * ?FF ≤ ?f⇧T * ?FF" by (meson conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) order.trans (*‹⟦?a ≤ ?b; ?b ≤ ?c⟧ ⟹ ?a ≤ ?c›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) sup.cobounded1 (*‹?a ≤ ?a ⊔ ?b›*)) hence 6: "(f ⊓ -q)⇧T * ?FF ≤ ?FF" using "3" (*‹(f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)⇧T * forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e) ≤ forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)›*) order.trans (*‹⟦?a ≤ ?b; ?b ≤ ?c⟧ ⟹ ?a ≤ ?c›*) by blast have "(f ⊓ q)⇧T * ?FF ≤ ?f * ?FF" by (simp add: mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) sup.left_commute (*‹?b ⊔ (?a ⊔ ?c) = ?a ⊔ (?b ⊔ ?c)›*) sup_assoc (*‹?x ⊔ ?y ⊔ ?z = ?x ⊔ (?y ⊔ ?z)›*)) hence "(f ⊓ q)⇧T * ?FF ≤ ?FF" using "2" (*‹(f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e) * forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e) ≤ forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)›*) order.trans (*‹⟦?a ≤ ?b; ?b ≤ ?c⟧ ⟹ ?a ≤ ?c›*) by blast hence "((f ⊓ -q)⇧T ⊔ (f ⊓ q)⇧T) * ?FF ≤ ?FF" using "6" (*‹(f ⊓ - q)⇧T * forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e) ≤ forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)›*) mult_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*) by simp hence "f⇧T * ?FF ≤ ?FF" by (metis assms( (*‹regular q›*) 2) conv_dist_sup (*‹(?x ⊔ ?y)⇧T = ?x⇧T ⊔ ?y⇧T›*) maddux_3_11_pp (*‹?x ⊓ - ?y ⊔ ?x ⊓ - - ?y = ?x›*)) hence 7: "?F * ?FF ≤ ?FF" using "5" (*‹(f::'a)⇧⋆ * forest_components (f ⊓ - (q::'a) ⊔ (f ⊓ q)⇧T ⊔ (e::'a)) ≤ forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)›*) star_left_induct (*‹?z ⊔ ?y * ?x ≤ ?x ⟶ ?y⇧⋆ * ?z ≤ ?x›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) by simp have 8: "e * ?FF ≤ ?FF" using "2" (*‹(f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e) * forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e) ≤ forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)›*) by (simp add: mult_right_dist_sup (*‹((?x::'a) ⊔ (?y::'a)) * (?z::'a) = ?x * ?z ⊔ ?y * ?z›*) mult_left_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x * (?z::'a) ≤ ?y * ?z›*)) have "e⇧T * ?FF ≤ ?f⇧T * ?FF" by (simp add: mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*)) also (*calculation: ‹e⇧T * forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e) ≤ (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)⇧T * forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)›*) have "... ≤ ?FF * ?FF" using "1" (*‹equivalence (forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e))›*) by (metis forest_components_increasing (*‹?x ≤ forest_components ?x›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*)) finally (*calculation: ‹e⇧T * forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e) ≤ forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e) * forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)›*) have "e⇧T * ?FF ≤ ?FF" using "1" (*‹equivalence (forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e))›*) preorder_idempotent (*‹preorder ?x ⟹ idempotent ?x›*) by auto hence 9: "(?F ⊔ e ⊔ e⇧T) * ?FF ≤ ?FF" using "7" (*‹forest_components f * forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e) ≤ forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)›*) "8" (*‹(e::'a) * forest_components ((f::'a) ⊓ - (q::'a) ⊔ (f ⊓ q)⇧T ⊔ e) ≤ forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)›*) mult_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*) by simp have "components (-?h ⊓ g) ≤ ((-h ⊓ --g) ⊔ e ⊔ e⇧T)⇧⋆" by (metis assms( (*‹regular e›*) 3) comp_inf.mult_left_sub_dist_sup_left (*‹?x ⊓ ?y ≤ ?x ⊓ (?y ⊔ ?z)›*) conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) p_dist_inf (*‹- (?x ⊓ ?y) = - ?x ⊔ - ?y›*) pp_dist_inf (*‹- - (?x ⊓ ?y) = - - ?x ⊓ - - ?y›*) regular_closed_p (*‹regular (- ?x)›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) sup_inf_distrib2 (*‹?y ⊓ ?z ⊔ ?x = (?y ⊔ ?x) ⊓ (?z ⊔ ?x)›*) sup_monoid.add_assoc (*‹?a ⊔ ?b ⊔ ?c = ?a ⊔ (?b ⊔ ?c)›*)) also (*calculation: ‹components (- (h ⊓ - e ⊓ - e⇧T) ⊓ g) ≤ (- h ⊓ - - g ⊔ e ⊔ e⇧T)⇧⋆›*) have "... ≤ ((-h ⊓ --g)⇧⋆ ⊔ e ⊔ e⇧T)⇧⋆" using star.circ_increasing (*‹?x ≤ ?x⇧⋆›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) sup_left_isotone (*‹(?x::'a::type) ≤ (?y::'a::type) ⟹ ?x ⊔ (?z::'a::type) ≤ ?y ⊔ ?z›*) by simp also (*calculation: ‹components (- (h ⊓ - e ⊓ - e⇧T) ⊓ g) ≤ ((- h ⊓ - - g)⇧⋆ ⊔ e ⊔ e⇧T)⇧⋆›*) have "... ≤ (?F ⊔ e ⊔ e⇧T)⇧⋆" using assms(4) (*‹(- h ⊓ - - g)⇧⋆ ≤ forest_components f›*) sup_left_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x ⊔ (?z::'a) ≤ ?y ⊔ ?z›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) by simp also (*calculation: ‹components (- (h ⊓ - e ⊓ - e⇧T) ⊓ g) ≤ (forest_components f ⊔ e ⊔ e⇧T)⇧⋆›*) have "... ≤ ?FF" using "1" (*‹equivalence (forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e))›*) "9" (*‹(forest_components f ⊔ e ⊔ e⇧T) * forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e) ≤ forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)›*) star_left_induct (*‹?z ⊔ ?y * ?x ≤ ?x ⟶ ?y⇧⋆ * ?z ≤ ?x›*) by force finally (*calculation: ‹components (- (h ⊓ - e ⊓ - e⇧T) ⊓ g) ≤ forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)›*) show "?thesis" (*goal: ‹components (- (h ⊓ - e ⊓ - e⇧T) ⊓ g) ≤ forest_components (f ⊓ - q ⊔ (f ⊓ q)⇧T ⊔ e)›*) by simp qed lemma kruskal_exchange_spanning_inv_1: assumes "injective ((w ⊓ -q) ⊔ (w ⊓ q)⇧T)" and "regular (w ⊓ q)" and "components g ≤ forest_components w" shows "components g ≤ forest_components ((w ⊓ -q) ⊔ (w ⊓ q)⇧T)" proof (-) (*goal: ‹components g ≤ forest_components (w ⊓ - q ⊔ (w ⊓ q)⇧T)›*) let ?p = "w ⊓ q" let ?w = "(w ⊓ -q) ⊔ ?p⇧T" have 1: "w ⊓ -?p ≤ forest_components ?w" by (metis forest_components_increasing (*‹(?x::'a::type) ≤ forest_components ?x›*) inf_import_p (*‹(?x::'a::type) ⊓ - (?x ⊓ (?y::'a::type)) = ?x ⊓ - ?y›*) le_supE (*‹⟦(?a::'a::type) ⊔ (?b::'a::type) ≤ (?x::'a::type); ⟦?a ≤ ?x; ?b ≤ ?x⟧ ⟹ ?P::bool⟧ ⟹ ?P›*)) have "w ⊓ ?p ≤ ?w⇧T" by (simp add: conv_dist_sup (*‹(?x ⊔ ?y)⇧T = ?x⇧T ⊔ ?y⇧T›*)) also (*calculation: ‹(w::'a) ⊓ (w ⊓ (q::'a)) ≤ (w ⊓ - q ⊔ (w ⊓ q)⇧T)⇧T›*) have "... ≤ forest_components ?w" by (metis assms( (*‹injective (w ⊓ - q ⊔ (w ⊓ q)⇧T)›*) 1) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) forest_components_equivalence (*‹injective ?x ⟹ equivalence (forest_components ?x)›*) forest_components_increasing (*‹?x ≤ forest_components ?x›*)) finally (*calculation: ‹w ⊓ (w ⊓ q) ≤ forest_components (w ⊓ - q ⊔ (w ⊓ q)⇧T)›*) have "w ⊓ (?p ⊔ -?p) ≤ forest_components ?w" using "1" (*‹w ⊓ - (w ⊓ q) ≤ forest_components (w ⊓ - q ⊔ (w ⊓ q)⇧T)›*) inf_sup_distrib1 (*‹?x ⊓ (?y ⊔ ?z) = ?x ⊓ ?y ⊔ ?x ⊓ ?z›*) by simp hence "w ≤ forest_components ?w" by (metis assms( (*‹regular (w ⊓ q)›*) 2) inf_top_right (*‹?x ⊓ top = ?x›*) stone (*‹- ?x ⊔ - - ?x = top›*)) hence 2: "w⇧⋆ ≤ forest_components ?w" using assms(1) (*‹injective (w ⊓ - q ⊔ (w ⊓ q)⇧T)›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) forest_components_star (*‹injective (?x::'a::type) ⟹ forest_components ?x⇧⋆ = forest_components ?x›*) by force hence 3: "w⇧T⇧⋆ ≤ forest_components ?w" using assms(1) (*‹injective (w ⊓ - q ⊔ (w ⊓ q)⇧T)›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) forest_components_equivalence (*‹injective ?x ⟹ equivalence (forest_components ?x)›*) by force have "components g ≤ forest_components w" using assms(3) (*‹components g ≤ forest_components w›*) by simp also (*calculation: ‹components g ≤ forest_components w›*) have "... ≤ forest_components ?w * forest_components ?w" using "2" (*‹w⇧⋆ ≤ forest_components (w ⊓ - q ⊔ (w ⊓ q)⇧T)›*) "3" (*‹w⇧T⇧⋆ ≤ forest_components (w ⊓ - q ⊔ (w ⊓ q)⇧T)›*) mult_isotone (*‹⟦?w ≤ ?y; ?x ≤ ?z⟧ ⟹ ?w * ?x ≤ ?y * ?z›*) by simp also (*calculation: ‹components g ≤ forest_components (w ⊓ - q ⊔ (w ⊓ q)⇧T) * forest_components (w ⊓ - q ⊔ (w ⊓ q)⇧T)›*) have "... = forest_components ?w" using assms(1) (*‹injective ((w::'a) ⊓ - (q::'a) ⊔ (w ⊓ q)⇧T)›*) forest_components_equivalence (*‹injective (?x::'a) ⟹ equivalence (forest_components ?x)›*) preorder_idempotent (*‹preorder ?x ⟹ idempotent ?x›*) by simp finally (*calculation: ‹components g ≤ forest_components (w ⊓ - q ⊔ (w ⊓ q)⇧T)›*) show "?thesis" (*goal: ‹components g ≤ forest_components (w ⊓ - q ⊔ (w ⊓ q)⇧T)›*) by simp qed lemma kruskal_exchange_spanning_inv_2: assumes "injective w" and "w⇧⋆ * e⇧T = e⇧T" and "f ⊔ f⇧T ≤ (w ⊓ -d ⊓ -d⇧T) ⊔ (w⇧T ⊓ -d ⊓ -d⇧T)" and "d ≤ forest_components f * e⇧T * top" shows "d ≤ (w ⊓ -d)⇧T⇧⋆ * e⇧T * top" proof (-) (*goal: ‹d ≤ (w ⊓ - d)⇧T⇧⋆ * e⇧T * top›*) have 1: "(w ⊓ -d ⊓ -d⇧T) * (w⇧T ⊓ -d ⊓ -d⇧T) ≤ 1" using assms(1) (*‹injective w›*) comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) order.trans (*‹⟦?a ≤ ?b; ?b ≤ ?c⟧ ⟹ ?a ≤ ?c›*) inf.cobounded1 (*‹?a ⊓ ?b ≤ ?a›*) by blast have "d ≤ forest_components f * e⇧T * top" using assms(4) (*‹d ≤ forest_components f * e⇧T * top›*) by simp also (*calculation: ‹(d::'a) ≤ forest_components (f::'a) * (e::'a)⇧T * top›*) have "... ≤ (f ⊔ f⇧T)⇧⋆ * (f ⊔ f⇧T)⇧⋆ * e⇧T * top" by (simp add: comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) also (*calculation: ‹d ≤ (f ⊔ f⇧T)⇧⋆ * (f ⊔ f⇧T)⇧⋆ * e⇧T * top›*) have "... = (f ⊔ f⇧T)⇧⋆ * e⇧T * top" by (simp add: star.circ_transitive_equal (*‹idempotent (?x⇧⋆)›*)) also (*calculation: ‹(d::'a::type) ≤ ((f::'a::type) ⊔ f⇧T)⇧⋆ * (e::'a::type)⇧T * top›*) have "... ≤ ((w ⊓ -d ⊓ -d⇧T) ⊔ (w⇧T ⊓ -d ⊓ -d⇧T))⇧⋆ * e⇧T * top" using assms(3) (*‹f ⊔ f⇧T ≤ w ⊓ - d ⊓ - d⇧T ⊔ w⇧T ⊓ - d ⊓ - d⇧T›*) by (simp add: comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) also (*calculation: ‹d ≤ (w ⊓ - d ⊓ - d⇧T ⊔ w⇧T ⊓ - d ⊓ - d⇧T)⇧⋆ * e⇧T * top›*) have "... = (w⇧T ⊓ -d ⊓ -d⇧T)⇧⋆ * (w ⊓ -d ⊓ -d⇧T)⇧⋆ * e⇧T * top" using "1" (*‹coreflexive ((w ⊓ - d ⊓ - d⇧T) * (w⇧T ⊓ - d ⊓ - d⇧T))›*) cancel_separate_1 (*‹coreflexive (?x * ?y) ⟹ (?x ⊔ ?y)⇧⋆ = ?y⇧⋆ * ?x⇧⋆›*) by simp also (*calculation: ‹d ≤ (w⇧T ⊓ - d ⊓ - d⇧T)⇧⋆ * (w ⊓ - d ⊓ - d⇧T)⇧⋆ * e⇧T * top›*) have "... ≤ (w⇧T ⊓ -d ⊓ -d⇧T)⇧⋆ * w⇧⋆ * e⇧T * top" by (simp add: inf_assoc (*‹(?x::'a) ⊓ (?y::'a) ⊓ (?z::'a) = ?x ⊓ (?y ⊓ ?z)›*) mult_left_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x * (?z::'a) ≤ ?y * ?z›*) mult_right_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ (?z::'a) * ?x ≤ ?z * ?y›*) star_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) also (*calculation: ‹(d::'a) ≤ ((w::'a)⇧T ⊓ - d ⊓ - d⇧T)⇧⋆ * w⇧⋆ * (e::'a)⇧T * top›*) have "... = (w⇧T ⊓ -d ⊓ -d⇧T)⇧⋆ * e⇧T * top" using assms(2) (*‹w⇧⋆ * e⇧T = e⇧T›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) by simp also (*calculation: ‹d ≤ (w⇧T ⊓ - d ⊓ - d⇧T)⇧⋆ * e⇧T * top›*) have "... ≤ (w⇧T ⊓ -d⇧T)⇧⋆ * e⇧T * top" using mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) comp_inf.mult_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊓ ?x ≤ ?z ⊓ ?y›*) inf.cobounded2 (*‹?a ⊓ ?b ≤ ?b›*) inf.left_commute (*‹?b ⊓ (?a ⊓ ?c) = ?a ⊓ (?b ⊓ ?c)›*) inf.sup_monoid.add_commute (*‹?a ⊓ ?b = ?b ⊓ ?a›*) by presburger also (*calculation: ‹(d::'a::type) ≤ ((w::'a::type)⇧T ⊓ - d⇧T)⇧⋆ * (e::'a::type)⇧T * top›*) have "... = (w ⊓ -d)⇧T⇧⋆ * e⇧T * top" using conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) conv_dist_inf (*‹((?x::'a) ⊓ (?y::'a))⇧T = ?x⇧T ⊓ ?y⇧T›*) by presburger finally (*calculation: ‹d ≤ (w ⊓ - d)⇧T⇧⋆ * e⇧T * top›*) show "?thesis" (*goal: ‹d ≤ (w ⊓ - d)⇧T⇧⋆ * e⇧T * top›*) by simp qed lemma kruskal_spanning_inv_1: assumes "e ≤ F" and "regular e" and "components (-h ⊓ g) ≤ F" and "equivalence F" shows "components (-(h ⊓ -e ⊓ -e⇧T) ⊓ g) ≤ F" proof (-) (*goal: ‹components (- (h ⊓ - e ⊓ - e⇧T) ⊓ g) ≤ F›*) have 1: "F * F ≤ F" using assms(4) (*‹equivalence F›*) by simp hence 2: "e * F ≤ F" using assms(1) (*‹(e::'a) ≤ (F::'a)›*) mult_left_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x * (?z::'a) ≤ ?y * ?z›*) order_lesseq_imp (*‹(∀z≥?x. ?y ≤ z) = (?y ≤ ?x)›*) by blast have "e⇧T * F ≤ F" by (metis assms( (*‹e ≤ F› ‹equivalence F›*) 1,4) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) preorder_idempotent (*‹preorder ?x ⟹ idempotent ?x›*)) hence 3: "(F ⊔ e ⊔ e⇧T) * F ≤ F" using "1" (*‹transitive F›*) "2" (*‹(e::'a) * (F::'a) ≤ F›*) mult_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*) by simp have "components (-(h ⊓ -e ⊓ -e⇧T) ⊓ g) ≤ ((-h ⊓ --g) ⊔ e ⊔ e⇧T)⇧⋆" by (metis assms( (*‹regular e›*) 2) comp_inf.mult_left_sub_dist_sup_left (*‹?x ⊓ ?y ≤ ?x ⊓ (?y ⊔ ?z)›*) conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) p_dist_inf (*‹- (?x ⊓ ?y) = - ?x ⊔ - ?y›*) pp_dist_inf (*‹- - (?x ⊓ ?y) = - - ?x ⊓ - - ?y›*) regular_closed_p (*‹regular (- ?x)›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) sup_inf_distrib2 (*‹?y ⊓ ?z ⊔ ?x = (?y ⊔ ?x) ⊓ (?z ⊔ ?x)›*) sup_monoid.add_assoc (*‹?a ⊔ ?b ⊔ ?c = ?a ⊔ (?b ⊔ ?c)›*)) also (*calculation: ‹components (- (h ⊓ - e ⊓ - e⇧T) ⊓ g) ≤ (- h ⊓ - - g ⊔ e ⊔ e⇧T)⇧⋆›*) have "... ≤ ((-h ⊓ --g)⇧⋆ ⊔ e ⊔ e⇧T)⇧⋆" using sup_left_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x ⊔ (?z::'a) ≤ ?y ⊔ ?z›*) star.circ_increasing (*‹?x ≤ ?x⇧⋆›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) by simp also (*calculation: ‹components (- (h ⊓ - e ⊓ - e⇧T) ⊓ g) ≤ ((- h ⊓ - - g)⇧⋆ ⊔ e ⊔ e⇧T)⇧⋆›*) have "... ≤ (F ⊔ e ⊔ e⇧T)⇧⋆" using assms(3) (*‹components (- h ⊓ g) ≤ F›*) sup_left_isotone (*‹?x ≤ ?y ⟹ ?x ⊔ ?z ≤ ?y ⊔ ?z›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) by simp also (*calculation: ‹components (- (h ⊓ - e ⊓ - e⇧T) ⊓ g) ≤ (F ⊔ e ⊔ e⇧T)⇧⋆›*) have "... ≤ F" using "3" (*‹(F ⊔ e ⊔ e⇧T) * F ≤ F›*) assms(4) (*‹equivalence F›*) star_left_induct (*‹(?z::'a) ⊔ (?y::'a) * (?x::'a) ≤ ?x ⟶ ?y⇧⋆ * ?z ≤ ?x›*) by force finally (*calculation: ‹components (- (h ⊓ - e ⊓ - e⇧T) ⊓ g) ≤ F›*) show "?thesis" (*goal: ‹components (- (h ⊓ - e ⊓ - e⇧T) ⊓ g) ≤ F›*) by simp qed lemma kruskal_reroot_edge: assumes "injective (e⇧T * top)" and "acyclic w" shows "((w ⊓ -(top * e * w⇧T⇧⋆)) ⊔ (w ⊓ top * e * w⇧T⇧⋆)⇧T) * e⇧T = bot" proof (-) (*goal: ‹((w::'a) ⊓ - (top * (e::'a) * w⇧T⇧⋆) ⊔ (w ⊓ top * e * w⇧T⇧⋆)⇧T) * e⇧T = bot›*) let ?q = "top * e * w⇧T⇧⋆" let ?p = "w ⊓ ?q" let ?w = "(w ⊓ -?q) ⊔ ?p⇧T" have "(w ⊓ -?q) * e⇧T * top = w * (e⇧T * top ⊓ -?q⇧T)" by (metis comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_inf_vector_1 (*‹(?x ⊓ top * ?y) * ?z = ?x * (?z ⊓ (top * ?y)⇧T)›*) conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) covector_complement_closed (*‹covector ?x ⟹ covector (- ?x)›*) vector_top_closed (*‹surjective top›*)) also (*calculation: ‹((w::'a) ⊓ - (top * (e::'a) * w⇧T⇧⋆)) * e⇧T * top = w * (e⇧T * top ⊓ - (top * e * w⇧T⇧⋆)⇧T)›*) have "... = w * (e⇧T * top ⊓ -(w⇧⋆ * e⇧T * top))" by (simp add: conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹(w ⊓ - (top * e * w⇧T⇧⋆)) * e⇧T * top = w * (e⇧T * top ⊓ - (w⇧⋆ * e⇧T * top))›*) have "... = bot" by (metis comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_inf.semiring.mult_not_zero (*‹?a ⊓ ?b ≠ bot ⟹ ?a ≠ bot ∧ ?b ≠ bot›*) inf.sup_relative_same_increasing (*‹⟦?y ≤ ?x; ?x ⊓ ?z = ?x ⊓ ?w⟧ ⟹ ?y ⊓ ?z = ?y ⊓ ?w›*) inf_p (*‹?x ⊓ - ?x = bot›*) mult_right_zero (*‹?x * bot = bot›*) star.circ_loop_fixpoint (*‹?y * (?y⇧⋆ * ?z) ⊔ ?z = ?y⇧⋆ * ?z›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*) sup_left_divisibility (*‹(?x ≤ ?y) = (∃z. ?x ⊔ z = ?y)›*)) finally (*calculation: ‹(w ⊓ - (top * e * w⇧T⇧⋆)) * e⇧T * top = bot›*) have 1: "(w ⊓ -?q) * e⇧T * top = bot" by simp have "?p⇧T * e⇧T * top = (w⇧T ⊓ w⇧⋆ * e⇧T * top) * e⇧T * top" by (simp add: conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*)) also (*calculation: ‹(w ⊓ top * e * w⇧T⇧⋆)⇧T * e⇧T * top = (w⇧T ⊓ w⇧⋆ * e⇧T * top) * e⇧T * top›*) have "... = w⇧⋆ * e⇧T * top ⊓ w⇧T * e⇧T * top" by (simp add: inf_vector_comp (*‹(?x ⊓ ?y * top) * ?z = ?y * top ⊓ ?x * ?z›*) vector_export_comp (*‹(?x * top ⊓ ?y) * ?z = ?x * top ⊓ ?y * ?z›*)) also (*calculation: ‹(w ⊓ top * e * w⇧T⇧⋆)⇧T * e⇧T * top = w⇧⋆ * e⇧T * top ⊓ w⇧T * e⇧T * top›*) have "... = (w⇧⋆ ⊓ w⇧T) * e⇧T * top" using assms(1) (*‹injective (e⇧T * top)›*) injective_comp_right_dist_inf (*‹injective ?z ⟹ (?x ⊓ ?y) * ?z = ?x * ?z ⊓ ?y * ?z›*) mult_assoc (*‹(?a::'a::type) * (?b::'a::type) * (?c::'a::type) = ?a * (?b * ?c)›*) by simp also (*calculation: ‹(w ⊓ top * e * w⇧T⇧⋆)⇧T * e⇧T * top = (w⇧⋆ ⊓ w⇧T) * e⇧T * top›*) have "... = bot" using assms(2) (*‹pd_kleene_allegory_class.acyclic w›*) acyclic_star_below_complement_1 (*‹pd_kleene_allegory_class.acyclic ?w = (?w⇧⋆ ⊓ ?w⇧T = bot)›*) semiring.mult_not_zero (*‹?a * ?b ≠ bot ⟹ ?a ≠ bot ∧ ?b ≠ bot›*) by blast finally (*calculation: ‹(w ⊓ top * e * w⇧T⇧⋆)⇧T * e⇧T * top = bot›*) have "?w * e⇧T * top = bot" using "1" (*‹(w ⊓ - (top * e * w⇧T⇧⋆)) * e⇧T * top = bot›*) mult_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*) by simp thus "?thesis" (*goal: ‹(w ⊓ - (top * e * w⇧T⇧⋆) ⊔ (w ⊓ top * e * w⇧T⇧⋆)⇧T) * e⇧T = bot›*) by (metis star.circ_top (*‹top⇧⋆ = top›*) star_absorb (*‹?x * ?y = bot ⟹ ?x * ?y⇧⋆ = ?x›*)) qed subsubsection ‹Exchange gives Minimum Spanning Trees› text ‹ The lemmas in this section are used to show that the after exchange we obtain a minimum spanning tree. The following lemmas show that the relation characterising the edge across the cut is an arc. › lemma kruskal_edge_arc: assumes "equivalence F" and "forest w" and "arc e" and "regular F" and "F ≤ forest_components (F ⊓ w)" and "regular w" and "w * e⇧T = bot" and "e * F * e = bot" and "e⇧T ≤ w⇧⋆" shows "arc (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * -F)" proof (unfold arc_expanded (*‹arc ?x = (coreflexive (?x * top * ?x⇧T) ∧ coreflexive (?x⇧T * top * ?x) ∧ times_top_class.total (top * ?x))›*), intro conjI (*‹⟦?P::bool; ?Q::bool⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹coreflexive ((w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T)› 2. ‹coreflexive ((w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F))› 3. ‹times_top_class.total (top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F))›*) let ?E = "top * e⇧T * w⇧T⇧⋆" let ?F = "F * e⇧T * top" let ?G = "top * e * -F" let ?FF = "F * e⇧T * e * F" let ?GG = "-F * e⇧T * e * -F" let ?w = "forest_components (F ⊓ w)" have "F ⊓ w⇧T⇧⋆ ≤ forest_components (F ⊓ w) ⊓ w⇧T⇧⋆" by (simp add: assms( (*‹F ≤ forest_components (F ⊓ w)›*) 5) inf.coboundedI1 (*‹?a ≤ ?c ⟹ ?a ⊓ ?b ≤ ?c›*)) also (*calculation: ‹F ⊓ w⇧T⇧⋆ ≤ forest_components (F ⊓ w) ⊓ w⇧T⇧⋆›*) have "... ≤ (F ⊓ w)⇧T⇧⋆ * ((F ⊓ w)⇧⋆ ⊓ w⇧T⇧⋆)" apply (rule inf_star_import (*‹⟦?x ≤ ?z; univalent ?z; reflexive ?y; regular ?z⟧ ⟹ ?x⇧⋆ * ?y ⊓ ?z⇧⋆ ≤ ?x⇧⋆ * (?y ⊓ ?z⇧⋆)›*)) (*goals: 1. ‹(F ⊓ w)⇧T ≤ w⇧T› 2. ‹univalent (w⇧T)› 3. ‹reflexive ((F ⊓ w)⇧⋆)› 4. ‹regular (w⇧T)› discuss goal 1*) apply (simp add: conv_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x⇧T ≤ ?y⇧T›*)) (*discuss goal 2*) apply (simp add: assms( (*‹forest w›*) 2)) (*discuss goal 3*) apply (simp add: star.circ_reflexive (*‹reflexive (?x⇧⋆)›*)) (*discuss goal 4*) apply (metis assms( (*‹regular (w::'a)›*) 6) conv_complement (*‹(- (?x::'a))⇧T = - ?x⇧T›*)) (*proven 4 subgoals*) . also (*calculation: ‹F ⊓ w⇧T⇧⋆ ≤ (F ⊓ w)⇧T⇧⋆ * ((F ⊓ w)⇧⋆ ⊓ w⇧T⇧⋆)›*) have "... ≤ (F ⊓ w)⇧T⇧⋆ * (w⇧⋆ ⊓ w⇧T⇧⋆)" using comp_inf.mult_left_isotone (*‹?x ≤ ?y ⟹ ?x ⊓ ?z ≤ ?y ⊓ ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star_isotone (*‹(?x::'a::type) ≤ (?y::'a::type) ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) by simp also (*calculation: ‹F ⊓ w⇧T⇧⋆ ≤ (F ⊓ w)⇧T⇧⋆ * (w⇧⋆ ⊓ w⇧T⇧⋆)›*) have "... = (F ⊓ w)⇧T⇧⋆" by (simp add: assms( (*‹forest (w::'a::type)›*) 2) acyclic_star_inf_conv (*‹pd_kleene_allegory_class.acyclic (?w::'a::type) ⟹ ?w⇧⋆ ⊓ ?w⇧T⇧⋆ = (1::'a::type)›*)) finally (*calculation: ‹F ⊓ w⇧T⇧⋆ ≤ (F ⊓ w)⇧T⇧⋆›*) have "w * (F ⊓ w⇧T⇧⋆) * e⇧T * e ≤ w * (F ⊓ w)⇧T⇧⋆ * e⇧T * e" by (simp add: mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹(w::'a::type) * ((F::'a::type) ⊓ w⇧T⇧⋆) * (e::'a::type)⇧T * e ≤ w * (F ⊓ w)⇧T⇧⋆ * e⇧T * e›*) have "... = w * e⇧T * e ⊔ w * (F ⊓ w)⇧T⁺ * e⇧T * e" by (metis comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) mult_left_dist_sup (*‹?x * (?y ⊔ ?z) = ?x * ?y ⊔ ?x * ?z›*) star.circ_loop_fixpoint (*‹?y * (?y⇧⋆ * ?z) ⊔ ?z = ?y⇧⋆ * ?z›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*)) also (*calculation: ‹w * (F ⊓ w⇧T⇧⋆) * e⇧T * e ≤ w * e⇧T * e ⊔ w * (F ⊓ w)⇧T⁺ * e⇧T * e›*) have "... = w * (F ⊓ w)⇧T⁺ * e⇧T * e" by (simp add: assms( (*‹w * e⇧T = bot›*) 7)) also (*calculation: ‹w * (F ⊓ w⇧T⇧⋆) * e⇧T * e ≤ w * (F ⊓ w)⇧T⁺ * e⇧T * e›*) have "... ≤ w * (F ⊓ w)⇧T⁺" by (metis assms( (*‹arc e›*) 3) arc_univalent (*‹arc ?x ⟹ univalent ?x›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_1_right (*‹?a * 1 = ?a›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹w * (F ⊓ w⇧T⇧⋆) * e⇧T * e ≤ w * (F ⊓ w)⇧T⁺›*) have "... ≤ w * w⇧T * (F ⊓ w)⇧T⇧⋆" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹w * (F ⊓ w⇧T⇧⋆) * e⇧T * e ≤ w * w⇧T * (F ⊓ w)⇧T⇧⋆›*) have "... ≤ (F ⊓ w)⇧T⇧⋆" using assms(2) (*‹forest w›*) coreflexive_comp_top_inf (*‹coreflexive ?x ⟹ ?x * top ⊓ ?y = ?x * ?y›*) inf.sup_right_divisibility (*‹((?y::'a) ≤ (?x::'a)) = (∃z::'a. z ⊓ ?x = ?y)›*) by auto also (*calculation: ‹w * (F ⊓ w⇧T⇧⋆) * e⇧T * e ≤ (F ⊓ w)⇧T⇧⋆›*) have "... ≤ F⇧T⇧⋆" by (simp add: conv_dist_inf (*‹((?x::'a) ⊓ (?y::'a))⇧T = ?x⇧T ⊓ ?y⇧T›*) star_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) finally (*calculation: ‹(w::'a::type) * ((F::'a::type) ⊓ w⇧T⇧⋆) * (e::'a::type)⇧T * e ≤ F⇧T⇧⋆›*) have 1: "w * (F ⊓ w⇧T⇧⋆) * e⇧T * e ≤ F" by (metis assms( (*‹equivalence F›*) 1) order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*) mult_1_left (*‹1 * ?a = ?a›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) star.circ_plus_same (*‹?x⇧⋆ * ?x = ?x⁺›*) star.circ_reflexive (*‹reflexive (?x⇧⋆)›*) star.left_plus_below_circ (*‹?x⁺ ≤ ?x⇧⋆›*) star_left_induct_mult_iff (*‹(?x * ?y ≤ ?y) = (?x⇧⋆ * ?y ≤ ?y)›*)) have "F * e⇧T * e ≤ forest_components (F ⊓ w) * e⇧T * e" by (simp add: assms( (*‹F ≤ forest_components (F ⊓ w)›*) 5) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) also (*calculation: ‹F * e⇧T * e ≤ forest_components (F ⊓ w) * e⇧T * e›*) have "... ≤ forest_components w * e⇧T * e" by (simp add: comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) also (*calculation: ‹F * e⇧T * e ≤ forest_components w * e⇧T * e›*) have "... = w⇧T⇧⋆ * e⇧T * e" by (metis (no_types) assms( (*‹w * e⇧T = bot›*) 7) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) conv_bot (*‹symmetric bot›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) star_absorb (*‹?x * ?y = bot ⟹ ?x * ?y⇧⋆ = ?x›*)) also (*calculation: ‹(F::'a) * (e::'a)⇧T * e ≤ (w::'a)⇧T⇧⋆ * e⇧T * e›*) have "... ≤ w⇧T⇧⋆" by (metis assms( (*‹arc e›*) 3) arc_univalent (*‹arc ?x ⟹ univalent ?x›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_1_right (*‹?a * 1 = ?a›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) finally (*calculation: ‹F * e⇧T * e ≤ w⇧T⇧⋆›*) have 2: "F * e⇧T * e ≤ w⇧T⇧⋆" by simp have "w * F * e⇧T * e ≤ w * F * e⇧T * e * e⇧T * e" using comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) ex231c (*‹?x ≤ ?x * ?x⇧T * ?x›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) by simp also (*calculation: ‹w * F * e⇧T * e ≤ w * F * e⇧T * e * e⇧T * e›*) have "... = w * (F * e⇧T * e ⊓ w⇧T⇧⋆) * e⇧T * e" using "2" (*‹F * e⇧T * e ≤ w⇧T⇧⋆›*) by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) inf.absorb1 (*‹?a ≤ ?b ⟹ ?a ⊓ ?b = ?a›*)) also (*calculation: ‹w * F * e⇧T * e ≤ w * (F * e⇧T * e ⊓ w⇧T⇧⋆) * e⇧T * e›*) have "... ≤ w * (F ⊓ w⇧T⇧⋆) * e⇧T * e" by (metis assms( (*‹arc e›*) 3) arc_univalent (*‹arc ?x ⟹ univalent ?x›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_1_right (*‹?a * 1 = ?a›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) inf.sup_left_isotone (*‹?y ≤ ?x ⟹ ?y ⊓ ?z ≤ ?x ⊓ ?z›*)) also (*calculation: ‹w * F * e⇧T * e ≤ w * (F ⊓ w⇧T⇧⋆) * e⇧T * e›*) have "... ≤ F" using "1" (*‹w * (F ⊓ w⇧T⇧⋆) * e⇧T * e ≤ F›*) by simp finally (*calculation: ‹w * F * e⇧T * e ≤ F›*) have 3: "w * F * e⇧T * e ≤ F" by simp hence "e⇧T * e * F * w⇧T ≤ F" by (metis assms( (*‹equivalence F›*) 1) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) inf.absorb_iff1 (*‹(?a ≤ ?b) = (?a ⊓ ?b = ?a)›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) hence "e⇧T * e * F * w⇧T ≤ e⇧T * top ⊓ F" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹e⇧T * e * F * w⇧T ≤ e⇧T * top ⊓ F›*) have "... ≤ e⇧T * e * F" by (metis conv_involutive (*‹(?x::'a::type)⇧T⇧T = ?x›*) dedekind_1 (*‹(?x::'a::type) * (?y::'a::type) ⊓ (?z::'a::type) ≤ ?x * (?y ⊓ ?x⇧T * ?z)›*) inf_top_left (*‹top ⊓ (?x::'a::type) = ?x›*) mult_assoc (*‹(?a::'a::type) * (?b::'a::type) * (?c::'a::type) = ?a * (?b * ?c)›*)) finally (*calculation: ‹e⇧T * e * F * w⇧T ≤ e⇧T * e * F›*) have 4: "e⇧T * e * F * w⇧T ≤ e⇧T * e * F" by simp have "(top * e)⇧T * (?F ⊓ w⇧T⇧⋆) = e⇧T * top * e * F * w⇧T⇧⋆" by (metis assms( (*‹equivalence F›*) 1) comp_inf.star.circ_decompose_9 (*‹top = top ⊓ top ⊓ top›*) comp_inf.star_star_absorb (*‹top ⊓ top ⊓ top = top ⊓ top›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_top (*‹symmetric top›*) covector_inf_comp_3 (*‹vector ?x ⟹ (?y ⊓ ?x⇧T) * ?z = ?y * (?x ⊓ ?z)›*) vector_top_closed (*‹surjective top›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹(top * e)⇧T * (F * e⇧T * top ⊓ w⇧T⇧⋆) = e⇧T * top * e * F * w⇧T⇧⋆›*) have "... = e⇧T * e * F * w⇧T⇧⋆" by (simp add: assms( (*‹arc e›*) 3) arc_top_edge (*‹arc ?x ⟹ ?x⇧T * top * ?x = ?x⇧T * ?x›*)) also (*calculation: ‹(top * e)⇧T * (F * e⇧T * top ⊓ w⇧T⇧⋆) = e⇧T * e * F * w⇧T⇧⋆›*) have "... ≤ e⇧T * e * F" using "4" (*‹e⇧T * e * F * w⇧T ≤ e⇧T * e * F›*) star_right_induct_mult (*‹?y * ?x ≤ ?y ⟹ ?y * ?x⇧⋆ ≤ ?y›*) by simp also (*calculation: ‹(top * e)⇧T * (F * e⇧T * top ⊓ w⇧T⇧⋆) ≤ e⇧T * e * F›*) have "... ≤ F" by (metis assms( (*‹arc e›*) 3) arc_injective (*‹arc ?x ⟹ injective ?x›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) mult_1_left (*‹1 * ?a = ?a›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) finally (*calculation: ‹(top * e)⇧T * (F * e⇧T * top ⊓ w⇧T⇧⋆) ≤ F›*) have 5: "(top * e)⇧T * (?F ⊓ w⇧T⇧⋆) ≤ F" by simp have "(?F ⊓ w) * w⇧T⁺ = ?F ⊓ w * w⇧T⁺" by (simp add: vector_export_comp (*‹(?x * top ⊓ ?y) * ?z = ?x * top ⊓ ?y * ?z›*)) also (*calculation: ‹(F * e⇧T * top ⊓ w) * w⇧T⁺ = F * e⇧T * top ⊓ w * w⇧T⁺›*) have "... ≤ ?F ⊓ w⇧T⇧⋆" by (metis assms( (*‹forest w›*) 2) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) inf.sup_right_isotone (*‹?y ≤ ?x ⟹ ?z ⊓ ?y ≤ ?z ⊓ ?x›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) star.circ_transitive_equal (*‹idempotent (?x⇧⋆)›*) star_left_unfold_equal (*‹1 ⊔ ?x⁺ = ?x⇧⋆›*) sup.absorb_iff2 (*‹(?a ≤ ?b) = (?a ⊔ ?b = ?b)›*) sup_monoid.add_assoc (*‹?a ⊔ ?b ⊔ ?c = ?a ⊔ (?b ⊔ ?c)›*)) also (*calculation: ‹(F * e⇧T * top ⊓ w) * w⇧T⁺ ≤ F * e⇧T * top ⊓ w⇧T⇧⋆›*) have 6: "... ≤ top * e * F" using "5" (*‹(top * e)⇧T * (F * e⇧T * top ⊓ w⇧T⇧⋆) ≤ F›*) by (metis assms( (*‹arc e›*) 3) shunt_mapping (*‹mapping ?z ⟹ (?x ≤ ?z * ?y) = (?z⇧T * ?x ≤ ?y)›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_top (*‹symmetric top›*)) finally (*calculation: ‹((F::'a) * (e::'a)⇧T * top ⊓ (w::'a)) * w⇧T⁺ ≤ top * e * F›*) have 7: "(?F ⊓ w) * w⇧T⁺ ≤ top * e * F" by simp have "e⇧T * top * e ≤ 1" by (simp add: assms( (*‹arc e›*) 3) point_injective (*‹arc ?x ⟹ coreflexive (?x⇧T * top * ?x)›*)) also (*calculation: ‹coreflexive ((e::'a)⇧T * top * e)›*) have "... ≤ F" by (simp add: assms( (*‹equivalence (F::'a::type)›*) 1)) finally (*calculation: ‹e⇧T * top * e ≤ F›*) have 8: "e * -F * e⇧T ≤ bot" by (metis p_antitone (*‹?x ≤ ?y ⟹ - ?y ≤ - ?x›*) p_antitone_iff (*‹(?x ≤ - ?y) = (?y ≤ - ?x)›*) p_bot (*‹- bot = top›*) regular_closed_bot (*‹regular bot›*) schroeder_3_p (*‹(?x * ?y ≤ - ?z) = (?x⇧T * ?z ≤ - ?y)›*) schroeder_4_p (*‹(?x * ?y ≤ - ?z) = (?z * ?y⇧T ≤ - ?x)›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) have "?FF ⊓ w * (w⇧T⁺ ⊓ ?GG) * w⇧T ≤ ?F ⊓ w * (w⇧T⁺ ⊓ ?GG) * w⇧T" using comp_inf.mult_left_isotone (*‹?x ≤ ?y ⟹ ?x ⊓ ?z ≤ ?y ⊓ ?z›*) mult_isotone (*‹⟦?w ≤ ?y; ?x ≤ ?z⟧ ⟹ ?w * ?x ≤ ?y * ?z›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) by simp also (*calculation: ‹F * e⇧T * e * F ⊓ w * (w⇧T⁺ ⊓ - F * e⇧T * e * - F) * w⇧T ≤ F * e⇧T * top ⊓ w * (w⇧T⁺ ⊓ - F * e⇧T * e * - F) * w⇧T›*) have "... ≤ ?F ⊓ w * (w⇧T⁺ ⊓ ?G) * w⇧T" by (metis assms( (*‹arc e›*) 3) arc_top_edge (*‹arc ?x ⟹ ?x⇧T * top * ?x = ?x⇧T * ?x›*) comp_inf.star.circ_decompose_9 (*‹top = top ⊓ top ⊓ top›*) comp_inf_covector (*‹?x * (?y ⊓ top * ?z) = ?x * ?y ⊓ top * ?z›*) inf.sup_right_isotone (*‹?y ≤ ?x ⟹ ?z ⊓ ?y ≤ ?z ⊓ ?x›*) inf_le2 (*‹?x ⊓ ?y ≤ ?y›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) vector_top_closed (*‹surjective top›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹F * e⇧T * e * F ⊓ w * (w⇧T⁺ ⊓ - F * e⇧T * e * - F) * w⇧T ≤ F * e⇧T * top ⊓ w * (w⇧T⁺ ⊓ top * e * - F) * w⇧T›*) have "... = (?F ⊓ w) * (w⇧T⁺ ⊓ ?G) * w⇧T" by (simp add: vector_export_comp (*‹((?x::'a) * top ⊓ (?y::'a)) * (?z::'a) = ?x * top ⊓ ?y * ?z›*)) also (*calculation: ‹F * e⇧T * e * F ⊓ w * (w⇧T⁺ ⊓ - F * e⇧T * e * - F) * w⇧T ≤ (F * e⇧T * top ⊓ w) * (w⇧T⁺ ⊓ top * e * - F) * w⇧T›*) have "... = (?F ⊓ w) * w⇧T⁺ * (?G⇧T ⊓ w⇧T)" by (simp add: covector_comp_inf (*‹covector (?z::'a) ⟹ (?x::'a) * ((?y::'a) ⊓ ?z) = ?x * ?y ⊓ ?z›*) covector_comp_inf_1 (*‹covector (?x::'a) ⟹ ((?y::'a) ⊓ ?x) * (?z::'a) = ?y * (?x⇧T ⊓ ?z)›*) covector_mult_closed (*‹covector (?x::'a) ⟹ covector (?x * (?y::'a))›*)) also (*calculation: ‹F * e⇧T * e * F ⊓ w * (w⇧T⁺ ⊓ - F * e⇧T * e * - F) * w⇧T ≤ (F * e⇧T * top ⊓ w) * w⇧T⁺ * ((top * e * - F)⇧T ⊓ w⇧T)›*) have "... ≤ top * e * F * (?G⇧T ⊓ w⇧T)" using "7" (*‹((F::'a) * (e::'a)⇧T * top ⊓ (w::'a)) * w⇧T⁺ ≤ top * e * F›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) by simp also (*calculation: ‹(F::'a) * (e::'a)⇧T * e * F ⊓ (w::'a) * (w⇧T⁺ ⊓ - F * e⇧T * e * - F) * w⇧T ≤ top * e * F * ((top * e * - F)⇧T ⊓ w⇧T)›*) have "... ≤ top * e * F * ?G⇧T" by (simp add: mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹F * e⇧T * e * F ⊓ w * (w⇧T⁺ ⊓ - F * e⇧T * e * - F) * w⇧T ≤ top * e * F * (top * e * - F)⇧T›*) have "... = top * e * -F * e⇧T * top" by (metis assms( (*‹equivalence (F::'a)›*) 1) conv_complement (*‹(- (?x::'a))⇧T = - ?x⇧T›*) conv_dist_comp (*‹((?x::'a) * (?y::'a))⇧T = ?y⇧T * ?x⇧T›*) conv_top (*‹symmetric top›*) equivalence_comp_left_complement (*‹equivalence (?x::'a) ⟹ ?x * - ?x = - ?x›*) mult_assoc (*‹(?a::'a) * (?b::'a) * (?c::'a) = ?a * (?b * ?c)›*)) finally (*calculation: ‹F * e⇧T * e * F ⊓ w * (w⇧T⁺ ⊓ - F * e⇧T * e * - F) * w⇧T ≤ top * e * - F * e⇧T * top›*) have 9: "?FF ⊓ w * (w⇧T⁺ ⊓ ?GG) * w⇧T = bot" using "8" (*‹e * - F * e⇧T ≤ bot›*) by (metis comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) covector_bot_closed (*‹covector bot›*) le_bot (*‹?a ≤ bot ⟹ ?a = bot›*) vector_bot_closed (*‹vector bot›*)) hence 10: "?FF ⊓ w * (w⁺ ⊓ ?GG) * w⇧T = bot" using assms(1) (*‹equivalence F›*) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) conv_bot (*‹symmetric bot›*) conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_dist_inf (*‹((?x::'a) ⊓ (?y::'a))⇧T = ?x⇧T ⊓ ?y⇧T›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) star.circ_plus_same (*‹?x⇧⋆ * ?x = ?x⁺›*) by fastforce have "(w ⊓ ?E ⊓ ?F ⊓ ?G) * top * (w ⊓ ?E ⊓ ?F ⊓ ?G)⇧T = (?F ⊓ (w ⊓ ?E ⊓ ?G)) * top * ((w ⊓ ?E ⊓ ?G)⇧T ⊓ ?F⇧T)" by (simp add: conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) inf_left_commute (*‹?x ⊓ (?y ⊓ ?z) = ?y ⊓ (?x ⊓ ?z)›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T = (F * e⇧T * top ⊓ (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F)) * top * ((w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F)⇧T ⊓ (F * e⇧T * top)⇧T)›*) have "... = (?F ⊓ (w ⊓ ?E ⊓ ?G)) * top * (w ⊓ ?E ⊓ ?G)⇧T ⊓ ?F⇧T" using covector_comp_inf (*‹covector ?z ⟹ ?x * (?y ⊓ ?z) = ?x * ?y ⊓ ?z›*) vector_conv_covector (*‹vector (?v::'a) = covector (?v⇧T)›*) vector_mult_closed (*‹vector ?y ⟹ vector (?x * ?y)›*) vector_top_closed (*‹surjective top›*) by simp also (*calculation: ‹((w::'a::type) ⊓ top * (e::'a::type)⇧T * w⇧T⇧⋆ ⊓ (F::'a::type) * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T = (F * e⇧T * top ⊓ (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F)) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F)⇧T ⊓ (F * e⇧T * top)⇧T›*) have "... = ?F ⊓ (w ⊓ ?E ⊓ ?G) * top * (w ⊓ ?E ⊓ ?G)⇧T ⊓ ?F⇧T" by (simp add: vector_export_comp (*‹(?x * top ⊓ ?y) * ?z = ?x * top ⊓ ?y * ?z›*)) also (*calculation: ‹((w::'a) ⊓ top * (e::'a)⇧T * w⇧T⇧⋆ ⊓ (F::'a) * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T = F * e⇧T * top ⊓ (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F)⇧T ⊓ (F * e⇧T * top)⇧T›*) have "... = ?F ⊓ top * e * F ⊓ (w ⊓ ?E ⊓ ?G) * top * (w ⊓ ?E ⊓ ?G)⇧T" by (simp add: assms( (*‹equivalence F›*) 1) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) inf_assoc (*‹?x ⊓ ?y ⊓ ?z = ?x ⊓ (?y ⊓ ?z)›*) inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T = F * e⇧T * top ⊓ top * e * F ⊓ (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F)⇧T›*) have "... = ?F * e * F ⊓ (w ⊓ ?E ⊓ ?G) * top * (w ⊓ ?E ⊓ ?G)⇧T" by (metis comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*) comp_inf_covector (*‹(?x::'a) * ((?y::'a) ⊓ top * (?z::'a)) = ?x * ?y ⊓ top * ?z›*) inf_top.left_neutral (*‹top ⊓ (?a::'a) = ?a›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T = F * e⇧T * top * e * F ⊓ (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F)⇧T›*) have "... = ?FF ⊓ (w ⊓ ?E ⊓ ?G) * (top * (w ⊓ ?E ⊓ ?G)⇧T)" using assms(3) (*‹arc e›*) arc_top_edge (*‹arc ?x ⟹ ?x⇧T * top * ?x = ?x⇧T * ?x›*) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) by simp also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T = F * e⇧T * e * F ⊓ (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F) * (top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F)⇧T)›*) have "... = ?FF ⊓ (w ⊓ ?E ⊓ ?G) * (top * (?G⇧T ⊓ (?E⇧T ⊓ w⇧T)))" by (simp add: conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) inf_assoc (*‹?x ⊓ ?y ⊓ ?z = ?x ⊓ (?y ⊓ ?z)›*) inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) inf_left_commute (*‹?x ⊓ (?y ⊓ ?z) = ?y ⊓ (?x ⊓ ?z)›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T = F * e⇧T * e * F ⊓ (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F) * (top * ((top * e * - F)⇧T ⊓ ((top * e⇧T * w⇧T⇧⋆)⇧T ⊓ w⇧T)))›*) have "... = ?FF ⊓ (w ⊓ ?E ⊓ ?G) * (?G * (?E⇧T ⊓ w⇧T))" by (metis covector_comp_inf_1 (*‹covector ?x ⟹ (?y ⊓ ?x) * ?z = ?y * (?x⇧T ⊓ ?z)›*) covector_top_closed (*‹surjective top›*) covector_mult_closed (*‹covector ?x ⟹ covector (?x * ?y)›*) inf_top_left (*‹top ⊓ ?x = ?x›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T = F * e⇧T * e * F ⊓ (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F) * (top * e * - F * ((top * e⇧T * w⇧T⇧⋆)⇧T ⊓ w⇧T))›*) have "... = ?FF ⊓ (w ⊓ ?E ⊓ ?G) * (?G ⊓ ?E) * w⇧T" by (metis covector_comp_inf_1 (*‹covector (?x::'a::type) ⟹ ((?y::'a::type) ⊓ ?x) * (?z::'a::type) = ?y * (?x⇧T ⊓ ?z)›*) covector_top_closed (*‹surjective top›*) mult_assoc (*‹(?a::'a::type) * (?b::'a::type) * (?c::'a::type) = ?a * (?b * ?c)›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T = F * e⇧T * e * F ⊓ (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F) * (top * e * - F ⊓ top * e⇧T * w⇧T⇧⋆) * w⇧T›*) have "... = ?FF ⊓ (w ⊓ ?E) * (?G⇧T ⊓ ?G ⊓ ?E) * w⇧T" by (metis covector_comp_inf_1 (*‹covector ?x ⟹ (?y ⊓ ?x) * ?z = ?y * (?x⇧T ⊓ ?z)›*) covector_mult_closed (*‹covector ?x ⟹ covector (?x * ?y)›*) inf.sup_monoid.add_assoc (*‹?a ⊓ ?b ⊓ ?c = ?a ⊓ (?b ⊓ ?c)›*) vector_top_closed (*‹surjective top›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T = F * e⇧T * e * F ⊓ (w ⊓ top * e⇧T * w⇧T⇧⋆) * ((top * e * - F)⇧T ⊓ top * e * - F ⊓ top * e⇧T * w⇧T⇧⋆) * w⇧T›*) have "... = ?FF ⊓ w * (?E⇧T ⊓ ?G⇧T ⊓ ?G ⊓ ?E) * w⇧T" by (metis covector_comp_inf_1 (*‹covector ?x ⟹ (?y ⊓ ?x) * ?z = ?y * (?x⇧T ⊓ ?z)›*) covector_mult_closed (*‹covector ?x ⟹ covector (?x * ?y)›*) inf.sup_monoid.add_assoc (*‹?a ⊓ ?b ⊓ ?c = ?a ⊓ (?b ⊓ ?c)›*) vector_top_closed (*‹surjective top›*)) also (*calculation: ‹((w::'a) ⊓ top * (e::'a)⇧T * w⇧T⇧⋆ ⊓ (F::'a) * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T = F * e⇧T * e * F ⊓ w * ((top * e⇧T * w⇧T⇧⋆)⇧T ⊓ (top * e * - F)⇧T ⊓ top * e * - F ⊓ top * e⇧T * w⇧T⇧⋆) * w⇧T›*) have "... = ?FF ⊓ w * (?E⇧T ⊓ ?E ⊓ (?G⇧T ⊓ ?G)) * w⇧T" by (simp add: inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) inf_left_commute (*‹?x ⊓ (?y ⊓ ?z) = ?y ⊓ (?x ⊓ ?z)›*)) also (*calculation: ‹((w::'a::type) ⊓ top * (e::'a::type)⇧T * w⇧T⇧⋆ ⊓ (F::'a::type) * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T = F * e⇧T * e * F ⊓ w * ((top * e⇧T * w⇧T⇧⋆)⇧T ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ ((top * e * - F)⇧T ⊓ top * e * - F)) * w⇧T›*) have "... = ?FF ⊓ w * (?E⇧T ⊓ ?E ⊓ (-F * e⇧T * top ⊓ ?G)) * w⇧T" by (simp add: assms( (*‹equivalence F›*) 1) conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T = F * e⇧T * e * F ⊓ w * ((top * e⇧T * w⇧T⇧⋆)⇧T ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ (- F * e⇧T * top ⊓ top * e * - F)) * w⇧T›*) have "... = ?FF ⊓ w * (?E⇧T ⊓ ?E ⊓ (-F * e⇧T * ?G)) * w⇧T" by (metis comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_inf_covector (*‹?x * (?y ⊓ top * ?z) = ?x * ?y ⊓ top * ?z›*) inf_top.left_neutral (*‹top ⊓ ?a = ?a›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T = F * e⇧T * e * F ⊓ w * ((top * e⇧T * w⇧T⇧⋆)⇧T ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ - F * e⇧T * (top * e * - F)) * w⇧T›*) have "... = ?FF ⊓ w * (?E⇧T ⊓ ?E ⊓ ?GG) * w⇧T" by (metis assms( (*‹arc e›*) 3) arc_top_edge (*‹arc ?x ⟹ ?x⇧T * top * ?x = ?x⇧T * ?x›*) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T = F * e⇧T * e * F ⊓ w * ((top * e⇧T * w⇧T⇧⋆)⇧T ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ - F * e⇧T * e * - F) * w⇧T›*) have "... = ?FF ⊓ w * (w⇧⋆ * e * top ⊓ ?E ⊓ ?GG) * w⇧T" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T = F * e⇧T * e * F ⊓ w * (w⇧⋆ * e * top ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ - F * e⇧T * e * - F) * w⇧T›*) have "... = ?FF ⊓ w * (w⇧⋆ * e * ?E ⊓ ?GG) * w⇧T" by (metis comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_inf_covector (*‹?x * (?y ⊓ top * ?z) = ?x * ?y ⊓ top * ?z›*) inf_top.left_neutral (*‹top ⊓ ?a = ?a›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T = F * e⇧T * e * F ⊓ w * (w⇧⋆ * e * (top * e⇧T * w⇧T⇧⋆) ⊓ - F * e⇧T * e * - F) * w⇧T›*) have "... ≤ ?FF ⊓ w * (w⇧⋆ * w⇧T⇧⋆ ⊓ ?GG) * w⇧T" by (metis assms( (*‹arc e›*) 3) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_1_right (*‹?a * 1 = ?a›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) inf.sup_left_isotone (*‹?y ≤ ?x ⟹ ?y ⊓ ?z ≤ ?x ⊓ ?z›*) inf.sup_right_isotone (*‹?y ≤ ?x ⟹ ?z ⊓ ?y ≤ ?z ⊓ ?x›*) arc_expanded (*‹arc ?x = (coreflexive (?x * top * ?x⇧T) ∧ coreflexive (?x⇧T * top * ?x) ∧ times_top_class.total (top * ?x))›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T ≤ F * e⇧T * e * F ⊓ w * (w⇧⋆ * w⇧T⇧⋆ ⊓ - F * e⇧T * e * - F) * w⇧T›*) have "... = ?FF ⊓ w * ((w⁺ ⊔ 1 ⊔ w⇧T⇧⋆) ⊓ ?GG) * w⇧T" by (simp add: assms( (*‹forest w›*) 2) cancel_separate_eq (*‹coreflexive (?x * ?y) ⟹ ?x⇧⋆ * ?y⇧⋆ = ?x⇧⋆ ⊔ ?y⇧⋆›*) star_left_unfold_equal (*‹1 ⊔ ?x⁺ = ?x⇧⋆›*) sup_monoid.add_commute (*‹?a ⊔ ?b = ?b ⊔ ?a›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T ≤ F * e⇧T * e * F ⊓ w * ((w⁺ ⊔ 1 ⊔ w⇧T⇧⋆) ⊓ - F * e⇧T * e * - F) * w⇧T›*) have "... = ?FF ⊓ w * ((w⁺ ⊔ 1 ⊔ w⇧T⁺) ⊓ ?GG) * w⇧T" using star.circ_plus_one (*‹?x⇧⋆ = 1 ⊔ ?x⇧⋆›*) star_left_unfold_equal (*‹1 ⊔ ?x⁺ = ?x⇧⋆›*) sup_assoc (*‹(?x::'a::type) ⊔ (?y::'a::type) ⊔ (?z::'a::type) = ?x ⊔ (?y ⊔ ?z)›*) by presburger also (*calculation: ‹((w::'a::type) ⊓ top * (e::'a::type)⇧T * w⇧T⇧⋆ ⊓ (F::'a::type) * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T ≤ F * e⇧T * e * F ⊓ w * ((w⁺ ⊔ (1::'a::type) ⊔ w⇧T⁺) ⊓ - F * e⇧T * e * - F) * w⇧T›*) have "... = (?FF ⊓ w * (w⁺ ⊓ ?GG) * w⇧T) ⊔ (?FF ⊓ w * (1 ⊓ ?GG) * w⇧T) ⊔ (?FF ⊓ w * (w⇧T⁺ ⊓ ?GG) * w⇧T)" by (simp add: inf_sup_distrib1 (*‹?x ⊓ (?y ⊔ ?z) = ?x ⊓ ?y ⊔ ?x ⊓ ?z›*) inf_sup_distrib2 (*‹(?y ⊔ ?z) ⊓ ?x = ?y ⊓ ?x ⊔ ?z ⊓ ?x›*) semiring.distrib_left (*‹?a * (?b ⊔ ?c) = ?a * ?b ⊔ ?a * ?c›*) semiring.distrib_right (*‹(?a ⊔ ?b) * ?c = ?a * ?c ⊔ ?b * ?c›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T ≤ F * e⇧T * e * F ⊓ w * (w⁺ ⊓ - F * e⇧T * e * - F) * w⇧T ⊔ F * e⇧T * e * F ⊓ w * (1 ⊓ - F * e⇧T * e * - F) * w⇧T ⊔ F * e⇧T * e * F ⊓ w * (w⇧T⁺ ⊓ - F * e⇧T * e * - F) * w⇧T›*) have "... ≤ w * (1 ⊓ ?GG) * w⇧T" using "9" (*‹F * e⇧T * e * F ⊓ w * (w⇧T⁺ ⊓ - F * e⇧T * e * - F) * w⇧T = bot›*) "10" (*‹F * e⇧T * e * F ⊓ w * (w⁺ ⊓ - F * e⇧T * e * - F) * w⇧T = bot›*) by simp also (*calculation: ‹((w::'a::type) ⊓ top * (e::'a::type)⇧T * w⇧T⇧⋆ ⊓ (F::'a::type) * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T ≤ w * ((1::'a::type) ⊓ - F * e⇧T * e * - F) * w⇧T›*) have "... ≤ w * w⇧T" by (metis inf.cobounded1 (*‹?a ⊓ ?b ≤ ?a›*) mult_1_right (*‹?a * 1 = ?a›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹((w::'a::type) ⊓ top * (e::'a::type)⇧T * w⇧T⇧⋆ ⊓ (F::'a::type) * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T ≤ w * w⇧T›*) have "... ≤ 1" by (simp add: assms( (*‹forest w›*) 2)) finally (*calculation: ‹coreflexive ((w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T)›*) show "(w ⊓ ?E ⊓ ?F ⊓ ?G) * top * (w ⊓ ?E ⊓ ?F ⊓ ?G)⇧T ≤ 1" by simp have "w⇧T⁺ ⊓ -F * e⇧T * e * -F ⊓ w⇧T * F * e⇧T * e * F * w ≤ w⇧T⁺ ⊓ ?G ⊓ w⇧T * F * e⇧T * e * F * w" using top_greatest (*‹?x ≤ top›*) inf.sup_left_isotone (*‹?y ≤ ?x ⟹ ?y ⊓ ?z ≤ ?x ⊓ ?z›*) inf.sup_right_isotone (*‹?y ≤ ?x ⟹ ?z ⊓ ?y ≤ ?z ⊓ ?x›*) mult_left_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x * (?z::'a) ≤ ?y * ?z›*) by simp also (*calculation: ‹w⇧T⁺ ⊓ - F * e⇧T * e * - F ⊓ w⇧T * F * e⇧T * e * F * w ≤ w⇧T⁺ ⊓ top * e * - F ⊓ w⇧T * F * e⇧T * e * F * w›*) have "... ≤ w⇧T⁺ ⊓ ?G ⊓ w⇧T * ?F" using comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) inf.sup_right_isotone (*‹(?y::'a::type) ≤ (?x::'a::type) ⟹ (?z::'a::type) ⊓ ?y ≤ ?z ⊓ ?x›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) top.extremum (*‹?a ≤ top›*) by presburger also (*calculation: ‹w⇧T⁺ ⊓ - F * e⇧T * e * - F ⊓ w⇧T * F * e⇧T * e * F * w ≤ w⇧T⁺ ⊓ top * e * - F ⊓ w⇧T * (F * e⇧T * top)›*) have "... = w⇧T * (w⇧T⇧⋆ ⊓ ?F) ⊓ ?G" using assms(2) (*‹forest w›*) inf_assoc (*‹?x ⊓ ?y ⊓ ?z = ?x ⊓ (?y ⊓ ?z)›*) inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) inf_left_commute (*‹?x ⊓ (?y ⊓ ?z) = ?y ⊓ (?x ⊓ ?z)›*) univalent_comp_left_dist_inf (*‹univalent ?x ⟹ ?x * (?y ⊓ ?z) = ?x * ?y ⊓ ?x * ?z›*) by simp also (*calculation: ‹w⇧T⁺ ⊓ - F * e⇧T * e * - F ⊓ w⇧T * F * e⇧T * e * F * w ≤ w⇧T * (w⇧T⇧⋆ ⊓ F * e⇧T * top) ⊓ top * e * - F›*) have "... ≤ w⇧T * (top * e * F) ⊓ ?G" using "6" (*‹F * e⇧T * top ⊓ w⇧T⇧⋆ ≤ top * e * F›*) by (metis inf.sup_monoid.add_commute (*‹?a ⊓ ?b = ?b ⊓ ?a›*) inf.sup_right_isotone (*‹?y ≤ ?x ⟹ ?z ⊓ ?y ≤ ?z ⊓ ?x›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹(w::'a)⇧T⁺ ⊓ - (F::'a) * (e::'a)⇧T * e * - F ⊓ w⇧T * F * e⇧T * e * F * w ≤ w⇧T * (top * e * F) ⊓ top * e * - F›*) have "... ≤ top * e * F ⊓ ?G" by (metis comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_inf_covector (*‹?x * (?y ⊓ top * ?z) = ?x * ?y ⊓ top * ?z›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) top.extremum (*‹?a ≤ top›*)) also (*calculation: ‹w⇧T⁺ ⊓ - F * e⇧T * e * - F ⊓ w⇧T * F * e⇧T * e * F * w ≤ top * e * F ⊓ top * e * - F›*) have "... = bot" by (metis assms( (*‹arc e›*) 3) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_top (*‹symmetric top›*) inf_p (*‹?x ⊓ - ?x = bot›*) mult_right_zero (*‹?x * bot = bot›*) univalent_comp_left_dist_inf (*‹univalent ?x ⟹ ?x * (?y ⊓ ?z) = ?x * ?y ⊓ ?x * ?z›*)) finally (*calculation: ‹w⇧T⁺ ⊓ - F * e⇧T * e * - F ⊓ w⇧T * F * e⇧T * e * F * w ≤ bot›*) have 11: "w⇧T⁺ ⊓ -F * e⇧T * e * -F ⊓ w⇧T * F * e⇧T * e * F * w = bot" by (simp add: order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) hence 12: "w⁺ ⊓ -F * e⇧T * e * -F ⊓ w⇧T * F * e⇧T * e * F * w = bot" using assms(1) (*‹equivalence F›*) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) conv_bot (*‹symmetric bot›*) conv_complement (*‹(- (?x::'a::type))⇧T = - ?x⇧T›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*) star.circ_plus_same (*‹?x⇧⋆ * ?x = ?x⁺›*) by fastforce have "(w ⊓ ?E ⊓ ?F ⊓ ?G)⇧T * top * (w ⊓ ?E ⊓ ?F ⊓ ?G) = ((w ⊓ ?E ⊓ ?G)⇧T ⊓ ?F⇧T) * top * (?F ⊓ (w ⊓ ?E ⊓ ?G))" by (simp add: conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) inf_left_commute (*‹?x ⊓ (?y ⊓ ?z) = ?y ⊓ (?x ⊓ ?z)›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) = ((w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F)⇧T ⊓ (F * e⇧T * top)⇧T) * top * (F * e⇧T * top ⊓ (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F))›*) have "... = (w ⊓ ?E ⊓ ?G)⇧T * ?F * (?F ⊓ (w ⊓ ?E ⊓ ?G))" by (simp add: covector_inf_comp_3 (*‹vector ?x ⟹ (?y ⊓ ?x⇧T) * ?z = ?y * (?x ⊓ ?z)›*) vector_mult_closed (*‹vector ?y ⟹ vector (?x * ?y)›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) = (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F)⇧T * (F * e⇧T * top) * (F * e⇧T * top ⊓ (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F))›*) have "... = (w ⊓ ?E ⊓ ?G)⇧T * (?F ⊓ ?F⇧T) * (w ⊓ ?E ⊓ ?G)" using covector_comp_inf (*‹covector ?z ⟹ ?x * (?y ⊓ ?z) = ?x * ?y ⊓ ?z›*) covector_inf_comp_3 (*‹vector ?x ⟹ (?y ⊓ ?x⇧T) * ?z = ?y * (?x ⊓ ?z)›*) vector_conv_covector (*‹vector (?v::'a) = covector (?v⇧T)›*) vector_mult_closed (*‹vector ?y ⟹ vector (?x * ?y)›*) by simp also (*calculation: ‹((w::'a) ⊓ top * (e::'a)⇧T * w⇧T⇧⋆ ⊓ (F::'a) * e⇧T * top ⊓ top * e * - F)⇧T * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) = (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F)⇧T * (F * e⇧T * top ⊓ (F * e⇧T * top)⇧T) * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F)›*) have "... = (w ⊓ ?E ⊓ ?G)⇧T * (?F ⊓ ?F⇧T) * (w ⊓ ?E) ⊓ ?G" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_inf_covector (*‹?x * (?y ⊓ top * ?z) = ?x * ?y ⊓ top * ?z›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) = (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F)⇧T * (F * e⇧T * top ⊓ (F * e⇧T * top)⇧T) * (w ⊓ top * e⇧T * w⇧T⇧⋆) ⊓ top * e * - F›*) have "... = (w ⊓ ?E ⊓ ?G)⇧T * (?F ⊓ ?F⇧T) * w ⊓ ?E ⊓ ?G" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_inf_covector (*‹?x * (?y ⊓ top * ?z) = ?x * ?y ⊓ top * ?z›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) = (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F)⇧T * (F * e⇧T * top ⊓ (F * e⇧T * top)⇧T) * w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F›*) have "... = (?G⇧T ⊓ (?E⇧T ⊓ w⇧T)) * (?F ⊓ ?F⇧T) * w ⊓ ?E ⊓ ?G" by (simp add: conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) inf.left_commute (*‹?b ⊓ (?a ⊓ ?c) = ?a ⊓ (?b ⊓ ?c)›*) inf.sup_monoid.add_commute (*‹?a ⊓ ?b = ?b ⊓ ?a›*)) also (*calculation: ‹((w::'a) ⊓ top * (e::'a)⇧T * w⇧T⇧⋆ ⊓ (F::'a) * e⇧T * top ⊓ top * e * - F)⇧T * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) = ((top * e * - F)⇧T ⊓ ((top * e⇧T * w⇧T⇧⋆)⇧T ⊓ w⇧T)) * (F * e⇧T * top ⊓ (F * e⇧T * top)⇧T) * w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F›*) have "... = ?G⇧T ⊓ (?E⇧T ⊓ w⇧T) * (?F ⊓ ?F⇧T) * w ⊓ ?E ⊓ ?G" by (metis (no_types) comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_top (*‹symmetric top›*) vector_export_comp (*‹(?x * top ⊓ ?y) * ?z = ?x * top ⊓ ?y * ?z›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) = (top * e * - F)⇧T ⊓ ((top * e⇧T * w⇧T⇧⋆)⇧T ⊓ w⇧T) * (F * e⇧T * top ⊓ (F * e⇧T * top)⇧T) * w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F›*) have "... = ?G⇧T ⊓ ?E⇧T ⊓ w⇧T * (?F ⊓ ?F⇧T) * w ⊓ ?E ⊓ ?G" by (metis (no_types) comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*) inf_assoc (*‹(?x::'a) ⊓ (?y::'a) ⊓ (?z::'a) = ?x ⊓ (?y ⊓ ?z)›*) conv_dist_comp (*‹((?x::'a) * (?y::'a))⇧T = ?y⇧T * ?x⇧T›*) conv_top (*‹symmetric top›*) vector_export_comp (*‹((?x::'a) * top ⊓ (?y::'a)) * (?z::'a) = ?x * top ⊓ ?y * ?z›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) = (top * e * - F)⇧T ⊓ (top * e⇧T * w⇧T⇧⋆)⇧T ⊓ w⇧T * (F * e⇧T * top ⊓ (F * e⇧T * top)⇧T) * w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ top * e * - F›*) have "... = ?E⇧T ⊓ ?E ⊓ (?G⇧T ⊓ ?G) ⊓ w⇧T * (?F ⊓ ?F⇧T) * w" by (simp add: inf_assoc (*‹?x ⊓ ?y ⊓ ?z = ?x ⊓ (?y ⊓ ?z)›*) inf.left_commute (*‹?b ⊓ (?a ⊓ ?c) = ?a ⊓ (?b ⊓ ?c)›*) inf.sup_monoid.add_commute (*‹?a ⊓ ?b = ?b ⊓ ?a›*)) also (*calculation: ‹((w::'a) ⊓ top * (e::'a)⇧T * w⇧T⇧⋆ ⊓ (F::'a) * e⇧T * top ⊓ top * e * - F)⇧T * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) = (top * e⇧T * w⇧T⇧⋆)⇧T ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ ((top * e * - F)⇧T ⊓ top * e * - F) ⊓ w⇧T * (F * e⇧T * top ⊓ (F * e⇧T * top)⇧T) * w›*) have "... = w⇧⋆ * e * top ⊓ ?E ⊓ (?G⇧T ⊓ ?G) ⊓ w⇧T * (?F ⊓ ?F⇧T) * w" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) = w⇧⋆ * e * top ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ ((top * e * - F)⇧T ⊓ top * e * - F) ⊓ w⇧T * (F * e⇧T * top ⊓ (F * e⇧T * top)⇧T) * w›*) have "... = w⇧⋆ * e * ?E ⊓ (?G⇧T ⊓ ?G) ⊓ w⇧T * (?F ⊓ ?F⇧T) * w" by (metis comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_inf_covector (*‹?x * (?y ⊓ top * ?z) = ?x * ?y ⊓ top * ?z›*) inf_top.left_neutral (*‹top ⊓ ?a = ?a›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) = w⇧⋆ * e * (top * e⇧T * w⇧T⇧⋆) ⊓ ((top * e * - F)⇧T ⊓ top * e * - F) ⊓ w⇧T * (F * e⇧T * top ⊓ (F * e⇧T * top)⇧T) * w›*) have "... ≤ w⇧⋆ * w⇧T⇧⋆ ⊓ (?G⇧T ⊓ ?G) ⊓ w⇧T * (?F ⊓ ?F⇧T) * w" by (metis assms( (*‹arc e›*) 3) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_1_right (*‹?a * 1 = ?a›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) inf.sup_left_isotone (*‹?y ≤ ?x ⟹ ?y ⊓ ?z ≤ ?x ⊓ ?z›*) arc_expanded (*‹arc ?x = (coreflexive (?x * top * ?x⇧T) ∧ coreflexive (?x⇧T * top * ?x) ∧ times_top_class.total (top * ?x))›*)) also (*calculation: ‹((w::'a) ⊓ top * (e::'a)⇧T * w⇧T⇧⋆ ⊓ (F::'a) * e⇧T * top ⊓ top * e * - F)⇧T * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) ≤ w⇧⋆ * w⇧T⇧⋆ ⊓ ((top * e * - F)⇧T ⊓ top * e * - F) ⊓ w⇧T * (F * e⇧T * top ⊓ (F * e⇧T * top)⇧T) * w›*) have "... = w⇧⋆ * w⇧T⇧⋆ ⊓ (-F * e⇧T * top ⊓ ?G) ⊓ w⇧T * (?F ⊓ ?F⇧T) * w" by (simp add: assms( (*‹equivalence (F::'a)›*) 1) conv_complement (*‹(- (?x::'a))⇧T = - ?x⇧T›*) conv_dist_comp (*‹((?x::'a) * (?y::'a))⇧T = ?y⇧T * ?x⇧T›*) mult_assoc (*‹(?a::'a) * (?b::'a) * (?c::'a) = ?a * (?b * ?c)›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) ≤ w⇧⋆ * w⇧T⇧⋆ ⊓ (- F * e⇧T * top ⊓ top * e * - F) ⊓ w⇧T * (F * e⇧T * top ⊓ (F * e⇧T * top)⇧T) * w›*) have "... = w⇧⋆ * w⇧T⇧⋆ ⊓ -F * e⇧T * ?G ⊓ w⇧T * (?F ⊓ ?F⇧T) * w" by (metis comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_inf_covector (*‹?x * (?y ⊓ top * ?z) = ?x * ?y ⊓ top * ?z›*) inf_top.left_neutral (*‹top ⊓ ?a = ?a›*)) also (*calculation: ‹((w::'a) ⊓ top * (e::'a)⇧T * w⇧T⇧⋆ ⊓ (F::'a) * e⇧T * top ⊓ top * e * - F)⇧T * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) ≤ w⇧⋆ * w⇧T⇧⋆ ⊓ - F * e⇧T * (top * e * - F) ⊓ w⇧T * (F * e⇧T * top ⊓ (F * e⇧T * top)⇧T) * w›*) have "... = w⇧⋆ * w⇧T⇧⋆ ⊓ -F * e⇧T * e * -F ⊓ w⇧T * (?F ⊓ ?F⇧T) * w" by (metis assms( (*‹arc e›*) 3) arc_top_edge (*‹arc ?x ⟹ ?x⇧T * top * ?x = ?x⇧T * ?x›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) ≤ w⇧⋆ * w⇧T⇧⋆ ⊓ - F * e⇧T * e * - F ⊓ w⇧T * (F * e⇧T * top ⊓ (F * e⇧T * top)⇧T) * w›*) have "... = w⇧⋆ * w⇧T⇧⋆ ⊓ -F * e⇧T * e * -F ⊓ w⇧T * (?F ⊓ top * e * F) * w" by (simp add: assms( (*‹equivalence F›*) 1) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹((w::'a) ⊓ top * (e::'a)⇧T * w⇧T⇧⋆ ⊓ (F::'a) * e⇧T * top ⊓ top * e * - F)⇧T * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) ≤ w⇧⋆ * w⇧T⇧⋆ ⊓ - F * e⇧T * e * - F ⊓ w⇧T * (F * e⇧T * top ⊓ top * e * F) * w›*) have "... = w⇧⋆ * w⇧T⇧⋆ ⊓ -F * e⇧T * e * -F ⊓ w⇧T * (?F * e * F) * w" by (metis comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_inf_covector (*‹?x * (?y ⊓ top * ?z) = ?x * ?y ⊓ top * ?z›*) inf_top.left_neutral (*‹top ⊓ ?a = ?a›*)) also (*calculation: ‹((w::'a) ⊓ top * (e::'a)⇧T * w⇧T⇧⋆ ⊓ (F::'a) * e⇧T * top ⊓ top * e * - F)⇧T * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) ≤ w⇧⋆ * w⇧T⇧⋆ ⊓ - F * e⇧T * e * - F ⊓ w⇧T * (F * e⇧T * top * e * F) * w›*) have "... = w⇧⋆ * w⇧T⇧⋆ ⊓ -F * e⇧T * e * -F ⊓ w⇧T * F * e⇧T * e * F * w" by (metis assms( (*‹arc (e::'a::type)›*) 3) arc_top_edge (*‹arc (?x::'a::type) ⟹ ?x⇧T * top * ?x = ?x⇧T * ?x›*) mult_assoc (*‹(?a::'a::type) * (?b::'a::type) * (?c::'a::type) = ?a * (?b * ?c)›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) ≤ w⇧⋆ * w⇧T⇧⋆ ⊓ - F * e⇧T * e * - F ⊓ w⇧T * F * e⇧T * e * F * w›*) have "... = (w⁺ ⊔ 1 ⊔ w⇧T⇧⋆) ⊓ -F * e⇧T * e * -F ⊓ w⇧T * F * e⇧T * e * F * w" by (simp add: assms( (*‹forest w›*) 2) cancel_separate_eq (*‹coreflexive (?x * ?y) ⟹ ?x⇧⋆ * ?y⇧⋆ = ?x⇧⋆ ⊔ ?y⇧⋆›*) star_left_unfold_equal (*‹1 ⊔ ?x⁺ = ?x⇧⋆›*) sup_monoid.add_commute (*‹?a ⊔ ?b = ?b ⊔ ?a›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) ≤ (w⁺ ⊔ 1 ⊔ w⇧T⇧⋆) ⊓ - F * e⇧T * e * - F ⊓ w⇧T * F * e⇧T * e * F * w›*) have "... = (w⁺ ⊔ 1 ⊔ w⇧T⁺) ⊓ -F * e⇧T * e * -F ⊓ w⇧T * F * e⇧T * e * F * w" using star.circ_plus_one (*‹(?x::'a)⇧⋆ = (1::'a) ⊔ ?x⇧⋆›*) star_left_unfold_equal (*‹1 ⊔ ?x⁺ = ?x⇧⋆›*) sup_assoc (*‹?x ⊔ ?y ⊔ ?z = ?x ⊔ (?y ⊔ ?z)›*) by presburger also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) ≤ (w⁺ ⊔ 1 ⊔ w⇧T⁺) ⊓ - F * e⇧T * e * - F ⊓ w⇧T * F * e⇧T * e * F * w›*) have "... = (w⁺ ⊓ -F * e⇧T * e * -F ⊓ w⇧T * F * e⇧T * e * F * w) ⊔ (1 ⊓ -F * e⇧T * e * -F ⊓ w⇧T * F * e⇧T * e * F * w) ⊔ (w⇧T⁺ ⊓ -F * e⇧T * e * -F ⊓ w⇧T * F * e⇧T * e * F * w)" by (simp add: inf_sup_distrib2 (*‹(?y ⊔ ?z) ⊓ ?x = ?y ⊓ ?x ⊔ ?z ⊓ ?x›*)) also (*calculation: ‹(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F) ≤ w⁺ ⊓ - F * e⇧T * e * - F ⊓ w⇧T * F * e⇧T * e * F * w ⊔ 1 ⊓ - F * e⇧T * e * - F ⊓ w⇧T * F * e⇧T * e * F * w ⊔ w⇧T⁺ ⊓ - F * e⇧T * e * - F ⊓ w⇧T * F * e⇧T * e * F * w›*) have "... ≤ 1" using "11" (*‹(w::'a)⇧T⁺ ⊓ - (F::'a) * (e::'a)⇧T * e * - F ⊓ w⇧T * F * e⇧T * e * F * w = bot›*) "12" (*‹w⁺ ⊓ - F * e⇧T * e * - F ⊓ w⇧T * F * e⇧T * e * F * w = bot›*) by (simp add: inf.coboundedI1 (*‹?a ≤ ?c ⟹ ?a ⊓ ?b ≤ ?c›*)) finally (*calculation: ‹coreflexive ((w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)⇧T * top * (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F))›*) show "(w ⊓ ?E ⊓ ?F ⊓ ?G)⇧T * top * (w ⊓ ?E ⊓ ?F ⊓ ?G) ≤ 1" by simp have "(w ⊓ -F) * (F ⊓ w⇧T) ≤ w * w⇧T ⊓ -F * F" by (simp add: mult_isotone (*‹⟦(?w::'a::type) ≤ (?y::'a::type); (?x::'a::type) ≤ (?z::'a::type)⟧ ⟹ ?w * ?x ≤ ?y * ?z›*)) also (*calculation: ‹((w::'a) ⊓ - (F::'a)) * (F ⊓ w⇧T) ≤ w * w⇧T ⊓ - F * F›*) have "... ≤ 1 ⊓ -F" using assms(1,2) (*‹equivalence F› ‹forest w›*) comp_inf.comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x ⊓ ?w ≤ ?y ⊓ ?z›*) equivalence_comp_right_complement (*‹equivalence ?x ⟹ - ?x * ?x = - ?x›*) by auto also (*calculation: ‹((w::'a::type) ⊓ - (F::'a::type)) * (F ⊓ w⇧T) ≤ (1::'a::type) ⊓ - F›*) have "... = bot" using assms(1) (*‹equivalence (F::'a::type)›*) bot_unique (*‹(?a ≤ bot) = (?a = bot)›*) pp_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ - - ?x ≤ - - ?y›*) pseudo_complement_pp (*‹(?x ⊓ ?y = bot) = (- - ?x ≤ - ?y)›*) by blast finally (*calculation: ‹(w ⊓ - F) * (F ⊓ w⇧T) ≤ bot›*) have 13: "(w ⊓ -F) * (F ⊓ w⇧T) = bot" by (simp add: order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) have "w ⊓ ?G ≤ F * (w ⊓ ?G)" by (metis assms( (*‹equivalence F›*) 1) mult_1_left (*‹1 * ?a = ?a›*) mult_right_dist_sup (*‹(?x ⊔ ?y) * ?z = ?x * ?z ⊔ ?y * ?z›*) sup.absorb_iff2 (*‹(?a ≤ ?b) = (?a ⊔ ?b = ?b)›*)) also (*calculation: ‹w ⊓ top * e * - F ≤ F * (w ⊓ top * e * - F)›*) have "... ≤ F * (w ⊓ ?G) * w⇧⋆" by (metis eq_refl (*‹?x = ?y ⟹ ?x ≤ ?y›*) le_supE (*‹⟦?a ⊔ ?b ≤ ?x; ⟦?a ≤ ?x; ?b ≤ ?x⟧ ⟹ ?P⟧ ⟹ ?P›*) star.circ_back_loop_fixpoint (*‹?z * ?y⇧⋆ * ?y ⊔ ?z = ?z * ?y⇧⋆›*)) finally (*calculation: ‹w ⊓ top * e * - F ≤ F * (w ⊓ top * e * - F) * w⇧⋆›*) have 14: "w ⊓ ?G ≤ F * (w ⊓ ?G) * w⇧⋆" by simp have "w ⊓ top * e * F ≤ w * (e * F)⇧T * e * F" by (metis (no_types) comp_inf.star_slide (*‹top ⊓ ?x = ?x ⊓ top›*) dedekind_2 (*‹?y * ?x ⊓ ?z ≤ (?y ⊓ ?z * ?x⇧T) * ?x›*) inf_left_commute (*‹?x ⊓ (?y ⊓ ?z) = ?y ⊓ (?x ⊓ ?z)›*) inf_top_right (*‹?x ⊓ top = ?x›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹w ⊓ top * e * F ≤ w * (e * F)⇧T * e * F›*) have "... ≤ F" using "3" (*‹w * F * e⇧T * e ≤ F›*) assms(1) (*‹equivalence F›*) by (metis comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) preorder_idempotent (*‹preorder ?x ⟹ idempotent ?x›*)) finally (*calculation: ‹w ⊓ top * e * F ≤ F›*) have "w ⊓ -F ≤ -(top * e * F)" using order.trans (*‹⟦?a ≤ ?b; ?b ≤ ?c⟧ ⟹ ?a ≤ ?c›*) p_shunting_swap (*‹(?x ⊓ ?y ≤ - ?z) = (?x ⊓ ?z ≤ - ?y)›*) pp_increasing (*‹?x ≤ - - ?x›*) by blast also (*calculation: ‹w ⊓ - F ≤ - (top * e * F)›*) have "... = ?G" by (metis assms( (*‹arc e›*) 3) comp_mapping_complement (*‹mapping ?x ⟹ ?x * - ?y = - (?x * ?y)›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_top (*‹symmetric top›*)) finally (*calculation: ‹w ⊓ - F ≤ top * e * - F›*) have "(w ⊓ -F) * F * (w ⊓ ?G) = (w ⊓ -F ⊓ ?G) * F * (w ⊓ ?G)" by (simp add: inf.absorb1 (*‹(?a::'a) ≤ (?b::'a) ⟹ ?a ⊓ ?b = ?a›*)) also (*calculation: ‹(w ⊓ - F) * F * (w ⊓ top * e * - F) = (w ⊓ - F ⊓ top * e * - F) * F * (w ⊓ top * e * - F)›*) have "... ≤ (w ⊓ -F ⊓ ?G) * F * w" by (simp add: comp_isotone (*‹⟦?x ≤ ?y; ?w ≤ ?z⟧ ⟹ ?x * ?w ≤ ?y * ?z›*)) also (*calculation: ‹(w ⊓ - F) * F * (w ⊓ top * e * - F) ≤ (w ⊓ - F ⊓ top * e * - F) * F * w›*) have "... ≤ (w ⊓ -F ⊓ ?G) * forest_components (F ⊓ w) * w" by (simp add: assms( (*‹F ≤ forest_components (F ⊓ w)›*) 5) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹((w::'a) ⊓ - (F::'a)) * F * (w ⊓ top * (e::'a) * - F) ≤ (w ⊓ - F ⊓ top * e * - F) * forest_components (F ⊓ w) * w›*) have "... ≤ (w ⊓ -F ⊓ ?G) * (F ⊓ w)⇧T⇧⋆ * w⇧⋆ * w" by (simp add: mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹(w ⊓ - F) * F * (w ⊓ top * e * - F) ≤ (w ⊓ - F ⊓ top * e * - F) * (F ⊓ w)⇧T⇧⋆ * w⇧⋆ * w›*) have "... ≤ (w ⊓ -F ⊓ ?G) * (F ⊓ w)⇧T⇧⋆ * w⇧⋆" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) star.circ_plus_same (*‹?x⇧⋆ * ?x = ?x⁺›*) star.left_plus_below_circ (*‹?x⁺ ≤ ?x⇧⋆›*)) also (*calculation: ‹(w ⊓ - F) * F * (w ⊓ top * e * - F) ≤ (w ⊓ - F ⊓ top * e * - F) * (F ⊓ w)⇧T⇧⋆ * w⇧⋆›*) have "... = (w ⊓ -F ⊓ ?G) * w⇧⋆ ⊔ (w ⊓ -F ⊓ ?G) * (F ⊓ w)⇧T⁺ * w⇧⋆" by (metis comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) inf.sup_monoid.add_assoc (*‹?a ⊓ ?b ⊓ ?c = ?a ⊓ (?b ⊓ ?c)›*) mult_left_dist_sup (*‹?x * (?y ⊔ ?z) = ?x * ?y ⊔ ?x * ?z›*) star.circ_loop_fixpoint (*‹?y * (?y⇧⋆ * ?z) ⊔ ?z = ?y⇧⋆ * ?z›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*)) also (*calculation: ‹(w ⊓ - F) * F * (w ⊓ top * e * - F) ≤ (w ⊓ - F ⊓ top * e * - F) * w⇧⋆ ⊔ (w ⊓ - F ⊓ top * e * - F) * (F ⊓ w)⇧T⁺ * w⇧⋆›*) have "... ≤ (w ⊓ -F ⊓ ?G) * w⇧⋆ ⊔ (w ⊓ -F ⊓ ?G) * (F ⊓ w)⇧T * top" by (metis mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) top_greatest (*‹?x ≤ top›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*) sup_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊔ ?x ≤ ?z ⊔ ?y›*)) also (*calculation: ‹(w ⊓ - F) * F * (w ⊓ top * e * - F) ≤ (w ⊓ - F ⊓ top * e * - F) * w⇧⋆ ⊔ (w ⊓ - F ⊓ top * e * - F) * (F ⊓ w)⇧T * top›*) have "... ≤ (w ⊓ -F ⊓ ?G) * w⇧⋆ ⊔ (w ⊓ -F) * (F ⊓ w)⇧T * top" using inf.cobounded1 (*‹?a ⊓ ?b ≤ ?a›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) sup_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊔ ?x ≤ ?z ⊔ ?y›*) by blast also (*calculation: ‹(w ⊓ - F) * F * (w ⊓ top * e * - F) ≤ (w ⊓ - F ⊓ top * e * - F) * w⇧⋆ ⊔ (w ⊓ - F) * (F ⊓ w)⇧T * top›*) have "... ≤ (w ⊓ ?G) * w⇧⋆ ⊔ (w ⊓ -F) * (F ⊓ w)⇧T * top" using inf.sup_monoid.add_assoc (*‹(?a::'a::type) ⊓ (?b::'a::type) ⊓ (?c::'a::type) = ?a ⊓ (?b ⊓ ?c)›*) inf.sup_right_isotone (*‹?y ≤ ?x ⟹ ?z ⊓ ?y ≤ ?z ⊓ ?x›*) mult_left_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x * (?z::'a) ≤ ?y * ?z›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*) sup_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊔ ?x ≤ ?z ⊔ ?y›*) by simp also (*calculation: ‹(w ⊓ - F) * F * (w ⊓ top * e * - F) ≤ (w ⊓ top * e * - F) * w⇧⋆ ⊔ (w ⊓ - F) * (F ⊓ w)⇧T * top›*) have "... = (w ⊓ ?G) * w⇧⋆ ⊔ (w ⊓ -F) * (F ⊓ w⇧T) * top" by (simp add: assms( (*‹equivalence F›*) 1) conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*)) also (*calculation: ‹((w::'a::type) ⊓ - (F::'a::type)) * F * (w ⊓ top * (e::'a::type) * - F) ≤ (w ⊓ top * e * - F) * w⇧⋆ ⊔ (w ⊓ - F) * (F ⊓ w⇧T) * top›*) have "... ≤ 1 * (w ⊓ ?G) * w⇧⋆" using "13" (*‹(w ⊓ - F) * (F ⊓ w⇧T) = bot›*) by simp also (*calculation: ‹(w ⊓ - F) * F * (w ⊓ top * e * - F) ≤ 1 * (w ⊓ top * e * - F) * w⇧⋆›*) have "... ≤ F * (w ⊓ ?G) * w⇧⋆" using assms(1) (*‹equivalence F›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) by blast finally (*calculation: ‹(w ⊓ - F) * F * (w ⊓ top * e * - F) ≤ F * (w ⊓ top * e * - F) * w⇧⋆›*) have 15: "(w ⊓ -F) * F * (w ⊓ ?G) ≤ F * (w ⊓ ?G) * w⇧⋆" by simp have "(w ⊓ F) * F * (w ⊓ ?G) ≤ F * F * (w ⊓ ?G)" by (simp add: mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) also (*calculation: ‹(w ⊓ F) * F * (w ⊓ top * e * - F) ≤ F * F * (w ⊓ top * e * - F)›*) have "... = F * (w ⊓ ?G)" by (simp add: assms( (*‹equivalence F›*) 1) preorder_idempotent (*‹preorder ?x ⟹ idempotent ?x›*)) also (*calculation: ‹(w ⊓ F) * F * (w ⊓ top * e * - F) ≤ F * (w ⊓ top * e * - F)›*) have "... ≤ F * (w ⊓ ?G) * w⇧⋆" by (metis eq_refl (*‹?x = ?y ⟹ ?x ≤ ?y›*) le_supE (*‹⟦?a ⊔ ?b ≤ ?x; ⟦?a ≤ ?x; ?b ≤ ?x⟧ ⟹ ?P⟧ ⟹ ?P›*) star.circ_back_loop_fixpoint (*‹?z * ?y⇧⋆ * ?y ⊔ ?z = ?z * ?y⇧⋆›*)) finally (*calculation: ‹(w ⊓ F) * F * (w ⊓ top * e * - F) ≤ F * (w ⊓ top * e * - F) * w⇧⋆›*) have "(w ⊓ F) * F * (w ⊓ ?G) ≤ F * (w ⊓ ?G) * w⇧⋆" by simp hence "((w ⊓ F) ⊔ (w ⊓ -F)) * F * (w ⊓ ?G) ≤ F * (w ⊓ ?G) * w⇧⋆" using "15" (*‹(w ⊓ - F) * F * (w ⊓ top * e * - F) ≤ F * (w ⊓ top * e * - F) * w⇧⋆›*) by (simp add: semiring.distrib_right (*‹((?a::'a) ⊔ (?b::'a)) * (?c::'a) = ?a * ?c ⊔ ?b * ?c›*)) hence "w * F * (w ⊓ ?G) ≤ F * (w ⊓ ?G) * w⇧⋆" by (metis assms( (*‹regular F›*) 4) maddux_3_11_pp (*‹?x ⊓ - ?y ⊔ ?x ⊓ - - ?y = ?x›*)) hence "w * F * (w ⊓ ?G) * w⇧⋆ ≤ F * (w ⊓ ?G) * w⇧⋆" by (metis (full_types) comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*) mult_left_isotone (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x * (?z::'a) ≤ ?y * ?z›*) star.circ_transitive_equal (*‹idempotent ((?x::'a)⇧⋆)›*)) hence "w⇧⋆ * (w ⊓ ?G) ≤ F * (w ⊓ ?G) * w⇧⋆" using "14" (*‹w ⊓ top * e * - F ≤ F * (w ⊓ top * e * - F) * w⇧⋆›*) by (simp add: mult_assoc (*‹(?a::'a) * (?b::'a) * (?c::'a) = ?a * (?b * ?c)›*) star_left_induct (*‹(?z::'a) ⊔ (?y::'a) * (?x::'a) ≤ ?x ⟶ ?y⇧⋆ * ?z ≤ ?x›*)) hence 16: "w⁺ ⊓ ?G ≤ F * (w ⊓ ?G) * w⇧⋆" by (simp add: covector_comp_inf (*‹covector (?z::'a) ⟹ (?x::'a) * ((?y::'a) ⊓ ?z) = ?x * ?y ⊓ ?z›*) covector_mult_closed (*‹covector (?x::'a) ⟹ covector (?x * (?y::'a))›*) star.circ_plus_same (*‹(?x::'a)⇧⋆ * ?x = ?x⁺›*)) have 17: "e⇧T * top * e⇧T ≤ -F" using assms(8) (*‹e * F * e = bot›*) le_bot (*‹(?a::'a) ≤ bot ⟹ ?a = bot›*) triple_schroeder_p (*‹(?x * ?y * ?z ≤ - ?w) = (?x⇧T * ?w * ?z⇧T ≤ - ?y)›*) by simp hence "(top * e)⇧T * e⇧T ≤ -F" by (simp add: conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*)) hence 18: "e⇧T ≤ ?G" by (metis assms( (*‹arc e›*) 3) shunt_mapping (*‹mapping ?z ⟹ (?x ≤ ?z * ?y) = (?z⇧T * ?x ≤ ?y)›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_top (*‹symmetric top›*)) have "e⇧T ≤ -F" using "17" (*‹e⇧T * top * e⇧T ≤ - F›*) by (simp add: assms( (*‹arc (e::'a)›*) 3) arc_top_arc (*‹arc (?x::'a) ⟹ ?x * top * ?x = ?x›*)) also (*calculation: ‹e⇧T ≤ - F›*) have "... ≤ -1" by (simp add: assms( (*‹equivalence F›*) 1) p_antitone (*‹?x ≤ ?y ⟹ - ?y ≤ - ?x›*)) finally (*calculation: ‹irreflexive ((e::'a)⇧T)›*) have "e⇧T ≤ w⇧⋆ ⊓ -1" using assms(9) (*‹(e::'a::type)⇧T ≤ (w::'a::type)⇧⋆›*) by simp also (*calculation: ‹e⇧T ≤ w⇧⋆ ⊓ - 1›*) have "... ≤ w⁺" using shunting_var_p (*‹(?x ⊓ - ?y ≤ ?z) = (?x ≤ ?z ⊔ - - ?y)›*) star_left_unfold_equal (*‹1 ⊔ ?x⁺ = ?x⇧⋆›*) sup_commute (*‹?x ⊔ ?y = ?y ⊔ ?x›*) by simp finally (*calculation: ‹e⇧T ≤ w⁺›*) have "e⇧T ≤ w⁺ ⊓ ?G" using "18" (*‹e⇧T ≤ top * e * - F›*) by simp hence "e⇧T ≤ F * (w ⊓ ?G) * w⇧⋆" using "16" (*‹w⁺ ⊓ top * e * - F ≤ F * (w ⊓ top * e * - F) * w⇧⋆›*) order_trans (*‹⟦?x ≤ ?y; ?y ≤ ?z⟧ ⟹ ?x ≤ ?z›*) by blast also (*calculation: ‹e⇧T ≤ F * (w ⊓ top * e * - F) * w⇧⋆›*) have "... = (F * w ⊓ ?G) * w⇧⋆" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_inf_covector (*‹?x * (?y ⊓ top * ?z) = ?x * ?y ⊓ top * ?z›*)) finally (*calculation: ‹e⇧T ≤ (F * w ⊓ top * e * - F) * w⇧⋆›*) have "e⇧T * top * e⇧T ≤ (F * w ⊓ ?G) * w⇧⋆" by (simp add: assms( (*‹arc e›*) 3) arc_top_arc (*‹arc ?x ⟹ ?x * top * ?x = ?x›*)) hence "e⇧T * top * (e * top)⇧T ≤ (F * w ⊓ ?G) * w⇧⋆" by (metis conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_top (*‹symmetric top›*) vector_top_closed (*‹surjective top›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) hence "e⇧T * top ≤ (F * w ⊓ ?G) * w⇧⋆ * e * top" by (metis assms( (*‹arc e›*) 3) shunt_bijective (*‹bijective ?z ⟹ (?x ≤ ?y * ?z) = (?x * ?z⇧T ≤ ?y)›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) hence "(top * e)⇧T * top ≤ (F * w ⊓ ?G) * w⇧⋆ * e * top" by (simp add: conv_dist_comp (*‹((?x::'a) * (?y::'a))⇧T = ?y⇧T * ?x⇧T›*) mult_assoc (*‹(?a::'a) * (?b::'a) * (?c::'a) = ?a * (?b * ?c)›*)) hence "top ≤ top * e * (F * w ⊓ ?G) * w⇧⋆ * e * top" by (metis assms( (*‹arc e›*) 3) shunt_mapping (*‹mapping ?z ⟹ (?x ≤ ?z * ?y) = (?z⇧T * ?x ≤ ?y)›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_involutive (*‹?x⇧T⇧T = ?x›*) conv_top (*‹symmetric top›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹top ≤ top * e * (F * w ⊓ top * e * - F) * w⇧⋆ * e * top›*) have "... = top * e * F * w * (w⇧⋆ * e * top ⊓ ?G⇧T)" by (metis comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*) comp_inf_vector_1 (*‹((?x::'a) ⊓ top * (?y::'a)) * (?z::'a) = ?x * (?z ⊓ (top * ?y)⇧T)›*)) also (*calculation: ‹top ≤ top * e * F * w * (w⇧⋆ * e * top ⊓ (top * e * - F)⇧T)›*) have "... = top * (w ⊓ (top * e * F)⇧T) * (w⇧⋆ * e * top ⊓ ?G⇧T)" by (metis comp_inf_vector_1 (*‹(?x ⊓ top * ?y) * ?z = ?x * (?z ⊓ (top * ?y)⇧T)›*) inf_top.left_neutral (*‹top ⊓ ?a = ?a›*)) also (*calculation: ‹top ≤ top * ((w::'a::type) ⊓ (top * (e::'a::type) * (F::'a::type))⇧T) * (w⇧⋆ * e * top ⊓ (top * e * - F)⇧T)›*) have "... = top * (w ⊓ ?F) * (w⇧⋆ * e * top ⊓ ?G⇧T)" by (simp add: assms( (*‹equivalence F›*) 1) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) also (*calculation: ‹top ≤ top * ((w::'a) ⊓ (F::'a) * (e::'a)⇧T * top) * (w⇧⋆ * e * top ⊓ (top * e * - F)⇧T)›*) have "... = top * (w ⊓ ?F) * (?E⇧T ⊓ ?G⇧T)" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*)) also (*calculation: ‹top ≤ top * (w ⊓ F * e⇧T * top) * ((top * e⇧T * w⇧T⇧⋆)⇧T ⊓ (top * e * - F)⇧T)›*) have "... = top * (w ⊓ ?F ⊓ ?G) * ?E⇧T" by (simp add: comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_inf_vector_1 (*‹(?x ⊓ top * ?y) * ?z = ?x * (?z ⊓ (top * ?y)⇧T)›*)) also (*calculation: ‹top ≤ top * (w ⊓ F * e⇧T * top ⊓ top * e * - F) * (top * e⇧T * w⇧T⇧⋆)⇧T›*) have "... = top * (w ⊓ ?F ⊓ ?G ⊓ ?E) * top" using comp_inf_vector_1 (*‹(?x ⊓ top * ?y) * ?z = ?x * (?z ⊓ (top * ?y)⇧T)›*) mult_assoc (*‹(?a::'a::type) * (?b::'a::type) * (?c::'a::type) = ?a * (?b * ?c)›*) by simp finally (*calculation: ‹top ≤ top * ((w::'a) ⊓ (F::'a) * (e::'a)⇧T * top ⊓ top * e * - F ⊓ top * e⇧T * w⇧T⇧⋆) * top›*) show "top * (w ⊓ ?E ⊓ ?F ⊓ ?G) * top = top" by (simp add: inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) inf_left_commute (*‹?x ⊓ (?y ⊓ ?z) = ?y ⊓ (?x ⊓ ?z)›*) top_le (*‹top ≤ ?a ⟹ ?a = top›*)) qed lemma kruskal_edge_arc_1: assumes "e ≤ --h" and "h ≤ g" and "symmetric g" and "components g ≤ forest_components w" and "w * e⇧T = bot" shows "e⇧T ≤ w⇧⋆" proof (-) (*goal: ‹(e::'a::type)⇧T ≤ (w::'a::type)⇧⋆›*) have "w⇧T * top ≤ -(e⇧T * top)" using assms(5) (*‹w * e⇧T = bot›*) schroeder_3_p (*‹(?x * ?y ≤ - ?z) = (?x⇧T * ?z ≤ - ?y)›*) vector_bot_closed (*‹vector bot›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) by fastforce hence 1: "w⇧T * top ⊓ e⇧T * top = bot" using pseudo_complement (*‹((?x::'a::type) ⊓ (?y::'a::type) = bot) = (?x ≤ - ?y)›*) by simp have "e⇧T ≤ e⇧T * top ⊓ --h⇧T" using assms(1) (*‹e ≤ - - h›*) conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) top_right_mult_increasing (*‹(?x::'a) ≤ ?x * top›*) by fastforce also (*calculation: ‹e⇧T ≤ e⇧T * top ⊓ - - h⇧T›*) have "... ≤ e⇧T * top ⊓ --g" by (metis assms( (*‹h ≤ g› ‹symmetric g›*) 2,3) inf.sup_right_isotone (*‹?y ≤ ?x ⟹ ?z ⊓ ?y ≤ ?z ⊓ ?x›*) pp_isotone (*‹?x ≤ ?y ⟹ - - ?x ≤ - - ?y›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*)) also (*calculation: ‹e⇧T ≤ e⇧T * top ⊓ - - g›*) have "... ≤ e⇧T * top ⊓ components g" using inf.sup_right_isotone (*‹?y ≤ ?x ⟹ ?z ⊓ ?y ≤ ?z ⊓ ?x›*) star.circ_increasing (*‹?x ≤ ?x⇧⋆›*) by simp also (*calculation: ‹e⇧T ≤ e⇧T * top ⊓ components g›*) have "... ≤ e⇧T * top ⊓ forest_components w" using assms(4) (*‹components (g::'a::type) ≤ forest_components (w::'a::type)›*) comp_inf.mult_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊓ ?x ≤ ?z ⊓ ?y›*) by simp also (*calculation: ‹e⇧T ≤ e⇧T * top ⊓ forest_components w›*) have "... = (e⇧T * top ⊓ w⇧T⇧⋆) * w⇧⋆" by (simp add: inf_assoc (*‹?x ⊓ ?y ⊓ ?z = ?x ⊓ (?y ⊓ ?z)›*) vector_export_comp (*‹(?x * top ⊓ ?y) * ?z = ?x * top ⊓ ?y * ?z›*)) also (*calculation: ‹(e::'a)⇧T ≤ (e⇧T * top ⊓ (w::'a)⇧T⇧⋆) * w⇧⋆›*) have "... = (e⇧T * top ⊓ 1) * w⇧⋆ ⊔ (e⇧T * top ⊓ w⇧T⁺) * w⇧⋆" by (metis inf_sup_distrib1 (*‹(?x::'a) ⊓ ((?y::'a) ⊔ (?z::'a)) = ?x ⊓ ?y ⊔ ?x ⊓ ?z›*) semiring.distrib_right (*‹((?a::'a) ⊔ (?b::'a)) * (?c::'a) = ?a * ?c ⊔ ?b * ?c›*) star_left_unfold_equal (*‹(1::'a) ⊔ (?x::'a)⁺ = ?x⇧⋆›*)) also (*calculation: ‹e⇧T ≤ (e⇧T * top ⊓ 1) * w⇧⋆ ⊔ (e⇧T * top ⊓ w⇧T⁺) * w⇧⋆›*) have "... ≤ w⇧⋆ ⊔ (e⇧T * top ⊓ w⇧T⁺) * w⇧⋆" by (metis inf_le2 (*‹?x ⊓ ?y ≤ ?y›*) mult_1_left (*‹1 * ?a = ?a›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*) sup_left_isotone (*‹?x ≤ ?y ⟹ ?x ⊔ ?z ≤ ?y ⊔ ?z›*)) also (*calculation: ‹e⇧T ≤ w⇧⋆ ⊔ (e⇧T * top ⊓ w⇧T⁺) * w⇧⋆›*) have "... ≤ w⇧⋆ ⊔ (e⇧T * top ⊓ w⇧T) * top" using comp_associative (*‹?x * ?y * ?z = ?x * (?y * ?z)›*) comp_inf.mult_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊓ ?x ≤ ?z ⊓ ?y›*) sup_right_isotone (*‹?x ≤ ?y ⟹ ?z ⊔ ?x ≤ ?z ⊔ ?y›*) mult_right_isotone (*‹(?x::'a::type) ≤ (?y::'a::type) ⟹ (?z::'a::type) * ?x ≤ ?z * ?y›*) top.extremum (*‹?a ≤ top›*) vector_export_comp (*‹(?x * top ⊓ ?y) * ?z = ?x * top ⊓ ?y * ?z›*) by presburger also (*calculation: ‹e⇧T ≤ w⇧⋆ ⊔ (e⇧T * top ⊓ w⇧T) * top›*) have "... = w⇧⋆" using "1" (*‹w⇧T * top ⊓ e⇧T * top = bot›*) inf.sup_monoid.add_commute (*‹?a ⊓ ?b = ?b ⊓ ?a›*) inf_vector_comp (*‹((?x::'a) ⊓ (?y::'a) * top) * (?z::'a) = ?y * top ⊓ ?x * ?z›*) by simp finally (*calculation: ‹e⇧T ≤ w⇧⋆›*) show "?thesis" (*goal: ‹e⇧T ≤ w⇧⋆›*) by simp qed lemma kruskal_edge_between_components_1: assumes "equivalence F" and "mapping (top * e)" shows "F ≤ -(w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * -F)" proof (-) (*goal: ‹F ≤ - (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)›*) let ?d = "w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * -F" have "?d ⊓ F ≤ F * e⇧T * top ⊓ F" by (meson inf_le1 (*‹?x ⊓ ?y ≤ ?x›*) inf_le2 (*‹?x ⊓ ?y ≤ ?y›*) le_infI (*‹⟦?x ≤ ?a; ?x ≤ ?b⟧ ⟹ ?x ≤ ?a ⊓ ?b›*) order_trans (*‹⟦?x ≤ ?y; ?y ≤ ?z⟧ ⟹ ?x ≤ ?z›*)) also (*calculation: ‹(w::'a) ⊓ top * (e::'a)⇧T * w⇧T⇧⋆ ⊓ (F::'a) * e⇧T * top ⊓ top * e * - F ⊓ F ≤ F * e⇧T * top ⊓ F›*) have "... ≤ (F * e⇧T * top)⇧T * F" by (simp add: mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) vector_restrict_comp_conv (*‹vector ?x ⟹ ?x ⊓ ?y ≤ ?x⇧T * ?y›*)) also (*calculation: ‹(w::'a) ⊓ top * (e::'a)⇧T * w⇧T⇧⋆ ⊓ (F::'a) * e⇧T * top ⊓ top * e * - F ⊓ F ≤ (F * e⇧T * top)⇧T * F›*) have "... = top * e * F * F" by (simp add: assms( (*‹equivalence (F::'a)›*) 1) comp_associative (*‹(?x::'a) * (?y::'a) * (?z::'a) = ?x * (?y * ?z)›*) conv_dist_comp (*‹((?x::'a) * (?y::'a))⇧T = ?y⇧T * ?x⇧T›*) conv_star_commute (*‹(?x::'a)⇧⋆⇧T = ?x⇧T⇧⋆›*)) also (*calculation: ‹(w::'a) ⊓ top * (e::'a)⇧T * w⇧T⇧⋆ ⊓ (F::'a) * e⇧T * top ⊓ top * e * - F ⊓ F ≤ top * e * F * F›*) have "... = top * e * F" using assms(1) (*‹equivalence F›*) preorder_idempotent (*‹preorder (?x::'a::type) ⟹ idempotent ?x›*) mult_assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) by fastforce finally (*calculation: ‹w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F ⊓ F ≤ top * e * F›*) have "?d ⊓ F ≤ top * e * F ⊓ top * e * -F" by (simp add: le_infI1 (*‹?a ≤ ?x ⟹ ?a ⊓ ?b ≤ ?x›*)) also (*calculation: ‹w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F ⊓ F ≤ top * e * F ⊓ top * e * - F›*) have "... = top * e * F ⊓ -(top * e * F)" using assms(2) (*‹mapping (top * e)›*) conv_dist_comp (*‹((?x::'a) * (?y::'a))⇧T = ?y⇧T * ?x⇧T›*) total_conv_surjective (*‹times_top_class.total (?x::'a) = surjective (?x⇧T)›*) comp_mapping_complement (*‹mapping ?x ⟹ ?x * - ?y = - (?x * ?y)›*) by simp finally (*calculation: ‹(w::'a) ⊓ top * (e::'a)⇧T * w⇧T⇧⋆ ⊓ (F::'a) * e⇧T * top ⊓ top * e * - F ⊓ F ≤ top * e * F ⊓ - (top * e * F)›*) show "?thesis" (*goal: ‹F ≤ - (w ⊓ top * e⇧T * w⇧T⇧⋆ ⊓ F * e⇧T * top ⊓ top * e * - F)›*) by (metis inf_p (*‹?x ⊓ - ?x = bot›*) le_bot (*‹?a ≤ bot ⟹ ?a = bot›*) p_antitone_iff (*‹(?x ≤ - ?y) = (?y ≤ - ?x)›*) pseudo_complement (*‹(?x ⊓ ?y = bot) = (?x ≤ - ?y)›*)) qed lemma kruskal_edge_between_components_2: assumes "forest_components f ≤ -d" and "injective f" and "f ⊔ f⇧T ≤ w ⊔ w⇧T" shows "f ⊔ f⇧T ≤ (w ⊓ -d ⊓ -d⇧T) ⊔ (w⇧T ⊓ -d ⊓ -d⇧T)" proof (-) (*goal: ‹(f::'a) ⊔ f⇧T ≤ (w::'a) ⊓ - (d::'a) ⊓ - d⇧T ⊔ w⇧T ⊓ - d ⊓ - d⇧T›*) let ?F = "forest_components f" have "?F⇧T ≤ -d⇧T" using assms(1) (*‹forest_components f ≤ - d›*) conv_complement (*‹(- ?x)⇧T = - ?x⇧T›*) conv_order (*‹(?x ≤ ?y) = (?x⇧T ≤ ?y⇧T)›*) by fastforce hence 1: "?F ≤ -d⇧T" by (simp add: conv_dist_comp (*‹(?x * ?y)⇧T = ?y⇧T * ?x⇧T›*) conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*)) have "equivalence ?F" using assms(2) (*‹injective f›*) forest_components_equivalence (*‹injective ?x ⟹ equivalence (forest_components ?x)›*) by simp hence "f ⊔ f⇧T ≤ ?F" by (metis conv_dist_inf (*‹(?x ⊓ ?y)⇧T = ?x⇧T ⊓ ?y⇧T›*) forest_components_increasing (*‹?x ≤ forest_components ?x›*) inf.absorb_iff2 (*‹(?b ≤ ?a) = (?a ⊓ ?b = ?b)›*) sup.boundedI (*‹⟦?b ≤ ?a; ?c ≤ ?a⟧ ⟹ ?b ⊔ ?c ≤ ?a›*)) also (*calculation: ‹(f::'a::type) ⊔ f⇧T ≤ forest_components f›*) have "... ≤ -d ⊓ -d⇧T" using "1" (*‹forest_components f ≤ - d⇧T›*) assms(1) (*‹forest_components f ≤ - d›*) by simp finally (*calculation: ‹(f::'a) ⊔ f⇧T ≤ - (d::'a) ⊓ - d⇧T›*) have "f ⊔ f⇧T ≤ -d ⊓ -d⇧T" by simp thus "?thesis" (*goal: ‹f ⊔ f⇧T ≤ w ⊓ - d ⊓ - d⇧T ⊔ w⇧T ⊓ - d ⊓ - d⇧T›*) by (metis assms( (*‹f ⊔ f⇧T ≤ w ⊔ w⇧T›*) 3) inf_sup_distrib2 (*‹(?y ⊔ ?z) ⊓ ?x = ?y ⊓ ?x ⊔ ?z ⊓ ?x›*) le_inf_iff (*‹(?x ≤ ?y ⊓ ?z) = (?x ≤ ?y ∧ ?x ≤ ?z)›*)) qed end subsection ‹Related Structures› text ‹ Stone algebras can be expanded to Stone-Kleene relation algebras by reusing some operations. › sublocale stone_algebra < comp_inf: stone_kleene_relation_algebra where star = "λx . top" and one = top and times = inf and conv = id apply unfold_locales (*goal: ‹class.stone_kleene_relation_algebra (λx. top) top (⊓) (⊔) (≤) (<) bot (⊓) top id uminus›*) by simp text ‹ Every bounded linear order can be expanded to a Stone algebra, which can be expanded to a Stone relation algebra, which can be expanded to a Stone-Kleene relation algebra. › class linorder_stone_kleene_relation_algebra_expansion = linorder_stone_relation_algebra_expansion + star + assumes star_def [simp]: "x⇧⋆ = top" begin subclass kleene_algebra apply unfold_locales apply simp apply (simp add: min.coboundedI1 min.commute) by (simp add: min.coboundedI1) subclass stone_kleene_relation_algebra apply unfold_locales by simp end text ‹ A Kleene relation algebra is based on a relation algebra. › class kleene_relation_algebra = relation_algebra + stone_kleene_relation_algebra begin text ‹See 🌐‹https://arxiv.org/abs/2310.08946› for the following results ‹scc_1›-‹scc_4›.› lemma scc_1: assumes "1 ⊓ y ≤ z" and "x⇧T * y ≤ y" and "y * z⇧T ≤ y" and "(x ⊓ y) * z ≤ z" shows "x⇧⋆ ⊓ y ≤ z" proof (-) (*goal: ‹x⇧⋆ ⊓ y ≤ z›*) have "x * (-y ⊔ z) ⊓ y = x * z ⊓ y" proof (rule order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹x * (- y ⊔ z) ⊓ y ≤ x * z ⊓ y› 2. ‹x * z ⊓ y ≤ x * (- y ⊔ z) ⊓ y›*) have "x * (-y ⊔ z) ⊓ y ≤ x * ((-y ⊔ z) ⊓ x⇧T * y)" by (simp add: dedekind_1 (*‹?x * ?y ⊓ ?z ≤ ?x * (?y ⊓ ?x⇧T * ?z)›*)) also (*calculation: ‹x * (- y ⊔ z) ⊓ y ≤ x * ((- y ⊔ z) ⊓ x⇧T * y)›*) have "... ≤ x * ((-y ⊔ z) ⊓ y)" by (simp add: assms( (*‹x⇧T * y ≤ y›*) 2) le_infI2 (*‹?b ≤ ?x ⟹ ?a ⊓ ?b ≤ ?x›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹x * (- y ⊔ z) ⊓ y ≤ x * ((- y ⊔ z) ⊓ y)›*) have "... ≤ x * z" by (simp add: inf.sup_monoid.add_commute (*‹?a ⊓ ?b = ?b ⊓ ?a›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) finally (*calculation: ‹x * (- y ⊔ z) ⊓ y ≤ x * z›*) show "x * (-y ⊔ z) ⊓ y ≤ x * z ⊓ y" by simp show "x * z ⊓ y ≤ x * (-y ⊔ z) ⊓ y" by (simp add: inf_commute (*‹?x ⊓ ?y = ?y ⊓ ?x›*) le_infI2 (*‹?b ≤ ?x ⟹ ?a ⊓ ?b ≤ ?x›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) qed also (*calculation: ‹x * (- y ⊔ z) ⊓ y = x * z ⊓ y›*) have "... ≤ (x ⊓ y * z⇧T) * z" by (simp add: dedekind_2 (*‹(?y::'a) * (?x::'a) ⊓ (?z::'a) ≤ (?y ⊓ ?z * ?x⇧T) * ?x›*)) also (*calculation: ‹(x::'a) * (- (y::'a) ⊔ (z::'a)) ⊓ y ≤ (x ⊓ y * z⇧T) * z›*) have "... ≤ (x ⊓ y) * z" by (simp add: assms( (*‹y * z⇧T ≤ y›*) 3) le_infI2 (*‹?b ≤ ?x ⟹ ?a ⊓ ?b ≤ ?x›*) mult_left_isotone (*‹?x ≤ ?y ⟹ ?x * ?z ≤ ?y * ?z›*)) also (*calculation: ‹x * (- y ⊔ z) ⊓ y ≤ (x ⊓ y) * z›*) have "... ≤ z" by (simp add: assms( (*‹((x::'a) ⊓ (y::'a)) * (z::'a) ≤ z›*) 4)) finally (*calculation: ‹x * (- y ⊔ z) ⊓ y ≤ z›*) have 1: "x * (-y ⊔ z) ⊓ y ≤ z" . have "(1 ⊔ x * (-y ⊔ z)) ⊓ y = (1 ⊓ y) ⊔ (x * (-y ⊔ z) ⊓ y)" by (simp add: comp_inf.mult_right_dist_sup (*‹((?x::'a) ⊔ (?y::'a)) ⊓ (?z::'a) = ?x ⊓ ?z ⊔ ?y ⊓ ?z›*)) also (*calculation: ‹Rf x (- y ⊔ z) ⊓ y = 1 ⊓ y ⊔ x * (- y ⊔ z) ⊓ y›*) have "... ≤ z" using "1" (*‹(x::'a) * (- (y::'a) ⊔ (z::'a)) ⊓ y ≤ z›*) by (simp add: assms( (*‹1 ⊓ y ≤ z›*) 1)) finally (*calculation: ‹Rf x (- y ⊔ z) ⊓ y ≤ z›*) have "1 ⊔ x * (-y ⊔ z) ≤ -y ⊔ z" using shunt1 (*‹(?x ⊓ ?y ≤ ?z) = (?x ≤ - ?y ⊔ ?z)›*) by blast hence "x⇧⋆ ≤ -y ⊔ z" using star_left_induct (*‹?z ⊔ ?y * ?x ≤ ?x ⟶ ?y⇧⋆ * ?z ≤ ?x›*) by fastforce thus "?thesis" (*goal: ‹(x::'a::type)⇧⋆ ⊓ (y::'a::type) ≤ (z::'a::type)›*) by (simp add: shunt1 (*‹(?x ⊓ ?y ≤ ?z) = (?x ≤ - ?y ⊔ ?z)›*)) qed lemma scc_2: assumes "x⇧T * y ≤ y" and "y * (x ⊓ y)⇧⋆⇧T ≤ y" shows "x⇧⋆ ⊓ y ≤ (x ⊓ y)⇧⋆" proof (-) (*goal: ‹x⇧⋆ ⊓ y ≤ (x ⊓ y)⇧⋆›*) have 1: "1 ⊓ y ≤ (x ⊓ y)⇧⋆" by (simp add: inf.coboundedI1 (*‹?a ≤ ?c ⟹ ?a ⊓ ?b ≤ ?c›*) star.circ_reflexive (*‹reflexive (?x⇧⋆)›*)) have "(x ⊓ y) * (x ⊓ y)⇧⋆ ≤ (x ⊓ y)⇧⋆" by (simp add: star.left_plus_below_circ (*‹?x⁺ ≤ ?x⇧⋆›*)) thus "?thesis" (*goal: ‹x⇧⋆ ⊓ y ≤ (x ⊓ y)⇧⋆›*) using "1" (*‹1 ⊓ y ≤ (x ⊓ y)⇧⋆›*) assms (*‹(x::'a)⇧T * (y::'a) ≤ y› ‹y * (x ⊓ y)⇧⋆⇧T ≤ y›*) scc_1 (*‹⟦1 ⊓ ?y ≤ ?z; ?x⇧T * ?y ≤ ?y; ?y * ?z⇧T ≤ ?y; (?x ⊓ ?y) * ?z ≤ ?z⟧ ⟹ ?x⇧⋆ ⊓ ?y ≤ ?z›*) by blast qed lemma scc_3: "x⇧⋆ ⊓ x⇧T⇧⋆ ≤ (x ⊓ x⇧T⇧⋆)⇧⋆" proof (-) (*goal: ‹(x::'a)⇧⋆ ⊓ x⇧T⇧⋆ ≤ (x ⊓ x⇧T⇧⋆)⇧⋆›*) have 1: "x⇧T * x⇧T⇧⋆ ≤ x⇧T⇧⋆" by (simp add: star.left_plus_below_circ (*‹?x⁺ ≤ ?x⇧⋆›*)) have "x⇧T⇧⋆ * (x ⊓ x⇧T⇧⋆)⇧⋆⇧T ≤ x⇧T⇧⋆ * x⇧⋆⇧T" by (simp add: star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*) conv_isotone (*‹?x ≤ ?y ⟹ ?x⇧T ≤ ?y⇧T›*) mult_right_isotone (*‹?x ≤ ?y ⟹ ?z * ?x ≤ ?z * ?y›*)) also (*calculation: ‹x⇧T⇧⋆ * (x ⊓ x⇧T⇧⋆)⇧⋆⇧T ≤ x⇧T⇧⋆ * x⇧⋆⇧T›*) have "... = x⇧T⇧⋆ * x⇧T⇧⋆" by (simp add: conv_star_commute (*‹?x⇧⋆⇧T = ?x⇧T⇧⋆›*)) finally (*calculation: ‹x⇧T⇧⋆ * (x ⊓ x⇧T⇧⋆)⇧⋆⇧T ≤ x⇧T⇧⋆ * x⇧T⇧⋆›*) have "x⇧T⇧⋆ * (x ⊓ x⇧T⇧⋆)⇧⋆⇧T ≤ x⇧T⇧⋆" by (simp add: star.circ_transitive_equal (*‹idempotent (?x⇧⋆)›*)) thus "?thesis" (*goal: ‹x⇧⋆ ⊓ x⇧T⇧⋆ ≤ (x ⊓ x⇧T⇧⋆)⇧⋆›*) using "1" (*‹x⇧T⁺ ≤ x⇧T⇧⋆›*) scc_2 (*‹⟦?x⇧T * ?y ≤ ?y; ?y * (?x ⊓ ?y)⇧⋆⇧T ≤ ?y⟧ ⟹ ?x⇧⋆ ⊓ ?y ≤ (?x ⊓ ?y)⇧⋆›*) by auto qed lemma scc_4: "x⇧⋆ ⊓ x⇧T⇧⋆ = (x ⊓ x⇧T⇧⋆)⇧⋆" proof (rule order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹x⇧⋆ ⊓ x⇧T⇧⋆ ≤ (x ⊓ x⇧T⇧⋆)⇧⋆› 2. ‹(x ⊓ x⇧T⇧⋆)⇧⋆ ≤ x⇧⋆ ⊓ x⇧T⇧⋆›*) show "x⇧⋆ ⊓ x⇧T⇧⋆ ≤ (x ⊓ x⇧T⇧⋆)⇧⋆" by (simp add: scc_3 (*‹?x⇧⋆ ⊓ ?x⇧T⇧⋆ ≤ (?x ⊓ ?x⇧T⇧⋆)⇧⋆›*)) have 1: "(x ⊓ x⇧T⇧⋆)⇧⋆ ≤ x⇧⋆" by (simp add: star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) have "(x ⊓ x⇧T⇧⋆)⇧⋆ ≤ x⇧T⇧⋆⇧⋆" by (simp add: star_isotone (*‹?x ≤ ?y ⟹ ?x⇧⋆ ≤ ?y⇧⋆›*)) also (*calculation: ‹((x::'a) ⊓ x⇧T⇧⋆)⇧⋆ ≤ x⇧T⇧⋆⇧⋆›*) have "... = x⇧T⇧⋆" using star_involutive (*‹(?x::'a::type)⇧⋆ = ?x⇧⋆⇧⋆›*) by auto finally (*calculation: ‹(x ⊓ x⇧T⇧⋆)⇧⋆ ≤ x⇧T⇧⋆›*) show "(x ⊓ x⇧T⇧⋆)⇧⋆ ≤ x⇧⋆ ⊓ x⇧T⇧⋆" using "1" (*‹(x ⊓ x⇧T⇧⋆)⇧⋆ ≤ x⇧⋆›*) by simp qed end class stone_kleene_relation_algebra_tarski = stone_kleene_relation_algebra + stone_relation_algebra_tarski class kleene_relation_algebra_tarski = kleene_relation_algebra + stone_kleene_relation_algebra_tarski begin subclass relation_algebra_tarski .. end class stone_kleene_relation_algebra_consistent = stone_kleene_relation_algebra + stone_relation_algebra_consistent begin lemma acyclic_reachable_different: assumes "acyclic p" "bijective y" "x ≤ p⁺ * y" shows "x ≠ y" proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹¬ x ≠ y ⟹ False›*) assume 1: "¬ x ≠ y" (*‹¬ (x::'a) ≠ (y::'a)›*) have "x * y⇧T ≤ p⁺" using assms(2,3) (*‹bijective y› ‹(x::'a::type) ≤ (p::'a::type)⁺ * (y::'a::type)›*) shunt_bijective (*‹bijective (?z::'a) ⟹ ((?x::'a) ≤ (?y::'a) * ?z) = (?x * ?z⇧T ≤ ?y)›*) by blast also (*calculation: ‹x * y⇧T ≤ p⁺›*) have "... ≤ -1" by (simp add: assms( (*‹pd_kleene_allegory_class.acyclic (p::'a::type)›*) 1)) finally (*calculation: ‹irreflexive (x * y⇧T)›*) show False using "1" (*‹¬ x ≠ y›*) by (metis assms( (*‹bijective y›*) 2) dual_order.antisym (*‹⟦?b ≤ ?a; ?a ≤ ?b⟧ ⟹ ?a = ?b›*) le_supI2 (*‹?x ≤ ?b ⟹ ?x ≤ ?a ⊔ ?b›*) mult_1_left (*‹1 * ?a = ?a›*) order_char_1 (*‹(?x ≤ ?y) = (?x ≤ ?y ⊔ - ?x)›*) point_not_bot (*‹point ?p ⟹ ?p ≠ bot›*) schroeder_4_p (*‹(?x * ?y ≤ - ?z) = (?z * ?y⇧T ≤ - ?x)›*) semiring.mult_not_zero (*‹?a * ?b ≠ bot ⟹ ?a ≠ bot ∧ ?b ≠ bot›*)) qed end class kleene_relation_algebra_consistent = kleene_relation_algebra + stone_kleene_relation_algebra_consistent begin subclass relation_algebra_consistent .. end class stone_kleene_relation_algebra_tarski_consistent = stone_kleene_relation_algebra + stone_relation_algebra_tarski_consistent begin subclass stone_kleene_relation_algebra_tarski .. subclass stone_kleene_relation_algebra_consistent .. end class kleene_relation_algebra_tarski_consistent = kleene_relation_algebra + stone_kleene_relation_algebra_tarski_consistent begin subclass relation_algebra_tarski_consistent .. end class linorder_stone_kleene_relation_algebra_tarski_consistent_expansion = linorder_stone_kleene_relation_algebra_expansion + non_trivial_bounded_order begin subclass stone_kleene_relation_algebra_tarski_consistent apply unfold_locales by (simp_all add: bot_not_top) end end
{ "path": "afp-2025-02-12/thys/Stone_Kleene_Relation_Algebras/Kleene_Relation_Algebras.thy", "repo": "afp-2025-02-12", "sha": "a4a8747a27fba43cd6352134873de9e34334e70bac1cbb07f13bcbc78538fce5" }
(* * Copyright 2014, NICTA * * This software may be distributed and modified according to the terms of * the BSD 2-Clause license. Note that NO WARRANTY is provided. * See "LICENSE_BSD2.txt" for details. * * @TAG(NICTA_BSD) *) (* Miscellaneous library definitions and lemmas. *) chapter "Library" theory Lib imports Main begin (* FIXME: eliminate *) lemma hd_map_simp: "b ≠ [] ⟹ hd (map a b) = a (hd b)" by (rule hd_map (*‹?xs ≠ [] ⟹ hd (map ?f ?xs) = ?f (hd ?xs)›*)) lemma tl_map_simp: "tl (map a b) = map a (tl b)" apply (induct b) (*goals: 1. ‹tl (map (a::'b ⇒ 'a) []) = map a (tl [])› 2. ‹⋀(aa::'b) b::'b list. tl (map (a::'b ⇒ 'a) b) = map a (tl b) ⟹ tl (map a (aa # b)) = map a (tl (aa # b))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . (* FIXME: could be added to Set.thy *) lemma Collect_eq: "{x. P x} = {x. Q x} ⟷ (∀x. P x = Q x)" apply (rule iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*)) (*goals: 1. ‹{x::'a. (P::'a ⇒ bool) x} = {x::'a. (Q::'a ⇒ bool) x} ⟹ ∀x::'a. P x = Q x› 2. ‹∀x::'a. (P::'a ⇒ bool) x = (Q::'a ⇒ bool) x ⟹ {x::'a. P x} = {x::'a. Q x}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . (* FIXME: move next to HOL.iff_allI *) lemma iff_impI: "⟦P ⟹ Q = R⟧ ⟹ (P ⟶ Q) = (P ⟶ R)" by blast definition fun_app :: "('a ⇒ 'b) ⇒ 'a ⇒ 'b" (infixr "$" 10) where "f $ x ≡ f x" declare fun_app_def [iff] lemma fun_app_cong[fundef_cong]: "⟦ f x = f' x' ⟧ ⟹ (f $ x) = (f' $ x')" by simp lemma fun_app_apply_cong[fundef_cong]: "f x y = f' x' y' ⟹ (f $ x) y = (f' $ x') y'" by simp lemma if_apply_cong[fundef_cong]: "⟦ P = P'; x = x'; P' ⟹ f x' = f' x'; ¬ P' ⟹ g x' = g' x' ⟧ ⟹ (if P then f else g) x = (if P' then f' else g') x'" by simp lemma case_prod_apply_cong[fundef_cong]: "⟦ f (fst p) (snd p) s = f' (fst p') (snd p') s' ⟧ ⟹ case_prod f p s = case_prod f' p' s'" by (simp add: split_def (*‹case_prod = (λc p. c (fst p) (snd p))›*)) definition pred_conj :: "('a ⇒ bool) ⇒ ('a ⇒ bool) ⇒ ('a ⇒ bool)" (infixl "and" 35) where "pred_conj P Q ≡ λx. P x ∧ Q x" definition pred_disj :: "('a ⇒ bool) ⇒ ('a ⇒ bool) ⇒ ('a ⇒ bool)" (infixl "or" 30) where "pred_disj P Q ≡ λx. P x ∨ Q x" definition pred_neg :: "('a ⇒ bool) ⇒ ('a ⇒ bool)" ("not _" [40] 40) where "pred_neg P ≡ λx. ¬ P x" definition "K ≡ λx y. x" definition zipWith :: "('a ⇒ 'b ⇒ 'c) ⇒ 'a list ⇒ 'b list ⇒ 'c list" where "zipWith f xs ys ≡ map (case_prod f) (zip xs ys)" primrec delete :: "'a ⇒ 'a list ⇒ 'a list" where "delete y [] = []" | "delete y (x#xs) = (if y=x then xs else x # delete y xs)" primrec find :: "('a ⇒ bool) ⇒ 'a list ⇒ 'a option" where "find f [] = None" | "find f (x # xs) = (if f x then Some x else find f xs)" definition "swp f ≡ λx y. f y x" primrec (nonexhaustive) theRight :: "'a + 'b ⇒ 'b" where "theRight (Inr x) = x" primrec (nonexhaustive) theLeft :: "'a + 'b ⇒ 'a" where "theLeft (Inl x) = x" definition "isLeft x ≡ (∃y. x = Inl y)" definition "isRight x ≡ (∃y. x = Inr y)" definition "const x ≡ λy. x" lemma tranclD2: "(x, y) ∈ R⁺ ⟹ ∃z. (x, z) ∈ R⇧* ∧ (z, y) ∈ R" apply (erule tranclE (*‹⟦(?a, ?b) ∈ ?r⁺; (?a, ?b) ∈ ?r ⟹ ?thesis; ⋀c. ⟦(?a, c) ∈ ?r⁺; (c, ?b) ∈ ?r⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) (*goals: 1. ‹(x, y) ∈ R ⟹ ∃z. (x, z) ∈ R⇧* ∧ (z, y) ∈ R› 2. ‹⋀c. ⟦(x, c) ∈ R⁺; (c, y) ∈ R⟧ ⟹ ∃z. (x, z) ∈ R⇧* ∧ (z, y) ∈ R› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma linorder_min_same1 [simp]: "(min y x = y) = (y ≤ (x::'a::linorder))" by (auto simp: min_def (*‹min (?a::?'a::ord) (?b::?'a::ord) = (if ?a ≤ ?b then ?a else ?b)›*) linorder_not_less (*‹(¬ (?x::?'a::linorder) < (?y::?'a::linorder)) = (?y ≤ ?x)›*)) lemma linorder_min_same2 [simp]: "(min x y = y) = (y ≤ (x::'a::linorder))" by (auto simp: min_def (*‹min ?a ?b = (if ?a ≤ ?b then ?a else ?b)›*) linorder_not_le (*‹(¬ ?x ≤ ?y) = (?y < ?x)›*)) text ‹A combinator for pairing up well-formed relations. The divisor function splits the population in halves, with the True half greater than the False half, and the supplied relations control the order within the halves.› definition wf_sum :: "('a ⇒ bool) ⇒ ('a × 'a) set ⇒ ('a × 'a) set ⇒ ('a × 'a) set" where "wf_sum divisor r r' ≡ ({(x, y). ¬ divisor x ∧ ¬ divisor y} ∩ r') ∪ {(x, y). ¬ divisor x ∧ divisor y} ∪ ({(x, y). divisor x ∧ divisor y} ∩ r)" lemma wf_sum_wf: "⟦ wf r; wf r' ⟧ ⟹ wf (wf_sum divisor r r')" apply (simp add: wf_sum_def (*‹wf_sum (?divisor::?'a ⇒ bool) (?r::(?'a × ?'a) set) (?r'::(?'a × ?'a) set) ≡ {(x::?'a, y::?'a). ¬ ?divisor x ∧ ¬ ?divisor y} ∩ ?r' ∪ {(x::?'a, y::?'a). ¬ ?divisor x ∧ ?divisor y} ∪ {(x::?'a, y::?'a). ?divisor x ∧ ?divisor y} ∩ ?r›*)) (*goal: ‹⟦wf r; wf r'⟧ ⟹ wf (wf_sum divisor r r')›*) apply (rule wf_Un (*‹⟦wf ?r; wf ?s; Domain ?r ∩ Range ?s = {}⟧ ⟹ wf (?r ∪ ?s)›*)) (*goals: 1. ‹⟦wf r; wf r'⟧ ⟹ wf ({x. ¬ divisor x} × {y. ¬ divisor y} ∩ r' ∪ {x. ¬ divisor x} × {y. divisor y})› 2. ‹⟦wf r; wf r'⟧ ⟹ wf ({x. divisor x} × {y. divisor y} ∩ r)› 3. ‹⟦wf r; wf r'⟧ ⟹ Domain ({x. ¬ divisor x} × {y. ¬ divisor y} ∩ r' ∪ {x. ¬ divisor x} × {y. divisor y}) ∩ Range ({x. divisor x} × {y. divisor y} ∩ r) = {}› discuss goal 1*) apply (rule wf_Un (*‹⟦wf ?r; wf ?s; Domain ?r ∩ Range ?s = {}⟧ ⟹ wf (?r ∪ ?s)›*)) (*goals: 1. ‹⟦wf r; wf r'⟧ ⟹ wf ({x. ¬ divisor x} × {y. ¬ divisor y} ∩ r')› 2. ‹⟦wf r; wf r'⟧ ⟹ wf ({x. ¬ divisor x} × {y. divisor y})› 3. ‹⟦wf r; wf r'⟧ ⟹ Domain ({x. ¬ divisor x} × {y. ¬ divisor y} ∩ r') ∩ Range ({x. ¬ divisor x} × {y. divisor y}) = {}› discuss goal 1*) apply (erule wf_Int2 (*‹wf (?r::(?'a × ?'a) set) ⟹ wf ((?r'::(?'a × ?'a) set) ∩ ?r)›*)) (*discuss goal 2*) apply (rule wf_subset [where r="measure (λx. If (divisor x) 1 0)"] (*‹⟦wf (measure (λx. if divisor x then 1 else 0)); ?p ⊆ measure (λx. if divisor x then 1 else 0)⟧ ⟹ wf ?p›*)) (*goals: 1. ‹⟦wf r; wf r'⟧ ⟹ wf (measure (λx. if divisor x then 1 else 0))› 2. ‹⟦wf r; wf r'⟧ ⟹ {x. ¬ divisor x} × {y. divisor y} ⊆ measure (λx. if divisor x then 1 else 0)› discuss goal 1*) apply simp (*discuss goal 2*) apply clarsimp (*proven 2 subgoals*) (*discuss goal 3*) apply blast (*proven 3 subgoals*) (*discuss goal 2*) apply (erule wf_Int2 (*‹wf (?r::(?'a × ?'a) set) ⟹ wf ((?r'::(?'a × ?'a) set) ∩ ?r)›*)) (*discuss goal 3*) apply blast (*proven 3 subgoals*) . abbreviation(input) "option_map == map_option" lemmas option_map_def = map_option_case lemma False_implies_equals [simp]: "((False ⟹ P) ⟹ PROP Q) ≡ PROP Q" apply (rule equal_intr_rule (*‹⟦PROP ?phi ⟹ PROP ?psi; PROP ?psi ⟹ PROP ?phi⟧ ⟹ PROP ?phi ≡ PROP ?psi›*)) (*goals: 1. ‹((False ⟹ P::bool) ⟹ PROP Q::prop) ⟹ PROP Q› 2. ‹⟦PROP Q::prop; False ⟹ P::bool⟧ ⟹ PROP Q› discuss goal 1*) apply (erule meta_mp (*‹⟦PROP ?P ⟹ PROP ?Q; PROP ?P⟧ ⟹ PROP ?Q›*)) (*top goal: ‹((False ⟹ P) ⟹ PROP Q) ⟹ PROP Q› and 1 goal remains*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma split_paired_Ball: "(∀x ∈ A. P x) = (∀x y. (x,y) ∈ A ⟶ P (x,y))" by auto lemma split_paired_Bex: "(∃x ∈ A. P x) = (∃x y. (x,y) ∈ A ∧ P (x,y))" by auto end
{ "path": "afp-2025-02-12/thys/Planarity_Certificates/l4v/lib/Lib.thy", "repo": "afp-2025-02-12", "sha": "7c6784c0102fce15842ee97e76d44c417c89ccd343cd2d0d5bb34f34e30bb2f8" }
(* Author: Wenda Li <wl302@cam.ac.uk / liwenda1990@hotmail.com> *) section ‹Some useful lemmas about transcendental functions› theory Missing_Transcendental imports Missing_Topology Missing_Algebraic begin subsection ‹Misc› lemma exp_Arg2pi2pi_multivalue: assumes "exp (𝗂 * of_real x) = z" shows "∃k::int. x = Arg2pi z + 2*k*pi" proof (-) (*goal: ‹∃xa. x = Arg2pi z + 2 * real_of_int xa * pi›*) define k where "k=floor( x/(2*pi))" define x' where "x'= x - (2*k*pi)" have "x'/(2*pi) ≥0" unfolding x'_def k_def (*goal: ‹0 ≤ (x - real_of_int (2 * ⌊x / (2 * pi)⌋) * pi) / (2 * pi)›*) by (simp add: diff_divide_distrib (*‹((?a::?'a::division_ring) - (?b::?'a::division_ring)) / (?c::?'a::division_ring) = ?a / ?c - ?b / ?c›*)) moreover have "x'/(2*pi) < 1" proof (-) (*goal: ‹x' / (2 * pi) < 1›*) have "x/(2*pi) - k < 1" unfolding k_def (*goal: ‹x / (2 * pi) - real_of_int ⌊x / (2 * pi)⌋ < 1›*) by linarith thus "?thesis" (*goal: ‹x' / (2 * pi) < 1›*) unfolding k_def x'_def (*goal: ‹(x - real_of_int (2 * ⌊x / (2 * pi)⌋) * pi) / (2 * pi) < 1›*) by (auto simp add:field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 77 facts*)) qed ultimately have "x'≥0" and "x'<2*pi" apply - (*goals: 1. ‹⟦0 ≤ x' / (2 * pi); x' / (2 * pi) < 1⟧ ⟹ 0 ≤ x'› 2. ‹⟦0 ≤ x' / (2 * pi); x' / (2 * pi) < 1⟧ ⟹ x' < 2 * pi› discuss goal 1*) apply ((auto simp add:field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 77 facts*))[1]) (*discuss goal 2*) apply ((auto simp add:field_simps (*‹(?a::?'a::semigroup_add) + (?b::?'a::semigroup_add) + (?c::?'a::semigroup_add) = ?a + (?b + ?c)› ‹(?a::?'a::ab_semigroup_add) + (?b::?'a::ab_semigroup_add) = ?b + ?a› ‹(?b::?'a::ab_semigroup_add) + ((?a::?'a::ab_semigroup_add) + (?c::?'a::ab_semigroup_add)) = ?a + (?b + ?c)› ‹(?a::?'a::semigroup_mult) * (?b::?'a::semigroup_mult) * (?c::?'a::semigroup_mult) = ?a * (?b * ?c)› ‹(?a::?'a::ab_semigroup_mult) * (?b::?'a::ab_semigroup_mult) = ?b * ?a› ‹(?b::?'a::ab_semigroup_mult) * ((?a::?'a::ab_semigroup_mult) * (?c::?'a::ab_semigroup_mult)) = ?a * (?b * ?c)› ‹(?a::?'a::cancel_ab_semigroup_add) - (?b::?'a::cancel_ab_semigroup_add) - (?c::?'a::cancel_ab_semigroup_add) = ?a - (?b + ?c)› ‹(?a::?'a::group_add) + ((?b::?'a::group_add) - (?c::?'a::group_add)) = ?a + ?b - ?c› ‹((?a::?'a::group_add) - (?b::?'a::group_add) = (?c::?'a::group_add)) = (?a = ?c + ?b)› ‹((?a::?'a::group_add) = (?c::?'a::group_add) - (?b::?'a::group_add)) = (?a + ?b = ?c)› ‹(?a::?'a::group_add) - ((?b::?'a::group_add) - (?c::?'a::group_add)) = ?a + ?c - ?b› ‹(?a::?'a::ab_group_add) - (?b::?'a::ab_group_add) + (?c::?'a::ab_group_add) = ?a + ?c - ?b› and more 77 facts*))[1]) (*proven 2 subgoals*) . moreover have "exp (𝗂 * complex_of_real x') = z" using assms (*‹exp (𝗂 * complex_of_real x) = z›*) x'_def (*‹(x'::real) = (x::real) - real_of_int ((2::int) * (k::int)) * pi›*) by (auto simp add:field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 77 facts*)) ultimately have "Arg2pi z = x'" using Arg2pi_unique[of 1 x' z, simplified] (*‹⟦exp (𝗂 * complex_of_real x') = z; 0 ≤ x'; x' < 2 * pi⟧ ⟹ Arg2pi z = x'›*) by auto hence " x = Arg2pi z + 2*k*pi" unfolding x'_def (*goal: ‹x = Arg2pi z + real_of_int (2 * k) * pi›*) by auto thus "?thesis" (*goal: ‹∃xa. x = Arg2pi z + 2 * real_of_int xa * pi›*) by auto qed lemma uniform_discrete_tan_eq: "uniform_discrete {x::real. tan x = y}" proof (-) (*goal: ‹uniform_discrete {x. tan x = y}›*) have "x1=x2" if dist: "dist x1 x2<pi/2" and "tan x1=y" "tan x2=y" for x1 and x2 proof (-) (*goal: ‹x1 = x2›*) obtain k1 :: int where x1: "x1 = arctan y + k1*pi ∨ (x1 = pi/2 + k1*pi ∧ y=0)" (*goal: ‹(⋀k1. x1 = arctan y + real_of_int k1 * pi ∨ x1 = pi / 2 + real_of_int k1 * pi ∧ y = 0 ⟹ thesis) ⟹ thesis›*) using tan_eq_arctan_Ex (*‹(tan ?x = ?y) = (∃x. ?x = arctan ?y + real_of_int x * pi ∨ ?x = pi / 2 + real_of_int x * pi ∧ ?y = 0)›*) ‹tan x1=y› (*‹tan x1 = y›*) by auto obtain k2 :: int where x2: "x2 = arctan y + k2*pi ∨ (x2 = pi/2 + k2*pi ∧ y=0)" (*goal: ‹(⋀k2::int. (x2::real) = arctan (y::real) + real_of_int k2 * pi ∨ x2 = pi / (2::real) + real_of_int k2 * pi ∧ y = (0::real) ⟹ thesis::bool) ⟹ thesis›*) using tan_eq_arctan_Ex (*‹(tan ?x = ?y) = (∃x. ?x = arctan ?y + real_of_int x * pi ∨ ?x = pi / 2 + real_of_int x * pi ∧ ?y = 0)›*) ‹tan x2=y› (*‹tan x2 = y›*) by auto let ?xk1 = "x1 = arctan y + k1*pi" and ?xk1' = "x1 = pi/2 + k1*pi ∧ y=0" let ?xk2 = "x2 = arctan y + k2*pi" and ?xk2' = "x2 = pi/2 + k2*pi ∧ y=0" have "?thesis" if "(?xk1 ∧ ?xk2) ∨ (?xk1' ∧ ?xk2')" proof (-) (*goal: ‹x1 = x2›*) have "x1-x2= (k1 - k2) *pi" if "?xk1" "?xk2" using arg_cong2[where f = minus, OF ‹?xk1› ‹?xk2›] (*‹x1 - x2 = arctan y + real_of_int k1 * pi - (arctan y + real_of_int k2 * pi)›*) by (auto simp add:algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 34 facts*)) moreover have "x1-x2= (k1 - k2) *pi" if "?xk1'" "?xk2'" using arg_cong2[where f = minus, OF conjunct1 [ OF ‹?xk1'› ] conjunct1 [ OF ‹?xk2'› ]] (*‹(x1::real) - (x2::real) = pi / (2::real) + real_of_int (k1::int) * pi - (pi / (2::real) + real_of_int (k2::int) * pi)›*) by (auto simp add:algebra_simps (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)› ‹(?a::?'a) * (?b::?'a) * (?c::?'a) = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)› ‹(?a::?'a) - (?b::?'a) - (?c::?'a) = ?a - (?b + ?c)› ‹(?a::?'a) + ((?b::?'a) - (?c::?'a)) = ?a + ?b - ?c› ‹((?a::?'a) - (?b::?'a) = (?c::?'a)) = (?a = ?c + ?b)› ‹((?a::?'a) = (?c::?'a) - (?b::?'a)) = (?a + ?b = ?c)› ‹(?a::?'a) - ((?b::?'a) - (?c::?'a)) = ?a + ?c - ?b› ‹(?a::?'a) - (?b::?'a) + (?c::?'a) = ?a + ?c - ?b› and more 34 facts*)) ultimately have "x1-x2= (k1 - k2) *pi" using that (*‹(x1::real) = arctan (y::real) + real_of_int (k1::int) * pi ∧ (x2::real) = arctan y + real_of_int (k2::int) * pi ∨ (x1 = pi / (2::real) + real_of_int k1 * pi ∧ y = (0::real)) ∧ x2 = pi / (2::real) + real_of_int k2 * pi ∧ y = (0::real)›*) by auto then have "¦k1 - k2¦ < 1/2" using dist[unfolded dist_real_def] (*‹¦x1 - x2¦ < pi / 2›*) by (auto simp add:abs_mult (*‹¦(?a::?'a) * (?b::?'a)¦ = ¦?a¦ * ¦?b¦›*)) then have "k1=k2" by linarith then show "?thesis" (*goal: ‹x1 = x2›*) using that (*‹(x1::real) = arctan (y::real) + real_of_int (k1::int) * pi ∧ (x2::real) = arctan y + real_of_int (k2::int) * pi ∨ (x1 = pi / (2::real) + real_of_int k1 * pi ∧ y = (0::real)) ∧ x2 = pi / (2::real) + real_of_int k2 * pi ∧ y = (0::real)›*) by auto qed moreover have "?thesis" if "?xk1" "?xk2'" proof (-) (*goal: ‹x1 = x2›*) have "x1 = k1*pi" "x2 = pi / 2 + k2 * pi" using ‹?xk2'› (*‹x2 = pi / 2 + real_of_int k2 * pi ∧ y = 0›*) ‹?xk1› (*‹x1 = arctan y + real_of_int k1 * pi›*) apply - (*goals: 1. ‹⟦x2 = pi / 2 + real_of_int k2 * pi ∧ y = 0; x1 = arctan y + real_of_int k1 * pi⟧ ⟹ x1 = real_of_int k1 * pi› 2. ‹⟦x2 = pi / 2 + real_of_int k2 * pi ∧ y = 0; x1 = arctan y + real_of_int k1 * pi⟧ ⟹ x2 = pi / 2 + real_of_int k2 * pi› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . from arg_cong2[where f = minus, OF this] (*‹(x1::real) - (x2::real) = real_of_int (k1::int) * pi - (pi / (2::real) + real_of_int (k2::int) * pi)›*) have "x1 - x2 = (k1 - k2) * pi -pi/2" by (auto simp add:algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 34 facts*)) then have "¦(k1 - k2) * pi -pi/2¦ < pi/2" using dist[unfolded dist_real_def] (*‹¦x1 - x2¦ < pi / 2›*) by auto then have "0<k1-k2" "k1-k2<1" unfolding abs_less_iff (*goals: 1. ‹0 < k1 - k2› 2. ‹k1 - k2 < 1›*) apply - (*goals: 1. ‹real_of_int (k1 - k2) * pi - pi / 2 < pi / 2 ∧ - (real_of_int (k1 - k2) * pi - pi / 2) < pi / 2 ⟹ 0 < k1 - k2› 2. ‹real_of_int (k1 - k2) * pi - pi / 2 < pi / 2 ∧ - (real_of_int (k1 - k2) * pi - pi / 2) < pi / 2 ⟹ k1 - k2 < 1› discuss goal 1*) apply ((auto simp add: zero_less_mult_iff (*‹(0 < ?a * ?b) = (0 < ?a ∧ 0 < ?b ∨ ?a < 0 ∧ ?b < 0)›*))[1]) (*discuss goal 2*) apply ((auto simp add: zero_less_mult_iff (*‹(0 < ?a * ?b) = (0 < ?a ∧ 0 < ?b ∨ ?a < 0 ∧ ?b < 0)›*))[1]) (*proven 2 subgoals*) . then have False by simp then show "?thesis" (*goal: ‹(x1::real) = (x2::real)›*) by auto qed moreover have "?thesis" if "?xk1'" "?xk2" proof (-) (*goal: ‹x1 = x2›*) have "x1 = pi / 2 + k1*pi" "x2 = k2 * pi" using ‹?xk2› (*‹x2 = arctan y + real_of_int k2 * pi›*) ‹?xk1'› (*‹(x1::real) = pi / (2::real) + real_of_int (k1::int) * pi ∧ (y::real) = (0::real)›*) apply - (*goals: 1. ‹⟦x2 = arctan y + real_of_int k2 * pi; x1 = pi / 2 + real_of_int k1 * pi ∧ y = 0⟧ ⟹ x1 = pi / 2 + real_of_int k1 * pi› 2. ‹⟦x2 = arctan y + real_of_int k2 * pi; x1 = pi / 2 + real_of_int k1 * pi ∧ y = 0⟧ ⟹ x2 = real_of_int k2 * pi› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . from arg_cong2[where f = minus, OF this] (*‹(x1::real) - (x2::real) = pi / (2::real) + real_of_int (k1::int) * pi - real_of_int (k2::int) * pi›*) have "x1 - x2 = (k1 - k2) * pi + pi/2" by (auto simp add:algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 34 facts*)) then have "¦(k1 - k2) * pi + pi/2¦ < pi/2" using dist[unfolded dist_real_def] (*‹¦x1 - x2¦ < pi / 2›*) by auto then have "¦(k1 - k2 + 1/2)*pi¦ < pi/2" by (auto simp add:algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 34 facts*)) then have "¦(k1 - k2 + 1/2)¦ < 1/2" by (auto simp add:abs_mult (*‹¦?a * ?b¦ = ¦?a¦ * ¦?b¦›*)) then have "-1<k1-k2 ∧ k1-k2<0" unfolding abs_less_iff (*goal: ‹- (1::int) < (k1::int) - (k2::int) ∧ k1 - k2 < (0::int)›*) by linarith then have False by auto then show "?thesis" (*goal: ‹x1 = x2›*) by auto qed ultimately show "?thesis" (*goal: ‹(x1::real) = (x2::real)›*) using x1 (*‹x1 = arctan y + real_of_int k1 * pi ∨ x1 = pi / 2 + real_of_int k1 * pi ∧ y = 0›*) x2 (*‹x2 = arctan y + real_of_int k2 * pi ∨ x2 = pi / 2 + real_of_int k2 * pi ∧ y = 0›*) by blast qed then show "?thesis" (*goal: ‹uniform_discrete {x. tan x = y}›*) unfolding uniform_discrete_def (*goal: ‹∃e>0. ∀x∈{x. tan x = y}. ∀y∈{x. tan x = y}. dist x y < e ⟶ x = y›*) apply (intro exI[where x="pi/2"] (*‹(?P::real ⇒ bool) (pi / (2::real)) ⟹ ∃x::real. ?P x›*)) (*goal: ‹∃e>0::real. ∀x::real∈{x::real. tan x = (y::real)}. ∀y::real∈{x::real. tan x = y}. dist x y < e ⟶ x = y›*) by auto qed lemma get_norm_value: fixes a::"'a::{floor_ceiling}" assumes "pp>0" obtains k::int and a1 where "a=(of_int k)*pp+a1" "a0≤a1" "a1<a0+pp" proof (-) (*goal: ‹(⋀k a1. ⟦a = of_int k * pp + a1; a0 ≤ a1; a1 < a0 + pp⟧ ⟹ thesis) ⟹ thesis›*) define k where "k=floor ((a-a0)/pp)" define a1 where "a1=a-(of_int k)*pp" have "of_int ⌊(a - a0) / pp⌋ * pp ≤ a- a0" using assms (*‹0 < pp›*) by (meson le_divide_eq (*‹(?a ≤ ?b / ?c) = (if 0 < ?c then ?a * ?c ≤ ?b else if ?c < 0 then ?b ≤ ?a * ?c else ?a ≤ 0)›*) of_int_floor_le (*‹of_int ⌊?x⌋ ≤ ?x›*)) moreover have "a-a0 < of_int (⌊(a - a0) / pp⌋+1) * pp" using assms (*‹0 < pp›*) by (meson divide_less_eq (*‹((?b::?'a::linordered_field) / (?c::?'a::linordered_field) < (?a::?'a::linordered_field)) = (if (0::?'a::linordered_field) < ?c then ?b < ?a * ?c else if ?c < (0::?'a::linordered_field) then ?a * ?c < ?b else (0::?'a::linordered_field) < ?a)›*) floor_correct (*‹of_int ⌊?x::?'a::floor_ceiling⌋ ≤ ?x ∧ ?x < of_int (⌊?x⌋ + (1::int))›*)) ultimately show "?thesis" (*goal: ‹thesis›*) apply (intro that[of k a1] (*‹⟦a = of_int k * pp + a1; a0 ≤ a1; a1 < a0 + pp⟧ ⟹ thesis›*)) (*goal: ‹thesis›*) unfolding k_def a1_def (*goals: 1. ‹⟦of_int ⌊(a - a0) / pp⌋ * pp ≤ a - a0; a - a0 < of_int (⌊(a - a0) / pp⌋ + 1) * pp⟧ ⟹ a = of_int ⌊(a - a0) / pp⌋ * pp + (a - of_int ⌊(a - a0) / pp⌋ * pp)› 2. ‹⟦of_int ⌊(a - a0) / pp⌋ * pp ≤ a - a0; a - a0 < of_int (⌊(a - a0) / pp⌋ + 1) * pp⟧ ⟹ a0 ≤ a - of_int ⌊(a - a0) / pp⌋ * pp› 3. ‹⟦of_int ⌊(a - a0) / pp⌋ * pp ≤ a - a0; a - a0 < of_int (⌊(a - a0) / pp⌋ + 1) * pp⟧ ⟹ a - of_int ⌊(a - a0) / pp⌋ * pp < a0 + pp›*) using assms (*‹(0::'a::floor_ceiling) < (pp::'a::floor_ceiling)›*) (*goals: 1. ‹⟦of_int ⌊(a - a0) / pp⌋ * pp ≤ a - a0; a - a0 < of_int (⌊(a - a0) / pp⌋ + 1) * pp⟧ ⟹ a = of_int ⌊(a - a0) / pp⌋ * pp + (a - of_int ⌊(a - a0) / pp⌋ * pp)› 2. ‹⟦of_int ⌊(a - a0) / pp⌋ * pp ≤ a - a0; a - a0 < of_int (⌊(a - a0) / pp⌋ + 1) * pp⟧ ⟹ a0 ≤ a - of_int ⌊(a - a0) / pp⌋ * pp› 3. ‹⟦of_int ⌊(a - a0) / pp⌋ * pp ≤ a - a0; a - a0 < of_int (⌊(a - a0) / pp⌋ + 1) * pp⟧ ⟹ a - of_int ⌊(a - a0) / pp⌋ * pp < a0 + pp› discuss goal 1*) apply ((auto simp add:algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 34 facts*))[1]) (*discuss goal 2*) apply ((auto simp add:algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 34 facts*))[1]) (*discuss goal 3*) apply ((auto simp add:algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 34 facts*))[1]) (*proven 3 subgoals*) . qed (*Is it possible to generalise or simplify this messy proof?*) lemma filtermap_tan_at_right: fixes a::real assumes "cos a≠0" shows "filtermap tan (at_right a) = at_right (tan a)" proof (-) (*goal: ‹filtermap tan (at_right a) = at_right (tan a)›*) obtain k :: int and a1 where aa1: "a=k*pi+a1" and pi_a1: "-pi/2≤a1" "a1<pi/2" (*goal: ‹(⋀(k::int) a1::real. ⟦(a::real) = real_of_int k * pi + a1; - pi / (2::real) ≤ a1; a1 < pi / (2::real)⟧ ⟹ thesis::bool) ⟹ thesis›*) using get_norm_value[of pi a "-pi/2"] (*‹⟦0 < pi; ⋀k a1. ⟦a = real_of_int k * pi + a1; - pi / 2 ≤ a1; a1 < - pi / 2 + pi⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) by auto have "-pi/2 < a1" using assms (*‹cos a ≠ 0›*) by (smt (verit, ccfv_SIG) pi_a1 (*‹- pi / (2::real) ≤ (a1::real)› ‹(a1::real) < pi / (2::real)›*) aa1 (*‹(a::real) = real_of_int (k::int) * pi + (a1::real)›*) cos_2pi_minus (*‹cos ((2::real) * pi - (?x::real)) = cos ?x›*) cos_diff (*‹cos ((?x::?'a) - (?y::?'a)) = cos ?x * cos ?y + sin ?x * sin ?y›*) cos_pi_half (*‹cos (pi / (2::real)) = (0::real)›*) cos_two_pi (*‹cos ((2::real) * pi) = (1::real)›*) divide_minus_left (*‹- (?a::?'a) / (?b::?'a) = - (?a / ?b)›*) mult_of_int_commute (*‹of_int (?x::int) * (?y::?'a) = ?y * of_int ?x›*) sin_add (*‹sin ((?x::?'a) + (?y::?'a)) = sin ?x * cos ?y + cos ?x * sin ?y›*) sin_npi_int (*‹sin (pi * real_of_int (?n::int)) = (0::real)›*) sin_pi_half (*‹sin (pi / (2::real)) = (1::real)›*) sin_two_pi (*‹sin ((2::real) * pi) = (0::real)›*)) have "eventually P (at_right (tan a))" if "eventually P (filtermap tan (at_right a))" for P proof (-) (*goal: ‹eventually P (at_right (tan a))›*) obtain b1 where "b1>a" and b1_imp: " ∀y>a. y < b1 ⟶ P (tan y)" (*goal: ‹(⋀b1. ⟦a < b1; ∀y>a. y < b1 ⟶ P (tan y)⟧ ⟹ thesis) ⟹ thesis›*) by (metis Sturm_Tarski.eventually_at_right (*‹eventually ?P (at_right ?x) = (∃b>?x. ∀y>?x. y < b ⟶ ?P y)›*) ‹eventually P (filtermap tan (at_right a))› eventually_filtermap (*‹eventually ?P (filtermap ?f ?F) = (∀⇩F x in ?F. ?P (?f x))›*)) define b2 where "b2=min b1 (k*pi+pi/4+a1/2)" define b3 where "b3=b2 - k*pi" have "-pi/2 < b3" "b3<pi/2" proof (-) (*goals: 1. ‹- pi / (2::real) < (b3::real)› 2. ‹(b3::real) < pi / (2::real)›*) have "a1<b3" using ‹b1>a› (*‹(a::real) < (b1::real)›*) aa1 (*‹a = real_of_int k * pi + a1›*) ‹a1<pi/2› (*‹a1 < pi / 2›*) unfolding b2_def b3_def (*goal: ‹a1 < min b1 (real_of_int k * pi + pi / 4 + a1 / 2) - real_of_int k * pi›*) by (auto simp add:field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 77 facts*)) then show "-pi/2 < b3" using ‹-pi/2≤a1› (*‹- pi / 2 ≤ a1›*) by auto show "b3 < pi/2" using b2_def (*‹b2 = min b1 (real_of_int k * pi + pi / 4 + a1 / 2)›*) b3_def (*‹b3 = b2 - real_of_int k * pi›*) pi_a1(2) (*‹a1 < pi / 2›*) by linarith qed have "tan b2 > tan a" proof (-) (*goal: ‹tan a < tan b2›*) have "tan a = tan a1" using aa1 (*‹a = real_of_int k * pi + a1›*) by (simp add: add.commute (*‹?a + ?b = ?b + ?a›*)) also (*calculation: ‹tan a = tan a1›*) have "... < tan b3" proof (-) (*goal: ‹tan a1 < tan b3›*) have "a1<b3" using ‹b1>a› (*‹a < b1›*) aa1 (*‹a = real_of_int k * pi + a1›*) ‹a1<pi/2› (*‹a1 < pi / 2›*) unfolding b2_def b3_def (*goal: ‹a1 < min b1 (real_of_int k * pi + pi / 4 + a1 / 2) - real_of_int k * pi›*) by (auto simp add:field_simps (*‹(?a::?'a::semigroup_add) + (?b::?'a::semigroup_add) + (?c::?'a::semigroup_add) = ?a + (?b + ?c)› ‹(?a::?'a::ab_semigroup_add) + (?b::?'a::ab_semigroup_add) = ?b + ?a› ‹(?b::?'a::ab_semigroup_add) + ((?a::?'a::ab_semigroup_add) + (?c::?'a::ab_semigroup_add)) = ?a + (?b + ?c)› ‹(?a::?'a::semigroup_mult) * (?b::?'a::semigroup_mult) * (?c::?'a::semigroup_mult) = ?a * (?b * ?c)› ‹(?a::?'a::ab_semigroup_mult) * (?b::?'a::ab_semigroup_mult) = ?b * ?a› ‹(?b::?'a::ab_semigroup_mult) * ((?a::?'a::ab_semigroup_mult) * (?c::?'a::ab_semigroup_mult)) = ?a * (?b * ?c)› ‹(?a::?'a::cancel_ab_semigroup_add) - (?b::?'a::cancel_ab_semigroup_add) - (?c::?'a::cancel_ab_semigroup_add) = ?a - (?b + ?c)› ‹(?a::?'a::group_add) + ((?b::?'a::group_add) - (?c::?'a::group_add)) = ?a + ?b - ?c› ‹((?a::?'a::group_add) - (?b::?'a::group_add) = (?c::?'a::group_add)) = (?a = ?c + ?b)› ‹((?a::?'a::group_add) = (?c::?'a::group_add) - (?b::?'a::group_add)) = (?a + ?b = ?c)› ‹(?a::?'a::group_add) - ((?b::?'a::group_add) - (?c::?'a::group_add)) = ?a + ?c - ?b› ‹(?a::?'a::ab_group_add) - (?b::?'a::ab_group_add) + (?c::?'a::ab_group_add) = ?a + ?c - ?b› and more 77 facts*)) then show "?thesis" (*goal: ‹tan a1 < tan b3›*) using tan_monotone (*‹⟦- (pi / (2::real)) < (?y::real); ?y < (?x::real); ?x < pi / (2::real)⟧ ⟹ tan ?y < tan ?x›*) ‹-pi/2 < a1› (*‹- pi / (2::real) < (a1::real)›*) ‹b3 < pi/2› (*‹b3 < pi / 2›*) by simp qed also (*calculation: ‹tan a < tan b3›*) have "... = tan b2" unfolding b3_def (*goal: ‹tan (b2 - real_of_int k * pi) = tan b2›*) by (metis Groups.mult_ac( (*‹?a * ?b = ?b * ?a›*) 2) add_uminus_conv_diff (*‹?a + - ?b = ?a - ?b›*) mult_minus_right (*‹?a * - ?b = - (?a * ?b)›*) of_int_minus (*‹of_int (- ?z) = - of_int ?z›*) tan_periodic_int (*‹tan (?x + real_of_int ?i * pi) = tan ?x›*)) finally (*calculation: ‹tan (a::real) < tan (b2::real)›*) show "?thesis" (*goal: ‹tan a < tan b2›*) . qed moreover have "P y" if "y>tan a" "y < tan b2" for y proof (-) (*goal: ‹P y›*) define y1 where "y1=arctan y+ k * pi" have "a<y1" proof (-) (*goal: ‹a < y1›*) have "arctan (tan a) < arctan y" using ‹y>tan a› (*‹tan (a::real) < (y::real)›*) arctan_monotone (*‹?x < ?y ⟹ arctan ?x < arctan ?y›*) by auto then have "a1<arctan y" using arctan_tan (*‹⟦- (pi / (2::real)) < (?x::real); ?x < pi / (2::real)⟧ ⟹ arctan (tan ?x) = ?x›*) ‹-pi/2 < a1› (*‹- pi / (2::real) < (a1::real)›*) ‹a1<pi/2› (*‹a1 < pi / 2›*) unfolding aa1 (*goal: ‹a1 < arctan y›*) by (simp add: add.commute (*‹?a + ?b = ?b + ?a›*)) then show "?thesis" (*goal: ‹a < y1›*) unfolding y1_def aa1 (*goal: ‹real_of_int k * pi + a1 < arctan y + real_of_int k * pi›*) by auto qed moreover have "y1<b2" proof (-) (*goal: ‹y1 < b2›*) have "arctan y < arctan (tan b2)" using ‹y < tan b2› (*‹y < tan b2›*) arctan_monotone (*‹?x < ?y ⟹ arctan ?x < arctan ?y›*) by auto moreover have "arctan (tan b2) = b3" using arctan_tan[of b3] (*‹⟦- (pi / 2) < b3; b3 < pi / 2⟧ ⟹ arctan (tan b3) = b3›*) ‹-pi/2 < b3› (*‹- pi / 2 < b3›*) ‹b3<pi/2› (*‹b3 < pi / 2›*) unfolding b3_def (*goal: ‹arctan (tan (b2::real)) = b2 - real_of_int (k::int) * pi›*) by (metis add.inverse_inverse (*‹- (- ?a) = ?a›*) diff_minus_eq_add (*‹?a - - ?b = ?a + ?b›*) divide_minus_left (*‹- ?a / ?b = - (?a / ?b)›*) mult.commute (*‹?a * ?b = ?b * ?a›*) mult_minus_right (*‹?a * - ?b = - (?a * ?b)›*) of_int_minus (*‹of_int (- ?z) = - of_int ?z›*) tan_periodic_int (*‹tan (?x + real_of_int ?i * pi) = tan ?x›*)) ultimately have "arctan y < b3" by auto then show "?thesis" (*goal: ‹y1 < b2›*) unfolding y1_def b3_def (*goal: ‹arctan y + real_of_int k * pi < b2›*) by auto qed moreover have "∀y>a. y < b2 ⟶ P (tan y)" using b1_imp (*‹∀y>a. y < b1 ⟶ P (tan y)›*) unfolding b2_def (*goal: ‹∀y>a::real. y < min (b1::real) (real_of_int (k::int) * pi + pi / (4::real) + (a1::real) / (2::real)) ⟶ (P::real ⇒ bool) (tan y)›*) by auto moreover have "tan y1=y" unfolding y1_def (*goal: ‹tan (arctan y + real_of_int k * pi) = y›*) by (auto simp add:tan_arctan (*‹tan (arctan (?y::real)) = ?y›*)) ultimately show "?thesis" (*goal: ‹P y›*) by auto qed ultimately show "eventually P (at_right (tan a))" unfolding eventually_at_right (*goal: ‹∃b>tan a. ∀y>tan a. y < b ⟶ P y›*) by (metis eventually_at_right_field (*‹eventually (?P::?'a::{linordered_field,linorder_topology} ⇒ bool) (at_right (?x::?'a::{linordered_field,linorder_topology})) = (∃b>?x. ∀y>?x. y < b ⟶ ?P y)›*)) qed moreover have "eventually P (filtermap tan (at_right a))" if "eventually P (at_right (tan a))" for P proof (-) (*goal: ‹eventually (P::real ⇒ bool) (filtermap tan (at_right (a::real)))›*) obtain b1 where "b1>tan a" and b1_imp: "∀y>tan a. y < b1 ⟶ P y" (*goal: ‹(⋀b1. ⟦tan a < b1; ∀y>tan a. y < b1 ⟶ P y⟧ ⟹ thesis) ⟹ thesis›*) using ‹eventually P (at_right (tan a))› (*‹eventually P (at_right (tan a))›*) unfolding eventually_at_right (*goal: ‹(⋀b1::real. ⟦tan (a::real) < b1; ∀y>tan a. y < b1 ⟶ (P::real ⇒ bool) y⟧ ⟹ thesis::bool) ⟹ thesis›*) by (metis eventually_at_right_field (*‹eventually ?P (at_right ?x) = (∃b>?x. ∀y>?x. y < b ⟶ ?P y)›*)) define b2 where "b2=arctan b1 + k*pi" have "a1 < arctan b1" by (metis ‹- pi / 2 < a1› ‹a1 < pi / 2› ‹tan a < b1› aa1 (*‹a = real_of_int k * pi + a1›*) add.commute (*‹?a + ?b = ?b + ?a›*) arctan_less_iff (*‹(arctan ?x < arctan ?y) = (?x < ?y)›*) arctan_tan (*‹⟦- (pi / 2) < ?x; ?x < pi / 2⟧ ⟹ arctan (tan ?x) = ?x›*) divide_minus_left (*‹- ?a / ?b = - (?a / ?b)›*) tan_periodic_int (*‹tan (?x + real_of_int ?i * pi) = tan ?x›*)) then have "b2>a" unfolding aa1 b2_def (*goal: ‹real_of_int (k::int) * pi + (a1::real) < arctan (b1::real) + real_of_int k * pi›*) by auto moreover have "P (tan y)" if "y>a" "y < b2" for y proof (-) (*goal: ‹P (tan y)›*) define y1 where "y1 = y - k*pi" have "a1 < y1" "y1 < arctan b1" unfolding y1_def (*goals: 1. ‹a1 < y - real_of_int k * pi› 2. ‹y - real_of_int k * pi < arctan b1›*) subgoal for using ‹y>a› (*‹a < y›*) unfolding aa1 (*goal: ‹(a1::real) < (y::real) - real_of_int (k::int) * pi›*) by auto subgoal for using b2_def (*‹b2 = arctan b1 + real_of_int k * pi›*) that(2) (*‹(y::real) < (b2::real)›*) by linarith . then have "tan a1 < tan y1" "tan y1< b1" subgoal for using ‹a1>-pi/2› (*‹- pi / (2::real) < (a1::real)›*) apply (intro tan_monotone (*‹⟦- (pi / 2) < ?y; ?y < ?x; ?x < pi / 2⟧ ⟹ tan ?y < tan ?x›*), simp, simp) (*goal: ‹tan a1 < tan y1›*) using arctan_ubound (*‹arctan ?y < pi / 2›*) less_trans (*‹⟦?x < ?y; ?y < ?z⟧ ⟹ ?x < ?z›*) by blast subgoal for by (metis ‹- pi / 2 < a1› ‹a1 < y1› ‹y1 < arctan b1› arctan_less_iff (*‹(arctan ?x < arctan ?y) = (?x < ?y)›*) arctan_tan (*‹⟦- (pi / 2) < ?x; ?x < pi / 2⟧ ⟹ arctan (tan ?x) = ?x›*) arctan_ubound (*‹arctan ?y < pi / 2›*) divide_minus_left (*‹- ?a / ?b = - (?a / ?b)›*) less_trans (*‹⟦?x < ?y; ?y < ?z⟧ ⟹ ?x < ?z›*)) . have "tan y>tan a" by (metis ‹tan a1 < tan y1› aa1 (*‹(a::real) = real_of_int (k::int) * pi + (a1::real)›*) add.commute (*‹(?a::?'a) + (?b::?'a) = ?b + ?a›*) add_uminus_conv_diff (*‹(?a::?'a) + - (?b::?'a) = ?a - ?b›*) mult.commute (*‹(?a::?'a) * (?b::?'a) = ?b * ?a›*) mult_minus_right (*‹(?a::?'a) * - (?b::?'a) = - (?a * ?b)›*) of_int_minus (*‹of_int (- (?z::int)) = - of_int ?z›*) tan_periodic_int (*‹tan ((?x::real) + real_of_int (?i::int) * pi) = tan ?x›*) y1_def (*‹(y1::real) = (y::real) - real_of_int (k::int) * pi›*)) moreover have "tan y<b1" by (metis ‹tan y1 < b1› add_uminus_conv_diff (*‹?a + - ?b = ?a - ?b›*) mult.commute (*‹?a * ?b = ?b * ?a›*) mult_minus_right (*‹?a * - ?b = - (?a * ?b)›*) of_int_minus (*‹of_int (- ?z) = - of_int ?z›*) tan_periodic_int (*‹tan (?x + real_of_int ?i * pi) = tan ?x›*) y1_def (*‹y1 = y - real_of_int k * pi›*)) ultimately show "?thesis" (*goal: ‹P (tan y)›*) using b1_imp (*‹∀y>tan a. y < b1 ⟶ P y›*) by auto qed ultimately show "?thesis" (*goal: ‹eventually (P::real ⇒ bool) (filtermap tan (at_right (a::real)))›*) unfolding eventually_filtermap eventually_at_right (*goal: ‹∃b>a::real. ∀y>a. y < b ⟶ (P::real ⇒ bool) (tan y)›*) by (metis eventually_at_right_field (*‹eventually ?P (at_right ?x) = (∃b>?x. ∀y>?x. y < b ⟶ ?P y)›*)) qed ultimately show "?thesis" (*goal: ‹filtermap tan (at_right (a::real)) = at_right (tan a)›*) unfolding filter_eq_iff (*goal: ‹∀P. eventually P (filtermap tan (at_right a)) = eventually P (at_right (tan a))›*) by blast qed lemma filtermap_tan_at_left: fixes a::real assumes "cos a≠0" shows "filtermap tan (at_left a) = at_left (tan a)" proof (-) (*goal: ‹filtermap tan (at_left a) = at_left (tan a)›*) have "filtermap tan (at_right (- a)) = at_right (tan (- a))" using filtermap_tan_at_right[of "-a"] (*‹cos (- a) ≠ 0 ⟹ filtermap tan (at_right (- a)) = at_right (tan (- a))›*) assms (*‹cos (a::real) ≠ (0::real)›*) by auto then have "filtermap (uminus o tan) (at_left a) = filtermap uminus (at_left (tan a))" unfolding at_right_minus filtermap_filtermap comp_def (*goal: ‹filtermap (λx. - tan x) (at_left a) = filtermap uminus (at_left (tan a))›*) by auto then have "filtermap uminus (filtermap (uminus o tan) (at_left a)) = filtermap uminus (filtermap uminus (at_left (tan a)))" by auto then show "?thesis" (*goal: ‹filtermap tan (at_left a) = at_left (tan a)›*) unfolding filtermap_filtermap comp_def (*goal: ‹filtermap tan (at_left a) = at_left (tan a)›*) by auto qed lemma filtermap_tan_at_right_inf: fixes a::real assumes "cos a=0" shows "filtermap tan (at_right a) = at_bot" proof (-) (*goal: ‹filtermap tan (at_right a) = at_bot›*) obtain k :: int where ak: "a=k*pi + pi/2" (*goal: ‹(⋀k. a = real_of_int k * pi + pi / 2 ⟹ thesis) ⟹ thesis›*) using cos_zero_iff_int2 (*‹(cos ?x = 0) = (∃x. ?x = real_of_int x * pi + pi / 2)›*) assms (*‹cos a = 0›*) by auto have "eventually P at_bot" if "eventually P (filtermap tan (at_right a))" for P proof (-) (*goal: ‹eventually P at_bot›*) obtain b1 where "b1>a" and b1_imp: "∀y>a. y < b1 ⟶ P (tan y)" (*goal: ‹(⋀b1. ⟦a < b1; ∀y>a. y < b1 ⟶ P (tan y)⟧ ⟹ thesis) ⟹ thesis›*) using ‹eventually P (filtermap tan (at_right a))› (*‹eventually (P::real ⇒ bool) (filtermap tan (at_right (a::real)))›*) unfolding eventually_filtermap eventually_at_right (*goal: ‹(⋀b1. ⟦a < b1; ∀y>a. y < b1 ⟶ P (tan y)⟧ ⟹ thesis) ⟹ thesis›*) by (metis eventually_at_right_field (*‹eventually ?P (at_right ?x) = (∃b>?x. ∀y>?x. y < b ⟶ ?P y)›*)) define b2 where "b2=min (k*pi+pi) b1" have "P y" if "y<tan b2" for y proof (-) (*goal: ‹(P::real ⇒ bool) (y::real)›*) define y1 where "y1=(k+1)*pi+arctan y" have "a < y1" unfolding ak y1_def (*goal: ‹real_of_int k * pi + pi / 2 < real_of_int (k + 1) * pi + arctan y›*) using arctan_lbound[of y] (*‹- (pi / 2) < arctan y›*) by (auto simp add:field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 77 facts*)) moreover have "y1 < b2" proof (-) (*goal: ‹y1 < b2›*) define b3 where "b3=b2-(k+1) * pi" have "-pi/2 < b3" "b3<pi/2" using ‹b1>a› (*‹(a::real) < (b1::real)›*) unfolding b3_def b2_def ak (*goals: 1. ‹- pi / 2 < min (real_of_int k * pi + pi) b1 - real_of_int (k + 1) * pi› 2. ‹min (real_of_int k * pi + pi) b1 - real_of_int (k + 1) * pi < pi / 2›*) apply - (*goals: 1. ‹real_of_int k * pi + pi / 2 < b1 ⟹ - pi / 2 < min (real_of_int k * pi + pi) b1 - real_of_int (k + 1) * pi› 2. ‹real_of_int k * pi + pi / 2 < b1 ⟹ min (real_of_int k * pi + pi) b1 - real_of_int (k + 1) * pi < pi / 2› discuss goal 1*) apply ((auto simp add:field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 77 facts*) min_mult_distrib_left (*‹?p * min ?x ?y = (if 0 ≤ ?p then min (?p * ?x) (?p * ?y) else max (?p * ?x) (?p * ?y))›*) intro!:min.strict_coboundedI1 (*‹?a < ?c ⟹ min ?a ?b < ?c›*))[1]) (*discuss goal 2*) apply ((auto simp add:field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 77 facts*) min_mult_distrib_left (*‹?p * min ?x ?y = (if 0 ≤ ?p then min (?p * ?x) (?p * ?y) else max (?p * ?x) (?p * ?y))›*) intro!:min.strict_coboundedI1 (*‹?a < ?c ⟹ min ?a ?b < ?c›*))[1]) (*proven 2 subgoals*) . then have "arctan (tan b3) = b3" by (simp add: arctan_tan (*‹⟦- (pi / 2) < ?x; ?x < pi / 2⟧ ⟹ arctan (tan ?x) = ?x›*)) then have "arctan (tan b2) = b3" unfolding b3_def (*goal: ‹arctan (tan b2) = b2 - real_of_int (k + 1) * pi›*) by (metis diff_eq_eq (*‹((?a::?'a) - (?b::?'a) = (?c::?'a)) = (?a = ?c + ?b)›*) tan_periodic_int (*‹tan ((?x::real) + real_of_int (?i::int) * pi) = tan ?x›*)) then have "arctan y < b3" using arctan_monotone[OF ‹y<tan b2›] (*‹arctan y < arctan (tan b2)›*) by simp then show "?thesis" (*goal: ‹y1 < b2›*) unfolding y1_def b3_def (*goal: ‹real_of_int (k + 1) * pi + arctan y < b2›*) by auto qed then have "y1<b1" unfolding b2_def (*goal: ‹(y1::real) < (b1::real)›*) by auto ultimately have " P (tan y1)" using b1_imp[rule_format, of y1, simplified] (*‹⟦a < y1; y1 < b1⟧ ⟹ P (tan y1)›*) by auto then show "?thesis" (*goal: ‹P y›*) unfolding y1_def (*goal: ‹(P::real ⇒ bool) (y::real)›*) by (metis add.commute (*‹?a + ?b = ?b + ?a›*) arctan (*‹- (pi / 2) < arctan ?y ∧ arctan ?y < pi / 2 ∧ tan (arctan ?y) = ?y›*) tan_periodic_int (*‹tan (?x + real_of_int ?i * pi) = tan ?x›*)) qed then show "?thesis" (*goal: ‹eventually (P::real ⇒ bool) at_bot›*) unfolding eventually_at_bot_dense (*goal: ‹∃N. ∀n<N. P n›*) by auto qed moreover have "eventually P (filtermap tan (at_right a))" if "eventually P at_bot" for P proof (-) (*goal: ‹eventually P (filtermap tan (at_right a))›*) obtain b1 where b1_imp: "∀n<b1. P n" (*goal: ‹(⋀b1. ∀n<b1. P n ⟹ thesis) ⟹ thesis›*) using ‹eventually P at_bot› (*‹eventually P at_bot›*) unfolding eventually_at_bot_dense (*goal: ‹(⋀b1. ∀n<b1. P n ⟹ thesis) ⟹ thesis›*) by auto define b2 where "b2=arctan b1 + (k+1)*pi" have "b2>a" unfolding ak b2_def (*goal: ‹real_of_int k * pi + pi / 2 < arctan b1 + real_of_int (k + 1) * pi›*) using arctan_lbound[of b1] (*‹- (pi / 2) < arctan b1›*) by (auto simp add:algebra_simps (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)› ‹(?a::?'a) * (?b::?'a) * (?c::?'a) = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)› ‹(?a::?'a) - (?b::?'a) - (?c::?'a) = ?a - (?b + ?c)› ‹(?a::?'a) + ((?b::?'a) - (?c::?'a)) = ?a + ?b - ?c› ‹((?a::?'a) - (?b::?'a) = (?c::?'a)) = (?a = ?c + ?b)› ‹((?a::?'a) = (?c::?'a) - (?b::?'a)) = (?a + ?b = ?c)› ‹(?a::?'a) - ((?b::?'a) - (?c::?'a)) = ?a + ?c - ?b› ‹(?a::?'a) - (?b::?'a) + (?c::?'a) = ?a + ?c - ?b› and more 34 facts*)) moreover have "P (tan y)" if "a < y" " y < b2 " for y proof (-) (*goal: ‹P (tan y)›*) define y1 where "y1=y-(k+1)*pi" have "tan y1 < tan (arctan b1)" apply (rule tan_monotone (*‹⟦- (pi / (2::real)) < (?y::real); ?y < (?x::real); ?x < pi / (2::real)⟧ ⟹ tan ?y < tan ?x›*)) (*goal: ‹tan (y1::real) < tan (arctan (b1::real))›*) subgoal for using ‹a<y› (*‹a < y›*) unfolding y1_def ak (*goal: ‹- (pi / (2::real)) < (y::real) - real_of_int ((k::int) + (1::int)) * pi›*) by (auto simp add:algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 34 facts*)) subgoal for using ‹y < b2› (*‹y < b2›*) unfolding y1_def b2_def (*goal: ‹y - real_of_int (k + 1) * pi < arctan b1›*) by (auto simp add:algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 34 facts*)) subgoal for using arctan_ubound (*‹arctan (?y::real) < pi / (2::real)›*) by auto . then have "tan y1<b1" by (simp add: arctan (*‹- (pi / (2::real)) < arctan (?y::real) ∧ arctan ?y < pi / (2::real) ∧ tan (arctan ?y) = ?y›*)) then have "tan y < b1" unfolding y1_def (*goal: ‹tan y < b1›*) by (metis diff_eq_eq (*‹((?a::?'a::group_add) - (?b::?'a::group_add) = (?c::?'a::group_add)) = (?a = ?c + ?b)›*) tan_periodic_int (*‹tan ((?x::real) + real_of_int (?i::int) * pi) = tan ?x›*)) then show "?thesis" (*goal: ‹(P::real ⇒ bool) (tan (y::real))›*) using b1_imp (*‹∀n<b1::real. (P::real ⇒ bool) n›*) by auto qed ultimately show "eventually P (filtermap tan (at_right a))" unfolding eventually_filtermap eventually_at_right (*goal: ‹∃b>a. ∀y>a. y < b ⟶ P (tan y)›*) by (metis eventually_at_right_field (*‹eventually ?P (at_right ?x) = (∃b>?x. ∀y>?x. y < b ⟶ ?P y)›*)) qed ultimately show "?thesis" (*goal: ‹filtermap tan (at_right a) = at_bot›*) unfolding filter_eq_iff (*goal: ‹∀P. eventually P (filtermap tan (at_right a)) = eventually P at_bot›*) by auto qed lemma filtermap_tan_at_left_inf: fixes a::real assumes "cos a=0" shows "filtermap tan (at_left a) = at_top" proof (-) (*goal: ‹filtermap tan (at_left a) = at_top›*) have "filtermap tan (at_right (- a)) = at_bot" using filtermap_tan_at_right_inf[of "-a"] (*‹cos (- a) = 0 ⟹ filtermap tan (at_right (- a)) = at_bot›*) assms (*‹cos a = 0›*) by auto then have "filtermap (uminus o tan) (at_left a) = at_bot" unfolding at_right_minus filtermap_filtermap comp_def (*goal: ‹filtermap (λx. - tan x) (at_left a) = at_bot›*) by auto then have "filtermap uminus (filtermap (uminus o tan) (at_left a)) = filtermap uminus at_bot" by auto then show "?thesis" (*goal: ‹filtermap tan (at_left a) = at_top›*) unfolding filtermap_filtermap comp_def (*goal: ‹filtermap tan (at_left a) = at_top›*) using at_top_mirror[where 'a = real] (*‹at_top = filtermap uminus at_bot›*) by auto qed subsection ‹Periodic set› (*Devised to characterize roots of Trigonometric equations, which are usually uniformly discrete.*) definition periodic_set:: "real set ⇒ real ⇒ bool" where "periodic_set S δ ⟷ (∃B. finite B ∧ (∀x∈S. ∃b∈B. ∃k::int. x =b + k * δ ))" lemma periodic_set_multiple: assumes "k≠0" shows "periodic_set S δ ⟷ periodic_set S (of_int k*δ)" proof (standard) (*goals: 1. ‹periodic_set (S::real set) (δ::real) ⟹ periodic_set S (real_of_int (k::int) * δ)› 2. ‹periodic_set (S::real set) (real_of_int (k::int) * (δ::real)) ⟹ periodic_set S δ›*) assume asm: "periodic_set S δ " (*‹periodic_set (S::real set) (δ::real)›*) then obtain B1 where "finite B1" and B1_def: "∀x∈S. ∃b∈B1. (∃k::int. x = b + k * δ)" (*goal: ‹(⋀B1. ⟦finite B1; ∀x∈S. ∃b∈B1. ∃xa. x = b + real_of_int xa * δ⟧ ⟹ thesis) ⟹ thesis›*) unfolding periodic_set_def (*goal: ‹(⋀B1::real set. ⟦finite B1; ∀x::real∈S::real set. ∃b::real∈B1. ∃xa::int. x = b + real_of_int xa * (δ::real)⟧ ⟹ thesis::bool) ⟹ thesis›*) by metis define B where "B = B1 ∪ {b+i*δ | b i. b∈B1 ∧ i∈{0..<¦k¦}}" have "∃b∈B. ∃k'. x = b + real_of_int k' * (real_of_int k * δ)" if "x∈S" for x proof (-) (*goal: ‹∃b∈B. ∃k'. x = b + real_of_int k' * (real_of_int k * δ)›*) obtain b1 and k1 :: int where "b1∈B1" and "x_δ": "x = b1 + k1 * δ" (*goal: ‹(⋀(b1::real) k1::int. ⟦b1 ∈ (B1::real set); (x::real) = b1 + real_of_int k1 * (δ::real)⟧ ⟹ thesis::bool) ⟹ thesis›*) using B1_def[rule_format, OF ‹x∈S›] (*‹∃b∈B1. ∃xa. x = b + real_of_int xa * δ›*) by auto define r and d where "r= k1 mod ¦k¦" and "d = k1 div ¦k¦" define b and kk where "b=b1+r*δ" and "kk = (if k>0 then d else -d)" have "x = b1 + (r+¦k¦*d)*δ" using "x_δ" (*‹x = b1 + real_of_int k1 * δ›*) unfolding r_def d_def (*goal: ‹x = b1 + real_of_int (k1 mod ¦k¦ + ¦k¦ * (k1 div ¦k¦)) * δ›*) by auto then have "x = b + kk*(k*δ)" unfolding b_def kk_def (*goal: ‹x = b1 + real_of_int r * δ + real_of_int (if 0 < k then d else - d) * (real_of_int k * δ)›*) using ‹k≠0› (*‹k ≠ 0›*) by (auto simp add:algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 34 facts*)) moreover have "b∈B" proof (-) (*goal: ‹b ∈ B›*) have "r ∈ {0..<¦k¦}" unfolding r_def (*goal: ‹k1 mod ¦k¦ ∈ {0..<¦k¦}›*) by (simp add: ‹k≠0›) then show "?thesis" (*goal: ‹b ∈ B›*) unfolding b_def B_def (*goal: ‹b1 + real_of_int r * δ ∈ B1 ∪ {b + real_of_int i * δ |b i. b ∈ B1 ∧ i ∈ {0..<¦k¦}}›*) using ‹b1∈B1› (*‹b1 ∈ B1›*) by blast qed ultimately show "?thesis" (*goal: ‹∃b∈B. ∃k'. x = b + real_of_int k' * (real_of_int k * δ)›*) by auto qed moreover have "finite B" unfolding B_def (*goal: ‹finite (B1 ∪ {b + real_of_int i * δ |b i. b ∈ B1 ∧ i ∈ {0..<¦k¦}})›*) using ‹finite B1› (*‹finite B1›*) by (simp add: finite_image_set2 (*‹⟦finite {x::?'a. (?P::?'a ⇒ bool) x}; finite {y::?'b. (?Q::?'b ⇒ bool) y}⟧ ⟹ finite {(?f::?'a ⇒ ?'b ⇒ ?'c) x y |(x::?'a) y::?'b. ?P x ∧ ?Q y}›*)) ultimately show "periodic_set S (real_of_int k * δ)" unfolding periodic_set_def (*goal: ‹∃B. finite B ∧ (∀x∈S. ∃b∈B. ∃xa. x = b + real_of_int xa * (real_of_int k * δ))›*) by auto next (*goal: ‹periodic_set S (real_of_int k * δ) ⟹ periodic_set S δ›*) assume "periodic_set S (real_of_int k * δ)" (*‹periodic_set (S::real set) (real_of_int (k::int) * (δ::real))›*) then show "periodic_set S δ" unfolding periodic_set_def (*goal: ‹∃B. finite B ∧ (∀x∈S. ∃b∈B. ∃xa. x = b + real_of_int xa * δ)›*) by (metis mult.commute (*‹?a * ?b = ?b * ?a›*) mult.left_commute (*‹?b * (?a * ?c) = ?a * (?b * ?c)›*) of_int_mult (*‹of_int (?w * ?z) = of_int ?w * of_int ?z›*)) qed lemma periodic_set_empty[simp]: "periodic_set {} δ" unfolding periodic_set_def (*goal: ‹∃B. finite B ∧ (∀x∈{}. ∃b∈B. ∃xa. x = b + real_of_int xa * δ)›*) by auto lemma periodic_set_finite: assumes "finite S" shows "periodic_set S δ" unfolding periodic_set_def (*goal: ‹∃B. finite B ∧ (∀x∈S. ∃b∈B. ∃xa. x = b + real_of_int xa * δ)›*) using assms (*‹finite S›*) mult.commute (*‹?a * ?b = ?b * ?a›*) by force lemma periodic_set_subset[elim]: assumes "periodic_set S δ" "T ⊆ S" shows "periodic_set T δ" using assms (*‹periodic_set S δ› ‹T ⊆ S›*) unfolding periodic_set_def (*goal: ‹∃B. finite B ∧ (∀x∈T. ∃b∈B. ∃xa. x = b + real_of_int xa * δ)›*) by (meson subsetCE (*‹⟦?A ⊆ ?B; ?c ∉ ?A ⟹ ?P; ?c ∈ ?B ⟹ ?P⟧ ⟹ ?P›*)) lemma periodic_set_union: assumes "periodic_set S δ" "periodic_set T δ" shows "periodic_set (S ∪ T) δ" using assms (*‹periodic_set (S::real set) (δ::real)› ‹periodic_set (T::real set) (δ::real)›*) unfolding periodic_set_def (*goal: ‹∃B. finite B ∧ (∀x∈S ∪ T. ∃b∈B. ∃xa. x = b + real_of_int xa * δ)›*) by (metis Un_iff (*‹(?c ∈ ?A ∪ ?B) = (?c ∈ ?A ∨ ?c ∈ ?B)›*) infinite_Un (*‹infinite (?S ∪ ?T) = (infinite ?S ∨ infinite ?T)›*)) lemma periodic_imp_uniform_discrete: assumes "periodic_set S δ" shows "uniform_discrete S" proof (-) (*goal: ‹uniform_discrete (S::real set)›*) have "?thesis" if "S≠{}" "δ≠0" proof (-) (*goal: ‹uniform_discrete S›*) obtain B and g where "finite B" and g_def: "∀x∈S. g x∈B ∧ (∃k::int. x = g x + k * δ)" (*goal: ‹(⋀B g. ⟦finite B; ∀x∈S. g x ∈ B ∧ (∃xa. x = g x + real_of_int xa * δ)⟧ ⟹ thesis) ⟹ thesis›*) using assms (*‹periodic_set S δ›*) unfolding periodic_set_def (*goal: ‹(⋀(B::real set) g::real ⇒ real. ⟦finite B; ∀x::real∈S::real set. g x ∈ B ∧ (∃xa::int. x = g x + real_of_int xa * (δ::real))⟧ ⟹ thesis::bool) ⟹ thesis›*) by metis define P where "P = ((*) δ) ` Ints" define B_diff where "B_diff = {¦x-y¦ | x y. x∈B ∧ y∈B} - P" have "finite B_diff" unfolding B_diff_def (*goal: ‹finite ({¦x - y¦ |x y. x ∈ B ∧ y ∈ B} - P)›*) using ‹finite B› (*‹finite (B::real set)›*) by (simp add: finite_image_set2 (*‹⟦finite {x. ?P x}; finite {y. ?Q y}⟧ ⟹ finite {?f x y |x y. ?P x ∧ ?Q y}›*)) define e where "e = (if setdist B_diff P = 0 then ¦δ¦ else min (setdist B_diff P) (¦δ¦))" have "e>0" unfolding e_def (*goal: ‹(0::real) < (if setdist (B_diff::real set) (P::real set) = (0::real) then ¦δ::real¦ else min (setdist B_diff P) ¦δ¦)›*) using setdist_pos_le[unfolded order_class.le_less] (*‹0 < setdist ?s ?t ∨ 0 = setdist ?s ?t›*) ‹δ≠0› (*‹(δ::real) ≠ (0::real)›*) by auto moreover have "x=y" if "x∈S" "y∈S" "dist x y<e" for x and y proof (-) (*goal: ‹x = y›*) obtain k1 :: int where k1: "x = g x + k1 * δ" and "g x∈B" (*goal: ‹(⋀k1::int. ⟦(x::real) = (g::real ⇒ real) x + real_of_int k1 * (δ::real); g x ∈ (B::real set)⟧ ⟹ thesis::bool) ⟹ thesis›*) using g_def (*‹∀x∈S. g x ∈ B ∧ (∃xa. x = g x + real_of_int xa * δ)›*) ‹x∈S› (*‹x ∈ S›*) by auto obtain k2 :: int where k2: "y = g y + k2 * δ" and "g y∈B" (*goal: ‹(⋀k2::int. ⟦(y::real) = (g::real ⇒ real) y + real_of_int k2 * (δ::real); g y ∈ (B::real set)⟧ ⟹ thesis::bool) ⟹ thesis›*) using g_def (*‹∀x∈S. g x ∈ B ∧ (∃xa. x = g x + real_of_int xa * δ)›*) ‹y∈S› (*‹y ∈ S›*) by auto have "?thesis" if "¦g x - g y¦ ∈ P" proof (-) (*goal: ‹x = y›*) obtain k :: int where k: "g x - g y = k * δ" (*goal: ‹(⋀k::int. (g::real ⇒ real) (x::real) - g (y::real) = real_of_int k * (δ::real) ⟹ thesis::bool) ⟹ thesis›*) proof (-) (*goal: ‹(⋀k. g x - g y = real_of_int k * δ ⟹ thesis) ⟹ thesis›*) obtain k' where "k'∈Ints" and "*": "¦g x - g y¦ = δ * k'" (*goal: ‹(⋀k'. ⟦k' ∈ ℤ; ¦g x - g y¦ = δ * k'⟧ ⟹ thesis) ⟹ thesis›*) using ‹¦g x - g y¦ ∈ P› (*‹¦g x - g y¦ ∈ P›*) unfolding P_def image_iff (*goal: ‹(⋀k'. ⟦k' ∈ ℤ; ¦g x - g y¦ = δ * k'⟧ ⟹ thesis) ⟹ thesis›*) by auto then obtain k where "**": "k' = of_int k" (*goal: ‹(⋀k. k' = real_of_int k ⟹ thesis) ⟹ thesis›*) using Ints_cases (*‹⟦?q ∈ ℤ; ⋀z. ?q = of_int z ⟹ ?thesis⟧ ⟹ ?thesis›*) by auto show "?thesis" (*goal: ‹thesis›*) apply (cases "g x - g y ≥ 0") (*goal: ‹thesis›*) subgoal for using that[of k] (*‹g x - g y = real_of_int k * δ ⟹ thesis›*) "*" (*‹¦g x - g y¦ = δ * k'›*) "**" (*‹k' = real_of_int k›*) by simp subgoal for using that[of "-k"] (*‹g x - g y = real_of_int (- k) * δ ⟹ thesis›*) "*" (*‹¦g x - g y¦ = δ * k'›*) "**" (*‹k' = real_of_int k›*) by (auto simp add:algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 34 facts*)) . qed have "dist x y = ¦(g x - g y)+(k1-k2)*δ¦" unfolding dist_real_def (*goal: ‹¦x - y¦ = ¦g x - g y + real_of_int (k1 - k2) * 䦛*) apply (subst k1 (*‹x = g x + real_of_int k1 * δ›*)) (*goal: ‹¦x - y¦ = ¦g x - g y + real_of_int (k1 - k2) * 䦛*) apply (subst k2 (*‹y = g y + real_of_int k2 * δ›*)) (*goal: ‹¦(g::real ⇒ real) (x::real) + real_of_int (k1::int) * (δ::real) - (y::real)¦ = ¦g x - g y + real_of_int (k1 - (k2::int)) * 䦛*) by (simp add:algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 34 facts*)) also (*calculation: ‹dist x y = ¦g x - g y + real_of_int (k1 - k2) * 䦛*) have "... = ¦(k+k1-k2)*δ¦" apply (subst k (*‹g x - g y = real_of_int k * δ›*)) (*goal: ‹¦g x - g y + real_of_int (k1 - k2) * δ¦ = ¦real_of_int (k + k1 - k2) * 䦛*) by (simp add:algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 34 facts*)) also (*calculation: ‹dist x y = ¦real_of_int (k + k1 - k2) * 䦛*) have "... = ¦k+k1-k2¦*¦δ¦" by (simp add: abs_mult (*‹¦(?a::?'a) * (?b::?'a)¦ = ¦?a¦ * ¦?b¦›*)) finally (*calculation: ‹dist (x::real) (y::real) = real_of_int ¦(k::int) + (k1::int) - (k2::int)¦ * ¦δ::real¦›*) have "*": "dist x y = ¦k+k1-k2¦*¦δ¦" . then have "¦k+k1-k2¦*¦δ¦ < e" using ‹dist x y<e› (*‹dist (x::real) (y::real) < (e::real)›*) by auto then have "¦k+k1-k2¦*¦δ¦ < ¦δ¦" by (simp add: e_def (*‹e = (if setdist B_diff P = 0 then ¦δ¦ else min (setdist B_diff P) ¦δ¦)›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) then have "¦k+k1-k2¦ = 0" unfolding e_def (*goal: ‹¦k + k1 - k2¦ = 0›*) using ‹δ≠0› (*‹δ ≠ 0›*) by force then have "dist x y=0" using "*" (*‹dist x y = real_of_int ¦k + k1 - k2¦ * ¦δ¦›*) by auto then show "?thesis" (*goal: ‹x = y›*) by auto qed moreover have "?thesis" if "¦g x - g y¦ ∉ P" proof (-) (*goal: ‹x = y›*) have "¦g x - g y¦ ∈ B_diff" unfolding B_diff_def (*goal: ‹¦g x - g y¦ ∈ {¦x - y¦ |x y. x ∈ B ∧ y ∈ B} - P›*) using ‹g x∈B› (*‹g x ∈ B›*) ‹g y∈B› (*‹g y ∈ B›*) that (*‹¦g x - g y¦ ∉ P›*) by auto have "e ≤ ¦¦g x - g y¦ - ¦(k1-k2)*䦦" proof (-) (*goal: ‹e ≤ ¦¦g x - g y¦ - ¦real_of_int (k1 - k2) * 䦦›*) have "¦g x - g y¦ ∈ B_diff" unfolding B_diff_def (*goal: ‹¦g x - g y¦ ∈ {¦x - y¦ |x y. x ∈ B ∧ y ∈ B} - P›*) using ‹g x∈B› (*‹(g::real ⇒ real) (x::real) ∈ (B::real set)›*) ‹g y∈B› (*‹g y ∈ B›*) that (*‹¦g x - g y¦ ∉ P›*) by auto moreover have "¦(k1-k2)*δ¦ ∈ P" unfolding P_def (*goal: ‹¦real_of_int (k1 - k2) * δ¦ ∈ (*) δ ` ℤ›*) apply (intro rev_image_eqI[of "(if δ≥0 then ¦of_int(k1-k2)¦ else - ¦of_int(k1-k2)¦)"] (*‹⟦(if 0 ≤ δ then ¦of_int (k1 - k2)¦ else - ¦of_int (k1 - k2)¦) ∈ ?A; ?b = ?f (if 0 ≤ δ then ¦of_int (k1 - k2)¦ else - ¦of_int (k1 - k2)¦)⟧ ⟹ ?b ∈ ?f ` ?A›*)) (*goals: 1. ‹(if 0 ≤ δ then ¦real_of_int (k1 - k2)¦ else - ¦real_of_int (k1 - k2)¦) ∈ ℤ› 2. ‹¦real_of_int (k1 - k2) * δ¦ = δ * (if 0 ≤ δ then ¦real_of_int (k1 - k2)¦ else - ¦real_of_int (k1 - k2)¦)› discuss goal 1*) apply (metis Ints_minus (*‹?a ∈ ℤ ⟹ - ?a ∈ ℤ›*) Ints_of_int (*‹of_int ?z ∈ ℤ›*) of_int_abs (*‹of_int ¦?x¦ = ¦of_int ?x¦›*)) (*discuss goal 2*) apply (auto simp add:abs_mult (*‹¦?a * ?b¦ = ¦?a¦ * ¦?b¦›*)) (*proven 2 subgoals*) . ultimately have "¦¦g x - g y¦ - ¦(k1-k2)*䦦 ≥ setdist B_diff P" using setdist_le_dist[of _ B_diff _ P] (*‹⟦?x ∈ B_diff; ?y ∈ P⟧ ⟹ setdist B_diff P ≤ dist ?x ?y›*) dist_real_def (*‹dist ?x ?y = ¦?x - ?y¦›*) by auto moreover have "setdist B_diff P ≠ 0" proof (-) (*goal: ‹setdist B_diff P ≠ 0›*) have "compact B_diff " using ‹finite B_diff› (*‹finite (B_diff::real set)›*) using finite_imp_compact (*‹finite ?S ⟹ compact ?S›*) by blast moreover have "closed P" unfolding P_def (*goal: ‹closed ((*) δ ` ℤ)›*) using closed_scaling[OF closed_Ints [ where 'a = real ], of δ] (*‹closed ((*⇩R) (δ::real) ` ℤ)›*) by auto moreover have "P ≠ {}" using Ints_0 (*‹0 ∈ ℤ›*) unfolding P_def (*goal: ‹(*) (δ::real) ` ℤ ≠ {}›*) by blast moreover have "B_diff ∩ P = {}" unfolding B_diff_def (*goal: ‹({¦x - y¦ |x y. x ∈ B ∧ y ∈ B} - P) ∩ P = {}›*) by auto moreover have "B_diff ≠{}" unfolding B_diff_def (*goal: ‹{¦x - y¦ |x y. x ∈ B ∧ y ∈ B} - P ≠ {}›*) using ‹g x∈B› (*‹(g::real ⇒ real) (x::real) ∈ (B::real set)›*) ‹g y∈B› (*‹g y ∈ B›*) that (*‹¦g x - g y¦ ∉ P›*) by auto ultimately show "?thesis" (*goal: ‹setdist B_diff P ≠ 0›*) using setdist_eq_0_compact_closed[of B_diff P] (*‹⟦compact B_diff; closed P⟧ ⟹ (setdist B_diff P = 0) = (B_diff = {} ∨ P = {} ∨ B_diff ∩ P ≠ {})›*) by auto qed ultimately show "?thesis" (*goal: ‹e ≤ ¦¦g x - g y¦ - ¦real_of_int (k1 - k2) * 䦦›*) unfolding e_def (*goal: ‹(if setdist B_diff P = 0 then ¦δ¦ else min (setdist B_diff P) ¦δ¦) ≤ ¦¦g x - g y¦ - ¦real_of_int (k1 - k2) * 䦦›*) by argo qed also (*calculation: ‹e ≤ ¦¦g x - g y¦ - ¦real_of_int (k1 - k2) * 䦦›*) have "... ≤ ¦(g x - g y) + (k1-k2)*δ¦" proof (-) (*goal: ‹¦¦g x - g y¦ - ¦real_of_int (k1 - k2) * 䦦 ≤ ¦g x - g y + real_of_int (k1 - k2) * 䦛*) define t1 where "t1=g x - g y" define t2 where "t2 = of_int (k1 - k2) * δ" show "?thesis" (*goal: ‹¦¦g x - g y¦ - ¦real_of_int (k1 - k2) * 䦦 ≤ ¦g x - g y + real_of_int (k1 - k2) * 䦛*) apply (fold t1_def t2_def) (*goal: ‹¦¦g x - g y¦ - ¦real_of_int (k1 - k2) * 䦦 ≤ ¦g x - g y + real_of_int (k1 - k2) * 䦛*) by linarith qed also (*calculation: ‹e ≤ ¦g x - g y + real_of_int (k1 - k2) * 䦛*) have "... = dist x y" unfolding dist_real_def (*goal: ‹¦(g::real ⇒ real) (x::real) - g (y::real) + real_of_int ((k1::int) - (k2::int)) * (δ::real)¦ = ¦x - y¦›*) apply (subst (2) k1 (*‹(x::real) = (g::real ⇒ real) x + real_of_int (k1::int) * (δ::real)›*)) (*goal: ‹¦(g::real ⇒ real) (x::real) - g (y::real) + real_of_int ((k1::int) - (k2::int)) * (δ::real)¦ = ¦x - y¦›*) apply (subst (2) k2 (*‹(y::real) = (g::real ⇒ real) y + real_of_int (k2::int) * (δ::real)›*)) (*goal: ‹¦g x - g y + real_of_int (k1 - k2) * δ¦ = ¦g x + real_of_int k1 * δ - y¦›*) by (simp add:algebra_simps (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)› ‹(?a::?'a) * (?b::?'a) * (?c::?'a) = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)› ‹(?a::?'a) - (?b::?'a) - (?c::?'a) = ?a - (?b + ?c)› ‹(?a::?'a) + ((?b::?'a) - (?c::?'a)) = ?a + ?b - ?c› ‹((?a::?'a) - (?b::?'a) = (?c::?'a)) = (?a = ?c + ?b)› ‹((?a::?'a) = (?c::?'a) - (?b::?'a)) = (?a + ?b = ?c)› ‹(?a::?'a) - ((?b::?'a) - (?c::?'a)) = ?a + ?c - ?b› ‹(?a::?'a) - (?b::?'a) + (?c::?'a) = ?a + ?c - ?b› and more 34 facts*)) finally (*calculation: ‹(e::real) ≤ dist (x::real) (y::real)›*) have "dist x y≥e" . then have False using ‹dist x y<e› (*‹dist x y < e›*) by auto then show "?thesis" (*goal: ‹x = y›*) by auto qed ultimately show "?thesis" (*goal: ‹x = y›*) by auto qed ultimately show "?thesis" (*goal: ‹uniform_discrete S›*) unfolding uniform_discrete_def (*goal: ‹∃e>0. ∀x∈S. ∀y∈S. dist x y < e ⟶ x = y›*) by auto qed moreover have "?thesis" if "S={}" using that (*‹S = {}›*) by auto moreover have "?thesis" if "δ=0" proof (-) (*goal: ‹uniform_discrete S›*) obtain B and g where "finite B" and g_def: "∀x∈S. g x∈B ∧ (∃k::int. x = g x + k * δ)" (*goal: ‹(⋀(B::real set) g::real ⇒ real. ⟦finite B; ∀x::real∈S::real set. g x ∈ B ∧ (∃xa::int. x = g x + real_of_int xa * (δ::real))⟧ ⟹ thesis::bool) ⟹ thesis›*) using assms (*‹periodic_set (S::real set) (δ::real)›*) unfolding periodic_set_def (*goal: ‹(⋀B g. ⟦finite B; ∀x∈S. g x ∈ B ∧ (∃xa. x = g x + real_of_int xa * δ)⟧ ⟹ thesis) ⟹ thesis›*) by metis then have "∀x∈S. g x∈B ∧ (x = g x)" using that (*‹δ = 0›*) by fastforce then have "S ⊆ g ` B" by auto then have "finite S" using ‹finite B› (*‹finite B›*) by (auto elim:finite_subset (*‹⟦?A ⊆ ?B; finite ?B⟧ ⟹ finite ?A›*)) then show "?thesis" (*goal: ‹uniform_discrete S›*) using uniform_discrete_finite_iff (*‹(uniform_discrete (?S::?'a set) ∧ bounded ?S) = finite ?S›*) by blast qed ultimately show "?thesis" (*goal: ‹uniform_discrete S›*) by blast qed lemma periodic_set_tan_linear: assumes "a≠0" "c≠0" shows "periodic_set (roots (λx. a*tan (x/c) + b)) (c*pi)" proof (-) (*goal: ‹periodic_set (roots (λx::real. (a::real) * tan (x / (c::real)) + (b::real))) (c * pi)›*) define B where "B = { c*arctan (- b / a), c*pi/2}" have "∃b∈B. ∃k::int. x = b + k * (c*pi)" if "x∈roots (λx. a * tan (x/c) + b)" for x proof (-) (*goal: ‹∃b∈B. ∃xa. x = b + real_of_int xa * (c * pi)›*) define C1 where "C1 = (∃k::int. x = c*arctan (- b / a) + k * (c*pi))" define C2 where "C2 = (∃k::int. x = c*pi / 2 + k * (c*pi) ∧ - b / a = 0)" have "tan (x/c) = - b/a" using that (*‹x ∈ roots (λx. a * tan (x / c) + b)›*) ‹a≠0› (*‹a ≠ 0›*) unfolding roots_within_def (*goal: ‹tan (x / c) = - b / a›*) by (auto simp add:field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 77 facts*)) then have "C1 ∨ C2" unfolding C1_def C2_def (*goal: ‹(∃xa. x = c * arctan (- b / a) + real_of_int xa * (c * pi)) ∨ (∃xa. x = c * pi / 2 + real_of_int xa * (c * pi) ∧ - b / a = 0)›*) using tan_eq_arctan_Ex[of "x/c" "-b/a"] (*‹(tan (x / c) = - b / a) = (∃xa. x / c = arctan (- b / a) + real_of_int xa * pi ∨ x / c = pi / 2 + real_of_int xa * pi ∧ - b / a = 0)›*) ‹c≠0› (*‹c ≠ 0›*) by (auto simp add:field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 77 facts*)) moreover have "?thesis" if C1 using that (*‹C1›*) unfolding C1_def B_def (*goal: ‹∃b::real∈{(c::real) * arctan (- (b::real) / (a::real)), c * pi / (2::real)}. ∃xa::int. (x::real) = b + real_of_int xa * (c * pi)›*) by blast moreover have "?thesis" if C2 using that (*‹C2›*) unfolding C2_def B_def (*goal: ‹∃b∈{c * arctan (- b / a), c * pi / 2}. ∃xa. x = b + real_of_int xa * (c * pi)›*) by blast ultimately show "?thesis" (*goal: ‹∃b∈B. ∃xa. x = b + real_of_int xa * (c * pi)›*) by auto qed moreover have "finite B" unfolding B_def (*goal: ‹finite {(c::real) * arctan (- (b::real) / (a::real)), c * pi / (2::real)}›*) by auto ultimately show "?thesis" (*goal: ‹periodic_set (roots (λx. a * tan (x / c) + b)) (c * pi)›*) unfolding periodic_set_def (*goal: ‹∃B. finite B ∧ (∀x∈roots (λx. a * tan (x / c) + b). ∃b∈B. ∃xa. x = b + real_of_int xa * (c * pi))›*) by auto qed lemma periodic_set_cos_linear: assumes "a≠0" "c≠0" shows "periodic_set (roots (λx. a*cos (x/c) + b)) (2*c*pi)" proof (-) (*goal: ‹periodic_set (roots (λx::real. (a::real) * cos (x / (c::real)) + (b::real))) ((2::real) * c * pi)›*) define B where "B = { c*arccos (- b / a), - c*arccos (- b / a)}" have "∃b∈B. ∃k::int. x = b + k * (2*c*pi)" if "x∈roots (λx. a * cos (x/c) + b)" for x proof (-) (*goal: ‹∃b::real∈B::real set. ∃xa::int. (x::real) = b + real_of_int xa * ((2::real) * (c::real) * pi)›*) define C1 where "C1 = (∃k::int. x = c*arccos (- b / a) + k * (2*c*pi))" define C2 where "C2 = (∃k::int. x = - c*arccos (- b / a) + k * (2*c*pi))" have "cos (x/c) = - b/a" using that (*‹x ∈ roots (λx. a * cos (x / c) + b)›*) ‹a≠0› (*‹a ≠ 0›*) unfolding roots_within_def (*goal: ‹cos (x / c) = - b / a›*) by (auto simp add:field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 77 facts*)) then have "C1 ∨ C2" unfolding cos_eq_arccos_Ex ex_disj_distrib C1_def C2_def (*goal: ‹(∃xa. x = c * arccos (- b / a) + real_of_int xa * (2 * c * pi)) ∨ (∃xa. x = - c * arccos (- b / a) + real_of_int xa * (2 * c * pi))›*) using ‹c≠0› (*‹c ≠ 0›*) apply (auto simp add:divide_simps (*‹inverse ?a = 1 / ?a› ‹?a + ?b / ?z = (if ?z = 0 then ?a else (?a * ?z + ?b) / ?z)› ‹?a / ?z + ?b = (if ?z = 0 then ?b else (?a + ?b * ?z) / ?z)› ‹- (?a / ?z) + ?b = (if ?z = 0 then ?b else (- ?a + ?b * ?z) / ?z)› ‹?a - ?b / ?z = (if ?z = 0 then ?a else (?a * ?z - ?b) / ?z)› ‹?a / ?z - ?b = (if ?z = 0 then - ?b else (?a - ?b * ?z) / ?z)› ‹- (?a / ?z) - ?b = (if ?z = 0 then - ?b else (- ?a - ?b * ?z) / ?z)› ‹(?b / ?c = ?a) = (if ?c ≠ 0 then ?b = ?a * ?c else ?a = 0)› ‹(?a = ?b / ?c) = (if ?c ≠ 0 then ?a * ?c = ?b else ?a = 0)› ‹(- (?b / ?c) = ?a) = (if ?c ≠ 0 then - ?b = ?a * ?c else ?a = 0)› ‹(?a = - (?b / ?c)) = (if ?c ≠ 0 then ?a * ?c = - ?b else ?a = 0)› ‹(?a ≤ ?b / ?c) = (if 0 < ?c then ?a * ?c ≤ ?b else if ?c < 0 then ?b ≤ ?a * ?c else ?a ≤ 0)› and more 13 facts*)) (*goals: 1. ‹⋀xa. ⟦c ≠ 0; if 0 < a then - 1 * a ≤ - b else if a < 0 then - b ≤ - 1 * a else - 1 ≤ 0; if 0 < a then - 1 * a ≤ b else if a < 0 then b ≤ - 1 * a else - 1 ≤ 0; ∀x. (arccos (- (b / a)) + 2 * real_of_int xa * pi) * c ≠ real_of_int x * (2 * c * pi) - c * arccos (- (b / a)); x = (arccos (- (b / a)) + 2 * real_of_int xa * pi) * c⟧ ⟹ ∃x. (arccos (- (b / a)) + 2 * real_of_int xa * pi) * c = c * arccos (- (b / a)) + real_of_int x * (2 * c * pi)› 2. ‹⋀xa. ⟦c ≠ 0; if 0 < a then - 1 * a ≤ - b else if a < 0 then - b ≤ - 1 * a else - 1 ≤ 0; if 0 < a then - 1 * a ≤ b else if a < 0 then b ≤ - 1 * a else - 1 ≤ 0; ∀x. (2 * real_of_int xa * pi - arccos (- (b / a))) * c ≠ real_of_int x * (2 * c * pi) - c * arccos (- (b / a)); x = (2 * real_of_int xa * pi - arccos (- (b / a))) * c⟧ ⟹ ∃x. (2 * real_of_int xa * pi - arccos (- (b / a))) * c = c * arccos (- (b / a)) + real_of_int x * (2 * c * pi)› discuss goal 1*) apply ((auto simp add:algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 34 facts*))[1]) (*discuss goal 2*) apply ((auto simp add:algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 34 facts*))[1]) (*proven 2 subgoals*) . moreover have "?thesis" if C1 using that (*‹C1›*) unfolding C1_def B_def (*goal: ‹∃b∈{c * arccos (- b / a), - c * arccos (- b / a)}. ∃xa. x = b + real_of_int xa * (2 * c * pi)›*) by blast moreover have "?thesis" if C2 using that (*‹C2›*) unfolding C2_def B_def (*goal: ‹∃b∈{c * arccos (- b / a), - c * arccos (- b / a)}. ∃xa. x = b + real_of_int xa * (2 * c * pi)›*) by blast ultimately show "?thesis" (*goal: ‹∃b∈B. ∃xa. x = b + real_of_int xa * (2 * c * pi)›*) by auto qed moreover have "finite B" unfolding B_def (*goal: ‹finite {(c::real) * arccos (- (b::real) / (a::real)), - c * arccos (- b / a)}›*) by auto ultimately show "?thesis" (*goal: ‹periodic_set (roots (λx. a * cos (x / c) + b)) (2 * c * pi)›*) unfolding periodic_set_def (*goal: ‹∃B. finite B ∧ (∀x∈roots (λx. a * cos (x / c) + b). ∃b∈B. ∃xa. x = b + real_of_int xa * (2 * c * pi))›*) by auto qed lemma periodic_set_tan_poly: assumes "p≠0" "c≠0" shows "periodic_set (roots (λx. poly p (tan (x/c)))) (c*pi)" using assms (*‹p ≠ 0› ‹c ≠ 0›*) proof (induct rule:poly_root_induct_alt (*‹⟦?Q 0; ⋀p. (⋀a. poly p a ≠ 0) ⟹ ?Q p; ⋀a p. ?Q p ⟹ ?Q ([:- a, 1:] * p)⟧ ⟹ ?Q ?p›*)) (*goals: 1. ‹⟦0 ≠ 0; c ≠ 0⟧ ⟹ periodic_set (roots (λx. poly 0 (tan (x / c)))) (c * pi)› 2. ‹⋀p. ⟦⋀a. poly p a ≠ 0; p ≠ 0; c ≠ 0⟧ ⟹ periodic_set (roots (λx. poly p (tan (x / c)))) (c * pi)› 3. ‹⋀a p. ⟦⟦p ≠ 0; c ≠ 0⟧ ⟹ periodic_set (roots (λx. poly p (tan (x / c)))) (c * pi); [:- a, 1:] * p ≠ 0; c ≠ 0⟧ ⟹ periodic_set (roots (λx. poly ([:- a, 1:] * p) (tan (x / c)))) (c * pi)›*) case 0 (*‹0 ≠ 0› ‹(c::real) ≠ (0::real)›*) then show "?case" (*goal: ‹periodic_set (roots (λx. poly 0 (tan (x / c)))) (c * pi)›*) by simp next (*goals: 1. ‹⋀p. ⟦⋀a. poly p a ≠ 0; p ≠ 0; c ≠ 0⟧ ⟹ periodic_set (roots (λx. poly p (tan (x / c)))) (c * pi)› 2. ‹⋀a p. ⟦⟦p ≠ 0; c ≠ 0⟧ ⟹ periodic_set (roots (λx. poly p (tan (x / c)))) (c * pi); [:- a, 1:] * p ≠ 0; c ≠ 0⟧ ⟹ periodic_set (roots (λx. poly ([:- a, 1:] * p) (tan (x / c)))) (c * pi)›*) case (no_proots p) (*‹poly p ?a ≠ 0› ‹p ≠ 0› ‹c ≠ 0›*) then show "?case" (*goal: ‹periodic_set (roots (λx::real. poly (p::real poly) (tan (x / (c::real))))) (c * pi)›*) unfolding roots_within_def (*goal: ‹periodic_set {x ∈ UNIV. poly p (tan (x / c)) = 0} (c * pi)›*) by simp next (*goal: ‹⋀(a::real) p::real poly. ⟦⟦p ≠ (0::real poly); (c::real) ≠ (0::real)⟧ ⟹ periodic_set (roots (λx::real. poly p (tan (x / c)))) (c * pi); [:- a, 1::real:] * p ≠ (0::real poly); c ≠ (0::real)⟧ ⟹ periodic_set (roots (λx::real. poly ([:- a, 1::real:] * p) (tan (x / c)))) (c * pi)›*) case (root a p) (*‹⟦p ≠ 0; c ≠ 0⟧ ⟹ periodic_set (roots (λx. poly p (tan (x / c)))) (c * pi)› ‹[:- (a::real), 1::real:] * (p::real poly) ≠ (0::real poly)› ‹c ≠ 0›*) have "roots (λx. poly ([:- a, 1:] * p) (tan (x/c))) = roots (λx. tan (x/c) - a) ∪ roots (λx. poly p (tan (x/c)))" unfolding roots_within_def (*goal: ‹{x ∈ UNIV. poly ([:- a, 1:] * p) (tan (x / c)) = 0} = {x ∈ UNIV. tan (x / c) - a = 0} ∪ {x ∈ UNIV. poly p (tan (x / c)) = 0}›*) by auto moreover have "periodic_set (roots (λx. tan (x/c) - a)) (c*pi)" using periodic_set_tan_linear[OF _ ‹c≠0›, of 1 "-a", simplified] (*‹periodic_set (roots (λx. tan (x / c) - a)) (c * pi)›*) . moreover have "periodic_set (roots (λx. poly p (tan (x/c)))) (c*pi)" using root (*‹⟦p ≠ 0; c ≠ 0⟧ ⟹ periodic_set (roots (λx. poly p (tan (x / c)))) (c * pi)› ‹[:- (a::real), 1::real:] * (p::real poly) ≠ (0::real poly)› ‹c ≠ 0›*) by fastforce ultimately show "?case" (*goal: ‹periodic_set (roots (λx. poly ([:- a, 1:] * p) (tan (x / c)))) (c * pi)›*) using periodic_set_union (*‹⟦periodic_set ?S ?δ; periodic_set ?T ?δ⟧ ⟹ periodic_set (?S ∪ ?T) ?δ›*) by simp qed lemma periodic_set_sin_cos_linear: fixes a b c ::real assumes "a≠0 ∨ b≠0 ∨ c≠0" shows "periodic_set (roots (λx. a * cos x + b * sin x + c)) (4*pi)" proof (-) (*goal: ‹periodic_set (roots (λx. a * cos x + b * sin x + c)) (4 * pi)›*) define f where "f x= a * cos x + b * sin x + c" for x have "roots f = (roots f ∩ {x. cos (x/2) = 0}) ∪ (roots f ∩ {x. cos (x/2) ≠ 0})" by auto moreover have "periodic_set (roots f ∩ {x. cos (x/2) = 0}) (4*pi)" proof (-) (*goal: ‹periodic_set (roots f ∩ {x. cos (x / 2) = 0}) (4 * pi)›*) have "periodic_set ({x. cos (x/2) = 0}) (4*pi)" using periodic_set_cos_linear[of 1 2 0, unfolded roots_within_def, simplified] (*‹periodic_set {x::real. cos (x / (2::real)) = (0::real)} ((4::real) * pi)›*) by simp then show "?thesis" (*goal: ‹periodic_set (roots f ∩ {x. cos (x / 2) = 0}) (4 * pi)›*) by auto qed moreover have "periodic_set (roots f ∩ {x. cos (x/2) ≠ 0}) (4*pi)" proof (-) (*goal: ‹periodic_set (roots f ∩ {x. cos (x / 2) ≠ 0}) (4 * pi)›*) define p where "p=[:a+c,2*b,c-a:]" have "poly p (tan (x/2)) = 0 ⟷ f x=0" if "cos (x/2) ≠0" for x proof (-) (*goal: ‹(poly (p::real poly) (tan ((x::real) / (2::real))) = (0::real)) = ((f::real ⇒ real) x = (0::real))›*) define t where "t=tan (x/2)" define tt where "tt = 1+t^2" have "cos x = (1-t^2) / tt" unfolding tt_def t_def (*goal: ‹cos (x::real) = ((1::real) - (tan (x / (2::real)))²) / ((1::real) + (tan (x / (2::real)))²)›*) using cos_tan_half[OF that, simplified] (*‹cos x = (1 - (tan (x / 2))²) / (1 + (tan (x / 2))²)›*) by simp moreover have "sin x = 2*t / tt" unfolding tt_def t_def (*goal: ‹sin (x::real) = (2::real) * tan (x / (2::real)) / ((1::real) + (tan (x / (2::real)))²)›*) using sin_tan_half[of "x/2", simplified] (*‹sin x = 2 * tan (x / 2) / (1 + (tan (x / 2))²)›*) by simp moreover have "tt≠0" unfolding tt_def (*goal: ‹1 + t² ≠ 0›*) by (metis power_one (*‹1 ^ ?n = 1›*) sum_power2_eq_zero_iff (*‹(?x² + ?y² = 0) = (?x = 0 ∧ ?y = 0)›*) zero_neq_one (*‹0 ≠ 1›*)) ultimately show "?thesis" (*goal: ‹(poly p (tan (x / 2)) = 0) = (f x = 0)›*) unfolding f_def p_def (*goal: ‹(poly [:a + c, 2 * b, c - a:] (tan (x / 2)) = 0) = (a * cos x + b * sin x + c = 0)›*) apply (fold t_def) (*goal: ‹(poly [:a + c, 2 * b, c - a:] (tan (x / 2)) = 0) = (a * cos x + b * sin x + c = 0)›*) apply simp (*goal: ‹⟦cos x = (1 - t²) / tt; sin x = 2 * t / tt; tt ≠ 0⟧ ⟹ (poly [:a + c, 2 * b, c - a:] t = 0) = (a * cos x + b * sin x + c = 0)›*) apply (auto simp add:field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 77 facts*)) (*goals: 1. ‹⟦(tt::real) * cos (x::real) + (t::real)² = (1::real); tt * sin x = t * (2::real); tt ≠ (0::real); (a::real) + ((c::real) + (c * (t * t) + (b::real) * (t * (2::real)))) = a * (t * t)⟧ ⟹ a + (c * tt + b * (t * (2::real))) = a * t²› 2. ‹⟦(tt::real) * cos (x::real) + (t::real)² = (1::real); tt * sin x = t * (2::real); tt ≠ (0::real); (a::real) + ((c::real) * tt + (b::real) * (t * (2::real))) = a * t²⟧ ⟹ a + (c + (c * (t * t) + b * (t * (2::real)))) = a * (t * t)› discuss goal 1*) apply ((auto simp add:algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 34 facts*) tt_def (*‹tt = 1 + t²›*) power2_eq_square (*‹?a² = ?a * ?a›*))[1]) (*discuss goal 2*) apply ((auto simp add:algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 34 facts*) tt_def (*‹tt = 1 + t²›*) power2_eq_square (*‹?a² = ?a * ?a›*))[1]) (*proven 2 subgoals*) . qed then have "roots f ∩ {x. cos (x/2) ≠ 0} = roots (λx. poly p (tan (x/2))) ∩ {x. cos (x/2) ≠ 0}" unfolding roots_within_def (*goal: ‹{x::real ∈ UNIV. (f::real ⇒ real) x = (0::real)} ∩ {x::real. cos (x / (2::real)) ≠ (0::real)} = {x::real ∈ UNIV. poly (p::real poly) (tan (x / (2::real))) = (0::real)} ∩ {x::real. cos (x / (2::real)) ≠ (0::real)}›*) by auto moreover have "periodic_set (roots (λx. poly p (tan (x/2))) ∩ {x. cos (x/2) ≠ 0}) (4*pi)" proof (-) (*goal: ‹periodic_set (roots (λx::real. poly (p::real poly) (tan (x / (2::real)))) ∩ {x::real. cos (x / (2::real)) ≠ (0::real)}) ((4::real) * pi)›*) have "p≠0" unfolding p_def (*goal: ‹[:a + c, 2 * b, c - a:] ≠ 0›*) using assms (*‹a ≠ 0 ∨ b ≠ 0 ∨ c ≠ 0›*) by auto then have "periodic_set (roots (λx. poly p (tan (x/2)))) (4*pi)" using periodic_set_tan_poly[of p 2, simplified] (*‹(p::real poly) ≠ (0::real poly) ⟹ periodic_set (roots (λx::real. poly p (tan (x / (2::real))))) ((2::real) * pi)›*) periodic_set_multiple[of 2 _ "2*pi", simplified] (*‹periodic_set (?S::real set) ((2::real) * pi) = periodic_set ?S ((4::real) * pi)›*) by auto then show "?thesis" (*goal: ‹periodic_set (roots (λx::real. poly (p::real poly) (tan (x / (2::real)))) ∩ {x::real. cos (x / (2::real)) ≠ (0::real)}) ((4::real) * pi)›*) by auto qed ultimately show "?thesis" (*goal: ‹periodic_set (roots f ∩ {x. cos (x / 2) ≠ 0}) (4 * pi)›*) by auto qed ultimately show "periodic_set (roots f) (4*pi)" using periodic_set_union (*‹⟦periodic_set (?S::real set) (?δ::real); periodic_set (?T::real set) ?δ⟧ ⟹ periodic_set (?S ∪ ?T) ?δ›*) by metis qed end
{ "path": "afp-2025-02-12/thys/Winding_Number_Eval/Missing_Transcendental.thy", "repo": "afp-2025-02-12", "sha": "03a3b318e4baf946c69c7152beaab5776b8756a042f6e84d32ba0c93e40988ce" }
(* Title: HOL/UNITY/Simple/Network.thy Author: Lawrence C Paulson, Cambridge University Computer Laboratory Copyright 1998 University of Cambridge The Communication Network. From Misra, "A Logic for Concurrent Programming" (1994), section 5.7. *) theory Network imports "../UNITY" begin (*The state assigns a number to each process variable*) datatype pvar = Sent | Rcvd | Idle datatype pname = Aproc | Bproc type_synonym state = "pname * pvar => nat" locale F_props = fixes F assumes rsA: "F ∈ stable {s. s(Bproc,Rcvd) ≤ s(Aproc,Sent)}" and rsB: "F ∈ stable {s. s(Aproc,Rcvd) ≤ s(Bproc,Sent)}" and sent_nondec: "F ∈ stable {s. m ≤ s(proc,Sent)}" and rcvd_nondec: "F ∈ stable {s. n ≤ s(proc,Rcvd)}" and rcvd_idle: "F ∈ {s. s(proc,Idle) = Suc 0 & s(proc,Rcvd) = m} co {s. s(proc,Rcvd) = m --> s(proc,Idle) = Suc 0}" and sent_idle: "F ∈ {s. s(proc,Idle) = Suc 0 & s(proc,Sent) = n} co {s. s(proc,Sent) = n}" begin lemmas sent_nondec_A = sent_nondec [of _ Aproc] and sent_nondec_B = sent_nondec [of _ Bproc] and rcvd_nondec_A = rcvd_nondec [of _ Aproc] and rcvd_nondec_B = rcvd_nondec [of _ Bproc] and rcvd_idle_A = rcvd_idle [of Aproc] and rcvd_idle_B = rcvd_idle [of Bproc] and sent_idle_A = sent_idle [of Aproc] and sent_idle_B = sent_idle [of Bproc] and rs_AB = stable_Int [OF rsA rsB] lemmas sent_nondec_AB = stable_Int [OF sent_nondec_A sent_nondec_B] and rcvd_nondec_AB = stable_Int [OF rcvd_nondec_A rcvd_nondec_B] and rcvd_idle_AB = constrains_Int [OF rcvd_idle_A rcvd_idle_B] and sent_idle_AB = constrains_Int [OF sent_idle_A sent_idle_B] lemmas nondec_AB = stable_Int [OF sent_nondec_AB rcvd_nondec_AB] and idle_AB = constrains_Int [OF rcvd_idle_AB sent_idle_AB] lemmas nondec_idle = constrains_Int [OF nondec_AB [unfolded stable_def] idle_AB] lemma shows "F ∈ stable {s. s(Aproc,Idle) = Suc 0 & s(Bproc,Idle) = Suc 0 & s(Aproc,Sent) = s(Bproc,Rcvd) & s(Bproc,Sent) = s(Aproc,Rcvd) & s(Aproc,Rcvd) = m & s(Bproc,Rcvd) = n}" apply (unfold stable_def (*‹UNITY.stable ?A ≡ ?A co ?A›*)) (*goal: ‹F ∈ UNITY.stable {s. s (Aproc, Idle) = Suc 0 ∧ s (Bproc, Idle) = Suc 0 ∧ s (Aproc, Sent) = s (Bproc, Rcvd) ∧ s (Bproc, Sent) = s (Aproc, Rcvd) ∧ s (Aproc, Rcvd) = m ∧ s (Bproc, Rcvd) = n}›*) apply (rule constrainsI (*‹(⋀act s s'. ⟦act ∈ Acts ?F; (s, s') ∈ act; s ∈ ?A⟧ ⟹ s' ∈ ?A') ⟹ ?F ∈ ?A co ?A'›*)) (*goal: ‹F ∈ {s. s (Aproc, Idle) = Suc 0 ∧ s (Bproc, Idle) = Suc 0 ∧ s (Aproc, Sent) = s (Bproc, Rcvd) ∧ s (Bproc, Sent) = s (Aproc, Rcvd) ∧ s (Aproc, Rcvd) = m ∧ s (Bproc, Rcvd) = n} co {s. s (Aproc, Idle) = Suc 0 ∧ s (Bproc, Idle) = Suc 0 ∧ s (Aproc, Sent) = s (Bproc, Rcvd) ∧ s (Bproc, Sent) = s (Aproc, Rcvd) ∧ s (Aproc, Rcvd) = m ∧ s (Bproc, Rcvd) = n}›*) apply (drule constrains_Int [OF rs_AB [unfolded stable_def] nondec_idle, THEN constrainsD] (*‹⟦(?act::((pname × pvar ⇒ nat) × (pname × pvar ⇒ nat)) set) ∈ Acts (F::(pname × pvar ⇒ nat) program); (?s::pname × pvar ⇒ nat, ?s'::pname × pvar ⇒ nat) ∈ ?act; ?s ∈ {s::pname × pvar ⇒ nat. s (Bproc, Rcvd) ≤ s (Aproc, Sent)} ∩ {s::pname × pvar ⇒ nat. s (Aproc, Rcvd) ≤ s (Bproc, Sent)} ∩ ({s::pname × pvar ⇒ nat. (?maa2::nat) ≤ s (Aproc, Sent)} ∩ {s::pname × pvar ⇒ nat. (?mb2::nat) ≤ s (Bproc, Sent)} ∩ ({s::pname × pvar ⇒ nat. (?naa2::nat) ≤ s (Aproc, Rcvd)} ∩ {s::pname × pvar ⇒ nat. (?nb2::nat) ≤ s (Bproc, Rcvd)}) ∩ ({s::pname × pvar ⇒ nat. s (Aproc, Idle) = Suc (0::nat) ∧ s (Aproc, Rcvd) = (?ma2::nat)} ∩ {s::pname × pvar ⇒ nat. s (Bproc, Idle) = Suc (0::nat) ∧ s (Bproc, Rcvd) = (?m2::nat)} ∩ ({s::pname × pvar ⇒ nat. s (Aproc, Idle) = Suc (0::nat) ∧ s (Aproc, Sent) = (?na2::nat)} ∩ {s::pname × pvar ⇒ nat. s (Bproc, Idle) = Suc (0::nat) ∧ s (Bproc, Sent) = (?n2::nat)})))⟧ ⟹ ?s' ∈ {s::pname × pvar ⇒ nat. s (Bproc, Rcvd) ≤ s (Aproc, Sent)} ∩ {s::pname × pvar ⇒ nat. s (Aproc, Rcvd) ≤ s (Bproc, Sent)} ∩ ({s::pname × pvar ⇒ nat. ?maa2 ≤ s (Aproc, Sent)} ∩ {s::pname × pvar ⇒ nat. ?mb2 ≤ s (Bproc, Sent)} ∩ ({s::pname × pvar ⇒ nat. ?naa2 ≤ s (Aproc, Rcvd)} ∩ {s::pname × pvar ⇒ nat. ?nb2 ≤ s (Bproc, Rcvd)}) ∩ ({s::pname × pvar ⇒ nat. s (Aproc, Rcvd) = ?ma2 ⟶ s (Aproc, Idle) = Suc (0::nat)} ∩ {s::pname × pvar ⇒ nat. s (Bproc, Rcvd) = ?m2 ⟶ s (Bproc, Idle) = Suc (0::nat)} ∩ ({s::pname × pvar ⇒ nat. s (Aproc, Sent) = ?na2} ∩ {s::pname × pvar ⇒ nat. s (Bproc, Sent) = ?n2})))›*), assumption) (*goal: ‹⋀(act::((pname × pvar ⇒ nat) × (pname × pvar ⇒ nat)) set) (s::pname × pvar ⇒ nat) s'::pname × pvar ⇒ nat. ⟦act ∈ Acts (F::(pname × pvar ⇒ nat) program); (s, s') ∈ act; s ∈ {s::pname × pvar ⇒ nat. s (Aproc, Idle) = Suc (0::nat) ∧ s (Bproc, Idle) = Suc (0::nat) ∧ s (Aproc, Sent) = s (Bproc, Rcvd) ∧ s (Bproc, Sent) = s (Aproc, Rcvd) ∧ s (Aproc, Rcvd) = (m::nat) ∧ s (Bproc, Rcvd) = (n::nat)}⟧ ⟹ s' ∈ {s::pname × pvar ⇒ nat. s (Aproc, Idle) = Suc (0::nat) ∧ s (Bproc, Idle) = Suc (0::nat) ∧ s (Aproc, Sent) = s (Bproc, Rcvd) ∧ s (Bproc, Sent) = s (Aproc, Rcvd) ∧ s (Aproc, Rcvd) = m ∧ s (Bproc, Rcvd) = n}›*) apply simp_all (*top goal: ‹⋀act s s'. ⟦(s, s') ∈ act; s ∈ {s. s (Aproc, Idle) = Suc 0 ∧ s (Bproc, Idle) = Suc 0 ∧ s (Aproc, Sent) = s (Bproc, Rcvd) ∧ s (Bproc, Sent) = s (Aproc, Rcvd) ∧ s (Aproc, Rcvd) = m ∧ s (Bproc, Rcvd) = n}⟧ ⟹ s ∈ {s. s (Bproc, Rcvd) ≤ s (Aproc, Sent)} ∩ {s. s (Aproc, Rcvd) ≤ s (Bproc, Sent)} ∩ ({sa. ?maa2 act s s' ≤ sa (Aproc, Sent)} ∩ {sa. ?mb2 act s s' ≤ sa (Bproc, Sent)} ∩ ({sa. ?naa2 act s s' ≤ sa (Aproc, Rcvd)} ∩ {sa. ?nb2 act s s' ≤ sa (Bproc, Rcvd)}) ∩ ({sa. sa (Aproc, Idle) = Suc 0 ∧ sa (Aproc, Rcvd) = ?ma2 act s s'} ∩ {sa. sa (Bproc, Idle) = Suc 0 ∧ sa (Bproc, Rcvd) = ?m2 act s s'} ∩ ({sa. sa (Aproc, Idle) = Suc 0 ∧ sa (Aproc, Sent) = ?na2 act s s'} ∩ {sa. sa (Bproc, Idle) = Suc 0 ∧ sa (Bproc, Sent) = ?n2 act s s'})))› and 1 goal remains*) apply (blast del: le0 (*‹0 ≤ ?n›*), clarify) (*top goal: ‹⋀act s s'. ⟦(s, s') ∈ act; s (Aproc, Idle) = Suc 0 ∧ s (Bproc, Idle) = Suc 0 ∧ s (Aproc, Sent) = s (Bproc, Rcvd) ∧ s (Bproc, Sent) = s (Aproc, Rcvd) ∧ s (Aproc, Rcvd) = m ∧ s (Bproc, Rcvd) = n⟧ ⟹ ?maa2 act s s' ≤ n ∧ ?mb2 act s s' ≤ m ∧ ?naa2 act s s' ≤ m ∧ ?nb2 act s s' ≤ n ∧ m = ?ma2 act s s' ∧ n = ?m2 act s s' ∧ n = ?na2 act s s' ∧ m = ?n2 act s s'› and 1 goal remains*) apply (subgoal_tac "s' (Aproc, Rcvd) = s (Aproc, Rcvd)") (*goal: ‹⋀act s s'. ⟦(s, s') ∈ act; s (Aproc, Idle) = Suc 0; s' (Bproc, Rcvd) ≤ s' (Aproc, Sent); s (Bproc, Idle) = Suc 0; s' (Aproc, Rcvd) ≤ s' (Bproc, Sent); s (Aproc, Sent) = s (Bproc, Rcvd); s (Bproc, Rcvd) ≤ s' (Aproc, Sent); s (Bproc, Sent) = s (Aproc, Rcvd); s (Aproc, Rcvd) ≤ s' (Bproc, Sent); m = s (Aproc, Rcvd); n = s (Bproc, Rcvd); s (Aproc, Rcvd) ≤ s' (Aproc, Rcvd); s (Bproc, Rcvd) ≤ s' (Bproc, Rcvd); s' (Aproc, Rcvd) = s (Aproc, Rcvd) ⟶ s' (Aproc, Idle) = Suc 0; s' (Bproc, Rcvd) = s (Bproc, Rcvd) ⟶ s' (Bproc, Idle) = Suc 0; s' (Aproc, Sent) = s (Bproc, Rcvd); s' (Bproc, Sent) = s (Aproc, Rcvd)⟧ ⟹ s' (Aproc, Idle) = Suc 0 ∧ s' (Bproc, Idle) = Suc 0 ∧ s' (Aproc, Sent) = s' (Bproc, Rcvd) ∧ s' (Bproc, Sent) = s' (Aproc, Rcvd) ∧ s' (Aproc, Rcvd) = s (Aproc, Rcvd) ∧ s' (Bproc, Rcvd) = s (Bproc, Rcvd)›*) apply (subgoal_tac "s' (Bproc, Rcvd) = s (Bproc, Rcvd)") (*top goal: ‹⋀act s s'. ⟦(s, s') ∈ act; s (Aproc, Idle) = Suc 0; s' (Bproc, Rcvd) ≤ s' (Aproc, Sent); s (Bproc, Idle) = Suc 0; s' (Aproc, Rcvd) ≤ s' (Bproc, Sent); s (Aproc, Sent) = s (Bproc, Rcvd); s (Bproc, Rcvd) ≤ s' (Aproc, Sent); s (Bproc, Sent) = s (Aproc, Rcvd); s (Aproc, Rcvd) ≤ s' (Bproc, Sent); m = s (Aproc, Rcvd); n = s (Bproc, Rcvd); s (Aproc, Rcvd) ≤ s' (Aproc, Rcvd); s (Bproc, Rcvd) ≤ s' (Bproc, Rcvd); s' (Aproc, Rcvd) = s (Aproc, Rcvd) ⟶ s' (Aproc, Idle) = Suc 0; s' (Bproc, Rcvd) = s (Bproc, Rcvd) ⟶ s' (Bproc, Idle) = Suc 0; s' (Aproc, Sent) = s (Bproc, Rcvd); s' (Bproc, Sent) = s (Aproc, Rcvd); s' (Aproc, Rcvd) = s (Aproc, Rcvd)⟧ ⟹ s' (Aproc, Idle) = Suc 0 ∧ s' (Bproc, Idle) = Suc 0 ∧ s' (Aproc, Sent) = s' (Bproc, Rcvd) ∧ s' (Bproc, Sent) = s' (Aproc, Rcvd) ∧ s' (Aproc, Rcvd) = s (Aproc, Rcvd) ∧ s' (Bproc, Rcvd) = s (Bproc, Rcvd)› and 1 goal remains*) apply simp (*top goal: ‹⋀(act::((pname × pvar ⇒ nat) × (pname × pvar ⇒ nat)) set) (s::pname × pvar ⇒ nat) s'::pname × pvar ⇒ nat. ⟦(s, s') ∈ act; s (Aproc, Idle) = Suc (0::nat); s' (Bproc, Rcvd) ≤ s' (Aproc, Sent); s (Bproc, Idle) = Suc (0::nat); s' (Aproc, Rcvd) ≤ s' (Bproc, Sent); s (Aproc, Sent) = s (Bproc, Rcvd); s (Bproc, Rcvd) ≤ s' (Aproc, Sent); s (Bproc, Sent) = s (Aproc, Rcvd); s (Aproc, Rcvd) ≤ s' (Bproc, Sent); (m::nat) = s (Aproc, Rcvd); (n::nat) = s (Bproc, Rcvd); s (Aproc, Rcvd) ≤ s' (Aproc, Rcvd); s (Bproc, Rcvd) ≤ s' (Bproc, Rcvd); s' (Aproc, Rcvd) = s (Aproc, Rcvd) ⟶ s' (Aproc, Idle) = Suc (0::nat); s' (Bproc, Rcvd) = s (Bproc, Rcvd) ⟶ s' (Bproc, Idle) = Suc (0::nat); s' (Aproc, Sent) = s (Bproc, Rcvd); s' (Bproc, Sent) = s (Aproc, Rcvd); s' (Aproc, Rcvd) = s (Aproc, Rcvd); s' (Bproc, Rcvd) = s (Bproc, Rcvd)⟧ ⟹ s' (Aproc, Idle) = Suc (0::nat) ∧ s' (Bproc, Idle) = Suc (0::nat) ∧ s' (Aproc, Sent) = s' (Bproc, Rcvd) ∧ s' (Bproc, Sent) = s' (Aproc, Rcvd) ∧ s' (Aproc, Rcvd) = s (Aproc, Rcvd) ∧ s' (Bproc, Rcvd) = s (Bproc, Rcvd)› and 2 goals remain*) by ((blast intro: order_antisym (*‹⟦?x ≤ ?y; ?y ≤ ?x⟧ ⟹ ?x = ?y›*) le_trans (*‹⟦?i ≤ ?j; ?j ≤ ?k⟧ ⟹ ?i ≤ ?k›*) eq_imp_le (*‹?m = ?n ⟹ ?m ≤ ?n›*))+) end end
{ "path": "Isabelle2024/src/HOL/UNITY/Simple/Network.thy", "repo": "Isabelle2024", "sha": "3291aa1187c119983d1a1b83fc143d69ea5e722e0b4afc0ff7cc192d9f77ad9d" }
(* Title: Examples/TTS_Foundations/Orders/Type_Simple_Orders.thy Author: Mihails Milehins Copyright 2021 (C) Mihails Milehins *) section‹Abstract orders on types› theory Type_Simple_Orders imports "../Foundations/FNDS_Definite_Description" FNDS_Auxiliary begin subsection‹Background› text‹ The results presented in this section were ported (with amendments and additions) from the theories \<^text>‹Orderings› and \<^text>‹Set_Interval› in the main library of Isabelle/HOL. › subsection‹Order operations› text‹Abstract order operations.› locale ord = fixes le ls :: "['a, 'a] ⇒ bool" locale ord_syntax = ord le ls for le ls :: "['a, 'a] ⇒ bool" begin notation le ("'(≤⇩a')") and le (infix "≤⇩a" 50) and ls ("'(<⇩a')") and ls (infix "<⇩a" 50) abbreviation (input) ge (infix "≥⇩a" 50) where "x ≥⇩a y ≡ y ≤⇩a x" abbreviation (input) gt (infix ">⇩a" 50) where "x >⇩a y ≡ y <⇩a x" notation ge ("'(≥⇩a')") and ge (infix "≥⇩a" 50) and gt ("'(>⇩a')") and gt (infix ">⇩a" 50) end locale ord_dual = ord le ls for le ls :: "['a, 'a] ⇒ bool" begin interpretation ord_syntax . sublocale dual: ord ge gt . end text‹Pairs.› locale ord_pair = ord⇩a: ord le⇩a ls⇩a + ord⇩b: ord le⇩b ls⇩b for le⇩a ls⇩a :: "['a, 'a] ⇒ bool" and le⇩b ls⇩b :: "['b, 'b] ⇒ bool" begin sublocale rev: ord_pair le⇩b ls⇩b le⇩a ls⇩a . end locale ord_pair_syntax = ord_pair le⇩a ls⇩a le⇩b ls⇩b for le⇩a ls⇩a :: "['a, 'a] ⇒ bool" and le⇩b ls⇩b :: "['b, 'b] ⇒ bool" begin sublocale ord⇩a: ord_syntax le⇩a ls⇩a + ord⇩b: ord_syntax le⇩b ls⇩b . notation le⇩a (‹'(≤⇩a')›) and le⇩a (infix ‹≤⇩a› 50) and ls⇩a (‹'(<⇩a')›) and ls⇩a (infix ‹<⇩a› 50) and le⇩b (‹'(≤⇩b')›) and le⇩b (infix ‹≤⇩b› 50) and ls⇩b (‹'(<⇩b')›) and ls⇩b (infix ‹<⇩b› 50) notation ord⇩a.ge (‹'(≥⇩a')›) and ord⇩a.ge (infix ‹≥⇩a› 50) and ord⇩a.gt (‹'(>⇩a')›) and ord⇩a.gt (infix ‹>⇩a› 50) and ord⇩b.ge (‹'(≥⇩b')›) and ord⇩b.ge (infix ‹≥⇩b› 50) and ord⇩b.gt (‹'(>⇩b')›) and ord⇩b.gt (infix ‹>⇩b› 50) end locale ord_pair_dual = ord_pair le⇩a ls⇩a le⇩b ls⇩b for le⇩a ls⇩a :: "['a, 'a] ⇒ bool" and le⇩b ls⇩b :: "['b, 'b] ⇒ bool" begin interpretation ord_pair_syntax . sublocale ord_dual: ord_pair ‹(≤⇩a)› ‹(<⇩a)› ‹(≥⇩b)› ‹(>⇩b)› . sublocale dual_ord: ord_pair ‹(≥⇩a)› ‹(>⇩a)› ‹(≤⇩b)› ‹(<⇩b)› . sublocale dual_dual: ord_pair ‹(≥⇩a)› ‹(>⇩a)› ‹(≥⇩b)› ‹(>⇩b)› . end subsection‹Preorders› subsubsection‹Definitions› text‹Abstract preorders.› locale preorder = ord le ls for le ls :: "['a, 'a] ⇒ bool" + assumes less_le_not_le: "ls x y ⟷ le x y ∧ ¬ (le y x)" and order_refl[iff]: "le x x" and order_trans: "le x y ⟹ le y z ⟹ le x z" locale preorder_dual = preorder le ls for le ls :: "['a, 'a] ⇒ bool" begin interpretation ord_syntax . sublocale ord_dual . sublocale dual: preorder ge gt apply standard (*goals: 1. ‹⋀x y. (y <⇩a x) = (y ≤⇩a x ∧ ¬ x ≤⇩a y)› 2. ‹⋀x. x ≤⇩a x› 3. ‹⋀x y z. ⟦y ≤⇩a x; z ≤⇩a y⟧ ⟹ z ≤⇩a x› discuss goal 1*) apply ((auto simp: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*) intro: order_trans (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?z⟧ ⟹ ?x ≤⇩a ?z›*))[1]) (*discuss goal 2*) apply ((auto simp: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*) intro: order_trans (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?z⟧ ⟹ ?x ≤⇩a ?z›*))[1]) (*discuss goal 3*) apply ((auto simp: less_le_not_le (*‹((?x::'a::type) <⇩a (?y::'a::type)) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*) intro: order_trans (*‹⟦(?x::'a::type) ≤⇩a (?y::'a::type); ?y ≤⇩a (?z::'a::type)⟧ ⟹ ?x ≤⇩a ?z›*))[1]) (*proven 3 subgoals*) . end text‹Pairs.› locale ord_preorder = ord_pair le⇩a ls⇩a le⇩b ls⇩b + ord⇩b: preorder le⇩b ls⇩b for le⇩a ls⇩a :: "['a, 'a] ⇒ bool" and le⇩b ls⇩b :: "['b, 'b] ⇒ bool" locale ord_preorder_dual = ord_preorder le⇩a ls⇩a le⇩b ls⇩b for le⇩a ls⇩a :: "['a, 'a] ⇒ bool" and le⇩b ls⇩b :: "['b, 'b] ⇒ bool" begin interpretation ord_pair_syntax . sublocale ord_pair_dual . sublocale ord_dual: ord_preorder ‹(≤⇩a)› ‹(<⇩a)› ‹(≥⇩b)› ‹(>⇩b)› apply unfold_locales (*goals: 1. ‹⋀x y. (y <⇩b x) = (y ≤⇩b x ∧ ¬ x ≤⇩b y)› 2. ‹⋀x. x ≤⇩b x› 3. ‹⋀x y z. ⟦y ≤⇩b x; z ≤⇩b y⟧ ⟹ z ≤⇩b x› discuss goal 1*) apply ((auto simp: ord⇩b.less_le_not_le (*‹(?x <⇩b ?y) = (?x ≤⇩b ?y ∧ ¬ ?y ≤⇩b ?x)›*) intro: ord⇩b.order_trans (*‹⟦?x ≤⇩b ?y; ?y ≤⇩b ?z⟧ ⟹ ?x ≤⇩b ?z›*))[1]) (*discuss goal 2*) apply ((auto simp: ord⇩b.less_le_not_le (*‹(?x <⇩b ?y) = (?x ≤⇩b ?y ∧ ¬ ?y ≤⇩b ?x)›*) intro: ord⇩b.order_trans (*‹⟦?x ≤⇩b ?y; ?y ≤⇩b ?z⟧ ⟹ ?x ≤⇩b ?z›*))[1]) (*discuss goal 3*) apply ((auto simp: ord⇩b.less_le_not_le (*‹(?x <⇩b ?y) = (?x ≤⇩b ?y ∧ ¬ ?y ≤⇩b ?x)›*) intro: ord⇩b.order_trans (*‹⟦?x ≤⇩b ?y; ?y ≤⇩b ?z⟧ ⟹ ?x ≤⇩b ?z›*))[1]) (*proven 3 subgoals*) . sublocale dual_ord: ord_preorder ‹(≥⇩a)› ‹(>⇩a)› ‹(≤⇩b)› ‹(<⇩b)› by (rule ord_preorder_axioms (*‹ord_preorder (≤⇩b) (<⇩b)›*)) sublocale dual_dual: ord_preorder ‹(≥⇩a)› ‹(>⇩a)› ‹(≥⇩b)› ‹(>⇩b)› by (rule ord_dual.ord_preorder_axioms (*‹ord_preorder (λx y. y ≤⇩b x) (λx y. y <⇩b x)›*)) end locale preorder_pair = ord_preorder le⇩a ls⇩a le⇩b ls⇩b + ord⇩a: preorder le⇩a ls⇩a for le⇩a ls⇩a :: "['a, 'a] ⇒ bool" and le⇩b ls⇩b :: "['b, 'b] ⇒ bool" begin sublocale rev: preorder_pair le⇩b ls⇩b le⇩a ls⇩a by standard end locale preorder_pair_dual = preorder_pair le⇩a ls⇩a le⇩b ls⇩b for le⇩a ls⇩a :: "['a, 'a] ⇒ bool" and le⇩b ls⇩b :: "['b, 'b] ⇒ bool" begin interpretation ord_pair_syntax . sublocale ord_preorder_dual by standard sublocale ord_dual: preorder_pair ‹(≤⇩a)› ‹(<⇩a)› ‹(≥⇩b)› ‹(>⇩b)› by standard sublocale dual_ord: preorder_pair ‹(≥⇩a)› ‹(>⇩a)› ‹(≤⇩b)› ‹(<⇩b)› apply unfold_locales (*goals: 1. ‹⋀x y. (y <⇩a x) = (y ≤⇩a x ∧ ¬ x ≤⇩a y)› 2. ‹⋀x. x ≤⇩a x› 3. ‹⋀x y z. ⟦y ≤⇩a x; z ≤⇩a y⟧ ⟹ z ≤⇩a x› discuss goal 1*) apply ((auto intro: ord⇩a.order_trans (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?z⟧ ⟹ ?x ≤⇩a ?z›*) simp: ord⇩a.less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*))[1]) (*discuss goal 2*) apply ((auto intro: ord⇩a.order_trans (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?z⟧ ⟹ ?x ≤⇩a ?z›*) simp: ord⇩a.less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*))[1]) (*discuss goal 3*) apply ((auto intro: ord⇩a.order_trans (*‹⟦(?x::'a) ≤⇩a (?y::'a); ?y ≤⇩a (?z::'a)⟧ ⟹ ?x ≤⇩a ?z›*) simp: ord⇩a.less_le_not_le (*‹((?x::'a) <⇩a (?y::'a)) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*))[1]) (*proven 3 subgoals*) . sublocale dual_dual: preorder_pair ‹(≥⇩a)› ‹(>⇩a)› ‹(≥⇩b)› ‹(>⇩b)› by standard end subsubsection‹Results› context preorder begin interpretation ord_syntax . text‹Reflexivity.› lemma eq_refl: assumes "x = y" shows "x ≤⇩a y" using assms (*‹(x::'a) = (y::'a)›*) apply (rule ssubst (*‹⟦?t = ?s; ?P ?s⟧ ⟹ ?P ?t›*)) (*goal: ‹x ≤⇩a y›*) by (rule order_refl (*‹?x ≤⇩a ?x›*)) lemma less_irrefl[iff]: "¬ x <⇩a x" by (simp add: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*)) lemma less_imp_le: assumes "x <⇩a y" shows "x ≤⇩a y" using assms (*‹x <⇩a y›*) by (simp add: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*)) lemma strict_implies_not_eq: assumes "a <⇩a b" shows "a ≠ b" using assms (*‹a <⇩a b›*) by blast text‹Asymmetry.› lemma less_not_sym: assumes "x <⇩a y" shows "¬ (y <⇩a x)" using assms (*‹(x::'a::type) <⇩a (y::'a::type)›*) by (simp add: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*)) lemma asym: assumes "a <⇩a b" and "b <⇩a a" shows False using assms (*‹a <⇩a b› ‹b <⇩a a›*) by (simp add: less_not_sym (*‹?x <⇩a ?y ⟹ ¬ ?y <⇩a ?x›*)) lemma less_asym: assumes "x <⇩a y" and "(¬ P ⟹ y <⇩a x)" shows P using assms (*‹x <⇩a y› ‹¬ P ⟹ y <⇩a x›*) by (auto dest: asym (*‹⟦?a <⇩a ?b; ?b <⇩a ?a⟧ ⟹ False›*)) text‹Transitivity.› lemma less_trans: assumes "x <⇩a y" and "y <⇩a z" shows "x <⇩a z" using assms (*‹x <⇩a y› ‹y <⇩a z›*) by (auto simp: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*) intro: order_trans (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?z⟧ ⟹ ?x ≤⇩a ?z›*)) lemma le_less_trans: assumes "x ≤⇩a y" and "y <⇩a z" shows "x <⇩a z" using assms (*‹(x::'a::type) ≤⇩a (y::'a::type)› ‹y <⇩a z›*) by (auto simp: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*) intro: order_trans (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?z⟧ ⟹ ?x ≤⇩a ?z›*)) lemma less_le_trans: assumes "x <⇩a y" and "y ≤⇩a z" shows "x <⇩a z" using assms (*‹(x::'a) <⇩a (y::'a)› ‹y ≤⇩a z›*) by (auto simp: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*) intro: order_trans (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?z⟧ ⟹ ?x ≤⇩a ?z›*)) lemma less_imp_not_less: assumes "x <⇩a y" shows "(¬ y <⇩a x) ⟷ True" using assms (*‹x <⇩a y›*) apply (elim less_asym (*‹⟦(?x::'a::type) <⇩a (?y::'a::type); ¬ (?P::bool) ⟹ ?y <⇩a ?x⟧ ⟹ ?P›*)) (*goal: ‹(¬ y <⇩a x) = True›*) by simp lemma less_imp_triv: assumes "x <⇩a y" shows "(y <⇩a x ⟶ P) ⟷ True" using assms (*‹(x::'a::type) <⇩a (y::'a::type)›*) apply (elim less_asym (*‹⟦?x <⇩a ?y; ¬ ?P ⟹ ?y <⇩a ?x⟧ ⟹ ?P›*)) (*goal: ‹((y::'a) <⇩a (x::'a) ⟶ (P::bool)) = True›*) by simp lemma less_asym': assumes "a <⇩a b" and "b <⇩a a" shows P using assms (*‹a <⇩a b› ‹(b::'a::type) <⇩a (a::'a::type)›*) by (rule less_asym (*‹⟦?x <⇩a ?y; ¬ ?P ⟹ ?y <⇩a ?x⟧ ⟹ ?P›*)) end subsection‹Partial orders› subsubsection‹Definitions› text‹Abstract partial orders.› locale order = preorder le ls for le ls :: "['a, 'a] ⇒ bool" + assumes antisym: "le x y ⟹ le y x ⟹ x = y" locale order_dual = order le ls for le ls :: "['a, 'a] ⇒ bool" begin interpretation ord_syntax . sublocale preorder_dual by standard sublocale dual: order ge gt unfolding order_def order_axioms_def (*goal: ‹preorder (λ(x::'a) y::'a. y ≤⇩a x) (λ(x::'a) y::'a. y <⇩a x) ∧ (∀(x::'a) y::'a. y ≤⇩a x ⟶ x ≤⇩a y ⟶ x = y)›*) apply unfold_locales (*goal: ‹preorder (λx y. y ≤⇩a x) (λx y. y <⇩a x) ∧ (∀x y. y ≤⇩a x ⟶ x ≤⇩a y ⟶ x = y)›*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goal: ‹preorder (λx y. y ≤⇩a x) (λx y. y <⇩a x) ∧ (∀x y. y ≤⇩a x ⟶ x ≤⇩a y ⟶ x = y)›*) subgoal for by (rule dual.preorder_axioms (*‹preorder (λx y. y ≤⇩a x) (λx y. y <⇩a x)›*)) subgoal for by (simp add: antisym (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?x⟧ ⟹ ?x = ?y›*)) . end text‹Pairs.› locale ord_order = ord_preorder le⇩a ls⇩a le⇩b ls⇩b + ord⇩b: order le⇩b ls⇩b for le⇩a ls⇩a :: "'a ⇒ 'a ⇒ bool" and le⇩b ls⇩b :: "'b ⇒ 'b ⇒ bool" locale ord_order_dual = ord_order le⇩a ls⇩a le⇩b ls⇩b for le⇩a ls⇩a :: "'a ⇒ 'a ⇒ bool" and le⇩b ls⇩b :: "'b ⇒ 'b ⇒ bool" begin interpretation ord_pair_syntax . sublocale ord_preorder_dual by standard sublocale ord_dual: ord_order ‹(≤⇩a)› ‹(<⇩a)› ‹(≥⇩b)› ‹(>⇩b)› apply unfold_locales (*goal: ‹ord_order (λ(x::'b) y::'b. y ≤⇩b x) (λ(x::'b) y::'b. y <⇩b x)›*) by (simp add: ord⇩b.antisym (*‹⟦?x ≤⇩b ?y; ?y ≤⇩b ?x⟧ ⟹ ?x = ?y›*)) sublocale dual_ord: ord_order ‹(≥⇩a)› ‹(>⇩a)› ‹(≤⇩b)› ‹(<⇩b)› by (rule ord_order_axioms (*‹ord_order (≤⇩b) (<⇩b)›*)) sublocale dual_dual: ord_order ‹(≥⇩a)› ‹(>⇩a)› ‹(≥⇩b)› ‹(>⇩b)› by (rule ord_dual.ord_order_axioms (*‹ord_order (λx y. y ≤⇩b x) (λx y. y <⇩b x)›*)) end locale preorder_order = ord_order le⇩a ls⇩a le⇩b ls⇩b + ord⇩a: preorder le⇩a ls⇩a for le⇩a ls⇩a :: "['a, 'a] ⇒ bool" and le⇩b ls⇩b :: "['b, 'b] ⇒ bool" begin sublocale preorder_pair by standard end locale preorder_order_dual = preorder_order le⇩a ls⇩a le⇩b ls⇩b for le⇩a ls⇩a :: "['a, 'a] ⇒ bool" and le⇩b ls⇩b :: "['b, 'b] ⇒ bool" begin interpretation ord_pair_syntax . sublocale ord_order_dual by standard sublocale preorder_pair_dual by standard sublocale ord_dual: preorder_order ‹(≤⇩a)› ‹(<⇩a)› ‹(≥⇩b)› ‹(>⇩b)› by standard sublocale dual_ord: preorder_order ‹(≥⇩a)› ‹(>⇩a)› ‹(≤⇩b)› ‹(<⇩b)› by standard sublocale dual_dual: preorder_order ‹(≥⇩a)› ‹(>⇩a)› ‹(≥⇩b)› ‹(>⇩b)› by standard end locale order_pair = preorder_order le⇩a ls⇩a le⇩b ls⇩b + ord⇩a: order le⇩a ls⇩a for le⇩a ls⇩a :: "['a, 'a] ⇒ bool" and le⇩b ls⇩b :: "['b, 'b] ⇒ bool" begin sublocale rev: order_pair le⇩b ls⇩b le⇩a ls⇩a by standard end locale order_pair_dual = order_pair le⇩a ls⇩a le⇩b ls⇩b for le⇩a ls⇩a :: "['a, 'a] ⇒ bool" and le⇩b ls⇩b :: "['b, 'b] ⇒ bool" begin interpretation ord_pair_syntax . sublocale preorder_order_dual by standard sublocale ord_dual: order_pair ‹(≤⇩a)› ‹(<⇩a)› ‹(≥⇩b)› ‹(>⇩b)› by standard sublocale dual_ord: order_pair ‹(≥⇩a)› ‹(>⇩a)› ‹(≤⇩b)› ‹(<⇩b)› apply unfold_locales (*goal: ‹order_pair (λx y. y ≤⇩a x) (λx y. y <⇩a x) (≤⇩b) (<⇩b)›*) by (simp add: ord⇩a.antisym (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?x⟧ ⟹ ?x = ?y›*)) sublocale dual_dual: order_pair ‹(≥⇩a)› ‹(>⇩a)› ‹(≥⇩b)› ‹(>⇩b)› by standard end subsubsection‹Results› context order begin interpretation ord_syntax . text‹Reflexivity.› lemma less_le: "x <⇩a y ⟷ x ≤⇩a y ∧ x ≠ y" by (auto simp: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*) intro: antisym (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?x⟧ ⟹ ?x = ?y›*)) lemma le_less: "x ≤⇩a y ⟷ x <⇩a y ∨ x = y" by (auto simp: less_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ?x ≠ ?y)›*)) lemma le_imp_less_or_eq: assumes "x ≤⇩a y" shows "x <⇩a y ∨ x = y" using assms (*‹x ≤⇩a y›*) by (simp add: le_less (*‹(?x ≤⇩a ?y) = (?x <⇩a ?y ∨ ?x = ?y)›*)) lemma less_imp_not_eq: assumes "x <⇩a y" shows "(x = y) ⟷ False" using assms (*‹x <⇩a y›*) by auto lemma less_imp_not_eq2: assumes "x <⇩a y" shows "(y = x) ⟷ False" using assms (*‹x <⇩a y›*) by auto text‹Transitivity.› lemma neq_le_trans: assumes "a ≠ b" and "a ≤⇩a b" shows "a <⇩a b" using assms (*‹a ≠ b› ‹a ≤⇩a b›*) by (simp add: less_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ?x ≠ ?y)›*)) lemma le_neq_trans: assumes "a ≤⇩a b" and "a ≠ b" shows "a <⇩a b" using assms (*‹a ≤⇩a b› ‹a ≠ b›*) by (simp add: less_le (*‹((?x::'a) <⇩a (?y::'a)) = (?x ≤⇩a ?y ∧ ?x ≠ ?y)›*)) text‹Asymmetry.› lemma eq_iff: "x = y ⟷ x ≤⇩a y ∧ y ≤⇩a x" by (blast intro: antisym (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?x⟧ ⟹ ?x = ?y›*)) lemma antisym_conv: assumes "y ≤⇩a x" shows "x ≤⇩a y ⟷ x = y" using assms (*‹y ≤⇩a x›*) by (blast intro: antisym (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?x⟧ ⟹ ?x = ?y›*)) text‹Other results.› lemma antisym_conv1: assumes "¬ x <⇩a y" shows "x ≤⇩a y ⟷ x = y" using assms (*‹¬ x <⇩a y›*) by (simp add: le_less (*‹(?x ≤⇩a ?y) = (?x <⇩a ?y ∨ ?x = ?y)›*)) lemma antisym_conv2: assumes "x ≤⇩a y" shows "¬ x <⇩a y ⟷ x = y" using assms (*‹(x::'a) ≤⇩a (y::'a)›*) le_less (*‹((?x::'a) ≤⇩a (?y::'a)) = (?x <⇩a ?y ∨ ?x = ?y)›*) by auto lemma leD: assumes "y ≤⇩a x" shows "¬ x <⇩a y" using assms (*‹y ≤⇩a x›*) by (simp add: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*)) end subsection‹Dense orders› text‹Abstract dense orders.› locale dense_order = order le ls for le ls :: "['a, 'a] ⇒ bool" + assumes dense: "ls x y ⟹ (∃z. ls x z ∧ ls z y)" locale dense_order_dual = dense_order le ls for le ls :: "['a, 'a] ⇒ bool" begin interpretation ord_syntax . sublocale order_dual by standard sublocale dual: dense_order ge gt using dense (*‹?x <⇩a ?y ⟹ ∃z. ?x <⇩a z ∧ z <⇩a ?y›*) apply unfold_locales (*goal: ‹dense_order (λx y. y ≤⇩a x) (λx y. y <⇩a x)›*) by auto end text‹Pairs.› locale ord_dense_order = ord_order le⇩a ls⇩a le⇩b ls⇩b + ord⇩b: dense_order le⇩b ls⇩b for le⇩a ls⇩a :: "'a ⇒ 'a ⇒ bool" and le⇩b ls⇩b :: "'b ⇒ 'b ⇒ bool" locale ord_dense_order_dual = ord_dense_order le⇩a ls⇩a le⇩b ls⇩b for le⇩a ls⇩a :: "'a ⇒ 'a ⇒ bool" and le⇩b ls⇩b :: "'b ⇒ 'b ⇒ bool" begin interpretation ord_pair_syntax . sublocale ord_order_dual by standard sublocale ord_dual: ord_dense_order ‹(≤⇩a)› ‹(<⇩a)› ‹(≥⇩b)› ‹(>⇩b)› using "ord⇩b.dense" (*‹(?x::'b) <⇩b (?y::'b) ⟹ ∃z::'b. ?x <⇩b z ∧ z <⇩b ?y›*) apply unfold_locales (*goal: ‹ord_dense_order (λx y. y ≤⇩b x) (λx y. y <⇩b x)›*) by blast sublocale dual_ord: ord_dense_order ‹(≥⇩a)› ‹(>⇩a)› ‹(≤⇩b)› ‹(<⇩b)› by (rule ord_dense_order_axioms (*‹ord_dense_order (≤⇩b) (<⇩b)›*)) sublocale dual_dual: ord_dense_order ‹(≥⇩a)› ‹(>⇩a)› ‹(≥⇩b)› ‹(>⇩b)› by (rule ord_dual.ord_dense_order_axioms (*‹ord_dense_order (λx y. y ≤⇩b x) (λx y. y <⇩b x)›*)) end locale preorder_dense_order = ord_dense_order le⇩a ls⇩a le⇩b ls⇩b + ord⇩a: preorder le⇩a ls⇩a for le⇩a ls⇩a :: "'a ⇒ 'a ⇒ bool" and le⇩b ls⇩b :: "'b ⇒ 'b ⇒ bool" begin sublocale preorder_order by standard end locale preorder_dense_order_dual = preorder_dense_order le⇩a ls⇩a le⇩b ls⇩b for le⇩a ls⇩a :: "'a ⇒ 'a ⇒ bool" and le⇩b ls⇩b :: "'b ⇒ 'b ⇒ bool" begin interpretation ord_pair_syntax . sublocale ord_dense_order_dual by standard sublocale preorder_order_dual by standard sublocale ord_dual: preorder_dense_order ‹(≤⇩a)› ‹(<⇩a)› ‹(≥⇩b)› ‹(>⇩b)› by standard sublocale dual_ord: preorder_dense_order ‹(≥⇩a)› ‹(>⇩a)› ‹(≤⇩b)› ‹(<⇩b)› by standard sublocale dual_dual: preorder_dense_order ‹(≥⇩a)› ‹(>⇩a)› ‹(≥⇩b)› ‹(>⇩b)› by standard end locale order_dense_order = preorder_dense_order le⇩a ls⇩a le⇩b ls⇩b + ord⇩a: order le⇩a ls⇩a for le⇩a ls⇩a :: "'a ⇒ 'a ⇒ bool" and le⇩b ls⇩b :: "'b ⇒ 'b ⇒ bool" begin sublocale order_pair by standard end locale order_dense_order_dual = order_dense_order le⇩a ls⇩a le⇩b ls⇩b for le⇩a ls⇩a :: "'a ⇒ 'a ⇒ bool" and le⇩b ls⇩b :: "'b ⇒ 'b ⇒ bool" begin interpretation ord_pair_syntax . sublocale preorder_dense_order_dual by standard sublocale order_pair_dual by standard sublocale ord_dual: order_dense_order ‹(≤⇩a)› ‹(<⇩a)› ‹(≥⇩b)› ‹(>⇩b)› by standard sublocale dual_ord: order_dense_order ‹(≥⇩a)› ‹(>⇩a)› ‹(≤⇩b)› ‹(<⇩b)› by standard sublocale dual_dual: order_dense_order ‹(≥⇩a)› ‹(>⇩a)› ‹(≥⇩b)› ‹(>⇩b)› by standard end locale dense_order_pair = order_dense_order le⇩a ls⇩a le⇩b ls⇩b + ord⇩a: dense_order le⇩a ls⇩a for le⇩a ls⇩a :: "'a ⇒ 'a ⇒ bool" and le⇩b ls⇩b :: "'b ⇒ 'b ⇒ bool" locale dense_order_pair_dual = dense_order_pair le⇩a ls⇩a le⇩b ls⇩b for le⇩a ls⇩a :: "'a ⇒ 'a ⇒ bool" and le⇩b ls⇩b :: "'b ⇒ 'b ⇒ bool" begin interpretation ord_pair_syntax . sublocale order_dense_order_dual by standard sublocale ord_dual: dense_order_pair ‹(≤⇩a)› ‹(<⇩a)› ‹(≥⇩b)› ‹(>⇩b)› by standard sublocale dual_ord: dense_order_pair ‹(≥⇩a)› ‹(>⇩a)› ‹(≤⇩b)› ‹(<⇩b)› using "ord⇩a.dense" (*‹?x <⇩a ?y ⟹ ∃z. ?x <⇩a z ∧ z <⇩a ?y›*) apply unfold_locales (*goal: ‹dense_order_pair (λx y. y ≤⇩a x) (λx y. y <⇩a x) (≤⇩b) (<⇩b)›*) by auto sublocale dual_dual: dense_order_pair ‹(≥⇩a)› ‹(>⇩a)› ‹(≥⇩b)› ‹(>⇩b)› by standard end subsection‹(Unique) top and bottom elements› text‹Abstract extremum.› locale extremum = fixes extremum :: 'a locale ord_extremum = ord le ls + extremum extremum for le ls :: "'a ⇒ 'a ⇒ bool" and extremum :: 'a text‹Concrete syntax.› locale bot = extremum bot for bot :: 'a begin notation bot ("⊥") end locale top = extremum top for top :: 'a begin notation top ("⊤") end subsection‹(Unique) top and bottom elements for partial orders› subsubsection‹Definitions› text‹Abstract partial order with extremum.› locale order_extremum = ord_extremum le ls extremum + order le ls for le ls :: "'a ⇒ 'a ⇒ bool" and extremum :: 'a + assumes extremum[simp]: "le a extremum" text‹Concrete syntax.› locale order_bot = order_dual le ls + dual: order_extremum ‹λx y. le y x› ‹λx y. ls y x› bot + bot bot for le ls :: "'a ⇒ 'a ⇒ bool" and bot :: 'a locale order_top = order_dual le ls + order_extremum le ls top + top top for le ls :: "'a ⇒ 'a ⇒ bool" and top :: 'a subsubsection‹Results› context order_extremum begin interpretation ord_syntax . lemma extremum_uniqueI: assumes "extremum ≤⇩a a" shows "a = extremum" using assms (*‹extremum ≤⇩a a›*) by (simp add: antisym (*‹⟦(?x::'a) ≤⇩a (?y::'a); ?y ≤⇩a ?x⟧ ⟹ ?x = ?y›*)) lemma extremum_unique: "extremum ≤⇩a a ⟷ a = extremum" by (auto intro: antisym (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?x⟧ ⟹ ?x = ?y›*)) lemma extremum_strict[simp]: "¬ (extremum <⇩a a)" by (fastforce simp: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*)) lemma not_eq_extremum: "a ≠ extremum ⟷ a <⇩a extremum" using le_imp_less_or_eq (*‹?x ≤⇩a ?y ⟹ ?x <⇩a ?y ∨ ?x = ?y›*) by (auto intro: extremum (*‹?a ≤⇩a extremum›*)) end subsection‹Partial orders without top or bottom elements› text‹Abstract partial orders without top or bottom elements.› locale no_extremum = order le ls for le ls :: "'a ⇒ 'a ⇒ bool" + assumes gt_ex: "∃y. ls x y" text‹Concrete syntax.› locale no_top = order_dual le ls + no_extremum le ls for le ls :: "'a ⇒ 'a ⇒ bool" locale no_bot = order_dual le ls + dual: no_extremum ‹λx y. le y x› ‹λx y. ls y x› for le ls :: "'a ⇒ 'a ⇒ bool" subsection‹Least and greatest operators› definition Least :: "['a set, ['a, 'a] ⇒ bool, 'a ⇒ bool] ⇒ 'a option" (‹(on _ with _ : «Least» _)› [1000, 1000, 1000] 10) where "on U with op : «Least» P ≡ (THE x on U. P x ∧ (∀y∈U. P y ⟶ op x y))" ctr relativization synthesis ctr_simps assumes [transfer_domain_rule, transfer_rule]: "Domainp A = (λx. x ∈ U)" and [transfer_rule]: "bi_unique A" "right_total A" trp (?'a A) in Least_def context ord_syntax begin abbreviation Least where "Least ≡ Type_Simple_Orders.Least UNIV (≤⇩a)" abbreviation Greatest where "Greatest ≡ Type_Simple_Orders.Least UNIV (≥⇩a)" lemmas Least_def = Least_def[of UNIV ‹(≤⇩a)›] end context order begin interpretation ord_syntax . lemma Least_equality: assumes "P x" and "⋀y. P y ⟹ x ≤⇩a y" shows "Least P = Some x" unfolding Least_def (*goal: ‹(THE x on UNIV. P x ∧ (∀y∈UNIV. P y ⟶ x ≤⇩a y)) = Some x›*) apply (rule The_on_Some_equality (*‹⟦(?a::?'a) ∈ (?U::?'a set); (?P::?'a ⇒ bool) ?a; ⋀x::?'a. ⟦x ∈ ?U; ?P x⟧ ⟹ x = ?a⟧ ⟹ (THE x::?'a on ?U. ?P x) = Some ?a›*)) (*goals: 1. ‹x ∈ UNIV› 2. ‹P x ∧ (∀y∈UNIV. P y ⟶ x ≤⇩a y)› 3. ‹⋀xa. ⟦xa ∈ UNIV; P xa ∧ (∀y∈UNIV. P y ⟶ xa ≤⇩a y)⟧ ⟹ xa = x› discuss goal 1*) apply ((auto simp: assms (*‹P x› ‹P ?y ⟹ x ≤⇩a ?y›*) antisym (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?x⟧ ⟹ ?x = ?y›*))[1]) (*discuss goal 2*) apply ((auto simp: assms (*‹P x› ‹P ?y ⟹ x ≤⇩a ?y›*) antisym (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?x⟧ ⟹ ?x = ?y›*))[1]) (*discuss goal 3*) apply ((auto simp: assms (*‹(P::'a ⇒ bool) (x::'a)› ‹(P::'a ⇒ bool) (?y::'a) ⟹ (x::'a) ≤⇩a ?y›*) antisym (*‹⟦(?x::'a) ≤⇩a (?y::'a); ?y ≤⇩a ?x⟧ ⟹ ?x = ?y›*))[1]) (*proven 3 subgoals*) . lemma LeastI2_order: assumes "P x" and "⋀y. P y ⟹ x ≤⇩a y" and "⋀x. P x ⟹ ∀y. P y ⟶ x ≤⇩a y ⟹ Q x" obtains z where "Least P = Some z" and "Q z" unfolding Least_def (*goal: ‹(⋀z::'a. ⟦(THE x::'a on UNIV. (P::'a ⇒ bool) x ∧ (∀y::'a∈UNIV. P y ⟶ x ≤⇩a y)) = Some z; (Q::'a ⇒ bool) z⟧ ⟹ thesis::bool) ⟹ thesis›*) using assms (*‹P x› ‹P ?y ⟹ x ≤⇩a ?y› ‹⟦P ?x; ∀y. P y ⟶ ?x ≤⇩a y⟧ ⟹ Q ?x›*) by (clarsimp simp: that (*‹⟦local.Least (P::'a ⇒ bool) = Some (?z::'a); (Q::'a ⇒ bool) ?z⟧ ⟹ thesis::bool›*) Least_equality (*‹⟦(?P::'a ⇒ bool) (?x::'a); ⋀y::'a. ?P y ⟹ ?x ≤⇩a y⟧ ⟹ local.Least ?P = Some ?x›*)) lemma Least_ex1: assumes "∃!x. P x ∧ (∀y. P y ⟶ x ≤⇩a y)" obtains x where "Least P = Some x" and "P x" and "P z ⟹ x ≤⇩a z" using assms (*‹∃!x::'a::type. (P::'a::type ⇒ bool) x ∧ (∀y::'a::type. P y ⟶ x ≤⇩a y)›*) unfolding Least_def (*goal: ‹(⋀x. ⟦(THE x on UNIV. P x ∧ (∀y∈UNIV. P y ⟶ x ≤⇩a y)) = Some x; P x; P z ⟹ x ≤⇩a z⟧ ⟹ thesis) ⟹ thesis›*) by (clarsimp simp: that (*‹⟦local.Least P = Some ?x; P ?x; P z ⟹ ?x ≤⇩a z⟧ ⟹ thesis›*) Least_equality (*‹⟦?P ?x; ⋀y. ?P y ⟹ ?x ≤⇩a y⟧ ⟹ local.Least ?P = Some ?x›*)) end subsection‹min and max› definition min :: "[['a, 'a] ⇒ bool, 'a, 'a] ⇒ 'a" where "min le a b = (if le a b then a else b)" ctr parametricity in min_def context ord_syntax begin abbreviation min where "min ≡ Type_Simple_Orders.min (≤⇩a)" abbreviation max where "max ≡ Type_Simple_Orders.min (≥⇩a)" end context ord begin interpretation ord_syntax . lemma min_absorb1: "x ≤⇩a y ⟹ min x y = x" unfolding min_def (*goal: ‹x ≤⇩a y ⟹ (if x ≤⇩a y then x else y) = x›*) by simp end context order begin interpretation ord_syntax . lemma min_absorb2: assumes "y ≤⇩a x" shows "min x y = y" using assms (*‹y ≤⇩a x›*) unfolding min_def (*goal: ‹(if x ≤⇩a y then x else y) = y›*) by (simp add: eq_iff (*‹(?x = ?y) = (?x ≤⇩a ?y ∧ ?y ≤⇩a ?x)›*)) end context order_extremum begin interpretation ord_syntax . lemma max_top[simp]: "max extremum x = extremum" by (simp add: ord.min_absorb1 (*‹(?le::?'a ⇒ ?'a ⇒ bool) (?x::?'a) (?y::?'a) ⟹ Type_Simple_Orders.min ?le ?x ?y = ?x›*)) lemma max_top2[simp]: "max x extremum = extremum" unfolding min_def (*goal: ‹(if extremum ≤⇩a x then x else extremum) = extremum›*) by (simp add: extremum_uniqueI (*‹extremum ≤⇩a ?a ⟹ ?a = extremum›*)) lemma min_top[simp]: "min extremum x = x" by (simp add: min_absorb2 (*‹?y ≤⇩a ?x ⟹ local.min ?x ?y = ?y›*)) lemma min_top2[simp]: "min x extremum = x" by (simp add: min_def (*‹Type_Simple_Orders.min (?le::?'a ⇒ ?'a ⇒ bool) (?a::?'a) (?b::?'a) = (if ?le ?a ?b then ?a else ?b)›*) top_unique (*‹(top ≤ (?a::?'a)) = (?a = top)›*)) end subsection‹Monotonicity› definition mono :: "['a set, ['a, 'a] ⇒ bool, ['b, 'b] ⇒ bool, 'a ⇒ 'b] ⇒ bool" (‹(on _ with _ _ : «mono» _)› [1000, 1000, 999, 1000] 10) where "on U⇩a with op₁ op₂ : «mono» f ≡ ∀x∈U⇩a. ∀y∈U⇩a. op₁ x y ⟶ op₂ (f x) (f y)" ctr parametricity in mono_def context ord_pair_syntax begin abbreviation mono⇩a⇩b where "mono⇩a⇩b ≡ Type_Simple_Orders.mono UNIV (≤⇩a) (≤⇩b)" abbreviation mono⇩b⇩a where "mono⇩b⇩a ≡ Type_Simple_Orders.mono UNIV (≤⇩b) (≤⇩a)" abbreviation antimono⇩a⇩b where "antimono⇩a⇩b ≡ Type_Simple_Orders.mono UNIV (≤⇩a) (≥⇩b)" abbreviation antimono⇩b⇩a where "antimono⇩b⇩a ≡ Type_Simple_Orders.mono UNIV (≤⇩b) (≥⇩a)" abbreviation strict_mono⇩a⇩b where "strict_mono⇩a⇩b ≡ Type_Simple_Orders.mono UNIV (<⇩a) (<⇩b)" abbreviation strict_mono⇩b⇩a where "strict_mono⇩b⇩a ≡ Type_Simple_Orders.mono UNIV (<⇩b) (<⇩a)" abbreviation strict_antimono⇩a⇩b where "strict_antimono⇩a⇩b ≡ Type_Simple_Orders.mono UNIV (<⇩a) (>⇩b)" abbreviation strict_antimono⇩b⇩a where "strict_antimono⇩b⇩a ≡ Type_Simple_Orders.mono UNIV (<⇩b) (>⇩a)" end context ord_pair begin interpretation ord_pair_syntax . lemma monoI[intro?]: assumes "⋀x y. x ≤⇩a y ⟹ f x ≤⇩b f y" shows "mono⇩a⇩b f" unfolding mono_def (*goal: ‹∀x∈UNIV. ∀y∈UNIV. x ≤⇩a y ⟶ f x ≤⇩b f y›*) using assms (*‹?x ≤⇩a ?y ⟹ f ?x ≤⇩b f ?y›*) by simp lemma monoD[dest?]: assumes "mono⇩a⇩b f" and "x ≤⇩a y" shows "f x ≤⇩b f y" using assms (*‹mono⇩a⇩b f› ‹x ≤⇩a y›*) unfolding mono_def (*goal: ‹f x ≤⇩b f y›*) by simp lemma monoE: assumes "mono⇩a⇩b f" and "x ≤⇩a y" obtains "f x ≤⇩b f y" using assms (*‹mono⇩a⇩b (f::'a ⇒ 'b)› ‹x ≤⇩a y›*) unfolding mono_def (*goal: ‹((f::'a ⇒ 'b) (x::'a) ≤⇩b f (y::'a) ⟹ thesis::bool) ⟹ thesis›*) by simp lemma strict_monoI[intro?]: assumes "⋀x y. x <⇩a y ⟹ f x <⇩b f y" shows "strict_mono⇩a⇩b f" unfolding mono_def (*goal: ‹∀x::'a∈UNIV. ∀y::'a∈UNIV. x <⇩a y ⟶ (f::'a ⇒ 'b) x <⇩b f y›*) using assms (*‹?x <⇩a ?y ⟹ f ?x <⇩b f ?y›*) by simp lemma strict_monoD[dest?]: assumes "strict_mono⇩a⇩b f" and "x <⇩a y" shows "f x <⇩b f y" using assms (*‹strict_mono⇩a⇩b f› ‹x <⇩a y›*) unfolding mono_def (*goal: ‹f x <⇩b f y›*) by simp lemma strict_monoE: assumes "strict_mono⇩a⇩b f" and "x <⇩a y" obtains "f x <⇩b f y" using assms (*‹strict_mono⇩a⇩b f› ‹x <⇩a y›*) unfolding mono_def (*goal: ‹(f x <⇩b f y ⟹ thesis) ⟹ thesis›*) by simp end context order_pair begin interpretation ord_pair_syntax . lemma strict_mono_mono[dest?]: assumes "strict_mono⇩a⇩b f" shows "mono⇩a⇩b f" proof (rule monoI (*‹(⋀x y. x ≤⇩a y ⟹ ?f x ≤⇩b ?f y) ⟹ mono⇩a⇩b ?f›*)) (*goal: ‹⋀x y. x ≤⇩a y ⟹ f x ≤⇩b f y›*) fix x and y assume "x ≤⇩a y" (*‹(x::'a) ≤⇩a (y::'a)›*) show "f x ≤⇩b f y" proof (cases "x = y") (*goals: 1. ‹x = y ⟹ f x ≤⇩b f y› 2. ‹x ≠ y ⟹ f x ≤⇩b f y›*) case True (*‹x = y›*) then show "?thesis" (*goal: ‹(f::'a ⇒ 'b) (x::'a) ≤⇩b f (y::'a)›*) by simp next (*goal: ‹(x::'a) ≠ (y::'a) ⟹ (f::'a ⇒ 'b) x ≤⇩b f y›*) case False (*‹x ≠ y›*) with ‹x ≤⇩a y› (*‹(x::'a) ≤⇩a (y::'a)›*) have "x <⇩a y" by (simp add: ord⇩a.neq_le_trans (*‹⟦(?a::'a) ≠ (?b::'a); ?a ≤⇩a ?b⟧ ⟹ ?a <⇩a ?b›*)) with assms (*‹strict_mono⇩a⇩b (f::'a ⇒ 'b)›*) strict_monoD (*‹⟦strict_mono⇩a⇩b ?f; ?x <⇩a ?y⟧ ⟹ ?f ?x <⇩b ?f ?y›*) have "f x <⇩b f y" by simp then show "?thesis" (*goal: ‹(f::'a ⇒ 'b) (x::'a) ≤⇩b f (y::'a)›*) by (simp add: ord⇩b.le_less (*‹(?x ≤⇩b ?y) = (?x <⇩b ?y ∨ ?x = ?y)›*)) qed qed end subsection‹Set intervals› definition ray :: "['a set, ['a, 'a] ⇒ bool, 'a] ⇒ 'a set" (‹(on _ with _ : {..⊏_})› [1000, 1000, 1000] 10) where "on U with op : {..⊏u} ≡ {x ∈ U. op x u}" definition interval :: "['a set, ['a, 'a] ⇒ bool, ['a, 'a] ⇒ bool, 'a, 'a] ⇒ 'a set" (‹(on _ with _ _ : {_⊏..⊏_})› [1000, 1000, 999, 1000, 1000] 10) where "on U with op₁ op₂ : {l⊏..⊏u} ≡ (on U with (λx y. op₁ y x) : {..⊏l}) ∩ (on U with op₂ : {..⊏u})" lemma ray_transfer[transfer_rule]: includes lifting_syntax assumes [transfer_rule]: "bi_unique A" "right_total A" shows "(rel_set A ===> (A ===> A ===> (=)) ===> A ===> rel_set A) ray ray" unfolding ray_def (*goal: ‹(rel_set A ===> (A ===> A ===> (=)) ===> A ===> rel_set A) (λU op u. {x ∈ U. op x u}) (λU op u. {x ∈ U. op x u})›*) proof (intro rel_funI (*‹(⋀x y. ?A x y ⟹ ?B (?f x) (?g y)) ⟹ (?A ===> ?B) ?f ?g›*)) (*goal: ‹⋀(x::'a set) (y::'b set) (xa::'a ⇒ 'a ⇒ bool) (ya::'b ⇒ 'b ⇒ bool) (xb::'a) yb::'b. ⟦rel_set (A::'a ⇒ 'b ⇒ bool) x y; (A ===> A ===> (=)) xa ya; A xb yb⟧ ⟹ rel_set A {xc::'a ∈ x. xa xc xb} {x::'b ∈ y. ya x yb}›*) fix S :: "'a set" and S' :: "'b set" and le :: "['a, 'a] ⇒ bool" and le' :: "['b, 'b] ⇒ bool" and u and u' assume [transfer_rule]: "rel_set A S S'" and [transfer_rule]: "(A ===> A ===> (=)) le le'" and [transfer_rule]: "A u u'" (*‹rel_set (A::'a ⇒ 'b ⇒ bool) (S::'a set) (S'::'b set)› ‹((A::'a ⇒ 'b ⇒ bool) ===> A ===> (=)) (le::'a ⇒ 'a ⇒ bool) (le'::'b ⇒ 'b ⇒ bool)› ‹(A::'a ⇒ 'b ⇒ bool) (u::'a) (u'::'b)›*) show "rel_set A {xc ∈ S. le xc u} {x ∈ S'. le' x u'}" proof (intro rel_setI (*‹⟦⋀x. x ∈ ?A ⟹ ∃y∈?B. ?R x y; ⋀y. y ∈ ?B ⟹ ∃x∈?A. ?R x y⟧ ⟹ rel_set ?R ?A ?B›*)) (*goals: 1. ‹⋀x. x ∈ {xc ∈ S. le xc u} ⟹ ∃y∈{x ∈ S'. le' x u'}. A x y› 2. ‹⋀y. y ∈ {x ∈ S'. le' x u'} ⟹ ∃x∈{xc ∈ S. le xc u}. A x y›*) show "x ∈ {xc ∈ S. le xc u} ⟹ ∃x'∈{x ∈ S'. le' x u'}. A x x'" for x proof (-) (*goal: ‹x ∈ {xc ∈ S. le xc u} ⟹ ∃x'∈{x ∈ S'. le' x u'}. A x x'›*) assume x: "x ∈ {xc ∈ S. le xc u}" (*‹(x::'a) ∈ {xc::'a ∈ S::'a set. (le::'a ⇒ 'a ⇒ bool) xc (u::'a)}›*) then obtain x' where [transfer_rule]: "A x x'" (*goal: ‹(⋀x'. A x x' ⟹ thesis) ⟹ thesis›*) using ‹rel_set A S S'› (*‹rel_set A S S'›*) rel_setD1 (*‹⟦rel_set ?R ?A ?B; ?x ∈ ?A⟧ ⟹ ∃y∈?B. ?R ?x y›*) by fastforce from x (*‹x ∈ {xc ∈ S. le xc u}›*) have "x' ∈ {x ∈ S'. le' x u'}" apply transfer (*goal: ‹(x'::'b) ∈ {x::'b ∈ S'::'b set. (le'::'b ⇒ 'b ⇒ bool) x (u'::'b)}›*) using ‹A x x'› (*‹A x x'›*) by auto then show "?thesis" (*goal: ‹∃x'∈{x ∈ S'. le' x u'}. A x x'›*) by (auto simp: ‹A x x'›) qed show "x' ∈ {x ∈ S'. le' x u'} ⟹ ∃x∈{xc ∈ S. le xc u}. A x x'" for x' proof (-) (*goal: ‹x' ∈ {x ∈ S'. le' x u'} ⟹ ∃x∈{xc ∈ S. le xc u}. A x x'›*) assume x': "x' ∈ {x ∈ S'. le' x u'}" (*‹(x'::'b) ∈ {x::'b ∈ S'::'b set. (le'::'b ⇒ 'b ⇒ bool) x (u'::'b)}›*) then obtain x where [transfer_rule]: "A x x'" (*goal: ‹(⋀x. A x x' ⟹ thesis) ⟹ thesis›*) using assms(2) (*‹right_total A›*) by (auto elim: right_totalE (*‹⟦right_total (?A::?'a::type ⇒ ?'b::type ⇒ bool); ⋀x::?'a::type. ?A x (?y::?'b::type) ⟹ ?thesis::bool⟧ ⟹ ?thesis›*)) from x' (*‹x' ∈ {x ∈ S'. le' x u'}›*) have "x ∈ {xc ∈ S. le xc u}" apply transfer (*goal: ‹x ∈ {xc ∈ S. le xc u}›*) by auto then show "?thesis" (*goal: ‹∃x∈{xc ∈ S. le xc u}. A x x'›*) by (auto simp: ‹A x x'›) qed qed qed ctr relativization assumes [transfer_rule]: "right_total A" "bi_unique A" trp (?'a A) in interval_def lemma interval_ge_le: "(on UNIV with (λx y. le⇩a y x) (λx y. le⇩b y x) : {l⊏..⊏h}) = (on UNIV with le⇩b le⇩a : {h⊏..⊏l})" unfolding interval_def (*goal: ‹(on UNIV with le⇩a : {..⊏l}) ∩ (on UNIV with (λx y. le⇩b y x) : {..⊏h}) = (on UNIV with (λx y. le⇩b y x) : {..⊏h}) ∩ (on UNIV with le⇩a : {..⊏l})›*) by auto context ord_syntax begin abbreviation lessThan (‹{..<⇩a_}›) where "{..<⇩au} ≡ on UNIV with (<⇩a) : {..⊏u}" abbreviation atMost (‹{..≤⇩a_}›) where "{..≤⇩au} ≡ on UNIV with (≤⇩a) : {..⊏u}" abbreviation greaterThan (‹{_<⇩a..}›) where "{l<⇩a..} ≡ on UNIV with (>⇩a) : {..⊏l}" abbreviation atLeast (‹{_≤⇩a..}›) where "{l≤⇩a..} ≡ on UNIV with (≥⇩a) : {..⊏l}" abbreviation greaterThanLessThan (‹{_<⇩a..<⇩a_}›) where "{l<⇩a..<⇩au} ≡ on UNIV with (<⇩a) (<⇩a) : {l⊏..⊏u}" abbreviation atLeastLessThan (‹{_≤⇩a..<⇩a_}›) where "{l≤⇩a..<⇩au} ≡ on UNIV with (≤⇩a) (<⇩a) : {l⊏..⊏u}" abbreviation greaterThanAtMost (‹{_<⇩a..≤⇩a_}›) where "{l<⇩a..≤⇩au} ≡ on UNIV with (<⇩a) (≤⇩a) : {l⊏..⊏u}" abbreviation atLeastAtMost (‹{_≤⇩a..≤⇩a_}›) where "{l≤⇩a..≤⇩au} ≡ on UNIV with (≤⇩a) (≤⇩a) : {l⊏..⊏u}" abbreviation lessThanGreaterThan (‹{_>⇩a..>⇩a_}›) where "{l>⇩a..>⇩au} ≡ on UNIV with (>⇩a) (>⇩a) : {l⊏..⊏u}" abbreviation lessThanAtLeast (‹{_≥⇩a..>⇩a_}›) where "{l≥⇩a..>⇩au} ≡ on UNIV with (≥⇩a) (>⇩a) : {l⊏..⊏u}" abbreviation atMostGreaterThan (‹{_>⇩a..≥⇩a_}›) where "{l>⇩a..≥⇩au} ≡ on UNIV with (>⇩a) (≥⇩a) : {l⊏..⊏u}" abbreviation atMostAtLeast (‹{_≥⇩a..≥⇩a_}›) where "{l≥⇩a..≥⇩au} ≡ on UNIV with (≥⇩a) (≥⇩a) : {l⊏..⊏u}" end context ord begin interpretation ord_syntax . lemma lessThan_iff[iff]: "(i ∈ {..<⇩ak}) = (i <⇩a k)" unfolding ray_def (*goal: ‹(i ∈ {x ∈ UNIV. x <⇩a k}) = (i <⇩a k)›*) by simp lemma atLeast_iff[iff]: "(i ∈ {k≤⇩a..}) = (k ≤⇩a i)" unfolding ray_def (*goal: ‹(i ∈ {x ∈ UNIV. k ≤⇩a x}) = (k ≤⇩a i)›*) by simp lemma greaterThanLessThan_iff[simp]: "(i ∈ {l<⇩a..<⇩au}) = (l <⇩a i ∧ i <⇩a u)" unfolding interval_def ray_def (*goal: ‹(i ∈ {x ∈ UNIV. l <⇩a x} ∩ {x ∈ UNIV. x <⇩a u}) = (l <⇩a i ∧ i <⇩a u)›*) by simp lemma atLeastLessThan_iff[simp]: "(i ∈ {l≤⇩a..<⇩au}) = (l ≤⇩a i ∧ i <⇩a u)" unfolding interval_def ray_def (*goal: ‹(i ∈ {x ∈ UNIV. l ≤⇩a x} ∩ {x ∈ UNIV. x <⇩a u}) = (l ≤⇩a i ∧ i <⇩a u)›*) by simp lemma greaterThanAtMost_iff[simp]: "(i ∈ {l<⇩a..≤⇩au}) = (l <⇩a i ∧ i ≤⇩a u)" unfolding interval_def ray_def (*goal: ‹(i ∈ {x ∈ UNIV. l <⇩a x} ∩ {x ∈ UNIV. x ≤⇩a u}) = (l <⇩a i ∧ i ≤⇩a u)›*) by simp lemma atLeastAtMost_iff[simp]: "(i ∈ {l≤⇩a..≤⇩au}) = (l ≤⇩a i ∧ i ≤⇩a u)" unfolding interval_def ray_def (*goal: ‹(i ∈ {x ∈ UNIV. l ≤⇩a x} ∩ {x ∈ UNIV. x ≤⇩a u}) = (l ≤⇩a i ∧ i ≤⇩a u)›*) by simp lemma greaterThanLessThan_eq: "{a<⇩a..<⇩ab} = {a<⇩a..} ∩ {..<⇩ab}" unfolding interval_def ray_def (*goal: ‹{x ∈ UNIV. a <⇩a x} ∩ {x ∈ UNIV. x <⇩a b} = {x ∈ UNIV. a <⇩a x} ∩ {x ∈ UNIV. x <⇩a b}›*) by simp end context ord_pair_syntax begin notation ord⇩a.lessThan (‹{..<⇩a_}›) and ord⇩a.atMost (‹{..≤⇩a_}›) and ord⇩a.greaterThan (‹{_<⇩a..}›) and ord⇩a.atLeast (‹{_≤⇩a..}›) and ord⇩a.greaterThanLessThan (‹{_<⇩a..<⇩a_}›) and ord⇩a.atLeastLessThan (‹{_≤⇩a..<⇩a_}›) and ord⇩a.greaterThanAtMost (‹{_<⇩a..≤⇩a_}›) and ord⇩a.atLeastAtMost (‹{_≤⇩a..≤⇩a_}›) and ord⇩a.lessThanGreaterThan (‹{_>⇩a..>⇩a_}›) and ord⇩a.lessThanAtLeast (‹{_≥⇩a..>⇩a_}›) and ord⇩a.atMostGreaterThan (‹{_>⇩a..≥⇩a_}›) and ord⇩a.atMostAtLeast (‹{_≥⇩a..≥⇩a_}›) and ord⇩b.lessThan (‹{..<⇩b_}›) and ord⇩b.atMost (‹{..≤⇩b_}›) and ord⇩b.greaterThan (‹{_<⇩b..}›) and ord⇩b.atLeast (‹{_≤⇩b..}›) and ord⇩b.greaterThanLessThan (‹{_<⇩b..<⇩b_}›) and ord⇩b.atLeastLessThan (‹{_≤⇩b..<⇩b_}›) and ord⇩b.greaterThanAtMost (‹{_<⇩b..≤⇩b_}›) and ord⇩b.atLeastAtMost (‹{_≤⇩b..≤⇩b_}›) and ord⇩b.lessThanGreaterThan (‹{_>⇩b..>⇩b_}›) and ord⇩b.lessThanAtLeast (‹{_≥⇩b..>⇩b_}›) and ord⇩b.atMostGreaterThan (‹{_>⇩b..≥⇩b_}›) and ord⇩b.atMostAtLeast (‹{_≥⇩b..≥⇩b_}›) end context preorder begin interpretation ord_syntax . lemma Ioi_le_Ico: "{a<⇩a..} ⊆ {a≤⇩a..}" unfolding ray_def (*goal: ‹{x ∈ UNIV. a <⇩a x} ⊆ {x ∈ UNIV. a ≤⇩a x}›*) by (fastforce simp: less_le_not_le (*‹((?x::'a) <⇩a (?y::'a)) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*)) end context preorder begin interpretation ord_syntax . interpretation preorder_dual le ls by (rule preorder_dual.intro[OF preorder_axioms] (*‹preorder_dual (≤⇩a) (<⇩a)›*)) lemma single_Diff_lessThan[simp]: "{k} - {..<⇩ak} = {k}" by auto lemma atLeast_subset_iff[iff]: "({x≤⇩a..} ⊆ {y≤⇩a..}) = (y ≤⇩a x)" by (auto intro: order_trans (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?z⟧ ⟹ ?x ≤⇩a ?z›*)) lemma atLeastatMost_empty[simp]: assumes "b <⇩a a" shows "{a≤⇩a..≤⇩ab} = {}" unfolding interval_def (*goal: ‹{a::'a≤⇩a..} ∩ {..≤⇩ab::'a} = {}›*) using less_le_not_le (*‹((?x::'a) <⇩a (?y::'a)) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*) assms (*‹b <⇩a a›*) by (metis Int_emptyI (*‹(⋀x. ⟦x ∈ ?A; x ∈ ?B⟧ ⟹ False) ⟹ ?A ∩ ?B = {}›*) ord.lessThan_iff (*‹(?i ∈ (on UNIV with ?ls : {..⊏?k})) = ?ls ?i ?k›*) atLeast_iff (*‹(?i ∈ {?k≤⇩a..}) = (?k ≤⇩a ?i)›*) order_trans (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?z⟧ ⟹ ?x ≤⇩a ?z›*)) lemma atLeastatMost_empty_iff[simp]: "{a≤⇩a..≤⇩ab} = {} ⟷ (¬ a ≤⇩a b)" apply auto (*goal: ‹({a≤⇩a..≤⇩ab} = {}) = (¬ a ≤⇩a b)›*) by (blast intro: order_trans (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?z⟧ ⟹ ?x ≤⇩a ?z›*)) lemma atLeastatMost_empty_iff2[simp]: "{} = {a≤⇩a..≤⇩ab} ⟷ (¬ a ≤⇩a b)" apply auto (*goal: ‹({} = {a≤⇩a..≤⇩ab}) = (¬ a ≤⇩a b)›*) by (blast intro: order_trans (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?z⟧ ⟹ ?x ≤⇩a ?z›*)) lemma atLeastLessThan_empty[simp]: assumes "b ≤⇩a a" shows "{a≤⇩a..<⇩ab} = {}" unfolding interval_def (*goal: ‹{a≤⇩a..} ∩ {..<⇩ab} = {}›*) using assms (*‹b ≤⇩a a›*) less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*) by (blast intro: order_trans (*‹⟦(?x::'a) ≤⇩a (?y::'a); ?y ≤⇩a (?z::'a)⟧ ⟹ ?x ≤⇩a ?z›*)) lemma atLeastLessThan_empty_iff[simp]: "{a≤⇩a..<⇩ab} = {} ⟷ (¬ a <⇩a b)" unfolding interval_def (*goal: ‹({a≤⇩a..} ∩ {..<⇩ab} = {}) = (¬ a <⇩a b)›*) by (auto simp: le_less_trans (*‹⟦?x ≤⇩a ?y; ?y <⇩a ?z⟧ ⟹ ?x <⇩a ?z›*) ord.lessThan_iff (*‹(?i ∈ (on UNIV with ?ls : {..⊏?k})) = ?ls ?i ?k›*)) lemma atLeastLessThan_empty_iff2[simp]: "{} = {a≤⇩a..<⇩ab} ⟷ (¬ a <⇩a b)" unfolding interval_def (*goal: ‹({} = {a≤⇩a..} ∩ {..<⇩ab}) = (¬ a <⇩a b)›*) by (auto simp: le_less_trans (*‹⟦?x ≤⇩a ?y; ?y <⇩a ?z⟧ ⟹ ?x <⇩a ?z›*) ord.lessThan_iff (*‹(?i ∈ (on UNIV with ?ls : {..⊏?k})) = ?ls ?i ?k›*)) lemma greaterThanAtMost_empty[simp]: assumes "l ≤⇩a k" shows "{k<⇩a..≤⇩al} = {}" using assms (*‹l ≤⇩a k›*) atLeastLessThan_empty[OF assms] (*‹{k≤⇩a..<⇩al} = {}›*) unfolding greaterThanAtMost_eq_atLeastAtMost_diff atLeastLessThan_eq_atLeastAtMost_diff (*goal: ‹{k<⇩a..≤⇩al} = {}›*) using le_less_trans (*‹⟦?x ≤⇩a ?y; ?y <⇩a ?z⟧ ⟹ ?x <⇩a ?z›*) apply auto (*goal: ‹{k<⇩a..≤⇩al} = {}›*) by blast lemma greaterThanAtMost_empty_iff[simp]: "{k<⇩a..≤⇩al} = {} ⟷ ¬ k <⇩a l" by (auto simp: dual.le_less_trans (*‹⟦?y ≤⇩a ?x; ?z <⇩a ?y⟧ ⟹ ?z <⇩a ?x›*)) lemma greaterThanAtMost_empty_iff2[simp]: "{} = {k<⇩a..≤⇩al} ⟷ ¬ k <⇩a l" unfolding interval_def ray_def (*goal: ‹({} = {x ∈ UNIV. k <⇩a x} ∩ {x ∈ UNIV. x ≤⇩a l}) = (¬ k <⇩a l)›*) by (blast intro: less_le_trans (*‹⟦?x <⇩a ?y; ?y ≤⇩a ?z⟧ ⟹ ?x <⇩a ?z›*)) lemma greaterThanLessThan_empty[simp]: assumes "l ≤⇩a k" shows "{k<⇩a..<⇩al} = {}" using assms (*‹(l::'a) ≤⇩a (k::'a)›*) apply auto (*goal: ‹{k<⇩a..<⇩al} = {}›*) by (blast intro: le_less_trans (*‹⟦?x ≤⇩a ?y; ?y <⇩a ?z⟧ ⟹ ?x <⇩a ?z›*) asym (*‹⟦?a <⇩a ?b; ?b <⇩a ?a⟧ ⟹ False›*) equals0I (*‹(⋀y. y ∈ ?A ⟹ False) ⟹ ?A = {}›*)) lemma atLeastatMost_subset_iff[simp]: "{a≤⇩a..≤⇩ab} ≤ {c≤⇩a..≤⇩ad} ⟷ (¬ a ≤⇩a b) ∨ c ≤⇩a a ∧ b ≤⇩a d" apply auto (*goals: 1. ‹⋀x. ⟦¬ a ≤⇩a b; a ≤⇩a x; x ≤⇩a b⟧ ⟹ c ≤⇩a x› 2. ‹⋀x. ⟦¬ a ≤⇩a b; a ≤⇩a x; x ≤⇩a b⟧ ⟹ x ≤⇩a d› 3. ‹⋀x. ⟦c ≤⇩a a; b ≤⇩a d; a ≤⇩a x; x ≤⇩a b⟧ ⟹ c ≤⇩a x› 4. ‹⋀x. ⟦c ≤⇩a a; b ≤⇩a d; a ≤⇩a x; x ≤⇩a b⟧ ⟹ x ≤⇩a d› discuss goal 1*) apply (blast intro: order_trans (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?z⟧ ⟹ ?x ≤⇩a ?z›*)) (*discuss goal 2*) apply (blast intro: order_trans (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?z⟧ ⟹ ?x ≤⇩a ?z›*)) (*discuss goal 3*) apply (blast intro: order_trans (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?z⟧ ⟹ ?x ≤⇩a ?z›*)) (*discuss goal 4*) apply (blast intro: order_trans (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?z⟧ ⟹ ?x ≤⇩a ?z›*)) (*proven 4 subgoals*) . lemma atLeastatMost_psubset_iff: "{a≤⇩a..≤⇩ab} < {c≤⇩a..≤⇩ad} ⟷ ((¬ a ≤⇩a b) ∨ c ≤⇩a a ∧ b ≤⇩a d ∧ (c <⇩a a ∨ b <⇩a d)) ∧ c ≤⇩a d" apply (simp add: psubset_eq (*‹(?A ⊂ ?B) = (?A ⊆ ?B ∧ ?A ≠ ?B)›*) set_eq_iff (*‹(?A = ?B) = (∀x. (x ∈ ?A) = (x ∈ ?B))›*) less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*)) (*goal: ‹({a::'a≤⇩a..≤⇩ab::'a} ⊂ {c::'a≤⇩a..≤⇩ad::'a}) = ((¬ a ≤⇩a b ∨ c ≤⇩a a ∧ b ≤⇩a d ∧ (c <⇩a a ∨ b <⇩a d)) ∧ c ≤⇩a d)›*) by (blast intro: order_trans (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?z⟧ ⟹ ?x ≤⇩a ?z›*)) lemma Icc_subset_Ici_iff[simp]: "{l≤⇩a..≤⇩ah} ⊆ {l'≤⇩a..} = (¬ l ≤⇩a h ∨ l ≥⇩a l')" by (auto simp: subset_eq (*‹((?A::?'a::type set) ⊆ (?B::?'a::type set)) = (∀x::?'a::type∈?A. x ∈ ?B)›*) intro: order_trans (*‹⟦(?x::'a::type) ≤⇩a (?y::'a::type); ?y ≤⇩a (?z::'a::type)⟧ ⟹ ?x ≤⇩a ?z›*)) lemma Icc_subset_Iic_iff[simp]: "{l≤⇩a..≤⇩ah} ⊆ {..≤⇩ah'} = (¬ l ≤⇩a h ∨ h ≤⇩a h')" unfolding interval_def ray_def (*goal: ‹({x ∈ UNIV. l ≤⇩a x} ∩ {x ∈ UNIV. x ≤⇩a h} ⊆ {x ∈ UNIV. x ≤⇩a h'}) = (¬ l ≤⇩a h ∨ h ≤⇩a h')›*) by (blast intro: order_trans (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?z⟧ ⟹ ?x ≤⇩a ?z›*)) lemma not_Ici_eq_empty[simp]: "{l≤⇩a..} ≠ {}" by (auto simp: set_eq_iff (*‹(?A = ?B) = (∀x. (x ∈ ?A) = (x ∈ ?B))›*)) lemmas not_empty_eq_Ici_eq_empty[simp] = not_Ici_eq_empty[symmetric] lemma Iio_Int_singleton: "{..<⇩ak} ∩ {x} = (if x <⇩a k then {x} else {})" by simp lemma ivl_disj_int_one: "{..≤⇩al} ∩ {l<⇩a..<⇩au} = {}" "{..<⇩al} ∩ {l≤⇩a..<⇩au} = {}" "{..≤⇩al} ∩ {l<⇩a..≤⇩au} = {}" "{..<⇩al} ∩ {l≤⇩a..≤⇩au} = {}" "{l<⇩a..≤⇩au} ∩ {u<⇩a..} = {}" "{l<⇩a..<⇩au} ∩ {u≤⇩a..} = {}" "{l≤⇩a..≤⇩au} ∩ {u<⇩a..} = {}" "{l≤⇩a..<⇩au} ∩ {u≤⇩a..} = {}" using lessThan_iff (*‹(?i ∈ {..<⇩a?k}) = (?i <⇩a ?k)›*) dual.lessThan_iff (*‹(?i ∈ {?k<⇩a..}) = (?k <⇩a ?i)›*) apply - (*goals: 1. ‹⟦⋀i k. (i ∈ {..<⇩ak}) = (i <⇩a k); ⋀i k. (i ∈ {k<⇩a..}) = (k <⇩a i)⟧ ⟹ {..≤⇩al} ∩ {l<⇩a..<⇩au} = {}› 2. ‹⟦⋀i k. (i ∈ {..<⇩ak}) = (i <⇩a k); ⋀i k. (i ∈ {k<⇩a..}) = (k <⇩a i)⟧ ⟹ {..<⇩al} ∩ {l≤⇩a..<⇩au} = {}› 3. ‹⟦⋀i k. (i ∈ {..<⇩ak}) = (i <⇩a k); ⋀i k. (i ∈ {k<⇩a..}) = (k <⇩a i)⟧ ⟹ {..≤⇩al} ∩ {l<⇩a..≤⇩au} = {}› 4. ‹⟦⋀i k. (i ∈ {..<⇩ak}) = (i <⇩a k); ⋀i k. (i ∈ {k<⇩a..}) = (k <⇩a i)⟧ ⟹ {..<⇩al} ∩ {l≤⇩a..≤⇩au} = {}› 5. ‹⟦⋀i k. (i ∈ {..<⇩ak}) = (i <⇩a k); ⋀i k. (i ∈ {k<⇩a..}) = (k <⇩a i)⟧ ⟹ {l<⇩a..≤⇩au} ∩ {u<⇩a..} = {}› 6. ‹⟦⋀i k. (i ∈ {..<⇩ak}) = (i <⇩a k); ⋀i k. (i ∈ {k<⇩a..}) = (k <⇩a i)⟧ ⟹ {l<⇩a..<⇩au} ∩ {u≤⇩a..} = {}› 7. ‹⟦⋀i k. (i ∈ {..<⇩ak}) = (i <⇩a k); ⋀i k. (i ∈ {k<⇩a..}) = (k <⇩a i)⟧ ⟹ {l≤⇩a..≤⇩au} ∩ {u<⇩a..} = {}› 8. ‹⟦⋀i k. (i ∈ {..<⇩ak}) = (i <⇩a k); ⋀i k. (i ∈ {k<⇩a..}) = (k <⇩a i)⟧ ⟹ {l≤⇩a..<⇩au} ∩ {u≤⇩a..} = {}› discuss goal 1*) apply ((auto simp: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*))[1]) (*discuss goal 2*) apply ((auto simp: less_le_not_le (*‹((?x::'a::type) <⇩a (?y::'a::type)) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*))[1]) (*discuss goal 3*) apply ((auto simp: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*))[1]) (*discuss goal 4*) apply ((auto simp: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*))[1]) (*discuss goal 5*) apply ((auto simp: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*))[1]) (*discuss goal 6*) apply ((auto simp: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*))[1]) (*discuss goal 7*) apply ((auto simp: less_le_not_le (*‹((?x::'a) <⇩a (?y::'a)) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*))[1]) (*discuss goal 8*) apply ((auto simp: less_le_not_le (*‹((?x::'a) <⇩a (?y::'a)) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*))[1]) (*proven 8 subgoals*) . lemma ivl_disj_int_two: "{l<⇩a..<⇩am} ∩ {m≤⇩a..<⇩au} = {}" "{l<⇩a..≤⇩am} ∩ {m<⇩a..<⇩au} = {}" "{l≤⇩a..<⇩am} ∩ {m≤⇩a..<⇩au} = {}" "{l≤⇩a..≤⇩am} ∩ {m<⇩a..<⇩au} = {}" "{l<⇩a..<⇩am} ∩ {m≤⇩a..≤⇩au} = {}" "{l<⇩a..≤⇩am} ∩ {m<⇩a..≤⇩au} = {}" "{l≤⇩a..<⇩am} ∩ {m≤⇩a..≤⇩au} = {}" "{l≤⇩a..≤⇩am} ∩ {m<⇩a..≤⇩au} = {}" using lessThan_iff (*‹(?i ∈ {..<⇩a?k}) = (?i <⇩a ?k)›*) (*goals: 1. ‹{l<⇩a..<⇩am} ∩ {m≤⇩a..<⇩au} = {}› 2. ‹{l<⇩a..≤⇩am} ∩ {m<⇩a..<⇩au} = {}› 3. ‹{l≤⇩a..<⇩am} ∩ {m≤⇩a..<⇩au} = {}› 4. ‹{l≤⇩a..≤⇩am} ∩ {m<⇩a..<⇩au} = {}› 5. ‹{l<⇩a..<⇩am} ∩ {m≤⇩a..≤⇩au} = {}› 6. ‹{l<⇩a..≤⇩am} ∩ {m<⇩a..≤⇩au} = {}› 7. ‹{l≤⇩a..<⇩am} ∩ {m≤⇩a..≤⇩au} = {}› 8. ‹{l≤⇩a..≤⇩am} ∩ {m<⇩a..≤⇩au} = {}› discuss goal 1*) apply ((auto simp: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*))[1]) (*discuss goal 2*) apply ((auto simp: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*))[1]) (*discuss goal 3*) apply ((auto simp: less_le_not_le (*‹((?x::'a) <⇩a (?y::'a)) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*))[1]) (*discuss goal 4*) apply ((auto simp: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*))[1]) (*discuss goal 5*) apply ((auto simp: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*))[1]) (*discuss goal 6*) apply ((auto simp: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*))[1]) (*discuss goal 7*) apply ((auto simp: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*))[1]) (*discuss goal 8*) apply ((auto simp: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*))[1]) (*proven 8 subgoals*) . end context order begin interpretation ord_syntax . interpretation order_dual le ls by (rule order_dual.intro[OF order_axioms] (*‹order_dual (≤⇩a) (<⇩a)›*)) lemma atMost_Int_atLeast: "{..≤⇩an} ∩ {n≤⇩a..} = {n}" unfolding ray_def (*goal: ‹{x::'a ∈ UNIV. x ≤⇩a (n::'a)} ∩ {x::'a ∈ UNIV. n ≤⇩a x} = {n}›*) by (auto simp: eq_iff (*‹(?x = ?y) = (?x ≤⇩a ?y ∧ ?y ≤⇩a ?x)›*)) lemma atLeast_eq_iff[iff]: "({x≤⇩a..} = {y≤⇩a..}) = (x = y)" unfolding ray_def (*goal: ‹({xa::'a::type ∈ UNIV. (x::'a::type) ≤⇩a xa} = {x::'a::type ∈ UNIV. (y::'a::type) ≤⇩a x}) = (x = y)›*) using antisym (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?x⟧ ⟹ ?x = ?y›*) by auto lemma atLeastLessThan_eq_atLeastAtMost_diff: "{a≤⇩a..<⇩ab} = {a≤⇩a..≤⇩ab} - {b}" unfolding interval_def ray_def (*goal: ‹{x::'a::type ∈ UNIV. (a::'a::type) ≤⇩a x} ∩ {x::'a::type ∈ UNIV. x <⇩a (b::'a::type)} = {x::'a::type ∈ UNIV. a ≤⇩a x} ∩ {x::'a::type ∈ UNIV. x ≤⇩a b} - {b}›*) by (auto simp: less_imp_le (*‹?x <⇩a ?y ⟹ ?x ≤⇩a ?y›*) le_less (*‹(?x ≤⇩a ?y) = (?x <⇩a ?y ∨ ?x = ?y)›*)) lemma greaterThanAtMost_eq_atLeastAtMost_diff: "{a<⇩a..≤⇩ab} = {a≤⇩a..≤⇩ab} - {a}" unfolding interval_def ray_def (*goal: ‹{x ∈ UNIV. a <⇩a x} ∩ {x ∈ UNIV. x ≤⇩a b} = {x ∈ UNIV. a ≤⇩a x} ∩ {x ∈ UNIV. x ≤⇩a b} - {a}›*) by (auto simp: less_imp_le (*‹?x <⇩a ?y ⟹ ?x ≤⇩a ?y›*) le_less (*‹(?x ≤⇩a ?y) = (?x <⇩a ?y ∨ ?x = ?y)›*)) lemma atLeastAtMost_singleton[simp]: "{a≤⇩a..≤⇩aa} = {a}" using atMost_Int_atLeast (*‹{..≤⇩a?n::'a} ∩ {?n≤⇩a..} = {?n}›*) by (fastforce simp: ray_def (*‹on ?U with ?op : {..⊏?u} ≡ {x ∈ ?U. ?op x ?u}›*)) lemma atLeastAtMost_singleton': assumes "a = b" shows "{a≤⇩a..≤⇩ab} = {a}" using assms (*‹a = b›*) by simp lemma Icc_eq_Icc[simp]: "{l≤⇩a..≤⇩ah} = {l'≤⇩a..≤⇩ah'} = (l = l' ∧ h = h' ∨ ¬ l ≤⇩a h ∧ ¬ l' ≤⇩a h')" apply (rule iffI (*‹⟦?P::bool ⟹ ?Q::bool; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*)) (*goal: ‹({l≤⇩a..≤⇩ah} = {l'≤⇩a..≤⇩ah'}) = (l = l' ∧ h = h' ∨ ¬ l ≤⇩a h ∧ ¬ l' ≤⇩a h')›*) subgoal for by (metis antisym (*‹⟦(?x::'a) ≤⇩a (?y::'a); ?y ≤⇩a ?x⟧ ⟹ ?x = ?y›*) atLeastatMost_subset_iff (*‹({?a::'a≤⇩a..≤⇩a?b::'a} ⊆ {?c::'a≤⇩a..≤⇩a?d::'a}) = (¬ ?a ≤⇩a ?b ∨ ?c ≤⇩a ?a ∧ ?b ≤⇩a ?d)›*) eq_refl (*‹(?x::'a) = (?y::'a) ⟹ ?x ≤⇩a ?y›*)) subgoal for using atLeastatMost_empty_iff (*‹({?a≤⇩a..≤⇩a?b} = {}) = (¬ ?a ≤⇩a ?b)›*) by blast . lemma atLeastAtMost_singleton_iff[simp]: "{a≤⇩a..≤⇩ab} = {c} ⟷ a = b ∧ b = c" proof (standard) (*goals: 1. ‹{a::'a::type≤⇩a..≤⇩ab::'a::type} = {c::'a::type} ⟹ a = b ∧ b = c› 2. ‹(a::'a::type) = (b::'a::type) ∧ b = (c::'a::type) ⟹ {a≤⇩a..≤⇩ab} = {c}›*) assume "{a≤⇩a..≤⇩ab} = {c}" (*‹{a::'a≤⇩a..≤⇩ab::'a} = {c::'a}›*) hence "*": "¬ (¬ a ≤⇩a b)" unfolding atLeastatMost_empty_iff[symmetric] (*goal: ‹{a≤⇩a..≤⇩ab} ≠ {}›*) by simp with ‹{a≤⇩a..≤⇩ab} = {c}› (*‹{a::'a≤⇩a..≤⇩ab::'a} = {c::'a}›*) have "c ≤⇩a a ∧ b ≤⇩a c" by auto with "*" (*‹¬ ¬ (a::'a) ≤⇩a (b::'a)›*) show "a = b ∧ b = c" by (auto intro: antisym (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?x⟧ ⟹ ?x = ?y›*) order_trans (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?z⟧ ⟹ ?x ≤⇩a ?z›*)) qed (simp) (*solved the remaining goal: ‹a = b ∧ b = c ⟹ {a≤⇩a..≤⇩ab} = {c}›*) end context order_extremum begin interpretation ord_syntax . lemma atMost_eq_UNIV_iff: "{..≤⇩ax} = UNIV ⟷ x = extremum" by (metis ord.lessThan_iff (*‹(?i ∈ (on UNIV with ?ls : {..⊏?k})) = ?ls ?i ?k›*) eq_iff (*‹(?x = ?y) = (?x ≤⇩a ?y ∧ ?y ≤⇩a ?x)›*) UNIV_I (*‹?x ∈ UNIV›*) UNIV_eq_I (*‹(⋀x. x ∈ ?A) ⟹ UNIV = ?A›*) extremum (*‹?a ≤⇩a extremum›*)) end context no_extremum begin interpretation ord_syntax . interpretation order_dual le ls by (rule order_dual.intro[OF order_axioms] (*‹order_dual (≤⇩a) (<⇩a)›*)) lemma not_UNIV_le_Icc[simp]: "¬ UNIV ⊆ {l≤⇩a..≤⇩ah}" using gt_ex[of h] (*‹∃y::'a::type. (h::'a::type) <⇩a y›*) by (auto simp: subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*) less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*)) lemma not_UNIV_le_Iic[simp]: "¬ UNIV ⊆ {..≤⇩ah}" using gt_ex[of h] (*‹∃y. h <⇩a y›*) by (auto simp: less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*)) lemma not_Ici_le_Icc[simp]: "¬ {l≤⇩a..} ⊆ {l'≤⇩a..≤⇩ah'}" using gt_ex[of h'] (*‹∃y::'a::type. (h'::'a::type) <⇩a y›*) apply (auto simp: subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*) less_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ?x ≠ ?y)›*)) (*goal: ‹¬ {l≤⇩a..} ⊆ {l'≤⇩a..≤⇩ah'}›*) by (blast dest: antisym_conv (*‹?y ≤⇩a ?x ⟹ (?x ≤⇩a ?y) = (?x = ?y)›*) intro: order_trans (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?z⟧ ⟹ ?x ≤⇩a ?z›*)) lemma not_Ici_le_Iic[simp]: "¬ {l≤⇩a..} ⊆ {..≤⇩ah'}" proof (standard) (*goal: ‹{l≤⇩a..} ⊆ {..≤⇩ah'} ⟹ False›*) assume "{l≤⇩a..} ⊆ {..≤⇩ah'}" (*‹{l::'a≤⇩a..} ⊆ {..≤⇩ah'::'a}›*) then have x: "l ≤⇩a x ⟹ x ≤⇩a h'" for x by auto from gt_ex (*‹∃y. ?x <⇩a y›*) obtain x where "h' <⇩a x" (*goal: ‹(⋀x. h' <⇩a x ⟹ thesis) ⟹ thesis›*) by auto show False proof (cases ‹l ≤⇩a x›) (*goals: 1. ‹l ≤⇩a x ⟹ False› 2. ‹¬ l ≤⇩a x ⟹ False›*) case True (*‹l ≤⇩a x›*) show "?thesis" (*goal: ‹False›*) using x[OF True] (*‹x ≤⇩a h'›*) less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*) by (force simp: ‹h' <⇩a x›) next (*goal: ‹¬ (l::'a) ≤⇩a (x::'a) ⟹ False›*) case False (*‹¬ (l::'a) ≤⇩a (x::'a)›*) obtain y where "x ≤⇩a y" and "y <⇩a l" (*goal: ‹(⋀y. ⟦x ≤⇩a y; y <⇩a l⟧ ⟹ thesis) ⟹ thesis›*) using ‹h' <⇩a x› (*‹(h'::'a) <⇩a (x::'a)›*) dual.less_le_trans (*‹⟦?y <⇩a ?x; ?z ≤⇩a ?y⟧ ⟹ ?z <⇩a ?x›*) by (blast intro: x (*‹l ≤⇩a ?x ⟹ ?x ≤⇩a h'›*) less_imp_le (*‹?x <⇩a ?y ⟹ ?x ≤⇩a ?y›*)) then have "x <⇩a l" by (rule le_less_trans (*‹⟦(?x::'a::type) ≤⇩a (?y::'a::type); ?y <⇩a (?z::'a::type)⟧ ⟹ ?x <⇩a ?z›*)) then show "?thesis" (*goal: ‹False›*) using ‹h' <⇩a x› (*‹h' <⇩a x›*) less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*) by (blast intro: x (*‹l ≤⇩a ?x ⟹ ?x ≤⇩a h'›*) dual.less_trans (*‹⟦?y <⇩a ?x; ?z <⇩a ?y⟧ ⟹ ?z <⇩a ?x›*)) qed qed lemma not_UNIV_eq_Icc[simp]: "UNIV ≠ {l'≤⇩a..≤⇩ah'}" using gt_ex (*‹∃y::'a. (?x::'a) <⇩a y›*) by (auto simp: set_eq_iff (*‹(?A = ?B) = (∀x. (x ∈ ?A) = (x ∈ ?B))›*) less_le_not_le (*‹(?x <⇩a ?y) = (?x ≤⇩a ?y ∧ ¬ ?y ≤⇩a ?x)›*)) lemmas not_Icc_eq_UNIV[simp] = not_UNIV_eq_Icc[symmetric] lemma not_UNIV_eq_Iic[simp]: "UNIV ≠ {..≤⇩ah'}" using gt_ex[of h'] (*‹∃y. h' <⇩a y›*) not_UNIV_le_Iic (*‹¬ UNIV ⊆ {..≤⇩a?h}›*) by blast lemmas not_Iic_eq_UNIV[simp] = not_UNIV_eq_Iic[symmetric] lemma not_Icc_eq_Ici[simp]: "{l≤⇩a..≤⇩ah} ≠ {l'≤⇩a..}" using not_Ici_le_Icc (*‹¬ {?l≤⇩a..} ⊆ {?l'≤⇩a..≤⇩a?h'}›*) by blast lemmas not_Ici_eq_Icc[simp] = not_Icc_eq_Ici[symmetric] lemma not_Iic_eq_Ici[simp]: "{..≤⇩ah} ≠ {l'≤⇩a..}" using not_Ici_le_Iic[of l' h] (*‹¬ {l'≤⇩a..} ⊆ {..≤⇩ah}›*) by blast lemmas not_Ici_eq_Iic[simp] = not_Iic_eq_Ici[symmetric] lemma greaterThan_non_empty[simp]: "{x<⇩a..} ≠ {}" using gt_ex[of x] (*‹∃y. x <⇩a y›*) unfolding ray_def (*goal: ‹{xa::'a::type ∈ UNIV. (x::'a::type) <⇩a xa} ≠ {}›*) by simp end context order begin interpretation ord_syntax . interpretation order_pair le ls le ls by standard interpretation ord_pair_syntax le ls le ls . lemma mono_image_least: assumes f_mono: "mono⇩a⇩b f" and f_img: "f ` {m≤⇩a..<⇩an} = {m'≤⇩a..<⇩an'}" and "m <⇩a n" shows "f m = m'" proof (-) (*goal: ‹(f::'a ⇒ 'a) (m::'a) = (m'::'a)›*) from f_img (*‹f ` {m≤⇩a..<⇩an} = {m'≤⇩a..<⇩an'}›*) have "{m'≤⇩a..<⇩an'} ≠ {}" by (force simp: assms( (*‹m <⇩a n›*) 3)) with f_img (*‹f ` {m≤⇩a..<⇩an} = {m'≤⇩a..<⇩an'}›*) have "m' ∈ f ` {m≤⇩a..<⇩an}" by auto then obtain k where "f k = m'" "m ≤⇩a k" (*goal: ‹(⋀k. ⟦f k = m'; m ≤⇩a k⟧ ⟹ thesis) ⟹ thesis›*) by auto moreover have "m' ≤⇩a f m" unfolding interval_def (*goal: ‹m' ≤⇩a f m›*) using f_img (*‹f ` {m≤⇩a..<⇩an} = {m'≤⇩a..<⇩an'}›*) by (auto simp: assms( (*‹m <⇩a n›*) 3)) ultimately show "f m = m'" using f_mono (*‹mono⇩b⇩a (f::'a ⇒ 'a)›*) by (auto dest: monoD (*‹⟦mono⇩b⇩a ?f; ?x ≤⇩a ?y⟧ ⟹ ?f ?x ≤⇩a ?f ?y›*) intro: antisym (*‹⟦?x ≤⇩a ?y; ?y ≤⇩a ?x⟧ ⟹ ?x = ?y›*)) qed end subsection‹Bounded sets› definition bdd :: "['a set, ['a, 'a] ⇒ bool, 'a set] ⇒ bool" (‹(on _ with _ : «bdd» _)› [1000, 1000, 1000] 10) where "bdd U op A ⟷ (∃M∈U. ∀x ∈ A. op x M)" ctr parametricity in bdd_def context ord_syntax begin abbreviation bdd_above where "bdd_above ≡ bdd UNIV (≤⇩a)" abbreviation bdd_below where "bdd_below ≡ bdd UNIV (≥⇩a)" end context preorder begin interpretation ord_syntax . interpretation preorder_dual by standard lemma bdd_aboveI[intro]: assumes "⋀x. x ∈ A ⟹ x ≤⇩a M" shows "bdd_above A" using assms (*‹?x ∈ A ⟹ ?x ≤⇩a M›*) unfolding bdd_def (*goal: ‹∃M∈UNIV. ∀x∈A. x ≤⇩a M›*) by auto lemma bdd_belowI[intro]: assumes "⋀x. x ∈ A ⟹ m ≤⇩a x" shows "bdd_below A" using assms (*‹?x ∈ A ⟹ m ≤⇩a ?x›*) unfolding bdd_def (*goal: ‹∃M::'a::type∈UNIV. ∀x::'a::type∈A::'a::type set. M ≤⇩a x›*) by auto lemma bdd_aboveI2: assumes "⋀x. x ∈ A ⟹ f x ≤⇩a M" shows "bdd_above (f ` A)" using assms (*‹(?x::'b) ∈ (A::'b set) ⟹ (f::'b ⇒ 'a) ?x ≤⇩a (M::'a)›*) by force lemma bdd_belowI2: assumes "⋀x. x ∈ A ⟹ m ≤⇩a f x" shows "bdd_below (f ` A)" using assms (*‹(?x::'b) ∈ (A::'b set) ⟹ (m::'a) ≤⇩a (f::'b ⇒ 'a) ?x›*) by force lemma bdd_above_empty[simp, intro]: "bdd_above {}" unfolding bdd_above_def (*goal: ‹local.bdd_above {}›*) by auto lemma bdd_below_empty[simp, intro]: "bdd_below {}" unfolding bdd_below_def (*goal: ‹local.bdd_below {}›*) by auto lemma bdd_above_mono: assumes "bdd_above B" and "A ⊆ B" shows "bdd_above A" using assms (*‹local.bdd_above B› ‹(A::'a set) ⊆ (B::'a set)›*) unfolding bdd_def (*goal: ‹∃M∈UNIV. ∀x∈A. x ≤⇩a M›*) by auto lemma bdd_below_mono: assumes "bdd_below B" and "A ⊆ B" shows "bdd_below A" using assms (*‹local.bdd_below B› ‹A ⊆ B›*) unfolding bdd_def (*goal: ‹∃M::'a∈UNIV. ∀x::'a∈A::'a set. M ≤⇩a x›*) by auto lemma bdd_above_Int1[simp]: assumes "bdd_above A" shows "bdd_above (A ∩ B)" using assms (*‹local.bdd_above A›*) by (auto simp: bdd_above_mono (*‹⟦local.bdd_above ?B; ?A ⊆ ?B⟧ ⟹ local.bdd_above ?A›*)) lemma bdd_above_Int2[simp]: assumes "bdd_above B" shows "bdd_above (A ∩ B)" using assms (*‹local.bdd_above B›*) by (auto simp: bdd_above_mono (*‹⟦local.bdd_above ?B; ?A ⊆ ?B⟧ ⟹ local.bdd_above ?A›*)) lemma bdd_below_Int1[simp]: assumes "bdd_below A" shows "bdd_below (A ∩ B)" using assms (*‹local.bdd_below A›*) by (auto simp: bdd_below_mono (*‹⟦local.bdd_below (?B::'a::type set); (?A::'a::type set) ⊆ ?B⟧ ⟹ local.bdd_below ?A›*)) lemma bdd_below_Int2[simp]: assumes "bdd_below B" shows "bdd_below (A ∩ B)" using assms (*‹local.bdd_below B›*) by (auto simp: bdd_below_mono (*‹⟦local.bdd_below ?B; ?A ⊆ ?B⟧ ⟹ local.bdd_below ?A›*)) lemma bdd_above_Ioo[simp, intro]: "bdd_above {a<⇩a..<⇩ab}" by (auto intro!: less_imp_le (*‹?x <⇩a ?y ⟹ ?x ≤⇩a ?y›*)) lemma bdd_above_Ico[simp, intro]: "bdd_above {a≤⇩a..<⇩ab}" by (auto intro!: less_imp_le (*‹(?x::'a) <⇩a (?y::'a) ⟹ ?x ≤⇩a ?y›*)) lemma bdd_above_Iio[simp, intro]: "bdd_above {..<⇩ab}" by (auto intro: less_imp_le (*‹?x <⇩a ?y ⟹ ?x ≤⇩a ?y›*)) lemma bdd_above_Ioc[simp, intro]: "bdd_above {a<⇩a..≤⇩ab}" by auto lemma bdd_above_Icc[simp, intro]: "bdd_above {a≤⇩a..≤⇩ab}" by (auto intro: less_imp_le (*‹?x <⇩a ?y ⟹ ?x ≤⇩a ?y›*)) lemma bdd_above_Iic[simp, intro]: "bdd_above {..≤⇩ab}" by (auto intro: less_imp_le (*‹?x <⇩a ?y ⟹ ?x ≤⇩a ?y›*)) lemma bdd_below_Ioo[simp, intro]: "bdd_below {a<⇩a..<⇩ab}" by (auto intro!: less_imp_le (*‹?x <⇩a ?y ⟹ ?x ≤⇩a ?y›*)) lemma bdd_below_Ioc[simp, intro]: "bdd_below {a<⇩a..≤⇩ab}" by (auto intro!: less_imp_le (*‹(?x::'a::type) <⇩a (?y::'a::type) ⟹ ?x ≤⇩a ?y›*)) lemma bdd_below_Ioi[simp, intro]: "bdd_below {a<⇩a..}" by (auto intro: less_imp_le (*‹?x <⇩a ?y ⟹ ?x ≤⇩a ?y›*)) lemma bdd_below_Ico[simp, intro]: "bdd_below {a≤⇩a..<⇩ab}" by auto lemma bdd_below_Icc[simp, intro]: "bdd_below {a≤⇩a..≤⇩ab}" by auto lemma bdd_below_Ici[simp, intro]: "bdd_below {a≤⇩a..}" by (auto intro: less_imp_le (*‹?x <⇩a ?y ⟹ ?x ≤⇩a ?y›*)) end context order_pair begin interpretation ord_pair_syntax . lemma bdd_above_image_mono: assumes "mono⇩a⇩b f" and "ord⇩a.bdd_above A" shows "ord⇩b.bdd_above (f ` A)" using assms (*‹mono⇩a⇩b f› ‹ord⇩a.bdd_above A›*) by (auto simp: bdd_def (*‹(on ?U with ?op : «bdd» ?A) = (∃M∈?U. ∀x∈?A. ?op x M)›*) mono_def (*‹on ?U⇩a with ?op₁ ?op₂ : «mono» ?f ≡ ∀x∈?U⇩a. ∀y∈?U⇩a. ?op₁ x y ⟶ ?op₂ (?f x) (?f y)›*)) lemma bdd_below_image_mono: assumes "mono⇩a⇩b f" and "ord⇩a.bdd_below A" shows "ord⇩b.bdd_below (f ` A)" using assms (*‹mono⇩a⇩b f› ‹ord⇩a.bdd_below (A::'a set)›*) by (auto simp: bdd_def (*‹(on ?U with ?op : «bdd» ?A) = (∃M∈?U. ∀x∈?A. ?op x M)›*) mono_def (*‹on ?U⇩a with ?op₁ ?op₂ : «mono» ?f ≡ ∀x∈?U⇩a. ∀y∈?U⇩a. ?op₁ x y ⟶ ?op₂ (?f x) (?f y)›*)) lemma bdd_above_image_antimono: assumes "antimono⇩a⇩b f" and "ord⇩a.bdd_below A" shows "ord⇩b.bdd_above (f ` A)" using assms (*‹antimono⇩a⇩b f› ‹ord⇩a.bdd_below A›*) by (auto simp: bdd_def (*‹(on ?U with ?op : «bdd» ?A) = (∃M∈?U. ∀x∈?A. ?op x M)›*) mono_def (*‹on ?U⇩a with ?op₁ ?op₂ : «mono» ?f ≡ ∀x∈?U⇩a. ∀y∈?U⇩a. ?op₁ x y ⟶ ?op₂ (?f x) (?f y)›*)) lemma bdd_below_image_antimono: assumes "antimono⇩a⇩b f" and "ord⇩a.bdd_above A" shows "ord⇩b.bdd_below (f ` A)" using assms (*‹antimono⇩a⇩b f› ‹ord⇩a.bdd_above A›*) by (auto simp: bdd_def (*‹(on ?U with ?op : «bdd» ?A) = (∃M∈?U. ∀x∈?A. ?op x M)›*) mono_def (*‹on ?U⇩a with ?op₁ ?op₂ : «mono» ?f ≡ ∀x∈?U⇩a. ∀y∈?U⇩a. ?op₁ x y ⟶ ?op₂ (?f x) (?f y)›*)) end context order_extremum begin interpretation ord_syntax . interpretation order_dual by standard lemma bdd_above_top[simp, intro!]: "bdd_above A" apply (rule bdd_aboveI[of _ extremum] (*‹(⋀x. x ∈ ?A ⟹ x ≤⇩a extremum) ⟹ local.bdd_above ?A›*)) (*goal: ‹local.bdd_above (A::'a set)›*) by simp end text‹\newpage› end
{ "path": "afp-2025-02-12/thys/Types_To_Sets_Extension/Examples/TTS_Foundations/Orders/Type_Simple_Orders.thy", "repo": "afp-2025-02-12", "sha": "0cba0b60f48d3461fb80164ed31a18784d9e84f277efc145fb4bb8b80db7f112" }
(* Title: AnalyticTestFunction.thy Authors: Filip Smola and Jacques D. Fleuriot, University of Edinburgh, 2019-2021 *) theory AnalyticTestFunction imports HyperdualFunctionExtension "HOL-Decision_Procs.Approximation" begin subsection‹Analytic Test Function› text‹ We investigate the analytic test function used by Fike and Alonso in their 2011 paper~\<^cite>‹"fike_alonso-2011"› as a relatively non-trivial example. The function is defined as: @{term "λx. exp x / (sqrt (sin x ^ 3 + cos x ^ 3))"}. › definition fa_test :: "real ⇒ real" where "fa_test x = exp x / (sqrt (sin x ^ 3 + cos x ^ 3))" text‹ We define the same composition of functions but using the relevant hyperdual versions. Note that we implicitly use the facts that hyperdual extensions of plus, times and inverse are the same operations on hyperduals. › definition hyp_fa_test :: "real hyperdual ⇒ real hyperdual" where "hyp_fa_test x = ((*h* exp) x) / ((*h* sqrt) (((*h* sin) x) ^ 3 + ((*h* cos) x) ^ 3))" text‹We prove lemmas useful to show when this function is well defined.› lemma sin_cube_plus_cos_cube: "sin x ^ 3 + cos x ^ 3 = 1/2 * (sin x + cos x) * (2 - sin (2 * x))" for x :: "'a::{real_normed_field,banach}" proof (-) (*goal: ‹sin x ^ 3 + cos x ^ 3 = 1 / 2 * (sin x + cos x) * (2 - sin (2 * x))›*) have "sin x ^ 3 + cos x ^ 3 = (sin x + cos x) * (cos x ^ 2 - cos x * sin x + sin x ^ 2)" by (smt (z3) add.commute (*‹(?a::?'a) + (?b::?'a) = ?b + ?a›*) combine_common_factor (*‹(?a::?'a) * (?e::?'a) + ((?b::?'a) * ?e + (?c::?'a)) = (?a + ?b) * ?e + ?c›*) diff_add_cancel (*‹(?a::?'a) - (?b::?'a) + ?b = ?a›*) distrib_left (*‹(?a::?'a) * ((?b::?'a) + (?c::?'a)) = ?a * ?b + ?a * ?c›*) mult.commute (*‹(?a::?'a) * (?b::?'a) = ?b * ?a›*) mult.left_commute (*‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)›*) power2_eq_square (*‹(?a::?'a)² = ?a * ?a›*) power3_eq_cube (*‹(?a::?'a) ^ (3::nat) = ?a * ?a * ?a›*)) also (*calculation: ‹sin (x::'a) ^ (3::nat) + cos x ^ (3::nat) = (sin x + cos x) * ((cos x)² - cos x * sin x + (sin x)²)›*) have "… = (sin x + cos x) * (1 - cos x * sin x)" by simp finally (*calculation: ‹sin (x::'a) ^ (3::nat) + cos x ^ (3::nat) = (sin x + cos x) * ((1::'a) - cos x * sin x)›*) show "?thesis" (*goal: ‹sin x ^ 3 + cos x ^ 3 = 1 / 2 * (sin x + cos x) * (2 - sin (2 * x))›*) by (smt (z3) mult.commute (*‹?a * ?b = ?b * ?a›*) mult.left_neutral (*‹1 * ?a = ?a›*) mult_2 (*‹2 * ?z = ?z + ?z›*) nonzero_mult_div_cancel_left (*‹?a ≠ 0 ⟹ ?a * ?b div ?a = ?b›*) right_diff_distrib' (*‹?a * (?b - ?c) = ?a * ?b - ?a * ?c›*) sin_add (*‹sin (?x + ?y) = sin ?x * cos ?y + cos ?x * sin ?y›*) times_divide_eq_left (*‹?b / ?c * ?a = ?b * ?a / ?c›*) zero_neq_numeral (*‹0 ≠ numeral ?n›*)) qed lemma sin_cube_plus_cos_cube_gt_zero_iff: "(sin x ^ 3 + cos x ^ 3 > 0) = (sin x + cos x > 0)" for x ::real by (smt (verit, best) cos_zero (*‹cos 0 = 1›*) power3_eq_cube (*‹?a ^ 3 = ?a * ?a * ?a›*) power_zero_numeral (*‹0 ^ numeral ?k = 0›*) sin_cube_plus_cos_cube (*‹sin ?x ^ 3 + cos ?x ^ 3 = 1 / 2 * (sin ?x + cos ?x) * (2 - sin (2 * ?x))›*) sin_le_one (*‹sin ?x ≤ 1›*) sin_zero (*‹sin 0 = 0›*) zero_less_mult_iff (*‹(0 < ?a * ?b) = (0 < ?a ∧ 0 < ?b ∨ ?a < 0 ∧ ?b < 0)›*)) lemma sin_plus_cos_eq_45: "sin x + cos x = sqrt 2 * sin (x + pi/4)" apply (simp add: sin_add (*‹sin (?x + ?y) = sin ?x * cos ?y + cos ?x * sin ?y›*) sin_45 (*‹sin (pi / 4) = sqrt 2 / 2›*) cos_45 (*‹cos (pi / 4) = sqrt 2 / 2›*)) (*goal: ‹sin x + cos x = sqrt 2 * sin (x + pi / 4)›*) by (simp add: field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 77 facts*)) lemma sin_cube_plus_cos_cube_gt_zero_iff': "(sin x ^ 3 + cos x ^ 3 > 0) = (sin (x + pi/4) > 0)" by (smt (verit, best) mult_pos_pos (*‹⟦0 < ?a; 0 < ?b⟧ ⟹ 0 < ?a * ?b›*) real_sqrt_gt_0_iff (*‹(0 < sqrt ?y) = (0 < ?y)›*) sin_cube_plus_cos_cube_gt_zero_iff (*‹(0 < sin ?x ^ 3 + cos ?x ^ 3) = (0 < sin ?x + cos ?x)›*) sin_plus_cos_eq_45 (*‹sin ?x + cos ?x = sqrt 2 * sin (?x + pi / 4)›*) zero_less_mult_pos (*‹⟦0 < ?a * ?b; 0 < ?a⟧ ⟹ 0 < ?b›*)) lemma sin_less_zero_pi: "⟦- pi < x; x < 0⟧ ⟹ sin x < 0" by (metis add.inverse_inverse (*‹- (- ?a) = ?a›*) add.inverse_neutral (*‹- 0 = 0›*) neg_less_iff_less (*‹(- ?b < - ?a) = (?a < ?b)›*) sin_gt_zero (*‹⟦0 < ?x; ?x < pi⟧ ⟹ 0 < sin ?x›*) sin_minus (*‹sin (- ?x) = - sin ?x›*)) lemma sin_45_positive_intervals: "(sin (x + pi/4) > 0) = (x ∈ (⋃n::int. {-pi/4 + 2*pi*n <..< 3*pi/4 + 2*pi*n}))" proof (standard; (elim UnionE (*‹⟦?A ∈ ⋃ ?C; ⋀X. ⟦?A ∈ X; X ∈ ?C⟧ ⟹ ?R⟧ ⟹ ?R›*) rangeE (*‹⟦?b ∈ range ?f; ⋀x. ?b = ?f x ⟹ ?P⟧ ⟹ ?P›*)) | (-)) (*goals: 1. ‹0 < sin (x + pi / 4) ⟹ x ∈ (⋃x. {- pi / 4 + 2 * pi * real_of_int x<..<3 * pi / 4 + 2 * pi * real_of_int x})› 2. ‹⋀X xa. ⟦x ∈ X; X = {- pi / 4 + 2 * pi * real_of_int xa<..<3 * pi / 4 + 2 * pi * real_of_int xa}⟧ ⟹ 0 < sin (x + pi / 4)›*) obtain y :: real and n :: int where "x = y + 2*pi*n" and "- pi ≤ y" and "y ≤ pi" (*goal: ‹(⋀y n. ⟦x = y + 2 * pi * real_of_int n; - pi ≤ y; y ≤ pi⟧ ⟹ thesis) ⟹ thesis›*) using sincos_principal_value (*‹∃y. (- pi < y ∧ y ≤ pi) ∧ sin y = sin ?x ∧ cos y = cos ?x›*) sin_cos_eq_iff (*‹(sin (?y::real) = sin (?x::real) ∧ cos ?y = cos ?x) = (∃x::int. ?y = ?x + (2::real) * pi * real_of_int x)›*) less_eq_real_def (*‹(?x ≤ ?y) = (?x < ?y ∨ ?x = ?y)›*) by metis note yn = this (*‹x = y + 2 * pi * real_of_int n› ‹- pi ≤ y› ‹y ≤ pi›*) assume "0 < sin (x + pi / 4)" (*‹(0::real) < sin ((x::real) + pi / (4::real))›*) then have a: "0 < sin (y + pi / 4)" using yn (*‹x = y + 2 * pi * real_of_int n› ‹- pi ≤ (y::real)› ‹y ≤ pi›*) by (metis sin_add (*‹sin (?x + ?y) = sin ?x * cos ?y + cos ?x * sin ?y›*) sin_cos_eq_iff (*‹(sin ?y = sin ?x ∧ cos ?y = cos ?x) = (∃x. ?y = ?x + 2 * pi * real_of_int x)›*)) then have "y ∈ {- pi / 4<..<3 * pi / 4}" proof (unfold greaterThanLessThan_iff (*‹(?i ∈ {?l<..<?u}) = (?l < ?i ∧ ?i < ?u)›*), safe) (*goals: 1. ‹⟦(0::real) < sin ((y::real) + pi / (4::real)); (0::real) < sin (y + pi / (4::real))⟧ ⟹ - pi / (4::real) < y› 2. ‹⟦(0::real) < sin ((y::real) + pi / (4::real)); (0::real) < sin (y + pi / (4::real))⟧ ⟹ y < (3::real) * pi / (4::real)›*) show "- pi / 4 < y" proof (rule ccontr (*‹(¬ (?P::bool) ⟹ False) ⟹ ?P›*)) (*goal: ‹¬ - pi / 4 < y ⟹ False›*) assume "¬ - pi / 4 < y" (*‹¬ - pi / (4::real) < (y::real)›*) then have "y < - pi / 4 ∨ y = - pi / 4" by (simp add: not_less (*‹(¬ ?x < ?y) = (?y ≤ ?x)›*) le_less (*‹(?x ≤ ?y) = (?x < ?y ∨ ?x = ?y)›*)) then show False using a (*‹(0::real) < sin ((y::real) + pi / (4::real))›*) sin_less_zero_pi[where x = "y + pi/4"] (*‹⟦- pi < (y::real) + pi / (4::real); y + pi / (4::real) < (0::real)⟧ ⟹ sin (y + pi / (4::real)) < (0::real)›*) yn (*‹x = y + 2 * pi * real_of_int n› ‹- pi ≤ y› ‹y ≤ pi›*) sin_zero (*‹sin 0 = 0›*) by force qed show "y < 3 * pi / 4" proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹¬ y < 3 * pi / 4 ⟹ False›*) assume "¬ y < 3 * pi / 4" (*‹¬ (y::real) < (3::real) * pi / (4::real)›*) then have "pi ≤ y + pi/4" by (simp add: not_less (*‹(¬ ?x < ?y) = (?y ≤ ?x)›*)) then show False using a (*‹0 < sin (y + pi / 4)›*) sin_le_zero (*‹⟦pi ≤ ?x; ?x < 2 * pi⟧ ⟹ sin ?x ≤ 0›*) yn (*‹(x::real) = (y::real) + (2::real) * pi * real_of_int (n::int)› ‹- pi ≤ (y::real)› ‹y ≤ pi›*) pi_ge_two (*‹2 ≤ pi›*) by fastforce qed qed then have "x ∈ {- pi / 4 + 2*pi*n<..<3 * pi / 4 + 2*pi*n}" using yn (*‹x = y + 2 * pi * real_of_int n› ‹- pi ≤ y› ‹y ≤ pi›*) greaterThanLessThan_iff (*‹(?i ∈ {?l<..<?u}) = (?l < ?i ∧ ?i < ?u)›*) by simp then show "x ∈ (⋃n::int. {- pi / 4 + 2*pi*n<..<3 * pi / 4 + 2*pi*n})" by blast next (*goal: ‹⋀X xa. ⟦x ∈ X; X = {- pi / 4 + 2 * pi * real_of_int xa<..<3 * pi / 4 + 2 * pi * real_of_int xa}⟧ ⟹ 0 < sin (x + pi / 4)›*) fix X and n :: int assume "x ∈ X" and "X = {- pi / 4 + 2*pi*n<..<3 * pi / 4 + 2*pi*n}" (*‹(x::real) ∈ (X::real set)› ‹(X::real set) = {- pi / (4::real) + (2::real) * pi * real_of_int (n::int)<..<(3::real) * pi / (4::real) + (2::real) * pi * real_of_int n}›*) then have "x ∈ {- pi / 4 + 2*pi*n<..<3 * pi / 4 + 2*pi*n}" by simp then obtain y :: real and n :: int where "x = y + 2*pi*n" and "- pi / 4 < y" and "y < 3 * pi / 4" (*goal: ‹(⋀y n. ⟦x = y + 2 * pi * real_of_int n; - pi / 4 < y; y < 3 * pi / 4⟧ ⟹ thesis) ⟹ thesis›*) by (smt (z3) greaterThanLessThan_iff (*‹(?i ∈ {?l<..<?u}) = (?l < ?i ∧ ?i < ?u)›*)) note yn = this (*‹x = y + 2 * pi * real_of_int n› ‹- pi / 4 < y› ‹y < 3 * pi / 4›*) have "0 < sin (y + pi / 4)" using sin_gt_zero (*‹⟦0 < ?x; ?x < pi⟧ ⟹ 0 < sin ?x›*) yn (*‹x = y + 2 * pi * real_of_int n› ‹- pi / 4 < y› ‹y < 3 * pi / 4›*) by force then show "0 < sin (x + pi / 4)" using yn (*‹x = y + 2 * pi * real_of_int n› ‹- pi / (4::real) < (y::real)› ‹y < 3 * pi / 4›*) sin_cos_eq_iff[of "x + pi / 4" "y + pi / 4"] (*‹(sin (x + pi / 4) = sin (y + pi / 4) ∧ cos (x + pi / 4) = cos (y + pi / 4)) = (∃xa. x + pi / 4 = y + pi / 4 + 2 * pi * real_of_int xa)›*) by simp qed text‹When the function is well defined our hyperdual definition is equal to the hyperdual extension.› lemma hypext_fa_test: assumes "Base x ∈ (⋃n::int. {-pi/4 + 2*pi*n <..< 3*pi/4 + 2*pi*n})" shows "(*h* fa_test) x = hyp_fa_test x" proof (-) (*goal: ‹(*h* fa_test) x = hyp_fa_test x›*) have inverse_sqrt_valid: "0 < sin (Base x) ^ 3 + cos (Base x) ^ 3" using assms (*‹Base x ∈ (⋃x. {- pi / 4 + 2 * pi * real_of_int x<..<3 * pi / 4 + 2 * pi * real_of_int x})›*) sin_45_positive_intervals (*‹(0 < sin (?x + pi / 4)) = (?x ∈ (⋃x. {- pi / 4 + 2 * pi * real_of_int x<..<3 * pi / 4 + 2 * pi * real_of_int x}))›*) sin_cube_plus_cos_cube_gt_zero_iff' (*‹((0::real) < sin (?x::real) ^ (3::nat) + cos ?x ^ (3::nat)) = ((0::real) < sin (?x + pi / (4::real)))›*) by force have "⋀f. (λx. (sin x) ^ 3) twice_field_differentiable_at Base x" and "⋀f. (λx. (cos x) ^ 3) twice_field_differentiable_at Base x" (*goals: 1. ‹⋀f. (λx. sin x ^ 3) twice_field_differentiable_at Base x› 2. ‹⋀f. (λx. cos x ^ 3) twice_field_differentiable_at Base x› discuss goal 1*) apply (simp add: twice_field_differentiable_at_compose[OF _ twice_field_differentiable_at_power] (*‹(?f::?'a ⇒ ?'a) twice_field_differentiable_at (?x::?'a) ⟹ (λx::?'a. ?f x ^ (?n1::nat)) twice_field_differentiable_at ?x›*)) (*discuss goal 2*) apply (simp add: twice_field_differentiable_at_compose[OF _ twice_field_differentiable_at_power] (*‹?f twice_field_differentiable_at ?x ⟹ (λx. ?f x ^ ?n1) twice_field_differentiable_at ?x›*)) (*proven 2 subgoals*) . then have "(*h* (λx. sin x ^ 3 + cos x ^ 3)) x = (*h* sin) x ^ 3 + (*h* cos) x ^ 3" and d_sincos: "(λx. sin x ^ 3 + cos x ^ 3) twice_field_differentiable_at Base x" using hypext_fun_add[of "λx. sin x ^ 3" x "λx. cos x ^ 3"] (*‹⟦(λx::real. sin x ^ (3::nat)) twice_field_differentiable_at Base (x::real hyperdual); (λx::real. cos x ^ (3::nat)) twice_field_differentiable_at Base x⟧ ⟹ (*h* (λx::real. sin x ^ (3::nat) + cos x ^ (3::nat))) x = (*h* (λx::real. sin x ^ (3::nat))) x + (*h* (λx::real. cos x ^ (3::nat))) x›*) apply - (*goals: 1. ‹⟦(λx::real. sin x ^ (3::nat)) twice_field_differentiable_at Base (x::real hyperdual); (λx::real. cos x ^ (3::nat)) twice_field_differentiable_at Base x; ⟦(λx::real. sin x ^ (3::nat)) twice_field_differentiable_at Base x; (λx::real. cos x ^ (3::nat)) twice_field_differentiable_at Base x⟧ ⟹ (*h* (λx::real. sin x ^ (3::nat) + cos x ^ (3::nat))) x = (*h* (λx::real. sin x ^ (3::nat))) x + (*h* (λx::real. cos x ^ (3::nat))) x⟧ ⟹ (*h* (λx::real. sin x ^ (3::nat) + cos x ^ (3::nat))) x = (*h* sin) x ^ (3::nat) + (*h* cos) x ^ (3::nat)› 2. ‹⟦(λx::real. sin x ^ (3::nat)) twice_field_differentiable_at Base (x::real hyperdual); (λx::real. cos x ^ (3::nat)) twice_field_differentiable_at Base x; ⟦(λx::real. sin x ^ (3::nat)) twice_field_differentiable_at Base x; (λx::real. cos x ^ (3::nat)) twice_field_differentiable_at Base x⟧ ⟹ (*h* (λx::real. sin x ^ (3::nat) + cos x ^ (3::nat))) x = (*h* (λx::real. sin x ^ (3::nat))) x + (*h* (λx::real. cos x ^ (3::nat))) x⟧ ⟹ (λx::real. sin x ^ (3::nat) + cos x ^ (3::nat)) twice_field_differentiable_at Base x› discuss goal 1*) apply (simp add: hypext_fun_power (*‹?f twice_field_differentiable_at Base ?x ⟹ (*h* (λx. ?f x ^ ?n)) ?x = (*h* ?f) ?x ^ ?n›*) twice_field_differentiable_at_add (*‹⟦?f twice_field_differentiable_at ?x; ?g twice_field_differentiable_at ?x⟧ ⟹ (λx. ?f x + ?g x) twice_field_differentiable_at ?x›*)) (*discuss goal 2*) apply (simp add: hypext_fun_power (*‹?f twice_field_differentiable_at Base ?x ⟹ (*h* (λx. ?f x ^ ?n)) ?x = (*h* ?f) ?x ^ ?n›*) twice_field_differentiable_at_add (*‹⟦?f twice_field_differentiable_at ?x; ?g twice_field_differentiable_at ?x⟧ ⟹ (λx. ?f x + ?g x) twice_field_differentiable_at ?x›*)) (*proven 2 subgoals*) . then have "(*h* (λx. sqrt (sin x ^ 3 + cos x ^ 3))) x = (*h* sqrt) ((*h* sin) x ^ 3 + (*h* cos) x ^ 3)" using inverse_sqrt_valid (*‹(0::real) < sin (Base (x::real hyperdual)) ^ (3::nat) + cos (Base x) ^ (3::nat)›*) hypext_compose[of "λx. sin x ^ 3 + cos x ^ 3" x] (*‹⟦(λx. sin x ^ 3 + cos x ^ 3) twice_field_differentiable_at Base x; ?g twice_field_differentiable_at sin (Base x) ^ 3 + cos (Base x) ^ 3⟧ ⟹ (*h* (λx. ?g (sin x ^ 3 + cos x ^ 3))) x = (*h* ?g) ((*h* (λx. sin x ^ 3 + cos x ^ 3)) x)›*) by simp moreover have d_sqrt: "(λx. sqrt (sin x ^ 3 + cos x ^ 3)) twice_field_differentiable_at Base x" using inverse_sqrt_valid (*‹0 < sin (Base x) ^ 3 + cos (Base x) ^ 3›*) d_sincos (*‹(λx. sin x ^ 3 + cos x ^ 3) twice_field_differentiable_at Base x›*) twice_field_differentiable_at_compose (*‹⟦?f twice_field_differentiable_at ?x; ?g twice_field_differentiable_at ?f ?x⟧ ⟹ (λx. ?g (?f x)) twice_field_differentiable_at ?x›*) twice_field_differentiable_at_sqrt (*‹0 < ?x ⟹ sqrt twice_field_differentiable_at ?x›*) by blast ultimately have "(*h* (λx. inverse (sqrt (sin x ^ 3 + cos x ^ 3)))) x = inverse ((*h* sqrt) ((*h* sin) x ^ 3 + (*h* cos) x ^ 3))" using inverse_sqrt_valid (*‹(0::real) < sin (Base (x::real hyperdual)) ^ (3::nat) + cos (Base x) ^ (3::nat)›*) hypext_fun_inverse[of "λx. sqrt (sin x ^ 3 + cos x ^ 3)" x] (*‹⟦(λx. sqrt (sin x ^ 3 + cos x ^ 3)) twice_field_differentiable_at Base x; sqrt (sin (Base x) ^ 3 + cos (Base x) ^ 3) ≠ 0⟧ ⟹ (*h* (λx. inverse (sqrt (sin x ^ 3 + cos x ^ 3)))) x = inverse ((*h* (λx. sqrt (sin x ^ 3 + cos x ^ 3))) x)›*) by simp moreover have "(λx. inverse (sqrt (sin x ^ 3 + cos x ^ 3))) twice_field_differentiable_at Base x" using inverse_sqrt_valid (*‹0 < sin (Base x) ^ 3 + cos (Base x) ^ 3›*) d_sqrt (*‹(λx. sqrt (sin x ^ 3 + cos x ^ 3)) twice_field_differentiable_at Base x›*) real_sqrt_eq_zero_cancel_iff (*‹(sqrt ?x = 0) = (?x = 0)›*) twice_field_differentiable_at_compose (*‹⟦?f twice_field_differentiable_at ?x; ?g twice_field_differentiable_at ?f ?x⟧ ⟹ (λx. ?g (?f x)) twice_field_differentiable_at ?x›*) twice_field_differentiable_at_inverse (*‹?x ≠ 0 ⟹ inverse twice_field_differentiable_at ?x›*) less_numeral_extra(3) (*‹¬ 0 < 0›*) by force ultimately have "(*h* (λx. exp x * inverse (sqrt (sin x ^ 3 + cos x ^ 3)))) x = (*h* exp) x * inverse ((*h* sqrt) ((*h* sin) x ^ 3 + (*h* cos) x ^ 3))" by (simp add: hypext_fun_mult (*‹⟦?f twice_field_differentiable_at Base ?x; ?g twice_field_differentiable_at Base ?x⟧ ⟹ (*h* (λz. ?f z * ?g z)) ?x = (*h* ?f) ?x * (*h* ?g) ?x›*)) then have "(*h* (λx. exp x / sqrt (sin x ^ 3 + cos x ^ 3))) x = (*h* exp) x / (*h* sqrt) ((*h* sin) x ^ 3 + (*h* cos) x ^ 3)" by (simp add: inverse_eq_divide (*‹inverse ?a = 1 / ?a›*) hyp_divide_inverse (*‹?a / ?b = ?a * inverse ?b›*)) then show "?thesis" (*goal: ‹(*h* fa_test) x = hyp_fa_test x›*) unfolding fa_test_def hyp_fa_test_def (*goal: ‹(*h* (λx::real. exp x / sqrt (sin x ^ (3::nat) + cos x ^ (3::nat)))) (x::real hyperdual) = (*h* exp) x / (*h* sqrt) ((*h* sin) x ^ (3::nat) + (*h* cos) x ^ (3::nat))›*) . qed text‹ We can show that our hyperdual extension gives (approximately) the same values as those found by Fike and Alonso when evaluated at @{term "1.5"}. › lemma assumes "x = hyp_fa_test (β 1.5)" shows "¦Base x - 4.4978¦ ≤ 0.00005" and "¦Eps1 x - 4.0534¦ ≤ 0.00005" and "¦Eps12 x - 9.4631¦ ≤ 0.00005" proof (-) (*goals: 1. ‹¦Base (x::real hyperdual) - (44978::real) / (10::real) ^ (4::nat)¦ ≤ (5::real) / (10::real) ^ (5::nat)› 2. ‹¦Eps1 (x::real hyperdual) - (40534::real) / (10::real) ^ (4::nat)¦ ≤ (5::real) / (10::real) ^ (5::nat)› 3. ‹¦Eps12 (x::real hyperdual) - (94631::real) / (10::real) ^ (4::nat)¦ ≤ (5::real) / (10::real) ^ (5::nat)›*) show "¦Base x - 4.4978¦ ≤ 0.00005" by (msorry) have d: "0 < sin (3/2 :: real) ^ 3 + cos (3/2 :: real) ^ 3" using sin_cube_plus_cos_cube_gt_zero_iff' (*‹(0 < sin ?x ^ 3 + cos ?x ^ 3) = (0 < sin (?x + pi / 4))›*) sin_gt_zero (*‹⟦0 < ?x; ?x < pi⟧ ⟹ 0 < sin ?x›*) pos_add_strict (*‹⟦0 < ?a; ?b < ?c⟧ ⟹ ?b < ?a + ?c›*) pi_gt3 (*‹(3::real) < pi›*) by force show "¦Eps1 x - 4.0534¦ ≤ 0.00005" by (msorry) show "¦Eps12 x - 9.4631¦ ≤ 0.00005" by (msorry) qed text‹A number of additional lemmas that will be required to prove the derivatives:› lemma hypext_sqrt_hyperdual_parts: "a > 0 ⟹ (*h* sqrt) (a *⇩H ba + b *⇩H e1 + c *⇩H e2 + d *⇩H e12) = sqrt a *⇩H ba + (b * inverse (sqrt a) / 2) *⇩H e1 + (c * inverse (sqrt a) / 2) *⇩H e2 + (d * inverse (sqrt a) / 2 - b * c * inverse (sqrt a ^ 3) / 4) *⇩H e12" by (metis Hyperdual_eq (*‹Hyperdual ?a ?b ?c ?d = ?a *⇩H ba + ?b *⇩H e1 + ?c *⇩H e2 + ?d *⇩H e12›*) hypext_sqrt_Hyperdual (*‹0 < ?a ⟹ (*h* sqrt) (Hyperdual ?a ?b ?c ?d) = sqrt ?a *⇩H ba + (?b * inverse (sqrt ?a) / 2) *⇩H e1 + (?c * inverse (sqrt ?a) / 2) *⇩H e2 + (?d * inverse (sqrt ?a) / 2 - ?b * ?c * inverse (sqrt ?a ^ 3) / 4) *⇩H e12›*)) lemma cos_multiple: "cos (n * x) = 2 * cos x * cos ((n - 1) * x) - cos ((n - 2) * x)" for x :: "'a :: {banach,real_normed_field}" proof (-) (*goal: ‹cos (n * x) = 2 * cos x * cos ((n - 1) * x) - cos ((n - 2) * x)›*) have "cos ((n - 1) * x + x) + cos ((n - 1) * x - x) = 2 * cos ((n - 1) * x) * cos x" by (simp add: cos_add (*‹cos ((?x::?'a) + (?y::?'a)) = cos ?x * cos ?y - sin ?x * sin ?y›*) cos_diff (*‹cos ((?x::?'a) - (?y::?'a)) = cos ?x * cos ?y + sin ?x * sin ?y›*)) then show "?thesis" (*goal: ‹cos ((n::'a::{banach,real_normed_field}) * (x::'a::{banach,real_normed_field})) = (2::'a::{banach,real_normed_field}) * cos x * cos ((n - (1::'a::{banach,real_normed_field})) * x) - cos ((n - (2::'a::{banach,real_normed_field})) * x)›*) by (simp add: left_diff_distrib' (*‹(?b - ?c) * ?a = ?b * ?a - ?c * ?a›*) eq_diff_eq (*‹(?a = ?c - ?b) = (?a + ?b = ?c)›*)) qed lemma sin_multiple: "sin (n * x) = 2 * cos x * sin ((n - 1) * x) - sin ((n - 2) * x)" for x :: "'a :: {banach,real_normed_field}" proof (-) (*goal: ‹sin (n * x) = 2 * cos x * sin ((n - 1) * x) - sin ((n - 2) * x)›*) have "sin ((n - 1) * x + x) + sin ((n - 1) * x - x) = 2 * cos x * sin ((n - 1) * x)" by (simp add: sin_add (*‹sin ((?x::?'a) + (?y::?'a)) = sin ?x * cos ?y + cos ?x * sin ?y›*) sin_diff (*‹sin ((?x::?'a) - (?y::?'a)) = sin ?x * cos ?y - cos ?x * sin ?y›*)) then show "?thesis" (*goal: ‹sin (n * x) = 2 * cos x * sin ((n - 1) * x) - sin ((n - 2) * x)›*) by (simp add: left_diff_distrib' (*‹(?b - ?c) * ?a = ?b * ?a - ?c * ?a›*) eq_diff_eq (*‹(?a = ?c - ?b) = (?a + ?b = ?c)›*)) qed lemma power5: fixes z :: "'a :: monoid_mult" shows "z ^ 5 = z * z * z * z * z" by (simp add: mult.assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) power2_eq_square (*‹?a² = ?a * ?a›*) power_numeral_odd (*‹?z ^ numeral (num.Bit1 ?w) = (let w = ?z ^ numeral ?w in ?z * w * w)›*)) lemma power6: fixes z :: "'a :: monoid_mult" shows "z ^ 6 = z * z * z * z * z * z" by (simp add: mult.assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) power3_eq_cube (*‹?a ^ 3 = ?a * ?a * ?a›*) power_numeral_even (*‹?z ^ numeral (num.Bit0 ?w) = (let w = ?z ^ numeral ?w in w * w)›*)) text‹ We find the derivatives of @{const fa_test} by applying a Wengert list approach, as done by Fike and Alonso, to make the same composition but in hyperduals. We know that this is equal to the hyperdual extension which in turn gives us the derivatives. › lemma Wengert_autodiff_fa_test: assumes "x ∈ (⋃n::int. {-pi/4 + 2*pi*n <..< 3*pi/4 + 2*pi*n})" shows "First (autodiff fa_test x) = (exp x * (3 * cos x + 5 * cos (3 * x) + 9 * sin x + sin (3 * x))) / (8 * (sqrt (sin x ^ 3 + cos x ^ 3)) ^ 3)" and "Second (autodiff fa_test x) = (exp x * (130 - 12 * cos (2 * x) + 30 * cos (4 * x) + 12 * cos (6 * x) - 111 * sin (2 * x) + 48 * sin (4 * x) + 5 * sin (6 * x))) / (64 * (sqrt (sin x ^ 3 + cos x ^ 3)) ^ 5)" proof (-) (*goals: 1. ‹First (autodiff fa_test x) = exp x * (3 * cos x + 5 * cos (3 * x) + 9 * sin x + sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)› 2. ‹Second (autodiff fa_test x) = exp x * (130 - 12 * cos (2 * x) + 30 * cos (4 * x) + 12 * cos (6 * x) - 111 * sin (2 * x) + 48 * sin (4 * x) + 5 * sin (6 * x)) / (64 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5)›*) have s3_c3_gt_zero: "(sin x) ^ 3 + (cos x) ^ 3 > 0" using assms (*‹(x::real) ∈ (⋃x::int. {- pi / (4::real) + (2::real) * pi * real_of_int x<..<(3::real) * pi / (4::real) + (2::real) * pi * real_of_int x})›*) sin_45_positive_intervals (*‹(0 < sin (?x + pi / 4)) = (?x ∈ (⋃x. {- pi / 4 + 2 * pi * real_of_int x<..<3 * pi / 4 + 2 * pi * real_of_int x}))›*) sin_cube_plus_cos_cube_gt_zero_iff' (*‹(0 < sin ?x ^ 3 + cos ?x ^ 3) = (0 < sin (?x + pi / 4))›*) sin_gt_zero (*‹⟦0 < ?x; ?x < pi⟧ ⟹ 0 < sin ?x›*) by force let ?w0 = "β x" have w0: "?w0 = x *⇩H ba + 1 *⇩H e1 + 1 *⇩H e2 + 0 *⇩H e12" by (simp add: Hyperdual_eq (*‹Hyperdual ?a ?b ?c ?d = ?a *⇩H ba + ?b *⇩H e1 + ?c *⇩H e2 + ?d *⇩H e12›*) hyperdualx_def (*‹β ?x = Hyperdual ?x 1 1 0›*)) let ?w1 = "(*h* exp) ?w0" have w1: "?w1 = exp x *⇩H ba + exp x *⇩H e1 + exp x *⇩H e2 + exp x *⇩H e12" using hypext_exp_extract (*‹(*h* exp) (β (?x::?'a)) = exp ?x *⇩H ba + exp ?x *⇩H e1 + exp ?x *⇩H e2 + exp ?x *⇩H e12›*) by blast let ?w2 = "(*h* sin) ?w0" have w2: "?w2 = sin x *⇩H ba + cos x *⇩H e1 + cos x *⇩H e2 + - sin x *⇩H e12" by (simp add: hypext_sin_extract (*‹(*h* sin) (β ?x) = sin ?x *⇩H ba + cos ?x *⇩H e1 + cos ?x *⇩H e2 - sin ?x *⇩H e12›*) of_comp_minus (*‹of_comp (- ?a) = - of_comp ?a›*) scaleH_times (*‹?f *⇩H ?x = of_comp ?f * ?x›*)) let ?w3 = "(*h* (λx. x ^ 3)) ?w2" have w3: "?w3 = (sin x) ^ 3 *⇩H ba + (3 * cos x * (sin x)²) *⇩H e1 + (3 * cos x * (sin x)²) *⇩H e2 + - (3/4 * (sin x - 3 * sin (3 * x))) *⇩H e12" by (simp add: w2 (*‹(*h* sin) (β x) = sin x *⇩H ba + cos x *⇩H e1 + cos x *⇩H e2 + - sin x *⇩H e12›*) hypext_power_Hyperdual_parts (*‹(*h* (λx. x ^ ?n)) (?a *⇩H ba + ?b *⇩H e1 + ?c *⇩H e2 + ?d *⇩H e12) = ?a ^ ?n *⇩H ba + (of_nat ?n * ?b * ?a ^ (?n - 1)) *⇩H e1 + (of_nat ?n * ?c * ?a ^ (?n - 1)) *⇩H e2 + (?d * (of_nat ?n * ?a ^ (?n - 1)) + ?b * ?c * (of_nat ?n * of_nat (?n - 1) * ?a ^ (?n - 2))) *⇩H e12›*) power2_eq_square (*‹?a² = ?a * ?a›*) cos_times_cos (*‹cos ?w * cos ?z = (cos (?w - ?z) + cos (?w + ?z)) / 2›*) sin_times_sin (*‹sin ?w * sin ?z = (cos (?w - ?z) - cos (?w + ?z)) / 2›*) sin_times_cos (*‹sin ?w * cos ?z = (sin (?w + ?z) + sin (?w - ?z)) / 2›*) distrib_left (*‹?a * (?b + ?c) = ?a * ?b + ?a * ?c›*) right_diff_distrib' (*‹?a * (?b - ?c) = ?a * ?b - ?a * ?c›*) divide_simps (*‹inverse ?a = 1 / ?a› ‹?a + ?b / ?z = (if ?z = 0 then ?a else (?a * ?z + ?b) / ?z)› ‹?a / ?z + ?b = (if ?z = 0 then ?b else (?a + ?b * ?z) / ?z)› ‹- (?a / ?z) + ?b = (if ?z = 0 then ?b else (- ?a + ?b * ?z) / ?z)› ‹?a - ?b / ?z = (if ?z = 0 then ?a else (?a * ?z - ?b) / ?z)› ‹?a / ?z - ?b = (if ?z = 0 then - ?b else (?a - ?b * ?z) / ?z)› ‹- (?a / ?z) - ?b = (if ?z = 0 then - ?b else (- ?a - ?b * ?z) / ?z)› ‹(?b / ?c = ?a) = (if ?c ≠ 0 then ?b = ?a * ?c else ?a = 0)› ‹(?a = ?b / ?c) = (if ?c ≠ 0 then ?a * ?c = ?b else ?a = 0)› ‹(- (?b / ?c) = ?a) = (if ?c ≠ 0 then - ?b = ?a * ?c else ?a = 0)› ‹(?a = - (?b / ?c)) = (if ?c ≠ 0 then ?a * ?c = - ?b else ?a = 0)› ‹(?a ≤ ?b / ?c) = (if 0 < ?c then ?a * ?c ≤ ?b else if ?c < 0 then ?b ≤ ?a * ?c else ?a ≤ 0)› and more 25 facts*)) let ?w4 = "(*h* cos) ?w0" have w4: "?w4 = cos x *⇩H ba + - sin x *⇩H e1 + - sin x *⇩H e2 + - cos x *⇩H e12" by (simp add: hypext_cos_extract (*‹(*h* cos) (β (?x::?'a)) = cos ?x *⇩H ba - sin ?x *⇩H e1 - sin ?x *⇩H e2 - cos ?x *⇩H e12›*) of_comp_minus (*‹of_comp (- (?a::?'a)) = - of_comp ?a›*) scaleH_times (*‹(?f::?'a) *⇩H (?x::?'a hyperdual) = of_comp ?f * ?x›*)) let ?w5 = "(*h* (λx. x ^ 3)) ?w4" have w5: "?w5 = (cos x) ^ 3 *⇩H ba + - (3 * sin x * (cos x)²) *⇩H e1 + - (3 * sin x * (cos x)²) *⇩H e2 + - (3/4 * (cos x + 3 * cos (3 * x))) *⇩H e12" by (simp add: w4 (*‹(*h* cos) (β x) = cos x *⇩H ba + - sin x *⇩H e1 + - sin x *⇩H e2 + - cos x *⇩H e12›*) hypext_power_Hyperdual_parts (*‹(*h* (λx. x ^ ?n)) (?a *⇩H ba + ?b *⇩H e1 + ?c *⇩H e2 + ?d *⇩H e12) = ?a ^ ?n *⇩H ba + (of_nat ?n * ?b * ?a ^ (?n - 1)) *⇩H e1 + (of_nat ?n * ?c * ?a ^ (?n - 1)) *⇩H e2 + (?d * (of_nat ?n * ?a ^ (?n - 1)) + ?b * ?c * (of_nat ?n * of_nat (?n - 1) * ?a ^ (?n - 2))) *⇩H e12›*) sin_times_sin (*‹sin ?w * sin ?z = (cos (?w - ?z) - cos (?w + ?z)) / 2›*) right_diff_distrib' (*‹?a * (?b - ?c) = ?a * ?b - ?a * ?c›*) cos_times_cos (*‹cos ?w * cos ?z = (cos (?w - ?z) + cos (?w + ?z)) / 2›*) power2_eq_square (*‹?a² = ?a * ?a›*) distrib_left (*‹?a * (?b + ?c) = ?a * ?b + ?a * ?c›*) sin_times_cos (*‹sin ?w * cos ?z = (sin (?w + ?z) + sin (?w - ?z)) / 2›*) divide_simps (*‹inverse ?a = 1 / ?a› ‹?a + ?b / ?z = (if ?z = 0 then ?a else (?a * ?z + ?b) / ?z)› ‹?a / ?z + ?b = (if ?z = 0 then ?b else (?a + ?b * ?z) / ?z)› ‹- (?a / ?z) + ?b = (if ?z = 0 then ?b else (- ?a + ?b * ?z) / ?z)› ‹?a - ?b / ?z = (if ?z = 0 then ?a else (?a * ?z - ?b) / ?z)› ‹?a / ?z - ?b = (if ?z = 0 then - ?b else (?a - ?b * ?z) / ?z)› ‹- (?a / ?z) - ?b = (if ?z = 0 then - ?b else (- ?a - ?b * ?z) / ?z)› ‹(?b / ?c = ?a) = (if ?c ≠ 0 then ?b = ?a * ?c else ?a = 0)› ‹(?a = ?b / ?c) = (if ?c ≠ 0 then ?a * ?c = ?b else ?a = 0)› ‹(- (?b / ?c) = ?a) = (if ?c ≠ 0 then - ?b = ?a * ?c else ?a = 0)› ‹(?a = - (?b / ?c)) = (if ?c ≠ 0 then ?a * ?c = - ?b else ?a = 0)› ‹(?a ≤ ?b / ?c) = (if 0 < ?c then ?a * ?c ≤ ?b else if ?c < 0 then ?b ≤ ?a * ?c else ?a ≤ 0)› and more 25 facts*)) let ?w6 = "?w3 + ?w5" have sqrt_pos: "Base ?w6 > 0" using s3_c3_gt_zero (*‹0 < sin x ^ 3 + cos x ^ 3›*) by auto have w6: "?w6 = (sin x ^ 3 + cos x ^ 3) *⇩H ba + (3 * cos x * sin x * (sin x - cos x)) *⇩H e1 + (3 * cos x * sin x * (sin x - cos x)) *⇩H e2 + - (3/4 * (sin x + cos x + 3 * cos (3 * x) - 3 * sin (3 * x))) *⇩H e12" by (auto simp add: w3 (*‹(*h* (λx. x ^ 3)) ((*h* sin) (β x)) = sin x ^ 3 *⇩H ba + (3 * cos x * (sin x)²) *⇩H e1 + (3 * cos x * (sin x)²) *⇩H e2 + - (3 / 4 * (sin x - 3 * sin (3 * x))) *⇩H e12›*) w5 (*‹(*h* (λx. x ^ 3)) ((*h* cos) (β x)) = cos x ^ 3 *⇩H ba + - (3 * sin x * (cos x)²) *⇩H e1 + - (3 * sin x * (cos x)²) *⇩H e2 + - (3 / 4 * (cos x + 3 * cos (3 * x))) *⇩H e12›*) add_hyperdual_parts (*‹?a *⇩H ba + ?b *⇩H e1 + ?c *⇩H e2 + ?d *⇩H e12 + (?a' *⇩H ba + ?b' *⇩H e1 + ?c' *⇩H e2 + ?d' *⇩H e12) = (?a + ?a') *⇩H ba + (?b + ?b') *⇩H e1 + (?c + ?c') *⇩H e2 + (?d + ?d') *⇩H e12›*) power2_eq_square (*‹?a² = ?a * ?a›*) right_diff_distrib' (*‹?a * (?b - ?c) = ?a * ?b - ?a * ?c›*) divide_simps (*‹inverse ?a = 1 / ?a› ‹?a + ?b / ?z = (if ?z = 0 then ?a else (?a * ?z + ?b) / ?z)› ‹?a / ?z + ?b = (if ?z = 0 then ?b else (?a + ?b * ?z) / ?z)› ‹- (?a / ?z) + ?b = (if ?z = 0 then ?b else (- ?a + ?b * ?z) / ?z)› ‹?a - ?b / ?z = (if ?z = 0 then ?a else (?a * ?z - ?b) / ?z)› ‹?a / ?z - ?b = (if ?z = 0 then - ?b else (?a - ?b * ?z) / ?z)› ‹- (?a / ?z) - ?b = (if ?z = 0 then - ?b else (- ?a - ?b * ?z) / ?z)› ‹(?b / ?c = ?a) = (if ?c ≠ 0 then ?b = ?a * ?c else ?a = 0)› ‹(?a = ?b / ?c) = (if ?c ≠ 0 then ?a * ?c = ?b else ?a = 0)› ‹(- (?b / ?c) = ?a) = (if ?c ≠ 0 then - ?b = ?a * ?c else ?a = 0)› ‹(?a = - (?b / ?c)) = (if ?c ≠ 0 then ?a * ?c = - ?b else ?a = 0)› ‹(?a ≤ ?b / ?c) = (if 0 < ?c then ?a * ?c ≤ ?b else if ?c < 0 then ?b ≤ ?a * ?c else ?a ≤ 0)› and more 25 facts*)) let ?w7 = "inverse ((*h* sqrt) ?w6)" have w7: "?w7 = inverse(sqrt(sin x ^ 3 + cos x ^ 3)) *⇩H ba + - ((3 * cos x * sin x * (sin x - cos x))/(2 * (sqrt (sin x ^ 3 + cos x ^ 3)) ^ 3)) *⇩H e1 + - ((3 * cos x * sin x * (sin x - cos x))/(2 * (sqrt (sin x ^ 3 + cos x ^ 3)) ^ 3)) *⇩H e2 + ((3 * (30 + 2 * cos (4 * x) - 41 * sin (2 * x) + 3 * sin (6 * x)))/(64 * (sqrt (sin x ^ 3 + cos x ^ 3)) ^ 5)) *⇩H e12" proof (-) (*goal: ‹inverse ((*h* sqrt) ((*h* (λx::real. x ^ (3::nat))) ((*h* sin) (β (x::real))) + (*h* (λx::real. x ^ (3::nat))) ((*h* cos) (β x)))) = inverse (sqrt (sin x ^ (3::nat) + cos x ^ (3::nat))) *⇩H ba + - ((3::real) * cos x * sin x * (sin x - cos x) / ((2::real) * sqrt (sin x ^ (3::nat) + cos x ^ (3::nat)) ^ (3::nat))) *⇩H e1 + - ((3::real) * cos x * sin x * (sin x - cos x) / ((2::real) * sqrt (sin x ^ (3::nat) + cos x ^ (3::nat)) ^ (3::nat))) *⇩H e2 + ((3::real) * ((30::real) + (2::real) * cos ((4::real) * x) - (41::real) * sin ((2::real) * x) + (3::real) * sin ((6::real) * x)) / ((64::real) * sqrt (sin x ^ (3::nat) + cos x ^ (3::nat)) ^ (5::nat))) *⇩H e12›*) let ?w7a = "(*h* sqrt) ?w6" have w7a: "?w7a = sqrt (sin x ^ 3 + cos x ^ 3) *⇩H ba + ((3 * (cos x * (sin x * (sin x - cos x)))) * inverse (sqrt (sin x ^ 3 + cos x ^ 3)) / 2) *⇩H e1 + ((3 * (cos x * (sin x * (sin x - cos x)))) * inverse (sqrt (sin x ^ 3 + cos x ^ 3)) / 2) *⇩H e2 + (- ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) * inverse (sqrt (sin x ^ 3 + cos x ^ 3)) / 8) + - 9 * (cos x * (sin x * ((sin x - cos x) * (cos x * (sin x * (sin x - cos x)))))) * inverse (sqrt (sin x ^ 3 + cos x ^ 3) ^ 3) / 4) *⇩H e12" unfolding w6 (*goal: ‹(*h* sqrt) ((sin x ^ 3 + cos x ^ 3) *⇩H ba + (3 * cos x * sin x * (sin x - cos x)) *⇩H e1 + (3 * cos x * sin x * (sin x - cos x)) *⇩H e2 + - (3 / 4 * (sin x + cos x + 3 * cos (3 * x) - 3 * sin (3 * x))) *⇩H e12) = sqrt (sin x ^ 3 + cos x ^ 3) *⇩H ba + (3 * (cos x * (sin x * (sin x - cos x))) * inverse (sqrt (sin x ^ 3 + cos x ^ 3)) / 2) *⇩H e1 + (3 * (cos x * (sin x * (sin x - cos x))) * inverse (sqrt (sin x ^ 3 + cos x ^ 3)) / 2) *⇩H e2 + (- ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) * inverse (sqrt (sin x ^ 3 + cos x ^ 3)) / 8) + - 9 * (cos x * (sin x * ((sin x - cos x) * (cos x * (sin x * (sin x - cos x)))))) * inverse (sqrt (sin x ^ 3 + cos x ^ 3) ^ 3) / 4) *⇩H e12›*) using sqrt_pos (*‹(0::real) < Base ((*h* (λx::real. x ^ (3::nat))) ((*h* sin) (β (x::real))) + (*h* (λx::real. x ^ (3::nat))) ((*h* cos) (β x)))›*) by (simp add: hypext_sqrt_hyperdual_parts (*‹0 < ?a ⟹ (*h* sqrt) (?a *⇩H ba + ?b *⇩H e1 + ?c *⇩H e2 + ?d *⇩H e12) = sqrt ?a *⇩H ba + (?b * inverse (sqrt ?a) / 2) *⇩H e1 + (?c * inverse (sqrt ?a) / 2) *⇩H e2 + (?d * inverse (sqrt ?a) / 2 - ?b * ?c * inverse (sqrt ?a ^ 3) / 4) *⇩H e12›*) mult.assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*)) let ?w7b = "inverse ?w7a" have "?w7b = (1 / sqrt (sin x ^ 3 + cos x ^ 3)) *⇩H ba + - (3 * (cos x * (sin x * (sin x - cos x))) * inverse (sqrt (sin x ^ 3 + cos x ^ 3)) / (2 * (sqrt (sin x ^ 3 + cos x ^ 3))²)) *⇩H e1 + - (3 * (cos x * (sin x * (sin x - cos x))) * inverse (sqrt (sin x ^ 3 + cos x ^ 3)) / (2 * (sqrt (sin x ^ 3 + cos x ^ 3))²)) *⇩H e2 + (9 * (cos x * (cos x * (sin x * (sin x * ((sin x - cos x) * ((sin x - cos x) * (inverse (sqrt (sin x ^ 3 + cos x ^ 3)) * inverse (sqrt (sin x ^ 3 + cos x ^ 3))))))))) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3) - (- ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) * inverse (sqrt (sin x ^ 3 + cos x ^ 3)) / 8) - 9 * (cos x * (sin x * ((sin x - cos x) * (cos x * (sin x * (sin x - cos x)))))) * inverse (sqrt (sin x ^ 3 + cos x ^ 3) ^ 3) / 4) / (sqrt (sin x ^ 3 + cos x ^ 3))²) *⇩H e12" by (simp add: w7a (*‹(*h* sqrt) ((*h* (λx. x ^ 3)) ((*h* sin) (β x)) + (*h* (λx. x ^ 3)) ((*h* cos) (β x))) = sqrt (sin x ^ 3 + cos x ^ 3) *⇩H ba + (3 * (cos x * (sin x * (sin x - cos x))) * inverse (sqrt (sin x ^ 3 + cos x ^ 3)) / 2) *⇩H e1 + (3 * (cos x * (sin x * (sin x - cos x))) * inverse (sqrt (sin x ^ 3 + cos x ^ 3)) / 2) *⇩H e2 + (- ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) * inverse (sqrt (sin x ^ 3 + cos x ^ 3)) / 8) + - 9 * (cos x * (sin x * ((sin x - cos x) * (cos x * (sin x * (sin x - cos x)))))) * inverse (sqrt (sin x ^ 3 + cos x ^ 3) ^ 3) / 4) *⇩H e12›*) inverse_hyperdual_parts (*‹inverse (?a *⇩H ba + ?b *⇩H e1 + ?c *⇩H e2 + ?d *⇩H e12) = (1 / ?a) *⇩H ba + (- ?b / ?a²) *⇩H e1 + (- ?c / ?a²) *⇩H e2 + (2 * (?b * ?c / ?a ^ 3) - ?d / ?a²) *⇩H e12›*)) then have w7b: "?w7b = (inverse (sqrt (sin x ^ 3 + cos x ^ 3))) *⇩H ba + - (3 * cos x * sin x * (sin x - cos x) / (2 * (sqrt (sin x ^ 3 + cos x ^ 3)) ^ 3)) *⇩H e1 + - (3 * cos x * sin x * (sin x - cos x) / (2 * (sqrt (sin x ^ 3 + cos x ^ 3)) ^ 3)) *⇩H e2 + (9 * cos x * cos x * sin x * sin x * ((sin x - cos x) * (sin x - cos x) / ((sqrt (sin x ^ 3 + cos x ^ 3)) ^ 2)) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3) - (- ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3))) - 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) / (sqrt (sin x ^ 3 + cos x ^ 3))²) *⇩H e12" by (simp add: power2_eq_square (*‹(?a::?'a)² = ?a * ?a›*) power3_eq_cube (*‹(?a::?'a) ^ (3::nat) = ?a * ?a * ?a›*) field_simps (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)› ‹(?a::?'a) * (?b::?'a) * (?c::?'a) = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)› ‹(?a::?'a) - (?b::?'a) - (?c::?'a) = ?a - (?b + ?c)› ‹(?a::?'a) + ((?b::?'a) - (?c::?'a)) = ?a + ?b - ?c› ‹((?a::?'a) - (?b::?'a) = (?c::?'a)) = (?a = ?c + ?b)› ‹((?a::?'a) = (?c::?'a) - (?b::?'a)) = (?a + ?b = ?c)› ‹(?a::?'a) - ((?b::?'a) - (?c::?'a)) = ?a + ?c - ?b› ‹(?a::?'a) - (?b::?'a) + (?c::?'a) = ?a + ?c - ?b› and more 77 facts*)) have "9 * cos x * cos x * sin x * sin x * ((sin x - cos x) * (sin x - cos x)) / ((sqrt (sin x ^ 3 + cos x ^ 3))² * (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) - (- ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3))) - 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) / (sqrt (sin x ^ 3 + cos x ^ 3))² = (90 + 6 * cos (4 * x) - 123 * sin (2 * x) + 9 * sin (6 * x)) / (64 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5)" proof (-) (*goal: ‹9 * cos x * cos x * sin x * sin x * ((sin x - cos x) * (sin x - cos x)) / ((sqrt (sin x ^ 3 + cos x ^ 3))² * (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) - (- ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3))) - 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) / (sqrt (sin x ^ 3 + cos x ^ 3))² = (90 + 6 * cos (4 * x) - 123 * sin (2 * x) + 9 * sin (6 * x)) / (64 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5)›*) have "9 * cos x * cos x * sin x * sin x * ((sin x - cos x) * (sin x - cos x)) / ((sqrt (sin x ^ 3 + cos x ^ 3))² * (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) - (- ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3))) - 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) / (sqrt (sin x ^ 3 + cos x ^ 3))² = 9 * cos x * cos x * sin x * sin x * (sin x - cos x) * (sin x - cos x) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5) + ( (3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3)) + 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) / (sqrt (sin x ^ 3 + cos x ^ 3)) ^ 2" by (simp add: divide_simps (*‹inverse ?a = 1 / ?a› ‹?a + ?b / ?z = (if ?z = 0 then ?a else (?a * ?z + ?b) / ?z)› ‹?a / ?z + ?b = (if ?z = 0 then ?b else (?a + ?b * ?z) / ?z)› ‹- (?a / ?z) + ?b = (if ?z = 0 then ?b else (- ?a + ?b * ?z) / ?z)› ‹?a - ?b / ?z = (if ?z = 0 then ?a else (?a * ?z - ?b) / ?z)› ‹?a / ?z - ?b = (if ?z = 0 then - ?b else (?a - ?b * ?z) / ?z)› ‹- (?a / ?z) - ?b = (if ?z = 0 then - ?b else (- ?a - ?b * ?z) / ?z)› ‹(?b / ?c = ?a) = (if ?c ≠ 0 then ?b = ?a * ?c else ?a = 0)› ‹(?a = ?b / ?c) = (if ?c ≠ 0 then ?a * ?c = ?b else ?a = 0)› ‹(- (?b / ?c) = ?a) = (if ?c ≠ 0 then - ?b = ?a * ?c else ?a = 0)› ‹(?a = - (?b / ?c)) = (if ?c ≠ 0 then ?a * ?c = - ?b else ?a = 0)› ‹(?a ≤ ?b / ?c) = (if 0 < ?c then ?a * ?c ≤ ?b else if ?c < 0 then ?b ≤ ?a * ?c else ?a ≤ 0)› and more 25 facts*)) also (*calculation: ‹9 * cos x * cos x * sin x * sin x * ((sin x - cos x) * (sin x - cos x)) / ((sqrt (sin x ^ 3 + cos x ^ 3))² * (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) - (- ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3))) - 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) / (sqrt (sin x ^ 3 + cos x ^ 3))² = 9 * cos x * cos x * sin x * sin x * (sin x - cos x) * (sin x - cos x) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5) + ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3)) + 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) / (sqrt (sin x ^ 3 + cos x ^ 3))²›*) have "... = 9 * cos x * cos x * sin x * sin x * (sin x - cos x) * (sin x - cos x) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5) + ( (3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) / (8 * (sqrt (sin x ^ 3 + cos x ^ 3)) ^ 3) + 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3 * (sqrt (sin x ^ 3 + cos x ^ 3)) ^ 2))" by (simp add: add_divide_distrib (*‹((?a::?'a::division_ring) + (?b::?'a::division_ring)) / (?c::?'a::division_ring) = ?a / ?c + ?b / ?c›*) power2_eq_square (*‹(?a::?'a::monoid_mult)² = ?a * ?a›*) power3_eq_cube (*‹(?a::?'a::monoid_mult) ^ (3::nat) = ?a * ?a * ?a›*) mult.commute (*‹(?a::?'a::ab_semigroup_mult) * (?b::?'a::ab_semigroup_mult) = ?b * ?a›*) mult.left_commute (*‹(?b::?'a::ab_semigroup_mult) * ((?a::?'a::ab_semigroup_mult) * (?c::?'a::ab_semigroup_mult)) = ?a * (?b * ?c)›*)) also (*calculation: ‹9 * cos x * cos x * sin x * sin x * ((sin x - cos x) * (sin x - cos x)) / ((sqrt (sin x ^ 3 + cos x ^ 3))² * (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) - (- ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3))) - 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) / (sqrt (sin x ^ 3 + cos x ^ 3))² = 9 * cos x * cos x * sin x * sin x * (sin x - cos x) * (sin x - cos x) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5) + ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3) + 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3 * (sqrt (sin x ^ 3 + cos x ^ 3))²))›*) have "... = 9 * cos x * cos x * sin x * sin x * (sin x - cos x) * (sin x - cos x) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5) + ( (3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) / (8 * (sqrt (sin x ^ 3 + cos x ^ 3)) ^ 3) + 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5))" by (simp add: mult.commute (*‹?a * ?b = ?b * ?a›*) mult.left_commute (*‹?b * (?a * ?c) = ?a * (?b * ?c)›*)) also (*calculation: ‹9 * cos x * cos x * sin x * sin x * ((sin x - cos x) * (sin x - cos x)) / ((sqrt (sin x ^ 3 + cos x ^ 3))² * (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) - (- ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3))) - 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) / (sqrt (sin x ^ 3 + cos x ^ 3))² = 9 * cos x * cos x * sin x * sin x * (sin x - cos x) * (sin x - cos x) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5) + ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3) + 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5))›*) have "... = 9 * cos x * cos x * sin x * sin x * (sin x - cos x) * (sin x - cos x) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5) + ( (3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) * (sin x ^ 3 + cos x ^ 3) / (8 * (sqrt (sin x ^ 3 + cos x ^ 3)) ^ 5) + 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5))" proof (-) (*goal: ‹9 * cos x * cos x * sin x * sin x * (sin x - cos x) * (sin x - cos x) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5) + ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3) + 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5)) = 9 * cos x * cos x * sin x * sin x * (sin x - cos x) * (sin x - cos x) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5) + ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) * (sin x ^ 3 + cos x ^ 3) / (8 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5) + 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5))›*) have "(sin x ^ 3 + cos x ^ 3) * inverse ((sqrt (sin x ^ 3 + cos x ^ 3)) ^ 2) = 1" using s3_c3_gt_zero (*‹0 < sin x ^ 3 + cos x ^ 3›*) by auto then have "1 / (8 * (sqrt (sin x ^ 3 + cos x ^ 3)) ^ 3) = (sin x ^ 3 + cos x ^ 3) / ((sqrt (sin x ^ 3 + cos x ^ 3)) ^ 2) / (8 * (sqrt (sin x ^ 3 + cos x ^ 3)) ^ 3)" by (simp add: field_simps (*‹(?a::?'a::semigroup_add) + (?b::?'a::semigroup_add) + (?c::?'a::semigroup_add) = ?a + (?b + ?c)› ‹(?a::?'a::ab_semigroup_add) + (?b::?'a::ab_semigroup_add) = ?b + ?a› ‹(?b::?'a::ab_semigroup_add) + ((?a::?'a::ab_semigroup_add) + (?c::?'a::ab_semigroup_add)) = ?a + (?b + ?c)› ‹(?a::?'a::semigroup_mult) * (?b::?'a::semigroup_mult) * (?c::?'a::semigroup_mult) = ?a * (?b * ?c)› ‹(?a::?'a::ab_semigroup_mult) * (?b::?'a::ab_semigroup_mult) = ?b * ?a› ‹(?b::?'a::ab_semigroup_mult) * ((?a::?'a::ab_semigroup_mult) * (?c::?'a::ab_semigroup_mult)) = ?a * (?b * ?c)› ‹(?a::?'a::cancel_ab_semigroup_add) - (?b::?'a::cancel_ab_semigroup_add) - (?c::?'a::cancel_ab_semigroup_add) = ?a - (?b + ?c)› ‹(?a::?'a::group_add) + ((?b::?'a::group_add) - (?c::?'a::group_add)) = ?a + ?b - ?c› ‹((?a::?'a::group_add) - (?b::?'a::group_add) = (?c::?'a::group_add)) = (?a = ?c + ?b)› ‹((?a::?'a::group_add) = (?c::?'a::group_add) - (?b::?'a::group_add)) = (?a + ?b = ?c)› ‹(?a::?'a::group_add) - ((?b::?'a::group_add) - (?c::?'a::group_add)) = ?a + ?c - ?b› ‹(?a::?'a::ab_group_add) - (?b::?'a::ab_group_add) + (?c::?'a::ab_group_add) = ?a + ?c - ?b› and more 77 facts*)) then have "1 / (8 * (sqrt (sin x ^ 3 + cos x ^ 3)) ^ 3) = (sin x ^ 3 + cos x ^ 3) / (8 * (sqrt (sin x ^ 3 + cos x ^ 3)) ^ 5)" by auto then show "?thesis" (*goal: ‹9 * cos x * cos x * sin x * sin x * (sin x - cos x) * (sin x - cos x) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5) + ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3) + 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5)) = 9 * cos x * cos x * sin x * sin x * (sin x - cos x) * (sin x - cos x) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5) + ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) * (sin x ^ 3 + cos x ^ 3) / (8 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5) + 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5))›*) by (metis (mono_tags, lifting) divide_real_def (*‹?x / ?y = ?x * inverse ?y›*) inverse_eq_divide (*‹inverse ?a = 1 / ?a›*) times_divide_eq_right (*‹?a * (?b / ?c) = ?a * ?b / ?c›*)) qed also (*calculation: ‹9 * cos x * cos x * sin x * sin x * ((sin x - cos x) * (sin x - cos x)) / ((sqrt (sin x ^ 3 + cos x ^ 3))² * (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) - (- ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3))) - 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) / (sqrt (sin x ^ 3 + cos x ^ 3))² = 9 * cos x * cos x * sin x * sin x * (sin x - cos x) * (sin x - cos x) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5) + ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) * (sin x ^ 3 + cos x ^ 3) / (8 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5) + 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5))›*) have "... = ( 288 * cos x * cos x * sin x * sin x * (sin x - cos x) * (sin x - cos x) + (3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) * (sin x ^ 3 + cos x ^ 3) * 8 + 144 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x)) / (64 * (sqrt (sin x ^ 3 + cos x ^ 3)) ^ 5)" by (simp add: divide_simps (*‹inverse ?a = 1 / ?a› ‹?a + ?b / ?z = (if ?z = 0 then ?a else (?a * ?z + ?b) / ?z)› ‹?a / ?z + ?b = (if ?z = 0 then ?b else (?a + ?b * ?z) / ?z)› ‹- (?a / ?z) + ?b = (if ?z = 0 then ?b else (- ?a + ?b * ?z) / ?z)› ‹?a - ?b / ?z = (if ?z = 0 then ?a else (?a * ?z - ?b) / ?z)› ‹?a / ?z - ?b = (if ?z = 0 then - ?b else (?a - ?b * ?z) / ?z)› ‹- (?a / ?z) - ?b = (if ?z = 0 then - ?b else (- ?a - ?b * ?z) / ?z)› ‹(?b / ?c = ?a) = (if ?c ≠ 0 then ?b = ?a * ?c else ?a = 0)› ‹(?a = ?b / ?c) = (if ?c ≠ 0 then ?a * ?c = ?b else ?a = 0)› ‹(- (?b / ?c) = ?a) = (if ?c ≠ 0 then - ?b = ?a * ?c else ?a = 0)› ‹(?a = - (?b / ?c)) = (if ?c ≠ 0 then ?a * ?c = - ?b else ?a = 0)› ‹(?a ≤ ?b / ?c) = (if 0 < ?c then ?a * ?c ≤ ?b else if ?c < 0 then ?b ≤ ?a * ?c else ?a ≤ 0)› and more 25 facts*)) also (*calculation: ‹9 * cos x * cos x * sin x * sin x * ((sin x - cos x) * (sin x - cos x)) / ((sqrt (sin x ^ 3 + cos x ^ 3))² * (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) - (- ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3))) - 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) / (sqrt (sin x ^ 3 + cos x ^ 3))² = (288 * cos x * cos x * sin x * sin x * (sin x - cos x) * (sin x - cos x) + (3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) * (sin x ^ 3 + cos x ^ 3) * 8 + 144 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x)) / (64 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5)›*) have "... = ( 432 * cos x * cos x * sin x * sin x * (sin x - cos x) * (sin x - cos x) + (24 * sin x + 24 * cos x + 72 * cos (3 * x) - 72 * sin (3 * x)) * (sin x ^ 3 + cos x ^ 3)) / (64 * (sqrt (sin x ^ 3 + cos x ^ 3)) ^ 5)" by (simp add: divide_simps (*‹inverse ?a = 1 / ?a› ‹?a + ?b / ?z = (if ?z = 0 then ?a else (?a * ?z + ?b) / ?z)› ‹?a / ?z + ?b = (if ?z = 0 then ?b else (?a + ?b * ?z) / ?z)› ‹- (?a / ?z) + ?b = (if ?z = 0 then ?b else (- ?a + ?b * ?z) / ?z)› ‹?a - ?b / ?z = (if ?z = 0 then ?a else (?a * ?z - ?b) / ?z)› ‹?a / ?z - ?b = (if ?z = 0 then - ?b else (?a - ?b * ?z) / ?z)› ‹- (?a / ?z) - ?b = (if ?z = 0 then - ?b else (- ?a - ?b * ?z) / ?z)› ‹(?b / ?c = ?a) = (if ?c ≠ 0 then ?b = ?a * ?c else ?a = 0)› ‹(?a = ?b / ?c) = (if ?c ≠ 0 then ?a * ?c = ?b else ?a = 0)› ‹(- (?b / ?c) = ?a) = (if ?c ≠ 0 then - ?b = ?a * ?c else ?a = 0)› ‹(?a = - (?b / ?c)) = (if ?c ≠ 0 then ?a * ?c = - ?b else ?a = 0)› ‹(?a ≤ ?b / ?c) = (if 0 < ?c then ?a * ?c ≤ ?b else if ?c < 0 then ?b ≤ ?a * ?c else ?a ≤ 0)› and more 25 facts*)) finally (*calculation: ‹9 * cos x * cos x * sin x * sin x * ((sin x - cos x) * (sin x - cos x)) / ((sqrt (sin x ^ 3 + cos x ^ 3))² * (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) - (- ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3))) - 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) / (sqrt (sin x ^ 3 + cos x ^ 3))² = (432 * cos x * cos x * sin x * sin x * (sin x - cos x) * (sin x - cos x) + (24 * sin x + 24 * cos x + 72 * cos (3 * x) - 72 * sin (3 * x)) * (sin x ^ 3 + cos x ^ 3)) / (64 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5)›*) show "?thesis" (*goal: ‹9 * cos x * cos x * sin x * sin x * ((sin x - cos x) * (sin x - cos x)) / ((sqrt (sin x ^ 3 + cos x ^ 3))² * (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) - (- ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3))) - 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) / (sqrt (sin x ^ 3 + cos x ^ 3))² = (90 + 6 * cos (4 * x) - 123 * sin (2 * x) + 9 * sin (6 * x)) / (64 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5)›*) apply simp (*goal: ‹9 * cos x * cos x * sin x * sin x * ((sin x - cos x) * (sin x - cos x)) / ((sqrt (sin x ^ 3 + cos x ^ 3))² * (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) - (- ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3))) - 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) / (sqrt (sin x ^ 3 + cos x ^ 3))² = (90 + 6 * cos (4 * x) - 123 * sin (2 * x) + 9 * sin (6 * x)) / (64 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5)›*) by (force intro: disjI2 (*‹?Q ⟹ ?P ∨ ?Q›*) simp add: power2_eq_square (*‹?a² = ?a * ?a›*) power4_eq_xxxx (*‹?x ^ 4 = ?x * ?x * ?x * ?x›*) power3_eq_cube (*‹?a ^ 3 = ?a * ?a * ?a›*) cos_times_sin (*‹cos ?w * sin ?z = (sin (?w + ?z) - sin (?w - ?z)) / 2›*) sin_times_cos (*‹sin ?w * cos ?z = (sin (?w + ?z) + sin (?w - ?z)) / 2›*) cos_times_cos (*‹cos ?w * cos ?z = (cos (?w - ?z) + cos (?w + ?z)) / 2›*) sin_times_sin (*‹sin ?w * sin ?z = (cos (?w - ?z) - cos (?w + ?z)) / 2›*) right_diff_distrib (*‹?a * (?b - ?c) = ?a * ?b - ?a * ?c›*) power6 (*‹?z ^ 6 = ?z * ?z * ?z * ?z * ?z * ?z›*) power5 (*‹?z ^ 5 = ?z * ?z * ?z * ?z * ?z›*) distrib_left (*‹?a * (?b + ?c) = ?a * ?b + ?a * ?c›*) distrib_right (*‹(?a + ?b) * ?c = ?a * ?c + ?b * ?c›*) left_diff_distrib (*‹(?a - ?b) * ?c = ?a * ?c - ?b * ?c›*) divide_simps (*‹inverse ?a = 1 / ?a› ‹?a + ?b / ?z = (if ?z = 0 then ?a else (?a * ?z + ?b) / ?z)› ‹?a / ?z + ?b = (if ?z = 0 then ?b else (?a + ?b * ?z) / ?z)› ‹- (?a / ?z) + ?b = (if ?z = 0 then ?b else (- ?a + ?b * ?z) / ?z)› ‹?a - ?b / ?z = (if ?z = 0 then ?a else (?a * ?z - ?b) / ?z)› ‹?a / ?z - ?b = (if ?z = 0 then - ?b else (?a - ?b * ?z) / ?z)› ‹- (?a / ?z) - ?b = (if ?z = 0 then - ?b else (- ?a - ?b * ?z) / ?z)› ‹(?b / ?c = ?a) = (if ?c ≠ 0 then ?b = ?a * ?c else ?a = 0)› ‹(?a = ?b / ?c) = (if ?c ≠ 0 then ?a * ?c = ?b else ?a = 0)› ‹(- (?b / ?c) = ?a) = (if ?c ≠ 0 then - ?b = ?a * ?c else ?a = 0)› ‹(?a = - (?b / ?c)) = (if ?c ≠ 0 then ?a * ?c = - ?b else ?a = 0)› ‹(?a ≤ ?b / ?c) = (if 0 < ?c then ?a * ?c ≤ ?b else if ?c < 0 then ?b ≤ ?a * ?c else ?a ≤ 0)› and more 25 facts*)) qed then show "?thesis" (*goal: ‹inverse ((*h* sqrt) ((*h* (λx. x ^ 3)) ((*h* sin) (β x)) + (*h* (λx. x ^ 3)) ((*h* cos) (β x)))) = inverse (sqrt (sin x ^ 3 + cos x ^ 3)) *⇩H ba + - (3 * cos x * sin x * (sin x - cos x) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) *⇩H e1 + - (3 * cos x * sin x * (sin x - cos x) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) *⇩H e2 + (3 * (30 + 2 * cos (4 * x) - 41 * sin (2 * x) + 3 * sin (6 * x)) / (64 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5)) *⇩H e12›*) by (simp add: w7b (*‹inverse ((*h* sqrt) ((*h* (λx. x ^ 3)) ((*h* sin) (β x)) + (*h* (λx. x ^ 3)) ((*h* cos) (β x)))) = inverse (sqrt (sin x ^ 3 + cos x ^ 3)) *⇩H ba + - (3 * cos x * sin x * (sin x - cos x) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) *⇩H e1 + - (3 * cos x * sin x * (sin x - cos x) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) *⇩H e2 + (9 * cos x * cos x * sin x * sin x * ((sin x - cos x) * (sin x - cos x) / (sqrt (sin x ^ 3 + cos x ^ 3))²) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3) - (- ((3 * sin x + 3 * cos x + 9 * cos (3 * x) - 9 * sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3))) - 9 * cos x * sin x * (sin x - cos x) * cos x * sin x * (sin x - cos x) / (4 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) / (sqrt (sin x ^ 3 + cos x ^ 3))²) *⇩H e12›*)) qed let ?w8 = "?w1 * ?w7" have w8: "?w8 = ((exp x)/(sqrt(sin x ^ 3 + cos x ^ 3))) *⇩H ba + ((exp x * (3 * cos x + 5 * cos (3 * x) + 9 * sin x + sin (3 * x)))/(8 * (sqrt (sin x ^ 3 + cos x ^ 3)) ^ 3)) *⇩H e1 + ((exp x * (3 * cos x + 5 * cos (3 * x) + 9 * sin x + sin (3 * x)))/(8 * (sqrt (sin x ^ 3 + cos x ^ 3)) ^ 3)) *⇩H e2 + ((exp x * (130 - 12 * cos (2 * x) + 30 * cos (4 * x) + 12 * cos (6 * x) - 111 * sin (2 * x) + 48 * sin (4 * x) + 5 * sin (6 * x)))/(64 * (sqrt (sin x ^ 3 + cos x ^ 3)) ^ 5)) *⇩H e12" proof (auto simp add: w7 (*‹inverse ((*h* sqrt) ((*h* (λx. x ^ 3)) ((*h* sin) (β x)) + (*h* (λx. x ^ 3)) ((*h* cos) (β x)))) = inverse (sqrt (sin x ^ 3 + cos x ^ 3)) *⇩H ba + - (3 * cos x * sin x * (sin x - cos x) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) *⇩H e1 + - (3 * cos x * sin x * (sin x - cos x) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) *⇩H e2 + (3 * (30 + 2 * cos (4 * x) - 41 * sin (2 * x) + 3 * sin (6 * x)) / (64 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5)) *⇩H e12›*) w1 (*‹(*h* exp) (β x) = exp x *⇩H ba + exp x *⇩H e1 + exp x *⇩H e2 + exp x *⇩H e12›*) times_hyperdual_parts (*‹(?a *⇩H ba + ?b *⇩H e1 + ?c *⇩H e2 + ?d *⇩H e12) * (?a' *⇩H ba + ?b' *⇩H e1 + ?c' *⇩H e2 + ?d' *⇩H e12) = (?a * ?a') *⇩H ba + (?a * ?b' + ?b * ?a') *⇩H e1 + (?a * ?c' + ?c * ?a') *⇩H e2 + (?a * ?d' + ?b * ?c' + ?c * ?b' + ?d * ?a') *⇩H e12›*)) (*goals: 1. ‹exp x * inverse (sqrt (sin x ^ 3 + cos x ^ 3)) = exp x / sqrt (sin x ^ 3 + cos x ^ 3)› 2. ‹exp x * inverse (sqrt (sin x ^ 3 + cos x ^ 3)) - exp x * (3 * cos x * sin x * (sin x - cos x)) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3) = exp x * (3 * cos x + 5 * cos (3 * x) + 9 * sin x + sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)› 3. ‹exp x * (90 + 6 * cos (4 * x) - 123 * sin (2 * x) + 9 * sin (6 * x)) / (64 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5) - 3 * (cos x * (exp x * (sin x * (sin x - cos x)))) / sqrt (sin x ^ 3 + cos x ^ 3) ^ 3 + exp x * inverse (sqrt (sin x ^ 3 + cos x ^ 3)) = exp x * (130 - 12 * cos (2 * x) + 30 * cos (4 * x) + 12 * cos (6 * x) - 111 * sin (2 * x) + 48 * sin (4 * x) + 5 * sin (6 * x)) / (64 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5)›*) show "exp x * inverse (sqrt (sin x ^ 3 + cos x ^ 3)) = exp x / sqrt (sin x ^ 3 + cos x ^ 3)" by (simp add: divide_inverse (*‹(?a::?'a::division_ring) / (?b::?'a::division_ring) = ?a * inverse ?b›*)) have sqrt_sc3: "sqrt (sin x ^ 3 + cos x ^ 3) ^ 3 = (sin x ^ 3 + cos x ^ 3) * sqrt (sin x ^ 3 + cos x ^ 3)" using s3_c3_gt_zero (*‹(0::real) < sin (x::real) ^ (3::nat) + cos x ^ (3::nat)›*) by (simp add: power3_eq_cube (*‹?a ^ 3 = ?a * ?a * ?a›*)) then have "inverse (sqrt (sin x ^ 3 + cos x ^ 3)) - (3 * cos x * sin x * (sin x - cos x)) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3) = (3 * cos x + 5 * cos (3 * x) + 9 * sin x + sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)" using sqrt_pos (*‹0 < Base ((*h* (λx. x ^ 3)) ((*h* sin) (β x)) + (*h* (λx. x ^ 3)) ((*h* cos) (β x)))›*) apply (simp add: right_diff_distrib' (*‹?a * (?b - ?c) = ?a * ?b - ?a * ?c›*) sin_times_sin (*‹sin ?w * sin ?z = (cos (?w - ?z) - cos (?w + ?z)) / 2›*) cos_times_cos (*‹cos ?w * cos ?z = (cos (?w - ?z) + cos (?w + ?z)) / 2›*) sin_times_cos (*‹sin ?w * cos ?z = (sin (?w + ?z) + sin (?w - ?z)) / 2›*) cos_times_sin (*‹cos ?w * sin ?z = (sin (?w + ?z) - sin (?w - ?z)) / 2›*) power3_eq_cube (*‹?a ^ 3 = ?a * ?a * ?a›*) left_diff_distrib' (*‹(?b - ?c) * ?a = ?b * ?a - ?c * ?a›*) divide_simps (*‹inverse ?a = 1 / ?a› ‹?a + ?b / ?z = (if ?z = 0 then ?a else (?a * ?z + ?b) / ?z)› ‹?a / ?z + ?b = (if ?z = 0 then ?b else (?a + ?b * ?z) / ?z)› ‹- (?a / ?z) + ?b = (if ?z = 0 then ?b else (- ?a + ?b * ?z) / ?z)› ‹?a - ?b / ?z = (if ?z = 0 then ?a else (?a * ?z - ?b) / ?z)› ‹?a / ?z - ?b = (if ?z = 0 then - ?b else (?a - ?b * ?z) / ?z)› ‹- (?a / ?z) - ?b = (if ?z = 0 then - ?b else (- ?a - ?b * ?z) / ?z)› ‹(?b / ?c = ?a) = (if ?c ≠ 0 then ?b = ?a * ?c else ?a = 0)› ‹(?a = ?b / ?c) = (if ?c ≠ 0 then ?a * ?c = ?b else ?a = 0)› ‹(- (?b / ?c) = ?a) = (if ?c ≠ 0 then - ?b = ?a * ?c else ?a = 0)› ‹(?a = - (?b / ?c)) = (if ?c ≠ 0 then ?a * ?c = - ?b else ?a = 0)› ‹(?a ≤ ?b / ?c) = (if 0 < ?c then ?a * ?c ≤ ?b else if ?c < 0 then ?b ≤ ?a * ?c else ?a ≤ 0)› and more 25 facts*)) (*goal: ‹inverse (sqrt (sin x ^ 3 + cos x ^ 3)) - 3 * cos x * sin x * (sin x - cos x) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3) = (3 * cos x + 5 * cos (3 * x) + 9 * sin x + sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)›*) by (simp add: distrib_right (*‹(?a + ?b) * ?c = ?a * ?c + ?b * ?c›*) cos_times_cos (*‹cos ?w * cos ?z = (cos (?w - ?z) + cos (?w + ?z)) / 2›*)) then show " exp x * inverse (sqrt (sin x ^ 3 + cos x ^ 3)) - exp x * (3 * cos x * sin x * (sin x - cos x)) / (2 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3) = exp x * (3 * cos x + 5 * cos (3 * x) + 9 * sin x + sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)" by (simp add: algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 34 facts*)) have "sqrt (sin x ^ 3 + cos x ^ 3) ^ 8 = (sin x ^ 3 + cos x ^ 3) ^ 4" using s3_c3_gt_zero (*‹0 < sin x ^ 3 + cos x ^ 3›*) by (smt mult_2 (*‹2 * ?z = ?z + ?z›*) numeral_Bit0 (*‹numeral (num.Bit0 ?n) = numeral ?n + numeral ?n›*) power2_eq_square (*‹?a² = ?a * ?a›*) power_even_eq (*‹?a ^ (2 * ?n) = (?a ^ ?n)²›*) real_sqrt_mult_self (*‹sqrt ?a * sqrt ?a = ¦?a¦›*)) moreover have "sqrt (sin x ^ 3 + cos x ^ 3) ^ 5 = (sin x ^ 3 + cos x ^ 3) ^ 2 * sqrt (sin x ^ 3 + cos x ^ 3)" by (simp add: mult.assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) power2_eq_square (*‹?a² = ?a * ?a›*) power5 (*‹?z ^ 5 = ?z * ?z * ?z * ?z * ?z›*)) ultimately have "(90 + 6 * cos (4 * x) - 123 * sin (2 * x) + 9 * sin (6 * x)) / (64 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5) - 3 * (cos x * ((sin x * (sin x - cos x)))) / sqrt (sin x ^ 3 + cos x ^ 3) ^ 3 + inverse (sqrt (sin x ^ 3 + cos x ^ 3)) = (130 - 12 * cos (2 * x) + 30 * cos (4 * x) + 12 * cos (6 * x) - 111 * sin (2 * x) + 48 * sin (4 * x) + 5 * sin (6 * x)) / (64 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5)" using sqrt_pos (*‹0 < Base ((*h* (λx. x ^ 3)) ((*h* sin) (β x)) + (*h* (λx. x ^ 3)) ((*h* cos) (β x)))›*) apply (simp add: sqrt_sc3 (*‹sqrt (sin x ^ 3 + cos x ^ 3) ^ 3 = (sin x ^ 3 + cos x ^ 3) * sqrt (sin x ^ 3 + cos x ^ 3)›*) power2_eq_square (*‹?a² = ?a * ?a›*) divide_simps (*‹inverse ?a = 1 / ?a› ‹?a + ?b / ?z = (if ?z = 0 then ?a else (?a * ?z + ?b) / ?z)› ‹?a / ?z + ?b = (if ?z = 0 then ?b else (?a + ?b * ?z) / ?z)› ‹- (?a / ?z) + ?b = (if ?z = 0 then ?b else (- ?a + ?b * ?z) / ?z)› ‹?a - ?b / ?z = (if ?z = 0 then ?a else (?a * ?z - ?b) / ?z)› ‹?a / ?z - ?b = (if ?z = 0 then - ?b else (?a - ?b * ?z) / ?z)› ‹- (?a / ?z) - ?b = (if ?z = 0 then - ?b else (- ?a - ?b * ?z) / ?z)› ‹(?b / ?c = ?a) = (if ?c ≠ 0 then ?b = ?a * ?c else ?a = 0)› ‹(?a = ?b / ?c) = (if ?c ≠ 0 then ?a * ?c = ?b else ?a = 0)› ‹(- (?b / ?c) = ?a) = (if ?c ≠ 0 then - ?b = ?a * ?c else ?a = 0)› ‹(?a = - (?b / ?c)) = (if ?c ≠ 0 then ?a * ?c = - ?b else ?a = 0)› ‹(?a ≤ ?b / ?c) = (if 0 < ?c then ?a * ?c ≤ ?b else if ?c < 0 then ?b ≤ ?a * ?c else ?a ≤ 0)› and more 25 facts*)) (*goal: ‹(90 + 6 * cos (4 * x) - 123 * sin (2 * x) + 9 * sin (6 * x)) / (64 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5) - 3 * (cos x * (sin x * (sin x - cos x))) / sqrt (sin x ^ 3 + cos x ^ 3) ^ 3 + inverse (sqrt (sin x ^ 3 + cos x ^ 3)) = (130 - 12 * cos (2 * x) + 30 * cos (4 * x) + 12 * cos (6 * x) - 111 * sin (2 * x) + 48 * sin (4 * x) + 5 * sin (6 * x)) / (64 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5)›*) by (simp add: distrib_right (*‹(?a + ?b) * ?c = ?a * ?c + ?b * ?c›*) distrib_left (*‹?a * (?b + ?c) = ?a * ?b + ?a * ?c›*) power3_eq_cube (*‹?a ^ 3 = ?a * ?a * ?a›*) sin_times_sin (*‹sin ?w * sin ?z = (cos (?w - ?z) - cos (?w + ?z)) / 2›*) sin_times_cos (*‹sin ?w * cos ?z = (sin (?w + ?z) + sin (?w - ?z)) / 2›*) cos_times_cos (*‹cos ?w * cos ?z = (cos (?w - ?z) + cos (?w + ?z)) / 2›*) cos_times_sin (*‹cos ?w * sin ?z = (sin (?w + ?z) - sin (?w - ?z)) / 2›*) right_diff_distrib' (*‹?a * (?b - ?c) = ?a * ?b - ?a * ?c›*) left_diff_distrib' (*‹(?b - ?c) * ?a = ?b * ?a - ?c * ?a›*) divide_simps (*‹inverse ?a = 1 / ?a› ‹?a + ?b / ?z = (if ?z = 0 then ?a else (?a * ?z + ?b) / ?z)› ‹?a / ?z + ?b = (if ?z = 0 then ?b else (?a + ?b * ?z) / ?z)› ‹- (?a / ?z) + ?b = (if ?z = 0 then ?b else (- ?a + ?b * ?z) / ?z)› ‹?a - ?b / ?z = (if ?z = 0 then ?a else (?a * ?z - ?b) / ?z)› ‹?a / ?z - ?b = (if ?z = 0 then - ?b else (?a - ?b * ?z) / ?z)› ‹- (?a / ?z) - ?b = (if ?z = 0 then - ?b else (- ?a - ?b * ?z) / ?z)› ‹(?b / ?c = ?a) = (if ?c ≠ 0 then ?b = ?a * ?c else ?a = 0)› ‹(?a = ?b / ?c) = (if ?c ≠ 0 then ?a * ?c = ?b else ?a = 0)› ‹(- (?b / ?c) = ?a) = (if ?c ≠ 0 then - ?b = ?a * ?c else ?a = 0)› ‹(?a = - (?b / ?c)) = (if ?c ≠ 0 then ?a * ?c = - ?b else ?a = 0)› ‹(?a ≤ ?b / ?c) = (if 0 < ?c then ?a * ?c ≤ ?b else if ?c < 0 then ?b ≤ ?a * ?c else ?a ≤ 0)› and more 25 facts*)) moreover have "∀r a b c. (a::real) * b - c * (a * r) = a * (b - c * r)" by (simp add: right_diff_distrib (*‹?a * (?b - ?c) = ?a * ?b - ?a * ?c›*)) ultimately show "exp x * (90 + 6 * cos (4 * x) - 123 * sin (2 * x) + 9 * sin (6 * x)) / (64 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5) - 3 * (cos x * (exp x * (sin x * (sin x - cos x)))) / sqrt (sin x ^ 3 + cos x ^ 3) ^ 3 + exp x * inverse (sqrt (sin x ^ 3 + cos x ^ 3)) = exp x * (130 - 12 * cos (2 * x) + 30 * cos (4 * x) + 12 * cos (6 * x) - 111 * sin (2 * x) + 48 * sin (4 * x) + 5 * sin (6 * x)) / (64 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5)" by (metis (mono_tags, opaque_lifting) distrib_left (*‹?a * (?b + ?c) = ?a * ?b + ?a * ?c›*) mult.left_commute (*‹?b * (?a * ?c) = ?a * (?b * ?c)›*) times_divide_eq_right (*‹?a * (?b / ?c) = ?a * ?b / ?c›*)) qed moreover have w8_eq_hyp_fa_test: "?w8 = (*h* fa_test) (β x)" using assms (*‹x ∈ (⋃x. {- pi / 4 + 2 * pi * real_of_int x<..<3 * pi / 4 + 2 * pi * real_of_int x})›*) by (simp add: hyp_divide_inverse (*‹(?a::?'a hyperdual) / (?b::?'a hyperdual) = ?a * inverse ?b›*) hyp_fa_test_def (*‹hyp_fa_test (?x::real hyperdual) = (*h* exp) ?x / (*h* sqrt) ((*h* sin) ?x ^ (3::nat) + (*h* cos) ?x ^ (3::nat))›*) hypext_fa_test (*‹Base (?x::real hyperdual) ∈ (⋃x::int. {- pi / (4::real) + (2::real) * pi * real_of_int x<..<(3::real) * pi / (4::real) + (2::real) * pi * real_of_int x}) ⟹ (*h* fa_test) ?x = hyp_fa_test ?x›*) hypext_power (*‹(*h* (λx::?'a. x ^ (?n::nat))) (?x::?'a hyperdual) = ?x ^ ?n›*)) ultimately show "First (autodiff fa_test x) = (exp x * (3 * cos x + 5 * cos (3 * x) + 9 * sin x + sin (3 * x))) / (8 * (sqrt (sin x ^ 3 + cos x ^ 3)) ^ 3)" and "Second (autodiff fa_test x) = exp x * (130 - 12 * cos (2 * x) + 30 * cos (4 * x) + 12 * cos (6 * x) - 111 * sin (2 * x) + 48 * sin (4 * x) + 5 * sin (6 * x)) / (64 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5)" apply - (*goals: 1. ‹⟦(*h* exp) (β x) * inverse ((*h* sqrt) ((*h* (λx. x ^ 3)) ((*h* sin) (β x)) + (*h* (λx. x ^ 3)) ((*h* cos) (β x)))) = (exp x / sqrt (sin x ^ 3 + cos x ^ 3)) *⇩H ba + (exp x * (3 * cos x + 5 * cos (3 * x) + 9 * sin x + sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) *⇩H e1 + (exp x * (3 * cos x + 5 * cos (3 * x) + 9 * sin x + sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) *⇩H e2 + (exp x * (130 - 12 * cos (2 * x) + 30 * cos (4 * x) + 12 * cos (6 * x) - 111 * sin (2 * x) + 48 * sin (4 * x) + 5 * sin (6 * x)) / (64 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5)) *⇩H e12; (*h* exp) (β x) * inverse ((*h* sqrt) ((*h* (λx. x ^ 3)) ((*h* sin) (β x)) + (*h* (λx. x ^ 3)) ((*h* cos) (β x)))) = (*h* fa_test) (β x)⟧ ⟹ First (autodiff fa_test x) = exp x * (3 * cos x + 5 * cos (3 * x) + 9 * sin x + sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)› 2. ‹⟦(*h* exp) (β x) * inverse ((*h* sqrt) ((*h* (λx. x ^ 3)) ((*h* sin) (β x)) + (*h* (λx. x ^ 3)) ((*h* cos) (β x)))) = (exp x / sqrt (sin x ^ 3 + cos x ^ 3)) *⇩H ba + (exp x * (3 * cos x + 5 * cos (3 * x) + 9 * sin x + sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) *⇩H e1 + (exp x * (3 * cos x + 5 * cos (3 * x) + 9 * sin x + sin (3 * x)) / (8 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 3)) *⇩H e2 + (exp x * (130 - 12 * cos (2 * x) + 30 * cos (4 * x) + 12 * cos (6 * x) - 111 * sin (2 * x) + 48 * sin (4 * x) + 5 * sin (6 * x)) / (64 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5)) *⇩H e12; (*h* exp) (β x) * inverse ((*h* sqrt) ((*h* (λx. x ^ 3)) ((*h* sin) (β x)) + (*h* (λx. x ^ 3)) ((*h* cos) (β x)))) = (*h* fa_test) (β x)⟧ ⟹ Second (autodiff fa_test x) = exp x * (130 - 12 * cos (2 * x) + 30 * cos (4 * x) + 12 * cos (6 * x) - 111 * sin (2 * x) + 48 * sin (4 * x) + 5 * sin (6 * x)) / (64 * sqrt (sin x ^ 3 + cos x ^ 3) ^ 5)› discuss goal 1*) apply (metis autodiff_sel (*‹Value (autodiff ?f ?x) = Base ((*h* ?f) (β ?x))› ‹First (autodiff ?f ?x) = Eps1 ((*h* ?f) (β ?x))› ‹Second (autodiff ?f ?x) = Eps12 ((*h* ?f) (β ?x))›*) hyperdual_comb_sel (*‹Base (?a *⇩H ba + ?b *⇩H e1 + ?c *⇩H e2 + ?d *⇩H e12) = ?a› ‹Eps1 (?a *⇩H ba + ?b *⇩H e1 + ?c *⇩H e2 + ?d *⇩H e12) = ?b› ‹Eps2 (?a *⇩H ba + ?b *⇩H e1 + ?c *⇩H e2 + ?d *⇩H e12) = ?c› ‹Eps12 (?a *⇩H ba + ?b *⇩H e1 + ?c *⇩H e2 + ?d *⇩H e12) = ?d›*)) (*discuss goal 2*) apply (metis autodiff_sel (*‹Value (autodiff ?f ?x) = Base ((*h* ?f) (β ?x))› ‹First (autodiff ?f ?x) = Eps1 ((*h* ?f) (β ?x))› ‹Second (autodiff ?f ?x) = Eps12 ((*h* ?f) (β ?x))›*) hyperdual_comb_sel (*‹Base (?a *⇩H ba + ?b *⇩H e1 + ?c *⇩H e2 + ?d *⇩H e12) = ?a› ‹Eps1 (?a *⇩H ba + ?b *⇩H e1 + ?c *⇩H e2 + ?d *⇩H e12) = ?b› ‹Eps2 (?a *⇩H ba + ?b *⇩H e1 + ?c *⇩H e2 + ?d *⇩H e12) = ?c› ‹Eps12 (?a *⇩H ba + ?b *⇩H e1 + ?c *⇩H e2 + ?d *⇩H e12) = ?d›*)) (*proven 2 subgoals*) . qed end
{ "path": "afp-2025-02-12/thys/Hyperdual/AnalyticTestFunction.thy", "repo": "afp-2025-02-12", "sha": "2625d1b46c1b37d8606629dc6bc5f7769f6d5e31e2bd79f334b8c8ed8b801114" }
(*<*) ―‹ ******************************************************************** * Project : HOL-CSP - A Shallow Embedding of CSP in Isabelle/HOL * Version : 2.0 * * Author : Burkhart Wolff, Safouan Taha, Lina Ye. * (Based on HOL-CSP 1.0 by Haykal Tej and Burkhart Wolff) * * This file : A Combined CSP Theory * * Copyright (c) 2009 Université Paris-Sud, France * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * * Neither the name of the copyright holders nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************› (*>*) chapter‹ Annex: Refinement Example with Buffer over infinite Alphabet› theory CopyBuffer imports CSP "Assertions" begin section‹ Defining the Copy-Buffer Example › datatype 'a channel = left 'a | right 'a | mid 'a | ack definition SYN :: "('a channel) set" where "SYN ≡ (range mid) ∪ {ack}" definition COPY :: "('a channel) process" where "COPY ≡ (μ COPY. left❙?x → (right❙!x → COPY))" definition SEND :: "('a channel) process" where "SEND ≡ (μ SEND. left❙?x → (mid❙!x →( ack → SEND)))" definition REC :: "('a channel) process" where "REC ≡ (μ REC. mid❙?x → (right❙!x → (ack → REC)))" definition SYSTEM :: "('a channel) process" where ‹SYSTEM ≡ (SEND ⟦ SYN ⟧ REC) \ SYN› thm SYSTEM_def section‹ The Standard Proof › subsection‹ Channels and Synchronization Sets› text‹ First part: abstract properties for these events to SYN. This kind of stuff could be automated easily by some extra-syntax for channels and SYN-sets. › lemma [simp]: "left x ∉ SYN" by (auto simp: SYN_def (*‹SYN ≡ range mid ∪ {ack}›*)) lemma [simp]: "right x ∉ SYN" by (auto simp: SYN_def (*‹SYN ≡ range mid ∪ {ack}›*)) lemma [simp]: "ack ∈ SYN" by (auto simp: SYN_def (*‹SYN ≡ range mid ∪ {ack}›*)) lemma [simp]: "mid x ∈ SYN" by (auto simp: SYN_def (*‹SYN ≡ range mid ∪ {ack}›*)) lemma [simp]: "inj mid" by (auto simp: inj_on_def (*‹inj_on ?f ?A = (∀x∈?A. ∀y∈?A. ?f x = ?f y ⟶ x = y)›*)) lemma "finite (SYN:: 'a channel set) ⟹ finite {(t::'a). True}" by (metis (no_types) SYN_def (*‹SYN ≡ range mid ∪ {ack}›*) UNIV_def (*‹UNIV = {x. True}›*) channel.inject( (*‹(mid ?x3.0 = mid ?y3.0) = (?x3.0 = ?y3.0)›*) 3) finite_Un (*‹finite (?F ∪ ?G) = (finite ?F ∧ finite ?G)›*) finite_imageD (*‹⟦finite (?f ` ?A); inj_on ?f ?A⟧ ⟹ finite ?A›*) inj_on_def (*‹inj_on ?f ?A = (∀x∈?A. ∀y∈?A. ?f x = ?f y ⟶ x = y)›*)) subsection‹ Definitions by Recursors › text‹ Second part: Derive recursive process equations, which are easier to handle in proofs. This part IS actually automated if we could reuse the fixrec-syntax below. › lemma COPY_rec: "COPY = left❙?x → right❙!x → COPY" apply (simp add: COPY_def (*‹COPY ≡ μ x::?'a::type channel process. left❙?xa::?'a::type → right❙!xa → x›*)) (*goal: ‹COPY = left❙?x::'a::type → right❙!x → COPY›*) apply (rule trans (*‹⟦?r = ?s; ?s = ?t⟧ ⟹ ?r = ?t›*)) (*goals: 1. ‹(μ x. left❙?xa → right❙!xa → x) = ?s› 2. ‹?s = left❙?x → right❙!x → (μ x. left❙?xa → right❙!xa → x)› discuss goal 1*) apply (rule fix_eq (*‹fix⋅(?F::?'a → ?'a) = ?F⋅(fix⋅?F)›*)) (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma SEND_rec: "SEND = left❙?x → mid❙!x → (ack → SEND)" apply (simp add: SEND_def (*‹SEND ≡ μ x::?'a channel process. left❙?xa::?'a → mid❙!xa → ack → x›*)) (*goal: ‹SEND = left❙?x → mid❙!x → ack → SEND›*) apply (rule trans (*‹⟦(?r::?'a) = (?s::?'a); ?s = (?t::?'a)⟧ ⟹ ?r = ?t›*)) (*goals: 1. ‹(μ x::'a channel process. left❙?xa::'a → mid❙!xa → ack → x) = (?s::'a channel process)› 2. ‹(?s::'a channel process) = left❙?x::'a → mid❙!x → ack → (μ x::'a channel process. left❙?xa::'a → mid❙!xa → ack → x)› discuss goal 1*) apply (rule fix_eq (*‹fix⋅?F = ?F⋅(fix⋅?F)›*)) (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma REC_rec: "REC = mid❙?x → right❙!x → (ack → REC)" apply (simp add: REC_def (*‹REC ≡ μ x. mid❙?xa → right❙!xa → ack → x›*)) (*goal: ‹REC = mid❙?x → right❙!x → ack → REC›*) apply (rule trans (*‹⟦?r = ?s; ?s = ?t⟧ ⟹ ?r = ?t›*)) (*goals: 1. ‹(μ x::'a::type channel process. mid❙?xa::'a::type → right❙!xa → ack → x) = (?s::'a::type channel process)› 2. ‹(?s::'a::type channel process) = mid❙?x::'a::type → right❙!x → ack → (μ x::'a::type channel process. mid❙?xa::'a::type → right❙!xa → ack → x)› discuss goal 1*) apply (rule fix_eq (*‹fix⋅?F = ?F⋅(fix⋅?F)›*)) (*discuss goal 2*) apply simp (*proven 2 subgoals*) . subsection‹ A Refinement Proof › text‹ Third part: No comes the proof by fixpoint induction. Not too bad in automation considering what is inferred, but wouldn't scale for large examples. › lemma impl_refines_spec : "COPY ⊑⇩F⇩D SYSTEM" sorry lemma spec_refines_impl : assumes fin: "finite (SYN:: 'a channel set)" shows "SYSTEM ⊑⇩F⇩D (COPY :: 'a channel process)" apply (simp add: SYSTEM_def (*‹SYSTEM ≡ SEND ⟦SYN⟧ REC \ SYN›*) SEND_def (*‹SEND ≡ μ x. left❙?xa → mid❙!xa → ack → x›*)) (*goal: ‹SYSTEM ⊑⇩F⇩D COPY›*) apply (rule fix_ind (*‹⟦adm ?P; ?P ⊥; ⋀x. ?P x ⟹ ?P (?F⋅x)⟧ ⟹ ?P (fix⋅?F)›*)) (*goals: 1. ‹adm (λa. (a ⟦SYN⟧ REC \ SYN) ⊑⇩F⇩D COPY)› 2. ‹(⊥ ⟦SYN⟧ REC \ SYN) ⊑⇩F⇩D COPY› 3. ‹⋀x. (x ⟦SYN⟧ REC \ SYN) ⊑⇩F⇩D COPY ⟹ ((Λ x. left❙?xa → mid❙!xa → ack → x)⋅x ⟦SYN⟧ REC \ SYN) ⊑⇩F⇩D COPY› discuss goal 1*) apply (intro le_FD_adm (*‹⟦cont ?u; monofun ?v⟧ ⟹ adm (λx. ?u x ⊑⇩F⇩D ?v x)›*)) (*goals: 1. ‹cont (λx. x ⟦SYN⟧ REC \ SYN)› 2. ‹monofun (λx. COPY)› discuss goal 1*) apply (simp add: fin (*‹finite SYN›*)) (*discuss goal 2*) apply (simp add: cont2mono (*‹cont ?f ⟹ monofun ?f›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply (simp add: Hiding_set_BOT (*‹⊥ \ ?A = ⊥›*) Sync_BOT (*‹?P ⟦?S⟧ ⊥ = ⊥›*) Sync_commute (*‹?P ⟦?S⟧ ?Q = ?Q ⟦?S⟧ ?P›*)) (*discuss goal 3*) apply simp (*goal: ‹⋀x. (x ⟦SYN⟧ REC \ SYN) ⊑⇩F⇩D COPY ⟹ ((Λ x. left❙?xa → mid❙!xa → ack → x)⋅x ⟦SYN⟧ REC \ SYN) ⊑⇩F⇩D COPY›*) apply (subst COPY_rec (*‹COPY = left❙?x → right❙!x → COPY›*)) (*goal: ‹⋀x. (x ⟦SYN⟧ REC \ SYN) ⊑⇩F⇩D COPY ⟹ (left❙?xa → mid❙!xa → ack → x ⟦SYN⟧ REC \ SYN) ⊑⇩F⇩D COPY›*) apply (subst REC_rec (*‹REC = mid❙?x → right❙!x → ack → REC›*)) (*goal: ‹⋀x. (x ⟦SYN⟧ REC \ SYN) ⊑⇩F⇩D COPY ⟹ (left❙?xa → mid❙!xa → ack → x ⟦SYN⟧ REC \ SYN) ⊑⇩F⇩D left❙?x → right❙!x → COPY›*) apply (simp add: Sync_rules (*‹?a ∈ ?S ⟹ ?a → ?P ⟦?S⟧ ?a → ?Q = ?a → (?P ⟦?S⟧ ?Q)› ‹(⋀y. ?c y ∈ ?S) ⟹ read ?c UNIV ?P ⟦?S⟧ read ?c UNIV ?Q = ?c❙?x → (?P x ⟦?S⟧ ?Q x)› ‹⟦⋀y. ?c y ∉ ?S; ⋀y. ?d y ∈ ?S⟧ ⟹ read ?c UNIV ?P ⟦?S⟧ read ?d UNIV ?Q = ?c❙?x → (?P x ⟦?S⟧ read ?d UNIV ?Q)› ‹⟦⋀y. ?c y ∈ ?S; inj ?c⟧ ⟹ ?c❙!?a → ?P ⟦?S⟧ read ?c UNIV ?Q = ?c❙!?a → (?P ⟦?S⟧ ?Q ?a)› ‹⟦?d ?a ∉ ?S; ⋀y. ?c y ∈ ?S⟧ ⟹ ?d❙!?a → ?P ⟦?S⟧ read ?c UNIV ?Q = ?d❙!?a → (?P ⟦?S⟧ read ?c UNIV ?Q)› ‹⟦?d ∈ ?S; ⋀y. ?c y ∉ ?S⟧ ⟹ ?d → ?P ⟦?S⟧ read ?c UNIV ?Q = ?c❙?x → (?d → ?P ⟦?S⟧ ?Q x)› ‹⟦?d ?a ∉ ?C; ?c ∈ ?C⟧ ⟹ ?c → ?Q ⟦?C⟧ ?d❙!?a → ?P = ?d❙!?a → (?c → ?Q ⟦?C⟧ ?P)›*) Hiding_rules (*‹∀y. ?c y ∉ ?B ⟹ read ?c UNIV ?P \ ?B = ?c❙?x → (?P x \ ?B)› ‹∀y. ?c y ∉ ?B ⟹ ?c❙!?a → ?P \ ?B = ?c❙!?a → (?P \ ?B)› ‹?c ?a ∈ ?B ⟹ ?c❙!?a → ?P \ ?B = ?P \ ?B› ‹?a ∈ ?B ⟹ ?a → ?P \ ?B = ?P \ ?B›*)) (*proven 3 subgoals*) . text‹ Note that this was actually proven for the Process ordering, not the refinement ordering. But the former implies the latter. And due to anti-symmetry, equality follows for the case of finite alphabets \ldots › lemma spec_equal_impl : assumes fin: "finite (SYN::('a channel)set)" shows "SYSTEM = (COPY::'a channel process)" by (simp add: FD_antisym (*‹⟦?P ⊑⇩F⇩D ?Q; ?Q ⊑⇩F⇩D ?P⟧ ⟹ ?P = ?Q›*) fin (*‹finite SYN›*) impl_refines_spec (*‹COPY ⊑⇩F⇩D SYSTEM›*) spec_refines_impl (*‹finite SYN ⟹ SYSTEM ⊑⇩F⇩D COPY›*)) subsection‹Deadlock Freeness Proof › text‹HOL-CSP can be used to prove deadlock-freeness of processes with infinite alphabet. In the case of the @{term COPY} - process, this can be formulated as the following refinement problem:› lemma DF_COPY : "(DF (range left ∪ range right)) ⊑⇩F⇩D COPY" proof (simp add:DF_def (*‹DF ?A ≡ μ x. ⊓xa∈?A → x›*), rule fix_ind2 (*‹⟦adm ?P; ?P ⊥; ?P (?F⋅⊥); ⋀x. ⟦?P x; ?P (?F⋅x)⟧ ⟹ ?P (?F⋅(?F⋅x))⟧ ⟹ ?P (fix⋅?F)›*)) (*goals: 1. ‹adm (λa::'a::type channel process. a ⊑⇩F⇩D COPY)› 2. ‹⊥ ⊑⇩F⇩D COPY› 3. ‹(Λ (x::'a::type channel process). ⊓xa::'a::type channel∈range left ∪ range right → x)⋅⊥ ⊑⇩F⇩D COPY› 4. ‹⋀x::'a::type channel process. ⟦x ⊑⇩F⇩D COPY; (Λ (x::'a::type channel process). ⊓xa::'a::type channel∈range left ∪ range right → x)⋅x ⊑⇩F⇩D COPY⟧ ⟹ (Λ (x::'a::type channel process). ⊓xa::'a::type channel∈range left ∪ range right → x)⋅((Λ (x::'a::type channel process). ⊓xa::'a::type channel∈range left ∪ range right → x)⋅x) ⊑⇩F⇩D COPY›*) show "adm (λa. a ⊑⇩F⇩D COPY)" apply (rule le_FD_adm (*‹⟦cont ?u; monofun ?v⟧ ⟹ adm (λx. ?u x ⊑⇩F⇩D ?v x)›*)) (*goals: 1. ‹cont (λx. x)› 2. ‹monofun (λx. COPY)› discuss goal 1*) apply (simp add: monofunI (*‹(⋀x y. x ⊑ y ⟹ ?f x ⊑ ?f y) ⟹ monofun ?f›*)) (*discuss goal 2*) apply (simp add: monofunI (*‹(⋀(x::?'a::po) y::?'a::po. x ⊑ y ⟹ (?f::?'a::po ⇒ ?'b::po) x ⊑ ?f y) ⟹ monofun ?f›*)) (*proven 2 subgoals*) . next (*goals: 1. ‹⊥ ⊑⇩F⇩D COPY› 2. ‹(Λ x. ⊓xa∈range left ∪ range right → x)⋅⊥ ⊑⇩F⇩D COPY› 3. ‹⋀x. ⟦x ⊑⇩F⇩D COPY; (Λ x. ⊓xa∈range left ∪ range right → x)⋅x ⊑⇩F⇩D COPY⟧ ⟹ (Λ x. ⊓xa∈range left ∪ range right → x)⋅((Λ x. ⊓xa∈range left ∪ range right → x)⋅x) ⊑⇩F⇩D COPY›*) show "⊥ ⊑⇩F⇩D COPY" by fastforce next (*goals: 1. ‹(Λ x. ⊓xa∈range left ∪ range right → x)⋅⊥ ⊑⇩F⇩D COPY› 2. ‹⋀x. ⟦x ⊑⇩F⇩D COPY; (Λ x. ⊓xa∈range left ∪ range right → x)⋅x ⊑⇩F⇩D COPY⟧ ⟹ (Λ x. ⊓xa∈range left ∪ range right → x)⋅((Λ x. ⊓xa∈range left ∪ range right → x)⋅x) ⊑⇩F⇩D COPY›*) have 1: "(⊓xa∈ range left ∪ range right → ⊥) ⊑⇩F⇩D (⊓xa∈ range left → ⊥)" apply (rule mono_Mndetprefix_FD_set (*‹⟦?A ≠ {}; ?A ⊆ ?B⟧ ⟹ Mndetprefix ?B ?P ⊑⇩F⇩D Mndetprefix ?A ?P›*)) (*goals: 1. ‹range left ≠ {}› 2. ‹range left ⊆ range left ∪ range right› discuss goal 1*) apply simp (*discuss goal 2*) apply blast (*proven 2 subgoals*) . have 2: "(⊓xa∈ range left → ⊥) ⊑⇩F⇩D (left❙?x → ⊥)" unfolding read_def (*goal: ‹⊓xa∈range left → ⊥ ⊑⇩F⇩D Mprefix (range left) ((λx. ⊥) ∘ inv left)›*) by (meson Mprefix_refines_Mndetprefix_FD (*‹Mndetprefix ?A ?P ⊑⇩F⇩D Mprefix ?A ?P›*) BOT_leFD (*‹⊥ ⊑⇩F⇩D ?Q›*) mono_Mndetprefix_FD (*‹∀x∈?A. ?P x ⊑⇩F⇩D ?P' x ⟹ Mndetprefix ?A ?P ⊑⇩F⇩D Mndetprefix ?A ?P'›*) trans_FD (*‹⟦?P ⊑⇩F⇩D ?Q; ?Q ⊑⇩F⇩D ?S⟧ ⟹ ?P ⊑⇩F⇩D ?S›*)) show "(Λ x. ⊓xa∈range left ∪ range right → x)⋅⊥ ⊑⇩F⇩D COPY" apply simp (*goal: ‹(Λ x. ⊓xa∈range left ∪ range right → x)⋅⊥ ⊑⇩F⇩D COPY›*) by (metis (mono_tags, lifting) 1 (*‹⊓xa∈range left ∪ range right → ⊥ ⊑⇩F⇩D ⊓xa∈range left → ⊥›*) 2 (*‹⊓xa∈range left → ⊥ ⊑⇩F⇩D left❙?x → ⊥›*) COPY_rec (*‹COPY = left❙?x → right❙!x → COPY›*) mono_read_FD (*‹(⋀x. ?P x ⊑⇩F⇩D ?Q x) ⟹ read ?c UNIV ?P ⊑⇩F⇩D read ?c UNIV ?Q›*) BOT_leFD (*‹⊥ ⊑⇩F⇩D ?Q›*) trans_FD (*‹⟦?P ⊑⇩F⇩D ?Q; ?Q ⊑⇩F⇩D ?S⟧ ⟹ ?P ⊑⇩F⇩D ?S›*)) next (*goal: ‹⋀x::'a::type channel process. ⟦x ⊑⇩F⇩D COPY; (Λ (x::'a::type channel process). ⊓xa::'a::type channel∈range left ∪ range right → x)⋅x ⊑⇩F⇩D COPY⟧ ⟹ (Λ (x::'a::type channel process). ⊓xa::'a::type channel∈range left ∪ range right → x)⋅((Λ (x::'a::type channel process). ⊓xa::'a::type channel∈range left ∪ range right → x)⋅x) ⊑⇩F⇩D COPY›*) fix P :: "'a channel process" assume "*": "P ⊑⇩F⇩D COPY" and "**": "(Λ x. ⊓xa∈range left ∪ range right → x)⋅P ⊑⇩F⇩D COPY" (*‹(P::'a channel process) ⊑⇩F⇩D COPY› ‹(Λ (x::'a channel process). ⊓xa::'a channel∈range left ∪ range right → x)⋅(P::'a channel process) ⊑⇩F⇩D COPY›*) have 1: "(⊓xa∈ range left ∪ range right → P) ⊑⇩F⇩D (⊓xa∈ range right → P)" apply (rule mono_Mndetprefix_FD_set (*‹⟦?A ≠ {}; ?A ⊆ ?B⟧ ⟹ Mndetprefix ?B ?P ⊑⇩F⇩D Mndetprefix ?A ?P›*)) (*goals: 1. ‹range right ≠ {}› 2. ‹range right ⊆ range left ∪ range right› discuss goal 1*) apply simp (*discuss goal 2*) apply blast (*proven 2 subgoals*) . have 2: "(⊓xa∈ range right → P) ⊑⇩F⇩D (right❙!x → P)" for x apply (unfold write_def (*‹?c❙!?a → ?P ≡ □x∈{?c ?a} → ?P›*)) (*goal: ‹⊓xa∈range right → P ⊑⇩F⇩D right❙!x → P›*) apply (rule trans_FD[OF mono_Mndetprefix_FD_set[of ‹{right x}› ‹range right›]] (*‹⟦{right x} ≠ {}; {right x} ⊆ range right; Mndetprefix {right x} ?P1 ⊑⇩F⇩D ?S⟧ ⟹ Mndetprefix (range right) ?P1 ⊑⇩F⇩D ?S›*)) (*goals: 1. ‹{right x} ≠ {}› 2. ‹{right x} ⊆ range right› 3. ‹⊓xa∈{right x} → P ⊑⇩F⇩D □x∈{right x} → P› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) . from "1" (*‹⊓xa∈range left ∪ range right → P ⊑⇩F⇩D ⊓xa∈range right → P›*) "2" (*‹⊓xa∈range right → P ⊑⇩F⇩D right❙!?x → P›*) have ab: "(⊓xa∈ range left ∪ range right → P) ⊑⇩F⇩D (right❙!x → P)" for x using trans_FD (*‹⟦?P ⊑⇩F⇩D ?Q; ?Q ⊑⇩F⇩D ?S⟧ ⟹ ?P ⊑⇩F⇩D ?S›*) by blast hence 3: "(left❙?x → (⊓xa∈ range left ∪ range right → P)) ⊑⇩F⇩D (left❙?x →(right❙!x → P))" by simp have 4: "⋀X. (⊓xa∈ range left ∪ range right → X) ⊑⇩F⇩D (⊓xa∈ range left → X)" apply (rule mono_Mndetprefix_FD_set (*‹⟦?A ≠ {}; ?A ⊆ ?B⟧ ⟹ Mndetprefix ?B ?P ⊑⇩F⇩D Mndetprefix ?A ?P›*)) (*goals: 1. ‹⋀X. range left ≠ {}› 2. ‹⋀X. range left ⊆ range left ∪ range right› discuss goal 1*) apply simp (*discuss goal 2*) apply blast (*proven 2 subgoals*) . have 5: "⋀X. (⊓xa∈ range left → X) ⊑⇩F⇩D (left❙?x → X)" apply (unfold read_def (*‹read ?c ?A ?P ≡ Mprefix (?c ` ?A) (?P ∘ inv_into ?A ?c)›*)) (*goal: ‹⋀X. ⊓xa∈range left → X ⊑⇩F⇩D left❙?x → X›*) apply (subst K_record_comp (*‹(λx. ?c) ∘ ?f = (λx. ?c)›*)) (*goal: ‹⋀X. ⊓xa∈range left → X ⊑⇩F⇩D Mprefix (range left) ((λx. X) ∘ inv left)›*) by (fact Mprefix_refines_Mndetprefix_FD (*‹Mndetprefix ?A ?P ⊑⇩F⇩D Mprefix ?A ?P›*)) from "3" (*‹left❙?x → (⊓xa∈range left ∪ range right → P) ⊑⇩F⇩D left❙?x → right❙!x → P›*) "4"[of "(⊓xa∈ range left ∪ range right → P)"] (*‹⊓xa::'a channel∈range left ∪ range right → ⊓xa::'a channel∈range left ∪ range right → (P::'a channel process) ⊑⇩F⇩D ⊓xa::'a channel∈range left → ⊓xa::'a channel∈range left ∪ range right → P›*) "5"[of "(⊓xa∈ range left ∪ range right → P)"] (*‹⊓xa∈range left → ⊓xa∈range left ∪ range right → P ⊑⇩F⇩D left❙?x → (⊓xa∈range left ∪ range right → P)›*) have 6: "(⊓xa∈ range left ∪ range right → (⊓xa∈ range left ∪ range right → P)) ⊑⇩F⇩D (left❙?x → (right❙!x → P))" using trans_FD (*‹⟦?P ⊑⇩F⇩D ?Q; ?Q ⊑⇩F⇩D ?S⟧ ⟹ ?P ⊑⇩F⇩D ?S›*) by blast from "*" (*‹P ⊑⇩F⇩D COPY›*) "**" (*‹(Λ (x::'a::type channel process). ⊓xa::'a::type channel∈range left ∪ range right → x)⋅(P::'a::type channel process) ⊑⇩F⇩D COPY›*) have 7: "left❙?x → right❙!x → P ⊑⇩F⇩D left❙?x → right❙!x → COPY" by simp show "(Λ x. ⊓xa∈range left ∪ range right → x)⋅ ((Λ x. ⊓xa∈range left ∪ range right → x)⋅P) ⊑⇩F⇩D COPY" apply simp (*goal: ‹(Λ x. ⊓xa∈range left ∪ range right → x)⋅((Λ x. ⊓xa∈range left ∪ range right → x)⋅P) ⊑⇩F⇩D COPY›*) by (metis (mono_tags, lifting) "6" (*‹⊓xa∈range left ∪ range right → ⊓xa∈range left ∪ range right → P ⊑⇩F⇩D left❙?x → right❙!x → P›*) "7" (*‹left❙?x → right❙!x → P ⊑⇩F⇩D left❙?x → right❙!x → COPY›*) COPY_rec (*‹COPY = left❙?x → right❙!x → COPY›*) trans_FD (*‹⟦?P ⊑⇩F⇩D ?Q; ?Q ⊑⇩F⇩D ?S⟧ ⟹ ?P ⊑⇩F⇩D ?S›*)) qed section‹ An Alternative Approach: Using the fixrec-Package › subsection‹ Channels and Synchronisation Sets › text‹ As before. › subsection‹ Process Definitions via fixrec-Package › fixrec COPY' :: "('a channel) process" and SEND' :: "('a channel) process" and REC' :: "('a channel) process" where COPY'_rec[simp del]: "COPY' = left❙?x → right❙!x → COPY'" | SEND'_rec[simp del]: "SEND' = left❙?x → mid❙!x → (ack → SEND')" | REC'_rec[simp del] : "REC' = mid❙?x → right❙!x → (ack → REC')" thm COPY'_rec definition SYSTEM' :: "('a channel) process" where ‹SYSTEM' ≡ ((SEND' ⟦ SYN ⟧ REC') \ SYN)› subsection‹ Another Refinement Proof on fixrec-infrastructure › text‹ Third part: No comes the proof by fixpoint induction. Not too bad in automation considering what is inferred, but wouldn't scale for large examples. › thm COPY'_SEND'_REC'.induct lemma impl_refines_spec' : "(COPY'::'a channel process) ⊑⇩F⇩D SYSTEM'" apply (unfold SYSTEM'_def (*‹SYSTEM' ≡ SEND' ⟦SYN⟧ REC' \ SYN›*)) (*goal: ‹COPY' ⊑⇩F⇩D SYSTEM'›*) apply (rule_tac P=‹λ a b c. a ⊑⇩F⇩D ((SEND' ⟦SYN⟧ REC') \ SYN)› in COPY'_SEND'_REC'.induct (*‹⟦adm (λ(COPY', SEND', REC'). ?P COPY' SEND' REC'); ?P ⊥ ⊥ ⊥; ⋀a aa b. ?P a aa b ⟹ ?P (left❙?x → right❙!x → a) (left❙?x → mid❙!x → ack → aa) (mid❙?x → right❙!x → ack → b)⟧ ⟹ ?P COPY' SEND' REC'›*)) (*goals: 1. ‹adm (λ(COPY', SEND'a, REC'a). COPY' ⊑⇩F⇩D (SEND' ⟦SYN⟧ REC' \ SYN))› 2. ‹⊥ ⊑⇩F⇩D (SEND' ⟦SYN⟧ REC' \ SYN)› 3. ‹⋀a aa b. a ⊑⇩F⇩D (SEND' ⟦SYN⟧ REC' \ SYN) ⟹ left❙?x → right❙!x → a ⊑⇩F⇩D (SEND' ⟦SYN⟧ REC' \ SYN)› discuss goal 1*) apply (subst case_prod_beta' (*‹(λ(x, y). ?f x y) = (λx. ?f (fst x) (snd x))›*)) (*top goal: ‹adm (λ(COPY', SEND'a, REC'a). COPY' ⊑⇩F⇩D (SEND' ⟦SYN⟧ REC' \ SYN))› and 2 goals remain*) apply (subst case_prod_beta' (*‹(λ(x, y). ?f x y) = (λx. ?f (fst x) (snd x))›*)) (*top goal: ‹adm (λx::'a channel process × 'a channel process × 'a channel process. case snd x of (SEND'a::'a channel process, REC'a::'a channel process) ⇒ fst x ⊑⇩F⇩D (SEND' ⟦SYN⟧ REC' \ SYN))› and 2 goals remain*) apply (intro le_FD_adm (*‹⟦cont ?u; monofun ?v⟧ ⟹ adm (λx. ?u x ⊑⇩F⇩D ?v x)›*)) (*goals: 1. ‹cont fst› 2. ‹monofun (λx. SEND' ⟦SYN⟧ REC' \ SYN)› discuss goal 1*) apply (simp add: monofunI (*‹(⋀x y. x ⊑ y ⟹ ?f x ⊑ ?f y) ⟹ monofun ?f›*)) (*discuss goal 2*) apply (simp add: monofunI (*‹(⋀x y. x ⊑ y ⟹ ?f x ⊑ ?f y) ⟹ monofun ?f›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply (simp add: monofunI (*‹(⋀x y. x ⊑ y ⟹ ?f x ⊑ ?f y) ⟹ monofun ?f›*)) (*discuss goal 3*) apply (simp add: monofunI (*‹(⋀(x::?'a) y::?'a. x ⊑ y ⟹ (?f::?'a ⇒ ?'b) x ⊑ ?f y) ⟹ monofun ?f›*)) (*goal: ‹⋀(a::'a channel process) (aa::'a channel process) b::'a channel process. a ⊑⇩F⇩D (SEND' ⟦SYN⟧ REC' \ SYN) ⟹ left❙?x::'a → right❙!x → a ⊑⇩F⇩D (SEND' ⟦SYN⟧ REC' \ SYN)›*) apply (subst SEND'_rec (*‹SEND' = left❙?x → mid❙!x → ack → SEND'›*)) (*goal: ‹⋀a. a ⊑⇩F⇩D (SEND' ⟦SYN⟧ REC' \ SYN) ⟹ left❙?x → right❙!x → a ⊑⇩F⇩D (SEND' ⟦SYN⟧ REC' \ SYN)›*) apply (subst REC'_rec (*‹REC' = mid❙?x → right❙!x → ack → REC'›*)) (*goal: ‹⋀a. a ⊑⇩F⇩D (SEND' ⟦SYN⟧ REC' \ SYN) ⟹ left❙?x → right❙!x → a ⊑⇩F⇩D (left❙?x → mid❙!x → ack → SEND' ⟦SYN⟧ REC' \ SYN)›*) apply (simp add: Sync_rules (*‹?a ∈ ?S ⟹ ?a → ?P ⟦?S⟧ ?a → ?Q = ?a → (?P ⟦?S⟧ ?Q)› ‹(⋀y. ?c y ∈ ?S) ⟹ read ?c UNIV ?P ⟦?S⟧ read ?c UNIV ?Q = ?c❙?x → (?P x ⟦?S⟧ ?Q x)› ‹⟦⋀y. ?c y ∉ ?S; ⋀y. ?d y ∈ ?S⟧ ⟹ read ?c UNIV ?P ⟦?S⟧ read ?d UNIV ?Q = ?c❙?x → (?P x ⟦?S⟧ read ?d UNIV ?Q)› ‹⟦⋀y. ?c y ∈ ?S; inj ?c⟧ ⟹ ?c❙!?a → ?P ⟦?S⟧ read ?c UNIV ?Q = ?c❙!?a → (?P ⟦?S⟧ ?Q ?a)› ‹⟦?d ?a ∉ ?S; ⋀y. ?c y ∈ ?S⟧ ⟹ ?d❙!?a → ?P ⟦?S⟧ read ?c UNIV ?Q = ?d❙!?a → (?P ⟦?S⟧ read ?c UNIV ?Q)› ‹⟦?d ∈ ?S; ⋀y. ?c y ∉ ?S⟧ ⟹ ?d → ?P ⟦?S⟧ read ?c UNIV ?Q = ?c❙?x → (?d → ?P ⟦?S⟧ ?Q x)› ‹⟦?d ?a ∉ ?C; ?c ∈ ?C⟧ ⟹ ?c → ?Q ⟦?C⟧ ?d❙!?a → ?P = ?d❙!?a → (?c → ?Q ⟦?C⟧ ?P)›*) Hiding_rules (*‹∀y. ?c y ∉ ?B ⟹ read ?c UNIV ?P \ ?B = ?c❙?x → (?P x \ ?B)› ‹∀y. ?c y ∉ ?B ⟹ ?c❙!?a → ?P \ ?B = ?c❙!?a → (?P \ ?B)› ‹?c ?a ∈ ?B ⟹ ?c❙!?a → ?P \ ?B = ?P \ ?B› ‹?a ∈ ?B ⟹ ?a → ?P \ ?B = ?P \ ?B›*)) (*proven 3 subgoals*) . lemma spec_refines_impl' : assumes fin: "finite (SYN::('a channel)set)" shows "SYSTEM' ⊑⇩F⇩D (COPY'::'a channel process)" proof (unfold SYSTEM'_def (*‹SYSTEM' ≡ SEND' ⟦SYN⟧ REC' \ SYN›*), rule_tac P=‹λ a b c. ((b ⟦SYN⟧ REC') \ SYN) ⊑⇩F⇩D COPY'› in COPY'_SEND'_REC'.induct (*‹⟦adm (λ(COPY', SEND', REC'). ?P COPY' SEND' REC'); ?P ⊥ ⊥ ⊥; ⋀a aa b. ?P a aa b ⟹ ?P (left❙?x → right❙!x → a) (left❙?x → mid❙!x → ack → aa) (mid❙?x → right❙!x → ack → b)⟧ ⟹ ?P COPY' SEND' REC'›*), goal_cases) (*goals: 1. ‹adm (λ(COPY'a, SEND', REC'a). (SEND' ⟦SYN⟧ REC' \ SYN) ⊑⇩F⇩D COPY')› 2. ‹(⊥ ⟦SYN⟧ REC' \ SYN) ⊑⇩F⇩D COPY'› 3. ‹⋀a aa b. (aa ⟦SYN⟧ REC' \ SYN) ⊑⇩F⇩D COPY' ⟹ (left❙?x → mid❙!x → ack → aa ⟦SYN⟧ REC' \ SYN) ⊑⇩F⇩D COPY'›*) case 1 (*no hyothesis introduced yet*) have aa: "adm (λ(a::'a channel process). ((a ⟦SYN⟧ REC') \ SYN) ⊑⇩F⇩D COPY')" apply (intro le_FD_adm (*‹⟦cont (?u::?'a ⇒ ?'b process); monofun (?v::?'a ⇒ ?'b process)⟧ ⟹ adm (λx::?'a. ?u x ⊑⇩F⇩D ?v x)›*)) (*goals: 1. ‹cont (λx. x ⟦SYN⟧ REC' \ SYN)› 2. ‹monofun (λx. COPY')› discuss goal 1*) apply (simp add: fin (*‹finite SYN›*) cont2mono (*‹cont ?f ⟹ monofun ?f›*)) (*discuss goal 2*) apply (simp add: fin (*‹finite SYN›*) cont2mono (*‹cont (?f::?'a::cpo ⇒ ?'b::cpo) ⟹ monofun ?f›*)) (*proven 2 subgoals*) . thus "?case" (*goal: ‹adm (λ(COPY'a, SEND', REC'a). (SEND' ⟦SYN⟧ REC' \ SYN) ⊑⇩F⇩D COPY')›*) using adm_subst[of "λ(a,b,c). b", simplified, OF aa] (*‹adm (λx. ((case x of (a, b, c) ⇒ b) ⟦SYN⟧ REC' \ SYN) ⊑⇩F⇩D COPY')›*) by (simp add: split_def (*‹case_prod = (λ(c::?'a ⇒ ?'b ⇒ ?'c) p::?'a × ?'b. c (fst p) (snd p))›*)) next (*goals: 1. ‹(⊥ ⟦SYN⟧ REC' \ SYN) ⊑⇩F⇩D COPY'› 2. ‹⋀a aa b. (aa ⟦SYN⟧ REC' \ SYN) ⊑⇩F⇩D COPY' ⟹ (left❙?x → mid❙!x → ack → aa ⟦SYN⟧ REC' \ SYN) ⊑⇩F⇩D COPY'›*) case 2 (*no hyothesis introduced yet*) then show "?case" (*goal: ‹(⊥ ⟦SYN⟧ REC' \ SYN) ⊑⇩F⇩D COPY'›*) by (simp add: Hiding_set_BOT (*‹⊥ \ ?A = ⊥›*) Sync_BOT (*‹?P ⟦?S⟧ ⊥ = ⊥›*) Sync_commute (*‹?P ⟦?S⟧ ?Q = ?Q ⟦?S⟧ ?P›*)) next (*goal: ‹⋀(a::'a channel process) (aa::'a channel process) b::'a channel process. (aa ⟦SYN⟧ REC' \ SYN) ⊑⇩F⇩D COPY' ⟹ (left❙?x::'a → mid❙!x → ack → aa ⟦SYN⟧ REC' \ SYN) ⊑⇩F⇩D COPY'›*) case (3 a aa b) (*‹(aa ⟦SYN⟧ REC' \ SYN) ⊑⇩F⇩D COPY'›*) then show "?case" (*goal: ‹(left❙?x → mid❙!x → ack → aa ⟦SYN⟧ REC' \ SYN) ⊑⇩F⇩D COPY'›*) apply (subst COPY'_rec (*‹COPY' = left❙?x → right❙!x → COPY'›*)) (*goal: ‹(left❙?x → mid❙!x → ack → aa ⟦SYN⟧ REC' \ SYN) ⊑⇩F⇩D COPY'›*) apply (subst REC'_rec (*‹REC' = mid❙?x → right❙!x → ack → REC'›*)) (*goal: ‹(aa ⟦SYN⟧ REC' \ SYN) ⊑⇩F⇩D COPY' ⟹ (left❙?x → mid❙!x → ack → aa ⟦SYN⟧ REC' \ SYN) ⊑⇩F⇩D left❙?x → right❙!x → COPY'›*) by (simp add: Sync_rules (*‹?a ∈ ?S ⟹ ?a → ?P ⟦?S⟧ ?a → ?Q = ?a → (?P ⟦?S⟧ ?Q)› ‹(⋀y. ?c y ∈ ?S) ⟹ read ?c UNIV ?P ⟦?S⟧ read ?c UNIV ?Q = ?c❙?x → (?P x ⟦?S⟧ ?Q x)› ‹⟦⋀y. ?c y ∉ ?S; ⋀y. ?d y ∈ ?S⟧ ⟹ read ?c UNIV ?P ⟦?S⟧ read ?d UNIV ?Q = ?c❙?x → (?P x ⟦?S⟧ read ?d UNIV ?Q)› ‹⟦⋀y. ?c y ∈ ?S; inj ?c⟧ ⟹ ?c❙!?a → ?P ⟦?S⟧ read ?c UNIV ?Q = ?c❙!?a → (?P ⟦?S⟧ ?Q ?a)› ‹⟦?d ?a ∉ ?S; ⋀y. ?c y ∈ ?S⟧ ⟹ ?d❙!?a → ?P ⟦?S⟧ read ?c UNIV ?Q = ?d❙!?a → (?P ⟦?S⟧ read ?c UNIV ?Q)› ‹⟦?d ∈ ?S; ⋀y. ?c y ∉ ?S⟧ ⟹ ?d → ?P ⟦?S⟧ read ?c UNIV ?Q = ?c❙?x → (?d → ?P ⟦?S⟧ ?Q x)› ‹⟦?d ?a ∉ ?C; ?c ∈ ?C⟧ ⟹ ?c → ?Q ⟦?C⟧ ?d❙!?a → ?P = ?d❙!?a → (?c → ?Q ⟦?C⟧ ?P)›*) Hiding_rules (*‹∀y. ?c y ∉ ?B ⟹ read ?c UNIV ?P \ ?B = ?c❙?x → (?P x \ ?B)› ‹∀y. ?c y ∉ ?B ⟹ ?c❙!?a → ?P \ ?B = ?c❙!?a → (?P \ ?B)› ‹?c ?a ∈ ?B ⟹ ?c❙!?a → ?P \ ?B = ?P \ ?B› ‹?a ∈ ?B ⟹ ?a → ?P \ ?B = ?P \ ?B›*)) qed lemma spec_equal_impl' : assumes fin: "finite (SYN::('a channel)set)" shows "SYSTEM' = (COPY'::'a channel process)" apply (rule FD_antisym (*‹⟦?P ⊑⇩F⇩D ?Q; ?Q ⊑⇩F⇩D ?P⟧ ⟹ ?P = ?Q›*)) (*goals: 1. ‹SYSTEM' ⊑⇩F⇩D COPY'› 2. ‹COPY' ⊑⇩F⇩D SYSTEM'› discuss goal 1*) apply (rule spec_refines_impl'[OF fin] (*‹SYSTEM' ⊑⇩F⇩D COPY'›*)) (*discuss goal 2*) apply (rule impl_refines_spec' (*‹COPY' ⊑⇩F⇩D SYSTEM'›*)) (*proven 2 subgoals*) . end
{ "path": "afp-2025-02-12/thys/HOL-CSP/CopyBuffer.thy", "repo": "afp-2025-02-12", "sha": "9eb5813e78c288d7056f66267d7d01b5f512194a3591228a1c3c63565cc66b25" }
(* Author: Andreas Lochbihler, ETH Zurich Author: Joshua Schneider, ETH Zurich *) subsection ‹Pointwise arithmetic on infinite binary trees› theory Cotree_Algebra imports Cotree begin subsubsection ‹Constants and operators› instantiation tree :: (zero) zero begin definition [applicative_unfold]: "0 = pure_tree 0" instance .. end instantiation tree :: (one) one begin definition [applicative_unfold]: "1 = pure_tree 1" instance .. end instantiation tree :: (plus) plus begin definition [applicative_unfold]: "plus x y = pure (+) ⋄ x ⋄ (y :: 'a tree)" instance .. end lemma plus_tree_simps [simp]: "root (t + t') = root t + root t'" "left (t + t') = left t + left t'" "right (t + t') = right t + right t'" (*goals: 1. ‹root (t + t') = root t + root t'› 2. ‹left (t + t') = left t + left t'› 3. ‹right (t + t') = right t + right t'› discuss goal 1*) apply (simp add: plus_tree_def (*‹?x + ?y = pure (+) ⋄ ?x ⋄ ?y›*)) (*discuss goal 2*) apply (simp add: plus_tree_def (*‹?x + ?y = pure (+) ⋄ ?x ⋄ ?y›*)) (*discuss goal 3*) apply (simp add: plus_tree_def (*‹?x + ?y = pure (+) ⋄ ?x ⋄ ?y›*)) (*proven 3 subgoals*) . friend_of_corec plus where "t + t' = Node (root t + root t') (left t + left t') (right t + right t')" subgoal by(rule tree.expand; simp) subgoal by transfer_prover done instantiation tree :: (minus) minus begin definition [applicative_unfold]: "minus x y = pure (-) ⋄ x ⋄ (y :: 'a tree)" instance .. end lemma minus_tree_simps [simp]: "root (t - t') = root t - root t'" "left (t - t') = left t - left t'" "right (t - t') = right t - right t'" (*goals: 1. ‹root (t - t') = root t - root t'› 2. ‹left (t - t') = left t - left t'› 3. ‹right (t - t') = right t - right t'› discuss goal 1*) apply (simp add: minus_tree_def (*‹?x - ?y = pure (-) ⋄ ?x ⋄ ?y›*)) (*discuss goal 2*) apply (simp add: minus_tree_def (*‹?x - ?y = pure (-) ⋄ ?x ⋄ ?y›*)) (*discuss goal 3*) apply (simp add: minus_tree_def (*‹?x - ?y = pure (-) ⋄ ?x ⋄ ?y›*)) (*proven 3 subgoals*) . instantiation tree :: (uminus) uminus begin definition [applicative_unfold tree]: "uminus = ((⋄) (pure uminus) :: 'a tree ⇒ 'a tree)" instance .. end instantiation tree :: (times) times begin definition [applicative_unfold]: "times x y = pure (*) ⋄ x ⋄ (y :: 'a tree)" instance .. end lemma times_tree_simps [simp]: "root (t * t') = root t * root t'" "left (t * t') = left t * left t'" "right (t * t') = right t * right t'" (*goals: 1. ‹root (t * t') = root t * root t'› 2. ‹left (t * t') = left t * left t'› 3. ‹right (t * t') = right t * right t'› discuss goal 1*) apply (simp add: times_tree_def (*‹?x * ?y = pure (*) ⋄ ?x ⋄ ?y›*)) (*discuss goal 2*) apply (simp add: times_tree_def (*‹?x * ?y = pure (*) ⋄ ?x ⋄ ?y›*)) (*discuss goal 3*) apply (simp add: times_tree_def (*‹?x * ?y = pure (*) ⋄ ?x ⋄ ?y›*)) (*proven 3 subgoals*) . instance tree :: (Rings.dvd) Rings.dvd .. instantiation tree :: (modulo) modulo begin definition [applicative_unfold]: "x div y = pure_tree (div) ⋄ x ⋄ (y :: 'a tree)" definition [applicative_unfold]: "x mod y = pure_tree (mod) ⋄ x ⋄ (y :: 'a tree)" instance .. end lemma mod_tree_simps [simp]: "root (t mod t') = root t mod root t'" "left (t mod t') = left t mod left t'" "right (t mod t') = right t mod right t'" (*goals: 1. ‹root (t mod t') = root t mod root t'› 2. ‹left (t mod t') = left t mod left t'› 3. ‹right (t mod t') = right t mod right t'› discuss goal 1*) apply (simp add: modulo_tree_def (*‹?x mod ?y = pure (mod) ⋄ ?x ⋄ ?y›*)) (*discuss goal 2*) apply (simp add: modulo_tree_def (*‹?x mod ?y = pure (mod) ⋄ ?x ⋄ ?y›*)) (*discuss goal 3*) apply (simp add: modulo_tree_def (*‹?x mod ?y = pure (mod) ⋄ ?x ⋄ ?y›*)) (*proven 3 subgoals*) . subsubsection ‹Algebraic instances› instance tree :: (semigroup_add) semigroup_add using add.assoc by intro_classes applicative_lifting instance tree :: (ab_semigroup_add) ab_semigroup_add using add.commute by intro_classes applicative_lifting instance tree :: (semigroup_mult) semigroup_mult using mult.assoc by intro_classes applicative_lifting instance tree :: (ab_semigroup_mult) ab_semigroup_mult using mult.commute by intro_classes applicative_lifting instance tree :: (monoid_add) monoid_add by intro_classes (applicative_lifting, simp)+ instance tree :: (comm_monoid_add) comm_monoid_add by intro_classes (applicative_lifting, simp) instance tree :: (comm_monoid_diff) comm_monoid_diff by intro_classes (applicative_lifting, simp add: diff_diff_add)+ instance tree :: (monoid_mult) monoid_mult by intro_classes (applicative_lifting, simp)+ instance tree :: (comm_monoid_mult) comm_monoid_mult by intro_classes (applicative_lifting, simp) instance tree :: (cancel_semigroup_add) cancel_semigroup_add proof fix a b c :: "'a tree" assume "a + b = a + c" thus "b = c" proof (coinduction arbitrary: a b c) case (Eq_tree a b c) hence "root (a + b) = root (a + c)" "left (a + b) = left (a + c)" "right (a + b) = right (a + c)" by simp_all thus ?case by (auto) qed next fix a b c :: "'a tree" assume "b + a = c + a" thus "b = c" proof (coinduction arbitrary: a b c) case (Eq_tree a b c) hence "root (b + a) = root (c + a)" "left (b + a) = left (c + a)" "right (b + a) = right (c + a)" by simp_all thus ?case by (auto) qed qed instance tree :: (cancel_ab_semigroup_add) cancel_ab_semigroup_add by intro_classes (applicative_lifting, simp add: diff_diff_eq)+ instance tree :: (cancel_comm_monoid_add) cancel_comm_monoid_add .. instance tree :: (group_add) group_add by intro_classes (applicative_lifting, simp)+ instance tree :: (ab_group_add) ab_group_add by intro_classes (applicative_lifting, simp)+ instance tree :: (semiring) semiring by intro_classes (applicative_lifting, simp add: ring_distribs)+ instance tree :: (mult_zero) mult_zero by intro_classes (applicative_lifting, simp)+ instance tree :: (semiring_0) semiring_0 .. instance tree :: (semiring_0_cancel) semiring_0_cancel .. instance tree :: (comm_semiring) comm_semiring by intro_classes(rule distrib_right) instance tree :: (comm_semiring_0) comm_semiring_0 .. instance tree :: (comm_semiring_0_cancel) comm_semiring_0_cancel .. lemma pure_tree_inject[simp]: "pure_tree x = pure_tree y ⟷ x = y" proof (standard) (*goals: 1. ‹pure x = pure y ⟹ x = y› 2. ‹x = y ⟹ pure x = pure y›*) assume "pure_tree x = pure_tree y" (*‹pure (x::'a) = pure (y::'a)›*) hence "root (pure_tree x) = root (pure_tree y)" by simp thus "x = y" by simp qed (simp) (*solved the remaining goal: ‹x = y ⟹ pure x = pure y›*) instance tree :: (zero_neq_one) zero_neq_one by intro_classes (applicative_unfold tree) instance tree :: (semiring_1) semiring_1 .. instance tree :: (comm_semiring_1) comm_semiring_1 .. instance tree :: (semiring_1_cancel) semiring_1_cancel .. instance tree :: (comm_semiring_1_cancel) comm_semiring_1_cancel by(intro_classes; applicative_lifting, rule right_diff_distrib') instance tree :: (ring) ring .. instance tree :: (comm_ring) comm_ring .. instance tree :: (ring_1) ring_1 .. instance tree :: (comm_ring_1) comm_ring_1 .. instance tree :: (numeral) numeral .. instance tree :: (neg_numeral) neg_numeral .. instance tree :: (semiring_numeral) semiring_numeral .. lemma of_nat_tree: "of_nat n = pure_tree (of_nat n)" proof (induction n) (*goals: 1. ‹of_nat 0 = pure (of_nat 0)› 2. ‹⋀n. of_nat n = pure (of_nat n) ⟹ of_nat (Suc n) = pure (of_nat (Suc n))›*) case 0 (*no hyothesis introduced yet*) show "?case" (*goal: ‹of_nat 0 = pure (of_nat 0)›*) by (simp add: zero_tree_def (*‹0 = pure 0›*)) next (*goal: ‹⋀n. of_nat n = pure (of_nat n) ⟹ of_nat (Suc n) = pure (of_nat (Suc n))›*) case (Suc n) (*‹of_nat n = pure (of_nat n)›*) have "1 + pure (of_nat n) = pure (1 + of_nat n)" apply applicative_nf (*goal: ‹1 + pure (of_nat n) = pure (1 + of_nat n)›*) by rule with Suc.IH (*‹of_nat n = pure (of_nat n)›*) show "?case" (*goal: ‹of_nat (Suc n) = pure (of_nat (Suc n))›*) by simp qed instance tree :: (semiring_char_0) semiring_char_0 by intro_classes (simp add: inj_on_def of_nat_tree) lemma numeral_tree_simps [simp]: "root (numeral n) = numeral n" "left (numeral n) = numeral n" "right (numeral n) = numeral n" apply (induct n) (*goals: 1. ‹root Numeral1 = Numeral1› 2. ‹left Numeral1 = Numeral1› 3. ‹right Numeral1 = Numeral1› 4. ‹⋀n. ⟦root (numeral n) = numeral n; left (numeral n) = numeral n; right (numeral n) = numeral n⟧ ⟹ root (numeral (num.Bit0 n)) = numeral (num.Bit0 n)› 5. ‹⋀n. ⟦root (numeral n) = numeral n; left (numeral n) = numeral n; right (numeral n) = numeral n⟧ ⟹ left (numeral (num.Bit0 n)) = numeral (num.Bit0 n)› 6. ‹⋀n. ⟦root (numeral n) = numeral n; left (numeral n) = numeral n; right (numeral n) = numeral n⟧ ⟹ right (numeral (num.Bit0 n)) = numeral (num.Bit0 n)› 7. ‹⋀n. ⟦root (numeral n) = numeral n; left (numeral n) = numeral n; right (numeral n) = numeral n⟧ ⟹ root (numeral (num.Bit1 n)) = numeral (num.Bit1 n)› 8. ‹⋀n. ⟦root (numeral n) = numeral n; left (numeral n) = numeral n; right (numeral n) = numeral n⟧ ⟹ left (numeral (num.Bit1 n)) = numeral (num.Bit1 n)› 9. ‹⋀n. ⟦root (numeral n) = numeral n; left (numeral n) = numeral n; right (numeral n) = numeral n⟧ ⟹ right (numeral (num.Bit1 n)) = numeral (num.Bit1 n)› discuss goal 1*) apply ((auto simp add: numeral.simps (*‹Numeral1 = 1› ‹numeral (num.Bit0 ?n) = numeral ?n + numeral ?n› ‹numeral (num.Bit1 ?n) = numeral ?n + numeral ?n + 1›*) plus_tree_def (*‹?x + ?y = pure (+) ⋄ ?x ⋄ ?y›*) one_tree_def (*‹1 = pure 1›*))[1]) (*discuss goal 2*) apply ((auto simp add: numeral.simps (*‹Numeral1 = 1› ‹numeral (num.Bit0 ?n) = numeral ?n + numeral ?n› ‹numeral (num.Bit1 ?n) = numeral ?n + numeral ?n + 1›*) plus_tree_def (*‹?x + ?y = pure (+) ⋄ ?x ⋄ ?y›*) one_tree_def (*‹1 = pure 1›*))[1]) (*discuss goal 3*) apply ((auto simp add: numeral.simps (*‹Numeral1 = 1› ‹numeral (num.Bit0 ?n) = numeral ?n + numeral ?n› ‹numeral (num.Bit1 ?n) = numeral ?n + numeral ?n + 1›*) plus_tree_def (*‹?x + ?y = pure (+) ⋄ ?x ⋄ ?y›*) one_tree_def (*‹1 = pure 1›*))[1]) (*discuss goal 4*) apply ((auto simp add: numeral.simps (*‹Numeral1 = (1::?'a)› ‹numeral (num.Bit0 (?n::num)) = numeral ?n + numeral ?n› ‹numeral (num.Bit1 (?n::num)) = numeral ?n + numeral ?n + (1::?'a)›*) plus_tree_def (*‹(?x::?'a tree) + (?y::?'a tree) = pure (+) ⋄ ?x ⋄ ?y›*) one_tree_def (*‹(1::?'a tree) = pure (1::?'a)›*))[1]) (*discuss goal 5*) apply ((auto simp add: numeral.simps (*‹Numeral1 = 1› ‹numeral (num.Bit0 ?n) = numeral ?n + numeral ?n› ‹numeral (num.Bit1 ?n) = numeral ?n + numeral ?n + 1›*) plus_tree_def (*‹?x + ?y = pure (+) ⋄ ?x ⋄ ?y›*) one_tree_def (*‹1 = pure 1›*))[1]) (*discuss goal 6*) apply ((auto simp add: numeral.simps (*‹Numeral1 = (1::?'a)› ‹numeral (num.Bit0 (?n::num)) = numeral ?n + numeral ?n› ‹numeral (num.Bit1 (?n::num)) = numeral ?n + numeral ?n + (1::?'a)›*) plus_tree_def (*‹(?x::?'a tree) + (?y::?'a tree) = pure (+) ⋄ ?x ⋄ ?y›*) one_tree_def (*‹(1::?'a tree) = pure (1::?'a)›*))[1]) (*discuss goal 7*) apply ((auto simp add: numeral.simps (*‹Numeral1 = (1::?'a::numeral)› ‹numeral (num.Bit0 (?n::num)) = numeral ?n + numeral ?n› ‹numeral (num.Bit1 (?n::num)) = numeral ?n + numeral ?n + (1::?'a::numeral)›*) plus_tree_def (*‹(?x::?'a::plus tree) + (?y::?'a::plus tree) = pure (+) ⋄ ?x ⋄ ?y›*) one_tree_def (*‹(1::?'a::one tree) = pure (1::?'a::one)›*))[1]) (*discuss goal 8*) apply ((auto simp add: numeral.simps (*‹Numeral1 = (1::?'a)› ‹numeral (num.Bit0 (?n::num)) = numeral ?n + numeral ?n› ‹numeral (num.Bit1 (?n::num)) = numeral ?n + numeral ?n + (1::?'a)›*) plus_tree_def (*‹(?x::?'a tree) + (?y::?'a tree) = pure (+) ⋄ ?x ⋄ ?y›*) one_tree_def (*‹(1::?'a tree) = pure (1::?'a)›*))[1]) (*discuss goal 9*) apply ((auto simp add: numeral.simps (*‹Numeral1 = 1› ‹numeral (num.Bit0 ?n) = numeral ?n + numeral ?n› ‹numeral (num.Bit1 ?n) = numeral ?n + numeral ?n + 1›*) plus_tree_def (*‹?x + ?y = pure (+) ⋄ ?x ⋄ ?y›*) one_tree_def (*‹1 = pure 1›*))[1]) (*proven 9 subgoals*) . lemma numeral_tree_conv_pure [applicative_unfold]: "numeral n = pure (numeral n)" apply (rule pure_tree_unique (*‹(?f::?'a::type tree) = Node (?x::?'a::type) ?f ?f ⟹ ?f = pure ?x›*)) (*goal: ‹numeral n = pure (numeral n)›*) apply (rule tree.expand (*‹root ?tree = root ?tree' ∧ left ?tree = left ?tree' ∧ right ?tree = right ?tree' ⟹ ?tree = ?tree'›*)) (*goal: ‹numeral n = Node (numeral n) (numeral n) (numeral n)›*) by simp instance tree :: (ring_char_0) ring_char_0 .. end
{ "path": "afp-2025-02-12/thys/Stern_Brocot/Cotree_Algebra.thy", "repo": "afp-2025-02-12", "sha": "e9241385d802f5e6e4d80da5bf3e1f716141ced433d98433d2804343e381cf1c" }
(******************************************************************************* Project: Sumcheck Protocol Authors: Azucena Garvia Bosshard <zucegb@gmail.com> Christoph Sprenger, ETH Zurich <sprenger@inf.ethz.ch> Jonathan Bootle, IBM Research Europe <jbt@zurich.ibm.com> *******************************************************************************) section ‹Instantiation for Multivariate Polynomials› theory Polynomial_Instantiation imports "Polynomials.More_MPoly_Type" begin text ‹ \textbf{NOTE:} if considered to be useful enough, the definitions and lemmas in this theory could be moved to the theory @{theory "Polynomials.More_MPoly_Type"}. › text ‹Define instantiation of mpoly's. The conditions @{term "(≠) 1"} and @{term "(≠) 0"} in the sets being multiplied or added over are needed to prove the correspondence with evaluation: a full instance corresponds to an evaluation (see lemma below).› subsection ‹Instantiation of monomials› type_synonym ('a, 'b) subst = "'a ⇀ 'b" lift_definition inst_monom_coeff :: ‹(nat ⇒₀ nat) ⇒ (nat, 'a) subst ⇒ 'a::comm_semiring_1› is ‹λm σ. (∏v | v ∈ dom σ ∧ the (σ v) ^ m v ≠ 1. the (σ v) ^ m v)› . lift_definition inst_monom_resid :: ‹(nat ⇒₀ nat) ⇒ (nat, 'a) subst ⇒ (nat ⇒₀ nat)› is ‹(λm σ v. m v when v ∉ dom σ)› by (metis (mono_tags, lifting) finite_subset mem_Collect_eq subsetI zero_when) lemmas inst_monom_defs = inst_monom_coeff_def inst_monom_resid_def lemma lookup_inst_monom_resid: shows ‹lookup (inst_monom_resid m σ) v = (if v ∈ dom σ then 0 else lookup m v)› apply transfer (*goal: ‹lookup (inst_monom_resid m σ) v = (if v ∈ dom σ then 0 else lookup m v)›*) by simp subsection ‹Instantiation of polynomials› definition inst_fun :: ‹((nat ⇒₀ nat) ⇒ 'a) ⇒ (nat, 'a) subst ⇒ (nat ⇒₀ nat) ⇒ 'a::comm_semiring_1› where ‹inst_fun p σ = (λm. (∑m' | inst_monom_resid m' σ = m ∧ p m' * inst_monom_coeff m' σ ≠ 0. p m' * inst_monom_coeff m' σ))› lemma finite_inst_fun_keys: assumes ‹finite {m. p m ≠ 0}› shows ‹finite {m. (∑m' | inst_monom_resid m' σ = m ∧ p m' ≠ 0 ∧ inst_monom_coeff m' σ ≠ 0. p m' * inst_monom_coeff m' σ) ≠ 0}› proof (-) (*goal: ‹finite {m. (∑m' | inst_monom_resid m' σ = m ∧ p m' ≠ 0 ∧ inst_monom_coeff m' σ ≠ 0. p m' * inst_monom_coeff m' σ) ≠ 0}›*) from ‹finite {m. p m ≠ 0}› (*‹finite {m. p m ≠ 0}›*) have "finite ((λm'. inst_monom_resid m' σ)`{x. p x ≠ 0})" by auto moreover have "{m. (∑m' | inst_monom_resid m' σ = m ∧ p m' ≠ 0 ∧ inst_monom_coeff m' σ ≠ 0. p m' * inst_monom_coeff m' σ) ≠ 0} ⊆ (λm'. inst_monom_resid m' σ)`{m. p m ≠ 0}" by (auto elim: sum.not_neutral_contains_not_neutral (*‹⟦sum ?g ?A ≠ 0; ⋀a. ⟦a ∈ ?A; ?g a ≠ 0⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) ultimately show "?thesis" (*goal: ‹finite {m. (∑m' | inst_monom_resid m' σ = m ∧ p m' ≠ 0 ∧ inst_monom_coeff m' σ ≠ 0. p m' * inst_monom_coeff m' σ) ≠ 0}›*) by (auto elim: finite_subset (*‹⟦?A ⊆ ?B; finite ?B⟧ ⟹ finite ?A›*)) qed lemma finite_inst_fun_keys_ext: assumes ‹finite {m. p m ≠ 0}› shows "finite {a. (∑m' | inst_monom_resid m' σ = a ∧ p m' ≠ 0 ∧ inst_monom_coeff m' σ ≠ 0. p m' * inst_monom_coeff m' σ * (∏aa. the (ρ aa) ^ lookup (inst_monom_resid m' σ) aa)) ≠ 0}" proof (-) (*goal: ‹finite {a. (∑m' | inst_monom_resid m' σ = a ∧ p m' ≠ 0 ∧ inst_monom_coeff m' σ ≠ 0. p m' * inst_monom_coeff m' σ * (∏aa. the (ρ aa) ^ lookup (inst_monom_resid m' σ) aa)) ≠ 0}›*) from ‹finite {m. p m ≠ 0}› (*‹finite {m. p m ≠ 0}›*) have "finite ((λm'. inst_monom_resid m' σ)`{x. p x ≠ 0})" by auto moreover have "{m. (∑m' | inst_monom_resid m' σ = m ∧ p m' ≠ 0 ∧ inst_monom_coeff m' σ ≠ 0. p m' * inst_monom_coeff m' σ * (∏aa. the (ρ aa) ^ lookup (inst_monom_resid m' σ) aa)) ≠ 0} ⊆ (λm'. inst_monom_resid m' σ)`{m. p m ≠ 0}" by (auto elim: sum.not_neutral_contains_not_neutral (*‹⟦sum ?g ?A ≠ 0; ⋀a. ⟦a ∈ ?A; ?g a ≠ 0⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) ultimately show "?thesis" (*goal: ‹finite {a. (∑m' | inst_monom_resid m' σ = a ∧ p m' ≠ 0 ∧ inst_monom_coeff m' σ ≠ 0. p m' * inst_monom_coeff m' σ * (∏aa. the (ρ aa) ^ lookup (inst_monom_resid m' σ) aa)) ≠ 0}›*) by (auto elim: finite_subset (*‹⟦?A ⊆ ?B; finite ?B⟧ ⟹ finite ?A›*)) qed lift_definition inst_aux :: ‹((nat ⇒₀ nat) ⇒₀ 'a) ⇒ (nat, 'a) subst ⇒ (nat ⇒₀ nat) ⇒₀ 'a::semidom› is inst_fun by (auto simp add: inst_fun_def intro: finite_inst_fun_keys) lift_definition inst :: ‹'a mpoly ⇒ (nat, 'a::semidom) subst ⇒ 'a mpoly› is inst_aux . lemmas inst_defs = inst_def inst_aux_def inst_fun_def subsection ‹Full instantiation corresponds to evaluation› lemma dom_Some: ‹dom (Some o f) = UNIV› by (simp add: dom_def (*‹dom ?m = {a. ?m a ≠ None}›*)) lemma inst_full_eq_insertion: fixes p :: ‹('a::semidom) mpoly› and σ :: ‹nat ⇒ 'a› shows ‹inst p (Some o σ) = Const (insertion σ p)› proof (transfer) (*goal: ‹⋀p σ. inst_aux p (Some ∘ σ) = Const₀ (insertion_aux σ p)›*) fix p :: "(nat ⇒₀ nat) ⇒₀ 'a" and σ :: "nat ⇒ 'a" show "inst_aux p (Some o σ) = Const₀ (insertion_aux σ p)" unfolding poly_mapping_eq_iff (*goal: ‹lookup (inst_aux (p::(nat ⇒₀ nat) ⇒₀ 'a) (Some ∘ (σ::nat ⇒ 'a))) = lookup (Const₀ (insertion_aux σ p))›*) apply (simp add: Const₀_def (*‹Const₀ ?c ≡ Poly_Mapping.single 0 ?c›*) inst_aux.rep_eq (*‹lookup (inst_aux ?x ?xa) = inst_fun (lookup ?x) ?xa›*) inst_fun_def (*‹inst_fun ?p ?σ = (λm. ∑m' | inst_monom_resid m' ?σ = m ∧ ?p m' * inst_monom_coeff m' ?σ ≠ 0. ?p m' * inst_monom_coeff m' ?σ)›*) inst_monom_defs (*‹inst_monom_coeff ≡ map_fun lookup id (λm σ. ∏v∈{v ∈ dom σ. the (σ v) ^ m v ≠ 1}. the (σ v) ^ m v)› ‹inst_monom_resid ≡ map_fun lookup (map_fun id Abs_poly_mapping) (λm σ v. m v when v ∉ dom σ)›*) Poly_Mapping.single.rep_eq (*‹lookup (Poly_Mapping.single ?x ?xa) = (λk'. ?xa when ?x = k')›*) insertion_aux.rep_eq (*‹insertion_aux ?x ?xa = insertion_fun ?x (lookup ?xa)›*) insertion_fun_def (*‹insertion_fun ?f ?p = (∑m. ?p m * (∏v. ?f v ^ lookup m v))›*)) (*goal: ‹lookup (inst_aux p (Some ∘ σ)) = lookup (Const₀ (insertion_aux σ p))›*) apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹(λm. ∑m' | Abs_poly_mapping (λv. lookup m' v when v ∉ dom (Some ∘ σ)) = m ∧ lookup p m' ≠ 0 ∧ (∏v∈{v ∈ dom (Some ∘ σ). σ v ^ lookup m' v ≠ 1}. σ v ^ lookup m' v) ≠ 0. lookup p m' * (∏v∈{v ∈ dom (Some ∘ σ). σ v ^ lookup m' v ≠ 1}. σ v ^ lookup m' v)) = (λk'. (∑m. lookup p m * (∏v. σ v ^ lookup m v)) when k' = 0)›*) subgoal for m apply (cases "m = 0") (*goals: 1. ‹m = 0 ⟹ (∑m' | Abs_poly_mapping (λv. lookup m' v when v ∉ dom (Some ∘ σ)) = m ∧ lookup p m' ≠ 0 ∧ (∏v∈{v ∈ dom (Some ∘ σ). σ v ^ lookup m' v ≠ 1}. σ v ^ lookup m' v) ≠ 0. lookup p m' * (∏v∈{v ∈ dom (Some ∘ σ). σ v ^ lookup m' v ≠ 1}. σ v ^ lookup m' v)) = ((∑m. lookup p m * (∏v. σ v ^ lookup m v)) when m = 0)› 2. ‹m ≠ 0 ⟹ (∑m' | Abs_poly_mapping (λv. lookup m' v when v ∉ dom (Some ∘ σ)) = m ∧ lookup p m' ≠ 0 ∧ (∏v∈{v ∈ dom (Some ∘ σ). σ v ^ lookup m' v ≠ 1}. σ v ^ lookup m' v) ≠ 0. lookup p m' * (∏v∈{v ∈ dom (Some ∘ σ). σ v ^ lookup m' v ≠ 1}. σ v ^ lookup m' v)) = ((∑m. lookup p m * (∏v. σ v ^ lookup m v)) when m = 0)› discuss goal 1*) apply (simp add: Sum_any.expand_set (*‹Sum_any ?g = sum ?g {a. ?g a ≠ 0}›*) Prod_any.expand_set (*‹Prod_any ?g = prod ?g {a. ?g a ≠ 1}›*) dom_Some (*‹dom (Some ∘ ?f) = UNIV›*)) (*discuss goal 2*) apply (simp add: Sum_any.expand_set (*‹Sum_any ?g = sum ?g {a. ?g a ≠ 0}›*) Prod_any.expand_set (*‹Prod_any ?g = prod ?g {a. ?g a ≠ 1}›*) dom_Some (*‹dom (Some ∘ ?f) = UNIV›*)) (*proven 2 subgoals*) . . qed end
{ "path": "afp-2025-02-12/thys/Sumcheck_Protocol/Instantiation_with_Polynomials/Polynomial_Instantiation.thy", "repo": "afp-2025-02-12", "sha": "ae8569b83d90532877a6665fdec613b60b1514685bd80c1442a3836366ae299d" }
(* Title: Error_Monad Author: Christian Sternagel Author: René Thiemann *) section ‹The Sum Type as Error Monad› theory Error_Monad imports "HOL-Library.Monad_Syntax" Error_Syntax begin text ‹Make monad syntax (including do-notation) available for the sum type.› definition bind :: "'e + 'a ⇒ ('a ⇒ 'e + 'b) ⇒ 'e + 'b" where "bind m f = (case m of Inr x ⇒ f x | Inl e ⇒ Inl e)" adhoc_overloading Monad_Syntax.bind bind abbreviation (input) "return ≡ Inr" abbreviation (input) "error ≡ Inl" abbreviation (input) "run ≡ projr" subsection ‹Monad Laws› lemma return_bind [simp]: "(return x ⤜ f) = f x" by (simp add: bind_def (*‹?m ⤜ ?f = (case ?m of Inl e ⇒ Inl e | Inr x ⇒ ?f x)›*)) lemma bind_return [simp]: "(m ⤜ return) = m" apply (cases m) (*goals: 1. ‹⋀a. m = Inl a ⟹ m ⤜ Inr = m› 2. ‹⋀b. m = Inr b ⟹ m ⤜ Inr = m› discuss goal 1*) apply (simp add: bind_def (*‹?m ⤜ ?f = (case ?m of Inl e ⇒ Inl e | Inr x ⇒ ?f x)›*)) (*discuss goal 2*) apply (simp add: bind_def (*‹?m ⤜ ?f = (case ?m of Inl e ⇒ Inl e | Inr x ⇒ ?f x)›*)) (*proven 2 subgoals*) . lemma error_bind [simp]: "(error e ⤜ f) = error e" by (simp add: bind_def (*‹(?m::?'e + ?'a) ⤜ (?f::?'a ⇒ ?'e + ?'b) = (case ?m of Inl (e::?'e) ⇒ Inl e | Inr (x::?'a) ⇒ ?f x)›*)) lemma bind_assoc [simp]: fixes m :: "'a + 'b" shows "((m ⤜ f) ⤜ g) = (m ⤜ (λx. f x ⤜ g))" apply (cases m) (*goals: 1. ‹⋀a. m = Inl a ⟹ m ⤜ f ⤜ g = m ⤜ (λx. f x ⤜ g)› 2. ‹⋀b. m = Inr b ⟹ m ⤜ f ⤜ g = m ⤜ (λx. f x ⤜ g)› discuss goal 1*) apply (simp add: bind_def (*‹?m ⤜ ?f = (case ?m of Inl e ⇒ Inl e | Inr x ⇒ ?f x)›*)) (*discuss goal 2*) apply (simp add: bind_def (*‹(?m::?'e + ?'a) ⤜ (?f::?'a ⇒ ?'e + ?'b) = (case ?m of Inl (e::?'e) ⇒ Inl e | Inr (x::?'a) ⇒ ?f x)›*)) (*proven 2 subgoals*) . lemma bind_cong [fundef_cong]: fixes m1 m2 :: "'e + 'a" and f1 f2 :: "'a ⇒ 'e + 'b" assumes "m1 = m2" and "⋀y. m2 = Inr y ⟹ f1 y = f2 y" shows "(m1 ⤜ f1) = (m2 ⤜ f2)" using assms (*‹(m1::'e + 'a) = (m2::'e + 'a)› ‹m2 = Inr ?y ⟹ f1 ?y = f2 ?y›*) apply (cases "m1") (*goals: 1. ‹⋀a. ⟦m1 = m2; ⋀y. m2 = Inr y ⟹ f1 y = f2 y; m1 = Inl a⟧ ⟹ m1 ⤜ f1 = m2 ⤜ f2› 2. ‹⋀b. ⟦m1 = m2; ⋀y. m2 = Inr y ⟹ f1 y = f2 y; m1 = Inr b⟧ ⟹ m1 ⤜ f1 = m2 ⤜ f2› discuss goal 1*) apply ((auto simp: bind_def (*‹?m ⤜ ?f = (case ?m of Inl e ⇒ Inl e | Inr x ⇒ ?f x)›*))[1]) (*discuss goal 2*) apply ((auto simp: bind_def (*‹?m ⤜ ?f = (case ?m of Inl e ⇒ Inl e | Inr x ⇒ ?f x)›*))[1]) (*proven 2 subgoals*) . definition catch_error :: "'e + 'a ⇒ ('e ⇒ 'f + 'a) ⇒ 'f + 'a" where catch_def: "catch_error m f = (case m of Inl e ⇒ f e | Inr x ⇒ Inr x)" adhoc_overloading Error_Syntax.catch catch_error lemma catch_splits: "P (try m catch f) ⟷ (∀e. m = Inl e ⟶ P (f e)) ∧ (∀x. m = Inr x ⟶ P (Inr x))" "P (try m catch f) ⟷ (¬ ((∃e. m = Inl e ∧ ¬ P (f e)) ∨ (∃x. m = Inr x ∧ ¬ P (Inr x))))" (*goals: 1. ‹(P::'a + 'b ⇒ bool) (try (m::'c + 'b) catch (f::'c ⇒ 'a + 'b)) = ((∀e::'c. m = Inl e ⟶ P (f e)) ∧ (∀x::'b. m = Inr x ⟶ P (Inr x)))› 2. ‹(P::'a + 'b ⇒ bool) (try (m::'c + 'b) catch (f::'c ⇒ 'a + 'b)) = (¬ ((∃e::'c. m = Inl e ∧ ¬ P (f e)) ∨ (∃x::'b. m = Inr x ∧ ¬ P (Inr x))))› discuss goal 1*) apply ((case_tac [!] m)[1]) (*goals: 1. ‹⋀a. m = Inl a ⟹ P (try m catch f) = ((∀e. m = Inl e ⟶ P (f e)) ∧ (∀x. m = Inr x ⟶ P (Inr x)))› 2. ‹⋀b. m = Inr b ⟹ P (try m catch f) = ((∀e. m = Inl e ⟶ P (f e)) ∧ (∀x. m = Inr x ⟶ P (Inr x)))› discuss goal 1*) apply (simp add: catch_def (*‹(try ?m catch ?f) = (case ?m of Inl e ⇒ ?f e | Inr x ⇒ Inr x)›*)) (*discuss goal 2*) apply (simp add: catch_def (*‹(try (?m::?'e::type + ?'a::type) catch (?f::?'e::type ⇒ ?'f::type + ?'a::type)) = (case ?m of Inl (e::?'e::type) ⇒ ?f e | Inr (x::?'a::type) ⇒ Inr x)›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply ((case_tac [!] m)[1]) (*goals: 1. ‹⋀a. m = Inl a ⟹ P (try m catch f) = (¬ ((∃e. m = Inl e ∧ ¬ P (f e)) ∨ (∃x. m = Inr x ∧ ¬ P (Inr x))))› 2. ‹⋀b. m = Inr b ⟹ P (try m catch f) = (¬ ((∃e. m = Inl e ∧ ¬ P (f e)) ∨ (∃x. m = Inr x ∧ ¬ P (Inr x))))› discuss goal 1*) apply (simp add: catch_def (*‹(try ?m catch ?f) = (case ?m of Inl e ⇒ ?f e | Inr x ⇒ Inr x)›*)) (*discuss goal 2*) apply (simp add: catch_def (*‹(try (?m::?'e::type + ?'a::type) catch (?f::?'e::type ⇒ ?'f::type + ?'a::type)) = (case ?m of Inl (e::?'e::type) ⇒ ?f e | Inr (x::?'a::type) ⇒ Inr x)›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) . abbreviation update_error :: "'e + 'a ⇒ ('e ⇒ 'f) ⇒ 'f + 'a" where "update_error m f ≡ try m catch (λx. error (f x))" adhoc_overloading Error_Syntax.update_error update_error lemma catch_return [simp]: "(try return x catch f) = return x" by (simp add: catch_def (*‹(try ?m catch ?f) = (case ?m of Inl e ⇒ ?f e | Inr x ⇒ Inr x)›*)) lemma catch_error [simp]: "(try error e catch f) = f e" by (simp add: catch_def (*‹(try ?m catch ?f) = (case ?m of Inl e ⇒ ?f e | Inr x ⇒ Inr x)›*)) lemma update_error_return [simp]: "(m <+? c = return x) ⟷ (m = return x)" apply (cases m) (*goals: 1. ‹⋀a. m = Inl a ⟹ ((try m catch (λx. Inl (c x))) = Inr x) = (m = Inr x)› 2. ‹⋀b. m = Inr b ⟹ ((try m catch (λx. Inl (c x))) = Inr x) = (m = Inr x)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . definition "isOK m ⟷ (case m of Inl e ⇒ False | Inr x ⇒ True)" lemma isOK_E [elim]: assumes "isOK m" obtains x where "m = return x" using assms (*‹isOK m›*) apply (cases m) (*goals: 1. ‹⋀a::'a::type. ⟦⋀x::'b::type. (m::'a::type + 'b::type) = Inr x ⟹ thesis::bool; isOK m; m = Inl a⟧ ⟹ thesis› 2. ‹⋀b::'b::type. ⟦⋀x::'b::type. (m::'a::type + 'b::type) = Inr x ⟹ thesis::bool; isOK m; m = Inr b⟧ ⟹ thesis› discuss goal 1*) apply (simp add: isOK_def (*‹isOK ?m = (case ?m of Inl e ⇒ False | Inr x ⇒ True)›*)) (*discuss goal 2*) apply (simp add: isOK_def (*‹isOK ?m = (case ?m of Inl e ⇒ False | Inr x ⇒ True)›*)) (*proven 2 subgoals*) . lemma isOK_I [simp, intro]: "m = return x ⟹ isOK m" apply (cases m) (*goals: 1. ‹⋀a. ⟦m = Inr x; m = Inl a⟧ ⟹ isOK m› 2. ‹⋀b. ⟦m = Inr x; m = Inr b⟧ ⟹ isOK m› discuss goal 1*) apply (simp add: isOK_def (*‹isOK (?m::?'a + ?'b) = (case ?m of Inl (e::?'a) ⇒ False | Inr (x::?'b) ⇒ True)›*)) (*discuss goal 2*) apply (simp add: isOK_def (*‹isOK ?m = (case ?m of Inl e ⇒ False | Inr x ⇒ True)›*)) (*proven 2 subgoals*) . lemma isOK_iff: "isOK m ⟷ (∃x. m = return x)" by blast lemma isOK_error [simp]: "isOK (error x) = False" by blast lemma isOK_bind [simp]: "isOK (m ⤜ f) ⟷ isOK m ∧ isOK (f (run m))" apply (cases m) (*goals: 1. ‹⋀a. m = Inl a ⟹ isOK (m ⤜ f) = (isOK m ∧ isOK (f (projr m)))› 2. ‹⋀b. m = Inr b ⟹ isOK (m ⤜ f) = (isOK m ∧ isOK (f (projr m)))› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma isOK_update_error [simp]: "isOK (m <+? f) ⟷ isOK m" apply (cases m) (*goals: 1. ‹⋀a. m = Inl a ⟹ isOK (try m catch (λx. Inl (f x))) = isOK m› 2. ‹⋀b. m = Inr b ⟹ isOK (try m catch (λx. Inl (f x))) = isOK m› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma isOK_case_prod [simp]: "isOK (case lr of (l, r) ⇒ P l r) = (case lr of (l, r) ⇒ isOK (P l r))" by (rule prod.case_distrib (*‹(?h::?'c::type ⇒ ?'d::type) (case ?prod::?'a::type × ?'b::type of (x::?'a::type, xa::?'b::type) ⇒ (?f::?'a::type ⇒ ?'b::type ⇒ ?'c::type) x xa) = (case ?prod of (x1::?'a::type, x2::?'b::type) ⇒ ?h (?f x1 x2))›*)) lemma isOK_case_option [simp]: "isOK (case x of None ⇒ P | Some v ⇒ Q v) = (case x of None ⇒ isOK P | Some v ⇒ isOK (Q v))" apply (cases x) (*goals: 1. ‹x = None ⟹ isOK (case x of None ⇒ P | Some v ⇒ Q v) = (case x of None ⇒ isOK P | Some v ⇒ isOK (Q v))› 2. ‹⋀a. x = Some a ⟹ isOK (case x of None ⇒ P | Some v ⇒ Q v) = (case x of None ⇒ isOK P | Some v ⇒ isOK (Q v))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma isOK_Let [simp]: "isOK (Let s f) = isOK (f s)" by (simp add: Let_def (*‹Let ?s ?f ≡ ?f ?s›*)) lemma run_bind [simp]: "isOK m ⟹ run (m ⤜ f) = run (f (run m))" by auto lemma run_catch [simp]: "isOK m ⟹ run (try m catch f) = run m" by auto fun foldM :: "('a ⇒ 'b ⇒ 'e + 'a) ⇒ 'a ⇒ 'b list ⇒ 'e + 'a" where "foldM f d [] = return d" | "foldM f d (x # xs) = do { y ← f d x; foldM f y xs }" fun forallM_index_aux :: "('a ⇒ nat ⇒ 'e + unit) ⇒ nat ⇒ 'a list ⇒ (('a × nat) × 'e) + unit" where "forallM_index_aux P i [] = return ()" | "forallM_index_aux P i (x # xs) = do { P x i <+? Pair (x, i); forallM_index_aux P (Suc i) xs }" lemma isOK_forallM_index_aux [simp]: "isOK (forallM_index_aux P n xs) = (∀i < length xs. isOK (P (xs ! i) (i + n)))" proof (induct xs arbitrary: n) (*goals: 1. ‹⋀n. isOK (forallM_index_aux P n []) = (∀i<length []. isOK (P ([] ! i) (i + n)))› 2. ‹⋀a xs n. (⋀n. isOK (forallM_index_aux P n xs) = (∀i<length xs. isOK (P (xs ! i) (i + n)))) ⟹ isOK (forallM_index_aux P n (a # xs)) = (∀i<length (a # xs). isOK (P ((a # xs) ! i) (i + n)))›*) case (Cons x xs) (*‹isOK (forallM_index_aux P ?n xs) = (∀i<length xs. isOK (P (xs ! i) (i + ?n)))›*) have "(∀i < length (x # xs). isOK (P ((x # xs) ! i) (i + n))) ⟷ (isOK (P x n) ∧ (∀i < length xs. isOK (P (xs ! i) (i + Suc n))))" apply auto (*goal: ‹(∀i<length ((x::'a::type) # (xs::'a::type list)). isOK ((P::'a::type ⇒ nat ⇒ 'b::type + unit) ((x # xs) ! i) (i + (n::nat)))) = (isOK (P x n) ∧ (∀i<length xs. isOK (P (xs ! i) (i + Suc n))))›*) apply (case_tac i) (*goals: 1. ‹⋀i. ⟦isOK (P x n); ∀i<length xs. isOK (P (xs ! i) (Suc (i + n))); i < Suc (length xs); i = 0⟧ ⟹ isOK (P ((x # xs) ! i) (i + n))› 2. ‹⋀i nat. ⟦isOK (P x n); ∀i<length xs. isOK (P (xs ! i) (Suc (i + n))); i < Suc (length xs); i = Suc nat⟧ ⟹ isOK (P ((x # xs) ! i) (i + n))› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . then show "?case" (*goal: ‹isOK (forallM_index_aux P n (x # xs)) = (∀i<length (x # xs). isOK (P ((x # xs) ! i) (i + n)))›*) unfolding Cons[of "Suc n", symmetric] (*goal: ‹isOK (forallM_index_aux P n (x # xs)) = (∀i<length (x # xs). isOK (P ((x # xs) ! i) (i + n)))›*) by simp qed (auto) (*solved the remaining goal: ‹⋀n. isOK (forallM_index_aux P n []) = (∀i<length []. isOK (P ([] ! i) (i + n)))›*) definition forallM_index :: "('a ⇒ nat ⇒ 'e + unit) ⇒ 'a list ⇒ (('a × nat) × 'e) + unit" where "forallM_index P xs = forallM_index_aux P 0 xs" lemma isOK_forallM_index [simp]: "isOK (forallM_index P xs) ⟷ (∀i < length xs. isOK (P (xs ! i) i))" unfolding forallM_index_def isOK_forallM_index_aux (*goal: ‹(∀i<length xs. isOK (P (xs ! i) (i + 0))) = (∀i<length xs. isOK (P (xs ! i) i))›*) by simp lemma forallM_index [fundef_cong]: fixes c :: "'a ⇒ nat ⇒ 'e + unit" assumes "⋀x i. x ∈ set xs ⟹ c x i = d x i" shows "forallM_index c xs = forallM_index d xs" proof (-) (*goal: ‹forallM_index c xs = forallM_index d xs›*) { fix n have "forallM_index_aux c n xs = forallM_index_aux d n xs" using assms (*‹?x ∈ set xs ⟹ c ?x ?i = d ?x ?i›*) apply (induct xs arbitrary: n) (*goals: 1. ‹⋀n::nat. (⋀(x::'a::type) i::nat. x ∈ set [] ⟹ (c::'a::type ⇒ nat ⇒ 'e::type + unit) x i = (d::'a::type ⇒ nat ⇒ 'e::type + unit) x i) ⟹ forallM_index_aux c n [] = forallM_index_aux d n []› 2. ‹⋀(a::'a::type) (xs::'a::type list) n::nat. ⟦⋀n::nat. (⋀(x::'a::type) i::nat. x ∈ set xs ⟹ (c::'a::type ⇒ nat ⇒ 'e::type + unit) x i = (d::'a::type ⇒ nat ⇒ 'e::type + unit) x i) ⟹ forallM_index_aux c n xs = forallM_index_aux d n xs; ⋀(x::'a::type) i::nat. x ∈ set (a # xs) ⟹ c x i = d x i⟧ ⟹ forallM_index_aux c n (a # xs) = forallM_index_aux d n (a # xs)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . } then show "?thesis" (*goal: ‹forallM_index c xs = forallM_index d xs›*) by (simp add: forallM_index_def (*‹forallM_index ?P ?xs = forallM_index_aux ?P 0 ?xs›*)) qed hide_const forallM_index_aux text ‹ Check whether @{term f} succeeds for all elements of a given list. In case it doesn't, return the first offending element together with the produced error. › fun forallM :: "('a ⇒ 'e + unit) ⇒ 'a list ⇒ ('a * 'e) + unit" where "forallM f [] = return ()" | "forallM f (x # xs) = f x <+? Pair x ⪢ forallM f xs" lemma forallM_fundef_cong [fundef_cong]: assumes "xs = ys" "⋀x. x ∈ set ys ⟹ f x = g x" shows "forallM f xs = forallM g ys" unfolding assms(1) (*goal: ‹forallM f ys = forallM g ys›*) using assms(2) (*‹(?x::'a) ∈ set (ys::'a list) ⟹ (f::'a ⇒ 'b + unit) ?x = (g::'a ⇒ 'b + unit) ?x›*) proof (induct ys) (*goals: 1. ‹(⋀x. x ∈ set [] ⟹ f x = g x) ⟹ forallM f [] = forallM g []› 2. ‹⋀a ys. ⟦(⋀x. x ∈ set ys ⟹ f x = g x) ⟹ forallM f ys = forallM g ys; ⋀x. x ∈ set (a # ys) ⟹ f x = g x⟧ ⟹ forallM f (a # ys) = forallM g (a # ys)›*) case (Cons x xs) (*‹(⋀x. x ∈ set xs ⟹ f x = g x) ⟹ forallM f xs = forallM g xs› ‹?x ∈ set (x # xs) ⟹ f ?x = g ?x›*) thus "?case" (*goal: ‹forallM f (x # xs) = forallM g (x # xs)›*) apply (cases "g x") (*goals: 1. ‹⋀a. ⟦(⋀x. x ∈ set xs ⟹ f x = g x) ⟹ forallM f xs = forallM g xs; ⋀xa. xa ∈ set (x # xs) ⟹ f xa = g xa; g x = Inl a⟧ ⟹ forallM f (x # xs) = forallM g (x # xs)› 2. ‹⋀b. ⟦(⋀x. x ∈ set xs ⟹ f x = g x) ⟹ forallM f xs = forallM g xs; ⋀xa. xa ∈ set (x # xs) ⟹ f xa = g xa; g x = Inr b⟧ ⟹ forallM f (x # xs) = forallM g (x # xs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed (auto) (*solved the remaining goal: ‹(⋀x. x ∈ set [] ⟹ f x = g x) ⟹ forallM f [] = forallM g []›*) lemma isOK_forallM [simp]: "isOK (forallM f xs) ⟷ (∀x ∈ set xs. isOK (f x))" apply (induct xs) (*goals: 1. ‹isOK (forallM f []) = (∀x∈set []. isOK (f x))› 2. ‹⋀a xs. isOK (forallM f xs) = (∀x∈set xs. isOK (f x)) ⟹ isOK (forallM f (a # xs)) = (∀x∈set (a # xs). isOK (f x))› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . text ‹ Check whether @{term f} succeeds for at least one element of a given list. In case it doesn't, return the list of produced errors. › fun existsM :: "('a ⇒ 'e + unit) ⇒ 'a list ⇒ 'e list + unit" where "existsM f [] = error []" | "existsM f (x # xs) = (try f x catch (λe. existsM f xs <+? Cons e))" lemma existsM_cong [fundef_cong]: assumes "xs = ys" and "⋀x. x ∈ set ys ⟹ f x = g x" shows "existsM f xs = existsM g ys" using assms (*‹xs = ys› ‹?x ∈ set ys ⟹ f ?x = g ?x›*) apply (induct ys arbitrary:xs) (*goals: 1. ‹⋀xs. ⟦xs = []; ⋀x. x ∈ set [] ⟹ f x = g x⟧ ⟹ existsM f xs = existsM g []› 2. ‹⋀a ys xs. ⟦⋀xs. ⟦xs = ys; ⋀x. x ∈ set ys ⟹ f x = g x⟧ ⟹ existsM f xs = existsM g ys; xs = a # ys; ⋀x. x ∈ set (a # ys) ⟹ f x = g x⟧ ⟹ existsM f xs = existsM g (a # ys)› discuss goal 1*) apply ((auto split:catch_splits (*‹(?P::?'a + ?'b ⇒ bool) (try (?m::?'c + ?'b) catch (?f::?'c ⇒ ?'a + ?'b)) = ((∀e::?'c. ?m = Inl e ⟶ ?P (?f e)) ∧ (∀x::?'b. ?m = Inr x ⟶ ?P (Inr x)))› ‹(?P::?'a + ?'b ⇒ bool) (try (?m::?'c + ?'b) catch (?f::?'c ⇒ ?'a + ?'b)) = (¬ ((∃e::?'c. ?m = Inl e ∧ ¬ ?P (?f e)) ∨ (∃x::?'b. ?m = Inr x ∧ ¬ ?P (Inr x))))›*))[1]) (*discuss goal 2*) apply ((auto split:catch_splits (*‹(?P::?'a + ?'b ⇒ bool) (try (?m::?'c + ?'b) catch (?f::?'c ⇒ ?'a + ?'b)) = ((∀e::?'c. ?m = Inl e ⟶ ?P (?f e)) ∧ (∀x::?'b. ?m = Inr x ⟶ ?P (Inr x)))› ‹(?P::?'a + ?'b ⇒ bool) (try (?m::?'c + ?'b) catch (?f::?'c ⇒ ?'a + ?'b)) = (¬ ((∃e::?'c. ?m = Inl e ∧ ¬ ?P (?f e)) ∨ (∃x::?'b. ?m = Inr x ∧ ¬ ?P (Inr x))))›*))[1]) (*proven 2 subgoals*) . lemma isOK_existsM [simp]: "isOK (existsM f xs) ⟷ (∃x∈set xs. isOK (f x))" proof (induct xs) (*goals: 1. ‹isOK (existsM f []) = (∃x∈set []. isOK (f x))› 2. ‹⋀a xs. isOK (existsM f xs) = (∃x∈set xs. isOK (f x)) ⟹ isOK (existsM f (a # xs)) = (∃x∈set (a # xs). isOK (f x))›*) case (Cons x xs) (*‹isOK (existsM f xs) = (∃x∈set xs. isOK (f x))›*) show "?case" (*goal: ‹isOK (existsM f (x # xs)) = (∃x∈set (x # xs). isOK (f x))›*) proof (cases "f x") (*goals: 1. ‹⋀a. f x = Inl a ⟹ isOK (existsM f (x # xs)) = (∃x∈set (x # xs). isOK (f x))› 2. ‹⋀b. f x = Inr b ⟹ isOK (existsM f (x # xs)) = (∃x∈set (x # xs). isOK (f x))›*) case (Inl e) (*‹f x = Inl e›*) with Cons (*‹isOK (existsM f xs) = (∃x∈set xs. isOK (f x))›*) show "?thesis" (*goal: ‹isOK (existsM f (x # xs)) = (∃x∈set (x # xs). isOK (f x))›*) by simp qed (auto simp add: catch_def (*‹(try ?m catch ?f) = (case ?m of Inl e ⇒ ?f e | Inr x ⇒ Inr x)›*)) (*solved the remaining goal: ‹⋀b::unit. (f::'b::type ⇒ 'a::type + unit) (x::'b::type) = Inr b ⟹ isOK (existsM f (x # (xs::'b::type list))) = (∃x::'b::type∈set (x # xs). isOK (f x))›*) qed (simp) (*solved the remaining goal: ‹isOK (existsM f []) = (∃x∈set []. isOK (f x))›*) lemma is_OK_if_return [simp]: "isOK (if b then return x else m) ⟷ b ∨ isOK m" "isOK (if b then m else return x) ⟷ ¬ b ∨ isOK m" (*goals: 1. ‹isOK (if b::bool then Inr (x::'b) else (m::'a + 'b)) = (b ∨ isOK m)› 2. ‹isOK (if b::bool then m::'a + 'b else Inr (x::'b)) = (¬ b ∨ isOK m)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma isOK_if_error [simp]: "isOK (if b then error e else m) ⟷ ¬ b ∧ isOK m" "isOK (if b then m else error e) ⟷ b ∧ isOK m" (*goals: 1. ‹isOK (if b then Inl e else m) = (¬ b ∧ isOK m)› 2. ‹isOK (if b then m else Inl e) = (b ∧ isOK m)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma isOK_if: "isOK (if b then x else y) ⟷ b ∧ isOK x ∨ ¬ b ∧ isOK y" by simp fun sequence :: "('e + 'a) list ⇒ 'e + 'a list" where "sequence [] = Inr []" | "sequence (m # ms) = do { x ← m; xs ← sequence ms; return (x # xs) }" subsection ‹Monadic Map for Error Monad› fun mapM :: "('a ⇒ 'e + 'b) ⇒ 'a list ⇒ 'e + 'b list" where "mapM f [] = return []" | "mapM f (x#xs) = do { y ← f x; ys ← mapM f xs; Inr (y # ys) }" lemma mapM_error: "(∃e. mapM f xs = error e) ⟷ (∃x∈set xs. ∃e. f x = error e)" proof (induct xs) (*goals: 1. ‹(∃e. mapM f [] = Inl e) = (∃x∈set []. ∃e. f x = Inl e)› 2. ‹⋀a xs. (∃e. mapM f xs = Inl e) = (∃x∈set xs. ∃e. f x = Inl e) ⟹ (∃e. mapM f (a # xs) = Inl e) = (∃x∈set (a # xs). ∃e. f x = Inl e)›*) case (Cons x xs) (*‹(∃e. mapM f xs = Inl e) = (∃x∈set xs. ∃e. f x = Inl e)›*) then show "?case" (*goal: ‹(∃e. mapM f (x # xs) = Inl e) = (∃x∈set (x # xs). ∃e. f x = Inl e)›*) apply (cases "f x") (*goals: 1. ‹⋀a. ⟦(∃e. mapM f xs = Inl e) = (∃x∈set xs. ∃e. f x = Inl e); f x = Inl a⟧ ⟹ (∃e. mapM f (x # xs) = Inl e) = (∃x∈set (x # xs). ∃e. f x = Inl e)› 2. ‹⋀b. ⟦(∃e. mapM f xs = Inl e) = (∃x∈set xs. ∃e. f x = Inl e); f x = Inr b⟧ ⟹ (∃e. mapM f (x # xs) = Inl e) = (∃x∈set (x # xs). ∃e. f x = Inl e)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*goal: ‹⋀b::'b. ⟦(∃e::'a. mapM (f::'c ⇒ 'a + 'b) (xs::'c list) = Inl e) = (∃x::'c∈set xs. ∃e::'a. f x = Inl e); f (x::'c) = Inr b⟧ ⟹ (∃e::'a. mapM f (x # xs) = Inl e) = (∃x::'c∈set (x # xs). ∃e::'a. f x = Inl e)›*) apply (cases "mapM f xs") (*goals: 1. ‹⋀b a. ⟦(∃e. mapM f xs = Inl e) = (∃x∈set xs. ∃e. f x = Inl e); f x = Inr b; mapM f xs = Inl a⟧ ⟹ (∃e. mapM f xs ⤜ (λys. Inr (b # ys)) = Inl e) = (∃x∈set xs. ∃e. f x = Inl e)› 2. ‹⋀b ba. ⟦(∃e. mapM f xs = Inl e) = (∃x∈set xs. ∃e. f x = Inl e); f x = Inr b; mapM f xs = Inr ba⟧ ⟹ (∃e. mapM f xs ⤜ (λys. Inr (b # ys)) = Inl e) = (∃x∈set xs. ∃e. f x = Inl e)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) . qed (simp) (*solved the remaining goal: ‹(∃e. mapM f [] = Inl e) = (∃x∈set []. ∃e. f x = Inl e)›*) lemma mapM_return: assumes "mapM f xs = return ys" shows "ys = map (run ∘ f) xs ∧ (∀x∈set xs. ∀e. f x ≠ error e)" using assms (*‹mapM f xs = Inr ys›*) proof (induct xs arbitrary: ys) (*goals: 1. ‹⋀ys. mapM f [] = Inr ys ⟹ ys = map (projr ∘ f) [] ∧ (∀x∈set []. ∀e. f x ≠ Inl e)› 2. ‹⋀a xs ys. ⟦⋀ys. mapM f xs = Inr ys ⟹ ys = map (projr ∘ f) xs ∧ (∀x∈set xs. ∀e. f x ≠ Inl e); mapM f (a # xs) = Inr ys⟧ ⟹ ys = map (projr ∘ f) (a # xs) ∧ (∀x∈set (a # xs). ∀e. f x ≠ Inl e)›*) case (Cons x xs ys) (*‹mapM f xs = Inr ?ys ⟹ ?ys = map (projr ∘ f) xs ∧ (∀x∈set xs. ∀e. f x ≠ Inl e)› ‹mapM f (x # xs) = Inr ys›*) then show "?case" (*goal: ‹ys = map (projr ∘ f) (x # xs) ∧ (∀x∈set (x # xs). ∀e. f x ≠ Inl e)›*) apply (cases "f x") (*goals: 1. ‹⋀a. ⟦⋀ys. mapM f xs = Inr ys ⟹ ys = map (projr ∘ f) xs ∧ (∀x∈set xs. ∀e. f x ≠ Inl e); mapM f (x # xs) = Inr ys; f x = Inl a⟧ ⟹ ys = map (projr ∘ f) (x # xs) ∧ (∀x∈set (x # xs). ∀e. f x ≠ Inl e)› 2. ‹⋀b. ⟦⋀ys. mapM f xs = Inr ys ⟹ ys = map (projr ∘ f) xs ∧ (∀x∈set xs. ∀e. f x ≠ Inl e); mapM f (x # xs) = Inr ys; f x = Inr b⟧ ⟹ ys = map (projr ∘ f) (x # xs) ∧ (∀x∈set (x # xs). ∀e. f x ≠ Inl e)› discuss goal 1*) apply simp (*discuss goal 2*) apply (cases "mapM f xs") (*goals: 1. ‹⋀b a. ⟦⋀ys. mapM f xs = Inr ys ⟹ ys = map (projr ∘ f) xs ∧ (∀x∈set xs. ∀e. f x ≠ Inl e); mapM f (x # xs) = Inr ys; f x = Inr b; mapM f xs = Inl a⟧ ⟹ ys = map (projr ∘ f) (x # xs) ∧ (∀x∈set (x # xs). ∀e. f x ≠ Inl e)› 2. ‹⋀b ba. ⟦⋀ys. mapM f xs = Inr ys ⟹ ys = map (projr ∘ f) xs ∧ (∀x∈set xs. ∀e. f x ≠ Inl e); mapM f (x # xs) = Inr ys; f x = Inr b; mapM f xs = Inr ba⟧ ⟹ ys = map (projr ∘ f) (x # xs) ∧ (∀x∈set (x # xs). ∀e. f x ≠ Inl e)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) . qed (simp) (*solved the remaining goal: ‹⋀ys. mapM f [] = Inr ys ⟹ ys = map (projr ∘ f) [] ∧ (∀x∈set []. ∀e. f x ≠ Inl e)›*) lemma mapM_return_idx: assumes *: "mapM f xs = Inr ys" and "i < length xs" shows "∃y. f (xs ! i) = Inr y ∧ ys ! i = y" proof (-) (*goal: ‹∃y::'b::type. (f::'c::type ⇒ 'a::type + 'b::type) ((xs::'c::type list) ! (i::nat)) = Inr y ∧ (ys::'b::type list) ! i = y›*) note "**" = mapM_return[OF *, unfolded set_conv_nth] (*‹ys = map (projr ∘ f) xs ∧ (∀x∈{xs ! i |i. i < length xs}. ∀e. f x ≠ Inl e)›*) with assms (*‹mapM f xs = Inr ys› ‹(i::nat) < length (xs::'c list)›*) have "⋀e. f (xs ! i) ≠ Inl e" by auto then obtain y where "f (xs ! i) = Inr y" (*goal: ‹(⋀y. f (xs ! i) = Inr y ⟹ thesis) ⟹ thesis›*) apply (cases "f (xs ! i)") (*goals: 1. ‹⋀a::'a. ⟦⋀y::'b. (f::'c ⇒ 'a + 'b) ((xs::'c list) ! (i::nat)) = Inr y ⟹ thesis::bool; ⋀e::'a. f (xs ! i) ≠ Inl e; f (xs ! i) = Inl a⟧ ⟹ thesis› 2. ‹⋀b::'b. ⟦⋀y::'b. (f::'c ⇒ 'a + 'b) ((xs::'c list) ! (i::nat)) = Inr y ⟹ thesis::bool; ⋀e::'a. f (xs ! i) ≠ Inl e; f (xs ! i) = Inr b⟧ ⟹ thesis› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . then have "f (xs ! i) = Inr y ∧ ys ! i = y" unfolding "**"[THEN conjunct1] (*goal: ‹f (xs ! i) = Inr y ∧ map (projr ∘ f) xs ! i = y›*) using assms (*‹mapM f xs = Inr ys› ‹(i::nat) < length (xs::'c list)›*) by auto then show "?thesis" (*goal: ‹∃y::'b. (f::'c ⇒ 'a + 'b) ((xs::'c list) ! (i::nat)) = Inr y ∧ (ys::'b list) ! i = y›*) apply - (*goal: ‹∃y. f (xs ! i) = Inr y ∧ ys ! i = y›*) by standard qed lemma mapM_cong [fundef_cong]: assumes "xs = ys" and "⋀x. x ∈ set ys ⟹ f x = g x" shows "mapM f xs = mapM g ys" unfolding assms(1) (*goal: ‹mapM f ys = mapM g ys›*) using assms(2) (*‹(?x::'a) ∈ set (ys::'a list) ⟹ (f::'a ⇒ 'b + 'c) ?x = (g::'a ⇒ 'b + 'c) ?x›*) apply (induct ys) (*goals: 1. ‹(⋀x::'a. x ∈ set [] ⟹ (f::'a ⇒ 'b + 'c) x = (g::'a ⇒ 'b + 'c) x) ⟹ mapM f [] = mapM g []› 2. ‹⋀(a::'a) ys::'a list. ⟦(⋀x::'a. x ∈ set ys ⟹ (f::'a ⇒ 'b + 'c) x = (g::'a ⇒ 'b + 'c) x) ⟹ mapM f ys = mapM g ys; ⋀x::'a. x ∈ set (a # ys) ⟹ f x = g x⟧ ⟹ mapM f (a # ys) = mapM g (a # ys)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma bindE [elim]: assumes "(p ⤜ f) = return x" obtains y where "p = return y" and "f y = return x" using assms (*‹p ⤜ f = Inr x›*) apply (cases p) (*goals: 1. ‹⋀a. ⟦⋀y. ⟦p = Inr y; f y = Inr x⟧ ⟹ thesis; p ⤜ f = Inr x; p = Inl a⟧ ⟹ thesis› 2. ‹⋀b. ⟦⋀y. ⟦p = Inr y; f y = Inr x⟧ ⟹ thesis; p ⤜ f = Inr x; p = Inr b⟧ ⟹ thesis› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma then_return_eq [simp]: "(p ⪢ q) = return f ⟷ isOK p ∧ q = return f" apply (cases p) (*goals: 1. ‹⋀a. p = Inl a ⟹ (p ⤜ (λ_. q) = Inr f) = (isOK p ∧ q = Inr f)› 2. ‹⋀b. p = Inr b ⟹ (p ⤜ (λ_. q) = Inr f) = (isOK p ∧ q = Inr f)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . fun choice :: "('e + 'a) list ⇒ 'e list + 'a" where "choice [] = error []" | "choice (x # xs) = (try x catch (λe. choice xs <+? Cons e))" declare choice.simps [simp del] lemma isOK_mapM: assumes "isOK (mapM f xs)" shows "(∀x. x ∈ set xs ⟶ isOK (f x)) ∧ run (mapM f xs) = map (λx. run (f x)) xs" using assms (*‹isOK (mapM f xs)›*) mapM_return[of f xs] (*‹mapM f xs = Inr ?ys ⟹ ?ys = map (projr ∘ f) xs ∧ (∀x∈set xs. ∀e. f x ≠ Inl e)›*) by (force simp: isOK_def (*‹isOK ?m = (case ?m of Inl e ⇒ False | Inr x ⇒ True)›*) split: sum.splits (*‹?P (case ?sum of Inl x ⇒ ?f1.0 x | Inr x ⇒ ?f2.0 x) = ((∀x1. ?sum = Inl x1 ⟶ ?P (?f1.0 x1)) ∧ (∀x2. ?sum = Inr x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?sum of Inl x ⇒ ?f1.0 x | Inr x ⇒ ?f2.0 x) = (¬ ((∃x1. ?sum = Inl x1 ∧ ¬ ?P (?f1.0 x1)) ∨ (∃x2. ?sum = Inr x2 ∧ ¬ ?P (?f2.0 x2))))›*)) fun firstM where "firstM f [] = error []" | "firstM f (x # xs) = (try f x ⪢ return x catch (λe. firstM f xs <+? Cons e))" lemma firstM: "isOK (firstM f xs) ⟷ (∃x∈set xs. isOK (f x))" apply (induct xs) (*goals: 1. ‹isOK (firstM (f::'b::type ⇒ 'a::type + 'c::type) []) = (∃x::'b::type∈set []. isOK (f x))› 2. ‹⋀(a::'b::type) xs::'b::type list. isOK (firstM (f::'b::type ⇒ 'a::type + 'c::type) xs) = (∃x::'b::type∈set xs. isOK (f x)) ⟹ isOK (firstM f (a # xs)) = (∃x::'b::type∈set (a # xs). isOK (f x))› discuss goal 1*) apply ((auto simp: catch_def (*‹(try ?m catch ?f) = (case ?m of Inl e ⇒ ?f e | Inr x ⇒ Inr x)›*) split: sum.splits (*‹?P (case ?sum of Inl x ⇒ ?f1.0 x | Inr x ⇒ ?f2.0 x) = ((∀x1. ?sum = Inl x1 ⟶ ?P (?f1.0 x1)) ∧ (∀x2. ?sum = Inr x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?sum of Inl x ⇒ ?f1.0 x | Inr x ⇒ ?f2.0 x) = (¬ ((∃x1. ?sum = Inl x1 ∧ ¬ ?P (?f1.0 x1)) ∨ (∃x2. ?sum = Inr x2 ∧ ¬ ?P (?f2.0 x2))))›*))[1]) (*discuss goal 2*) apply ((auto simp: catch_def (*‹(try ?m catch ?f) = (case ?m of Inl e ⇒ ?f e | Inr x ⇒ Inr x)›*) split: sum.splits (*‹?P (case ?sum of Inl x ⇒ ?f1.0 x | Inr x ⇒ ?f2.0 x) = ((∀x1. ?sum = Inl x1 ⟶ ?P (?f1.0 x1)) ∧ (∀x2. ?sum = Inr x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?sum of Inl x ⇒ ?f1.0 x | Inr x ⇒ ?f2.0 x) = (¬ ((∃x1. ?sum = Inl x1 ∧ ¬ ?P (?f1.0 x1)) ∨ (∃x2. ?sum = Inr x2 ∧ ¬ ?P (?f2.0 x2))))›*))[1]) (*proven 2 subgoals*) . lemma firstM_return: assumes "firstM f xs = return y" shows "isOK (f y) ∧ y ∈ set xs" using assms (*‹firstM f xs = Inr y›*) apply (induct xs) (*goals: 1. ‹firstM f [] = Inr y ⟹ isOK (f y) ∧ y ∈ set []› 2. ‹⋀a xs. ⟦firstM f xs = Inr y ⟹ isOK (f y) ∧ y ∈ set xs; firstM f (a # xs) = Inr y⟧ ⟹ isOK (f y) ∧ y ∈ set (a # xs)› discuss goal 1*) apply ((auto simp: catch_def (*‹(try ?m catch ?f) = (case ?m of Inl e ⇒ ?f e | Inr x ⇒ Inr x)›*) split: sum.splits (*‹?P (case ?sum of Inl x ⇒ ?f1.0 x | Inr x ⇒ ?f2.0 x) = ((∀x1. ?sum = Inl x1 ⟶ ?P (?f1.0 x1)) ∧ (∀x2. ?sum = Inr x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?sum of Inl x ⇒ ?f1.0 x | Inr x ⇒ ?f2.0 x) = (¬ ((∃x1. ?sum = Inl x1 ∧ ¬ ?P (?f1.0 x1)) ∨ (∃x2. ?sum = Inr x2 ∧ ¬ ?P (?f2.0 x2))))›*))[1]) (*discuss goal 2*) apply ((auto simp: catch_def (*‹(try ?m catch ?f) = (case ?m of Inl e ⇒ ?f e | Inr x ⇒ Inr x)›*) split: sum.splits (*‹?P (case ?sum of Inl x ⇒ ?f1.0 x | Inr x ⇒ ?f2.0 x) = ((∀x1. ?sum = Inl x1 ⟶ ?P (?f1.0 x1)) ∧ (∀x2. ?sum = Inr x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?sum of Inl x ⇒ ?f1.0 x | Inr x ⇒ ?f2.0 x) = (¬ ((∃x1. ?sum = Inl x1 ∧ ¬ ?P (?f1.0 x1)) ∨ (∃x2. ?sum = Inr x2 ∧ ¬ ?P (?f2.0 x2))))›*))[1]) (*proven 2 subgoals*) . end
{ "path": "afp-2025-02-12/thys/Certification_Monads/Error_Monad.thy", "repo": "afp-2025-02-12", "sha": "9470f51cf98b391d40c6afa636bdb669f43f3b52638d59c60e6d40328d38f842" }
section‹Separative notions and proper extensions› theory Proper_Extension imports Names begin text‹The key ingredient to obtain a proper extension is to have a ∗‹separative preorder›:› locale separative_notion = forcing_notion + assumes separative: "p∈ℙ ⟹ ∃q∈ℙ. ∃r∈ℙ. q ≼ p ∧ r ≼ p ∧ q ⊥ r" begin text‹For separative preorders, the complement of every filter is dense. Hence an $M$-generic filter cannot belong to the ground model.› lemma filter_complement_dense: assumes "filter(G)" shows "dense(ℙ - G)" proof (standard) (*goal: ‹⋀p. p ∈ ℙ ⟹ ∃d∈ℙ - G. d ≼ p›*) fix p assume "p∈ℙ" (*‹(p::i) ∈ ℙ›*) show "∃d∈ℙ - G. d ≼ p" proof (cases "p∈G") (*goals: 1. ‹p ∈ G ⟹ ∃d∈ℙ - G. d ≼ p› 2. ‹p ∉ G ⟹ ∃d∈ℙ - G. d ≼ p›*) case True (*‹p ∈ G›*) note ‹p∈ℙ› (*‹p ∈ ℙ›*) assms (*‹local.filter(G)›*) moreover obtain q and r where "q ≼ p" "r ≼ p" "q ⊥ r" "q∈ℙ" "r∈ℙ" (*goal: ‹(⋀q r. ⟦q ≼ p; r ≼ p; q ⊥ r; q ∈ ℙ; r ∈ ℙ⟧ ⟹ thesis) ⟹ thesis›*) using separative[OF ‹p∈ℙ›] (*‹∃q∈ℙ. ∃r∈ℙ. q ≼ p ∧ r ≼ p ∧ q ⊥ r›*) by force with ‹filter(G)› (*‹local.filter(G::i)›*) obtain s where "s ≼ p" "s ∉ G" "s ∈ ℙ" (*goal: ‹(⋀s. ⟦s ≼ p; s ∉ G; s ∈ ℙ⟧ ⟹ thesis) ⟹ thesis›*) using filter_imp_compat[of G q r] (*‹⟦local.filter(G::i); (q::i) ∈ G; (r::i) ∈ G⟧ ⟹ compat(q, r)›*) by auto then show "?thesis" (*goal: ‹∃d::i∈ℙ - (G::i). d ≼ (p::i)›*) by blast next (*goal: ‹p ∉ G ⟹ ∃d∈ℙ - G. d ≼ p›*) case False (*‹p ∉ G›*) with ‹p∈ℙ› (*‹p ∈ ℙ›*) show "?thesis" (*goal: ‹∃d∈ℙ - G. d ≼ p›*) using refl_leq (*‹?r ∈ ℙ ⟹ ?r ≼ ?r›*) unfolding Diff_def (*goal: ‹∃d::i∈{x::i ∈ ℙ . x ∉ (G::i)}. d ≼ (p::i)›*) by auto qed qed end ― ‹\<^locale>‹separative_notion›› locale ctm_separative = forcing_data1 + separative_notion begin context fixes G assumes generic: "M_generic(G)" begin interpretation G_generic1 ℙ leq 𝟭 M enum G apply unfold_locales (*goal: ‹G_generic1(ℙ, leq, 𝟭, M, enum, G)›*) by (simp add:generic (*‹M_generic(G)›*)) lemma generic_not_in_M: shows "G ∉ M" proof (standard) (*goal: ‹(G::i) ∈ (M::i) ⟹ False›*) assume "G∈M" (*‹(G::i) ∈ (M::i)›*) then have "ℙ - G ∈ M" using Diff_closed (*‹⟦(##(M::i))(?A::i); (##M)(?B::i)⟧ ⟹ (##M)(?A - ?B)›*) by simp moreover have "¬(∃q∈G. q ∈ ℙ - G)" "(ℙ - G) ⊆ ℙ" unfolding Diff_def (*goals: 1. ‹¬ (∃q∈G. q ∈ {x ∈ ℙ . x ∉ G})› 2. ‹{x ∈ ℙ . x ∉ G} ⊆ ℙ›*) (*goals: 1. ‹¬ (∃q::i∈G::i. q ∈ {x::i ∈ ℙ . x ∉ G})› 2. ‹{x::i ∈ ℙ . x ∉ (G::i)} ⊆ ℙ› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . moreover note generic (*‹M_generic(G)›*) ultimately show False using filter_complement_dense[of G] (*‹local.filter(G) ⟹ dense(ℙ - G)›*) M_generic_denseD[of "ℙ-G"] (*‹⟦dense(ℙ - G); ℙ - G ⊆ ℙ; ℙ - G ∈ M⟧ ⟹ ∃q∈G. q ∈ ℙ - G›*) by auto qed theorem proper_extension: "M ≠ M[G]" using generic (*‹M_generic(G)›*) G_in_Gen_Ext (*‹G ∈ M[G]›*) one_in_G (*‹𝟭 ∈ G›*) generic_not_in_M (*‹G ∉ M›*) by force end end ― ‹\<^locale>‹ctm_separative›› end
{ "path": "afp-2025-02-12/thys/Independence_CH/Proper_Extension.thy", "repo": "afp-2025-02-12", "sha": "e75b2f4e2a96e6766dff6b448bcafd0e89ef5c05b862605ec5899532aadf6b99" }
theory Asymptotic_Security imports Concrete_Security begin section ‹Asymptotic security definition› locale constructive_security_obsf' = fixes real_resource :: "security ⇒ ('a + 'e, 'b + 'f) resource" and ideal_resource :: "security ⇒ ('c + 'e, 'd + 'f) resource" and sim :: "security ⇒ ('a, 'b, 'c, 'd) converter" and ℐ_real :: "security ⇒ ('a, 'b) ℐ" and ℐ_ideal :: "security ⇒ ('c, 'd) ℐ" and ℐ_common :: "security ⇒ ('e, 'f) ℐ" and 𝒜 :: "security ⇒ ('a + 'e, 'b + 'f) distinguisher_obsf" assumes constructive_security_aux_obsf: "⋀η. constructive_security_aux_obsf (real_resource η) (ideal_resource η) (sim η) (ℐ_real η) (ℐ_ideal η) (ℐ_common η) 0" and adv: "⟦ ⋀η. exception_ℐ (ℐ_real η ⊕⇩ℐ ℐ_common η) ⊢g 𝒜 η √ ⟧ ⟹ negligible (λη. advantage (𝒜 η) (obsf_resource (sim η |₌ 1⇩C ⊳ ideal_resource η)) (obsf_resource (real_resource η)))" begin sublocale constructive_security_aux_obsf "real_resource η" "ideal_resource η" "sim η" "ℐ_real η" "ℐ_ideal η" "ℐ_common η" "0" for η by (rule constructive_security_aux_obsf (*‹constructive_security_aux_obsf ((real_resource::nat ⇒ ('a + 'e, 'b + 'f) resource) (?η::nat)) ((ideal_resource::nat ⇒ ('c + 'e, 'd + 'f) resource) ?η) ((sim::nat ⇒ ('a, 'b, 'c, 'd) converter) ?η) ((ℐ_real::nat ⇒ ('a, 'b) ℐ) ?η) ((ℐ_ideal::nat ⇒ ('c, 'd) ℐ) ?η) ((ℐ_common::nat ⇒ ('e, 'f) ℐ) ?η) (0::real)›*)) lemma constructive_security_obsf'D: "constructive_security_obsf (real_resource η) (ideal_resource η) (sim η) (ℐ_real η) (ℐ_ideal η) (ℐ_common η) (𝒜 η) (advantage (𝒜 η) (obsf_resource (sim η |₌ 1⇩C ⊳ ideal_resource η)) (obsf_resource (real_resource η)))" by (rule constructive_security_obsf_refl (*‹constructive_security_obsf ((real_resource::nat ⇒ ('a + 'e, 'b + 'f) resource) (?η::nat)) ((ideal_resource::nat ⇒ ('c + 'e, 'd + 'f) resource) ?η) ((sim::nat ⇒ ('a, 'b, 'c, 'd) converter) ?η) ((ℐ_real::nat ⇒ ('a, 'b) ℐ) ?η) ((ℐ_ideal::nat ⇒ ('c, 'd) ℐ) ?η) ((ℐ_common::nat ⇒ ('e, 'f) ℐ) ?η) (?𝒜::('a + 'e, 'b + 'f) distinguisher_obsf) (advantage ?𝒜 (obsf_resource (sim ?η |₌ 1⇩C ⊳ ideal_resource ?η)) (obsf_resource (real_resource ?η)))›*)) end lemma constructive_security_obsf'I: assumes "⋀η. constructive_security_obsf (real_resource η) (ideal_resource η) (sim η) (ℐ_real η) (ℐ_ideal η) (ℐ_common η) (𝒜 η) (adv η)" and "(⋀η. exception_ℐ (ℐ_real η ⊕⇩ℐ ℐ_common η) ⊢g 𝒜 η √) ⟹ negligible adv" shows "constructive_security_obsf' real_resource ideal_resource sim ℐ_real ℐ_ideal ℐ_common 𝒜" proof (-) (*goal: ‹constructive_security_obsf' (real_resource::nat ⇒ ('a + 'b, 'c + 'd) resource) (ideal_resource::nat ⇒ ('e + 'b, 'f + 'd) resource) (sim::nat ⇒ ('a, 'c, 'e, 'f) converter) (ℐ_real::nat ⇒ ('a, 'c) ℐ) (ℐ_ideal::nat ⇒ ('e, 'f) ℐ) (ℐ_common::nat ⇒ ('b, 'd) ℐ) (𝒜::nat ⇒ ('a + 'b, 'c + 'd) distinguisher_obsf)›*) interpret constructive_security_obsf "real_resource η" "ideal_resource η" "sim η" "ℐ_real η" "ℐ_ideal η" "ℐ_common η" "𝒜 η" "adv η" for η by fact show "?thesis" (*goal: ‹constructive_security_obsf' (real_resource::nat ⇒ ('a + 'b, 'c + 'd) resource) (ideal_resource::nat ⇒ ('e + 'b, 'f + 'd) resource) (sim::nat ⇒ ('a, 'c, 'e, 'f) converter) (ℐ_real::nat ⇒ ('a, 'c) ℐ) (ℐ_ideal::nat ⇒ ('e, 'f) ℐ) (ℐ_common::nat ⇒ ('b, 'd) ℐ) (𝒜::nat ⇒ ('a + 'b, 'c + 'd) distinguisher_obsf)›*) proof (standard) (*goals: 1. ‹⋀η. ℐ_real η ⊕⇩ℐ ℐ_common η ⊢res real_resource η √› 2. ‹⋀η. ℐ_ideal η ⊕⇩ℐ ℐ_common η ⊢res ideal_resource η √› 3. ‹⋀η. ℐ_real η, ℐ_ideal η ⊢⇩C sim η √› 4. ‹⋀η. pfinite_converter (ℐ_real η) (ℐ_ideal η) (sim η)› 5. ‹⋀η. 0 ≤ 0› 6. ‹(⋀η. exception_ℐ (ℐ_real η ⊕⇩ℐ ℐ_common η) ⊢g 𝒜 η √) ⟹ Negligible.negligible (λη. advantage (𝒜 η) (obsf_resource (sim η |₌ 1⇩C ⊳ ideal_resource η)) (obsf_resource (real_resource η)))›*) show "negligible (λη. advantage (𝒜 η) (obsf_resource (sim η |₌ 1⇩C ⊳ ideal_resource η)) (obsf_resource (real_resource η)))" if "⋀η. exception_ℐ (ℐ_real η ⊕⇩ℐ ℐ_common η) ⊢g 𝒜 η √" using assms(2)[OF that] (*‹Negligible.negligible (adv::nat ⇒ real)›*) apply (rule negligible_mono (*‹⟦Negligible.negligible (?g::nat ⇒ real); (?f::nat ⇒ real) ∈ O(?g)⟧ ⟹ Negligible.negligible ?f›*)) (*goal: ‹Negligible.negligible (λη. advantage (𝒜 η) (obsf_resource (sim η |₌ 1⇩C ⊳ ideal_resource η)) (obsf_resource (real_resource η)))›*) by (auto intro!: eventuallyI (*‹(⋀x::?'a::type. (?P::?'a::type ⇒ bool) x) ⟹ eventually ?P (?F::?'a::type filter)›*) landau_o.big_mono (*‹∀⇩F x::?'a::type in ?F::?'a::type filter. norm ((?f::?'a::type ⇒ ?'b::real_normed_field) x) ≤ norm ((?g::?'a::type ⇒ ?'b::real_normed_field) x) ⟹ ?f ∈ O[?F](?g)›*) simp add: advantage_nonneg (*‹(0::real) ≤ advantage (?𝒜::(?'a::type, ?'b::type) distinguisher) (?res1.0::(?'a::type, ?'b::type) resource) (?res2.0::(?'a::type, ?'b::type) resource)›*) adv_nonneg (*‹(0::real) ≤ (adv::nat ⇒ real) (?η::nat)›*) adv[OF that] (*‹advantage ((𝒜::nat ⇒ ('a::type + 'b::type, 'c::type + 'd::type) distinguisher_obsf) (?η::nat)) (obsf_resource ((sim::nat ⇒ ('a::type, 'c::type, 'e::type, 'f::type) converter) ?η |₌ 1⇩C ⊳ (ideal_resource::nat ⇒ ('e::type + 'b::type, 'f::type + 'd::type) resource) ?η)) (obsf_resource ((real_resource::nat ⇒ ('a::type + 'b::type, 'c::type + 'd::type) resource) ?η)) ≤ (adv::nat ⇒ real) ?η›*)) qed ((rule WT_intro (*‹map_ℐ ?g ?h ?ℐ ⊢g ?gpv √ ⟹ ?ℐ ⊢g map_gpv' ?f ?g ?h ?gpv √› ‹map_ℐ ?g id ?ℐ ⊢g ?gpv √ ⟹ ?ℐ ⊢g map_gpv ?f ?g ?gpv √› ‹⟦?ℐ1.0 ⊢res ?res1.0 √; ?ℐ2.0 ⊢res ?res2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0 ⊢res ?res1.0 ∥ ?res2.0 √› ‹⟦map_ℐ (inv ?f) (inv ?g) ?ℐ, map_ℐ ?f' ?g' ?ℐ' ⊢⇩C ?conv √; inj ?f; surj ?g⟧ ⟹ ?ℐ, ?ℐ' ⊢⇩C map_converter ?f ?g ?f' ?g' ?conv √› ‹?ℐ, ?ℐ ⊢⇩C 1⇩C √› ‹?ℐ, ?ℐ' ⊢⇩C ⊥⇩C √› ‹⟦?ℐ1.0, ?ℐ2.0 ⊢⇩C ?conv1.0 √; ?ℐ1', ?ℐ2' ⊢⇩C ?conv2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ1', ?ℐ2.0 ⊕⇩ℐ ?ℐ2' ⊢⇩C ?conv1.0 |₌ ?conv2.0 √› ‹⟦?ℐ1.0, ?ℐ ⊢⇩C ?conv1.0 √; ?ℐ2.0, ?ℐ ⊢⇩C ?conv2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0, ?ℐ ⊢⇩C ?conv1.0 |⇩∝ ?conv2.0 √› ‹?ℐ ⊢res ?res √ ⟹ ?ℐ, ?ℐ' ⊢⇩C converter_of_resource ?res √› ‹?ℐ, ?ℐ' ⊢⇩C ?cnv √ ⟹ ?ℐ, ?ℐ' ⊢⇩C restrict_converter ?A ?ℐ' ?cnv √› ‹⟦?ℐ, ?ℐ' ⊢⇩C ?conv √; ?ℐ' ⊢res ?res √⟧ ⟹ ?ℐ ⊢res ?conv ⊳ ?res √› ‹⟦?ℐ, ?ℐ' ⊢⇩C ?conv √; ?ℐ', ?ℐ'' ⊢⇩C ?conv' √⟧ ⟹ ?ℐ, ?ℐ'' ⊢⇩C ?conv ⊙ ?conv' √› and more 27 facts*) pfinite_intro (*‹pfinite_converter ?ℐ ?ℐ 1⇩C› ‹pfinite_converter ?ℐ ?ℐ' ⊥⇩C› ‹⟦pfinite_converter ?ℐ1.0 ?ℐ1' ?conv1.0; pfinite_converter ?ℐ2.0 ?ℐ2' ?conv2.0⟧ ⟹ pfinite_converter (?ℐ1.0 ⊕⇩ℐ ?ℐ2.0) (?ℐ1' ⊕⇩ℐ ?ℐ2') (?conv1.0 |₌ ?conv2.0)› ‹⟦pfinite_converter ?ℐ1.0 ?ℐ2.0 ?conv1.0; pfinite_converter ?ℐ2.0 ?ℐ3.0 ?conv2.0; ?ℐ1.0, ?ℐ2.0 ⊢⇩C ?conv1.0 √; ?ℐ2.0, ?ℐ3.0 ⊢⇩C ?conv2.0 √⟧ ⟹ pfinite_converter ?ℐ1.0 ?ℐ3.0 (?conv1.0 ⊙ ?conv2.0)› ‹⟦pfinite_converter (map_ℐ (inv ?f) (inv ?g) ?ℐ) (map_ℐ ?f' ?g' ?ℐ') ?conv; inj ?f; surj ?g⟧ ⟹ pfinite_converter ?ℐ ?ℐ' (map_converter ?f ?g ?f' ?g' ?conv)› ‹pfinite_converter ((?ℐ1.0 ⊕⇩ℐ ?ℐ2.0) ⊕⇩ℐ ?ℐ3.0) (?ℐ1.0 ⊕⇩ℐ (?ℐ2.0 ⊕⇩ℐ ?ℐ3.0)) lassocr⇩C› ‹pfinite_converter (?ℐ1.0 ⊕⇩ℐ (?ℐ2.0 ⊕⇩ℐ ?ℐ3.0)) ((?ℐ1.0 ⊕⇩ℐ ?ℐ2.0) ⊕⇩ℐ ?ℐ3.0) rassocl⇩C› ‹pfinite_converter (?ℐ1.0 ⊕⇩ℐ ?ℐ2.0) (?ℐ2.0 ⊕⇩ℐ ?ℐ1.0) swap⇩C› ‹pfinite_converter (?ℐ1.0 ⊕⇩ℐ (?ℐ2.0 ⊕⇩ℐ ?ℐ3.0)) (?ℐ2.0 ⊕⇩ℐ (?ℐ1.0 ⊕⇩ℐ ?ℐ3.0)) swap_lassocr› ‹pfinite_converter ((?ℐ1.0 ⊕⇩ℐ ?ℐ2.0) ⊕⇩ℐ ?ℐ3.0) ((?ℐ1.0 ⊕⇩ℐ ?ℐ3.0) ⊕⇩ℐ ?ℐ2.0) swap_rassocl› ‹pfinite_converter ((?ℐ1.0 ⊕⇩ℐ ?ℐ2.0) ⊕⇩ℐ (?ℐ3.0 ⊕⇩ℐ ?ℐ4.0)) ((?ℐ1.0 ⊕⇩ℐ ?ℐ3.0) ⊕⇩ℐ (?ℐ2.0 ⊕⇩ℐ ?ℐ4.0)) parallel_wiring› ‹⟦pfinite_converter ?ℐ1.0 ?ℐ3.0 ?conv1.0; pfinite_converter ?ℐ2.0 ?ℐ3.0 ?conv2.0⟧ ⟹ pfinite_converter (?ℐ1.0 ⊕⇩ℐ ?ℐ2.0) ?ℐ3.0 (?conv1.0 |⇩∝ ?conv2.0)› and more 2 facts*) order_refl (*‹?x ≤ ?x›*))+) (*solves the remaining goals: 1. ‹⋀η. ℐ_real η ⊕⇩ℐ ℐ_common η ⊢res real_resource η √› 2. ‹⋀η. ℐ_ideal η ⊕⇩ℐ ℐ_common η ⊢res ideal_resource η √› 3. ‹⋀η. ℐ_real η, ℐ_ideal η ⊢⇩C sim η √› 4. ‹⋀η. pfinite_converter (ℐ_real η) (ℐ_ideal η) (sim η)› 5. ‹⋀η. 0 ≤ 0›*) qed lemma constructive_security_obsf'_into_constructive_security: assumes "⋀𝒜 :: security ⇒ ('a + 'b, 'c + 'd) distinguisher_obsf. ⟦ ⋀η. interaction_bounded_by (λ_. True) (𝒜 η) (bound η); ⋀η. lossless ⟹ plossless_gpv (exception_ℐ (ℐ_real η ⊕⇩ℐ ℐ_common η)) (𝒜 η) ⟧ ⟹ constructive_security_obsf' real_resource ideal_resource sim ℐ_real ℐ_ideal ℐ_common 𝒜" and correct: "∃cnv. ∀𝒟. (∀η. ℐ_ideal η ⊕⇩ℐ ℐ_common η ⊢g 𝒟 η √) ⟶ (∀η. interaction_any_bounded_by (𝒟 η) (bound η)) ⟶ (∀η. lossless ⟶ plossless_gpv (ℐ_ideal η ⊕⇩ℐ ℐ_common η) (𝒟 η)) ⟶ (∀η. wiring (ℐ_ideal η) (ℐ_real η) (cnv η) (w η)) ∧ Negligible.negligible (λη. advantage (𝒟 η) (ideal_resource η) (cnv η |₌ 1⇩C ⊳ real_resource η))" shows "constructive_security real_resource ideal_resource sim ℐ_real ℐ_ideal ℐ_common bound lossless w" proof (standard) (*goals: 1. ‹⋀η. ℐ_real η ⊕⇩ℐ ℐ_common η ⊢res real_resource η √› 2. ‹⋀η. ℐ_ideal η ⊕⇩ℐ ℐ_common η ⊢res ideal_resource η √› 3. ‹⋀η. ℐ_real η, ℐ_ideal η ⊢⇩C sim η √› 4. ‹⋀𝒜. ⟦⋀η. ℐ_real η ⊕⇩ℐ ℐ_common η ⊢g 𝒜 η √; ⋀η. interaction_any_bounded_by (𝒜 η) (bound η); ⋀η. lossless ⟹ plossless_gpv (ℐ_real η ⊕⇩ℐ ℐ_common η) (𝒜 η)⟧ ⟹ Negligible.negligible (λη. advantage (𝒜 η) (sim η |₌ 1⇩C ⊳ ideal_resource η) (real_resource η))› 5. ‹∃cnv. ∀𝒟. (∀η. ℐ_ideal η ⊕⇩ℐ ℐ_common η ⊢g 𝒟 η √) ⟶ (∀η. interaction_any_bounded_by (𝒟 η) (bound η)) ⟶ (∀η. lossless ⟶ plossless_gpv (ℐ_ideal η ⊕⇩ℐ ℐ_common η) (𝒟 η)) ⟶ (∀η. wiring (ℐ_ideal η) (ℐ_real η) (cnv η) (w η)) ∧ Negligible.negligible (λη. advantage (𝒟 η) (ideal_resource η) (cnv η |₌ 1⇩C ⊳ real_resource η))›*) interpret constructive_security_obsf' real_resource ideal_resource sim "ℐ_real" "ℐ_ideal" "ℐ_common" "λ_. Done undefined" apply (rule assms (*‹⟦⋀η. interaction_any_bounded_by (?𝒜 η) (bound η); ⋀η. lossless ⟹ plossless_gpv (exception_ℐ (ℐ_real η ⊕⇩ℐ ℐ_common η)) (?𝒜 η)⟧ ⟹ constructive_security_obsf' real_resource ideal_resource sim ℐ_real ℐ_ideal ℐ_common ?𝒜› ‹∃cnv. ∀𝒟. (∀η. ℐ_ideal η ⊕⇩ℐ ℐ_common η ⊢g 𝒟 η √) ⟶ (∀η. interaction_any_bounded_by (𝒟 η) (bound η)) ⟶ (∀η. lossless ⟶ plossless_gpv (ℐ_ideal η ⊕⇩ℐ ℐ_common η) (𝒟 η)) ⟶ (∀η. wiring (ℐ_ideal η) (ℐ_real η) (cnv η) (w η)) ∧ Negligible.negligible (λη. advantage (𝒟 η) (ideal_resource η) (cnv η |₌ 1⇩C ⊳ real_resource η))›*)) (*goals: 1. ‹⋀η. interaction_any_bounded_by (Done undefined) (bound η)› 2. ‹⋀η. lossless ⟹ plossless_gpv (exception_ℐ (ℐ_real η ⊕⇩ℐ ℐ_common η)) (Done undefined)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . show "ℐ_real η ⊕⇩ℐ ℐ_common η ⊢res real_resource η √" and "ℐ_ideal η ⊕⇩ℐ ℐ_common η ⊢res ideal_resource η √" and "ℐ_real η, ℐ_ideal η ⊢⇩C sim η √" for η (*goals: 1. ‹ℐ_real η ⊕⇩ℐ ℐ_common η ⊢res real_resource η √› 2. ‹ℐ_ideal η ⊕⇩ℐ ℐ_common η ⊢res ideal_resource η √› 3. ‹ℐ_real η, ℐ_ideal η ⊢⇩C sim η √› discuss goal 1*) apply (rule WT_intro (*‹map_ℐ ?g ?h ?ℐ ⊢g ?gpv √ ⟹ ?ℐ ⊢g map_gpv' ?f ?g ?h ?gpv √› ‹map_ℐ ?g id ?ℐ ⊢g ?gpv √ ⟹ ?ℐ ⊢g map_gpv ?f ?g ?gpv √› ‹⟦?ℐ1.0 ⊢res ?res1.0 √; ?ℐ2.0 ⊢res ?res2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0 ⊢res ?res1.0 ∥ ?res2.0 √› ‹⟦map_ℐ (inv ?f) (inv ?g) ?ℐ, map_ℐ ?f' ?g' ?ℐ' ⊢⇩C ?conv √; inj ?f; surj ?g⟧ ⟹ ?ℐ, ?ℐ' ⊢⇩C map_converter ?f ?g ?f' ?g' ?conv √› ‹?ℐ, ?ℐ ⊢⇩C 1⇩C √› ‹?ℐ, ?ℐ' ⊢⇩C ⊥⇩C √› ‹⟦?ℐ1.0, ?ℐ2.0 ⊢⇩C ?conv1.0 √; ?ℐ1', ?ℐ2' ⊢⇩C ?conv2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ1', ?ℐ2.0 ⊕⇩ℐ ?ℐ2' ⊢⇩C ?conv1.0 |₌ ?conv2.0 √› ‹⟦?ℐ1.0, ?ℐ ⊢⇩C ?conv1.0 √; ?ℐ2.0, ?ℐ ⊢⇩C ?conv2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0, ?ℐ ⊢⇩C ?conv1.0 |⇩∝ ?conv2.0 √› ‹?ℐ ⊢res ?res √ ⟹ ?ℐ, ?ℐ' ⊢⇩C converter_of_resource ?res √› ‹?ℐ, ?ℐ' ⊢⇩C ?cnv √ ⟹ ?ℐ, ?ℐ' ⊢⇩C restrict_converter ?A ?ℐ' ?cnv √› ‹⟦?ℐ, ?ℐ' ⊢⇩C ?conv √; ?ℐ' ⊢res ?res √⟧ ⟹ ?ℐ ⊢res ?conv ⊳ ?res √› ‹⟦?ℐ, ?ℐ' ⊢⇩C ?conv √; ?ℐ', ?ℐ'' ⊢⇩C ?conv' √⟧ ⟹ ?ℐ, ?ℐ'' ⊢⇩C ?conv ⊙ ?conv' √› and more 27 facts*)) (*discuss goal 2*) apply (rule WT_intro (*‹map_ℐ (?g::?'a ⇒ ?'d) (?h::?'e ⇒ ?'b) (?ℐ::(?'d, ?'e) ℐ) ⊢g ?gpv::(?'c, ?'a, ?'b) gpv √ ⟹ ?ℐ ⊢g map_gpv' (?f::?'c ⇒ ?'f) ?g ?h ?gpv √› ‹map_ℐ (?g::?'a ⇒ ?'d) id (?ℐ::(?'d, ?'b) ℐ) ⊢g ?gpv::(?'c, ?'a, ?'b) gpv √ ⟹ ?ℐ ⊢g map_gpv (?f::?'c ⇒ ?'e) ?g ?gpv √› ‹⟦(?ℐ1.0::(?'a, ?'b) ℐ) ⊢res ?res1.0::(?'a, ?'b) resource √; (?ℐ2.0::(?'c, ?'d) ℐ) ⊢res ?res2.0::(?'c, ?'d) resource √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0 ⊢res ?res1.0 ∥ ?res2.0 √› ‹⟦map_ℐ (inv (?f::?'e ⇒ ?'a)) (inv (?g::?'b ⇒ ?'f)) (?ℐ::(?'e, ?'f) ℐ), map_ℐ (?f'::?'c ⇒ ?'g) (?g'::?'h ⇒ ?'d) (?ℐ'::(?'g, ?'h) ℐ) ⊢⇩C ?conv::(?'a, ?'b, ?'c, ?'d) converter √; inj ?f; surj ?g⟧ ⟹ ?ℐ, ?ℐ' ⊢⇩C map_converter ?f ?g ?f' ?g' ?conv √› ‹(?ℐ::(?'a, ?'b) ℐ), ?ℐ ⊢⇩C 1⇩C √› ‹(?ℐ::(?'a, ?'b) ℐ), ?ℐ'::(?'c, ?'d) ℐ ⊢⇩C ⊥⇩C √› ‹⟦(?ℐ1.0::(?'a, ?'b) ℐ), ?ℐ2.0::(?'c, ?'d) ℐ ⊢⇩C ?conv1.0::(?'a, ?'b, ?'c, ?'d) converter √; (?ℐ1'::(?'e, ?'f) ℐ), ?ℐ2'::(?'g, ?'h) ℐ ⊢⇩C ?conv2.0::(?'e, ?'f, ?'g, ?'h) converter √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ1', ?ℐ2.0 ⊕⇩ℐ ?ℐ2' ⊢⇩C ?conv1.0 |₌ ?conv2.0 √› ‹⟦(?ℐ1.0::(?'a, ?'b) ℐ), ?ℐ::(?'c, ?'d) ℐ ⊢⇩C ?conv1.0::(?'a, ?'b, ?'c, ?'d) converter √; (?ℐ2.0::(?'e, ?'f) ℐ), ?ℐ ⊢⇩C ?conv2.0::(?'e, ?'f, ?'c, ?'d) converter √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0, ?ℐ ⊢⇩C ?conv1.0 |⇩∝ ?conv2.0 √› ‹(?ℐ::(?'a, ?'b) ℐ) ⊢res ?res::(?'a, ?'b) resource √ ⟹ ?ℐ, ?ℐ'::(?'c, ?'d) ℐ ⊢⇩C converter_of_resource ?res √› ‹(?ℐ::(?'a, ?'b) ℐ), ?ℐ'::(?'c, ?'d) ℐ ⊢⇩C ?cnv::(?'a, ?'b, ?'c, ?'d) converter √ ⟹ ?ℐ, ?ℐ' ⊢⇩C restrict_converter (?A::?'a set) ?ℐ' ?cnv √› ‹⟦(?ℐ::(?'a, ?'b) ℐ), ?ℐ'::(?'c, ?'d) ℐ ⊢⇩C ?conv::(?'a, ?'b, ?'c, ?'d) converter √; ?ℐ' ⊢res ?res::(?'c, ?'d) resource √⟧ ⟹ ?ℐ ⊢res ?conv ⊳ ?res √› ‹⟦(?ℐ::(?'a, ?'b) ℐ), ?ℐ'::(?'c, ?'d) ℐ ⊢⇩C ?conv::(?'a, ?'b, ?'c, ?'d) converter √; ?ℐ', ?ℐ''::(?'e, ?'f) ℐ ⊢⇩C ?conv'::(?'c, ?'d, ?'e, ?'f) converter √⟧ ⟹ ?ℐ, ?ℐ'' ⊢⇩C ?conv ⊙ ?conv' √› and more 27 facts*)) (*discuss goal 3*) apply (rule WT_intro (*‹map_ℐ ?g ?h ?ℐ ⊢g ?gpv √ ⟹ ?ℐ ⊢g map_gpv' ?f ?g ?h ?gpv √› ‹map_ℐ ?g id ?ℐ ⊢g ?gpv √ ⟹ ?ℐ ⊢g map_gpv ?f ?g ?gpv √› ‹⟦?ℐ1.0 ⊢res ?res1.0 √; ?ℐ2.0 ⊢res ?res2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0 ⊢res ?res1.0 ∥ ?res2.0 √› ‹⟦map_ℐ (inv ?f) (inv ?g) ?ℐ, map_ℐ ?f' ?g' ?ℐ' ⊢⇩C ?conv √; inj ?f; surj ?g⟧ ⟹ ?ℐ, ?ℐ' ⊢⇩C map_converter ?f ?g ?f' ?g' ?conv √› ‹?ℐ, ?ℐ ⊢⇩C 1⇩C √› ‹?ℐ, ?ℐ' ⊢⇩C ⊥⇩C √› ‹⟦?ℐ1.0, ?ℐ2.0 ⊢⇩C ?conv1.0 √; ?ℐ1', ?ℐ2' ⊢⇩C ?conv2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ1', ?ℐ2.0 ⊕⇩ℐ ?ℐ2' ⊢⇩C ?conv1.0 |₌ ?conv2.0 √› ‹⟦?ℐ1.0, ?ℐ ⊢⇩C ?conv1.0 √; ?ℐ2.0, ?ℐ ⊢⇩C ?conv2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0, ?ℐ ⊢⇩C ?conv1.0 |⇩∝ ?conv2.0 √› ‹?ℐ ⊢res ?res √ ⟹ ?ℐ, ?ℐ' ⊢⇩C converter_of_resource ?res √› ‹?ℐ, ?ℐ' ⊢⇩C ?cnv √ ⟹ ?ℐ, ?ℐ' ⊢⇩C restrict_converter ?A ?ℐ' ?cnv √› ‹⟦?ℐ, ?ℐ' ⊢⇩C ?conv √; ?ℐ' ⊢res ?res √⟧ ⟹ ?ℐ ⊢res ?conv ⊳ ?res √› ‹⟦?ℐ, ?ℐ' ⊢⇩C ?conv √; ?ℐ', ?ℐ'' ⊢⇩C ?conv' √⟧ ⟹ ?ℐ, ?ℐ'' ⊢⇩C ?conv ⊙ ?conv' √› and more 27 facts*)) (*proven 3 subgoals*) . show "∃cnv. ∀𝒟. (∀η. ℐ_ideal η ⊕⇩ℐ ℐ_common η ⊢g 𝒟 η √) ⟶ (∀η. interaction_any_bounded_by (𝒟 η) (bound η)) ⟶ (∀η. lossless ⟶ plossless_gpv (ℐ_ideal η ⊕⇩ℐ ℐ_common η) (𝒟 η)) ⟶ (∀η. wiring (ℐ_ideal η) (ℐ_real η) (cnv η) (w η)) ∧ Negligible.negligible (λη. advantage (𝒟 η) (ideal_resource η) (cnv η |₌ 1⇩C ⊳ real_resource η))" by fact next (*goal: ‹⋀𝒜::nat ⇒ ('a + 'b, 'c + 'd) distinguisher. ⟦⋀η::nat. (ℐ_real::nat ⇒ ('a, 'c) ℐ) η ⊕⇩ℐ (ℐ_common::nat ⇒ ('b, 'd) ℐ) η ⊢g 𝒜 η √; ⋀η::nat. interaction_any_bounded_by (𝒜 η) ((bound::nat ⇒ enat) η); ⋀η::nat. lossless::bool ⟹ plossless_gpv (ℐ_real η ⊕⇩ℐ ℐ_common η) (𝒜 η)⟧ ⟹ Negligible.negligible (λη::nat. advantage (𝒜 η) ((sim::nat ⇒ ('a, 'c, 'e, 'f) converter) η |₌ 1⇩C ⊳ (ideal_resource::nat ⇒ ('e + 'b, 'f + 'd) resource) η) ((real_resource::nat ⇒ ('a + 'b, 'c + 'd) resource) η))›*) fix 𝒜 :: "security ⇒ ('a + 'b, 'c + 'd) distinguisher" assume WT_adv[WT_intro]: "⋀η. ℐ_real η ⊕⇩ℐ ℐ_common η ⊢g 𝒜 η √" and bound[interaction_bound]: "⋀η. interaction_any_bounded_by (𝒜 η) (bound η)" and lossless: "⋀η. lossless ⟹ plossless_gpv (ℐ_real η ⊕⇩ℐ ℐ_common η) (𝒜 η)" (*‹(ℐ_real::nat ⇒ ('a, 'c) ℐ) (?η::nat) ⊕⇩ℐ (ℐ_common::nat ⇒ ('b, 'd) ℐ) ?η ⊢g (𝒜::nat ⇒ ('a + 'b, 'c + 'd) distinguisher) ?η √› ‹interaction_any_bounded_by ((𝒜::nat ⇒ ('a + 'b, 'c + 'd) distinguisher) (?η::nat)) ((bound::nat ⇒ enat) ?η)› ‹lossless::bool ⟹ plossless_gpv ((ℐ_real::nat ⇒ ('a, 'c) ℐ) (?η::nat) ⊕⇩ℐ (ℐ_common::nat ⇒ ('b, 'd) ℐ) ?η) ((𝒜::nat ⇒ ('a + 'b, 'c + 'd) distinguisher) ?η)›*) let ?𝒜 = "λη. obsf_distinguisher (𝒜 η)" interpret constructive_security_obsf' real_resource ideal_resource sim "ℐ_real" "ℐ_ideal" "ℐ_common" "?𝒜" proof (rule assms (*‹⟦⋀η. interaction_any_bounded_by (?𝒜 η) (bound η); ⋀η. lossless ⟹ plossless_gpv (exception_ℐ (ℐ_real η ⊕⇩ℐ ℐ_common η)) (?𝒜 η)⟧ ⟹ constructive_security_obsf' real_resource ideal_resource sim ℐ_real ℐ_ideal ℐ_common ?𝒜› ‹∃cnv. ∀𝒟. (∀η. ℐ_ideal η ⊕⇩ℐ ℐ_common η ⊢g 𝒟 η √) ⟶ (∀η. interaction_any_bounded_by (𝒟 η) (bound η)) ⟶ (∀η. lossless ⟶ plossless_gpv (ℐ_ideal η ⊕⇩ℐ ℐ_common η) (𝒟 η)) ⟶ (∀η. wiring (ℐ_ideal η) (ℐ_real η) (cnv η) (w η)) ∧ Negligible.negligible (λη. advantage (𝒟 η) (ideal_resource η) (cnv η |₌ 1⇩C ⊳ real_resource η))›*)) (*goals: 1. ‹⋀η. interaction_any_bounded_by (obsf_distinguisher (𝒜 η)) (bound η)› 2. ‹⋀η. lossless ⟹ plossless_gpv (exception_ℐ (ℐ_real η ⊕⇩ℐ ℐ_common η)) (obsf_distinguisher (𝒜 η))›*) show "interaction_any_bounded_by (?𝒜 η) (bound η)" for η apply (rule interaction_bound (*‹interaction_bounded_by ?consider (Done ?x) 0› ‹interaction_bounded_by ?consider Fail 0› ‹interaction_bounded_by ?consider (lift_spmf ?p) 0› ‹interaction_bounded_by ?consider (assert_gpv ?b) 0› ‹(⋀input. interaction_bounded_by ?consider (?c input) (?n input)) ⟹ interaction_bounded_by ?consider (Pause ?out ?c) (if ?consider ?out then 1 + ⨆ range ?n else ⨆ range ?n)› ‹⟦interaction_bounded_by ?consider ?gpv ?n; ⋀x. x ∈ results'_gpv ?gpv ⟹ interaction_bounded_by ?consider (?f x) (?m x)⟧ ⟹ interaction_bounded_by ?consider (bind_gpv ?gpv ?f) (?n + ⨆ (?m ` results'_gpv ?gpv))› ‹(⋀input. interaction_bounded_by ?consider (bind_gpv (?c input) ?f) (?n input)) ⟹ interaction_bounded_by ?consider (bind_gpv (Pause ?out ?c) ?f) (if ?consider ?out then ⨆input. ?n input + 1 else ⨆ range ?n)› ‹(⋀x. x ∈ set_spmf ?p ⟹ interaction_bounded_by ?consider (?f x) (?n x)) ⟹ interaction_bounded_by ?consider (bind_gpv (lift_spmf ?p) ?f) (⨆ (?n ` set_spmf ?p))› ‹interaction_bounded_by ?consider (?f ?x) ?n ⟹ interaction_bounded_by ?consider (bind_gpv (Done ?x) ?f) ?n› ‹⟦?b ⟹ interaction_bounded_by ?consider ?gpv1.0 ?n; ¬ ?b ⟹ interaction_bounded_by ?consider ?gpv2.0 ?m⟧ ⟹ interaction_bounded_by ?consider (if ?b then ?gpv1.0 else ?gpv2.0) (if ?b then ?n else ?m)› ‹⟦?b ⟹ interaction_bounded_by ?consider ?t ?bt; ¬ ?b ⟹ interaction_bounded_by ?consider ?f ?bf⟧ ⟹ interaction_bounded_by ?consider (case ?b of True ⇒ ?t | False ⇒ ?f) (if ?b then ?bt else ?bf)› ‹⟦⋀y. ?x = Inl y ⟹ interaction_bounded_by ?consider (?l y) (?bl y); ⋀y. ?x = Inr y ⟹ interaction_bounded_by ?consider (?r y) (?br y)⟧ ⟹ interaction_bounded_by ?consider (case ?x of Inl x ⇒ ?l x | Inr x ⇒ ?r x) (case ?x of Inl x ⇒ ?bl x | Inr x ⇒ ?br x)› and more 29 facts*)) (*goal: ‹interaction_any_bounded_by (obsf_distinguisher (𝒜 η)) (bound η)›*) by (rule interaction_bound (*‹interaction_bounded_by ?consider (Done ?x) 0› ‹interaction_bounded_by ?consider Fail 0› ‹interaction_bounded_by ?consider (lift_spmf ?p) 0› ‹interaction_bounded_by ?consider (assert_gpv ?b) 0› ‹(⋀input. interaction_bounded_by ?consider (?c input) (?n input)) ⟹ interaction_bounded_by ?consider (Pause ?out ?c) (if ?consider ?out then 1 + ⨆ range ?n else ⨆ range ?n)› ‹⟦interaction_bounded_by ?consider ?gpv ?n; ⋀x. x ∈ results'_gpv ?gpv ⟹ interaction_bounded_by ?consider (?f x) (?m x)⟧ ⟹ interaction_bounded_by ?consider (bind_gpv ?gpv ?f) (?n + ⨆ (?m ` results'_gpv ?gpv))› ‹(⋀input. interaction_bounded_by ?consider (bind_gpv (?c input) ?f) (?n input)) ⟹ interaction_bounded_by ?consider (bind_gpv (Pause ?out ?c) ?f) (if ?consider ?out then ⨆input. ?n input + 1 else ⨆ range ?n)› ‹(⋀x. x ∈ set_spmf ?p ⟹ interaction_bounded_by ?consider (?f x) (?n x)) ⟹ interaction_bounded_by ?consider (bind_gpv (lift_spmf ?p) ?f) (⨆ (?n ` set_spmf ?p))› ‹interaction_bounded_by ?consider (?f ?x) ?n ⟹ interaction_bounded_by ?consider (bind_gpv (Done ?x) ?f) ?n› ‹⟦?b ⟹ interaction_bounded_by ?consider ?gpv1.0 ?n; ¬ ?b ⟹ interaction_bounded_by ?consider ?gpv2.0 ?m⟧ ⟹ interaction_bounded_by ?consider (if ?b then ?gpv1.0 else ?gpv2.0) (if ?b then ?n else ?m)› ‹⟦?b ⟹ interaction_bounded_by ?consider ?t ?bt; ¬ ?b ⟹ interaction_bounded_by ?consider ?f ?bf⟧ ⟹ interaction_bounded_by ?consider (case ?b of True ⇒ ?t | False ⇒ ?f) (if ?b then ?bt else ?bf)› ‹⟦⋀y. ?x = Inl y ⟹ interaction_bounded_by ?consider (?l y) (?bl y); ⋀y. ?x = Inr y ⟹ interaction_bounded_by ?consider (?r y) (?br y)⟧ ⟹ interaction_bounded_by ?consider (case ?x of Inl x ⇒ ?l x | Inr x ⇒ ?r x) (case ?x of Inl x ⇒ ?bl x | Inr x ⇒ ?br x)› and more 29 facts*)) show "plossless_gpv (exception_ℐ (ℐ_real η ⊕⇩ℐ ℐ_common η)) (?𝒜 η)" if lossless for η using WT_adv[of η] (*‹ℐ_real η ⊕⇩ℐ ℐ_common η ⊢g 𝒜 η √›*) lossless (*‹lossless ⟹ plossless_gpv (ℐ_real ?η ⊕⇩ℐ ℐ_common ?η) (𝒜 ?η)›*) that (*‹lossless::bool›*) by simp qed have "negligible (λη. advantage (?𝒜 η) (obsf_resource (sim η |₌ 1⇩C ⊳ ideal_resource η)) (obsf_resource (real_resource η)))" apply (rule adv (*‹(⋀η. exception_ℐ (ℐ_real η ⊕⇩ℐ ℐ_common η) ⊢g obsf_distinguisher (𝒜 η) √) ⟹ Negligible.negligible (λη. advantage (obsf_distinguisher (𝒜 η)) (obsf_resource (sim η |₌ 1⇩C ⊳ ideal_resource η)) (obsf_resource (real_resource η)))›*)) (*goal: ‹Negligible.negligible (λη. advantage (obsf_distinguisher (𝒜 η)) (obsf_resource (sim η |₌ 1⇩C ⊳ ideal_resource η)) (obsf_resource (real_resource η)))›*) apply (rule WT_intro (*‹map_ℐ ?g ?h ?ℐ ⊢g ?gpv √ ⟹ ?ℐ ⊢g map_gpv' ?f ?g ?h ?gpv √› ‹map_ℐ ?g id ?ℐ ⊢g ?gpv √ ⟹ ?ℐ ⊢g map_gpv ?f ?g ?gpv √› ‹⟦?ℐ1.0 ⊢res ?res1.0 √; ?ℐ2.0 ⊢res ?res2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0 ⊢res ?res1.0 ∥ ?res2.0 √› ‹⟦map_ℐ (inv ?f) (inv ?g) ?ℐ, map_ℐ ?f' ?g' ?ℐ' ⊢⇩C ?conv √; inj ?f; surj ?g⟧ ⟹ ?ℐ, ?ℐ' ⊢⇩C map_converter ?f ?g ?f' ?g' ?conv √› ‹?ℐ, ?ℐ ⊢⇩C 1⇩C √› ‹?ℐ, ?ℐ' ⊢⇩C ⊥⇩C √› ‹⟦?ℐ1.0, ?ℐ2.0 ⊢⇩C ?conv1.0 √; ?ℐ1', ?ℐ2' ⊢⇩C ?conv2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ1', ?ℐ2.0 ⊕⇩ℐ ?ℐ2' ⊢⇩C ?conv1.0 |₌ ?conv2.0 √› ‹⟦?ℐ1.0, ?ℐ ⊢⇩C ?conv1.0 √; ?ℐ2.0, ?ℐ ⊢⇩C ?conv2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0, ?ℐ ⊢⇩C ?conv1.0 |⇩∝ ?conv2.0 √› ‹?ℐ ⊢res ?res √ ⟹ ?ℐ, ?ℐ' ⊢⇩C converter_of_resource ?res √› ‹?ℐ, ?ℐ' ⊢⇩C ?cnv √ ⟹ ?ℐ, ?ℐ' ⊢⇩C restrict_converter ?A ?ℐ' ?cnv √› ‹⟦?ℐ, ?ℐ' ⊢⇩C ?conv √; ?ℐ' ⊢res ?res √⟧ ⟹ ?ℐ ⊢res ?conv ⊳ ?res √› ‹⟦?ℐ, ?ℐ' ⊢⇩C ?conv √; ?ℐ', ?ℐ'' ⊢⇩C ?conv' √⟧ ⟹ ?ℐ, ?ℐ'' ⊢⇩C ?conv ⊙ ?conv' √› and more 28 facts*)) (*goal: ‹⋀η. exception_ℐ (ℐ_real η ⊕⇩ℐ ℐ_common η) ⊢g obsf_distinguisher (𝒜 η) √›*) by (rule WT_intro (*‹map_ℐ ?g ?h ?ℐ ⊢g ?gpv √ ⟹ ?ℐ ⊢g map_gpv' ?f ?g ?h ?gpv √› ‹map_ℐ ?g id ?ℐ ⊢g ?gpv √ ⟹ ?ℐ ⊢g map_gpv ?f ?g ?gpv √› ‹⟦?ℐ1.0 ⊢res ?res1.0 √; ?ℐ2.0 ⊢res ?res2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0 ⊢res ?res1.0 ∥ ?res2.0 √› ‹⟦map_ℐ (inv ?f) (inv ?g) ?ℐ, map_ℐ ?f' ?g' ?ℐ' ⊢⇩C ?conv √; inj ?f; surj ?g⟧ ⟹ ?ℐ, ?ℐ' ⊢⇩C map_converter ?f ?g ?f' ?g' ?conv √› ‹?ℐ, ?ℐ ⊢⇩C 1⇩C √› ‹?ℐ, ?ℐ' ⊢⇩C ⊥⇩C √› ‹⟦?ℐ1.0, ?ℐ2.0 ⊢⇩C ?conv1.0 √; ?ℐ1', ?ℐ2' ⊢⇩C ?conv2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ1', ?ℐ2.0 ⊕⇩ℐ ?ℐ2' ⊢⇩C ?conv1.0 |₌ ?conv2.0 √› ‹⟦?ℐ1.0, ?ℐ ⊢⇩C ?conv1.0 √; ?ℐ2.0, ?ℐ ⊢⇩C ?conv2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0, ?ℐ ⊢⇩C ?conv1.0 |⇩∝ ?conv2.0 √› ‹?ℐ ⊢res ?res √ ⟹ ?ℐ, ?ℐ' ⊢⇩C converter_of_resource ?res √› ‹?ℐ, ?ℐ' ⊢⇩C ?cnv √ ⟹ ?ℐ, ?ℐ' ⊢⇩C restrict_converter ?A ?ℐ' ?cnv √› ‹⟦?ℐ, ?ℐ' ⊢⇩C ?conv √; ?ℐ' ⊢res ?res √⟧ ⟹ ?ℐ ⊢res ?conv ⊳ ?res √› ‹⟦?ℐ, ?ℐ' ⊢⇩C ?conv √; ?ℐ', ?ℐ'' ⊢⇩C ?conv' √⟧ ⟹ ?ℐ, ?ℐ'' ⊢⇩C ?conv ⊙ ?conv' √› and more 28 facts*)) then show "negligible (λη. advantage (𝒜 η) (sim η |₌ 1⇩C ⊳ ideal_resource η) (real_resource η))" unfolding advantage_obsf_distinguisher (*goal: ‹Negligible.negligible (λη. advantage (𝒜 η) (sim η |₌ 1⇩C ⊳ ideal_resource η) (real_resource η))›*) . qed subsection ‹Composition theorems› theorem constructive_security_obsf'_composability: fixes real assumes "constructive_security_obsf' middle ideal sim_inner ℐ_middle ℐ_inner ℐ_common (λη. absorb (𝒜 η) (obsf_converter (sim_outer η |₌ 1⇩C)))" assumes "constructive_security_obsf' real middle sim_outer ℐ_real ℐ_middle ℐ_common 𝒜" shows "constructive_security_obsf' real ideal (λη. sim_outer η ⊙ sim_inner η) ℐ_real ℐ_inner ℐ_common 𝒜" proof(rule constructive_security_obsf'I) let ?𝒜 = "λη. absorb (𝒜 η) (obsf_converter (sim_outer η |₌ 1⇩C))" interpret inner: constructive_security_obsf' middle ideal sim_inner ℐ_middle ℐ_inner ℐ_common ?𝒜 by fact interpret outer: constructive_security_obsf' real middle sim_outer ℐ_real ℐ_middle ℐ_common 𝒜 by fact let ?adv1 = "λη. advantage (?𝒜 η) (obsf_resource (sim_inner η |₌ 1⇩C ⊳ ideal η)) (obsf_resource (middle η))" let ?adv2 = "λη. advantage (𝒜 η) (obsf_resource (sim_outer η |₌ 1⇩C ⊳ middle η)) (obsf_resource (real η))" let ?adv = "λη. ?adv1 η + ?adv2 η" show "constructive_security_obsf (real η) (ideal η) (sim_outer η ⊙ sim_inner η) (ℐ_real η) (ℐ_inner η) (ℐ_common η) (𝒜 η) (?adv η)" for η using inner.constructive_security_obsf'D outer.constructive_security_obsf'D by(rule constructive_security_obsf_composability) assume [WT_intro]: "exception_ℐ (ℐ_real η ⊕⇩ℐ ℐ_common η) ⊢g 𝒜 η √" for η have "negligible ?adv1" by(rule inner.adv)(rule WT_intro)+ also have "negligible ?adv2" by(rule outer.adv)(rule WT_intro)+ finally (negligible_plus) show "negligible ?adv" . qed theorem constructive_security_obsf'_lifting: (* TODO: generalize! *) assumes sec: "constructive_security_obsf' real_resource ideal_resource sim ℐ_real ℐ_ideal ℐ_common (λη. absorb (𝒜 η) (obsf_converter (1⇩C |₌ conv η)))" assumes WT_conv [WT_intro]: "⋀η. ℐ_common' η, ℐ_common η ⊢⇩C conv η √" and pfinite [pfinite_intro]: "⋀η. pfinite_converter (ℐ_common' η) (ℐ_common η) (conv η)" shows "constructive_security_obsf' (λη. 1⇩C |₌ conv η ⊳ real_resource η) (λη. 1⇩C |₌ conv η ⊳ ideal_resource η) sim ℐ_real ℐ_ideal ℐ_common' 𝒜" proof (rule constructive_security_obsf'I (*‹⟦⋀η. constructive_security_obsf (?real_resource η) (?ideal_resource η) (?sim η) (?ℐ_real η) (?ℐ_ideal η) (?ℐ_common η) (?𝒜 η) (?adv η); (⋀η. exception_ℐ (?ℐ_real η ⊕⇩ℐ ?ℐ_common η) ⊢g ?𝒜 η √) ⟹ Negligible.negligible ?adv⟧ ⟹ constructive_security_obsf' ?real_resource ?ideal_resource ?sim ?ℐ_real ?ℐ_ideal ?ℐ_common ?𝒜›*)) (*goals: 1. ‹⋀η. constructive_security_obsf (1⇩C |₌ conv η ⊳ real_resource η) (1⇩C |₌ conv η ⊳ ideal_resource η) (sim η) (ℐ_real η) (ℐ_ideal η) (ℐ_common' η) (𝒜 η) (?adv η)› 2. ‹(⋀η. exception_ℐ (ℐ_real η ⊕⇩ℐ ℐ_common' η) ⊢g 𝒜 η √) ⟹ Negligible.negligible ?adv›*) let ?𝒜 = "λη. absorb (𝒜 η) (obsf_converter (1⇩C |₌ conv η))" interpret constructive_security_obsf' real_resource ideal_resource sim "ℐ_real" "ℐ_ideal" "ℐ_common" "?𝒜" by fact let ?adv = "λη. advantage (?𝒜 η) (obsf_resource (sim η |₌ 1⇩C ⊳ ideal_resource η)) (obsf_resource (real_resource η))" fix η :: security show "constructive_security_obsf (1⇩C |₌ conv η ⊳ real_resource η) (1⇩C |₌ conv η ⊳ ideal_resource η) (sim η) (ℐ_real η) (ℐ_ideal η) (ℐ_common' η) (𝒜 η) (?adv η)" using constructive_security_obsf.constructive_security_aux_obsf[OF constructive_security_obsf'D] (*‹constructive_security_aux_obsf ((real_resource::nat ⇒ ('a + 'b, 'c + 'd) resource) (?η1::nat)) ((ideal_resource::nat ⇒ ('e + 'b, 'f + 'd) resource) ?η1) ((sim::nat ⇒ ('a, 'c, 'e, 'f) converter) ?η1) ((ℐ_real::nat ⇒ ('a, 'c) ℐ) ?η1) ((ℐ_ideal::nat ⇒ ('e, 'f) ℐ) ?η1) ((ℐ_common::nat ⇒ ('b, 'd) ℐ) ?η1) (advantage (absorb ((𝒜::nat ⇒ ('a + 'g, 'c + 'h) distinguisher_obsf) ?η1) (obsf_converter (1⇩C |₌ (conv::nat ⇒ ('g, 'h, 'b, 'd) converter) ?η1))) (obsf_resource (sim ?η1 |₌ 1⇩C ⊳ ideal_resource ?η1)) (obsf_resource (real_resource ?η1)))›*) constructive_security_obsf.constructive_security_sim_obsf[OF constructive_security_obsf'D] (*‹constructive_security_sim_obsf (real_resource ?η1) (ideal_resource ?η1) (sim ?η1) (ℐ_real ?η1) (ℐ_common ?η1) (absorb (𝒜 ?η1) (obsf_converter (1⇩C |₌ conv ?η1))) (advantage (absorb (𝒜 ?η1) (obsf_converter (1⇩C |₌ conv ?η1))) (obsf_resource (sim ?η1 |₌ 1⇩C ⊳ ideal_resource ?η1)) (obsf_resource (real_resource ?η1)))›*) apply (rule constructive_security_obsf_lifting_usr (*‹⟦constructive_security_aux_obsf (?real_resource::(?'a + ?'b, ?'c + ?'d) resource) (?ideal_resource::(?'e + ?'b, ?'f + ?'d) resource) (?sim::(?'a, ?'c, ?'e, ?'f) converter) (?ℐ_real::(?'a, ?'c) ℐ) (?ℐ_ideal::(?'e, ?'f) ℐ) (?ℐ_common::(?'b, ?'d) ℐ) (?adv::real); exception_ℐ (?ℐ_real ⊕⇩ℐ (?ℐ_common'::(?'g, ?'h) ℐ)) ⊢g ?𝒜::(?'a + ?'g, ?'c + ?'h) distinguisher_obsf √ ⟹ constructive_security_sim_obsf ?real_resource ?ideal_resource ?sim ?ℐ_real ?ℐ_common (absorb ?𝒜 (obsf_converter (1⇩C |₌ (?conv::(?'g, ?'h, ?'b, ?'d) converter)))) ?adv; ?ℐ_common', ?ℐ_common ⊢⇩C ?conv √; pfinite_converter ?ℐ_common' ?ℐ_common ?conv⟧ ⟹ constructive_security_obsf (1⇩C |₌ ?conv ⊳ ?real_resource) (1⇩C |₌ ?conv ⊳ ?ideal_resource) ?sim ?ℐ_real ?ℐ_ideal ?ℐ_common' ?𝒜 ?adv›*)) (*goals: 1. ‹(ℐ_common'::nat ⇒ ('g, 'h) ℐ) (η::nat), (ℐ_common::nat ⇒ ('b, 'd) ℐ) η ⊢⇩C (conv::nat ⇒ ('g, 'h, 'b, 'd) converter) η √› 2. ‹pfinite_converter ((ℐ_common'::nat ⇒ ('g, 'h) ℐ) (η::nat)) ((ℐ_common::nat ⇒ ('b, 'd) ℐ) η) ((conv::nat ⇒ ('g, 'h, 'b, 'd) converter) η)› discuss goal 1*) apply (rule WT_intro (*‹map_ℐ ?g ?h ?ℐ ⊢g ?gpv √ ⟹ ?ℐ ⊢g map_gpv' ?f ?g ?h ?gpv √› ‹map_ℐ ?g id ?ℐ ⊢g ?gpv √ ⟹ ?ℐ ⊢g map_gpv ?f ?g ?gpv √› ‹⟦?ℐ1.0 ⊢res ?res1.0 √; ?ℐ2.0 ⊢res ?res2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0 ⊢res ?res1.0 ∥ ?res2.0 √› ‹⟦map_ℐ (inv ?f) (inv ?g) ?ℐ, map_ℐ ?f' ?g' ?ℐ' ⊢⇩C ?conv √; inj ?f; surj ?g⟧ ⟹ ?ℐ, ?ℐ' ⊢⇩C map_converter ?f ?g ?f' ?g' ?conv √› ‹?ℐ, ?ℐ ⊢⇩C 1⇩C √› ‹?ℐ, ?ℐ' ⊢⇩C ⊥⇩C √› ‹⟦?ℐ1.0, ?ℐ2.0 ⊢⇩C ?conv1.0 √; ?ℐ1', ?ℐ2' ⊢⇩C ?conv2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ1', ?ℐ2.0 ⊕⇩ℐ ?ℐ2' ⊢⇩C ?conv1.0 |₌ ?conv2.0 √› ‹⟦?ℐ1.0, ?ℐ ⊢⇩C ?conv1.0 √; ?ℐ2.0, ?ℐ ⊢⇩C ?conv2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0, ?ℐ ⊢⇩C ?conv1.0 |⇩∝ ?conv2.0 √› ‹?ℐ ⊢res ?res √ ⟹ ?ℐ, ?ℐ' ⊢⇩C converter_of_resource ?res √› ‹?ℐ, ?ℐ' ⊢⇩C ?cnv √ ⟹ ?ℐ, ?ℐ' ⊢⇩C restrict_converter ?A ?ℐ' ?cnv √› ‹⟦?ℐ, ?ℐ' ⊢⇩C ?conv √; ?ℐ' ⊢res ?res √⟧ ⟹ ?ℐ ⊢res ?conv ⊳ ?res √› ‹⟦?ℐ, ?ℐ' ⊢⇩C ?conv √; ?ℐ', ?ℐ'' ⊢⇩C ?conv' √⟧ ⟹ ?ℐ, ?ℐ'' ⊢⇩C ?conv ⊙ ?conv' √› and more 28 facts*) pfinite_intro (*‹pfinite_converter ?ℐ ?ℐ 1⇩C› ‹pfinite_converter ?ℐ ?ℐ' ⊥⇩C› ‹⟦pfinite_converter ?ℐ1.0 ?ℐ1' ?conv1.0; pfinite_converter ?ℐ2.0 ?ℐ2' ?conv2.0⟧ ⟹ pfinite_converter (?ℐ1.0 ⊕⇩ℐ ?ℐ2.0) (?ℐ1' ⊕⇩ℐ ?ℐ2') (?conv1.0 |₌ ?conv2.0)› ‹⟦pfinite_converter ?ℐ1.0 ?ℐ2.0 ?conv1.0; pfinite_converter ?ℐ2.0 ?ℐ3.0 ?conv2.0; ?ℐ1.0, ?ℐ2.0 ⊢⇩C ?conv1.0 √; ?ℐ2.0, ?ℐ3.0 ⊢⇩C ?conv2.0 √⟧ ⟹ pfinite_converter ?ℐ1.0 ?ℐ3.0 (?conv1.0 ⊙ ?conv2.0)› ‹⟦pfinite_converter (map_ℐ (inv ?f) (inv ?g) ?ℐ) (map_ℐ ?f' ?g' ?ℐ') ?conv; inj ?f; surj ?g⟧ ⟹ pfinite_converter ?ℐ ?ℐ' (map_converter ?f ?g ?f' ?g' ?conv)› ‹pfinite_converter ((?ℐ1.0 ⊕⇩ℐ ?ℐ2.0) ⊕⇩ℐ ?ℐ3.0) (?ℐ1.0 ⊕⇩ℐ (?ℐ2.0 ⊕⇩ℐ ?ℐ3.0)) lassocr⇩C› ‹pfinite_converter (?ℐ1.0 ⊕⇩ℐ (?ℐ2.0 ⊕⇩ℐ ?ℐ3.0)) ((?ℐ1.0 ⊕⇩ℐ ?ℐ2.0) ⊕⇩ℐ ?ℐ3.0) rassocl⇩C› ‹pfinite_converter (?ℐ1.0 ⊕⇩ℐ ?ℐ2.0) (?ℐ2.0 ⊕⇩ℐ ?ℐ1.0) swap⇩C› ‹pfinite_converter (?ℐ1.0 ⊕⇩ℐ (?ℐ2.0 ⊕⇩ℐ ?ℐ3.0)) (?ℐ2.0 ⊕⇩ℐ (?ℐ1.0 ⊕⇩ℐ ?ℐ3.0)) swap_lassocr› ‹pfinite_converter ((?ℐ1.0 ⊕⇩ℐ ?ℐ2.0) ⊕⇩ℐ ?ℐ3.0) ((?ℐ1.0 ⊕⇩ℐ ?ℐ3.0) ⊕⇩ℐ ?ℐ2.0) swap_rassocl› ‹pfinite_converter ((?ℐ1.0 ⊕⇩ℐ ?ℐ2.0) ⊕⇩ℐ (?ℐ3.0 ⊕⇩ℐ ?ℐ4.0)) ((?ℐ1.0 ⊕⇩ℐ ?ℐ3.0) ⊕⇩ℐ (?ℐ2.0 ⊕⇩ℐ ?ℐ4.0)) parallel_wiring› ‹⟦pfinite_converter ?ℐ1.0 ?ℐ3.0 ?conv1.0; pfinite_converter ?ℐ2.0 ?ℐ3.0 ?conv2.0⟧ ⟹ pfinite_converter (?ℐ1.0 ⊕⇩ℐ ?ℐ2.0) ?ℐ3.0 (?conv1.0 |⇩∝ ?conv2.0)› and more 3 facts*)) (*discuss goal 2*) apply (rule WT_intro (*‹map_ℐ ?g ?h ?ℐ ⊢g ?gpv √ ⟹ ?ℐ ⊢g map_gpv' ?f ?g ?h ?gpv √› ‹map_ℐ ?g id ?ℐ ⊢g ?gpv √ ⟹ ?ℐ ⊢g map_gpv ?f ?g ?gpv √› ‹⟦?ℐ1.0 ⊢res ?res1.0 √; ?ℐ2.0 ⊢res ?res2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0 ⊢res ?res1.0 ∥ ?res2.0 √› ‹⟦map_ℐ (inv ?f) (inv ?g) ?ℐ, map_ℐ ?f' ?g' ?ℐ' ⊢⇩C ?conv √; inj ?f; surj ?g⟧ ⟹ ?ℐ, ?ℐ' ⊢⇩C map_converter ?f ?g ?f' ?g' ?conv √› ‹?ℐ, ?ℐ ⊢⇩C 1⇩C √› ‹?ℐ, ?ℐ' ⊢⇩C ⊥⇩C √› ‹⟦?ℐ1.0, ?ℐ2.0 ⊢⇩C ?conv1.0 √; ?ℐ1', ?ℐ2' ⊢⇩C ?conv2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ1', ?ℐ2.0 ⊕⇩ℐ ?ℐ2' ⊢⇩C ?conv1.0 |₌ ?conv2.0 √› ‹⟦?ℐ1.0, ?ℐ ⊢⇩C ?conv1.0 √; ?ℐ2.0, ?ℐ ⊢⇩C ?conv2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0, ?ℐ ⊢⇩C ?conv1.0 |⇩∝ ?conv2.0 √› ‹?ℐ ⊢res ?res √ ⟹ ?ℐ, ?ℐ' ⊢⇩C converter_of_resource ?res √› ‹?ℐ, ?ℐ' ⊢⇩C ?cnv √ ⟹ ?ℐ, ?ℐ' ⊢⇩C restrict_converter ?A ?ℐ' ?cnv √› ‹⟦?ℐ, ?ℐ' ⊢⇩C ?conv √; ?ℐ' ⊢res ?res √⟧ ⟹ ?ℐ ⊢res ?conv ⊳ ?res √› ‹⟦?ℐ, ?ℐ' ⊢⇩C ?conv √; ?ℐ', ?ℐ'' ⊢⇩C ?conv' √⟧ ⟹ ?ℐ, ?ℐ'' ⊢⇩C ?conv ⊙ ?conv' √› and more 28 facts*) pfinite_intro (*‹pfinite_converter ?ℐ ?ℐ 1⇩C› ‹pfinite_converter ?ℐ ?ℐ' ⊥⇩C› ‹⟦pfinite_converter ?ℐ1.0 ?ℐ1' ?conv1.0; pfinite_converter ?ℐ2.0 ?ℐ2' ?conv2.0⟧ ⟹ pfinite_converter (?ℐ1.0 ⊕⇩ℐ ?ℐ2.0) (?ℐ1' ⊕⇩ℐ ?ℐ2') (?conv1.0 |₌ ?conv2.0)› ‹⟦pfinite_converter ?ℐ1.0 ?ℐ2.0 ?conv1.0; pfinite_converter ?ℐ2.0 ?ℐ3.0 ?conv2.0; ?ℐ1.0, ?ℐ2.0 ⊢⇩C ?conv1.0 √; ?ℐ2.0, ?ℐ3.0 ⊢⇩C ?conv2.0 √⟧ ⟹ pfinite_converter ?ℐ1.0 ?ℐ3.0 (?conv1.0 ⊙ ?conv2.0)› ‹⟦pfinite_converter (map_ℐ (inv ?f) (inv ?g) ?ℐ) (map_ℐ ?f' ?g' ?ℐ') ?conv; inj ?f; surj ?g⟧ ⟹ pfinite_converter ?ℐ ?ℐ' (map_converter ?f ?g ?f' ?g' ?conv)› ‹pfinite_converter ((?ℐ1.0 ⊕⇩ℐ ?ℐ2.0) ⊕⇩ℐ ?ℐ3.0) (?ℐ1.0 ⊕⇩ℐ (?ℐ2.0 ⊕⇩ℐ ?ℐ3.0)) lassocr⇩C› ‹pfinite_converter (?ℐ1.0 ⊕⇩ℐ (?ℐ2.0 ⊕⇩ℐ ?ℐ3.0)) ((?ℐ1.0 ⊕⇩ℐ ?ℐ2.0) ⊕⇩ℐ ?ℐ3.0) rassocl⇩C› ‹pfinite_converter (?ℐ1.0 ⊕⇩ℐ ?ℐ2.0) (?ℐ2.0 ⊕⇩ℐ ?ℐ1.0) swap⇩C› ‹pfinite_converter (?ℐ1.0 ⊕⇩ℐ (?ℐ2.0 ⊕⇩ℐ ?ℐ3.0)) (?ℐ2.0 ⊕⇩ℐ (?ℐ1.0 ⊕⇩ℐ ?ℐ3.0)) swap_lassocr› ‹pfinite_converter ((?ℐ1.0 ⊕⇩ℐ ?ℐ2.0) ⊕⇩ℐ ?ℐ3.0) ((?ℐ1.0 ⊕⇩ℐ ?ℐ3.0) ⊕⇩ℐ ?ℐ2.0) swap_rassocl› ‹pfinite_converter ((?ℐ1.0 ⊕⇩ℐ ?ℐ2.0) ⊕⇩ℐ (?ℐ3.0 ⊕⇩ℐ ?ℐ4.0)) ((?ℐ1.0 ⊕⇩ℐ ?ℐ3.0) ⊕⇩ℐ (?ℐ2.0 ⊕⇩ℐ ?ℐ4.0)) parallel_wiring› ‹⟦pfinite_converter ?ℐ1.0 ?ℐ3.0 ?conv1.0; pfinite_converter ?ℐ2.0 ?ℐ3.0 ?conv2.0⟧ ⟹ pfinite_converter (?ℐ1.0 ⊕⇩ℐ ?ℐ2.0) ?ℐ3.0 (?conv1.0 |⇩∝ ?conv2.0)› and more 3 facts*)) (*proven 2 subgoals*) . show "negligible ?adv" if [WT_intro]: "⋀η. exception_ℐ (ℐ_real η ⊕⇩ℐ ℐ_common' η) ⊢g 𝒜 η √" apply (rule adv (*‹(⋀η. exception_ℐ (ℐ_real η ⊕⇩ℐ ℐ_common η) ⊢g absorb (𝒜 η) (obsf_converter (1⇩C |₌ conv η)) √) ⟹ Negligible.negligible (λη. advantage (absorb (𝒜 η) (obsf_converter (1⇩C |₌ conv η))) (obsf_resource (sim η |₌ 1⇩C ⊳ ideal_resource η)) (obsf_resource (real_resource η)))›*)) (*goal: ‹Negligible.negligible (λη. advantage (absorb (𝒜 η) (obsf_converter (1⇩C |₌ conv η))) (obsf_resource (sim η |₌ 1⇩C ⊳ ideal_resource η)) (obsf_resource (real_resource η)))›*) apply (rule WT_intro (*‹map_ℐ (?g::?'a ⇒ ?'d) (?h::?'e ⇒ ?'b) (?ℐ::(?'d, ?'e) ℐ) ⊢g ?gpv::(?'c, ?'a, ?'b) gpv √ ⟹ ?ℐ ⊢g map_gpv' (?f::?'c ⇒ ?'f) ?g ?h ?gpv √› ‹map_ℐ (?g::?'a ⇒ ?'d) id (?ℐ::(?'d, ?'b) ℐ) ⊢g ?gpv::(?'c, ?'a, ?'b) gpv √ ⟹ ?ℐ ⊢g map_gpv (?f::?'c ⇒ ?'e) ?g ?gpv √› ‹⟦(?ℐ1.0::(?'a, ?'b) ℐ) ⊢res ?res1.0::(?'a, ?'b) resource √; (?ℐ2.0::(?'c, ?'d) ℐ) ⊢res ?res2.0::(?'c, ?'d) resource √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0 ⊢res ?res1.0 ∥ ?res2.0 √› ‹⟦map_ℐ (inv (?f::?'e ⇒ ?'a)) (inv (?g::?'b ⇒ ?'f)) (?ℐ::(?'e, ?'f) ℐ), map_ℐ (?f'::?'c ⇒ ?'g) (?g'::?'h ⇒ ?'d) (?ℐ'::(?'g, ?'h) ℐ) ⊢⇩C ?conv::(?'a, ?'b, ?'c, ?'d) converter √; inj ?f; surj ?g⟧ ⟹ ?ℐ, ?ℐ' ⊢⇩C map_converter ?f ?g ?f' ?g' ?conv √› ‹(?ℐ::(?'a, ?'b) ℐ), ?ℐ ⊢⇩C 1⇩C √› ‹(?ℐ::(?'a, ?'b) ℐ), ?ℐ'::(?'c, ?'d) ℐ ⊢⇩C ⊥⇩C √› ‹⟦(?ℐ1.0::(?'a, ?'b) ℐ), ?ℐ2.0::(?'c, ?'d) ℐ ⊢⇩C ?conv1.0::(?'a, ?'b, ?'c, ?'d) converter √; (?ℐ1'::(?'e, ?'f) ℐ), ?ℐ2'::(?'g, ?'h) ℐ ⊢⇩C ?conv2.0::(?'e, ?'f, ?'g, ?'h) converter √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ1', ?ℐ2.0 ⊕⇩ℐ ?ℐ2' ⊢⇩C ?conv1.0 |₌ ?conv2.0 √› ‹⟦(?ℐ1.0::(?'a, ?'b) ℐ), ?ℐ::(?'c, ?'d) ℐ ⊢⇩C ?conv1.0::(?'a, ?'b, ?'c, ?'d) converter √; (?ℐ2.0::(?'e, ?'f) ℐ), ?ℐ ⊢⇩C ?conv2.0::(?'e, ?'f, ?'c, ?'d) converter √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0, ?ℐ ⊢⇩C ?conv1.0 |⇩∝ ?conv2.0 √› ‹(?ℐ::(?'a, ?'b) ℐ) ⊢res ?res::(?'a, ?'b) resource √ ⟹ ?ℐ, ?ℐ'::(?'c, ?'d) ℐ ⊢⇩C converter_of_resource ?res √› ‹(?ℐ::(?'a, ?'b) ℐ), ?ℐ'::(?'c, ?'d) ℐ ⊢⇩C ?cnv::(?'a, ?'b, ?'c, ?'d) converter √ ⟹ ?ℐ, ?ℐ' ⊢⇩C restrict_converter (?A::?'a set) ?ℐ' ?cnv √› ‹⟦(?ℐ::(?'a, ?'b) ℐ), ?ℐ'::(?'c, ?'d) ℐ ⊢⇩C ?conv::(?'a, ?'b, ?'c, ?'d) converter √; ?ℐ' ⊢res ?res::(?'c, ?'d) resource √⟧ ⟹ ?ℐ ⊢res ?conv ⊳ ?res √› ‹⟦(?ℐ::(?'a, ?'b) ℐ), ?ℐ'::(?'c, ?'d) ℐ ⊢⇩C ?conv::(?'a, ?'b, ?'c, ?'d) converter √; ?ℐ', ?ℐ''::(?'e, ?'f) ℐ ⊢⇩C ?conv'::(?'c, ?'d, ?'e, ?'f) converter √⟧ ⟹ ?ℐ, ?ℐ'' ⊢⇩C ?conv ⊙ ?conv' √› and more 29 facts*)) (*goals: 1. ‹⋀η. ?ℐ'1 η ⊢g 𝒜 η √› 2. ‹⋀η. ?ℐ'1 η, exception_ℐ (ℐ_real η ⊕⇩ℐ ℐ_common η) ⊢⇩C obsf_converter (1⇩C |₌ conv η) √› discuss goal 1*) apply (rule WT_intro (*‹map_ℐ ?g ?h ?ℐ ⊢g ?gpv √ ⟹ ?ℐ ⊢g map_gpv' ?f ?g ?h ?gpv √› ‹map_ℐ ?g id ?ℐ ⊢g ?gpv √ ⟹ ?ℐ ⊢g map_gpv ?f ?g ?gpv √› ‹⟦?ℐ1.0 ⊢res ?res1.0 √; ?ℐ2.0 ⊢res ?res2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0 ⊢res ?res1.0 ∥ ?res2.0 √› ‹⟦map_ℐ (inv ?f) (inv ?g) ?ℐ, map_ℐ ?f' ?g' ?ℐ' ⊢⇩C ?conv √; inj ?f; surj ?g⟧ ⟹ ?ℐ, ?ℐ' ⊢⇩C map_converter ?f ?g ?f' ?g' ?conv √› ‹?ℐ, ?ℐ ⊢⇩C 1⇩C √› ‹?ℐ, ?ℐ' ⊢⇩C ⊥⇩C √› ‹⟦?ℐ1.0, ?ℐ2.0 ⊢⇩C ?conv1.0 √; ?ℐ1', ?ℐ2' ⊢⇩C ?conv2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ1', ?ℐ2.0 ⊕⇩ℐ ?ℐ2' ⊢⇩C ?conv1.0 |₌ ?conv2.0 √› ‹⟦?ℐ1.0, ?ℐ ⊢⇩C ?conv1.0 √; ?ℐ2.0, ?ℐ ⊢⇩C ?conv2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0, ?ℐ ⊢⇩C ?conv1.0 |⇩∝ ?conv2.0 √› ‹?ℐ ⊢res ?res √ ⟹ ?ℐ, ?ℐ' ⊢⇩C converter_of_resource ?res √› ‹?ℐ, ?ℐ' ⊢⇩C ?cnv √ ⟹ ?ℐ, ?ℐ' ⊢⇩C restrict_converter ?A ?ℐ' ?cnv √› ‹⟦?ℐ, ?ℐ' ⊢⇩C ?conv √; ?ℐ' ⊢res ?res √⟧ ⟹ ?ℐ ⊢res ?conv ⊳ ?res √› ‹⟦?ℐ, ?ℐ' ⊢⇩C ?conv √; ?ℐ', ?ℐ'' ⊢⇩C ?conv' √⟧ ⟹ ?ℐ, ?ℐ'' ⊢⇩C ?conv ⊙ ?conv' √› and more 29 facts*)) (*discuss goal 2*) apply (rule WT_intro (*‹map_ℐ ?g ?h ?ℐ ⊢g ?gpv √ ⟹ ?ℐ ⊢g map_gpv' ?f ?g ?h ?gpv √› ‹map_ℐ ?g id ?ℐ ⊢g ?gpv √ ⟹ ?ℐ ⊢g map_gpv ?f ?g ?gpv √› ‹⟦?ℐ1.0 ⊢res ?res1.0 √; ?ℐ2.0 ⊢res ?res2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0 ⊢res ?res1.0 ∥ ?res2.0 √› ‹⟦map_ℐ (inv ?f) (inv ?g) ?ℐ, map_ℐ ?f' ?g' ?ℐ' ⊢⇩C ?conv √; inj ?f; surj ?g⟧ ⟹ ?ℐ, ?ℐ' ⊢⇩C map_converter ?f ?g ?f' ?g' ?conv √› ‹?ℐ, ?ℐ ⊢⇩C 1⇩C √› ‹?ℐ, ?ℐ' ⊢⇩C ⊥⇩C √› ‹⟦?ℐ1.0, ?ℐ2.0 ⊢⇩C ?conv1.0 √; ?ℐ1', ?ℐ2' ⊢⇩C ?conv2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ1', ?ℐ2.0 ⊕⇩ℐ ?ℐ2' ⊢⇩C ?conv1.0 |₌ ?conv2.0 √› ‹⟦?ℐ1.0, ?ℐ ⊢⇩C ?conv1.0 √; ?ℐ2.0, ?ℐ ⊢⇩C ?conv2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0, ?ℐ ⊢⇩C ?conv1.0 |⇩∝ ?conv2.0 √› ‹?ℐ ⊢res ?res √ ⟹ ?ℐ, ?ℐ' ⊢⇩C converter_of_resource ?res √› ‹?ℐ, ?ℐ' ⊢⇩C ?cnv √ ⟹ ?ℐ, ?ℐ' ⊢⇩C restrict_converter ?A ?ℐ' ?cnv √› ‹⟦?ℐ, ?ℐ' ⊢⇩C ?conv √; ?ℐ' ⊢res ?res √⟧ ⟹ ?ℐ ⊢res ?conv ⊳ ?res √› ‹⟦?ℐ, ?ℐ' ⊢⇩C ?conv √; ?ℐ', ?ℐ'' ⊢⇩C ?conv' √⟧ ⟹ ?ℐ, ?ℐ'' ⊢⇩C ?conv ⊙ ?conv' √› and more 29 facts*)) (*goal: ‹⋀η. exception_ℐ (ℐ_real η ⊕⇩ℐ ℐ_common' η), exception_ℐ (ℐ_real η ⊕⇩ℐ ℐ_common η) ⊢⇩C obsf_converter (1⇩C |₌ conv η) √›*) apply (rule WT_intro (*‹map_ℐ ?g ?h ?ℐ ⊢g ?gpv √ ⟹ ?ℐ ⊢g map_gpv' ?f ?g ?h ?gpv √› ‹map_ℐ ?g id ?ℐ ⊢g ?gpv √ ⟹ ?ℐ ⊢g map_gpv ?f ?g ?gpv √› ‹⟦?ℐ1.0 ⊢res ?res1.0 √; ?ℐ2.0 ⊢res ?res2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0 ⊢res ?res1.0 ∥ ?res2.0 √› ‹⟦map_ℐ (inv ?f) (inv ?g) ?ℐ, map_ℐ ?f' ?g' ?ℐ' ⊢⇩C ?conv √; inj ?f; surj ?g⟧ ⟹ ?ℐ, ?ℐ' ⊢⇩C map_converter ?f ?g ?f' ?g' ?conv √› ‹?ℐ, ?ℐ ⊢⇩C 1⇩C √› ‹?ℐ, ?ℐ' ⊢⇩C ⊥⇩C √› ‹⟦?ℐ1.0, ?ℐ2.0 ⊢⇩C ?conv1.0 √; ?ℐ1', ?ℐ2' ⊢⇩C ?conv2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ1', ?ℐ2.0 ⊕⇩ℐ ?ℐ2' ⊢⇩C ?conv1.0 |₌ ?conv2.0 √› ‹⟦?ℐ1.0, ?ℐ ⊢⇩C ?conv1.0 √; ?ℐ2.0, ?ℐ ⊢⇩C ?conv2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0, ?ℐ ⊢⇩C ?conv1.0 |⇩∝ ?conv2.0 √› ‹?ℐ ⊢res ?res √ ⟹ ?ℐ, ?ℐ' ⊢⇩C converter_of_resource ?res √› ‹?ℐ, ?ℐ' ⊢⇩C ?cnv √ ⟹ ?ℐ, ?ℐ' ⊢⇩C restrict_converter ?A ?ℐ' ?cnv √› ‹⟦?ℐ, ?ℐ' ⊢⇩C ?conv √; ?ℐ' ⊢res ?res √⟧ ⟹ ?ℐ ⊢res ?conv ⊳ ?res √› ‹⟦?ℐ, ?ℐ' ⊢⇩C ?conv √; ?ℐ', ?ℐ'' ⊢⇩C ?conv' √⟧ ⟹ ?ℐ, ?ℐ'' ⊢⇩C ?conv ⊙ ?conv' √› and more 29 facts*)) (*goals: 1. ‹⋀η. ℐ_real η, ℐ_real η ⊢⇩C 1⇩C √› 2. ‹⋀η. ℐ_common' η, ℐ_common η ⊢⇩C conv η √› discuss goal 1*) apply (rule WT_intro (*‹map_ℐ ?g ?h ?ℐ ⊢g ?gpv √ ⟹ ?ℐ ⊢g map_gpv' ?f ?g ?h ?gpv √› ‹map_ℐ ?g id ?ℐ ⊢g ?gpv √ ⟹ ?ℐ ⊢g map_gpv ?f ?g ?gpv √› ‹⟦?ℐ1.0 ⊢res ?res1.0 √; ?ℐ2.0 ⊢res ?res2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0 ⊢res ?res1.0 ∥ ?res2.0 √› ‹⟦map_ℐ (inv ?f) (inv ?g) ?ℐ, map_ℐ ?f' ?g' ?ℐ' ⊢⇩C ?conv √; inj ?f; surj ?g⟧ ⟹ ?ℐ, ?ℐ' ⊢⇩C map_converter ?f ?g ?f' ?g' ?conv √› ‹?ℐ, ?ℐ ⊢⇩C 1⇩C √› ‹?ℐ, ?ℐ' ⊢⇩C ⊥⇩C √› ‹⟦?ℐ1.0, ?ℐ2.0 ⊢⇩C ?conv1.0 √; ?ℐ1', ?ℐ2' ⊢⇩C ?conv2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ1', ?ℐ2.0 ⊕⇩ℐ ?ℐ2' ⊢⇩C ?conv1.0 |₌ ?conv2.0 √› ‹⟦?ℐ1.0, ?ℐ ⊢⇩C ?conv1.0 √; ?ℐ2.0, ?ℐ ⊢⇩C ?conv2.0 √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0, ?ℐ ⊢⇩C ?conv1.0 |⇩∝ ?conv2.0 √› ‹?ℐ ⊢res ?res √ ⟹ ?ℐ, ?ℐ' ⊢⇩C converter_of_resource ?res √› ‹?ℐ, ?ℐ' ⊢⇩C ?cnv √ ⟹ ?ℐ, ?ℐ' ⊢⇩C restrict_converter ?A ?ℐ' ?cnv √› ‹⟦?ℐ, ?ℐ' ⊢⇩C ?conv √; ?ℐ' ⊢res ?res √⟧ ⟹ ?ℐ ⊢res ?conv ⊳ ?res √› ‹⟦?ℐ, ?ℐ' ⊢⇩C ?conv √; ?ℐ', ?ℐ'' ⊢⇩C ?conv' √⟧ ⟹ ?ℐ, ?ℐ'' ⊢⇩C ?conv ⊙ ?conv' √› and more 29 facts*)) (*discuss goal 2*) apply (rule WT_intro (*‹map_ℐ (?g::?'a ⇒ ?'d) (?h::?'e ⇒ ?'b) (?ℐ::(?'d, ?'e) ℐ) ⊢g ?gpv::(?'c, ?'a, ?'b) gpv √ ⟹ ?ℐ ⊢g map_gpv' (?f::?'c ⇒ ?'f) ?g ?h ?gpv √› ‹map_ℐ (?g::?'a ⇒ ?'d) id (?ℐ::(?'d, ?'b) ℐ) ⊢g ?gpv::(?'c, ?'a, ?'b) gpv √ ⟹ ?ℐ ⊢g map_gpv (?f::?'c ⇒ ?'e) ?g ?gpv √› ‹⟦(?ℐ1.0::(?'a, ?'b) ℐ) ⊢res ?res1.0::(?'a, ?'b) resource √; (?ℐ2.0::(?'c, ?'d) ℐ) ⊢res ?res2.0::(?'c, ?'d) resource √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0 ⊢res ?res1.0 ∥ ?res2.0 √› ‹⟦map_ℐ (inv (?f::?'e ⇒ ?'a)) (inv (?g::?'b ⇒ ?'f)) (?ℐ::(?'e, ?'f) ℐ), map_ℐ (?f'::?'c ⇒ ?'g) (?g'::?'h ⇒ ?'d) (?ℐ'::(?'g, ?'h) ℐ) ⊢⇩C ?conv::(?'a, ?'b, ?'c, ?'d) converter √; inj ?f; surj ?g⟧ ⟹ ?ℐ, ?ℐ' ⊢⇩C map_converter ?f ?g ?f' ?g' ?conv √› ‹(?ℐ::(?'a, ?'b) ℐ), ?ℐ ⊢⇩C 1⇩C √› ‹(?ℐ::(?'a, ?'b) ℐ), ?ℐ'::(?'c, ?'d) ℐ ⊢⇩C ⊥⇩C √› ‹⟦(?ℐ1.0::(?'a, ?'b) ℐ), ?ℐ2.0::(?'c, ?'d) ℐ ⊢⇩C ?conv1.0::(?'a, ?'b, ?'c, ?'d) converter √; (?ℐ1'::(?'e, ?'f) ℐ), ?ℐ2'::(?'g, ?'h) ℐ ⊢⇩C ?conv2.0::(?'e, ?'f, ?'g, ?'h) converter √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ1', ?ℐ2.0 ⊕⇩ℐ ?ℐ2' ⊢⇩C ?conv1.0 |₌ ?conv2.0 √› ‹⟦(?ℐ1.0::(?'a, ?'b) ℐ), ?ℐ::(?'c, ?'d) ℐ ⊢⇩C ?conv1.0::(?'a, ?'b, ?'c, ?'d) converter √; (?ℐ2.0::(?'e, ?'f) ℐ), ?ℐ ⊢⇩C ?conv2.0::(?'e, ?'f, ?'c, ?'d) converter √⟧ ⟹ ?ℐ1.0 ⊕⇩ℐ ?ℐ2.0, ?ℐ ⊢⇩C ?conv1.0 |⇩∝ ?conv2.0 √› ‹(?ℐ::(?'a, ?'b) ℐ) ⊢res ?res::(?'a, ?'b) resource √ ⟹ ?ℐ, ?ℐ'::(?'c, ?'d) ℐ ⊢⇩C converter_of_resource ?res √› ‹(?ℐ::(?'a, ?'b) ℐ), ?ℐ'::(?'c, ?'d) ℐ ⊢⇩C ?cnv::(?'a, ?'b, ?'c, ?'d) converter √ ⟹ ?ℐ, ?ℐ' ⊢⇩C restrict_converter (?A::?'a set) ?ℐ' ?cnv √› ‹⟦(?ℐ::(?'a, ?'b) ℐ), ?ℐ'::(?'c, ?'d) ℐ ⊢⇩C ?conv::(?'a, ?'b, ?'c, ?'d) converter √; ?ℐ' ⊢res ?res::(?'c, ?'d) resource √⟧ ⟹ ?ℐ ⊢res ?conv ⊳ ?res √› ‹⟦(?ℐ::(?'a, ?'b) ℐ), ?ℐ'::(?'c, ?'d) ℐ ⊢⇩C ?conv::(?'a, ?'b, ?'c, ?'d) converter √; ?ℐ', ?ℐ''::(?'e, ?'f) ℐ ⊢⇩C ?conv'::(?'c, ?'d, ?'e, ?'f) converter √⟧ ⟹ ?ℐ, ?ℐ'' ⊢⇩C ?conv ⊙ ?conv' √› and more 29 facts*)) (*proven 2 subgoals*) (*proven 2 subgoals*) . qed theorem constructive_security_obsf'_trivial: fixes res assumes [WT_intro]: "⋀η. ℐ η ⊕⇩ℐ ℐ_common η ⊢res res η √" shows "constructive_security_obsf' res res (λ_. 1⇩C) ℐ ℐ ℐ_common 𝒜" proof (rule constructive_security_obsf'I (*‹⟦⋀η::nat. constructive_security_obsf ((?real_resource::nat ⇒ (?'a + ?'b, ?'c + ?'d) resource) η) ((?ideal_resource::nat ⇒ (?'e + ?'b, ?'f + ?'d) resource) η) ((?sim::nat ⇒ (?'a, ?'c, ?'e, ?'f) converter) η) ((?ℐ_real::nat ⇒ (?'a, ?'c) ℐ) η) ((?ℐ_ideal::nat ⇒ (?'e, ?'f) ℐ) η) ((?ℐ_common::nat ⇒ (?'b, ?'d) ℐ) η) ((?𝒜::nat ⇒ (?'a + ?'b, ?'c + ?'d) distinguisher_obsf) η) ((?adv::nat ⇒ real) η); (⋀η::nat. exception_ℐ (?ℐ_real η ⊕⇩ℐ ?ℐ_common η) ⊢g ?𝒜 η √) ⟹ Negligible.negligible ?adv⟧ ⟹ constructive_security_obsf' ?real_resource ?ideal_resource ?sim ?ℐ_real ?ℐ_ideal ?ℐ_common ?𝒜›*)) (*goals: 1. ‹⋀η::nat. constructive_security_obsf ((res::nat ⇒ ('a + 'b, 'c + 'd) resource) η) (res η) 1⇩C ((ℐ::nat ⇒ ('a, 'c) ℐ) η) (ℐ η) ((ℐ_common::nat ⇒ ('b, 'd) ℐ) η) ((𝒜::nat ⇒ ('a + 'b, 'c + 'd) distinguisher_obsf) η) ((?adv::nat ⇒ real) η)› 2. ‹(⋀η::nat. exception_ℐ ((ℐ::nat ⇒ ('a, 'c) ℐ) η ⊕⇩ℐ (ℐ_common::nat ⇒ ('b, 'd) ℐ) η) ⊢g (𝒜::nat ⇒ ('a + 'b, 'c + 'd) distinguisher_obsf) η √) ⟹ Negligible.negligible (?adv::nat ⇒ real)›*) show "constructive_security_obsf (res η) (res η) 1⇩C (ℐ η) (ℐ η) (ℐ_common η) (𝒜 η) 0" for η using assms (*‹(ℐ::nat ⇒ ('a, 'c) ℐ) (?η::nat) ⊕⇩ℐ (ℐ_common::nat ⇒ ('b, 'd) ℐ) ?η ⊢res (res::nat ⇒ ('a + 'b, 'c + 'd) resource) ?η √›*) by (rule constructive_security_obsf_trivial (*‹?ℐ ⊕⇩ℐ ?ℐ_common ⊢res ?res √ ⟹ constructive_security_obsf ?res ?res 1⇩C ?ℐ ?ℐ ?ℐ_common ?𝒜 0›*)) qed (simp) (*solved the remaining goal: ‹(⋀η. exception_ℐ (ℐ η ⊕⇩ℐ ℐ_common η) ⊢g 𝒜 η √) ⟹ Negligible.negligible (λη. 0)›*) theorem parallel_constructive_security_obsf': assumes "constructive_security_obsf' real1 ideal1 sim1 ℐ_real1 ℐ_inner1 ℐ_common1 (λη. absorb (𝒜 η) (obsf_converter (parallel_wiring ⊙ parallel_converter 1⇩C (converter_of_resource (sim2 η |₌ 1⇩C ⊳ ideal2 η)))))" (is "constructive_security_obsf' _ _ _ _ _ _ ?𝒜1") assumes "constructive_security_obsf' real2 ideal2 sim2 ℐ_real2 ℐ_inner2 ℐ_common2 (λη. absorb (𝒜 η) (obsf_converter (parallel_wiring ⊙ parallel_converter (converter_of_resource (real1 η)) 1⇩C)))" (is "constructive_security_obsf' _ _ _ _ _ _ ?𝒜2") shows "constructive_security_obsf' (λη. parallel_wiring ⊳ real1 η ∥ real2 η) (λη. parallel_wiring ⊳ ideal1 η ∥ ideal2 η) (λη. sim1 η |₌ sim2 η) (λη. ℐ_real1 η ⊕⇩ℐ ℐ_real2 η) (λη. ℐ_inner1 η ⊕⇩ℐ ℐ_inner2 η) (λη. ℐ_common1 η ⊕⇩ℐ ℐ_common2 η) 𝒜" proof(rule constructive_security_obsf'I) interpret sec1: constructive_security_obsf' real1 ideal1 sim1 ℐ_real1 ℐ_inner1 ℐ_common1 ?𝒜1 by fact interpret sec2: constructive_security_obsf' real2 ideal2 sim2 ℐ_real2 ℐ_inner2 ℐ_common2 ?𝒜2 by fact let ?adv1 = "λη. advantage (?𝒜1 η) (obsf_resource (sim1 η |₌ 1⇩C ⊳ ideal1 η)) (obsf_resource (real1 η))" let ?adv2 = "λη. advantage (?𝒜2 η) (obsf_resource (sim2 η |₌ 1⇩C ⊳ ideal2 η)) (obsf_resource (real2 η))" let ?adv = "λη. ?adv1 η + ?adv2 η" show "constructive_security_obsf (parallel_wiring ⊳ real1 η ∥ real2 η) (parallel_wiring ⊳ ideal1 η ∥ ideal2 η) (sim1 η |₌ sim2 η) (ℐ_real1 η ⊕⇩ℐ ℐ_real2 η) (ℐ_inner1 η ⊕⇩ℐ ℐ_inner2 η) (ℐ_common1 η ⊕⇩ℐ ℐ_common2 η) (𝒜 η) (?adv η)" for η using sec1.constructive_security_obsf'D sec2.constructive_security_obsf'D by(rule parallel_constructive_security_obsf) assume [WT_intro]: "exception_ℐ ((ℐ_real1 η ⊕⇩ℐ ℐ_real2 η) ⊕⇩ℐ (ℐ_common1 η ⊕⇩ℐ ℐ_common2 η)) ⊢g 𝒜 η √" for η have "negligible ?adv1" by(rule sec1.adv)(rule WT_intro)+ also have "negligible ?adv2" by(rule sec2.adv)(rule WT_intro)+ finally (negligible_plus) show "negligible ?adv" . qed end
{ "path": "afp-2025-02-12/thys/Constructive_Cryptography_CM/Asymptotic_Security.thy", "repo": "afp-2025-02-12", "sha": "d32f51650a6f0614b8e853a16727afa8c9b8983586cdf1b6ef594b3a1b53c401" }
(* Title: More_Manifolds Author: Richard Schmoetten <richard.schmoetten@ed.ac.uk>, 2024 Maintainer: Richard Schmoetten <richard.schmoetten@ed.ac.uk> *) section ‹Results about Manifolds and Analysis.› theory More_Manifolds imports Types_To_Sets_Extension.VS_Modules Smooth_Manifolds.Tangent_Space Smooth_Manifolds.Product_Manifold Groups_On_With begin text ‹Contains results not just about manifolds, but also supporting results about other parts of the standard Isabelle distribution/AFP.› subsection ‹General and Miscellaneous› lemma bij_betw_if_inverse: assumes "bij_betw f A B" and "⋀x. x∈A ⟹ f' (f x) = x" and "⋀y. y∈B ⟹ f (f' y) = y" shows "bij_betw f' B A" by (smt (verit, ccfv_SIG) assms (*‹bij_betw f A B› ‹?x ∈ A ⟹ f' (f ?x) = ?x› ‹?y ∈ B ⟹ f (f' ?y) = ?y›*) bij_betwE (*‹bij_betw ?f ?A ?B ⟹ ∀a∈?A. ?f a ∈ ?B›*) bij_betw_cong (*‹(⋀a. a ∈ ?A ⟹ ?f a = ?g a) ⟹ bij_betw ?f ?A ?A' = bij_betw ?g ?A ?A'›*) bij_betw_the_inv_into (*‹bij_betw ?f ?A ?B ⟹ bij_betw (the_inv_into ?A ?f) ?B ?A›*) f_the_inv_into_f_bij_betw (*‹⟦bij_betw ?f ?A ?B; bij_betw ?f ?A ?B ⟹ ?x ∈ ?B⟧ ⟹ ?f (the_inv_into ?A ?f ?x) = ?x›*))<close> lemma the_inv_into_f_f_bij_betw: "bij_betw f A B ⟹ (bij_betw f A B ⟹ x ∈ A) ⟹ the_inv_into A f (f x) = x" unfolding bij_betw_def (*goal: ‹⟦inj_on f A ∧ f ` A = B; inj_on f A ∧ f ` A = B ⟹ x ∈ A⟧ ⟹ the_inv_into A f (f x) = x›*) by (blast intro: the_inv_into_f_f (*‹⟦inj_on ?f ?A; ?x ∈ ?A⟧ ⟹ the_inv_into ?A ?f (?f ?x) = ?x›*)) lemma has_derivativeD: assumes "(f has_derivative f') (at x within s)" shows "bounded_linear f'" and "((λy. ((f y - f x) - f' (y - x)) /⇩R norm (y - x)) ⤏ 0) (at x within s)" using assms (*‹((f::'a::real_normed_vector ⇒ 'b::real_normed_vector) has_derivative (f'::'a::real_normed_vector ⇒ 'b::real_normed_vector)) (at (x::'a::real_normed_vector) within (s::'a::real_normed_vector set))›*) has_derivative_at_within (*‹(?f has_derivative ?f') (at ?x within ?s) = (bounded_linear ?f' ∧ ((λy. (?f y - ?f ?x - ?f' (y - ?x)) /⇩R norm (y - ?x)) ⤏ 0) (at ?x within ?s))›*) apply - (*goals: 1. ‹⟦(f has_derivative f') (at x within s); ⋀f f' x s. (f has_derivative f') (at x within s) = (bounded_linear f' ∧ ((λy. (f y - f x - f' (y - x)) /⇩R norm (y - x)) ⤏ 0) (at x within s))⟧ ⟹ bounded_linear f'› 2. ‹⟦(f has_derivative f') (at x within s); ⋀f f' x s. (f has_derivative f') (at x within s) = (bounded_linear f' ∧ ((λy. (f y - f x - f' (y - x)) /⇩R norm (y - x)) ⤏ 0) (at x within s))⟧ ⟹ ((λy. (f y - f x - f' (y - x)) /⇩R norm (y - x)) ⤏ 0) (at x within s)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma homeomorphism_imp_open_map': assumes hom: "homeomorphism S T f g" and U: "open U" "U ⊆ S" and T: "open T" shows "open (f ` U)" proof (-) (*goal: ‹open ((f::'a ⇒ 'b) ` (U::'a set))›*) have "openin (top_of_set T) (f`U)" by (simp add: open_subset (*‹⟦?S ⊆ ?T; open ?S⟧ ⟹ openin (top_of_set ?T) ?S›*) homeomorphism_imp_open_map[OF hom] (*‹openin (top_of_set S) ?U ⟹ openin (top_of_set T) (f ` ?U)›*) U (*‹open U› ‹U ⊆ S›*)) thus "?thesis" (*goal: ‹open ((f::'a ⇒ 'b) ` (U::'a set))›*) by (simp add: T (*‹open T›*) openin_open_eq (*‹open ?s ⟹ openin (top_of_set ?s) ?t = (open ?t ∧ ?t ⊆ ?s)›*)) qed lemma homeo_imp_bij: assumes "homeomorphism a b f f'" shows "bij_betw f a b" by (metis assms (*‹homeomorphism (a::'a set) (b::'b set) (f::'a ⇒ 'b) (f'::'b ⇒ 'a)›*) bij_betw_def (*‹bij_betw (?f::?'a ⇒ ?'b) (?A::?'a set) (?B::?'b set) = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*) homeomorphism_apply1 (*‹⟦homeomorphism (?S::?'a set) (?T::?'b set) (?f::?'a ⇒ ?'b) (?g::?'b ⇒ ?'a); (?x::?'a) ∈ ?S⟧ ⟹ ?g (?f ?x) = ?x›*) homeomorphism_image1 (*‹homeomorphism (?S::?'a set) (?T::?'b set) (?f::?'a ⇒ ?'b) (?g::?'b ⇒ ?'a) ⟹ ?f ` ?S = ?T›*) inj_onI (*‹(⋀(x::?'a) y::?'a. ⟦x ∈ (?A::?'a set); y ∈ ?A; (?f::?'a ⇒ ?'b) x = ?f y⟧ ⟹ x = y) ⟹ inj_on ?f ?A›*)) lemma smooth_on_cong': assumes "k-smooth_on T f" "S=T" shows "k-smooth_on S f" by (simp add: assms (*‹k-smooth_on T f› ‹S = T›*)) lemma ran_the_im_dom: "ran f = the ` (f ` dom f)" unfolding ran_def dom_def image_def (*goal: ‹{b. ∃a. f a = Some b} = {y. ∃x∈{y. ∃x∈{a. f a ≠ None}. y = f x}. y = the x}›*) by force lemma map_comp_assoc: "(h∘⇩mg)∘⇩mf = h∘⇩m(g∘⇩mf)" for f g h proof (standard) (*goal: ‹⋀x::'a. ((h::'d ⇒ 'b option) ∘⇩m (g::'c ⇒ 'd option) ∘⇩m (f::'a ⇒ 'c option)) x = (h ∘⇩m (g ∘⇩m f)) x›*) fix x consider (x_in)"x∈dom f" | (x_out)"x∉dom f" (*goal: ‹⟦x ∈ dom f ⟹ thesis; x ∉ dom f ⟹ thesis⟧ ⟹ thesis›*) by blast then show "(h ∘⇩m g ∘⇩m f) x = (h ∘⇩m (g ∘⇩m f)) x" apply cases (*goals: 1. ‹(x::'a) ∈ dom (f::'a ⇒ 'c option) ⟹ ((h::'d ⇒ 'b option) ∘⇩m (g::'c ⇒ 'd option) ∘⇩m f) x = (h ∘⇩m (g ∘⇩m f)) x› 2. ‹(x::'a) ∉ dom (f::'a ⇒ 'c option) ⟹ ((h::'d ⇒ 'b option) ∘⇩m (g::'c ⇒ 'd option) ∘⇩m f) x = (h ∘⇩m (g ∘⇩m f)) x› discuss goal 1*) apply (smt (verit, ccfv_threshold) map_comp_simps (*‹?m2.0 ?k = None ⟹ (?m1.0 ∘⇩m ?m2.0) ?k = None› ‹?m2.0 ?k = Some ?k' ⟹ (?m1.0 ∘⇩m ?m2.0) ?k = ?m1.0 ?k'›*) option.exhaust (*‹⟦?y = None ⟹ ?P; ⋀x2. ?y = Some x2 ⟹ ?P⟧ ⟹ ?P›*)) (*discuss goal 2*) apply (simp add: domIff (*‹(?a ∈ dom ?m) = (?m ?a ≠ None)›*)) (*proven 2 subgoals*) . qed lemma map_comp_dom: "dom (g∘⇩mf) = dom f" if "ran f ⊆ dom g" for f and g using ranI (*‹(?m::?'b::type ⇒ ?'a::type option) (?a::?'b::type) = Some (?b::?'a::type) ⟹ ?b ∈ ran ?m›*) subset_iff' (*‹(?A ⊆ ?B) = (∀t∈?A. t ∈ ?B)›*) that (*‹ran f ⊆ dom g›*) by fastforce text ‹It would be much nicer if instead of \<^term>‹f ∈ manifold_eucl.diff_fun_space k›, we could just state that \<^term>‹f› is differentiable at \<^term>‹p›. However, (one of) the difference between \<^term>‹directional_derivative› and \<^term>‹frechet_derivative› is that the former returns 0 whenever the argument function is non-zero anywhere outside the carrier. It is therefore not a local operation: two functions that differ only at a point far away may still have different \<^term>‹directional_derivative›s.› lemma directional_derivative_cong: assumes "open U" "p∈U" "∀x∈U. f x = g x" "k≠0" "f ∈ manifold_eucl.diff_fun_space k" "g ∈ manifold_eucl.diff_fun_space k" shows "directional_derivative k p v f = directional_derivative k p v g" using assms(5,6) (*‹f ∈ manifold_eucl.diff_fun_space k› ‹g ∈ manifold_eucl.diff_fun_space k›*) apply (simp add: directional_derivative_def (*‹directional_derivative ?k ?a ?v = restrict0 (manifold_eucl.diff_fun_space ?k) (λf. frechet_derivative f (at ?a) ?v)›*)) (*goal: ‹directional_derivative k p v f = directional_derivative k p v g›*) apply (intro frechet_derivative_transform_within_open_ext[OF _ assms(1,2)] (*‹⟦?f differentiable at p; ⋀x. x ∈ U ⟹ ?f x = ?g x⟧ ⟹ frechet_derivative ?f (at p) ?x = frechet_derivative ?g (at p) ?x›*)) (*goal: ‹⟦k-smooth_on UNIV f; k-smooth_on UNIV g⟧ ⟹ frechet_derivative f (at p) v = frechet_derivative g (at p) v›*) using differentiable_onD (*‹⟦?f differentiable_on ?S; ?x ∈ ?S⟧ ⟹ ?f differentiable at ?x within ?S›*) assms(3-6) (*‹∀x∈U. f x = g x› ‹k ≠ 0› ‹f ∈ manifold_eucl.diff_fun_space k› ‹g ∈ manifold_eucl.diff_fun_space k›*) Smooth.smooth_on_imp_differentiable_on (*‹⟦(?k::enat)-smooth_on (?S::?'a set) (?f::?'a ⇒ ?'b); ?k ≠ (0::enat)⟧ ⟹ ?f differentiable_on ?S›*) apply - (*goals: 1. ‹⟦k-smooth_on UNIV f; k-smooth_on UNIV g; ⋀f S x. ⟦f differentiable_on S; x ∈ S⟧ ⟹ f differentiable at x within S; ∀x∈U. f x = g x; k ≠ 0; f ∈ manifold_eucl.diff_fun_space k; g ∈ manifold_eucl.diff_fun_space k; ⋀k S f. ⟦k-smooth_on S f; k ≠ 0⟧ ⟹ f differentiable_on S⟧ ⟹ f differentiable at p› 2. ‹⋀x. ⟦k-smooth_on UNIV f; k-smooth_on UNIV g; x ∈ U; ⋀f S x. ⟦f differentiable_on S; x ∈ S⟧ ⟹ f differentiable at x within S; ∀x∈U. f x = g x; k ≠ 0; f ∈ manifold_eucl.diff_fun_space k; g ∈ manifold_eucl.diff_fun_space k; ⋀k S f. ⟦k-smooth_on S f; k ≠ 0⟧ ⟹ f differentiable_on S⟧ ⟹ f x = g x› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) . lemma inverse_bij_betw: assumes f: "bij_betw f A B" and g: "∀x∈A. g (f x) = x" "∀y∈B. f (g y) = y" shows "bij_betw g B A" unfolding bij_betw_def inj_on_def (*goal: ‹(∀x∈B. ∀y∈B. g x = g y ⟶ x = y) ∧ g ` B = A›*) apply (intro conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goal: ‹(∀x::'b∈B::'b set. ∀y::'b∈B. (g::'b ⇒ 'a) x = g y ⟶ x = y) ∧ g ` B = (A::'a set)›*) apply (metis g( (*‹∀y∈B. f (g y) = y›*) 2)) (*top goal: ‹∀x::'b::type∈B::'b::type set. ∀y::'b::type∈B. (g::'b::type ⇒ 'a::type) x = g y ⟶ x = y› and 1 goal remains*) using f (*‹bij_betw (f::'a ⇒ 'b) (A::'a set) (B::'b set)›*) g(1) (*‹∀x∈A. g (f x) = x›*) by (simp add: bij_betw_if_inverse (*‹⟦bij_betw ?f ?A ?B; ⋀x. x ∈ ?A ⟹ ?f' (?f x) = x; ⋀y. y ∈ ?B ⟹ ?f (?f' y) = y⟧ ⟹ bij_betw ?f' ?B ?A›*) bij_betw_imp_surj_on (*‹bij_betw ?f ?A ?B ⟹ ?f ` ?A = ?B›*) g( (*‹∀y∈B. f (g y) = y›*) 2)) lemma linear_on_inv: assumes lin: "linear_on A B scaleA scaleB a" and bij: "bij_betw a A B" and inv: "(∀x ∈ A. a x ∈ B ∧ b(a x) = x)" "(∀y ∈ B. b y ∈ A ∧ a(b y) = y)" shows "linear_on B A scaleB scaleA b" proof (-) (*goal: ‹linear_on B A scaleB scaleA b›*) interpret l: linear_on A B scaleA scaleB a using lin (*‹linear_on A B scaleA scaleB a›*) . show "linear_on B A scaleB scaleA b" apply unfold_locales (*goal: ‹linear_on B A scaleB scaleA b›*) using bij (*‹bij_betw (a::'a ⇒ 'b) (A::'a set) (B::'b set)›*) inv (*‹∀x∈A. a x ∈ B ∧ b (a x) = x› ‹∀y∈B. b y ∈ A ∧ a (b y) = y›*) l.add (*‹⟦(?b1.0::'a) ∈ (A::'a set); (?b2.0::'a) ∈ A⟧ ⟹ (a::'a ⇒ 'b) (?b1.0 + ?b2.0) = a ?b1.0 + a ?b2.0›*) l.m1.mem_add (*‹⟦?x ∈ A; ?y ∈ A⟧ ⟹ ?x + ?y ∈ A›*) l.m1.mem_scale (*‹?x ∈ A ⟹ scaleA ?a ?x ∈ A›*) l.scale (*‹(?b::'a::ab_group_add) ∈ (A::'a::ab_group_add set) ⟹ (a::'a::ab_group_add ⇒ 'b::ab_group_add) ((scaleA::'c::field ⇒ 'a::ab_group_add ⇒ 'a::ab_group_add) (?r::'c::field) ?b) = (scaleB::'c::field ⇒ 'b::ab_group_add ⇒ 'b::ab_group_add) ?r (a ?b)›*) apply - (*goals: 1. ‹⋀(b1::'b) b2::'b. ⟦b1 ∈ (B::'b set); b2 ∈ B; bij_betw (a::'a ⇒ 'b) (A::'a set) B; ∀x::'a∈A. a x ∈ B ∧ (b::'b ⇒ 'a) (a x) = x; ∀y::'b∈B. b y ∈ A ∧ a (b y) = y; ⋀(b1::'a) b2::'a. ⟦b1 ∈ A; b2 ∈ A⟧ ⟹ a (b1 + b2) = a b1 + a b2; ⋀(x::'a) y::'a. ⟦x ∈ A; y ∈ A⟧ ⟹ x + y ∈ A; ⋀(x::'a) a::'c. x ∈ A ⟹ (scaleA::'c ⇒ 'a ⇒ 'a) a x ∈ A; ⋀(b::'a) r::'c. b ∈ A ⟹ a (scaleA r b) = (scaleB::'c ⇒ 'b ⇒ 'b) r (a b)⟧ ⟹ b (b1 + b2) = b b1 + b b2› 2. ‹⋀(r::'c) ba::'b. ⟦ba ∈ (B::'b set); bij_betw (a::'a ⇒ 'b) (A::'a set) B; ∀x::'a∈A. a x ∈ B ∧ (b::'b ⇒ 'a) (a x) = x; ∀y::'b∈B. b y ∈ A ∧ a (b y) = y; ⋀(b1::'a) b2::'a. ⟦b1 ∈ A; b2 ∈ A⟧ ⟹ a (b1 + b2) = a b1 + a b2; ⋀(x::'a) y::'a. ⟦x ∈ A; y ∈ A⟧ ⟹ x + y ∈ A; ⋀(x::'a) a::'c. x ∈ A ⟹ (scaleA::'c ⇒ 'a ⇒ 'a) a x ∈ A; ⋀(b::'a) r::'c. b ∈ A ⟹ a (scaleA r b) = (scaleB::'c ⇒ 'b ⇒ 'b) r (a b)⟧ ⟹ b (scaleB r ba) = scaleA r (b ba)› discuss goal 1*) apply metis (*discuss goal 2*) apply metis (*proven 2 subgoals*) . qed lemma linear_on_the_inv_into: assumes "linear_on A B scaleA scaleB a" and "bij_betw a A B" shows "linear_on B A scaleB scaleA (the_inv_into A a)" using linear_on_inv (*‹⟦linear_on (?A::?'a set) (?B::?'b set) (?scaleA::?'c ⇒ ?'a ⇒ ?'a) (?scaleB::?'c ⇒ ?'b ⇒ ?'b) (?a::?'a ⇒ ?'b); bij_betw ?a ?A ?B; ∀x::?'a∈?A. ?a x ∈ ?B ∧ (?b::?'b ⇒ ?'a) (?a x) = x; ∀y::?'b∈?B. ?b y ∈ ?A ∧ ?a (?b y) = y⟧ ⟹ linear_on ?B ?A ?scaleB ?scaleA ?b›*) assms (*‹linear_on A B scaleA scaleB a› ‹bij_betw a A B›*) f_the_inv_into_f_bij_betw (*‹⟦bij_betw (?f::?'a::type ⇒ ?'b::type) (?A::?'a::type set) (?B::?'b::type set); bij_betw ?f ?A ?B ⟹ (?x::?'b::type) ∈ ?B⟧ ⟹ ?f (the_inv_into ?A ?f ?x) = ?x›*) the_inv_into_f_eq (*‹⟦inj_on ?f ?A; ?f ?x = ?y; ?x ∈ ?A⟧ ⟹ the_inv_into ?A ?f ?y = ?x›*) the_inv_into_onto (*‹inj_on ?f ?A ⟹ the_inv_into ?A ?f ` ?f ` ?A = ?A›*) bij_betw_iff_bijections (*‹bij_betw ?f ?A ?B = (∃g. (∀x∈?A. ?f x ∈ ?B ∧ g (?f x) = x) ∧ (∀y∈?B. g y ∈ ?A ∧ ?f (g y) = y))›*) bij_betw_the_inv_into (*‹bij_betw ?f ?A ?B ⟹ bij_betw (the_inv_into ?A ?f) ?B ?A›*) by (smt (verit, best)) lemma linear_on_image: assumes "linear_on A B scaleA scaleB a" and "a`A⊆B" shows "linear_on A (a`A) scaleA scaleB a" proof (-) (*goal: ‹linear_on A (a ` A) scaleA scaleB a›*) interpret l: linear_on A B scaleA scaleB a using assms(1) (*‹linear_on A B scaleA scaleB a›*) . show "?thesis" (*goal: ‹linear_on A (a ` A) scaleA scaleB a›*) apply unfold_locales (*goal: ‹linear_on A (a ` A) scaleA scaleB a›*) subgoal for by (meson assms( (*‹a ` A ⊆ B›*) 2) in_mono (*‹?A ⊆ ?B ⟹ ?x ∈ ?A ⟶ ?x ∈ ?B›*) l.m2.scale_right_distrib_on (*‹⟦?x ∈ B; ?y ∈ B⟧ ⟹ scaleB ?a (?x + ?y) = scaleB ?a ?x + scaleB ?a ?y›*)) using assms(2) (*‹a ` A ⊆ B›*) l.m2.scale_left_distrib_on (*‹?x ∈ B ⟹ scaleB (?a + ?b) ?x = scaleB ?a ?x + scaleB ?b ?x›*) apply ((auto)[3]) (*top goal: ‹⋀x aa b. x ∈ a ` A ⟹ scaleB (aa + b) x = scaleB aa x + scaleB b x› and 7 goals remain*) subgoal for using l.add (*‹⟦?b1.0 ∈ A; ?b2.0 ∈ A⟧ ⟹ a (?b1.0 + ?b2.0) = a ?b1.0 + a ?b2.0›*) l.m1.mem_add (*‹⟦?x ∈ A; ?y ∈ A⟧ ⟹ ?x + ?y ∈ A›*) by force subgoal for using l.add (*‹⟦?b1.0 ∈ A; ?b2.0 ∈ A⟧ ⟹ a (?b1.0 + ?b2.0) = a ?b1.0 + a ?b2.0›*) l.m1.mem_zero (*‹(0::'a::ab_group_add) ∈ (A::'a::ab_group_add set)›*) by force subgoal for by (metis (no_types, lifting) image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*) l.m1.mem_scale (*‹?x ∈ A ⟹ scaleA ?a ?x ∈ A›*) l.scale (*‹?b ∈ A ⟹ a (scaleA ?r ?b) = scaleB ?r (a ?b)›*)) subgoal for by (simp add: l.add (*‹⟦?b1.0 ∈ A; ?b2.0 ∈ A⟧ ⟹ a (?b1.0 + ?b2.0) = a ?b1.0 + a ?b2.0›*)) subgoal for by (simp add: l.scale (*‹?b ∈ A ⟹ a (scaleA ?r ?b) = scaleB ?r (a ?b)›*)) . qed lemma linear_on_the_inv_into': assumes "linear_on A B scaleA scaleB a" and "inj_on a A" "a`A⊆B" shows "linear_on (a`A) A scaleB scaleA (the_inv_into A a)" using linear_on_the_inv_into[OF linear_on_image [ OF assms ( 1 , 3 ) ]] (*‹bij_betw (a::'a ⇒ 'b) (A::'a set) (a ` A) ⟹ linear_on (a ` A) A (scaleB::'c ⇒ 'b ⇒ 'b) (scaleA::'c ⇒ 'a ⇒ 'a) (the_inv_into A a)›*) assms(2) (*‹inj_on a A›*) by (simp add: bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*)) lemma module_hom_on_compose: assumes "module_hom_on S1 S2 s1 s2 f" "module_hom_on S2 S3 s2 s3 g" "f ` S1 ⊆ S2" shows "module_hom_on S1 S3 s1 s3 (g o f)" proof (-) (*goal: ‹Linear_Algebra_On.module_hom_on S1 S3 s1 s3 (g ∘ f)›*) interpret f: module_hom_on S1 S2 s1 s2 f using assms(1) (*‹Linear_Algebra_On.module_hom_on S1 S2 s1 s2 f›*) . interpret g: module_hom_on S2 S3 s2 s3 g using assms(2) (*‹Linear_Algebra_On.module_hom_on S2 S3 s2 s3 g›*) . show "module_hom_on S1 S3 s1 s3 (g o f)" apply unfold_locales (*goal: ‹Linear_Algebra_On.module_hom_on S1 S3 s1 s3 (g ∘ f)›*) subgoal for using f.add (*‹⟦(?b1.0::'a) ∈ (S1::'a set); (?b2.0::'a) ∈ S1⟧ ⟹ (f::'a ⇒ 'b) (?b1.0 + ?b2.0) = f ?b1.0 + f ?b2.0›*) g.add (*‹⟦(?b1.0::'b::ab_group_add) ∈ (S2::'b::ab_group_add set); (?b2.0::'b::ab_group_add) ∈ S2⟧ ⟹ (g::'b::ab_group_add ⇒ 'd::ab_group_add) (?b1.0 + ?b2.0) = g ?b1.0 + g ?b2.0›*) assms(3) (*‹f ` S1 ⊆ S2›*) by fastforce subgoal for using f.scale (*‹?b ∈ S1 ⟹ f (s1 ?r ?b) = s2 ?r (f ?b)›*) g.scale (*‹?b ∈ S2 ⟹ g (s2 ?r ?b) = s3 ?r (g ?b)›*) assms(3) (*‹(f::'a ⇒ 'b) ` (S1::'a set) ⊆ (S2::'b set)›*) by fastforce . qed lemma linear_on_compose: assumes "linear_on S1 S2 s1 s2 f" "linear_on S2 S3 s2 s3 g" "f ` S1 ⊆ S2" shows "linear_on S1 S3 s1 s3 (g o f)" using module_hom_on_compose (*‹⟦Linear_Algebra_On.module_hom_on (?S1.0::?'a::ab_group_add set) (?S2.0::?'b::ab_group_add set) (?s1.0::?'c::comm_ring_1 ⇒ ?'a::ab_group_add ⇒ ?'a::ab_group_add) (?s2.0::?'c::comm_ring_1 ⇒ ?'b::ab_group_add ⇒ ?'b::ab_group_add) (?f::?'a::ab_group_add ⇒ ?'b::ab_group_add); Linear_Algebra_On.module_hom_on ?S2.0 (?S3.0::?'d::ab_group_add set) ?s2.0 (?s3.0::?'c::comm_ring_1 ⇒ ?'d::ab_group_add ⇒ ?'d::ab_group_add) (?g::?'b::ab_group_add ⇒ ?'d::ab_group_add); ?f ` ?S1.0 ⊆ ?S2.0⟧ ⟹ Linear_Algebra_On.module_hom_on ?S1.0 ?S3.0 ?s1.0 ?s3.0 (?g ∘ ?f)›*) assms (*‹linear_on (S1::'a set) (S2::'b set) (s1::'c ⇒ 'a ⇒ 'a) (s2::'c ⇒ 'b ⇒ 'b) (f::'a ⇒ 'b)› ‹linear_on S2 S3 s2 s3 g› ‹f ` S1 ⊆ S2›*) by (simp add: linear_on_def (*‹linear_on ?S1.0 ?S2.0 ?s1.0 ?s2.0 ?f ≡ Linear_Algebra_On.module_hom_on ?S1.0 ?S2.0 ?s1.0 ?s2.0 ?f›*)) lemma bij_betw_restrict0: assumes "bij_betw f A B" shows "bij_betw (restrict0 A f) A B" unfolding restrict0_def (*goal: ‹bij_betw (λx::'a. if x ∈ (A::'a set) then (f::'a ⇒ 'b) x else (0::'b)) A (B::'b set)›*) by (simp add: assms (*‹bij_betw f A B›*) bij_betw_cong (*‹(⋀a. a ∈ ?A ⟹ ?f a = ?g a) ⟹ bij_betw ?f ?A ?A' = bij_betw ?g ?A ?A'›*)) lemma linear_on_restrict0: assumes "linear_on S1 S2 s1 s2 f" shows "linear_on S1 S2 s1 s2 (restrict0 S1 f)" proof (-) (*goal: ‹linear_on S1 S2 s1 s2 (restrict0 S1 f)›*) interpret f: linear_on S1 S2 s1 s2 f using assms (*‹linear_on S1 S2 s1 s2 f›*) . show "?thesis" (*goal: ‹linear_on S1 S2 s1 s2 (restrict0 S1 f)›*) apply unfold_locales (*goals: 1. ‹⋀b1 b2. ⟦b1 ∈ S1; b2 ∈ S1⟧ ⟹ restrict0 S1 f (b1 + b2) = restrict0 S1 f b1 + restrict0 S1 f b2› 2. ‹⋀r b. b ∈ S1 ⟹ restrict0 S1 f (s1 r b) = s2 r (restrict0 S1 f b)› discuss goal 1*) apply (simp add: restrict0_def (*‹restrict0 ?A ?f ?x = (if ?x ∈ ?A then ?f ?x else 0)›*) f.m1.mem_scale (*‹?x ∈ S1 ⟹ s1 ?a ?x ∈ S1›*) f.scale (*‹?b ∈ S1 ⟹ f (s1 ?r ?b) = s2 ?r (f ?b)›*) f.add (*‹⟦?b1.0 ∈ S1; ?b2.0 ∈ S1⟧ ⟹ f (?b1.0 + ?b2.0) = f ?b1.0 + f ?b2.0›*) f.m1.mem_add (*‹⟦?x ∈ S1; ?y ∈ S1⟧ ⟹ ?x + ?y ∈ S1›*)) (*discuss goal 2*) apply (simp add: restrict0_def (*‹restrict0 ?A ?f ?x = (if ?x ∈ ?A then ?f ?x else 0)›*) f.m1.mem_scale (*‹?x ∈ S1 ⟹ s1 ?a ?x ∈ S1›*) f.scale (*‹?b ∈ S1 ⟹ f (s1 ?r ?b) = s2 ?r (f ?b)›*) f.add (*‹⟦?b1.0 ∈ S1; ?b2.0 ∈ S1⟧ ⟹ f (?b1.0 + ?b2.0) = f ?b1.0 + f ?b2.0›*) f.m1.mem_add (*‹⟦?x ∈ S1; ?y ∈ S1⟧ ⟹ ?x + ?y ∈ S1›*)) (*proven 2 subgoals*) . qed lemma extensional0_subset: assumes "extensional0 B f" "B⊆A" shows "extensional0 A f" using assms (*‹extensional0 B f› ‹(B::'a::type set) ⊆ (A::'a::type set)›*) unfolding extensional0_def (*goal: ‹∀x. x ∉ A ⟶ f x = 0›*) by auto lemma restrict0_subset: "B⊆A ⟹ restrict0 A (restrict0 B f) = restrict0 B f" unfolding restrict0_def (*goal: ‹B ⊆ A ⟹ (λx. if x ∈ A then if x ∈ B then f x else 0 else 0) = (λx. if x ∈ B then f x else 0)›*) by force lemma restrict0_subset': "B⊆A ⟹ extensional0 B f ⟹ restrict0 A f = f" unfolding restrict0_def extensional0_def (*goal: ‹⟦(B::'a::type set) ⊆ (A::'a::type set); ∀x::'a::type. x ∉ B ⟶ (f::'a::type ⇒ 'b::zero) x = (0::'b::zero)⟧ ⟹ (λx::'a::type. if x ∈ A then f x else (0::'b::zero)) = f›*) by force lemma (in linear_on) vector_space_pair_on: "vector_space_pair_on S1 S2 s1 s2" by unfold_locales lemma (in linear_on) linear_0: "f 0 = 0" using add (*‹⟦?b1.0 ∈ S1; ?b2.0 ∈ S1⟧ ⟹ f (?b1.0 + ?b2.0) = f ?b1.0 + f ?b2.0›*) m1.mem_zero (*‹(0::'b) ∈ (S1::'b set)›*) by fastforce lemma (in linear_on) linear_sum: "sum (f ∘ g) A = f (sum g A)" if "g`A⊆S1" "f`S1⊆S2" for g and A using that (*‹g ` A ⊆ S1› ‹f ` S1 ⊆ S2›*) apply (auto intro!: vector_space_pair_on.linear_sum'[OF _ _ _ linear_on_axioms, symmetric] (*‹⟦vector_space_pair_on S1 S2 s1 s2; ∀x. x ∈ S1 ⟶ f x ∈ S2; ∀x. x ∈ ?S ⟶ ?g x ∈ S1⟧ ⟹ (∑a∈?S. f (?g a)) = f (sum ?g ?S)›*)) (*goal: ‹sum (f ∘ g) A = f (sum g A)›*) by unfold_locales lemma (in linear_on) independent: assumes "¬ m1.dependent T" "T ⊆ S1" "inj_on f S1" "f ` S1 ⊆ S2" shows "¬ m2.dependent (f`T)" apply (intro vector_space_pair_on.linear_independent_injective_image[OF vector_space_pair_on _ _ linear_on_axioms] (*‹⟦∀x. x ∈ S1 ⟶ f x ∈ S2; ?s ⊆ S1; ¬ m1.dependent ?s; inj_on f (m1.span ?s)⟧ ⟹ ¬ m2.dependent (f ` ?s)›*)) (*goal: ‹¬ m2.dependent (f ` T)›*) using assms(1,2,4) (*‹¬ m1.dependent T› ‹T ⊆ S1› ‹f ` S1 ⊆ S2›*) inj_on_subset[OF assms ( 3 )] (*‹?B ⊆ S1 ⟹ inj_on f ?B›*) m1.span_minimal (*‹⟦(?Sa::'b set) ⊆ (S1::'b set); (?T::'b set) ⊆ S1; ?Sa ⊆ ?T; m1.subspace ?T⟧ ⟹ m1.span ?Sa ⊆ ?T›*) m1.subspace_UNIV (*‹m1.subspace S1›*) apply - (*goals: 1. ‹⟦¬ m1.dependent T; T ⊆ S1; f ` S1 ⊆ S2; ⋀B. B ⊆ S1 ⟹ inj_on f B; ⋀Sa T. ⟦Sa ⊆ S1; T ⊆ S1; Sa ⊆ T; m1.subspace T⟧ ⟹ m1.span Sa ⊆ T; m1.subspace S1⟧ ⟹ ∀x. x ∈ S1 ⟶ f x ∈ S2› 2. ‹⟦¬ m1.dependent T; T ⊆ S1; f ` S1 ⊆ S2; ⋀B. B ⊆ S1 ⟹ inj_on f B; ⋀Sa T. ⟦Sa ⊆ S1; T ⊆ S1; Sa ⊆ T; m1.subspace T⟧ ⟹ m1.span Sa ⊆ T; m1.subspace S1⟧ ⟹ T ⊆ S1› 3. ‹⟦¬ m1.dependent T; T ⊆ S1; f ` S1 ⊆ S2; ⋀B. B ⊆ S1 ⟹ inj_on f B; ⋀Sa T. ⟦Sa ⊆ S1; T ⊆ S1; Sa ⊆ T; m1.subspace T⟧ ⟹ m1.span Sa ⊆ T; m1.subspace S1⟧ ⟹ ¬ m1.dependent T› 4. ‹⟦¬ m1.dependent T; T ⊆ S1; f ` S1 ⊆ S2; ⋀B. B ⊆ S1 ⟹ inj_on f B; ⋀Sa T. ⟦Sa ⊆ S1; T ⊆ S1; Sa ⊆ T; m1.subspace T⟧ ⟹ m1.span Sa ⊆ T; m1.subspace S1⟧ ⟹ inj_on f (m1.span T)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . lemma (in linear_on) span: assumes "T ⊆ S1" "f ` S1 ⊆ S2" shows "m2.span (f`T) = f`(m1.span T)" apply (intro vector_space_pair_on.linear_span_image[OF vector_space_pair_on _ _ linear_on_axioms] (*‹⟦∀x. x ∈ S1 ⟶ f x ∈ S2; ?S ⊆ S1⟧ ⟹ m2.span (f ` ?S) = f ` m1.span ?S›*)) (*goal: ‹m2.span (f ` T) = f ` m1.span T›*) using assms (*‹T ⊆ S1› ‹f ` S1 ⊆ S2›*) apply - (*goals: 1. ‹⟦T ⊆ S1; f ` S1 ⊆ S2⟧ ⟹ ∀x. x ∈ S1 ⟶ f x ∈ S2› 2. ‹⟦T ⊆ S1; f ` S1 ⊆ S2⟧ ⟹ T ⊆ S1› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma (in linear_on) spanning: assumes "m1.span T = S1" "T ⊆ S1" "f`S1 = S2" shows "m2.span (f`T) = S2" proof (-) (*goal: ‹m2.span (f ` T) = S2›*) have "S2 ⊆ m2.span (f ` T)" apply (intro vector_space_pair_on.linear_spanning_surjective_image[OF vector_space_pair_on _ _ linear_on_axioms] (*‹⟦∀x. x ∈ S1 ⟶ f x ∈ S2; ?S ⊆ S1; S1 ⊆ m1.span ?S; f ` S1 = S2⟧ ⟹ S2 ⊆ m2.span (f ` ?S)›*)) (*goal: ‹S2 ⊆ m2.span (f ` T)›*) using assms(3) (*‹f ` S1 = S2›*) apply - (*goals: 1. ‹(f::'b ⇒ 'c) ` (S1::'b set) = (S2::'c set) ⟹ ∀x::'b. x ∈ S1 ⟶ f x ∈ S2› 2. ‹(f::'b ⇒ 'c) ` (S1::'b set) = (S2::'c set) ⟹ (T::'b set) ⊆ S1› 3. ‹(f::'b ⇒ 'c) ` (S1::'b set) = (S2::'c set) ⟹ S1 ⊆ m1.span (T::'b set)› 4. ‹(f::'b ⇒ 'c) ` (S1::'b set) = (S2::'c set) ⟹ f ` S1 = S2› discuss goal 1*) apply ((auto simp add: assms( (*‹m1.span (T::'b set) = (S1::'b set)› ‹(T::'b set) ⊆ (S1::'b set)›*) 1,2))[1]) (*discuss goal 2*) apply ((auto simp add: assms( (*‹m1.span T = S1› ‹T ⊆ S1›*) 1,2))[1]) (*discuss goal 3*) apply ((auto simp add: assms( (*‹m1.span (T::'b set) = (S1::'b set)› ‹(T::'b set) ⊆ (S1::'b set)›*) 1,2))[1]) (*discuss goal 4*) apply ((auto simp add: assms( (*‹m1.span T = S1› ‹T ⊆ S1›*) 1,2))[1]) (*proven 4 subgoals*) . thus "m2.span (f`T) = S2" by (metis assms( (*‹T ⊆ S1›*) 2) assms( (*‹f ` S1 = S2›*) 3) image_mono (*‹?A ⊆ ?B ⟹ ?f ` ?A ⊆ ?f ` ?B›*) m2.span_minimal (*‹⟦?Sa ⊆ S2; ?T ⊆ S2; ?Sa ⊆ ?T; m2.subspace ?T⟧ ⟹ m2.span ?Sa ⊆ ?T›*) m2.subspace_UNIV (*‹m2.subspace S2›*) set_eq_subset (*‹(?A = ?B) = (?A ⊆ ?B ∧ ?B ⊆ ?A)›*)) qed lemma (in linear_on) linear_on_cong: assumes "⋀x. x∈S1 ⟹ g x = f x" shows "linear_on S1 S2 s1 s2 g" using assms (*‹?x ∈ S1 ⟹ g ?x = f ?x›*) apply unfold_locales (*goals: 1. ‹⋀(b1::'b::ab_group_add) b2::'b::ab_group_add. ⟦⋀x::'b::ab_group_add. x ∈ (S1::'b::ab_group_add set) ⟹ (g::'b::ab_group_add ⇒ 'c::ab_group_add) x = (f::'b::ab_group_add ⇒ 'c::ab_group_add) x; b1 ∈ S1; b2 ∈ S1⟧ ⟹ g (b1 + b2) = g b1 + g b2› 2. ‹⋀(r::'a::field) b::'b::ab_group_add. ⟦⋀x::'b::ab_group_add. x ∈ (S1::'b::ab_group_add set) ⟹ (g::'b::ab_group_add ⇒ 'c::ab_group_add) x = (f::'b::ab_group_add ⇒ 'c::ab_group_add) x; b ∈ S1⟧ ⟹ g ((s1::'a::field ⇒ 'b::ab_group_add ⇒ 'b::ab_group_add) r b) = (s2::'a::field ⇒ 'c::ab_group_add ⇒ 'c::ab_group_add) r (g b)› discuss goal 1*) apply (simp add: add (*‹⟦?b1.0 ∈ S1; ?b2.0 ∈ S1⟧ ⟹ f (?b1.0 + ?b2.0) = f ?b1.0 + f ?b2.0›*) m1.mem_add (*‹⟦?x ∈ S1; ?y ∈ S1⟧ ⟹ ?x + ?y ∈ S1›*) m1.mem_scale (*‹?x ∈ S1 ⟹ s1 ?a ?x ∈ S1›*) scale (*‹?b ∈ S1 ⟹ f (s1 ?r ?b) = s2 ?r (f ?b)›*)) (*discuss goal 2*) apply (simp add: add (*‹⟦?b1.0 ∈ S1; ?b2.0 ∈ S1⟧ ⟹ f (?b1.0 + ?b2.0) = f ?b1.0 + f ?b2.0›*) m1.mem_add (*‹⟦?x ∈ S1; ?y ∈ S1⟧ ⟹ ?x + ?y ∈ S1›*) m1.mem_scale (*‹?x ∈ S1 ⟹ s1 ?a ?x ∈ S1›*) scale (*‹?b ∈ S1 ⟹ f (s1 ?r ?b) = s2 ?r (f ?b)›*)) (*proven 2 subgoals*) .<close> lemma frechet_derivative_linear_on_diff_fun_space: "k ≠ 0 ⟹ manifold_eucl.linear_diff_fun k (λf. frechet_derivative f (at a) x)" using directional_derivative_eq_frechet_derivative (*‹?k-smooth_on UNIV ?f ⟹ directional_derivative ?k ?a ?v ?f = frechet_derivative ?f (at ?a) ?v›*) directional_derivative_linear_on_diff_fun_space (*‹?k ≠ 0 ⟹ linear_on (manifold_eucl.diff_fun_space ?k) UNIV (*⇩R) (*⇩R) (directional_derivative ?k ?a ?x)›*) by (metis (no_types, lifting) linear_on.linear_on_cong (*‹⟦linear_on (?S1.0::?'b set) (?S2.0::?'c set) (?s1.0::?'a ⇒ ?'b ⇒ ?'b) (?s2.0::?'a ⇒ ?'c ⇒ ?'c) (?f::?'b ⇒ ?'c); ⋀x::?'b. x ∈ ?S1.0 ⟹ (?g::?'b ⇒ ?'c) x = ?f x⟧ ⟹ linear_on ?S1.0 ?S2.0 ?s1.0 ?s2.0 ?g›*) manifold_eucl.manifold_eucl_diff_fun_space_iff (*‹((?g::?'c ⇒ real) ∈ manifold_eucl.diff_fun_space (?k::enat)) = ?k-smooth_on UNIV ?g›*)) lemma real_vector_space_onI: assumes "vector_space_on S scaleR" shows "real_vector_space_on S" proof (standard) (*goal: ‹subspace S›*) interpret v: vector_space_on S scaleR using assms (*‹vector_space_on S (*⇩R)›*) . show "subspace S" unfolding subspace_def (*goal: ‹0 ∈ S ∧ (∀x∈S. ∀y∈S. x + y ∈ S) ∧ (∀c. ∀x∈S. c *⇩R x ∈ S)›*) by (auto simp add: v.mem_zero (*‹0 ∈ S›*) v.mem_add (*‹⟦?x ∈ S; ?y ∈ S⟧ ⟹ ?x + ?y ∈ S›*) v.mem_scale (*‹?x ∈ S ⟹ ?a *⇩R ?x ∈ S›*)) qed lemma finite_dimensional_real_vector_space_onI: assumes "finite_dimensional_vector_space_on S scaleR B" shows "finite_dimensional_real_vector_space_on S B" proof (standard) (*goals: 1. ‹subspace (S::'a set)› 2. ‹finite (B::'a set)› 3. ‹independent (B::'a set)› 4. ‹span (B::'a set) = (S::'a set)› 5. ‹(B::'a set) ⊆ (S::'a set)›*) interpret v: finite_dimensional_vector_space_on S scaleR B using assms (*‹finite_dimensional_vector_space_on (S::'a set) (*⇩R) (B::'a set)›*) . show "subspace S" unfolding subspace_def (*goal: ‹0 ∈ S ∧ (∀x∈S. ∀y∈S. x + y ∈ S) ∧ (∀c. ∀x∈S. c *⇩R x ∈ S)›*) by (auto simp add: v.mem_zero (*‹0 ∈ S›*) v.mem_add (*‹⟦?x ∈ S; ?y ∈ S⟧ ⟹ ?x + ?y ∈ S›*) v.mem_scale (*‹?x ∈ S ⟹ ?a *⇩R ?x ∈ S›*)) show "finite B" by (simp add: v.finite_Basis (*‹finite (B::'a set)›*)) show "independent B" by (simp add: dependent_with (*‹dependent = dependent_with (+) 0 (*⇩R)›*) v.implicit_dependent_with (*‹dependent_with (+) 0 (*⇩R) = v.dependent›*) v.independent_Basis (*‹¬ v.dependent B›*)) show "B ⊆ S" by (simp add: v.basis_subset (*‹(B::'a::real_vector set) ⊆ (S::'a::real_vector set)›*)) show "span B = S" by (metis ‹subspace S› span_minimal (*‹⟦?S ⊆ ?T; subspace ?T⟧ ⟹ span ?S ⊆ ?T›*) span_subspace (*‹⟦?A ⊆ ?B; ?B ⊆ span ?A; subspace ?B⟧ ⟹ span ?A = ?B›*) span_superset (*‹?S ⊆ span ?S›*) subspace_def (*‹subspace ?S = (0 ∈ ?S ∧ (∀x∈?S. ∀y∈?S. x + y ∈ ?S) ∧ (∀c. ∀x∈?S. c *⇩R x ∈ ?S))›*) subspace_span (*‹subspace (span ?S)›*) v.basis_subset (*‹B ⊆ S›*) v.span_Basis (*‹v.span B = S›*) v.span_minimal (*‹⟦?Sa ⊆ S; ?T ⊆ S; ?Sa ⊆ ?T; v.subspace ?T⟧ ⟹ v.span ?Sa ⊆ ?T›*) v.subspace_on_def (*‹v.subspace ?T = (0 ∈ ?T ∧ (∀x∈?T. ∀y∈?T. x + y ∈ ?T) ∧ (∀c. ∀x∈?T. c *⇩R x ∈ ?T))›*)) qed lemma (in finite_dimensional_real_vector_space_on) basis_transfer: assumes "linear_on S T scaleR scaleR f" "bij_betw f S T" shows "finite_dimensional_real_vector_space_on T (f`basis)" proof (intro finite_dimensional_real_vector_space_onI (*‹finite_dimensional_vector_space_on ?S (*⇩R) ?B ⟹ finite_dimensional_real_vector_space_on ?S ?B›*)) (*goal: ‹finite_dimensional_vector_space_on (T::'b set) (*⇩R) ((f::'a ⇒ 'b) ` (basis::'a set))›*) interpret f: linear_on S T scaleR scaleR f using assms(1) (*‹linear_on (S::'a::real_vector set) (T::'b::real_vector set) (*⇩R) (*⇩R) (f::'a::real_vector ⇒ 'b::real_vector)›*) . show "finite_dimensional_vector_space_on T scaleR (f ` basis)" proof (unfold_locales) (*goals: 1. ‹finite (f ` basis)› 2. ‹¬ f.m2.dependent (f ` basis)› 3. ‹f.m2.span (f ` basis) = T› 4. ‹f ` basis ⊆ T›*) show "finite (f ` basis)" by (simp add: finite_Basis (*‹finite basis›*)) show "f ` basis ⊆ T" using assms(2) (*‹bij_betw f S T›*) basis_subset (*‹basis ⊆ S›*) by (auto simp: bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*)) show "¬ f.m2.dependent (f ` basis)" apply (intro f.independent (*‹⟦¬ Linear_Algebra_On.module_on.dependent (*⇩R) ?T; ?T ⊆ S; inj_on f S; f ` S ⊆ T⟧ ⟹ ¬ f.m2.dependent (f ` ?T)›*)) (*goals: 1. ‹¬ Linear_Algebra_On.module_on.dependent (*⇩R) basis› 2. ‹basis ⊆ S› 3. ‹inj_on f S› 4. ‹f ` S ⊆ T› discuss goal 1*) apply (simp add: independent_Basis (*‹¬ Linear_Algebra_On.module_on.dependent (*⇩R) basis›*) basis_subset (*‹basis ⊆ S›*) assms(2)[unfolded bij_betw_def] (*‹inj_on f S ∧ f ` S = T›*)) (*discuss goal 2*) apply (simp add: independent_Basis (*‹¬ Linear_Algebra_On.module_on.dependent (*⇩R) (basis::'a set)›*) basis_subset (*‹(basis::'a set) ⊆ (S::'a set)›*) assms(2)[unfolded bij_betw_def] (*‹inj_on (f::'a ⇒ 'b) (S::'a set) ∧ f ` S = (T::'b set)›*)) (*discuss goal 3*) apply (simp add: independent_Basis (*‹¬ Linear_Algebra_On.module_on.dependent (*⇩R) (basis::'a::real_vector set)›*) basis_subset (*‹(basis::'a::real_vector set) ⊆ (S::'a::real_vector set)›*) assms(2)[unfolded bij_betw_def] (*‹inj_on (f::'a::real_vector ⇒ 'b::real_vector) (S::'a::real_vector set) ∧ f ` S = (T::'b::real_vector set)›*)) (*discuss goal 4*) apply (simp add: independent_Basis (*‹¬ Linear_Algebra_On.module_on.dependent (*⇩R) basis›*) basis_subset (*‹basis ⊆ S›*) assms(2)[unfolded bij_betw_def] (*‹inj_on f S ∧ f ` S = T›*)) (*proven 4 subgoals*) . show "f.m2.span (f ` basis) = T" apply (intro f.spanning (*‹⟦Linear_Algebra_On.module_on.span (*⇩R) ?T = S; ?T ⊆ S; f ` S = T⟧ ⟹ f.m2.span (f ` ?T) = T›*)) (*goals: 1. ‹Linear_Algebra_On.module_on.span (*⇩R) basis = S› 2. ‹basis ⊆ S› 3. ‹f ` S = T› discuss goal 1*) apply (simp add: span_Basis (*‹Linear_Algebra_On.module_on.span (*⇩R) basis = S›*) basis_subset (*‹basis ⊆ S›*) assms(2)[unfolded bij_betw_def] (*‹inj_on f S ∧ f ` S = T›*)) (*discuss goal 2*) apply (simp add: span_Basis (*‹Linear_Algebra_On.module_on.span (*⇩R) (basis::'a set) = (S::'a set)›*) basis_subset (*‹(basis::'a set) ⊆ (S::'a set)›*) assms(2)[unfolded bij_betw_def] (*‹inj_on (f::'a ⇒ 'b) (S::'a set) ∧ f ` S = (T::'b set)›*)) (*discuss goal 3*) apply (simp add: span_Basis (*‹Linear_Algebra_On.module_on.span (*⇩R) basis = S›*) basis_subset (*‹basis ⊆ S›*) assms(2)[unfolded bij_betw_def] (*‹inj_on f S ∧ f ` S = T›*)) (*proven 3 subgoals*) . qed qed lemma euclidean_components_eq_iff: shows "(∑i∈Basis. f i *⇩R i) = (∑i∈Basis. g i *⇩R i) ⟷ (∀i∈Basis. f i = g i)" apply auto (*goal: ‹((∑i∈Basis. f i *⇩R i) = (∑i∈Basis. g i *⇩R i)) = (∀i∈Basis. f i = g i)›*) by (metis inner_sum_left_Basis (*‹?b ∈ Basis ⟹ (∑i∈Basis. ?f i *⇩R i) ∙ ?b = ?f ?b›*)) lemma (in finite_dimensional_vector_space_on) VS_module_on: "VS_Modules.module_on S scale" apply unfold_locales (*goals: 1. ‹⋀x y a. ⟦x ∈ S; y ∈ S⟧ ⟹ scale a (x + y) = scale a x + scale a y› 2. ‹⋀x a b. x ∈ S ⟹ scale (a + b) x = scale a x + scale b x› 3. ‹⋀x a b. x ∈ S ⟹ scale a (scale b x) = scale (a * b) x› 4. ‹⋀x. x ∈ S ⟹ scale 1 x = x› 5. ‹⋀x y. ⟦x ∈ S; y ∈ S⟧ ⟹ x + y ∈ S› 6. ‹0 ∈ S› 7. ‹⋀x a. x ∈ S ⟹ scale a x ∈ S› discuss goal 1*) apply (simp add: scale_right_distrib_on (*‹⟦?x ∈ S; ?y ∈ S⟧ ⟹ scale ?a (?x + ?y) = scale ?a ?x + scale ?a ?y›*) scale_left_distrib_on (*‹?x ∈ S ⟹ scale (?a + ?b) ?x = scale ?a ?x + scale ?b ?x›*) mem_add (*‹⟦?x ∈ S; ?y ∈ S⟧ ⟹ ?x + ?y ∈ S›*) mem_zero (*‹0 ∈ S›*) mem_scale (*‹?x ∈ S ⟹ scale ?a ?x ∈ S›*)) (*discuss goal 2*) apply (simp add: scale_right_distrib_on (*‹⟦?x ∈ S; ?y ∈ S⟧ ⟹ scale ?a (?x + ?y) = scale ?a ?x + scale ?a ?y›*) scale_left_distrib_on (*‹?x ∈ S ⟹ scale (?a + ?b) ?x = scale ?a ?x + scale ?b ?x›*) mem_add (*‹⟦?x ∈ S; ?y ∈ S⟧ ⟹ ?x + ?y ∈ S›*) mem_zero (*‹0 ∈ S›*) mem_scale (*‹?x ∈ S ⟹ scale ?a ?x ∈ S›*)) (*discuss goal 3*) apply (simp add: scale_right_distrib_on (*‹⟦?x ∈ S; ?y ∈ S⟧ ⟹ scale ?a (?x + ?y) = scale ?a ?x + scale ?a ?y›*) scale_left_distrib_on (*‹?x ∈ S ⟹ scale (?a + ?b) ?x = scale ?a ?x + scale ?b ?x›*) mem_add (*‹⟦?x ∈ S; ?y ∈ S⟧ ⟹ ?x + ?y ∈ S›*) mem_zero (*‹0 ∈ S›*) mem_scale (*‹?x ∈ S ⟹ scale ?a ?x ∈ S›*)) (*discuss goal 4*) apply (simp add: scale_right_distrib_on (*‹⟦?x ∈ S; ?y ∈ S⟧ ⟹ scale ?a (?x + ?y) = scale ?a ?x + scale ?a ?y›*) scale_left_distrib_on (*‹?x ∈ S ⟹ scale (?a + ?b) ?x = scale ?a ?x + scale ?b ?x›*) mem_add (*‹⟦?x ∈ S; ?y ∈ S⟧ ⟹ ?x + ?y ∈ S›*) mem_zero (*‹0 ∈ S›*) mem_scale (*‹?x ∈ S ⟹ scale ?a ?x ∈ S›*)) (*discuss goal 5*) apply (simp add: scale_right_distrib_on (*‹⟦?x ∈ S; ?y ∈ S⟧ ⟹ scale ?a (?x + ?y) = scale ?a ?x + scale ?a ?y›*) scale_left_distrib_on (*‹?x ∈ S ⟹ scale (?a + ?b) ?x = scale ?a ?x + scale ?b ?x›*) mem_add (*‹⟦?x ∈ S; ?y ∈ S⟧ ⟹ ?x + ?y ∈ S›*) mem_zero (*‹0 ∈ S›*) mem_scale (*‹?x ∈ S ⟹ scale ?a ?x ∈ S›*)) (*discuss goal 6*) apply (simp add: scale_right_distrib_on (*‹⟦?x ∈ S; ?y ∈ S⟧ ⟹ scale ?a (?x + ?y) = scale ?a ?x + scale ?a ?y›*) scale_left_distrib_on (*‹?x ∈ S ⟹ scale (?a + ?b) ?x = scale ?a ?x + scale ?b ?x›*) mem_add (*‹⟦?x ∈ S; ?y ∈ S⟧ ⟹ ?x + ?y ∈ S›*) mem_zero (*‹0 ∈ S›*) mem_scale (*‹?x ∈ S ⟹ scale ?a ?x ∈ S›*)) (*discuss goal 7*) apply (simp add: scale_right_distrib_on (*‹⟦?x ∈ S; ?y ∈ S⟧ ⟹ scale ?a (?x + ?y) = scale ?a ?x + scale ?a ?y›*) scale_left_distrib_on (*‹?x ∈ S ⟹ scale (?a + ?b) ?x = scale ?a ?x + scale ?b ?x›*) mem_add (*‹⟦?x ∈ S; ?y ∈ S⟧ ⟹ ?x + ?y ∈ S›*) mem_zero (*‹0 ∈ S›*) mem_scale (*‹?x ∈ S ⟹ scale ?a ?x ∈ S›*)) (*proven 7 subgoals*) .<close> lemma (in finite_dimensional_vector_space_on) unique_representation_basis': assumes "B ⊆ basis" and "⋀v. ⟦v ∈ S; f v ≠ 0⟧ ⟹ v ∈ B" and "⋀v. ⟦v ∈ S; g v ≠ 0⟧ ⟹ v ∈ B" and "(∑v∈{x∈S. f x ≠ 0}. scale (f v) v) = (∑v∈{x∈S. g x ≠ 0}. scale (g v) v)" shows "∀x∈S. f x = g x" proof (-) (*goal: ‹∀x::'a::ab_group_add∈S::'a::ab_group_add set. (f::'a::ab_group_add ⇒ 'b::field) x = (g::'a::ab_group_add ⇒ 'b::field) x›*) interpret ETTS_mod: VS_Modules.module_on S scale using VS_module_on (*‹VS_Modules.module_on S scale›*) . have "¬ ETTS_mod.dependent basis" using ETTS_mod.dependent_explicit (*‹?V ⊆ S ⟹ ETTS_mod.dependent ?V = (∃U⊆S. ∃f. finite U ∧ U ⊆ ?V ∧ (∃v∈U. f v ≠ 0) ∧ (∑v∈U. scale (f v) v) = 0)›*) basis_subset (*‹basis ⊆ S›*) dependent_explicit (*‹(?s::'a set) ⊆ (S::'a set) ⟹ local.dependent ?s = (∃t⊆S. finite t ∧ t ⊆ ?s ∧ (∃u::'a ⇒ 'b. (∑v::'a∈t. (scale::'b ⇒ 'a ⇒ 'a) (u v) v) = (0::'a) ∧ (∃v::'a∈t. u v ≠ (0::'b))))›*) independent_Basis (*‹¬ local.dependent basis›*) by fastforce hence 1: "¬ ETTS_mod.dependent B" using ETTS_mod.dependent_mono (*‹⟦?A ⊆ S; ETTS_mod.dependent ?B; ?B ⊆ ?A⟧ ⟹ ETTS_mod.dependent ?A›*) assms(1) (*‹B ⊆ basis›*) basis_subset (*‹basis ⊆ S›*) by blast have 2: "finite {x ∈ S. f x ≠ 0}" "finite {x ∈ S. g x ≠ 0}" using finite_Basis (*‹finite basis›*) assms(1,2,3) (*‹B ⊆ basis› ‹⟦?v ∈ S; f ?v ≠ 0⟧ ⟹ ?v ∈ B› ‹⟦(?v::'a::ab_group_add) ∈ (S::'a::ab_group_add set); (g::'a::ab_group_add ⇒ 'b::field) ?v ≠ (0::'b::field)⟧ ⟹ ?v ∈ (B::'a::ab_group_add set)›*) apply - (*goals: 1. ‹⟦finite basis; B ⊆ basis; ⋀v. ⟦v ∈ S; f v ≠ 0⟧ ⟹ v ∈ B; ⋀v. ⟦v ∈ S; g v ≠ 0⟧ ⟹ v ∈ B⟧ ⟹ finite {x ∈ S. f x ≠ 0}› 2. ‹⟦finite basis; B ⊆ basis; ⋀v. ⟦v ∈ S; f v ≠ 0⟧ ⟹ v ∈ B; ⋀v. ⟦v ∈ S; g v ≠ 0⟧ ⟹ v ∈ B⟧ ⟹ finite {x ∈ S. g x ≠ 0}› discuss goal 1*) apply ((auto intro: finite_subset (*‹⟦?A ⊆ ?B; finite ?B⟧ ⟹ finite ?A›*))[1]) (*discuss goal 2*) apply ((auto intro: finite_subset (*‹⟦?A ⊆ ?B; finite ?B⟧ ⟹ finite ?A›*))[1]) (*proven 2 subgoals*) . show "?thesis" (*goal: ‹∀x::'a∈S::'a set. (f::'a ⇒ 'b) x = (g::'a ⇒ 'b) x›*) apply (rule ETTS_mod.unique_representation[of B] (*‹⟦B ⊆ S; ¬ ETTS_mod.dependent B; ⋀v. ⟦v ∈ S; ?f v ≠ 0⟧ ⟹ v ∈ B; ⋀v. ⟦v ∈ S; ?g v ≠ 0⟧ ⟹ v ∈ B; finite {x ∈ S. ?f x ≠ 0}; finite {x ∈ S. ?g x ≠ 0}; (∑v∈{x ∈ S. ?f x ≠ 0}. scale (?f v) v) = (∑v∈{x ∈ S. ?g x ≠ 0}. scale (?g v) v)⟧ ⟹ ∀x∈S. ?f x = ?g x›*)) (*goal: ‹∀x::'a::ab_group_add∈S::'a::ab_group_add set. (f::'a::ab_group_add ⇒ 'b::field) x = (g::'a::ab_group_add ⇒ 'b::field) x›*) using assms (*‹B ⊆ basis› ‹⟦(?v::'a::ab_group_add) ∈ (S::'a::ab_group_add set); (f::'a::ab_group_add ⇒ 'b::field) ?v ≠ (0::'b::field)⟧ ⟹ ?v ∈ (B::'a::ab_group_add set)› ‹⟦(?v::'a) ∈ (S::'a set); (g::'a ⇒ 'b) ?v ≠ (0::'b)⟧ ⟹ ?v ∈ (B::'a set)› ‹(∑v∈{x ∈ S. f x ≠ 0}. scale (f v) v) = (∑v∈{x ∈ S. g x ≠ 0}. scale (g v) v)›*) basis_subset (*‹basis ⊆ S›*) "1" (*‹¬ ETTS_mod.dependent B›*) "2" (*‹finite {x ∈ S. f x ≠ 0}› ‹finite {x ∈ S. g x ≠ 0}›*) apply - (*goals: 1. ‹⟦B ⊆ basis; ⋀v. ⟦v ∈ S; f v ≠ 0⟧ ⟹ v ∈ B; ⋀v. ⟦v ∈ S; g v ≠ 0⟧ ⟹ v ∈ B; (∑v∈{x ∈ S. f x ≠ 0}. scale (f v) v) = (∑v∈{x ∈ S. g x ≠ 0}. scale (g v) v); basis ⊆ S; ¬ ETTS_mod.dependent B; finite {x ∈ S. f x ≠ 0}; finite {x ∈ S. g x ≠ 0}⟧ ⟹ B ⊆ S› 2. ‹⟦B ⊆ basis; ⋀v. ⟦v ∈ S; f v ≠ 0⟧ ⟹ v ∈ B; ⋀v. ⟦v ∈ S; g v ≠ 0⟧ ⟹ v ∈ B; (∑v∈{x ∈ S. f x ≠ 0}. scale (f v) v) = (∑v∈{x ∈ S. g x ≠ 0}. scale (g v) v); basis ⊆ S; ¬ ETTS_mod.dependent B; finite {x ∈ S. f x ≠ 0}; finite {x ∈ S. g x ≠ 0}⟧ ⟹ ¬ ETTS_mod.dependent B› 3. ‹⋀v. ⟦v ∈ S; f v ≠ 0; B ⊆ basis; ⋀v. ⟦v ∈ S; f v ≠ 0⟧ ⟹ v ∈ B; ⋀v. ⟦v ∈ S; g v ≠ 0⟧ ⟹ v ∈ B; (∑v∈{x ∈ S. f x ≠ 0}. scale (f v) v) = (∑v∈{x ∈ S. g x ≠ 0}. scale (g v) v); basis ⊆ S; ¬ ETTS_mod.dependent B; finite {x ∈ S. f x ≠ 0}; finite {x ∈ S. g x ≠ 0}⟧ ⟹ v ∈ B› 4. ‹⋀v. ⟦v ∈ S; g v ≠ 0; B ⊆ basis; ⋀v. ⟦v ∈ S; f v ≠ 0⟧ ⟹ v ∈ B; ⋀v. ⟦v ∈ S; g v ≠ 0⟧ ⟹ v ∈ B; (∑v∈{x ∈ S. f x ≠ 0}. scale (f v) v) = (∑v∈{x ∈ S. g x ≠ 0}. scale (g v) v); basis ⊆ S; ¬ ETTS_mod.dependent B; finite {x ∈ S. f x ≠ 0}; finite {x ∈ S. g x ≠ 0}⟧ ⟹ v ∈ B› 5. ‹⟦B ⊆ basis; ⋀v. ⟦v ∈ S; f v ≠ 0⟧ ⟹ v ∈ B; ⋀v. ⟦v ∈ S; g v ≠ 0⟧ ⟹ v ∈ B; (∑v∈{x ∈ S. f x ≠ 0}. scale (f v) v) = (∑v∈{x ∈ S. g x ≠ 0}. scale (g v) v); basis ⊆ S; ¬ ETTS_mod.dependent B; finite {x ∈ S. f x ≠ 0}; finite {x ∈ S. g x ≠ 0}⟧ ⟹ finite {x ∈ S. f x ≠ 0}› 6. ‹⟦B ⊆ basis; ⋀v. ⟦v ∈ S; f v ≠ 0⟧ ⟹ v ∈ B; ⋀v. ⟦v ∈ S; g v ≠ 0⟧ ⟹ v ∈ B; (∑v∈{x ∈ S. f x ≠ 0}. scale (f v) v) = (∑v∈{x ∈ S. g x ≠ 0}. scale (g v) v); basis ⊆ S; ¬ ETTS_mod.dependent B; finite {x ∈ S. f x ≠ 0}; finite {x ∈ S. g x ≠ 0}⟧ ⟹ finite {x ∈ S. g x ≠ 0}› 7. ‹⟦B ⊆ basis; ⋀v. ⟦v ∈ S; f v ≠ 0⟧ ⟹ v ∈ B; ⋀v. ⟦v ∈ S; g v ≠ 0⟧ ⟹ v ∈ B; (∑v∈{x ∈ S. f x ≠ 0}. scale (f v) v) = (∑v∈{x ∈ S. g x ≠ 0}. scale (g v) v); basis ⊆ S; ¬ ETTS_mod.dependent B; finite {x ∈ S. f x ≠ 0}; finite {x ∈ S. g x ≠ 0}⟧ ⟹ (∑v∈{x ∈ S. f x ≠ 0}. scale (f v) v) = (∑v∈{x ∈ S. g x ≠ 0}. scale (g v) v)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*proven 7 subgoals*) . qed lemma (in finite_dimensional_vector_space_on) unique_representation_basis: assumes "⋀v. ⟦v ∈ S; f v ≠ 0⟧ ⟹ v ∈ basis" and "⋀v. ⟦v ∈ S; g v ≠ 0⟧ ⟹ v ∈ basis" and "(∑v∈{x∈S. f x ≠ 0}. scale (f v) v) = (∑v∈{x∈S. g x ≠ 0}. scale (g v) v)" shows "∀x∈S. f x = g x" using unique_representation_basis' (*‹⟦?B ⊆ basis; ⋀v. ⟦v ∈ S; ?f v ≠ 0⟧ ⟹ v ∈ ?B; ⋀v. ⟦v ∈ S; ?g v ≠ 0⟧ ⟹ v ∈ ?B; (∑v∈{x ∈ S. ?f x ≠ 0}. scale (?f v) v) = (∑v∈{x ∈ S. ?g x ≠ 0}. scale (?g v) v)⟧ ⟹ ∀x∈S. ?f x = ?g x›*) assms (*‹⟦(?v::'a) ∈ (S::'a set); (f::'a ⇒ 'b) ?v ≠ (0::'b)⟧ ⟹ ?v ∈ (basis::'a set)› ‹⟦(?v::'a) ∈ (S::'a set); (g::'a ⇒ 'b) ?v ≠ (0::'b)⟧ ⟹ ?v ∈ (basis::'a set)› ‹(∑v∈{x ∈ S. f x ≠ 0}. scale (f v) v) = (∑v∈{x ∈ S. g x ≠ 0}. scale (g v) v)›*) by auto lemma (in finite_dimensional_vector_space_on) components_eq_iff: assumes "⋀v. v ∈ S ∧ f v ≠ 0 ⟷ v ∈ basis" and "⋀v. v ∈ S ∧ g v ≠ 0 ⟷ v ∈ basis" shows "(∑i∈basis. scale (f i) i) = (∑i∈basis. scale (g i) i) ⟷ (∀i∈basis. f i = g i)" proof (-) (*goal: ‹((∑i∈basis. scale (f i) i) = (∑i∈basis. scale (g i) i)) = (∀i∈basis. f i = g i)›*) have "∀i∈S. f i = g i" if "(∑i∈basis. scale (f i) i) = (∑i∈basis. scale (g i) i)" apply (rule unique_representation_basis (*‹⟦⋀v. ⟦v ∈ S; ?f v ≠ 0⟧ ⟹ v ∈ basis; ⋀v. ⟦v ∈ S; ?g v ≠ 0⟧ ⟹ v ∈ basis; (∑v∈{x ∈ S. ?f x ≠ 0}. scale (?f v) v) = (∑v∈{x ∈ S. ?g x ≠ 0}. scale (?g v) v)⟧ ⟹ ∀x∈S. ?f x = ?g x›*)) (*goal: ‹∀i::'a∈S::'a set. (f::'a ⇒ 'b) i = (g::'a ⇒ 'b) i›*) using assms (*‹(?v ∈ S ∧ f ?v ≠ 0) = (?v ∈ basis)› ‹(?v ∈ S ∧ g ?v ≠ 0) = (?v ∈ basis)›*) that (*‹(∑i∈basis. scale (f i) i) = (∑i∈basis. scale (g i) i)›*) apply - (*goals: 1. ‹⋀v. ⟦v ∈ S; f v ≠ 0; ⋀v. (v ∈ S ∧ f v ≠ 0) = (v ∈ basis); ⋀v. (v ∈ S ∧ g v ≠ 0) = (v ∈ basis); (∑i∈basis. scale (f i) i) = (∑i∈basis. scale (g i) i)⟧ ⟹ v ∈ basis› 2. ‹⋀v. ⟦v ∈ S; g v ≠ 0; ⋀v. (v ∈ S ∧ f v ≠ 0) = (v ∈ basis); ⋀v. (v ∈ S ∧ g v ≠ 0) = (v ∈ basis); (∑i∈basis. scale (f i) i) = (∑i∈basis. scale (g i) i)⟧ ⟹ v ∈ basis› 3. ‹⟦⋀v. (v ∈ S ∧ f v ≠ 0) = (v ∈ basis); ⋀v. (v ∈ S ∧ g v ≠ 0) = (v ∈ basis); (∑i∈basis. scale (f i) i) = (∑i∈basis. scale (g i) i)⟧ ⟹ (∑v∈{i ∈ S. f i ≠ 0}. scale (f v) v) = (∑v∈{i ∈ S. g i ≠ 0}. scale (g v) v)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . from this (*‹(∑i∈basis. scale (f i) i) = (∑i∈basis. scale (g i) i) ⟹ ∀i∈S. f i = g i›*) show "?thesis" (*goal: ‹((∑i::'a∈(basis::'a set). (scale::'b ⇒ 'a ⇒ 'a) ((f::'a ⇒ 'b) i) i) = (∑i::'a∈basis. scale ((g::'a ⇒ 'b) i) i)) = (∀i::'a∈basis. f i = g i)›*) using basis_subset (*‹basis ⊆ S›*) by auto qed lemma linear_on_subset: assumes "linear_on C B scaleR scaleR f" and closed_A: "A⊆C" "A≠{}" "⋀x r. x∈A ⟹ scaleR r x ∈ A" "⋀x y. ⟦x∈A; y∈A⟧ ⟹ x+y ∈ A" shows "linear_on A B scaleR scaleR f" proof (-) (*goal: ‹linear_on (A::'a set) (B::'b set) (*⇩R) (*⇩R) (f::'a ⇒ 'b)›*) interpret linear_on C B scaleR scaleR f by fact show "?thesis" (*goal: ‹linear_on A B (*⇩R) (*⇩R) f›*) using closed_A (*‹A ⊆ C› ‹A ≠ {}› ‹?x ∈ A ⟹ ?r *⇩R ?x ∈ A› ‹⟦?x ∈ A; ?y ∈ A⟧ ⟹ ?x + ?y ∈ A›*) apply unfold_locales (*goals: 1. ‹⋀x y a. ⟦A ⊆ C; A ≠ {}; ⋀x r. x ∈ A ⟹ r *⇩R x ∈ A; ⋀x y. ⟦x ∈ A; y ∈ A⟧ ⟹ x + y ∈ A; x ∈ A; y ∈ A⟧ ⟹ a *⇩R (x + y) = a *⇩R x + a *⇩R y› 2. ‹⋀x a b. ⟦A ⊆ C; A ≠ {}; ⋀x r. x ∈ A ⟹ r *⇩R x ∈ A; ⋀x y. ⟦x ∈ A; y ∈ A⟧ ⟹ x + y ∈ A; x ∈ A⟧ ⟹ (a + b) *⇩R x = a *⇩R x + b *⇩R x› 3. ‹⋀x a b. ⟦A ⊆ C; A ≠ {}; ⋀x r. x ∈ A ⟹ r *⇩R x ∈ A; ⋀x y. ⟦x ∈ A; y ∈ A⟧ ⟹ x + y ∈ A; x ∈ A⟧ ⟹ a *⇩R b *⇩R x = (a * b) *⇩R x› 4. ‹⋀x. ⟦A ⊆ C; A ≠ {}; ⋀x r. x ∈ A ⟹ r *⇩R x ∈ A; ⋀x y. ⟦x ∈ A; y ∈ A⟧ ⟹ x + y ∈ A; x ∈ A⟧ ⟹ 1 *⇩R x = x› 5. ‹⋀x y. ⟦A ⊆ C; A ≠ {}; ⋀x r. x ∈ A ⟹ r *⇩R x ∈ A; ⋀x y. ⟦x ∈ A; y ∈ A⟧ ⟹ x + y ∈ A; x ∈ A; y ∈ A⟧ ⟹ x + y ∈ A› 6. ‹⟦A ⊆ C; A ≠ {}; ⋀x r. x ∈ A ⟹ r *⇩R x ∈ A; ⋀x y. ⟦x ∈ A; y ∈ A⟧ ⟹ x + y ∈ A⟧ ⟹ 0 ∈ A› 7. ‹⋀x a. ⟦A ⊆ C; A ≠ {}; ⋀x r. x ∈ A ⟹ r *⇩R x ∈ A; ⋀x y. ⟦x ∈ A; y ∈ A⟧ ⟹ x + y ∈ A; x ∈ A⟧ ⟹ a *⇩R x ∈ A› 8. ‹⋀b1 b2. ⟦A ⊆ C; A ≠ {}; ⋀x r. x ∈ A ⟹ r *⇩R x ∈ A; ⋀x y. ⟦x ∈ A; y ∈ A⟧ ⟹ x + y ∈ A; b1 ∈ A; b2 ∈ A⟧ ⟹ f (b1 + b2) = f b1 + f b2› 9. ‹⋀r b. ⟦A ⊆ C; A ≠ {}; ⋀x r. x ∈ A ⟹ r *⇩R x ∈ A; ⋀x y. ⟦x ∈ A; y ∈ A⟧ ⟹ x + y ∈ A; b ∈ A⟧ ⟹ f (r *⇩R b) = r *⇩R f b› discuss goal 1*) apply ((auto simp: algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 44 facts*) add (*‹⟦?b1.0 ∈ C; ?b2.0 ∈ C⟧ ⟹ f (?b1.0 + ?b2.0) = f ?b1.0 + f ?b2.0›*) scale (*‹?b ∈ C ⟹ f (?r *⇩R ?b) = ?r *⇩R f ?b›*) subset_iff (*‹(?A ⊆ ?B) = (∀t. t ∈ ?A ⟶ t ∈ ?B)›*))[1]) (*discuss goal 2*) apply ((auto simp: algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 44 facts*) add (*‹⟦?b1.0 ∈ C; ?b2.0 ∈ C⟧ ⟹ f (?b1.0 + ?b2.0) = f ?b1.0 + f ?b2.0›*) scale (*‹?b ∈ C ⟹ f (?r *⇩R ?b) = ?r *⇩R f ?b›*) subset_iff (*‹(?A ⊆ ?B) = (∀t. t ∈ ?A ⟶ t ∈ ?B)›*))[1]) (*discuss goal 3*) apply ((auto simp: algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 44 facts*) add (*‹⟦?b1.0 ∈ C; ?b2.0 ∈ C⟧ ⟹ f (?b1.0 + ?b2.0) = f ?b1.0 + f ?b2.0›*) scale (*‹?b ∈ C ⟹ f (?r *⇩R ?b) = ?r *⇩R f ?b›*) subset_iff (*‹(?A ⊆ ?B) = (∀t. t ∈ ?A ⟶ t ∈ ?B)›*))[1]) (*discuss goal 4*) apply ((auto simp: algebra_simps (*‹(?a::?'a::semigroup_add) + (?b::?'a::semigroup_add) + (?c::?'a::semigroup_add) = ?a + (?b + ?c)› ‹(?a::?'a::ab_semigroup_add) + (?b::?'a::ab_semigroup_add) = ?b + ?a› ‹(?b::?'a::ab_semigroup_add) + ((?a::?'a::ab_semigroup_add) + (?c::?'a::ab_semigroup_add)) = ?a + (?b + ?c)› ‹(?a::?'a::semigroup_mult) * (?b::?'a::semigroup_mult) * (?c::?'a::semigroup_mult) = ?a * (?b * ?c)› ‹(?a::?'a::ab_semigroup_mult) * (?b::?'a::ab_semigroup_mult) = ?b * ?a› ‹(?b::?'a::ab_semigroup_mult) * ((?a::?'a::ab_semigroup_mult) * (?c::?'a::ab_semigroup_mult)) = ?a * (?b * ?c)› ‹(?a::?'a::cancel_ab_semigroup_add) - (?b::?'a::cancel_ab_semigroup_add) - (?c::?'a::cancel_ab_semigroup_add) = ?a - (?b + ?c)› ‹(?a::?'a::group_add) + ((?b::?'a::group_add) - (?c::?'a::group_add)) = ?a + ?b - ?c› ‹((?a::?'a::group_add) - (?b::?'a::group_add) = (?c::?'a::group_add)) = (?a = ?c + ?b)› ‹((?a::?'a::group_add) = (?c::?'a::group_add) - (?b::?'a::group_add)) = (?a + ?b = ?c)› ‹(?a::?'a::group_add) - ((?b::?'a::group_add) - (?c::?'a::group_add)) = ?a + ?c - ?b› ‹(?a::?'a::ab_group_add) - (?b::?'a::ab_group_add) + (?c::?'a::ab_group_add) = ?a + ?c - ?b› and more 44 facts*) add (*‹⟦(?b1.0::'a::{ab_group_add,scaleR}) ∈ (C::'a::{ab_group_add,scaleR} set); (?b2.0::'a::{ab_group_add,scaleR}) ∈ C⟧ ⟹ (f::'a::{ab_group_add,scaleR} ⇒ 'b::{ab_group_add,scaleR}) (?b1.0 + ?b2.0) = f ?b1.0 + f ?b2.0›*) scale (*‹(?b::'a::{ab_group_add,scaleR}) ∈ (C::'a::{ab_group_add,scaleR} set) ⟹ (f::'a::{ab_group_add,scaleR} ⇒ 'b::{ab_group_add,scaleR}) ((?r::real) *⇩R ?b) = ?r *⇩R f ?b›*) subset_iff (*‹((?A::?'a::type set) ⊆ (?B::?'a::type set)) = (∀t::?'a::type. t ∈ ?A ⟶ t ∈ ?B)›*))[1]) (*discuss goal 5*) apply ((auto simp: algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 44 facts*) add (*‹⟦?b1.0 ∈ C; ?b2.0 ∈ C⟧ ⟹ f (?b1.0 + ?b2.0) = f ?b1.0 + f ?b2.0›*) scale (*‹?b ∈ C ⟹ f (?r *⇩R ?b) = ?r *⇩R f ?b›*) subset_iff (*‹(?A ⊆ ?B) = (∀t. t ∈ ?A ⟶ t ∈ ?B)›*))[1]) (*discuss goal 6*) apply ((auto simp: algebra_simps (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)› ‹(?a::?'a) * (?b::?'a) * (?c::?'a) = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)› ‹(?a::?'a) - (?b::?'a) - (?c::?'a) = ?a - (?b + ?c)› ‹(?a::?'a) + ((?b::?'a) - (?c::?'a)) = ?a + ?b - ?c› ‹((?a::?'a) - (?b::?'a) = (?c::?'a)) = (?a = ?c + ?b)› ‹((?a::?'a) = (?c::?'a) - (?b::?'a)) = (?a + ?b = ?c)› ‹(?a::?'a) - ((?b::?'a) - (?c::?'a)) = ?a + ?c - ?b› ‹(?a::?'a) - (?b::?'a) + (?c::?'a) = ?a + ?c - ?b› and more 44 facts*) add (*‹⟦(?b1.0::'a) ∈ (C::'a set); (?b2.0::'a) ∈ C⟧ ⟹ (f::'a ⇒ 'b) (?b1.0 + ?b2.0) = f ?b1.0 + f ?b2.0›*) scale (*‹(?b::'a) ∈ (C::'a set) ⟹ (f::'a ⇒ 'b) ((?r::real) *⇩R ?b) = ?r *⇩R f ?b›*) subset_iff (*‹((?A::?'a set) ⊆ (?B::?'a set)) = (∀t::?'a. t ∈ ?A ⟶ t ∈ ?B)›*))[1]) (*top goal: ‹⟦A ⊆ C; A ≠ {}; ⋀x r. x ∈ A ⟹ r *⇩R x ∈ A; ⋀x y. ⟦x ∈ A; y ∈ A⟧ ⟹ x + y ∈ A⟧ ⟹ 0 ∈ A› and 3 goals remain*) apply (metis m1.scale_zero_left (*‹?x ∈ C ⟹ 0 *⇩R ?x = 0›*)) (*discuss goal 7*) apply ((auto simp: algebra_simps (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)› ‹(?a::?'a) * (?b::?'a) * (?c::?'a) = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)› ‹(?a::?'a) - (?b::?'a) - (?c::?'a) = ?a - (?b + ?c)› ‹(?a::?'a) + ((?b::?'a) - (?c::?'a)) = ?a + ?b - ?c› ‹((?a::?'a) - (?b::?'a) = (?c::?'a)) = (?a = ?c + ?b)› ‹((?a::?'a) = (?c::?'a) - (?b::?'a)) = (?a + ?b = ?c)› ‹(?a::?'a) - ((?b::?'a) - (?c::?'a)) = ?a + ?c - ?b› ‹(?a::?'a) - (?b::?'a) + (?c::?'a) = ?a + ?c - ?b› and more 44 facts*) add (*‹⟦(?b1.0::'a) ∈ (C::'a set); (?b2.0::'a) ∈ C⟧ ⟹ (f::'a ⇒ 'b) (?b1.0 + ?b2.0) = f ?b1.0 + f ?b2.0›*) scale (*‹(?b::'a) ∈ (C::'a set) ⟹ (f::'a ⇒ 'b) ((?r::real) *⇩R ?b) = ?r *⇩R f ?b›*) subset_iff (*‹((?A::?'a set) ⊆ (?B::?'a set)) = (∀t::?'a. t ∈ ?A ⟶ t ∈ ?B)›*))[1]) (*discuss goal 8*) apply ((auto simp: algebra_simps (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)› ‹(?a::?'a) * (?b::?'a) * (?c::?'a) = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)› ‹(?a::?'a) - (?b::?'a) - (?c::?'a) = ?a - (?b + ?c)› ‹(?a::?'a) + ((?b::?'a) - (?c::?'a)) = ?a + ?b - ?c› ‹((?a::?'a) - (?b::?'a) = (?c::?'a)) = (?a = ?c + ?b)› ‹((?a::?'a) = (?c::?'a) - (?b::?'a)) = (?a + ?b = ?c)› ‹(?a::?'a) - ((?b::?'a) - (?c::?'a)) = ?a + ?c - ?b› ‹(?a::?'a) - (?b::?'a) + (?c::?'a) = ?a + ?c - ?b› and more 44 facts*) add (*‹⟦(?b1.0::'a) ∈ (C::'a set); (?b2.0::'a) ∈ C⟧ ⟹ (f::'a ⇒ 'b) (?b1.0 + ?b2.0) = f ?b1.0 + f ?b2.0›*) scale (*‹(?b::'a) ∈ (C::'a set) ⟹ (f::'a ⇒ 'b) ((?r::real) *⇩R ?b) = ?r *⇩R f ?b›*) subset_iff (*‹((?A::?'a set) ⊆ (?B::?'a set)) = (∀t::?'a. t ∈ ?A ⟶ t ∈ ?B)›*))[1]) (*discuss goal 9*) apply ((auto simp: algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 44 facts*) add (*‹⟦?b1.0 ∈ C; ?b2.0 ∈ C⟧ ⟹ f (?b1.0 + ?b2.0) = f ?b1.0 + f ?b2.0›*) scale (*‹?b ∈ C ⟹ f (?r *⇩R ?b) = ?r *⇩R f ?b›*) subset_iff (*‹(?A ⊆ ?B) = (∀t. t ∈ ?A ⟶ t ∈ ?B)›*))[1]) (*proven 9 subgoals*) . qed lemma fixes f :: "'a::euclidean_space ⇒ 'b::real_normed_vector" assumes "linear f" shows linear_imp_higher_differentiable_on: "higher_differentiable_on S f n" and linear_imp_smooth_on: "smooth_on S f" using bounded_linear.higher_differentiable_on (*‹bounded_linear ?f ⟹ higher_differentiable_on ?S ?f ?n›*) bounded_linear.smooth_on (*‹bounded_linear (?f::?'a ⇒ ?'b) ⟹ (?k::enat)-smooth_on (?S::?'a set) ?f›*) assms (*‹linear f›*) apply - (*goals: 1. ‹⟦⋀f S n. bounded_linear f ⟹ higher_differentiable_on S f n; ⋀f k S. bounded_linear f ⟹ k-smooth_on S f; linear f⟧ ⟹ higher_differentiable_on S f n› 2. ‹⟦⋀f S n. bounded_linear f ⟹ higher_differentiable_on S f n; ⋀f k S. bounded_linear f ⟹ k-smooth_on S f; linear f⟧ ⟹ smooth_on S f› discuss goal 1*) apply ((auto simp: linear_conv_bounded_linear[of f] (*‹linear f = bounded_linear f›*))[1]) (*discuss goal 2*) by ((auto simp: linear_conv_bounded_linear[of f] (*‹linear f = bounded_linear f›*))[1]) (*proven 2 subgoals*) lemma differentiable_transform_within: assumes "f differentiable (at x within s)" and "0 < d" and "x ∈ s" and "⋀x'. ⟦x' ∈ s; dist x' x < d⟧ ⟹ f x' = g x'" shows "g differentiable (at x within s)" using assms (*‹(f::'a ⇒ 'b) differentiable at (x::'a) within (s::'a set)› ‹0 < d› ‹x ∈ s› ‹⟦?x' ∈ s; dist ?x' x < d⟧ ⟹ f ?x' = g ?x'›*) has_derivative_transform_within (*‹⟦(?f has_derivative ?f') (at ?x within ?s); 0 < ?d; ?x ∈ ?s; ⋀x'. ⟦x' ∈ ?s; dist x' ?x < ?d⟧ ⟹ ?f x' = ?g x'⟧ ⟹ (?g has_derivative ?f') (at ?x within ?s)›*) unfolding differentiable_def (*goal: ‹∃D. (g has_derivative D) (at x within s)›*) by blast lemma differentiable_transform_within_open: assumes "f differentiable (at x within t)" and "open s" and "x ∈ s" and "⋀x. x∈s ⟹ f x = g x" shows "g differentiable (at x within t)" using assms (*‹f differentiable at x within t› ‹open s› ‹(x::'a) ∈ (s::'a set)› ‹?x ∈ s ⟹ f ?x = g ?x›*) has_derivative_transform_within_open (*‹⟦(?f has_derivative ?f') (at ?x within ?t); open ?s; ?x ∈ ?s; ⋀x. x ∈ ?s ⟹ ?f x = ?g x⟧ ⟹ (?g has_derivative ?f') (at ?x within ?t)›*) unfolding differentiable_def (*goal: ‹∃D. (g has_derivative D) (at x within t)›*) by blast lemma differentiable_transform: assumes "x ∈ s" "⋀x. x ∈ s ⟹ g x = f x" assumes "f differentiable (at x within s)" shows "g differentiable (at x within s)" using assms (*‹(x::'a) ∈ (s::'a set)› ‹?x ∈ s ⟹ g ?x = f ?x› ‹f differentiable at x within s›*) has_derivative_transform (*‹⟦(?x::?'a) ∈ (?s::?'a set); ⋀x::?'a. x ∈ ?s ⟹ (?g::?'a ⇒ ?'b) x = (?f::?'a ⇒ ?'b) x; (?f has_derivative (?f'::?'a ⇒ ?'b)) (at ?x within ?s)⟧ ⟹ (?g has_derivative ?f') (at ?x within ?s)›*) unfolding differentiable_def (*goal: ‹∃D::'a::real_normed_vector ⇒ 'b::real_normed_vector. ((g::'a::real_normed_vector ⇒ 'b::real_normed_vector) has_derivative D) (at (x::'a::real_normed_vector) within (s::'a::real_normed_vector set))›*) by blast lemma derivative_is_smooth2': "smooth_on S (λv. frechet_derivative f (at x) v)" if "f differentiable_on S" "x∈S" "open S" for S x and f :: "'i::euclidean_space ⇒ 'o::real_normed_vector" proof (-) (*goal: ‹smooth_on (S::'i::euclidean_space set) (frechet_derivative (f::'i::euclidean_space ⇒ 'o::real_normed_vector) (at (x::'i::euclidean_space)))›*) have linear_deriv: "linear (frechet_derivative f (at x within S))" using that(1,2) (*‹f differentiable_on S› ‹(x::'i) ∈ (S::'i set)›*) by (auto intro: linear_frechet_derivative (*‹(?f::?'a::real_normed_vector ⇒ ?'b::real_normed_vector) differentiable (?net::?'a::real_normed_vector filter) ⟹ linear (frechet_derivative ?f ?net)›*) simp: differentiable_on_def (*‹((?f::?'a::real_normed_vector ⇒ ?'b::real_normed_vector) differentiable_on (?s::?'a::real_normed_vector set)) = (∀x::?'a::real_normed_vector∈?s. ?f differentiable at x within ?s)›*)) show "?thesis" (*goal: ‹smooth_on S (frechet_derivative f (at x))›*) using linear_imp_smooth_on[OF linear_deriv] (*‹smooth_on ?S (frechet_derivative f (at x within S))›*) at_within_open[OF that ( 2 , 3 )] (*‹at x within S = at x›*) by force qed lemma derivative_is_smooth2: "smooth_on S (λv. frechet_derivative f (at x) v)" if "smooth_on S f" "x∈S" "open S" for S x and f :: "'i::euclidean_space ⇒ 'o::real_normed_vector" using derivative_is_smooth2'[OF smooth_on_imp_differentiable_on [ OF that ( 1 ) ] that ( 2 , 3 )] (*‹0 < ∞ ⟹ smooth_on S (frechet_derivative f (at x))›*) by simp lemma (in c_manifold) diff_fun_on_open: assumes "open A" shows "diff_fun_on A f ⟷ A ⊆ carrier ∧ diff_fun k (charts_submanifold A) f" proof (intro iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*) conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹diff_fun_on A f ⟹ A ⊆ carrier› 2. ‹diff_fun_on A f ⟹ diff_fun k (charts_submanifold A) f› 3. ‹A ⊆ carrier ∧ diff_fun k (charts_submanifold A) f ⟹ diff_fun_on A f›*) assume diff_A_f: "diff_fun_on A f" (*‹diff_fun_on (A::'a set) (f::'a ⇒ 'c)›*) thus "diff_fun k (charts_submanifold A) f" proof (-) (*goal: ‹diff_fun_on A f ⟹ diff_fun k (charts_submanifold A) f›*) { fix W and f' assume asm: "open W" "A⊆W" "W ⊆ carrier" "∀x∈A. f x = f' x" "diff_fun k (charts_submanifold W) f'" (*‹open (W::'a set)› ‹(A::'a set) ⊆ (W::'a set)› ‹(W::'a set) ⊆ carrier› ‹∀x::'a∈A::'a set. (f::'a ⇒ 'c) x = (f'::'a ⇒ 'c) x› ‹diff_fun (k::enat) (charts_submanifold (W::'a set)) (f'::'a ⇒ 'c)›*) interpret W: manifold "restrict_chart W ` charts" . have 1: "manifold.charts_submanifold (charts_submanifold W) A = charts_submanifold A" apply (simp add: charts_submanifold_def (*‹charts_submanifold ?S = restrict_chart ?S ` charts›*) W.charts_submanifold_def (*‹W.charts_submanifold ?S = restrict_chart ?S ` restrict_chart W ` charts›*)) (*goal: ‹manifold.charts_submanifold (charts_submanifold W) A = charts_submanifold A›*) using restrict_chart_restrict_chart (*‹⟦open ?X; open ?Y⟧ ⟹ restrict_chart ?X (restrict_chart ?Y ?c) = restrict_chart (?X ∩ ?Y) ?c›*) asm(1-2) (*‹open W› ‹A ⊆ W›*) assms (*‹open A›*) by (smt (verit, best) image_cong (*‹⟦(?M::?'a set) = (?N::?'a set); ⋀x::?'a. x ∈ ?N ⟹ (?f::?'a ⇒ ?'b) x = (?g::?'a ⇒ ?'b) x⟧ ⟹ ?f ` ?M = ?g ` ?N›*) image_image (*‹(?f::?'b ⇒ ?'a) ` (?g::?'c ⇒ ?'b) ` (?A::?'c set) = (λx::?'c. ?f (?g x)) ` ?A›*) inf.absorb_iff1 (*‹((?a::?'a) ≤ (?b::?'a)) = (inf ?a ?b = ?a)›*)) then interpret f': diff_fun k "charts_submanifold A" f' unfolding diff_fun_def (*goal: ‹diff k (charts_submanifold A) charts_eucl f'›*) using diff.diff_submanifold[OF asm ( 5 ) [ unfolded diff_fun_def ] assms] (*‹diff k (manifold.charts_submanifold (charts_submanifold W) A) charts_eucl f'›*) by simp have "diff_fun k (charts_submanifold A) f" apply (rule f'.diff_fun_cong (*‹(⋀x. x ∈ f'.src.carrier ⟹ f' x = ?g x) ⟹ diff_fun k (charts_submanifold A) ?g›*)) (*goal: ‹diff_fun k (charts_submanifold A) f›*) using assms (*‹open A›*) asm(4) (*‹∀x∈A. f x = f' x›*) by (metis (no_types, lifting) Int_iff (*‹(?c ∈ ?A ∩ ?B) = (?c ∈ ?A ∧ ?c ∈ ?B)›*) domain_restrict_chart (*‹open ?S ⟹ domain (restrict_chart ?S ?c) = domain ?c ∩ ?S›*) f'.src.carrierE (*‹⟦?x ∈ f'.src.carrier; ⋀c. ⟦c ∈ charts_submanifold A; ?x ∈ domain c⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*) manifold.charts_submanifold_def (*‹manifold.charts_submanifold ?charts ?S = restrict_chart ?S ` ?charts›*)) } then show "?thesis" (*goal: ‹diff_fun k (charts_submanifold A) f›*) using diff_A_f (*‹diff_fun_on A f›*) by (metis diff_fun_onE (*‹⟦diff_fun_on ?A ?f; ⋀W f'. ⟦?A ⊆ W; W ⊆ carrier; open W; diff_fun k (charts_submanifold W) f'; ⋀x. x ∈ ?A ⟹ ?f x = f' x⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) qed show "A ⊆ carrier" using diff_A_f (*‹diff_fun_on (A::'a set) (f::'a ⇒ 'c)›*) unfolding diff_fun_on_def (*goal: ‹A ⊆ carrier›*) by auto next (*goal: ‹A ⊆ carrier ∧ diff_fun k (charts_submanifold A) f ⟹ diff_fun_on A f›*) assume asm: "A⊆carrier ∧ diff_fun k (charts_submanifold A) f" (*‹(A::'a set) ⊆ carrier ∧ diff_fun (k::enat) (charts_submanifold A) (f::'a ⇒ 'c)›*) show "diff_fun_on A f" using asm (*‹A ⊆ carrier ∧ diff_fun k (charts_submanifold A) f›*) assms (*‹open A›*) by (auto intro: exI[of _ A] (*‹?P A ⟹ ∃x. ?P x›*) simp: diff_fun_on_def (*‹diff_fun_on ?A ?f = (∃W. ?A ⊆ W ∧ W ⊆ carrier ∧ open W ∧ (∃f'. diff_fun k (charts_submanifold W) f' ∧ (∀x∈?A. ?f x = f' x)))›*)) qed lemma (in c_manifold) diff_fun_differentiable_at: "(f ∘ (inv_chart c)) differentiable at (c p)" if "diff_fun k charts f" "c ∈ atlas" "p ∈ domain c" "k>0" using diff_fun.diff_fun_between_chartsD[OF that ( 1 - 3 )] (*‹k-smooth_on (codomain c) (f ∘ inv_chart c)›*) higher_differentiable_on.simps(2) (*‹higher_differentiable_on (?S::?'a::real_normed_vector set) (?f::?'a::real_normed_vector ⇒ ?'b::real_normed_vector) (Suc (?n::nat)) = ((∀x::?'a::real_normed_vector∈?S. ?f differentiable at x) ∧ (∀v::?'a::real_normed_vector. higher_differentiable_on ?S (λx::?'a::real_normed_vector. frechet_derivative ?f (at x) v) ?n))›*) that(3,4) (*‹(p::'a) ∈ domain (c::('a, 'b) chart)› ‹0 < k›*) unfolding smooth_on_def diff_fun_def diff_def diff_axioms_def (*goal: ‹f ∘ inv_chart c differentiable at (apply_chart c p)›*) by (metis Suc_ile_eq (*‹(enat (Suc ?m) ≤ ?n) = (enat ?m < ?n)›*) chart_in_codomain (*‹?x ∈ domain ?c ⟹ apply_chart ?c ?x ∈ codomain ?c›*) enat_0_iff( (*‹(0 = enat ?x) = (?x = 0)›*) 2)) lemma (in submanifold) sub_diff_fun_differentiable_at: "(f ∘ (inv_chart c)) differentiable at (c p)" if "diff_fun k (charts_submanifold S) f" "c ∈ sub.atlas" "p ∈ domain c" "k>0" using sub.diff_fun_differentiable_at (*‹⟦diff_fun k (charts_submanifold S) ?f; ?c ∈ sub.atlas; ?p ∈ domain ?c; 0 < k⟧ ⟹ ?f ∘ inv_chart ?c differentiable at (apply_chart ?c ?p)›*) that (*‹diff_fun k (charts_submanifold S) f› ‹(c::('a, 'b) chart) ∈ sub.atlas› ‹p ∈ domain c› ‹(0::enat) < (k::enat)›*) by blast lemma (in c_manifold) diff_fun_on_differentiable_at: "(f ∘ (inv_chart c)) differentiable at (c p)" if "diff_fun_on S f" "c ∈ atlas" "p ∈ S" "S ⊆ domain c" "k>0" "open S" proof (-) (*goal: ‹f ∘ inv_chart c differentiable at (apply_chart c p)›*) interpret S: submanifold charts k S apply unfold_locales (*goal: ‹submanifold charts k S›*) by fact show "?thesis" (*goal: ‹f ∘ inv_chart c differentiable at (apply_chart c p)›*) apply (rule S.sub_diff_fun_differentiable_at[of f "restrict_chart S c" p, simplified] (*‹⟦diff_fun k (charts_submanifold S) f; restrict_chart S c ∈ S.sub.atlas; p ∈ domain (restrict_chart S c); k ≠ 0⟧ ⟹ f ∘ inv_chart c differentiable at (apply_chart c p)›*)) (*goal: ‹(f::'a ⇒ 'c) ∘ inv_chart (c::('a, 'b) chart) differentiable at (apply_chart c (p::'a))›*) using diff_fun_on_open[OF that ( 6 )] (*‹diff_fun_on S ?f = (S ⊆ carrier ∧ diff_fun k (charts_submanifold S) ?f)›*) that (*‹diff_fun_on S f› ‹c ∈ atlas› ‹p ∈ S› ‹S ⊆ domain c› ‹0 < k› ‹open S›*) S.submanifold_atlasI (*‹?c ∈ atlas ⟹ restrict_chart S ?c ∈ S.sub.atlas›*) apply - (*goals: 1. ‹⟦⋀f. diff_fun_on S f = (S ⊆ carrier ∧ diff_fun k (charts_submanifold S) f); diff_fun_on S f; c ∈ atlas; p ∈ S; S ⊆ domain c; 0 < k; open S; ⋀c. c ∈ atlas ⟹ restrict_chart S c ∈ S.sub.atlas⟧ ⟹ diff_fun k (charts_submanifold S) f› 2. ‹⟦⋀f. diff_fun_on S f = (S ⊆ carrier ∧ diff_fun k (charts_submanifold S) f); diff_fun_on S f; c ∈ atlas; p ∈ S; S ⊆ domain c; 0 < k; open S; ⋀c. c ∈ atlas ⟹ restrict_chart S c ∈ S.sub.atlas⟧ ⟹ restrict_chart S c ∈ S.sub.atlas› 3. ‹⟦⋀f. diff_fun_on S f = (S ⊆ carrier ∧ diff_fun k (charts_submanifold S) f); diff_fun_on S f; c ∈ atlas; p ∈ S; S ⊆ domain c; 0 < k; open S; ⋀c. c ∈ atlas ⟹ restrict_chart S c ∈ S.sub.atlas⟧ ⟹ p ∈ domain (restrict_chart S c)› 4. ‹⟦⋀f. diff_fun_on S f = (S ⊆ carrier ∧ diff_fun k (charts_submanifold S) f); diff_fun_on S f; c ∈ atlas; p ∈ S; S ⊆ domain c; 0 < k; open S; ⋀c. c ∈ atlas ⟹ restrict_chart S c ∈ S.sub.atlas⟧ ⟹ k ≠ 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . qed subsection ‹Products› subsubsection ‹\<^term>‹map_prod› and \<^term>‹swap› (no manifolds required)› lemma continuous_on_swap2[continuous_intros]: "continuous_on (s × t) f ⟹ continuous_on (t × s) (f ∘ prod.swap)" using continuous_on_compose (*‹⟦continuous_on ?s ?f; continuous_on (?f ` ?s) ?g⟧ ⟹ continuous_on ?s (?g ∘ ?f)›*) by (metis continuous_on_swap (*‹continuous_on ?A prod.swap›*) product_swap (*‹prod.swap ` (?A × ?B) = ?B × ?A›*)) lemma homeomorphism_prod_swap: "homeomorphism (b × a) (c × d) (λ(y, x). (f x, g y)) (λ(x, y). (g' y, f' x))" if "homeomorphism a c f f'" "homeomorphism b d g g'" proof (-) (*goal: ‹homeomorphism (b × a) (c × d) (λ(y, x). (f x, g y)) (λ(x, y). (g' y, f' x))›*) { fix x and y assume asm: "x∈a" "y∈b" (*‹(x::'a) ∈ (a::'a set)› ‹(y::'c) ∈ (b::'c set)›*) have "(f x, g y) ∈ (λx. (f (snd x), g (fst x))) ` (b × a)" and "(y, x) ∈ (λx. (g' (snd x), f' (fst x))) ` (f ` a × g ` b)" using asm (*‹x ∈ a› ‹y ∈ b›*) that (*‹homeomorphism a c f f'› ‹homeomorphism b d g g'›*) unfolding homeomorphism_def (*goals: 1. ‹(f x, g y) ∈ (λx. (f (snd x), g (fst x))) ` (b × a)› 2. ‹(y, x) ∈ (λx. (g' (snd x), f' (fst x))) ` (f ` a × g ` b)›*) using image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*) apply - (*goals: 1. ‹⟦x ∈ a; y ∈ b; (∀x∈a. f' (f x) = x) ∧ f ` a = c ∧ continuous_on a f ∧ (∀y∈c. f (f' y) = y) ∧ f' ` c = a ∧ continuous_on c f'; (∀x∈b. g' (g x) = x) ∧ g ` b = d ∧ continuous_on b g ∧ (∀y∈d. g (g' y) = y) ∧ g' ` d = b ∧ continuous_on d g'; ⋀z f A. (z ∈ f ` A) = (∃x∈A. z = f x)⟧ ⟹ (f x, g y) ∈ (λx. (f (snd x), g (fst x))) ` (b × a)› 2. ‹⟦x ∈ a; y ∈ b; (∀x∈a. f' (f x) = x) ∧ f ` a = c ∧ continuous_on a f ∧ (∀y∈c. f (f' y) = y) ∧ f' ` c = a ∧ continuous_on c f'; (∀x∈b. g' (g x) = x) ∧ g ` b = d ∧ continuous_on b g ∧ (∀y∈d. g (g' y) = y) ∧ g' ` d = b ∧ continuous_on d g'; ⋀z f A. (z ∈ f ` A) = (∃x∈A. z = f x)⟧ ⟹ (y, x) ∈ (λx. (g' (snd x), f' (fst x))) ` (f ` a × g ` b)› discuss goal 1*) apply fastforce (*discuss goal 2*) apply fastforce (*proven 2 subgoals*) . } thus "?thesis" (*goal: ‹homeomorphism (b × a) (c × d) (λ(y, x). (f x, g y)) (λ(x, y). (g' y, f' x))›*) using that (*‹homeomorphism a c f f'› ‹homeomorphism b d g g'›*) unfolding homeomorphism_def (*goal: ‹(∀x∈b × a. (case case x of (y, x) ⇒ (f x, g y) of (x, y) ⇒ (g' y, f' x)) = x) ∧ (λ(y, x). (f x, g y)) ` (b × a) = c × d ∧ continuous_on (b × a) (λ(y, x). (f x, g y)) ∧ (∀y∈c × d. (case case y of (x, y) ⇒ (g' y, f' x) of (y, x) ⇒ (f x, g y)) = y) ∧ (λ(x, y). (g' y, f' x)) ` (c × d) = b × a ∧ continuous_on (c × d) (λ(x, y). (g' y, f' x))›*) by (auto simp: split_beta (*‹(case ?prod of (x, xa) ⇒ ?f x xa) = ?f (fst ?prod) (snd ?prod)›*) image_prod (*‹(λ(x, y). (?f x, ?g y)) ` (?A × ?B) = ?f ` ?A × ?g ` ?B›*) intro!: continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 240 facts*) elim: continuous_on_compose2 (*‹⟦continuous_on ?t ?g; continuous_on ?s ?f; ?f ` ?s ⊆ ?t⟧ ⟹ continuous_on ?s (λx. ?g (?f x))›*)) qed lemma continuous_on_map_prod: assumes "continuous_on A f" "continuous_on B g" shows "continuous_on (A×B) (map_prod f g)" proof (-) (*goal: ‹continuous_on (A × B) (map_prod f g)›*) have "continuous_on (A × B) (f ∘ fst)" apply (rule continuous_on_compose[OF continuous_on_fst[OF continuous_on_id]] (*‹continuous_on (fst ` ?s) ?g ⟹ continuous_on ?s (?g ∘ fst)›*)) (*goal: ‹continuous_on (A × B) (f ∘ fst)›*) by (simp add: assms( (*‹continuous_on A f›*) 1)) moreover have "continuous_on (A × B) (g ∘ snd)" apply (rule continuous_on_compose[OF continuous_on_snd[OF continuous_on_id]] (*‹continuous_on (snd ` ?s) ?g ⟹ continuous_on ?s (?g ∘ snd)›*)) (*goal: ‹continuous_on (A × B) (g ∘ snd)›*) by (simp add: assms( (*‹continuous_on B g›*) 2)) ultimately show "?thesis" (*goal: ‹continuous_on (A × B) (map_prod f g)›*) using continuous_on_Pair[of "A×B" "f∘fst" "g∘snd"] (*‹⟦continuous_on ((A::'a set) × (B::'c set)) ((f::'a ⇒ 'b) ∘ fst); continuous_on (A × B) ((g::'c ⇒ 'd) ∘ snd)⟧ ⟹ continuous_on (A × B) (λx::'a × 'c. ((f ∘ fst) x, (g ∘ snd) x))›*) by (simp add: map_prod_def (*‹map_prod ?f ?g = (λ(x, y). (?f x, ?g y))›*) case_prod_beta (*‹(case ?p of (x, xa) ⇒ ?f x xa) = ?f (fst ?p) (snd ?p)›*)) qed lemma continuous_on_map_proj: assumes "continuous_on (A×B) (map_prod f g)" shows "continuous_on (A×B) (f∘fst)" "continuous_on (A×B) (g∘snd)" using assms (*‹continuous_on ((A::'a set) × (B::'b set)) (map_prod (f::'a ⇒ 'c) (g::'b ⇒ 'd))›*) continuous_on_fst (*‹continuous_on (?s::?'a::topological_space set) (?f::?'a::topological_space ⇒ ?'b::topological_space × ?'c::topological_space) ⟹ continuous_on ?s (λx::?'a::topological_space. fst (?f x))›*) continuous_on_snd (*‹continuous_on ?s ?f ⟹ continuous_on ?s (λx. snd (?f x))›*) apply - (*goals: 1. ‹⟦continuous_on (A × B) (map_prod f g); ⋀s f. continuous_on s f ⟹ continuous_on s (λx. fst (f x)); ⋀s f. continuous_on s f ⟹ continuous_on s (λx. snd (f x))⟧ ⟹ continuous_on (A × B) (f ∘ fst)› 2. ‹⟦continuous_on (A × B) (map_prod f g); ⋀s f. continuous_on s f ⟹ continuous_on s (λx. fst (f x)); ⋀s f. continuous_on s f ⟹ continuous_on s (λx. snd (f x))⟧ ⟹ continuous_on (A × B) (g ∘ snd)› discuss goal 1*) apply fastforce (*discuss goal 2*) apply fastforce (*proven 2 subgoals*) . lemma homeomorphism_swap: fixes a :: "'a::topological_space set" and b :: "'b::topological_space set" and c :: "'c::topological_space set" and d :: "'d::topological_space set" assumes "homeomorphism S T F G" shows "homeomorphism (prod.swap`S) T (F∘prod.swap) (prod.swap∘G)" (is "homeomorphism ?S' T ?F' ?G'") proof (standard) (*goals: 1. ‹continuous_on (prod.swap ` S) (F ∘ prod.swap)› 2. ‹continuous_on T (prod.swap ∘ G)› 3. ‹(F ∘ prod.swap) ` prod.swap ` S ⊆ T› 4. ‹(prod.swap ∘ G) ` T ⊆ prod.swap ` S› 5. ‹⋀x. x ∈ prod.swap ` S ⟹ (prod.swap ∘ G) ((F ∘ prod.swap) x) = x› 6. ‹⋀y. y ∈ T ⟹ (F ∘ prod.swap) ((prod.swap ∘ G) y) = y›*) have "continuous_on S F" using assms (*‹homeomorphism S T F G›*) by (simp add: homeomorphism_cont1 (*‹homeomorphism ?S ?T ?f ?g ⟹ continuous_on ?S ?f›*)) thus "continuous_on ?S' ?F'" using continuous_on_compose[OF continuous_on_swap, of "?S'" "F"] (*‹continuous_on (prod.swap ` prod.swap ` S) F ⟹ continuous_on (prod.swap ` S) (F ∘ prod.swap)›*) by (simp add: image_comp (*‹?f ` ?g ` ?r = (?f ∘ ?g) ` ?r›*)) have "continuous_on T G" using assms (*‹homeomorphism (S::('e × 'f) set) (T::'g set) (F::'e × 'f ⇒ 'g) (G::'g ⇒ 'e × 'f)›*) by (simp add: homeomorphism_cont2 (*‹homeomorphism (?S::?'a set) (?T::?'b set) (?f::?'a ⇒ ?'b) (?g::?'b ⇒ ?'a) ⟹ continuous_on ?T ?g›*)) from continuous_on_compose[OF this continuous_on_swap] (*‹continuous_on T (prod.swap ∘ G)›*) show "continuous_on T ?G'" by (simp add: case_prod_unfold (*‹case_prod = (λc p. c (fst p) (snd p))›*)) show "?F' ` ?S' ⊆ T" using homeomorphism_image1[OF assms] (*‹(F::'e × 'f ⇒ 'g) ` (S::('e × 'f) set) = (T::'g set)›*) by auto show "?G' ` T ⊆ ?S'" using homeomorphism_image2[OF assms] (*‹G ` T = S›*) by auto show "⋀y. y∈T ⟹ (?F'(?G' y) = y)" using homeomorphism_apply2[OF assms] (*‹?x ∈ T ⟹ F (G ?x) = ?x›*) by auto show "⋀x. x∈?S' ⟹ (?G'(?F' x) = x)" using homeomorphism_apply1[OF assms] (*‹?x ∈ S ⟹ G (F ?x) = ?x›*) by auto qed lemma homeomorphism_swap': fixes a :: "'a::topological_space set" and b :: "'b::topological_space set" and c :: "'c::topological_space set" and d :: "'d::topological_space set" assumes "homeomorphism (a × b) (c × d) (λ(x, y). (f x, g y)) (λ(x, y). (f' x, g' y))" shows "homeomorphism (b × a) (c × d) (λ(y, x). (f x, g y)) (λ(x, y). (g' y, f' x))" apply (rule homeomorphism_cong[OF homeomorphism_swap[OF assms]] (*‹⟦?X' = prod.swap ` (a × b); ?Y' = c × d; ⋀x. x ∈ prod.swap ` (a × b) ⟹ ?f' x = ((λ(x, y). (f x, g y)) ∘ prod.swap) x; ⋀y. y ∈ c × d ⟹ ?g' y = (prod.swap ∘ (λ(x, y). (f' x, g' y))) y⟧ ⟹ homeomorphism ?X' ?Y' ?f' ?g'›*)) (*goals: 1. ‹(b::'b set) × (a::'a set) = prod.swap ` (a × b)› 2. ‹(c::'c set) × (d::'d set) = c × d› 3. ‹⋀x::'b × 'a. x ∈ prod.swap ` ((a::'a set) × (b::'b set)) ⟹ (case x of (y::'b, x::'a) ⇒ ((f::'a ⇒ 'c) x, (g::'b ⇒ 'd) y)) = ((λ(x::'a, y::'b). (f x, g y)) ∘ prod.swap) x› 4. ‹⋀y::'c × 'd. y ∈ (c::'c set) × (d::'d set) ⟹ (case y of (x::'c, y::'d) ⇒ ((g'::'d ⇒ 'b) y, (f'::'c ⇒ 'a) x)) = (prod.swap ∘ (λ(x::'c, y::'d). (f' x, g' y))) y› discuss goal 1*) apply (simp add: product_swap (*‹prod.swap ` (?A × ?B) = ?B × ?A›*) case_prod_unfold (*‹case_prod = (λc p. c (fst p) (snd p))›*)) (*discuss goal 2*) apply (simp add: product_swap (*‹prod.swap ` (?A × ?B) = ?B × ?A›*) case_prod_unfold (*‹case_prod = (λc p. c (fst p) (snd p))›*)) (*discuss goal 3*) apply (simp add: product_swap (*‹prod.swap ` ((?A::?'b set) × (?B::?'a set)) = ?B × ?A›*) case_prod_unfold (*‹case_prod = (λ(c::?'a ⇒ ?'b ⇒ ?'c) p::?'a × ?'b. c (fst p) (snd p))›*)) (*discuss goal 4*) apply (simp add: product_swap (*‹prod.swap ` (?A × ?B) = ?B × ?A›*) case_prod_unfold (*‹case_prod = (λc p. c (fst p) (snd p))›*)) (*proven 4 subgoals*) . lemma open_swap: "open a ⟹ open (prod.swap ` a)" by (smt (verit) imageE (*‹⟦(?b::?'a::type) ∈ (?f::?'b::type ⇒ ?'a::type) ` (?A::?'b::type set); ⋀x::?'b::type. ⟦?b = ?f x; x ∈ ?A⟧ ⟹ ?thesis::bool⟧ ⟹ ?thesis›*) image_mono (*‹(?A::?'a::type set) ⊆ (?B::?'a::type set) ⟹ (?f::?'a::type ⇒ ?'b::type) ` ?A ⊆ ?f ` ?B›*) open_prod_def (*‹open (?S::(?'a::topological_space × ?'b::topological_space) set) = (∀x::?'a::topological_space × ?'b::topological_space∈?S. ∃(A::?'a::topological_space set) B::?'b::topological_space set. open A ∧ open B ∧ x ∈ A × B ∧ A × B ⊆ ?S)›*) prod.swap_def (*‹prod.swap (?p::?'a::type × ?'b::type) = (snd ?p, fst ?p)›*) product_swap (*‹prod.swap ` ((?A::?'b::type set) × (?B::?'a::type set)) = ?B × ?A›*) swap_simp (*‹prod.swap (?x::?'b::type, ?y::?'a::type) = (?y, ?x)›*)) lemma bounded_linear_swap: assumes f: "bounded_linear f" shows "bounded_linear (f ∘ prod.swap)" proof (standard) (*goals: 1. ‹⋀(b1::'b × 'a) b2::'b × 'a. ((f::'a × 'b ⇒ 'c) ∘ prod.swap) (b1 + b2) = (f ∘ prod.swap) b1 + (f ∘ prod.swap) b2› 2. ‹⋀(r::real) b::'b × 'a. ((f::'a × 'b ⇒ 'c) ∘ prod.swap) (r *⇩R b) = r *⇩R (f ∘ prod.swap) b› 3. ‹∃K::real. ∀x::'b × 'a. norm (((f::'a × 'b ⇒ 'c) ∘ prod.swap) x) ≤ norm x * K›*) interpret f: bounded_linear f by fact fix x :: "'b×'a" and y :: "'b×'a" and r :: real show "(f ∘ prod.swap) (x + y) = (f ∘ prod.swap) x + (f ∘ prod.swap) y" using f.add (*‹f (?b1.0 + ?b2.0) = f ?b1.0 + f ?b2.0›*) by (auto simp add: prod.swap_def (*‹prod.swap (?p::?'a × ?'b) = (snd ?p, fst ?p)›*)) show "(f ∘ prod.swap) (r *⇩R x) = r *⇩R (f ∘ prod.swap) x" using f.scale (*‹f (?r *⇩R ?b) = ?r *⇩R f ?b›*) by (auto simp: prod.swap_def (*‹prod.swap ?p = (snd ?p, fst ?p)›*)) obtain Kf where "0 < Kf" and norm_f: "⋀x. norm (f x) ≤ norm x * Kf" (*goal: ‹(⋀Kf. ⟦0 < Kf; ⋀x. norm (f x) ≤ norm x * Kf⟧ ⟹ thesis) ⟹ thesis›*) using f.pos_bounded (*‹∃K>0::real. ∀x::'a × 'b. norm ((f::'a × 'b ⇒ 'c) x) ≤ norm x * K›*) by fast have "∀x. norm ((f ∘ prod.swap) x) ≤ norm x * Kf" apply (simp add: prod.swap_def (*‹prod.swap ?p = (snd ?p, fst ?p)›*)) (*goal: ‹∀x. norm ((f ∘ prod.swap) x) ≤ norm x * Kf›*) by (metis norm_commute (*‹norm (?x, ?y) = norm (?y, ?x)›*) norm_f (*‹norm (f ?x) ≤ norm ?x * Kf›*)) then show "∃K. ∀x. norm ((f ∘ prod.swap) x) ≤ norm x * K" apply - (*goal: ‹∃K. ∀x. norm ((f ∘ prod.swap) x) ≤ norm x * K›*) by standard qed lemma norm_swap: "norm x = norm (prod.swap x)" using norm_commute (*‹norm (?x, ?y) = norm (?y, ?x)›*) apply (simp add: prod.swap_def (*‹prod.swap ?p = (snd ?p, fst ?p)›*)) (*goal: ‹norm x = norm (prod.swap x)›*) by (smt (verit, ccfv_threshold) norm_commute (*‹norm (?x::?'a, ?y::?'b) = norm (?y, ?x)›*) prod.exhaust_sel (*‹((?prod::?'a × ?'b) = (fst ?prod, snd ?prod) ⟹ ?P::bool) ⟹ ?P›*)) subsubsection ‹Pair is a smooth map (just like fst and snd)› context c_manifold_prod begin sublocale prod_manifold: c_manifold prod_charts k using c_manifold_atlas_product (*‹c_manifold prod_charts k›*) by auto lemma prod_carrier: "prod_manifold.carrier = m1.carrier × m2.carrier" proof (-) (*goal: ‹prod_manifold.carrier = m1.carrier × m2.carrier›*) have "domain ` prod_charts = {domain (prod_chart c1 c2) |c1 c2. c1 ∈ charts1 ∧ c2 ∈ charts2}" unfolding prod_charts_def (*goal: ‹domain ` {prod_chart c1 c2 |c1 c2. c1 ∈ charts1 ∧ c2 ∈ charts2} = {domain (prod_chart c1 c2) |c1 c2. c1 ∈ charts1 ∧ c2 ∈ charts2}›*) by blast also (*calculation: ‹domain ` prod_charts = {domain (prod_chart c1 c2) |c1 c2. c1 ∈ charts1 ∧ c2 ∈ charts2}›*) have "… = {domain c1 × domain c2 |c1 c2. c1 ∈ charts1 ∧ c2 ∈ charts2}" by auto finally (*calculation: ‹domain ` prod_charts = {domain c1 × domain c2 |c1 c2. c1 ∈ charts1 ∧ c2 ∈ charts2}›*) show "?thesis" (*goal: ‹prod_manifold.carrier = m1.carrier × m2.carrier›*) unfolding manifold.carrier_def (*goal: ‹⋃ (domain ` prod_charts) = ⋃ (domain ` charts1) × ⋃ (domain ` charts2)›*) by auto qed (* is this a good name? overlap with manifold.carrier not a problem? *) abbreviation (in c_manifold_prod) "carrier ≡ manifold.carrier prod_charts" lemma diff_fst: shows "diff k prod_charts charts1 fst" proof (standard) (*goal: ‹⋀x. x ∈ carrier ⟹ ∃c1∈prod_manifold.atlas. ∃c2∈m1.atlas. x ∈ domain c1 ∧ fst ` domain c1 ⊆ domain c2 ∧ k-smooth_on (codomain c1) (apply_chart c2 ∘ fst ∘ inv_chart c1)›*) let ?prod_atl = "c_manifold.atlas prod_charts k" fix x assume "x ∈ manifold.carrier prod_charts" (*‹(x::'a × 'c) ∈ carrier›*) then obtain c where c: "x ∈ domain c" "c ∈ prod_charts" (*goal: ‹(⋀c::('a × 'c, 'b × 'd) chart. ⟦(x::'a × 'c) ∈ domain c; c ∈ prod_charts⟧ ⟹ thesis::bool) ⟹ thesis›*) by (meson manifold.carrierE (*‹⟦?x ∈ manifold.carrier ?charts; ⋀c. ⟦c ∈ ?charts; ?x ∈ domain c⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) then obtain c1 and c2 where c12: "c1 ∈ charts1" "c2 ∈ charts2" "c = prod_chart c1 c2" (*goal: ‹(⋀c1 c2. ⟦c1 ∈ charts1; c2 ∈ charts2; c = prod_chart c1 c2⟧ ⟹ thesis) ⟹ thesis›*) using prod_charts_def (*‹prod_charts = {prod_chart c1 c2 |c1 c2. c1 ∈ charts1 ∧ c2 ∈ charts2}›*) by force show "∃c1 ∈ ?prod_atl. ∃c2 ∈ m1.atlas. x ∈ domain c1 ∧ fst ` domain c1 ⊆ domain c2 ∧ k-smooth_on (codomain c1) (apply_chart c2 ∘ fst ∘ inv_chart c1)" proof (intro bexI (*‹⟦?P ?x; ?x ∈ ?A⟧ ⟹ ∃x∈?A. ?P x›*) conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹x ∈ domain ?c1.0› 2. ‹fst ` domain ?c1.0 ⊆ domain ?c2.1› 3. ‹k-smooth_on (codomain ?c1.0) (apply_chart ?c2.1 ∘ fst ∘ inv_chart ?c1.0)› 4. ‹?c2.1 ∈ m1.atlas› 5. ‹?c1.0 ∈ prod_manifold.atlas›*) show "x ∈ domain c" "c ∈ ?prod_atl" "c1 ∈ m1.atlas" (*goals: 1. ‹x ∈ domain c› 2. ‹c ∈ prod_manifold.atlas› 3. ‹c1 ∈ m1.atlas› discuss goal 1*) apply (simp add: c (*‹x ∈ domain c› ‹c ∈ prod_charts›*) c_manifold.in_charts_in_atlas (*‹⟦c_manifold ?charts ?k; ?x ∈ ?charts⟧ ⟹ ?x ∈ c_manifold.atlas ?charts ?k›*) c_manifold_atlas_product (*‹c_manifold prod_charts k›*) c12( (*‹c1 ∈ charts1›*) 1) m1.in_charts_in_atlas (*‹?x ∈ charts1 ⟹ ?x ∈ m1.atlas›*)) (*discuss goal 2*) apply (simp add: c (*‹(x::'a × 'c) ∈ domain (c::('a × 'c, 'b × 'd) chart)› ‹(c::('a × 'c, 'b × 'd) chart) ∈ prod_charts›*) c_manifold.in_charts_in_atlas (*‹⟦c_manifold (?charts::(?'a, ?'b) chart set) (?k::enat); (?x::(?'a, ?'b) chart) ∈ ?charts⟧ ⟹ ?x ∈ c_manifold.atlas ?charts ?k›*) c_manifold_atlas_product (*‹c_manifold prod_charts (k::enat)›*) c12( (*‹(c1::('a, 'b) chart) ∈ (charts1::('a, 'b) chart set)›*) 1) m1.in_charts_in_atlas (*‹(?x::('a, 'b) chart) ∈ (charts1::('a, 'b) chart set) ⟹ ?x ∈ m1.atlas›*)) (*discuss goal 3*) apply (simp add: c (*‹x ∈ domain c› ‹c ∈ prod_charts›*) c_manifold.in_charts_in_atlas (*‹⟦c_manifold ?charts ?k; ?x ∈ ?charts⟧ ⟹ ?x ∈ c_manifold.atlas ?charts ?k›*) c_manifold_atlas_product (*‹c_manifold prod_charts k›*) c12( (*‹c1 ∈ charts1›*) 1) m1.in_charts_in_atlas (*‹?x ∈ charts1 ⟹ ?x ∈ m1.atlas›*)) (*proven 3 subgoals*) . show "fst ` domain c ⊆ domain c1" using domain_prod_chart (*‹domain (prod_chart ?c1.0 ?c2.0) = domain ?c1.0 × domain ?c2.0›*) c12(3) (*‹c = prod_chart c1 c2›*) by auto let ?f = "apply_chart c1 ∘ fst ∘ inv_chart c" let ?g = "λ(x,y). (inv_chart c1 x, inv_chart c2 y)" have 1: "codomain c = codomain c1 × codomain c2" by (simp add: c12( (*‹(c::('a × 'c, 'b × 'd) chart) = prod_chart (c1::('a, 'b) chart) (c2::('c, 'd) chart)›*) 3)) then have 2: "⋀x. x ∈ codomain c ⟹ ?f x = fst x" using c12(3) (*‹c = prod_chart c1 c2›*) by fastforce have "smooth_on (codomain c1 × codomain c2) ?f" by (auto intro!: smooth_on_cong[OF _ _ 2] (*‹⟦?k-smooth_on ?S (λx. fst (?x4 x)); open ?S; ⋀x. x ∈ ?S ⟹ ?x4 x ∈ codomain c⟧ ⟹ ?k-smooth_on ?S (λx. (apply_chart c1 ∘ fst ∘ inv_chart c) (?x4 x))›*) smooth_on_fst (*‹⟦?k-smooth_on ?S ?f; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. fst (?f x))›*) simp only: 1[symmetric] (*‹codomain c1 × codomain c2 = codomain c›*)) then show "k-smooth_on (codomain c) ?f" using "1" (*‹codomain c = codomain c1 × codomain c2›*) smooth_on_le (*‹⟦(?k::enat)-smooth_on (?S::?'a set) (?f::?'a ⇒ ?'b); (?l::enat) ≤ ?k⟧ ⟹ ?l-smooth_on ?S ?f›*) by force qed qed lemma diff_snd: shows "diff k prod_charts charts2 snd" proof (standard) (*goal: ‹⋀x. x ∈ carrier ⟹ ∃c1∈prod_manifold.atlas. ∃c2∈m2.atlas. x ∈ domain c1 ∧ snd ` domain c1 ⊆ domain c2 ∧ k-smooth_on (codomain c1) (apply_chart c2 ∘ snd ∘ inv_chart c1)›*) let ?prod_atl = "c_manifold.atlas prod_charts k" fix x assume "x ∈ manifold.carrier prod_charts" (*‹(x::'a × 'c) ∈ carrier›*) then obtain c where "x ∈ domain c" "c ∈ prod_charts" (*goal: ‹(⋀c::('a × 'c, 'b × 'd) chart. ⟦(x::'a × 'c) ∈ domain c; c ∈ prod_charts⟧ ⟹ thesis::bool) ⟹ thesis›*) by (meson manifold.carrierE (*‹⟦?x ∈ manifold.carrier ?charts; ⋀c. ⟦c ∈ ?charts; ?x ∈ domain c⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) then obtain c1 and c2 where "c = prod_chart c1 c2" "c1 ∈ charts1" "c2 ∈ charts2" (*goal: ‹(⋀c1 c2. ⟦c = prod_chart c1 c2; c1 ∈ charts1; c2 ∈ charts2⟧ ⟹ thesis) ⟹ thesis›*) using prod_charts_def (*‹prod_charts = {prod_chart c1 c2 |c1 c2. c1 ∈ charts1 ∧ c2 ∈ charts2}›*) by force show "∃c1 ∈ ?prod_atl. ∃c2 ∈ m2.atlas. x ∈ domain c1 ∧ snd ` domain c1 ⊆ domain c2 ∧ k-smooth_on (codomain c1) (apply_chart c2 ∘ snd ∘ inv_chart c1)" proof (intro bexI (*‹⟦?P ?x; ?x ∈ ?A⟧ ⟹ ∃x∈?A. ?P x›*), intro conjI (*‹⟦?P::bool; ?Q::bool⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹x ∈ domain ?c1.0› 2. ‹snd ` domain ?c1.0 ⊆ domain ?c2.1› 3. ‹k-smooth_on (codomain ?c1.0) (apply_chart ?c2.1 ∘ snd ∘ inv_chart ?c1.0)› 4. ‹?c2.1 ∈ m2.atlas› 5. ‹?c1.0 ∈ prod_manifold.atlas›*) show "x ∈ domain c" by (simp add: ‹x ∈ domain c›) show "c2 ∈ m2.atlas" by (simp add: ‹c2 ∈ charts2› m2.in_charts_in_atlas (*‹?x ∈ charts2 ⟹ ?x ∈ m2.atlas›*)) show "snd ` domain c ⊆ domain c2" using ‹c = prod_chart c1 c2› (*‹c = prod_chart c1 c2›*) by simp show "c ∈ ?prod_atl" by (simp add: ‹c ∈ prod_charts› c_manifold.in_charts_in_atlas (*‹⟦c_manifold ?charts ?k; ?x ∈ ?charts⟧ ⟹ ?x ∈ c_manifold.atlas ?charts ?k›*) c_manifold_atlas_product (*‹c_manifold prod_charts k›*)) let ?f = "apply_chart c2 ∘ snd ∘ inv_chart c" have 1: "codomain c = codomain c1 × codomain c2" by (simp add: ‹c = prod_chart c1 c2›) have 2: "⋀x. x ∈ codomain c ⟹ ?f x = snd x" using "1" (*‹codomain c = codomain c1 × codomain c2›*) ‹c = prod_chart c1 c2› (*‹c = prod_chart c1 c2›*) by fastforce have "smooth_on (codomain c1 × codomain c2) ?f" using "1" (*‹codomain c = codomain c1 × codomain c2›*) "2" (*‹?x3 ∈ codomain c ⟹ (apply_chart c2 ∘ snd ∘ inv_chart c) ?x3 = snd ?x3›*) smooth_on_snd (*‹⟦?k-smooth_on ?S ?f; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. snd (?f x))›*) smooth_on_id (*‹?k-smooth_on ?S (λx. x)›*) open_codomain (*‹open (codomain ?c)›*) smooth_on_cong (*‹⟦(?k::enat)-smooth_on (?S::?'a set) (?g::?'a ⇒ ?'b); open ?S; ⋀x::?'a. x ∈ ?S ⟹ (?f::?'a ⇒ ?'b) x = ?g x⟧ ⟹ ?k-smooth_on ?S ?f›*) by (smt (verit, ccfv_threshold)) then show "k-smooth_on (codomain c) ?f" using "1" (*‹codomain c = codomain c1 × codomain c2›*) smooth_on_le (*‹⟦(?k::enat)-smooth_on (?S::?'a::real_normed_vector set) (?f::?'a::real_normed_vector ⇒ ?'b::real_normed_vector); (?l::enat) ≤ ?k⟧ ⟹ ?l-smooth_on ?S ?f›*) by force qed qed lemma prod_chartsI: assumes "c1 ∈ charts1" "c2 ∈ charts2" shows "prod_chart c1 c2 ∈ prod_charts" unfolding prod_charts_def (*goal: ‹prod_chart c1 c2 ∈ {prod_chart c1 c2 |c1 c2. c1 ∈ charts1 ∧ c2 ∈ charts2}›*) using assms (*‹c1 ∈ charts1› ‹(c2::('c, 'd) chart) ∈ (charts2::('c, 'd) chart set)›*) by auto lemma prod_chart_in_atlas: assumes "c1 ∈ charts1" "c2 ∈ charts2" shows "prod_chart c1 c2 ∈ prod_manifold.atlas" using prod_chartsI (*‹⟦?c1.0 ∈ charts1; ?c2.0 ∈ charts2⟧ ⟹ prod_chart ?c1.0 ?c2.0 ∈ prod_charts›*) prod_manifold.in_charts_in_atlas (*‹?x ∈ prod_charts ⟹ ?x ∈ prod_manifold.atlas›*) assms (*‹(c1::('a, 'b) chart) ∈ (charts1::('a, 'b) chart set)› ‹c2 ∈ charts2›*) by simp text ‹This next lemma is in \<^locale>‹c_manifolds›, rather than \<^locale>‹c_manifold_prod›, so that we can pick and choose the charts it applies to later.› lemma (in c_manifolds) diff_const: "diff k charts1 charts2 (λz. x)" if "x ∈ dest.carrier" apply unfold_locales (*goal: ‹diff k charts1 charts2 (λz. x)›*) apply auto (*goal: ‹⋀xa. xa ∈ src.carrier ⟹ ∃c1∈src.atlas. ∃c2∈dest.atlas. xa ∈ domain c1 ∧ (λz. x) ` domain c1 ⊆ domain c2 ∧ k-smooth_on (codomain c1) (apply_chart c2 ∘ (λz. x) ∘ inv_chart c1)›*) by (metis dest.atlasE (*‹⟦?x ∈ dest.carrier; ⋀c. ⟦c ∈ dest.atlas; ?x ∈ domain c⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) image_subsetI (*‹(⋀x. x ∈ ?A ⟹ ?f x ∈ ?B) ⟹ ?f ` ?A ⊆ ?B›*) smooth_on_const (*‹?k-smooth_on ?S (λx. ?c)›*) src.atlasE (*‹⟦?x ∈ src.carrier; ⋀c. ⟦c ∈ src.atlas; ?x ∈ domain c⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) that (*‹x ∈ dest.carrier›*)) lemma diff_Pair: assumes m3: "c_manifold charts3 k" and diff_f: "diff k charts3 charts1 f" and diff_g: "diff k charts3 charts2 g" shows "diff k charts3 prod_charts (λx. (f x, g x))" proof (unfold_locales) (*goals: 1. ‹⋀c1 c2. ⟦c1 ∈ charts3; c2 ∈ charts3⟧ ⟹ k-smooth_compat c1 c2› 2. ‹⋀x. x ∈ manifold.carrier charts3 ⟹ ∃c1∈c_manifold.atlas charts3 k. ∃c2∈prod_manifold.atlas. x ∈ domain c1 ∧ (λx. (f x, g x)) ` domain c1 ⊆ domain c2 ∧ k-smooth_on (codomain c1) (apply_chart c2 ∘ (λx. (f x, g x)) ∘ inv_chart c1)›*) show "c1 ∈ charts3 ⟹ c2 ∈ charts3 ⟹ k-smooth_compat c1 c2" for c1 and c2 using c_manifold.pairwise_compat[OF m3] (*‹⟦(?c1.0::('e, 'f) chart) ∈ (charts3::('e, 'f) chart set); (?c2.0::('e, 'f) chart) ∈ charts3⟧ ⟹ (k::enat)-smooth_compat ?c1.0 ?c2.0›*) . let ?prod_atl = prod_manifold.atlas let ?atl3 = "c_manifold.atlas charts3 k" let ?m3 = "manifold.carrier charts3" fix x assume x[simp]: "x ∈ ?m3" (*‹(x::'e) ∈ manifold.carrier (charts3::('e, 'f) chart set)›*) obtain c1 and c2 where c1[simp]: "c1 ∈ charts1" "f x ∈ domain c1" and c2[simp]: "c2 ∈ charts2" "g x ∈ domain c2" (*goal: ‹(⋀c1 c2. ⟦c1 ∈ charts1; f x ∈ domain c1; c2 ∈ charts2; g x ∈ domain c2⟧ ⟹ thesis) ⟹ thesis›*) using manifold.carrierE (*‹⟦?x ∈ manifold.carrier ?charts; ⋀c. ⟦c ∈ ?charts; ?x ∈ domain c⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) x (*‹x ∈ manifold.carrier charts3›*) diff.defined (*‹diff ?k ?charts1.0 ?charts2.0 ?f ⟹ ?f ` manifold.carrier ?charts1.0 ⊆ manifold.carrier ?charts2.0›*) diff_f (*‹diff (k::enat) (charts3::('e::{second_countable_topology,t2_space}, 'f::euclidean_space) chart set) (charts1::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart set) (f::'e::{second_countable_topology,t2_space} ⇒ 'a::{second_countable_topology,t2_space})›*) diff_g (*‹diff k charts3 charts2 g›*) by (metis image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*)) obtain c3' where c3': "c3' ∈ charts3" "x ∈ domain c3'" (*goal: ‹(⋀c3'. ⟦c3' ∈ charts3; x ∈ domain c3'⟧ ⟹ thesis) ⟹ thesis›*) using x (*‹x ∈ manifold.carrier charts3›*) manifold.carrierE (*‹⟦?x ∈ manifold.carrier ?charts; ⋀c. ⟦c ∈ ?charts; ?x ∈ domain c⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) m3 (*‹c_manifold charts3 k›*) by blast have open_int_f_g: "open ((f -` domain c1) ∩ (g -` domain c2) ∩ ?m3)" using diff_f (*‹diff (k::enat) (charts3::('e, 'f) chart set) (charts1::('a, 'b) chart set) (f::'e ⇒ 'a)›*) diff.continuous_on (*‹diff ?k ?charts1.0 ?charts2.0 ?f ⟹ continuous_on (manifold.carrier ?charts1.0) ?f›*) diff_g (*‹diff k charts3 charts2 g›*) open_domain (*‹open (domain ?c)›*) manifold.open_carrier (*‹open (manifold.carrier ?charts)›*) open_continuous_vimage (*‹⟦open ?s; continuous_on ?s ?f; open ?B⟧ ⟹ open (?f -` ?B ∩ ?s)›*) by (metis (no_types, lifting) Int_lower2 (*‹?A ∩ ?B ⊆ ?B›*) inf.absorb_iff2 (*‹(?b ≤ ?a) = (inf ?a ?b = ?b)›*) inf_assoc (*‹inf (inf ?x ?y) ?z = inf ?x (inf ?y ?z)›*) open_Int (*‹⟦open ?S; open ?T⟧ ⟹ open (?S ∩ ?T)›*)) then obtain c3 where c3: "c3 ∈ ?atl3" "x ∈ domain c3" "c3 = restrict_chart ((f -` domain c1) ∩ (g -` domain c2) ∩ ?m3) c3'" (*goal: ‹(⋀c3. ⟦c3 ∈ c_manifold.atlas charts3 k; x ∈ domain c3; c3 = restrict_chart (f -` domain c1 ∩ g -` domain c2 ∩ manifold.carrier charts3) c3'⟧ ⟹ thesis) ⟹ thesis›*) by (simp add: c3' (*‹c3' ∈ charts3› ‹x ∈ domain c3'›*) c_manifold.in_charts_in_atlas (*‹⟦c_manifold ?charts ?k; ?x ∈ ?charts⟧ ⟹ ?x ∈ c_manifold.atlas ?charts ?k›*) c_manifold.restrict_chart_in_atlas (*‹⟦c_manifold ?charts ?k; ?c ∈ c_manifold.atlas ?charts ?k⟧ ⟹ restrict_chart ?S ?c ∈ c_manifold.atlas ?charts ?k›*) m3 (*‹c_manifold charts3 k›*)) have c3_simps[simp]: "domain c3 = (f -` domain c1) ∩ (g -` domain c2) ∩ ?m3 ∩ domain c3'" "codomain c3 = codomain c3' ∩ inv_chart c3' -` ((f -` domain c1) ∩ (g -` domain c2) ∩ ?m3 ∩ domain c3')" "apply_chart c3 = c3'" "inv_chart c3 = inv_chart c3'" using open_int_f_g (*‹open (f -` domain c1 ∩ g -` domain c2 ∩ manifold.carrier charts3)›*) c3 (*‹c3 ∈ c_manifold.atlas charts3 k› ‹(x::'e) ∈ domain (c3::('e, 'f) chart)› ‹(c3::('e::{second_countable_topology,t2_space}, 'f::euclidean_space) chart) = restrict_chart ((f::'e::{second_countable_topology,t2_space} ⇒ 'a::{second_countable_topology,t2_space}) -` domain (c1::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart) ∩ (g::'e::{second_countable_topology,t2_space} ⇒ 'c::{second_countable_topology,t2_space}) -` domain (c2::('c::{second_countable_topology,t2_space}, 'd::euclidean_space) chart) ∩ manifold.carrier (charts3::('e::{second_countable_topology,t2_space}, 'f::euclidean_space) chart set)) (c3'::('e::{second_countable_topology,t2_space}, 'f::euclidean_space) chart)›*) apply - (*goals: 1. ‹⟦open ((f::'e::{second_countable_topology,t2_space} ⇒ 'a::{second_countable_topology,t2_space}) -` domain (c1::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart) ∩ (g::'e::{second_countable_topology,t2_space} ⇒ 'c::{second_countable_topology,t2_space}) -` domain (c2::('c::{second_countable_topology,t2_space}, 'd::euclidean_space) chart) ∩ manifold.carrier (charts3::('e::{second_countable_topology,t2_space}, 'f::euclidean_space) chart set)); (c3::('e::{second_countable_topology,t2_space}, 'f::euclidean_space) chart) ∈ c_manifold.atlas charts3 (k::enat); (x::'e::{second_countable_topology,t2_space}) ∈ domain c3; c3 = restrict_chart (f -` domain c1 ∩ g -` domain c2 ∩ manifold.carrier charts3) (c3'::('e::{second_countable_topology,t2_space}, 'f::euclidean_space) chart)⟧ ⟹ domain c3 = f -` domain c1 ∩ g -` domain c2 ∩ manifold.carrier charts3 ∩ domain c3'› 2. ‹⟦open ((f::'e::{second_countable_topology,t2_space} ⇒ 'a::{second_countable_topology,t2_space}) -` domain (c1::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart) ∩ (g::'e::{second_countable_topology,t2_space} ⇒ 'c::{second_countable_topology,t2_space}) -` domain (c2::('c::{second_countable_topology,t2_space}, 'd::euclidean_space) chart) ∩ manifold.carrier (charts3::('e::{second_countable_topology,t2_space}, 'f::euclidean_space) chart set)); (c3::('e::{second_countable_topology,t2_space}, 'f::euclidean_space) chart) ∈ c_manifold.atlas charts3 (k::enat); (x::'e::{second_countable_topology,t2_space}) ∈ domain c3; c3 = restrict_chart (f -` domain c1 ∩ g -` domain c2 ∩ manifold.carrier charts3) (c3'::('e::{second_countable_topology,t2_space}, 'f::euclidean_space) chart)⟧ ⟹ codomain c3 = codomain c3' ∩ inv_chart c3' -` (f -` domain c1 ∩ g -` domain c2 ∩ manifold.carrier charts3 ∩ domain c3')› 3. ‹⟦open ((f::'e::{second_countable_topology,t2_space} ⇒ 'a::{second_countable_topology,t2_space}) -` domain (c1::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart) ∩ (g::'e::{second_countable_topology,t2_space} ⇒ 'c::{second_countable_topology,t2_space}) -` domain (c2::('c::{second_countable_topology,t2_space}, 'd::euclidean_space) chart) ∩ manifold.carrier (charts3::('e::{second_countable_topology,t2_space}, 'f::euclidean_space) chart set)); (c3::('e::{second_countable_topology,t2_space}, 'f::euclidean_space) chart) ∈ c_manifold.atlas charts3 (k::enat); (x::'e::{second_countable_topology,t2_space}) ∈ domain c3; c3 = restrict_chart (f -` domain c1 ∩ g -` domain c2 ∩ manifold.carrier charts3) (c3'::('e::{second_countable_topology,t2_space}, 'f::euclidean_space) chart)⟧ ⟹ apply_chart c3 = apply_chart c3'› 4. ‹⟦open ((f::'e::{second_countable_topology,t2_space} ⇒ 'a::{second_countable_topology,t2_space}) -` domain (c1::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart) ∩ (g::'e::{second_countable_topology,t2_space} ⇒ 'c::{second_countable_topology,t2_space}) -` domain (c2::('c::{second_countable_topology,t2_space}, 'd::euclidean_space) chart) ∩ manifold.carrier (charts3::('e::{second_countable_topology,t2_space}, 'f::euclidean_space) chart set)); (c3::('e::{second_countable_topology,t2_space}, 'f::euclidean_space) chart) ∈ c_manifold.atlas charts3 (k::enat); (x::'e::{second_countable_topology,t2_space}) ∈ domain c3; c3 = restrict_chart (f -` domain c1 ∩ g -` domain c2 ∩ manifold.carrier charts3) (c3'::('e::{second_countable_topology,t2_space}, 'f::euclidean_space) chart)⟧ ⟹ inv_chart c3 = inv_chart c3'› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . let ?c = "prod_chart c1 c2" show "∃c3 ∈ ?atl3. ∃c ∈ ?prod_atl. x ∈ domain c3 ∧ (λx. (f x, g x)) ` domain c3 ⊆ domain c ∧ k-smooth_on (codomain c3) (c ∘ (λx. (f x, g x)) ∘ inv_chart c3)" proof (intro bexI (*‹⟦?P ?x; ?x ∈ ?A⟧ ⟹ ∃x∈?A. ?P x›*), intro conjI (*‹⟦?P::bool; ?Q::bool⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹x ∈ domain ?c3.0› 2. ‹(λx. (f x, g x)) ` domain ?c3.0 ⊆ domain ?c1› 3. ‹k-smooth_on (codomain ?c3.0) (apply_chart ?c1 ∘ (λx. (f x, g x)) ∘ inv_chart ?c3.0)› 4. ‹?c1 ∈ prod_manifold.atlas› 5. ‹?c3.0 ∈ c_manifold.atlas charts3 k›*) show "?c ∈ ?prod_atl" using prod_chart_in_atlas (*‹⟦?c1.0 ∈ charts1; ?c2.0 ∈ charts2⟧ ⟹ prod_chart ?c1.0 ?c2.0 ∈ prod_manifold.atlas›*) by simp show "c3 ∈ ?atl3" "x ∈ domain c3" using c3(1,2) (*‹(c3::('e, 'f) chart) ∈ c_manifold.atlas (charts3::('e, 'f) chart set) (k::enat)› ‹(x::'e::{second_countable_topology,t2_space}) ∈ domain (c3::('e::{second_countable_topology,t2_space}, 'f::euclidean_space) chart)›*) apply - (*goals: 1. ‹⟦c3 ∈ c_manifold.atlas charts3 k; x ∈ domain c3⟧ ⟹ c3 ∈ c_manifold.atlas charts3 k› 2. ‹⟦c3 ∈ c_manifold.atlas charts3 k; x ∈ domain c3⟧ ⟹ x ∈ domain c3› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) show "(λx. (f x, g x)) ` domain c3 ⊆ domain (prod_chart c1 c2)" by (auto simp: open_int_f_g (*‹open (f -` domain c1 ∩ g -` domain c2 ∩ manifold.carrier charts3)›*)) let ?f = "apply_chart ?c ∘ (λx. (f x, g x)) ∘ inv_chart c3" have unfold_f: "⋀y. y ∈ codomain c3 ⟹ ?f y = (c1 (f (inv_chart c3 y)), c2 (g (inv_chart c3 y)))" by fastforce have comp_cong[simp]: "(c1 ∘ f ∘ inv_chart c3) z = (λy. c1 (f (inv_chart c3 y))) z" "(c2 ∘ g ∘ inv_chart c3) z = (λy. c2 (g (inv_chart c3 y))) z" if "z ∈ codomain c3" for z (*goals: 1. ‹(apply_chart c1 ∘ f ∘ inv_chart c3) z = apply_chart c1 (f (inv_chart c3 z))› 2. ‹(apply_chart c2 ∘ g ∘ inv_chart c3) z = apply_chart c2 (g (inv_chart c3 z))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have open_c3: "open (codomain c3)" by (simp add: c3 (*‹c3 ∈ c_manifold.atlas charts3 k› ‹x ∈ domain c3› ‹c3 = restrict_chart (f -` domain c1 ∩ g -` domain c2 ∩ manifold.carrier charts3) c3'›*)) moreover have "k-smooth_on (codomain c3) (λy. apply_chart c1 (f (inv_chart c3 y)))" apply (rule smooth_on_cong(1)[OF _ open_c3 comp_cong(1)[symmetric]] (*‹⟦?k-smooth_on (codomain c3) (λx. (apply_chart c1 ∘ f ∘ inv_chart c3) (?z1 x)); ⋀x. x ∈ codomain c3 ⟹ ?z1 x ∈ codomain c3⟧ ⟹ ?k-smooth_on (codomain c3) (λx. apply_chart c1 (f (inv_chart c3 (?z1 x))))›*)) (*goals: 1. ‹(k::enat)-smooth_on (codomain (c3::('e::{second_countable_topology,t2_space}, 'f::euclidean_space) chart)) (apply_chart (c1::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart) ∘ (f::'e::{second_countable_topology,t2_space} ⇒ 'a::{second_countable_topology,t2_space}) ∘ inv_chart c3)› 2. ‹⋀y::'f::euclidean_space. y ∈ codomain (c3::('e::{second_countable_topology,t2_space}, 'f::euclidean_space) chart) ⟹ y ∈ codomain c3› discuss goal 1*) apply (rule smooth_on_cong'[OF diff.diff_chartsD[OF diff_f c3(1) m1.in_charts_in_atlas[OF c1(1)]]] (*‹?S = codomain c3 ∩ inv_chart c3 -` (manifold.carrier charts3 ∩ f -` domain c1) ⟹ k-smooth_on ?S (apply_chart c1 ∘ f ∘ inv_chart c3)›*)) (*top goal: ‹k-smooth_on (codomain c3) (apply_chart c1 ∘ f ∘ inv_chart c3)› and 1 goal remains*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . moreover have "k-smooth_on (codomain c3) (λy. apply_chart c2 (g (inv_chart c3 y)))" apply (rule smooth_on_cong(1)[OF _ open_c3 comp_cong(2)[symmetric]] (*‹⟦?k-smooth_on (codomain c3) (λx. (apply_chart c2 ∘ g ∘ inv_chart c3) (?z1 x)); ⋀x. x ∈ codomain c3 ⟹ ?z1 x ∈ codomain c3⟧ ⟹ ?k-smooth_on (codomain c3) (λx. apply_chart c2 (g (inv_chart c3 (?z1 x))))›*)) (*goals: 1. ‹k-smooth_on (codomain c3) (apply_chart c2 ∘ g ∘ inv_chart c3)› 2. ‹⋀y. y ∈ codomain c3 ⟹ y ∈ codomain c3› discuss goal 1*) apply (rule smooth_on_cong'[OF diff.diff_chartsD[OF diff_g c3(1) m2.in_charts_in_atlas[OF c2(1)]]] (*‹?S = codomain c3 ∩ inv_chart c3 -` (manifold.carrier charts3 ∩ g -` domain c2) ⟹ k-smooth_on ?S (apply_chart c2 ∘ g ∘ inv_chart c3)›*)) (*top goal: ‹k-smooth_on (codomain c3) (apply_chart c2 ∘ g ∘ inv_chart c3)› and 1 goal remains*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . ultimately show "k-smooth_on (codomain c3) ?f" using smooth_on_Pair (*‹⟦open ?S; ?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g⟧ ⟹ ?k-smooth_on ?S (λx. (?f x, ?g x))›*) smooth_on_cong (*‹⟦?k-smooth_on ?S ?g; open ?S; ⋀x. x ∈ ?S ⟹ ?f x = ?g x⟧ ⟹ ?k-smooth_on ?S ?f›*) unfold_f (*‹(?y3::'f) ∈ codomain (c3::('e, 'f) chart) ⟹ (apply_chart (prod_chart (c1::('a, 'b) chart) (c2::('c, 'd) chart)) ∘ (λx::'e. ((f::'e ⇒ 'a) x, (g::'e ⇒ 'c) x)) ∘ inv_chart c3) ?y3 = (apply_chart c1 (f (inv_chart c3 ?y3)), apply_chart c2 (g (inv_chart c3 ?y3)))›*) by blast qed qed lemma diff_Pair': assumes m3: "c_manifold charts3 k" and diff_f: "diff k charts3 charts1 (fst∘f)" and diff_g: "diff k charts3 charts2 (snd∘f)" shows "diff k charts3 prod_charts f" using diff_Pair[OF assms] (*‹diff k charts3 prod_charts (λx. ((fst ∘ f) x, (snd ∘ f) x))›*) by simp lemma diff_left_Pair: "diff k charts2 prod_charts (λy. (x,y))" if "x ∈ m1.carrier" using diff_Pair[of charts2 "λz. x" id] (*‹⟦c_manifold charts2 k; diff k charts2 charts1 (λz. x); diff k charts2 charts2 id⟧ ⟹ diff k charts2 prod_charts (λxa. (x, id xa))›*) using c_manifold_prod_axioms (*‹c_manifold_prod k charts1 charts2›*) unfolding c_manifold_prod_def (*goal: ‹diff k charts2 prod_charts (Pair x)›*) using c_manifolds.diff_const[of k charts2 charts1 x] (*‹⟦c_manifolds k charts2 charts1; x ∈ m1.carrier⟧ ⟹ diff k charts2 charts1 (λz. x)›*) unfolding c_manifolds_def (*goal: ‹diff (k::enat) (charts2::('c, 'd) chart set) prod_charts (Pair (x::'a))›*) using m2.diff_id (*‹diff k charts2 charts2 (λx. x)›*) by (simp add: diff.diff_cong (*‹⟦diff ?k ?charts1.0 ?charts2.0 ?f; ⋀x. x ∈ manifold.carrier ?charts1.0 ⟹ ?f x = ?g x⟧ ⟹ diff ?k ?charts1.0 ?charts2.0 ?g›*) that (*‹x ∈ m1.carrier›*)) lemma diff_right_Pair: "diff k charts1 prod_charts (λx. (x,y))" if "y ∈ m2.carrier" using diff_Pair[of charts1 id "λz. y"] (*‹⟦c_manifold (charts1::('a, 'b) chart set) (k::enat); diff k charts1 charts1 id; diff k charts1 (charts2::('c, 'd) chart set) (λz::'a. y::'c)⟧ ⟹ diff k charts1 prod_charts (λx::'a. (id x, y))›*) using c_manifold_prod_axioms (*‹c_manifold_prod k charts1 charts2›*) unfolding c_manifold_prod_def (*goal: ‹diff k charts1 prod_charts (λx. (x, y))›*) using c_manifolds.diff_const[of k charts1 charts2 y] (*‹⟦c_manifolds (k::enat) (charts1::('a, 'b) chart set) (charts2::('c, 'd) chart set); (y::'c) ∈ m2.carrier⟧ ⟹ diff k charts1 charts2 (λz::'a. y)›*) unfolding c_manifolds_def (*goal: ‹diff k charts1 prod_charts (λx. (x, y))›*) using m1.diff_id (*‹diff (k::enat) (charts1::('a, 'b) chart set) charts1 (λx::'a. x)›*) by (simp add: diff.diff_cong (*‹⟦diff (?k::enat) (?charts1.0::(?'a, ?'e) chart set) (?charts2.0::(?'b, ?'f) chart set) (?f::?'a ⇒ ?'b); ⋀x::?'a. x ∈ manifold.carrier ?charts1.0 ⟹ ?f x = (?g::?'a ⇒ ?'b) x⟧ ⟹ diff ?k ?charts1.0 ?charts2.0 ?g›*) that (*‹(y::'c) ∈ m2.carrier›*)) lemma (in c_manifold) diff_on_sqr_Pair: "diff k charts (c_manifold_prod.prod_charts charts charts) (λx. (f x, g x))" if "diff k charts charts f" "diff k charts charts g" using c_manifold_prod.diff_Pair[OF _ _ that] (*‹⟦c_manifold_prod k charts charts; c_manifold charts k⟧ ⟹ diff k charts (c_manifold_prod.prod_charts charts charts) (λx. (f x, g x))›*) by (simp add: c_manifold_axioms (*‹c_manifold (charts::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart set) (k::enat)›*) c_manifold_prod.intro (*‹⟦c_manifold (?charts1.0::(?'a::{second_countable_topology,t2_space}, ?'b::euclidean_space) chart set) (?k::enat); c_manifold (?charts2.0::(?'c::{second_countable_topology,t2_space}, ?'d::euclidean_space) chart set) ?k⟧ ⟹ c_manifold_prod ?k ?charts1.0 ?charts2.0›*)) end (* context c_manifold_prod *) lemma smooth_on_Pair': "k-smooth_on S f" if "open S" "k-smooth_on S (fst∘f)" "k-smooth_on S (snd∘f)" for f::"_::euclidean_space⇒_" and g::"_::euclidean_space⇒_" using smooth_on_Pair[OF that] (*‹k-smooth_on S (λx. ((fst ∘ f) x, (snd ∘ f) x))›*) by simp subsubsection ‹Some results about Euclidean manifolds and their products.› abbreviation prod_chart_eucl::"('a×'a,'a×'a::euclidean_space)chart" where "prod_chart_eucl ≡ c_manifold_prod.prod_chart chart_eucl chart_eucl" abbreviation prod_charts_eucl where "prod_charts_eucl ≡ c_manifold_prod.prod_charts charts_eucl charts_eucl" lemma eucl_makes_product_manifold: "c_manifold_prod ∞ charts_eucl charts_eucl" by (simp add: c_manifold_prod.intro (*‹⟦c_manifold ?charts1.0 ?k; c_manifold ?charts2.0 ?k⟧ ⟹ c_manifold_prod ?k ?charts1.0 ?charts2.0›*) manifold_eucl.c_manifold_axioms (*‹c_manifold charts_eucl ?k›*)) lemma prod_chart_in_prod_charts: "prod_chart_eucl ∈ prod_charts_eucl" using c_manifold_prod.prod_chartsI (*‹⟦c_manifold_prod ?k ?charts1.0 ?charts2.0; ?c1.0 ∈ ?charts1.0; ?c2.0 ∈ ?charts2.0⟧ ⟹ c_manifold_prod.prod_chart ?c1.0 ?c2.0 ∈ c_manifold_prod.prod_charts ?charts1.0 ?charts2.0›*) eucl_makes_product_manifold (*‹c_manifold_prod ∞ charts_eucl charts_eucl›*) by blast lemma chart_eucl_id: "apply_chart chart_eucl = (λx. x)" by simp lemma inv_prod_chart_eucl_id: "inv_chart prod_chart_eucl = (λ(x,y). (x,y))" using c_manifold_prod.inv_chart_prod_chart[OF eucl_makes_product_manifold] (*‹inv_chart (c_manifold_prod.prod_chart (?c1.0::(?'b::euclidean_space, ?'b::euclidean_space) chart) (?c2.0::(?'d::euclidean_space, ?'d::euclidean_space) chart)) = (λ(x::?'b::euclidean_space, y::?'d::euclidean_space). (inv_chart ?c1.0 x, inv_chart ?c2.0 y))›*) by (simp add: ‹⋀c2 c1. inv_chart (c_manifold_prod.prod_chart c1 c2) = (λ(x, y). (inv_chart c1 x, inv_chart c2 y))›) lemma map_fun_eucl_prod_id_f: "apply_chart chart_eucl ∘ f ∘ inv_chart (prod_chart_eucl) = f" proof (-) (*goal: ‹apply_chart chart_eucl ∘ (f::'a::euclidean_space × 'a::euclidean_space ⇒ 'b::euclidean_space) ∘ inv_chart prod_chart_eucl = f›*) have "apply_chart chart_eucl ∘ f = f" using chart_eucl_id (*‹apply_chart chart_eucl = (λx. x)›*) by auto thus "apply_chart chart_eucl ∘ f ∘ inv_chart (prod_chart_eucl) = f" using inv_prod_chart_eucl_id (*‹inv_chart prod_chart_eucl = (λ(x, y). (x, y))›*) by (metis case_prod_Pair (*‹(λ(x, y). (x, y)) = id›*) comp_id (*‹?f ∘ id = ?f›*)) qed lemma map_fun_eucl_id_f: "apply_chart chart_eucl ∘ f ∘ inv_chart (chart_eucl) = f" by auto lemma map_fun_eucl_prod_id: "map_fun (inv_chart (prod_chart_eucl)) (apply_chart chart_eucl) = id" unfolding map_fun_def (*goal: ‹(λh. apply_chart chart_eucl ∘ h ∘ inv_chart prod_chart_eucl) = id›*) using map_fun_eucl_prod_id_f (*‹apply_chart chart_eucl ∘ ?f ∘ inv_chart prod_chart_eucl = ?f›*) eq_id_iff (*‹(∀x. ?f x = x) = (?f = id)›*) by auto text ‹Maps that are at least \<^term>‹diff 1› between Euclidean spaces in the manifold-sense, are differentiable in the usual real analysis sense.› lemma diff_eucl_differentiable: fixes charts_eucl1 :: "('a::euclidean_space, 'a) chart set" and charts_eucl2 :: "('b::euclidean_space, 'b) chart set" defines "charts_eucl1 ≡ charts_eucl" and "charts_eucl2 ≡ charts_eucl" assumes "diff 1 charts_eucl1 charts_eucl2 f" "x ∈ manifold.carrier charts_eucl1" shows "f differentiable at x" proof (-) (*goal: ‹f differentiable at x›*) interpret eucl1: c_manifold charts_eucl1 1 using charts_eucl1_def (*‹charts_eucl1 ≡ charts_eucl›*) c1_manifold_atlas_eucl (*‹c_manifold charts_eucl ?k›*) by auto interpret eucl2: c_manifold charts_eucl2 1 using charts_eucl2_def (*‹charts_eucl2 ≡ charts_eucl›*) c1_manifold_atlas_eucl (*‹c_manifold charts_eucl (?k::enat)›*) by auto text ‹First, obtain some charts in which we know f is differentiable in the real analysis sense.› obtain c1' and c2' where c1': "c1' ∈ eucl1.atlas" "x ∈ domain c1'" and c2': "c2' ∈ eucl2.atlas" "f ` domain c1' ⊆ domain c2'" and f': "1-smooth_on (codomain c1') (c2' ∘ f ∘ inv_chart c1')" (*goal: ‹(⋀c1' c2'. ⟦c1' ∈ eucl1.atlas; x ∈ domain c1'; c2' ∈ eucl2.atlas; f ` domain c1' ⊆ domain c2'; 1-smooth_on (codomain c1') (apply_chart c2' ∘ f ∘ inv_chart c1')⟧ ⟹ thesis) ⟹ thesis›*) using assms (*‹charts_eucl1 ≡ charts_eucl› ‹charts_eucl2 ≡ charts_eucl› ‹diff 1 charts_eucl1 charts_eucl2 f› ‹(x::'a::euclidean_space) ∈ eucl1.carrier›*) unfolding diff_def diff_axioms_def (*goal: ‹(⋀c1' c2'. ⟦c1' ∈ eucl1.atlas; x ∈ domain c1'; c2' ∈ eucl2.atlas; f ` domain c1' ⊆ domain c2'; 1-smooth_on (codomain c1') (apply_chart c2' ∘ f ∘ inv_chart c1')⟧ ⟹ thesis) ⟹ thesis›*) by blast text ‹Then show that smooth compatibility preserves this property in the \<^term>‹charts_eucl› (the identity).› obtain c1 and c2 where c_eucl: "c1 = chart_eucl" "c1 ∈ charts_eucl1" "c2 = chart_eucl" "c2 ∈ charts_eucl2" (*goal: ‹(⋀c1 c2. ⟦c1 = chart_eucl; c1 ∈ charts_eucl1; c2 = chart_eucl; c2 ∈ charts_eucl2⟧ ⟹ thesis) ⟹ thesis›*) by (simp add: charts_eucl1_def (*‹charts_eucl1 ≡ charts_eucl›*) charts_eucl2_def (*‹charts_eucl2 ≡ charts_eucl›*)) have c1: "c1 ∈ eucl1.atlas" "x ∈ domain c1" and c2: "c2 ∈ eucl2.atlas" "f ` domain c1 ⊆ domain c2" (*goals: 1. ‹c1 ∈ eucl1.atlas› 2. ‹x ∈ domain c1› 3. ‹c2 ∈ eucl2.atlas› 4. ‹f ` domain c1 ⊆ domain c2› discuss goal 1*) apply (simp add: c_eucl( (*‹c1 = chart_eucl› ‹c2 = chart_eucl›*) 1,3) charts_eucl1_def (*‹charts_eucl1 ≡ charts_eucl›*) charts_eucl2_def (*‹charts_eucl2 ≡ charts_eucl›*)) (*discuss goal 2*) apply (simp add: c_eucl( (*‹c1 = chart_eucl› ‹c2 = chart_eucl›*) 1,3) charts_eucl1_def (*‹charts_eucl1 ≡ charts_eucl›*) charts_eucl2_def (*‹charts_eucl2 ≡ charts_eucl›*)) (*discuss goal 3*) apply (simp add: c_eucl( (*‹c1 = chart_eucl› ‹c2 = chart_eucl›*) 1,3) charts_eucl1_def (*‹charts_eucl1 ≡ charts_eucl›*) charts_eucl2_def (*‹charts_eucl2 ≡ charts_eucl›*)) (*discuss goal 4*) apply (simp add: c_eucl( (*‹c1 = chart_eucl› ‹c2 = chart_eucl›*) 1,3) charts_eucl1_def (*‹charts_eucl1 ≡ charts_eucl›*) charts_eucl2_def (*‹charts_eucl2 ≡ charts_eucl›*)) (*proven 4 subgoals*) . have f: "1-smooth_on (domain c1') (c2 ∘ f ∘ inv_chart c1)" proof (-) (*goal: ‹1-smooth_on (domain c1') (apply_chart c2 ∘ f ∘ inv_chart c1)›*) have 1: "1-smooth_on (codomain c1') (c2 ∘ inv_chart c2' ∘ (c2' ∘ f ∘ inv_chart c1'))" apply (rule smooth_on_compose[OF smooth_compat_D1[of 1 c2' c2] f'] (*‹⟦1-smooth_compat c2' c2; open (codomain c1'); open (apply_chart c2' ` (domain c2' ∩ domain c2)); (apply_chart c2' ∘ f ∘ inv_chart c1') ` codomain c1' ⊆ apply_chart c2' ` (domain c2' ∩ domain c2)⟧ ⟹ 1-smooth_on (codomain c1') (apply_chart c2 ∘ inv_chart c2' ∘ (apply_chart c2' ∘ f ∘ inv_chart c1'))›*)) (*goal: ‹1-smooth_on (codomain c1') (apply_chart c2 ∘ inv_chart c2' ∘ (apply_chart c2' ∘ f ∘ inv_chart c1'))›*) using c2' (*‹c2' ∈ eucl2.atlas› ‹f ` domain c1' ⊆ domain c2'›*) c2(1) (*‹c2 ∈ eucl2.atlas›*) apply - (*goals: 1. ‹⟦(c2'::('b, 'b) chart) ∈ eucl2.atlas; (f::'a ⇒ 'b) ` domain (c1'::('a, 'a) chart) ⊆ domain c2'; (c2::('b, 'b) chart) ∈ eucl2.atlas⟧ ⟹ (1::enat)-smooth_compat c2' c2› 2. ‹⟦(c2'::('b, 'b) chart) ∈ eucl2.atlas; (f::'a ⇒ 'b) ` domain (c1'::('a, 'a) chart) ⊆ domain c2'; (c2::('b, 'b) chart) ∈ eucl2.atlas⟧ ⟹ open (codomain c1')› 3. ‹⟦(c2'::('b, 'b) chart) ∈ eucl2.atlas; (f::'a ⇒ 'b) ` domain (c1'::('a, 'a) chart) ⊆ domain c2'; (c2::('b, 'b) chart) ∈ eucl2.atlas⟧ ⟹ open (apply_chart c2' ` (domain c2' ∩ domain c2))› 4. ‹⟦(c2'::('b, 'b) chart) ∈ eucl2.atlas; (f::'a ⇒ 'b) ` domain (c1'::('a, 'a) chart) ⊆ domain c2'; (c2::('b, 'b) chart) ∈ eucl2.atlas⟧ ⟹ (apply_chart c2' ∘ f ∘ inv_chart c1') ` codomain c1' ⊆ apply_chart c2' ` (domain c2' ∩ domain c2)› discuss goal 1*) apply ((auto simp: c_eucl( (*‹c2 = chart_eucl›*) 3) eucl2.atlas_is_atlas (*‹⟦?a1.0 ∈ eucl2.atlas; ?a2.0 ∈ eucl2.atlas⟧ ⟹ 1-smooth_compat ?a1.0 ?a2.0›*) open_Int (*‹⟦open ?S; open ?T⟧ ⟹ open (?S ∩ ?T)›*))[1]) (*discuss goal 2*) apply ((auto simp: c_eucl( (*‹(c2::('b, 'b) chart) = chart_eucl›*) 3) eucl2.atlas_is_atlas (*‹⟦(?a1.0::('b, 'b) chart) ∈ eucl2.atlas; (?a2.0::('b, 'b) chart) ∈ eucl2.atlas⟧ ⟹ (1::enat)-smooth_compat ?a1.0 ?a2.0›*) open_Int (*‹⟦open (?S::?'a set); open (?T::?'a set)⟧ ⟹ open (?S ∩ ?T)›*))[1]) (*discuss goal 3*) apply ((auto simp: c_eucl( (*‹c2 = chart_eucl›*) 3) eucl2.atlas_is_atlas (*‹⟦?a1.0 ∈ eucl2.atlas; ?a2.0 ∈ eucl2.atlas⟧ ⟹ 1-smooth_compat ?a1.0 ?a2.0›*) open_Int (*‹⟦open ?S; open ?T⟧ ⟹ open (?S ∩ ?T)›*))[1]) (*discuss goal 4*) apply ((auto simp: c_eucl( (*‹(c2::('b, 'b) chart) = chart_eucl›*) 3) eucl2.atlas_is_atlas (*‹⟦(?a1.0::('b, 'b) chart) ∈ eucl2.atlas; (?a2.0::('b, 'b) chart) ∈ eucl2.atlas⟧ ⟹ (1::enat)-smooth_compat ?a1.0 ?a2.0›*) open_Int (*‹⟦open (?S::?'a set); open (?T::?'a set)⟧ ⟹ open (?S ∩ ?T)›*))[1]) (*proven 4 subgoals*) . have 2: "1-smooth_on (c1 ` (domain c1 ∩ domain c1')) ((c2 ∘ inv_chart c2' ∘ (c2' ∘ f ∘ inv_chart c1')) ∘ (c1' ∘ inv_chart c1))" apply (rule smooth_on_compose[OF 1 smooth_compat_D1[of 1 c1 c1']] (*‹⟦1-smooth_compat c1 c1'; open (apply_chart c1 ` (domain c1 ∩ domain c1')); open (codomain c1'); (apply_chart c1' ∘ inv_chart c1) ` apply_chart c1 ` (domain c1 ∩ domain c1') ⊆ codomain c1'⟧ ⟹ 1-smooth_on (apply_chart c1 ` (domain c1 ∩ domain c1')) (apply_chart c2 ∘ inv_chart c2' ∘ (apply_chart c2' ∘ f ∘ inv_chart c1') ∘ (apply_chart c1' ∘ inv_chart c1))›*)) (*goal: ‹1-smooth_on (apply_chart c1 ` (domain c1 ∩ domain c1')) (apply_chart c2 ∘ inv_chart c2' ∘ (apply_chart c2' ∘ f ∘ inv_chart c1') ∘ (apply_chart c1' ∘ inv_chart c1))›*) using c1'(1) (*‹(c1'::('a, 'a) chart) ∈ eucl1.atlas›*) c1(1) (*‹c1 ∈ eucl1.atlas›*) apply - (*goals: 1. ‹⟦c1' ∈ eucl1.atlas; c1 ∈ eucl1.atlas⟧ ⟹ 1-smooth_compat c1 c1'› 2. ‹⟦c1' ∈ eucl1.atlas; c1 ∈ eucl1.atlas⟧ ⟹ open (apply_chart c1 ` (domain c1 ∩ domain c1'))› 3. ‹⟦c1' ∈ eucl1.atlas; c1 ∈ eucl1.atlas⟧ ⟹ open (codomain c1')› 4. ‹⟦c1' ∈ eucl1.atlas; c1 ∈ eucl1.atlas⟧ ⟹ (apply_chart c1' ∘ inv_chart c1) ` apply_chart c1 ` (domain c1 ∩ domain c1') ⊆ codomain c1'› discuss goal 1*) apply ((auto simp: open_Int (*‹⟦open ?S; open ?T⟧ ⟹ open (?S ∩ ?T)›*) eucl1.atlas_is_atlas (*‹⟦?a1.0 ∈ eucl1.atlas; ?a2.0 ∈ eucl1.atlas⟧ ⟹ 1-smooth_compat ?a1.0 ?a2.0›*) c_eucl( (*‹c1 = chart_eucl›*) 1) image_subsetI (*‹(⋀x. x ∈ ?A ⟹ ?f x ∈ ?B) ⟹ ?f ` ?A ⊆ ?B›*))[1]) (*discuss goal 2*) apply ((auto simp: open_Int (*‹⟦open ?S; open ?T⟧ ⟹ open (?S ∩ ?T)›*) eucl1.atlas_is_atlas (*‹⟦?a1.0 ∈ eucl1.atlas; ?a2.0 ∈ eucl1.atlas⟧ ⟹ 1-smooth_compat ?a1.0 ?a2.0›*) c_eucl( (*‹c1 = chart_eucl›*) 1) image_subsetI (*‹(⋀x. x ∈ ?A ⟹ ?f x ∈ ?B) ⟹ ?f ` ?A ⊆ ?B›*))[1]) (*discuss goal 3*) apply ((auto simp: open_Int (*‹⟦open ?S; open ?T⟧ ⟹ open (?S ∩ ?T)›*) eucl1.atlas_is_atlas (*‹⟦?a1.0 ∈ eucl1.atlas; ?a2.0 ∈ eucl1.atlas⟧ ⟹ 1-smooth_compat ?a1.0 ?a2.0›*) c_eucl( (*‹c1 = chart_eucl›*) 1) image_subsetI (*‹(⋀x. x ∈ ?A ⟹ ?f x ∈ ?B) ⟹ ?f ` ?A ⊆ ?B›*))[1]) (*discuss goal 4*) apply ((auto simp: open_Int (*‹⟦open ?S; open ?T⟧ ⟹ open (?S ∩ ?T)›*) eucl1.atlas_is_atlas (*‹⟦?a1.0 ∈ eucl1.atlas; ?a2.0 ∈ eucl1.atlas⟧ ⟹ 1-smooth_compat ?a1.0 ?a2.0›*) c_eucl( (*‹c1 = chart_eucl›*) 1) image_subsetI (*‹(⋀x. x ∈ ?A ⟹ ?f x ∈ ?B) ⟹ ?f ` ?A ⊆ ?B›*))[1]) (*proven 4 subgoals*) . have "1-smooth_on (c1 ` (domain c1 ∩ domain c1')) (c2 ∘ f ∘ inv_chart c1)" apply (rule smooth_on_cong[OF 2] (*‹⟦open (apply_chart (c1::('a, 'a) chart) ` (domain c1 ∩ domain (c1'::('a, 'a) chart))); ⋀x::'a. x ∈ apply_chart c1 ` (domain c1 ∩ domain c1') ⟹ (?f::'a ⇒ 'b) x = (apply_chart (c2::('b, 'b) chart) ∘ inv_chart (c2'::('b, 'b) chart) ∘ (apply_chart c2' ∘ (f::'a ⇒ 'b) ∘ inv_chart c1') ∘ (apply_chart c1' ∘ inv_chart c1)) x⟧ ⟹ (1::enat)-smooth_on (apply_chart c1 ` (domain c1 ∩ domain c1')) ?f›*)) (*goal: ‹1-smooth_on (apply_chart c1 ` (domain c1 ∩ domain c1')) (apply_chart c2 ∘ f ∘ inv_chart c1)›*) using c2'(2) (*‹f ` domain c1' ⊆ domain c2'›*) inv_chart_inverse (*‹?x ∈ domain ?c ⟹ inv_chart ?c (apply_chart ?c ?x) = ?x›*) apply - (*goals: 1. ‹⟦f ` domain c1' ⊆ domain c2'; ⋀x c. x ∈ domain c ⟹ inv_chart c (apply_chart c x) = x⟧ ⟹ open (apply_chart c1 ` (domain c1 ∩ domain c1'))› 2. ‹⋀x. ⟦x ∈ apply_chart c1 ` (domain c1 ∩ domain c1'); f ` domain c1' ⊆ domain c2'; ⋀x c. x ∈ domain c ⟹ inv_chart c (apply_chart c x) = x⟧ ⟹ (apply_chart c2 ∘ f ∘ inv_chart c1) x = (apply_chart c2 ∘ inv_chart c2' ∘ (apply_chart c2' ∘ f ∘ inv_chart c1') ∘ (apply_chart c1' ∘ inv_chart c1)) x› discuss goal 1*) apply ((auto simp: open_Int (*‹⟦open ?S; open ?T⟧ ⟹ open (?S ∩ ?T)›*))[1]) (*discuss goal 2*) apply ((auto simp: open_Int (*‹⟦open ?S; open ?T⟧ ⟹ open (?S ∩ ?T)›*))[1]) (*proven 2 subgoals*) . thus "?thesis" (*goal: ‹1-smooth_on (domain c1') (apply_chart c2 ∘ f ∘ inv_chart c1)›*) using c_eucl(1) (*‹c1 = chart_eucl›*) by auto qed hence "higher_differentiable_on (domain c1') (c2 ∘ f ∘ inv_chart c1) 1" unfolding smooth_on_def (*goal: ‹higher_differentiable_on (domain c1') (apply_chart c2 ∘ f ∘ inv_chart c1) 1›*) by (simp add: one_enat_def (*‹1 = enat 1›*)) text ‹Finally, put it all together: \<^term>‹f› sandwiched between two identity maps is differentiable on a domain containing \<^term>‹x›, thus \<^term>‹f differentiable at x› in the real analysis sense.› thus "?thesis" (*goal: ‹f differentiable at x›*) using higher_differentiable_on_imp_differentiable_on (*‹⟦higher_differentiable_on ?S ?f ?k; 0 < ?k⟧ ⟹ ?f differentiable_on ?S›*) differentiable_onD (*‹⟦?f differentiable_on ?S; ?x ∈ ?S⟧ ⟹ ?f differentiable at ?x within ?S›*) by (metis at_within_domain (*‹?x ∈ domain ?c ⟹ at ?x within domain ?c = at ?x›*) c1'( (*‹x ∈ domain c1'›*) 2) c_eucl( (*‹c1 = chart_eucl› ‹c2 = chart_eucl›*) 1,3) map_fun_eucl_id_f (*‹apply_chart chart_eucl ∘ ?f ∘ inv_chart chart_eucl = ?f›*) less_one (*‹(?n < 1) = (?n = 0)›*)) qed<close> lemma smooth_on_proj: "smooth_on (manifold.carrier prod_charts_eucl) fst" "smooth_on (manifold.carrier prod_charts_eucl) snd" using smooth_on_fst[OF smooth_on_id manifold.open_carrier] (*‹?k-smooth_on (manifold.carrier ?charts1) fst›*) using smooth_on_snd[OF smooth_on_id manifold.open_carrier] (*‹?k-smooth_on (manifold.carrier ?charts1) snd›*) apply - (*goals: 1. ‹⟦⋀k charts. k-smooth_on (manifold.carrier charts) fst; ⋀k charts. k-smooth_on (manifold.carrier charts) snd⟧ ⟹ smooth_on (manifold.carrier prod_charts_eucl) fst› 2. ‹⟦⋀k charts. k-smooth_on (manifold.carrier charts) fst; ⋀k charts. k-smooth_on (manifold.carrier charts) snd⟧ ⟹ smooth_on (manifold.carrier prod_charts_eucl) snd› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) . lemma eucl_add_smooth: "smooth_on (manifold.carrier prod_charts_eucl) (λ(x,y). x+y)" using smooth_on_add[OF smooth_on_proj manifold.open_carrier] (*‹smooth_on (manifold.carrier prod_charts_eucl) (λx. fst x + snd x)›*) by (simp add: case_prod_beta' (*‹(λ(x, y). ?f x y) = (λx. ?f (fst x) (snd x))›*)) lemma eucl_um_smooth: "smooth_on manifold_eucl.carrier uminus" using smooth_on_uminus[OF smooth_on_id manifold.open_carrier] (*‹?k-smooth_on (manifold.carrier ?charts1) uminus›*) by blast subsection ‹Swapping a product manifold.› context c_manifold_prod begin lift_definition swap_chart :: "('a × 'c, 'b × 'd) chart ⇒ ('c × 'a, 'b × 'd) chart" is "λ(d::('a×'c) set, d'::('b×'d) set, f::('a×'c)⇒('b×'d), f'::('b×'d)⇒('a×'c)). (prod.swap ` d, d', f ∘ prod.swap, prod.swap ∘ f')" by (auto intro: open_Times simp: open_swap homeomorphism_swap) lemma domain_swap_chart[simp]: "domain (swap_chart c) = prod.swap ` (domain c)" and codomain_swap_chart[simp]: "codomain (swap_chart c) = codomain c" and apply_swap_chart[simp]: "apply_chart (swap_chart c) = c ∘ prod.swap" and inv_chart_swap_chart[simp]: "inv_chart (swap_chart c) = prod.swap ∘ (inv_chart c)" (*goals: 1. ‹domain (swap_chart c) = prod.swap ` domain c› 2. ‹codomain (swap_chart c) = codomain c› 3. ‹apply_chart (swap_chart c) = apply_chart c ∘ prod.swap› 4. ‹inv_chart (swap_chart c) = prod.swap ∘ inv_chart c› discuss goal 1*) apply transfer (*top goal: ‹domain (swap_chart (c::('a × 'c, 'b × 'd) chart)) = prod.swap ` domain c› and 3 goals remain*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*goals: 1. ‹⋀(a::'b) b::'d. (a, b) ∈ codomain (swap_chart (c::('a × 'c, 'b × 'd) chart)) ⟹ (a, b) ∈ codomain c› 2. ‹⋀(a::'b) b::'d. (a, b) ∈ codomain (c::('a × 'c, 'b × 'd) chart) ⟹ (a, b) ∈ codomain (swap_chart c)› discuss goal 1*) apply transfer (*top goal: ‹⋀a b. (a, b) ∈ codomain (swap_chart c) ⟹ (a, b) ∈ codomain c› and 3 goals remain*) apply auto (*discuss goal 2*) apply transfer (*top goal: ‹⋀(a::'b) b::'d. (a, b) ∈ codomain (c::('a × 'c, 'b × 'd) chart) ⟹ (a, b) ∈ codomain (swap_chart c)› and 2 goals remain*) apply auto (*proven 2 subgoals*) (*discuss goal 3*) apply transfer (*top goal: ‹apply_chart (swap_chart c) = apply_chart c ∘ prod.swap› and 1 goal remains*) apply auto (*discuss goal 4*) apply transfer (*goal: ‹inv_chart (swap_chart c) = prod.swap ∘ inv_chart c›*) apply auto (*proven 4 subgoals*) . lemma domain_swap_prod_chart[simp]: "domain (swap_chart (prod_chart c1 c2)) = domain c2 × domain c1" and codomain_swap_prod_chart[simp]: "codomain (swap_chart (prod_chart c1 c2)) = codomain c1 × codomain c2" and apply_swap_prod_chart[simp]: "apply_chart (swap_chart (prod_chart c1 c2)) = (λ(y,x). (c1 x, c2 y))" and inv_chart_swap_prod_chart[simp]: "inv_chart (swap_chart (prod_chart c1 c2)) = (λ(x,y). (inv_chart c2 y, inv_chart c1 x))" (*goals: 1. ‹domain (swap_chart (prod_chart c1 c2)) = domain c2 × domain c1› 2. ‹codomain (swap_chart (prod_chart c1 c2)) = codomain c1 × codomain c2› 3. ‹apply_chart (swap_chart (prod_chart c1 c2)) = (λ(y, x). (apply_chart c1 x, apply_chart c2 y))› 4. ‹inv_chart (swap_chart (prod_chart c1 c2)) = (λ(x, y). (inv_chart c2 y, inv_chart c1 x))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . end (* context c_manifold_prod *) subsection ‹The diffeomorphism group of a manifold.› lemma (in diffeomorphism) diffeo_f': "diffeomorphism k charts2 charts1 f' f" apply unfold_locales (*goals: 1. ‹⋀x. x ∈ dest.carrier ⟹ f (f' x) = x› 2. ‹⋀y. y ∈ src.carrier ⟹ f' (f y) = y› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma (in diffeomorphism) is_homeomorphism: "homeomorphism src.carrier dest.carrier f f'" by (simp add: defined (*‹f ` src.carrier ⊆ dest.carrier›*) homeomorphismI (*‹⟦continuous_on ?S ?f; continuous_on ?T ?g; ?f ` ?S ⊆ ?T; ?g ` ?T ⊆ ?S; ⋀x. x ∈ ?S ⟹ ?g (?f x) = x; ⋀y. y ∈ ?T ⟹ ?f (?g y) = y⟧ ⟹ homeomorphism ?S ?T ?f ?g›*) inv.continuous_on (*‹continuous_on dest.carrier f'›*) inv.defined (*‹f' ` dest.carrier ⊆ src.carrier›*) local.continuous_on (*‹continuous_on src.carrier f›*)) context c_manifold begin lemma id_diffeomorphism: "diffeomorphism k charts charts id id" proof (standard) (*goals: 1. ‹⋀x::'a::{second_countable_topology,t2_space}. x ∈ carrier ⟹ ∃c1::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart∈atlas. ∃c2::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart∈atlas. x ∈ domain c1 ∧ id ` domain c1 ⊆ domain c2 ∧ (k::enat)-smooth_on (codomain c1) (apply_chart c2 ∘ id ∘ inv_chart c1)› 2. ‹⋀x::'a::{second_countable_topology,t2_space}. x ∈ carrier ⟹ id (id x) = x›*) fix x assume "x∈carrier" (*‹(x::'a) ∈ carrier›*) then obtain c where c: "c∈atlas" "x ∈ domain c" (*goal: ‹(⋀c. ⟦c ∈ atlas; x ∈ domain c⟧ ⟹ thesis) ⟹ thesis›*) using atlasE (*‹⟦(?x::'a) ∈ carrier; ⋀c::('a, 'b) chart. ⟦c ∈ atlas; ?x ∈ domain c⟧ ⟹ ?thesis::bool⟧ ⟹ ?thesis›*) by blast show "∃c1∈atlas. ∃c2∈atlas. x ∈ domain c1 ∧ id ` domain c1 ⊆ domain c2 ∧ k-smooth_on (codomain c1) (apply_chart c2 ∘ id ∘ inv_chart c1)" proof (-) (*goal: ‹∃c1∈atlas. ∃c2∈atlas. x ∈ domain c1 ∧ id ` domain c1 ⊆ domain c2 ∧ k-smooth_on (codomain c1) (apply_chart c2 ∘ id ∘ inv_chart c1)›*) have "id ` domain c ⊆ domain c" "k-smooth_on (codomain c) (apply_chart c ∘ id ∘ inv_chart c)" (*goals: 1. ‹id ` domain c ⊆ domain c› 2. ‹k-smooth_on (codomain c) (apply_chart c ∘ id ∘ inv_chart c)› discuss goal 1*) apply simp (*discuss goal 2*) apply (metis Int_absorb (*‹?A ∩ ?A = ?A›*) comp_id (*‹?f ∘ id = ?f›*) image_domain_eq (*‹apply_chart ?c ` domain ?c = codomain ?c›*) smooth_compat_D2 (*‹?k-smooth_compat ?c1.0 ?c2.0 ⟹ ?k-smooth_on (apply_chart ?c2.0 ` (domain ?c1.0 ∩ domain ?c2.0)) (apply_chart ?c1.0 ∘ inv_chart ?c2.0)›*) smooth_compat_refl (*‹?k-smooth_compat ?x ?x›*)) (*proven 2 subgoals*) . thus "?thesis" (*goal: ‹∃c1∈atlas. ∃c2∈atlas. x ∈ domain c1 ∧ id ` domain c1 ⊆ domain c2 ∧ k-smooth_on (codomain c1) (apply_chart c2 ∘ id ∘ inv_chart c1)›*) using c (*‹c ∈ atlas› ‹(x::'a) ∈ domain (c::('a, 'b) chart)›*) by blast qed qed (simp) (*solved the remaining goal: ‹⋀x. x ∈ carrier ⟹ id (id x) = x›*) lemma diffeomorphism_compose: "diffeomorphism k M1 M3 (g ∘ f) (f' ∘ g')" if "diffeomorphism k M1 M2 f f'" "diffeomorphism k M2 M3 g g'" proof (intro diffeomorphism.intro (*‹⟦diff ?k ?charts1.0 ?charts2.0 ?f; diff ?k ?charts2.0 ?charts1.0 ?f'; diffeomorphism_axioms ?charts1.0 ?charts2.0 ?f ?f'⟧ ⟹ Differentiable_Manifold.diffeomorphism ?k ?charts1.0 ?charts2.0 ?f ?f'›*) diffeomorphism_axioms.intro (*‹⟦⋀x. x ∈ manifold.carrier ?charts1.0 ⟹ ?f' (?f x) = x; ⋀y. y ∈ manifold.carrier ?charts2.0 ⟹ ?f (?f' y) = y⟧ ⟹ diffeomorphism_axioms ?charts1.0 ?charts2.0 ?f ?f'›*) conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*) allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*) impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goals: 1. ‹diff k M1 M3 (g ∘ f)› 2. ‹diff k M3 M1 (f' ∘ g')› 3. ‹⋀x. x ∈ manifold.carrier M1 ⟹ (f' ∘ g') ((g ∘ f) x) = x› 4. ‹⋀y. y ∈ manifold.carrier M3 ⟹ (g ∘ f) ((f' ∘ g') y) = y›*) let ?M1 = "manifold.carrier M1" and ?M2 = "manifold.carrier M2" and ?M3 = "manifold.carrier M3" { fix x assume x: "x∈?M1" (*‹(x::'c) ∈ manifold.carrier (M1::('c, 'd) chart set)›*) have "f x ∈ ?M2" using that(1) (*‹Differentiable_Manifold.diffeomorphism k M1 M2 f f'›*) x (*‹x ∈ manifold.carrier M1›*) diff.defined[of k M1 M2 f] (*‹diff k M1 M2 f ⟹ f ` manifold.carrier M1 ⊆ manifold.carrier M2›*) by (simp add: image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*) diffeomorphism_def (*‹Differentiable_Manifold.diffeomorphism ?k ?charts1.0 ?charts2.0 ?f ?f' ≡ diff ?k ?charts1.0 ?charts2.0 ?f ∧ diff ?k ?charts2.0 ?charts1.0 ?f' ∧ diffeomorphism_axioms ?charts1.0 ?charts2.0 ?f ?f'›*)) thus "(f' ∘ g') ((g ∘ f) x) = x" using that (*‹Differentiable_Manifold.diffeomorphism (k::enat) (M1::('c, 'd) chart set) (M2::('e, 'f) chart set) (f::'c ⇒ 'e) (f'::'e ⇒ 'c)› ‹Differentiable_Manifold.diffeomorphism k M2 M3 g g'›*) by (simp add: diffeomorphism.f_inv (*‹⟦Differentiable_Manifold.diffeomorphism ?k ?charts1.0 ?charts2.0 ?f ?f'; ?x ∈ manifold.carrier ?charts1.0⟧ ⟹ ?f' (?f ?x) = ?x›*) x (*‹x ∈ manifold.carrier M1›*)) } { fix y assume y: "y ∈ ?M3" (*‹(y::'g) ∈ manifold.carrier (M3::('g, 'h) chart set)›*) have "g' y ∈ ?M2" using that(2) (*‹Differentiable_Manifold.diffeomorphism k M2 M3 g g'›*) y (*‹y ∈ manifold.carrier M3›*) diff.defined[of k M3 M2 g'] (*‹diff (k::enat) (M3::('g, 'h) chart set) (M2::('e, 'f) chart set) (g'::'g ⇒ 'e) ⟹ g' ` manifold.carrier M3 ⊆ manifold.carrier M2›*) by (simp add: image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*) diffeomorphism_def (*‹Differentiable_Manifold.diffeomorphism ?k ?charts1.0 ?charts2.0 ?f ?f' ≡ diff ?k ?charts1.0 ?charts2.0 ?f ∧ diff ?k ?charts2.0 ?charts1.0 ?f' ∧ diffeomorphism_axioms ?charts1.0 ?charts2.0 ?f ?f'›*)) thus "(g ∘ f) ((f' ∘ g') y) = y" using that (*‹Differentiable_Manifold.diffeomorphism k M1 M2 f f'› ‹Differentiable_Manifold.diffeomorphism k M2 M3 g g'›*) by (simp add: diffeomorphism.f'_inv (*‹⟦Differentiable_Manifold.diffeomorphism ?k ?charts1.0 ?charts2.0 ?f ?f'; ?y ∈ manifold.carrier ?charts2.0⟧ ⟹ ?f (?f' ?y) = ?y›*) y (*‹y ∈ manifold.carrier M3›*)) } show "diff k M1 M3 (g ∘ f)" "diff k M3 M1 (f' ∘ g')" using diff_compose (*‹⟦diff (?k::enat) (?M1.0::(?'a, ?'b) chart set) (?M2.0::(?'c, ?'d) chart set) (?f::?'a ⇒ ?'c); diff ?k ?M2.0 (?M3.0::(?'e, ?'f) chart set) (?g::?'c ⇒ ?'e)⟧ ⟹ diff ?k ?M1.0 ?M3.0 (?g ∘ ?f)›*) that (*‹Differentiable_Manifold.diffeomorphism k M1 M2 f f'› ‹Differentiable_Manifold.diffeomorphism k M2 M3 g g'›*) unfolding diffeomorphism_def (*goals: 1. ‹diff k M1 M3 (g ∘ f)› 2. ‹diff k M3 M1 (f' ∘ g')›*) apply - (*goals: 1. ‹⟦⋀k M1 M2 f M3 g. ⟦diff k M1 M2 f; diff k M2 M3 g⟧ ⟹ diff k M1 M3 (g ∘ f); diff k M1 M2 f ∧ diff k M2 M1 f' ∧ diffeomorphism_axioms M1 M2 f f'; diff k M2 M3 g ∧ diff k M3 M2 g' ∧ diffeomorphism_axioms M2 M3 g g'⟧ ⟹ diff k M1 M3 (g ∘ f)› 2. ‹⟦⋀k M1 M2 f M3 g. ⟦diff k M1 M2 f; diff k M2 M3 g⟧ ⟹ diff k M1 M3 (g ∘ f); diff k M1 M2 f ∧ diff k M2 M1 f' ∧ diffeomorphism_axioms M1 M2 f f'; diff k M2 M3 g ∧ diff k M3 M2 g' ∧ diffeomorphism_axioms M2 M3 g g'⟧ ⟹ diff k M3 M1 (f' ∘ g')› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) . qed end (* context c_manifold *) lemma (in diffeomorphism) is_bij_betw: "bij_betw f src.carrier dest.carrier" using defined (*‹f ` src.carrier ⊆ dest.carrier›*) apply (simp add: bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*), intro conjI (*‹⟦?P::bool; ?Q::bool⟧ ⟹ ?P ∧ ?Q›*) inj_onI (*‹(⋀(x::?'a) y::?'a. ⟦x ∈ (?A::?'a set); y ∈ ?A; (?f::?'a ⇒ ?'b) x = ?f y⟧ ⟹ x = y) ⟹ inj_on ?f ?A›*)) (*goal: ‹bij_betw f src.carrier dest.carrier›*) using f_inv (*‹?x ∈ src.carrier ⟹ f' (f ?x) = ?x›*) f'_inv (*‹?y ∈ dest.carrier ⟹ f (f' ?y) = ?y›*) apply metis (*top goal: ‹⋀x y. ⟦f ` src.carrier ⊆ dest.carrier; f ` src.carrier ⊆ dest.carrier; x ∈ src.carrier; y ∈ src.carrier; f x = f y⟧ ⟹ x = y› and 1 goal remains*) using f_inv (*‹?x ∈ src.carrier ⟹ f' (f ?x) = ?x›*) f'_inv (*‹?y ∈ dest.carrier ⟹ f (f' ?y) = ?y›*) by (meson homeomorphism_image1 (*‹homeomorphism ?S ?T ?f ?g ⟹ ?f ` ?S = ?T›*) is_homeomorphism (*‹homeomorphism src.carrier dest.carrier f f'›*)) locale c_automorphism = diffeomorphism k charts charts f f' for k charts f f' begin abbreviation "carrier ≡ src.carrier" lemma in_dest: "f x ∈ carrier" if "x ∈ carrier" using defined (*‹f ` carrier ⊆ carrier›*) that (*‹x ∈ carrier›*) by blast lemma inverse_automorphism: "c_automorphism k charts f' f" apply unfold_locales (*goals: 1. ‹⋀x. x ∈ carrier ⟹ f (f' x) = x› 2. ‹⋀y. y ∈ carrier ⟹ f' (f y) = y› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma automorphism_compose: assumes "c_automorphism k charts g g'" shows "c_automorphism k charts (g∘f) (f'∘g')" proof (intro c_automorphism.intro (*‹Differentiable_Manifold.diffeomorphism ?k ?charts ?charts ?f ?f' ⟹ c_automorphism ?k ?charts ?f ?f'›*) diffeomorphism.intro (*‹⟦diff ?k ?charts1.0 ?charts2.0 ?f; diff ?k ?charts2.0 ?charts1.0 ?f'; diffeomorphism_axioms ?charts1.0 ?charts2.0 ?f ?f'⟧ ⟹ Differentiable_Manifold.diffeomorphism ?k ?charts1.0 ?charts2.0 ?f ?f'›*) diffeomorphism_axioms.intro (*‹⟦⋀x. x ∈ manifold.carrier ?charts1.0 ⟹ ?f' (?f x) = x; ⋀y. y ∈ manifold.carrier ?charts2.0 ⟹ ?f (?f' y) = y⟧ ⟹ diffeomorphism_axioms ?charts1.0 ?charts2.0 ?f ?f'›*)) (*goals: 1. ‹diff k charts charts (g ∘ f)› 2. ‹diff k charts charts (f' ∘ g')› 3. ‹⋀x. x ∈ carrier ⟹ (f' ∘ g') ((g ∘ f) x) = x› 4. ‹⋀y. y ∈ carrier ⟹ (g ∘ f) ((f' ∘ g') y) = y›*) show "diff k charts charts (g ∘ f)" "diff k charts charts (f' ∘ g')" using c_automorphism_axioms (*‹c_automorphism k charts f f'›*) assms (*‹c_automorphism k charts g g'›*) diff_compose (*‹⟦diff ?k ?M1.0 ?M2.0 ?f; diff ?k ?M2.0 ?M3.0 ?g⟧ ⟹ diff ?k ?M1.0 ?M3.0 (?g ∘ ?f)›*) unfolding c_automorphism_def diffeomorphism_def (*goals: 1. ‹diff k charts charts (g ∘ f)› 2. ‹diff k charts charts (f' ∘ g')›*) apply - (*goals: 1. ‹⟦diff k charts charts f ∧ diff k charts charts f' ∧ diffeomorphism_axioms charts charts f f'; diff k charts charts g ∧ diff k charts charts g' ∧ diffeomorphism_axioms charts charts g g'; ⋀k M1 M2 f M3 g. ⟦diff k M1 M2 f; diff k M2 M3 g⟧ ⟹ diff k M1 M3 (g ∘ f)⟧ ⟹ diff k charts charts (g ∘ f)› 2. ‹⟦diff k charts charts f ∧ diff k charts charts f' ∧ diffeomorphism_axioms charts charts f f'; diff k charts charts g ∧ diff k charts charts g' ∧ diffeomorphism_axioms charts charts g g'; ⋀k M1 M2 f M3 g. ⟦diff k M1 M2 f; diff k M2 M3 g⟧ ⟹ diff k M1 M3 (g ∘ f)⟧ ⟹ diff k charts charts (f' ∘ g')› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) . fix x assume "x∈carrier" (*‹(x::'a) ∈ carrier›*) show "(f' ∘ g') ((g ∘ f) x) = x" using ‹x ∈ carrier› (*‹x ∈ carrier›*) assms (*‹c_automorphism (k::enat) (charts::('a, 'b) chart set) (g::'a ⇒ 'a) (g'::'a ⇒ 'a)›*) c_automorphism.axioms (*‹c_automorphism ?k ?charts ?f ?f' ⟹ Differentiable_Manifold.diffeomorphism ?k ?charts ?charts ?f ?f'›*) diffeomorphism.f_inv (*‹⟦Differentiable_Manifold.diffeomorphism ?k ?charts1.0 ?charts2.0 ?f ?f'; ?x ∈ manifold.carrier ?charts1.0⟧ ⟹ ?f' (?f ?x) = ?x›*) in_dest (*‹?x ∈ carrier ⟹ f ?x ∈ carrier›*) by fastforce show "(g ∘ f) ((f' ∘ g') x) = x" by (meson ‹x ∈ carrier› assms (*‹c_automorphism k charts g g'›*) c_automorphism_def (*‹c_automorphism ?k ?charts ?f ?f' ≡ Differentiable_Manifold.diffeomorphism ?k ?charts ?charts ?f ?f'›*) diffeomorphism.f'_inv (*‹⟦Differentiable_Manifold.diffeomorphism ?k ?charts1.0 ?charts2.0 ?f ?f'; ?y ∈ manifold.carrier ?charts2.0⟧ ⟹ ?f (?f' ?y) = ?y›*) diffeomorphism_axioms (*‹Differentiable_Manifold.diffeomorphism k charts charts f f'›*) manifold_eucl.diffeomorphism_compose (*‹⟦Differentiable_Manifold.diffeomorphism ?k ?M1.0 ?M2.0 ?f ?f'; Differentiable_Manifold.diffeomorphism ?k ?M2.0 ?M3.0 ?g ?g'⟧ ⟹ Differentiable_Manifold.diffeomorphism ?k ?M1.0 ?M3.0 (?g ∘ ?f) (?f' ∘ ?g')›*)) qed lemma c_automorphism_cong: assumes "⋀x. x∈carrier ⟹ f x = g x" shows "c_automorphism k charts g f'" proof (intro c_automorphism.intro (*‹Differentiable_Manifold.diffeomorphism ?k ?charts ?charts ?f ?f' ⟹ c_automorphism ?k ?charts ?f ?f'›*) diffeomorphism.intro (*‹⟦diff ?k ?charts1.0 ?charts2.0 ?f; diff ?k ?charts2.0 ?charts1.0 ?f'; diffeomorphism_axioms ?charts1.0 ?charts2.0 ?f ?f'⟧ ⟹ Differentiable_Manifold.diffeomorphism ?k ?charts1.0 ?charts2.0 ?f ?f'›*) diffeomorphism_axioms.intro (*‹⟦⋀x. x ∈ manifold.carrier ?charts1.0 ⟹ ?f' (?f x) = x; ⋀y. y ∈ manifold.carrier ?charts2.0 ⟹ ?f (?f' y) = y⟧ ⟹ diffeomorphism_axioms ?charts1.0 ?charts2.0 ?f ?f'›*)) (*goals: 1. ‹diff (k::enat) (charts::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart set) charts (g::'a::{second_countable_topology,t2_space} ⇒ 'a::{second_countable_topology,t2_space})› 2. ‹diff (k::enat) (charts::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart set) charts (f'::'a::{second_countable_topology,t2_space} ⇒ 'a::{second_countable_topology,t2_space})› 3. ‹⋀x::'a::{second_countable_topology,t2_space}. x ∈ carrier ⟹ (f'::'a::{second_countable_topology,t2_space} ⇒ 'a::{second_countable_topology,t2_space}) ((g::'a::{second_countable_topology,t2_space} ⇒ 'a::{second_countable_topology,t2_space}) x) = x› 4. ‹⋀y::'a::{second_countable_topology,t2_space}. y ∈ carrier ⟹ (g::'a::{second_countable_topology,t2_space} ⇒ 'a::{second_countable_topology,t2_space}) ((f'::'a::{second_countable_topology,t2_space} ⇒ 'a::{second_countable_topology,t2_space}) y) = y›*) show "diff k charts charts g" "diff k charts charts f'" using c_automorphism_axioms (*‹c_automorphism k charts f f'›*) assms (*‹?x3 ∈ carrier ⟹ f ?x3 = g ?x3›*) diff_cong (*‹(⋀x. x ∈ carrier ⟹ f x = ?g x) ⟹ diff k charts charts ?g›*) unfolding c_automorphism_def diffeomorphism_def (*goals: 1. ‹diff k charts charts g› 2. ‹diff k charts charts f'›*) apply - (*goals: 1. ‹⟦diff k charts charts f ∧ diff k charts charts f' ∧ diffeomorphism_axioms charts charts f f'; ⋀x. x ∈ carrier ⟹ f x = g x; ⋀g. (⋀x. x ∈ carrier ⟹ f x = g x) ⟹ diff k charts charts g⟧ ⟹ diff k charts charts g› 2. ‹⟦diff k charts charts f ∧ diff k charts charts f' ∧ diffeomorphism_axioms charts charts f f'; ⋀x. x ∈ carrier ⟹ f x = g x; ⋀g. (⋀x. x ∈ carrier ⟹ f x = g x) ⟹ diff k charts charts g⟧ ⟹ diff k charts charts f'› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) . fix x assume "x∈carrier" (*‹(x::'a) ∈ carrier›*) show "f' (g x) = x" using ‹x ∈ carrier› (*‹x ∈ carrier›*) assms (*‹?x3 ∈ carrier ⟹ f ?x3 = g ?x3›*) f_inv (*‹?x ∈ carrier ⟹ f' (f ?x) = ?x›*) by presburger show "g (f' x) = x" by (metis ‹x ∈ carrier› assms (*‹?x3 ∈ carrier ⟹ f ?x3 = g ?x3›*) f'_inv (*‹?y ∈ carrier ⟹ f (f' ?y) = ?y›*) image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*) inv.defined (*‹f' ` carrier ⊆ carrier›*)) qed lemma automorphism_cong': assumes "⋀x. x∈carrier ⟹ f' x = g x" shows "c_automorphism k charts f g" proof (intro c_automorphism.intro (*‹Differentiable_Manifold.diffeomorphism (?k::enat) (?charts::(?'a, ?'b) chart set) ?charts (?f::?'a ⇒ ?'a) (?f'::?'a ⇒ ?'a) ⟹ c_automorphism ?k ?charts ?f ?f'›*) diffeomorphism.intro (*‹⟦diff (?k::enat) (?charts1.0::(?'a, ?'b) chart set) (?charts2.0::(?'c, ?'d) chart set) (?f::?'a ⇒ ?'c); diff ?k ?charts2.0 ?charts1.0 (?f'::?'c ⇒ ?'a); diffeomorphism_axioms ?charts1.0 ?charts2.0 ?f ?f'⟧ ⟹ Differentiable_Manifold.diffeomorphism ?k ?charts1.0 ?charts2.0 ?f ?f'›*) diffeomorphism_axioms.intro (*‹⟦⋀x::?'a. x ∈ manifold.carrier (?charts1.0::(?'a, ?'b) chart set) ⟹ (?f'::?'c ⇒ ?'a) ((?f::?'a ⇒ ?'c) x) = x; ⋀y::?'c. y ∈ manifold.carrier (?charts2.0::(?'c, ?'d) chart set) ⟹ ?f (?f' y) = y⟧ ⟹ diffeomorphism_axioms ?charts1.0 ?charts2.0 ?f ?f'›*)) (*goals: 1. ‹diff (k::enat) (charts::('a, 'b) chart set) charts (f::'a ⇒ 'a)› 2. ‹diff (k::enat) (charts::('a, 'b) chart set) charts (g::'a ⇒ 'a)› 3. ‹⋀x::'a. x ∈ carrier ⟹ (g::'a ⇒ 'a) ((f::'a ⇒ 'a) x) = x› 4. ‹⋀y::'a. y ∈ carrier ⟹ (f::'a ⇒ 'a) ((g::'a ⇒ 'a) y) = y›*) show "diff k charts charts g" "diff k charts charts f" using c_automorphism_axioms (*‹c_automorphism k charts f f'›*) assms (*‹?x3 ∈ carrier ⟹ f' ?x3 = g ?x3›*) unfolding c_automorphism_def diffeomorphism_def (*goals: 1. ‹diff k charts charts g› 2. ‹diff k charts charts f›*) apply - (*goals: 1. ‹⟦diff k charts charts f ∧ diff k charts charts f' ∧ diffeomorphism_axioms charts charts f f'; ⋀x. x ∈ carrier ⟹ f' x = g x⟧ ⟹ diff k charts charts g› 2. ‹⟦diff k charts charts f ∧ diff k charts charts f' ∧ diffeomorphism_axioms charts charts f f'; ⋀x. x ∈ carrier ⟹ f' x = g x⟧ ⟹ diff k charts charts f› discuss goal 1*) apply (simp add: inv.diff_cong (*‹(⋀x. x ∈ carrier ⟹ f' x = ?g x) ⟹ diff k charts charts ?g›*)) (*discuss goal 2*) apply (simp add: inv.diff_cong (*‹(⋀x. x ∈ carrier ⟹ f' x = ?g x) ⟹ diff k charts charts ?g›*)) (*proven 2 subgoals*) . fix x assume "x∈carrier" (*‹(x::'a) ∈ carrier›*) show "f (g x) = x" using ‹x ∈ carrier› (*‹x ∈ carrier›*) assms (*‹(?x3::'a) ∈ carrier ⟹ (f'::'a ⇒ 'a) ?x3 = (g::'a ⇒ 'a) ?x3›*) f'_inv (*‹?y ∈ carrier ⟹ f (f' ?y) = ?y›*) by presburger show "g (f x) = x" by (metis ‹x ∈ carrier› assms (*‹?x3 ∈ carrier ⟹ f' ?x3 = g ?x3›*) f_inv (*‹?x ∈ carrier ⟹ f' (f ?x) = ?x›*) image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*) defined (*‹f ` carrier ⊆ carrier›*)) qed end (* c_automorphism *) text ‹Now define an automorphism (of a \<^locale>‹c_manifold›) as a partial function (whose domain is the carrier set) which is also a \<^locale>‹c_automorphism›.› context c_manifold begin definition automorphism :: "('a⇀'a) ⇒ bool" where "automorphism f ≡ (∃f'. c_automorphism k charts (λx. the (f x)) f') ∧ dom f = carrier" lemma automorphismD [dest]: assumes "automorphism f" shows "∃f'. c_automorphism k charts (λx. the (f x)) f'" and "dom f = carrier" using assms (*‹automorphism f›*) apply - (*goals: 1. ‹automorphism f ⟹ ∃f'. c_automorphism k charts (λx. the (f x)) f'› 2. ‹automorphism f ⟹ dom f = carrier› discuss goal 1*) apply ((auto simp: automorphism_def (*‹automorphism (?f::'a::{second_countable_topology,t2_space} ⇒ 'a::{second_countable_topology,t2_space} option) ≡ (∃f'::'a::{second_countable_topology,t2_space} ⇒ 'a::{second_countable_topology,t2_space}. c_automorphism (k::enat) (charts::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart set) (λx::'a::{second_countable_topology,t2_space}. the (?f x)) f') ∧ dom ?f = carrier›*))[1]) (*discuss goal 2*) apply ((auto simp: automorphism_def (*‹automorphism ?f ≡ (∃f'. c_automorphism k charts (λx. the (?f x)) f') ∧ dom ?f = carrier›*))[1]) (*proven 2 subgoals*) . lemma automorphismD2: assumes "automorphism f" obtains f' where "c_automorphism k charts (λx. the (f x)) f'" using automorphismD(1)[OF assms] (*‹∃f'. c_automorphism k charts (λx. the (f x)) f'›*) by blast lemma automorphismI [intro]: assumes "∃f'. c_automorphism k charts (λx. the (f x)) f'" and "dom f = carrier" shows "automorphism f" using assms (*‹∃f'. c_automorphism k charts (λx. the (f x)) f'› ‹dom f = carrier›*) by (auto simp: automorphism_def (*‹automorphism ?f ≡ (∃f'. c_automorphism k charts (λx. the (?f x)) f') ∧ dom ?f = carrier›*)) lemma automorphism_partial_id: "automorphism (λx. if x ∈ carrier then Some x else None)" (is "automorphism ?part_id") proof (intro automorphismI (*‹⟦∃f'. c_automorphism k charts (λx. the (?f x)) f'; dom ?f = carrier⟧ ⟹ automorphism ?f›*) exI (*‹?P ?x ⟹ ∃x. ?P x›*) c_automorphism.intro (*‹Differentiable_Manifold.diffeomorphism ?k ?charts ?charts ?f ?f' ⟹ c_automorphism ?k ?charts ?f ?f'›*)) (*goals: 1. ‹Differentiable_Manifold.diffeomorphism k charts charts (λx. the (if x ∈ carrier then Some x else None)) ?f'1› 2. ‹dom (λx. if x ∈ carrier then Some x else None) = carrier›*) have part_id_on_carrier: "(λx. the (?part_id x)) y = id y" if "y∈carrier" for y by (simp add: that (*‹y ∈ carrier›*)) show "diffeomorphism k charts charts (λx. the (?part_id x)) id" apply (intro diffeomorphism.intro (*‹⟦diff ?k ?charts1.0 ?charts2.0 ?f; diff ?k ?charts2.0 ?charts1.0 ?f'; diffeomorphism_axioms ?charts1.0 ?charts2.0 ?f ?f'⟧ ⟹ Differentiable_Manifold.diffeomorphism ?k ?charts1.0 ?charts2.0 ?f ?f'›*) diffeomorphism_axioms.intro (*‹⟦⋀x. x ∈ manifold.carrier ?charts1.0 ⟹ ?f' (?f x) = x; ⋀y. y ∈ manifold.carrier ?charts2.0 ⟹ ?f (?f' y) = y⟧ ⟹ diffeomorphism_axioms ?charts1.0 ?charts2.0 ?f ?f'›*)) (*goal: ‹Differentiable_Manifold.diffeomorphism k charts charts (λx. the (if x ∈ carrier then Some x else None)) id›*) subgoal for using diff_id (*‹diff (k::enat) (charts::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart set) charts (λx::'a::{second_countable_topology,t2_space}. x)›*) diff.diff_cong[of k charts charts] (*‹⟦diff k charts charts ?f; ⋀x. x ∈ carrier ⟹ ?f x = ?g x⟧ ⟹ diff k charts charts ?g›*) part_id_on_carrier (*‹?y3 ∈ carrier ⟹ the (if ?y3 ∈ carrier then Some ?y3 else None) = id ?y3›*) by force subgoal for using diff_id (*‹diff (k::enat) (charts::('a, 'b) chart set) charts (λx::'a. x)›*) eq_id_iff (*‹(∀x. ?f x = x) = (?f = id)›*) by metis (*goals: 1. ‹⋀x. x ∈ carrier ⟹ id (the (if x ∈ carrier then Some x else None)) = x› 2. ‹⋀y. y ∈ carrier ⟹ the (if id y ∈ carrier then Some (id y) else None) = y› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . show "dom ?part_id = carrier" using domIff (*‹((?a::?'a::type) ∈ dom (?m::?'a::type ⇒ ?'b::type option)) = (?m ?a ≠ None)›*) by fastforce qed lemma automorphism_openin: assumes "automorphism f" "openin (top_of_set carrier) S" shows "openin (top_of_set carrier) (the ` f ` S)" using assms (*‹automorphism (f::'a ⇒ 'a option)› ‹openin (top_of_set carrier) S›*) diffeomorphism.is_homeomorphism (*‹Differentiable_Manifold.diffeomorphism (?k::enat) (?charts1.0::(?'a, ?'b) chart set) (?charts2.0::(?'c, ?'d) chart set) (?f::?'a ⇒ ?'c) (?f'::?'c ⇒ ?'a) ⟹ homeomorphism (manifold.carrier ?charts1.0) (manifold.carrier ?charts2.0) ?f ?f'›*) homeomorphism_imp_open_map (*‹⟦homeomorphism ?S ?T ?f ?g; openin (top_of_set ?S) ?U⟧ ⟹ openin (top_of_set ?T) (?f ` ?U)›*) unfolding automorphism_def c_automorphism_def (*goal: ‹openin (top_of_set carrier) (the ` f ` S)›*) by (metis (no_types, lifting) image_cong (*‹⟦?M = ?N; ⋀x. x ∈ ?N ⟹ ?f x = ?g x⟧ ⟹ ?f ` ?M = ?g ` ?N›*) image_image (*‹?f ` ?g ` ?A = (λx. ?f (?g x)) ` ?A›*)) lemma obtain_inverse_aut: assumes "automorphism f" obtains f' where "automorphism f'" and "⋀x. x ∈ carrier ⟹ the (f' (the (f x))) = x" and "⋀x. x ∈ carrier ⟹ the (f (the (f' x))) = x" proof (-) (*goal: ‹(⋀f'. ⟦automorphism f'; ⋀x. x ∈ carrier ⟹ the (f' (the (f x))) = x; ⋀x. x ∈ carrier ⟹ the (f (the (f' x))) = x⟧ ⟹ thesis) ⟹ thesis›*) let ?g = "λx. the (f x)" obtain g' where g': "c_automorphism k charts ?g g'" and dom_f: "dom f = carrier" (*goal: ‹(⋀g'. ⟦c_automorphism k charts (λx. the (f x)) g'; dom f = carrier⟧ ⟹ thesis) ⟹ thesis›*) using assms (*‹automorphism f›*) automorphismD (*‹automorphism ?f ⟹ ∃f'. c_automorphism k charts (λx. the (?f x)) f'› ‹automorphism ?f ⟹ dom ?f = carrier›*) by auto let ?f' = "λy::'a. if y∈carrier then Some (g' y) else None" have dom_f': "dom ?f' = carrier" using subset_iff (*‹(?A ⊆ ?B) = (∀t. t ∈ ?A ⟶ t ∈ ?B)›*) by fastforce have unwrap_the: "(λx. the (?f' x)) y = g' y" if "y ∈ carrier" for y using that (*‹y ∈ carrier›*) by auto { fix x assume "x ∈ carrier" (*‹(x::'a) ∈ carrier›*) have "automorphism ?f'" "the (?f' (the (f x))) = x" "the (f (the (?f' x))) = x" proof (-) (*goals: 1. ‹automorphism (λy. if y ∈ carrier then Some (g' y) else None)› 2. ‹the (if the (f x) ∈ carrier then Some (g' (the (f x))) else None) = x› 3. ‹the (f (the (if x ∈ carrier then Some (g' x) else None))) = x›*) have diff_f': "diff k charts charts (λx. the (?f' x))" using c_automorphism.inverse_automorphism[OF g'] (*‹c_automorphism k charts g' (λx. the (f x))›*) diff.diff_cong (*‹⟦diff (?k::enat) (?charts1.0::(?'a, ?'e) chart set) (?charts2.0::(?'b, ?'f) chart set) (?f::?'a ⇒ ?'b); ⋀x::?'a. x ∈ manifold.carrier ?charts1.0 ⟹ ?f x = (?g::?'a ⇒ ?'b) x⟧ ⟹ diff ?k ?charts1.0 ?charts2.0 ?g›*) unfolding c_automorphism_def diffeomorphism_def (*goal: ‹diff k charts charts (λx. the (if x ∈ carrier then Some (g' x) else None))›*) by fastforce text ‹Finding an inverse diffeomorphism is the main part of this proof.› have diffeo_f': "diffeomorphism k charts charts (λx. the (?f' x)) (λx. the (f x))" apply (intro diffeomorphism.intro (*‹⟦diff ?k ?charts1.0 ?charts2.0 ?f; diff ?k ?charts2.0 ?charts1.0 ?f'; diffeomorphism_axioms ?charts1.0 ?charts2.0 ?f ?f'⟧ ⟹ Differentiable_Manifold.diffeomorphism ?k ?charts1.0 ?charts2.0 ?f ?f'›*) diffeomorphism_axioms.intro (*‹⟦⋀x. x ∈ manifold.carrier ?charts1.0 ⟹ ?f' (?f x) = x; ⋀y. y ∈ manifold.carrier ?charts2.0 ⟹ ?f (?f' y) = y⟧ ⟹ diffeomorphism_axioms ?charts1.0 ?charts2.0 ?f ?f'›*) conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goal: ‹Differentiable_Manifold.diffeomorphism (k::enat) (charts::('a, 'b) chart set) charts (λx::'a. the (if x ∈ carrier then Some ((g'::'a ⇒ 'a) x) else None)) (λx::'a. the ((f::'a ⇒ 'a option) x))›*) subgoal for using diff_f' (*‹diff (k::enat) (charts::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart set) charts (λx::'a::{second_countable_topology,t2_space}. the (if x ∈ carrier then Some ((g'::'a::{second_countable_topology,t2_space} ⇒ 'a::{second_countable_topology,t2_space}) x) else None))›*) . subgoal for using assms (*‹automorphism f›*) unfolding automorphism_def c_automorphism_def diffeomorphism_def (*goal: ‹diff k charts charts (λx. the (f x))›*) by simp subgoal for apply simp (*goal: ‹x_ ∈ carrier ⟹ the (f (the (if x_ ∈ carrier then Some (g' x_) else None))) = x_›*) by (metis c_automorphism.axioms( (*‹c_automorphism ?k ?charts ?f ?f' ⟹ Differentiable_Manifold.diffeomorphism ?k ?charts ?charts ?f ?f'›*) 1) diffeomorphism.f'_inv (*‹⟦Differentiable_Manifold.diffeomorphism ?k ?charts1.0 ?charts2.0 ?f ?f'; ?y ∈ manifold.carrier ?charts2.0⟧ ⟹ ?f (?f' ?y) = ?y›*) g' (*‹c_automorphism k charts (λx. the (f x)) g'›*)) subgoal for using c_automorphism.in_dest (*‹⟦c_automorphism ?k ?charts ?f ?f'; ?x ∈ manifold.carrier ?charts⟧ ⟹ ?f ?x ∈ manifold.carrier ?charts›*) diffeomorphism.f_inv (*‹⟦Differentiable_Manifold.diffeomorphism ?k ?charts1.0 ?charts2.0 ?f ?f'; ?x ∈ manifold.carrier ?charts1.0⟧ ⟹ ?f' (?f ?x) = ?x›*) g' (*‹c_automorphism k charts (λx. the (f x)) g'›*) apply (simp add: c_automorphism_def (*‹c_automorphism ?k ?charts ?f ?f' ≡ Differentiable_Manifold.diffeomorphism ?k ?charts ?charts ?f ?f'›*)) (*goal: ‹y_ ∈ carrier ⟹ the (if the (f y_) ∈ carrier then Some (g' (the (f y_))) else None) = y_›*) by blast . show "automorphism ?f'" apply (intro automorphismI (*‹⟦∃f'. c_automorphism k charts (λx. the (?f x)) f'; dom ?f = carrier⟧ ⟹ automorphism ?f›*) exI[of _ "λx. the (f x)"] (*‹?P (λx. the (f x)) ⟹ ∃x. ?P x›*)) (*goals: 1. ‹c_automorphism k charts (λx. the (if x ∈ carrier then Some (g' x) else None)) (λf'. the (f f'))› 2. ‹dom (λy. if y ∈ carrier then Some (g' y) else None) = carrier› discuss goal 1*) apply ((auto intro: c_automorphism.intro (*‹Differentiable_Manifold.diffeomorphism ?k ?charts ?charts ?f ?f' ⟹ c_automorphism ?k ?charts ?f ?f'›*) simp: dom_f' (*‹dom (λy. if y ∈ carrier then Some (g' y) else None) = carrier›*) diffeo_f' (*‹Differentiable_Manifold.diffeomorphism k charts charts (λx. the (if x ∈ carrier then Some (g' x) else None)) (λx. the (f x))›*))[1]) (*discuss goal 2*) apply ((auto intro: c_automorphism.intro (*‹Differentiable_Manifold.diffeomorphism ?k ?charts ?charts ?f ?f' ⟹ c_automorphism ?k ?charts ?f ?f'›*) simp: dom_f' (*‹dom (λy. if y ∈ carrier then Some (g' y) else None) = carrier›*) diffeo_f' (*‹Differentiable_Manifold.diffeomorphism k charts charts (λx. the (if x ∈ carrier then Some (g' x) else None)) (λx. the (f x))›*))[1]) (*proven 2 subgoals*) . show "the (?f' (the (f x))) = x" using ‹x ∈ carrier› (*‹x ∈ carrier›*) diffeo_f' (*‹Differentiable_Manifold.diffeomorphism (k::enat) (charts::('a, 'b) chart set) charts (λx::'a. the (if x ∈ carrier then Some ((g'::'a ⇒ 'a) x) else None)) (λx::'a. the ((f::'a ⇒ 'a option) x))›*) diffeomorphism.f'_inv (*‹⟦Differentiable_Manifold.diffeomorphism ?k ?charts1.0 ?charts2.0 ?f ?f'; ?y ∈ manifold.carrier ?charts2.0⟧ ⟹ ?f (?f' ?y) = ?y›*) by blast show "the (f (the (?f' x))) = x" using ‹x ∈ carrier› (*‹x ∈ carrier›*) diffeo_f' (*‹Differentiable_Manifold.diffeomorphism k charts charts (λx. the (if x ∈ carrier then Some (g' x) else None)) (λx. the (f x))›*) diffeomorphism.f_inv (*‹⟦Differentiable_Manifold.diffeomorphism (?k::enat) (?charts1.0::(?'a, ?'b) chart set) (?charts2.0::(?'c, ?'d) chart set) (?f::?'a ⇒ ?'c) (?f'::?'c ⇒ ?'a); (?x::?'a) ∈ manifold.carrier ?charts1.0⟧ ⟹ ?f' (?f ?x) = ?x›*) by blast qed } thus "?thesis" (*goal: ‹thesis›*) using that (*‹⟦automorphism ?f'3; ⋀x. x ∈ carrier ⟹ the (?f'3 (the (f x))) = x; ⋀x. x ∈ carrier ⟹ the (f (the (?f'3 x))) = x⟧ ⟹ thesis›*) assms (*‹automorphism f›*) by blast qed lemma aut_cong: assumes "automorphism f" and "⋀x. x∈carrier ⟹ f x = g x" "dom g = carrier" shows "automorphism g" apply (intro automorphismI (*‹⟦∃f'. c_automorphism k charts (λx. the (?f x)) f'; dom ?f = carrier⟧ ⟹ automorphism ?f›*)) (*goal: ‹automorphism g›*) using c_automorphism.c_automorphism_cong (*‹⟦c_automorphism ?k ?charts ?f ?f'; ⋀x. x ∈ manifold.carrier ?charts ⟹ ?f x = ?g x⟧ ⟹ c_automorphism ?k ?charts ?g ?f'›*) (*goals: 1. ‹∃f'. c_automorphism k charts (λx. the (g x)) f'› 2. ‹dom g = carrier› discuss goal 1*) apply (metis assms( (*‹automorphism f› ‹?x3 ∈ carrier ⟹ f ?x3 = g ?x3›*) 1,2) automorphism_def (*‹automorphism ?f ≡ (∃f'. c_automorphism k charts (λx. the (?f x)) f') ∧ dom ?f = carrier›*)) (*discuss goal 2*) apply (simp add: assms( (*‹dom g = carrier›*) 3)) (*proven 2 subgoals*) . lemma aut_comp_simps [simp]: "(g ∘⇩m f) x = (g (the (f x)))" "automorphism g ⟹ ∃z∈carrier. Some z = (g ∘⇩m f) x" if "x ∈ carrier" "automorphism f" for x subgoal for by (metis automorphismD( (*‹automorphism ?f ⟹ dom ?f = carrier›*) 2) domIff (*‹(?a ∈ dom ?m) = (?m ?a ≠ None)›*) map_comp_simps( (*‹?m2.0 ?k = Some ?k' ⟹ (?m1.0 ∘⇩m ?m2.0) ?k = ?m1.0 ?k'›*) 2) option.exhaust_sel (*‹⟦?option = None ⟹ ?P; ?option = Some (the ?option) ⟹ ?P⟧ ⟹ ?P›*) that (*‹x ∈ carrier› ‹automorphism f›*)) subgoal for using that (*‹(x::'a) ∈ carrier› ‹automorphism f›*) automorphismD (*‹automorphism ?f ⟹ ∃f'. c_automorphism k charts (λx. the (?f x)) f'› ‹automorphism ?f ⟹ dom ?f = carrier›*) domIff (*‹(?a ∈ dom ?m) = (?m ?a ≠ None)›*) map_comp_simps (*‹?m2.0 ?k = None ⟹ (?m1.0 ∘⇩m ?m2.0) ?k = None› ‹?m2.0 ?k = Some ?k' ⟹ (?m1.0 ∘⇩m ?m2.0) ?k = ?m1.0 ?k'›*) by (smt (verit, del_insts) c_automorphism.in_dest (*‹⟦c_automorphism ?k ?charts ?f ?f'; ?x ∈ manifold.carrier ?charts⟧ ⟹ ?f ?x ∈ manifold.carrier ?charts›*) option.exhaust_sel (*‹⟦?option = None ⟹ ?P; ?option = Some (the ?option) ⟹ ?P⟧ ⟹ ?P›*)) . lemma aut_to [simp]: "the (f x) ∈ carrier" if "automorphism f" "x ∈ carrier" by (metis (mono_tags, lifting) c_manifold.aut_comp_simps (*‹⟦c_manifold ?charts ?k; ?x ∈ manifold.carrier ?charts; c_manifold.automorphism ?charts ?k ?f⟧ ⟹ (?g ∘⇩m ?f) ?x = ?g (the (?f ?x))› ‹⟦c_manifold ?charts ?k; ?x ∈ manifold.carrier ?charts; c_manifold.automorphism ?charts ?k ?f; c_manifold.automorphism ?charts ?k ?g⟧ ⟹ ∃z∈manifold.carrier ?charts. Some z = (?g ∘⇩m ?f) ?x›*) c_manifold.automorphismD( (*‹⟦c_manifold ?charts ?k; c_manifold.automorphism ?charts ?k ?f⟧ ⟹ dom ?f = manifold.carrier ?charts›*) 2) c_manifold_axioms (*‹c_manifold charts k›*) domI (*‹?m ?a = Some ?b ⟹ ?a ∈ dom ?m›*) that (*‹automorphism f› ‹x ∈ carrier›*)) lemma automorphism_ran: "ran f = carrier" if "automorphism f" unfolding ran_def (*goal: ‹{b::'a. ∃a::'a. (f::'a ⇒ 'a option) a = Some b} = carrier›*) apply (intro subset_antisym (*‹⟦?A ⊆ ?B; ?B ⊆ ?A⟧ ⟹ ?A = ?B›*) subsetI (*‹(⋀x. x ∈ ?A ⟹ x ∈ ?B) ⟹ ?A ⊆ ?B›*)) (*goal: ‹{b. ∃a. f a = Some b} = carrier›*) using automorphismD(2) (*‹automorphism ?f ⟹ dom ?f = carrier›*) aut_to (*‹⟦automorphism ?f; ?x ∈ carrier⟧ ⟹ the (?f ?x) ∈ carrier›*) mem_Collect_eq (*‹((?a::?'a::type) ∈ Collect (?P::?'a::type ⇒ bool)) = ?P ?a›*) option.sel (*‹the (Some ?x2.0) = ?x2.0›*) that (*‹automorphism f›*) apply - (*goals: 1. ‹⋀x. ⟦x ∈ {b. ∃a. f a = Some b}; ⋀f. automorphism f ⟹ dom f = carrier; ⋀f x. ⟦automorphism f; x ∈ carrier⟧ ⟹ the (f x) ∈ carrier; ⋀a P. (a ∈ Collect P) = P a; ⋀x2. the (Some x2) = x2; automorphism f⟧ ⟹ x ∈ carrier› 2. ‹⋀x. ⟦x ∈ carrier; ⋀f. automorphism f ⟹ dom f = carrier; ⋀f x. ⟦automorphism f; x ∈ carrier⟧ ⟹ the (f x) ∈ carrier; ⋀a P. (a ∈ Collect P) = P a; ⋀x2. the (Some x2) = x2; automorphism f⟧ ⟹ x ∈ {b. ∃a. f a = Some b}› discuss goal 1*) apply ((msorry)[1]) (*discuss goal 2*) apply ((msorry)[1]) (*proven 2 subgoals*) . lemma aut_comp: assumes "automorphism f" "automorphism g" shows "automorphism (g ∘⇩m f)" proof (intro automorphismI (*‹⟦∃f'. c_automorphism k charts (λx. the (?f x)) f'; dom ?f = carrier⟧ ⟹ automorphism ?f›*)) (*goals: 1. ‹∃f'. c_automorphism k charts (λx. the ((g ∘⇩m f) x)) f'› 2. ‹dom (g ∘⇩m f) = carrier›*) obtain f' where f': "c_automorphism k charts (λx. the (f x)) f'" and domf: "dom f = carrier" (*goal: ‹(⋀f'::'a ⇒ 'a. ⟦c_automorphism (k::enat) (charts::('a, 'b) chart set) (λx::'a. the ((f::'a ⇒ 'a option) x)) f'; dom f = carrier⟧ ⟹ thesis::bool) ⟹ thesis›*) using automorphismD[OF assms ( 1 )] (*‹∃f'::'a ⇒ 'a. c_automorphism (k::enat) (charts::('a, 'b) chart set) (λx::'a. the ((f::'a ⇒ 'a option) x)) f'› ‹dom (f::'a ⇒ 'a option) = carrier›*) by blast obtain g' where g': "c_automorphism k charts (λx. the (g x)) g'" and domg: "dom g = carrier" (*goal: ‹(⋀g'. ⟦c_automorphism k charts (λx. the (g x)) g'; dom g = carrier⟧ ⟹ thesis) ⟹ thesis›*) using automorphismD[OF assms ( 2 )] (*‹∃f'::'a ⇒ 'a. c_automorphism (k::enat) (charts::('a, 'b) chart set) (λx::'a. the ((g::'a ⇒ 'a option) x)) f'› ‹dom g = carrier›*) by blast show dom_comp: "dom (g ∘⇩m f) = carrier" using map_comp_dom (*‹ran (?f::?'b::type ⇒ ?'a::type option) ⊆ dom (?g::?'a::type ⇒ ?'c::type option) ⟹ dom (?g ∘⇩m ?f) = dom ?f›*) automorphism_ran (*‹automorphism ?f ⟹ ran ?f = carrier›*) by (metis assms( (*‹automorphism (f::'a ⇒ 'a option)›*) 1) domf (*‹dom (f::'a ⇒ 'a option) = carrier›*) domg (*‹dom (g::'a ⇒ 'a option) = carrier›*) subsetI (*‹(⋀x::?'a. x ∈ (?A::?'a set) ⟹ x ∈ (?B::?'a set)) ⟹ ?A ⊆ ?B›*)) have "c_automorphism k charts (λx. the (g (the (f x)))) (f' ∘ g')" using c_automorphism.automorphism_compose[OF f' g'] (*‹c_automorphism (k::enat) (charts::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart set) ((λx::'a::{second_countable_topology,t2_space}. the ((g::'a::{second_countable_topology,t2_space} ⇒ 'a::{second_countable_topology,t2_space} option) x)) ∘ (λx::'a::{second_countable_topology,t2_space}. the ((f::'a::{second_countable_topology,t2_space} ⇒ 'a::{second_countable_topology,t2_space} option) x))) ((f'::'a::{second_countable_topology,t2_space} ⇒ 'a::{second_countable_topology,t2_space}) ∘ (g'::'a::{second_countable_topology,t2_space} ⇒ 'a::{second_countable_topology,t2_space}))›*) c_automorphism.c_automorphism_cong (*‹⟦c_automorphism ?k ?charts ?f ?f'; ⋀x. x ∈ manifold.carrier ?charts ⟹ ?f x = ?g x⟧ ⟹ c_automorphism ?k ?charts ?g ?f'›*) by fastforce thus "∃f'. c_automorphism k charts (λx. the ((g ∘⇩m f) x)) f'" by (auto intro: exI[of _ "f' ∘ g'"] (*‹?P (f' ∘ g') ⟹ ∃x. ?P x›*) simp: assms( (*‹automorphism f›*) 1) c_automorphism.c_automorphism_cong (*‹⟦c_automorphism ?k ?charts ?f ?f'; ⋀x. x ∈ manifold.carrier ?charts ⟹ ?f x = ?g x⟧ ⟹ c_automorphism ?k ?charts ?g ?f'›*)) qed definition "Diff ≡ {f. automorphism f}" lemma DiffD [dest]: "f ∈ Diff ⟹ automorphism f" by (simp add: Diff_def (*‹Diff ≡ Collect automorphism›*)) lemma DiffI [intro]: "automorphism f ⟹ f ∈ Diff" by (simp add: Diff_def (*‹Diff ≡ Collect automorphism›*)) abbreviation (input) Diff_comp::"('a⇀'a) ⇒ ('a⇀'a) ⇒ ('a⇀'a)" where "Diff_comp ≡ map_comp" abbreviation (*input*) "Diff_id x ≡ if x∈carrier then Some x else None" (* abbreviation (input) "Diff_inv x ≡ res (SOME y. )" *) lemma Diff_grp: "grp_on Diff Diff_comp Diff_id" proof (unfold_locales) (*goals: 1. ‹⋀a b c. ⟦a ∈ Diff; b ∈ Diff; c ∈ Diff⟧ ⟹ a ∘⇩m b ∘⇩m c = a ∘⇩m (b ∘⇩m c)› 2. ‹⋀a b. ⟦a ∈ Diff; b ∈ Diff⟧ ⟹ a ∘⇩m b ∈ Diff› 3. ‹⋀a. a ∈ Diff ⟹ Diff_id ∘⇩m a = a ∧ a ∘⇩m Diff_id = a› 4. ‹Diff_id ∈ Diff› 5. ‹∀x∈Diff. ∃y∈Diff. x ∘⇩m y = Diff_id ∧ y ∘⇩m x = Diff_id›*) show assoc: "Diff_comp (Diff_comp a b) c = Diff_comp a (Diff_comp b c)" if asms: "a ∈ Diff" "b ∈ Diff" "c ∈ Diff" for a and b and c using map_comp_assoc (*‹(?h::?'d ⇒ ?'b option) ∘⇩m (?g::?'c ⇒ ?'d option) ∘⇩m (?f::?'a ⇒ ?'c option) = ?h ∘⇩m (?g ∘⇩m ?f)›*) by blast show id_comp: "Diff_comp Diff_id a = a ∧ Diff_comp a Diff_id = a" if "a ∈ Diff" for a apply (standard; standard) (*goal: ‹Diff_id ∘⇩m (a::'a ⇒ 'a option) = a ∧ a ∘⇩m Diff_id = a›*) subgoal for using automorphismD[OF DiffD [ OF that ]] (*‹∃f'. c_automorphism k charts (λx. the (a x)) f'› ‹dom a = carrier›*) c_automorphism.in_dest (*‹⟦c_automorphism ?k ?charts ?f ?f'; ?x ∈ manifold.carrier ?charts⟧ ⟹ ?f ?x ∈ manifold.carrier ?charts›*) by (smt (verit, del_insts) domIff (*‹(?a ∈ dom ?m) = (?m ?a ≠ None)›*) map_comp_simps( (*‹?m2.0 ?k = None ⟹ (?m1.0 ∘⇩m ?m2.0) ?k = None›*) 1) map_comp_simps( (*‹?m2.0 ?k = Some ?k' ⟹ (?m1.0 ∘⇩m ?m2.0) ?k = ?m1.0 ?k'›*) 2) option.collapse (*‹?option ≠ None ⟹ Some (the ?option) = ?option›*)) subgoal for using automorphismD[OF DiffD [ OF that ]] (*‹∃f'. c_automorphism k charts (λx. the (a x)) f'› ‹dom a = carrier›*) c_automorphism.in_dest (*‹⟦c_automorphism ?k ?charts ?f ?f'; ?x ∈ manifold.carrier ?charts⟧ ⟹ ?f ?x ∈ manifold.carrier ?charts›*) by (smt (verit, ccfv_threshold) domIff (*‹(?a ∈ dom ?m) = (?m ?a ≠ None)›*) map_comp_simps( (*‹?m2.0 ?k = None ⟹ (?m1.0 ∘⇩m ?m2.0) ?k = None›*) 1) map_comp_simps( (*‹?m2.0 ?k = Some ?k' ⟹ (?m1.0 ∘⇩m ?m2.0) ?k = ?m1.0 ?k'›*) 2)) . show id_mem: "Diff_id ∈ Diff" by (auto simp: automorphism_partial_id (*‹automorphism Diff_id›*)) { fix x and y assume x: "x∈Diff" and y: "y∈Diff" (*‹(x::'a ⇒ 'a option) ∈ Diff› ‹(y::'a ⇒ 'a option) ∈ Diff›*) show "Diff_comp x y ∈ Diff" using aut_comp (*‹⟦automorphism ?f; automorphism ?g⟧ ⟹ automorphism (?g ∘⇩m ?f)›*) DiffD (*‹?f ∈ Diff ⟹ automorphism ?f›*) x (*‹x ∈ Diff›*) y (*‹y ∈ Diff›*) by auto } { fix f assume f: "f∈Diff" (*‹(f::'a ⇒ 'a option) ∈ Diff›*) obtain g where g: "g∈Diff" "∀x ∈ carrier. the (g (the (f x))) = x" "∀x ∈ carrier. the (f (the (g x))) = x" (*goal: ‹(⋀g. ⟦g ∈ Diff; ∀x∈carrier. the (g (the (f x))) = x; ∀x∈carrier. the (f (the (g x))) = x⟧ ⟹ thesis) ⟹ thesis›*) using obtain_inverse_aut[OF DiffD [ OF f ]] (*‹(⋀f'. ⟦automorphism f'; ⋀x. x ∈ carrier ⟹ the (f' (the (f x))) = x; ⋀x. x ∈ carrier ⟹ the (f (the (f' x))) = x⟧ ⟹ ?thesis) ⟹ ?thesis›*) by (metis DiffI (*‹automorphism ?f ⟹ ?f ∈ Diff›*)) have "∃g∈Diff. Diff_comp f g = Diff_id ∧ Diff_comp g f = Diff_id" apply (intro bexI[OF _ g(1)] (*‹(?P::('a ⇒ 'a option) ⇒ bool) (g::'a ⇒ 'a option) ⟹ ∃x::'a ⇒ 'a option∈Diff. ?P x›*)) (*goal: ‹∃g∈Diff. f ∘⇩m g = Diff_id ∧ g ∘⇩m f = Diff_id›*) using g (*‹g ∈ Diff› ‹∀x∈carrier. the (g (the (f x))) = x› ‹∀x∈carrier. the (f (the (g x))) = x›*) aut_comp_simps(1) (*‹⟦?x ∈ carrier; automorphism ?f⟧ ⟹ (?g ∘⇩m ?f) ?x = ?g (the (?f ?x))›*) aut_to (*‹⟦automorphism ?f; ?x ∈ carrier⟧ ⟹ the (?f ?x) ∈ carrier›*) by (metis (opaque_lifting) DiffD (*‹?f ∈ Diff ⟹ automorphism ?f›*) automorphismD( (*‹automorphism ?f ⟹ dom ?f = carrier›*) 2) domIff (*‹(?a ∈ dom ?m) = (?m ?a ≠ None)›*) f (*‹f ∈ Diff›*) map_comp_simps( (*‹?m2.0 ?k = None ⟹ (?m1.0 ∘⇩m ?m2.0) ?k = None›*) 1) option.collapse (*‹?option ≠ None ⟹ Some (the ?option) = ?option›*)) } thus "∀x∈Diff. ∃y∈Diff. Diff_comp x y = Diff_id ∧ Diff_comp y x = Diff_id" by blast qed sublocale Diff_grp: grp_on Diff Diff_comp Diff_id by (rule Diff_grp (*‹grp_on Diff (∘⇩m) Diff_id›*)) abbreviation "Diff_inv ≡ Diff_grp.invs" abbreviation "Diff_comp_inv ≡ Diff_grp.mns" end section ‹Coordinates and isomorphisms of tangent spaces› text ‹To work with local coordinates, we fix an atlas chart on a manifold.› locale c_manifold_local = c_manifold + fixes ψ assumes ψ [simp]: "ψ ∈ atlas" begin sublocale sub_ψ: submanifold charts k "domain ψ" apply unfold_locales (*goal: ‹submanifold (charts::('a, 'b) chart set) (k::enat) (domain (ψ::('a, 'b) chart))›*) by simp lemma sub_ψ_carrier: "sub_ψ.sub.carrier = domain ψ" unfolding "sub_ψ.sub.carrier_def" charts_submanifold_def manifold.carrier_def (*goal: ‹⋃ (domain ` restrict_chart (domain ψ) ` charts) = domain ψ›*) apply auto (*goal: ‹⋃ (domain ` restrict_chart (domain (ψ::('a, 'b) chart)) ` (charts::('a, 'b) chart set)) = domain ψ›*) by (meson ψ (*‹ψ ∈ atlas›*) carrierE (*‹⟦?x ∈ carrier; ⋀c. ⟦c ∈ charts; ?x ∈ domain c⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) in_carrier_atlasI (*‹⟦?c ∈ atlas; ?x ∈ domain ?c⟧ ⟹ ?x ∈ carrier›*)) lemma sub_ψ: "ψ ∈ sub_ψ.sub.atlas" by (metis ψ (*‹ψ ∈ atlas›*) atlas_is_atlas (*‹⟦?a1.0 ∈ atlas; ?a2.0 ∈ atlas⟧ ⟹ k-smooth_compat ?a1.0 ?a2.0›*) c_manifold.maximal_atlas (*‹⟦c_manifold ?charts ?k; ⋀c'. c' ∈ c_manifold.atlas ?charts ?k ⟹ ?k-smooth_compat ?c c'; domain ?c ⊆ manifold.carrier ?charts⟧ ⟹ ?c ∈ c_manifold.atlas ?charts ?k›*) equalityE (*‹⟦?A = ?B; ⟦?A ⊆ ?B; ?B ⊆ ?A⟧ ⟹ ?P⟧ ⟹ ?P›*) sub_ψ.sub.c_manifold_axioms (*‹c_manifold (charts_submanifold (domain ψ)) k›*) sub_ψ.submanifold_atlasE (*‹?c ∈ sub_ψ.sub.atlas ⟹ ?c ∈ atlas›*) sub_ψ_carrier (*‹sub_ψ.sub.carrier = domain ψ›*)) text ‹Although the inclusion is not a diffeomorphism, the push-forward still defines a vector isomorphism. Therefore, it has an inverse.› notation sub_ψ.inclusion.push_forward (‹dι›) lemma (in c_manifold) diffeomorphism_chart: assumes c: "c ∈ atlas" shows "diffeomorphism k (charts_submanifold (domain c)) (manifold_eucl.charts_submanifold (codomain c)) (apply_chart c) (inv_chart c)" proof (-) (*goal: ‹Differentiable_Manifold.diffeomorphism k (charts_submanifold (domain c)) (manifold_eucl.dest.charts_submanifold (codomain c)) (apply_chart c) (inv_chart c)›*) have sub_c_carrier: "manifold.carrier (charts_submanifold (domain c)) = domain c" using c (*‹c ∈ atlas›*) c_manifold_axioms (*‹c_manifold charts k›*) "c_manifold_local.sub_ψ_carrier" (*‹c_manifold_local ?charts ?k ?ψ ⟹ manifold.carrier (manifold.charts_submanifold ?charts (domain ?ψ)) = domain ?ψ›*) c_manifold_local_axioms.intro (*‹?ψ ∈ c_manifold.atlas ?charts ?k ⟹ c_manifold_local_axioms ?charts ?k ?ψ›*) c_manifold_local_def (*‹c_manifold_local ?charts ?k ?ψ ≡ c_manifold ?charts ?k ∧ c_manifold_local_axioms ?charts ?k ?ψ›*) by blast interpret diff_c: diff k "charts_submanifold (domain c)" charts_eucl c using diff_apply_chart[OF c] (*‹diff k (charts_submanifold (domain c)) charts_eucl (apply_chart c)›*) . interpret diff_c_inv: diff k "manifold_eucl.charts_submanifold (codomain c)" charts "inv_chart c" using diff_inv_chart[OF c] (*‹diff (k::enat) (manifold_eucl.dest.charts_submanifold (codomain (c::('a, 'b) chart))) (charts::('a, 'b) chart set) (inv_chart c)›*) . have diff_c_inv_carrier[simp]: "diff_c_inv.src.carrier = codomain c" unfolding diff_c_inv.src.carrier_def manifold_eucl.dest.charts_submanifold_def manifold.carrier_def (*goal: ‹⋃ (domain ` restrict_chart (codomain c) ` charts_eucl) = codomain c›*) by auto show "diffeomorphism k (charts_submanifold (domain c)) (manifold_eucl.charts_submanifold (codomain c)) c (inv_chart c)" apply (unfold diffeomorphism_def (*‹Differentiable_Manifold.diffeomorphism (?k::enat) (?charts1.0::(?'a, ?'b) chart set) (?charts2.0::(?'c, ?'d) chart set) (?f::?'a ⇒ ?'c) (?f'::?'c ⇒ ?'a) ≡ diff ?k ?charts1.0 ?charts2.0 ?f ∧ diff ?k ?charts2.0 ?charts1.0 ?f' ∧ diffeomorphism_axioms ?charts1.0 ?charts2.0 ?f ?f'›*), intro conjI (*‹⟦?P::bool; ?Q::bool⟧ ⟹ ?P ∧ ?Q›*)) (*goal: ‹Differentiable_Manifold.diffeomorphism (k::enat) (charts_submanifold (domain (c::('a, 'b) chart))) (manifold_eucl.dest.charts_submanifold (codomain c)) (apply_chart c) (inv_chart c)›*) subgoal for by (auto intro: diff_c.diff_submanifold2 (*‹⟦open ?S; apply_chart c ` diff_c.src.carrier ⊆ ?S⟧ ⟹ diff k (charts_submanifold (domain c)) (manifold_eucl.dest.charts_submanifold ?S) (apply_chart c)›*) simp: sub_c_carrier (*‹diff_c.src.carrier = domain c›*)) subgoal for by (auto intro: diff_c_inv.diff_submanifold2 (*‹⟦open (?S::'a set); inv_chart (c::('a, 'b) chart) ` diff_c_inv.src.carrier ⊆ ?S⟧ ⟹ diff (k::enat) (manifold_eucl.dest.charts_submanifold (codomain c)) (charts_submanifold ?S) (inv_chart c)›*)) apply unfold_locales (*goals: 1. ‹⋀x::'a. x ∈ diff_c.src.carrier ⟹ inv_chart (c::('a, 'b) chart) (apply_chart c x) = x› 2. ‹⋀y::'b. y ∈ diff_c_inv.src.carrier ⟹ apply_chart (c::('a, 'b) chart) (inv_chart c y) = y› discuss goal 1*) apply (simp add: sub_c_carrier (*‹diff_c.src.carrier = domain c›*)) (*discuss goal 2*) apply (simp add: sub_c_carrier (*‹diff_c.src.carrier = domain c›*)) (*proven 2 subgoals*) . qed sublocale diffeo_ψ: diffeomorphism k "charts_submanifold (domain ψ)" "manifold_eucl.charts_submanifold (codomain ψ)" ψ "inv_chart ψ" using diffeomorphism_chart (*‹?c ∈ atlas ⟹ Differentiable_Manifold.diffeomorphism k (charts_submanifold (domain ?c)) (manifold_eucl.dest.charts_submanifold (codomain ?c)) (apply_chart ?c) (inv_chart ?c)›*) by auto lemma diffeo_ψ_inv: "diffeomorphism k (manifold_eucl.charts_submanifold (codomain ψ)) (charts_submanifold (domain ψ)) (inv_chart ψ) ψ" using "diffeo_ψ.diffeo_f'" (*‹Differentiable_Manifold.diffeomorphism k (manifold_eucl.dest.charts_submanifold (codomain ψ)) (charts_submanifold (domain ψ)) (inv_chart ψ) (apply_chart ψ)›*) . abbreviation differential_apply_chart :: "(('a⇒real)⇒real) ⇒ (('b⇒real)⇒real)" (‹dψ›) where (*[simp]:*) "differential_apply_chart ≡ diffeo_ψ.push_forward" abbreviation differential_inv_chart :: "(('b⇒real)⇒real) ⇒ (('a⇒real)⇒real)" (‹dψ¯›) where (*[simp]:*) "differential_inv_chart ≡ diffeo_ψ.inv.push_forward" sublocale diff_fun_ψ: diff_fun k "charts_submanifold (domain ψ)" ψ using diff_apply_chart[OF ψ] (*‹diff k (charts_submanifold (domain ψ)) charts_eucl (apply_chart ψ)›*) by (simp add: diff_fun.intro (*‹diff ?k ?charts charts_eucl ?f ⟹ diff_fun ?k ?charts ?f›*)) sublocale sub_eucl: submanifold charts_eucl k "codomain ψ" apply unfold_locales (*goal: ‹submanifold charts_eucl (k::enat) (codomain (ψ::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart))›*) by simp notation sub_eucl.inclusion.push_forward (‹dκ›) text ‹Inverses for the pushforward under the inclusion. If we are to ``glue together'' coordinate charts on multiple domains, these pushforwards need to coordinatise tangent spaces over a small neighbourhood on the manifold (a thin bundle).› abbreviation differential_inclusion_inv_at (‹dι¯›) where "dι¯ p ≡ restrict0 (tangent_space p) (the_inv_into (sub_ψ.sub.tangent_space p) dι)" abbreviation differential_inclusion_eucl_inv_at (‹dκ¯›) where "dκ¯ p ≡ restrict0 (manifold_eucl.tangent_space k (ψ p)) (the_inv_into (diffeo_ψ.dest.tangent_space (ψ p)) dκ)" end locale c_manifold_point = c_manifold_local + fixes p assumes p [simp]: "p∈domain ψ" begin text ‹Given local coordinates from a chart \<^term>‹ψ› on a manifold, we can coordinatize the tangent space at any point \<^term>‹p› contained in the \<^term>‹domain ψ›.› abbreviation "T⇩pM ≡ tangent_space p" abbreviation "T⇩pU ≡ sub_ψ.sub.tangent_space p" abbreviation "T⇩ψ⇩pE ≡ manifold_eucl.tangent_space k (ψ p)" abbreviation "T⇩ψ⇩pψU ≡ diffeo_ψ.dest.tangent_space (ψ p)" abbreviation dRestr (‹dκ¯›) where "dRestr ≡ differential_inclusion_eucl_inv_at p" abbreviation dRestr2 (‹dι¯›) where "dRestr2 ≡ differential_inclusion_inv_at p" lemma ψp_in [simp]: "ψ p ∈ diffeo_ψ.dest.carrier" using "diffeo_ψ.defined" (*‹apply_chart ψ ` sub_ψ.sub.carrier ⊆ diffeo_ψ.dest.carrier›*) "sub_ψ_carrier" (*‹sub_ψ.sub.carrier = domain ψ›*) by force lemma bij_betw_directional_derivative: "bij_betw (directional_derivative k (ψ p)) UNIV T⇩ψ⇩pE" if "k=∞" unfolding bij_betw_def (*goal: ‹inj (directional_derivative k (apply_chart ψ p)) ∧ range (directional_derivative k (apply_chart ψ p)) = T⇩ψ⇩pE›*) using that (*‹(k::enat) = ∞›*) by (simp add: inj_on_directional_derivative (*‹?k ≠ 0 ⟹ inj_on (directional_derivative ?k ?a) ?S›*) surj_directional_derivative (*‹?k = ∞ ⟹ range (directional_derivative ?k ?a) = manifold_eucl.tangent_space ?k ?a›*)) end lemma (in c_manifold) c_manifold_point: assumes "c ∈ atlas" "p ∈ domain c" shows "c_manifold_point charts k c p" using assms (*‹c ∈ atlas› ‹p ∈ domain c›*) apply unfold_locales (*goals: 1. ‹⟦c ∈ atlas; p ∈ domain c⟧ ⟹ c ∈ atlas› 2. ‹⟦c ∈ atlas; p ∈ domain c⟧ ⟹ p ∈ domain c› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . subsection ‹Results extracted from \<^theory>‹Smooth_Manifolds.Tangent_Space›.› text ‹Some of the proofs in the above theory are quite long, and contain statements that may be useful outside that proof. Some proofs in this subsection are due to Immler \& Zhan \cite{Smooth_Manifolds-AFP}.› definition (in c_manifold_point) coord_fun where "coord_fun X i = X (λx. (x - (ψ p)) ∙ i)" lemma (in c_manifold_point) euclidean_tangent_space_coordinatesE: fixes X defines "v ≡ coord_fun X" assumes "X ∈ manifold_eucl.tangent_space k (ψ p)" "k=∞" shows "X = directional_derivative k (ψ p) (∑i∈Basis. v i *⇩R i)" ― ‹Extracted from Immler and Zhan's @{thm surj_directional_derivative}.› proof (-) (*goal: ‹X = directional_derivative k (apply_chart ψ p) (∑i∈Basis. v i *⇩R i)›*) have linear_X: "manifold_eucl.linear_diff_fun k X" apply (rule manifold_eucl.tangent_space_linear_on (*‹?X ∈ manifold_eucl.tangent_space ?k ?p ⟹ linear_on (manifold_eucl.diff_fun_space ?k) UNIV (*⇩R) (*⇩R) ?X›*)) (*goal: ‹linear_on manifold_eucl.dest.diff_fun_space UNIV (*⇩R) (*⇩R) X›*) by fact note X_sum = manifold_eucl.diff_fun_space.linear_sum'[OF _ _ linear_X] (*‹⟦∀x. x ∈ manifold_eucl.dest.diff_fun_space ⟶ X x ∈ UNIV; ∀x. x ∈ ?S ⟶ ?g x ∈ manifold_eucl.dest.diff_fun_space⟧ ⟹ X (sum ?g ?S) = (∑a∈?S. X (?g a))›*) note X_add = manifold_eucl.diff_fun_space.linear_add[OF _ _ _ linear_X] (*‹⟦∀x::'b ⇒ real. x ∈ manifold_eucl.dest.diff_fun_space ⟶ (X::('b ⇒ real) ⇒ real) x ∈ UNIV; (?b1.0::'b ⇒ real) ∈ manifold_eucl.dest.diff_fun_space; (?b2.0::'b ⇒ real) ∈ manifold_eucl.dest.diff_fun_space⟧ ⟹ X (?b1.0 + ?b2.0) = X ?b1.0 + X ?b2.0›*) note X_scale = manifold_eucl.diff_fun_space.linear_scale[OF _ _ linear_X] (*‹⟦∀x. x ∈ manifold_eucl.dest.diff_fun_space ⟶ X x ∈ UNIV; ?b ∈ manifold_eucl.dest.diff_fun_space⟧ ⟹ X (?r *⇩R ?b) = ?r *⇩R X ?b›*) have X_is_derivative: "X f = directional_derivative k (apply_chart ψ p) (∑i∈Basis. v i *⇩R i) f" if f: "f ∈ manifold_eucl.dest.diff_fun_space" for f proof (-) (*goal: ‹(X::('b ⇒ real) ⇒ real) (f::'b ⇒ real) = directional_derivative (k::enat) (apply_chart (ψ::('a, 'b) chart) (p::'a)) (∑i::'b∈Basis. (v::'b ⇒ real) i *⇩R i) f›*) have "smooth_on UNIV f" using ‹k = ∞› (*‹k = ∞›*) f (*‹f ∈ manifold_eucl.dest.diff_fun_space›*) by simp from smooth_on_Taylor2E[OF this, of "ψ p"] (*‹(⋀g::'b ⇒ 'b ⇒ 'b ⇒ real. ⟦⋀Y::'b. (f::'b ⇒ real) Y = f (apply_chart (ψ::('a, 'b) chart) (p::'a)) + frechet_derivative f (at (apply_chart ψ p)) (Y - apply_chart ψ p) + (∑i::'b∈Basis. ∑j::'b∈Basis. (Y - apply_chart ψ p) ∙ j * ((Y - apply_chart ψ p) ∙ i) * g i j Y); ⋀(i::'b) j::'b. ⟦i ∈ Basis; j ∈ Basis⟧ ⟹ smooth_on UNIV (g i j)⟧ ⟹ ?thesis::bool) ⟹ ?thesis›*) obtain g where f_exp: "⋀x. f x = f (ψ p) + frechet_derivative f (at (ψ p)) (x - (ψ p)) + (∑i∈Basis. ∑j∈Basis. (x - (ψ p)) ∙ j * ((x - (ψ p)) ∙ i) * g i j x)" and g: "⋀i j. i ∈ Basis ⟹ j ∈ Basis ⟹ smooth_on UNIV (g i j)" (*goal: ‹(⋀g. ⟦⋀x. f x = f (apply_chart ψ p) + frechet_derivative f (at (apply_chart ψ p)) (x - apply_chart ψ p) + (∑i∈Basis. ∑j∈Basis. (x - apply_chart ψ p) ∙ j * ((x - apply_chart ψ p) ∙ i) * g i j x); ⋀i j. ⟦i ∈ Basis; j ∈ Basis⟧ ⟹ smooth_on UNIV (g i j)⟧ ⟹ thesis) ⟹ thesis›*) by auto note [simp] = assms(3) (*‹k = ∞›*) have "*": "X (λx. ∑i∈Basis. ∑j∈Basis. (x - (ψ p)) ∙ j * ((x - (ψ p)) ∙ i) * g i j x) = 0" apply (subst X_sum[unfolded sum_fun_def] (*‹⟦∀x. x ∈ manifold_eucl.dest.diff_fun_space ⟶ X x ∈ UNIV; ∀x. x ∈ ?S ⟶ ?g x ∈ manifold_eucl.dest.diff_fun_space⟧ ⟹ X (λx. ∑i∈?S. ?g i x) = (∑a∈?S. X (?g a))›*), safe) (*goal: ‹X (λx. ∑i∈Basis. ∑j∈Basis. (x - apply_chart ψ p) ∙ j * ((x - apply_chart ψ p) ∙ i) * g i j x) = 0›*) subgoal for by auto subgoal for by (auto intro!: smooth_on_sum (*‹⟦⋀i. ⟦i ∈ ?F; finite ?F⟧ ⟹ ?n-smooth_on ?S (?f i); open ?S⟧ ⟹ ?n-smooth_on ?S (λx. ∑i∈?F. ?f i x)›*) smooth_on_mult (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x * ?g x)›*) smooth_on_inner (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x ∙ ?g x)›*) smooth_on_minus (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x - ?g x)›*) simp: g (*‹⟦?i4 ∈ Basis; ?j4 ∈ Basis⟧ ⟹ smooth_on UNIV (g ?i4 ?j4)›*)) apply (intro sum.neutral (*‹∀x∈?A. ?g x = 0 ⟹ sum ?g ?A = 0›*) ballI (*‹(⋀x. x ∈ ?A ⟹ ?P x) ⟹ ∀x∈?A. ?P x›*)) (*goal: ‹(∑a∈Basis. X (λx. ∑j∈Basis. (x - apply_chart ψ p) ∙ j * ((x - apply_chart ψ p) ∙ a) * g a j x)) = 0›*) apply (subst X_sum[unfolded sum_fun_def] (*‹⟦∀x. x ∈ manifold_eucl.dest.diff_fun_space ⟶ X x ∈ UNIV; ∀x. x ∈ ?S ⟶ ?g x ∈ manifold_eucl.dest.diff_fun_space⟧ ⟹ X (λx. ∑i∈?S. ?g i x) = (∑a∈?S. X (?g a))›*)) (*goal: ‹⋀x. x ∈ Basis ⟹ X (λxa. ∑j∈Basis. (xa - apply_chart ψ p) ∙ j * ((xa - apply_chart ψ p) ∙ x) * g x j xa) = 0›*) subgoal for by (auto intro!: smooth_on_mult (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x * ?g x)›*) smooth_on_inner (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x ∙ ?g x)›*) smooth_on_minus (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x - ?g x)›*) g (*‹⟦?i4 ∈ Basis; ?j4 ∈ Basis⟧ ⟹ smooth_on UNIV (g ?i4 ?j4)›*)) subgoal for by (auto intro!: smooth_on_mult (*‹⟦(?k::enat)-smooth_on (?S::?'d set) (?f::?'d ⇒ ?'a); ?k-smooth_on ?S (?g::?'d ⇒ ?'a); open ?S⟧ ⟹ ?k-smooth_on ?S (λx::?'d. ?f x * ?g x)›*) smooth_on_inner (*‹⟦(?k::enat)-smooth_on (?S::?'d set) (?f::?'d ⇒ ?'a); ?k-smooth_on ?S (?g::?'d ⇒ ?'a); open ?S⟧ ⟹ ?k-smooth_on ?S (λx::?'d. ?f x ∙ ?g x)›*) smooth_on_minus (*‹⟦(?k::enat)-smooth_on (?S::?'a set) (?f::?'a ⇒ ?'b); ?k-smooth_on ?S (?g::?'a ⇒ ?'b); open ?S⟧ ⟹ ?k-smooth_on ?S (λx::?'a. ?f x - ?g x)›*) g (*‹⟦(?i4::'b) ∈ Basis; (?j4::'b) ∈ Basis⟧ ⟹ smooth_on UNIV ((g::'b ⇒ 'b ⇒ 'b ⇒ real) ?i4 ?j4)›*)) proof (intro sum.neutral (*‹∀x::?'b::type∈?A::?'b::type set. (?g::?'b::type ⇒ ?'a::comm_monoid_add) x = (0::?'a::comm_monoid_add) ⟹ sum ?g ?A = (0::?'a::comm_monoid_add)›*) ballI (*‹(⋀x::?'a::type. x ∈ (?A::?'a::type set) ⟹ (?P::?'a::type ⇒ bool) x) ⟹ ∀x::?'a::type∈?A. ?P x›*)) (*goal: ‹⋀x xa. ⟦x ∈ Basis; xa ∈ Basis⟧ ⟹ X (λxb. (xb - apply_chart ψ p) ∙ xa * ((xb - apply_chart ψ p) ∙ x) * g x xa xb) = 0›*) fix i :: 'b and j :: 'b assume ij: "i ∈ Basis" "j ∈ Basis" (*‹(i::'b) ∈ Basis› ‹(j::'b) ∈ Basis›*) have "X (λxb. (xb - (ψ p)) ∙ j * ((xb - (ψ p)) ∙ i) * g i j xb) = X ((λxb. (xb - (ψ p)) ∙ j) * (λxb. ((xb - (ψ p)) ∙ i) * g i j xb))" by (auto simp: times_fun_def (*‹?f * ?g = (λx. ?f x * ?g x)›*) ac_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹((?a ∧ ?b) ∧ ?c) = (?a ∧ ?b ∧ ?c)› ‹(?a ∧ ?b) = (?b ∧ ?a)› ‹(?b ∧ ?a ∧ ?c) = (?a ∧ ?b ∧ ?c)› ‹((?a ∨ ?b) ∨ ?c) = (?a ∨ ?b ∨ ?c)› ‹(?a ∨ ?b) = (?b ∨ ?a)› ‹(?b ∨ ?a ∨ ?c) = (?a ∨ ?b ∨ ?c)› and more 31 facts*)) also (*calculation: ‹X (λxb. (xb - apply_chart ψ p) ∙ j * ((xb - apply_chart ψ p) ∙ i) * g i j xb) = X ((λxb. (xb - apply_chart ψ p) ∙ j) * (λxb. (xb - apply_chart ψ p) ∙ i * g i j xb))›*) have "… = 0" apply (rule manifold_eucl.derivation_times_eq_zeroI (*‹⟦?X ∈ manifold_eucl.tangent_space ?k ?p; ?f ∈ manifold_eucl.diff_fun_space ?k; ?g ∈ manifold_eucl.diff_fun_space ?k; ?f ?p = 0; ?g ?p = 0⟧ ⟹ ?X (?f * ?g) = 0›*)) (*goal: ‹(X::('b ⇒ real) ⇒ real) ((λxb::'b. (xb - apply_chart (ψ::('a, 'b) chart) (p::'a)) ∙ (j::'b)) * (λxb::'b. (xb - apply_chart ψ p) ∙ (i::'b) * (g::'b ⇒ 'b ⇒ 'b ⇒ real) i j xb)) = (0::real)›*) apply fact (*top goal: ‹(X::('b ⇒ real) ⇒ real) ∈ manifold_eucl.tangent_space (?k::enat) (?p::'b)› and 4 goals remain*) subgoal for by (auto intro!: smooth_on_sum (*‹⟦⋀i. ⟦i ∈ ?F; finite ?F⟧ ⟹ ?n-smooth_on ?S (?f i); open ?S⟧ ⟹ ?n-smooth_on ?S (λx. ∑i∈?F. ?f i x)›*) smooth_on_mult (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x * ?g x)›*) smooth_on_inner (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x ∙ ?g x)›*) smooth_on_minus (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x - ?g x)›*)) subgoal for by (auto intro!: smooth_on_mult (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x * ?g x)›*) smooth_on_inner (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x ∙ ?g x)›*) smooth_on_minus (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x - ?g x)›*) g (*‹⟦?i4 ∈ Basis; ?j4 ∈ Basis⟧ ⟹ smooth_on UNIV (g ?i4 ?j4)›*) ij (*‹i ∈ Basis› ‹j ∈ Basis›*)) (*goals: 1. ‹(apply_chart ψ p - apply_chart ψ p) ∙ j = 0› 2. ‹(apply_chart ψ p - apply_chart ψ p) ∙ i * g i j (apply_chart ψ p) = 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . finally (*calculation: ‹X (λxb. (xb - apply_chart ψ p) ∙ j * ((xb - apply_chart ψ p) ∙ i) * g i j xb) = 0›*) show "X (λxb. (xb - (ψ p)) ∙ j * ((xb - (ψ p)) ∙ i) * g i j xb) = 0" by simp qed from f (*‹(f::'b ⇒ real) ∈ manifold_eucl.dest.diff_fun_space›*) have "smooth_on UNIV f" by auto have "f differentiable at (ψ p)" apply (rule differentiable_onD (*‹⟦?f differentiable_on ?S; ?x ∈ ?S⟧ ⟹ ?f differentiable at ?x within ?S›*)) (*goals: 1. ‹f differentiable_on UNIV› 2. ‹apply_chart ψ p ∈ UNIV› discuss goal 1*) apply (rule smooth_on_imp_differentiable_on (*‹⟦?k-smooth_on ?S ?f; 0 < ?k⟧ ⟹ ?f differentiable_on ?S›*)) (*goals: 1. ‹?k3-smooth_on UNIV f› 2. ‹0 < ?k3› discuss goal 1*) apply fact (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . interpret Df: linear "frechet_derivative f (at (ψ p))" apply (rule linear_frechet_derivative (*‹?f differentiable ?net ⟹ linear (frechet_derivative ?f ?net)›*)) (*goal: ‹linear (frechet_derivative (f::'b::euclidean_space ⇒ real) (at (apply_chart (ψ::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart) (p::'a::{second_countable_topology,t2_space}))))›*) by fact have X_mult_right: "k-smooth_on UNIV xx ⟹ X (λx. xx x * cc) = X xx * cc" for xx and cc using X_scale[unfolded scaleR_fun_def, simplified, of xx cc] (*‹smooth_on UNIV xx ⟹ X (λx. cc * xx x) = cc * X xx›*) by (auto simp: ac_simps (*‹(?a::?'a::semigroup_add) + (?b::?'a::semigroup_add) + (?c::?'a::semigroup_add) = ?a + (?b + ?c)› ‹(?a::?'a::ab_semigroup_add) + (?b::?'a::ab_semigroup_add) = ?b + ?a› ‹(?b::?'a::ab_semigroup_add) + ((?a::?'a::ab_semigroup_add) + (?c::?'a::ab_semigroup_add)) = ?a + (?b + ?c)› ‹(?a::?'a::semigroup_mult) * (?b::?'a::semigroup_mult) * (?c::?'a::semigroup_mult) = ?a * (?b * ?c)› ‹(?a::?'a::ab_semigroup_mult) * (?b::?'a::ab_semigroup_mult) = ?b * ?a› ‹(?b::?'a::ab_semigroup_mult) * ((?a::?'a::ab_semigroup_mult) * (?c::?'a::ab_semigroup_mult)) = ?a * (?b * ?c)› ‹(((?a::bool) ∧ (?b::bool)) ∧ (?c::bool)) = (?a ∧ ?b ∧ ?c)› ‹((?a::bool) ∧ (?b::bool)) = (?b ∧ ?a)› ‹((?b::bool) ∧ (?a::bool) ∧ (?c::bool)) = (?a ∧ ?b ∧ ?c)› ‹(((?a::bool) ∨ (?b::bool)) ∨ (?c::bool)) = (?a ∨ ?b ∨ ?c)› ‹((?a::bool) ∨ (?b::bool)) = (?b ∨ ?a)› ‹((?b::bool) ∨ (?a::bool) ∨ (?c::bool)) = (?a ∨ ?b ∨ ?c)› and more 31 facts*)) have blf: "bounded_linear (frechet_derivative f (at (ψ p)))" apply (rule has_derivative_bounded_linear (*‹(?f has_derivative ?f') ?F ⟹ bounded_linear ?f'›*)) (*goal: ‹bounded_linear (frechet_derivative f (at (apply_chart ψ p)))›*) apply (rule frechet_derivative_worksI (*‹?f differentiable ?net ⟹ (?f has_derivative frechet_derivative ?f ?net) ?net›*)) (*goal: ‹(?f has_derivative frechet_derivative f (at (apply_chart ψ p))) ?F›*) by fact note smooth_on_frechet = smooth_on_compose[OF bounded_linear.smooth_on [ OF blf ], unfolded o_def, OF _ _ open_UNIV subset_UNIV] (*‹⟦?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. frechet_derivative f (at (apply_chart ψ p)) (?g x))›*) have "**": "X (λx. frechet_derivative f (at (ψ p)) (x - (ψ p))) = frechet_derivative f (at (ψ p)) (∑i∈Basis. v i *⇩R i)" unfolding assms(1) coord_fun_def (*goal: ‹X (λx. frechet_derivative f (at (apply_chart ψ p)) (x - apply_chart ψ p)) = frechet_derivative f (at (apply_chart ψ p)) (∑i∈Basis. X (λx. (x - apply_chart ψ p) ∙ i) *⇩R i)›*) apply (subst frechet_derivative_componentwise (*‹?f differentiable at ?a ⟹ frechet_derivative ?f (at ?a) ?v = (∑i∈Basis. ?v ∙ i * frechet_derivative ?f (at ?a) i)›*)) (*goal: ‹X (λx. frechet_derivative f (at (apply_chart ψ p)) (x - apply_chart ψ p)) = frechet_derivative f (at (apply_chart ψ p)) (∑i∈Basis. X (λx. (x - apply_chart ψ p) ∙ i) *⇩R i)›*) subgoal for by fact apply (subst X_sum[unfolded sum_fun_def] (*‹⟦∀x. x ∈ manifold_eucl.dest.diff_fun_space ⟶ X x ∈ UNIV; ∀x. x ∈ ?S ⟶ ?g x ∈ manifold_eucl.dest.diff_fun_space⟧ ⟹ X (λx. ∑i∈?S. ?g i x) = (∑a∈?S. X (?g a))›*)) (*goal: ‹(X::('b ⇒ real) ⇒ real) (λx::'b. ∑i::'b∈Basis. (x - apply_chart (ψ::('a, 'b) chart) (p::'a)) ∙ i * frechet_derivative (f::'b ⇒ real) (at (apply_chart ψ p)) i) = frechet_derivative f (at (apply_chart ψ p)) (∑i::'b∈Basis. X (λx::'b. (x - apply_chart ψ p) ∙ i) *⇩R i)›*) subgoal for by (auto intro!: smooth_on_sum (*‹⟦⋀i. ⟦i ∈ ?F; finite ?F⟧ ⟹ ?n-smooth_on ?S (?f i); open ?S⟧ ⟹ ?n-smooth_on ?S (λx. ∑i∈?F. ?f i x)›*) smooth_on_mult (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x * ?g x)›*) smooth_on_inner (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x ∙ ?g x)›*) smooth_on_minus (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x - ?g x)›*)) subgoal for by (auto intro!: smooth_on_frechet (*‹⟦?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. frechet_derivative f (at (apply_chart ψ p)) (?g x))›*) smooth_on_minus (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x - ?g x)›*) smooth_on_mult (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x * ?g x)›*) smooth_on_inner (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x ∙ ?g x)›*)) apply (subst X_mult_right (*‹k-smooth_on UNIV ?xx4 ⟹ X (λx. ?xx4 x * ?cc4) = X ?xx4 * ?cc4›*)) (*goal: ‹(∑a∈Basis. X (λx. (x - apply_chart ψ p) ∙ a * frechet_derivative f (at (apply_chart ψ p)) a)) = frechet_derivative f (at (apply_chart ψ p)) (∑i∈Basis. X (λx. (x - apply_chart ψ p) ∙ i) *⇩R i)›*) subgoal for by (auto intro!: smooth_on_sum (*‹⟦⋀i. ⟦i ∈ ?F; finite ?F⟧ ⟹ ?n-smooth_on ?S (?f i); open ?S⟧ ⟹ ?n-smooth_on ?S (λx. ∑i∈?F. ?f i x)›*) smooth_on_mult (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x * ?g x)›*) smooth_on_inner (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x ∙ ?g x)›*) smooth_on_minus (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x - ?g x)›*)) apply (subst Df.sum (*‹frechet_derivative f (at (apply_chart ψ p)) (sum ?g ?S) = (∑a∈?S. frechet_derivative f (at (apply_chart ψ p)) (?g a))›*)) (*goal: ‹(∑a∈Basis. X (λx. (x - apply_chart ψ p) ∙ a) * frechet_derivative f (at (apply_chart ψ p)) a) = frechet_derivative f (at (apply_chart ψ p)) (∑i∈Basis. X (λx. (x - apply_chart ψ p) ∙ i) *⇩R i)›*) apply (rule sum.cong (*‹⟦?A = ?B; ⋀x. x ∈ ?B ⟹ ?g x = ?h x⟧ ⟹ sum ?g ?A = sum ?h ?B›*)) (*goals: 1. ‹Basis = Basis› 2. ‹⋀x. x ∈ Basis ⟹ X (λxa. (xa - apply_chart ψ p) ∙ x) * frechet_derivative f (at (apply_chart ψ p)) x = frechet_derivative f (at (apply_chart ψ p)) (X (λxa. (xa - apply_chart ψ p) ∙ x) *⇩R x)› discuss goal 1*) apply (rule refl (*‹?t = ?t›*)) (*discuss goal 2*) apply (subst Df.scaleR (*‹frechet_derivative f (at (apply_chart ψ p)) (?r *⇩R ?b) = ?r *⇩R frechet_derivative f (at (apply_chart ψ p)) ?b›*)) (*goal: ‹⋀x. x ∈ Basis ⟹ X (λxa. (xa - apply_chart ψ p) ∙ x) * frechet_derivative f (at (apply_chart ψ p)) x = frechet_derivative f (at (apply_chart ψ p)) (X (λxa. (xa - apply_chart ψ p) ∙ x) *⇩R x)›*) apply auto (*proven 2 subgoals*) . show "X f = directional_derivative k (ψ p) (∑i∈Basis. v i *⇩R i) f" apply (subst f_exp[abs_def] (*‹f::'b ⇒ real ≡ λx::'b. f (apply_chart (ψ::('a, 'b) chart) (p::'a)) + frechet_derivative f (at (apply_chart ψ p)) (x - apply_chart ψ p) + (∑i::'b∈Basis. ∑j::'b∈Basis. (x - apply_chart ψ p) ∙ j * ((x - apply_chart ψ p) ∙ i) * (g::'b ⇒ 'b ⇒ 'b ⇒ real) i j x)›*)) (*goal: ‹X f = directional_derivative k (apply_chart ψ p) (∑i∈Basis. v i *⇩R i) f›*) apply (subst X_add[unfolded plus_fun_def] (*‹⟦∀x. x ∈ manifold_eucl.dest.diff_fun_space ⟶ X x ∈ UNIV; ?b1.0 ∈ manifold_eucl.dest.diff_fun_space; ?b2.0 ∈ manifold_eucl.dest.diff_fun_space⟧ ⟹ X (λx. ?b1.0 x + ?b2.0 x) = X ?b1.0 + X ?b2.0›*)) (*goal: ‹(X::('b::euclidean_space ⇒ real) ⇒ real) (λx::'b::euclidean_space. (f::'b::euclidean_space ⇒ real) (apply_chart (ψ::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart) (p::'a::{second_countable_topology,t2_space})) + frechet_derivative f (at (apply_chart ψ p)) (x - apply_chart ψ p) + (∑i::'b::euclidean_space∈Basis. ∑j::'b::euclidean_space∈Basis. (x - apply_chart ψ p) ∙ j * ((x - apply_chart ψ p) ∙ i) * (g::'b::euclidean_space ⇒ 'b::euclidean_space ⇒ 'b::euclidean_space ⇒ real) i j x)) = directional_derivative (k::enat) (apply_chart ψ p) (∑i::'b::euclidean_space∈Basis. (v::'b::euclidean_space ⇒ real) i *⇩R i) f›*) subgoal for by simp subgoal for by (auto intro!: smooth_on_add (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x + ?g x)›*) smooth_on_frechet (*‹⟦?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. frechet_derivative f (at (apply_chart ψ p)) (?g x))›*) smooth_on_minus (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x - ?g x)›*)) subgoal for by (auto intro!: smooth_on_add (*‹⟦(?k::enat)-smooth_on (?S::?'a set) (?f::?'a ⇒ ?'b); ?k-smooth_on ?S (?g::?'a ⇒ ?'b); open ?S⟧ ⟹ ?k-smooth_on ?S (λx::?'a. ?f x + ?g x)›*) smooth_on_sum (*‹⟦⋀i::?'a. ⟦i ∈ (?F::?'a set); finite ?F⟧ ⟹ (?n::enat)-smooth_on (?S::?'b set) ((?f::?'a ⇒ ?'b ⇒ ?'c) i); open ?S⟧ ⟹ ?n-smooth_on ?S (λx::?'b. ∑i::?'a∈?F. ?f i x)›*) smooth_on_mult (*‹⟦(?k::enat)-smooth_on (?S::?'d set) (?f::?'d ⇒ ?'a); ?k-smooth_on ?S (?g::?'d ⇒ ?'a); open ?S⟧ ⟹ ?k-smooth_on ?S (λx::?'d. ?f x * ?g x)›*) smooth_on_inner (*‹⟦(?k::enat)-smooth_on (?S::?'d set) (?f::?'d ⇒ ?'a); ?k-smooth_on ?S (?g::?'d ⇒ ?'a); open ?S⟧ ⟹ ?k-smooth_on ?S (λx::?'d. ?f x ∙ ?g x)›*) g (*‹⟦(?i4::'b) ∈ Basis; (?j4::'b) ∈ Basis⟧ ⟹ smooth_on UNIV ((g::'b ⇒ 'b ⇒ 'b ⇒ real) ?i4 ?j4)›*) smooth_on_minus (*‹⟦(?k::enat)-smooth_on (?S::?'a set) (?f::?'a ⇒ ?'b); ?k-smooth_on ?S (?g::?'a ⇒ ?'b); open ?S⟧ ⟹ ?k-smooth_on ?S (λx::?'a. ?f x - ?g x)›*)) apply (subst X_add[unfolded plus_fun_def] (*‹⟦∀x. x ∈ manifold_eucl.dest.diff_fun_space ⟶ X x ∈ UNIV; ?b1.0 ∈ manifold_eucl.dest.diff_fun_space; ?b2.0 ∈ manifold_eucl.dest.diff_fun_space⟧ ⟹ X (λx. ?b1.0 x + ?b2.0 x) = X ?b1.0 + X ?b2.0›*)) (*goal: ‹X (λx. f (apply_chart ψ p) + frechet_derivative f (at (apply_chart ψ p)) (x - apply_chart ψ p)) + X (λx. ∑i∈Basis. ∑j∈Basis. (x - apply_chart ψ p) ∙ j * ((x - apply_chart ψ p) ∙ i) * g i j x) = directional_derivative k (apply_chart ψ p) (∑i∈Basis. v i *⇩R i) f›*) subgoal for by auto subgoal for by (auto intro!: smooth_on_add (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x + ?g x)›*) smooth_on_frechet (*‹⟦?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. frechet_derivative f (at (apply_chart ψ p)) (?g x))›*) smooth_on_minus (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x - ?g x)›*)) subgoal for by (auto intro!: smooth_on_frechet (*‹⟦?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. frechet_derivative f (at (apply_chart ψ p)) (?g x))›*) smooth_on_minus (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x - ?g x)›*)) apply (subst manifold_eucl.derivation_const_eq_zero[where c="f (ψ p)" and X=X, simplified] (*‹X ∈ manifold_eucl.tangent_space ?k ?p ⟹ X (λx. f (apply_chart ψ p)) = 0›*), fact) (*goal: ‹X (λx. f (apply_chart ψ p)) + X (λx. frechet_derivative f (at (apply_chart ψ p)) (x - apply_chart ψ p)) + X (λx. ∑i∈Basis. ∑j∈Basis. (x - apply_chart ψ p) ∙ j * ((x - apply_chart ψ p) ∙ i) * g i j x) = directional_derivative k (apply_chart ψ p) (∑i∈Basis. v i *⇩R i) f›*) apply (subst * (*‹X (λx. ∑i∈Basis. ∑j∈Basis. (x - apply_chart ψ p) ∙ j * ((x - apply_chart ψ p) ∙ i) * g i j x) = 0›*)) (*goal: ‹0 + X (λx. frechet_derivative f (at (apply_chart ψ p)) (x - apply_chart ψ p)) + X (λx. ∑i∈Basis. ∑j∈Basis. (x - apply_chart ψ p) ∙ j * ((x - apply_chart ψ p) ∙ i) * g i j x) = directional_derivative k (apply_chart ψ p) (∑i∈Basis. v i *⇩R i) f›*) apply simp (*goal: ‹0 + X (λx. frechet_derivative f (at (apply_chart ψ p)) (x - apply_chart ψ p)) + 0 = directional_derivative k (apply_chart ψ p) (∑i∈Basis. v i *⇩R i) f›*) using f (*‹f ∈ manifold_eucl.dest.diff_fun_space›*) by (simp add: directional_derivative_def (*‹directional_derivative ?k ?a ?v = restrict0 (manifold_eucl.diff_fun_space ?k) (λf. frechet_derivative f (at ?a) ?v)›*) ** (*‹X (λx. frechet_derivative f (at (apply_chart ψ p)) (x - apply_chart ψ p)) = frechet_derivative f (at (apply_chart ψ p)) (∑i∈Basis. v i *⇩R i)›*)) qed show "X = directional_derivative k (ψ p) (∑i∈Basis. v i *⇩R i)" apply (rule ext_extensional0 (*‹⟦extensional0 ?S ?f; extensional0 ?S ?g; ⋀x. x ∈ ?S ⟹ ?f x = ?g x⟧ ⟹ ?f = ?g›*)) (*goal: ‹X = directional_derivative k (apply_chart ψ p) (∑i∈Basis. v i *⇩R i)›*) using assms(2) (*‹(X::('b ⇒ real) ⇒ real) ∈ T⇩ψ⇩pE›*) (*goals: 1. ‹extensional0 (?S::('b::euclidean_space ⇒ real) set) (X::('b::euclidean_space ⇒ real) ⇒ real)› 2. ‹extensional0 (?S::('b::euclidean_space ⇒ real) set) (directional_derivative (k::enat) (apply_chart (ψ::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart) (p::'a::{second_countable_topology,t2_space})) (∑i::'b::euclidean_space∈Basis. (v::'b::euclidean_space ⇒ real) i *⇩R i))› 3. ‹⋀x::'b::euclidean_space ⇒ real. x ∈ (?S::('b::euclidean_space ⇒ real) set) ⟹ (X::('b::euclidean_space ⇒ real) ⇒ real) x = directional_derivative (k::enat) (apply_chart (ψ::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart) (p::'a::{second_countable_topology,t2_space})) (∑i::'b::euclidean_space∈Basis. (v::'b::euclidean_space ⇒ real) i *⇩R i) x› discuss goal 1*) apply (rule manifold_eucl.tangent_space_restrict (*‹(?X::(?'a ⇒ real) ⇒ real) ∈ manifold_eucl.tangent_space (?k::enat) (?p::?'a) ⟹ extensional0 (manifold_eucl.diff_fun_space ?k) ?X›*)) (*discuss goal 2*) apply (rule extensional0_directional_derivative (*‹extensional0 (manifold_eucl.diff_fun_space ?k) (directional_derivative ?k ?a ?v)›*)) (*discuss goal 3*) by (rule X_is_derivative (*‹?f4 ∈ manifold_eucl.dest.diff_fun_space ⟹ X ?f4 = directional_derivative k (apply_chart ψ p) (∑i∈Basis. v i *⇩R i) ?f4›*)) (*proven 3 subgoals*) qed text ‹Applying a tangent vector (in $T_{\psi(p)}\mathbb R^n$) to the coordinate functions of the Euclidean space yields components of the tangent vector in the basis of the directional derivatives.› lemma (in c_manifold_point) directional_derivative_inverse: defines "D ≡ directional_derivative k (ψ p)" and "Di ≡ λX :: ('b ⇒ real) ⇒ real. (∑i∈Basis. coord_fun X i *⇩R i)" assumes k: "k=∞" shows "⋀X. X ∈ T⇩ψ⇩pE ⟹ D (Di X) = X" and "⋀v. Di (D v) = v" and "bij_betw Di T⇩ψ⇩pE UNIV" proof (-) (*goals: 1. ‹⋀X. X ∈ T⇩ψ⇩pE ⟹ D (Di X) = X› 2. ‹⋀v. Di (D v) = v› 3. ‹bij_betw Di T⇩ψ⇩pE UNIV›*) show 1: "⋀X. X ∈ T⇩ψ⇩pE ⟹ D (Di X) = X" using assms (*‹D ≡ directional_derivative k (apply_chart ψ p)› ‹Di ≡ λX. ∑i∈Basis. coord_fun X i *⇩R i› ‹k = ∞›*) euclidean_tangent_space_coordinatesE (*‹⟦?X ∈ T⇩ψ⇩pE; k = ∞⟧ ⟹ ?X = directional_derivative k (apply_chart ψ p) (∑i∈Basis. coord_fun ?X i *⇩R i)›*) by simp { fix v have "(directional_derivative k (ψ p) v (λx. (x - ψ p) ∙ i)) = frechet_derivative (λx. (x - ψ p) ∙ i) (at (ψ p)) v" for i :: 'b apply (intro directional_derivative_eq_frechet_derivative (*‹?k-smooth_on UNIV ?f ⟹ directional_derivative ?k ?a ?v ?f = frechet_derivative ?f (at ?a) ?v›*)) (*goal: ‹directional_derivative k (apply_chart ψ p) v (λx. (x - apply_chart ψ p) ∙ i) = frechet_derivative (λx. (x - apply_chart ψ p) ∙ i) (at (apply_chart ψ p)) v›*) by (auto intro!: smooth_on_inner (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x ∙ ?g x)›*) smooth_on_minus (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x - ?g x)›*) simp: smooth_on_const (*‹?k-smooth_on ?S (λx. ?c)›*) smooth_on_id (*‹?k-smooth_on ?S (λx. x)›*)) moreover have "((λx. (x - ψ p) ∙ i) has_derivative (λh. h ∙ i)) (at (ψ p))" for i :: 'b apply (rule has_derivative_eq_rhs (*‹⟦(?f has_derivative ?f') ?F; ?f' = ?g'⟧ ⟹ (?f has_derivative ?g') ?F›*)) (*goals: 1. ‹((λx. (x - apply_chart ψ p) ∙ i) has_derivative ?f') (at (apply_chart ψ p))› 2. ‹?f' = (λh. h ∙ i)› discuss goal 1*) apply (rule has_derivative_inner (*‹⟦(?f has_derivative ?f') (at ?x within ?s); (?g has_derivative ?g') (at ?x within ?s)⟧ ⟹ ((λx. ?f x ∙ ?g x) has_derivative (λh. ?f ?x ∙ ?g' h + ?f' h ∙ ?g ?x)) (at ?x within ?s)›*)) (*goals: 1. ‹((λx. x - apply_chart ψ p) has_derivative ?f'3) (at (apply_chart ψ p))› 2. ‹((λx. i) has_derivative ?g'3) (at (apply_chart ψ p))› discuss goal 1*) apply (rule has_derivative_diff (*‹⟦(?f has_derivative ?f') ?F; (?g has_derivative ?g') ?F⟧ ⟹ ((λx. ?f x - ?g x) has_derivative (λx. ?f' x - ?g' x)) ?F›*)) (*goals: 1. ‹((λx. x) has_derivative ?f'6) (at (apply_chart ψ p))› 2. ‹((λx. apply_chart ψ p) has_derivative ?g'6) (at (apply_chart ψ p))› discuss goal 1*) apply (rule has_derivative_ident (*‹((λx. x) has_derivative (λx. x)) ?F›*)) (*discuss goal 2*) apply (rule has_derivative_const (*‹((λx::?'a. ?c::?'b) has_derivative (λx::?'a. 0::?'b)) (?F::?'a filter)›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply (rule has_derivative_const (*‹((λx. ?c) has_derivative (λx. 0)) ?F›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*proven 2 subgoals*) . ultimately have "(∑i∈Basis. directional_derivative k (ψ p) v (λx. (x - ψ p) ∙ i) *⇩R i) = (∑i∈Basis. (v ∙ i) *⇩R i)" by (metis (no_types, lifting) frechet_derivative_at (*‹(?f has_derivative ?f') (at ?x) ⟹ ?f' = frechet_derivative ?f (at ?x)›*)) then show "Di (D v) = v" unfolding assms(1,2) coord_fun_def (*goal: ‹(∑i∈Basis. directional_derivative k (apply_chart ψ p) v (λx. (x - apply_chart ψ p) ∙ i) *⇩R i) = v›*) by (simp add: euclidean_representation (*‹(∑b∈Basis. (?x ∙ b) *⇩R b) = ?x›*)) } note 2 = this (*‹Di (D ?v6) = ?v6›*) show "bij_betw Di T⇩ψ⇩pE UNIV" apply (rule bij_betw_if_inverse (*‹⟦bij_betw ?f ?A ?B; ⋀x. x ∈ ?A ⟹ ?f' (?f x) = x; ⋀y. y ∈ ?B ⟹ ?f (?f' y) = y⟧ ⟹ bij_betw ?f' ?B ?A›*)) (*goal: ‹bij_betw (Di::(('b ⇒ real) ⇒ real) ⇒ 'b) T⇩ψ⇩pE UNIV›*) using bij_betw_directional_derivative[OF k] (*‹bij_betw (directional_derivative k (apply_chart ψ p)) UNIV T⇩ψ⇩pE›*) "1" (*‹(?X4::('b::euclidean_space ⇒ real) ⇒ real) ∈ T⇩ψ⇩pE ⟹ (D::'b::euclidean_space ⇒ ('b::euclidean_space ⇒ real) ⇒ real) ((Di::(('b::euclidean_space ⇒ real) ⇒ real) ⇒ 'b::euclidean_space) ?X4) = ?X4›*) "2" (*‹Di (D ?v6) = ?v6›*) D_def (*‹D ≡ directional_derivative k (apply_chart ψ p)›*) by auto qed subsection ‹\<^term>‹dψ› is an isomorphism \<^term>‹T⇩pM→T⇩ψ⇩pE›.› context c_manifold_point begin text ‹The map \<^term>‹dψ› is \<^term>‹linear› (i.e. linear on the type universe) because functions add and scale. However, because there are many smooth functions on $M$ that are not equal on $M$, but are equal on a strict submanifold $U$, it is not bijective (isomorphic) between universes, but only between the tangent spaces (i.e. \<^term>‹extensional0› functions) it is actually meant to act on.› lemma linear_on_dψ: "linear_on T⇩pM T⇩ψ⇩pE scaleR scaleR dψ" apply (intro linear_imp_linear_on (*‹⟦linear ?f; subspace ?A; subspace ?B⟧ ⟹ linear_on ?A ?B (*⇩R) (*⇩R) ?f›*)) (*goal: ‹linear_on T⇩pM T⇩ψ⇩pE (*⇩R) (*⇩R) dψ›*) using "diffeo_ψ.linear_push_forward" (*‹linear dψ›*) subspace_tangent_space (*‹subspace (tangent_space ?p)›*) manifold_eucl.subspace_tangent_space (*‹subspace (manifold_eucl.tangent_space ?k ?p)›*) apply - (*goals: 1. ‹⟦linear dψ; ⋀p::'a::{second_countable_topology,t2_space}. subspace (tangent_space p); ⋀(k::enat) p::?'a17::euclidean_space. subspace (manifold_eucl.tangent_space k p)⟧ ⟹ linear dψ› 2. ‹⟦linear dψ; ⋀p::'a::{second_countable_topology,t2_space}. subspace (tangent_space p); ⋀(k::enat) p::?'a11::euclidean_space. subspace (manifold_eucl.tangent_space k p)⟧ ⟹ subspace T⇩pM› 3. ‹⟦linear dψ; ⋀p::'a::{second_countable_topology,t2_space}. subspace (tangent_space p); ⋀(k::enat) p::?'a5::euclidean_space. subspace (manifold_eucl.tangent_space k p)⟧ ⟹ subspace T⇩ψ⇩pE› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) apply ((assumption)[1]) (*discuss goal 3*) . (*proven 3 subgoals*) lemma linear_on_dψ': "linear_on T⇩pU T⇩ψ⇩pψU scaleR scaleR dψ" apply unfold_locales (*goals: 1. ‹⋀b1 b2. ⟦b1 ∈ T⇩pU; b2 ∈ T⇩pU⟧ ⟹ dψ (b1 + b2) = dψ b1 + dψ b2› 2. ‹⋀r b. b ∈ T⇩pU ⟹ dψ (r *⇩R b) = r *⇩R dψ b› discuss goal 1*) apply (simp add: diffeo_ψ.linear_push_forward (*‹linear dψ›*) linear_add (*‹linear ?f ⟹ ?f (?b1.0 + ?b2.0) = ?f ?b1.0 + ?f ?b2.0›*) linear_cmul (*‹linear ?f ⟹ ?f (?r *⇩R ?b) = ?r *⇩R ?f ?b›*)) (*discuss goal 2*) apply (simp add: diffeo_ψ.linear_push_forward (*‹linear dψ›*) linear_add (*‹linear ?f ⟹ ?f (?b1.0 + ?b2.0) = ?f ?b1.0 + ?f ?b2.0›*) linear_cmul (*‹linear ?f ⟹ ?f (?r *⇩R ?b) = ?r *⇩R ?f ?b›*)) (*proven 2 subgoals*) . lemma linear_on_dψ_inv: "linear_on T⇩ψ⇩pE T⇩pM scaleR scaleR dψ¯" apply unfold_locales (*goals: 1. ‹⋀b1 b2. ⟦b1 ∈ T⇩ψ⇩pE; b2 ∈ T⇩ψ⇩pE⟧ ⟹ dψ¯ (b1 + b2) = dψ¯ b1 + dψ¯ b2› 2. ‹⋀r b. b ∈ T⇩ψ⇩pE ⟹ dψ¯ (r *⇩R b) = r *⇩R dψ¯ b› discuss goal 1*) apply (simp add: diffeo_ψ.inv.linear_push_forward (*‹linear dψ¯›*) linear_add (*‹linear ?f ⟹ ?f (?b1.0 + ?b2.0) = ?f ?b1.0 + ?f ?b2.0›*) linear_cmul (*‹linear ?f ⟹ ?f (?r *⇩R ?b) = ?r *⇩R ?f ?b›*)) (*discuss goal 2*) apply (simp add: diffeo_ψ.inv.linear_push_forward (*‹linear dψ¯›*) linear_add (*‹linear ?f ⟹ ?f (?b1.0 + ?b2.0) = ?f ?b1.0 + ?f ?b2.0›*) linear_cmul (*‹linear ?f ⟹ ?f (?r *⇩R ?b) = ?r *⇩R ?f ?b›*)) (*proven 2 subgoals*) . lemma linear_on_dψ_inv': "linear_on T⇩ψ⇩pψU T⇩pU scaleR scaleR dψ¯" apply unfold_locales (*goals: 1. ‹⋀(b1::('b ⇒ real) ⇒ real) b2::('b ⇒ real) ⇒ real. ⟦b1 ∈ T⇩ψ⇩pψU; b2 ∈ T⇩ψ⇩pψU⟧ ⟹ dψ¯ (b1 + b2) = dψ¯ b1 + dψ¯ b2› 2. ‹⋀(r::real) b::('b ⇒ real) ⇒ real. b ∈ T⇩ψ⇩pψU ⟹ dψ¯ (r *⇩R b) = r *⇩R dψ¯ b› discuss goal 1*) apply (simp add: diffeo_ψ.inv.linear_push_forward (*‹linear dψ¯›*) linear_add (*‹linear ?f ⟹ ?f (?b1.0 + ?b2.0) = ?f ?b1.0 + ?f ?b2.0›*) linear_cmul (*‹linear ?f ⟹ ?f (?r *⇩R ?b) = ?r *⇩R ?f ?b›*)) (*discuss goal 2*) apply (simp add: diffeo_ψ.inv.linear_push_forward (*‹linear dψ¯›*) linear_add (*‹linear ?f ⟹ ?f (?b1.0 + ?b2.0) = ?f ?b1.0 + ?f ?b2.0›*) linear_cmul (*‹linear ?f ⟹ ?f (?r *⇩R ?b) = ?r *⇩R ?f ?b›*)) (*proven 2 subgoals*) . lemma bij_betw_dψ: "bij_betw dψ (sub_ψ.sub.tangent_space p) (diffeo_ψ.dest.tangent_space (ψ p))" using "diffeo_ψ.bij_betw_push_forward" (*‹?p ∈ sub_ψ.sub.carrier ⟹ bij_betw dψ (sub_ψ.sub.tangent_space ?p) (diffeo_ψ.dest.tangent_space (apply_chart ψ ?p))›*) "sub_ψ_carrier" (*‹sub_ψ.sub.carrier = domain ψ›*) p (*‹(p::'a::{second_countable_topology,t2_space}) ∈ domain (ψ::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart)›*) by blast lemma bij_betw_dψ_inv: "bij_betw dψ¯ (diffeo_ψ.dest.tangent_space (ψ p)) (sub_ψ.sub.tangent_space p)" using diffeomorphism.bij_betw_push_forward[OF diffeo_ψ.diffeo_f', of "ψ p", simplified] (*‹bij_betw dψ¯ T⇩ψ⇩pψU T⇩pU›*) "diffeo_ψ.defined" (*‹apply_chart ψ ` sub_ψ.sub.carrier ⊆ diffeo_ψ.dest.carrier›*) p (*‹p ∈ domain ψ›*) "sub_ψ_carrier" (*‹sub_ψ.sub.carrier = domain ψ›*) by blast lemma inverse_dψ: shows "v ∈ (sub_ψ.sub.tangent_space p) ⟹ dψ¯ (dψ v) = v" "u ∈ (diffeo_ψ.dest.tangent_space (ψ p)) ⟹ dψ (dψ¯ u) = u" using "diffeo_ψ.push_forward_inverse" (*‹⟦?X ∈ sub_ψ.sub.tangent_space ?p; ?p ∈ sub_ψ.sub.carrier⟧ ⟹ dψ¯ (dψ ?X) = ?X›*) "diffeo_ψ.inv_push_forward_inverse" (*‹⟦?X ∈ diffeo_ψ.dest.tangent_space ?p; ?p ∈ diffeo_ψ.dest.carrier⟧ ⟹ dψ (dψ¯ ?X) = ?X›*) "diffeo_ψ.defined" (*‹apply_chart ψ ` sub_ψ.sub.carrier ⊆ diffeo_ψ.dest.carrier›*) p (*‹p ∈ domain ψ›*) "sub_ψ_carrier" (*‹sub_ψ.sub.carrier = domain ψ›*) apply - (*goals: 1. ‹⟦v ∈ T⇩pU; ⋀X p. ⟦X ∈ sub_ψ.sub.tangent_space p; p ∈ sub_ψ.sub.carrier⟧ ⟹ dψ¯ (dψ X) = X; ⋀X p. ⟦X ∈ diffeo_ψ.dest.tangent_space p; p ∈ diffeo_ψ.dest.carrier⟧ ⟹ dψ (dψ¯ X) = X; apply_chart ψ ` sub_ψ.sub.carrier ⊆ diffeo_ψ.dest.carrier; p ∈ domain ψ; sub_ψ.sub.carrier = domain ψ⟧ ⟹ dψ¯ (dψ v) = v› 2. ‹⟦u ∈ T⇩ψ⇩pψU; ⋀X p. ⟦X ∈ sub_ψ.sub.tangent_space p; p ∈ sub_ψ.sub.carrier⟧ ⟹ dψ¯ (dψ X) = X; ⋀X p. ⟦X ∈ diffeo_ψ.dest.tangent_space p; p ∈ diffeo_ψ.dest.carrier⟧ ⟹ dψ (dψ¯ X) = X; apply_chart ψ ` sub_ψ.sub.carrier ⊆ diffeo_ψ.dest.carrier; p ∈ domain ψ; sub_ψ.sub.carrier = domain ψ⟧ ⟹ dψ (dψ¯ u) = u› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) . end (* c_manifold_point *) context c_manifold_local begin text ‹The map \<^term>‹dψ› is \<^term>‹linear› (i.e. linear on the type universe) because functions add and scale. However, because there are many smooth functions on $M$ that are not equal on $M$, but are equal on a strict submanifold $U$, it is not bijective (isomorphic) between universes, but only between the tangent spaces (i.e. \<^term>‹extensional0› functions) it is actually meant to act on.› lemma linear_on_dψ: "linear_on (tangent_space p) (diffeo_ψ.dest.tangent_space (ψ p)) scaleR scaleR dψ" apply unfold_locales (*goals: 1. ‹⋀b1 b2. ⟦b1 ∈ tangent_space p; b2 ∈ tangent_space p⟧ ⟹ dψ (b1 + b2) = dψ b1 + dψ b2› 2. ‹⋀r b. b ∈ tangent_space p ⟹ dψ (r *⇩R b) = r *⇩R dψ b› discuss goal 1*) apply (simp add: diffeo_ψ.linear_push_forward (*‹linear dψ›*) linear_add (*‹linear ?f ⟹ ?f (?b1.0 + ?b2.0) = ?f ?b1.0 + ?f ?b2.0›*) linear_cmul (*‹linear ?f ⟹ ?f (?r *⇩R ?b) = ?r *⇩R ?f ?b›*)) (*discuss goal 2*) apply (simp add: diffeo_ψ.linear_push_forward (*‹linear dψ›*) linear_add (*‹linear ?f ⟹ ?f (?b1.0 + ?b2.0) = ?f ?b1.0 + ?f ?b2.0›*) linear_cmul (*‹linear ?f ⟹ ?f (?r *⇩R ?b) = ?r *⇩R ?f ?b›*)) (*proven 2 subgoals*) . lemma bij_betw_dψ: "bij_betw dψ (sub_ψ.sub.tangent_space p) (diffeo_ψ.dest.tangent_space (ψ p))" if "p∈domain ψ" for p using "diffeo_ψ.bij_betw_push_forward" (*‹(?p::'a) ∈ sub_ψ.sub.carrier ⟹ bij_betw dψ (sub_ψ.sub.tangent_space ?p) (diffeo_ψ.dest.tangent_space (apply_chart (ψ::('a, 'b) chart) ?p))›*) "sub_ψ_carrier" (*‹sub_ψ.sub.carrier = domain ψ›*) that (*‹p ∈ domain ψ›*) by blast lemma bij_betw_dψ_inv: "bij_betw dψ¯ (diffeo_ψ.dest.tangent_space (ψ p)) (sub_ψ.sub.tangent_space p)" if "p∈domain ψ" for p using diffeomorphism.bij_betw_push_forward[OF diffeo_ψ.diffeo_f', of "ψ p"] (*‹apply_chart ψ p ∈ diffeo_ψ.dest.carrier ⟹ bij_betw dψ¯ (diffeo_ψ.dest.tangent_space (apply_chart ψ p)) (sub_ψ.sub.tangent_space (inv_chart ψ (apply_chart ψ p)))›*) "diffeo_ψ.defined" (*‹apply_chart ψ ` sub_ψ.sub.carrier ⊆ diffeo_ψ.dest.carrier›*) that (*‹p ∈ domain ψ›*) "sub_ψ_carrier" (*‹sub_ψ.sub.carrier = domain ψ›*) by simp lemma inverse_dψ: assumes "p∈domain ψ" shows "v ∈ (sub_ψ.sub.tangent_space p) ⟹ dψ¯ (dψ v) = v" "u ∈ (diffeo_ψ.dest.tangent_space (ψ p)) ⟹ dψ (dψ¯ u) = u" using "diffeo_ψ.push_forward_inverse" (*‹⟦?X ∈ sub_ψ.sub.tangent_space ?p; ?p ∈ sub_ψ.sub.carrier⟧ ⟹ dψ¯ (dψ ?X) = ?X›*) "diffeo_ψ.inv_push_forward_inverse" (*‹⟦?X ∈ diffeo_ψ.dest.tangent_space ?p; ?p ∈ diffeo_ψ.dest.carrier⟧ ⟹ dψ (dψ¯ ?X) = ?X›*) "diffeo_ψ.defined" (*‹apply_chart ψ ` sub_ψ.sub.carrier ⊆ diffeo_ψ.dest.carrier›*) assms (*‹p ∈ domain ψ›*) "sub_ψ_carrier" (*‹sub_ψ.sub.carrier = domain ψ›*) apply - (*goals: 1. ‹⟦v ∈ sub_ψ.sub.tangent_space p; ⋀X p. ⟦X ∈ sub_ψ.sub.tangent_space p; p ∈ sub_ψ.sub.carrier⟧ ⟹ dψ¯ (dψ X) = X; ⋀X p. ⟦X ∈ diffeo_ψ.dest.tangent_space p; p ∈ diffeo_ψ.dest.carrier⟧ ⟹ dψ (dψ¯ X) = X; apply_chart ψ ` sub_ψ.sub.carrier ⊆ diffeo_ψ.dest.carrier; p ∈ domain ψ; sub_ψ.sub.carrier = domain ψ⟧ ⟹ dψ¯ (dψ v) = v› 2. ‹⟦u ∈ diffeo_ψ.dest.tangent_space (apply_chart ψ p); ⋀X p. ⟦X ∈ sub_ψ.sub.tangent_space p; p ∈ sub_ψ.sub.carrier⟧ ⟹ dψ¯ (dψ X) = X; ⋀X p. ⟦X ∈ diffeo_ψ.dest.tangent_space p; p ∈ diffeo_ψ.dest.carrier⟧ ⟹ dψ (dψ¯ X) = X; apply_chart ψ ` sub_ψ.sub.carrier ⊆ diffeo_ψ.dest.carrier; p ∈ domain ψ; sub_ψ.sub.carrier = domain ψ⟧ ⟹ dψ (dψ¯ u) = u› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) . end (* c_manifold_local *) subsection ‹\<^term>‹dι› is an isomorphism \<^term>‹T⇩pU→T⇩pM›› context submanifold begin lemma tangent_submanifold_isomorphism: assumes "p∈sub.carrier" shows bij_betw_dι: "bij_betw inclusion.push_forward (sub.tangent_space p) (tangent_space p)" and linear_on_dι: "linear_on (sub.tangent_space p) (tangent_space p) scaleR scaleR inclusion.push_forward" using inj_on_push_forward_inclusion[OF assms] (*‹inj_on inclusion.push_forward (sub.tangent_space p)›*) inclusion.push_forward_in_tangent_space[OF assms] (*‹inclusion.push_forward ` sub.tangent_space p ⊆ tangent_space p›*) surj_on_push_forward_inclusion[OF assms] (*‹tangent_space (p::'a) ⊆ inclusion.push_forward ` sub.tangent_space p›*) (*goals: 1. ‹bij_betw inclusion.push_forward (sub.tangent_space (p::'a::{second_countable_topology,t2_space})) (tangent_space p)› 2. ‹linear_on (sub.tangent_space (p::'a::{second_countable_topology,t2_space})) (tangent_space p) (*⇩R) (*⇩R) inclusion.push_forward› discuss goal 1*) apply (auto simp: bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*)) (*discuss goal 2*) apply (rule linear_on_push_forward_inclusion (*‹linear_on (sub.tangent_space ?p) (tangent_space ?p) (*⇩R) (*⇩R) inclusion.push_forward›*)) (*proven 2 subgoals*) . lemma bij_betw_dι_inv: fixes p and dι_inv defines "dι_inv ≡ restrict0 (tangent_space p) (the_inv_into (sub.tangent_space p) inclusion.push_forward)" assumes "p∈sub.carrier" shows "bij_betw dι_inv (tangent_space p) (sub.tangent_space p)" using bij_betw_the_inv_into[OF tangent_submanifold_isomorphism ( 1 )] (*‹?p1 ∈ sub.carrier ⟹ bij_betw (the_inv_into (sub.tangent_space ?p1) inclusion.push_forward) (tangent_space ?p1) (sub.tangent_space ?p1)›*) assms (*‹dι_inv ≡ restrict0 (tangent_space p) (the_inv_into (sub.tangent_space p) inclusion.push_forward)› ‹(p::'a) ∈ sub.carrier›*) by (simp add: bij_betw_restrict0 (*‹bij_betw ?f ?A ?B ⟹ bij_betw (restrict0 ?A ?f) ?A ?B›*)) lemma linear_on_dι_inv: fixes p and dι_inv defines "dι_inv ≡ restrict0 (tangent_space p) (the_inv_into (sub.tangent_space p) inclusion.push_forward)" assumes "p∈sub.carrier" shows "linear_on (tangent_space p) (sub.tangent_space p) scaleR scaleR dι_inv" using linear_on_the_inv_into[OF linear_on_push_forward_inclusion tangent_submanifold_isomorphism ( 1 )] (*‹?p1 ∈ sub.carrier ⟹ linear_on (tangent_space ?p1) (sub.tangent_space ?p1) (*⇩R) (*⇩R) (the_inv_into (sub.tangent_space ?p1) inclusion.push_forward)›*) assms (*‹dι_inv ≡ restrict0 (tangent_space p) (the_inv_into (sub.tangent_space p) inclusion.push_forward)› ‹p ∈ sub.carrier›*) by (simp add: linear_on_restrict0 (*‹linear_on ?S1.0 ?S2.0 ?s1.0 ?s2.0 ?f ⟹ linear_on ?S1.0 ?S2.0 ?s1.0 ?s2.0 (restrict0 ?S1.0 ?f)›*)) end context c_manifold_point begin lemma tangent_submanifold_isomorphism: shows bij_betw_dι: "bij_betw dι T⇩pU T⇩pM" and linear_on_dι: "linear_on T⇩pU T⇩pM scaleR scaleR dι" using "sub_ψ_carrier" (*‹sub_ψ.sub.carrier = domain ψ›*) p (*‹p ∈ domain ψ›*) apply (simp only: bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*), intro conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*top goal: ‹bij_betw dι T⇩pU T⇩pM› and 1 goal remains*) subgoal for using "sub_ψ.inj_on_push_forward_inclusion" (*‹?p ∈ sub_ψ.sub.carrier ⟹ inj_on dι (sub_ψ.sub.tangent_space ?p)›*) by blast subgoal for using "sub_ψ.inclusion.push_forward_in_tangent_space" (*‹?p ∈ sub_ψ.sub.carrier ⟹ dι ` sub_ψ.sub.tangent_space ?p ⊆ tangent_space ?p›*) "sub_ψ.surj_on_push_forward_inclusion" (*‹?p ∈ sub_ψ.sub.carrier ⟹ tangent_space ?p ⊆ dι ` sub_ψ.sub.tangent_space ?p›*) by (simp add: subset_antisym (*‹⟦(?A::?'a::type set) ⊆ (?B::?'a::type set); ?B ⊆ ?A⟧ ⟹ ?A = ?B›*)) subgoal for by (rule sub_ψ.linear_on_push_forward_inclusion (*‹linear_on (sub_ψ.sub.tangent_space ?p) (tangent_space ?p) (*⇩R) (*⇩R) dι›*)) . lemma bij_betw_dι_inv: "bij_betw dι¯ T⇩pM T⇩pU" using bij_betw_the_inv_into[OF tangent_submanifold_isomorphism ( 1 )] (*‹bij_betw (the_inv_into T⇩pU dι) T⇩pM T⇩pU›*) by (simp add: bij_betw_restrict0 (*‹bij_betw (?f::?'a ⇒ ?'b) (?A::?'a set) (?B::?'b set) ⟹ bij_betw (restrict0 ?A ?f) ?A ?B›*)) lemma linear_on_dι_inv: "linear_on T⇩pM T⇩pU scaleR scaleR dι¯" using linear_on_the_inv_into[OF sub_ψ.linear_on_push_forward_inclusion tangent_submanifold_isomorphism ( 1 )] (*‹linear_on T⇩pM T⇩pU (*⇩R) (*⇩R) (the_inv_into T⇩pU dι)›*) by (simp add: linear_on_restrict0 (*‹linear_on ?S1.0 ?S2.0 ?s1.0 ?s2.0 ?f ⟹ linear_on ?S1.0 ?S2.0 ?s1.0 ?s2.0 (restrict0 ?S1.0 ?f)›*)) subsection ‹\<^term>‹dκ› is an isomorphism \<^term>‹T⇩ψ⇩pψU→T⇩ψ⇩pE›› lemma eq_T⇩ψ⇩pE_range_inclusion: "T⇩ψ⇩pE = dκ ` T⇩ψ⇩pψU" using sub_eucl.surj_on_push_forward_inclusion[of "ψ p"] (*‹apply_chart (ψ::('a, 'b) chart) (p::'a) ∈ diffeo_ψ.dest.carrier ⟹ T⇩ψ⇩pE ⊆ dκ ` T⇩ψ⇩pψU›*) sub_eucl.inclusion.push_forward_in_tangent_space[of "ψ p"] (*‹apply_chart ψ p ∈ diffeo_ψ.dest.carrier ⟹ dκ ` T⇩ψ⇩pψU ⊆ T⇩ψ⇩pE›*) by auto lemma eq_T⇩ψ⇩pE_range_inclusion2: "range (directional_derivative k (ψ p)) = dκ ` T⇩ψ⇩pψU" if "k=∞" apply (subst surj_directional_derivative[OF that] (*‹range (directional_derivative (k::enat) (?a::?'a::euclidean_space)) = manifold_eucl.dest.tangent_space ?a›*)) (*goal: ‹range (directional_derivative k (apply_chart ψ p)) = dκ ` T⇩ψ⇩pψU›*) using "eq_T⇩ψ⇩pE_range_inclusion" (*‹T⇩ψ⇩pE = dκ ` T⇩ψ⇩pψU›*) . lemma bij_betw_dκ: "bij_betw dκ T⇩ψ⇩pψU T⇩ψ⇩pE" unfolding bij_betw_def (*goal: ‹inj_on dκ T⇩ψ⇩pψU ∧ dκ ` T⇩ψ⇩pψU = T⇩ψ⇩pE›*) using sub_eucl.surj_on_push_forward_inclusion[of "ψ p"] (*‹apply_chart ψ p ∈ diffeo_ψ.dest.carrier ⟹ T⇩ψ⇩pE ⊆ dκ ` T⇩ψ⇩pψU›*) sub_eucl.inj_on_push_forward_inclusion (*‹?p ∈ diffeo_ψ.dest.carrier ⟹ inj_on dκ (diffeo_ψ.dest.tangent_space ?p)›*) sub_eucl.inclusion.push_forward_in_tangent_space[of "ψ p"] (*‹apply_chart ψ p ∈ diffeo_ψ.dest.carrier ⟹ dκ ` T⇩ψ⇩pψU ⊆ T⇩ψ⇩pE›*) by simp lemma bij_betw_dκ_inv: "bij_betw dκ¯ T⇩ψ⇩pE T⇩ψ⇩pψU" using bij_betw_the_inv_into[OF bij_betw_dκ] (*‹bij_betw (the_inv_into T⇩ψ⇩pψU dκ) T⇩ψ⇩pE T⇩ψ⇩pψU›*) by (simp add: bij_betw_restrict0 (*‹bij_betw ?f ?A ?B ⟹ bij_betw (restrict0 ?A ?f) ?A ?B›*)) lemma linear_on_dκ_inv: "linear_on T⇩ψ⇩pE T⇩ψ⇩pψU scaleR scaleR dκ¯" using linear_on_the_inv_into[OF sub_eucl.linear_on_push_forward_inclusion bij_betw_dκ] (*‹linear_on T⇩ψ⇩pE T⇩ψ⇩pψU (*⇩R) (*⇩R) (the_inv_into T⇩ψ⇩pψU dκ)›*) by (simp add: linear_on_restrict0 (*‹linear_on ?S1.0 ?S2.0 ?s1.0 ?s2.0 ?f ⟹ linear_on ?S1.0 ?S2.0 ?s1.0 ?s2.0 (restrict0 ?S1.0 ?f)›*)) subsection ‹The coordinate basis of a tangent space› lemma (in submanifold) vector_apply_sub_eq_localI: fixes p and dι and dι_inv defines dι: "dι ≡ inclusion.push_forward" and dι_inv: "dι_inv ≡ the_inv_into (sub.tangent_space p) dι" assumes p: "p∈N" and S: "S ⊆ carrier" and N: "open N" "N ⊆ S" and f: "f ∈ diff_fun_space" "f' ∈ sub.diff_fun_space" "⋀x. x ∈ N ⟹ f x = f' x" shows "⋀v. v∈(sub.tangent_space p) ⟹ v f' = (dι v) f" "⋀v. v∈(tangent_space p) ⟹ (dι_inv v) f' = v f" proof (-) (*goals: 1. ‹⋀v. v ∈ sub.tangent_space p ⟹ v f' = dι v f› 2. ‹⋀v. v ∈ tangent_space p ⟹ dι_inv v f' = v f›*) have 1: "restrict0 (S∩carrier) f ∈ sub.diff_fun_space" apply (rule sub.restrict0_in_fun_space[simplified] (*‹diff_fun k (charts_submanifold S) ?f ⟹ restrict0 (S ∩ carrier) ?f ∈ sub.diff_fun_space›*)) (*goal: ‹restrict0 (S ∩ carrier) f ∈ sub.diff_fun_space›*) apply (rule diff_fun.diff_fun_submanifold[OF diff_fun_spaceD[OF f(1)]] (*‹open ?S ⟹ diff_fun k (charts_submanifold ?S) f›*)) (*goal: ‹diff_fun (k::enat) (charts_submanifold (S::'a::{second_countable_topology,t2_space} set)) (f::'a::{second_countable_topology,t2_space} ⇒ real)›*) by (simp add: open_submanifold (*‹open (S::'a::{second_countable_topology,t2_space} set)›*)) have p_sub: "p∈sub.carrier" using p (*‹p ∈ N›*) S (*‹(S::'a set) ⊆ carrier›*) N(2) (*‹N ⊆ S›*) by auto { fix v assume v: "v∈(sub.tangent_space p)" (*‹(v::('a ⇒ real) ⇒ real) ∈ sub.tangent_space (p::'a)›*) show "v f' = (dι v) f" apply (simp add: f( (*‹f ∈ diff_fun_space›*) 1) assms( (*‹dι ≡ inclusion.push_forward›*) 1) inclusion.push_forward_def (*‹inclusion.push_forward ?X = restrict0 diff_fun_space (λg. ?X (restrict0 sub.carrier (g ∘ (λx. x))))›*) comp_id[unfolded id_def] (*‹?f ∘ (λx. x) = ?f›*)) (*goal: ‹v f' = dι v f›*) apply (rule sub.derivation_eq_localI[OF N(1) p _ v f(2) 1] (*‹⟦N ⊆ sub.carrier; ⋀x. x ∈ N ⟹ f' x = restrict0 (S ∩ carrier) f x⟧ ⟹ v f' = v (restrict0 (S ∩ carrier) f)›*)) (*goal: ‹v f' = v (restrict0 (S ∩ carrier) f)›*) using N(2) (*‹N ⊆ S›*) S (*‹S ⊆ carrier›*) apply - (*goals: 1. ‹⟦N ⊆ S; S ⊆ carrier⟧ ⟹ N ⊆ sub.carrier› 2. ‹⋀x. ⟦x ∈ N; N ⊆ S; S ⊆ carrier⟧ ⟹ f' x = restrict0 (S ∩ carrier) f x› discuss goal 1*) apply simp (*discuss goal 2*) apply (metis f( (*‹?x3 ∈ N ⟹ f ?x3 = f' ?x3›*) 3) inf.orderE (*‹⟦?a ≤ ?b; ?a = inf ?a ?b ⟹ ?thesis⟧ ⟹ ?thesis›*) restrict0_def (*‹restrict0 ?A ?f ?x = (if ?x ∈ ?A then ?f ?x else 0)›*) subsetD (*‹⟦?A ⊆ ?B; ?c ∈ ?A⟧ ⟹ ?c ∈ ?B›*)) (*proven 2 subgoals*) . } moreover { fix v assume v_in: "v∈(tangent_space p)" (*‹(v::('a ⇒ real) ⇒ real) ∈ tangent_space (p::'a)›*) then have "(dι_inv v) ∈ (sub.tangent_space p)" using bij_betwE[OF bij_betw_dι_inv [ OF p_sub ]] (*‹∀a∈tangent_space p. restrict0 (tangent_space p) (the_inv_into (sub.tangent_space p) inclusion.push_forward) a ∈ sub.tangent_space p›*) unfolding assms(1,2) (*goal: ‹the_inv_into (sub.tangent_space p) inclusion.push_forward v ∈ sub.tangent_space p›*) by simp from calculation[OF this] (*‹dι_inv v f' = dι (dι_inv v) f›*) f_the_inv_into_f (*‹⟦inj_on (?f::?'a ⇒ ?'b) (?A::?'a set); (?y::?'b) ∈ ?f ` ?A⟧ ⟹ ?f (the_inv_into ?A ?f ?y) = ?y›*) tangent_submanifold_isomorphism(1) (*‹?p ∈ sub.carrier ⟹ bij_betw inclusion.push_forward (sub.tangent_space ?p) (tangent_space ?p)›*) v_in (*‹v ∈ tangent_space p›*) p_sub (*‹p ∈ sub.carrier›*) show "(dι_inv v) f' = v f" unfolding assms(1,2) bij_betw_def (*goal: ‹the_inv_into (sub.tangent_space p) inclusion.push_forward v f' = v f›*) by fastforce } qed lemma vector_apply_eq_localI: defines dι_inv: "dι_inv ≡ the_inv_into T⇩pU dι" assumes N: "p∈N" "open N" "N ⊆ sub_ψ.sub.carrier" and f: "f ∈ diff_fun_space" "f' ∈ sub_ψ.sub.diff_fun_space" "⋀x. x ∈ N ⟹ f x = f' x" shows "⋀v. v∈T⇩pU ⟹ v f' = (dι v) f" "⋀v. v∈T⇩pM ⟹ (dι_inv v) f' = v f" proof (-) (*goals: 1. ‹⋀v. v ∈ T⇩pU ⟹ v f' = dι v f› 2. ‹⋀v. v ∈ T⇩pM ⟹ dι_inv v f' = v f›*) have 1: "restrict0 (domain ψ ∩ carrier) f ∈ sub_ψ.sub.diff_fun_space" unfolding "sub_ψ.sub.diff_fun_space_def" (*goal: ‹restrict0 (domain ψ ∩ carrier) f ∈ {f. diff_fun k (charts_submanifold (domain ψ)) f ∧ extensional0 sub_ψ.sub.carrier f}›*) apply auto (*goal: ‹restrict0 (domain ψ ∩ carrier) f ∈ {f. diff_fun k (charts_submanifold (domain ψ)) f ∧ extensional0 sub_ψ.sub.carrier f}›*) by (metis diff_fun.diff_fun_submanifold (*‹⟦diff_fun ?k ?charts ?f; open ?S⟧ ⟹ diff_fun ?k (manifold.charts_submanifold ?charts ?S) ?f›*) diff_fun_spaceD (*‹?f ∈ diff_fun_space ⟹ diff_fun k charts ?f›*) f( (*‹f ∈ diff_fun_space›*) 1) open_domain (*‹open (domain ?c)›*) sub_ψ.carrier_submanifold (*‹sub_ψ.sub.carrier = domain ψ ∩ carrier›*) sub_ψ.sub.diff_fun_spaceD (*‹?f ∈ sub_ψ.sub.diff_fun_space ⟹ diff_fun k (charts_submanifold (domain ψ)) ?f›*) sub_ψ.sub.restrict0_in_fun_space (*‹diff_fun k (charts_submanifold (domain ψ)) ?f ⟹ restrict0 sub_ψ.sub.carrier ?f ∈ sub_ψ.sub.diff_fun_space›*)) { fix v assume v: "v∈T⇩pU" (*‹(v::('a ⇒ real) ⇒ real) ∈ T⇩pU›*) show "v f' = (dι v) f" apply (simp add: f( (*‹f ∈ diff_fun_space›*) 1) sub_ψ.inclusion.push_forward_def (*‹dι ?X = restrict0 diff_fun_space (λg. ?X (restrict0 sub_ψ.sub.carrier (g ∘ (λx. x))))›*) comp_id[unfolded id_def] (*‹?f ∘ (λx. x) = ?f›*)) (*goal: ‹v f' = dι v f›*) apply (rule sub_ψ.sub.derivation_eq_localI[OF N(2,1) _ v f(2)] (*‹⟦N ⊆ sub_ψ.sub.carrier; ?g ∈ sub_ψ.sub.diff_fun_space; ⋀x. x ∈ N ⟹ f' x = ?g x⟧ ⟹ v f' = v ?g›*)) (*goal: ‹(v::('a::{second_countable_topology,t2_space} ⇒ real) ⇒ real) (f'::'a::{second_countable_topology,t2_space} ⇒ real) = v (restrict0 (domain (ψ::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart) ∩ carrier) (f::'a::{second_countable_topology,t2_space} ⇒ real))›*) using N(3) (*‹N ⊆ sub_ψ.sub.carrier›*) "1" (*‹restrict0 (domain ψ ∩ carrier) f ∈ sub_ψ.sub.diff_fun_space›*) apply - (*goals: 1. ‹⟦N ⊆ sub_ψ.sub.carrier; restrict0 (domain ψ ∩ carrier) f ∈ sub_ψ.sub.diff_fun_space⟧ ⟹ N ⊆ sub_ψ.sub.carrier› 2. ‹⟦N ⊆ sub_ψ.sub.carrier; restrict0 (domain ψ ∩ carrier) f ∈ sub_ψ.sub.diff_fun_space⟧ ⟹ restrict0 (domain ψ ∩ carrier) f ∈ sub_ψ.sub.diff_fun_space› 3. ‹⋀x. ⟦x ∈ N; N ⊆ sub_ψ.sub.carrier; restrict0 (domain ψ ∩ carrier) f ∈ sub_ψ.sub.diff_fun_space⟧ ⟹ f' x = restrict0 (domain ψ ∩ carrier) f x› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply (metis N( (*‹N ⊆ sub_ψ.sub.carrier›*) 3) f( (*‹?x4 ∈ N ⟹ f ?x4 = f' ?x4›*) 3) in_mono (*‹?A ⊆ ?B ⟹ ?x ∈ ?A ⟶ ?x ∈ ?B›*) restrict0_apply_in (*‹?x ∈ ?A ⟹ restrict0 ?A ?f ?x = ?f ?x›*) sub_ψ.carrier_submanifold (*‹sub_ψ.sub.carrier = domain ψ ∩ carrier›*)) (*proven 3 subgoals*) . } moreover { fix v assume v_in: "v∈T⇩pM" (*‹(v::('a ⇒ real) ⇒ real) ∈ T⇩pM›*) then have "(dι_inv v) ∈ T⇩pU" using tangent_submanifold_isomorphism(1) (*‹bij_betw dι T⇩pU T⇩pM›*) the_inv_into_into (*‹⟦inj_on ?f ?A; ?x ∈ ?f ` ?A; ?A ⊆ ?B⟧ ⟹ the_inv_into ?A ?f ?x ∈ ?B›*) unfolding "dι_inv" bij_betw_def (*goal: ‹the_inv_into T⇩pU dι v ∈ T⇩pU›*) by fastforce from calculation[OF this] (*‹dι_inv v f' = dι (dι_inv v) f›*) f_the_inv_into_f (*‹⟦inj_on ?f ?A; ?y ∈ ?f ` ?A⟧ ⟹ ?f (the_inv_into ?A ?f ?y) = ?y›*) tangent_submanifold_isomorphism(1) (*‹bij_betw dι T⇩pU T⇩pM›*) v_in (*‹v ∈ T⇩pM›*) show "(dι_inv v) f' = v f" unfolding "dι_inv" bij_betw_def (*goal: ‹the_inv_into T⇩pU dι v f' = v f›*) by fastforce } qed<close> lemma extension_lemma_localE: fixes f::"'a⇒real" defines dι_inv: "dι_inv ≡ the_inv_into T⇩pU dι" assumes f: "f ∈ sub_ψ.sub.diff_fun_space" obtains N f' where "p∈N" "open N" "compact (closure N)" "closure N ⊆ sub_ψ.sub.carrier" "f' ∈ diff_fun_space" "f' ∈ sub_ψ.sub.diff_fun_space" "⋀x. x ∈ closure N ⟹ f' x = f x" "⋀v. v∈T⇩pU ⟹ v f = v f'" "⋀v. v∈T⇩pU ⟹ v f' = (dι v) f'" "⋀v. v∈(tangent_space p) ⟹ (dι_inv v) f = v f'" proof (-) (*goal: ‹(⋀N f'. ⟦p ∈ N; open N; compact (closure N); closure N ⊆ sub_ψ.sub.carrier; f' ∈ diff_fun_space; f' ∈ sub_ψ.sub.diff_fun_space; ⋀x. x ∈ closure N ⟹ f' x = f x; ⋀v. v ∈ T⇩pU ⟹ v f = v f'; ⋀v. v ∈ T⇩pU ⟹ v f' = dι v f'; ⋀v. v ∈ T⇩pM ⟹ dι_inv v f = v f'⟧ ⟹ thesis) ⟹ thesis›*) obtain N where N: "p∈N" "open N" "compact (closure N)" "closure N ⊆ sub_ψ.sub.carrier" (*goal: ‹(⋀N. ⟦p ∈ N; open N; compact (closure N); closure N ⊆ sub_ψ.sub.carrier⟧ ⟹ thesis) ⟹ thesis›*) using "sub_ψ.sub.precompact_neighborhoodE" (*‹⟦(?x::'a) ∈ sub_ψ.sub.carrier; ⋀C::'a set. ⟦?x ∈ C; open C; compact (closure C); closure C ⊆ sub_ψ.sub.carrier⟧ ⟹ ?thesis::bool⟧ ⟹ ?thesis›*) p (*‹p ∈ domain ψ›*) "sub_ψ_carrier" (*‹sub_ψ.sub.carrier = domain (ψ::('a, 'b) chart)›*) by metis obtain f' where f': "diff_fun k charts f'" "⋀x. x ∈ closure N ⟹ f' x = f x" "csupport_on carrier f' ∩ carrier ⊆ sub_ψ.sub.carrier" (*goal: ‹(⋀f'. ⟦diff_fun k charts f'; ⋀x. x ∈ closure N ⟹ f' x = f x; csupport_on carrier f' ∩ carrier ⊆ sub_ψ.sub.carrier⟧ ⟹ thesis) ⟹ thesis›*) using "sub_ψ.extension_lemma_submanifoldE"[OF sub_ψ.sub.diff_fun_spaceD [ OF f ] closed_closure N ( 4 )] (*‹(⋀f'. ⟦diff_fun k charts f'; ⋀x. x ∈ closure N ⟹ f' x = f x; csupport_on carrier f' ∩ carrier ⊆ sub_ψ.sub.carrier⟧ ⟹ ?thesis) ⟹ ?thesis›*) by blast let ?f1 = "restrict0 carrier f'" have f1: "?f1 ∈ diff_fun_space" "⋀x. x ∈ closure N ⟹ ?f1 x = f x" "extensional0 sub_ψ.sub.carrier ?f1" using restrict0_in_fun_space[OF f' ( 1 )] (*‹restrict0 carrier f' ∈ diff_fun_space›*) apply force (*top goal: ‹restrict0 carrier f' ∈ diff_fun_space› and 2 goals remain*) using N(4) (*‹closure (N::'a set) ⊆ sub_ψ.sub.carrier›*) restrict0_apply_in[of _ carrier f'] (*‹?x ∈ carrier ⟹ restrict0 carrier f' ?x = f' ?x›*) f'(2) (*‹?x4 ∈ closure N ⟹ f' ?x4 = f ?x4›*) apply force (*top goal: ‹⋀x. x ∈ closure N ⟹ restrict0 carrier f' x = f x› and 1 goal remains*) unfolding extensional0_def restrict0_def (*goal: ‹∀x::'a. x ∉ sub_ψ.sub.carrier ⟶ (if x ∈ carrier then (f'::'a ⇒ real) x else (0::real)) = (0::real)›*) using f'(3) (*‹csupport_on carrier f' ∩ carrier ⊆ sub_ψ.sub.carrier›*) not_in_csupportD (*‹⟦?x ∉ csupport_on ?carrier ?φ; ?x ∈ ?carrier⟧ ⟹ ?φ ?x = 0›*) by fastforce have f1_sub: "?f1 ∈ sub_ψ.sub.diff_fun_space" using f1(1,3) (*‹restrict0 carrier (f'::'a::{second_countable_topology,t2_space} ⇒ real) ∈ diff_fun_space› ‹extensional0 sub_ψ.sub.carrier (restrict0 carrier f')›*) diff_fun.diff_fun_submanifold[of k charts _ "domain ψ"] (*‹⟦diff_fun (k::enat) (charts::('a, 'b) chart set) (?f::'a ⇒ ?'b); open (domain (ψ::('a, 'b) chart))⟧ ⟹ diff_fun k (charts_submanifold (domain ψ)) ?f›*) by (auto simp: sub_ψ.sub.diff_fun_space_def (*‹sub_ψ.sub.diff_fun_space = {f. diff_fun k (charts_submanifold (domain ψ)) f ∧ extensional0 sub_ψ.sub.carrier f}›*) diff_fun_space_def (*‹diff_fun_space = {f. diff_fun k charts f ∧ extensional0 carrier f}›*)) { fix v assume v: "v∈T⇩pU" (*‹(v::('a ⇒ real) ⇒ real) ∈ T⇩pU›*) have "v ?f1 = (dι v) ?f1" apply (simp add: f1( (*‹restrict0 carrier f' ∈ diff_fun_space›*) 1) sub_ψ.inclusion.push_forward_def (*‹dι ?X = restrict0 diff_fun_space (λg. ?X (restrict0 sub_ψ.sub.carrier (g ∘ (λx. x))))›*)) (*goal: ‹v (restrict0 carrier f') = dι v (restrict0 carrier f')›*) using f1(3) (*‹extensional0 sub_ψ.sub.carrier (restrict0 carrier f')›*) by (metis (mono_tags, lifting) comp_apply (*‹(?f ∘ ?g) ?x = ?f (?g ?x)›*) ext_extensional0 (*‹⟦extensional0 ?S ?f; extensional0 ?S ?g; ⋀x. x ∈ ?S ⟹ ?f x = ?g x⟧ ⟹ ?f = ?g›*) restrict0_apply_in (*‹?x ∈ ?A ⟹ restrict0 ?A ?f ?x = ?f ?x›*) extensional0_restrict0 (*‹extensional0 ?A (restrict0 ?A ?f)›*) sub_ψ.carrier_submanifold (*‹sub_ψ.sub.carrier = domain ψ ∩ carrier›*)) } moreover { fix v assume v: "v∈T⇩pU" (*‹(v::('a ⇒ real) ⇒ real) ∈ T⇩pU›*) have "v f = v ?f1" apply (rule sub_ψ.sub.derivation_eq_localI[OF N(2,1) _ v f f1_sub] (*‹⟦N ⊆ sub_ψ.sub.carrier; ⋀x. x ∈ N ⟹ f x = restrict0 carrier f' x⟧ ⟹ v f = v (restrict0 carrier f')›*)) (*goal: ‹(v::('a ⇒ real) ⇒ real) (f::'a ⇒ real) = v (restrict0 carrier (f'::'a ⇒ real))›*) using N(4) (*‹closure N ⊆ sub_ψ.sub.carrier›*) f'(2) (*‹(?x4::'a) ∈ closure (N::'a set) ⟹ (f'::'a ⇒ real) ?x4 = (f::'a ⇒ real) ?x4›*) apply - (*goals: 1. ‹⟦closure N ⊆ sub_ψ.sub.carrier; ⋀x. x ∈ closure N ⟹ f' x = f x⟧ ⟹ N ⊆ sub_ψ.sub.carrier› 2. ‹⋀x. ⟦x ∈ N; closure N ⊆ sub_ψ.sub.carrier; ⋀x. x ∈ closure N ⟹ f' x = f x⟧ ⟹ f x = restrict0 carrier f' x› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . } moreover { fix v assume v_in: "v∈T⇩pM" (*‹(v::('a ⇒ real) ⇒ real) ∈ T⇩pM›*) have "(dι_inv v) f = v ?f1" unfolding assms(1) (*goal: ‹the_inv_into T⇩pU dι v f = v (restrict0 carrier f')›*) apply (rule vector_apply_eq_localI(2)[OF N(1,2) _ f1(1) f _ v_in] (*‹⟦(N::'a set) ⊆ sub_ψ.sub.carrier; ⋀x::'a. x ∈ N ⟹ restrict0 carrier (f'::'a ⇒ real) x = (f::'a ⇒ real) x⟧ ⟹ the_inv_into T⇩pU dι (v::('a ⇒ real) ⇒ real) f = v (restrict0 carrier f')›*)) (*goal: ‹the_inv_into T⇩pU dι v f = v (restrict0 carrier f')›*) using N(4) (*‹closure N ⊆ sub_ψ.sub.carrier›*) f1(2) (*‹?x4 ∈ closure N ⟹ restrict0 carrier f' ?x4 = f ?x4›*) apply - (*goals: 1. ‹⟦closure N ⊆ sub_ψ.sub.carrier; ⋀x. x ∈ closure N ⟹ restrict0 carrier f' x = f x⟧ ⟹ N ⊆ sub_ψ.sub.carrier› 2. ‹⋀x. ⟦x ∈ N; closure N ⊆ sub_ψ.sub.carrier; ⋀x. x ∈ closure N ⟹ restrict0 carrier f' x = f x⟧ ⟹ restrict0 carrier f' x = f x› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . } ultimately show "?thesis" (*goal: ‹thesis›*) using N (*‹p ∈ N› ‹open N› ‹compact (closure N)› ‹closure N ⊆ sub_ψ.sub.carrier›*) f1_sub (*‹restrict0 carrier f' ∈ sub_ψ.sub.diff_fun_space›*) f1 (*‹restrict0 carrier (f'::'a::{second_countable_topology,t2_space} ⇒ real) ∈ diff_fun_space› ‹?x4 ∈ closure N ⟹ restrict0 carrier f' ?x4 = f ?x4› ‹extensional0 sub_ψ.sub.carrier (restrict0 carrier (f'::'a ⇒ real))›*) that (*‹⟦p ∈ ?N4; open ?N4; compact (closure ?N4); closure ?N4 ⊆ sub_ψ.sub.carrier; ?f'4 ∈ diff_fun_space; ?f'4 ∈ sub_ψ.sub.diff_fun_space; ⋀x. x ∈ closure ?N4 ⟹ ?f'4 x = f x; ⋀v. v ∈ T⇩pU ⟹ v f = v ?f'4; ⋀v. v ∈ T⇩pU ⟹ v ?f'4 = dι v ?f'4; ⋀v. v ∈ T⇩pM ⟹ dι_inv v f = v ?f'4⟧ ⟹ thesis›*) by presburger qed lemma extension_lemma_localE2: fixes f::"'b⇒real" assumes f: "f ∈ diffeo_ψ.dest.diff_fun_space" obtains N f' where "ψ p ∈ N" "open N" "compact (closure N)" "closure N ⊆ diffeo_ψ.dest.carrier" "f' ∈ manifold_eucl.diff_fun_space k" "f' ∈ diffeo_ψ.dest.diff_fun_space" "⋀x. x ∈ closure N ⟹ f' x = f x" "⋀v. v∈T⇩ψ⇩pψU ⟹ v f = v f'" "⋀v. v∈T⇩ψ⇩pψU ⟹ v f' = (dκ v) f'" "⋀v. v∈T⇩ψ⇩pE ⟹ (dκ¯ v) f = v f'" proof (-) (*goal: ‹(⋀N f'. ⟦apply_chart ψ p ∈ N; open N; compact (closure N); closure N ⊆ diffeo_ψ.dest.carrier; f' ∈ manifold_eucl.dest.diff_fun_space; f' ∈ diffeo_ψ.dest.diff_fun_space; ⋀x. x ∈ closure N ⟹ f' x = f x; ⋀v. v ∈ T⇩ψ⇩pψU ⟹ v f = v f'; ⋀v. v ∈ T⇩ψ⇩pψU ⟹ v f' = dκ v f'; ⋀v. v ∈ T⇩ψ⇩pE ⟹ dκ¯ v f = v f'⟧ ⟹ thesis) ⟹ thesis›*) interpret local_eucl: c_manifold_point charts_eucl k "restrict_chart (codomain ψ) chart_eucl" "ψ p" apply unfold_locales (*goals: 1. ‹restrict_chart (codomain ψ) chart_eucl ∈ manifold_eucl.dest.atlas› 2. ‹apply_chart ψ p ∈ domain (restrict_chart (codomain ψ) chart_eucl)› discuss goal 1*) apply (simp add: manifold_eucl.dest.restrict_chart_in_atlas (*‹(?c::(?'c, ?'c) chart) ∈ manifold_eucl.dest.atlas ⟹ restrict_chart (?S::?'c set) ?c ∈ manifold_eucl.dest.atlas›*)) (*discuss goal 2*) apply (simp add: manifold_eucl.dest.restrict_chart_in_atlas (*‹?c ∈ manifold_eucl.dest.atlas ⟹ restrict_chart ?S ?c ∈ manifold_eucl.dest.atlas›*)) (*proven 2 subgoals*) . show "?thesis" (*goal: ‹thesis::bool›*) using that (*‹⟦apply_chart ψ p ∈ ?N4; open ?N4; compact (closure ?N4); closure ?N4 ⊆ diffeo_ψ.dest.carrier; ?f'4 ∈ manifold_eucl.dest.diff_fun_space; ?f'4 ∈ diffeo_ψ.dest.diff_fun_space; ⋀x. x ∈ closure ?N4 ⟹ ?f'4 x = f x; ⋀v. v ∈ T⇩ψ⇩pψU ⟹ v f = v ?f'4; ⋀v. v ∈ T⇩ψ⇩pψU ⟹ v ?f'4 = dκ v ?f'4; ⋀v. v ∈ local_eucl.T⇩pM ⟹ dκ¯ v f = v ?f'4⟧ ⟹ thesis›*) local_eucl.extension_lemma_localE (*‹⟦?f ∈ local_eucl.sub_ψ.sub.diff_fun_space; ⋀N f'. ⟦apply_chart ψ p ∈ N; open N; compact (closure N); closure N ⊆ local_eucl.sub_ψ.sub.carrier; f' ∈ manifold_eucl.dest.diff_fun_space; f' ∈ local_eucl.sub_ψ.sub.diff_fun_space; ⋀x. x ∈ closure N ⟹ f' x = ?f x; ⋀v. v ∈ local_eucl.T⇩pU ⟹ v ?f = v f'; ⋀v. v ∈ local_eucl.T⇩pU ⟹ v f' = local_eucl.sub_ψ.inclusion.push_forward v f'; ⋀v. v ∈ local_eucl.T⇩pM ⟹ the_inv_into local_eucl.T⇩pU local_eucl.sub_ψ.inclusion.push_forward v ?f = v f'⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) f (*‹f ∈ diffeo_ψ.dest.diff_fun_space›*) by auto qed text ‹In order to get not just a linear map, but an isomorphism, we have to wrap the differential of the chart \<^term>‹ψ› with the correct (inclusion) maps. This is because the tangent spaces at ‹p› considered on a manifold vs a submanifold contain fundamentally different functions, being zero outside the differentiable function sets on the respective carriers. The linearity of e.g. \<^term>‹dψ¯›, @{thm linear_on_dψ_inv}, is due to the zero function agreeing with the vector space operations, and is not a ``truly'' geometric statement.› text ‹The basis of \<^term>‹directional_derivative›s for the tangent space \<^term>‹T⇩ψ⇩pE› at \<^term>‹ψ p› of a \<^typ>‹'b::euclidean_space› can be pulled back through the chart \<^term>‹ψ :: ('a,'b)chart› into a basis for the tangent space \<^term>‹T⇩pM› at \<^term>‹p›.› definition coordinate_vector :: "'b ⇒ (('a ⇒ real) ⇒ real)" where "coordinate_vector = dι ∘ dψ¯ ∘ dκ¯ ∘ (directional_derivative k (ψ p))" lemma coordinate_vector_apply: "coordinate_vector v ≡ dι (dψ¯ (dRestr (directional_derivative k (ψ p) v)))" unfolding coordinate_vector_def (*goal: ‹(dι ∘ dψ¯ ∘ dκ¯ ∘ directional_derivative k (apply_chart ψ p)) v ≡ dι (dψ¯ (dκ¯ (directional_derivative k (apply_chart ψ p) v)))›*) by auto lemma coordinate_vector_bij: "bij_betw coordinate_vector UNIV T⇩pM" if "k=∞" using bij_betw_directional_derivative[OF that] (*‹bij_betw (directional_derivative k (apply_chart ψ p)) UNIV T⇩ψ⇩pE›*) "bij_betw_dκ_inv" (*‹bij_betw dκ¯ T⇩ψ⇩pE T⇩ψ⇩pψU›*) "bij_betw_dψ_inv" (*‹bij_betw dψ¯ T⇩ψ⇩pψU T⇩pU›*) tangent_submanifold_isomorphism(1) (*‹bij_betw dι T⇩pU T⇩pM›*) by (auto intro: bij_betw_trans (*‹⟦bij_betw ?f ?A ?B; bij_betw ?g ?B ?C⟧ ⟹ bij_betw (?g ∘ ?f) ?A ?C›*) simp: coordinate_vector_def (*‹coordinate_vector = dι ∘ dψ¯ ∘ dκ¯ ∘ directional_derivative k (apply_chart ψ p)›*)) lemma coordinate_vector_linear_on: "linear_on UNIV T⇩pM scaleR scaleR coordinate_vector" if "k=∞" proof (-) (*goal: ‹linear_on UNIV T⇩pM (*⇩R) (*⇩R) coordinate_vector›*) have k: "k≠0" using that (*‹k = ∞›*) by simp have "*": "linear_on UNIV T⇩ψ⇩pE scaleR scaleR (directional_derivative k (apply_chart ψ p))" using linear_directional_derivative[OF k] (*‹linear (directional_derivative k ?a)›*) manifold_eucl.subspace_tangent_space (*‹subspace (manifold_eucl.tangent_space ?k ?p)›*) by (auto intro!: linear_imp_linear_on (*‹⟦linear ?f; subspace ?A; subspace ?B⟧ ⟹ linear_on ?A ?B (*⇩R) (*⇩R) ?f›*)) show "?thesis" (*goal: ‹linear_on UNIV T⇩pM (*⇩R) (*⇩R) coordinate_vector›*) apply (simp add: coordinate_vector_def (*‹coordinate_vector = dι ∘ dψ¯ ∘ dκ¯ ∘ directional_derivative k (apply_chart ψ p)›*)) (*goal: ‹linear_on UNIV T⇩pM (*⇩R) (*⇩R) coordinate_vector›*) apply (intro linear_on_compose (*‹⟦linear_on ?S1.0 ?S2.0 ?s1.0 ?s2.0 ?f; linear_on ?S2.0 ?S3.0 ?s2.0 ?s3.0 ?g; ?f ` ?S1.0 ⊆ ?S2.0⟧ ⟹ linear_on ?S1.0 ?S3.0 ?s1.0 ?s3.0 (?g ∘ ?f)›*)) (*goal: ‹linear_on UNIV T⇩pM (*⇩R) (*⇩R) (dι ∘ dψ¯ ∘ dκ¯ ∘ directional_derivative k (apply_chart ψ p))›*) using "*" (*‹linear_on UNIV T⇩ψ⇩pE (*⇩R) (*⇩R) (directional_derivative k (apply_chart ψ p))›*) "linear_on_dκ_inv" (*‹linear_on T⇩ψ⇩pE T⇩ψ⇩pψU (*⇩R) (*⇩R) dκ¯›*) "linear_on_dψ_inv'" (*‹linear_on T⇩ψ⇩pψU T⇩pU (*⇩R) (*⇩R) dψ¯›*) tangent_submanifold_isomorphism(2) (*‹linear_on T⇩pU T⇩pM (*⇩R) (*⇩R) dι›*) apply - (*goals: 1. ‹⟦linear_on UNIV T⇩ψ⇩pE (*⇩R) (*⇩R) (directional_derivative k (apply_chart ψ p)); linear_on T⇩ψ⇩pE T⇩ψ⇩pψU (*⇩R) (*⇩R) dκ¯; linear_on T⇩ψ⇩pψU T⇩pU (*⇩R) (*⇩R) dψ¯; linear_on T⇩pU T⇩pM (*⇩R) (*⇩R) dι⟧ ⟹ linear_on UNIV ?S2.1 (*⇩R) ?s2.1 (directional_derivative k (apply_chart ψ p))› 2. ‹⟦linear_on UNIV T⇩ψ⇩pE (*⇩R) (*⇩R) (directional_derivative k (apply_chart ψ p)); linear_on T⇩ψ⇩pE T⇩ψ⇩pψU (*⇩R) (*⇩R) dκ¯; linear_on T⇩ψ⇩pψU T⇩pU (*⇩R) (*⇩R) dψ¯; linear_on T⇩pU T⇩pM (*⇩R) (*⇩R) dι⟧ ⟹ linear_on ?S2.1 ?S2.2 ?s2.1 ?s2.2 dκ¯› 3. ‹⟦linear_on UNIV T⇩ψ⇩pE (*⇩R) (*⇩R) (directional_derivative k (apply_chart ψ p)); linear_on T⇩ψ⇩pE T⇩ψ⇩pψU (*⇩R) (*⇩R) dκ¯; linear_on T⇩ψ⇩pψU T⇩pU (*⇩R) (*⇩R) dψ¯; linear_on T⇩pU T⇩pM (*⇩R) (*⇩R) dι⟧ ⟹ linear_on ?S2.2 ?S2.3 ?s2.2 ?s2.3 dψ¯› 4. ‹⟦linear_on UNIV T⇩ψ⇩pE (*⇩R) (*⇩R) (directional_derivative k (apply_chart ψ p)); linear_on T⇩ψ⇩pE T⇩ψ⇩pψU (*⇩R) (*⇩R) dκ¯; linear_on T⇩ψ⇩pψU T⇩pU (*⇩R) (*⇩R) dψ¯; linear_on T⇩pU T⇩pM (*⇩R) (*⇩R) dι⟧ ⟹ linear_on ?S2.3 T⇩pM ?s2.3 (*⇩R) dι› 5. ‹⟦linear_on UNIV T⇩ψ⇩pE (*⇩R) (*⇩R) (directional_derivative k (apply_chart ψ p)); linear_on T⇩ψ⇩pE T⇩ψ⇩pψU (*⇩R) (*⇩R) dκ¯; linear_on T⇩ψ⇩pψU T⇩pU (*⇩R) (*⇩R) dψ¯; linear_on T⇩pU T⇩pM (*⇩R) (*⇩R) dι⟧ ⟹ dψ¯ ` ?S2.2 ⊆ ?S2.3› 6. ‹⟦linear_on UNIV T⇩ψ⇩pE (*⇩R) (*⇩R) (directional_derivative k (apply_chart ψ p)); linear_on T⇩ψ⇩pE T⇩ψ⇩pψU (*⇩R) (*⇩R) dκ¯; linear_on T⇩ψ⇩pψU T⇩pU (*⇩R) (*⇩R) dψ¯; linear_on T⇩pU T⇩pM (*⇩R) (*⇩R) dι⟧ ⟹ dκ¯ ` ?S2.1 ⊆ ?S2.2› 7. ‹⟦linear_on UNIV T⇩ψ⇩pE (*⇩R) (*⇩R) (directional_derivative k (apply_chart ψ p)); linear_on T⇩ψ⇩pE T⇩ψ⇩pψU (*⇩R) (*⇩R) dκ¯; linear_on T⇩ψ⇩pψU T⇩pU (*⇩R) (*⇩R) dψ¯; linear_on T⇩pU T⇩pM (*⇩R) (*⇩R) dι⟧ ⟹ range (directional_derivative k (apply_chart ψ p)) ⊆ ?S2.1› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply (metis ψp_in (*‹apply_chart (ψ::('a, 'b) chart) (p::'a) ∈ diffeo_ψ.dest.carrier›*) diffeo_ψ.inv.push_forward_in_tangent_space (*‹(?p::'b) ∈ diffeo_ψ.dest.carrier ⟹ dψ¯ ` diffeo_ψ.dest.tangent_space ?p ⊆ sub_ψ.sub.tangent_space (inv_chart (ψ::('a, 'b) chart) ?p)›*) inv_chart_inverse (*‹(?x::?'a) ∈ domain (?c::(?'a, ?'b) chart) ⟹ inv_chart ?c (apply_chart ?c ?x) = ?x›*) p (*‹(p::'a) ∈ domain (ψ::('a, 'b) chart)›*)) (*discuss goal 6*) apply (simp add: eq_T⇩ψ⇩pE_range_inclusion (*‹T⇩ψ⇩pE = dκ ` T⇩ψ⇩pψU›*) sub_eucl.submanifold_axioms (*‹submanifold charts_eucl k (codomain ψ)›*) submanifold.inj_on_push_forward_inclusion (*‹⟦submanifold ?charts ?k ?S; ?p ∈ manifold.carrier (manifold.charts_submanifold ?charts ?S)⟧ ⟹ inj_on (diff.push_forward ?k (manifold.charts_submanifold ?charts ?S) ?charts (λx. x)) (c_manifold.tangent_space (manifold.charts_submanifold ?charts ?S) ?k ?p)›*)) (*discuss goal 7*) apply (simp add: that (*‹k = ∞›*) surj_directional_derivative (*‹?k = ∞ ⟹ range (directional_derivative ?k ?a) = manifold_eucl.tangent_space ?k ?a›*)) (*proven 7 subgoals*) . qed lemma coordinate_vector_isomorphismE: assumes "k=∞" shows coordinate_vector_linear: "linear coordinate_vector" and coordinate_vector_inj: "inj coordinate_vector" and coordinate_vector_surj: "range coordinate_vector = T⇩pM" proof (-) (*goals: 1. ‹linear coordinate_vector› 2. ‹inj coordinate_vector› 3. ‹range coordinate_vector = T⇩pM›*) show coordinate_vector_inj: "inj coordinate_vector" and coordinate_vector_surj: "range coordinate_vector = T⇩pM" using coordinate_vector_bij[OF assms] (*‹bij_betw coordinate_vector UNIV T⇩pM›*) unfolding bij_betw_def (*goals: 1. ‹inj coordinate_vector› 2. ‹range coordinate_vector = T⇩pM›*) apply - (*goals: 1. ‹inj coordinate_vector ∧ range coordinate_vector = T⇩pM ⟹ inj coordinate_vector› 2. ‹inj coordinate_vector ∧ range coordinate_vector = T⇩pM ⟹ range coordinate_vector = T⇩pM› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have k': "k ≠ 0" using assms (*‹k = ∞›*) by simp have "*": "linear_on UNIV T⇩ψ⇩pE scaleR scaleR (directional_derivative k (apply_chart ψ p))" using linear_directional_derivative[OF k'] (*‹linear (directional_derivative k ?a)›*) manifold_eucl.subspace_tangent_space (*‹subspace (manifold_eucl.tangent_space ?k ?p)›*) by (auto intro!: linear_imp_linear_on (*‹⟦linear (?f::?'a::real_vector ⇒ ?'b::real_vector); subspace (?A::?'a::real_vector set); subspace (?B::?'b::real_vector set)⟧ ⟹ linear_on ?A ?B (*⇩R) (*⇩R) ?f›*)) interpret f: linear_on UNIV "T⇩pM" scaleR scaleR coordinate_vector using coordinate_vector_linear_on[OF assms] (*‹linear_on UNIV T⇩pM (*⇩R) (*⇩R) coordinate_vector›*) . show "linear coordinate_vector" using f.add (*‹⟦(?b1.0::'b) ∈ UNIV; (?b2.0::'b) ∈ UNIV⟧ ⟹ coordinate_vector (?b1.0 + ?b2.0) = coordinate_vector ?b1.0 + coordinate_vector ?b2.0›*) f.scale (*‹?b ∈ UNIV ⟹ coordinate_vector (?r *⇩R ?b) = ?r *⇩R coordinate_vector ?b›*) apply unfold_locales (*goals: 1. ‹⋀b1 b2. ⟦⋀b1 b2. ⟦b1 ∈ UNIV; b2 ∈ UNIV⟧ ⟹ coordinate_vector (b1 + b2) = coordinate_vector b1 + coordinate_vector b2; ⋀b r. b ∈ UNIV ⟹ coordinate_vector (r *⇩R b) = r *⇩R coordinate_vector b⟧ ⟹ coordinate_vector (b1 + b2) = coordinate_vector b1 + coordinate_vector b2› 2. ‹⋀r b. ⟦⋀b1 b2. ⟦b1 ∈ UNIV; b2 ∈ UNIV⟧ ⟹ coordinate_vector (b1 + b2) = coordinate_vector b1 + coordinate_vector b2; ⋀b r. b ∈ UNIV ⟹ coordinate_vector (r *⇩R b) = r *⇩R coordinate_vector b⟧ ⟹ coordinate_vector (r *⇩R b) = r *⇩R coordinate_vector b› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed lemma coordinate_vector_i_linear_on: "linear_on diff_fun_space UNIV scaleR scaleR (coordinate_vector i)" if k: "k=∞" using coordinate_vector_isomorphismE(3)[OF k] (*‹range coordinate_vector = T⇩pM›*) mem_tangent_space[of "coordinate_vector i" p] (*‹(coordinate_vector i ∈ T⇩pM) = (is_derivation (coordinate_vector i) p ∧ extensional0 diff_fun_space (coordinate_vector i))›*) by (auto intro: is_derivation_linear_on (*‹is_derivation ?X ?p ⟹ linear_on diff_fun_space UNIV (*⇩R) (*⇩R) ?X›*)) lemma coordinate_basis: "finite_dimensional_real_vector_space_on T⇩pM (coordinate_vector ` Basis)" if k: "k=∞" proof (-) (*goal: ‹finite_dimensional_real_vector_space_on T⇩pM (coordinate_vector ` Basis)›*) interpret E: finite_dimensional_real_vector_space_on UNIV "Basis :: 'b set" apply unfold_locales (*goals: 1. ‹subspace UNIV› 2. ‹finite Basis› 3. ‹independent Basis› 4. ‹span Basis = UNIV› 5. ‹Basis ⊆ UNIV› discuss goal 1*) apply ((auto simp: independent_Basis (*‹independent Basis›*))[1]) (*discuss goal 2*) apply ((auto simp: independent_Basis (*‹independent Basis›*))[1]) (*discuss goal 3*) apply ((auto simp: independent_Basis (*‹independent Basis›*))[1]) (*discuss goal 4*) apply ((auto simp: independent_Basis (*‹independent Basis›*))[1]) (*discuss goal 5*) apply ((auto simp: independent_Basis (*‹independent Basis›*))[1]) (*proven 5 subgoals*) . show "?thesis" (*goal: ‹finite_dimensional_real_vector_space_on T⇩pM (coordinate_vector ` Basis)›*) apply (intro E.basis_transfer (*‹⟦linear_on UNIV ?T (*⇩R) (*⇩R) ?f; bij_betw ?f UNIV ?T⟧ ⟹ finite_dimensional_real_vector_space_on ?T (?f ` Basis)›*) coordinate_vector_linear_on (*‹k = ∞ ⟹ linear_on UNIV T⇩pM (*⇩R) (*⇩R) coordinate_vector›*) coordinate_vector_bij (*‹k = ∞ ⟹ bij_betw coordinate_vector UNIV T⇩pM›*)) (*goals: 1. ‹(k::enat) = ∞› 2. ‹(k::enat) = ∞› discuss goal 1*) apply (fact that (*‹k = ∞›*)) (*discuss goal 2*) apply (fact that (*‹k = ∞›*)) (*proven 2 subgoals*) . qed lemma coordinate_vector_apply_in: assumes k: "k=∞" and f: "f∈diff_fun_space" shows "(coordinate_vector b) f = (frechet_derivative (f ∘ inv_chart ψ) (at (ψ p)) b)" proof (unfold coordinate_vector_apply (*‹coordinate_vector ?v ≡ dι (dψ¯ (dκ¯ (directional_derivative k (apply_chart ψ p) ?v)))›*)) (*goal: ‹dι (dψ¯ (dκ¯ (directional_derivative (k::enat) (apply_chart (ψ::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart) (p::'a::{second_countable_topology,t2_space})) (b::'b::euclidean_space)))) (f::'a::{second_countable_topology,t2_space} ⇒ real) = frechet_derivative (f ∘ inv_chart ψ) (at (apply_chart ψ p)) b›*) define D where D[simp]: "D ≡ directional_derivative k (ψ p) b" have k': "k≠0" using k (*‹k = ∞›*) by simp let ?y = "THE y. y ∈ T⇩ψ⇩pψU ∧ dκ y = D" have y_eq: "?y = dκ¯ D" "?y = (the_inv_into T⇩ψ⇩pψU dκ) D" unfolding the_inv_into_def (*goals: 1. ‹(THE y::('b ⇒ real) ⇒ real. y ∈ T⇩ψ⇩pψU ∧ dκ y = (D::('b ⇒ real) ⇒ real)) = restrict0 T⇩ψ⇩pE (λx::('b ⇒ real) ⇒ real. THE y::('b ⇒ real) ⇒ real. y ∈ T⇩ψ⇩pψU ∧ dκ y = x) D› 2. ‹(THE y::('b ⇒ real) ⇒ real. y ∈ T⇩ψ⇩pψU ∧ dκ y = (D::('b ⇒ real) ⇒ real)) = (THE y::('b ⇒ real) ⇒ real. y ∈ T⇩ψ⇩pψU ∧ dκ y = D)›*) using directional_derivative_in_tangent_space[OF k', of "ψ p"] (*‹directional_derivative (k::enat) (apply_chart (ψ::('a, 'b) chart) (p::'a)) (?x::'b) ∈ T⇩ψ⇩pE›*) apply - (*goals: 1. ‹(⋀x. directional_derivative k (apply_chart ψ p) x ∈ T⇩ψ⇩pE) ⟹ (THE y. y ∈ T⇩ψ⇩pψU ∧ dκ y = D) = restrict0 T⇩ψ⇩pE (λx. THE y. y ∈ T⇩ψ⇩pψU ∧ dκ y = x) D› 2. ‹(⋀x. directional_derivative k (apply_chart ψ p) x ∈ T⇩ψ⇩pE) ⟹ (THE y. y ∈ T⇩ψ⇩pψU ∧ dκ y = D) = (THE y. y ∈ T⇩ψ⇩pψU ∧ dκ y = D)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . have y: "?y ∈ T⇩ψ⇩pψU" "dκ ?y = D" apply (simp_all only: y_eq(2)) (*top goal: ‹(THE y. y ∈ T⇩ψ⇩pψU ∧ dκ y = D) ∈ T⇩ψ⇩pψU› and 1 goal remains*) subgoal for apply (intro the_inv_into_into[of dκ T⇩ψ⇩pψU D] (*‹⟦inj_on dκ T⇩ψ⇩pψU; (D::('b::euclidean_space ⇒ real) ⇒ real) ∈ dκ ` T⇩ψ⇩pψU; T⇩ψ⇩pψU ⊆ (?B::(('b::euclidean_space ⇒ real) ⇒ real) set)⟧ ⟹ the_inv_into T⇩ψ⇩pψU dκ D ∈ ?B›*)) (*goal: ‹the_inv_into T⇩ψ⇩pψU dκ D ∈ T⇩ψ⇩pψU›*) using "bij_betw_dκ" (*‹bij_betw dκ T⇩ψ⇩pψU T⇩ψ⇩pE›*) directional_derivative_in_tangent_space[OF k', of "ψ p"] (*‹directional_derivative k (apply_chart ψ p) ?x ∈ T⇩ψ⇩pE›*) apply - (*goals: 1. ‹⟦bij_betw dκ T⇩ψ⇩pψU T⇩ψ⇩pE; ⋀x. directional_derivative k (apply_chart ψ p) x ∈ T⇩ψ⇩pE⟧ ⟹ inj_on dκ T⇩ψ⇩pψU› 2. ‹⟦bij_betw dκ T⇩ψ⇩pψU T⇩ψ⇩pE; ⋀x. directional_derivative k (apply_chart ψ p) x ∈ T⇩ψ⇩pE⟧ ⟹ D ∈ dκ ` T⇩ψ⇩pψU› 3. ‹⟦bij_betw dκ T⇩ψ⇩pψU T⇩ψ⇩pE; ⋀x. directional_derivative k (apply_chart ψ p) x ∈ T⇩ψ⇩pE⟧ ⟹ T⇩ψ⇩pψU ⊆ T⇩ψ⇩pψU› discuss goal 1*) apply ((auto simp: bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*))[1]) (*discuss goal 2*) apply ((auto simp: bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*))[1]) (*discuss goal 3*) apply ((auto simp: bij_betw_def (*‹bij_betw (?f::?'a::type ⇒ ?'b::type) (?A::?'a::type set) (?B::?'b::type set) = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*))[1]) (*proven 3 subgoals*) . subgoal for apply (intro f_the_inv_into_f[of dκ T⇩ψ⇩pψU D] (*‹⟦inj_on dκ T⇩ψ⇩pψU; (D::('b::euclidean_space ⇒ real) ⇒ real) ∈ dκ ` T⇩ψ⇩pψU⟧ ⟹ dκ (the_inv_into T⇩ψ⇩pψU dκ D) = D›*)) (*goal: ‹dκ (the_inv_into T⇩ψ⇩pψU dκ D) = D›*) using "bij_betw_dκ" (*‹bij_betw dκ T⇩ψ⇩pψU T⇩ψ⇩pE›*) directional_derivative_in_tangent_space[OF k', of "ψ p"] (*‹directional_derivative k (apply_chart ψ p) ?x ∈ T⇩ψ⇩pE›*) apply - (*goals: 1. ‹⟦bij_betw dκ T⇩ψ⇩pψU T⇩ψ⇩pE; ⋀x. directional_derivative k (apply_chart ψ p) x ∈ T⇩ψ⇩pE⟧ ⟹ inj_on dκ T⇩ψ⇩pψU› 2. ‹⟦bij_betw dκ T⇩ψ⇩pψU T⇩ψ⇩pE; ⋀x. directional_derivative k (apply_chart ψ p) x ∈ T⇩ψ⇩pE⟧ ⟹ D ∈ dκ ` T⇩ψ⇩pψU› discuss goal 1*) apply ((auto simp: bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*))[1]) (*discuss goal 2*) apply ((auto simp: bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*))[1]) (*proven 2 subgoals*) . . have 1[simp]: "domain ψ ∩ carrier = domain ψ" using domain_atlas_subset_carrier[OF ψ] (*‹domain ψ ⊆ carrier›*) by auto have 2: "restrict0 sub_ψ.sub.carrier f ∈ sub_ψ.sub.diff_fun_space" using f[unfolded diff_fun_space_def] (*‹f ∈ {f. diff_fun k charts f ∧ extensional0 carrier f}›*) by (auto simp: sub_ψ.sub.diff_fun_space_def (*‹sub_ψ.sub.diff_fun_space = {f. diff_fun k (charts_submanifold (domain ψ)) f ∧ extensional0 sub_ψ.sub.carrier f}›*) intro!: diff_fun.diff_fun_cong[where f=f and g="restrict0 (domain ψ) f"] (*‹⟦diff_fun ?k ?charts f; ⋀x. x ∈ manifold.carrier ?charts ⟹ f x = restrict0 (domain ψ) f x⟧ ⟹ diff_fun ?k ?charts (restrict0 (domain ψ) f)›*) intro: diff_fun.diff_fun_submanifold (*‹⟦diff_fun ?k ?charts ?f; open ?S⟧ ⟹ diff_fun ?k (manifold.charts_submanifold ?charts ?S) ?f›*)) let ?f = "(restrict0 diffeo_ψ.dest.carrier (restrict0 sub_ψ.sub.carrier f ∘ inv_chart ψ))" have f2: "?f ∈ diffeo_ψ.dest.diff_fun_space" apply (simp add: diffeo_ψ.dest.diff_fun_space_def (*‹diffeo_ψ.dest.diff_fun_space = {f. diff_fun k (manifold_eucl.dest.charts_submanifold (codomain ψ)) f ∧ extensional0 diffeo_ψ.dest.carrier f}›*)) (*goal: ‹restrict0 diffeo_ψ.dest.carrier (restrict0 sub_ψ.sub.carrier f ∘ inv_chart ψ) ∈ diffeo_ψ.dest.diff_fun_space›*) apply (rule diff_fun.diff_fun_cong[where f="f ∘ inv_chart ψ"] (*‹⟦diff_fun (?k::enat) (?charts::('b, ?'c) chart set) ((f::'a ⇒ real) ∘ inv_chart (ψ::('a, 'b) chart)); ⋀x::'b. x ∈ manifold.carrier ?charts ⟹ (f ∘ inv_chart ψ) x = (?g::'b ⇒ real) x⟧ ⟹ diff_fun ?k ?charts ?g›*)) (*goals: 1. ‹diff_fun (k::enat) (manifold_eucl.dest.charts_submanifold (codomain (ψ::('a, 'b) chart))) ((f::'a ⇒ real) ∘ inv_chart ψ)› 2. ‹⋀x::'b. x ∈ diffeo_ψ.dest.carrier ⟹ ((f::'a ⇒ real) ∘ inv_chart (ψ::('a, 'b) chart)) x = restrict0 (codomain ψ) (restrict0 (domain ψ) f ∘ inv_chart ψ) x› discuss goal 1*) apply (rule diff_fun_compose[of _ _ "charts_submanifold (domain ψ)"] (*‹⟦diff ?k ?M1.0 (charts_submanifold (domain ψ)) ?f; diff_fun ?k (charts_submanifold (domain ψ)) ?g⟧ ⟹ diff_fun ?k ?M1.0 (?g ∘ ?f)›*)) (*goals: 1. ‹diff (k::enat) (manifold_eucl.dest.charts_submanifold (codomain (ψ::('a, 'b) chart))) (charts_submanifold (domain ψ)) (inv_chart ψ)› 2. ‹diff_fun (k::enat) (charts_submanifold (domain (ψ::('a, 'b) chart))) (f::'a ⇒ real)› discuss goal 1*) apply (simp add: diffeo_ψ.inv.diff_axioms (*‹diff (k::enat) (manifold_eucl.dest.charts_submanifold (codomain (ψ::('a, 'b) chart))) (charts_submanifold (domain ψ)) (inv_chart ψ)›*) diff_fun.diff_fun_submanifold (*‹⟦diff_fun (?k::enat) (?charts::(?'a, ?'c) chart set) (?f::?'a ⇒ ?'b); open (?S::?'a set)⟧ ⟹ diff_fun ?k (manifold.charts_submanifold ?charts ?S) ?f›*) diff_fun_spaceD (*‹(?f::'a ⇒ real) ∈ diff_fun_space ⟹ diff_fun (k::enat) (charts::('a, 'b) chart set) ?f›*) f (*‹(f::'a ⇒ real) ∈ diff_fun_space›*)) (*discuss goal 2*) apply (simp add: diffeo_ψ.inv.diff_axioms (*‹diff k (manifold_eucl.dest.charts_submanifold (codomain ψ)) (charts_submanifold (domain ψ)) (inv_chart ψ)›*) diff_fun.diff_fun_submanifold (*‹⟦diff_fun ?k ?charts ?f; open ?S⟧ ⟹ diff_fun ?k (manifold.charts_submanifold ?charts ?S) ?f›*) diff_fun_spaceD (*‹?f ∈ diff_fun_space ⟹ diff_fun k charts ?f›*) f (*‹f ∈ diff_fun_space›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply (simp add: diffeo_ψ.inv.diff_axioms (*‹diff k (manifold_eucl.dest.charts_submanifold (codomain ψ)) (charts_submanifold (domain ψ)) (inv_chart ψ)›*) diff_fun.diff_fun_submanifold (*‹⟦diff_fun ?k ?charts ?f; open ?S⟧ ⟹ diff_fun ?k (manifold.charts_submanifold ?charts ?S) ?f›*) diff_fun_spaceD (*‹?f ∈ diff_fun_space ⟹ diff_fun k charts ?f›*) f (*‹f ∈ diff_fun_space›*)) (*proven 2 subgoals*) . obtain Ng and g where Ng: "ψ p ∈ Ng" "open Ng" "compact (closure Ng)" "closure Ng ⊆ diffeo_ψ.dest.carrier" and g: "g ∈ manifold_eucl.dest.diff_fun_space" "g ∈ diffeo_ψ.dest.diff_fun_space" "⋀x. x ∈ closure Ng ⟹ g x = ?f x" and vg: "⋀v. v ∈ T⇩ψ⇩pψU ⟹ v ?f = v g" "⋀v. v ∈ T⇩ψ⇩pψU ⟹ v g = dκ v g" "⋀v. v ∈ T⇩ψ⇩pE ⟹ dκ¯ v ?f = v g" (*goal: ‹(⋀(Ng::'b::euclidean_space set) g::'b::euclidean_space ⇒ real. ⟦apply_chart (ψ::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart) (p::'a::{second_countable_topology,t2_space}) ∈ Ng; open Ng; compact (closure Ng); closure Ng ⊆ diffeo_ψ.dest.carrier; g ∈ manifold_eucl.dest.diff_fun_space; g ∈ diffeo_ψ.dest.diff_fun_space; ⋀x::'b::euclidean_space. x ∈ closure Ng ⟹ g x = restrict0 diffeo_ψ.dest.carrier (restrict0 sub_ψ.sub.carrier (f::'a::{second_countable_topology,t2_space} ⇒ real) ∘ inv_chart ψ) x; ⋀v::('b::euclidean_space ⇒ real) ⇒ real. v ∈ T⇩ψ⇩pψU ⟹ v (restrict0 diffeo_ψ.dest.carrier (restrict0 sub_ψ.sub.carrier f ∘ inv_chart ψ)) = v g; ⋀v::('b::euclidean_space ⇒ real) ⇒ real. v ∈ T⇩ψ⇩pψU ⟹ v g = dκ v g; ⋀v::('b::euclidean_space ⇒ real) ⇒ real. v ∈ T⇩ψ⇩pE ⟹ dκ¯ v (restrict0 diffeo_ψ.dest.carrier (restrict0 sub_ψ.sub.carrier f ∘ inv_chart ψ)) = v g⟧ ⟹ thesis::bool) ⟹ thesis›*) using extension_lemma_localE2[OF f2] (*‹(⋀N f'. ⟦apply_chart ψ p ∈ N; open N; compact (closure N); closure N ⊆ diffeo_ψ.dest.carrier; f' ∈ manifold_eucl.dest.diff_fun_space; f' ∈ diffeo_ψ.dest.diff_fun_space; ⋀x. x ∈ closure N ⟹ f' x = restrict0 diffeo_ψ.dest.carrier (restrict0 sub_ψ.sub.carrier f ∘ inv_chart ψ) x; ⋀v. v ∈ T⇩ψ⇩pψU ⟹ v (restrict0 diffeo_ψ.dest.carrier (restrict0 sub_ψ.sub.carrier f ∘ inv_chart ψ)) = v f'; ⋀v. v ∈ T⇩ψ⇩pψU ⟹ v f' = dκ v f'; ⋀v. v ∈ T⇩ψ⇩pE ⟹ dκ¯ v (restrict0 diffeo_ψ.dest.carrier (restrict0 sub_ψ.sub.carrier f ∘ inv_chart ψ)) = v f'⟧ ⟹ ?thesis) ⟹ ?thesis›*) by blast have "dι (dψ¯ (dκ¯ D)) f = dψ¯ (dκ¯ D) (restrict0 sub_ψ.sub.carrier (f))" unfolding "sub_ψ.inclusion.push_forward_def" (*goal: ‹restrict0 diff_fun_space (λg. dψ¯ (dκ¯ D) (restrict0 sub_ψ.sub.carrier (g ∘ (λx. x)))) f = dψ¯ (dκ¯ D) (restrict0 sub_ψ.sub.carrier f)›*) by (auto simp: restrict0_apply_in[OF f] (*‹restrict0 diff_fun_space ?f f = ?f f›*) comp_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*)) also (*calculation: ‹dι (dψ¯ (dκ¯ D)) f = dψ¯ (dκ¯ D) (restrict0 sub_ψ.sub.carrier f)›*) have "… = (dκ¯ D) (restrict0 diffeo_ψ.dest.carrier ((restrict0 sub_ψ.sub.carrier f) ∘ inv_chart ψ))" unfolding "diffeo_ψ.inv.push_forward_def" (*goal: ‹restrict0 sub_ψ.sub.diff_fun_space (λg. dκ¯ D (restrict0 diffeo_ψ.dest.carrier (g ∘ inv_chart ψ))) (restrict0 sub_ψ.sub.carrier f) = dκ¯ D (restrict0 diffeo_ψ.dest.carrier (restrict0 sub_ψ.sub.carrier f ∘ inv_chart ψ))›*) using restrict0_apply_in (*‹?x ∈ ?A ⟹ restrict0 ?A ?f ?x = ?f ?x›*) "2" (*‹restrict0 sub_ψ.sub.carrier f ∈ sub_ψ.sub.diff_fun_space›*) by simp also (*calculation: ‹dι (dψ¯ (dκ¯ (D::('b ⇒ real) ⇒ real))) (f::'a ⇒ real) = dκ¯ D (restrict0 diffeo_ψ.dest.carrier (restrict0 sub_ψ.sub.carrier f ∘ inv_chart (ψ::('a, 'b) chart)))›*) have "… = ?y ?f" unfolding the_inv_into_def (*goal: ‹restrict0 T⇩ψ⇩pE (λx. THE y. y ∈ T⇩ψ⇩pψU ∧ dκ y = x) D (restrict0 diffeo_ψ.dest.carrier (restrict0 sub_ψ.sub.carrier f ∘ inv_chart ψ)) = (THE y. y ∈ T⇩ψ⇩pψU ∧ dκ y = D) (restrict0 diffeo_ψ.dest.carrier (restrict0 sub_ψ.sub.carrier f ∘ inv_chart ψ))›*) using directional_derivative_in_tangent_space[OF k', of "ψ p"] (*‹directional_derivative k (apply_chart ψ p) ?x ∈ T⇩ψ⇩pE›*) by (simp add: k (*‹k = ∞›*)) also (*calculation: ‹dι (dψ¯ (dκ¯ D)) f = (THE y. y ∈ T⇩ψ⇩pψU ∧ dκ y = D) (restrict0 diffeo_ψ.dest.carrier (restrict0 sub_ψ.sub.carrier f ∘ inv_chart ψ))›*) have "?y ?f = D g" using vg(1,2)[OF y ( 1 )] (*‹(THE y. y ∈ T⇩ψ⇩pψU ∧ dκ y = D) (restrict0 diffeo_ψ.dest.carrier (restrict0 sub_ψ.sub.carrier f ∘ inv_chart ψ)) = (THE y. y ∈ T⇩ψ⇩pψU ∧ dκ y = D) g› ‹(THE y. y ∈ T⇩ψ⇩pψU ∧ dκ y = D) g = dκ (THE y. y ∈ T⇩ψ⇩pψU ∧ dκ y = D) g›*) y(2) (*‹dκ (THE y. y ∈ T⇩ψ⇩pψU ∧ dκ y = D) = D›*) by simp also (*calculation: ‹dι (dψ¯ (dκ¯ D)) f = D g›*) have "D g = frechet_derivative g (at (ψ p)) b" unfolding D directional_derivative_def (*goal: ‹restrict0 manifold_eucl.dest.diff_fun_space (λf. frechet_derivative f (at (apply_chart ψ p)) b) g = frechet_derivative g (at (apply_chart ψ p)) b›*) using restrict0_apply_in[OF g ( 1 )] (*‹restrict0 manifold_eucl.dest.diff_fun_space (?f::('b ⇒ real) ⇒ ?'b) (g::'b ⇒ real) = ?f g›*) by auto also (*calculation: ‹dι (dψ¯ (dκ¯ D)) f = frechet_derivative g (at (apply_chart ψ p)) b›*) have "… = frechet_derivative (f ∘ inv_chart ψ) (at (ψ p)) b" apply (rule frechet_derivative_transform_within_open_ext[where X=Ng] (*‹⟦?f differentiable at ?xa; open Ng; ?xa ∈ Ng; ⋀x. x ∈ Ng ⟹ ?f x = ?g x⟧ ⟹ frechet_derivative ?f (at ?xa) ?x = frechet_derivative ?g (at ?xa) ?x›*)) (*goal: ‹frechet_derivative g (at (apply_chart ψ p)) b = frechet_derivative (f ∘ inv_chart ψ) (at (apply_chart ψ p)) b›*) using g(3) (*‹?x4 ∈ closure Ng ⟹ g ?x4 = restrict0 diffeo_ψ.dest.carrier (restrict0 sub_ψ.sub.carrier f ∘ inv_chart ψ) ?x4›*) Ng(1,2,4) (*‹apply_chart ψ p ∈ Ng› ‹open Ng› ‹closure (Ng::'b set) ⊆ diffeo_ψ.dest.carrier›*) g(1) (*‹g ∈ manifold_eucl.dest.diff_fun_space›*) k (*‹(k::enat) = ∞›*) apply - (*goals: 1. ‹⟦⋀x::'b. x ∈ closure (Ng::'b set) ⟹ (g::'b ⇒ real) x = restrict0 diffeo_ψ.dest.carrier (restrict0 sub_ψ.sub.carrier (f::'a ⇒ real) ∘ inv_chart (ψ::('a, 'b) chart)) x; apply_chart ψ (p::'a) ∈ Ng; open Ng; closure Ng ⊆ diffeo_ψ.dest.carrier; g ∈ manifold_eucl.dest.diff_fun_space; (k::enat) = ∞⟧ ⟹ g differentiable at (apply_chart ψ p)› 2. ‹⟦⋀x::'b. x ∈ closure (Ng::'b set) ⟹ (g::'b ⇒ real) x = restrict0 diffeo_ψ.dest.carrier (restrict0 sub_ψ.sub.carrier (f::'a ⇒ real) ∘ inv_chart (ψ::('a, 'b) chart)) x; apply_chart ψ (p::'a) ∈ Ng; open Ng; closure Ng ⊆ diffeo_ψ.dest.carrier; g ∈ manifold_eucl.dest.diff_fun_space; (k::enat) = ∞⟧ ⟹ open Ng› 3. ‹⟦⋀x::'b. x ∈ closure (Ng::'b set) ⟹ (g::'b ⇒ real) x = restrict0 diffeo_ψ.dest.carrier (restrict0 sub_ψ.sub.carrier (f::'a ⇒ real) ∘ inv_chart (ψ::('a, 'b) chart)) x; apply_chart ψ (p::'a) ∈ Ng; open Ng; closure Ng ⊆ diffeo_ψ.dest.carrier; g ∈ manifold_eucl.dest.diff_fun_space; (k::enat) = ∞⟧ ⟹ apply_chart ψ p ∈ Ng› 4. ‹⋀x::'b. ⟦x ∈ (Ng::'b set); ⋀x::'b. x ∈ closure Ng ⟹ (g::'b ⇒ real) x = restrict0 diffeo_ψ.dest.carrier (restrict0 sub_ψ.sub.carrier (f::'a ⇒ real) ∘ inv_chart (ψ::('a, 'b) chart)) x; apply_chart ψ (p::'a) ∈ Ng; open Ng; closure Ng ⊆ diffeo_ψ.dest.carrier; g ∈ manifold_eucl.dest.diff_fun_space; (k::enat) = ∞⟧ ⟹ g x = (f ∘ inv_chart ψ) x› discuss goal 1*) apply ((auto simp: differentiable_onD (*‹⟦(?f::?'a::real_normed_vector ⇒ ?'b::real_normed_vector) differentiable_on (?S::?'a::real_normed_vector set); (?x::?'a::real_normed_vector) ∈ ?S⟧ ⟹ ?f differentiable at ?x within ?S›*))[1]) (*discuss goal 2*) apply ((auto simp: differentiable_onD (*‹⟦?f differentiable_on ?S; ?x ∈ ?S⟧ ⟹ ?f differentiable at ?x within ?S›*))[1]) (*discuss goal 3*) apply ((auto simp: differentiable_onD (*‹⟦?f differentiable_on ?S; ?x ∈ ?S⟧ ⟹ ?f differentiable at ?x within ?S›*))[1]) (*discuss goal 4*) apply ((auto simp: differentiable_onD (*‹⟦?f differentiable_on ?S; ?x ∈ ?S⟧ ⟹ ?f differentiable at ?x within ?S›*))[1]) (*proven 4 subgoals*) . finally (*calculation: ‹dι (dψ¯ (dκ¯ D)) f = frechet_derivative (f ∘ inv_chart ψ) (at (apply_chart ψ p)) b›*) show "dι (dψ¯ (dκ¯ (directional_derivative k (apply_chart ψ p) b))) f = frechet_derivative (f ∘ inv_chart ψ) (at (ψ p)) b" by auto qed lemma coordinate_vector_apply_out: assumes k: "k=∞" and f: "f ∉ diff_fun_space" shows "(coordinate_vector b) f = 0" using bij_betwE[OF coordinate_vector_bij [ OF k ]] (*‹∀a∈UNIV. coordinate_vector a ∈ T⇩pM›*) f (*‹f ∉ diff_fun_space›*) extensional0_outside (*‹⟦?x ∉ ?S; extensional0 ?S ?f⟧ ⟹ ?f ?x = 0›*) unfolding tangent_space_def (*goal: ‹coordinate_vector b f = 0›*) by fastforce text ‹Just the same as @{thm coordinate_vector_apply_in}, but with unfolded definition. For display.› lemma coordinate_vector_apply_in': assumes k: "k=∞" and f: "f∈diff_fun_space" shows "(dι ∘ dψ¯ ∘ dκ¯ ∘ directional_derivative ∞ (ψ p)) b f = frechet_derivative (f ∘ inv_chart ψ) (at (ψ p)) b" using coordinate_vector_apply_in[OF assms] (*‹coordinate_vector ?b f = frechet_derivative (f ∘ inv_chart ψ) (at (apply_chart ψ p)) ?b›*) unfolding coordinate_vector_def k[symmetric] (*goal: ‹(dι ∘ dψ¯ ∘ dκ¯ ∘ directional_derivative k (apply_chart ψ p)) b f = frechet_derivative (f ∘ inv_chart ψ) (at (apply_chart ψ p)) b›*) . definition component_function :: "(('a ⇒ real) ⇒ real) ⇒ 'b ⇒ real" where "component_function ≡ coord_fun ∘ dκ ∘ dψ ∘ dι¯" definition tangent_chart_fun :: "(('a ⇒ real) ⇒ real) ⇒ 'b" where "tangent_chart_fun v ≡ ∑i∈Basis. component_function v i *⇩R i" lemma component_function_T⇩pU: "component_function (dι v) = coord_fun (dκ (dψ v))" if "v ∈ T⇩pU" for v using tangent_submanifold_isomorphism(1) (*‹bij_betw dι T⇩pU T⇩pM›*) that (*‹v ∈ T⇩pU›*) by (auto simp: bij_betwE (*‹bij_betw ?f ?A ?B ⟹ ∀a∈?A. ?f a ∈ ?B›*) the_inv_into_f_f[OF bij_betw_imp_inj_on] (*‹⟦bij_betw ?f ?A ?B1; ?x ∈ ?A⟧ ⟹ the_inv_into ?A ?f (?f ?x) = ?x›*) component_function_def (*‹component_function ≡ coord_fun ∘ dκ ∘ dψ ∘ dι¯›*)) lemma component_function_apply_in_T⇩pU: "component_function (dι v) i = v (restrict0 (domain ψ) (λx. (ψ x - ψ p) ∙ i))" if "v ∈ T⇩pU" for v i proof (-) (*goal: ‹component_function (dι (v::('a::{second_countable_topology,t2_space} ⇒ real) ⇒ real)) (i::'b::euclidean_space) = v (restrict0 (domain (ψ::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart)) (λx::'a::{second_countable_topology,t2_space}. (apply_chart ψ x - apply_chart ψ (p::'a::{second_countable_topology,t2_space})) ∙ i))›*) from that (*‹(v::('a ⇒ real) ⇒ real) ∈ T⇩pU›*) have assms: "dι v ∈ T⇩pM" "v∈T⇩pU" using tangent_submanifold_isomorphism(1) (*‹bij_betw dι T⇩pU T⇩pM›*) apply - (*goals: 1. ‹⟦(v::('a::{second_countable_topology,t2_space} ⇒ real) ⇒ real) ∈ T⇩pU; bij_betw dι T⇩pU T⇩pM⟧ ⟹ dι v ∈ T⇩pM› 2. ‹⟦(v::('a::{second_countable_topology,t2_space} ⇒ real) ⇒ real) ∈ T⇩pU; bij_betw dι T⇩pU T⇩pM⟧ ⟹ v ∈ T⇩pU› discuss goal 1*) apply ((auto simp: bij_betwE (*‹bij_betw (?f::?'a ⇒ ?'b) (?A::?'a set) (?B::?'b set) ⟹ ∀a::?'a∈?A. ?f a ∈ ?B›*))[1]) (*discuss goal 2*) apply ((auto simp: bij_betwE (*‹bij_betw (?f::?'a ⇒ ?'b) (?A::?'a set) (?B::?'b set) ⟹ ∀a::?'a∈?A. ?f a ∈ ?B›*))[1]) (*proven 2 subgoals*) . have 1: "(λx. (x - ψ p) ∙ i) ∈ manifold_eucl.dest.diff_fun_space" by (auto intro!: smooth_on_inner (*‹⟦(?k::enat)-smooth_on (?S::?'d set) (?f::?'d ⇒ ?'a); ?k-smooth_on ?S (?g::?'d ⇒ ?'a); open ?S⟧ ⟹ ?k-smooth_on ?S (λx::?'d. ?f x ∙ ?g x)›*) smooth_on_minus (*‹⟦(?k::enat)-smooth_on (?S::?'a set) (?f::?'a ⇒ ?'b); ?k-smooth_on ?S (?g::?'a ⇒ ?'b); open ?S⟧ ⟹ ?k-smooth_on ?S (λx::?'a. ?f x - ?g x)›*)) have 2: "(restrict0 diffeo_ψ.dest.carrier ((λx. (x - ψ p) ∙ i) ∘ (λx. x))) ∈ diffeo_ψ.dest.diff_fun_space" apply (simp add: diffeo_ψ.dest.diff_fun_space_def (*‹diffeo_ψ.dest.diff_fun_space = {f. diff_fun k (manifold_eucl.dest.charts_submanifold (codomain ψ)) f ∧ extensional0 diffeo_ψ.dest.carrier f}›*)) (*goal: ‹restrict0 diffeo_ψ.dest.carrier ((λx. (x - apply_chart ψ p) ∙ i) ∘ (λx. x)) ∈ diffeo_ψ.dest.diff_fun_space›*) apply (rule diff_fun.diff_fun_cong[of k _ "(λx. (x - ψ p) ∙ i)"] (*‹⟦diff_fun k ?charts (λx. (x - apply_chart ψ p) ∙ i); ⋀x. x ∈ manifold.carrier ?charts ⟹ (x - apply_chart ψ p) ∙ i = ?g x⟧ ⟹ diff_fun k ?charts ?g›*)) (*goal: ‹diff_fun k (manifold_eucl.dest.charts_submanifold (codomain ψ)) (restrict0 (codomain ψ) ((λx. (x - apply_chart ψ p) ∙ i) ∘ (λx. x)))›*) apply (rule diff_fun.diff_fun_submanifold (*‹⟦diff_fun ?k ?charts ?f; open ?S⟧ ⟹ diff_fun ?k (manifold.charts_submanifold ?charts ?S) ?f›*)) (*top goal: ‹diff_fun k (manifold_eucl.dest.charts_submanifold (codomain ψ)) (λx. (x - apply_chart ψ p) ∙ i)› and 1 goal remains*) using "1" (*‹(λx. (x - apply_chart ψ p) ∙ i) ∈ manifold_eucl.dest.diff_fun_space›*) apply - (*goals: 1. ‹(λx. (x - apply_chart ψ p) ∙ i) ∈ manifold_eucl.dest.diff_fun_space ⟹ diff_fun k charts_eucl (λx. (x - apply_chart ψ p) ∙ i)› 2. ‹(λx. (x - apply_chart ψ p) ∙ i) ∈ manifold_eucl.dest.diff_fun_space ⟹ open (codomain ψ)› 3. ‹⋀x. ⟦x ∈ diffeo_ψ.dest.carrier; (λx. (x - apply_chart ψ p) ∙ i) ∈ manifold_eucl.dest.diff_fun_space⟧ ⟹ (x - apply_chart ψ p) ∙ i = restrict0 (codomain ψ) ((λx. (x - apply_chart ψ p) ∙ i) ∘ (λx. x)) x› discuss goal 1*) apply ((auto intro: diff_fun_charts_euclI (*‹?k-smooth_on UNIV ?g ⟹ diff_fun ?k charts_eucl ?g›*))[1]) (*discuss goal 2*) apply ((auto intro: diff_fun_charts_euclI (*‹(?k::enat)-smooth_on UNIV (?g::?'a ⇒ ?'b) ⟹ diff_fun ?k charts_eucl ?g›*))[1]) (*discuss goal 3*) apply ((auto intro: diff_fun_charts_euclI (*‹?k-smooth_on UNIV ?g ⟹ diff_fun ?k charts_eucl ?g›*))[1]) (*proven 3 subgoals*) . let ?g = "restrict0 diffeo_ψ.dest.carrier (λx. (x - ψ p) ∙ i)" let ?f = "restrict0 sub_ψ.sub.carrier (?g ∘ ψ)" have f: "?f ∈ sub_ψ.sub.diff_fun_space" apply (simp add: sub_ψ.sub.diff_fun_space_def (*‹sub_ψ.sub.diff_fun_space = {f. diff_fun k (charts_submanifold (domain ψ)) f ∧ extensional0 sub_ψ.sub.carrier f}›*)) (*goal: ‹restrict0 sub_ψ.sub.carrier (restrict0 diffeo_ψ.dest.carrier (λx. (x - apply_chart ψ p) ∙ i) ∘ apply_chart ψ) ∈ sub_ψ.sub.diff_fun_space›*) apply (rule diff_fun.diff_fun_cong[of k _ "(λx. (x - ψ p) ∙ i) ∘ ψ"] (*‹⟦diff_fun k ?charts ((λx. (x - apply_chart ψ p) ∙ i) ∘ apply_chart ψ); ⋀x. x ∈ manifold.carrier ?charts ⟹ ((λx. (x - apply_chart ψ p) ∙ i) ∘ apply_chart ψ) x = ?g x⟧ ⟹ diff_fun k ?charts ?g›*)) (*goal: ‹diff_fun k (charts_submanifold (domain ψ)) (restrict0 (domain ψ ∩ carrier) (restrict0 (codomain ψ) (λx. (x - apply_chart ψ p) ∙ i) ∘ apply_chart ψ))›*) apply (rule diff_fun_compose[of k _ "manifold_eucl.charts_submanifold (codomain ψ)"] (*‹⟦diff k ?M1.0 (manifold_eucl.dest.charts_submanifold (codomain ψ)) ?f; diff_fun k (manifold_eucl.dest.charts_submanifold (codomain ψ)) ?g⟧ ⟹ diff_fun k ?M1.0 (?g ∘ ?f)›*)) (*top goal: ‹diff_fun k (charts_submanifold (domain ψ)) ((λx. (x - apply_chart ψ p) ∙ i) ∘ apply_chart ψ)› and 1 goal remains*) using "1" (*‹(λx. (x - apply_chart ψ p) ∙ i) ∈ manifold_eucl.dest.diff_fun_space›*) apply - (*goals: 1. ‹(λx::'b::euclidean_space. (x - apply_chart (ψ::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart) (p::'a::{second_countable_topology,t2_space})) ∙ (i::'b::euclidean_space)) ∈ manifold_eucl.dest.diff_fun_space ⟹ diff (k::enat) (charts_submanifold (domain ψ)) (manifold_eucl.dest.charts_submanifold (codomain ψ)) (apply_chart ψ)› 2. ‹(λx::'b::euclidean_space. (x - apply_chart (ψ::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart) (p::'a::{second_countable_topology,t2_space})) ∙ (i::'b::euclidean_space)) ∈ manifold_eucl.dest.diff_fun_space ⟹ diff_fun (k::enat) (manifold_eucl.dest.charts_submanifold (codomain ψ)) (λx::'b::euclidean_space. (x - apply_chart ψ p) ∙ i)› 3. ‹⋀x::'a::{second_countable_topology,t2_space}. ⟦x ∈ sub_ψ.sub.carrier; (λx::'b::euclidean_space. (x - apply_chart (ψ::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart) (p::'a::{second_countable_topology,t2_space})) ∙ (i::'b::euclidean_space)) ∈ manifold_eucl.dest.diff_fun_space⟧ ⟹ ((λx::'b::euclidean_space. (x - apply_chart ψ p) ∙ i) ∘ apply_chart ψ) x = restrict0 (domain ψ ∩ carrier) (restrict0 (codomain ψ) (λx::'b::euclidean_space. (x - apply_chart ψ p) ∙ i) ∘ apply_chart ψ) x› discuss goal 1*) apply ((auto intro: diff_fun_charts_euclI (*‹?k-smooth_on UNIV ?g ⟹ diff_fun ?k charts_eucl ?g›*) diffeo_ψ.diff_axioms (*‹diff k (charts_submanifold (domain ψ)) (manifold_eucl.dest.charts_submanifold (codomain ψ)) (apply_chart ψ)›*) diff_fun.diff_fun_submanifold (*‹⟦diff_fun ?k ?charts ?f; open ?S⟧ ⟹ diff_fun ?k (manifold.charts_submanifold ?charts ?S) ?f›*))[1]) (*discuss goal 2*) apply ((auto intro: diff_fun_charts_euclI (*‹(?k::enat)-smooth_on UNIV (?g::?'a::euclidean_space ⇒ ?'b::euclidean_space) ⟹ diff_fun ?k charts_eucl ?g›*) diffeo_ψ.diff_axioms (*‹diff (k::enat) (charts_submanifold (domain (ψ::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart))) (manifold_eucl.dest.charts_submanifold (codomain ψ)) (apply_chart ψ)›*) diff_fun.diff_fun_submanifold (*‹⟦diff_fun (?k::enat) (?charts::(?'a::{second_countable_topology,t2_space}, ?'c::euclidean_space) chart set) (?f::?'a::{second_countable_topology,t2_space} ⇒ ?'b::euclidean_space); open (?S::?'a::{second_countable_topology,t2_space} set)⟧ ⟹ diff_fun ?k (manifold.charts_submanifold ?charts ?S) ?f›*))[1]) (*discuss goal 3*) apply ((auto intro: diff_fun_charts_euclI (*‹?k-smooth_on UNIV ?g ⟹ diff_fun ?k charts_eucl ?g›*) diffeo_ψ.diff_axioms (*‹diff k (charts_submanifold (domain ψ)) (manifold_eucl.dest.charts_submanifold (codomain ψ)) (apply_chart ψ)›*) diff_fun.diff_fun_submanifold (*‹⟦diff_fun ?k ?charts ?f; open ?S⟧ ⟹ diff_fun ?k (manifold.charts_submanifold ?charts ?S) ?f›*))[1]) (*proven 3 subgoals*) . have "component_function (dι v) i = (coord_fun (dκ (dψ v))) i" using "component_function_T⇩pU"[OF assms ( 2 )] (*‹component_function (dι v) = coord_fun (dκ (dψ v))›*) by simp also (*calculation: ‹component_function (dι (v::('a::{second_countable_topology,t2_space} ⇒ real) ⇒ real)) (i::'b::euclidean_space) = coord_fun (dκ (dψ v)) i›*) have "… = (λg. dψ v (restrict0 diffeo_ψ.dest.carrier (g ∘ (λx. x)))) (λx. (x - ψ p) ∙ i)" by (simp only: restrict0_apply_in[OF 1] (*‹restrict0 manifold_eucl.dest.diff_fun_space (?f::('b::euclidean_space ⇒ real) ⇒ ?'b::zero) (λx::'b::euclidean_space. (x - apply_chart (ψ::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart) (p::'a::{second_countable_topology,t2_space})) ∙ (i::'b::euclidean_space)) = ?f (λx::'b::euclidean_space. (x - apply_chart ψ p) ∙ i)›*) coord_fun_def (*‹coord_fun (?X::('b::euclidean_space ⇒ real) ⇒ ?'c::type) (?i::'b::euclidean_space) = ?X (λx::'b::euclidean_space. (x - apply_chart (ψ::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart) (p::'a::{second_countable_topology,t2_space})) ∙ ?i)›*) sub_eucl.inclusion.push_forward_def (*‹dκ (?X::('b::euclidean_space ⇒ real) ⇒ real) = restrict0 manifold_eucl.dest.diff_fun_space (λg::'b::euclidean_space ⇒ real. ?X (restrict0 diffeo_ψ.dest.carrier (g ∘ (λx::'b::euclidean_space. x))))›*)) also (*calculation: ‹component_function (dι v) i = dψ v (restrict0 diffeo_ψ.dest.carrier ((λx. (x - apply_chart ψ p) ∙ i) ∘ (λx. x)))›*) have "… = v (restrict0 sub_ψ.sub.carrier (?g ∘ ψ))" apply (simp only: diffeo_ψ.push_forward_def (*‹dψ ?X = restrict0 diffeo_ψ.dest.diff_fun_space (λg. ?X (restrict0 sub_ψ.sub.carrier (g ∘ apply_chart ψ)))›*) restrict0_apply_in[OF 2] (*‹restrict0 diffeo_ψ.dest.diff_fun_space ?f (restrict0 diffeo_ψ.dest.carrier ((λx. (x - apply_chart ψ p) ∙ i) ∘ (λx. x))) = ?f (restrict0 diffeo_ψ.dest.carrier ((λx. (x - apply_chart ψ p) ∙ i) ∘ (λx. x)))›*)) (*goal: ‹dψ (v::('a ⇒ real) ⇒ real) (restrict0 diffeo_ψ.dest.carrier ((λx::'b. (x - apply_chart (ψ::('a, 'b) chart) (p::'a)) ∙ (i::'b)) ∘ (λx::'b. x))) = v (restrict0 sub_ψ.sub.carrier (restrict0 diffeo_ψ.dest.carrier (λx::'b. (x - apply_chart ψ p) ∙ i) ∘ apply_chart ψ))›*) by (simp only: o_id[unfolded id_def] (*‹?f ∘ (λx. x) = ?f›*)) also (*calculation: ‹component_function (dι (v::('a::{second_countable_topology,t2_space} ⇒ real) ⇒ real)) (i::'b::euclidean_space) = v (restrict0 sub_ψ.sub.carrier (restrict0 diffeo_ψ.dest.carrier (λx::'b::euclidean_space. (x - apply_chart (ψ::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart) (p::'a::{second_countable_topology,t2_space})) ∙ i) ∘ apply_chart ψ))›*) have "v ?f = v (restrict0 (domain ψ) (λx. (ψ x - ψ p) ∙ i))" apply (rule sub_ψ.sub.derivation_eq_localI[of "domain ψ" p v] (*‹⟦open (domain ψ); p ∈ domain ψ; domain ψ ⊆ sub_ψ.sub.carrier; v ∈ T⇩pU; ?f ∈ sub_ψ.sub.diff_fun_space; ?g ∈ sub_ψ.sub.diff_fun_space; ⋀x. x ∈ domain ψ ⟹ ?f x = ?g x⟧ ⟹ v ?f = v ?g›*)) (*goal: ‹v (restrict0 sub_ψ.sub.carrier (restrict0 diffeo_ψ.dest.carrier (λx. (x - apply_chart ψ p) ∙ i) ∘ apply_chart ψ)) = v (restrict0 (domain ψ) (λx. (apply_chart ψ x - apply_chart ψ p) ∙ i))›*) prefer 6 (*top goal: ‹restrict0 (domain ψ) (λx. (apply_chart ψ x - apply_chart ψ p) ∙ i) ∈ sub_ψ.sub.diff_fun_space› and 6 goals remain*) subgoal for apply (simp add: sub_ψ.sub.diff_fun_space_def (*‹sub_ψ.sub.diff_fun_space = {f::'a::{second_countable_topology,t2_space} ⇒ real. diff_fun (k::enat) (charts_submanifold (domain (ψ::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart))) f ∧ extensional0 sub_ψ.sub.carrier f}›*), intro conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goal: ‹restrict0 (domain ψ) (λx. (apply_chart ψ x - apply_chart ψ p) ∙ i) ∈ sub_ψ.sub.diff_fun_space›*) apply (rule diff_fun.diff_fun_cong[of _ _ "(λx. (x - ψ p) ∙ i) ∘ ψ"] (*‹⟦diff_fun ?k ?charts ((λx. (x - apply_chart ψ p) ∙ i) ∘ apply_chart ψ); ⋀x. x ∈ manifold.carrier ?charts ⟹ ((λx. (x - apply_chart ψ p) ∙ i) ∘ apply_chart ψ) x = ?g x⟧ ⟹ diff_fun ?k ?charts ?g›*)) (*top goal: ‹diff_fun k (charts_submanifold (domain ψ)) (restrict0 (domain ψ) (λx. (apply_chart ψ x - apply_chart ψ p) ∙ i))› and 1 goal remains*) apply (rule diff_fun_compose[of k _ "manifold_eucl.charts_submanifold (codomain ψ)"] (*‹⟦diff k ?M1.0 (manifold_eucl.dest.charts_submanifold (codomain ψ)) ?f; diff_fun k (manifold_eucl.dest.charts_submanifold (codomain ψ)) ?g⟧ ⟹ diff_fun k ?M1.0 (?g ∘ ?f)›*)) (*top goal: ‹diff_fun (k::enat) (charts_submanifold (domain (ψ::('a, 'b) chart))) ((λx::'b. (x - apply_chart ψ (p::'a)) ∙ (i::'b)) ∘ apply_chart ψ)› and 2 goals remain*) using "1" (*‹(λx. (x - apply_chart ψ p) ∙ i) ∈ manifold_eucl.dest.diff_fun_space›*) "sub_ψ_carrier" (*‹sub_ψ.sub.carrier = domain (ψ::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart)›*) apply - (*goals: 1. ‹⟦(λx::'b. (x - apply_chart (ψ::('a, 'b) chart) (p::'a)) ∙ (i::'b)) ∈ manifold_eucl.dest.diff_fun_space; sub_ψ.sub.carrier = domain ψ⟧ ⟹ diff (k::enat) (charts_submanifold (domain ψ)) (manifold_eucl.dest.charts_submanifold (codomain ψ)) (apply_chart ψ)› 2. ‹⟦(λx::'b. (x - apply_chart (ψ::('a, 'b) chart) (p::'a)) ∙ (i::'b)) ∈ manifold_eucl.dest.diff_fun_space; sub_ψ.sub.carrier = domain ψ⟧ ⟹ diff_fun (k::enat) (manifold_eucl.dest.charts_submanifold (codomain ψ)) (λx::'b. (x - apply_chart ψ p) ∙ i)› 3. ‹⋀x::'a. ⟦x ∈ sub_ψ.sub.carrier; (λx::'b. (x - apply_chart (ψ::('a, 'b) chart) (p::'a)) ∙ (i::'b)) ∈ manifold_eucl.dest.diff_fun_space; sub_ψ.sub.carrier = domain ψ⟧ ⟹ ((λx::'b. (x - apply_chart ψ p) ∙ i) ∘ apply_chart ψ) x = restrict0 (domain ψ) (λx::'a. (apply_chart ψ x - apply_chart ψ p) ∙ i) x› 4. ‹⟦(λx::'b. (x - apply_chart (ψ::('a, 'b) chart) (p::'a)) ∙ (i::'b)) ∈ manifold_eucl.dest.diff_fun_space; sub_ψ.sub.carrier = domain ψ⟧ ⟹ extensional0 (domain ψ ∩ carrier) (restrict0 (domain ψ) (λx::'a. (apply_chart ψ x - apply_chart ψ p) ∙ i))› discuss goal 1*) apply ((auto simp: diffeo_ψ.diff_axioms (*‹diff k (charts_submanifold (domain ψ)) (manifold_eucl.dest.charts_submanifold (codomain ψ)) (apply_chart ψ)›*) manifold_eucl.dest.diff_fun_spaceD (*‹?f ∈ manifold_eucl.dest.diff_fun_space ⟹ diff_fun k charts_eucl ?f›*) diff_fun.diff_fun_submanifold (*‹⟦diff_fun ?k ?charts ?f; open ?S⟧ ⟹ diff_fun ?k (manifold.charts_submanifold ?charts ?S) ?f›*))[1]) (*discuss goal 2*) apply ((auto simp: diffeo_ψ.diff_axioms (*‹diff k (charts_submanifold (domain ψ)) (manifold_eucl.dest.charts_submanifold (codomain ψ)) (apply_chart ψ)›*) manifold_eucl.dest.diff_fun_spaceD (*‹?f ∈ manifold_eucl.dest.diff_fun_space ⟹ diff_fun k charts_eucl ?f›*) diff_fun.diff_fun_submanifold (*‹⟦diff_fun ?k ?charts ?f; open ?S⟧ ⟹ diff_fun ?k (manifold.charts_submanifold ?charts ?S) ?f›*))[1]) (*discuss goal 3*) apply ((auto simp: diffeo_ψ.diff_axioms (*‹diff k (charts_submanifold (domain ψ)) (manifold_eucl.dest.charts_submanifold (codomain ψ)) (apply_chart ψ)›*) manifold_eucl.dest.diff_fun_spaceD (*‹?f ∈ manifold_eucl.dest.diff_fun_space ⟹ diff_fun k charts_eucl ?f›*) diff_fun.diff_fun_submanifold (*‹⟦diff_fun ?k ?charts ?f; open ?S⟧ ⟹ diff_fun ?k (manifold.charts_submanifold ?charts ?S) ?f›*))[1]) (*discuss goal 4*) apply ((auto simp: diffeo_ψ.diff_axioms (*‹diff k (charts_submanifold (domain ψ)) (manifold_eucl.dest.charts_submanifold (codomain ψ)) (apply_chart ψ)›*) manifold_eucl.dest.diff_fun_spaceD (*‹?f ∈ manifold_eucl.dest.diff_fun_space ⟹ diff_fun k charts_eucl ?f›*) diff_fun.diff_fun_submanifold (*‹⟦diff_fun ?k ?charts ?f; open ?S⟧ ⟹ diff_fun ?k (manifold.charts_submanifold ?charts ?S) ?f›*))[1]) (*proven 4 subgoals*) . using domain_atlas_subset_carrier (*‹?c ∈ atlas ⟹ domain ?c ⊆ carrier›*) assms(2) (*‹v ∈ T⇩pU›*) f (*‹restrict0 sub_ψ.sub.carrier (restrict0 diffeo_ψ.dest.carrier (λx. (x - apply_chart ψ p) ∙ i) ∘ apply_chart ψ) ∈ sub_ψ.sub.diff_fun_space›*) "sub_ψ_carrier" (*‹sub_ψ.sub.carrier = domain ψ›*) apply - (*goals: 1. ‹⟦⋀c. c ∈ atlas ⟹ domain c ⊆ carrier; v ∈ T⇩pU; restrict0 sub_ψ.sub.carrier (restrict0 diffeo_ψ.dest.carrier (λx. (x - apply_chart ψ p) ∙ i) ∘ apply_chart ψ) ∈ sub_ψ.sub.diff_fun_space; sub_ψ.sub.carrier = domain ψ⟧ ⟹ open (domain ψ)› 2. ‹⟦⋀c. c ∈ atlas ⟹ domain c ⊆ carrier; v ∈ T⇩pU; restrict0 sub_ψ.sub.carrier (restrict0 diffeo_ψ.dest.carrier (λx. (x - apply_chart ψ p) ∙ i) ∘ apply_chart ψ) ∈ sub_ψ.sub.diff_fun_space; sub_ψ.sub.carrier = domain ψ⟧ ⟹ p ∈ domain ψ› 3. ‹⟦⋀c. c ∈ atlas ⟹ domain c ⊆ carrier; v ∈ T⇩pU; restrict0 sub_ψ.sub.carrier (restrict0 diffeo_ψ.dest.carrier (λx. (x - apply_chart ψ p) ∙ i) ∘ apply_chart ψ) ∈ sub_ψ.sub.diff_fun_space; sub_ψ.sub.carrier = domain ψ⟧ ⟹ domain ψ ⊆ sub_ψ.sub.carrier› 4. ‹⟦⋀c. c ∈ atlas ⟹ domain c ⊆ carrier; v ∈ T⇩pU; restrict0 sub_ψ.sub.carrier (restrict0 diffeo_ψ.dest.carrier (λx. (x - apply_chart ψ p) ∙ i) ∘ apply_chart ψ) ∈ sub_ψ.sub.diff_fun_space; sub_ψ.sub.carrier = domain ψ⟧ ⟹ v ∈ T⇩pU› 5. ‹⟦⋀c. c ∈ atlas ⟹ domain c ⊆ carrier; v ∈ T⇩pU; restrict0 sub_ψ.sub.carrier (restrict0 diffeo_ψ.dest.carrier (λx. (x - apply_chart ψ p) ∙ i) ∘ apply_chart ψ) ∈ sub_ψ.sub.diff_fun_space; sub_ψ.sub.carrier = domain ψ⟧ ⟹ restrict0 sub_ψ.sub.carrier (restrict0 diffeo_ψ.dest.carrier (λx. (x - apply_chart ψ p) ∙ i) ∘ apply_chart ψ) ∈ sub_ψ.sub.diff_fun_space› 6. ‹⋀x. ⟦x ∈ domain ψ; ⋀c. c ∈ atlas ⟹ domain c ⊆ carrier; v ∈ T⇩pU; restrict0 sub_ψ.sub.carrier (restrict0 diffeo_ψ.dest.carrier (λx. (x - apply_chart ψ p) ∙ i) ∘ apply_chart ψ) ∈ sub_ψ.sub.diff_fun_space; sub_ψ.sub.carrier = domain ψ⟧ ⟹ restrict0 sub_ψ.sub.carrier (restrict0 diffeo_ψ.dest.carrier (λx. (x - apply_chart ψ p) ∙ i) ∘ apply_chart ψ) x = restrict0 (domain ψ) (λx. (apply_chart ψ x - apply_chart ψ p) ∙ i) x› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*proven 6 subgoals*) . finally (*calculation: ‹component_function (dι v) i = v (restrict0 (domain ψ) (λx. (apply_chart ψ x - apply_chart ψ p) ∙ i))›*) show "component_function (dι v) i = v (restrict0 (domain ψ) (λx. (ψ x - ψ p) ∙ i))" . qed lemma component_function_apply_in_T⇩pM: "component_function v i = (dι¯ v) (restrict0 (domain ψ) (λx. (ψ x - ψ p) ∙ i))" if "v ∈ T⇩pM" for v i proof (-) (*goal: ‹component_function v i = dι¯ v (restrict0 (domain ψ) (λx. (apply_chart ψ x - apply_chart ψ p) ∙ i))›*) let ?u = "dι¯ v" have 1: "?u ∈ T⇩pU" using bij_betwE[OF bij_betw_dι_inv] (*‹∀a∈T⇩pM. dι¯ a ∈ T⇩pU›*) that (*‹v ∈ T⇩pM›*) by auto have "v = dι ?u" using that (*‹v ∈ T⇩pM›*) tangent_submanifold_isomorphism(1) (*‹bij_betw dι T⇩pU T⇩pM›*) by (auto simp: f_the_inv_into_f (*‹⟦inj_on ?f ?A; ?y ∈ ?f ` ?A⟧ ⟹ ?f (the_inv_into ?A ?f ?y) = ?y›*) bij_betw_imp_inj_on (*‹bij_betw ?f ?A ?B ⟹ inj_on ?f ?A›*) bij_betw_imp_surj_on (*‹bij_betw ?f ?A ?B ⟹ ?f ` ?A = ?B›*)) thus "?thesis" (*goal: ‹component_function v i = dι¯ v (restrict0 (domain ψ) (λx. (apply_chart ψ x - apply_chart ψ p) ∙ i))›*) using "component_function_apply_in_T⇩pU"[OF 1] (*‹component_function (dι (dι¯ (v::('a::{second_countable_topology,t2_space} ⇒ real) ⇒ real))) (?i::'b::euclidean_space) = dι¯ v (restrict0 (domain (ψ::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart)) (λx::'a::{second_countable_topology,t2_space}. (apply_chart ψ x - apply_chart ψ (p::'a::{second_countable_topology,t2_space})) ∙ ?i))›*) by simp qed<close> lemma component_function_apply_in: assumes "v ∈ T⇩pM" "domain ψ = carrier" shows "component_function v i = v (restrict0 carrier (λx. (ψ x - ψ p) ∙ i))" using "component_function_apply_in_T⇩pU" (*‹?v ∈ T⇩pU ⟹ component_function (dι ?v) ?i = ?v (restrict0 (domain ψ) (λx. (apply_chart ψ x - apply_chart ψ p) ∙ ?i))›*) assms (*‹v ∈ T⇩pM› ‹domain ψ = carrier›*) p (*‹p ∈ domain ψ›*) push_forward_id (*‹⟦⋀x. x ∈ carrier ⟹ ?f x = x; ?X ∈ tangent_space ?p; ?p ∈ carrier⟧ ⟹ diff.push_forward k charts charts ?f ?X = ?X›*) by force lemma component_function_apply_out: "component_function v i = 0" if "¬ v ∈ T⇩pM" for v i unfolding component_function_def (*goal: ‹(coord_fun ∘ dκ ∘ dψ ∘ dι¯) v i = 0›*) apply (simp add: restrict0_apply_out[OF that, of "the_inv_into (sub_ψ.sub.tangent_space p) dι"] (*‹dι¯ (v::('a::{second_countable_topology,t2_space} ⇒ real) ⇒ real) = (0::('a::{second_countable_topology,t2_space} ⇒ real) ⇒ real)›*)) (*goal: ‹(coord_fun ∘ dκ ∘ dψ ∘ dι¯) v i = 0›*) apply (simp add: linear_on.linear_0[OF linear_on_dψ] (*‹dψ 0 = 0›*)) (*goal: ‹coord_fun (dκ (dψ 0)) i = 0›*) apply (simp add: linear_on.linear_0[OF sub_eucl.linear_on_push_forward_inclusion[of "ψ p"]] (*‹dκ 0 = 0›*)) (*goal: ‹coord_fun (dκ 0) i = 0›*) by (simp add: coord_fun_def (*‹coord_fun ?X ?i = ?X (λx. (x - apply_chart ψ p) ∙ ?i)›*)) lemma coordinate_vector_inverse: assumes k: "k=∞" shows "v ∈ T⇩pM ⟹ v = coordinate_vector (∑i∈Basis. component_function v i *⇩R i)" and "x = (∑i∈Basis. component_function (coordinate_vector x) i *⇩R i)" proof (-) (*goals: 1. ‹v ∈ T⇩pM ⟹ v = coordinate_vector (∑i∈Basis. component_function v i *⇩R i)› 2. ‹x = (∑i∈Basis. component_function (coordinate_vector x) i *⇩R i)›*) fix v assume "v∈T⇩pM" (*‹(v::('a ⇒ real) ⇒ real) ∈ T⇩pM›*) hence v: "v ∈ T⇩pM" "dι¯ v ∈ T⇩pU" "dψ (dι¯ v) ∈ T⇩ψ⇩pψU" "dκ (dψ (dι¯ v)) ∈ T⇩ψ⇩pE" using "bij_betw_dι_inv" (*‹bij_betw dι¯ T⇩pM T⇩pU›*) "bij_betw_dψ" (*‹bij_betw dψ T⇩pU T⇩ψ⇩pψU›*) "bij_betw_dκ" (*‹bij_betw dκ T⇩ψ⇩pψU T⇩ψ⇩pE›*) apply - (*goals: 1. ‹⟦v ∈ T⇩pM; bij_betw dι¯ T⇩pM T⇩pU; bij_betw dψ T⇩pU T⇩ψ⇩pψU; bij_betw dκ T⇩ψ⇩pψU T⇩ψ⇩pE⟧ ⟹ v ∈ T⇩pM› 2. ‹⟦v ∈ T⇩pM; bij_betw dι¯ T⇩pM T⇩pU; bij_betw dψ T⇩pU T⇩ψ⇩pψU; bij_betw dκ T⇩ψ⇩pψU T⇩ψ⇩pE⟧ ⟹ dι¯ v ∈ T⇩pU› 3. ‹⟦v ∈ T⇩pM; bij_betw dι¯ T⇩pM T⇩pU; bij_betw dψ T⇩pU T⇩ψ⇩pψU; bij_betw dκ T⇩ψ⇩pψU T⇩ψ⇩pE⟧ ⟹ dψ (dι¯ v) ∈ T⇩ψ⇩pψU› 4. ‹⟦v ∈ T⇩pM; bij_betw dι¯ T⇩pM T⇩pU; bij_betw dψ T⇩pU T⇩ψ⇩pψU; bij_betw dκ T⇩ψ⇩pψU T⇩ψ⇩pE⟧ ⟹ dκ (dψ (dι¯ v)) ∈ T⇩ψ⇩pE› discuss goal 1*) apply (simp only: bij_betwE (*‹bij_betw (?f::?'a ⇒ ?'b) (?A::?'a set) (?B::?'b set) ⟹ ∀a::?'a∈?A. ?f a ∈ ?B›*)) (*discuss goal 2*) apply (simp only: bij_betwE (*‹bij_betw ?f ?A ?B ⟹ ∀a∈?A. ?f a ∈ ?B›*)) (*discuss goal 3*) apply (simp only: bij_betwE (*‹bij_betw ?f ?A ?B ⟹ ∀a∈?A. ?f a ∈ ?B›*)) (*discuss goal 4*) apply (simp only: bij_betwE (*‹bij_betw ?f ?A ?B ⟹ ∀a∈?A. ?f a ∈ ?B›*)) (*proven 4 subgoals*) . have "v = dι (dψ¯ (dκ¯ (dκ (dψ (dι¯ v)))))" apply (simp add: the_inv_into_f_f_bij_betw[OF bij_betw_dκ] (*‹(bij_betw dκ T⇩ψ⇩pψU T⇩ψ⇩pE ⟹ ?x ∈ T⇩ψ⇩pψU) ⟹ the_inv_into T⇩ψ⇩pψU dκ (dκ ?x) = ?x›*) v( (*‹dψ (dι¯ v) ∈ T⇩ψ⇩pψU› ‹dκ (dψ (dι¯ v)) ∈ T⇩ψ⇩pE›*) 3,4)) (*goal: ‹v = dι (dψ¯ (dκ¯ (dκ (dψ (dι¯ v)))))›*) apply (simp add: inverse_dψ( (*‹?v ∈ T⇩pU ⟹ dψ¯ (dψ ?v) = ?v›*) 1) v( (*‹dι¯ v ∈ T⇩pU›*) 2)) (*goal: ‹v = dι (dψ¯ (dψ (dι¯ v)))›*) by (simp add: f_the_inv_into_f_bij_betw[OF bij_betw_dι] (*‹(bij_betw dι T⇩pU T⇩pM ⟹ (?x::('a ⇒ real) ⇒ real) ∈ T⇩pM) ⟹ dι (the_inv_into T⇩pU dι ?x) = ?x›*) v( (*‹(v::('a ⇒ real) ⇒ real) ∈ T⇩pM›*) 1)) then show "v = coordinate_vector (∑i∈Basis. component_function v i *⇩R i)" using euclidean_tangent_space_coordinatesE[OF v ( 4 ) k] (*‹dκ (dψ (dι¯ (v::('a ⇒ real) ⇒ real))) = directional_derivative (k::enat) (apply_chart (ψ::('a, 'b) chart) (p::'a)) (∑i::'b∈Basis. coord_fun (dκ (dψ (dι¯ v))) i *⇩R i)›*) by (simp add: coordinate_vector_apply (*‹coordinate_vector ?v ≡ dι (dψ¯ (dκ¯ (directional_derivative k (apply_chart ψ p) ?v)))›*) component_function_def (*‹component_function ≡ coord_fun ∘ dκ ∘ dψ ∘ dι¯›*)) next (*goal: ‹x = (∑i∈Basis. component_function (coordinate_vector x) i *⇩R i)›*) fix x :: 'b define D where "D ≡ directional_derivative k (ψ p)" define D_inv (D¯ [] 1000) where "D¯ ≡ λX. ∑i∈Basis. coord_fun X i *⇩R i" have D_inv: "x = D¯ (D x)" "bij_betw D¯ T⇩ψ⇩pE UNIV" for x using directional_derivative_inverse(2,3)[OF k] (*‹(∑i::'b∈Basis. coord_fun (directional_derivative (k::enat) (apply_chart (ψ::('a, 'b) chart) (p::'a)) (?v::'b)) i *⇩R i) = ?v› ‹bij_betw (λX. ∑i∈Basis. coord_fun X i *⇩R i) T⇩ψ⇩pE UNIV›*) apply - (*goals: 1. ‹⟦⋀v. (∑i∈Basis. coord_fun (directional_derivative k (apply_chart ψ p) v) i *⇩R i) = v; bij_betw (λX. ∑i∈Basis. coord_fun X i *⇩R i) T⇩ψ⇩pE UNIV⟧ ⟹ x = D¯ (D x)› 2. ‹⟦⋀v. (∑i∈Basis. coord_fun (directional_derivative k (apply_chart ψ p) v) i *⇩R i) = v; bij_betw (λX. ∑i∈Basis. coord_fun X i *⇩R i) T⇩ψ⇩pE UNIV⟧ ⟹ bij_betw D¯ T⇩ψ⇩pE UNIV› discuss goal 1*) apply (simp add: D_def (*‹D ≡ directional_derivative k (apply_chart ψ p)›*) D_inv_def (*‹D¯ ≡ λX. ∑i∈Basis. coord_fun X i *⇩R i›*)) (*discuss goal 2*) apply (simp add: D_def (*‹D ≡ directional_derivative k (apply_chart ψ p)›*) D_inv_def (*‹D¯ ≡ λX. ∑i∈Basis. coord_fun X i *⇩R i›*)) (*proven 2 subgoals*) . have x: "D x ∈ T⇩ψ⇩pE" "dκ¯ (D x) ∈ T⇩ψ⇩pψU" "dψ¯ (dκ¯ (D x)) ∈ T⇩pU" "dι (dψ¯ (dκ¯ (D x))) ∈ T⇩pM" using bij_betw_directional_derivative[OF k] (*‹bij_betw (directional_derivative k (apply_chart ψ p)) UNIV T⇩ψ⇩pE›*) "bij_betw_dκ_inv" (*‹bij_betw dκ¯ T⇩ψ⇩pE T⇩ψ⇩pψU›*) "bij_betw_dψ_inv" (*‹bij_betw dψ¯ T⇩ψ⇩pψU T⇩pU›*) "bij_betw_dι" (*‹bij_betw dι T⇩pU T⇩pM›*) apply - (*goals: 1. ‹⟦bij_betw (directional_derivative k (apply_chart ψ p)) UNIV T⇩ψ⇩pE; bij_betw dκ¯ T⇩ψ⇩pE T⇩ψ⇩pψU; bij_betw dψ¯ T⇩ψ⇩pψU T⇩pU; bij_betw dι T⇩pU T⇩pM⟧ ⟹ D x ∈ T⇩ψ⇩pE› 2. ‹⟦bij_betw (directional_derivative k (apply_chart ψ p)) UNIV T⇩ψ⇩pE; bij_betw dκ¯ T⇩ψ⇩pE T⇩ψ⇩pψU; bij_betw dψ¯ T⇩ψ⇩pψU T⇩pU; bij_betw dι T⇩pU T⇩pM⟧ ⟹ dκ¯ (D x) ∈ T⇩ψ⇩pψU› 3. ‹⟦bij_betw (directional_derivative k (apply_chart ψ p)) UNIV T⇩ψ⇩pE; bij_betw dκ¯ T⇩ψ⇩pE T⇩ψ⇩pψU; bij_betw dψ¯ T⇩ψ⇩pψU T⇩pU; bij_betw dι T⇩pU T⇩pM⟧ ⟹ dψ¯ (dκ¯ (D x)) ∈ T⇩pU› 4. ‹⟦bij_betw (directional_derivative k (apply_chart ψ p)) UNIV T⇩ψ⇩pE; bij_betw dκ¯ T⇩ψ⇩pE T⇩ψ⇩pψU; bij_betw dψ¯ T⇩ψ⇩pψU T⇩pU; bij_betw dι T⇩pU T⇩pM⟧ ⟹ dι (dψ¯ (dκ¯ (D x))) ∈ T⇩pM› discuss goal 1*) apply (simp only: bij_betwE (*‹bij_betw ?f ?A ?B ⟹ ∀a∈?A. ?f a ∈ ?B›*) D_def (*‹D ≡ directional_derivative k (apply_chart ψ p)›*) UNIV_I (*‹?x ∈ UNIV›*)) (*discuss goal 2*) apply (simp only: bij_betwE (*‹bij_betw ?f ?A ?B ⟹ ∀a∈?A. ?f a ∈ ?B›*) D_def (*‹D ≡ directional_derivative k (apply_chart ψ p)›*) UNIV_I (*‹?x ∈ UNIV›*)) (*discuss goal 3*) apply (simp only: bij_betwE (*‹bij_betw ?f ?A ?B ⟹ ∀a∈?A. ?f a ∈ ?B›*) D_def (*‹D ≡ directional_derivative k (apply_chart ψ p)›*) UNIV_I (*‹?x ∈ UNIV›*)) (*discuss goal 4*) apply (simp only: bij_betwE (*‹bij_betw ?f ?A ?B ⟹ ∀a∈?A. ?f a ∈ ?B›*) D_def (*‹D ≡ directional_derivative k (apply_chart ψ p)›*) UNIV_I (*‹?x ∈ UNIV›*)) (*proven 4 subgoals*) . have "x = D¯ (dκ (dψ (dι¯ (dι (dψ¯ (dκ¯ (D x)))))))" apply (simp add: the_inv_into_f_f_bij_betw[OF bij_betw_dι] (*‹(bij_betw dι T⇩pU T⇩pM ⟹ ?x ∈ T⇩pU) ⟹ the_inv_into T⇩pU dι (dι ?x) = ?x›*) x( (*‹dψ¯ (dκ¯ (D x)) ∈ T⇩pU› ‹dι (dψ¯ (dκ¯ (D x))) ∈ T⇩pM›*) 3,4)) (*goal: ‹x = D¯ (dκ (dψ (dι¯ (dι (dψ¯ (dκ¯ (D x)))))))›*) apply (simp add: inverse_dψ( (*‹?u ∈ T⇩ψ⇩pψU ⟹ dψ (dψ¯ ?u) = ?u›*) 2) x( (*‹dκ¯ (D x) ∈ T⇩ψ⇩pψU›*) 2)) (*goal: ‹x = D¯ (dκ (dψ (dψ¯ (dκ¯ (D x)))))›*) by (simp add: f_the_inv_into_f_bij_betw[OF bij_betw_dκ] (*‹(bij_betw dκ T⇩ψ⇩pψU T⇩ψ⇩pE ⟹ ?x ∈ T⇩ψ⇩pE) ⟹ dκ (the_inv_into T⇩ψ⇩pψU dκ ?x) = ?x›*) x( (*‹D x ∈ T⇩ψ⇩pE›*) 1) D_inv( (*‹?x4 = D¯ (D ?x4)›*) 1)) then show "x = (∑i∈Basis. component_function (coordinate_vector x) i *⇩R i)" by (simp add: coordinate_vector_apply[folded D_def] (*‹coordinate_vector ?v ≡ dι (dψ¯ (dκ¯ (D ?v)))›*) component_function_def (*‹component_function ≡ coord_fun ∘ dκ ∘ dψ ∘ dι¯›*) D_inv_def (*‹D¯ ≡ λX. ∑i∈Basis. coord_fun X i *⇩R i›*)) qed<close> lemma tangent_chart_fun_inverse: assumes k: "k=∞" shows "v ∈ T⇩pM ⟹ v = coordinate_vector (tangent_chart_fun v)" and "x = tangent_chart_fun (coordinate_vector x)" unfolding tangent_chart_fun_def (*goals: 1. ‹(v::('a ⇒ real) ⇒ real) ∈ T⇩pM ⟹ v = coordinate_vector (∑i::'b∈Basis. component_function v i *⇩R i)› 2. ‹(x::'b) = (∑i::'b∈Basis. component_function (coordinate_vector x) i *⇩R i)›*) using coordinate_vector_inverse[OF assms] (*‹(?v::('a::{second_countable_topology,t2_space} ⇒ real) ⇒ real) ∈ T⇩pM ⟹ ?v = coordinate_vector (∑i::'b::euclidean_space∈Basis. component_function ?v i *⇩R i)› ‹?x = (∑i∈Basis. component_function (coordinate_vector ?x) i *⇩R i)›*) apply - (*goals: 1. ‹⟦v ∈ T⇩pM; ⋀v. v ∈ T⇩pM ⟹ v = coordinate_vector (∑i∈Basis. component_function v i *⇩R i); ⋀x. x = (∑i∈Basis. component_function (coordinate_vector x) i *⇩R i)⟧ ⟹ v = coordinate_vector (∑i∈Basis. component_function v i *⇩R i)› 2. ‹⟦⋀v. v ∈ T⇩pM ⟹ v = coordinate_vector (∑i∈Basis. component_function v i *⇩R i); ⋀x. x = (∑i∈Basis. component_function (coordinate_vector x) i *⇩R i)⟧ ⟹ x = (∑i∈Basis. component_function (coordinate_vector x) i *⇩R i)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma tangent_chart_fun_bij: "bij_betw tangent_chart_fun T⇩pM UNIV" if "k=∞" using coordinate_vector_bij[OF that] (*‹bij_betw coordinate_vector UNIV T⇩pM›*) coordinate_vector_inverse[OF that] (*‹?v ∈ T⇩pM ⟹ ?v = coordinate_vector (∑i∈Basis. component_function ?v i *⇩R i)› ‹?x = (∑i∈Basis. component_function (coordinate_vector ?x) i *⇩R i)›*) by (auto intro: inverse_bij_betw (*‹⟦bij_betw ?f ?A ?B; ∀x∈?A. ?g (?f x) = x; ∀y∈?B. ?f (?g y) = y⟧ ⟹ bij_betw ?g ?B ?A›*) simp: tangent_chart_fun_def (*‹tangent_chart_fun ?v ≡ ∑i∈Basis. component_function ?v i *⇩R i›*)) lemma tangent_chart_fun_linear_on: "linear_on T⇩pM UNIV scaleR scaleR tangent_chart_fun" if "k=∞" apply (rule linear_on_inv (*‹⟦linear_on ?A ?B ?scaleA ?scaleB ?a; bij_betw ?a ?A ?B; ∀x∈?A. ?a x ∈ ?B ∧ ?b (?a x) = x; ∀y∈?B. ?b y ∈ ?A ∧ ?a (?b y) = y⟧ ⟹ linear_on ?B ?A ?scaleB ?scaleA ?b›*)) (*goal: ‹linear_on T⇩pM UNIV (*⇩R) (*⇩R) tangent_chart_fun›*) using coordinate_vector_bij[OF that] (*‹bij_betw coordinate_vector UNIV T⇩pM›*) coordinate_vector_inverse[OF that] (*‹?v ∈ T⇩pM ⟹ ?v = coordinate_vector (∑i∈Basis. component_function ?v i *⇩R i)› ‹?x = (∑i∈Basis. component_function (coordinate_vector ?x) i *⇩R i)›*) coordinate_vector_linear_on[OF that] (*‹linear_on UNIV T⇩pM (*⇩R) (*⇩R) coordinate_vector›*) by (auto simp: bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*) tangent_chart_fun_def (*‹tangent_chart_fun ?v ≡ ∑i∈Basis. component_function ?v i *⇩R i›*)) lemma coordinate_vector_representation: assumes v: "v ∈ T⇩pM" and k: "k=∞" shows "v = (∑i∈Basis. (component_function v i) *⇩R (coordinate_vector i))" (is ‹v = (∑b∈Basis. (?f⇩v b) *⇩R (?c b))›) proof (-) (*goal: ‹(v::('a ⇒ real) ⇒ real) = (∑i::'b∈Basis. component_function v i *⇩R coordinate_vector i)›*) have v: "v ∈ T⇩pM" "dι¯ v ∈ T⇩pU" "dψ (dι¯ v) ∈ T⇩ψ⇩pψU" "dκ (dψ (dι¯ v)) ∈ T⇩ψ⇩pE" using "bij_betw_dι_inv" (*‹bij_betw dι¯ T⇩pM T⇩pU›*) "bij_betw_dψ" (*‹bij_betw dψ T⇩pU T⇩ψ⇩pψU›*) "bij_betw_dκ" (*‹bij_betw dκ T⇩ψ⇩pψU T⇩ψ⇩pE›*) v (*‹v ∈ T⇩pM›*) apply - (*goals: 1. ‹⟦bij_betw dι¯ T⇩pM T⇩pU; bij_betw dψ T⇩pU T⇩ψ⇩pψU; bij_betw dκ T⇩ψ⇩pψU T⇩ψ⇩pE; v ∈ T⇩pM⟧ ⟹ v ∈ T⇩pM› 2. ‹⟦bij_betw dι¯ T⇩pM T⇩pU; bij_betw dψ T⇩pU T⇩ψ⇩pψU; bij_betw dκ T⇩ψ⇩pψU T⇩ψ⇩pE; v ∈ T⇩pM⟧ ⟹ dι¯ v ∈ T⇩pU› 3. ‹⟦bij_betw dι¯ T⇩pM T⇩pU; bij_betw dψ T⇩pU T⇩ψ⇩pψU; bij_betw dκ T⇩ψ⇩pψU T⇩ψ⇩pE; v ∈ T⇩pM⟧ ⟹ dψ (dι¯ v) ∈ T⇩ψ⇩pψU› 4. ‹⟦bij_betw dι¯ T⇩pM T⇩pU; bij_betw dψ T⇩pU T⇩ψ⇩pψU; bij_betw dκ T⇩ψ⇩pψU T⇩ψ⇩pE; v ∈ T⇩pM⟧ ⟹ dκ (dψ (dι¯ v)) ∈ T⇩ψ⇩pE› discuss goal 1*) apply (simp only: bij_betwE (*‹bij_betw (?f::?'a ⇒ ?'b) (?A::?'a set) (?B::?'b set) ⟹ ∀a::?'a∈?A. ?f a ∈ ?B›*)) (*discuss goal 2*) apply (simp only: bij_betwE (*‹bij_betw ?f ?A ?B ⟹ ∀a∈?A. ?f a ∈ ?B›*)) (*discuss goal 3*) apply (simp only: bij_betwE (*‹bij_betw ?f ?A ?B ⟹ ∀a∈?A. ?f a ∈ ?B›*)) (*discuss goal 4*) apply (simp only: bij_betwE (*‹bij_betw (?f::?'a::type ⇒ ?'b::type) (?A::?'a::type set) (?B::?'b::type set) ⟹ ∀a::?'a::type∈?A. ?f a ∈ ?B›*)) (*proven 4 subgoals*) . have "v = ?c (∑i∈Basis. ?f⇩v i *⇩R i)" using coordinate_vector_inverse(1)[OF k v ( 1 )] (*‹(v::('a ⇒ real) ⇒ real) = coordinate_vector (∑i::'b∈Basis. component_function v i *⇩R i)›*) . also (*calculation: ‹v = coordinate_vector (∑i∈Basis. component_function v i *⇩R i)›*) have "… = (∑b∈Basis. ?c ((?f⇩v b) *⇩R b))" apply (rule linear_sum (*‹linear (?f::?'a::real_vector ⇒ ?'b::real_vector) ⟹ ?f (sum (?g::?'d::type ⇒ ?'a::real_vector) (?S::?'d::type set)) = (∑a::?'d::type∈?S. ?f (?g a))›*)) (*goal: ‹coordinate_vector (∑i∈Basis. component_function v i *⇩R i) = (∑b∈Basis. coordinate_vector (component_function v b *⇩R b))›*) by (fact coordinate_vector_linear[OF k] (*‹linear coordinate_vector›*)) also (*calculation: ‹(v::('a ⇒ real) ⇒ real) = (∑b::'b∈Basis. coordinate_vector (component_function v b *⇩R b))›*) have "… = (∑b∈Basis. (?f⇩v b) *⇩R (?c b))" using linear_cmul (*‹linear ?f ⟹ ?f (?r *⇩R ?b) = ?r *⇩R ?f ?b›*) coordinate_vector_linear (*‹k = ∞ ⟹ linear coordinate_vector›*) k (*‹k = ∞›*) by (auto intro: sum.cong (*‹⟦?A = ?B; ⋀x. x ∈ ?B ⟹ ?g x = ?h x⟧ ⟹ sum ?g ?A = sum ?h ?B›*)) finally (*calculation: ‹(v::('a ⇒ real) ⇒ real) = (∑b::'b∈Basis. component_function v b *⇩R coordinate_vector b)›*) show "v = (∑b∈Basis. (?f⇩v b) *⇩R (?c b))" . qed lemma coordinate_vector_representation_apply_in: assumes v: "v ∈ T⇩pM" and k: "k=∞" and f: "f ∈ diff_fun_space" shows "v f = (∑i∈Basis. (component_function v i) *⇩R (coordinate_vector i f))" using coordinate_vector_representation[OF assms ( 1 , 2 )] (*‹v = (∑i∈Basis. component_function v i *⇩R coordinate_vector i)›*) apply (auto simp: scaleR_fun_def (*‹?r *⇩R ?f = (λx. ?r *⇩R ?f x)›*) sum_fun_def (*‹sum ?f ?I = (λx. ∑i∈?I. ?f i x)›*)) (*goal: ‹(v::('a::{second_countable_topology,t2_space} ⇒ real) ⇒ real) (f::'a::{second_countable_topology,t2_space} ⇒ real) = (∑i::'b::euclidean_space∈Basis. component_function v i *⇩R coordinate_vector i f)›*) by metis<close> lemma (in c_manifold) derivation_eq_localI': "X f = X g" if "k=∞" "p ∈ U" "U ⊆ domain c" "c ∈ atlas" "X ∈ tangent_space p" "f ∈ diff_fun_space" "g ∈ diff_fun_space" "⋀x. x ∈ U ⟹ frechet_derivative (f ∘ inv_chart c) (at (c x)) = frechet_derivative (g ∘ inv_chart c) (at (c x))" proof (-) (*goal: ‹(X::('a ⇒ real) ⇒ real) (f::'a ⇒ real) = X (g::'a ⇒ real)›*) interpret p: c_manifold_point charts k c p using that(2-4) (*‹p ∈ U› ‹(U::'a::{second_countable_topology,t2_space} set) ⊆ domain (c::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart)› ‹c ∈ atlas›*) apply unfold_locales (*goals: 1. ‹⟦p ∈ U; U ⊆ domain c; c ∈ atlas⟧ ⟹ c ∈ atlas› 2. ‹⟦p ∈ U; U ⊆ domain c; c ∈ atlas⟧ ⟹ p ∈ domain c› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . show "?thesis" (*goal: ‹X f = X g›*) apply (simp only: p.coordinate_vector_representation_apply_in[OF that(5,1)] (*‹?f ∈ diff_fun_space ⟹ X ?f = (∑i∈Basis. p.component_function X i *⇩R p.coordinate_vector i ?f)›*) p.coordinate_vector_apply_in[OF that(1)] (*‹?f ∈ diff_fun_space ⟹ p.coordinate_vector ?b ?f = frechet_derivative (?f ∘ inv_chart c) (at (apply_chart c p)) ?b›*) that( (*‹f ∈ diff_fun_space› ‹g ∈ diff_fun_space›*) 6,7)) (*goal: ‹X f = X g›*) using that(2,8) (*‹p ∈ U› ‹?x3 ∈ U ⟹ frechet_derivative (f ∘ inv_chart c) (at (apply_chart c ?x3)) = frechet_derivative (g ∘ inv_chart c) (at (apply_chart c ?x3))›*) by presburger qed lemma coordinate_vector_restrict_chart: assumes "p ∈ S" "open S" and k: "k=∞" shows "coordinate_vector i = (c_manifold_point.coordinate_vector charts ∞ (restrict_chart S ψ) p) i" (is ‹_ = ?coordinate_restrict i›) proof (standard) (*goal: ‹⋀x. coordinate_vector i x = c_manifold_point.coordinate_vector charts ∞ (restrict_chart S ψ) p i x›*) fix f :: "'a ⇒ real" interpret S: c_manifold_point charts "∞" "restrict_chart S ψ" p using "ψ" (*‹ψ ∈ atlas›*) assms (*‹p ∈ S› ‹open (S::'a set)› ‹k = ∞›*) c_manifold_point (*‹⟦(?c::('a, 'b) chart) ∈ atlas; (?p::'a) ∈ domain ?c⟧ ⟹ c_manifold_point (charts::('a, 'b) chart set) (k::enat) ?c ?p›*) restrict_chart_in_atlas (*‹?c ∈ atlas ⟹ restrict_chart ?S ?c ∈ atlas›*) by auto have 1: "coordinate_vector i ∈ T⇩pM" using bij_betwE (*‹bij_betw ?f ?A ?B ⟹ ∀a∈?A. ?f a ∈ ?B›*) coordinate_vector_bij (*‹(k::enat) = ∞ ⟹ bij_betw coordinate_vector UNIV T⇩pM›*) k (*‹(k::enat) = ∞›*) by blast have 2: "?coordinate_restrict i ∈ T⇩pM" using bij_betwE (*‹bij_betw ?f ?A ?B ⟹ ∀a∈?A. ?f a ∈ ?B›*) S.coordinate_vector_bij (*‹∞ = ∞ ⟹ bij_betw S.coordinate_vector UNIV S.T⇩pM›*) k (*‹(k::enat) = ∞›*) by blast show "coordinate_vector i f = ?coordinate_restrict i f" proof (cases "f ∈ diff_fun_space") (*goals: 1. ‹f ∈ diff_fun_space ⟹ coordinate_vector i f = S.coordinate_vector i f› 2. ‹f ∉ diff_fun_space ⟹ coordinate_vector i f = S.coordinate_vector i f›*) case True (*‹f ∈ diff_fun_space›*) thus "?thesis" (*goal: ‹coordinate_vector (i::'b) (f::'a ⇒ real) = S.coordinate_vector i f›*) using coordinate_vector_apply_in[OF k] (*‹(?f::'a::{second_countable_topology,t2_space} ⇒ real) ∈ diff_fun_space ⟹ coordinate_vector (?b::'b::euclidean_space) ?f = frechet_derivative (?f ∘ inv_chart (ψ::('a::{second_countable_topology,t2_space}, 'b::euclidean_space) chart)) (at (apply_chart ψ (p::'a::{second_countable_topology,t2_space}))) ?b›*) by (simp add: S.coordinate_vector_apply_in (*‹⟦∞ = ∞; ?f ∈ S.diff_fun_space⟧ ⟹ S.coordinate_vector ?b ?f = frechet_derivative (?f ∘ inv_chart (restrict_chart S ψ)) (at (apply_chart (restrict_chart S ψ) p)) ?b›*) k (*‹k = ∞›*)) next (*goal: ‹f ∉ diff_fun_space ⟹ coordinate_vector i f = S.coordinate_vector i f›*) case False (*‹f ∉ diff_fun_space›*) thus "?thesis" (*goal: ‹coordinate_vector i f = S.coordinate_vector i f›*) using coordinate_vector_apply_out (*‹⟦k = ∞; ?f ∉ diff_fun_space⟧ ⟹ coordinate_vector ?b ?f = 0›*) by (simp add: S.coordinate_vector_apply_out (*‹⟦∞ = ∞; (?f::'a::{second_countable_topology,t2_space} ⇒ real) ∉ S.diff_fun_space⟧ ⟹ S.coordinate_vector (?b::'b::euclidean_space) ?f = (0::real)›*) k (*‹(k::enat) = ∞›*)) qed qed lemma inj_coordinate_vector: assumes k: "k=∞" shows "inj_on coordinate_vector S" using bij_betw_imp_inj_on[OF coordinate_vector_bij [ OF k ]] (*‹inj coordinate_vector›*) by (simp add: inj_def (*‹inj ?f = (∀x y. ?f x = ?f y ⟶ x = y)›*) inj_onI (*‹(⋀x y. ⟦x ∈ ?A; y ∈ ?A; ?f x = ?f y⟧ ⟹ x = y) ⟹ inj_on ?f ?A›*)) lemma (in finite_dimensional_vector_space_on) mem_scaled_basis_sum: shows "(∑i∈basis. scale (f i) i) ∈ S" using finite_Basis (*‹finite basis›*) span_Basis (*‹local.span basis = S›*) span_on_def (*‹local.span ?b = {∑a∈t. scale (r a) a |t r. finite t ∧ t ⊆ ?b}›*) by auto<close> lemma euclidean_coordinates_eq_iff: assumes k: "k=∞" shows "((∑i∈Basis. f i *⇩R coordinate_vector i) = (∑i∈Basis. g i *⇩R coordinate_vector i)) ⟷ (∀i∈Basis. f i = g i)" proof (-) (*goal: ‹((∑i∈Basis. f i *⇩R coordinate_vector i) = (∑i∈Basis. g i *⇩R coordinate_vector i)) = (∀i∈Basis. f i = g i)›*) let ?B = "coordinate_vector ` Basis" interpret coordinate_basis: finite_dimensional_real_vector_space_on "T⇩pM" "?B" using coordinate_basis[OF k] (*‹finite_dimensional_real_vector_space_on T⇩pM (coordinate_vector ` Basis)›*) . have "((∑i∈Basis. f i *⇩R coordinate_vector i) = (∑i∈Basis. g i *⇩R coordinate_vector i)) ⟷ (∑i∈Basis. f i *⇩R i) = (∑i∈Basis. g i *⇩R i)" (is "?LHS1 = ?LHS2 ⟷ ?RHS") proof (-) (*goal: ‹((∑i∈Basis. f i *⇩R coordinate_vector i) = (∑i∈Basis. g i *⇩R coordinate_vector i)) = ((∑i∈Basis. f i *⇩R i) = (∑i∈Basis. g i *⇩R i))›*) have tan_eq_simp: "l = r ⟷ tangent_chart_fun l = tangent_chart_fun r" if "l∈T⇩pM" "r∈T⇩pM" for l and r using tangent_chart_fun_bij[OF k] (*‹bij_betw tangent_chart_fun T⇩pM UNIV›*) that (*‹l ∈ T⇩pM› ‹r ∈ T⇩pM›*) by (auto simp: bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*) inj_onD (*‹⟦inj_on ?f ?A; ?f ?x = ?f ?y; ?x ∈ ?A; ?y ∈ ?A⟧ ⟹ ?x = ?y›*)) have tan_sum_simp: "tangent_chart_fun (∑i∈Basis. f i *⇩R coordinate_vector i) = (∑i∈Basis. f i *⇩R i)" for f :: "'b ⇒ real" proof (-) (*goal: ‹tangent_chart_fun (∑i∈Basis. f i *⇩R coordinate_vector i) = (∑i∈Basis. f i *⇩R i)›*) have "tangent_chart_fun (∑i∈Basis. f i *⇩R coordinate_vector i) = sum (tangent_chart_fun ∘ (λi. f i *⇩R coordinate_vector i)) Basis" apply (rule linear_on.linear_sum[symmetric] (*‹⟦linear_on ?S1.0 ?S2.0 ?s1.0 ?s2.0 ?f; ?g ` ?A ⊆ ?S1.0; ?f ` ?S1.0 ⊆ ?S2.0⟧ ⟹ ?f (sum ?g ?A) = sum (?f ∘ ?g) ?A›*)) (*goal: ‹tangent_chart_fun (∑i∈Basis. f i *⇩R coordinate_vector i) = sum (tangent_chart_fun ∘ (λi. f i *⇩R coordinate_vector i)) Basis›*) apply (rule tangent_chart_fun_linear_on[OF k] (*‹linear_on T⇩pM UNIV (*⇩R) (*⇩R) tangent_chart_fun›*)) (*top goal: ‹linear_on (?S1.0::(('a ⇒ real) ⇒ real) set) (?S2.0::'b set) (?s1.0::?'a ⇒ (('a ⇒ real) ⇒ real) ⇒ ('a ⇒ real) ⇒ real) (?s2.0::?'a ⇒ 'b ⇒ 'b) tangent_chart_fun› and 2 goals remain*) using coordinate_vector_surj (*‹k = ∞ ⟹ range coordinate_vector = T⇩pM›*) k (*‹k = ∞›*) tangent_space.mem_scale (*‹?x ∈ tangent_space ?p ⟹ ?a *⇩R ?x ∈ tangent_space ?p›*) (*goals: 1. ‹(λa. f a *⇩R coordinate_vector a) ` Basis ⊆ T⇩pM› 2. ‹tangent_chart_fun ` T⇩pM ⊆ UNIV› discuss goal 1*) apply blast (*discuss goal 2*) apply simp (*proven 2 subgoals*) . also (*calculation: ‹tangent_chart_fun (∑i∈Basis. f i *⇩R coordinate_vector i) = sum (tangent_chart_fun ∘ (λi. f i *⇩R coordinate_vector i)) Basis›*) have "… = (∑i∈Basis. f i *⇩R tangent_chart_fun (coordinate_vector i))" proof (-) (*goal: ‹sum (tangent_chart_fun ∘ (λi. f i *⇩R coordinate_vector i)) Basis = (∑i∈Basis. f i *⇩R tangent_chart_fun (coordinate_vector i))›*) have "tangent_chart_fun (f i *⇩R coordinate_vector i) = f i *⇩R tangent_chart_fun (coordinate_vector i)" if "i∈Basis" for i :: 'b apply (rule vector_space_pair_on.linear_scale[OF _ _ _ tangent_chart_fun_linear_on[OF k]] (*‹⟦vector_space_pair_on T⇩pM UNIV (*⇩R) (*⇩R); ∀x. x ∈ T⇩pM ⟶ tangent_chart_fun x ∈ UNIV; ?b ∈ T⇩pM⟧ ⟹ tangent_chart_fun (?r *⇩R ?b) = ?r *⇩R tangent_chart_fun ?b›*)) (*goals: 1. ‹vector_space_pair_on T⇩pM UNIV (*⇩R) (*⇩R)› 2. ‹∀x. x ∈ T⇩pM ⟶ tangent_chart_fun x ∈ UNIV› 3. ‹coordinate_vector i ∈ T⇩pM› discuss goal 1*) apply unfold_locales (*goals: 1. ‹⋀x y a. ⟦x ∈ UNIV; y ∈ UNIV⟧ ⟹ a *⇩R (x + y) = a *⇩R x + a *⇩R y› 2. ‹⋀x a b. x ∈ UNIV ⟹ (a + b) *⇩R x = a *⇩R x + b *⇩R x› 3. ‹⋀x a b. x ∈ UNIV ⟹ a *⇩R b *⇩R x = (a * b) *⇩R x› 4. ‹⋀x. x ∈ UNIV ⟹ 1 *⇩R x = x› 5. ‹⋀x y. ⟦x ∈ UNIV; y ∈ UNIV⟧ ⟹ x + y ∈ UNIV› 6. ‹0 ∈ UNIV› 7. ‹⋀x a. x ∈ UNIV ⟹ a *⇩R x ∈ UNIV› discuss goal 1*) apply (simp add: scaleR_right_distrib (*‹?a *⇩R (?x + ?y) = ?a *⇩R ?x + ?a *⇩R ?y›*) scaleR_left_distrib (*‹(?a + ?b) *⇩R ?x = ?a *⇩R ?x + ?b *⇩R ?x›*) bij_betwE[OF coordinate_vector_bij[OF k]] (*‹∀a∈UNIV. coordinate_vector a ∈ T⇩pM›*)) (*discuss goal 2*) apply (simp add: scaleR_right_distrib (*‹?a *⇩R (?x + ?y) = ?a *⇩R ?x + ?a *⇩R ?y›*) scaleR_left_distrib (*‹(?a + ?b) *⇩R ?x = ?a *⇩R ?x + ?b *⇩R ?x›*) bij_betwE[OF coordinate_vector_bij[OF k]] (*‹∀a∈UNIV. coordinate_vector a ∈ T⇩pM›*)) (*discuss goal 3*) apply (simp add: scaleR_right_distrib (*‹?a *⇩R (?x + ?y) = ?a *⇩R ?x + ?a *⇩R ?y›*) scaleR_left_distrib (*‹(?a + ?b) *⇩R ?x = ?a *⇩R ?x + ?b *⇩R ?x›*) bij_betwE[OF coordinate_vector_bij[OF k]] (*‹∀a∈UNIV. coordinate_vector a ∈ T⇩pM›*)) (*discuss goal 4*) apply (simp add: scaleR_right_distrib (*‹(?a::real) *⇩R ((?x::?'a) + (?y::?'a)) = ?a *⇩R ?x + ?a *⇩R ?y›*) scaleR_left_distrib (*‹((?a::real) + (?b::real)) *⇩R (?x::?'a) = ?a *⇩R ?x + ?b *⇩R ?x›*) bij_betwE[OF coordinate_vector_bij[OF k]] (*‹∀a::'b∈UNIV. coordinate_vector a ∈ T⇩pM›*)) (*discuss goal 5*) apply (simp add: scaleR_right_distrib (*‹?a *⇩R (?x + ?y) = ?a *⇩R ?x + ?a *⇩R ?y›*) scaleR_left_distrib (*‹(?a + ?b) *⇩R ?x = ?a *⇩R ?x + ?b *⇩R ?x›*) bij_betwE[OF coordinate_vector_bij[OF k]] (*‹∀a∈UNIV. coordinate_vector a ∈ T⇩pM›*)) (*discuss goal 6*) apply (simp add: scaleR_right_distrib (*‹(?a::real) *⇩R ((?x::?'a) + (?y::?'a)) = ?a *⇩R ?x + ?a *⇩R ?y›*) scaleR_left_distrib (*‹((?a::real) + (?b::real)) *⇩R (?x::?'a) = ?a *⇩R ?x + ?b *⇩R ?x›*) bij_betwE[OF coordinate_vector_bij[OF k]] (*‹∀a::'b∈UNIV. coordinate_vector a ∈ T⇩pM›*)) (*discuss goal 7*) apply (simp add: scaleR_right_distrib (*‹?a *⇩R (?x + ?y) = ?a *⇩R ?x + ?a *⇩R ?y›*) scaleR_left_distrib (*‹(?a + ?b) *⇩R ?x = ?a *⇩R ?x + ?b *⇩R ?x›*) bij_betwE[OF coordinate_vector_bij[OF k]] (*‹∀a∈UNIV. coordinate_vector a ∈ T⇩pM›*)) (*proven 7 subgoals*) (*discuss goal 2*) apply (simp add: scaleR_right_distrib (*‹?a *⇩R (?x + ?y) = ?a *⇩R ?x + ?a *⇩R ?y›*) scaleR_left_distrib (*‹(?a + ?b) *⇩R ?x = ?a *⇩R ?x + ?b *⇩R ?x›*) bij_betwE[OF coordinate_vector_bij[OF k]] (*‹∀a∈UNIV. coordinate_vector a ∈ T⇩pM›*)) (*discuss goal 3*) apply (simp add: scaleR_right_distrib (*‹?a *⇩R (?x + ?y) = ?a *⇩R ?x + ?a *⇩R ?y›*) scaleR_left_distrib (*‹(?a + ?b) *⇩R ?x = ?a *⇩R ?x + ?b *⇩R ?x›*) bij_betwE[OF coordinate_vector_bij[OF k]] (*‹∀a∈UNIV. coordinate_vector a ∈ T⇩pM›*)) (*proven 3 subgoals*) . thus "?thesis" (*goal: ‹sum (tangent_chart_fun ∘ (λi. f i *⇩R coordinate_vector i)) Basis = (∑i∈Basis. f i *⇩R tangent_chart_fun (coordinate_vector i))›*) by simp qed finally (*calculation: ‹tangent_chart_fun (∑i∈Basis. f i *⇩R coordinate_vector i) = (∑i∈Basis. f i *⇩R tangent_chart_fun (coordinate_vector i))›*) show "?thesis" (*goal: ‹tangent_chart_fun (∑i∈Basis. f i *⇩R coordinate_vector i) = (∑i∈Basis. f i *⇩R i)›*) using coordinate_vector_inverse(2)[OF k] (*‹?x = (∑i∈Basis. component_function (coordinate_vector ?x) i *⇩R i)›*) by (simp add: tangent_chart_fun_def (*‹tangent_chart_fun (?v::('a ⇒ real) ⇒ real) ≡ ∑i::'b∈Basis. component_function ?v i *⇩R i›*)) qed have "?LHS1 = ?LHS2 ⟷ tangent_chart_fun ?LHS1 = tangent_chart_fun ?LHS2" proof (-) (*goal: ‹((∑i∈Basis. f i *⇩R coordinate_vector i) = (∑i∈Basis. g i *⇩R coordinate_vector i)) = (tangent_chart_fun (∑i∈Basis. f i *⇩R coordinate_vector i) = tangent_chart_fun (∑i∈Basis. g i *⇩R coordinate_vector i))›*) have "f i *⇩R coordinate_vector i ∈ T⇩pM" if "i∈Basis" for i and f using coordinate_basis.basis_subset (*‹coordinate_vector ` Basis ⊆ T⇩pM›*) that (*‹(i::'b) ∈ Basis›*) by (auto simp add: tangent_space.mem_scale (*‹?x ∈ tangent_space ?p ⟹ ?a *⇩R ?x ∈ tangent_space ?p›*)) hence 1: "(∑i∈Basis. f i *⇩R coordinate_vector i) ∈ T⇩pM" for f by (metis (no_types, lifting) coordinate_basis.finite_dimensional_basis( (*‹span (coordinate_vector ` Basis) = T⇩pM›*) 3) span_sum (*‹(⋀x. x ∈ ?A ⟹ ?f x ∈ span ?S) ⟹ sum ?f ?A ∈ span ?S›*)) then show "?thesis" (*goal: ‹((∑i∈Basis. f i *⇩R coordinate_vector i) = (∑i∈Basis. g i *⇩R coordinate_vector i)) = (tangent_chart_fun (∑i∈Basis. f i *⇩R coordinate_vector i) = tangent_chart_fun (∑i∈Basis. g i *⇩R coordinate_vector i))›*) by (auto intro!: tan_eq_simp (*‹⟦(?l4::('a ⇒ real) ⇒ real) ∈ T⇩pM; (?r4::('a ⇒ real) ⇒ real) ∈ T⇩pM⟧ ⟹ (?l4 = ?r4) = (tangent_chart_fun ?l4 = tangent_chart_fun ?r4)›*)) qed then show "?thesis" (*goal: ‹((∑i::'b∈Basis. (f::'b ⇒ real) i *⇩R coordinate_vector i) = (∑i::'b∈Basis. (g::'b ⇒ real) i *⇩R coordinate_vector i)) = ((∑i::'b∈Basis. f i *⇩R i) = (∑i::'b∈Basis. g i *⇩R i))›*) using tan_sum_simp (*‹tangent_chart_fun (∑i∈Basis. ?f4 i *⇩R coordinate_vector i) = (∑i∈Basis. ?f4 i *⇩R i)›*) by presburger qed thus "?thesis" (*goal: ‹((∑i∈Basis. f i *⇩R coordinate_vector i) = (∑i∈Basis. g i *⇩R coordinate_vector i)) = (∀i∈Basis. f i = g i)›*) using euclidean_components_eq_iff (*‹((∑i∈Basis. ?f i *⇩R i) = (∑i∈Basis. ?g i *⇩R i)) = (∀i∈Basis. ?f i = ?g i)›*) by auto qed<close> lemma coordinate_sum_eq_imp_components_eq': assumes "∀v. f v ≠ 0 ⟶ v ∈ Basis" "∀v. g v ≠ 0 ⟶ v ∈ Basis" and k: "k=∞" and "(∑i∈{v. f v ≠ 0}. (f i) *⇩R coordinate_vector i) = (∑i∈{v. g v ≠ 0}. (g i) *⇩R coordinate_vector i)" shows "∀i. f i = g i" proof (-) (*goal: ‹∀i. f i = g i›*) text ‹This proof is mostly about massaging ‹∑› expressions. We know coordinate vectors form a basis, and we know a basis is linearly independent. The rest is about getting from an expression entirely in the vector space of @{thm coordinate_basis} to an expression that uses linear independence in the tangent space, while talking about the \<^term>‹Basis› of the corresponding \<^typ>‹'b::euclidean_space›.› let ?B = "coordinate_vector ` Basis" interpret VS: finite_dimensional_real_vector_space_on "T⇩pM" "?B" using coordinate_basis[OF k] (*‹finite_dimensional_real_vector_space_on T⇩pM (coordinate_vector ` Basis)›*) . have 1: "v ∈ ?B" if "v ∈ T⇩pM" "f (tangent_chart_fun v) ≠ 0 ∨ g (tangent_chart_fun v) ≠ 0" for v using that(2) (*‹(f::'b ⇒ real) (tangent_chart_fun (v::('a ⇒ real) ⇒ real)) ≠ (0::real) ∨ (g::'b ⇒ real) (tangent_chart_fun v) ≠ (0::real)›*) unfolding tangent_chart_fun_def (*goal: ‹(v::('a::{second_countable_topology,t2_space} ⇒ real) ⇒ real) ∈ coordinate_vector ` Basis›*) using VS.basis_subset (*‹coordinate_vector ` Basis ⊆ T⇩pM›*) coordinate_vector_inverse(1)[OF k that ( 1 )] (*‹v = coordinate_vector (∑i∈Basis. component_function v i *⇩R i)›*) assms(1,2) (*‹∀v. f v ≠ 0 ⟶ v ∈ Basis› ‹∀v. g v ≠ 0 ⟶ v ∈ Basis›*) by auto have f_eq_g: "∀x∈T⇩pM. f (tangent_chart_fun x) = g (tangent_chart_fun x)" proof (rule VS.unique_representation_basis (*‹⟦⋀v::('a ⇒ real) ⇒ real. ⟦v ∈ T⇩pM; (?f::(('a ⇒ real) ⇒ real) ⇒ real) v ≠ (0::real)⟧ ⟹ v ∈ coordinate_vector ` Basis; ⋀v::('a ⇒ real) ⇒ real. ⟦v ∈ T⇩pM; (?g::(('a ⇒ real) ⇒ real) ⇒ real) v ≠ (0::real)⟧ ⟹ v ∈ coordinate_vector ` Basis; (∑v::('a ⇒ real) ⇒ real∈{x::('a ⇒ real) ⇒ real ∈ T⇩pM. ?f x ≠ (0::real)}. ?f v *⇩R v) = (∑v::('a ⇒ real) ⇒ real∈{x::('a ⇒ real) ⇒ real ∈ T⇩pM. ?g x ≠ (0::real)}. ?g v *⇩R v)⟧ ⟹ ∀x::('a ⇒ real) ⇒ real∈T⇩pM. ?f x = ?g x›*)) (*goals: 1. ‹⋀v. ⟦v ∈ T⇩pM; f (tangent_chart_fun v) ≠ 0⟧ ⟹ v ∈ coordinate_vector ` Basis› 2. ‹⋀v. ⟦v ∈ T⇩pM; g (tangent_chart_fun v) ≠ 0⟧ ⟹ v ∈ coordinate_vector ` Basis› 3. ‹(∑v∈{x ∈ T⇩pM. f (tangent_chart_fun x) ≠ 0}. f (tangent_chart_fun v) *⇩R v) = (∑v∈{x ∈ T⇩pM. g (tangent_chart_fun x) ≠ 0}. g (tangent_chart_fun v) *⇩R v)›*) have set_simps: "{x ∈ T⇩pM. f (tangent_chart_fun x) ≠ 0} = coordinate_vector ` {v. f v ≠ 0}" "{x ∈ T⇩pM. g (tangent_chart_fun x) ≠ 0} = coordinate_vector ` {v. g v ≠ 0}" using coordinate_vector_inverse[OF k] (*‹(?v::('a ⇒ real) ⇒ real) ∈ T⇩pM ⟹ ?v = coordinate_vector (∑i::'b∈Basis. component_function ?v i *⇩R i)› ‹?x = (∑i∈Basis. component_function (coordinate_vector ?x) i *⇩R i)›*) unfolding tangent_chart_fun_def (*goals: 1. ‹{x ∈ T⇩pM. f (∑i∈Basis. component_function x i *⇩R i) ≠ 0} = coordinate_vector ` {v. f v ≠ 0}› 2. ‹{x ∈ T⇩pM. g (∑i∈Basis. component_function x i *⇩R i) ≠ 0} = coordinate_vector ` {v. g v ≠ 0}›*) using assms(1,2) (*‹∀v::'b. (f::'b ⇒ real) v ≠ (0::real) ⟶ v ∈ Basis› ‹∀v. g v ≠ 0 ⟶ v ∈ Basis›*) component_function_apply_out (*‹?v ∉ T⇩pM ⟹ component_function ?v ?i = 0›*) apply - (*goals: 1. ‹⟦⋀v. v ∈ T⇩pM ⟹ v = coordinate_vector (∑i∈Basis. component_function v i *⇩R i); ⋀x. x = (∑i∈Basis. component_function (coordinate_vector x) i *⇩R i); ∀v. f v ≠ 0 ⟶ v ∈ Basis; ∀v. g v ≠ 0 ⟶ v ∈ Basis; ⋀v i. v ∉ T⇩pM ⟹ component_function v i = 0⟧ ⟹ {x ∈ T⇩pM. f (∑i∈Basis. component_function x i *⇩R i) ≠ 0} = coordinate_vector ` {v. f v ≠ 0}› 2. ‹⟦⋀v. v ∈ T⇩pM ⟹ v = coordinate_vector (∑i∈Basis. component_function v i *⇩R i); ⋀x. x = (∑i∈Basis. component_function (coordinate_vector x) i *⇩R i); ∀v. f v ≠ 0 ⟶ v ∈ Basis; ∀v. g v ≠ 0 ⟶ v ∈ Basis; ⋀v i. v ∉ T⇩pM ⟹ component_function v i = 0⟧ ⟹ {x ∈ T⇩pM. g (∑i∈Basis. component_function x i *⇩R i) ≠ 0} = coordinate_vector ` {v. g v ≠ 0}› discuss goal 1*) apply ((auto)[1]) (*top goal: ‹⟦⋀v. v ∈ T⇩pM ⟹ v = coordinate_vector (∑i∈Basis. component_function v i *⇩R i); ⋀x. x = (∑i∈Basis. component_function (coordinate_vector x) i *⇩R i); ∀v. f v ≠ 0 ⟶ v ∈ Basis; ∀v. g v ≠ 0 ⟶ v ∈ Basis; ⋀v i. v ∉ T⇩pM ⟹ component_function v i = 0⟧ ⟹ {x ∈ T⇩pM. f (∑i∈Basis. component_function x i *⇩R i) ≠ 0} = coordinate_vector ` {v. f v ≠ 0}› and 1 goal remains*) apply (metis (no_types, lifting) Basis_zero (*‹0 ∉ Basis›*) scaleR_eq_0_iff (*‹(?a *⇩R ?x = 0) = (?a = 0 ∨ ?x = 0)›*) sum.not_neutral_contains_not_neutral (*‹⟦sum ?g ?A ≠ 0; ⋀a. ⟦a ∈ ?A; ?g a ≠ 0⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) (*discuss goal 2*) apply ((auto)[1]) (*goal: ‹⟦⋀v. v ∈ T⇩pM ⟹ v = coordinate_vector (∑i∈Basis. component_function v i *⇩R i); ⋀x. x = (∑i∈Basis. component_function (coordinate_vector x) i *⇩R i); ∀v. f v ≠ 0 ⟶ v ∈ Basis; ∀v. g v ≠ 0 ⟶ v ∈ Basis; ⋀v i. v ∉ T⇩pM ⟹ component_function v i = 0⟧ ⟹ {x ∈ T⇩pM. g (∑i∈Basis. component_function x i *⇩R i) ≠ 0} = coordinate_vector ` {v. g v ≠ 0}›*) apply (metis (no_types, lifting) Basis_zero (*‹0 ∉ Basis›*) scaleR_eq_0_iff (*‹(?a *⇩R ?x = 0) = (?a = 0 ∨ ?x = 0)›*) sum.not_neutral_contains_not_neutral (*‹⟦sum ?g ?A ≠ 0; ⋀a. ⟦a ∈ ?A; ?g a ≠ 0⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) (*proven 2 subgoals*) . have "(∑v∈{x ∈ T⇩pM. f (tangent_chart_fun x) ≠ 0}. f (tangent_chart_fun v) *⇩R v) = (∑i∈{v. f v ≠ 0}. f i *⇩R coordinate_vector i)" apply (simp add: set_simps (*‹{x ∈ T⇩pM. f (tangent_chart_fun x) ≠ 0} = coordinate_vector ` {v. f v ≠ 0}› ‹{x ∈ T⇩pM. g (tangent_chart_fun x) ≠ 0} = coordinate_vector ` {v. g v ≠ 0}›*)) (*goal: ‹(∑v∈{x ∈ T⇩pM. f (tangent_chart_fun x) ≠ 0}. f (tangent_chart_fun v) *⇩R v) = (∑i∈{v. f v ≠ 0}. f i *⇩R coordinate_vector i)›*) using coordinate_vector_inverse(2)[OF k] (*‹?x = (∑i∈Basis. component_function (coordinate_vector ?x) i *⇩R i)›*) by (simp add: tangent_chart_fun_def (*‹tangent_chart_fun ?v ≡ ∑i∈Basis. component_function ?v i *⇩R i›*) sum.reindex[OF inj_coordinate_vector[OF k]] (*‹sum ?g (coordinate_vector ` ?A) = sum (?g ∘ coordinate_vector) ?A›*)) also (*calculation: ‹(∑v∈{x ∈ T⇩pM. f (tangent_chart_fun x) ≠ 0}. f (tangent_chart_fun v) *⇩R v) = (∑i∈{v. f v ≠ 0}. f i *⇩R coordinate_vector i)›*) have "… = (∑i∈{v. g v ≠ 0}. (g i) *⇩R coordinate_vector i)" using assms(4) (*‹(∑i∈{v. f v ≠ 0}. f i *⇩R coordinate_vector i) = (∑i∈{v. g v ≠ 0}. g i *⇩R coordinate_vector i)›*) . finally (*calculation: ‹(∑v∈{x ∈ T⇩pM. f (tangent_chart_fun x) ≠ 0}. f (tangent_chart_fun v) *⇩R v) = (∑i∈{v. g v ≠ 0}. g i *⇩R coordinate_vector i)›*) show "(∑v∈{x ∈ T⇩pM. f (tangent_chart_fun x) ≠ 0}. f (tangent_chart_fun v) *⇩R v) = (∑v∈{x ∈ T⇩pM. g (tangent_chart_fun x) ≠ 0}. g (tangent_chart_fun v) *⇩R v)" apply (simp add: set_simps (*‹{x ∈ T⇩pM. f (tangent_chart_fun x) ≠ 0} = coordinate_vector ` {v. f v ≠ 0}› ‹{x ∈ T⇩pM. g (tangent_chart_fun x) ≠ 0} = coordinate_vector ` {v. g v ≠ 0}›*)) (*goal: ‹(∑v∈{x ∈ T⇩pM. f (tangent_chart_fun x) ≠ 0}. f (tangent_chart_fun v) *⇩R v) = (∑v∈{x ∈ T⇩pM. g (tangent_chart_fun x) ≠ 0}. g (tangent_chart_fun v) *⇩R v)›*) using coordinate_vector_inverse[OF k] (*‹?v ∈ T⇩pM ⟹ ?v = coordinate_vector (∑i∈Basis. component_function ?v i *⇩R i)› ‹?x = (∑i∈Basis. component_function (coordinate_vector ?x) i *⇩R i)›*) by (simp add: tangent_chart_fun_def (*‹tangent_chart_fun (?v::('a ⇒ real) ⇒ real) ≡ ∑i::'b∈Basis. component_function ?v i *⇩R i›*) sum.reindex[OF inj_coordinate_vector[OF k]] (*‹sum (?g::(('a ⇒ real) ⇒ real) ⇒ ?'a) (coordinate_vector ` (?A::'b set)) = sum (?g ∘ coordinate_vector) ?A›*)) qed (simp_all add: 1) (*solves the remaining goals: 1. ‹⋀v. ⟦v ∈ T⇩pM; f (tangent_chart_fun v) ≠ 0⟧ ⟹ v ∈ coordinate_vector ` Basis› 2. ‹⋀v. ⟦v ∈ T⇩pM; g (tangent_chart_fun v) ≠ 0⟧ ⟹ v ∈ coordinate_vector ` Basis›*) show "?thesis" (*goal: ‹∀i. f i = g i›*) using coordinate_vector_inverse[unfolded tangent_chart_fun_def [ symmetric ]] (*‹⟦k = ∞; ?v ∈ T⇩pM⟧ ⟹ ?v = coordinate_vector (tangent_chart_fun ?v)› ‹(k::enat) = ∞ ⟹ (?x::'b) = tangent_chart_fun (coordinate_vector ?x)›*) using tangent_chart_fun_bij (*‹k = ∞ ⟹ bij_betw tangent_chart_fun T⇩pM UNIV›*) coordinate_vector_bij (*‹(k::enat) = ∞ ⟹ bij_betw coordinate_vector UNIV T⇩pM›*) f_eq_g (*‹∀x::('a::{second_countable_topology,t2_space} ⇒ real) ⇒ real∈T⇩pM. (f::'b::euclidean_space ⇒ real) (tangent_chart_fun x) = (g::'b::euclidean_space ⇒ real) (tangent_chart_fun x)›*) by (metis coordinate_vector_surj (*‹k = ∞ ⟹ range coordinate_vector = T⇩pM›*) k (*‹k = ∞›*) rangeI (*‹?f ?x ∈ range ?f›*)) qed lemma coordinate_sum_eq_imp_components_eq: assumes k: "k=∞" and "(∑i∈Basis. (f i) *⇩R coordinate_vector i) = (∑i∈Basis. (g i) *⇩R coordinate_vector i)" shows "∀i∈Basis. f i = g i" using euclidean_coordinates_eq_iff[OF k] (*‹((∑i∈Basis. ?f i *⇩R coordinate_vector i) = (∑i∈Basis. ?g i *⇩R coordinate_vector i)) = (∀i∈Basis. ?f i = ?g i)›*) assms(2) (*‹(∑i∈Basis. f i *⇩R coordinate_vector i) = (∑i∈Basis. g i *⇩R coordinate_vector i)›*) by blast<close> lemma coordinate_sum_eq_iff: assumes "⋀v. f v ≠ 0 ⟷ v ∈ Basis" and "⋀v. g v ≠ 0 ⟷ v ∈ Basis" and k: "k=∞" shows "(∑i∈Basis. (f i) *⇩R coordinate_vector i) = (∑i∈Basis. (g i) *⇩R coordinate_vector i) ⟷ (∀i∈Basis. f i = g i)" using coordinate_sum_eq_imp_components_eq (*‹⟦k = ∞; (∑i∈Basis. ?f i *⇩R coordinate_vector i) = (∑i∈Basis. ?g i *⇩R coordinate_vector i)⟧ ⟹ ∀i∈Basis. ?f i = ?g i›*) assms (*‹(f ?v4 ≠ 0) = (?v4 ∈ Basis)› ‹(g ?v4 ≠ 0) = (?v4 ∈ Basis)› ‹(k::enat) = ∞›*) by auto lemma component_function_restrict_chart: assumes S: "p ∈ S" "open S" and v: "v ∈ T⇩pM" and i: "i ∈ Basis" and k: "k=∞" shows "component_function v i = (c_manifold_point.component_function charts ∞ (restrict_chart S ψ) p) v i" proof (-) (*goal: ‹component_function (v::('a ⇒ real) ⇒ real) (i::'b) = c_manifold_point.component_function (charts::('a, 'b) chart set) ∞ (restrict_chart (S::'a set) (ψ::('a, 'b) chart)) (p::'a) v i›*) interpret p2: c_manifold_point charts "∞" "restrict_chart S ψ" p using "ψ" (*‹ψ ∈ atlas›*) S (*‹p ∈ S› ‹open S›*) k (*‹(k::enat) = ∞›*) c_manifold_point (*‹⟦(?c::('a, 'b) chart) ∈ atlas; (?p::'a) ∈ domain ?c⟧ ⟹ c_manifold_point (charts::('a, 'b) chart set) (k::enat) ?c ?p›*) restrict_chart_in_atlas (*‹?c ∈ atlas ⟹ restrict_chart ?S ?c ∈ atlas›*) by force have coord_vec_eq: "coordinate_vector i = p2.coordinate_vector i" for i using coordinate_vector_restrict_chart[OF S k] (*‹coordinate_vector ?i = p2.coordinate_vector ?i›*) . let ?c = "restrict0 Basis (component_function v)" and ?c2 = "restrict0 Basis (p2.component_function v)" have "(∑i∈Basis. ?c i *⇩R coordinate_vector i) = (∑i∈Basis. ?c2 i *⇩R coordinate_vector i)" using coordinate_vector_representation (*‹⟦?v ∈ T⇩pM; k = ∞⟧ ⟹ ?v = (∑i∈Basis. component_function ?v i *⇩R coordinate_vector i)›*) p2.coordinate_vector_representation (*‹⟦?v ∈ p2.T⇩pM; ∞ = ∞⟧ ⟹ ?v = (∑i∈Basis. p2.component_function ?v i *⇩R p2.coordinate_vector i)›*) coord_vec_eq (*‹coordinate_vector (?i4::'b) = p2.coordinate_vector ?i4›*) k (*‹k = ∞›*) v (*‹v ∈ T⇩pM›*) by simp thus "?thesis" (*goal: ‹component_function (v::('a::{second_countable_topology,t2_space} ⇒ real) ⇒ real) (i::'b::euclidean_space) = p2.component_function v i›*) using euclidean_coordinates_eq_iff[OF k] (*‹((∑i∈Basis. ?f i *⇩R coordinate_vector i) = (∑i∈Basis. ?g i *⇩R coordinate_vector i)) = (∀i∈Basis. ?f i = ?g i)›*) i (*‹i ∈ Basis›*) restrict0_apply_in (*‹?x ∈ ?A ⟹ restrict0 ?A ?f ?x = ?f ?x›*) by auto qed lemma coordinate_vector_uminus: "coordinate_vector i (- f) = - coordinate_vector i f" if k: "k=∞" and f: "f ∈ diff_fun_space" proof (-) (*goal: ‹coordinate_vector (i::'b) (- (f::'a ⇒ real)) = - coordinate_vector i f›*) interpret l: linear_on diff_fun_space UNIV scaleR scaleR "coordinate_vector i" using coordinate_vector_i_linear_on[OF k] (*‹linear_on diff_fun_space UNIV (*⇩R) (*⇩R) (coordinate_vector ?i)›*) . show "?thesis" (*goal: ‹coordinate_vector i (- f) = - coordinate_vector i f›*) using diff_fun_space.m1.mem_uminus (*‹(?x::'a::{second_countable_topology,t2_space} ⇒ real) ∈ diff_fun_space ⟹ - ?x ∈ diff_fun_space›*) l.add (*‹⟦?b1.0 ∈ diff_fun_space; ?b2.0 ∈ diff_fun_space⟧ ⟹ coordinate_vector i (?b1.0 + ?b2.0) = coordinate_vector i ?b1.0 + coordinate_vector i ?b2.0›*) l.linear_0 (*‹coordinate_vector (i::'b) (0::'a ⇒ real) = (0::real)›*) f (*‹f ∈ diff_fun_space›*) by fastforce qed<close> lemma coordinate_vector_cong': "coordinate_vector i g = coordinate_vector i f" if k: "k=∞" and g: "g ∈ diff_fun_space" and f: "f ∈ diff_fun_space" and gf: "frechet_derivative (g ∘ inv_chart ψ) (at (ψ p)) = frechet_derivative (f ∘ inv_chart ψ) (at (ψ p))" using coordinate_vector_apply_in[OF k, of _ i] (*‹?f ∈ diff_fun_space ⟹ coordinate_vector i ?f = frechet_derivative (?f ∘ inv_chart ψ) (at (apply_chart ψ p)) i›*) g (*‹g ∈ diff_fun_space›*) f (*‹f ∈ diff_fun_space›*) gf (*‹frechet_derivative (g ∘ inv_chart ψ) (at (apply_chart ψ p)) = frechet_derivative (f ∘ inv_chart ψ) (at (apply_chart ψ p))›*) by presburger lemma coordinate_vector_cong: "coordinate_vector i g = coordinate_vector i f" if k: "k=∞" and g: "g ∈ diff_fun_space" and f: "f ∈ diff_fun_space" and gf: "⋀x. x∈(domain ψ) ⟹ g x = f x" proof (-) (*goal: ‹coordinate_vector i g = coordinate_vector i f›*) have "frechet_derivative (g ∘ inv_chart ψ) (at (ψ p)) = frechet_derivative (f ∘ inv_chart ψ) (at (ψ p))" apply (rule frechet_derivative_transform_within_open (*‹⟦(?f::?'a::real_normed_vector ⇒ ?'b::real_normed_vector) differentiable at (?x::?'a::real_normed_vector); open (?X::?'a::real_normed_vector set); ?x ∈ ?X; ⋀x::?'a::real_normed_vector. x ∈ ?X ⟹ ?f x = (?g::?'a::real_normed_vector ⇒ ?'b::real_normed_vector) x⟧ ⟹ frechet_derivative ?f (at ?x) = frechet_derivative ?g (at ?x)›*)) (*goal: ‹frechet_derivative (g ∘ inv_chart ψ) (at (apply_chart ψ p)) = frechet_derivative (f ∘ inv_chart ψ) (at (apply_chart ψ p))›*) using diff_fun_differentiable_at (*‹⟦diff_fun k charts ?f; ?c ∈ atlas; ?p ∈ domain ?c; 0 < k⟧ ⟹ ?f ∘ inv_chart ?c differentiable at (apply_chart ?c ?p)›*) g[unfolded diff_fun_space_def] (*‹g ∈ {f. diff_fun k charts f ∧ extensional0 carrier f}›*) "ψ" (*‹ψ ∈ atlas›*) k (*‹k = ∞›*) p (*‹(p::'a) ∈ domain (ψ::('a, 'b) chart)›*) apply (simp, blast) (*top goal: ‹g ∘ inv_chart ψ differentiable at (apply_chart ψ p)› and 3 goals remain*) using gf (*‹?x4 ∈ domain ψ ⟹ g ?x4 = f ?x4›*) by (auto simp: o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*)) from coordinate_vector_cong'[OF that ( 1 - 3 ) this] (*‹coordinate_vector ?i g = coordinate_vector ?i f›*) show "?thesis" (*goal: ‹coordinate_vector i g = coordinate_vector i f›*) . qed end (*context c_manifold_point*) lemma (in c_manifold) diff_fun_components_iff: fixes f :: "'b::euclidean_space ⇒ 'a::{second_countable_topology,t2_space} ⇒ real" shows "diff_fun k charts (λx. ∑i∈Basis. (f i x) *⇩R i) ⟷ (∀i∈Basis. diff_fun k charts (f i))" (is ‹?diff_sum ⟷ ?diff_cpt›) proof (standard) (*goals: 1. ‹diff_fun k charts (λx. ∑i∈Basis. f i x *⇩R i) ⟹ ∀i∈Basis. diff_fun k charts (f i)› 2. ‹∀i∈Basis. diff_fun k charts (f i) ⟹ diff_fun k charts (λx. ∑i∈Basis. f i x *⇩R i)›*) assume asm: "?diff_sum" (*‹diff_fun (k::enat) (charts::('a, 'b) chart set) (λx::'a. ∑i::'b∈Basis. (f::'b ⇒ 'a ⇒ real) i x *⇩R i)›*) have f_eq_inner_sum_cpt: "(∑j∈Basis. (f j x) *⇩R j) ∙ i = f i x" if "i∈Basis" for i :: 'b and x using that (*‹i ∈ Basis›*) by force show "?diff_cpt" proof (standard) (*goal: ‹⋀i. i ∈ Basis ⟹ diff_fun k charts (f i)›*) fix i :: 'b assume i: "i∈Basis" (*‹(i::'b) ∈ Basis›*) hence 1: "((λx. x ∙ i) ∘ (λx. ∑j∈Basis. f j x *⇩R j)) x = f i x" for x using f_eq_inner_sum_cpt (*‹?i3 ∈ Basis ⟹ (∑j∈Basis. f j ?x3 *⇩R j) ∙ ?i3 = f ?i3 ?x3›*) by (simp add: comp_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*)) show "diff_fun k charts (f i)" apply (rule diff_fun.diff_fun_cong[OF _ 1] (*‹diff_fun ?k ?charts (λx. ((λx. x ∙ i) ∘ (λx. ∑j∈Basis. f j x *⇩R j)) (?x4 x)) ⟹ diff_fun ?k ?charts (λx. f i (?x4 x))›*)) (*goal: ‹diff_fun k charts (f i)›*) apply (rule diff_fun_compose[of _ _ charts_eucl] (*‹⟦diff (?k::enat) (?M1.0::(?'a, ?'b) chart set) charts_eucl (?f::?'a ⇒ ?'c3); diff_fun ?k charts_eucl (?g::?'c3 ⇒ ?'e)⟧ ⟹ diff_fun ?k ?M1.0 (?g ∘ ?f)›*)) (*goal: ‹diff_fun k charts ((λx. x ∙ i) ∘ (λx. ∑j∈Basis. f j x *⇩R j))›*) using asm[unfolded diff_fun_def] (*‹diff k charts charts_eucl (λx. ∑i∈Basis. f i x *⇩R i)›*) apply - (*goals: 1. ‹diff k charts charts_eucl (λx. ∑i∈Basis. f i x *⇩R i) ⟹ diff k charts charts_eucl (λx. ∑j∈Basis. f j x *⇩R j)› 2. ‹diff k charts charts_eucl (λx. ∑i∈Basis. f i x *⇩R i) ⟹ diff_fun k charts_eucl (λx. x ∙ i)› discuss goal 1*) apply ((auto intro: diff_fun_charts_euclI (*‹(?k::enat)-smooth_on UNIV (?g::?'a::euclidean_space ⇒ ?'b::euclidean_space) ⟹ diff_fun ?k charts_eucl ?g›*) smooth_on_inner (*‹⟦(?k::enat)-smooth_on (?S::?'d::real_normed_vector set) (?f::?'d::real_normed_vector ⇒ ?'a::real_inner); ?k-smooth_on ?S (?g::?'d::real_normed_vector ⇒ ?'a::real_inner); open ?S⟧ ⟹ ?k-smooth_on ?S (λx::?'d::real_normed_vector. ?f x ∙ ?g x)›*))[1]) (*discuss goal 2*) apply ((auto intro: diff_fun_charts_euclI (*‹?k-smooth_on UNIV ?g ⟹ diff_fun ?k charts_eucl ?g›*) smooth_on_inner (*‹⟦?k-smooth_on ?S ?f; ?k-smooth_on ?S ?g; open ?S⟧ ⟹ ?k-smooth_on ?S (λx. ?f x ∙ ?g x)›*))[1]) (*proven 2 subgoals*) . qed next (*goal: ‹∀i∈Basis. diff_fun k charts (f i) ⟹ diff_fun k charts (λx. ∑i∈Basis. f i x *⇩R i)›*) assume "?diff_cpt" (*‹∀i::'b∈Basis. diff_fun (k::enat) (charts::('a, 'b) chart set) ((f::'b ⇒ 'a ⇒ real) i)›*) then show "?diff_sum" by (auto intro!: diff_fun_sum (*‹(⋀i. i ∈ ?S ⟹ diff_fun k charts (?f i)) ⟹ diff_fun k charts (λx. ∑i∈?S. ?f i x)›*) diff_fun_scaleR (*‹⟦diff_fun k charts ?a; diff_fun k charts ?b⟧ ⟹ diff_fun k charts (λx. ?a x *⇩R ?b x)›*) simp: diff_fun_const (*‹diff_fun k charts (λx. ?c)›*)) qed end
{ "path": "afp-2025-02-12/thys/Lie_Groups/More_Manifolds.thy", "repo": "afp-2025-02-12", "sha": "1e573d76ee583d30471a5e0a788d7fd528f5df816c7053fb65f28ac28cad2bb2" }
(* Title: Isomorphism Classes of Groups Author: Jakob von Raumer, Karlsruhe Institute of Technology Maintainer: Jakob von Raumer <jakob.raumer@student.kit.edu> *) theory GroupIsoClasses imports "HOL-Algebra.Coset" begin section ‹Isomorphism Classes of Groups› text ‹We construct a quotient type for isomorphism classes of groups.› typedef 'a group = "{G :: 'a monoid. group G}" proof show "⋀a. ⦇carrier = {a}, mult = (λx y. x), one = a⦈ ∈ {G. group G}" unfolding group_def group_axioms_def monoid_def Units_def by auto qed definition group_iso_rel :: "'a group ⇒ 'a group ⇒ bool" where "group_iso_rel G H = (∃φ. φ ∈ iso (Rep_group G) (Rep_group H))" quotient_type 'a group_iso_class = "'a group" / group_iso_rel morphisms Rep_group_iso Abs_group_iso proof (rule equivpI) show "reflp group_iso_rel" proof (rule reflpI) fix G :: "'b group" show "group_iso_rel G G" unfolding group_iso_rel_def using iso_set_refl by blast qed next show "symp group_iso_rel" proof (rule sympI) fix G H :: "'b group" assume "group_iso_rel G H" then obtain φ where "φ ∈ iso (Rep_group G) (Rep_group H)" unfolding group_iso_rel_def by auto then obtain φ' where "φ' ∈ iso (Rep_group H) (Rep_group G)" using group.iso_sym Rep_group using group.iso_set_sym by blast thus "group_iso_rel H G" unfolding group_iso_rel_def by auto qed next show "transp group_iso_rel" proof (rule transpI) fix G H I :: "'b group" assume "group_iso_rel G H" "group_iso_rel H I" then obtain φ ψ where "φ ∈ iso (Rep_group G) (Rep_group H)" "ψ ∈ iso (Rep_group H) (Rep_group I)" unfolding group_iso_rel_def by auto then obtain π where "π ∈ iso (Rep_group G) (Rep_group I)" using iso_set_trans by blast thus "group_iso_rel G I" unfolding group_iso_rel_def by auto qed qed text ‹This assigns to a given group the group isomorphism class› definition (in group) iso_class :: "'a group_iso_class" where "iso_class = Abs_group_iso (Abs_group (monoid.truncate G))" text ‹Two isomorphic groups do indeed have the same isomorphism class:› lemma iso_classes_iff: assumes "group G" assumes "group H" shows "(∃φ. φ ∈ iso G H) = (group.iso_class G = group.iso_class H)" proof (-) (*goal: ‹(∃φ::'a ⇒ 'a. φ ∈ Group.iso (G::('a, 'b) monoid_scheme) (H::('a, 'c) monoid_scheme)) = (group.iso_class G = group.iso_class H)›*) from assms(1,2) (*‹Group.group G› ‹Group.group H›*) have groups: "group (monoid.truncate G)" "group (monoid.truncate H)" unfolding monoid.truncate_def group_def group_axioms_def Units_def monoid_def (*goals: 1. ‹(((∀x y. x ∈ carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈ ⟶ y ∈ carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈ ⟶ x ⊗⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ y ∈ carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈) ∧ (∀x y z. x ∈ carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈ ⟶ y ∈ carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈ ⟶ z ∈ carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈ ⟶ x ⊗⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ y ⊗⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ z = x ⊗⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ (y ⊗⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ z))) ∧ 𝟭⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ ∈ carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈ ∧ (∀x. x ∈ carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈ ⟶ 𝟭⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ ⊗⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ x = x) ∧ (∀x. x ∈ carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈ ⟶ x ⊗⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ 𝟭⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ = x)) ∧ carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈ ⊆ {y ∈ carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈. ∃x∈carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈. x ⊗⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ y = 𝟭⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ ∧ y ⊗⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ x = 𝟭⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙}› 2. ‹(((∀x y. x ∈ carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈ ⟶ y ∈ carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈ ⟶ x ⊗⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ y ∈ carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈) ∧ (∀x y z. x ∈ carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈ ⟶ y ∈ carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈ ⟶ z ∈ carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈ ⟶ x ⊗⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ y ⊗⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ z = x ⊗⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ (y ⊗⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ z))) ∧ 𝟭⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ ∈ carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈ ∧ (∀x. x ∈ carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈ ⟶ 𝟭⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ ⊗⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ x = x) ∧ (∀x. x ∈ carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈ ⟶ x ⊗⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ 𝟭⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ = x)) ∧ carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈ ⊆ {y ∈ carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈. ∃x∈carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈. x ⊗⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ y = 𝟭⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ ∧ y ⊗⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ x = 𝟭⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙}›*) apply - (*goals: 1. ‹⟦(((∀x y. x ∈ carrier G ⟶ y ∈ carrier G ⟶ x ⊗⇘G⇙ y ∈ carrier G) ∧ (∀x y z. x ∈ carrier G ⟶ y ∈ carrier G ⟶ z ∈ carrier G ⟶ x ⊗⇘G⇙ y ⊗⇘G⇙ z = x ⊗⇘G⇙ (y ⊗⇘G⇙ z))) ∧ 𝟭⇘G⇙ ∈ carrier G ∧ (∀x. x ∈ carrier G ⟶ 𝟭⇘G⇙ ⊗⇘G⇙ x = x) ∧ (∀x. x ∈ carrier G ⟶ x ⊗⇘G⇙ 𝟭⇘G⇙ = x)) ∧ carrier G ⊆ {y ∈ carrier G. ∃x∈carrier G. x ⊗⇘G⇙ y = 𝟭⇘G⇙ ∧ y ⊗⇘G⇙ x = 𝟭⇘G⇙}; (((∀x y. x ∈ carrier H ⟶ y ∈ carrier H ⟶ x ⊗⇘H⇙ y ∈ carrier H) ∧ (∀x y z. x ∈ carrier H ⟶ y ∈ carrier H ⟶ z ∈ carrier H ⟶ x ⊗⇘H⇙ y ⊗⇘H⇙ z = x ⊗⇘H⇙ (y ⊗⇘H⇙ z))) ∧ 𝟭⇘H⇙ ∈ carrier H ∧ (∀x. x ∈ carrier H ⟶ 𝟭⇘H⇙ ⊗⇘H⇙ x = x) ∧ (∀x. x ∈ carrier H ⟶ x ⊗⇘H⇙ 𝟭⇘H⇙ = x)) ∧ carrier H ⊆ {y ∈ carrier H. ∃x∈carrier H. x ⊗⇘H⇙ y = 𝟭⇘H⇙ ∧ y ⊗⇘H⇙ x = 𝟭⇘H⇙}⟧ ⟹ (((∀x y. x ∈ carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈ ⟶ y ∈ carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈ ⟶ x ⊗⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ y ∈ carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈) ∧ (∀x y z. x ∈ carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈ ⟶ y ∈ carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈ ⟶ z ∈ carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈ ⟶ x ⊗⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ y ⊗⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ z = x ⊗⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ (y ⊗⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ z))) ∧ 𝟭⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ ∈ carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈ ∧ (∀x. x ∈ carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈ ⟶ 𝟭⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ ⊗⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ x = x) ∧ (∀x. x ∈ carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈ ⟶ x ⊗⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ 𝟭⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ = x)) ∧ carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈ ⊆ {y ∈ carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈. ∃x∈carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈. x ⊗⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ y = 𝟭⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ ∧ y ⊗⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ x = 𝟭⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙}› 2. ‹⟦(((∀x y. x ∈ carrier G ⟶ y ∈ carrier G ⟶ x ⊗⇘G⇙ y ∈ carrier G) ∧ (∀x y z. x ∈ carrier G ⟶ y ∈ carrier G ⟶ z ∈ carrier G ⟶ x ⊗⇘G⇙ y ⊗⇘G⇙ z = x ⊗⇘G⇙ (y ⊗⇘G⇙ z))) ∧ 𝟭⇘G⇙ ∈ carrier G ∧ (∀x. x ∈ carrier G ⟶ 𝟭⇘G⇙ ⊗⇘G⇙ x = x) ∧ (∀x. x ∈ carrier G ⟶ x ⊗⇘G⇙ 𝟭⇘G⇙ = x)) ∧ carrier G ⊆ {y ∈ carrier G. ∃x∈carrier G. x ⊗⇘G⇙ y = 𝟭⇘G⇙ ∧ y ⊗⇘G⇙ x = 𝟭⇘G⇙}; (((∀x y. x ∈ carrier H ⟶ y ∈ carrier H ⟶ x ⊗⇘H⇙ y ∈ carrier H) ∧ (∀x y z. x ∈ carrier H ⟶ y ∈ carrier H ⟶ z ∈ carrier H ⟶ x ⊗⇘H⇙ y ⊗⇘H⇙ z = x ⊗⇘H⇙ (y ⊗⇘H⇙ z))) ∧ 𝟭⇘H⇙ ∈ carrier H ∧ (∀x. x ∈ carrier H ⟶ 𝟭⇘H⇙ ⊗⇘H⇙ x = x) ∧ (∀x. x ∈ carrier H ⟶ x ⊗⇘H⇙ 𝟭⇘H⇙ = x)) ∧ carrier H ⊆ {y ∈ carrier H. ∃x∈carrier H. x ⊗⇘H⇙ y = 𝟭⇘H⇙ ∧ y ⊗⇘H⇙ x = 𝟭⇘H⇙}⟧ ⟹ (((∀x y. x ∈ carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈ ⟶ y ∈ carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈ ⟶ x ⊗⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ y ∈ carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈) ∧ (∀x y z. x ∈ carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈ ⟶ y ∈ carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈ ⟶ z ∈ carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈ ⟶ x ⊗⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ y ⊗⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ z = x ⊗⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ (y ⊗⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ z))) ∧ 𝟭⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ ∈ carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈ ∧ (∀x. x ∈ carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈ ⟶ 𝟭⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ ⊗⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ x = x) ∧ (∀x. x ∈ carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈ ⟶ x ⊗⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ 𝟭⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ = x)) ∧ carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈ ⊆ {y ∈ carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈. ∃x∈carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈. x ⊗⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ y = 𝟭⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ ∧ y ⊗⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ x = 𝟭⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have "(∃φ. φ ∈ iso G H) = (∃φ. φ ∈ iso (monoid.truncate G) (monoid.truncate H))" unfolding iso_def hom_def monoid.truncate_def (*goal: ‹(∃φ. φ ∈ {h ∈ {h ∈ carrier G → carrier H. ∀x∈carrier G. ∀y∈carrier G. h (x ⊗⇘G⇙ y) = h x ⊗⇘H⇙ h y}. bij_betw h (carrier G) (carrier H)}) = (∃φ. φ ∈ {h ∈ {h ∈ carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈ → carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈. ∀x∈carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈. ∀y∈carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈. h (x ⊗⇘⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈⇙ y) = h x ⊗⇘⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈⇙ h y}. bij_betw h (carrier ⦇carrier = carrier G, mult = (⊗⇘G⇙), one = 𝟭⇘G⇙⦈) (carrier ⦇carrier = carrier H, mult = (⊗⇘H⇙), one = 𝟭⇘H⇙⦈)})›*) by auto also (*calculation: ‹(∃φ. φ ∈ Group.iso G H) = (∃φ. φ ∈ Group.iso (monoid.truncate G) (monoid.truncate H))›*) have "… = group_iso_rel (Abs_group (monoid.truncate G)) (Abs_group (monoid.truncate H))" unfolding group_iso_rel_def (*goal: ‹(∃φ::'a ⇒ 'a. φ ∈ Group.iso (monoid.truncate (G::('a, 'b) monoid_scheme)) (monoid.truncate (H::('a, 'c) monoid_scheme))) = (∃φ::'a ⇒ 'a. φ ∈ Group.iso (Rep_group (Abs_group (monoid.truncate G))) (Rep_group (Abs_group (monoid.truncate H))))›*) using groups (*‹Group.group (monoid.truncate G)› ‹Group.group (monoid.truncate H)›*) group.Abs_group_inverse (*‹?y ∈ {G. Group.group G} ⟹ Rep_group (Abs_group ?y) = ?y›*) by (metis mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*)) also (*calculation: ‹(∃φ. φ ∈ Group.iso G H) = group_iso_rel (Abs_group (monoid.truncate G)) (Abs_group (monoid.truncate H))›*) have "… = (group.iso_class G = group.iso_class H)" using group.iso_class_def (*‹Group.group ?G ⟹ group.iso_class ?G = Abs_group_iso (Abs_group (monoid.truncate ?G))›*) assms (*‹Group.group G› ‹Group.group H›*) group_iso_class.abs_eq_iff (*‹(Abs_group_iso ?x = Abs_group_iso ?y) = group_iso_rel ?x ?y›*) by metis finally (*calculation: ‹(∃φ. φ ∈ Group.iso G H) = (group.iso_class G = group.iso_class H)›*) show "?thesis" (*goal: ‹(∃φ. φ ∈ Group.iso G H) = (group.iso_class G = group.iso_class H)›*) . qed end
{ "path": "afp-2025-02-12/thys/Jordan_Hoelder/GroupIsoClasses.thy", "repo": "afp-2025-02-12", "sha": "6caa7eff858cc10b7ad0062fa38a0f89ae43a955de5983ba3a95c64b8d48144a" }
(* Title: variants/e_all_abcd/OAodv.thy License: BSD 2-Clause. See LICENSE. Author: Timothy Bourke, Inria *) section "The `open' AODV model" theory E_OAodv imports E_Aodv AWN.OAWN_SOS_Labels AWN.OAWN_Convert begin text ‹Definitions for stating and proving global network properties over individual processes.› definition σ⇩A⇩O⇩D⇩V' :: "((ip ⇒ state) × ((state, msg, pseqp, pseqp label) seqp)) set" where "σ⇩A⇩O⇩D⇩V' ≡ {(λi. aodv_init i, Γ⇩A⇩O⇩D⇩V PAodv)}" abbreviation opaodv :: "ip ⇒ ((ip ⇒ state) × (state, msg, pseqp, pseqp label) seqp, msg seq_action) automaton" where "opaodv i ≡ ⦇ init = σ⇩A⇩O⇩D⇩V', trans = oseqp_sos Γ⇩A⇩O⇩D⇩V i ⦈" lemma initiali_aodv [intro!, simp]: "initiali i (init (opaodv i)) (init (paodv i))" unfolding "σ⇩A⇩O⇩D⇩V_def" "σ⇩A⇩O⇩D⇩V'_def" (*goal: ‹initiali i (init ⦇init = {(λi. ⦇ip = i, sn = 1, rt = λx. None, rreqs = {}, store = λx. None, msg = SOME x. True, data = SOME x. True, dests = SOME x. True, dip = SOME x. True, oip = SOME x. True, hops = SOME x. True, dsn = SOME x. True, dsk = SOME x. True, osn = SOME x. True, sip = SOME x. x ≠ i, handled = SOME x. True⦈, Γ⇩A⇩O⇩D⇩V PAodv)}, trans = oseqp_sos Γ⇩A⇩O⇩D⇩V i⦈) (init ⦇init = {(⦇ip = i, sn = 1, rt = λx. None, rreqs = {}, store = λx. None, msg = SOME x. True, data = SOME x. True, dests = SOME x. True, dip = SOME x. True, oip = SOME x. True, hops = SOME x. True, dsn = SOME x. True, dsk = SOME x. True, osn = SOME x. True, sip = SOME x. x ≠ i, handled = SOME x. True⦈, Γ⇩A⇩O⇩D⇩V PAodv)}, trans = seqp_sos Γ⇩A⇩O⇩D⇩V⦈)›*) apply rule (*goals: 1. ‹⋀σ p. (σ, p) ∈ init ⦇init = {(λi. ⦇ip = i, sn = 1, rt = λx. None, rreqs = {}, store = λx. None, msg = SOME x. True, data = SOME x. True, dests = SOME x. True, dip = SOME x. True, oip = SOME x. True, hops = SOME x. True, dsn = SOME x. True, dsk = SOME x. True, osn = SOME x. True, sip = SOME x. x ≠ i, handled = SOME x. True⦈, Γ⇩A⇩O⇩D⇩V PAodv)}, trans = oseqp_sos Γ⇩A⇩O⇩D⇩V i⦈ ⟹ (σ i, p) ∈ init ⦇init = {(⦇ip = i, sn = 1, rt = λx. None, rreqs = {}, store = λx. None, msg = SOME x. True, data = SOME x. True, dests = SOME x. True, dip = SOME x. True, oip = SOME x. True, hops = SOME x. True, dsn = SOME x. True, dsk = SOME x. True, osn = SOME x. True, sip = SOME x. x ≠ i, handled = SOME x. True⦈, Γ⇩A⇩O⇩D⇩V PAodv)}, trans = seqp_sos Γ⇩A⇩O⇩D⇩V⦈› 2. ‹⋀ξ p. (ξ, p) ∈ init ⦇init = {(⦇ip = i, sn = 1, rt = λx. None, rreqs = {}, store = λx. None, msg = SOME x. True, data = SOME x. True, dests = SOME x. True, dip = SOME x. True, oip = SOME x. True, hops = SOME x. True, dsn = SOME x. True, dsk = SOME x. True, osn = SOME x. True, sip = SOME x. x ≠ i, handled = SOME x. True⦈, Γ⇩A⇩O⇩D⇩V PAodv)}, trans = seqp_sos Γ⇩A⇩O⇩D⇩V⦈ ⟹ ∃σ. ξ = σ i ∧ (σ, p) ∈ init ⦇init = {(λi. ⦇ip = i, sn = 1, rt = λx. None, rreqs = {}, store = λx. None, msg = SOME x. True, data = SOME x. True, dests = SOME x. True, dip = SOME x. True, oip = SOME x. True, hops = SOME x. True, dsn = SOME x. True, dsk = SOME x. True, osn = SOME x. True, sip = SOME x. x ≠ i, handled = SOME x. True⦈, Γ⇩A⇩O⇩D⇩V PAodv)}, trans = oseqp_sos Γ⇩A⇩O⇩D⇩V i⦈› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma oaodv_control_within [simp]: "control_within Γ⇩A⇩O⇩D⇩V (init (opaodv i))" unfolding "σ⇩A⇩O⇩D⇩V'_def" (*goal: ‹control_within Γ⇩A⇩O⇩D⇩V (init ⦇init = {(λi. ⦇ip = i, sn = 1, rt = λx. None, rreqs = {}, store = λx. None, msg = SOME x. True, data = SOME x. True, dests = SOME x. True, dip = SOME x. True, oip = SOME x. True, hops = SOME x. True, dsn = SOME x. True, dsk = SOME x. True, osn = SOME x. True, sip = SOME x. x ≠ i, handled = SOME x. True⦈, Γ⇩A⇩O⇩D⇩V PAodv)}, trans = oseqp_sos Γ⇩A⇩O⇩D⇩V i⦈)›*) apply (rule control_withinI (*‹(⋀p::(?'a, ?'b, ?'c, ?'d) seqp. p ∈ Range (?σ::(?'e × (?'a, ?'b, ?'c, ?'d) seqp) set) ⟹ ∃pn::?'c. p ∈ subterms ((?Γ::?'c ⇒ (?'a, ?'b, ?'c, ?'d) seqp) pn)) ⟹ control_within ?Γ ?σ›*)) (*goal: ‹control_within Γ⇩A⇩O⇩D⇩V (init ⦇init = {(λi. ⦇ip = i, sn = 1, rt = λx. None, rreqs = {}, store = λx. None, msg = SOME x. True, data = SOME x. True, dests = SOME x. True, dip = SOME x. True, oip = SOME x. True, hops = SOME x. True, dsn = SOME x. True, dsk = SOME x. True, osn = SOME x. True, sip = SOME x. x ≠ i, handled = SOME x. True⦈, Γ⇩A⇩O⇩D⇩V PAodv)}, trans = oseqp_sos Γ⇩A⇩O⇩D⇩V i⦈)›*) by (auto simp del: Γ⇩A⇩O⇩D⇩V_simps (*‹Γ⇩A⇩O⇩D⇩V PAodv = {PAodv-:0}receive(λmsg'. msg_update (λ_. msg')) . ({PAodv-:1}⟨is_newpkt⟩ {PAodv-:2}⟦λξ. clear_locals ξ⦇data := data ξ, dip := ip ξ⦈⟧ call(PNewPkt) ⊕ {PAodv-:1}⟨is_pkt⟩ {PAodv-:3}⟦λξ. clear_locals ξ⦇data := data ξ, dip := dip ξ, oip := oip ξ⦈⟧ call(PPkt) ⊕ {PAodv-:1}⟨is_rreq⟩ {PAodv-:4}⟦λξ. ξ⦇rt := update (rt ξ) (sip ξ) (0, unk, val, Suc 0, sip ξ)⦈⟧ {PAodv-:5}⟦λξ. clear_locals ξ⦇hops := hops ξ, dip := dip ξ, dsn := dsn ξ, dsk := dsk ξ, oip := oip ξ, osn := osn ξ, sip := sip ξ, handled := handled ξ⦈⟧ call(PRreq) ⊕ {PAodv-:1}⟨is_rrep⟩ {PAodv-:6}⟦λξ. ξ⦇rt := update (rt ξ) (sip ξ) (0, unk, val, Suc 0, sip ξ)⦈⟧ {PAodv-:7}⟦λξ. clear_locals ξ⦇hops := hops ξ, dip := dip ξ, dsn := dsn ξ, oip := oip ξ, sip := sip ξ⦈⟧ call(PRrep) ⊕ {PAodv-:1}⟨is_rerr⟩ {PAodv-:8}⟦λξ. ξ⦇rt := update (rt ξ) (sip ξ) (0, unk, val, Suc 0, sip ξ)⦈⟧ {PAodv-:9}⟦λξ. clear_locals ξ⦇dests := dests ξ, sip := sip ξ⦈⟧ call(PRerr)) ⊕ {PAodv-:0}⟨λξ. {ξ⦇dip := dip⦈ |dip. dip ∈ qD (store ξ) ∧ dip ∈ vD (rt ξ)}⟩ {PAodv-:10}⟦λξ. ξ⦇data := hd σ⇘queue⇙(store ξ, dip ξ)⦈⟧ {PAodv-:11}unicast(λξ. the (nhop (rt ξ) (dip ξ)), λξ. Pkt (data ξ) (dip ξ) (ip ξ)) . {PAodv-:12}⟦λξ. ξ⦇store := the (E_Aodv_Data.drop (dip ξ) (store ξ))⦈⟧ {PAodv-:13}⟦clear_locals⟧ call(PAodv) ▹ {PAodv-:14}⟦λξ. ξ⦇dests := λrip. if rip ∈ vD (rt ξ) ∧ nhop (rt ξ) rip = nhop (rt ξ) (dip ξ) then Some (inc (sqn (rt ξ) rip)) else None⦈⟧ {PAodv-:15}⟦λξ. ξ⦇rt := invalidate (rt ξ) (dests ξ)⦈⟧ {PAodv-:16}⟦λξ. ξ⦇store := setRRF (store ξ) (dests ξ)⦈⟧ {PAodv-:17}broadcast(λξ. Rerr (dests ξ) (ip ξ)) . {PAodv-:18}⟦clear_locals⟧ call(PAodv) ⊕ {PAodv-:0}⟨λξ. {ξ⦇dip := dip⦈ |dip. dip ∈ qD (store ξ) ∧ dip ∉ vD (rt ξ) ∧ the σ⇘p-flag⇙(store ξ, dip) = req}⟩ {PAodv-:19}⟦λξ. ξ⦇store := unsetRRF (store ξ) (dip ξ)⦈⟧ {PAodv-:20}⟦λξ. ξ⦇sn := inc (sn ξ)⦈⟧ {PAodv-:21}⟦λξ. ξ⦇rreqs := insert (ip ξ, sn ξ) (rreqs ξ)⦈⟧ {PAodv-:22}broadcast(λξ. Rreq 0 (dip ξ) (sqn (rt ξ) (dip ξ)) (sqnf (rt ξ) (dip ξ)) (ip ξ) (sn ξ) (ip ξ) False) . {PAodv-:23}⟦clear_locals⟧ call(PAodv)› ‹Γ⇩A⇩O⇩D⇩V PNewPkt = {PNewPkt-:0}⟨λξ. if dip ξ = ip ξ then {ξ} else {}⟩ {PNewPkt-:1}deliver(data) . {PNewPkt-:2}⟦clear_locals⟧ call(PAodv) ⊕ {PNewPkt-:0}⟨λξ. if dip ξ ≠ ip ξ then {ξ} else {}⟩ {PNewPkt-:3}⟦λξ. ξ⦇store := add (data ξ) (dip ξ) (store ξ)⦈⟧ {PNewPkt-:4}⟦clear_locals⟧ call(PAodv)› ‹Γ⇩A⇩O⇩D⇩V PPkt = {PPkt-:0}⟨λξ. if dip ξ = ip ξ then {ξ} else {}⟩ {PPkt-:1}deliver(data) . {PPkt-:2}⟦clear_locals⟧ call(PAodv) ⊕ {PPkt-:0}⟨λξ. if dip ξ ≠ ip ξ then {ξ} else {}⟩ ({PPkt-:3}⟨λξ. if dip ξ ∈ vD (rt ξ) then {ξ} else {}⟩ {PPkt-:4}unicast(λξ. the (nhop (rt ξ) (dip ξ)), λξ. Pkt (data ξ) (dip ξ) (oip ξ)) . {PPkt-:5}⟦clear_locals⟧ call(PAodv) ▹ {PPkt-:6}⟦λξ. ξ⦇dests := λrip. if rip ∈ vD (rt ξ) ∧ nhop (rt ξ) rip = nhop (rt ξ) (dip ξ) then Some (inc (sqn (rt ξ) rip)) else None⦈⟧ {PPkt-:7}⟦λξ. ξ⦇rt := invalidate (rt ξ) (dests ξ)⦈⟧ {PPkt-:8}⟦λξ. ξ⦇store := setRRF (store ξ) (dests ξ)⦈⟧ {PPkt-:9}broadcast(λξ. Rerr (dests ξ) (ip ξ)) . {PPkt-:10}⟦clear_locals⟧ call(PAodv) ⊕ {PPkt-:3}⟨λξ. if dip ξ ∉ vD (rt ξ) then {ξ} else {}⟩ ({PPkt-:11}⟨λξ. if dip ξ ∈ iD (rt ξ) then {ξ} else {}⟩ {PPkt-:12}broadcast(λξ. Rerr [dip ξ ↦ sqn (rt ξ) (dip ξ)] (ip ξ)) . {PPkt-:13}⟦clear_locals⟧ call(PAodv) ⊕ {PPkt-:11}⟨λξ. if dip ξ ∉ iD (rt ξ) then {ξ} else {}⟩ {PPkt-:14}⟦clear_locals⟧ call(PAodv)))› ‹Γ⇩A⇩O⇩D⇩V PRreq = {PRreq-:0}⟨λξ. if (oip ξ, osn ξ) ∈ rreqs ξ then {ξ} else {}⟩ {PRreq-:1}⟦clear_locals⟧ call(PAodv) ⊕ {PRreq-:0}⟨λξ. if (oip ξ, osn ξ) ∉ rreqs ξ then {ξ} else {}⟩ {PRreq-:2}⟦λξ. ξ⦇rt := update (rt ξ) (oip ξ) (osn ξ, kno, val, Suc (hops ξ), sip ξ)⦈⟧ {PRreq-:3}⟦λξ. ξ⦇rreqs := insert (oip ξ, osn ξ) (rreqs ξ)⦈⟧ ({PRreq-:4}⟨λξ. if ¬ handled ξ then {ξ} else {}⟩ ({PRreq-:5}⟨λξ. if dip ξ = ip ξ then {ξ} else {}⟩ {PRreq-:6}⟦λξ. ξ⦇sn := max (sn ξ) (dsn ξ)⦈⟧ {PRreq-:7}unicast(λξ. the (nhop (rt ξ) (oip ξ)), λξ. Rrep 0 (dip ξ) (sn ξ) (oip ξ) (ip ξ)) . {PRreq-:8}broadcast(λξ. Rreq (Suc (hops ξ)) (dip ξ) (dsn ξ) (dsk ξ) (oip ξ) (osn ξ) (ip ξ) True) . {PRreq-:9}⟦clear_locals⟧ call(PAodv) ▹ {PRreq-:10}⟦λξ. ξ⦇dests := λrip. if rip ∈ vD (rt ξ) ∧ nhop (rt ξ) rip = nhop (rt ξ) (oip ξ) then Some (inc (sqn (rt ξ) rip)) else None⦈⟧ {PRreq-:11}⟦λξ. ξ⦇rt := invalidate (rt ξ) (dests ξ)⦈⟧ {PRreq-:12}⟦λξ. ξ⦇store := setRRF (store ξ) (dests ξ)⦈⟧ {PRreq-:13}broadcast(λξ. Rerr (dests ξ) (ip ξ)) . {PRreq-:14}⟦clear_locals⟧ call(PAodv) ⊕ {PRreq-:5}⟨λξ. if dip ξ ≠ ip ξ then {ξ} else {}⟩ ({PRreq-:15}⟨λξ. if dip ξ ∈ vD (rt ξ) ∧ dsn ξ ≤ sqn (rt ξ) (dip ξ) ∧ sqnf (rt ξ) (dip ξ) = kno then {ξ} else {}⟩ {PRreq-:16}unicast(λξ. the (nhop (rt ξ) (oip ξ)), λξ. Rrep (the (dhops (rt ξ) (dip ξ))) (dip ξ) (sqn (rt ξ) (dip ξ)) (oip ξ) (ip ξ)) . {PRreq-:17}broadcast(λξ. Rreq (Suc (hops ξ)) (dip ξ) (dsn ξ) (dsk ξ) (oip ξ) (osn ξ) (ip ξ) True) . {PRreq-:18}⟦clear_locals⟧ call(PAodv) ▹ {PRreq-:19}⟦λξ. ξ⦇dests := λrip. if rip ∈ vD (rt ξ) ∧ nhop (rt ξ) rip = nhop (rt ξ) (oip ξ) then Some (inc (sqn (rt ξ) rip)) else None⦈⟧ {PRreq-:20}⟦λξ. ξ⦇rt := invalidate (rt ξ) (dests ξ)⦈⟧ {PRreq-:21}⟦λξ. ξ⦇store := setRRF (store ξ) (dests ξ)⦈⟧ {PRreq-:22}broadcast(λξ. Rerr (dests ξ) (ip ξ)) . {PRreq-:23}⟦clear_locals⟧ call(PAodv) ⊕ {PRreq-:15}⟨λξ. if dip ξ ∈ vD (rt ξ) ⟶ sqn (rt ξ) (dip ξ) < dsn ξ ∨ π₃ (the (rt ξ (dip ξ))) = unk then {ξ} else {}⟩ {PRreq-:24}broadcast(λξ. Rreq (Suc (hops ξ)) (dip ξ) (max (sqn (rt ξ) (dip ξ)) (dsn ξ)) (dsk ξ) (oip ξ) (osn ξ) (ip ξ) False) . {PRreq-:25}⟦clear_locals⟧ call(PAodv))) ⊕ {PRreq-:4}⟨λξ. if handled ξ then {ξ} else {}⟩ {PRreq-:26}broadcast(λξ. Rreq (Suc (hops ξ)) (dip ξ) (dsn ξ) (dsk ξ) (oip ξ) (osn ξ) (ip ξ) True) . {PRreq-:27}⟦clear_locals⟧ call(PAodv))› ‹Γ⇩A⇩O⇩D⇩V PRrep = {PRrep-:0}⟦λξ. ξ⦇rt := update (rt ξ) (dip ξ) (dsn ξ, kno, val, Suc (hops ξ), sip ξ)⦈⟧ ({PRrep-:1}⟨λξ. if oip ξ = ip ξ then {ξ} else {}⟩ {PRrep-:2}⟦clear_locals⟧ call(PAodv) ⊕ {PRrep-:1}⟨λξ. if oip ξ ≠ ip ξ then {ξ} else {}⟩ ({PRrep-:3}⟨λξ. if oip ξ ∈ vD (rt ξ) ∧ dip ξ ∈ vD (rt ξ) then {ξ} else {}⟩ {PRrep-:4}unicast(λξ. the (nhop (rt ξ) (oip ξ)), λξ. Rrep (the (dhops (rt ξ) (dip ξ))) (dip ξ) (sqn (rt ξ) (dip ξ)) (oip ξ) (ip ξ)) . {PRrep-:5}⟦clear_locals⟧ call(PAodv) ▹ {PRrep-:6}⟦λξ. ξ⦇dests := λrip. if rip ∈ vD (rt ξ) ∧ nhop (rt ξ) rip = nhop (rt ξ) (oip ξ) then Some (inc (sqn (rt ξ) rip)) else None⦈⟧ {PRrep-:7}⟦λξ. ξ⦇rt := invalidate (rt ξ) (dests ξ)⦈⟧ {PRrep-:8}⟦λξ. ξ⦇store := setRRF (store ξ) (dests ξ)⦈⟧ {PRrep-:9}broadcast(λξ. Rerr (dests ξ) (ip ξ)) . {PRrep-:10}⟦clear_locals⟧ call(PAodv) ⊕ {PRrep-:3}⟨λξ. if oip ξ ∈ vD (rt ξ) ⟶ dip ξ ∉ vD (rt ξ) then {ξ} else {}⟩ {PRrep-:11}⟦clear_locals⟧ call(PAodv)))› ‹Γ⇩A⇩O⇩D⇩V PRerr = {PRerr-:0}⟦λξ. ξ⦇dests := λrip. case dests ξ rip of None ⇒ None | Some rsn ⇒ if rip ∈ vD (rt ξ) ∧ the (nhop (rt ξ) rip) = sip ξ ∧ sqn (rt ξ) rip < rsn then Some rsn else None⦈⟧ {PRerr-:1}⟦λξ. ξ⦇rt := invalidate (rt ξ) (dests ξ)⦈⟧ {PRerr-:2}⟦λξ. ξ⦇store := setRRF (store ξ) (dests ξ)⦈⟧ ({PRerr-:3}⟨λξ. if dests ξ ≠ (λx. None) then {ξ} else {}⟩ {PRerr-:4}broadcast(λξ. Rerr (dests ξ) (ip ξ)) . {PRerr-:5}⟦clear_locals⟧ call(PAodv) ⊕ {PRerr-:3}⟨λξ. if dests ξ = (λx. None) then {ξ} else {}⟩ {PRerr-:6}⟦clear_locals⟧ call(PAodv))›*)) lemma σ⇩A⇩O⇩D⇩V'_labels [simp]: "(σ, p) ∈ σ⇩A⇩O⇩D⇩V' ⟹ labels Γ⇩A⇩O⇩D⇩V p = {PAodv-:0}" unfolding "σ⇩A⇩O⇩D⇩V'_def" (*goal: ‹(σ, p) ∈ {(λi. ⦇ip = i, sn = 1, rt = λx. None, rreqs = {}, store = λx. None, msg = SOME x. True, data = SOME x. True, dests = SOME x. True, dip = SOME x. True, oip = SOME x. True, hops = SOME x. True, dsn = SOME x. True, dsk = SOME x. True, osn = SOME x. True, sip = SOME x. x ≠ i, handled = SOME x. True⦈, Γ⇩A⇩O⇩D⇩V PAodv)} ⟹ labels Γ⇩A⇩O⇩D⇩V p = {PAodv-:0}›*) by simp lemma oaodv_init_kD_empty [simp]: "(σ, p) ∈ σ⇩A⇩O⇩D⇩V' ⟹ kD (rt (σ i)) = {}" unfolding "σ⇩A⇩O⇩D⇩V'_def" kD_def (*goal: ‹(σ, p) ∈ {(λi. ⦇ip = i, sn = 1, rt = λx. None, rreqs = {}, store = λx. None, msg = SOME x. True, data = SOME x. True, dests = SOME x. True, dip = SOME x. True, oip = SOME x. True, hops = SOME x. True, dsn = SOME x. True, dsk = SOME x. True, osn = SOME x. True, sip = SOME x. x ≠ i, handled = SOME x. True⦈, Γ⇩A⇩O⇩D⇩V PAodv)} ⟹ {dip. rt (σ i) dip ≠ None} = {}›*) by simp lemma oaodv_init_vD_empty [simp]: "(σ, p) ∈ σ⇩A⇩O⇩D⇩V' ⟹ vD (rt (σ i)) = {}" unfolding "σ⇩A⇩O⇩D⇩V'_def" vD_def (*goal: ‹(σ::nat ⇒ state, p::(state, msg, pseqp, pseqp label) seqp) ∈ {(λi::nat. ⦇ip = i, sn = 1::nat, rt = λx::nat. None, rreqs = {}, store = λx::nat. None, msg = SOME x::msg. True, data = SOME x::nat. True, dests = SOME x::nat ⇒ nat option. True, dip = SOME x::nat. True, oip = SOME x::nat. True, hops = SOME x::nat. True, dsn = SOME x::nat. True, dsk = SOME x::k. True, osn = SOME x::nat. True, sip = SOME x::nat. x ≠ i, handled = SOME x::bool. True⦈, Γ⇩A⇩O⇩D⇩V PAodv)} ⟹ {dip::nat. flag (rt (σ (i::nat))) dip = Some val} = {}›*) by simp lemma oaodv_trans: "trans (opaodv i) = oseqp_sos Γ⇩A⇩O⇩D⇩V i" by simp declare oseq_invariant_ctermsI [OF aodv_wf oaodv_control_within aodv_simple_labels oaodv_trans, cterms_intros] oseq_step_invariant_ctermsI [OF aodv_wf oaodv_control_within aodv_simple_labels oaodv_trans, cterms_intros] end
{ "path": "afp-2025-02-12/thys/AODV/variants/e_all_abcd/E_OAodv.thy", "repo": "afp-2025-02-12", "sha": "d9bdc5c8b265a338ebb0c4708c69bccbf024ad883132db97b1250883bda2fa0a" }
(* Title: Signed (Finite) Multisets Author: Jasmin Blanchette <jasmin.blanchette at inria.fr>, 2016 Maintainer: Jasmin Blanchette <jasmin.blanchette at inria.fr> *) section ‹Signed (Finite) Multisets› theory Signed_Multiset imports Multiset_More abbrevs "!z" = "⇩z" begin unbundle multiset.lifting subsection ‹Definition of Signed Multisets› definition equiv_zmset :: "'a multiset × 'a multiset ⇒ 'a multiset × 'a multiset ⇒ bool" where "equiv_zmset = (λ(Mp, Mn) (Np, Nn). Mp + Nn = Np + Mn)" quotient_type 'a zmultiset = "'a multiset × 'a multiset" / equiv_zmset by (rule equivpI, simp_all add: equiv_zmset_def reflp_def symp_def transp_def) (metis multi_union_self_other_eq union_lcomm) subsection ‹Basic Operations on Signed Multisets› instantiation zmultiset :: (type) cancel_comm_monoid_add begin lift_definition zero_zmultiset :: "'a zmultiset" is "({#}, {#})" . abbreviation empty_zmset :: "'a zmultiset" ("{#}⇩z") where "empty_zmset ≡ 0" lift_definition minus_zmultiset :: "'a zmultiset ⇒ 'a zmultiset ⇒ 'a zmultiset" is "λ(Mp, Mn) (Np, Nn). (Mp + Nn, Mn + Np)" by (auto simp: equiv_zmset_def union_commute union_lcomm) lift_definition plus_zmultiset :: "'a zmultiset ⇒ 'a zmultiset ⇒ 'a zmultiset" is "λ(Mp, Mn) (Np, Nn). (Mp + Np, Mn + Nn)" by (auto simp: equiv_zmset_def union_commute union_lcomm) instance by (intro_classes; transfer) (auto simp: equiv_zmset_def) end instantiation zmultiset :: (type) group_add begin lift_definition uminus_zmultiset :: "'a zmultiset ⇒ 'a zmultiset" is "λ(Mp, Mn). (Mn, Mp)" by (auto simp: equiv_zmset_def add.commute) instance by (intro_classes; transfer) (auto simp: equiv_zmset_def) end lift_definition zcount :: "'a zmultiset ⇒ 'a ⇒ int" is "λ(Mp, Mn) x. int (count Mp x) - int (count Mn x)" by (auto simp del: of_nat_add simp: equiv_zmset_def fun_eq_iff multiset_eq_iff diff_eq_eq diff_add_eq eq_diff_eq of_nat_add[symmetric]) lemma zcount_inject: "zcount M = zcount N ⟷ M = N" apply transfer (*goal: ‹(zcount M = zcount N) = (M = N)›*) by (auto simp del: of_nat_add (*‹of_nat (?m + ?n) = of_nat ?m + of_nat ?n›*) simp: equiv_zmset_def (*‹equiv_zmset = (λ(Mp, Mn) (Np, Nn). Mp + Nn = Np + Mn)›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) multiset_eq_iff (*‹(?M = ?N) = (∀a. count ?M a = count ?N a)›*) diff_eq_eq (*‹(?a - ?b = ?c) = (?a = ?c + ?b)›*) diff_add_eq (*‹?a - ?b + ?c = ?a + ?c - ?b›*) eq_diff_eq (*‹(?a = ?c - ?b) = (?a + ?b = ?c)›*) of_nat_add[symmetric] (*‹of_nat ?m + of_nat ?n = of_nat (?m + ?n)›*)) lemma zmultiset_eq_iff: "M = N ⟷ (∀a. zcount M a = zcount N a)" by (simp only: zcount_inject[symmetric] (*‹(?M = ?N) = (zcount ?M = zcount ?N)›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*)) lemma zmultiset_eqI: "(⋀x. zcount A x = zcount B x) ⟹ A = B" using zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*) by auto lemma zcount_uminus[simp]: "zcount (- A) x = - zcount A x" apply transfer (*goal: ‹zcount (- A) x = - zcount A x›*) by auto lift_definition add_zmset :: "'a ⇒ 'a zmultiset ⇒ 'a zmultiset" is "λx (Mp, Mn). (add_mset x Mp, Mn)" by (auto simp: equiv_zmset_def) syntax "_zmultiset" :: "args ⇒ 'a zmultiset" ("{#(_)#}⇩z") translations "{#x, xs#}⇩z" == "CONST add_zmset x {#xs#}⇩z" "{#x#}⇩z" == "CONST add_zmset x {#}⇩z" lemma zcount_empty[simp]: "zcount {#}⇩z a = 0" apply transfer (*goal: ‹zcount {#}⇩z a = 0›*) by auto lemma zcount_add_zmset[simp]: "zcount (add_zmset b A) a = (if b = a then zcount A a + 1 else zcount A a)" apply transfer (*goal: ‹zcount (add_zmset b A) a = (if b = a then zcount A a + 1 else zcount A a)›*) by auto lemma zcount_single: "zcount {#b#}⇩z a = (if b = a then 1 else 0)" by simp lemma add_add_same_iff_zmset[simp]: "add_zmset a A = add_zmset a B ⟷ A = B" by (auto simp: zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*)) lemma add_zmset_commute: "add_zmset x (add_zmset y M) = add_zmset y (add_zmset x M)" by (auto simp: zmultiset_eq_iff (*‹((?M::?'a::type zmultiset) = (?N::?'a::type zmultiset)) = (∀a::?'a::type. zcount ?M a = zcount ?N a)›*)) lemma singleton_ne_empty_zmset[simp]: "{#x#}⇩z ≠ {#}⇩z" and empty_ne_singleton_zmset[simp]: "{#}⇩z ≠ {#x#}⇩z" (*goals: 1. ‹{#x#}⇩z ≠ {#}⇩z› 2. ‹{#}⇩z ≠ {#x#}⇩z› discuss goal 1*) apply ((auto dest!: arg_cong2[of _ _ x _ zcount] (*‹⟦?a = ?b; x = ?d⟧ ⟹ zcount ?a x = zcount ?b ?d›*))[1]) (*discuss goal 2*) apply ((auto dest!: arg_cong2[of _ _ x _ zcount] (*‹⟦?a = ?b; x = ?d⟧ ⟹ zcount ?a x = zcount ?b ?d›*))[1]) (*proven 2 subgoals*) . lemma singleton_ne_uminus_singleton_zmset[simp]: "{#x#}⇩z ≠ - {#y#}⇩z" and uminus_singleton_ne_singleton_zmset[simp]: "- {#x#}⇩z ≠ {#y#}⇩z" (*goals: 1. ‹{#x#}⇩z ≠ - {#y#}⇩z› 2. ‹- {#x#}⇩z ≠ {#y#}⇩z› discuss goal 1*) apply ((auto dest!: arg_cong2[of _ _ x x zcount] (*‹⟦?a = ?b; x = x⟧ ⟹ zcount ?a x = zcount ?b x›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto dest!: arg_cong2[of _ _ x x zcount] (*‹⟦?a = ?b; x = x⟧ ⟹ zcount ?a x = zcount ?b x›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 2 subgoals*) . subsubsection ‹Conversion to Set and Membership› definition set_zmset :: "'a zmultiset ⇒ 'a set" where "set_zmset M = {x. zcount M x ≠ 0}" abbreviation elem_zmset :: "'a ⇒ 'a zmultiset ⇒ bool" where "elem_zmset a M ≡ a ∈ set_zmset M" notation elem_zmset ("'(∈#⇩z')") and elem_zmset ("(_/ ∈#⇩z _)" [51, 51] 50) notation (ASCII) elem_zmset ("'(:#z')") and elem_zmset ("(_/ :#z _)" [51, 51] 50) abbreviation not_elem_zmset :: "'a ⇒ 'a zmultiset ⇒ bool" where "not_elem_zmset a M ≡ a ∉ set_zmset M" notation not_elem_zmset ("'(∉#⇩z')") and not_elem_zmset ("(_/ ∉#⇩z _)" [51, 51] 50) notation (ASCII) not_elem_zmset ("'(~:#z')") and not_elem_zmset ("(_/ ~:#z _)" [51, 51] 50) context begin qualified abbreviation Ball :: "'a zmultiset ⇒ ('a ⇒ bool) ⇒ bool" where "Ball M ≡ Set.Ball (set_zmset M)" qualified abbreviation Bex :: "'a zmultiset ⇒ ('a ⇒ bool) ⇒ bool" where "Bex M ≡ Set.Bex (set_zmset M)" end syntax "_ZMBall" :: "pttrn ⇒ 'a set ⇒ bool ⇒ bool" ("(3∀_∈#⇩z_./ _)" [0, 0, 10] 10) "_ZMBex" :: "pttrn ⇒ 'a set ⇒ bool ⇒ bool" ("(3∃_∈#⇩z_./ _)" [0, 0, 10] 10) syntax (ASCII) "_ZMBall" :: "pttrn ⇒ 'a set ⇒ bool ⇒ bool" ("(3∀_:#⇩z_./ _)" [0, 0, 10] 10) "_ZMBex" :: "pttrn ⇒ 'a set ⇒ bool ⇒ bool" ("(3∃_:#⇩z_./ _)" [0, 0, 10] 10) translations "∀x∈#⇩zA. P" ⇌ "CONST Signed_Multiset.Ball A (λx. P)" "∃x∈#⇩zA. P" ⇌ "CONST Signed_Multiset.Bex A (λx. P)" lemma zcount_eq_zero_iff: "zcount M x = 0 ⟷ x ∉#⇩z M" by (auto simp add: set_zmset_def (*‹set_zmset (?M::?'a zmultiset) = {x::?'a. zcount ?M x ≠ (0::int)}›*)) lemma not_in_iff_zmset: "x ∉#⇩z M ⟷ zcount M x = 0" by (auto simp add: zcount_eq_zero_iff (*‹(zcount ?M ?x = 0) = (?x ∉#⇩z ?M)›*)) lemma zcount_ne_zero_iff[simp]: "zcount M x ≠ 0 ⟷ x ∈#⇩z M" by (auto simp add: set_zmset_def (*‹set_zmset ?M = {x. zcount ?M x ≠ 0}›*)) lemma zcount_inI: assumes "zcount M x = 0 ⟹ False" shows "x ∈#⇩z M" proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹x ∉#⇩z M ⟹ False›*) assume "x ∉#⇩z M" (*‹(x::'a) ∉#⇩z (M::'a zmultiset)›*) with assms (*‹zcount M x = 0 ⟹ False›*) show False by (simp add: not_in_iff_zmset (*‹(?x ∉#⇩z ?M) = (zcount ?M ?x = 0)›*)) qed lemma set_zmset_empty[simp]: "set_zmset {#}⇩z = {}" by (simp add: set_zmset_def (*‹set_zmset ?M = {x. zcount ?M x ≠ 0}›*)) lemma set_zmset_single: "set_zmset {#b#}⇩z = {b}" by (simp add: set_zmset_def (*‹set_zmset ?M = {x. zcount ?M x ≠ 0}›*)) lemma set_zmset_eq_empty_iff[simp]: "set_zmset M = {} ⟷ M = {#}⇩z" by (auto simp add: zmultiset_eq_iff (*‹((?M::?'a zmultiset) = (?N::?'a zmultiset)) = (∀a::?'a. zcount ?M a = zcount ?N a)›*) zcount_eq_zero_iff (*‹(zcount (?M::?'a zmultiset) (?x::?'a) = (0::int)) = (?x ∉#⇩z ?M)›*)) lemma finite_count_ne: "finite {x. count M x ≠ count N x}" proof (-) (*goal: ‹finite {x. count M x ≠ count N x}›*) have "{x. count M x ≠ count N x} ⊆ set_mset M ∪ set_mset N" by (auto simp: not_in_iff (*‹((?x::?'a) ∉# (?M::?'a multiset)) = (count ?M ?x = (0::nat))›*)) moreover have "finite (set_mset M ∪ set_mset N)" by (rule finite_UnI[OF finite_set_mset finite_set_mset] (*‹finite (set_mset ?M2 ∪ set_mset ?M1)›*)) ultimately show "?thesis" (*goal: ‹finite {x. count M x ≠ count N x}›*) by (rule finite_subset (*‹⟦?A ⊆ ?B; finite ?B⟧ ⟹ finite ?A›*)) qed lemma finite_set_zmset[iff]: "finite (set_zmset M)" unfolding set_zmset_def (*goal: ‹finite {x::'a. zcount (M::'a zmultiset) x ≠ (0::int)}›*) apply transfer (*goal: ‹finite {x. zcount M x ≠ 0}›*) by (auto intro: finite_count_ne (*‹finite {x. count ?M x ≠ count ?N x}›*)) lemma zmultiset_nonemptyE[elim]: assumes "A ≠ {#}⇩z" obtains x where "x ∈#⇩z A" proof (-) (*goal: ‹(⋀x::'a. x ∈#⇩z (A::'a zmultiset) ⟹ thesis::bool) ⟹ thesis›*) have "∃x. x ∈#⇩z A" apply (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹∃x. x ∈#⇩z A›*) apply (insert assms (*‹A ≠ {#}⇩z›*)) (*goal: ‹∄x::'a. x ∈#⇩z (A::'a zmultiset) ⟹ False›*) by auto with that (*‹?x ∈#⇩z A ⟹ thesis›*) show "?thesis" (*goal: ‹thesis›*) by blast qed subsubsection ‹Union› lemma zcount_union[simp]: "zcount (M + N) a = zcount M a + zcount N a" apply transfer (*goal: ‹zcount (M + N) a = zcount M a + zcount N a›*) by auto lemma union_add_left_zmset[simp]: "add_zmset a A + B = add_zmset a (A + B)" by (auto simp: zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*)) lemma union_zmset_add_zmset_right[simp]: "A + add_zmset a B = add_zmset a (A + B)" by (auto simp: zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*)) lemma add_zmset_add_single: ‹add_zmset a A = A + {#a#}⇩z› apply (subst union_zmset_add_zmset_right (*‹?A + add_zmset ?a ?B = add_zmset ?a (?A + ?B)›*)) (*goal: ‹add_zmset a A = A + {#a#}⇩z›*) apply (subst add.comm_neutral (*‹(?a::?'a) + (0::?'a) = ?a›*)) (*goal: ‹add_zmset (a::'a) (A::'a zmultiset) = add_zmset a (A + {#}⇩z)›*) by (rule refl (*‹?t = ?t›*)) subsubsection ‹Difference› lemma zcount_diff[simp]: "zcount (M - N) a = zcount M a - zcount N a" apply transfer (*goal: ‹zcount (M - N) a = zcount M a - zcount N a›*) by auto lemma add_zmset_diff_bothsides: ‹add_zmset a M - add_zmset a A = M - A› by (auto simp: zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*)) lemma in_diff_zcount: "a ∈#⇩z M - N ⟷ zcount N a ≠ zcount M a" by (fastforce simp: set_zmset_def (*‹set_zmset ?M = {x. zcount ?M x ≠ 0}›*)) lemma diff_add_zmset: fixes M N Q :: "'a zmultiset" shows "M - (N + Q) = M - N - Q" apply (rule sym (*‹?s = ?t ⟹ ?t = ?s›*)) (*goal: ‹M - (N + Q) = M - N - Q›*) by (fact diff_diff_add (*‹?a - ?b - ?c = ?a - (?b + ?c)›*)) lemma insert_Diff_zmset[simp]: "add_zmset x (M - {#x#}⇩z) = M" by (clarsimp simp: zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*)) lemma diff_union_swap_zmset: "add_zmset b (M - {#a#}⇩z) = add_zmset b M - {#a#}⇩z" by (auto simp add: zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*)) lemma diff_add_zmset_swap[simp]: "add_zmset b M - A = add_zmset b (M - A)" by (auto simp add: zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*)) lemma diff_diff_add_zmset[simp]: "(M :: 'a zmultiset) - N - P = M - (N + P)" by (rule diff_diff_add (*‹?a - ?b - ?c = ?a - (?b + ?c)›*)) lemma zmset_add[elim?]: obtains B where "A = add_zmset a B" proof (-) (*goal: ‹(⋀B. A = add_zmset a B ⟹ thesis) ⟹ thesis›*) have "A = add_zmset a (A - {#a#}⇩z)" by simp with that (*‹(A::'a::type zmultiset) = add_zmset (a::'a::type) (?B::'a::type zmultiset) ⟹ thesis::bool›*) show thesis . qed subsubsection ‹Equality of Signed Multisets› lemma single_eq_single_zmset[simp]: "{#a#}⇩z = {#b#}⇩z ⟷ a = b" by (auto simp add: zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*)) lemma multi_self_add_other_not_self_zmset[simp]: "M = add_zmset x M ⟷ False" by (auto simp add: zmultiset_eq_iff (*‹((?M::?'a zmultiset) = (?N::?'a zmultiset)) = (∀a::?'a. zcount ?M a = zcount ?N a)›*)) lemma add_zmset_remove_trivial: ‹add_zmset x M - {#x#}⇩z = M› by simp lemma diff_single_eq_union_zmset: "M - {#x#}⇩z = N ⟷ M = add_zmset x N" by auto lemma union_single_eq_diff_zmset: "add_zmset x M = N ⟹ M = N - {#x#}⇩z" unfolding add_zmset_add_single[of _ M] (*goal: ‹(M::'a::type zmultiset) + {#x::'a::type#}⇩z = (N::'a::type zmultiset) ⟹ M = N - {#x#}⇩z›*) by (fact add_implies_diff (*‹(?c::?'a) + (?b::?'a) = (?a::?'a) ⟹ ?c = ?a - ?b›*)) lemma add_zmset_eq_conv_diff: "add_zmset a M = add_zmset b N ⟷ M = N ∧ a = b ∨ M = add_zmset b (N - {#a#}⇩z) ∧ N = add_zmset a (M - {#b#}⇩z)" apply (simp add: zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*)) (*goal: ‹(add_zmset a M = add_zmset b N) = (M = N ∧ a = b ∨ M = add_zmset b (N - {#a#}⇩z) ∧ N = add_zmset a (M - {#b#}⇩z))›*) by fastforce lemma add_zmset_eq_conv_ex: "(add_zmset a M = add_zmset b N) = (M = N ∧ a = b ∨ (∃K. M = add_zmset b K ∧ N = add_zmset a K))" by (auto simp add: add_zmset_eq_conv_diff (*‹(add_zmset ?a ?M = add_zmset ?b ?N) = (?M = ?N ∧ ?a = ?b ∨ ?M = add_zmset ?b (?N - {#?a#}⇩z) ∧ ?N = add_zmset ?a (?M - {#?b#}⇩z))›*)) lemma multi_member_split: "∃A. M = add_zmset x A" apply (rule exI[where x = "M - {#x#}⇩z"] (*‹?P (M - {#x#}⇩z) ⟹ ∃x. ?P x›*)) (*goal: ‹∃A. M = add_zmset x A›*) by simp subsection ‹Conversions from and to Multisets› lift_definition zmset_of :: "'a multiset ⇒ 'a zmultiset" is "λf. (Abs_multiset f, {#})" . lemma zmset_of_inject[simp]: "zmset_of M = zmset_of N ⟷ M = N" apply (simp add: zmset_of_def (*‹zmset_of ≡ map_fun count abs_zmultiset (λf. (Abs_multiset f, {#}))›*)) (*goal: ‹(zmset_of (M::'a::type multiset) = zmset_of (N::'a::type multiset)) = (M = N)›*) apply transfer' (*goal: ‹(abs_zmultiset (M, {#}) = abs_zmultiset (N, {#})) = (M = N)›*) by (auto simp: equiv_zmset_def (*‹equiv_zmset = (λ(Mp, Mn) (Np, Nn). Mp + Nn = Np + Mn)›*)) lemma zmset_of_empty[simp]: "zmset_of {#} = {#}⇩z" by (simp add: zmset_of_def (*‹zmset_of ≡ map_fun count abs_zmultiset (λf::?'a::type ⇒ nat. (Abs_multiset f, {#}))›*) zero_zmultiset_def (*‹{#}⇩z ≡ abs_zmultiset ({#}, {#})›*)) lemma zmset_of_add_mset[simp]: "zmset_of (add_mset x M) = add_zmset x (zmset_of M)" apply transfer (*goal: ‹zmset_of (add_mset x M) = add_zmset x (zmset_of M)›*) by (auto simp: equiv_zmset_def (*‹equiv_zmset = (λ(Mp::?'a::type multiset, Mn::?'a::type multiset) (Np::?'a::type multiset, Nn::?'a::type multiset). Mp + Nn = Np + Mn)›*) add_mset_def (*‹add_mset ≡ map_fun id (map_fun count Abs_multiset) (λ(a::?'a::type) (M::?'a::type ⇒ nat) b::?'a::type. if b = a then Suc (M b) else M b)›*) cong: if_cong (*‹⟦(?b::bool) = (?c::bool); ?c ⟹ (?x::?'a::type) = (?u::?'a::type); ¬ ?c ⟹ (?y::?'a::type) = (?v::?'a::type)⟧ ⟹ (if ?b then ?x else ?y) = (if ?c then ?u else ?v)›*)) lemma zcount_of_mset[simp]: "zcount (zmset_of M) x = int (count M x)" apply (induct M) (*goals: 1. ‹zcount (zmset_of {#}) x = int (count {#} x)› 2. ‹⋀xa M. zcount (zmset_of M) x = int (count M x) ⟹ zcount (zmset_of (add_mset xa M)) x = int (count (add_mset xa M) x)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma zmset_of_plus: "zmset_of (M + N) = zmset_of M + zmset_of N" apply transfer (*goal: ‹zmset_of (M + N) = zmset_of M + zmset_of N›*) by (auto simp: equiv_zmset_def (*‹equiv_zmset = (λ(Mp::?'a::type multiset, Mn::?'a::type multiset) (Np::?'a::type multiset, Nn::?'a::type multiset). Mp + Nn = Np + Mn)›*) eq_onp_same_args (*‹eq_onp (?P::?'a::type ⇒ bool) (?x::?'a::type) ?x = ?P ?x›*) plus_multiset.abs_eq (*‹⟦eq_onp (λf::?'a::type ⇒ nat. finite {x::?'a::type. (0::nat) < f x}) (?xa::?'a::type ⇒ nat) ?xa; eq_onp (λf::?'a::type ⇒ nat. finite {x::?'a::type. (0::nat) < f x}) (?x::?'a::type ⇒ nat) ?x⟧ ⟹ Abs_multiset ?xa + Abs_multiset ?x = Abs_multiset (λa::?'a::type. ?xa a + ?x a)›*)) lift_definition mset_pos :: "'a zmultiset ⇒ 'a multiset" is "λ(Mp, Mn). count (Mp - Mn)" by (auto simp add: equiv_zmset_def simp flip: set_mset_diff) (metis add.commute add_diff_cancel_right) lift_definition mset_neg :: "'a zmultiset ⇒ 'a multiset" is "λ(Mp, Mn). count (Mn - Mp)" by (auto simp add: equiv_zmset_def simp flip: set_mset_diff) (metis add.commute add_diff_cancel_right) lemma zmset_of_inverse[simp]: "mset_pos (zmset_of M) = M" and minus_zmset_of_inverse[simp]: "mset_neg (- zmset_of M) = M" (*goals: 1. ‹mset_pos (zmset_of (M::'a multiset)) = M› 2. ‹mset_neg (- zmset_of (M::'a multiset)) = M› discuss goal 1*) apply transfer (*top goal: ‹mset_pos (zmset_of M) = M› and 1 goal remains*) apply simp (*discuss goal 2*) apply transfer (*goal: ‹mset_neg (- zmset_of M) = M›*) apply simp (*proven 2 subgoals*) . lemma neg_zmset_pos[simp]: "mset_neg (zmset_of M) = {#}" apply (rule zmset_of_inject[THEN iffD1] (*‹zmset_of ?M1 = zmset_of ?N1 ⟹ ?M1 = ?N1›*)) (*goal: ‹mset_neg (zmset_of M) = {#}›*) apply simp (*goal: ‹zmset_of (mset_neg (zmset_of M)) = zmset_of {#}›*) apply transfer (*goal: ‹zmset_of (mset_neg (zmset_of (M::'a::type multiset))) = {#}⇩z›*) by (auto simp: equiv_zmset_def (*‹equiv_zmset = (λ(Mp, Mn) (Np, Nn). Mp + Nn = Np + Mn)›*)) lemma count_mset_pos[simp]: "count (mset_pos M) x = nat (zcount M x)" and count_mset_neg[simp]: "count (mset_neg M) x = nat (- zcount M x)" (*goals: 1. ‹count (mset_pos (M::'a zmultiset)) (x::'a) = nat (zcount M x)› 2. ‹count (mset_neg (M::'a zmultiset)) (x::'a) = nat (- zcount M x)› discuss goal 1*) apply transfer (*top goal: ‹count (mset_pos M) x = nat (zcount M x)› and 1 goal remains*) apply auto (*discuss goal 2*) apply transfer (*goal: ‹count (mset_neg M) x = nat (- zcount M x)›*) apply auto (*proven 2 subgoals*) . lemma mset_pos_empty[simp]: "mset_pos {#}⇩z = {#}" and mset_neg_empty[simp]: "mset_neg {#}⇩z = {#}" (*goals: 1. ‹mset_pos {#}⇩z = {#}› 2. ‹mset_neg {#}⇩z = {#}› discuss goal 1*) apply (rule multiset_eqI (*‹(⋀x::?'a. count (?A::?'a multiset) x = count (?B::?'a multiset) x) ⟹ ?A = ?B›*)) (*top goal: ‹mset_pos {#}⇩z = {#}› and 1 goal remains*) apply simp (*discuss goal 2*) apply (rule multiset_eqI (*‹(⋀x::?'a::type. count (?A::?'a::type multiset) x = count (?B::?'a::type multiset) x) ⟹ ?A = ?B›*)) (*goal: ‹mset_neg {#}⇩z = {#}›*) apply simp (*proven 2 subgoals*) . lemma mset_pos_singleton[simp]: "mset_pos {#x#}⇩z = {#x#}" and mset_neg_singleton[simp]: "mset_neg {#x#}⇩z = {#}" (*goals: 1. ‹mset_pos {#x#}⇩z = {#x#}› 2. ‹mset_neg {#x#}⇩z = {#}› discuss goal 1*) apply (rule multiset_eqI (*‹(⋀x. count ?A x = count ?B x) ⟹ ?A = ?B›*)) (*top goal: ‹mset_pos {#x#}⇩z = {#x#}› and 1 goal remains*) apply simp (*discuss goal 2*) apply (rule multiset_eqI (*‹(⋀x::?'a. count (?A::?'a multiset) x = count (?B::?'a multiset) x) ⟹ ?A = ?B›*)) (*goal: ‹mset_neg {#x::'a#}⇩z = {#}›*) apply simp (*proven 2 subgoals*) . lemma mset_pos_neg_partition: "M = zmset_of (mset_pos M) - zmset_of (mset_neg M)" and mset_pos_as_neg: "zmset_of (mset_pos M) = zmset_of (mset_neg M) + M" and mset_neg_as_pos: "zmset_of (mset_neg M) = zmset_of (mset_pos M) - M" (*goals: 1. ‹(M::'a zmultiset) = zmset_of (mset_pos M) - zmset_of (mset_neg M)› 2. ‹zmset_of (mset_pos (M::'a zmultiset)) = zmset_of (mset_neg M) + M› 3. ‹zmset_of (mset_neg (M::'a zmultiset)) = zmset_of (mset_pos M) - M› discuss goal 1*) apply (rule zmultiset_eqI (*‹(⋀x. zcount ?A x = zcount ?B x) ⟹ ?A = ?B›*)) (*top goal: ‹(M::'a zmultiset) = zmset_of (mset_pos M) - zmset_of (mset_neg M)› and 2 goals remain*) apply simp (*discuss goal 2*) apply (rule zmultiset_eqI (*‹(⋀x. zcount ?A x = zcount ?B x) ⟹ ?A = ?B›*)) (*top goal: ‹zmset_of (mset_pos (M::'a::type zmultiset)) = zmset_of (mset_neg M) + M› and 1 goal remains*) apply simp (*discuss goal 3*) apply (rule zmultiset_eqI (*‹(⋀x. zcount ?A x = zcount ?B x) ⟹ ?A = ?B›*)) (*goal: ‹zmset_of (mset_neg M) = zmset_of (mset_pos M) - M›*) apply simp (*proven 3 subgoals*) . lemma mset_pos_uminus[simp]: "mset_pos (- A) = mset_neg A" apply (rule multiset_eqI (*‹(⋀x. count ?A x = count ?B x) ⟹ ?A = ?B›*)) (*goal: ‹mset_pos (- (A::'a zmultiset)) = mset_neg A›*) by simp lemma mset_neg_uminus[simp]: "mset_neg (- A) = mset_pos A" apply (rule multiset_eqI (*‹(⋀x. count ?A x = count ?B x) ⟹ ?A = ?B›*)) (*goal: ‹mset_neg (- (A::'a zmultiset)) = mset_pos A›*) by simp lemma mset_pos_plus[simp]: "mset_pos (A + B) = (mset_pos A - mset_neg B) + (mset_pos B - mset_neg A)" apply (rule multiset_eqI (*‹(⋀x::?'a. count (?A::?'a multiset) x = count (?B::?'a multiset) x) ⟹ ?A = ?B›*)) (*goal: ‹mset_pos (A + B) = mset_pos A - mset_neg B + (mset_pos B - mset_neg A)›*) by simp lemma mset_neg_plus[simp]: "mset_neg (A + B) = (mset_neg A - mset_pos B) + (mset_neg B - mset_pos A)" apply (rule multiset_eqI (*‹(⋀x. count ?A x = count ?B x) ⟹ ?A = ?B›*)) (*goal: ‹mset_neg (A + B) = mset_neg A - mset_pos B + (mset_neg B - mset_pos A)›*) by simp lemma mset_pos_diff[simp]: "mset_pos (A - B) = (mset_pos A - mset_pos B) + (mset_neg B - mset_neg A)" by (rule mset_pos_plus[of A "- B", simplified] (*‹mset_pos (A - B) = mset_pos A - mset_pos B + (mset_neg B - mset_neg A)›*)) lemma mset_neg_diff[simp]: "mset_neg (A - B) = (mset_neg A - mset_neg B) + (mset_pos B - mset_pos A)" by (rule mset_neg_plus[of A "- B", simplified] (*‹mset_neg (A - B) = mset_neg A - mset_neg B + (mset_pos B - mset_pos A)›*)) lemma mset_pos_neg_dual: "mset_pos a + mset_pos b + (mset_neg a - mset_pos b) + (mset_neg b - mset_pos a) = mset_neg a + mset_neg b + (mset_pos a - mset_neg b) + (mset_pos b - mset_neg a)" using [linarith_split_limit = 20] (*‹TERM _›*) apply (rule multiset_eqI (*‹(⋀x. count ?A x = count ?B x) ⟹ ?A = ?B›*)) (*goal: ‹mset_pos (a::'a zmultiset) + mset_pos (b::'a zmultiset) + (mset_neg a - mset_pos b) + (mset_neg b - mset_pos a) = mset_neg a + mset_neg b + (mset_pos a - mset_neg b) + (mset_pos b - mset_neg a)›*) by simp lemma decompose_zmset_of2: obtains A B C where "M = zmset_of A + C" and "N = zmset_of B + C" proof (standard) (*goals: 1. ‹(⋀A C B. ⟦M = zmset_of A + C; N = zmset_of B + C⟧ ⟹ thesis) ⟹ M = zmset_of ?A2 + ?C2› 2. ‹(⋀A C B. ⟦M = zmset_of A + C; N = zmset_of B + C⟧ ⟹ thesis) ⟹ N = zmset_of ?B2 + ?C2›*) let ?A = "zmset_of (mset_pos M + mset_neg N)" let ?B = "zmset_of (mset_pos N + mset_neg M)" let ?C = "- (zmset_of (mset_neg M) + zmset_of (mset_neg N))" show "M = ?A + ?C" by (simp add: zmset_of_plus (*‹zmset_of ((?M::?'a multiset) + (?N::?'a multiset)) = zmset_of ?M + zmset_of ?N›*) mset_pos_neg_partition (*‹(?M::?'a zmultiset) = zmset_of (mset_pos ?M) - zmset_of (mset_neg ?M)›*)) show "N = ?B + ?C" by (simp add: zmset_of_plus (*‹zmset_of (?M + ?N) = zmset_of ?M + zmset_of ?N›*) diff_add_zmset (*‹?M - (?N + ?Q) = ?M - ?N - ?Q›*) mset_pos_neg_partition (*‹?M = zmset_of (mset_pos ?M) - zmset_of (mset_neg ?M)›*)) qed subsubsection ‹Pointwise Ordering Induced by @{const zcount}› definition subseteq_zmset :: "'a zmultiset ⇒ 'a zmultiset ⇒ bool" (infix "⊆#⇩z" 50) where "A ⊆#⇩z B ⟷ (∀a. zcount A a ≤ zcount B a)" definition subset_zmset :: "'a zmultiset ⇒ 'a zmultiset ⇒ bool" (infix "⊂#⇩z" 50) where "A ⊂#⇩z B ⟷ A ⊆#⇩z B ∧ A ≠ B" abbreviation (input) supseteq_zmset :: "'a zmultiset ⇒ 'a zmultiset ⇒ bool" (infix "⊇#⇩z" 50) where "supseteq_zmset A B ≡ B ⊆#⇩z A" abbreviation (input) supset_zmset :: "'a zmultiset ⇒ 'a zmultiset ⇒ bool" (infix "⊃#⇩z" 50) where "supset_zmset A B ≡ B ⊂#⇩z A" notation (input) subseteq_zmset (infix "⊆#⇩z" 50) and supseteq_zmset (infix "⊇#⇩z" 50) notation (ASCII) subseteq_zmset (infix "⊆#⇩z" 50) and subset_zmset (infix "⊂#⇩z" 50) and supseteq_zmset (infix "⊇#⇩z" 50) and supset_zmset (infix ">#⇩z" 50) interpretation subset_zmset: ordered_ab_semigroup_add_imp_le "(+)" "(-)" "(⊆#⇩z)" "(⊂#⇩z)" apply unfold_locales (*goals: 1. ‹⋀x y. (x ⊂#⇩z y) = (x ⊆#⇩z y ∧ ¬ y ⊆#⇩z x)› 2. ‹⋀x. x ⊆#⇩z x› 3. ‹⋀x y z. ⟦x ⊆#⇩z y; y ⊆#⇩z z⟧ ⟹ x ⊆#⇩z z› 4. ‹⋀x y. ⟦x ⊆#⇩z y; y ⊆#⇩z x⟧ ⟹ x = y› 5. ‹⋀a b c. a ⊆#⇩z b ⟹ c + a ⊆#⇩z c + b› 6. ‹⋀c a b. c + a ⊆#⇩z c + b ⟹ a ⊆#⇩z b› discuss goal 1*) apply ((auto simp add: subset_zmset_def (*‹(?A ⊂#⇩z ?B) = (?A ⊆#⇩z ?B ∧ ?A ≠ ?B)›*) subseteq_zmset_def (*‹(?A ⊆#⇩z ?B) = (∀a. zcount ?A a ≤ zcount ?B a)›*) zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*) intro: order_trans (*‹⟦?x ≤ ?y; ?y ≤ ?z⟧ ⟹ ?x ≤ ?z›*) antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*))[1]) (*discuss goal 2*) apply ((auto simp add: subset_zmset_def (*‹(?A ⊂#⇩z ?B) = (?A ⊆#⇩z ?B ∧ ?A ≠ ?B)›*) subseteq_zmset_def (*‹(?A ⊆#⇩z ?B) = (∀a. zcount ?A a ≤ zcount ?B a)›*) zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*) intro: order_trans (*‹⟦?x ≤ ?y; ?y ≤ ?z⟧ ⟹ ?x ≤ ?z›*) antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*))[1]) (*discuss goal 3*) apply ((auto simp add: subset_zmset_def (*‹(?A ⊂#⇩z ?B) = (?A ⊆#⇩z ?B ∧ ?A ≠ ?B)›*) subseteq_zmset_def (*‹(?A ⊆#⇩z ?B) = (∀a. zcount ?A a ≤ zcount ?B a)›*) zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*) intro: order_trans (*‹⟦?x ≤ ?y; ?y ≤ ?z⟧ ⟹ ?x ≤ ?z›*) antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*))[1]) (*discuss goal 4*) apply ((auto simp add: subset_zmset_def (*‹(?A ⊂#⇩z ?B) = (?A ⊆#⇩z ?B ∧ ?A ≠ ?B)›*) subseteq_zmset_def (*‹(?A ⊆#⇩z ?B) = (∀a. zcount ?A a ≤ zcount ?B a)›*) zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*) intro: order_trans (*‹⟦?x ≤ ?y; ?y ≤ ?z⟧ ⟹ ?x ≤ ?z›*) antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*))[1]) (*discuss goal 5*) apply ((auto simp add: subset_zmset_def (*‹((?A::?'a::type zmultiset) ⊂#⇩z (?B::?'a::type zmultiset)) = (?A ⊆#⇩z ?B ∧ ?A ≠ ?B)›*) subseteq_zmset_def (*‹((?A::?'a::type zmultiset) ⊆#⇩z (?B::?'a::type zmultiset)) = (∀a::?'a::type. zcount ?A a ≤ zcount ?B a)›*) zmultiset_eq_iff (*‹((?M::?'a::type zmultiset) = (?N::?'a::type zmultiset)) = (∀a::?'a::type. zcount ?M a = zcount ?N a)›*) intro: order_trans (*‹⟦(?x::?'a::preorder) ≤ (?y::?'a::preorder); ?y ≤ (?z::?'a::preorder)⟧ ⟹ ?x ≤ ?z›*) antisym (*‹⟦(?a::?'a::order) ≤ (?b::?'a::order); ?b ≤ ?a⟧ ⟹ ?a = ?b›*))[1]) (*discuss goal 6*) apply ((auto simp add: subset_zmset_def (*‹(?A ⊂#⇩z ?B) = (?A ⊆#⇩z ?B ∧ ?A ≠ ?B)›*) subseteq_zmset_def (*‹(?A ⊆#⇩z ?B) = (∀a. zcount ?A a ≤ zcount ?B a)›*) zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*) intro: order_trans (*‹⟦?x ≤ ?y; ?y ≤ ?z⟧ ⟹ ?x ≤ ?z›*) antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*))[1]) (*proven 6 subgoals*) . interpretation subset_zmset: ordered_ab_semigroup_monoid_add_imp_le "(+)" 0 "(-)" "(⊆#⇩z)" "(⊂#⇩z)" by unfold_locales lemma zmset_subset_eqI: "(⋀a. zcount A a ≤ zcount B a) ⟹ A ⊆#⇩z B" by (simp add: subseteq_zmset_def (*‹(?A ⊆#⇩z ?B) = (∀a. zcount ?A a ≤ zcount ?B a)›*)) lemma zmset_subset_eq_zcount: "A ⊆#⇩z B ⟹ zcount A a ≤ zcount B a" by (simp add: subseteq_zmset_def (*‹(?A ⊆#⇩z ?B) = (∀a. zcount ?A a ≤ zcount ?B a)›*)) lemma zmset_subset_eq_add_zmset_cancel: ‹add_zmset a A ⊆#⇩z add_zmset a B ⟷ A ⊆#⇩z B› unfolding add_zmset_add_single[of _ A] add_zmset_add_single[of _ B] (*goal: ‹(A + {#a#}⇩z ⊆#⇩z B + {#a#}⇩z) = (A ⊆#⇩z B)›*) by (rule subset_zmset.add_le_cancel_right (*‹((?a::?'a zmultiset) + (?c::?'a zmultiset) ⊆#⇩z (?b::?'a zmultiset) + ?c) = (?a ⊆#⇩z ?b)›*)) lemma zmset_subset_eq_zmultiset_union_diff_commute: "A - B + C = A + C - B" for A B C :: "'a zmultiset" by (simp add: add.commute (*‹?a + ?b = ?b + ?a›*) add_diff_eq (*‹?a + (?b - ?c) = ?a + ?b - ?c›*)) lemma zmset_subset_eq_insertD: "add_zmset x A ⊆#⇩z B ⟹ A ⊂#⇩z B" unfolding subset_zmset_def subseteq_zmset_def (*goal: ‹∀a. zcount (add_zmset x A) a ≤ zcount B a ⟹ (∀a. zcount A a ≤ zcount B a) ∧ A ≠ B›*) by (metis (no_types) add.commute (*‹?a + ?b = ?b + ?a›*) add_le_same_cancel2 (*‹(?a + ?b ≤ ?b) = (?a ≤ 0)›*) zcount_add_zmset (*‹zcount (add_zmset ?b ?A) ?a = (if ?b = ?a then zcount ?A ?a + 1 else zcount ?A ?a)›*) dual_order.trans (*‹⟦?b ≤ ?a; ?c ≤ ?b⟧ ⟹ ?c ≤ ?a›*) le_cases (*‹⟦?x ≤ ?y ⟹ ?P; ?y ≤ ?x ⟹ ?P⟧ ⟹ ?P›*) le_numeral_extra( (*‹¬ 1 ≤ 0›*) 2)) lemma zmset_subset_insertD: "add_zmset x A ⊂#⇩z B ⟹ A ⊂#⇩z B" apply (rule zmset_subset_eq_insertD (*‹add_zmset ?x ?A ⊆#⇩z ?B ⟹ ?A ⊂#⇩z ?B›*)) (*goal: ‹add_zmset x A ⊂#⇩z B ⟹ A ⊂#⇩z B›*) by (rule subset_zmset.less_imp_le (*‹(?x::?'a zmultiset) ⊂#⇩z (?y::?'a zmultiset) ⟹ ?x ⊆#⇩z ?y›*)) lemma subset_eq_diff_conv_zmset: "A - C ⊆#⇩z B ⟷ A ⊆#⇩z B + C" by (simp add: subseteq_zmset_def (*‹(?A ⊆#⇩z ?B) = (∀a. zcount ?A a ≤ zcount ?B a)›*) ordered_ab_group_add_class.diff_le_eq (*‹(?a - ?b ≤ ?c) = (?a ≤ ?c + ?b)›*)) lemma multi_psub_of_add_self_zmset[simp]: "A ⊂#⇩z add_zmset x A" by (auto simp: subset_zmset_def (*‹(?A ⊂#⇩z ?B) = (?A ⊆#⇩z ?B ∧ ?A ≠ ?B)›*) subseteq_zmset_def (*‹(?A ⊆#⇩z ?B) = (∀a. zcount ?A a ≤ zcount ?B a)›*)) lemma multi_psub_self_zmset: "A ⊂#⇩z A = False" by simp lemma zmset_subset_add_zmset[simp]: "add_zmset x N ⊂#⇩z add_zmset x M ⟷ N ⊂#⇩z M" unfolding add_zmset_add_single[of _ N] add_zmset_add_single[of _ M] (*goal: ‹(N + {#x#}⇩z ⊂#⇩z M + {#x#}⇩z) = (N ⊂#⇩z M)›*) by (fact subset_zmset.add_less_cancel_right (*‹(?a + ?c ⊂#⇩z ?b + ?c) = (?a ⊂#⇩z ?b)›*)) lemma zmset_of_subseteq_iff[simp]: "zmset_of M ⊆#⇩z zmset_of N ⟷ M ⊆# N" by (simp add: subseteq_zmset_def (*‹(?A ⊆#⇩z ?B) = (∀a. zcount ?A a ≤ zcount ?B a)›*) subseteq_mset_def (*‹(?A ⊆# ?B) = (∀a. count ?A a ≤ count ?B a)›*)) lemma zmset_of_subset_iff[simp]: "zmset_of M ⊂#⇩z zmset_of N ⟷ M ⊂# N" by (simp add: subset_zmset_def (*‹(?A ⊂#⇩z ?B) = (?A ⊆#⇩z ?B ∧ ?A ≠ ?B)›*) subset_mset_def (*‹(?A ⊂# ?B) = (?A ⊆# ?B ∧ ?A ≠ ?B)›*)) lemma mset_pos_supset: "A ⊆#⇩z zmset_of (mset_pos A)" and mset_neg_supset: "- A ⊆#⇩z zmset_of (mset_neg A)" (*goals: 1. ‹A ⊆#⇩z zmset_of (mset_pos A)› 2. ‹- A ⊆#⇩z zmset_of (mset_neg A)› discuss goal 1*) apply ((auto intro: zmset_subset_eqI (*‹(⋀a::?'a::type. zcount (?A::?'a::type zmultiset) a ≤ zcount (?B::?'a::type zmultiset) a) ⟹ ?A ⊆#⇩z ?B›*))[1]) (*discuss goal 2*) apply ((auto intro: zmset_subset_eqI (*‹(⋀a. zcount ?A a ≤ zcount ?B a) ⟹ ?A ⊆#⇩z ?B›*))[1]) (*proven 2 subgoals*) . lemma subset_mset_zmsetE: assumes "M ⊂#⇩z N" obtains A B C where "M = zmset_of A + C" and "N = zmset_of B + C" and "A ⊂# B" by (metis assms (*‹M ⊂#⇩z N›*) decompose_zmset_of2 (*‹(⋀A B C. ⟦?M = zmset_of A + C; ?N = zmset_of B + C⟧ ⟹ ?thesis) ⟹ ?thesis›*) subset_zmset.add_less_cancel_right (*‹(?a + ?c ⊂#⇩z ?b + ?c) = (?a ⊂#⇩z ?b)›*) zmset_of_subset_iff (*‹(zmset_of ?M ⊂#⇩z zmset_of ?N) = (?M ⊂# ?N)›*)) lemma subseteq_mset_zmsetE: assumes "M ⊆#⇩z N" obtains A B C where "M = zmset_of A + C" and "N = zmset_of B + C" and "A ⊆# B" by (metis assms (*‹(M::'a zmultiset) ⊆#⇩z (N::'a zmultiset)›*) add.commute (*‹(?a::?'a) + (?b::?'a) = ?b + ?a›*) add.right_neutral (*‹(?a::?'a) + (0::?'a) = ?a›*) subset_mset.order_refl (*‹(?x::?'a multiset) ⊆# ?x›*) subset_mset_def (*‹((?A::?'a multiset) ⊂# (?B::?'a multiset)) = (?A ⊆# ?B ∧ ?A ≠ ?B)›*) subset_mset_zmsetE (*‹⟦(?M::?'a zmultiset) ⊂#⇩z (?N::?'a zmultiset); ⋀(A::?'a multiset) (B::?'a multiset) C::?'a zmultiset. ⟦?M = zmset_of A + C; ?N = zmset_of B + C; A ⊂# B⟧ ⟹ ?thesis::bool⟧ ⟹ ?thesis›*) subset_zmset_def (*‹((?A::?'a zmultiset) ⊂#⇩z (?B::?'a zmultiset)) = (?A ⊆#⇩z ?B ∧ ?A ≠ ?B)›*) zmset_of_empty (*‹zmset_of {#} = {#}⇩z›*)) subsubsection ‹Subset is an Order› interpretation subset_zmset: order "(⊆#⇩z)" "(⊂#⇩z)" by unfold_locales subsection ‹Replicate and Repeat Operations› definition replicate_zmset :: "nat ⇒ 'a ⇒ 'a zmultiset" where "replicate_zmset n x = (add_zmset x ^^ n) {#}⇩z" lemma replicate_zmset_0[simp]: "replicate_zmset 0 x = {#}⇩z" unfolding replicate_zmset_def (*goal: ‹(add_zmset x ^^ 0) {#}⇩z = {#}⇩z›*) by simp lemma replicate_zmset_Suc[simp]: "replicate_zmset (Suc n) x = add_zmset x (replicate_zmset n x)" unfolding replicate_zmset_def (*goal: ‹(add_zmset x ^^ Suc n) {#}⇩z = add_zmset x ((add_zmset x ^^ n) {#}⇩z)›*) apply (induct n) (*goals: 1. ‹(add_zmset x ^^ Suc 0) {#}⇩z = add_zmset x ((add_zmset x ^^ 0) {#}⇩z)› 2. ‹⋀n. (add_zmset x ^^ Suc n) {#}⇩z = add_zmset x ((add_zmset x ^^ n) {#}⇩z) ⟹ (add_zmset x ^^ Suc (Suc n)) {#}⇩z = add_zmset x ((add_zmset x ^^ Suc n) {#}⇩z)› discuss goal 1*) apply ((auto intro: add.commute (*‹?a + ?b = ?b + ?a›*))[1]) (*discuss goal 2*) apply ((auto intro: add.commute (*‹?a + ?b = ?b + ?a›*))[1]) (*proven 2 subgoals*) . lemma count_replicate_zmset[simp]: "zcount (replicate_zmset n x) y = (if y = x then of_nat n else 0)" unfolding replicate_zmset_def (*goal: ‹zcount ((add_zmset x ^^ n) {#}⇩z) y = (if y = x then int n else 0)›*) apply (induct n) (*goals: 1. ‹zcount ((add_zmset x ^^ 0) {#}⇩z) y = (if y = x then int 0 else 0)› 2. ‹⋀n. zcount ((add_zmset x ^^ n) {#}⇩z) y = (if y = x then int n else 0) ⟹ zcount ((add_zmset x ^^ Suc n) {#}⇩z) y = (if y = x then int (Suc n) else 0)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . fun repeat_zmset :: "nat ⇒ 'a zmultiset ⇒ 'a zmultiset" where "repeat_zmset 0 _ = {#}⇩z" | "repeat_zmset (Suc n) A = A + repeat_zmset n A" lemma count_repeat_zmset[simp]: "zcount (repeat_zmset i A) a = of_nat i * zcount A a" apply (induct i) (*goals: 1. ‹zcount (repeat_zmset (0::nat) (A::'a zmultiset)) (a::'a) = int (0::nat) * zcount A a› 2. ‹⋀i::nat. zcount (repeat_zmset i (A::'a zmultiset)) (a::'a) = int i * zcount A a ⟹ zcount (repeat_zmset (Suc i) A) a = int (Suc i) * zcount A a› discuss goal 1*) apply ((auto simp: semiring_normalization_rules( (*‹?m + ?a * ?m = (?a + 1) * ?m›*) 3))[1]) (*discuss goal 2*) apply ((auto simp: semiring_normalization_rules( (*‹?m + ?a * ?m = (?a + 1) * ?m›*) 3))[1]) (*proven 2 subgoals*) . lemma repeat_zmset_right[simp]: "repeat_zmset a (repeat_zmset b A) = repeat_zmset (a * b) A" by (auto simp: zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*) left_diff_distrib' (*‹(?b - ?c) * ?a = ?b * ?a - ?c * ?a›*)) lemma left_diff_repeat_zmset_distrib': ‹i ≥ j ⟹ repeat_zmset (i - j) u = repeat_zmset i u - repeat_zmset j u› by (auto simp: zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*) int_distrib( (*‹(?z1.0 - ?z2.0) * ?w = ?z1.0 * ?w - ?z2.0 * ?w›*) 3) of_nat_diff (*‹?n ≤ ?m ⟹ of_nat (?m - ?n) = of_nat ?m - of_nat ?n›*)) lemma left_add_mult_distrib_zmset: "repeat_zmset i u + (repeat_zmset j u + k) = repeat_zmset (i+j) u + k" by (auto simp: zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*) add_mult_distrib (*‹(?m + ?n) * ?k = ?m * ?k + ?n * ?k›*) int_distrib( (*‹(?z1.0 + ?z2.0) * ?w = ?z1.0 * ?w + ?z2.0 * ?w›*) 1)) lemma repeat_zmset_distrib: "repeat_zmset (m + n) A = repeat_zmset m A + repeat_zmset n A" by (auto simp: zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*) Nat.add_mult_distrib (*‹(?m + ?n) * ?k = ?m * ?k + ?n * ?k›*) int_distrib( (*‹(?z1.0 + ?z2.0) * ?w = ?z1.0 * ?w + ?z2.0 * ?w›*) 1)) lemma repeat_zmset_distrib2[simp]: "repeat_zmset n (A + B) = repeat_zmset n A + repeat_zmset n B" by (auto simp: zmultiset_eq_iff (*‹((?M::?'a zmultiset) = (?N::?'a zmultiset)) = (∀a::?'a. zcount ?M a = zcount ?N a)›*) add_mult_distrib2 (*‹(?k::nat) * ((?m::nat) + (?n::nat)) = ?k * ?m + ?k * ?n›*) int_distrib( (*‹(?w::int) * ((?z1.0::int) + (?z2.0::int)) = ?w * ?z1.0 + ?w * ?z2.0›*) 2)) lemma repeat_zmset_replicate_zmset[simp]: "repeat_zmset n {#a#}⇩z = replicate_zmset n a" by (auto simp: zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*)) lemma repeat_zmset_distrib_add_zmset[simp]: "repeat_zmset n (add_zmset a A) = replicate_zmset n a + repeat_zmset n A" by (auto simp: zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*) int_distrib( (*‹?w * (?z1.0 + ?z2.0) = ?w * ?z1.0 + ?w * ?z2.0›*) 2)) lemma repeat_zmset_empty[simp]: "repeat_zmset n {#}⇩z = {#}⇩z" apply (induct n) (*goals: 1. ‹repeat_zmset 0 {#}⇩z = {#}⇩z› 2. ‹⋀n. repeat_zmset n {#}⇩z = {#}⇩z ⟹ repeat_zmset (Suc n) {#}⇩z = {#}⇩z› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . subsubsection ‹Filter (with Comprehension Syntax)› lift_definition filter_zmset :: "('a ⇒ bool) ⇒ 'a zmultiset ⇒ 'a zmultiset" is "λP (Mp, Mn). (filter_mset P Mp, filter_mset P Mn)" by (auto simp del: filter_union_mset simp: equiv_zmset_def filter_union_mset[symmetric]) syntax (ASCII) "_ZMCollect" :: "pttrn ⇒ 'a zmultiset ⇒ bool ⇒ 'a zmultiset" ("(1{#_ :#z _./ _#})") syntax "_ZMCollect" :: "pttrn ⇒ 'a zmultiset ⇒ bool ⇒ 'a zmultiset" ("(1{#_ ∈#⇩z _./ _#})") translations "{#x ∈#⇩z M. P#}" == "CONST filter_zmset (λx. P) M" lemma count_filter_zmset[simp]: "zcount (filter_zmset P M) a = (if P a then zcount M a else 0)" apply transfer (*goal: ‹zcount (filter_zmset P M) a = (if P a then zcount M a else 0)›*) by auto lemma filter_empty_zmset[simp]: "filter_zmset P {#}⇩z = {#}⇩z" apply (rule zmultiset_eqI (*‹(⋀x. zcount ?A x = zcount ?B x) ⟹ ?A = ?B›*)) (*goal: ‹filter_zmset P {#}⇩z = {#}⇩z›*) by simp lemma filter_single_zmset: "filter_zmset P {#x#}⇩z = (if P x then {#x#}⇩z else {#}⇩z)" apply (rule zmultiset_eqI (*‹(⋀x. zcount ?A x = zcount ?B x) ⟹ ?A = ?B›*)) (*goal: ‹filter_zmset P {#x#}⇩z = (if P x then {#x#}⇩z else {#}⇩z)›*) by simp lemma filter_union_zmset[simp]: "filter_zmset P (M + N) = filter_zmset P M + filter_zmset P N" apply (rule zmultiset_eqI (*‹(⋀x::?'a. zcount (?A::?'a zmultiset) x = zcount (?B::?'a zmultiset) x) ⟹ ?A = ?B›*)) (*goal: ‹filter_zmset P (M + N) = filter_zmset P M + filter_zmset P N›*) by simp lemma filter_diff_zmset[simp]: "filter_zmset P (M - N) = filter_zmset P M - filter_zmset P N" apply (rule zmultiset_eqI (*‹(⋀x::?'a::type. zcount (?A::?'a::type zmultiset) x = zcount (?B::?'a::type zmultiset) x) ⟹ ?A = ?B›*)) (*goal: ‹filter_zmset P (M - N) = filter_zmset P M - filter_zmset P N›*) by simp lemma filter_add_zmset[simp]: "filter_zmset P (add_zmset x A) = (if P x then add_zmset x (filter_zmset P A) else filter_zmset P A)" by (auto simp: zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*)) lemma zmultiset_filter_mono: assumes "A ⊆#⇩z B" shows "filter_zmset f A ⊆#⇩z filter_zmset f B" using assms (*‹A ⊆#⇩z B›*) by (simp add: subseteq_zmset_def (*‹((?A::?'a zmultiset) ⊆#⇩z (?B::?'a zmultiset)) = (∀a::?'a. zcount ?A a ≤ zcount ?B a)›*)) lemma filter_filter_zmset: "filter_zmset P (filter_zmset Q M) = {#x ∈#⇩z M. Q x ∧ P x#}" by (auto simp: zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*)) lemma filter_zmset_True[simp]: "{#y ∈#⇩z M. True#} = M" and filter_zmset_False[simp]: "{#y ∈#⇩z M. False#} = {#}⇩z" (*goals: 1. ‹{#y::'a ∈#⇩z M::'a zmultiset. True#} = M› 2. ‹{#y::'a ∈#⇩z M::'a zmultiset. False#} = {#}⇩z› discuss goal 1*) apply ((auto simp: zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*))[1]) (*discuss goal 2*) apply ((auto simp: zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*))[1]) (*proven 2 subgoals*) . subsection ‹Uncategorized› lemma multi_drop_mem_not_eq_zmset: "B - {#c#}⇩z ≠ B" by (simp add: diff_single_eq_union_zmset (*‹(?M - {#?x#}⇩z = ?N) = (?M = add_zmset ?x ?N)›*)) lemma zmultiset_partition: "M = {#x ∈#⇩z M. P x #} + {#x ∈#⇩z M. ¬ P x#}" apply (subst zmultiset_eq_iff (*‹(?M = ?N) = (∀a. zcount ?M a = zcount ?N a)›*)) (*goal: ‹M = filter_zmset P M + {#x ∈#⇩z M. ¬ P x#}›*) by auto subsection ‹Image› definition image_zmset :: "('a ⇒ 'b) ⇒ 'a zmultiset ⇒ 'b zmultiset" where "image_zmset f M = zmset_of (fold_mset (add_mset ∘ f) {#} (mset_pos M)) - zmset_of (fold_mset (add_mset ∘ f) {#} (mset_neg M))" subsection ‹Multiset Order› instantiation zmultiset :: (preorder) order begin lift_definition less_zmultiset :: "'a zmultiset ⇒ 'a zmultiset ⇒ bool" is "λ(Mp, Mn) (Np, Nn). Mp + Nn < Mn + Np" proof (clarsimp simp: equiv_zmset_def) fix A1 B2 B1 A2 C1 D2 D1 C2 :: "'a multiset" assume ab: "A1 + A2 = B1 + B2" and cd: "C1 + C2 = D1 + D2" have "A1 + D2 < B2 + C1 ⟷ A1 + A2 + D2 < A2 + B2 + C1" by simp also have "… ⟷ B1 + B2 + D2 < A2 + B2 + C1" unfolding ab by (rule refl) also have "… ⟷ B1 + D2 < A2 + C1" by simp also have "… ⟷ B1 + D1 + D2 < A2 + C1 + D1" by simp also have "… ⟷ B1 + C1 + C2 < A2 + C1 + D1" using cd by (simp add: add.assoc) also have "… ⟷ B1 + C2 < A2 + D1" by simp finally show "A1 + D2 < B2 + C1 ⟷ B1 + C2 < A2 + D1" by assumption qed definition less_eq_zmultiset :: "'a zmultiset ⇒ 'a zmultiset ⇒ bool" where "less_eq_zmultiset M' M ⟷ M' < M ∨ M' = M" instance proof ((intro_classes; unfold less_eq_zmultiset_def; transfer), auto simp: equiv_zmset_def union_commute) fix A1 B1 D C B2 A2 :: "'a multiset" assume ab: "A1 + A2 ≠ B1 + B2" { assume ab1: "A1 + C < B1 + D" { assume ab2: "D + A2 < C + B2" show "A1 + A2 < B1 + B2" proof - have f1: "⋀m. D + A2 + m < C + B2 + m" using ab2 add_less_cancel_right by blast have "⋀m. C + (A1 + m) < D + (B1 + m)" by (simp add: ab1 add.commute) then have "D + (A2 + A1) < D + (B1 + B2)" using f1 by (metis add.assoc add.commute mset_le_trans) then show ?thesis by (simp add: add.commute) qed } { assume ab2: "D + A2 = C + B2" show "A1 + A2 < B1 + B2" proof - have "⋀m. C + A1 + m < D + B1 + m" by (simp add: ab1 add.commute) then have "D + (A2 + A1) < D + (B1 + B2)" by (metis (no_types) ab2 add.assoc add.commute) then show ?thesis by (simp add: add.commute) qed } } { assume ab1: "A1 + C = B1 + D" { assume ab2: "D + A2 < C + B2" show "A1 + A2 < B1 + B2" proof - have "A1 + (D + A2) < B1 + (D + B2)" by (metis (no_types) ab1 ab2 add.assoc add_less_cancel_left) then show ?thesis by simp qed } { assume ab2: "D + A2 = C + B2" have False by (metis (no_types) ab ab1 ab2 add.assoc add.commute add_diff_cancel_right') thus "A1 + A2 < B1 + B2" by sat } } qed end instance zmultiset :: (preorder) ordered_cancel_comm_monoid_add by (intro_classes, unfold less_eq_zmultiset_def, transfer, auto simp: equiv_zmset_def) instance zmultiset :: (preorder) ordered_ab_group_add by (intro_classes; transfer; auto simp: equiv_zmset_def) instantiation zmultiset :: (linorder) distrib_lattice begin definition inf_zmultiset :: "'a zmultiset ⇒ 'a zmultiset ⇒ 'a zmultiset" where "inf_zmultiset A B = (if A < B then A else B)" definition sup_zmultiset :: "'a zmultiset ⇒ 'a zmultiset ⇒ 'a zmultiset" where "sup_zmultiset A B = (if B > A then B else A)" lemma not_lt_iff_ge_zmset: "¬ x < y ⟷ x ≥ y" for x y :: "'a zmultiset" apply (unfold less_eq_zmultiset_def (*‹(?M' ≤ ?M) = (?M' < ?M ∨ ?M' = ?M)›*)) (*goal: ‹(¬ x < y) = (y ≤ x)›*) apply transfer (*goal: ‹(¬ x < y) = (y < x ∨ y = x)›*) by (auto simp: equiv_zmset_def (*‹equiv_zmset = (λ(Mp, Mn) (Np, Nn). Mp + Nn = Np + Mn)›*) algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 11 facts*)) instance by intro_classes (auto simp: less_eq_zmultiset_def inf_zmultiset_def sup_zmultiset_def dest!: not_lt_iff_ge_zmset[THEN iffD1]) end lemma zmset_of_less: "zmset_of M < zmset_of N ⟷ M < N" apply (clarsimp simp: zmset_of_def (*‹zmset_of ≡ map_fun count abs_zmultiset (λf. (Abs_multiset f, {#}))›*)) (*goal: ‹(zmset_of M < zmset_of N) = (M < N)›*) apply transfer' (*goal: ‹(abs_zmultiset (M, {#}) < abs_zmultiset (N, {#})) = (M < N)›*) by simp lemma zmset_of_le: "zmset_of M ≤ zmset_of N ⟷ M ≤ N" apply (simp add: less_eq_zmultiset_def (*‹((?M'::?'a zmultiset) ≤ (?M::?'a zmultiset)) = (?M' < ?M ∨ ?M' = ?M)›*) zmset_of_def (*‹zmset_of ≡ map_fun count abs_zmultiset (λf::?'a ⇒ nat. (Abs_multiset f, {#}))›*)) (*goal: ‹(zmset_of M ≤ zmset_of N) = (M ≤ N)›*) apply transfer' (*goal: ‹(abs_zmultiset (M, {#}) < abs_zmultiset (N, {#}) ∨ abs_zmultiset (M, {#}) = abs_zmultiset (N, {#})) = (M ≤ N)›*) by (auto simp: equiv_zmset_def (*‹equiv_zmset = (λ(Mp, Mn) (Np, Nn). Mp + Nn = Np + Mn)›*)) instance zmultiset :: (preorder) ordered_ab_semigroup_add by (intro_classes, unfold less_eq_zmultiset_def, transfer, auto simp: equiv_zmset_def) lemma uminus_add_conv_diff_mset[cancelation_simproc_pre]: ‹-a + b = b - a› for a :: ‹'a zmultiset› by (simp add: add.commute (*‹?a + ?b = ?b + ?a›*)) lemma uminus_add_add_uminus[cancelation_simproc_pre]: ‹b -a + c = b + c - a› for a :: ‹'a zmultiset› by (simp add: uminus_add_conv_diff_mset (*‹- ?a + ?b = ?b - ?a›*) zmset_subset_eq_zmultiset_union_diff_commute (*‹?A - ?B + ?C = ?A + ?C - ?B›*)) lemma add_zmset_eq_add_NO_MATCH[cancelation_simproc_pre]: ‹NO_MATCH {#}⇩z H ⟹ add_zmset a H = {#a#}⇩z + H› by auto lemma repeat_zmset_iterate_add: ‹repeat_zmset n M = iterate_add n M› unfolding iterate_add_def (*goal: ‹repeat_zmset n M = ((+) M ^^ n) {#}⇩z›*) apply (induction n) (*goals: 1. ‹repeat_zmset 0 M = ((+) M ^^ 0) {#}⇩z› 2. ‹⋀n. repeat_zmset n M = ((+) M ^^ n) {#}⇩z ⟹ repeat_zmset (Suc n) M = ((+) M ^^ Suc n) {#}⇩z› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . declare repeat_zmset_iterate_add[cancelation_simproc_pre] declare repeat_zmset_iterate_add[symmetric, cancelation_simproc_post] simproc_setup zmseteq_cancel_numerals ("(l::'a zmultiset) + m = n" | "(l::'a zmultiset) = m + n" | "add_zmset a m = n" | "m = add_zmset a n" | "replicate_zmset p a = n" | "m = replicate_zmset p a" | "repeat_zmset p m = n" | "m = repeat_zmset p m") = ‹fn phi => Cancel_Simprocs.eq_cancel› lemma zmset_subseteq_add_iff1: ‹j ≤ i ⟹ (repeat_zmset i u + m ⊆#⇩z repeat_zmset j u + n) = (repeat_zmset (i - j) u + m ⊆#⇩z n)› by (simp add: add.commute (*‹?a + ?b = ?b + ?a›*) add_diff_eq (*‹?a + (?b - ?c) = ?a + ?b - ?c›*) left_diff_repeat_zmset_distrib' (*‹?j ≤ ?i ⟹ repeat_zmset (?i - ?j) ?u = repeat_zmset ?i ?u - repeat_zmset ?j ?u›*) subset_eq_diff_conv_zmset (*‹(?A - ?C ⊆#⇩z ?B) = (?A ⊆#⇩z ?B + ?C)›*)) lemma zmset_subseteq_add_iff2: ‹i ≤ j ⟹ (repeat_zmset i u + m ⊆#⇩z repeat_zmset j u + n) = (m ⊆#⇩z repeat_zmset (j - i) u + n)› proof (-) (*goal: ‹(i::nat) ≤ (j::nat) ⟹ (repeat_zmset i (u::'a::type zmultiset) + (m::'a::type zmultiset) ⊆#⇩z repeat_zmset j u + (n::'a::type zmultiset)) = (m ⊆#⇩z repeat_zmset (j - i) u + n)›*) assume "i ≤ j" (*‹(i::nat) ≤ (j::nat)›*) then have "⋀z. repeat_zmset j (z::'a zmultiset) - repeat_zmset i z = repeat_zmset (j - i) z" by (simp add: left_diff_repeat_zmset_distrib' (*‹?j ≤ ?i ⟹ repeat_zmset (?i - ?j) ?u = repeat_zmset ?i ?u - repeat_zmset ?j ?u›*)) then show "?thesis" (*goal: ‹(repeat_zmset i u + m ⊆#⇩z repeat_zmset j u + n) = (m ⊆#⇩z repeat_zmset (j - i) u + n)›*) by (metis add.commute (*‹?a + ?b = ?b + ?a›*) diff_diff_eq2 (*‹?a - (?b - ?c) = ?a + ?c - ?b›*) subset_eq_diff_conv_zmset (*‹(?A - ?C ⊆#⇩z ?B) = (?A ⊆#⇩z ?B + ?C)›*)) qed lemma zmset_subset_add_iff1: ‹j ≤ i ⟹ (repeat_zmset i u + m ⊂#⇩z repeat_zmset j u + n) = (repeat_zmset (i - j) u + m ⊂#⇩z n)› by (simp add: subset_zmset.less_le_not_le (*‹(?x ⊂#⇩z ?y) = (?x ⊆#⇩z ?y ∧ ¬ ?y ⊆#⇩z ?x)›*) zmset_subseteq_add_iff1 (*‹?j ≤ ?i ⟹ (repeat_zmset ?i ?u + ?m ⊆#⇩z repeat_zmset ?j ?u + ?n) = (repeat_zmset (?i - ?j) ?u + ?m ⊆#⇩z ?n)›*) zmset_subseteq_add_iff2 (*‹?i ≤ ?j ⟹ (repeat_zmset ?i ?u + ?m ⊆#⇩z repeat_zmset ?j ?u + ?n) = (?m ⊆#⇩z repeat_zmset (?j - ?i) ?u + ?n)›*)) lemma zmset_subset_add_iff2: ‹i ≤ j ⟹ (repeat_zmset i u + m ⊂#⇩z repeat_zmset j u + n) = (m ⊂#⇩z repeat_zmset (j - i) u + n)› by (simp add: subset_zmset.less_le_not_le (*‹(?x ⊂#⇩z ?y) = (?x ⊆#⇩z ?y ∧ ¬ ?y ⊆#⇩z ?x)›*) zmset_subseteq_add_iff1 (*‹?j ≤ ?i ⟹ (repeat_zmset ?i ?u + ?m ⊆#⇩z repeat_zmset ?j ?u + ?n) = (repeat_zmset (?i - ?j) ?u + ?m ⊆#⇩z ?n)›*) zmset_subseteq_add_iff2 (*‹?i ≤ ?j ⟹ (repeat_zmset ?i ?u + ?m ⊆#⇩z repeat_zmset ?j ?u + ?n) = (?m ⊆#⇩z repeat_zmset (?j - ?i) ?u + ?n)›*)) ML_file ‹zmultiset_simprocs.ML› simproc_setup zmsetsubset_cancel ("(l::'a zmultiset) + m ⊂#⇩z n" | "(l::'a zmultiset) ⊂#⇩z m + n" | "add_zmset a m ⊂#⇩z n" | "m ⊂#⇩z add_zmset a n" | "replicate_zmset p a ⊂#⇩z n" | "m ⊂#⇩z replicate_zmset p a" | "repeat_zmset p m ⊂#⇩z n" | "m ⊂#⇩z repeat_zmset p m") = ‹fn phi => ZMultiset_Simprocs.subset_cancel_zmsets› simproc_setup zmsetsubseteq_cancel ("(l::'a zmultiset) + m ⊆#⇩z n" | "(l::'a zmultiset) ⊆#⇩z m + n" | "add_zmset a m ⊆#⇩z n" | "m ⊆#⇩z add_zmset a n" | "replicate_zmset p a ⊆#⇩z n" | "m ⊆#⇩z replicate_zmset p a" | "repeat_zmset p m ⊆#⇩z n" | "m ⊆#⇩z repeat_zmset p m") = ‹fn phi => ZMultiset_Simprocs.subseteq_cancel_zmsets› instance zmultiset :: (preorder) ordered_ab_semigroup_add_imp_le by (intro_classes; unfold less_eq_zmultiset_def; transfer; auto) simproc_setup zmsetless_cancel ("(l::'a::preorder zmultiset) + m < n" | "(l::'a zmultiset) < m + n" | "add_zmset a m < n" | "m < add_zmset a n" | "replicate_zmset p a < n" | "m < replicate_zmset p a" | "repeat_zmset p m < n" | "m < repeat_zmset p m") = ‹fn phi => Cancel_Simprocs.less_cancel› simproc_setup zmsetless_eq_cancel ("(l::'a::preorder zmultiset) + m ≤ n" | "(l::'a zmultiset) ≤ m + n" | "add_zmset a m ≤ n" | "m ≤ add_zmset a n" | "replicate_zmset p a ≤ n" | "m ≤ replicate_zmset p a" | "repeat_zmset p m ≤ n" | "m ≤ repeat_zmset p m") = ‹fn phi => Cancel_Simprocs.less_eq_cancel› simproc_setup zmsetdiff_cancel ("n + (l::'a zmultiset)" | "(l::'a zmultiset) - m" | "add_zmset a m - n" | "m - add_zmset a n" | "replicate_zmset p r - n" | "m - replicate_zmset p r" | "repeat_zmset p m - n" | "m - repeat_zmset p m") = ‹fn phi => Cancel_Simprocs.diff_cancel› instance zmultiset :: (linorder) linordered_cancel_ab_semigroup_add by (intro_classes, unfold less_eq_zmultiset_def, transfer, auto simp: equiv_zmset_def add.commute) lemma less_mset_zmsetE: assumes "M < N" obtains A B C where "M = zmset_of A + C" and "N = zmset_of B + C" and "A < B" by (metis add_less_imp_less_right (*‹?a + ?c < ?b + ?c ⟹ ?a < ?b›*) assms (*‹M < N›*) decompose_zmset_of2 (*‹(⋀A B C. ⟦?M = zmset_of A + C; ?N = zmset_of B + C⟧ ⟹ ?thesis) ⟹ ?thesis›*) zmset_of_less (*‹(zmset_of ?M < zmset_of ?N) = (?M < ?N)›*)) lemma less_eq_mset_zmsetE: assumes "M ≤ N" obtains A B C where "M = zmset_of A + C" and "N = zmset_of B + C" and "A ≤ B" by (metis add.commute (*‹?a + ?b = ?b + ?a›*) add.right_neutral (*‹?a + 0 = ?a›*) assms (*‹M ≤ N›*) le_neq_trans (*‹⟦?a ≤ ?b; ?a ≠ ?b⟧ ⟹ ?a < ?b›*) less_imp_le (*‹?x < ?y ⟹ ?x ≤ ?y›*) less_mset_zmsetE (*‹⟦?M < ?N; ⋀A B C. ⟦?M = zmset_of A + C; ?N = zmset_of B + C; A < B⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) order_refl (*‹?x ≤ ?x›*) zmset_of_empty (*‹zmset_of {#} = {#}⇩z›*)) lemma subset_eq_imp_le_zmset: "M ⊆#⇩z N ⟹ M ≤ N" by (metis (no_types) add_mono_thms_linordered_semiring( (*‹?i ≤ ?j ∧ ?k = ?l ⟹ ?i + ?k ≤ ?j + ?l›*) 3) subset_eq_imp_le_multiset (*‹?M ⊆# ?N ⟹ ?M ≤ ?N›*) subseteq_mset_zmsetE (*‹⟦?M ⊆#⇩z ?N; ⋀A B C. ⟦?M = zmset_of A + C; ?N = zmset_of B + C; A ⊆# B⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) zmset_of_le (*‹(zmset_of ?M ≤ zmset_of ?N) = (?M ≤ ?N)›*)) lemma subset_imp_less_zmset: "M ⊂#⇩z N ⟹ M < N" by (metis le_neq_trans (*‹⟦?a ≤ ?b; ?a ≠ ?b⟧ ⟹ ?a < ?b›*) subset_eq_imp_le_zmset (*‹?M ⊆#⇩z ?N ⟹ ?M ≤ ?N›*) subset_zmset_def (*‹(?A ⊂#⇩z ?B) = (?A ⊆#⇩z ?B ∧ ?A ≠ ?B)›*)) lemma lt_imp_ex_zcount_lt: assumes m_lt_n: "M < N" shows "∃y. zcount M y < zcount N y" apply (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹∃y. zcount M y < zcount N y›*) proof (clarsimp) (*goal: ‹∀y. ¬ zcount M y < zcount N y ⟹ False›*) assume "∀y. ¬ zcount M y < zcount N y" (*‹∀y::'a. ¬ zcount (M::'a zmultiset) y < zcount (N::'a zmultiset) y›*) hence "∀y. zcount M y ≥ zcount N y" by (simp add: leI (*‹¬ ?x < ?y ⟹ ?y ≤ ?x›*)) hence "M ⊇#⇩z N" by (simp add: zmset_subset_eqI (*‹(⋀a. zcount ?A a ≤ zcount ?B a) ⟹ ?A ⊆#⇩z ?B›*)) hence "M ≥ N" by (simp add: subset_eq_imp_le_zmset (*‹?M ⊆#⇩z ?N ⟹ ?M ≤ ?N›*)) thus False using m_lt_n (*‹M < N›*) by simp qed instance zmultiset :: (preorder) no_top proof fix M :: ‹'a zmultiset› obtain a :: 'a where True by fast let ?M = ‹zmset_of (mset_pos M) + zmset_of (mset_neg M)› have ‹M < add_zmset a ?M + ?M› by (subst mset_pos_neg_partition) (auto simp: subset_zmset_def subseteq_zmset_def zmultiset_eq_iff intro!: subset_imp_less_zmset) then show ‹∃N. M < N› by blast qed lifting_update multiset.lifting lifting_forget multiset.lifting end
{ "path": "afp-2025-02-12/thys/Nested_Multisets_Ordinals/Signed_Multiset.thy", "repo": "afp-2025-02-12", "sha": "98fc4666e08c33288fdfdbdcb7d2aa4029cb0ab8974d89c96fbb67a41b2b732f" }
(* Author: Tobias Nipkow *) subsection "Parity Analysis" theory Abs_Int1_parity imports Abs_Int1 begin datatype parity = Even | Odd | Either text‹Instantiation of class \<^class>‹order› with type \<^typ>‹parity›:› instantiation parity :: order begin text‹First the definition of the interface function ‹≤›. Note that the header of the definition must refer to the ascii name \<^const>‹less_eq› of the constants as ‹less_eq_parity› and the definition is named ‹less_eq_parity_def›. Inside the definition the symbolic names can be used.› definition less_eq_parity where "x ≤ y = (y = Either ∨ x=y)" text‹We also need ‹<›, which is defined canonically:› definition less_parity where "x < y = (x ≤ y ∧ ¬ y ≤ (x::parity))" text‹\noindent(The type annotation is necessary to fix the type of the polymorphic predicates.) Now the instance proof, i.e.\ the proof that the definition fulfills the axioms (assumptions) of the class. The initial proof-step generates the necessary proof obligations.› instance proof fix x::parity show "x ≤ x" by(auto simp: less_eq_parity_def) next fix x y z :: parity assume "x ≤ y" "y ≤ z" thus "x ≤ z" by(auto simp: less_eq_parity_def) next fix x y :: parity assume "x ≤ y" "y ≤ x" thus "x = y" by(auto simp: less_eq_parity_def) next fix x y :: parity show "(x < y) = (x ≤ y ∧ ¬ y ≤ x)" by(rule less_parity_def) qed end text‹Instantiation of class \<^class>‹semilattice_sup_top› with type \<^typ>‹parity›:› instantiation parity :: semilattice_sup_top begin definition sup_parity where "x ⊔ y = (if x = y then x else Either)" definition top_parity where "⊤ = Either" text‹Now the instance proof. This time we take a shortcut with the help of proof method ‹goal_cases›: it creates cases 1 ... n for the subgoals 1 ... n; in case i, i is also the name of the assumptions of subgoal i and ‹case?› refers to the conclusion of subgoal i. The class axioms are presented in the same order as in the class definition.› instance proof (standard, goal_cases) case 1 (*sup1*) show ?case by(auto simp: less_eq_parity_def sup_parity_def) next case 2 (*sup2*) show ?case by(auto simp: less_eq_parity_def sup_parity_def) next case 3 (*sup least*) thus ?case by(auto simp: less_eq_parity_def sup_parity_def) next case 4 (*top*) show ?case by(auto simp: less_eq_parity_def top_parity_def) qed end text‹Now we define the functions used for instantiating the abstract interpretation locales. Note that the Isabelle terminology is \emph{interpretation}, not \emph{instantiation} of locales, but we use instantiation to avoid confusion with abstract interpretation.› fun γ_parity :: "parity ⇒ val set" where "γ_parity Even = {i. i mod 2 = 0}" | "γ_parity Odd = {i. i mod 2 = 1}" | "γ_parity Either = UNIV" fun num_parity :: "val ⇒ parity" where "num_parity i = (if i mod 2 = 0 then Even else Odd)" fun plus_parity :: "parity ⇒ parity ⇒ parity" where "plus_parity Even Even = Even" | "plus_parity Odd Odd = Even" | "plus_parity Even Odd = Odd" | "plus_parity Odd Even = Odd" | "plus_parity Either y = Either" | "plus_parity x Either = Either" text‹First we instantiate the abstract value interface and prove that the functions on type \<^typ>‹parity› have all the necessary properties:› global_interpretation Val_semilattice where γ = γ_parity and num' = num_parity and plus' = plus_parity proof (standard, goal_cases) (*goals: 1. ‹⋀a b. a ≤ b ⟹ γ_parity a ⊆ γ_parity b› 2. ‹γ_parity ⊤ = UNIV› 3. ‹⋀i. i ∈ γ_parity (num_parity i)› 4. ‹⋀i1 a1 i2 a2. ⟦i1 ∈ γ_parity a1; i2 ∈ γ_parity a2⟧ ⟹ i1 + i2 ∈ γ_parity (plus_parity a1 a2)›*) txt‹subgoals are the locale axioms› case 1 (*‹a_ ≤ b_›*) thus "?case" (*goal: ‹γ_parity a_ ⊆ γ_parity b_›*) by (auto simp: less_eq_parity_def (*‹(?x ≤ ?y) = (?y = Either ∨ ?x = ?y)›*)) next (*goals: 1. ‹γ_parity ⊤ = UNIV› 2. ‹⋀i. i ∈ γ_parity (num_parity i)› 3. ‹⋀i1 a1 i2 a2. ⟦i1 ∈ γ_parity a1; i2 ∈ γ_parity a2⟧ ⟹ i1 + i2 ∈ γ_parity (plus_parity a1 a2)›*) case 2 (*no hyothesis introduced yet*) show "?case" (*goal: ‹γ_parity ⊤ = UNIV›*) by (auto simp: top_parity_def (*‹⊤ = Either›*)) next (*goals: 1. ‹⋀i. i ∈ γ_parity (num_parity i)› 2. ‹⋀i1 a1 i2 a2. ⟦i1 ∈ γ_parity a1; i2 ∈ γ_parity a2⟧ ⟹ i1 + i2 ∈ γ_parity (plus_parity a1 a2)›*) case 3 (*no hyothesis introduced yet*) show "?case" (*goal: ‹i_ ∈ γ_parity (num_parity i_)›*) by auto next (*goal: ‹⋀i1 a1 i2 a2. ⟦i1 ∈ γ_parity a1; i2 ∈ γ_parity a2⟧ ⟹ i1 + i2 ∈ γ_parity (plus_parity a1 a2)›*) case (4_ a1_ a2) (*‹i1_ ∈ γ_parity a1› ‹i2_ ∈ γ_parity a2›*) thus "?case" (*goal: ‹(i1_::int) + (i2_::int) ∈ γ_parity (plus_parity (a1::parity) (a2::parity))›*) apply (induction a1 a2 rule: plus_parity.induct (*‹⟦?P Even Even; ?P Odd Odd; ?P Even Odd; ?P Odd Even; ⋀y. ?P Either y; ?P Even Either; ?P Odd Either⟧ ⟹ ?P ?a0.0 ?a1.0›*)) (*goals: 1. ‹⟦i1_ ∈ γ_parity Even; i2_ ∈ γ_parity Even⟧ ⟹ i1_ + i2_ ∈ γ_parity (plus_parity Even Even)› 2. ‹⟦i1_ ∈ γ_parity Odd; i2_ ∈ γ_parity Odd⟧ ⟹ i1_ + i2_ ∈ γ_parity (plus_parity Odd Odd)› 3. ‹⟦i1_ ∈ γ_parity Even; i2_ ∈ γ_parity Odd⟧ ⟹ i1_ + i2_ ∈ γ_parity (plus_parity Even Odd)› 4. ‹⟦i1_ ∈ γ_parity Odd; i2_ ∈ γ_parity Even⟧ ⟹ i1_ + i2_ ∈ γ_parity (plus_parity Odd Even)› 5. ‹⋀y. ⟦i1_ ∈ γ_parity Either; i2_ ∈ γ_parity y⟧ ⟹ i1_ + i2_ ∈ γ_parity (plus_parity Either y)› 6. ‹⟦i1_ ∈ γ_parity Even; i2_ ∈ γ_parity Either⟧ ⟹ i1_ + i2_ ∈ γ_parity (plus_parity Even Either)› 7. ‹⟦i1_ ∈ γ_parity Odd; i2_ ∈ γ_parity Either⟧ ⟹ i1_ + i2_ ∈ γ_parity (plus_parity Odd Either)› discuss goal 1*) apply ((auto simp add: mod_add_eq [symmetric] (*‹(?a + ?b) mod ?c = (?a mod ?c + ?b mod ?c) mod ?c›*))[1]) (*discuss goal 2*) apply ((auto simp add: mod_add_eq [symmetric] (*‹(?a + ?b) mod ?c = (?a mod ?c + ?b mod ?c) mod ?c›*))[1]) (*discuss goal 3*) apply ((auto simp add: mod_add_eq [symmetric] (*‹((?a::?'a) + (?b::?'a)) mod (?c::?'a) = (?a mod ?c + ?b mod ?c) mod ?c›*))[1]) (*discuss goal 4*) apply ((auto simp add: mod_add_eq [symmetric] (*‹(?a + ?b) mod ?c = (?a mod ?c + ?b mod ?c) mod ?c›*))[1]) (*discuss goal 5*) apply ((auto simp add: mod_add_eq [symmetric] (*‹(?a + ?b) mod ?c = (?a mod ?c + ?b mod ?c) mod ?c›*))[1]) (*discuss goal 6*) apply ((auto simp add: mod_add_eq [symmetric] (*‹((?a::?'a::euclidean_semiring_cancel) + (?b::?'a::euclidean_semiring_cancel)) mod (?c::?'a::euclidean_semiring_cancel) = (?a mod ?c + ?b mod ?c) mod ?c›*))[1]) (*discuss goal 7*) apply ((auto simp add: mod_add_eq [symmetric] (*‹(?a + ?b) mod ?c = (?a mod ?c + ?b mod ?c) mod ?c›*))[1]) (*proven 7 subgoals*) . qed text‹In case 4 we needed to refer to particular variables. Writing (i x y z) fixes the names of the variables in case i to be x, y and z in the left-to-right order in which the variables occur in the subgoal. Underscores are anonymous placeholders for variable names we don't care to fix.› text‹Instantiating the abstract interpretation locale requires no more proofs (they happened in the instatiation above) but delivers the instantiated abstract interpreter which we call ‹AI_parity›:› global_interpretation Abs_Int where γ = γ_parity and num' = num_parity and plus' = plus_parity defines aval_parity = aval' and step_parity = step' and AI_parity = AI by standard subsubsection "Tests" definition "test1_parity = ''x'' ::= N 1;; WHILE Less (V ''x'') (N 100) DO ''x'' ::= Plus (V ''x'') (N 2)" value "show_acom (the(AI_parity test1_parity))" definition "test2_parity = ''x'' ::= N 1;; WHILE Less (V ''x'') (N 100) DO ''x'' ::= Plus (V ''x'') (N 3)" definition "steps c i = ((step_parity ⊤) ^^ i) (bot c)" value "show_acom (steps test2_parity 0)" value "show_acom (steps test2_parity 1)" value "show_acom (steps test2_parity 2)" value "show_acom (steps test2_parity 3)" value "show_acom (steps test2_parity 4)" value "show_acom (steps test2_parity 5)" value "show_acom (steps test2_parity 6)" value "show_acom (the(AI_parity test2_parity))" subsubsection "Termination" global_interpretation Abs_Int_mono where γ = γ_parity and num' = num_parity and plus' = plus_parity apply standard (*goal: ‹Abs_Int_mono num_parity plus_parity γ_parity›*) proof (goal_cases) (*goal: ‹⋀(a1::parity) (b1::parity) (a2::parity) b2::parity. ⟦a1 ≤ b1; a2 ≤ b2⟧ ⟹ plus_parity a1 a2 ≤ plus_parity b1 b2›*) case (1_ a1_ a2) (*‹a1_ ≤ a1› ‹(a2_::parity) ≤ (a2::parity)›*) thus "?case" (*goal: ‹plus_parity (a1_::parity) (a2_::parity) ≤ plus_parity (a1::parity) (a2::parity)›*) apply (induction a1 a2 rule: plus_parity.induct (*‹⟦?P Even Even; ?P Odd Odd; ?P Even Odd; ?P Odd Even; ⋀y. ?P Either y; ?P Even Either; ?P Odd Either⟧ ⟹ ?P ?a0.0 ?a1.0›*)) (*goals: 1. ‹⟦a1_ ≤ Even; a2_ ≤ Even⟧ ⟹ plus_parity a1_ a2_ ≤ plus_parity Even Even› 2. ‹⟦a1_ ≤ Odd; a2_ ≤ Odd⟧ ⟹ plus_parity a1_ a2_ ≤ plus_parity Odd Odd› 3. ‹⟦a1_ ≤ Even; a2_ ≤ Odd⟧ ⟹ plus_parity a1_ a2_ ≤ plus_parity Even Odd› 4. ‹⟦a1_ ≤ Odd; a2_ ≤ Even⟧ ⟹ plus_parity a1_ a2_ ≤ plus_parity Odd Even› 5. ‹⋀y. ⟦a1_ ≤ Either; a2_ ≤ y⟧ ⟹ plus_parity a1_ a2_ ≤ plus_parity Either y› 6. ‹⟦a1_ ≤ Even; a2_ ≤ Either⟧ ⟹ plus_parity a1_ a2_ ≤ plus_parity Even Either› 7. ‹⟦a1_ ≤ Odd; a2_ ≤ Either⟧ ⟹ plus_parity a1_ a2_ ≤ plus_parity Odd Either› discuss goal 1*) apply ((auto simp add:less_eq_parity_def (*‹((?x::parity) ≤ (?y::parity)) = (?y = Either ∨ ?x = ?y)›*))[1]) (*discuss goal 2*) apply ((auto simp add:less_eq_parity_def (*‹(?x ≤ ?y) = (?y = Either ∨ ?x = ?y)›*))[1]) (*discuss goal 3*) apply ((auto simp add:less_eq_parity_def (*‹(?x ≤ ?y) = (?y = Either ∨ ?x = ?y)›*))[1]) (*discuss goal 4*) apply ((auto simp add:less_eq_parity_def (*‹(?x ≤ ?y) = (?y = Either ∨ ?x = ?y)›*))[1]) (*discuss goal 5*) apply ((auto simp add:less_eq_parity_def (*‹(?x ≤ ?y) = (?y = Either ∨ ?x = ?y)›*))[1]) (*discuss goal 6*) apply ((auto simp add:less_eq_parity_def (*‹((?x::parity) ≤ (?y::parity)) = (?y = Either ∨ ?x = ?y)›*))[1]) (*discuss goal 7*) apply ((auto simp add:less_eq_parity_def (*‹(?x ≤ ?y) = (?y = Either ∨ ?x = ?y)›*))[1]) (*proven 7 subgoals*) . qed definition m_parity :: "parity ⇒ nat" where "m_parity x = (if x = Either then 0 else 1)" global_interpretation Abs_Int_measure where γ = γ_parity and num' = num_parity and plus' = plus_parity and m = m_parity and h = "1" proof (standard, goal_cases) (*goals: 1. ‹⋀x. m_parity x ≤ 1› 2. ‹⋀x y. x < y ⟹ m_parity y < m_parity x›*) case 1 (*no hyothesis introduced yet*) thus "?case" (*goal: ‹m_parity x_ ≤ 1›*) by (auto simp add: m_parity_def (*‹m_parity ?x = (if ?x = Either then 0 else 1)›*) less_eq_parity_def (*‹(?x ≤ ?y) = (?y = Either ∨ ?x = ?y)›*)) next (*goal: ‹⋀x y. x < y ⟹ m_parity y < m_parity x›*) case 2 (*‹x_ < y_›*) thus "?case" (*goal: ‹m_parity y_ < m_parity x_›*) by (auto simp add: m_parity_def (*‹m_parity ?x = (if ?x = Either then 0 else 1)›*) less_eq_parity_def (*‹(?x ≤ ?y) = (?y = Either ∨ ?x = ?y)›*) less_parity_def (*‹(?x < ?y) = (?x ≤ ?y ∧ ¬ ?y ≤ ?x)›*)) qed thm AI_Some_measure end
{ "path": "Isabelle2024/src/HOL/IMP/Abs_Int1_parity.thy", "repo": "Isabelle2024", "sha": "51944ece9ff9fcac35e55fa8f965f08d5e34fc9c379402f35e301690481457e2" }
section ‹Symbol sequence operations› theory Symbol_Ops imports Two_Four_Symbols begin text ‹ While previous sections have focused on ``formatted'' symbol sequences for numbers and lists, in this section we devise some Turing machines dealing with ``unstructured'' arbitrary symbol sequences. The only ``structure'' that is often imposed is that of not containing a blank symbol because when reading a symbol sequence, say from the input tape, a blank would signal the end of the symbol sequence. › subsection ‹Checking for being over an alphabet› text ‹ In this section we devise a Turing machine that checks if a proper symbol sequence is over a given alphabet represented by an upper bound symbol $z$. › abbreviation proper_symbols_lt :: "symbol ⇒ symbol list ⇒ bool" where "proper_symbols_lt z zs ≡ proper_symbols zs ∧ symbols_lt z zs" text ‹ The next Turing machine checks if the symbol sequence (up until the first blank) on tape $j_1$ contains only symbols from $\{2, \dots, z - 1\}$, where $z$ is a parameter of the TM, and writes to tape $j_2$ the number~1 or~0, representing True or False, respectively. It assumes that $j_2$ initially contains at most one symbol. › definition tm_proper_symbols_lt :: "tapeidx ⇒ tapeidx ⇒ symbol ⇒ machine" where "tm_proper_symbols_lt j1 j2 z ≡ tm_write j2 𝟭 ;; WHILE [] ; λrs. rs ! j1 ≠ □ DO IF λrs. rs ! j1 < 2 ∨ rs ! j1 ≥ z THEN tm_write j2 □ ELSE [] ENDIF ;; tm_right j1 DONE ;; tm_cr j1" lemma tm_proper_symbols_lt_tm: assumes "0 < j2" "j1 < k" "j2 < k" and "G ≥ 4" shows "turing_machine k G (tm_proper_symbols_lt j1 j2 z)" using assms (*‹0 < j2› ‹j1 < k› ‹(j2::nat) < (k::nat)› ‹4 ≤ G›*) tm_write_tm (*‹⟦(0::nat) < (?j::nat); ?j < (?k::nat); (?h::nat) < (?G::nat); (4::nat) ≤ ?G⟧ ⟹ turing_machine ?k ?G (tm_write ?j ?h)›*) tm_right_tm (*‹⟦2 ≤ ?k; 4 ≤ ?G⟧ ⟹ turing_machine ?k ?G (tm_right ?j)›*) tm_cr_tm (*‹⟦2 ≤ ?k; 4 ≤ ?G⟧ ⟹ turing_machine ?k ?G (tm_cr ?j)›*) Nil_tm (*‹⟦4 ≤ ?G; 2 ≤ ?k⟧ ⟹ turing_machine ?k ?G []›*) tm_proper_symbols_lt_def (*‹tm_proper_symbols_lt (?j1.0::nat) (?j2.0::nat) (?z::nat) ≡ tm_write ?j2.0 (3::nat) ;; WHILE [] ; λrs::nat list. rs ! ?j1.0 ≠ (0::nat) DO IF λrs::nat list. rs ! ?j1.0 < (2::nat) ∨ ?z ≤ rs ! ?j1.0 THEN tm_write ?j2.0 (0::nat) ELSE [] ENDIF ;; tm_right ?j1.0 DONE ;; tm_cr ?j1.0›*) turing_machine_loop_turing_machine (*‹⟦turing_machine ?k ?G ?M1.0; turing_machine ?k ?G ?M2.0⟧ ⟹ turing_machine ?k ?G (WHILE ?M1.0 ; ?cond DO ?M2.0 DONE)›*) turing_machine_branch_turing_machine (*‹⟦turing_machine ?k ?G ?M1.0; turing_machine ?k ?G ?M2.0⟧ ⟹ turing_machine ?k ?G (IF ?cond THEN ?M1.0 ELSE ?M2.0 ENDIF)›*) by simp locale turing_machine_proper_symbols_lt = fixes j1 j2 :: tapeidx and z :: symbol begin definition "tm1 ≡ tm_write j2 𝟭" definition "tm2 ≡ IF λrs. rs ! j1 < 2 ∨ rs ! j1 ≥ z THEN tm_write j2 □ ELSE [] ENDIF" definition "tm3 ≡ tm2 ;; tm_right j1" definition "tm4 ≡ WHILE [] ; λrs. rs ! j1 ≠ □ DO tm3 DONE" definition "tm5 ≡ tm1 ;; tm4" definition "tm6 ≡ tm5 ;; tm_cr j1" lemma tm6_eq_tm_proper_symbols_lt: "tm6 = tm_proper_symbols_lt j1 j2 z" unfolding tm6_def tm5_def tm4_def tm3_def tm2_def tm1_def tm_proper_symbols_lt_def (*goal: ‹tm_write j2 3 ;; WHILE [] ; λrs. rs ! j1 ≠ 0 DO IF λrs. rs ! j1 < 2 ∨ z ≤ rs ! j1 THEN tm_write j2 0 ELSE [] ENDIF ;; tm_right j1 DONE ;; tm_cr j1 = tm_write j2 3 ;; WHILE [] ; λrs. rs ! j1 ≠ 0 DO IF λrs. rs ! j1 < 2 ∨ z ≤ rs ! j1 THEN tm_write j2 0 ELSE [] ENDIF ;; tm_right j1 DONE ;; tm_cr j1›*) by simp context fixes zs :: "symbol list" and tps0 :: "tape list" and k :: nat assumes jk: "k = length tps0" "j1 ≠ j2" "j1 < k" "j2 < k" and zs: "proper_symbols zs" and tps0: "tps0 ! j1 = (⌊zs⌋, 1)" "tps0 ! j2 = (⌊[]⌋, 1)" begin definition "tps1 t ≡ tps0 [j1 := (⌊zs⌋, Suc t), j2 := (if proper_symbols_lt z (take t zs) then ⌊[𝟭]⌋ else ⌊[]⌋, 1)]" lemma tm1 [transforms_intros]: "transforms tm1 tps0 1 (tps1 0)" unfolding tm1_def (*goal: ‹transforms (tm_write j2 3) tps0 1 (tps1 0)›*) proof (tform tps: jk tps0) (*goal: ‹tps1 0 = tps0[j2 := tps0 ! j2 |:=| 3]›*) have "(if proper_symbols_lt z (take 0 zs) then ⌊[𝟭]⌋ else ⌊[]⌋, 1) = (⌊[𝟭]⌋, 1)" by simp moreover have "tps0 ! j2 |:=| 𝟭 = (⌊[𝟭]⌋, 1)" using tps0(2) (*‹tps0 ! j2 = (⌊[]⌋, 1)›*) contents_def (*‹⌊?xs⌋ ?i ≡ if ?i = 0 then 1 else if ?i ≤ length ?xs then ?xs ! (?i - 1) else 0›*) by auto moreover have "tps0[j1 := (⌊zs⌋, Suc 0)] = tps0" using tps0(1) (*‹tps0 ! j1 = (⌊zs⌋, 1)›*) by (metis One_nat_def (*‹1 = Suc 0›*) list_update_id (*‹?xs[?i := ?xs ! ?i] = ?xs›*)) ultimately show "tps1 0 = tps0[j2 := tps0 ! j2 |:=| 𝟭]" unfolding tps1_def (*goal: ‹tps0[j1 := (⌊zs⌋, Suc 0), j2 := (if (∀i<length (take 0 zs). Suc 0 < take 0 zs ! i) ∧ symbols_lt z (take 0 zs) then ⌊[3]⌋ else ⌊[]⌋, 1)] = tps0[j2 := tps0 ! j2 |:=| 3]›*) by auto qed definition "tps2 t ≡ tps0 [j1 := (⌊zs⌋, Suc t), j2 := (if proper_symbols_lt z (take (Suc t) zs) then ⌊[𝟭]⌋ else ⌊[]⌋, 1)]" lemma tm2 [transforms_intros]: assumes "t < length zs" shows "transforms tm2 (tps1 t) 3 (tps2 t)" unfolding tm2_def (*goal: ‹transforms (IF λrs. rs ! j1 < 2 ∨ z ≤ rs ! j1 THEN tm_write j2 0 ELSE [] ENDIF) (tps1 t) 3 (tps2 t)›*) proof (tform tps: jk tps1_def) (*goals: 1. ‹read (tps1 t) ! j1 < 2 ∨ z ≤ read (tps1 t) ! j1 ⟹ tps2 t = (tps1 t)[j2 := tps1 t ! j2 |:=| 0]› 2. ‹¬ (read (tps1 t) ! j1 < 2 ∨ z ≤ read (tps1 t) ! j1) ⟹ tps2 t = tps1 t›*) have "tps1 t ! j1 = (⌊zs⌋, Suc t)" using tps1_def (*‹tps1 ?t ≡ tps0[j1 := (⌊zs⌋, Suc ?t), j2 := (if (∀i<length (take ?t zs). Suc 0 < take ?t zs ! i) ∧ symbols_lt z (take ?t zs) then ⌊[3]⌋ else ⌊[]⌋, 1)]›*) jk (*‹k = length tps0› ‹j1 ≠ j2› ‹j1 < k› ‹j2 < k›*) by simp moreover have "read (tps1 t) ! j1 = tps1 t :.: j1" using tapes_at_read' (*‹?j < length ?tps ⟹ |.| (?tps ! ?j) = read ?tps ! ?j›*) jk (*‹k = length tps0› ‹j1 ≠ j2› ‹j1 < k› ‹j2 < k›*) tps1_def (*‹tps1 ?t ≡ tps0[j1 := (⌊zs⌋, Suc ?t), j2 := (if (∀i<length (take ?t zs). Suc 0 < take ?t zs ! i) ∧ symbols_lt z (take ?t zs) then ⌊[3]⌋ else ⌊[]⌋, 1)]›*) by (metis (no_types, lifting) length_list_update (*‹length (?xs[?i := ?x]) = length ?xs›*)) ultimately have "*": "read (tps1 t) ! j1 = zs ! t" using contents_inbounds (*‹⟦0 < ?i; ?i ≤ length ?zs⟧ ⟹ ⌊?zs⌋ ?i = ?zs ! (?i - 1)›*) assms(1) (*‹t < length zs›*) by simp have j2: "tps1 t ! j2 = (if proper_symbols_lt z (take t zs) then ⌊[𝟭]⌋ else ⌊[]⌋, 1)" using tps1_def (*‹tps1 (?t::nat) ≡ (tps0::((nat ⇒ nat) × nat) list)[j1::nat := (⌊zs::nat list⌋, Suc ?t), j2::nat := (if (∀i<length (take ?t zs). Suc (0::nat) < take ?t zs ! i) ∧ symbols_lt (z::nat) (take ?t zs) then ⌊[3::nat]⌋ else ⌊[]⌋, 1::nat)]›*) jk (*‹k = length tps0› ‹j1 ≠ j2› ‹j1 < k› ‹j2 < k›*) by simp show "tps2 t = (tps1 t)[j2 := tps1 t ! j2 |:=| □]" if "read (tps1 t) ! j1 < 2 ∨ z ≤ read (tps1 t) ! j1" proof (-) (*goal: ‹tps2 (t::nat) = (tps1 t)[j2::nat := tps1 t ! j2 |:=| (0::nat)]›*) have c3: "(⌊[𝟭]⌋, 1) |:=| □ = (⌊[]⌋, 1)" using contents_def (*‹⌊?xs⌋ ?i ≡ if ?i = 0 then 1 else if ?i ≤ length ?xs then ?xs ! (?i - 1) else 0›*) by auto have "(if proper_symbols_lt z (take t zs) then ⌊[𝟭]⌋ else ⌊[]⌋, 1) |:=| □ = (if proper_symbols_lt z (take (Suc t) zs) then ⌊[𝟭]⌋ else ⌊[]⌋, 1)" proof (cases "proper_symbols_lt z (take t zs)") (*goals: 1. ‹(∀i<length (take t zs). Suc 0 < take t zs ! i) ∧ symbols_lt z (take t zs) ⟹ (if (∀i<length (take t zs). Suc 0 < take t zs ! i) ∧ symbols_lt z (take t zs) then ⌊[3]⌋ else ⌊[]⌋, 1) |:=| 0 = (if (∀i<length (take (Suc t) zs). Suc 0 < take (Suc t) zs ! i) ∧ symbols_lt z (take (Suc t) zs) then ⌊[3]⌋ else ⌊[]⌋, 1)› 2. ‹¬ ((∀i<length (take t zs). Suc 0 < take t zs ! i) ∧ symbols_lt z (take t zs)) ⟹ (if (∀i<length (take t zs). Suc 0 < take t zs ! i) ∧ symbols_lt z (take t zs) then ⌊[3]⌋ else ⌊[]⌋, 1) |:=| 0 = (if (∀i<length (take (Suc t) zs). Suc 0 < take (Suc t) zs ! i) ∧ symbols_lt z (take (Suc t) zs) then ⌊[3]⌋ else ⌊[]⌋, 1)›*) case True (*‹(∀i<length (take t zs). Suc 0 < take t zs ! i) ∧ symbols_lt z (take t zs)›*) have "zs ! t < 2 ∨ z ≤ zs ! t" using that (*‹read (tps1 t) ! j1 < 2 ∨ z ≤ read (tps1 t) ! j1›*) "*" (*‹read (tps1 t) ! j1 = zs ! t›*) by simp then have "¬ proper_symbols_lt z (take (Suc t) zs)" using assms(1) (*‹t < length zs›*) by auto then show "?thesis" (*goal: ‹(if (∀i<length (take t zs). Suc 0 < take t zs ! i) ∧ symbols_lt z (take t zs) then ⌊[3]⌋ else ⌊[]⌋, 1) |:=| 0 = (if (∀i<length (take (Suc t) zs). Suc 0 < take (Suc t) zs ! i) ∧ symbols_lt z (take (Suc t) zs) then ⌊[3]⌋ else ⌊[]⌋, 1)›*) using c3 (*‹(⌊[3::nat]⌋, 1::nat) |:=| (0::nat) = (⌊[]⌋, 1::nat)›*) by auto next (*goal: ‹¬ ((∀i<length (take t zs). Suc 0 < take t zs ! i) ∧ symbols_lt z (take t zs)) ⟹ (if (∀i<length (take t zs). Suc 0 < take t zs ! i) ∧ symbols_lt z (take t zs) then ⌊[3]⌋ else ⌊[]⌋, 1) |:=| 0 = (if (∀i<length (take (Suc t) zs). Suc 0 < take (Suc t) zs ! i) ∧ symbols_lt z (take (Suc t) zs) then ⌊[3]⌋ else ⌊[]⌋, 1)›*) case False (*‹¬ ((∀i<length (take t zs). Suc 0 < take t zs ! i) ∧ symbols_lt z (take t zs))›*) then have "¬ proper_symbols_lt z (take (Suc t) zs)" by auto then show "?thesis" (*goal: ‹(if (∀i<length (take t zs). Suc 0 < take t zs ! i) ∧ symbols_lt z (take t zs) then ⌊[3]⌋ else ⌊[]⌋, 1) |:=| 0 = (if (∀i<length (take (Suc t) zs). Suc 0 < take (Suc t) zs ! i) ∧ symbols_lt z (take (Suc t) zs) then ⌊[3]⌋ else ⌊[]⌋, 1)›*) using c3 (*‹(⌊[3]⌋, 1) |:=| 0 = (⌊[]⌋, 1)›*) False (*‹¬ ((∀i<length (take t zs). Suc 0 < take t zs ! i) ∧ symbols_lt z (take t zs))›*) by auto qed then have "tps1 t ! j2 |:=| □ = (if proper_symbols_lt z (take (Suc t) zs) then ⌊[𝟭]⌋ else ⌊[]⌋, 1)" using j2 (*‹tps1 t ! j2 = (if (∀i<length (take t zs). Suc 0 < take t zs ! i) ∧ symbols_lt z (take t zs) then ⌊[3]⌋ else ⌊[]⌋, 1)›*) by simp then show "tps2 t = (tps1 t)[j2 := tps1 t ! j2 |:=| □]" unfolding tps2_def tps1_def (*goal: ‹tps0[j1 := (⌊zs⌋, Suc t), j2 := (if (∀i<length (take (Suc t) zs). Suc 0 < take (Suc t) zs ! i) ∧ symbols_lt z (take (Suc t) zs) then ⌊[3]⌋ else ⌊[]⌋, 1)] = tps0[j1 := (⌊zs⌋, Suc t), j2 := (if (∀i<length (take t zs). Suc 0 < take t zs ! i) ∧ symbols_lt z (take t zs) then ⌊[3]⌋ else ⌊[]⌋, 1), j2 := tps0[j1 := (⌊zs⌋, Suc t), j2 := (if (∀i<length (take t zs). Suc 0 < take t zs ! i) ∧ symbols_lt z (take t zs) then ⌊[3]⌋ else ⌊[]⌋, 1)] ! j2 |:=| 0]›*) using c3 (*‹(⌊[3::nat]⌋, 1::nat) |:=| (0::nat) = (⌊[]⌋, 1::nat)›*) jk(1,4) (*‹k = length tps0› ‹(j2::nat) < (k::nat)›*) by simp qed show "tps2 t = tps1 t" if "¬ (read (tps1 t) ! j1 < 2 ∨ z ≤ read (tps1 t) ! j1)" proof (-) (*goal: ‹tps2 (t::nat) = tps1 t›*) have 1: "zs ! t ≥ 2 ∧ z > zs ! t" using that (*‹¬ (read (tps1 t) ! j1 < 2 ∨ z ≤ read (tps1 t) ! j1)›*) "*" (*‹read (tps1 t) ! j1 = zs ! t›*) by simp show "tps2 t = tps1 t" proof (cases "proper_symbols_lt z (take t zs)") (*goals: 1. ‹(∀i<length (take t zs). Suc 0 < take t zs ! i) ∧ symbols_lt z (take t zs) ⟹ tps2 t = tps1 t› 2. ‹¬ ((∀i<length (take t zs). Suc 0 < take t zs ! i) ∧ symbols_lt z (take t zs)) ⟹ tps2 t = tps1 t›*) case True (*‹(∀i<length (take t zs). Suc 0 < take t zs ! i) ∧ symbols_lt z (take t zs)›*) have "proper_symbols_lt z (take (Suc t) zs)" using True (*‹(∀i<length (take t zs). Suc 0 < take t zs ! i) ∧ symbols_lt z (take t zs)›*) "1" (*‹(2::nat) ≤ (zs::nat list) ! (t::nat) ∧ zs ! t < (z::nat)›*) assms(1) (*‹t < length zs›*) zs (*‹∀i<length zs. Suc 0 < zs ! i›*) by (metis length_take (*‹length (take ?n ?xs) = min (length ?xs) ?n›*) less_antisym (*‹⟦¬ ?n < ?m; ?n < Suc ?m⟧ ⟹ ?m = ?n›*) min_less_iff_conj (*‹(?z < min ?x ?y) = (?z < ?x ∧ ?z < ?y)›*) nth_take (*‹?i < ?n ⟹ take ?n ?xs ! ?i = ?xs ! ?i›*)) then show "?thesis" (*goal: ‹tps2 t = tps1 t›*) using tps1_def (*‹tps1 ?t ≡ tps0[j1 := (⌊zs⌋, Suc ?t), j2 := (if (∀i<length (take ?t zs). Suc 0 < take ?t zs ! i) ∧ symbols_lt z (take ?t zs) then ⌊[3]⌋ else ⌊[]⌋, 1)]›*) tps2_def (*‹tps2 ?t ≡ tps0[j1 := (⌊zs⌋, Suc ?t), j2 := (if (∀i<length (take (Suc ?t) zs). Suc 0 < take (Suc ?t) zs ! i) ∧ symbols_lt z (take (Suc ?t) zs) then ⌊[3]⌋ else ⌊[]⌋, 1)]›*) jk (*‹(k::nat) = length (tps0::((nat ⇒ nat) × nat) list)› ‹(j1::nat) ≠ (j2::nat)› ‹j1 < k› ‹j2 < k›*) by simp next (*goal: ‹¬ ((∀i<length (take t zs). Suc 0 < take t zs ! i) ∧ symbols_lt z (take t zs)) ⟹ tps2 t = tps1 t›*) case False (*‹¬ ((∀i<length (take t zs). Suc 0 < take t zs ! i) ∧ symbols_lt z (take t zs))›*) then have "¬ proper_symbols_lt z (take (Suc t) zs)" by auto then show "?thesis" (*goal: ‹tps2 t = tps1 t›*) using tps1_def (*‹tps1 (?t::nat) ≡ (tps0::((nat ⇒ nat) × nat) list)[j1::nat := (⌊zs::nat list⌋, Suc ?t), j2::nat := (if (∀i<length (take ?t zs). Suc (0::nat) < take ?t zs ! i) ∧ symbols_lt (z::nat) (take ?t zs) then ⌊[3::nat]⌋ else ⌊[]⌋, 1::nat)]›*) tps2_def (*‹tps2 ?t ≡ tps0[j1 := (⌊zs⌋, Suc ?t), j2 := (if (∀i<length (take (Suc ?t) zs). Suc 0 < take (Suc ?t) zs ! i) ∧ symbols_lt z (take (Suc ?t) zs) then ⌊[3]⌋ else ⌊[]⌋, 1)]›*) jk (*‹(k::nat) = length (tps0::((nat ⇒ nat) × nat) list)› ‹(j1::nat) ≠ (j2::nat)› ‹j1 < k› ‹j2 < k›*) False (*‹¬ ((∀i<length (take t zs). Suc 0 < take t zs ! i) ∧ symbols_lt z (take t zs))›*) by auto qed qed qed lemma tm3 [transforms_intros]: assumes "t < length zs" shows "transforms tm3 (tps1 t) 4 (tps1 (Suc t))" unfolding tm3_def (*goal: ‹transforms (tm2 ;; tm_right j1) (tps1 t) 4 (tps1 (Suc t))›*) proof (tform tps: assms jk tps2_def) (*goal: ‹tps1 (Suc t) = (tps2 t)[j1 := tps2 t ! j1 |+| 1]›*) have "tps2 t ! j1 |+| 1 = (⌊zs⌋, Suc (Suc t))" using tps2_def (*‹tps2 ?t ≡ tps0[j1 := (⌊zs⌋, Suc ?t), j2 := (if (∀i<length (take (Suc ?t) zs). Suc 0 < take (Suc ?t) zs ! i) ∧ symbols_lt z (take (Suc ?t) zs) then ⌊[3]⌋ else ⌊[]⌋, 1)]›*) jk (*‹k = length tps0› ‹j1 ≠ j2› ‹j1 < k› ‹j2 < k›*) by simp then show "tps1 (Suc t) = (tps2 t)[j1 := tps2 t ! j1 |+| 1]" unfolding tps1_def tps2_def (*goal: ‹tps0[j1 := (⌊zs⌋, Suc (Suc t)), j2 := (if (∀i<length (take (Suc t) zs). Suc 0 < take (Suc t) zs ! i) ∧ symbols_lt z (take (Suc t) zs) then ⌊[3]⌋ else ⌊[]⌋, 1)] = tps0[j1 := (⌊zs⌋, Suc t), j2 := (if (∀i<length (take (Suc t) zs). Suc 0 < take (Suc t) zs ! i) ∧ symbols_lt z (take (Suc t) zs) then ⌊[3]⌋ else ⌊[]⌋, 1), j1 := tps0[j1 := (⌊zs⌋, Suc t), j2 := (if (∀i<length (take (Suc t) zs). Suc 0 < take (Suc t) zs ! i) ∧ symbols_lt z (take (Suc t) zs) then ⌊[3]⌋ else ⌊[]⌋, 1)] ! j1 |+| 1]›*) by (metis (no_types, lifting) jk( (*‹j1 ≠ j2›*) 2) list_update_overwrite (*‹?xs[?i := ?x, ?i := ?y] = ?xs[?i := ?y]›*) list_update_swap (*‹?i ≠ ?i' ⟹ ?xs[?i := ?x, ?i' := ?x'] = ?xs[?i' := ?x', ?i := ?x]›*)) qed lemma tm4 [transforms_intros]: assumes "ttt = 1 + 6 * length zs" shows "transforms tm4 (tps1 0) ttt (tps1 (length zs))" unfolding tm4_def (*goal: ‹transforms (WHILE [] ; λrs. rs ! j1 ≠ 0 DO tm3 DONE) (tps1 0) ttt (tps1 (length zs))›*) proof (tform time: assms) (*goals: 1. ‹⋀i. i < length zs ⟹ read (tps1 i) ! j1 ≠ 0› 2. ‹¬ read (tps1 (length zs)) ! j1 ≠ 0›*) show "read (tps1 t) ! j1 ≠ □" if "t < length zs" for t proof (-) (*goal: ‹read (tps1 t) ! j1 ≠ 0›*) have "tps1 t ! j1 = (⌊zs⌋, Suc t)" using tps1_def (*‹tps1 ?t ≡ tps0[j1 := (⌊zs⌋, Suc ?t), j2 := (if (∀i<length (take ?t zs). Suc 0 < take ?t zs ! i) ∧ symbols_lt z (take ?t zs) then ⌊[3]⌋ else ⌊[]⌋, 1)]›*) jk (*‹k = length tps0› ‹j1 ≠ j2› ‹j1 < k› ‹j2 < k›*) by simp moreover have "read (tps1 t) ! j1 = tps1 t :.: j1" using tapes_at_read' (*‹?j < length ?tps ⟹ |.| (?tps ! ?j) = read ?tps ! ?j›*) jk (*‹k = length tps0› ‹(j1::nat) ≠ (j2::nat)› ‹j1 < k› ‹j2 < k›*) tps1_def (*‹tps1 ?t ≡ tps0[j1 := (⌊zs⌋, Suc ?t), j2 := (if (∀i<length (take ?t zs). Suc 0 < take ?t zs ! i) ∧ symbols_lt z (take ?t zs) then ⌊[3]⌋ else ⌊[]⌋, 1)]›*) by (metis (no_types, lifting) length_list_update (*‹length ((?xs::?'a list)[?i::nat := ?x::?'a]) = length ?xs›*)) ultimately have "read (tps1 t) ! j1 = zs ! t" using contents_inbounds (*‹⟦(0::nat) < (?i::nat); ?i ≤ length (?zs::nat list)⟧ ⟹ ⌊?zs⌋ ?i = ?zs ! (?i - (1::nat))›*) that (*‹t < length zs›*) by simp then show "?thesis" (*goal: ‹read (tps1 t) ! j1 ≠ 0›*) using zs (*‹∀i<length (zs::nat list). Suc (0::nat) < zs ! i›*) that (*‹t < length zs›*) by auto qed show "¬ read (tps1 (length zs)) ! j1 ≠ □" proof (-) (*goal: ‹¬ read (tps1 (length zs)) ! j1 ≠ 0›*) have "tps1 (length zs) ! j1 = (⌊zs⌋, Suc (length zs))" using tps1_def (*‹tps1 ?t ≡ tps0[j1 := (⌊zs⌋, Suc ?t), j2 := (if (∀i<length (take ?t zs). Suc 0 < take ?t zs ! i) ∧ symbols_lt z (take ?t zs) then ⌊[3]⌋ else ⌊[]⌋, 1)]›*) jk (*‹(k::nat) = length (tps0::((nat ⇒ nat) × nat) list)› ‹j1 ≠ j2› ‹j1 < k› ‹j2 < k›*) by simp moreover have "read (tps1 (length zs)) ! j1 = tps1 (length zs) :.: j1" using tapes_at_read' (*‹?j < length ?tps ⟹ |.| (?tps ! ?j) = read ?tps ! ?j›*) jk (*‹k = length tps0› ‹j1 ≠ j2› ‹j1 < k› ‹j2 < k›*) tps1_def (*‹tps1 ?t ≡ tps0[j1 := (⌊zs⌋, Suc ?t), j2 := (if (∀i<length (take ?t zs). Suc 0 < take ?t zs ! i) ∧ symbols_lt z (take ?t zs) then ⌊[3]⌋ else ⌊[]⌋, 1)]›*) by (metis (no_types, lifting) length_list_update (*‹length (?xs[?i := ?x]) = length ?xs›*)) ultimately show "?thesis" (*goal: ‹¬ read (tps1 (length zs)) ! j1 ≠ 0›*) by simp qed qed lemma tm5 [transforms_intros]: assumes "ttt = 2 + 6 * length zs" shows "transforms tm5 tps0 ttt (tps1 (length zs))" unfolding tm5_def (*goal: ‹transforms (tm1 ;; tm4) (tps0::((nat ⇒ nat) × nat) list) (ttt::nat) (tps1 (length (zs::nat list)))›*) by (tform time: assms) definition "tps5 ≡ tps0 [j1 := (⌊zs⌋, 1), j2 := (if proper_symbols_lt z zs then ⌊[𝟭]⌋ else ⌊[]⌋, 1)]" definition "tps5' ≡ tps0 [j2 := (if proper_symbols_lt z zs then ⌊[𝟭]⌋ else ⌊[]⌋, 1)]" lemma tm6: assumes "ttt = 5 + 7 * length zs" shows "transforms tm6 tps0 ttt tps5'" unfolding tm6_def (*goal: ‹transforms (tm5 ;; tm_cr (j1::nat)) (tps0::((nat ⇒ nat) × nat) list) (ttt::nat) tps5'›*) proof (tform time: assms tps1_def jk) (*goals: 1. ‹clean_tape (tps1 (length zs) ! j1)› 2. ‹tps5' = (tps1 (length zs))[j1 := tps1 (length zs) ! j1 |#=| 1]›*) have "*": "tps1 (length zs) ! j1 = (⌊zs⌋, Suc (length zs))" using tps1_def (*‹tps1 (?t::nat) ≡ (tps0::((nat ⇒ nat) × nat) list)[j1::nat := (⌊zs::nat list⌋, Suc ?t), j2::nat := (if (∀i<length (take ?t zs). Suc (0::nat) < take ?t zs ! i) ∧ symbols_lt (z::nat) (take ?t zs) then ⌊[3::nat]⌋ else ⌊[]⌋, 1::nat)]›*) jk (*‹k = length tps0› ‹j1 ≠ j2› ‹j1 < k› ‹j2 < k›*) by simp show "clean_tape (tps1 (length zs) ! j1)" using "*" (*‹tps1 (length zs) ! j1 = (⌊zs⌋, Suc (length zs))›*) zs (*‹∀i<length (zs::nat list). Suc (0::nat) < zs ! i›*) by simp have "tps5 = (tps1 (length zs))[j1 := (⌊zs⌋, Suc (length zs)) |#=| 1]" unfolding tps5_def tps1_def (*goal: ‹(tps0::((nat ⇒ nat) × nat) list)[j1::nat := (⌊zs::nat list⌋, 1::nat), j2::nat := (if (∀i<length zs. Suc (0::nat) < zs ! i) ∧ symbols_lt (z::nat) zs then ⌊[3::nat]⌋ else ⌊[]⌋, 1::nat)] = tps0[j1 := (⌊zs⌋, Suc (length zs)), j2 := (if (∀i<length (take (length zs) zs). Suc (0::nat) < take (length zs) zs ! i) ∧ symbols_lt z (take (length zs) zs) then ⌊[3::nat]⌋ else ⌊[]⌋, 1::nat), j1 := (⌊zs⌋, Suc (length zs)) |#=| (1::nat)]›*) by (simp add: list_update_swap[OF jk(2)] (*‹?xs[j1 := ?x, j2 := ?x'] = ?xs[j2 := ?x', j1 := ?x]›*)) then have "tps5 = (tps1 (length zs))[j1 := tps1 (length zs) ! j1 |#=| 1]" using "*" (*‹tps1 (length zs) ! j1 = (⌊zs⌋, Suc (length zs))›*) by simp moreover have "tps5' = tps5" using tps5'_def (*‹tps5' ≡ tps0[j2 := (if (∀i<length zs. Suc 0 < zs ! i) ∧ symbols_lt z zs then ⌊[3]⌋ else ⌊[]⌋, 1)]›*) tps5_def (*‹tps5 ≡ tps0[j1 := (⌊zs⌋, 1), j2 := (if (∀i<length zs. Suc 0 < zs ! i) ∧ symbols_lt z zs then ⌊[3]⌋ else ⌊[]⌋, 1)]›*) tps0 (*‹tps0 ! j1 = (⌊zs⌋, 1)› ‹tps0 ! j2 = (⌊[]⌋, 1)›*) jk (*‹k = length tps0› ‹(j1::nat) ≠ (j2::nat)› ‹j1 < k› ‹j2 < k›*) by (metis list_update_id (*‹?xs[?i := ?xs ! ?i] = ?xs›*)) ultimately show "tps5' = (tps1 (length zs))[j1 := tps1 (length zs) ! j1 |#=| 1]" by simp qed definition "tps6 ≡ tps0 [j2 := (⌊proper_symbols_lt z zs⌋⇩B, 1)]" lemma tm6': assumes "ttt = 5 + 7 * length zs" shows "transforms tm6 tps0 ttt tps6" proof (-) (*goal: ‹transforms tm6 tps0 ttt tps6›*) have "tps6 = tps5'" using tps6_def (*‹tps6 ≡ tps0[j2 := (⌊(∀i<length zs. Suc 0 < zs ! i) ∧ symbols_lt z zs⌋⇩B, 1)]›*) tps5'_def (*‹tps5' ≡ tps0[j2 := (if (∀i<length zs. Suc 0 < zs ! i) ∧ symbols_lt z zs then ⌊[3]⌋ else ⌊[]⌋, 1)]›*) canrepr_0 (*‹canrepr 0 = []›*) canrepr_1 (*‹canrepr 1 = [3]›*) by auto then show "?thesis" (*goal: ‹transforms tm6 tps0 ttt tps6›*) using tm6 (*‹?ttt = 5 + 7 * length zs ⟹ transforms tm6 tps0 ?ttt tps5'›*) assms (*‹ttt = 5 + 7 * length zs›*) by simp qed end end (* locale *) lemma transforms_tm_proper_symbols_ltI [transforms_intros]: fixes j1 j2 :: tapeidx and z :: symbol fixes zs :: "symbol list" and tps tps' :: "tape list" and k :: nat assumes "k = length tps" "j1 ≠ j2" "j1 < k" "j2 < k" and "proper_symbols zs" assumes "tps ! j1 = (⌊zs⌋, 1)" "tps ! j2 = (⌊[]⌋, 1)" assumes "ttt = 5 + 7 * length zs" assumes "tps' = tps [j2 := (⌊proper_symbols_lt z zs⌋⇩B, 1)]" shows "transforms (tm_proper_symbols_lt j1 j2 z) tps ttt tps'" proof (-) (*goal: ‹transforms (tm_proper_symbols_lt j1 j2 z) tps ttt tps'›*) interpret loc: turing_machine_proper_symbols_lt j1 j2 . show "?thesis" (*goal: ‹transforms (tm_proper_symbols_lt (j1::nat) (j2::nat) (z::nat)) (tps::((nat ⇒ nat) × nat) list) (ttt::nat) (tps'::((nat ⇒ nat) × nat) list)›*) using assms (*‹(k::nat) = length (tps::((nat ⇒ nat) × nat) list)› ‹j1 ≠ j2› ‹j1 < k› ‹j2 < k› ‹∀i<length (zs::nat list). Suc (0::nat) < zs ! i› ‹tps ! j1 = (⌊zs⌋, 1)› ‹tps ! j2 = (⌊[]⌋, 1)› ‹ttt = 5 + 7 * length zs› ‹(tps'::((nat ⇒ nat) × nat) list) = (tps::((nat ⇒ nat) × nat) list)[j2::nat := (⌊(∀i<length (zs::nat list). Suc (0::nat) < zs ! i) ∧ symbols_lt (z::nat) zs⌋⇩B, 1::nat)]›*) loc.tm6_eq_tm_proper_symbols_lt (*‹loc.tm6 = tm_proper_symbols_lt j1 j2 z›*) loc.tps6_def (*‹⟦?k = length ?tps0.0; j1 ≠ j2; j1 < ?k; j2 < ?k; ∀i<length ?zs. Suc 0 < ?zs ! i; ?tps0.0 ! j1 = (⌊?zs⌋, 1); ?tps0.0 ! j2 = (⌊[]⌋, 1)⟧ ⟹ loc.tps6 ?zs ?tps0.0 ≡ ?tps0.0[j2 := (⌊(∀i<length ?zs. Suc 0 < ?zs ! i) ∧ symbols_lt z ?zs⌋⇩B, 1)]›*) loc.tm6' (*‹⟦?k = length ?tps0.0; j1 ≠ j2; j1 < ?k; j2 < ?k; ∀i<length ?zs. Suc 0 < ?zs ! i; ?tps0.0 ! j1 = (⌊?zs⌋, 1); ?tps0.0 ! j2 = (⌊[]⌋, 1); ?ttt = 5 + 7 * length ?zs⟧ ⟹ transforms loc.tm6 ?tps0.0 ?ttt (loc.tps6 ?zs ?tps0.0)›*) by simp qed subsection ‹The length of the input› text ‹ The Turing machine in this section reads the input tape until the first blank and increments a counter on tape $j$ for every symbol read. In the end it performs a carriage return on the input tape, and tape $j$ contains the length of the input as binary number. For this to work, tape $j$ must initially be empty. › lemma proper_tape_read: assumes "proper_symbols zs" shows "|.| (⌊zs⌋, i) = □ ⟷ i > length zs" proof (-) (*goal: ‹(|.| (⌊zs::nat list⌋, i::nat) = (0::nat)) = (length zs < i)›*) have "|.| (⌊zs⌋, i) = □" if "i > length zs" for i using that (*‹length (zs::nat list) < (i::nat)›*) contents_outofbounds (*‹length ?zs < ?i ⟹ ⌊?zs⌋ ?i = 0›*) by simp moreover have "|.| (⌊zs⌋, i) ≠ □" if "i ≤ length zs" for i using that (*‹i ≤ length zs›*) contents_inbounds (*‹⟦(0::nat) < (?i::nat); ?i ≤ length (?zs::nat list)⟧ ⟹ ⌊?zs⌋ ?i = ?zs ! (?i - (1::nat))›*) assms (*‹∀i<length (zs::nat list). Suc (0::nat) < zs ! i›*) contents_def (*‹⌊?xs⌋ ?i ≡ if ?i = 0 then 1 else if ?i ≤ length ?xs then ?xs ! (?i - 1) else 0›*) proper_symbols_ne0 (*‹∀i<length ?xs. Suc 0 < ?xs ! i ⟹ ∀i<length ?xs. ?xs ! i ≠ 0›*) by simp ultimately show "?thesis" (*goal: ‹(|.| (⌊zs⌋, i) = 0) = (length zs < i)›*) by (meson le_less_linear (*‹?x ≤ ?y ∨ ?y < ?x›*)) qed definition tm_length_input :: "tapeidx ⇒ machine" where "tm_length_input j ≡ WHILE [] ; λrs. rs ! 0 ≠ □ DO tm_incr j ;; tm_right 0 DONE ;; tm_cr 0" lemma tm_length_input_tm: assumes "G ≥ 4" and "0 < j" and "j < k" shows "turing_machine k G (tm_length_input j)" using tm_length_input_def (*‹tm_length_input ?j ≡ WHILE [] ; λrs. rs ! 0 ≠ 0 DO tm_incr ?j ;; tm_right 0 DONE ;; tm_cr 0›*) tm_incr_tm (*‹⟦4 ≤ ?G; 2 ≤ ?k; ?j < ?k; 0 < ?j⟧ ⟹ turing_machine ?k ?G (tm_incr ?j)›*) assms (*‹4 ≤ G› ‹0 < j› ‹j < k›*) Nil_tm (*‹⟦4 ≤ ?G; 2 ≤ ?k⟧ ⟹ turing_machine ?k ?G []›*) tm_right_tm (*‹⟦2 ≤ ?k; 4 ≤ ?G⟧ ⟹ turing_machine ?k ?G (tm_right ?j)›*) tm_cr_tm (*‹⟦2 ≤ ?k; 4 ≤ ?G⟧ ⟹ turing_machine ?k ?G (tm_cr ?j)›*) by (simp add: turing_machine_loop_turing_machine (*‹⟦turing_machine ?k ?G ?M1.0; turing_machine ?k ?G ?M2.0⟧ ⟹ turing_machine ?k ?G (WHILE ?M1.0 ; ?cond DO ?M2.0 DONE)›*)) locale turing_machine_length_input = fixes j :: tapeidx begin definition "tmL1 ≡ tm_incr j" definition "tmL2 ≡ tmL1 ;; tm_right 0" definition "tm1 ≡ WHILE [] ; λrs. rs ! 0 ≠ □ DO tmL2 DONE" definition "tm2 ≡ tm1 ;; tm_cr 0" lemma tm2_eq_tm_length_input: "tm2 = tm_length_input j" unfolding tm2_def tm1_def tmL2_def tmL1_def tm_length_input_def (*goal: ‹WHILE [] ; λrs. rs ! 0 ≠ 0 DO tm_incr j ;; tm_right 0 DONE ;; tm_cr 0 = WHILE [] ; λrs. rs ! 0 ≠ 0 DO tm_incr j ;; tm_right 0 DONE ;; tm_cr 0›*) by simp context fixes tps0 :: "tape list" and k :: nat and zs :: "symbol list" assumes jk: "0 < j" "j < k" "length tps0 = k" and zs: "proper_symbols zs" and tps0: "tps0 ! 0 = (⌊zs⌋, 1)" "tps0 ! j = (⌊0⌋⇩N, 1)" begin definition tpsL :: "nat ⇒ tape list" where "tpsL t ≡ tps0[0 := (⌊zs⌋, 1 + t), j := (⌊t⌋⇩N, 1)]" lemma tpsL_eq_tps0: "tpsL 0 = tps0" using tpsL_def (*‹tpsL (?t::nat) ≡ (tps0::((nat ⇒ nat) × nat) list)[0::nat := (⌊zs::nat list⌋, (1::nat) + ?t), j::nat := (⌊?t⌋⇩N, 1::nat)]›*) tps0 (*‹(tps0::((nat ⇒ nat) × nat) list) ! (0::nat) = (⌊zs::nat list⌋, 1::nat)› ‹tps0 ! j = (⌊0⌋⇩N, 1)›*) jk (*‹0 < j› ‹j < k› ‹length tps0 = k›*) by (metis One_nat_def (*‹1 = Suc 0›*) list_update_id (*‹?xs[?i := ?xs ! ?i] = ?xs›*) plus_1_eq_Suc (*‹(+) 1 = Suc›*)) definition tpsL1 :: "nat ⇒ tape list" where "tpsL1 t ≡ tps0[0 := (⌊zs⌋, 1 + t), j := (⌊Suc t⌋⇩N, 1)]" definition tpsL2 :: "nat ⇒ tape list" where "tpsL2 t ≡ tps0[0 := (⌊zs⌋, 1 + Suc t), j := (⌊Suc t⌋⇩N, 1)]" lemma tmL1 [transforms_intros]: assumes "t < length zs" and "ttt = 5 + 2 * nlength t" shows "transforms tmL1 (tpsL t) ttt (tpsL1 t)" unfolding tmL1_def (*goal: ‹transforms (tm_incr j) (tpsL t) ttt (tpsL1 t)›*) by (tform tps: assms(1) tpsL_def tpsL1_def tps0 jk time: assms(2)) lemma tmL2: assumes "t < length zs" and "ttt = 6 + 2 * nlength t" shows "transforms tmL2 (tpsL t) ttt (tpsL (Suc t))" unfolding tmL2_def (*goal: ‹transforms (tmL1 ;; tm_right 0) (tpsL t) ttt (tpsL (Suc t))›*) proof (tform tps: assms(1) tpsL_def tpsL1_def tps0 jk time: assms(2)) (*goal: ‹tpsL (Suc t) = (tpsL1 t)[0 := tpsL1 t ! 0 |+| 1]›*) have "tpsL1 t ! 0 = (⌊zs⌋, 1 + t)" using tpsL2_def (*‹tpsL2 (?t::nat) ≡ (tps0::((nat ⇒ nat) × nat) list)[0::nat := (⌊zs::nat list⌋, (1::nat) + Suc ?t), j::nat := (⌊Suc ?t⌋⇩N, 1::nat)]›*) tpsL1_def (*‹tpsL1 ?t ≡ tps0[0 := (⌊zs⌋, 1 + ?t), j := (⌊Suc ?t⌋⇩N, 1)]›*) jk (*‹(0::nat) < (j::nat)› ‹j < k› ‹length tps0 = k›*) tps0 (*‹tps0 ! 0 = (⌊zs⌋, 1)› ‹tps0 ! j = (⌊0⌋⇩N, 1)›*) by simp then have "tpsL2 t = (tpsL1 t)[0 := tpsL1 t ! 0 |#=| Suc (tpsL1 t :#: 0)]" using tpsL2_def (*‹tpsL2 ?t ≡ tps0[0 := (⌊zs⌋, 1 + Suc ?t), j := (⌊Suc ?t⌋⇩N, 1)]›*) tpsL1_def (*‹tpsL1 ?t ≡ tps0[0 := (⌊zs⌋, 1 + ?t), j := (⌊Suc ?t⌋⇩N, 1)]›*) jk (*‹0 < j› ‹(j::nat) < (k::nat)› ‹length tps0 = k›*) tps0 (*‹tps0 ! 0 = (⌊zs⌋, 1)› ‹tps0 ! j = (⌊0⌋⇩N, 1)›*) by (smt (verit) fstI (*‹?x = (?y, ?z) ⟹ fst ?x = ?y›*) list_update_overwrite (*‹?xs[?i := ?x, ?i := ?y] = ?xs[?i := ?y]›*) list_update_swap (*‹?i ≠ ?i' ⟹ ?xs[?i := ?x, ?i' := ?x'] = ?xs[?i' := ?x', ?i := ?x]›*) nat_neq_iff (*‹(?m ≠ ?n) = (?m < ?n ∨ ?n < ?m)›*) plus_1_eq_Suc (*‹(+) 1 = Suc›*) prod.sel( (*‹snd (?x1.0, ?x2.0) = ?x2.0›*) 2)) then show "tpsL (Suc t) = (tpsL1 t)[0 := tpsL1 t ! 0 |+| 1]" using tpsL2_def (*‹tpsL2 ?t ≡ tps0[0 := (⌊zs⌋, 1 + Suc ?t), j := (⌊Suc ?t⌋⇩N, 1)]›*) tpsL_def (*‹tpsL (?t::nat) ≡ (tps0::((nat ⇒ nat) × nat) list)[0::nat := (⌊zs::nat list⌋, (1::nat) + ?t), j::nat := (⌊?t⌋⇩N, 1::nat)]›*) tpsL1_def (*‹tpsL1 ?t ≡ tps0[0 := (⌊zs⌋, 1 + ?t), j := (⌊Suc ?t⌋⇩N, 1)]›*) jk (*‹0 < j› ‹j < k› ‹length (tps0::((nat ⇒ nat) × nat) list) = (k::nat)›*) tps0 (*‹tps0 ! 0 = (⌊zs⌋, 1)› ‹tps0 ! j = (⌊0⌋⇩N, 1)›*) by simp qed lemma tmL2': assumes "t < length zs" and "ttt = 6 + 2 * nlength (length zs)" shows "transforms tmL2 (tpsL t) ttt (tpsL (Suc t))" proof (-) (*goal: ‹transforms tmL2 (tpsL t) ttt (tpsL (Suc t))›*) have "6 + 2 * nlength t ≤ 6 + 2 * nlength (length zs)" using assms(1) (*‹t < length zs›*) nlength_mono (*‹?n1.0 ≤ ?n2.0 ⟹ nlength ?n1.0 ≤ nlength ?n2.0›*) by simp then show "?thesis" (*goal: ‹transforms tmL2 (tpsL t) ttt (tpsL (Suc t))›*) using assms (*‹t < length zs› ‹ttt = 6 + 2 * nlength (length zs)›*) tmL2 (*‹⟦?t < length zs; ?ttt = 6 + 2 * nlength ?t⟧ ⟹ transforms tmL2 (tpsL ?t) ?ttt (tpsL (Suc ?t))›*) transforms_monotone (*‹⟦transforms ?M ?tps ?t ?tps'; ?t ≤ ?t'⟧ ⟹ transforms ?M ?tps ?t' ?tps'›*) by blast qed lemma tm1: assumes "ttt = length zs * (8 + 2 * nlength (length zs)) + 1" shows "transforms tm1 (tpsL 0) ttt (tpsL (length zs))" unfolding tm1_def (*goal: ‹transforms (WHILE [] ; λrs::nat list. rs ! (0::nat) ≠ (0::nat) DO tmL2 DONE) (tpsL (0::nat)) (ttt::nat) (tpsL (length (zs::nat list)))›*) proof (tform) (*goals: 1. ‹⋀i. i < length zs ⟹ transforms tmL2 (tpsL i) ?t1 (tpsL (Suc i))› 2. ‹⋀i. i < length zs ⟹ read (tpsL i) ! 0 ≠ 0› 3. ‹¬ read (tpsL (length zs)) ! 0 ≠ 0› 4. ‹length zs * (?t1 + 2) + 1 ≤ ttt›*) let ?t = "6 + 2 * nlength (length zs)" show "⋀t. t < length zs ⟹ transforms tmL2 (tpsL t) ?t (tpsL (Suc t))" using tmL2' (*‹⟦?t < length zs; ?ttt = 6 + 2 * nlength (length zs)⟧ ⟹ transforms tmL2 (tpsL ?t) ?ttt (tpsL (Suc ?t))›*) by simp have "*": "tpsL t ! 0 = (⌊zs⌋, Suc t)" for t using tpsL_def (*‹tpsL (?t::nat) ≡ (tps0::((nat ⇒ nat) × nat) list)[0::nat := (⌊zs::nat list⌋, (1::nat) + ?t), j::nat := (⌊?t⌋⇩N, 1::nat)]›*) jk (*‹(0::nat) < (j::nat)› ‹j < k› ‹length (tps0::((nat ⇒ nat) × nat) list) = (k::nat)›*) by simp then show "⋀t. t < length zs ⟹ read (tpsL t) ! 0 ≠ □" using proper_tape_read[OF zs] (*‹(|.| (⌊zs⌋, ?i) = 0) = (length zs < ?i)›*) tpsL_def (*‹tpsL ?t ≡ tps0[0 := (⌊zs⌋, 1 + ?t), j := (⌊?t⌋⇩N, 1)]›*) jk (*‹0 < j› ‹j < k› ‹length tps0 = k›*) tapes_at_read' (*‹(?j::nat) < length (?tps::((nat ⇒ nat) × nat) list) ⟹ |.| (?tps ! ?j) = read ?tps ! ?j›*) by (metis length_list_update (*‹length ((?xs::?'a list)[?i::nat := ?x::?'a]) = length ?xs›*) less_Suc_eq_0_disj (*‹((?m::nat) < Suc (?n::nat)) = (?m = (0::nat) ∨ (∃j::nat. ?m = Suc j ∧ j < ?n))›*) not_less_eq (*‹(¬ (?m::nat) < (?n::nat)) = (?n < Suc ?m)›*)) show "¬ read (tpsL (length zs)) ! 0 ≠ □" using proper_tape_read[OF zs] (*‹(|.| (⌊zs::nat list⌋, ?i::nat) = (0::nat)) = (length zs < ?i)›*) tpsL_def (*‹tpsL ?t ≡ tps0[0 := (⌊zs⌋, 1 + ?t), j := (⌊?t⌋⇩N, 1)]›*) jk (*‹0 < j› ‹(j::nat) < (k::nat)› ‹length tps0 = k›*) tapes_at_read' (*‹?j < length ?tps ⟹ |.| (?tps ! ?j) = read ?tps ! ?j›*) "*" (*‹tpsL ?t ! 0 = (⌊zs⌋, Suc ?t)›*) by (metis length_list_update (*‹length ((?xs::?'a list)[?i::nat := ?x::?'a]) = length ?xs›*) less_Suc_eq_0_disj (*‹((?m::nat) < Suc (?n::nat)) = (?m = (0::nat) ∨ (∃j::nat. ?m = Suc j ∧ j < ?n))›*) less_imp_Suc_add (*‹(?m::nat) < (?n::nat) ⟹ ∃k::nat. ?n = Suc (?m + k)›*) nat_neq_iff (*‹((?m::nat) ≠ (?n::nat)) = (?m < ?n ∨ ?n < ?m)›*) not_less_less_Suc_eq (*‹¬ (?n::nat) < (?m::nat) ⟹ (?n < Suc ?m) = (?n = ?m)›*)) show "length zs * (6 + 2 * nlength (length zs) + 2) + 1 ≤ ttt" using assms (*‹(ttt::nat) = length (zs::nat list) * ((8::nat) + (2::nat) * nlength (length zs)) + (1::nat)›*) by simp qed lemma tmL' [transforms_intros]: assumes "ttt = 10 * length zs ^ 2 + 1" shows "transforms tm1 (tpsL 0) ttt (tpsL (length zs))" proof (-) (*goal: ‹transforms tm1 (tpsL 0) ttt (tpsL (length zs))›*) let ?ttt = "length zs * (8 + 2 * nlength (length zs)) + 1" have "?ttt ≤ length zs * (8 + 2 * length zs) + 1" using nlength_le_n (*‹nlength ?n ≤ ?n›*) by simp also (*calculation: ‹length zs * (8 + 2 * nlength (length zs)) + 1 ≤ length zs * (8 + 2 * length zs) + 1›*) have "... ≤ 8 * length zs + 2 * length zs ^ 2 + 1" by (simp add: add_mult_distrib2 (*‹?k * (?m + ?n) = ?k * ?m + ?k * ?n›*) power2_eq_square (*‹?a² = ?a * ?a›*)) also (*calculation: ‹length zs * (8 + 2 * nlength (length zs)) + 1 ≤ 8 * length zs + 2 * (length zs)² + 1›*) have "... ≤ 10 * length zs ^ 2 + 1" using linear_le_pow (*‹0 < ?d1.0 ⟹ ?n ≤ ?n ^ ?d1.0›*) by simp finally (*calculation: ‹length zs * (8 + 2 * nlength (length zs)) + 1 ≤ 10 * (length zs)² + 1›*) have "?ttt ≤ 10 * length zs ^ 2 + 1" . then show "?thesis" (*goal: ‹transforms tm1 (tpsL (0::nat)) (ttt::nat) (tpsL (length (zs::nat list)))›*) using tm1 (*‹(?ttt::nat) = length (zs::nat list) * ((8::nat) + (2::nat) * nlength (length zs)) + (1::nat) ⟹ transforms tm1 (tpsL (0::nat)) ?ttt (tpsL (length zs))›*) assms (*‹ttt = 10 * (length zs)² + 1›*) transforms_monotone (*‹⟦transforms ?M ?tps ?t ?tps'; ?t ≤ ?t'⟧ ⟹ transforms ?M ?tps ?t' ?tps'›*) by simp qed definition tps2 :: "tape list" where "tps2 ≡ tps0[0 := (⌊zs⌋, 1), j := (⌊length zs⌋⇩N, 1)]" lemma tm2: assumes "ttt = 10 * length zs ^ 2 + length zs + 4" shows "transforms tm2 (tpsL 0) ttt tps2" unfolding tm2_def (*goal: ‹transforms (tm1 ;; tm_cr 0) (tpsL 0) ttt tps2›*) proof (tform time: assms tpsL_def jk tps: tpsL_def tpsL1_def tps0 jk) (*goals: 1. ‹clean_tape (tpsL (length zs) ! 0)› 2. ‹tps2 = (tpsL (length zs))[0 := tpsL (length zs) ! 0 |#=| 1]›*) show "clean_tape (tpsL (length zs) ! 0)" using tpsL_def (*‹tpsL ?t ≡ tps0[0 := (⌊zs⌋, 1 + ?t), j := (⌊?t⌋⇩N, 1)]›*) jk (*‹0 < j› ‹j < k› ‹length tps0 = k›*) clean_contents_proper[OF zs] (*‹clean_tape (⌊zs⌋, ?q)›*) by simp have "tpsL (length zs) ! 0 = (⌊zs⌋, Suc (length zs))" using tpsL_def (*‹tpsL (?t::nat) ≡ (tps0::((nat ⇒ nat) × nat) list)[0::nat := (⌊zs::nat list⌋, (1::nat) + ?t), j::nat := (⌊?t⌋⇩N, 1::nat)]›*) jk (*‹0 < j› ‹(j::nat) < (k::nat)› ‹length tps0 = k›*) by simp then show "tps2 = (tpsL (length zs))[0 := tpsL (length zs) ! 0 |#=| 1]" using tps2_def (*‹tps2 ≡ (tps0::((nat ⇒ nat) × nat) list)[0::nat := (⌊zs::nat list⌋, 1::nat), j::nat := (⌊length zs⌋⇩N, 1::nat)]›*) tpsL_def (*‹tpsL ?t ≡ tps0[0 := (⌊zs⌋, 1 + ?t), j := (⌊?t⌋⇩N, 1)]›*) jk (*‹0 < j› ‹j < k› ‹length tps0 = k›*) by (simp add: list_update_swap_less (*‹?i' < ?i ⟹ ?ys[?i := ?x, ?i' := ?x'] = ?ys[?i' := ?x', ?i := ?x]›*)) qed definition tps2' :: "tape list" where "tps2' ≡ tps0[j := (⌊length zs⌋⇩N, 1)]" lemma tm2': assumes "ttt = 11 * length zs ^ 2 + 4" shows "transforms tm2 tps0 ttt tps2'" proof (-) (*goal: ‹transforms tm2 (tps0::((nat ⇒ nat) × nat) list) (ttt::nat) tps2'›*) have "10 * length zs ^ 2 + length zs + 4 ≤ ttt" using assms (*‹ttt = 11 * (length zs)² + 4›*) linear_le_pow[of 2 "length zs"] (*‹0 < 2 ⟹ length zs ≤ (length zs)²›*) by simp moreover have "tps2 = tps2'" using tps2_def (*‹tps2 ≡ tps0[0 := (⌊zs⌋, 1), j := (⌊length zs⌋⇩N, 1)]›*) tps2'_def (*‹tps2' ≡ tps0[j := (⌊length zs⌋⇩N, 1)]›*) jk (*‹0 < j› ‹j < k› ‹length tps0 = k›*) tps0 (*‹tps0 ! 0 = (⌊zs⌋, 1)› ‹tps0 ! j = (⌊0⌋⇩N, 1)›*) by (metis list_update_id (*‹?xs[?i := ?xs ! ?i] = ?xs›*)) ultimately show "?thesis" (*goal: ‹transforms tm2 tps0 ttt tps2'›*) using transforms_monotone (*‹⟦transforms ?M ?tps ?t ?tps'; ?t ≤ ?t'⟧ ⟹ transforms ?M ?tps ?t' ?tps'›*) tm2 (*‹?ttt = 10 * (length zs)² + length zs + 4 ⟹ transforms tm2 (tpsL 0) ?ttt tps2›*) tpsL_eq_tps0 (*‹tpsL 0 = tps0›*) by simp qed end end lemma transforms_tm_length_inputI [transforms_intros]: fixes j :: tapeidx fixes tps tps' :: "tape list" and k :: nat and zs :: "symbol list" assumes "0 < j" "j < k" "length tps = k" and "proper_symbols zs" assumes "tps ! 0 = (⌊zs⌋, 1)" "tps ! j = (⌊0⌋⇩N, 1)" assumes "ttt = 11 * length zs ^ 2 + 4" assumes "tps' = tps [j := (⌊length zs⌋⇩N, 1)]" shows "transforms (tm_length_input j) tps ttt tps'" proof (-) (*goal: ‹transforms (tm_length_input j) tps ttt tps'›*) interpret loc: turing_machine_length_input j . show "?thesis" (*goal: ‹transforms (tm_length_input j) tps ttt tps'›*) using loc.tm2' (*‹⟦0 < j; j < ?k; length ?tps0.0 = ?k; ∀i<length ?zs. Suc 0 < ?zs ! i; ?tps0.0 ! 0 = (⌊?zs⌋, 1); ?tps0.0 ! j = (⌊0⌋⇩N, 1); ?ttt = 11 * (length ?zs)² + 4⟧ ⟹ transforms loc.tm2 ?tps0.0 ?ttt (loc.tps2' ?tps0.0 ?zs)›*) loc.tps2'_def (*‹⟦0 < j; j < ?k; length ?tps0.0 = ?k; ∀i<length ?zs. Suc 0 < ?zs ! i; ?tps0.0 ! 0 = (⌊?zs⌋, 1); ?tps0.0 ! j = (⌊0⌋⇩N, 1)⟧ ⟹ loc.tps2' ?tps0.0 ?zs ≡ ?tps0.0[j := (⌊length ?zs⌋⇩N, 1)]›*) loc.tm2_eq_tm_length_input (*‹loc.tm2 = tm_length_input j›*) assms (*‹0 < j› ‹(j::nat) < (k::nat)› ‹length tps = k› ‹∀i<length zs. Suc 0 < zs ! i› ‹tps ! 0 = (⌊zs⌋, 1)› ‹tps ! j = (⌊0⌋⇩N, 1)› ‹ttt = 11 * (length zs)² + 4› ‹tps' = tps[j := (⌊length zs⌋⇩N, 1)]›*) by simp qed subsection ‹Whether the length is even› text ‹ The next Turing machines reads the symbols on tape $j_1$ until the first blank and alternates between numbers~0 and~1 on tape $j_2$. Then tape $j_2$ contains the parity of the length of the symbol sequence on tape $j_1$. Finally, the TM flips the output once more, so that tape $j_2$ contains a Boolean indicating whether the length was even or not. We assume tape $j_2$ is initially empty, that is, represents the number~0. › definition tm_even_length :: "tapeidx ⇒ tapeidx ⇒ machine" where "tm_even_length j1 j2 ≡ WHILE [] ; λrs. rs ! j1 ≠ □ DO tm_not j2 ;; tm_right j1 DONE ;; tm_not j2 ;; tm_cr j1" lemma tm_even_length_tm: assumes "k ≥ 2" and "G ≥ 4" and "j1 < k" "0 < j2" "j2 < k" shows "turing_machine k G (tm_even_length j1 j2)" using tm_even_length_def (*‹tm_even_length ?j1.0 ?j2.0 ≡ WHILE [] ; λrs. rs ! ?j1.0 ≠ 0 DO tm_not ?j2.0 ;; tm_right ?j1.0 DONE ;; tm_not ?j2.0 ;; tm_cr ?j1.0›*) tm_right_tm (*‹⟦(2::nat) ≤ (?k::nat); (4::nat) ≤ (?G::nat)⟧ ⟹ turing_machine ?k ?G (tm_right (?j::nat))›*) tm_not_tm (*‹⟦2 ≤ ?k; 4 ≤ ?G; 0 < ?j; ?j < ?k⟧ ⟹ turing_machine ?k ?G (tm_not ?j)›*) Nil_tm (*‹⟦4 ≤ ?G; 2 ≤ ?k⟧ ⟹ turing_machine ?k ?G []›*) assms (*‹2 ≤ k› ‹(4::nat) ≤ (G::nat)› ‹j1 < k› ‹0 < j2› ‹j2 < k›*) tm_cr_tm (*‹⟦2 ≤ ?k; 4 ≤ ?G⟧ ⟹ turing_machine ?k ?G (tm_cr ?j)›*) turing_machine_loop_turing_machine (*‹⟦turing_machine ?k ?G ?M1.0; turing_machine ?k ?G ?M2.0⟧ ⟹ turing_machine ?k ?G (WHILE ?M1.0 ; ?cond DO ?M2.0 DONE)›*) by simp locale turing_machine_even_length = fixes j1 j2 :: tapeidx begin definition "tmB ≡ tm_not j2 ;; tm_right j1" definition "tmL ≡ WHILE [] ; λrs. rs ! j1 ≠ □ DO tmB DONE" definition "tm2 ≡ tmL ;; tm_not j2" definition "tm3 ≡ tm2 ;; tm_cr j1" lemma tm3_eq_tm_even_length: "tm3 = tm_even_length j1 j2" unfolding tm3_def tm2_def tmL_def tmB_def tm_even_length_def (*goal: ‹WHILE [] ; λrs. rs ! j1 ≠ 0 DO tm_not j2 ;; tm_right j1 DONE ;; tm_not j2 ;; tm_cr j1 = WHILE [] ; λrs. rs ! j1 ≠ 0 DO tm_not j2 ;; tm_right j1 DONE ;; tm_not j2 ;; tm_cr j1›*) by simp context fixes tps0 :: "tape list" and k :: nat and zs :: "symbol list" assumes zs: "proper_symbols zs" assumes jk: "j1 < k" "j2 < k" "j1 ≠ j2" "length tps0 = k" assumes tps0: "tps0 ! j1 = (⌊zs⌋, 1)" "tps0 ! j2 = (⌊0⌋⇩N, 1)" begin definition tpsL :: "nat ⇒ tape list" where "tpsL t ≡ tps0 [j1 := (⌊zs⌋, Suc t), j2 := (⌊odd t⌋⇩B, 1)]" lemma tpsL0: "tpsL 0 = tps0" unfolding tpsL_def (*goal: ‹(tps0::((nat ⇒ nat) × nat) list)[j1::nat := (⌊zs::nat list⌋, Suc (0::nat)), j2::nat := (⌊odd (0::nat)⌋⇩B, 1::nat)] = tps0›*) using tps0 (*‹tps0 ! j1 = (⌊zs⌋, 1)› ‹tps0 ! j2 = (⌊0⌋⇩N, 1)›*) jk (*‹j1 < k› ‹j2 < k› ‹j1 ≠ j2› ‹length tps0 = k›*) by (metis (mono_tags, opaque_lifting) One_nat_def (*‹1 = Suc 0›*) even_zero (*‹even 0›*) list_update_id (*‹?xs[?i := ?xs ! ?i] = ?xs›*)) lemma tmL2 [transforms_intros]: "transforms tmB (tpsL t) 4 (tpsL (Suc t))" unfolding tmB_def (*goal: ‹transforms (tm_not (j2::nat) ;; tm_right (j1::nat)) (tpsL (t::nat)) (4::nat) (tpsL (Suc t))›*) proof (tform tps: tpsL_def jk) (*goal: ‹tpsL (Suc t) = (tpsL t)[j2 := (⌊(if odd t then 1 else 0) ≠ 1⌋⇩B, 1), j1 := (tpsL t)[j2 := (⌊(if odd t then 1 else 0) ≠ 1⌋⇩B, 1)] ! j1 |+| 1]›*) have "(tpsL t) [j2 := (⌊(if odd t then 1 else 0 :: nat) ≠ 1⌋⇩B, 1), j1 := (tpsL t)[j2 := (⌊ (if odd t then 1 else 0 :: nat) ≠ 1 ⌋⇩B, 1)] ! j1 |+| 1] = (tpsL t) [j2 := (⌊odd (Suc t)⌋⇩B, 1), j1 := (tpsL t) ! j1 |+| 1]" using jk (*‹j1 < k› ‹j2 < k› ‹j1 ≠ j2› ‹length tps0 = k›*) by simp also (*calculation: ‹(tpsL t)[j2 := (⌊(if odd t then 1 else 0) ≠ 1⌋⇩B, 1), j1 := (tpsL t)[j2 := (⌊(if odd t then 1 else 0) ≠ 1⌋⇩B, 1)] ! j1 |+| 1] = (tpsL t)[j2 := (⌊odd (Suc t)⌋⇩B, 1), j1 := tpsL t ! j1 |+| 1]›*) have "... = (tpsL t) [j2 := (⌊odd (Suc t)⌋⇩B, 1), j1 := (⌊zs⌋, Suc (Suc t))]" using tpsL_def (*‹tpsL ?t ≡ tps0[j1 := (⌊zs⌋, Suc ?t), j2 := (⌊odd ?t⌋⇩B, 1)]›*) jk (*‹j1 < k› ‹j2 < k› ‹(j1::nat) ≠ (j2::nat)› ‹length (tps0::((nat ⇒ nat) × nat) list) = (k::nat)›*) by simp also (*calculation: ‹(tpsL t)[j2 := (⌊(if odd t then 1 else 0) ≠ 1⌋⇩B, 1), j1 := (tpsL t)[j2 := (⌊(if odd t then 1 else 0) ≠ 1⌋⇩B, 1)] ! j1 |+| 1] = (tpsL t)[j2 := (⌊odd (Suc t)⌋⇩B, 1), j1 := (⌊zs⌋, Suc (Suc t))]›*) have "... = (tpsL t) [j1 := (⌊zs⌋, Suc (Suc t)), j2 := (⌊odd (Suc t)⌋⇩B, 1)]" using jk (*‹(j1::nat) < (k::nat)› ‹j2 < k› ‹j1 ≠ j2› ‹length tps0 = k›*) by (simp add: list_update_swap (*‹?i ≠ ?i' ⟹ ?xs[?i := ?x, ?i' := ?x'] = ?xs[?i' := ?x', ?i := ?x]›*)) also (*calculation: ‹(tpsL t)[j2 := (⌊(if odd t then 1 else 0) ≠ 1⌋⇩B, 1), j1 := (tpsL t)[j2 := (⌊(if odd t then 1 else 0) ≠ 1⌋⇩B, 1)] ! j1 |+| 1] = (tpsL t)[j1 := (⌊zs⌋, Suc (Suc t)), j2 := (⌊odd (Suc t)⌋⇩B, 1)]›*) have "... = tps0 [j1 := (⌊zs⌋, Suc (Suc t)), j2 := (⌊odd (Suc t)⌋⇩B, 1)]" using jk (*‹j1 < k› ‹(j2::nat) < (k::nat)› ‹j1 ≠ j2› ‹length tps0 = k›*) tpsL_def (*‹tpsL ?t ≡ tps0[j1 := (⌊zs⌋, Suc ?t), j2 := (⌊odd ?t⌋⇩B, 1)]›*) by (simp add: list_update_swap (*‹?i ≠ ?i' ⟹ ?xs[?i := ?x, ?i' := ?x'] = ?xs[?i' := ?x', ?i := ?x]›*)) also (*calculation: ‹(tpsL t)[j2 := (⌊(if odd t then 1 else 0) ≠ 1⌋⇩B, 1), j1 := (tpsL t)[j2 := (⌊(if odd t then 1 else 0) ≠ 1⌋⇩B, 1)] ! j1 |+| 1] = tps0[j1 := (⌊zs⌋, Suc (Suc t)), j2 := (⌊odd (Suc t)⌋⇩B, 1)]›*) have "... = tpsL (Suc t)" using tpsL_def (*‹tpsL (?t::nat) ≡ (tps0::((nat ⇒ nat) × nat) list)[j1::nat := (⌊zs::nat list⌋, Suc ?t), j2::nat := (⌊odd ?t⌋⇩B, 1::nat)]›*) by simp finally (*calculation: ‹(tpsL t)[j2 := (⌊(if odd t then 1 else 0) ≠ 1⌋⇩B, 1), j1 := (tpsL t)[j2 := (⌊(if odd t then 1 else 0) ≠ 1⌋⇩B, 1)] ! j1 |+| 1] = tpsL (Suc t)›*) show "tpsL (Suc t) = (tpsL t) [j2 := (⌊(if odd t then 1 else 0 :: nat) ≠ 1⌋⇩B, 1), j1 := (tpsL t)[j2 := (⌊(if odd t then 1 else 0 :: nat) ≠ 1⌋⇩B, 1)] ! j1 |+| 1]" by simp qed lemma tmL: assumes "ttt = 6 * length zs + 1" shows "transforms tmL (tpsL 0) ttt (tpsL (length zs))" unfolding tmL_def (*goal: ‹transforms (WHILE [] ; λrs. rs ! j1 ≠ 0 DO tmB DONE) (tpsL 0) ttt (tpsL (length zs))›*) proof (tform time: assms) (*goals: 1. ‹⋀i. i < length zs ⟹ read (tpsL i) ! j1 ≠ 0› 2. ‹¬ read (tpsL (length zs)) ! j1 ≠ 0›*) have "read (tpsL t) ! j1 = tpsL t :.: j1" for t using tpsL_def (*‹tpsL ?t ≡ tps0[j1 := (⌊zs⌋, Suc ?t), j2 := (⌊odd ?t⌋⇩B, 1)]›*) tapes_at_read' (*‹?j < length ?tps ⟹ |.| (?tps ! ?j) = read ?tps ! ?j›*) jk (*‹j1 < k› ‹j2 < k› ‹(j1::nat) ≠ (j2::nat)› ‹length (tps0::((nat ⇒ nat) × nat) list) = (k::nat)›*) by (metis (no_types, lifting) length_list_update (*‹length (?xs[?i := ?x]) = length ?xs›*)) then have "read (tpsL t) ! j1 = ⌊zs⌋ (Suc t)" for t using tpsL_def (*‹tpsL ?t ≡ tps0[j1 := (⌊zs⌋, Suc ?t), j2 := (⌊odd ?t⌋⇩B, 1)]›*) jk (*‹(j1::nat) < (k::nat)› ‹j2 < k› ‹j1 ≠ j2› ‹length (tps0::((nat ⇒ nat) × nat) list) = (k::nat)›*) by simp then show "⋀t. t < length zs ⟹ read (tpsL t) ! j1 ≠ □" and "¬ read (tpsL (length zs)) ! j1 ≠ □" using zs (*‹∀i<length zs. Suc 0 < zs ! i›*) apply - (*goals: 1. ‹⋀t. ⟦t < length zs; ⋀t. read (tpsL t) ! j1 = ⌊zs⌋ (Suc t); ∀i<length zs. Suc 0 < zs ! i⟧ ⟹ read (tpsL t) ! j1 ≠ 0› 2. ‹⟦⋀t. read (tpsL t) ! j1 = ⌊zs⌋ (Suc t); ∀i<length zs. Suc 0 < zs ! i⟧ ⟹ ¬ read (tpsL (length zs)) ! j1 ≠ 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed lemma tmL' [transforms_intros]: assumes "ttt = 6 * length zs + 1" shows "transforms tmL tps0 ttt (tpsL (length zs))" using assms (*‹ttt = 6 * length zs + 1›*) tmL (*‹(?ttt::nat) = (6::nat) * length (zs::nat list) + (1::nat) ⟹ transforms tmL (tpsL (0::nat)) ?ttt (tpsL (length zs))›*) tpsL0 (*‹tpsL (0::nat) = (tps0::((nat ⇒ nat) × nat) list)›*) by simp definition tps2 :: "tape list" where "tps2 ≡ tps0 [j1 := (⌊zs⌋, Suc (length zs)), j2 := (⌊even (length zs) ⌋⇩B, 1)]" lemma tm2 [transforms_intros]: assumes "ttt = 6 * length zs + 4" shows "transforms tm2 tps0 ttt tps2" unfolding tm2_def (*goal: ‹transforms (tmL ;; tm_not j2) tps0 ttt tps2›*) proof (tform tps: tpsL_def jk time: assms) (*goal: ‹tps2 = (tpsL (length (zs::nat list)))[j2::nat := (⌊(if odd (length zs) then 1::nat else (0::nat)) ≠ (1::nat)⌋⇩B, 1::nat)]›*) show "tps2 = (tpsL (length zs))[j2 := (⌊(if odd (length zs) then 1 else 0 :: nat) ≠ 1⌋⇩B, 1)]" unfolding tps2_def tpsL_def (*goal: ‹tps0[j1 := (⌊zs⌋, Suc (length zs)), j2 := (⌊even (length zs)⌋⇩B, 1)] = tps0[j1 := (⌊zs⌋, Suc (length zs)), j2 := (⌊odd (length zs)⌋⇩B, 1), j2 := (⌊(if odd (length zs) then 1 else 0) ≠ 1⌋⇩B, 1)]›*) by (simp add: list_update_swap (*‹?i ≠ ?i' ⟹ ?xs[?i := ?x, ?i' := ?x'] = ?xs[?i' := ?x', ?i := ?x]›*)) qed definition tps3 :: "tape list" where "tps3 ≡ tps0 [j1 := (⌊zs⌋, 1), j2 := (⌊even (length zs)⌋⇩B, 1)]" lemma tm3: assumes "ttt = 7 * length zs + 7" shows "transforms tm3 tps0 ttt tps3" unfolding tm3_def (*goal: ‹transforms (tm2 ;; tm_cr (j1::nat)) (tps0::((nat ⇒ nat) × nat) list) (ttt::nat) tps3›*) proof (tform tps: tps2_def jk time: assms) (*goals: 1. ‹clean_tape (tps2 ! j1)› 2. ‹tps3 = tps2[j1 := tps2 ! j1 |#=| 1]› 3. ‹ttt = 6 * length zs + 4 + (tps2 :#: j1 + 2)›*) show "clean_tape (tps2 ! j1)" using tps2_def (*‹tps2 ≡ (tps0::((nat ⇒ nat) × nat) list)[j1::nat := (⌊zs::nat list⌋, Suc (length zs)), j2::nat := (⌊even (length zs)⌋⇩B, 1::nat)]›*) jk (*‹j1 < k› ‹j2 < k› ‹j1 ≠ j2› ‹length tps0 = k›*) zs (*‹∀i<length zs. Suc 0 < zs ! i›*) clean_contents_proper (*‹∀i<length ?zs. Suc 0 < ?zs ! i ⟹ clean_tape (⌊?zs⌋, ?q)›*) by simp have "tps2 ! j1 |#=| 1 = (⌊zs⌋, 1)" using tps2_def (*‹tps2 ≡ tps0[j1 := (⌊zs⌋, Suc (length zs)), j2 := (⌊even (length zs)⌋⇩B, 1)]›*) jk (*‹j1 < k› ‹j2 < k› ‹j1 ≠ j2› ‹length (tps0::((nat ⇒ nat) × nat) list) = (k::nat)›*) by simp then show "tps3 = tps2[j1 := tps2 ! j1 |#=| 1]" unfolding tps3_def tps2_def (*goal: ‹tps0[j1 := (⌊zs⌋, 1), j2 := (⌊even (length zs)⌋⇩B, 1)] = tps0[j1 := (⌊zs⌋, Suc (length zs)), j2 := (⌊even (length zs)⌋⇩B, 1), j1 := tps0[j1 := (⌊zs⌋, Suc (length zs)), j2 := (⌊even (length zs)⌋⇩B, 1)] ! j1 |#=| 1]›*) using jk (*‹j1 < k› ‹j2 < k› ‹j1 ≠ j2› ‹length tps0 = k›*) by (simp add: list_update_swap (*‹?i ≠ ?i' ⟹ ?xs[?i := ?x, ?i' := ?x'] = ?xs[?i' := ?x', ?i := ?x]›*)) show "ttt = 6 * length zs + 4 + (tps2 :#: j1 + 2)" using assms (*‹ttt = 7 * length zs + 7›*) tps2_def (*‹tps2 ≡ tps0[j1 := (⌊zs⌋, Suc (length zs)), j2 := (⌊even (length zs)⌋⇩B, 1)]›*) jk (*‹j1 < k› ‹j2 < k› ‹j1 ≠ j2› ‹length (tps0::((nat ⇒ nat) × nat) list) = (k::nat)›*) by simp qed definition tps3' :: "tape list" where "tps3' ≡ tps0 [j2 := (⌊even (length zs)⌋⇩B, 1)]" lemma tps3': "tps3' = tps3" using tps3'_def (*‹tps3' ≡ tps0[j2 := (⌊even (length zs)⌋⇩B, 1)]›*) tps3_def (*‹tps3 ≡ tps0[j1 := (⌊zs⌋, 1), j2 := (⌊even (length zs)⌋⇩B, 1)]›*) tps0 (*‹tps0 ! j1 = (⌊zs⌋, 1)› ‹tps0 ! j2 = (⌊0⌋⇩N, 1)›*) by (metis list_update_id (*‹?xs[?i := ?xs ! ?i] = ?xs›*)) lemma tm3': assumes "ttt = 7 * length zs + 7" shows "transforms tm3 tps0 ttt tps3'" using tps3' (*‹tps3' = tps3›*) tm3 (*‹?ttt = 7 * length zs + 7 ⟹ transforms tm3 tps0 ?ttt tps3›*) assms (*‹ttt = 7 * length zs + 7›*) by simp end (* context *) end (* locale *) lemma transforms_tm_even_lengthI [transforms_intros]: fixes j1 j2 :: tapeidx fixes tps tps' :: "tape list" and k :: nat and zs :: "symbol list" assumes "j1 < k" "j2 < k" "j1 ≠ j2" and "proper_symbols zs" and "length tps = k" assumes "tps ! j1 = (⌊zs⌋, 1)" "tps ! j2 = (⌊0⌋⇩N, 1)" assumes "tps' = tps [j2 := (⌊even (length zs)⌋⇩B, 1)]" assumes "ttt = 7 * length zs + 7" shows "transforms (tm_even_length j1 j2) tps ttt tps'" proof (-) (*goal: ‹transforms (tm_even_length j1 j2) tps ttt tps'›*) interpret loc: turing_machine_even_length j1 j2 . show "?thesis" (*goal: ‹transforms (tm_even_length j1 j2) tps ttt tps'›*) using assms (*‹j1 < k› ‹j2 < k› ‹(j1::nat) ≠ (j2::nat)› ‹∀i<length zs. Suc 0 < zs ! i› ‹length tps = k› ‹tps ! j1 = (⌊zs⌋, 1)› ‹tps ! j2 = (⌊0⌋⇩N, 1)› ‹tps' = tps[j2 := (⌊even (length zs)⌋⇩B, 1)]› ‹ttt = 7 * length zs + 7›*) loc.tps3'_def (*‹⟦∀i<length ?zs. Suc 0 < ?zs ! i; j1 < ?k; j2 < ?k; j1 ≠ j2; length ?tps0.0 = ?k; ?tps0.0 ! j1 = (⌊?zs⌋, 1); ?tps0.0 ! j2 = (⌊0⌋⇩N, 1)⟧ ⟹ loc.tps3' ?tps0.0 ?zs ≡ ?tps0.0[j2 := (⌊even (length ?zs)⌋⇩B, 1)]›*) loc.tm3' (*‹⟦∀i<length ?zs. Suc 0 < ?zs ! i; j1 < ?k; j2 < ?k; j1 ≠ j2; length ?tps0.0 = ?k; ?tps0.0 ! j1 = (⌊?zs⌋, 1); ?tps0.0 ! j2 = (⌊0⌋⇩N, 1); ?ttt = 7 * length ?zs + 7⟧ ⟹ transforms loc.tm3 ?tps0.0 ?ttt (loc.tps3' ?tps0.0 ?zs)›*) loc.tm3_eq_tm_even_length (*‹loc.tm3 = tm_even_length j1 j2›*) by simp qed subsection ‹Checking for ends-with or empty› text ‹ The next Turing machine implements a slightly idiosyncratic operation that we use in the next section for checking if a symbol sequence represents a list of numbers. The operation consists in checking if the symbol sequence on tape $j_1$ either is empty or ends with the symbol $z$, which is another parameter of the TM. If the condition is met, the number~1 is written to tape $j_2$, otherwise the number~0. › definition tm_empty_or_endswith :: "tapeidx ⇒ tapeidx ⇒ symbol ⇒ machine" where "tm_empty_or_endswith j1 j2 z ≡ tm_right_until j1 {□} ;; tm_left j1 ;; IF λrs. rs ! j1 ∈ {▹, z} THEN tm_setn j2 1 ELSE [] ENDIF ;; tm_cr j1" lemma tm_empty_or_endswith_tm: assumes "k ≥ 2" and "G ≥ 4" and "0 < j2" and "j1 < k" and "j2 < k" shows "turing_machine k G (tm_empty_or_endswith j1 j2 z)" using assms (*‹2 ≤ k› ‹(4::nat) ≤ (G::nat)› ‹0 < j2› ‹j1 < k› ‹j2 < k›*) Nil_tm (*‹⟦4 ≤ ?G; 2 ≤ ?k⟧ ⟹ turing_machine ?k ?G []›*) tm_right_until_tm (*‹⟦?j < ?k; 2 ≤ ?k; 4 ≤ ?G⟧ ⟹ turing_machine ?k ?G (tm_right_until ?j ?H)›*) tm_left_tm (*‹⟦(2::nat) ≤ (?k::nat); (4::nat) ≤ (?G::nat)⟧ ⟹ turing_machine ?k ?G (tm_left (?j::nat))›*) tm_setn_tm (*‹⟦2 ≤ ?k; 4 ≤ ?G; ?j < ?k; 0 < ?j⟧ ⟹ turing_machine ?k ?G (tm_setn ?j ?n)›*) tm_cr_tm (*‹⟦2 ≤ ?k; 4 ≤ ?G⟧ ⟹ turing_machine ?k ?G (tm_cr ?j)›*) turing_machine_branch_turing_machine (*‹⟦turing_machine (?k::nat) (?G::nat) (?M1.0::(nat list ⇒ nat × (nat × direction) list) list); turing_machine ?k ?G (?M2.0::(nat list ⇒ nat × (nat × direction) list) list)⟧ ⟹ turing_machine ?k ?G (IF ?cond::nat list ⇒ bool THEN ?M1.0 ELSE ?M2.0 ENDIF)›*) tm_empty_or_endswith_def (*‹tm_empty_or_endswith ?j1.0 ?j2.0 ?z ≡ tm_right_until ?j1.0 {0} ;; tm_left ?j1.0 ;; IF λrs. rs ! ?j1.0 ∈ {1, ?z} THEN tm_setn ?j2.0 1 ELSE [] ENDIF ;; tm_cr ?j1.0›*) by simp locale turing_machine_empty_or_endswith = fixes j1 j2 :: tapeidx and z :: symbol begin definition "tm1 ≡ tm_right_until j1 {□}" definition "tm2 ≡ tm1 ;; tm_left j1" definition "tmI ≡ IF λrs. rs ! j1 ∈ {▹, z} THEN tm_setn j2 1 ELSE [] ENDIF" definition "tm3 ≡ tm2 ;; tmI" definition "tm4 ≡ tm3 ;; tm_cr j1" lemma tm4_eq_tm_empty_or_endswith: "tm4 = tm_empty_or_endswith j1 j2 z" unfolding tm4_def tm3_def tmI_def tm2_def tm1_def tm_empty_or_endswith_def (*goal: ‹tm_right_until j1 {0} ;; tm_left j1 ;; IF λrs. rs ! j1 ∈ {1, z} THEN tm_setn j2 1 ELSE [] ENDIF ;; tm_cr j1 = tm_right_until j1 {0} ;; tm_left j1 ;; IF λrs. rs ! j1 ∈ {1, z} THEN tm_setn j2 1 ELSE [] ENDIF ;; tm_cr j1›*) by simp context fixes tps0 :: "tape list" and k :: nat and zs :: "symbol list" assumes jk: "j1 ≠ j2" "j1 < k" "j2 < k" "length tps0 = k" and zs: "proper_symbols zs" and tps0: "tps0 ! j1 = (⌊zs⌋, 1)" "tps0 ! j2 = (⌊0⌋⇩N, 1)" begin definition tps1 :: "tape list" where "tps1 ≡ tps0 [j1 := (⌊zs⌋, Suc (length zs))]" lemma tm1 [transforms_intros]: assumes "ttt = Suc (length zs)" shows "transforms tm1 tps0 ttt tps1" unfolding tm1_def (*goal: ‹transforms (tm_right_until j1 {0}) tps0 ttt tps1›*) proof (tform time: assms tps: tps0 tps1_def jk) (*goal: ‹rneigh (tps0 ! j1) {0} (length zs)›*) show "rneigh (tps0 ! j1) {0} (length zs)" proof (rule rneighI (*‹⟦fst ?tp (snd ?tp + ?n) ∈ ?H; ⋀n'. n' < ?n ⟹ fst ?tp (snd ?tp + n') ∉ ?H⟧ ⟹ rneigh ?tp ?H ?n›*)) (*goals: 1. ‹(tps0 ::: j1) (tps0 :#: j1 + length zs) ∈ {0}› 2. ‹⋀n'. n' < length zs ⟹ (tps0 ::: j1) (tps0 :#: j1 + n') ∉ {0}›*) show "(tps0 ::: j1) (tps0 :#: j1 + length zs) ∈ {0}" using tps0 (*‹tps0 ! j1 = (⌊zs⌋, 1)› ‹tps0 ! j2 = (⌊0⌋⇩N, 1)›*) by simp show "⋀n'. n' < length zs ⟹ (tps0 ::: j1) (tps0 :#: j1 + n') ∉ {0}" using zs (*‹∀i<length zs. Suc 0 < zs ! i›*) tps0 (*‹tps0 ! j1 = (⌊zs⌋, 1)› ‹(tps0::((nat ⇒ nat) × nat) list) ! (j2::nat) = (⌊0::nat⌋⇩N, 1::nat)›*) by auto qed qed definition tps2 :: "tape list" where "tps2 ≡ tps0 [j1 := (⌊zs⌋, length zs)]" lemma tm2 [transforms_intros]: assumes "ttt = 2 + length zs" shows "transforms tm2 tps0 ttt tps2" unfolding tm2_def (*goal: ‹transforms (tm1 ;; tm_left j1) tps0 ttt tps2›*) by (tform time: assms tps: tps1_def tps2_def jk) definition tps3 :: "tape list" where "tps3 ≡ tps0 [j1 := (⌊zs⌋, length zs), j2 := (⌊zs = [] ∨ last zs = z⌋⇩B, 1)]" lemma tmI [transforms_intros]: "transforms tmI tps2 14 tps3" unfolding tmI_def (*goal: ‹transforms (IF λrs. rs ! j1 ∈ {1, z} THEN tm_setn j2 1 ELSE [] ENDIF) tps2 14 tps3›*) proof (tform tps: tps0 tps2_def jk) (*goals: 1. ‹read tps2 ! j1 ∈ {1, z} ⟹ tps3 = tps2[j2 := (⌊1⌋⇩N, 1)]› 2. ‹read tps2 ! j1 ∈ {1, z} ⟹ 10 + 2 * nlength 0 + 2 * nlength 1 + 2 ≤ 14› 3. ‹read tps2 ! j1 ∉ {1, z} ⟹ tps3 = tps2›*) have "*": "read tps2 ! j1 = ⌊zs⌋ (length zs)" using tps2_def (*‹tps2 ≡ tps0[j1 := (⌊zs⌋, length zs)]›*) jk (*‹(j1::nat) ≠ (j2::nat)› ‹j1 < k› ‹j2 < k› ‹length tps0 = k›*) tapes_at_read'[of j1 tps2] (*‹j1 < length tps2 ⟹ |.| (tps2 ! j1) = read tps2 ! j1›*) by simp show "tps3 = tps2[j2 := (⌊1⌋⇩N, 1)]" if "read tps2 ! j1 ∈ {▹, z}" proof (-) (*goal: ‹tps3 = tps2[j2 := (⌊1⌋⇩N, 1)]›*) have "zs = [] ∨ last zs = z" using that (*‹read tps2 ! j1 ∈ {1, z}›*) "*" (*‹read tps2 ! j1 = ⌊zs⌋ (length zs)›*) contents_inbounds (*‹⟦0 < ?i; ?i ≤ length ?zs⟧ ⟹ ⌊?zs⌋ ?i = ?zs ! (?i - 1)›*) zs (*‹∀i<length zs. Suc 0 < zs ! i›*) by (metis diff_less (*‹⟦(0::nat) < (?n::nat); (0::nat) < (?m::nat)⟧ ⟹ ?m - ?n < ?m›*) dual_order.refl (*‹(?a::?'a) ≤ ?a›*) insert_iff (*‹((?a::?'a) ∈ insert (?b::?'a) (?A::?'a set)) = (?a = ?b ∨ ?a ∈ ?A)›*) last_conv_nth (*‹(?xs::?'a list) ≠ [] ⟹ last ?xs = ?xs ! (length ?xs - (1::nat))›*) length_greater_0_conv (*‹((0::nat) < length (?xs::?'a list)) = (?xs ≠ [])›*) proper_symbols_ne1 (*‹∀i<length (?xs::nat list). Suc (0::nat) < ?xs ! i ⟹ ∀i<length ?xs. ?xs ! i ≠ (1::nat)›*) singletonD (*‹(?b::?'a) ∈ {?a::?'a} ⟹ ?b = ?a›*) zero_less_one (*‹(0::?'a) < (1::?'a)›*)) then have "(if zs = [] ∨ last zs = z then 1 else 0) = 1" by simp then show "?thesis" (*goal: ‹tps3 = tps2[j2 := (⌊1⌋⇩N, 1)]›*) using tps2_def (*‹tps2 ≡ tps0[j1 := (⌊zs⌋, length zs)]›*) tps3_def (*‹tps3 ≡ tps0[j1 := (⌊zs⌋, length zs), j2 := (⌊zs = [] ∨ last zs = z⌋⇩B, 1)]›*) jk (*‹j1 ≠ j2› ‹j1 < k› ‹j2 < k› ‹length (tps0::((nat ⇒ nat) × nat) list) = (k::nat)›*) by (smt (verit, best)) qed show "tps3 = tps2" if "read tps2 ! j1 ∉ {▹, z}" proof (-) (*goal: ‹tps3 = tps2›*) have "¬ (zs = [] ∨ last zs = z)" using that (*‹read tps2 ! (j1::nat) ∉ {1::nat, z::nat}›*) "*" (*‹read tps2 ! j1 = ⌊zs⌋ (length zs)›*) contents_inbounds (*‹⟦0 < ?i; ?i ≤ length ?zs⟧ ⟹ ⌊?zs⌋ ?i = ?zs ! (?i - 1)›*) zs (*‹∀i<length zs. Suc 0 < zs ! i›*) by (metis contents_at_0 (*‹⌊?zs⌋ 0 = 1›*) dual_order.refl (*‹?a ≤ ?a›*) insertCI (*‹(?a ∉ ?B ⟹ ?a = ?b) ⟹ ?a ∈ insert ?b ?B›*) last_conv_nth (*‹?xs ≠ [] ⟹ last ?xs = ?xs ! (length ?xs - 1)›*) length_greater_0_conv (*‹(0 < length ?xs) = (?xs ≠ [])›*) list.size( (*‹length [] = 0›*) 3)) then have "(if zs = [] ∨ last zs = z then 1 else 0) = 0" by simp then show "?thesis" (*goal: ‹tps3 = tps2›*) using tps2_def (*‹tps2 ≡ (tps0::((nat ⇒ nat) × nat) list)[j1::nat := (⌊zs::nat list⌋, length zs)]›*) tps3_def (*‹tps3 ≡ tps0[j1 := (⌊zs⌋, length zs), j2 := (⌊zs = [] ∨ last zs = z⌋⇩B, 1)]›*) jk (*‹j1 ≠ j2› ‹j1 < k› ‹(j2::nat) < (k::nat)› ‹length tps0 = k›*) tps0 (*‹tps0 ! j1 = (⌊zs⌋, 1)› ‹tps0 ! j2 = (⌊0⌋⇩N, 1)›*) by (smt (verit, best) list_update_id (*‹?xs[?i := ?xs ! ?i] = ?xs›*) nth_list_update_neq (*‹?i ≠ ?j ⟹ ?xs[?i := ?x] ! ?j = ?xs ! ?j›*)) qed show "10 + 2 * nlength 0 + 2 * nlength 1 + 2 ≤ 14" using nlength_1_simp (*‹nlength 1 = 1›*) by simp qed lemma tm3 [transforms_intros]: assumes "ttt = 16 + length zs" shows "transforms tm3 tps0 ttt tps3" unfolding tm3_def (*goal: ‹transforms (tm2 ;; tmI) tps0 ttt tps3›*) by (tform tps: assms) definition tps4 :: "tape list" where "tps4 ≡ tps0 [j2 := (⌊zs = [] ∨ last zs = z⌋⇩B, 1)]" lemma tm4: assumes "ttt = 18 + 2 * length zs" shows "transforms tm4 tps0 ttt tps4" unfolding tm4_def (*goal: ‹transforms (tm3 ;; tm_cr j1) tps0 ttt tps4›*) proof (tform time: assms tps3_def jk tps: tps3_def jk zs) (*goal: ‹tps4 = tps3[j1::nat := tps3 ! j1 |#=| (1::nat)]›*) have "tps3 ! j1 |#=| 1 = (⌊zs⌋, 1)" using tps3_def (*‹tps3 ≡ tps0[j1 := (⌊zs⌋, length zs), j2 := (⌊zs = [] ∨ last zs = z⌋⇩B, 1)]›*) jk (*‹j1 ≠ j2› ‹j1 < k› ‹j2 < k› ‹length tps0 = k›*) zs (*‹∀i<length zs. Suc 0 < zs ! i›*) by simp then show "tps4 = tps3[j1 := tps3 ! j1 |#=| 1]" using tps4_def (*‹tps4 ≡ (tps0::((nat ⇒ nat) × nat) list)[j2::nat := (⌊(zs::nat list) = [] ∨ last zs = (z::nat)⌋⇩B, 1::nat)]›*) tps3_def (*‹tps3 ≡ tps0[j1 := (⌊zs⌋, length zs), j2 := (⌊zs = [] ∨ last zs = z⌋⇩B, 1)]›*) jk (*‹(j1::nat) ≠ (j2::nat)› ‹j1 < k› ‹j2 < k› ‹length tps0 = k›*) tps0(1) (*‹tps0 ! j1 = (⌊zs⌋, 1)›*) by (metis list_update_id (*‹(?xs::?'a list)[?i::nat := ?xs ! ?i] = ?xs›*) list_update_overwrite (*‹(?xs::?'a list)[?i::nat := ?x::?'a, ?i := ?y::?'a] = ?xs[?i := ?y]›*) list_update_swap (*‹(?i::nat) ≠ (?i'::nat) ⟹ (?xs::?'a list)[?i := ?x::?'a, ?i' := ?x'::?'a] = ?xs[?i' := ?x', ?i := ?x]›*)) qed end (* context *) end (* locale *) lemma transforms_tm_empty_or_endswithI [transforms_intros]: fixes j1 j2 :: tapeidx and z :: symbol fixes tps tps' :: "tape list" and k :: nat and zs :: "symbol list" assumes "j1 ≠ j2" "j1 < k" "j2 < k" and "length tps = k" and "proper_symbols zs" assumes "tps ! j1 = (⌊zs⌋, 1)" "tps ! j2 = (⌊0⌋⇩N, 1)" assumes "ttt = 18 + 2 * length zs" assumes "tps' = tps [j2 := (⌊zs = [] ∨ last zs = z⌋⇩B, 1)]" shows "transforms (tm_empty_or_endswith j1 j2 z) tps ttt tps'" proof (-) (*goal: ‹transforms (tm_empty_or_endswith (j1::nat) (j2::nat) (z::nat)) (tps::((nat ⇒ nat) × nat) list) (ttt::nat) (tps'::((nat ⇒ nat) × nat) list)›*) interpret loc: turing_machine_empty_or_endswith j1 j2 z . show "?thesis" (*goal: ‹transforms (tm_empty_or_endswith j1 j2 z) tps ttt tps'›*) using assms (*‹j1 ≠ j2› ‹j1 < k› ‹j2 < k› ‹length (tps::((nat ⇒ nat) × nat) list) = (k::nat)› ‹∀i<length zs. Suc 0 < zs ! i› ‹(tps::((nat ⇒ nat) × nat) list) ! (j1::nat) = (⌊zs::nat list⌋, 1::nat)› ‹tps ! j2 = (⌊0⌋⇩N, 1)› ‹ttt = 18 + 2 * length zs› ‹tps' = tps[j2 := (⌊zs = [] ∨ last zs = z⌋⇩B, 1)]›*) loc.tps4_def (*‹⟦j1 ≠ j2; j1 < ?k; j2 < ?k; length ?tps0.0 = ?k; ∀i<length ?zs. Suc 0 < ?zs ! i; ?tps0.0 ! j1 = (⌊?zs⌋, 1); ?tps0.0 ! j2 = (⌊0⌋⇩N, 1)⟧ ⟹ loc.tps4 ?tps0.0 ?zs ≡ ?tps0.0[j2 := (⌊?zs = [] ∨ last ?zs = z⌋⇩B, 1)]›*) loc.tm4 (*‹⟦(j1::nat) ≠ (j2::nat); j1 < (?k::nat); j2 < ?k; length (?tps0.0::((nat ⇒ nat) × nat) list) = ?k; ∀i<length (?zs::nat list). Suc (0::nat) < ?zs ! i; ?tps0.0 ! j1 = (⌊?zs⌋, 1::nat); ?tps0.0 ! j2 = (⌊0::nat⌋⇩N, 1::nat); (?ttt::nat) = (18::nat) + (2::nat) * length ?zs⟧ ⟹ transforms loc.tm4 ?tps0.0 ?ttt (loc.tps4 ?tps0.0 ?zs)›*) loc.tm4_eq_tm_empty_or_endswith (*‹loc.tm4 = tm_empty_or_endswith j1 j2 z›*) by simp qed subsection ‹Stripping trailing symbols› text ‹ Stripping the symbol $z$ from the end of a symbol sequence @{term zs} means: › definition rstrip :: "symbol ⇒ symbol list ⇒ symbol list" where "rstrip z zs ≡ take (LEAST i. i ≤ length zs ∧ set (drop i zs) ⊆ {z}) zs" lemma length_rstrip: "length (rstrip z zs) = (LEAST i. i ≤ length zs ∧ set (drop i zs) ⊆ {z})" using rstrip_def (*‹rstrip ?z ?zs ≡ take (LEAST i. i ≤ length ?zs ∧ set (drop i ?zs) ⊆ {?z}) ?zs›*) wellorder_Least_lemma[where ?P = "λi. i ≤ length zs ∧ set (drop i zs) ⊆ {z}"] (*‹?k ≤ length zs ∧ set (drop ?k zs) ⊆ {z} ⟹ (LEAST x. x ≤ length zs ∧ set (drop x zs) ⊆ {z}) ≤ length zs ∧ set (drop (LEAST x. x ≤ length zs ∧ set (drop x zs) ⊆ {z}) zs) ⊆ {z}› ‹(?k::nat) ≤ length (zs::nat list) ∧ set (drop ?k zs) ⊆ {z::nat} ⟹ (LEAST x::nat. x ≤ length zs ∧ set (drop x zs) ⊆ {z}) ≤ ?k›*) by simp lemma length_rstrip_le: "length (rstrip z zs) ≤ length zs" using rstrip_def (*‹rstrip ?z ?zs ≡ take (LEAST i. i ≤ length ?zs ∧ set (drop i ?zs) ⊆ {?z}) ?zs›*) by simp lemma rstrip_stripped: assumes "i ≥ length (rstrip z zs)" and "i < length zs" shows "zs ! i = z" proof (-) (*goal: ‹zs ! i = z›*) let ?P = "λi. i ≤ length zs ∧ set (drop i zs) ⊆ {z}" have "?P (length zs)" by simp then have "?P i" using assms (*‹length (rstrip z zs) ≤ i› ‹i < length zs›*) length_rstrip (*‹length (rstrip (?z::nat) (?zs::nat list)) = (LEAST i::nat. i ≤ length ?zs ∧ set (drop i ?zs) ⊆ {?z})›*) LeastI[where ?P = "?P"] (*‹(?k::nat) ≤ length (zs::nat list) ∧ set (drop ?k zs) ⊆ {z::nat} ⟹ (LEAST x::nat. x ≤ length zs ∧ set (drop x zs) ⊆ {z}) ≤ length zs ∧ set (drop (LEAST x::nat. x ≤ length zs ∧ set (drop x zs) ⊆ {z}) zs) ⊆ {z}›*) Least_le[where ?P = "?P"] (*‹?k ≤ length zs ∧ set (drop ?k zs) ⊆ {z} ⟹ (LEAST x. x ≤ length zs ∧ set (drop x zs) ⊆ {z}) ≤ ?k›*) by (metis (mono_tags, lifting) dual_order.trans (*‹⟦?b ≤ ?a; ?c ≤ ?b⟧ ⟹ ?c ≤ ?a›*) order_less_imp_le (*‹?x < ?y ⟹ ?x ≤ ?y›*) set_drop_subset_set_drop (*‹?n ≤ ?m ⟹ set (drop ?m ?xs) ⊆ set (drop ?n ?xs)›*)) then have "set (drop i zs) ⊆ {z}" by simp then show "?thesis" (*goal: ‹zs ! i = z›*) using assms(2) (*‹(i::nat) < length (zs::nat list)›*) by (metis Cons_nth_drop_Suc (*‹?i < length ?xs ⟹ ?xs ! ?i # drop (Suc ?i) ?xs = drop ?i ?xs›*) drop_eq_Nil2 (*‹([] = drop ?n ?xs) = (length ?xs ≤ ?n)›*) leD (*‹?y ≤ ?x ⟹ ¬ ?x < ?y›*) list.set( (*‹set (?x21.0 # ?x22.0) = insert ?x21.0 (set ?x22.0)›*) 2) set_empty (*‹(set ?xs = {}) = (?xs = [])›*) singleton_insert_inj_eq (*‹({?b} = insert ?a ?A) = (?a = ?b ∧ ?A ⊆ {?b})›*) subset_singletonD (*‹?A ⊆ {?x} ⟹ ?A = {} ∨ ?A = {?x}›*)) qed lemma rstrip_replicate: "rstrip z (replicate n z) = []" using rstrip_def (*‹rstrip ?z ?zs ≡ take (LEAST i. i ≤ length ?zs ∧ set (drop i ?zs) ⊆ {?z}) ?zs›*) by (metis (no_types, lifting) Least_eq_0 (*‹?P 0 ⟹ Least ?P = 0›*) empty_replicate (*‹([] = replicate ?n ?x) = (?n = 0)›*) set_drop_subset (*‹set (drop ?n ?xs) ⊆ set ?xs›*) set_replicate (*‹?n ≠ 0 ⟹ set (replicate ?n ?x) = {?x}›*) take_eq_Nil (*‹(take ?n ?xs = []) = (?n = 0 ∨ ?xs = [])›*) zero_le (*‹0 ≤ ?x›*)) lemma rstrip_not_ex: assumes "¬ (∃i<length zs. zs ! i ≠ z)" shows "rstrip z zs = []" using assms (*‹¬ (∃i<length zs. zs ! i ≠ z)›*) rstrip_def (*‹rstrip (?z::nat) (?zs::nat list) ≡ take (LEAST i::nat. i ≤ length ?zs ∧ set (drop i ?zs) ⊆ {?z}) ?zs›*) by (metis in_set_conv_nth (*‹(?x ∈ set ?xs) = (∃i<length ?xs. ?xs ! i = ?x)›*) replicate_eqI (*‹⟦length ?xs = ?n; ⋀y. y ∈ set ?xs ⟹ y = ?x⟧ ⟹ ?xs = replicate ?n ?x›*) rstrip_replicate (*‹rstrip ?z (replicate ?n ?z) = []›*)) lemma assumes "∃i<length zs. zs ! i ≠ z" shows rstrip_ex_length: "length (rstrip z zs) > 0" and rstrip_ex_last: "last (rstrip z zs) ≠ z" proof (-) (*goals: 1. ‹0 < length (rstrip z zs)› 2. ‹last (rstrip z zs) ≠ z›*) let ?P = "λi. i ≤ length zs ∧ set (drop i zs) ⊆ {z}" obtain i where i: "i < length zs" "zs ! i ≠ z" (*goal: ‹(⋀i. ⟦i < length zs; zs ! i ≠ z⟧ ⟹ thesis) ⟹ thesis›*) using assms (*‹∃i<length zs. zs ! i ≠ z›*) by auto then have "¬ set (drop i zs) ⊆ {z}" by (metis Cons_nth_drop_Suc (*‹?i < length ?xs ⟹ ?xs ! ?i # drop (Suc ?i) ?xs = drop ?i ?xs›*) drop_eq_Nil2 (*‹([] = drop ?n ?xs) = (length ?xs ≤ ?n)›*) leD (*‹?y ≤ ?x ⟹ ¬ ?x < ?y›*) list.set( (*‹set (?x21.0 # ?x22.0) = insert ?x21.0 (set ?x22.0)›*) 2) set_empty (*‹(set ?xs = {}) = (?xs = [])›*) singleton_insert_inj_eq' (*‹(insert ?a ?A = {?b}) = (?a = ?b ∧ ?A ⊆ {?b})›*) subset_singletonD (*‹?A ⊆ {?x} ⟹ ?A = {} ∨ ?A = {?x}›*)) then have "¬ set (drop 0 zs) ⊆ {z}" by (metis drop.simps( (*‹drop ?n [] = []›*) 1) drop_0 (*‹drop 0 ?xs = ?xs›*) set_drop_subset (*‹set (drop ?n ?xs) ⊆ set ?xs›*) set_empty (*‹(set ?xs = {}) = (?xs = [])›*) subset_singletonD (*‹?A ⊆ {?x} ⟹ ?A = {} ∨ ?A = {?x}›*)) then show len: "length (rstrip z zs) > 0" using length_rstrip (*‹length (rstrip ?z ?zs) = (LEAST i. i ≤ length ?zs ∧ set (drop i ?zs) ⊆ {?z})›*) by (metis (no_types, lifting) LeastI (*‹(?P::?'a::wellorder ⇒ bool) (?k::?'a::wellorder) ⟹ ?P (LEAST x::?'a::wellorder. ?P x)›*) bot.extremum (*‹bot ≤ (?a::?'a::order_bot)›*) drop_all (*‹length (?xs::?'a::type list) ≤ (?n::nat) ⟹ drop ?n ?xs = []›*) dual_order.refl (*‹(?a::?'a::preorder) ≤ ?a›*) gr0I (*‹((?n::nat) = (0::nat) ⟹ 𝕆) ⟹ (0::nat) < ?n›*) list.set( (*‹set [] = {}›*) 1)) let ?j = "length (rstrip z zs) - 1" have 3: "?j < length (rstrip z zs)" using len (*‹0 < length (rstrip z zs)›*) by simp then have 4: "?j < Least ?P" using length_rstrip (*‹length (rstrip ?z ?zs) = (LEAST i. i ≤ length ?zs ∧ set (drop i ?zs) ⊆ {?z})›*) by simp have 5: "?P (length (rstrip z zs))" using LeastI_ex[of "?P"] (*‹∃x≤length (zs::nat list). set (drop x zs) ⊆ {z::nat} ⟹ (LEAST i::nat. i ≤ length zs ∧ set (drop i zs) ⊆ {z}) ≤ length zs ∧ set (drop (LEAST i::nat. i ≤ length zs ∧ set (drop i zs) ⊆ {z}) zs) ⊆ {z}›*) length_rstrip (*‹length (rstrip ?z ?zs) = (LEAST i. i ≤ length ?zs ∧ set (drop i ?zs) ⊆ {?z})›*) by fastforce show "last (rstrip z zs) ≠ z" proof (rule ccontr (*‹(¬ ?P ⟹ 𝕆) ⟹ ?P›*)) (*goal: ‹¬ last (rstrip z zs) ≠ z ⟹ 𝕆›*) assume "¬ last (rstrip z zs) ≠ z" (*‹¬ last (rstrip (z::nat) (zs::nat list)) ≠ z›*) then have "last (rstrip z zs) = z" by simp then have "rstrip z zs ! ?j = z" using len (*‹0 < length (rstrip z zs)›*) by (simp add: last_conv_nth (*‹?xs ≠ [] ⟹ last ?xs = ?xs ! (length ?xs - 1)›*)) then have 2: "zs ! ?j = z" using len (*‹(0::nat) < length (rstrip (z::nat) (zs::nat list))›*) length_rstrip (*‹length (rstrip ?z ?zs) = (LEAST i. i ≤ length ?zs ∧ set (drop i ?zs) ⊆ {?z})›*) rstrip_def (*‹rstrip ?z ?zs ≡ take (LEAST i. i ≤ length ?zs ∧ set (drop i ?zs) ⊆ {?z}) ?zs›*) by auto have "?P ?j" proof (-) (*goal: ‹length (rstrip z zs) - 1 ≤ length zs ∧ set (drop (length (rstrip z zs) - 1) zs) ⊆ {z}›*) have "?j ≤ length zs" using "3" (*‹length (rstrip z zs) - 1 < length (rstrip z zs)›*) length_rstrip_le (*‹length (rstrip ?z ?zs) ≤ length ?zs›*) by (meson le_eq_less_or_eq (*‹(?m ≤ ?n) = (?m < ?n ∨ ?m = ?n)›*) order_less_le_trans (*‹⟦?x < ?y; ?y ≤ ?z⟧ ⟹ ?x < ?z›*)) moreover have "set (drop ?j zs) ⊆ {z}" using "5" (*‹length (rstrip (z::nat) (zs::nat list)) ≤ length zs ∧ set (drop (length (rstrip z zs)) zs) ⊆ {z}›*) "3" (*‹length (rstrip (z::nat) (zs::nat list)) - (1::nat) < length (rstrip z zs)›*) "2" (*‹zs ! (length (rstrip z zs) - 1) = z›*) by (metis Cons_nth_drop_Suc (*‹(?i::nat) < length (?xs::?'a list) ⟹ ?xs ! ?i # drop (Suc ?i) ?xs = drop ?i ?xs›*) One_nat_def (*‹(1::nat) = Suc (0::nat)›*) Suc_pred (*‹(0::nat) < (?n::nat) ⟹ Suc (?n - Suc (0::nat)) = ?n›*) insert_subset (*‹(insert (?x::?'a) (?A::?'a set) ⊆ (?B::?'a set)) = (?x ∈ ?B ∧ ?A ⊆ ?B)›*) len (*‹(0::nat) < length (rstrip (z::nat) (zs::nat list))›*) list.simps( (*‹set ((?x21.0::?'a) # (?x22.0::?'a list)) = insert ?x21.0 (set ?x22.0)›*) 15) order_less_le_trans (*‹⟦(?x::?'a) < (?y::?'a); ?y ≤ (?z::?'a)⟧ ⟹ ?x < ?z›*) set_eq_subset (*‹((?A::?'a set) = (?B::?'a set)) = (?A ⊆ ?B ∧ ?B ⊆ ?A)›*)) ultimately show "?thesis" (*goal: ‹length (rstrip z zs) - 1 ≤ length zs ∧ set (drop (length (rstrip z zs) - 1) zs) ⊆ {z}›*) by simp qed then show False using "4" (*‹length (rstrip (z::nat) (zs::nat list)) - (1::nat) < (LEAST i::nat. i ≤ length zs ∧ set (drop i zs) ⊆ {z})›*) Least_le[of "?P"] (*‹?k ≤ length zs ∧ set (drop ?k zs) ⊆ {z} ⟹ (LEAST x. x ≤ length zs ∧ set (drop x zs) ⊆ {z}) ≤ ?k›*) by fastforce qed qed text ‹ A Turing machine stripping the non-blank, non-start symbol $z$ from a proper symbol sequence works in the obvious way. First it moves to the end of the symbol sequence, that is, to the first blank. Then it moves left to the first non-$z$ symbol thereby overwriting every symbol with a blank. Finally it performs a ``carriage return''. › definition tm_rstrip :: "symbol ⇒ tapeidx ⇒ machine" where "tm_rstrip z j ≡ tm_right_until j {□} ;; tm_left j ;; tm_lconst_until j j (UNIV - {z}) □ ;; tm_cr j" lemma tm_rstrip_tm: assumes "k ≥ 2" and "G ≥ 4" and "0 < j" and "j < k" shows "turing_machine k G (tm_rstrip z j)" using assms (*‹2 ≤ k› ‹4 ≤ G› ‹0 < j› ‹j < k›*) tm_right_until_tm (*‹⟦?j < ?k; 2 ≤ ?k; 4 ≤ ?G⟧ ⟹ turing_machine ?k ?G (tm_right_until ?j ?H)›*) tm_left_tm (*‹⟦2 ≤ ?k; 4 ≤ ?G⟧ ⟹ turing_machine ?k ?G (tm_left ?j)›*) tm_lconst_until_tm (*‹⟦0 < ?j2.0; ?j1.0 < ?k; ?j2.0 < ?k; ?h < ?G; 2 ≤ ?k; 4 ≤ ?G⟧ ⟹ turing_machine ?k ?G (tm_lconst_until ?j1.0 ?j2.0 ?H ?h)›*) tm_cr_tm (*‹⟦2 ≤ ?k; 4 ≤ ?G⟧ ⟹ turing_machine ?k ?G (tm_cr ?j)›*) tm_rstrip_def (*‹tm_rstrip ?z ?j ≡ tm_right_until ?j {0} ;; tm_left ?j ;; tm_lconst_until ?j ?j (UNIV - {?z}) 0 ;; tm_cr ?j›*) by simp locale turing_machine_rstrip = fixes z :: symbol and j :: tapeidx begin definition "tm1 ≡ tm_right_until j {□}" definition "tm2 ≡ tm1 ;; tm_left j" definition "tm3 ≡ tm2 ;; tm_lconst_until j j (UNIV - {z}) □" definition "tm4 ≡ tm3 ;; tm_cr j" lemma tm4_eq_tm_rstrip: "tm4 = tm_rstrip z j" unfolding tm4_def tm3_def tm2_def tm1_def tm_rstrip_def (*goal: ‹tm_right_until j {0} ;; tm_left j ;; tm_lconst_until j j (UNIV - {z}) 0 ;; tm_cr j = tm_right_until j {0} ;; tm_left j ;; tm_lconst_until j j (UNIV - {z}) 0 ;; tm_cr j›*) by simp context fixes tps0 :: "tape list" and zs :: "symbol list" and k :: nat assumes z: "z > 1" assumes zs: "proper_symbols zs" assumes jk: "0 < j" "j < k" "length tps0 = k" assumes tps0: "tps0 ! j = (⌊zs⌋, 1)" begin definition "tps1 ≡ tps0 [j := (⌊zs⌋, Suc (length zs))]" lemma tm1 [transforms_intros]: assumes "ttt = Suc (length zs)" shows "transforms tm1 tps0 ttt tps1" unfolding tm1_def (*goal: ‹transforms (tm_right_until (j::nat) {0::nat}) (tps0::((nat ⇒ nat) × nat) list) (ttt::nat) tps1›*) proof (tform tps: tps0 tps1_def jk time: assms) (*goal: ‹rneigh (tps0 ! j) {0} (length zs)›*) have "*": "tps0 ! j = (⌊zs⌋, 1)" using tps0 (*‹tps0 ! j = (⌊zs⌋, 1)›*) jk (*‹0 < j› ‹j < k› ‹length tps0 = k›*) by simp show "rneigh (tps0 ! j) {□} (length zs)" using "*" (*‹tps0 ! j = (⌊zs⌋, 1)›*) zs (*‹∀i<length zs. Suc 0 < zs ! i›*) apply (intro rneighI (*‹⟦fst (?tp::(nat ⇒ nat) × nat) (snd ?tp + (?n::nat)) ∈ (?H::nat set); ⋀n'::nat. n' < ?n ⟹ fst ?tp (snd ?tp + n') ∉ ?H⟧ ⟹ rneigh ?tp ?H ?n›*)) (*goals: 1. ‹⟦tps0 ! j = (⌊zs⌋, 1); ∀i<length zs. Suc 0 < zs ! i⟧ ⟹ (tps0 ::: j) (tps0 :#: j + length zs) ∈ {0}› 2. ‹⋀n'. ⟦tps0 ! j = (⌊zs⌋, 1); ∀i<length zs. Suc 0 < zs ! i; n' < length zs⟧ ⟹ (tps0 ::: j) (tps0 :#: j + n') ∉ {0}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed definition "tps2 ≡ tps0 [j := (⌊zs⌋, length zs)]" lemma tm2 [transforms_intros]: assumes "ttt = length zs + 2" shows "transforms tm2 tps0 ttt tps2" unfolding tm2_def (*goal: ‹transforms (tm1 ;; tm_left j) tps0 ttt tps2›*) by (tform tps: tps1_def tps2_def jk time: assms) definition "tps3 ≡ tps0 [j := (⌊rstrip z zs⌋, length (rstrip z zs))]" lemma tm3 [transforms_intros]: assumes "ttt = length zs + 2 + Suc (length zs - length (rstrip z zs))" shows "transforms tm3 tps0 ttt tps3" unfolding tm3_def (*goal: ‹transforms (tm2 ;; tm_lconst_until j j (UNIV - {z}) 0) tps0 ttt tps3›*) proof (tform tps: tps2_def tps3_def jk time: assms jk tps2_def) (*goals: 1. ‹lneigh (tps2 ! j) (UNIV - {z}) (length zs - length (rstrip z zs))› 2. ‹tps3 = tps2[j := tps2 ! j |-| length zs - length (rstrip z zs), j := lconstplant (tps2 ! j) 0 (length zs - length (rstrip z zs))]›*) let ?n = "length zs - length (rstrip z zs)" have "*": "tps2 ! j = (⌊zs⌋, length zs)" using tps2_def (*‹tps2 ≡ tps0[j := (⌊zs⌋, length zs)]›*) jk (*‹0 < j› ‹j < k› ‹length tps0 = k›*) by simp show "lneigh (tps2 ! j) (UNIV - {z}) ?n" proof (cases "∃i<length zs. zs ! i ≠ z") (*goals: 1. ‹∃i<length zs. zs ! i ≠ z ⟹ lneigh (tps2 ! j) (UNIV - {z}) (length zs - length (rstrip z zs))› 2. ‹¬ (∃i<length zs. zs ! i ≠ z) ⟹ lneigh (tps2 ! j) (UNIV - {z}) (length zs - length (rstrip z zs))›*) case True (*‹∃i<length zs. zs ! i ≠ z›*) then have 1: "length (rstrip z zs) > 0" using rstrip_ex_length (*‹∃i<length ?zs. ?zs ! i ≠ ?z ⟹ 0 < length (rstrip ?z ?zs)›*) by simp show "?thesis" (*goal: ‹lneigh (tps2 ! j) (UNIV - {z}) (length zs - length (rstrip z zs))›*) proof (rule lneighI (*‹⟦fst ?tp (snd ?tp - ?n) ∈ ?H; ⋀n'. n' < ?n ⟹ fst ?tp (snd ?tp - n') ∉ ?H⟧ ⟹ lneigh ?tp ?H ?n›*)) (*goals: 1. ‹(tps2 ::: j) (tps2 :#: j - (length zs - length (rstrip z zs))) ∈ UNIV - {z}› 2. ‹⋀n'. n' < length zs - length (rstrip z zs) ⟹ (tps2 ::: j) (tps2 :#: j - n') ∉ UNIV - {z}›*) show "(tps2 ::: j) (tps2 :#: j - ?n) ∈ UNIV - {z}" using "*" (*‹tps2 ! j = (⌊zs⌋, length zs)›*) "1" (*‹(0::nat) < length (rstrip (z::nat) (zs::nat list))›*) contents_inbounds (*‹⟦0 < ?i; ?i ≤ length ?zs⟧ ⟹ ⌊?zs⌋ ?i = ?zs ! (?i - 1)›*) True (*‹∃i<length zs. zs ! i ≠ z›*) length_rstrip (*‹length (rstrip ?z ?zs) = (LEAST i. i ≤ length ?zs ∧ set (drop i ?zs) ⊆ {?z})›*) length_rstrip_le (*‹length (rstrip ?z ?zs) ≤ length ?zs›*) rstrip_def (*‹rstrip ?z ?zs ≡ take (LEAST i. i ≤ length ?zs ∧ set (drop i ?zs) ⊆ {?z}) ?zs›*) rstrip_ex_last (*‹∃i<length (?zs::nat list). ?zs ! i ≠ (?z::nat) ⟹ last (rstrip ?z ?zs) ≠ ?z›*) by (smt (verit, best) DiffI (*‹⟦?c ∈ ?A; ?c ∉ ?B⟧ ⟹ ?c ∈ ?A - ?B›*) One_nat_def (*‹1 = Suc 0›*) UNIV_I (*‹?x ∈ UNIV›*) diff_diff_cancel (*‹?i ≤ ?n ⟹ ?n - (?n - ?i) = ?i›*) diff_less (*‹⟦0 < ?n; 0 < ?m⟧ ⟹ ?m - ?n < ?m›*) fst_conv (*‹fst (?x1.0, ?x2.0) = ?x1.0›*) last_conv_nth (*‹?xs ≠ [] ⟹ last ?xs = ?xs ! (length ?xs - 1)›*) le_eq_less_or_eq (*‹(?m ≤ ?n) = (?m < ?n ∨ ?m = ?n)›*) length_greater_0_conv (*‹(0 < length ?xs) = (?xs ≠ [])›*) less_Suc_eq_le (*‹(?m < Suc ?n) = (?m ≤ ?n)›*) nth_take (*‹?i < ?n ⟹ take ?n ?xs ! ?i = ?xs ! ?i›*) singletonD (*‹?b ∈ {?a} ⟹ ?b = ?a›*) snd_conv (*‹snd (?x1.0, ?x2.0) = ?x2.0›*)) have "⋀n'. n' < ?n ⟹ (tps2 ::: j) (tps2 :#: j - n') = z" using "*" (*‹tps2 ! j = (⌊zs⌋, length zs)›*) rstrip_stripped (*‹⟦length (rstrip ?z ?zs) ≤ ?i; ?i < length ?zs⟧ ⟹ ?zs ! ?i = ?z›*) by simp then show "⋀n'. n' < ?n ⟹ (tps2 ::: j) (tps2 :#: j - n') ∉ UNIV - {z}" by simp qed next (*goal: ‹¬ (∃i<length (zs::nat list). zs ! i ≠ (z::nat)) ⟹ lneigh (tps2 ! (j::nat)) (UNIV - {z}) (length zs - length (rstrip z zs))›*) case False (*‹¬ (∃i<length (zs::nat list). zs ! i ≠ (z::nat))›*) then have 1: "rstrip z zs = []" using rstrip_not_ex (*‹¬ (∃i<length ?zs. ?zs ! i ≠ ?z) ⟹ rstrip ?z ?zs = []›*) by simp show "?thesis" (*goal: ‹lneigh (tps2 ! j) (UNIV - {z}) (length zs - length (rstrip z zs))›*) proof (rule lneighI (*‹⟦fst ?tp (snd ?tp - ?n) ∈ ?H; ⋀n'. n' < ?n ⟹ fst ?tp (snd ?tp - n') ∉ ?H⟧ ⟹ lneigh ?tp ?H ?n›*)) (*goals: 1. ‹(tps2 ::: j) (tps2 :#: j - (length zs - length (rstrip z zs))) ∈ UNIV - {z}› 2. ‹⋀n'. n' < length zs - length (rstrip z zs) ⟹ (tps2 ::: j) (tps2 :#: j - n') ∉ UNIV - {z}›*) show "(tps2 ::: j) (tps2 :#: j - ?n) ∈ UNIV - {z}" using "*" (*‹tps2 ! j = (⌊zs⌋, length zs)›*) "1" (*‹rstrip z zs = []›*) z (*‹1 < z›*) by simp show "⋀n'. n' < ?n ⟹ (tps2 ::: j) (tps2 :#: j - n') ∉ UNIV - {z}" using "*" (*‹tps2 ! j = (⌊zs⌋, length zs)›*) rstrip_stripped (*‹⟦length (rstrip ?z ?zs) ≤ ?i; ?i < length ?zs⟧ ⟹ ?zs ! ?i = ?z›*) by simp qed qed have "lconstplant (⌊zs⌋, length zs) □ ?n = (⌊rstrip z zs⌋, length (rstrip z zs))" (is "?lhs = _") proof (-) (*goal: ‹lconstplant (⌊zs⌋, length zs) 0 (length zs - length (rstrip z zs)) = (⌊rstrip z zs⌋, length (rstrip z zs))›*) have "?lhs = (λi. if length zs - ?n < i ∧ i ≤ length zs then □ else ⌊zs⌋ i, length zs - ?n)" using lconstplant[of "(⌊zs⌋, length zs)" 0 "?n"] (*‹lconstplant (⌊zs⌋, length zs) 0 (length zs - length (rstrip z zs)) = (λi. if snd (⌊zs⌋, length zs) - (length zs - length (rstrip z zs)) < i ∧ i ≤ snd (⌊zs⌋, length zs) then 0 else fst (⌊zs⌋, length zs) i, snd (⌊zs⌋, length zs) - (length zs - length (rstrip z zs)))›*) by auto moreover have "(λi. if length zs - ?n < i ∧ i ≤ length zs then □ else ⌊zs⌋ i) = ⌊rstrip z zs⌋" proof (standard) (*goal: ‹⋀i::nat. (if length (zs::nat list) - (length zs - length (rstrip (z::nat) zs)) < i ∧ i ≤ length zs then 0::nat else ⌊zs⌋ i) = ⌊rstrip z zs⌋ i›*) fix i consider "length zs - ?n < i ∧ i ≤ length zs" | "i > length zs" | "i ≤ length (rstrip z zs)" (*goal: ‹⟦length zs - (length zs - length (rstrip z zs)) < i ∧ i ≤ length zs ⟹ thesis; length zs < i ⟹ thesis; i ≤ length (rstrip z zs) ⟹ thesis⟧ ⟹ thesis›*) by linarith then show "(if length zs - ?n < i ∧ i ≤ length zs then □ else ⌊zs⌋ i) = ⌊rstrip z zs⌋ i" proof (cases) (*goals: 1. ‹length zs - (length zs - length (rstrip z zs)) < i ∧ i ≤ length zs ⟹ (if length zs - (length zs - length (rstrip z zs)) < i ∧ i ≤ length zs then 0 else ⌊zs⌋ i) = ⌊rstrip z zs⌋ i› 2. ‹length zs < i ⟹ (if length zs - (length zs - length (rstrip z zs)) < i ∧ i ≤ length zs then 0 else ⌊zs⌋ i) = ⌊rstrip z zs⌋ i› 3. ‹i ≤ length (rstrip z zs) ⟹ (if length zs - (length zs - length (rstrip z zs)) < i ∧ i ≤ length zs then 0 else ⌊zs⌋ i) = ⌊rstrip z zs⌋ i›*) case 1 (*‹length (zs::nat list) - (length zs - length (rstrip (z::nat) zs)) < (i::nat) ∧ i ≤ length zs›*) then show "?thesis" (*goal: ‹(if length zs - (length zs - length (rstrip z zs)) < i ∧ i ≤ length zs then 0 else ⌊zs⌋ i) = ⌊rstrip z zs⌋ i›*) by auto next (*goals: 1. ‹length zs < i ⟹ (if length zs - (length zs - length (rstrip z zs)) < i ∧ i ≤ length zs then 0 else ⌊zs⌋ i) = ⌊rstrip z zs⌋ i› 2. ‹i ≤ length (rstrip z zs) ⟹ (if length zs - (length zs - length (rstrip z zs)) < i ∧ i ≤ length zs then 0 else ⌊zs⌋ i) = ⌊rstrip z zs⌋ i›*) case 2 (*‹length zs < i›*) then show "?thesis" (*goal: ‹(if length (zs::nat list) - (length zs - length (rstrip (z::nat) zs)) < (i::nat) ∧ i ≤ length zs then 0::nat else ⌊zs⌋ i) = ⌊rstrip z zs⌋ i›*) by (metis contents_outofbounds (*‹length (?zs::nat list) < (?i::nat) ⟹ ⌊?zs⌋ ?i = (0::nat)›*) diff_diff_cancel (*‹(?i::nat) ≤ (?n::nat) ⟹ ?n - (?n - ?i) = ?i›*) length_rstrip_le (*‹length (rstrip (?z::nat) (?zs::nat list)) ≤ length ?zs›*) less_imp_diff_less (*‹(?j::nat) < (?k::nat) ⟹ ?j - (?n::nat) < ?k›*)) next (*goal: ‹i ≤ length (rstrip z zs) ⟹ (if length zs - (length zs - length (rstrip z zs)) < i ∧ i ≤ length zs then 0 else ⌊zs⌋ i) = ⌊rstrip z zs⌋ i›*) case 3 (*‹i ≤ length (rstrip z zs)›*) then show "?thesis" (*goal: ‹(if length zs - (length zs - length (rstrip z zs)) < i ∧ i ≤ length zs then 0 else ⌊zs⌋ i) = ⌊rstrip z zs⌋ i›*) using contents_def (*‹⌊?xs⌋ ?i ≡ if ?i = 0 then 1 else if ?i ≤ length ?xs then ?xs ! (?i - 1) else 0›*) length_rstrip (*‹length (rstrip ?z ?zs) = (LEAST i. i ≤ length ?zs ∧ set (drop i ?zs) ⊆ {?z})›*) length_rstrip_le (*‹length (rstrip ?z ?zs) ≤ length ?zs›*) rstrip_def (*‹rstrip ?z ?zs ≡ take (LEAST i. i ≤ length ?zs ∧ set (drop i ?zs) ⊆ {?z}) ?zs›*) by auto qed qed moreover have "length zs - ?n = length (rstrip z zs)" using diff_diff_cancel (*‹?i ≤ ?n ⟹ ?n - (?n - ?i) = ?i›*) length_rstrip_le (*‹length (rstrip ?z ?zs) ≤ length ?zs›*) by simp ultimately show "?thesis" (*goal: ‹lconstplant (⌊zs::nat list⌋, length zs) (0::nat) (length zs - length (rstrip (z::nat) zs)) = (⌊rstrip z zs⌋, length (rstrip z zs))›*) by simp qed then have "lconstplant (tps2 ! j) □ ?n = (⌊rstrip z zs⌋, length (rstrip z zs))" using tps2_def (*‹tps2 ≡ tps0[j := (⌊zs⌋, length zs)]›*) jk (*‹(0::nat) < (j::nat)› ‹j < k› ‹length tps0 = k›*) by simp then show "tps3 = tps2 [j := tps2 ! j |-| ?n, j := lconstplant (tps2 ! j) □ ?n]" unfolding tps3_def tps2_def (*goal: ‹tps0[j := (⌊rstrip z zs⌋, length (rstrip z zs))] = tps0[j := (⌊zs⌋, length zs), j := tps0[j := (⌊zs⌋, length zs)] ! j |-| length zs - length (rstrip z zs), j := lconstplant (tps0[j := (⌊zs⌋, length zs)] ! j) 0 (length zs - length (rstrip z zs))]›*) by simp qed definition "tps4 ≡ tps0 [j := (⌊rstrip z zs⌋, 1)]" lemma tm4: assumes "ttt = length zs + 2 + Suc (length zs - length (rstrip z zs)) + length (rstrip z zs) + 2" shows "transforms tm4 tps0 ttt tps4" unfolding tm4_def (*goal: ‹transforms (tm3 ;; tm_cr j) tps0 ttt tps4›*) proof (tform tps: tps3_def tps4_def jk time: assms tps3_def jk) (*goal: ‹clean_tape (tps3 ! j)›*) show "clean_tape (tps3 ! j)" using tps3_def (*‹tps3 ≡ tps0[j := (⌊rstrip z zs⌋, length (rstrip z zs))]›*) jk (*‹(0::nat) < (j::nat)› ‹j < k› ‹length tps0 = k›*) zs (*‹∀i<length (zs::nat list). Suc (0::nat) < zs ! i›*) rstrip_def (*‹rstrip ?z ?zs ≡ take (LEAST i. i ≤ length ?zs ∧ set (drop i ?zs) ⊆ {?z}) ?zs›*) by simp qed lemma tm4': assumes "ttt = 3 * length zs + 5" shows "transforms tm4 tps0 ttt tps4" proof (-) (*goal: ‹transforms tm4 tps0 ttt tps4›*) let ?ttt = "length zs + 2 + Suc (length zs - length (rstrip z zs)) + length (rstrip z zs) + 2" have "?ttt = length zs + 5 + (length zs - length (rstrip z zs)) + length (rstrip z zs)" by simp also (*calculation: ‹length zs + 2 + Suc (length zs - length (rstrip z zs)) + length (rstrip z zs) + 2 = length zs + 5 + (length zs - length (rstrip z zs)) + length (rstrip z zs)›*) have "... ≤ length zs + 5 + length zs + length (rstrip z zs)" by simp also (*calculation: ‹length (zs::nat list) + (2::nat) + Suc (length zs - length (rstrip (z::nat) zs)) + length (rstrip z zs) + (2::nat) ≤ length zs + (5::nat) + length zs + length (rstrip z zs)›*) have "... ≤ length zs + 5 + length zs + length zs" using length_rstrip_le (*‹length (rstrip ?z ?zs) ≤ length ?zs›*) by simp also (*calculation: ‹length zs + 2 + Suc (length zs - length (rstrip z zs)) + length (rstrip z zs) + 2 ≤ length zs + 5 + length zs + length zs›*) have "... = 3 * length zs + 5" by simp finally (*calculation: ‹length zs + 2 + Suc (length zs - length (rstrip z zs)) + length (rstrip z zs) + 2 ≤ 3 * length zs + 5›*) have "?ttt ≤ 3 * length zs + 5" . then show "?thesis" (*goal: ‹transforms tm4 tps0 ttt tps4›*) using assms (*‹ttt = 3 * length zs + 5›*) transforms_monotone (*‹⟦transforms ?M ?tps ?t ?tps'; ?t ≤ ?t'⟧ ⟹ transforms ?M ?tps ?t' ?tps'›*) tm4 (*‹?ttt = length zs + 2 + Suc (length zs - length (rstrip z zs)) + length (rstrip z zs) + 2 ⟹ transforms tm4 tps0 ?ttt tps4›*) by simp qed end (* context *) end (* locale *) lemma transforms_tm_rstripI [transforms_intros]: fixes z :: symbol and j :: tapeidx fixes tps tps' :: "tape list" and zs :: "symbol list" and k :: nat assumes "z > 1" and "0 < j" "j < k" and "proper_symbols zs" and "length tps = k" assumes "tps ! j = (⌊zs⌋, 1)" assumes "ttt = 3 * length zs + 5" assumes "tps' = tps[j := (⌊rstrip z zs⌋, 1)]" shows "transforms (tm_rstrip z j) tps ttt tps'" proof (-) (*goal: ‹transforms (tm_rstrip z j) tps ttt tps'›*) interpret loc: turing_machine_rstrip z j . show "?thesis" (*goal: ‹transforms (tm_rstrip z j) tps ttt tps'›*) using assms (*‹1 < z› ‹(0::nat) < (j::nat)› ‹j < k› ‹∀i<length (zs::nat list). Suc (0::nat) < zs ! i› ‹length (tps::((nat ⇒ nat) × nat) list) = (k::nat)› ‹tps ! j = (⌊zs⌋, 1)› ‹ttt = 3 * length zs + 5› ‹tps' = tps[j := (⌊rstrip z zs⌋, 1)]›*) loc.tm4' (*‹⟦1 < z; ∀i<length ?zs. Suc 0 < ?zs ! i; 0 < j; j < ?k; length ?tps0.0 = ?k; ?tps0.0 ! j = (⌊?zs⌋, 1); ?ttt = 3 * length ?zs + 5⟧ ⟹ transforms loc.tm4 ?tps0.0 ?ttt (loc.tps4 ?tps0.0 ?zs)›*) loc.tps4_def (*‹⟦1 < z; ∀i<length ?zs. Suc 0 < ?zs ! i; 0 < j; j < ?k; length ?tps0.0 = ?k; ?tps0.0 ! j = (⌊?zs⌋, 1)⟧ ⟹ loc.tps4 ?tps0.0 ?zs ≡ ?tps0.0[j := (⌊rstrip z ?zs⌋, 1)]›*) loc.tm4_eq_tm_rstrip (*‹loc.tm4 = tm_rstrip z j›*) by simp qed subsection ‹Writing arbitrary length sequences of the same symbol› text ‹ The next Turing machine accepts a number $n$ on tape $j_1$ and writes the symbol sequence $z^n$ to tape $j_2$. The symbol $z$ is a parameter of the TM. The TM decrements the number on tape $j_1$ until it reaches zero. › definition tm_write_replicate :: "symbol ⇒ tapeidx ⇒ tapeidx ⇒ machine" where "tm_write_replicate z j1 j2 ≡ WHILE [] ; λrs. rs ! j1 ≠ □ DO tm_char j2 z ;; tm_decr j1 DONE ;; tm_cr j2" lemma tm_write_replicate_tm: assumes "0 < j1" and "0 < j2" and "j1 < k" and "j2 < k" and "j1 ≠ j2" and "G ≥ 4" and "z < G" shows "turing_machine k G (tm_write_replicate z j1 j2)" unfolding tm_write_replicate_def (*goal: ‹turing_machine k G (WHILE [] ; λrs. rs ! j1 ≠ 0 DO tm_char j2 z ;; tm_decr j1 DONE ;; tm_cr j2)›*) using turing_machine_loop_turing_machine (*‹⟦turing_machine ?k ?G ?M1.0; turing_machine ?k ?G ?M2.0⟧ ⟹ turing_machine ?k ?G (WHILE ?M1.0 ; ?cond DO ?M2.0 DONE)›*) Nil_tm (*‹⟦(4::nat) ≤ (?G::nat); (2::nat) ≤ (?k::nat)⟧ ⟹ turing_machine ?k ?G []›*) tm_char_tm (*‹⟦0 < ?j; ?j < ?k; 4 ≤ ?G; ?z < ?G⟧ ⟹ turing_machine ?k ?G (tm_char ?j ?z)›*) tm_decr_tm (*‹⟦4 ≤ ?G; 2 ≤ ?k; ?j < ?k; 0 < ?j⟧ ⟹ turing_machine ?k ?G (tm_decr ?j)›*) tm_cr_tm (*‹⟦2 ≤ ?k; 4 ≤ ?G⟧ ⟹ turing_machine ?k ?G (tm_cr ?j)›*) assms (*‹0 < j1› ‹0 < j2› ‹j1 < k› ‹j2 < k› ‹j1 ≠ j2› ‹4 ≤ G› ‹z < G›*) by simp locale turing_machine_write_replicate = fixes j1 j2 :: tapeidx and z :: symbol begin definition "tm1 ≡ tm_char j2 z" definition "tm2 ≡ tm1 ;; tm_decr j1" definition "tmL ≡ WHILE [] ; λrs. rs ! j1 ≠ □ DO tm2 DONE" definition "tm3 ≡ tmL ;; tm_cr j2" lemma tm3_eq_tm_write_replicate: "tm3 = tm_write_replicate z j1 j2" using tm3_def (*‹tm3 ≡ tmL ;; tm_cr j2›*) tm2_def (*‹tm2 ≡ tm1 ;; tm_decr j1›*) tm1_def (*‹tm1 ≡ tm_char j2 z›*) tm_write_replicate_def (*‹tm_write_replicate ?z ?j1.0 ?j2.0 ≡ WHILE [] ; λrs. rs ! ?j1.0 ≠ 0 DO tm_char ?j2.0 ?z ;; tm_decr ?j1.0 DONE ;; tm_cr ?j2.0›*) tmL_def (*‹tmL ≡ WHILE [] ; λrs. rs ! j1 ≠ 0 DO tm2 DONE›*) by simp context fixes tps0 :: "tape list" and k n :: nat assumes jk: "length tps0 = k" "0 < j1" "0 < j2" "j1 ≠ j2" "j1 < k" "j2 < k" and z: "1 < z" assumes tps0: "tps0 ! j1 = (⌊n⌋⇩N, 1)" "tps0 ! j2 = (⌊[]⌋, 1)" begin definition tpsL :: "nat ⇒ tape list" where "tpsL t ≡ tps0 [j1 := (⌊n - t⌋⇩N, 1), j2 := (⌊replicate t z⌋, Suc t)]" lemma tpsL0: "tpsL 0 = tps0" using tpsL_def (*‹tpsL ?t ≡ tps0[j1 := (⌊n - ?t⌋⇩N, 1), j2 := (⌊replicate ?t z⌋, Suc ?t)]›*) tps0 (*‹tps0 ! j1 = (⌊n⌋⇩N, 1)› ‹tps0 ! j2 = (⌊[]⌋, 1)›*) jk (*‹length tps0 = k› ‹(0::nat) < (j1::nat)› ‹(0::nat) < (j2::nat)› ‹j1 ≠ j2› ‹j1 < k› ‹j2 < k›*) by (metis One_nat_def (*‹1 = Suc 0›*) diff_zero (*‹?a - 0 = ?a›*) list_update_id (*‹?xs[?i := ?xs ! ?i] = ?xs›*) replicate_empty (*‹(replicate ?n ?x = []) = (?n = 0)›*)) definition tpsL1 :: "nat ⇒ tape list" where "tpsL1 t ≡ tps0 [j1 := (⌊n - t⌋⇩N, 1), j2 := (⌊replicate (Suc t) z⌋, Suc (Suc t))]" lemma tmL1 [transforms_intros]: "transforms tm1 (tpsL t) 1 (tpsL1 t)" unfolding tm1_def (*goal: ‹transforms (tm_char j2 z) (tpsL t) 1 (tpsL1 t)›*) proof (tform tps: tpsL_def tpsL1_def tps0 jk) (*goal: ‹tpsL1 t = (tpsL t)[j2 := tpsL t ! j2 |:=| z |+| 1]›*) have "tpsL t :#: j2 = Suc t" using tpsL1_def (*‹tpsL1 ?t ≡ tps0[j1 := (⌊n - ?t⌋⇩N, 1), j2 := (⌊replicate (Suc ?t) z⌋, Suc (Suc ?t))]›*) jk (*‹length tps0 = k› ‹(0::nat) < (j1::nat)› ‹(0::nat) < (j2::nat)› ‹j1 ≠ j2› ‹j1 < k› ‹j2 < k›*) by (metis length_list_update (*‹length (?xs[?i := ?x]) = length ?xs›*) nth_list_update_eq (*‹?i < length ?xs ⟹ ?xs[?i := ?x] ! ?i = ?x›*) snd_conv (*‹snd (?x1.0, ?x2.0) = ?x2.0›*) tpsL_def (*‹tpsL ?t ≡ tps0[j1 := (⌊n - ?t⌋⇩N, 1), j2 := (⌊replicate ?t z⌋, Suc ?t)]›*)) moreover have "tpsL t ::: j2 = ⌊replicate t z⌋" using tpsL1_def (*‹tpsL1 (?t::nat) ≡ (tps0::((nat ⇒ nat) × nat) list)[j1::nat := (⌊(n::nat) - ?t⌋⇩N, 1::nat), j2::nat := (⌊replicate (Suc ?t) (z::nat)⌋, Suc (Suc ?t))]›*) jk (*‹length tps0 = k› ‹0 < j1› ‹0 < j2› ‹j1 ≠ j2› ‹j1 < k› ‹j2 < k›*) by (metis fst_conv (*‹fst (?x1.0::?'a, ?x2.0::?'b) = ?x1.0›*) length_list_update (*‹length ((?xs::?'a list)[?i::nat := ?x::?'a]) = length ?xs›*) nth_list_update_eq (*‹(?i::nat) < length (?xs::?'a list) ⟹ ?xs[?i := ?x::?'a] ! ?i = ?x›*) tpsL_def (*‹tpsL (?t::nat) ≡ (tps0::((nat ⇒ nat) × nat) list)[j1::nat := (⌊(n::nat) - ?t⌋⇩N, 1::nat), j2::nat := (⌊replicate ?t (z::nat)⌋, Suc ?t)]›*)) moreover have "⌊replicate t z⌋(Suc t := z) = ⌊replicate (Suc t) z⌋" using contents_snoc (*‹⌊?ys⌋(Suc (length ?ys) := ?w) = ⌊?ys @ [?w]⌋›*) by (metis length_replicate (*‹length (replicate ?n ?x) = ?n›*) replicate_Suc (*‹replicate (Suc ?n) ?x = ?x # replicate ?n ?x›*) replicate_append_same (*‹replicate ?i ?x @ [?x] = ?x # replicate ?i ?x›*)) ultimately show "tpsL1 t = (tpsL t)[j2 := tpsL t ! j2 |:=| z |+| 1]" unfolding tpsL1_def tpsL_def (*goal: ‹tps0[j1 := (⌊n - t⌋⇩N, 1), j2 := (⌊replicate (Suc t) z⌋, Suc (Suc t))] = tps0[j1 := (⌊n - t⌋⇩N, 1), j2 := (⌊replicate t z⌋, Suc t), j2 := tps0[j1 := (⌊n - t⌋⇩N, 1), j2 := (⌊replicate t z⌋, Suc t)] ! j2 |:=| z |+| 1]›*) by simp qed lemma tmL2: assumes "ttt = 9 + 2 * nlength (n - t)" shows "transforms tm2 (tpsL t) ttt (tpsL (Suc t))" unfolding tm2_def (*goal: ‹transforms (tm1 ;; tm_decr j1) (tpsL t) ttt (tpsL (Suc t))›*) proof (tform tps: assms tpsL_def tpsL1_def tps0 jk) (*goal: ‹tpsL (Suc t) = (tpsL1 t)[j1 := (⌊n - t - 1⌋⇩N, 1)]›*) show "tpsL (Suc t) = (tpsL1 t)[j1 := (⌊n - t - 1⌋⇩N, 1)]" unfolding tpsL_def tpsL1_def (*goal: ‹(tps0::((nat ⇒ nat) × nat) list)[j1::nat := (⌊(n::nat) - Suc (t::nat)⌋⇩N, 1::nat), j2::nat := (⌊replicate (Suc t) (z::nat)⌋, Suc (Suc t))] = tps0[j1 := (⌊n - t⌋⇩N, 1::nat), j2 := (⌊replicate (Suc t) z⌋, Suc (Suc t)), j1 := (⌊n - t - (1::nat)⌋⇩N, 1::nat)]›*) using jk (*‹length (tps0::((nat ⇒ nat) × nat) list) = (k::nat)› ‹0 < j1› ‹0 < j2› ‹j1 ≠ j2› ‹(j1::nat) < (k::nat)› ‹j2 < k›*) by (simp add: list_update_swap (*‹?i ≠ ?i' ⟹ ?xs[?i := ?x, ?i' := ?x'] = ?xs[?i' := ?x', ?i := ?x]›*)) qed lemma tmL2' [transforms_intros]: assumes "ttt = 9 + 2 * nlength n" shows "transforms tm2 (tpsL t) ttt (tpsL (Suc t))" proof (-) (*goal: ‹transforms tm2 (tpsL t) ttt (tpsL (Suc t))›*) have "9 + 2 * nlength (n - t) ≤ 9 + 2 * nlength n" using nlength_mono[of "n - t" n] (*‹n - t ≤ n ⟹ nlength (n - t) ≤ nlength n›*) by simp then show "?thesis" (*goal: ‹transforms tm2 (tpsL t) ttt (tpsL (Suc t))›*) using assms (*‹ttt = 9 + 2 * nlength n›*) tmL2 (*‹?ttt = 9 + 2 * nlength (n - ?t) ⟹ transforms tm2 (tpsL ?t) ?ttt (tpsL (Suc ?t))›*) transforms_monotone (*‹⟦transforms ?M ?tps ?t ?tps'; ?t ≤ ?t'⟧ ⟹ transforms ?M ?tps ?t' ?tps'›*) by blast qed lemma tmL [transforms_intros]: assumes "ttt = n * (11 + 2 * nlength n) + 1" shows "transforms tmL (tpsL 0) ttt (tpsL n)" unfolding tmL_def (*goal: ‹transforms (WHILE [] ; λrs::nat list. rs ! (j1::nat) ≠ (0::nat) DO tm2 DONE) (tpsL (0::nat)) (ttt::nat) (tpsL (n::nat))›*) proof (tform) (*goals: 1. ‹⋀i. i < n ⟹ read (tpsL i) ! j1 ≠ 0› 2. ‹¬ read (tpsL n) ! j1 ≠ 0› 3. ‹n * (9 + 2 * nlength n + 2) + 1 ≤ ttt›*) let ?t = "9 + 2 * nlength n" show "⋀i. i < n ⟹ read (tpsL i) ! j1 ≠ □" using jk (*‹length tps0 = k› ‹0 < j1› ‹(0::nat) < (j2::nat)› ‹j1 ≠ j2› ‹j1 < k› ‹j2 < k›*) tpsL_def (*‹tpsL ?t ≡ tps0[j1 := (⌊n - ?t⌋⇩N, 1), j2 := (⌊replicate ?t z⌋, Suc ?t)]›*) read_ncontents_eq_0 (*‹⟦?tps ! ?j = (⌊?n⌋⇩N, 1); ?j < length ?tps⟧ ⟹ (read ?tps ! ?j = 0) = (?n = 0)›*) by simp show "¬ read (tpsL n) ! j1 ≠ □" using jk (*‹length tps0 = k› ‹0 < j1› ‹0 < j2› ‹j1 ≠ j2› ‹j1 < k› ‹j2 < k›*) tpsL_def (*‹tpsL ?t ≡ tps0[j1 := (⌊n - ?t⌋⇩N, 1), j2 := (⌊replicate ?t z⌋, Suc ?t)]›*) read_ncontents_eq_0 (*‹⟦?tps ! ?j = (⌊?n⌋⇩N, 1); ?j < length ?tps⟧ ⟹ (read ?tps ! ?j = 0) = (?n = 0)›*) by simp show "n * (9 + 2 * nlength n + 2) + 1 ≤ ttt" using assms (*‹ttt = n * (11 + 2 * nlength n) + 1›*) by simp qed definition tps3 :: "tape list" where "tps3 ≡ tps0 [j1 := (⌊0⌋⇩N, 1), j2 := (⌊replicate n z⌋, 1)]" lemma tm3: assumes "ttt = n * (12 + 2 * nlength n) + 4" shows "transforms tm3 (tpsL 0) ttt tps3" unfolding tm3_def (*goal: ‹transforms (tmL ;; tm_cr j2) (tpsL 0) ttt tps3›*) proof (tform tps: z tpsL_def tps3_def tps0 jk) (*goal: ‹ttt = n * (11 + 2 * nlength n) + 1 + (tpsL n :#: j2 + 2)›*) have "ttt = Suc (n * (11 + 2 * nlength n)) + Suc (Suc (Suc n))" proof (-) (*goal: ‹ttt = Suc (n * (11 + 2 * nlength n)) + Suc (Suc (Suc n))›*) have "Suc (n * (11 + 2 * nlength n)) + Suc (Suc (Suc n)) = n * (11 + 2 * nlength n) + 4 + n" by simp also (*calculation: ‹Suc (n * (11 + 2 * nlength n)) + Suc (Suc (Suc n)) = n * (11 + 2 * nlength n) + 4 + n›*) have "... = n * (12 + 2 * nlength n) + 4" by algebra finally (*calculation: ‹Suc (n * (11 + 2 * nlength n)) + Suc (Suc (Suc n)) = n * (12 + 2 * nlength n) + 4›*) have "Suc (n * (11 + 2 * nlength n)) + Suc (Suc (Suc n)) = ttt" using assms (*‹ttt = n * (12 + 2 * nlength n) + 4›*) by simp then show "?thesis" (*goal: ‹ttt = Suc (n * (11 + 2 * nlength n)) + Suc (Suc (Suc n))›*) by simp qed then show "ttt = n * (11 + 2 * nlength n) + 1 + (tpsL n :#: j2 + 2)" using tpsL_def (*‹tpsL ?t ≡ tps0[j1 := (⌊n - ?t⌋⇩N, 1), j2 := (⌊replicate ?t z⌋, Suc ?t)]›*) jk (*‹length tps0 = k› ‹0 < j1› ‹0 < j2› ‹j1 ≠ j2› ‹j1 < k› ‹j2 < k›*) by simp qed lemma tm3': assumes "ttt = n * (12 + 2 * nlength n) + 4" shows "transforms tm3 tps0 ttt tps3" using tm3 (*‹?ttt = n * (12 + 2 * nlength n) + 4 ⟹ transforms tm3 (tpsL 0) ?ttt tps3›*) tpsL0 (*‹tpsL 0 = tps0›*) assms (*‹ttt = n * (12 + 2 * nlength n) + 4›*) by simp end end lemma transforms_tm_write_replicateI [transforms_intros]: fixes j1 j2 :: tapeidx fixes tps tps' :: "tape list" and ttt k n :: nat assumes "length tps = k" "0 < j1" "0 < j2" "j1 ≠ j2" "j1 < k" "j2 < k" and "1 < z" assumes "tps ! j1 = (⌊n⌋⇩N, 1)" "tps ! j2 = (⌊[]⌋, 1)" assumes "ttt = n * (12 + 2 * nlength n) + 4" assumes "tps' = tps [j1 := (⌊0⌋⇩N, 1), j2 := (⌊replicate n z⌋, 1)]" shows "transforms (tm_write_replicate z j1 j2) tps ttt tps'" proof (-) (*goal: ‹transforms (tm_write_replicate z j1 j2) tps ttt tps'›*) interpret loc: turing_machine_write_replicate j1 j2 . show "?thesis" (*goal: ‹transforms (tm_write_replicate z j1 j2) tps ttt tps'›*) using assms (*‹length tps = k› ‹0 < j1› ‹0 < j2› ‹j1 ≠ j2› ‹j1 < k› ‹j2 < k› ‹1 < z› ‹(tps::((nat ⇒ nat) × nat) list) ! (j1::nat) = (⌊n::nat⌋⇩N, 1::nat)› ‹tps ! j2 = (⌊[]⌋, 1)› ‹(ttt::nat) = (n::nat) * ((12::nat) + (2::nat) * nlength n) + (4::nat)› ‹(tps'::((nat ⇒ nat) × nat) list) = (tps::((nat ⇒ nat) × nat) list)[j1::nat := (⌊0::nat⌋⇩N, 1::nat), j2::nat := (⌊replicate (n::nat) (z::nat)⌋, 1::nat)]›*) loc.tm3' (*‹⟦length (?tps0.0::((nat ⇒ nat) × nat) list) = (?k::nat); (0::nat) < (j1::nat); (0::nat) < (j2::nat); j1 ≠ j2; j1 < ?k; j2 < ?k; (1::nat) < (z::nat); ?tps0.0 ! j1 = (⌊?n::nat⌋⇩N, 1::nat); ?tps0.0 ! j2 = (⌊[]⌋, 1::nat); (?ttt::nat) = ?n * ((12::nat) + (2::nat) * nlength ?n) + (4::nat)⟧ ⟹ transforms loc.tm3 ?tps0.0 ?ttt (loc.tps3 ?tps0.0 ?n)›*) loc.tps3_def (*‹⟦length ?tps0.0 = ?k; 0 < j1; 0 < j2; j1 ≠ j2; j1 < ?k; j2 < ?k; 1 < z; ?tps0.0 ! j1 = (⌊?n⌋⇩N, 1); ?tps0.0 ! j2 = (⌊[]⌋, 1)⟧ ⟹ loc.tps3 ?tps0.0 ?n ≡ ?tps0.0[j1 := (⌊0⌋⇩N, 1), j2 := (⌊replicate ?n z⌋, 1)]›*) loc.tm3_eq_tm_write_replicate (*‹loc.tm3 = tm_write_replicate z j1 j2›*) by simp qed subsection ‹Extracting the elements of a pair› text ‹ In Section~\ref{s:tm-basic-pair} we defined a pairing function for strings. For example, $\langle \bbbI\bbbI, \bbbO\bbbO\rangle$ is first mapped to $\bbbI\bbbI\#\bbbO\bbbO$ and ultimately represented as $\bbbO\bbbI\bbbO\bbbI\bbbI\bbbI\bbbO\bbbO\bbbO\bbbO$. A Turing machine that is to compute a function for the argument $\langle \bbbI\bbbI, \bbbO\bbbO\rangle$ would receive as input the symbols \textbf{0101110000}. Typically the TM would then extract the two components \textbf{11} and \textbf{00}. In this section we devise TMs to do just that. As it happens, applying the quaternary alphabet decoding function @{const bindecode} (see Section~\ref{s:tm-quaternary}) to such a symbol sequence gets us halfway to extracting the elements of the pair. For example, decoding \textbf{0101110000} yields @{text "𝟭𝟭♯𝟬𝟬"}, and now the TM only has to locate the @{text ♯}. A Turing machine cannot rely on being given a well-formed pair. After decoding, the symbol sequence might have more or fewer than one @{text ♯} symbol or even @{text "¦"} symbols. The following functions @{term first} and @{term second} are designed to extract the first and second element of a symbol sequence representing a pair, and for other symbol sequences at least allow for an efficient implementation. Implementations will come further down in this section. › definition first :: "symbol list ⇒ symbol list" where "first ys ≡ take (if ∃i<length ys. ys ! i ∈ {¦, ♯} then LEAST i. i < length ys ∧ ys ! i ∈ {¦, ♯} else length ys) ys" definition second :: "symbol list ⇒ symbol list" where "second zs ≡ drop (Suc (length (first zs))) zs" lemma firstD: assumes "∃i<length ys. ys ! i ∈ {¦, ♯}" and "m = (LEAST i. i < length ys ∧ ys ! i ∈ {¦, ♯})" shows "m < length ys" and "ys ! m ∈ {¦, ♯}" and "∀i<m. ys ! i ∉ {¦, ♯}" using LeastI_ex[OF assms ( 1 )] (*‹(LEAST i::nat. i < length (ys::nat list) ∧ ys ! i ∈ {4::nat, 5::nat}) < length ys ∧ ys ! (LEAST i::nat. i < length ys ∧ ys ! i ∈ {4::nat, 5::nat}) ∈ {4::nat, 5::nat}›*) assms(2) (*‹m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5})›*) apply - (*goals: 1. ‹⟦(LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}) < length ys ∧ ys ! (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}) ∈ {4, 5}; m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5})⟧ ⟹ m < length ys› 2. ‹⟦(LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}) < length ys ∧ ys ! (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}) ∈ {4, 5}; m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5})⟧ ⟹ ys ! m ∈ {4, 5}› 3. ‹⟦(LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}) < length ys ∧ ys ! (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}) ∈ {4, 5}; m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5})⟧ ⟹ ∀i<m. ys ! i ∉ {4, 5}› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*goal: ‹⟦(LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}) < length ys ∧ ys ! (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}) ∈ {4, 5}; m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5})⟧ ⟹ ∀i<m. ys ! i ∉ {4, 5}›*) apply (use less_trans not_less_Least in blast) (*proven 3 subgoals*) . lemma firstI: assumes "m < length ys" and "ys ! m ∈ {¦, ♯}" and "∀i<m. ys ! i ∉ {¦, ♯}" shows "(LEAST i. i < length ys ∧ ys ! i ∈ {¦, ♯}) = m" using assms (*‹m < length ys› ‹ys ! m ∈ {4, 5}› ‹∀i<m. ys ! i ∉ {4, 5}›*) by (metis (mono_tags, lifting) LeastI (*‹?P ?k ⟹ ?P (LEAST x. ?P x)›*) less_linear (*‹?x < ?y ∨ ?x = ?y ∨ ?y < ?x›*) not_less_Least (*‹?k < (LEAST x. ?P x) ⟹ ¬ ?P ?k›*)) lemma length_first_ex: assumes "∃i<length ys. ys ! i ∈ {¦, ♯}" and "m = (LEAST i. i < length ys ∧ ys ! i ∈ {¦, ♯})" shows "length (first ys) = m" proof (-) (*goal: ‹length (first ys) = m›*) have "m < length ys" using assms (*‹∃i<length ys. ys ! i ∈ {4, 5}› ‹m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5})›*) firstD(1) (*‹⟦∃i<length (?ys::nat list). ?ys ! i ∈ {4::nat, 5::nat}; (?m::nat) = (LEAST i::nat. i < length ?ys ∧ ?ys ! i ∈ {4::nat, 5::nat})⟧ ⟹ ?m < length ?ys›*) by presburger moreover have "first ys = take m ys" using assms (*‹∃i<length ys. ys ! i ∈ {4, 5}› ‹m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5})›*) first_def (*‹first ?ys ≡ take (if ∃i<length ?ys. ?ys ! i ∈ {4, 5} then LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5} else length ?ys) ?ys›*) by simp ultimately show "?thesis" (*goal: ‹length (first (ys::nat list)) = (m::nat)›*) by simp qed lemma first_notex: assumes "¬ (∃i<length ys. ys ! i ∈ {¦, ♯})" shows "first ys = ys" using assms (*‹¬ (∃i<length ys. ys ! i ∈ {4, 5})›*) first_def (*‹first ?ys ≡ take (if ∃i<length ?ys. ?ys ! i ∈ {4, 5} then LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5} else length ?ys) ?ys›*) by auto lemma length_first: "length (first ys) ≤ length ys" using length_first_ex (*‹⟦∃i<length ?ys. ?ys ! i ∈ {4, 5}; ?m = (LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5})⟧ ⟹ length (first ?ys) = ?m›*) first_notex (*‹¬ (∃i<length (?ys::nat list). ?ys ! i ∈ {4::nat, 5::nat}) ⟹ first ?ys = ?ys›*) first_def (*‹first ?ys ≡ take (if ∃i<length ?ys. ?ys ! i ∈ {4, 5} then LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5} else length ?ys) ?ys›*) by simp lemma length_second_first: "length (second zs) = length zs - Suc (length (first zs))" using second_def (*‹second (?zs::nat list) ≡ drop (Suc (length (first ?zs))) ?zs›*) by simp lemma length_second: "length (second zs) ≤ length zs" using second_def (*‹second ?zs ≡ drop (Suc (length (first ?zs))) ?zs›*) by simp text ‹ Our next goal is to show that @{const first} and @{const second} really extract the first and second element of a pair. › lemma bindecode_bitenc: fixes x :: string shows "bindecode (string_to_symbols (bitenc x)) = string_to_symbols x" proof (induction x) (*goals: 1. ‹bindecode (map (λb. if b then 3 else 2) (bitenc [])) = map (λb. if b then 3 else 2) []› 2. ‹⋀a x. bindecode (map (λb. if b then 3 else 2) (bitenc x)) = map (λb. if b then 3 else 2) x ⟹ bindecode (map (λb. if b then 3 else 2) (bitenc (a # x))) = map (λb. if b then 3 else 2) (a # x)›*) case Nil (*no hyothesis introduced yet*) then show "?case" (*goal: ‹bindecode (map (λb. if b then 3 else 2) (bitenc [])) = map (λb. if b then 3 else 2) []›*) using less_2_cases_iff (*‹((?n::nat) < (2::nat)) = (?n = (0::nat) ∨ ?n = Suc (0::nat))›*) by force next (*goal: ‹⋀a x. bindecode (map (λb. if b then 3 else 2) (bitenc x)) = map (λb. if b then 3 else 2) x ⟹ bindecode (map (λb. if b then 3 else 2) (bitenc (a # x))) = map (λb. if b then 3 else 2) (a # x)›*) case (Cons a x) (*‹bindecode (map (λb. if b then 3 else 2) (bitenc x)) = map (λb. if b then 3 else 2) x›*) have "bitenc (a # x) = bitenc [a] @ bitenc x" by simp then have "string_to_symbols (bitenc (a # x)) = string_to_symbols (bitenc [a] @ bitenc x)" by simp then have "string_to_symbols (bitenc (a # x)) = string_to_symbols (bitenc [a]) @ string_to_symbols (bitenc x)" by simp then have "bindecode (string_to_symbols (bitenc (a # x))) = bindecode (string_to_symbols (bitenc [a]) @ string_to_symbols (bitenc x))" by simp also (*calculation: ‹bindecode (map (λb. if b then 3 else 2) (bitenc (a # x))) = bindecode (map (λb. if b then 3 else 2) (bitenc [a]) @ map (λb. if b then 3 else 2) (bitenc x))›*) have "... = bindecode (string_to_symbols (bitenc [a])) @ bindecode (string_to_symbols (bitenc x))" using bindecode_append (*‹⟦even (length ?ys); even (length ?zs)⟧ ⟹ bindecode (?ys @ ?zs) = bindecode ?ys @ bindecode ?zs›*) length_bitenc (*‹length (bitenc ?z) = 2 * length ?z›*) by (metis (no_types, lifting) dvd_triv_left (*‹?a dvd ?a * ?b›*) length_map (*‹length (map ?f ?xs) = length ?xs›*)) also (*calculation: ‹bindecode (map (λb. if b then 3 else 2) (bitenc (a # x))) = bindecode (map (λb. if b then 3 else 2) (bitenc [a])) @ bindecode (map (λb. if b then 3 else 2) (bitenc x))›*) have "... = bindecode (string_to_symbols (bitenc [a])) @ string_to_symbols x" using Cons (*‹bindecode (map (λb. if b then 3 else 2) (bitenc x)) = map (λb. if b then 3 else 2) x›*) by simp also (*calculation: ‹bindecode (map (λb. if b then 3 else 2) (bitenc (a # x))) = bindecode (map (λb. if b then 3 else 2) (bitenc [a])) @ map (λb. if b then 3 else 2) x›*) have "... = string_to_symbols [a] @ string_to_symbols x" using bindecode_def (*‹bindecode ?zs ≡ map (λi. 2 * (if ?zs ! (2 * i) = 3 then 1 else 0) + (if ?zs ! Suc (2 * i) = 3 then 1 else 0) + 2) [0..<length ?zs div 2]›*) by simp also (*calculation: ‹bindecode (map (λb::bool. if b then 3::nat else (2::nat)) (bitenc ((a::bool) # (x::bool list)))) = map (λb::bool. if b then 3::nat else (2::nat)) [a] @ map (λb::bool. if b then 3::nat else (2::nat)) x›*) have "... = string_to_symbols ([a] @ x)" by simp also (*calculation: ‹bindecode (map (λb. if b then 3 else 2) (bitenc (a # x))) = map (λb. if b then 3 else 2) ([a] @ x)›*) have "... = string_to_symbols (a # x)" by simp finally (*calculation: ‹bindecode (map (λb. if b then 3 else 2) (bitenc (a # x))) = map (λb. if b then 3 else 2) (a # x)›*) show "?case" (*goal: ‹bindecode (map (λb. if b then 3 else 2) (bitenc (a # x))) = map (λb. if b then 3 else 2) (a # x)›*) . qed lemma bindecode_string_pair: fixes x u :: string shows "bindecode ⟨x; u⟩ = string_to_symbols x @ [♯] @ string_to_symbols u" proof (-) (*goal: ‹bindecode (map (λb. if b then 3 else 2) ⟨x, u⟩) = map (λb. if b then 3 else 2) x @ [5] @ map (λb. if b then 3 else 2) u›*) have "bindecode ⟨x; u⟩ = bindecode (string_to_symbols (bitenc x @ [True, True] @ bitenc u))" using string_pair_def (*‹⟨?x, ?y⟩ ≡ bitenc ?x @ [𝕀, 𝕀] @ bitenc ?y›*) by simp also (*calculation: ‹bindecode (map (λb. if b then 3 else 2) ⟨x, u⟩) = bindecode (map (λb. if b then 3 else 2) (bitenc x @ [𝕀, 𝕀] @ bitenc u))›*) have "... = bindecode (string_to_symbols (bitenc x) @ string_to_symbols [𝕀, 𝕀] @ string_to_symbols (bitenc u))" by simp also (*calculation: ‹bindecode (map (λb. if b then 3 else 2) ⟨x, u⟩) = bindecode (map (λb. if b then 3 else 2) (bitenc x) @ map (λb. if b then 3 else 2) [𝕀, 𝕀] @ map (λb. if b then 3 else 2) (bitenc u))›*) have "... = bindecode (string_to_symbols (bitenc x)) @ bindecode (string_to_symbols [𝕀, 𝕀]) @ bindecode (string_to_symbols (bitenc u))" proof (-) (*goal: ‹bindecode (map (λb. if b then 3 else 2) (bitenc x) @ map (λb. if b then 3 else 2) [𝕀, 𝕀] @ map (λb. if b then 3 else 2) (bitenc u)) = bindecode (map (λb. if b then 3 else 2) (bitenc x)) @ bindecode (map (λb. if b then 3 else 2) [𝕀, 𝕀]) @ bindecode (map (λb. if b then 3 else 2) (bitenc u))›*) have "even (length (string_to_symbols [True, True]))" by simp moreover have "even (length (string_to_symbols (bitenc y)))" for y by (simp add: length_bitenc (*‹length (bitenc ?z) = 2 * length ?z›*)) ultimately show "?thesis" (*goal: ‹bindecode (map (λb. if b then 3 else 2) (bitenc x) @ map (λb. if b then 3 else 2) [𝕀, 𝕀] @ map (λb. if b then 3 else 2) (bitenc u)) = bindecode (map (λb. if b then 3 else 2) (bitenc x)) @ bindecode (map (λb. if b then 3 else 2) [𝕀, 𝕀]) @ bindecode (map (λb. if b then 3 else 2) (bitenc u))›*) using bindecode_append (*‹⟦even (length ?ys); even (length ?zs)⟧ ⟹ bindecode (?ys @ ?zs) = bindecode ?ys @ bindecode ?zs›*) length_bindecode (*‹length (bindecode ?zs) = length ?zs div 2›*) length_bitenc (*‹length (bitenc ?z) = 2 * length ?z›*) by (smt (verit) add_mult_distrib2 (*‹?k * (?m + ?n) = ?k * ?m + ?k * ?n›*) add_self_div_2 (*‹(?m + ?m) div 2 = ?m›*) dvd_triv_left (*‹?a dvd ?a * ?b›*) length_append (*‹length (?xs @ ?ys) = length ?xs + length ?ys›*) length_map (*‹length (map ?f ?xs) = length ?xs›*) mult_2 (*‹2 * ?z = ?z + ?z›*)) qed also (*calculation: ‹bindecode (map (λb. if b then 3 else 2) ⟨x, u⟩) = bindecode (map (λb. if b then 3 else 2) (bitenc x)) @ bindecode (map (λb. if b then 3 else 2) [𝕀, 𝕀]) @ bindecode (map (λb. if b then 3 else 2) (bitenc u))›*) have "... = string_to_symbols x @ bindecode (string_to_symbols [𝕀, 𝕀]) @ string_to_symbols u" using bindecode_bitenc (*‹bindecode (map (λb::bool. if b then 3::nat else (2::nat)) (bitenc (?x::bool list))) = map (λb::bool. if b then 3::nat else (2::nat)) ?x›*) by simp also (*calculation: ‹bindecode (map (λb. if b then 3 else 2) ⟨x, u⟩) = map (λb. if b then 3 else 2) x @ bindecode (map (λb. if b then 3 else 2) [𝕀, 𝕀]) @ map (λb. if b then 3 else 2) u›*) have "... = string_to_symbols x @ [♯] @ string_to_symbols u" using bindecode_def (*‹bindecode ?zs ≡ map (λi. 2 * (if ?zs ! (2 * i) = 3 then 1 else 0) + (if ?zs ! Suc (2 * i) = 3 then 1 else 0) + 2) [0..<length ?zs div 2]›*) by simp finally (*calculation: ‹bindecode (map (λb. if b then 3 else 2) ⟨x, u⟩) = map (λb. if b then 3 else 2) x @ [5] @ map (λb. if b then 3 else 2) u›*) show "?thesis" (*goal: ‹bindecode (map (λb::bool. if b then 3::nat else (2::nat)) ⟨x::bool list, u::bool list⟩) = map (λb::bool. if b then 3::nat else (2::nat)) x @ [5::nat] @ map (λb::bool. if b then 3::nat else (2::nat)) u›*) . qed lemma first_pair: fixes ys :: "symbol list" and x u :: string assumes "ys = bindecode ⟨x; u⟩" shows "first ys = string_to_symbols x" proof (-) (*goal: ‹first (ys::nat list) = map (λb::bool. if b then 3::nat else (2::nat)) (x::bool list)›*) have ys: "ys = string_to_symbols x @ [♯] @ string_to_symbols u" using bindecode_string_pair (*‹bindecode (map (λb. if b then 3 else 2) ⟨?x, ?u⟩) = map (λb. if b then 3 else 2) ?x @ [5] @ map (λb. if b then 3 else 2) ?u›*) assms (*‹ys = bindecode (map (λb. if b then 3 else 2) ⟨x, u⟩)›*) by simp have bs: "bit_symbols (string_to_symbols x)" by simp have "ys ! (length (string_to_symbols x)) = ♯" using ys (*‹ys = map (λb. if b then 3 else 2) x @ [5] @ map (λb. if b then 3 else 2) u›*) by (metis append_Cons (*‹(?x # ?xs) @ ?ys = ?x # ?xs @ ?ys›*) nth_append_length (*‹(?xs @ ?x # ?ys) ! length ?xs = ?x›*)) then have ex: "ys ! (length (string_to_symbols x)) ∈ {¦, ♯}" by simp have "(LEAST i. i < length ys ∧ ys ! i ∈ {¦, ♯}) = length (string_to_symbols x)" using ex (*‹ys ! length (map (λb. if b then 3 else 2) x) ∈ {4, 5}›*) ys (*‹(ys::nat list) = map (λb::bool. if b then 3::nat else (2::nat)) (x::bool list) @ [5::nat] @ map (λb::bool. if b then 3::nat else (2::nat)) (u::bool list)›*) bs (*‹∀i<length (map (λb. if b then 3 else 2) x). map (λb. if b then 3 else 2) x ! i = 2 ∨ map (λb. if b then 3 else 2) x ! i = 3›*) apply (intro firstI (*‹⟦?m < length ?ys; ?ys ! ?m ∈ {4, 5}; ∀i<?m. ?ys ! i ∉ {4, 5}⟧ ⟹ (LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5}) = ?m›*)) (*goals: 1. ‹⟦ys ! length (map (λb. if b then 3 else 2) x) ∈ {4, 5}; ys = map (λb. if b then 3 else 2) x @ [5] @ map (λb. if b then 3 else 2) u; ∀i<length (map (λb. if b then 3 else 2) x). map (λb. if b then 3 else 2) x ! i = 2 ∨ map (λb. if b then 3 else 2) x ! i = 3⟧ ⟹ length (map (λb. if b then 3 else 2) x) < length ys› 2. ‹⟦ys ! length (map (λb. if b then 3 else 2) x) ∈ {4, 5}; ys = map (λb. if b then 3 else 2) x @ [5] @ map (λb. if b then 3 else 2) u; ∀i<length (map (λb. if b then 3 else 2) x). map (λb. if b then 3 else 2) x ! i = 2 ∨ map (λb. if b then 3 else 2) x ! i = 3⟧ ⟹ ys ! length (map (λb. if b then 3 else 2) x) ∈ {4, 5}› 3. ‹⟦ys ! length (map (λb. if b then 3 else 2) x) ∈ {4, 5}; ys = map (λb. if b then 3 else 2) x @ [5] @ map (λb. if b then 3 else 2) u; ∀i<length (map (λb. if b then 3 else 2) x). map (λb. if b then 3 else 2) x ! i = 2 ∨ map (λb. if b then 3 else 2) x ! i = 3⟧ ⟹ ∀i<length (map (λb. if b then 3 else 2) x). ys ! i ∉ {4, 5}› discuss goal 1*) apply (simp add: nth_append (*‹((?xs::?'a list) @ (?ys::?'a list)) ! (?n::nat) = (if ?n < length ?xs then ?xs ! ?n else ?ys ! (?n - length ?xs))›*)) (*discuss goal 2*) apply (simp add: nth_append (*‹(?xs @ ?ys) ! ?n = (if ?n < length ?xs then ?xs ! ?n else ?ys ! (?n - length ?xs))›*)) (*discuss goal 3*) apply (simp add: nth_append (*‹(?xs @ ?ys) ! ?n = (if ?n < length ?xs then ?xs ! ?n else ?ys ! (?n - length ?xs))›*)) (*proven 3 subgoals*) . moreover have "length (string_to_symbols x) < length ys" using ys (*‹(ys::nat list) = map (λb::bool. if b then 3::nat else (2::nat)) (x::bool list) @ [5::nat] @ map (λb::bool. if b then 3::nat else (2::nat)) (u::bool list)›*) by simp ultimately have "first ys = take (length (string_to_symbols x)) ys" using ex (*‹ys ! length (map (λb. if b then 3 else 2) x) ∈ {4, 5}›*) first_def (*‹first ?ys ≡ take (if ∃i<length ?ys. ?ys ! i ∈ {4, 5} then LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5} else length ?ys) ?ys›*) by auto then show "first ys = string_to_symbols x" using ys (*‹ys = map (λb. if b then 3 else 2) x @ [5] @ map (λb. if b then 3 else 2) u›*) by simp qed lemma second_pair: fixes ys :: "symbol list" and x u :: string assumes "ys = bindecode ⟨x; u⟩" shows "second ys = string_to_symbols u" proof (-) (*goal: ‹second (ys::nat list) = map (λb::bool. if b then 3::nat else (2::nat)) (u::bool list)›*) have ys: "ys = string_to_symbols x @ [♯] @ string_to_symbols u" using bindecode_string_pair (*‹bindecode (map (λb. if b then 3 else 2) ⟨?x, ?u⟩) = map (λb. if b then 3 else 2) ?x @ [5] @ map (λb. if b then 3 else 2) ?u›*) assms (*‹ys = bindecode (map (λb. if b then 3 else 2) ⟨x, u⟩)›*) by simp let ?m = "length (string_to_symbols x)" have "length (first ys) = ?m" using assms (*‹ys = bindecode (map (λb. if b then 3 else 2) ⟨x, u⟩)›*) first_pair (*‹(?ys::nat list) = bindecode (map (λb::bool. if b then 3::nat else (2::nat)) ⟨?x::bool list, ?u::bool list⟩) ⟹ first ?ys = map (λb::bool. if b then 3::nat else (2::nat)) ?x›*) by presburger moreover have "drop (Suc ?m) ys = string_to_symbols u" using ys (*‹(ys::nat list) = map (λb::bool. if b then 3::nat else (2::nat)) (x::bool list) @ [5::nat] @ map (λb::bool. if b then 3::nat else (2::nat)) (u::bool list)›*) by simp ultimately have "drop (Suc (length (first ys))) ys = string_to_symbols u" by simp then show "?thesis" (*goal: ‹second (ys::nat list) = map (λb::bool. if b then 3::nat else (2::nat)) (u::bool list)›*) using second_def (*‹second ?zs ≡ drop (Suc (length (first ?zs))) ?zs›*) by simp qed subsubsection ‹A Turing machine for extracting the first element› text ‹ Unlike most other Turing machines, the one in this section is not meant to be reusable, but rather to compute a function, namely the function @{const first}. For this reason there are no tape index parameters. Instead, the encoded pair is expected on the input tape, and the output is written to the output tape. \null › lemma bit_symbols_first: assumes "ys = bindecode (string_to_symbols x)" shows "bit_symbols (first ys)" proof (cases "∃i<length ys. ys ! i ∈ {¦, ♯}") (*goals: 1. ‹∃i<length ys. ys ! i ∈ {4, 5} ⟹ ∀i<length (first ys). first ys ! i = 2 ∨ first ys ! i = 3› 2. ‹¬ (∃i<length ys. ys ! i ∈ {4, 5}) ⟹ ∀i<length (first ys). first ys ! i = 2 ∨ first ys ! i = 3›*) case True (*‹∃i<length ys. ys ! i ∈ {4, 5}›*) define m where "m = (LEAST i. i < length ys ∧ ys ! i ∈ {¦, ♯})" then have m: "m < length ys" "ys ! m ∈ {¦, ♯}" "∀i<m. ys ! i ∉ {¦, ♯}" using firstD[OF True] (*‹?m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}) ⟹ ?m < length ys› ‹?m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}) ⟹ ys ! ?m ∈ {4, 5}› ‹?m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}) ⟹ ∀i<?m. ys ! i ∉ {4, 5}›*) apply - (*goals: 1. ‹⟦m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}); ⋀m. m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}) ⟹ m < length ys; ⋀m. m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}) ⟹ ys ! m ∈ {4, 5}; ⋀m. m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}) ⟹ ∀i<m. ys ! i ∉ {4, 5}⟧ ⟹ m < length ys› 2. ‹⟦m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}); ⋀m. m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}) ⟹ m < length ys; ⋀m. m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}) ⟹ ys ! m ∈ {4, 5}; ⋀m. m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}) ⟹ ∀i<m. ys ! i ∉ {4, 5}⟧ ⟹ ys ! m ∈ {4, 5}› 3. ‹⟦m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}); ⋀m. m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}) ⟹ m < length ys; ⋀m. m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}) ⟹ ys ! m ∈ {4, 5}; ⋀m. m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}) ⟹ ∀i<m. ys ! i ∉ {4, 5}⟧ ⟹ ∀i<m. ys ! i ∉ {4, 5}› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*discuss goal 3*) apply blast (*proven 3 subgoals*) . have len: "length (first ys) = m" using length_first_ex[OF True] (*‹?m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5}) ⟹ length (first ys) = ?m›*) m_def (*‹m = (LEAST i. i < length ys ∧ ys ! i ∈ {4, 5})›*) by simp have "bit_symbols (string_to_symbols x)" by simp then have "∀i<length ys. ys ! i ∈ {2..<6}" using assms (*‹ys = bindecode (map (λb. if b then 3 else 2) x)›*) bindecode2345 (*‹∀i<length ?zs. ?zs ! i = 2 ∨ ?zs ! i = 3 ⟹ ∀i<length (bindecode ?zs). bindecode ?zs ! i ∈ {2..<6}›*) by simp then have "∀i<m. ys ! i ∈ {2..<6}" using m(1) (*‹m < length ys›*) by simp then have "∀i<m. ys ! i ∈ {2..<4}" using m(3) (*‹∀i<m. ys ! i ∉ {4, 5}›*) by fastforce then show "?thesis" (*goal: ‹∀i<length (first ys). first ys ! i = 2 ∨ first ys ! i = 3›*) using first_def (*‹first ?ys ≡ take (if ∃i<length ?ys. ?ys ! i ∈ {4, 5} then LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5} else length ?ys) ?ys›*) len (*‹length (first (ys::nat list)) = (m::nat)›*) by auto next (*goal: ‹¬ (∃i<length ys. ys ! i ∈ {4, 5}) ⟹ ∀i<length (first ys). first ys ! i = 2 ∨ first ys ! i = 3›*) case False (*‹¬ (∃i<length ys. ys ! i ∈ {4, 5})›*) then have 1: "∀i<length ys. ys ! i ∉ {¦, ♯}" by simp have "bit_symbols (string_to_symbols x)" by simp then have "∀i<length ys. ys ! i ∈ {2..<6}" using assms (*‹(ys::nat list) = bindecode (map (λb::bool. if b then 3::nat else (2::nat)) (x::bool list))›*) bindecode2345 (*‹∀i<length ?zs. ?zs ! i = 2 ∨ ?zs ! i = 3 ⟹ ∀i<length (bindecode ?zs). bindecode ?zs ! i ∈ {2..<6}›*) by simp then have "∀i<length ys. ys ! i ∈ {2..<4}" using "1" (*‹∀i<length ys. ys ! i ∉ {4, 5}›*) by fastforce then show "?thesis" (*goal: ‹∀i<length (first ys). first ys ! i = 2 ∨ first ys ! i = 3›*) using False (*‹¬ (∃i<length ys. ys ! i ∈ {4, 5})›*) first_notex (*‹¬ (∃i<length ?ys. ?ys ! i ∈ {4, 5}) ⟹ first ?ys = ?ys›*) by auto qed definition tm_first :: machine where "tm_first ≡ tm_right_many {0, 1, 2} ;; tm_bindecode 0 2 ;; tm_cp_until 2 1 {□, ¦, ♯}" lemma tm_first_tm: "G ≥ 6 ⟹ k ≥ 3 ⟹ turing_machine k G tm_first" unfolding tm_first_def (*goal: ‹⟦(6::nat) ≤ (G::nat); (3::nat) ≤ (k::nat)⟧ ⟹ turing_machine k G (tm_right_many {0::nat, 1::nat, 2::nat} ;; tm_bindecode (0::nat) (2::nat) ;; tm_cp_until (2::nat) (1::nat) {0::nat, 4::nat, 5::nat})›*) using tm_cp_until_tm (*‹⟦0 < ?j2.0; ?j1.0 < ?k; ?j2.0 < ?k; 4 ≤ ?G⟧ ⟹ turing_machine ?k ?G (tm_cp_until ?j1.0 ?j2.0 ?H)›*) tm_start_tm (*‹⟦2 ≤ ?k; 4 ≤ ?G⟧ ⟹ turing_machine ?k ?G (tm_start ?j)›*) tm_bindecode_tm (*‹⟦6 ≤ ?G; ?j1.0 < ?k; ?j2.0 < ?k; 0 < ?j2.0; ?j1.0 ≠ ?j2.0⟧ ⟹ turing_machine ?k ?G (tm_bindecode ?j1.0 ?j2.0)›*) tm_right_many_tm (*‹⟦2 ≤ ?k; 4 ≤ ?G⟧ ⟹ turing_machine ?k ?G (tm_right_many ?J)›*) by simp locale turing_machine_fst_pair = fixes k :: nat assumes k: "k ≥ 3" begin definition "tm1 ≡ tm_right_many {0, 1, 2}" definition "tm2 ≡ tm1 ;; tm_bindecode 0 2" definition "tm3 ≡ tm2 ;; tm_cp_until 2 1 {□, ¦, ♯}" lemma tm3_eq_tm_first: "tm3 = tm_first" using tm1_def (*‹tm1 ≡ tm_right_many {0, 1, 2}›*) tm2_def (*‹tm2 ≡ tm1 ;; tm_bindecode 0 2›*) tm3_def (*‹tm3 ≡ tm2 ;; tm_cp_until (2::nat) (1::nat) {0::nat, 4::nat, 5::nat}›*) tm_first_def (*‹tm_first ≡ tm_right_many {0, 1, 2} ;; tm_bindecode 0 2 ;; tm_cp_until 2 1 {0, 4, 5}›*) by simp context fixes xs :: "symbol list" assumes bs: "bit_symbols xs" begin definition "tps0 ≡ snd (start_config k xs)" lemma lentps [simp]: "length tps0 = k" using tps0_def (*‹tps0 ≡ snd (start_config k xs)›*) start_config_length (*‹0 < ?k ⟹ ||start_config ?k ?xs|| = ?k›*) k (*‹3 ≤ k›*) by simp lemma tps0_0: "tps0 ! 0 = (⌊xs⌋, 0)" using tps0_def (*‹tps0 ≡ snd (start_config k xs)›*) start_config_def (*‹start_config (?k::nat) (?xs::nat list) ≡ (0::nat, (⌊?xs⌋, 0::nat) # replicate (?k - (1::nat)) (⌊[]⌋, 0::nat))›*) contents_def (*‹⌊?xs⌋ ?i ≡ if ?i = 0 then 1 else if ?i ≤ length ?xs then ?xs ! (?i - 1) else 0›*) by auto lemma tps0_gt_0: "j > 0 ⟹ j < k ⟹ tps0 ! j = (⌊[]⌋, 0)" using tps0_def (*‹tps0 ≡ snd (start_config k xs)›*) start_config_def (*‹start_config ?k ?xs ≡ (0, (⌊?xs⌋, 0) # replicate (?k - 1) (⌊[]⌋, 0))›*) contents_def (*‹⌊?xs::nat list⌋ (?i::nat) ≡ if ?i = (0::nat) then 1::nat else if ?i ≤ length ?xs then ?xs ! (?i - (1::nat)) else (0::nat)›*) by auto definition "tps1 ≡ tps0 [0 := (⌊xs⌋, 1), 1 := (⌊[]⌋, 1), 2 := (⌊[]⌋, 1)]" lemma tm1 [transforms_intros]: "transforms tm1 tps0 1 tps1" unfolding tm1_def (*goal: ‹transforms (tm_right_many {0, 1, 2}) tps0 1 tps1›*) proof (tform) (*goal: ‹tps1 = map (λj. if j ∈ {0, 1, 2} then tps0 ! j |+| 1 else tps0 ! j) [0..<length tps0]›*) show "tps1 = map (λj. if j ∈ {0, 1, 2} then tps0 ! j |+| 1 else tps0 ! j) [0..<length tps0]" (is "_ = ?rhs") proof (rule nth_equalityI (*‹⟦length ?xs = length ?ys; ⋀i. i < length ?xs ⟹ ?xs ! i = ?ys ! i⟧ ⟹ ?xs = ?ys›*)) (*goals: 1. ‹length tps1 = length (map (λj. if j ∈ {0, 1, 2} then tps0 ! j |+| 1 else tps0 ! j) [0..<length tps0])› 2. ‹⋀i. i < length tps1 ⟹ tps1 ! i = map (λj. if j ∈ {0, 1, 2} then tps0 ! j |+| 1 else tps0 ! j) [0..<length tps0] ! i›*) show "length tps1 = length ?rhs" using tps0_def (*‹tps0 ≡ snd (start_config k xs)›*) tps1_def (*‹tps1 ≡ tps0[0 := (⌊xs⌋, 1), 1 := (⌊[]⌋, 1), 2 := (⌊[]⌋, 1)]›*) by simp show "tps1 ! j = ?rhs ! j" if "j < length tps1" for j using that (*‹j < length tps1›*) tps0_0 (*‹tps0 ! 0 = (⌊xs⌋, 0)›*) tps0_gt_0 (*‹⟦0 < ?j; ?j < k⟧ ⟹ tps0 ! ?j = (⌊[]⌋, 0)›*) tps1_def (*‹tps1 ≡ tps0[0 := (⌊xs⌋, 1), 1 := (⌊[]⌋, 1), 2 := (⌊[]⌋, 1)]›*) by simp qed qed definition "tps2 ≡ tps0 [0 := (⌊xs⌋, 1), 1 := (⌊[]⌋, 1), 2 := (⌊bindecode xs⌋, 1)]" lemma tm2 [transforms_intros]: assumes "ttt = 8 + 3 * length xs" shows "transforms tm2 tps0 ttt tps2" unfolding tm2_def (*goal: ‹transforms (tm1 ;; tm_bindecode 0 2) tps0 ttt tps2›*) by (tform tps: bs k tps1_def assms tps2_def) definition "tps3 ≡ tps0 [0 := (⌊xs⌋, 1), 1 := (⌊first (bindecode xs)⌋, Suc (length (first (bindecode xs)))), 2 := (⌊bindecode xs⌋, Suc (length (first (bindecode xs))))]" lemma tm3: assumes "ttt = 8 + 3 * length xs + Suc (length (first (bindecode xs)))" shows "transforms tm3 tps0 ttt tps3" unfolding tm3_def (*goal: ‹transforms (tm2 ;; tm_cp_until (2::nat) (1::nat) {0::nat, 4::nat, 5::nat}) tps0 (ttt::nat) tps3›*) proof (tform tps: k tps2_def time: assms) (*goals: 1. ‹rneigh (tps2 ! 2) {0, 4, 5} (length (first (bindecode xs)))› 2. ‹tps3 = tps2[2 := tps2 ! 2 |+| length (first (bindecode xs)), 1 := implant (tps2 ! 2) (tps2 ! 1) (length (first (bindecode xs)))]›*) let ?ys = "bindecode xs" have tps2: "tps2 ! 2 = (⌊?ys⌋, 1)" using tps2_def (*‹tps2 ≡ tps0[0 := (⌊xs⌋, 1), 1 := (⌊[]⌋, 1), 2 := (⌊bindecode xs⌋, 1)]›*) k (*‹3 ≤ k›*) by simp show "rneigh (tps2 ! 2) {□, ¦, ♯} (length (first ?ys))" proof (cases "∃i<length ?ys. ?ys ! i ∈ {¦, ♯}") (*goals: 1. ‹∃i<length (bindecode xs). bindecode xs ! i ∈ {4, 5} ⟹ rneigh (tps2 ! 2) {0, 4, 5} (length (first (bindecode xs)))› 2. ‹¬ (∃i<length (bindecode xs). bindecode xs ! i ∈ {4, 5}) ⟹ rneigh (tps2 ! 2) {0, 4, 5} (length (first (bindecode xs)))›*) case ex5: True (*‹∃i<length (bindecode xs). bindecode xs ! i ∈ {4, 5}›*) define m where "m = (LEAST i. i < length ?ys ∧ ?ys ! i ∈ {¦, ♯})" then have m: "m = length (first ?ys)" using length_first_ex (*‹⟦∃i<length ?ys. ?ys ! i ∈ {4, 5}; ?m = (LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5})⟧ ⟹ length (first ?ys) = ?m›*) ex5 (*‹∃i<length (bindecode xs). bindecode xs ! i ∈ {4, 5}›*) by simp show "?thesis" (*goal: ‹rneigh (tps2 ! (2::nat)) {0::nat, 4::nat, 5::nat} (length (first (bindecode (xs::nat list))))›*) proof (rule rneighI (*‹⟦fst (?tp::(nat ⇒ nat) × nat) (snd ?tp + (?n::nat)) ∈ (?H::nat set); ⋀n'::nat. n' < ?n ⟹ fst ?tp (snd ?tp + n') ∉ ?H⟧ ⟹ rneigh ?tp ?H ?n›*)) (*goals: 1. ‹(tps2 ::: 2) (tps2 :#: 2 + length (first (bindecode xs))) ∈ {0, 4, 5}› 2. ‹⋀n'. n' < length (first (bindecode xs)) ⟹ (tps2 ::: 2) (tps2 :#: 2 + n') ∉ {0, 4, 5}›*) have "?ys ! m ∈ {¦, ♯}" using firstD (*‹⟦∃i<length (?ys::nat list). ?ys ! i ∈ {4::nat, 5::nat}; (?m::nat) = (LEAST i::nat. i < length ?ys ∧ ?ys ! i ∈ {4::nat, 5::nat})⟧ ⟹ ?m < length ?ys› ‹⟦∃i<length ?ys. ?ys ! i ∈ {4, 5}; ?m = (LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5})⟧ ⟹ ?ys ! ?m ∈ {4, 5}› ‹⟦∃i<length (?ys::nat list). ?ys ! i ∈ {4::nat, 5::nat}; (?m::nat) = (LEAST i::nat. i < length ?ys ∧ ?ys ! i ∈ {4::nat, 5::nat})⟧ ⟹ ∀i<?m. ?ys ! i ∉ {4::nat, 5::nat}›*) m_def (*‹m = (LEAST i. i < length (bindecode xs) ∧ bindecode xs ! i ∈ {4, 5})›*) ex5 (*‹∃i<length (bindecode (xs::nat list)). bindecode xs ! i ∈ {4::nat, 5::nat}›*) by blast then show "(tps2 ::: 2) (tps2 :#: 2 + length (first ?ys)) ∈ {□, ¦, ♯}" using m (*‹m = length (first (bindecode xs))›*) tps2 (*‹tps2 ! 2 = (⌊bindecode xs⌋, 1)›*) contents_def (*‹⌊?xs⌋ ?i ≡ if ?i = 0 then 1 else if ?i ≤ length ?xs then ?xs ! (?i - 1) else 0›*) by simp show "(tps2 ::: 2) (tps2 :#: 2 + i) ∉ {□, ¦, ♯}" if "i < length (first ?ys)" for i proof (-) (*goal: ‹(tps2 ::: 2) (tps2 :#: 2 + i) ∉ {0, 4, 5}›*) have "m < length ?ys" using ex5 (*‹∃i<length (bindecode xs). bindecode xs ! i ∈ {4, 5}›*) firstD(1) (*‹⟦∃i<length ?ys. ?ys ! i ∈ {4, 5}; ?m = (LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5})⟧ ⟹ ?m < length ?ys›*) length_first_ex (*‹⟦∃i<length ?ys. ?ys ! i ∈ {4, 5}; ?m = (LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5})⟧ ⟹ length (first ?ys) = ?m›*) m (*‹m = length (first (bindecode xs))›*) by blast then have "length (first ?ys) < length ?ys" using m (*‹m = length (first (bindecode xs))›*) by simp then have "i < length ?ys" using that (*‹i < length (first (bindecode xs))›*) by simp then have "?ys ! i ≠ 0" using proper_bindecode (*‹∀i<length (bindecode ?zs). Suc 0 < bindecode ?zs ! i›*) by fastforce moreover have "?ys ! i ∉ {¦, ♯}" using ex5 (*‹∃i<length (bindecode xs). bindecode xs ! i ∈ {4, 5}›*) firstD(3) (*‹⟦∃i<length ?ys. ?ys ! i ∈ {4, 5}; ?m = (LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5})⟧ ⟹ ∀i<?m. ?ys ! i ∉ {4, 5}›*) length_first_ex (*‹⟦∃i<length ?ys. ?ys ! i ∈ {4, 5}; ?m = (LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5})⟧ ⟹ length (first ?ys) = ?m›*) that (*‹i < length (first (bindecode xs))›*) by blast ultimately show "?thesis" (*goal: ‹(tps2 ::: 2) (tps2 :#: 2 + i) ∉ {0, 4, 5}›*) using Suc_neq_Zero (*‹Suc ?m = 0 ⟹ ?R›*) ‹i < length (bindecode xs)› (*‹i < length (bindecode xs)›*) tps2 (*‹tps2 ! 2 = (⌊bindecode xs⌋, 1)›*) by simp qed qed next (*goal: ‹¬ (∃i<length (bindecode xs). bindecode xs ! i ∈ {4, 5}) ⟹ rneigh (tps2 ! 2) {0, 4, 5} (length (first (bindecode xs)))›*) case notex5: False (*‹¬ (∃i<length (bindecode xs). bindecode xs ! i ∈ {4, 5})›*) then have ys: "?ys = first ?ys" using first_notex (*‹¬ (∃i<length ?ys. ?ys ! i ∈ {4, 5}) ⟹ first ?ys = ?ys›*) by simp show "?thesis" (*goal: ‹rneigh (tps2 ! 2) {0, 4, 5} (length (first (bindecode xs)))›*) proof (rule rneighI (*‹⟦fst ?tp (snd ?tp + ?n) ∈ ?H; ⋀n'. n' < ?n ⟹ fst ?tp (snd ?tp + n') ∉ ?H⟧ ⟹ rneigh ?tp ?H ?n›*)) (*goals: 1. ‹(tps2 ::: 2) (tps2 :#: 2 + length (first (bindecode xs))) ∈ {0, 4, 5}› 2. ‹⋀n'. n' < length (first (bindecode xs)) ⟹ (tps2 ::: 2) (tps2 :#: 2 + n') ∉ {0, 4, 5}›*) show "(tps2 ::: 2) (tps2 :#: 2 + length (first ?ys)) ∈ {□, ¦, ♯}" using ys (*‹bindecode xs = first (bindecode xs)›*) tps2 (*‹tps2 ! 2 = (⌊bindecode xs⌋, 1)›*) by simp show "(tps2 ::: 2) (tps2 :#: 2 + i) ∉ {□, ¦, ♯}" if "i < length (first ?ys)" for i using notex5 (*‹¬ (∃i<length (bindecode xs). bindecode xs ! i ∈ {4, 5})›*) that (*‹i < length (first (bindecode xs))›*) ys (*‹bindecode xs = first (bindecode xs)›*) proper_bindecode (*‹∀i<length (bindecode ?zs). Suc 0 < bindecode ?zs ! i›*) contents_inbounds (*‹⟦0 < ?i; ?i ≤ length ?zs⟧ ⟹ ⌊?zs⌋ ?i = ?zs ! (?i - 1)›*) by (metis Suc_leI (*‹?m < ?n ⟹ Suc ?m ≤ ?n›*) add_gr_0 (*‹(0 < ?m + ?n) = (0 < ?m ∨ 0 < ?n)›*) diff_Suc_1 (*‹Suc ?n - 1 = ?n›*) fst_conv (*‹fst (?x1.0, ?x2.0) = ?x1.0›*) gr_implies_not0 (*‹?m < ?n ⟹ ?n ≠ 0›*) insert_iff (*‹(?a ∈ insert ?b ?A) = (?a = ?b ∨ ?a ∈ ?A)›*) plus_1_eq_Suc (*‹(+) 1 = Suc›*) snd_conv (*‹snd (?x1.0, ?x2.0) = ?x2.0›*) tps2 (*‹tps2 ! 2 = (⌊bindecode xs⌋, 1)›*) zero_less_one (*‹0 < 1›*)) qed qed show "tps3 = tps2[2 := tps2 ! 2 |+| length (first ?ys), 1 := implant (tps2 ! 2) (tps2 ! 1) (length (first ?ys))]" (is "_ = ?tps") proof (-) (*goal: ‹tps3 = tps2[2::nat := tps2 ! (2::nat) |+| length (first (bindecode (xs::nat list))), 1::nat := implant (tps2 ! (2::nat)) (tps2 ! (1::nat)) (length (first (bindecode xs)))]›*) have 0: "tps3 ! 0 = ?tps ! 0" using tps2_def (*‹tps2 ≡ tps0[0 := (⌊xs⌋, 1), 1 := (⌊[]⌋, 1), 2 := (⌊bindecode xs⌋, 1)]›*) tps3_def (*‹tps3 ≡ tps0[0 := (⌊xs⌋, 1), 1 := (⌊first (bindecode xs)⌋, Suc (length (first (bindecode xs)))), 2 := (⌊bindecode xs⌋, Suc (length (first (bindecode xs))))]›*) by simp have 1: "tps3 ! 2 = ?tps ! 2" using tps2_def (*‹tps2 ≡ tps0[0 := (⌊xs⌋, 1), 1 := (⌊[]⌋, 1), 2 := (⌊bindecode xs⌋, 1)]›*) tps3_def (*‹tps3 ≡ tps0[0 := (⌊xs⌋, 1), 1 := (⌊first (bindecode xs)⌋, Suc (length (first (bindecode xs)))), 2 := (⌊bindecode xs⌋, Suc (length (first (bindecode xs))))]›*) k (*‹3 ≤ k›*) by simp have lentps2: "length tps2 > 2" using k (*‹3 ≤ k›*) tps2_def (*‹tps2 ≡ tps0[0 := (⌊xs⌋, 1), 1 := (⌊[]⌋, 1), 2 := (⌊bindecode xs⌋, 1)]›*) by simp have "implant (tps2 ! 2) (tps2 ! 1) (length (first ?ys)) = (⌊first ?ys⌋, Suc (length (first ?ys)))" proof (-) (*goal: ‹implant (tps2 ! 2) (tps2 ! 1) (length (first (bindecode xs))) = (⌊first (bindecode xs)⌋, Suc (length (first (bindecode xs))))›*) have len: "length (first ?ys) ≤ length ?ys" using first_def (*‹first ?ys ≡ take (if ∃i<length ?ys. ?ys ! i ∈ {4, 5} then LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5} else length ?ys) ?ys›*) by simp have "tps2 ! 1 = (⌊[]⌋, 1)" using tps2_def (*‹tps2 ≡ tps0[0 := (⌊xs⌋, 1), 1 := (⌊[]⌋, 1), 2 := (⌊bindecode xs⌋, 1)]›*) lentps2 (*‹(2::nat) < length tps2›*) by simp then have "implant (tps2 ! 2) (tps2 ! 1) (length (first ?ys)) = implant (⌊?ys⌋, 1) (⌊[]⌋, 1) (length (first ?ys))" using tps2 (*‹tps2 ! 2 = (⌊bindecode xs⌋, 1)›*) by simp also (*calculation: ‹implant (tps2 ! 2) (tps2 ! 1) (length (first (bindecode xs))) = implant (⌊bindecode xs⌋, 1) (⌊[]⌋, 1) (length (first (bindecode xs)))›*) have "... = (⌊take (length (first ?ys)) ?ys⌋, Suc (length (first ?ys)))" using implant_contents[of 1 "length (first ?ys)" ?ys "[]"] (*‹⟦0 < 1; length (first (bindecode xs)) + (1 - 1) ≤ length (bindecode xs)⟧ ⟹ implant (⌊bindecode xs⌋, 1) (⌊[]⌋, Suc (length [])) (length (first (bindecode xs))) = (⌊[] @ take (length (first (bindecode xs))) (drop (1 - 1) (bindecode xs))⌋, Suc (length []) + length (first (bindecode xs)))›*) len (*‹length (first (bindecode xs)) ≤ length (bindecode xs)›*) by simp also (*calculation: ‹implant (tps2 ! 2) (tps2 ! 1) (length (first (bindecode xs))) = (⌊take (length (first (bindecode xs))) (bindecode xs)⌋, Suc (length (first (bindecode xs))))›*) have "... = (⌊first ?ys⌋, Suc (length (first ?ys)))" using first_def (*‹first ?ys ≡ take (if ∃i<length ?ys. ?ys ! i ∈ {4, 5} then LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5} else length ?ys) ?ys›*) using first_notex (*‹¬ (∃i<length ?ys. ?ys ! i ∈ {4, 5}) ⟹ first ?ys = ?ys›*) length_first_ex (*‹⟦∃i<length ?ys. ?ys ! i ∈ {4, 5}; ?m = (LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5})⟧ ⟹ length (first ?ys) = ?m›*) by presburger finally (*calculation: ‹implant (tps2 ! 2) (tps2 ! 1) (length (first (bindecode xs))) = (⌊first (bindecode xs)⌋, Suc (length (first (bindecode xs))))›*) show "?thesis" (*goal: ‹implant (tps2 ! 2) (tps2 ! 1) (length (first (bindecode xs))) = (⌊first (bindecode xs)⌋, Suc (length (first (bindecode xs))))›*) . qed moreover have "length tps2 > 2" using k (*‹3 ≤ k›*) tps2_def (*‹tps2 ≡ tps0[0 := (⌊xs⌋, 1), 1 := (⌊[]⌋, 1), 2 := (⌊bindecode xs⌋, 1)]›*) by simp ultimately show "?thesis" (*goal: ‹tps3 = tps2[2::nat := tps2 ! (2::nat) |+| length (first (bindecode (xs::nat list))), 1::nat := implant (tps2 ! (2::nat)) (tps2 ! (1::nat)) (length (first (bindecode xs)))]›*) using "0" (*‹tps3 ! 0 = tps2[2 := tps2 ! 2 |+| length (first (bindecode xs)), 1 := implant (tps2 ! 2) (tps2 ! 1) (length (first (bindecode xs)))] ! 0›*) "1" (*‹tps3 ! 2 = tps2[2 := tps2 ! 2 |+| length (first (bindecode xs)), 1 := implant (tps2 ! 2) (tps2 ! 1) (length (first (bindecode xs)))] ! 2›*) tps2_def (*‹tps2 ≡ tps0[0::nat := (⌊xs::nat list⌋, 1::nat), 1::nat := (⌊[]⌋, 1::nat), 2::nat := (⌊bindecode xs⌋, 1::nat)]›*) tps3_def (*‹tps3 ≡ tps0[0 := (⌊xs⌋, 1), 1 := (⌊first (bindecode xs)⌋, Suc (length (first (bindecode xs)))), 2 := (⌊bindecode xs⌋, Suc (length (first (bindecode xs))))]›*) tps0_def (*‹tps0 ≡ snd (start_config k xs)›*) lentps (*‹length tps0 = k›*) k (*‹3 ≤ k›*) tps2 (*‹tps2 ! 2 = (⌊bindecode xs⌋, 1)›*) by (smt (verit) length_list_update (*‹length (?xs[?i := ?x]) = length ?xs›*) list_update_overwrite (*‹?xs[?i := ?x, ?i := ?y] = ?xs[?i := ?y]›*) list_update_swap (*‹?i ≠ ?i' ⟹ ?xs[?i := ?x, ?i' := ?x'] = ?xs[?i' := ?x', ?i := ?x]›*) nth_list_update (*‹?i < length ?xs ⟹ ?xs[?i := ?x] ! ?j = (if ?i = ?j then ?x else ?xs ! ?j)›*)) qed qed lemma tm3': assumes "ttt = 9 + 4 * length xs" shows "transforms tm3 tps0 ttt tps3" proof (-) (*goal: ‹transforms tm3 tps0 ttt tps3›*) let ?t = "8 + 3 * length xs + Suc (length (first (bindecode xs)))" have "?t ≤ 8 + 3 * length xs + Suc (length (bindecode xs))" using length_first (*‹length (first ?ys) ≤ length ?ys›*) by (meson Suc_le_mono (*‹(Suc ?n ≤ Suc ?m) = (?n ≤ ?m)›*) add_le_mono (*‹⟦?i ≤ ?j; ?k ≤ ?l⟧ ⟹ ?i + ?k ≤ ?j + ?l›*) order_refl (*‹?x ≤ ?x›*)) also (*calculation: ‹8 + 3 * length xs + Suc (length (first (bindecode xs))) ≤ 8 + 3 * length xs + Suc (length (bindecode xs))›*) have "... ≤ 8 + 3 * length xs + Suc (length xs)" using length_bindecode (*‹length (bindecode ?zs) = length ?zs div 2›*) by simp also (*calculation: ‹8 + 3 * length xs + Suc (length (first (bindecode xs))) ≤ 8 + 3 * length xs + Suc (length xs)›*) have "... = 9 + 3 * length xs + length xs" by simp also (*calculation: ‹(8::nat) + (3::nat) * length (xs::nat list) + Suc (length (first (bindecode xs))) ≤ (9::nat) + (3::nat) * length xs + length xs›*) have "... = 9 + 4 * length xs" by simp finally (*calculation: ‹8 + 3 * length xs + Suc (length (first (bindecode xs))) ≤ 9 + 4 * length xs›*) have "?t ≤ ttt" using assms(1) (*‹ttt = 9 + 4 * length xs›*) by simp moreover have "transforms tm3 tps0 ?t tps3" using tm3 (*‹?ttt = 8 + 3 * length xs + Suc (length (first (bindecode xs))) ⟹ transforms tm3 tps0 ?ttt tps3›*) by simp ultimately show "?thesis" (*goal: ‹transforms tm3 tps0 ttt tps3›*) using transforms_monotone (*‹⟦transforms ?M ?tps ?t ?tps'; ?t ≤ ?t'⟧ ⟹ transforms ?M ?tps ?t' ?tps'›*) by simp qed end (* context tps *) lemma tm3_computes: "computes_in_time k tm3 (λx. symbols_to_string (first (bindecode (string_to_symbols x)))) (λn. 9 + 4 * n)" proof (-) (*goal: ‹computes_in_time k tm3 (λx. map (λz. z = 3) (first (bindecode (map (λb. if b then 3 else 2) x)))) (λn. 9 + 4 * n)›*) define f where "f = (λx. symbols_to_string (first (bindecode (string_to_symbols x))))" define T :: "nat ⇒ nat" where "T = (λn. 9 + 4 * n)" have "computes_in_time k tm3 f T" proof (standard) (*goal: ‹⋀x. ∃tps. tps ::: 1 = (λi. if i = 0 then 1 else if i ≤ length (f x) then if f x ! (i - 1) then 3 else 2 else 0) ∧ transforms tm3 (snd (start_config k (map (λb. if b then 3 else 2) x))) (T (length x)) tps›*) fix x :: string let ?xs = "string_to_symbols x" have bs: "bit_symbols ?xs" by simp define tps where "tps = tps3 ?xs" have trans: "transforms tm3 (tps0 ?xs) (9 + 4 * length ?xs) tps" using bs (*‹∀i<length (map (λb. if b then 3 else 2) x). map (λb. if b then 3 else 2) x ! i = 2 ∨ map (λb. if b then 3 else 2) x ! i = 3›*) tm3' (*‹⟦∀i<length ?xs. ?xs ! i = 2 ∨ ?xs ! i = 3; ?ttt = 9 + 4 * length ?xs⟧ ⟹ transforms tm3 (tps0 ?xs) ?ttt (tps3 ?xs)›*) tps_def (*‹tps = tps3 (map (λb. if b then 3 else 2) x)›*) by blast have "tps3 ?xs ::: 1 = ⌊first (bindecode ?xs)⌋" using bs (*‹∀i<length (map (λb::bool. if b then 3::nat else (2::nat)) (x::bool list)). map (λb::bool. if b then 3::nat else (2::nat)) x ! i = (2::nat) ∨ map (λb::bool. if b then 3::nat else (2::nat)) x ! i = (3::nat)›*) tps3_def (*‹∀i<length ?xs. ?xs ! i = 2 ∨ ?xs ! i = 3 ⟹ tps3 ?xs ≡ (tps0 ?xs)[0 := (⌊?xs⌋, 1), 1 := (⌊first (bindecode ?xs)⌋, Suc (length (first (bindecode ?xs)))), 2 := (⌊bindecode ?xs⌋, Suc (length (first (bindecode ?xs))))]›*) k (*‹(3::nat) ≤ (k::nat)›*) by simp moreover have "bit_symbols (first (bindecode ?xs))" using bit_symbols_first (*‹?ys = bindecode (map (λb. if b then 3 else 2) ?x) ⟹ ∀i<length (first ?ys). first ?ys ! i = 2 ∨ first ?ys ! i = 3›*) by simp ultimately have "tps3 ?xs ::: 1 = string_to_contents (symbols_to_string (first (bindecode ?xs)))" using bit_symbols_to_symbols (*‹∀i<length ?zs. ?zs ! i = 2 ∨ ?zs ! i = 3 ⟹ map (λb. if b then 3 else 2) (map (λz. z = 3) ?zs) = ?zs›*) contents_string_to_contents (*‹(λi. if i = 0 then 1 else if i ≤ length ?xs then if ?xs ! (i - 1) then 3 else 2 else 0) = ⌊map (λb. if b then 3 else 2) ?xs⌋›*) by simp then have "*": "tps ::: 1 = string_to_contents (f x)" using tps_def (*‹tps = tps3 (map (λb. if b then 3 else 2) x)›*) f_def (*‹f = (λx. map (λz. z = 3) (first (bindecode (map (λb. if b then 3 else 2) x))))›*) by auto then have "transforms tm3 (snd (start_config k (string_to_symbols x))) (T (length x)) tps" using trans (*‹transforms tm3 (tps0 (map (λb. if b then 3 else 2) x)) (9 + 4 * length (map (λb. if b then 3 else 2) x)) tps›*) T_def (*‹T = (λn. 9 + 4 * n)›*) tps0_def (*‹∀i<length ?xs. ?xs ! i = 2 ∨ ?xs ! i = 3 ⟹ tps0 ?xs ≡ snd (start_config k ?xs)›*) by simp then show "∃tps. tps ::: 1 = string_to_contents (f x) ∧ transforms tm3 (snd (start_config k (string_to_symbols x))) (T (length x)) tps" using "*" (*‹(tps::((nat ⇒ nat) × nat) list) ::: (1::nat) = (λi::nat. if i = (0::nat) then 1::nat else if i ≤ length ((f::bool list ⇒ bool list) (x::bool list)) then if f x ! (i - (1::nat)) then 3::nat else (2::nat) else (0::nat))›*) by auto qed then show "?thesis" (*goal: ‹computes_in_time k tm3 (λx. map (λz. z = 3) (first (bindecode (map (λb. if b then 3 else 2) x)))) (λn. 9 + 4 * n)›*) using f_def (*‹f = (λx. map (λz. z = 3) (first (bindecode (map (λb. if b then 3 else 2) x))))›*) T_def (*‹(T::nat ⇒ nat) = (λn::nat. (9::nat) + (4::nat) * n)›*) by simp qed end (* locale turing_machine_fst_pair *) lemma tm_first_computes: assumes "k ≥ 3" shows "computes_in_time k tm_first (λx. symbols_to_string (first (bindecode (string_to_symbols x)))) (λn. 9 + 4 * n)" proof (-) (*goal: ‹computes_in_time k tm_first (λx. map (λz. z = 3) (first (bindecode (map (λb. if b then 3 else 2) x)))) (λn. 9 + 4 * n)›*) interpret loc: turing_machine_fst_pair k using turing_machine_fst_pair.intro (*‹3 ≤ ?k ⟹ turing_machine_fst_pair ?k›*) assms (*‹(3::nat) ≤ (k::nat)›*) by simp show "?thesis" (*goal: ‹computes_in_time k tm_first (λx. map (λz. z = 3) (first (bindecode (map (λb. if b then 3 else 2) x)))) (λn. 9 + 4 * n)›*) using loc.tm3_eq_tm_first (*‹loc.tm3 = tm_first›*) loc.tm3_computes (*‹computes_in_time k loc.tm3 (λx. map (λz. z = 3) (first (bindecode (map (λb. if b then 3 else 2) x)))) (λn. 9 + 4 * n)›*) by simp qed subsubsection ‹A Turing machine for splitting pairs› text ‹ The next Turing machine expects a proper symbol sequence @{term zs} on tape $j_1$ and outputs @{term "first zs"} and @{term "second zs"} on tapes $j_2$ and $j_3$, respectively. › definition tm_unpair :: "tapeidx ⇒ tapeidx ⇒ tapeidx ⇒ machine" where "tm_unpair j1 j2 j3 ≡ tm_cp_until j1 j2 {□, ¦, ♯} ;; tm_right j1 ;; tm_cp_until j1 j3 {□} ;; tm_cr j1 ;; tm_cr j2 ;; tm_cr j3" lemma tm_unpair_tm: assumes "k ≥ 2" and "G ≥ 4" and "0 < j2" and "0 < j3" and "j1 < k" "j2 < k" "j3 < k" shows "turing_machine k G (tm_unpair j1 j2 j3)" using tm_cp_until_tm (*‹⟦0 < ?j2.0; ?j1.0 < ?k; ?j2.0 < ?k; 4 ≤ ?G⟧ ⟹ turing_machine ?k ?G (tm_cp_until ?j1.0 ?j2.0 ?H)›*) tm_right_tm (*‹⟦2 ≤ ?k; 4 ≤ ?G⟧ ⟹ turing_machine ?k ?G (tm_right ?j)›*) tm_cr_tm (*‹⟦2 ≤ ?k; 4 ≤ ?G⟧ ⟹ turing_machine ?k ?G (tm_cr ?j)›*) assms (*‹2 ≤ k› ‹4 ≤ G› ‹0 < j2› ‹(0::nat) < (j3::nat)› ‹j1 < k› ‹(j2::nat) < (k::nat)› ‹j3 < k›*) tm_unpair_def (*‹tm_unpair (?j1.0::nat) (?j2.0::nat) (?j3.0::nat) ≡ tm_cp_until ?j1.0 ?j2.0 {0::nat, 4::nat, 5::nat} ;; tm_right ?j1.0 ;; tm_cp_until ?j1.0 ?j3.0 {0::nat} ;; tm_cr ?j1.0 ;; tm_cr ?j2.0 ;; tm_cr ?j3.0›*) by simp locale turing_machine_unpair = fixes j1 j2 j3 :: tapeidx begin definition "tm1 ≡ tm_cp_until j1 j2 {□, ¦, ♯}" definition "tm2 ≡ tm1 ;; tm_right j1" definition "tm3 ≡ tm2 ;; tm_cp_until j1 j3 {□}" definition "tm4 ≡ tm3 ;; tm_cr j1" definition "tm5 ≡ tm4 ;; tm_cr j2" definition "tm6 ≡ tm5 ;; tm_cr j3" lemma tm6_eq_tm_unpair: "tm6 = tm_unpair j1 j2 j3" unfolding tm6_def tm5_def tm4_def tm3_def tm2_def tm1_def tm_unpair_def (*goal: ‹tm_cp_until (j1::nat) (j2::nat) {0::nat, 4::nat, 5::nat} ;; tm_right j1 ;; tm_cp_until j1 (j3::nat) {0::nat} ;; tm_cr j1 ;; tm_cr j2 ;; tm_cr j3 = tm_cp_until j1 j2 {0::nat, 4::nat, 5::nat} ;; tm_right j1 ;; tm_cp_until j1 j3 {0::nat} ;; tm_cr j1 ;; tm_cr j2 ;; tm_cr j3›*) by simp context fixes tps0 :: "tape list" and k :: nat and zs :: "symbol list" assumes jk: "0 < j2" "0 < j3" "j1 ≠ j2" "j1 ≠ j3" "j2 ≠ j3" "j1 < k" "j2 < k" "j3 < k" "length tps0 = k" and zs: "proper_symbols zs" and tps0: "tps0 ! j1 = (⌊zs⌋, 1)" "tps0 ! j2 = (⌊[]⌋, 1)" "tps0 ! j3 = (⌊[]⌋, 1)" begin definition "tps1 ≡ tps0 [j1 := (⌊zs⌋, Suc (length (first zs))), j2 := (⌊first zs⌋, Suc (length (first zs)))]" lemma tm1 [transforms_intros]: assumes "ttt = Suc (length (first zs))" shows "transforms tm1 tps0 ttt tps1" unfolding tm1_def (*goal: ‹transforms (tm_cp_until j1 j2 {0, 4, 5}) tps0 ttt tps1›*) proof (tform tps: assms tps0 tps1_def jk) (*goals: 1. ‹rneigh (tps0 ! j1) {0, 4, 5} (length (first zs))› 2. ‹tps1 = tps0[j1 := tps0 ! j1 |+| length (first zs), j2 := implant (tps0 ! j1) (tps0 ! j2) (length (first zs))]›*) let ?n = "length (first zs)" have "*": "tps0 ! j1 = (⌊zs⌋, 1)" using tps0 (*‹(tps0::((nat ⇒ nat) × nat) list) ! (j1::nat) = (⌊zs::nat list⌋, 1::nat)› ‹tps0 ! j2 = (⌊[]⌋, 1)› ‹tps0 ! j3 = (⌊[]⌋, 1)›*) jk (*‹0 < j2› ‹0 < j3› ‹j1 ≠ j2› ‹j1 ≠ j3› ‹j2 ≠ j3› ‹j1 < k› ‹j2 < k› ‹(j3::nat) < (k::nat)› ‹length tps0 = k›*) by simp show "rneigh (tps0 ! j1) {□, ¦, ♯} (length (first zs))" proof (cases "∃i<length zs. zs ! i ∈ {¦, ♯}") (*goals: 1. ‹∃i<length zs. zs ! i ∈ {4, 5} ⟹ rneigh (tps0 ! j1) {0, 4, 5} (length (first zs))› 2. ‹¬ (∃i<length zs. zs ! i ∈ {4, 5}) ⟹ rneigh (tps0 ! j1) {0, 4, 5} (length (first zs))›*) case ex5: True (*‹∃i<length zs. zs ! i ∈ {4, 5}›*) define m where "m = (LEAST i. i < length zs ∧ zs ! i ∈ {¦, ♯})" then have m: "m = length (first zs)" using length_first_ex (*‹⟦∃i<length ?ys. ?ys ! i ∈ {4, 5}; ?m = (LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5})⟧ ⟹ length (first ?ys) = ?m›*) ex5 (*‹∃i<length zs. zs ! i ∈ {4, 5}›*) by simp show "?thesis" (*goal: ‹rneigh (tps0 ! j1) {0, 4, 5} (length (first zs))›*) proof (rule rneighI (*‹⟦fst ?tp (snd ?tp + ?n) ∈ ?H; ⋀n'. n' < ?n ⟹ fst ?tp (snd ?tp + n') ∉ ?H⟧ ⟹ rneigh ?tp ?H ?n›*)) (*goals: 1. ‹((tps0::((nat ⇒ nat) × nat) list) ::: (j1::nat)) (tps0 :#: j1 + length (first (zs::nat list))) ∈ {0::nat, 4::nat, 5::nat}› 2. ‹⋀n'::nat. n' < length (first (zs::nat list)) ⟹ ((tps0::((nat ⇒ nat) × nat) list) ::: (j1::nat)) (tps0 :#: j1 + n') ∉ {0::nat, 4::nat, 5::nat}›*) have "zs ! m ∈ {¦, ♯}" using firstD (*‹⟦∃i<length ?ys. ?ys ! i ∈ {4, 5}; ?m = (LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5})⟧ ⟹ ?m < length ?ys› ‹⟦∃i<length ?ys. ?ys ! i ∈ {4, 5}; ?m = (LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5})⟧ ⟹ ?ys ! ?m ∈ {4, 5}› ‹⟦∃i<length ?ys. ?ys ! i ∈ {4, 5}; ?m = (LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5})⟧ ⟹ ∀i<?m. ?ys ! i ∉ {4, 5}›*) m_def (*‹m = (LEAST i. i < length zs ∧ zs ! i ∈ {4, 5})›*) ex5 (*‹∃i<length zs. zs ! i ∈ {4, 5}›*) by blast then show "(tps0 ::: j1) (tps0 :#: j1 + length (first zs)) ∈ {□, ¦, ♯}" using m (*‹m = length (first zs)›*) "*" (*‹tps0 ! j1 = (⌊zs⌋, 1)›*) contents_def (*‹⌊?xs⌋ ?i ≡ if ?i = 0 then 1 else if ?i ≤ length ?xs then ?xs ! (?i - 1) else 0›*) by simp show "(tps0 ::: j1) (tps0 :#: j1 + i) ∉ {□, ¦, ♯}" if "i < length (first zs)" for i proof (-) (*goal: ‹(tps0 ::: j1) (tps0 :#: j1 + i) ∉ {0, 4, 5}›*) have "m < length zs" using ex5 (*‹∃i<length (zs::nat list). zs ! i ∈ {4::nat, 5::nat}›*) firstD(1) (*‹⟦∃i<length ?ys. ?ys ! i ∈ {4, 5}; ?m = (LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5})⟧ ⟹ ?m < length ?ys›*) length_first_ex (*‹⟦∃i<length (?ys::nat list). ?ys ! i ∈ {4::nat, 5::nat}; (?m::nat) = (LEAST i::nat. i < length ?ys ∧ ?ys ! i ∈ {4::nat, 5::nat})⟧ ⟹ length (first ?ys) = ?m›*) m (*‹m = length (first zs)›*) by blast then have "length (first zs) < length zs" using m (*‹m = length (first zs)›*) by simp then have "i < length zs" using that (*‹i < length (first zs)›*) by simp then have "zs ! i ≠ □" using zs (*‹∀i<length (zs::nat list). Suc (0::nat) < zs ! i›*) by fastforce moreover have "zs ! i ∉ {¦, ♯}" using ex5 (*‹∃i<length zs. zs ! i ∈ {4, 5}›*) firstD(3) (*‹⟦∃i<length (?ys::nat list). ?ys ! i ∈ {4::nat, 5::nat}; (?m::nat) = (LEAST i::nat. i < length ?ys ∧ ?ys ! i ∈ {4::nat, 5::nat})⟧ ⟹ ∀i<?m. ?ys ! i ∉ {4::nat, 5::nat}›*) length_first_ex (*‹⟦∃i<length ?ys. ?ys ! i ∈ {4, 5}; ?m = (LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5})⟧ ⟹ length (first ?ys) = ?m›*) that (*‹(i::nat) < length (first (zs::nat list))›*) by blast ultimately show "?thesis" (*goal: ‹(tps0 ::: j1) (tps0 :#: j1 + i) ∉ {0, 4, 5}›*) using Suc_neq_Zero (*‹Suc ?m = 0 ⟹ ?R›*) ‹i < length zs› (*‹i < length zs›*) "*" (*‹tps0 ! j1 = (⌊zs⌋, 1)›*) by simp qed qed next (*goal: ‹¬ (∃i<length zs. zs ! i ∈ {4, 5}) ⟹ rneigh (tps0 ! j1) {0, 4, 5} (length (first zs))›*) case notex5: False (*‹¬ (∃i<length zs. zs ! i ∈ {4, 5})›*) then have ys: "zs = first zs" using first_notex (*‹¬ (∃i<length ?ys. ?ys ! i ∈ {4, 5}) ⟹ first ?ys = ?ys›*) by simp show "?thesis" (*goal: ‹rneigh (tps0 ! j1) {0, 4, 5} (length (first zs))›*) proof (rule rneighI (*‹⟦fst ?tp (snd ?tp + ?n) ∈ ?H; ⋀n'. n' < ?n ⟹ fst ?tp (snd ?tp + n') ∉ ?H⟧ ⟹ rneigh ?tp ?H ?n›*)) (*goals: 1. ‹(tps0 ::: j1) (tps0 :#: j1 + length (first zs)) ∈ {0, 4, 5}› 2. ‹⋀n'. n' < length (first zs) ⟹ (tps0 ::: j1) (tps0 :#: j1 + n') ∉ {0, 4, 5}›*) show "(tps0 ::: j1) (tps0 :#: j1 + length (first zs)) ∈ {□, ¦, ♯}" using ys (*‹zs = first zs›*) "*" (*‹(tps0::((nat ⇒ nat) × nat) list) ! (j1::nat) = (⌊zs::nat list⌋, 1::nat)›*) by simp show "(tps0 ::: j1) (tps0 :#: j1 + i) ∉ {□, ¦, ♯}" if "i < length (first zs)" for i using notex5 (*‹¬ (∃i<length zs. zs ! i ∈ {4, 5})›*) that (*‹i < length (first zs)›*) ys (*‹zs = first zs›*) proper_bindecode (*‹∀i<length (bindecode ?zs). Suc 0 < bindecode ?zs ! i›*) contents_inbounds (*‹⟦(0::nat) < (?i::nat); ?i ≤ length (?zs::nat list)⟧ ⟹ ⌊?zs⌋ ?i = ?zs ! (?i - (1::nat))›*) "*" (*‹tps0 ! j1 = (⌊zs⌋, 1)›*) zs (*‹∀i<length zs. Suc 0 < zs ! i›*) by auto qed qed have 1: "implant (tps0 ! j1) (tps0 ! j2) ?n = (⌊first zs⌋, Suc ?n)" proof (-) (*goal: ‹implant ((tps0::((nat ⇒ nat) × nat) list) ! (j1::nat)) (tps0 ! (j2::nat)) (length (first (zs::nat list))) = (⌊first zs⌋, Suc (length (first zs)))›*) have "implant (tps0 ! j1) (tps0 ! j2) ?n = (⌊[] @ take (length (first zs)) (drop (1 - 1) zs)⌋, Suc (length []) + length (first zs))" using implant_contents[of 1 "length (first zs)" zs "[]"] (*‹⟦0 < 1; length (first zs) + (1 - 1) ≤ length zs⟧ ⟹ implant (⌊zs⌋, 1) (⌊[]⌋, Suc (length [])) (length (first zs)) = (⌊[] @ take (length (first zs)) (drop (1 - 1) zs)⌋, Suc (length []) + length (first zs))›*) tps0(1,2) (*‹tps0 ! j1 = (⌊zs⌋, 1)› ‹tps0 ! j2 = (⌊[]⌋, 1)›*) by (metis (mono_tags, lifting) add.right_neutral (*‹?a + 0 = ?a›*) diff_Suc_1 (*‹Suc ?n - 1 = ?n›*) le_eq_less_or_eq (*‹(?m ≤ ?n) = (?m < ?n ∨ ?m = ?n)›*) firstD( (*‹⟦∃i<length ?ys. ?ys ! i ∈ {4, 5}; ?m = (LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5})⟧ ⟹ ?m < length ?ys›*) 1) first_notex (*‹¬ (∃i<length ?ys. ?ys ! i ∈ {4, 5}) ⟹ first ?ys = ?ys›*) length_first_ex (*‹⟦∃i<length ?ys. ?ys ! i ∈ {4, 5}; ?m = (LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5})⟧ ⟹ length (first ?ys) = ?m›*) less_one (*‹(?n < 1) = (?n = 0)›*) list.size( (*‹length [] = 0›*) 3) plus_1_eq_Suc (*‹(+) 1 = Suc›*)) then have "implant (tps0 ! j1) (tps0 ! j2) ?n = (⌊take ?n zs⌋, Suc ?n)" by simp then show "implant (tps0 ! j1) (tps0 ! j2) ?n = (⌊first zs⌋, Suc ?n)" using first_def (*‹first ?ys ≡ take (if ∃i<length ?ys. ?ys ! i ∈ {4, 5} then LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5} else length ?ys) ?ys›*) length_first_ex (*‹⟦∃i<length (?ys::nat list). ?ys ! i ∈ {4::nat, 5::nat}; (?m::nat) = (LEAST i::nat. i < length ?ys ∧ ?ys ! i ∈ {4::nat, 5::nat})⟧ ⟹ length (first ?ys) = ?m›*) by auto qed have 2: "tps0 ! j1 |+| ?n = (⌊zs⌋, Suc ?n)" using tps0 (*‹tps0 ! j1 = (⌊zs⌋, 1)› ‹tps0 ! j2 = (⌊[]⌋, 1)› ‹tps0 ! j3 = (⌊[]⌋, 1)›*) jk (*‹(0::nat) < (j2::nat)› ‹0 < j3› ‹(j1::nat) ≠ (j2::nat)› ‹j1 ≠ j3› ‹j2 ≠ j3› ‹j1 < k› ‹j2 < k› ‹(j3::nat) < (k::nat)› ‹length tps0 = k›*) by simp show "tps1 = tps0 [j1 := tps0 ! j1 |+| ?n, j2 := implant (tps0 ! j1) (tps0 ! j2) ?n]" unfolding tps1_def (*goal: ‹tps0[j1 := (⌊zs⌋, Suc (length (first zs))), j2 := (⌊first zs⌋, Suc (length (first zs)))] = tps0[j1 := tps0 ! j1 |+| length (first zs), j2 := implant (tps0 ! j1) (tps0 ! j2) (length (first zs))]›*) using jk (*‹(0::nat) < (j2::nat)› ‹0 < j3› ‹j1 ≠ j2› ‹(j1::nat) ≠ (j3::nat)› ‹j2 ≠ j3› ‹(j1::nat) < (k::nat)› ‹j2 < k› ‹j3 < k› ‹length tps0 = k›*) "1" (*‹implant (tps0 ! j1) (tps0 ! j2) (length (first zs)) = (⌊first zs⌋, Suc (length (first zs)))›*) "2" (*‹(tps0::((nat ⇒ nat) × nat) list) ! (j1::nat) |+| length (first (zs::nat list)) = (⌊zs⌋, Suc (length (first zs)))›*) by simp qed definition "tps2 ≡ tps0 [j1 := (⌊zs⌋, length (first zs) + 2), j2 := (⌊first zs⌋, Suc (length (first zs)))]" lemma tm2 [transforms_intros]: assumes "ttt = length (first zs) + 2" shows "transforms tm2 tps0 ttt tps2" unfolding tm2_def (*goal: ‹transforms (tm1 ;; tm_right j1) tps0 ttt tps2›*) proof (tform tps: tps1_def jk tps2_def time: assms) (*goal: ‹tps2 = tps1[j1 := tps1 ! j1 |+| 1]›*) have "tps1 ! j1 |+| 1 = (⌊zs⌋, length (first zs) + 2)" using tps1_def (*‹tps1 ≡ (tps0::((nat ⇒ nat) × nat) list)[j1::nat := (⌊zs::nat list⌋, Suc (length (first zs))), j2::nat := (⌊first zs⌋, Suc (length (first zs)))]›*) jk (*‹0 < j2› ‹0 < j3› ‹j1 ≠ j2› ‹(j1::nat) ≠ (j3::nat)› ‹j2 ≠ j3› ‹j1 < k› ‹(j2::nat) < (k::nat)› ‹j3 < k› ‹length tps0 = k›*) by simp then show "tps2 = tps1[j1 := tps1 ! j1 |+| 1]" unfolding tps2_def tps1_def (*goal: ‹tps0[j1 := (⌊zs⌋, length (first zs) + 2), j2 := (⌊first zs⌋, Suc (length (first zs)))] = tps0[j1 := (⌊zs⌋, Suc (length (first zs))), j2 := (⌊first zs⌋, Suc (length (first zs))), j1 := tps0[j1 := (⌊zs⌋, Suc (length (first zs))), j2 := (⌊first zs⌋, Suc (length (first zs)))] ! j1 |+| 1]›*) using jk (*‹0 < j2› ‹0 < j3› ‹j1 ≠ j2› ‹j1 ≠ j3› ‹(j2::nat) ≠ (j3::nat)› ‹j1 < k› ‹j2 < k› ‹j3 < k› ‹length tps0 = k›*) by (simp add: list_update_swap (*‹?i ≠ ?i' ⟹ ?xs[?i := ?x, ?i' := ?x'] = ?xs[?i' := ?x', ?i := ?x]›*)) qed definition "tps3 ≡ tps0 [j1 := (⌊zs⌋, length (first zs) + 2 + (length zs - Suc (length (first zs)))), j2 := (⌊first zs⌋, Suc (length (first zs))), j3 := (⌊second zs⌋, Suc (length (second zs)))]" lemma tm3 [transforms_intros]: assumes "ttt = length (first zs) + 2 + Suc (length zs - Suc (length (first zs)))" shows "transforms tm3 tps0 ttt tps3" unfolding tm3_def (*goal: ‹transforms (tm2 ;; tm_cp_until (j1::nat) (j3::nat) {0::nat}) (tps0::((nat ⇒ nat) × nat) list) (ttt::nat) tps3›*) proof (tform tps: assms tps2_def tps3_def jk) (*goals: 1. ‹rneigh (tps2 ! j1) {0} (length zs - Suc (length (first zs)))› 2. ‹tps3 = tps2[j1 := tps2 ! j1 |+| length zs - Suc (length (first zs)), j3 := implant (tps2 ! j1) (tps2 ! j3) (length zs - Suc (length (first zs)))]›*) let ?ll = "length (first zs)" let ?n = "length zs - Suc ?ll" have at_j1: "tps2 ! j1 = (⌊zs⌋, length (first zs) + 2)" using tps2_def (*‹tps2 ≡ (tps0::((nat ⇒ nat) × nat) list)[j1::nat := (⌊zs::nat list⌋, length (first zs) + (2::nat)), j2::nat := (⌊first zs⌋, Suc (length (first zs)))]›*) jk (*‹(0::nat) < (j2::nat)› ‹0 < j3› ‹j1 ≠ j2› ‹j1 ≠ j3› ‹j2 ≠ j3› ‹j1 < k› ‹j2 < k› ‹j3 < k› ‹length tps0 = k›*) by simp show "rneigh (tps2 ! j1) {0} ?n" proof (rule rneighI (*‹⟦fst ?tp (snd ?tp + ?n) ∈ ?H; ⋀n'. n' < ?n ⟹ fst ?tp (snd ?tp + n') ∉ ?H⟧ ⟹ rneigh ?tp ?H ?n›*)) (*goals: 1. ‹(tps2 ::: j1) (tps2 :#: j1 + (length zs - Suc (length (first zs)))) ∈ {0}› 2. ‹⋀n'. n' < length zs - Suc (length (first zs)) ⟹ (tps2 ::: j1) (tps2 :#: j1 + n') ∉ {0}›*) show "(tps2 ::: j1) (tps2 :#: j1 + (length zs - Suc ?ll)) ∈ {0}" using at_j1 (*‹tps2 ! (j1::nat) = (⌊zs::nat list⌋, length (first zs) + (2::nat))›*) by simp show "(tps2 ::: j1) (tps2 :#: j1 + m) ∉ {0}" if "m < length zs - Suc ?ll" for m proof (-) (*goal: ‹(tps2 ::: j1) (tps2 :#: j1 + m) ∉ {0}›*) have "*": "(tps2 ::: j1) (tps2 :#: j1 + m) = ⌊zs⌋ (?ll + 2 + m)" using at_j1 (*‹tps2 ! j1 = (⌊zs⌋, length (first zs) + 2)›*) by simp have "Suc ?ll < length zs" using that (*‹m < length zs - Suc (length (first zs))›*) by simp then have "?ll + 2 + m ≤ Suc (length zs)" using that (*‹m < length zs - Suc (length (first zs))›*) by simp then have "⌊zs⌋ (?ll + 2 + m) = zs ! (?ll + 1 + m)" using that (*‹m < length zs - Suc (length (first zs))›*) by simp then have "⌊zs⌋ (?ll + 2 + m) > 0" using zs (*‹∀i<length (zs::nat list). Suc (0::nat) < zs ! i›*) that (*‹(m::nat) < length (zs::nat list) - Suc (length (first zs))›*) by (metis add.commute (*‹(?a::?'a::ab_semigroup_add) + (?b::?'a::ab_semigroup_add) = ?b + ?a›*) gr0I (*‹((?n::nat) = (0::nat) ⟹ 𝕆) ⟹ (0::nat) < ?n›*) less_diff_conv (*‹((?i::nat) < (?j::nat) - (?k::nat)) = (?i + ?k < ?j)›*) not_add_less2 (*‹¬ (?j::nat) + (?i::nat) < ?i›*) plus_1_eq_Suc (*‹(+) (1::nat) = Suc›*)) then show "?thesis" (*goal: ‹(tps2 ::: (j1::nat)) (tps2 :#: j1 + (m::nat)) ∉ {0::nat}›*) using "*" (*‹(tps2 ::: (j1::nat)) (tps2 :#: j1 + (m::nat)) = ⌊zs::nat list⌋ (length (first zs) + (2::nat) + m)›*) by simp qed qed have 1: "implant (tps2 ! j1) (tps2 ! j3) ?n = (⌊second zs⌋, Suc (length (second zs)))" proof (cases "Suc ?ll ≤ length zs") (*goals: 1. ‹Suc (length (first zs)) ≤ length zs ⟹ implant (tps2 ! j1) (tps2 ! j3) (length zs - Suc (length (first zs))) = (⌊second zs⌋, Suc (length (second zs)))› 2. ‹¬ Suc (length (first zs)) ≤ length zs ⟹ implant (tps2 ! j1) (tps2 ! j3) (length zs - Suc (length (first zs))) = (⌊second zs⌋, Suc (length (second zs)))›*) case True (*‹Suc (length (first zs)) ≤ length zs›*) have "implant (tps2 ! j1) (tps2 ! j3) ?n = implant (⌊zs⌋, ?ll + 2) (⌊[]⌋, 1) ?n" using tps2_def (*‹tps2 ≡ tps0[j1 := (⌊zs⌋, length (first zs) + 2), j2 := (⌊first zs⌋, Suc (length (first zs)))]›*) jk (*‹0 < j2› ‹(0::nat) < (j3::nat)› ‹(j1::nat) ≠ (j2::nat)› ‹j1 ≠ j3› ‹j2 ≠ j3› ‹j1 < k› ‹j2 < k› ‹j3 < k› ‹length tps0 = k›*) by (metis at_j1 (*‹tps2 ! j1 = (⌊zs⌋, length (first zs) + 2)›*) nth_list_update_neq' (*‹?j ≠ ?i ⟹ ?xs[?i := ?x] ! ?j = ?xs ! ?j›*) tps0( (*‹tps0 ! j3 = (⌊[]⌋, 1)›*) 3)) also (*calculation: ‹implant (tps2 ! j1) (tps2 ! j3) (length zs - Suc (length (first zs))) = implant (⌊zs⌋, length (first zs) + 2) (⌊[]⌋, 1) (length zs - Suc (length (first zs)))›*) have "... = (⌊take ?n (drop (Suc ?ll) zs)⌋, Suc ?n)" using True (*‹Suc (length (first (zs::nat list))) ≤ length zs›*) implant_contents (*‹⟦(0::nat) < (?i::nat); (?n::nat) + (?i - (1::nat)) ≤ length (?xs::nat list)⟧ ⟹ implant (⌊?xs⌋, ?i) (⌊?ys::nat list⌋, Suc (length ?ys)) ?n = (⌊?ys @ take ?n (drop (?i - (1::nat)) ?xs)⌋, Suc (length ?ys) + ?n)›*) by (metis (no_types, lifting) One_nat_def (*‹1 = Suc 0›*) add.commute (*‹?a + ?b = ?b + ?a›*) add_2_eq_Suc' (*‹?n + 2 = Suc (Suc ?n)›*) append.simps( (*‹[] @ ?ys = ?ys›*) 1) diff_Suc_1 (*‹Suc ?n - 1 = ?n›*) dual_order.refl (*‹?a ≤ ?a›*) le_add_diff_inverse2 (*‹?b ≤ ?a ⟹ ?a - ?b + ?b = ?a›*) list.size( (*‹length [] = 0›*) 3) plus_1_eq_Suc (*‹(+) 1 = Suc›*) zero_less_Suc (*‹0 < Suc ?n›*)) also (*calculation: ‹implant (tps2 ! j1) (tps2 ! j3) (length zs - Suc (length (first zs))) = (⌊take (length zs - Suc (length (first zs))) (drop (Suc (length (first zs))) zs)⌋, Suc (length zs - Suc (length (first zs))))›*) have "... = (⌊take (length (second zs)) (drop (Suc ?ll) zs)⌋, Suc (length (second zs)))" using length_second_first (*‹length (second ?zs) = length ?zs - Suc (length (first ?zs))›*) by simp also (*calculation: ‹implant (tps2 ! j1) (tps2 ! j3) (length zs - Suc (length (first zs))) = (⌊take (length (second zs)) (drop (Suc (length (first zs))) zs)⌋, Suc (length (second zs)))›*) have "... = (⌊second zs⌋, Suc (length (second zs)))" using second_def (*‹second (?zs::nat list) ≡ drop (Suc (length (first ?zs))) ?zs›*) by simp finally (*calculation: ‹implant (tps2 ! j1) (tps2 ! j3) (length zs - Suc (length (first zs))) = (⌊second zs⌋, Suc (length (second zs)))›*) show "?thesis" (*goal: ‹implant (tps2 ! j1) (tps2 ! j3) (length zs - Suc (length (first zs))) = (⌊second zs⌋, Suc (length (second zs)))›*) . next (*goal: ‹¬ Suc (length (first zs)) ≤ length zs ⟹ implant (tps2 ! j1) (tps2 ! j3) (length zs - Suc (length (first zs))) = (⌊second zs⌋, Suc (length (second zs)))›*) case False (*‹¬ Suc (length (first zs)) ≤ length zs›*) then have "?n = 0" by simp then have "implant (tps2 ! j1) (tps2 ! j3) ?n = implant (⌊zs⌋, ?ll + 2) (⌊[]⌋, 1) 0" using tps2_def (*‹tps2 ≡ tps0[j1 := (⌊zs⌋, length (first zs) + 2), j2 := (⌊first zs⌋, Suc (length (first zs)))]›*) jk (*‹0 < j2› ‹(0::nat) < (j3::nat)› ‹(j1::nat) ≠ (j2::nat)› ‹j1 ≠ j3› ‹j2 ≠ j3› ‹j1 < k› ‹j2 < k› ‹j3 < k› ‹length tps0 = k›*) by (metis at_j1 (*‹tps2 ! j1 = (⌊zs⌋, length (first zs) + 2)›*) nth_list_update_neq' (*‹?j ≠ ?i ⟹ ?xs[?i := ?x] ! ?j = ?xs ! ?j›*) tps0( (*‹tps0 ! j3 = (⌊[]⌋, 1)›*) 3)) then have "implant (tps2 ! j1) (tps2 ! j3) ?n = (⌊[]⌋, 1)" using transplant_0 (*‹transplant ?tp1.0 ?tp2.0 ?f 0 = ?tp2.0›*) by simp moreover have "second zs = []" using False (*‹¬ Suc (length (first zs)) ≤ length zs›*) second_def (*‹second ?zs ≡ drop (Suc (length (first ?zs))) ?zs›*) by simp ultimately show "?thesis" (*goal: ‹implant (tps2 ! j1) (tps2 ! j3) (length zs - Suc (length (first zs))) = (⌊second zs⌋, Suc (length (second zs)))›*) by simp qed show "tps3 = tps2 [j1 := tps2 ! j1 |+| ?n, j3 := implant (tps2 ! j1) (tps2 ! j3) ?n]" using tps3_def (*‹tps3 ≡ (tps0::((nat ⇒ nat) × nat) list)[j1::nat := (⌊zs::nat list⌋, length (first zs) + (2::nat) + (length zs - Suc (length (first zs)))), j2::nat := (⌊first zs⌋, Suc (length (first zs))), j3::nat := (⌊second zs⌋, Suc (length (second zs)))]›*) tps2_def (*‹tps2 ≡ tps0[j1 := (⌊zs⌋, length (first zs) + 2), j2 := (⌊first zs⌋, Suc (length (first zs)))]›*) using "1" (*‹implant (tps2 ! j1) (tps2 ! j3) (length zs - Suc (length (first zs))) = (⌊second zs⌋, Suc (length (second zs)))›*) jk (*‹0 < j2› ‹0 < j3› ‹j1 ≠ j2› ‹j1 ≠ j3› ‹j2 ≠ j3› ‹j1 < k› ‹(j2::nat) < (k::nat)› ‹j3 < k› ‹length tps0 = k›*) at_j1 (*‹tps2 ! j1 = (⌊zs⌋, length (first zs) + 2)›*) by (simp add: list_update_swap[of j1] (*‹j1 ≠ ?i' ⟹ ?xs[j1 := ?x, ?i' := ?x'] = ?xs[?i' := ?x', j1 := ?x]›*)) qed definition "tps4 ≡ tps0 [j1 := (⌊zs⌋, 1), j2 := (⌊first zs⌋, Suc (length (first zs))), j3 := (⌊second zs⌋, Suc (length (second zs)))]" lemma tm4: assumes "ttt = 2 * length (first zs) + 7 + 2 * (length zs - Suc (length (first zs)))" shows "transforms tm4 tps0 ttt tps4" unfolding tm4_def (*goal: ‹transforms (tm3 ;; tm_cr j1) tps0 ttt tps4›*) proof (tform tps: assms tps3_def tps4_def jk zs) (*goal: ‹tps4 = tps3[j1 := tps3 ! j1 |#=| 1]›*) have "tps3 ! j1 |#=| 1 = (⌊zs⌋, 1)" using tps3_def (*‹tps3 ≡ tps0[j1 := (⌊zs⌋, length (first zs) + 2 + (length zs - Suc (length (first zs)))), j2 := (⌊first zs⌋, Suc (length (first zs))), j3 := (⌊second zs⌋, Suc (length (second zs)))]›*) jk (*‹0 < j2› ‹0 < j3› ‹(j1::nat) ≠ (j2::nat)› ‹(j1::nat) ≠ (j3::nat)› ‹j2 ≠ j3› ‹j1 < k› ‹(j2::nat) < (k::nat)› ‹j3 < k› ‹length tps0 = k›*) by simp then show "tps4 = tps3[j1 := tps3 ! j1 |#=| 1]" unfolding tps4_def tps3_def (*goal: ‹tps0[j1 := (⌊zs⌋, 1), j2 := (⌊first zs⌋, Suc (length (first zs))), j3 := (⌊second zs⌋, Suc (length (second zs)))] = tps0[j1 := (⌊zs⌋, length (first zs) + 2 + (length zs - Suc (length (first zs)))), j2 := (⌊first zs⌋, Suc (length (first zs))), j3 := (⌊second zs⌋, Suc (length (second zs))), j1 := tps0[j1 := (⌊zs⌋, length (first zs) + 2 + (length zs - Suc (length (first zs)))), j2 := (⌊first zs⌋, Suc (length (first zs))), j3 := (⌊second zs⌋, Suc (length (second zs)))] ! j1 |#=| 1]›*) using jk (*‹0 < j2› ‹0 < j3› ‹j1 ≠ j2› ‹j1 ≠ j3› ‹j2 ≠ j3› ‹j1 < k› ‹j2 < k› ‹(j3::nat) < (k::nat)› ‹length tps0 = k›*) by (simp add: list_update_swap (*‹?i ≠ ?i' ⟹ ?xs[?i := ?x, ?i' := ?x'] = ?xs[?i' := ?x', ?i := ?x]›*)) qed lemma tm4' [transforms_intros]: assumes "ttt = 4 * length zs + 7" shows "transforms tm4 tps0 ttt tps4" proof (-) (*goal: ‹transforms tm4 (tps0::((nat ⇒ nat) × nat) list) (ttt::nat) tps4›*) have "2 * length (first zs) + 7 + 2 * (length zs - Suc (length (first zs))) ≤ 2 * length (first zs) + 7 + 2 * length zs" by simp also (*calculation: ‹2 * length (first zs) + 7 + 2 * (length zs - Suc (length (first zs))) ≤ 2 * length (first zs) + 7 + 2 * length zs›*) have "... ≤ 2 * length zs + 7 + 2 * length zs" using length_first (*‹length (first ?ys) ≤ length ?ys›*) by simp also (*calculation: ‹2 * length (first zs) + 7 + 2 * (length zs - Suc (length (first zs))) ≤ 2 * length zs + 7 + 2 * length zs›*) have "... = ttt" using assms (*‹ttt = 4 * length zs + 7›*) by simp finally (*calculation: ‹2 * length (first zs) + 7 + 2 * (length zs - Suc (length (first zs))) ≤ ttt›*) have "2 * length (first zs) + 7 + 2 * (length zs - Suc (length (first zs))) ≤ ttt" . then show "?thesis" (*goal: ‹transforms tm4 tps0 ttt tps4›*) using assms (*‹ttt = 4 * length zs + 7›*) tm4 (*‹?ttt = 2 * length (first zs) + 7 + 2 * (length zs - Suc (length (first zs))) ⟹ transforms tm4 tps0 ?ttt tps4›*) transforms_monotone (*‹⟦transforms ?M ?tps ?t ?tps'; ?t ≤ ?t'⟧ ⟹ transforms ?M ?tps ?t' ?tps'›*) by simp qed definition "tps5 ≡ tps0 [j1 := (⌊zs⌋, 1), j2 := (⌊first zs⌋, 1), j3 := (⌊second zs⌋, Suc (length (second zs)))]" lemma tm5 [transforms_intros]: assumes "ttt = 4 * length zs + 9 + Suc (length (first zs))" shows "transforms tm5 tps0 ttt tps5" unfolding tm5_def (*goal: ‹transforms (tm4 ;; tm_cr j2) tps0 ttt tps5›*) proof (tform tps: assms tps4_def tps5_def jk) (*goals: 1. ‹clean_tape (tps4 ! j2)› 2. ‹tps5 = tps4[j2 := tps4 ! j2 |#=| 1]›*) show "clean_tape (tps4 ! j2)" using zs (*‹∀i<length zs. Suc 0 < zs ! i›*) first_def (*‹first ?ys ≡ take (if ∃i<length ?ys. ?ys ! i ∈ {4, 5} then LEAST i. i < length ?ys ∧ ?ys ! i ∈ {4, 5} else length ?ys) ?ys›*) tps4_def (*‹tps4 ≡ tps0[j1 := (⌊zs⌋, 1), j2 := (⌊first zs⌋, Suc (length (first zs))), j3 := (⌊second zs⌋, Suc (length (second zs)))]›*) jk (*‹0 < j2› ‹0 < j3› ‹j1 ≠ j2› ‹j1 ≠ j3› ‹j2 ≠ j3› ‹(j1::nat) < (k::nat)› ‹(j2::nat) < (k::nat)› ‹j3 < k› ‹length tps0 = k›*) by simp have "tps4 ! j2 |#=| 1 = (⌊first zs⌋, 1)" using tps4_def (*‹tps4 ≡ tps0[j1 := (⌊zs⌋, 1), j2 := (⌊first zs⌋, Suc (length (first zs))), j3 := (⌊second zs⌋, Suc (length (second zs)))]›*) jk (*‹(0::nat) < (j2::nat)› ‹0 < j3› ‹j1 ≠ j2› ‹j1 ≠ j3› ‹j2 ≠ j3› ‹(j1::nat) < (k::nat)› ‹j2 < k› ‹j3 < k› ‹length tps0 = k›*) by simp then show "tps5 = tps4[j2 := tps4 ! j2 |#=| 1]" unfolding tps5_def tps4_def (*goal: ‹tps0[j1 := (⌊zs⌋, 1), j2 := (⌊first zs⌋, 1), j3 := (⌊second zs⌋, Suc (length (second zs)))] = tps0[j1 := (⌊zs⌋, 1), j2 := (⌊first zs⌋, Suc (length (first zs))), j3 := (⌊second zs⌋, Suc (length (second zs))), j2 := tps0[j1 := (⌊zs⌋, 1), j2 := (⌊first zs⌋, Suc (length (first zs))), j3 := (⌊second zs⌋, Suc (length (second zs)))] ! j2 |#=| 1]›*) using jk (*‹(0::nat) < (j2::nat)› ‹(0::nat) < (j3::nat)› ‹(j1::nat) ≠ (j2::nat)› ‹j1 ≠ j3› ‹j2 ≠ j3› ‹(j1::nat) < (k::nat)› ‹j2 < k› ‹j3 < k› ‹length tps0 = k›*) by (simp add: list_update_swap (*‹?i ≠ ?i' ⟹ ?xs[?i := ?x, ?i' := ?x'] = ?xs[?i' := ?x', ?i := ?x]›*)) qed definition "tps6 ≡ tps0 [j1 := (⌊zs⌋, 1), j2 := (⌊first zs⌋, 1), j3 := (⌊second zs⌋, 1)]" lemma tm6: assumes "ttt = 4 * length zs + 11 + Suc (length (first zs)) + Suc (length (second zs))" shows "transforms tm6 tps0 ttt tps6" unfolding tm6_def (*goal: ‹transforms (tm5 ;; tm_cr j3) tps0 ttt tps6›*) proof (tform tps: assms tps5_def tps6_def jk) (*goal: ‹clean_tape (tps5 ! j3)›*) show "clean_tape (tps5 ! j3)" using zs (*‹∀i<length (zs::nat list). Suc (0::nat) < zs ! i›*) second_def (*‹second ?zs ≡ drop (Suc (length (first ?zs))) ?zs›*) tps5_def (*‹tps5 ≡ tps0[j1 := (⌊zs⌋, 1), j2 := (⌊first zs⌋, 1), j3 := (⌊second zs⌋, Suc (length (second zs)))]›*) jk (*‹0 < j2› ‹0 < j3› ‹(j1::nat) ≠ (j2::nat)› ‹j1 ≠ j3› ‹j2 ≠ j3› ‹j1 < k› ‹(j2::nat) < (k::nat)› ‹j3 < k› ‹length tps0 = k›*) by simp qed definition "tps6' ≡ tps0 [j2 := (⌊first zs⌋, 1), j3 := (⌊second zs⌋, 1)]" lemma tps6': "tps6' = tps6" using tps6_def (*‹tps6 ≡ (tps0::((nat ⇒ nat) × nat) list)[j1::nat := (⌊zs::nat list⌋, 1::nat), j2::nat := (⌊first zs⌋, 1::nat), j3::nat := (⌊second zs⌋, 1::nat)]›*) tps6'_def (*‹tps6' ≡ tps0[j2 := (⌊first zs⌋, 1), j3 := (⌊second zs⌋, 1)]›*) list_update_id (*‹?xs[?i := ?xs ! ?i] = ?xs›*) tps0(1) (*‹tps0 ! j1 = (⌊zs⌋, 1)›*) by metis lemma tm6': assumes "ttt = 6 * length zs + 13" shows "transforms tm6 tps0 ttt tps6'" proof (-) (*goal: ‹transforms tm6 (tps0::((nat ⇒ nat) × nat) list) (ttt::nat) tps6'›*) have "4 * length zs + 11 + Suc (length (first zs)) + Suc (length (second zs)) ≤ 4 * length zs + 13 + length zs + length (second zs)" using length_first (*‹length (first ?ys) ≤ length ?ys›*) by simp also (*calculation: ‹4 * length zs + 11 + Suc (length (first zs)) + Suc (length (second zs)) ≤ 4 * length zs + 13 + length zs + length (second zs)›*) have "... ≤ 6 * length zs + 13" using length_second (*‹length (second ?zs) ≤ length ?zs›*) by simp finally (*calculation: ‹4 * length zs + 11 + Suc (length (first zs)) + Suc (length (second zs)) ≤ 6 * length zs + 13›*) have "4 * length zs + 11 + Suc (length (first zs)) + Suc (length (second zs)) ≤ ttt" using assms (*‹ttt = 6 * length zs + 13›*) by simp then show "?thesis" (*goal: ‹transforms tm6 tps0 ttt tps6'›*) using tm6 (*‹?ttt = 4 * length zs + 11 + Suc (length (first zs)) + Suc (length (second zs)) ⟹ transforms tm6 tps0 ?ttt tps6›*) tps6' (*‹tps6' = tps6›*) transforms_monotone (*‹⟦transforms (?M::(nat list ⇒ nat × (nat × direction) list) list) (?tps::((nat ⇒ nat) × nat) list) (?t::nat) (?tps'::((nat ⇒ nat) × nat) list); ?t ≤ (?t'::nat)⟧ ⟹ transforms ?M ?tps ?t' ?tps'›*) by simp qed end (* context *) end (* locale *) lemma transforms_tm_unpairI [transforms_intros]: fixes j1 j2 j3 :: tapeidx fixes tps tps' :: "tape list" and k :: nat and zs :: "symbol list" assumes "0 < j2" "0 < j3" "j1 ≠ j2" "j1 ≠ j3" "j2 ≠ j3" "j1 < k" "j2 < k" "j3 < k" and "length tps = k" and "proper_symbols zs" assumes "tps ! j1 = (⌊zs⌋, 1)" "tps ! j2 = (⌊[]⌋, 1)" "tps ! j3 = (⌊[]⌋, 1)" assumes "ttt = 6 * length zs + 13" assumes "tps' = tps [j2 := (⌊first zs⌋, 1), j3 := (⌊second zs⌋, 1)]" shows "transforms (tm_unpair j1 j2 j3) tps ttt tps'" proof (-) (*goal: ‹transforms (tm_unpair j1 j2 j3) tps ttt tps'›*) interpret loc: turing_machine_unpair j1 j2 j3 . show "?thesis" (*goal: ‹transforms (tm_unpair j1 j2 j3) tps ttt tps'›*) using assms (*‹(0::nat) < (j2::nat)› ‹0 < j3› ‹j1 ≠ j2› ‹j1 ≠ j3› ‹j2 ≠ j3› ‹j1 < k› ‹j2 < k› ‹j3 < k› ‹length tps = k› ‹∀i<length zs. Suc 0 < zs ! i› ‹tps ! j1 = (⌊zs⌋, 1)› ‹tps ! j2 = (⌊[]⌋, 1)› and more 3 facts*) loc.tps6'_def (*‹⟦0 < j2; 0 < j3; j1 ≠ j2; j1 ≠ j3; j2 ≠ j3; j1 < ?k; j2 < ?k; j3 < ?k; length ?tps0.0 = ?k; ∀i<length ?zs. Suc 0 < ?zs ! i; ?tps0.0 ! j1 = (⌊?zs⌋, 1); ?tps0.0 ! j2 = (⌊[]⌋, 1); ?tps0.0 ! j3 = (⌊[]⌋, 1)⟧ ⟹ loc.tps6' ?tps0.0 ?zs ≡ ?tps0.0[j2 := (⌊first ?zs⌋, 1), j3 := (⌊second ?zs⌋, 1)]›*) loc.tm6' (*‹⟦0 < j2; 0 < j3; j1 ≠ j2; j1 ≠ j3; j2 ≠ j3; j1 < ?k; j2 < ?k; j3 < ?k; length ?tps0.0 = ?k; ∀i<length ?zs. Suc 0 < ?zs ! i; ?tps0.0 ! j1 = (⌊?zs⌋, 1); ?tps0.0 ! j2 = (⌊[]⌋, 1); ?tps0.0 ! j3 = (⌊[]⌋, 1); ?ttt = 6 * length ?zs + 13⟧ ⟹ transforms loc.tm6 ?tps0.0 ?ttt (loc.tps6' ?tps0.0 ?zs)›*) loc.tm6_eq_tm_unpair (*‹loc.tm6 = tm_unpair j1 j2 j3›*) by metis qed end
{ "path": "afp-2025-02-12/thys/Cook_Levin/Symbol_Ops.thy", "repo": "afp-2025-02-12", "sha": "2b6e4782e44b13f2e89689c293016aaa7110892ef1e73ee85295908050291950" }
theory Window imports "HOL-Library.AList" "HOL-Library.Mapping" "HOL-Library.While_Combinator" Timestamp begin type_synonym ('a, 'b) mmap = "('a × 'b) list" (* 'b is a polymorphic input symbol; 'c is a polymorphic DFA state; 'd is a timestamp; 'e is a submonitor state *) inductive chain_le :: "'d :: timestamp list ⇒ bool" where chain_le_Nil: "chain_le []" | chain_le_singleton: "chain_le [x]" | chain_le_cons: "chain_le (y # xs) ⟹ x ≤ y ⟹ chain_le (x # y # xs)" lemma chain_le_app: "chain_le (zs @ [z]) ⟹ z ≤ w ⟹ chain_le ((zs @ [z]) @ [w])" apply (induction "zs @ [z]" arbitrary: zs rule: chain_le.induct) (*goal: ‹⟦chain_le (zs @ [z]); z ≤ w⟧ ⟹ chain_le ((zs @ [z]) @ [w])›*) apply ((auto intro: chain_le.intros (*‹chain_le []› ‹chain_le [?x]› ‹⟦chain_le (?y # ?xs); ?x ≤ ?y⟧ ⟹ chain_le (?x # ?y # ?xs)›*))[2]) (*top goal: ‹⋀zs. ⟦[] = zs @ [z]; z ≤ w⟧ ⟹ chain_le ((zs @ [z]) @ [w])› and 2 goals remain*) subgoal for y and xs and x and zs apply (cases zs) (*goals: 1. ‹⟦chain_le (y # xs); ⋀zs. ⟦y # xs = zs @ [z]; z ≤ w⟧ ⟹ chain_le ((zs @ [z]) @ [w]); x ≤ y; x # y # xs = zs @ [z]; z ≤ w; zs = []⟧ ⟹ chain_le ((zs @ [z]) @ [w])› 2. ‹⋀a list. ⟦chain_le (y # xs); ⋀zs. ⟦y # xs = zs @ [z]; z ≤ w⟧ ⟹ chain_le ((zs @ [z]) @ [w]); x ≤ y; x # y # xs = zs @ [z]; z ≤ w; zs = a # list⟧ ⟹ chain_le ((zs @ [z]) @ [w])› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*goal: ‹⋀a list. ⟦chain_le (y # xs); ⋀zs. ⟦y # xs = zs @ [z]; z ≤ w⟧ ⟹ chain_le ((zs @ [z]) @ [w]); x ≤ y; x # y # xs = zs @ [z]; z ≤ w; zs = a # list⟧ ⟹ chain_le ((zs @ [z]) @ [w])›*) apply (metis append.assoc (*‹(?a @ ?b) @ ?c = ?a @ ?b @ ?c›*) append_Cons (*‹(?x # ?xs) @ ?ys = ?x # ?xs @ ?ys›*) append_Nil (*‹[] @ ?ys = ?ys›*) chain_le_cons (*‹⟦chain_le (?y # ?xs); ?x ≤ ?y⟧ ⟹ chain_le (?x # ?y # ?xs)›*)) (*proven 2 subgoals*) . . inductive reaches_on :: "('e ⇒ ('e × 'f) option) ⇒ 'e ⇒ 'f list ⇒ 'e ⇒ bool" for run :: "'e ⇒ ('e × 'f) option" where "reaches_on run s [] s" | "run s = Some (s', v) ⟹ reaches_on run s' vs s'' ⟹ reaches_on run s (v # vs) s''" lemma reaches_on_init_Some: "reaches_on r s xs s' ⟹ r s' ≠ None ⟹ r s ≠ None" by (auto elim: reaches_on.cases (*‹⟦reaches_on ?run ?a1.0 ?a2.0 ?a3.0; ⋀s. ⟦?a1.0 = s; ?a2.0 = []; ?a3.0 = s⟧ ⟹ ?P; ⋀s s' v vs s''. ⟦?a1.0 = s; ?a2.0 = v # vs; ?a3.0 = s''; ?run s = Some (s', v); reaches_on ?run s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*)) lemma reaches_on_split: "reaches_on run s vs s' ⟹ i < length vs ⟹ ∃s'' s'''. reaches_on run s (take i vs) s'' ∧ run s'' = Some (s''', vs ! i) ∧ reaches_on run s''' (drop (Suc i) vs) s'" proof (induction s vs s' arbitrary: i rule: reaches_on.induct) (*goals: 1. ‹⋀s i. i < length [] ⟹ ∃s'' s'''. reaches_on run s (take i []) s'' ∧ run s'' = Some (s''', [] ! i) ∧ reaches_on run s''' (drop (Suc i) []) s› 2. ‹⋀s s' v vs s'' i. ⟦run s = Some (s', v); reaches_on run s' vs s''; ⋀i. i < length vs ⟹ ∃s''a s'''. reaches_on run s' (take i vs) s''a ∧ run s''a = Some (s''', vs ! i) ∧ reaches_on run s''' (drop (Suc i) vs) s''; i < length (v # vs)⟧ ⟹ ∃s''a s'''. reaches_on run s (take i (v # vs)) s''a ∧ run s''a = Some (s''', (v # vs) ! i) ∧ reaches_on run s''' (drop (Suc i) (v # vs)) s''›*) case (2 s s' v vs s'') (*‹run s = Some (s', v)› ‹reaches_on run s' vs s''› ‹?i < length vs ⟹ ∃s''a s'''. reaches_on run s' (take ?i vs) s''a ∧ run s''a = Some (s''', vs ! ?i) ∧ reaches_on run s''' (drop (Suc ?i) vs) s''› ‹i < length (v # vs)›*) show "?case" (*goal: ‹∃s''a s'''. reaches_on run s (take i (v # vs)) s''a ∧ run s''a = Some (s''', (v # vs) ! i) ∧ reaches_on run s''' (drop (Suc i) (v # vs)) s''›*) using "2"(1,2) (*‹run s = Some (s', v)› ‹reaches_on run s' vs s''›*) proof (cases i) (*goals: 1. ‹⟦(run::'a ⇒ ('a × 'b) option) (s::'a) = Some (s'::'a, v::'b); reaches_on run s' (vs::'b list) (s''::'a); (i::nat) = (0::nat)⟧ ⟹ ∃(s''a::'a) s'''::'a. reaches_on run s (take i (v # vs)) s''a ∧ run s''a = Some (s''', (v # vs) ! i) ∧ reaches_on run s''' (drop (Suc i) (v # vs)) s''› 2. ‹⋀nat::nat. ⟦(run::'a ⇒ ('a × 'b) option) (s::'a) = Some (s'::'a, v::'b); reaches_on run s' (vs::'b list) (s''::'a); (i::nat) = Suc nat⟧ ⟹ ∃(s''a::'a) s'''::'a. reaches_on run s (take i (v # vs)) s''a ∧ run s''a = Some (s''', (v # vs) ! i) ∧ reaches_on run s''' (drop (Suc i) (v # vs)) s''›*) case (Suc n) (*‹i = Suc n›*) show "?thesis" (*goal: ‹∃s''a s'''. reaches_on run s (take i (v # vs)) s''a ∧ run s''a = Some (s''', (v # vs) ! i) ∧ reaches_on run s''' (drop (Suc i) (v # vs)) s''›*) using "2" (*‹(run::'a ⇒ ('a × 'b) option) (s::'a) = Some (s'::'a, v::'b)› ‹reaches_on (run::'a ⇒ ('a × 'b) option) (s'::'a) (vs::'b list) (s''::'a)› ‹(?i::nat) < length (vs::'b::type list) ⟹ ∃(s''a::'a::type) s'''::'a::type. reaches_on (run::'a::type ⇒ ('a::type × 'b::type) option) (s'::'a::type) (take ?i vs) s''a ∧ run s''a = Some (s''', vs ! ?i) ∧ reaches_on run s''' (drop (Suc ?i) vs) (s''::'a::type)› ‹(i::nat) < length ((v::'b) # (vs::'b list))›*) by (fastforce simp: Suc (*‹i = Suc n›*) intro: reaches_on.intros (*‹reaches_on ?run ?s [] ?s› ‹⟦?run ?s = Some (?s', ?v); reaches_on ?run ?s' ?vs ?s''⟧ ⟹ reaches_on ?run ?s (?v # ?vs) ?s''›*)) qed (auto intro: reaches_on.intros (*‹reaches_on ?run ?s [] ?s› ‹⟦?run ?s = Some (?s', ?v); reaches_on ?run ?s' ?vs ?s''⟧ ⟹ reaches_on ?run ?s (?v # ?vs) ?s''›*)) (*solved the remaining goal: ‹⟦run s = Some (s', v); reaches_on run s' vs s''; i = 0⟧ ⟹ ∃s''a s'''. reaches_on run s (take i (v # vs)) s''a ∧ run s''a = Some (s''', (v # vs) ! i) ∧ reaches_on run s''' (drop (Suc i) (v # vs)) s''›*) qed (auto) (*solved the remaining goal: ‹⋀(s::'a) i::nat. i < length [] ⟹ ∃(s''::'a) s'''::'a. reaches_on (run::'a ⇒ ('a × 'b) option) s (take i []) s'' ∧ run s'' = Some (s''', [] ! i) ∧ reaches_on run s''' (drop (Suc i) []) s›*) lemma reaches_on_split': "reaches_on run s vs s' ⟹ i ≤ length vs ⟹ ∃s'' . reaches_on run s (take i vs) s'' ∧ reaches_on run s'' (drop i vs) s'" proof (induction s vs s' arbitrary: i rule: reaches_on.induct) (*goals: 1. ‹⋀s i. i ≤ length [] ⟹ ∃s''. reaches_on run s (take i []) s'' ∧ reaches_on run s'' (drop i []) s› 2. ‹⋀s s' v vs s'' i. ⟦run s = Some (s', v); reaches_on run s' vs s''; ⋀i. i ≤ length vs ⟹ ∃s''a. reaches_on run s' (take i vs) s''a ∧ reaches_on run s''a (drop i vs) s''; i ≤ length (v # vs)⟧ ⟹ ∃s''a. reaches_on run s (take i (v # vs)) s''a ∧ reaches_on run s''a (drop i (v # vs)) s''›*) case (2 s s' v vs s'') (*‹run s = Some (s', v)› ‹reaches_on run s' vs s''› ‹?i ≤ length vs ⟹ ∃s''a. reaches_on run s' (take ?i vs) s''a ∧ reaches_on run s''a (drop ?i vs) s''› ‹i ≤ length (v # vs)›*) show "?case" (*goal: ‹∃s''a. reaches_on run s (take i (v # vs)) s''a ∧ reaches_on run s''a (drop i (v # vs)) s''›*) using "2"(1,2) (*‹run s = Some (s', v)› ‹reaches_on run s' vs s''›*) proof (cases i) (*goals: 1. ‹⟦run s = Some (s', v); reaches_on run s' vs s''; i = 0⟧ ⟹ ∃s''a. reaches_on run s (take i (v # vs)) s''a ∧ reaches_on run s''a (drop i (v # vs)) s''› 2. ‹⋀nat. ⟦run s = Some (s', v); reaches_on run s' vs s''; i = Suc nat⟧ ⟹ ∃s''a. reaches_on run s (take i (v # vs)) s''a ∧ reaches_on run s''a (drop i (v # vs)) s''›*) case (Suc n) (*‹i = Suc n›*) show "?thesis" (*goal: ‹∃s''a. reaches_on run s (take i (v # vs)) s''a ∧ reaches_on run s''a (drop i (v # vs)) s''›*) using "2" (*‹run s = Some (s', v)› ‹reaches_on run s' vs s''› ‹?i ≤ length vs ⟹ ∃s''a. reaches_on run s' (take ?i vs) s''a ∧ reaches_on run s''a (drop ?i vs) s''› ‹i ≤ length (v # vs)›*) by (fastforce simp: Suc (*‹i = Suc n›*) intro: reaches_on.intros (*‹reaches_on ?run ?s [] ?s› ‹⟦?run ?s = Some (?s', ?v); reaches_on ?run ?s' ?vs ?s''⟧ ⟹ reaches_on ?run ?s (?v # ?vs) ?s''›*)) qed (auto intro: reaches_on.intros (*‹reaches_on ?run ?s [] ?s› ‹⟦?run ?s = Some (?s', ?v); reaches_on ?run ?s' ?vs ?s''⟧ ⟹ reaches_on ?run ?s (?v # ?vs) ?s''›*)) (*solved the remaining goal: ‹⟦run s = Some (s', v); reaches_on run s' vs s''; i = 0⟧ ⟹ ∃s''a. reaches_on run s (take i (v # vs)) s''a ∧ reaches_on run s''a (drop i (v # vs)) s''›*) qed (auto intro: reaches_on.intros (*‹reaches_on ?run ?s [] ?s› ‹⟦?run ?s = Some (?s', ?v); reaches_on ?run ?s' ?vs ?s''⟧ ⟹ reaches_on ?run ?s (?v # ?vs) ?s''›*)) (*solved the remaining goal: ‹⋀(s::'a) i::nat. i ≤ length [] ⟹ ∃s''::'a. reaches_on (run::'a ⇒ ('a × 'b) option) s (take i []) s'' ∧ reaches_on run s'' (drop i []) s›*) lemma reaches_on_split_app: "reaches_on run s (vs @ vs') s' ⟹ ∃s''. reaches_on run s vs s'' ∧ reaches_on run s'' vs' s'" using reaches_on_split'[where i = "length vs", of run s "vs @ vs'" s'] (*‹⟦reaches_on (run::'a::type ⇒ ('a::type × 'b::type) option) (s::'a::type) ((vs::'b::type list) @ (vs'::'b::type list)) (s'::'a::type); length vs ≤ length (vs @ vs')⟧ ⟹ ∃s''::'a::type. reaches_on run s (take (length vs) (vs @ vs')) s'' ∧ reaches_on run s'' (drop (length vs) (vs @ vs')) s'›*) by auto lemma reaches_on_inj: "reaches_on run s vs t ⟹ reaches_on run s vs' t' ⟹ length vs = length vs' ⟹ vs = vs' ∧ t = t'" apply (induction s vs t arbitrary: vs' t' rule: reaches_on.induct) (*goal: ‹⟦reaches_on (run::'a ⇒ ('a × 'b) option) (s::'a) (vs::'b list) (t::'a); reaches_on run s (vs'::'b list) (t'::'a); length vs = length vs'⟧ ⟹ vs = vs' ∧ t = t'›*) apply ((auto elim: reaches_on.cases (*‹⟦reaches_on (?run::?'e::type ⇒ (?'e::type × ?'f::type) option) (?a1.0::?'e::type) (?a2.0::?'f::type list) (?a3.0::?'e::type); ⋀s::?'e::type. ⟦?a1.0 = s; ?a2.0 = []; ?a3.0 = s⟧ ⟹ ?P::bool; ⋀(s::?'e::type) (s'::?'e::type) (v::?'f::type) (vs::?'f::type list) s''::?'e::type. ⟦?a1.0 = s; ?a2.0 = v # vs; ?a3.0 = s''; ?run s = Some (s', v); reaches_on ?run s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*))[1]) (*top goal: ‹⋀(s::'a) (vs'::'b list) t'::'a. ⟦reaches_on (run::'a ⇒ ('a × 'b) option) s vs' t'; length [] = length vs'⟧ ⟹ [] = vs' ∧ s = t'› and 1 goal remains*) subgoal for s and s' and v and vs and s'' and vs' and t' apply (rule reaches_on.cases[of run s' vs s''] (*‹⟦reaches_on run s' vs s''; ⋀s. ⟦s' = s; vs = []; s'' = s⟧ ⟹ ?P; ⋀s s'a v vs s''a. ⟦s' = s; vs = v # vs; s'' = s''a; run s = Some (s'a, v); reaches_on run s'a vs s''a⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹⟦run s = Some (s', v); reaches_on run s' vs s''; ⋀vs' t'. ⟦reaches_on run s' vs' t'; length vs = length vs'⟧ ⟹ vs = vs' ∧ s'' = t'; reaches_on run s vs' t'; length (v # vs) = length vs'⟧ ⟹ reaches_on run s' vs s''› 2. ‹⋀s. ⟦run s = Some (s', v); reaches_on run s' vs s''; ⋀vs' t'. ⟦reaches_on run s' vs' t'; length vs = length vs'⟧ ⟹ vs = vs' ∧ s'' = t'; reaches_on run s vs' t'; length (v # vs) = length vs'; s' = s; vs = []; s'' = s⟧ ⟹ v # vs = vs' ∧ s'' = t'› 3. ‹⋀s s'a va vs s''a. ⟦run s = Some (s', v); reaches_on run s' vs s''; ⋀vs' t'. ⟦reaches_on run s' vs' t'; length vs = length vs'⟧ ⟹ vs = vs' ∧ s'' = t'; reaches_on run s vs' t'; length (v # vs) = length vs'; s' = s; vs = va # vs; s'' = s''a; run s = Some (s'a, va); reaches_on run s'a vs s''a⟧ ⟹ v # vs = vs' ∧ s'' = t'› discuss goal 1*) apply (rule reaches_on.cases[of run s vs' t'] (*‹⟦reaches_on run s vs' t'; ⋀s. ⟦s = s; vs' = []; t' = s⟧ ⟹ ?P; ⋀s s' v vs s''. ⟦s = s; vs' = v # vs; t' = s''; run s = Some (s', v); reaches_on run s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹⟦run s = Some (s', v); reaches_on run s' vs s''; ⋀vs' t'. ⟦reaches_on run s' vs' t'; length vs = length vs'⟧ ⟹ vs = vs' ∧ s'' = t'; reaches_on run s vs' t'; length (v # vs) = length vs'⟧ ⟹ reaches_on run s vs' t'› 2. ‹⋀s. ⟦run s = Some (s', v); reaches_on run s' vs s''; ⋀vs' t'. ⟦reaches_on run s' vs' t'; length vs = length vs'⟧ ⟹ vs = vs' ∧ s'' = t'; reaches_on run s vs' t'; length (v # vs) = length vs'; s = s; vs' = []; t' = s⟧ ⟹ reaches_on run s' vs s''› 3. ‹⋀s s'a va vs s''a. ⟦run s = Some (s', v); reaches_on run s' vs s''; ⋀vs' t'. ⟦reaches_on run s' vs' t'; length vs = length vs'⟧ ⟹ vs = vs' ∧ s'' = t'; reaches_on run s vs' t'; length (v # vs) = length vs'; s = s; vs' = va # vs; t' = s''a; run s = Some (s'a, va); reaches_on run s'a vs s''a⟧ ⟹ reaches_on run s' vs s''› discuss goal 1*) apply assumption (*discuss goal 2*) apply assumption (*discuss goal 3*) apply assumption (*proven 3 subgoals*) (*discuss goal 2*) apply (rule reaches_on.cases[of run s vs' t'] (*‹⟦reaches_on run s vs' t'; ⋀s. ⟦s = s; vs' = []; t' = s⟧ ⟹ ?P; ⋀s s' v vs s''. ⟦s = s; vs' = v # vs; t' = s''; run s = Some (s', v); reaches_on run s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹⋀s. ⟦run s = Some (s', v); reaches_on run s' vs s''; ⋀vs' t'. ⟦reaches_on run s' vs' t'; length vs = length vs'⟧ ⟹ vs = vs' ∧ s'' = t'; reaches_on run s vs' t'; length (v # vs) = length vs'; s' = s; vs = []; s'' = s⟧ ⟹ reaches_on run s vs' t'› 2. ‹⋀s saa. ⟦run s = Some (s', v); reaches_on run s' vs s''; ⋀vs' t'. ⟦reaches_on run s' vs' t'; length vs = length vs'⟧ ⟹ vs = vs' ∧ s'' = t'; reaches_on run s vs' t'; length (v # vs) = length vs'; s' = s; vs = []; s'' = s; s = saa; vs' = []; t' = saa⟧ ⟹ v # vs = vs' ∧ s'' = t'› 3. ‹⋀s saa s'a va vs s''a. ⟦run s = Some (s', v); reaches_on run s' vs s''; ⋀vs' t'. ⟦reaches_on run s' vs' t'; length vs = length vs'⟧ ⟹ vs = vs' ∧ s'' = t'; reaches_on run s vs' t'; length (v # vs) = length vs'; s' = s; vs = []; s'' = s; s = saa; vs' = va # vs; t' = s''a; run saa = Some (s'a, va); reaches_on run s'a vs s''a⟧ ⟹ v # vs = vs' ∧ s'' = t'› discuss goal 1*) apply assumption (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) (*discuss goal 3*) apply (rule reaches_on.cases[of run s vs' t'] (*‹⟦reaches_on run s vs' t'; ⋀s. ⟦s = s; vs' = []; t' = s⟧ ⟹ ?P; ⋀s s' v vs s''. ⟦s = s; vs' = v # vs; t' = s''; run s = Some (s', v); reaches_on run s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹⋀s s'a va vs s''a. ⟦run s = Some (s', v); reaches_on run s' vs s''; ⋀vs' t'. ⟦reaches_on run s' vs' t'; length vs = length vs'⟧ ⟹ vs = vs' ∧ s'' = t'; reaches_on run s vs' t'; length (v # vs) = length vs'; s' = s; vs = va # vs; s'' = s''a; run s = Some (s'a, va); reaches_on run s'a vs s''a⟧ ⟹ reaches_on run s vs' t'› 2. ‹⋀s s'a va vs s''a saa. ⟦run s = Some (s', v); reaches_on run s' vs s''; ⋀vs' t'. ⟦reaches_on run s' vs' t'; length vs = length vs'⟧ ⟹ vs = vs' ∧ s'' = t'; reaches_on run s vs' t'; length (v # vs) = length vs'; s' = s; vs = va # vs; s'' = s''a; run s = Some (s'a, va); reaches_on run s'a vs s''a; s = saa; vs' = []; t' = saa⟧ ⟹ v # vs = vs' ∧ s'' = t'› 3. ‹⋀s s'a va vs s''a saa s'aa vaa vsaa s''aa. ⟦run s = Some (s', v); reaches_on run s' vs s''; ⋀vs' t'. ⟦reaches_on run s' vs' t'; length vs = length vs'⟧ ⟹ vs = vs' ∧ s'' = t'; reaches_on run s vs' t'; length (v # vs) = length vs'; s' = s; vs = va # vs; s'' = s''a; run s = Some (s'a, va); reaches_on run s'a vs s''a; s = saa; vs' = vaa # vsaa; t' = s''aa; run saa = Some (s'aa, vaa); reaches_on run s'aa vsaa s''aa⟧ ⟹ v # vs = vs' ∧ s'' = t'› discuss goal 1*) apply fastforce (*discuss goal 2*) apply (metis length_0_conv (*‹(length ?xs = 0) = (?xs = [])›*) list.discI (*‹?list = ?x21.0 # ?x22.0 ⟹ ?list ≠ []›*)) (*discuss goal 3*) apply (metis Pair_inject (*‹⟦(?a, ?b) = (?a', ?b'); ⟦?a = ?a'; ?b = ?b'⟧ ⟹ ?R⟧ ⟹ ?R›*) length_Cons (*‹length (?x # ?xs) = Suc (length ?xs)›*) nat.inject (*‹(Suc ?x2.0 = Suc ?y2.0) = (?x2.0 = ?y2.0)›*) option.inject (*‹(Some ?x2.0 = Some ?y2.0) = (?x2.0 = ?y2.0)›*)) (*proven 3 subgoals*) (*proven 3 subgoals*) . . lemma reaches_on_split_last: "reaches_on run s (xs @ [x]) s'' ⟹ ∃s'. reaches_on run s xs s' ∧ run s' = Some (s'', x)" apply (induction s "xs @ [x]" s'' arbitrary: xs x rule: reaches_on.induct) (*goal: ‹reaches_on run s (xs @ [x]) s'' ⟹ ∃s'. reaches_on run s xs s' ∧ run s' = Some (s'', x)›*) apply simp (*top goal: ‹⋀s xs x. [] = xs @ [x] ⟹ ∃s'. reaches_on run s xs s' ∧ run s' = Some (s, x)› and 1 goal remains*) subgoal for s and s' and v and vs and s'' and xs and x apply (cases vs rule: rev_cases (*‹⟦?xs = [] ⟹ ?P; ⋀ys y. ?xs = ys @ [y] ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹⟦(run::'a ⇒ ('a × 'b) option) (s::'a) = Some (s'::'a, v::'b); reaches_on run s' (vs::'b list) (s''::'a); ⋀(xs::'b list) x::'b. vs = xs @ [x] ⟹ ∃s'a::'a. reaches_on run s' xs s'a ∧ run s'a = Some (s'', x); v # vs = (xs::'b list) @ [x::'b]; vs = []⟧ ⟹ ∃s'::'a. reaches_on run s xs s' ∧ run s' = Some (s'', x)› 2. ‹⋀(ys::'b list) y::'b. ⟦(run::'a ⇒ ('a × 'b) option) (s::'a) = Some (s'::'a, v::'b); reaches_on run s' (vs::'b list) (s''::'a); ⋀(xs::'b list) x::'b. vs = xs @ [x] ⟹ ∃s'a::'a. reaches_on run s' xs s'a ∧ run s'a = Some (s'', x); v # vs = (xs::'b list) @ [x::'b]; vs = ys @ [y]⟧ ⟹ ∃s'::'a. reaches_on run s xs s' ∧ run s' = Some (s'', x)› discuss goal 1*) apply (fastforce elim: reaches_on.cases (*‹⟦reaches_on ?run ?a1.0 ?a2.0 ?a3.0; ⋀s. ⟦?a1.0 = s; ?a2.0 = []; ?a3.0 = s⟧ ⟹ ?P; ⋀s s' v vs s''. ⟦?a1.0 = s; ?a2.0 = v # vs; ?a3.0 = s''; ?run s = Some (s', v); reaches_on ?run s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*) intro: reaches_on.intros (*‹reaches_on ?run ?s [] ?s› ‹⟦?run ?s = Some (?s', ?v); reaches_on ?run ?s' ?vs ?s''⟧ ⟹ reaches_on ?run ?s (?v # ?vs) ?s''›*)) (*discuss goal 2*) apply (fastforce elim: reaches_on.cases (*‹⟦reaches_on ?run ?a1.0 ?a2.0 ?a3.0; ⋀s. ⟦?a1.0 = s; ?a2.0 = []; ?a3.0 = s⟧ ⟹ ?P; ⋀s s' v vs s''. ⟦?a1.0 = s; ?a2.0 = v # vs; ?a3.0 = s''; ?run s = Some (s', v); reaches_on ?run s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*) intro: reaches_on.intros (*‹reaches_on ?run ?s [] ?s› ‹⟦?run ?s = Some (?s', ?v); reaches_on ?run ?s' ?vs ?s''⟧ ⟹ reaches_on ?run ?s (?v # ?vs) ?s''›*)) (*proven 2 subgoals*) . . lemma reaches_on_rev_induct[consumes 1]: "reaches_on run s vs s' ⟹ (⋀s. P s [] s) ⟹ (⋀s s' v vs s''. reaches_on run s vs s' ⟹ P s vs s' ⟹ run s' = Some (s'', v) ⟹ P s (vs @ [v]) s'') ⟹ P s vs s'" proof (induction vs arbitrary: s s' rule: rev_induct) (*goals: 1. ‹⋀s s'. ⟦reaches_on run s [] s'; ⋀s. P s [] s; ⋀s s' v vs s''. ⟦reaches_on run s vs s'; P s vs s'; run s' = Some (s'', v)⟧ ⟹ P s (vs @ [v]) s''⟧ ⟹ P s [] s'› 2. ‹⋀x xs s s'. ⟦⋀s s'. ⟦reaches_on run s xs s'; ⋀s. P s [] s; ⋀s s' v vs s''. ⟦reaches_on run s vs s'; P s vs s'; run s' = Some (s'', v)⟧ ⟹ P s (vs @ [v]) s''⟧ ⟹ P s xs s'; reaches_on run s (xs @ [x]) s'; ⋀s. P s [] s; ⋀s s' v vs s''. ⟦reaches_on run s vs s'; P s vs s'; run s' = Some (s'', v)⟧ ⟹ P s (vs @ [v]) s''⟧ ⟹ P s (xs @ [x]) s'›*) case (snoc x xs) (*‹⟦reaches_on run ?s xs ?s'; ⋀s. P s [] s; ⋀s s' v vs s''. ⟦reaches_on run s vs s'; P s vs s'; run s' = Some (s'', v)⟧ ⟹ P s (vs @ [v]) s''⟧ ⟹ P ?s xs ?s'› ‹reaches_on (run::'a::type ⇒ ('a::type × 'b::type) option) (s::'a::type) ((xs::'b::type list) @ [x::'b::type]) (s'::'a::type)› ‹P ?s [] ?s› ‹⟦reaches_on run ?s ?vs ?s'; P ?s ?vs ?s'; run ?s' = Some (?s'', ?v)⟧ ⟹ P ?s (?vs @ [?v]) ?s''›*) from snoc(2) (*‹reaches_on run s (xs @ [x]) s'›*) obtain s'' where s''_def: "reaches_on run s xs s''" "run s'' = Some (s', x)" (*goal: ‹(⋀s''::'a. ⟦reaches_on (run::'a ⇒ ('a × 'b) option) (s::'a) (xs::'b list) s''; run s'' = Some (s'::'a, x::'b)⟧ ⟹ thesis::bool) ⟹ thesis›*) using reaches_on_split_last (*‹reaches_on ?run ?s (?xs @ [?x]) ?s'' ⟹ ∃s'. reaches_on ?run ?s ?xs s' ∧ ?run s' = Some (?s'', ?x)›*) by fast show "?case" (*goal: ‹(P::'a::type ⇒ 'b::type list ⇒ 'a::type ⇒ bool) (s::'a::type) ((xs::'b::type list) @ [x::'b::type]) (s'::'a::type)›*) using snoc(4)[OF s''_def ( 1 ) _ s''_def ( 2 )] (*‹P s xs s'' ⟹ P s (xs @ [x]) s'›*) snoc(1)[OF s''_def ( 1 ) snoc ( 3 , 4 )] (*‹⟦⋀s s' v vs s''. ⟦reaches_on run s vs s'; P s vs s'; run s' = Some (s'', v)⟧ ⟹ reaches_on run s vs (?s'1 s s' v vs s''); ⋀s s' v vs s''. ⟦reaches_on run s vs s'; P s vs s'; run s' = Some (s'', v)⟧ ⟹ P s vs (?s'1 s s' v vs s''); ⋀s s' v vs s''. ⟦reaches_on run s vs s'; P s vs s'; run s' = Some (s'', v)⟧ ⟹ run (?s'1 s s' v vs s'') = Some (s'', v)⟧ ⟹ P s xs s''›*) by auto qed (auto elim: reaches_on.cases (*‹⟦reaches_on ?run ?a1.0 ?a2.0 ?a3.0; ⋀s. ⟦?a1.0 = s; ?a2.0 = []; ?a3.0 = s⟧ ⟹ ?P; ⋀s s' v vs s''. ⟦?a1.0 = s; ?a2.0 = v # vs; ?a3.0 = s''; ?run s = Some (s', v); reaches_on ?run s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*solved the remaining goal: ‹⋀s s'. ⟦reaches_on run s [] s'; ⋀s. P s [] s; ⋀s s' v vs s''. ⟦reaches_on run s vs s'; P s vs s'; run s' = Some (s'', v)⟧ ⟹ P s (vs @ [v]) s''⟧ ⟹ P s [] s'›*) lemma reaches_on_app: "reaches_on run s vs s' ⟹ run s' = Some (s'', v) ⟹ reaches_on run s (vs @ [v]) s''" apply (induction s vs s' rule: reaches_on.induct (*‹⟦reaches_on ?run ?x1.0 ?x2.0 ?x3.0; ⋀s. ?P s [] s; ⋀s s' v vs s''. ⟦?run s = Some (s', v); reaches_on ?run s' vs s''; ?P s' vs s''⟧ ⟹ ?P s (v # vs) s''⟧ ⟹ ?P ?x1.0 ?x2.0 ?x3.0›*)) (*goals: 1. ‹⋀s. run s = Some (s'', v) ⟹ reaches_on run s ([] @ [v]) s''› 2. ‹⋀s s' va vs s''a. ⟦run s = Some (s', va); reaches_on run s' vs s''a; run s''a = Some (s'', v) ⟹ reaches_on run s' (vs @ [v]) s''; run s''a = Some (s'', v)⟧ ⟹ reaches_on run s ((va # vs) @ [v]) s''› discuss goal 1*) apply ((auto intro: reaches_on.intros (*‹reaches_on ?run ?s [] ?s› ‹⟦?run ?s = Some (?s', ?v); reaches_on ?run ?s' ?vs ?s''⟧ ⟹ reaches_on ?run ?s (?v # ?vs) ?s''›*))[1]) (*discuss goal 2*) apply ((auto intro: reaches_on.intros (*‹reaches_on ?run ?s [] ?s› ‹⟦?run ?s = Some (?s', ?v); reaches_on ?run ?s' ?vs ?s''⟧ ⟹ reaches_on ?run ?s (?v # ?vs) ?s''›*))[1]) (*proven 2 subgoals*) . lemma reaches_on_trans: "reaches_on run s vs s' ⟹ reaches_on run s' vs' s'' ⟹ reaches_on run s (vs @ vs') s''" apply (induction s vs s' rule: reaches_on.induct (*‹⟦reaches_on ?run ?x1.0 ?x2.0 ?x3.0; ⋀s. ?P s [] s; ⋀s s' v vs s''. ⟦?run s = Some (s', v); reaches_on ?run s' vs s''; ?P s' vs s''⟧ ⟹ ?P s (v # vs) s''⟧ ⟹ ?P ?x1.0 ?x2.0 ?x3.0›*)) (*goals: 1. ‹⋀s. reaches_on run s vs' s'' ⟹ reaches_on run s ([] @ vs') s''› 2. ‹⋀s s' v vs s''a. ⟦run s = Some (s', v); reaches_on run s' vs s''a; reaches_on run s''a vs' s'' ⟹ reaches_on run s' (vs @ vs') s''; reaches_on run s''a vs' s''⟧ ⟹ reaches_on run s ((v # vs) @ vs') s''› discuss goal 1*) apply ((auto intro: reaches_on.intros (*‹reaches_on ?run ?s [] ?s› ‹⟦?run ?s = Some (?s', ?v); reaches_on ?run ?s' ?vs ?s''⟧ ⟹ reaches_on ?run ?s (?v # ?vs) ?s''›*))[1]) (*discuss goal 2*) apply ((auto intro: reaches_on.intros (*‹reaches_on ?run ?s [] ?s› ‹⟦?run ?s = Some (?s', ?v); reaches_on ?run ?s' ?vs ?s''⟧ ⟹ reaches_on ?run ?s (?v # ?vs) ?s''›*))[1]) (*proven 2 subgoals*) . lemma reaches_onD: "reaches_on run s ((t, b) # vs) s' ⟹ ∃s''. run s = Some (s'', (t, b)) ∧ reaches_on run s'' vs s'" by (auto elim: reaches_on.cases (*‹⟦reaches_on ?run ?a1.0 ?a2.0 ?a3.0; ⋀s. ⟦?a1.0 = s; ?a2.0 = []; ?a3.0 = s⟧ ⟹ ?P; ⋀s s' v vs s''. ⟦?a1.0 = s; ?a2.0 = v # vs; ?a3.0 = s''; ?run s = Some (s', v); reaches_on ?run s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*)) lemma reaches_on_setD: "reaches_on run s vs s' ⟹ x ∈ set vs ⟹ ∃vs' vs'' s''. reaches_on run s (vs' @ [x]) s'' ∧ reaches_on run s'' vs'' s' ∧ vs = vs' @ x # vs''" proof (induction s vs s' rule: reaches_on_rev_induct (*‹⟦reaches_on ?run ?s ?vs ?s'; ⋀s. ?P s [] s; ⋀s s' v vs s''. ⟦reaches_on ?run s vs s'; ?P s vs s'; ?run s' = Some (s'', v)⟧ ⟹ ?P s (vs @ [v]) s''⟧ ⟹ ?P ?s ?vs ?s'›*)) (*goals: 1. ‹⋀s. x ∈ set [] ⟹ ∃vs' vs'' s''. reaches_on run s (vs' @ [x]) s'' ∧ reaches_on run s'' vs'' s ∧ [] = vs' @ x # vs''› 2. ‹⋀s s' v vs s''. ⟦reaches_on run s vs s'; x ∈ set vs ⟹ ∃vs' vs'' s''. reaches_on run s (vs' @ [x]) s'' ∧ reaches_on run s'' vs'' s' ∧ vs = vs' @ x # vs''; run s' = Some (s'', v); x ∈ set (vs @ [v])⟧ ⟹ ∃vs' vs'' s''a. reaches_on run s (vs' @ [x]) s''a ∧ reaches_on run s''a vs'' s'' ∧ vs @ [v] = vs' @ x # vs''›*) case (2 s s' v vs s'') (*‹reaches_on run s vs s'› ‹run s' = Some (s'', v)› ‹(x::'b::type) ∈ set (vs::'b::type list) ⟹ ∃(vs'::'b::type list) (vs''::'b::type list) s''::'a::type. reaches_on (run::'a::type ⇒ ('a::type × 'b::type) option) (s::'a::type) (vs' @ [x]) s'' ∧ reaches_on run s'' vs'' (s'::'a::type) ∧ vs = vs' @ x # vs''› ‹x ∈ set (vs @ [v])›*) show "?case" (*goal: ‹∃vs' vs'' s''a. reaches_on run s (vs' @ [x]) s''a ∧ reaches_on run s''a vs'' s'' ∧ vs @ [v] = vs' @ x # vs''›*) proof (cases "x ∈ set vs") (*goals: 1. ‹(x::'b) ∈ set (vs::'b list) ⟹ ∃(vs'::'b list) (vs''::'b list) s''a::'a. reaches_on (run::'a ⇒ ('a × 'b) option) (s::'a) (vs' @ [x]) s''a ∧ reaches_on run s''a vs'' (s''::'a) ∧ vs @ [v::'b] = vs' @ x # vs''› 2. ‹(x::'b) ∉ set (vs::'b list) ⟹ ∃(vs'::'b list) (vs''::'b list) s''a::'a. reaches_on (run::'a ⇒ ('a × 'b) option) (s::'a) (vs' @ [x]) s''a ∧ reaches_on run s''a vs'' (s''::'a) ∧ vs @ [v::'b] = vs' @ x # vs''›*) case True (*‹x ∈ set vs›*) obtain vs' and vs'' and s''' where split_def: "reaches_on run s (vs' @ [x]) s'''" "reaches_on run s''' vs'' s'" "vs = vs' @ x # vs''" (*goal: ‹(⋀vs' s''' vs''. ⟦reaches_on run s (vs' @ [x]) s'''; reaches_on run s''' vs'' s'; vs = vs' @ x # vs''⟧ ⟹ thesis) ⟹ thesis›*) using "2"(3)[OF True] (*‹∃vs' vs'' s''. reaches_on run s (vs' @ [x]) s'' ∧ reaches_on run s'' vs'' s' ∧ vs = vs' @ x # vs''›*) by auto show "?thesis" (*goal: ‹∃vs' vs'' s''a. reaches_on run s (vs' @ [x]) s''a ∧ reaches_on run s''a vs'' s'' ∧ vs @ [v] = vs' @ x # vs''›*) using split_def(1,3) (*‹reaches_on run s (vs' @ [x]) s'''› ‹vs = vs' @ x # vs''›*) reaches_on_app[OF split_def ( 2 ) 2 ( 2 )] (*‹reaches_on run s''' (vs'' @ [v]) s''›*) by auto next (*goal: ‹(x::'b) ∉ set (vs::'b list) ⟹ ∃(vs'::'b list) (vs''::'b list) s''a::'a. reaches_on (run::'a ⇒ ('a × 'b) option) (s::'a) (vs' @ [x]) s''a ∧ reaches_on run s''a vs'' (s''::'a) ∧ vs @ [v::'b] = vs' @ x # vs''›*) case False (*‹(x::'b) ∉ set (vs::'b list)›*) have x_v: "x = v" using "2"(4) (*‹x ∈ set (vs @ [v])›*) False (*‹x ∉ set vs›*) by auto show "?thesis" (*goal: ‹∃vs' vs'' s''a. reaches_on run s (vs' @ [x]) s''a ∧ reaches_on run s''a vs'' s'' ∧ vs @ [v] = vs' @ x # vs''›*) unfolding x_v (*goal: ‹∃vs' vs'' s''a. reaches_on run s (vs' @ [v]) s''a ∧ reaches_on run s''a vs'' s'' ∧ vs @ [v] = vs' @ v # vs''›*) using reaches_on_app[OF 2 ( 1 , 2 )] (*‹reaches_on run s (vs @ [v]) s''›*) reaches_on.intros(1)[of run s''] (*‹reaches_on (run::'a ⇒ ('a × 'b) option) (s''::'a) [] s''›*) by auto qed qed (auto) (*solved the remaining goal: ‹⋀s. x ∈ set [] ⟹ ∃vs' vs'' s''. reaches_on run s (vs' @ [x]) s'' ∧ reaches_on run s'' vs'' s ∧ [] = vs' @ x # vs''›*) lemma reaches_on_len: "∃vs s'. reaches_on run s vs s' ∧ (length vs = n ∨ run s' = None)" proof (induction n arbitrary: s) (*goals: 1. ‹⋀s. ∃vs s'. reaches_on run s vs s' ∧ (length vs = 0 ∨ run s' = None)› 2. ‹⋀n s. (⋀s. ∃vs s'. reaches_on run s vs s' ∧ (length vs = n ∨ run s' = None)) ⟹ ∃vs s'. reaches_on run s vs s' ∧ (length vs = Suc n ∨ run s' = None)›*) case (Suc n) (*‹∃vs s'. reaches_on run ?s vs s' ∧ (length vs = n ∨ run s' = None)›*) show "?case" (*goal: ‹∃vs s'. reaches_on run s vs s' ∧ (length vs = Suc n ∨ run s' = None)›*) proof (cases "run s") (*goals: 1. ‹(run::'b ⇒ ('b × 'a) option) (s::'b) = None ⟹ ∃(vs::'a list) s'::'b. reaches_on run s vs s' ∧ (length vs = Suc (n::nat) ∨ run s' = None)› 2. ‹⋀a::'b × 'a. (run::'b ⇒ ('b × 'a) option) (s::'b) = Some a ⟹ ∃(vs::'a list) s'::'b. reaches_on run s vs s' ∧ (length vs = Suc (n::nat) ∨ run s' = None)›*) case (Some x) (*‹run s = Some x›*) obtain s' and v where x_def: "x = (s', v)" (*goal: ‹(⋀s' v. x = (s', v) ⟹ thesis) ⟹ thesis›*) apply (cases x) (*goal: ‹(⋀s' v. x = (s', v) ⟹ thesis) ⟹ thesis›*) by auto obtain vs and s'' where s''_def: "reaches_on run s' vs s''" "length vs = n ∨ run s'' = None" (*goal: ‹(⋀vs s''. ⟦reaches_on run s' vs s''; length vs = n ∨ run s'' = None⟧ ⟹ thesis) ⟹ thesis›*) using Suc[of s'] (*‹∃vs s'a. reaches_on run s' vs s'a ∧ (length vs = n ∨ run s'a = None)›*) by auto show "?thesis" (*goal: ‹∃vs s'. reaches_on run s vs s' ∧ (length vs = Suc n ∨ run s' = None)›*) using reaches_on.intros(2)[OF Some [ unfolded x_def ] s''_def ( 1 )] (*‹reaches_on run s (v # vs) s''›*) s''_def(2) (*‹length vs = n ∨ run s'' = None›*) by fastforce qed (auto intro: reaches_on.intros (*‹reaches_on ?run ?s [] ?s› ‹⟦?run ?s = Some (?s', ?v); reaches_on ?run ?s' ?vs ?s''⟧ ⟹ reaches_on ?run ?s (?v # ?vs) ?s''›*)) (*solved the remaining goal: ‹run s = None ⟹ ∃vs s'. reaches_on run s vs s' ∧ (length vs = Suc n ∨ run s' = None)›*) qed (auto intro: reaches_on.intros (*‹reaches_on ?run ?s [] ?s› ‹⟦?run ?s = Some (?s', ?v); reaches_on ?run ?s' ?vs ?s''⟧ ⟹ reaches_on ?run ?s (?v # ?vs) ?s''›*)) (*solved the remaining goal: ‹⋀s. ∃vs s'. reaches_on run s vs s' ∧ (length vs = 0 ∨ run s' = None)›*) lemma reaches_on_NilD: "reaches_on run q [] q' ⟹ q = q'" by (auto elim: reaches_on.cases (*‹⟦reaches_on ?run ?a1.0 ?a2.0 ?a3.0; ⋀s. ⟦?a1.0 = s; ?a2.0 = []; ?a3.0 = s⟧ ⟹ ?P; ⋀s s' v vs s''. ⟦?a1.0 = s; ?a2.0 = v # vs; ?a3.0 = s''; ?run s = Some (s', v); reaches_on ?run s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*)) lemma reaches_on_ConsD: "reaches_on run q (x # xs) q' ⟹ ∃q''. run q = Some (q'', x) ∧ reaches_on run q'' xs q'" by (auto elim: reaches_on.cases (*‹⟦reaches_on ?run ?a1.0 ?a2.0 ?a3.0; ⋀s. ⟦?a1.0 = s; ?a2.0 = []; ?a3.0 = s⟧ ⟹ ?P; ⋀s s' v vs s''. ⟦?a1.0 = s; ?a2.0 = v # vs; ?a3.0 = s''; ?run s = Some (s', v); reaches_on ?run s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*)) inductive reaches :: "('e ⇒ ('e × 'f) option) ⇒ 'e ⇒ nat ⇒ 'e ⇒ bool" for run :: "'e ⇒ ('e × 'f) option" where "reaches run s 0 s" | "run s = Some (s', v) ⟹ reaches run s' n s'' ⟹ reaches run s (Suc n) s''" lemma reaches_Suc_split_last: "reaches run s (Suc n) s' ⟹ ∃s'' x. reaches run s n s'' ∧ run s'' = Some (s', x)" proof (induction n arbitrary: s) (*goals: 1. ‹⋀s. reaches run s (Suc 0) s' ⟹ ∃s'' x. reaches run s 0 s'' ∧ run s'' = Some (s', x)› 2. ‹⋀n s. ⟦⋀s. reaches run s (Suc n) s' ⟹ ∃s'' x. reaches run s n s'' ∧ run s'' = Some (s', x); reaches run s (Suc (Suc n)) s'⟧ ⟹ ∃s'' x. reaches run s (Suc n) s'' ∧ run s'' = Some (s', x)›*) case (Suc n) (*‹reaches run ?s (Suc n) s' ⟹ ∃s'' x. reaches run ?s n s'' ∧ run s'' = Some (s', x)› ‹reaches run s (Suc (Suc n)) s'›*) obtain s'' and x where s''_def: "run s = Some (s'', x)" "reaches run s'' (Suc n) s'" (*goal: ‹(⋀s'' x. ⟦run s = Some (s'', x); reaches run s'' (Suc n) s'⟧ ⟹ thesis) ⟹ thesis›*) using Suc(2) (*‹reaches run s (Suc (Suc n)) s'›*) by (auto elim: reaches.cases (*‹⟦reaches ?run ?a1.0 ?a2.0 ?a3.0; ⋀s. ⟦?a1.0 = s; ?a2.0 = 0; ?a3.0 = s⟧ ⟹ ?P; ⋀s s' v n s''. ⟦?a1.0 = s; ?a2.0 = Suc n; ?a3.0 = s''; ?run s = Some (s', v); reaches ?run s' n s''⟧ ⟹ ?P⟧ ⟹ ?P›*)) show "?case" (*goal: ‹∃s'' x. reaches run s (Suc n) s'' ∧ run s'' = Some (s', x)›*) using s''_def(1) (*‹(run::'a::type ⇒ ('a::type × 'b::type) option) (s::'a::type) = Some (s''::'a::type, x::'b::type)›*) Suc(1)[OF s''_def ( 2 )] (*‹∃s''a x. reaches run s'' n s''a ∧ run s''a = Some (s', x)›*) by (auto intro: reaches.intros (*‹reaches ?run ?s 0 ?s› ‹⟦?run ?s = Some (?s', ?v); reaches ?run ?s' ?n ?s''⟧ ⟹ reaches ?run ?s (Suc ?n) ?s''›*)) qed (auto elim!: reaches.cases (*‹⟦reaches (?run::?'e ⇒ (?'e × ?'f) option) (?a1.0::?'e) (?a2.0::nat) (?a3.0::?'e); ⋀s::?'e. ⟦?a1.0 = s; ?a2.0 = (0::nat); ?a3.0 = s⟧ ⟹ ?P::bool; ⋀(s::?'e) (s'::?'e) (v::?'f) (n::nat) s''::?'e. ⟦?a1.0 = s; ?a2.0 = Suc n; ?a3.0 = s''; ?run s = Some (s', v); reaches ?run s' n s''⟧ ⟹ ?P⟧ ⟹ ?P›*) intro: reaches.intros (*‹reaches (?run::?'e ⇒ (?'e × ?'f) option) (?s::?'e) (0::nat) ?s› ‹⟦(?run::?'e ⇒ (?'e × ?'f) option) (?s::?'e) = Some (?s'::?'e, ?v::?'f); reaches ?run ?s' (?n::nat) (?s''::?'e)⟧ ⟹ reaches ?run ?s (Suc ?n) ?s''›*)) (*solved the remaining goal: ‹⋀s. reaches run s (Suc 0) s' ⟹ ∃s'' x. reaches run s 0 s'' ∧ run s'' = Some (s', x)›*) lemma reaches_invar: "reaches f x n y ⟹ P x ⟹ (⋀z z' v. P z ⟹ f z = Some (z', v) ⟹ P z') ⟹ P y" apply (induction x n y rule: reaches.induct (*‹⟦reaches ?run ?x1.0 ?x2.0 ?x3.0; ⋀s. ?P s 0 s; ⋀s s' v n s''. ⟦?run s = Some (s', v); reaches ?run s' n s''; ?P s' n s''⟧ ⟹ ?P s (Suc n) s''⟧ ⟹ ?P ?x1.0 ?x2.0 ?x3.0›*)) (*goals: 1. ‹⋀s::'a. ⟦(P::'a ⇒ bool) s; ⋀(z::'a) (z'::'a) v::'b. ⟦P z; (f::'a ⇒ ('a × 'b) option) z = Some (z', v)⟧ ⟹ P z'⟧ ⟹ P s› 2. ‹⋀(s::'a) (s'::'a) (v::'b) (n::nat) s''::'a. ⟦(f::'a ⇒ ('a × 'b) option) s = Some (s', v); reaches f s' n s''; ⟦(P::'a ⇒ bool) s'; ⋀(z::'a) (z'::'a) v::'b. ⟦P z; f z = Some (z', v)⟧ ⟹ P z'⟧ ⟹ P s''; P s; ⋀(z::'a) (z'::'a) v::'b. ⟦P z; f z = Some (z', v)⟧ ⟹ P z'⟧ ⟹ P s''› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma reaches_cong: "reaches f x n y ⟹ P x ⟹ (⋀z z' v. P z ⟹ f z = Some (z', v) ⟹ P z') ⟹ (⋀z. P z ⟹ f' (g z) = map_option (apfst g) (f z)) ⟹ reaches f' (g x) n (g y)" apply (induction x n y rule: reaches.induct (*‹⟦reaches (?run::?'e ⇒ (?'e × ?'f) option) (?x1.0::?'e) (?x2.0::nat) (?x3.0::?'e); ⋀s::?'e. (?P::?'e ⇒ nat ⇒ ?'e ⇒ bool) s (0::nat) s; ⋀(s::?'e) (s'::?'e) (v::?'f) (n::nat) s''::?'e. ⟦?run s = Some (s', v); reaches ?run s' n s''; ?P s' n s''⟧ ⟹ ?P s (Suc n) s''⟧ ⟹ ?P ?x1.0 ?x2.0 ?x3.0›*)) (*goals: 1. ‹⋀s. ⟦P s; ⋀z z' v. ⟦P z; f z = Some (z', v)⟧ ⟹ P z'; ⋀z. P z ⟹ f' (g z) = map_option (apfst g) (f z)⟧ ⟹ reaches f' (g s) 0 (g s)› 2. ‹⋀s s' v n s''. ⟦f s = Some (s', v); reaches f s' n s''; ⟦P s'; ⋀z z' v. ⟦P z; f z = Some (z', v)⟧ ⟹ P z'; ⋀z. P z ⟹ f' (g z) = map_option (apfst g) (f z)⟧ ⟹ reaches f' (g s') n (g s''); P s; ⋀z z' v. ⟦P z; f z = Some (z', v)⟧ ⟹ P z'; ⋀z. P z ⟹ f' (g z) = map_option (apfst g) (f z)⟧ ⟹ reaches f' (g s) (Suc n) (g s'')› discuss goal 1*) apply ((auto intro: reaches.intros (*‹reaches ?run ?s 0 ?s› ‹⟦?run ?s = Some (?s', ?v); reaches ?run ?s' ?n ?s''⟧ ⟹ reaches ?run ?s (Suc ?n) ?s''›*))[1]) (*discuss goal 2*) apply ((auto intro: reaches.intros (*‹reaches ?run ?s 0 ?s› ‹⟦?run ?s = Some (?s', ?v); reaches ?run ?s' ?n ?s''⟧ ⟹ reaches ?run ?s (Suc ?n) ?s''›*))[1]) (*proven 2 subgoals*) . lemma reaches_on_n: "reaches_on run s vs s' ⟹ reaches run s (length vs) s'" apply (induction s vs s' rule: reaches_on.induct (*‹⟦reaches_on ?run ?x1.0 ?x2.0 ?x3.0; ⋀s. ?P s [] s; ⋀s s' v vs s''. ⟦?run s = Some (s', v); reaches_on ?run s' vs s''; ?P s' vs s''⟧ ⟹ ?P s (v # vs) s''⟧ ⟹ ?P ?x1.0 ?x2.0 ?x3.0›*)) (*goals: 1. ‹⋀s. reaches run s (length []) s› 2. ‹⋀s s' v vs s''. ⟦run s = Some (s', v); reaches_on run s' vs s''; reaches run s' (length vs) s''⟧ ⟹ reaches run s (length (v # vs)) s''› discuss goal 1*) apply ((auto intro: reaches.intros (*‹reaches (?run::?'e::type ⇒ (?'e::type × ?'f::type) option) (?s::?'e::type) (0::nat) ?s› ‹⟦(?run::?'e::type ⇒ (?'e::type × ?'f::type) option) (?s::?'e::type) = Some (?s'::?'e::type, ?v::?'f::type); reaches ?run ?s' (?n::nat) (?s''::?'e::type)⟧ ⟹ reaches ?run ?s (Suc ?n) ?s''›*))[1]) (*discuss goal 2*) apply ((auto intro: reaches.intros (*‹reaches ?run ?s 0 ?s› ‹⟦?run ?s = Some (?s', ?v); reaches ?run ?s' ?n ?s''⟧ ⟹ reaches ?run ?s (Suc ?n) ?s''›*))[1]) (*proven 2 subgoals*) . lemma reaches_on: "reaches run s n s' ⟹ ∃vs. reaches_on run s vs s' ∧ length vs = n" apply (induction s n s' rule: reaches.induct (*‹⟦reaches ?run ?x1.0 ?x2.0 ?x3.0; ⋀s. ?P s 0 s; ⋀s s' v n s''. ⟦?run s = Some (s', v); reaches ?run s' n s''; ?P s' n s''⟧ ⟹ ?P s (Suc n) s''⟧ ⟹ ?P ?x1.0 ?x2.0 ?x3.0›*)) (*goals: 1. ‹⋀s. ∃vs. reaches_on run s vs s ∧ length vs = 0› 2. ‹⋀s s' v n s''. ⟦run s = Some (s', v); reaches run s' n s''; ∃vs. reaches_on run s' vs s'' ∧ length vs = n⟧ ⟹ ∃vs. reaches_on run s vs s'' ∧ length vs = Suc n› discuss goal 1*) apply ((auto intro: reaches_on.intros (*‹reaches_on ?run ?s [] ?s› ‹⟦?run ?s = Some (?s', ?v); reaches_on ?run ?s' ?vs ?s''⟧ ⟹ reaches_on ?run ?s (?v # ?vs) ?s''›*))[1]) (*discuss goal 2*) apply ((auto intro: reaches_on.intros (*‹reaches_on ?run ?s [] ?s› ‹⟦?run ?s = Some (?s', ?v); reaches_on ?run ?s' ?vs ?s''⟧ ⟹ reaches_on ?run ?s (?v # ?vs) ?s''›*))[1]) (*proven 2 subgoals*) . definition ts_at :: "('d × 'b) list ⇒ nat ⇒ 'd" where "ts_at rho i = fst (rho ! i)" definition bs_at :: "('d × 'b) list ⇒ nat ⇒ 'b" where "bs_at rho i = snd (rho ! i)" fun sub_bs :: "('d × 'b) list ⇒ nat × nat ⇒ 'b list" where "sub_bs rho (i, j) = map (bs_at rho) [i..<j]" definition steps :: "('c ⇒ 'b ⇒ 'c) ⇒ ('d × 'b) list ⇒ 'c ⇒ nat × nat ⇒ 'c" where "steps step rho q ij = foldl step q (sub_bs rho ij)" definition acc :: "('c ⇒ 'b ⇒ 'c) ⇒ ('c ⇒ bool) ⇒ ('d × 'b) list ⇒ 'c ⇒ nat × nat ⇒ bool" where "acc step accept rho q ij = accept (steps step rho q ij)" definition sup_acc :: "('c ⇒ 'b ⇒ 'c) ⇒ ('c ⇒ bool) ⇒ ('d × 'b) list ⇒ 'c ⇒ nat ⇒ nat ⇒ ('d × nat) option" where "sup_acc step accept rho q i j = (let L' = {l ∈ {i..<j}. acc step accept rho q (i, Suc l)}; m = Max L' in if L' = {} then None else Some (ts_at rho m, m))" definition sup_leadsto :: "'c ⇒ ('c ⇒ 'b ⇒ 'c) ⇒ ('d × 'b) list ⇒ nat ⇒ nat ⇒ 'c ⇒ 'd option" where "sup_leadsto init step rho i j q = (let L' = {l. l < i ∧ steps step rho init (l, j) = q}; m = Max L' in if L' = {} then None else Some (ts_at rho m))" definition mmap_keys :: "('a, 'b) mmap ⇒ 'a set" where "mmap_keys kvs = set (map fst kvs)" definition mmap_lookup :: "('a, 'b) mmap ⇒ 'a ⇒ 'b option" where "mmap_lookup = map_of" definition valid_s :: "'c ⇒ ('c ⇒ 'b ⇒ 'c) ⇒ ('c × 'b, 'c) mapping ⇒ ('c ⇒ bool) ⇒ ('d × 'b) list ⇒ nat ⇒ nat ⇒ nat ⇒ ('c, 'c × ('d × nat) option) mmap ⇒ bool" where "valid_s init step st accept rho u i j s ≡ (∀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v) ∧ (mmap_keys s = {q. (∃l ≤ u. steps step rho init (l, i) = q)} ∧ distinct (map fst s) ∧ (∀q. case mmap_lookup s q of None ⇒ True | Some (q', tstp) ⇒ steps step rho q (i, j) = q' ∧ tstp = sup_acc step accept rho q i j))" record ('b, 'c, 'd, 't, 'e) args = w_init :: 'c w_step :: "'c ⇒ 'b ⇒ 'c" w_accept :: "'c ⇒ bool" w_run_t :: "'t ⇒ ('t × 'd) option" w_read_t :: "'t ⇒ 'd option" w_run_sub :: "'e ⇒ ('e × 'b) option" record ('b, 'c, 'd, 't, 'e) window = w_st :: "('c × 'b, 'c) mapping" w_ac :: "('c, bool) mapping" w_i :: nat w_ti :: 't w_si :: 'e w_j :: nat w_tj :: 't w_sj :: 'e w_s :: "('c, 'c × ('d × nat) option) mmap" w_e :: "('c, 'd) mmap" copy_bnf (dead 'b, dead 'c, dead 'd, dead 't, 'e, dead 'ext) window_ext fun reach_window :: "('b, 'c, 'd, 't, 'e) args ⇒ 't ⇒ 'e ⇒ ('d × 'b) list ⇒ nat × 't × 'e × nat × 't × 'e ⇒ bool" where "reach_window args t0 sub rho (i, ti, si, j, tj, sj) ⟷ i ≤ j ∧ length rho = j ∧ reaches_on (w_run_t args) t0 (take i (map fst rho)) ti ∧ reaches_on (w_run_t args) ti (drop i (map fst rho)) tj ∧ reaches_on (w_run_sub args) sub (take i (map snd rho)) si ∧ reaches_on (w_run_sub args) si (drop i (map snd rho)) sj" lemma reach_windowI: "reaches_on (w_run_t args) t0 (take i (map fst rho)) ti ⟹ reaches_on (w_run_sub args) sub (take i (map snd rho)) si ⟹ reaches_on (w_run_t args) t0 (map fst rho) tj ⟹ reaches_on (w_run_sub args) sub (map snd rho) sj ⟹ i ≤ length rho ⟹ length rho = j ⟹ reach_window args t0 sub rho (i, ti, si, j, tj, sj)" apply auto (*goals: 1. ‹⟦reaches_on (w_run_t args) t0 (take i (map fst rho)) ti; reaches_on (w_run_sub args) sub (take i (map snd rho)) si; reaches_on (w_run_t args) t0 (map fst rho) tj; reaches_on (w_run_sub args) sub (map snd rho) sj; i ≤ length rho; j = length rho⟧ ⟹ reaches_on (w_run_t args) ti (drop i (map fst rho)) tj› 2. ‹⟦reaches_on (w_run_t args) t0 (take i (map fst rho)) ti; reaches_on (w_run_sub args) sub (take i (map snd rho)) si; reaches_on (w_run_t args) t0 (map fst rho) tj; reaches_on (w_run_sub args) sub (map snd rho) sj; i ≤ length rho; j = length rho⟧ ⟹ reaches_on (w_run_sub args) si (drop i (map snd rho)) sj› discuss goal 1*) apply (metis reaches_on_split'[of _ _ _ _ i] (*‹⟦reaches_on ?run ?s ?vs ?s'; i ≤ length ?vs⟧ ⟹ ∃s''. reaches_on ?run ?s (take i ?vs) s'' ∧ reaches_on ?run s'' (drop i ?vs) ?s'›*) length_map (*‹length (map ?f ?xs) = length ?xs›*) reaches_on_inj (*‹⟦reaches_on ?run ?s ?vs ?t; reaches_on ?run ?s ?vs' ?t'; length ?vs = length ?vs'⟧ ⟹ ?vs = ?vs' ∧ ?t = ?t'›*)) (*discuss goal 2*) apply (metis reaches_on_split'[of _ _ _ _ i] (*‹⟦reaches_on ?run ?s ?vs ?s'; i ≤ length ?vs⟧ ⟹ ∃s''. reaches_on ?run ?s (take i ?vs) s'' ∧ reaches_on ?run s'' (drop i ?vs) ?s'›*) length_map (*‹length (map ?f ?xs) = length ?xs›*) reaches_on_inj (*‹⟦reaches_on ?run ?s ?vs ?t; reaches_on ?run ?s ?vs' ?t'; length ?vs = length ?vs'⟧ ⟹ ?vs = ?vs' ∧ ?t = ?t'›*)) (*proven 2 subgoals*) . lemma reach_window_shift: assumes "reach_window args t0 sub rho (i, ti, si, j, tj, sj)" "i < j" "w_run_t args ti = Some (ti', t)" "w_run_sub args si = Some (si', s)" shows "reach_window args t0 sub rho (Suc i, ti', si', j, tj, sj)" using reaches_on_app[of "w_run_t args" t0 "take i (map fst rho)" ti ti' t] (*‹⟦reaches_on (w_run_t args) t0 (take i (map fst rho)) ti; w_run_t args ti = Some (ti', t)⟧ ⟹ reaches_on (w_run_t args) t0 (take i (map fst rho) @ [t]) ti'›*) reaches_on_app[of "w_run_sub args" sub "take i (map snd rho)" si si' s] (*‹⟦reaches_on (w_run_sub args) sub (take i (map snd rho)) si; w_run_sub args si = Some (si', s)⟧ ⟹ reaches_on (w_run_sub args) sub (take i (map snd rho) @ [s]) si'›*) assms (*‹reach_window args t0 sub rho (i, ti, si, j, tj, sj)› ‹i < j› ‹w_run_t args ti = Some (ti', t)› ‹w_run_sub args si = Some (si', s)›*) apply auto (*goals: 1. ‹⟦reaches_on (w_run_t args) t0 (take i (map fst rho) @ [t]) ti'; reaches_on (w_run_sub args) sub (take i (map snd rho) @ [s]) si'; i < length rho; w_run_t args ti = Some (ti', t); w_run_sub args si = Some (si', s); j = length rho; reaches_on (w_run_t args) t0 (take i (map fst rho)) ti; reaches_on (w_run_t args) ti (drop i (map fst rho)) tj; reaches_on (w_run_sub args) sub (take i (map snd rho)) si; reaches_on (w_run_sub args) si (drop i (map snd rho)) sj⟧ ⟹ reaches_on (w_run_t args) t0 (take (Suc i) (map fst rho)) ti'› 2. ‹⟦reaches_on (w_run_t args) t0 (take i (map fst rho) @ [t]) ti'; reaches_on (w_run_sub args) sub (take i (map snd rho) @ [s]) si'; i < length rho; w_run_t args ti = Some (ti', t); w_run_sub args si = Some (si', s); j = length rho; reaches_on (w_run_t args) t0 (take i (map fst rho)) ti; reaches_on (w_run_t args) ti (drop i (map fst rho)) tj; reaches_on (w_run_sub args) sub (take i (map snd rho)) si; reaches_on (w_run_sub args) si (drop i (map snd rho)) sj⟧ ⟹ reaches_on (w_run_t args) ti' (drop (Suc i) (map fst rho)) tj› 3. ‹⟦reaches_on (w_run_t args) t0 (take i (map fst rho) @ [t]) ti'; reaches_on (w_run_sub args) sub (take i (map snd rho) @ [s]) si'; i < length rho; w_run_t args ti = Some (ti', t); w_run_sub args si = Some (si', s); j = length rho; reaches_on (w_run_t args) t0 (take i (map fst rho)) ti; reaches_on (w_run_t args) ti (drop i (map fst rho)) tj; reaches_on (w_run_sub args) sub (take i (map snd rho)) si; reaches_on (w_run_sub args) si (drop i (map snd rho)) sj⟧ ⟹ reaches_on (w_run_sub args) sub (take (Suc i) (map snd rho)) si'› 4. ‹⟦reaches_on (w_run_t args) t0 (take i (map fst rho) @ [t]) ti'; reaches_on (w_run_sub args) sub (take i (map snd rho) @ [s]) si'; i < length rho; w_run_t args ti = Some (ti', t); w_run_sub args si = Some (si', s); j = length rho; reaches_on (w_run_t args) t0 (take i (map fst rho)) ti; reaches_on (w_run_t args) ti (drop i (map fst rho)) tj; reaches_on (w_run_sub args) sub (take i (map snd rho)) si; reaches_on (w_run_sub args) si (drop i (map snd rho)) sj⟧ ⟹ reaches_on (w_run_sub args) si' (drop (Suc i) (map snd rho)) sj› discuss goal 1*) apply (smt append_take_drop_id (*‹take ?n ?xs @ drop ?n ?xs = ?xs›*) id_take_nth_drop (*‹?i < length ?xs ⟹ ?xs = take ?i ?xs @ ?xs ! ?i # drop (Suc ?i) ?xs›*) length_map (*‹length (map ?f ?xs) = length ?xs›*) list.discI (*‹?list = ?x21.0 # ?x22.0 ⟹ ?list ≠ []›*) list.inject (*‹(?x21.0 # ?x22.0 = ?y21.0 # ?y22.0) = (?x21.0 = ?y21.0 ∧ ?x22.0 = ?y22.0)›*) option.inject (*‹(Some ?x2.0 = Some ?y2.0) = (?x2.0 = ?y2.0)›*) reaches_on.cases (*‹⟦reaches_on ?run ?a1.0 ?a2.0 ?a3.0; ⋀s. ⟦?a1.0 = s; ?a2.0 = []; ?a3.0 = s⟧ ⟹ ?P; ⋀s s' v vs s''. ⟦?a1.0 = s; ?a2.0 = v # vs; ?a3.0 = s''; ?run s = Some (s', v); reaches_on ?run s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*) same_append_eq (*‹(?xs @ ?ys = ?xs @ ?zs) = (?ys = ?zs)›*) snd_conv (*‹snd (?x1.0, ?x2.0) = ?x2.0›*) take_Suc_conv_app_nth (*‹?i < length ?xs ⟹ take (Suc ?i) ?xs = take ?i ?xs @ [?xs ! ?i]›*)) (*discuss goal 2*) apply (smt Cons_nth_drop_Suc (*‹?i < length ?xs ⟹ ?xs ! ?i # drop (Suc ?i) ?xs = drop ?i ?xs›*) fst_conv (*‹fst (?x1.0, ?x2.0) = ?x1.0›*) length_map (*‹length (map ?f ?xs) = length ?xs›*) list.discI (*‹?list = ?x21.0 # ?x22.0 ⟹ ?list ≠ []›*) list.inject (*‹(?x21.0 # ?x22.0 = ?y21.0 # ?y22.0) = (?x21.0 = ?y21.0 ∧ ?x22.0 = ?y22.0)›*) option.inject (*‹(Some ?x2.0 = Some ?y2.0) = (?x2.0 = ?y2.0)›*) reaches_on.cases (*‹⟦reaches_on ?run ?a1.0 ?a2.0 ?a3.0; ⋀s. ⟦?a1.0 = s; ?a2.0 = []; ?a3.0 = s⟧ ⟹ ?P; ⋀s s' v vs s''. ⟦?a1.0 = s; ?a2.0 = v # vs; ?a3.0 = s''; ?run s = Some (s', v); reaches_on ?run s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*discuss goal 3*) apply (smt append_take_drop_id (*‹take ?n ?xs @ drop ?n ?xs = ?xs›*) id_take_nth_drop (*‹?i < length ?xs ⟹ ?xs = take ?i ?xs @ ?xs ! ?i # drop (Suc ?i) ?xs›*) length_map (*‹length (map ?f ?xs) = length ?xs›*) list.discI (*‹?list = ?x21.0 # ?x22.0 ⟹ ?list ≠ []›*) list.inject (*‹(?x21.0 # ?x22.0 = ?y21.0 # ?y22.0) = (?x21.0 = ?y21.0 ∧ ?x22.0 = ?y22.0)›*) option.inject (*‹(Some ?x2.0 = Some ?y2.0) = (?x2.0 = ?y2.0)›*) reaches_on.cases (*‹⟦reaches_on ?run ?a1.0 ?a2.0 ?a3.0; ⋀s. ⟦?a1.0 = s; ?a2.0 = []; ?a3.0 = s⟧ ⟹ ?P; ⋀s s' v vs s''. ⟦?a1.0 = s; ?a2.0 = v # vs; ?a3.0 = s''; ?run s = Some (s', v); reaches_on ?run s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*) same_append_eq (*‹(?xs @ ?ys = ?xs @ ?zs) = (?ys = ?zs)›*) snd_conv (*‹snd (?x1.0, ?x2.0) = ?x2.0›*) take_Suc_conv_app_nth (*‹?i < length ?xs ⟹ take (Suc ?i) ?xs = take ?i ?xs @ [?xs ! ?i]›*)) (*discuss goal 4*) apply (smt Cons_nth_drop_Suc (*‹?i < length ?xs ⟹ ?xs ! ?i # drop (Suc ?i) ?xs = drop ?i ?xs›*) fst_conv (*‹fst (?x1.0, ?x2.0) = ?x1.0›*) length_map (*‹length (map ?f ?xs) = length ?xs›*) list.discI (*‹?list = ?x21.0 # ?x22.0 ⟹ ?list ≠ []›*) list.inject (*‹(?x21.0 # ?x22.0 = ?y21.0 # ?y22.0) = (?x21.0 = ?y21.0 ∧ ?x22.0 = ?y22.0)›*) option.inject (*‹(Some ?x2.0 = Some ?y2.0) = (?x2.0 = ?y2.0)›*) reaches_on.cases (*‹⟦reaches_on ?run ?a1.0 ?a2.0 ?a3.0; ⋀s. ⟦?a1.0 = s; ?a2.0 = []; ?a3.0 = s⟧ ⟹ ?P; ⋀s s' v vs s''. ⟦?a1.0 = s; ?a2.0 = v # vs; ?a3.0 = s''; ?run s = Some (s', v); reaches_on ?run s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*proven 4 subgoals*) . lemma reach_window_run_ti: "reach_window args t0 sub rho (i, ti, si, j, tj, sj) ⟹ i < j ⟹ ∃ti'. reaches_on (w_run_t args) t0 (take i (map fst rho)) ti ∧ w_run_t args ti = Some (ti', ts_at rho i) ∧ reaches_on (w_run_t args) ti' (drop (Suc i) (map fst rho)) tj" apply (auto simp: ts_at_def (*‹ts_at ?rho ?i = fst (?rho ! ?i)›*) elim!: reaches_on.cases[of "w_run_t args" ti "drop i (map fst rho)"] (*‹⟦reaches_on (w_run_t args) ti (drop i (map fst rho)) ?a3.0; ⋀s. ⟦ti = s; drop i (map fst rho) = []; ?a3.0 = s⟧ ⟹ ?P; ⋀s s' v vs s''. ⟦ti = s; drop i (map fst rho) = v # vs; ?a3.0 = s''; w_run_t args s = Some (s', v); reaches_on (w_run_t args) s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goal: ‹⟦reach_window (args::('a, 'b, 'c, 'd, 'e) Window.args) (t0::'d::type) (sub::'e::type) (rho::('c::type × 'a::type) list) (i::nat, ti::'d::type, si::'e::type, j::nat, tj::'d::type, sj::'e::type); i < j⟧ ⟹ ∃ti'::'d::type. reaches_on (w_run_t args) t0 (take i (map fst rho)) ti ∧ w_run_t args ti = Some (ti', ts_at rho i) ∧ reaches_on (w_run_t args) ti' (drop (Suc i) (map fst rho)) tj›*) using nth_via_drop (*‹drop ?n ?xs = ?y # ?ys ⟹ ?xs ! ?n = ?y›*) (*goals: 1. ‹⋀s' v vs. ⟦i < length rho; j = length rho; reaches_on (w_run_t args) t0 (take i (map fst rho)) ti; reaches_on (w_run_sub args) sub (take i (map snd rho)) si; reaches_on (w_run_sub args) si (drop i (map snd rho)) sj; drop i (map fst rho) = v # vs; w_run_t args ti = Some (s', v); reaches_on (w_run_t args) s' vs tj⟧ ⟹ v = fst (rho ! i)› 2. ‹⋀s' v vs. ⟦i < length rho; j = length rho; reaches_on (w_run_t args) t0 (take i (map fst rho)) ti; reaches_on (w_run_sub args) sub (take i (map snd rho)) si; reaches_on (w_run_sub args) si (drop i (map snd rho)) sj; drop i (map fst rho) = v # vs; w_run_t args ti = Some (s', v); reaches_on (w_run_t args) s' vs tj⟧ ⟹ reaches_on (w_run_t args) s' (drop (Suc i) (map fst rho)) tj› discuss goal 1*) apply fastforce (*discuss goal 2*) apply (metis Cons_nth_drop_Suc (*‹?i < length ?xs ⟹ ?xs ! ?i # drop (Suc ?i) ?xs = drop ?i ?xs›*) length_map (*‹length (map ?f ?xs) = length ?xs›*) list.inject (*‹(?x21.0 # ?x22.0 = ?y21.0 # ?y22.0) = (?x21.0 = ?y21.0 ∧ ?x22.0 = ?y22.0)›*)) (*proven 2 subgoals*) . lemma reach_window_run_si: "reach_window args t0 sub rho (i, ti, si, j, tj, sj) ⟹ i < j ⟹ ∃si'. reaches_on (w_run_sub args) sub (take i (map snd rho)) si ∧ w_run_sub args si = Some (si', bs_at rho i) ∧ reaches_on (w_run_sub args) si' (drop (Suc i) (map snd rho)) sj" apply (auto simp: bs_at_def (*‹bs_at ?rho ?i = snd (?rho ! ?i)›*) elim!: reaches_on.cases[of "w_run_sub args" si "drop i (map snd rho)"] (*‹⟦reaches_on (w_run_sub args) si (drop i (map snd rho)) ?a3.0; ⋀s. ⟦si = s; drop i (map snd rho) = []; ?a3.0 = s⟧ ⟹ ?P; ⋀s s' v vs s''. ⟦si = s; drop i (map snd rho) = v # vs; ?a3.0 = s''; w_run_sub args s = Some (s', v); reaches_on (w_run_sub args) s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goal: ‹⟦reach_window args t0 sub rho (i, ti, si, j, tj, sj); i < j⟧ ⟹ ∃si'. reaches_on (w_run_sub args) sub (take i (map snd rho)) si ∧ w_run_sub args si = Some (si', bs_at rho i) ∧ reaches_on (w_run_sub args) si' (drop (Suc i) (map snd rho)) sj›*) using nth_via_drop (*‹drop ?n ?xs = ?y # ?ys ⟹ ?xs ! ?n = ?y›*) (*goals: 1. ‹⋀s' v vs. ⟦i < length rho; j = length rho; reaches_on (w_run_t args) t0 (take i (map fst rho)) ti; reaches_on (w_run_t args) ti (drop i (map fst rho)) tj; reaches_on (w_run_sub args) sub (take i (map snd rho)) si; drop i (map snd rho) = v # vs; w_run_sub args si = Some (s', v); reaches_on (w_run_sub args) s' vs sj⟧ ⟹ v = snd (rho ! i)› 2. ‹⋀s' v vs. ⟦i < length rho; j = length rho; reaches_on (w_run_t args) t0 (take i (map fst rho)) ti; reaches_on (w_run_t args) ti (drop i (map fst rho)) tj; reaches_on (w_run_sub args) sub (take i (map snd rho)) si; drop i (map snd rho) = v # vs; w_run_sub args si = Some (s', v); reaches_on (w_run_sub args) s' vs sj⟧ ⟹ reaches_on (w_run_sub args) s' (drop (Suc i) (map snd rho)) sj› discuss goal 1*) apply fastforce (*discuss goal 2*) apply (metis Cons_nth_drop_Suc (*‹(?i::nat) < length (?xs::?'a list) ⟹ ?xs ! ?i # drop (Suc ?i) ?xs = drop ?i ?xs›*) length_map (*‹length (map (?f::?'b ⇒ ?'a) (?xs::?'b list)) = length ?xs›*) list.inject (*‹((?x21.0::?'a) # (?x22.0::?'a list) = (?y21.0::?'a) # (?y22.0::?'a list)) = (?x21.0 = ?y21.0 ∧ ?x22.0 = ?y22.0)›*)) (*proven 2 subgoals*) . lemma reach_window_run_tj: "reach_window args t0 sub rho (i, ti, si, j, tj, sj) ⟹ reaches_on (w_run_t args) t0 (map fst rho) tj" using reaches_on_trans (*‹⟦reaches_on ?run ?s ?vs ?s'; reaches_on ?run ?s' ?vs' ?s''⟧ ⟹ reaches_on ?run ?s (?vs @ ?vs') ?s''›*) by fastforce lemma reach_window_run_sj: "reach_window args t0 sub rho (i, ti, si, j, tj, sj) ⟹ reaches_on (w_run_sub args) sub (map snd rho) sj" using reaches_on_trans (*‹⟦reaches_on (?run::?'a::type ⇒ (?'a::type × ?'b::type) option) (?s::?'a::type) (?vs::?'b::type list) (?s'::?'a::type); reaches_on ?run ?s' (?vs'::?'b::type list) (?s''::?'a::type)⟧ ⟹ reaches_on ?run ?s (?vs @ ?vs') ?s''›*) by fastforce lemma reach_window_shift_all: "reach_window args t0 sub rho (i, si, ti, j, sj, tj) ⟹ reach_window args t0 sub rho (j, sj, tj, j, sj, tj)" using reach_window_run_tj[of args t0 sub rho] (*‹reach_window (args::('a, 'b, 'c, 'd, 'e) Window.args) (t0::'d) (sub::'e) (rho::('c × 'a) list) (?i::nat, ?ti::'d, ?si::'e, ?j::nat, ?tj::'d, ?sj::'e) ⟹ reaches_on (w_run_t args) t0 (map fst rho) ?tj›*) reach_window_run_sj[of args t0 sub rho] (*‹reach_window (args::('a, 'b, 'c, 'd, 'e) Window.args) (t0::'d) (sub::'e) (rho::('c × 'a) list) (?i::nat, ?ti::'d, ?si::'e, ?j::nat, ?tj::'d, ?sj::'e) ⟹ reaches_on (w_run_sub args) sub (map snd rho) ?sj›*) by (auto intro: reaches_on.intros (*‹reaches_on ?run ?s [] ?s› ‹⟦?run ?s = Some (?s', ?v); reaches_on ?run ?s' ?vs ?s''⟧ ⟹ reaches_on ?run ?s (?v # ?vs) ?s''›*)) lemma reach_window_app: "reach_window args t0 sub rho (i, si, ti, j, tj, sj) ⟹ w_run_t args tj = Some (tj', x) ⟹ w_run_sub args sj = Some (sj', y) ⟹ reach_window args t0 sub (rho @ [(x, y)]) (i, si, ti, Suc j, tj', sj')" by (fastforce simp add: reaches_on_app (*‹⟦reaches_on ?run ?s ?vs ?s'; ?run ?s' = Some (?s'', ?v)⟧ ⟹ reaches_on ?run ?s (?vs @ [?v]) ?s''›*)) fun init_args :: "('c × ('c ⇒ 'b ⇒ 'c) × ('c ⇒ bool)) ⇒ (('t ⇒ ('t × 'd) option) × ('t ⇒ 'd option)) ⇒ ('e ⇒ ('e × 'b) option) ⇒ ('b, 'c, 'd, 't, 'e) args" where "init_args (init, step, accept) (run_t, read_t) run_sub = ⦇w_init = init, w_step = step, w_accept = accept, w_run_t = run_t, w_read_t = read_t, w_run_sub = run_sub⦈" fun init_window :: "('b, 'c, 'd, 't, 'e) args ⇒ 't ⇒ 'e ⇒ ('b, 'c, 'd, 't, 'e) window" where "init_window args t0 sub = ⦇w_st = Mapping.empty, w_ac = Mapping.empty, w_i = 0, w_ti = t0, w_si = sub, w_j = 0, w_tj = t0, w_sj = sub, w_s =[(w_init args, (w_init args, None))], w_e = []⦈" definition valid_window :: "('b, 'c, 'd :: timestamp, 't, 'e) args ⇒ 't ⇒ 'e ⇒ ('d × 'b) list ⇒ ('b, 'c, 'd, 't, 'e) window ⇒ bool" where "valid_window args t0 sub rho w ⟷ (let init = w_init args; step = w_step args; accept = w_accept args; run_t = w_run_t args; run_sub = w_run_sub args; st = w_st w; ac = w_ac w; i = w_i w; ti = w_ti w; si = w_si w; j = w_j w; tj = w_tj w; sj = w_sj w; s = w_s w; e = w_e w in (reach_window args t0 sub rho (i, ti, si, j, tj, sj) ∧ (∀i j. i ≤ j ∧ j < length rho ⟶ ts_at rho i ≤ ts_at rho j) ∧ (∀q. case Mapping.lookup ac q of None ⇒ True | Some v ⇒ accept q = v) ∧ (∀q. mmap_lookup e q = sup_leadsto init step rho i j q) ∧ distinct (map fst e) ∧ valid_s init step st accept rho i i j s))" lemma valid_init_window: "valid_window args t0 sub [] (init_window args t0 sub)" by (auto simp: valid_window_def (*‹valid_window ?args ?t0.0 ?sub ?rho ?w = (let init = w_init ?args; step = w_step ?args; accept = w_accept ?args; run_t = w_run_t ?args; run_sub = w_run_sub ?args; st = w_st ?w; ac = w_ac ?w; i = w_i ?w; ti = w_ti ?w; si = w_si ?w; j = w_j ?w; tj = w_tj ?w; sj = w_sj ?w; s = w_s ?w; e = w_e ?w in reach_window ?args ?t0.0 ?sub ?rho (i, ti, si, j, tj, sj) ∧ (∀i j. i ≤ j ∧ j < length ?rho ⟶ ts_at ?rho i ≤ ts_at ?rho j) ∧ (∀q. case Mapping.lookup ac q of None ⇒ True | Some v ⇒ accept q = v) ∧ (∀q. mmap_lookup e q = sup_leadsto init step ?rho i j q) ∧ distinct (map fst e) ∧ valid_s init step st accept ?rho i i j s)›*) mmap_keys_def (*‹mmap_keys ?kvs = set (map fst ?kvs)›*) mmap_lookup_def (*‹mmap_lookup = map_of›*) sup_leadsto_def (*‹sup_leadsto ?init ?step ?rho ?i ?j ?q = (let L' = {l. l < ?i ∧ steps ?step ?rho ?init (l, ?j) = ?q}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m))›*) valid_s_def (*‹valid_s ?init ?step ?st ?accept ?rho ?u ?i ?j ?s ≡ (∀q bs. case Mapping.lookup ?st (q, bs) of None ⇒ True | Some v ⇒ ?step q bs = v) ∧ mmap_keys ?s = {q. ∃l≤?u. steps ?step ?rho ?init (l, ?i) = q} ∧ distinct (map fst ?s) ∧ (∀q. case mmap_lookup ?s q of None ⇒ True | Some (q', tstp) ⇒ steps ?step ?rho q (?i, ?j) = q' ∧ tstp = sup_acc ?step ?accept ?rho q ?i ?j)›*) steps_def (*‹steps ?step ?rho ?q ?ij = foldl ?step ?q (sub_bs ?rho ?ij)›*) sup_acc_def (*‹sup_acc ?step ?accept ?rho ?q ?i ?j = (let L' = {l ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*) intro: reaches_on.intros (*‹reaches_on ?run ?s [] ?s› ‹⟦?run ?s = Some (?s', ?v); reaches_on ?run ?s' ?vs ?s''⟧ ⟹ reaches_on ?run ?s (?v # ?vs) ?s''›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) lemma steps_app_cong: "j ≤ length rho ⟹ steps step (rho @ [x]) q (i, j) = steps step rho q (i, j)" proof (-) (*goal: ‹j ≤ length rho ⟹ steps step (rho @ [x]) q (i, j) = steps step rho q (i, j)›*) assume "j ≤ length rho" (*‹(j::nat) ≤ length (rho::('a × 'b) list)›*) then have map_cong: "map (bs_at (rho @ [x])) [i..<j] = map (bs_at rho) [i..<j]" by (auto simp: bs_at_def (*‹bs_at ?rho ?i = snd (?rho ! ?i)›*) nth_append (*‹(?xs @ ?ys) ! ?n = (if ?n < length ?xs then ?xs ! ?n else ?ys ! (?n - length ?xs))›*)) show "?thesis" (*goal: ‹steps step (rho @ [x]) q (i, j) = steps step rho q (i, j)›*) by (auto simp: steps_def (*‹steps (?step::?'c::type ⇒ ?'b::type ⇒ ?'c::type) (?rho::(?'d::type × ?'b::type) list) (?q::?'c::type) (?ij::nat × nat) = foldl ?step ?q (sub_bs ?rho ?ij)›*) map_cong (*‹map (bs_at ((rho::('a::type × 'b::type) list) @ [x::'a::type × 'b::type])) [i::nat..<j::nat] = map (bs_at rho) [i..<j]›*)) qed lemma acc_app_cong: "j < length rho ⟹ acc step accept (rho @ [x]) q (i, j) = acc step accept rho q (i, j)" by (auto simp: acc_def (*‹acc ?step ?accept ?rho ?q ?ij = ?accept (steps ?step ?rho ?q ?ij)›*) bs_at_def (*‹bs_at ?rho ?i = snd (?rho ! ?i)›*) nth_append (*‹(?xs @ ?ys) ! ?n = (if ?n < length ?xs then ?xs ! ?n else ?ys ! (?n - length ?xs))›*) steps_app_cong (*‹?j ≤ length ?rho ⟹ steps ?step (?rho @ [?x]) ?q (?i, ?j) = steps ?step ?rho ?q (?i, ?j)›*)) lemma sup_acc_app_cong: "j ≤ length rho ⟹ sup_acc step accept (rho @ [x]) q i j = sup_acc step accept rho q i j" apply (auto simp: sup_acc_def (*‹sup_acc ?step ?accept ?rho ?q ?i ?j = (let L' = {l ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) ts_at_def (*‹ts_at ?rho ?i = fst (?rho ! ?i)›*) nth_append (*‹(?xs @ ?ys) ! ?n = (if ?n < length ?xs then ?xs ! ?n else ?ys ! (?n - length ?xs))›*) acc_def (*‹acc ?step ?accept ?rho ?q ?ij = ?accept (steps ?step ?rho ?q ?ij)›*)) (*goals: 1. ‹⋀xa. ⟦j ≤ length rho; ∀xa<j. i ≤ xa ⟶ ¬ accept (steps step (rho @ [x]) q (i, Suc xa)); i ≤ xa; xa < j; accept (steps step rho q (i, Suc xa))⟧ ⟹ False› 2. ‹⋀xa. ⟦j ≤ length rho; xa < j; i ≤ xa; accept (steps step (rho @ [x]) q (i, Suc xa))⟧ ⟹ ∃x<j. i ≤ x ∧ accept (steps step rho q (i, Suc x))› 3. ‹⋀xa xaa. ⟦j ≤ length rho; xa < j; i ≤ xa; accept (steps step (rho @ [x]) q (i, Suc xa)); xaa < j; i ≤ xaa; accept (steps step rho q (i, Suc xaa))⟧ ⟹ fst (rho ! Max {l. i ≤ l ∧ l < j ∧ accept (steps step (rho @ [x]) q (i, Suc l))}) = fst (rho ! Max {l. i ≤ l ∧ l < j ∧ accept (steps step rho q (i, Suc l))})› 4. ‹⋀xa xaa. ⟦j ≤ length rho; xa < j; i ≤ xa; accept (steps step (rho @ [x]) q (i, Suc xa)); xaa < j; i ≤ xaa; accept (steps step rho q (i, Suc xaa))⟧ ⟹ Max {l. i ≤ l ∧ l < j ∧ accept (steps step (rho @ [x]) q (i, Suc l))} = Max {l. i ≤ l ∧ l < j ∧ accept (steps step rho q (i, Suc l))}› discuss goal 1*) apply (metis (mono_tags, opaque_lifting) less_eq_Suc_le (*‹(?n < ?m) = (Suc ?n ≤ ?m)›*) order_less_le_trans (*‹⟦?x < ?y; ?y ≤ ?z⟧ ⟹ ?x < ?z›*) steps_app_cong (*‹?j ≤ length ?rho ⟹ steps ?step (?rho @ [?x]) ?q (?i, ?j) = steps ?step ?rho ?q (?i, ?j)›*)) (*discuss goal 2*) apply (metis (mono_tags, opaque_lifting) less_eq_Suc_le (*‹(?n < ?m) = (Suc ?n ≤ ?m)›*) order_less_le_trans (*‹⟦?x < ?y; ?y ≤ ?z⟧ ⟹ ?x < ?z›*) steps_app_cong (*‹?j ≤ length ?rho ⟹ steps ?step (?rho @ [?x]) ?q (?i, ?j) = steps ?step ?rho ?q (?i, ?j)›*)) (*discuss goal 3*) apply (metis (mono_tags, opaque_lifting) less_eq_Suc_le (*‹((?n::nat) < (?m::nat)) = (Suc ?n ≤ ?m)›*) order_less_le_trans (*‹⟦(?x::?'a::preorder) < (?y::?'a::preorder); ?y ≤ (?z::?'a::preorder)⟧ ⟹ ?x < ?z›*) steps_app_cong (*‹(?j::nat) ≤ length (?rho::(?'a::type × ?'b::type) list) ⟹ steps (?step::?'c::type ⇒ ?'b::type ⇒ ?'c::type) (?rho @ [?x::?'a::type × ?'b::type]) (?q::?'c::type) (?i::nat, ?j) = steps ?step ?rho ?q (?i, ?j)›*)) (*discuss goal 4*) apply (metis (mono_tags, opaque_lifting) less_eq_Suc_le (*‹(?n < ?m) = (Suc ?n ≤ ?m)›*) order_less_le_trans (*‹⟦?x < ?y; ?y ≤ ?z⟧ ⟹ ?x < ?z›*) steps_app_cong (*‹?j ≤ length ?rho ⟹ steps ?step (?rho @ [?x]) ?q (?i, ?j) = steps ?step ?rho ?q (?i, ?j)›*)) (*proven 4 subgoals*) . lemma sup_acc_concat_cong: "j ≤ length rho ⟹ sup_acc step accept (rho @ rho') q i j = sup_acc step accept rho q i j" apply (induction rho' rule: rev_induct (*‹⟦?P []; ⋀x xs. ?P xs ⟹ ?P (xs @ [x])⟧ ⟹ ?P ?xs›*)) (*goals: 1. ‹j ≤ length rho ⟹ sup_acc step accept (rho @ []) q i j = sup_acc step accept rho q i j› 2. ‹⋀x xs. ⟦j ≤ length rho ⟹ sup_acc step accept (rho @ xs) q i j = sup_acc step accept rho q i j; j ≤ length rho⟧ ⟹ sup_acc step accept (rho @ xs @ [x]) q i j = sup_acc step accept rho q i j› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*goal: ‹⋀x xs. ⟦j ≤ length rho ⟹ sup_acc step accept (rho @ xs) q i j = sup_acc step accept rho q i j; j ≤ length rho⟧ ⟹ sup_acc step accept (rho @ xs @ [x]) q i j = sup_acc step accept rho q i j›*) apply (smt append.assoc (*‹((?a::?'a list) @ (?b::?'a list)) @ (?c::?'a list) = ?a @ ?b @ ?c›*) le_add1 (*‹(?n::nat) ≤ ?n + (?m::nat)›*) le_trans (*‹⟦(?i::nat) ≤ (?j::nat); ?j ≤ (?k::nat)⟧ ⟹ ?i ≤ ?k›*) length_append (*‹length ((?xs::?'a list) @ (?ys::?'a list)) = length ?xs + length ?ys›*) sup_acc_app_cong (*‹(?j::nat) ≤ length (?rho::(?'a × ?'b) list) ⟹ sup_acc (?step::?'c ⇒ ?'b ⇒ ?'c) (?accept::?'c ⇒ bool) (?rho @ [?x::?'a × ?'b]) (?q::?'c) (?i::nat) ?j = sup_acc ?step ?accept ?rho ?q ?i ?j›*)) (*proven 2 subgoals*) . lemma sup_leadsto_app_cong: "i ≤ j ⟹ j ≤ length rho ⟹ sup_leadsto init step (rho @ [x]) i j q = sup_leadsto init step rho i j q" proof (-) (*goal: ‹⟦i ≤ j; j ≤ length rho⟧ ⟹ sup_leadsto init step (rho @ [x]) i j q = sup_leadsto init step rho i j q›*) assume assms: "i ≤ j" "j ≤ length rho" (*‹(i::nat) ≤ (j::nat)› ‹(j::nat) ≤ length (rho::('a × 'b) list)›*) define L' where "L' = {l. l < i ∧ steps step rho init (l, j) = q}" define L'' where "L'' = {l. l < i ∧ steps step (rho @ [x]) init (l, j) = q}" show "?thesis" (*goal: ‹sup_leadsto (init::'c) (step::'c ⇒ 'b ⇒ 'c) ((rho::('a × 'b) list) @ [x::'a × 'b]) (i::nat) (j::nat) (q::'c) = sup_leadsto init step rho i j q›*) using assms (*‹i ≤ j› ‹j ≤ length rho›*) apply (cases "L' = {}") (*goals: 1. ‹⟦i ≤ j; j ≤ length rho; L' = {}⟧ ⟹ sup_leadsto init step (rho @ [x]) i j q = sup_leadsto init step rho i j q› 2. ‹⟦i ≤ j; j ≤ length rho; L' ≠ {}⟧ ⟹ sup_leadsto init step (rho @ [x]) i j q = sup_leadsto init step rho i j q› discuss goal 1*) apply ((auto simp: sup_leadsto_def (*‹sup_leadsto ?init ?step ?rho ?i ?j ?q = (let L' = {l. l < ?i ∧ steps ?step ?rho ?init (l, ?j) = ?q}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m))›*) L'_def (*‹L' = {l. l < i ∧ steps step rho init (l, j) = q}›*) L''_def (*‹L'' = {l. l < i ∧ steps step (rho @ [x]) init (l, j) = q}›*) ts_at_def (*‹ts_at ?rho ?i = fst (?rho ! ?i)›*) nth_append (*‹(?xs @ ?ys) ! ?n = (if ?n < length ?xs then ?xs ! ?n else ?ys ! (?n - length ?xs))›*) steps_app_cong (*‹?j ≤ length ?rho ⟹ steps ?step (?rho @ [?x]) ?q (?i, ?j) = steps ?step ?rho ?q (?i, ?j)›*))[1]) (*discuss goal 2*) apply ((auto simp: sup_leadsto_def (*‹sup_leadsto ?init ?step ?rho ?i ?j ?q = (let L' = {l. l < ?i ∧ steps ?step ?rho ?init (l, ?j) = ?q}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m))›*) L'_def (*‹L' = {l. l < i ∧ steps step rho init (l, j) = q}›*) L''_def (*‹L'' = {l. l < i ∧ steps step (rho @ [x]) init (l, j) = q}›*) ts_at_def (*‹ts_at ?rho ?i = fst (?rho ! ?i)›*) nth_append (*‹(?xs @ ?ys) ! ?n = (if ?n < length ?xs then ?xs ! ?n else ?ys ! (?n - length ?xs))›*) steps_app_cong (*‹?j ≤ length ?rho ⟹ steps ?step (?rho @ [?x]) ?q (?i, ?j) = steps ?step ?rho ?q (?i, ?j)›*))[1]) (*proven 2 subgoals*) . qed lemma chain_le: fixes xs :: "'d :: timestamp list" shows "chain_le xs ⟹ i ≤ j ⟹ j < length xs ⟹ xs ! i ≤ xs ! j" proof (induction xs arbitrary: i j rule: chain_le.induct) (*goals: 1. ‹⋀(i::nat) j::nat. ⟦i ≤ j; j < length []⟧ ⟹ [] ! i ≤ [] ! j› 2. ‹⋀(x::'d) (i::nat) j::nat. ⟦i ≤ j; j < length [x]⟧ ⟹ [x] ! i ≤ [x] ! j› 3. ‹⋀(y::'d) (xs::'d list) (x::'d) (i::nat) j::nat. ⟦chain_le (y # xs); ⋀(i::nat) j::nat. ⟦i ≤ j; j < length (y # xs)⟧ ⟹ (y # xs) ! i ≤ (y # xs) ! j; x ≤ y; i ≤ j; j < length (x # y # xs)⟧ ⟹ (x # y # xs) ! i ≤ (x # y # xs) ! j›*) case (chain_le_cons y xs x) (*‹chain_le (y # xs)› ‹(x::'d) ≤ (y::'d)› ‹⟦?i ≤ ?j; ?j < length (y # xs)⟧ ⟹ (y # xs) ! ?i ≤ (y # xs) ! ?j› ‹i ≤ j› ‹j < length (x # y # xs)›*) then show "?case" (*goal: ‹(x # y # xs) ! i ≤ (x # y # xs) ! j›*) proof (cases i) (*goals: 1. ‹⟦chain_le (y # xs); x ≤ y; ⋀i j. ⟦i ≤ j; j < length (y # xs)⟧ ⟹ (y # xs) ! i ≤ (y # xs) ! j; i ≤ j; j < length (x # y # xs); i = 0⟧ ⟹ (x # y # xs) ! i ≤ (x # y # xs) ! j› 2. ‹⋀nat. ⟦chain_le (y # xs); x ≤ y; ⋀i j. ⟦i ≤ j; j < length (y # xs)⟧ ⟹ (y # xs) ! i ≤ (y # xs) ! j; i ≤ j; j < length (x # y # xs); i = Suc nat⟧ ⟹ (x # y # xs) ! i ≤ (x # y # xs) ! j›*) case 0 (*‹i = 0›*) then show "?thesis" (*goal: ‹(x # y # xs) ! i ≤ (x # y # xs) ! j›*) using chain_le_cons (*‹chain_le (y # xs)› ‹x ≤ y› ‹⟦?i ≤ ?j; ?j < length (y # xs)⟧ ⟹ (y # xs) ! ?i ≤ (y # xs) ! ?j› ‹i ≤ j› ‹j < length (x # y # xs)›*) apply (cases j) (*goals: 1. ‹⟦i = 0; chain_le (y # xs); x ≤ y; ⋀i j. ⟦i ≤ j; j < length (y # xs)⟧ ⟹ (y # xs) ! i ≤ (y # xs) ! j; i ≤ j; j < length (x # y # xs); j = 0⟧ ⟹ (x # y # xs) ! i ≤ (x # y # xs) ! j› 2. ‹⋀nat. ⟦i = 0; chain_le (y # xs); x ≤ y; ⋀i j. ⟦i ≤ j; j < length (y # xs)⟧ ⟹ (y # xs) ! i ≤ (y # xs) ! j; i ≤ j; j < length (x # y # xs); j = Suc nat⟧ ⟹ (x # y # xs) ! i ≤ (x # y # xs) ! j› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*goal: ‹⋀nat. ⟦i = 0; chain_le (y # xs); x ≤ y; ⋀i j. ⟦i ≤ j; j < length (y # xs)⟧ ⟹ (y # xs) ! i ≤ (y # xs) ! j; i ≤ j; j < length (x # y # xs); j = Suc nat⟧ ⟹ (x # y # xs) ! i ≤ (x # y # xs) ! j›*) apply (metis (no_types, lifting) le_add1 (*‹?n ≤ ?n + ?m›*) le_add_same_cancel1 (*‹(?a ≤ ?a + ?b) = (0 ≤ ?b)›*) le_less (*‹(?x ≤ ?y) = (?x < ?y ∨ ?x = ?y)›*) less_le_trans (*‹⟦?x < ?y; ?y ≤ ?z⟧ ⟹ ?x < ?z›*) nth_Cons_0 (*‹(?x # ?xs) ! 0 = ?x›*)) (*proven 2 subgoals*) . qed (auto) (*solved the remaining goal: ‹⋀nat. ⟦chain_le (y # xs); x ≤ y; ⋀i j. ⟦i ≤ j; j < length (y # xs)⟧ ⟹ (y # xs) ! i ≤ (y # xs) ! j; i ≤ j; j < length (x # y # xs); i = Suc nat⟧ ⟹ (x # y # xs) ! i ≤ (x # y # xs) ! j›*) qed (auto) (*solves the remaining goals: 1. ‹⋀i j. ⟦i ≤ j; j < length []⟧ ⟹ [] ! i ≤ [] ! j› 2. ‹⋀x i j. ⟦i ≤ j; j < length [x]⟧ ⟹ [x] ! i ≤ [x] ! j›*) lemma steps_refl[simp]: "steps step rho q (i, i) = q" unfolding steps_def (*goal: ‹foldl step q (sub_bs rho (i, i)) = q›*) by auto lemma steps_split: "i < j ⟹ steps step rho q (i, j) = steps step rho (step q (bs_at rho i)) (Suc i, j)" unfolding steps_def (*goal: ‹i < j ⟹ foldl step q (sub_bs rho (i, j)) = foldl step (step q (bs_at rho i)) (sub_bs rho (Suc i, j))›*) by (simp add: upt_rec (*‹[?i..<?j] = (if ?i < ?j then ?i # [Suc ?i..<?j] else [])›*)) lemma steps_app: "i ≤ j ⟹ steps step rho q (i, j + 1) = step (steps step rho q (i, j)) (bs_at rho j)" unfolding steps_def (*goal: ‹i ≤ j ⟹ foldl step q (sub_bs rho (i, j + 1)) = step (foldl step q (sub_bs rho (i, j))) (bs_at rho j)›*) by auto lemma steps_appE: "i ≤ j ⟹ steps step rho q (i, Suc j) = q' ⟹ ∃q''. steps step rho q (i, j) = q'' ∧ q' = step q'' (bs_at rho j)" unfolding steps_def sub_bs.simps (*goal: ‹⟦i ≤ j; foldl step q (map (bs_at rho) [i..<Suc j]) = q'⟧ ⟹ ∃q''. foldl step q (map (bs_at rho) [i..<j]) = q'' ∧ q' = step q'' (bs_at rho j)›*) by auto lemma steps_comp: "i ≤ l ⟹ l ≤ j ⟹ steps step rho q (i, l) = q' ⟹ steps step rho q' (l, j) = q'' ⟹ steps step rho q (i, j) = q''" proof (-) (*goal: ‹⟦i ≤ l; l ≤ j; steps step rho q (i, l) = q'; steps step rho q' (l, j) = q''⟧ ⟹ steps step rho q (i, j) = q''›*) assume assms: "i ≤ l" "l ≤ j" "steps step rho q (i, l) = q'" "steps step rho q' (l, j) = q''" (*‹(i::nat) ≤ (l::nat)› ‹(l::nat) ≤ (j::nat)› ‹steps (step::'a ⇒ 'b ⇒ 'a) (rho::('c × 'b) list) (q::'a) (i::nat, l::nat) = (q'::'a)› ‹steps (step::'a ⇒ 'b ⇒ 'a) (rho::('c × 'b) list) (q'::'a) (l::nat, j::nat) = (q''::'a)›*) have range_app: "[i..<l] @ [l..<j] = [i..<j]" using assms(1,2) (*‹i ≤ l› ‹l ≤ j›*) by (metis le_Suc_ex (*‹?k ≤ ?l ⟹ ∃n. ?l = ?k + n›*) upt_add_eq_append (*‹?i ≤ ?j ⟹ [?i..<?j + ?k] = [?i..<?j] @ [?j..<?j + ?k]›*)) have "q' = foldl step q (map (bs_at rho) [i..<l])" using assms(3) (*‹steps step rho q (i, l) = q'›*) unfolding steps_def (*goal: ‹(q'::'a) = foldl (step::'a ⇒ 'b ⇒ 'a) (q::'a) (map (bs_at (rho::('c × 'b) list)) [i::nat..<l::nat])›*) by auto moreover have "q'' = foldl step q' (map (bs_at rho) [l..<j])" using assms(4) (*‹steps step rho q' (l, j) = q''›*) unfolding steps_def (*goal: ‹q'' = foldl step q' (map (bs_at rho) [l..<j])›*) by auto ultimately have "q'' = foldl step q (map (bs_at rho) ([i..<l] @ [l..<j]))" by auto then show "?thesis" (*goal: ‹steps step rho q (i, j) = q''›*) unfolding steps_def range_app (*goal: ‹foldl step q (sub_bs rho (i, j)) = q''›*) by auto qed lemma sup_acc_SomeI: "acc step accept rho q (i, Suc l) ⟹ l ∈ {i..<j} ⟹ ∃tp. sup_acc step accept rho q i j = Some (ts_at rho tp, tp) ∧ l ≤ tp ∧ tp < j" proof (-) (*goal: ‹⟦acc (step::'a ⇒ 'b ⇒ 'a) (accept::'a ⇒ bool) (rho::('c × 'b) list) (q::'a) (i::nat, Suc (l::nat)); l ∈ {i..<j::nat}⟧ ⟹ ∃tp::nat. sup_acc step accept rho q i j = Some (ts_at rho tp, tp) ∧ l ≤ tp ∧ tp < j›*) assume assms: "acc step accept rho q (i, Suc l)" "l ∈ {i..<j}" (*‹acc (step::'a ⇒ 'b ⇒ 'a) (accept::'a ⇒ bool) (rho::('c × 'b) list) (q::'a) (i::nat, Suc (l::nat))› ‹(l::nat) ∈ {i::nat..<j::nat}›*) define L where "L = {l ∈ {i..<j}. acc step accept rho q (i, Suc l)}" have L_props: "finite L" "L ≠ {}" "l ∈ L" using assms (*‹acc step accept rho q (i, Suc l)› ‹l ∈ {i..<j}›*) unfolding L_def (*goals: 1. ‹finite {l::nat ∈ {i::nat..<j::nat}. acc (step::'a ⇒ 'b ⇒ 'a) (accept::'a ⇒ bool) (rho::('c × 'b) list) (q::'a) (i, Suc l)}› 2. ‹{l::nat ∈ {i::nat..<j::nat}. acc (step::'a ⇒ 'b ⇒ 'a) (accept::'a ⇒ bool) (rho::('c × 'b) list) (q::'a) (i, Suc l)} ≠ {}› 3. ‹(l::nat) ∈ {l::nat ∈ {i::nat..<j::nat}. acc (step::'a ⇒ 'b ⇒ 'a) (accept::'a ⇒ bool) (rho::('c × 'b) list) (q::'a) (i, Suc l)}›*) apply - (*goals: 1. ‹⟦acc (step::'a ⇒ 'b ⇒ 'a) (accept::'a ⇒ bool) (rho::('c × 'b) list) (q::'a) (i::nat, Suc (l::nat)); l ∈ {i..<j::nat}⟧ ⟹ finite {l::nat ∈ {i..<j}. acc step accept rho q (i, Suc l)}› 2. ‹⟦acc (step::'a ⇒ 'b ⇒ 'a) (accept::'a ⇒ bool) (rho::('c × 'b) list) (q::'a) (i::nat, Suc (l::nat)); l ∈ {i..<j::nat}⟧ ⟹ {l::nat ∈ {i..<j}. acc step accept rho q (i, Suc l)} ≠ {}› 3. ‹⟦acc (step::'a ⇒ 'b ⇒ 'a) (accept::'a ⇒ bool) (rho::('c × 'b) list) (q::'a) (i::nat, Suc (l::nat)); l ∈ {i..<j::nat}⟧ ⟹ l ∈ {l::nat ∈ {i..<j}. acc step accept rho q (i, Suc l)}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . then show "∃tp. sup_acc step accept rho q i j = Some (ts_at rho tp, tp) ∧ l ≤ tp ∧ tp < j" using L_def (*‹L = {l ∈ {i..<j}. acc step accept rho q (i, Suc l)}›*) L_props (*‹finite L› ‹L ≠ {}› ‹l ∈ L›*) apply (auto simp add: sup_acc_def (*‹sup_acc ?step ?accept ?rho ?q ?i ?j = (let L' = {l ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*)) (*goal: ‹∃tp. sup_acc step accept rho q i j = Some (ts_at rho tp, tp) ∧ l ≤ tp ∧ tp < j›*) by (smt L_props( (*‹finite L›*) 1) L_props( (*‹L ≠ {}›*) 2) Max_ge (*‹⟦finite ?A; ?x ∈ ?A⟧ ⟹ ?x ≤ Max ?A›*) Max_in (*‹⟦finite ?A; ?A ≠ {}⟧ ⟹ Max ?A ∈ ?A›*) mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*)) qed lemma sup_acc_Some_ts: "sup_acc step accept rho q i j = Some (ts, tp) ⟹ ts = ts_at rho tp" by (auto simp add: sup_acc_def (*‹sup_acc ?step ?accept ?rho ?q ?i ?j = (let L' = {l ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) lemma sup_acc_SomeE: "sup_acc step accept rho q i j = Some (ts, tp) ⟹ tp ∈ {i..<j} ∧ acc step accept rho q (i, Suc tp)" proof (-) (*goal: ‹sup_acc step accept rho q i j = Some (ts, tp) ⟹ tp ∈ {i..<j} ∧ acc step accept rho q (i, Suc tp)›*) assume assms: "sup_acc step accept rho q i j = Some (ts, tp)" (*‹sup_acc (step::'b ⇒ 'c ⇒ 'b) (accept::'b ⇒ bool) (rho::('a × 'c) list) (q::'b) (i::nat) (j::nat) = Some (ts::'a, tp::nat)›*) define L where "L = {l ∈ {i..<j}. acc step accept rho q (i, Suc l)}" have L_props: "finite L" "L ≠ {}" "Max L = tp" unfolding L_def (*goals: 1. ‹finite {l ∈ {i..<j}. acc step accept rho q (i, Suc l)}› 2. ‹{l ∈ {i..<j}. acc step accept rho q (i, Suc l)} ≠ {}› 3. ‹Max {l ∈ {i..<j}. acc step accept rho q (i, Suc l)} = tp›*) using assms (*‹sup_acc step accept rho q i j = Some (ts, tp)›*) apply - (*goals: 1. ‹sup_acc step accept rho q i j = Some (ts, tp) ⟹ finite {l ∈ {i..<j}. acc step accept rho q (i, Suc l)}› 2. ‹sup_acc step accept rho q i j = Some (ts, tp) ⟹ {l ∈ {i..<j}. acc step accept rho q (i, Suc l)} ≠ {}› 3. ‹sup_acc step accept rho q i j = Some (ts, tp) ⟹ Max {l ∈ {i..<j}. acc step accept rho q (i, Suc l)} = tp› discuss goal 1*) apply ((auto simp add: sup_acc_def (*‹sup_acc ?step ?accept ?rho ?q ?i ?j = (let L' = {l ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto simp add: sup_acc_def (*‹sup_acc ?step ?accept ?rho ?q ?i ?j = (let L' = {l ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 3*) apply ((auto simp add: sup_acc_def (*‹sup_acc ?step ?accept ?rho ?q ?i ?j = (let L' = {l ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 3 subgoals*) . show "?thesis" (*goal: ‹tp ∈ {i..<j} ∧ acc step accept rho q (i, Suc tp)›*) using Max_in[OF L_props ( 1 , 2 )] (*‹Max (L::nat set) ∈ L›*) unfolding L_props(3) (*goal: ‹tp ∈ {i..<j} ∧ acc step accept rho q (i, Suc tp)›*) unfolding L_def (*goal: ‹tp ∈ {i..<j} ∧ acc step accept rho q (i, Suc tp)›*) by auto qed lemma sup_acc_NoneE: "l ∈ {i..<j} ⟹ sup_acc step accept rho q i j = None ⟹ ¬acc step accept rho q (i, Suc l)" by (auto simp add: sup_acc_def (*‹sup_acc ?step ?accept ?rho ?q ?i ?j = (let L' = {l ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) lemma sup_acc_same: "sup_acc step accept rho q i i = None" by (auto simp add: sup_acc_def (*‹sup_acc ?step ?accept ?rho ?q ?i ?j = (let L' = {l ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*)) lemma sup_acc_None_restrict: "i ≤ j ⟹ sup_acc step accept rho q i j = None ⟹ sup_acc step accept rho (step q (bs_at rho i)) (Suc i) j = None" using steps_split (*‹?i < ?j ⟹ steps ?step ?rho ?q (?i, ?j) = steps ?step ?rho (?step ?q (bs_at ?rho ?i)) (Suc ?i, ?j)›*) apply (auto simp add: sup_acc_def (*‹sup_acc ?step ?accept ?rho ?q ?i ?j = (let L' = {l ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) acc_def (*‹acc ?step ?accept ?rho ?q ?ij = ?accept (steps ?step ?rho ?q ?ij)›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) (*goal: ‹⟦i ≤ j; sup_acc step accept rho q i j = None⟧ ⟹ sup_acc step accept rho (step q (bs_at rho i)) (Suc i) j = None›*) by (smt (z3) lessI (*‹?n < Suc ?n›*) less_imp_le_nat (*‹?m < ?n ⟹ ?m ≤ ?n›*) order_less_le_trans (*‹⟦?x < ?y; ?y ≤ ?z⟧ ⟹ ?x < ?z›*) steps_split (*‹?i < ?j ⟹ steps ?step ?rho ?q (?i, ?j) = steps ?step ?rho (?step ?q (bs_at ?rho ?i)) (Suc ?i, ?j)›*)) lemma sup_acc_ext_idle: "i ≤ j ⟹ ¬acc step accept rho q (i, Suc j) ⟹ sup_acc step accept rho q i (Suc j) = sup_acc step accept rho q i j" proof (-) (*goal: ‹⟦(i::nat) ≤ (j::nat); ¬ acc (step::'a ⇒ 'b ⇒ 'a) (accept::'a ⇒ bool) (rho::('c × 'b) list) (q::'a) (i, Suc j)⟧ ⟹ sup_acc step accept rho q i (Suc j) = sup_acc step accept rho q i j›*) assume assms: "i ≤ j" "¬acc step accept rho q (i, Suc j)" (*‹(i::nat) ≤ (j::nat)› ‹¬ acc (step::'a ⇒ 'b ⇒ 'a) (accept::'a ⇒ bool) (rho::('c × 'b) list) (q::'a) (i::nat, Suc (j::nat))›*) define L where "L = {l ∈ {i..<j}. acc step accept rho q (i, Suc l)}" define L' where "L' = {l ∈ {i..<Suc j}. acc step accept rho q (i, Suc l)}" have L_L': "L = L'" unfolding L_def L'_def (*goal: ‹{l ∈ {i..<j}. acc step accept rho q (i, Suc l)} = {l ∈ {i..<Suc j}. acc step accept rho q (i, Suc l)}›*) using assms(2) (*‹¬ acc step accept rho q (i, Suc j)›*) less_antisym (*‹⟦¬ ?n < ?m; ?n < Suc ?m⟧ ⟹ ?m = ?n›*) by fastforce show "sup_acc step accept rho q i (Suc j) = sup_acc step accept rho q i j" using L_def (*‹L = {l ∈ {i..<j}. acc step accept rho q (i, Suc l)}›*) L'_def (*‹L' = {l ∈ {i..<Suc j}. acc step accept rho q (i, Suc l)}›*) L_L' (*‹L = L'›*) by (auto simp add: sup_acc_def (*‹sup_acc ?step ?accept ?rho ?q ?i ?j = (let L' = {l ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*)) qed lemma sup_acc_comp_Some_ge: "i ≤ l ⟹ l ≤ j ⟹ tp ≥ l ⟹ sup_acc step accept rho (steps step rho q (i, l)) l j = Some (ts, tp) ⟹ sup_acc step accept rho q i j = sup_acc step accept rho (steps step rho q (i, l)) l j" proof (-) (*goal: ‹⟦i ≤ l; l ≤ j; l ≤ tp; sup_acc step accept rho (steps step rho q (i, l)) l j = Some (ts, tp)⟧ ⟹ sup_acc step accept rho q i j = sup_acc step accept rho (steps step rho q (i, l)) l j›*) assume assms: "i ≤ l" "l ≤ j" "sup_acc step accept rho (steps step rho q (i, l)) l j = Some (ts, tp)" "tp ≥ l" (*‹(i::nat) ≤ (l::nat)› ‹(l::nat) ≤ (j::nat)› ‹sup_acc (step::'b ⇒ 'c ⇒ 'b) (accept::'b ⇒ bool) (rho::('a × 'c) list) (steps step rho (q::'b) (i::nat, l::nat)) l (j::nat) = Some (ts::'a, tp::nat)› ‹(l::nat) ≤ (tp::nat)›*) define L where "L = {l ∈ {i..<j}. acc step accept rho q (i, Suc l)}" define L' where "L' = {l' ∈ {l..<j}. acc step accept rho (steps step rho q (i, l)) (l, Suc l')}" have L'_props: "finite L'" "L' ≠ {}" "tp = Max L'" "ts = ts_at rho tp" using assms(3) (*‹sup_acc step accept rho (steps step rho q (i, l)) l j = Some (ts, tp)›*) unfolding L'_def (*goals: 1. ‹finite {l' ∈ {l..<j}. acc step accept rho (steps step rho q (i, l)) (l, Suc l')}› 2. ‹{l' ∈ {l..<j}. acc step accept rho (steps step rho q (i, l)) (l, Suc l')} ≠ {}› 3. ‹tp = Max {l' ∈ {l..<j}. acc step accept rho (steps step rho q (i, l)) (l, Suc l')}› 4. ‹ts = ts_at rho tp›*) apply - (*goals: 1. ‹sup_acc (step::'b ⇒ 'c ⇒ 'b) (accept::'b ⇒ bool) (rho::('a × 'c) list) (steps step rho (q::'b) (i::nat, l::nat)) l (j::nat) = Some (ts::'a, tp::nat) ⟹ finite {l'::nat ∈ {l..<j}. acc step accept rho (steps step rho q (i, l)) (l, Suc l')}› 2. ‹sup_acc (step::'b ⇒ 'c ⇒ 'b) (accept::'b ⇒ bool) (rho::('a × 'c) list) (steps step rho (q::'b) (i::nat, l::nat)) l (j::nat) = Some (ts::'a, tp::nat) ⟹ {l'::nat ∈ {l..<j}. acc step accept rho (steps step rho q (i, l)) (l, Suc l')} ≠ {}› 3. ‹sup_acc (step::'b ⇒ 'c ⇒ 'b) (accept::'b ⇒ bool) (rho::('a × 'c) list) (steps step rho (q::'b) (i::nat, l::nat)) l (j::nat) = Some (ts::'a, tp::nat) ⟹ tp = Max {l'::nat ∈ {l..<j}. acc step accept rho (steps step rho q (i, l)) (l, Suc l')}› 4. ‹sup_acc (step::'b ⇒ 'c ⇒ 'b) (accept::'b ⇒ bool) (rho::('a × 'c) list) (steps step rho (q::'b) (i::nat, l::nat)) l (j::nat) = Some (ts::'a, tp::nat) ⟹ ts = ts_at rho tp› discuss goal 1*) apply ((auto simp add: sup_acc_def (*‹sup_acc ?step ?accept ?rho ?q ?i ?j = (let L' = {l ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto simp add: sup_acc_def (*‹sup_acc (?step::?'c::type ⇒ ?'b::type ⇒ ?'c::type) (?accept::?'c::type ⇒ bool) (?rho::(?'d::type × ?'b::type) list) (?q::?'c::type) (?i::nat) (?j::nat) = (let L'::nat set = {l::nat ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m::nat = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*) Let_def (*‹Let (?s::?'a::type) (?f::?'a::type ⇒ ?'b::type) ≡ ?f ?s›*) split: if_splits (*‹(?P::?'a::type ⇒ bool) (if ?Q::bool then ?x::?'a::type else (?y::?'a::type)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹(?P::?'a::type ⇒ bool) (if ?Q::bool then ?x::?'a::type else (?y::?'a::type)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 3*) apply ((auto simp add: sup_acc_def (*‹sup_acc ?step ?accept ?rho ?q ?i ?j = (let L' = {l ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 4*) apply ((auto simp add: sup_acc_def (*‹sup_acc ?step ?accept ?rho ?q ?i ?j = (let L' = {l ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 4 subgoals*) . have tp_in_L': "tp ∈ L'" using Max_in[OF L'_props ( 1 , 2 )] (*‹Max L' ∈ L'›*) unfolding L'_props(3) (*goal: ‹Max (L'::nat set) ∈ L'›*) . then have tp_in_L: "tp ∈ L" unfolding L_def L'_def (*goal: ‹tp ∈ {l ∈ {i..<j}. acc step accept rho q (i, Suc l)}›*) using assms(1) (*‹i ≤ l›*) steps_comp[OF assms ( 1 , 2 ), of step rho] (*‹⟦steps step rho ?q (i, l) = ?q'; steps step rho ?q' (l, j) = ?q''⟧ ⟹ steps step rho ?q (i, j) = ?q''›*) apply (auto simp add: acc_def (*‹acc ?step ?accept ?rho ?q ?ij = ?accept (steps ?step ?rho ?q ?ij)›*)) (*goal: ‹tp ∈ {l ∈ {i..<j}. acc step accept rho q (i, Suc l)}›*) using steps_comp (*‹⟦?i ≤ ?l; ?l ≤ ?j; steps ?step ?rho ?q (?i, ?l) = ?q'; steps ?step ?rho ?q' (?l, ?j) = ?q''⟧ ⟹ steps ?step ?rho ?q (?i, ?j) = ?q''›*) by (metis le_SucI (*‹?m ≤ ?n ⟹ ?m ≤ Suc ?n›*)) have L_props: "finite L" "L ≠ {}" using L_def (*‹L = {l ∈ {i..<j}. acc step accept rho q (i, Suc l)}›*) tp_in_L (*‹tp ∈ L›*) apply - (*goals: 1. ‹⟦(L::nat set) = {l::nat ∈ {i::nat..<j::nat}. acc (step::'b::type ⇒ 'c::type ⇒ 'b::type) (accept::'b::type ⇒ bool) (rho::('a::type × 'c::type) list) (q::'b::type) (i, Suc l)}; (tp::nat) ∈ L⟧ ⟹ finite L› 2. ‹⟦(L::nat set) = {l::nat ∈ {i::nat..<j::nat}. acc (step::'b::type ⇒ 'c::type ⇒ 'b::type) (accept::'b::type ⇒ bool) (rho::('a::type × 'c::type) list) (q::'b::type) (i, Suc l)}; (tp::nat) ∈ L⟧ ⟹ L ≠ {}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have "⋀l'. l' ∈ L ⟹ l' ≤ tp" proof (-) (*goal: ‹⋀l'. l' ∈ L ⟹ l' ≤ tp›*) fix l' assume assm: "l' ∈ L" (*‹(l'::nat) ∈ (L::nat set)›*) show "l' ≤ tp" proof (cases "l' < l") (*goals: 1. ‹l' < l ⟹ l' ≤ tp› 2. ‹¬ l' < l ⟹ l' ≤ tp›*) case True (*‹l' < l›*) then show "?thesis" (*goal: ‹l' ≤ tp›*) using assms(4) (*‹(l::nat) ≤ (tp::nat)›*) by auto next (*goal: ‹¬ l' < l ⟹ l' ≤ tp›*) case False (*‹¬ l' < l›*) then have "l' ∈ L'" using assm (*‹(l'::nat) ∈ (L::nat set)›*) unfolding L_def L'_def (*goal: ‹l' ∈ {l' ∈ {l..<j}. acc step accept rho (steps step rho q (i, l)) (l, Suc l')}›*) apply (auto simp add: acc_def (*‹acc (?step::?'c ⇒ ?'b ⇒ ?'c) (?accept::?'c ⇒ bool) (?rho::(?'d × ?'b) list) (?q::?'c) (?ij::nat × nat) = ?accept (steps ?step ?rho ?q ?ij)›*)) (*goal: ‹(l'::nat) ∈ {l'::nat ∈ {l::nat..<j::nat}. acc (step::'b::type ⇒ 'c::type ⇒ 'b::type) (accept::'b::type ⇒ bool) (rho::('a::type × 'c::type) list) (steps step rho (q::'b::type) (i::nat, l)) (l, Suc l')}›*) by (metis assms( (*‹i ≤ l›*) 1) less_imp_le_nat (*‹?m < ?n ⟹ ?m ≤ ?n›*) not_less_eq (*‹(¬ ?m < ?n) = (?n < Suc ?m)›*) steps_comp (*‹⟦?i ≤ ?l; ?l ≤ ?j; steps ?step ?rho ?q (?i, ?l) = ?q'; steps ?step ?rho ?q' (?l, ?j) = ?q''⟧ ⟹ steps ?step ?rho ?q (?i, ?j) = ?q''›*)) then show "?thesis" (*goal: ‹l' ≤ tp›*) using Max_eq_iff[OF L'_props ( 1 , 2 )] (*‹(Max L' = ?m) = (?m ∈ L' ∧ (∀a∈L'. a ≤ ?m))›*) L'_props(3) (*‹tp = Max L'›*) by auto qed qed then have "Max L = tp" using Max_eq_iff[OF L_props] (*‹(Max L = ?m) = (?m ∈ L ∧ (∀a∈L. a ≤ ?m))›*) tp_in_L (*‹tp ∈ L›*) by auto then have "sup_acc step accept rho q i j = Some (ts, tp)" using L_def (*‹L = {l ∈ {i..<j}. acc step accept rho q (i, Suc l)}›*) L_props(2) (*‹(L::nat set) ≠ {}›*) unfolding L'_props(4) (*goal: ‹sup_acc step accept rho q i j = Some (ts_at rho tp, tp)›*) by (auto simp add: sup_acc_def (*‹sup_acc ?step ?accept ?rho ?q ?i ?j = (let L' = {l ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*)) then show "sup_acc step accept rho q i j = sup_acc step accept rho (steps step rho q (i, l)) l j" using assms(3) (*‹sup_acc step accept rho (steps step rho q (i, l)) l j = Some (ts, tp)›*) by auto qed lemma sup_acc_comp_None: "i ≤ l ⟹ l ≤ j ⟹ sup_acc step accept rho (steps step rho q (i, l)) l j = None ⟹ sup_acc step accept rho q i j = sup_acc step accept rho q i l" proof (induction "j - l" arbitrary: l) (*goals: 1. ‹⋀l. ⟦0 = j - l; i ≤ l; l ≤ j; sup_acc step accept rho (steps step rho q (i, l)) l j = None⟧ ⟹ sup_acc step accept rho q i j = sup_acc step accept rho q i l› 2. ‹⋀x l. ⟦⋀l. ⟦x = j - l; i ≤ l; l ≤ j; sup_acc step accept rho (steps step rho q (i, l)) l j = None⟧ ⟹ sup_acc step accept rho q i j = sup_acc step accept rho q i l; Suc x = j - l; i ≤ l; l ≤ j; sup_acc step accept rho (steps step rho q (i, l)) l j = None⟧ ⟹ sup_acc step accept rho q i j = sup_acc step accept rho q i l›*) case (Suc n) (*‹⟦n = j - ?l; i ≤ ?l; ?l ≤ j; sup_acc step accept rho (steps step rho q (i, ?l)) ?l j = None⟧ ⟹ sup_acc step accept rho q i j = sup_acc step accept rho q i ?l› ‹Suc (n::nat) = (j::nat) - (l::nat)› ‹i ≤ l› ‹l ≤ j› ‹sup_acc step accept rho (steps step rho q (i, l)) l j = None›*) have i_lt_j: "i < j" using Suc (*‹⟦(n::nat) = (j::nat) - (?l::nat); (i::nat) ≤ ?l; ?l ≤ j; sup_acc (step::'b ⇒ 'c ⇒ 'b) (accept::'b ⇒ bool) (rho::('a × 'c) list) (steps step rho (q::'b) (i, ?l)) ?l j = None⟧ ⟹ sup_acc step accept rho q i j = sup_acc step accept rho q i ?l› ‹Suc n = j - l› ‹i ≤ l› ‹l ≤ j› ‹sup_acc step accept rho (steps step rho q (i, l)) l j = None›*) by auto have l_lt_j: "l < j" using Suc (*‹⟦n = j - ?l; i ≤ ?l; ?l ≤ j; sup_acc step accept rho (steps step rho q (i, ?l)) ?l j = None⟧ ⟹ sup_acc step accept rho q i j = sup_acc step accept rho q i ?l› ‹Suc n = j - l› ‹i ≤ l› ‹l ≤ j› ‹sup_acc step accept rho (steps step rho q (i, l)) l j = None›*) by auto have "¬acc step accept rho q (i, Suc l)" using sup_acc_NoneE[of l l j step accept rho "steps step rho q (i, l)"] (*‹⟦l ∈ {l..<j}; sup_acc step accept rho (steps step rho q (i, l)) l j = None⟧ ⟹ ¬ acc step accept rho (steps step rho q (i, l)) (l, Suc l)›*) Suc(2-) (*‹Suc n = j - l› ‹i ≤ l› ‹l ≤ j› ‹sup_acc step accept rho (steps step rho q (i, l)) l j = None›*) by (auto simp add: acc_def (*‹acc ?step ?accept ?rho ?q ?ij = ?accept (steps ?step ?rho ?q ?ij)›*) steps_def (*‹steps ?step ?rho ?q ?ij = foldl ?step ?q (sub_bs ?rho ?ij)›*)) then have "sup_acc step accept rho q i (l + 1) = sup_acc step accept rho q i l" using sup_acc_ext_idle[OF Suc ( 3 )] (*‹¬ acc (?step::?'a ⇒ ?'b ⇒ ?'a) (?accept::?'a ⇒ bool) (?rho::(?'c × ?'b) list) (?q::?'a) (i::nat, Suc (l::nat)) ⟹ sup_acc ?step ?accept ?rho ?q i (Suc l) = sup_acc ?step ?accept ?rho ?q i l›*) by auto moreover have "sup_acc step accept rho (steps step rho q (i, l + 1)) (l + 1) j = None" using sup_acc_None_restrict[OF Suc ( 4 , 5 )] (*‹sup_acc step accept rho (step (steps step rho q (i, l)) (bs_at rho l)) (Suc l) j = None›*) steps_app[OF Suc ( 3 ), of step rho] (*‹steps step rho ?q (i, l + 1) = step (steps step rho ?q (i, l)) (bs_at rho l)›*) by auto ultimately show "?case" (*goal: ‹sup_acc step accept rho q i j = sup_acc step accept rho q i l›*) using Suc(1)[of "l + 1"] (*‹⟦n = j - (l + 1); i ≤ l + 1; l + 1 ≤ j; sup_acc step accept rho (steps step rho q (i, l + 1)) (l + 1) j = None⟧ ⟹ sup_acc step accept rho q i j = sup_acc step accept rho q i (l + 1)›*) Suc(2,3,4,5) (*‹Suc (n::nat) = (j::nat) - (l::nat)› ‹i ≤ l› ‹(l::nat) ≤ (j::nat)› ‹sup_acc step accept rho (steps step rho q (i, l)) l j = None›*) by auto qed (auto simp add: sup_acc_same (*‹sup_acc ?step ?accept ?rho ?q ?i ?i = None›*)) (*solved the remaining goal: ‹⋀l. ⟦0 = j - l; i ≤ l; l ≤ j; sup_acc step accept rho (steps step rho q (i, l)) l j = None⟧ ⟹ sup_acc step accept rho q i j = sup_acc step accept rho q i l›*) lemma sup_acc_ext: "i ≤ j ⟹ acc step accept rho q (i, Suc j) ⟹ sup_acc step accept rho q i (Suc j) = Some (ts_at rho j, j)" proof (-) (*goal: ‹⟦i ≤ j; acc step accept rho q (i, Suc j)⟧ ⟹ sup_acc step accept rho q i (Suc j) = Some (ts_at rho j, j)›*) assume assms: "i ≤ j" "acc step accept rho q (i, Suc j)" (*‹(i::nat) ≤ (j::nat)› ‹acc (step::'a ⇒ 'b ⇒ 'a) (accept::'a ⇒ bool) (rho::('c × 'b) list) (q::'a) (i::nat, Suc (j::nat))›*) define L' where "L' = {l ∈ {i..<j + 1}. acc step accept rho q (i, Suc l)}" have j_in_L': "finite L'" "L' ≠ {}" "j ∈ L'" using assms (*‹i ≤ j› ‹acc step accept rho q (i, Suc j)›*) unfolding L'_def (*goals: 1. ‹finite {l ∈ {i..<j + 1}. acc step accept rho q (i, Suc l)}› 2. ‹{l ∈ {i..<j + 1}. acc step accept rho q (i, Suc l)} ≠ {}› 3. ‹j ∈ {l ∈ {i..<j + 1}. acc step accept rho q (i, Suc l)}›*) apply - (*goals: 1. ‹⟦i ≤ j; acc step accept rho q (i, Suc j)⟧ ⟹ finite {l ∈ {i..<j + 1}. acc step accept rho q (i, Suc l)}› 2. ‹⟦i ≤ j; acc step accept rho q (i, Suc j)⟧ ⟹ {l ∈ {i..<j + 1}. acc step accept rho q (i, Suc l)} ≠ {}› 3. ‹⟦i ≤ j; acc step accept rho q (i, Suc j)⟧ ⟹ j ∈ {l ∈ {i..<j + 1}. acc step accept rho q (i, Suc l)}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . have j_is_Max: "Max L' = j" using Max_eq_iff[OF j_in_L' ( 1 , 2 )] (*‹(Max (L'::nat set) = (?m::nat)) = (?m ∈ L' ∧ (∀a::nat∈L'. a ≤ ?m))›*) j_in_L'(3) (*‹(j::nat) ∈ (L'::nat set)›*) by (auto simp add: L'_def (*‹L' = {l ∈ {i..<j + 1}. acc step accept rho q (i, Suc l)}›*)) show "sup_acc step accept rho q i (Suc j) = Some (ts_at rho j, j)" using L'_def (*‹L' = {l ∈ {i..<j + 1}. acc step accept rho q (i, Suc l)}›*) j_is_Max (*‹Max L' = j›*) j_in_L'(2) (*‹(L'::nat set) ≠ {}›*) by (auto simp add: sup_acc_def (*‹sup_acc ?step ?accept ?rho ?q ?i ?j = (let L' = {l ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*)) qed lemma sup_acc_None: "i < j ⟹ sup_acc step accept rho q i j = None ⟹ sup_acc step accept rho (step q (bs_at rho i)) (i + 1) j = None" using steps_split[of _ _ step rho] (*‹?i < ?j ⟹ steps step rho ?q (?i, ?j) = steps step rho (step ?q (bs_at rho ?i)) (Suc ?i, ?j)›*) by (auto simp add: sup_acc_def (*‹sup_acc ?step ?accept ?rho ?q ?i ?j = (let L' = {l ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) acc_def (*‹acc ?step ?accept ?rho ?q ?ij = ?accept (steps ?step ?rho ?q ?ij)›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) lemma sup_acc_i: "i < j ⟹ sup_acc step accept rho q i j = Some (ts, i) ⟹ sup_acc step accept rho (step q (bs_at rho i)) (Suc i) j = None" proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹⟦i < j; sup_acc step accept rho q i j = Some (ts, i); sup_acc step accept rho (step q (bs_at rho i)) (Suc i) j ≠ None⟧ ⟹ False›*) assume assms: "i < j" "sup_acc step accept rho q i j = Some (ts, i)" "sup_acc step accept rho (step q (bs_at rho i)) (Suc i) j ≠ None" (*‹(i::nat) < (j::nat)› ‹sup_acc (step::'b ⇒ 'c ⇒ 'b) (accept::'b ⇒ bool) (rho::('a × 'c) list) (q::'b) (i::nat) (j::nat) = Some (ts::'a, i)› ‹sup_acc (step::'b ⇒ 'c ⇒ 'b) (accept::'b ⇒ bool) (rho::('a × 'c) list) (step (q::'b) (bs_at rho (i::nat))) (Suc i) (j::nat) ≠ None›*) from assms(3) (*‹sup_acc (step::'b ⇒ 'c ⇒ 'b) (accept::'b ⇒ bool) (rho::('a × 'c) list) (step (q::'b) (bs_at rho (i::nat))) (Suc i) (j::nat) ≠ None›*) obtain l where l_def: "l ∈ {Suc i..<j}" "acc step accept rho (step q (bs_at rho i)) (Suc i, Suc l)" (*goal: ‹(⋀l. ⟦l ∈ {Suc i..<j}; acc step accept rho (step q (bs_at rho i)) (Suc i, Suc l)⟧ ⟹ thesis) ⟹ thesis›*) by (auto simp add: sup_acc_def (*‹sup_acc ?step ?accept ?rho ?q ?i ?j = (let L' = {l ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) define L' where "L' = {l ∈ {i..<j}. acc step accept rho q (i, Suc l)}" from assms(2) (*‹sup_acc step accept rho q i j = Some (ts, i)›*) have L'_props: "finite L'" "L' ≠ {}" "Max L' = i" apply - (*goals: 1. ‹sup_acc (step::'b::type ⇒ 'c::type ⇒ 'b::type) (accept::'b::type ⇒ bool) (rho::('a::type × 'c::type) list) (q::'b::type) (i::nat) (j::nat) = Some (ts::'a::type, i) ⟹ finite (L'::nat set)› 2. ‹sup_acc (step::'b::type ⇒ 'c::type ⇒ 'b::type) (accept::'b::type ⇒ bool) (rho::('a::type × 'c::type) list) (q::'b::type) (i::nat) (j::nat) = Some (ts::'a::type, i) ⟹ (L'::nat set) ≠ {}› 3. ‹sup_acc (step::'b::type ⇒ 'c::type ⇒ 'b::type) (accept::'b::type ⇒ bool) (rho::('a::type × 'c::type) list) (q::'b::type) (i::nat) (j::nat) = Some (ts::'a::type, i) ⟹ Max (L'::nat set) = i› discuss goal 1*) apply ((auto simp add: sup_acc_def (*‹sup_acc ?step ?accept ?rho ?q ?i ?j = (let L' = {l ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*) L'_def (*‹L' = {l ∈ {i..<j}. acc step accept rho q (i, Suc l)}›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto simp add: sup_acc_def (*‹sup_acc (?step::?'c ⇒ ?'b ⇒ ?'c) (?accept::?'c ⇒ bool) (?rho::(?'d × ?'b) list) (?q::?'c) (?i::nat) (?j::nat) = (let L'::nat set = {l::nat ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m::nat = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*) L'_def (*‹(L'::nat set) = {l::nat ∈ {i::nat..<j::nat}. acc (step::'b ⇒ 'c ⇒ 'b) (accept::'b ⇒ bool) (rho::('a × 'c) list) (q::'b) (i, Suc l)}›*) Let_def (*‹Let (?s::?'a) (?f::?'a ⇒ ?'b) ≡ ?f ?s›*) split: if_splits (*‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 3*) apply ((auto simp add: sup_acc_def (*‹sup_acc ?step ?accept ?rho ?q ?i ?j = (let L' = {l ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*) L'_def (*‹L' = {l ∈ {i..<j}. acc step accept rho q (i, Suc l)}›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 3 subgoals*) . have i_lt_l: "i < l" using l_def(1) (*‹l ∈ {Suc i..<j}›*) by auto from l_def (*‹(l::nat) ∈ {Suc (i::nat)..<j::nat}› ‹acc step accept rho (step q (bs_at rho i)) (Suc i, Suc l)›*) have "l ∈ L'" unfolding L'_def acc_def (*goal: ‹l ∈ {l ∈ {i..<j}. accept (steps step rho q (i, Suc l))}›*) using steps_split[OF i_lt_l, of step rho] (*‹steps step rho ?q (i, l) = steps step rho (step ?q (bs_at rho i)) (Suc i, l)›*) by (auto simp: steps_def (*‹steps ?step ?rho ?q ?ij = foldl ?step ?q (sub_bs ?rho ?ij)›*)) then show False using l_def(1) (*‹l ∈ {Suc i..<j}›*) L'_props (*‹finite L'› ‹L' ≠ {}› ‹Max L' = i›*) Max_ge (*‹⟦finite ?A; ?x ∈ ?A⟧ ⟹ ?x ≤ Max ?A›*) i_lt_l (*‹i < l›*) not_le (*‹(¬ ?x ≤ ?y) = (?y < ?x)›*) by auto qed lemma sup_acc_l: "i < j ⟹ i ≠ l ⟹ sup_acc step accept rho q i j = Some (ts, l) ⟹ sup_acc step accept rho q i j = sup_acc step accept rho (step q (bs_at rho i)) (Suc i) j" proof (-) (*goal: ‹⟦(i::nat) < (j::nat); i ≠ (l::nat); sup_acc (step::'b ⇒ 'c ⇒ 'b) (accept::'b ⇒ bool) (rho::('a × 'c) list) (q::'b) i j = Some (ts::'a, l)⟧ ⟹ sup_acc step accept rho q i j = sup_acc step accept rho (step q (bs_at rho i)) (Suc i) j›*) assume assms: "i < j" "i ≠ l" "sup_acc step accept rho q i j = Some (ts, l)" (*‹(i::nat) < (j::nat)› ‹(i::nat) ≠ (l::nat)› ‹sup_acc (step::'b ⇒ 'c ⇒ 'b) (accept::'b ⇒ bool) (rho::('a × 'c) list) (q::'b) (i::nat) (j::nat) = Some (ts::'a, l::nat)›*) define L where "L = {l ∈ {i..<j}. acc step accept rho q (i, Suc l)}" define L' where "L' = {l ∈ {Suc i..<j}. acc step accept rho (step q (bs_at rho i)) (Suc i, Suc l)}" from assms(3) (*‹sup_acc step accept rho q i j = Some (ts, l)›*) have L_props: "finite L" "L ≠ {}" "l = Max L" "sup_acc step accept rho q i j = Some (ts_at rho l, l)" apply - (*goals: 1. ‹sup_acc step accept rho q i j = Some (ts, l) ⟹ finite L› 2. ‹sup_acc step accept rho q i j = Some (ts, l) ⟹ L ≠ {}› 3. ‹sup_acc step accept rho q i j = Some (ts, l) ⟹ l = Max L› 4. ‹sup_acc step accept rho q i j = Some (ts, l) ⟹ sup_acc step accept rho q i j = Some (ts_at rho l, l)› discuss goal 1*) apply ((auto simp add: sup_acc_def (*‹sup_acc (?step::?'c ⇒ ?'b ⇒ ?'c) (?accept::?'c ⇒ bool) (?rho::(?'d × ?'b) list) (?q::?'c) (?i::nat) (?j::nat) = (let L'::nat set = {l::nat ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m::nat = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*) L_def (*‹(L::nat set) = {l::nat ∈ {i::nat..<j::nat}. acc (step::'b ⇒ 'c ⇒ 'b) (accept::'b ⇒ bool) (rho::('a × 'c) list) (q::'b) (i, Suc l)}›*) Let_def (*‹Let (?s::?'a) (?f::?'a ⇒ ?'b) ≡ ?f ?s›*) split: if_splits (*‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto simp add: sup_acc_def (*‹sup_acc (?step::?'c ⇒ ?'b ⇒ ?'c) (?accept::?'c ⇒ bool) (?rho::(?'d × ?'b) list) (?q::?'c) (?i::nat) (?j::nat) = (let L'::nat set = {l::nat ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m::nat = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*) L_def (*‹(L::nat set) = {l::nat ∈ {i::nat..<j::nat}. acc (step::'b ⇒ 'c ⇒ 'b) (accept::'b ⇒ bool) (rho::('a × 'c) list) (q::'b) (i, Suc l)}›*) Let_def (*‹Let (?s::?'a) (?f::?'a ⇒ ?'b) ≡ ?f ?s›*) split: if_splits (*‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 3*) apply ((auto simp add: sup_acc_def (*‹sup_acc (?step::?'c::type ⇒ ?'b::type ⇒ ?'c::type) (?accept::?'c::type ⇒ bool) (?rho::(?'d::type × ?'b::type) list) (?q::?'c::type) (?i::nat) (?j::nat) = (let L'::nat set = {l::nat ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m::nat = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*) L_def (*‹(L::nat set) = {l::nat ∈ {i::nat..<j::nat}. acc (step::'b::type ⇒ 'c::type ⇒ 'b::type) (accept::'b::type ⇒ bool) (rho::('a::type × 'c::type) list) (q::'b::type) (i, Suc l)}›*) Let_def (*‹Let (?s::?'a::type) (?f::?'a::type ⇒ ?'b::type) ≡ ?f ?s›*) split: if_splits (*‹(?P::?'a::type ⇒ bool) (if ?Q::bool then ?x::?'a::type else (?y::?'a::type)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹(?P::?'a::type ⇒ bool) (if ?Q::bool then ?x::?'a::type else (?y::?'a::type)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 4*) apply ((auto simp add: sup_acc_def (*‹sup_acc ?step ?accept ?rho ?q ?i ?j = (let L' = {l ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*) L_def (*‹L = {l ∈ {i..<j}. acc step accept rho q (i, Suc l)}›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 4 subgoals*) . have l_in_L: "l ∈ L" using Max_in[OF L_props ( 1 , 2 )] (*‹Max L ∈ L›*) L_props(3) (*‹l = Max L›*) by auto then have i_lt_l: "i < l" unfolding L_def (*goal: ‹i < l›*) using assms(2) (*‹i ≠ l›*) by auto have l_in_L': "finite L'" "L' ≠ {}" "l ∈ L'" using steps_split[OF i_lt_l, of step rho q] (*‹steps (step::'b ⇒ 'c ⇒ 'b) (rho::('a × 'c) list) (q::'b) (i::nat, l::nat) = steps step rho (step q (bs_at rho i)) (Suc i, l)›*) l_in_L (*‹l ∈ L›*) assms(2) (*‹i ≠ l›*) unfolding L_def L'_def acc_def (*goals: 1. ‹finite {l ∈ {Suc i..<j}. accept (steps step rho (step q (bs_at rho i)) (Suc i, Suc l))}› 2. ‹{l ∈ {Suc i..<j}. accept (steps step rho (step q (bs_at rho i)) (Suc i, Suc l))} ≠ {}› 3. ‹l ∈ {l ∈ {Suc i..<j}. accept (steps step rho (step q (bs_at rho i)) (Suc i, Suc l))}›*) apply - (*goals: 1. ‹⟦steps step rho q (i, l) = steps step rho (step q (bs_at rho i)) (Suc i, l); l ∈ {l ∈ {i..<j}. accept (steps step rho q (i, Suc l))}; i ≠ l⟧ ⟹ finite {l ∈ {Suc i..<j}. accept (steps step rho (step q (bs_at rho i)) (Suc i, Suc l))}› 2. ‹⟦steps step rho q (i, l) = steps step rho (step q (bs_at rho i)) (Suc i, l); l ∈ {l ∈ {i..<j}. accept (steps step rho q (i, Suc l))}; i ≠ l⟧ ⟹ {l ∈ {Suc i..<j}. accept (steps step rho (step q (bs_at rho i)) (Suc i, Suc l))} ≠ {}› 3. ‹⟦steps step rho q (i, l) = steps step rho (step q (bs_at rho i)) (Suc i, l); l ∈ {l ∈ {i..<j}. accept (steps step rho q (i, Suc l))}; i ≠ l⟧ ⟹ l ∈ {l ∈ {Suc i..<j}. accept (steps step rho (step q (bs_at rho i)) (Suc i, Suc l))}› discuss goal 1*) apply ((auto simp: steps_def (*‹steps ?step ?rho ?q ?ij = foldl ?step ?q (sub_bs ?rho ?ij)›*))[1]) (*discuss goal 2*) apply ((auto simp: steps_def (*‹steps ?step ?rho ?q ?ij = foldl ?step ?q (sub_bs ?rho ?ij)›*))[1]) (*discuss goal 3*) apply ((auto simp: steps_def (*‹steps (?step::?'c::type ⇒ ?'b::type ⇒ ?'c::type) (?rho::(?'d::type × ?'b::type) list) (?q::?'c::type) (?ij::nat × nat) = foldl ?step ?q (sub_bs ?rho ?ij)›*))[1]) (*proven 3 subgoals*) . have "⋀l'. l' ∈ L' ⟹ l' ≤ l" proof (-) (*goal: ‹⋀l'. l' ∈ L' ⟹ l' ≤ l›*) fix l' assume assms: "l' ∈ L'" (*‹(l'::nat) ∈ (L'::nat set)›*) have i_lt_l': "i < l'" using assms (*‹l' ∈ L'›*) unfolding L'_def (*goal: ‹(i::nat) < (l'::nat)›*) by auto have "l' ∈ L" using steps_split[OF i_lt_l', of step rho] (*‹steps step rho ?q (i, l') = steps step rho (step ?q (bs_at rho i)) (Suc i, l')›*) assms (*‹l' ∈ L'›*) unfolding L_def L'_def acc_def (*goal: ‹(l'::nat) ∈ {l::nat ∈ {i::nat..<j::nat}. (accept::'b ⇒ bool) (steps (step::'b ⇒ 'c ⇒ 'b) (rho::('a × 'c) list) (q::'b) (i, Suc l))}›*) by (auto simp: steps_def (*‹steps ?step ?rho ?q ?ij = foldl ?step ?q (sub_bs ?rho ?ij)›*)) then show "l' ≤ l" using L_props (*‹finite L› ‹(L::nat set) ≠ {}› ‹l = Max L› ‹sup_acc (step::'b ⇒ 'c ⇒ 'b) (accept::'b ⇒ bool) (rho::('a × 'c) list) (q::'b) (i::nat) (j::nat) = Some (ts_at rho (l::nat), l)›*) by simp qed then have l_sup_L': "Max L' = l" using Max_eq_iff[OF l_in_L' ( 1 , 2 )] (*‹(Max L' = ?m) = (?m ∈ L' ∧ (∀a∈L'. a ≤ ?m))›*) l_in_L'(3) (*‹l ∈ L'›*) by auto then show "sup_acc step accept rho q i j = sup_acc step accept rho (step q (bs_at rho i)) (Suc i) j" unfolding L_props(4) (*goal: ‹Some (ts_at (rho::('a::type × 'c::type) list) (l::nat), l) = sup_acc (step::'b::type ⇒ 'c::type ⇒ 'b::type) (accept::'b::type ⇒ bool) rho (step (q::'b::type) (bs_at rho (i::nat))) (Suc i) (j::nat)›*) unfolding sup_acc_def Let_def (*goal: ‹Some (ts_at rho l, l) = (if {l ∈ {Suc i..<j}. acc step accept rho (step q (bs_at rho i)) (Suc i, Suc l)} = {} then None else Some (ts_at rho (Max {l ∈ {Suc i..<j}. acc step accept rho (step q (bs_at rho i)) (Suc i, Suc l)}), Max {l ∈ {Suc i..<j}. acc step accept rho (step q (bs_at rho i)) (Suc i, Suc l)}))›*) using L'_def (*‹(L'::nat set) = {l::nat ∈ {Suc (i::nat)..<j::nat}. acc (step::'b ⇒ 'c ⇒ 'b) (accept::'b ⇒ bool) (rho::('a × 'c) list) (step (q::'b) (bs_at rho i)) (Suc i, Suc l)}›*) l_in_L'(2,3) (*‹(L'::nat set) ≠ {}› ‹l ∈ L'›*) L_props (*‹finite (L::nat set)› ‹L ≠ {}› ‹l = Max L› ‹sup_acc step accept rho q i j = Some (ts_at rho l, l)›*) unfolding Suc_eq_plus1 (*goal: ‹Some (ts_at rho l, l) = (if {l ∈ {i + 1..<j}. acc step accept rho (step q (bs_at rho i)) (i + 1, l + 1)} = {} then None else Some (ts_at rho (Max {l ∈ {i + 1..<j}. acc step accept rho (step q (bs_at rho i)) (i + 1, l + 1)}), Max {l ∈ {i + 1..<j}. acc step accept rho (step q (bs_at rho i)) (i + 1, l + 1)}))›*) by auto qed lemma sup_leadsto_idle: "i < j ⟹ steps step rho init (i, j) ≠ q ⟹ sup_leadsto init step rho i j q = sup_leadsto init step rho (i + 1) j q" proof (-) (*goal: ‹⟦i < j; steps step rho init (i, j) ≠ q⟧ ⟹ sup_leadsto init step rho i j q = sup_leadsto init step rho (i + 1) j q›*) assume assms: "i < j" "steps step rho init (i, j) ≠ q" (*‹(i::nat) < (j::nat)› ‹steps (step::'a ⇒ 'b ⇒ 'a) (rho::('c × 'b) list) (init::'a) (i::nat, j::nat) ≠ (q::'a)›*) define L where "L = {l. l < i ∧ steps step rho init (l, j) = q}" define L' where "L' = {l. l < i + 1 ∧ steps step rho init (l, j) = q}" have L_L': "L = L'" unfolding L_def L'_def (*goal: ‹{l. l < i ∧ steps step rho init (l, j) = q} = {l. l < i + 1 ∧ steps step rho init (l, j) = q}›*) using assms(2) (*‹steps (step::'a ⇒ 'b ⇒ 'a) (rho::('c × 'b) list) (init::'a) (i::nat, j::nat) ≠ (q::'a)›*) less_antisym (*‹⟦¬ ?n < ?m; ?n < Suc ?m⟧ ⟹ ?m = ?n›*) by fastforce show "sup_leadsto init step rho i j q = sup_leadsto init step rho (i + 1) j q" using L_def (*‹L = {l. l < i ∧ steps step rho init (l, j) = q}›*) L'_def (*‹L' = {l. l < i + 1 ∧ steps step rho init (l, j) = q}›*) L_L' (*‹L = L'›*) by (auto simp add: sup_leadsto_def (*‹sup_leadsto ?init ?step ?rho ?i ?j ?q = (let L' = {l. l < ?i ∧ steps ?step ?rho ?init (l, ?j) = ?q}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m))›*)) qed lemma sup_leadsto_SomeI: "l < i ⟹ steps step rho init (l, j) = q ⟹ ∃l'. sup_leadsto init step rho i j q = Some (ts_at rho l') ∧ l ≤ l' ∧ l' < i" proof (-) (*goal: ‹⟦l < i; steps step rho init (l, j) = q⟧ ⟹ ∃l'. sup_leadsto init step rho i j q = Some (ts_at rho l') ∧ l ≤ l' ∧ l' < i›*) assume assms: "l < i" "steps step rho init (l, j) = q" (*‹(l::nat) < (i::nat)› ‹steps (step::'a ⇒ 'b ⇒ 'a) (rho::('c × 'b) list) (init::'a) (l::nat, j::nat) = (q::'a)›*) define L' where "L' = {l. l < i ∧ steps step rho init (l, j) = q}" have fin_L': "finite L'" unfolding L'_def (*goal: ‹finite {l. l < i ∧ steps step rho init (l, j) = q}›*) by auto moreover have L_nonempty: "L' ≠ {}" using assms (*‹(l::nat) < (i::nat)› ‹steps (step::'a::type ⇒ 'b::type ⇒ 'a::type) (rho::('c::type × 'b::type) list) (init::'a::type) (l::nat, j::nat) = (q::'a::type)›*) unfolding L'_def (*goal: ‹{l. l < i ∧ steps step rho init (l, j) = q} ≠ {}›*) by (auto simp add: sup_leadsto_def (*‹sup_leadsto ?init ?step ?rho ?i ?j ?q = (let L' = {l. l < ?i ∧ steps ?step ?rho ?init (l, ?j) = ?q}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m))›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) ultimately have "Max L' ∈ L'" using Max_in (*‹⟦finite ?A; ?A ≠ {}⟧ ⟹ Max ?A ∈ ?A›*) by auto then show "∃l'. sup_leadsto init step rho i j q = Some (ts_at rho l') ∧ l ≤ l' ∧ l' < i" using L'_def (*‹L' = {l. l < i ∧ steps step rho init (l, j) = q}›*) L_nonempty (*‹(L'::nat set) ≠ {}›*) assms (*‹(l::nat) < (i::nat)› ‹steps step rho init (l, j) = q›*) by (fastforce simp add: sup_leadsto_def (*‹sup_leadsto ?init ?step ?rho ?i ?j ?q = (let L' = {l. l < ?i ∧ steps ?step ?rho ?init (l, ?j) = ?q}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m))›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) qed lemma sup_leadsto_SomeE: "i ≤ j ⟹ sup_leadsto init step rho i j q = Some ts ⟹ ∃l < i. steps step rho init (l, j) = q ∧ ts_at rho l = ts" proof (-) (*goal: ‹⟦(i::nat) ≤ (j::nat); sup_leadsto (init::'b) (step::'b ⇒ 'c ⇒ 'b) (rho::('a × 'c) list) i j (q::'b) = Some (ts::'a)⟧ ⟹ ∃l<i. steps step rho init (l, j) = q ∧ ts_at rho l = ts›*) assume assms: "i ≤ j" "sup_leadsto init step rho i j q = Some ts" (*‹(i::nat) ≤ (j::nat)› ‹sup_leadsto (init::'b) (step::'b ⇒ 'c ⇒ 'b) (rho::('a × 'c) list) (i::nat) (j::nat) (q::'b) = Some (ts::'a)›*) define L' where "L' = {l. l < i ∧ steps step rho init (l, j) = q}" have fin_L': "finite L'" unfolding L'_def (*goal: ‹finite {l. l < i ∧ steps step rho init (l, j) = q}›*) by auto moreover have L_nonempty: "L' ≠ {}" using assms(2) (*‹sup_leadsto init step rho i j q = Some ts›*) unfolding L'_def (*goal: ‹{l. l < i ∧ steps step rho init (l, j) = q} ≠ {}›*) by (auto simp add: sup_leadsto_def (*‹sup_leadsto ?init ?step ?rho ?i ?j ?q = (let L' = {l. l < ?i ∧ steps ?step ?rho ?init (l, ?j) = ?q}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m))›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) ultimately have "Max L' ∈ L'" using Max_in (*‹⟦finite ?A; ?A ≠ {}⟧ ⟹ Max ?A ∈ ?A›*) by auto then show "∃l < i. steps step rho init (l, j) = q ∧ ts_at rho l = ts" using assms(2) (*‹sup_leadsto (init::'b) (step::'b ⇒ 'c ⇒ 'b) (rho::('a × 'c) list) (i::nat) (j::nat) (q::'b) = Some (ts::'a)›*) L'_def (*‹(L'::nat set) = {l::nat. l < (i::nat) ∧ steps (step::'b ⇒ 'c ⇒ 'b) (rho::('a × 'c) list) (init::'b) (l, j::nat) = (q::'b)}›*) apply (auto simp add: sup_leadsto_def (*‹sup_leadsto ?init ?step ?rho ?i ?j ?q = (let L' = {l. l < ?i ∧ steps ?step ?rho ?init (l, ?j) = ?q}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m))›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) (*goal: ‹∃l<i. steps step rho init (l, j) = q ∧ ts_at rho l = ts›*) using ‹Max L' ∈ L'› (*‹Max L' ∈ L'›*) by blast qed lemma Mapping_keys_dest: "x ∈ mmap_keys f ⟹ ∃y. mmap_lookup f x = Some y" by (auto simp add: mmap_keys_def (*‹mmap_keys (?kvs::(?'a × ?'b) list) = set (map fst ?kvs)›*) mmap_lookup_def (*‹mmap_lookup = map_of›*) weak_map_of_SomeI (*‹(?k::?'a, ?x::?'b) ∈ set (?l::(?'a × ?'b) list) ⟹ ∃x::?'b. map_of ?l ?k = Some x›*)) lemma Mapping_keys_intro: "mmap_lookup f x ≠ None ⟹ x ∈ mmap_keys f" apply (auto simp add: mmap_keys_def (*‹mmap_keys ?kvs = set (map fst ?kvs)›*) mmap_lookup_def (*‹mmap_lookup = map_of›*)) (*goal: ‹mmap_lookup f x ≠ None ⟹ x ∈ mmap_keys f›*) by (metis map_of_eq_None_iff (*‹(map_of (?xys::(?'b × ?'a) list) (?x::?'b) = None) = (?x ∉ fst ` set ?xys)›*) option.distinct( (*‹None ≠ Some (?x2.0::?'a)›*) 1)) lemma Mapping_not_keys_intro: "mmap_lookup f x = None ⟹ x ∉ mmap_keys f" unfolding mmap_lookup_def mmap_keys_def (*goal: ‹map_of (f::('b × 'a) list) (x::'b) = None ⟹ x ∉ set (map fst f)›*) using weak_map_of_SomeI (*‹(?k, ?x) ∈ set ?l ⟹ ∃x. map_of ?l ?k = Some x›*) by force lemma Mapping_lookup_None_intro: "x ∉ mmap_keys f ⟹ mmap_lookup f x = None" unfolding mmap_lookup_def mmap_keys_def (*goal: ‹(x::'a::type) ∉ set (map fst (f::('a::type × 'b::type) list)) ⟹ map_of f x = None›*) by (simp add: map_of_eq_None_iff (*‹(map_of ?xys ?x = None) = (?x ∉ fst ` set ?xys)›*)) primrec mmap_combine :: "'key ⇒ 'val ⇒ ('val ⇒ 'val ⇒ 'val) ⇒ ('key × 'val) list ⇒ ('key × 'val) list" where "mmap_combine k v c [] = [(k, v)]" | "mmap_combine k v c (p # ps) = (case p of (k', v') ⇒ if k = k' then (k, c v' v) # ps else p # mmap_combine k v c ps)" lemma mmap_combine_distinct_set: "distinct (map fst r) ⟹ distinct (map fst (mmap_combine k v c r)) ∧ set (map fst (mmap_combine k v c r)) = set (map fst r) ∪ {k}" apply (induction r) (*goals: 1. ‹distinct (map fst []) ⟹ distinct (map fst (mmap_combine k v c [])) ∧ set (map fst (mmap_combine k v c [])) = set (map fst []) ∪ {k}› 2. ‹⋀a r. ⟦distinct (map fst r) ⟹ distinct (map fst (mmap_combine k v c r)) ∧ set (map fst (mmap_combine k v c r)) = set (map fst r) ∪ {k}; distinct (map fst (a # r))⟧ ⟹ distinct (map fst (mmap_combine k v c (a # r))) ∧ set (map fst (mmap_combine k v c (a # r))) = set (map fst (a # r)) ∪ {k}› discuss goal 1*) apply force (*discuss goal 2*) apply force (*proven 2 subgoals*) . lemma mmap_combine_lookup: "distinct (map fst r) ⟹ mmap_lookup (mmap_combine k v c r) z = (if k = z then (case mmap_lookup r k of None ⇒ Some v | Some v' ⇒ Some (c v' v)) else mmap_lookup r z)" using eq_key_imp_eq_value (*‹⟦distinct (map fst ?xs); (?k, ?v1.0) ∈ set ?xs; (?k, ?v2.0) ∈ set ?xs⟧ ⟹ ?v1.0 = ?v2.0›*) apply (induction r) (*goals: 1. ‹⟦distinct (map fst []); ⋀xs k v1 v2. ⟦distinct (map fst xs); (k, v1) ∈ set xs; (k, v2) ∈ set xs⟧ ⟹ v1 = v2⟧ ⟹ mmap_lookup (mmap_combine k v c []) z = (if k = z then case mmap_lookup [] k of None ⇒ Some v | Some v' ⇒ Some (c v' v) else mmap_lookup [] z)› 2. ‹⋀a r. ⟦⟦distinct (map fst r); ⋀xs k v1 v2. ⟦distinct (map fst xs); (k, v1) ∈ set xs; (k, v2) ∈ set xs⟧ ⟹ v1 = v2⟧ ⟹ mmap_lookup (mmap_combine k v c r) z = (if k = z then case mmap_lookup r k of None ⇒ Some v | Some v' ⇒ Some (c v' v) else mmap_lookup r z); distinct (map fst (a # r)); ⋀xs k v1 v2. ⟦distinct (map fst xs); (k, v1) ∈ set xs; (k, v2) ∈ set xs⟧ ⟹ v1 = v2⟧ ⟹ mmap_lookup (mmap_combine k v c (a # r)) z = (if k = z then case mmap_lookup (a # r) k of None ⇒ Some v | Some v' ⇒ Some (c v' v) else mmap_lookup (a # r) z)› discuss goal 1*) apply (fastforce simp: mmap_lookup_def (*‹mmap_lookup = map_of›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) (*discuss goal 2*) apply (fastforce simp: mmap_lookup_def (*‹mmap_lookup = map_of›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) (*proven 2 subgoals*) . definition mmap_fold :: "('c, 'd) mmap ⇒ (('c × 'd) ⇒ ('c × 'd)) ⇒ ('d ⇒ 'd ⇒ 'd) ⇒ ('c, 'd) mmap ⇒ ('c, 'd) mmap" where "mmap_fold m f c r = foldl (λr p. case f p of (k, v) ⇒ mmap_combine k v c r) r m" definition mmap_fold' :: "('c, 'd) mmap ⇒ 'e ⇒ (('c × 'd) × 'e ⇒ ('c × 'd) × 'e) ⇒ ('d ⇒ 'd ⇒ 'd) ⇒ ('c, 'd) mmap ⇒ ('c, 'd) mmap × 'e" where "mmap_fold' m e f c r = foldl (λ(r, e) p. case f (p, e) of ((k, v), e') ⇒ (mmap_combine k v c r, e')) (r, e) m" lemma mmap_fold'_eq: "mmap_fold' m e f' c r = (m', e') ⟹ P e ⟹ (⋀p e p' e'. P e ⟹ f' (p, e) = (p', e') ⟹ p' = f p ∧ P e') ⟹ m' = mmap_fold m f c r ∧ P e'" proof (induction m arbitrary: e r m' e') (*goals: 1. ‹⋀(e::'c::type) (r::('a::type × 'b::type) list) (m'::('a::type × 'b::type) list) e'::'c::type. ⟦mmap_fold' [] e (f'::('a::type × 'b::type) × 'c::type ⇒ ('a::type × 'b::type) × 'c::type) (c::'b::type ⇒ 'b::type ⇒ 'b::type) r = (m', e'); (P::'c::type ⇒ bool) e; ⋀(p::'a::type × 'b::type) (e::'c::type) (p'::'a::type × 'b::type) e'::'c::type. ⟦P e; f' (p, e) = (p', e')⟧ ⟹ p' = (f::'a::type × 'b::type ⇒ 'a::type × 'b::type) p ∧ P e'⟧ ⟹ m' = mmap_fold [] f c r ∧ P e'› 2. ‹⋀(a::'a::type × 'b::type) (m::('a::type × 'b::type) list) (e::'c::type) (r::('a::type × 'b::type) list) (m'::('a::type × 'b::type) list) e'::'c::type. ⟦⋀(e::'c::type) (r::('a::type × 'b::type) list) (m'::('a::type × 'b::type) list) e'::'c::type. ⟦mmap_fold' m e (f'::('a::type × 'b::type) × 'c::type ⇒ ('a::type × 'b::type) × 'c::type) (c::'b::type ⇒ 'b::type ⇒ 'b::type) r = (m', e'); (P::'c::type ⇒ bool) e; ⋀(p::'a::type × 'b::type) (e::'c::type) (p'::'a::type × 'b::type) e'::'c::type. ⟦P e; f' (p, e) = (p', e')⟧ ⟹ p' = (f::'a::type × 'b::type ⇒ 'a::type × 'b::type) p ∧ P e'⟧ ⟹ m' = mmap_fold m f c r ∧ P e'; mmap_fold' (a # m) e f' c r = (m', e'); P e; ⋀(p::'a::type × 'b::type) (e::'c::type) (p'::'a::type × 'b::type) e'::'c::type. ⟦P e; f' (p, e) = (p', e')⟧ ⟹ p' = f p ∧ P e'⟧ ⟹ m' = mmap_fold (a # m) f c r ∧ P e'›*) case (Cons p m) (*‹⟦mmap_fold' m ?e f' c ?r = (?m', ?e'); P ?e; ⋀p e p' e'. ⟦P e; f' (p, e) = (p', e')⟧ ⟹ p' = f p ∧ P e'⟧ ⟹ ?m' = mmap_fold m f c ?r ∧ P ?e'› ‹mmap_fold' ((p::'a × 'b) # (m::('a × 'b) list)) (e::'c) (f'::('a × 'b) × 'c ⇒ ('a × 'b) × 'c) (c::'b ⇒ 'b ⇒ 'b) (r::('a × 'b) list) = (m'::('a × 'b) list, e'::'c)› ‹(P::'c::type ⇒ bool) (e::'c::type)› ‹⟦P ?e; f' (?p, ?e) = (?p', ?e')⟧ ⟹ ?p' = f ?p ∧ P ?e'›*) obtain k and v and e'' where kv_def: "f' (p, e) = ((k, v), e'')" "P e''" (*goal: ‹(⋀k v e''. ⟦f' (p, e) = ((k, v), e''); P e''⟧ ⟹ thesis) ⟹ thesis›*) using Cons (*‹⟦mmap_fold' m ?e f' c ?r = (?m', ?e'); P ?e; ⋀p e p' e'. ⟦P e; f' (p, e) = (p', e')⟧ ⟹ p' = f p ∧ P e'⟧ ⟹ ?m' = mmap_fold m f c ?r ∧ P ?e'› ‹mmap_fold' (p # m) e f' c r = (m', e')› ‹P e› ‹⟦(P::'c ⇒ bool) (?e::'c); (f'::('a × 'b) × 'c ⇒ ('a × 'b) × 'c) (?p::'a × 'b, ?e) = (?p'::'a × 'b, ?e'::'c)⟧ ⟹ ?p' = (f::'a × 'b ⇒ 'a × 'b) ?p ∧ P ?e'›*) apply (cases "f' (p, e)") (*goal: ‹(⋀k v e''. ⟦f' (p, e) = ((k, v), e''); P e''⟧ ⟹ thesis) ⟹ thesis›*) by fastforce have mmap_fold: "mmap_fold m f c (mmap_combine k v c r) = mmap_fold (p # m) f c r" using Cons(1)[OF _ kv_def ( 2 ), where ?r = "mmap_combine k v c r"] (*‹⟦mmap_fold' m e'' f' c (mmap_combine k v c r) = (?m', ?e'); ⋀p e p' e'. ⟦P e; f' (p, e) = (p', e')⟧ ⟹ p' = f p ∧ P e'⟧ ⟹ ?m' = mmap_fold m f c (mmap_combine k v c r) ∧ P ?e'›*) Cons(2,3,4) (*‹mmap_fold' (p # m) e f' c r = (m', e')› ‹P e› ‹⟦P ?e; f' (?p, ?e) = (?p', ?e')⟧ ⟹ ?p' = f ?p ∧ P ?e'›*) by (simp add: mmap_fold_def (*‹mmap_fold ?m ?f ?c ?r = foldl (λr p. case ?f p of (k, v) ⇒ mmap_combine k v ?c r) ?r ?m›*) mmap_fold'_def (*‹mmap_fold' ?m ?e ?f ?c ?r = foldl (λ(r, e) p. case ?f (p, e) of ((k, v), e') ⇒ (mmap_combine k v ?c r, e')) (?r, ?e) ?m›*) kv_def( (*‹f' (p, e) = ((k, v), e'')›*) 1)) have mmap_fold': "mmap_fold' m e'' f' c (mmap_combine k v c r) = (m', e')" using Cons(2) (*‹mmap_fold' ((p::'a × 'b) # (m::('a × 'b) list)) (e::'c) (f'::('a × 'b) × 'c ⇒ ('a × 'b) × 'c) (c::'b ⇒ 'b ⇒ 'b) (r::('a × 'b) list) = (m'::('a × 'b) list, e'::'c)›*) by (auto simp: mmap_fold'_def (*‹mmap_fold' (?m::(?'c × ?'d) list) (?e::?'e) (?f::(?'c × ?'d) × ?'e ⇒ (?'c × ?'d) × ?'e) (?c::?'d ⇒ ?'d ⇒ ?'d) (?r::(?'c × ?'d) list) = foldl (λ(r::(?'c × ?'d) list, e::?'e) p::?'c × ?'d. case ?f (p, e) of ((k::?'c, v::?'d), e'::?'e) ⇒ (mmap_combine k v ?c r, e')) (?r, ?e) ?m›*) kv_def (*‹(f'::('a × 'b) × 'c ⇒ ('a × 'b) × 'c) (p::'a × 'b, e::'c) = ((k::'a, v::'b), e''::'c)› ‹(P::'c ⇒ bool) (e''::'c)›*)) show "?case" (*goal: ‹(m'::('a × 'b) list) = mmap_fold ((p::'a × 'b) # (m::('a × 'b) list)) (f::'a × 'b ⇒ 'a × 'b) (c::'b ⇒ 'b ⇒ 'b) (r::('a × 'b) list) ∧ (P::'c ⇒ bool) (e'::'c)›*) using Cons(1)[OF mmap_fold' kv_def ( 2 ) Cons ( 4 )] (*‹⟦⋀p e p' e'. ⟦P e; f' (p, e) = (p', e')⟧ ⟹ P (?e1 p e p' e'); ⋀p e p' e'. ⟦P e; f' (p, e) = (p', e')⟧ ⟹ f' (p, ?e1 p e p' e') = (p', e')⟧ ⟹ m' = mmap_fold m f c (mmap_combine k v c r) ∧ P e'›*) unfolding mmap_fold (*goal: ‹(m'::('a × 'b) list) = mmap_fold ((p::'a × 'b) # (m::('a × 'b) list)) (f::'a × 'b ⇒ 'a × 'b) (c::'b ⇒ 'b ⇒ 'b) (r::('a × 'b) list) ∧ (P::'c ⇒ bool) (e'::'c)›*) by auto qed (auto simp: mmap_fold_def (*‹mmap_fold ?m ?f ?c ?r = foldl (λr p. case ?f p of (k, v) ⇒ mmap_combine k v ?c r) ?r ?m›*) mmap_fold'_def (*‹mmap_fold' ?m ?e ?f ?c ?r = foldl (λ(r, e) p. case ?f (p, e) of ((k, v), e') ⇒ (mmap_combine k v ?c r, e')) (?r, ?e) ?m›*)) (*solved the remaining goal: ‹⋀e r m' e'. ⟦mmap_fold' [] e f' c r = (m', e'); P e; ⋀p e p' e'. ⟦P e; f' (p, e) = (p', e')⟧ ⟹ p' = f p ∧ P e'⟧ ⟹ m' = mmap_fold [] f c r ∧ P e'›*) lemma foldl_mmap_combine_distinct_set: "distinct (map fst r) ⟹ distinct (map fst (mmap_fold m f c r)) ∧ set (map fst (mmap_fold m f c r)) = set (map fst r) ∪ set (map (fst ∘ f) m)" apply (induction m arbitrary: r) (*goal: ‹distinct (map fst r) ⟹ distinct (map fst (mmap_fold m f c r)) ∧ set (map fst (mmap_fold m f c r)) = set (map fst r) ∪ set (map (fst ∘ f) m)›*) using mmap_combine_distinct_set (*‹distinct (map fst (?r::(?'a × ?'b) list)) ⟹ distinct (map fst (mmap_combine (?k::?'a) (?v::?'b) (?c::?'b ⇒ ?'b ⇒ ?'b) ?r)) ∧ set (map fst (mmap_combine ?k ?v ?c ?r)) = set (map fst ?r) ∪ {?k}›*) apply (auto simp: mmap_fold_def (*‹mmap_fold ?m ?f ?c ?r = foldl (λr p. case ?f p of (k, v) ⇒ mmap_combine k v ?c r) ?r ?m›*) split: prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*)) (*top goal: ‹⋀r. distinct (map fst r) ⟹ distinct (map fst (mmap_fold [] f c r)) ∧ set (map fst (mmap_fold [] f c r)) = set (map fst r) ∪ set (map (fst ∘ f) [])› and 1 goal remains*) apply force (*top goal: ‹⋀(a::'a::type) (b::'b::type) (m::('a::type × 'b::type) list) (r::('a::type × 'b::type) list) (x1::'a::type) x2::'b::type. ⟦⋀r::('a::type × 'b::type) list. distinct (map fst r) ⟹ distinct (map fst (foldl (λ(r::('a::type × 'b::type) list) p::'a::type × 'b::type. case (f::'a::type × 'b::type ⇒ 'a::type × 'b::type) p of (k::'a::type, v::'b::type) ⇒ mmap_combine k v (c::'b::type ⇒ 'b::type ⇒ 'b::type) r) r m)) ∧ fst ` set (foldl (λ(r::('a::type × 'b::type) list) p::'a::type × 'b::type. case f p of (k::'a::type, v::'b::type) ⇒ mmap_combine k v c r) r m) = fst ` set r ∪ (λx::'a::type × 'b::type. fst (f x)) ` set m; distinct (map fst r); ⋀(r::(?'a2::type × ?'b2::type) list) (k::?'a2::type) (v::?'b2::type) c::?'b2::type ⇒ ?'b2::type ⇒ ?'b2::type. distinct (map fst r) ⟹ distinct (map fst (mmap_combine k v c r)) ∧ fst ` set (mmap_combine k v c r) = insert k (fst ` set r); f (a, b) = (x1, x2)⟧ ⟹ distinct (map fst (foldl (λ(r::('a::type × 'b::type) list) p::'a::type × 'b::type. case f p of (k::'a::type, v::'b::type) ⇒ mmap_combine k v c r) (mmap_combine x1 x2 c r) m))› and 4 goals remain*) apply (smt Un_iff (*‹(?c ∈ ?A ∪ ?B) = (?c ∈ ?A ∨ ?c ∈ ?B)›*) fst_conv (*‹fst (?x1.0, ?x2.0) = ?x1.0›*) imageI (*‹?x ∈ ?A ⟹ ?f ?x ∈ ?f ` ?A›*) insert_iff (*‹(?a ∈ insert ?b ?A) = (?a = ?b ∨ ?a ∈ ?A)›*)) (*top goal: ‹⋀a b m r x1 x2 aa ba. ⟦⋀r. distinct (map fst r) ⟹ distinct (map fst (foldl (λr p. case f p of (k, v) ⇒ mmap_combine k v c r) r m)) ∧ fst ` set (foldl (λr p. case f p of (k, v) ⇒ mmap_combine k v c r) r m) = fst ` set r ∪ (λx. fst (f x)) ` set m; distinct (map fst r); ⋀r k v c. distinct (map fst r) ⟹ distinct (map fst (mmap_combine k v c r)) ∧ fst ` set (mmap_combine k v c r) = insert k (fst ` set r); f (a, b) = (x1, x2); (aa, ba) ∈ set (foldl (λr p. case f p of (k, v) ⇒ mmap_combine k v c r) (mmap_combine x1 x2 c r) m); aa ≠ x1; aa ∉ (λx. fst (f x)) ` set m⟧ ⟹ aa ∈ fst ` set r› and 3 goals remain*) using mk_disjoint_insert (*‹(?a::?'a) ∈ (?A::?'a set) ⟹ ∃B::?'a set. ?A = insert ?a B ∧ ?a ∉ B›*) apply - (*goals: 1. ‹⋀a b m r x1 x2. ⟦⋀r. distinct (map fst r) ⟹ distinct (map fst (foldl (λr p. case f p of (k, v) ⇒ mmap_combine k v c r) r m)) ∧ fst ` set (foldl (λr p. case f p of (k, v) ⇒ mmap_combine k v c r) r m) = fst ` set r ∪ (λx. fst (f x)) ` set m; distinct (map fst r); ⋀r k v c. distinct (map fst r) ⟹ distinct (map fst (mmap_combine k v c r)) ∧ fst ` set (mmap_combine k v c r) = insert k (fst ` set r); f (a, b) = (x1, x2); ⋀a A. a ∈ A ⟹ ∃B. A = insert a B ∧ a ∉ B⟧ ⟹ x1 ∈ fst ` set (foldl (λr p. case f p of (k, v) ⇒ mmap_combine k v c r) (mmap_combine x1 x2 c r) m)› 2. ‹⋀a b m r x1 x2 aa ba. ⟦⋀r. distinct (map fst r) ⟹ distinct (map fst (foldl (λr p. case f p of (k, v) ⇒ mmap_combine k v c r) r m)) ∧ fst ` set (foldl (λr p. case f p of (k, v) ⇒ mmap_combine k v c r) r m) = fst ` set r ∪ (λx. fst (f x)) ` set m; distinct (map fst r); ⋀r k v c. distinct (map fst r) ⟹ distinct (map fst (mmap_combine k v c r)) ∧ fst ` set (mmap_combine k v c r) = insert k (fst ` set r); f (a, b) = (x1, x2); (aa, ba) ∈ set r; ⋀a A. a ∈ A ⟹ ∃B. A = insert a B ∧ a ∉ B⟧ ⟹ aa ∈ fst ` set (foldl (λr p. case f p of (k, v) ⇒ mmap_combine k v c r) (mmap_combine x1 x2 c r) m)› 3. ‹⋀a b m r x1 x2 aa ba. ⟦⋀r. distinct (map fst r) ⟹ distinct (map fst (foldl (λr p. case f p of (k, v) ⇒ mmap_combine k v c r) r m)) ∧ fst ` set (foldl (λr p. case f p of (k, v) ⇒ mmap_combine k v c r) r m) = fst ` set r ∪ (λx. fst (f x)) ` set m; distinct (map fst r); ⋀r k v c. distinct (map fst r) ⟹ distinct (map fst (mmap_combine k v c r)) ∧ fst ` set (mmap_combine k v c r) = insert k (fst ` set r); f (a, b) = (x1, x2); (aa, ba) ∈ set m; ⋀a A. a ∈ A ⟹ ∃B. A = insert a B ∧ a ∉ B⟧ ⟹ fst (f (aa, ba)) ∈ fst ` set (foldl (λr p. case f p of (k, v) ⇒ mmap_combine k v c r) (mmap_combine x1 x2 c r) m)› discuss goal 1*) apply fastforce (*discuss goal 2*) apply fastforce (*discuss goal 3*) apply fastforce (*proven 3 subgoals*) . lemma mmap_fold_lookup_rec: "distinct (map fst r) ⟹ mmap_lookup (mmap_fold m f c r) z = (case map (snd ∘ f) (filter (λ(k, v). fst (f (k, v)) = z) m) of [] ⇒ mmap_lookup r z | v # vs ⇒ (case mmap_lookup r z of None ⇒ Some (foldl c v vs) | Some w ⇒ Some (foldl c w (v # vs))))" proof (induction m arbitrary: r) (*goals: 1. ‹⋀r. distinct (map fst r) ⟹ mmap_lookup (mmap_fold [] f c r) z = (case map (snd ∘ f) (filter (λ(k, v). fst (f (k, v)) = z) []) of [] ⇒ mmap_lookup r z | v # vs ⇒ case mmap_lookup r z of None ⇒ Some (foldl c v vs) | Some w ⇒ Some (foldl c w (v # vs)))› 2. ‹⋀a m r. ⟦⋀r. distinct (map fst r) ⟹ mmap_lookup (mmap_fold m f c r) z = (case map (snd ∘ f) (filter (λ(k, v). fst (f (k, v)) = z) m) of [] ⇒ mmap_lookup r z | v # vs ⇒ case mmap_lookup r z of None ⇒ Some (foldl c v vs) | Some w ⇒ Some (foldl c w (v # vs))); distinct (map fst r)⟧ ⟹ mmap_lookup (mmap_fold (a # m) f c r) z = (case map (snd ∘ f) (filter (λ(k, v). fst (f (k, v)) = z) (a # m)) of [] ⇒ mmap_lookup r z | v # vs ⇒ case mmap_lookup r z of None ⇒ Some (foldl c v vs) | Some w ⇒ Some (foldl c w (v # vs)))›*) case (Cons p ps) (*‹distinct (map fst ?r) ⟹ mmap_lookup (mmap_fold ps f c ?r) z = (case map (snd ∘ f) (filter (λa. case a of (k, v) ⇒ fst (f (k, v)) = z) ps) of [] ⇒ mmap_lookup ?r z | v # vs ⇒ case mmap_lookup ?r z of None ⇒ Some (foldl c v vs) | Some w ⇒ Some (foldl c w (v # vs)))› ‹distinct (map fst r)›*) obtain k and v where kv_def: "f p = (k, v)" (*goal: ‹(⋀(k::'a) v::'b. (f::'a × 'b ⇒ 'a × 'b) (p::'a × 'b) = (k, v) ⟹ thesis::bool) ⟹ thesis›*) by fastforce have distinct: "distinct (map fst (mmap_combine k v c r))" using mmap_combine_distinct_set[OF Cons ( 2 )] (*‹distinct (map fst (mmap_combine ?k ?v ?c r)) ∧ set (map fst (mmap_combine ?k ?v ?c r)) = set (map fst r) ∪ {?k}›*) by auto show "?case" (*goal: ‹mmap_lookup (mmap_fold (p # ps) f c r) z = (case map (snd ∘ f) (filter (λa. case a of (k, v) ⇒ fst (f (k, v)) = z) (p # ps)) of [] ⇒ mmap_lookup r z | v # vs ⇒ case mmap_lookup r z of None ⇒ Some (foldl c v vs) | Some w ⇒ Some (foldl c w (v # vs)))›*) using Cons(1)[OF distinct, unfolded mmap_combine_lookup [ OF Cons ( 2 ) ]] (*‹mmap_lookup (mmap_fold ps f c (mmap_combine k v c r)) z = (case map (snd ∘ f) (filter (λa. case a of (k, v) ⇒ fst (f (k, v)) = z) ps) of [] ⇒ if k = z then case mmap_lookup r k of None ⇒ Some v | Some v' ⇒ Some (c v' v) else mmap_lookup r z | va # vs ⇒ case if k = z then case mmap_lookup r k of None ⇒ Some v | Some v' ⇒ Some (c v' v) else mmap_lookup r z of None ⇒ Some (foldl c va vs) | Some w ⇒ Some (foldl c w (va # vs)))›*) by (auto simp: mmap_lookup_def (*‹mmap_lookup = map_of›*) kv_def (*‹f p = (k, v)›*) mmap_fold_def (*‹mmap_fold ?m ?f ?c ?r = foldl (λr p. case ?f p of (k, v) ⇒ mmap_combine k v ?c r) ?r ?m›*) split: list.splits (*‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = ((?list = [] ⟶ ?P ?f1.0) ∧ (∀x21 x22. ?list = x21 # x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = (¬ (?list = [] ∧ ¬ ?P ?f1.0 ∨ (∃x21 x22. ?list = x21 # x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*) option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) qed (auto simp: mmap_fold_def (*‹mmap_fold ?m ?f ?c ?r = foldl (λr p. case ?f p of (k, v) ⇒ mmap_combine k v ?c r) ?r ?m›*)) (*solved the remaining goal: ‹⋀r. distinct (map fst r) ⟹ mmap_lookup (mmap_fold [] f c r) z = (case map (snd ∘ f) (filter (λ(k, v). fst (f (k, v)) = z) []) of [] ⇒ mmap_lookup r z | v # vs ⇒ case mmap_lookup r z of None ⇒ Some (foldl c v vs) | Some w ⇒ Some (foldl c w (v # vs)))›*) lemma mmap_fold_distinct: "distinct (map fst m) ⟹ distinct (map fst (mmap_fold m f c []))" using foldl_mmap_combine_distinct_set[of "[]"] (*‹distinct (map fst []) ⟹ distinct (map fst (mmap_fold ?m ?f ?c [])) ∧ set (map fst (mmap_fold ?m ?f ?c [])) = set (map fst []) ∪ set (map (fst ∘ ?f) ?m)›*) by auto lemma mmap_fold_set: "distinct (map fst m) ⟹ set (map fst (mmap_fold m f c [])) = (fst ∘ f) ` set m" using foldl_mmap_combine_distinct_set[of "[]"] (*‹distinct (map fst []) ⟹ distinct (map fst (mmap_fold (?m::(?'c1 × ?'d1) list) (?f::?'c1 × ?'d1 ⇒ ?'c1 × ?'d1) (?c::?'d1 ⇒ ?'d1 ⇒ ?'d1) [])) ∧ set (map fst (mmap_fold ?m ?f ?c [])) = set (map fst []) ∪ set (map (fst ∘ ?f) ?m)›*) by force lemma mmap_lookup_empty: "mmap_lookup [] z = None" by (auto simp: mmap_lookup_def (*‹mmap_lookup = map_of›*)) lemma mmap_fold_lookup: "distinct (map fst m) ⟹ mmap_lookup (mmap_fold m f c []) z = (case map (snd ∘ f) (filter (λ(k, v). fst (f (k, v)) = z) m) of [] ⇒ None | v # vs ⇒ Some (foldl c v vs))" using mmap_fold_lookup_rec[of "[]" _ f c] (*‹distinct (map fst []) ⟹ mmap_lookup (mmap_fold ?m f c []) ?z = (case map (snd ∘ f) (filter (λ(k, v). fst (f (k, v)) = ?z) ?m) of [] ⇒ mmap_lookup [] ?z | v # vs ⇒ case mmap_lookup [] ?z of None ⇒ Some (foldl c v vs) | Some w ⇒ Some (foldl c w (v # vs)))›*) by (auto simp: mmap_lookup_empty (*‹mmap_lookup [] ?z = None›*) split: list.splits (*‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = ((?list = [] ⟶ ?P ?f1.0) ∧ (∀x21 x22. ?list = x21 # x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = (¬ (?list = [] ∧ ¬ ?P ?f1.0 ∨ (∃x21 x22. ?list = x21 # x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*)) definition fold_sup :: "('c, 'd :: timestamp) mmap ⇒ ('c ⇒ 'c) ⇒ ('c, 'd) mmap" where "fold_sup m f = mmap_fold m (λ(x, y). (f x, y)) sup []" lemma mmap_lookup_distinct: "distinct (map fst m) ⟹ (k, v) ∈ set m ⟹ mmap_lookup m k = Some v" by (auto simp: mmap_lookup_def (*‹mmap_lookup = map_of›*)) lemma fold_sup_distinct: "distinct (map fst m) ⟹ distinct (map fst (fold_sup m f))" using mmap_fold_distinct (*‹distinct (map fst ?m) ⟹ distinct (map fst (mmap_fold ?m ?f ?c []))›*) by (auto simp: fold_sup_def (*‹fold_sup ?m ?f = mmap_fold ?m (λ(x, y). (?f x, y)) sup []›*)) lemma fold_sup: fixes v :: "'d :: timestamp" shows "foldl sup v vs = fold sup vs v" apply (induction vs arbitrary: v) (*goals: 1. ‹⋀v. foldl sup v [] = fold sup [] v› 2. ‹⋀a vs v. (⋀v. foldl sup v vs = fold sup vs v) ⟹ foldl sup v (a # vs) = fold sup (a # vs) v› discuss goal 1*) apply ((auto simp: sup.commute (*‹sup ?a ?b = sup ?b ?a›*))[1]) (*discuss goal 2*) apply ((auto simp: sup.commute (*‹sup ?a ?b = sup ?b ?a›*))[1]) (*proven 2 subgoals*) . lemma lookup_fold_sup: assumes distinct: "distinct (map fst m)" shows "mmap_lookup (fold_sup m f) z = (let Z = {x ∈ mmap_keys m. f x = z} in if Z = {} then None else Some (Sup_fin ((the ∘ mmap_lookup m) ` Z)))" proof (cases "{x ∈ mmap_keys m. f x = z} = {}") (*goals: 1. ‹{x ∈ mmap_keys m. f x = z} = {} ⟹ mmap_lookup (fold_sup m f) z = (let Z = {x ∈ mmap_keys m. f x = z} in if Z = {} then None else Some (⨆⇩f⇩i⇩n ((the ∘ mmap_lookup m) ` Z)))› 2. ‹{x ∈ mmap_keys m. f x = z} ≠ {} ⟹ mmap_lookup (fold_sup m f) z = (let Z = {x ∈ mmap_keys m. f x = z} in if Z = {} then None else Some (⨆⇩f⇩i⇩n ((the ∘ mmap_lookup m) ` Z)))›*) case True (*‹{x ∈ mmap_keys m. f x = z} = {}›*) have "z ∉ mmap_keys (mmap_fold m (λ(x, y). (f x, y)) sup [])" using True[unfolded mmap_keys_def] (*‹{x ∈ set (map fst m). f x = z} = {}›*) mmap_fold_set[OF distinct] (*‹set (map fst (mmap_fold m ?f ?c [])) = (fst ∘ ?f) ` set m›*) by (auto simp: mmap_keys_def (*‹mmap_keys ?kvs = set (map fst ?kvs)›*)) then have "mmap_lookup (fold_sup m f) z = None" unfolding fold_sup_def (*goal: ‹mmap_lookup (mmap_fold m (λ(x, y). (f x, y)) sup []) z = None›*) by (meson Mapping_keys_intro (*‹mmap_lookup ?f ?x ≠ None ⟹ ?x ∈ mmap_keys ?f›*)) then show "?thesis" (*goal: ‹mmap_lookup (fold_sup m f) z = (let Z = {x ∈ mmap_keys m. f x = z} in if Z = {} then None else Some (⨆⇩f⇩i⇩n ((the ∘ mmap_lookup m) ` Z)))›*) unfolding True (*goal: ‹mmap_lookup (fold_sup m f) z = (let Z = {} in if Z = {} then None else Some (⨆⇩f⇩i⇩n ((the ∘ mmap_lookup m) ` Z)))›*) by auto next (*goal: ‹{x ∈ mmap_keys m. f x = z} ≠ {} ⟹ mmap_lookup (fold_sup m f) z = (let Z = {x ∈ mmap_keys m. f x = z} in if Z = {} then None else Some (⨆⇩f⇩i⇩n ((the ∘ mmap_lookup m) ` Z)))›*) case False (*‹{x::'a ∈ mmap_keys (m::('a × 'b) list). (f::'a ⇒ 'a) x = (z::'a)} ≠ {}›*) have z_in_keys: "z ∈ mmap_keys (mmap_fold m (λ(x, y). (f x, y)) sup [])" using False[unfolded mmap_keys_def] (*‹{x ∈ set (map fst m). f x = z} ≠ {}›*) mmap_fold_set[OF distinct] (*‹set (map fst (mmap_fold m ?f ?c [])) = (fst ∘ ?f) ` set m›*) by (force simp: mmap_keys_def (*‹mmap_keys ?kvs = set (map fst ?kvs)›*)) obtain v and vs where vs_def: "mmap_lookup (fold_sup m f) z = Some (foldl sup v vs)" "v # vs = map snd (filter (λ(k, v). f k = z) m)" (*goal: ‹(⋀(v::'b::timestamp) vs::'b::timestamp list. ⟦mmap_lookup (fold_sup (m::('a::type × 'b::timestamp) list) (f::'a::type ⇒ 'a::type)) (z::'a::type) = Some (foldl sup v vs); v # vs = map snd (filter (λ(k::'a::type, v::'b::timestamp). f k = z) m)⟧ ⟹ thesis::bool) ⟹ thesis›*) using mmap_fold_lookup[OF distinct, of "(λ(x, y). (f x, y))" sup z] (*‹mmap_lookup (mmap_fold m (λ(x, y). (f x, y)) sup []) z = (case map (snd ∘ (λ(x, y). (f x, y))) (filter (λ(k, v). fst (case (k, v) of (x, y) ⇒ (f x, y)) = z) m) of [] ⇒ None | v # vs ⇒ Some (foldl sup v vs))›*) Mapping_keys_dest[OF z_in_keys] (*‹∃y. mmap_lookup (mmap_fold m (λ(x, y). (f x, y)) sup []) z = Some y›*) by (force simp: fold_sup_def (*‹fold_sup ?m ?f = mmap_fold ?m (λ(x, y). (?f x, y)) sup []›*) mmap_keys_def (*‹mmap_keys ?kvs = set (map fst ?kvs)›*) comp_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*) split: list.splits (*‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = ((?list = [] ⟶ ?P ?f1.0) ∧ (∀x21 x22. ?list = x21 # x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = (¬ (?list = [] ∧ ¬ ?P ?f1.0 ∨ (∃x21 x22. ?list = x21 # x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*) prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*)) have "set (v # vs) = (the ∘ mmap_lookup m) ` {x ∈ mmap_keys m. f x = z}" proof (rule set_eqI (*‹(⋀x::?'a. (x ∈ (?A::?'a set)) = (x ∈ (?B::?'a set))) ⟹ ?A = ?B›*), rule iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*)) (*goals: 1. ‹⋀x::'b::timestamp. x ∈ set ((v::'b::timestamp) # (vs::'b::timestamp list)) ⟹ x ∈ (the ∘ mmap_lookup (m::('a::type × 'b::timestamp) list)) ` {x::'a::type ∈ mmap_keys m. (f::'a::type ⇒ 'a::type) x = (z::'a::type)}› 2. ‹⋀x::'b::timestamp. x ∈ (the ∘ mmap_lookup (m::('a::type × 'b::timestamp) list)) ` {x::'a::type ∈ mmap_keys m. (f::'a::type ⇒ 'a::type) x = (z::'a::type)} ⟹ x ∈ set ((v::'b::timestamp) # (vs::'b::timestamp list))›*) fix w assume "w ∈ set (v # vs)" (*‹(w::'b) ∈ set ((v::'b) # (vs::'b list))›*) then obtain x where x_def: "x ∈ mmap_keys m" "f x = z" "(x, w) ∈ set m" (*goal: ‹(⋀x. ⟦x ∈ mmap_keys m; f x = z; (x, w) ∈ set m⟧ ⟹ thesis) ⟹ thesis›*) using vs_def(2) (*‹v # vs = map snd (filter (λ(k, v). f k = z) m)›*) by (auto simp add: mmap_keys_def (*‹mmap_keys ?kvs = set (map fst ?kvs)›*) rev_image_eqI (*‹⟦?x ∈ ?A; ?b = ?f ?x⟧ ⟹ ?b ∈ ?f ` ?A›*)) show "w ∈ (the ∘ mmap_lookup m) ` {x ∈ mmap_keys m. f x = z}" using x_def(1,2) (*‹x ∈ mmap_keys m› ‹f x = z›*) mmap_lookup_distinct[OF distinct x_def ( 3 )] (*‹mmap_lookup m x = Some w›*) by force next (*goal: ‹⋀x. x ∈ (the ∘ mmap_lookup m) ` {x ∈ mmap_keys m. f x = z} ⟹ x ∈ set (v # vs)›*) fix w assume "w ∈ (the ∘ mmap_lookup m) ` {x ∈ mmap_keys m. f x = z}" (*‹(w::'b) ∈ (the ∘ mmap_lookup (m::('a × 'b) list)) ` {x::'a ∈ mmap_keys m. (f::'a ⇒ 'a) x = (z::'a)}›*) then obtain x where x_def: "x ∈ mmap_keys m" "f x = z" "(x, w) ∈ set m" (*goal: ‹(⋀x. ⟦x ∈ mmap_keys m; f x = z; (x, w) ∈ set m⟧ ⟹ thesis) ⟹ thesis›*) using mmap_lookup_distinct[OF distinct] (*‹(?k, ?v) ∈ set m ⟹ mmap_lookup m ?k = Some ?v›*) by (auto simp add: Mapping_keys_intro (*‹mmap_lookup ?f ?x ≠ None ⟹ ?x ∈ mmap_keys ?f›*) distinct (*‹distinct (map fst m)›*) mmap_lookup_def (*‹mmap_lookup = map_of›*) dest: Mapping_keys_dest (*‹?x ∈ mmap_keys ?f ⟹ ∃y. mmap_lookup ?f ?x = Some y›*)) show "w ∈ set (v # vs)" using x_def (*‹x ∈ mmap_keys m› ‹f x = z› ‹(x, w) ∈ set m›*) by (force simp: vs_def( (*‹v # vs = map snd (filter (λ(k, v). f k = z) m)›*) 2)) qed then have "foldl sup v vs = Sup_fin ((the ∘ mmap_lookup m) ` {x ∈ mmap_keys m. f x = z})" unfolding fold_sup (*goal: ‹fold sup vs v = ⨆⇩f⇩i⇩n ((the ∘ mmap_lookup m) ` {x ∈ mmap_keys m. f x = z})›*) by (metis Sup_fin.set_eq_fold (*‹⨆⇩f⇩i⇩n set (?x # ?xs) = fold sup ?xs ?x›*)) then show "?thesis" (*goal: ‹mmap_lookup (fold_sup m f) z = (let Z = {x ∈ mmap_keys m. f x = z} in if Z = {} then None else Some (⨆⇩f⇩i⇩n ((the ∘ mmap_lookup m) ` Z)))›*) using False (*‹{x ∈ mmap_keys m. f x = z} ≠ {}›*) by (auto simp: vs_def( (*‹mmap_lookup (fold_sup (m::('a × 'b) list) (f::'a ⇒ 'a)) (z::'a) = Some (foldl sup (v::'b) (vs::'b list))›*) 1)) qed definition mmap_map :: "('a ⇒ 'b ⇒ 'c) ⇒ ('a, 'b) mmap ⇒ ('a, 'c) mmap" where "mmap_map f m = map (λ(k, v). (k, f k v)) m" lemma mmap_map_keys: "mmap_keys (mmap_map f m) = mmap_keys m" by (force simp: mmap_map_def (*‹mmap_map ?f ?m = map (λ(k, v). (k, ?f k v)) ?m›*) mmap_keys_def (*‹mmap_keys ?kvs = set (map fst ?kvs)›*)) lemma mmap_map_fst: "map fst (mmap_map f m) = map fst m" by (auto simp: mmap_map_def (*‹mmap_map ?f ?m = map (λ(k, v). (k, ?f k v)) ?m›*)) definition cstep :: "('c ⇒ 'b ⇒ 'c) ⇒ ('c × 'b, 'c) mapping ⇒ 'c ⇒ 'b ⇒ ('c × ('c × 'b, 'c) mapping)" where "cstep step st q bs = (case Mapping.lookup st (q, bs) of None ⇒ (let res = step q bs in (res, Mapping.update (q, bs) res st)) | Some v ⇒ (v, st))" definition cac :: "('c ⇒ bool) ⇒ ('c, bool) mapping ⇒ 'c ⇒ (bool × ('c, bool) mapping)" where "cac accept ac q = (case Mapping.lookup ac q of None ⇒ (let res = accept q in (res, Mapping.update q res ac)) | Some v ⇒ (v, ac))" fun mmap_fold_s :: "('c ⇒ 'b ⇒ 'c) ⇒ ('c × 'b, 'c) mapping ⇒ ('c ⇒ bool) ⇒ ('c, bool) mapping ⇒ 'b ⇒ 'd ⇒ nat ⇒ ('c, 'c × ('d × nat) option) mmap ⇒ (('c, 'c × ('d × nat) option) mmap × ('c × 'b, 'c) mapping × ('c, bool) mapping)" where "mmap_fold_s step st accept ac bs t j [] = ([], st, ac)" | "mmap_fold_s step st accept ac bs t j ((q, (q', tstp)) # qbss) = (let (q'', st') = cstep step st q' bs; (β, ac') = cac accept ac q''; (qbss', st'', ac'') = mmap_fold_s step st' accept ac' bs t j qbss in ((q, (q'', if β then Some (t, j) else tstp)) # qbss', st'', ac''))" lemma mmap_fold_s_sound: "mmap_fold_s step st accept ac bs t j qbss = (qbss', st', ac') ⟹ (⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v) ⟹ (⋀q bs. case Mapping.lookup ac q of None ⇒ True | Some v ⇒ accept q = v) ⟹ qbss' = mmap_map (λq (q', tstp). (step q' bs, if accept (step q' bs) then Some (t, j) else tstp)) qbss ∧ (∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some v ⇒ step q bs = v) ∧ (∀q bs. case Mapping.lookup ac' q of None ⇒ True | Some v ⇒ accept q = v)" proof (induction qbss arbitrary: st ac qbss') (*goals: 1. ‹⋀st ac qbss'. ⟦mmap_fold_s step st accept ac bs t j [] = (qbss', st', ac'); ⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some x ⇒ step q bs = x; ⋀q bs. case Mapping.lookup ac q of None ⇒ True | Some x ⇒ accept q = x⟧ ⟹ qbss' = mmap_map (λq (q', tstp). (step q' bs, if accept (step q' bs) then Some (t, j) else tstp)) [] ∧ (∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some x ⇒ step q bs = x) ∧ (∀q bs. case Mapping.lookup ac' q of None ⇒ True | Some x ⇒ accept q = x)› 2. ‹⋀a qbss st ac qbss'. ⟦⋀st ac qbss'. ⟦mmap_fold_s step st accept ac bs t j qbss = (qbss', st', ac'); ⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some x ⇒ step q bs = x; ⋀q bs. case Mapping.lookup ac q of None ⇒ True | Some x ⇒ accept q = x⟧ ⟹ qbss' = mmap_map (λq (q', tstp). (step q' bs, if accept (step q' bs) then Some (t, j) else tstp)) qbss ∧ (∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some x ⇒ step q bs = x) ∧ (∀q bs. case Mapping.lookup ac' q of None ⇒ True | Some x ⇒ accept q = x); mmap_fold_s step st accept ac bs t j (a # qbss) = (qbss', st', ac'); ⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some x ⇒ step q bs = x; ⋀q bs. case Mapping.lookup ac q of None ⇒ True | Some x ⇒ accept q = x⟧ ⟹ qbss' = mmap_map (λq (q', tstp). (step q' bs, if accept (step q' bs) then Some (t, j) else tstp)) (a # qbss) ∧ (∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some x ⇒ step q bs = x) ∧ (∀q bs. case Mapping.lookup ac' q of None ⇒ True | Some x ⇒ accept q = x)›*) case (Cons a qbss) (*‹⟦mmap_fold_s step ?st accept ?ac bs t j qbss = (?qbss', st', ac'); ⋀q bs. case Mapping.lookup ?st (q, bs) of None ⇒ True | Some a ⇒ step q bs = a; ⋀q bs. case Mapping.lookup ?ac q of None ⇒ True | Some a ⇒ accept q = a⟧ ⟹ ?qbss' = mmap_map (λq a. case a of (q', tstp) ⇒ (step q' bs, if accept (step q' bs) then Some (t, j) else tstp)) qbss ∧ (∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some a ⇒ step q bs = a) ∧ (∀q bs. case Mapping.lookup ac' q of None ⇒ True | Some a ⇒ accept q = a)› ‹mmap_fold_s step st accept ac bs t j (a # qbss) = (qbss', st', ac')› ‹case Mapping.lookup (st::('a × 'c, 'a) mapping) (?q::'a, ?bs::'c) of None ⇒ True | Some (a::'a) ⇒ (step::'a ⇒ 'c ⇒ 'a) ?q ?bs = a› ‹case Mapping.lookup ac ?q of None ⇒ True | Some a ⇒ accept ?q = a›*) obtain q and q' and tstp where a_def: "a = (q, (q', tstp))" (*goal: ‹(⋀(q::'a::type) (q'::'a::type) tstp::('b::type × nat) option. (a::'a::type × 'a::type × ('b::type × nat) option) = (q, q', tstp) ⟹ thesis::bool) ⟹ thesis›*) apply (cases a) (*goal: ‹(⋀q q' tstp. a = (q, q', tstp) ⟹ thesis) ⟹ thesis›*) by auto obtain q'' and st'' where q''_def: "cstep step st q' bs = (q'', st'')" "q'' = step q' bs" (*goal: ‹(⋀q'' st''. ⟦cstep step st q' bs = (q'', st''); q'' = step q' bs⟧ ⟹ thesis) ⟹ thesis›*) using Cons(3) (*‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some a ⇒ step ?q ?bs = a›*) apply (cases "cstep step st q' bs") (*goal: ‹(⋀q'' st''. ⟦cstep step st q' bs = (q'', st''); q'' = step q' bs⟧ ⟹ thesis) ⟹ thesis›*) by (auto simp: cstep_def (*‹cstep ?step ?st ?q ?bs = (case Mapping.lookup ?st (?q, ?bs) of None ⇒ let res = ?step ?q ?bs in (res, Mapping.update (?q, ?bs) res ?st) | Some v ⇒ (v, ?st))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) option.case_eq_if (*‹(case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (if ?option = None then ?f1.0 else ?f2.0 (the ?option))›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) obtain b and ac'' where b_def: "cac accept ac q'' = (b, ac'')" "b = accept q''" (*goal: ‹(⋀b ac''. ⟦cac accept ac q'' = (b, ac''); b = accept q''⟧ ⟹ thesis) ⟹ thesis›*) using Cons(4) (*‹case Mapping.lookup ac ?q of None ⇒ True | Some a ⇒ accept ?q = a›*) apply (cases "cac accept ac q''") (*goal: ‹(⋀(b::bool) ac''::('a, bool) mapping. ⟦cac (accept::'a ⇒ bool) (ac::('a, bool) mapping) (q''::'a) = (b, ac''); b = accept q''⟧ ⟹ thesis::bool) ⟹ thesis›*) by (auto simp: cac_def (*‹cac ?accept ?ac ?q = (case Mapping.lookup ?ac ?q of None ⇒ let res = ?accept ?q in (res, Mapping.update ?q res ?ac) | Some v ⇒ (v, ?ac))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) option.case_eq_if (*‹(case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (if ?option = None then ?f1.0 else ?f2.0 (the ?option))›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) obtain qbss'' where qbss''_def: "mmap_fold_s step st'' accept ac'' bs t j qbss = (qbss'', st', ac')" "qbss' = (q, q'', if b then Some (t, j) else tstp) # qbss''" (*goal: ‹(⋀qbss''. ⟦mmap_fold_s step st'' accept ac'' bs t j qbss = (qbss'', st', ac'); qbss' = (q, q'', if b then Some (t, j) else tstp) # qbss''⟧ ⟹ thesis) ⟹ thesis›*) using Cons(2)[unfolded a_def mmap_fold_s.simps q''_def ( 1 ) b_def ( 1 )] (*‹(let (q'', st') = (q'', st''); (β, ac') = cac accept ac q''; (qbss', st'', ac'') = mmap_fold_s step st' accept ac' bs t j qbss in ((q, q'', if β then Some (t, j) else tstp) # qbss', st'', ac'')) = (qbss', st', ac')›*) unfolding Let_def (*goal: ‹(⋀qbss''. ⟦mmap_fold_s step st'' accept ac'' bs t j qbss = (qbss'', st', ac'); qbss' = (q, q'', if b then Some (t, j) else tstp) # qbss''⟧ ⟹ thesis) ⟹ thesis›*) by (auto simp: b_def( (*‹cac accept ac q'' = (b, ac'')›*) 1) split: prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*)) have ih: "⋀q bs. case Mapping.lookup st'' (q, bs) of None ⇒ True | Some a ⇒ step q bs = a" "⋀q bs. case Mapping.lookup ac'' q of None ⇒ True | Some a ⇒ accept q = a" using q''_def (*‹cstep step st q' bs = (q'', st'')› ‹(q''::'a) = (step::'a ⇒ 'c ⇒ 'a) (q'::'a) (bs::'c)›*) b_def (*‹cac accept ac q'' = (b, ac'')› ‹b = accept q''›*) Cons(3,4) (*‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some a ⇒ step ?q ?bs = a› ‹case Mapping.lookup ac ?q of None ⇒ True | Some a ⇒ accept ?q = a›*) apply - (*goals: 1. ‹⋀q bsa. ⟦cstep step st q' bs = (q'', st''); q'' = step q' bs; cac accept ac q'' = (b, ac''); b = accept q''; ⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some a ⇒ step q bs = a; ⋀q. case Mapping.lookup ac q of None ⇒ True | Some a ⇒ accept q = a⟧ ⟹ case Mapping.lookup st'' (q, bsa) of None ⇒ True | Some a ⇒ step q bsa = a› 2. ‹⋀q bsa. ⟦cstep step st q' bs = (q'', st''); q'' = step q' bs; cac accept ac q'' = (b, ac''); b = accept q''; ⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some a ⇒ step q bs = a; ⋀q. case Mapping.lookup ac q of None ⇒ True | Some a ⇒ accept q = a⟧ ⟹ case Mapping.lookup ac'' q of None ⇒ True | Some a ⇒ accept q = a› discuss goal 1*) apply ((auto simp: cstep_def (*‹cstep ?step ?st ?q ?bs = (case Mapping.lookup ?st (?q, ?bs) of None ⇒ let res = ?step ?q ?bs in (res, Mapping.update (?q, ?bs) res ?st) | Some v ⇒ (v, ?st))›*) cac_def (*‹cac ?accept ?ac ?q = (case Mapping.lookup ?ac ?q of None ⇒ let res = ?accept ?q in (res, Mapping.update ?q res ?ac) | Some v ⇒ (v, ?ac))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) Mapping.lookup_update' (*‹Mapping.lookup (Mapping.update ?k ?v ?m) ?k' = (if ?k = ?k' then Some ?v else Mapping.lookup ?m ?k')›*) option.case_eq_if (*‹(case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (if ?option = None then ?f1.0 else ?f2.0 (the ?option))›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto simp: cstep_def (*‹cstep (?step::?'c ⇒ ?'b ⇒ ?'c) (?st::(?'c × ?'b, ?'c) mapping) (?q::?'c) (?bs::?'b) = (case Mapping.lookup ?st (?q, ?bs) of None ⇒ let res::?'c = ?step ?q ?bs in (res, Mapping.update (?q, ?bs) res ?st) | Some (v::?'c) ⇒ (v, ?st))›*) cac_def (*‹cac (?accept::?'c ⇒ bool) (?ac::(?'c, bool) mapping) (?q::?'c) = (case Mapping.lookup ?ac ?q of None ⇒ let res::bool = ?accept ?q in (res, Mapping.update ?q res ?ac) | Some (v::bool) ⇒ (v, ?ac))›*) Let_def (*‹Let (?s::?'a) (?f::?'a ⇒ ?'b) ≡ ?f ?s›*) Mapping.lookup_update' (*‹Mapping.lookup (Mapping.update (?k::?'b) (?v::?'a) (?m::(?'b, ?'a) mapping)) (?k'::?'b) = (if ?k = ?k' then Some ?v else Mapping.lookup ?m ?k')›*) option.case_eq_if (*‹(case ?option::?'a option of None ⇒ ?f1.0::?'b | Some (x::?'a) ⇒ (?f2.0::?'a ⇒ ?'b) x) = (if ?option = None then ?f1.0 else ?f2.0 (the ?option))›*) split: option.splits (*‹(?P::?'b ⇒ bool) (case ?option::?'a option of None ⇒ ?f1.0::?'b | Some (x::?'a) ⇒ (?f2.0::?'a ⇒ ?'b) x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2::?'a. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹(?P::?'b ⇒ bool) (case ?option::?'a option of None ⇒ ?f1.0::?'b | Some (x::?'a) ⇒ (?f2.0::?'a ⇒ ?'b) x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2::?'a. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) if_splits (*‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 2 subgoals*) . show "?case" (*goal: ‹qbss' = mmap_map (λq a. case a of (q', tstp) ⇒ (step q' bs, if accept (step q' bs) then Some (t, j) else tstp)) (a # qbss) ∧ (∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some a ⇒ step q bs = a) ∧ (∀q bs. case Mapping.lookup ac' q of None ⇒ True | Some a ⇒ accept q = a)›*) using Cons(1)[OF qbss''_def ( 1 ) ih] (*‹qbss'' = mmap_map (λq a. case a of (q', tstp) ⇒ (step q' bs, if accept (step q' bs) then Some (t, j) else tstp)) qbss ∧ (∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some a ⇒ step q bs = a) ∧ (∀q bs. case Mapping.lookup ac' q of None ⇒ True | Some a ⇒ accept q = a)›*) unfolding a_def q''_def(2) b_def(2) qbss''_def(2) (*goal: ‹(q, step q' bs, if accept (step q' bs) then Some (t, j) else tstp) # qbss'' = mmap_map (λq a. case a of (q', tstp) ⇒ (step q' bs, if accept (step q' bs) then Some (t, j) else tstp)) ((q, q', tstp) # qbss) ∧ (∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some a ⇒ step q bs = a) ∧ (∀q bs. case Mapping.lookup ac' q of None ⇒ True | Some a ⇒ accept q = a)›*) by (auto simp: mmap_map_def (*‹mmap_map ?f ?m = map (λ(k, v). (k, ?f k v)) ?m›*)) qed (auto simp: mmap_map_def (*‹mmap_map ?f ?m = map (λ(k, v). (k, ?f k v)) ?m›*)) (*solved the remaining goal: ‹⋀(st::('a::type × 'c::type, 'a::type) mapping) (ac::('a::type, bool) mapping) qbss'::('a::type × 'a::type × ('b::type × nat) option) list. ⟦mmap_fold_s (step::'a::type ⇒ 'c::type ⇒ 'a::type) st (accept::'a::type ⇒ bool) ac (bs::'c::type) (t::'b::type) (j::nat) [] = (qbss', st'::('a::type × 'c::type, 'a::type) mapping, ac'::('a::type, bool) mapping); ⋀(q::'a::type) bs::'c::type. case Mapping.lookup st (q, bs) of None ⇒ True | Some (x::'a::type) ⇒ step q bs = x; ⋀(q::'a::type) bs::'d::type. case Mapping.lookup ac q of None ⇒ True | Some (x::bool) ⇒ accept q = x⟧ ⟹ qbss' = mmap_map (λ(q::'a::type) (q'::'a::type, tstp::('b::type × nat) option). (step q' bs, if accept (step q' bs) then Some (t, j) else tstp)) [] ∧ (∀(q::'a::type) bs::'c::type. case Mapping.lookup st' (q, bs) of None ⇒ True | Some (x::'a::type) ⇒ step q bs = x) ∧ (∀(q::'a::type) bs::'e::type. case Mapping.lookup ac' q of None ⇒ True | Some (x::bool) ⇒ accept q = x)›*) definition adv_end :: "('b, 'c, 'd :: timestamp, 't, 'e) args ⇒ ('b, 'c, 'd, 't, 'e) window ⇒ ('b, 'c, 'd, 't, 'e) window option" where "adv_end args w = (let step = w_step args; accept = w_accept args; run_t = w_run_t args; run_sub = w_run_sub args; st = w_st w; ac = w_ac w; j = w_j w; tj = w_tj w; sj = w_sj w; s = w_s w; e = w_e w in (case run_t tj of None ⇒ None | Some (tj', t) ⇒ (case run_sub sj of None ⇒ None | Some (sj', bs) ⇒ let (s', st', ac') = mmap_fold_s step st accept ac bs t j s; (e', st'') = mmap_fold' e st' (λ((x, y), st). let (q', st') = cstep step st x bs in ((q', y), st')) sup [] in Some (w⦇w_st := st'', w_ac := ac', w_j := Suc j, w_tj := tj', w_sj := sj', w_s := s', w_e := e'⦈))))" lemma map_values_lookup: "mmap_lookup (mmap_map f m) z = Some v' ⟹ ∃v. mmap_lookup m z = Some v ∧ v' = f z v" apply (induction m) (*goals: 1. ‹mmap_lookup (mmap_map f []) z = Some v' ⟹ ∃v. mmap_lookup [] z = Some v ∧ v' = f z v› 2. ‹⋀a m. ⟦mmap_lookup (mmap_map f m) z = Some v' ⟹ ∃v. mmap_lookup m z = Some v ∧ v' = f z v; mmap_lookup (mmap_map f (a # m)) z = Some v'⟧ ⟹ ∃v. mmap_lookup (a # m) z = Some v ∧ v' = f z v› discuss goal 1*) apply ((auto simp: mmap_lookup_def (*‹mmap_lookup = map_of›*) mmap_map_def (*‹mmap_map ?f ?m = map (λ(k, v). (k, ?f k v)) ?m›*))[1]) (*discuss goal 2*) apply ((auto simp: mmap_lookup_def (*‹mmap_lookup = map_of›*) mmap_map_def (*‹mmap_map ?f ?m = map (λ(k, v). (k, ?f k v)) ?m›*))[1]) (*proven 2 subgoals*) . lemma acc_app: assumes "i ≤ j" "steps step rho q (i, Suc j) = q'" "accept q'" shows "sup_acc step accept rho q i (Suc j) = Some (ts_at rho j, j)" proof (-) (*goal: ‹sup_acc step accept rho q i (Suc j) = Some (ts_at rho j, j)›*) define L where "L = {l ∈ {i..<Suc j}. accept (steps step rho q (i, Suc l))}" have nonempty: "finite L" "L ≠ {}" using assms (*‹i ≤ j› ‹steps step rho q (i, Suc j) = q'› ‹accept q'›*) unfolding L_def (*goals: 1. ‹finite {l ∈ {i..<Suc j}. accept (steps step rho q (i, Suc l))}› 2. ‹{l ∈ {i..<Suc j}. accept (steps step rho q (i, Suc l))} ≠ {}›*) apply - (*goals: 1. ‹⟦i ≤ j; steps step rho q (i, Suc j) = q'; accept q'⟧ ⟹ finite {l ∈ {i..<Suc j}. accept (steps step rho q (i, Suc l))}› 2. ‹⟦i ≤ j; steps step rho q (i, Suc j) = q'; accept q'⟧ ⟹ {l ∈ {i..<Suc j}. accept (steps step rho q (i, Suc l))} ≠ {}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . moreover have "Max {l ∈ {i..<Suc j}. accept (steps step rho q (i, Suc l))} = j" unfolding L_def[symmetric] Max_eq_iff[OF nonempty, of j] (*goal: ‹j ∈ L ∧ (∀a∈L. a ≤ j)›*) unfolding L_def (*goal: ‹j ∈ {l ∈ {i..<Suc j}. accept (steps step rho q (i, Suc l))} ∧ (∀a∈{l ∈ {i..<Suc j}. accept (steps step rho q (i, Suc l))}. a ≤ j)›*) using assms (*‹i ≤ j› ‹steps step rho q (i, Suc j) = q'› ‹(accept::'a::type ⇒ bool) (q'::'a::type)›*) by auto ultimately show "?thesis" (*goal: ‹sup_acc step accept rho q i (Suc j) = Some (ts_at rho j, j)›*) by (auto simp add: sup_acc_def (*‹sup_acc (?step::?'c::type ⇒ ?'b::type ⇒ ?'c::type) (?accept::?'c::type ⇒ bool) (?rho::(?'d::type × ?'b::type) list) (?q::?'c::type) (?i::nat) (?j::nat) = (let L'::nat set = {l::nat ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m::nat = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*) acc_def (*‹acc (?step::?'c::type ⇒ ?'b::type ⇒ ?'c::type) (?accept::?'c::type ⇒ bool) (?rho::(?'d::type × ?'b::type) list) (?q::?'c::type) (?ij::nat × nat) = ?accept (steps ?step ?rho ?q ?ij)›*) L_def (*‹(L::nat set) = {l::nat ∈ {i::nat..<Suc (j::nat)}. (accept::'a::type ⇒ bool) (steps (step::'a::type ⇒ 'b::type ⇒ 'a::type) (rho::('c::type × 'b::type) list) (q::'a::type) (i, Suc l))}›*)) qed lemma acc_app_idle: assumes "i ≤ j" "steps step rho q (i, Suc j) = q'" "¬accept q'" shows "sup_acc step accept rho q i (Suc j) = sup_acc step accept rho q i j" using assms (*‹i ≤ j› ‹steps step rho q (i, Suc j) = q'› ‹¬ accept q'›*) apply (auto simp add: sup_acc_def (*‹sup_acc ?step ?accept ?rho ?q ?i ?j = (let L' = {l ∈ {?i..<?j}. acc ?step ?accept ?rho ?q (?i, Suc l)}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m, m))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) acc_def (*‹acc ?step ?accept ?rho ?q ?ij = ?accept (steps ?step ?rho ?q ?ij)›*) elim: less_SucE (*‹⟦?m < Suc ?n; ?m < ?n ⟹ ?P; ?m = ?n ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹⋀x xa. ⟦¬ accept (steps step rho q (i, Suc j)); q' = steps step rho q (i, Suc j); x < Suc j; i ≤ x; accept (steps step rho q (i, Suc x)); xa < j; i ≤ xa; accept (steps step rho q (i, Suc xa))⟧ ⟹ ts_at rho (Max {l. i ≤ l ∧ l < Suc j ∧ accept (steps step rho q (i, Suc l))}) = ts_at rho (Max {l. i ≤ l ∧ l < j ∧ accept (steps step rho q (i, Suc l))})› 2. ‹⋀x xa. ⟦¬ accept (steps step rho q (i, Suc j)); q' = steps step rho q (i, Suc j); x < Suc j; i ≤ x; accept (steps step rho q (i, Suc x)); xa < j; i ≤ xa; accept (steps step rho q (i, Suc xa))⟧ ⟹ Max {l. i ≤ l ∧ l < Suc j ∧ accept (steps step rho q (i, Suc l))} = Max {l. i ≤ l ∧ l < j ∧ accept (steps step rho q (i, Suc l))}› discuss goal 1*) apply (metis less_Suc_eq (*‹(?m < Suc ?n) = (?m < ?n ∨ ?m = ?n)›*)) (*discuss goal 2*) apply (metis less_Suc_eq (*‹(?m < Suc ?n) = (?m < ?n ∨ ?m = ?n)›*)) (*proven 2 subgoals*) . lemma sup_fin_closed: "finite A ⟹ A ≠ {} ⟹ (⋀x y. x ∈ A ⟹ y ∈ A ⟹ sup x y ∈ {x, y}) ⟹ ⨆⇩f⇩i⇩n A ∈ A" apply (induct A rule: finite.induct (*‹⟦finite (?x::?'a set); (?P::?'a set ⇒ bool) {}; ⋀(A::?'a set) a::?'a. ⟦finite A; ?P A⟧ ⟹ ?P (insert a A)⟧ ⟹ ?P ?x›*)) (*goal: ‹⟦finite (A::'a::semilattice_sup set); A ≠ {}; ⋀(x::'a::semilattice_sup) y::'a::semilattice_sup. ⟦x ∈ A; y ∈ A⟧ ⟹ sup x y ∈ {x, y}⟧ ⟹ ⨆⇩f⇩i⇩n A ∈ A›*) using Sup_fin.insert (*‹⟦finite ?A; ?A ≠ {}⟧ ⟹ ⨆⇩f⇩i⇩n insert ?x ?A = sup ?x (⨆⇩f⇩i⇩n ?A)›*) apply - (*goals: 1. ‹⟦{} ≠ {}; ⋀x y. ⟦x ∈ {}; y ∈ {}⟧ ⟹ sup x y ∈ {x, y}; ⋀A x. ⟦finite A; A ≠ {}⟧ ⟹ ⨆⇩f⇩i⇩n insert x A = sup x (⨆⇩f⇩i⇩n A)⟧ ⟹ ⨆⇩f⇩i⇩n {} ∈ {}› 2. ‹⋀A a. ⟦finite A; ⟦A ≠ {}; ⋀x y. ⟦x ∈ A; y ∈ A⟧ ⟹ sup x y ∈ {x, y}⟧ ⟹ ⨆⇩f⇩i⇩n A ∈ A; insert a A ≠ {}; ⋀x y. ⟦x ∈ insert a A; y ∈ insert a A⟧ ⟹ sup x y ∈ {x, y}; ⋀A x. ⟦finite A; A ≠ {}⟧ ⟹ ⨆⇩f⇩i⇩n insert x A = sup x (⨆⇩f⇩i⇩n A)⟧ ⟹ ⨆⇩f⇩i⇩n insert a A ∈ insert a A› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*goal: ‹⋀A a. ⟦finite A; ⟦A ≠ {}; ⋀x y. ⟦x ∈ A; y ∈ A⟧ ⟹ sup x y ∈ {x, y}⟧ ⟹ ⨆⇩f⇩i⇩n A ∈ A; insert a A ≠ {}; ⋀x y. ⟦x ∈ insert a A; y ∈ insert a A⟧ ⟹ sup x y ∈ {x, y}; ⋀A x. ⟦finite A; A ≠ {}⟧ ⟹ ⨆⇩f⇩i⇩n insert x A = sup x (⨆⇩f⇩i⇩n A)⟧ ⟹ ⨆⇩f⇩i⇩n insert a A ∈ insert a A›*) apply fastforce (*proven 2 subgoals*) . lemma valid_adv_end: assumes "valid_window args t0 sub rho w" "w_run_t args (w_tj w) = Some (tj', t)" "w_run_sub args (w_sj w) = Some (sj', bs)" "⋀t'. t' ∈ set (map fst rho) ⟹ t' ≤ t" shows "case adv_end args w of None ⇒ False | Some w' ⇒ valid_window args t0 sub (rho @ [(t, bs)]) w'" proof (-) (*goal: ‹case adv_end args w of None ⇒ False | Some w' ⇒ valid_window args t0 sub (rho @ [(t, bs)]) w'›*) define init where "init = w_init args" define step where "step = w_step args" define accept where "accept = w_accept args" define run_t where "run_t = w_run_t args" define run_sub where "run_sub = w_run_sub args" define st where "st = w_st w" define ac where "ac = w_ac w" define i where "i = w_i w" define ti where "ti = w_ti w" define si where "si = w_si w" define j where "j = w_j w" define tj where "tj = w_tj w" define sj where "sj = w_sj w" define s where "s = w_s w" define e where "e = w_e w" have valid_before: "reach_window args t0 sub rho (i, ti, si, j, tj, sj)" "⋀i j. i ≤ j ⟹ j < length rho ⟹ ts_at rho i ≤ ts_at rho j" "(⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v)" "(⋀q bs. case Mapping.lookup ac q of None ⇒ True | Some v ⇒ accept q = v)" "∀q. mmap_lookup e q = sup_leadsto init step rho i j q" "distinct (map fst e)" "valid_s init step st accept rho i i j s" using assms(1) (*‹valid_window args t0 sub rho w›*) unfolding valid_window_def valid_s_def Let_def init_def step_def accept_def run_t_def run_sub_def st_def ac_def i_def ti_def si_def j_def tj_def sj_def s_def e_def (*goals: 1. ‹reach_window args t0 sub rho (w_i w, w_ti w, w_si w, w_j w, w_tj w, w_sj w)› 2. ‹⋀i j. ⟦i ≤ j; j < length rho⟧ ⟹ ts_at rho i ≤ ts_at rho j› 3. ‹⋀q bs. case Mapping.lookup (w_st w) (q, bs) of None ⇒ True | Some v ⇒ w_step args q bs = v› 4. ‹⋀q bs. case Mapping.lookup (w_ac w) q of None ⇒ True | Some v ⇒ w_accept args q = v› 5. ‹∀q. mmap_lookup (w_e w) q = sup_leadsto (w_init args) (w_step args) rho (w_i w) (w_j w) q› 6. ‹distinct (map fst (w_e w))› 7. ‹(∀q bs. case Mapping.lookup (w_st w) (q, bs) of None ⇒ True | Some v ⇒ w_step args q bs = v) ∧ mmap_keys (w_s w) = {q. ∃l≤w_i w. steps (w_step args) rho (w_init args) (l, w_i w) = q} ∧ distinct (map fst (w_s w)) ∧ (∀q. case mmap_lookup (w_s w) q of None ⇒ True | Some (q', tstp) ⇒ steps (w_step args) rho q (w_i w, w_j w) = q' ∧ tstp = sup_acc (w_step args) (w_accept args) rho q (w_i w) (w_j w))›*) apply - (*goals: 1. ‹reach_window args t0 sub rho (w_i w, w_ti w, w_si w, w_j w, w_tj w, w_sj w) ∧ (∀i j. i ≤ j ∧ j < length rho ⟶ ts_at rho i ≤ ts_at rho j) ∧ (∀q. case Mapping.lookup (w_ac w) q of None ⇒ True | Some x ⇒ w_accept args q = x) ∧ (∀q. mmap_lookup (w_e w) q = sup_leadsto (w_init args) (w_step args) rho (w_i w) (w_j w) q) ∧ distinct (map fst (w_e w)) ∧ (∀q bs. case Mapping.lookup (w_st w) (q, bs) of None ⇒ True | Some x ⇒ w_step args q bs = x) ∧ mmap_keys (w_s w) = {q. ∃l≤w_i w. steps (w_step args) rho (w_init args) (l, w_i w) = q} ∧ distinct (map fst (w_s w)) ∧ (∀q. case mmap_lookup (w_s w) q of None ⇒ True | Some (q', tstp) ⇒ steps (w_step args) rho q (w_i w, w_j w) = q' ∧ tstp = sup_acc (w_step args) (w_accept args) rho q (w_i w) (w_j w)) ⟹ reach_window args t0 sub rho (w_i w, w_ti w, w_si w, w_j w, w_tj w, w_sj w)› 2. ‹⋀i j. ⟦i ≤ j; j < length rho; reach_window args t0 sub rho (w_i w, w_ti w, w_si w, w_j w, w_tj w, w_sj w) ∧ (∀i j. i ≤ j ∧ j < length rho ⟶ ts_at rho i ≤ ts_at rho j) ∧ (∀q. case Mapping.lookup (w_ac w) q of None ⇒ True | Some x ⇒ w_accept args q = x) ∧ (∀q. mmap_lookup (w_e w) q = sup_leadsto (w_init args) (w_step args) rho (w_i w) (w_j w) q) ∧ distinct (map fst (w_e w)) ∧ (∀q bs. case Mapping.lookup (w_st w) (q, bs) of None ⇒ True | Some x ⇒ w_step args q bs = x) ∧ mmap_keys (w_s w) = {q. ∃l≤w_i w. steps (w_step args) rho (w_init args) (l, w_i w) = q} ∧ distinct (map fst (w_s w)) ∧ (∀q. case mmap_lookup (w_s w) q of None ⇒ True | Some (q', tstp) ⇒ steps (w_step args) rho q (w_i w, w_j w) = q' ∧ tstp = sup_acc (w_step args) (w_accept args) rho q (w_i w) (w_j w))⟧ ⟹ ts_at rho i ≤ ts_at rho j› 3. ‹⋀q bs. reach_window args t0 sub rho (w_i w, w_ti w, w_si w, w_j w, w_tj w, w_sj w) ∧ (∀i j. i ≤ j ∧ j < length rho ⟶ ts_at rho i ≤ ts_at rho j) ∧ (∀q. case Mapping.lookup (w_ac w) q of None ⇒ True | Some x ⇒ w_accept args q = x) ∧ (∀q. mmap_lookup (w_e w) q = sup_leadsto (w_init args) (w_step args) rho (w_i w) (w_j w) q) ∧ distinct (map fst (w_e w)) ∧ (∀q bs. case Mapping.lookup (w_st w) (q, bs) of None ⇒ True | Some x ⇒ w_step args q bs = x) ∧ mmap_keys (w_s w) = {q. ∃l≤w_i w. steps (w_step args) rho (w_init args) (l, w_i w) = q} ∧ distinct (map fst (w_s w)) ∧ (∀q. case mmap_lookup (w_s w) q of None ⇒ True | Some (q', tstp) ⇒ steps (w_step args) rho q (w_i w, w_j w) = q' ∧ tstp = sup_acc (w_step args) (w_accept args) rho q (w_i w) (w_j w)) ⟹ case Mapping.lookup (w_st w) (q, bs) of None ⇒ True | Some v ⇒ w_step args q bs = v› 4. ‹⋀q bs. reach_window args t0 sub rho (w_i w, w_ti w, w_si w, w_j w, w_tj w, w_sj w) ∧ (∀i j. i ≤ j ∧ j < length rho ⟶ ts_at rho i ≤ ts_at rho j) ∧ (∀q. case Mapping.lookup (w_ac w) q of None ⇒ True | Some x ⇒ w_accept args q = x) ∧ (∀q. mmap_lookup (w_e w) q = sup_leadsto (w_init args) (w_step args) rho (w_i w) (w_j w) q) ∧ distinct (map fst (w_e w)) ∧ (∀q bs. case Mapping.lookup (w_st w) (q, bs) of None ⇒ True | Some x ⇒ w_step args q bs = x) ∧ mmap_keys (w_s w) = {q. ∃l≤w_i w. steps (w_step args) rho (w_init args) (l, w_i w) = q} ∧ distinct (map fst (w_s w)) ∧ (∀q. case mmap_lookup (w_s w) q of None ⇒ True | Some (q', tstp) ⇒ steps (w_step args) rho q (w_i w, w_j w) = q' ∧ tstp = sup_acc (w_step args) (w_accept args) rho q (w_i w) (w_j w)) ⟹ case Mapping.lookup (w_ac w) q of None ⇒ True | Some v ⇒ w_accept args q = v› 5. ‹reach_window args t0 sub rho (w_i w, w_ti w, w_si w, w_j w, w_tj w, w_sj w) ∧ (∀i j. i ≤ j ∧ j < length rho ⟶ ts_at rho i ≤ ts_at rho j) ∧ (∀q. case Mapping.lookup (w_ac w) q of None ⇒ True | Some x ⇒ w_accept args q = x) ∧ (∀q. mmap_lookup (w_e w) q = sup_leadsto (w_init args) (w_step args) rho (w_i w) (w_j w) q) ∧ distinct (map fst (w_e w)) ∧ (∀q bs. case Mapping.lookup (w_st w) (q, bs) of None ⇒ True | Some x ⇒ w_step args q bs = x) ∧ mmap_keys (w_s w) = {q. ∃l≤w_i w. steps (w_step args) rho (w_init args) (l, w_i w) = q} ∧ distinct (map fst (w_s w)) ∧ (∀q. case mmap_lookup (w_s w) q of None ⇒ True | Some (q', tstp) ⇒ steps (w_step args) rho q (w_i w, w_j w) = q' ∧ tstp = sup_acc (w_step args) (w_accept args) rho q (w_i w) (w_j w)) ⟹ ∀q. mmap_lookup (w_e w) q = sup_leadsto (w_init args) (w_step args) rho (w_i w) (w_j w) q› 6. ‹reach_window args t0 sub rho (w_i w, w_ti w, w_si w, w_j w, w_tj w, w_sj w) ∧ (∀i j. i ≤ j ∧ j < length rho ⟶ ts_at rho i ≤ ts_at rho j) ∧ (∀q. case Mapping.lookup (w_ac w) q of None ⇒ True | Some x ⇒ w_accept args q = x) ∧ (∀q. mmap_lookup (w_e w) q = sup_leadsto (w_init args) (w_step args) rho (w_i w) (w_j w) q) ∧ distinct (map fst (w_e w)) ∧ (∀q bs. case Mapping.lookup (w_st w) (q, bs) of None ⇒ True | Some x ⇒ w_step args q bs = x) ∧ mmap_keys (w_s w) = {q. ∃l≤w_i w. steps (w_step args) rho (w_init args) (l, w_i w) = q} ∧ distinct (map fst (w_s w)) ∧ (∀q. case mmap_lookup (w_s w) q of None ⇒ True | Some (q', tstp) ⇒ steps (w_step args) rho q (w_i w, w_j w) = q' ∧ tstp = sup_acc (w_step args) (w_accept args) rho q (w_i w) (w_j w)) ⟹ distinct (map fst (w_e w))› 7. ‹reach_window args t0 sub rho (w_i w, w_ti w, w_si w, w_j w, w_tj w, w_sj w) ∧ (∀i j. i ≤ j ∧ j < length rho ⟶ ts_at rho i ≤ ts_at rho j) ∧ (∀q. case Mapping.lookup (w_ac w) q of None ⇒ True | Some x ⇒ w_accept args q = x) ∧ (∀q. mmap_lookup (w_e w) q = sup_leadsto (w_init args) (w_step args) rho (w_i w) (w_j w) q) ∧ distinct (map fst (w_e w)) ∧ (∀q bs. case Mapping.lookup (w_st w) (q, bs) of None ⇒ True | Some x ⇒ w_step args q bs = x) ∧ mmap_keys (w_s w) = {q. ∃l≤w_i w. steps (w_step args) rho (w_init args) (l, w_i w) = q} ∧ distinct (map fst (w_s w)) ∧ (∀q. case mmap_lookup (w_s w) q of None ⇒ True | Some (q', tstp) ⇒ steps (w_step args) rho q (w_i w, w_j w) = q' ∧ tstp = sup_acc (w_step args) (w_accept args) rho q (w_i w) (w_j w)) ⟹ (∀q bs. case Mapping.lookup (w_st w) (q, bs) of None ⇒ True | Some v ⇒ w_step args q bs = v) ∧ mmap_keys (w_s w) = {q. ∃l≤w_i w. steps (w_step args) rho (w_init args) (l, w_i w) = q} ∧ distinct (map fst (w_s w)) ∧ (∀q. case mmap_lookup (w_s w) q of None ⇒ True | Some (q', tstp) ⇒ steps (w_step args) rho q (w_i w, w_j w) = q' ∧ tstp = sup_acc (w_step args) (w_accept args) rho q (w_i w) (w_j w))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*proven 7 subgoals*) . have i_j: "i ≤ j" using valid_before(1) (*‹reach_window args t0 sub rho (i, ti, si, j, tj, sj)›*) by auto have distinct_before: "distinct (map fst s)" "distinct (map fst e)" using valid_before (*‹reach_window args t0 sub rho (i, ti, si, j, tj, sj)› ‹⟦?i ≤ ?j; ?j < length rho⟧ ⟹ ts_at rho ?i ≤ ts_at rho ?j› ‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ step ?q ?bs = v› ‹case Mapping.lookup ac ?q of None ⇒ True | Some v ⇒ accept ?q = v› ‹∀q::'b::type. mmap_lookup (e::('b::type × 'c::timestamp) list) q = sup_leadsto (init::'b::type) (step::'b::type ⇒ 'a::type ⇒ 'b::type) (rho::('c::timestamp × 'a::type) list) (i::nat) (j::nat) q› ‹distinct (map fst e)› ‹valid_s init step st accept rho i i j s›*) apply - (*goals: 1. ‹⟦reach_window args t0 sub rho (i, ti, si, j, tj, sj); ⋀i j. ⟦i ≤ j; j < length rho⟧ ⟹ ts_at rho i ≤ ts_at rho j; ⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v; ⋀q. case Mapping.lookup ac q of None ⇒ True | Some v ⇒ accept q = v; ∀q. mmap_lookup e q = sup_leadsto init step rho i j q; distinct (map fst e); valid_s init step st accept rho i i j s⟧ ⟹ distinct (map fst s)› 2. ‹⟦reach_window args t0 sub rho (i, ti, si, j, tj, sj); ⋀i j. ⟦i ≤ j; j < length rho⟧ ⟹ ts_at rho i ≤ ts_at rho j; ⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v; ⋀q. case Mapping.lookup ac q of None ⇒ True | Some v ⇒ accept q = v; ∀q. mmap_lookup e q = sup_leadsto init step rho i j q; distinct (map fst e); valid_s init step st accept rho i i j s⟧ ⟹ distinct (map fst e)› discuss goal 1*) apply ((auto simp: valid_s_def (*‹valid_s ?init ?step ?st ?accept ?rho ?u ?i ?j ?s ≡ (∀q bs. case Mapping.lookup ?st (q, bs) of None ⇒ True | Some v ⇒ ?step q bs = v) ∧ mmap_keys ?s = {q. ∃l≤?u. steps ?step ?rho ?init (l, ?i) = q} ∧ distinct (map fst ?s) ∧ (∀q. case mmap_lookup ?s q of None ⇒ True | Some (q', tstp) ⇒ steps ?step ?rho q (?i, ?j) = q' ∧ tstp = sup_acc ?step ?accept ?rho q ?i ?j)›*))[1]) (*discuss goal 2*) apply ((auto simp: valid_s_def (*‹valid_s ?init ?step ?st ?accept ?rho ?u ?i ?j ?s ≡ (∀q bs. case Mapping.lookup ?st (q, bs) of None ⇒ True | Some v ⇒ ?step q bs = v) ∧ mmap_keys ?s = {q. ∃l≤?u. steps ?step ?rho ?init (l, ?i) = q} ∧ distinct (map fst ?s) ∧ (∀q. case mmap_lookup ?s q of None ⇒ True | Some (q', tstp) ⇒ steps ?step ?rho q (?i, ?j) = q' ∧ tstp = sup_acc ?step ?accept ?rho q ?i ?j)›*))[1]) (*proven 2 subgoals*) . note run_tj = assms(2)[folded run_t_def tj_def] (*‹run_t tj = Some (tj', t)›*) note run_sj = assms(3)[folded run_sub_def sj_def] (*‹run_sub sj = Some (sj', bs)›*) define rho' where "rho' = rho @ [(t, bs)]" have ts_at_mono: "⋀i j. i ≤ j ⟹ j < length rho' ⟹ ts_at rho' i ≤ ts_at rho' j" using valid_before(2) (*‹⟦?i ≤ ?j; ?j < length rho⟧ ⟹ ts_at rho ?i ≤ ts_at rho ?j›*) assms(4) (*‹?t' ∈ set (map fst rho) ⟹ ?t' ≤ t›*) by (auto simp: rho'_def (*‹rho' = rho @ [(t, bs)]›*) ts_at_def (*‹ts_at ?rho ?i = fst (?rho ! ?i)›*) nth_append (*‹(?xs @ ?ys) ! ?n = (if ?n < length ?xs then ?xs ! ?n else ?ys ! (?n - length ?xs))›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) list.splits (*‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = ((?list = [] ⟶ ?P ?f1.0) ∧ (∀x21 x22. ?list = x21 # x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = (¬ (?list = [] ∧ ¬ ?P ?f1.0 ∨ (∃x21 x22. ?list = x21 # x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*) if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) obtain s' and st' and ac' where s'_def: "mmap_fold_s step st accept ac bs t j s = (s', st', ac')" (*goal: ‹(⋀s' st' ac'. mmap_fold_s step st accept ac bs t j s = (s', st', ac') ⟹ thesis) ⟹ thesis›*) apply (cases "mmap_fold_s step st accept ac bs t j s") (*goal: ‹(⋀s' st' ac'. mmap_fold_s step st accept ac bs t j s = (s', st', ac') ⟹ thesis) ⟹ thesis›*) by auto have s'_mmap_map: "s' = mmap_map (λq (q', tstp). (step q' bs, if accept (step q' bs) then Some (t, j) else tstp)) s" "(⋀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some v ⇒ step q bs = v)" "(⋀q bs. case Mapping.lookup ac' q of None ⇒ True | Some v ⇒ accept q = v)" using mmap_fold_s_sound[OF s'_def valid_before ( 3 , 4 )] (*‹s' = mmap_map (λq (q', tstp). (step q' bs, if accept (step q' bs) then Some (t, j) else tstp)) s ∧ (∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some v ⇒ step q bs = v) ∧ (∀q bs. case Mapping.lookup ac' q of None ⇒ True | Some v ⇒ accept q = v)›*) apply - (*goals: 1. ‹s' = mmap_map (λq (q', tstp). (step q' bs, if accept (step q' bs) then Some (t, j) else tstp)) s ∧ (∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some v ⇒ step q bs = v) ∧ (∀q bs. case Mapping.lookup ac' q of None ⇒ True | Some v ⇒ accept q = v) ⟹ s' = mmap_map (λq (q', tstp). (step q' bs, if accept (step q' bs) then Some (t, j) else tstp)) s› 2. ‹⋀q bsa. s' = mmap_map (λq (q', tstp). (step q' bs, if accept (step q' bs) then Some (t, j) else tstp)) s ∧ (∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some v ⇒ step q bs = v) ∧ (∀q bs. case Mapping.lookup ac' q of None ⇒ True | Some v ⇒ accept q = v) ⟹ case Mapping.lookup st' (q, bsa) of None ⇒ True | Some v ⇒ step q bsa = v› 3. ‹⋀q bsa. s' = mmap_map (λq (q', tstp). (step q' bs, if accept (step q' bs) then Some (t, j) else tstp)) s ∧ (∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some v ⇒ step q bs = v) ∧ (∀q bs. case Mapping.lookup ac' q of None ⇒ True | Some v ⇒ accept q = v) ⟹ case Mapping.lookup ac' q of None ⇒ True | Some v ⇒ accept q = v› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . obtain e' and st'' where e'_def: "mmap_fold' e st' (λ((x, y), st). let (q', st') = cstep step st x bs in ((q', y), st')) sup [] = (e', st'')" (*goal: ‹(⋀(e'::('b::type × 'c::timestamp) list) st''::('b::type × 'a::type, 'b::type) mapping. mmap_fold' (e::('b::type × 'c::timestamp) list) (st'::('b::type × 'a::type, 'b::type) mapping) (λ((x::'b::type, y::'c::timestamp), st::('b::type × 'a::type, 'b::type) mapping). let (q'::'b::type, st'::('b::type × 'a::type, 'b::type) mapping) = cstep (step::'b::type ⇒ 'a::type ⇒ 'b::type) st x (bs::'a::type) in ((q', y), st')) sup [] = (e', st'') ⟹ thesis::bool) ⟹ thesis›*) by (metis old.prod.exhaust (*‹(⋀a b. ?y = (a, b) ⟹ ?P) ⟹ ?P›*)) define inv where "inv ≡ λst'. ∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some v ⇒ step q bs = v" have inv_st': "inv st'" using s'_mmap_map(2) (*‹case Mapping.lookup st' (?q1, ?bs1) of None ⇒ True | Some v ⇒ step ?q1 ?bs1 = v›*) by (auto simp: inv_def (*‹inv ≡ λst'. ∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some v ⇒ step q bs = v›*)) have "⋀p e p' e'. inv e ⟹ (case (p, e) of (x, xa) ⇒ (case x of (x, y) ⇒ λst. let (q', st') = cstep step st x bs in ((q', y), st')) xa) = (p', e') ⟹ p' = (case p of (x, y) ⇒ (step x bs, y)) ∧ inv e'" by (auto simp: inv_def (*‹inv ≡ λst'. ∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some v ⇒ step q bs = v›*) cstep_def (*‹cstep ?step ?st ?q ?bs = (case Mapping.lookup ?st (?q, ?bs) of None ⇒ let res = ?step ?q ?bs in (res, Mapping.update (?q, ?bs) res ?st) | Some v ⇒ (v, ?st))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) Mapping.lookup_update' (*‹Mapping.lookup (Mapping.update ?k ?v ?m) ?k' = (if ?k = ?k' then Some ?v else Mapping.lookup ?m ?k')›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) then have e'_fold_sup_st'': "e' = fold_sup e (λq. step q bs)" "(⋀q bs. case Mapping.lookup st'' (q, bs) of None ⇒ True | Some v ⇒ step q bs = v)" using mmap_fold'_eq[OF e'_def, of inv "λ(x, y). (step x bs, y)", OF inv_st'] (*‹(⋀p e p' e'. ⟦inv e; (case (p, e) of (x, xa) ⇒ (case x of (x, y) ⇒ λst. let (q', st') = cstep step st x bs in ((q', y), st')) xa) = (p', e')⟧ ⟹ p' = (case p of (x, y) ⇒ (step x bs, y)) ∧ inv e') ⟹ e' = mmap_fold e (λ(x, y). (step x bs, y)) sup [] ∧ inv st''›*) apply - (*goals: 1. ‹⟦⋀e p p' e'. ⟦inv e; (case (p, e) of (x, xa) ⇒ (case x of (x, y) ⇒ λst. let (q', st') = cstep step st x bs in ((q', y), st')) xa) = (p', e')⟧ ⟹ p' = (case p of (x, y) ⇒ (step x bs, y)) ∧ inv e'; (⋀p e p' e'. ⟦inv e; (case (p, e) of (x, xa) ⇒ (case x of (x, y) ⇒ λst. let (q', st') = cstep step st x bs in ((q', y), st')) xa) = (p', e')⟧ ⟹ p' = (case p of (x, y) ⇒ (step x bs, y)) ∧ inv e') ⟹ e' = mmap_fold e (λ(x, y). (step x bs, y)) sup [] ∧ inv st''⟧ ⟹ e' = fold_sup e (λq. step q bs)› 2. ‹⋀q bsa. ⟦⋀e p p' e'. ⟦inv e; (case (p, e) of (x, xa) ⇒ (case x of (x, y) ⇒ λst. let (q', st') = cstep step st x bs in ((q', y), st')) xa) = (p', e')⟧ ⟹ p' = (case p of (x, y) ⇒ (step x bs, y)) ∧ inv e'; (⋀p e p' e'. ⟦inv e; (case (p, e) of (x, xa) ⇒ (case x of (x, y) ⇒ λst. let (q', st') = cstep step st x bs in ((q', y), st')) xa) = (p', e')⟧ ⟹ p' = (case p of (x, y) ⇒ (step x bs, y)) ∧ inv e') ⟹ e' = mmap_fold e (λ(x, y). (step x bs, y)) sup [] ∧ inv st''⟧ ⟹ case Mapping.lookup st'' (q, bsa) of None ⇒ True | Some v ⇒ step q bsa = v› discuss goal 1*) apply (fastforce simp: fold_sup_def (*‹fold_sup (?m::(?'c × ?'d) list) (?f::?'c ⇒ ?'c) = mmap_fold ?m (λ(x::?'c, y::?'d). (?f x, y)) sup []›*) inv_def (*‹inv::('b × 'a, 'b) mapping ⇒ bool ≡ λst'::('b × 'a, 'b) mapping. ∀(q::'b) bs::'a. case Mapping.lookup st' (q, bs) of None ⇒ True | Some (v::'b) ⇒ (step::'b ⇒ 'a ⇒ 'b) q bs = v›*)) (*discuss goal 2*) apply (fastforce simp: fold_sup_def (*‹fold_sup ?m ?f = mmap_fold ?m (λ(x, y). (?f x, y)) sup []›*) inv_def (*‹inv ≡ λst'. ∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some v ⇒ step q bs = v›*)) (*proven 2 subgoals*) . have adv_end: "adv_end args w = Some (w⦇w_st := st'', w_ac := ac', w_j := Suc j, w_tj := tj', w_sj := sj', w_s := s', w_e := e'⦈)" using run_tj (*‹(run_t::'d::type ⇒ ('d::type × 'c::timestamp) option) (tj::'d::type) = Some (tj'::'d::type, t::'c::timestamp)›*) run_sj (*‹(run_sub::'e::type ⇒ ('e::type × 'a::type) option) (sj::'e::type) = Some (sj'::'e::type, bs::'a::type)›*) e'_def[unfolded st_def] (*‹mmap_fold' e st' (λ((x, y), st). let (q', st') = cstep step st x bs in ((q', y), st')) sup [] = (e', st'')›*) unfolding adv_end_def init_def step_def accept_def run_t_def run_sub_def i_def ti_def si_def j_def tj_def sj_def s_def e_def s'_def e'_def (*goal: ‹(let step = w_step args; accept = w_accept args; run_t = w_run_t args; run_sub = w_run_sub args; st = w_st w; ac = w_ac w; j = w_j w; tj = w_tj w; sj = w_sj w; s = w_s w; e = w_e w in case run_t tj of None ⇒ None | Some (tj', t) ⇒ case run_sub sj of None ⇒ None | Some (sj', bs) ⇒ let (s', st', ac') = mmap_fold_s step st accept ac bs t j s; (e', st'') = mmap_fold' e st' (λ((x, y), st). let (q', ya) = cstep step st x bs in ((q', y), ya)) sup [] in Some (w⦇w_st := st'', w_ac := ac', w_j := Suc j, w_tj := tj', w_sj := sj', w_s := s', w_e := e'⦈)) = Some (w⦇w_st := st'', w_ac := ac', w_j := Suc (w_j w), w_tj := tj', w_sj := sj', w_s := s', w_e := e'⦈)›*) by (auto simp: Let_def (*‹Let ?s ?f ≡ ?f ?s›*) s'_def[unfolded step_def st_def accept_def ac_def j_def s_def] (*‹mmap_fold_s (w_step args) (w_st w) (w_accept args) (w_ac w) bs t (w_j w) (w_s w) = (s', st', ac')›*)) have keys_s': "mmap_keys s' = mmap_keys s" by (force simp: mmap_keys_def (*‹mmap_keys ?kvs = set (map fst ?kvs)›*) mmap_map_def (*‹mmap_map ?f ?m = map (λ(k, v). (k, ?f k v)) ?m›*) s'_mmap_map( (*‹s' = mmap_map (λq (q', tstp). (step q' bs, if accept (step q' bs) then Some (t, j) else tstp)) s›*) 1)) have lookup_s: "⋀q q' tstp. mmap_lookup s q = Some (q', tstp) ⟹ steps step rho' q (i, j) = q' ∧ tstp = sup_acc step accept rho' q i j" using valid_before (*‹reach_window args t0 sub rho (i, ti, si, j, tj, sj)› ‹⟦?i ≤ ?j; ?j < length rho⟧ ⟹ ts_at rho ?i ≤ ts_at rho ?j› ‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ step ?q ?bs = v› ‹case Mapping.lookup (ac::('b, bool) mapping) (?q::'b) of None ⇒ True | Some (v::bool) ⇒ (accept::'b ⇒ bool) ?q = v› ‹∀q. mmap_lookup e q = sup_leadsto init step rho i j q› ‹distinct (map fst e)› ‹valid_s init step st accept rho i i j s›*) Mapping_keys_intro (*‹mmap_lookup ?f ?x ≠ None ⟹ ?x ∈ mmap_keys ?f›*) by (force simp add: Let_def (*‹Let ?s ?f ≡ ?f ?s›*) rho'_def (*‹rho' = rho @ [(t, bs)]›*) valid_s_def (*‹valid_s ?init ?step ?st ?accept ?rho ?u ?i ?j ?s ≡ (∀q bs. case Mapping.lookup ?st (q, bs) of None ⇒ True | Some v ⇒ ?step q bs = v) ∧ mmap_keys ?s = {q. ∃l≤?u. steps ?step ?rho ?init (l, ?i) = q} ∧ distinct (map fst ?s) ∧ (∀q. case mmap_lookup ?s q of None ⇒ True | Some (q', tstp) ⇒ steps ?step ?rho q (?i, ?j) = q' ∧ tstp = sup_acc ?step ?accept ?rho q ?i ?j)›*) steps_app_cong (*‹?j ≤ length ?rho ⟹ steps ?step (?rho @ [?x]) ?q (?i, ?j) = steps ?step ?rho ?q (?i, ?j)›*) sup_acc_app_cong (*‹?j ≤ length ?rho ⟹ sup_acc ?step ?accept (?rho @ [?x]) ?q ?i ?j = sup_acc ?step ?accept ?rho ?q ?i ?j›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) have bs_at_rho'_j: "bs_at rho' j = bs" using valid_before (*‹reach_window args t0 sub rho (i, ti, si, j, tj, sj)› ‹⟦?i ≤ ?j; ?j < length rho⟧ ⟹ ts_at rho ?i ≤ ts_at rho ?j› ‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ step ?q ?bs = v› ‹case Mapping.lookup (ac::('b::type, bool) mapping) (?q::'b::type) of None ⇒ True | Some (v::bool) ⇒ (accept::'b::type ⇒ bool) ?q = v› ‹∀q. mmap_lookup e q = sup_leadsto init step rho i j q› ‹distinct (map fst e)› ‹valid_s init step st accept rho i i j s›*) by (auto simp: rho'_def (*‹rho' = rho @ [(t, bs)]›*) bs_at_def (*‹bs_at ?rho ?i = snd (?rho ! ?i)›*) nth_append (*‹(?xs @ ?ys) ! ?n = (if ?n < length ?xs then ?xs ! ?n else ?ys ! (?n - length ?xs))›*)) have ts_at_rho'_j: "ts_at rho' j = t" using valid_before (*‹reach_window args t0 sub rho (i, ti, si, j, tj, sj)› ‹⟦?i ≤ ?j; ?j < length rho⟧ ⟹ ts_at rho ?i ≤ ts_at rho ?j› ‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ step ?q ?bs = v› ‹case Mapping.lookup ac ?q of None ⇒ True | Some v ⇒ accept ?q = v› ‹∀q::'b::type. mmap_lookup (e::('b::type × 'c::timestamp) list) q = sup_leadsto (init::'b::type) (step::'b::type ⇒ 'a::type ⇒ 'b::type) (rho::('c::timestamp × 'a::type) list) (i::nat) (j::nat) q› ‹distinct (map fst e)› ‹valid_s init step st accept rho i i j s›*) by (auto simp: rho'_def (*‹rho' = rho @ [(t, bs)]›*) ts_at_def (*‹ts_at ?rho ?i = fst (?rho ! ?i)›*) nth_append (*‹(?xs @ ?ys) ! ?n = (if ?n < length ?xs then ?xs ! ?n else ?ys ! (?n - length ?xs))›*)) have lookup_s': "⋀q q' tstp. mmap_lookup s' q = Some (q', tstp) ⟹ steps step rho' q (i, Suc j) = q' ∧ tstp = sup_acc step accept rho' q i (Suc j)" proof (-) (*goal: ‹⋀q q' tstp. mmap_lookup s' q = Some (q', tstp) ⟹ steps step rho' q (i, Suc j) = q' ∧ tstp = sup_acc step accept rho' q i (Suc j)›*) fix q and q'' and tstp' assume assm: "mmap_lookup s' q = Some (q'', tstp')" (*‹mmap_lookup (s'::('b × 'b × ('c × nat) option) list) (q::'b) = Some (q''::'b, tstp'::('c × nat) option)›*) obtain q' and tstp where "mmap_lookup s q = Some (q', tstp)" "q'' = step q' bs" "tstp' = (if accept (step q' bs) then Some (t, j) else tstp)" (*goal: ‹(⋀q' tstp. ⟦mmap_lookup s q = Some (q', tstp); q'' = step q' bs; tstp' = (if accept (step q' bs) then Some (t, j) else tstp)⟧ ⟹ thesis) ⟹ thesis›*) using map_values_lookup[OF assm [ unfolded s'_mmap_map ]] (*‹∃v. mmap_lookup s q = Some v ∧ (q'', tstp') = (case v of (q', tstp) ⇒ (step q' bs, if accept (step q' bs) then Some (t, j) else tstp))›*) by auto then show "steps step rho' q (i, Suc j) = q'' ∧ tstp' = sup_acc step accept rho' q i (Suc j)" using lookup_s (*‹mmap_lookup (s::('b::type × 'b::type × ('c::timestamp × nat) option) list) (?q3::'b::type) = Some (?q'3::'b::type, ?tstp3::('c::timestamp × nat) option) ⟹ steps (step::'b::type ⇒ 'a::type ⇒ 'b::type) (rho'::('c::timestamp × 'a::type) list) ?q3 (i::nat, j::nat) = ?q'3 ∧ ?tstp3 = sup_acc step (accept::'b::type ⇒ bool) rho' ?q3 i j›*) apply (auto simp: bs_at_rho'_j (*‹bs_at rho' j = bs›*) ts_at_rho'_j (*‹ts_at rho' j = t›*)) (*goals: 1. ‹⟦mmap_lookup s q = Some (q', tstp); q'' = step q' bs; tstp' = Some (t, j); ⋀q q' tstp. mmap_lookup s q = Some (q', tstp) ⟹ steps step rho' q (i, j) = q' ∧ tstp = sup_acc step accept rho' q i j; accept (step q' bs)⟧ ⟹ steps step rho' q (i, Suc j) = step q' bs› 2. ‹⟦mmap_lookup s q = Some (q', tstp); q'' = step q' bs; tstp' = Some (t, j); ⋀q q' tstp. mmap_lookup s q = Some (q', tstp) ⟹ steps step rho' q (i, j) = q' ∧ tstp = sup_acc step accept rho' q i j; accept (step q' bs)⟧ ⟹ Some (t, j) = sup_acc step accept rho' q i (Suc j)› 3. ‹⟦mmap_lookup s q = Some (q', tstp); q'' = step q' bs; tstp' = tstp; ⋀q q' tstp. mmap_lookup s q = Some (q', tstp) ⟹ steps step rho' q (i, j) = q' ∧ tstp = sup_acc step accept rho' q i j; ¬ accept (step q' bs)⟧ ⟹ steps step rho' q (i, Suc j) = step q' bs› 4. ‹⟦mmap_lookup s q = Some (q', tstp); q'' = step q' bs; tstp' = tstp; ⋀q q' tstp. mmap_lookup s q = Some (q', tstp) ⟹ steps step rho' q (i, j) = q' ∧ tstp = sup_acc step accept rho' q i j; ¬ accept (step q' bs)⟧ ⟹ tstp = sup_acc step accept rho' q i (Suc j)› discuss goal 1*) apply (metis Suc_eq_plus1 (*‹Suc ?n = ?n + 1›*) bs_at_rho'_j (*‹bs_at rho' j = bs›*) i_j (*‹i ≤ j›*) steps_app (*‹?i ≤ ?j ⟹ steps ?step ?rho ?q (?i, ?j + 1) = ?step (steps ?step ?rho ?q (?i, ?j)) (bs_at ?rho ?j)›*)) (*discuss goal 2*) apply (metis acc_app (*‹⟦?i ≤ ?j; steps ?step ?rho ?q (?i, Suc ?j) = ?q'; ?accept ?q'⟧ ⟹ sup_acc ?step ?accept ?rho ?q ?i (Suc ?j) = Some (ts_at ?rho ?j, ?j)›*) bs_at_rho'_j (*‹bs_at rho' j = bs›*) i_j (*‹i ≤ j›*) steps_appE (*‹⟦?i ≤ ?j; steps ?step ?rho ?q (?i, Suc ?j) = ?q'⟧ ⟹ ∃q''. steps ?step ?rho ?q (?i, ?j) = q'' ∧ ?q' = ?step q'' (bs_at ?rho ?j)›*) ts_at_rho'_j (*‹ts_at rho' j = t›*)) (*discuss goal 3*) apply (metis Suc_eq_plus1 (*‹Suc ?n = ?n + 1›*) bs_at_rho'_j (*‹bs_at rho' j = bs›*) i_j (*‹i ≤ j›*) steps_app (*‹?i ≤ ?j ⟹ steps ?step ?rho ?q (?i, ?j + 1) = ?step (steps ?step ?rho ?q (?i, ?j)) (bs_at ?rho ?j)›*)) (*discuss goal 4*) apply (metis (no_types, lifting) acc_app_idle (*‹⟦(?i::nat) ≤ (?j::nat); steps (?step::?'a ⇒ ?'b ⇒ ?'a) (?rho::(?'c × ?'b) list) (?q::?'a) (?i, Suc ?j) = (?q'::?'a); ¬ (?accept::?'a ⇒ bool) ?q'⟧ ⟹ sup_acc ?step ?accept ?rho ?q ?i (Suc ?j) = sup_acc ?step ?accept ?rho ?q ?i ?j›*) bs_at_rho'_j (*‹bs_at (rho'::('c × 'a) list) (j::nat) = (bs::'a)›*) i_j (*‹(i::nat) ≤ (j::nat)›*) steps_appE (*‹⟦(?i::nat) ≤ (?j::nat); steps (?step::?'a ⇒ ?'b ⇒ ?'a) (?rho::(?'c × ?'b) list) (?q::?'a) (?i, Suc ?j) = (?q'::?'a)⟧ ⟹ ∃q''::?'a. steps ?step ?rho ?q (?i, ?j) = q'' ∧ ?q' = ?step q'' (bs_at ?rho ?j)›*)) (*proven 4 subgoals*) . qed have lookup_e: "⋀q. mmap_lookup e q = sup_leadsto init step rho' i j q" using valid_before (*‹reach_window args t0 sub rho (i, ti, si, j, tj, sj)› ‹⟦?i ≤ ?j; ?j < length rho⟧ ⟹ ts_at rho ?i ≤ ts_at rho ?j› ‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ step ?q ?bs = v› ‹case Mapping.lookup ac ?q of None ⇒ True | Some v ⇒ accept ?q = v› ‹∀q::'b::type. mmap_lookup (e::('b::type × 'c::timestamp) list) q = sup_leadsto (init::'b::type) (step::'b::type ⇒ 'a::type ⇒ 'b::type) (rho::('c::timestamp × 'a::type) list) (i::nat) (j::nat) q› ‹distinct (map fst e)› ‹valid_s init step st accept rho i i j s›*) sup_leadsto_app_cong[of _ _ rho init step] (*‹⟦(?i::nat) ≤ (?j::nat); ?j ≤ length (rho::('c::timestamp × 'a::type) list)⟧ ⟹ sup_leadsto (init::'b::type) (step::'b::type ⇒ 'a::type ⇒ 'b::type) (rho @ [?x::'c::timestamp × 'a::type]) ?i ?j (?q::'b::type) = sup_leadsto init step rho ?i ?j ?q›*) by (auto simp: rho'_def (*‹rho' = rho @ [(t, bs)]›*)) have keys_e_alt: "mmap_keys e = {q. ∃l < i. steps step rho' init (l, j) = q}" using valid_before (*‹reach_window args t0 sub rho (i, ti, si, j, tj, sj)› ‹⟦?i ≤ ?j; ?j < length rho⟧ ⟹ ts_at rho ?i ≤ ts_at rho ?j› ‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ step ?q ?bs = v› ‹case Mapping.lookup ac ?q of None ⇒ True | Some v ⇒ accept ?q = v› ‹∀q. mmap_lookup e q = sup_leadsto init step rho i j q› ‹distinct (map fst e)› ‹valid_s init step st accept rho i i j s›*) apply (auto simp add: sup_leadsto_def (*‹sup_leadsto ?init ?step ?rho ?i ?j ?q = (let L' = {l. l < ?i ∧ steps ?step ?rho ?init (l, ?j) = ?q}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m))›*) rho'_def (*‹rho' = rho @ [(t, bs)]›*)) (*goals: 1. ‹⋀x. ⟦⋀i j. ⟦i ≤ j; j < length rho⟧ ⟹ ts_at rho i ≤ ts_at rho j; ⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v; ⋀q. case Mapping.lookup ac q of None ⇒ True | Some v ⇒ accept q = v; ∀q. mmap_lookup e q = (if ∀x<i. steps step rho init (x, length rho) ≠ q then None else Some (ts_at rho (Max {l. l < i ∧ steps step rho init (l, length rho) = q}))); distinct (map fst e); valid_s init step st accept rho i i (length rho) s; i ≤ length rho; j = length rho; reaches_on (w_run_t args) t0 (take i (map fst rho)) ti; reaches_on (w_run_t args) ti (drop i (map fst rho)) tj; reaches_on (w_run_sub args) sub (take i (map snd rho)) si; reaches_on (w_run_sub args) si (drop i (map snd rho)) sj; x ∈ mmap_keys e⟧ ⟹ ∃l<i. steps step (rho @ [(t, bs)]) init (l, length rho) = x› 2. ‹⋀l. ⟦⋀i j. ⟦i ≤ j; j < length rho⟧ ⟹ ts_at rho i ≤ ts_at rho j; ⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some x ⇒ step q bs = x; ⋀q. case Mapping.lookup ac q of None ⇒ True | Some x ⇒ accept q = x; ∀q. mmap_lookup e q = (if ∀x<i. steps step rho init (x, length rho) ≠ q then None else Some (ts_at rho (Max {l. l < i ∧ steps step rho init (l, length rho) = q}))); distinct (map fst e); valid_s init step st accept rho i i (length rho) s; i ≤ length rho; j = length rho; reaches_on (w_run_t args) t0 (take i (map fst rho)) ti; reaches_on (w_run_t args) ti (drop i (map fst rho)) tj; reaches_on (w_run_sub args) sub (take i (map snd rho)) si; reaches_on (w_run_sub args) si (drop i (map snd rho)) sj; l < i⟧ ⟹ steps step (rho @ [(t, bs)]) init (l, length rho) ∈ mmap_keys e› discuss goal 1*) apply (metis (no_types, lifting) Mapping_keys_dest (*‹?x ∈ mmap_keys ?f ⟹ ∃y. mmap_lookup ?f ?x = Some y›*) lookup_e (*‹mmap_lookup e ?q3 = sup_leadsto init step rho' i j ?q3›*) rho'_def (*‹rho' = rho @ [(t, bs)]›*) sup_leadsto_SomeE (*‹⟦?i ≤ ?j; sup_leadsto ?init ?step ?rho ?i ?j ?q = Some ?ts⟧ ⟹ ∃l<?i. steps ?step ?rho ?init (l, ?j) = ?q ∧ ts_at ?rho l = ?ts›*)) (*discuss goal 2*) apply (metis (no_types, lifting) Mapping_keys_intro (*‹mmap_lookup ?f ?x ≠ None ⟹ ?x ∈ mmap_keys ?f›*) option.simps( (*‹Some ?x2.0 ≠ None›*) 3) order_refl (*‹?x ≤ ?x›*) steps_app_cong (*‹?j ≤ length ?rho ⟹ steps ?step (?rho @ [?x]) ?q (?i, ?j) = steps ?step ?rho ?q (?i, ?j)›*)) (*proven 2 subgoals*) . have finite_keys_e: "finite (mmap_keys e)" unfolding keys_e_alt (*goal: ‹finite {q. ∃l<i. steps step rho' init (l, j) = q}›*) apply (rule finite_surj[of "{l. l < i}"] (*‹⟦finite {l. l < i}; ?B ⊆ ?f ` {l. l < i}⟧ ⟹ finite ?B›*)) (*goals: 1. ‹finite {l. l < i}› 2. ‹{q. ∃l<i. steps step rho' init (l, j) = q} ⊆ ?f ` {l. l < i}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have "reaches_on run_sub sub (map snd rho) sj" using valid_before (*‹reach_window (args::('a, 'b, 'c, 'd, 'e) Window.args) (t0::'d::type) (sub::'e::type) (rho::('c::timestamp × 'a::type) list) (i::nat, ti::'d::type, si::'e::type, j::nat, tj::'d::type, sj::'e::type)› ‹⟦?i ≤ ?j; ?j < length rho⟧ ⟹ ts_at rho ?i ≤ ts_at rho ?j› ‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ step ?q ?bs = v› ‹case Mapping.lookup ac ?q of None ⇒ True | Some v ⇒ accept ?q = v› ‹∀q. mmap_lookup e q = sup_leadsto init step rho i j q› ‹distinct (map fst (e::('b × 'c) list))› ‹valid_s init step st accept rho i i j s›*) reaches_on_trans (*‹⟦reaches_on ?run ?s ?vs ?s'; reaches_on ?run ?s' ?vs' ?s''⟧ ⟹ reaches_on ?run ?s (?vs @ ?vs') ?s''›*) unfolding run_sub_def sub_def (*goal: ‹reaches_on (w_run_sub args) sub (map snd rho) sj›*) by fastforce then have reaches_on': "reaches_on run_sub sub (map snd rho @ [bs]) sj'" using reaches_on_app (*‹⟦reaches_on ?run ?s ?vs ?s'; ?run ?s' = Some (?s'', ?v)⟧ ⟹ reaches_on ?run ?s (?vs @ [?v]) ?s''›*) run_sj (*‹run_sub sj = Some (sj', bs)›*) by fast have "reaches_on run_t t0 (map fst rho) tj" using valid_before (*‹reach_window args t0 sub rho (i, ti, si, j, tj, sj)› ‹⟦(?i::nat) ≤ (?j::nat); ?j < length (rho::('c × 'a) list)⟧ ⟹ ts_at rho ?i ≤ ts_at rho ?j› ‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ step ?q ?bs = v› ‹case Mapping.lookup ac ?q of None ⇒ True | Some v ⇒ accept ?q = v› ‹∀q. mmap_lookup e q = sup_leadsto init step rho i j q› ‹distinct (map fst e)› ‹valid_s init step st accept rho i i j s›*) reaches_on_trans (*‹⟦reaches_on (?run::?'a ⇒ (?'a × ?'b) option) (?s::?'a) (?vs::?'b list) (?s'::?'a); reaches_on ?run ?s' (?vs'::?'b list) (?s''::?'a)⟧ ⟹ reaches_on ?run ?s (?vs @ ?vs') ?s''›*) unfolding run_t_def (*goal: ‹reaches_on (w_run_t args) t0 (map fst rho) tj›*) by fastforce then have reach_t': "reaches_on run_t t0 (map fst rho') tj'" using reaches_on_app (*‹⟦reaches_on (?run::?'a ⇒ (?'a × ?'b) option) (?s::?'a) (?vs::?'b list) (?s'::?'a); ?run ?s' = Some (?s''::?'a, ?v::?'b)⟧ ⟹ reaches_on ?run ?s (?vs @ [?v]) ?s''›*) run_tj (*‹(run_t::'d::type ⇒ ('d::type × 'c::timestamp) option) (tj::'d::type) = Some (tj'::'d::type, t::'c::timestamp)›*) unfolding rho'_def (*goal: ‹reaches_on run_t t0 (map fst (rho @ [(t, bs)])) tj'›*) by fastforce have lookup_e': "⋀q. mmap_lookup e' q = sup_leadsto init step rho' i (Suc j) q" proof (-) (*goal: ‹⋀q. mmap_lookup e' q = sup_leadsto init step rho' i (Suc j) q›*) fix q define Z where "Z = {x ∈ mmap_keys e. step x bs = q}" show "mmap_lookup e' q = sup_leadsto init step rho' i (Suc j) q" proof (cases "Z = {}") (*goals: 1. ‹Z = {} ⟹ mmap_lookup e' q = sup_leadsto init step rho' i (Suc j) q› 2. ‹Z ≠ {} ⟹ mmap_lookup e' q = sup_leadsto init step rho' i (Suc j) q›*) case True (*‹Z = {}›*) then have "mmap_lookup e' q = None" using Z_def (*‹Z = {x ∈ mmap_keys e. step x bs = q}›*) lookup_fold_sup[OF distinct_before ( 2 )] (*‹mmap_lookup (fold_sup e ?f) ?z = (let Z = {x ∈ mmap_keys e. ?f x = ?z} in if Z = {} then None else Some (⨆⇩f⇩i⇩n ((the ∘ mmap_lookup e) ` Z)))›*) unfolding e'_fold_sup_st'' (*goal: ‹mmap_lookup (fold_sup e (λq. step q bs)) q = None›*) by (auto simp: Let_def (*‹Let ?s ?f ≡ ?f ?s›*)) moreover have "sup_leadsto init step rho' i (Suc j) q = None" proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹sup_leadsto (init::'b) (step::'b ⇒ 'a ⇒ 'b) (rho'::('c × 'a) list) (i::nat) (Suc (j::nat)) (q::'b) ≠ None ⟹ False›*) assume assm: "sup_leadsto init step rho' i (Suc j) q ≠ None" (*‹sup_leadsto (init::'b) (step::'b ⇒ 'a ⇒ 'b) (rho'::('c × 'a) list) (i::nat) (Suc (j::nat)) (q::'b) ≠ None›*) obtain l where l_def: "l < i" "steps step rho' init (l, Suc j) = q" (*goal: ‹(⋀l. ⟦l < i; steps step rho' init (l, Suc j) = q⟧ ⟹ thesis) ⟹ thesis›*) using i_j (*‹i ≤ j›*) sup_leadsto_SomeE[of i "Suc j"] (*‹⟦i ≤ Suc j; sup_leadsto ?init ?step ?rho i (Suc j) ?q = Some ?ts⟧ ⟹ ∃l<i. steps ?step ?rho ?init (l, Suc j) = ?q ∧ ts_at ?rho l = ?ts›*) assm (*‹sup_leadsto init step rho' i (Suc j) q ≠ None›*) by force have l_j: "l ≤ j" using less_le_trans[OF l_def ( 1 ) i_j] (*‹l < j›*) by auto obtain q'' where q''_def: "steps step rho' init (l, j) = q''" "step q'' bs = q" (*goal: ‹(⋀q''. ⟦steps step rho' init (l, j) = q''; step q'' bs = q⟧ ⟹ thesis) ⟹ thesis›*) using steps_appE[OF _ l_def ( 2 )] (*‹l ≤ j ⟹ ∃q''. steps step rho' init (l, j) = q'' ∧ q = step q'' (bs_at rho' j)›*) l_j (*‹(l::nat) ≤ (j::nat)›*) by (auto simp: bs_at_rho'_j (*‹bs_at rho' j = bs›*)) then have "q'' ∈ mmap_keys e" using keys_e_alt (*‹mmap_keys (e::('b × 'c) list) = {q::'b. ∃l<i::nat. steps (step::'b ⇒ 'a ⇒ 'b) (rho'::('c × 'a) list) (init::'b) (l, j::nat) = q}›*) l_def(1) (*‹l < i›*) by auto then show False using Z_def (*‹Z = {x ∈ mmap_keys e. step x bs = q}›*) q''_def(2) (*‹step q'' bs = q›*) True (*‹Z = {}›*) by auto qed ultimately show "?thesis" (*goal: ‹mmap_lookup e' q = sup_leadsto init step rho' i (Suc j) q›*) by auto next (*goal: ‹Z ≠ {} ⟹ mmap_lookup e' q = sup_leadsto init step rho' i (Suc j) q›*) case False (*‹(Z::'b set) ≠ {}›*) then have lookup_e': "mmap_lookup e' q = Some (Sup_fin ((the ∘ mmap_lookup e) ` Z))" using Z_def (*‹Z = {x ∈ mmap_keys e. step x bs = q}›*) lookup_fold_sup[OF distinct_before ( 2 )] (*‹mmap_lookup (fold_sup e ?f) ?z = (let Z = {x ∈ mmap_keys e. ?f x = ?z} in if Z = {} then None else Some (⨆⇩f⇩i⇩n ((the ∘ mmap_lookup e) ` Z)))›*) unfolding e'_fold_sup_st'' (*goal: ‹mmap_lookup (fold_sup e (λq. step q bs)) q = Some (⨆⇩f⇩i⇩n ((the ∘ mmap_lookup e) ` Z))›*) by (auto simp: Let_def (*‹Let ?s ?f ≡ ?f ?s›*)) define L where "L = {l. l < i ∧ steps step rho' init (l, Suc j) = q}" have fin_L: "finite L" unfolding L_def (*goal: ‹finite {l. l < i ∧ steps step rho' init (l, Suc j) = q}›*) by auto have Z_alt: "Z = {x. ∃l < i. steps step rho' init (l, j) = x ∧ step x bs = q}" using Z_def[unfolded keys_e_alt] (*‹Z = {x ∈ {q. ∃l<i. steps step rho' init (l, j) = q}. step x bs = q}›*) by auto have fin_Z: "finite Z" unfolding Z_alt (*goal: ‹finite {x. ∃l<i. steps step rho' init (l, j) = x ∧ step x bs = q}›*) by auto have L_nonempty: "L ≠ {}" using L_def (*‹(L::nat set) = {l::nat. l < (i::nat) ∧ steps (step::'b::type ⇒ 'a::type ⇒ 'b::type) (rho'::('c::timestamp × 'a::type) list) (init::'b::type) (l, Suc (j::nat)) = (q::'b::type)}›*) Z_alt (*‹Z = {x. ∃l<i. steps step rho' init (l, j) = x ∧ step x bs = q}›*) False (*‹Z ≠ {}›*) i_j (*‹i ≤ j›*) steps_app[of _ _ step rho q] (*‹?i ≤ ?j ⟹ steps step rho q (?i, ?j + 1) = step (steps step rho q (?i, ?j)) (bs_at rho ?j)›*) apply (auto simp: bs_at_rho'_j (*‹bs_at rho' j = bs›*)) (*goal: ‹L ≠ {}›*) by (smt Suc_eq_plus1 (*‹Suc ?n = ?n + 1›*) bs_at_rho'_j (*‹bs_at rho' j = bs›*) less_irrefl_nat (*‹?n < ?n ⟹ ?R›*) less_le_trans (*‹⟦?x < ?y; ?y ≤ ?z⟧ ⟹ ?x < ?z›*) nat_le_linear (*‹?m ≤ ?n ∨ ?n ≤ ?m›*) steps_app (*‹?i ≤ ?j ⟹ steps ?step ?rho ?q (?i, ?j + 1) = ?step (steps ?step ?rho ?q (?i, ?j)) (bs_at ?rho ?j)›*)) have sup_leadsto: "sup_leadsto init step rho' i (Suc j) q = Some (ts_at rho' (Max L))" using L_nonempty (*‹L ≠ {}›*) L_def (*‹L = {l. l < i ∧ steps step rho' init (l, Suc j) = q}›*) by (auto simp add: sup_leadsto_def (*‹sup_leadsto ?init ?step ?rho ?i ?j ?q = (let L' = {l. l < ?i ∧ steps ?step ?rho ?init (l, ?j) = ?q}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m))›*)) have j_lt_rho': "j < length rho'" using valid_before (*‹reach_window (args::('a, 'b, 'c, 'd, 'e) Window.args) (t0::'d) (sub::'e) (rho::('c × 'a) list) (i::nat, ti::'d, si::'e, j::nat, tj::'d, sj::'e)› ‹⟦(?i::nat) ≤ (?j::nat); ?j < length (rho::('c × 'a) list)⟧ ⟹ ts_at rho ?i ≤ ts_at rho ?j› ‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ step ?q ?bs = v› ‹case Mapping.lookup ac ?q of None ⇒ True | Some v ⇒ accept ?q = v› ‹∀q. mmap_lookup e q = sup_leadsto init step rho i j q› ‹distinct (map fst e)› ‹valid_s init step st accept rho i i j s›*) by (auto simp: rho'_def (*‹rho' = rho @ [(t, bs)]›*)) have "Sup_fin ((the ∘ mmap_lookup e) ` Z) = ts_at rho' (Max L)" proof (rule antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹⨆⇩f⇩i⇩n ((the ∘ mmap_lookup e) ` Z) ≤ ts_at rho' (Max L)› 2. ‹ts_at rho' (Max L) ≤ ⨆⇩f⇩i⇩n ((the ∘ mmap_lookup e) ` Z)›*) obtain z and ts where zts_def: "z ∈ Z" "(the ∘ mmap_lookup e) z = ts" "Sup_fin ((the ∘ mmap_lookup e) ` Z) = ts" (*goal: ‹(⋀z ts. ⟦z ∈ Z; (the ∘ mmap_lookup e) z = ts; ⨆⇩f⇩i⇩n ((the ∘ mmap_lookup e) ` Z) = ts⟧ ⟹ thesis) ⟹ thesis›*) proof (-) (*goal: ‹(⋀z ts. ⟦z ∈ Z; (the ∘ mmap_lookup e) z = ts; ⨆⇩f⇩i⇩n ((the ∘ mmap_lookup e) ` Z) = ts⟧ ⟹ thesis) ⟹ thesis›*) assume lassm: "⋀z ts. z ∈ Z ⟹ (the ∘ mmap_lookup e) z = ts ⟹ ⨆⇩f⇩i⇩n ((the ∘ mmap_lookup e) ` Z) = ts ⟹ thesis" (*‹⟦(?z3::'b) ∈ (Z::'b set); (the ∘ mmap_lookup (e::('b × 'c) list)) ?z3 = (?ts3::'c); ⨆⇩f⇩i⇩n ((the ∘ mmap_lookup e) ` Z) = ?ts3⟧ ⟹ thesis::bool›*) define T where "T = (the ∘ mmap_lookup e) ` Z" have T_sub: "T ⊆ ts_at rho' ` {..j}" using lookup_e (*‹mmap_lookup (e::('b::type × 'c::timestamp) list) (?q3::'b::type) = sup_leadsto (init::'b::type) (step::'b::type ⇒ 'a::type ⇒ 'b::type) (rho'::('c::timestamp × 'a::type) list) (i::nat) (j::nat) ?q3›*) keys_e_alt (*‹mmap_keys e = {q. ∃l<i. steps step rho' init (l, j) = q}›*) i_j (*‹i ≤ j›*) by (auto simp add: T_def (*‹T = (the ∘ mmap_lookup e) ` Z›*) Z_def (*‹Z = {x ∈ mmap_keys e. step x bs = q}›*) sup_leadsto_def (*‹sup_leadsto ?init ?step ?rho ?i ?j ?q = (let L' = {l. l < ?i ∧ steps ?step ?rho ?init (l, ?j) = ?q}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m))›*)) have "finite T" "T ≠ {}" using fin_Z (*‹finite Z›*) False (*‹(Z::'b::type set) ≠ {}›*) apply - (*goals: 1. ‹⟦finite Z; Z ≠ {}⟧ ⟹ finite T› 2. ‹⟦finite Z; Z ≠ {}⟧ ⟹ T ≠ {}› discuss goal 1*) apply ((auto simp add: T_def (*‹T = (the ∘ mmap_lookup e) ` Z›*))[1]) (*discuss goal 2*) apply ((auto simp add: T_def (*‹T = (the ∘ mmap_lookup e) ` Z›*))[1]) (*proven 2 subgoals*) . then have sup_in: "⨆⇩f⇩i⇩n T ∈ T" proof (rule sup_fin_closed (*‹⟦finite ?A; ?A ≠ {}; ⋀x y. ⟦x ∈ ?A; y ∈ ?A⟧ ⟹ sup x y ∈ {x, y}⟧ ⟹ ⨆⇩f⇩i⇩n ?A ∈ ?A›*)) (*goal: ‹⋀x y. ⟦x ∈ T; y ∈ T⟧ ⟹ sup x y ∈ {x, y}›*) fix x and y assume xy: "x ∈ T" "y ∈ T" (*‹(x::'c) ∈ (T::'c set)› ‹(y::'c) ∈ (T::'c set)›*) then obtain a and c where "x = ts_at rho' a" "y = ts_at rho' c" "a ≤ j" "c ≤ j" (*goal: ‹(⋀a c. ⟦x = ts_at rho' a; y = ts_at rho' c; a ≤ j; c ≤ j⟧ ⟹ thesis) ⟹ thesis›*) using T_sub (*‹T ⊆ ts_at rho' ` {..j}›*) by (meson atMost_iff (*‹(?i ∈ {..?k}) = (?i ≤ ?k)›*) imageE (*‹⟦?b ∈ ?f ` ?A; ⋀x. ⟦?b = ?f x; x ∈ ?A⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) subsetD (*‹⟦?A ⊆ ?B; ?c ∈ ?A⟧ ⟹ ?c ∈ ?B›*)) then show "sup x y ∈ {x, y}" using ts_at_mono (*‹⟦?i1 ≤ ?j1; ?j1 < length rho'⟧ ⟹ ts_at rho' ?i1 ≤ ts_at rho' ?j1›*) j_lt_rho' (*‹(j::nat) < length (rho'::('c × 'a) list)›*) apply (cases "a ≤ c") (*goals: 1. ‹⟦x = ts_at rho' a; y = ts_at rho' c; a ≤ j; c ≤ j; ⋀i j. ⟦i ≤ j; j < length rho'⟧ ⟹ ts_at rho' i ≤ ts_at rho' j; j < length rho'; a ≤ c⟧ ⟹ sup x y ∈ {x, y}› 2. ‹⟦x = ts_at rho' a; y = ts_at rho' c; a ≤ j; c ≤ j; ⋀i j. ⟦i ≤ j; j < length rho'⟧ ⟹ ts_at rho' i ≤ ts_at rho' j; j < length rho'; ¬ a ≤ c⟧ ⟹ sup x y ∈ {x, y}› discuss goal 1*) apply ((auto simp add: sup.absorb1 (*‹?b ≤ ?a ⟹ sup ?a ?b = ?a›*) sup.absorb2 (*‹?a ≤ ?b ⟹ sup ?a ?b = ?b›*))[1]) (*discuss goal 2*) apply ((auto simp add: sup.absorb1 (*‹?b ≤ ?a ⟹ sup ?a ?b = ?a›*) sup.absorb2 (*‹?a ≤ ?b ⟹ sup ?a ?b = ?b›*))[1]) (*proven 2 subgoals*) . qed then show "?thesis" (*goal: ‹thesis›*) using lassm (*‹⟦?z3 ∈ Z; (the ∘ mmap_lookup e) ?z3 = ?ts3; ⨆⇩f⇩i⇩n ((the ∘ mmap_lookup e) ` Z) = ?ts3⟧ ⟹ thesis›*) by (auto simp add: T_def (*‹T = (the ∘ mmap_lookup e) ` Z›*)) qed from zts_def(2) (*‹(the ∘ mmap_lookup e) z = ts›*) have lookup_e_z: "mmap_lookup e z = Some ts" using zts_def(1) (*‹z ∈ Z›*) Z_def (*‹Z = {x ∈ mmap_keys e. step x bs = q}›*) by (auto dest: Mapping_keys_dest (*‹(?x::?'a) ∈ mmap_keys (?f::(?'a × ?'b) list) ⟹ ∃y::?'b. mmap_lookup ?f ?x = Some y›*)) have "sup_leadsto init step rho' i j z = Some ts" using lookup_e_z (*‹mmap_lookup e z = Some ts›*) lookup_e (*‹mmap_lookup e ?q3 = sup_leadsto init step rho' i j ?q3›*) by auto then obtain l where l_def: "l < i" "steps step rho' init (l, j) = z" "ts_at rho' l = ts" (*goal: ‹(⋀l. ⟦l < i; steps step rho' init (l, j) = z; ts_at rho' l = ts⟧ ⟹ thesis) ⟹ thesis›*) using sup_leadsto_SomeE[OF i_j] (*‹sup_leadsto (?init::?'b) (?step::?'b ⇒ ?'c ⇒ ?'b) (?rho::(?'a × ?'c) list) (i::nat) (j::nat) (?q::?'b) = Some (?ts::?'a) ⟹ ∃l<i. steps ?step ?rho ?init (l, j) = ?q ∧ ts_at ?rho l = ?ts›*) by (fastforce simp: rho'_def (*‹rho' = rho @ [(t, bs)]›*) ts_at_def (*‹ts_at ?rho ?i = fst (?rho ! ?i)›*) nth_append (*‹(?xs @ ?ys) ! ?n = (if ?n < length ?xs then ?xs ! ?n else ?ys ! (?n - length ?xs))›*)) have l_j: "l ≤ j" using less_le_trans[OF l_def ( 1 ) i_j] (*‹l < j›*) by auto have "l ∈ L" unfolding L_def (*goal: ‹l ∈ {l. l < i ∧ steps step rho' init (l, Suc j) = q}›*) using l_def (*‹l < i› ‹steps step rho' init (l, j) = z› ‹ts_at rho' l = ts›*) zts_def(1) (*‹z ∈ Z›*) Z_alt (*‹Z = {x. ∃l<i. steps step rho' init (l, j) = x ∧ step x bs = q}›*) apply auto (*goal: ‹(l::nat) ∈ {l::nat. l < (i::nat) ∧ steps (step::'b ⇒ 'a ⇒ 'b) (rho'::('c × 'a) list) (init::'b) (l, Suc (j::nat)) = (q::'b)}›*) by (metis (no_types, lifting) Suc_eq_plus1 (*‹Suc ?n = ?n + 1›*) bs_at_rho'_j (*‹bs_at rho' j = bs›*) l_j (*‹l ≤ j›*) steps_app (*‹?i ≤ ?j ⟹ steps ?step ?rho ?q (?i, ?j + 1) = ?step (steps ?step ?rho ?q (?i, ?j)) (bs_at ?rho ?j)›*)) then have "l ≤ Max L" "Max L < i" using L_nonempty (*‹L ≠ {}›*) fin_L (*‹finite (L::nat set)›*) apply - (*goals: 1. ‹⟦l ∈ L; L ≠ {}; finite L⟧ ⟹ l ≤ Max L› 2. ‹⟦l ∈ L; L ≠ {}; finite L⟧ ⟹ Max L < i› discuss goal 1*) apply ((auto simp add: L_def (*‹L = {l. l < i ∧ steps step rho' init (l, Suc j) = q}›*))[1]) (*discuss goal 2*) apply ((auto simp add: L_def (*‹L = {l. l < i ∧ steps step rho' init (l, Suc j) = q}›*))[1]) (*proven 2 subgoals*) . then show "Sup_fin ((the ∘ mmap_lookup e) ` Z) ≤ ts_at rho' (Max L)" unfolding zts_def(3) l_def(3)[symmetric] (*goal: ‹ts_at rho' l ≤ ts_at rho' (Max L)›*) using ts_at_mono (*‹⟦?i1 ≤ ?j1; ?j1 < length rho'⟧ ⟹ ts_at rho' ?i1 ≤ ts_at rho' ?j1›*) i_j (*‹i ≤ j›*) j_lt_rho' (*‹j < length rho'›*) by (auto simp: rho'_def (*‹rho' = rho @ [(t, bs)]›*)) next (*goal: ‹ts_at rho' (Max L) ≤ ⨆⇩f⇩i⇩n ((the ∘ mmap_lookup e) ` Z)›*) obtain l where l_def: "Max L = l" "l < i" "steps step rho' init (l, Suc j) = q" (*goal: ‹(⋀l::nat. ⟦Max (L::nat set) = l; l < (i::nat); steps (step::'b ⇒ 'a ⇒ 'b) (rho'::('c × 'a) list) (init::'b) (l, Suc (j::nat)) = (q::'b)⟧ ⟹ thesis::bool) ⟹ thesis›*) using Max_in[OF fin_L L_nonempty] (*‹Max (L::nat set) ∈ L›*) L_def (*‹(L::nat set) = {l::nat. l < (i::nat) ∧ steps (step::'b::type ⇒ 'a::type ⇒ 'b::type) (rho'::('c::timestamp × 'a::type) list) (init::'b::type) (l, Suc (j::nat)) = (q::'b::type)}›*) by auto obtain z where z_def: "steps step rho' init (l, j) = z" "step z bs = q" (*goal: ‹(⋀z. ⟦steps step rho' init (l, j) = z; step z bs = q⟧ ⟹ thesis) ⟹ thesis›*) using l_def(2,3) (*‹l < i› ‹steps step rho' init (l, Suc j) = q›*) i_j (*‹i ≤ j›*) bs_at_rho'_j (*‹bs_at (rho'::('c × 'a) list) (j::nat) = (bs::'a)›*) by (metis less_imp_le_nat (*‹(?m::nat) < (?n::nat) ⟹ ?m ≤ ?n›*) less_le_trans (*‹⟦(?x::?'a) < (?y::?'a); ?y ≤ (?z::?'a)⟧ ⟹ ?x < ?z›*) steps_appE (*‹⟦(?i::nat) ≤ (?j::nat); steps (?step::?'a ⇒ ?'b ⇒ ?'a) (?rho::(?'c × ?'b) list) (?q::?'a) (?i, Suc ?j) = (?q'::?'a)⟧ ⟹ ∃q''::?'a. steps ?step ?rho ?q (?i, ?j) = q'' ∧ ?q' = ?step q'' (bs_at ?rho ?j)›*)) have z_in_Z: "z ∈ Z" unfolding Z_alt (*goal: ‹(z::'b) ∈ {x::'b. ∃l<i::nat. steps (step::'b ⇒ 'a ⇒ 'b) (rho'::('c × 'a) list) (init::'b) (l, j::nat) = x ∧ step x (bs::'a) = (q::'b)}›*) using l_def(2) (*‹l < i›*) z_def (*‹steps step rho' init (l, j) = z› ‹step z bs = q›*) i_j (*‹i ≤ j›*) by fastforce have lookup_e_z: "mmap_lookup e z = sup_leadsto init step rho' i j z" using lookup_e (*‹mmap_lookup e ?q3 = sup_leadsto init step rho' i j ?q3›*) z_in_Z (*‹z ∈ Z›*) Z_alt (*‹(Z::'b set) = {x::'b. ∃l<i::nat. steps (step::'b ⇒ 'a ⇒ 'b) (rho'::('c × 'a) list) (init::'b) (l, j::nat) = x ∧ step x (bs::'a) = (q::'b)}›*) by auto obtain l' where l'_def: "sup_leadsto init step rho' i j z = Some (ts_at rho' l')" "l ≤ l'" "l' < i" (*goal: ‹(⋀l'. ⟦sup_leadsto init step rho' i j z = Some (ts_at rho' l'); l ≤ l'; l' < i⟧ ⟹ thesis) ⟹ thesis›*) using sup_leadsto_SomeI[OF l_def ( 2 ) z_def ( 1 )] (*‹∃l'. sup_leadsto init step rho' i j z = Some (ts_at rho' l') ∧ l ≤ l' ∧ l' < i›*) by auto have "ts_at rho' l' ∈ (the ∘ mmap_lookup e) ` Z" using lookup_e_z (*‹mmap_lookup e z = sup_leadsto init step rho' i j z›*) l'_def(1) (*‹sup_leadsto init step rho' i j z = Some (ts_at rho' l')›*) z_in_Z (*‹z ∈ Z›*) by force then have "ts_at rho' l' ≤ Sup_fin ((the ∘ mmap_lookup e) ` Z)" using Inf_fin_le_Sup_fin (*‹⟦finite ?A; ?A ≠ {}⟧ ⟹ ⨅⇩f⇩i⇩n ?A ≤ ⨆⇩f⇩i⇩n ?A›*) fin_Z (*‹finite (Z::'b set)›*) z_in_Z (*‹z ∈ Z›*) by (simp add: Sup_fin.coboundedI (*‹⟦finite ?A; ?a ∈ ?A⟧ ⟹ ?a ≤ ⨆⇩f⇩i⇩n ?A›*)) then show "ts_at rho' (Max L) ≤ Sup_fin ((the ∘ mmap_lookup e) ` Z)" unfolding l_def(1) (*goal: ‹ts_at (rho'::('c × 'a) list) (l::nat) ≤ ⨆⇩f⇩i⇩n ((the ∘ mmap_lookup (e::('b × 'c) list)) ` (Z::'b set))›*) using ts_at_mono (*‹⟦?i1 ≤ ?j1; ?j1 < length rho'⟧ ⟹ ts_at rho' ?i1 ≤ ts_at rho' ?j1›*) l'_def(2,3) (*‹l ≤ l'› ‹(l'::nat) < (i::nat)›*) i_j (*‹i ≤ j›*) j_lt_rho' (*‹j < length rho'›*) by (fastforce simp: rho'_def (*‹rho' = rho @ [(t, bs)]›*)) qed then show "?thesis" (*goal: ‹mmap_lookup e' q = sup_leadsto init step rho' i (Suc j) q›*) unfolding lookup_e' sup_leadsto (*goal: ‹Some (⨆⇩f⇩i⇩n ((the ∘ mmap_lookup e) ` Z)) = Some (ts_at rho' (Max L))›*) by auto qed qed have "distinct (map fst s')" "distinct (map fst e')" using distinct_before (*‹distinct (map fst s)› ‹distinct (map fst e)›*) mmap_fold_distinct (*‹distinct (map fst ?m) ⟹ distinct (map fst (mmap_fold ?m ?f ?c []))›*) unfolding s'_mmap_map mmap_map_fst e'_fold_sup_st'' fold_sup_def (*goals: 1. ‹distinct (map fst s)› 2. ‹distinct (map fst (mmap_fold e (λ(x, y). (step x bs, y)) sup []))›*) apply - (*goals: 1. ‹⟦distinct (map fst s); distinct (map fst e); ⋀m f c. distinct (map fst m) ⟹ distinct (map fst (mmap_fold m f c []))⟧ ⟹ distinct (map fst s)› 2. ‹⟦distinct (map fst s); distinct (map fst e); ⋀m f c. distinct (map fst m) ⟹ distinct (map fst (mmap_fold m f c []))⟧ ⟹ distinct (map fst (mmap_fold e (λ(x, y). (step x bs, y)) sup []))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . moreover have "mmap_keys s' = {q. ∃l≤i. steps step rho' init (l, i) = q}" unfolding keys_s' rho'_def (*goal: ‹mmap_keys s = {q. ∃l≤i. steps step (rho @ [(t, bs)]) init (l, i) = q}›*) using valid_before(1,7) (*‹reach_window args t0 sub rho (i, ti, si, j, tj, sj)› ‹valid_s init step st accept rho i i j s›*) valid_s_def[of init step st accept rho i i j s] (*‹valid_s init step st accept rho i i j s ≡ (∀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v) ∧ mmap_keys s = {q. ∃l≤i. steps step rho init (l, i) = q} ∧ distinct (map fst s) ∧ (∀q. case mmap_lookup s q of None ⇒ True | Some (q', tstp) ⇒ steps step rho q (i, j) = q' ∧ tstp = sup_acc step accept rho q i j)›*) by (auto simp: steps_app_cong[of _ rho step] (*‹?j ≤ length rho ⟹ steps step (rho @ [?x]) ?q (?i, ?j) = steps step rho ?q (?i, ?j)›*)) moreover have "reaches_on run_t ti (drop i (map fst rho')) tj'" "reaches_on run_sub si (drop i (map snd rho')) sj'" using valid_before (*‹reach_window (args::('a, 'b, 'c, 'd, 'e) Window.args) (t0::'d) (sub::'e) (rho::('c × 'a) list) (i::nat, ti::'d, si::'e, j::nat, tj::'d, sj::'e)› ‹⟦(?i::nat) ≤ (?j::nat); ?j < length (rho::('c × 'a) list)⟧ ⟹ ts_at rho ?i ≤ ts_at rho ?j› ‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ step ?q ?bs = v› ‹case Mapping.lookup ac ?q of None ⇒ True | Some v ⇒ accept ?q = v› ‹∀q. mmap_lookup e q = sup_leadsto init step rho i j q› ‹distinct (map fst e)› ‹valid_s (init::'b) (step::'b ⇒ 'a ⇒ 'b) (st::('b × 'a, 'b) mapping) (accept::'b ⇒ bool) (rho::('c × 'a) list) (i::nat) i (j::nat) (s::('b × 'b × ('c × nat) option) list)›*) reaches_on_app (*‹⟦reaches_on ?run ?s ?vs ?s'; ?run ?s' = Some (?s'', ?v)⟧ ⟹ reaches_on ?run ?s (?vs @ [?v]) ?s''›*) run_tj (*‹(run_t::'d ⇒ ('d × 'c) option) (tj::'d) = Some (tj'::'d, t::'c)›*) run_sj (*‹run_sub sj = Some (sj', bs)›*) apply - (*goals: 1. ‹⟦reach_window (args::('a, 'b, 'c, 'd, 'e) Window.args) (t0::'d::type) (sub::'e::type) (rho::('c::timestamp × 'a::type) list) (i::nat, ti::'d::type, si::'e::type, j::nat, tj::'d::type, sj::'e::type); ⋀(i::nat) j::nat. ⟦i ≤ j; j < length rho⟧ ⟹ ts_at rho i ≤ ts_at rho j; ⋀(q::'b::type) bs::'a::type. case Mapping.lookup (st::('b::type × 'a::type, 'b::type) mapping) (q, bs) of None ⇒ True | Some (v::'b::type) ⇒ (step::'b::type ⇒ 'a::type ⇒ 'b::type) q bs = v; ⋀q::'b::type. case Mapping.lookup (ac::('b::type, bool) mapping) q of None ⇒ True | Some (v::bool) ⇒ (accept::'b::type ⇒ bool) q = v; ∀q::'b::type. mmap_lookup (e::('b::type × 'c::timestamp) list) q = sup_leadsto (init::'b::type) step rho i j q; distinct (map fst e); valid_s init step st accept rho i i j (s::('b::type × 'b::type × ('c::timestamp × nat) option) list); ⋀(run::?'a24::type ⇒ (?'a24::type × ?'b24::type) option) (s::?'a24::type) (vs::?'b24::type list) (s'::?'a24::type) (s''::?'a24::type) v::?'b24::type. ⟦reaches_on run s vs s'; run s' = Some (s'', v)⟧ ⟹ reaches_on run s (vs @ [v]) s''; (run_t::'d::type ⇒ ('d::type × 'c::timestamp) option) tj = Some (tj'::'d::type, t::'c::timestamp); (run_sub::'e::type ⇒ ('e::type × 'a::type) option) sj = Some (sj'::'e::type, bs::'a::type)⟧ ⟹ reaches_on run_t ti (drop i (map fst (rho'::('c::timestamp × 'a::type) list))) tj'› 2. ‹⟦reach_window (args::('a, 'b, 'c, 'd, 'e) Window.args) (t0::'d::type) (sub::'e::type) (rho::('c::timestamp × 'a::type) list) (i::nat, ti::'d::type, si::'e::type, j::nat, tj::'d::type, sj::'e::type); ⋀(i::nat) j::nat. ⟦i ≤ j; j < length rho⟧ ⟹ ts_at rho i ≤ ts_at rho j; ⋀(q::'b::type) bs::'a::type. case Mapping.lookup (st::('b::type × 'a::type, 'b::type) mapping) (q, bs) of None ⇒ True | Some (v::'b::type) ⇒ (step::'b::type ⇒ 'a::type ⇒ 'b::type) q bs = v; ⋀q::'b::type. case Mapping.lookup (ac::('b::type, bool) mapping) q of None ⇒ True | Some (v::bool) ⇒ (accept::'b::type ⇒ bool) q = v; ∀q::'b::type. mmap_lookup (e::('b::type × 'c::timestamp) list) q = sup_leadsto (init::'b::type) step rho i j q; distinct (map fst e); valid_s init step st accept rho i i j (s::('b::type × 'b::type × ('c::timestamp × nat) option) list); ⋀(run::?'a10::type ⇒ (?'a10::type × ?'b10::type) option) (s::?'a10::type) (vs::?'b10::type list) (s'::?'a10::type) (s''::?'a10::type) v::?'b10::type. ⟦reaches_on run s vs s'; run s' = Some (s'', v)⟧ ⟹ reaches_on run s (vs @ [v]) s''; (run_t::'d::type ⇒ ('d::type × 'c::timestamp) option) tj = Some (tj'::'d::type, t::'c::timestamp); (run_sub::'e::type ⇒ ('e::type × 'a::type) option) sj = Some (sj'::'e::type, bs::'a::type)⟧ ⟹ reaches_on run_sub si (drop i (map snd (rho'::('c::timestamp × 'a::type) list))) sj'› discuss goal 1*) apply ((auto simp: rho'_def (*‹(rho'::('c × 'a) list) = (rho::('c × 'a) list) @ [(t::'c, bs::'a)]›*) run_t_def (*‹(run_t::'d ⇒ ('d × 'c) option) = w_run_t (args::('a, 'b, 'c, 'd, 'e) Window.args)›*) run_sub_def (*‹(run_sub::'e ⇒ ('e × 'a) option) = w_run_sub (args::('a, 'b, 'c, 'd, 'e) Window.args)›*))[1]) (*top goal: ‹⟦reach_window args t0 sub rho (i, ti, si, j, tj, sj); ⋀i j. ⟦i ≤ j; j < length rho⟧ ⟹ ts_at rho i ≤ ts_at rho j; ⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v; ⋀q. case Mapping.lookup ac q of None ⇒ True | Some v ⇒ accept q = v; ∀q. mmap_lookup e q = sup_leadsto init step rho i j q; distinct (map fst e); valid_s init step st accept rho i i j s; ⋀run s vs s' s'' v. ⟦reaches_on run s vs s'; run s' = Some (s'', v)⟧ ⟹ reaches_on run s (vs @ [v]) s''; run_t tj = Some (tj', t); run_sub sj = Some (sj', bs)⟧ ⟹ reaches_on run_t ti (drop i (map fst rho')) tj'› and 1 goal remains*) apply ((assumption)[1]) (*discuss goal 2*) by ((auto simp: rho'_def (*‹rho' = rho @ [(t, bs)]›*) run_t_def (*‹run_t = w_run_t args›*) run_sub_def (*‹run_sub = w_run_sub args›*))[1]) (*proven 2 subgoals*) ultimately show "?thesis" (*goal: ‹case adv_end args w of None ⇒ False | Some w' ⇒ valid_window args t0 sub (rho @ [(t, bs)]) w'›*) unfolding adv_end (*goal: ‹case Some (w⦇w_st := st'', w_ac := ac', w_j := Suc j, w_tj := tj', w_sj := sj', w_s := s', w_e := e'⦈) of None ⇒ False | Some w' ⇒ valid_window args t0 sub (rho @ [(t, bs)]) w'›*) using valid_before (*‹reach_window args t0 sub rho (i, ti, si, j, tj, sj)› ‹⟦?i ≤ ?j; ?j < length rho⟧ ⟹ ts_at rho ?i ≤ ts_at rho ?j› ‹case Mapping.lookup (st::('b × 'a, 'b) mapping) (?q::'b, ?bs::'a) of None ⇒ True | Some (v::'b) ⇒ (step::'b ⇒ 'a ⇒ 'b) ?q ?bs = v› ‹case Mapping.lookup ac ?q of None ⇒ True | Some v ⇒ accept ?q = v› ‹∀q. mmap_lookup e q = sup_leadsto init step rho i j q› ‹distinct (map fst e)› ‹valid_s init step st accept rho i i j s›*) lookup_e' (*‹mmap_lookup e' ?q3 = sup_leadsto init step rho' i (Suc j) ?q3›*) lookup_s' (*‹mmap_lookup s' ?q3 = Some (?q'3, ?tstp3) ⟹ steps step rho' ?q3 (i, Suc j) = ?q'3 ∧ ?tstp3 = sup_acc step accept rho' ?q3 i (Suc j)›*) ts_at_mono (*‹⟦?i1 ≤ ?j1; ?j1 < length rho'⟧ ⟹ ts_at rho' ?i1 ≤ ts_at rho' ?j1›*) s'_mmap_map(3) (*‹case Mapping.lookup ac' ?q1 of None ⇒ True | Some v ⇒ accept ?q1 = v›*) e'_fold_sup_st''(2) (*‹case Mapping.lookup st'' (?q3, ?bs3) of None ⇒ True | Some v ⇒ step ?q3 ?bs3 = v›*) by (fastforce simp: valid_window_def (*‹valid_window ?args ?t0.0 ?sub ?rho ?w = (let init = w_init ?args; step = w_step ?args; accept = w_accept ?args; run_t = w_run_t ?args; run_sub = w_run_sub ?args; st = w_st ?w; ac = w_ac ?w; i = w_i ?w; ti = w_ti ?w; si = w_si ?w; j = w_j ?w; tj = w_tj ?w; sj = w_sj ?w; s = w_s ?w; e = w_e ?w in reach_window ?args ?t0.0 ?sub ?rho (i, ti, si, j, tj, sj) ∧ (∀i j. i ≤ j ∧ j < length ?rho ⟶ ts_at ?rho i ≤ ts_at ?rho j) ∧ (∀q. case Mapping.lookup ac q of None ⇒ True | Some v ⇒ accept q = v) ∧ (∀q. mmap_lookup e q = sup_leadsto init step ?rho i j q) ∧ distinct (map fst e) ∧ valid_s init step st accept ?rho i i j s)›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) init_def (*‹init = w_init args›*) step_def (*‹step = w_step args›*) accept_def (*‹accept = w_accept args›*) run_t_def (*‹run_t = w_run_t args›*) run_sub_def (*‹run_sub = w_run_sub args›*) i_def (*‹i = w_i w›*) ti_def (*‹ti = w_ti w›*) si_def (*‹si = w_si w›*) j_def (*‹j = w_j w›*) tj_def (*‹tj = w_tj w›*) sj_def (*‹sj = w_sj w›*) s_def (*‹s = w_s w›*) e'_def (*‹mmap_fold' e st' (λ((x, y), st). let (q', st') = cstep step st x bs in ((q', y), st')) sup [] = (e', st'')›*) rho'_def (*‹rho' = rho @ [(t, bs)]›*) valid_s_def (*‹valid_s ?init ?step ?st ?accept ?rho ?u ?i ?j ?s ≡ (∀q bs. case Mapping.lookup ?st (q, bs) of None ⇒ True | Some v ⇒ ?step q bs = v) ∧ mmap_keys ?s = {q. ∃l≤?u. steps ?step ?rho ?init (l, ?i) = q} ∧ distinct (map fst ?s) ∧ (∀q. case mmap_lookup ?s q of None ⇒ True | Some (q', tstp) ⇒ steps ?step ?rho q (?i, ?j) = q' ∧ tstp = sup_acc ?step ?accept ?rho q ?i ?j)›*) intro!: exI[of _ rho'] (*‹?P rho' ⟹ ∃x. ?P x›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) qed lemma adv_end_bounds: assumes "w_run_t args (w_tj w) = Some (tj', t)" "w_run_sub args (w_sj w) = Some (sj', bs)" "adv_end args w = Some w'" shows "w_i w' = w_i w" "w_ti w' = w_ti w" "w_si w' = w_si w" "w_j w' = Suc (w_j w)" "w_tj w' = tj'" "w_sj w' = sj'" using assms (*‹w_run_t args (w_tj w) = Some (tj', t)› ‹w_run_sub args (w_sj w) = Some (sj', bs)› ‹adv_end args w = Some w'›*) apply - (*goals: 1. ‹⟦w_run_t (args::('c, 'd, 'b, 'a, 'e) Window.args) (w_tj (w::('c, 'd, 'b, 'a, 'e) window)) = Some (tj'::'a, t::'b); w_run_sub args (w_sj w) = Some (sj'::'e, bs::'c); adv_end args w = Some (w'::('c, 'd, 'b, 'a, 'e) window)⟧ ⟹ w_i w' = w_i w› 2. ‹⟦w_run_t (args::('c, 'd, 'b, 'a, 'e) Window.args) (w_tj (w::('c, 'd, 'b, 'a, 'e) window)) = Some (tj'::'a, t::'b); w_run_sub args (w_sj w) = Some (sj'::'e, bs::'c); adv_end args w = Some (w'::('c, 'd, 'b, 'a, 'e) window)⟧ ⟹ w_ti w' = w_ti w› 3. ‹⟦w_run_t (args::('c, 'd, 'b, 'a, 'e) Window.args) (w_tj (w::('c, 'd, 'b, 'a, 'e) window)) = Some (tj'::'a, t::'b); w_run_sub args (w_sj w) = Some (sj'::'e, bs::'c); adv_end args w = Some (w'::('c, 'd, 'b, 'a, 'e) window)⟧ ⟹ w_si w' = w_si w› 4. ‹⟦w_run_t (args::('c, 'd, 'b, 'a, 'e) Window.args) (w_tj (w::('c, 'd, 'b, 'a, 'e) window)) = Some (tj'::'a, t::'b); w_run_sub args (w_sj w) = Some (sj'::'e, bs::'c); adv_end args w = Some (w'::('c, 'd, 'b, 'a, 'e) window)⟧ ⟹ w_j w' = Suc (w_j w)› 5. ‹⟦w_run_t (args::('c, 'd, 'b, 'a, 'e) Window.args) (w_tj (w::('c, 'd, 'b, 'a, 'e) window)) = Some (tj'::'a, t::'b); w_run_sub args (w_sj w) = Some (sj'::'e, bs::'c); adv_end args w = Some (w'::('c, 'd, 'b, 'a, 'e) window)⟧ ⟹ w_tj w' = tj'› 6. ‹⟦w_run_t (args::('c, 'd, 'b, 'a, 'e) Window.args) (w_tj (w::('c, 'd, 'b, 'a, 'e) window)) = Some (tj'::'a, t::'b); w_run_sub args (w_sj w) = Some (sj'::'e, bs::'c); adv_end args w = Some (w'::('c, 'd, 'b, 'a, 'e) window)⟧ ⟹ w_sj w' = sj'› discuss goal 1*) apply ((auto simp: adv_end_def (*‹adv_end (?args::(?'b, ?'c, ?'d, ?'t, ?'e) Window.args) (?w::(?'b, ?'c, ?'d, ?'t, ?'e) window) = (let step::?'c ⇒ ?'b ⇒ ?'c = w_step ?args; accept::?'c ⇒ bool = w_accept ?args; run_t::?'t ⇒ (?'t × ?'d) option = w_run_t ?args; run_sub::?'e ⇒ (?'e × ?'b) option = w_run_sub ?args; st::(?'c × ?'b, ?'c) mapping = w_st ?w; ac::(?'c, bool) mapping = w_ac ?w; j::nat = w_j ?w; tj::?'t = w_tj ?w; sj::?'e = w_sj ?w; s::(?'c × ?'c × (?'d × nat) option) list = w_s ?w; e::(?'c × ?'d) list = w_e ?w in case run_t tj of None ⇒ None | Some (tj'::?'t, t::?'d) ⇒ case run_sub sj of None ⇒ None | Some (sj'::?'e, bs::?'b) ⇒ let (s'::(?'c × ?'c × (?'d × nat) option) list, st'::(?'c × ?'b, ?'c) mapping, ac'::(?'c, bool) mapping) = mmap_fold_s step st accept ac bs t j s; (e'::(?'c × ?'d) list, st''::(?'c × ?'b, ?'c) mapping) = mmap_fold' e st' (λ((x::?'c, y::?'d), st::(?'c × ?'b, ?'c) mapping). let (q'::?'c, st'::(?'c × ?'b, ?'c) mapping) = cstep step st x bs in ((q', y), st')) sup [] in Some (?w⦇w_st := st'', w_ac := ac', w_j := Suc j, w_tj := tj', w_sj := sj', w_s := s', w_e := e'⦈))›*) Let_def (*‹Let (?s::?'a) (?f::?'a ⇒ ?'b) ≡ ?f ?s›*) split: prod.splits (*‹(?P::?'c ⇒ bool) (case ?prod::?'a × ?'b of (x::?'a, xa::?'b) ⇒ (?f::?'a ⇒ ?'b ⇒ ?'c) x xa) = (∀(x1::?'a) x2::?'b. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹(?P::?'c ⇒ bool) (case ?prod::?'a × ?'b of (x::?'a, xa::?'b) ⇒ (?f::?'a ⇒ ?'b ⇒ ?'c) x xa) = (∄(x1::?'a) x2::?'b. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*))[1]) (*discuss goal 2*) apply ((auto simp: adv_end_def (*‹adv_end ?args ?w = (let step = w_step ?args; accept = w_accept ?args; run_t = w_run_t ?args; run_sub = w_run_sub ?args; st = w_st ?w; ac = w_ac ?w; j = w_j ?w; tj = w_tj ?w; sj = w_sj ?w; s = w_s ?w; e = w_e ?w in case run_t tj of None ⇒ None | Some (tj', t) ⇒ case run_sub sj of None ⇒ None | Some (sj', bs) ⇒ let (s', st', ac') = mmap_fold_s step st accept ac bs t j s; (e', st'') = mmap_fold' e st' (λ((x, y), st). let (q', st') = cstep step st x bs in ((q', y), st')) sup [] in Some (?w⦇w_st := st'', w_ac := ac', w_j := Suc j, w_tj := tj', w_sj := sj', w_s := s', w_e := e'⦈))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) split: prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*))[1]) (*discuss goal 3*) apply ((auto simp: adv_end_def (*‹adv_end ?args ?w = (let step = w_step ?args; accept = w_accept ?args; run_t = w_run_t ?args; run_sub = w_run_sub ?args; st = w_st ?w; ac = w_ac ?w; j = w_j ?w; tj = w_tj ?w; sj = w_sj ?w; s = w_s ?w; e = w_e ?w in case run_t tj of None ⇒ None | Some (tj', t) ⇒ case run_sub sj of None ⇒ None | Some (sj', bs) ⇒ let (s', st', ac') = mmap_fold_s step st accept ac bs t j s; (e', st'') = mmap_fold' e st' (λ((x, y), st). let (q', st') = cstep step st x bs in ((q', y), st')) sup [] in Some (?w⦇w_st := st'', w_ac := ac', w_j := Suc j, w_tj := tj', w_sj := sj', w_s := s', w_e := e'⦈))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) split: prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*))[1]) (*discuss goal 4*) apply ((auto simp: adv_end_def (*‹adv_end ?args ?w = (let step = w_step ?args; accept = w_accept ?args; run_t = w_run_t ?args; run_sub = w_run_sub ?args; st = w_st ?w; ac = w_ac ?w; j = w_j ?w; tj = w_tj ?w; sj = w_sj ?w; s = w_s ?w; e = w_e ?w in case run_t tj of None ⇒ None | Some (tj', t) ⇒ case run_sub sj of None ⇒ None | Some (sj', bs) ⇒ let (s', st', ac') = mmap_fold_s step st accept ac bs t j s; (e', st'') = mmap_fold' e st' (λ((x, y), st). let (q', st') = cstep step st x bs in ((q', y), st')) sup [] in Some (?w⦇w_st := st'', w_ac := ac', w_j := Suc j, w_tj := tj', w_sj := sj', w_s := s', w_e := e'⦈))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) split: prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*))[1]) (*discuss goal 5*) apply ((auto simp: adv_end_def (*‹adv_end ?args ?w = (let step = w_step ?args; accept = w_accept ?args; run_t = w_run_t ?args; run_sub = w_run_sub ?args; st = w_st ?w; ac = w_ac ?w; j = w_j ?w; tj = w_tj ?w; sj = w_sj ?w; s = w_s ?w; e = w_e ?w in case run_t tj of None ⇒ None | Some (tj', t) ⇒ case run_sub sj of None ⇒ None | Some (sj', bs) ⇒ let (s', st', ac') = mmap_fold_s step st accept ac bs t j s; (e', st'') = mmap_fold' e st' (λ((x, y), st). let (q', st') = cstep step st x bs in ((q', y), st')) sup [] in Some (?w⦇w_st := st'', w_ac := ac', w_j := Suc j, w_tj := tj', w_sj := sj', w_s := s', w_e := e'⦈))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) split: prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*))[1]) (*discuss goal 6*) apply ((auto simp: adv_end_def (*‹adv_end ?args ?w = (let step = w_step ?args; accept = w_accept ?args; run_t = w_run_t ?args; run_sub = w_run_sub ?args; st = w_st ?w; ac = w_ac ?w; j = w_j ?w; tj = w_tj ?w; sj = w_sj ?w; s = w_s ?w; e = w_e ?w in case run_t tj of None ⇒ None | Some (tj', t) ⇒ case run_sub sj of None ⇒ None | Some (sj', bs) ⇒ let (s', st', ac') = mmap_fold_s step st accept ac bs t j s; (e', st'') = mmap_fold' e st' (λ((x, y), st). let (q', st') = cstep step st x bs in ((q', y), st')) sup [] in Some (?w⦇w_st := st'', w_ac := ac', w_j := Suc j, w_tj := tj', w_sj := sj', w_s := s', w_e := e'⦈))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) split: prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*))[1]) (*proven 6 subgoals*) . definition drop_cur :: "nat ⇒ ('c × ('d × nat) option) ⇒ ('c × ('d × nat) option)" where "drop_cur i = (λ(q', tstp). (q', case tstp of Some (ts, tp) ⇒ if tp = i then None else tstp | None ⇒ tstp))" definition adv_d :: "('c ⇒ 'b ⇒ 'c) ⇒ ('c × 'b, 'c) mapping ⇒ nat ⇒ 'b ⇒ ('c, 'c × ('d × nat) option) mmap ⇒ (('c, 'c × ('d × nat) option) mmap × ('c × 'b, 'c) mapping)" where "adv_d step st i b s = (mmap_fold' s st (λ((x, v), st). case cstep step st x b of (x', st') ⇒ ((x', drop_cur i v), st')) (λx y. x) [])" lemma adv_d_mmap_fold: assumes inv: "⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v" and fold': "mmap_fold' s st (λ((x, v), st). case cstep step st x bs of (x', st') ⇒ ((x', drop_cur i v), st')) (λx y. x) r = (s', st')" shows "s' = mmap_fold s (λ(x, v). (step x bs, drop_cur i v)) (λx y. x) r ∧ (∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some v ⇒ step q bs = v)" proof (-) (*goal: ‹s' = mmap_fold s (λ(x, v). (step x bs, drop_cur i v)) (λx y. x) r ∧ (∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some v ⇒ step q bs = v)›*) define inv where "inv ≡ λst. ∀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v" have inv_st: "inv st" using inv (*‹case Mapping.lookup (st::('a::type × 'b::type, 'a::type) mapping) (?q::'a::type, ?bs::'b::type) of None ⇒ True | Some (v::'a::type) ⇒ (step::'a::type ⇒ 'b::type ⇒ 'a::type) ?q ?bs = v›*) by (auto simp: inv_def (*‹inv ≡ λst. ∀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v›*)) show "?thesis" (*goal: ‹s' = mmap_fold s (λ(x, v). (step x bs, drop_cur i v)) (λx y. x) r ∧ (∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some v ⇒ step q bs = v)›*) apply (rule mmap_fold'_eq[OF fold', of inv "λ(x, v). (step x bs, drop_cur i v)", OF inv_st, unfolded inv_def] (*‹(⋀(p::'a × 'c × ('d × nat) option) (e::('a × 'b, 'a) mapping) (p'::'a × 'c × ('d × nat) option) e'::('a × 'b, 'a) mapping. ⟦∀(q::'a) bs::'b. case Mapping.lookup e (q, bs) of None ⇒ True | Some (x::'a) ⇒ (step::'a ⇒ 'b ⇒ 'a) q bs = x; (case (p, e) of (x::'a × 'c × ('d × nat) option, xa::('a × 'b, 'a) mapping) ⇒ (case x of (x::'a, v::'c × ('d × nat) option) ⇒ λst::('a × 'b, 'a) mapping. case cstep step st x (bs::'b) of (x'::'a, st'::('a × 'b, 'a) mapping) ⇒ ((x', drop_cur (i::nat) v), st')) xa) = (p', e')⟧ ⟹ p' = (case p of (x::'a, v::'c × ('d × nat) option) ⇒ (step x bs, drop_cur i v)) ∧ (∀(q::'a) bs::'b. case Mapping.lookup e' (q, bs) of None ⇒ True | Some (x::'a) ⇒ step q bs = x)) ⟹ (s'::('a × 'c × ('d × nat) option) list) = mmap_fold (s::('a × 'c × ('d × nat) option) list) (λ(x::'a, v::'c × ('d × nat) option). (step x bs, drop_cur i v)) (λ(x::'c × ('d × nat) option) y::'c × ('d × nat) option. x) (r::('a × 'c × ('d × nat) option) list) ∧ (∀(q::'a) bs::'b. case Mapping.lookup (st'::('a × 'b, 'a) mapping) (q, bs) of None ⇒ True | Some (x::'a) ⇒ step q bs = x)›*)) (*goal: ‹s' = mmap_fold s (λ(x, v). (step x bs, drop_cur i v)) (λx y. x) r ∧ (∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some v ⇒ step q bs = v)›*) by (auto simp: cstep_def (*‹cstep ?step ?st ?q ?bs = (case Mapping.lookup ?st (?q, ?bs) of None ⇒ let res = ?step ?q ?bs in (res, Mapping.update (?q, ?bs) res ?st) | Some v ⇒ (v, ?st))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) Mapping.lookup_update' (*‹Mapping.lookup (Mapping.update ?k ?v ?m) ?k' = (if ?k = ?k' then Some ?v else Mapping.lookup ?m ?k')›*) split: prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*) option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) qed definition keys_idem :: "('c ⇒ 'b ⇒ 'c) ⇒ nat ⇒ 'b ⇒ ('c, 'c × ('d × nat) option) mmap ⇒ bool" where "keys_idem step i b s = (∀x ∈ mmap_keys s. ∀x' ∈ mmap_keys s. step x b = step x' b ⟶ drop_cur i (the (mmap_lookup s x)) = drop_cur i (the (mmap_lookup s x')))" lemma adv_d_keys: assumes inv: "⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v" and distinct: "distinct (map fst s)" and adv_d: "adv_d step st i bs s = (s', st')" shows "mmap_keys s' = (λq. step q bs) ` (mmap_keys s)" using adv_d_mmap_fold[OF inv adv_d [ unfolded adv_d_def ]] (*‹s' = mmap_fold s (λ(x, v). (step x bs, drop_cur i v)) (λx y. x) [] ∧ (∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some v ⇒ step q bs = v)›*) mmap_fold_set[OF distinct] (*‹set (map fst (mmap_fold (s::('a × 'a × ('c × nat) option) list) (?f::'a × 'a × ('c × nat) option ⇒ 'a × 'a × ('c × nat) option) (?c::'a × ('c × nat) option ⇒ 'a × ('c × nat) option ⇒ 'a × ('c × nat) option) [])) = (fst ∘ ?f) ` set s›*) unfolding mmap_keys_def (*goal: ‹set (map fst s') = (λq. step q bs) ` set (map fst s)›*) by fastforce lemma lookup_adv_d_None: assumes inv: "⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v" and distinct: "distinct (map fst s)" and adv_d: "adv_d step st i bs s = (s', st')" and Z_empty: "{x ∈ mmap_keys s. step x bs = z} = {}" shows "mmap_lookup s' z = None" proof (-) (*goal: ‹mmap_lookup s' z = None›*) have "z ∉ mmap_keys (mmap_fold s (λ(x, v). (step x bs, drop_cur i v)) (λx y. x) [])" using Z_empty[unfolded mmap_keys_def] (*‹{x ∈ set (map fst s). step x bs = z} = {}›*) mmap_fold_set[OF distinct] (*‹set (map fst (mmap_fold s ?f ?c [])) = (fst ∘ ?f) ` set s›*) by (auto simp: mmap_keys_def (*‹mmap_keys (?kvs::(?'a × ?'b) list) = set (map fst ?kvs)›*)) then show "?thesis" (*goal: ‹mmap_lookup s' z = None›*) using adv_d (*‹adv_d (step::'a::type ⇒ 'b::type ⇒ 'a::type) (st::('a::type × 'b::type, 'a::type) mapping) (i::nat) (bs::'b::type) (s::('a::type × 'a::type × ('c::type × nat) option) list) = (s'::('a::type × 'a::type × ('c::type × nat) option) list, st'::('a::type × 'b::type, 'a::type) mapping)›*) adv_d_mmap_fold[OF inv adv_d [ unfolded adv_d_def ]] (*‹s' = mmap_fold s (λ(x, v). (step x bs, drop_cur i v)) (λx y. x) [] ∧ (∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some v ⇒ step q bs = v)›*) unfolding adv_d_def (*goal: ‹mmap_lookup s' z = None›*) by (simp add: Mapping_lookup_None_intro (*‹(?x::?'a::type) ∉ mmap_keys (?f::(?'a::type × ?'b::type) list) ⟹ mmap_lookup ?f ?x = None›*)) qed lemma lookup_adv_d_Some: assumes inv: "⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v" and distinct: "distinct (map fst s)" and idem: "keys_idem step i bs s" and wit: "x ∈ mmap_keys s" "step x bs = z" and adv_d: "adv_d step st i bs s = (s', st')" shows "mmap_lookup s' z = Some (drop_cur i (the (mmap_lookup s x)))" proof (-) (*goal: ‹mmap_lookup s' z = Some (drop_cur i (the (mmap_lookup s x)))›*) have z_in_keys: "z ∈ mmap_keys (mmap_fold s (λ(x, v). (step x bs, drop_cur i v)) (λx y. x) [])" using wit(1,2)[unfolded mmap_keys_def] (*‹x ∈ set (map fst s)› ‹step x bs = z›*) mmap_fold_set[OF distinct] (*‹set (map fst (mmap_fold s ?f ?c [])) = (fst ∘ ?f) ` set s›*) by (force simp: mmap_keys_def (*‹mmap_keys ?kvs = set (map fst ?kvs)›*)) obtain v and vs where vs_def: "mmap_lookup s' z = Some (foldl (λx y. x) v vs)" "v # vs = map (λ(x, v). drop_cur i v) (filter (λ(k, v). step k bs = z) s)" (*goal: ‹(⋀v vs. ⟦mmap_lookup s' z = Some (foldl (λx y. x) v vs); v # vs = map (λ(x, v). drop_cur i v) (filter (λ(k, v). step k bs = z) s)⟧ ⟹ thesis) ⟹ thesis›*) using adv_d (*‹adv_d step st i bs s = (s', st')›*) adv_d_mmap_fold[OF inv adv_d [ unfolded adv_d_def ]] (*‹s' = mmap_fold s (λ(x, v). (step x bs, drop_cur i v)) (λx y. x) [] ∧ (∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some v ⇒ step q bs = v)›*) unfolding adv_d_def (*goal: ‹(⋀v vs. ⟦mmap_lookup s' z = Some (foldl (λx y. x) v vs); v # vs = map (λ(x, v). drop_cur i v) (filter (λ(k, v). step k bs = z) s)⟧ ⟹ thesis) ⟹ thesis›*) using mmap_fold_lookup[OF distinct, of "(λ(x, v). (step x bs, drop_cur i v))" "λx y. x" z] (*‹mmap_lookup (mmap_fold s (λ(x, v). (step x bs, drop_cur i v)) (λx y. x) []) z = (case map (snd ∘ (λ(x, v). (step x bs, drop_cur i v))) (filter (λ(k, v). fst (case (k, v) of (x, v) ⇒ (step x bs, drop_cur i v)) = z) s) of [] ⇒ None | v # vs ⇒ Some (foldl (λx y. x) v vs))›*) Mapping_keys_dest[OF z_in_keys] (*‹∃y. mmap_lookup (mmap_fold s (λ(x, v). (step x bs, drop_cur i v)) (λx y. x) []) z = Some y›*) by (force simp: adv_d_def (*‹adv_d ?step ?st ?i ?b ?s = mmap_fold' ?s ?st (λ((x, v), st). case cstep ?step st x ?b of (x', st') ⇒ ((x', drop_cur ?i v), st')) (λx y. x) []›*) mmap_keys_def (*‹mmap_keys ?kvs = set (map fst ?kvs)›*) split: list.splits (*‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = ((?list = [] ⟶ ?P ?f1.0) ∧ (∀x21 x22. ?list = x21 # x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = (¬ (?list = [] ∧ ¬ ?P ?f1.0 ∨ (∃x21 x22. ?list = x21 # x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*)) have "set (v # vs) = drop_cur i ` (the ∘ mmap_lookup s) ` {x ∈ mmap_keys s. step x bs = z}" proof (rule set_eqI (*‹(⋀x. (x ∈ ?A) = (x ∈ ?B)) ⟹ ?A = ?B›*), rule iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*)) (*goals: 1. ‹⋀x. x ∈ set (v # vs) ⟹ x ∈ drop_cur i ` (the ∘ mmap_lookup s) ` {x ∈ mmap_keys s. step x bs = z}› 2. ‹⋀x. x ∈ drop_cur i ` (the ∘ mmap_lookup s) ` {x ∈ mmap_keys s. step x bs = z} ⟹ x ∈ set (v # vs)›*) fix w assume "w ∈ set (v # vs)" (*‹(w::'a × ('c × nat) option) ∈ set ((v::'a × ('c × nat) option) # (vs::('a × ('c × nat) option) list))›*) then obtain x and y where xy_def: "x ∈ mmap_keys s" "step x bs = z" "(x, y) ∈ set s" "w = drop_cur i y" (*goal: ‹(⋀x y. ⟦x ∈ mmap_keys s; step x bs = z; (x, y) ∈ set s; w = drop_cur i y⟧ ⟹ thesis) ⟹ thesis›*) using vs_def(2) (*‹(v::'a::type × ('c::type × nat) option) # (vs::('a::type × ('c::type × nat) option) list) = map (λ(x::'a::type, v::'a::type × ('c::type × nat) option). drop_cur (i::nat) v) (filter (λ(k::'a::type, v::'a::type × ('c::type × nat) option). (step::'a::type ⇒ 'b::type ⇒ 'a::type) k (bs::'b::type) = (z::'a::type)) (s::('a::type × 'a::type × ('c::type × nat) option) list))›*) by (auto simp add: mmap_keys_def (*‹mmap_keys ?kvs = set (map fst ?kvs)›*) rev_image_eqI (*‹⟦?x ∈ ?A; ?b = ?f ?x⟧ ⟹ ?b ∈ ?f ` ?A›*)) show "w ∈ drop_cur i ` (the ∘ mmap_lookup s) ` {x ∈ mmap_keys s. step x bs = z}" using xy_def(1,2,4) (*‹(x::'a) ∈ mmap_keys (s::('a × 'a × ('c × nat) option) list)› ‹step x bs = z› ‹w = drop_cur i y›*) mmap_lookup_distinct[OF distinct xy_def ( 3 )] (*‹mmap_lookup s x = Some y›*) by force next (*goal: ‹⋀x. x ∈ drop_cur i ` (the ∘ mmap_lookup s) ` {x ∈ mmap_keys s. step x bs = z} ⟹ x ∈ set (v # vs)›*) fix w assume "w ∈ drop_cur i ` (the ∘ mmap_lookup s) ` {x ∈ mmap_keys s. step x bs = z}" (*‹(w::'a × ('c × nat) option) ∈ drop_cur (i::nat) ` (the ∘ mmap_lookup (s::('a × 'a × ('c × nat) option) list)) ` {x::'a ∈ mmap_keys s. (step::'a ⇒ 'b ⇒ 'a) x (bs::'b) = (z::'a)}›*) then obtain x and y where xy_def: "x ∈ mmap_keys s" "step x bs = z" "(x, y) ∈ set s" "w = drop_cur i y" (*goal: ‹(⋀(x::'a) y::'a × ('c × nat) option. ⟦x ∈ mmap_keys (s::('a × 'a × ('c × nat) option) list); (step::'a ⇒ 'b ⇒ 'a) x (bs::'b) = (z::'a); (x, y) ∈ set s; (w::'a × ('c × nat) option) = drop_cur (i::nat) y⟧ ⟹ thesis::bool) ⟹ thesis›*) using mmap_lookup_distinct[OF distinct] (*‹(?k, ?v) ∈ set s ⟹ mmap_lookup s ?k = Some ?v›*) by (auto simp add: Mapping_keys_intro (*‹mmap_lookup ?f ?x ≠ None ⟹ ?x ∈ mmap_keys ?f›*) distinct (*‹distinct (map fst s)›*) mmap_lookup_def (*‹mmap_lookup = map_of›*) dest: Mapping_keys_dest (*‹?x ∈ mmap_keys ?f ⟹ ∃y. mmap_lookup ?f ?x = Some y›*)) show "w ∈ set (v # vs)" using xy_def (*‹x ∈ mmap_keys s› ‹step x bs = z› ‹(x, y) ∈ set s› ‹w = drop_cur i y›*) by (force simp: vs_def( (*‹v # vs = map (λ(x, v). drop_cur i v) (filter (λ(k, v). step k bs = z) s)›*) 2)) qed then have "foldl (λx y. x) v vs = drop_cur i (the (mmap_lookup s x))" using wit (*‹x ∈ mmap_keys s› ‹step x bs = z›*) apply (induction vs arbitrary: v) (*goals: 1. ‹⋀v. ⟦set [v] = drop_cur i ` (the ∘ mmap_lookup s) ` {x ∈ mmap_keys s. step x bs = z}; x ∈ mmap_keys s; step x bs = z⟧ ⟹ foldl (λx y. x) v [] = drop_cur i (the (mmap_lookup s x))› 2. ‹⋀a vs v. ⟦⋀v. ⟦set (v # vs) = drop_cur i ` (the ∘ mmap_lookup s) ` {x ∈ mmap_keys s. step x bs = z}; x ∈ mmap_keys s; step x bs = z⟧ ⟹ foldl (λx y. x) v vs = drop_cur i (the (mmap_lookup s x)); set (v # a # vs) = drop_cur i ` (the ∘ mmap_lookup s) ` {x ∈ mmap_keys s. step x bs = z}; x ∈ mmap_keys s; step x bs = z⟧ ⟹ foldl (λx y. x) v (a # vs) = drop_cur i (the (mmap_lookup s x))› discuss goal 1*) apply ((auto)[1]) (*top goal: ‹⋀v. ⟦set [v] = drop_cur i ` (the ∘ mmap_lookup s) ` {x ∈ mmap_keys s. step x bs = z}; x ∈ mmap_keys s; step x bs = z⟧ ⟹ foldl (λx y. x) v [] = drop_cur i (the (mmap_lookup s x))› and 1 goal remains*) apply (smt empty_is_image (*‹({} = ?f ` ?A) = (?A = {})›*) idem (*‹keys_idem step i bs s›*) imageE (*‹⟦?b ∈ ?f ` ?A; ⋀x. ⟦?b = ?f x; x ∈ ?A⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) insert_not_empty (*‹insert ?a ?A ≠ {}›*) keys_idem_def (*‹keys_idem ?step ?i ?b ?s = (∀x∈mmap_keys ?s. ∀x'∈mmap_keys ?s. ?step x ?b = ?step x' ?b ⟶ drop_cur ?i (the (mmap_lookup ?s x)) = drop_cur ?i (the (mmap_lookup ?s x')))›*) mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*) the_elem_eq (*‹the_elem {?x} = ?x›*) the_elem_image_unique (*‹⟦?A ≠ {}; ⋀y. y ∈ ?A ⟹ ?f y = ?f ?x⟧ ⟹ the_elem (?f ` ?A) = ?f ?x›*)) (*discuss goal 2*) apply ((auto)[1]) (*goal: ‹⋀(a::'a × ('c × nat) option) (vs::('a × ('c × nat) option) list) v::'a × ('c × nat) option. ⟦⋀v::'a × ('c × nat) option. ⟦set (v # vs) = drop_cur (i::nat) ` (the ∘ mmap_lookup (s::('a × 'a × ('c × nat) option) list)) ` {x::'a ∈ mmap_keys s. (step::'a ⇒ 'b ⇒ 'a) x (bs::'b) = (z::'a)}; (x::'a) ∈ mmap_keys s; step x bs = z⟧ ⟹ foldl (λ(x::'a × ('c × nat) option) y::'a × ('c × nat) option. x) v vs = drop_cur i (the (mmap_lookup s x)); set (v # a # vs) = drop_cur i ` (the ∘ mmap_lookup s) ` {x::'a ∈ mmap_keys s. step x bs = z}; x ∈ mmap_keys s; step x bs = z⟧ ⟹ foldl (λ(x::'a × ('c × nat) option) y::'a × ('c × nat) option. x) v (a # vs) = drop_cur i (the (mmap_lookup s x))›*) apply (smt Collect_cong (*‹(⋀x. ?P x = ?Q x) ⟹ {x. ?P x} = {x. ?Q x}›*) idem (*‹keys_idem step i bs s›*) imageE (*‹⟦?b ∈ ?f ` ?A; ⋀x. ⟦?b = ?f x; x ∈ ?A⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) insert_compr (*‹insert ?a ?B = {x. x = ?a ∨ x ∈ ?B}›*) keys_idem_def (*‹keys_idem ?step ?i ?b ?s = (∀x∈mmap_keys ?s. ∀x'∈mmap_keys ?s. ?step x ?b = ?step x' ?b ⟶ drop_cur ?i (the (mmap_lookup ?s x)) = drop_cur ?i (the (mmap_lookup ?s x')))›*) mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*)) (*proven 2 subgoals*) . then show "?thesis" (*goal: ‹mmap_lookup s' z = Some (drop_cur i (the (mmap_lookup s x)))›*) using wit (*‹(x::'a) ∈ mmap_keys (s::('a × 'a × ('c × nat) option) list)› ‹step x bs = z›*) by (auto simp: vs_def( (*‹mmap_lookup s' z = Some (foldl (λx y. x) v vs)›*) 1)) qed definition "loop_cond j = (λ(st, ac, i, ti, si, q, s, tstp). i < j ∧ q ∉ mmap_keys s)" definition "loop_body step accept run_t run_sub = (λ(st, ac, i, ti, si, q, s, tstp). case run_t ti of Some (ti', t) ⇒ case run_sub si of Some (si', b) ⇒ case adv_d step st i b s of (s', st') ⇒ case cstep step st' q b of (q', st'') ⇒ case cac accept ac q' of (β, ac') ⇒ (st'', ac', Suc i, ti', si', q', s', if β then Some (t, i) else tstp))" definition "loop_inv init step accept args t0 sub rho u j tj sj = (λ(st, ac, i, ti, si, q, s, tstp). u + 1 ≤ i ∧ reach_window args t0 sub rho (i, ti, si, j, tj, sj) ∧ steps step rho init (u + 1, i) = q ∧ (∀q. case Mapping.lookup ac q of None ⇒ True | Some v ⇒ accept q = v) ∧ valid_s init step st accept rho u i j s ∧ tstp = sup_acc step accept rho init (u + 1) i)" definition mmap_update :: "'a ⇒ 'b ⇒ ('a, 'b) mmap ⇒ ('a, 'b) mmap" where "mmap_update = AList.update" lemma mmap_update_distinct: "distinct (map fst m) ⟹ distinct (map fst (mmap_update k v m))" by (auto simp: mmap_update_def (*‹mmap_update = AList.update›*) distinct_update (*‹distinct (map fst ?al) ⟹ distinct (map fst (AList.update ?k ?v ?al))›*)) definition adv_start :: "('b, 'c, 'd :: timestamp, 't, 'e) args ⇒ ('b, 'c, 'd, 't, 'e) window ⇒ ('b, 'c, 'd, 't, 'e) window" where "adv_start args w = (let init = w_init args; step = w_step args; accept = w_accept args; run_t = w_run_t args; run_sub = w_run_sub args; st = w_st w; ac = w_ac w; i = w_i w; ti = w_ti w; si = w_si w; j = w_j w; s = w_s w; e = w_e w in (case run_t ti of Some (ti', t) ⇒ (case run_sub si of Some (si', bs) ⇒ let (s', st') = adv_d step st i bs s; e' = mmap_update (fst (the (mmap_lookup s init))) t e; (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) = while (loop_cond j) (loop_body step accept run_t run_sub) (st', ac, Suc i, ti', si', init, s', None); s'' = mmap_update init (case mmap_lookup s_cur q_cur of Some (q', tstp') ⇒ (case tstp' of Some (ts, tp) ⇒ (q', tstp') | None ⇒ (q', tstp_cur)) | None ⇒ (q_cur, tstp_cur)) s' in w⦇w_st := st_cur, w_ac := ac_cur, w_i := Suc i, w_ti := ti', w_si := si', w_s := s'', w_e := e'⦈)))" lemma valid_adv_d: assumes valid_before: "valid_s init step st accept rho u i j s" and u_le_i: "u ≤ i" and i_lt_j: "i < j" and b_def: "b = bs_at rho i" and adv_d: "adv_d step st i b s = (s', st')" shows "valid_s init step st' accept rho u (i + 1) j s'" proof (-) (*goal: ‹valid_s (init::'a::type) (step::'a::type ⇒ 'b::type ⇒ 'a::type) (st'::('a::type × 'b::type, 'a::type) mapping) (accept::'a::type ⇒ bool) (rho::('c::type × 'b::type) list) (u::nat) ((i::nat) + (1::nat)) (j::nat) (s'::('a::type × 'a::type × ('c::type × nat) option) list)›*) have inv_st: "⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v" using valid_before (*‹valid_s (init::'a) (step::'a ⇒ 'b ⇒ 'a) (st::('a × 'b, 'a) mapping) (accept::'a ⇒ bool) (rho::('c × 'b) list) (u::nat) (i::nat) (j::nat) (s::('a × 'a × ('c × nat) option) list)›*) by (auto simp add: valid_s_def (*‹valid_s ?init ?step ?st ?accept ?rho ?u ?i ?j ?s ≡ (∀q bs. case Mapping.lookup ?st (q, bs) of None ⇒ True | Some v ⇒ ?step q bs = v) ∧ mmap_keys ?s = {q. ∃l≤?u. steps ?step ?rho ?init (l, ?i) = q} ∧ distinct (map fst ?s) ∧ (∀q. case mmap_lookup ?s q of None ⇒ True | Some (q', tstp) ⇒ steps ?step ?rho q (?i, ?j) = q' ∧ tstp = sup_acc ?step ?accept ?rho q ?i ?j)›*)) have keys_s: "mmap_keys s = {q. (∃l ≤ u. steps step rho init (l, i) = q)}" using valid_before (*‹valid_s init step st accept rho u i j s›*) by (auto simp add: valid_s_def (*‹valid_s ?init ?step ?st ?accept ?rho ?u ?i ?j ?s ≡ (∀q bs. case Mapping.lookup ?st (q, bs) of None ⇒ True | Some v ⇒ ?step q bs = v) ∧ mmap_keys ?s = {q. ∃l≤?u. steps ?step ?rho ?init (l, ?i) = q} ∧ distinct (map fst ?s) ∧ (∀q. case mmap_lookup ?s q of None ⇒ True | Some (q', tstp) ⇒ steps ?step ?rho q (?i, ?j) = q' ∧ tstp = sup_acc ?step ?accept ?rho q ?i ?j)›*)) have fin_keys_s: "finite (mmap_keys s)" using valid_before (*‹valid_s init step st accept rho u i j s›*) by (auto simp add: valid_s_def (*‹valid_s ?init ?step ?st ?accept ?rho ?u ?i ?j ?s ≡ (∀q bs. case Mapping.lookup ?st (q, bs) of None ⇒ True | Some v ⇒ ?step q bs = v) ∧ mmap_keys ?s = {q. ∃l≤?u. steps ?step ?rho ?init (l, ?i) = q} ∧ distinct (map fst ?s) ∧ (∀q. case mmap_lookup ?s q of None ⇒ True | Some (q', tstp) ⇒ steps ?step ?rho q (?i, ?j) = q' ∧ tstp = sup_acc ?step ?accept ?rho q ?i ?j)›*)) have lookup_s: "⋀q q' tstp. mmap_lookup s q = Some (q', tstp) ⟹ steps step rho q (i, j) = q' ∧ tstp = sup_acc step accept rho q i j" using valid_before (*‹valid_s init step st accept rho u i j s›*) Mapping_keys_intro (*‹mmap_lookup (?f::(?'b::type × ?'a::type) list) (?x::?'b::type) ≠ None ⟹ ?x ∈ mmap_keys ?f›*) apply (auto simp add: valid_s_def (*‹valid_s ?init ?step ?st ?accept ?rho ?u ?i ?j ?s ≡ (∀q bs. case Mapping.lookup ?st (q, bs) of None ⇒ True | Some v ⇒ ?step q bs = v) ∧ mmap_keys ?s = {q. ∃l≤?u. steps ?step ?rho ?init (l, ?i) = q} ∧ distinct (map fst ?s) ∧ (∀q. case mmap_lookup ?s q of None ⇒ True | Some (q', tstp) ⇒ steps ?step ?rho q (?i, ?j) = q' ∧ tstp = sup_acc ?step ?accept ?rho q ?i ?j)›*)) (*goals: 1. ‹⋀q q' tstp. ⟦mmap_lookup s q = Some (q', tstp); ⋀f x. ∃y. mmap_lookup f x = Some y ⟹ x ∈ mmap_keys f; ∀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v; mmap_keys s = {q. ∃l≤u. steps step rho init (l, i) = q}; distinct (map fst s); ∀q. case mmap_lookup s q of None ⇒ True | Some (q', tstp) ⇒ steps step rho q (i, j) = q' ∧ tstp = sup_acc step accept rho q i j⟧ ⟹ steps step rho q (i, j) = q'› 2. ‹⋀q q' tstp. ⟦mmap_lookup s q = Some (q', tstp); ⋀f x. ∃y. mmap_lookup f x = Some y ⟹ x ∈ mmap_keys f; ∀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v; mmap_keys s = {q. ∃l≤u. steps step rho init (l, i) = q}; distinct (map fst s); ∀q. case mmap_lookup s q of None ⇒ True | Some (q', tstp) ⇒ steps step rho q (i, j) = q' ∧ tstp = sup_acc step accept rho q i j⟧ ⟹ tstp = sup_acc step accept rho q i j› discuss goal 1*) apply (smt case_prodD (*‹case (?a, ?b) of (c, d) ⇒ ?f c d ⟹ ?f ?a ?b›*) option.simps( (*‹(case Some ?x2.0 of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ?f2.0 ?x2.0›*) 5)) (*discuss goal 2*) apply (smt case_prodD (*‹case (?a, ?b) of (c, d) ⇒ ?f c d ⟹ ?f ?a ?b›*) option.simps( (*‹(case Some ?x2.0 of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ?f2.0 ?x2.0›*) 5)) (*proven 2 subgoals*) . have drop_cur_i: "⋀x. x ∈ mmap_keys s ⟹ drop_cur i (the (mmap_lookup s x)) = (steps step rho (step x (bs_at rho i)) (i + 1, j), sup_acc step accept rho (step x (bs_at rho i)) (i + 1) j)" proof (-) (*goal: ‹⋀x. x ∈ mmap_keys s ⟹ drop_cur i (the (mmap_lookup s x)) = (steps step rho (step x (bs_at rho i)) (i + 1, j), sup_acc step accept rho (step x (bs_at rho i)) (i + 1) j)›*) fix x assume assms: "x ∈ mmap_keys s" (*‹(x::'a) ∈ mmap_keys (s::('a × 'a × ('c × nat) option) list)›*) obtain q and tstp where q_def: "mmap_lookup s x = Some (q, tstp)" (*goal: ‹(⋀q tstp. mmap_lookup s x = Some (q, tstp) ⟹ thesis) ⟹ thesis›*) using assms(1) (*‹x ∈ mmap_keys s›*) by (auto dest: Mapping_keys_dest (*‹?x ∈ mmap_keys ?f ⟹ ∃y. mmap_lookup ?f ?x = Some y›*)) have q_q': "q = steps step rho (step x (bs_at rho i)) (i + 1, j)" "tstp = sup_acc step accept rho x i j" using lookup_s[OF q_def] (*‹steps step rho x (i, j) = q ∧ tstp = sup_acc step accept rho x i j›*) steps_split[OF i_lt_j] (*‹steps ?step ?rho ?q (i, j) = steps ?step ?rho (?step ?q (bs_at ?rho i)) (Suc i, j)›*) assms(1) (*‹x ∈ mmap_keys s›*) by auto show "drop_cur i (the (mmap_lookup s x)) = (steps step rho (step x (bs_at rho i)) (i + 1, j), sup_acc step accept rho (step x (bs_at rho i)) (i + 1) j)" using q_def (*‹mmap_lookup s x = Some (q, tstp)›*) sup_acc_None[OF i_lt_j, of step accept rho] (*‹sup_acc (step::'a ⇒ 'b ⇒ 'a) (accept::'a ⇒ bool) (rho::('c × 'b) list) (?q::'a) (i::nat) (j::nat) = None ⟹ sup_acc step accept rho (step ?q (bs_at rho i)) (i + (1::nat)) j = None›*) sup_acc_i[OF i_lt_j, of step accept rho] (*‹sup_acc (step::'a ⇒ 'b ⇒ 'a) (accept::'a ⇒ bool) (rho::('c × 'b) list) (?q::'a) (i::nat) (j::nat) = Some (?ts::'c, i) ⟹ sup_acc step accept rho (step ?q (bs_at rho i)) (Suc i) j = None›*) sup_acc_l[OF i_lt_j, of _ step accept rho] (*‹⟦(i::nat) ≠ (?l::nat); sup_acc (step::'a ⇒ 'b ⇒ 'a) (accept::'a ⇒ bool) (rho::('c × 'b) list) (?q::'a) i (j::nat) = Some (?ts::'c, ?l)⟧ ⟹ sup_acc step accept rho ?q i j = sup_acc step accept rho (step ?q (bs_at rho i)) (Suc i) j›*) unfolding q_q' (*goal: ‹drop_cur (i::nat) (the (mmap_lookup (s::('a × 'a × ('c × nat) option) list) (x::'a))) = (steps (step::'a ⇒ 'b ⇒ 'a) (rho::('c × 'b) list) (step x (bs_at rho i)) (i + (1::nat), j::nat), sup_acc step (accept::'a ⇒ bool) rho (step x (bs_at rho i)) (i + (1::nat)) j)›*) by (auto simp add: drop_cur_def (*‹drop_cur (?i::nat) = (λ(q'::?'c::type, tstp::(?'d::type × nat) option). (q', case tstp of None ⇒ tstp | Some (ts::?'d::type, tp::nat) ⇒ if tp = ?i then None else tstp))›*) split: option.splits (*‹(?P::?'b::type ⇒ bool) (case ?option::?'a::type option of None ⇒ ?f1.0::?'b::type | Some (x::?'a::type) ⇒ (?f2.0::?'a::type ⇒ ?'b::type) x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2::?'a::type. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹(?P::?'b::type ⇒ bool) (case ?option::?'a::type option of None ⇒ ?f1.0::?'b::type | Some (x::?'a::type) ⇒ (?f2.0::?'a::type ⇒ ?'b::type) x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2::?'a::type. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) qed have valid_drop_cur: "⋀x x'. x ∈ mmap_keys s ⟹ x' ∈ mmap_keys s ⟹ step x (bs_at rho i) = step x' (bs_at rho i) ⟹ drop_cur i (the (mmap_lookup s x)) = drop_cur i (the (mmap_lookup s x'))" using drop_cur_i (*‹(?x::'a) ∈ mmap_keys (s::('a × 'a × ('c × nat) option) list) ⟹ drop_cur (i::nat) (the (mmap_lookup s ?x)) = (steps (step::'a ⇒ 'b ⇒ 'a) (rho::('c × 'b) list) (step ?x (bs_at rho i)) (i + (1::nat), j::nat), sup_acc step (accept::'a ⇒ bool) rho (step ?x (bs_at rho i)) (i + (1::nat)) j)›*) by auto then have keys_idem: "keys_idem step i b s" unfolding keys_idem_def b_def (*goal: ‹∀x::'a::type∈mmap_keys (s::('a::type × 'a::type × ('c::type × nat) option) list). ∀x'::'a::type∈mmap_keys s. (step::'a::type ⇒ 'b::type ⇒ 'a::type) x (bs_at (rho::('c::type × 'b::type) list) (i::nat)) = step x' (bs_at rho i) ⟶ drop_cur i (the (mmap_lookup s x)) = drop_cur i (the (mmap_lookup s x'))›*) by blast have distinct: "distinct (map fst s)" using valid_before (*‹valid_s init step st accept rho u i j s›*) by (auto simp: valid_s_def (*‹valid_s ?init ?step ?st ?accept ?rho ?u ?i ?j ?s ≡ (∀q bs. case Mapping.lookup ?st (q, bs) of None ⇒ True | Some v ⇒ ?step q bs = v) ∧ mmap_keys ?s = {q. ∃l≤?u. steps ?step ?rho ?init (l, ?i) = q} ∧ distinct (map fst ?s) ∧ (∀q. case mmap_lookup ?s q of None ⇒ True | Some (q', tstp) ⇒ steps ?step ?rho q (?i, ?j) = q' ∧ tstp = sup_acc ?step ?accept ?rho q ?i ?j)›*)) have "(λq. step q (bs_at rho i)) ` {q. ∃l≤u. steps step rho init (l, i) = q} = {q. ∃l≤u. steps step rho init (l, i + 1) = q}" using steps_app[of _ i step rho init] (*‹?i ≤ i ⟹ steps step rho init (?i, i + 1) = step (steps step rho init (?i, i)) (bs_at rho i)›*) u_le_i (*‹(u::nat) ≤ (i::nat)›*) by auto then have keys_s': "mmap_keys s' = {q. ∃l≤u. steps step rho init (l, i + 1) = q}" using adv_d_keys[OF _ distinct adv_d] (*‹(⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v) ⟹ mmap_keys s' = (λq. step q b) ` mmap_keys s›*) inv_st (*‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ step ?q ?bs = v›*) unfolding keys_s b_def (*goal: ‹mmap_keys (s'::('a::type × 'a::type × ('c::type × nat) option) list) = {q::'a::type. ∃l≤u::nat. steps (step::'a::type ⇒ 'b::type ⇒ 'a::type) (rho::('c::type × 'b::type) list) (init::'a::type) (l, (i::nat) + (1::nat)) = q}›*) by auto have lookup_s': "⋀q q' tstp. mmap_lookup s' q = Some (q', tstp) ⟹ steps step rho q (i + 1, j) = q' ∧ tstp = sup_acc step accept rho q (i + 1) j" proof (-) (*goal: ‹⋀q q' tstp. mmap_lookup s' q = Some (q', tstp) ⟹ steps step rho q (i + 1, j) = q' ∧ tstp = sup_acc step accept rho q (i + 1) j›*) fix q and q' and tstp assume assm: "mmap_lookup s' q = Some (q', tstp)" (*‹mmap_lookup (s'::('a × 'a × ('c × nat) option) list) (q::'a) = Some (q'::'a, tstp::('c × nat) option)›*) obtain x where wit: "x ∈ mmap_keys s" "step x (bs_at rho i) = q" (*goal: ‹(⋀x. ⟦x ∈ mmap_keys s; step x (bs_at rho i) = q⟧ ⟹ thesis) ⟹ thesis›*) using assm (*‹mmap_lookup s' q = Some (q', tstp)›*) lookup_adv_d_None[OF _ distinct adv_d] (*‹⟦⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v; {x ∈ mmap_keys s. step x b = ?z} = {}⟧ ⟹ mmap_lookup s' ?z = None›*) inv_st (*‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ step ?q ?bs = v›*) by (fastforce simp: b_def (*‹b = bs_at rho i›*)) have lookup_s'_q: "mmap_lookup s' q = Some (drop_cur i (the (mmap_lookup s x)))" using lookup_adv_d_Some[OF _ distinct keys_idem wit [ folded b_def ] adv_d] (*‹(⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v) ⟹ mmap_lookup s' q = Some (drop_cur i (the (mmap_lookup s x)))›*) inv_st (*‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ step ?q ?bs = v›*) by auto then show "steps step rho q (i + 1, j) = q' ∧ tstp = sup_acc step accept rho q (i + 1) j" using assm (*‹mmap_lookup s' q = Some (q', tstp)›*) by (simp add: drop_cur_i (*‹(?x::'a) ∈ mmap_keys (s::('a × 'a × ('c × nat) option) list) ⟹ drop_cur (i::nat) (the (mmap_lookup s ?x)) = (steps (step::'a ⇒ 'b ⇒ 'a) (rho::('c × 'b) list) (step ?x (bs_at rho i)) (i + (1::nat), j::nat), sup_acc step (accept::'a ⇒ bool) rho (step ?x (bs_at rho i)) (i + (1::nat)) j)›*) wit (*‹(x::'a) ∈ mmap_keys (s::('a × 'a × ('c × nat) option) list)› ‹(step::'a ⇒ 'b ⇒ 'a) (x::'a) (bs_at (rho::('c × 'b) list) (i::nat)) = (q::'a)›*)) qed have "distinct (map fst s')" using mmap_fold_distinct[OF distinct] (*‹distinct (map fst (mmap_fold (s::('a × 'a × ('c × nat) option) list) (?f::'a × 'a × ('c × nat) option ⇒ 'a × 'a × ('c × nat) option) (?c::'a × ('c × nat) option ⇒ 'a × ('c × nat) option ⇒ 'a × ('c × nat) option) []))›*) adv_d_mmap_fold[OF inv_st adv_d [ unfolded adv_d_def ]] (*‹s' = mmap_fold s (λ(x, v). (step x b, drop_cur i v)) (λx y. x) [] ∧ (∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some v ⇒ step q bs = v)›*) unfolding adv_d_def mmap_map_fst (*goal: ‹distinct (map fst s')›*) by auto then show "valid_s init step st' accept rho u (i + 1) j s'" unfolding valid_s_def (*goal: ‹(∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some v ⇒ step q bs = v) ∧ mmap_keys s' = {q. ∃l≤u. steps step rho init (l, i + 1) = q} ∧ distinct (map fst s') ∧ (∀q. case mmap_lookup s' q of None ⇒ True | Some (q', tstp) ⇒ steps step rho q (i + 1, j) = q' ∧ tstp = sup_acc step accept rho q (i + 1) j)›*) using keys_s' (*‹mmap_keys s' = {q. ∃l≤u. steps step rho init (l, i + 1) = q}›*) lookup_s' (*‹mmap_lookup (s'::('a::type × 'a::type × ('c::type × nat) option) list) (?q::'a::type) = Some (?q'::'a::type, ?tstp::('c::type × nat) option) ⟹ steps (step::'a::type ⇒ 'b::type ⇒ 'a::type) (rho::('c::type × 'b::type) list) ?q ((i::nat) + (1::nat), j::nat) = ?q' ∧ ?tstp = sup_acc step (accept::'a::type ⇒ bool) rho ?q (i + (1::nat)) j›*) u_le_i (*‹u ≤ i›*) inv_st (*‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ step ?q ?bs = v›*) adv_d[unfolded adv_d_def] (*‹mmap_fold' s st (λ((x, v), st). case cstep step st x b of (x', x) ⇒ ((x', drop_cur i v), x)) (λx y. x) [] = (s', st')›*) adv_d_mmap_fold[OF inv_st adv_d [ unfolded adv_d_def ]] (*‹s' = mmap_fold s (λ(x, v). (step x b, drop_cur i v)) (λx y. x) [] ∧ (∀q bs. case Mapping.lookup st' (q, bs) of None ⇒ True | Some v ⇒ step q bs = v)›*) by (auto split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) dest: Mapping_keys_dest (*‹?x ∈ mmap_keys ?f ⟹ ∃y. mmap_lookup ?f ?x = Some y›*)) qed lemma mmap_lookup_update': "mmap_lookup (mmap_update k v kvs) z = (if k = z then Some v else mmap_lookup kvs z)" unfolding mmap_lookup_def mmap_update_def (*goal: ‹map_of (AList.update k v kvs) z = (if k = z then Some v else map_of kvs z)›*) by (auto simp add: update_conv' (*‹map_of (AList.update ?k ?v ?al) = (map_of ?al)(?k ↦ ?v)›*)) lemma mmap_keys_update: "mmap_keys (mmap_update k v kvs) = mmap_keys kvs ∪ {k}" apply (induction kvs) (*goals: 1. ‹mmap_keys (mmap_update k v []) = mmap_keys [] ∪ {k}› 2. ‹⋀a kvs. mmap_keys (mmap_update k v kvs) = mmap_keys kvs ∪ {k} ⟹ mmap_keys (mmap_update k v (a # kvs)) = mmap_keys (a # kvs) ∪ {k}› discuss goal 1*) apply ((auto simp: mmap_keys_def (*‹mmap_keys ?kvs = set (map fst ?kvs)›*) mmap_update_def (*‹mmap_update = AList.update›*))[1]) (*discuss goal 2*) apply ((auto simp: mmap_keys_def (*‹mmap_keys ?kvs = set (map fst ?kvs)›*) mmap_update_def (*‹mmap_update = AList.update›*))[1]) (*proven 2 subgoals*) . lemma valid_adv_start: assumes "valid_window args t0 sub rho w" "w_i w < w_j w" shows "valid_window args t0 sub rho (adv_start args w)" proof (-) (*goal: ‹valid_window args t0 sub rho (adv_start args w)›*) define init where "init = w_init args" define step where "step = w_step args" define accept where "accept = w_accept args" define run_t where "run_t = w_run_t args" define run_sub where "run_sub = w_run_sub args" define st where "st = w_st w" define ac where "ac = w_ac w" define i where "i = w_i w" define ti where "ti = w_ti w" define si where "si = w_si w" define j where "j = w_j w" define tj where "tj = w_tj w" define sj where "sj = w_sj w" define s where "s = w_s w" define e where "e = w_e w" have valid_before: "reach_window args t0 sub rho (i, ti, si, j, tj, sj)" "⋀i j. i ≤ j ⟹ j < length rho ⟹ ts_at rho i ≤ ts_at rho j" "(⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v)" "(⋀q bs. case Mapping.lookup ac q of None ⇒ True | Some v ⇒ accept q = v)" "∀q. mmap_lookup e q = sup_leadsto init step rho i j q" "distinct (map fst e)" "valid_s init step st accept rho i i j s" using assms(1) (*‹valid_window args t0 sub rho w›*) unfolding valid_window_def valid_s_def Let_def init_def step_def accept_def run_t_def run_sub_def st_def ac_def i_def ti_def si_def j_def tj_def sj_def s_def e_def (*goals: 1. ‹reach_window args t0 sub rho (w_i w, w_ti w, w_si w, w_j w, w_tj w, w_sj w)› 2. ‹⋀i j. ⟦i ≤ j; j < length rho⟧ ⟹ ts_at rho i ≤ ts_at rho j› 3. ‹⋀q bs. case Mapping.lookup (w_st w) (q, bs) of None ⇒ True | Some v ⇒ w_step args q bs = v› 4. ‹⋀q bs. case Mapping.lookup (w_ac w) q of None ⇒ True | Some v ⇒ w_accept args q = v› 5. ‹∀q. mmap_lookup (w_e w) q = sup_leadsto (w_init args) (w_step args) rho (w_i w) (w_j w) q› 6. ‹distinct (map fst (w_e w))› 7. ‹(∀q bs. case Mapping.lookup (w_st w) (q, bs) of None ⇒ True | Some v ⇒ w_step args q bs = v) ∧ mmap_keys (w_s w) = {q. ∃l≤w_i w. steps (w_step args) rho (w_init args) (l, w_i w) = q} ∧ distinct (map fst (w_s w)) ∧ (∀q. case mmap_lookup (w_s w) q of None ⇒ True | Some (q', tstp) ⇒ steps (w_step args) rho q (w_i w, w_j w) = q' ∧ tstp = sup_acc (w_step args) (w_accept args) rho q (w_i w) (w_j w))›*) apply - (*goals: 1. ‹reach_window args t0 sub rho (w_i w, w_ti w, w_si w, w_j w, w_tj w, w_sj w) ∧ (∀i j. i ≤ j ∧ j < length rho ⟶ ts_at rho i ≤ ts_at rho j) ∧ (∀q. case Mapping.lookup (w_ac w) q of None ⇒ True | Some x ⇒ w_accept args q = x) ∧ (∀q. mmap_lookup (w_e w) q = sup_leadsto (w_init args) (w_step args) rho (w_i w) (w_j w) q) ∧ distinct (map fst (w_e w)) ∧ (∀q bs. case Mapping.lookup (w_st w) (q, bs) of None ⇒ True | Some x ⇒ w_step args q bs = x) ∧ mmap_keys (w_s w) = {q. ∃l≤w_i w. steps (w_step args) rho (w_init args) (l, w_i w) = q} ∧ distinct (map fst (w_s w)) ∧ (∀q. case mmap_lookup (w_s w) q of None ⇒ True | Some (q', tstp) ⇒ steps (w_step args) rho q (w_i w, w_j w) = q' ∧ tstp = sup_acc (w_step args) (w_accept args) rho q (w_i w) (w_j w)) ⟹ reach_window args t0 sub rho (w_i w, w_ti w, w_si w, w_j w, w_tj w, w_sj w)› 2. ‹⋀i j. ⟦i ≤ j; j < length rho; reach_window args t0 sub rho (w_i w, w_ti w, w_si w, w_j w, w_tj w, w_sj w) ∧ (∀i j. i ≤ j ∧ j < length rho ⟶ ts_at rho i ≤ ts_at rho j) ∧ (∀q. case Mapping.lookup (w_ac w) q of None ⇒ True | Some x ⇒ w_accept args q = x) ∧ (∀q. mmap_lookup (w_e w) q = sup_leadsto (w_init args) (w_step args) rho (w_i w) (w_j w) q) ∧ distinct (map fst (w_e w)) ∧ (∀q bs. case Mapping.lookup (w_st w) (q, bs) of None ⇒ True | Some x ⇒ w_step args q bs = x) ∧ mmap_keys (w_s w) = {q. ∃l≤w_i w. steps (w_step args) rho (w_init args) (l, w_i w) = q} ∧ distinct (map fst (w_s w)) ∧ (∀q. case mmap_lookup (w_s w) q of None ⇒ True | Some (q', tstp) ⇒ steps (w_step args) rho q (w_i w, w_j w) = q' ∧ tstp = sup_acc (w_step args) (w_accept args) rho q (w_i w) (w_j w))⟧ ⟹ ts_at rho i ≤ ts_at rho j› 3. ‹⋀q bs. reach_window args t0 sub rho (w_i w, w_ti w, w_si w, w_j w, w_tj w, w_sj w) ∧ (∀i j. i ≤ j ∧ j < length rho ⟶ ts_at rho i ≤ ts_at rho j) ∧ (∀q. case Mapping.lookup (w_ac w) q of None ⇒ True | Some x ⇒ w_accept args q = x) ∧ (∀q. mmap_lookup (w_e w) q = sup_leadsto (w_init args) (w_step args) rho (w_i w) (w_j w) q) ∧ distinct (map fst (w_e w)) ∧ (∀q bs. case Mapping.lookup (w_st w) (q, bs) of None ⇒ True | Some x ⇒ w_step args q bs = x) ∧ mmap_keys (w_s w) = {q. ∃l≤w_i w. steps (w_step args) rho (w_init args) (l, w_i w) = q} ∧ distinct (map fst (w_s w)) ∧ (∀q. case mmap_lookup (w_s w) q of None ⇒ True | Some (q', tstp) ⇒ steps (w_step args) rho q (w_i w, w_j w) = q' ∧ tstp = sup_acc (w_step args) (w_accept args) rho q (w_i w) (w_j w)) ⟹ case Mapping.lookup (w_st w) (q, bs) of None ⇒ True | Some v ⇒ w_step args q bs = v› 4. ‹⋀q bs. reach_window args t0 sub rho (w_i w, w_ti w, w_si w, w_j w, w_tj w, w_sj w) ∧ (∀i j. i ≤ j ∧ j < length rho ⟶ ts_at rho i ≤ ts_at rho j) ∧ (∀q. case Mapping.lookup (w_ac w) q of None ⇒ True | Some x ⇒ w_accept args q = x) ∧ (∀q. mmap_lookup (w_e w) q = sup_leadsto (w_init args) (w_step args) rho (w_i w) (w_j w) q) ∧ distinct (map fst (w_e w)) ∧ (∀q bs. case Mapping.lookup (w_st w) (q, bs) of None ⇒ True | Some x ⇒ w_step args q bs = x) ∧ mmap_keys (w_s w) = {q. ∃l≤w_i w. steps (w_step args) rho (w_init args) (l, w_i w) = q} ∧ distinct (map fst (w_s w)) ∧ (∀q. case mmap_lookup (w_s w) q of None ⇒ True | Some (q', tstp) ⇒ steps (w_step args) rho q (w_i w, w_j w) = q' ∧ tstp = sup_acc (w_step args) (w_accept args) rho q (w_i w) (w_j w)) ⟹ case Mapping.lookup (w_ac w) q of None ⇒ True | Some v ⇒ w_accept args q = v› 5. ‹reach_window args t0 sub rho (w_i w, w_ti w, w_si w, w_j w, w_tj w, w_sj w) ∧ (∀i j. i ≤ j ∧ j < length rho ⟶ ts_at rho i ≤ ts_at rho j) ∧ (∀q. case Mapping.lookup (w_ac w) q of None ⇒ True | Some x ⇒ w_accept args q = x) ∧ (∀q. mmap_lookup (w_e w) q = sup_leadsto (w_init args) (w_step args) rho (w_i w) (w_j w) q) ∧ distinct (map fst (w_e w)) ∧ (∀q bs. case Mapping.lookup (w_st w) (q, bs) of None ⇒ True | Some x ⇒ w_step args q bs = x) ∧ mmap_keys (w_s w) = {q. ∃l≤w_i w. steps (w_step args) rho (w_init args) (l, w_i w) = q} ∧ distinct (map fst (w_s w)) ∧ (∀q. case mmap_lookup (w_s w) q of None ⇒ True | Some (q', tstp) ⇒ steps (w_step args) rho q (w_i w, w_j w) = q' ∧ tstp = sup_acc (w_step args) (w_accept args) rho q (w_i w) (w_j w)) ⟹ ∀q. mmap_lookup (w_e w) q = sup_leadsto (w_init args) (w_step args) rho (w_i w) (w_j w) q› 6. ‹reach_window args t0 sub rho (w_i w, w_ti w, w_si w, w_j w, w_tj w, w_sj w) ∧ (∀i j. i ≤ j ∧ j < length rho ⟶ ts_at rho i ≤ ts_at rho j) ∧ (∀q. case Mapping.lookup (w_ac w) q of None ⇒ True | Some x ⇒ w_accept args q = x) ∧ (∀q. mmap_lookup (w_e w) q = sup_leadsto (w_init args) (w_step args) rho (w_i w) (w_j w) q) ∧ distinct (map fst (w_e w)) ∧ (∀q bs. case Mapping.lookup (w_st w) (q, bs) of None ⇒ True | Some x ⇒ w_step args q bs = x) ∧ mmap_keys (w_s w) = {q. ∃l≤w_i w. steps (w_step args) rho (w_init args) (l, w_i w) = q} ∧ distinct (map fst (w_s w)) ∧ (∀q. case mmap_lookup (w_s w) q of None ⇒ True | Some (q', tstp) ⇒ steps (w_step args) rho q (w_i w, w_j w) = q' ∧ tstp = sup_acc (w_step args) (w_accept args) rho q (w_i w) (w_j w)) ⟹ distinct (map fst (w_e w))› 7. ‹reach_window args t0 sub rho (w_i w, w_ti w, w_si w, w_j w, w_tj w, w_sj w) ∧ (∀i j. i ≤ j ∧ j < length rho ⟶ ts_at rho i ≤ ts_at rho j) ∧ (∀q. case Mapping.lookup (w_ac w) q of None ⇒ True | Some x ⇒ w_accept args q = x) ∧ (∀q. mmap_lookup (w_e w) q = sup_leadsto (w_init args) (w_step args) rho (w_i w) (w_j w) q) ∧ distinct (map fst (w_e w)) ∧ (∀q bs. case Mapping.lookup (w_st w) (q, bs) of None ⇒ True | Some x ⇒ w_step args q bs = x) ∧ mmap_keys (w_s w) = {q. ∃l≤w_i w. steps (w_step args) rho (w_init args) (l, w_i w) = q} ∧ distinct (map fst (w_s w)) ∧ (∀q. case mmap_lookup (w_s w) q of None ⇒ True | Some (q', tstp) ⇒ steps (w_step args) rho q (w_i w, w_j w) = q' ∧ tstp = sup_acc (w_step args) (w_accept args) rho q (w_i w) (w_j w)) ⟹ (∀q bs. case Mapping.lookup (w_st w) (q, bs) of None ⇒ True | Some v ⇒ w_step args q bs = v) ∧ mmap_keys (w_s w) = {q. ∃l≤w_i w. steps (w_step args) rho (w_init args) (l, w_i w) = q} ∧ distinct (map fst (w_s w)) ∧ (∀q. case mmap_lookup (w_s w) q of None ⇒ True | Some (q', tstp) ⇒ steps (w_step args) rho q (w_i w, w_j w) = q' ∧ tstp = sup_acc (w_step args) (w_accept args) rho q (w_i w) (w_j w))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*proven 7 subgoals*) . have distinct_before: "distinct (map fst s)" "distinct (map fst e)" using valid_before (*‹reach_window args t0 sub rho (i, ti, si, j, tj, sj)› ‹⟦?i ≤ ?j; ?j < length rho⟧ ⟹ ts_at rho ?i ≤ ts_at rho ?j› ‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ step ?q ?bs = v› ‹case Mapping.lookup ac ?q of None ⇒ True | Some v ⇒ accept ?q = v› ‹∀q. mmap_lookup e q = sup_leadsto init step rho i j q› ‹distinct (map fst e)› ‹valid_s init step st accept rho i i j s›*) apply - (*goals: 1. ‹⟦reach_window args t0 sub rho (i, ti, si, j, tj, sj); ⋀i j. ⟦i ≤ j; j < length rho⟧ ⟹ ts_at rho i ≤ ts_at rho j; ⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v; ⋀q. case Mapping.lookup ac q of None ⇒ True | Some v ⇒ accept q = v; ∀q. mmap_lookup e q = sup_leadsto init step rho i j q; distinct (map fst e); valid_s init step st accept rho i i j s⟧ ⟹ distinct (map fst s)› 2. ‹⟦reach_window args t0 sub rho (i, ti, si, j, tj, sj); ⋀i j. ⟦i ≤ j; j < length rho⟧ ⟹ ts_at rho i ≤ ts_at rho j; ⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v; ⋀q. case Mapping.lookup ac q of None ⇒ True | Some v ⇒ accept q = v; ∀q. mmap_lookup e q = sup_leadsto init step rho i j q; distinct (map fst e); valid_s init step st accept rho i i j s⟧ ⟹ distinct (map fst e)› discuss goal 1*) apply ((auto simp: valid_s_def (*‹valid_s (?init::?'c) (?step::?'c ⇒ ?'b ⇒ ?'c) (?st::(?'c × ?'b, ?'c) mapping) (?accept::?'c ⇒ bool) (?rho::(?'d × ?'b) list) (?u::nat) (?i::nat) (?j::nat) (?s::(?'c × ?'c × (?'d × nat) option) list) ≡ (∀(q::?'c) bs::?'b. case Mapping.lookup ?st (q, bs) of None ⇒ True | Some (v::?'c) ⇒ ?step q bs = v) ∧ mmap_keys ?s = {q::?'c. ∃l≤?u. steps ?step ?rho ?init (l, ?i) = q} ∧ distinct (map fst ?s) ∧ (∀q::?'c. case mmap_lookup ?s q of None ⇒ True | Some (q'::?'c, tstp::(?'d × nat) option) ⇒ steps ?step ?rho q (?i, ?j) = q' ∧ tstp = sup_acc ?step ?accept ?rho q ?i ?j)›*))[1]) (*discuss goal 2*) apply ((auto simp: valid_s_def (*‹valid_s ?init ?step ?st ?accept ?rho ?u ?i ?j ?s ≡ (∀q bs. case Mapping.lookup ?st (q, bs) of None ⇒ True | Some v ⇒ ?step q bs = v) ∧ mmap_keys ?s = {q. ∃l≤?u. steps ?step ?rho ?init (l, ?i) = q} ∧ distinct (map fst ?s) ∧ (∀q. case mmap_lookup ?s q of None ⇒ True | Some (q', tstp) ⇒ steps ?step ?rho q (?i, ?j) = q' ∧ tstp = sup_acc ?step ?accept ?rho q ?i ?j)›*))[1]) (*proven 2 subgoals*) . note i_lt_j = assms(2)[folded i_def j_def] (*‹i < j›*) obtain ti' and si' and t and b where tb_def: "run_t ti = Some (ti', t)" "run_sub si = Some (si', b)" "reaches_on run_t ti' (drop (Suc i) (map fst rho)) tj" "reaches_on run_sub si' (drop (Suc i) (map snd rho)) sj" "t = ts_at rho i" "b = bs_at rho i" (*goal: ‹(⋀ti' t si' b. ⟦run_t ti = Some (ti', t); run_sub si = Some (si', b); reaches_on run_t ti' (drop (Suc i) (map fst rho)) tj; reaches_on run_sub si' (drop (Suc i) (map snd rho)) sj; t = ts_at rho i; b = bs_at rho i⟧ ⟹ thesis) ⟹ thesis›*) using valid_before (*‹reach_window args t0 sub rho (i, ti, si, j, tj, sj)› ‹⟦?i ≤ ?j; ?j < length rho⟧ ⟹ ts_at rho ?i ≤ ts_at rho ?j› ‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ step ?q ?bs = v› ‹case Mapping.lookup (ac::('b::type, bool) mapping) (?q::'b::type) of None ⇒ True | Some (v::bool) ⇒ (accept::'b::type ⇒ bool) ?q = v› ‹∀q::'b::type. mmap_lookup (e::('b::type × 'c::timestamp) list) q = sup_leadsto (init::'b::type) (step::'b::type ⇒ 'a::type ⇒ 'b::type) (rho::('c::timestamp × 'a::type) list) (i::nat) (j::nat) q› ‹distinct (map fst e)› ‹valid_s init step st accept rho i i j s›*) i_lt_j (*‹i < j›*) apply (auto simp: ts_at_def (*‹ts_at ?rho ?i = fst (?rho ! ?i)›*) bs_at_def (*‹bs_at ?rho ?i = snd (?rho ! ?i)›*) run_t_def[symmetric] (*‹w_run_t args = run_t›*) run_sub_def[symmetric] (*‹w_run_sub args = run_sub›*) elim!: reaches_on.cases[of run_t ti "drop i (map fst rho)" tj] (*‹⟦reaches_on run_t ti (drop i (map fst rho)) tj; ⋀s. ⟦ti = s; drop i (map fst rho) = []; tj = s⟧ ⟹ ?P; ⋀s s' v vs s''. ⟦ti = s; drop i (map fst rho) = v # vs; tj = s''; run_t s = Some (s', v); reaches_on run_t s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*) reaches_on.cases[of run_sub si "drop i (map snd rho)" sj] (*‹⟦reaches_on run_sub si (drop i (map snd rho)) sj; ⋀s. ⟦si = s; drop i (map snd rho) = []; sj = s⟧ ⟹ ?P; ⋀s s' v vs s''. ⟦si = s; drop i (map snd rho) = v # vs; sj = s''; run_sub s = Some (s', v); reaches_on run_sub s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goal: ‹(⋀ti' t si' b. ⟦run_t ti = Some (ti', t); run_sub si = Some (si', b); reaches_on run_t ti' (drop (Suc i) (map fst rho)) tj; reaches_on run_sub si' (drop (Suc i) (map snd rho)) sj; t = ts_at rho i; b = bs_at rho i⟧ ⟹ thesis) ⟹ thesis›*) by (metis Cons_nth_drop_Suc (*‹?i < length ?xs ⟹ ?xs ! ?i # drop (Suc ?i) ?xs = drop ?i ?xs›*) length_map (*‹length (map ?f ?xs) = length ?xs›*) list.inject (*‹(?x21.0 # ?x22.0 = ?y21.0 # ?y22.0) = (?x21.0 = ?y21.0 ∧ ?x22.0 = ?y22.0)›*) nth_map (*‹?n < length ?xs ⟹ map ?f ?xs ! ?n = ?f (?xs ! ?n)›*)) have reaches_on_si': "reaches_on run_sub sub (take (Suc i) (map snd rho)) si'" using valid_before (*‹reach_window args t0 sub rho (i, ti, si, j, tj, sj)› ‹⟦?i ≤ ?j; ?j < length rho⟧ ⟹ ts_at rho ?i ≤ ts_at rho ?j› ‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ step ?q ?bs = v› ‹case Mapping.lookup ac ?q of None ⇒ True | Some v ⇒ accept ?q = v› ‹∀q. mmap_lookup e q = sup_leadsto init step rho i j q› ‹distinct (map fst e)› ‹valid_s init step st accept rho i i j s›*) tb_def(2,3,4) (*‹run_sub si = Some (si', b)› ‹reaches_on (run_t::'d ⇒ ('d × 'c) option) (ti'::'d) (drop (Suc (i::nat)) (map fst (rho::('c × 'a) list))) (tj::'d)› ‹reaches_on (run_sub::'e ⇒ ('e × 'a) option) (si'::'e) (drop (Suc (i::nat)) (map snd (rho::('c × 'a) list))) (sj::'e)›*) i_lt_j (*‹i < j›*) reaches_on_app (*‹⟦reaches_on ?run ?s ?vs ?s'; ?run ?s' = Some (?s'', ?v)⟧ ⟹ reaches_on ?run ?s (?vs @ [?v]) ?s''›*) tb_def(1) (*‹run_t ti = Some (ti', t)›*) by (auto simp: run_sub_def (*‹run_sub = w_run_sub args›*) sub_def (*‹Code_Numeral.sub ≡ map_fun id (map_fun id integer_of_int) (λm n. numeral m - numeral n)›*) bs_at_def (*‹bs_at ?rho ?i = snd (?rho ! ?i)›*) take_Suc_conv_app_nth (*‹?i < length ?xs ⟹ take (Suc ?i) ?xs = take ?i ?xs @ [?xs ! ?i]›*) reaches_on_app (*‹⟦reaches_on ?run ?s ?vs ?s'; ?run ?s' = Some (?s'', ?v)⟧ ⟹ reaches_on ?run ?s (?vs @ [?v]) ?s''›*) tb_def( (*‹b = bs_at rho i›*) 6)) have reaches_on_ti': "reaches_on run_t t0 (take (Suc i) (map fst rho)) ti'" using valid_before (*‹reach_window args t0 sub rho (i, ti, si, j, tj, sj)› ‹⟦?i ≤ ?j; ?j < length rho⟧ ⟹ ts_at rho ?i ≤ ts_at rho ?j› ‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ step ?q ?bs = v› ‹case Mapping.lookup ac ?q of None ⇒ True | Some v ⇒ accept ?q = v› ‹∀q. mmap_lookup e q = sup_leadsto init step rho i j q› ‹distinct (map fst (e::('b::type × 'c::timestamp) list))› ‹valid_s (init::'b) (step::'b ⇒ 'a ⇒ 'b) (st::('b × 'a, 'b) mapping) (accept::'b ⇒ bool) (rho::('c × 'a) list) (i::nat) i (j::nat) (s::('b × 'b × ('c × nat) option) list)›*) tb_def(2,3,4) (*‹run_sub si = Some (si', b)› ‹reaches_on (run_t::'d ⇒ ('d × 'c) option) (ti'::'d) (drop (Suc (i::nat)) (map fst (rho::('c × 'a) list))) (tj::'d)› ‹reaches_on (run_sub::'e::type ⇒ ('e::type × 'a::type) option) (si'::'e::type) (drop (Suc (i::nat)) (map snd (rho::('c::timestamp × 'a::type) list))) (sj::'e::type)›*) i_lt_j (*‹i < j›*) reaches_on_app (*‹⟦reaches_on ?run ?s ?vs ?s'; ?run ?s' = Some (?s'', ?v)⟧ ⟹ reaches_on ?run ?s (?vs @ [?v]) ?s''›*) tb_def(1) (*‹run_t ti = Some (ti', t)›*) by (auto simp: run_t_def (*‹run_t = w_run_t args›*) ts_at_def (*‹ts_at ?rho ?i = fst (?rho ! ?i)›*) take_Suc_conv_app_nth (*‹?i < length ?xs ⟹ take (Suc ?i) ?xs = take ?i ?xs @ [?xs ! ?i]›*) reaches_on_app (*‹⟦reaches_on ?run ?s ?vs ?s'; ?run ?s' = Some (?s'', ?v)⟧ ⟹ reaches_on ?run ?s (?vs @ [?v]) ?s''›*) tb_def( (*‹t = ts_at rho i›*) 5)) define e' where "e' = mmap_update (fst (the (mmap_lookup s init))) t e" obtain st' and s' where s'_def: "adv_d step st i b s = (s', st')" (*goal: ‹(⋀s' st'. adv_d step st i b s = (s', st') ⟹ thesis) ⟹ thesis›*) by (metis old.prod.exhaust (*‹(⋀a b. ?y = (a, b) ⟹ ?P) ⟹ ?P›*)) obtain st_cur and ac_cur and i_cur and ti_cur and si_cur and q_cur and s_cur and tstp_cur where loop_def: "(st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) = while (loop_cond j) (loop_body step accept run_t run_sub) (st', ac, Suc i, ti', si', init, s', None)" (*goal: ‹(⋀st_cur ac_cur i_cur ti_cur si_cur q_cur s_cur tstp_cur. (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) = while (loop_cond j) (loop_body step accept run_t run_sub) (st', ac, Suc i, ti', si', init, s', None) ⟹ thesis) ⟹ thesis›*) apply (cases "while (loop_cond j) (loop_body step accept run_t run_sub) (st', ac, Suc i, ti', si', init, s', None)") (*goal: ‹(⋀st_cur ac_cur i_cur ti_cur si_cur q_cur s_cur tstp_cur. (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) = while (loop_cond j) (loop_body step accept run_t run_sub) (st', ac, Suc i, ti', si', init, s', None) ⟹ thesis) ⟹ thesis›*) by auto define s'' where "s'' = mmap_update init (case mmap_lookup s_cur q_cur of Some (q', tstp') ⇒ (case tstp' of Some (ts, tp) ⇒ (q', tstp') | None ⇒ (q', tstp_cur)) | None ⇒ (q_cur, tstp_cur)) s'" have i_le_j: "i ≤ j" using i_lt_j (*‹i < j›*) by auto have length_rho: "length rho = j" using valid_before (*‹reach_window args t0 sub rho (i, ti, si, j, tj, sj)› ‹⟦?i ≤ ?j; ?j < length rho⟧ ⟹ ts_at rho ?i ≤ ts_at rho ?j› ‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ step ?q ?bs = v› ‹case Mapping.lookup ac ?q of None ⇒ True | Some v ⇒ accept ?q = v› ‹∀q. mmap_lookup e q = sup_leadsto init step rho i j q› ‹distinct (map fst e)› ‹valid_s init step st accept rho i i j s›*) by auto have lookup_s: "⋀q q' tstp. mmap_lookup s q = Some (q', tstp) ⟹ steps step rho q (i, j) = q' ∧ tstp = sup_acc step accept rho q i j" using valid_before (*‹reach_window args t0 sub rho (i, ti, si, j, tj, sj)› ‹⟦?i ≤ ?j; ?j < length rho⟧ ⟹ ts_at rho ?i ≤ ts_at rho ?j› ‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ step ?q ?bs = v› ‹case Mapping.lookup (ac::('b::type, bool) mapping) (?q::'b::type) of None ⇒ True | Some (v::bool) ⇒ (accept::'b::type ⇒ bool) ?q = v› ‹∀q::'b::type. mmap_lookup (e::('b::type × 'c::timestamp) list) q = sup_leadsto (init::'b::type) (step::'b::type ⇒ 'a::type ⇒ 'b::type) (rho::('c::timestamp × 'a::type) list) (i::nat) (j::nat) q› ‹distinct (map fst e)› ‹valid_s init step st accept rho i i j s›*) Mapping_keys_intro (*‹mmap_lookup ?f ?x ≠ None ⟹ ?x ∈ mmap_keys ?f›*) apply (auto simp: valid_s_def (*‹valid_s ?init ?step ?st ?accept ?rho ?u ?i ?j ?s ≡ (∀q bs. case Mapping.lookup ?st (q, bs) of None ⇒ True | Some v ⇒ ?step q bs = v) ∧ mmap_keys ?s = {q. ∃l≤?u. steps ?step ?rho ?init (l, ?i) = q} ∧ distinct (map fst ?s) ∧ (∀q. case mmap_lookup ?s q of None ⇒ True | Some (q', tstp) ⇒ steps ?step ?rho q (?i, ?j) = q' ∧ tstp = sup_acc ?step ?accept ?rho q ?i ?j)›*)) (*goals: 1. ‹⋀q q' tstp. ⟦mmap_lookup s q = Some (q', tstp); ⋀i j. ⟦i ≤ j; j < length rho⟧ ⟹ ts_at rho i ≤ ts_at rho j; ⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v; ⋀q. case Mapping.lookup ac q of None ⇒ True | Some v ⇒ accept q = v; ∀q. mmap_lookup e q = sup_leadsto init step rho i (length rho) q; distinct (map fst e); ⋀f x. ∃y. mmap_lookup f x = Some y ⟹ x ∈ mmap_keys f; i ≤ length rho; mmap_keys s = {q. ∃l≤i. steps step rho init (l, i) = q}; j = length rho; distinct (map fst s); ∀q. case mmap_lookup s q of None ⇒ True | Some (q', tstp) ⇒ steps step rho q (i, length rho) = q' ∧ tstp = sup_acc step accept rho q i (length rho); reaches_on (w_run_t args) t0 (take i (map fst rho)) ti; reaches_on (w_run_t args) ti (drop i (map fst rho)) tj; reaches_on (w_run_sub args) sub (take i (map snd rho)) si; reaches_on (w_run_sub args) si (drop i (map snd rho)) sj⟧ ⟹ steps step rho q (i, length rho) = q'› 2. ‹⋀q q' tstp. ⟦mmap_lookup s q = Some (q', tstp); ⋀i j. ⟦i ≤ j; j < length rho⟧ ⟹ ts_at rho i ≤ ts_at rho j; ⋀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v; ⋀q. case Mapping.lookup ac q of None ⇒ True | Some v ⇒ accept q = v; ∀q. mmap_lookup e q = sup_leadsto init step rho i (length rho) q; distinct (map fst e); ⋀f x. ∃y. mmap_lookup f x = Some y ⟹ x ∈ mmap_keys f; i ≤ length rho; mmap_keys s = {q. ∃l≤i. steps step rho init (l, i) = q}; j = length rho; distinct (map fst s); ∀q. case mmap_lookup s q of None ⇒ True | Some (q', tstp) ⇒ steps step rho q (i, length rho) = q' ∧ tstp = sup_acc step accept rho q i (length rho); reaches_on (w_run_t args) t0 (take i (map fst rho)) ti; reaches_on (w_run_t args) ti (drop i (map fst rho)) tj; reaches_on (w_run_sub args) sub (take i (map snd rho)) si; reaches_on (w_run_sub args) si (drop i (map snd rho)) sj⟧ ⟹ tstp = sup_acc step accept rho q i (length rho)› discuss goal 1*) apply (smt case_prodD (*‹case (?a, ?b) of (c, d) ⇒ ?f c d ⟹ ?f ?a ?b›*) option.simps( (*‹(case Some ?x2.0 of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ?f2.0 ?x2.0›*) 5)) (*discuss goal 2*) apply (smt case_prodD (*‹case (?a, ?b) of (c, d) ⇒ ?f c d ⟹ ?f ?a ?b›*) option.simps( (*‹(case Some ?x2.0 of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ?f2.0 ?x2.0›*) 5)) (*proven 2 subgoals*) . have init_in_keys_s: "init ∈ mmap_keys s" using valid_before (*‹reach_window args t0 sub rho (i, ti, si, j, tj, sj)› ‹⟦?i ≤ ?j; ?j < length rho⟧ ⟹ ts_at rho ?i ≤ ts_at rho ?j› ‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ step ?q ?bs = v› ‹case Mapping.lookup ac ?q of None ⇒ True | Some v ⇒ accept ?q = v› ‹∀q. mmap_lookup e q = sup_leadsto init step rho i j q› ‹distinct (map fst (e::('b::type × 'c::timestamp) list))› ‹valid_s (init::'b::type) (step::'b::type ⇒ 'a::type ⇒ 'b::type) (st::('b::type × 'a::type, 'b::type) mapping) (accept::'b::type ⇒ bool) (rho::('c::timestamp × 'a::type) list) (i::nat) i (j::nat) (s::('b::type × 'b::type × ('c::timestamp × nat) option) list)›*) by (auto simp add: valid_s_def (*‹valid_s ?init ?step ?st ?accept ?rho ?u ?i ?j ?s ≡ (∀q bs. case Mapping.lookup ?st (q, bs) of None ⇒ True | Some v ⇒ ?step q bs = v) ∧ mmap_keys ?s = {q. ∃l≤?u. steps ?step ?rho ?init (l, ?i) = q} ∧ distinct (map fst ?s) ∧ (∀q. case mmap_lookup ?s q of None ⇒ True | Some (q', tstp) ⇒ steps ?step ?rho q (?i, ?j) = q' ∧ tstp = sup_acc ?step ?accept ?rho q ?i ?j)›*)) then have run_init_i_j: "steps step rho init (i, j) = fst (the (mmap_lookup s init))" using lookup_s (*‹mmap_lookup s ?q1 = Some (?q'1, ?tstp1) ⟹ steps step rho ?q1 (i, j) = ?q'1 ∧ ?tstp1 = sup_acc step accept rho ?q1 i j›*) by (auto dest: Mapping_keys_dest (*‹?x ∈ mmap_keys ?f ⟹ ∃y. mmap_lookup ?f ?x = Some y›*)) have lookup_e: "⋀q. mmap_lookup e q = sup_leadsto init step rho i j q" using valid_before (*‹reach_window (args::('a, 'b, 'c, 'd, 'e) Window.args) (t0::'d) (sub::'e) (rho::('c × 'a) list) (i::nat, ti::'d, si::'e, j::nat, tj::'d, sj::'e)› ‹⟦?i ≤ ?j; ?j < length rho⟧ ⟹ ts_at rho ?i ≤ ts_at rho ?j› ‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ step ?q ?bs = v› ‹case Mapping.lookup ac ?q of None ⇒ True | Some v ⇒ accept ?q = v› ‹∀q. mmap_lookup e q = sup_leadsto init step rho i j q› ‹distinct (map fst e)› ‹valid_s (init::'b) (step::'b ⇒ 'a ⇒ 'b) (st::('b × 'a, 'b) mapping) (accept::'b ⇒ bool) (rho::('c × 'a) list) (i::nat) i (j::nat) (s::('b × 'b × ('c × nat) option) list)›*) by auto have lookup_e': "⋀q. mmap_lookup e' q = sup_leadsto init step rho (i + 1) j q" proof (-) (*goal: ‹⋀q. mmap_lookup e' q = sup_leadsto init step rho (i + 1) j q›*) fix q show "mmap_lookup e' q = sup_leadsto init step rho (i + 1) j q" proof (cases "steps step rho init (i, j) = q") (*goals: 1. ‹steps step rho init (i, j) = q ⟹ mmap_lookup e' q = sup_leadsto init step rho (i + 1) j q› 2. ‹steps step rho init (i, j) ≠ q ⟹ mmap_lookup e' q = sup_leadsto init step rho (i + 1) j q›*) case True (*‹steps (step::'b ⇒ 'a ⇒ 'b) (rho::('c × 'a) list) (init::'b) (i::nat, j::nat) = (q::'b)›*) have "Max {l. l < Suc i ∧ steps step rho init (l, j) = steps step rho init (i, j)} = i" apply (rule iffD2[OF Max_eq_iff] (*‹⟦finite ?A1; ?A1 ≠ {}; ?m1 ∈ ?A1 ∧ (∀a∈?A1. a ≤ ?m1)⟧ ⟹ Max ?A1 = ?m1›*)) (*goals: 1. ‹finite {l. l < Suc i ∧ steps step rho init (l, j) = steps step rho init (i, j)}› 2. ‹{l. l < Suc i ∧ steps step rho init (l, j) = steps step rho init (i, j)} ≠ {}› 3. ‹i ∈ {l. l < Suc i ∧ steps step rho init (l, j) = steps step rho init (i, j)} ∧ (∀a∈{l. l < Suc i ∧ steps step rho init (l, j) = steps step rho init (i, j)}. a ≤ i)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . then have "sup_leadsto init step rho (i + 1) j q = Some (ts_at rho i)" by (auto simp add: sup_leadsto_def (*‹sup_leadsto ?init ?step ?rho ?i ?j ?q = (let L' = {l. l < ?i ∧ steps ?step ?rho ?init (l, ?j) = ?q}; m = Max L' in if L' = {} then None else Some (ts_at ?rho m))›*) True (*‹steps step rho init (i, j) = q›*)) then show "?thesis" (*goal: ‹mmap_lookup e' q = sup_leadsto init step rho (i + 1) j q›*) unfolding e'_def (*goal: ‹mmap_lookup (mmap_update (fst (the (mmap_lookup s init))) t e) q = sup_leadsto init step rho (i + 1) j q›*) using run_init_i_j (*‹steps step rho init (i, j) = fst (the (mmap_lookup s init))›*) tb_def (*‹run_t ti = Some (ti', t)› ‹run_sub si = Some (si', b)› ‹reaches_on run_t ti' (drop (Suc i) (map fst rho)) tj› ‹reaches_on run_sub si' (drop (Suc i) (map snd rho)) sj› ‹t = ts_at rho i› ‹b = bs_at rho i›*) by (auto simp add: mmap_lookup_update' (*‹mmap_lookup (mmap_update ?k ?v ?kvs) ?z = (if ?k = ?z then Some ?v else mmap_lookup ?kvs ?z)›*) True (*‹steps step rho init (i, j) = q›*)) next (*goal: ‹steps step rho init (i, j) ≠ q ⟹ mmap_lookup e' q = sup_leadsto init step rho (i + 1) j q›*) case False (*‹steps step rho init (i, j) ≠ q›*) show "?thesis" (*goal: ‹mmap_lookup e' q = sup_leadsto init step rho (i + 1) j q›*) using run_init_i_j (*‹steps step rho init (i, j) = fst (the (mmap_lookup s init))›*) sup_leadsto_idle[OF i_lt_j False] (*‹sup_leadsto init step rho i j q = sup_leadsto init step rho (i + 1) j q›*) lookup_e[of q] (*‹mmap_lookup (e::('b × 'c) list) (q::'b) = sup_leadsto (init::'b) (step::'b ⇒ 'a ⇒ 'b) (rho::('c × 'a) list) (i::nat) (j::nat) q›*) False (*‹steps step rho init (i, j) ≠ q›*) by (auto simp add: e'_def (*‹(e'::('b × 'c) list) = mmap_update (fst (the (mmap_lookup (s::('b × 'b × ('c × nat) option) list) (init::'b)))) (t::'c) (e::('b × 'c) list)›*) mmap_lookup_update' (*‹mmap_lookup (mmap_update (?k::?'b) (?v::?'a) (?kvs::(?'b × ?'a) list)) (?z::?'b) = (if ?k = ?z then Some ?v else mmap_lookup ?kvs ?z)›*)) qed qed have reach_split: "{q. ∃l≤i + 1. steps step rho init (l, i + 1) = q} = {q. ∃l≤i. steps step rho init (l, i + 1) = q} ∪ {init}" using le_Suc_eq (*‹(?m ≤ Suc ?n) = (?m ≤ ?n ∨ ?m = Suc ?n)›*) by auto have valid_s_i: "valid_s init step st accept rho i i j s" using valid_before (*‹reach_window args t0 sub rho (i, ti, si, j, tj, sj)› ‹⟦?i ≤ ?j; ?j < length rho⟧ ⟹ ts_at rho ?i ≤ ts_at rho ?j› ‹case Mapping.lookup (st::('b × 'a, 'b) mapping) (?q::'b, ?bs::'a) of None ⇒ True | Some (v::'b) ⇒ (step::'b ⇒ 'a ⇒ 'b) ?q ?bs = v› ‹case Mapping.lookup ac ?q of None ⇒ True | Some v ⇒ accept ?q = v› ‹∀q. mmap_lookup e q = sup_leadsto init step rho i j q› ‹distinct (map fst (e::('b × 'c) list))› ‹valid_s init step st accept rho i i j s›*) by auto have valid_s'_Suc_i: "valid_s init step st' accept rho i (i + 1) j s'" using valid_adv_d[OF valid_s_i order.refl i_lt_j, OF tb_def ( 6 ) s'_def] (*‹valid_s init step st' accept rho i (i + 1) j s'›*) unfolding s'_def (*goal: ‹valid_s init step st' accept rho i (i + 1) j s'›*) . have loop: "loop_inv init step accept args t0 sub rho i j tj sj (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) ∧ ¬loop_cond j (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur)" unfolding loop_def (*goal: ‹loop_inv (init::'b::type) (step::'b::type ⇒ 'a::type ⇒ 'b::type) (accept::'b::type ⇒ bool) (args::('a, 'b, 'c, 'd, 'e) Window.args) (t0::'d::type) (sub::'e::type) (rho::('c::timestamp × 'a::type) list) (i::nat) (j::nat) (tj::'d::type) (sj::'e::type) (while (loop_cond j) (loop_body step accept (run_t::'d::type ⇒ ('d::type × 'c::timestamp) option) (run_sub::'e::type ⇒ ('e::type × 'a::type) option)) (st'::('b::type × 'a::type, 'b::type) mapping, ac::('b::type, bool) mapping, Suc i, ti'::'d::type, si'::'e::type, init, s'::('b::type × 'b::type × ('c::timestamp × nat) option) list, None)) ∧ ¬ loop_cond j (while (loop_cond j) (loop_body step accept run_t run_sub) (st', ac, Suc i, ti', si', init, s', None))›*) proof (rule while_rule_lemma[of "loop_inv init step accept args t0 sub rho i j tj sj" "loop_cond j" "loop_body step accept run_t run_sub" "λs. loop_inv init step accept args t0 sub rho i j tj sj s ∧ ¬ loop_cond j s"] (*‹⟦⋀s. ⟦loop_inv init step accept args t0 sub rho i j tj sj s; loop_cond j s⟧ ⟹ loop_inv init step accept args t0 sub rho i j tj sj (loop_body step accept run_t run_sub s); ⋀s. ⟦loop_inv init step accept args t0 sub rho i j tj sj s; ¬ loop_cond j s⟧ ⟹ loop_inv init step accept args t0 sub rho i j tj sj s ∧ ¬ loop_cond j s; wf {(t, s). loop_inv init step accept args t0 sub rho i j tj sj s ∧ loop_cond j s ∧ t = loop_body step accept run_t run_sub s}; loop_inv init step accept args t0 sub rho i j tj sj ?s⟧ ⟹ loop_inv init step accept args t0 sub rho i j tj sj (while (loop_cond j) (loop_body step accept run_t run_sub) ?s) ∧ ¬ loop_cond j (while (loop_cond j) (loop_body step accept run_t run_sub) ?s)›*)) (*goals: 1. ‹⋀s. ⟦loop_inv init step accept args t0 sub rho i j tj sj s; loop_cond j s⟧ ⟹ loop_inv init step accept args t0 sub rho i j tj sj (loop_body step accept run_t run_sub s)› 2. ‹⋀s. ⟦loop_inv init step accept args t0 sub rho i j tj sj s; ¬ loop_cond j s⟧ ⟹ loop_inv init step accept args t0 sub rho i j tj sj s ∧ ¬ loop_cond j s› 3. ‹wf {(t, s). loop_inv init step accept args t0 sub rho i j tj sj s ∧ loop_cond j s ∧ t = loop_body step accept run_t run_sub s}› 4. ‹loop_inv init step accept args t0 sub rho i j tj sj (st', ac, Suc i, ti', si', init, s', None)›*) show "loop_inv init step accept args t0 sub rho i j tj sj (st', ac, Suc i, ti', si', init, s', None)" unfolding loop_inv_def (*goal: ‹case (st', ac, Suc i, ti', si', init, s', None) of (st, ac, ia, ti, si, q, s, tstp) ⇒ i + 1 ≤ ia ∧ reach_window args t0 sub rho (ia, ti, si, j, tj, sj) ∧ steps step rho init (i + 1, ia) = q ∧ (∀q. case Mapping.lookup ac q of None ⇒ True | Some x ⇒ accept q = x) ∧ valid_s init step st accept rho i ia j s ∧ tstp = sup_acc step accept rho init (i + 1) ia›*) using i_lt_j (*‹i < j›*) valid_s'_Suc_i (*‹valid_s init step st' accept rho i (i + 1) j s'›*) sup_acc_same[of step accept rho] (*‹sup_acc step accept rho ?q ?i ?i = None›*) length_rho (*‹length rho = j›*) reaches_on_si' (*‹reaches_on run_sub sub (take (Suc i) (map snd rho)) si'›*) reaches_on_ti' (*‹reaches_on (run_t::'d ⇒ ('d × 'c) option) (t0::'d) (take (Suc (i::nat)) (map fst (rho::('c × 'a) list))) (ti'::'d)›*) tb_def(3,4) (*‹reaches_on run_t ti' (drop (Suc i) (map fst rho)) tj› ‹reaches_on (run_sub::'e ⇒ ('e × 'a) option) (si'::'e) (drop (Suc (i::nat)) (map snd (rho::('c × 'a) list))) (sj::'e)›*) valid_before(4) (*‹case Mapping.lookup (ac::('b::type, bool) mapping) (?q::'b::type) of None ⇒ True | Some (v::bool) ⇒ (accept::'b::type ⇒ bool) ?q = v›*) by (auto simp: run_t_def (*‹run_t = w_run_t args›*) run_sub_def (*‹run_sub = w_run_sub args›*) split: prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*)) next (*goals: 1. ‹⋀s::('b::type × 'a::type, 'b::type) mapping × ('b::type, bool) mapping × nat × 'd::type × 'e::type × 'b::type × ('b::type × 'b::type × ('c::timestamp × nat) option) list × ('c::timestamp × nat) option. ⟦loop_inv (init::'b::type) (step::'b::type ⇒ 'a::type ⇒ 'b::type) (accept::'b::type ⇒ bool) (args::('a, 'b, 'c, 'd, 'e) Window.args) (t0::'d::type) (sub::'e::type) (rho::('c::timestamp × 'a::type) list) (i::nat) (j::nat) (tj::'d::type) (sj::'e::type) s; loop_cond j s⟧ ⟹ loop_inv init step accept args t0 sub rho i j tj sj (loop_body step accept (run_t::'d::type ⇒ ('d::type × 'c::timestamp) option) (run_sub::'e::type ⇒ ('e::type × 'a::type) option) s)› 2. ‹⋀s::('b::type × 'a::type, 'b::type) mapping × ('b::type, bool) mapping × nat × 'd::type × 'e::type × 'b::type × ('b::type × 'b::type × ('c::timestamp × nat) option) list × ('c::timestamp × nat) option. ⟦loop_inv (init::'b::type) (step::'b::type ⇒ 'a::type ⇒ 'b::type) (accept::'b::type ⇒ bool) (args::('a, 'b, 'c, 'd, 'e) Window.args) (t0::'d::type) (sub::'e::type) (rho::('c::timestamp × 'a::type) list) (i::nat) (j::nat) (tj::'d::type) (sj::'e::type) s; ¬ loop_cond j s⟧ ⟹ loop_inv init step accept args t0 sub rho i j tj sj s ∧ ¬ loop_cond j s› 3. ‹wf {(t::('b::type × 'a::type, 'b::type) mapping × ('b::type, bool) mapping × nat × 'd::type × 'e::type × 'b::type × ('b::type × 'b::type × ('c::timestamp × nat) option) list × ('c::timestamp × nat) option, s::('b::type × 'a::type, 'b::type) mapping × ('b::type, bool) mapping × nat × 'd::type × 'e::type × 'b::type × ('b::type × 'b::type × ('c::timestamp × nat) option) list × ('c::timestamp × nat) option). loop_inv (init::'b::type) (step::'b::type ⇒ 'a::type ⇒ 'b::type) (accept::'b::type ⇒ bool) (args::('a, 'b, 'c, 'd, 'e) Window.args) (t0::'d::type) (sub::'e::type) (rho::('c::timestamp × 'a::type) list) (i::nat) (j::nat) (tj::'d::type) (sj::'e::type) s ∧ loop_cond j s ∧ t = loop_body step accept (run_t::'d::type ⇒ ('d::type × 'c::timestamp) option) (run_sub::'e::type ⇒ ('e::type × 'a::type) option) s}›*) have "{(t, s). loop_inv init step accept args t0 sub rho i j tj sj s ∧ loop_cond j s ∧ t = loop_body step accept run_t run_sub s} ⊆ measure (λ(st, ac, i_cur, ti, si, q, s, tstp). j - i_cur)" unfolding loop_inv_def loop_cond_def loop_body_def (*goal: ‹{(t, s). (case s of (st, ac, ia, ti, si, q, s, tstp) ⇒ i + 1 ≤ ia ∧ reach_window args t0 sub rho (ia, ti, si, j, tj, sj) ∧ steps step rho init (i + 1, ia) = q ∧ (∀q. case Mapping.lookup ac q of None ⇒ True | Some x ⇒ accept q = x) ∧ valid_s init step st accept rho i ia j s ∧ tstp = sup_acc step accept rho init (i + 1) ia) ∧ (case s of (st, ac, i, ti, si, q, s, tstp) ⇒ i < j ∧ q ∉ mmap_keys s) ∧ t = (case s of (st, ac, i, ti, si, q, s, tstp) ⇒ case run_t ti of Some (ti', t) ⇒ case run_sub si of Some (si', b) ⇒ case adv_d step st i b s of (s', st') ⇒ case cstep step st' q b of (q', st'') ⇒ case cac accept ac q' of (β, ac') ⇒ (st'', ac', Suc i, ti', si', q', s', if β then Some (t, i) else tstp))} ⊆ measure (λ(st, ac, i_cur, ti, si, q, s, tstp). j - i_cur)›*) apply (auto simp: run_t_def (*‹run_t = w_run_t args›*) run_sub_def (*‹run_sub = w_run_sub args›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) (*goals: 1. ‹⋀(a::('b × 'a, 'b) mapping) (aa::('b, bool) mapping) (ab::nat) (ac::'d) (ad::'e) (ae::'b) (af::('b × 'b × ('c × nat) option) list) (b::('c × nat) option) (ag::('b × 'a, 'b) mapping) (ah::('b, bool) mapping) (ai::nat) (aj::'d) (ak::'e) am::('b × 'b × ('c × nat) option) list. ⟦ai < length (rho::('c × 'a) list); steps (step::'b ⇒ 'a ⇒ 'b) rho (init::'b) (Suc (i::nat), ai) ∉ mmap_keys am; (j::nat) = length rho; reaches_on (w_run_t (args::('a, 'b, 'c, 'd, 'e) Window.args)) (t0::'d) (take ai (map fst rho)) aj; reaches_on (w_run_t args) aj (drop ai (map fst rho)) (tj::'d); reaches_on (w_run_sub args) (sub::'e) (take ai (map snd rho)) ak; reaches_on (w_run_sub args) ak (drop ai (map snd rho)) (sj::'e); ∀(q::'b) x2::bool. Mapping.lookup ah q = Some x2 ⟶ (accept::'b ⇒ bool) q = x2; valid_s init step ag accept rho i ai (length rho) am; Suc i ≤ ai; w_run_t args aj = None; (a, aa, ab, ac, ad, ae, af, b) = undefined⟧ ⟹ (case undefined of (st::('b × 'a, 'b) mapping, ac::('b, bool) mapping, i_cur::nat, ti::'d, si::'e, q::'b, s::('b × 'b × ('c × nat) option) list, tstp::('c × nat) option) ⇒ length rho - i_cur) < length rho - ai› 2. ‹⋀(a::('b × 'a, 'b) mapping) (aa::('b, bool) mapping) (ab::nat) (ac::'d) (ad::'e) (ae::'b) (af::('b × 'b × ('c × nat) option) list) (b::('c × nat) option) (ag::('b × 'a, 'b) mapping) (ah::('b, bool) mapping) (ai::nat) (aj::'d) (ak::'e) (am::('b × 'b × ('c × nat) option) list) (an::'d) bb::'c. ⟦ai < length (rho::('c × 'a) list); steps (step::'b ⇒ 'a ⇒ 'b) rho (init::'b) (Suc (i::nat), ai) ∉ mmap_keys am; (j::nat) = length rho; reaches_on (w_run_t (args::('a, 'b, 'c, 'd, 'e) Window.args)) (t0::'d) (take ai (map fst rho)) aj; reaches_on (w_run_t args) aj (drop ai (map fst rho)) (tj::'d); reaches_on (w_run_sub args) (sub::'e) (take ai (map snd rho)) ak; reaches_on (w_run_sub args) ak (drop ai (map snd rho)) (sj::'e); ∀(q::'b) x2::bool. Mapping.lookup ah q = Some x2 ⟶ (accept::'b ⇒ bool) q = x2; valid_s init step ag accept rho i ai (length rho) am; Suc i ≤ ai; w_run_t args aj = Some (an, bb); (a, aa, ab, ac, ad, ae, af, b) = undefined; w_run_sub args ak = None⟧ ⟹ (case undefined of (st::('b × 'a, 'b) mapping, ac::('b, bool) mapping, i_cur::nat, ti::'d, si::'e, q::'b, s::('b × 'b × ('c × nat) option) list, tstp::('c × nat) option) ⇒ length rho - i_cur) < length rho - ai› 3. ‹⋀(a::('b × 'a, 'b) mapping) (aa::('b, bool) mapping) (ab::nat) (ac::'d) (ad::'e) (ae::'b) (af::('b × 'b × ('c × nat) option) list) (b::('c × nat) option) (ag::('b × 'a, 'b) mapping) (ah::('b, bool) mapping) (ai::nat) (aj::'d) (ak::'e) (am::('b × 'b × ('c × nat) option) list) (an::'d) (bb::'c) (ao::'e) bc::'a. ⟦ai < length (rho::('c × 'a) list); steps (step::'b ⇒ 'a ⇒ 'b) rho (init::'b) (Suc (i::nat), ai) ∉ mmap_keys am; (j::nat) = length rho; reaches_on (w_run_t (args::('a, 'b, 'c, 'd, 'e) Window.args)) (t0::'d) (take ai (map fst rho)) aj; reaches_on (w_run_t args) aj (drop ai (map fst rho)) (tj::'d); reaches_on (w_run_sub args) (sub::'e) (take ai (map snd rho)) ak; reaches_on (w_run_sub args) ak (drop ai (map snd rho)) (sj::'e); ∀(q::'b) x2::bool. Mapping.lookup ah q = Some x2 ⟶ (accept::'b ⇒ bool) q = x2; valid_s init step ag accept rho i ai (length rho) am; Suc i ≤ ai; w_run_t args aj = Some (an, bb); (a, aa, ab, ac, ad, ae, af, b) = (case adv_d step ag ai bc am of (s'::('b × 'b × ('c × nat) option) list, st'::('b × 'a, 'b) mapping) ⇒ case cstep step st' (steps step rho init (Suc i, ai)) bc of (q'::'b, st''::('b × 'a, 'b) mapping) ⇒ case cac accept ah q' of (β::bool, ac'::('b, bool) mapping) ⇒ (st'', ac', Suc ai, an, ao, q', s', if β then Some (bb, ai) else sup_acc step accept rho init (Suc i) ai)); w_run_sub args ak = Some (ao, bc)⟧ ⟹ (case case adv_d step ag ai bc am of (s'::('b × 'b × ('c × nat) option) list, st'::('b × 'a, 'b) mapping) ⇒ case cstep step st' (steps step rho init (Suc i, ai)) bc of (q'::'b, st''::('b × 'a, 'b) mapping) ⇒ case cac accept ah q' of (β::bool, ac'::('b, bool) mapping) ⇒ (st'', ac', Suc ai, an, ao, q', s', if β then Some (bb, ai) else sup_acc step accept rho init (Suc i) ai) of (st::('b × 'a, 'b) mapping, ac::('b, bool) mapping, i_cur::nat, ti::'d, si::'e, q::'b, s::('b × 'b × ('c × nat) option) list, tstp::('c × nat) option) ⇒ length rho - i_cur) < length rho - ai› discuss goal 1*) apply (metis drop_eq_Nil (*‹(drop ?n ?xs = []) = (length ?xs ≤ ?n)›*) length_map (*‹length (map ?f ?xs) = length ?xs›*) not_less (*‹(¬ ?x < ?y) = (?y ≤ ?x)›*) option.distinct( (*‹None ≠ Some ?x2.0›*) 1) reaches_on.simps (*‹reaches_on ?run ?a1.0 ?a2.0 ?a3.0 = ((∃s. ?a1.0 = s ∧ ?a2.0 = [] ∧ ?a3.0 = s) ∨ (∃s s' v vs s''. ?a1.0 = s ∧ ?a2.0 = v # vs ∧ ?a3.0 = s'' ∧ ?run s = Some (s', v) ∧ reaches_on ?run s' vs s''))›*)) (*discuss goal 2*) apply (metis (no_types, lifting) drop_eq_Nil (*‹(drop ?n ?xs = []) = (length ?xs ≤ ?n)›*) length_map (*‹length (map ?f ?xs) = length ?xs›*) not_less (*‹(¬ ?x < ?y) = (?y ≤ ?x)›*) option.distinct( (*‹None ≠ Some ?x2.0›*) 1) reaches_on.simps (*‹reaches_on ?run ?a1.0 ?a2.0 ?a3.0 = ((∃s. ?a1.0 = s ∧ ?a2.0 = [] ∧ ?a3.0 = s) ∨ (∃s s' v vs s''. ?a1.0 = s ∧ ?a2.0 = v # vs ∧ ?a3.0 = s'' ∧ ?run s = Some (s', v) ∧ reaches_on ?run s' vs s''))›*)) (*discuss goal 3*) apply (auto split: prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*)) (*proven 3 subgoals*) . then show "wf {(t, s). loop_inv init step accept args t0 sub rho i j tj sj s ∧ loop_cond j s ∧ t = loop_body step accept run_t run_sub s}" using wf_measure (*‹wf (measure (?f::?'a ⇒ nat))›*) wf_subset (*‹⟦wf ?r; ?p ⊆ ?r⟧ ⟹ wf ?p›*) by auto next (*goals: 1. ‹⋀s. ⟦loop_inv init step accept args t0 sub rho i j tj sj s; loop_cond j s⟧ ⟹ loop_inv init step accept args t0 sub rho i j tj sj (loop_body step accept run_t run_sub s)› 2. ‹⋀s. ⟦loop_inv init step accept args t0 sub rho i j tj sj s; ¬ loop_cond j s⟧ ⟹ loop_inv init step accept args t0 sub rho i j tj sj s ∧ ¬ loop_cond j s›*) fix state assume assms: "loop_inv init step accept args t0 sub rho i j tj sj state" "loop_cond j state" (*‹loop_inv (init::'b) (step::'b ⇒ 'a ⇒ 'b) (accept::'b ⇒ bool) (args::('a, 'b, 'c, 'd, 'e) Window.args) (t0::'d) (sub::'e) (rho::('c × 'a) list) (i::nat) (j::nat) (tj::'d) (sj::'e) (state::('b × 'a, 'b) mapping × ('b, bool) mapping × nat × 'd × 'e × 'b × ('b × 'b × ('c × nat) option) list × ('c × nat) option)› ‹loop_cond (j::nat) (state::('b × 'a, 'b) mapping × ('b, bool) mapping × nat × 'd × 'e × 'b × ('b × 'b × ('c × nat) option) list × ('c × nat) option)›*) obtain st_cur and ac_cur and i_cur and ti_cur and si_cur and q_cur and s_cur and tstp_cur where state_def: "state = (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur)" (*goal: ‹(⋀st_cur ac_cur i_cur ti_cur si_cur q_cur s_cur tstp_cur. state = (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) ⟹ thesis) ⟹ thesis›*) apply (cases state) (*goal: ‹(⋀st_cur ac_cur i_cur ti_cur si_cur q_cur s_cur tstp_cur. state = (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) ⟹ thesis) ⟹ thesis›*) by auto obtain ti'_cur and si'_cur and t_cur and b_cur where tb_cur_def: "run_t ti_cur = Some (ti'_cur, t_cur)" "run_sub si_cur = Some (si'_cur, b_cur)" "reaches_on run_t ti'_cur (drop (Suc i_cur) (map fst rho)) tj" "reaches_on run_sub si'_cur (drop (Suc i_cur) (map snd rho)) sj" "t_cur = ts_at rho i_cur" "b_cur = bs_at rho i_cur" (*goal: ‹(⋀ti'_cur t_cur si'_cur b_cur. ⟦run_t ti_cur = Some (ti'_cur, t_cur); run_sub si_cur = Some (si'_cur, b_cur); reaches_on run_t ti'_cur (drop (Suc i_cur) (map fst rho)) tj; reaches_on run_sub si'_cur (drop (Suc i_cur) (map snd rho)) sj; t_cur = ts_at rho i_cur; b_cur = bs_at rho i_cur⟧ ⟹ thesis) ⟹ thesis›*) using assms (*‹loop_inv init step accept args t0 sub rho i j tj sj state› ‹loop_cond j state›*) unfolding loop_inv_def loop_cond_def state_def (*goal: ‹(⋀(ti'_cur::'d) (t_cur::'c) (si'_cur::'e) b_cur::'a. ⟦(run_t::'d ⇒ ('d × 'c) option) (ti_cur::'d) = Some (ti'_cur, t_cur); (run_sub::'e ⇒ ('e × 'a) option) (si_cur::'e) = Some (si'_cur, b_cur); reaches_on run_t ti'_cur (drop (Suc (i_cur::nat)) (map fst (rho::('c × 'a) list))) (tj::'d); reaches_on run_sub si'_cur (drop (Suc i_cur) (map snd rho)) (sj::'e); t_cur = ts_at rho i_cur; b_cur = bs_at rho i_cur⟧ ⟹ thesis::bool) ⟹ thesis›*) apply (auto simp: ts_at_def (*‹ts_at (?rho::(?'d × ?'b) list) (?i::nat) = fst (?rho ! ?i)›*) bs_at_def (*‹bs_at (?rho::(?'d × ?'b) list) (?i::nat) = snd (?rho ! ?i)›*) run_t_def[symmetric] (*‹w_run_t (args::('a, 'b, 'c, 'd, 'e) Window.args) = (run_t::'d ⇒ ('d × 'c) option)›*) run_sub_def[symmetric] (*‹w_run_sub (args::('a, 'b, 'c, 'd, 'e) Window.args) = (run_sub::'e ⇒ ('e × 'a) option)›*) elim!: reaches_on.cases[of run_t ti_cur "drop i_cur (map fst rho)" tj] (*‹⟦reaches_on (run_t::'d ⇒ ('d × 'c) option) (ti_cur::'d) (drop (i_cur::nat) (map fst (rho::('c × 'a) list))) (tj::'d); ⋀s::'d. ⟦ti_cur = s; drop i_cur (map fst rho) = []; tj = s⟧ ⟹ ?P::bool; ⋀(s::'d) (s'::'d) (v::'c) (vs::'c list) s''::'d. ⟦ti_cur = s; drop i_cur (map fst rho) = v # vs; tj = s''; run_t s = Some (s', v); reaches_on run_t s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*) reaches_on.cases[of run_sub si_cur "drop i_cur (map snd rho)" sj] (*‹⟦reaches_on (run_sub::'e ⇒ ('e × 'a) option) (si_cur::'e) (drop (i_cur::nat) (map snd (rho::('c × 'a) list))) (sj::'e); ⋀s::'e. ⟦si_cur = s; drop i_cur (map snd rho) = []; sj = s⟧ ⟹ ?P::bool; ⋀(s::'e) (s'::'e) (v::'a) (vs::'a list) s''::'e. ⟦si_cur = s; drop i_cur (map snd rho) = v # vs; sj = s''; run_sub s = Some (s', v); reaches_on run_sub s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goal: ‹(⋀ti'_cur t_cur si'_cur b_cur. ⟦run_t ti_cur = Some (ti'_cur, t_cur); run_sub si_cur = Some (si'_cur, b_cur); reaches_on run_t ti'_cur (drop (Suc i_cur) (map fst rho)) tj; reaches_on run_sub si'_cur (drop (Suc i_cur) (map snd rho)) sj; t_cur = ts_at rho i_cur; b_cur = bs_at rho i_cur⟧ ⟹ thesis) ⟹ thesis›*) by (metis Cons_nth_drop_Suc (*‹?i < length ?xs ⟹ ?xs ! ?i # drop (Suc ?i) ?xs = drop ?i ?xs›*) length_map (*‹length (map ?f ?xs) = length ?xs›*) list.inject (*‹(?x21.0 # ?x22.0 = ?y21.0 # ?y22.0) = (?x21.0 = ?y21.0 ∧ ?x22.0 = ?y22.0)›*) nth_map (*‹?n < length ?xs ⟹ map ?f ?xs ! ?n = ?f (?xs ! ?n)›*)) obtain s'_cur and st'_cur where s'_cur_def: "adv_d step st_cur i_cur b_cur s_cur = (s'_cur, st'_cur)" (*goal: ‹(⋀s'_cur st'_cur. adv_d step st_cur i_cur b_cur s_cur = (s'_cur, st'_cur) ⟹ thesis) ⟹ thesis›*) by fastforce have valid_s'_cur: "valid_s init step st'_cur accept rho i (i_cur + 1) j s'_cur" using assms (*‹loop_inv init step accept args t0 sub rho i j tj sj state› ‹loop_cond j state›*) valid_adv_d[of init step st_cur accept rho] (*‹⟦valid_s (init::'b::type) (step::'b::type ⇒ 'a::type ⇒ 'b::type) (st_cur::('b::type × 'a::type, 'b::type) mapping) (accept::'b::type ⇒ bool) (rho::('c::timestamp × 'a::type) list) (?u::nat) (?i::nat) (?j::nat) (?s::('b::type × 'b::type × ('c::timestamp × nat) option) list); ?u ≤ ?i; ?i < ?j; (?b::'a::type) = bs_at rho ?i; adv_d step st_cur ?i ?b ?s = (?s'::('b::type × 'b::type × ('c::timestamp × nat) option) list, ?st'::('b::type × 'a::type, 'b::type) mapping)⟧ ⟹ valid_s init step ?st' accept rho ?u (?i + (1::nat)) ?j ?s'›*) tb_cur_def(6) (*‹b_cur = bs_at rho i_cur›*) s'_cur_def (*‹adv_d step st_cur i_cur b_cur s_cur = (s'_cur, st'_cur)›*) unfolding loop_inv_def loop_cond_def state_def (*goal: ‹valid_s init step st'_cur accept rho i (i_cur + 1) j s'_cur›*) by auto obtain q' and st''_cur where q'_def: "cstep step st'_cur q_cur b_cur = (q', st''_cur)" (*goal: ‹(⋀q' st''_cur. cstep step st'_cur q_cur b_cur = (q', st''_cur) ⟹ thesis) ⟹ thesis›*) by fastforce obtain β and ac'_cur where b_def: "cac accept ac_cur q' = (β, ac'_cur)" (*goal: ‹(⋀(β::bool) ac'_cur::('b::type, bool) mapping. cac (accept::'b::type ⇒ bool) (ac_cur::('b::type, bool) mapping) (q'::'b::type) = (β, ac'_cur) ⟹ thesis::bool) ⟹ thesis›*) by fastforce have step: "q' = step q_cur b_cur" "⋀q bs. case Mapping.lookup st''_cur (q, bs) of None ⇒ True | Some v ⇒ step q bs = v" using valid_s'_cur (*‹valid_s init step st'_cur accept rho i (i_cur + 1) j s'_cur›*) q'_def (*‹cstep step st'_cur q_cur b_cur = (q', st''_cur)›*) unfolding valid_s_def (*goals: 1. ‹q' = step q_cur b_cur› 2. ‹⋀q bs. case Mapping.lookup st''_cur (q, bs) of None ⇒ True | Some v ⇒ step q bs = v›*) apply - (*goals: 1. ‹⟦(∀(q::'b::type) bs::'a::type. case Mapping.lookup (st'_cur::('b::type × 'a::type, 'b::type) mapping) (q, bs) of None ⇒ True | Some (v::'b::type) ⇒ (step::'b::type ⇒ 'a::type ⇒ 'b::type) q bs = v) ∧ mmap_keys (s'_cur::('b::type × 'b::type × ('c::timestamp × nat) option) list) = {q::'b::type. ∃l≤i::nat. steps step (rho::('c::timestamp × 'a::type) list) (init::'b::type) (l, (i_cur::nat) + (1::nat)) = q} ∧ distinct (map fst s'_cur) ∧ (∀q::'b::type. case mmap_lookup s'_cur q of None ⇒ True | Some (q'::'b::type, tstp::('c::timestamp × nat) option) ⇒ steps step rho q (i_cur + (1::nat), j::nat) = q' ∧ tstp = sup_acc step (accept::'b::type ⇒ bool) rho q (i_cur + (1::nat)) j); cstep step st'_cur (q_cur::'b::type) (b_cur::'a::type) = (q'::'b::type, st''_cur::('b::type × 'a::type, 'b::type) mapping)⟧ ⟹ q' = step q_cur b_cur› 2. ‹⋀(q::'b::type) bs::'a::type. ⟦(∀(q::'b::type) bs::'a::type. case Mapping.lookup (st'_cur::('b::type × 'a::type, 'b::type) mapping) (q, bs) of None ⇒ True | Some (v::'b::type) ⇒ (step::'b::type ⇒ 'a::type ⇒ 'b::type) q bs = v) ∧ mmap_keys (s'_cur::('b::type × 'b::type × ('c::timestamp × nat) option) list) = {q::'b::type. ∃l≤i::nat. steps step (rho::('c::timestamp × 'a::type) list) (init::'b::type) (l, (i_cur::nat) + (1::nat)) = q} ∧ distinct (map fst s'_cur) ∧ (∀q::'b::type. case mmap_lookup s'_cur q of None ⇒ True | Some (q'::'b::type, tstp::('c::timestamp × nat) option) ⇒ steps step rho q (i_cur + (1::nat), j::nat) = q' ∧ tstp = sup_acc step (accept::'b::type ⇒ bool) rho q (i_cur + (1::nat)) j); cstep step st'_cur (q_cur::'b::type) (b_cur::'a::type) = (q'::'b::type, st''_cur::('b::type × 'a::type, 'b::type) mapping)⟧ ⟹ case Mapping.lookup st''_cur (q, bs) of None ⇒ True | Some (v::'b::type) ⇒ step q bs = v› discuss goal 1*) apply ((auto simp: cstep_def (*‹cstep ?step ?st ?q ?bs = (case Mapping.lookup ?st (?q, ?bs) of None ⇒ let res = ?step ?q ?bs in (res, Mapping.update (?q, ?bs) res ?st) | Some v ⇒ (v, ?st))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) Mapping.lookup_update' (*‹Mapping.lookup (Mapping.update ?k ?v ?m) ?k' = (if ?k = ?k' then Some ?v else Mapping.lookup ?m ?k')›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto simp: cstep_def (*‹cstep (?step::?'c ⇒ ?'b ⇒ ?'c) (?st::(?'c × ?'b, ?'c) mapping) (?q::?'c) (?bs::?'b) = (case Mapping.lookup ?st (?q, ?bs) of None ⇒ let res::?'c = ?step ?q ?bs in (res, Mapping.update (?q, ?bs) res ?st) | Some (v::?'c) ⇒ (v, ?st))›*) Let_def (*‹Let (?s::?'a) (?f::?'a ⇒ ?'b) ≡ ?f ?s›*) Mapping.lookup_update' (*‹Mapping.lookup (Mapping.update (?k::?'b) (?v::?'a) (?m::(?'b, ?'a) mapping)) (?k'::?'b) = (if ?k = ?k' then Some ?v else Mapping.lookup ?m ?k')›*) split: option.splits (*‹(?P::?'b ⇒ bool) (case ?option::?'a option of None ⇒ ?f1.0::?'b | Some (x::?'a) ⇒ (?f2.0::?'a ⇒ ?'b) x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2::?'a. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹(?P::?'b ⇒ bool) (case ?option::?'a option of None ⇒ ?f1.0::?'b | Some (x::?'a) ⇒ (?f2.0::?'a ⇒ ?'b) x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2::?'a. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) if_splits (*‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 2 subgoals*) . have accept: "β = accept q'" "⋀q. case Mapping.lookup ac'_cur q of None ⇒ True | Some v ⇒ accept q = v" using assms (*‹loop_inv init step accept args t0 sub rho i j tj sj state› ‹loop_cond j state›*) b_def (*‹cac accept ac_cur q' = (β, ac'_cur)›*) unfolding loop_inv_def state_def (*goals: 1. ‹(β::bool) = (accept::'b::type ⇒ bool) (q'::'b::type)› 2. ‹⋀q::'b::type. case Mapping.lookup (ac'_cur::('b::type, bool) mapping) q of None ⇒ True | Some (v::bool) ⇒ (accept::'b::type ⇒ bool) q = v›*) apply - (*goals: 1. ‹⟦case (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) of (st, ac, ia, ti, si, q, s, tstp) ⇒ i + 1 ≤ ia ∧ reach_window args t0 sub rho (ia, ti, si, j, tj, sj) ∧ steps step rho init (i + 1, ia) = q ∧ (∀q. case Mapping.lookup ac q of None ⇒ True | Some x ⇒ accept q = x) ∧ valid_s init step st accept rho i ia j s ∧ tstp = sup_acc step accept rho init (i + 1) ia; loop_cond j (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur); cac accept ac_cur q' = (β, ac'_cur)⟧ ⟹ β = accept q'› 2. ‹⋀q. ⟦case (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) of (st, ac, ia, ti, si, q, s, tstp) ⇒ i + 1 ≤ ia ∧ reach_window args t0 sub rho (ia, ti, si, j, tj, sj) ∧ steps step rho init (i + 1, ia) = q ∧ (∀q. case Mapping.lookup ac q of None ⇒ True | Some x ⇒ accept q = x) ∧ valid_s init step st accept rho i ia j s ∧ tstp = sup_acc step accept rho init (i + 1) ia; loop_cond j (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur); cac accept ac_cur q' = (β, ac'_cur)⟧ ⟹ case Mapping.lookup ac'_cur q of None ⇒ True | Some v ⇒ accept q = v› discuss goal 1*) apply ((auto simp: cac_def (*‹cac ?accept ?ac ?q = (case Mapping.lookup ?ac ?q of None ⇒ let res = ?accept ?q in (res, Mapping.update ?q res ?ac) | Some v ⇒ (v, ?ac))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) Mapping.lookup_update' (*‹Mapping.lookup (Mapping.update ?k ?v ?m) ?k' = (if ?k = ?k' then Some ?v else Mapping.lookup ?m ?k')›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto simp: cac_def (*‹cac (?accept::?'c ⇒ bool) (?ac::(?'c, bool) mapping) (?q::?'c) = (case Mapping.lookup ?ac ?q of None ⇒ let res::bool = ?accept ?q in (res, Mapping.update ?q res ?ac) | Some (v::bool) ⇒ (v, ?ac))›*) Let_def (*‹Let (?s::?'a) (?f::?'a ⇒ ?'b) ≡ ?f ?s›*) Mapping.lookup_update' (*‹Mapping.lookup (Mapping.update (?k::?'b) (?v::?'a) (?m::(?'b, ?'a) mapping)) (?k'::?'b) = (if ?k = ?k' then Some ?v else Mapping.lookup ?m ?k')›*) split: option.splits (*‹(?P::?'b ⇒ bool) (case ?option::?'a option of None ⇒ ?f1.0::?'b | Some (x::?'a) ⇒ (?f2.0::?'a ⇒ ?'b) x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2::?'a. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹(?P::?'b ⇒ bool) (case ?option::?'a option of None ⇒ ?f1.0::?'b | Some (x::?'a) ⇒ (?f2.0::?'a ⇒ ?'b) x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2::?'a. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) if_splits (*‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 2 subgoals*) . have steps_q': "steps step rho init (i + 1, Suc i_cur) = q'" using assms (*‹loop_inv init step accept args t0 sub rho i j tj sj state› ‹loop_cond j state›*) unfolding loop_inv_def state_def (*goal: ‹steps step rho init (i + 1, Suc i_cur) = q'›*) apply auto (*goal: ‹steps step rho init (i + 1, Suc i_cur) = q'›*) by (metis local.step( (*‹q' = step q_cur b_cur›*) 1) steps_appE (*‹⟦?i ≤ ?j; steps ?step ?rho ?q (?i, Suc ?j) = ?q'⟧ ⟹ ∃q''. steps ?step ?rho ?q (?i, ?j) = q'' ∧ ?q' = ?step q'' (bs_at ?rho ?j)›*) tb_cur_def( (*‹b_cur = bs_at rho i_cur›*) 6)) have b_acc: "β = acc step accept rho init (i + 1, Suc i_cur)" unfolding accept(1) acc_def steps_q' (*goal: ‹(accept::'b ⇒ bool) (q'::'b) = accept q'›*) by (auto simp: tb_cur_def (*‹run_t ti_cur = Some (ti'_cur, t_cur)› ‹run_sub si_cur = Some (si'_cur, b_cur)› ‹reaches_on run_t ti'_cur (drop (Suc i_cur) (map fst rho)) tj› ‹reaches_on run_sub si'_cur (drop (Suc i_cur) (map snd rho)) sj› ‹t_cur = ts_at rho i_cur› ‹b_cur = bs_at rho i_cur›*)) have valid_s''_cur: "valid_s init step st''_cur accept rho i (i_cur + 1) j s'_cur" using valid_s'_cur (*‹valid_s init step st'_cur accept rho i (i_cur + 1) j s'_cur›*) step(2) (*‹case Mapping.lookup (st''_cur::('b × 'a, 'b) mapping) (?q1::'b, ?bs1::'a) of None ⇒ True | Some (v::'b) ⇒ (step::'b ⇒ 'a ⇒ 'b) ?q1 ?bs1 = v›*) unfolding valid_s_def (*goal: ‹(∀q bs. case Mapping.lookup st''_cur (q, bs) of None ⇒ True | Some v ⇒ step q bs = v) ∧ mmap_keys s'_cur = {q. ∃l≤i. steps step rho init (l, i_cur + 1) = q} ∧ distinct (map fst s'_cur) ∧ (∀q. case mmap_lookup s'_cur q of None ⇒ True | Some (q', tstp) ⇒ steps step rho q (i_cur + 1, j) = q' ∧ tstp = sup_acc step accept rho q (i_cur + 1) j)›*) by auto have reaches_on_si': "reaches_on run_sub sub (take (Suc i_cur) (map snd rho)) si'_cur" using assms (*‹loop_inv (init::'b::type) (step::'b::type ⇒ 'a::type ⇒ 'b::type) (accept::'b::type ⇒ bool) (args::('a, 'b, 'c, 'd, 'e) Window.args) (t0::'d::type) (sub::'e::type) (rho::('c::timestamp × 'a::type) list) (i::nat) (j::nat) (tj::'d::type) (sj::'e::type) (state::('b::type × 'a::type, 'b::type) mapping × ('b::type, bool) mapping × nat × 'd::type × 'e::type × 'b::type × ('b::type × 'b::type × ('c::timestamp × nat) option) list × ('c::timestamp × nat) option)› ‹loop_cond j state›*) unfolding loop_inv_def loop_cond_def state_def (*goal: ‹reaches_on (run_sub::'e ⇒ ('e × 'a) option) (sub::'e) (take (Suc (i_cur::nat)) (map snd (rho::('c × 'a) list))) (si'_cur::'e)›*) apply (auto simp: run_sub_def (*‹run_sub = w_run_sub args›*) sub_def (*‹Code_Numeral.sub ≡ map_fun id (map_fun id integer_of_int) (λm n. numeral m - numeral n)›*) bs_at_def (*‹bs_at ?rho ?i = snd (?rho ! ?i)›*) take_Suc_conv_app_nth (*‹?i < length ?xs ⟹ take (Suc ?i) ?xs = take ?i ?xs @ [?xs ! ?i]›*) reaches_on_app (*‹⟦reaches_on ?run ?s ?vs ?s'; ?run ?s' = Some (?s'', ?v)⟧ ⟹ reaches_on ?run ?s (?vs @ [?v]) ?s''›*) tb_cur_def( (*‹run_sub si_cur = Some (si'_cur, b_cur)› ‹reaches_on run_sub si'_cur (drop (Suc i_cur) (map snd rho)) sj› ‹b_cur = bs_at rho i_cur›*) 2,4,6)) (*goal: ‹reaches_on run_sub sub (take (Suc i_cur) (map snd rho)) si'_cur›*) by (metis bs_at_def (*‹bs_at ?rho ?i = snd (?rho ! ?i)›*) reaches_on_app (*‹⟦reaches_on ?run ?s ?vs ?s'; ?run ?s' = Some (?s'', ?v)⟧ ⟹ reaches_on ?run ?s (?vs @ [?v]) ?s''›*) run_sub_def (*‹run_sub = w_run_sub args›*) tb_cur_def( (*‹run_sub si_cur = Some (si'_cur, b_cur)›*) 2) tb_cur_def( (*‹b_cur = bs_at rho i_cur›*) 6)) have reaches_on_ti': "reaches_on run_t t0 (take (Suc i_cur) (map fst rho)) ti'_cur" using assms (*‹loop_inv init step accept args t0 sub rho i j tj sj state› ‹loop_cond (j::nat) (state::('b × 'a, 'b) mapping × ('b, bool) mapping × nat × 'd × 'e × 'b × ('b × 'b × ('c × nat) option) list × ('c × nat) option)›*) unfolding loop_inv_def loop_cond_def state_def (*goal: ‹reaches_on run_t t0 (take (Suc i_cur) (map fst rho)) ti'_cur›*) apply (auto simp: run_t_def (*‹run_t = w_run_t args›*) ts_at_def (*‹ts_at ?rho ?i = fst (?rho ! ?i)›*) take_Suc_conv_app_nth (*‹?i < length ?xs ⟹ take (Suc ?i) ?xs = take ?i ?xs @ [?xs ! ?i]›*) reaches_on_app (*‹⟦reaches_on ?run ?s ?vs ?s'; ?run ?s' = Some (?s'', ?v)⟧ ⟹ reaches_on ?run ?s (?vs @ [?v]) ?s''›*) tb_cur_def( (*‹run_t ti_cur = Some (ti'_cur, t_cur)› ‹reaches_on run_t ti'_cur (drop (Suc i_cur) (map fst rho)) tj› ‹t_cur = ts_at rho i_cur›*) 1,3,5)) (*goal: ‹reaches_on run_t t0 (take (Suc i_cur) (map fst rho)) ti'_cur›*) by (metis reaches_on_app (*‹⟦reaches_on ?run ?s ?vs ?s'; ?run ?s' = Some (?s'', ?v)⟧ ⟹ reaches_on ?run ?s (?vs @ [?v]) ?s''›*) run_t_def (*‹run_t = w_run_t args›*) tb_cur_def( (*‹run_t ti_cur = Some (ti'_cur, t_cur)›*) 1) tb_cur_def( (*‹t_cur = ts_at rho i_cur›*) 5) ts_at_def (*‹ts_at ?rho ?i = fst (?rho ! ?i)›*)) have "reach_window args t0 sub rho (Suc i_cur, ti'_cur, si'_cur, j, tj, sj)" using reaches_on_si' (*‹reaches_on run_sub sub (take (Suc i_cur) (map snd rho)) si'_cur›*) reaches_on_ti' (*‹reaches_on run_t t0 (take (Suc i_cur) (map fst rho)) ti'_cur›*) tb_cur_def(3,4) (*‹reaches_on run_t ti'_cur (drop (Suc i_cur) (map fst rho)) tj› ‹reaches_on run_sub si'_cur (drop (Suc i_cur) (map snd rho)) sj›*) length_rho (*‹length rho = j›*) assms(2) (*‹loop_cond j state›*) unfolding loop_cond_def state_def (*goal: ‹reach_window args t0 sub rho (Suc i_cur, ti'_cur, si'_cur, j, tj, sj)›*) by (auto simp: run_t_def (*‹run_t = w_run_t args›*) run_sub_def (*‹run_sub = w_run_sub args›*)) moreover have "steps step rho init (i + 1, Suc i_cur) = q'" using assms (*‹loop_inv init step accept args t0 sub rho i j tj sj state› ‹loop_cond j state›*) steps_app (*‹?i ≤ ?j ⟹ steps ?step ?rho ?q (?i, ?j + 1) = ?step (steps ?step ?rho ?q (?i, ?j)) (bs_at ?rho ?j)›*) unfolding loop_inv_def state_def step(1) (*goal: ‹steps step rho init (i + 1, Suc i_cur) = step q_cur b_cur›*) by (auto simp: tb_cur_def( (*‹b_cur = bs_at rho i_cur›*) 6)) ultimately show "loop_inv init step accept args t0 sub rho i j tj sj (loop_body step accept run_t run_sub state)" using assms (*‹loop_inv init step accept args t0 sub rho i j tj sj state› ‹loop_cond j state›*) accept(2) (*‹case Mapping.lookup ac'_cur ?q1 of None ⇒ True | Some v ⇒ accept ?q1 = v›*) valid_s''_cur (*‹valid_s init step st''_cur accept rho i (i_cur + 1) j s'_cur›*) sup_acc_ext[of _ _ step accept rho] (*‹⟦?i ≤ ?j; acc step accept rho ?q (?i, Suc ?j)⟧ ⟹ sup_acc step accept rho ?q ?i (Suc ?j) = Some (ts_at rho ?j, ?j)›*) sup_acc_ext_idle[of _ _ step accept rho] (*‹⟦?i ≤ ?j; ¬ acc step accept rho ?q (?i, Suc ?j)⟧ ⟹ sup_acc step accept rho ?q ?i (Suc ?j) = sup_acc step accept rho ?q ?i ?j›*) unfolding loop_inv_def loop_body_def state_def (*goal: ‹case case (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) of (st, ac, i, ti, si, q, s, tstp) ⇒ case run_t ti of Some (ti', t) ⇒ case run_sub si of Some (si', b) ⇒ case adv_d step st i b s of (s', st') ⇒ case cstep step st' q b of (q', st'') ⇒ case cac accept ac q' of (β, ac') ⇒ (st'', ac', Suc i, ti', si', q', s', if β then Some (t, i) else tstp) of (st, ac, ia, ti, si, q, s, tstp) ⇒ i + 1 ≤ ia ∧ reach_window args t0 sub rho (ia, ti, si, j, tj, sj) ∧ steps step rho init (i + 1, ia) = q ∧ (∀q. case Mapping.lookup ac q of None ⇒ True | Some x ⇒ accept q = x) ∧ valid_s init step st accept rho i ia j s ∧ tstp = sup_acc step accept rho init (i + 1) ia›*) by (auto simp: tb_cur_def( (*‹run_t ti_cur = Some (ti'_cur, t_cur)› ‹run_sub si_cur = Some (si'_cur, b_cur)› ‹t_cur = ts_at rho i_cur›*) 1,2,5) s'_cur_def (*‹adv_d step st_cur i_cur b_cur s_cur = (s'_cur, st'_cur)›*) q'_def (*‹cstep step st'_cur q_cur b_cur = (q', st''_cur)›*) b_def (*‹cac accept ac_cur q' = (β, ac'_cur)›*) b_acc (*‹β = acc step accept rho init (i + 1, Suc i_cur)›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*)) qed (auto) (*solved the remaining goal: ‹⋀s. ⟦loop_inv init step accept args t0 sub rho i j tj sj s; ¬ loop_cond j s⟧ ⟹ loop_inv init step accept args t0 sub rho i j tj sj s ∧ ¬ loop_cond j s›*) have valid_stac_cur: "∀q bs. case Mapping.lookup st_cur (q, bs) of None ⇒ True | Some v ⇒ step q bs = v" "∀q. case Mapping.lookup ac_cur q of None ⇒ True | Some v ⇒ accept q = v" using loop (*‹loop_inv (init::'b) (step::'b ⇒ 'a ⇒ 'b) (accept::'b ⇒ bool) (args::('a, 'b, 'c, 'd, 'e) Window.args) (t0::'d) (sub::'e) (rho::('c × 'a) list) (i::nat) (j::nat) (tj::'d) (sj::'e) (st_cur::('b × 'a, 'b) mapping, ac_cur::('b, bool) mapping, i_cur::nat, ti_cur::'d, si_cur::'e, q_cur::'b, s_cur::('b × 'b × ('c × nat) option) list, tstp_cur::('c × nat) option) ∧ ¬ loop_cond j (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur)›*) unfolding loop_inv_def valid_s_def (*goals: 1. ‹∀q bs. case Mapping.lookup st_cur (q, bs) of None ⇒ True | Some v ⇒ step q bs = v› 2. ‹∀q. case Mapping.lookup ac_cur q of None ⇒ True | Some v ⇒ accept q = v›*) apply - (*goals: 1. ‹(case (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) of (st, ac, ia, ti, si, q, s, tstp) ⇒ i + 1 ≤ ia ∧ reach_window args t0 sub rho (ia, ti, si, j, tj, sj) ∧ steps step rho init (i + 1, ia) = q ∧ (∀q. case Mapping.lookup ac q of None ⇒ True | Some x ⇒ accept q = x) ∧ ((∀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v) ∧ mmap_keys s = {q. ∃l≤i. steps step rho init (l, ia) = q} ∧ distinct (map fst s) ∧ (∀q. case mmap_lookup s q of None ⇒ True | Some (q', tstp) ⇒ steps step rho q (ia, j) = q' ∧ tstp = sup_acc step accept rho q ia j)) ∧ tstp = sup_acc step accept rho init (i + 1) ia) ∧ ¬ loop_cond j (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) ⟹ ∀q bs. case Mapping.lookup st_cur (q, bs) of None ⇒ True | Some v ⇒ step q bs = v› 2. ‹(case (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) of (st, ac, ia, ti, si, q, s, tstp) ⇒ i + 1 ≤ ia ∧ reach_window args t0 sub rho (ia, ti, si, j, tj, sj) ∧ steps step rho init (i + 1, ia) = q ∧ (∀q. case Mapping.lookup ac q of None ⇒ True | Some x ⇒ accept q = x) ∧ ((∀q bs. case Mapping.lookup st (q, bs) of None ⇒ True | Some v ⇒ step q bs = v) ∧ mmap_keys s = {q. ∃l≤i. steps step rho init (l, ia) = q} ∧ distinct (map fst s) ∧ (∀q. case mmap_lookup s q of None ⇒ True | Some (q', tstp) ⇒ steps step rho q (ia, j) = q' ∧ tstp = sup_acc step accept rho q ia j)) ∧ tstp = sup_acc step accept rho init (i + 1) ia) ∧ ¬ loop_cond j (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) ⟹ ∀q. case Mapping.lookup ac_cur q of None ⇒ True | Some v ⇒ accept q = v› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have valid_s'': "valid_s init step st_cur accept rho (i + 1) (i + 1) j s''" proof (cases "mmap_lookup s_cur q_cur") (*goals: 1. ‹mmap_lookup s_cur q_cur = None ⟹ valid_s init step st_cur accept rho (i + 1) (i + 1) j s''› 2. ‹⋀a. mmap_lookup s_cur q_cur = Some a ⟹ valid_s init step st_cur accept rho (i + 1) (i + 1) j s''›*) case None (*‹mmap_lookup s_cur q_cur = None›*) then have added: "steps step rho init (i + 1, j) = q_cur" "tstp_cur = sup_acc step accept rho init (i + 1) j" using loop (*‹loop_inv init step accept args t0 sub rho i j tj sj (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) ∧ ¬ loop_cond j (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur)›*) unfolding loop_inv_def loop_cond_def (*goals: 1. ‹steps step rho init (i + 1, j) = q_cur› 2. ‹tstp_cur = sup_acc step accept rho init (i + 1) j›*) apply - (*goals: 1. ‹⟦mmap_lookup (s_cur::('b × 'b × ('c × nat) option) list) (q_cur::'b) = None; (case (st_cur::('b × 'a, 'b) mapping, ac_cur::('b, bool) mapping, i_cur::nat, ti_cur::'d, si_cur::'e, q_cur, s_cur, tstp_cur::('c × nat) option) of (st::('b × 'a, 'b) mapping, ac::('b, bool) mapping, ia::nat, ti::'d, si::'e, q::'b, s::('b × 'b × ('c × nat) option) list, tstp::('c × nat) option) ⇒ (i::nat) + (1::nat) ≤ ia ∧ reach_window (args::('a, 'b, 'c, 'd, 'e) Window.args) (t0::'d) (sub::'e) (rho::('c × 'a) list) (ia, ti, si, j::nat, tj::'d, sj::'e) ∧ steps (step::'b ⇒ 'a ⇒ 'b) rho (init::'b) (i + (1::nat), ia) = q ∧ (∀q::'b. case Mapping.lookup ac q of None ⇒ True | Some (x::bool) ⇒ (accept::'b ⇒ bool) q = x) ∧ valid_s init step st accept rho i ia j s ∧ tstp = sup_acc step accept rho init (i + (1::nat)) ia) ∧ ¬ (case (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) of (st::('b × 'a, 'b) mapping, ac::('b, bool) mapping, i::nat, ti::'d, si::'e, q::'b, s::('b × 'b × ('c × nat) option) list, tstp::('c × nat) option) ⇒ i < j ∧ q ∉ mmap_keys s)⟧ ⟹ steps step rho init (i + (1::nat), j) = q_cur› 2. ‹⟦mmap_lookup (s_cur::('b × 'b × ('c × nat) option) list) (q_cur::'b) = None; (case (st_cur::('b × 'a, 'b) mapping, ac_cur::('b, bool) mapping, i_cur::nat, ti_cur::'d, si_cur::'e, q_cur, s_cur, tstp_cur::('c × nat) option) of (st::('b × 'a, 'b) mapping, ac::('b, bool) mapping, ia::nat, ti::'d, si::'e, q::'b, s::('b × 'b × ('c × nat) option) list, tstp::('c × nat) option) ⇒ (i::nat) + (1::nat) ≤ ia ∧ reach_window (args::('a, 'b, 'c, 'd, 'e) Window.args) (t0::'d) (sub::'e) (rho::('c × 'a) list) (ia, ti, si, j::nat, tj::'d, sj::'e) ∧ steps (step::'b ⇒ 'a ⇒ 'b) rho (init::'b) (i + (1::nat), ia) = q ∧ (∀q::'b. case Mapping.lookup ac q of None ⇒ True | Some (x::bool) ⇒ (accept::'b ⇒ bool) q = x) ∧ valid_s init step st accept rho i ia j s ∧ tstp = sup_acc step accept rho init (i + (1::nat)) ia) ∧ ¬ (case (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) of (st::('b × 'a, 'b) mapping, ac::('b, bool) mapping, i::nat, ti::'d, si::'e, q::'b, s::('b × 'b × ('c × nat) option) list, tstp::('c × nat) option) ⇒ i < j ∧ q ∉ mmap_keys s)⟧ ⟹ tstp_cur = sup_acc step accept rho init (i + (1::nat)) j› discuss goal 1*) apply ((auto dest: Mapping_keys_dest (*‹?x ∈ mmap_keys ?f ⟹ ∃y. mmap_lookup ?f ?x = Some y›*))[1]) (*discuss goal 2*) apply ((auto dest: Mapping_keys_dest (*‹?x ∈ mmap_keys ?f ⟹ ∃y. mmap_lookup ?f ?x = Some y›*))[1]) (*proven 2 subgoals*) . have s''_case: "s'' = mmap_update init (q_cur, tstp_cur) s'" unfolding s''_def (*goal: ‹mmap_update init (case mmap_lookup s_cur q_cur of None ⇒ (q_cur, tstp_cur) | Some (q', tstp') ⇒ case tstp' of None ⇒ (q', tstp_cur) | Some (ts, tp) ⇒ (q', tstp')) s' = mmap_update init (q_cur, tstp_cur) s'›*) using None (*‹mmap_lookup s_cur q_cur = None›*) by auto show "?thesis" (*goal: ‹valid_s init step st_cur accept rho (i + 1) (i + 1) j s''›*) using valid_s'_Suc_i (*‹valid_s init step st' accept rho i (i + 1) j s'›*) reach_split (*‹{q. ∃l≤i + 1. steps step rho init (l, i + 1) = q} = {q. ∃l≤i. steps step rho init (l, i + 1) = q} ∪ {init}›*) added (*‹steps step rho init (i + 1, j) = q_cur› ‹tstp_cur = sup_acc step accept rho init (i + 1) j›*) mmap_update_distinct (*‹distinct (map fst ?m) ⟹ distinct (map fst (mmap_update ?k ?v ?m))›*) valid_stac_cur (*‹∀q bs. case Mapping.lookup st_cur (q, bs) of None ⇒ True | Some v ⇒ step q bs = v› ‹∀q. case Mapping.lookup ac_cur q of None ⇒ True | Some v ⇒ accept q = v›*) unfolding s''_case valid_s_def mmap_keys_update (*goal: ‹(∀q bs. case Mapping.lookup st_cur (q, bs) of None ⇒ True | Some v ⇒ step q bs = v) ∧ mmap_keys s' ∪ {init} = {q. ∃l≤i + 1. steps step rho init (l, i + 1) = q} ∧ distinct (map fst (mmap_update init (q_cur, tstp_cur) s')) ∧ (∀q. case mmap_lookup (mmap_update init (q_cur, tstp_cur) s') q of None ⇒ True | Some (q', tstp) ⇒ steps step rho q (i + 1, j) = q' ∧ tstp = sup_acc step accept rho q (i + 1) j)›*) by (auto simp add: mmap_lookup_update' (*‹mmap_lookup (mmap_update ?k ?v ?kvs) ?z = (if ?k = ?z then Some ?v else mmap_lookup ?kvs ?z)›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) next (*goal: ‹⋀a. mmap_lookup s_cur q_cur = Some a ⟹ valid_s init step st_cur accept rho (i + 1) (i + 1) j s''›*) case (Some p) (*‹mmap_lookup s_cur q_cur = Some p›*) obtain q' and tstp' where p_def: "p = (q', tstp')" (*goal: ‹(⋀q' tstp'. p = (q', tstp') ⟹ thesis) ⟹ thesis›*) apply (cases p) (*goal: ‹(⋀(q'::'b::type) tstp'::('c::timestamp × nat) option. (p::'b::type × ('c::timestamp × nat) option) = (q', tstp') ⟹ thesis::bool) ⟹ thesis›*) by auto note lookup_s_cur = Some[unfolded p_def] (*‹mmap_lookup (s_cur::('b::type × 'b::type × ('c::timestamp × nat) option) list) (q_cur::'b::type) = Some (q'::'b::type, tstp'::('c::timestamp × nat) option)›*) have i_cur_in: "i + 1 ≤ i_cur" "i_cur ≤ j" using loop (*‹loop_inv init step accept args t0 sub rho i j tj sj (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) ∧ ¬ loop_cond j (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur)›*) unfolding loop_inv_def (*goals: 1. ‹i + 1 ≤ i_cur› 2. ‹i_cur ≤ j›*) apply - (*goals: 1. ‹(case (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) of (st, ac, ia, ti, si, q, s, tstp) ⇒ i + 1 ≤ ia ∧ reach_window args t0 sub rho (ia, ti, si, j, tj, sj) ∧ steps step rho init (i + 1, ia) = q ∧ (∀q. case Mapping.lookup ac q of None ⇒ True | Some x ⇒ accept q = x) ∧ valid_s init step st accept rho i ia j s ∧ tstp = sup_acc step accept rho init (i + 1) ia) ∧ ¬ loop_cond j (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) ⟹ i + 1 ≤ i_cur› 2. ‹(case (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) of (st, ac, ia, ti, si, q, s, tstp) ⇒ i + 1 ≤ ia ∧ reach_window args t0 sub rho (ia, ti, si, j, tj, sj) ∧ steps step rho init (i + 1, ia) = q ∧ (∀q. case Mapping.lookup ac q of None ⇒ True | Some x ⇒ accept q = x) ∧ valid_s init step st accept rho i ia j s ∧ tstp = sup_acc step accept rho init (i + 1) ia) ∧ ¬ loop_cond j (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) ⟹ i_cur ≤ j› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have q_cur_def: "steps step rho init (i + 1, i_cur) = q_cur" using loop (*‹loop_inv init step accept args t0 sub rho i j tj sj (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) ∧ ¬ loop_cond j (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur)›*) unfolding loop_inv_def (*goal: ‹steps step rho init (i + 1, i_cur) = q_cur›*) by auto have valid_s_cur: "valid_s init step st_cur accept rho i i_cur j s_cur" using loop (*‹loop_inv init step accept args t0 sub rho i j tj sj (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) ∧ ¬ loop_cond j (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur)›*) unfolding loop_inv_def (*goal: ‹valid_s init step st_cur accept rho i i_cur j s_cur›*) by auto have q'_steps: "steps step rho q_cur (i_cur, j) = q'" using Some (*‹mmap_lookup s_cur q_cur = Some p›*) valid_s_cur (*‹valid_s init step st_cur accept rho i i_cur j s_cur›*) unfolding valid_s_def p_def (*goal: ‹steps (step::'b ⇒ 'a ⇒ 'b) (rho::('c × 'a) list) (q_cur::'b) (i_cur::nat, j::nat) = (q'::'b)›*) apply (auto intro: Mapping_keys_intro (*‹mmap_lookup ?f ?x ≠ None ⟹ ?x ∈ mmap_keys ?f›*)) (*goal: ‹steps step rho q_cur (i_cur, j) = q'›*) by (smt case_prodD (*‹case (?a, ?b) of (c, d) ⇒ ?f c d ⟹ ?f ?a ?b›*) option.simps( (*‹(case Some ?x2.0 of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ?f2.0 ?x2.0›*) 5)) have tstp_cur: "tstp_cur = sup_acc step accept rho init (i + 1) i_cur" using loop (*‹loop_inv init step accept args t0 sub rho i j tj sj (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) ∧ ¬ loop_cond j (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur)›*) unfolding loop_inv_def (*goal: ‹tstp_cur = sup_acc step accept rho init (i + 1) i_cur›*) by auto have tstp': "tstp' = sup_acc step accept rho q_cur i_cur j" using loop (*‹loop_inv init step accept args t0 sub rho i j tj sj (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) ∧ ¬ loop_cond j (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur)›*) Some (*‹mmap_lookup s_cur q_cur = Some p›*) unfolding loop_inv_def p_def valid_s_def (*goal: ‹tstp' = sup_acc step accept rho q_cur i_cur j›*) apply (auto intro: Mapping_keys_intro (*‹mmap_lookup ?f ?x ≠ None ⟹ ?x ∈ mmap_keys ?f›*)) (*goal: ‹tstp' = sup_acc step accept rho q_cur i_cur j›*) by (smt case_prodD (*‹case (?a, ?b) of (c, d) ⇒ ?f c d ⟹ ?f ?a ?b›*) option.simps( (*‹(case Some ?x2.0 of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ?f2.0 ?x2.0›*) 5)) have added: "steps step rho init (i + 1, j) = q'" using steps_comp[OF i_cur_in q_cur_def q'_steps] (*‹steps (step::'b::type ⇒ 'a::type ⇒ 'b::type) (rho::('c::timestamp × 'a::type) list) (init::'b::type) ((i::nat) + (1::nat), j::nat) = (q'::'b::type)›*) . show "?thesis" (*goal: ‹valid_s init step st_cur accept rho (i + 1) (i + 1) j s''›*) proof (cases tstp') (*goals: 1. ‹tstp' = None ⟹ valid_s init step st_cur accept rho (i + 1) (i + 1) j s''› 2. ‹⋀a. tstp' = Some a ⟹ valid_s init step st_cur accept rho (i + 1) (i + 1) j s''›*) case None (*‹tstp' = None›*) have s''_case: "s'' = mmap_update init (q', tstp_cur) s'" unfolding s''_def lookup_s_cur None (*goal: ‹mmap_update init (case Some (q', None) of None ⇒ (q_cur, tstp_cur) | Some (q', tstp') ⇒ case tstp' of None ⇒ (q', tstp_cur) | Some (ts, tp) ⇒ (q', tstp')) s' = mmap_update init (q', tstp_cur) s'›*) by auto have tstp_cur_opt: "tstp_cur = sup_acc step accept rho init (i + 1) j" using sup_acc_comp_None[OF i_cur_in, of step accept rho init, unfolded q_cur_def, OF tstp' [ unfolded None , symmetric ]] (*‹sup_acc step accept rho init (i + 1) j = sup_acc step accept rho init (i + 1) i_cur›*) unfolding tstp_cur (*goal: ‹sup_acc step accept rho init (i + 1) i_cur = sup_acc step accept rho init (i + 1) j›*) by auto then show "?thesis" (*goal: ‹valid_s init step st_cur accept rho (i + 1) (i + 1) j s''›*) using valid_s'_Suc_i (*‹valid_s init step st' accept rho i (i + 1) j s'›*) reach_split (*‹{q::'b::type. ∃l≤(i::nat) + (1::nat). steps (step::'b::type ⇒ 'a::type ⇒ 'b::type) (rho::('c::timestamp × 'a::type) list) (init::'b::type) (l, i + (1::nat)) = q} = {q::'b::type. ∃l≤i. steps step rho init (l, i + (1::nat)) = q} ∪ {init}›*) added (*‹steps (step::'b ⇒ 'a ⇒ 'b) (rho::('c × 'a) list) (init::'b) ((i::nat) + (1::nat), j::nat) = (q'::'b)›*) mmap_update_distinct (*‹distinct (map fst (?m::(?'a::type × ?'b::type) list)) ⟹ distinct (map fst (mmap_update (?k::?'a::type) (?v::?'b::type) ?m))›*) valid_stac_cur (*‹∀(q::'b::type) bs::'a::type. case Mapping.lookup (st_cur::('b::type × 'a::type, 'b::type) mapping) (q, bs) of None ⇒ True | Some (v::'b::type) ⇒ (step::'b::type ⇒ 'a::type ⇒ 'b::type) q bs = v› ‹∀q. case Mapping.lookup ac_cur q of None ⇒ True | Some v ⇒ accept q = v›*) unfolding s''_case valid_s_def mmap_keys_update (*goal: ‹(∀q bs. case Mapping.lookup st_cur (q, bs) of None ⇒ True | Some v ⇒ step q bs = v) ∧ mmap_keys s' ∪ {init} = {q. ∃l≤i + 1. steps step rho init (l, i + 1) = q} ∧ distinct (map fst (mmap_update init (q', tstp_cur) s')) ∧ (∀q. case mmap_lookup (mmap_update init (q', tstp_cur) s') q of None ⇒ True | Some (q', tstp) ⇒ steps step rho q (i + 1, j) = q' ∧ tstp = sup_acc step accept rho q (i + 1) j)›*) by (auto simp add: mmap_lookup_update' (*‹mmap_lookup (mmap_update ?k ?v ?kvs) ?z = (if ?k = ?z then Some ?v else mmap_lookup ?kvs ?z)›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) next (*goal: ‹⋀a::'c × nat. (tstp'::('c × nat) option) = Some a ⟹ valid_s (init::'b) (step::'b ⇒ 'a ⇒ 'b) (st_cur::('b × 'a, 'b) mapping) (accept::'b ⇒ bool) (rho::('c × 'a) list) ((i::nat) + (1::nat)) (i + (1::nat)) (j::nat) (s''::('b × 'b × ('c × nat) option) list)›*) case (Some p') (*‹(tstp'::('c::timestamp × nat) option) = Some (p'::'c::timestamp × nat)›*) obtain ts and tp where p'_def: "p' = (ts, tp)" (*goal: ‹(⋀(ts::'c) tp::nat. (p'::'c × nat) = (ts, tp) ⟹ thesis::bool) ⟹ thesis›*) apply (cases p') (*goal: ‹(⋀ts tp. p' = (ts, tp) ⟹ thesis) ⟹ thesis›*) by auto have True: "tp ≥ i_cur" using sup_acc_SomeE[OF tstp' [ unfolded Some p'_def , symmetric ]] (*‹tp ∈ {i_cur..<j} ∧ acc step accept rho q_cur (i_cur, Suc tp)›*) by auto have s''_case: "s'' = mmap_update init (q', tstp') s'" unfolding s''_def lookup_s_cur Some p'_def (*goal: ‹mmap_update (init::'b) (case Some (q'::'b, Some (ts::'c, tp::nat)) of None ⇒ (q_cur::'b, tstp_cur::('c × nat) option) | Some (q'::'b, tstp'::('c × nat) option) ⇒ case tstp' of None ⇒ (q', tstp_cur) | Some (ts::'c, tp::nat) ⇒ (q', tstp')) (s'::('b × 'b × ('c × nat) option) list) = mmap_update init (q', Some (ts, tp)) s'›*) using True (*‹i_cur ≤ tp›*) by auto have tstp'_opt: "tstp' = sup_acc step accept rho init (i + 1) j" using sup_acc_comp_Some_ge[OF i_cur_in True tstp' [ unfolded Some p'_def q_cur_def [ symmetric ] , symmetric ]] (*‹sup_acc (step::'b::type ⇒ 'a::type ⇒ 'b::type) (accept::'b::type ⇒ bool) (rho::('c::timestamp × 'a::type) list) (init::'b::type) ((i::nat) + (1::nat)) (j::nat) = sup_acc step accept rho (steps step rho init (i + (1::nat), i_cur::nat)) i_cur j›*) unfolding tstp' (*goal: ‹sup_acc (step::'b ⇒ 'a ⇒ 'b) (accept::'b ⇒ bool) (rho::('c × 'a) list) (q_cur::'b) (i_cur::nat) (j::nat) = sup_acc step accept rho (init::'b) ((i::nat) + (1::nat)) j›*) by (auto simp: q_cur_def[symmetric] (*‹(q_cur::'b) = steps (step::'b ⇒ 'a ⇒ 'b) (rho::('c × 'a) list) (init::'b) ((i::nat) + (1::nat), i_cur::nat)›*)) then show "?thesis" (*goal: ‹valid_s init step st_cur accept rho (i + 1) (i + 1) j s''›*) using valid_s'_Suc_i (*‹valid_s init step st' accept rho i (i + 1) j s'›*) reach_split (*‹{q. ∃l≤i + 1. steps step rho init (l, i + 1) = q} = {q. ∃l≤i. steps step rho init (l, i + 1) = q} ∪ {init}›*) added (*‹steps step rho init (i + 1, j) = q'›*) mmap_update_distinct (*‹distinct (map fst ?m) ⟹ distinct (map fst (mmap_update ?k ?v ?m))›*) valid_stac_cur (*‹∀q bs. case Mapping.lookup st_cur (q, bs) of None ⇒ True | Some v ⇒ step q bs = v› ‹∀q. case Mapping.lookup ac_cur q of None ⇒ True | Some v ⇒ accept q = v›*) unfolding s''_case valid_s_def mmap_keys_update (*goal: ‹(∀(q::'b) bs::'a. case Mapping.lookup (st_cur::('b × 'a, 'b) mapping) (q, bs) of None ⇒ True | Some (v::'b) ⇒ (step::'b ⇒ 'a ⇒ 'b) q bs = v) ∧ mmap_keys (s'::('b × 'b × ('c × nat) option) list) ∪ {init::'b} = {q::'b. ∃l≤(i::nat) + (1::nat). steps step (rho::('c × 'a) list) init (l, i + (1::nat)) = q} ∧ distinct (map fst (mmap_update init (q'::'b, tstp'::('c × nat) option) s')) ∧ (∀q::'b. case mmap_lookup (mmap_update init (q', tstp') s') q of None ⇒ True | Some (q'::'b, tstp::('c × nat) option) ⇒ steps step rho q (i + (1::nat), j::nat) = q' ∧ tstp = sup_acc step (accept::'b ⇒ bool) rho q (i + (1::nat)) j)›*) by (auto simp add: mmap_lookup_update' (*‹mmap_lookup (mmap_update (?k::?'b::type) (?v::?'a::type) (?kvs::(?'b::type × ?'a::type) list)) (?z::?'b::type) = (if ?k = ?z then Some ?v else mmap_lookup ?kvs ?z)›*) split: option.splits (*‹(?P::?'b::type ⇒ bool) (case ?option::?'a::type option of None ⇒ ?f1.0::?'b::type | Some (x::?'a::type) ⇒ (?f2.0::?'a::type ⇒ ?'b::type) x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2::?'a::type. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹(?P::?'b::type ⇒ bool) (case ?option::?'a::type option of None ⇒ ?f1.0::?'b::type | Some (x::?'a::type) ⇒ (?f2.0::?'a::type ⇒ ?'b::type) x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2::?'a::type. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) qed qed have "distinct (map fst e')" using mmap_update_distinct[OF distinct_before ( 2 ), unfolded e'_def] (*‹distinct (map fst (mmap_update (?k::'b) (?v::'c) (e::('b × 'c) list)))›*) unfolding e'_def (*goal: ‹distinct (map fst (mmap_update (fst (the (mmap_lookup (s::('b::type × 'b::type × ('c::timestamp × nat) option) list) (init::'b::type)))) (t::'c::timestamp) (e::('b::type × 'c::timestamp) list)))›*) . then have "valid_window args t0 sub rho (w⦇w_st := st_cur, w_ac := ac_cur, w_i := Suc i, w_ti := ti', w_si := si', w_s := s'', w_e := e'⦈)" using i_lt_j (*‹i < j›*) lookup_e' (*‹mmap_lookup e' ?q1 = sup_leadsto init step rho (i + 1) j ?q1›*) valid_s'' (*‹valid_s init step st_cur accept rho (i + 1) (i + 1) j s''›*) length_rho (*‹length rho = j›*) tb_def(3,4) (*‹reaches_on run_t ti' (drop (Suc i) (map fst rho)) tj› ‹reaches_on run_sub si' (drop (Suc i) (map snd rho)) sj›*) reaches_on_si' (*‹reaches_on run_sub sub (take (Suc i) (map snd rho)) si'›*) reaches_on_ti' (*‹reaches_on run_t t0 (take (Suc i) (map fst rho)) ti'›*) valid_before[unfolded step_def accept_def] (*‹reach_window args t0 sub rho (i, ti, si, j, tj, sj)› ‹⟦?i ≤ ?j; ?j < length rho⟧ ⟹ ts_at rho ?i ≤ ts_at rho ?j› ‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ w_step args ?q ?bs = v› ‹case Mapping.lookup ac ?q of None ⇒ True | Some v ⇒ w_accept args ?q = v› ‹∀q. mmap_lookup e q = sup_leadsto init (w_step args) rho i j q› ‹distinct (map fst e)› ‹valid_s init (w_step args) st (w_accept args) rho i i j s›*) valid_stac_cur(2)[unfolded accept_def] (*‹∀q. case Mapping.lookup ac_cur q of None ⇒ True | Some v ⇒ w_accept args q = v›*) by (auto simp: valid_window_def (*‹valid_window (?args::(?'b, ?'c, ?'d, ?'t, ?'e) Window.args) (?t0.0::?'t) (?sub::?'e) (?rho::(?'d × ?'b) list) (?w::(?'b, ?'c, ?'d, ?'t, ?'e) window) = (let init::?'c = w_init ?args; step::?'c ⇒ ?'b ⇒ ?'c = w_step ?args; accept::?'c ⇒ bool = w_accept ?args; run_t::?'t ⇒ (?'t × ?'d) option = w_run_t ?args; run_sub::?'e ⇒ (?'e × ?'b) option = w_run_sub ?args; st::(?'c × ?'b, ?'c) mapping = w_st ?w; ac::(?'c, bool) mapping = w_ac ?w; i::nat = w_i ?w; ti::?'t = w_ti ?w; si::?'e = w_si ?w; j::nat = w_j ?w; tj::?'t = w_tj ?w; sj::?'e = w_sj ?w; s::(?'c × ?'c × (?'d × nat) option) list = w_s ?w; e::(?'c × ?'d) list = w_e ?w in reach_window ?args ?t0.0 ?sub ?rho (i, ti, si, j, tj, sj) ∧ (∀(i::nat) j::nat. i ≤ j ∧ j < length ?rho ⟶ ts_at ?rho i ≤ ts_at ?rho j) ∧ (∀q::?'c. case Mapping.lookup ac q of None ⇒ True | Some (v::bool) ⇒ accept q = v) ∧ (∀q::?'c. mmap_lookup e q = sup_leadsto init step ?rho i j q) ∧ distinct (map fst e) ∧ valid_s init step st accept ?rho i i j s)›*) Let_def (*‹Let (?s::?'a) (?f::?'a ⇒ ?'b) ≡ ?f ?s›*) init_def (*‹(init::'b) = w_init (args::('a, 'b, 'c, 'd, 'e) Window.args)›*) step_def (*‹(step::'b ⇒ 'a ⇒ 'b) = w_step (args::('a, 'b, 'c, 'd, 'e) Window.args)›*) accept_def (*‹(accept::'b ⇒ bool) = w_accept (args::('a, 'b, 'c, 'd, 'e) Window.args)›*) run_t_def (*‹(run_t::'d ⇒ ('d × 'c) option) = w_run_t (args::('a, 'b, 'c, 'd, 'e) Window.args)›*) run_sub_def (*‹(run_sub::'e ⇒ ('e × 'a) option) = w_run_sub (args::('a, 'b, 'c, 'd, 'e) Window.args)›*) st_def (*‹(st::('b × 'a, 'b) mapping) = w_st (w::('a, 'b, 'c, 'd, 'e) window)›*) ac_def (*‹(ac::('b, bool) mapping) = w_ac (w::('a, 'b, 'c, 'd, 'e) window)›*) i_def (*‹(i::nat) = w_i (w::('a, 'b, 'c, 'd, 'e) window)›*) ti_def (*‹(ti::'d) = w_ti (w::('a, 'b, 'c, 'd, 'e) window)›*) si_def (*‹(si::'e) = w_si (w::('a, 'b, 'c, 'd, 'e) window)›*) j_def (*‹(j::nat) = w_j (w::('a, 'b, 'c, 'd, 'e) window)›*) tj_def (*‹(tj::'d) = w_tj (w::('a, 'b, 'c, 'd, 'e) window)›*) sj_def (*‹(sj::'e) = w_sj (w::('a, 'b, 'c, 'd, 'e) window)›*) s_def (*‹(s::('b × 'b × ('c × nat) option) list) = w_s (w::('a, 'b, 'c, 'd, 'e) window)›*) e_def (*‹(e::('b × 'c) list) = w_e (w::('a, 'b, 'c, 'd, 'e) window)›*)) moreover have "adv_start args w = w⦇w_st := st_cur, w_ac := ac_cur, w_i := Suc i, w_ti := ti', w_si := si', w_s := s'', w_e := e'⦈" unfolding adv_start_def Let_def s''_def e'_def (*goal: ‹(case w_run_t args (w_ti w) of Some (ti', t) ⇒ case w_run_sub args (w_si w) of Some (si', bs) ⇒ case adv_d (w_step args) (w_st w) (w_i w) bs (w_s w) of (s', st') ⇒ case while (loop_cond (w_j w)) (loop_body (w_step args) (w_accept args) (w_run_t args) (w_run_sub args)) (st', w_ac w, Suc (w_i w), ti', si', w_init args, s', None) of (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) ⇒ w⦇w_st := st_cur, w_ac := ac_cur, w_i := Suc (w_i w), w_ti := ti', w_si := si', w_s := mmap_update (w_init args) (case mmap_lookup s_cur q_cur of None ⇒ (q_cur, tstp_cur) | Some (q', tstp') ⇒ case tstp' of None ⇒ (q', tstp_cur) | Some (ts, tp) ⇒ (q', tstp')) s', w_e := mmap_update (fst (the (mmap_lookup (w_s w) (w_init args)))) t (w_e w)⦈) = w⦇w_st := st_cur, w_ac := ac_cur, w_i := Suc i, w_ti := ti', w_si := si', w_s := mmap_update init (case mmap_lookup s_cur q_cur of None ⇒ (q_cur, tstp_cur) | Some (q', tstp') ⇒ case tstp' of None ⇒ (q', tstp_cur) | Some (ts, tp) ⇒ (q', tstp')) s', w_e := mmap_update (fst (the (mmap_lookup s init))) t e⦈›*) using tb_def(1,2) (*‹run_t ti = Some (ti', t)› ‹run_sub si = Some (si', b)›*) s'_def (*‹adv_d step st i b s = (s', st')›*) i_lt_j (*‹i < j›*) loop_def (*‹(st_cur::('b × 'a, 'b) mapping, ac_cur::('b, bool) mapping, i_cur::nat, ti_cur::'d, si_cur::'e, q_cur::'b, s_cur::('b × 'b × ('c × nat) option) list, tstp_cur::('c × nat) option) = while (loop_cond (j::nat)) (loop_body (step::'b ⇒ 'a ⇒ 'b) (accept::'b ⇒ bool) (run_t::'d ⇒ ('d × 'c) option) (run_sub::'e ⇒ ('e × 'a) option)) (st'::('b × 'a, 'b) mapping, ac::('b, bool) mapping, Suc (i::nat), ti'::'d, si'::'e, init::'b, s'::('b × 'b × ('c × nat) option) list, None)›*) valid_before(3) (*‹case Mapping.lookup st (?q, ?bs) of None ⇒ True | Some v ⇒ step ?q ?bs = v›*) by (auto simp: valid_window_def (*‹valid_window ?args ?t0.0 ?sub ?rho ?w = (let init = w_init ?args; step = w_step ?args; accept = w_accept ?args; run_t = w_run_t ?args; run_sub = w_run_sub ?args; st = w_st ?w; ac = w_ac ?w; i = w_i ?w; ti = w_ti ?w; si = w_si ?w; j = w_j ?w; tj = w_tj ?w; sj = w_sj ?w; s = w_s ?w; e = w_e ?w in reach_window ?args ?t0.0 ?sub ?rho (i, ti, si, j, tj, sj) ∧ (∀i j. i ≤ j ∧ j < length ?rho ⟶ ts_at ?rho i ≤ ts_at ?rho j) ∧ (∀q. case Mapping.lookup ac q of None ⇒ True | Some v ⇒ accept q = v) ∧ (∀q. mmap_lookup e q = sup_leadsto init step ?rho i j q) ∧ distinct (map fst e) ∧ valid_s init step st accept ?rho i i j s)›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) init_def (*‹init = w_init args›*) step_def (*‹step = w_step args›*) accept_def (*‹accept = w_accept args›*) run_t_def (*‹run_t = w_run_t args›*) run_sub_def (*‹run_sub = w_run_sub args›*) st_def (*‹st = w_st w›*) ac_def (*‹ac = w_ac w›*) i_def (*‹i = w_i w›*) ti_def (*‹ti = w_ti w›*) si_def (*‹si = w_si w›*) j_def (*‹j = w_j w›*) tj_def (*‹tj = w_tj w›*) sj_def (*‹sj = w_sj w›*) s_def (*‹s = w_s w›*) e_def (*‹e = w_e w›*) split: prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*)) ultimately show "?thesis" (*goal: ‹valid_window args t0 sub rho (adv_start args w)›*) by auto qed lemma valid_adv_start_bounds: assumes "valid_window args t0 sub rho w" "w_i w < w_j w" shows "w_i (adv_start args w) = Suc (w_i w)" "w_j (adv_start args w) = w_j w" "w_tj (adv_start args w) = w_tj w" "w_sj (adv_start args w) = w_sj w" using assms (*‹valid_window args t0 sub rho w› ‹w_i w < w_j w›*) apply - (*goals: 1. ‹⟦valid_window args t0 sub rho w; w_i w < w_j w⟧ ⟹ w_i (adv_start args w) = Suc (w_i w)› 2. ‹⟦valid_window args t0 sub rho w; w_i w < w_j w⟧ ⟹ w_j (adv_start args w) = w_j w› 3. ‹⟦valid_window args t0 sub rho w; w_i w < w_j w⟧ ⟹ w_tj (adv_start args w) = w_tj w› 4. ‹⟦valid_window args t0 sub rho w; w_i w < w_j w⟧ ⟹ w_sj (adv_start args w) = w_sj w› discuss goal 1*) apply ((auto simp: adv_start_def (*‹adv_start (?args::(?'b, ?'c, ?'d, ?'t, ?'e) Window.args) (?w::(?'b, ?'c, ?'d, ?'t, ?'e) window) = (let init::?'c = w_init ?args; step::?'c ⇒ ?'b ⇒ ?'c = w_step ?args; accept::?'c ⇒ bool = w_accept ?args; run_t::?'t ⇒ (?'t × ?'d) option = w_run_t ?args; run_sub::?'e ⇒ (?'e × ?'b) option = w_run_sub ?args; st::(?'c × ?'b, ?'c) mapping = w_st ?w; ac::(?'c, bool) mapping = w_ac ?w; i::nat = w_i ?w; ti::?'t = w_ti ?w; si::?'e = w_si ?w; j::nat = w_j ?w; s::(?'c × ?'c × (?'d × nat) option) list = w_s ?w; e::(?'c × ?'d) list = w_e ?w in case run_t ti of Some (ti'::?'t, t::?'d) ⇒ case run_sub si of Some (si'::?'e, bs::?'b) ⇒ let (s'::(?'c × ?'c × (?'d × nat) option) list, st'::(?'c × ?'b, ?'c) mapping) = adv_d step st i bs s; e'::(?'c × ?'d) list = mmap_update (fst (the (mmap_lookup s init))) t e; (st_cur::(?'c × ?'b, ?'c) mapping, ac_cur::(?'c, bool) mapping, i_cur::nat, ti_cur::?'t, si_cur::?'e, q_cur::?'c, s_cur::(?'c × ?'c × (?'d × nat) option) list, tstp_cur::(?'d × nat) option) = while (loop_cond j) (loop_body step accept run_t run_sub) (st', ac, Suc i, ti', si', init, s', None); s''::(?'c × ?'c × (?'d × nat) option) list = mmap_update init (case mmap_lookup s_cur q_cur of None ⇒ (q_cur, tstp_cur) | Some (q'::?'c, tstp'::(?'d × nat) option) ⇒ case tstp' of None ⇒ (q', tstp_cur) | Some (ts::?'d, tp::nat) ⇒ (q', tstp')) s' in ?w⦇w_st := st_cur, w_ac := ac_cur, w_i := Suc i, w_ti := ti', w_si := si', w_s := s'', w_e := e'⦈)›*) Let_def (*‹Let (?s::?'a) (?f::?'a ⇒ ?'b) ≡ ?f ?s›*) valid_window_def (*‹valid_window (?args::(?'b, ?'c, ?'d, ?'t, ?'e) Window.args) (?t0.0::?'t) (?sub::?'e) (?rho::(?'d × ?'b) list) (?w::(?'b, ?'c, ?'d, ?'t, ?'e) window) = (let init::?'c = w_init ?args; step::?'c ⇒ ?'b ⇒ ?'c = w_step ?args; accept::?'c ⇒ bool = w_accept ?args; run_t::?'t ⇒ (?'t × ?'d) option = w_run_t ?args; run_sub::?'e ⇒ (?'e × ?'b) option = w_run_sub ?args; st::(?'c × ?'b, ?'c) mapping = w_st ?w; ac::(?'c, bool) mapping = w_ac ?w; i::nat = w_i ?w; ti::?'t = w_ti ?w; si::?'e = w_si ?w; j::nat = w_j ?w; tj::?'t = w_tj ?w; sj::?'e = w_sj ?w; s::(?'c × ?'c × (?'d × nat) option) list = w_s ?w; e::(?'c × ?'d) list = w_e ?w in reach_window ?args ?t0.0 ?sub ?rho (i, ti, si, j, tj, sj) ∧ (∀(i::nat) j::nat. i ≤ j ∧ j < length ?rho ⟶ ts_at ?rho i ≤ ts_at ?rho j) ∧ (∀q::?'c. case Mapping.lookup ac q of None ⇒ True | Some (v::bool) ⇒ accept q = v) ∧ (∀q::?'c. mmap_lookup e q = sup_leadsto init step ?rho i j q) ∧ distinct (map fst e) ∧ valid_s init step st accept ?rho i i j s)›*) split: option.splits (*‹(?P::?'b ⇒ bool) (case ?option::?'a option of None ⇒ ?f1.0::?'b | Some (x::?'a) ⇒ (?f2.0::?'a ⇒ ?'b) x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2::?'a. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹(?P::?'b ⇒ bool) (case ?option::?'a option of None ⇒ ?f1.0::?'b | Some (x::?'a) ⇒ (?f2.0::?'a ⇒ ?'b) x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2::?'a. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) prod.splits (*‹(?P::?'c ⇒ bool) (case ?prod::?'a × ?'b of (x::?'a, xa::?'b) ⇒ (?f::?'a ⇒ ?'b ⇒ ?'c) x xa) = (∀(x1::?'a) x2::?'b. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹(?P::?'c ⇒ bool) (case ?prod::?'a × ?'b of (x::?'a, xa::?'b) ⇒ (?f::?'a ⇒ ?'b ⇒ ?'c) x xa) = (∄(x1::?'a) x2::?'b. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*) elim: reaches_on.cases (*‹⟦reaches_on (?run::?'e ⇒ (?'e × ?'f) option) (?a1.0::?'e) (?a2.0::?'f list) (?a3.0::?'e); ⋀s::?'e. ⟦?a1.0 = s; ?a2.0 = []; ?a3.0 = s⟧ ⟹ ?P::bool; ⋀(s::?'e) (s'::?'e) (v::?'f) (vs::?'f list) s''::?'e. ⟦?a1.0 = s; ?a2.0 = v # vs; ?a3.0 = s''; ?run s = Some (s', v); reaches_on ?run s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*))[1]) (*discuss goal 2*) apply ((auto simp: adv_start_def (*‹adv_start ?args ?w = (let init = w_init ?args; step = w_step ?args; accept = w_accept ?args; run_t = w_run_t ?args; run_sub = w_run_sub ?args; st = w_st ?w; ac = w_ac ?w; i = w_i ?w; ti = w_ti ?w; si = w_si ?w; j = w_j ?w; s = w_s ?w; e = w_e ?w in case run_t ti of Some (ti', t) ⇒ case run_sub si of Some (si', bs) ⇒ let (s', st') = adv_d step st i bs s; e' = mmap_update (fst (the (mmap_lookup s init))) t e; (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) = while (loop_cond j) (loop_body step accept run_t run_sub) (st', ac, Suc i, ti', si', init, s', None); s'' = mmap_update init (case mmap_lookup s_cur q_cur of None ⇒ (q_cur, tstp_cur) | Some (q', tstp') ⇒ case tstp' of None ⇒ (q', tstp_cur) | Some (ts, tp) ⇒ (q', tstp')) s' in ?w⦇w_st := st_cur, w_ac := ac_cur, w_i := Suc i, w_ti := ti', w_si := si', w_s := s'', w_e := e'⦈)›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) valid_window_def (*‹valid_window ?args ?t0.0 ?sub ?rho ?w = (let init = w_init ?args; step = w_step ?args; accept = w_accept ?args; run_t = w_run_t ?args; run_sub = w_run_sub ?args; st = w_st ?w; ac = w_ac ?w; i = w_i ?w; ti = w_ti ?w; si = w_si ?w; j = w_j ?w; tj = w_tj ?w; sj = w_sj ?w; s = w_s ?w; e = w_e ?w in reach_window ?args ?t0.0 ?sub ?rho (i, ti, si, j, tj, sj) ∧ (∀i j. i ≤ j ∧ j < length ?rho ⟶ ts_at ?rho i ≤ ts_at ?rho j) ∧ (∀q. case Mapping.lookup ac q of None ⇒ True | Some v ⇒ accept q = v) ∧ (∀q. mmap_lookup e q = sup_leadsto init step ?rho i j q) ∧ distinct (map fst e) ∧ valid_s init step st accept ?rho i i j s)›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*) elim: reaches_on.cases (*‹⟦reaches_on ?run ?a1.0 ?a2.0 ?a3.0; ⋀s. ⟦?a1.0 = s; ?a2.0 = []; ?a3.0 = s⟧ ⟹ ?P; ⋀s s' v vs s''. ⟦?a1.0 = s; ?a2.0 = v # vs; ?a3.0 = s''; ?run s = Some (s', v); reaches_on ?run s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*))[1]) (*discuss goal 3*) apply ((auto simp: adv_start_def (*‹adv_start ?args ?w = (let init = w_init ?args; step = w_step ?args; accept = w_accept ?args; run_t = w_run_t ?args; run_sub = w_run_sub ?args; st = w_st ?w; ac = w_ac ?w; i = w_i ?w; ti = w_ti ?w; si = w_si ?w; j = w_j ?w; s = w_s ?w; e = w_e ?w in case run_t ti of Some (ti', t) ⇒ case run_sub si of Some (si', bs) ⇒ let (s', st') = adv_d step st i bs s; e' = mmap_update (fst (the (mmap_lookup s init))) t e; (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) = while (loop_cond j) (loop_body step accept run_t run_sub) (st', ac, Suc i, ti', si', init, s', None); s'' = mmap_update init (case mmap_lookup s_cur q_cur of None ⇒ (q_cur, tstp_cur) | Some (q', tstp') ⇒ case tstp' of None ⇒ (q', tstp_cur) | Some (ts, tp) ⇒ (q', tstp')) s' in ?w⦇w_st := st_cur, w_ac := ac_cur, w_i := Suc i, w_ti := ti', w_si := si', w_s := s'', w_e := e'⦈)›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) valid_window_def (*‹valid_window ?args ?t0.0 ?sub ?rho ?w = (let init = w_init ?args; step = w_step ?args; accept = w_accept ?args; run_t = w_run_t ?args; run_sub = w_run_sub ?args; st = w_st ?w; ac = w_ac ?w; i = w_i ?w; ti = w_ti ?w; si = w_si ?w; j = w_j ?w; tj = w_tj ?w; sj = w_sj ?w; s = w_s ?w; e = w_e ?w in reach_window ?args ?t0.0 ?sub ?rho (i, ti, si, j, tj, sj) ∧ (∀i j. i ≤ j ∧ j < length ?rho ⟶ ts_at ?rho i ≤ ts_at ?rho j) ∧ (∀q. case Mapping.lookup ac q of None ⇒ True | Some v ⇒ accept q = v) ∧ (∀q. mmap_lookup e q = sup_leadsto init step ?rho i j q) ∧ distinct (map fst e) ∧ valid_s init step st accept ?rho i i j s)›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*) elim: reaches_on.cases (*‹⟦reaches_on ?run ?a1.0 ?a2.0 ?a3.0; ⋀s. ⟦?a1.0 = s; ?a2.0 = []; ?a3.0 = s⟧ ⟹ ?P; ⋀s s' v vs s''. ⟦?a1.0 = s; ?a2.0 = v # vs; ?a3.0 = s''; ?run s = Some (s', v); reaches_on ?run s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*))[1]) (*discuss goal 4*) apply ((auto simp: adv_start_def (*‹adv_start ?args ?w = (let init = w_init ?args; step = w_step ?args; accept = w_accept ?args; run_t = w_run_t ?args; run_sub = w_run_sub ?args; st = w_st ?w; ac = w_ac ?w; i = w_i ?w; ti = w_ti ?w; si = w_si ?w; j = w_j ?w; s = w_s ?w; e = w_e ?w in case run_t ti of Some (ti', t) ⇒ case run_sub si of Some (si', bs) ⇒ let (s', st') = adv_d step st i bs s; e' = mmap_update (fst (the (mmap_lookup s init))) t e; (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) = while (loop_cond j) (loop_body step accept run_t run_sub) (st', ac, Suc i, ti', si', init, s', None); s'' = mmap_update init (case mmap_lookup s_cur q_cur of None ⇒ (q_cur, tstp_cur) | Some (q', tstp') ⇒ case tstp' of None ⇒ (q', tstp_cur) | Some (ts, tp) ⇒ (q', tstp')) s' in ?w⦇w_st := st_cur, w_ac := ac_cur, w_i := Suc i, w_ti := ti', w_si := si', w_s := s'', w_e := e'⦈)›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) valid_window_def (*‹valid_window ?args ?t0.0 ?sub ?rho ?w = (let init = w_init ?args; step = w_step ?args; accept = w_accept ?args; run_t = w_run_t ?args; run_sub = w_run_sub ?args; st = w_st ?w; ac = w_ac ?w; i = w_i ?w; ti = w_ti ?w; si = w_si ?w; j = w_j ?w; tj = w_tj ?w; sj = w_sj ?w; s = w_s ?w; e = w_e ?w in reach_window ?args ?t0.0 ?sub ?rho (i, ti, si, j, tj, sj) ∧ (∀i j. i ≤ j ∧ j < length ?rho ⟶ ts_at ?rho i ≤ ts_at ?rho j) ∧ (∀q. case Mapping.lookup ac q of None ⇒ True | Some v ⇒ accept q = v) ∧ (∀q. mmap_lookup e q = sup_leadsto init step ?rho i j q) ∧ distinct (map fst e) ∧ valid_s init step st accept ?rho i i j s)›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*) elim: reaches_on.cases (*‹⟦reaches_on ?run ?a1.0 ?a2.0 ?a3.0; ⋀s. ⟦?a1.0 = s; ?a2.0 = []; ?a3.0 = s⟧ ⟹ ?P; ⋀s s' v vs s''. ⟦?a1.0 = s; ?a2.0 = v # vs; ?a3.0 = s''; ?run s = Some (s', v); reaches_on ?run s' vs s''⟧ ⟹ ?P⟧ ⟹ ?P›*))[1]) (*proven 4 subgoals*) . lemma valid_adv_start_bounds': assumes "valid_window args t0 sub rho w" "w_run_t args (w_ti w) = Some (ti', t)" "w_run_sub args (w_si w) = Some (si', bs)" shows "w_ti (adv_start args w) = ti'" "w_si (adv_start args w) = si'" using assms (*‹valid_window (args::('a, 'b, 'c, 'd, 'e) Window.args) (t0::'d::type) (sub::'e::type) (rho::('c::timestamp × 'a::type) list) (w::('a, 'b, 'c, 'd, 'e) window)› ‹w_run_t args (w_ti w) = Some (ti', t)› ‹w_run_sub (args::('a, 'b, 'c, 'd, 'e) Window.args) (w_si (w::('a, 'b, 'c, 'd, 'e) window)) = Some (si'::'e, bs::'a)›*) apply - (*goals: 1. ‹⟦valid_window args t0 sub rho w; w_run_t args (w_ti w) = Some (ti', t); w_run_sub args (w_si w) = Some (si', bs)⟧ ⟹ w_ti (adv_start args w) = ti'› 2. ‹⟦valid_window args t0 sub rho w; w_run_t args (w_ti w) = Some (ti', t); w_run_sub args (w_si w) = Some (si', bs)⟧ ⟹ w_si (adv_start args w) = si'› discuss goal 1*) apply ((auto simp: adv_start_def (*‹adv_start ?args ?w = (let init = w_init ?args; step = w_step ?args; accept = w_accept ?args; run_t = w_run_t ?args; run_sub = w_run_sub ?args; st = w_st ?w; ac = w_ac ?w; i = w_i ?w; ti = w_ti ?w; si = w_si ?w; j = w_j ?w; s = w_s ?w; e = w_e ?w in case run_t ti of Some (ti', t) ⇒ case run_sub si of Some (si', bs) ⇒ let (s', st') = adv_d step st i bs s; e' = mmap_update (fst (the (mmap_lookup s init))) t e; (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) = while (loop_cond j) (loop_body step accept run_t run_sub) (st', ac, Suc i, ti', si', init, s', None); s'' = mmap_update init (case mmap_lookup s_cur q_cur of None ⇒ (q_cur, tstp_cur) | Some (q', tstp') ⇒ case tstp' of None ⇒ (q', tstp_cur) | Some (ts, tp) ⇒ (q', tstp')) s' in ?w⦇w_st := st_cur, w_ac := ac_cur, w_i := Suc i, w_ti := ti', w_si := si', w_s := s'', w_e := e'⦈)›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) valid_window_def (*‹valid_window ?args ?t0.0 ?sub ?rho ?w = (let init = w_init ?args; step = w_step ?args; accept = w_accept ?args; run_t = w_run_t ?args; run_sub = w_run_sub ?args; st = w_st ?w; ac = w_ac ?w; i = w_i ?w; ti = w_ti ?w; si = w_si ?w; j = w_j ?w; tj = w_tj ?w; sj = w_sj ?w; s = w_s ?w; e = w_e ?w in reach_window ?args ?t0.0 ?sub ?rho (i, ti, si, j, tj, sj) ∧ (∀i j. i ≤ j ∧ j < length ?rho ⟶ ts_at ?rho i ≤ ts_at ?rho j) ∧ (∀q. case Mapping.lookup ac q of None ⇒ True | Some v ⇒ accept q = v) ∧ (∀q. mmap_lookup e q = sup_leadsto init step ?rho i j q) ∧ distinct (map fst e) ∧ valid_s init step st accept ?rho i i j s)›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*))[1]) (*discuss goal 2*) apply ((auto simp: adv_start_def (*‹adv_start ?args ?w = (let init = w_init ?args; step = w_step ?args; accept = w_accept ?args; run_t = w_run_t ?args; run_sub = w_run_sub ?args; st = w_st ?w; ac = w_ac ?w; i = w_i ?w; ti = w_ti ?w; si = w_si ?w; j = w_j ?w; s = w_s ?w; e = w_e ?w in case run_t ti of Some (ti', t) ⇒ case run_sub si of Some (si', bs) ⇒ let (s', st') = adv_d step st i bs s; e' = mmap_update (fst (the (mmap_lookup s init))) t e; (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) = while (loop_cond j) (loop_body step accept run_t run_sub) (st', ac, Suc i, ti', si', init, s', None); s'' = mmap_update init (case mmap_lookup s_cur q_cur of None ⇒ (q_cur, tstp_cur) | Some (q', tstp') ⇒ case tstp' of None ⇒ (q', tstp_cur) | Some (ts, tp) ⇒ (q', tstp')) s' in ?w⦇w_st := st_cur, w_ac := ac_cur, w_i := Suc i, w_ti := ti', w_si := si', w_s := s'', w_e := e'⦈)›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) valid_window_def (*‹valid_window ?args ?t0.0 ?sub ?rho ?w = (let init = w_init ?args; step = w_step ?args; accept = w_accept ?args; run_t = w_run_t ?args; run_sub = w_run_sub ?args; st = w_st ?w; ac = w_ac ?w; i = w_i ?w; ti = w_ti ?w; si = w_si ?w; j = w_j ?w; tj = w_tj ?w; sj = w_sj ?w; s = w_s ?w; e = w_e ?w in reach_window ?args ?t0.0 ?sub ?rho (i, ti, si, j, tj, sj) ∧ (∀i j. i ≤ j ∧ j < length ?rho ⟶ ts_at ?rho i ≤ ts_at ?rho j) ∧ (∀q. case Mapping.lookup ac q of None ⇒ True | Some v ⇒ accept q = v) ∧ (∀q. mmap_lookup e q = sup_leadsto init step ?rho i j q) ∧ distinct (map fst e) ∧ valid_s init step st accept ?rho i i j s)›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*))[1]) (*proven 2 subgoals*) . end
{ "path": "afp-2025-02-12/thys/VYDRA_MDL/Window.thy", "repo": "afp-2025-02-12", "sha": "db44879f4a6f0536619e9a10b8cee279d0ffd4d45781576d8e774e16777e55af" }
theory Padic_Field_Polynomials imports Padic_Fields begin (**************************************************************************************************) (**************************************************************************************************) section‹$p$-adic Univariate Polynomials and Hensel's Lemma› (**************************************************************************************************) (**************************************************************************************************) type_synonym padic_field_poly = "nat ⇒ padic_number" type_synonym padic_field_fun = "padic_number ⇒ padic_number" (**************************************************************************************************) (**************************************************************************************************) subsection‹Gauss Norms of Polynomials› (**************************************************************************************************) (**************************************************************************************************) text ‹ The Gauss norm of a polynomial is defined to be the minimum valuation of a coefficient of that polynomial. This induces a valuation on the ring of polynomials, and in particular it satisfies the ultrametric inequality. In addition, the Gauss norm of a polynomial $f(x)$ gives a lower bound for the value $\text{val } (f(a))$ in terms of $\text{val }(a)$, for a point $a \in \mathbb{Q}_p$. We introduce Gauss norms here as a useful tool for stating and proving Hensel's Lemma for the field $\mathbb{Q}_p$. We are abusing terminology slightly in calling this the Gauss norm, rather than the Gauss valuation, but this is just to conform with our decision to work exclusively with the $p$-adic valuation and not discuss the equivalent real-valued $p$-adic norm. For a detailed treatment of Gauss norms one can see, for example \<^cite>‹"engler2005valued"›. › context padic_fields begin no_notation Zp.to_fun (infixl‹∙› 70) abbreviation(input) Q⇩p_x where "Q⇩p_x ≡ UP Q⇩p" definition gauss_norm where "gauss_norm g = Min (val ` g ` {..degree g}) " lemma gauss_normE: assumes "g ∈ carrier Q⇩p_x" shows "gauss_norm g ≤ val (g k)" apply (cases "k ≤ degree g") (*goal: ‹gauss_norm g ≤ val (g k)›*) unfolding gauss_norm_def (*goals: 1. ‹k ≤ deg Q⇩p g ⟹ Min (val ` g ` {..deg Q⇩p g}) ≤ val (g k)› 2. ‹¬ k ≤ deg Q⇩p g ⟹ Min (val ` g ` {..deg Q⇩p g}) ≤ val (g k)›*) using assms (*‹g ∈ carrier (UP Q⇩p)›*) proof ((auto)[1]) (*goal: ‹¬ k ≤ deg Q⇩p g ⟹ Min (val ` g ` {..deg Q⇩p g}) ≤ val (g k)›*) assume "¬ k ≤ degree g" (*‹¬ (k::nat) ≤ deg Q⇩p (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)›*) then have "g k = 𝟬⇘Q⇩p⇙ " by (simp add: UPQ.deg_leE (*‹⟦?p ∈ carrier (UP Q⇩p); deg Q⇩p ?p < ?k⟧ ⟹ ?p ?k = 𝟬›*) assms (*‹g ∈ carrier (UP Q⇩p)›*)) then show "Min (val ` g ` {..deg Q⇩p g}) ≤ val (g k)" by (simp add: local.val_zero (*‹val 𝟬 = ∞›*)) qed lemma gauss_norm_geqI: assumes "g ∈ carrier (UP Q⇩p)" assumes "⋀n. val (g n) ≥ α" shows "gauss_norm g ≥ α" unfolding gauss_norm_def (*goal: ‹α ≤ Min (val ` g ` {..deg Q⇩p g})›*) using assms (*‹g ∈ carrier (UP Q⇩p)› ‹(α::eint) ≤ val ((g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (?n1::nat))›*) by simp lemma gauss_norm_eqI: assumes "g ∈ carrier (UP Q⇩p)" assumes "⋀n. val (g n) ≥ α" assumes "val (g i) = α" shows "gauss_norm g = α" proof (-) (*goal: ‹gauss_norm g = α›*) have 0: "gauss_norm g ≤ α" using assms (*‹g ∈ carrier (UP Q⇩p)› ‹α ≤ val (g ?n1)› ‹val (g i) = α›*) gauss_normE (*‹?g ∈ carrier (UP Q⇩p) ⟹ gauss_norm ?g ≤ val (?g ?k)›*) gauss_norm_def (*‹gauss_norm ?g = Min (val ` ?g ` {..deg Q⇩p ?g})›*) by fastforce have 1: "gauss_norm g ≥ α" using assms (*‹g ∈ carrier (UP Q⇩p)› ‹(α::eint) ≤ val ((g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (?n1::nat))› ‹val (g i) = α›*) gauss_norm_geqI (*‹⟦?g ∈ carrier (UP Q⇩p); ⋀n. ?α ≤ val (?g n)⟧ ⟹ ?α ≤ gauss_norm ?g›*) by auto show "?thesis" (*goal: ‹gauss_norm (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) = (α::eint)›*) using "0" (*‹gauss_norm (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ≤ (α::eint)›*) "1" (*‹(α::eint) ≤ gauss_norm (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)›*) by auto qed lemma nonzero_poly_nonzero_coeff: assumes "g ∈ carrier Q⇩p_x" assumes "g ≠ 𝟬⇘Q⇩p_x⇙" shows "∃k. k ≤degree g ∧ g k ≠𝟬⇘Q⇩p⇙" proof (rule ccontr (*‹(¬ (?P::bool) ⟹ False) ⟹ ?P›*)) (*goal: ‹¬ (∃k≤deg Q⇩p g. g k ≠ 𝟬) ⟹ False›*) assume "¬ (∃k≤degree g. g k ≠ 𝟬⇘Q⇩p⇙)" (*‹¬ (∃k≤deg Q⇩p (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set). g k ≠ 𝟬)›*) then have 0: "⋀k. g k = 𝟬⇘Q⇩p⇙" by (meson UPQ.deg_leE (*‹⟦?p ∈ carrier (UP Q⇩p); deg Q⇩p ?p < ?k⟧ ⟹ ?p ?k = 𝟬›*) assms( (*‹g ∈ carrier (UP Q⇩p)›*) 1) not_le_imp_less (*‹¬ ?y ≤ ?x ⟹ ?x < ?y›*)) then show False using assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ≠ 𝟬⇘UP Q⇩p⇙›*) UPQ.cfs_zero (*‹𝟬⇘UP Q⇩p⇙ ?n = 𝟬›*) by blast qed lemma gauss_norm_prop: assumes "g ∈ carrier Q⇩p_x" assumes "g ≠ 𝟬⇘Q⇩p_x⇙" shows "gauss_norm g ≠ ∞" proof (-) (*goal: ‹gauss_norm g ≠ ∞›*) obtain k where k_def: "k ≤degree g ∧ g k ≠𝟬⇘Q⇩p⇙" (*goal: ‹(⋀k. k ≤ deg Q⇩p g ∧ g k ≠ 𝟬 ⟹ thesis) ⟹ thesis›*) using assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ≠ 𝟬⇘UP Q⇩p⇙›*) nonzero_poly_nonzero_coeff (*‹⟦?g ∈ carrier (UP Q⇩p); ?g ≠ 𝟬⇘UP Q⇩p⇙⟧ ⟹ ∃k≤deg Q⇩p ?g. ?g k ≠ 𝟬›*) by blast then have 0: "gauss_norm g ≤ val (g k)" using assms(1) (*‹g ∈ carrier (UP Q⇩p)›*) gauss_normE (*‹?g ∈ carrier (UP Q⇩p) ⟹ gauss_norm ?g ≤ val (?g ?k)›*) by blast have "g k ∈ carrier Q⇩p" using UPQ.cfs_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ ?f ?n ∈ carrier Q⇩p›*) assms(1) (*‹g ∈ carrier (UP Q⇩p)›*) by blast hence "val (g k) < ∞" using k_def (*‹k ≤ deg Q⇩p g ∧ g k ≠ 𝟬›*) assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ≠ 𝟬⇘UP Q⇩p⇙›*) by (metis eint_ord_code( (*‹((?q::eint) ≤ ∞) = True›*) 3) eint_ord_simps( (*‹((?q::eint) < ∞) = (?q ≠ ∞)›*) 4) val_ineq (*‹⟦(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p; val 𝟬 ≤ val ?a⟧ ⟹ ?a = 𝟬›*)) then show "?thesis" (*goal: ‹gauss_norm g ≠ ∞›*) using "0" (*‹gauss_norm g ≤ val (g k)›*) not_le (*‹(¬ ?x ≤ ?y) = (?y < ?x)›*) by fastforce qed lemma gauss_norm_coeff_norm: "∃n ≤ degree g. (gauss_norm g) = val (g n)" proof (-) (*goal: ‹∃n≤deg Q⇩p g. gauss_norm g = val (g n)›*) have "finite (val ` g ` {..deg Q⇩p g})" by blast hence "∃x ∈ (val ` g ` {..deg Q⇩p g}). gauss_norm g = x" unfolding gauss_norm_def (*goal: ‹∃x∈val ` g ` {..deg Q⇩p g}. Min (val ` g ` {..deg Q⇩p g}) = x›*) by auto thus "?thesis" (*goal: ‹∃n≤deg Q⇩p (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set). gauss_norm g = val (g n)›*) unfolding gauss_norm_def (*goal: ‹∃n≤deg Q⇩p g. Min (val ` g ` {..deg Q⇩p g}) = val (g n)›*) by blast qed lemma gauss_norm_smult_cfs: assumes "g ∈ carrier Q⇩p_x" assumes "a ∈ carrier Q⇩p" assumes "gauss_norm g = val (g k)" shows "gauss_norm (a ⊙⇘Q⇩p_x⇙ g) = val a + val (g k)" proof (-) (*goal: ‹gauss_norm (a ⊙⇘UP Q⇩p⇙ g) = val a + val (g k)›*) obtain l where l_def: "gauss_norm (a ⊙⇘Q⇩p_x⇙ g) = val ((a ⊙⇘Q⇩p_x⇙ g) l)" (*goal: ‹(⋀l. gauss_norm (a ⊙⇘UP Q⇩p⇙ g) = val ((a ⊙⇘UP Q⇩p⇙ g) l) ⟹ thesis) ⟹ thesis›*) using gauss_norm_coeff_norm (*‹∃n≤deg Q⇩p ?g. gauss_norm ?g = val (?g n)›*) by blast then have "gauss_norm (a ⊙⇘Q⇩p_x⇙ g) = val (a ⊗⇘Q⇩p⇙ (g l))" using assms (*‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹a ∈ carrier Q⇩p› ‹gauss_norm g = val (g k)›*) by simp then have "gauss_norm (a ⊙⇘Q⇩p_x⇙ g) = val a + val (g l)" by (simp add: UPQ.cfs_closed (*‹(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p) ⟹ ?f (?n::nat) ∈ carrier Q⇩p›*) assms( (*‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)›*) 1) assms( (*‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p›*) 2) val_mult (*‹⟦(?x::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p; (?y::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p⟧ ⟹ val (?x ⊗ ?y) = val ?x + val ?y›*)) then have 0: "gauss_norm (a ⊙⇘Q⇩p_x⇙ g) ≤ val a +val (g k)" using assms (*‹g ∈ carrier (UP Q⇩p)› ‹a ∈ carrier Q⇩p› ‹gauss_norm g = val (g k)›*) gauss_normE[of g l] (*‹g ∈ carrier (UP Q⇩p) ⟹ gauss_norm g ≤ val (g l)›*) by (metis UPQ.UP_smult_closed (*‹⟦?a ∈ carrier Q⇩p; ?p ∈ carrier (UP Q⇩p)⟧ ⟹ ?a ⊙⇘UP Q⇩p⇙ ?p ∈ carrier (UP Q⇩p)›*) UPQ.cfs_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ ?f ?n ∈ carrier Q⇩p›*) UPQ.cfs_smult (*‹⟦?a ∈ carrier Q⇩p; ?p ∈ carrier (UP Q⇩p)⟧ ⟹ (?a ⊙⇘UP Q⇩p⇙ ?p) ?n = ?a ⊗ ?p ?n›*) gauss_normE (*‹?g ∈ carrier (UP Q⇩p) ⟹ gauss_norm ?g ≤ val (?g ?k)›*) val_mult (*‹⟦?x ∈ carrier Q⇩p; ?y ∈ carrier Q⇩p⟧ ⟹ val (?x ⊗ ?y) = val ?x + val ?y›*)) have "val a + val (g k) = val ((a ⊙⇘Q⇩p_x⇙ g) k)" by (simp add: UPQ.cfs_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ ?f ?n ∈ carrier Q⇩p›*) assms( (*‹g ∈ carrier (UP Q⇩p)›*) 1) assms( (*‹a ∈ carrier Q⇩p›*) 2) val_mult (*‹⟦?x ∈ carrier Q⇩p; ?y ∈ carrier Q⇩p⟧ ⟹ val (?x ⊗ ?y) = val ?x + val ?y›*)) then have "gauss_norm (a ⊙⇘Q⇩p_x⇙ g) ≥ val a + val (g k)" by (metis ‹gauss_norm (a ⊙⇘UP Q⇩p⇙ g) = val a + val (g l)› add_left_mono (*‹?a ≤ ?b ⟹ ?c + ?a ≤ ?c + ?b›*) assms( (*‹g ∈ carrier (UP Q⇩p)›*) 1) assms( (*‹gauss_norm g = val (g k)›*) 3) gauss_normE (*‹?g ∈ carrier (UP Q⇩p) ⟹ gauss_norm ?g ≤ val (?g ?k)›*)) then show "?thesis" (*goal: ‹gauss_norm (a ⊙⇘UP Q⇩p⇙ g) = val a + val (g k)›*) using "0" (*‹gauss_norm (a ⊙⇘UP Q⇩p⇙ g) ≤ val a + val (g k)›*) by auto qed lemma gauss_norm_smult: assumes "g ∈ carrier Q⇩p_x" assumes "a ∈ carrier Q⇩p" shows "gauss_norm (a ⊙⇘Q⇩p_x⇙ g) = val a + gauss_norm g" using gauss_norm_smult_cfs[of g a] (*‹⟦g ∈ carrier (UP Q⇩p); a ∈ carrier Q⇩p; gauss_norm g = val (g ?k)⟧ ⟹ gauss_norm (a ⊙⇘UP Q⇩p⇙ g) = val a + val (g ?k)›*) gauss_norm_coeff_norm[of g] (*‹∃n≤deg Q⇩p g. gauss_norm g = val (g n)›*) assms (*‹g ∈ carrier (UP Q⇩p)› ‹a ∈ carrier Q⇩p›*) by metis lemma gauss_norm_ultrametric: assumes "g ∈ carrier Q⇩p_x" assumes "h ∈ carrier Q⇩p_x" shows "gauss_norm (g ⊕⇘Q⇩p_x⇙ h) ≥ min (gauss_norm g) (gauss_norm h)" proof (-) (*goal: ‹min (gauss_norm g) (gauss_norm h) ≤ gauss_norm (g ⊕⇘UP Q⇩p⇙ h)›*) obtain k where "gauss_norm (g ⊕⇘Q⇩p_x⇙ h) = val ((g ⊕⇘Q⇩p_x⇙ h) k)" (*goal: ‹(⋀k. gauss_norm (g ⊕⇘UP Q⇩p⇙ h) = val ((g ⊕⇘UP Q⇩p⇙ h) k) ⟹ thesis) ⟹ thesis›*) using gauss_norm_coeff_norm (*‹∃n≤deg Q⇩p (?g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set). gauss_norm ?g = val (?g n)›*) by blast then have 0: "gauss_norm (g ⊕⇘Q⇩p_x⇙ h) = val (g k ⊕⇘Q⇩p⇙ h k)" by (simp add: assms( (*‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)›*) 1) assms( (*‹(h::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)›*) 2)) have "min (val (g k)) (val (h k))≥ min (gauss_norm g) (gauss_norm h)" using gauss_normE[of g k] (*‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p) ⟹ gauss_norm g ≤ val (g (k::nat))›*) gauss_normE[of h k] (*‹h ∈ carrier (UP Q⇩p) ⟹ gauss_norm h ≤ val (h k)›*) assms(1) (*‹g ∈ carrier (UP Q⇩p)›*) assms(2) (*‹h ∈ carrier (UP Q⇩p)›*) min.mono (*‹⟦(?a::?'a::linorder) ≤ (?c::?'a::linorder); (?b::?'a::linorder) ≤ (?d::?'a::linorder)⟧ ⟹ min ?a ?b ≤ min ?c ?d›*) by blast then show "?thesis" (*goal: ‹min (gauss_norm (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)) (gauss_norm (h::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)) ≤ gauss_norm (g ⊕⇘UP Q⇩p⇙ h)›*) using "0" (*‹gauss_norm (g ⊕⇘UP Q⇩p⇙ h) = val (g k ⊕ h k)›*) val_ultrametric[of "g k" "h k"] (*‹⟦(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (k::nat) ∈ carrier Q⇩p; (h::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) k ∈ carrier Q⇩p⟧ ⟹ min (val (g k)) (val (h k)) ≤ val (g k ⊕ h k)›*) assms(1) (*‹g ∈ carrier (UP Q⇩p)›*) assms(2) (*‹h ∈ carrier (UP Q⇩p)›*) dual_order.trans (*‹⟦?b ≤ ?a; ?c ≤ ?b⟧ ⟹ ?c ≤ ?a›*) by (metis (no_types, lifting) UPQ.cfs_closed (*‹(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p) ⟹ ?f (?n::nat) ∈ carrier Q⇩p›*)) qed lemma gauss_norm_a_inv: assumes "f ∈ carrier (UP Q⇩p)" shows "gauss_norm (⊖⇘UP Q⇩p⇙f) = gauss_norm f" proof (-) (*goal: ‹gauss_norm (⊖⇘UP Q⇩p⇙ (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)) = gauss_norm f›*) have 0: "⋀n. ((⊖⇘UP Q⇩p⇙f) n) = ⊖ (f n)" using assms (*‹f ∈ carrier (UP Q⇩p)›*) by simp have 1: "⋀n. val ((⊖⇘UP Q⇩p⇙f) n) = val (f n)" using "0" (*‹(⊖⇘UP Q⇩p⇙ f) ?n1 = ⊖ f ?n1›*) assms (*‹f ∈ carrier (UP Q⇩p)›*) UPQ.UP_car_memE(1) (*‹?g ∈ carrier (UP Q⇩p) ⟹ ?g ?x ∈ carrier Q⇩p›*) val_minus (*‹?a ∈ carrier Q⇩p ⟹ val ?a = val (⊖ ?a)›*) by presburger obtain i where i_def: "gauss_norm f = val (f i)" (*goal: ‹(⋀i. gauss_norm f = val (f i) ⟹ thesis) ⟹ thesis›*) using assms (*‹(f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)›*) gauss_norm_coeff_norm (*‹∃n≤deg Q⇩p ?g. gauss_norm ?g = val (?g n)›*) by blast have 2: "⋀k. val ((⊖⇘UP Q⇩p⇙f) k) ≥ val (f i)" unfolding "1" (*goal: ‹⋀k. val (f i) ≤ val (f k)›*) using i_def (*‹gauss_norm f = val (f i)›*) assms (*‹f ∈ carrier (UP Q⇩p)›*) gauss_normE (*‹(?g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p) ⟹ gauss_norm ?g ≤ val (?g (?k::nat))›*) by fastforce show "?thesis" (*goal: ‹gauss_norm (⊖⇘UP Q⇩p⇙ f) = gauss_norm f›*) apply (rule gauss_norm_eqI[of _ _ i] (*‹⟦?g ∈ carrier (UP Q⇩p); ⋀n. ?α ≤ val (?g n); val (?g i) = ?α⟧ ⟹ gauss_norm ?g = ?α›*)) (*goal: ‹gauss_norm (⊖⇘UP Q⇩p⇙ f) = gauss_norm f›*) apply (simp add: assms (*‹f ∈ carrier (UP Q⇩p)›*); fail) (*top goal: ‹⊖⇘UP Q⇩p⇙ f ∈ carrier (UP Q⇩p)› and 2 goals remain*) unfolding "1" (*goals: 1. ‹⋀n::nat. gauss_norm (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ≤ val (f n)› 2. ‹val ((f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (i::nat)) = gauss_norm f›*) using assms (*‹f ∈ carrier (UP Q⇩p)›*) gauss_normE (*‹?g ∈ carrier (UP Q⇩p) ⟹ gauss_norm ?g ≤ val (?g ?k)›*) apply blast (*top goal: ‹⋀n::nat. gauss_norm (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ≤ val (f n)› and 1 goal remains*) unfolding i_def (*goal: ‹val (f i) = val (f i)›*) by blast qed lemma gauss_norm_ultrametric': assumes "f ∈ carrier (UP Q⇩p)" assumes "g ∈ carrier (UP Q⇩p)" shows "gauss_norm (f ⊖⇘UP Q⇩p⇙ g) ≥ min (gauss_norm f) (gauss_norm g)" unfolding a_minus_def (*goal: ‹min (gauss_norm f) (gauss_norm g) ≤ gauss_norm (f ⊕⇘UP Q⇩p⇙ ⊖⇘UP Q⇩p⇙ g)›*) using assms (*‹(f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹g ∈ carrier (UP Q⇩p)›*) gauss_norm_a_inv[of g] (*‹g ∈ carrier (UP Q⇩p) ⟹ gauss_norm (⊖⇘UP Q⇩p⇙ g) = gauss_norm g›*) gauss_norm_ultrametric (*‹⟦?g ∈ carrier (UP Q⇩p); ?h ∈ carrier (UP Q⇩p)⟧ ⟹ min (gauss_norm ?g) (gauss_norm ?h) ≤ gauss_norm (?g ⊕⇘UP Q⇩p⇙ ?h)›*) by (metis UPQ.UP_a_inv_closed (*‹?p ∈ carrier (UP Q⇩p) ⟹ ⊖⇘UP Q⇩p⇙ ?p ∈ carrier (UP Q⇩p)›*)) lemma gauss_norm_finsum: assumes "f ∈ A → carrier Q⇩p_x" assumes "finite A" assumes "A ≠ {}" shows " gauss_norm (⨁⇘Q⇩p_x⇙i∈A. f i) ≥ Min (gauss_norm ` (f`A))" proof (-) (*goal: ‹Min (gauss_norm ` f ` A) ≤ gauss_norm (finsum (UP Q⇩p) f A)›*) obtain k where k_def: "val ((⨁⇘Q⇩p_x⇙i∈A. f i) k) = gauss_norm (⨁⇘Q⇩p_x⇙i∈A. f i)" (*goal: ‹(⋀k. val (finsum (UP Q⇩p) f A k) = gauss_norm (finsum (UP Q⇩p) f A) ⟹ thesis) ⟹ thesis›*) by (metis gauss_norm_coeff_norm (*‹∃n≤deg Q⇩p ?g. gauss_norm ?g = val (?g n)›*)) then have 0: "val (⨁⇘Q⇩p⇙i∈A. f i k) ≥ Min (val ` (λ i. f i k) ` A)" using finsum_val_ultrametric[of "λ i. f i k" A] (*‹⟦(λi::'a. (f::'a ⇒ nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) i (k::nat)) ∈ (A::'a set) → carrier Q⇩p; finite A; A ≠ {}⟧ ⟹ Min (val ` (λi::'a. f i k) ` A) ≤ val (⨁i::'a∈A. f i k)›*) assms (*‹f ∈ A → carrier (UP Q⇩p)› ‹finite A› ‹A ≠ {}›*) by (simp add: ‹⟦(λi. f i k) ∈ A → carrier Q⇩p; finite A; A ≠ {}⟧ ⟹ Min (val ` (λi. f i k) ` A) ≤ val (⨁i∈A. f i k)› Pi_iff (*‹(?f ∈ Pi ?I ?X) = (∀i∈?I. ?f i ∈ ?X i)›*) UPQ.cfs_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ ?f ?n ∈ carrier Q⇩p›*)) have "(⋀a. a ∈ A ⟹ (val ∘ (λi. f i k)) a ≥ gauss_norm (f a))" using gauss_normE (*‹?g ∈ carrier (UP Q⇩p) ⟹ gauss_norm ?g ≤ val (?g ?k)›*) assms (*‹f ∈ A → carrier (UP Q⇩p)› ‹finite A› ‹A ≠ {}›*) by (metis (no_types, lifting) Pi_split_insert_domain (*‹((?x::?'a ⇒ ?'b) ∈ Pi (insert (?i::?'a) (?I::?'a set)) (?X::?'a ⇒ ?'b set)) = (?x ∈ Pi ?I ?X ∧ ?x ?i ∈ ?X ?i)›*) Set.set_insert (*‹⟦(?x::?'a) ∈ (?A::?'a set); ⋀B::?'a set. ⟦?A = insert ?x B; ?x ∉ B⟧ ⟹ ?thesis::bool⟧ ⟹ ?thesis›*) comp_apply (*‹((?f::?'b ⇒ ?'a) ∘ (?g::?'c ⇒ ?'b)) (?x::?'c) = ?f (?g ?x)›*)) then have "Min (val ` (λ i. f i k) ` A) ≥ Min ((λ i. gauss_norm (f i)) ` A)" using Min_mono'[of A] (*‹⟦finite A; ⋀a. a ∈ A ⟹ ?f a ≤ ?g a⟧ ⟹ Min (?f ` A) ≤ Min (?g ` A)›*) by (simp add: assms( (*‹finite A›*) 2) image_comp (*‹?f ` ?g ` ?r = (?f ∘ ?g) ` ?r›*)) then have 1: "Min (val ` (λ i. f i k) ` A) ≥ Min (gauss_norm ` f ` A)" by (metis image_image (*‹?f ` ?g ` ?A = (λx. ?f (?g x)) ` ?A›*)) have "f ∈ A → carrier (UP Q⇩p) ⟶ ((⨁⇘Q⇩p_x⇙i∈A. f i) ∈ carrier Q⇩p_x ∧ ((⨁⇘Q⇩p_x⇙i∈A. f i) k) = (⨁⇘Q⇩p⇙i∈A. f i k)) " apply (rule finite.induct[of A] (*‹⟦finite (A::'a::type set); (?P::'a::type set ⇒ bool) {}; ⋀(A::'a::type set) a::'a::type. ⟦finite A; ?P A⟧ ⟹ ?P (insert a A)⟧ ⟹ ?P A›*)) (*goal: ‹f ∈ A → carrier (UP Q⇩p) ⟶ finsum (UP Q⇩p) f A ∈ carrier (UP Q⇩p) ∧ finsum (UP Q⇩p) f A k = (⨁i∈A. f i k)›*) apply (simp add: assms( (*‹finite A›*) 2); fail) (*top goal: ‹finite A› and 2 goals remain*) proof (metis (no_types, lifting) Pi_I (*‹(⋀x::?'a::type. x ∈ (?A::?'a::type set) ⟹ (?f::?'a::type ⇒ ?'b::type) x ∈ (?B::?'a::type ⇒ ?'b::type set) x) ⟹ ?f ∈ Pi ?A ?B›*) Qp.add.finprod_one_eqI (*‹(⋀x::?'c::type. x ∈ (?A::?'c::type set) ⟹ (?f::?'c::type ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) x = 𝟬) ⟹ finsum Q⇩p ?f ?A = 𝟬›*) UPQ.P.finsum_closed (*‹(?f::?'c::type ⇒ nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ (?A::?'c::type set) → carrier (UP Q⇩p) ⟹ finsum (UP Q⇩p) ?f ?A ∈ carrier (UP Q⇩p)›*) UPQ.P.finsum_empty (*‹finsum (UP Q⇩p) (?f::?'c::type ⇒ nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) {} = 𝟬⇘UP Q⇩p⇙›*) UPQ.cfs_zero (*‹𝟬⇘UP Q⇩p⇙ (?n::nat) = 𝟬›*) empty_iff (*‹((?c::?'a::type) ∈ {}) = False›*)) (*goal: ‹⋀A a. ⟦finite A; f ∈ A → carrier (UP Q⇩p) ⟶ finsum (UP Q⇩p) f A ∈ carrier (UP Q⇩p) ∧ finsum (UP Q⇩p) f A k = (⨁i∈A. f i k)⟧ ⟹ f ∈ insert a A → carrier (UP Q⇩p) ⟶ finsum (UP Q⇩p) f (insert a A) ∈ carrier (UP Q⇩p) ∧ finsum (UP Q⇩p) f (insert a A) k = (⨁i∈insert a A. f i k)›*) fix a and A assume A: "finite A" "f ∈ A → carrier (UP Q⇩p) ⟶ ( finsum (UP Q⇩p) f A ∈ carrier (UP Q⇩p) ∧ finsum (UP Q⇩p) f A k = (⨁i∈A. f i k)) " (*‹finite (A::'a set)› ‹(f::'a ⇒ nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ (A::'a set) → carrier (UP Q⇩p) ⟶ finsum (UP Q⇩p) f A ∈ carrier (UP Q⇩p) ∧ finsum (UP Q⇩p) f A (k::nat) = (⨁i::'a∈A. f i k)›*) show " f ∈ insert a A → carrier (UP Q⇩p) ⟶ finsum (UP Q⇩p) f (insert a A) ∈ carrier (UP Q⇩p) ∧ finsum (UP Q⇩p) f (insert a A) k = (⨁i∈insert a A. f i k)" apply (cases "a ∈ A") (*goal: ‹f ∈ insert a A → carrier (UP Q⇩p) ⟶ finsum (UP Q⇩p) f (insert a A) ∈ carrier (UP Q⇩p) ∧ finsum (UP Q⇩p) f (insert a A) k = (⨁i∈insert a A. f i k)›*) using A (*‹finite (A::'a set)› ‹(f::'a::type ⇒ nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ (A::'a::type set) → carrier (UP Q⇩p) ⟶ finsum (UP Q⇩p) f A ∈ carrier (UP Q⇩p) ∧ finsum (UP Q⇩p) f A (k::nat) = (⨁i::'a::type∈A. f i k)›*) apply (simp add: insert_absorb (*‹?a ∈ ?A ⟹ insert ?a ?A = ?A›*); fail) (*top goal: ‹a ∈ A ⟹ f ∈ insert a A → carrier (UP Q⇩p) ⟶ finsum (UP Q⇩p) f (insert a A) ∈ carrier (UP Q⇩p) ∧ finsum (UP Q⇩p) f (insert a A) k = (⨁i∈insert a A. f i k)› and 1 goal remains*) proof (standard) (*goal: ‹⟦a ∉ A; f ∈ insert a A → carrier (UP Q⇩p)⟧ ⟹ finsum (UP Q⇩p) f (insert a A) ∈ carrier (UP Q⇩p) ∧ finsum (UP Q⇩p) f (insert a A) k = (⨁i∈insert a A. f i k)›*) assume B: "a ∉ A" " f ∈ insert a A → carrier (UP Q⇩p)" (*‹(a::'a) ∉ (A::'a set)› ‹(f::'a ⇒ nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ insert (a::'a) (A::'a set) → carrier (UP Q⇩p)›*) then have f_a: "f a ∈ carrier (UP Q⇩p)" by blast have f_A: "f ∈ A → carrier (UP Q⇩p)" using B (*‹(a::'a::type) ∉ (A::'a::type set)› ‹f ∈ insert a A → carrier (UP Q⇩p)›*) by blast have "finsum (UP Q⇩p) f (insert a A) = f a ⊕⇘UP Q⇩p⇙finsum (UP Q⇩p) f A" using assms (*‹(f::'a ⇒ nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ (A::'a set) → carrier (UP Q⇩p)› ‹finite A› ‹A ≠ {}›*) A (*‹finite A› ‹f ∈ A → carrier (UP Q⇩p) ⟶ finsum (UP Q⇩p) f A ∈ carrier (UP Q⇩p) ∧ finsum (UP Q⇩p) f A k = (⨁i∈A. f i k)›*) B (*‹(a::'a) ∉ (A::'a set)› ‹f ∈ insert a A → carrier (UP Q⇩p)›*) f_a (*‹f a ∈ carrier (UP Q⇩p)›*) f_A (*‹f ∈ A → carrier (UP Q⇩p)›*) finsum_insert (*‹⟦finite ?F; ?a ∉ ?F; ?f ∈ ?F → carrier (UP Q⇩p); ?f ?a ∈ carrier (UP Q⇩p)⟧ ⟹ finsum (UP Q⇩p) ?f (insert ?a ?F) = ?f ?a ⊕⇘UP Q⇩p⇙ finsum (UP Q⇩p) ?f ?F›*) by simp then have 0: "finsum (UP Q⇩p) f (insert a A) k = f a k ⊕⇘Q⇩p⇙ (finsum (UP Q⇩p) f A) k" using f_a (*‹f a ∈ carrier (UP Q⇩p)›*) f_A (*‹f ∈ A → carrier (UP Q⇩p)›*) A (*‹finite (A::'a set)› ‹f ∈ A → carrier (UP Q⇩p) ⟶ finsum (UP Q⇩p) f A ∈ carrier (UP Q⇩p) ∧ finsum (UP Q⇩p) f A k = (⨁i∈A. f i k)›*) B (*‹(a::'a) ∉ (A::'a set)› ‹f ∈ insert a A → carrier (UP Q⇩p)›*) by simp have " ( λ a. f a k) ∈ A → carrier Q⇩p" proof (standard) (*goal: ‹⋀x. x ∈ A ⟹ f x k ∈ carrier Q⇩p›*) fix a assume "a ∈ A" (*‹(a::'a) ∈ (A::'a set)›*) then have "f a ∈ carrier (UP Q⇩p)" using f_A (*‹f ∈ A → carrier (UP Q⇩p)›*) by blast then show "f a k ∈ carrier Q⇩p" using A (*‹finite A› ‹f ∈ A → carrier (UP Q⇩p) ⟶ finsum (UP Q⇩p) f A ∈ carrier (UP Q⇩p) ∧ finsum (UP Q⇩p) f A k = (⨁i∈A. f i k)›*) cfs_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ ?f ?n ∈ carrier Q⇩p›*) by blast qed then have 0: "finsum (UP Q⇩p) f (insert a A) k = (⨁i∈insert a A. f i k)" using A (*‹finite A› ‹f ∈ A → carrier (UP Q⇩p) ⟶ finsum (UP Q⇩p) f A ∈ carrier (UP Q⇩p) ∧ finsum (UP Q⇩p) f A k = (⨁i∈A. f i k)›*) B (*‹a ∉ A› ‹f ∈ insert a A → carrier (UP Q⇩p)›*) Qp.finsum_insert[of A a "λ a. f a k"] (*‹⟦finite A; a ∉ A; (λa. f a k) ∈ A → carrier Q⇩p; f a k ∈ carrier Q⇩p⟧ ⟹ (⨁a∈insert a A. f a k) = f a k ⊕ (⨁a∈A. f a k)›*) by (simp add: UPQ.cfs_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ ?f ?n ∈ carrier Q⇩p›*)) thus " finsum (UP Q⇩p) f (insert a A) ∈ carrier (UP Q⇩p) ∧ finsum (UP Q⇩p) f (insert a A) k = (⨁i∈insert a A. f i k)" using B(2) (*‹f ∈ insert a A → carrier (UP Q⇩p)›*) UPQ.P.finsum_closed (*‹(?f::?'c ⇒ nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ (?A::?'c set) → carrier (UP Q⇩p) ⟹ finsum (UP Q⇩p) ?f ?A ∈ carrier (UP Q⇩p)›*) by blast qed qed then have "(⨁⇘Q⇩p_x⇙i∈A. f i) ∈ carrier Q⇩p_x ∧ ((⨁⇘Q⇩p_x⇙i∈A. f i) k) = (⨁⇘Q⇩p⇙i∈A. f i k)" using assms (*‹f ∈ A → carrier (UP Q⇩p)› ‹finite A› ‹A ≠ {}›*) by blast hence 3: "gauss_norm (⨁⇘Q⇩p_x⇙i∈A. f i) ≥ Min (val ` (λ i. f i k) ` A)" using "0" (*‹Min (val ` (λi. f i k) ` A) ≤ val (⨁i∈A. f i k)›*) k_def (*‹val (finsum (UP Q⇩p) (f::'a ⇒ nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (A::'a set) (k::nat)) = gauss_norm (finsum (UP Q⇩p) f A)›*) by auto thus "?thesis" (*goal: ‹Min (gauss_norm ` f ` A) ≤ gauss_norm (finsum (UP Q⇩p) f A)›*) using "1" (*‹Min (gauss_norm ` f ` A) ≤ Min (val ` (λi. f i k) ` A)›*) le_trans (*‹⟦?i ≤ ?j; ?j ≤ ?k⟧ ⟹ ?i ≤ ?k›*) by auto qed lemma gauss_norm_monom: assumes "a ∈ carrier Q⇩p" shows "gauss_norm (monom Q⇩p_x a n) = val a" proof (-) (*goal: ‹gauss_norm (monom (UP Q⇩p) a n) = val a›*) have "val ((monom Q⇩p_x a n) n) ≥ gauss_norm (monom Q⇩p_x a n)" using assms (*‹a ∈ carrier Q⇩p›*) gauss_normE[of "monom Q⇩p_x a n" n] (*‹monom (UP Q⇩p) a n ∈ carrier (UP Q⇩p) ⟹ gauss_norm (monom (UP Q⇩p) a n) ≤ val (monom (UP Q⇩p) a n n)›*) UPQ.monom_closed (*‹?a ∈ carrier Q⇩p ⟹ monom (UP Q⇩p) ?a ?n ∈ carrier (UP Q⇩p)›*) by blast then show "?thesis" (*goal: ‹gauss_norm (monom (UP Q⇩p) a n) = val a›*) using gauss_norm_coeff_norm[of "monom Q⇩p_x a n"] (*‹∃na≤deg Q⇩p (monom (UP Q⇩p) a n). gauss_norm (monom (UP Q⇩p) a n) = val (monom (UP Q⇩p) a n na)›*) assms (*‹a ∈ carrier Q⇩p›*) val_ineq (*‹⟦?a ∈ carrier Q⇩p; val 𝟬 ≤ val ?a⟧ ⟹ ?a = 𝟬›*) UPQ.cfs_monom (*‹?a ∈ carrier Q⇩p ⟹ monom (UP Q⇩p) ?a ?m ?n = (if ?m = ?n then ?a else 𝟬)›*) by fastforce qed lemma val_val_ring_prod: assumes "a ∈ 𝒪⇩p" assumes "b ∈ carrier Q⇩p" shows "val (a ⊗⇘Q⇩p⇙ b) ≥ val b" proof (-) (*goal: ‹val b ≤ val (a ⊗ b)›*) have 0: "val (a ⊗⇘Q⇩p⇙ b) = val a + val b" using assms (*‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p› ‹b ∈ carrier Q⇩p›*) val_ring_memE[of a] (*‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ (0::eint) ≤ val a› ‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ a ∈ carrier Q⇩p›*) val_mult (*‹⟦(?x::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p; (?y::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p⟧ ⟹ val (?x ⊗ ?y) = val ?x + val ?y›*) by blast have 1: " val a ≥ 0" using assms (*‹a ∈ 𝒪⇩p› ‹b ∈ carrier Q⇩p›*) by (simp add: val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*)) then show "?thesis" (*goal: ‹val b ≤ val (a ⊗ b)›*) using assms (*‹a ∈ 𝒪⇩p› ‹b ∈ carrier Q⇩p›*) "0" (*‹val ((a::((nat ⇒ int) × (nat ⇒ int)) set) ⊗ (b::((nat ⇒ int) × (nat ⇒ int)) set)) = val a + val b›*) by simp qed lemma val_val_ring_prod': assumes "a ∈ 𝒪⇩p" assumes "b ∈ carrier Q⇩p" shows "val (b ⊗⇘Q⇩p⇙ a) ≥ val b" using val_val_ring_prod[of a b] (*‹⟦a ∈ 𝒪⇩p; b ∈ carrier Q⇩p⟧ ⟹ val b ≤ val (a ⊗ b)›*) by (simp add: Qp.m_comm (*‹⟦?x ∈ carrier Q⇩p; ?y ∈ carrier Q⇩p⟧ ⟹ ?x ⊗ ?y = ?y ⊗ ?x›*) val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) assms( (*‹a ∈ 𝒪⇩p›*) 1) assms( (*‹b ∈ carrier Q⇩p›*) 2)) lemma val_ring_nat_pow_closed: assumes "a ∈ 𝒪⇩p" shows "(a[^](n::nat)) ∈ 𝒪⇩p" apply (induction n) (*goal: ‹a [^] n ∈ 𝒪⇩p›*) apply ((auto)[1]) (*top goal: ‹a [^] 0 ∈ 𝒪⇩p› and 1 goal remains*) using Qp.inv_one (*‹inv 𝟭 = 𝟭›*) "Z⇩p_mem" (*‹?a ∈ carrier Q⇩p ⟹ ?a ∈ 𝒪⇩p ∨ inv ?a ∈ 𝒪⇩p›*) (*goals: 1. ‹𝟭 ∈ 𝒪⇩p› 2. ‹⋀n. a [^] n ∈ 𝒪⇩p ⟹ a [^] Suc n ∈ 𝒪⇩p› discuss goal 1*) apply blast (*discuss goal 2*) apply (metis Qp.nat_pow_Suc (*‹?x [^] Suc ?n = ?x [^] ?n ⊗ ?x›*) Qp.nat_pow_closed (*‹?x ∈ carrier Q⇩p ⟹ ?x [^] ?n ∈ carrier Q⇩p›*) val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) assms (*‹a ∈ 𝒪⇩p›*) image_eqI (*‹⟦?b = ?f ?x; ?x ∈ ?A⟧ ⟹ ?b ∈ ?f ` ?A›*) inc_of_prod (*‹⟦?a ∈ carrier Z⇩p; ?b ∈ carrier Z⇩p⟧ ⟹ ι (?a ⊗⇘Z⇩p⇙ ?b) = ι ?a ⊗ ι ?b›*) to_Zp_closed (*‹?a ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier Z⇩p›*) to_Zp_inc (*‹?a ∈ 𝒪⇩p ⟹ ι (to_Zp ?a) = ?a›*) to_Zp_mult (*‹⟦?a ∈ 𝒪⇩p; ?b ∈ 𝒪⇩p⟧ ⟹ to_Zp (?a ⊗ ?b) = to_Zp ?a ⊗⇘Z⇩p⇙ to_Zp ?b›*)) (*proven 2 subgoals*) . lemma val_ringI: assumes "a ∈ carrier Q⇩p" assumes "val a ≥0" shows " a ∈ 𝒪⇩p" apply (rule val_ring_val_criterion (*‹⟦?a ∈ carrier Q⇩p; 0 ≤ val ?a⟧ ⟹ ?a ∈ 𝒪⇩p›*)) (*goal: ‹a ∈ 𝒪⇩p›*) using assms (*‹a ∈ carrier Q⇩p› ‹(0::eint) ≤ val (a::((nat ⇒ int) × (nat ⇒ int)) set)›*) apply - (*goals: 1. ‹⟦(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p; (0::eint) ≤ val a⟧ ⟹ a ∈ carrier Q⇩p› 2. ‹⟦(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p; (0::eint) ≤ val a⟧ ⟹ (0::eint) ≤ val a› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . notation UPQ.to_fun (infixl‹∙› 70) lemma val_gauss_norm_eval: assumes "g ∈ carrier Q⇩p_x" assumes "a ∈ 𝒪⇩p" shows "val (g ∙ a) ≥ gauss_norm g" proof (-) (*goal: ‹gauss_norm g ≤ val (g ∙ a)›*) have 0: "g∙a = (⨁⇘Q⇩p⇙i∈{..degree g}. (g i)⊗⇘Q⇩p⇙ (a[^]i))" using val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) assms (*‹g ∈ carrier (UP Q⇩p)› ‹a ∈ 𝒪⇩p›*) to_fun_formula[of g a] (*‹⟦g ∈ carrier (UP Q⇩p); a ∈ carrier Q⇩p⟧ ⟹ g ∙ a = (⨁i∈{..deg Q⇩p g}. g i ⊗ a [^] i)›*) by auto have 1: "(λi. g i ⊗⇘Q⇩p⇙ (a[^]i)) ∈ {..degree g} → carrier Q⇩p" using assms (*‹g ∈ carrier (UP Q⇩p)› ‹a ∈ 𝒪⇩p›*) by (meson Pi_I (*‹(⋀x. x ∈ ?A ⟹ ?f x ∈ ?B x) ⟹ ?f ∈ Pi ?A ?B›*) val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) cfs_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ ?f ?n ∈ carrier Q⇩p›*) monom_term_car (*‹⟦?c ∈ carrier Q⇩p; ?x ∈ carrier Q⇩p⟧ ⟹ ?c ⊗ ?x [^] ?n ∈ carrier Q⇩p›*)) then have 2: "val (g∙a) ≥ Min (val ` (λ i. ((g i)⊗⇘Q⇩p⇙ (a[^]i))) ` {..degree g})" using "0" (*‹g ∙ a = (⨁i∈{..deg Q⇩p g}. g i ⊗ a [^] i)›*) finsum_val_ultrametric[of "λ i. ((g i)⊗⇘Q⇩p⇙ (a[^]i))" "{..degree g}"] (*‹⟦(λi. g i ⊗ a [^] i) ∈ {..deg Q⇩p g} → carrier Q⇩p; finite {..deg Q⇩p g}; {..deg Q⇩p g} ≠ {}⟧ ⟹ Min (val ` (λi. g i ⊗ a [^] i) ` {..deg Q⇩p g}) ≤ val (⨁i∈{..deg Q⇩p g}. g i ⊗ a [^] i)›*) by (metis finite_atMost (*‹finite {..?k}›*) not_empty_eq_Iic_eq_empty (*‹{} ≠ {..?h}›*)) have 3: "⋀ i. val ((g i)⊗⇘Q⇩p⇙ (a[^]i)) = val (g i) + val (a[^]i)" using assms (*‹g ∈ carrier (UP Q⇩p)› ‹a ∈ 𝒪⇩p›*) val_mult (*‹⟦(?x::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p; (?y::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p⟧ ⟹ val (?x ⊗ ?y) = val ?x + val ?y›*) by (simp add: val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) UPQ.cfs_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ ?f ?n ∈ carrier Q⇩p›*)) have 4: "⋀ i. val ((g i)⊗⇘Q⇩p⇙ (a[^]i)) ≥ val (g i)" proof (-) (*goal: ‹⋀i. val (g i) ≤ val (g i ⊗ a [^] i)›*) fix i show "val ((g i)⊗⇘Q⇩p⇙ (a[^]i)) ≥ val (g i)" using val_val_ring_prod'[of "a[^]i" "g i"] (*‹⟦a [^] i ∈ 𝒪⇩p; g i ∈ carrier Q⇩p⟧ ⟹ val (g i) ≤ val (g i ⊗ a [^] i)›*) assms(1) (*‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)›*) assms(2) (*‹a ∈ 𝒪⇩p›*) val_ring_nat_pow_closed (*‹?a ∈ 𝒪⇩p ⟹ ?a [^] ?n ∈ 𝒪⇩p›*) cfs_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ ?f ?n ∈ carrier Q⇩p›*) by simp qed have "Min (val ` (λi. g i ⊗⇘Q⇩p⇙ (a[^]i)) ` {..degree g}) ≥ Min ((λi. val (g i)) ` {..degree g})" using Min_mono'[of "{..degree g}" "λi. val (g i)" "λi. val (g i ⊗⇘Q⇩p⇙ (a[^]i))"] (*‹⟦finite {..deg Q⇩p g}; ⋀aa. aa ∈ {..deg Q⇩p g} ⟹ val (g aa) ≤ val (g aa ⊗ a [^] aa)⟧ ⟹ (MIN i∈{..deg Q⇩p g}. val (g i)) ≤ (MIN i∈{..deg Q⇩p g}. val (g i ⊗ a [^] i))›*) "4" (*‹val (g ?i1) ≤ val (g ?i1 ⊗ a [^] ?i1)›*) "2" (*‹Min (val ` (λi. g i ⊗ a [^] i) ` {..deg Q⇩p g}) ≤ val (g ∙ a)›*) by (metis finite_atMost (*‹finite {..?k}›*) image_image (*‹?f ` ?g ` ?A = (λx. ?f (?g x)) ` ?A›*)) then have "Min (val ` (λi. g i ⊗⇘Q⇩p⇙ (a[^]i)) ` {..degree g}) ≥ Min (val ` g ` {..degree g})" by (metis image_image (*‹?f ` ?g ` ?A = (λx. ?f (?g x)) ` ?A›*)) then have "val (g∙a) ≥ Min (val ` g ` {..degree g})" using "2" (*‹Min (val ` (λi::nat. (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) i ⊗ (a::((nat ⇒ int) × (nat ⇒ int)) set) [^] i) ` {..deg Q⇩p g}) ≤ val (g ∙ a)›*) by (meson atMost_iff (*‹(?i ∈ {..?k}) = (?i ≤ ?k)›*) atMost_subset_iff (*‹({..?x} ⊆ {..?y}) = (?x ≤ ?y)›*) in_mono (*‹?A ⊆ ?B ⟹ ?x ∈ ?A ⟶ ?x ∈ ?B›*)) then show "?thesis" (*goal: ‹gauss_norm g ≤ val (g ∙ a)›*) by (simp add: ‹val (g∙a) ≥ Min (val ` g ` {..degree g})› gauss_norm_def (*‹gauss_norm ?g = Min (val ` ?g ` {..deg Q⇩p ?g})›*)) qed lemma positive_gauss_norm_eval: assumes "g ∈ carrier Q⇩p_x" assumes "gauss_norm g ≥ 0" assumes "a ∈ 𝒪⇩p" shows "(g∙a) ∈ 𝒪⇩p" apply (rule val_ring_val_criterion[of "g∙a"] (*‹⟦g ∙ a ∈ carrier Q⇩p; 0 ≤ val (g ∙ a)⟧ ⟹ g ∙ a ∈ 𝒪⇩p›*)) (*goal: ‹g ∙ a ∈ 𝒪⇩p›*) using assms (*‹g ∈ carrier (UP Q⇩p)› ‹(0::eint) ≤ gauss_norm (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)› ‹a ∈ 𝒪⇩p›*) val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) using UPQ.to_fun_closed (*‹⟦?f ∈ carrier (UP Q⇩p); ?x ∈ carrier Q⇩p⟧ ⟹ ?f ∙ ?x ∈ carrier Q⇩p›*) apply blast (*top goal: ‹g ∙ a ∈ carrier Q⇩p› and 1 goal remains*) using assms (*‹g ∈ carrier (UP Q⇩p)› ‹0 ≤ gauss_norm g› ‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p›*) val_gauss_norm_eval[of g a] (*‹⟦g ∈ carrier (UP Q⇩p); a ∈ 𝒪⇩p⟧ ⟹ gauss_norm g ≤ val (g ∙ a)›*) by auto lemma positive_gauss_norm_valuation_ring_coeffs: assumes "g ∈ carrier Q⇩p_x" assumes "gauss_norm g ≥ 0" shows "g n ∈ 𝒪⇩p" apply (rule val_ringI (*‹⟦?a ∈ carrier Q⇩p; 0 ≤ val ?a⟧ ⟹ ?a ∈ 𝒪⇩p›*)) (*goal: ‹g n ∈ 𝒪⇩p›*) using cfs_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ ?f ?n ∈ carrier Q⇩p›*) assms(1) (*‹g ∈ carrier (UP Q⇩p)›*) apply blast (*top goal: ‹g n ∈ carrier Q⇩p› and 1 goal remains*) using gauss_normE[of g n] (*‹g ∈ carrier (UP Q⇩p) ⟹ gauss_norm g ≤ val (g n)›*) assms (*‹g ∈ carrier (UP Q⇩p)› ‹0 ≤ gauss_norm g›*) by auto lemma val_ring_cfs_imp_nonneg_gauss_norm: assumes "g ∈ carrier (UP Q⇩p)" assumes "⋀n. g n ∈ 𝒪⇩p" shows "gauss_norm g ≥ 0" apply (rule gauss_norm_geqI (*‹⟦?g ∈ carrier (UP Q⇩p); ⋀n. ?α ≤ val (?g n)⟧ ⟹ ?α ≤ gauss_norm ?g›*)) (*goals: 1. ‹g ∈ carrier (UP Q⇩p)› 2. ‹⋀n. 0 ≤ val (g n)› discuss goal 1*) apply (rule assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?n1 ∈ 𝒪⇩p›*)) (*discuss goal 2*) apply (rule val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*)) (*goal: ‹⋀n. 0 ≤ val (g n)›*) apply (rule assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?n1 ∈ 𝒪⇩p›*)) (*proven 2 subgoals*) . lemma val_of_add_pow: assumes "a ∈ carrier Q⇩p" shows "val ([(n::nat)]⋅a) ≥ val a" proof (-) (*goal: ‹val a ≤ val ([n] ⋅ a)›*) have 0: "[(n::nat)]⋅a = ([n]⋅𝟭)⊗a" using assms (*‹a ∈ carrier Q⇩p›*) Qp.add_pow_ldistr (*‹⟦(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p; (?b::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p⟧ ⟹ [(?k::nat)] ⋅ ?a ⊗ ?b = [?k] ⋅ (?a ⊗ ?b)›*) Qp.cring_simprules(12) (*‹?x ∈ carrier Q⇩p ⟹ 𝟭 ⊗ ?x = ?x›*) Qp.one_closed (*‹𝟭 ∈ carrier Q⇩p›*) by presburger have 1: "val ([(n::nat)]⋅a) = val ([n]⋅𝟭) + val a" unfolding "0" (*goal: ‹val ([n] ⋅ 𝟭 ⊗ a) = val ([n] ⋅ 𝟭) + val a›*) apply (rule val_mult (*‹⟦?x ∈ carrier Q⇩p; ?y ∈ carrier Q⇩p⟧ ⟹ val (?x ⊗ ?y) = val ?x + val ?y›*)) (*goals: 1. ‹[n] ⋅ 𝟭 ∈ carrier Q⇩p› 2. ‹a ∈ carrier Q⇩p› discuss goal 1*) apply simp (*discuss goal 2*) apply (rule assms (*‹a ∈ carrier Q⇩p›*)) (*proven 2 subgoals*) . show "?thesis" (*goal: ‹val a ≤ val ([n] ⋅ a)›*) unfolding "1" (*goal: ‹val a ≤ val ([n] ⋅ 𝟭) + val a›*) using assms (*‹a ∈ carrier Q⇩p›*) by (simp add: val_of_nat_inc (*‹0 ≤ val ([?k] ⋅ 𝟭)›*)) qed lemma gauss_norm_pderiv: assumes "g ∈ carrier (UP Q⇩p)" shows "gauss_norm g ≤ gauss_norm (pderiv g)" apply (rule gauss_norm_geqI (*‹⟦?g ∈ carrier (UP Q⇩p); ⋀n. ?α ≤ val (?g n)⟧ ⟹ ?α ≤ gauss_norm ?g›*)) (*goal: ‹gauss_norm (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ≤ gauss_norm (UPQ.pderiv g)›*) using UPQ.pderiv_closed (*‹(?p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p) ⟹ UPQ.pderiv ?p ∈ carrier (UP Q⇩p)›*) assms (*‹g ∈ carrier (UP Q⇩p)›*) apply blast (*top goal: ‹UPQ.pderiv g ∈ carrier (UP Q⇩p)› and 1 goal remains*) using gauss_normE (*‹?g ∈ carrier (UP Q⇩p) ⟹ gauss_norm ?g ≤ val (?g ?k)›*) pderiv_cfs (*‹(?g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p) ⟹ UPQ.pderiv ?g (?n::nat) = [Suc ?n] ⋅ ?g (Suc ?n)›*) val_of_add_pow (*‹?a ∈ carrier Q⇩p ⟹ val ?a ≤ val ([?n] ⋅ ?a)›*) by (smt UPQ.cfs_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ ?f ?n ∈ carrier Q⇩p›*) assms (*‹g ∈ carrier (UP Q⇩p)›*) dual_order.trans (*‹⟦?b ≤ ?a; ?c ≤ ?b⟧ ⟹ ?c ≤ ?a›*)) (**************************************************************************************************) (**************************************************************************************************) subsection‹Mapping Polynomials with Value Ring Coefficients to Polynomials over $\mathbb{Z}_p$› (**************************************************************************************************) (**************************************************************************************************) definition to_Zp_poly where "to_Zp_poly g = (λn. to_Zp (g n))" lemma to_Zp_poly_closed: assumes "g ∈ carrier Q⇩p_x" assumes "gauss_norm g ≥ 0" shows "to_Zp_poly g ∈ carrier (UP Z⇩p)" proof (-) (*goal: ‹to_Zp_poly (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring))›*) have "to_Zp_poly g ∈ up Z⇩p" apply (rule mem_upI (*‹⟦⋀n. ?f n ∈ carrier ?R; ∃n. bound 𝟬⇘?R⇙ n ?f⟧ ⟹ ?f ∈ up ?R›*)) (*goal: ‹to_Zp_poly (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ up (Z⇩p::(nat ⇒ int) ring)›*) unfolding to_Zp_poly_def (*goals: 1. ‹⋀n. to_Zp (g n) ∈ carrier Z⇩p› 2. ‹∃n. bound 𝟬⇘Z⇩p⇙ n (λn. to_Zp (g n))›*) using cfs_closed[of g] (*‹g ∈ carrier (UP Q⇩p) ⟹ g ?n ∈ carrier Q⇩p›*) assms(1) (*‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)›*) to_Zp_closed[of] (*‹?a ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier Z⇩p›*) proof (blast) (*goal: ‹∃n::nat. bound 𝟬⇘Z⇩p::(nat ⇒ int) ring⇙ n (λn::nat. to_Zp ((g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) n))›*) have "∃n. bound 𝟬⇘Q⇩p⇙ n g" using UPQ.deg_leE (*‹⟦?p ∈ carrier (UP Q⇩p); deg Q⇩p ?p < ?k⟧ ⟹ ?p ?k = 𝟬›*) assms(1) (*‹g ∈ carrier (UP Q⇩p)›*) by auto then obtain n where n_def: " bound 𝟬⇘Q⇩p⇙ n g" (*goal: ‹(⋀n. bound 𝟬 n g ⟹ thesis) ⟹ thesis›*) by blast then have " bound 𝟬⇘Z⇩p⇙ n (λn. to_Zp (g n))" unfolding bound_def (*goal: ‹∀m>n. to_Zp (g m) = 𝟬⇘Z⇩p⇙›*) by (simp add: to_Zp_zero (*‹to_Zp 𝟬 = 𝟬⇘Z⇩p::(nat ⇒ int) ring⇙›*)) then show "∃n. bound 𝟬⇘Z⇩p⇙ n (λn. to_Zp (g n))" by blast qed then show "?thesis" (*goal: ‹to_Zp_poly g ∈ carrier (UP Z⇩p)›*) using UP_def[of Z⇩p] (*‹UP (Z⇩p::(nat ⇒ int) ring) = ⦇carrier = up Z⇩p, monoid.mult = λp::nat ⇒ nat ⇒ int∈up Z⇩p. λq::nat ⇒ nat ⇒ int∈up Z⇩p. λn::nat. ⨁⇘Z⇩p⇙i::nat∈{..n}. p i ⊗⇘Z⇩p⇙ q (n - i), one = λi::nat. if i = (0::nat) then 𝟭⇘Z⇩p⇙ else 𝟬⇘Z⇩p⇙, zero = λi::nat. 𝟬⇘Z⇩p⇙, add = λp::nat ⇒ nat ⇒ int∈up Z⇩p. λq::nat ⇒ nat ⇒ int∈up Z⇩p. λi::nat. p i ⊕⇘Z⇩p⇙ q i, smult = λa::nat ⇒ int∈carrier Z⇩p. λp::nat ⇒ nat ⇒ int∈up Z⇩p. λi::nat. a ⊗⇘Z⇩p⇙ p i, monom = λa::nat ⇒ int∈carrier Z⇩p. λ(n::nat) i::nat. if i = n then a else 𝟬⇘Z⇩p⇙, coeff = λp::nat ⇒ nat ⇒ int∈up Z⇩p. p⦈›*) by simp qed definition poly_inc where "poly_inc g = (λn::nat. ι (g n))" lemma poly_inc_closed: assumes "g ∈ carrier (UP Z⇩p)" shows "poly_inc g ∈ carrier Q⇩p_x" proof (-) (*goal: ‹poly_inc g ∈ carrier (UP Q⇩p)›*) have "poly_inc g ∈ up Q⇩p" proof (rule mem_upI (*‹⟦⋀n. ?f n ∈ carrier ?R; ∃n. bound 𝟬⇘?R⇙ n ?f⟧ ⟹ ?f ∈ up ?R›*)) (*goals: 1. ‹⋀n. poly_inc g n ∈ carrier Q⇩p› 2. ‹∃n. bound 𝟬 n (poly_inc g)›*) show "⋀n. poly_inc g n ∈ carrier Q⇩p" proof (-) (*goal: ‹⋀n. poly_inc g n ∈ carrier Q⇩p›*) fix n have "g n ∈ carrier Z⇩p" using assms (*‹(g::nat ⇒ nat ⇒ int) ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring))›*) UP_def (*‹UP ?R = ⦇carrier = up ?R, monoid.mult = λp∈up ?R. λq∈up ?R. λn. ⨁⇘?R⇙i∈{..n}. p i ⊗⇘?R⇙ q (n - i), one = λi. if i = 0 then 𝟭⇘?R⇙ else 𝟬⇘?R⇙, zero = λi. 𝟬⇘?R⇙, add = λp∈up ?R. λq∈up ?R. λi. p i ⊕⇘?R⇙ q i, smult = λa∈carrier ?R. λp∈up ?R. λi. a ⊗⇘?R⇙ p i, monom = λa∈carrier ?R. λn i. if i = n then a else 𝟬⇘?R⇙, coeff = λp∈up ?R. p⦈›*) by (simp add: UP_def (*‹UP ?R = ⦇carrier = up ?R, monoid.mult = λp∈up ?R. λq∈up ?R. λn. ⨁⇘?R⇙i∈{..n}. p i ⊗⇘?R⇙ q (n - i), one = λi. if i = 0 then 𝟭⇘?R⇙ else 𝟬⇘?R⇙, zero = λi. 𝟬⇘?R⇙, add = λp∈up ?R. λq∈up ?R. λi. p i ⊕⇘?R⇙ q i, smult = λa∈carrier ?R. λp∈up ?R. λi. a ⊗⇘?R⇙ p i, monom = λa∈carrier ?R. λn i. if i = n then a else 𝟬⇘?R⇙, coeff = λp∈up ?R. p⦈›*) mem_upD (*‹?f ∈ up ?R ⟹ ?f ?n ∈ carrier ?R›*)) then show "poly_inc g n ∈ carrier Q⇩p" using assms (*‹(g::nat ⇒ nat ⇒ int) ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring))›*) poly_inc_def[of g] (*‹poly_inc g = (λn. ι (g n))›*) inc_def[of "g n"] (*‹g n ∈ carrier Z⇩p ⟹ ι (g n) = fraction Z⇩p (g n) 𝟭⇘Z⇩p⇙›*) inc_closed (*‹?a ∈ carrier Z⇩p ⟹ ι ?a ∈ carrier Q⇩p›*) by force qed show "∃n. bound 𝟬⇘Q⇩p⇙ n (poly_inc g)" proof (-) (*goal: ‹∃n::nat. bound 𝟬 n (poly_inc (g::nat ⇒ nat ⇒ int))›*) obtain n where n_def: " bound 𝟬⇘Z⇩p⇙ n g" (*goal: ‹(⋀n::nat. bound 𝟬⇘Z⇩p::(nat ⇒ int) ring⇙ n (g::nat ⇒ nat ⇒ int) ⟹ thesis::bool) ⟹ thesis›*) using assms (*‹g ∈ carrier (UP Z⇩p)›*) bound_def[of "𝟬⇘Z⇩p⇙" _ g] (*‹bound 𝟬⇘Z⇩p⇙ ?n g ≡ ∀m>?n. g m = 𝟬⇘Z⇩p⇙›*) Zp.cring_axioms (*‹cring Z⇩p›*) UP_cring.deg_leE[of Z⇩p g] (*‹⟦UP_cring (Z⇩p::(nat ⇒ int) ring); (g::nat ⇒ nat ⇒ int) ∈ carrier (UP Z⇩p); deg Z⇩p g < (?k::nat)⟧ ⟹ g ?k = 𝟬⇘Z⇩p⇙›*) unfolding UP_cring_def (*goal: ‹(⋀n. bound 𝟬⇘Z⇩p⇙ n g ⟹ thesis) ⟹ thesis›*) by metis then have " bound 𝟬⇘Q⇩p⇙ n (poly_inc g)" unfolding poly_inc_def bound_def (*goal: ‹∀m>n. ι (g m) = 𝟬›*) by (metis Qp.nat_inc_zero (*‹[0] ⋅ 𝟭 = 𝟬›*) Zp.nat_inc_zero (*‹[0] ⋅⇘Z⇩p⇙ 𝟭⇘Z⇩p⇙ = 𝟬⇘Z⇩p⇙›*) inc_of_nat (*‹ι ([?n] ⋅⇘Z⇩p⇙ 𝟭⇘Z⇩p⇙) = [?n] ⋅ 𝟭›*)) then show "?thesis" (*goal: ‹∃n. bound 𝟬 n (poly_inc g)›*) by blast qed qed then show "?thesis" (*goal: ‹poly_inc g ∈ carrier (UP Q⇩p)›*) by (simp add: ‹poly_inc g ∈ up Q⇩p› UP_def (*‹UP ?R = ⦇carrier = up ?R, monoid.mult = λp∈up ?R. λq∈up ?R. λn. ⨁⇘?R⇙i∈{..n}. p i ⊗⇘?R⇙ q (n - i), one = λi. if i = 0 then 𝟭⇘?R⇙ else 𝟬⇘?R⇙, zero = λi. 𝟬⇘?R⇙, add = λp∈up ?R. λq∈up ?R. λi. p i ⊕⇘?R⇙ q i, smult = λa∈carrier ?R. λp∈up ?R. λi. a ⊗⇘?R⇙ p i, monom = λa∈carrier ?R. λn i. if i = n then a else 𝟬⇘?R⇙, coeff = λp∈up ?R. p⦈›*)) qed lemma poly_inc_inverse_right: assumes "g ∈ carrier (UP Z⇩p)" shows "to_Zp_poly (poly_inc g) = g" proof (-) (*goal: ‹to_Zp_poly (poly_inc g) = g›*) have 0: "⋀n. g n ∈ carrier Z⇩p" by (simp add: Zp.cfs_closed (*‹?f ∈ carrier (UP Z⇩p) ⟹ ?f ?n ∈ carrier Z⇩p›*) assms (*‹g ∈ carrier (UP Z⇩p)›*)) show "?thesis" (*goal: ‹to_Zp_poly (poly_inc g) = g›*) unfolding to_Zp_poly_def poly_inc_def (*goal: ‹(λn. to_Zp (ι (g n))) = g›*) proof (standard) (*goal: ‹⋀n. to_Zp (ι (g n)) = g n›*) fix n show "to_Zp (ι (g n)) = g n" using "0" (*‹g ?n2 ∈ carrier Z⇩p›*) inc_to_Zp (*‹?b ∈ carrier Z⇩p ⟹ to_Zp (ι ?b) = ?b›*) by auto qed qed lemma poly_inc_inverse_left: assumes "g ∈ carrier Q⇩p_x" assumes "gauss_norm g ≥0" shows "poly_inc (to_Zp_poly g) = g" proof (standard) (*goal: ‹⋀x::nat. poly_inc (to_Zp_poly (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)) x = g x›*) fix x show "poly_inc (to_Zp_poly g) x = g x" using assms (*‹g ∈ carrier (UP Q⇩p)› ‹0 ≤ gauss_norm g›*) unfolding poly_inc_def to_Zp_poly_def (*goal: ‹ι (to_Zp (g x)) = g x›*) by (simp add: positive_gauss_norm_valuation_ring_coeffs (*‹⟦?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g⟧ ⟹ ?g ?n ∈ 𝒪⇩p›*) to_Zp_inc (*‹?a ∈ 𝒪⇩p ⟹ ι (to_Zp ?a) = ?a›*)) qed lemma poly_inc_plus: assumes "f ∈ carrier (UP Z⇩p)" assumes "g ∈ carrier (UP Z⇩p)" shows "poly_inc (f ⊕⇘UP Z⇩p⇙ g) = poly_inc f ⊕⇘UP Q⇩p⇙ poly_inc g" proof (standard) (*goal: ‹⋀x. poly_inc (f ⊕⇘UP Z⇩p⇙ g) x = (poly_inc f ⊕⇘UP Q⇩p⇙ poly_inc g) x›*) fix n have 0: "poly_inc (f ⊕⇘UP Z⇩p⇙ g) n = ι (f n ⊕⇘Z⇩p⇙ g n)" unfolding poly_inc_def (*goal: ‹ι ((f ⊕⇘UP Z⇩p⇙ g) n) = ι (f n ⊕⇘Z⇩p⇙ g n)›*) using assms (*‹f ∈ carrier (UP Z⇩p)› ‹g ∈ carrier (UP Z⇩p)›*) by auto have 1: "(poly_inc f ⊕⇘UP Q⇩p⇙ poly_inc g) n = poly_inc f n ⊕ poly_inc g n" apply (rule cfs_add (*‹⟦?p ∈ carrier (UP Q⇩p); ?q ∈ carrier (UP Q⇩p)⟧ ⟹ (?p ⊕⇘UP Q⇩p⇙ ?q) ?n = ?p ?n ⊕ ?q ?n›*)) (*goals: 1. ‹poly_inc f ∈ carrier (UP Q⇩p)› 2. ‹poly_inc g ∈ carrier (UP Q⇩p)› discuss goal 1*) apply (rule poly_inc_closed (*‹?g ∈ carrier (UP Z⇩p) ⟹ poly_inc ?g ∈ carrier (UP Q⇩p)›*)) (*top goal: ‹poly_inc f ∈ carrier (UP Q⇩p)› and 1 goal remains*) apply (rule assms (*‹f ∈ carrier (UP Z⇩p)› ‹g ∈ carrier (UP Z⇩p)›*)) (*discuss goal 2*) apply (rule poly_inc_closed (*‹?g ∈ carrier (UP Z⇩p) ⟹ poly_inc ?g ∈ carrier (UP Q⇩p)›*)) (*goal: ‹poly_inc (g::nat ⇒ nat ⇒ int) ∈ carrier (UP Q⇩p)›*) apply (rule assms (*‹f ∈ carrier (UP Z⇩p)› ‹g ∈ carrier (UP Z⇩p)›*)) (*proven 2 subgoals*) . show "poly_inc (f ⊕⇘UP Z⇩p⇙ g) n = (poly_inc f ⊕⇘UP Q⇩p⇙ poly_inc g) n" unfolding "0" "1" (*goal: ‹ι (f n ⊕⇘Z⇩p⇙ g n) = poly_inc f n ⊕ poly_inc g n›*) unfolding poly_inc_def (*goal: ‹ι (f n ⊕⇘Z⇩p⇙ g n) = ι (f n) ⊕ ι (g n)›*) apply (rule inc_of_sum (*‹⟦?a ∈ carrier Z⇩p; ?b ∈ carrier Z⇩p⟧ ⟹ ι (?a ⊕⇘Z⇩p⇙ ?b) = ι ?a ⊕ ι ?b›*)) (*goal: ‹ι (f n ⊕⇘Z⇩p⇙ g n) = ι (f n) ⊕ ι (g n)›*) using assms (*‹f ∈ carrier (UP Z⇩p)› ‹g ∈ carrier (UP Z⇩p)›*) apply (simp add: Zp.cfs_closed (*‹?f ∈ carrier (UP Z⇩p) ⟹ ?f ?n ∈ carrier Z⇩p›*); fail) (*top goal: ‹(f::nat ⇒ nat ⇒ int) (n::nat) ∈ carrier (Z⇩p::(nat ⇒ int) ring)› and 1 goal remains*) using assms (*‹(f::nat ⇒ nat ⇒ int) ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring))› ‹g ∈ carrier (UP Z⇩p)›*) by (simp add: Zp.cfs_closed (*‹?f ∈ carrier (UP Z⇩p) ⟹ ?f ?n ∈ carrier Z⇩p›*)) qed lemma poly_inc_monom: assumes "a ∈ carrier Z⇩p" shows "poly_inc (monom (UP Z⇩p) a m) = monom (UP Q⇩p) (ι a) m" proof (standard) (*goal: ‹⋀x. poly_inc (monom (UP Z⇩p) a m) x = monom (UP Q⇩p) (ι a) m x›*) fix n show "poly_inc (monom (UP Z⇩p) a m) n = monom (UP Q⇩p) (ι a) m n" apply (cases "m = n") (*goal: ‹poly_inc (monom (UP Z⇩p) a m) n = monom (UP Q⇩p) (ι a) m n›*) using assms (*‹a ∈ carrier Z⇩p›*) cfs_monom[of "ι a"] (*‹ι a ∈ carrier Q⇩p ⟹ monom (UP Q⇩p) (ι a) ?m ?n = (if ?m = ?n then ι a else 𝟬)›*) Zp.cfs_monom[of a] (*‹a ∈ carrier Z⇩p ⟹ monom (UP Z⇩p) a ?m ?n = (if ?m = ?n then a else 𝟬⇘Z⇩p⇙)›*) unfolding poly_inc_def (*goals: 1. ‹m = n ⟹ ι (monom (UP Z⇩p) a m n) = monom (UP Q⇩p) (ι a) m n› 2. ‹m ≠ n ⟹ ι (monom (UP Z⇩p) a m n) = monom (UP Q⇩p) (ι a) m n›*) apply (simp add: inc_closed (*‹(?a::nat ⇒ int) ∈ carrier (Z⇩p::(nat ⇒ int) ring) ⟹ (ι::(nat ⇒ int) ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ?a ∈ carrier Q⇩p›*); fail) (*top goal: ‹m = n ⟹ ι (monom (UP Z⇩p) a m n) = monom (UP Q⇩p) (ι a) m n› and 1 goal remains*) using assms (*‹a ∈ carrier Z⇩p›*) cfs_monom[of "ι a"] (*‹(ι::(nat ⇒ int) ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (a::nat ⇒ int) ∈ carrier Q⇩p ⟹ monom (UP Q⇩p) (ι a) (?m::nat) (?n::nat) = (if ?m = ?n then ι a else 𝟬)›*) Zp.cfs_monom[of a] (*‹a ∈ carrier Z⇩p ⟹ monom (UP Z⇩p) a ?m ?n = (if ?m = ?n then a else 𝟬⇘Z⇩p⇙)›*) unfolding poly_inc_def (*goal: ‹m ≠ n ⟹ ι (monom (UP Z⇩p) a m n) = monom (UP Q⇩p) (ι a) m n›*) by (metis Qp.nat_mult_zero (*‹[0] ⋅ ?x = 𝟬›*) Zp_nat_inc_zero (*‹[0] ⋅⇘Z⇩p⇙ ?x = 𝟬⇘Z⇩p⇙›*) inc_closed (*‹?a ∈ carrier Z⇩p ⟹ ι ?a ∈ carrier Q⇩p›*) inc_of_nat (*‹ι ([?n] ⋅⇘Z⇩p⇙ 𝟭⇘Z⇩p⇙) = [?n] ⋅ 𝟭›*)) qed lemma poly_inc_times: assumes "f ∈ carrier (UP Z⇩p)" assumes "g ∈ carrier (UP Z⇩p)" shows "poly_inc (f ⊗⇘UP Z⇩p⇙ g) = poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc g" apply (rule UP_ring.poly_induct3[of Z⇩p] (*‹⟦UP_ring Z⇩p; ?p ∈ carrier (UP Z⇩p); ⋀p q. ⟦q ∈ carrier (UP Z⇩p); p ∈ carrier (UP Z⇩p); ?Q p; ?Q q⟧ ⟹ ?Q (p ⊕⇘UP Z⇩p⇙ q); ⋀a n. a ∈ carrier Z⇩p ⟹ ?Q (monom (UP Z⇩p) a n)⟧ ⟹ ?Q ?p›*)) (*goal: ‹poly_inc (f ⊗⇘UP Z⇩p⇙ g) = poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc g›*) apply (simp add: Zp.is_UP_ring (*‹UP_ring Z⇩p›*); fail) (*top goal: ‹UP_ring Z⇩p› and 3 goals remain*) using assms (*‹f ∈ carrier (UP Z⇩p)› ‹g ∈ carrier (UP Z⇩p)›*) proof (blast) (*goals: 1. ‹⋀p q. ⟦q ∈ carrier (UP Z⇩p); p ∈ carrier (UP Z⇩p); poly_inc (f ⊗⇘UP Z⇩p⇙ p) = poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc p; poly_inc (f ⊗⇘UP Z⇩p⇙ q) = poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc q⟧ ⟹ poly_inc (f ⊗⇘UP Z⇩p⇙ (p ⊕⇘UP Z⇩p⇙ q)) = poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc (p ⊕⇘UP Z⇩p⇙ q)› 2. ‹⋀a n. a ∈ carrier Z⇩p ⟹ poly_inc (f ⊗⇘UP Z⇩p⇙ monom (UP Z⇩p) a n) = poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc (monom (UP Z⇩p) a n)›*) fix p and q assume A: "q ∈ carrier (UP Z⇩p)" "p ∈ carrier (UP Z⇩p)" "poly_inc (f ⊗⇘UP Z⇩p⇙ p) = poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc p" "poly_inc (f ⊗⇘UP Z⇩p⇙ q) = poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc q" (*‹(q::nat ⇒ nat ⇒ int) ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring))› ‹(p::nat ⇒ nat ⇒ int) ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring))› ‹poly_inc ((f::nat ⇒ nat ⇒ int) ⊗⇘UP (Z⇩p::(nat ⇒ int) ring)⇙ (p::nat ⇒ nat ⇒ int)) = poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc p› ‹poly_inc ((f::nat ⇒ nat ⇒ int) ⊗⇘UP (Z⇩p::(nat ⇒ int) ring)⇙ (q::nat ⇒ nat ⇒ int)) = poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc q›*) have 0: "(f ⊗⇘UP Z⇩p⇙ (p ⊕⇘UP Z⇩p⇙ q)) = (f ⊗⇘UP Z⇩p⇙ p) ⊕⇘UP Z⇩p⇙ (f ⊗⇘UP Z⇩p⇙ q)" using assms(1) (*‹(f::nat ⇒ nat ⇒ int) ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring))›*) A (*‹q ∈ carrier (UP Z⇩p)› ‹p ∈ carrier (UP Z⇩p)› ‹poly_inc (f ⊗⇘UP Z⇩p⇙ p) = poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc p› ‹poly_inc (f ⊗⇘UP Z⇩p⇙ q) = poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc q›*) by (simp add: Zp.P.r_distr (*‹⟦(?x::nat ⇒ nat ⇒ int) ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring)); (?y::nat ⇒ nat ⇒ int) ∈ carrier (UP Z⇩p); (?z::nat ⇒ nat ⇒ int) ∈ carrier (UP Z⇩p)⟧ ⟹ ?z ⊗⇘UP Z⇩p⇙ (?x ⊕⇘UP Z⇩p⇙ ?y) = ?z ⊗⇘UP Z⇩p⇙ ?x ⊕⇘UP Z⇩p⇙ ?z ⊗⇘UP Z⇩p⇙ ?y›*)) have 1: "poly_inc (p ⊕⇘UP Z⇩p⇙ q) = poly_inc p ⊕⇘UP Q⇩p⇙ poly_inc q" apply (rule poly_inc_plus (*‹⟦?f ∈ carrier (UP Z⇩p); ?g ∈ carrier (UP Z⇩p)⟧ ⟹ poly_inc (?f ⊕⇘UP Z⇩p⇙ ?g) = poly_inc ?f ⊕⇘UP Q⇩p⇙ poly_inc ?g›*)) (*goals: 1. ‹p ∈ carrier (UP Z⇩p)› 2. ‹q ∈ carrier (UP Z⇩p)› discuss goal 1*) apply (rule A (*‹(q::nat ⇒ nat ⇒ int) ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring))› ‹(p::nat ⇒ nat ⇒ int) ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring))› ‹poly_inc ((f::nat ⇒ nat ⇒ int) ⊗⇘UP (Z⇩p::(nat ⇒ int) ring)⇙ (p::nat ⇒ nat ⇒ int)) = poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc p› ‹poly_inc ((f::nat ⇒ nat ⇒ int) ⊗⇘UP (Z⇩p::(nat ⇒ int) ring)⇙ (q::nat ⇒ nat ⇒ int)) = poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc q›*)) (*discuss goal 2*) apply (rule A (*‹q ∈ carrier (UP Z⇩p)› ‹p ∈ carrier (UP Z⇩p)› ‹poly_inc (f ⊗⇘UP Z⇩p⇙ p) = poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc p› ‹poly_inc (f ⊗⇘UP Z⇩p⇙ q) = poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc q›*)) (*proven 2 subgoals*) . show "poly_inc (f ⊗⇘UP Z⇩p⇙ (p ⊕⇘UP Z⇩p⇙ q)) = poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc (p ⊕⇘UP Z⇩p⇙ q)" unfolding "0" "1" (*goal: ‹poly_inc (f ⊗⇘UP Z⇩p⇙ p ⊕⇘UP Z⇩p⇙ f ⊗⇘UP Z⇩p⇙ q) = poly_inc f ⊗⇘UP Q⇩p⇙ (poly_inc p ⊕⇘UP Q⇩p⇙ poly_inc q)›*) using A (*‹q ∈ carrier (UP Z⇩p)› ‹p ∈ carrier (UP Z⇩p)› ‹poly_inc (f ⊗⇘UP Z⇩p⇙ p) = poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc p› ‹poly_inc (f ⊗⇘UP Z⇩p⇙ q) = poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc q›*) poly_inc_closed (*‹?g ∈ carrier (UP Z⇩p) ⟹ poly_inc ?g ∈ carrier (UP Q⇩p)›*) poly_inc_plus (*‹⟦?f ∈ carrier (UP Z⇩p); ?g ∈ carrier (UP Z⇩p)⟧ ⟹ poly_inc (?f ⊕⇘UP Z⇩p⇙ ?g) = poly_inc ?f ⊕⇘UP Q⇩p⇙ poly_inc ?g›*) by (simp add: UPQ.P.r_distr (*‹⟦?x ∈ carrier (UP Q⇩p); ?y ∈ carrier (UP Q⇩p); ?z ∈ carrier (UP Q⇩p)⟧ ⟹ ?z ⊗⇘UP Q⇩p⇙ (?x ⊕⇘UP Q⇩p⇙ ?y) = ?z ⊗⇘UP Q⇩p⇙ ?x ⊕⇘UP Q⇩p⇙ ?z ⊗⇘UP Q⇩p⇙ ?y›*) assms( (*‹f ∈ carrier (UP Z⇩p)›*) 1)) next (*goal: ‹⋀a n. a ∈ carrier Z⇩p ⟹ poly_inc (f ⊗⇘UP Z⇩p⇙ monom (UP Z⇩p) a n) = poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc (monom (UP Z⇩p) a n)›*) fix a fix n :: nat assume A: "a ∈ carrier Z⇩p" (*‹(a::nat ⇒ int) ∈ carrier (Z⇩p::(nat ⇒ int) ring)›*) show "poly_inc (f ⊗⇘UP Z⇩p⇙ monom (UP Z⇩p) a n) = poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc (monom (UP Z⇩p) a n)" proof (standard) (*goal: ‹⋀x::nat. poly_inc ((f::nat ⇒ nat ⇒ int) ⊗⇘UP (Z⇩p::(nat ⇒ int) ring)⇙ monom (UP Z⇩p) (a::nat ⇒ int) (n::nat)) x = (poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc (monom (UP Z⇩p) a n)) x›*) fix m show "poly_inc (f ⊗⇘UP Z⇩p⇙ monom (UP Z⇩p) a n) m = (poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc (monom (UP Z⇩p) a n)) m" proof (cases "m < n") (*goals: 1. ‹m < n ⟹ poly_inc (f ⊗⇘UP Z⇩p⇙ monom (UP Z⇩p) a n) m = (poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc (monom (UP Z⇩p) a n)) m› 2. ‹¬ m < n ⟹ poly_inc (f ⊗⇘UP Z⇩p⇙ monom (UP Z⇩p) a n) m = (poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc (monom (UP Z⇩p) a n)) m›*) case True (*‹(m::nat) < (n::nat)›*) have T0: "(f ⊗⇘UP Z⇩p⇙ monom (UP Z⇩p) a n) m = 𝟬⇘Z⇩p⇙" using True (*‹m < n›*) Zp.cfs_monom_mult[of f a m n] (*‹⟦f ∈ carrier (UP Z⇩p); a ∈ carrier Z⇩p; m < n⟧ ⟹ (f ⊗⇘UP Z⇩p⇙ monom (UP Z⇩p) a n) m = 𝟬⇘Z⇩p⇙›*) A (*‹(a::nat ⇒ int) ∈ carrier (Z⇩p::(nat ⇒ int) ring)›*) assms (*‹f ∈ carrier (UP Z⇩p)› ‹g ∈ carrier (UP Z⇩p)›*) by blast have T1: "poly_inc (monom (UP Z⇩p) a n) = (monom (UP Q⇩p) (ι a) n)" apply (rule poly_inc_monom (*‹(?a::nat ⇒ int) ∈ carrier (Z⇩p::(nat ⇒ int) ring) ⟹ poly_inc (monom (UP Z⇩p) ?a (?m::nat)) = monom (UP Q⇩p) ((ι::(nat ⇒ int) ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ?a) ?m›*)) (*goal: ‹poly_inc (monom (UP Z⇩p) a n) = monom (UP Q⇩p) (ι a) n›*) by (rule A (*‹a ∈ carrier Z⇩p›*)) show "?thesis" (*goal: ‹poly_inc ((f::nat ⇒ nat ⇒ int) ⊗⇘UP (Z⇩p::(nat ⇒ int) ring)⇙ monom (UP Z⇩p) (a::nat ⇒ int) (n::nat)) (m::nat) = (poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc (monom (UP Z⇩p) a n)) m›*) unfolding T0 T1 (*goal: ‹poly_inc ((f::nat ⇒ nat ⇒ int) ⊗⇘UP (Z⇩p::(nat ⇒ int) ring)⇙ monom (UP Z⇩p) (a::nat ⇒ int) (n::nat)) (m::nat) = (poly_inc f ⊗⇘UP Q⇩p⇙ monom (UP Q⇩p) ((ι::(nat ⇒ int) ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) a) n) m›*) using True (*‹m < n›*) by (metis A (*‹a ∈ carrier Z⇩p›*) Q⇩p_def (*‹Q⇩p ≡ Frac Z⇩p›*) T0 (*‹(f ⊗⇘UP Z⇩p⇙ monom (UP Z⇩p) a n) m = 𝟬⇘Z⇩p⇙›*) UPQ.cfs_monom_mult (*‹⟦?p ∈ carrier (UP Q⇩p); ?a ∈ carrier Q⇩p; ?k < ?n⟧ ⟹ (?p ⊗⇘UP Q⇩p⇙ monom (UP Q⇩p) ?a ?n) ?k = 𝟬›*) Zp_def (*‹Z⇩p ≡ padic_int p›*) assms( (*‹f ∈ carrier (UP Z⇩p)›*) 1) inc_closed (*‹?a ∈ carrier Z⇩p ⟹ ι ?a ∈ carrier Q⇩p›*) padic_fields.to_Zp_zero (*‹padic_fields ?p ⟹ padic_fields.to_Zp ?p 𝟬⇘Frac (padic_int ?p)⇙ = 𝟬⇘padic_int ?p⇙›*) padic_fields_axioms (*‹padic_fields p›*) poly_inc_closed (*‹?g ∈ carrier (UP Z⇩p) ⟹ poly_inc ?g ∈ carrier (UP Q⇩p)›*) poly_inc_def (*‹poly_inc ?g = (λn. ι (?g n))›*) to_Zp_inc (*‹?a ∈ 𝒪⇩p ⟹ ι (to_Zp ?a) = ?a›*) zero_in_val_ring (*‹𝟬 ∈ 𝒪⇩p›*)) next (*goal: ‹¬ m < n ⟹ poly_inc (f ⊗⇘UP Z⇩p⇙ monom (UP Z⇩p) a n) m = (poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc (monom (UP Z⇩p) a n)) m›*) case False (*‹¬ (m::nat) < (n::nat)›*) then have F0: "m ≥ n" using False (*‹¬ m < n›*) by simp have F1: "(f ⊗⇘UP Z⇩p⇙ monom (UP Z⇩p) a n) m = a ⊗⇘Z⇩p⇙ f (m - n)" using Zp.cfs_monom_mult_l' (*‹⟦?f ∈ carrier (UP Z⇩p); ?a ∈ carrier Z⇩p; ?n ≤ ?m⟧ ⟹ (?f ⊗⇘UP Z⇩p⇙ monom (UP Z⇩p) ?a ?n) ?m = ?a ⊗⇘Z⇩p⇙ ?f (?m - ?n)›*) F0 (*‹n ≤ m›*) A (*‹(a::nat ⇒ int) ∈ carrier (Z⇩p::(nat ⇒ int) ring)›*) assms (*‹f ∈ carrier (UP Z⇩p)› ‹g ∈ carrier (UP Z⇩p)›*) by simp have F2: "poly_inc (monom (UP Z⇩p) a n) = monom (UP Q⇩p) (ι a) n " apply (rule poly_inc_monom (*‹?a ∈ carrier Z⇩p ⟹ poly_inc (monom (UP Z⇩p) ?a ?m) = monom (UP Q⇩p) (ι ?a) ?m›*)) (*goal: ‹poly_inc (monom (UP Z⇩p) a n) = monom (UP Q⇩p) (ι a) n›*) by (rule A (*‹a ∈ carrier Z⇩p›*)) have F3: "(poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc (monom (UP Z⇩p) a n)) m = (ι a) ⊗ (poly_inc f (m -n))" using UPQ.cfs_monom_mult_l' (*‹⟦?f ∈ carrier (UP Q⇩p); ?a ∈ carrier Q⇩p; ?n ≤ ?m⟧ ⟹ (?f ⊗⇘UP Q⇩p⇙ monom (UP Q⇩p) ?a ?n) ?m = ?a ⊗ ?f (?m - ?n)›*) F0 (*‹n ≤ m›*) A (*‹(a::nat ⇒ int) ∈ carrier (Z⇩p::(nat ⇒ int) ring)›*) assms (*‹f ∈ carrier (UP Z⇩p)› ‹(g::nat ⇒ nat ⇒ int) ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring))›*) poly_inc_closed (*‹?g ∈ carrier (UP Z⇩p) ⟹ poly_inc ?g ∈ carrier (UP Q⇩p)›*) by (simp add: F2 (*‹poly_inc (monom (UP Z⇩p) a n) = monom (UP Q⇩p) (ι a) n›*) inc_closed (*‹?a ∈ carrier Z⇩p ⟹ ι ?a ∈ carrier Q⇩p›*)) show "?thesis" (*goal: ‹poly_inc (f ⊗⇘UP Z⇩p⇙ monom (UP Z⇩p) a n) m = (poly_inc f ⊗⇘UP Q⇩p⇙ poly_inc (monom (UP Z⇩p) a n)) m›*) unfolding F3 (*goal: ‹poly_inc (f ⊗⇘UP Z⇩p⇙ monom (UP Z⇩p) a n) m = ι a ⊗ poly_inc f (m - n)›*) unfolding poly_inc_def F1 (*goal: ‹(ι::(nat ⇒ int) ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ((a::nat ⇒ int) ⊗⇘Z⇩p::(nat ⇒ int) ring⇙ (f::nat ⇒ nat ⇒ int) ((m::nat) - (n::nat))) = ι a ⊗ ι (f (m - n))›*) apply (rule inc_of_prod (*‹⟦?a ∈ carrier Z⇩p; ?b ∈ carrier Z⇩p⟧ ⟹ ι (?a ⊗⇘Z⇩p⇙ ?b) = ι ?a ⊗ ι ?b›*), rule A (*‹a ∈ carrier Z⇩p›*)) (*goal: ‹(ι::(nat ⇒ int) ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ((a::nat ⇒ int) ⊗⇘Z⇩p::(nat ⇒ int) ring⇙ (f::nat ⇒ nat ⇒ int) ((m::nat) - (n::nat))) = ι a ⊗ ι (f (m - n))›*) using assms (*‹f ∈ carrier (UP Z⇩p)› ‹(g::nat ⇒ nat ⇒ int) ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring))›*) Zp.cfs_closed (*‹?f ∈ carrier (UP Z⇩p) ⟹ ?f ?n ∈ carrier Z⇩p›*) by blast qed qed qed lemma poly_inc_one: "poly_inc (𝟭⇘UP Z⇩p⇙) = 𝟭⇘UP Q⇩p⇙" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹poly_inc 𝟭⇘UP (Z⇩p::(nat ⇒ int) ring)⇙ = 𝟭⇘UP Q⇩p⇙›*) unfolding poly_inc_def (*goal: ‹⋀x. ι (𝟭⇘UP Z⇩p⇙ x) = 𝟭⇘UP Q⇩p⇙ x›*) using inc_of_one (*‹ι 𝟭⇘Z⇩p⇙ = 𝟭›*) inc_of_zero (*‹ι 𝟬⇘Z⇩p⇙ = 𝟬›*) by simp lemma poly_inc_zero: "poly_inc (𝟬⇘UP Z⇩p⇙) = 𝟬⇘UP Q⇩p⇙" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹poly_inc 𝟬⇘UP Z⇩p⇙ = 𝟬⇘UP Q⇩p⇙›*) unfolding poly_inc_def (*goal: ‹⋀x. ι (𝟬⇘UP Z⇩p⇙ x) = 𝟬⇘UP Q⇩p⇙ x›*) using inc_of_one (*‹ι 𝟭⇘Z⇩p⇙ = 𝟭›*) inc_of_zero (*‹ι 𝟬⇘Z⇩p⇙ = 𝟬›*) by simp lemma poly_inc_hom: "poly_inc ∈ ring_hom (UP Z⇩p) (UP Q⇩p)" apply (rule ring_hom_memI (*‹⟦⋀x::?'a. x ∈ carrier (?R::(?'a, ?'b) ring_scheme) ⟹ (?h::?'a ⇒ ?'c) x ∈ carrier (?S::(?'c, ?'d) ring_scheme); ⋀(x::?'a) y::?'a. ⟦x ∈ carrier ?R; y ∈ carrier ?R⟧ ⟹ ?h (x ⊗⇘?R⇙ y) = ?h x ⊗⇘?S⇙ ?h y; ⋀(x::?'a) y::?'a. ⟦x ∈ carrier ?R; y ∈ carrier ?R⟧ ⟹ ?h (x ⊕⇘?R⇙ y) = ?h x ⊕⇘?S⇙ ?h y; ?h 𝟭⇘?R⇙ = 𝟭⇘?S⇙⟧ ⟹ ?h ∈ ring_hom ?R ?S›*)) (*goals: 1. ‹⋀x. x ∈ carrier (UP Z⇩p) ⟹ poly_inc x ∈ carrier (UP Q⇩p)› 2. ‹⋀x y. ⟦x ∈ carrier (UP Z⇩p); y ∈ carrier (UP Z⇩p)⟧ ⟹ poly_inc (x ⊗⇘UP Z⇩p⇙ y) = poly_inc x ⊗⇘UP Q⇩p⇙ poly_inc y› 3. ‹⋀x y. ⟦x ∈ carrier (UP Z⇩p); y ∈ carrier (UP Z⇩p)⟧ ⟹ poly_inc (x ⊕⇘UP Z⇩p⇙ y) = poly_inc x ⊕⇘UP Q⇩p⇙ poly_inc y› 4. ‹poly_inc 𝟭⇘UP Z⇩p⇙ = 𝟭⇘UP Q⇩p⇙› discuss goal 1*) apply (rule poly_inc_closed (*‹?g ∈ carrier (UP Z⇩p) ⟹ poly_inc ?g ∈ carrier (UP Q⇩p)›*)) (*top goal: ‹⋀x. x ∈ carrier (UP Z⇩p) ⟹ poly_inc x ∈ carrier (UP Q⇩p)› and 3 goals remain*) apply blast (*discuss goal 2*) apply (rule poly_inc_times (*‹⟦?f ∈ carrier (UP Z⇩p); ?g ∈ carrier (UP Z⇩p)⟧ ⟹ poly_inc (?f ⊗⇘UP Z⇩p⇙ ?g) = poly_inc ?f ⊗⇘UP Q⇩p⇙ poly_inc ?g›*)) (*goals: 1. ‹⋀(x::nat ⇒ nat ⇒ int) y::nat ⇒ nat ⇒ int. ⟦x ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring)); y ∈ carrier (UP Z⇩p)⟧ ⟹ x ∈ carrier (UP Z⇩p)› 2. ‹⋀(x::nat ⇒ nat ⇒ int) y::nat ⇒ nat ⇒ int. ⟦x ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring)); y ∈ carrier (UP Z⇩p)⟧ ⟹ y ∈ carrier (UP Z⇩p)› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) (*discuss goal 3*) apply (rule poly_inc_plus (*‹⟦?f ∈ carrier (UP Z⇩p); ?g ∈ carrier (UP Z⇩p)⟧ ⟹ poly_inc (?f ⊕⇘UP Z⇩p⇙ ?g) = poly_inc ?f ⊕⇘UP Q⇩p⇙ poly_inc ?g›*)) (*goals: 1. ‹⋀(x::nat ⇒ nat ⇒ int) y::nat ⇒ nat ⇒ int. ⟦x ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring)); y ∈ carrier (UP Z⇩p)⟧ ⟹ x ∈ carrier (UP Z⇩p)› 2. ‹⋀(x::nat ⇒ nat ⇒ int) y::nat ⇒ nat ⇒ int. ⟦x ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring)); y ∈ carrier (UP Z⇩p)⟧ ⟹ y ∈ carrier (UP Z⇩p)› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) (*discuss goal 4*) apply (rule poly_inc_one (*‹poly_inc 𝟭⇘UP Z⇩p⇙ = 𝟭⇘UP Q⇩p⇙›*)) (*proven 4 subgoals*) . lemma poly_inc_as_poly_lift_hom: assumes "f ∈ carrier (UP Z⇩p)" shows "poly_inc f = poly_lift_hom Z⇩p Q⇩p ι f" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹poly_inc f = poly_lift_hom Z⇩p Q⇩p ι f›*) unfolding poly_inc_def (*goal: ‹⋀x. ι (f x) = poly_lift_hom Z⇩p Q⇩p ι f x›*) using Zp.poly_lift_hom_cf[of Q⇩p ι f] (*‹⟦cring Q⇩p; ι ∈ ring_hom Z⇩p Q⇩p; f ∈ carrier (UP Z⇩p)⟧ ⟹ poly_lift_hom Z⇩p Q⇩p ι f ?k = ι (f ?k)›*) assms (*‹f ∈ carrier (UP Z⇩p)›*) UPQ.R_cring (*‹cring Q⇩p›*) local.inc_is_hom (*‹ι ∈ ring_hom Z⇩p Q⇩p›*) by blast lemma poly_inc_eval: assumes "g ∈ carrier (UP Z⇩p)" assumes "a ∈ carrier Z⇩p" shows "to_function Q⇩p (poly_inc g) (ι a) = ι (to_function Z⇩p g a)" proof (-) (*goal: ‹to_function Q⇩p (poly_inc g) (ι a) = ι (to_function Z⇩p g a)›*) have 0: "poly_inc g = poly_lift_hom Z⇩p Q⇩p ι g" using assms (*‹g ∈ carrier (UP Z⇩p)› ‹a ∈ carrier Z⇩p›*) poly_inc_as_poly_lift_hom[of g] (*‹(g::nat ⇒ nat ⇒ int) ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring)) ⟹ poly_inc g = poly_lift_hom Z⇩p Q⇩p (ι::(nat ⇒ int) ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) g›*) by blast have 1: "to_function Q⇩p (poly_lift_hom Z⇩p Q⇩p ι g) (ι a) = ι (to_function Z⇩p g a)" using Zp.poly_lift_hom_eval[of Q⇩p ι g a] (*‹⟦cring Q⇩p; ι ∈ ring_hom Z⇩p Q⇩p; g ∈ carrier (UP Z⇩p); a ∈ carrier Z⇩p⟧ ⟹ poly_lift_hom Z⇩p Q⇩p ι g ∙ ι a = ι (Zp.to_fun g a)›*) assms (*‹g ∈ carrier (UP Z⇩p)› ‹a ∈ carrier Z⇩p›*) inc_is_hom (*‹ι ∈ ring_hom Z⇩p Q⇩p›*) unfolding to_fun_def Zp.to_fun_def (*goal: ‹to_function Q⇩p (poly_lift_hom Z⇩p Q⇩p ι g) (ι a) = ι (to_function Z⇩p g a)›*) using UPQ.R_cring (*‹cring Q⇩p›*) by blast show "?thesis" (*goal: ‹to_function Q⇩p (poly_inc g) (ι a) = ι (to_function Z⇩p g a)›*) unfolding "0" "1" (*goal: ‹ι (to_function Z⇩p g a) = ι (to_function Z⇩p g a)›*) by blast qed lemma val_ring_poly_eval: assumes "f ∈ carrier (UP Q⇩p)" assumes "⋀ i. f i ∈ 𝒪⇩p" shows "⋀x. x ∈ 𝒪⇩p ⟹ f ∙ x ∈ 𝒪⇩p" apply (rule positive_gauss_norm_eval (*‹⟦?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g; ?a ∈ 𝒪⇩p⟧ ⟹ ?g ∙ ?a ∈ 𝒪⇩p›*), rule assms (*‹(f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹(f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (?i2::nat) ∈ 𝒪⇩p›*)) (*goal: ‹⋀x. x ∈ 𝒪⇩p ⟹ f ∙ x ∈ 𝒪⇩p›*) apply (rule val_ring_cfs_imp_nonneg_gauss_norm (*‹⟦?g ∈ carrier (UP Q⇩p); ⋀n. ?g n ∈ 𝒪⇩p⟧ ⟹ 0 ≤ gauss_norm ?g›*)) (*top goal: ‹⋀x. x ∈ 𝒪⇩p ⟹ 0 ≤ gauss_norm f› and 1 goal remains*) using assms (*‹f ∈ carrier (UP Q⇩p)› ‹f ?i2 ∈ 𝒪⇩p›*) apply - (*goals: 1. ‹⋀x. ⟦x ∈ 𝒪⇩p; f ∈ carrier (UP Q⇩p); ⋀i. f i ∈ 𝒪⇩p⟧ ⟹ f ∈ carrier (UP Q⇩p)› 2. ‹⋀x n. ⟦x ∈ 𝒪⇩p; f ∈ carrier (UP Q⇩p); ⋀i. f i ∈ 𝒪⇩p⟧ ⟹ f n ∈ 𝒪⇩p› 3. ‹⋀x. ⟦x ∈ 𝒪⇩p; f ∈ carrier (UP Q⇩p); ⋀i. f i ∈ 𝒪⇩p⟧ ⟹ x ∈ 𝒪⇩p› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . lemma Zp_res_of_pow: assumes "a ∈ carrier Z⇩p" assumes "b ∈ carrier Z⇩p" assumes "a n = b n" shows "(a[^]⇘Z⇩p⇙(k::nat)) n = (b[^]⇘Z⇩p⇙(k::nat)) n" apply (induction k) (*goal: ‹(a [^]⇘Z⇩p⇙ k) n = (b [^]⇘Z⇩p⇙ k) n›*) using assms (*‹a ∈ carrier Z⇩p› ‹b ∈ carrier Z⇩p› ‹a n = b n›*) Group.nat_pow_0 (*‹(?x::?'a) [^]⇘?G::(?'a, ?'b) monoid_scheme⇙ (0::nat) = 𝟭⇘?G⇙›*) to_Zp_one (*‹to_Zp 𝟭 = 𝟭⇘Z⇩p⇙›*) apply metis (*top goal: ‹(a [^]⇘Z⇩p⇙ 0) n = (b [^]⇘Z⇩p⇙ 0) n› and 1 goal remains*) using Zp.geometric_series_id[of a b] (*‹⟦a ∈ carrier Z⇩p; b ∈ carrier Z⇩p⟧ ⟹ a [^]⇘Z⇩p⇙ Suc ?n ⊖⇘Z⇩p⇙ b [^]⇘Z⇩p⇙ Suc ?n = (a ⊖⇘Z⇩p⇙ b) ⊗⇘Z⇩p⇙ Zp.geometric_series ?n a b›*) Zp_residue_mult_zero(1) (*‹?a ?k = 0 ⟹ (?a ⊗⇘Z⇩p⇙ ?b) ?k = 0›*) assms(1) (*‹a ∈ carrier Z⇩p›*) assms(2) (*‹b ∈ carrier Z⇩p›*) assms(3) (*‹a n = b n›*) pow_closed (*‹(?a::nat ⇒ int) ∈ carrier (Z⇩p::(nat ⇒ int) ring) ⟹ ?a [^]⇘Z⇩p⇙ (?n::nat) ∈ carrier Z⇩p›*) res_diff_zero_fact'' (*‹⟦?a ∈ carrier Z⇩p; ?b ∈ carrier Z⇩p; ?a ?k = ?b ?k⟧ ⟹ (?a ⊖⇘Z⇩p⇙ ?b) ?k = 0›*) res_diff_zero_fact(1) (*‹⟦(?a::nat ⇒ int) ∈ carrier (Z⇩p::(nat ⇒ int) ring); (?b::nat ⇒ int) ∈ carrier Z⇩p; (?a ⊖⇘Z⇩p⇙ ?b) (?k::nat) = (0::int)⟧ ⟹ ?a ?k = ?b ?k›*) by metis lemma to_Zp_nat_pow: assumes "a ∈ 𝒪⇩p" shows "to_Zp (a[^](n::nat)) = (to_Zp a)[^]⇘Z⇩p⇙(n::nat)" apply (induction n) (*goal: ‹to_Zp (a [^] n) = to_Zp a [^]⇘Z⇩p⇙ n›*) using assms (*‹a ∈ 𝒪⇩p›*) Group.nat_pow_0 (*‹?x [^]⇘?G⇙ 0 = 𝟭⇘?G⇙›*) to_Zp_one (*‹to_Zp 𝟭 = 𝟭⇘Z⇩p⇙›*) apply metis (*top goal: ‹to_Zp (a [^] 0) = to_Zp a [^]⇘Z⇩p⇙ 0› and 1 goal remains*) using assms (*‹a ∈ 𝒪⇩p›*) to_Zp_mult[of a] (*‹⟦a ∈ 𝒪⇩p; ?b ∈ 𝒪⇩p⟧ ⟹ to_Zp (a ⊗ ?b) = to_Zp a ⊗⇘Z⇩p⇙ to_Zp ?b›*) Qp.m_comm (*‹⟦?x ∈ carrier Q⇩p; ?y ∈ carrier Q⇩p⟧ ⟹ ?x ⊗ ?y = ?y ⊗ ?x›*) Qp.nat_pow_Suc (*‹?x [^] Suc ?n = ?x [^] ?n ⊗ ?x›*) val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) pow_suc (*‹?a ∈ carrier Z⇩p ⟹ ?a [^]⇘Z⇩p⇙ Suc ?n = ?a ⊗⇘Z⇩p⇙ ?a [^]⇘Z⇩p⇙ ?n›*) to_Zp_closed (*‹?a ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier Z⇩p›*) val_ring_nat_pow_closed (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ ?a [^] (?n::nat) ∈ 𝒪⇩p›*) by metis lemma to_Zp_res_of_pow: assumes "a ∈ 𝒪⇩p" assumes "b ∈ 𝒪⇩p" assumes "to_Zp a n = to_Zp b n" shows "to_Zp (a[^](k::nat)) n = to_Zp (b[^](k::nat)) n" using assms (*‹a ∈ 𝒪⇩p› ‹b ∈ 𝒪⇩p› ‹to_Zp a n = to_Zp b n›*) val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) Zp_res_of_pow (*‹⟦?a ∈ carrier Z⇩p; ?b ∈ carrier Z⇩p; ?a ?n = ?b ?n⟧ ⟹ (?a [^]⇘Z⇩p⇙ ?k) ?n = (?b [^]⇘Z⇩p⇙ ?k) ?n›*) to_Zp_closed (*‹?a ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier Z⇩p›*) to_Zp_nat_pow (*‹?a ∈ 𝒪⇩p ⟹ to_Zp (?a [^] ?n) = to_Zp ?a [^]⇘Z⇩p⇙ ?n›*) by presburger lemma poly_eval_cong: assumes "g ∈ carrier (UP Q⇩p)" assumes "⋀i. g i ∈ 𝒪⇩p" assumes "a ∈ 𝒪⇩p" assumes "b ∈ 𝒪⇩p" assumes "to_Zp a k = to_Zp b k" shows "to_Zp (g ∙ a) k = to_Zp (g ∙ b) k" proof (-) (*goal: ‹to_Zp (g ∙ a) k = to_Zp (g ∙ b) k›*) have "(∀i. g i ∈ 𝒪⇩p) ⟶ to_Zp (g ∙ a) k = to_Zp (g ∙ b) k" proof (rule UPQ.poly_induct[of g] (*‹⟦g ∈ carrier (UP Q⇩p); ⋀p. ⟦p ∈ carrier (UP Q⇩p); deg Q⇩p p = 0⟧ ⟹ ?Q p; ⋀p. ⟦⋀q. ⟦q ∈ carrier (UP Q⇩p); deg Q⇩p q < deg Q⇩p p⟧ ⟹ ?Q q; p ∈ carrier (UP Q⇩p); 0 < deg Q⇩p p⟧ ⟹ ?Q p⟧ ⟹ ?Q g›*)) (*goals: 1. ‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› 2. ‹⋀p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set. ⟦p ∈ carrier (UP Q⇩p); deg Q⇩p p = (0::nat)⟧ ⟹ (∀i::nat. p i ∈ 𝒪⇩p) ⟶ to_Zp (p ∙ (a::((nat ⇒ int) × (nat ⇒ int)) set)) (k::nat) = to_Zp (p ∙ (b::((nat ⇒ int) × (nat ⇒ int)) set)) k› 3. ‹⋀p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set. ⟦⋀q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set. ⟦q ∈ carrier (UP Q⇩p); deg Q⇩p q < deg Q⇩p p⟧ ⟹ (∀i::nat. q i ∈ 𝒪⇩p) ⟶ to_Zp (q ∙ (a::((nat ⇒ int) × (nat ⇒ int)) set)) (k::nat) = to_Zp (q ∙ (b::((nat ⇒ int) × (nat ⇒ int)) set)) k; p ∈ carrier (UP Q⇩p); (0::nat) < deg Q⇩p p⟧ ⟹ (∀i::nat. p i ∈ 𝒪⇩p) ⟶ to_Zp (p ∙ a) k = to_Zp (p ∙ b) k›*) show " g ∈ carrier (UP Q⇩p)" using assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?i2 ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p› ‹b ∈ 𝒪⇩p› ‹to_Zp a k = to_Zp b k›*) by blast show "⋀p. p ∈ carrier (UP Q⇩p) ⟹ deg Q⇩p p = 0 ⟹ (∀i. p i ∈ 𝒪⇩p) ⟶ to_Zp (p ∙ a) k = to_Zp (p ∙ b) k" proof (standard) (*goal: ‹⋀p. ⟦p ∈ carrier (UP Q⇩p); deg Q⇩p p = 0; ∀i. p i ∈ 𝒪⇩p⟧ ⟹ to_Zp (p ∙ a) k = to_Zp (p ∙ b) k›*) fix p assume A: "p ∈ carrier (UP Q⇩p)" "deg Q⇩p p = 0" "∀i. p i ∈ 𝒪⇩p" (*‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) = (0::nat)› ‹∀i::nat. (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) i ∈ 𝒪⇩p›*) obtain c where c_def: "c ∈ carrier Q⇩p ∧ p = up_ring.monom (UP Q⇩p) c 0" (*goal: ‹(⋀c. c ∈ carrier Q⇩p ∧ p = monom (UP Q⇩p) c 0 ⟹ thesis) ⟹ thesis›*) using A (*‹p ∈ carrier (UP Q⇩p)› ‹deg Q⇩p p = 0› ‹∀i. p i ∈ 𝒪⇩p›*) by (metis UPQ.zcf_degree_zero (*‹⟦?f ∈ carrier (UP Q⇩p); deg Q⇩p ?f = 0⟧ ⟹ ?f (deg Q⇩p ?f) = zcf ?f›*) UPQ.cfs_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ ?f ?n ∈ carrier Q⇩p›*) UPQ.trms_of_deg_leq_0 (*‹?f ∈ carrier (UP Q⇩p) ⟹ UPQ.trms_of_deg_leq 0 ?f = monom (UP Q⇩p) (?f 0) 0›*) UPQ.trms_of_deg_leq_degree_f (*‹?f ∈ carrier (UP Q⇩p) ⟹ UPQ.trms_of_deg_leq (deg Q⇩p ?f) ?f = ?f›*)) have p_eq: "p = up_ring.monom (UP Q⇩p) c 0" using c_def (*‹(c::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p ∧ (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) = monom (UP Q⇩p) c (0::nat)›*) by blast have p_cfs: "p 0 = c" unfolding p_eq (*goal: ‹monom (UP Q⇩p) (c::((nat ⇒ int) × (nat ⇒ int)) set) (0::nat) (0::nat) = c›*) using c_def (*‹c ∈ carrier Q⇩p ∧ p = monom (UP Q⇩p) c 0›*) UP_ring.cfs_monom[of Q⇩p c 0 0] (*‹⟦UP_ring Q⇩p; c ∈ carrier Q⇩p⟧ ⟹ monom (UP Q⇩p) c 0 0 = (if 0 = 0 then c else 𝟬)›*) UPQ.P_is_UP_ring (*‹UP_ring Q⇩p›*) by presburger have c_closed: "c ∈ 𝒪⇩p" using p_cfs (*‹p 0 = c›*) A(3) (*‹∀i. p i ∈ 𝒪⇩p›*) by blast have 0: "(p ∙ a) = c" unfolding p_eq (*goal: ‹monom (UP Q⇩p) c 0 ∙ a = c›*) using c_def (*‹(c::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p ∧ (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) = monom (UP Q⇩p) c (0::nat)›*) assms (*‹g ∈ carrier (UP Q⇩p)› ‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (?i2::nat) ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p› ‹b ∈ 𝒪⇩p› ‹to_Zp a k = to_Zp b k›*) by (meson UPQ.to_fun_const (*‹⟦?a ∈ carrier Q⇩p; ?b ∈ carrier Q⇩p⟧ ⟹ monom (UP Q⇩p) ?a 0 ∙ ?b = ?a›*) val_ring_memE( (*‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) 2)) have 1: "(p ∙ b) = c" unfolding p_eq (*goal: ‹monom (UP Q⇩p) c 0 ∙ b = c›*) using c_def (*‹(c::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p ∧ (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) = monom (UP Q⇩p) c (0::nat)›*) assms (*‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹g ?i2 ∈ 𝒪⇩p› ‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p› ‹(b::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p› ‹to_Zp a k = to_Zp b k›*) UPQ.to_fun_const (*‹⟦?a ∈ carrier Q⇩p; ?b ∈ carrier Q⇩p⟧ ⟹ monom (UP Q⇩p) ?a 0 ∙ ?b = ?a›*) val_ring_memE(2) (*‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) by presburger show " to_Zp (p ∙ a) k = to_Zp (p ∙ b) k" unfolding "0" "1" (*goal: ‹to_Zp c k = to_Zp c k›*) by blast qed show "⋀p. (⋀q. q ∈ carrier (UP Q⇩p) ⟹ deg Q⇩p q < deg Q⇩p p ⟹ (∀i. q i ∈ 𝒪⇩p) ⟶ to_Zp (q ∙ a) k = to_Zp (q ∙ b) k) ⟹ p ∈ carrier (UP Q⇩p) ⟹ 0 < deg Q⇩p p ⟹ (∀i. p i ∈ 𝒪⇩p) ⟶ to_Zp (p ∙ a) k = to_Zp (p ∙ b) k" proof (standard) (*goal: ‹⋀p. ⟦⋀q. ⟦q ∈ carrier (UP Q⇩p); deg Q⇩p q < deg Q⇩p p⟧ ⟹ (∀i. q i ∈ 𝒪⇩p) ⟶ to_Zp (q ∙ a) k = to_Zp (q ∙ b) k; p ∈ carrier (UP Q⇩p); 0 < deg Q⇩p p; ∀i. p i ∈ 𝒪⇩p⟧ ⟹ to_Zp (p ∙ a) k = to_Zp (p ∙ b) k›*) fix p assume A: "(⋀q. q ∈ carrier (UP Q⇩p) ⟹ deg Q⇩p q < deg Q⇩p p ⟹ (∀i. q i ∈ 𝒪⇩p) ⟶ to_Zp (q ∙ a) k = to_Zp (q ∙ b) k)" "p ∈ carrier (UP Q⇩p)" "0 < deg Q⇩p p " " ∀i. p i ∈ 𝒪⇩p" (*‹⟦(?q2::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); deg Q⇩p ?q2 < deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)⟧ ⟹ (∀i::nat. ?q2 i ∈ 𝒪⇩p) ⟶ to_Zp (?q2 ∙ (a::((nat ⇒ int) × (nat ⇒ int)) set)) (k::nat) = to_Zp (?q2 ∙ (b::((nat ⇒ int) × (nat ⇒ int)) set)) k› ‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹(0::nat) < deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)› ‹∀i::nat. (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) i ∈ 𝒪⇩p›*) obtain q where q_def: "q ∈ carrier (UP Q⇩p) ∧ deg Q⇩p q < deg Q⇩p p ∧ p = UPQ.ltrm p ⊕⇘UP Q⇩p⇙q" (*goal: ‹(⋀q. q ∈ carrier (UP Q⇩p) ∧ deg Q⇩p q < deg Q⇩p p ∧ p = monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ⊕⇘UP Q⇩p⇙ q ⟹ thesis) ⟹ thesis›*) by (metis A( (*‹p ∈ carrier (UP Q⇩p)›*) 2) A( (*‹0 < deg Q⇩p p›*) 3) UPQ.ltrm_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f) ∈ carrier (UP Q⇩p)›*) UPQ.ltrm_decomp (*‹⟦?f ∈ carrier (UP Q⇩p); 0 < deg Q⇩p ?f; ⋀g. g ∈ carrier (UP Q⇩p) ∧ ?f = g ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f) ∧ deg Q⇩p g < deg Q⇩p ?f ⟹ ?thesis⟧ ⟹ ?thesis›*) UPQ.UP_a_comm (*‹⟦?p ∈ carrier (UP Q⇩p); ?q ∈ carrier (UP Q⇩p)⟧ ⟹ ?p ⊕⇘UP Q⇩p⇙ ?q = ?q ⊕⇘UP Q⇩p⇙ ?p›*)) have 0: "⋀i. p i = q i ⊕ UPQ.ltrm p i" using q_def (*‹q ∈ carrier (UP Q⇩p) ∧ deg Q⇩p q < deg Q⇩p p ∧ p = monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ⊕⇘UP Q⇩p⇙ q›*) A (*‹⟦?q2 ∈ carrier (UP Q⇩p); deg Q⇩p ?q2 < deg Q⇩p p⟧ ⟹ (∀i. ?q2 i ∈ 𝒪⇩p) ⟶ to_Zp (?q2 ∙ a) k = to_Zp (?q2 ∙ b) k› ‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹0 < deg Q⇩p p› ‹∀i. p i ∈ 𝒪⇩p›*) by (metis Qp.a_ac( (*‹⟦?x ∈ carrier Q⇩p; ?y ∈ carrier Q⇩p⟧ ⟹ ?x ⊕ ?y = ?y ⊕ ?x›*) 2) UPQ.ltrm_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f) ∈ carrier (UP Q⇩p)›*) UPQ.UP_car_memE( (*‹?g ∈ carrier (UP Q⇩p) ⟹ ?g ?x ∈ carrier Q⇩p›*) 1) UPQ.cfs_add (*‹⟦?p ∈ carrier (UP Q⇩p); ?q ∈ carrier (UP Q⇩p)⟧ ⟹ (?p ⊕⇘UP Q⇩p⇙ ?q) ?n = ?p ?n ⊕ ?q ?n›*)) have 1: "∀i. q i ∈ 𝒪⇩p" proof (standard) (*goal: ‹⋀i. q i ∈ 𝒪⇩p›*) fix i show "q i ∈ 𝒪⇩p" apply (cases "i < deg Q⇩p p") (*goal: ‹(q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (i::nat) ∈ 𝒪⇩p›*) using "0"[of i] (*‹p i = q i ⊕ monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) i›*) A(4) (*‹∀i. p i ∈ 𝒪⇩p›*) A(2) (*‹p ∈ carrier (UP Q⇩p)›*) q_def (*‹q ∈ carrier (UP Q⇩p) ∧ deg Q⇩p q < deg Q⇩p p ∧ p = monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ⊕⇘UP Q⇩p⇙ q›*) using UPQ.ltrm_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f) ∈ carrier (UP Q⇩p)›*) UPQ.P.a_ac(2) (*‹⟦?x ∈ carrier (UP Q⇩p); ?y ∈ carrier (UP Q⇩p)⟧ ⟹ ?x ⊕⇘UP Q⇩p⇙ ?y = ?y ⊕⇘UP Q⇩p⇙ ?x›*) UPQ.trunc_cfs (*‹⟦?p ∈ carrier (UP Q⇩p); ?n < deg Q⇩p ?p⟧ ⟹ Cring_Poly.truncate Q⇩p ?p ?n = ?p ?n›*) UPQ.trunc_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ Cring_Poly.truncate Q⇩p ?f ∈ carrier (UP Q⇩p)›*) UPQ.trunc_simps(1) (*‹(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p) ⟹ ?f = Cring_Poly.truncate Q⇩p ?f ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f)›*) apply (metis Qp.r_zero (*‹?x ∈ carrier Q⇩p ⟹ ?x ⊕ 𝟬 = ?x›*) UPQ.ltrm_cfs (*‹?f ∈ carrier (UP Q⇩p) ⟹ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f) ?n = (if ?n = deg Q⇩p ?f then ?f (deg Q⇩p ?f) else 𝟬)›*) UPQ.cfs_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ ?f ?n ∈ carrier Q⇩p›*) UPQ.deg_leE (*‹⟦?p ∈ carrier (UP Q⇩p); deg Q⇩p ?p < ?k⟧ ⟹ ?p ?k = 𝟬›*)) (*top goal: ‹i < deg Q⇩p p ⟹ q i ∈ 𝒪⇩p› and 1 goal remains*) using q_def (*‹(q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p) ∧ deg Q⇩p q < deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∧ p = monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ⊕⇘UP Q⇩p⇙ q›*) by (metis (no_types, opaque_lifting) A( (*‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)›*) 2) A( (*‹∀i::nat. (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) i ∈ 𝒪⇩p›*) 4) UPQ.P.add.m_closed (*‹⟦(?x::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (?y::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)⟧ ⟹ ?x ⊕⇘UP Q⇩p⇙ ?y ∈ carrier (UP Q⇩p)›*) UPQ.coeff_of_sum_diff_degree0 (*‹⟦(?p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (?q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); deg Q⇩p ?q < (?n::nat)⟧ ⟹ (?p ⊕⇘UP Q⇩p⇙ ?q) ?n = ?p ?n›*) UPQ.deg_leE (*‹⟦(?p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); deg Q⇩p ?p < (?k::nat)⟧ ⟹ ?p ?k = 𝟬›*) UPQ.equal_deg_sum (*‹⟦(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (?g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); deg Q⇩p ?f < (?n::nat); deg Q⇩p ?g = ?n⟧ ⟹ deg Q⇩p (?f ⊕⇘UP Q⇩p⇙ ?g) = ?n›*) UPQ.equal_deg_sum' (*‹⟦(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (?g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); deg Q⇩p ?g < (?n::nat); deg Q⇩p ?f = ?n⟧ ⟹ deg Q⇩p (?f ⊕⇘UP Q⇩p⇙ ?g) = ?n›*) ‹⋀thesis. (⋀q. q ∈ carrier (UP Q⇩p) ∧ deg Q⇩p q < deg Q⇩p p ∧ p = up_ring.monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ⊕⇘UP Q⇩p⇙ q ⟹ thesis) ⟹ thesis› lessI (*‹(?n::nat) < Suc ?n›*) linorder_neqE_nat (*‹⟦(?x::nat) ≠ (?y::nat); ?x < ?y ⟹ ?R::bool; ?y < ?x ⟹ ?R⟧ ⟹ ?R›*)) qed have 2: "UPQ.lcf p ∈ 𝒪⇩p" using A(4) (*‹∀i. p i ∈ 𝒪⇩p›*) by blast have 3: "UPQ.ltrm p ∙ a = UPQ.lcf p ⊗ a[^] deg Q⇩p p" apply (rule UP_cring.to_fun_monom (*‹⟦UP_cring ?R; ?c ∈ carrier ?R; ?x ∈ carrier ?R⟧ ⟹ UP_cring.to_fun ?R (monom (UP ?R) ?c ?n) ?x = ?c ⊗⇘?R⇙ ?x [^]⇘?R⇙ ?n›*)) (*goal: ‹monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ a = p (deg Q⇩p p) ⊗ a [^] deg Q⇩p p›*) unfolding UP_cring_def (*goals: 1. ‹cring Q⇩p› 2. ‹p (deg Q⇩p p) ∈ carrier Q⇩p› 3. ‹a ∈ carrier Q⇩p›*) apply (simp add: UPQ.R_cring (*‹cring Q⇩p›*)) (*top goal: ‹cring Q⇩p› and 2 goals remain*) apply (simp add: A( (*‹p ∈ carrier (UP Q⇩p)›*) 2) UPQ.cfs_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ ?f ?n ∈ carrier Q⇩p›*)) (*top goal: ‹p (deg Q⇩p p) ∈ carrier Q⇩p› and 1 goal remains*) using assms(3) (*‹a ∈ 𝒪⇩p›*) val_ring_memE(2) (*‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) by blast have 4: "UPQ.ltrm p ∙ b = UPQ.lcf p ⊗ b[^] deg Q⇩p p" apply (rule UP_cring.to_fun_monom (*‹⟦UP_cring ?R; ?c ∈ carrier ?R; ?x ∈ carrier ?R⟧ ⟹ UP_cring.to_fun ?R (monom (UP ?R) ?c ?n) ?x = ?c ⊗⇘?R⇙ ?x [^]⇘?R⇙ ?n›*)) (*goal: ‹monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b = p (deg Q⇩p p) ⊗ b [^] deg Q⇩p p›*) unfolding UP_cring_def (*goals: 1. ‹cring Q⇩p› 2. ‹p (deg Q⇩p p) ∈ carrier Q⇩p› 3. ‹b ∈ carrier Q⇩p›*) apply (simp add: UPQ.R_cring (*‹cring Q⇩p›*)) (*top goal: ‹cring Q⇩p› and 2 goals remain*) apply (simp add: A( (*‹p ∈ carrier (UP Q⇩p)›*) 2) UPQ.cfs_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ ?f ?n ∈ carrier Q⇩p›*)) (*top goal: ‹p (deg Q⇩p p) ∈ carrier Q⇩p› and 1 goal remains*) using assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?i2 ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p› ‹b ∈ 𝒪⇩p› ‹to_Zp a k = to_Zp b k›*) val_ring_memE(2) (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) by blast have p_eq: "p = q ⊕⇘UP Q⇩p⇙ UPQ.ltrm p" using q_def (*‹(q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p) ∧ deg Q⇩p q < deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∧ p = monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ⊕⇘UP Q⇩p⇙ q›*) by (metis A( (*‹p ∈ carrier (UP Q⇩p)›*) 2) UPQ.ltrm_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f) ∈ carrier (UP Q⇩p)›*) UPQ.UP_a_comm (*‹⟦?p ∈ carrier (UP Q⇩p); ?q ∈ carrier (UP Q⇩p)⟧ ⟹ ?p ⊕⇘UP Q⇩p⇙ ?q = ?q ⊕⇘UP Q⇩p⇙ ?p›*)) have 5: "p ∙ a = q ∙ a ⊕ UPQ.lcf p ⊗ a[^] deg Q⇩p p" using assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?i2 ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p› ‹b ∈ 𝒪⇩p› ‹to_Zp a k = to_Zp b k›*) val_ring_memE(2) (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) p_eq (*‹p = q ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)›*) q_def (*‹q ∈ carrier (UP Q⇩p) ∧ deg Q⇩p q < deg Q⇩p p ∧ p = monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ⊕⇘UP Q⇩p⇙ q›*) UPQ.to_fun_plus[of q "UPQ.ltrm p" a] (*‹⟦q ∈ carrier (UP Q⇩p); monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∈ carrier (UP Q⇩p); a ∈ carrier Q⇩p⟧ ⟹ (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ⊕⇘UP Q⇩p⇙ q) ∙ a = monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ a ⊕ q ∙ a›*) by (metis "3" (*‹monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ a = p (deg Q⇩p p) ⊗ a [^] deg Q⇩p p›*) A( (*‹p ∈ carrier (UP Q⇩p)›*) 2) UPQ.ltrm_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f) ∈ carrier (UP Q⇩p)›*) UPQ.to_fun_plus (*‹⟦?g ∈ carrier (UP Q⇩p); ?f ∈ carrier (UP Q⇩p); ?x ∈ carrier Q⇩p⟧ ⟹ (?f ⊕⇘UP Q⇩p⇙ ?g) ∙ ?x = ?f ∙ ?x ⊕ ?g ∙ ?x›*)) have 6: "p ∙ b = q ∙ b ⊕ UPQ.lcf p ⊗ b[^] deg Q⇩p p" using assms (*‹g ∈ carrier (UP Q⇩p)› ‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (?i2::nat) ∈ 𝒪⇩p› ‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p› ‹(b::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p› ‹to_Zp a k = to_Zp b k›*) val_ring_memE(2) (*‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) p_eq (*‹p = q ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)›*) q_def (*‹q ∈ carrier (UP Q⇩p) ∧ deg Q⇩p q < deg Q⇩p p ∧ p = monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ⊕⇘UP Q⇩p⇙ q›*) UPQ.to_fun_plus[of q "UPQ.ltrm p" a] (*‹⟦q ∈ carrier (UP Q⇩p); monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∈ carrier (UP Q⇩p); a ∈ carrier Q⇩p⟧ ⟹ (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ⊕⇘UP Q⇩p⇙ q) ∙ a = monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ a ⊕ q ∙ a›*) by (metis "4" (*‹monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b = p (deg Q⇩p p) ⊗ b [^] deg Q⇩p p›*) A( (*‹p ∈ carrier (UP Q⇩p)›*) 2) UPQ.ltrm_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f) ∈ carrier (UP Q⇩p)›*) UPQ.to_fun_plus (*‹⟦?g ∈ carrier (UP Q⇩p); ?f ∈ carrier (UP Q⇩p); ?x ∈ carrier Q⇩p⟧ ⟹ (?f ⊕⇘UP Q⇩p⇙ ?g) ∙ ?x = ?f ∙ ?x ⊕ ?g ∙ ?x›*)) have 7: "UPQ.lcf p ⊗ b[^] deg Q⇩p p ∈ 𝒪⇩p" apply (rule val_ring_times_closed (*‹⟦?a ∈ 𝒪⇩p; ?b ∈ 𝒪⇩p⟧ ⟹ ?a ⊗ ?b ∈ 𝒪⇩p›*)) (*goal: ‹p (deg Q⇩p p) ⊗ b [^] deg Q⇩p p ∈ 𝒪⇩p›*) using "2" (*‹p (deg Q⇩p p) ∈ 𝒪⇩p›*) (*goals: 1. ‹p (deg Q⇩p p) ∈ 𝒪⇩p› 2. ‹b [^] deg Q⇩p p ∈ 𝒪⇩p› discuss goal 1*) apply linarith (*discuss goal 2*) apply (rule val_ring_nat_pow_closed (*‹?a ∈ 𝒪⇩p ⟹ ?a [^] ?n ∈ 𝒪⇩p›*)) (*goal: ‹(b::((nat ⇒ int) × (nat ⇒ int)) set) [^] deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p›*) apply (rule assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?i2 ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p› ‹b ∈ 𝒪⇩p› ‹to_Zp a k = to_Zp b k›*)) (*proven 2 subgoals*) . have 8: "UPQ.lcf p ⊗ a[^] deg Q⇩p p ∈ 𝒪⇩p" apply (rule val_ring_times_closed (*‹⟦?a ∈ 𝒪⇩p; ?b ∈ 𝒪⇩p⟧ ⟹ ?a ⊗ ?b ∈ 𝒪⇩p›*)) (*goal: ‹p (deg Q⇩p p) ⊗ a [^] deg Q⇩p p ∈ 𝒪⇩p›*) using "2" (*‹p (deg Q⇩p p) ∈ 𝒪⇩p›*) (*goals: 1. ‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p p) ∈ 𝒪⇩p› 2. ‹(a::((nat ⇒ int) × (nat ⇒ int)) set) [^] deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p› discuss goal 1*) apply linarith (*discuss goal 2*) apply (rule val_ring_nat_pow_closed (*‹?a ∈ 𝒪⇩p ⟹ ?a [^] ?n ∈ 𝒪⇩p›*)) (*goal: ‹(a::((nat ⇒ int) × (nat ⇒ int)) set) [^] deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p›*) apply (rule assms (*‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (?i2::nat) ∈ 𝒪⇩p› ‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p› ‹(b::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p› ‹to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set) (k::nat) = to_Zp (b::((nat ⇒ int) × (nat ⇒ int)) set) k›*)) (*proven 2 subgoals*) . have 9: "q ∙ a ∈ 𝒪⇩p" using q_def (*‹q ∈ carrier (UP Q⇩p) ∧ deg Q⇩p q < deg Q⇩p p ∧ p = monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ⊕⇘UP Q⇩p⇙ q›*) "1" (*‹∀i. q i ∈ 𝒪⇩p›*) assms(3) (*‹a ∈ 𝒪⇩p›*) val_ring_poly_eval (*‹⟦?f ∈ carrier (UP Q⇩p); ⋀i. ?f i ∈ 𝒪⇩p; ?x ∈ 𝒪⇩p⟧ ⟹ ?f ∙ ?x ∈ 𝒪⇩p›*) by blast have 10: "q ∙ b ∈ 𝒪⇩p" using q_def (*‹q ∈ carrier (UP Q⇩p) ∧ deg Q⇩p q < deg Q⇩p p ∧ p = monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ⊕⇘UP Q⇩p⇙ q›*) "1" (*‹∀i::nat. (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) i ∈ 𝒪⇩p›*) assms(4) (*‹b ∈ 𝒪⇩p›*) val_ring_poly_eval (*‹⟦?f ∈ carrier (UP Q⇩p); ⋀i. ?f i ∈ 𝒪⇩p; ?x ∈ 𝒪⇩p⟧ ⟹ ?f ∙ ?x ∈ 𝒪⇩p›*) by blast have 11: "to_Zp (p ∙ a) = to_Zp (q ∙ a) ⊕⇘Z⇩p⇙ to_Zp (UPQ.ltrm p ∙ a)" using "5" (*‹p ∙ a = q ∙ a ⊕ p (deg Q⇩p p) ⊗ a [^] deg Q⇩p p›*) "8" (*‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p p) ⊗ (a::((nat ⇒ int) × (nat ⇒ int)) set) [^] deg Q⇩p p ∈ 𝒪⇩p›*) "9" (*‹q ∙ a ∈ 𝒪⇩p›*) to_Zp_add (*‹⟦?a ∈ 𝒪⇩p; ?b ∈ 𝒪⇩p⟧ ⟹ to_Zp (?a ⊕ ?b) = to_Zp ?a ⊕⇘Z⇩p⇙ to_Zp ?b›*) "3" (*‹monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ a = p (deg Q⇩p p) ⊗ a [^] deg Q⇩p p›*) by presburger have 12: "to_Zp (p ∙ b) = to_Zp (q ∙ b) ⊕⇘Z⇩p⇙ to_Zp (UPQ.ltrm p ∙ b)" using "6" (*‹p ∙ b = q ∙ b ⊕ p (deg Q⇩p p) ⊗ b [^] deg Q⇩p p›*) "10" (*‹q ∙ b ∈ 𝒪⇩p›*) "7" (*‹p (deg Q⇩p p) ⊗ b [^] deg Q⇩p p ∈ 𝒪⇩p›*) to_Zp_add (*‹⟦?a ∈ 𝒪⇩p; ?b ∈ 𝒪⇩p⟧ ⟹ to_Zp (?a ⊕ ?b) = to_Zp ?a ⊕⇘Z⇩p⇙ to_Zp ?b›*) "4" (*‹monom (UP Q⇩p) ((p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p p)) (deg Q⇩p p) ∙ (b::((nat ⇒ int) × (nat ⇒ int)) set) = p (deg Q⇩p p) ⊗ b [^] deg Q⇩p p›*) by presburger have 13: "to_Zp (p ∙ a) k = to_Zp (q ∙ a) k ⊕⇘Zp_res_ring k⇙ to_Zp (UPQ.ltrm p ∙ a) k" unfolding "11" (*goal: ‹(to_Zp (q ∙ a) ⊕⇘Z⇩p⇙ to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ a)) k = to_Zp (q ∙ a) k ⊕⇘residue_ring (p ^ k)⇙ to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ a) k›*) using residue_of_sum (*‹(?a ⊕⇘Z⇩p⇙ ?b) ?k = ?a ?k ⊕⇘residue_ring (p ^ ?k)⇙ ?b ?k›*) by blast have 14: "to_Zp (p ∙ b) k = to_Zp (q ∙ b) k ⊕⇘Zp_res_ring k⇙ to_Zp (UPQ.ltrm p ∙ b) k" unfolding "12" (*goal: ‹(to_Zp (q ∙ b) ⊕⇘Z⇩p⇙ to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b)) k = to_Zp (q ∙ b) k ⊕⇘residue_ring (p ^ k)⇙ to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b) k›*) using residue_of_sum (*‹((?a::nat ⇒ int) ⊕⇘Z⇩p::(nat ⇒ int) ring⇙ (?b::nat ⇒ int)) (?k::nat) = ?a ?k ⊕⇘residue_ring ((p::int) ^ ?k)⇙ ?b ?k›*) by blast have 15: "to_Zp (UPQ.ltrm p ∙ a) k = to_Zp (UPQ.ltrm p ∙ b) k" proof (cases "k = 0") (*goals: 1. ‹k = 0 ⟹ to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ a) k = to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b) k› 2. ‹k ≠ 0 ⟹ to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ a) k = to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b) k›*) case True (*‹k = 0›*) have T0: "to_Zp (UPQ.ltrm p ∙ a) ∈ carrier Z⇩p" unfolding "3" (*goal: ‹to_Zp (p (deg Q⇩p p) ⊗ a [^] deg Q⇩p p) ∈ carrier Z⇩p›*) using "8" (*‹p (deg Q⇩p p) ⊗ a [^] deg Q⇩p p ∈ 𝒪⇩p›*) to_Zp_closed (*‹?a ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier Z⇩p›*) val_ring_memE(2) (*‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) by blast have T1: "to_Zp (UPQ.ltrm p ∙ b) ∈ carrier Z⇩p" unfolding "4" (*goal: ‹to_Zp (p (deg Q⇩p p) ⊗ b [^] deg Q⇩p p) ∈ carrier Z⇩p›*) using "7" (*‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p p) ⊗ (b::((nat ⇒ int) × (nat ⇒ int)) set) [^] deg Q⇩p p ∈ 𝒪⇩p›*) to_Zp_closed (*‹?a ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier Z⇩p›*) val_ring_memE(2) (*‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) by blast show "?thesis" (*goal: ‹to_Zp (monom (UP Q⇩p) ((p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p p)) (deg Q⇩p p) ∙ (a::((nat ⇒ int) × (nat ⇒ int)) set)) (k::nat) = to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ (b::((nat ⇒ int) × (nat ⇒ int)) set)) k›*) unfolding True (*goal: ‹to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ a) 0 = to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b) 0›*) using T0 (*‹to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ a) ∈ carrier Z⇩p›*) T1 (*‹to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b) ∈ carrier Z⇩p›*) padic_integers.p_res_ring_0 (*‹padic_integers ?p ⟹ carrier (residue_ring (?p ^ 0)) = {0}›*) by (metis p_res_ring_0' (*‹?x ∈ carrier (residue_ring (p ^ 0)) ⟹ ?x = 0›*) residues_closed (*‹?a ∈ carrier Z⇩p ⟹ ?a ?k ∈ carrier (residue_ring (p ^ ?k))›*)) next (*goal: ‹k ≠ 0 ⟹ to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ a) k = to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b) k›*) case False (*‹k ≠ 0›*) have k_pos: "k > 0" using False (*‹k ≠ 0›*) by presburger have 150: "to_Zp (p (deg Q⇩p p) ⊗ a [^] deg Q⇩p p) = to_Zp (p (deg Q⇩p p)) ⊗⇘Z⇩p⇙ to_Zp( a [^] deg Q⇩p p)" apply (rule to_Zp_mult (*‹⟦?a ∈ 𝒪⇩p; ?b ∈ 𝒪⇩p⟧ ⟹ to_Zp (?a ⊗ ?b) = to_Zp ?a ⊗⇘Z⇩p⇙ to_Zp ?b›*)) (*goal: ‹to_Zp (p (deg Q⇩p p) ⊗ a [^] deg Q⇩p p) = to_Zp (p (deg Q⇩p p)) ⊗⇘Z⇩p⇙ to_Zp (a [^] deg Q⇩p p)›*) using "2" (*‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p p) ∈ 𝒪⇩p›*) (*goals: 1. ‹p (deg Q⇩p p) ∈ 𝒪⇩p› 2. ‹a [^] deg Q⇩p p ∈ 𝒪⇩p› discuss goal 1*) apply blast (*discuss goal 2*) apply (rule val_ring_nat_pow_closed (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ ?a [^] (?n::nat) ∈ 𝒪⇩p›*)) (*goal: ‹a [^] deg Q⇩p p ∈ 𝒪⇩p›*) apply (rule assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?i2 ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p› ‹b ∈ 𝒪⇩p› ‹to_Zp a k = to_Zp b k›*)) (*proven 2 subgoals*) . have 151: "to_Zp (p (deg Q⇩p p) ⊗ b [^] deg Q⇩p p) = to_Zp (p (deg Q⇩p p)) ⊗⇘Z⇩p⇙ to_Zp( b [^] deg Q⇩p p)" apply (rule to_Zp_mult (*‹⟦?a ∈ 𝒪⇩p; ?b ∈ 𝒪⇩p⟧ ⟹ to_Zp (?a ⊗ ?b) = to_Zp ?a ⊗⇘Z⇩p⇙ to_Zp ?b›*)) (*goal: ‹to_Zp (p (deg Q⇩p p) ⊗ b [^] deg Q⇩p p) = to_Zp (p (deg Q⇩p p)) ⊗⇘Z⇩p⇙ to_Zp (b [^] deg Q⇩p p)›*) using "2" (*‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p p) ∈ 𝒪⇩p›*) (*goals: 1. ‹p (deg Q⇩p p) ∈ 𝒪⇩p› 2. ‹b [^] deg Q⇩p p ∈ 𝒪⇩p› discuss goal 1*) apply blast (*discuss goal 2*) apply (rule val_ring_nat_pow_closed (*‹?a ∈ 𝒪⇩p ⟹ ?a [^] ?n ∈ 𝒪⇩p›*)) (*goal: ‹b [^] deg Q⇩p p ∈ 𝒪⇩p›*) apply (rule assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?i2 ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p› ‹b ∈ 𝒪⇩p› ‹to_Zp a k = to_Zp b k›*)) (*proven 2 subgoals*) . have 152: "to_Zp (p (deg Q⇩p p) ⊗ a [^] deg Q⇩p p) k = to_Zp (p (deg Q⇩p p)) k ⊗⇘Zp_res_ring k⇙ to_Zp( a [^] deg Q⇩p p) k" unfolding "150" (*goal: ‹(to_Zp ((p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p p)) ⊗⇘Z⇩p::(nat ⇒ int) ring⇙ to_Zp ((a::((nat ⇒ int) × (nat ⇒ int)) set) [^] deg Q⇩p p)) (k::nat) = to_Zp (p (deg Q⇩p p)) k ⊗⇘residue_ring ((p::int) ^ k)⇙ to_Zp (a [^] deg Q⇩p p) k›*) using residue_of_prod (*‹(?a ⊗⇘Z⇩p⇙ ?b) ?k = ?a ?k ⊗⇘residue_ring (p ^ ?k)⇙ ?b ?k›*) by blast have 153: "to_Zp (p (deg Q⇩p p) ⊗ b [^] deg Q⇩p p) k = to_Zp (p (deg Q⇩p p)) k ⊗⇘Zp_res_ring k⇙ to_Zp( b [^] deg Q⇩p p) k" unfolding "151" (*goal: ‹(to_Zp (p (deg Q⇩p p)) ⊗⇘Z⇩p⇙ to_Zp (b [^] deg Q⇩p p)) k = to_Zp (p (deg Q⇩p p)) k ⊗⇘residue_ring (p ^ k)⇙ to_Zp (b [^] deg Q⇩p p) k›*) using residue_of_prod (*‹(?a ⊗⇘Z⇩p⇙ ?b) ?k = ?a ?k ⊗⇘residue_ring (p ^ ?k)⇙ ?b ?k›*) by blast have 154: "to_Zp( a [^] deg Q⇩p p) k = to_Zp a k [^]⇘Zp_res_ring k⇙ deg Q⇩p p" proof (-) (*goal: ‹to_Zp (a [^] deg Q⇩p p) k = to_Zp a k [^]⇘residue_ring (p ^ k)⇙ deg Q⇩p p›*) have 01: "⋀m::nat. to_Zp (a[^]m) k = to_Zp a k [^]⇘Zp_res_ring k⇙ m" proof (-) (*goal: ‹⋀m::nat. to_Zp ((a::((nat ⇒ int) × (nat ⇒ int)) set) [^] m) (k::nat) = to_Zp a k [^]⇘residue_ring ((p::int) ^ k)⇙ m›*) fix m :: nat show "to_Zp (a [^] m) k = to_Zp a k [^]⇘Zp_res_ring k⇙ m" proof (-) (*goal: ‹to_Zp (a [^] m) k = to_Zp a k [^]⇘residue_ring (p ^ k)⇙ m›*) have 00: "to_Zp (a[^]m) = to_Zp a [^]⇘Z⇩p⇙ m" using assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?i2 ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p› ‹(b::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p› ‹to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set) (k::nat) = to_Zp (b::((nat ⇒ int) × (nat ⇒ int)) set) k›*) to_Zp_nat_pow[of a "m"] (*‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ to_Zp (a [^] (m::nat)) = to_Zp a [^]⇘Z⇩p::(nat ⇒ int) ring⇙ m›*) by blast have 01: "to_Zp a ∈ carrier Z⇩p" using assms (*‹g ∈ carrier (UP Q⇩p)› ‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (?i2::nat) ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p› ‹b ∈ 𝒪⇩p› ‹to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set) (k::nat) = to_Zp (b::((nat ⇒ int) × (nat ⇒ int)) set) k›*) to_Zp_closed (*‹?a ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier Z⇩p›*) val_ring_memE(2) (*‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) by blast have 02: "to_Zp a k ∈ carrier (Zp_res_ring k)" using "01" (*‹to_Zp a ∈ carrier Z⇩p›*) residues_closed (*‹?a ∈ carrier Z⇩p ⟹ ?a ?k ∈ carrier (residue_ring (p ^ ?k))›*) by blast have 03: "cring (Zp_res_ring k)" using k_pos (*‹(0::nat) < (k::nat)›*) padic_integers.R_cring (*‹⟦padic_integers ?p; 0 < ?m⟧ ⟹ cring (residue_ring (?p ^ ?m))›*) padic_integers_axioms (*‹padic_integers p›*) by blast have 01: "(to_Zp a [^]⇘Z⇩p⇙ m) k = (to_Zp a) k [^]⇘Zp_res_ring k⇙ m" apply (induction m) (*goal: ‹(to_Zp a [^]⇘Z⇩p⇙ m) k = to_Zp a k [^]⇘residue_ring (p ^ k)⇙ m›*) using "01" (*‹to_Zp a ∈ carrier Z⇩p›*) "02" (*‹to_Zp a k ∈ carrier (residue_ring (p ^ k))›*) apply (metis Group.nat_pow_0 (*‹?x [^]⇘?G⇙ 0 = 𝟭⇘?G⇙›*) k_pos (*‹0 < k›*) residue_of_one( (*‹0 < ?k ⟹ 𝟭⇘Z⇩p⇙ ?k = 𝟭⇘residue_ring (p ^ ?k)⇙›*) 1)) (*top goal: ‹(to_Zp a [^]⇘Z⇩p⇙ 0) k = to_Zp a k [^]⇘residue_ring (p ^ k)⇙ 0› and 1 goal remains*) using residue_of_prod[of "to_Zp a [^]⇘Z⇩p⇙ m" "to_Zp a" k] (*‹(to_Zp a [^]⇘Z⇩p⇙ m ⊗⇘Z⇩p⇙ to_Zp a) k = (to_Zp a [^]⇘Z⇩p⇙ m) k ⊗⇘residue_ring (p ^ k)⇙ to_Zp a k›*) "01" (*‹to_Zp a ∈ carrier Z⇩p›*) "02" (*‹to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set) (k::nat) ∈ carrier (residue_ring ((p::int) ^ k))›*) "03" (*‹cring (residue_ring (p ^ k))›*) proof (-) (*goal: ‹⋀ma. ⟦(to_Zp a [^]⇘Z⇩p⇙ ma) k = to_Zp a k [^]⇘residue_ring (p ^ k)⇙ ma; (to_Zp a [^]⇘Z⇩p⇙ m ⊗⇘Z⇩p⇙ to_Zp a) k = (to_Zp a [^]⇘Z⇩p⇙ m) k ⊗⇘residue_ring (p ^ k)⇙ to_Zp a k; to_Zp a ∈ carrier Z⇩p; to_Zp a k ∈ carrier (residue_ring (p ^ k)); cring (residue_ring (p ^ k))⟧ ⟹ (to_Zp a [^]⇘Z⇩p⇙ Suc ma) k = to_Zp a k [^]⇘residue_ring (p ^ k)⇙ Suc ma›*) fix ma :: nat assume "(to_Zp a [^]⇘Z⇩p⇙ ma) k = to_Zp a k [^]⇘Zp_res_ring k⇙ ma" (*‹(to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set) [^]⇘Z⇩p::(nat ⇒ int) ring⇙ (ma::nat)) (k::nat) = to_Zp a k [^]⇘residue_ring ((p::int) ^ k)⇙ ma›*) then show "(to_Zp a [^]⇘Z⇩p⇙ Suc ma) k = to_Zp a k [^]⇘Zp_res_ring k⇙ Suc ma" by (metis (no_types) Group.nat_pow_Suc (*‹?x [^]⇘?G⇙ Suc ?n = ?x [^]⇘?G⇙ ?n ⊗⇘?G⇙ ?x›*) residue_of_prod (*‹(?a ⊗⇘Z⇩p⇙ ?b) ?k = ?a ?k ⊗⇘residue_ring (p ^ ?k)⇙ ?b ?k›*)) qed show "?thesis" (*goal: ‹to_Zp (a [^] m) k = to_Zp a k [^]⇘residue_ring (p ^ k)⇙ m›*) unfolding "00" "01" (*goal: ‹to_Zp a k [^]⇘residue_ring (p ^ k)⇙ m = to_Zp a k [^]⇘residue_ring (p ^ k)⇙ m›*) by blast qed qed thus "?thesis" (*goal: ‹to_Zp ((a::((nat ⇒ int) × (nat ⇒ int)) set) [^] deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)) (k::nat) = to_Zp a k [^]⇘residue_ring ((p::int) ^ k)⇙ deg Q⇩p p›*) by blast qed have 155: "to_Zp( b [^] deg Q⇩p p) k = to_Zp b k [^]⇘Zp_res_ring k⇙ deg Q⇩p p" using assms (*‹g ∈ carrier (UP Q⇩p)› ‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (?i2::nat) ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p› ‹b ∈ 𝒪⇩p› ‹to_Zp a k = to_Zp b k›*) by (metis "154" (*‹to_Zp (a [^] deg Q⇩p p) k = to_Zp a k [^]⇘residue_ring (p ^ k)⇙ deg Q⇩p p›*) to_Zp_res_of_pow (*‹⟦?a ∈ 𝒪⇩p; ?b ∈ 𝒪⇩p; to_Zp ?a ?n = to_Zp ?b ?n⟧ ⟹ to_Zp (?a [^] ?k) ?n = to_Zp (?b [^] ?k) ?n›*)) show "?thesis" (*goal: ‹to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ a) k = to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b) k›*) unfolding "3" "4" "152" "153" "154" "155" assms (*goal: ‹to_Zp (p (deg Q⇩p p)) k ⊗⇘residue_ring (p ^ k)⇙ to_Zp b k [^]⇘residue_ring (p ^ k)⇙ deg Q⇩p p = to_Zp (p (deg Q⇩p p)) k ⊗⇘residue_ring (p ^ k)⇙ to_Zp b k [^]⇘residue_ring (p ^ k)⇙ deg Q⇩p p›*) by blast qed show "to_Zp (p ∙ a) k = to_Zp (p ∙ b) k" unfolding "13" "14" "15" (*goal: ‹to_Zp (q ∙ a) k ⊕⇘residue_ring (p ^ k)⇙ to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b) k = to_Zp (q ∙ b) k ⊕⇘residue_ring (p ^ k)⇙ to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b) k›*) using A (*‹⟦?q2 ∈ carrier (UP Q⇩p); deg Q⇩p ?q2 < deg Q⇩p p⟧ ⟹ (∀i. ?q2 i ∈ 𝒪⇩p) ⟶ to_Zp (?q2 ∙ a) k = to_Zp (?q2 ∙ b) k› ‹p ∈ carrier (UP Q⇩p)› ‹0 < deg Q⇩p p› ‹∀i. p i ∈ 𝒪⇩p›*) "1" (*‹∀i::nat. (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) i ∈ 𝒪⇩p›*) q_def (*‹(q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p) ∧ deg Q⇩p q < deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∧ p = monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ⊕⇘UP Q⇩p⇙ q›*) by presburger qed qed thus "?thesis" (*goal: ‹to_Zp (g ∙ a) k = to_Zp (g ∙ b) k›*) using assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?i2 ∈ 𝒪⇩p› ‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p› ‹(b::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p› ‹to_Zp a k = to_Zp b k›*) by blast qed lemma to_Zp_poly_eval: assumes "g ∈ carrier Q⇩p_x" assumes "gauss_norm g ≥ 0" assumes "a ∈ 𝒪⇩p" shows "to_Zp (to_function Q⇩p g a) = to_function Z⇩p (to_Zp_poly g) (to_Zp a)" proof (-) (*goal: ‹to_Zp (to_function Q⇩p (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (a::((nat ⇒ int) × (nat ⇒ int)) set)) = to_function (Z⇩p::(nat ⇒ int) ring) (to_Zp_poly g) (to_Zp a)›*) obtain h where h_def: "h = to_Zp_poly g" (*goal: ‹(⋀h. h = to_Zp_poly g ⟹ thesis) ⟹ thesis›*) by blast obtain b where b_def: "b = to_Zp a" (*goal: ‹(⋀b. b = to_Zp a ⟹ thesis) ⟹ thesis›*) by blast have h_poly_inc: "poly_inc h = g" unfolding h_def (*goal: ‹poly_inc (to_Zp_poly (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)) = g›*) using assms (*‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹0 ≤ gauss_norm g› ‹a ∈ 𝒪⇩p›*) by (simp add: poly_inc_inverse_left (*‹⟦(?g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (0::eint) ≤ gauss_norm ?g⟧ ⟹ poly_inc (to_Zp_poly ?g) = ?g›*)) have b_inc: "ι b = a" unfolding b_def (*goal: ‹ι (to_Zp a) = a›*) using assms (*‹g ∈ carrier (UP Q⇩p)› ‹(0::eint) ≤ gauss_norm (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)› ‹a ∈ 𝒪⇩p›*) by (simp add: to_Zp_inc (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ (ι::(nat ⇒ int) ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (to_Zp ?a) = ?a›*)) have h_closed: "h ∈ carrier (UP Z⇩p)" unfolding h_def (*goal: ‹to_Zp_poly g ∈ carrier (UP Z⇩p)›*) using assms (*‹g ∈ carrier (UP Q⇩p)› ‹0 ≤ gauss_norm g› ‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p›*) by (simp add: to_Zp_poly_closed (*‹⟦?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g⟧ ⟹ to_Zp_poly ?g ∈ carrier (UP Z⇩p)›*)) have b_closed: "b ∈ carrier Z⇩p" unfolding b_def (*goal: ‹to_Zp a ∈ carrier Z⇩p›*) using assms (*‹g ∈ carrier (UP Q⇩p)› ‹0 ≤ gauss_norm g› ‹a ∈ 𝒪⇩p›*) by (simp add: to_Zp_closed (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier (Z⇩p::(nat ⇒ int) ring)›*) val_ring_memE (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ (0::eint) ≤ val ?a› ‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*)) have 0: "to_function Q⇩p (poly_inc h) (ι b) = ι (to_function Z⇩p h b)" apply (rule poly_inc_eval (*‹⟦?g ∈ carrier (UP Z⇩p); ?a ∈ carrier Z⇩p⟧ ⟹ to_function Q⇩p (poly_inc ?g) (ι ?a) = ι (to_function Z⇩p ?g ?a)›*)) (*goal: ‹to_function Q⇩p (poly_inc h) (ι b) = ι (to_function Z⇩p h b)›*) using h_def (*‹(h::nat ⇒ nat ⇒ int) = to_Zp_poly (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)›*) assms (*‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹0 ≤ gauss_norm g› ‹a ∈ 𝒪⇩p›*) apply (simp add: to_Zp_poly_closed (*‹⟦?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g⟧ ⟹ to_Zp_poly ?g ∈ carrier (UP Z⇩p)›*); fail) (*top goal: ‹h ∈ carrier (UP Z⇩p)› and 1 goal remains*) unfolding b_def (*goal: ‹to_Zp a ∈ carrier Z⇩p›*) using assms (*‹g ∈ carrier (UP Q⇩p)› ‹0 ≤ gauss_norm g› ‹a ∈ 𝒪⇩p›*) by (simp add: to_Zp_closed (*‹?a ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier Z⇩p›*) val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*)) have 1: "to_Zp (to_function Q⇩p (poly_inc h) (ι b)) = to_function Z⇩p h b" unfolding "0" (*goal: ‹to_Zp (ι (to_function Z⇩p h b)) = to_function Z⇩p h b›*) using h_closed (*‹h ∈ carrier (UP Z⇩p)›*) b_closed (*‹b ∈ carrier Z⇩p›*) Zp.to_fun_closed (*‹⟦?f ∈ carrier (UP Z⇩p); ?x ∈ carrier Z⇩p⟧ ⟹ Zp.to_fun ?f ?x ∈ carrier Z⇩p›*) Zp.to_fun_def (*‹Zp.to_fun ?f ≡ to_function Z⇩p ?f›*) inc_to_Zp (*‹?b ∈ carrier Z⇩p ⟹ to_Zp (ι ?b) = ?b›*) by auto show "?thesis" (*goal: ‹to_Zp (to_function Q⇩p g a) = to_function Z⇩p (to_Zp_poly g) (to_Zp a)›*) using "1" (*‹to_Zp (to_function Q⇩p (poly_inc (h::nat ⇒ nat ⇒ int)) ((ι::(nat ⇒ int) ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (b::nat ⇒ int))) = to_function (Z⇩p::(nat ⇒ int) ring) h b›*) unfolding h_poly_inc b_inc (*goal: ‹to_Zp (to_function Q⇩p g a) = to_function Z⇩p (to_Zp_poly g) (to_Zp a)›*) unfolding h_def b_def (*goal: ‹to_Zp (to_function Q⇩p g a) = to_function Z⇩p (to_Zp_poly g) (to_Zp a)›*) by blast qed lemma poly_eval_equal_val: assumes "g ∈ carrier (UP Q⇩p)" assumes "⋀x. g x ∈ 𝒪⇩p" assumes "a ∈ 𝒪⇩p" assumes "b ∈ 𝒪⇩p" assumes "val (g ∙ a) < eint n" assumes "to_Zp a n = to_Zp b n" shows "val (g ∙ b) = val (g ∙ a)" proof (-) (*goal: ‹val (g ∙ b) = val (g ∙ a)›*) have "(∀x. g x ∈ 𝒪⇩p) ⟶ to_Zp (g ∙ b) n = to_Zp (g ∙ a) n" proof (rule poly_induct[of g] (*‹⟦g ∈ carrier (UP Q⇩p); ⋀p. ⟦p ∈ carrier (UP Q⇩p); deg Q⇩p p = 0⟧ ⟹ ?Q p; ⋀p. ⟦⋀q. ⟦q ∈ carrier (UP Q⇩p); deg Q⇩p q < deg Q⇩p p⟧ ⟹ ?Q q; p ∈ carrier (UP Q⇩p); 0 < deg Q⇩p p⟧ ⟹ ?Q p⟧ ⟹ ?Q g›*)) (*goals: 1. ‹g ∈ carrier (UP Q⇩p)› 2. ‹⋀p. ⟦p ∈ carrier (UP Q⇩p); deg Q⇩p p = 0⟧ ⟹ (∀x. p x ∈ 𝒪⇩p) ⟶ to_Zp (p ∙ b) n = to_Zp (p ∙ a) n› 3. ‹⋀p. ⟦⋀q. ⟦q ∈ carrier (UP Q⇩p); deg Q⇩p q < deg Q⇩p p⟧ ⟹ (∀x. q x ∈ 𝒪⇩p) ⟶ to_Zp (q ∙ b) n = to_Zp (q ∙ a) n; p ∈ carrier (UP Q⇩p); 0 < deg Q⇩p p⟧ ⟹ (∀x. p x ∈ 𝒪⇩p) ⟶ to_Zp (p ∙ b) n = to_Zp (p ∙ a) n›*) show "g ∈ carrier (UP Q⇩p)" by (simp add: assms( (*‹g ∈ carrier (UP Q⇩p)›*) 1)) show "⋀p. p ∈ carrier (UP Q⇩p) ⟹ deg Q⇩p p = 0 ⟹ (∀x. p x ∈ 𝒪⇩p) ⟶ to_Zp (p ∙ b) n = to_Zp (p ∙ a) n" proof (standard) (*goal: ‹⋀p. ⟦p ∈ carrier (UP Q⇩p); deg Q⇩p p = 0; ∀x. p x ∈ 𝒪⇩p⟧ ⟹ to_Zp (p ∙ b) n = to_Zp (p ∙ a) n›*) fix p assume A: "p ∈ carrier (UP Q⇩p)" " deg Q⇩p p = 0 " "∀x. p x ∈ 𝒪⇩p " (*‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) = (0::nat)› ‹∀x::nat. (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) x ∈ 𝒪⇩p›*) show "to_Zp (p ∙ b) n = to_Zp (p ∙ a) n" using A (*‹p ∈ carrier (UP Q⇩p)› ‹deg Q⇩p p = 0› ‹∀x. p x ∈ 𝒪⇩p›*) by (metis val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) UPQ.to_fun_ctrm (*‹⟦?f ∈ carrier (UP Q⇩p); ?b ∈ carrier Q⇩p⟧ ⟹ monom (UP Q⇩p) (?f 0) 0 ∙ ?b = ?f 0›*) UPQ.trms_of_deg_leq_0 (*‹?f ∈ carrier (UP Q⇩p) ⟹ UPQ.trms_of_deg_leq 0 ?f = monom (UP Q⇩p) (?f 0) 0›*) UPQ.trms_of_deg_leq_degree_f (*‹?f ∈ carrier (UP Q⇩p) ⟹ UPQ.trms_of_deg_leq (deg Q⇩p ?f) ?f = ?f›*) assms( (*‹a ∈ 𝒪⇩p›*) 3) assms( (*‹b ∈ 𝒪⇩p›*) 4)) qed show "⋀p. (⋀q. q ∈ carrier (UP Q⇩p) ⟹ deg Q⇩p q < deg Q⇩p p ⟹ (∀x. q x ∈ 𝒪⇩p) ⟶ to_Zp (q ∙ b) n = to_Zp (q ∙ a) n) ⟹ p ∈ carrier (UP Q⇩p) ⟹ 0 < deg Q⇩p p ⟹ (∀x. p x ∈ 𝒪⇩p) ⟶ to_Zp (p ∙ b) n = to_Zp (p ∙ a) n" proof (standard) (*goal: ‹⋀p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set. ⟦⋀q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set. ⟦q ∈ carrier (UP Q⇩p); deg Q⇩p q < deg Q⇩p p⟧ ⟹ (∀x::nat. q x ∈ 𝒪⇩p) ⟶ to_Zp (q ∙ (b::((nat ⇒ int) × (nat ⇒ int)) set)) (n::nat) = to_Zp (q ∙ (a::((nat ⇒ int) × (nat ⇒ int)) set)) n; p ∈ carrier (UP Q⇩p); (0::nat) < deg Q⇩p p; ∀x::nat. p x ∈ 𝒪⇩p⟧ ⟹ to_Zp (p ∙ b) n = to_Zp (p ∙ a) n›*) fix p assume IH: "(⋀q. q ∈ carrier (UP Q⇩p) ⟹ deg Q⇩p q < deg Q⇩p p ⟹ (∀x. q x ∈ 𝒪⇩p) ⟶ to_Zp (q ∙ b) n = to_Zp (q ∙ a) n)" (*‹⟦(?q2::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); deg Q⇩p ?q2 < deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)⟧ ⟹ (∀x::nat. ?q2 x ∈ 𝒪⇩p) ⟶ to_Zp (?q2 ∙ (b::((nat ⇒ int) × (nat ⇒ int)) set)) (n::nat) = to_Zp (?q2 ∙ (a::((nat ⇒ int) × (nat ⇒ int)) set)) n›*) assume A: "p ∈ carrier (UP Q⇩p)" "0 < deg Q⇩p p" "∀x. p x ∈ 𝒪⇩p" (*‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹(0::nat) < deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)› ‹∀x::nat. (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) x ∈ 𝒪⇩p›*) show "to_Zp (p ∙ b) n = to_Zp (p ∙ a) n" proof (-) (*goal: ‹to_Zp (p ∙ b) n = to_Zp (p ∙ a) n›*) obtain q where q_def: "q ∈ carrier (UP Q⇩p) ∧ deg Q⇩p q < deg Q⇩p p ∧ p = q ⊕⇘UP Q⇩p⇙ ltrm p" (*goal: ‹(⋀q. q ∈ carrier (UP Q⇩p) ∧ deg Q⇩p q < deg Q⇩p p ∧ p = q ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ⟹ thesis) ⟹ thesis›*) using A (*‹p ∈ carrier (UP Q⇩p)› ‹0 < deg Q⇩p p› ‹∀x. p x ∈ 𝒪⇩p›*) by (meson UPQ.ltrm_decomp (*‹⟦?f ∈ carrier (UP Q⇩p); 0 < deg Q⇩p ?f; ⋀g. g ∈ carrier (UP Q⇩p) ∧ ?f = g ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f) ∧ deg Q⇩p g < deg Q⇩p ?f ⟹ ?thesis⟧ ⟹ ?thesis›*)) have p_eq: "p = q ⊕⇘UP Q⇩p⇙ ltrm p" using q_def (*‹q ∈ carrier (UP Q⇩p) ∧ deg Q⇩p q < deg Q⇩p p ∧ p = q ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)›*) by blast have "∀x. q x ∈ 𝒪⇩p" proof (standard) (*goal: ‹⋀x. q x ∈ 𝒪⇩p›*) fix x have px: "p x = (q ⊕⇘UP Q⇩p⇙ ltrm p) x" using p_eq (*‹p = q ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)›*) by simp show "q x ∈ 𝒪⇩p" proof (cases "x ≤ deg Q⇩p q") (*goals: 1. ‹x ≤ deg Q⇩p q ⟹ q x ∈ 𝒪⇩p› 2. ‹¬ x ≤ deg Q⇩p q ⟹ q x ∈ 𝒪⇩p›*) case True (*‹(x::nat) ≤ deg Q⇩p (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)›*) then have "p x = q x" unfolding px (*goal: ‹((q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) ((p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p p)) (deg Q⇩p p)) (x::nat) = q x›*) using q_def (*‹q ∈ carrier (UP Q⇩p) ∧ deg Q⇩p q < deg Q⇩p p ∧ p = q ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)›*) A (*‹p ∈ carrier (UP Q⇩p)› ‹0 < deg Q⇩p p› ‹∀x. p x ∈ 𝒪⇩p›*) by (smt UPQ.ltrm_closed (*‹(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p) ⟹ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f) ∈ carrier (UP Q⇩p)›*) UPQ.P.add.right_cancel (*‹⟦(?x::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (?y::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (?z::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)⟧ ⟹ (?y ⊕⇘UP Q⇩p⇙ ?x = ?z ⊕⇘UP Q⇩p⇙ ?x) = (?y = ?z)›*) UPQ.coeff_of_sum_diff_degree0 (*‹⟦(?p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (?q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); deg Q⇩p ?q < (?n::nat)⟧ ⟹ (?p ⊕⇘UP Q⇩p⇙ ?q) ?n = ?p ?n›*) UPQ.deg_ltrm (*‹(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p) ⟹ deg Q⇩p (monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f)) = deg Q⇩p ?f›*) UPQ.trunc_cfs (*‹⟦(?p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (?n::nat) < deg Q⇩p ?p⟧ ⟹ Cring_Poly.truncate Q⇩p ?p ?n = ?p ?n›*) UPQ.trunc_closed (*‹(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p) ⟹ Cring_Poly.truncate Q⇩p ?f ∈ carrier (UP Q⇩p)›*) UPQ.trunc_simps( (*‹(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p) ⟹ ?f = Cring_Poly.truncate Q⇩p ?f ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f)›*) 1) less_eq_Suc_le (*‹((?n::nat) < (?m::nat)) = (Suc ?n ≤ ?m)›*) nat_neq_iff (*‹((?m::nat) ≠ (?n::nat)) = (?m < ?n ∨ ?n < ?m)›*) not_less_eq_eq (*‹(¬ (?m::nat) ≤ (?n::nat)) = (Suc ?n ≤ ?m)›*)) then show "?thesis" (*goal: ‹(q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (x::nat) ∈ 𝒪⇩p›*) using A (*‹p ∈ carrier (UP Q⇩p)› ‹0 < deg Q⇩p p› ‹∀x::nat. (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) x ∈ 𝒪⇩p›*) by blast next (*goal: ‹¬ x ≤ deg Q⇩p q ⟹ q x ∈ 𝒪⇩p›*) case False (*‹¬ (x::nat) ≤ deg Q⇩p (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)›*) then show "?thesis" (*goal: ‹q x ∈ 𝒪⇩p›*) using q_def (*‹q ∈ carrier (UP Q⇩p) ∧ deg Q⇩p q < deg Q⇩p p ∧ p = q ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)›*) UPQ.deg_eqI (*‹⟦(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); deg Q⇩p ?f ≤ (?n::nat); ?f ?n ≠ 𝟬⟧ ⟹ deg Q⇩p ?f = ?n›*) eq_imp_le (*‹?m = ?n ⟹ ?m ≤ ?n›*) nat_le_linear (*‹?m ≤ ?n ∨ ?n ≤ ?m›*) zero_in_val_ring (*‹𝟬 ∈ 𝒪⇩p›*) by (metis (no_types, lifting) UPQ.coeff_simp (*‹?f ∈ carrier (UP Q⇩p) ⟹ coeff (UP Q⇩p) ?f = ?f›*) UPQ.deg_belowI (*‹⟦?n ≠ 0 ⟹ coeff (UP Q⇩p) ?p ?n ≠ 𝟬; ?p ∈ carrier (UP Q⇩p)⟧ ⟹ ?n ≤ deg Q⇩p ?p›*)) qed qed then have 0: " to_Zp (q ∙ b) n = to_Zp (q ∙ a) n" using IH (*‹⟦?q2 ∈ carrier (UP Q⇩p); deg Q⇩p ?q2 < deg Q⇩p p⟧ ⟹ (∀x. ?q2 x ∈ 𝒪⇩p) ⟶ to_Zp (?q2 ∙ b) n = to_Zp (?q2 ∙ a) n›*) q_def (*‹(q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p) ∧ deg Q⇩p q < deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∧ p = q ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)›*) by blast have 1: "to_Zp (ltrm p ∙ b) n = to_Zp (ltrm p ∙ a) n" proof (-) (*goal: ‹to_Zp (monom (UP Q⇩p) ((p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p p)) (deg Q⇩p p) ∙ (b::((nat ⇒ int) × (nat ⇒ int)) set)) (n::nat) = to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ (a::((nat ⇒ int) × (nat ⇒ int)) set)) n›*) have 10: "(ltrm p ∙ b) = (p (deg Q⇩p p)) ⊗ b[^] (deg Q⇩p p)" using assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?x2 ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p› ‹b ∈ 𝒪⇩p› ‹val (g ∙ a) < eint (int n)› ‹to_Zp a n = to_Zp b n›*) A (*‹p ∈ carrier (UP Q⇩p)› ‹0 < deg Q⇩p p› ‹∀x. p x ∈ 𝒪⇩p›*) by (meson val_ring_memE (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ (0::eint) ≤ val ?a› ‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) UPQ.to_fun_monom (*‹⟦(?c::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p; (?x::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p⟧ ⟹ monom (UP Q⇩p) ?c (?n::nat) ∙ ?x = ?c ⊗ ?x [^] ?n›*)) have 11: "(ltrm p ∙ a) = (p (deg Q⇩p p)) ⊗ a[^] (deg Q⇩p p)" using assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?x2 ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p› ‹(b::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p› ‹val ((g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ (a::((nat ⇒ int) × (nat ⇒ int)) set)) < eint (int (n::nat))› ‹to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set) (n::nat) = to_Zp (b::((nat ⇒ int) × (nat ⇒ int)) set) n›*) A (*‹p ∈ carrier (UP Q⇩p)› ‹0 < deg Q⇩p p› ‹∀x. p x ∈ 𝒪⇩p›*) by (meson val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) UPQ.to_fun_monom (*‹⟦?c ∈ carrier Q⇩p; ?x ∈ carrier Q⇩p⟧ ⟹ monom (UP Q⇩p) ?c ?n ∙ ?x = ?c ⊗ ?x [^] ?n›*)) have 12: "to_Zp (b[^] (deg Q⇩p p)) n = to_Zp (a[^] (deg Q⇩p p)) n" using to_Zp_res_of_pow (*‹⟦?a ∈ 𝒪⇩p; ?b ∈ 𝒪⇩p; to_Zp ?a ?n = to_Zp ?b ?n⟧ ⟹ to_Zp (?a [^] ?k) ?n = to_Zp (?b [^] ?k) ?n›*) assms (*‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹g ?x2 ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p› ‹(b::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p› ‹val (g ∙ a) < eint (int n)› ‹to_Zp a n = to_Zp b n›*) by metis have 13: "p (deg Q⇩p p) ∈ 𝒪⇩p" using A(3) (*‹∀x. p x ∈ 𝒪⇩p›*) by blast have 14: "b[^] (deg Q⇩p p) ∈ 𝒪⇩p" using assms(4) (*‹b ∈ 𝒪⇩p›*) val_ring_nat_pow_closed (*‹?a ∈ 𝒪⇩p ⟹ ?a [^] ?n ∈ 𝒪⇩p›*) by blast have 15: "a[^] (deg Q⇩p p) ∈ 𝒪⇩p" using assms(3) (*‹a ∈ 𝒪⇩p›*) val_ring_nat_pow_closed (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ ?a [^] (?n::nat) ∈ 𝒪⇩p›*) by blast have 16: "(ltrm p ∙ b) ∈ 𝒪⇩p" by (simp add: "10" (*‹monom (UP Q⇩p) ((p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p p)) (deg Q⇩p p) ∙ (b::((nat ⇒ int) × (nat ⇒ int)) set) = p (deg Q⇩p p) ⊗ b [^] deg Q⇩p p›*) "13" (*‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p p) ∈ 𝒪⇩p›*) "14" (*‹(b::((nat ⇒ int) × (nat ⇒ int)) set) [^] deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p›*) val_ring_times_closed (*‹⟦(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p; (?b::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p⟧ ⟹ ?a ⊗ ?b ∈ 𝒪⇩p›*)) have 17: "to_Zp (ltrm p ∙ b) n = to_Zp (p (deg Q⇩p p)) n ⊗⇘Zp_res_ring n⇙ to_Zp (b[^] (deg Q⇩p p)) n" using "10" (*‹monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b = p (deg Q⇩p p) ⊗ b [^] deg Q⇩p p›*) "13" (*‹p (deg Q⇩p p) ∈ 𝒪⇩p›*) "14" (*‹b [^] deg Q⇩p p ∈ 𝒪⇩p›*) "15" (*‹a [^] deg Q⇩p p ∈ 𝒪⇩p›*) "16" (*‹monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b ∈ 𝒪⇩p›*) assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?x2 ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p› ‹b ∈ 𝒪⇩p› ‹val (g ∙ a) < eint (int n)› ‹to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set) (n::nat) = to_Zp (b::((nat ⇒ int) × (nat ⇒ int)) set) n›*) residue_of_prod (*‹(?a ⊗⇘Z⇩p⇙ ?b) ?k = ?a ?k ⊗⇘residue_ring (p ^ ?k)⇙ ?b ?k›*) to_Zp_mult (*‹⟦?a ∈ 𝒪⇩p; ?b ∈ 𝒪⇩p⟧ ⟹ to_Zp (?a ⊗ ?b) = to_Zp ?a ⊗⇘Z⇩p⇙ to_Zp ?b›*) by presburger have 18: "(ltrm p ∙ a) ∈ 𝒪⇩p" by (simp add: "11" (*‹monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ a = p (deg Q⇩p p) ⊗ a [^] deg Q⇩p p›*) "15" (*‹a [^] deg Q⇩p p ∈ 𝒪⇩p›*) A( (*‹∀x. p x ∈ 𝒪⇩p›*) 3) val_ring_times_closed (*‹⟦?a ∈ 𝒪⇩p; ?b ∈ 𝒪⇩p⟧ ⟹ ?a ⊗ ?b ∈ 𝒪⇩p›*)) have 19: "to_Zp (ltrm p ∙ a) n = to_Zp (p (deg Q⇩p p)) n ⊗⇘Zp_res_ring n⇙ to_Zp (a[^] (deg Q⇩p p)) n" using "10" (*‹monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b = p (deg Q⇩p p) ⊗ b [^] deg Q⇩p p›*) "13" (*‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p p) ∈ 𝒪⇩p›*) "14" (*‹(b::((nat ⇒ int) × (nat ⇒ int)) set) [^] deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p›*) "15" (*‹a [^] deg Q⇩p p ∈ 𝒪⇩p›*) "16" (*‹monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b ∈ 𝒪⇩p›*) "17" (*‹to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b) n = to_Zp (p (deg Q⇩p p)) n ⊗⇘residue_ring (p ^ n)⇙ to_Zp (b [^] deg Q⇩p p) n›*) "18" (*‹monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ a ∈ 𝒪⇩p›*) assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?x2 ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p› ‹b ∈ 𝒪⇩p› ‹val (g ∙ a) < eint (int n)› ‹to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set) (n::nat) = to_Zp (b::((nat ⇒ int) × (nat ⇒ int)) set) n›*) residue_of_prod (*‹(?a ⊗⇘Z⇩p⇙ ?b) ?k = ?a ?k ⊗⇘residue_ring (p ^ ?k)⇙ ?b ?k›*) to_Zp_mult (*‹⟦?a ∈ 𝒪⇩p; ?b ∈ 𝒪⇩p⟧ ⟹ to_Zp (?a ⊗ ?b) = to_Zp ?a ⊗⇘Z⇩p⇙ to_Zp ?b›*) "11" (*‹monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ a = p (deg Q⇩p p) ⊗ a [^] deg Q⇩p p›*) by presburger show "?thesis" (*goal: ‹to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b) n = to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ a) n›*) using "12" (*‹to_Zp (b [^] deg Q⇩p p) n = to_Zp (a [^] deg Q⇩p p) n›*) "17" (*‹to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b) n = to_Zp (p (deg Q⇩p p)) n ⊗⇘residue_ring (p ^ n)⇙ to_Zp (b [^] deg Q⇩p p) n›*) "19" (*‹to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ a) n = to_Zp (p (deg Q⇩p p)) n ⊗⇘residue_ring (p ^ n)⇙ to_Zp (a [^] deg Q⇩p p) n›*) by presburger qed have 2: "p (deg Q⇩p p) ∈ 𝒪⇩p" using A(3) (*‹∀x. p x ∈ 𝒪⇩p›*) by blast have 3: "(ltrm p ∙ b) ∈ 𝒪⇩p" using "2" (*‹p (deg Q⇩p p) ∈ 𝒪⇩p›*) assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?x2 ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p› ‹b ∈ 𝒪⇩p› ‹val (g ∙ a) < eint (int n)› ‹to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set) (n::nat) = to_Zp (b::((nat ⇒ int) × (nat ⇒ int)) set) n›*) by (metis A( (*‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)›*) 1) Q⇩p_def (*‹Q⇩p ≡ Frac (Z⇩p::(nat ⇒ int) ring)›*) val_ring_memE (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ (0::eint) ≤ val ?a› ‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) val_ring_memE (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ (0::eint) ≤ val ?a› ‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) UPQ.ltrm_closed (*‹(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p) ⟹ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f) ∈ carrier (UP Q⇩p)›*) Zp_def (*‹Z⇩p::(nat ⇒ int) ring ≡ padic_int (p::int)›*) ι_def (*‹ι::(nat ⇒ int) ⇒ ((nat ⇒ int) × (nat ⇒ int)) set ≡ Frac_inc (Z⇩p::(nat ⇒ int) ring)›*) gauss_norm_monom (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p ⟹ gauss_norm (monom (UP Q⇩p) ?a (?n::nat)) = val ?a›*) padic_fields.positive_gauss_norm_eval (*‹⟦padic_fields (?p::int); (?g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP (Frac (padic_int ?p))); (0::eint) ≤ padic_fields.gauss_norm ?p ?g; (?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ Frac_inc (padic_int ?p) ` carrier (padic_int ?p)⟧ ⟹ UP_cring.to_fun (Frac (padic_int ?p)) ?g ?a ∈ Frac_inc (padic_int ?p) ` carrier (padic_int ?p)›*) padic_fields_axioms (*‹padic_fields (p::int)›*)) have 4: "(ltrm p ∙ a) ∈ 𝒪⇩p" using "2" (*‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p p) ∈ 𝒪⇩p›*) assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?x2 ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p› ‹b ∈ 𝒪⇩p› ‹val ((g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ (a::((nat ⇒ int) × (nat ⇒ int)) set)) < eint (int (n::nat))› ‹to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set) (n::nat) = to_Zp (b::((nat ⇒ int) × (nat ⇒ int)) set) n›*) by (metis A( (*‹p ∈ carrier (UP Q⇩p)›*) 1) Q⇩p_def (*‹Q⇩p ≡ Frac Z⇩p›*) val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) UPQ.ltrm_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f) ∈ carrier (UP Q⇩p)›*) Zp_def (*‹Z⇩p ≡ padic_int p›*) ι_def (*‹ι ≡ Frac_inc Z⇩p›*) gauss_norm_monom (*‹?a ∈ carrier Q⇩p ⟹ gauss_norm (monom (UP Q⇩p) ?a ?n) = val ?a›*) padic_fields.positive_gauss_norm_eval (*‹⟦padic_fields ?p; ?g ∈ carrier (UP (Frac (padic_int ?p))); 0 ≤ padic_fields.gauss_norm ?p ?g; ?a ∈ Frac_inc (padic_int ?p) ` carrier (padic_int ?p)⟧ ⟹ UP_cring.to_fun (Frac (padic_int ?p)) ?g ?a ∈ Frac_inc (padic_int ?p) ` carrier (padic_int ?p)›*) padic_fields_axioms (*‹padic_fields p›*)) have 5: "(q ∙ b) ∈ 𝒪⇩p" using ‹∀x. q x ∈ 𝒪⇩p› (*‹∀x. q x ∈ 𝒪⇩p›*) assms(4) (*‹(b::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p›*) q_def (*‹q ∈ carrier (UP Q⇩p) ∧ deg Q⇩p q < deg Q⇩p p ∧ p = q ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)›*) by (metis gauss_norm_coeff_norm (*‹∃n≤deg Q⇩p ?g. gauss_norm ?g = val (?g n)›*) positive_gauss_norm_eval (*‹⟦?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g; ?a ∈ 𝒪⇩p⟧ ⟹ ?g ∙ ?a ∈ 𝒪⇩p›*) val_ring_memE( (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a›*) 1)) have 6: "(q ∙ a) ∈ 𝒪⇩p" using ‹∀x. q x ∈ 𝒪⇩p› (*‹∀x. q x ∈ 𝒪⇩p›*) assms(3) (*‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p›*) q_def (*‹q ∈ carrier (UP Q⇩p) ∧ deg Q⇩p q < deg Q⇩p p ∧ p = q ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)›*) by (metis gauss_norm_coeff_norm (*‹∃n≤deg Q⇩p ?g. gauss_norm ?g = val (?g n)›*) positive_gauss_norm_eval (*‹⟦?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g; ?a ∈ 𝒪⇩p⟧ ⟹ ?g ∙ ?a ∈ 𝒪⇩p›*) val_ring_memE( (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a›*) 1)) have 7: "to_Zp (p ∙ b) = to_Zp (ltrm p ∙ b) ⊕⇘Z⇩p⇙ to_Zp (q ∙ b)" using "5" (*‹q ∙ b ∈ 𝒪⇩p›*) "3" (*‹monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b ∈ 𝒪⇩p›*) q_def (*‹q ∈ carrier (UP Q⇩p) ∧ deg Q⇩p q < deg Q⇩p p ∧ p = q ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)›*) by (metis (no_types, lifting) A( (*‹p ∈ carrier (UP Q⇩p)›*) 1) val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) UPQ.ltrm_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f) ∈ carrier (UP Q⇩p)›*) UPQ.to_fun_plus (*‹⟦?g ∈ carrier (UP Q⇩p); ?f ∈ carrier (UP Q⇩p); ?x ∈ carrier Q⇩p⟧ ⟹ (?f ⊕⇘UP Q⇩p⇙ ?g) ∙ ?x = ?f ∙ ?x ⊕ ?g ∙ ?x›*) add_comm (*‹?a ⊕⇘Z⇩p⇙ ?b = ?b ⊕⇘Z⇩p⇙ ?a›*) assms( (*‹b ∈ 𝒪⇩p›*) 4) to_Zp_add (*‹⟦?a ∈ 𝒪⇩p; ?b ∈ 𝒪⇩p⟧ ⟹ to_Zp (?a ⊕ ?b) = to_Zp ?a ⊕⇘Z⇩p⇙ to_Zp ?b›*)) have 8: "to_Zp (p ∙ a) = to_Zp (ltrm p ∙ a) ⊕⇘Z⇩p⇙ to_Zp (q ∙ a)" using "4" (*‹monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ a ∈ 𝒪⇩p›*) "6" (*‹q ∙ a ∈ 𝒪⇩p›*) q_def (*‹q ∈ carrier (UP Q⇩p) ∧ deg Q⇩p q < deg Q⇩p p ∧ p = q ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)›*) by (metis (no_types, lifting) A( (*‹p ∈ carrier (UP Q⇩p)›*) 1) val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) UPQ.ltrm_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f) ∈ carrier (UP Q⇩p)›*) UPQ.to_fun_plus (*‹⟦?g ∈ carrier (UP Q⇩p); ?f ∈ carrier (UP Q⇩p); ?x ∈ carrier Q⇩p⟧ ⟹ (?f ⊕⇘UP Q⇩p⇙ ?g) ∙ ?x = ?f ∙ ?x ⊕ ?g ∙ ?x›*) add_comm (*‹?a ⊕⇘Z⇩p⇙ ?b = ?b ⊕⇘Z⇩p⇙ ?a›*) assms( (*‹a ∈ 𝒪⇩p›*) 3) to_Zp_add (*‹⟦?a ∈ 𝒪⇩p; ?b ∈ 𝒪⇩p⟧ ⟹ to_Zp (?a ⊕ ?b) = to_Zp ?a ⊕⇘Z⇩p⇙ to_Zp ?b›*)) have 9: "to_Zp (p ∙ b) ∈ carrier Z⇩p" using A (*‹p ∈ carrier (UP Q⇩p)› ‹0 < deg Q⇩p p› ‹∀x. p x ∈ 𝒪⇩p›*) assms (*‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹g ?x2 ∈ 𝒪⇩p› ‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p› ‹b ∈ 𝒪⇩p› ‹val (g ∙ a) < eint (int n)› ‹to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set) (n::nat) = to_Zp (b::((nat ⇒ int) × (nat ⇒ int)) set) n›*) by (meson val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) UPQ.to_fun_closed (*‹⟦?f ∈ carrier (UP Q⇩p); ?x ∈ carrier Q⇩p⟧ ⟹ ?f ∙ ?x ∈ carrier Q⇩p›*) to_Zp_closed (*‹?a ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier Z⇩p›*)) have 10: "to_Zp (p ∙ a) ∈ carrier Z⇩p" using A (*‹p ∈ carrier (UP Q⇩p)› ‹(0::nat) < deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)› ‹∀x. p x ∈ 𝒪⇩p›*) assms (*‹g ∈ carrier (UP Q⇩p)› ‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (?x2::nat) ∈ 𝒪⇩p› ‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p› ‹b ∈ 𝒪⇩p› ‹val (g ∙ a) < eint (int n)› ‹to_Zp a n = to_Zp b n›*) val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) UPQ.to_fun_closed (*‹⟦(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (?x::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p⟧ ⟹ ?f ∙ ?x ∈ carrier Q⇩p›*) to_Zp_closed (*‹?a ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier Z⇩p›*) by presburger have 11: "to_Zp (p ∙ b) n = to_Zp (ltrm p ∙ b) n ⊕⇘Zp_res_ring n⇙ to_Zp (q ∙ b) n" using "7" (*‹to_Zp ((p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ (b::((nat ⇒ int) × (nat ⇒ int)) set)) = to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b) ⊕⇘Z⇩p::(nat ⇒ int) ring⇙ to_Zp ((q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ b)›*) "9" (*‹to_Zp (p ∙ b) ∈ carrier Z⇩p›*) "5" (*‹(q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ (b::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p›*) "3" (*‹monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b ∈ 𝒪⇩p›*) residue_of_sum (*‹(?a ⊕⇘Z⇩p⇙ ?b) ?k = ?a ?k ⊕⇘residue_ring (p ^ ?k)⇙ ?b ?k›*) by presburger have 12: "to_Zp (p ∙ a) n = to_Zp (ltrm p ∙ a) n ⊕⇘Zp_res_ring n⇙ to_Zp (q ∙ a) n" using "8" (*‹to_Zp (p ∙ a) = to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ a) ⊕⇘Z⇩p⇙ to_Zp (q ∙ a)›*) "6" (*‹q ∙ a ∈ 𝒪⇩p›*) "4" (*‹monom (UP Q⇩p) ((p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p p)) (deg Q⇩p p) ∙ (a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p›*) residue_of_sum (*‹(?a ⊕⇘Z⇩p⇙ ?b) ?k = ?a ?k ⊕⇘residue_ring (p ^ ?k)⇙ ?b ?k›*) by presburger show "?thesis" (*goal: ‹to_Zp ((p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ (b::((nat ⇒ int) × (nat ⇒ int)) set)) (n::nat) = to_Zp (p ∙ (a::((nat ⇒ int) × (nat ⇒ int)) set)) n›*) using "0" (*‹to_Zp (q ∙ b) n = to_Zp (q ∙ a) n›*) "11" (*‹to_Zp ((p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ (b::((nat ⇒ int) × (nat ⇒ int)) set)) (n::nat) = to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b) n ⊕⇘residue_ring ((p::int) ^ n)⇙ to_Zp ((q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ b) n›*) "12" (*‹to_Zp (p ∙ a) n = to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ a) n ⊕⇘residue_ring (p ^ n)⇙ to_Zp (q ∙ a) n›*) q_def (*‹q ∈ carrier (UP Q⇩p) ∧ deg Q⇩p q < deg Q⇩p p ∧ p = q ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)›*) assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?x2 ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p› ‹b ∈ 𝒪⇩p› ‹val (g ∙ a) < eint (int n)› ‹to_Zp a n = to_Zp b n›*) using "1" (*‹to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ b) n = to_Zp (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∙ a) n›*) by presburger qed qed qed have "(∀x. g x ∈ 𝒪⇩p) " using assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?x2 ∈ 𝒪⇩p› ‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p› ‹(b::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p› ‹val ((g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ (a::((nat ⇒ int) × (nat ⇒ int)) set)) < eint (int (n::nat))› ‹to_Zp a n = to_Zp b n›*) by blast hence 0: "to_Zp (g ∙ b) n = to_Zp (g ∙ a) n" using ‹(∀x. g x ∈ 𝒪⇩p) ⟶ to_Zp (g ∙ b) n = to_Zp (g ∙ a) n› (*‹(∀x. g x ∈ 𝒪⇩p) ⟶ to_Zp (g ∙ b) n = to_Zp (g ∙ a) n›*) by blast have 1: "g ∙ a ∈ 𝒪⇩p" using assms(1) (*‹g ∈ carrier (UP Q⇩p)›*) assms(2) (*‹g ?x2 ∈ 𝒪⇩p›*) assms(3) (*‹a ∈ 𝒪⇩p›*) by (metis gauss_norm_coeff_norm (*‹∃n≤deg Q⇩p ?g. gauss_norm ?g = val (?g n)›*) positive_gauss_norm_eval (*‹⟦?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g; ?a ∈ 𝒪⇩p⟧ ⟹ ?g ∙ ?a ∈ 𝒪⇩p›*) val_ring_memE( (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a›*) 1)) have 2: "g ∙ b ∈ 𝒪⇩p" using assms(1) (*‹g ∈ carrier (UP Q⇩p)›*) assms(2) (*‹g ?x2 ∈ 𝒪⇩p›*) assms(4) (*‹b ∈ 𝒪⇩p›*) by (metis gauss_norm_coeff_norm (*‹∃n≤deg Q⇩p ?g. gauss_norm ?g = val (?g n)›*) positive_gauss_norm_eval (*‹⟦?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g; ?a ∈ 𝒪⇩p⟧ ⟹ ?g ∙ ?a ∈ 𝒪⇩p›*) val_ring_memE( (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a›*) 1)) have 3: "val (g ∙ b) < eint n" proof (-) (*goal: ‹val ((g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ (b::((nat ⇒ int) × (nat ⇒ int)) set)) < eint (int (n::nat))›*) have P0: "to_Zp (g ∙ a) ∈ carrier Z⇩p" using "1" (*‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ (a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p›*) val_ring_memE (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ (0::eint) ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) to_Zp_closed (*‹?a ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier Z⇩p›*) by blast have P1: "to_Zp (g ∙ b) ∈ carrier Z⇩p" using "2" (*‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ (b::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p›*) val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) to_Zp_closed (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier (Z⇩p::(nat ⇒ int) ring)›*) by blast have P2: "val_Zp (to_Zp (g ∙ a)) < n" using "1" (*‹g ∙ a ∈ 𝒪⇩p›*) assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?x2 ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p› ‹b ∈ 𝒪⇩p› ‹val (g ∙ a) < eint (int n)› ‹to_Zp a n = to_Zp b n›*) to_Zp_val (*‹?a ∈ 𝒪⇩p ⟹ val_Zp (to_Zp ?a) = val ?a›*) by presburger have P3: "to_Zp (g ∙ a) ≠ 𝟬⇘Z⇩p⇙" using P2 (*‹val_Zp (to_Zp (g ∙ a)) < eint (int n)›*) P0 (*‹to_Zp (g ∙ a) ∈ carrier Z⇩p›*) unfolding val_Zp_def (*goal: ‹to_Zp (g ∙ a) ≠ 𝟬⇘Z⇩p⇙›*) by (metis P2 (*‹val_Zp (to_Zp (g ∙ a)) < eint (int n)›*) infinity_ilessE (*‹∞ < eint ?m ⟹ ?R›*) val_Zp_def (*‹val_Zp = (λx. if x = 𝟬⇘Z⇩p⇙ then ∞ else eint (padic_val p x))›*)) have P4: "(to_Zp (g ∙ a)) n ≠ 0" using "1" (*‹g ∙ a ∈ 𝒪⇩p›*) P2 (*‹val_Zp (to_Zp ((g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ (a::((nat ⇒ int) × (nat ⇒ int)) set))) < eint (int (n::nat))›*) P3 (*‹to_Zp ((g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ (a::((nat ⇒ int) × (nat ⇒ int)) set)) ≠ 𝟬⇘Z⇩p::(nat ⇒ int) ring⇙›*) above_ord_nonzero[of "to_Zp (g ∙ a)" n] (*‹⟦to_Zp (g ∙ a) ∈ carrier Z⇩p; to_Zp (g ∙ a) ≠ 𝟬⇘Z⇩p⇙; ord_Zp (to_Zp (g ∙ a)) < int n⟧ ⟹ to_Zp (g ∙ a) n ≠ 0›*) by (metis P0 (*‹to_Zp (g ∙ a) ∈ carrier Z⇩p›*) eint.inject (*‹(eint ?int = eint ?int') = (?int = ?int')›*) less_eintE (*‹⟦?n < eint ?m; ⋀k. ⟦?n = eint k; k < ?m⟧ ⟹ ?P⟧ ⟹ ?P›*) val_ord_Zp (*‹?a ≠ 𝟬⇘Z⇩p⇙ ⟹ val_Zp ?a = eint (ord_Zp ?a)›*)) then have "to_Zp (g ∙ b) n ≠ 0" using "0" (*‹to_Zp (g ∙ b) n = to_Zp (g ∙ a) n›*) by linarith then have "val_Zp (to_Zp (g ∙ b)) < n" using P1 (*‹to_Zp (g ∙ b) ∈ carrier Z⇩p›*) P0 (*‹to_Zp (g ∙ a) ∈ carrier Z⇩p›*) by (smt below_val_Zp_zero (*‹⟦(?x::nat ⇒ int) ∈ carrier (Z⇩p::(nat ⇒ int) ring); ?x (Suc (?n::nat)) ≠ (0::int)⟧ ⟹ val_Zp ?x ≤ eint (int ?n)›*) eint_ile (*‹(?n::eint) ≤ eint (?m::int) ⟹ ∃k::int. ?n = eint k›*) eint_ord_simps( (*‹(eint (?m::int) ≤ eint (?n::int)) = (?m ≤ ?n)›*) 1) eint_ord_simps( (*‹(eint (?m::int) < eint (?n::int)) = (?m < ?n)›*) 2) nonzero_imp_ex_nonzero_res (*‹⟦(?x::nat ⇒ int) ∈ carrier (Z⇩p::(nat ⇒ int) ring); ?x ≠ 𝟬⇘Z⇩p⇙⟧ ⟹ ∃k::nat. ?x (Suc k) ≠ (0::int)›*) residue_of_zero( (*‹𝟬⇘Z⇩p::(nat ⇒ int) ring⇙ (?k::nat) = (0::int)›*) 2) zero_below_val_Zp (*‹⟦(?x::nat ⇒ int) ∈ carrier (Z⇩p::(nat ⇒ int) ring); eint (int (?n::nat)) ≤ val_Zp ?x⟧ ⟹ ?x ?n = (0::int)›*)) then show "?thesis" (*goal: ‹val ((g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ (b::((nat ⇒ int) × (nat ⇒ int)) set)) < eint (int (n::nat))›*) using "2" (*‹g ∙ b ∈ 𝒪⇩p›*) by (metis to_Zp_val (*‹?a ∈ 𝒪⇩p ⟹ val_Zp (to_Zp ?a) = val ?a›*)) qed thus "?thesis" (*goal: ‹val ((g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ (b::((nat ⇒ int) × (nat ⇒ int)) set)) = val (g ∙ (a::((nat ⇒ int) × (nat ⇒ int)) set))›*) using "0" (*‹to_Zp (g ∙ b) n = to_Zp (g ∙ a) n›*) "1" (*‹g ∙ a ∈ 𝒪⇩p›*) "2" (*‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ (b::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p›*) assms (*‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹g ?x2 ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p› ‹b ∈ 𝒪⇩p› ‹val (g ∙ a) < eint (int n)› ‹to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set) (n::nat) = to_Zp (b::((nat ⇒ int) × (nat ⇒ int)) set) n›*) val_ring_equal_res_imp_equal_val[of "g ∙ b" "g ∙ a" n] (*‹⟦g ∙ b ∈ 𝒪⇩p; g ∙ a ∈ 𝒪⇩p; val (g ∙ b) < eint (int n); val (g ∙ a) < eint (int n); to_Zp (g ∙ b) n = to_Zp (g ∙ a) n⟧ ⟹ val (g ∙ b) = val (g ∙ a)›*) by blast qed lemma to_Zp_poly_monom: assumes "a ∈ 𝒪⇩p" shows "to_Zp_poly (monom (UP Q⇩p) a n) = monom (UP Z⇩p) (to_Zp a) n" unfolding to_Zp_poly_def (*goal: ‹(λna. to_Zp (monom (UP Q⇩p) a n na)) = monom (UP Z⇩p) (to_Zp a) n›*) apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹(λna::nat. to_Zp (monom (UP Q⇩p) (a::((nat ⇒ int) × (nat ⇒ int)) set) (n::nat) na)) = monom (UP (Z⇩p::(nat ⇒ int) ring)) (to_Zp a) n›*) using assms (*‹a ∈ 𝒪⇩p›*) cfs_monom[of a n] (*‹a ∈ carrier Q⇩p ⟹ monom (UP Q⇩p) a n ?n = (if n = ?n then a else 𝟬)›*) Zp.cfs_monom[of "to_Zp a" n] (*‹to_Zp a ∈ carrier Z⇩p ⟹ monom (UP Z⇩p) (to_Zp a) n ?n = (if n = ?n then to_Zp a else 𝟬⇘Z⇩p⇙)›*) by (simp add: to_Zp_closed (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier (Z⇩p::(nat ⇒ int) ring)›*) to_Zp_zero (*‹to_Zp 𝟬 = 𝟬⇘Z⇩p::(nat ⇒ int) ring⇙›*) val_ring_memE( (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) 2)) lemma to_Zp_poly_add: assumes "f ∈ carrier (UP Q⇩p)" assumes "gauss_norm f ≥ 0" assumes "g ∈ carrier (UP Q⇩p)" assumes "gauss_norm g ≥ 0" shows "to_Zp_poly (f ⊕⇘UP Q⇩p⇙ g) = to_Zp_poly f ⊕⇘UP Z⇩p⇙ to_Zp_poly g" proof (-) (*goal: ‹to_Zp_poly ((f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ⊕⇘UP Q⇩p⇙ (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)) = to_Zp_poly f ⊕⇘UP (Z⇩p::(nat ⇒ int) ring)⇙ to_Zp_poly g›*) obtain F where F_def: "F = to_Zp_poly f" (*goal: ‹(⋀F. F = to_Zp_poly f ⟹ thesis) ⟹ thesis›*) by blast obtain G where G_def: "G = to_Zp_poly g" (*goal: ‹(⋀G. G = to_Zp_poly g ⟹ thesis) ⟹ thesis›*) by blast have F_closed: "F ∈ carrier (UP Z⇩p)" unfolding F_def (*goal: ‹to_Zp_poly f ∈ carrier (UP Z⇩p)›*) using assms (*‹f ∈ carrier (UP Q⇩p)› ‹0 ≤ gauss_norm f› ‹g ∈ carrier (UP Q⇩p)› ‹0 ≤ gauss_norm g›*) by (simp add: to_Zp_poly_closed (*‹⟦?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g⟧ ⟹ to_Zp_poly ?g ∈ carrier (UP Z⇩p)›*)) have G_closed: "G ∈ carrier (UP Z⇩p)" unfolding G_def (*goal: ‹to_Zp_poly g ∈ carrier (UP Z⇩p)›*) using assms (*‹f ∈ carrier (UP Q⇩p)› ‹0 ≤ gauss_norm f› ‹g ∈ carrier (UP Q⇩p)› ‹0 ≤ gauss_norm g›*) by (simp add: to_Zp_poly_closed (*‹⟦(?g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (0::eint) ≤ gauss_norm ?g⟧ ⟹ to_Zp_poly ?g ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring))›*)) have F_inc: "poly_inc F = f" using assms (*‹f ∈ carrier (UP Q⇩p)› ‹0 ≤ gauss_norm f› ‹g ∈ carrier (UP Q⇩p)› ‹0 ≤ gauss_norm g›*) unfolding F_def (*goal: ‹poly_inc (to_Zp_poly f) = f›*) using poly_inc_inverse_left (*‹⟦?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g⟧ ⟹ poly_inc (to_Zp_poly ?g) = ?g›*) by blast have G_inc: "poly_inc G = g" using assms (*‹(f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹(0::eint) ≤ gauss_norm (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)› ‹g ∈ carrier (UP Q⇩p)› ‹(0::eint) ≤ gauss_norm (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)›*) unfolding G_def (*goal: ‹poly_inc (to_Zp_poly (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)) = g›*) by (simp add: poly_inc_inverse_left (*‹⟦?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g⟧ ⟹ poly_inc (to_Zp_poly ?g) = ?g›*)) have 0: "poly_inc (F ⊕⇘UP Z⇩p⇙ G) = poly_inc F ⊕⇘UP Q⇩p⇙ poly_inc G" using F_closed (*‹F ∈ carrier (UP Z⇩p)›*) G_closed (*‹G ∈ carrier (UP Z⇩p)›*) by (simp add: poly_inc_plus (*‹⟦?f ∈ carrier (UP Z⇩p); ?g ∈ carrier (UP Z⇩p)⟧ ⟹ poly_inc (?f ⊕⇘UP Z⇩p⇙ ?g) = poly_inc ?f ⊕⇘UP Q⇩p⇙ poly_inc ?g›*)) have 1: "to_Zp_poly (poly_inc (F ⊕⇘UP Z⇩p⇙ G)) = F ⊕⇘UP Z⇩p⇙ G" using G_closed (*‹G ∈ carrier (UP Z⇩p)›*) F_closed (*‹(F::nat ⇒ nat ⇒ int) ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring))›*) by (simp add: poly_inc_inverse_right (*‹?g ∈ carrier (UP Z⇩p) ⟹ to_Zp_poly (poly_inc ?g) = ?g›*)) show "?thesis" (*goal: ‹to_Zp_poly (f ⊕⇘UP Q⇩p⇙ g) = to_Zp_poly f ⊕⇘UP Z⇩p⇙ to_Zp_poly g›*) using "1" (*‹to_Zp_poly (poly_inc (F ⊕⇘UP Z⇩p⇙ G)) = F ⊕⇘UP Z⇩p⇙ G›*) unfolding F_inc G_inc "0" (*goal: ‹to_Zp_poly (f ⊕⇘UP Q⇩p⇙ g) = to_Zp_poly f ⊕⇘UP Z⇩p⇙ to_Zp_poly g›*) unfolding F_def G_def (*goal: ‹to_Zp_poly (f ⊕⇘UP Q⇩p⇙ g) = to_Zp_poly f ⊕⇘UP Z⇩p⇙ to_Zp_poly g›*) by blast qed lemma to_Zp_poly_zero: "to_Zp_poly (𝟬⇘UP Q⇩p⇙) = 𝟬⇘UP Z⇩p⇙" unfolding to_Zp_poly_def (*goal: ‹(λn::nat. to_Zp (𝟬⇘UP Q⇩p⇙ n)) = 𝟬⇘UP (Z⇩p::(nat ⇒ int) ring)⇙›*) apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹(λn::nat. to_Zp (𝟬⇘UP Q⇩p⇙ n)) = 𝟬⇘UP (Z⇩p::(nat ⇒ int) ring)⇙›*) by (simp add: to_Zp_zero (*‹to_Zp 𝟬 = 𝟬⇘Z⇩p⇙›*)) lemma to_Zp_poly_one: "to_Zp_poly (𝟭⇘UP Q⇩p⇙) = 𝟭⇘UP Z⇩p⇙" unfolding to_Zp_poly_def (*goal: ‹(λn. to_Zp (𝟭⇘UP Q⇩p⇙ n)) = 𝟭⇘UP Z⇩p⇙›*) apply (rule ext (*‹(⋀x::?'a. (?f::?'a ⇒ ?'b) x = (?g::?'a ⇒ ?'b) x) ⟹ ?f = ?g›*)) (*goal: ‹(λn. to_Zp (𝟭⇘UP Q⇩p⇙ n)) = 𝟭⇘UP Z⇩p⇙›*) by (metis Zp.UP_one_closed (*‹𝟭⇘UP Z⇩p⇙ ∈ carrier (UP Z⇩p)›*) poly_inc_inverse_right (*‹?g ∈ carrier (UP Z⇩p) ⟹ to_Zp_poly (poly_inc ?g) = ?g›*) poly_inc_one (*‹poly_inc 𝟭⇘UP Z⇩p⇙ = 𝟭⇘UP Q⇩p⇙›*) to_Zp_poly_def (*‹to_Zp_poly ?g = (λn. to_Zp (?g n))›*)) lemma val_ring_add_pow: assumes "a ∈ carrier Q⇩p" assumes "val a ≥ 0" shows "val ([(n::nat)]⋅a) ≥ 0" proof (-) (*goal: ‹0 ≤ val ([n] ⋅ a)›*) have 0: "[(n::nat)]⋅a = ([n]⋅𝟭)⊗a" using assms (*‹a ∈ carrier Q⇩p› ‹(0::eint) ≤ val (a::((nat ⇒ int) × (nat ⇒ int)) set)›*) Qp.add_pow_ldistr (*‹⟦?a ∈ carrier Q⇩p; ?b ∈ carrier Q⇩p⟧ ⟹ [?k] ⋅ ?a ⊗ ?b = [?k] ⋅ (?a ⊗ ?b)›*) Qp.cring_simprules(12) (*‹?x ∈ carrier Q⇩p ⟹ 𝟭 ⊗ ?x = ?x›*) Qp.one_closed (*‹𝟭 ∈ carrier Q⇩p›*) by presburger show "?thesis" (*goal: ‹0 ≤ val ([n] ⋅ a)›*) unfolding "0" (*goal: ‹0 ≤ val ([n] ⋅ 𝟭 ⊗ a)›*) using assms (*‹a ∈ carrier Q⇩p› ‹0 ≤ val a›*) by (meson Qp.nat_inc_closed (*‹[?n] ⋅ 𝟭 ∈ carrier Q⇩p›*) val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) val_of_nat_inc (*‹0 ≤ val ([?k] ⋅ 𝟭)›*) val_ringI (*‹⟦?a ∈ carrier Q⇩p; 0 ≤ val ?a⟧ ⟹ ?a ∈ 𝒪⇩p›*) val_ring_times_closed (*‹⟦?a ∈ 𝒪⇩p; ?b ∈ 𝒪⇩p⟧ ⟹ ?a ⊗ ?b ∈ 𝒪⇩p›*)) qed lemma to_Zp_poly_pderiv: assumes "g ∈ carrier (UP Q⇩p)" assumes "gauss_norm g ≥ 0" shows "to_Zp_poly (pderiv g) = Zp.pderiv (to_Zp_poly g)" proof (-) (*goal: ‹to_Zp_poly (UPQ.pderiv g) = Zp.pderiv (to_Zp_poly g)›*) have 0: "gauss_norm g ≥ 0 ⟶ to_Zp_poly (pderiv g) = Zp.pderiv (to_Zp_poly g)" proof (rule poly_induct (*‹⟦(?p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); ⋀p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set. ⟦p ∈ carrier (UP Q⇩p); deg Q⇩p p = (0::nat)⟧ ⟹ (?Q::(nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ⇒ bool) p; ⋀p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set. ⟦⋀q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set. ⟦q ∈ carrier (UP Q⇩p); deg Q⇩p q < deg Q⇩p p⟧ ⟹ ?Q q; p ∈ carrier (UP Q⇩p); (0::nat) < deg Q⇩p p⟧ ⟹ ?Q p⟧ ⟹ ?Q ?p›*), rule assms (*‹g ∈ carrier (UP Q⇩p)› ‹0 ≤ gauss_norm g›*), rule) (*goals: 1. ‹⋀p. ⟦p ∈ carrier (UP Q⇩p); deg Q⇩p p = 0; 0 ≤ gauss_norm p⟧ ⟹ to_Zp_poly (UPQ.pderiv p) = Zp.pderiv (to_Zp_poly p)› 2. ‹⋀p. ⟦⋀q. ⟦q ∈ carrier (UP Q⇩p); deg Q⇩p q < deg Q⇩p p⟧ ⟹ 0 ≤ gauss_norm q ⟶ to_Zp_poly (UPQ.pderiv q) = Zp.pderiv (to_Zp_poly q); p ∈ carrier (UP Q⇩p); 0 < deg Q⇩p p⟧ ⟹ 0 ≤ gauss_norm p ⟶ to_Zp_poly (UPQ.pderiv p) = Zp.pderiv (to_Zp_poly p)›*) fix p assume A: " p ∈ carrier (UP Q⇩p)" "deg Q⇩p p = 0" "0 ≤ gauss_norm p" (*‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) = (0::nat)› ‹(0::eint) ≤ gauss_norm (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)›*) obtain a where a_def: "a ∈ 𝒪⇩p ∧ p = monom (UP Q⇩p) a 0" (*goal: ‹(⋀a. a ∈ 𝒪⇩p ∧ p = monom (UP Q⇩p) a 0 ⟹ thesis) ⟹ thesis›*) using A (*‹p ∈ carrier (UP Q⇩p)› ‹deg Q⇩p p = 0› ‹0 ≤ gauss_norm p›*) by (metis UPQ.ltrm_deg_0 (*‹⟦?p ∈ carrier (UP Q⇩p); deg Q⇩p ?p = 0⟧ ⟹ monom (UP Q⇩p) (?p (deg Q⇩p ?p)) (deg Q⇩p ?p) = ?p›*) positive_gauss_norm_valuation_ring_coeffs (*‹⟦?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g⟧ ⟹ ?g ?n ∈ 𝒪⇩p›*)) have p_eq: "p = monom (UP Q⇩p) a 0" using a_def (*‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ∧ (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) = monom (UP Q⇩p) a (0::nat)›*) by blast have 0: "to_Zp_poly p = monom (UP Z⇩p) (to_Zp a) 0" unfolding p_eq (*goal: ‹to_Zp_poly (monom (UP Q⇩p) a 0) = monom (UP Z⇩p) (to_Zp a) 0›*) apply (rule to_Zp_poly_monom (*‹?a ∈ 𝒪⇩p ⟹ to_Zp_poly (monom (UP Q⇩p) ?a ?n) = monom (UP Z⇩p) (to_Zp ?a) ?n›*)) (*goal: ‹to_Zp_poly (monom (UP Q⇩p) a 0) = monom (UP Z⇩p) (to_Zp a) 0›*) using a_def (*‹a ∈ 𝒪⇩p ∧ p = monom (UP Q⇩p) a 0›*) by blast have 1: "UPQ.pderiv (monom (UP Q⇩p) a 0) = 𝟬⇘UP Q⇩p⇙" using A(1) (*‹p ∈ carrier (UP Q⇩p)›*) A(2) (*‹deg Q⇩p p = 0›*) UPQ.pderiv_deg_0 (*‹⟦(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); deg Q⇩p ?f = (0::nat)⟧ ⟹ UPQ.pderiv ?f = 𝟬⇘UP Q⇩p⇙›*) p_eq (*‹p = monom (UP Q⇩p) a 0›*) by blast have 2: "Zp.pderiv (monom (UP Z⇩p) (to_Zp a) 0) = 𝟬⇘UP Z⇩p⇙" apply (rule Zp.pderiv_deg_0 (*‹⟦?f ∈ carrier (UP Z⇩p); deg Z⇩p ?f = 0⟧ ⟹ Zp.pderiv ?f = 𝟬⇘UP Z⇩p⇙›*)) (*goal: ‹Zp.pderiv (monom (UP Z⇩p) (to_Zp a) 0) = 𝟬⇘UP Z⇩p⇙›*) apply (rule Zp.monom_closed (*‹?a ∈ carrier Z⇩p ⟹ monom (UP Z⇩p) ?a ?n ∈ carrier (UP Z⇩p)›*), rule to_Zp_closed (*‹?a ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier Z⇩p›*)) (*top goal: ‹monom (UP (Z⇩p::(nat ⇒ int) ring)) (to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set)) (0::nat) ∈ carrier (UP Z⇩p)› and 1 goal remains*) using a_def (*‹a ∈ 𝒪⇩p ∧ p = monom (UP Q⇩p) a 0›*) apply (simp add: val_ring_memE( (*‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) 2); fail) (*top goal: ‹a ∈ carrier Q⇩p› and 1 goal remains*) apply (cases "to_Zp a = 𝟬⇘Z⇩p⇙") (*goal: ‹deg Z⇩p (monom (UP Z⇩p) (to_Zp a) 0) = 0›*) apply (simp; fail) (*top goal: ‹to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set) = 𝟬⇘Z⇩p::(nat ⇒ int) ring⇙ ⟹ deg Z⇩p (monom (UP Z⇩p) (to_Zp a) (0::nat)) = (0::nat)› and 1 goal remains*) apply (rule Zp.deg_monom (*‹⟦?a ≠ 𝟬⇘Z⇩p⇙; ?a ∈ carrier Z⇩p⟧ ⟹ deg Z⇩p (monom (UP Z⇩p) ?a ?n) = ?n›*), blast) (*goal: ‹to_Zp a ≠ 𝟬⇘Z⇩p⇙ ⟹ deg Z⇩p (monom (UP Z⇩p) (to_Zp a) 0) = 0›*) using a_def (*‹a ∈ 𝒪⇩p ∧ p = monom (UP Q⇩p) a 0›*) by (simp add: to_Zp_closed (*‹?a ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier Z⇩p›*) val_ring_memE( (*‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) 2)) show "to_Zp_poly (UPQ.pderiv p) = Zp.pderiv (to_Zp_poly p)" unfolding "0" (*goal: ‹to_Zp_poly (UPQ.pderiv p) = Zp.pderiv (monom (UP Z⇩p) (to_Zp a) 0)›*) unfolding p_eq (*goal: ‹to_Zp_poly (UPQ.pderiv (monom (UP Q⇩p) a 0)) = Zp.pderiv (monom (UP Z⇩p) (to_Zp a) 0)›*) unfolding "1" "2" to_Zp_poly_zero (*goal: ‹𝟬⇘UP Z⇩p⇙ = 𝟬⇘UP Z⇩p⇙›*) by blast next (*goal: ‹⋀p. ⟦⋀q. ⟦q ∈ carrier (UP Q⇩p); deg Q⇩p q < deg Q⇩p p⟧ ⟹ 0 ≤ gauss_norm q ⟶ to_Zp_poly (UPQ.pderiv q) = Zp.pderiv (to_Zp_poly q); p ∈ carrier (UP Q⇩p); 0 < deg Q⇩p p⟧ ⟹ 0 ≤ gauss_norm p ⟶ to_Zp_poly (UPQ.pderiv p) = Zp.pderiv (to_Zp_poly p)›*) fix p assume A: "⋀q. q ∈ carrier (UP Q⇩p) ⟹ deg Q⇩p q < deg Q⇩p p ⟹ 0 ≤ gauss_norm q ⟶ to_Zp_poly (UPQ.pderiv q) = Zp.pderiv (to_Zp_poly q)" "p ∈ carrier (UP Q⇩p)" " 0 < deg Q⇩p p" (*‹⟦(?q2::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); deg Q⇩p ?q2 < deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)⟧ ⟹ (0::eint) ≤ gauss_norm ?q2 ⟶ to_Zp_poly (UPQ.pderiv ?q2) = Zp.pderiv (to_Zp_poly ?q2)› ‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹(0::nat) < deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)›*) show "0 ≤ gauss_norm p ⟶ to_Zp_poly (UPQ.pderiv p) = Zp.pderiv (to_Zp_poly p)" proof (standard) (*goal: ‹(0::eint) ≤ gauss_norm (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ⟹ to_Zp_poly (UPQ.pderiv p) = Zp.pderiv (to_Zp_poly p)›*) assume B: "0 ≤ gauss_norm p" (*‹(0::eint) ≤ gauss_norm (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)›*) obtain q where q_def: "q = trunc p" (*goal: ‹(⋀q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set. q = Cring_Poly.truncate Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ⟹ thesis::bool) ⟹ thesis›*) by blast have p_eq: "p = q ⊕⇘UP Q⇩p⇙ ltrm p" by (simp add: A( (*‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)›*) 2) UPQ.trunc_simps( (*‹(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p) ⟹ ?f = Cring_Poly.truncate Q⇩p ?f ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f)›*) 1) q_def (*‹(q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) = Cring_Poly.truncate Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)›*)) have q_gauss_norm: "gauss_norm q ≥ 0" unfolding q_def (*goal: ‹0 ≤ gauss_norm (Cring_Poly.truncate Q⇩p p)›*) apply (rule gauss_norm_geqI (*‹⟦(?g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); ⋀n::nat. (?α::eint) ≤ val (?g n)⟧ ⟹ ?α ≤ gauss_norm ?g›*)) (*goal: ‹0 ≤ gauss_norm (Cring_Poly.truncate Q⇩p p)›*) using A (*‹⟦?q2 ∈ carrier (UP Q⇩p); deg Q⇩p ?q2 < deg Q⇩p p⟧ ⟹ 0 ≤ gauss_norm ?q2 ⟶ to_Zp_poly (UPQ.pderiv ?q2) = Zp.pderiv (to_Zp_poly ?q2)› ‹p ∈ carrier (UP Q⇩p)› ‹0 < deg Q⇩p p›*) apply (simp add: UPQ.trunc_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ Cring_Poly.truncate Q⇩p ?f ∈ carrier (UP Q⇩p)›*); fail) (*top goal: ‹Cring_Poly.truncate Q⇩p p ∈ carrier (UP Q⇩p)› and 1 goal remains*) using trunc_cfs[of p] (*‹⟦p ∈ carrier (UP Q⇩p); ?n < deg Q⇩p p⟧ ⟹ Cring_Poly.truncate Q⇩p p ?n = p ?n›*) A (*‹⟦?q2 ∈ carrier (UP Q⇩p); deg Q⇩p ?q2 < deg Q⇩p p⟧ ⟹ 0 ≤ gauss_norm ?q2 ⟶ to_Zp_poly (UPQ.pderiv ?q2) = Zp.pderiv (to_Zp_poly ?q2)› ‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹(0::nat) < deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)›*) gauss_normE (*‹?g ∈ carrier (UP Q⇩p) ⟹ gauss_norm ?g ≤ val (?g ?k)›*) proof (-) (*goal: ‹⋀n. ⟦⋀n. ⟦p ∈ carrier (UP Q⇩p); n < deg Q⇩p p⟧ ⟹ Cring_Poly.truncate Q⇩p p n = p n; ⋀q. ⟦q ∈ carrier (UP Q⇩p); deg Q⇩p q < deg Q⇩p p⟧ ⟹ 0 ≤ gauss_norm q ⟶ to_Zp_poly (UPQ.pderiv q) = Zp.pderiv (to_Zp_poly q); p ∈ carrier (UP Q⇩p); 0 < deg Q⇩p p; ⋀g k. g ∈ carrier (UP Q⇩p) ⟹ gauss_norm g ≤ val (g k)⟧ ⟹ 0 ≤ val (Cring_Poly.truncate Q⇩p p n)›*) fix n :: nat have f1: "𝟬 = q (deg Q⇩p p)" by (simp add: UPQ.deg_leE (*‹⟦?p ∈ carrier (UP Q⇩p); deg Q⇩p ?p < ?k⟧ ⟹ ?p ?k = 𝟬›*) UPQ.trunc_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ Cring_Poly.truncate Q⇩p ?f ∈ carrier (UP Q⇩p)›*) UPQ.trunc_degree (*‹⟦?f ∈ carrier (UP Q⇩p); 0 < deg Q⇩p ?f⟧ ⟹ deg Q⇩p (Cring_Poly.truncate Q⇩p ?f) < deg Q⇩p ?f›*) ‹0 < deg Q⇩p p› ‹p ∈ carrier (UP Q⇩p)› q_def (*‹q = Cring_Poly.truncate Q⇩p p›*)) have "∀n. 0 ≤ val (p n)" by (meson B (*‹0 ≤ gauss_norm p›*) ‹p ∈ carrier (UP Q⇩p)› eint_ord_trans (*‹⟦?a ≤ ?b; ?b ≤ ?c⟧ ⟹ ?a ≤ ?c›*) gauss_normE (*‹?g ∈ carrier (UP Q⇩p) ⟹ gauss_norm ?g ≤ val (?g ?k)›*)) then show "0 ≤ val (Cring_Poly.truncate Q⇩p p n)" using f1 (*‹𝟬 = (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set))›*) by (metis (no_types) Qp.nat_mult_zero (*‹[0] ⋅ ?x = 𝟬›*) UPQ.ltrm_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f) ∈ carrier (UP Q⇩p)›*) UPQ.coeff_of_sum_diff_degree0 (*‹⟦?p ∈ carrier (UP Q⇩p); ?q ∈ carrier (UP Q⇩p); deg Q⇩p ?q < ?n⟧ ⟹ (?p ⊕⇘UP Q⇩p⇙ ?q) ?n = ?p ?n›*) UPQ.deg_ltrm (*‹?f ∈ carrier (UP Q⇩p) ⟹ deg Q⇩p (monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f)) = deg Q⇩p ?f›*) UPQ.trunc_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ Cring_Poly.truncate Q⇩p ?f ∈ carrier (UP Q⇩p)›*) ‹⋀n. ⟦p ∈ carrier (UP Q⇩p); n < deg Q⇩p p⟧ ⟹ Cring_Poly.truncate Q⇩p p n = p n› ‹p ∈ carrier (UP Q⇩p)› nat_neq_iff (*‹(?m ≠ ?n) = (?m < ?n ∨ ?n < ?m)›*) p_eq (*‹p = q ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)›*) q_def (*‹q = Cring_Poly.truncate Q⇩p p›*) val_of_nat_inc (*‹0 ≤ val ([?k] ⋅ 𝟭)›*)) qed have 0: "to_Zp_poly (UPQ.pderiv q) = Zp.pderiv (to_Zp_poly q)" using A (*‹⟦?q2 ∈ carrier (UP Q⇩p); deg Q⇩p ?q2 < deg Q⇩p p⟧ ⟹ 0 ≤ gauss_norm ?q2 ⟶ to_Zp_poly (UPQ.pderiv ?q2) = Zp.pderiv (to_Zp_poly ?q2)› ‹p ∈ carrier (UP Q⇩p)› ‹0 < deg Q⇩p p›*) q_def (*‹q = Cring_Poly.truncate Q⇩p p›*) q_gauss_norm (*‹(0::eint) ≤ gauss_norm (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)›*) by (simp add: UPQ.trunc_closed (*‹(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p) ⟹ Cring_Poly.truncate Q⇩p ?f ∈ carrier (UP Q⇩p)›*) UPQ.trunc_degree (*‹⟦(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (0::nat) < deg Q⇩p ?f⟧ ⟹ deg Q⇩p (Cring_Poly.truncate Q⇩p ?f) < deg Q⇩p ?f›*)) have 1: "UPQ.pderiv (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)) = monom (UP Q⇩p) ([deg Q⇩p p] ⋅ p (deg Q⇩p p)) (deg Q⇩p p - 1)" apply (rule pderiv_monom (*‹?a ∈ carrier Q⇩p ⟹ UPQ.pderiv (monom (UP Q⇩p) ?a ?n) = monom (UP Q⇩p) ([?n] ⋅ ?a) (?n - 1)›*)) (*goal: ‹UPQ.pderiv (monom (UP Q⇩p) ((p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p p)) (deg Q⇩p p)) = monom (UP Q⇩p) ([deg Q⇩p p] ⋅ p (deg Q⇩p p)) (deg Q⇩p p - (1::nat))›*) using A (*‹⟦?q2 ∈ carrier (UP Q⇩p); deg Q⇩p ?q2 < deg Q⇩p p⟧ ⟹ 0 ≤ gauss_norm ?q2 ⟶ to_Zp_poly (UPQ.pderiv ?q2) = Zp.pderiv (to_Zp_poly ?q2)› ‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹0 < deg Q⇩p p›*) by (simp add: UPQ.UP_car_memE( (*‹?g ∈ carrier (UP Q⇩p) ⟹ ?g ?x ∈ carrier Q⇩p›*) 1)) have 2: "Zp.pderiv (monom (UP Z⇩p) (to_Zp (p (deg Q⇩p p))) (deg Q⇩p p)) = monom (UP Z⇩p) ([deg Q⇩p p] ⋅⇘Z⇩p⇙ to_Zp ( p (deg Q⇩p p))) (deg Q⇩p p - 1)" using A (*‹⟦?q2 ∈ carrier (UP Q⇩p); deg Q⇩p ?q2 < deg Q⇩p p⟧ ⟹ 0 ≤ gauss_norm ?q2 ⟶ to_Zp_poly (UPQ.pderiv ?q2) = Zp.pderiv (to_Zp_poly ?q2)› ‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹0 < deg Q⇩p p›*) Zp.pderiv_monom[of "to_Zp ( p (deg Q⇩p p))" "deg Q⇩p p"] (*‹to_Zp (p (deg Q⇩p p)) ∈ carrier Z⇩p ⟹ Zp.pderiv (monom (UP Z⇩p) (to_Zp (p (deg Q⇩p p))) (deg Q⇩p p)) = monom (UP Z⇩p) ([deg Q⇩p p] ⋅⇘Z⇩p⇙ to_Zp (p (deg Q⇩p p))) (deg Q⇩p p - 1)›*) by (simp add: UPQ.lcf_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ ?f (deg Q⇩p ?f) ∈ carrier Q⇩p›*) to_Zp_closed (*‹?a ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier Z⇩p›*)) have 3: "to_Zp_poly (UPQ.pderiv (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p))) = monom (UP Z⇩p) (to_Zp ([deg Q⇩p p] ⋅ p (deg Q⇩p p))) (deg Q⇩p p - 1)" unfolding "1" (*goal: ‹to_Zp_poly (monom (UP Q⇩p) ([deg Q⇩p p] ⋅ p (deg Q⇩p p)) (deg Q⇩p p - 1)) = monom (UP Z⇩p) (to_Zp ([deg Q⇩p p] ⋅ p (deg Q⇩p p))) (deg Q⇩p p - 1)›*) apply (rule to_Zp_poly_monom (*‹?a ∈ 𝒪⇩p ⟹ to_Zp_poly (monom (UP Q⇩p) ?a ?n) = monom (UP Z⇩p) (to_Zp ?a) ?n›*)) (*goal: ‹to_Zp_poly (monom (UP Q⇩p) ([deg Q⇩p p] ⋅ p (deg Q⇩p p)) (deg Q⇩p p - 1)) = monom (UP Z⇩p) (to_Zp ([deg Q⇩p p] ⋅ p (deg Q⇩p p))) (deg Q⇩p p - 1)›*) apply (rule val_ring_memI (*‹⟦?a ∈ carrier Q⇩p; 0 ≤ val ?a⟧ ⟹ ?a ∈ 𝒪⇩p›*)) (*goal: ‹[deg Q⇩p p] ⋅ p (deg Q⇩p p) ∈ 𝒪⇩p›*) apply (simp add: A( (*‹p ∈ carrier (UP Q⇩p)›*) 2) UPQ.UP_car_memE( (*‹?g ∈ carrier (UP Q⇩p) ⟹ ?g ?x ∈ carrier Q⇩p›*) 1); fail) (*top goal: ‹[deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)] ⋅ p (deg Q⇩p p) ∈ carrier Q⇩p› and 1 goal remains*) apply (rule val_ring_add_pow (*‹⟦?a ∈ carrier Q⇩p; 0 ≤ val ?a⟧ ⟹ 0 ≤ val ([?n] ⋅ ?a)›*)) (*goal: ‹0 ≤ val ([deg Q⇩p p] ⋅ p (deg Q⇩p p))›*) using A (*‹⟦?q2 ∈ carrier (UP Q⇩p); deg Q⇩p ?q2 < deg Q⇩p p⟧ ⟹ 0 ≤ gauss_norm ?q2 ⟶ to_Zp_poly (UPQ.pderiv ?q2) = Zp.pderiv (to_Zp_poly ?q2)› ‹p ∈ carrier (UP Q⇩p)› ‹0 < deg Q⇩p p›*) apply (simp add: UPQ.lcf_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ ?f (deg Q⇩p ?f) ∈ carrier Q⇩p›*); fail) (*top goal: ‹p (deg Q⇩p p) ∈ carrier Q⇩p› and 1 goal remains*) using B (*‹0 ≤ gauss_norm p›*) A (*‹⟦?q2 ∈ carrier (UP Q⇩p); deg Q⇩p ?q2 < deg Q⇩p p⟧ ⟹ 0 ≤ gauss_norm ?q2 ⟶ to_Zp_poly (UPQ.pderiv ?q2) = Zp.pderiv (to_Zp_poly ?q2)› ‹p ∈ carrier (UP Q⇩p)› ‹0 < deg Q⇩p p›*) by (simp add: positive_gauss_norm_valuation_ring_coeffs (*‹⟦?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g⟧ ⟹ ?g ?n ∈ 𝒪⇩p›*) val_ring_memE( (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a›*) 1)) have 4: "to_Zp_poly (ltrm p) = monom (UP Z⇩p) (to_Zp (p (deg Q⇩p p))) (deg Q⇩p p)" apply (rule to_Zp_poly_monom (*‹?a ∈ 𝒪⇩p ⟹ to_Zp_poly (monom (UP Q⇩p) ?a ?n) = monom (UP Z⇩p) (to_Zp ?a) ?n›*)) (*goal: ‹to_Zp_poly (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)) = monom (UP Z⇩p) (to_Zp (p (deg Q⇩p p))) (deg Q⇩p p)›*) using A (*‹⟦?q2 ∈ carrier (UP Q⇩p); deg Q⇩p ?q2 < deg Q⇩p p⟧ ⟹ 0 ≤ gauss_norm ?q2 ⟶ to_Zp_poly (UPQ.pderiv ?q2) = Zp.pderiv (to_Zp_poly ?q2)› ‹p ∈ carrier (UP Q⇩p)› ‹0 < deg Q⇩p p›*) by (simp add: B (*‹(0::eint) ≤ gauss_norm (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)›*) positive_gauss_norm_valuation_ring_coeffs (*‹⟦(?g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (0::eint) ≤ gauss_norm ?g⟧ ⟹ ?g (?n::nat) ∈ 𝒪⇩p›*)) have 5: "to_Zp_poly (UPQ.pderiv (ltrm p)) = Zp.pderiv (to_Zp_poly (ltrm p))" unfolding "3" "4" "2" (*goal: ‹monom (UP Z⇩p) (to_Zp ([deg Q⇩p p] ⋅ p (deg Q⇩p p))) (deg Q⇩p p - 1) = monom (UP Z⇩p) ([deg Q⇩p p] ⋅⇘Z⇩p⇙ to_Zp (p (deg Q⇩p p))) (deg Q⇩p p - 1)›*) by (simp add: A( (*‹p ∈ carrier (UP Q⇩p)›*) 2) B (*‹0 ≤ gauss_norm p›*) positive_gauss_norm_valuation_ring_coeffs (*‹⟦?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g⟧ ⟹ ?g ?n ∈ 𝒪⇩p›*) to_Zp_nat_add_pow (*‹?a ∈ 𝒪⇩p ⟹ to_Zp ([?n] ⋅ ?a) = [?n] ⋅⇘Z⇩p⇙ to_Zp ?a›*)) have 6: "pderiv p = pderiv q ⊕⇘UP Q⇩p⇙ pderiv (ltrm p)" using p_eq (*‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) = (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)›*) by (metis A( (*‹p ∈ carrier (UP Q⇩p)›*) 2) UPQ.ltrm_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f) ∈ carrier (UP Q⇩p)›*) UPQ.pderiv_add (*‹⟦?p ∈ carrier (UP Q⇩p); ?q ∈ carrier (UP Q⇩p)⟧ ⟹ UPQ.pderiv (?p ⊕⇘UP Q⇩p⇙ ?q) = UPQ.pderiv ?p ⊕⇘UP Q⇩p⇙ UPQ.pderiv ?q›*) UPQ.trunc_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ Cring_Poly.truncate Q⇩p ?f ∈ carrier (UP Q⇩p)›*) p_eq (*‹p = q ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)›*) q_def (*‹q = Cring_Poly.truncate Q⇩p p›*)) have 7: "to_Zp_poly p = to_Zp_poly q ⊕⇘UP Z⇩p⇙ to_Zp_poly (ltrm p)" using p_eq (*‹p = q ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)›*) by (metis (no_types, lifting) A( (*‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)›*) 2) B (*‹(0::eint) ≤ gauss_norm (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)›*) UPQ.ltrm_closed (*‹(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p) ⟹ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f) ∈ carrier (UP Q⇩p)›*) UPQ.cfs_closed (*‹(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p) ⟹ ?f (?n::nat) ∈ carrier Q⇩p›*) UPQ.trunc_closed (*‹(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p) ⟹ Cring_Poly.truncate Q⇩p ?f ∈ carrier (UP Q⇩p)›*) gauss_norm_monom (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p ⟹ gauss_norm (monom (UP Q⇩p) ?a (?n::nat)) = val ?a›*) positive_gauss_norm_valuation_ring_coeffs (*‹⟦(?g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (0::eint) ≤ gauss_norm ?g⟧ ⟹ ?g (?n::nat) ∈ 𝒪⇩p›*) q_def (*‹(q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) = Cring_Poly.truncate Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)›*) q_gauss_norm (*‹(0::eint) ≤ gauss_norm (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)›*) to_Zp_poly_add (*‹⟦(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (0::eint) ≤ gauss_norm ?f; (?g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (0::eint) ≤ gauss_norm ?g⟧ ⟹ to_Zp_poly (?f ⊕⇘UP Q⇩p⇙ ?g) = to_Zp_poly ?f ⊕⇘UP (Z⇩p::(nat ⇒ int) ring)⇙ to_Zp_poly ?g›*) val_ring_memE( (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ (0::eint) ≤ val ?a›*) 1)) have 8: "to_Zp_poly (pderiv p) = to_Zp_poly (UPQ.pderiv q) ⊕⇘UP Z⇩p⇙ to_Zp_poly (UPQ.pderiv (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)))" unfolding "6" (*goal: ‹to_Zp_poly (UPQ.pderiv q ⊕⇘UP Q⇩p⇙ UPQ.pderiv (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p))) = to_Zp_poly (UPQ.pderiv q) ⊕⇘UP Z⇩p⇙ to_Zp_poly (UPQ.pderiv (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)))›*) apply (rule to_Zp_poly_add (*‹⟦?f ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?f; ?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g⟧ ⟹ to_Zp_poly (?f ⊕⇘UP Q⇩p⇙ ?g) = to_Zp_poly ?f ⊕⇘UP Z⇩p⇙ to_Zp_poly ?g›*)) (*goal: ‹to_Zp_poly (UPQ.pderiv (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ⊕⇘UP Q⇩p⇙ UPQ.pderiv (monom (UP Q⇩p) ((p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p p)) (deg Q⇩p p))) = to_Zp_poly (UPQ.pderiv q) ⊕⇘UP (Z⇩p::(nat ⇒ int) ring)⇙ to_Zp_poly (UPQ.pderiv (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)))›*) apply (simp add: A( (*‹p ∈ carrier (UP Q⇩p)›*) 2) UPQ.pderiv_closed (*‹?p ∈ carrier (UP Q⇩p) ⟹ UPQ.pderiv ?p ∈ carrier (UP Q⇩p)›*) UPQ.trunc_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ Cring_Poly.truncate Q⇩p ?f ∈ carrier (UP Q⇩p)›*) q_def (*‹q = Cring_Poly.truncate Q⇩p p›*); fail) (*top goal: ‹UPQ.pderiv q ∈ carrier (UP Q⇩p)› and 3 goals remain*) apply (metis A( (*‹p ∈ carrier (UP Q⇩p)›*) 2) UPQ.cfs_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ ?f ?n ∈ carrier Q⇩p›*) UPQ.pderiv_cfs (*‹?g ∈ carrier (UP Q⇩p) ⟹ UPQ.pderiv ?g ?n = [Suc ?n] ⋅ ?g (Suc ?n)›*) UPQ.trunc_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ Cring_Poly.truncate Q⇩p ?f ∈ carrier (UP Q⇩p)›*) gauss_norm_coeff_norm (*‹∃n≤deg Q⇩p ?g. gauss_norm ?g = val (?g n)›*) positive_gauss_norm_valuation_ring_coeffs (*‹⟦?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g⟧ ⟹ ?g ?n ∈ 𝒪⇩p›*) q_def (*‹q = Cring_Poly.truncate Q⇩p p›*) q_gauss_norm (*‹0 ≤ gauss_norm q›*) val_ring_add_pow (*‹⟦?a ∈ carrier Q⇩p; 0 ≤ val ?a⟧ ⟹ 0 ≤ val ([?n] ⋅ ?a)›*) val_ring_memE( (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a›*) 1)) (*top goal: ‹0 ≤ gauss_norm (UPQ.pderiv q)› and 2 goals remain*) apply (simp add: A( (*‹p ∈ carrier (UP Q⇩p)›*) 2) UPQ.UP_car_memE( (*‹?g ∈ carrier (UP Q⇩p) ⟹ ?g ?x ∈ carrier Q⇩p›*) 1) UPQ.pderiv_closed (*‹?p ∈ carrier (UP Q⇩p) ⟹ UPQ.pderiv ?p ∈ carrier (UP Q⇩p)›*); fail) (*top goal: ‹UPQ.pderiv (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)) ∈ carrier (UP Q⇩p)› and 1 goal remains*) apply (rule eint_ord_trans[of _ "gauss_norm (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p))"] (*‹⟦?a ≤ gauss_norm (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)); gauss_norm (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)) ≤ ?c⟧ ⟹ ?a ≤ ?c›*)) (*goal: ‹0 ≤ gauss_norm (UPQ.pderiv (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)))›*) apply (simp add: A( (*‹p ∈ carrier (UP Q⇩p)›*) 2) B (*‹0 ≤ gauss_norm p›*) UPQ.cfs_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ ?f ?n ∈ carrier Q⇩p›*) gauss_norm_monom (*‹?a ∈ carrier Q⇩p ⟹ gauss_norm (monom (UP Q⇩p) ?a ?n) = val ?a›*) positive_gauss_norm_valuation_ring_coeffs (*‹⟦?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g⟧ ⟹ ?g ?n ∈ 𝒪⇩p›*) val_ring_memE( (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a›*) 1); fail) (*top goal: ‹0 ≤ gauss_norm (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p))› and 1 goal remains*) apply (rule gauss_norm_pderiv (*‹(?g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p) ⟹ gauss_norm ?g ≤ gauss_norm (UPQ.pderiv ?g)›*)) (*goal: ‹gauss_norm (monom (UP Q⇩p) ((p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p p)) (deg Q⇩p p)) ≤ gauss_norm (UPQ.pderiv (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)))›*) using A(2) (*‹p ∈ carrier (UP Q⇩p)›*) UPQ.ltrm_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f) ∈ carrier (UP Q⇩p)›*) by blast have 9: "Zp.pderiv (to_Zp_poly p) = Zp.pderiv (to_Zp_poly q) ⊕⇘UP Z⇩p⇙ Zp.pderiv (to_Zp_poly (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)))" unfolding "7" (*goal: ‹Zp.pderiv (to_Zp_poly q ⊕⇘UP Z⇩p⇙ to_Zp_poly (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p))) = Zp.pderiv (to_Zp_poly q) ⊕⇘UP Z⇩p⇙ Zp.pderiv (to_Zp_poly (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)))›*) apply (rule Zp.pderiv_add (*‹⟦?p ∈ carrier (UP Z⇩p); ?q ∈ carrier (UP Z⇩p)⟧ ⟹ Zp.pderiv (?p ⊕⇘UP Z⇩p⇙ ?q) = Zp.pderiv ?p ⊕⇘UP Z⇩p⇙ Zp.pderiv ?q›*)) (*goals: 1. ‹to_Zp_poly q ∈ carrier (UP Z⇩p)› 2. ‹to_Zp_poly (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)) ∈ carrier (UP Z⇩p)› discuss goal 1*) apply (rule to_Zp_poly_closed (*‹⟦(?g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (0::eint) ≤ gauss_norm ?g⟧ ⟹ to_Zp_poly ?g ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring))›*)) (*goals: 1. ‹q ∈ carrier (UP Q⇩p)› 2. ‹0 ≤ gauss_norm q› discuss goal 1*) apply (simp add: A( (*‹p ∈ carrier (UP Q⇩p)›*) 2) UPQ.trunc_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ Cring_Poly.truncate Q⇩p ?f ∈ carrier (UP Q⇩p)›*) q_def (*‹q = Cring_Poly.truncate Q⇩p p›*)) (*discuss goal 2*) apply (simp add: q_gauss_norm (*‹(0::eint) ≤ gauss_norm (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply (rule to_Zp_poly_closed (*‹⟦?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g⟧ ⟹ to_Zp_poly ?g ∈ carrier (UP Z⇩p)›*)) (*goals: 1. ‹monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p) ∈ carrier (UP Q⇩p)› 2. ‹0 ≤ gauss_norm (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p))› discuss goal 1*) apply (simp add: A( (*‹p ∈ carrier (UP Q⇩p)›*) 2) UPQ.UP_car_memE( (*‹?g ∈ carrier (UP Q⇩p) ⟹ ?g ?x ∈ carrier Q⇩p›*) 1)) (*discuss goal 2*) apply (simp add: A( (*‹p ∈ carrier (UP Q⇩p)›*) 2) B (*‹0 ≤ gauss_norm p›*) UPQ.cfs_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ ?f ?n ∈ carrier Q⇩p›*) gauss_norm_monom (*‹?a ∈ carrier Q⇩p ⟹ gauss_norm (monom (UP Q⇩p) ?a ?n) = val ?a›*) positive_gauss_norm_valuation_ring_coeffs (*‹⟦?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g⟧ ⟹ ?g ?n ∈ 𝒪⇩p›*) val_ring_memE( (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a›*) 1)) (*proven 2 subgoals*) (*proven 2 subgoals*) . show "to_Zp_poly (UPQ.pderiv p) = Zp.pderiv (to_Zp_poly p)" unfolding "9" "8" "5" "0" (*goal: ‹Zp.pderiv (to_Zp_poly (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)) ⊕⇘UP (Z⇩p::(nat ⇒ int) ring)⇙ Zp.pderiv (to_Zp_poly (monom (UP Q⇩p) ((p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p p)) (deg Q⇩p p))) = Zp.pderiv (to_Zp_poly q) ⊕⇘UP Z⇩p⇙ Zp.pderiv (to_Zp_poly (monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)))›*) by blast qed qed thus "?thesis" (*goal: ‹to_Zp_poly (UPQ.pderiv g) = Zp.pderiv (to_Zp_poly g)›*) using assms (*‹g ∈ carrier (UP Q⇩p)› ‹0 ≤ gauss_norm g›*) by blast qed lemma val_p_int_pow: "val (𝔭[^]k) = eint (k)" by (simp add: ord_p_pow_int (*‹ord (𝔭 [^] (?n::int)) = ?n›*) p_intpow_closed( (*‹𝔭 [^] (?n::int) ∈ nonzero Q⇩p›*) 2)) definition int_gauss_norm where "int_gauss_norm g = (SOME n::int. eint n = gauss_norm g)" lemma int_gauss_norm_eq: assumes "g ∈ carrier (UP Q⇩p)" assumes "g ≠ 𝟬⇘UP Q⇩p⇙" shows "eint (int_gauss_norm g) = gauss_norm g" proof (-) (*goal: ‹eint (int_gauss_norm (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)) = gauss_norm g›*) have 0: "gauss_norm g < ∞" using assms (*‹g ∈ carrier (UP Q⇩p)› ‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ≠ 𝟬⇘UP Q⇩p⇙›*) by (simp add: gauss_norm_prop (*‹⟦?g ∈ carrier (UP Q⇩p); ?g ≠ 𝟬⇘UP Q⇩p⇙⟧ ⟹ gauss_norm ?g ≠ ∞›*)) then show "?thesis" (*goal: ‹eint (int_gauss_norm g) = gauss_norm g›*) unfolding int_gauss_norm_def (*goal: ‹eint (SOME n. eint n = gauss_norm g) = gauss_norm g›*) using assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ≠ 𝟬⇘UP Q⇩p⇙›*) by fastforce qed lemma int_gauss_norm_smult: assumes "g ∈ carrier (UP Q⇩p)" assumes "g ≠ 𝟬⇘UP Q⇩p⇙" assumes "a ∈ nonzero Q⇩p" shows "int_gauss_norm (a ⊙⇘UP Q⇩p⇙ g) = ord a + int_gauss_norm g" using gauss_norm_smult[of g a] (*‹⟦(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p⟧ ⟹ gauss_norm (a ⊙⇘UP Q⇩p⇙ g) = val a + gauss_norm g›*) int_gauss_norm_eq (*‹⟦?g ∈ carrier (UP Q⇩p); ?g ≠ 𝟬⇘UP Q⇩p⇙⟧ ⟹ eint (int_gauss_norm ?g) = gauss_norm ?g›*) val_ord (*‹?a ∈ nonzero Q⇩p ⟹ val ?a = eint (ord ?a)›*) assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ≠ 𝟬⇘UP Q⇩p⇙› ‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ nonzero Q⇩p›*) by (metis (no_types, opaque_lifting) Qp.nonzero_closed (*‹?a ∈ nonzero Q⇩p ⟹ ?a ∈ carrier Q⇩p›*) UPQ.UP_smult_closed (*‹⟦?a ∈ carrier Q⇩p; ?p ∈ carrier (UP Q⇩p)⟧ ⟹ ?a ⊙⇘UP Q⇩p⇙ ?p ∈ carrier (UP Q⇩p)›*) UPQ.cfs_zero (*‹𝟬⇘UP Q⇩p⇙ ?n = 𝟬›*) eint.distinct( (*‹∞ ≠ eint ?int1›*) 2) eint.inject (*‹(eint ?int = eint ?int') = (?int = ?int')›*) gauss_norm_coeff_norm (*‹∃n≤deg Q⇩p ?g. gauss_norm ?g = val (?g n)›*) local.val_zero (*‹val 𝟬 = ∞›*) plus_eint_simps( (*‹eint ?m + eint ?n = eint (?m + ?n)›*) 1)) definition normalize_poly where "normalize_poly g = (if g = 𝟬⇘UP Q⇩p⇙ then g else (𝔭[^](- int_gauss_norm g)) ⊙⇘Q⇩p_x⇙ g)" lemma normalize_poly_zero: "normalize_poly 𝟬⇘UP Q⇩p⇙ = 𝟬⇘UP Q⇩p⇙" unfolding normalize_poly_def (*goal: ‹(if 𝟬⇘UP Q⇩p⇙ = 𝟬⇘UP Q⇩p⇙ then 𝟬⇘UP Q⇩p⇙ else 𝔭 [^] - int_gauss_norm 𝟬⇘UP Q⇩p⇙ ⊙⇘UP Q⇩p⇙ 𝟬⇘UP Q⇩p⇙) = 𝟬⇘UP Q⇩p⇙›*) by simp lemma normalize_poly_nonzero_eq: assumes "g ≠ 𝟬⇘UP Q⇩p⇙" assumes "g ∈ carrier (UP Q⇩p)" shows "normalize_poly g = (𝔭[^](- int_gauss_norm g)) ⊙⇘UP Q⇩p⇙ g" using assms (*‹g ≠ 𝟬⇘UP Q⇩p⇙› ‹g ∈ carrier (UP Q⇩p)›*) unfolding normalize_poly_def (*goal: ‹(if (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) = 𝟬⇘UP Q⇩p⇙ then g else 𝔭 [^] - int_gauss_norm g ⊙⇘UP Q⇩p⇙ g) = 𝔭 [^] - int_gauss_norm g ⊙⇘UP Q⇩p⇙ g›*) by simp lemma int_gauss_norm_normalize_poly: assumes "g ≠ 𝟬⇘UP Q⇩p⇙" assumes "g ∈ carrier (UP Q⇩p)" shows "int_gauss_norm (normalize_poly g) = 0" using normalize_poly_nonzero_eq (*‹⟦?g ≠ 𝟬⇘UP Q⇩p⇙; ?g ∈ carrier (UP Q⇩p)⟧ ⟹ normalize_poly ?g = 𝔭 [^] - int_gauss_norm ?g ⊙⇘UP Q⇩p⇙ ?g›*) int_gauss_norm_smult (*‹⟦?g ∈ carrier (UP Q⇩p); ?g ≠ 𝟬⇘UP Q⇩p⇙; ?a ∈ nonzero Q⇩p⟧ ⟹ int_gauss_norm (?a ⊙⇘UP Q⇩p⇙ ?g) = ord ?a + int_gauss_norm ?g›*) assms (*‹g ≠ 𝟬⇘UP Q⇩p⇙› ‹g ∈ carrier (UP Q⇩p)›*) by (simp add: ord_p_pow_int (*‹ord (𝔭 [^] ?n) = ?n›*) p_intpow_closed( (*‹𝔭 [^] ?n ∈ nonzero Q⇩p›*) 2)) lemma normalize_poly_closed: assumes "g ∈ carrier (UP Q⇩p)" shows "normalize_poly g ∈ carrier (UP Q⇩p)" using assms (*‹g ∈ carrier (UP Q⇩p)›*) unfolding normalize_poly_def (*goal: ‹(if g = 𝟬⇘UP Q⇩p⇙ then g else 𝔭 [^] - int_gauss_norm g ⊙⇘UP Q⇩p⇙ g) ∈ carrier (UP Q⇩p)›*) by (simp add: p_intpow_closed( (*‹𝔭 [^] ?n ∈ carrier Q⇩p›*) 1)) lemma normalize_poly_nonzero: assumes "g ≠ 𝟬⇘UP Q⇩p⇙" assumes "g ∈ carrier (UP Q⇩p)" shows "normalize_poly g ≠ 𝟬⇘UP Q⇩p⇙" using assms (*‹g ≠ 𝟬⇘UP Q⇩p⇙› ‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)›*) normalize_poly_nonzero_eq (*‹⟦?g ≠ 𝟬⇘UP Q⇩p⇙; ?g ∈ carrier (UP Q⇩p)⟧ ⟹ normalize_poly ?g = 𝔭 [^] - int_gauss_norm ?g ⊙⇘UP Q⇩p⇙ ?g›*) by (metis (no_types, lifting) UPQ.UP_smult_one (*‹?p ∈ carrier (UP Q⇩p) ⟹ 𝟭 ⊙⇘UP Q⇩p⇙ ?p = ?p›*) UPQ.module_axioms (*‹Module.module Q⇩p (UP Q⇩p)›*) UPQ.smult_r_null (*‹?a ∈ carrier Q⇩p ⟹ ?a ⊙⇘UP Q⇩p⇙ 𝟬⇘UP Q⇩p⇙ = 𝟬⇘UP Q⇩p⇙›*) module.smult_assoc1 (*‹⟦Module.module ?R ?M; ?a ∈ carrier ?R; ?b ∈ carrier ?R; ?x ∈ carrier ?M⟧ ⟹ ?a ⊗⇘?R⇙ ?b ⊙⇘?M⇙ ?x = ?a ⊙⇘?M⇙ (?b ⊙⇘?M⇙ ?x)›*) p_intpow_closed( (*‹𝔭 [^] ?n ∈ carrier Q⇩p›*) 1) p_intpow_inv' (*‹𝔭 [^] - ?n ⊗ 𝔭 [^] ?n = 𝟭›*)) lemma gauss_norm_normalize_poly: assumes "g ≠ 𝟬⇘UP Q⇩p⇙" assumes "g ∈ carrier (UP Q⇩p)" shows "gauss_norm (normalize_poly g) = 0" proof (-) (*goal: ‹gauss_norm (normalize_poly g) = 0›*) have 0: "eint (int_gauss_norm (normalize_poly g)) = gauss_norm (normalize_poly g)" apply (rule int_gauss_norm_eq (*‹⟦(?g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); ?g ≠ 𝟬⇘UP Q⇩p⇙⟧ ⟹ eint (int_gauss_norm ?g) = gauss_norm ?g›*)) (*goals: 1. ‹normalize_poly g ∈ carrier (UP Q⇩p)› 2. ‹normalize_poly g ≠ 𝟬⇘UP Q⇩p⇙› discuss goal 1*) apply (rule normalize_poly_closed (*‹?g ∈ carrier (UP Q⇩p) ⟹ normalize_poly ?g ∈ carrier (UP Q⇩p)›*)) (*top goal: ‹normalize_poly g ∈ carrier (UP Q⇩p)› and 1 goal remains*) apply (rule assms (*‹g ≠ 𝟬⇘UP Q⇩p⇙› ‹g ∈ carrier (UP Q⇩p)›*)) (*discuss goal 2*) apply (rule normalize_poly_nonzero (*‹⟦(?g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ≠ 𝟬⇘UP Q⇩p⇙; ?g ∈ carrier (UP Q⇩p)⟧ ⟹ normalize_poly ?g ≠ 𝟬⇘UP Q⇩p⇙›*)) (*goals: 1. ‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ≠ 𝟬⇘UP Q⇩p⇙› 2. ‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› discuss goal 1*) apply (rule assms (*‹g ≠ 𝟬⇘UP Q⇩p⇙› ‹g ∈ carrier (UP Q⇩p)›*)) (*discuss goal 2*) apply (rule assms (*‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ≠ 𝟬⇘UP Q⇩p⇙› ‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) . show "?thesis" (*goal: ‹gauss_norm (normalize_poly (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)) = (0::eint)›*) using "0" (*‹eint (int_gauss_norm (normalize_poly (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set))) = gauss_norm (normalize_poly g)›*) int_gauss_norm_normalize_poly (*‹⟦?g ≠ 𝟬⇘UP Q⇩p⇙; ?g ∈ carrier (UP Q⇩p)⟧ ⟹ int_gauss_norm (normalize_poly ?g) = 0›*) assms (*‹g ≠ 𝟬⇘UP Q⇩p⇙› ‹g ∈ carrier (UP Q⇩p)›*) by (simp add: zero_eint_def (*‹0 = eint 0›*)) qed lemma taylor_term_eval_eq: assumes "f ∈ carrier (UP Q⇩p)" assumes "x ∈ carrier Q⇩p" assumes "t ∈ carrier Q⇩p" assumes "⋀j. i ≠ j ⟹ val (UPQ.taylor_term x f i ∙ t) < val (UPQ.taylor_term x f j ∙ t) " shows "val (f ∙ t) = val (UPQ.taylor_term x f i ∙ t)" proof (-) (*goal: ‹val ((f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ (t::((nat ⇒ int) × (nat ⇒ int)) set)) = val (UPQ.taylor_term (x::((nat ⇒ int) × (nat ⇒ int)) set) f (i::nat) ∙ t)›*) have 0: "f = finsum (UP Q⇩p) (UPQ.taylor_term x f) {..deg Q⇩p f}" apply (rule UPQ.taylor_term_sum[of f "deg Q⇩p f" x] (*‹⟦f ∈ carrier (UP Q⇩p); deg Q⇩p f ≤ deg Q⇩p f; x ∈ carrier Q⇩p⟧ ⟹ f = finsum (UP Q⇩p) (UPQ.taylor_term x f) {..deg Q⇩p f}›*)) (*goals: 1. ‹f ∈ carrier (UP Q⇩p)› 2. ‹deg Q⇩p f ≤ deg Q⇩p f› 3. ‹x ∈ carrier Q⇩p› discuss goal 1*) apply (rule assms (*‹f ∈ carrier (UP Q⇩p)› ‹x ∈ carrier Q⇩p› ‹t ∈ carrier Q⇩p› ‹i ≠ ?j2 ⟹ val (UPQ.taylor_term x f i ∙ t) < val (UPQ.taylor_term x f ?j2 ∙ t)›*)) (*discuss goal 2*) apply blast (*discuss goal 3*) apply (rule assms (*‹f ∈ carrier (UP Q⇩p)› ‹x ∈ carrier Q⇩p› ‹t ∈ carrier Q⇩p› ‹i ≠ ?j2 ⟹ val (UPQ.taylor_term x f i ∙ t) < val (UPQ.taylor_term x f ?j2 ∙ t)›*)) (*proven 3 subgoals*) . show "?thesis" (*goal: ‹val (f ∙ t) = val (UPQ.taylor_term x f i ∙ t)›*) proof (cases "i ∈ {..deg Q⇩p f}") (*goals: 1. ‹i ∈ {..deg Q⇩p f} ⟹ val (f ∙ t) = val (UPQ.taylor_term x f i ∙ t)› 2. ‹i ∉ {..deg Q⇩p f} ⟹ val (f ∙ t) = val (UPQ.taylor_term x f i ∙ t)›*) case True (*‹i ∈ {..deg Q⇩p f}›*) have T0: "finsum (UP Q⇩p) (UPQ.taylor_term x f) {..deg Q⇩p f} = UPQ.taylor_term x f i ⊕⇘UP Q⇩p⇙ finsum (UP Q⇩p) (UPQ.taylor_term x f) ({..deg Q⇩p f} - {i})" apply (rule UPQ.P.finsum_remove[of "{..deg Q⇩p f}" "UPQ.taylor_term x f" i] (*‹⟦⋀i. i ∈ {..deg Q⇩p f} ⟹ UPQ.taylor_term x f i ∈ carrier (UP Q⇩p); finite {..deg Q⇩p f}; i ∈ {..deg Q⇩p f}⟧ ⟹ finsum (UP Q⇩p) (UPQ.taylor_term x f) {..deg Q⇩p f} = UPQ.taylor_term x f i ⊕⇘UP Q⇩p⇙ finsum (UP Q⇩p) (UPQ.taylor_term x f) ({..deg Q⇩p f} - {i})›*)) (*goals: 1. ‹⋀i. i ∈ {..deg Q⇩p f} ⟹ UPQ.taylor_term x f i ∈ carrier (UP Q⇩p)› 2. ‹finite {..deg Q⇩p f}› 3. ‹i ∈ {..deg Q⇩p f}› discuss goal 1*) apply (rule UPQ.taylor_term_closed (*‹⟦?p ∈ carrier (UP Q⇩p); ?a ∈ carrier Q⇩p⟧ ⟹ UPQ.taylor_term ?a ?p ?i ∈ carrier (UP Q⇩p)›*)) (*goals: 1. ‹⋀i::nat. i ∈ {..deg Q⇩p (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)} ⟹ f ∈ carrier (UP Q⇩p)› 2. ‹⋀i::nat. i ∈ {..deg Q⇩p (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)} ⟹ (x::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p› discuss goal 1*) apply (rule assms (*‹f ∈ carrier (UP Q⇩p)› ‹x ∈ carrier Q⇩p› ‹t ∈ carrier Q⇩p› ‹i ≠ ?j2 ⟹ val (UPQ.taylor_term x f i ∙ t) < val (UPQ.taylor_term x f ?j2 ∙ t)›*)) (*discuss goal 2*) apply (rule assms (*‹f ∈ carrier (UP Q⇩p)› ‹x ∈ carrier Q⇩p› ‹t ∈ carrier Q⇩p› ‹i ≠ ?j2 ⟹ val (UPQ.taylor_term x f i ∙ t) < val (UPQ.taylor_term x f ?j2 ∙ t)›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply blast (*discuss goal 3*) apply (rule True (*‹i ∈ {..deg Q⇩p f}›*)) (*proven 3 subgoals*) . have T1: "f = UPQ.taylor_term x f i ⊕⇘UP Q⇩p⇙ finsum (UP Q⇩p) (UPQ.taylor_term x f) ({..deg Q⇩p f} - {i})" using "0" (*‹(f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) = finsum (UP Q⇩p) (UPQ.taylor_term (x::((nat ⇒ int) × (nat ⇒ int)) set) f) {..deg Q⇩p f}›*) T0 (*‹finsum (UP Q⇩p) (UPQ.taylor_term (x::((nat ⇒ int) × (nat ⇒ int)) set) (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)) {..deg Q⇩p f} = UPQ.taylor_term x f (i::nat) ⊕⇘UP Q⇩p⇙ finsum (UP Q⇩p) (UPQ.taylor_term x f) ({..deg Q⇩p f} - {i})›*) by metis have T2: "finsum (UP Q⇩p) (UPQ.taylor_term x f) ({..deg Q⇩p f} - {i}) ∈ carrier (UP Q⇩p)" apply (rule UPQ.P.finsum_closed (*‹?f ∈ ?A → carrier (UP Q⇩p) ⟹ finsum (UP Q⇩p) ?f ?A ∈ carrier (UP Q⇩p)›*)) (*goal: ‹finsum (UP Q⇩p) (UPQ.taylor_term x f) ({..deg Q⇩p f} - {i}) ∈ carrier (UP Q⇩p)›*) using UPQ.taylor_term_closed (*‹⟦(?p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p⟧ ⟹ UPQ.taylor_term ?a ?p (?i::nat) ∈ carrier (UP Q⇩p)›*) assms(1) (*‹f ∈ carrier (UP Q⇩p)›*) assms(2) (*‹x ∈ carrier Q⇩p›*) by blast have T3: "UPQ.taylor_term x f i ∈ carrier (UP Q⇩p)" apply (rule UPQ.taylor_term_closed (*‹⟦?p ∈ carrier (UP Q⇩p); ?a ∈ carrier Q⇩p⟧ ⟹ UPQ.taylor_term ?a ?p ?i ∈ carrier (UP Q⇩p)›*)) (*goals: 1. ‹(f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› 2. ‹(x::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p› discuss goal 1*) apply (rule assms (*‹f ∈ carrier (UP Q⇩p)› ‹x ∈ carrier Q⇩p› ‹t ∈ carrier Q⇩p› ‹i ≠ ?j2 ⟹ val (UPQ.taylor_term x f i ∙ t) < val (UPQ.taylor_term x f ?j2 ∙ t)›*)) (*discuss goal 2*) apply (rule assms (*‹f ∈ carrier (UP Q⇩p)› ‹x ∈ carrier Q⇩p› ‹t ∈ carrier Q⇩p› ‹i ≠ ?j2 ⟹ val (UPQ.taylor_term x f i ∙ t) < val (UPQ.taylor_term x f ?j2 ∙ t)›*)) (*proven 2 subgoals*) . obtain g where g_def: "g = f" (*goal: ‹(⋀g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set. g = (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ⟹ thesis::bool) ⟹ thesis›*) by blast have T4: "g = UPQ.taylor_term x f i ⊕⇘UP Q⇩p⇙ finsum (UP Q⇩p) (UPQ.taylor_term x f) ({..deg Q⇩p f} - {i})" unfolding g_def (*goal: ‹f = UPQ.taylor_term x f i ⊕⇘UP Q⇩p⇙ finsum (UP Q⇩p) (UPQ.taylor_term x f) ({..deg Q⇩p f} - {i})›*) by (rule T1 (*‹f = UPQ.taylor_term x f i ⊕⇘UP Q⇩p⇙ finsum (UP Q⇩p) (UPQ.taylor_term x f) ({..deg Q⇩p f} - {i})›*)) have g_closed: "g ∈ carrier (UP Q⇩p)" unfolding g_def (*goal: ‹f ∈ carrier (UP Q⇩p)›*) by (rule assms (*‹f ∈ carrier (UP Q⇩p)› ‹x ∈ carrier Q⇩p› ‹t ∈ carrier Q⇩p› ‹i ≠ ?j2 ⟹ val (UPQ.taylor_term x f i ∙ t) < val (UPQ.taylor_term x f ?j2 ∙ t)›*)) have T5: "g ∙ t = UPQ.taylor_term x f i ∙ t ⊕ ( finsum (UP Q⇩p) (UPQ.taylor_term x f) ({..deg Q⇩p f} - {i})) ∙ t" unfolding T4 (*goal: ‹(UPQ.taylor_term x f i ⊕⇘UP Q⇩p⇙ finsum (UP Q⇩p) (UPQ.taylor_term x f) ({..deg Q⇩p f} - {i})) ∙ t = UPQ.taylor_term x f i ∙ t ⊕ finsum (UP Q⇩p) (UPQ.taylor_term x f) ({..deg Q⇩p f} - {i}) ∙ t›*) apply (rule UPQ.to_fun_plus (*‹⟦?g ∈ carrier (UP Q⇩p); ?f ∈ carrier (UP Q⇩p); ?x ∈ carrier Q⇩p⟧ ⟹ (?f ⊕⇘UP Q⇩p⇙ ?g) ∙ ?x = ?f ∙ ?x ⊕ ?g ∙ ?x›*)) (*goals: 1. ‹finsum (UP Q⇩p) (UPQ.taylor_term x f) ({..deg Q⇩p f} - {i}) ∈ carrier (UP Q⇩p)› 2. ‹UPQ.taylor_term x f i ∈ carrier (UP Q⇩p)› 3. ‹t ∈ carrier Q⇩p› discuss goal 1*) apply (rule T2 (*‹finsum (UP Q⇩p) (UPQ.taylor_term x f) ({..deg Q⇩p f} - {i}) ∈ carrier (UP Q⇩p)›*)) (*discuss goal 2*) apply (rule T3 (*‹UPQ.taylor_term x f i ∈ carrier (UP Q⇩p)›*)) (*discuss goal 3*) apply (rule assms (*‹f ∈ carrier (UP Q⇩p)› ‹x ∈ carrier Q⇩p› ‹t ∈ carrier Q⇩p› ‹i ≠ ?j2 ⟹ val (UPQ.taylor_term x f i ∙ t) < val (UPQ.taylor_term x f ?j2 ∙ t)›*)) (*proven 3 subgoals*) . have T6: "( finsum (UP Q⇩p) (UPQ.taylor_term x f) ({..deg Q⇩p f} - {i})) ∙ t = ( finsum Q⇩p (λi. UPQ.taylor_term x f i ∙ t) ({..deg Q⇩p f} - {i}))" apply (rule UPQ.to_fun_finsum (*‹⟦finite ?Y; ?f ∈ UNIV → carrier (UP Q⇩p); ?t ∈ carrier Q⇩p⟧ ⟹ finsum (UP Q⇩p) ?f ?Y ∙ ?t = (⨁i∈?Y. ?f i ∙ ?t)›*), blast) (*goal: ‹finsum (UP Q⇩p) (UPQ.taylor_term x f) ({..deg Q⇩p f} - {i}) ∙ t = (⨁i∈{..deg Q⇩p f} - {i}. UPQ.taylor_term x f i ∙ t)›*) using assms (*‹f ∈ carrier (UP Q⇩p)› ‹x ∈ carrier Q⇩p› ‹t ∈ carrier Q⇩p› ‹i ≠ ?j2 ⟹ val (UPQ.taylor_term x f i ∙ t) < val (UPQ.taylor_term x f ?j2 ∙ t)›*) UPQ.taylor_term_closed (*‹⟦?p ∈ carrier (UP Q⇩p); ?a ∈ carrier Q⇩p⟧ ⟹ UPQ.taylor_term ?a ?p ?i ∈ carrier (UP Q⇩p)›*) apply blast (*top goal: ‹UPQ.taylor_term x f ∈ UNIV → carrier (UP Q⇩p)› and 1 goal remains*) using assms (*‹(f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹(x::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p› ‹t ∈ carrier Q⇩p› ‹i ≠ ?j2 ⟹ val (UPQ.taylor_term x f i ∙ t) < val (UPQ.taylor_term x f ?j2 ∙ t)›*) by blast have T7: "⋀j. j ∈ {..deg Q⇩p f} - {i} ⟹ val (UPQ.taylor_term x f j ∙ t) > val (UPQ.taylor_term x f i ∙ t)" using assms (*‹f ∈ carrier (UP Q⇩p)› ‹x ∈ carrier Q⇩p› ‹t ∈ carrier Q⇩p› ‹i ≠ ?j2 ⟹ val (UPQ.taylor_term x f i ∙ t) < val (UPQ.taylor_term x f ?j2 ∙ t)›*) by (metis Diff_iff (*‹((?c::?'a::type) ∈ (?A::?'a::type set) - (?B::?'a::type set)) = (?c ∈ ?A ∧ ?c ∉ ?B)›*) singletonI (*‹(?a::?'a::type) ∈ {?a}›*)) have T8: "val (( finsum (UP Q⇩p) (UPQ.taylor_term x f) ({..deg Q⇩p f} - {i})) ∙ t) > val (UPQ.taylor_term x f i ∙ t)" unfolding T6 (*goal: ‹val (UPQ.taylor_term x f i ∙ t) < val (⨁i∈{..deg Q⇩p f} - {i}. UPQ.taylor_term x f i ∙ t)›*) apply (rule finsum_val_ultrametric'' (*‹⟦?g ∈ ?A → carrier Q⇩p; finite ?A; ⋀i. i ∈ ?A ⟹ ?c < val (?g i); ?c < ∞⟧ ⟹ ?c < val (finsum Q⇩p ?g ?A)›*)) (*goal: ‹val (UPQ.taylor_term x f i ∙ t) < val (⨁i∈{..deg Q⇩p f} - {i}. UPQ.taylor_term x f i ∙ t)›*) using UPQ.taylor_term_closed (*‹⟦?p ∈ carrier (UP Q⇩p); ?a ∈ carrier Q⇩p⟧ ⟹ UPQ.taylor_term ?a ?p ?i ∈ carrier (UP Q⇩p)›*) assms (*‹f ∈ carrier (UP Q⇩p)› ‹x ∈ carrier Q⇩p› ‹t ∈ carrier Q⇩p› ‹i ≠ ?j2 ⟹ val (UPQ.taylor_term x f i ∙ t) < val (UPQ.taylor_term x f ?j2 ∙ t)›*) apply (metis (no_types, lifting) Pi_I (*‹(⋀x::?'a. x ∈ (?A::?'a set) ⟹ (?f::?'a ⇒ ?'b) x ∈ (?B::?'a ⇒ ?'b set) x) ⟹ ?f ∈ Pi ?A ?B›*) UPQ.to_fun_closed (*‹⟦(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (?x::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p⟧ ⟹ ?f ∙ ?x ∈ carrier Q⇩p›*)) (*top goal: ‹(λi::nat. UPQ.taylor_term (x::((nat ⇒ int) × (nat ⇒ int)) set) (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) i ∙ (t::((nat ⇒ int) × (nat ⇒ int)) set)) ∈ {..deg Q⇩p f} - {i::nat} → carrier Q⇩p› and 3 goals remain*) apply blast (*top goal: ‹finite ({..deg Q⇩p f} - {i})› and 2 goals remain*) using assms (*‹f ∈ carrier (UP Q⇩p)› ‹x ∈ carrier Q⇩p› ‹t ∈ carrier Q⇩p› ‹i ≠ ?j2 ⟹ val (UPQ.taylor_term x f i ∙ t) < val (UPQ.taylor_term x f ?j2 ∙ t)›*) T7 (*‹(?j2::nat) ∈ {..deg Q⇩p (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)} - {i::nat} ⟹ val (UPQ.taylor_term (x::((nat ⇒ int) × (nat ⇒ int)) set) f i ∙ (t::((nat ⇒ int) × (nat ⇒ int)) set)) < val (UPQ.taylor_term x f ?j2 ∙ t)›*) apply blast (*top goal: ‹⋀ia. ia ∈ {..deg Q⇩p f} - {i} ⟹ val (UPQ.taylor_term x f i ∙ t) < val (UPQ.taylor_term x f ia ∙ t)› and 1 goal remains*) using assms(4)[of "Suc i"] (*‹i ≠ Suc i ⟹ val (UPQ.taylor_term x f i ∙ t) < val (UPQ.taylor_term x f (Suc i) ∙ t)›*) using eint_ord_simps(4) (*‹(?q < ∞) = (?q ≠ ∞)›*) assms(4) (*‹i ≠ ?j2 ⟹ val (UPQ.taylor_term x f i ∙ t) < val (UPQ.taylor_term x f ?j2 ∙ t)›*) eint_ord_code(6) (*‹(∞ < ?q) = False›*) g_def (*‹g = f›*) gr_implies_not_zero (*‹(?m::?'a) < (?n::?'a) ⟹ ?n ≠ (0::?'a)›*) less_one (*‹(?n < 1) = (?n = 0)›*) by smt have T9: "val (g ∙ t) = val (UPQ.taylor_term x f i ∙ t)" unfolding T5 (*goal: ‹val (UPQ.taylor_term x f i ∙ t ⊕ finsum (UP Q⇩p) (UPQ.taylor_term x f) ({..deg Q⇩p f} - {i}) ∙ t) = val (UPQ.taylor_term x f i ∙ t)›*) using T8 (*‹val (UPQ.taylor_term x f i ∙ t) < val (finsum (UP Q⇩p) (UPQ.taylor_term x f) ({..deg Q⇩p f} - {i}) ∙ t)›*) T2 (*‹finsum (UP Q⇩p) (UPQ.taylor_term x f) ({..deg Q⇩p f} - {i}) ∈ carrier (UP Q⇩p)›*) T3 (*‹UPQ.taylor_term x f i ∈ carrier (UP Q⇩p)›*) by (metis (no_types, lifting) Qp.add.m_comm (*‹⟦?x ∈ carrier Q⇩p; ?y ∈ carrier Q⇩p⟧ ⟹ ?x ⊕ ?y = ?y ⊕ ?x›*) UPQ.to_fun_closed (*‹⟦?f ∈ carrier (UP Q⇩p); ?x ∈ carrier Q⇩p⟧ ⟹ ?f ∙ ?x ∈ carrier Q⇩p›*) assms( (*‹t ∈ carrier Q⇩p›*) 3) val_ultrametric_noteq (*‹⟦?x ∈ carrier Q⇩p; ?y ∈ carrier Q⇩p; val ?y < val ?x⟧ ⟹ val (?x ⊕ ?y) = val ?y›*)) show "?thesis" (*goal: ‹val (f ∙ t) = val (UPQ.taylor_term x f i ∙ t)›*) using T9 (*‹val ((g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ (t::((nat ⇒ int) × (nat ⇒ int)) set)) = val (UPQ.taylor_term (x::((nat ⇒ int) × (nat ⇒ int)) set) (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (i::nat) ∙ t)›*) unfolding g_def (*goal: ‹val (f ∙ t) = val (UPQ.taylor_term x f i ∙ t)›*) by blast next (*goal: ‹i ∉ {..deg Q⇩p f} ⟹ val (f ∙ t) = val (UPQ.taylor_term x f i ∙ t)›*) case False (*‹(i::nat) ∉ {..deg Q⇩p (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)}›*) have "i > deg Q⇩p f" using False (*‹i ∉ {..deg Q⇩p f}›*) by simp hence "i > deg Q⇩p (UPQ.taylor x f)" using assms (*‹f ∈ carrier (UP Q⇩p)› ‹x ∈ carrier Q⇩p› ‹t ∈ carrier Q⇩p› ‹i ≠ ?j2 ⟹ val (UPQ.taylor_term x f i ∙ t) < val (UPQ.taylor_term x f ?j2 ∙ t)›*) UPQ.taylor_deg (*‹⟦?a ∈ carrier Q⇩p; ?p ∈ carrier (UP Q⇩p)⟧ ⟹ deg Q⇩p (UPQ.taylor ?a ?p) = deg Q⇩p ?p›*) by presburger hence F0: "UPQ.taylor x f i = 𝟬" using assms (*‹f ∈ carrier (UP Q⇩p)› ‹x ∈ carrier Q⇩p› ‹t ∈ carrier Q⇩p› ‹(i::nat) ≠ (?j2::nat) ⟹ val (UPQ.taylor_term (x::((nat ⇒ int) × (nat ⇒ int)) set) (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) i ∙ (t::((nat ⇒ int) × (nat ⇒ int)) set)) < val (UPQ.taylor_term x f ?j2 ∙ t)›*) UPQ.taylor_closed (*‹⟦?f ∈ carrier (UP Q⇩p); ?a ∈ carrier Q⇩p⟧ ⟹ UPQ.taylor ?a ?f ∈ carrier (UP Q⇩p)›*) UPQ.deg_leE (*‹⟦?p ∈ carrier (UP Q⇩p); deg Q⇩p ?p < ?k⟧ ⟹ ?p ?k = 𝟬›*) by blast have F1: "(UPQ.taylor_term x f i ∙ t) = 𝟬" using UPQ.to_fun_taylor_term[of f t x i] (*‹⟦f ∈ carrier (UP Q⇩p); t ∈ carrier Q⇩p; x ∈ carrier Q⇩p⟧ ⟹ UPQ.taylor_term x f i ∙ t = UPQ.taylor x f i ⊗ (t ⊖ x) [^] i›*) unfolding F0 (*goal: ‹UPQ.taylor_term (x::((nat ⇒ int) × (nat ⇒ int)) set) (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (i::nat) ∙ (t::((nat ⇒ int) × (nat ⇒ int)) set) = 𝟬›*) using assms (*‹f ∈ carrier (UP Q⇩p)› ‹x ∈ carrier Q⇩p› ‹t ∈ carrier Q⇩p› ‹i ≠ ?j2 ⟹ val (UPQ.taylor_term x f i ∙ t) < val (UPQ.taylor_term x f ?j2 ∙ t)›*) Qp.cring_simprules(2) (*‹𝟬 ∈ carrier Q⇩p›*) Qp.cring_simprules(4) (*‹⟦?x ∈ carrier Q⇩p; ?y ∈ carrier Q⇩p⟧ ⟹ ?x ⊖ ?y ∈ carrier Q⇩p›*) Qp.integral_iff (*‹⟦?a ∈ carrier Q⇩p; ?b ∈ carrier Q⇩p⟧ ⟹ (?a ⊗ ?b = 𝟬) = (?a = 𝟬 ∨ ?b = 𝟬)›*) Qp.nat_pow_closed (*‹?x ∈ carrier Q⇩p ⟹ ?x [^] ?n ∈ carrier Q⇩p›*) by presburger show "?thesis" (*goal: ‹val (f ∙ t) = val (UPQ.taylor_term x f i ∙ t)›*) using assms(4)[of "Suc i"] (*‹i ≠ Suc i ⟹ val (UPQ.taylor_term x f i ∙ t) < val (UPQ.taylor_term x f (Suc i) ∙ t)›*) unfolding F1 (*goal: ‹val (f ∙ t) = val 𝟬›*) by (metis eint_ord_code( (*‹(∞ < ?q) = False›*) 6) local.val_zero (*‹val 𝟬 = ∞›*) n_not_Suc_n (*‹?n ≠ Suc ?n›*)) qed qed (**************************************************************************************************) (**************************************************************************************************) subsection‹Hensel's Lemma for ‹p›-adic fields› (**************************************************************************************************) (**************************************************************************************************) theorem hensels_lemma: assumes "f ∈ carrier (UP Q⇩p)" assumes "a ∈ 𝒪⇩p" assumes "gauss_norm f ≥ 0" assumes "val (f∙a) > 2*val ((pderiv f)∙a)" shows "∃!α ∈ 𝒪⇩p. f∙α = 𝟬 ∧ val (a ⊖ α) > val ((pderiv f)∙a)" proof (-) (*goal: ‹∃!α. α ∈ 𝒪⇩p ∧ f ∙ α = 𝟬 ∧ val (UPQ.pderiv f ∙ a) < val (a ⊖ α)›*) have a_closed: "a ∈ carrier Q⇩p" using assms (*‹(f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹a ∈ 𝒪⇩p› ‹0 ≤ gauss_norm f› ‹eint 2 * val (UPQ.pderiv f ∙ a) < val (f ∙ a)›*) val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) by auto have f_nonzero: "f ≠ 𝟬⇘UP Q⇩p⇙" proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹¬ f ≠ 𝟬⇘UP Q⇩p⇙ ⟹ False›*) assume N: "¬ f ≠ 𝟬⇘UP Q⇩p⇙" (*‹¬ (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ≠ 𝟬⇘UP Q⇩p⇙›*) then have 0: "pderiv f = 𝟬⇘UP Q⇩p⇙" using UPQ.deg_zero (*‹deg Q⇩p 𝟬⇘UP Q⇩p⇙ = (0::nat)›*) UPQ.pderiv_deg_0 (*‹⟦(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); deg Q⇩p ?f = (0::nat)⟧ ⟹ UPQ.pderiv ?f = 𝟬⇘UP Q⇩p⇙›*) by blast have 1: "f = 𝟬⇘UP Q⇩p⇙" using N (*‹¬ f ≠ 𝟬⇘UP Q⇩p⇙›*) by auto have 2: "eint 2 * val (UPQ.pderiv 𝟬⇘UP Q⇩p⇙ ∙ a) = ∞" by (simp add: UPQ.to_fun_zero (*‹?a ∈ carrier Q⇩p ⟹ 𝟬⇘UP Q⇩p⇙ ∙ ?a = 𝟬›*) local.a_closed (*‹a ∈ carrier Q⇩p›*) local.val_zero (*‹val 𝟬 = ∞›*)) show False using assms (*‹f ∈ carrier (UP Q⇩p)› ‹a ∈ 𝒪⇩p› ‹(0::eint) ≤ gauss_norm (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)› ‹eint 2 * val (UPQ.pderiv f ∙ a) < val (f ∙ a)›*) a_closed (*‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p›*) unfolding "2" "1" (*goal: ‹False›*) using eint_ord_simps(6) (*‹(∞ < ?q) = False›*) by blast qed obtain h where h_def: "h = to_Zp_poly f" (*goal: ‹(⋀h. h = to_Zp_poly f ⟹ thesis) ⟹ thesis›*) by blast have h_closed: "h ∈ carrier (UP Z⇩p)" unfolding h_def (*goal: ‹to_Zp_poly (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring))›*) using assms (*‹f ∈ carrier (UP Q⇩p)› ‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p› ‹(0::eint) ≤ gauss_norm (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)› ‹eint 2 * val (UPQ.pderiv f ∙ a) < val (f ∙ a)›*) by (simp add: to_Zp_poly_closed (*‹⟦?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g⟧ ⟹ to_Zp_poly ?g ∈ carrier (UP Z⇩p)›*)) have h_deriv: "Zp.pderiv h = to_Zp_poly (pderiv f)" unfolding h_def (*goal: ‹Zp.pderiv (to_Zp_poly f) = to_Zp_poly (UPQ.pderiv f)›*) using to_Zp_poly_pderiv[of f] (*‹⟦f ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm f⟧ ⟹ to_Zp_poly (UPQ.pderiv f) = Zp.pderiv (to_Zp_poly f)›*) assms (*‹(f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹a ∈ 𝒪⇩p› ‹0 ≤ gauss_norm f› ‹eint 2 * val (UPQ.pderiv f ∙ a) < val (f ∙ a)›*) by auto have 0: "to_Zp (f∙a) = to_function Z⇩p h (to_Zp a)" unfolding h_def (*goal: ‹to_Zp (f ∙ a) = to_function Z⇩p (to_Zp_poly f) (to_Zp a)›*) using assms (*‹f ∈ carrier (UP Q⇩p)› ‹a ∈ 𝒪⇩p› ‹0 ≤ gauss_norm f› ‹eint 2 * val (UPQ.pderiv f ∙ a) < val (f ∙ a)›*) a_closed (*‹a ∈ carrier Q⇩p›*) by (simp add: UPQ.to_fun_def (*‹(∙) ?f ≡ to_function Q⇩p ?f›*) to_Zp_poly_eval (*‹⟦?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g; ?a ∈ 𝒪⇩p⟧ ⟹ to_Zp (to_function Q⇩p ?g ?a) = to_function Z⇩p (to_Zp_poly ?g) (to_Zp ?a)›*)) have 1: "to_Zp ((pderiv f)∙a) = to_function Z⇩p (Zp.pderiv h) (to_Zp a)" unfolding h_deriv (*goal: ‹to_Zp (UPQ.pderiv f ∙ a) = to_function Z⇩p (to_Zp_poly (UPQ.pderiv f)) (to_Zp a)›*) using assms (*‹f ∈ carrier (UP Q⇩p)› ‹a ∈ 𝒪⇩p› ‹0 ≤ gauss_norm f› ‹eint 2 * val (UPQ.pderiv f ∙ a) < val (f ∙ a)›*) a_closed (*‹a ∈ carrier Q⇩p›*) UPQ.pderiv_closed (*‹?p ∈ carrier (UP Q⇩p) ⟹ UPQ.pderiv ?p ∈ carrier (UP Q⇩p)›*) UPQ.to_fun_def (*‹(∙) (?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ≡ to_function Q⇩p ?f›*) eint_ord_trans (*‹⟦?a ≤ ?b; ?b ≤ ?c⟧ ⟹ ?a ≤ ?c›*) gauss_norm_pderiv (*‹?g ∈ carrier (UP Q⇩p) ⟹ gauss_norm ?g ≤ gauss_norm (UPQ.pderiv ?g)›*) to_Zp_poly_eval (*‹⟦(?g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (0::eint) ≤ gauss_norm ?g; (?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p⟧ ⟹ to_Zp (to_function Q⇩p ?g ?a) = to_function (Z⇩p::(nat ⇒ int) ring) (to_Zp_poly ?g) (to_Zp ?a)›*) by presburger have 2: "val (f∙a) = val_Zp (to_function Z⇩p h (to_Zp a))" proof (-) (*goal: ‹val (f ∙ a) = val_Zp (to_function Z⇩p h (to_Zp a))›*) have 20: "f∙a ∈ 𝒪⇩p" using assms (*‹f ∈ carrier (UP Q⇩p)› ‹a ∈ 𝒪⇩p› ‹0 ≤ gauss_norm f› ‹eint (2::int) * val (UPQ.pderiv (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ (a::((nat ⇒ int) × (nat ⇒ int)) set)) < val (f ∙ a)›*) positive_gauss_norm_eval (*‹⟦(?g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (0::eint) ≤ gauss_norm ?g; (?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p⟧ ⟹ ?g ∙ ?a ∈ 𝒪⇩p›*) by blast have 21: "val (f∙a) = val_Zp (to_Zp (f∙a))" using "20" (*‹f ∙ a ∈ 𝒪⇩p›*) by (simp add: to_Zp_val (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ val_Zp (to_Zp ?a) = val ?a›*)) show "?thesis" (*goal: ‹val (f ∙ a) = val_Zp (to_function Z⇩p h (to_Zp a))›*) unfolding "21" "0" (*goal: ‹val_Zp (to_function Z⇩p h (to_Zp a)) = val_Zp (to_function Z⇩p h (to_Zp a))›*) by blast qed have 3: "val ((pderiv f)∙a) = val_Zp ( to_function Z⇩p (Zp.pderiv h) (to_Zp a))" proof (-) (*goal: ‹val (UPQ.pderiv f ∙ a) = val_Zp (to_function Z⇩p (Zp.pderiv h) (to_Zp a))›*) have 30: "(pderiv f)∙a ∈ 𝒪⇩p" using positive_gauss_norm_eval (*‹⟦(?g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (0::eint) ≤ gauss_norm ?g; (?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p⟧ ⟹ ?g ∙ ?a ∈ 𝒪⇩p›*) assms (*‹f ∈ carrier (UP Q⇩p)› ‹a ∈ 𝒪⇩p› ‹0 ≤ gauss_norm f› ‹eint (2::int) * val (UPQ.pderiv (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ (a::((nat ⇒ int) × (nat ⇒ int)) set)) < val (f ∙ a)›*) gauss_norm_pderiv (*‹?g ∈ carrier (UP Q⇩p) ⟹ gauss_norm ?g ≤ gauss_norm (UPQ.pderiv ?g)›*) by (meson UPQ.pderiv_closed (*‹?p ∈ carrier (UP Q⇩p) ⟹ UPQ.pderiv ?p ∈ carrier (UP Q⇩p)›*) eint_ord_trans (*‹⟦?a ≤ ?b; ?b ≤ ?c⟧ ⟹ ?a ≤ ?c›*)) have 31: "val ((pderiv f)∙a) = val_Zp (to_Zp ((pderiv f)∙a))" using "30" (*‹UPQ.pderiv f ∙ a ∈ 𝒪⇩p›*) by (simp add: to_Zp_val (*‹?a ∈ 𝒪⇩p ⟹ val_Zp (to_Zp ?a) = val ?a›*)) show "?thesis" (*goal: ‹val (UPQ.pderiv f ∙ a) = val_Zp (to_function Z⇩p (Zp.pderiv h) (to_Zp a))›*) unfolding "31" "1" (*goal: ‹val_Zp (to_function (Z⇩p::(nat ⇒ int) ring) (Zp.pderiv (h::nat ⇒ nat ⇒ int)) (to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set))) = val_Zp (to_function Z⇩p (Zp.pderiv h) (to_Zp a))›*) by blast qed have 4: "∃!α. α ∈ carrier Z⇩p ∧ Zp.to_fun (to_Zp_poly f) α = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp a ⊖⇘Z⇩p⇙ α)" apply (rule hensels_lemma' (*‹⟦?f ∈ carrier (UP Z⇩p); ?a ∈ carrier Z⇩p; eint 2 * val_Zp (Zp.to_fun (Zp.pderiv ?f) ?a) < val_Zp (Zp.to_fun ?f ?a)⟧ ⟹ ∃!α. α ∈ carrier Z⇩p ∧ Zp.to_fun ?f α = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv ?f) ?a) < val_Zp (?a ⊖⇘Z⇩p⇙ α)›*)) (*goal: ‹∃!α. α ∈ carrier Z⇩p ∧ Zp.to_fun (to_Zp_poly f) α = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp a ⊖⇘Z⇩p⇙ α)›*) using h_closed (*‹h ∈ carrier (UP Z⇩p)›*) h_def (*‹(h::nat ⇒ nat ⇒ int) = to_Zp_poly (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)›*) apply blast (*top goal: ‹to_Zp_poly f ∈ carrier (UP Z⇩p)› and 2 goals remain*) using assms (*‹(f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p› ‹0 ≤ gauss_norm f› ‹eint 2 * val (UPQ.pderiv f ∙ a) < val (f ∙ a)›*) local.a_closed (*‹a ∈ carrier Q⇩p›*) to_Zp_closed (*‹?a ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier Z⇩p›*) apply blast (*top goal: ‹to_Zp a ∈ carrier Z⇩p› and 1 goal remains*) using assms (*‹f ∈ carrier (UP Q⇩p)› ‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p› ‹0 ≤ gauss_norm f› ‹eint (2::int) * val (UPQ.pderiv (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ (a::((nat ⇒ int) × (nat ⇒ int)) set)) < val (f ∙ a)›*) unfolding "2" "3" h_def Zp.to_fun_def (*goal: ‹eint 2 * val_Zp (to_function Z⇩p (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_function Z⇩p (to_Zp_poly f) (to_Zp a))›*) by blast obtain α where "α_def": "α ∈ carrier Z⇩p ∧ Zp.to_fun (to_Zp_poly f) α = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp a ⊖⇘Z⇩p⇙ α) ∧ (∀x. x ∈ carrier Z⇩p ∧ Zp.to_fun (to_Zp_poly f) x = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp a ⊖⇘Z⇩p⇙ x) ⟶ x = α)" (*goal: ‹(⋀α. α ∈ carrier Z⇩p ∧ Zp.to_fun (to_Zp_poly f) α = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp a ⊖⇘Z⇩p⇙ α) ∧ (∀x. x ∈ carrier Z⇩p ∧ Zp.to_fun (to_Zp_poly f) x = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp a ⊖⇘Z⇩p⇙ x) ⟶ x = α) ⟹ thesis) ⟹ thesis›*) using "4" (*‹∃!α. α ∈ carrier Z⇩p ∧ Zp.to_fun (to_Zp_poly f) α = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp a ⊖⇘Z⇩p⇙ α)›*) by blast obtain β where "β_def": "β = ι α" (*goal: ‹(⋀β. β = ι α ⟹ thesis) ⟹ thesis›*) by blast have "β_closed": "β ∈ 𝒪⇩p" using "α_def" (*‹α ∈ carrier Z⇩p ∧ Zp.to_fun (to_Zp_poly f) α = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp a ⊖⇘Z⇩p⇙ α) ∧ (∀x. x ∈ carrier Z⇩p ∧ Zp.to_fun (to_Zp_poly f) x = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp a ⊖⇘Z⇩p⇙ x) ⟶ x = α)›*) unfolding "β_def" (*goal: ‹ι α ∈ 𝒪⇩p›*) by simp have 5: "(Zp.to_fun (to_Zp_poly f) α) = to_Zp (f∙β)" using "β_closed" (*‹(β::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p›*) to_Zp_poly_eval[of f β] (*‹⟦(f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (0::eint) ≤ gauss_norm f; (β::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p⟧ ⟹ to_Zp (to_function Q⇩p f β) = to_function (Z⇩p::(nat ⇒ int) ring) (to_Zp_poly f) (to_Zp β)›*) assms (*‹(f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹a ∈ 𝒪⇩p› ‹0 ≤ gauss_norm f› ‹eint (2::int) * val (UPQ.pderiv (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ (a::((nat ⇒ int) × (nat ⇒ int)) set)) < val (f ∙ a)›*) unfolding "β_def" UPQ.to_fun_def (*goal: ‹Zp.to_fun (to_Zp_poly f) α = to_Zp (to_function Q⇩p f (ι α))›*) by (simp add: Zp.to_fun_def (*‹Zp.to_fun ?f ≡ to_function Z⇩p ?f›*) α_def (*‹α ∈ carrier Z⇩p ∧ Zp.to_fun (to_Zp_poly f) α = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp a ⊖⇘Z⇩p⇙ α) ∧ (∀x. x ∈ carrier Z⇩p ∧ Zp.to_fun (to_Zp_poly f) x = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp a ⊖⇘Z⇩p⇙ x) ⟶ x = α)›*) inc_to_Zp (*‹?b ∈ carrier Z⇩p ⟹ to_Zp (ι ?b) = ?b›*)) have 6: "to_Zp (f∙β) = 𝟬⇘Z⇩p⇙" using "5" (*‹Zp.to_fun (to_Zp_poly f) α = to_Zp (f ∙ β)›*) "α_def" (*‹α ∈ carrier Z⇩p ∧ Zp.to_fun (to_Zp_poly f) α = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp a ⊖⇘Z⇩p⇙ α) ∧ (∀x. x ∈ carrier Z⇩p ∧ Zp.to_fun (to_Zp_poly f) x = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp a ⊖⇘Z⇩p⇙ x) ⟶ x = α)›*) by auto have "β_closed": "β ∈ 𝒪⇩p" unfolding "β_def" (*goal: ‹(ι::(nat ⇒ int) ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (α::nat ⇒ int) ∈ 𝒪⇩p›*) using "α_def" (*‹α ∈ carrier Z⇩p ∧ Zp.to_fun (to_Zp_poly f) α = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp a ⊖⇘Z⇩p⇙ α) ∧ (∀x. x ∈ carrier Z⇩p ∧ Zp.to_fun (to_Zp_poly f) x = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp a ⊖⇘Z⇩p⇙ x) ⟶ x = α)›*) by simp have 7: "(f∙β) = 𝟬" using "6" (*‹to_Zp (f ∙ β) = 𝟬⇘Z⇩p⇙›*) assms (*‹f ∈ carrier (UP Q⇩p)› ‹a ∈ 𝒪⇩p› ‹(0::eint) ≤ gauss_norm (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)› ‹eint 2 * val (UPQ.pderiv f ∙ a) < val (f ∙ a)›*) unfolding "β_def" (*goal: ‹f ∙ ι α = 𝟬›*) by (metis β_closed (*‹β ∈ 𝒪⇩p›*) β_def (*‹β = ι α›*) inc_of_zero (*‹ι 𝟬⇘Z⇩p⇙ = 𝟬›*) positive_gauss_norm_eval (*‹⟦?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g; ?a ∈ 𝒪⇩p⟧ ⟹ ?g ∙ ?a ∈ 𝒪⇩p›*) to_Zp_inc (*‹?a ∈ 𝒪⇩p ⟹ ι (to_Zp ?a) = ?a›*)) have 8: "α = to_Zp β" unfolding "β_def" (*goal: ‹α = to_Zp (ι α)›*) using "α_def" (*‹(α::nat ⇒ int) ∈ carrier (Z⇩p::(nat ⇒ int) ring) ∧ Zp.to_fun (to_Zp_poly (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)) α = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set))) < val_Zp (to_Zp a ⊖⇘Z⇩p⇙ α) ∧ (∀x::nat ⇒ int. x ∈ carrier Z⇩p ∧ Zp.to_fun (to_Zp_poly f) x = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp a ⊖⇘Z⇩p⇙ x) ⟶ x = α)›*) by (simp add: inc_to_Zp (*‹?b ∈ carrier Z⇩p ⟹ to_Zp (ι ?b) = ?b›*)) have 9: "to_Zp a ⊖⇘Z⇩p⇙ α = to_Zp (a ⊖ β)" unfolding "8" (*goal: ‹to_Zp a ⊖⇘Z⇩p⇙ to_Zp β = to_Zp (a ⊖ β)›*) using assms(2) (*‹a ∈ 𝒪⇩p›*) "β_closed" (*‹β ∈ 𝒪⇩p›*) by (simp add: to_Zp_minus (*‹⟦?a ∈ 𝒪⇩p; ?b ∈ 𝒪⇩p⟧ ⟹ to_Zp (?a ⊖ ?b) = to_Zp ?a ⊖⇘Z⇩p⇙ to_Zp ?b›*)) have 10: "val (a ⊖ β) = val_Zp (to_Zp a ⊖⇘Z⇩p⇙ α)" unfolding "9" (*goal: ‹val ((a::((nat ⇒ int) × (nat ⇒ int)) set) ⊖ (β::((nat ⇒ int) × (nat ⇒ int)) set)) = val_Zp (to_Zp (a ⊖ β))›*) using "β_closed" (*‹β ∈ 𝒪⇩p›*) assms(2) (*‹a ∈ 𝒪⇩p›*) to_Zp_val (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ val_Zp (to_Zp ?a) = val ?a›*) val_ring_minus_closed (*‹⟦?a ∈ 𝒪⇩p; ?b ∈ 𝒪⇩p⟧ ⟹ ?a ⊖ ?b ∈ 𝒪⇩p›*) by presburger have 11: "val (a ⊖ β) > val ((pderiv f)∙a)" using "α_def" (*‹(α::nat ⇒ int) ∈ carrier (Z⇩p::(nat ⇒ int) ring) ∧ Zp.to_fun (to_Zp_poly (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)) α = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set))) < val_Zp (to_Zp a ⊖⇘Z⇩p⇙ α) ∧ (∀x::nat ⇒ int. x ∈ carrier Z⇩p ∧ Zp.to_fun (to_Zp_poly f) x = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp a ⊖⇘Z⇩p⇙ x) ⟶ x = α)›*) unfolding "9" "10" "3" h_def (*goal: ‹val_Zp (to_function Z⇩p (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp (a ⊖ β))›*) by (simp add: Zp.to_fun_def (*‹Zp.to_fun (?f::nat ⇒ nat ⇒ int) ≡ to_function (Z⇩p::(nat ⇒ int) ring) ?f›*)) have 12: "β ∈ 𝒪⇩p ∧ f ∙ β = 𝟬 ∧ val (UPQ.pderiv f ∙ a) < val (a ⊖ β)" using "11" (*‹val (UPQ.pderiv f ∙ a) < val (a ⊖ β)›*) "7" (*‹(f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ (β::((nat ⇒ int) × (nat ⇒ int)) set) = 𝟬›*) "β_closed" (*‹β ∈ 𝒪⇩p›*) by linarith have 13: "∀x. x∈ 𝒪⇩p ∧ f ∙ x = 𝟬 ∧ val (UPQ.pderiv f ∙ a) < val (a ⊖ x) ⟶ x = β" apply rule (*goal: ‹∀x. x ∈ 𝒪⇩p ∧ f ∙ x = 𝟬 ∧ val (UPQ.pderiv f ∙ a) < val (a ⊖ x) ⟶ x = β›*) proof (rule) (*goal: ‹⋀x. x ∈ 𝒪⇩p ∧ f ∙ x = 𝟬 ∧ val (UPQ.pderiv f ∙ a) < val (a ⊖ x) ⟹ x = β›*) fix x assume A: "x ∈ 𝒪⇩p ∧ f ∙ x = 𝟬 ∧ val (UPQ.pderiv f ∙ a) < val (a ⊖ x)" (*‹(x::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ∧ (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ x = 𝟬 ∧ val (UPQ.pderiv f ∙ (a::((nat ⇒ int) × (nat ⇒ int)) set)) < val (a ⊖ x)›*) obtain y where y_def: "y = to_Zp x" (*goal: ‹(⋀y. y = to_Zp x ⟹ thesis) ⟹ thesis›*) by blast have y_closed: "y ∈ carrier Z⇩p" unfolding y_def (*goal: ‹to_Zp x ∈ carrier Z⇩p›*) using A (*‹x ∈ 𝒪⇩p ∧ f ∙ x = 𝟬 ∧ val (UPQ.pderiv f ∙ a) < val (a ⊖ x)›*) by (simp add: to_Zp_closed (*‹?a ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier Z⇩p›*) val_ring_memE( (*‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) 2)) have eval: "Zp.to_fun (to_Zp_poly f) y = 𝟬⇘Z⇩p⇙" unfolding y_def (*goal: ‹Zp.to_fun (to_Zp_poly f) (to_Zp x) = 𝟬⇘Z⇩p⇙›*) using A (*‹x ∈ 𝒪⇩p ∧ f ∙ x = 𝟬 ∧ val (UPQ.pderiv f ∙ a) < val (a ⊖ x)›*) assms (*‹f ∈ carrier (UP Q⇩p)› ‹a ∈ 𝒪⇩p› ‹0 ≤ gauss_norm f› ‹eint 2 * val (UPQ.pderiv f ∙ a) < val (f ∙ a)›*) by (metis UPQ.to_fun_def (*‹(∙) ?f ≡ to_function Q⇩p ?f›*) Zp.to_fun_def (*‹Zp.to_fun ?f ≡ to_function Z⇩p ?f›*) to_Zp_poly_eval (*‹⟦?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g; ?a ∈ 𝒪⇩p⟧ ⟹ to_Zp (to_function Q⇩p ?g ?a) = to_function Z⇩p (to_Zp_poly ?g) (to_Zp ?a)›*) to_Zp_zero (*‹to_Zp 𝟬 = 𝟬⇘Z⇩p⇙›*)) have 0: "to_Zp a ⊖⇘Z⇩p⇙ y = to_Zp (a ⊖ x)" unfolding y_def (*goal: ‹to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set) ⊖⇘Z⇩p::(nat ⇒ int) ring⇙ to_Zp (x::((nat ⇒ int) × (nat ⇒ int)) set) = to_Zp (a ⊖ x)›*) using A (*‹x ∈ 𝒪⇩p ∧ f ∙ x = 𝟬 ∧ val (UPQ.pderiv f ∙ a) < val (a ⊖ x)›*) assms (*‹(f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹a ∈ 𝒪⇩p› ‹0 ≤ gauss_norm f› ‹eint 2 * val (UPQ.pderiv f ∙ a) < val (f ∙ a)›*) by (simp add: to_Zp_minus (*‹⟦(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p; (?b::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p⟧ ⟹ to_Zp (?a ⊖ ?b) = to_Zp ?a ⊖⇘Z⇩p::(nat ⇒ int) ring⇙ to_Zp ?b›*)) have q: " val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) = val (UPQ.pderiv f ∙ a)" by (simp add: "3" (*‹val (UPQ.pderiv f ∙ a) = val_Zp (to_function Z⇩p (Zp.pderiv h) (to_Zp a))›*) Zp.to_fun_def (*‹Zp.to_fun ?f ≡ to_function Z⇩p ?f›*) h_def (*‹h = to_Zp_poly f›*)) have 1: "y ∈ carrier Z⇩p ∧ Zp.to_fun (to_Zp_poly f) y = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp a ⊖⇘Z⇩p⇙ y)" unfolding "0" eval Zp.to_fun_def h_def (*goal: ‹y ∈ carrier Z⇩p ∧ to_function Z⇩p (to_Zp_poly f) y = 𝟬⇘Z⇩p⇙ ∧ val_Zp (to_function Z⇩p (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp (a ⊖ x))›*) apply (intro conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*) y_closed (*‹y ∈ carrier Z⇩p›*)) (*goal: ‹y ∈ carrier Z⇩p ∧ to_function Z⇩p (to_Zp_poly f) y = 𝟬⇘Z⇩p⇙ ∧ val_Zp (to_function Z⇩p (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp (a ⊖ x))›*) using eval (*‹Zp.to_fun (to_Zp_poly (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)) (y::nat ⇒ int) = 𝟬⇘Z⇩p::(nat ⇒ int) ring⇙›*) Zp.to_fun_def (*‹Zp.to_fun ?f ≡ to_function Z⇩p ?f›*) apply (simp; fail) (*top goal: ‹to_function Z⇩p (to_Zp_poly f) y = 𝟬⇘Z⇩p⇙› and 1 goal remains*) using A (*‹x ∈ 𝒪⇩p ∧ f ∙ x = 𝟬 ∧ val (UPQ.pderiv f ∙ a) < val (a ⊖ x)›*) unfolding "0" eval Zp.to_fun_def h_def "3" (*goal: ‹val_Zp (to_function Z⇩p (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp (a ⊖ x))›*) using assms(2) (*‹a ∈ 𝒪⇩p›*) to_Zp_val (*‹?a ∈ 𝒪⇩p ⟹ val_Zp (to_Zp ?a) = val ?a›*) val_ring_minus_closed (*‹⟦?a ∈ 𝒪⇩p; ?b ∈ 𝒪⇩p⟧ ⟹ ?a ⊖ ?b ∈ 𝒪⇩p›*) by presburger have 2: "y = α" using "1" (*‹(y::nat ⇒ int) ∈ carrier (Z⇩p::(nat ⇒ int) ring) ∧ Zp.to_fun (to_Zp_poly (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)) y = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set))) < val_Zp (to_Zp a ⊖⇘Z⇩p⇙ y)›*) "α_def" (*‹α ∈ carrier Z⇩p ∧ Zp.to_fun (to_Zp_poly f) α = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp a ⊖⇘Z⇩p⇙ α) ∧ (∀x. x ∈ carrier Z⇩p ∧ Zp.to_fun (to_Zp_poly f) x = 𝟬⇘Z⇩p⇙ ∧ val_Zp (Zp.to_fun (Zp.pderiv (to_Zp_poly f)) (to_Zp a)) < val_Zp (to_Zp a ⊖⇘Z⇩p⇙ x) ⟶ x = α)›*) by blast show "x = β" using y_def (*‹y = to_Zp x›*) unfolding "2" "8" (*goal: ‹x = β›*) using A (*‹(x::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ∧ (f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∙ x = 𝟬 ∧ val (UPQ.pderiv f ∙ (a::((nat ⇒ int) × (nat ⇒ int)) set)) < val (a ⊖ x)›*) "β_closed" (*‹β ∈ 𝒪⇩p›*) by (metis to_Zp_inc (*‹?a ∈ 𝒪⇩p ⟹ ι (to_Zp ?a) = ?a›*)) qed show "∃!α. α ∈ 𝒪⇩p ∧ f ∙ α = 𝟬 ∧ val (UPQ.pderiv f ∙ a) < val (a ⊖ α)" using "12" (*‹β ∈ 𝒪⇩p ∧ f ∙ β = 𝟬 ∧ val (UPQ.pderiv f ∙ a) < val (a ⊖ β)›*) "13" (*‹∀x. x ∈ 𝒪⇩p ∧ f ∙ x = 𝟬 ∧ val (UPQ.pderiv f ∙ a) < val (a ⊖ x) ⟶ x = β›*) by metis qed lemma nth_root_poly_root_fixed: assumes "(n::nat) > 1" assumes "a ∈ 𝒪⇩p" assumes "val (𝟭 ⊖⇘Q⇩p⇙ a) > 2* val ([n]⋅𝟭)" shows "(∃! b ∈ 𝒪⇩p. (b[^]n) = a ∧ val (b ⊖ 𝟭) > val ([n]⋅𝟭))" proof (-) (*goal: ‹∃!b. b ∈ 𝒪⇩p ∧ b [^] n = a ∧ val ([n] ⋅ 𝟭) < val (b ⊖ 𝟭)›*) obtain f where f_def: "f = up_ring.monom (UP Q⇩p) 𝟭 n ⊖⇘UP Q⇩p⇙ up_ring.monom (UP Q⇩p) a 0" (*goal: ‹(⋀f. f = monom (UP Q⇩p) 𝟭 n ⊖⇘UP Q⇩p⇙ monom (UP Q⇩p) a 0 ⟹ thesis) ⟹ thesis›*) by blast have f_closed: "f ∈ carrier (UP Q⇩p)" unfolding f_def (*goal: ‹monom (UP Q⇩p) 𝟭 n ⊖⇘UP Q⇩p⇙ monom (UP Q⇩p) a 0 ∈ carrier (UP Q⇩p)›*) apply (rule UPQ.P.ring_simprules (*‹⟦?x ∈ carrier (UP Q⇩p); ?y ∈ carrier (UP Q⇩p)⟧ ⟹ ?x ⊕⇘UP Q⇩p⇙ ?y ∈ carrier (UP Q⇩p)› ‹𝟬⇘UP Q⇩p⇙ ∈ carrier (UP Q⇩p)› ‹?x ∈ carrier (UP Q⇩p) ⟹ ⊖⇘UP Q⇩p⇙ ?x ∈ carrier (UP Q⇩p)› ‹⟦?x ∈ carrier (UP Q⇩p); ?y ∈ carrier (UP Q⇩p)⟧ ⟹ ?x ⊖⇘UP Q⇩p⇙ ?y ∈ carrier (UP Q⇩p)› ‹⟦?x ∈ carrier (UP Q⇩p); ?y ∈ carrier (UP Q⇩p)⟧ ⟹ ?x ⊗⇘UP Q⇩p⇙ ?y ∈ carrier (UP Q⇩p)› ‹𝟭⇘UP Q⇩p⇙ ∈ carrier (UP Q⇩p)› ‹⟦?x ∈ carrier (UP Q⇩p); ?y ∈ carrier (UP Q⇩p); ?z ∈ carrier (UP Q⇩p)⟧ ⟹ ?x ⊕⇘UP Q⇩p⇙ ?y ⊕⇘UP Q⇩p⇙ ?z = ?x ⊕⇘UP Q⇩p⇙ (?y ⊕⇘UP Q⇩p⇙ ?z)› ‹?x ∈ carrier (UP Q⇩p) ⟹ 𝟬⇘UP Q⇩p⇙ ⊕⇘UP Q⇩p⇙ ?x = ?x› ‹?x ∈ carrier (UP Q⇩p) ⟹ ⊖⇘UP Q⇩p⇙ ?x ⊕⇘UP Q⇩p⇙ ?x = 𝟬⇘UP Q⇩p⇙› ‹⟦?x ∈ carrier (UP Q⇩p); ?y ∈ carrier (UP Q⇩p)⟧ ⟹ ?x ⊕⇘UP Q⇩p⇙ ?y = ?y ⊕⇘UP Q⇩p⇙ ?x› ‹⟦?x ∈ carrier (UP Q⇩p); ?y ∈ carrier (UP Q⇩p); ?z ∈ carrier (UP Q⇩p)⟧ ⟹ ?x ⊗⇘UP Q⇩p⇙ ?y ⊗⇘UP Q⇩p⇙ ?z = ?x ⊗⇘UP Q⇩p⇙ (?y ⊗⇘UP Q⇩p⇙ ?z)› ‹?x ∈ carrier (UP Q⇩p) ⟹ 𝟭⇘UP Q⇩p⇙ ⊗⇘UP Q⇩p⇙ ?x = ?x› and more 15 facts*)) (*goal: ‹monom (UP Q⇩p) 𝟭 n ⊖⇘UP Q⇩p⇙ monom (UP Q⇩p) a 0 ∈ carrier (UP Q⇩p)›*) apply (simp; fail) (*top goal: ‹monom (UP Q⇩p) 𝟭 (n::nat) ∈ carrier (UP Q⇩p)› and 1 goal remains*) using assms (*‹1 < n› ‹a ∈ 𝒪⇩p› ‹eint 2 * val ([n] ⋅ 𝟭) < val (𝟭 ⊖ a)›*) by (simp add: val_ring_memE( (*‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) 2)) have 0: "UPQ.pderiv (up_ring.monom (UP Q⇩p) a 0) = 𝟬⇘UP Q⇩p⇙" using assms (*‹1 < n› ‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p› ‹eint 2 * val ([n] ⋅ 𝟭) < val (𝟭 ⊖ a)›*) by (simp add: val_ring_memE( (*‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) 2)) have 1: "UPQ.pderiv (up_ring.monom (UP Q⇩p) (𝟭) n) = (up_ring.monom (UP Q⇩p) ([n]⋅𝟭) (n-1)) " using UPQ.pderiv_monom (*‹?a ∈ carrier Q⇩p ⟹ UPQ.pderiv (monom (UP Q⇩p) ?a ?n) = monom (UP Q⇩p) ([?n] ⋅ ?a) (?n - 1)›*) by blast have 2: "up_ring.monom (UP Q⇩p) 𝟭 n ∈ carrier (UP Q⇩p)" by simp have 3: "up_ring.monom (UP Q⇩p) a 0 ∈ carrier (UP Q⇩p)" using assms (*‹1 < n› ‹a ∈ 𝒪⇩p› ‹eint 2 * val ([n] ⋅ 𝟭) < val (𝟭 ⊖ a)›*) val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) by simp have 4: "UPQ.pderiv f = up_ring.monom (UP Q⇩p) ([n] ⋅ 𝟭) (n - 1) ⊖⇘UP Q⇩p⇙ 𝟬⇘UP Q⇩p⇙" using "2" (*‹monom (UP Q⇩p) 𝟭 n ∈ carrier (UP Q⇩p)›*) "3" (*‹monom (UP Q⇩p) (a::((nat ⇒ int) × (nat ⇒ int)) set) (0::nat) ∈ carrier (UP Q⇩p)›*) assms (*‹1 < n› ‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p› ‹eint 2 * val ([n] ⋅ 𝟭) < val (𝟭 ⊖ a)›*) val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) UPQ.pderiv_minus[of "up_ring.monom (UP Q⇩p) 𝟭 n" "up_ring.monom (UP Q⇩p) a 0"] (*‹⟦monom (UP Q⇩p) 𝟭 n ∈ carrier (UP Q⇩p); monom (UP Q⇩p) a 0 ∈ carrier (UP Q⇩p)⟧ ⟹ UPQ.pderiv (monom (UP Q⇩p) 𝟭 n ⊖⇘UP Q⇩p⇙ monom (UP Q⇩p) a 0) = UPQ.pderiv (monom (UP Q⇩p) 𝟭 n) ⊖⇘UP Q⇩p⇙ UPQ.pderiv (monom (UP Q⇩p) a 0)›*) unfolding f_def "0" "1" (*goal: ‹UPQ.pderiv (monom (UP Q⇩p) 𝟭 n ⊖⇘UP Q⇩p⇙ monom (UP Q⇩p) a 0) = monom (UP Q⇩p) ([n] ⋅ 𝟭) (n - 1) ⊖⇘UP Q⇩p⇙ 𝟬⇘UP Q⇩p⇙›*) by blast have 5: "UPQ.pderiv f = (up_ring.monom (UP Q⇩p) ([n]⋅𝟭) (n-1))" unfolding "4" a_minus_def (*goal: ‹monom (UP Q⇩p) ([(n::nat)] ⋅ 𝟭) (n - (1::nat)) ⊕⇘UP Q⇩p⇙ ⊖⇘UP Q⇩p⇙ 𝟬⇘UP Q⇩p⇙ = monom (UP Q⇩p) ([n] ⋅ 𝟭) (n - (1::nat))›*) by simp have a_closed: "a ∈ carrier Q⇩p" using assms (*‹1 < n› ‹a ∈ 𝒪⇩p› ‹eint 2 * val ([n] ⋅ 𝟭) < val (𝟭 ⊖ a)›*) val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) by blast have 6: "UPQ.pderiv f ∙ 𝟭 = [n]⋅𝟭 ⊗ 𝟭[^](n-1)" unfolding "5" (*goal: ‹monom (UP Q⇩p) ([n] ⋅ 𝟭) (n - 1) ∙ 𝟭 = [n] ⋅ 𝟭 ⊗ 𝟭 [^] (n - 1)›*) using a_closed (*‹a ∈ carrier Q⇩p›*) by (simp add: UPQ.to_fun_monom (*‹⟦(?c::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p; (?x::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p⟧ ⟹ monom (UP Q⇩p) ?c (?n::nat) ∙ ?x = ?c ⊗ ?x [^] ?n›*)) have 7: "val (𝟭 ⊖⇘Q⇩p⇙ a) > val 𝟭" proof (-) (*goal: ‹val 𝟭 < val (𝟭 ⊖ a)›*) have "eint 2 * val ([n] ⋅ 𝟭) ≥ 0" by (meson eint_ord_trans (*‹⟦(?a::eint) ≤ (?b::eint); ?b ≤ (?c::eint)⟧ ⟹ ?a ≤ ?c›*) eint_pos_int_times_ge (*‹⟦(0::eint) ≤ (?c::eint); (0::int) < (?n::int)⟧ ⟹ ?c ≤ eint ?n * ?c›*) val_of_nat_inc (*‹(0::eint) ≤ val ([(?k::nat)] ⋅ 𝟭)›*) zero_less_numeral (*‹(0::?'a) < numeral (?n::num)›*)) thus "?thesis" (*goal: ‹val 𝟭 < val (𝟭 ⊖ a)›*) using assms (*‹1 < n› ‹a ∈ 𝒪⇩p› ‹eint 2 * val ([n] ⋅ 𝟭) < val (𝟭 ⊖ a)›*) unfolding val_one (*goal: ‹0 < val (𝟭 ⊖ a)›*) by (simp add: Q⇩p_def (*‹Q⇩p ≡ Frac Z⇩p›*)) qed hence 8: "val a = val 𝟭" using a_closed (*‹a ∈ carrier Q⇩p›*) by (metis Qp.cring_simprules( (*‹𝟭 ∈ carrier Q⇩p›*) 6) ultrametric_equal_eq' (*‹⟦?x ∈ carrier Q⇩p; ?y ∈ carrier Q⇩p; val ?x < val (?x ⊖ ?y)⟧ ⟹ val ?x = val ?y›*)) have 9: "val (a [^] (n - 1)) = 0" by (simp add: "8" (*‹val a = val 𝟭›*) local.a_closed (*‹a ∈ carrier Q⇩p›*) val_zero_imp_val_pow_zero (*‹⟦?a ∈ carrier Q⇩p; val ?a = 0⟧ ⟹ val (?a [^] ?n) = 0›*)) have 10: "val ([n]⋅𝟭 ⊗ 𝟭[^](n-1)) = val ([n]⋅𝟭)" unfolding val_one "9" (*goal: ‹val ([n] ⋅ 𝟭 ⊗ 𝟭 [^] (n - 1)) = val ([n] ⋅ 𝟭)›*) by simp have 11: "0 ≤ gauss_norm f" proof (-) (*goal: ‹0 ≤ gauss_norm f›*) have p0: "gauss_norm (up_ring.monom (UP Q⇩p) 𝟭 n) ≥ 0" using gauss_norm_monom (*‹?a ∈ carrier Q⇩p ⟹ gauss_norm (monom (UP Q⇩p) ?a ?n) = val ?a›*) by simp have p1: "gauss_norm (up_ring.monom (UP Q⇩p) a 0) ≥ 0" using gauss_norm_monom (*‹?a ∈ carrier Q⇩p ⟹ gauss_norm (monom (UP Q⇩p) ?a ?n) = val ?a›*) assms (*‹1 < n› ‹a ∈ 𝒪⇩p› ‹eint 2 * val ([n] ⋅ 𝟭) < val (𝟭 ⊖ a)›*) val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) by simp have p2: "min (gauss_norm (up_ring.monom (UP Q⇩p) 𝟭 n)) (gauss_norm (up_ring.monom (UP Q⇩p) a 0)) ≥ 0" using p0 (*‹0 ≤ gauss_norm (monom (UP Q⇩p) 𝟭 n)›*) p1 (*‹0 ≤ gauss_norm (monom (UP Q⇩p) a 0)›*) by simp have p3: "0 ≤ gauss_norm (up_ring.monom (UP Q⇩p) 𝟭 n ⊖⇘UP Q⇩p⇙ up_ring.monom (UP Q⇩p) a 0)" using gauss_norm_ultrametric'[of "up_ring.monom (UP Q⇩p) 𝟭 n" "up_ring.monom (UP Q⇩p) a 0"] (*‹⟦monom (UP Q⇩p) 𝟭 n ∈ carrier (UP Q⇩p); monom (UP Q⇩p) a 0 ∈ carrier (UP Q⇩p)⟧ ⟹ min (gauss_norm (monom (UP Q⇩p) 𝟭 n)) (gauss_norm (monom (UP Q⇩p) a 0)) ≤ gauss_norm (monom (UP Q⇩p) 𝟭 n ⊖⇘UP Q⇩p⇙ monom (UP Q⇩p) a 0)›*) p2 (*‹0 ≤ min (gauss_norm (monom (UP Q⇩p) 𝟭 n)) (gauss_norm (monom (UP Q⇩p) a 0))›*) "2" (*‹monom (UP Q⇩p) 𝟭 n ∈ carrier (UP Q⇩p)›*) "3" (*‹monom (UP Q⇩p) a 0 ∈ carrier (UP Q⇩p)›*) eint_ord_trans (*‹⟦?a ≤ ?b; ?b ≤ ?c⟧ ⟹ ?a ≤ ?c›*) by blast show "?thesis" (*goal: ‹0 ≤ gauss_norm f›*) using p3 (*‹(0::eint) ≤ gauss_norm (monom (UP Q⇩p) 𝟭 (n::nat) ⊖⇘UP Q⇩p⇙ monom (UP Q⇩p) (a::((nat ⇒ int) × (nat ⇒ int)) set) (0::nat))›*) unfolding f_def (*goal: ‹0 ≤ gauss_norm (monom (UP Q⇩p) 𝟭 n ⊖⇘UP Q⇩p⇙ monom (UP Q⇩p) a 0)›*) by simp qed have 12: "⋀α. α ∈ 𝒪⇩p ⟹ f ∙ α = α[^]n ⊖ a" unfolding f_def (*goal: ‹⋀α. α ∈ 𝒪⇩p ⟹ (monom (UP Q⇩p) 𝟭 n ⊖⇘UP Q⇩p⇙ monom (UP Q⇩p) a 0) ∙ α = α [^] n ⊖ a›*) using a_closed (*‹a ∈ carrier Q⇩p›*) by (simp add: UPQ.to_fun_const (*‹⟦?a ∈ carrier Q⇩p; ?b ∈ carrier Q⇩p⟧ ⟹ monom (UP Q⇩p) ?a 0 ∙ ?b = ?a›*) UPQ.to_fun_diff (*‹⟦?p ∈ carrier (UP Q⇩p); ?q ∈ carrier (UP Q⇩p); ?a ∈ carrier Q⇩p⟧ ⟹ (?p ⊖⇘UP Q⇩p⇙ ?q) ∙ ?a = ?p ∙ ?a ⊖ ?q ∙ ?a›*) UPQ.to_fun_monic_monom (*‹?b ∈ carrier Q⇩p ⟹ monom (UP Q⇩p) 𝟭 ?n ∙ ?b = ?b [^] ?n›*) val_ring_memE( (*‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) 2)) have 13: "∃!α. α ∈ 𝒪⇩p ∧ f ∙ α = 𝟬 ∧ val (UPQ.pderiv f ∙ 𝟭) < val (𝟭 ⊖ α)" apply (rule hensels_lemma (*‹⟦?f ∈ carrier (UP Q⇩p); ?a ∈ 𝒪⇩p; 0 ≤ gauss_norm ?f; eint 2 * val (UPQ.pderiv ?f ∙ ?a) < val (?f ∙ ?a)⟧ ⟹ ∃!α. α ∈ 𝒪⇩p ∧ ?f ∙ α = 𝟬 ∧ val (UPQ.pderiv ?f ∙ ?a) < val (?a ⊖ α)›*), rule f_closed (*‹f ∈ carrier (UP Q⇩p)›*), rule one_in_val_ring (*‹𝟭 ∈ 𝒪⇩p›*), rule 11 (*‹0 ≤ gauss_norm f›*)) (*goal: ‹∃!α. α ∈ 𝒪⇩p ∧ f ∙ α = 𝟬 ∧ val (UPQ.pderiv f ∙ 𝟭) < val (𝟭 ⊖ α)›*) unfolding "6" "10" (*goal: ‹eint 2 * val ([n] ⋅ 𝟭) < val (f ∙ 𝟭)›*) using a_closed (*‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p›*) assms (*‹1 < n› ‹a ∈ 𝒪⇩p› ‹eint (2::int) * val ([(n::nat)] ⋅ 𝟭) < val (𝟭 ⊖ (a::((nat ⇒ int) × (nat ⇒ int)) set))›*) "12"[of 𝟭] (*‹𝟭 ∈ 𝒪⇩p ⟹ f ∙ 𝟭 = 𝟭 [^] n ⊖ a›*) assms(3) (*‹eint (2::int) * val ([(n::nat)] ⋅ 𝟭) < val (𝟭 ⊖ (a::((nat ⇒ int) × (nat ⇒ int)) set))›*) by (simp add: one_in_val_ring (*‹𝟭 ∈ 𝒪⇩p›*)) have 14: "⋀α. α ∈ 𝒪⇩p ⟹ α[^]n = a ⟷ f ∙ α = 𝟬" unfolding f_def (*goal: ‹⋀α::((nat ⇒ int) × (nat ⇒ int)) set. α ∈ 𝒪⇩p ⟹ (α [^] (n::nat) = (a::((nat ⇒ int) × (nat ⇒ int)) set)) = ((monom (UP Q⇩p) 𝟭 n ⊖⇘UP Q⇩p⇙ monom (UP Q⇩p) a (0::nat)) ∙ α = 𝟬)›*) using a_closed (*‹a ∈ carrier Q⇩p›*) "12" (*‹?α2 ∈ 𝒪⇩p ⟹ f ∙ ?α2 = ?α2 [^] n ⊖ a›*) f_def (*‹(f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) = monom (UP Q⇩p) 𝟭 (n::nat) ⊖⇘UP Q⇩p⇙ monom (UP Q⇩p) (a::((nat ⇒ int) × (nat ⇒ int)) set) (0::nat)›*) val_ring_memE(2) (*‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) by auto have 15: "val (UPQ.pderiv f ∙ 𝟭) = val ([n]⋅𝟭)" unfolding "6" "10" (*goal: ‹val ([n] ⋅ 𝟭) = val ([n] ⋅ 𝟭)›*) by auto have 16: "⋀α. α ∈ 𝒪⇩p ⟹ val (𝟭 ⊖ α) = val (α ⊖ 𝟭)" proof (-) (*goal: ‹⋀α. α ∈ 𝒪⇩p ⟹ val (𝟭 ⊖ α) = val (α ⊖ 𝟭)›*) have 17: "⋀α. α ∈ 𝒪⇩p ⟹ (𝟭 ⊖ α) = ⊖ (α ⊖ 𝟭)" using val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) by (meson Qp.minus_a_inv (*‹⟦(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p; (?b::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p⟧ ⟹ ?a ⊖ ?b = ⊖ (?b ⊖ ?a)›*) Qp.one_closed (*‹𝟭 ∈ carrier Q⇩p›*)) show "⋀α. α ∈ 𝒪⇩p ⟹ val (𝟭 ⊖ α) = val (α ⊖ 𝟭)" unfolding "17" (*goal: ‹⋀α. α ∈ 𝒪⇩p ⟹ val (⊖ (α ⊖ 𝟭)) = val (α ⊖ 𝟭)›*) using Qp.minus_closed (*‹⟦?x ∈ carrier Q⇩p; ?y ∈ carrier Q⇩p⟧ ⟹ ?x ⊖ ?y ∈ carrier Q⇩p›*) Qp.one_closed (*‹𝟭 ∈ carrier Q⇩p›*) val_minus (*‹?a ∈ carrier Q⇩p ⟹ val ?a = val (⊖ ?a)›*) val_ring_memE(2) (*‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) by presburger qed show "?thesis" (*goal: ‹∃!b. b ∈ 𝒪⇩p ∧ b [^] n = a ∧ val ([n] ⋅ 𝟭) < val (b ⊖ 𝟭)›*) using "13" (*‹∃!α. α ∈ 𝒪⇩p ∧ f ∙ α = 𝟬 ∧ val (UPQ.pderiv f ∙ 𝟭) < val (𝟭 ⊖ α)›*) unfolding "15" (*goal: ‹∃!b::((nat ⇒ int) × (nat ⇒ int)) set. b ∈ 𝒪⇩p ∧ b [^] (n::nat) = (a::((nat ⇒ int) × (nat ⇒ int)) set) ∧ val ([n] ⋅ 𝟭) < val (b ⊖ 𝟭)›*) using "14" (*‹?α2 ∈ 𝒪⇩p ⟹ (?α2 [^] n = a) = (f ∙ ?α2 = 𝟬)›*) "16" (*‹?α2 ∈ 𝒪⇩p ⟹ val (𝟭 ⊖ ?α2) = val (?α2 ⊖ 𝟭)›*) Qp.one_closed (*‹𝟭 ∈ carrier Q⇩p›*) val_ring_memE(2) (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) by metis qed lemma mod_zeroE: assumes "(a::int) mod k = 0" shows "∃l. a = l*k" using assms (*‹a mod k = 0›*) using Groups.mult_ac(2) (*‹?a * ?b = ?b * ?a›*) by blast lemma to_Zp_poly_closed': assumes "g ∈ carrier (UP Q⇩p)" assumes "⋀i. g i ∈ 𝒪⇩p" shows "to_Zp_poly g ∈ carrier (UP Z⇩p)" proof (rule to_Zp_poly_closed (*‹⟦?g ∈ carrier (UP Q⇩p); 0 ≤ gauss_norm ?g⟧ ⟹ to_Zp_poly ?g ∈ carrier (UP Z⇩p)›*)) (*goals: 1. ‹g ∈ carrier (UP Q⇩p)› 2. ‹0 ≤ gauss_norm g›*) show "g ∈ carrier (UP Q⇩p)" using assms(1) (*‹g ∈ carrier (UP Q⇩p)›*) by blast show "0 ≤ gauss_norm g" proof (-) (*goal: ‹0 ≤ gauss_norm g›*) have "⋀i. val (g i) ≥ 0" using assms (*‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹g ?i2 ∈ 𝒪⇩p›*) val_ring_memE (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ (0::eint) ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) by blast thus "?thesis" (*goal: ‹0 ≤ gauss_norm g›*) unfolding gauss_norm_def (*goal: ‹0 ≤ Min (val ` g ` {..deg Q⇩p g})›*) by (metis gauss_norm_coeff_norm (*‹∃n≤deg Q⇩p (?g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set). gauss_norm ?g = val (?g n)›*) gauss_norm_def (*‹gauss_norm (?g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) = Min (val ` ?g ` {..deg Q⇩p ?g})›*)) qed qed lemma to_Zp_poly_eval_to_Zp: assumes "g ∈ carrier (UP Q⇩p)" assumes "⋀i. g i ∈ 𝒪⇩p" assumes "a ∈ 𝒪⇩p" shows "to_function Z⇩p (to_Zp_poly g) (to_Zp a) = to_Zp (g ∙ a)" proof (-) (*goal: ‹to_function (Z⇩p::(nat ⇒ int) ring) (to_Zp_poly (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)) (to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set)) = to_Zp (g ∙ a)›*) have "(∀i. g i ∈ 𝒪⇩p) ⟶ to_function Z⇩p (to_Zp_poly g) (to_Zp a) = to_Zp (g ∙ a)" apply (rule UPQ.poly_induct[of g] (*‹⟦g ∈ carrier (UP Q⇩p); ⋀p. ⟦p ∈ carrier (UP Q⇩p); deg Q⇩p p = 0⟧ ⟹ ?Q p; ⋀p. ⟦⋀q. ⟦q ∈ carrier (UP Q⇩p); deg Q⇩p q < deg Q⇩p p⟧ ⟹ ?Q q; p ∈ carrier (UP Q⇩p); 0 < deg Q⇩p p⟧ ⟹ ?Q p⟧ ⟹ ?Q g›*)) (*goal: ‹(∀i::nat. (g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) i ∈ 𝒪⇩p) ⟶ to_function (Z⇩p::(nat ⇒ int) ring) (to_Zp_poly g) (to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set)) = to_Zp (g ∙ a)›*) using assms (*‹g ∈ carrier (UP Q⇩p)› ‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (?i2::nat) ∈ 𝒪⇩p› ‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p›*) apply blast (*top goal: ‹g ∈ carrier (UP Q⇩p)› and 2 goals remain*) proof (standard) (*goals: 1. ‹⋀p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set. ⟦p ∈ carrier (UP Q⇩p); deg Q⇩p p = (0::nat); ∀i::nat. p i ∈ 𝒪⇩p⟧ ⟹ to_function (Z⇩p::(nat ⇒ int) ring) (to_Zp_poly p) (to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set)) = to_Zp (p ∙ a)› 2. ‹⋀p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set. ⟦⋀q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set. ⟦q ∈ carrier (UP Q⇩p); deg Q⇩p q < deg Q⇩p p⟧ ⟹ (∀i::nat. q i ∈ 𝒪⇩p) ⟶ to_function (Z⇩p::(nat ⇒ int) ring) (to_Zp_poly q) (to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set)) = to_Zp (q ∙ a); p ∈ carrier (UP Q⇩p); (0::nat) < deg Q⇩p p⟧ ⟹ (∀i::nat. p i ∈ 𝒪⇩p) ⟶ to_function Z⇩p (to_Zp_poly p) (to_Zp a) = to_Zp (p ∙ a)›*) fix p assume A: "p ∈ carrier (UP Q⇩p)" "deg Q⇩p p = 0" "∀i. p i ∈ 𝒪⇩p" (*‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) = (0::nat)› ‹∀i::nat. (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) i ∈ 𝒪⇩p›*) obtain c where c_def: "c ∈ carrier Q⇩p ∧ p = up_ring.monom (UP Q⇩p) c 0" (*goal: ‹(⋀c. c ∈ carrier Q⇩p ∧ p = monom (UP Q⇩p) c 0 ⟹ thesis) ⟹ thesis›*) using A (*‹p ∈ carrier (UP Q⇩p)› ‹deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) = (0::nat)› ‹∀i. p i ∈ 𝒪⇩p›*) by (metis UPQ.ltrm_deg_0 (*‹⟦?p ∈ carrier (UP Q⇩p); deg Q⇩p ?p = 0⟧ ⟹ monom (UP Q⇩p) (?p (deg Q⇩p ?p)) (deg Q⇩p ?p) = ?p›*) val_ring_memE( (*‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) 2)) have 0: "to_Zp_poly (up_ring.monom (UP Q⇩p) c 0) = up_ring.monom (UP Z⇩p) (to_Zp c) 0" unfolding to_Zp_poly_def (*goal: ‹(λn. to_Zp (monom (UP Q⇩p) c 0 n)) = monom (UP Z⇩p) (to_Zp c) 0›*) proof (standard) (*goal: ‹⋀n. to_Zp (monom (UP Q⇩p) c 0 n) = monom (UP Z⇩p) (to_Zp c) 0 n›*) fix n show " to_Zp (up_ring.monom (UP Q⇩p) c 0 n) = up_ring.monom (UP Z⇩p) (to_Zp c) 0 n" using UP_ring.cfs_monom[of Z⇩p "to_Zp c" 0 n] (*‹⟦UP_ring Z⇩p; to_Zp c ∈ carrier Z⇩p⟧ ⟹ monom (UP Z⇩p) (to_Zp c) 0 n = (if 0 = n then to_Zp c else 𝟬⇘Z⇩p⇙)›*) UP_ring.cfs_monom[of Q⇩p c 0 n] (*‹⟦UP_ring Q⇩p; c ∈ carrier Q⇩p⟧ ⟹ monom (UP Q⇩p) c 0 n = (if 0 = n then c else 𝟬)›*) to_Zp_closed[of c] (*‹c ∈ carrier Q⇩p ⟹ to_Zp c ∈ carrier Z⇩p›*) unfolding UP_ring_def (*goal: ‹to_Zp (monom (UP Q⇩p) (c::((nat ⇒ int) × (nat ⇒ int)) set) (0::nat) (n::nat)) = monom (UP (Z⇩p::(nat ⇒ int) ring)) (to_Zp c) (0::nat) n›*) apply (cases "0 = n") (*goal: ‹to_Zp (monom (UP Q⇩p) c 0 n) = monom (UP Z⇩p) (to_Zp c) 0 n›*) using UPQ.cfs_monom (*‹?a ∈ carrier Q⇩p ⟹ monom (UP Q⇩p) ?a ?m ?n = (if ?m = ?n then ?a else 𝟬)›*) Zp.cfs_monom (*‹?a ∈ carrier Z⇩p ⟹ monom (UP Z⇩p) ?a ?m ?n = (if ?m = ?n then ?a else 𝟬⇘Z⇩p⇙)›*) c_def (*‹c ∈ carrier Q⇩p ∧ p = monom (UP Q⇩p) c 0›*) apply presburger (*top goal: ‹⟦⟦ring Z⇩p; to_Zp c ∈ carrier Z⇩p⟧ ⟹ monom (UP Z⇩p) (to_Zp c) 0 n = (if 0 = n then to_Zp c else 𝟬⇘Z⇩p⇙); ⟦ring Q⇩p; c ∈ carrier Q⇩p⟧ ⟹ monom (UP Q⇩p) c 0 n = (if 0 = n then c else 𝟬); c ∈ carrier Q⇩p ⟹ to_Zp c ∈ carrier Z⇩p; 0 = n⟧ ⟹ to_Zp (monom (UP Q⇩p) c 0 n) = monom (UP Z⇩p) (to_Zp c) 0 n› and 1 goal remains*) using UPQ.cfs_monom (*‹?a ∈ carrier Q⇩p ⟹ monom (UP Q⇩p) ?a ?m ?n = (if ?m = ?n then ?a else 𝟬)›*) Zp.cfs_monom (*‹?a ∈ carrier Z⇩p ⟹ monom (UP Z⇩p) ?a ?m ?n = (if ?m = ?n then ?a else 𝟬⇘Z⇩p⇙)›*) c_def (*‹(c::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p ∧ (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) = monom (UP Q⇩p) c (0::nat)›*) using to_Zp_zero (*‹to_Zp 𝟬 = 𝟬⇘Z⇩p⇙›*) by presburger qed have p_eq: "p = up_ring.monom (UP Q⇩p) c 0" using c_def (*‹c ∈ carrier Q⇩p ∧ p = monom (UP Q⇩p) c 0›*) by blast have 1: "(up_ring.monom (UP Q⇩p) c 0 ∙ a) = c" using UPQ.to_fun_to_poly[of c a] (*‹⟦(c::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p; (a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p⟧ ⟹ to_polynomial Q⇩p c ∙ a = c›*) c_def (*‹c ∈ carrier Q⇩p ∧ p = monom (UP Q⇩p) c 0›*) assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?i2 ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p›*) val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) unfolding to_polynomial_def (*goal: ‹monom (UP Q⇩p) c 0 ∙ a = c›*) by blast show "to_function Z⇩p (to_Zp_poly p) (to_Zp a) = to_Zp (p ∙ a)" using c_def (*‹c ∈ carrier Q⇩p ∧ p = monom (UP Q⇩p) c 0›*) assms(3) (*‹a ∈ 𝒪⇩p›*) val_ring_memE(2)[of a] (*‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ a ∈ carrier Q⇩p›*) UP_cring.to_fun_to_poly[of Z⇩p "to_Zp c" "to_Zp a"] (*‹⟦UP_cring Z⇩p; to_Zp c ∈ carrier Z⇩p; to_Zp a ∈ carrier Z⇩p⟧ ⟹ Zp.to_fun (to_polynomial Z⇩p (to_Zp c)) (to_Zp a) = to_Zp c›*) unfolding p_eq "0" "1" Zp.to_fun_def to_polynomial_def (*goal: ‹to_function (Z⇩p::(nat ⇒ int) ring) (monom (UP Z⇩p) (to_Zp (c::((nat ⇒ int) × (nat ⇒ int)) set)) (0::nat)) (to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set)) = to_Zp c›*) using Zp.UP_cring_axioms (*‹UP_cring (Z⇩p::(nat ⇒ int) ring)›*) to_Zp_closed (*‹?a ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier Z⇩p›*) by blast next (*goal: ‹⋀p. ⟦⋀q. ⟦q ∈ carrier (UP Q⇩p); deg Q⇩p q < deg Q⇩p p⟧ ⟹ (∀i. q i ∈ 𝒪⇩p) ⟶ to_function Z⇩p (to_Zp_poly q) (to_Zp a) = to_Zp (q ∙ a); p ∈ carrier (UP Q⇩p); 0 < deg Q⇩p p⟧ ⟹ (∀i. p i ∈ 𝒪⇩p) ⟶ to_function Z⇩p (to_Zp_poly p) (to_Zp a) = to_Zp (p ∙ a)›*) show "⋀p. (⋀q. q ∈ carrier (UP Q⇩p) ⟹ deg Q⇩p q < deg Q⇩p p ⟹ (∀i. q i ∈ 𝒪⇩p) ⟶ to_function Z⇩p (to_Zp_poly q) (to_Zp a) = to_Zp (q ∙ a)) ⟹ p ∈ carrier (UP Q⇩p) ⟹ 0 < deg Q⇩p p ⟹ (∀i. p i ∈ 𝒪⇩p) ⟶ to_function Z⇩p (to_Zp_poly p) (to_Zp a) = to_Zp (p ∙ a)" proof (standard) (*goal: ‹⋀p. ⟦⋀q. ⟦q ∈ carrier (UP Q⇩p); deg Q⇩p q < deg Q⇩p p⟧ ⟹ (∀i. q i ∈ 𝒪⇩p) ⟶ to_function Z⇩p (to_Zp_poly q) (to_Zp a) = to_Zp (q ∙ a); p ∈ carrier (UP Q⇩p); 0 < deg Q⇩p p; ∀i. p i ∈ 𝒪⇩p⟧ ⟹ to_function Z⇩p (to_Zp_poly p) (to_Zp a) = to_Zp (p ∙ a)›*) fix p assume A: "(⋀q. q ∈ carrier (UP Q⇩p) ⟹ deg Q⇩p q < deg Q⇩p p ⟹ (∀i. q i ∈ 𝒪⇩p) ⟶ to_function Z⇩p (to_Zp_poly q) (to_Zp a) = to_Zp (q ∙ a))" "p ∈ carrier (UP Q⇩p)" "0 < deg Q⇩p p" "∀i. p i ∈ 𝒪⇩p" (*‹⟦(?q2::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); deg Q⇩p ?q2 < deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)⟧ ⟹ (∀i::nat. ?q2 i ∈ 𝒪⇩p) ⟶ to_function (Z⇩p::(nat ⇒ int) ring) (to_Zp_poly ?q2) (to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set)) = to_Zp (?q2 ∙ a)› ‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹(0::nat) < deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)› ‹∀i::nat. (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) i ∈ 𝒪⇩p›*) show "to_function Z⇩p (to_Zp_poly p) (to_Zp a) = to_Zp (p ∙ a)" proof (-) (*goal: ‹to_function Z⇩p (to_Zp_poly p) (to_Zp a) = to_Zp (p ∙ a)›*) obtain q where q_def: "q = truncate Q⇩p p" (*goal: ‹(⋀q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set. q = Cring_Poly.truncate Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ⟹ thesis::bool) ⟹ thesis›*) by blast have q_closed: "q ∈ carrier (UP Q⇩p)" unfolding q_def (*goal: ‹Cring_Poly.truncate Q⇩p p ∈ carrier (UP Q⇩p)›*) apply (rule UPQ.trunc_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ Cring_Poly.truncate Q⇩p ?f ∈ carrier (UP Q⇩p)›*)) (*goal: ‹Cring_Poly.truncate Q⇩p p ∈ carrier (UP Q⇩p)›*) by (rule A (*‹⟦?q2 ∈ carrier (UP Q⇩p); deg Q⇩p ?q2 < deg Q⇩p p⟧ ⟹ (∀i. ?q2 i ∈ 𝒪⇩p) ⟶ to_function Z⇩p (to_Zp_poly ?q2) (to_Zp a) = to_Zp (?q2 ∙ a)› ‹p ∈ carrier (UP Q⇩p)› ‹0 < deg Q⇩p p› ‹∀i. p i ∈ 𝒪⇩p›*)) obtain c where c_def: "c = UPQ.lcf p" (*goal: ‹(⋀c. c = p (deg Q⇩p p) ⟹ thesis) ⟹ thesis›*) by blast obtain n where n_def: "n = deg Q⇩p p" (*goal: ‹(⋀n::nat. n = deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ⟹ thesis::bool) ⟹ thesis›*) by blast have 0: "p = q ⊕⇘UP Q⇩p⇙ up_ring.monom (UP Q⇩p) c n" unfolding c_def n_def q_def (*goal: ‹p = Cring_Poly.truncate Q⇩p p ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (p (deg Q⇩p p)) (deg Q⇩p p)›*) using A(2) (*‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)›*) UPQ.trunc_simps(1) (*‹?f ∈ carrier (UP Q⇩p) ⟹ ?f = Cring_Poly.truncate Q⇩p ?f ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f)›*) by blast have 1: "up_ring.monom (UP Q⇩p) c n ∈ carrier (UP Q⇩p)" using A(2) (*‹p ∈ carrier (UP Q⇩p)›*) UPQ.ltrm_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f) ∈ carrier (UP Q⇩p)›*) c_def (*‹(c::((nat ⇒ int) × (nat ⇒ int)) set) = (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p p)›*) n_def (*‹n = deg Q⇩p p›*) by blast have 2: "p ∙ a = q ∙ a ⊕ (c ⊗ a[^]n)" unfolding "0" (*goal: ‹(q ⊕⇘UP Q⇩p⇙ monom (UP Q⇩p) c n) ∙ a = q ∙ a ⊕ c ⊗ a [^] n›*) using assms (*‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹g ?i2 ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p›*) val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) by (metis "1" (*‹monom (UP Q⇩p) (c::((nat ⇒ int) × (nat ⇒ int)) set) (n::nat) ∈ carrier (UP Q⇩p)›*) A( (*‹∀i::nat. (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) i ∈ 𝒪⇩p›*) 4) UPQ.to_fun_monom (*‹⟦(?c::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p; (?x::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p⟧ ⟹ monom (UP Q⇩p) ?c (?n::nat) ∙ ?x = ?c ⊗ ?x [^] ?n›*) UPQ.to_fun_plus (*‹⟦(?g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (?x::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p⟧ ⟹ (?f ⊕⇘UP Q⇩p⇙ ?g) ∙ ?x = ?f ∙ ?x ⊕ ?g ∙ ?x›*) c_def (*‹(c::((nat ⇒ int) × (nat ⇒ int)) set) = (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p p)›*) q_closed (*‹(q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)›*)) have 3: "⋀i. i < n ⟹ q i = p i" unfolding n_def q_def (*goal: ‹⋀i. i < deg Q⇩p p ⟹ Cring_Poly.truncate Q⇩p p i = p i›*) using A(2) (*‹p ∈ carrier (UP Q⇩p)›*) UPQ.trunc_cfs (*‹⟦?p ∈ carrier (UP Q⇩p); ?n < deg Q⇩p ?p⟧ ⟹ Cring_Poly.truncate Q⇩p ?p ?n = ?p ?n›*) by blast have 4: "deg Q⇩p q < n" unfolding n_def q_def (*goal: ‹deg Q⇩p (Cring_Poly.truncate Q⇩p p) < deg Q⇩p p›*) using A (*‹⟦(?q2::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); deg Q⇩p ?q2 < deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)⟧ ⟹ (∀i::nat. ?q2 i ∈ 𝒪⇩p) ⟶ to_function (Z⇩p::(nat ⇒ int) ring) (to_Zp_poly ?q2) (to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set)) = to_Zp (?q2 ∙ a)› ‹p ∈ carrier (UP Q⇩p)› ‹(0::nat) < deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)› ‹∀i::nat. (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) i ∈ 𝒪⇩p›*) using UPQ.trunc_degree (*‹⟦(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); (0::nat) < deg Q⇩p ?f⟧ ⟹ deg Q⇩p (Cring_Poly.truncate Q⇩p ?f) < deg Q⇩p ?f›*) by presburger have 5: "⋀i. i ≥ n ⟹ i > deg Q⇩p q" using A[of] (*‹⟦?q2 ∈ carrier (UP Q⇩p); deg Q⇩p ?q2 < deg Q⇩p p⟧ ⟹ (∀i. ?q2 i ∈ 𝒪⇩p) ⟶ to_function Z⇩p (to_Zp_poly ?q2) (to_Zp a) = to_Zp (?q2 ∙ a)› ‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹(0::nat) < deg Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)› ‹∀i. p i ∈ 𝒪⇩p›*) less_le_trans[of "deg Q⇩p q" "deg Q⇩p p"] (*‹⟦deg Q⇩p q < deg Q⇩p p; deg Q⇩p p ≤ ?z⟧ ⟹ deg Q⇩p q < ?z›*) unfolding q_def n_def (*goal: ‹⋀i. deg Q⇩p p ≤ i ⟹ deg Q⇩p (Cring_Poly.truncate Q⇩p p) < i›*) using "4" (*‹deg Q⇩p q < n›*) n_def (*‹n = deg Q⇩p p›*) q_def (*‹(q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) = Cring_Poly.truncate Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)›*) by blast have 6: "⋀i. i ≥ n ⟹ q i = 𝟬" using q_closed (*‹q ∈ carrier (UP Q⇩p)›*) "5" (*‹(n::nat) ≤ (?i2::nat) ⟹ deg Q⇩p (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) < ?i2›*) UPQ.deg_leE (*‹⟦(?p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); deg Q⇩p ?p < (?k::nat)⟧ ⟹ ?p ?k = 𝟬›*) by blast have 7: "(∀i. q i ∈ 𝒪⇩p) ⟶ to_function Z⇩p (to_Zp_poly q) (to_Zp a) = to_Zp (q ∙ a)" apply (rule A (*‹⟦?q2 ∈ carrier (UP Q⇩p); deg Q⇩p ?q2 < deg Q⇩p p⟧ ⟹ (∀i. ?q2 i ∈ 𝒪⇩p) ⟶ to_function Z⇩p (to_Zp_poly ?q2) (to_Zp a) = to_Zp (?q2 ∙ a)› ‹p ∈ carrier (UP Q⇩p)› ‹0 < deg Q⇩p p› ‹∀i. p i ∈ 𝒪⇩p›*)) (*goal: ‹(∀i. q i ∈ 𝒪⇩p) ⟶ to_function Z⇩p (to_Zp_poly q) (to_Zp a) = to_Zp (q ∙ a)›*) unfolding q_def (*goals: 1. ‹Cring_Poly.truncate Q⇩p p ∈ carrier (UP Q⇩p)› 2. ‹deg Q⇩p (Cring_Poly.truncate Q⇩p p) < deg Q⇩p p›*) using q_closed (*‹q ∈ carrier (UP Q⇩p)›*) q_def (*‹q = Cring_Poly.truncate Q⇩p p›*) apply blast (*top goal: ‹Cring_Poly.truncate Q⇩p p ∈ carrier (UP Q⇩p)› and 1 goal remains*) using "4" (*‹deg Q⇩p q < n›*) n_def (*‹n = deg Q⇩p p›*) q_def (*‹(q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) = Cring_Poly.truncate Q⇩p (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)›*) by blast have 8: "(∀i. q i ∈ 𝒪⇩p)" proof (standard) (*goal: ‹⋀i. q i ∈ 𝒪⇩p›*) fix i show "q i ∈ 𝒪⇩p" apply (cases "i < n") (*goal: ‹q i ∈ 𝒪⇩p›*) using "3" (*‹?i2 < n ⟹ q ?i2 = p ?i2›*) A(4) (*‹∀i. p i ∈ 𝒪⇩p›*) apply blast (*top goal: ‹(i::nat) < (n::nat) ⟹ (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) i ∈ 𝒪⇩p› and 1 goal remains*) using "6"[of i] (*‹n ≤ i ⟹ q i = 𝟬›*) by (metis less_or_eq_imp_le (*‹?m < ?n ∨ ?m = ?n ⟹ ?m ≤ ?n›*) linorder_neqE_nat (*‹⟦?x ≠ ?y; ?x < ?y ⟹ ?R; ?y < ?x ⟹ ?R⟧ ⟹ ?R›*) zero_in_val_ring (*‹𝟬 ∈ 𝒪⇩p›*)) qed have 9: "to_function Z⇩p (to_Zp_poly q) (to_Zp a) = to_Zp (q ∙ a)" using "7" (*‹(∀i. q i ∈ 𝒪⇩p) ⟶ to_function Z⇩p (to_Zp_poly q) (to_Zp a) = to_Zp (q ∙ a)›*) "8" (*‹∀i::nat. (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) i ∈ 𝒪⇩p›*) by blast have 10: "to_Zp_poly p = to_Zp_poly q ⊕⇘UP Z⇩p⇙ to_Zp_poly (up_ring.monom (UP Q⇩p) c n)" proof (standard) (*goal: ‹⋀x. to_Zp_poly p x = (to_Zp_poly q ⊕⇘UP Z⇩p⇙ to_Zp_poly (monom (UP Q⇩p) c n)) x›*) fix x have 100: "to_Zp_poly (up_ring.monom (UP Q⇩p) c n) = (up_ring.monom (UP Z⇩p) (to_Zp c) n)" using to_Zp_poly_monom[of c] (*‹c ∈ 𝒪⇩p ⟹ to_Zp_poly (monom (UP Q⇩p) c ?n) = monom (UP Z⇩p) (to_Zp c) ?n›*) A(4) (*‹∀i. p i ∈ 𝒪⇩p›*) c_def (*‹(c::((nat ⇒ int) × (nat ⇒ int)) set) = (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p p)›*) by blast have 101: "deg Z⇩p (to_Zp_poly q) ≤ n-1" apply (rule UP_cring.deg_leqI (*‹⟦UP_cring ?R; ?p ∈ carrier (UP ?R); ⋀n. ?k < n ⟹ ?p n = 𝟬⇘?R⇙⟧ ⟹ deg ?R ?p ≤ ?k›*)) (*goal: ‹deg Z⇩p (to_Zp_poly q) ≤ n - 1›*) unfolding UP_cring_def (*goals: 1. ‹cring Z⇩p› 2. ‹to_Zp_poly q ∈ carrier (UP Z⇩p)› 3. ‹⋀na. n - 1 < na ⟹ to_Zp_poly q na = 𝟬⇘Z⇩p⇙›*) using Zp.R_cring (*‹cring Z⇩p›*) apply ((auto)[1]) (*top goal: ‹cring Z⇩p› and 2 goals remain*) using to_Zp_poly_closed' (*‹⟦(?g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p); ⋀i::nat. ?g i ∈ 𝒪⇩p⟧ ⟹ to_Zp_poly ?g ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring))›*) "8" (*‹∀i::nat. (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) i ∈ 𝒪⇩p›*) q_closed (*‹q ∈ carrier (UP Q⇩p)›*) apply blast (*top goal: ‹to_Zp_poly q ∈ carrier (UP Z⇩p)› and 1 goal remains*) unfolding to_Zp_poly_def (*goal: ‹⋀na::nat. (n::nat) - (1::nat) < na ⟹ to_Zp ((q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) na) = 𝟬⇘Z⇩p::(nat ⇒ int) ring⇙›*) using "4" (*‹deg Q⇩p q < n›*) "6" (*‹n ≤ ?i2 ⟹ q ?i2 = 𝟬›*) by (simp add: to_Zp_zero (*‹to_Zp 𝟬 = 𝟬⇘Z⇩p⇙›*)) have 102: "(to_Zp_poly q) ∈ carrier (UP Z⇩p)" apply (rule to_Zp_poly_closed' (*‹⟦?g ∈ carrier (UP Q⇩p); ⋀i. ?g i ∈ 𝒪⇩p⟧ ⟹ to_Zp_poly ?g ∈ carrier (UP Z⇩p)›*), rule q_closed (*‹(q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)›*)) (*goal: ‹to_Zp_poly q ∈ carrier (UP Z⇩p)›*) using "8" (*‹∀i. q i ∈ 𝒪⇩p›*) by blast have 103: "deg Z⇩p (to_Zp_poly q) < n" using "101" (*‹deg Z⇩p (to_Zp_poly q) ≤ n - 1›*) "4" (*‹deg Q⇩p q < n›*) by linarith have T0: "(to_Zp_poly q ⊕⇘UP Z⇩p⇙ to_Zp_poly (up_ring.monom (UP Q⇩p) c n)) x = (to_Zp_poly q x) ⊕⇘Z⇩p⇙ (to_Zp_poly (up_ring.monom (UP Q⇩p) c n) x)" apply (rule UP_ring.cfs_add (*‹⟦UP_ring ?R; ?p ∈ carrier (UP ?R); ?q ∈ carrier (UP ?R)⟧ ⟹ (?p ⊕⇘UP ?R⇙ ?q) ?n = ?p ?n ⊕⇘?R⇙ ?q ?n›*)) (*goal: ‹(to_Zp_poly (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ⊕⇘UP (Z⇩p::(nat ⇒ int) ring)⇙ to_Zp_poly (monom (UP Q⇩p) (c::((nat ⇒ int) × (nat ⇒ int)) set) (n::nat))) (x::nat) = to_Zp_poly q x ⊕⇘Z⇩p⇙ to_Zp_poly (monom (UP Q⇩p) c n) x›*) apply (simp add: Zp.is_UP_ring (*‹UP_ring Z⇩p›*)) (*top goal: ‹UP_ring Z⇩p› and 2 goals remain*) apply (simp add: "102" (*‹to_Zp_poly q ∈ carrier (UP Z⇩p)›*)) (*top goal: ‹to_Zp_poly q ∈ carrier (UP Z⇩p)› and 1 goal remains*) using "100" (*‹to_Zp_poly (monom (UP Q⇩p) c n) = monom (UP Z⇩p) (to_Zp c) n›*) A(2) (*‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)›*) UPQ.lcf_closed (*‹(?f::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p) ⟹ ?f (deg Q⇩p ?f) ∈ carrier Q⇩p›*) c_def (*‹c = p (deg Q⇩p p)›*) to_Zp_closed (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier (Z⇩p::(nat ⇒ int) ring)›*) by auto have c_closed: "c ∈ 𝒪⇩p" unfolding c_def (*goal: ‹p (deg Q⇩p p) ∈ 𝒪⇩p›*) using A(4) (*‹∀i. p i ∈ 𝒪⇩p›*) by blast have to_Zp_c_closed: "to_Zp c ∈ carrier Z⇩p" using c_closed (*‹c ∈ 𝒪⇩p›*) to_Zp_closed (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier (Z⇩p::(nat ⇒ int) ring)›*) val_ring_memE(2) (*‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) by blast show "to_Zp_poly p x = (to_Zp_poly q ⊕⇘UP Z⇩p⇙ to_Zp_poly (up_ring.monom (UP Q⇩p) c n)) x" proof (cases "x < n") (*goals: 1. ‹x < n ⟹ to_Zp_poly p x = (to_Zp_poly q ⊕⇘UP Z⇩p⇙ to_Zp_poly (monom (UP Q⇩p) c n)) x› 2. ‹¬ x < n ⟹ to_Zp_poly p x = (to_Zp_poly q ⊕⇘UP Z⇩p⇙ to_Zp_poly (monom (UP Q⇩p) c n)) x›*) case True (*‹(x::nat) < (n::nat)›*) have T1: "(to_Zp_poly (up_ring.monom (UP Q⇩p) c n) x) = 𝟬⇘Z⇩p⇙" using True (*‹x < n›*) UP_ring.cfs_monom[of Z⇩p] (*‹⟦UP_ring Z⇩p; ?a ∈ carrier Z⇩p⟧ ⟹ monom (UP Z⇩p) ?a ?m ?n = (if ?m = ?n then ?a else 𝟬⇘Z⇩p⇙)›*) unfolding UP_ring_def (*goal: ‹to_Zp_poly (monom (UP Q⇩p) c n) x = 𝟬⇘Z⇩p⇙›*) by (simp add: A( (*‹p ∈ carrier (UP Q⇩p)›*) 2) UPQ.ltrm_cfs (*‹?f ∈ carrier (UP Q⇩p) ⟹ monom (UP Q⇩p) (?f (deg Q⇩p ?f)) (deg Q⇩p ?f) ?n = (if ?n = deg Q⇩p ?f then ?f (deg Q⇩p ?f) else 𝟬)›*) c_def (*‹c = p (deg Q⇩p p)›*) n_def (*‹n = deg Q⇩p p›*) to_Zp_poly_def (*‹to_Zp_poly ?g = (λn. to_Zp (?g n))›*) to_Zp_zero (*‹to_Zp 𝟬 = 𝟬⇘Z⇩p⇙›*)) have T2: "to_Zp (p x) = to_Zp (q x)" using "3"[of x] (*‹x < n ⟹ q x = p x›*) True (*‹(x::nat) < (n::nat)›*) by smt have T3: "to_Zp (p x) ∈ carrier Z⇩p" apply (rule to_Zp_closed (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier (Z⇩p::(nat ⇒ int) ring)›*)) (*goal: ‹to_Zp (p x) ∈ carrier Z⇩p›*) using A(2) (*‹p ∈ carrier (UP Q⇩p)›*) UPQ.UP_car_memE(1) (*‹?g ∈ carrier (UP Q⇩p) ⟹ ?g ?x ∈ carrier Q⇩p›*) by blast show "?thesis" (*goal: ‹to_Zp_poly p x = (to_Zp_poly q ⊕⇘UP Z⇩p⇙ to_Zp_poly (monom (UP Q⇩p) c n)) x›*) using T3 (*‹to_Zp (p x) ∈ carrier Z⇩p›*) unfolding T0 (*goal: ‹to_Zp_poly (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (x::nat) = to_Zp_poly (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) x ⊕⇘Z⇩p::(nat ⇒ int) ring⇙ to_Zp_poly (monom (UP Q⇩p) (c::((nat ⇒ int) × (nat ⇒ int)) set) (n::nat)) x›*) unfolding T1 (*goal: ‹to_Zp_poly p x = to_Zp_poly q x ⊕⇘Z⇩p⇙ 𝟬⇘Z⇩p⇙›*) unfolding to_Zp_poly_def T2 (*goal: ‹to_Zp (q x) = to_Zp (q x) ⊕⇘Z⇩p⇙ 𝟬⇘Z⇩p⇙›*) using Zp.cring_simprules(8) (*‹?x ∈ carrier Z⇩p ⟹ 𝟬⇘Z⇩p⇙ ⊕⇘Z⇩p⇙ ?x = ?x›*) add_comm (*‹?a ⊕⇘Z⇩p⇙ ?b = ?b ⊕⇘Z⇩p⇙ ?a›*) by presburger next (*goal: ‹¬ x < n ⟹ to_Zp_poly p x = (to_Zp_poly q ⊕⇘UP Z⇩p⇙ to_Zp_poly (monom (UP Q⇩p) c n)) x›*) case False (*‹¬ x < n›*) have F: "q x = 𝟬 " using False (*‹¬ (x::nat) < (n::nat)›*) by (metis "6" (*‹(n::nat) ≤ (?i2::nat) ⟹ (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ?i2 = 𝟬›*) less_or_eq_imp_le (*‹(?m::nat) < (?n::nat) ∨ ?m = ?n ⟹ ?m ≤ ?n›*) linorder_neqE_nat (*‹⟦(?x::nat) ≠ (?y::nat); ?x < ?y ⟹ ?R::bool; ?y < ?x ⟹ ?R⟧ ⟹ ?R›*)) have F': "(to_Zp_poly q) x = 𝟬⇘Z⇩p⇙" unfolding to_Zp_poly_def F (*goal: ‹to_Zp 𝟬 = 𝟬⇘Z⇩p::(nat ⇒ int) ring⇙›*) using to_Zp_zero (*‹to_Zp 𝟬 = 𝟬⇘Z⇩p⇙›*) by blast show "to_Zp_poly p x = (to_Zp_poly q ⊕⇘UP Z⇩p⇙ to_Zp_poly (up_ring.monom (UP Q⇩p) c n)) x" proof (cases "x = n") (*goals: 1. ‹x = n ⟹ to_Zp_poly p x = (to_Zp_poly q ⊕⇘UP Z⇩p⇙ to_Zp_poly (monom (UP Q⇩p) c n)) x› 2. ‹x ≠ n ⟹ to_Zp_poly p x = (to_Zp_poly q ⊕⇘UP Z⇩p⇙ to_Zp_poly (monom (UP Q⇩p) c n)) x›*) case True (*‹x = n›*) have T1: "to_Zp (p x) ∈ carrier Z⇩p" apply (rule to_Zp_closed (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier (Z⇩p::(nat ⇒ int) ring)›*)) (*goal: ‹to_Zp ((p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (x::nat)) ∈ carrier (Z⇩p::(nat ⇒ int) ring)›*) using A(2) (*‹p ∈ carrier (UP Q⇩p)›*) UPQ.UP_car_memE(1) (*‹?g ∈ carrier (UP Q⇩p) ⟹ ?g ?x ∈ carrier Q⇩p›*) by blast have T2: "(to_Zp_poly (up_ring.monom (UP Q⇩p) c n) x) = to_Zp c" unfolding "100" (*goal: ‹monom (UP Z⇩p) (to_Zp c) n x = to_Zp c›*) using UP_ring.cfs_monom[of Z⇩p "to_Zp c" n n] (*‹⟦UP_ring Z⇩p; to_Zp c ∈ carrier Z⇩p⟧ ⟹ monom (UP Z⇩p) (to_Zp c) n n = (if n = n then to_Zp c else 𝟬⇘Z⇩p⇙)›*) unfolding UP_ring_def True (*goal: ‹monom (UP Z⇩p) (to_Zp c) n n = to_Zp c›*) using Zp.ring_axioms (*‹ring Z⇩p›*) to_Zp_c_closed (*‹to_Zp c ∈ carrier Z⇩p›*) by presburger show "?thesis" (*goal: ‹to_Zp_poly (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (x::nat) = (to_Zp_poly (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ⊕⇘UP (Z⇩p::(nat ⇒ int) ring)⇙ to_Zp_poly (monom (UP Q⇩p) (c::((nat ⇒ int) × (nat ⇒ int)) set) (n::nat))) x›*) using to_Zp_c_closed (*‹to_Zp c ∈ carrier Z⇩p›*) unfolding T0 F' T2 (*goal: ‹to_Zp_poly (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (x::nat) = 𝟬⇘Z⇩p⇙ ⊕⇘Z⇩p::(nat ⇒ int) ring⇙ to_Zp (c::((nat ⇒ int) × (nat ⇒ int)) set)›*) unfolding to_Zp_poly_def True c_def n_def (*goal: ‹to_Zp (p (deg Q⇩p p)) = 𝟬⇘Z⇩p⇙ ⊕⇘Z⇩p⇙ to_Zp (p (deg Q⇩p p))›*) using Zp.cring_simprules(8) (*‹(?x::nat ⇒ int) ∈ carrier (Z⇩p::(nat ⇒ int) ring) ⟹ 𝟬⇘Z⇩p⇙ ⊕⇘Z⇩p⇙ ?x = ?x›*) by presburger next (*goal: ‹(x::nat) ≠ (n::nat) ⟹ to_Zp_poly (p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) x = (to_Zp_poly (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ⊕⇘UP (Z⇩p::(nat ⇒ int) ring)⇙ to_Zp_poly (monom (UP Q⇩p) (c::((nat ⇒ int) × (nat ⇒ int)) set) n)) x›*) case FF: False (*‹(x::nat) ≠ (n::nat)›*) have F0: "p x = 𝟬" using FF (*‹(x::nat) ≠ (n::nat)›*) False (*‹¬ (x::nat) < (n::nat)›*) unfolding n_def (*goal: ‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (x::nat) = 𝟬›*) using A(2) (*‹p ∈ carrier (UP Q⇩p)›*) UPQ.UP_car_memE(2) (*‹⟦?g ∈ carrier (UP Q⇩p); deg Q⇩p ?g < ?x⟧ ⟹ ?g ?x = 𝟬›*) linorder_neqE_nat (*‹⟦(?x::nat) ≠ (?y::nat); ?x < ?y ⟹ ?R::bool; ?y < ?x ⟹ ?R⟧ ⟹ ?R›*) by blast have F1: "q x = 𝟬" using FF (*‹x ≠ n›*) False (*‹¬ x < n›*) F (*‹q x = 𝟬›*) by linarith have F2: "(up_ring.monom (UP Q⇩p) c n) x = 𝟬" using FF (*‹x ≠ n›*) False (*‹¬ (x::nat) < (n::nat)›*) A(2) (*‹p ∈ carrier (UP Q⇩p)›*) UPQ.cfs_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ ?f ?n ∈ carrier Q⇩p›*) UPQ.cfs_monom (*‹?a ∈ carrier Q⇩p ⟹ monom (UP Q⇩p) ?a ?m ?n = (if ?m = ?n then ?a else 𝟬)›*) c_def (*‹c = p (deg Q⇩p p)›*) by presburger show "?thesis" (*goal: ‹to_Zp_poly p x = (to_Zp_poly q ⊕⇘UP Z⇩p⇙ to_Zp_poly (monom (UP Q⇩p) c n)) x›*) unfolding T0 (*goal: ‹to_Zp_poly p x = to_Zp_poly q x ⊕⇘Z⇩p⇙ to_Zp_poly (monom (UP Q⇩p) c n) x›*) unfolding to_Zp_poly_def F0 F1 F2 (*goal: ‹to_Zp 𝟬 = to_Zp 𝟬 ⊕⇘Z⇩p::(nat ⇒ int) ring⇙ to_Zp 𝟬›*) using Zp.r_zero (*‹?x ∈ carrier Z⇩p ⟹ ?x ⊕⇘Z⇩p⇙ 𝟬⇘Z⇩p⇙ = ?x›*) Zp.zero_closed (*‹𝟬⇘Z⇩p⇙ ∈ carrier Z⇩p›*) to_Zp_zero (*‹to_Zp 𝟬 = 𝟬⇘Z⇩p::(nat ⇒ int) ring⇙›*) by presburger qed qed qed have 11: "deg Z⇩p (to_Zp_poly q) ≤ n-1" apply (rule UP_cring.deg_leqI (*‹⟦UP_cring ?R; ?p ∈ carrier (UP ?R); ⋀n. ?k < n ⟹ ?p n = 𝟬⇘?R⇙⟧ ⟹ deg ?R ?p ≤ ?k›*)) (*goal: ‹deg Z⇩p (to_Zp_poly q) ≤ n - 1›*) unfolding UP_cring_def (*goals: 1. ‹cring (Z⇩p::(nat ⇒ int) ring)› 2. ‹to_Zp_poly (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring))› 3. ‹⋀na::nat. (n::nat) - (1::nat) < na ⟹ to_Zp_poly (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) na = 𝟬⇘Z⇩p::(nat ⇒ int) ring⇙›*) using Zp.R_cring (*‹cring Z⇩p›*) apply ((auto)[1]) (*top goal: ‹cring Z⇩p› and 2 goals remain*) using to_Zp_poly_closed' (*‹⟦?g ∈ carrier (UP Q⇩p); ⋀i. ?g i ∈ 𝒪⇩p⟧ ⟹ to_Zp_poly ?g ∈ carrier (UP Z⇩p)›*) "8" (*‹∀i. q i ∈ 𝒪⇩p›*) q_closed (*‹q ∈ carrier (UP Q⇩p)›*) apply blast (*top goal: ‹to_Zp_poly (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring))› and 1 goal remains*) unfolding to_Zp_poly_def (*goal: ‹⋀na. n - 1 < na ⟹ to_Zp (q na) = 𝟬⇘Z⇩p⇙›*) using "4" (*‹deg Q⇩p q < n›*) "6" (*‹n ≤ ?i2 ⟹ q ?i2 = 𝟬›*) by (smt diff_commute (*‹?i - ?j - ?k = ?i - ?k - ?j›*) diff_diff_cancel (*‹?i ≤ ?n ⟹ ?n - (?n - ?i) = ?i›*) less_one (*‹(?n < 1) = (?n = 0)›*) less_or_eq_imp_le (*‹?m < ?n ∨ ?m = ?n ⟹ ?m ≤ ?n›*) linorder_neqE_nat (*‹⟦?x ≠ ?y; ?x < ?y ⟹ ?R; ?y < ?x ⟹ ?R⟧ ⟹ ?R›*) to_Zp_zero (*‹to_Zp 𝟬 = 𝟬⇘Z⇩p⇙›*) zero_less_diff (*‹(0 < ?n - ?m) = (?m < ?n)›*)) have 12: "(to_Zp_poly q) ∈ carrier (UP Z⇩p)" apply (rule to_Zp_poly_closed' (*‹⟦?g ∈ carrier (UP Q⇩p); ⋀i. ?g i ∈ 𝒪⇩p⟧ ⟹ to_Zp_poly ?g ∈ carrier (UP Z⇩p)›*), rule q_closed (*‹q ∈ carrier (UP Q⇩p)›*)) (*goal: ‹to_Zp_poly q ∈ carrier (UP Z⇩p)›*) using "8" (*‹∀i::nat. (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) i ∈ 𝒪⇩p›*) by blast have 13: "deg Z⇩p (to_Zp_poly q) < n" using "11" (*‹deg (Z⇩p::(nat ⇒ int) ring) (to_Zp_poly (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set)) ≤ (n::nat) - (1::nat)›*) "4" (*‹deg Q⇩p q < n›*) by linarith have 14: "to_Zp_poly (up_ring.monom (UP Q⇩p) c n) = (up_ring.monom (UP Z⇩p) (to_Zp c) n)" using to_Zp_poly_monom[of c] (*‹c ∈ 𝒪⇩p ⟹ to_Zp_poly (monom (UP Q⇩p) c ?n) = monom (UP Z⇩p) (to_Zp c) ?n›*) A(4) (*‹∀i. p i ∈ 𝒪⇩p›*) c_def (*‹c = p (deg Q⇩p p)›*) by blast have 15: "Zp.to_fun (to_Zp_poly q ⊕⇘UP Z⇩p⇙ to_Zp_poly (up_ring.monom (UP Q⇩p) c n)) (to_Zp a)= Zp.to_fun (to_Zp_poly q) (to_Zp a) ⊕⇘Z⇩p⇙ Zp.to_fun (to_Zp_poly (up_ring.monom (UP Q⇩p) c n)) (to_Zp a)" apply (rule Zp.to_fun_plus (*‹⟦?g ∈ carrier (UP Z⇩p); ?f ∈ carrier (UP Z⇩p); ?x ∈ carrier Z⇩p⟧ ⟹ Zp.to_fun (?f ⊕⇘UP Z⇩p⇙ ?g) ?x = Zp.to_fun ?f ?x ⊕⇘Z⇩p⇙ Zp.to_fun ?g ?x›*)) (*goal: ‹Zp.to_fun (to_Zp_poly (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ⊕⇘UP (Z⇩p::(nat ⇒ int) ring)⇙ to_Zp_poly (monom (UP Q⇩p) (c::((nat ⇒ int) × (nat ⇒ int)) set) (n::nat))) (to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set)) = Zp.to_fun (to_Zp_poly q) (to_Zp a) ⊕⇘Z⇩p⇙ Zp.to_fun (to_Zp_poly (monom (UP Q⇩p) c n)) (to_Zp a)›*) unfolding "14" (*goals: 1. ‹monom (UP Z⇩p) (to_Zp c) n ∈ carrier (UP Z⇩p)› 2. ‹to_Zp_poly q ∈ carrier (UP Z⇩p)› 3. ‹to_Zp a ∈ carrier Z⇩p›*) apply (rule UP_ring.monom_closed (*‹⟦UP_ring ?R; ?a ∈ carrier ?R⟧ ⟹ monom (UP ?R) ?a ?n ∈ carrier (UP ?R)›*)) (*top goal: ‹monom (UP Z⇩p) (to_Zp c) n ∈ carrier (UP Z⇩p)› and 2 goals remain*) unfolding UP_ring_def (*goals: 1. ‹ring Z⇩p› 2. ‹to_Zp c ∈ carrier Z⇩p› 3. ‹to_Zp_poly q ∈ carrier (UP Z⇩p)› 4. ‹to_Zp a ∈ carrier Z⇩p›*) apply (simp add: Zp.ring_axioms (*‹ring Z⇩p›*)) (*top goal: ‹ring Z⇩p› and 3 goals remain*) apply (simp add: A( (*‹p ∈ carrier (UP Q⇩p)›*) 2) UPQ.cfs_closed (*‹?f ∈ carrier (UP Q⇩p) ⟹ ?f ?n ∈ carrier Q⇩p›*) c_def (*‹c = p (deg Q⇩p p)›*) to_Zp_closed (*‹?a ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier Z⇩p›*)) (*top goal: ‹to_Zp (c::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (Z⇩p::(nat ⇒ int) ring)› and 2 goals remain*) using "12" (*‹to_Zp_poly q ∈ carrier (UP Z⇩p)›*) apply blast (*top goal: ‹to_Zp_poly (q::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP (Z⇩p::(nat ⇒ int) ring))› and 1 goal remains*) apply (rule to_Zp_closed (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier (Z⇩p::(nat ⇒ int) ring)›*)) (*goal: ‹to_Zp a ∈ carrier Z⇩p›*) using assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?i2 ∈ 𝒪⇩p› ‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p›*) val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) by blast have 16: "to_Zp (q ∙ a ⊕ c ⊗ a [^] n) = to_Zp (q ∙ a) ⊕⇘Z⇩p⇙ to_Zp (c ⊗ a [^] n)" apply (rule to_Zp_add (*‹⟦?a ∈ 𝒪⇩p; ?b ∈ 𝒪⇩p⟧ ⟹ to_Zp (?a ⊕ ?b) = to_Zp ?a ⊕⇘Z⇩p⇙ to_Zp ?b›*)) (*goal: ‹to_Zp (q ∙ a ⊕ c ⊗ a [^] n) = to_Zp (q ∙ a) ⊕⇘Z⇩p⇙ to_Zp (c ⊗ a [^] n)›*) apply (rule val_ring_poly_eval (*‹⟦?f ∈ carrier (UP Q⇩p); ⋀i. ?f i ∈ 𝒪⇩p; ?x ∈ 𝒪⇩p⟧ ⟹ ?f ∙ ?x ∈ 𝒪⇩p›*), rule q_closed (*‹q ∈ carrier (UP Q⇩p)›*)) (*top goal: ‹q ∙ a ∈ 𝒪⇩p› and 1 goal remains*) using "8" (*‹∀i. q i ∈ 𝒪⇩p›*) apply blast (*top goal: ‹⋀i. q i ∈ 𝒪⇩p› and 2 goals remain*) apply (rule assms (*‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (?i2::nat) ∈ 𝒪⇩p› ‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p›*)) (*top goal: ‹a ∈ 𝒪⇩p› and 1 goal remains*) apply (rule val_ring_times_closed (*‹⟦?a ∈ 𝒪⇩p; ?b ∈ 𝒪⇩p⟧ ⟹ ?a ⊗ ?b ∈ 𝒪⇩p›*)) (*goal: ‹(c::((nat ⇒ int) × (nat ⇒ int)) set) ⊗ (a::((nat ⇒ int) × (nat ⇒ int)) set) [^] (n::nat) ∈ 𝒪⇩p›*) unfolding c_def (*goals: 1. ‹p (deg Q⇩p p) ∈ 𝒪⇩p› 2. ‹a [^] n ∈ 𝒪⇩p›*) using A(4) (*‹∀i. p i ∈ 𝒪⇩p›*) (*goals: 1. ‹p (deg Q⇩p p) ∈ 𝒪⇩p› 2. ‹a [^] n ∈ 𝒪⇩p› discuss goal 1*) apply blast (*discuss goal 2*) apply (rule val_ring_nat_pow_closed (*‹(?a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p ⟹ ?a [^] (?n::nat) ∈ 𝒪⇩p›*)) (*goal: ‹a [^] n ∈ 𝒪⇩p›*) apply (rule assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?i2 ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p›*)) (*proven 2 subgoals*) . have 17: " to_function Z⇩p (up_ring.monom (UP Z⇩p) (to_Zp c) n) (to_Zp a) = to_Zp (c ⊗ a [^] n)" proof (-) (*goal: ‹to_function Z⇩p (monom (UP Z⇩p) (to_Zp c) n) (to_Zp a) = to_Zp (c ⊗ a [^] n)›*) have 170: "to_Zp (c ⊗ a [^] n) = to_Zp c ⊗⇘Z⇩p⇙ to_Zp (a [^] n)" apply (rule to_Zp_mult[of c "a[^]n"] (*‹⟦(c::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p; (a::((nat ⇒ int) × (nat ⇒ int)) set) [^] (n::nat) ∈ 𝒪⇩p⟧ ⟹ to_Zp (c ⊗ a [^] n) = to_Zp c ⊗⇘Z⇩p::(nat ⇒ int) ring⇙ to_Zp (a [^] n)›*)) (*goal: ‹to_Zp (c ⊗ a [^] n) = to_Zp c ⊗⇘Z⇩p⇙ to_Zp (a [^] n)›*) unfolding c_def (*goals: 1. ‹p (deg Q⇩p p) ∈ 𝒪⇩p› 2. ‹a [^] n ∈ 𝒪⇩p›*) using A(4) (*‹∀i. p i ∈ 𝒪⇩p›*) (*goals: 1. ‹(p::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (deg Q⇩p p) ∈ 𝒪⇩p› 2. ‹(a::((nat ⇒ int) × (nat ⇒ int)) set) [^] (n::nat) ∈ 𝒪⇩p› discuss goal 1*) apply blast (*discuss goal 2*) apply (rule val_ring_nat_pow_closed (*‹?a ∈ 𝒪⇩p ⟹ ?a [^] ?n ∈ 𝒪⇩p›*)) (*goal: ‹a [^] n ∈ 𝒪⇩p›*) apply (rule assms (*‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (UP Q⇩p)› ‹(g::nat ⇒ ((nat ⇒ int) × (nat ⇒ int)) set) (?i2::nat) ∈ 𝒪⇩p› ‹(a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ 𝒪⇩p›*)) (*proven 2 subgoals*) . have 171: "to_Zp (a [^] n) = (to_Zp a [^]⇘Z⇩p⇙n)" apply (rule to_Zp_nat_pow (*‹?a ∈ 𝒪⇩p ⟹ to_Zp (?a [^] ?n) = to_Zp ?a [^]⇘Z⇩p⇙ ?n›*)) (*goal: ‹to_Zp (a [^] n) = to_Zp a [^]⇘Z⇩p⇙ n›*) by (rule assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?i2 ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p›*)) have 172: "to_Zp c ∈ carrier Z⇩p " apply (rule to_Zp_closed (*‹?a ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier Z⇩p›*)) (*goal: ‹to_Zp c ∈ carrier Z⇩p›*) unfolding c_def (*goal: ‹p (deg Q⇩p p) ∈ carrier Q⇩p›*) using A(2) (*‹p ∈ carrier (UP Q⇩p)›*) UPQ.UP_car_memE(1) (*‹?g ∈ carrier (UP Q⇩p) ⟹ ?g ?x ∈ carrier Q⇩p›*) by blast have 173: "to_Zp a ∈ carrier Z⇩p " apply (rule to_Zp_closed (*‹?a ∈ carrier Q⇩p ⟹ to_Zp ?a ∈ carrier Z⇩p›*)) (*goal: ‹to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (Z⇩p::(nat ⇒ int) ring)›*) using assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?i2 ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p›*) val_ring_memE (*‹?a ∈ 𝒪⇩p ⟹ 0 ≤ val ?a› ‹?a ∈ 𝒪⇩p ⟹ ?a ∈ carrier Q⇩p›*) by blast show "?thesis" (*goal: ‹to_function Z⇩p (monom (UP Z⇩p) (to_Zp c) n) (to_Zp a) = to_Zp (c ⊗ a [^] n)›*) using "172" (*‹to_Zp c ∈ carrier Z⇩p›*) "173" (*‹to_Zp (a::((nat ⇒ int) × (nat ⇒ int)) set) ∈ carrier (Z⇩p::(nat ⇒ int) ring)›*) Zp.to_fun_monom[of "to_Zp c" "to_Zp a" n] (*‹⟦to_Zp c ∈ carrier Z⇩p; to_Zp a ∈ carrier Z⇩p⟧ ⟹ Zp.to_fun (monom (UP Z⇩p) (to_Zp c) n) (to_Zp a) = to_Zp c ⊗⇘Z⇩p⇙ to_Zp a [^]⇘Z⇩p⇙ n›*) unfolding Zp.to_fun_def "170" "171" (*goal: ‹to_function Z⇩p (monom (UP Z⇩p) (to_Zp c) n) (to_Zp a) = to_Zp c ⊗⇘Z⇩p⇙ to_Zp a [^]⇘Z⇩p⇙ n›*) by blast qed show "?thesis" (*goal: ‹to_function Z⇩p (to_Zp_poly p) (to_Zp a) = to_Zp (p ∙ a)›*) using "15" (*‹Zp.to_fun (to_Zp_poly q ⊕⇘UP Z⇩p⇙ to_Zp_poly (monom (UP Q⇩p) c n)) (to_Zp a) = Zp.to_fun (to_Zp_poly q) (to_Zp a) ⊕⇘Z⇩p⇙ Zp.to_fun (to_Zp_poly (monom (UP Q⇩p) c n)) (to_Zp a)›*) unfolding Zp.to_fun_def "10" "2" "16" "9" (*goal: ‹to_function Z⇩p (to_Zp_poly q ⊕⇘UP Z⇩p⇙ to_Zp_poly (monom (UP Q⇩p) c n)) (to_Zp a) = to_Zp (q ∙ a) ⊕⇘Z⇩p⇙ to_Zp (c ⊗ a [^] n)›*) unfolding "14" "17" (*goal: ‹to_function Z⇩p (to_Zp_poly q ⊕⇘UP Z⇩p⇙ monom (UP Z⇩p) (to_Zp c) n) (to_Zp a) = to_Zp (q ∙ a) ⊕⇘Z⇩p⇙ to_Zp (c ⊗ a [^] n)›*) by blast qed qed qed thus "?thesis" (*goal: ‹to_function Z⇩p (to_Zp_poly g) (to_Zp a) = to_Zp (g ∙ a)›*) using assms (*‹g ∈ carrier (UP Q⇩p)› ‹g ?i2 ∈ 𝒪⇩p› ‹a ∈ 𝒪⇩p›*) by blast qed lemma inc_nat_pow: assumes "a ∈ carrier Z⇩p" shows "ι ([(n::nat)] ⋅⇘Z⇩p⇙a) = [n]⋅(ι a)" apply (induction n) (*goal: ‹ι ([n] ⋅⇘Z⇩p⇙ a) = [n] ⋅ ι a›*) apply (metis Q⇩p_def (*‹Q⇩p ≡ Frac Z⇩p›*) Qp.int_inc_zero (*‹[0] ⋅ 𝟭 = 𝟬›*) Qp.nat_mult_zero (*‹[0] ⋅ ?x = 𝟬›*) Zp.add.nat_pow_0 (*‹[0] ⋅⇘Z⇩p⇙ ?x = 𝟬⇘Z⇩p⇙›*) Zp_int_inc_zero' (*‹[0] ⋅⇘Z⇩p⇙ ?x = 𝟬⇘Z⇩p⇙›*) ι_def (*‹ι ≡ Frac_inc Z⇩p›*) frac_inc_of_int (*‹Frac_inc Z⇩p ([?n] ⋅⇘Z⇩p⇙ 𝟭⇘Z⇩p⇙) = [?n] ⋅⇘Frac Z⇩p⇙ 𝟭⇘Frac Z⇩p⇙›*)) (*top goal: ‹ι ([0] ⋅⇘Z⇩p⇙ a) = [0] ⋅ ι a› and 1 goal remains*) unfolding Qp.add.nat_pow_Suc Zp.add.nat_pow_Suc (*goal: ‹⋀n. ι ([n] ⋅⇘Z⇩p⇙ a) = [n] ⋅ ι a ⟹ ι ([n] ⋅⇘Z⇩p⇙ a ⊕⇘Z⇩p⇙ a) = [n] ⋅ ι a ⊕ ι a›*) using Zp_nat_mult_closed (*‹(?x::nat ⇒ int) ∈ carrier (Z⇩p::(nat ⇒ int) ring) ⟹ [(?n::nat)] ⋅⇘Z⇩p⇙ ?x ∈ carrier Z⇩p›*) assms (*‹a ∈ carrier Z⇩p›*) inc_of_sum (*‹⟦?a ∈ carrier Z⇩p; ?b ∈ carrier Z⇩p⟧ ⟹ ι (?a ⊕⇘Z⇩p⇙ ?b) = ι ?a ⊕ ι ?b›*) by presburger lemma poly_inc_pderiv: assumes "g ∈ carrier (UP Z⇩p)" shows "poly_inc (Zp.pderiv g) = UPQ.pderiv (poly_inc g)" proof (standard) (*goal: ‹⋀x::nat. poly_inc (Zp.pderiv (g::nat ⇒ nat ⇒ int)) x = UPQ.pderiv (poly_inc g) x›*) fix x have 0: "UPQ.pderiv (poly_inc g) x = [Suc x] ⋅ poly_inc g (Suc x)" apply (rule UPQ.pderiv_cfs[of "poly_inc g" x] (*‹poly_inc g ∈ carrier (UP Q⇩p) ⟹ UPQ.pderiv (poly_inc g) x = [Suc x] ⋅ poly_inc g (Suc x)›*)) (*goal: ‹UPQ.pderiv (poly_inc g) x = [Suc x] ⋅ poly_inc g (Suc x)›*) apply (rule poly_inc_closed (*‹?g ∈ carrier (UP Z⇩p) ⟹ poly_inc ?g ∈ carrier (UP Q⇩p)›*)) (*goal: ‹poly_inc g ∈ carrier (UP Q⇩p)›*) by (rule assms (*‹g ∈ carrier (UP Z⇩p)›*)) have 1: "Zp.pderiv g x = [Suc x] ⋅⇘Z⇩p⇙ g (Suc x)" apply (rule Zp.pderiv_cfs[of g x] (*‹g ∈ carrier (UP Z⇩p) ⟹ Zp.pderiv g x = [Suc x] ⋅⇘Z⇩p⇙ g (Suc x)›*)) (*goal: ‹Zp.pderiv g x = [Suc x] ⋅⇘Z⇩p⇙ g (Suc x)›*) by (rule assms (*‹g ∈ carrier (UP Z⇩p)›*)) show "poly_inc (Zp.pderiv g) x = UPQ.pderiv (poly_inc g) x" unfolding "0" (*goal: ‹poly_inc (Zp.pderiv g) x = [Suc x] ⋅ poly_inc g (Suc x)›*) unfolding poly_inc_def "1" (*goal: ‹ι ([Suc x] ⋅⇘Z⇩p⇙ g (Suc x)) = [Suc x] ⋅ ι (g (Suc x))›*) apply (rule inc_nat_pow (*‹?a ∈ carrier Z⇩p ⟹ ι ([?n] ⋅⇘Z⇩p⇙ ?a) = [?n] ⋅ ι ?a›*)) (*goal: ‹ι ([Suc x] ⋅⇘Z⇩p⇙ g (Suc x)) = [Suc x] ⋅ ι (g (Suc x))›*) using Zp.UP_car_memE(1) (*‹?g ∈ carrier (UP Z⇩p) ⟹ ?g ?x ∈ carrier Z⇩p›*) assms (*‹g ∈ carrier (UP Z⇩p)›*) by blast qed lemma Zp_hensels_lemma: assumes "f ∈ carrier Zp_x" assumes "a ∈ carrier Z⇩p" assumes "Zp.to_fun (Zp.pderiv f) a ≠ 𝟬⇘Z⇩p⇙" assumes "Zp.to_fun f a ≠ 𝟬⇘Z⇩p ⇙" assumes "val_Zp (Zp.to_fun f a) > eint 2 * val_Zp (Zp.to_fun (Zp.pderiv f) a)" obtains α where "Zp.to_fun f α = 𝟬⇘Z⇩p⇙" and "α ∈ carrier Z⇩p" "val_Zp (a ⊖⇘Z⇩p⇙ α) > val_Zp (Zp.to_fun (Zp.pderiv f) a)" "val_Zp (a ⊖⇘Z⇩p⇙ α) = val_Zp (divide (Zp.to_fun f a) (Zp.to_fun (Zp.pderiv f) a))" "val_Zp (Zp.to_fun (Zp.pderiv f) α) = val_Zp (Zp.to_fun (Zp.pderiv f) a)" proof (-) (*goal: ‹(⋀α. ⟦Zp.to_fun f α = 𝟬⇘Z⇩p⇙; α ∈ carrier Z⇩p; val_Zp (Zp.to_fun (Zp.pderiv f) a) < val_Zp (a ⊖⇘Z⇩p⇙ α); val_Zp (a ⊖⇘Z⇩p⇙ α) = val_Zp (local.divide (Zp.to_fun f a) (Zp.to_fun (Zp.pderiv f) a)); val_Zp (Zp.to_fun (Zp.pderiv f) α) = val_Zp (Zp.to_fun (Zp.pderiv f) a)⟧ ⟹ thesis) ⟹ thesis›*) have "hensel p f a" using assms (*‹f ∈ carrier (UP Z⇩p)› ‹a ∈ carrier Z⇩p› ‹Zp.to_fun (Zp.pderiv f) a ≠ 𝟬⇘Z⇩p⇙› ‹Zp.to_fun f a ≠ 𝟬⇘Z⇩p⇙› ‹eint 2 * val_Zp (Zp.to_fun (Zp.pderiv f) a) < val_Zp (Zp.to_fun f a)›*) by (simp add: Zp_def (*‹Z⇩p ≡ padic_int p›*) hensel.intro (*‹⟦padic_integers ?p; hensel_axioms ?p ?f ?a⟧ ⟹ hensel ?p ?f ?a›*) hensel_axioms.intro (*‹⟦?f ∈ carrier (UP (padic_int ?p)); ?a ∈ carrier (padic_int ?p); UP_cring.to_fun (padic_int ?p) ?f ?a ≠ 𝟬⇘padic_int ?p⇙; eint 2 * padic_integers.val_Zp ?p (UP_cring.to_fun (padic_int ?p) (UP_cring.pderiv (padic_int ?p) ?f) ?a) < padic_integers.val_Zp ?p (UP_cring.to_fun (padic_int ?p) ?f ?a)⟧ ⟹ hensel_axioms ?p ?f ?a›*) padic_integers_axioms (*‹padic_integers p›*)) then show "?thesis" (*goal: ‹thesis::bool›*) using hensel.full_hensels_lemma[of p f a] (*‹⟦hensel p f a; ⋀α. ⟦UP_cring.to_fun (padic_int p) f α = 𝟬⇘padic_int p⇙; α ∈ carrier (padic_int p); val_Zp (UP_cring.to_fun (padic_int p) (UP_cring.pderiv (padic_int p) f) a) < val_Zp (a ⊖⇘padic_int p⇙ α); val_Zp (a ⊖⇘padic_int p⇙ α) = val_Zp (local.divide (UP_cring.to_fun (padic_int p) f a) (UP_cring.to_fun (padic_int p) (UP_cring.pderiv (padic_int p) f) a)); val_Zp (UP_cring.to_fun (padic_int p) (UP_cring.pderiv (padic_int p) f) α) = val_Zp (UP_cring.to_fun (padic_int p) (UP_cring.pderiv (padic_int p) f) a)⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) that (*‹⟦Zp.to_fun f ?α2 = 𝟬⇘Z⇩p⇙; ?α2 ∈ carrier Z⇩p; val_Zp (Zp.to_fun (Zp.pderiv f) a) < val_Zp (a ⊖⇘Z⇩p⇙ ?α2); val_Zp (a ⊖⇘Z⇩p⇙ ?α2) = val_Zp (local.divide (Zp.to_fun f a) (Zp.to_fun (Zp.pderiv f) a)); val_Zp (Zp.to_fun (Zp.pderiv f) ?α2) = val_Zp (Zp.to_fun (Zp.pderiv f) a)⟧ ⟹ thesis›*) unfolding Zp_def (*goal: ‹thesis›*) by blast qed end end
{ "path": "afp-2025-02-12/thys/Padic_Field/Padic_Field_Polynomials.thy", "repo": "afp-2025-02-12", "sha": "b26076a426fc9355981e8996579acef39991eb54d29fad14545f7d35c2d42fb4" }
(* * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230) * Copyright (c) 2022 Apple Inc. All rights reserved. * * SPDX-License-Identifier: BSD-2-Clause *) (* Miscellaneous library definitions and lemmas. *) chapter "Misc. Definitions and Lemmas" theory More_Lib imports Introduction_AutoCorres2 "HOL-Library.Prefix_Order" "Word_Lib.Word_Lib_Sumo" "HOL-Eisbach.Eisbach_Tools" begin (* FIXME: eliminate *) abbreviation (input) split :: "('a ⇒ 'b ⇒ 'c) ⇒ 'a × 'b ⇒ 'c" where "split == case_prod" (* FIXME: eliminate *) lemma hd_map_simp: "b ≠ [] ⟹ hd (map a b) = a (hd b)" by (rule hd_map (*‹(?xs::?'a list) ≠ [] ⟹ hd (map (?f::?'a ⇒ ?'b) ?xs) = ?f (hd ?xs)›*)) lemma tl_map_simp: "tl (map a b) = map a (tl b)" apply (induct b) (*goals: 1. ‹tl (map a []) = map a (tl [])› 2. ‹⋀aa b. tl (map a b) = map a (tl b) ⟹ tl (map a (aa # b)) = map a (tl (aa # b))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . (* FIXME: could be added to Set.thy *) lemma Collect_eq: "{x. P x} = {x. Q x} ⟷ (∀x. P x = Q x)" apply (rule iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*)) (*goals: 1. ‹{x. P x} = {x. Q x} ⟹ ∀x. P x = Q x› 2. ‹∀x. P x = Q x ⟹ {x. P x} = {x. Q x}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . (* FIXME: move next to HOL.iff_allI *) lemma iff_impI: "⟦P ⟹ Q = R⟧ ⟹ (P ⟶ Q) = (P ⟶ R)" by blast (* Long ago, I, fun_app, the verification master of darkness, unleashed an unspeakable evil upon the world. But a foolish proof engineer wielding an input abbreviation stepped forth to oppose me. Before the final blow was struck, I tore open a hole in a number of refinement proofs, and flung him into a broken proof state, where my evil is law. *) definition fun_app :: "('a ⇒ 'b) ⇒ 'a ⇒ 'b" (infixr "$" 10) where "f $ x ≡ f x" declare fun_app_def [iff] lemma fun_app_cong[fundef_cong]: "⟦ f x = f' x' ⟧ ⟹ (f $ x) = (f' $ x')" by simp lemma fun_app_apply_cong[fundef_cong]: "f x y = f' x' y' ⟹ (f $ x) y = (f' $ x') y'" by simp lemma if_apply_cong[fundef_cong]: "⟦ P = P'; x = x'; P' ⟹ f x' = f' x'; ¬ P' ⟹ g x' = g' x' ⟧ ⟹ (if P then f else g) x = (if P' then f' else g') x'" by simp lemma case_prod_apply_cong[fundef_cong]: "⟦ f (fst p) (snd p) s = f' (fst p') (snd p') s' ⟧ ⟹ case_prod f p s = case_prod f' p' s'" by (simp add: split_def (*‹case_prod = (λc p. c (fst p) (snd p))›*)) lemma prod_injects: "(x,y) = p ⟹ x = fst p ∧ y = snd p" "p = (x,y) ⟹ x = fst p ∧ y = snd p" (*goals: 1. ‹(x::'a, y::'b) = (p::'a × 'b) ⟹ x = fst p ∧ y = snd p› 2. ‹(p::'a × 'b) = (x::'a, y::'b) ⟹ x = fst p ∧ y = snd p› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . definition pred_imp :: "('a ⇒ bool) ⇒ ('a ⇒ bool) ⇒ bool" where "pred_imp P Q ≡ ∀x. P x ⟶ Q x" lemma pred_impI: "(⋀x. P x ⟹ Q x) ⟹ pred_imp P Q" by (simp add: pred_imp_def (*‹pred_imp ?P ?Q ≡ ∀x. ?P x ⟶ ?Q x›*)) definition pred_conj :: "('a ⇒ bool) ⇒ ('a ⇒ bool) ⇒ ('a ⇒ bool)" (infixl "and" 35) where "pred_conj P Q ≡ λx. P x ∧ Q x" definition pred_disj :: "('a ⇒ bool) ⇒ ('a ⇒ bool) ⇒ ('a ⇒ bool)" (infixl "or" 30) where "pred_disj P Q ≡ λx. P x ∨ Q x" definition pred_neg :: "('a ⇒ bool) ⇒ ('a ⇒ bool)" ("not _" [40] 40) where "pred_neg P ≡ λx. ¬ P x" lemma pred_neg_simp[simp]: "(not P) s ⟷ ¬ (P s)" by (simp add: pred_neg_def (*‹not ?P ≡ λx. ¬ ?P x›*)) definition "K ≡ λx y. x" definition zipWith :: "('a ⇒ 'b ⇒ 'c) ⇒ 'a list ⇒ 'b list ⇒ 'c list" where "zipWith f xs ys ≡ map (case_prod f) (zip xs ys)" primrec delete :: "'a ⇒ 'a list ⇒ 'a list" where "delete y [] = []" | "delete y (x#xs) = (if y=x then xs else x # delete y xs)" definition "swp f ≡ λx y. f y x" lemma swp_apply[simp]: "swp f y x = f x y" by (simp add: swp_def (*‹swp ?f ≡ λx y. ?f y x›*)) primrec (nonexhaustive) theRight :: "'a + 'b ⇒ 'b" where "theRight (Inr x) = x" primrec (nonexhaustive) theLeft :: "'a + 'b ⇒ 'a" where "theLeft (Inl x) = x" definition "isLeft x ≡ (∃y. x = Inl y)" definition "isRight x ≡ (∃y. x = Inr y)" definition "const x ≡ λy. x" primrec opt_rel :: "('a ⇒ 'b ⇒ bool) ⇒ 'a option ⇒ 'b option ⇒ bool" where "opt_rel f None y = (y = None)" | "opt_rel f (Some x) y = (∃y'. y = Some y' ∧ f x y')" lemma opt_rel_None_rhs[simp]: "opt_rel f x None = (x = None)" apply (cases x) (*goals: 1. ‹x = None ⟹ opt_rel f x None = (x = None)› 2. ‹⋀a. x = Some a ⟹ opt_rel f x None = (x = None)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma opt_rel_Some_rhs[simp]: "opt_rel f x (Some y) = (∃x'. x = Some x' ∧ f x' y)" apply (cases x) (*goals: 1. ‹x = None ⟹ opt_rel f x (Some y) = (∃x'. x = Some x' ∧ f x' y)› 2. ‹⋀a. x = Some a ⟹ opt_rel f x (Some y) = (∃x'. x = Some x' ∧ f x' y)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma tranclD2: "(x, y) ∈ R⁺ ⟹ ∃z. (x, z) ∈ R⇧* ∧ (z, y) ∈ R" apply (erule tranclE (*‹⟦(?a::?'a, ?b::?'a) ∈ (?r::(?'a × ?'a) set)⁺; (?a, ?b) ∈ ?r ⟹ ?thesis::bool; ⋀c::?'a. ⟦(?a, c) ∈ ?r⁺; (c, ?b) ∈ ?r⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) (*goals: 1. ‹(x, y) ∈ R ⟹ ∃z. (x, z) ∈ R⇧* ∧ (z, y) ∈ R› 2. ‹⋀c. ⟦(x, c) ∈ R⁺; (c, y) ∈ R⟧ ⟹ ∃z. (x, z) ∈ R⇧* ∧ (z, y) ∈ R› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma linorder_min_same1 [simp]: "(min y x = y) = (y ≤ (x::'a::linorder))" by (auto simp: min_def (*‹min ?a ?b = (if ?a ≤ ?b then ?a else ?b)›*) linorder_not_less (*‹(¬ ?x < ?y) = (?y ≤ ?x)›*)) lemma linorder_min_same2 [simp]: "(min x y = y) = (y ≤ (x::'a::linorder))" by (auto simp: min_def (*‹min ?a ?b = (if ?a ≤ ?b then ?a else ?b)›*) linorder_not_le (*‹(¬ ?x ≤ ?y) = (?y < ?x)›*)) text ‹A combinator for pairing up well-formed relations. The divisor function splits the population in halves, with the True half greater than the False half, and the supplied relations control the order within the halves.› definition wf_sum :: "('a ⇒ bool) ⇒ ('a × 'a) set ⇒ ('a × 'a) set ⇒ ('a × 'a) set" where "wf_sum divisor r r' ≡ ({(x, y). ¬ divisor x ∧ ¬ divisor y} ∩ r') ∪ {(x, y). ¬ divisor x ∧ divisor y} ∪ ({(x, y). divisor x ∧ divisor y} ∩ r)" lemma wf_sum_wf: "⟦ wf r; wf r' ⟧ ⟹ wf (wf_sum divisor r r')" apply (simp add: wf_sum_def (*‹wf_sum ?divisor ?r ?r' ≡ {(x, y). ¬ ?divisor x ∧ ¬ ?divisor y} ∩ ?r' ∪ {(x, y). ¬ ?divisor x ∧ ?divisor y} ∪ {(x, y). ?divisor x ∧ ?divisor y} ∩ ?r›*)) (*goal: ‹⟦wf r; wf r'⟧ ⟹ wf (wf_sum divisor r r')›*) apply (rule wf_Un (*‹⟦wf (?r::(?'a × ?'a) set); wf (?s::(?'a × ?'a) set); Domain ?r ∩ Range ?s = {}⟧ ⟹ wf (?r ∪ ?s)›*)) (*goals: 1. ‹⟦wf (r::('a × 'a) set); wf (r'::('a × 'a) set)⟧ ⟹ wf ({x::'a. ¬ (divisor::'a ⇒ bool) x} × {y::'a. ¬ divisor y} ∩ r' ∪ {x::'a. ¬ divisor x} × {y::'a. divisor y})› 2. ‹⟦wf (r::('a × 'a) set); wf (r'::('a × 'a) set)⟧ ⟹ wf ({x::'a. (divisor::'a ⇒ bool) x} × {y::'a. divisor y} ∩ r)› 3. ‹⟦wf (r::('a × 'a) set); wf (r'::('a × 'a) set)⟧ ⟹ Domain ({x::'a. ¬ (divisor::'a ⇒ bool) x} × {y::'a. ¬ divisor y} ∩ r' ∪ {x::'a. ¬ divisor x} × {y::'a. divisor y}) ∩ Range ({x::'a. divisor x} × {y::'a. divisor y} ∩ r) = {}› discuss goal 1*) apply (rule wf_Un (*‹⟦wf ?r; wf ?s; Domain ?r ∩ Range ?s = {}⟧ ⟹ wf (?r ∪ ?s)›*)) (*goals: 1. ‹⟦wf (r::('a::type × 'a::type) set); wf (r'::('a::type × 'a::type) set)⟧ ⟹ wf ({x::'a::type. ¬ (divisor::'a::type ⇒ bool) x} × {y::'a::type. ¬ divisor y} ∩ r')› 2. ‹⟦wf (r::('a::type × 'a::type) set); wf (r'::('a::type × 'a::type) set)⟧ ⟹ wf ({x::'a::type. ¬ (divisor::'a::type ⇒ bool) x} × {y::'a::type. divisor y})› 3. ‹⟦wf (r::('a::type × 'a::type) set); wf (r'::('a::type × 'a::type) set)⟧ ⟹ Domain ({x::'a::type. ¬ (divisor::'a::type ⇒ bool) x} × {y::'a::type. ¬ divisor y} ∩ r') ∩ Range ({x::'a::type. ¬ divisor x} × {y::'a::type. divisor y}) = {}› discuss goal 1*) apply (erule wf_Int2 (*‹wf ?r ⟹ wf (?r' ∩ ?r)›*)) (*discuss goal 2*) apply (rule wf_subset [where r="measure (λx. If (divisor x) 1 0)"] (*‹⟦wf (measure (λx. if divisor x then 1 else 0)); ?p ⊆ measure (λx. if divisor x then 1 else 0)⟧ ⟹ wf ?p›*)) (*goals: 1. ‹⟦wf r; wf r'⟧ ⟹ wf (measure (λx. if divisor x then 1 else 0))› 2. ‹⟦wf r; wf r'⟧ ⟹ {x. ¬ divisor x} × {y. divisor y} ⊆ measure (λx. if divisor x then 1 else 0)› discuss goal 1*) apply simp (*discuss goal 2*) apply clarsimp (*proven 2 subgoals*) (*discuss goal 3*) apply blast (*proven 3 subgoals*) (*discuss goal 2*) apply (erule wf_Int2 (*‹wf ?r ⟹ wf (?r' ∩ ?r)›*)) (*discuss goal 3*) apply blast (*proven 3 subgoals*) . abbreviation(input) "option_map == map_option" lemmas option_map_def = map_option_case lemma False_implies_equals [simp]: "((False ⟹ P) ⟹ PROP Q) ≡ PROP Q" apply (rule equal_intr_rule (*‹⟦PROP ?phi ⟹ PROP ?psi; PROP ?psi ⟹ PROP ?phi⟧ ⟹ PROP ?phi ≡ PROP ?psi›*)) (*goals: 1. ‹((False ⟹ P) ⟹ PROP Q) ⟹ PROP Q› 2. ‹⟦PROP Q; False ⟹ P⟧ ⟹ PROP Q› discuss goal 1*) apply (erule meta_mp (*‹⟦PROP ?P::prop ⟹ PROP ?Q::prop; PROP ?P⟧ ⟹ PROP ?Q›*)) (*top goal: ‹((False ⟹ P) ⟹ PROP Q) ⟹ PROP Q› and 1 goal remains*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma split_paired_Ball: "(∀x ∈ A. P x) = (∀x y. (x,y) ∈ A ⟶ P (x,y))" by auto lemma split_paired_Bex: "(∃x ∈ A. P x) = (∃x y. (x,y) ∈ A ∧ P (x,y))" by auto lemma bexI_minus: "⟦ P x; x ∈ A; x ∉ B ⟧ ⟹ ∃x ∈ A - B. P x" unfolding Bex_def (*goal: ‹⟦P x; x ∈ A; x ∉ B⟧ ⟹ ∃x. x ∈ A - B ∧ P x›*) by blast lemma delete_remove1: "delete x xs = remove1 x xs" apply (induct xs) (*goals: 1. ‹delete x [] = remove1 x []› 2. ‹⋀a xs. delete x xs = remove1 x xs ⟹ delete x (a # xs) = remove1 x (a # xs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma ignore_if: "(y and z) s ⟹ (if x then y else z) s" by (clarsimp simp: pred_conj_def (*‹?P and ?Q ≡ λx. ?P x ∧ ?Q x›*)) lemma zipWith_Nil2 : "zipWith f xs [] = []" unfolding zipWith_def (*goal: ‹map2 f xs [] = []›*) by simp lemma isRight_right_map: "isRight (case_sum Inl (Inr o f) v) = isRight v" by (simp add: isRight_def (*‹isRight ?x ≡ ∃y. ?x = Inr y›*) split: sum.split (*‹?P (case ?sum of Inl x ⇒ ?f1.0 x | Inr x ⇒ ?f2.0 x) = ((∀x1. ?sum = Inl x1 ⟶ ?P (?f1.0 x1)) ∧ (∀x2. ?sum = Inr x2 ⟶ ?P (?f2.0 x2)))›*)) lemma zipWith_nth: "⟦ n < min (length xs) (length ys) ⟧ ⟹ zipWith f xs ys ! n = f (xs ! n) (ys ! n)" unfolding zipWith_def (*goal: ‹n < min (length xs) (length ys) ⟹ map2 f xs ys ! n = f (xs ! n) (ys ! n)›*) by simp lemma length_zipWith [simp]: "length (zipWith f xs ys) = min (length xs) (length ys)" unfolding zipWith_def (*goal: ‹length (map2 (f::'b::type ⇒ 'c::type ⇒ 'a::type) (xs::'b::type list) (ys::'c::type list)) = min (length xs) (length ys)›*) by simp lemma first_in_uptoD: "a ≤ b ⟹ (a::'a::order) ∈ {a..b}" by simp lemma construct_singleton: "⟦ S ≠ {}; ∀s∈S. ∀s'. s ≠ s' ⟶ s' ∉ S ⟧ ⟹ ∃x. S = {x}" by blast lemmas insort_com = insort_left_comm lemma bleeding_obvious: "(P ⟹ True) ≡ (Trueprop True)" by auto lemma Some_helper: "x = Some y ⟹ x ≠ None" by simp lemma in_empty_interE: "⟦ A ∩ B = {}; x ∈ A; x ∈ B ⟧ ⟹ False" by blast lemma None_upd_eq: "g x = None ⟹ g(x := None) = g" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹g x = None ⟹ g(x := None) = g›*) by simp lemma exx [iff]: "∃x. x" by blast lemma ExNot [iff]: "Ex Not" by blast lemma cases_simp2 [simp]: "((¬ P ⟶ Q) ∧ (P ⟶ Q)) = Q" by blast lemma a_imp_b_imp_b: "((a ⟶ b) ⟶ b) = (a ∨ b)" by blast lemma length_neq: "length as ≠ length bs ⟹ as ≠ bs" by auto lemma take_neq_length: "⟦ x ≠ y; x ≤ length as; y ≤ length bs⟧ ⟹ take x as ≠ take y bs" apply (rule length_neq (*‹length ?as ≠ length ?bs ⟹ ?as ≠ ?bs›*)) (*goal: ‹⟦x ≠ y; x ≤ length as; y ≤ length bs⟧ ⟹ take x as ≠ take y bs›*) by simp lemma eq_concat_lenD: "xs = ys @ zs ⟹ length xs = length ys + length zs" by simp lemma map_upt_reindex': "map f [a ..< b] = map (λn. f (n + a - x)) [x ..< x + b - a]" apply (rule nth_equalityI (*‹⟦length ?xs = length ?ys; ⋀i. i < length ?xs ⟹ ?xs ! i = ?ys ! i⟧ ⟹ ?xs = ?ys›*)) (*goals: 1. ‹length (map f [a..<b]) = length (map (λn. f (n + a - x)) [x..<x + b - a])› 2. ‹⋀i. i < length (map f [a..<b]) ⟹ map f [a..<b] ! i = map (λn. f (n + a - x)) [x..<x + b - a] ! i› discuss goal 1*) apply (clarsimp simp: add.commute (*‹(?a::?'a) + (?b::?'a) = ?b + ?a›*)) (*discuss goal 2*) apply (clarsimp simp: add.commute (*‹?a + ?b = ?b + ?a›*)) (*proven 2 subgoals*) . lemma map_upt_reindex: "map f [a ..< b] = map (λn. f (n + a)) [0 ..< b - a]" apply (subst map_upt_reindex' [where x=0] (*‹map (?f::nat ⇒ ?'a::type) [?a::nat..<?b::nat] = map (λn::nat. ?f (n + ?a - (0::nat))) [0::nat..<(0::nat) + ?b - ?a]›*)) (*goal: ‹map f [a..<b] = map (λn. f (n + a)) [0..<b - a]›*) by clarsimp lemma notemptyI: "x ∈ S ⟹ S ≠ {}" by clarsimp lemma setcomp_Max_has_prop: assumes a: "P x" shows "P (Max {(x::'a::{finite,linorder}). P x})" proof (-) (*goal: ‹(P::'a ⇒ bool) (Max {x::'a. P x})›*) from a (*‹(P::'a::{finite,linorder} ⇒ bool) (x::'a::{finite,linorder})›*) have "Max {x. P x} ∈ {x. P x}" apply - (*goal: ‹Max {x. P x} ∈ {x. P x}›*) apply (rule Max_in (*‹⟦finite ?A; ?A ≠ {}⟧ ⟹ Max ?A ∈ ?A›*)) (*goals: 1. ‹P x ⟹ finite {x. P x}› 2. ‹P x ⟹ {x. P x} ≠ {}› discuss goal 1*) apply ((auto intro: notemptyI (*‹?x ∈ ?S ⟹ ?S ≠ {}›*))[1]) (*discuss goal 2*) apply ((auto intro: notemptyI (*‹?x ∈ ?S ⟹ ?S ≠ {}›*))[1]) (*proven 2 subgoals*) . thus "?thesis" (*goal: ‹P (Max {x. P x})›*) by auto qed lemma cons_set_intro: "lst = x # xs ⟹ x ∈ set lst" by fastforce lemma list_all2_conj_nth: assumes lall: "list_all2 P as cs" and rl: "⋀n. ⟦P (as ! n) (cs ! n); n < length as⟧ ⟹ Q (as ! n) (cs ! n)" shows "list_all2 (λa b. P a b ∧ Q a b) as cs" proof (rule list_all2_all_nthI (*‹⟦length ?a = length ?b; ⋀n. n < length ?a ⟹ ?P (?a ! n) (?b ! n)⟧ ⟹ list_all2 ?P ?a ?b›*)) (*goals: 1. ‹length as = length cs› 2. ‹⋀n. n < length as ⟹ P (as ! n) (cs ! n) ∧ Q (as ! n) (cs ! n)›*) from lall (*‹list_all2 P as cs›*) show "length as = length cs" by standard next (*goal: ‹⋀n. n < length as ⟹ P (as ! n) (cs ! n) ∧ Q (as ! n) (cs ! n)›*) fix n assume "n < length as" (*‹(n::nat) < length (as::'a list)›*) show "P (as ! n) (cs ! n) ∧ Q (as ! n) (cs ! n)" proof (standard) (*goals: 1. ‹P (as ! n) (cs ! n)› 2. ‹Q (as ! n) (cs ! n)›*) from lall (*‹list_all2 P as cs›*) show "P (as ! n) (cs ! n)" apply (rule list_all2_nthD (*‹⟦list_all2 ?P ?xs ?ys; ?p < length ?xs⟧ ⟹ ?P (?xs ! ?p) (?ys ! ?p)›*)) (*goal: ‹P (as ! n) (cs ! n)›*) by fact thus "Q (as ! n) (cs ! n)" apply (rule rl (*‹⟦P (as ! ?n) (cs ! ?n); ?n < length as⟧ ⟹ Q (as ! ?n) (cs ! ?n)›*)) (*goal: ‹Q (as ! n) (cs ! n)›*) by fact qed qed lemma list_all2_conj: assumes lall1: "list_all2 P as cs" and lall2: "list_all2 Q as cs" shows "list_all2 (λa b. P a b ∧ Q a b) as cs" proof (rule list_all2_all_nthI (*‹⟦length ?a = length ?b; ⋀n. n < length ?a ⟹ ?P (?a ! n) (?b ! n)⟧ ⟹ list_all2 ?P ?a ?b›*)) (*goals: 1. ‹length as = length cs› 2. ‹⋀n. n < length as ⟹ P (as ! n) (cs ! n) ∧ Q (as ! n) (cs ! n)›*) from lall1 (*‹list_all2 P as cs›*) show "length as = length cs" by standard next (*goal: ‹⋀n. n < length as ⟹ P (as ! n) (cs ! n) ∧ Q (as ! n) (cs ! n)›*) fix n assume "n < length as" (*‹(n::nat) < length (as::'a list)›*) show "P (as ! n) (cs ! n) ∧ Q (as ! n) (cs ! n)" proof (standard) (*goals: 1. ‹(P::'a::type ⇒ 'b::type ⇒ bool) ((as::'a::type list) ! (n::nat)) ((cs::'b::type list) ! n)› 2. ‹(Q::'a::type ⇒ 'b::type ⇒ bool) ((as::'a::type list) ! (n::nat)) ((cs::'b::type list) ! n)›*) from lall1 (*‹list_all2 P as cs›*) show "P (as ! n) (cs ! n)" apply (rule list_all2_nthD (*‹⟦list_all2 ?P ?xs ?ys; ?p < length ?xs⟧ ⟹ ?P (?xs ! ?p) (?ys ! ?p)›*)) (*goal: ‹(P::'a ⇒ 'b ⇒ bool) ((as::'a list) ! (n::nat)) ((cs::'b list) ! n)›*) by fact from lall2 (*‹list_all2 (Q::'a ⇒ 'b ⇒ bool) (as::'a list) (cs::'b list)›*) show "Q (as ! n) (cs ! n)" apply (rule list_all2_nthD (*‹⟦list_all2 ?P ?xs ?ys; ?p < length ?xs⟧ ⟹ ?P (?xs ! ?p) (?ys ! ?p)›*)) (*goal: ‹Q (as ! n) (cs ! n)›*) by fact qed qed lemma all_set_into_list_all2: assumes lall: "∀x ∈ set ls. P x" and "length ls = length ls'" shows "list_all2 (λa b. P a) ls ls'" proof (rule list_all2_all_nthI (*‹⟦length ?a = length ?b; ⋀n. n < length ?a ⟹ ?P (?a ! n) (?b ! n)⟧ ⟹ list_all2 ?P ?a ?b›*)) (*goals: 1. ‹length ls = length ls'› 2. ‹⋀n. n < length ls ⟹ P (ls ! n)›*) fix n assume "n < length ls" (*‹(n::nat) < length (ls::'a list)›*) from lall (*‹∀x∈set ls. P x›*) show "P (ls ! n)" apply (rule bspec [OF _ nth_mem] (*‹⟦∀x∈set ?xs1. ?P x; ?n1 < length ?xs1⟧ ⟹ ?P (?xs1 ! ?n1)›*)) (*goal: ‹P (ls ! n)›*) by fact qed (fact) (*solved the remaining goal: ‹length (ls::'a list) = length (ls'::'b list)›*) lemma GREATEST_lessE: fixes x :: "'a :: order" assumes gts: "(GREATEST x. P x) < X" and px: "P x" and gtst: "∃max. P max ∧ (∀z. P z ⟶ (z ≤ max))" shows "x < X" proof (-) (*goal: ‹(x::'a) < (X::'a)›*) from gtst (*‹∃max::'a. (P::'a ⇒ bool) max ∧ (∀z::'a. P z ⟶ z ≤ max)›*) obtain max where pm: "P max" and g': "⋀z. P z ⟹ z ≤ max" (*goal: ‹(⋀max. ⟦P max; ⋀z. P z ⟹ z ≤ max⟧ ⟹ thesis) ⟹ thesis›*) by auto hence "(GREATEST x. P x) = max" by (auto intro: Greatest_equality (*‹⟦?P ?x; ⋀y. ?P y ⟹ y ≤ ?x⟧ ⟹ Greatest ?P = ?x›*)) moreover have "x ≤ max" using px (*‹P x›*) by (rule g' (*‹(P::'a ⇒ bool) (?z::'a) ⟹ ?z ≤ (max::'a)›*)) ultimately show "?thesis" (*goal: ‹x < X›*) using gts (*‹(GREATEST x. P x) < X›*) by simp qed lemma set_has_max: fixes ls :: "('a :: linorder) list" assumes ls: "ls ≠ []" shows "∃max ∈ set ls. ∀z ∈ set ls. z ≤ max" using ls (*‹(ls::'a list) ≠ []›*) proof (induct ls) (*goals: 1. ‹[] ≠ [] ⟹ ∃max∈set []. ∀z∈set []. z ≤ max› 2. ‹⋀a ls. ⟦ls ≠ [] ⟹ ∃max∈set ls. ∀z∈set ls. z ≤ max; a # ls ≠ []⟧ ⟹ ∃max∈set (a # ls). ∀z∈set (a # ls). z ≤ max›*) case Nil (*‹[] ≠ []›*) thus "?case" (*goal: ‹∃max∈set []. ∀z∈set []. z ≤ max›*) by simp next (*goal: ‹⋀a ls. ⟦ls ≠ [] ⟹ ∃max∈set ls. ∀z∈set ls. z ≤ max; a # ls ≠ []⟧ ⟹ ∃max∈set (a # ls). ∀z∈set (a # ls). z ≤ max›*) case (Cons l ls) (*‹ls ≠ [] ⟹ ∃max∈set ls. ∀z∈set ls. z ≤ max› ‹l # ls ≠ []›*) show "?case" (*goal: ‹∃max∈set (l # ls). ∀z∈set (l # ls). z ≤ max›*) proof (cases "ls = []") (*goals: 1. ‹ls = [] ⟹ ∃max∈set (l # ls). ∀z∈set (l # ls). z ≤ max› 2. ‹ls ≠ [] ⟹ ∃max∈set (l # ls). ∀z∈set (l # ls). z ≤ max›*) case True (*‹ls = []›*) thus "?thesis" (*goal: ‹∃max::'a::linorder∈set ((l::'a::linorder) # (ls::'a::linorder list)). ∀z::'a::linorder∈set (l # ls). z ≤ max›*) by simp next (*goal: ‹(ls::'a list) ≠ [] ⟹ ∃max::'a∈set ((l::'a) # ls). ∀z::'a∈set (l # ls). z ≤ max›*) case False (*‹(ls::'a list) ≠ []›*) then obtain max where mv: "max ∈ set ls" and mm: "∀z ∈ set ls. z ≤ max" (*goal: ‹(⋀max. ⟦max ∈ set ls; ∀z∈set ls. z ≤ max⟧ ⟹ thesis) ⟹ thesis›*) using Cons.hyps (*‹ls ≠ [] ⟹ ∃max∈set ls. ∀z∈set ls. z ≤ max›*) by auto show "?thesis" (*goal: ‹∃max::'a∈set ((l::'a) # (ls::'a list)). ∀z::'a∈set (l # ls). z ≤ max›*) proof (cases "max ≤ l") (*goals: 1. ‹max ≤ l ⟹ ∃max∈set (l # ls). ∀z∈set (l # ls). z ≤ max› 2. ‹¬ max ≤ l ⟹ ∃max∈set (l # ls). ∀z∈set (l # ls). z ≤ max›*) case True (*‹max ≤ l›*) have "l ∈ set (l # ls)" by simp thus "?thesis" (*goal: ‹∃max∈set (l # ls). ∀z∈set (l # ls). z ≤ max›*) proof (standard) (*goal: ‹∀z∈set (l # ls). z ≤ l›*) from mm (*‹∀z∈set ls. z ≤ max›*) show "∀z ∈ set (l # ls). z ≤ l" using True (*‹max ≤ l›*) by auto qed next (*goal: ‹¬ max ≤ l ⟹ ∃max∈set (l # ls). ∀z∈set (l # ls). z ≤ max›*) case False (*‹¬ max ≤ l›*) from mv (*‹max ∈ set ls›*) have "max ∈ set (l # ls)" by simp thus "?thesis" (*goal: ‹∃max∈set (l # ls). ∀z∈set (l # ls). z ≤ max›*) proof (standard) (*goal: ‹∀z∈set (l # ls). z ≤ max›*) from mm (*‹∀z∈set ls. z ≤ max›*) show "∀z ∈ set (l # ls). z ≤ max" using False (*‹¬ max ≤ l›*) by auto qed qed qed qed lemma True_notin_set_replicate_conv: "True ∉ set ls = (ls = replicate (length ls) False)" apply (induct ls) (*goals: 1. ‹(True ∉ set []) = ([] = replicate (length []) False)› 2. ‹⋀(a::bool) ls::bool list. (True ∉ set ls) = (ls = replicate (length ls) False) ⟹ (True ∉ set (a # ls)) = (a # ls = replicate (length (a # ls)) False)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma Collect_singleton_eqI: "(⋀x. P x = (x = v)) ⟹ {x. P x} = {v}" by auto lemma exEI: "⟦ ∃y. P y; ⋀x. P x ⟹ Q x ⟧ ⟹ ∃z. Q z" apply (rule ex_forward (*‹⟦∃x. ?P' x; ⋀x. ?P' x ⟹ ?P x⟧ ⟹ ∃x. ?P x›*)) (*goals: 1. ‹⟦∃y::'a. (P::'a ⇒ bool) y; ⋀x::'a. P x ⟹ (Q::'a ⇒ bool) x⟧ ⟹ ∃z::'a. (?P'::'a ⇒ bool) z› 2. ‹⋀z::'a. ⟦∃y::'a. (P::'a ⇒ bool) y; ⋀x::'a. P x ⟹ (Q::'a ⇒ bool) x; (?P'::'a ⇒ bool) z⟧ ⟹ Q z› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) lemma allEI: assumes "∀x. P x" assumes "⋀x. P x ⟹ Q x" shows "∀x. Q x" using assms (*‹∀x::'a. (P::'a ⇒ bool) x› ‹P ?x ⟹ Q ?x›*) by (rule all_forward (*‹⟦∀x. ?P' x; ⋀x. ?P' x ⟹ ?P x⟧ ⟹ ∀x. ?P x›*)) text ‹General lemmas that should be in the library› lemma dom_ran: "x ∈ dom f ⟹ the (f x) ∈ ran f" by (simp add: domD (*‹?a ∈ dom ?m ⟹ ∃b. ?m ?a = Some b›*) ranI (*‹?m ?a = Some ?b ⟹ ?b ∈ ran ?m›*)) lemma orthD1: "⟦ S ∩ S' = {}; x ∈ S⟧ ⟹ x ∉ S'" by auto lemma orthD2: "⟦ S ∩ S' = {}; x ∈ S'⟧ ⟹ x ∉ S" by auto lemma distinct_element: "⟦ b ∩ d = {}; a ∈ b; c ∈ d⟧⟹ a ≠ c" by auto lemma ball_reorder: "(∀x ∈ A. ∀y ∈ B. P x y) = (∀y ∈ B. ∀x ∈ A. P x y)" by auto lemma hd_map: "ls ≠ [] ⟹ hd (map f ls) = f (hd ls)" apply (cases ls) (*goals: 1. ‹⟦ls ≠ []; ls = []⟧ ⟹ hd (map f ls) = f (hd ls)› 2. ‹⋀a list. ⟦ls ≠ []; ls = a # list⟧ ⟹ hd (map f ls) = f (hd ls)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma tl_map: "tl (map f ls) = map f (tl ls)" apply (cases ls) (*goals: 1. ‹ls = [] ⟹ tl (map f ls) = map f (tl ls)› 2. ‹⋀a list. ls = a # list ⟹ tl (map f ls) = map f (tl ls)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma not_NilE: "⟦ xs ≠ []; ⋀x xs'. xs = x # xs' ⟹ R ⟧ ⟹ R" apply (cases xs) (*goals: 1. ‹⟦xs ≠ []; ⋀x xs'. xs = x # xs' ⟹ R; xs = []⟧ ⟹ R› 2. ‹⋀a list. ⟦xs ≠ []; ⋀x xs'. xs = x # xs' ⟹ R; xs = a # list⟧ ⟹ R› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma length_SucE: "⟦ length xs = Suc n; ⋀x xs'. xs = x # xs' ⟹ R ⟧ ⟹ R" apply (cases xs) (*goals: 1. ‹⟦length xs = Suc n; ⋀x xs'. xs = x # xs' ⟹ R; xs = []⟧ ⟹ R› 2. ‹⋀a list. ⟦length xs = Suc n; ⋀x xs'. xs = x # xs' ⟹ R; xs = a # list⟧ ⟹ R› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma map_upt_unfold: assumes ab: "a < b" shows "map f [a ..< b] = f a # map f [Suc a ..< b]" using assms (*‹a < b›*) upt_conv_Cons (*‹(?i::nat) < (?j::nat) ⟹ [?i..<?j] = ?i # [Suc ?i..<?j]›*) by auto lemma tl_nat_list_simp: "tl [a..<b] = [a + 1 ..<b]" apply (induct b) (*goals: 1. ‹tl [a..<0] = [a + 1..<0]› 2. ‹⋀b. tl [a..<b] = [a + 1..<b] ⟹ tl [a..<Suc b] = [a + 1..<Suc b]› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma image_Collect2: "case_prod f ` {x. P (fst x) (snd x)} = {f x y |x y. P x y}" apply (subst image_Collect (*‹?f ` {x. ?P x} = {?f x |x. ?P x}›*)) (*goal: ‹(λ(x::'b, y::'c). (f::'b ⇒ 'c ⇒ 'a) x y) ` {x::'b × 'c. (P::'b ⇒ 'c ⇒ bool) (fst x) (snd x)} = {f x y |(x::'b) y::'c. P x y}›*) by simp lemma image_id': "id ` Y = Y" by clarsimp lemma image_invert: assumes r: "f ∘ g = id" and g: "B = g ` A" shows "A = f ` B" by (simp add: g (*‹B = g ` A›*) image_comp (*‹?f ` ?g ` ?r = (?f ∘ ?g) ` ?r›*) r (*‹f ∘ g = id›*)) lemma Collect_image_fun_cong: assumes rl: "⋀a. P a ⟹ f a = g a" shows "{f x | x. P x} = {g x | x. P x}" using rl (*‹P ?a ⟹ f ?a = g ?a›*) by force lemma inj_on_take: shows "inj_on (take n) {x. drop n x = k}" proof (rule inj_onI (*‹(⋀x y. ⟦x ∈ ?A; y ∈ ?A; ?f x = ?f y⟧ ⟹ x = y) ⟹ inj_on ?f ?A›*)) (*goal: ‹⋀x y. ⟦x ∈ {x. drop n x = k}; y ∈ {x. drop n x = k}; take n x = take n y⟧ ⟹ x = y›*) fix x and y assume xv: "x ∈ {x. drop n x = k}" and yv: "y ∈ {x. drop n x = k}" and tk: "take n x = take n y" (*‹(x::'a list) ∈ {x::'a list. drop (n::nat) x = (k::'a list)}› ‹(y::'a list) ∈ {x::'a list. drop (n::nat) x = (k::'a list)}› ‹take (n::nat) (x::'a list) = take n (y::'a list)›*) from xv (*‹x ∈ {x. drop n x = k}›*) have "take n x @ k = x" using append_take_drop_id (*‹take ?n ?xs @ drop ?n ?xs = ?xs›*) mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*) by auto moreover from yv (*‹y ∈ {x. drop n x = k}›*) tk (*‹take n x = take n y›*) have "take n x @ k = y" using append_take_drop_id (*‹take ?n ?xs @ drop ?n ?xs = ?xs›*) mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*) by auto ultimately show "x = y" by simp qed lemma foldr_upd_dom: "dom (foldr (λp ps. ps (p ↦ f p)) as g) = dom g ∪ set as" proof (induct as) (*goals: 1. ‹dom (foldr (λ(p::'a) ps::'a ⇒ 'b option. ps(p ↦ (f::'a ⇒ 'b) p)) [] (g::'a ⇒ 'b option)) = dom g ∪ set []› 2. ‹⋀(a::'a) as::'a list. dom (foldr (λ(p::'a) ps::'a ⇒ 'b option. ps(p ↦ (f::'a ⇒ 'b) p)) as (g::'a ⇒ 'b option)) = dom g ∪ set as ⟹ dom (foldr (λ(p::'a) ps::'a ⇒ 'b option. ps(p ↦ f p)) (a # as) g) = dom g ∪ set (a # as)›*) case Nil (*no hyothesis introduced yet*) thus "?case" (*goal: ‹dom (foldr (λp ps. ps(p ↦ f p)) [] g) = dom g ∪ set []›*) by simp next (*goal: ‹⋀(a::'a) as::'a list. dom (foldr (λ(p::'a) ps::'a ⇒ 'b option. ps(p ↦ (f::'a ⇒ 'b) p)) as (g::'a ⇒ 'b option)) = dom g ∪ set as ⟹ dom (foldr (λ(p::'a) ps::'a ⇒ 'b option. ps(p ↦ f p)) (a # as) g) = dom g ∪ set (a # as)›*) case (Cons a as) (*‹dom (foldr (λ(p::'a) ps::'a ⇒ 'b option. ps(p ↦ (f::'a ⇒ 'b) p)) (as::'a list) (g::'a ⇒ 'b option)) = dom g ∪ set as›*) show "?case" (*goal: ‹dom (foldr (λ(p::'a::type) ps::'a::type ⇒ 'b::type option. ps(p ↦ (f::'a::type ⇒ 'b::type) p)) ((a::'a::type) # (as::'a::type list)) (g::'a::type ⇒ 'b::type option)) = dom g ∪ set (a # as)›*) proof (cases "a ∈ set as ∨ a ∈ dom g") (*goals: 1. ‹a ∈ set as ∨ a ∈ dom g ⟹ dom (foldr (λp ps. ps(p ↦ f p)) (a # as) g) = dom g ∪ set (a # as)› 2. ‹¬ (a ∈ set as ∨ a ∈ dom g) ⟹ dom (foldr (λp ps. ps(p ↦ f p)) (a # as) g) = dom g ∪ set (a # as)›*) case True (*‹(a::'a) ∈ set (as::'a list) ∨ a ∈ dom (g::'a ⇒ 'b option)›*) hence ain: "a ∈ dom g ∪ set as" by auto hence "dom g ∪ set (a # as) = dom g ∪ set as" by auto thus "?thesis" (*goal: ‹dom (foldr (λp ps. ps(p ↦ f p)) (a # as) g) = dom g ∪ set (a # as)›*) using Cons (*‹dom (foldr (λp ps. ps(p ↦ f p)) as g) = dom g ∪ set as›*) by fastforce next (*goal: ‹¬ (a ∈ set as ∨ a ∈ dom g) ⟹ dom (foldr (λp ps. ps(p ↦ f p)) (a # as) g) = dom g ∪ set (a # as)›*) case False (*‹¬ (a ∈ set as ∨ a ∈ dom g)›*) hence "a ∉ (dom g ∪ set as)" by simp hence "dom g ∪ set (a # as) = insert a (dom g ∪ set as)" by simp thus "?thesis" (*goal: ‹dom (foldr (λp ps. ps(p ↦ f p)) (a # as) g) = dom g ∪ set (a # as)›*) using Cons (*‹dom (foldr (λp ps. ps(p ↦ f p)) as g) = dom g ∪ set as›*) by fastforce qed qed lemma foldr_upd_app: assumes xin: "x ∈ set as" shows "(foldr (λp ps. ps (p ↦ f p)) as g) x = Some (f x)" (is "(?f as g) x = Some (f x)") using xin (*‹x ∈ set as›*) proof (induct as arbitrary: x) (*goals: 1. ‹⋀x. x ∈ set [] ⟹ foldr (λp ps. ps(p ↦ f p)) [] g x = Some (f x)› 2. ‹⋀a as x. ⟦⋀x. x ∈ set as ⟹ foldr (λp ps. ps(p ↦ f p)) as g x = Some (f x); x ∈ set (a # as)⟧ ⟹ foldr (λp ps. ps(p ↦ f p)) (a # as) g x = Some (f x)›*) case Nil (*‹x ∈ set []›*) thus "?case" (*goal: ‹foldr (λ(p::'a) ps::'a ⇒ 'b option. ps(p ↦ (f::'a ⇒ 'b) p)) [] (g::'a ⇒ 'b option) (x::'a) = Some (f x)›*) by simp next (*goal: ‹⋀a as x. ⟦⋀x. x ∈ set as ⟹ foldr (λp ps. ps(p ↦ f p)) as g x = Some (f x); x ∈ set (a # as)⟧ ⟹ foldr (λp ps. ps(p ↦ f p)) (a # as) g x = Some (f x)›*) case (Cons a as) (*‹?x ∈ set as ⟹ foldr (λp ps. ps(p ↦ f p)) as g ?x = Some (f ?x)› ‹x ∈ set (a # as)›*) from Cons.prems (*‹x ∈ set (a # as)›*) show "?case" (*goal: ‹foldr (λp ps. ps(p ↦ f p)) (a # as) g x = Some (f x)›*) apply (subst foldr.simps (*‹foldr ?f [] = id› ‹foldr ?f (?x # ?xs) = ?f ?x ∘ foldr ?f ?xs›*)) (*goal: ‹foldr (λp ps. ps(p ↦ f p)) (a # as) g x = Some (f x)›*) by (auto intro: Cons.hyps (*‹?x ∈ set as ⟹ foldr (λp ps. ps(p ↦ f p)) as g ?x = Some (f ?x)›*)) qed lemma foldr_upd_app_other: assumes xin: "x ∉ set as" shows "(foldr (λp ps. ps (p ↦ f p)) as g) x = g x" (is "(?f as g) x = g x") using xin (*‹x ∉ set as›*) proof (induct as arbitrary: x) (*goals: 1. ‹⋀x. x ∉ set [] ⟹ foldr (λp ps. ps(p ↦ f p)) [] g x = g x› 2. ‹⋀a as x. ⟦⋀x. x ∉ set as ⟹ foldr (λp ps. ps(p ↦ f p)) as g x = g x; x ∉ set (a # as)⟧ ⟹ foldr (λp ps. ps(p ↦ f p)) (a # as) g x = g x›*) case Nil (*‹x ∉ set []›*) thus "?case" (*goal: ‹foldr (λp ps. ps(p ↦ f p)) [] g x = g x›*) by simp next (*goal: ‹⋀a as x. ⟦⋀x. x ∉ set as ⟹ foldr (λp ps. ps(p ↦ f p)) as g x = g x; x ∉ set (a # as)⟧ ⟹ foldr (λp ps. ps(p ↦ f p)) (a # as) g x = g x›*) case (Cons a as) (*‹?x ∉ set as ⟹ foldr (λp ps. ps(p ↦ f p)) as g ?x = g ?x› ‹x ∉ set (a # as)›*) from Cons.prems (*‹(x::'a) ∉ set ((a::'a) # (as::'a list))›*) show "?case" (*goal: ‹foldr (λp ps. ps(p ↦ f p)) (a # as) g x = g x›*) apply (subst foldr.simps (*‹foldr (?f::?'a ⇒ ?'b ⇒ ?'b) [] = id› ‹foldr (?f::?'a ⇒ ?'b ⇒ ?'b) ((?x::?'a) # (?xs::?'a list)) = ?f ?x ∘ foldr ?f ?xs›*)) (*goal: ‹foldr (λp ps. ps(p ↦ f p)) (a # as) g x = g x›*) by (auto intro: Cons.hyps (*‹?x ∉ set as ⟹ foldr (λp ps. ps(p ↦ f p)) as g ?x = g ?x›*)) qed lemma foldr_upd_app_if: "foldr (λp ps. ps(p ↦ f p)) as g = (λx. if x ∈ set as then Some (f x) else g x)" by (auto simp: foldr_upd_app (*‹?x ∈ set ?as ⟹ foldr (λp ps. ps(p ↦ ?f p)) ?as ?g ?x = Some (?f ?x)›*) foldr_upd_app_other (*‹?x ∉ set ?as ⟹ foldr (λp ps. ps(p ↦ ?f p)) ?as ?g ?x = ?g ?x›*)) lemma foldl_fun_upd_value: "⋀Y. foldl (λf p. f(p := X p)) Y e p = (if p∈set e then X p else Y p)" apply (induct e) (*goals: 1. ‹⋀Y. foldl (λf p. f(p := X p)) Y [] p = (if p ∈ set [] then X p else Y p)› 2. ‹⋀a e Y. (⋀Y. foldl (λf p. f(p := X p)) Y e p = (if p ∈ set e then X p else Y p)) ⟹ foldl (λf p. f(p := X p)) Y (a # e) p = (if p ∈ set (a # e) then X p else Y p)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma foldr_fun_upd_value: "⋀Y. foldr (λp f. f(p := X p)) e Y p = (if p∈set e then X p else Y p)" apply (induct e) (*goals: 1. ‹⋀Y::'a ⇒ 'b. foldr (λ(p::'a) f::'a ⇒ 'b. f(p := (X::'a ⇒ 'b) p)) [] Y (p::'a) = (if p ∈ set [] then X p else Y p)› 2. ‹⋀(a::'a) (e::'a list) Y::'a ⇒ 'b. (⋀Y::'a ⇒ 'b. foldr (λ(p::'a) f::'a ⇒ 'b. f(p := (X::'a ⇒ 'b) p)) e Y (p::'a) = (if p ∈ set e then X p else Y p)) ⟹ foldr (λ(p::'a) f::'a ⇒ 'b. f(p := X p)) (a # e) Y p = (if p ∈ set (a # e) then X p else Y p)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma foldl_fun_upd_eq_foldr: "!!m. foldl (λf p. f(p := g p)) m xs = foldr (λp f. f(p := g p)) xs m" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹⋀m. foldl (λf p. f(p := g p)) m xs = foldr (λp f. f(p := g p)) xs m›*) by (simp add: foldl_fun_upd_value (*‹foldl (λf p. f(p := ?X p)) ?Y ?e ?p = (if ?p ∈ set ?e then ?X ?p else ?Y ?p)›*) foldr_fun_upd_value (*‹foldr (λp f. f(p := ?X p)) ?e ?Y ?p = (if ?p ∈ set ?e then ?X ?p else ?Y ?p)›*)) lemma Cons_eq_neq: "⟦ y = x; x # xs ≠ y # ys ⟧ ⟹ xs ≠ ys" by simp lemma map_upt_append: assumes lt: "x ≤ y" and lt2: "a ≤ x" shows "map f [a ..< y] = map f [a ..< x] @ map f [x ..< y]" apply (subst map_append [symmetric] (*‹map ?f ?xs @ map ?f ?ys = map ?f (?xs @ ?ys)›*)) (*goal: ‹map f [a..<y] = map f [a..<x] @ map f [x..<y]›*) proof (rule arg_cong [where f = "map f"] (*‹(?x::nat list) = (?y::nat list) ⟹ map (f::nat ⇒ 'a) ?x = map f ?y›*)) (*goal: ‹[a..<y] = [a..<x] @ [x..<y]›*) from lt (*‹(x::nat) ≤ (y::nat)›*) obtain k where ky: "x + k = y" (*goal: ‹(⋀k. x + k = y ⟹ thesis) ⟹ thesis›*) by (auto simp: le_iff_add (*‹((?a::?'a) ≤ (?b::?'a)) = (∃c::?'a. ?b = ?a + c)›*)) thus "[a ..< y] = [a ..< x] @ [x ..< y]" using lt2 (*‹(a::nat) ≤ (x::nat)›*) by (auto intro: upt_add_eq_append (*‹?i ≤ ?j ⟹ [?i..<?j + ?k] = [?i..<?j] @ [?j..<?j + ?k]›*)) qed lemma Min_image_distrib: assumes minf: "⋀x y. ⟦ x ∈ A; y ∈ A ⟧ ⟹ min (f x) (f y) = f (min x y)" and fa: "finite A" and ane: "A ≠ {}" shows "Min (f ` A) = f (Min A)" proof (-) (*goal: ‹Min (f ` A) = f (Min A)›*) have rl: "⋀F. ⟦ F ⊆ A; F ≠ {} ⟧ ⟹ Min (f ` F) = f (Min F)" proof (-) (*goal: ‹⋀F. ⟦F ⊆ A; F ≠ {}⟧ ⟹ Min (f ` F) = f (Min F)›*) fix F assume fa: "F ⊆ A" and fne: "F ≠ {}" (*‹(F::'a set) ⊆ (A::'a set)› ‹(F::'a set) ≠ {}›*) have "finite F" apply (rule finite_subset (*‹⟦?A ⊆ ?B; finite ?B⟧ ⟹ finite ?A›*)) (*goals: 1. ‹F ⊆ ?B› 2. ‹finite ?B› discuss goal 1*) apply fact (*discuss goal 2*) apply fact (*proven 2 subgoals*) . thus "?thesis F" (*goal: ‹Min (f ` F) = f (Min F)›*) unfolding min_def (*goal: ‹Min ((f::'a ⇒ 'b) ` (F::'a set)) = f (Min F)›*) using fa (*‹(F::'a set) ⊆ (A::'a set)›*) fne (*‹F ≠ {}›*) fa (*‹F ⊆ A›*) proof (induct rule: finite_subset_induct (*‹⟦finite (?F::?'a set); ?F ⊆ (?A::?'a set); (?P::?'a set ⇒ bool) {}; ⋀(a::?'a) F::?'a set. ⟦finite F; a ∈ ?A; a ∉ F; ?P F⟧ ⟹ ?P (insert a F)⟧ ⟹ ?P ?F›*)) (*goals: 1. ‹⟦{} ≠ {}; {} ⊆ A⟧ ⟹ Min (f ` {}) = f (Min {})› 2. ‹⋀a F. ⟦finite F; a ∈ A; a ∉ F; ⟦F ≠ {}; F ⊆ A⟧ ⟹ Min (f ` F) = f (Min F); insert a F ≠ {}; insert a F ⊆ A⟧ ⟹ Min (f ` insert a F) = f (Min (insert a F))›*) case empty (*‹{} ≠ {}› ‹{} ⊆ A›*) thus "?case" (*goal: ‹Min ((f::'a ⇒ 'b) ` {}) = f (Min {})›*) by simp next (*goal: ‹⋀(a::'a::linorder) F::'a::linorder set. ⟦finite F; a ∈ (A::'a::linorder set); a ∉ F; ⟦F ≠ {}; F ⊆ A⟧ ⟹ Min ((f::'a::linorder ⇒ 'b::linorder) ` F) = f (Min F); insert a F ≠ {}; insert a F ⊆ A⟧ ⟹ Min (f ` insert a F) = f (Min (insert a F))›*) case (insert x F) (*‹finite F› ‹x ∈ A› ‹x ∉ F› ‹⟦F ≠ {}; F ⊆ A⟧ ⟹ Min (f ` F) = f (Min F)› ‹insert x F ≠ {}› ‹insert x F ⊆ A›*) thus "?case" (*goal: ‹Min ((f::'a ⇒ 'b) ` insert (x::'a) (F::'a set)) = f (Min (insert x F))›*) apply (cases "F = {}") (*goals: 1. ‹⟦finite F; x ∈ A; x ∉ F; ⟦F ≠ {}; F ⊆ A⟧ ⟹ Min (f ` F) = f (Min F); insert x F ≠ {}; insert x F ⊆ A; F = {}⟧ ⟹ Min (f ` insert x F) = f (Min (insert x F))› 2. ‹⟦finite F; x ∈ A; x ∉ F; ⟦F ≠ {}; F ⊆ A⟧ ⟹ Min (f ` F) = f (Min F); insert x F ≠ {}; insert x F ⊆ A; F ≠ {}⟧ ⟹ Min (f ` insert x F) = f (Min (insert x F))› discuss goal 1*) apply ((auto dest: Min_in (*‹⟦finite ?A; ?A ≠ {}⟧ ⟹ Min ?A ∈ ?A›*) intro: minf (*‹⟦?x ∈ A; ?y ∈ A⟧ ⟹ min (f ?x) (f ?y) = f (min ?x ?y)›*))[1]) (*discuss goal 2*) apply ((auto dest: Min_in (*‹⟦finite (?A::?'a set); ?A ≠ {}⟧ ⟹ Min ?A ∈ ?A›*) intro: minf (*‹⟦(?x::'a) ∈ (A::'a set); (?y::'a) ∈ A⟧ ⟹ min ((f::'a ⇒ 'b) ?x) (f ?y) = f (min ?x ?y)›*))[1]) (*proven 2 subgoals*) . qed qed show "?thesis" (*goal: ‹Min (f ` A) = f (Min A)›*) apply (rule rl [OF order_refl] (*‹A ≠ {} ⟹ Min (f ` A) = f (Min A)›*)) (*goal: ‹Min (f ` A) = f (Min A)›*) by fact qed lemma min_of_mono': assumes "(f a ≤ f c) = (a ≤ c)" shows "min (f a) (f c) = f (min a c)" unfolding min_def (*goal: ‹(if f a ≤ f c then f a else f c) = f (if a ≤ c then a else c)›*) apply (subst if_distrib [where f = f, symmetric] (*‹(if ?c then f ?x else f ?y) = f (if ?c then ?x else ?y)›*)) (*goal: ‹(if f a ≤ f c then f a else f c) = f (if a ≤ c then a else c)›*) apply (rule arg_cong [where f = f] (*‹?x = ?y ⟹ f ?x = f ?y›*)) (*goal: ‹(f::'b::ord ⇒ 'a::ord) (if f (a::'b::ord) ≤ f (c::'b::ord) then a else c) = f (if a ≤ c then a else c)›*) apply (rule if_cong [OF _ refl refl] (*‹(?b::bool) = (?c::bool) ⟹ (if ?b then ?u::?'a else (?v::?'a)) = (if ?c then ?u else ?v)›*)) (*goal: ‹(if f a ≤ f c then a else c) = (if a ≤ c then a else c)›*) by fact lemma nat_diff_less: fixes x :: nat shows "⟦ x < y + z; z ≤ x⟧ ⟹ x - z < y" using less_diff_conv2 (*‹(?k::nat) ≤ (?j::nat) ⟹ (?j - ?k < (?i::nat)) = (?j < ?i + ?k)›*) by blast lemma take_map_Not: "(take n (map Not xs) = take n xs) = (n = 0 ∨ xs = [])" apply (cases n) (*goals: 1. ‹n = 0 ⟹ (take n (map Not xs) = take n xs) = (n = 0 ∨ xs = [])› 2. ‹⋀nat. n = Suc nat ⟹ (take n (map Not xs) = take n xs) = (n = 0 ∨ xs = [])› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*goal: ‹⋀nat. n = Suc nat ⟹ (take n (map Not xs) = take n xs) = (n = 0 ∨ xs = [])›*) apply (cases xs) (*goals: 1. ‹⋀nat::nat. ⟦(n::nat) = Suc nat; (xs::bool list) = []⟧ ⟹ (take (Suc nat) (map Not xs) = take (Suc nat) xs) = (xs = [])› 2. ‹⋀(nat::nat) (a::bool) list::bool list. ⟦(n::nat) = Suc nat; (xs::bool list) = a # list⟧ ⟹ (take (Suc nat) (map Not xs) = take (Suc nat) xs) = (xs = [])› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma union_trans: assumes SR: "⋀x y z. ⟦ (x,y) ∈ S; (y,z) ∈ R ⟧ ⟹ (x,z) ∈ S^*" shows "(R ∪ S)^* = R^* ∪ R^* O S^*" apply (rule set_eqI (*‹(⋀x. (x ∈ ?A) = (x ∈ ?B)) ⟹ ?A = ?B›*)) (*goal: ‹(R ∪ S)⇧* = R⇧* ∪ R⇧* O S⇧*›*) apply clarsimp (*goal: ‹⋀x. (x ∈ (R ∪ S)⇧*) = (x ∈ R⇧* ∪ R⇧* O S⇧*)›*) apply (rule iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*)) (*goals: 1. ‹⋀a b. (a, b) ∈ (R ∪ S)⇧* ⟹ (a, b) ∈ R⇧* ∨ (a, b) ∈ R⇧* O S⇧*› 2. ‹⋀a b. (a, b) ∈ R⇧* ∨ (a, b) ∈ R⇧* O S⇧* ⟹ (a, b) ∈ (R ∪ S)⇧*› discuss goal 1*) apply (erule rtrancl_induct (*‹⟦(?a, ?b) ∈ ?r⇧*; ?P ?a; ⋀y z. ⟦(?a, y) ∈ ?r⇧*; (y, z) ∈ ?r; ?P y⟧ ⟹ ?P z⟧ ⟹ ?P ?b›*)) (*goals: 1. ‹⋀a b. (a, a) ∈ R⇧* ∨ (a, a) ∈ R⇧* O S⇧*› 2. ‹⋀a b y z. ⟦(a, y) ∈ (R ∪ S)⇧*; (y, z) ∈ R ∪ S; (a, y) ∈ R⇧* ∨ (a, y) ∈ R⇧* O S⇧*⟧ ⟹ (a, z) ∈ R⇧* ∨ (a, z) ∈ R⇧* O S⇧*› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*top goal: ‹⋀a b y z. ⟦(a, y) ∈ (R ∪ S)⇧*; (y, z) ∈ R ∪ S; (a, y) ∈ R⇧* ∨ (a, y) ∈ R⇧* O S⇧*⟧ ⟹ (a, z) ∈ R⇧* ∨ (a, z) ∈ R⇧* O S⇧*› and 1 goal remains*) apply (erule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹⋀a y z. ⟦(a, y) ∈ (R ∪ S)⇧*; (a, y) ∈ R⇧* ∨ (a, y) ∈ R⇧* O S⇧*; (y, z) ∈ R⟧ ⟹ (a, z) ∈ R⇧* ∨ (a, z) ∈ R⇧* O S⇧*› 2. ‹⋀a y z. ⟦(a, y) ∈ (R ∪ S)⇧*; (a, y) ∈ R⇧* ∨ (a, y) ∈ R⇧* O S⇧*; (y, z) ∈ S⟧ ⟹ (a, z) ∈ R⇧* ∨ (a, z) ∈ R⇧* O S⇧*› discuss goal 1*) apply (erule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹⋀a y z. ⟦(a, y) ∈ (R ∪ S)⇧*; (y, z) ∈ R; (a, y) ∈ R⇧*⟧ ⟹ (a, z) ∈ R⇧* ∨ (a, z) ∈ R⇧* O S⇧*› 2. ‹⋀a y z. ⟦(a, y) ∈ (R ∪ S)⇧*; (y, z) ∈ R; (a, y) ∈ R⇧* O S⇧*⟧ ⟹ (a, z) ∈ R⇧* ∨ (a, z) ∈ R⇧* O S⇧*› discuss goal 1*) apply (drule (1) rtrancl_into_rtrancl (*‹⟦(?a, ?b) ∈ ?r⇧*; (?b, ?c) ∈ ?r⟧ ⟹ (?a, ?c) ∈ ?r⇧*›*)) (*top goal: ‹⋀a y z. ⟦(a, y) ∈ (R ∪ S)⇧*; (y, z) ∈ R; (a, y) ∈ R⇧*⟧ ⟹ (a, z) ∈ R⇧* ∨ (a, z) ∈ R⇧* O S⇧*› and 3 goals remain*) apply blast (*discuss goal 2*) apply clarsimp (*top goal: ‹⋀a y z. ⟦(a, y) ∈ (R ∪ S)⇧*; (y, z) ∈ R; (a, y) ∈ R⇧* O S⇧*⟧ ⟹ (a, z) ∈ R⇧* ∨ (a, z) ∈ R⇧* O S⇧*› and 2 goals remain*) apply (drule rtranclD [where R=S] (*‹(?a::'a, ?b::'a) ∈ (S::('a × 'a) set)⇧* ⟹ ?a = ?b ∨ ?a ≠ ?b ∧ (?a, ?b) ∈ S⁺›*)) (*top goal: ‹⋀z x ya za. ⟦(x, za) ∈ (R ∪ S)⇧*; (za, z) ∈ R; (x, ya) ∈ R⇧*; (ya, za) ∈ S⇧*; (x, z) ∉ R⇧* O S⇧*⟧ ⟹ (x, z) ∈ R⇧*› and 2 goals remain*) apply (erule disjE (*‹⟦(?P::bool) ∨ (?Q::bool); ?P ⟹ ?R::bool; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹⋀z x ya za. ⟦(x, za) ∈ (R ∪ S)⇧*; (za, z) ∈ R; (x, ya) ∈ R⇧*; (x, z) ∉ R⇧* O S⇧*; ya = za⟧ ⟹ (x, z) ∈ R⇧*› 2. ‹⋀z x ya za. ⟦(x, za) ∈ (R ∪ S)⇧*; (za, z) ∈ R; (x, ya) ∈ R⇧*; (x, z) ∉ R⇧* O S⇧*; ya ≠ za ∧ (ya, za) ∈ S⁺⟧ ⟹ (x, z) ∈ R⇧*› discuss goal 1*) apply simp (*discuss goal 2*) apply (erule conjE (*‹⟦?P ∧ ?Q; ⟦?P; ?Q⟧ ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀(z::'a) (x::'a) (ya::'a) za::'a. ⟦(x, za) ∈ ((R::('a × 'a) set) ∪ (S::('a × 'a) set))⇧*; (za, z) ∈ R; (x, ya) ∈ R⇧*; (x, z) ∉ R⇧* O S⇧*; ya ≠ za ∧ (ya, za) ∈ S⁺⟧ ⟹ (x, z) ∈ R⇧*› and 2 goals remain*) apply (drule tranclD2 (*‹(?x, ?y) ∈ ?R⁺ ⟹ ∃z. (?x, z) ∈ ?R⇧* ∧ (z, ?y) ∈ ?R›*)) (*top goal: ‹⋀z x ya za. ⟦(x, za) ∈ (R ∪ S)⇧*; (za, z) ∈ R; (x, ya) ∈ R⇧*; (x, z) ∉ R⇧* O S⇧*; ya ≠ za; (ya, za) ∈ S⁺⟧ ⟹ (x, z) ∈ R⇧*› and 2 goals remain*) apply (elim exE (*‹⟦∃x::?'a::type. (?P::?'a::type ⇒ bool) x; ⋀x::?'a::type. ?P x ⟹ ?Q::bool⟧ ⟹ ?Q›*) conjE (*‹⟦(?P::bool) ∧ (?Q::bool); ⟦?P; ?Q⟧ ⟹ ?R::bool⟧ ⟹ ?R›*)) (*top goal: ‹⋀z x ya za. ⟦(x, za) ∈ (R ∪ S)⇧*; (za, z) ∈ R; (x, ya) ∈ R⇧*; (x, z) ∉ R⇧* O S⇧*; ya ≠ za; ∃z. (ya, z) ∈ S⇧* ∧ (z, za) ∈ S⟧ ⟹ (x, z) ∈ R⇧*› and 2 goals remain*) apply (drule (1) SR (*‹⟦(?x, ?y) ∈ S; (?y, ?z) ∈ R⟧ ⟹ (?x, ?z) ∈ S⇧*›*)) (*top goal: ‹⋀z x ya za zb. ⟦(x, za) ∈ (R ∪ S)⇧*; (za, z) ∈ R; (x, ya) ∈ R⇧*; (x, z) ∉ R⇧* O S⇧*; ya ≠ za; (ya, zb) ∈ S⇧*; (zb, za) ∈ S⟧ ⟹ (x, z) ∈ R⇧*› and 2 goals remain*) apply (drule (1) rtrancl_trans (*‹⟦(?x::?'a, ?y::?'a) ∈ (?r::(?'a × ?'a) set)⇧*; (?y, ?z::?'a) ∈ ?r⇧*⟧ ⟹ (?x, ?z) ∈ ?r⇧*›*)) (*top goal: ‹⋀(z::'a) (x::'a) (ya::'a) (za::'a) zb::'a. ⟦(x, za) ∈ ((R::('a × 'a) set) ∪ (S::('a × 'a) set))⇧*; (za, z) ∈ R; (x, ya) ∈ R⇧*; (x, z) ∉ R⇧* O S⇧*; ya ≠ za; (ya, zb) ∈ S⇧*; (zb, z) ∈ S⇧*⟧ ⟹ (x, z) ∈ R⇧*› and 2 goals remain*) apply blast (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply (rule disjI2 (*‹?Q ⟹ ?P ∨ ?Q›*)) (*top goal: ‹⋀a y z. ⟦(a, y) ∈ (R ∪ S)⇧*; (a, y) ∈ R⇧* ∨ (a, y) ∈ R⇧* O S⇧*; (y, z) ∈ S⟧ ⟹ (a, z) ∈ R⇧* ∨ (a, z) ∈ R⇧* O S⇧*› and 1 goal remains*) apply (erule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹⋀a y z. ⟦(a, y) ∈ (R ∪ S)⇧*; (y, z) ∈ S; (a, y) ∈ R⇧*⟧ ⟹ (a, z) ∈ R⇧* O S⇧*› 2. ‹⋀a y z. ⟦(a, y) ∈ (R ∪ S)⇧*; (y, z) ∈ S; (a, y) ∈ R⇧* O S⇧*⟧ ⟹ (a, z) ∈ R⇧* O S⇧*› discuss goal 1*) apply (blast intro: in_rtrancl_UnI (*‹?x ∈ ?R⇧* ∨ ?x ∈ ?S⇧* ⟹ ?x ∈ (?R ∪ ?S)⇧*›*)) (*discuss goal 2*) apply clarsimp (*top goal: ‹⋀a y z. ⟦(a, y) ∈ (R ∪ S)⇧*; (y, z) ∈ S; (a, y) ∈ R⇧* O S⇧*⟧ ⟹ (a, z) ∈ R⇧* O S⇧*› and 1 goal remains*) apply (drule (1) rtrancl_into_rtrancl (*‹⟦(?a, ?b) ∈ ?r⇧*; (?b, ?c) ∈ ?r⟧ ⟹ (?a, ?c) ∈ ?r⇧*›*)) (*top goal: ‹⋀z x ya za. ⟦(x, za) ∈ (R ∪ S)⇧*; (za, z) ∈ S; (x, ya) ∈ R⇧*; (ya, za) ∈ S⇧*⟧ ⟹ (x, z) ∈ R⇧* O S⇧*› and 1 goal remains*) apply (erule (1) relcompI (*‹⟦(?a, ?b) ∈ ?r; (?b, ?c) ∈ ?s⟧ ⟹ (?a, ?c) ∈ ?r O ?s›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply (erule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹⋀a b. (a, b) ∈ R⇧* ⟹ (a, b) ∈ (R ∪ S)⇧*› 2. ‹⋀a b. (a, b) ∈ R⇧* O S⇧* ⟹ (a, b) ∈ (R ∪ S)⇧*› discuss goal 1*) apply (blast intro: in_rtrancl_UnI (*‹?x ∈ ?R⇧* ∨ ?x ∈ ?S⇧* ⟹ ?x ∈ (?R ∪ ?S)⇧*›*)) (*discuss goal 2*) apply clarsimp (*goal: ‹⋀a b. (a, b) ∈ R⇧* O S⇧* ⟹ (a, b) ∈ (R ∪ S)⇧*›*) apply (blast intro: in_rtrancl_UnI (*‹?x ∈ ?R⇧* ∨ ?x ∈ ?S⇧* ⟹ ?x ∈ (?R ∪ ?S)⇧*›*) rtrancl_trans (*‹⟦(?x, ?y) ∈ ?r⇧*; (?y, ?z) ∈ ?r⇧*⟧ ⟹ (?x, ?z) ∈ ?r⇧*›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma trancl_trancl: "(R⁺)⁺ = R⁺" by auto text ‹Some rules for showing that the reflexive transitive closure of a relation/predicate doesn't add much if it was already transitively closed.› lemma rtrancl_eq_reflc_trans: assumes trans: "trans X" shows "rtrancl X = X ∪ Id" by (simp only: rtrancl_trancl_reflcl (*‹(?r::(?'a × ?'a) set)⇧* = (?r⁺)⁼›*) trancl_id[OF trans] (*‹(X::('a × 'a) set)⁺ = X›*)) lemma rtrancl_id: assumes refl: "Id ⊆ X" assumes trans: "trans X" shows "rtrancl X = X" using refl (*‹Id ⊆ X›*) rtrancl_eq_reflc_trans[OF trans] (*‹X⇧* = X⁼›*) by blast lemma rtranclp_eq_reflcp_transp: assumes trans: "transp X" shows "rtranclp X = (λx y. X x y ∨ x = y)" by (simp add: Enum.rtranclp_rtrancl_eq (*‹?r⇧*⇧* ?x ?y = ((?x, ?y) ∈ {(x, y). ?r x y}⇧*) › * ) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) rtrancl_eq_reflc_trans (*‹trans ?X ⟹ ?X⇧* = ?X⁼›*) trans[unfolded transp_trans] (*‹trans {(x, y). X x y}›*)) lemma rtranclp_id: shows "reflp X ⟹ transp X ⟹ rtranclp X = X" apply (simp add: rtranclp_eq_reflcp_transp (*‹transp ?X ⟹ ?X⇧*⇧* = (λx y. ?X x y ∨ x = y)›*)) (*goal: ‹⟦reflp X; transp X⟧ ⟹ X⇧*⇧* = X›*) by (auto simp: fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) elim: reflpD (*‹reflp ?R ⟹ ?R ?x ?x›*)) lemmas rtranclp_id2 = rtranclp_id[unfolded reflp_def transp_relcompp le_fun_def] lemma if_1_0_0: "((if P then 1 else 0) = (0 :: ('a :: zero_neq_one))) = (¬ P)" by (simp split: if_split (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))›*)) lemma neq_Nil_lengthI: "Suc 0 ≤ length xs ⟹ xs ≠ []" apply (cases xs) (*goals: 1. ‹⟦Suc 0 ≤ length xs; xs = []⟧ ⟹ xs ≠ []› 2. ‹⋀a list. ⟦Suc 0 ≤ length xs; xs = a # list⟧ ⟹ xs ≠ []› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemmas ex_with_length = Ex_list_of_length lemma in_singleton: "S = {x} ⟹ x ∈ S" by simp lemma singleton_set: "x ∈ set [a] ⟹ x = a" by auto lemma take_drop_eqI: assumes t: "take n xs = take n ys" assumes d: "drop n xs = drop n ys" shows "xs = ys" proof (-) (*goal: ‹xs = ys›*) have "xs = take n xs @ drop n xs" by simp with t (*‹take n xs = take n ys›*) d (*‹drop n xs = drop n ys›*) have "xs = take n ys @ drop n ys" by simp moreover have "ys = take n ys @ drop n ys" by simp ultimately show "?thesis" (*goal: ‹xs = ys›*) by simp qed lemma append_len2: "zs = xs @ ys ⟹ length xs = length zs - length ys" by auto lemma if_flip: "(if ¬P then T else F) = (if P then F else T)" by simp lemma not_in_domIff:"f x = None = (x ∉ dom f)" by blast lemma not_in_domD: "x ∉ dom f ⟹ f x = None" by (simp add:not_in_domIff (*‹((?f::?'b ⇒ ?'a option) (?x::?'b) = None) = (?x ∉ dom ?f)›*)) definition "graph_of f ≡ {(x,y). f x = Some y}" lemma graph_of_None_update: "graph_of (f (p := None)) = graph_of f - {p} × UNIV" by (auto simp: graph_of_def (*‹graph_of ?f ≡ {(x, y). ?f x = Some y}›*) split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) lemma graph_of_Some_update: "graph_of (f (p ↦ v)) = (graph_of f - {p} × UNIV) ∪ {(p,v)}" by (auto simp: graph_of_def (*‹graph_of ?f ≡ {(x, y). ?f x = Some y}›*) split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) lemma graph_of_restrict_map: "graph_of (m |` S) ⊆ graph_of m" by (simp add: graph_of_def (*‹graph_of ?f ≡ {(x, y). ?f x = Some y}›*) restrict_map_def (*‹?m |` ?A = (λx. if x ∈ ?A then ?m x else None)›*) subset_iff (*‹(?A ⊆ ?B) = (∀t. t ∈ ?A ⟶ t ∈ ?B)›*)) lemma graph_ofD: "(x,y) ∈ graph_of f ⟹ f x = Some y" by (simp add: graph_of_def (*‹graph_of ?f ≡ {(x, y). ?f x = Some y}›*)) lemma graph_ofI: "m x = Some y ⟹ (x, y) ∈ graph_of m" by (simp add: graph_of_def (*‹graph_of ?f ≡ {(x, y). ?f x = Some y}›*)) lemma graph_of_empty : "graph_of Map.empty = {}" by (simp add: graph_of_def (*‹graph_of ?f ≡ {(x, y). ?f x = Some y}›*)) lemma graph_of_in_ranD: "∀y ∈ ran f. P y ⟹ (x,y) ∈ graph_of f ⟹ P y" by (auto simp: graph_of_def (*‹graph_of ?f ≡ {(x, y). ?f x = Some y}›*) ran_def (*‹ran ?m = {b. ∃a. ?m a = Some b}›*)) lemma graph_of_SomeD: "⟦ graph_of f ⊆ graph_of g; f x = Some y ⟧ ⟹ g x = Some y" unfolding graph_of_def (*goal: ‹⟦{(x, y). f x = Some y} ⊆ {(x, y). g x = Some y}; f x = Some y⟧ ⟹ g x = Some y›*) by auto lemma graph_of_comp: "⟦ g x = y; f y = Some z ⟧ ⟹ (x,z) ∈ graph_of (f ∘ g)" by (auto simp: graph_of_def (*‹graph_of ?f ≡ {(x, y). ?f x = Some y}›*)) lemma in_set_zip_refl : "(x,y) ∈ set (zip xs xs) = (y = x ∧ x ∈ set xs)" apply (induct xs) (*goals: 1. ‹((x, y) ∈ set (zip [] [])) = (y = x ∧ x ∈ set [])› 2. ‹⋀a xs. ((x, y) ∈ set (zip xs xs)) = (y = x ∧ x ∈ set xs) ⟹ ((x, y) ∈ set (zip (a # xs) (a # xs))) = (y = x ∧ x ∈ set (a # xs))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma map_conv_upd: "m v = None ⟹ m o (f (x := v)) = (m o f) (x := None)" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹m v = None ⟹ m ∘ f(x := v) = (m ∘ f)(x := None)›*) by (clarsimp simp: o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*)) lemma sum_all_ex [simp]: "(∀a. x ≠ Inl a) = (∃a. x = Inr a)" "(∀a. x ≠ Inr a) = (∃a. x = Inl a)" (*goals: 1. ‹(∀a. x ≠ Inl a) = (∃a. x = Inr a)› 2. ‹(∀a. x ≠ Inr a) = (∃a. x = Inl a)› discuss goal 1*) apply (metis Inr_not_Inl (*‹Inr (?b::?'b) ≠ Inl (?a::?'a)›*) sum.exhaust (*‹⟦⋀x1::?'a. (?y::?'a + ?'b) = Inl x1 ⟹ ?P::bool; ⋀x2::?'b. ?y = Inr x2 ⟹ ?P⟧ ⟹ ?P›*)) (*discuss goal 2*) apply (metis Inr_not_Inl (*‹Inr ?b ≠ Inl ?a›*) sum.exhaust (*‹⟦⋀x1. ?y = Inl x1 ⟹ ?P; ⋀x2. ?y = Inr x2 ⟹ ?P⟧ ⟹ ?P›*)) (*proven 2 subgoals*) . lemma split_distrib: "case_prod (λa b. T (f a b)) = (λx. T (case_prod (λa b. f a b) x))" by (clarsimp simp: split_def (*‹case_prod = (λc p. c (fst p) (snd p))›*)) lemma case_sum_triv [simp]: "(case x of Inl x ⇒ Inl x | Inr x ⇒ Inr x) = x" by (clarsimp split: sum.splits (*‹?P (case ?sum of Inl x ⇒ ?f1.0 x | Inr x ⇒ ?f2.0 x) = ((∀x1. ?sum = Inl x1 ⟶ ?P (?f1.0 x1)) ∧ (∀x2. ?sum = Inr x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?sum of Inl x ⇒ ?f1.0 x | Inr x ⇒ ?f2.0 x) = (¬ ((∃x1. ?sum = Inl x1 ∧ ¬ ?P (?f1.0 x1)) ∨ (∃x2. ?sum = Inr x2 ∧ ¬ ?P (?f2.0 x2))))›*)) lemma set_eq_UNIV: "({a. P a} = UNIV) = (∀a. P a)" by force lemma allE2: "⟦∀x y. P x y; P x y ⟹ R⟧ ⟹ R" by blast lemma allE3: "⟦ ∀x y z. P x y z; P x y z ⟹ R ⟧ ⟹ R" by auto lemma my_BallE: "⟦ ∀x ∈ A. P x; y ∈ A; P y ⟹ Q ⟧ ⟹ Q" by (simp add: Ball_def (*‹Ball ?A ?P = (∀x. x ∈ ?A ⟶ ?P x)›*)) lemma unit_Inl_or_Inr [simp]: "(a ≠ Inl ()) = (a = Inr ())" "(a ≠ Inr ()) = (a = Inl ())" (*goals: 1. ‹((a::unit + unit) ≠ Inl ()) = (a = Inr ())› 2. ‹((a::unit + unit) ≠ Inr ()) = (a = Inl ())› discuss goal 1*) apply (cases a) (*goals: 1. ‹⋀aa. a = Inl aa ⟹ (a ≠ Inl ()) = (a = Inr ())› 2. ‹⋀b. a = Inr b ⟹ (a ≠ Inl ()) = (a = Inr ())› discuss goal 1*) apply clarsimp (*discuss goal 2*) apply clarsimp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases a) (*goals: 1. ‹⋀aa. a = Inl aa ⟹ (a ≠ Inr ()) = (a = Inl ())› 2. ‹⋀b. a = Inr b ⟹ (a ≠ Inr ()) = (a = Inl ())› discuss goal 1*) apply clarsimp (*discuss goal 2*) apply clarsimp (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma disjE_L: "⟦ a ∨ b; a ⟹ R; ⟦ ¬ a; b ⟧ ⟹ R ⟧ ⟹ R" by blast lemma disjE_R: "⟦ a ∨ b; ⟦ ¬ b; a ⟧ ⟹ R; ⟦ b ⟧ ⟹ R ⟧ ⟹ R" by blast lemma int_max_thms: "(a :: int) ≤ max a b" "(b :: int) ≤ max a b" (*goals: 1. ‹a ≤ max a b› 2. ‹b ≤ max a b› discuss goal 1*) apply ((auto simp: max_def (*‹max ?a ?b = (if ?a ≤ ?b then ?b else ?a)›*))[1]) (*discuss goal 2*) apply ((auto simp: max_def (*‹max ?a ?b = (if ?a ≤ ?b then ?b else ?a)›*))[1]) (*proven 2 subgoals*) . lemma sgn_negation [simp]: "sgn (-(x::int)) = - sgn x" by (clarsimp simp: sgn_if (*‹sgn (?x::?'a) = (if ?x = (0::?'a) then 0::?'a else if (0::?'a) < ?x then 1::?'a else - (1::?'a))›*)) lemma sgn_sgn_nonneg [simp]: "sgn (a :: int) * sgn a ≠ -1" by (clarsimp simp: sgn_if (*‹sgn (?x::?'a::linordered_idom) = (if ?x = (0::?'a::linordered_idom) then 0::?'a::linordered_idom else if (0::?'a::linordered_idom) < ?x then 1::?'a::linordered_idom else - (1::?'a::linordered_idom))›*)) lemma inj_inj_on: "inj f ⟹ inj_on f A" by (metis injD (*‹⟦inj (?f::?'a ⇒ ?'b); ?f (?x::?'a) = ?f (?y::?'a)⟧ ⟹ ?x = ?y›*) inj_onI (*‹(⋀(x::?'a) y::?'a. ⟦x ∈ (?A::?'a set); y ∈ ?A; (?f::?'a ⇒ ?'b) x = ?f y⟧ ⟹ x = y) ⟹ inj_on ?f ?A›*)) lemma ex_eqI: "⟦⋀x. f x = g x⟧ ⟹ (∃x. f x) = (∃x. g x)" by simp lemma pre_post_ex: "⟦∃x. P x; ⋀x. P x ⟹ Q x⟧ ⟹ ∃x. Q x" by auto lemma ex_conj_increase: "((∃x. P x) ∧ Q) = (∃x. P x ∧ Q)" "(R ∧ (∃x. S x)) = (∃x. R ∧ S x)" (*goals: 1. ‹((∃x::'a. (P::'a ⇒ bool) x) ∧ (Q::bool)) = (∃x::'a. P x ∧ Q)› 2. ‹((R::bool) ∧ (∃x::'b. (S::'b ⇒ bool) x)) = (∃x::'b. R ∧ S x)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma all_conj_increase: "(( ∀x. P x) ∧ Q) = (∀x. P x ∧ Q)" "(R ∧ (∀x. S x)) = (∀x. R ∧ S x)" (*goals: 1. ‹((∀x. P x) ∧ Q) = (∀x. P x ∧ Q)› 2. ‹(R ∧ (∀x. S x)) = (∀x. R ∧ S x)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma Ball_conj_increase: "xs ≠ {} ⟹ (( ∀x ∈ xs. P x) ∧ Q) = (∀x ∈ xs. P x ∧ Q)" "xs ≠ {} ⟹ (R ∧ (∀x ∈ xs. S x)) = (∀x ∈ xs. R ∧ S x)" (*goals: 1. ‹xs ≠ {} ⟹ ((∀x∈xs. P x) ∧ Q) = (∀x∈xs. P x ∧ Q)› 2. ‹xs ≠ {} ⟹ (R ∧ (∀x∈xs. S x)) = (∀x∈xs. R ∧ S x)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . (*************** * Union rules * ***************) lemma disjoint_subset: assumes "A' ⊆ A" and "A ∩ B = {}" shows "A' ∩ B = {}" using assms (*‹A' ⊆ A› ‹(A::'a set) ∩ (B::'a set) = {}›*) by auto lemma disjoint_subset2: assumes "B' ⊆ B" and "A ∩ B = {}" shows "A ∩ B' = {}" using assms (*‹B' ⊆ B› ‹A ∩ B = {}›*) by auto lemma UN_nth_mem: "i < length xs ⟹ f (xs ! i) ⊆ (⋃x∈set xs. f x)" by (metis UN_upper (*‹(?a::?'a) ∈ (?A::?'a set) ⟹ (?B::?'a ⇒ ?'b set) ?a ⊆ ⋃ (?B ` ?A)›*) nth_mem (*‹(?n::nat) < length (?xs::?'a list) ⟹ ?xs ! ?n ∈ set ?xs›*)) lemma Union_equal: "f ` A = f ` B ⟹ (⋃x ∈ A. f x) = (⋃x ∈ B. f x)" by blast lemma UN_Diff_disjoint: "i < length xs ⟹ (A - (⋃x∈set xs. f x)) ∩ f (xs ! i) = {}" by (metis Diff_disjoint (*‹?A ∩ (?B - ?A) = {}›*) Int_commute (*‹?A ∩ ?B = ?B ∩ ?A›*) UN_nth_mem (*‹?i < length ?xs ⟹ ?f (?xs ! ?i) ⊆ ⋃ (?f ` set ?xs)›*) disjoint_subset (*‹⟦?A' ⊆ ?A; ?A ∩ ?B = {}⟧ ⟹ ?A' ∩ ?B = {}›*)) lemma image_list_update: "f a = f (xs ! i) ⟹ f ` set (xs [i := a]) = f ` set xs" by (metis list_update_id (*‹?xs[?i := ?xs ! ?i] = ?xs›*) map_update (*‹map ?f (?xs[?k := ?y]) = (map ?f ?xs)[?k := ?f ?y]›*) set_map (*‹set (map ?f ?xs) = ?f ` set ?xs›*)) lemma Union_list_update_id: "f a = f (xs ! i) ⟹ (⋃x∈set (xs [i := a]). f x) = (⋃x∈set xs. f x)" apply (rule Union_equal (*‹?f ` ?A = ?f ` ?B ⟹ ⋃ (?f ` ?A) = ⋃ (?f ` ?B)›*)) (*goal: ‹f a = f (xs ! i) ⟹ ⋃ (f ` set (xs[i := a])) = ⋃ (f ` set xs)›*) by (erule image_list_update (*‹?f ?a = ?f (?xs ! ?i) ⟹ ?f ` set (?xs[?i := ?a]) = ?f ` set ?xs›*)) lemma Union_list_update_id': "⟦i < length xs; ⋀x. g (f x) = g x⟧ ⟹ (⋃x∈set (xs [i := f (xs ! i)]). g x) = (⋃x∈set xs. g x)" by (metis Union_list_update_id (*‹?f ?a = ?f (?xs ! ?i) ⟹ ⋃ (?f ` set (?xs[?i := ?a])) = ⋃ (?f ` set ?xs)›*)) lemma Union_subset: "⟦⋀x. x ∈ A ⟹ (f x) ⊆ (g x)⟧ ⟹ (⋃x ∈ A. f x) ⊆ (⋃x ∈ A. g x)" by (metis UN_mono (*‹⟦?A ⊆ ?B; ⋀x. x ∈ ?A ⟹ ?f x ⊆ ?g x⟧ ⟹ ⋃ (?f ` ?A) ⊆ ⋃ (?g ` ?B)›*) order_refl (*‹?x ≤ ?x›*)) lemma UN_sub_empty: "⟦list_all P xs; ⋀x. P x ⟹ f x = g x⟧ ⟹ (⋃x∈set xs. f x) - (⋃x∈set xs. g x) = {}" by (simp add: Ball_set_list_all[symmetric] (*‹list_all (?P::?'a::type ⇒ bool) (?xs::?'a::type list) = Ball (set ?xs) ?P›*) Union_subset (*‹(⋀x::?'a::type. x ∈ (?A::?'a::type set) ⟹ (?f::?'a::type ⇒ ?'b::type set) x ⊆ (?g::?'a::type ⇒ ?'b::type set) x) ⟹ ⋃ (?f ` ?A) ⊆ ⋃ (?g ` ?A)›*)) (******************* * bij_betw rules. * *******************) lemma bij_betw_fun_updI: "⟦x ∉ A; y ∉ B; bij_betw f A B⟧ ⟹ bij_betw (f(x := y)) (insert x A) (insert y B)" apply (clarsimp simp: bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*) fun_upd_image (*‹?f(?x := ?y) ` ?A = (if ?x ∈ ?A then insert ?y (?f ` (?A - {?x})) else ?f ` ?A)›*) inj_on_fun_updI (*‹⟦inj_on ?f ?A; ?y ∉ ?f ` ?A⟧ ⟹ inj_on (?f(?x := ?y)) ?A›*) split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) (*goal: ‹⟦x ∉ A; y ∉ B; bij_betw f A B⟧ ⟹ bij_betw (f(x := y)) (insert x A) (insert y B)›*) by blast definition "bij_betw_map f A B ≡ bij_betw f A (Some ` B)" lemma bij_betw_map_fun_updI: "⟦x ∉ A; y ∉ B; bij_betw_map f A B⟧ ⟹ bij_betw_map (f(x ↦ y)) (insert x A) (insert y B)" unfolding bij_betw_map_def (*goal: ‹⟦x ∉ A; y ∉ B; bij_betw f A (Some ` B)⟧ ⟹ bij_betw (f(x ↦ y)) (insert x A) (Some ` insert y B)›*) apply clarsimp (*goal: ‹⟦x ∉ A; y ∉ B; bij_betw f A (Some ` B)⟧ ⟹ bij_betw (f(x ↦ y)) (insert x A) (Some ` insert y B)›*) apply (erule bij_betw_fun_updI (*‹⟦?x ∉ ?A; ?y ∉ ?B; bij_betw ?f ?A ?B⟧ ⟹ bij_betw (?f(?x := ?y)) (insert ?x ?A) (insert ?y ?B)›*)) (*goals: 1. ‹⟦y ∉ B; bij_betw f A (Some ` B)⟧ ⟹ Some y ∉ Some ` B› 2. ‹⟦y ∉ B; bij_betw f A (Some ` B)⟧ ⟹ bij_betw f A (Some ` B)› discuss goal 1*) apply clarsimp (*discuss goal 2*) apply clarsimp (*proven 2 subgoals*) . lemma bij_betw_map_imp_inj_on: "bij_betw_map f A B ⟹ inj_on f A" by (simp add: bij_betw_map_def (*‹bij_betw_map ?f ?A ?B ≡ bij_betw ?f ?A (Some ` ?B)›*) bij_betw_imp_inj_on (*‹bij_betw ?f ?A ?B ⟹ inj_on ?f ?A›*)) lemma bij_betw_empty_dom_exists: "r = {} ⟹ ∃t. bij_betw t {} r" by (clarsimp simp: bij_betw_def (*‹bij_betw (?f::?'a ⇒ ?'b) (?A::?'a set) (?B::?'b set) = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*)) lemma bij_betw_map_empty_dom_exists: "r = {} ⟹ ∃t. bij_betw_map t {} r" by (clarsimp simp: bij_betw_map_def (*‹bij_betw_map ?f ?A ?B ≡ bij_betw ?f ?A (Some ` ?B)›*) bij_betw_empty_dom_exists (*‹?r = {} ⟹ ∃t. bij_betw t {} ?r›*)) (* * Function and Relation Powers. *) lemma funpow_add [simp]: fixes f :: "'a ⇒ 'a" shows "(f ^^ a) ((f ^^ b) s) = (f ^^ (a + b)) s" by (metis comp_apply (*‹(?f ∘ ?g) ?x = ?f (?g ?x)›*) funpow_add (*‹?f ^^ (?m + ?n) = ?f ^^ ?m ∘ ?f ^^ ?n›*)) lemma funpow_unfold: fixes f :: "'a ⇒ 'a" assumes "n > 0" shows "f ^^ n = (f ^^ (n - 1)) ∘ f" by (metis Suc_diff_1 (*‹0 < ?n ⟹ Suc (?n - 1) = ?n›*) assms (*‹0 < n›*) funpow_Suc_right (*‹?f ^^ Suc ?n = ?f ^^ ?n ∘ ?f›*)) lemma relpow_unfold: "n > 0 ⟹ S ^^ n = (S ^^ (n - 1)) O S" apply (cases n) (*goals: 1. ‹⟦(0::nat) < (n::nat); n = (0::nat)⟧ ⟹ (S::('a × 'a) set) ^^ n = S ^^ (n - (1::nat)) O S› 2. ‹⋀nat::nat. ⟦(0::nat) < (n::nat); n = Suc nat⟧ ⟹ (S::('a × 'a) set) ^^ n = S ^^ (n - (1::nat)) O S› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . (* * Equivalence relations. *) (* Convert a projection into an equivalence relation. *) definition equiv_of :: "('s ⇒ 't) ⇒ ('s × 's) set" where "equiv_of proj ≡ {(a, b). proj a = proj b}" lemma equiv_of_is_equiv_relation [simp]: "equiv UNIV (equiv_of proj)" by (auto simp: equiv_of_def (*‹equiv_of ?proj ≡ {(a, b). ?proj a = ?proj b}›*) intro!: equivI (*‹⟦refl_on ?A ?r; sym ?r; trans ?r⟧ ⟹ equiv ?A ?r›*) refl_onI (*‹⟦?r ⊆ ?A × ?A; ⋀x. x ∈ ?A ⟹ (x, x) ∈ ?r⟧ ⟹ refl_on ?A ?r›*) symI (*‹(⋀x y. (x, y) ∈ ?r ⟹ (y, x) ∈ ?r) ⟹ sym ?r›*) transI (*‹(⋀x y z. ⟦(x, y) ∈ ?r; (y, z) ∈ ?r⟧ ⟹ (x, z) ∈ ?r) ⟹ trans ?r›*)) lemma in_equiv_of [simp]: "((a, b) ∈ equiv_of f) ⟷ (f a = f b)" by (clarsimp simp: equiv_of_def (*‹equiv_of (?proj::?'s ⇒ ?'t) ≡ {(a::?'s, b::?'s). ?proj a = ?proj b}›*)) (* For every equivalence relation R, there exists a projection function * "f" such that "f x = f y ⟷ (x, y) ∈ R". That is, you can reason * about projections instead of equivalence relations if you so wish. *) lemma equiv_relation_to_projection: fixes R :: "('a × 'a) set" assumes equiv: "equiv UNIV R" shows "∃f :: 'a ⇒ 'a set. ∀x y. f x = f y ⟷ (x, y) ∈ R" apply (rule exI [of _ "λx. {y. (x, y) ∈ R}"] (*‹?P (λx. {y. (x, y) ∈ R}) ⟹ ∃x. ?P x›*)) (*goal: ‹∃f. ∀x y. (f x = f y) = ((x, y) ∈ R)›*) apply clarsimp (*goal: ‹∀x y. ({y. (x, y) ∈ R} = {ya. (y, ya) ∈ R}) = ((x, y) ∈ R)›*) subgoal for x and y apply (cases "(x, y) ∈ R") (*goals: 1. ‹(x::'a::type, y::'a::type) ∈ (R::('a::type × 'a::type) set) ⟹ ({y::'a::type. (x, y) ∈ R} = {ya::'a::type. (y, ya) ∈ R}) = ((x, y) ∈ R)› 2. ‹(x::'a::type, y::'a::type) ∉ (R::('a::type × 'a::type) set) ⟹ ({y::'a::type. (x, y) ∈ R} = {ya::'a::type. (y, ya) ∈ R}) = ((x, y) ∈ R)› discuss goal 1*) apply clarsimp (*top goal: ‹(x, y) ∈ R ⟹ ({y. (x, y) ∈ R} = {ya. (y, ya) ∈ R}) = ((x, y) ∈ R)› and 1 goal remains*) apply (rule set_eqI (*‹(⋀x. (x ∈ ?A) = (x ∈ ?B)) ⟹ ?A = ?B›*)) (*top goal: ‹(x::'a, y::'a) ∈ (R::('a × 'a) set) ⟹ {y::'a. (x, y) ∈ R} = {ya::'a. (y, ya) ∈ R}› and 1 goal remains*) apply clarsimp (*top goal: ‹⋀xa. (x, y) ∈ R ⟹ (xa ∈ {y. (x, y) ∈ R}) = (xa ∈ {ya. (y, ya) ∈ R})› and 1 goal remains*) apply (metis equivE (*‹⟦equiv ?A ?r; ⟦refl_on ?A ?r; sym ?r; trans ?r⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) sym_def (*‹sym ?r = (∀x y. (x, y) ∈ ?r ⟶ (y, x) ∈ ?r)›*) trans_def (*‹trans ?r = (∀x y z. (x, y) ∈ ?r ⟶ (y, z) ∈ ?r ⟶ (x, z) ∈ ?r)›*) equiv (*‹equiv UNIV R›*)) (*discuss goal 2*) apply clarsimp (*goal: ‹(x, y) ∉ R ⟹ ({y. (x, y) ∈ R} = {ya. (y, ya) ∈ R}) = ((x, y) ∈ R)›*) apply (metis UNIV_I (*‹?x ∈ UNIV›*) equiv (*‹equiv UNIV R›*) equivE (*‹⟦equiv ?A ?r; ⟦refl_on ?A ?r; sym ?r; trans ?r⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*) refl_on_def (*‹refl_on ?A ?r = (?r ⊆ ?A × ?A ∧ (∀x∈?A. (x, x) ∈ ?r))›*)) (*proven 2 subgoals*) . . lemma range_constant [simp]: "range (λ_. k) = {k}" by (clarsimp simp: image_def (*‹?f ` ?A = {y. ∃x∈?A. y = ?f x}›*)) lemma dom_unpack: "dom (map_of (map (λx. (f x, g x)) xs)) = set (map (λx. f x) xs)" by (simp add: dom_map_of_conv_image_fst (*‹dom (map_of ?xys) = fst ` set ?xys›*) image_image (*‹?f ` ?g ` ?A = (λx. ?f (?g x)) ` ?A›*)) lemma fold_to_disj: "fold (++) ms a x = Some y ⟹ (∃b ∈ set ms. b x = Some y) ∨ a x = Some y" apply (induct ms arbitrary:a x y) (*goals: 1. ‹⋀(a::'b ⇒ 'a option) (x::'b) y::'a. fold (++) [] a x = Some y ⟹ (∃b::'b ⇒ 'a option∈set []. b x = Some y) ∨ a x = Some y› 2. ‹⋀(a::'b ⇒ 'a option) (ms::('b ⇒ 'a option) list) (aa::'b ⇒ 'a option) (x::'b) y::'a. ⟦⋀(a::'b ⇒ 'a option) (x::'b) y::'a. fold (++) ms a x = Some y ⟹ (∃b::'b ⇒ 'a option∈set ms. b x = Some y) ∨ a x = Some y; fold (++) (a # ms) aa x = Some y⟧ ⟹ (∃b::'b ⇒ 'a option∈set (a # ms). b x = Some y) ∨ aa x = Some y› discuss goal 1*) apply clarsimp (*discuss goal 2*) apply clarsimp (*goal: ‹⋀a ms aa x y. ⟦⋀a x y. fold (++) ms a x = Some y ⟹ (∃b∈set ms. b x = Some y) ∨ a x = Some y; fold (++) (a # ms) aa x = Some y⟧ ⟹ (∃b∈set (a # ms). b x = Some y) ∨ aa x = Some y›*) apply blast (*proven 2 subgoals*) . lemma fold_ignore1: "a x = Some y ⟹ fold (++) ms a x = Some y" apply (induct ms arbitrary:a x y) (*goals: 1. ‹⋀a x y. a x = Some y ⟹ fold (++) [] a x = Some y› 2. ‹⋀a ms aa x y. ⟦⋀a x y. a x = Some y ⟹ fold (++) ms a x = Some y; aa x = Some y⟧ ⟹ fold (++) (a # ms) aa x = Some y› discuss goal 1*) apply clarsimp (*discuss goal 2*) apply clarsimp (*proven 2 subgoals*) . lemma fold_ignore2: "fold (++) ms a x = None ⟹ a x = None" by (metis fold_ignore1 (*‹?a ?x = Some ?y ⟹ fold (++) ?ms ?a ?x = Some ?y›*) option.collapse (*‹?option ≠ None ⟹ Some (the ?option) = ?option›*)) lemma fold_ignore3: "fold (++) ms a x = None ⟹ (∀b ∈ set ms. b x = None)" apply (induct ms arbitrary:a x) (*goals: 1. ‹⋀a x. fold (++) [] a x = None ⟹ ∀b∈set []. b x = None› 2. ‹⋀a ms aa x. ⟦⋀a x. fold (++) ms a x = None ⟹ ∀b∈set ms. b x = None; fold (++) (a # ms) aa x = None⟧ ⟹ ∀b∈set (a # ms). b x = None› discuss goal 1*) apply clarsimp (*discuss goal 2*) apply clarsimp (*goal: ‹⋀(a::'b ⇒ 'a option) (ms::('b ⇒ 'a option) list) (aa::'b ⇒ 'a option) x::'b. ⟦⋀(a::'b ⇒ 'a option) x::'b. fold (++) ms a x = None ⟹ ∀b::'b ⇒ 'a option∈set ms. b x = None; fold (++) (a # ms) aa x = None⟧ ⟹ ∀b::'b ⇒ 'a option∈set (a # ms). b x = None›*) apply (meson fold_ignore2 (*‹fold (++) ?ms ?a ?x = None ⟹ ?a ?x = None›*) map_add_None (*‹((?m ++ ?n) ?k = None) = (?n ?k = None ∧ ?m ?k = None)›*)) (*proven 2 subgoals*) . lemma fold_ignore4: "b ∈ set ms ⟹ b x = Some y ⟹ ∃y. fold (++) ms a x = Some y" using fold_ignore3 (*‹fold (++) ?ms ?a ?x = None ⟹ ∀b∈set ?ms. b ?x = None›*) by fastforce lemma dom_unpack2: "dom (fold (++) ms Map.empty) = ⋃(set (map dom ms))" apply (induct ms; clarsimp simp:dom_def (*‹dom ?m = {a. ?m a ≠ None}›*)) (*goal: ‹dom (fold (++) ms (λx. None)) = ⋃ (set (map dom ms))›*) apply (rule equalityI (*‹⟦?A ⊆ ?B; ?B ⊆ ?A⟧ ⟹ ?A = ?B›*); clarsimp) (*goal: ‹⋀a ms. {a. ∃y. fold (++) ms (λx. None) a = Some y} = (⋃a∈set ms. {aa. ∃y. a aa = Some y}) ⟹ {aa. ∃y. fold (++) ms a aa = Some y} = {aa. ∃y. a aa = Some y} ∪ (⋃a∈set ms. {aa. ∃y. a aa = Some y})›*) apply (drule fold_to_disj (*‹fold (++) (?ms::(?'b ⇒ ?'a option) list) (?a::?'b ⇒ ?'a option) (?x::?'b) = Some (?y::?'a) ⟹ (∃b::?'b ⇒ ?'a option∈set ?ms. b ?x = Some ?y) ∨ ?a ?x = Some ?y›*)) (*top goal: ‹⋀a ms x y. ⟦{a. ∃y. fold (++) ms (λx. None) a = Some y} = (⋃a∈set ms. {aa. ∃y. a aa = Some y}); ∀xa∈set ms. xa x = None; fold (++) ms a x = Some y⟧ ⟹ ∃y. a x = Some y› and 1 goal remains*) apply (erule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀a ms x y. ⟦{a. ∃y. fold (++) ms (λx. None) a = Some y} = (⋃a∈set ms. {aa. ∃y. a aa = Some y}); ∀xa∈set ms. xa x = None; (∃b∈set ms. b x = Some y) ∨ a x = Some y⟧ ⟹ ∃y. a x = Some y› and 1 goal remains*) apply clarsimp (*top goal: ‹⋀a ms x y. ⟦{a. ∃y. fold (++) ms (λx. None) a = Some y} = (⋃a∈set ms. {aa. ∃y. a aa = Some y}); ∀xa∈set ms. xa x = None; ∃b∈set ms. b x = Some y⟧ ⟹ ∃y. a x = Some y› and 2 goals remain*) apply (rename_tac b) (*top goal: ‹⋀a ms x y b. ⟦{a. ∃y. fold (++) ms (λx. None) a = Some y} = (⋃a∈set ms. {aa. ∃y. a aa = Some y}); ∀xa∈set ms. xa x = None; b ∈ set ms; b x = Some y⟧ ⟹ ∃y. a x = Some y› and 2 goals remain*) apply (erule_tac x=b in ballE (*‹⟦∀x∈?A. ?P x; ?P ?x ⟹ ?Q; ?x ∉ ?A ⟹ ?Q⟧ ⟹ ?Q›*); clarsimp) (*top goal: ‹⋀a ms x y b. ⟦{a. ∃y. fold (++) ms (λx. None) a = Some y} = (⋃a∈set ms. {aa. ∃y. a aa = Some y}); ∀xa∈set ms. xa x = None; b ∈ set ms; b x = Some y⟧ ⟹ ∃y. a x = Some y› and 2 goals remain*) apply clarsimp (*top goal: ‹⋀a ms x y. ⟦{a. ∃y. fold (++) ms (λx. None) a = Some y} = (⋃a∈set ms. {aa. ∃y. a aa = Some y}); ∀xa∈set ms. xa x = None; a x = Some y⟧ ⟹ ∃y. a x = Some y› and 1 goal remains*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goal: ‹⋀a ms. {a. ∃y. fold (++) ms (λx. None) a = Some y} = (⋃a∈set ms. {aa. ∃y. a aa = Some y}) ⟹ {aa. ∃y. a aa = Some y} ⊆ {aa. ∃y. fold (++) ms a aa = Some y} ∧ (⋃a∈set ms. {aa. ∃y. a aa = Some y}) ⊆ {aa. ∃y. fold (++) ms a aa = Some y}›*) apply clarsimp (*top goal: ‹⋀a ms. {a. ∃y. fold (++) ms (λx. None) a = Some y} = (⋃a∈set ms. {aa. ∃y. a aa = Some y}) ⟹ {aa. ∃y. a aa = Some y} ⊆ {aa. ∃y. fold (++) ms a aa = Some y}› and 1 goal remains*) subgoal for _ and _ and _ and y apply (rule exI[where x = y] (*‹(?P::'b ⇒ bool) (y::'b) ⟹ ∃x::'b. ?P x›*)) (*goal: ‹⟦{a::'a. ∃y::'b. fold (++) (ms_::('a ⇒ 'b option) list) (λx::'a. None) a = Some y} = (⋃a::'a ⇒ 'b option∈set ms_. {aa::'a. ∃y::'b. a aa = Some y}); (a_::'a ⇒ 'b option) (x_::'a) = Some (y::'b)⟧ ⟹ ∃y::'b. fold (++) ms_ a_ x_ = Some y›*) by (erule fold_ignore1 (*‹?a ?x = Some ?y ⟹ fold (++) ?ms ?a ?x = Some ?y›*)) apply clarsimp (*goal: ‹⋀(a::'a ⇒ 'b option) ms::('a ⇒ 'b option) list. {a::'a. ∃y::'b. fold (++) ms (λx::'a. None) a = Some y} = (⋃a::'a ⇒ 'b option∈set ms. {aa::'a. ∃y::'b. a aa = Some y}) ⟹ (⋃a::'a ⇒ 'b option∈set ms. {aa::'a. ∃y::'b. a aa = Some y}) ⊆ {aa::'a. ∃y::'b. fold (++) ms a aa = Some y}›*) apply (rename_tac y) (*goal: ‹⋀a ms x xa y. ⟦{a. ∃y. fold (++) ms (λx. None) a = Some y} = (⋃a∈set ms. {aa. ∃y. a aa = Some y}); xa ∈ set ms; xa x = Some y⟧ ⟹ ∃y. fold (++) ms a x = Some y›*) apply (erule_tac y=y in fold_ignore4 (*‹⟦(?b::?'a ⇒ ?'b option) ∈ set (?ms::(?'a ⇒ ?'b option) list); ?b (?x::?'a) = Some (?y::?'b)⟧ ⟹ ∃y::?'b. fold (++) ?ms (?a::?'a ⇒ ?'b option) ?x = Some y›*)) (*goal: ‹⋀a ms x xa y. ⟦{a. ∃y. fold (++) ms (λx. None) a = Some y} = (⋃a∈set ms. {aa. ∃y. a aa = Some y}); xa ∈ set ms; xa x = Some y⟧ ⟹ ∃y. fold (++) ms a x = Some y›*) by clarsimp lemma fold_ignore5:"fold (++) ms a x = Some y ⟹ a x = Some y ∨ (∃b ∈ set ms. b x = Some y)" apply (induct ms arbitrary:a x y) (*goals: 1. ‹⋀a x y. fold (++) [] a x = Some y ⟹ a x = Some y ∨ (∃b∈set []. b x = Some y)› 2. ‹⋀a ms aa x y. ⟦⋀a x y. fold (++) ms a x = Some y ⟹ a x = Some y ∨ (∃b∈set ms. b x = Some y); fold (++) (a # ms) aa x = Some y⟧ ⟹ aa x = Some y ∨ (∃b∈set (a # ms). b x = Some y)› discuss goal 1*) apply clarsimp (*discuss goal 2*) apply clarsimp (*goal: ‹⋀a ms aa x y. ⟦⋀a x y. fold (++) ms a x = Some y ⟹ a x = Some y ∨ (∃b∈set ms. b x = Some y); fold (++) (a # ms) aa x = Some y⟧ ⟹ aa x = Some y ∨ (∃b∈set (a # ms). b x = Some y)›*) apply blast (*proven 2 subgoals*) . lemma dom_inter_nothing:"dom f ∩ dom g = {} ⟹ ∀x. f x = None ∨ g x = None" by auto lemma fold_ignore6: "f x = None ⟹ fold (++) ms f x = fold (++) ms Map.empty x" apply (induct ms arbitrary:f x) (*goals: 1. ‹⋀f x. f x = None ⟹ fold (++) [] f x = fold (++) [] (λx. None) x› 2. ‹⋀a ms f x. ⟦⋀f x. f x = None ⟹ fold (++) ms f x = fold (++) ms (λx. None) x; f x = None⟧ ⟹ fold (++) (a # ms) f x = fold (++) (a # ms) (λx. None) x› discuss goal 1*) apply (clarsimp simp:map_add_def (*‹?m1.0 ++ ?m2.0 = (λx. case ?m2.0 x of None ⇒ ?m1.0 x | Some y ⇒ Some y)›*)) (*discuss goal 2*) apply (clarsimp simp:map_add_def (*‹?m1.0 ++ ?m2.0 = (λx. case ?m2.0 x of None ⇒ ?m1.0 x | Some y ⇒ Some y)›*)) (*goal: ‹⋀a ms f x. ⟦⋀f x. f x = None ⟹ fold (++) ms f x = fold (++) ms (λx. None) x; f x = None⟧ ⟹ fold (++) (a # ms) f x = fold (++) (a # ms) (λx. None) x›*) apply (metis (no_types, lifting) fold_ignore1 (*‹?a ?x = Some ?y ⟹ fold (++) ?ms ?a ?x = Some ?y›*) option.collapse (*‹?option ≠ None ⟹ Some (the ?option) = ?option›*) option.simps( (*‹(case None of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ?f1.0›*) 4)) (*proven 2 subgoals*) . lemma fold_ignore7: "m x = m' x ⟹ fold (++) ms m x = fold (++) ms m' x" apply (cases "m x") (*goals: 1. ‹⟦(m::'b ⇒ 'a option) (x::'b) = (m'::'b ⇒ 'a option) x; m x = None⟧ ⟹ fold (++) (ms::('b ⇒ 'a option) list) m x = fold (++) ms m' x› 2. ‹⋀a::'a. ⟦(m::'b ⇒ 'a option) (x::'b) = (m'::'b ⇒ 'a option) x; m x = Some a⟧ ⟹ fold (++) (ms::('b ⇒ 'a option) list) m x = fold (++) ms m' x› discuss goal 1*) apply (frule_tac ms=ms in fold_ignore6 (*‹?f ?x = None ⟹ fold (++) ?ms ?f ?x = fold (++) ?ms (λx. None) ?x›*)) (*top goal: ‹⟦m x = m' x; m x = None⟧ ⟹ fold (++) ms m x = fold (++) ms m' x› and 1 goal remains*) apply (cut_tac f=m' and ms=ms and x=x in fold_ignore6 (*‹?f ?x = None ⟹ fold (++) ?ms ?f ?x = fold (++) ?ms (λx. None) ?x›*)) (*goals: 1. ‹⟦m x = m' x; m x = None; fold (++) ms m x = fold (++) ms (λx. None) x⟧ ⟹ m' x = None› 2. ‹⟦m x = m' x; m x = None; fold (++) ms m x = fold (++) ms (λx. None) x; fold (++) ms m' x = fold (++) ms (λx. None) x⟧ ⟹ fold (++) ms m x = fold (++) ms m' x› discuss goal 1*) apply clarsimp (*discuss goal 2*) apply clarsimp (*proven 2 subgoals*) (*discuss goal 2*) apply clarsimp (*goal: ‹⋀a. ⟦m x = m' x; m x = Some a⟧ ⟹ fold (++) ms m x = fold (++) ms m' x›*) apply (rename_tac a) (*goal: ‹⋀a. ⟦Some a = m' x; m x = m' x⟧ ⟹ fold (++) ms m x = fold (++) ms m' x›*) apply (cut_tac ms=ms and a=m and x=x and y=a in fold_ignore1 (*‹?a ?x = Some ?y ⟹ fold (++) ?ms ?a ?x = Some ?y›*)) (*goals: 1. ‹⋀a. ⟦Some a = m' x; m x = m' x⟧ ⟹ m x = Some a› 2. ‹⋀a. ⟦Some a = m' x; m x = m' x; fold (++) ms m x = Some a⟧ ⟹ fold (++) ms m x = fold (++) ms m' x› discuss goal 1*) apply clarsimp (*discuss goal 2*) apply (cut_tac ms=ms and a=m' and x=x and y=a in fold_ignore1 (*‹?a ?x = Some ?y ⟹ fold (++) ?ms ?a ?x = Some ?y›*)) (*goals: 1. ‹⋀a. ⟦Some a = m' x; m x = m' x; fold (++) ms m x = Some a⟧ ⟹ m' x = Some a› 2. ‹⋀a. ⟦Some a = m' x; m x = m' x; fold (++) ms m x = Some a; fold (++) ms m' x = Some a⟧ ⟹ fold (++) ms m x = fold (++) ms m' x› discuss goal 1*) apply clarsimp (*discuss goal 2*) apply clarsimp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma fold_ignore8: "fold (++) ms [x ↦ y] = (fold (++) ms Map.empty)(x ↦ y)" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹fold (++) (ms::('a ⇒ 'b option) list) [x::'a ↦ y::'b] = (fold (++) ms (λx::'a. None))(x ↦ y)›*) subgoal for xa apply (cases "xa = x") (*goals: 1. ‹xa = x ⟹ fold (++) ms [x ↦ y] xa = ((fold (++) ms (λx. None))(x ↦ y)) xa› 2. ‹xa ≠ x ⟹ fold (++) ms [x ↦ y] xa = ((fold (++) ms (λx. None))(x ↦ y)) xa› discuss goal 1*) apply clarsimp (*top goal: ‹xa = x ⟹ fold (++) ms [x ↦ y] xa = ((fold (++) ms (λx. None))(x ↦ y)) xa› and 1 goal remains*) apply (rule fold_ignore1 (*‹?a ?x = Some ?y ⟹ fold (++) ?ms ?a ?x = Some ?y›*)) (*top goal: ‹xa = x ⟹ fold (++) ms [x ↦ y] x = Some y› and 1 goal remains*) apply clarsimp (*discuss goal 2*) apply (subst fold_ignore6 (*‹?f ?x = None ⟹ fold (++) ?ms ?f ?x = fold (++) ?ms (λx. None) ?x›*)) (*goals: 1. ‹xa ≠ x ⟹ [x ↦ y] xa = None› 2. ‹xa ≠ x ⟹ fold (++) ms (λx. None) xa = ((fold (++) ms (λx. None))(x ↦ y)) xa› discuss goal 1*) apply clarsimp (*discuss goal 2*) apply clarsimp (*proven 2 subgoals*) (*proven 2 subgoals*) . . lemma fold_ignore9: "⟦fold (++) ms [x ↦ y] x' = Some z; x = x'⟧ ⟹ y = z" apply (subst (asm) fold_ignore8 (*‹fold (++) (?ms::(?'a ⇒ ?'b option) list) [?x::?'a ↦ ?y::?'b] = (fold (++) ?ms (λx::?'a. None))(?x ↦ ?y)›*)) (*goal: ‹⟦fold (++) ms [x ↦ y] x' = Some z; x = x'⟧ ⟹ y = z›*) by clarsimp lemma fold_to_map_of: "fold (++) (map (λx. [f x ↦ g x]) xs) Map.empty = map_of (map (λx. (f x, g x)) xs)" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹fold (++) (map (λx. [f x ↦ g x]) xs) (λx. None) = map_of (map (λx. (f x, g x)) xs)›*) subgoal for x apply (cases "fold (++) (map (λx. [f x ↦ g x]) xs) Map.empty x") (*goals: 1. ‹fold (++) (map (λx. [f x ↦ g x]) xs) (λx. None) x = None ⟹ fold (++) (map (λx. [f x ↦ g x]) xs) (λx. None) x = map_of (map (λx. (f x, g x)) xs) x› 2. ‹⋀a. fold (++) (map (λx. [f x ↦ g x]) xs) (λx. None) x = Some a ⟹ fold (++) (map (λx. [f x ↦ g x]) xs) (λx. None) x = map_of (map (λx. (f x, g x)) xs) x› discuss goal 1*) apply clarsimp (*top goal: ‹fold (++) (map (λx. [f x ↦ g x]) xs) (λx. None) x = None ⟹ fold (++) (map (λx. [f x ↦ g x]) xs) (λx. None) x = map_of (map (λx. (f x, g x)) xs) x› and 1 goal remains*) apply (drule fold_ignore3 (*‹fold (++) ?ms ?a ?x = None ⟹ ∀b∈set ?ms. b ?x = None›*)) (*top goal: ‹fold (++) (map (λx. [f x ↦ g x]) xs) (λx. None) x = None ⟹ None = map_of (map (λx. (f x, g x)) xs) x› and 1 goal remains*) apply (clarsimp split:if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) (*top goal: ‹∀b::'a::type ⇒ 'b::type option∈set (map (λx::'c::type. [(f::'c::type ⇒ 'a::type) x ↦ (g::'c::type ⇒ 'b::type) x]) (xs::'c::type list)). b (x::'a::type) = None ⟹ None = map_of (map (λx::'c::type. (f x, g x)) xs) x› and 1 goal remains*) apply (rule sym (*‹?s = ?t ⟹ ?t = ?s›*)) (*top goal: ‹∀b∈set xs. x ≠ f b ⟹ None = map_of (map (λx. (f x, g x)) xs) x› and 1 goal remains*) apply (subst map_of_eq_None_iff (*‹(map_of ?xys ?x = None) = (?x ∉ fst ` set ?xys)›*)) (*top goal: ‹∀b∈set xs. x ≠ f b ⟹ map_of (map (λx. (f x, g x)) xs) x = None› and 1 goal remains*) apply clarsimp (*top goal: ‹∀b∈set xs. x ≠ f b ⟹ x ∉ fst ` set (map (λx. (f x, g x)) xs)› and 1 goal remains*) apply (rename_tac xa) (*top goal: ‹⋀xa. ⟦∀b∈set xs. f xa ≠ f b; x = f xa; xa ∈ set xs⟧ ⟹ False› and 1 goal remains*) apply (erule_tac x=xa in ballE (*‹⟦∀x∈?A. ?P x; ?P ?x ⟹ ?Q; ?x ∉ ?A ⟹ ?Q⟧ ⟹ ?Q›*)) (*goals: 1. ‹⋀xa. ⟦x = f xa; xa ∈ set xs; f xa ≠ f xa⟧ ⟹ False› 2. ‹⋀xa. ⟦x = f xa; xa ∈ set xs; xa ∉ set xs⟧ ⟹ False› discuss goal 1*) apply clarsimp (*discuss goal 2*) apply clarsimp (*proven 2 subgoals*) (*discuss goal 2*) apply clarsimp (*goal: ‹⋀a::'b. fold (++) (map (λx::'c. [(f::'c ⇒ 'a) x ↦ (g::'c ⇒ 'b) x]) (xs::'c list)) (λx::'a. None) (x::'a) = Some a ⟹ fold (++) (map (λx::'c. [f x ↦ g x]) xs) (λx::'a. None) x = map_of (map (λx::'c. (f x, g x)) xs) x›*) apply (frule fold_ignore5 (*‹fold (++) ?ms ?a ?x = Some ?y ⟹ ?a ?x = Some ?y ∨ (∃b∈set ?ms. b ?x = Some ?y)›*)) (*goal: ‹⋀a. fold (++) (map (λx. [f x ↦ g x]) xs) (λx. None) x = Some a ⟹ Some a = map_of (map (λx. (f x, g x)) xs) x›*) apply (clarsimp split:if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) (*goal: ‹⋀a. ⟦fold (++) (map (λx. [f x ↦ g x]) xs) (λx. None) x = Some a; None = Some a ∨ (∃b∈set (map (λx. [f x ↦ g x]) xs). b x = Some a)⟧ ⟹ Some a = map_of (map (λx. (f x, g x)) xs) x›*) apply (subst map_add_map_of_foldr[where m=Map.empty, simplified] (*‹map_of ?ps = foldr (λ(k, v) m. m(k ↦ v)) ?ps (λx. None)›*)) (*goal: ‹⋀b. ⟦fold (++) (map (λx. [f x ↦ g x]) xs) (λx. None) (f b) = Some (g b); b ∈ set xs; x = f b⟧ ⟹ Some (g b) = map_of (map (λx. (f x, g x)) xs) (f b)›*) apply (induct xs arbitrary:f g) (*goals: 1. ‹⋀b f g. ⟦fold (++) (map (λx. [f x ↦ g x]) []) (λx. None) (f b) = Some (g b); b ∈ set []; x = f b⟧ ⟹ Some (g b) = foldr (λ(k, v) m. m(k ↦ v)) (map (λx. (f x, g x)) []) (λx. None) (f b)› 2. ‹⋀a xs b f g. ⟦⋀b f g. ⟦fold (++) (map (λx. [f x ↦ g x]) xs) (λx. None) (f b) = Some (g b); b ∈ set xs; x = f b⟧ ⟹ Some (g b) = foldr (λ(k, v) m. m(k ↦ v)) (map (λx. (f x, g x)) xs) (λx. None) (f b); fold (++) (map (λx. [f x ↦ g x]) (a # xs)) (λx. None) (f b) = Some (g b); b ∈ set (a # xs); x = f b⟧ ⟹ Some (g b) = foldr (λ(k, v) m. m(k ↦ v)) (map (λx. (f x, g x)) (a # xs)) (λx. None) (f b)› discuss goal 1*) apply (clarsimp split:if_split (*‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))›*)) (*discuss goal 2*) apply (clarsimp split:if_split (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))›*)) (*goal: ‹⋀a xs b f g. ⟦⋀b f g. ⟦fold (++) (map (λx. [f x ↦ g x]) xs) (λx. None) (f b) = Some (g b); b ∈ set xs; x = f b⟧ ⟹ Some (g b) = foldr (λ(k, v) m. m(k ↦ v)) (map (λx. (f x, g x)) xs) (λx. None) (f b); fold (++) (map (λx. [f x ↦ g x]) (a # xs)) (λx. None) (f b) = Some (g b); b ∈ set (a # xs); x = f b⟧ ⟹ Some (g b) = foldr (λ(k, v) m. m(k ↦ v)) (map (λx. (f x, g x)) (a # xs)) (λx. None) (f b)›*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹⋀a xs b f g. ⟦⋀ba fa g. ⟦fold (++) (map (λx. [fa x ↦ g x]) xs) (λx. None) (fa ba) = Some (g ba); ba ∈ set xs; f b = fa ba⟧ ⟹ Some (g ba) = foldr (λ(k, v) m. m(k ↦ v)) (map (λx. (fa x, g x)) xs) (λx. None) (fa ba); fold (++) (map (λx. [f x ↦ g x]) xs) [f a ↦ g a] (f b) = Some (g b); b = a ∨ b ∈ set xs; x = f b⟧ ⟹ f b = f a ⟶ g b = g a› 2. ‹⋀a xs b f g. ⟦⋀ba fa g. ⟦fold (++) (map (λx. [fa x ↦ g x]) xs) (λx. None) (fa ba) = Some (g ba); ba ∈ set xs; f b = fa ba⟧ ⟹ Some (g ba) = foldr (λ(k, v) m. m(k ↦ v)) (map (λx. (fa x, g x)) xs) (λx. None) (fa ba); fold (++) (map (λx. [f x ↦ g x]) xs) [f a ↦ g a] (f b) = Some (g b); b = a ∨ b ∈ set xs; x = f b⟧ ⟹ f b ≠ f a ⟶ Some (g b) = foldr (λ(k, v) m. m(k ↦ v)) (map (λx. (f x, g x)) xs) (λx. None) (f b)› discuss goal 1*) apply clarsimp (*top goal: ‹⋀a xs b f g. ⟦⋀ba fa g. ⟦fold (++) (map (λx. [fa x ↦ g x]) xs) (λx. None) (fa ba) = Some (g ba); ba ∈ set xs; f b = fa ba⟧ ⟹ Some (g ba) = foldr (λ(k, v) m. m(k ↦ v)) (map (λx. (fa x, g x)) xs) (λx. None) (fa ba); fold (++) (map (λx. [f x ↦ g x]) xs) [f a ↦ g a] (f b) = Some (g b); b = a ∨ b ∈ set xs; x = f b⟧ ⟹ f b = f a ⟶ g b = g a› and 1 goal remains*) apply (drule fold_ignore9 (*‹⟦fold (++) (?ms::(?'b ⇒ ?'a option) list) [?x::?'b ↦ ?y::?'a] (?x'::?'b) = Some (?z::?'a); ?x = ?x'⟧ ⟹ ?y = ?z›*)) (*goals: 1. ‹⋀a xs b f g. ⟦⋀b fa g. ⟦fold (++) (map (λx. [fa x ↦ g x]) xs) (λx. None) (fa b) = Some (g b); b ∈ set xs; f a = fa b⟧ ⟹ Some (g b) = foldr (λ(k, v) m. m(k ↦ v)) (map (λx. (fa x, g x)) xs) (λx. None) (fa b); b = a ∨ b ∈ set xs; x = f a; f b = f a⟧ ⟹ f a = f a› 2. ‹⋀a xs b f g. ⟦⋀b fa g. ⟦fold (++) (map (λx. [fa x ↦ g x]) xs) (λx. None) (fa b) = Some (g b); b ∈ set xs; f a = fa b⟧ ⟹ Some (g b) = foldr (λ(k, v) m. m(k ↦ v)) (map (λx. (fa x, g x)) xs) (λx. None) (fa b); b = a ∨ b ∈ set xs; x = f a; f b = f a; g a = g b⟧ ⟹ g b = g a› discuss goal 1*) apply clarsimp (*discuss goal 2*) apply clarsimp (*proven 2 subgoals*) (*discuss goal 2*) apply clarsimp (*goal: ‹⋀(a::'c) (xs::'c list) (b::'c) (f::'c ⇒ 'a) g::'c ⇒ 'b. ⟦⋀(ba::'c) (fa::'c ⇒ 'a) g::'c ⇒ 'b. ⟦fold (++) (map (λx::'c. [fa x ↦ g x]) xs) (λx::'a. None) (fa ba) = Some (g ba); ba ∈ set xs; f b = fa ba⟧ ⟹ Some (g ba) = foldr (λ(k::'a, v::'b) m::'a ⇒ 'b option. m(k ↦ v)) (map (λx::'c. (fa x, g x)) xs) (λx::'a. None) (fa ba); fold (++) (map (λx::'c. [f x ↦ g x]) xs) [f a ↦ g a] (f b) = Some (g b); b = a ∨ b ∈ set xs; (x::'a) = f b⟧ ⟹ f b ≠ f a ⟶ Some (g b) = foldr (λ(k::'a, v::'b) m::'a ⇒ 'b option. m(k ↦ v)) (map (λx::'c. (f x, g x)) xs) (λx::'a. None) (f b)›*) apply (cut_tac ms="map (λx. [f x ↦ g x]) xs" and f="[f a ↦ g a]" and x="f b" in fold_ignore6 (*‹?f ?x = None ⟹ fold (++) ?ms ?f ?x = fold (++) ?ms (λx. None) ?x›*)) (*goals: 1. ‹⋀a xs b f g. ⟦⋀ba fa g. ⟦fold (++) (map (λx. [fa x ↦ g x]) xs) (λx. None) (fa ba) = Some (g ba); ba ∈ set xs; f b = fa ba⟧ ⟹ Some (g ba) = foldr (λ(k, v) m. m(k ↦ v)) (map (λx. (fa x, g x)) xs) (λx. None) (fa ba); fold (++) (map (λx. [f x ↦ g x]) xs) [f a ↦ g a] (f b) = Some (g b); b = a ∨ b ∈ set xs; x = f b; f b ≠ f a⟧ ⟹ [f a ↦ g a] (f b) = None› 2. ‹⋀a xs b f g. ⟦⋀ba fa g. ⟦fold (++) (map (λx. [fa x ↦ g x]) xs) (λx. None) (fa ba) = Some (g ba); ba ∈ set xs; f b = fa ba⟧ ⟹ Some (g ba) = foldr (λ(k, v) m. m(k ↦ v)) (map (λx. (fa x, g x)) xs) (λx. None) (fa ba); fold (++) (map (λx. [f x ↦ g x]) xs) [f a ↦ g a] (f b) = Some (g b); b = a ∨ b ∈ set xs; x = f b; f b ≠ f a; fold (++) (map (λx. [f x ↦ g x]) xs) [f a ↦ g a] (f b) = fold (++) (map (λx. [f x ↦ g x]) xs) (λx. None) (f b)⟧ ⟹ Some (g b) = foldr (λ(k, v) m. m(k ↦ v)) (map (λx. (f x, g x)) xs) (λx. None) (f b)› discuss goal 1*) apply clarsimp (*discuss goal 2*) apply auto (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . . lemma if_n_0_0: "((if P then n else 0) ≠ 0) = (P ∧ n ≠ 0)" by (simp split: if_split (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))›*)) lemma insert_dom: assumes fx: "f x = Some y" shows "insert x (dom f) = dom f" unfolding dom_def (*goal: ‹insert (x::'b::type) {a::'b::type. (f::'b::type ⇒ 'a::type option) a ≠ None} = {a::'b::type. f a ≠ None}›*) using fx (*‹f x = Some y›*) by auto lemma map_comp_subset_dom: "dom (prj ∘⇩m f) ⊆ dom f" unfolding dom_def (*goal: ‹{a. (prj ∘⇩m f) a ≠ None} ⊆ {a. f a ≠ None}›*) by (auto simp: map_comp_Some_iff (*‹((?m1.0 ∘⇩m ?m2.0) ?k = Some ?v) = (∃k'. ?m2.0 ?k = Some k' ∧ ?m1.0 k' = Some ?v)›*)) lemmas map_comp_subset_domD = subsetD [OF map_comp_subset_dom] lemma dom_map_comp: "x ∈ dom (prj ∘⇩m f) = (∃y z. f x = Some y ∧ prj y = Some z)" by (fastforce simp: dom_def (*‹dom ?m = {a. ?m a ≠ None}›*) map_comp_Some_iff (*‹((?m1.0 ∘⇩m ?m2.0) ?k = Some ?v) = (∃k'. ?m2.0 ?k = Some k' ∧ ?m1.0 k' = Some ?v)›*)) lemma map_option_Some_eq2: "(Some y = map_option f x) = (∃z. x = Some z ∧ f z = y)" by (metis map_option_eq_Some (*‹(map_option ?f ?xo = Some ?y) = (∃z. ?xo = Some z ∧ ?f z = ?y)›*)) lemma map_option_eq_dom_eq: assumes ome: "map_option f ∘ g = map_option f ∘ g'" shows "dom g = dom g'" proof (rule set_eqI (*‹(⋀x. (x ∈ ?A) = (x ∈ ?B)) ⟹ ?A = ?B›*)) (*goal: ‹⋀x. (x ∈ dom g) = (x ∈ dom g')›*) fix x { assume "x ∈ dom g" (*‹(x::'a) ∈ dom (g::'a ⇒ 'c option)›*) hence "Some (f (the (g x))) = (map_option f ∘ g) x" by (auto simp: map_option_case (*‹map_option (?f::?'b::type ⇒ ?'a::type) (?y::?'b::type option) = (case ?y of None ⇒ None | Some (x::?'b::type) ⇒ Some (?f x))›*) split: option.splits (*‹(?P::?'b::type ⇒ bool) (case ?option::?'a::type option of None ⇒ ?f1.0::?'b::type | Some (x::?'a::type) ⇒ (?f2.0::?'a::type ⇒ ?'b::type) x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2::?'a::type. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹(?P::?'b::type ⇒ bool) (case ?option::?'a::type option of None ⇒ ?f1.0::?'b::type | Some (x::?'a::type) ⇒ (?f2.0::?'a::type ⇒ ?'b::type) x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2::?'a::type. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) also (*calculation: ‹Some ((f::'c ⇒ 'b) (the ((g::'a ⇒ 'c option) (x::'a)))) = (map_option f ∘ g) x›*) have "… = (map_option f ∘ g') x" by (simp add: ome (*‹map_option (f::'c ⇒ 'b) ∘ (g::'a ⇒ 'c option) = map_option f ∘ (g'::'a ⇒ 'c option)›*)) finally (*calculation: ‹Some (f (the (g x))) = (map_option f ∘ g') x›*) have "x ∈ dom g'" by (auto simp: map_option_case (*‹map_option ?f ?y = (case ?y of None ⇒ None | Some x ⇒ Some (?f x))›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) } moreover { assume "x ∈ dom g'" (*‹(x::'a) ∈ dom (g'::'a ⇒ 'c option)›*) hence "Some (f (the (g' x))) = (map_option f ∘ g') x" by (auto simp: map_option_case (*‹map_option ?f ?y = (case ?y of None ⇒ None | Some x ⇒ Some (?f x))›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) also (*calculation: ‹Some ((f::'c ⇒ 'b) (the ((g'::'a ⇒ 'c option) (x::'a)))) = (map_option f ∘ g') x›*) have "… = (map_option f ∘ g) x" by (simp add: ome (*‹map_option f ∘ g = map_option f ∘ g'›*)) finally (*calculation: ‹Some ((f::'c ⇒ 'b) (the ((g'::'a ⇒ 'c option) (x::'a)))) = (map_option f ∘ (g::'a ⇒ 'c option)) x›*) have "x ∈ dom g" by (auto simp: map_option_case (*‹map_option ?f ?y = (case ?y of None ⇒ None | Some x ⇒ Some (?f x))›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) } ultimately show "(x ∈ dom g) = (x ∈ dom g')" by auto qed lemma cart_singleton_image: "S × {s} = (λv. (v, s)) ` S" by auto lemma singleton_eq_o2s: "({x} = set_option v) = (v = Some x)" apply (cases v) (*goals: 1. ‹v = None ⟹ ({x} = set_option v) = (v = Some x)› 2. ‹⋀a. v = Some a ⟹ ({x} = set_option v) = (v = Some x)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma option_set_singleton_eq: "(set_option opt = {v}) = (opt = Some v)" apply (cases opt) (*goals: 1. ‹(opt::'a::type option) = None ⟹ (set_option opt = {v::'a::type}) = (opt = Some v)› 2. ‹⋀a::'a::type. (opt::'a::type option) = Some a ⟹ (set_option opt = {v::'a::type}) = (opt = Some v)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemmas option_set_singleton_eqs = option_set_singleton_eq trans[OF eq_commute option_set_singleton_eq] lemma map_option_comp2: "map_option (f o g) = map_option f o map_option g" by (simp add: option.map_comp (*‹map_option ?g (map_option ?f ?v) = map_option (?g ∘ ?f) ?v›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*)) lemma compD: "⟦f ∘ g = f ∘ g'; g x = v ⟧ ⟹ f (g' x) = f v" by (metis comp_apply (*‹(?f ∘ ?g) ?x = ?f (?g ?x)›*)) lemma map_option_comp_eqE: assumes om: "map_option f ∘ mp = map_option f ∘ mp'" and p1: "⟦ mp x = None; mp' x = None ⟧ ⟹ P" and p2: "⋀v v'. ⟦ mp x = Some v; mp' x = Some v'; f v = f v' ⟧ ⟹ P" shows "P" proof (cases "mp x") (*goals: 1. ‹mp x = None ⟹ P› 2. ‹⋀a. mp x = Some a ⟹ P›*) case None (*‹mp x = None›*) hence "x ∉ dom mp" by (simp add: domIff (*‹((?a::?'a) ∈ dom (?m::?'a ⇒ ?'b option)) = (?m ?a ≠ None)›*)) hence "mp' x = None" by (simp add: map_option_eq_dom_eq [OF om] (*‹dom mp = dom mp'›*) domIff (*‹(?a ∈ dom ?m) = (?m ?a ≠ None)›*)) with None (*‹mp x = None›*) show "?thesis" (*goal: ‹P›*) by (rule p1 (*‹⟦mp x = None; mp' x = None⟧ ⟹ P›*)) next (*goal: ‹⋀a. mp x = Some a ⟹ P›*) case (Some v) (*‹mp x = Some v›*) hence "x ∈ dom mp" by clarsimp then obtain v' where Some': "mp' x = Some v'" (*goal: ‹(⋀v'. mp' x = Some v' ⟹ thesis) ⟹ thesis›*) by (clarsimp simp add: map_option_eq_dom_eq [OF om] (*‹dom mp = dom mp'›*)) with Some (*‹mp x = Some v›*) show "?thesis" (*goal: ‹P›*) proof (rule p2 (*‹⟦mp x = Some ?v; mp' x = Some ?v'; f ?v = f ?v'⟧ ⟹ P›*)) (*goal: ‹(f::'c::type ⇒ 'b::type) (v::'c::type) = f (v'::'c::type)›*) show "f v = f v'" using Some' (*‹mp' x = Some v'›*) compD[OF om, OF Some] (*‹map_option f (mp' x) = map_option f (Some v)›*) by simp qed qed lemma Some_the: "x ∈ dom f ⟹ f x = Some (the (f x))" by clarsimp lemma map_comp_update: "f ∘⇩m (g(x ↦ v)) = (f ∘⇩m g)(x := f v)" apply (intro ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹f ∘⇩m g(x ↦ v) = (f ∘⇩m g)(x := f v)›*) subgoal for y apply (cases "g y") (*goals: 1. ‹(g::'a ⇒ 'c option) (y::'a) = None ⟹ ((f::'c ⇒ 'b option) ∘⇩m g(x::'a ↦ v::'c)) y = ((f ∘⇩m g)(x := f v)) y› 2. ‹⋀a::'c. (g::'a ⇒ 'c option) (y::'a) = Some a ⟹ ((f::'c ⇒ 'b option) ∘⇩m g(x::'a ↦ v::'c)) y = ((f ∘⇩m g)(x := f v)) y› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . . lemma restrict_map_eqI: assumes req: "A |` S = B |` S" and mem: "x ∈ S" shows "A x = B x" proof (-) (*goal: ‹(A::'a ⇒ 'b option) (x::'a) = (B::'a ⇒ 'b option) x›*) from mem (*‹(x::'a) ∈ (S::'a set)›*) have "A x = (A |` S) x" by simp also (*calculation: ‹A x = (A |` S) x›*) have "… = (B |` S) x" using req (*‹(A::'a ⇒ 'b option) |` (S::'a set) = (B::'a ⇒ 'b option) |` S›*) by simp also (*calculation: ‹A x = (B |` S) x›*) have "… = B x" using mem (*‹x ∈ S›*) by simp finally (*calculation: ‹A x = B x›*) show "?thesis" (*goal: ‹(A::'a ⇒ 'b option) (x::'a) = (B::'a ⇒ 'b option) x›*) . qed lemma map_comp_eqI: assumes dm: "dom g = dom g'" and fg: "⋀x. x ∈ dom g' ⟹ f (the (g' x)) = f (the (g x))" shows "f ∘⇩m g = f ∘⇩m g'" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹f ∘⇩m g = f ∘⇩m g'›*) subgoal for x apply (cases "x ∈ dom g") (*goals: 1. ‹x ∈ dom g ⟹ (f ∘⇩m g) x = (f ∘⇩m g') x› 2. ‹x ∉ dom g ⟹ (f ∘⇩m g) x = (f ∘⇩m g') x› discuss goal 1*) apply (frule subst [OF dm] (*‹?P (dom g) ⟹ ?P (dom g')›*)) (*top goal: ‹x ∈ dom g ⟹ (f ∘⇩m g) x = (f ∘⇩m g') x› and 1 goal remains*) apply (clarsimp split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) (*top goal: ‹⟦x ∈ dom g; x ∈ dom g'⟧ ⟹ (f ∘⇩m g) x = (f ∘⇩m g') x› and 1 goal remains*) apply (frule domI [where m = g'] (*‹(g'::'a ⇒ 'b option) (?a::'a) = Some (?b::'b) ⟹ ?a ∈ dom g'›*)) (*top goal: ‹⋀y ya. ⟦g x = Some y; g' x = Some ya⟧ ⟹ f y = f ya› and 1 goal remains*) apply (drule fg (*‹?x ∈ dom g' ⟹ f (the (g' ?x)) = f (the (g ?x))›*)) (*top goal: ‹⋀y ya. ⟦g x = Some y; g' x = Some ya; x ∈ dom g'⟧ ⟹ f y = f ya› and 1 goal remains*) apply simp (*discuss goal 2*) apply (frule subst [OF dm] (*‹(?P::'a set ⇒ bool) (dom (g::'a ⇒ 'b option)) ⟹ ?P (dom (g'::'a ⇒ 'b option))›*)) (*goal: ‹x ∉ dom g ⟹ (f ∘⇩m g) x = (f ∘⇩m g') x›*) apply clarsimp (*goal: ‹⟦x ∉ dom g; x ∉ dom g'⟧ ⟹ (f ∘⇩m g) x = (f ∘⇩m g') x›*) apply (drule not_sym (*‹?t ≠ ?s ⟹ ?s ≠ ?t›*)) (*goal: ‹⟦None ≠ (f ∘⇩m g') x; g x = None⟧ ⟹ ∃y. g' x = Some y›*) apply (clarsimp simp: map_comp_Some_iff (*‹(((?m1.0::?'b ⇒ ?'a option) ∘⇩m (?m2.0::?'c ⇒ ?'b option)) (?k::?'c) = Some (?v::?'a)) = (∃k'::?'b. ?m2.0 ?k = Some k' ∧ ?m1.0 k' = Some ?v)›*)) (*proven 2 subgoals*) . . definition "modify_map m p f ≡ m (p := map_option f (m p))" lemma modify_map_id: "modify_map m p id = m" by (auto simp add: modify_map_def (*‹modify_map ?m ?p ?f ≡ ?m(?p := map_option ?f (?m ?p))›*) map_option_case (*‹map_option ?f ?y = (case ?y of None ⇒ None | Some x ⇒ Some (?f x))›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) lemma modify_map_addr_com: assumes com: "x ≠ y" shows "modify_map (modify_map m x g) y f = modify_map (modify_map m y f) x g" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹modify_map (modify_map m x g) y f = modify_map (modify_map m y f) x g›*) by (simp add: modify_map_def (*‹modify_map ?m ?p ?f ≡ ?m(?p := map_option ?f (?m ?p))›*) map_option_case (*‹map_option ?f ?y = (case ?y of None ⇒ None | Some x ⇒ Some (?f x))›*) com (*‹x ≠ y›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) lemma modify_map_dom : "dom (modify_map m p f) = dom m" unfolding modify_map_def (*goal: ‹dom ((m::'a ⇒ 'b option)(p::'a := map_option (f::'b ⇒ 'b) (m p))) = dom m›*) by (auto simp: dom_def (*‹dom ?m = {a. ?m a ≠ None}›*)) lemma modify_map_None: "m x = None ⟹ modify_map m x f = m" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹m x = None ⟹ modify_map m x f = m›*) by (simp add: modify_map_def (*‹modify_map ?m ?p ?f ≡ ?m(?p := map_option ?f (?m ?p))›*)) lemma modify_map_ndom : "x ∉ dom m ⟹ modify_map m x f = m" apply (rule modify_map_None (*‹?m ?x = None ⟹ modify_map ?m ?x ?f = ?m›*)) (*goal: ‹x ∉ dom m ⟹ modify_map m x f = m›*) by clarsimp lemma modify_map_app: "(modify_map m p f) q = (if p = q then map_option f (m p) else m q)" unfolding modify_map_def (*goal: ‹((m::'b ⇒ 'a option)(p::'b := map_option (f::'a ⇒ 'a) (m p))) (q::'b) = (if p = q then map_option f (m p) else m q)›*) by simp lemma modify_map_apply: "m p = Some x ⟹ modify_map m p f = m (p ↦ f x)" by (simp add: modify_map_def (*‹modify_map ?m ?p ?f ≡ ?m(?p := map_option ?f (?m ?p))›*)) lemma modify_map_com: assumes com: "⋀x. f (g x) = g (f x)" shows "modify_map (modify_map m x g) y f = modify_map (modify_map m y f) x g" using assms (*‹f (g ?x) = g (f ?x)›*) by (auto simp: modify_map_def (*‹modify_map ?m ?p ?f ≡ ?m(?p := map_option ?f (?m ?p))›*) map_option_case (*‹map_option ?f ?y = (case ?y of None ⇒ None | Some x ⇒ Some (?f x))›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) lemma modify_map_comp: "modify_map m x (f o g) = modify_map (modify_map m x g) x f" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹modify_map m x (f ∘ g) = modify_map (modify_map m x g) x f›*) by (simp add: modify_map_def (*‹modify_map ?m ?p ?f ≡ ?m(?p := map_option ?f (?m ?p))›*) option.map_comp (*‹map_option ?g (map_option ?f ?v) = map_option (?g ∘ ?f) ?v›*)) lemma modify_map_exists_eq: "(∃cte. modify_map m p' f p= Some cte) = (∃cte. m p = Some cte)" by (auto simp: modify_map_def (*‹modify_map (?m::?'a::type ⇒ ?'b::type option) (?p::?'a::type) (?f::?'b::type ⇒ ?'b::type) ≡ ?m(?p := map_option ?f (?m ?p))›*) split: if_splits (*‹(?P::?'a::type ⇒ bool) (if ?Q::bool then ?x::?'a::type else (?y::?'a::type)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹(?P::?'a::type ⇒ bool) (if ?Q::bool then ?x::?'a::type else (?y::?'a::type)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) lemma modify_map_other: "p ≠ q ⟹ (modify_map m p f) q = (m q)" by (simp add: modify_map_app (*‹modify_map ?m ?p ?f ?q = (if ?p = ?q then map_option ?f (?m ?p) else ?m ?q)›*)) lemma modify_map_same: "modify_map m p f p = map_option f (m p)" by (simp add: modify_map_app (*‹modify_map ?m ?p ?f ?q = (if ?p = ?q then map_option ?f (?m ?p) else ?m ?q)›*)) lemma next_update_is_modify: "⟦ m p = Some cte'; cte = f cte' ⟧ ⟹ (m(p ↦ cte)) = modify_map m p f" unfolding modify_map_def (*goal: ‹⟦(m::'b ⇒ 'a option) (p::'b) = Some (cte'::'a); (cte::'a) = (f::'a ⇒ 'a) cte'⟧ ⟹ m(p ↦ cte) = m(p := map_option f (m p))›*) by simp lemma nat_power_minus_less: "a < 2 ^ (x - n) ⟹ (a :: nat) < 2 ^ x" apply (erule order_less_le_trans (*‹⟦?x < ?y; ?y ≤ ?z⟧ ⟹ ?x < ?z›*)) (*goal: ‹a < 2 ^ (x - n) ⟹ a < 2 ^ x›*) by simp lemma neg_rtranclI: "⟦ x ≠ y; (x, y) ∉ R⁺ ⟧ ⟹ (x, y) ∉ R⇧*" by (meson rtranclD (*‹(?a, ?b) ∈ ?R⇧* ⟹ ?a = ?b ∨ ?a ≠ ?b ∧ (?a, ?b) ∈ ?R⁺›*)) lemma neg_rtrancl_into_trancl: "¬ (x, y) ∈ R⇧* ⟹ ¬ (x, y) ∈ R⁺" apply (erule contrapos_nn (*‹⟦¬ ?Q; ?P ⟹ ?Q⟧ ⟹ ¬ ?P›*)) (*goal: ‹(x, y) ∉ R⇧* ⟹ (x, y) ∉ R⁺›*) by (erule trancl_into_rtrancl (*‹(?a, ?b) ∈ ?r⁺ ⟹ (?a, ?b) ∈ ?r⇧*›*)) lemma set_neqI: "⟦ x ∈ S; x ∉ S' ⟧ ⟹ S ≠ S'" by clarsimp lemma set_pair_UN: "{x. P x} = ⋃ ((λxa. {xa} × {xb. P (xa, xb)}) ` {xa. ∃xb. P (xa, xb)})" by fastforce lemma singleton_elemD: "S = {x} ⟹ x ∈ S" by simp lemma singleton_eqD: "A = {x} ⟹ x ∈ A" by blast lemma ball_ran_fun_updI: "⟦ ∀v ∈ ran m. P v; ∀v. y = Some v ⟶ P v ⟧ ⟹ ∀v ∈ ran (m (x := y)). P v" by (auto simp add: ran_def (*‹ran (?m::?'a ⇒ ?'b option) = {b::?'b. ∃a::?'a. ?m a = Some b}›*)) lemma ball_ran_eq: "(∀y ∈ ran m. P y) = (∀x y. m x = Some y ⟶ P y)" by (auto simp add: ran_def (*‹ran ?m = {b. ∃a. ?m a = Some b}›*)) lemma cart_helper: "({} = {x} × S) = (S = {})" by blast lemmas converse_trancl_induct' = converse_trancl_induct [consumes 1, case_names base step] lemma disjCI2: "(¬ P ⟹ Q) ⟹ P ∨ Q" by blast lemma insert_UNIV : "insert x UNIV = UNIV" by blast lemma not_singletonE: "⟦ ∀p. S ≠ {p}; S ≠ {}; ⋀p p'. ⟦ p ≠ p'; p ∈ S; p' ∈ S ⟧ ⟹ R ⟧ ⟹ R" by blast lemma not_singleton_oneE: "⟦ ∀p. S ≠ {p}; p ∈ S; ⋀p'. ⟦ p ≠ p'; p' ∈ S ⟧ ⟹ R ⟧ ⟹ R" using not_singletonE (*‹⟦∀p. ?S ≠ {p}; ?S ≠ {}; ⋀p p'. ⟦p ≠ p'; p ∈ ?S; p' ∈ ?S⟧ ⟹ ?R⟧ ⟹ ?R›*) by fastforce lemma ball_ran_modify_map_eq: "⟦ ∀v. m x = Some v ⟶ P (f v) = P v ⟧ ⟹ (∀v ∈ ran (modify_map m x f). P v) = (∀v ∈ ran m. P v)" by (auto simp: modify_map_def (*‹modify_map ?m ?p ?f ≡ ?m(?p := map_option ?f (?m ?p))›*) ball_ran_eq (*‹(∀y∈ran ?m. ?P y) = (∀x y. ?m x = Some y ⟶ ?P y)›*)) lemma eq_singleton_redux: "⟦ S = {x} ⟧ ⟹ x ∈ S" by simp lemma if_eq_elem_helperE: "⟦ x ∈ (if P then S else S'); ⟦ P; x ∈ S ⟧ ⟹ a = b; ⟦ ¬ P; x ∈ S' ⟧ ⟹ a = c ⟧ ⟹ a = (if P then b else c)" by fastforce lemma if_option_Some: "((if P then None else Some x) = Some y) = (¬P ∧ x = y)" by simp lemma insert_minus_eq: "x ∉ A ⟹ A - S = (A - (S - {x}))" by auto lemma modify_map_K_D: "modify_map m p (λx. y) p' = Some v ⟹ (m (p ↦ y)) p' = Some v" by (simp add: modify_map_def (*‹modify_map (?m::?'a ⇒ ?'b option) (?p::?'a) (?f::?'b ⇒ ?'b) ≡ ?m(?p := map_option ?f (?m ?p))›*) split: if_split_asm (*‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) lemma tranclE2: assumes trancl: "(a, b) ∈ r⁺" and base: "(a, b) ∈ r ⟹ P" and step: "⋀c. ⟦(a, c) ∈ r; (c, b) ∈ r⁺⟧ ⟹ P" shows "P" using trancl (*‹(a::'a::type, b::'a::type) ∈ (r::('a::type × 'a::type) set)⁺›*) base (*‹(a, b) ∈ r ⟹ P›*) step (*‹⟦(a, ?c) ∈ r; (?c, b) ∈ r⁺⟧ ⟹ P›*) proof (-) (*goal: ‹⟦(a, b) ∈ r⁺; (a, b) ∈ r ⟹ P; ⋀c. ⟦(a, c) ∈ r; (c, b) ∈ r⁺⟧ ⟹ P⟧ ⟹ P›*) note rl = converse_trancl_induct[where P = "λx. x = a ⟶ P"] (*‹⟦(?a::'a, ?b::'a) ∈ (?r::('a × 'a) set)⁺; ⋀y::'a. (y, ?b) ∈ ?r ⟹ y = (a::'a) ⟶ (P::bool); ⋀(y::'a) z::'a. ⟦(y, z) ∈ ?r; (z, ?b) ∈ ?r⁺; z = a ⟶ P⟧ ⟹ y = a ⟶ P⟧ ⟹ ?a = a ⟶ P›*) from trancl (*‹(a::'a, b::'a) ∈ (r::('a × 'a) set)⁺›*) have "a = a ⟶ P" apply (rule rl (*‹⟦(?a, ?b) ∈ ?r⁺; ⋀y. (y, ?b) ∈ ?r ⟹ y = a ⟶ P; ⋀y z. ⟦(y, z) ∈ ?r; (z, ?b) ∈ ?r⁺; z = a ⟶ P⟧ ⟹ y = a ⟶ P⟧ ⟹ ?a = a ⟶ P›*)) (*goals: 1. ‹⋀y. (y, b) ∈ r ⟹ y = a ⟶ P› 2. ‹⋀y z. ⟦(y, z) ∈ r; (z, b) ∈ r⁺; z = a ⟶ P⟧ ⟹ y = a ⟶ P› discuss goal 1*) apply (iprover intro: base step) (*discuss goal 2*) apply (iprover intro: base step) (*proven 2 subgoals*) . thus "?thesis" (*goal: ‹P›*) by simp qed lemmas tranclE2' = tranclE2 [consumes 1, case_names base trancl] lemma weak_imp_cong: "⟦ P = R; Q = S ⟧ ⟹ (P ⟶ Q) = (R ⟶ S)" by simp lemma Collect_Diff_restrict_simp: "T - {x ∈ T. Q x} = T - {x. Q x}" by (auto intro: Collect_cong (*‹(⋀x. ?P x = ?Q x) ⟹ {x. ?P x} = {x. ?Q x}›*)) lemma Collect_Int_pred_eq: "{x ∈ S. P x} ∩ {x ∈ T. P x} = {x ∈ (S ∩ T). P x}" by (simp add: Collect_conj_eq [symmetric] (*‹{x. ?P x} ∩ {x. ?Q x} = {x. ?P x ∧ ?Q x}›*) conj_comms (*‹(?P ∧ ?Q) = (?Q ∧ ?P)› ‹(?P ∧ ?Q ∧ ?R) = (?Q ∧ ?P ∧ ?R)›*)) lemma Collect_restrict_predR: "{x. P x} ∩ T = {} ⟹ {x. P x} ∩ {x ∈ T. Q x} = {}" by (fastforce simp: disjoint_iff_not_equal (*‹(?A ∩ ?B = {}) = (∀x∈?A. ∀y∈?B. x ≠ y)›*)) lemma Diff_Un2: assumes emptyad: "A ∩ D = {}" and emptybc: "B ∩ C = {}" shows "(A ∪ B) - (C ∪ D) = (A - C) ∪ (B - D)" proof (-) (*goal: ‹A ∪ B - (C ∪ D) = A - C ∪ (B - D)›*) have "(A ∪ B) - (C ∪ D) = (A ∪ B - C) ∩ (A ∪ B - D)" by (rule Diff_Un (*‹(?A::?'a set) - ((?B::?'a set) ∪ (?C::?'a set)) = (?A - ?B) ∩ (?A - ?C)›*)) also (*calculation: ‹A ∪ B - (C ∪ D) = (A ∪ B - C) ∩ (A ∪ B - D)›*) have "… = ((A - C) ∪ B) ∩ (A ∪ (B - D))" using emptyad (*‹A ∩ D = {}›*) emptybc (*‹(B::'a set) ∩ (C::'a set) = {}›*) by (simp add: Un_Diff (*‹?A ∪ ?B - ?C = ?A - ?C ∪ (?B - ?C)›*) Diff_triv (*‹?A ∩ ?B = {} ⟹ ?A - ?B = ?A›*)) also (*calculation: ‹(A::'a set) ∪ (B::'a set) - ((C::'a set) ∪ (D::'a set)) = (A - C ∪ B) ∩ (A ∪ (B - D))›*) have "… = (A - C) ∪ (B - D)" proof (-) (*goal: ‹(A - C ∪ B) ∩ (A ∪ (B - D)) = A - C ∪ (B - D)›*) have "(A - C) ∩ (A ∪ (B - D)) = A - C" using emptyad (*‹A ∩ D = {}›*) emptybc (*‹(B::'a set) ∩ (C::'a set) = {}›*) by (metis Diff_Int2 (*‹?A ∩ ?C - ?B ∩ ?C = ?A ∩ ?C - ?B›*) Diff_Int_distrib2 (*‹(?A - ?B) ∩ ?C = ?A ∩ ?C - ?B ∩ ?C›*) inf_sup_absorb (*‹inf ?x (sup ?x ?y) = ?x›*)) moreover have "B ∩ (A ∪ (B - D)) = B - D" using emptyad (*‹(A::'a set) ∩ (D::'a set) = {}›*) emptybc (*‹B ∩ C = {}›*) by (metis Int_Diff (*‹?A ∩ ?B - ?C = ?A ∩ (?B - ?C)›*) Un_Diff (*‹?A ∪ ?B - ?C = ?A - ?C ∪ (?B - ?C)›*) Un_Diff_Int (*‹?A - ?B ∪ ?A ∩ ?B = ?A›*) Un_commute (*‹?A ∪ ?B = ?B ∪ ?A›*) Un_empty_left (*‹{} ∪ ?B = ?B›*) inf_sup_absorb (*‹inf ?x (sup ?x ?y) = ?x›*)) ultimately show "?thesis" (*goal: ‹(A - C ∪ B) ∩ (A ∪ (B - D)) = A - C ∪ (B - D)›*) by (simp add: Int_Un_distrib2 (*‹(?B ∪ ?C) ∩ ?A = ?B ∩ ?A ∪ ?C ∩ ?A›*)) qed finally (*calculation: ‹(A::'a set) ∪ (B::'a set) - ((C::'a set) ∪ (D::'a set)) = A - C ∪ (B - D)›*) show "?thesis" (*goal: ‹A ∪ B - (C ∪ D) = A - C ∪ (B - D)›*) . qed lemma ballEI: "⟦ ∀x ∈ S. Q x; ⋀x. ⟦ x ∈ S; Q x ⟧ ⟹ P x ⟧ ⟹ ∀x ∈ S. P x" by auto lemma dom_if_None: "dom (λx. if P x then None else f x) = dom f - {x. P x}" apply (simp add: dom_def (*‹dom ?m = {a. ?m a ≠ None}›*)) (*goal: ‹dom (λx. if P x then None else f x) = dom f - {x. P x}›*) by fastforce lemma restrict_map_Some_iff: "((m |` S) x = Some y) = (m x = Some y ∧ x ∈ S)" apply (cases "x ∈ S") (*goals: 1. ‹x ∈ S ⟹ ((m |` S) x = Some y) = (m x = Some y ∧ x ∈ S)› 2. ‹x ∉ S ⟹ ((m |` S) x = Some y) = (m x = Some y ∧ x ∈ S)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma context_case_bools: "⟦ ⋀v. P v ⟹ R v; ⟦ ¬ P v; ⋀v. P v ⟹ R v ⟧ ⟹ R v ⟧ ⟹ R v" apply (cases "P v") (*goals: 1. ‹⟦⋀v. P v ⟹ R v; ⟦¬ P v; ⋀v. P v ⟹ R v⟧ ⟹ R v; P v⟧ ⟹ R v› 2. ‹⟦⋀v. P v ⟹ R v; ⟦¬ P v; ⋀v. P v ⟹ R v⟧ ⟹ R v; ¬ P v⟧ ⟹ R v› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma inj_on_fun_upd_strongerI: "⟦inj_on f A; y ∉ f ` (A - {x})⟧ ⟹ inj_on (f(x := y)) A" by (fastforce simp: inj_on_def (*‹inj_on ?f ?A = (∀x∈?A. ∀y∈?A. ?f x = ?f y ⟶ x = y)›*)) lemma less_handy_casesE: "⟦ m < n; m = 0 ⟹ R; ⋀m' n'. ⟦ n = Suc n'; m = Suc m'; m < n ⟧ ⟹ R ⟧ ⟹ R" apply (cases n) (*goals: 1. ‹⟦(m::nat) < (n::nat); m = (0::nat) ⟹ R::bool; ⋀(m'::nat) n'::nat. ⟦n = Suc n'; m = Suc m'; m < n⟧ ⟹ R; n = (0::nat)⟧ ⟹ R› 2. ‹⋀nat::nat. ⟦(m::nat) < (n::nat); m = (0::nat) ⟹ R::bool; ⋀(m'::nat) n'::nat. ⟦n = Suc n'; m = Suc m'; m < n⟧ ⟹ R; n = Suc nat⟧ ⟹ R› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*goal: ‹⋀nat. ⟦m < n; m = 0 ⟹ R; ⋀m' n'. ⟦n = Suc n'; m = Suc m'; m < n⟧ ⟹ R; n = Suc nat⟧ ⟹ R›*) apply (cases m) (*goals: 1. ‹⋀nat. ⟦m < Suc nat; m = 0 ⟹ R; ⋀m'. m = Suc m' ⟹ R; n = Suc nat; m = 0⟧ ⟹ R› 2. ‹⋀nat nata. ⟦m < Suc nat; m = 0 ⟹ R; ⋀m'. m = Suc m' ⟹ R; n = Suc nat; m = Suc nata⟧ ⟹ R› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma subset_drop_Diff_strg: "(A ⊆ C) ⟶ (A - B ⊆ C)" by blast lemma inj_case_bool: "inj (case_bool a b) = (a ≠ b)" by (auto dest: inj_onD[where x=True and y=False] (*‹⟦inj_on ?f ?A; ?f True = ?f False; True ∈ ?A; False ∈ ?A⟧ ⟹ True = False›*) intro: inj_onI (*‹(⋀x y. ⟦x ∈ ?A; y ∈ ?A; ?f x = ?f y⟧ ⟹ x = y) ⟹ inj_on ?f ?A›*) split: bool.split_asm (*‹?P (case ?bool of True ⇒ ?f1.0 | False ⇒ ?f2.0) = (¬ (?bool = True ∧ ¬ ?P ?f1.0 ∨ ?bool = False ∧ ¬ ?P ?f2.0))›*)) lemma foldl_fun_upd: "foldl (λs r. s (r := g r)) f rs = (λx. if x ∈ set rs then g x else f x)" apply (induct rs arbitrary: f) (*goals: 1. ‹⋀f. foldl (λs r. s(r := g r)) f [] = (λx. if x ∈ set [] then g x else f x)› 2. ‹⋀a rs f. (⋀f. foldl (λs r. s(r := g r)) f rs = (λx. if x ∈ set rs then g x else f x)) ⟹ foldl (λs r. s(r := g r)) f (a # rs) = (λx. if x ∈ set (a # rs) then g x else f x)› discuss goal 1*) apply ((auto simp: fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*))[1]) (*discuss goal 2*) apply ((auto simp: fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*))[1]) (*proven 2 subgoals*) . lemma all_rv_choice_fn_eq_pred: "⟦ ⋀rv. P rv ⟹ ∃fn. f rv = g fn ⟧ ⟹ ∃fn. ∀rv. P rv ⟶ f rv = g (fn rv)" apply (rule exI[where x="λrv. SOME h. f rv = g h"] (*‹?P (λrv. SOME h. f rv = g h) ⟹ ∃x. ?P x›*)) (*goal: ‹(⋀rv. P rv ⟹ ∃fn. f rv = g fn) ⟹ ∃fn. ∀rv. P rv ⟶ f rv = g (fn rv)›*) apply (clarsimp split: if_split (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))›*)) (*goal: ‹(⋀rv. P rv ⟹ ∃fn. f rv = g fn) ⟹ ∀rv. P rv ⟶ f rv = g (SOME h. f rv = g h)›*) by (meson someI_ex (*‹∃x::?'a. (?P::?'a ⇒ bool) x ⟹ ?P (SOME x::?'a. ?P x)›*)) lemma ex_const_function: "∃f. ∀s. f (f' s) = v" by force lemma if_Const_helper: "If P (Con x) (Con y) = Con (If P x y)" by (simp split: if_split (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))›*)) lemmas if_Some_helper = if_Const_helper[where Con=Some] lemma expand_restrict_map_eq: "(m |` S = m' |` S) = (∀x. x ∈ S ⟶ m x = m' x)" by (simp add: fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) restrict_map_def (*‹?m |` ?A = (λx. if x ∈ ?A then ?m x else None)›*) split: if_split (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))›*)) lemma disj_imp_rhs: "(P ⟹ Q) ⟹ (P ∨ Q) = Q" by blast lemma remove1_filter: "distinct xs ⟹ remove1 x xs = filter (λy. x ≠ y) xs" apply (induct xs) (*goals: 1. ‹distinct [] ⟹ remove1 x [] = filter ((≠) x) []› 2. ‹⋀a xs. ⟦distinct xs ⟹ remove1 x xs = filter ((≠) x) xs; distinct (a # xs)⟧ ⟹ remove1 x (a # xs) = filter ((≠) x) (a # xs)› discuss goal 1*) apply ((auto intro!: filter_True [symmetric] (*‹∀x∈set ?t. ?P x ⟹ ?t = filter ?P ?t›*))[1]) (*discuss goal 2*) apply ((auto intro!: filter_True [symmetric] (*‹∀x∈set ?t. ?P x ⟹ ?t = filter ?P ?t›*))[1]) (*proven 2 subgoals*) . lemma Int_Union_empty: "(⋀x. x ∈ S ⟹ A ∩ P x = {}) ⟹ A ∩ (⋃x ∈ S. P x) = {}" by auto lemma UN_Int_empty: "(⋀x. x ∈ S ⟹ P x ∩ T = {}) ⟹ (⋃x ∈ S. P x) ∩ T = {}" by auto lemma disjointI: "⟦⋀x y. ⟦ x ∈ A; y ∈ B ⟧ ⟹ x ≠ y ⟧ ⟹ A ∩ B = {}" by auto lemma UN_disjointI: assumes rl: "⋀x y. ⟦ x ∈ A; y ∈ B ⟧ ⟹ P x ∩ Q y = {}" shows "(⋃x ∈ A. P x) ∩ (⋃x ∈ B. Q x) = {}" by (auto dest: rl (*‹⟦?x ∈ A; ?y ∈ B⟧ ⟹ P ?x ∩ Q ?y = {}›*)) lemma UN_set_member: assumes sub: "A ⊆ (⋃x ∈ S. P x)" and nz: "A ≠ {}" shows "∃x ∈ S. P x ∩ A ≠ {}" proof (-) (*goal: ‹∃x∈S. P x ∩ A ≠ {}›*) from nz (*‹A ≠ {}›*) obtain z where zA: "z ∈ A" (*goal: ‹(⋀z. z ∈ A ⟹ thesis) ⟹ thesis›*) by fastforce with sub (*‹A ⊆ ⋃ (P ` S)›*) obtain x where "x ∈ S" and "z ∈ P x" (*goal: ‹(⋀x. ⟦x ∈ S; z ∈ P x⟧ ⟹ thesis) ⟹ thesis›*) by auto hence "P x ∩ A ≠ {}" using zA (*‹z ∈ A›*) by auto thus "?thesis" (*goal: ‹∃x∈S. P x ∩ A ≠ {}›*) using sub (*‹(A::'a set) ⊆ ⋃ ((P::'b ⇒ 'a set) ` (S::'b set))›*) nz (*‹A ≠ {}›*) by auto qed lemma append_Cons_cases [consumes 1, case_names pre mid post]: "⟦(x, y) ∈ set (as @ b # bs); (x, y) ∈ set as ⟹ R; ⟦(x, y) ∉ set as; (x, y) ∉ set bs; (x, y) = b⟧ ⟹ R; (x, y) ∈ set bs ⟹ R⟧ ⟹ R" by auto lemma cart_singletons: "{a} × {b} = {(a, b)}" by blast lemma disjoint_subset_neg1: "⟦ B ∩ C = {}; A ⊆ B; A ≠ {} ⟧ ⟹ ¬ A ⊆ C" by auto lemma disjoint_subset_neg2: "⟦ B ∩ C = {}; A ⊆ C; A ≠ {} ⟧ ⟹ ¬ A ⊆ B" by auto lemma iffE2: "⟦ P = Q; ⟦ P; Q ⟧ ⟹ R; ⟦ ¬ P; ¬ Q ⟧ ⟹ R ⟧ ⟹ R" by blast lemma list_case_If: "(case xs of [] ⇒ P | _ ⇒ Q) = (if xs = [] then P else Q)" by (rule list.case_eq_if (*‹(case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = (if ?list = [] then ?f1.0 else ?f2.0 (hd ?list) (tl ?list))›*)) lemma remove1_Nil_in_set: "⟦ remove1 x xs = []; xs ≠ [] ⟧ ⟹ x ∈ set xs" apply (induct xs) (*goals: 1. ‹⟦remove1 x [] = []; [] ≠ []⟧ ⟹ x ∈ set []› 2. ‹⋀a xs. ⟦⟦remove1 x xs = []; xs ≠ []⟧ ⟹ x ∈ set xs; remove1 x (a # xs) = []; a # xs ≠ []⟧ ⟹ x ∈ set (a # xs)› discuss goal 1*) apply ((auto split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 2 subgoals*) . lemma remove1_empty: "(remove1 v xs = []) = (xs = [v] ∨ xs = [])" apply (cases xs) (*goals: 1. ‹xs = [] ⟹ (remove1 v xs = []) = (xs = [v] ∨ xs = [])› 2. ‹⋀a list. xs = a # list ⟹ (remove1 v xs = []) = (xs = [v] ∨ xs = [])› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma set_remove1: "x ∈ set (remove1 y xs) ⟹ x ∈ set xs" apply (induct xs) (*goals: 1. ‹x ∈ set (remove1 y []) ⟹ x ∈ set []› 2. ‹⋀a xs. ⟦x ∈ set (remove1 y xs) ⟹ x ∈ set xs; x ∈ set (remove1 y (a # xs))⟧ ⟹ x ∈ set (a # xs)› discuss goal 1*) apply ((auto split: if_split_asm (*‹(?P::?'a::type ⇒ bool) (if ?Q::bool then ?x::?'a::type else (?y::?'a::type)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 2 subgoals*) . lemma If_rearrage: "(if P then if Q then x else y else z) = (if P ∧ Q then x else if P then y else z)" by simp lemma disjI2_strg: "Q ⟶ (P ∨ Q)" by simp lemma eq_imp_strg: "P t ⟶ (t = s ⟶ P s)" by clarsimp lemma if_both_strengthen: "P ∧ Q ⟶ (if G then P else Q)" by simp lemma if_both_strengthen2: "P s ∧ Q s ⟶ (if G then P else Q) s" by simp lemma if_swap: "(if P then Q else R) = (if ¬P then R else Q)" by simp lemma imp_consequent: "P ⟶ Q ⟶ P" by simp lemma list_case_helper: "xs ≠ [] ⟹ case_list f g xs = g (hd xs) (tl xs)" apply (cases xs) (*goals: 1. ‹⟦xs ≠ []; xs = []⟧ ⟹ (case xs of [] ⇒ f | x # xa ⇒ g x xa) = g (hd xs) (tl xs)› 2. ‹⋀a list. ⟦xs ≠ []; xs = a # list⟧ ⟹ (case xs of [] ⇒ f | x # xa ⇒ g x xa) = g (hd xs) (tl xs)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma list_cons_rewrite: "(∀x xs. L = x # xs ⟶ P x xs) = (L ≠ [] ⟶ P (hd L) (tl L))" by (auto simp: neq_Nil_conv (*‹(?xs ≠ []) = (∃y ys. ?xs = y # ys)›*)) lemma list_not_Nil_manip: "⟦ xs = y # ys; case xs of [] ⇒ False | (y # ys) ⇒ P y ys ⟧ ⟹ P y ys" by simp lemma ran_ball_triv: "⋀P m S. ⟦ ∀x ∈ (ran S). P x ; m ∈ (ran S) ⟧ ⟹ P m" by blast lemma singleton_tuple_cartesian: "({(a, b)} = S × T) = ({a} = S ∧ {b} = T)" "(S × T = {(a, b)}) = ({a} = S ∧ {b} = T)" (*goals: 1. ‹({(a, b)} = S × T) = ({a} = S ∧ {b} = T)› 2. ‹(S × T = {(a, b)}) = ({a} = S ∧ {b} = T)› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) . lemma strengthen_ignore_if: "A s ∧ B s ⟶ (if P then A else B) s" by clarsimp lemma case_sum_True : "(case r of Inl a ⇒ True | Inr b ⇒ f b) = (∀b. r = Inr b ⟶ f b)" apply (cases r) (*goals: 1. ‹⋀a. r = Inl a ⟹ (case r of Inl a ⇒ True | Inr b ⇒ f b) = (∀b. r = Inr b ⟶ f b)› 2. ‹⋀b. r = Inr b ⟹ (case r of Inl a ⇒ True | Inr b ⇒ f b) = (∀b. r = Inr b ⟶ f b)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma sym_ex_elim: "F x = y ⟹ ∃x. y = F x" by auto lemma tl_drop_1 : "tl xs = drop 1 xs" by (simp add: drop_Suc (*‹drop (Suc ?n) ?xs = drop ?n (tl ?xs)›*)) lemma upt_lhs_sub_map: "[x ..< y] = map ((+) x) [0 ..< y - x]" apply (induct y) (*goals: 1. ‹[x..<0] = map ((+) x) [0..<0 - x]› 2. ‹⋀y. [x..<y] = map ((+) x) [0..<y - x] ⟹ [x..<Suc y] = map ((+) x) [0..<Suc y - x]› discuss goal 1*) apply ((auto simp: Suc_diff_le (*‹(?n::nat) ≤ (?m::nat) ⟹ Suc ?m - ?n = Suc (?m - ?n)›*))[1]) (*discuss goal 2*) apply ((auto simp: Suc_diff_le (*‹?n ≤ ?m ⟹ Suc ?m - ?n = Suc (?m - ?n)›*))[1]) (*proven 2 subgoals*) . lemma upto_0_to_4: "[0..<4] = 0 # [1..<4]" apply (subst upt_rec (*‹[?i..<?j] = (if ?i < ?j then ?i # [Suc ?i..<?j] else [])›*)) (*goal: ‹[0..<4] = 0 # [1..<4]›*) by simp lemma disjEI: "⟦ P ∨ Q; P ⟹ R; Q ⟹ S ⟧ ⟹ R ∨ S" by fastforce lemma dom_fun_upd2: "s x = Some z ⟹ dom (s (x ↦ y)) = dom s" by (simp add: insert_absorb (*‹?a ∈ ?A ⟹ insert ?a ?A = ?A›*) domI (*‹?m ?a = Some ?b ⟹ ?a ∈ dom ?m›*)) lemma foldl_True : "foldl (∨) True bs" apply (induct bs) (*goals: 1. ‹foldl (∨) True []› 2. ‹⋀a bs. foldl (∨) True bs ⟹ foldl (∨) True (a # bs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma image_set_comp: "f ` {g x | x. Q x} = (f ∘ g) ` {x. Q x}" by fastforce lemma mutual_exE: "⟦ ∃x. P x; ⋀x. P x ⟹ Q x ⟧ ⟹ ∃x. Q x" by blast lemma nat_diff_eq: fixes x :: nat shows "⟦ x - y = x - z; y < x⟧ ⟹ y = z" by arith lemma comp_upd_simp: "(f ∘ (g (x := y))) = ((f ∘ g) (x := f y))" by (rule fun_upd_comp (*‹?f ∘ ?g(?x := ?y) = (?f ∘ ?g)(?x := ?f ?y)›*)) lemma dom_option_map: "dom (map_option f o m) = dom m" by (rule dom_map_option_comp (*‹dom (map_option ?g ∘ ?m) = dom ?m›*)) lemma drop_imp: "P ⟹ (A ⟶ P) ∧ (B ⟶ P)" by blast lemma inj_on_fun_updI2: "⟦ inj_on f A; y ∉ f ` (A - {x}) ⟧ ⟹ inj_on (f(x := y)) A" apply (rule inj_on_fun_upd_strongerI (*‹⟦inj_on (?f::?'a ⇒ ?'b) (?A::?'a set); (?y::?'b) ∉ ?f ` (?A - {?x::?'a})⟧ ⟹ inj_on (?f(?x := ?y)) ?A›*)) (*goals: 1. ‹⟦inj_on (f::'a::type ⇒ 'b::type) (A::'a::type set); (y::'b::type) ∉ f ` (A - {x::'a::type})⟧ ⟹ inj_on f A› 2. ‹⟦inj_on (f::'a::type ⇒ 'b::type) (A::'a::type set); (y::'b::type) ∉ f ` (A - {x::'a::type})⟧ ⟹ y ∉ f ` (A - {x})› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) lemma inj_on_fun_upd_elsewhere: "x ∉ S ⟹ inj_on (f (x := y)) S = inj_on f S" apply (simp add: inj_on_def (*‹inj_on ?f ?A = (∀x∈?A. ∀y∈?A. ?f x = ?f y ⟶ x = y)›*)) (*goal: ‹x ∉ S ⟹ inj_on (f(x := y)) S = inj_on f S›*) by blast lemma not_Some_eq_tuple: "(∀y z. x ≠ Some (y, z)) = (x = None)" apply (cases x) (*goals: 1. ‹x = None ⟹ (∀y z. x ≠ Some (y, z)) = (x = None)› 2. ‹⋀a. x = Some a ⟹ (∀y z. x ≠ Some (y, z)) = (x = None)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma ran_option_map: "ran (map_option f o m) = f ` ran m" by (auto simp add: ran_def (*‹ran ?m = {b. ∃a. ?m a = Some b}›*)) lemma All_less_Ball: "(∀x < n. P x) = (∀x∈{..< n}. P x)" by fastforce lemma Int_image_empty: "⟦ ⋀x y. f x ≠ g y ⟧ ⟹ f ` S ∩ g ` T = {}" by auto lemma Max_prop: "⟦ Max S ∈ S ⟹ P (Max S); (S :: ('a :: {finite, linorder}) set) ≠ {} ⟧ ⟹ P (Max S)" by auto lemma Min_prop: "⟦ Min S ∈ S ⟹ P (Min S); (S :: ('a :: {finite, linorder}) set) ≠ {} ⟧ ⟹ P (Min S)" by auto lemma findSomeD: "find P xs = Some x ⟹ P x ∧ x ∈ set xs" apply (induct xs) (*goals: 1. ‹find (P::'a ⇒ bool) [] = Some (x::'a) ⟹ P x ∧ x ∈ set []› 2. ‹⋀(a::'a) xs::'a list. ⟦find (P::'a ⇒ bool) xs = Some (x::'a) ⟹ P x ∧ x ∈ set xs; find P (a # xs) = Some x⟧ ⟹ P x ∧ x ∈ set (a # xs)› discuss goal 1*) apply ((auto split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 2 subgoals*) . lemma findNoneD: "find P xs = None ⟹ ∀x ∈ set xs. ¬P x" apply (induct xs) (*goals: 1. ‹find P [] = None ⟹ ∀x∈set []. ¬ P x› 2. ‹⋀a xs. ⟦find P xs = None ⟹ ∀x∈set xs. ¬ P x; find P (a # xs) = None⟧ ⟹ ∀x∈set (a # xs). ¬ P x› discuss goal 1*) apply ((auto split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 2 subgoals*) . lemma dom_upd: "dom (λx. if x = y then None else f x) = dom f - {y}" apply (rule set_eqI (*‹(⋀x::?'a. (x ∈ (?A::?'a set)) = (x ∈ (?B::?'a set))) ⟹ ?A = ?B›*)) (*goal: ‹dom (λx. if x = y then None else f x) = dom f - {y}›*) by (auto split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) definition is_inv :: "('a ⇀ 'b) ⇒ ('b ⇀ 'a) ⇒ bool" where "is_inv f g ≡ ran f = dom g ∧ (∀x y. f x = Some y ⟶ g y = Some x)" lemma is_inv_NoneD: assumes "g x = None" assumes "is_inv f g" shows "x ∉ ran f" proof (-) (*goal: ‹x ∉ ran f›*) from assms (*‹g x = None› ‹is_inv f g›*) have "x ∉ dom g" by (auto simp: ran_def (*‹ran ?m = {b. ∃a. ?m a = Some b}›*)) moreover from assms (*‹g x = None› ‹is_inv f g›*) have "ran f = dom g" by (simp add: is_inv_def (*‹is_inv ?f ?g ≡ ran ?f = dom ?g ∧ (∀x y. ?f x = Some y ⟶ ?g y = Some x)›*)) ultimately show "?thesis" (*goal: ‹(x::'b) ∉ ran (f::'a ⇒ 'b option)›*) by simp qed lemma is_inv_SomeD: "⟦ f x = Some y; is_inv f g ⟧ ⟹ g y = Some x" by (simp add: is_inv_def (*‹is_inv (?f::?'a ⇒ ?'b option) (?g::?'b ⇒ ?'a option) ≡ ran ?f = dom ?g ∧ (∀(x::?'a) y::?'b. ?f x = Some y ⟶ ?g y = Some x)›*)) lemma is_inv_com: "is_inv f g ⟹ is_inv g f" apply (unfold is_inv_def (*‹is_inv ?f ?g ≡ ran ?f = dom ?g ∧ (∀x y. ?f x = Some y ⟶ ?g y = Some x)›*)) (*goal: ‹is_inv f g ⟹ is_inv g f›*) apply safe (*goals: 1. ‹⋀x. ⟦ran f = dom g; ∀x y. f x = Some y ⟶ g y = Some x; x ∈ ran g⟧ ⟹ ∃y. f x = Some y› 2. ‹⋀x y. ⟦ran f = dom g; ∀x y. f x = Some y ⟶ g y = Some x; f x = Some y⟧ ⟹ x ∈ ran g› 3. ‹⋀x y. ⟦ran f = dom g; ∀x y. f x = Some y ⟶ g y = Some x; g x = Some y⟧ ⟹ f y = Some x› discuss goal 1*) apply (clarsimp simp: ran_def (*‹ran ?m = {b. ∃a. ?m a = Some b}›*) dom_def (*‹dom ?m = {a. ?m a ≠ None}›*) set_eq_iff (*‹(?A = ?B) = (∀x. (x ∈ ?A) = (x ∈ ?B))›*)) (*top goal: ‹⋀x::'a. ⟦ran (f::'a ⇒ 'b option) = dom (g::'b ⇒ 'a option); ∀(x::'a) y::'b. f x = Some y ⟶ g y = Some x; x ∈ ran g⟧ ⟹ ∃y::'b. f x = Some y› and 2 goals remain*) apply (rename_tac a) (*top goal: ‹⋀x a. ⟦∀x. (∃a. f a = Some x) = (∃y. g x = Some y); ∀x y. f x = Some y ⟶ g y = Some x; g a = Some x⟧ ⟹ ∃y. f x = Some y› and 2 goals remain*) apply (erule_tac x=a in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀x a. ⟦∀x. (∃a. f a = Some x) = (∃y. g x = Some y); ∀x y. f x = Some y ⟶ g y = Some x; g a = Some x⟧ ⟹ ∃y. f x = Some y› and 2 goals remain*) apply clarsimp (*discuss goal 2*) apply (clarsimp simp: ran_def (*‹ran (?m::?'a ⇒ ?'b option) = {b::?'b. ∃a::?'a. ?m a = Some b}›*) dom_def (*‹dom (?m::?'a ⇒ ?'b option) = {a::?'a. ?m a ≠ None}›*) set_eq_iff (*‹((?A::?'a set) = (?B::?'a set)) = (∀x::?'a. (x ∈ ?A) = (x ∈ ?B))›*)) (*top goal: ‹⋀x y. ⟦ran f = dom g; ∀x y. f x = Some y ⟶ g y = Some x; f x = Some y⟧ ⟹ x ∈ ran g› and 1 goal remains*) apply blast (*discuss goal 3*) apply (clarsimp simp: ran_def (*‹ran ?m = {b. ∃a. ?m a = Some b}›*) dom_def (*‹dom ?m = {a. ?m a ≠ None}›*) set_eq_iff (*‹(?A = ?B) = (∀x. (x ∈ ?A) = (x ∈ ?B))›*)) (*goal: ‹⋀x y. ⟦ran f = dom g; ∀x y. f x = Some y ⟶ g y = Some x; g x = Some y⟧ ⟹ f y = Some x›*) apply (rename_tac x y) (*goal: ‹⋀(x::'b::type) y::'a::type. ⟦∀x::'b::type. (∃a::'a::type. (f::'a::type ⇒ 'b::type option) a = Some x) = (∃y::'a::type. (g::'b::type ⇒ 'a::type option) x = Some y); ∀(x::'a::type) y::'b::type. f x = Some y ⟶ g y = Some x; g x = Some y⟧ ⟹ f y = Some x›*) apply (erule_tac x=x in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*goal: ‹⋀x y. ⟦∀x. (∃a. f a = Some x) = (∃y. g x = Some y); ∀x y. f x = Some y ⟶ g y = Some x; g x = Some y⟧ ⟹ f y = Some x›*) apply clarsimp (*proven 3 subgoals*) . lemma is_inv_inj: "is_inv f g ⟹ inj_on f (dom f)" apply (frule is_inv_com (*‹is_inv ?f ?g ⟹ is_inv ?g ?f›*)) (*goal: ‹is_inv (f::'a ⇒ 'b option) (g::'b ⇒ 'a option) ⟹ inj_on f (dom f)›*) apply (clarsimp simp: inj_on_def (*‹inj_on ?f ?A = (∀x∈?A. ∀y∈?A. ?f x = ?f y ⟶ x = y)›*)) (*goal: ‹⟦is_inv (f::'a ⇒ 'b option) (g::'b ⇒ 'a option); is_inv g f⟧ ⟹ inj_on f (dom f)›*) apply (drule (1) is_inv_SomeD (*‹⟦?f ?x = Some ?y; is_inv ?f ?g⟧ ⟹ ?g ?y = Some ?x›*)) (*goal: ‹⋀x y ya. ⟦is_inv f g; is_inv g f; f y = Some ya; f x = Some ya⟧ ⟹ x = y›*) by (auto dest: is_inv_SomeD (*‹⟦?f ?x = Some ?y; is_inv ?f ?g⟧ ⟹ ?g ?y = Some ?x›*)) lemma ran_upd': "⟦inj_on f (dom f); f y = Some z⟧ ⟹ ran (f (y := None)) = ran f - {z}" by (force simp: ran_def (*‹ran (?m::?'a ⇒ ?'b option) = {b::?'b. ∃a::?'a. ?m a = Some b}›*) inj_on_def (*‹inj_on (?f::?'a ⇒ ?'b) (?A::?'a set) = (∀x::?'a∈?A. ∀y::?'a∈?A. ?f x = ?f y ⟶ x = y)›*) dom_def (*‹dom (?m::?'a ⇒ ?'b option) = {a::?'a. ?m a ≠ None}›*) intro!: set_eqI (*‹(⋀x::?'a. (x ∈ (?A::?'a set)) = (x ∈ (?B::?'a set))) ⟹ ?A = ?B›*)) lemma is_inv_None_upd: "⟦ is_inv f g; g x = Some y⟧ ⟹ is_inv (f(y := None)) (g(x := None))" apply (subst is_inv_def (*‹is_inv ?f ?g ≡ ran ?f = dom ?g ∧ (∀x y. ?f x = Some y ⟶ ?g y = Some x)›*)) (*goal: ‹⟦is_inv f g; g x = Some y⟧ ⟹ is_inv (f(y := None)) (g(x := None))›*) apply (clarsimp simp: dom_upd (*‹dom (λx::?'a. if x = (?y::?'a) then None else (?f::?'a ⇒ ?'b option) x) = dom ?f - {?y}›*)) (*goal: ‹⟦is_inv f g; g x = Some y⟧ ⟹ ran (f(y := None)) = dom (g(x := None)) ∧ (∀xa ya. (f(y := None)) xa = Some ya ⟶ (g(x := None)) ya = Some xa)›*) apply (drule is_inv_SomeD (*‹⟦?f ?x = Some ?y; is_inv ?f ?g⟧ ⟹ ?g ?y = Some ?x›*), erule is_inv_com (*‹is_inv ?f ?g ⟹ is_inv ?g ?f›*)) (*goal: ‹⟦is_inv (f::'a ⇒ 'b option) (g::'b ⇒ 'a option); g (x::'b) = Some (y::'a)⟧ ⟹ ran (f(y := None)) = dom g - {x} ∧ (∀xa::'a. xa ≠ y ⟶ (∀y::'b. (y = x ⟶ f xa ≠ Some x) ∧ (y ≠ x ⟶ f xa = Some y ⟶ g y = Some xa)))›*) apply (frule is_inv_inj (*‹is_inv (?f::?'a ⇒ ?'b option) (?g::?'b ⇒ ?'a option) ⟹ inj_on ?f (dom ?f)›*)) (*goal: ‹⟦is_inv f g; f y = Some x⟧ ⟹ ran (f(y := None)) = dom g - {x} ∧ (∀xa. xa ≠ y ⟶ (∀y. (y = x ⟶ f xa ≠ Some x) ∧ (y ≠ x ⟶ f xa = Some y ⟶ g y = Some xa)))›*) by (auto simp: ran_upd' (*‹⟦inj_on (?f::?'a::type ⇒ ?'b::type option) (dom ?f); ?f (?y::?'a::type) = Some (?z::?'b::type)⟧ ⟹ ran (?f(?y := None)) = ran ?f - {?z}›*) is_inv_def (*‹is_inv (?f::?'a::type ⇒ ?'b::type option) (?g::?'b::type ⇒ ?'a::type option) ≡ ran ?f = dom ?g ∧ (∀(x::?'a::type) y::?'b::type. ?f x = Some y ⟶ ?g y = Some x)›*) dest: is_inv_SomeD (*‹⟦(?f::?'b::type ⇒ ?'a::type option) (?x::?'b::type) = Some (?y::?'a::type); is_inv ?f (?g::?'a::type ⇒ ?'b::type option)⟧ ⟹ ?g ?y = Some ?x›*) is_inv_inj (*‹is_inv (?f::?'a::type ⇒ ?'b::type option) (?g::?'b::type ⇒ ?'a::type option) ⟹ inj_on ?f (dom ?f)›*)) lemma is_inv_inj2: "is_inv f g ⟹ inj_on g (dom g)" using is_inv_com (*‹is_inv ?f ?g ⟹ is_inv ?g ?f›*) is_inv_inj (*‹is_inv ?f ?g ⟹ inj_on ?f (dom ?f)›*) by blast text ‹Map inversion (implicitly assuming injectivity).› definition "the_inv_map m = (λs. if s∈ran m then Some (THE x. m x = Some s) else None)" text ‹Map inversion can be expressed by function inversion.› lemma the_inv_map_def2: "the_inv_map m = (Some ∘ the_inv_into (dom m) (the ∘ m)) |` (ran m)" apply (rule ext (*‹(⋀x::?'a::type. (?f::?'a::type ⇒ ?'b::type) x = (?g::?'a::type ⇒ ?'b::type) x) ⟹ ?f = ?g›*)) (*goal: ‹the_inv_map m = (Some ∘ the_inv_into (dom m) (the ∘ m)) |` ran m›*) apply (clarsimp simp: the_inv_map_def (*‹the_inv_map ?m = (λs. if s ∈ ran ?m then Some (THE x. ?m x = Some s) else None)›*) the_inv_into_def (*‹the_inv_into ?A ?f = (λx. THE y. y ∈ ?A ∧ ?f y = x)›*) dom_def (*‹dom ?m = {a. ?m a ≠ None}›*)) (*goal: ‹⋀x. the_inv_map m x = ((Some ∘ the_inv_into (dom m) (the ∘ m)) |` ran m) x›*) apply (rule arg_cong[where f=The] (*‹?x = ?y ⟹ The ?x = The ?y›*)) (*goal: ‹⋀x. x ∈ ran m ⟹ (THE xa. m xa = Some x) = (THE y. (∃ya. m y = Some ya) ∧ the (m y) = x)›*) apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹⋀x. x ∈ ran m ⟹ (λxa. m xa = Some x) = (λy. (∃ya. m y = Some ya) ∧ the (m y) = x)›*) by auto text ‹The domain of a function composition with Some is the universal set.› lemma dom_comp_Some[simp]: "dom (comp Some f) = UNIV" by (simp add: dom_def (*‹dom ?m = {a. ?m a ≠ None}›*)) text ‹Assuming injectivity, map inversion produces an inversive map.› lemma is_inv_the_inv_map: "inj_on m (dom m) ⟹ is_inv m (the_inv_map m)" apply (simp add: is_inv_def (*‹is_inv ?f ?g ≡ ran ?f = dom ?g ∧ (∀x y. ?f x = Some y ⟶ ?g y = Some x)›*)) (*goal: ‹inj_on m (dom m) ⟹ is_inv m (the_inv_map m)›*) apply (intro conjI (*‹⟦?P::bool; ?Q::bool⟧ ⟹ ?P ∧ ?Q›*) allI (*‹(⋀x::?'a::type. (?P::?'a::type ⇒ bool) x) ⟹ ∀x::?'a::type. ?P x›*) impI (*‹(?P::bool ⟹ ?Q::bool) ⟹ ?P ⟶ ?Q›*)) (*goals: 1. ‹inj_on (m::'a ⇒ 'b option) (dom m) ⟹ ran m = dom (the_inv_map m)› 2. ‹⋀(x::'a) y::'b. ⟦inj_on (m::'a ⇒ 'b option) (dom m); m x = Some y⟧ ⟹ the_inv_map m y = Some x› discuss goal 1*) apply (simp add: the_inv_map_def2 (*‹the_inv_map ?m = (Some ∘ the_inv_into (dom ?m) (the ∘ ?m)) |` ran ?m›*)) (*discuss goal 2*) apply (auto simp add: the_inv_map_def (*‹the_inv_map ?m = (λs. if s ∈ ran ?m then Some (THE x. ?m x = Some s) else None)›*) inj_on_def (*‹inj_on ?f ?A = (∀x∈?A. ∀y∈?A. ?f x = ?f y ⟶ x = y)›*) dom_def (*‹dom ?m = {a. ?m a ≠ None}›*) intro: ranI (*‹?m ?a = Some ?b ⟹ ?b ∈ ran ?m›*)) (*proven 2 subgoals*) . lemma the_the_inv_mapI: "inj_on m (dom m) ⟹ m x = Some y ⟹ the (the_inv_map m y) = x" by (auto simp: the_inv_map_def (*‹the_inv_map ?m = (λs. if s ∈ ran ?m then Some (THE x. ?m x = Some s) else None)›*) ran_def (*‹ran ?m = {b. ∃a. ?m a = Some b}›*) inj_on_def (*‹inj_on ?f ?A = (∀x∈?A. ∀y∈?A. ?f x = ?f y ⟶ x = y)›*) dom_def (*‹dom ?m = {a. ?m a ≠ None}›*)) lemma eq_restrict_map_None: "restrict_map m A x = None ⟷ x ~: (A ∩ dom m)" by (auto simp: restrict_map_def (*‹?m |` ?A = (λx. if x ∈ ?A then ?m x else None)›*) split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) lemma eq_the_inv_map_None[simp]: "the_inv_map m x = None ⟷ x∉ran m" by (simp add: the_inv_map_def2 (*‹the_inv_map ?m = (Some ∘ the_inv_into (dom ?m) (the ∘ ?m)) |` ran ?m›*) eq_restrict_map_None (*‹((?m |` ?A) ?x = None) = (?x ∉ ?A ∩ dom ?m)›*)) lemma is_inv_unique: "is_inv f g ⟹ is_inv f h ⟹ g=h" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹⟦is_inv (f::'a ⇒ 'b option) (g::'b ⇒ 'a option); is_inv f (h::'b ⇒ 'a option)⟧ ⟹ g = h›*) subgoal for x apply (clarsimp simp: is_inv_def (*‹is_inv ?f ?g ≡ ran ?f = dom ?g ∧ (∀x y. ?f x = Some y ⟶ ?g y = Some x)›*) dom_def (*‹dom ?m = {a. ?m a ≠ None}›*) Collect_eq (*‹({x. ?P x} = {x. ?Q x}) = (∀x. ?P x = ?Q x)›*) ran_def (*‹ran ?m = {b. ∃a. ?m a = Some b}›*)) (*goal: ‹⟦is_inv (f::'a ⇒ 'b option) (g::'b ⇒ 'a option); is_inv f (h::'b ⇒ 'a option)⟧ ⟹ g (x::'b) = h x›*) apply (drule_tac x=x in spec (*‹∀x. ?P x ⟹ ?P ?x›*)) (*goal: ‹⟦∀b. (∃a. f a = Some b) = (∃y. h b = Some y); ∀x y. f x = Some y ⟶ g y = Some x; ∀b. (∃y. g b = Some y) = (∃y. h b = Some y); ∀x y. f x = Some y ⟶ h y = Some x⟧ ⟹ g x = h x›*) apply (drule_tac x=x in spec (*‹∀x. ?P x ⟹ ?P ?x›*)) (*goal: ‹⟦∀(x::'a) y::'b. (f::'a ⇒ 'b option) x = Some y ⟶ (g::'b ⇒ 'a option) y = Some x; ∀b::'b. (∃y::'a. g b = Some y) = (∃y::'a. (h::'b ⇒ 'a option) b = Some y); ∀(x::'a) y::'b. f x = Some y ⟶ h y = Some x; (∃a::'a. f a = Some (x::'b)) = (∃y::'a. h x = Some y)⟧ ⟹ g x = h x›*) apply (cases "g x") (*goals: 1. ‹⟦∀x y. f x = Some y ⟶ g y = Some x; ∀x y. f x = Some y ⟶ h y = Some x; (∃a. f a = Some x) = (∃y. h x = Some y); (∃y. g x = Some y) = (∃y. h x = Some y); g x = None⟧ ⟹ g x = h x› 2. ‹⋀a. ⟦∀x y. f x = Some y ⟶ g y = Some x; ∀x y. f x = Some y ⟶ h y = Some x; (∃a. f a = Some x) = (∃y. h x = Some y); (∃y. g x = Some y) = (∃y. h x = Some y); g x = Some a⟧ ⟹ g x = h x› discuss goal 1*) apply clarsimp (*discuss goal 2*) apply clarsimp (*proven 2 subgoals*) . . lemma range_convergence1: "⟦ ∀z. x < z ∧ z ≤ y ⟶ P z; ∀z > y. P (z :: 'a :: linorder) ⟧ ⟹ ∀z > x. P z" using not_le (*‹(¬ ?x ≤ ?y) = (?y < ?x)›*) by blast lemma range_convergence2: "⟦ ∀z. x < z ∧ z ≤ y ⟶ P z; ∀z. z > y ∧ z < w ⟶ P (z :: 'a :: linorder) ⟧ ⟹ ∀z. z > x ∧ z < w ⟶ P z" using range_convergence1[where P = "λz. z < w ⟶ P z" and x = x and y = y] (*‹⟦∀z::'a. (x::'a) < z ∧ z ≤ (y::'a) ⟶ z < (w::'a) ⟶ (P::'a ⇒ bool) z; ∀z>y. z < w ⟶ P z⟧ ⟹ ∀z>x. z < w ⟶ P z›*) by auto lemma zip_upt_Cons: "a < b ⟹ zip [a ..< b] (x # xs) = (a, x) # zip [Suc a ..< b] xs" by (simp add: upt_conv_Cons (*‹?i < ?j ⟹ [?i..<?j] = ?i # [Suc ?i..<?j]›*)) lemma map_comp_eq: "f ∘⇩m g = case_option None f ∘ g" apply (rule ext (*‹(⋀x::?'a::type. (?f::?'a::type ⇒ ?'b::type) x = (?g::?'a::type ⇒ ?'b::type) x) ⟹ ?f = ?g›*)) (*goal: ‹f ∘⇩m g = case_option None f ∘ g›*) subgoal for x apply (cases "g x") (*goals: 1. ‹g x = None ⟹ (f ∘⇩m g) x = (case_option None f ∘ g) x› 2. ‹⋀a. g x = Some a ⟹ (f ∘⇩m g) x = (case_option None f ∘ g) x› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . . lemma dom_If_Some: "dom (λx. if x ∈ S then Some v else f x) = (S ∪ dom f)" by (auto split: if_split (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))›*)) lemma foldl_fun_upd_const: "foldl (λs x. s(f x := v)) s xs = (λx. if x ∈ f ` set xs then v else s x)" apply (induct xs arbitrary: s) (*goals: 1. ‹⋀s. foldl (λs x. s(f x := v)) s [] = (λx. if x ∈ f ` set [] then v else s x)› 2. ‹⋀a xs s. (⋀s. foldl (λs x. s(f x := v)) s xs = (λx. if x ∈ f ` set xs then v else s x)) ⟹ foldl (λs x. s(f x := v)) s (a # xs) = (λx. if x ∈ f ` set (a # xs) then v else s x)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma foldl_id: "foldl (λs x. s) s xs = s" apply (induct xs) (*goals: 1. ‹foldl (λs x. s) s [] = s› 2. ‹⋀a xs. foldl (λs x. s) s xs = s ⟹ foldl (λs x. s) s (a # xs) = s› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma SucSucMinus: "2 ≤ n ⟹ Suc (Suc (n - 2)) = n" by arith lemma ball_to_all: "(⋀x. (x ∈ A) = (P x)) ⟹ (∀x ∈ A. B x) = (∀x. P x ⟶ B x)" by blast lemma case_option_If: "case_option P (λx. Q) v = (if v = None then P else Q)" by clarsimp lemma case_option_If2: "case_option P Q v = If (v ≠ None) (Q (the v)) P" by (simp split: option.split (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))›*)) lemma if3_fold: "(if P then x else if Q then y else x) = (if P ∨ ¬ Q then x else y)" by simp lemma rtrancl_insert: assumes x_new: "⋀y. (x,y) ∉ R" shows "R^* `` insert x S = insert x (R^* `` S)" proof (-) (*goal: ‹R⇧* `` insert x S = insert x (R⇧* `` S)›*) have "R^* `` insert x S = R^* `` ({x} ∪ S)" by simp also (*calculation: ‹R⇧* `` insert x S = R⇧* `` ({x} ∪ S)›*) have "R^* `` ({x} ∪ S) = R^* `` {x} ∪ R^* `` S" apply (subst Image_Un (*‹?R `` (?A ∪ ?B) = ?R `` ?A ∪ ?R `` ?B›*)) (*goal: ‹R⇧* `` ({x} ∪ S) = R⇧* `` {x} ∪ R⇧* `` S›*) by simp also (*calculation: ‹R⇧* `` insert x S = R⇧* `` {x} ∪ R⇧* `` S›*) have "R^* `` {x} = {x}" by (meson Image_closed_trancl (*‹?r `` ?X ⊆ ?X ⟹ ?r⇧* `` ?X = ?X›*) Image_singleton_iff (*‹(?b ∈ ?r `` {?a}) = ((?a, ?b) ∈ ?r)›*) subsetI (*‹(⋀x. x ∈ ?A ⟹ x ∈ ?B) ⟹ ?A ⊆ ?B›*) x_new (*‹(x, ?y) ∉ R›*)) finally (*calculation: ‹R⇧* `` insert x S = {x} ∪ R⇧* `` S›*) show "?thesis" (*goal: ‹R⇧* `` insert x S = insert x (R⇧* `` S)›*) by simp qed lemma ran_del_subset: "y ∈ ran (f (x := None)) ⟹ y ∈ ran f" by (auto simp: ran_def (*‹ran (?m::?'a::type ⇒ ?'b::type option) = {b::?'b::type. ∃a::?'a::type. ?m a = Some b}›*) split: if_split_asm (*‹(?P::?'a::type ⇒ bool) (if ?Q::bool then ?x::?'a::type else (?y::?'a::type)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) lemma trancl_sub_lift: assumes sub: "⋀p p'. (p,p') ∈ r ⟹ (p,p') ∈ r'" shows "(p,p') ∈ r^+ ⟹ (p,p') ∈ r'^+" by (fastforce intro: trancl_mono (*‹⟦?p ∈ ?r⁺; ?r ⊆ ?s⟧ ⟹ ?p ∈ ?s⁺›*) sub (*‹(?p, ?p') ∈ r ⟹ (?p, ?p') ∈ r'›*)) lemma trancl_step_lift: assumes x_step: "⋀p p'. (p,p') ∈ r' ⟹ (p,p') ∈ r ∨ (p = x ∧ p' = y)" assumes y_new: "⋀p'. ¬(y,p') ∈ r" shows "(p,p') ∈ r'^+ ⟹ (p,p') ∈ r^+ ∨ ((p,x) ∈ r^+ ∧ p' = y) ∨ (p = x ∧ p' = y)" apply (erule trancl_induct (*‹⟦(?a, ?b) ∈ ?r⁺; ⋀y. (?a, y) ∈ ?r ⟹ ?P y; ⋀y z. ⟦(?a, y) ∈ ?r⁺; (y, z) ∈ ?r; ?P y⟧ ⟹ ?P z⟧ ⟹ ?P ?b›*)) (*goal: ‹(p::'a, p'::'a) ∈ (r'::('a × 'a) set)⁺ ⟹ (p, p') ∈ (r::('a × 'a) set)⁺ ∨ (p, x::'a) ∈ r⁺ ∧ p' = (y::'a) ∨ p = x ∧ p' = y›*) apply (drule x_step (*‹(?p, ?p') ∈ r' ⟹ (?p, ?p') ∈ r ∨ ?p = x ∧ ?p' = y›*)) (*top goal: ‹⋀ya::'a. (p::'a, ya) ∈ (r'::('a × 'a) set) ⟹ (p, ya) ∈ (r::('a × 'a) set)⁺ ∨ (p, x::'a) ∈ r⁺ ∧ ya = (y::'a) ∨ p = x ∧ ya = y› and 1 goal remains*) apply fastforce (*top goal: ‹⋀ya. (p, ya) ∈ r ∨ p = x ∧ ya = y ⟹ (p, ya) ∈ r⁺ ∨ (p, x) ∈ r⁺ ∧ ya = y ∨ p = x ∧ ya = y› and 1 goal remains*) apply (erule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goal: ‹⋀(ya::'a::type) z::'a::type. ⟦(p::'a::type, ya) ∈ (r'::('a::type × 'a::type) set)⁺; (ya, z) ∈ r'; (p, ya) ∈ (r::('a::type × 'a::type) set)⁺ ∨ (p, x::'a::type) ∈ r⁺ ∧ ya = (y::'a::type) ∨ p = x ∧ ya = y⟧ ⟹ (p, z) ∈ r⁺ ∨ (p, x) ∈ r⁺ ∧ z = y ∨ p = x ∧ z = y›*) apply (drule x_step (*‹(?p, ?p') ∈ r' ⟹ (?p, ?p') ∈ r ∨ ?p = x ∧ ?p' = y›*)) (*top goal: ‹⋀ya z. ⟦(p, ya) ∈ r'⁺; (ya, z) ∈ r'; (p, ya) ∈ r⁺⟧ ⟹ (p, z) ∈ r⁺ ∨ (p, x) ∈ r⁺ ∧ z = y ∨ p = x ∧ z = y› and 1 goal remains*) apply (erule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀(ya::'a) z::'a. ⟦(p::'a, ya) ∈ (r'::('a × 'a) set)⁺; (p, ya) ∈ (r::('a × 'a) set)⁺; (ya, z) ∈ r ∨ ya = (x::'a) ∧ z = (y::'a)⟧ ⟹ (p, z) ∈ r⁺ ∨ (p, x) ∈ r⁺ ∧ z = y ∨ p = x ∧ z = y› and 1 goal remains*) apply (drule trancl_trans (*‹⟦(?x::?'a, ?y::?'a) ∈ (?r::(?'a × ?'a) set)⁺; (?y, ?z::?'a) ∈ ?r⁺⟧ ⟹ (?x, ?z) ∈ ?r⁺›*), drule r_into_trancl (*‹(?a::?'a::type, ?b::?'a::type) ∈ (?r::(?'a::type × ?'a::type) set) ⟹ (?a, ?b) ∈ ?r⁺›*), assumption) (*top goal: ‹⋀ya z. ⟦(p, ya) ∈ r'⁺; (p, ya) ∈ r⁺; (ya, z) ∈ r⟧ ⟹ (p, z) ∈ r⁺ ∨ (p, x) ∈ r⁺ ∧ z = y ∨ p = x ∧ z = y› and 2 goals remain*) apply blast (*top goal: ‹⋀(ya::'a) z::'a. ⟦(p::'a, ya) ∈ (r'::('a × 'a) set)⁺; (ya, z) ∈ (r::('a × 'a) set); (p, z) ∈ r⁺⟧ ⟹ (p, z) ∈ r⁺ ∨ (p, x::'a) ∈ r⁺ ∧ z = (y::'a) ∨ p = x ∧ z = y› and 2 goals remain*) apply fastforce (*top goal: ‹⋀ya z. ⟦(p, ya) ∈ r'⁺; (p, ya) ∈ r⁺; ya = x ∧ z = y⟧ ⟹ (p, z) ∈ r⁺ ∨ (p, x) ∈ r⁺ ∧ z = y ∨ p = x ∧ z = y› and 1 goal remains*) by (fastforce simp: y_new (*‹(y, ?p') ∉ r›*) dest: x_step (*‹(?p, ?p') ∈ r' ⟹ (?p, ?p') ∈ r ∨ ?p = x ∧ ?p' = y›*)) lemma rtrancl_simulate_weak: assumes r: "(x,z) ∈ R⇧*" assumes s: "⋀y. (x,y) ∈ R ⟹ (y,z) ∈ R⇧* ⟹ (x,y) ∈ R' ∧ (y,z) ∈ R'⇧*" shows "(x,z) ∈ R'⇧*" apply (rule converse_rtranclE[OF r] (*‹⟦x = z ⟹ ?P; ⋀y. ⟦(x, y) ∈ R; (y, z) ∈ R⇧*⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹x = z ⟹ (x, z) ∈ R'⇧*› 2. ‹⋀y. ⟦(x, y) ∈ R; (y, z) ∈ R⇧*⟧ ⟹ (x, z) ∈ R'⇧*› discuss goal 1*) apply simp (*discuss goal 2*) apply (frule (1) s (*‹⟦(x::'a, ?y::'a) ∈ (R::('a × 'a) set); (?y, z::'a) ∈ R⇧*⟧ ⟹ (x, ?y) ∈ (R'::('a × 'a) set) ∧ (?y, z) ∈ R'⇧*›*)) (*goal: ‹⋀y. ⟦(x, y) ∈ R; (y, z) ∈ R⇧*⟧ ⟹ (x, z) ∈ R'⇧*›*) apply clarsimp (*goal: ‹⋀y::'a. ⟦(x::'a, y) ∈ (R::('a × 'a) set); (y, z::'a) ∈ R⇧*; (x, y) ∈ (R'::('a × 'a) set) ∧ (y, z) ∈ R'⇧*⟧ ⟹ (x, z) ∈ R'⇧*›*) apply (rule converse_rtrancl_into_rtrancl (*‹⟦(?a::?'a, ?b::?'a) ∈ (?r::(?'a × ?'a) set); (?b, ?c::?'a) ∈ ?r⇧*⟧ ⟹ (?a, ?c) ∈ ?r⇧*›*)) (*goals: 1. ‹⋀y. ⟦(x, y) ∈ R; (y, z) ∈ R⇧*; (x, y) ∈ R'; (y, z) ∈ R'⇧*⟧ ⟹ (x, ?b7 y) ∈ R'› 2. ‹⋀y. ⟦(x, y) ∈ R; (y, z) ∈ R⇧*; (x, y) ∈ R'; (y, z) ∈ R'⇧*⟧ ⟹ (?b7 y, z) ∈ R'⇧*› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) (*proven 2 subgoals*) lemma list_case_If2: "case_list f g xs = If (xs = []) f (g (hd xs) (tl xs))" by (simp split: list.split (*‹(?P::?'b ⇒ bool) (case ?list::?'a list of [] ⇒ ?f1.0::?'b | (x::?'a) # (xa::?'a list) ⇒ (?f2.0::?'a ⇒ ?'a list ⇒ ?'b) x xa) = ((?list = [] ⟶ ?P ?f1.0) ∧ (∀(x21::?'a) x22::?'a list. ?list = x21 # x22 ⟶ ?P (?f2.0 x21 x22)))›*)) lemma length_ineq_not_Nil: "length xs > n ⟹ xs ≠ []" "length xs ≥ n ⟹ n ≠ 0 ⟶ xs ≠ []" "¬ length xs < n ⟹ n ≠ 0 ⟶ xs ≠ []" "¬ length xs ≤ n ⟹ xs ≠ []" (*goals: 1. ‹n < length xs ⟹ xs ≠ []› 2. ‹n ≤ length xs ⟹ n ≠ 0 ⟶ xs ≠ []› 3. ‹¬ length xs < n ⟹ n ≠ 0 ⟶ xs ≠ []› 4. ‹¬ length xs ≤ n ⟹ xs ≠ []› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . lemma numeral_eqs: "2 = Suc (Suc 0)" "3 = Suc (Suc (Suc 0))" "4 = Suc (Suc (Suc (Suc 0)))" "5 = Suc (Suc (Suc (Suc (Suc 0))))" "6 = Suc (Suc (Suc (Suc (Suc (Suc 0)))))" (*goals: 1. ‹2 = Suc (Suc 0)› 2. ‹3 = Suc (Suc (Suc 0))› 3. ‹4 = Suc (Suc (Suc (Suc 0)))› 4. ‹5 = Suc (Suc (Suc (Suc (Suc 0))))› 5. ‹6 = Suc (Suc (Suc (Suc (Suc (Suc 0)))))› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*discuss goal 4*) apply simp (*discuss goal 5*) apply simp (*proven 5 subgoals*) . lemma psubset_singleton: "(S ⊂ {x}) = (S = {})" by blast lemma length_takeWhile_ge: "length (takeWhile f xs) = n ⟹ length xs = n ∨ (length xs > n ∧ ¬ f (xs ! n))" apply (induct xs arbitrary: n) (*goals: 1. ‹⋀n. length (takeWhile f []) = n ⟹ length [] = n ∨ n < length [] ∧ ¬ f ([] ! n)› 2. ‹⋀a xs n. ⟦⋀n. length (takeWhile f xs) = n ⟹ length xs = n ∨ n < length xs ∧ ¬ f (xs ! n); length (takeWhile f (a # xs)) = n⟧ ⟹ length (a # xs) = n ∨ n < length (a # xs) ∧ ¬ f ((a # xs) ! n)› discuss goal 1*) apply ((auto split: if_split_asm (*‹(?P::?'a::type ⇒ bool) (if ?Q::bool then ?x::?'a::type else (?y::?'a::type)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 2 subgoals*) . lemma length_takeWhile_le: "¬ f (xs ! n) ⟹ length (takeWhile f xs) ≤ n" apply (induct xs arbitrary: n; simp) (*goal: ‹¬ f (xs ! n) ⟹ length (takeWhile f xs) ≤ n›*) subgoal for x and xs and n apply (cases n) (*goals: 1. ‹⟦⋀n. ¬ f (xs ! n) ⟹ length (takeWhile f xs) ≤ n; ¬ f ((x # xs) ! n); n = 0⟧ ⟹ f x ⟶ Suc (length (takeWhile f xs)) ≤ n› 2. ‹⋀nat. ⟦⋀n. ¬ f (xs ! n) ⟹ length (takeWhile f xs) ≤ n; ¬ f ((x # xs) ! n); n = Suc nat⟧ ⟹ f x ⟶ Suc (length (takeWhile f xs)) ≤ n› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . . lemma length_takeWhile_gt: "n < length (takeWhile f xs) ⟹ (∃ys zs. length ys = Suc n ∧ xs = ys @ zs ∧ takeWhile f xs = ys @ takeWhile f zs)" apply (induct xs arbitrary: n; simp split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) (*goal: ‹(n::nat) < length (takeWhile (f::'a ⇒ bool) (xs::'a list)) ⟹ ∃(ys::'a list) zs::'a list. length ys = Suc n ∧ xs = ys @ zs ∧ takeWhile f xs = ys @ takeWhile f zs›*) subgoal for a and xs and n apply (cases n; simp) (*goal: ‹⟦⋀n. n < length (takeWhile f xs) ⟹ ∃ys. length ys = Suc n ∧ (∃zs. xs = ys @ zs ∧ takeWhile f xs = ys @ takeWhile f zs); f a; n < Suc (length (takeWhile f xs))⟧ ⟹ ∃ys. length ys = Suc n ∧ (∃zs. a # xs = ys @ zs ∧ a # takeWhile f xs = ys @ takeWhile f zs)›*) apply (rule exI[where x="[a]"] (*‹?P [a] ⟹ ∃x. ?P x›*)) (*top goal: ‹⟦⋀n. n < length (takeWhile f xs) ⟹ ∃ys. length ys = Suc n ∧ (∃zs. xs = ys @ zs ∧ takeWhile f xs = ys @ takeWhile f zs); f a; n = 0⟧ ⟹ ∃ys. length ys = Suc 0 ∧ (∃zs. a # xs = ys @ zs ∧ a # takeWhile f xs = ys @ takeWhile f zs)› and 1 goal remains*) apply simp (*top goal: ‹⟦⋀n. n < length (takeWhile f xs) ⟹ ∃ys. length ys = Suc n ∧ (∃zs. xs = ys @ zs ∧ takeWhile f xs = ys @ takeWhile f zs); f a; n = 0⟧ ⟹ length [a] = Suc 0 ∧ (∃zs. a # xs = [a] @ zs ∧ a # takeWhile f xs = [a] @ takeWhile f zs)› and 1 goal remains*) apply (erule meta_allE (*‹⟦⋀x. PROP ?P x; PROP ?P ?x ⟹ PROP ?W⟧ ⟹ PROP ?W›*), drule(1) meta_mp (*‹⟦PROP ?P ⟹ PROP ?Q; PROP ?P⟧ ⟹ PROP ?Q›*)) (*goal: ‹⋀nat. ⟦⋀n. n < length (takeWhile f xs) ⟹ ∃ys. length ys = Suc n ∧ (∃zs. xs = ys @ zs ∧ takeWhile f xs = ys @ takeWhile f zs); f a; nat < length (takeWhile f xs); n = Suc nat⟧ ⟹ ∃ys. length ys = Suc (Suc nat) ∧ (∃zs. a # xs = ys @ zs ∧ a # takeWhile f xs = ys @ takeWhile f zs)›*) apply clarsimp (*goal: ‹⋀nat. ⟦f a; nat < length (takeWhile f xs); n = Suc nat; ∃ys. length ys = Suc nat ∧ (∃zs. xs = ys @ zs ∧ takeWhile f xs = ys @ takeWhile f zs)⟧ ⟹ ∃ys. length ys = Suc (Suc nat) ∧ (∃zs. a # xs = ys @ zs ∧ a # takeWhile f xs = ys @ takeWhile f zs)›*) subgoal for _ and ys and zs apply (rule exI[where x="a # ys"] (*‹?P (a # ys) ⟹ ∃x. ?P x›*)) (*goal: ‹⟦(f::'a ⇒ bool) (a::'a); (n::nat) = Suc (nat_::nat); length (ys::'a list) = Suc nat_; takeWhile f (ys @ (zs::'a list)) = ys @ takeWhile f zs; (xs::'a list) = ys @ zs⟧ ⟹ ∃ysa::'a list. length ysa = Suc (Suc nat_) ∧ (∃zsa::'a list. a # ys @ zs = ysa @ zsa ∧ a # ys @ takeWhile f zs = ysa @ takeWhile f zsa)›*) by simp . . lemma hd_drop_conv_nth2: "n < length xs ⟹ hd (drop n xs) = xs ! n" apply (rule hd_drop_conv_nth (*‹?n < length ?xs ⟹ hd (drop ?n ?xs) = ?xs ! ?n›*)) (*goal: ‹n < length xs ⟹ hd (drop n xs) = xs ! n›*) by clarsimp lemma map_upt_eq_vals_D: "⟦ map f [0 ..< n] = ys; m < length ys ⟧ ⟹ f m = ys ! m" by clarsimp lemma length_le_helper: "⟦ n ≤ length xs; n ≠ 0 ⟧ ⟹ xs ≠ [] ∧ n - 1 ≤ length (tl xs)" apply (cases xs) (*goals: 1. ‹⟦n ≤ length xs; n ≠ 0; xs = []⟧ ⟹ xs ≠ [] ∧ n - 1 ≤ length (tl xs)› 2. ‹⋀a list. ⟦n ≤ length xs; n ≠ 0; xs = a # list⟧ ⟹ xs ≠ [] ∧ n - 1 ≤ length (tl xs)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma all_ex_eq_helper: "(∀v. (∃v'. v = f v' ∧ P v v') ⟶ Q v) = (∀v'. P (f v') v' ⟶ Q (f v'))" by auto lemma nat_less_cases': "(x::nat) < y ⟹ x = y - 1 ∨ x < y - 1" by auto lemma less_numeral_nat_iff_disj: "(n::nat) < numeral m ⟷ n = numeral m - 1 ∨ n < numeral m - 1" apply clarsimp using less_SucE numeral_eq_Suc by presburger lemma filter_to_shorter_upto: "n ≤ m ⟹ filter (λx. x < n) [0 ..< m] = [0 ..< n]" apply (induct m) (*goals: 1. ‹n ≤ 0 ⟹ filter (λx. x < n) [0..<0] = [0..<n]› 2. ‹⋀m. ⟦n ≤ m ⟹ filter (λx. x < n) [0..<m] = [0..<n]; n ≤ Suc m⟧ ⟹ filter (λx. x < n) [0..<Suc m] = [0..<n]› discuss goal 1*) apply ((auto elim: le_SucE (*‹⟦?m ≤ Suc ?n; ?m ≤ ?n ⟹ ?R; ?m = Suc ?n ⟹ ?R⟧ ⟹ ?R›*))[1]) (*discuss goal 2*) apply ((auto elim: le_SucE (*‹⟦?m ≤ Suc ?n; ?m ≤ ?n ⟹ ?R; ?m = Suc ?n ⟹ ?R⟧ ⟹ ?R›*))[1]) (*proven 2 subgoals*) . lemma in_emptyE: "⟦ A = {}; x ∈ A ⟧ ⟹ P" by blast lemma Ball_emptyI: "S = {} ⟹ (∀x ∈ S. P x)" by simp lemma allfEI: "⟦ ∀x. P x; ⋀x. P (f x) ⟹ Q x ⟧ ⟹ ∀x. Q x" by fastforce lemma cart_singleton_empty2: "({x} × S = {}) = (S = {})" "({} = S × {e}) = (S = {})" (*goals: 1. ‹({x} × S = {}) = (S = {})› 2. ‹({} = S × {e}) = (S = {})› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma cases_simp_conj: "((P ⟶ Q) ∧ (¬ P ⟶ Q) ∧ R) = (Q ∧ R)" by fastforce lemma domE : "⟦ x ∈ dom m; ⋀r. ⟦m x = Some r⟧ ⟹ P ⟧ ⟹ P" by clarsimp lemma dom_eqD: "⟦ f x = Some v; dom f = S ⟧ ⟹ x ∈ S" by clarsimp lemma exception_set_finite1: "finite {x. P x} ⟹ finite {x. (x = y ⟶ Q x) ∧ P x}" by (simp add: Collect_conj_eq (*‹{x. ?P x ∧ ?Q x} = {x. ?P x} ∩ {x. ?Q x}›*)) lemma exception_set_finite2: "finite {x. P x} ⟹ finite {x. x ≠ y ⟶ P x}" by (simp add: imp_conv_disj (*‹(?P ⟶ ?Q) = (¬ ?P ∨ ?Q)›*)) lemmas exception_set_finite = exception_set_finite1 exception_set_finite2 lemma exfEI: "⟦ ∃x. P x; ⋀x. P x ⟹ Q (f x) ⟧ ⟹ ∃x. Q x" by fastforce lemma Collect_int_vars: "{s. P rv s} ∩ {s. rv = xf s} = {s. P (xf s) s} ∩ {s. rv = xf s}" by auto lemma if_0_1_eq: "((if P then 1 else 0) = (case Q of True ⇒ of_nat 1 | False ⇒ of_nat 0)) = (P = Q)" by (simp split: if_split (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))›*) bool.split (*‹?P (case ?bool of True ⇒ ?f1.0 | False ⇒ ?f2.0) = ((?bool = True ⟶ ?P ?f1.0) ∧ (?bool = False ⟶ ?P ?f2.0))›*)) lemma modify_map_exists_cte : "(∃cte. modify_map m p f p' = Some cte) = (∃cte. m p' = Some cte)" by (simp add: modify_map_def (*‹modify_map (?m::?'a ⇒ ?'b option) (?p::?'a) (?f::?'b ⇒ ?'b) ≡ ?m(?p := map_option ?f (?m ?p))›*)) lemma dom_eqI: assumes c1: "⋀x y. P x = Some y ⟹ ∃y. Q x = Some y" and c2: "⋀x y. Q x = Some y ⟹ ∃y. P x = Some y" shows "dom P = dom Q" unfolding dom_def (*goal: ‹{a::'a. (P::'a ⇒ 'b option) a ≠ None} = {a::'a. (Q::'a ⇒ 'c option) a ≠ None}›*) by (auto simp: c1 (*‹P ?x = Some ?y ⟹ ∃y. Q ?x = Some y›*) c2 (*‹Q ?x = Some ?y ⟹ ∃y. P ?x = Some y›*)) lemma dvd_reduce_multiple: fixes k :: nat shows "(k dvd k * m + n) = (k dvd n)" apply (induct m) (*goals: 1. ‹((k::nat) dvd k * (0::nat) + (n::nat)) = (k dvd n)› 2. ‹⋀m::nat. ((k::nat) dvd k * m + (n::nat)) = (k dvd n) ⟹ (k dvd k * Suc m + n) = (k dvd n)› discuss goal 1*) apply ((auto simp: add_ac (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)›*))[1]) (*discuss goal 2*) apply ((auto simp: add_ac (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)›*))[1]) (*proven 2 subgoals*) . lemma image_iff2: "inj f ⟹ f x ∈ f ` S = (x ∈ S)" by (rule inj_image_mem_iff (*‹inj ?f ⟹ (?f ?a ∈ ?f ` ?A) = (?a ∈ ?A)›*)) lemma map_comp_restrict_map_Some_iff: "((g ∘⇩m (m |` S)) x = Some y) = ((g ∘⇩m m) x = Some y ∧ x ∈ S)" by (auto simp add: map_comp_Some_iff (*‹(((?m1.0::?'b ⇒ ?'a option) ∘⇩m (?m2.0::?'c ⇒ ?'b option)) (?k::?'c) = Some (?v::?'a)) = (∃k'::?'b. ?m2.0 ?k = Some k' ∧ ?m1.0 k' = Some ?v)›*) restrict_map_Some_iff (*‹(((?m::?'b ⇒ ?'a option) |` (?S::?'b set)) (?x::?'b) = Some (?y::?'a)) = (?m ?x = Some ?y ∧ ?x ∈ ?S)›*)) lemma range_subsetD: fixes a :: "'a :: order" shows "⟦ {a..b} ⊆ {c..d}; a ≤ b ⟧ ⟹ c ≤ a ∧ b ≤ d" by simp lemma case_option_dom: "(case f x of None ⇒ a | Some v ⇒ b v) = (if x ∈ dom f then b (the (f x)) else a)" by (auto split: option.split (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))›*)) lemma contrapos_imp: "P ⟶ Q ⟹ ¬ Q ⟶ ¬ P" by clarsimp lemma filter_eq_If: "distinct xs ⟹ filter (λv. v = x) xs = (if x ∈ set xs then [x] else [])" apply (induct xs) (*goals: 1. ‹distinct [] ⟹ filter (λv. v = x) [] = (if x ∈ set [] then [x] else [])› 2. ‹⋀a xs. ⟦distinct xs ⟹ filter (λv. v = x) xs = (if x ∈ set xs then [x] else []); distinct (a # xs)⟧ ⟹ filter (λv. v = x) (a # xs) = (if x ∈ set (a # xs) then [x] else [])› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma (in semigroup_add) foldl_assoc: shows "foldl (+) (x+y) zs = x + (foldl (+) y zs)" apply (induct zs arbitrary: y) (*goals: 1. ‹⋀y::'a::type. foldl (+) ((x::'a::type) + y) [] = x + foldl (+) y []› 2. ‹⋀(a::'a::type) (zs::'a::type list) y::'a::type. (⋀y::'a::type. foldl (+) ((x::'a::type) + y) zs = x + foldl (+) y zs) ⟹ foldl (+) (x + y) (a # zs) = x + foldl (+) y (a # zs)› discuss goal 1*) apply (simp add:add.assoc (*‹(?a::'a) + (?b::'a) + (?c::'a) = ?a + (?b + ?c)›*)) (*discuss goal 2*) apply (simp add:add.assoc (*‹?a + ?b + ?c = ?a + (?b + ?c)›*)) (*proven 2 subgoals*) . lemma (in monoid_add) foldl_absorb0: shows "x + (foldl (+) 0 zs) = foldl (+) x zs" apply (induct zs) (*goals: 1. ‹(x::'a) + foldl (+) (0::'a) [] = foldl (+) x []› 2. ‹⋀(a::'a) zs::'a list. (x::'a) + foldl (+) (0::'a) zs = foldl (+) x zs ⟹ x + foldl (+) (0::'a) (a # zs) = foldl (+) x (a # zs)› discuss goal 1*) apply (simp add:foldl_assoc (*‹foldl (+) (?x + ?y) ?zs = ?x + foldl (+) ?y ?zs›*)) (*discuss goal 2*) apply (simp add:foldl_assoc (*‹foldl (+) (?x + ?y) ?zs = ?x + foldl (+) ?y ?zs›*)) (*proven 2 subgoals*) . lemma foldl_conv_concat: "foldl (@) xs xss = xs @ concat xss" proof (induct xss arbitrary: xs) (*goals: 1. ‹⋀xs. foldl (@) xs [] = xs @ concat []› 2. ‹⋀a xss xs. (⋀xs. foldl (@) xs xss = xs @ concat xss) ⟹ foldl (@) xs (a # xss) = xs @ concat (a # xss)›*) case Nil (*no hyothesis introduced yet*) show "?case" (*goal: ‹foldl (@) (xs::'a::type list) [] = xs @ concat []›*) by simp next (*goal: ‹⋀a xss xs. (⋀xs. foldl (@) xs xss = xs @ concat xss) ⟹ foldl (@) xs (a # xss) = xs @ concat (a # xss)›*) interpret monoid_add "(@)" "[]" proof (standard) (*goals: 1. ‹⋀a b c. (a @ b) @ c = a @ b @ c› 2. ‹⋀a. [] @ a = a› 3. ‹⋀a. a @ [] = a›*) qed (simp_all) (*solves the remaining goals: 1. ‹⋀a b c. (a @ b) @ c = a @ b @ c› 2. ‹⋀a. [] @ a = a› 3. ‹⋀a. a @ [] = a›*) case Cons (*‹foldl (@) ?xs1 xss_ = ?xs1 @ concat xss_›*) then show "?case" (*goal: ‹foldl (@) xs (a_ # xss_) = xs @ concat (a_ # xss_)›*) by (simp add: foldl_absorb0 (*‹?x @ foldl (@) [] ?zs = foldl (@) ?x ?zs›*)) qed lemma foldl_concat_concat: "foldl (@) [] (xs @ ys) = foldl (@) [] xs @ foldl (@) [] ys" by (simp add: foldl_conv_concat (*‹foldl (@) ?xs ?xss = ?xs @ concat ?xss›*)) lemma foldl_does_nothing: "⟦ ⋀x. x ∈ set xs ⟹ f s x = s ⟧ ⟹ foldl f s xs = s" apply (induct xs) (*goals: 1. ‹(⋀x. x ∈ set [] ⟹ f s x = s) ⟹ foldl f s [] = s› 2. ‹⋀a xs. ⟦(⋀x. x ∈ set xs ⟹ f s x = s) ⟹ foldl f s xs = s; ⋀x. x ∈ set (a # xs) ⟹ f s x = s⟧ ⟹ foldl f s (a # xs) = s› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma foldl_use_filter: "⟦ ⋀v x. ⟦ ¬ g x; x ∈ set xs ⟧ ⟹ f v x = v ⟧ ⟹ foldl f v xs = foldl f v (filter g xs)" apply (induct xs arbitrary: v) (*goals: 1. ‹⋀v::'a. (⋀(v::'a) x::'b. ⟦¬ (g::'b ⇒ bool) x; x ∈ set []⟧ ⟹ (f::'a ⇒ 'b ⇒ 'a) v x = v) ⟹ foldl f v [] = foldl f v (filter g [])› 2. ‹⋀(a::'b) (xs::'b list) v::'a. ⟦⋀v::'a. (⋀(v::'a) x::'b. ⟦¬ (g::'b ⇒ bool) x; x ∈ set xs⟧ ⟹ (f::'a ⇒ 'b ⇒ 'a) v x = v) ⟹ foldl f v xs = foldl f v (filter g xs); ⋀(v::'a) x::'b. ⟦¬ g x; x ∈ set (a # xs)⟧ ⟹ f v x = v⟧ ⟹ foldl f v (a # xs) = foldl f v (filter g (a # xs))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma map_comp_update_lift: assumes fv: "f v = Some v'" shows "(f ∘⇩m (g(ptr ↦ v))) = ((f ∘⇩m g)(ptr ↦ v'))" by (simp add: fv (*‹f v = Some v'›*) map_comp_update (*‹?f ∘⇩m ?g(?x ↦ ?v) = (?f ∘⇩m ?g)(?x := ?f ?v)›*)) lemma restrict_map_cong: assumes sv: "S = S'" and rl: "⋀p. p ∈ S' ⟹ mp p = mp' p" shows "mp |` S = mp' |` S'" using expand_restrict_map_eq (*‹(?m |` ?S = ?m' |` ?S) = (∀x. x ∈ ?S ⟶ ?m x = ?m' x)›*) rl (*‹?p ∈ S' ⟹ mp ?p = mp' ?p›*) sv (*‹S = S'›*) by auto lemma case_option_over_if: "case_option P Q (if G then None else Some v) = (if G then P else Q v)" "case_option P Q (if G then Some v else None) = (if G then Q v else P)" (*goals: 1. ‹(case if G then None else Some v of None ⇒ P | Some x ⇒ Q x) = (if G then P else Q v)› 2. ‹(case if G then Some v else None of None ⇒ P | Some x ⇒ Q x) = (if G then Q v else P)› discuss goal 1*) apply (simp split: if_split (*‹(?P::?'a::type ⇒ bool) (if ?Q::bool then ?x::?'a::type else (?y::?'a::type)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))›*)) (*discuss goal 2*) apply (simp split: if_split (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))›*)) (*proven 2 subgoals*) . lemma map_length_cong: "⟦ length xs = length ys; ⋀x y. (x, y) ∈ set (zip xs ys) ⟹ f x = g y ⟧ ⟹ map f xs = map g ys" apply atomize (*goal: ‹⟦length xs = length ys; ⋀x y. (x, y) ∈ set (zip xs ys) ⟹ f x = g y⟧ ⟹ map f xs = map g ys›*) apply (erule rev_mp (*‹⟦?P; ?P ⟶ ?Q⟧ ⟹ ?Q›*), erule list_induct2 (*‹⟦length ?xs = length ?ys; ?P [] []; ⋀x xs y ys. ⟦length xs = length ys; ?P xs ys⟧ ⟹ ?P (x # xs) (y # ys)⟧ ⟹ ?P ?xs ?ys›*)) (*goal: ‹⟦length xs = length ys; ∀x y. (x, y) ∈ set (zip xs ys) ⟶ f x = g y⟧ ⟹ map f xs = map g ys›*) by auto lemma take_min_len: "take (min (length xs) n) xs = take n xs" by (simp add: min_def (*‹min ?a ?b = (if ?a ≤ ?b then ?a else ?b)›*)) lemmas interval_empty = atLeastatMost_empty_iff lemma fold_and_false[simp]: "¬(fold (∧) xs False)" apply clarsimp (*goal: ‹¬ fold (∧) xs False›*) apply (induct xs) (*goals: 1. ‹fold (∧) [] False ⟹ False› 2. ‹⋀a xs. ⟦fold (∧) xs False ⟹ False; fold (∧) (a # xs) False⟧ ⟹ False› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma fold_and_true: "fold (∧) xs True ⟹ ∀i < length xs. xs ! i" apply clarsimp (*goal: ‹fold (∧) (xs::bool list) True ⟹ ∀i<length xs. xs ! i›*) apply (induct xs) (*goal: ‹⋀i. ⟦fold (∧) xs True; i < length xs⟧ ⟹ xs ! i›*) apply simp (*top goal: ‹⋀i. ⟦fold (∧) [] True; i < length []⟧ ⟹ [] ! i› and 1 goal remains*) subgoal for a and xs and i apply ((cases "i = 0")[1]) (*goals: 1. ‹⟦⋀i::nat. ⟦fold (∧) (xs::bool list) True; i < length xs⟧ ⟹ xs ! i; fold (∧) ((a::bool) # xs) True; (i::nat) < length (a # xs); i = (0::nat)⟧ ⟹ (a # xs) ! i› 2. ‹⟦⋀i::nat. ⟦fold (∧) (xs::bool list) True; i < length xs⟧ ⟹ xs ! i; fold (∧) ((a::bool) # xs) True; (i::nat) < length (a # xs); i ≠ (0::nat)⟧ ⟹ (a # xs) ! i› discuss goal 1*) apply ((cases a)[1]) (*goals: 1. ‹⟦⋀i. ⟦fold (∧) xs True; i < length xs⟧ ⟹ xs ! i; fold (∧) (a # xs) True; i < length (a # xs); i = 0; a⟧ ⟹ (a # xs) ! i› 2. ‹⟦⋀i. ⟦fold (∧) xs True; i < length xs⟧ ⟹ xs ! i; fold (∧) (a # xs) True; i < length (a # xs); i = 0; ¬ a⟧ ⟹ (a # xs) ! i› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply ((cases a)[1]) (*goals: 1. ‹⟦⋀i. ⟦fold (∧) xs True; i < length xs⟧ ⟹ xs ! i; fold (∧) (a # xs) True; i < length (a # xs); i ≠ 0; a⟧ ⟹ (a # xs) ! i› 2. ‹⟦⋀i. ⟦fold (∧) xs True; i < length xs⟧ ⟹ xs ! i; fold (∧) (a # xs) True; i < length (a # xs); i ≠ 0; ¬ a⟧ ⟹ (a # xs) ! i› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) . . lemma fold_or_true[simp]: "fold (∨) xs True" apply (induct xs) (*goals: 1. ‹fold (∨) [] True› 2. ‹⋀a xs. fold (∨) xs True ⟹ fold (∨) (a # xs) True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma fold_or_false: "¬(fold (∨) xs False) ⟹ ∀i < length xs. ¬(xs ! i)" apply (induct xs, (simp)+) (*goal: ‹¬ fold (∨) xs False ⟹ ∀i<length xs. ¬ xs ! i›*) subgoal for a and xs apply (cases a, (simp)+) (*goal: ‹⟦¬ fold (∨) xs False ⟹ ∀i<length xs. ¬ xs ! i; ¬ fold (∨) xs a⟧ ⟹ ∀i<Suc (length xs). ¬ (a # xs) ! i›*) apply (rule allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*)) (*goal: ‹⟦∀i<length xs. ¬ xs ! i; ¬ fold (∨) xs False; ¬ a⟧ ⟹ ∀i<Suc (length xs). ¬ (False # xs) ! i›*) subgoal for i apply (cases "i = 0") (*goals: 1. ‹⟦∀i<length xs. ¬ xs ! i; ¬ fold (∨) xs False; ¬ a; i = 0⟧ ⟹ i < Suc (length xs) ⟶ ¬ (False # xs) ! i› 2. ‹⟦∀i<length xs. ¬ xs ! i; ¬ fold (∨) xs False; ¬ a; i ≠ 0⟧ ⟹ i < Suc (length xs) ⟶ ¬ (False # xs) ! i› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . . . section ‹ Take, drop, zip, ‹list_all› etc rules › method two_induct for xs ys = ((induct xs arbitrary: ys; simp?), (case_tac ys; simp)?) lemma map_fst_zip_prefix: "map fst (zip xs ys) ≤ xs" by (two_induct xs ys) lemma map_snd_zip_prefix: "map snd (zip xs ys) ≤ ys" by (two_induct xs ys) lemma nth_upt_0 [simp]: "i < length xs ⟹ [0..<length xs] ! i = i" by simp lemma take_insert_nth: "i < length xs⟹ insert (xs ! i) (set (take i xs)) = set (take (Suc i) xs)" apply (subst take_Suc_conv_app_nth (*‹(?i::nat) < length (?xs::?'a::type list) ⟹ take (Suc ?i) ?xs = take ?i ?xs @ [?xs ! ?i]›*)) (*goals: 1. ‹i < length xs ⟹ i < length xs› 2. ‹i < length xs ⟹ insert (xs ! i) (set (take i xs)) = set (take i xs @ [xs ! i])› discuss goal 1*) apply assumption (*discuss goal 2*) apply fastforce (*proven 2 subgoals*) . lemma zip_take_drop: "⟦n < length xs; length ys = length xs⟧ ⟹ zip xs (take n ys @ a # drop (Suc n) ys) = zip (take n xs) (take n ys) @ (xs ! n, a) # zip (drop (Suc n) xs) (drop (Suc n) ys)" apply (subst id_take_nth_drop (*‹?i < length ?xs ⟹ ?xs = take ?i ?xs @ ?xs ! ?i # drop (Suc ?i) ?xs›*)) (*goals: 1. ‹⟦n < length xs; length ys = length xs⟧ ⟹ ?i < length xs› 2. ‹⟦n < length xs; length ys = length xs⟧ ⟹ zip (take ?i xs @ xs ! ?i # drop (Suc ?i) xs) (take n ys @ a # drop (Suc n) ys) = zip (take n xs) (take n ys) @ (xs ! n, a) # zip (drop (Suc n) xs) (drop (Suc n) ys)› discuss goal 1*) apply assumption (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma take_nth_distinct: "⟦distinct xs; n < length xs; xs ! n ∈ set (take n xs)⟧ ⟹ False" by (fastforce simp: distinct_conv_nth (*‹distinct (?xs::?'a list) = (∀i<length ?xs. ∀j<length ?xs. i ≠ j ⟶ ?xs ! i ≠ ?xs ! j)›*) in_set_conv_nth (*‹((?x::?'a) ∈ set (?xs::?'a list)) = (∃i<length ?xs. ?xs ! i = ?x)›*)) lemma take_drop_append: "drop a xs = take b (drop a xs) @ drop (a + b) xs" by (metis append_take_drop_id (*‹take ?n ?xs @ drop ?n ?xs = ?xs›*) drop_drop (*‹drop ?n (drop ?m ?xs) = drop (?n + ?m) ?xs›*) add.commute (*‹?a + ?b = ?b + ?a›*)) lemma drop_take_drop: "drop a (take (b + a) xs) @ drop (b + a) xs = drop a xs" by (metis add.commute (*‹?a + ?b = ?b + ?a›*) take_drop (*‹take ?n (drop ?m ?xs) = drop ?m (take (?n + ?m) ?xs)›*) take_drop_append (*‹drop ?a ?xs = take ?b (drop ?a ?xs) @ drop (?a + ?b) ?xs›*)) lemma not_prefixI: "⟦ xs ≠ ys; length xs = length ys⟧ ⟹ ¬ xs ≤ ys" by (auto elim: prefixE (*‹⟦?xs ≤ ?ys; ⋀zs. ?ys = ?xs @ zs ⟹ ?thesis⟧ ⟹ ?thesis›*)) lemma map_fst_zip': "length xs ≤ length ys ⟹ map fst (zip xs ys) = xs" by (metis length_map (*‹length (map ?f ?xs) = length ?xs›*) length_zip (*‹length (zip ?xs ?ys) = min (length ?xs) (length ?ys)›*) map_fst_zip_prefix (*‹map fst (zip ?xs ?ys) ≤ ?xs›*) min_absorb1 (*‹?x ≤ ?y ⟹ min ?x ?y = ?x›*) not_prefixI (*‹⟦?xs ≠ ?ys; length ?xs = length ?ys⟧ ⟹ ¬ ?xs ≤ ?ys›*)) lemma zip_take_triv: "n ≥ length bs ⟹ zip (take n as) bs = zip as bs" apply (induct bs arbitrary: n as; simp) (*goal: ‹length bs ≤ n ⟹ zip (take n as) bs = zip as bs›*) subgoal for a and bs and n and as apply (cases n) (*goals: 1. ‹⟦⋀n as. length bs ≤ n ⟹ zip (take n as) bs = zip as bs; Suc (length bs) ≤ n; n = 0⟧ ⟹ zip (take n as) (a # bs) = zip as (a # bs)› 2. ‹⋀nat. ⟦⋀n as. length bs ≤ n ⟹ zip (take n as) bs = zip as bs; Suc (length bs) ≤ n; n = Suc nat⟧ ⟹ zip (take n as) (a # bs) = zip as (a # bs)› discuss goal 1*) apply (cases "as") (*goals: 1. ‹⟦⋀n as. length bs ≤ n ⟹ zip (take n as) bs = zip as bs; Suc (length bs) ≤ n; n = 0; as = []⟧ ⟹ zip (take n as) (a # bs) = zip as (a # bs)› 2. ‹⋀aa list. ⟦⋀n as. length bs ≤ n ⟹ zip (take n as) bs = zip as bs; Suc (length bs) ≤ n; n = 0; as = aa # list⟧ ⟹ zip (take n as) (a # bs) = zip as (a # bs)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "as") (*goals: 1. ‹⋀nat. ⟦⋀n as. length bs ≤ n ⟹ zip (take n as) bs = zip as bs; Suc (length bs) ≤ n; n = Suc nat; as = []⟧ ⟹ zip (take n as) (a # bs) = zip as (a # bs)› 2. ‹⋀nat aa list. ⟦⋀n as. length bs ≤ n ⟹ zip (take n as) bs = zip as bs; Suc (length bs) ≤ n; n = Suc nat; as = aa # list⟧ ⟹ zip (take n as) (a # bs) = zip as (a # bs)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) . . lemma zip_take_triv2: "length as ≤ n ⟹ zip as (take n bs) = zip as bs" apply (induct as arbitrary: n bs; simp) (*goal: ‹length (as::'a list) ≤ (n::nat) ⟹ zip as (take n (bs::'b list)) = zip as bs›*) subgoal for a and bs and n and as apply (cases n) (*goals: 1. ‹⟦⋀(n::nat) bs::'b list. length (bs::'a list) ≤ n ⟹ zip bs (take n bs) = zip bs bs; Suc (length bs) ≤ (n::nat); n = (0::nat)⟧ ⟹ zip ((a::'a) # bs) (take n (as::'b list)) = zip (a # bs) as› 2. ‹⋀nat::nat. ⟦⋀(n::nat) bs::'b list. length (bs::'a list) ≤ n ⟹ zip bs (take n bs) = zip bs bs; Suc (length bs) ≤ (n::nat); n = Suc nat⟧ ⟹ zip ((a::'a) # bs) (take n (as::'b list)) = zip (a # bs) as› discuss goal 1*) apply (cases "as") (*goals: 1. ‹⟦⋀n bs. length bs ≤ n ⟹ zip bs (take n bs) = zip bs bs; Suc (length bs) ≤ n; n = 0; as = []⟧ ⟹ zip (a # bs) (take n as) = zip (a # bs) as› 2. ‹⋀aa list. ⟦⋀n bs. length bs ≤ n ⟹ zip bs (take n bs) = zip bs bs; Suc (length bs) ≤ n; n = 0; as = aa # list⟧ ⟹ zip (a # bs) (take n as) = zip (a # bs) as› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "as") (*goals: 1. ‹⋀nat. ⟦⋀n bs. length bs ≤ n ⟹ zip bs (take n bs) = zip bs bs; Suc (length bs) ≤ n; n = Suc nat; as = []⟧ ⟹ zip (a # bs) (take n as) = zip (a # bs) as› 2. ‹⋀nat aa list. ⟦⋀n bs. length bs ≤ n ⟹ zip bs (take n bs) = zip bs bs; Suc (length bs) ≤ n; n = Suc nat; as = aa # list⟧ ⟹ zip (a # bs) (take n as) = zip (a # bs) as› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) . . lemma zip_take_length: "zip xs (take (length xs) ys) = zip xs ys" by (metis order_refl (*‹?x ≤ ?x›*) zip_take_triv2 (*‹length ?as ≤ ?n ⟹ zip ?as (take ?n ?bs) = zip ?as ?bs›*)) lemma zip_singleton: "ys ≠ [] ⟹ zip [a] ys = [(a, ys ! 0)]" apply (cases ys) (*goals: 1. ‹⟦ys ≠ []; ys = []⟧ ⟹ zip [a] ys = [(a, ys ! 0)]› 2. ‹⋀aa list. ⟦ys ≠ []; ys = aa # list⟧ ⟹ zip [a] ys = [(a, ys ! 0)]› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma zip_append_singleton: "⟦i = length xs; length xs < length ys⟧ ⟹ zip (xs @ [a]) ys = (zip xs ys) @ [(a,ys ! i)]" apply (induct xs) (*goals: 1. ‹⟦i = length []; length [] < length ys⟧ ⟹ zip ([] @ [a]) ys = zip [] ys @ [(a, ys ! i)]› 2. ‹⋀aa xs. ⟦⟦i = length xs; length xs < length ys⟧ ⟹ zip (xs @ [a]) ys = zip xs ys @ [(a, ys ! i)]; i = length (aa # xs); length (aa # xs) < length ys⟧ ⟹ zip ((aa # xs) @ [a]) ys = zip (aa # xs) ys @ [(a, ys ! i)]› discuss goal 1*) apply (cases ys) (*goals: 1. ‹⟦i = length []; length [] < length ys; ys = []⟧ ⟹ zip ([] @ [a]) ys = zip [] ys @ [(a, ys ! i)]› 2. ‹⋀aa list. ⟦i = length []; length [] < length ys; ys = aa # list⟧ ⟹ zip ([] @ [a]) ys = zip [] ys @ [(a, ys ! i)]› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases ys) (*goals: 1. ‹⋀aa xs. ⟦⟦i = length xs; length xs < length ys⟧ ⟹ zip (xs @ [a]) ys = zip xs ys @ [(a, ys ! i)]; i = length (aa # xs); length (aa # xs) < length ys; ys = []⟧ ⟹ zip ((aa # xs) @ [a]) ys = zip (aa # xs) ys @ [(a, ys ! i)]› 2. ‹⋀aa xs aaa list. ⟦⟦i = length xs; length xs < length ys⟧ ⟹ zip (xs @ [a]) ys = zip xs ys @ [(a, ys ! i)]; i = length (aa # xs); length (aa # xs) < length ys; ys = aaa # list⟧ ⟹ zip ((aa # xs) @ [a]) ys = zip (aa # xs) ys @ [(a, ys ! i)]› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*goal: ‹⋀(aa::'a) (xs::'a list) (aaa::'b) list::'b list. ⟦⟦(i::nat) = length xs; length xs < length (ys::'b list)⟧ ⟹ zip (xs @ [a::'a]) ys = zip xs ys @ [(a, ys ! i)]; i = length (aa # xs); length (aa # xs) < length ys; ys = aaa # list⟧ ⟹ zip ((aa # xs) @ [a]) ys = zip (aa # xs) ys @ [(a, ys ! i)]›*) apply (clarsimp simp: zip_append1 (*‹zip (?xs @ ?ys) ?zs = zip ?xs (take (length ?xs) ?zs) @ zip ?ys (drop (length ?xs) ?zs)›*) zip_take_length (*‹zip ?xs (take (length ?xs) ?ys) = zip ?xs ?ys›*) zip_singleton (*‹?ys ≠ [] ⟹ zip [?a] ?ys = [(?a, ?ys ! 0)]›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma ranE: "⟦ v ∈ ran f; ⋀x. f x = Some v ⟹ R⟧ ⟹ R" by (auto simp: ran_def (*‹ran ?m = {b. ∃a. ?m a = Some b}›*)) lemma ran_map_option_restrict_eq: "⟦ x ∈ ran (map_option f o g); x ∉ ran (map_option f o (g |` (- {y}))) ⟧ ⟹ ∃v. g y = Some v ∧ f v = x" apply (clarsimp simp: elim!: ranE (*‹⟦(?v::?'a) ∈ ran (?f::?'b ⇒ ?'a option); ⋀x::?'b. ?f x = Some ?v ⟹ ?R::bool⟧ ⟹ ?R›*)) (*goal: ‹⟦(x::'a) ∈ ran (map_option (f::'c ⇒ 'a) ∘ (g::'b ⇒ 'c option)); x ∉ ran (map_option f ∘ g |` (- {y::'b}))⟧ ⟹ ∃v::'c. g y = Some v ∧ f v = x›*) subgoal for w and z apply (cases "w = y") (*goals: 1. ‹⟦f z ∉ ran (map_option f ∘ g |` (- {y})); g w = Some z; x = f z; w = y⟧ ⟹ ∃v. g y = Some v ∧ f v = f z› 2. ‹⟦f z ∉ ran (map_option f ∘ g |` (- {y})); g w = Some z; x = f z; w ≠ y⟧ ⟹ ∃v. g y = Some v ∧ f v = f z› discuss goal 1*) apply clarsimp (*discuss goal 2*) apply (erule notE (*‹⟦¬ ?P; ?P⟧ ⟹ ?R›*)) (*goal: ‹⟦f z ∉ ran (map_option f ∘ g |` (- {y})); g w = Some z; x = f z; w ≠ y⟧ ⟹ ∃v. g y = Some v ∧ f v = f z›*) apply (rule ranI[where a=w] (*‹(?m::'b::type ⇒ ?'a::type option) (w::'b::type) = Some (?b::?'a::type) ⟹ ?b ∈ ran ?m›*)) (*goal: ‹⟦g w = Some z; x = f z; w ≠ y⟧ ⟹ f z ∈ ran (map_option f ∘ g |` (- {y}))›*) apply (simp add: restrict_map_def (*‹?m |` ?A = (λx. if x ∈ ?A then ?m x else None)›*)) (*proven 2 subgoals*) . . lemma map_of_zip_range: "⟦length xs = length ys; distinct xs⟧ ⟹ (λx. (the (map_of (zip xs ys) x))) ` set xs = set ys" apply (clarsimp simp: image_def (*‹?f ` ?A = {y. ∃x∈?A. y = ?f x}›*)) (*goal: ‹⟦length xs = length ys; distinct xs⟧ ⟹ (λx. the (map_of (zip xs ys) x)) ` set xs = set ys›*) apply (subst ran_map_of_zip [symmetric, where xs=xs and ys=ys] (*‹⟦length xs = length ys; distinct xs⟧ ⟹ set ys = ran (map_of (zip xs ys))›*)) (*goals: 1. ‹⟦length xs = length ys; distinct xs⟧ ⟹ length xs = length ys› 2. ‹⟦length xs = length ys; distinct xs⟧ ⟹ distinct xs› 3. ‹⟦length xs = length ys; distinct xs⟧ ⟹ {y. ∃x∈set xs. y = the (map_of (zip xs ys) x)} = ran (map_of (zip xs ys))› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (clarsimp simp: ran_def (*‹ran ?m = {b. ∃a. ?m a = Some b}›*)) (*goal: ‹⟦length xs = length ys; distinct xs⟧ ⟹ {y. ∃x∈set xs. y = the (map_of (zip xs ys) x)} = ran (map_of (zip xs ys))›*) apply (rule equalityI (*‹⟦?A ⊆ ?B; ?B ⊆ ?A⟧ ⟹ ?A = ?B›*)) (*goals: 1. ‹⟦length (xs::'a list) = length (ys::'b list); distinct xs⟧ ⟹ {y::'b. ∃x::'a∈set xs. y = the (map_of (zip xs ys) x)} ⊆ {b::'b. ∃a::'a. (a, b) ∈ set (zip xs ys)}› 2. ‹⟦length (xs::'a list) = length (ys::'b list); distinct xs⟧ ⟹ {b::'b. ∃a::'a. (a, b) ∈ set (zip xs ys)} ⊆ {y::'b. ∃x::'a∈set xs. y = the (map_of (zip xs ys) x)}› discuss goal 1*) apply clarsimp (*top goal: ‹⟦length (xs::'a::type list) = length (ys::'b::type list); distinct xs⟧ ⟹ {y::'b::type. ∃x::'a::type∈set xs. y = the (map_of (zip xs ys) x)} ⊆ {b::'b::type. ∃a::'a::type. (a, b) ∈ set (zip xs ys)}› and 1 goal remains*) apply (rename_tac x) (*top goal: ‹⋀xa::'a. ⟦length (xs::'a list) = length (ys::'b list); distinct xs; xa ∈ set xs⟧ ⟹ ∃a::'a. (a, the (map_of (zip xs ys) xa)) ∈ set (zip xs ys)› and 1 goal remains*) apply (frule_tac x=x in map_of_zip_is_Some (*‹length ?xs = length ?ys ⟹ (?x ∈ set ?xs) = (∃y. map_of (zip ?xs ?ys) ?x = Some y)›*)) (*top goal: ‹⋀x. ⟦length xs = length ys; distinct xs; x ∈ set xs⟧ ⟹ ∃a. (a, the (map_of (zip xs ys) x)) ∈ set (zip xs ys)› and 1 goal remains*) apply fastforce (*discuss goal 2*) apply (clarsimp simp: set_zip (*‹set (zip ?xs ?ys) = {(?xs ! i, ?ys ! i) |i. i < min (length ?xs) (length ?ys)}›*)) (*goal: ‹⟦length xs = length ys; distinct xs⟧ ⟹ {b. ∃a. (a, b) ∈ set (zip xs ys)} ⊆ {y. ∃x∈set xs. y = the (map_of (zip xs ys) x)}›*) apply (metis domI (*‹?m ?a = Some ?b ⟹ ?a ∈ dom ?m›*) dom_map_of_zip (*‹length ?xs = length ?ys ⟹ dom (map_of (zip ?xs ?ys)) = set ?xs›*) nth_mem (*‹?n < length ?xs ⟹ ?xs ! ?n ∈ set ?xs›*) ranE (*‹⟦?v ∈ ran ?f; ⋀x. ?f x = Some ?v ⟹ ?R⟧ ⟹ ?R›*) ran_map_of_zip (*‹⟦length ?xs = length ?ys; distinct ?xs⟧ ⟹ ran (map_of (zip ?xs ?ys)) = set ?ys›*) option.sel (*‹the (Some ?x2.0) = ?x2.0›*)) (*proven 2 subgoals*) (*proven 3 subgoals*) . lemma map_zip_fst: "length xs = length ys ⟹ map (λ(x, y). f x) (zip xs ys) = map f xs" by (two_induct xs ys) lemma map_zip_fst': "length xs ≤ length ys ⟹ map (λ(x, y). f x) (zip xs ys) = map f xs" by (metis length_map (*‹length (map ?f ?xs) = length ?xs›*) map_fst_zip' (*‹length ?xs ≤ length ?ys ⟹ map fst (zip ?xs ?ys) = ?xs›*) map_zip_fst (*‹length ?xs = length ?ys ⟹ map2 (λx y. ?f x) ?xs ?ys = map ?f ?xs›*) zip_map_fst_snd (*‹zip (map fst ?zs) (map snd ?zs) = ?zs›*)) lemma map_zip_snd: "length xs = length ys ⟹ map (λ(x, y). f y) (zip xs ys) = map f ys" by (two_induct xs ys) lemma map_zip_snd': "length ys ≤ length xs ⟹ map (λ(x, y). f y) (zip xs ys) = map f ys" by (two_induct xs ys) lemma map_of_zip_tuple_in: "⟦(x, y) ∈ set (zip xs ys); distinct xs⟧ ⟹ map_of (zip xs ys) x = Some y" apply (two_induct xs ys) (*goal: ‹⟦(x::'a, y::'b) ∈ set (zip (xs::'a list) (ys::'b list)); distinct xs⟧ ⟹ map_of (zip xs ys) x = Some y›*) by (auto intro: in_set_zipE (*‹⟦(?x, ?y) ∈ set (zip ?xs ?ys); ⟦?x ∈ set ?xs; ?y ∈ set ?ys⟧ ⟹ ?R⟧ ⟹ ?R›*)) lemma in_set_zip1: "(x, y) ∈ set (zip xs ys) ⟹ x ∈ set xs" by (erule in_set_zipE (*‹⟦(?x, ?y) ∈ set (zip ?xs ?ys); ⟦?x ∈ set ?xs; ?y ∈ set ?ys⟧ ⟹ ?R⟧ ⟹ ?R›*)) lemma in_set_zip2: "(x, y) ∈ set (zip xs ys) ⟹ y ∈ set ys" by (erule in_set_zipE (*‹⟦(?x, ?y) ∈ set (zip ?xs ?ys); ⟦?x ∈ set ?xs; ?y ∈ set ?ys⟧ ⟹ ?R⟧ ⟹ ?R›*)) lemma map_zip_snd_take: "map (λ(x, y). f y) (zip xs ys) = map f (take (length xs) ys)" apply (subst map_zip_snd' [symmetric, where xs=xs and ys="take (length xs) ys"] (*‹length (take (length xs) ys) ≤ length xs ⟹ map ?f (take (length xs) ys) = map2 (λx. ?f) xs (take (length xs) ys)›*)) (*goals: 1. ‹length (take (length xs) ys) ≤ length xs› 2. ‹map2 (λx. f) xs ys = map2 (λx. f) xs (take (length xs) ys)› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst zip_take_length [symmetric] (*‹zip ?xs ?ys = zip ?xs (take (length ?xs) ?ys)›*)) (*goal: ‹map2 (λx. f) xs ys = map2 (λx. f) xs (take (length xs) ys)›*) apply simp (*proven 2 subgoals*) . lemma map_of_zip_is_index: "⟦length xs = length ys; x ∈ set xs⟧ ⟹ ∃i. (map_of (zip xs ys)) x = Some (ys ! i)" apply (induct rule: list_induct2 (*‹⟦length ?xs = length ?ys; ?P [] []; ⋀x xs y ys. ⟦length xs = length ys; ?P xs ys⟧ ⟹ ?P (x # xs) (y # ys)⟧ ⟹ ?P ?xs ?ys›*)) (*goals: 1. ‹x ∈ set [] ⟹ ∃i. map_of (zip [] []) x = Some ([] ! i)› 2. ‹⋀xa xs y ys. ⟦length xs = length ys; x ∈ set xs ⟹ ∃i. map_of (zip xs ys) x = Some (ys ! i); x ∈ set (xa # xs)⟧ ⟹ ∃i. map_of (zip (xa # xs) (y # ys)) x = Some ((y # ys) ! i)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*goal: ‹⋀xa xs y ys. ⟦length xs = length ys; x ∈ set xs ⟹ ∃i. map_of (zip xs ys) x = Some (ys ! i); x ∈ set (xa # xs)⟧ ⟹ ∃i. map_of (zip (xa # xs) (y # ys)) x = Some ((y # ys) ! i)›*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹⋀xa xs y ys. ⟦length xs = length ys; x ∈ set xs ⟹ ∃i. map_of (zip xs ys) x = Some (ys ! i); x = xa ∨ x ∈ set xs⟧ ⟹ x = xa ⟶ (∃i. y = (y # ys) ! i)› 2. ‹⋀xa xs y ys. ⟦length xs = length ys; x ∈ set xs ⟹ ∃i. map_of (zip xs ys) x = Some (ys ! i); x = xa ∨ x ∈ set xs⟧ ⟹ x ≠ xa ⟶ (∃i. map_of (zip xs ys) x = Some ((y # ys) ! i))› discuss goal 1*) apply clarsimp (*top goal: ‹⋀xa xs y ys. ⟦length xs = length ys; x ∈ set xs ⟹ ∃i. map_of (zip xs ys) x = Some (ys ! i); x = xa ∨ x ∈ set xs⟧ ⟹ x = xa ⟶ (∃i. y = (y # ys) ! i)› and 1 goal remains*) apply (metis nth_Cons_0 (*‹(?x # ?xs) ! 0 = ?x›*)) (*discuss goal 2*) apply clarsimp (*goal: ‹⋀xa xs y ys. ⟦length xs = length ys; x ∈ set xs ⟹ ∃i. map_of (zip xs ys) x = Some (ys ! i); x = xa ∨ x ∈ set xs⟧ ⟹ x ≠ xa ⟶ (∃i. map_of (zip xs ys) x = Some ((y # ys) ! i))›*) apply (metis nth_Cons_Suc (*‹(?x # ?xs) ! Suc ?n = ?xs ! ?n›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma map_of_zip_take_update: "⟦i < length xs; length xs ≤ length ys; distinct xs⟧ ⟹ (map_of (zip (take i xs) ys))(xs ! i ↦ (ys ! i)) = map_of (zip (take (Suc i) xs) ys)" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹⟦(i::nat) < length (xs::'a list); length xs ≤ length (ys::'b list); distinct xs⟧ ⟹ (map_of (zip (take i xs) ys))(xs ! i ↦ ys ! i) = map_of (zip (take (Suc i) xs) ys)›*) subgoal for x apply (cases "x=xs ! i") (*goals: 1. ‹⟦i < length xs; length xs ≤ length ys; distinct xs; x = xs ! i⟧ ⟹ ((map_of (zip (take i xs) ys))(xs ! i ↦ ys ! i)) x = map_of (zip (take (Suc i) xs) ys) x› 2. ‹⟦i < length xs; length xs ≤ length ys; distinct xs; x ≠ xs ! i⟧ ⟹ ((map_of (zip (take i xs) ys))(xs ! i ↦ ys ! i)) x = map_of (zip (take (Suc i) xs) ys) x› discuss goal 1*) apply clarsimp (*top goal: ‹⟦(i::nat) < length (xs::'a list); length xs ≤ length (ys::'b list); distinct xs; (x::'a) = xs ! i⟧ ⟹ ((map_of (zip (take i xs) ys))(xs ! i ↦ ys ! i)) x = map_of (zip (take (Suc i) xs) ys) x› and 1 goal remains*) apply (rule map_of_is_SomeI[symmetric] (*‹⟦distinct (map fst ?xys); (?x, ?y) ∈ set ?xys⟧ ⟹ Some ?y = map_of ?xys ?x›*)) (*goals: 1. ‹⟦i < length xs; length xs ≤ length ys; distinct xs; x = xs ! i⟧ ⟹ distinct (map fst (zip (take (Suc i) xs) ys))› 2. ‹⟦i < length xs; length xs ≤ length ys; distinct xs; x = xs ! i⟧ ⟹ (xs ! i, ys ! i) ∈ set (zip (take (Suc i) xs) ys)› discuss goal 1*) apply (simp add: map_fst_zip' (*‹length ?xs ≤ length ?ys ⟹ map fst (zip ?xs ?ys) = ?xs›*)) (*discuss goal 2*) apply (force simp add: set_zip (*‹set (zip ?xs ?ys) = {(?xs ! i, ?ys ! i) |i. i < min (length ?xs) (length ?ys)}›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply clarsimp (*goal: ‹⟦i < length xs; length xs ≤ length ys; distinct xs; x ≠ xs ! i⟧ ⟹ ((map_of (zip (take i xs) ys))(xs ! i ↦ ys ! i)) x = map_of (zip (take (Suc i) xs) ys) x›*) apply (clarsimp simp: take_Suc_conv_app_nth (*‹?i < length ?xs ⟹ take (Suc ?i) ?xs = take ?i ?xs @ [?xs ! ?i]›*) zip_append_singleton (*‹⟦?i = length ?xs; length ?xs < length ?ys⟧ ⟹ zip (?xs @ [?a]) ?ys = zip ?xs ?ys @ [(?a, ?ys ! ?i)]›*) map_add_def (*‹?m1.0 ++ ?m2.0 = (λx. case ?m2.0 x of None ⇒ ?m1.0 x | Some y ⇒ Some y)›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) (*proven 2 subgoals*) . . (* A weaker version of map_of_zip_is_Some (from HOL). *) lemma map_of_zip_is_Some': "length xs ≤ length ys ⟹ (x ∈ set xs) = (∃y. map_of (zip xs ys) x = Some y)" apply (subst zip_take_length[symmetric] (*‹zip (?xs::?'a list) (?ys::?'b list) = zip ?xs (take (length ?xs) ?ys)›*)) (*goal: ‹length xs ≤ length ys ⟹ (x ∈ set xs) = (∃y. map_of (zip xs ys) x = Some y)›*) apply (rule map_of_zip_is_Some (*‹length (?xs::?'a list) = length (?ys::?'b list) ⟹ ((?x::?'a) ∈ set ?xs) = (∃y::?'b. map_of (zip ?xs ?ys) ?x = Some y)›*)) (*goal: ‹length xs ≤ length ys ⟹ (x ∈ set xs) = (∃y. map_of (zip xs (take (length xs) ys)) x = Some y)›*) by (metis length_take (*‹length (take ?n ?xs) = min (length ?xs) ?n›*) min_absorb2 (*‹?y ≤ ?x ⟹ min ?x ?y = ?y›*)) lemma map_of_zip_inj: "⟦distinct xs; distinct ys; length xs = length ys⟧ ⟹ inj_on (λx. (the (map_of (zip xs ys) x))) (set xs)" apply (clarsimp simp: inj_on_def (*‹inj_on (?f::?'a ⇒ ?'b) (?A::?'a set) = (∀x::?'a∈?A. ∀y::?'a∈?A. ?f x = ?f y ⟶ x = y)›*)) (*goal: ‹⟦distinct xs; distinct ys; length xs = length ys⟧ ⟹ inj_on (λx. the (map_of (zip xs ys) x)) (set xs)›*) apply (subst (asm) map_of_zip_is_Some (*‹length ?xs = length ?ys ⟹ (?x ∈ set ?xs) = (∃y. map_of (zip ?xs ?ys) ?x = Some y)›*)) (*goals: 1. ‹⋀x y. ⟦y ∈ set xs; the (map_of (zip xs ys) x) = the (map_of (zip xs ys) y); distinct xs; distinct ys; length xs = length ys⟧ ⟹ length xs = length (?ys7 x y)› 2. ‹⋀x y. ⟦distinct xs; distinct ys; length xs = length ys; ∃ya. map_of (zip xs (?ys7 x y)) x = Some ya; y ∈ set xs; the (map_of (zip xs ys) x) = the (map_of (zip xs ys) y)⟧ ⟹ x = y› discuss goal 1*) apply assumption (*discuss goal 2*) apply (subst (asm) map_of_zip_is_Some (*‹length ?xs = length ?ys ⟹ (?x ∈ set ?xs) = (∃y. map_of (zip ?xs ?ys) ?x = Some y)›*)) (*goals: 1. ‹⋀x y. ⟦the (map_of (zip xs ys) x) = the (map_of (zip xs ys) y); distinct xs; distinct ys; length xs = length ys; ∃y. map_of (zip xs ys) x = Some y⟧ ⟹ length xs = length (?ys8 x y)› 2. ‹⋀x y. ⟦distinct xs; distinct ys; length xs = length ys; ∃y. map_of (zip xs ys) x = Some y; ∃ya. map_of (zip xs (?ys8 x y)) y = Some ya; the (map_of (zip xs ys) x) = the (map_of (zip xs ys) y)⟧ ⟹ x = y› discuss goal 1*) apply assumption (*discuss goal 2*) apply clarsimp (*goal: ‹⋀x y. ⟦distinct xs; distinct ys; length xs = length ys; ∃y. map_of (zip xs ys) x = Some y; ∃ya. map_of (zip xs ys) y = Some ya; the (map_of (zip xs ys) x) = the (map_of (zip xs ys) y)⟧ ⟹ x = y›*) apply (clarsimp simp: set_zip (*‹set (zip ?xs ?ys) = {(?xs ! i, ?ys ! i) |i. i < min (length ?xs) (length ?ys)}›*)) (*goal: ‹⋀x y yb. ⟦distinct xs; distinct ys; length xs = length ys; (x, yb) ∈ set (zip xs ys); (y, yb) ∈ set (zip xs ys)⟧ ⟹ x = y›*) apply (metis nth_eq_iff_index_eq (*‹⟦distinct ?xs; ?i < length ?xs; ?j < length ?xs⟧ ⟹ (?xs ! ?i = ?xs ! ?j) = (?i = ?j)›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma map_of_zip_inj': "⟦distinct xs; distinct ys; length xs ≤ length ys⟧ ⟹ inj_on (λx. (the (map_of (zip xs ys) x))) (set xs)" apply (subst zip_take_length[symmetric] (*‹zip (?xs::?'a::type list) (?ys::?'b::type list) = zip ?xs (take (length ?xs) ?ys)›*)) (*goal: ‹⟦distinct xs; distinct ys; length xs ≤ length ys⟧ ⟹ inj_on (λx. the (map_of (zip xs ys) x)) (set xs)›*) apply (erule map_of_zip_inj (*‹⟦distinct ?xs; distinct ?ys; length ?xs = length ?ys⟧ ⟹ inj_on (λx. the (map_of (zip ?xs ?ys) x)) (set ?xs)›*)) (*goals: 1. ‹⟦distinct ys; length xs ≤ length ys⟧ ⟹ distinct (take (length xs) ys)› 2. ‹⟦distinct ys; length xs ≤ length ys⟧ ⟹ length xs = length (take (length xs) ys)› discuss goal 1*) apply simp (*discuss goal 2*) apply (metis length_take (*‹length (take ?n ?xs) = min (length ?xs) ?n›*) min_absorb2 (*‹?y ≤ ?x ⟹ min ?x ?y = ?y›*)) (*proven 2 subgoals*) . lemma list_all_nth: "⟦list_all P xs; i < length xs⟧ ⟹ P (xs ! i)" by (metis list_all_length (*‹list_all ?P ?xs = (∀n<length ?xs. ?P (?xs ! n))›*)) lemma list_all_update: "⟦list_all P xs; i < length xs; ⋀x. P x ⟹ P (f x)⟧ ⟹ list_all P (xs [i := f (xs ! i)])" by (metis length_list_update (*‹length (?xs[?i := ?x]) = length ?xs›*) list_all_length (*‹list_all ?P ?xs = (∀n<length ?xs. ?P (?xs ! n))›*) nth_list_update (*‹?i < length ?xs ⟹ ?xs[?i := ?x] ! ?j = (if ?i = ?j then ?x else ?xs ! ?j)›*)) lemma list_allI: "⟦list_all P xs; ⋀x. P x ⟹ P' x⟧ ⟹ list_all P' xs" by (metis list_all_length (*‹list_all ?P ?xs = (∀n<length ?xs. ?P (?xs ! n))›*)) lemma list_all_imp_filter: "list_all (λx. f x ⟶ g x) xs = list_all (λx. g x) [x←xs . f x]" by (fastforce simp: Ball_set_list_all[symmetric] (*‹list_all ?P ?xs = Ball (set ?xs) ?P›*)) lemma list_all_imp_filter2: "list_all (λx. f x ⟶ g x) xs = list_all (λx. ¬f x) [x←xs . (λx. ¬g x) x]" by (fastforce simp: Ball_set_list_all[symmetric] (*‹list_all (?P::?'a ⇒ bool) (?xs::?'a list) = Ball (set ?xs) ?P›*)) lemma list_all_imp_chain: "⟦list_all (λx. f x ⟶ g x) xs; list_all (λx. f' x ⟶ f x) xs⟧ ⟹ list_all (λx. f' x ⟶ g x) xs" by (clarsimp simp: Ball_set_list_all [symmetric] (*‹list_all ?P ?xs = Ball (set ?xs) ?P›*)) lemma inj_Pair: "inj_on (Pair x) S" apply (rule inj_onI (*‹(⋀(x::?'a) y::?'a. ⟦x ∈ (?A::?'a set); y ∈ ?A; (?f::?'a ⇒ ?'b) x = ?f y⟧ ⟹ x = y) ⟹ inj_on ?f ?A›*)) (*goal: ‹inj_on (Pair x) S›*) by simp lemma inj_on_split: "inj_on f S ⟹ inj_on (λx. (z, f x)) S" by (auto simp: inj_on_def (*‹inj_on ?f ?A = (∀x∈?A. ∀y∈?A. ?f x = ?f y ⟶ x = y)›*)) lemma split_state_strg: "(∃x. f s = x ∧ P x s) ⟶ P (f s) s" by clarsimp lemma theD: "⟦the (f x) = y; x ∈ dom f ⟧ ⟹ f x = Some y" by (auto simp add: dom_def (*‹dom ?m = {a. ?m a ≠ None}›*)) lemma bspec_split: "⟦ ∀(a, b) ∈ S. P a b; (a, b) ∈ S ⟧ ⟹ P a b" by fastforce lemma set_zip_same: "set (zip xs xs) = Id ∩ (set xs × set xs)" apply (induct xs) (*goals: 1. ‹set (zip [] []) = Restr Id (set [])› 2. ‹⋀a xs. set (zip xs xs) = Restr Id (set xs) ⟹ set (zip (a # xs) (a # xs)) = Restr Id (set (a # xs))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma ball_ran_updI: "(∀x ∈ ran m. P x) ⟹ P v ⟹ (∀x ∈ ran (m (y ↦ v)). P x)" by (auto simp add: ran_def (*‹ran ?m = {b. ∃a. ?m a = Some b}›*)) lemma not_psubset_eq: "⟦ ¬ A ⊂ B; A ⊆ B ⟧ ⟹ A = B" by blast lemma set_as_imp: "(A ∩ P ∪ B ∩ -P) = {s. (s ∈ P ⟶ s ∈ A) ∧ (s ∉ P ⟶ s ∈ B)}" by auto lemma in_image_op_plus: "(x + y ∈ (+) x ` S) = ((y :: 'a :: ring) ∈ S)" by (simp add: image_def (*‹(?f::?'a ⇒ ?'b) ` (?A::?'a set) = {y::?'b. ∃x::?'a∈?A. y = ?f x}›*)) lemma insert_subtract_new: "x ∉ S ⟹ (insert x S - S) = {x}" by auto lemmas zip_is_empty = zip_eq_Nil_iff lemma minus_Suc_0_lt: "a ≠ 0 ⟹ a - Suc 0 < a" by simp lemma fst_last_zip_upt: "zip [0 ..< m] xs ≠ [] ⟹ fst (last (zip [0 ..< m] xs)) = (if length xs < m then length xs - 1 else m - 1)" apply (subst last_conv_nth (*‹?xs ≠ [] ⟹ last ?xs = ?xs ! (length ?xs - 1)›*)) (*goals: 1. ‹zip [0..<m] xs ≠ [] ⟹ zip [0..<m] xs ≠ []› 2. ‹zip [0..<m] xs ≠ [] ⟹ fst (zip [0..<m] xs ! (length (zip [0..<m] xs) - 1)) = (if length xs < m then length xs - 1 else m - 1)› discuss goal 1*) apply assumption (*discuss goal 2*) apply (simp only: One_nat_def (*‹(1::nat) = Suc (0::nat)›*)) (*goal: ‹zip [0..<m] xs ≠ [] ⟹ fst (zip [0..<m] xs ! (length (zip [0..<m] xs) - 1)) = (if length xs < m then length xs - 1 else m - 1)›*) apply (subst nth_zip (*‹⟦(?i::nat) < length (?xs::?'a list); ?i < length (?ys::?'b list)⟧ ⟹ zip ?xs ?ys ! ?i = (?xs ! ?i, ?ys ! ?i)›*)) (*goals: 1. ‹zip [0..<m] xs ≠ [] ⟹ length (zip [0..<m] xs) - Suc 0 < length [0..<m]› 2. ‹zip [0..<m] xs ≠ [] ⟹ length (zip [0..<m] xs) - Suc 0 < length xs› 3. ‹zip [0..<m] xs ≠ [] ⟹ fst ([0..<m] ! (length (zip [0..<m] xs) - Suc 0), xs ! (length (zip [0..<m] xs) - Suc 0)) = (if length xs < m then length xs - Suc 0 else m - Suc 0)› discuss goal 1*) apply simp (*top goal: ‹zip [0::nat..<m::nat] (xs::'a list) ≠ [] ⟹ length (zip [0::nat..<m] xs) - Suc (0::nat) < length [0::nat..<m]› and 2 goals remain*) apply (rule order_less_le_trans[OF minus_Suc_0_lt] (*‹⟦?y ≠ 0; ?y ≤ ?z⟧ ⟹ ?y - Suc 0 < ?z›*)) (*goals: 1. ‹(0::nat) < (m::nat) ∧ (xs::'a::type list) ≠ [] ⟹ min m (length xs) ≠ (0::nat)› 2. ‹(0::nat) < (m::nat) ∧ (xs::'a::type list) ≠ [] ⟹ min m (length xs) ≤ m› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*top goal: ‹zip [0..<m] xs ≠ [] ⟹ length (zip [0..<m] xs) - Suc 0 < length xs› and 1 goal remains*) apply (rule order_less_le_trans[OF minus_Suc_0_lt] (*‹⟦?y ≠ 0; ?y ≤ ?z⟧ ⟹ ?y - Suc 0 < ?z›*)) (*goals: 1. ‹0 < m ∧ xs ≠ [] ⟹ min m (length xs) ≠ 0› 2. ‹0 < m ∧ xs ≠ [] ⟹ min m (length xs) ≤ length xs› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 3*) apply simp (*proven 3 subgoals*) (*proven 2 subgoals*) . lemma neq_into_nprefix: "⟦ x ≠ take (length x) y ⟧ ⟹ ¬ x ≤ y" by (clarsimp simp: prefix_def (*‹prefix ?xs ?ys = (∃zs. ?ys = ?xs @ zs)›*) less_eq_list_def (*‹?xs ≤ ?ys ≡ prefix ?xs ?ys›*)) lemma suffix_eqI: "⟦ suffix xs as; suffix xs bs; length as = length bs; take (length as - length xs) as ≤ take (length bs - length xs) bs⟧ ⟹ as = bs" by (clarsimp elim!: prefixE (*‹⟦?xs ≤ ?ys; ⋀zs. ?ys = ?xs @ zs ⟹ ?thesis⟧ ⟹ ?thesis›*) suffixE (*‹⟦suffix ?xs ?ys; ⋀zs. ?ys = zs @ ?xs ⟹ ?thesis⟧ ⟹ ?thesis›*)) lemma suffix_Cons_mem: "suffix (x # xs) as ⟹ x ∈ set as" by (metis in_set_conv_decomp (*‹(?x ∈ set ?xs) = (∃ys zs. ?xs = ys @ ?x # zs)›*) suffix_def (*‹suffix ?xs ?ys = (∃zs. ?ys = zs @ ?xs)›*)) lemma distinct_imply_not_in_tail: "⟦ distinct list; suffix (y # ys) list⟧ ⟹ y ∉ set ys" by (clarsimp simp:suffix_def (*‹suffix ?xs ?ys = (∃zs. ?ys = zs @ ?xs)›*)) lemma list_induct_suffix [case_names Nil Cons]: assumes nilr: "P []" and consr: "⋀x xs. ⟦P xs; suffix (x # xs) as ⟧ ⟹ P (x # xs)" shows "P as" proof (-) (*goal: ‹P as›*) define as' where "as' == as" have "suffix as as'" unfolding as'_def (*goal: ‹suffix as as›*) by simp then show "?thesis" (*goal: ‹P as›*) proof (induct as) (*goals: 1. ‹suffix [] as' ⟹ P []› 2. ‹⋀a as. ⟦suffix as as' ⟹ P as; suffix (a # as) as'⟧ ⟹ P (a # as)›*) case Nil (*‹suffix [] as'›*) show "?case" (*goal: ‹P []›*) by fact next (*goal: ‹⋀a as. ⟦suffix as as' ⟹ P as; suffix (a # as) as'⟧ ⟹ P (a # as)›*) case (Cons x xs) (*‹suffix (xs::'a list) (as'::'a list) ⟹ (P::'a list ⇒ bool) xs› ‹suffix (x # xs) as'›*) show "?case" (*goal: ‹P (x # xs)›*) proof (rule consr (*‹⟦P ?xs; suffix (?x # ?xs) as⟧ ⟹ P (?x # ?xs)›*)) (*goals: 1. ‹P xs› 2. ‹suffix (x # xs) as›*) from Cons.prems (*‹suffix (x # xs) as'›*) show "suffix (x # xs) as" unfolding as'_def (*goal: ‹suffix (x # xs) as›*) . then have "suffix xs as'" by (auto dest: suffix_ConsD (*‹suffix ((?x::?'a::type) # (?xs::?'a::type list)) (?ys::?'a::type list) ⟹ suffix ?xs ?ys›*) simp: as'_def (*‹as'::'a::type list ≡ as::'a::type list›*)) then show "P xs" using Cons.hyps (*‹suffix xs as' ⟹ P xs›*) by simp qed qed qed text ‹Parallel etc. and lemmas for list prefix› lemma prefix_induct [consumes 1, case_names Nil Cons]: fixes prefix assumes np: "prefix ≤ lst" and base: "⋀xs. P [] xs" and rl: "⋀x xs y ys. ⟦ x = y; xs ≤ ys; P xs ys ⟧ ⟹ P (x#xs) (y#ys)" shows "P prefix lst" using np (*‹prefix ≤ lst›*) proof (induct prefix arbitrary: lst) (*goals: 1. ‹⋀lst. [] ≤ lst ⟹ P [] lst› 2. ‹⋀a prefix lst. ⟦⋀lst. prefix ≤ lst ⟹ P prefix lst; a # prefix ≤ lst⟧ ⟹ P (a # prefix) lst›*) case Nil (*‹[] ≤ lst›*) show "?case" (*goal: ‹P [] lst›*) by fact next (*goal: ‹⋀a prefix lst. ⟦⋀lst. prefix ≤ lst ⟹ P prefix lst; a # prefix ≤ lst⟧ ⟹ P (a # prefix) lst›*) case (Cons x xs) (*‹xs ≤ ?lst ⟹ P xs ?lst› ‹x # xs ≤ lst›*) have prem: "(x # xs) ≤ lst" by fact then obtain y and ys where lv: "lst = y # ys" (*goal: ‹(⋀(y::'a::type) ys::'a::type list. (lst::'a::type list) = y # ys ⟹ thesis::bool) ⟹ thesis›*) apply (rule prefixE (*‹⟦?xs ≤ ?ys; ⋀zs. ?ys = ?xs @ zs ⟹ ?thesis⟧ ⟹ ?thesis›*)) (*goal: ‹(⋀y ys. lst = y # ys ⟹ thesis) ⟹ thesis›*) by auto have ih: "⋀lst. xs ≤ lst ⟹ P xs lst" by fact show "?case" (*goal: ‹P (x # xs) lst›*) using prem (*‹(x::'a) # (xs::'a list) ≤ (lst::'a list)›*) by (auto simp: lv (*‹(lst::'a::type list) = (y::'a::type) # (ys::'a::type list)›*) intro!: rl (*‹⟦(?x::'a::type) = (?y::'a::type); (?xs::'a::type list) ≤ (?ys::'a::type list); (P::'a::type list ⇒ 'a::type list ⇒ bool) ?xs ?ys⟧ ⟹ P (?x # ?xs) (?y # ?ys)›*) ih (*‹(xs::'a::type list) ≤ (?lst::'a::type list) ⟹ (P::'a::type list ⇒ 'a::type list ⇒ bool) xs ?lst›*)) qed lemma not_prefix_cases: fixes prefix assumes pfx: "¬ prefix ≤ lst" and c1: "⟦ prefix ≠ []; lst = [] ⟧ ⟹ R" and c2: "⋀a as x xs. ⟦ prefix = a#as; lst = x#xs; x = a; ¬ as ≤ xs⟧ ⟹ R" and c3: "⋀a as x xs. ⟦ prefix = a#as; lst = x#xs; x ≠ a⟧ ⟹ R" shows "R" proof (cases prefix) (*goals: 1. ‹prefix = [] ⟹ R› 2. ‹⋀a list. prefix = a # list ⟹ R›*) case Nil (*‹prefix = []›*) then show "?thesis" (*goal: ‹R›*) using pfx (*‹¬ prefix ≤ lst›*) by simp next (*goal: ‹⋀a list. prefix = a # list ⟹ R›*) case (Cons a as) (*‹prefix = a # as›*) have c: "prefix = a#as" by fact show "?thesis" (*goal: ‹R›*) proof (cases lst) (*goals: 1. ‹(lst::'a list) = [] ⟹ R::bool› 2. ‹⋀(a::'a) list::'a list. (lst::'a list) = a # list ⟹ R::bool›*) case Nil (*‹lst = []›*) then show "?thesis" (*goal: ‹R›*) apply (intro c1 (*‹⟦(prefix::'a list) ≠ []; (lst::'a list) = []⟧ ⟹ R::bool›*)) (*goals: 1. ‹lst = [] ⟹ prefix ≠ []› 2. ‹lst = [] ⟹ lst = []› discuss goal 1*) apply (simp add: Cons (*‹prefix = a # as›*)) (*discuss goal 2*) . (*proven 2 subgoals*) next (*goal: ‹⋀a list. lst = a # list ⟹ R›*) case (Cons x xs) (*‹lst = x # xs›*) show "?thesis" (*goal: ‹R›*) proof (cases "x = a") (*goals: 1. ‹x = a ⟹ R› 2. ‹x ≠ a ⟹ R›*) case True (*‹x = a›*) show "?thesis" (*goal: ‹R›*) proof (intro c2 (*‹⟦prefix = ?a # ?as; lst = ?x # ?xs; ?x = ?a; ¬ ?as ≤ ?xs⟧ ⟹ R›*)) (*goals: 1. ‹prefix = ?a # ?as› 2. ‹lst = ?x # ?xs› 3. ‹?x = ?a› 4. ‹¬ ?as ≤ ?xs›*) show "¬ as ≤ xs" using pfx (*‹¬ (prefix::'a list) ≤ (lst::'a list)›*) c (*‹prefix = a # as›*) Cons (*‹lst = x # xs›*) True (*‹x = a›*) by simp qed ((fact)+) (*solves the remaining goals: 1. ‹prefix = ?a # as› 2. ‹lst = ?x # xs› 3. ‹?x = ?a›*) next (*goal: ‹x ≠ a ⟹ R›*) case False (*‹x ≠ a›*) show "?thesis" (*goal: ‹R›*) apply (rule c3 (*‹⟦(prefix::'a::type list) = (?a::'a::type) # (?as::'a::type list); (lst::'a::type list) = (?x::'a::type) # (?xs::'a::type list); ?x ≠ ?a⟧ ⟹ R::bool›*)) (*goals: 1. ‹prefix = ?a # ?as› 2. ‹lst = ?x # ?xs› 3. ‹?x ≠ ?a› discuss goal 1*) apply fact (*discuss goal 2*) apply fact (*discuss goal 3*) apply fact (*proven 3 subgoals*) . qed qed qed lemma not_prefix_induct [consumes 1, case_names Nil Neq Eq]: fixes prefix assumes np: "¬ prefix ≤ lst" and base: "⋀x xs. P (x#xs) []" and r1: "⋀x xs y ys. x ≠ y ⟹ P (x#xs) (y#ys)" and r2: "⋀x xs y ys. ⟦ x = y; ¬ xs ≤ ys; P xs ys ⟧ ⟹ P (x#xs) (y#ys)" shows "P prefix lst" using np (*‹¬ prefix ≤ lst›*) proof (induct lst arbitrary: prefix) (*goals: 1. ‹⋀prefix. ¬ prefix ≤ [] ⟹ P prefix []› 2. ‹⋀a lst prefix. ⟦⋀prefix. ¬ prefix ≤ lst ⟹ P prefix lst; ¬ prefix ≤ a # lst⟧ ⟹ P prefix (a # lst)›*) case Nil (*‹¬ prefix ≤ []›*) then show "?case" (*goal: ‹P prefix []›*) by (auto simp: neq_Nil_conv (*‹(?xs ≠ []) = (∃y ys. ?xs = y # ys)›*) elim!: not_prefix_cases (*‹⟦¬ ?prefix ≤ ?lst; ⟦?prefix ≠ []; ?lst = []⟧ ⟹ ?R; ⋀a as x xs. ⟦?prefix = a # as; ?lst = x # xs; x = a; ¬ as ≤ xs⟧ ⟹ ?R; ⋀a as x xs. ⟦?prefix = a # as; ?lst = x # xs; x ≠ a⟧ ⟹ ?R⟧ ⟹ ?R›*) intro!: base (*‹P (?x # ?xs) []›*)) next (*goal: ‹⋀a lst prefix. ⟦⋀prefix. ¬ prefix ≤ lst ⟹ P prefix lst; ¬ prefix ≤ a # lst⟧ ⟹ P prefix (a # lst)›*) case (Cons y ys) (*‹¬ ?prefix ≤ ys ⟹ P ?prefix ys› ‹¬ (prefix::'a::type list) ≤ (y::'a::type) # (ys::'a::type list)›*) have npfx: "¬ prefix ≤ (y # ys)" by fact then obtain x and xs where pv: "prefix = x # xs" (*goal: ‹(⋀x xs. prefix = x # xs ⟹ thesis) ⟹ thesis›*) apply (rule not_prefix_cases (*‹⟦¬ (?prefix::?'a list) ≤ (?lst::?'a list); ⟦?prefix ≠ []; ?lst = []⟧ ⟹ ?R::bool; ⋀(a::?'a) (as::?'a list) (x::?'a) xs::?'a list. ⟦?prefix = a # as; ?lst = x # xs; x = a; ¬ as ≤ xs⟧ ⟹ ?R; ⋀(a::?'a) (as::?'a list) (x::?'a) xs::?'a list. ⟦?prefix = a # as; ?lst = x # xs; x ≠ a⟧ ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹⟦⋀x xs. prefix = x # xs ⟹ thesis; prefix ≠ []; y # ys = []⟧ ⟹ thesis› 2. ‹⋀a as x xs. ⟦⋀x xs. prefix = x # xs ⟹ thesis; prefix = a # as; y # ys = x # xs; x = a; ¬ as ≤ xs⟧ ⟹ thesis› 3. ‹⋀a as x xs. ⟦⋀x xs. prefix = x # xs ⟹ thesis; prefix = a # as; y # ys = x # xs; x ≠ a⟧ ⟹ thesis› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . have ih: "⋀prefix. ¬ prefix ≤ ys ⟹ P prefix ys" by fact show "?case" (*goal: ‹P prefix (y # ys)›*) using npfx (*‹¬ (prefix::'a::type list) ≤ (y::'a::type) # (ys::'a::type list)›*) apply (simp only: pv (*‹prefix = x # xs›*)) (*goal: ‹P prefix (y # ys)›*) apply (erule not_prefix_cases (*‹⟦¬ (?prefix::?'a list) ≤ (?lst::?'a list); ⟦?prefix ≠ []; ?lst = []⟧ ⟹ ?R::bool; ⋀(a::?'a) (as::?'a list) (x::?'a) xs::?'a list. ⟦?prefix = a # as; ?lst = x # xs; x = a; ¬ as ≤ xs⟧ ⟹ ?R; ⋀(a::?'a) (as::?'a list) (x::?'a) xs::?'a list. ⟦?prefix = a # as; ?lst = x # xs; x ≠ a⟧ ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹⟦x # xs ≠ []; y # ys = []⟧ ⟹ P (x # xs) (y # ys)› 2. ‹⋀a as xa xsa. ⟦x # xs = a # as; y # ys = xa # xsa; xa = a; ¬ as ≤ xsa⟧ ⟹ P (x # xs) (y # ys)› 3. ‹⋀a as xa xsa. ⟦x # xs = a # as; y # ys = xa # xsa; xa ≠ a⟧ ⟹ P (x # xs) (y # ys)› discuss goal 1*) apply ((auto intro: r1 (*‹?x ≠ ?y ⟹ P (?x # ?xs) (?y # ?ys)›*) r2 (*‹⟦?x = ?y; ¬ ?xs ≤ ?ys; P ?xs ?ys⟧ ⟹ P (?x # ?xs) (?y # ?ys)›*) ih (*‹¬ ?prefix ≤ ys ⟹ P ?prefix ys›*))[1]) (*discuss goal 2*) apply ((auto intro: r1 (*‹?x ≠ ?y ⟹ P (?x # ?xs) (?y # ?ys)›*) r2 (*‹⟦?x = ?y; ¬ ?xs ≤ ?ys; P ?xs ?ys⟧ ⟹ P (?x # ?xs) (?y # ?ys)›*) ih (*‹¬ ?prefix ≤ ys ⟹ P ?prefix ys›*))[1]) (*discuss goal 3*) apply ((auto intro: r1 (*‹?x ≠ ?y ⟹ P (?x # ?xs) (?y # ?ys)›*) r2 (*‹⟦?x = ?y; ¬ ?xs ≤ ?ys; P ?xs ?ys⟧ ⟹ P (?x # ?xs) (?y # ?ys)›*) ih (*‹¬ ?prefix ≤ ys ⟹ P ?prefix ys›*))[1]) (*proven 3 subgoals*) . qed lemma rsubst: "⟦ P s; s = t ⟧ ⟹ P t" by simp lemma ex_impE: "((∃x. P x) ⟶ Q) ⟹ P x ⟹ Q" by blast lemma option_Some_value_independent: "⟦ f x = Some v; ⋀v'. f x = Some v' ⟹ f y = Some v' ⟧ ⟹ f y = Some v" by blast text ‹Some int bitwise lemmas. Helpers for proofs about 🗏‹NatBitwise.thy›› lemma int_2p_eq_shiftl: "(2::int)^x = 1 << x" by (simp add: shiftl_int_def (*‹?x << ?n = ?x * 2 ^ ?n›*)) lemma nat_int_mul: "nat (int a * b) = a * nat b" by (simp add: nat_mult_distrib (*‹0 ≤ ?z ⟹ nat (?z * ?z') = nat ?z * nat ?z'›*)) lemma int_shiftl_less_cancel: "n ≤ m ⟹ ((x :: int) << n < y << m) = (x < y << (m - n))" apply (drule le_Suc_ex (*‹?k ≤ ?l ⟹ ∃n. ?l = ?k + n›*)) (*goal: ‹n ≤ m ⟹ (x << n < y << m) = (x < y << m - n)›*) by (clarsimp simp: shiftl_int_def (*‹?x << ?n = ?x * 2 ^ ?n›*) power_add (*‹?a ^ (?m + ?n) = ?a ^ ?m * ?a ^ ?n›*)) lemma int_shiftl_lt_2p_bits: "0 ≤ (x::int) ⟹ x < 1 << n ⟹ ∀i ≥ n. ¬ x !! i" apply (clarsimp simp: shiftl_int_def (*‹?x << ?n = ?x * 2 ^ ?n›*)) (*goal: ‹⟦(0::int) ≤ (x::int); x < (1::int) << (n::nat)⟧ ⟹ ∀i≥n. ¬ x !! i›*) by (metis bit_take_bit_iff (*‹take_bit ?m ?a !! ?n = (?n < ?m ∧ ?a !! ?n)›*) not_less (*‹(¬ ?x < ?y) = (?y ≤ ?x)›*) take_bit_int_eq_self_iff (*‹(take_bit ?n ?k = ?k) = (0 ≤ ?k ∧ ?k < 2 ^ ?n)›*))<close> lemmas int_eq_test_bit = bin_eq_iff lemmas int_eq_test_bitI = int_eq_test_bit[THEN iffD2, rule_format] lemma le_nat_shrink_left: "y ≤ z ⟹ y = Suc x ⟹ x < z" by simp lemma length_ge_split: "n < length xs ⟹ ∃x xs'. xs = x # xs' ∧ n ≤ length xs'" apply (cases xs) (*goals: 1. ‹⟦n < length xs; xs = []⟧ ⟹ ∃x xs'. xs = x # xs' ∧ n ≤ length xs'› 2. ‹⋀a list. ⟦n < length xs; xs = a # list⟧ ⟹ ∃x xs'. xs = x # xs' ∧ n ≤ length xs'› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . text ‹Support for defining enumerations on datatypes derived from enumerations› lemma distinct_map_enum: "⟦ (∀ x y. (F x = F y ⟶ x = y )) ⟧ ⟹ distinct (map F (enum_class.enum :: 'a :: enum list))" by (simp add: distinct_map (*‹distinct (map ?f ?xs) = (distinct ?xs ∧ inj_on ?f (set ?xs))›*) inj_onI (*‹(⋀x y. ⟦x ∈ ?A; y ∈ ?A; ?f x = ?f y⟧ ⟹ x = y) ⟹ inj_on ?f ?A›*)) lemma if_option_None_eq: "((if P then None else Some x) = None) = P" by (auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) lemma not_in_ran_None_upd: "x ∉ ran m ⟹ x ∉ ran (m(y := None))" by (auto simp: ran_def (*‹ran (?m::?'a ⇒ ?'b option) = {b::?'b. ∃a::?'a. ?m a = Some b}›*) split: if_split (*‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))›*)) text ‹Prevent clarsimp and others from creating Some from not None by folding this and unfolding again when safe.› definition "not_None x = (x ≠ None)" lemma sorted_wrt_hd_min: "⟦ ⋀x. P x x; sorted_wrt P xs ⟧ ⟹ (∀x ∈ set xs. P (hd xs) x)" apply (induction xs) (*goals: 1. ‹⟦⋀x. P x x; sorted_wrt P []⟧ ⟹ Ball (set []) (P (hd []))› 2. ‹⋀a xs. ⟦⟦⋀x. P x x; sorted_wrt P xs⟧ ⟹ Ball (set xs) (P (hd xs)); ⋀x. P x x; sorted_wrt P (a # xs)⟧ ⟹ Ball (set (a # xs)) (P (hd (a # xs)))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma disjoint_no_subset: "A ∩ B = {} ⟹ A ≠ {} ⟹ A ⊆ B ⟹ False" by blast lemma map_prod_split_case: "map_prod f g x = (case x of (a, b) => (f a, g b))" apply (cases x) (*goal: ‹map_prod f g x = (case x of (a, b) ⇒ (f a, g b))›*) by auto lemma map_prod_split_prj: "map_prod f g x = (f (fst x), g (snd x))" apply (cases x) (*goal: ‹map_prod f g x = (f (fst x), g (snd x))›*) by auto end
{ "path": "afp-2025-02-12/thys/AutoCorres2/lib/More_Lib.thy", "repo": "afp-2025-02-12", "sha": "648d769a0f14f8d5c0088eeb8f95c0451bdcb67d746ded5153457a8034c3b3b8" }
section ‹Translating terms into Graphs› text ‹We define the translation function and its properties.› theory RuleSemanticsConnection imports LabeledGraphSemantics RulesAndChains begin text ‹Definition 15.› fun translation :: "'c allegorical_term ⇒ ('c, nat) labeled_graph" where "translation (A_Lbl l) = LG {(l,0,1)} {0,1}" | "translation (A_Cnv e) = map_graph_fn (translation e) (λ x. if x<2 then (1-x) else x)" | "translation (A_Cmp e₁ e₂) = (let G₁ = translation e₁ ; G₂ = translation e₂ in graph_union (map_graph_fn G₁ (λ x. if x=0 then 0 else x+card(vertices G₂)-1)) (map_graph_fn G₂ (λ x. if x=0 then card (vertices G₂) else x)))" | "translation (A_Int e₁ e₂) = (let G₁ = translation e₁ ; G₂ = translation e₂ in graph_union G₁ (map_graph_fn G₂ (λ x. if x<2 then x else x+card(vertices G₁)-2)))" definition inv_translation where "inv_translation r ≡ {0..<card r} = r ∧ {0,1}⊆r" lemma inv_translationI4[intro]: assumes "finite r" "⋀ x. x < card r ⟹ x ∈ r" shows "r={0..<card r}" proof (insert assms (*‹finite r› ‹?x < card r ⟹ ?x ∈ r›*), induct "card r" arbitrary:r) (*goals: 1. ‹⋀r. ⟦0 = card r; finite r; ⋀x. x < card r ⟹ x ∈ r⟧ ⟹ r = {0..<card r}› 2. ‹⋀x r. ⟦⋀r. ⟦x = card r; finite r; ⋀x. x < card r ⟹ x ∈ r⟧ ⟹ r = {0..<card r}; Suc x = card r; finite r; ⋀x. x < card r ⟹ x ∈ r⟧ ⟹ r = {0..<card r}›*) case (Suc x r) (*‹⟦(x::nat) = card (?r::nat set); finite ?r; ⋀x::nat. x < card ?r ⟹ x ∈ ?r⟧ ⟹ ?r = {0::nat..<card ?r}› ‹Suc x = card r› ‹finite r› ‹?x < card r ⟹ ?x ∈ r›*) let ?r = "r - {x}" from Suc (*‹⟦(x::nat) = card (?r::nat set); finite ?r; ⋀x::nat. x < card ?r ⟹ x ∈ ?r⟧ ⟹ ?r = {0::nat..<card ?r}› ‹Suc x = card r› ‹finite r› ‹(?x::nat) < card (r::nat set) ⟹ ?x ∈ r›*) have p: "x = card ?r" "finite ?r" apply - (*goals: 1. ‹⟦⋀r::nat set. ⟦(x::nat) = card r; finite r; ⋀x::nat. x < card r ⟹ x ∈ r⟧ ⟹ r = {0::nat..<card r}; Suc x = card (r::nat set); finite r; ⋀x::nat. x < card r ⟹ x ∈ r⟧ ⟹ x = card (r - {x})› 2. ‹⟦⋀r::nat set. ⟦(x::nat) = card r; finite r; ⋀x::nat. x < card r ⟹ x ∈ r⟧ ⟹ r = {0::nat..<card r}; Suc x = card (r::nat set); finite r; ⋀x::nat. x < card r ⟹ x ∈ r⟧ ⟹ finite (r - {x})› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have p2: "xa < card ?r ⟹ xa ∈ ?r" for xa using Suc.prems(2)[of xa] (*‹xa < card r ⟹ xa ∈ r›*) Suc.hyps(2) (*‹Suc x = card r›*) unfolding p(1)[symmetric] (*goal: ‹xa < x ⟹ xa ∈ r - {x}›*) by auto from Suc.hyps(1)[OF p p2] (*‹(⋀xa. xa < card (r - {x}) ⟹ xa < card (r - {x})) ⟹ r - {x} = {0..<card (r - {x})}›*) have "?r={0..<card ?r}" . with Suc.hyps(2) (*‹Suc x = card r›*) Suc.prems(1) (*‹finite r›*) show "?case" (*goal: ‹(r::nat set) = {0::nat..<card r}›*) by (metis atLeast0_lessThan_Suc (*‹{0..<Suc ?n} = insert ?n {0..<?n}›*) card_Diff_singleton_if (*‹card (?A - {?x}) = (if ?x ∈ ?A then card ?A - 1 else card ?A)›*) insert_Diff (*‹?a ∈ ?A ⟹ insert ?a (?A - {?a}) = ?A›*) n_not_Suc_n (*‹?n ≠ Suc ?n›*) p( (*‹x = card (r - {x})›*) 1)) qed (auto) (*solved the remaining goal: ‹⋀r. ⟦0 = card r; finite r; ⋀x. x < card r ⟹ x ∈ r⟧ ⟹ r = {0..<card r}›*) lemma inv_translationI[intro!]: assumes "finite r" "⋀ x. x < card r ⟹ x ∈ r" "0 ∈ r" "Suc 0 ∈ r" shows "inv_translation r" proof (-) (*goal: ‹inv_translation r›*) from inv_translationI4[OF assms ( 1 , 2 ), symmetric] (*‹(⋀x. x < card r ⟹ x < card r) ⟹ {0..<card r} = r›*) have c: " {0..<card r} = r " by auto from assms(3,4) (*‹0 ∈ r› ‹Suc 0 ∈ r›*) have "{0,1} ⊆ r" by auto with c (*‹{0..<card r} = r›*) inv_translation_def (*‹inv_translation ?r ≡ {0..<card ?r} = ?r ∧ {0, 1} ⊆ ?r›*) show "?thesis" (*goal: ‹inv_translation r›*) by auto qed lemma verts_in_translation_finite[intro]: "finite (vertices (translation X))" "finite (edges (translation X))" "0 ∈ vertices (translation X)" "Suc 0 ∈ vertices (translation X)" proof (atomize(full), induction X) (*goals: 1. ‹⋀X1 X2. ⟦(finite (vertices (translation X1)) ∧ finite (edges (translation X1))) ∧ 0 ∈ vertices (translation X1) ∧ Suc 0 ∈ vertices (translation X1); (finite (vertices (translation X2)) ∧ finite (edges (translation X2))) ∧ 0 ∈ vertices (translation X2) ∧ Suc 0 ∈ vertices (translation X2)⟧ ⟹ (finite (vertices (translation (A_Int X1 X2))) ∧ finite (edges (translation (A_Int X1 X2)))) ∧ 0 ∈ vertices (translation (A_Int X1 X2)) ∧ Suc 0 ∈ vertices (translation (A_Int X1 X2))› 2. ‹⋀X1 X2. ⟦(finite (vertices (translation X1)) ∧ finite (edges (translation X1))) ∧ 0 ∈ vertices (translation X1) ∧ Suc 0 ∈ vertices (translation X1); (finite (vertices (translation X2)) ∧ finite (edges (translation X2))) ∧ 0 ∈ vertices (translation X2) ∧ Suc 0 ∈ vertices (translation X2)⟧ ⟹ (finite (vertices (translation (A_Cmp X1 X2))) ∧ finite (edges (translation (A_Cmp X1 X2)))) ∧ 0 ∈ vertices (translation (A_Cmp X1 X2)) ∧ Suc 0 ∈ vertices (translation (A_Cmp X1 X2))› 3. ‹⋀X. (finite (vertices (translation X)) ∧ finite (edges (translation X))) ∧ 0 ∈ vertices (translation X) ∧ Suc 0 ∈ vertices (translation X) ⟹ (finite (vertices (translation (A_Cnv X))) ∧ finite (edges (translation (A_Cnv X)))) ∧ 0 ∈ vertices (translation (A_Cnv X)) ∧ Suc 0 ∈ vertices (translation (A_Cnv X))› 4. ‹⋀x. (finite (vertices (translation (A_Lbl x))) ∧ finite (edges (translation (A_Lbl x)))) ∧ 0 ∈ vertices (translation (A_Lbl x)) ∧ Suc 0 ∈ vertices (translation (A_Lbl x))›*) case (A_Int X1 X2) (*‹(finite (vertices (translation X1)) ∧ finite (edges (translation X1))) ∧ 0 ∈ vertices (translation X1) ∧ Suc 0 ∈ vertices (translation X1)› ‹(finite (vertices (translation X2)) ∧ finite (edges (translation X2))) ∧ 0 ∈ vertices (translation X2) ∧ Suc 0 ∈ vertices (translation X2)›*) then show "?case" (*goal: ‹(finite (vertices (translation (A_Int (X1::'a::type allegorical_term) (X2::'a::type allegorical_term)))) ∧ finite (edges (translation (A_Int X1 X2)))) ∧ (0::nat) ∈ vertices (translation (A_Int X1 X2)) ∧ Suc (0::nat) ∈ vertices (translation (A_Int X1 X2))›*) by (auto simp:Let_def (*‹Let (?s::?'a) (?f::?'a ⇒ ?'b) ≡ ?f ?s›*)) next (*goals: 1. ‹⋀X1 X2. ⟦(finite (vertices (translation X1)) ∧ finite (edges (translation X1))) ∧ 0 ∈ vertices (translation X1) ∧ Suc 0 ∈ vertices (translation X1); (finite (vertices (translation X2)) ∧ finite (edges (translation X2))) ∧ 0 ∈ vertices (translation X2) ∧ Suc 0 ∈ vertices (translation X2)⟧ ⟹ (finite (vertices (translation (A_Cmp X1 X2))) ∧ finite (edges (translation (A_Cmp X1 X2)))) ∧ 0 ∈ vertices (translation (A_Cmp X1 X2)) ∧ Suc 0 ∈ vertices (translation (A_Cmp X1 X2))› 2. ‹⋀X. (finite (vertices (translation X)) ∧ finite (edges (translation X))) ∧ 0 ∈ vertices (translation X) ∧ Suc 0 ∈ vertices (translation X) ⟹ (finite (vertices (translation (A_Cnv X))) ∧ finite (edges (translation (A_Cnv X)))) ∧ 0 ∈ vertices (translation (A_Cnv X)) ∧ Suc 0 ∈ vertices (translation (A_Cnv X))› 3. ‹⋀x. (finite (vertices (translation (A_Lbl x))) ∧ finite (edges (translation (A_Lbl x)))) ∧ 0 ∈ vertices (translation (A_Lbl x)) ∧ Suc 0 ∈ vertices (translation (A_Lbl x))›*) case (A_Cmp X1 X2) (*‹(finite (vertices (translation X1)) ∧ finite (edges (translation X1))) ∧ 0 ∈ vertices (translation X1) ∧ Suc 0 ∈ vertices (translation X1)› ‹(finite (vertices (translation X2)) ∧ finite (edges (translation X2))) ∧ 0 ∈ vertices (translation X2) ∧ Suc 0 ∈ vertices (translation X2)›*) then show "?case" (*goal: ‹(finite (vertices (translation (A_Cmp X1 X2))) ∧ finite (edges (translation (A_Cmp X1 X2)))) ∧ 0 ∈ vertices (translation (A_Cmp X1 X2)) ∧ Suc 0 ∈ vertices (translation (A_Cmp X1 X2))›*) by (auto simp:Let_def (*‹Let ?s ?f ≡ ?f ?s›*)) next (*goals: 1. ‹⋀X. (finite (vertices (translation X)) ∧ finite (edges (translation X))) ∧ 0 ∈ vertices (translation X) ∧ Suc 0 ∈ vertices (translation X) ⟹ (finite (vertices (translation (A_Cnv X))) ∧ finite (edges (translation (A_Cnv X)))) ∧ 0 ∈ vertices (translation (A_Cnv X)) ∧ Suc 0 ∈ vertices (translation (A_Cnv X))› 2. ‹⋀x. (finite (vertices (translation (A_Lbl x))) ∧ finite (edges (translation (A_Lbl x)))) ∧ 0 ∈ vertices (translation (A_Lbl x)) ∧ Suc 0 ∈ vertices (translation (A_Lbl x))›*) have [simp]: "{x::nat. x < 2} = {0,1}" by auto case (A_Cnv X) (*‹(finite (vertices (translation X)) ∧ finite (edges (translation X))) ∧ 0 ∈ vertices (translation X) ∧ Suc 0 ∈ vertices (translation X)›*) then show "?case" (*goal: ‹(finite (vertices (translation (A_Cnv X))) ∧ finite (edges (translation (A_Cnv X)))) ∧ 0 ∈ vertices (translation (A_Cnv X)) ∧ Suc 0 ∈ vertices (translation (A_Cnv X))›*) by auto qed (auto) (*solved the remaining goal: ‹⋀x. (finite (vertices (translation (A_Lbl x))) ∧ finite (edges (translation (A_Lbl x)))) ∧ 0 ∈ vertices (translation (A_Lbl x)) ∧ Suc 0 ∈ vertices (translation (A_Lbl x))›*) lemma inv_tr_card_min: assumes "inv_translation r" shows "card r ≥ 2" proof (-) (*goal: ‹(2::nat) ≤ card (r::nat set)›*) note [simp] = inv_translation_def (*‹inv_translation ?r ≡ {0..<card ?r} = ?r ∧ {0, 1} ⊆ ?r›*) have "{0..<x} = r ⟹ 2 ≤ x ⟷ 0 ∈ r ∧ 1 ∈ r" for x by auto thus ge2: "card r≥2" using assms (*‹inv_translation r›*) by auto qed lemma verts_in_translation[intro]: "inv_translation (vertices (translation X))" proof (induct X) (*goals: 1. ‹⋀(X1::'a::type allegorical_term) X2::'a::type allegorical_term. ⟦inv_translation (vertices (translation X1)); inv_translation (vertices (translation X2))⟧ ⟹ inv_translation (vertices (translation (A_Int X1 X2)))› 2. ‹⋀(X1::'a::type allegorical_term) X2::'a::type allegorical_term. ⟦inv_translation (vertices (translation X1)); inv_translation (vertices (translation X2))⟧ ⟹ inv_translation (vertices (translation (A_Cmp X1 X2)))› 3. ‹⋀X::'a::type allegorical_term. inv_translation (vertices (translation X)) ⟹ inv_translation (vertices (translation (A_Cnv X)))› 4. ‹⋀x::'a::type. inv_translation (vertices (translation (A_Lbl x)))›*) { fix r assume assms: "inv_translation r" (*‹inv_translation (r::nat set)›*) note [simp] = inv_translation_def (*‹inv_translation ?r ≡ {0..<card ?r} = ?r ∧ {0, 1} ⊆ ?r›*) from assms (*‹inv_translation r›*) have a1: "finite r" apply (intro card_ge_0_finite (*‹0 < card ?A ⟹ finite ?A›*)) (*goal: ‹finite r›*) by auto have [simp]: "{0..<Suc x} = {0..<x} ∪ {x}" for x by auto note ge2 = inv_tr_card_min[OF assms] (*‹2 ≤ card r›*) from ge2 (*‹2 ≤ card r›*) assms (*‹inv_translation r›*) have r0: "r ∩ {0} = {0}" "r ∩ {x. x < 2} = {0,1}" apply - (*goals: 1. ‹⟦2 ≤ card r; inv_translation r⟧ ⟹ r ∩ {0} = {0}› 2. ‹⟦2 ≤ card r; inv_translation r⟧ ⟹ r ∩ {x. x < 2} = {0, 1}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have [intro !]: "⋀x. x ∈ r ⟹ x < card r" and g6: "⋀x. x < card r ⟷ x ∈ r" using assms[unfolded inv_translation_def] (*‹{0..<card r} = r ∧ {0, 1} ⊆ r›*) atLeastLessThan_iff (*‹((?i::?'a) ∈ {?l::?'a..<?u::?'a}) = (?l ≤ ?i ∧ ?i < ?u)›*) apply - (*goals: 1. ‹⋀x. ⟦x ∈ r; {0..<card r} = r ∧ {0, 1} ⊆ r; ⋀i l u. (i ∈ {l..<u}) = (l ≤ i ∧ i < u)⟧ ⟹ x < card r› 2. ‹⋀x. ⟦{0..<card r} = r ∧ {0, 1} ⊆ r; ⋀i l u. (i ∈ {l..<u}) = (l ≤ i ∧ i < u)⟧ ⟹ (x < card r) = (x ∈ r)› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) . have g4: "r ∩ {x. ¬ x < 2} = {2..<card r}" "r ∩ (Collect ((<) 0)) = {1..<card r}" using assms (*‹inv_translation r›*) apply - (*goals: 1. ‹inv_translation r ⟹ r ∩ {x. ¬ x < 2} = {2..<card r}› 2. ‹inv_translation r ⟹ r ∩ Collect ((<) 0) = {1..<card r}› discuss goal 1*) apply fastforce (*discuss goal 2*) apply fastforce (*proven 2 subgoals*) . have ins: "1 ∈ r" "0 ∈ r" using assms (*‹inv_translation r›*) apply - (*goals: 1. ‹inv_translation r ⟹ 1 ∈ r› 2. ‹inv_translation r ⟹ 0 ∈ r› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have d: "Suc (Suc (card r - 2)) = card r" using ge2 (*‹2 ≤ card r›*) One_nat_def (*‹1 = Suc 0›*) Suc_diff_Suc (*‹?n < ?m ⟹ Suc (?m - Suc ?n) = ?m - ?n›*) Suc_pred (*‹(0::nat) < (?n::nat) ⟹ Suc (?n - Suc (0::nat)) = ?n›*) numeral_2_eq_2 (*‹2 = Suc (Suc 0)›*) by presburger note ge2 (*‹2 ≤ card r›*) ins (*‹1 ∈ r› ‹0 ∈ r›*) g4 (*‹r ∩ {x. ¬ x < 2} = {2..<card r}› ‹r ∩ Collect ((<) 0) = {1..<card r}›*) g6 (*‹(?x < card r) = (?x ∈ r)›*) r0 (*‹(r::nat set) ∩ {0::nat} = {0::nat}› ‹r ∩ {x. x < 2} = {0, 1}›*) d (*‹Suc (Suc (card r - 2)) = card r›*) } note inv_translationD[simp] = this (*‹inv_translation ?r3 ⟹ 2 ≤ card ?r3› ‹inv_translation (?r3::nat set) ⟹ (1::nat) ∈ ?r3› ‹inv_translation ?r3 ⟹ 0 ∈ ?r3› ‹inv_translation (?r3::nat set) ⟹ ?r3 ∩ {x::nat. ¬ x < (2::nat)} = {2::nat..<card ?r3}› ‹inv_translation ?r3 ⟹ ?r3 ∩ Collect ((<) 0) = {1..<card ?r3}› ‹inv_translation (?r3::nat set) ⟹ ((?x::nat) < card ?r3) = (?x ∈ ?r3)› ‹inv_translation ?r3 ⟹ ?r3 ∩ {0} = {0}› ‹inv_translation ?r3 ⟹ ?r3 ∩ {x. x < 2} = {0, 1}› ‹inv_translation (?r3::nat set) ⟹ Suc (Suc (card ?r3 - (2::nat))) = card ?r3›*) { fix a and b and c assume assm: "b ≤ (a::nat)" (*‹(b::nat) ≤ (a::nat)›*) have "(λx. x + a - b) ` {b..<c} = {a..<c+a-b}" (is "?lhs = ?rhs") proof (-) (*goal: ‹(λx. x + a - b) ` {b..<c} = {a..<c + a - b}›*) from assm (*‹(b::nat) ≤ (a::nat)›*) have "?lhs = (λx. x + (a - b)) ` {b..<c}" by auto also (*calculation: ‹(λx. x + a - b) ` {b..<c} = (λx. x + (a - b)) ` {b..<c}›*) have "… = ?rhs" unfolding linordered_semidom_class.image_add_atLeastLessThan' (*goal: ‹{b + (a - b)..<c + (a - b)} = {a..<c + a - b}›*) using assm (*‹b ≤ a›*) by auto finally (*calculation: ‹(λx. x + a - b) ` {b..<c} = {a..<c + a - b}›*) show "?thesis" (*goal: ‹(λx. x + a - b) ` {b..<c} = {a..<c + a - b}›*) by auto qed } note e[simp] = this (*‹?b2 ≤ ?a2 ⟹ (λx. x + ?a2 - ?b2) ` {?b2..<?c2} = {?a2..<?c2 + ?a2 - ?b2}›*) { fix r and z assume a1: "inv_translation z" and a2: "inv_translation r" (*‹inv_translation (z::nat set)› ‹inv_translation (r::nat set)›*) let ?z2 = "card z + card r - 2" let ?z1 = "card z + card r - Suc 0" from a1 (*‹inv_translation z›*) a2 (*‹inv_translation r›*) have le1: "Suc 0 ≤ card r" by (metis Suc_leD (*‹Suc ?m ≤ ?n ⟹ ?m ≤ ?n›*) inv_translationD( (*‹inv_translation ?r3 ⟹ 2 ≤ card ?r3›*) 1) numerals( (*‹2 = Suc (Suc 0)›*) 2)) hence le2: "card r ≤ ?z1" by (metis Suc_leD (*‹Suc (?m::nat) ≤ (?n::nat) ⟹ ?m ≤ ?n›*) a1 (*‹inv_translation (z::nat set)›*) inv_translationD( (*‹inv_translation (?r3::nat set) ⟹ (2::nat) ≤ card ?r3›*) 1) numerals( (*‹(2::nat) = Suc (Suc (0::nat))›*) 2) ordered_cancel_comm_monoid_diff_class.le_add_diff (*‹(?a::?'a::ordered_cancel_comm_monoid_diff) ≤ (?b::?'a::ordered_cancel_comm_monoid_diff) ⟹ (?c::?'a::ordered_cancel_comm_monoid_diff) ≤ ?b + ?c - ?a›*)) with le1 (*‹Suc 0 ≤ card r›*) have b: "{card r ..< ?z1} ∪ {Suc 0 ..< card r} = {Suc 0 ..< ?z1}" by auto have a: "(insert (card r) {0..<card z + card r - Suc 0}) = {0..<card z + card r - Suc 0}" using le1 (*‹Suc 0 ≤ card r›*) le2 (*‹card (r::nat set) ≤ card (z::nat set) + card r - Suc (0::nat)›*) a1 (*‹inv_translation z›*) a2 (*‹inv_translation r›*) by (metis Suc_leD (*‹Suc ?m ≤ ?n ⟹ ?m ≤ ?n›*) add_Suc_right (*‹?m + Suc ?n = Suc (?m + ?n)›*) atLeastLessThan_iff (*‹(?i ∈ {?l..<?u}) = (?l ≤ ?i ∧ ?i < ?u)›*) diff_Suc_Suc (*‹Suc ?m - Suc ?n = ?m - ?n›*) insert_absorb (*‹?a ∈ ?A ⟹ insert ?a ?A = ?A›*) inv_translationD( (*‹inv_translation ?r3 ⟹ 2 ≤ card ?r3›*) 1) linorder_not_less (*‹(¬ ?x < ?y) = (?y ≤ ?x)›*) not_less_eq_eq (*‹(¬ ?m ≤ ?n) = (Suc ?n ≤ ?m)›*) numerals( (*‹2 = Suc (Suc 0)›*) 2) ordered_cancel_comm_monoid_diff_class.le_add_diff (*‹?a ≤ ?b ⟹ ?c ≤ ?b + ?c - ?a›*)) from a1 (*‹inv_translation (z::nat set)›*) a2 (*‹inv_translation r›*) have "card z + card r - 2 ≥ card (r::nat set)" by (simp add: ordered_cancel_comm_monoid_diff_class.le_add_diff (*‹?a ≤ ?b ⟹ ?c ≤ ?b + ?c - ?a›*)) with a2 (*‹inv_translation r›*) have c: "card (r ∪ {card r..<?z2}) = ?z2" by (metis atLeast0LessThan (*‹{0..<?n} = {..<?n}›*) card_atLeastLessThan (*‹card {?l..<?u} = ?u - ?l›*) diff_zero (*‹?a - 0 = ?a›*) inv_translation_def (*‹inv_translation ?r ≡ {0..<card ?r} = ?r ∧ {0, 1} ⊆ ?r›*) ivl_disj_un_one( (*‹?l ≤ ?u ⟹ {..<?l} ∪ {?l..<?u} = {..<?u}›*) 2)) note a (*‹insert (card r) {0..<card z + card r - Suc 0} = {0..<card z + card r - Suc 0}›*) b (*‹{card r..<card z + card r - Suc 0} ∪ {Suc 0..<card r} = {Suc 0..<card z + card r - Suc 0}›*) c (*‹card (r ∪ {card r..<card z + card r - 2}) = card z + card r - 2›*) } note [simp] = this (*‹⟦inv_translation ?z2; inv_translation ?r2⟧ ⟹ insert (card ?r2) {0..<card ?z2 + card ?r2 - Suc 0} = {0..<card ?z2 + card ?r2 - Suc 0}› ‹⟦inv_translation ?z2; inv_translation ?r2⟧ ⟹ {card ?r2..<card ?z2 + card ?r2 - Suc 0} ∪ {Suc 0..<card ?r2} = {Suc 0..<card ?z2 + card ?r2 - Suc 0}› ‹⟦inv_translation ?z2; inv_translation ?r2⟧ ⟹ card (?r2 ∪ {card ?r2..<card ?z2 + card ?r2 - 2}) = card ?z2 + card ?r2 - 2›*) have [simp]: "a < x ⟹ insert a {Suc a..<x} = {a..<x}" for a and x by auto { case (A_Int X1 X2) (*‹inv_translation (vertices (translation X1))› ‹inv_translation (vertices (translation (X2::'a::type allegorical_term)))›*) let ?v1 = "vertices (translation X1)" from A_Int (*‹inv_translation (vertices (translation X1))› ‹inv_translation (vertices (translation X2))›*) have [simp]: "(insert 0 (insert (Suc 0) (?v1 ∪ x))) = ?v1 ∪ x" for x unfolding inv_translation_def (*goal: ‹insert 0 (insert (Suc 0) (vertices (translation X1) ∪ x)) = vertices (translation X1) ∪ x›*) by auto from A_Int (*‹inv_translation (vertices (translation (X1::'a allegorical_term)))› ‹inv_translation (vertices (translation (X2::'a allegorical_term)))›*) show "?case" (*goal: ‹inv_translation (vertices (translation (A_Int X1 X2)))›*) by (auto simp:Let_def (*‹Let ?s ?f ≡ ?f ?s›*) linorder_not_le (*‹(¬ ?x ≤ ?y) = (?y < ?x)›*)) next (*goals: 1. ‹⋀(X1::'a allegorical_term) X2::'a allegorical_term. ⟦inv_translation (vertices (translation X1)); inv_translation (vertices (translation X2))⟧ ⟹ inv_translation (vertices (translation (A_Cmp X1 X2)))› 2. ‹⋀X::'a allegorical_term. inv_translation (vertices (translation X)) ⟹ inv_translation (vertices (translation (A_Cnv X)))› 3. ‹⋀x::'a. inv_translation (vertices (translation (A_Lbl x)))›*) case (A_Cmp X1 X2) (*‹inv_translation (vertices (translation X1))› ‹inv_translation (vertices (translation X2))›*) hence "2≤card (vertices (translation X1))" "2≤card (vertices (translation X2))" apply - (*goals: 1. ‹⟦inv_translation (vertices (translation X1)); inv_translation (vertices (translation X2))⟧ ⟹ 2 ≤ card (vertices (translation X1))› 2. ‹⟦inv_translation (vertices (translation X1)); inv_translation (vertices (translation X2))⟧ ⟹ 2 ≤ card (vertices (translation X2))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . hence "1 ≤card (vertices (translation X1))" "1≤card (vertices (translation X2))" "1 < card (vertices (translation X1)) + card (vertices (translation X2)) - 1" apply - (*goals: 1. ‹⟦2 ≤ card (vertices (translation X1)); 2 ≤ card (vertices (translation X2))⟧ ⟹ 1 ≤ card (vertices (translation X1))› 2. ‹⟦2 ≤ card (vertices (translation X1)); 2 ≤ card (vertices (translation X2))⟧ ⟹ 1 ≤ card (vertices (translation X2))› 3. ‹⟦2 ≤ card (vertices (translation X1)); 2 ≤ card (vertices (translation X2))⟧ ⟹ 1 < card (vertices (translation X1)) + card (vertices (translation X2)) - 1› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . from this (*‹1 ≤ card (vertices (translation X1))› ‹1 ≤ card (vertices (translation X2))› ‹1 < card (vertices (translation X1)) + card (vertices (translation X2)) - 1›*) A_Cmp (*‹inv_translation (vertices (translation X1))› ‹inv_translation (vertices (translation X2))›*) show "?case" (*goal: ‹inv_translation (vertices (translation (A_Cmp X1 X2)))›*) by (auto simp:Let_def (*‹Let (?s::?'a::type) (?f::?'a::type ⇒ ?'b::type) ≡ ?f ?s›*)) next (*goals: 1. ‹⋀X. inv_translation (vertices (translation X)) ⟹ inv_translation (vertices (translation (A_Cnv X)))› 2. ‹⋀x. inv_translation (vertices (translation (A_Lbl x)))›*) case (A_Cnv X) (*‹inv_translation (vertices (translation X))›*) thus "?case" (*goal: ‹inv_translation (vertices (translation (A_Cnv X)))›*) by (auto simp:Let_def (*‹Let ?s ?f ≡ ?f ?s›*)) } qed (auto) (*solved the remaining goal: ‹⋀x. inv_translation (vertices (translation (A_Lbl x)))›*) lemma translation_graph[intro]: "graph (translation X)" apply (induct X) (*goals: 1. ‹⋀(X1::'a allegorical_term) X2::'a allegorical_term. ⟦graph (translation X1); graph (translation X2)⟧ ⟹ graph (translation (A_Int X1 X2))› 2. ‹⋀(X1::'a allegorical_term) X2::'a allegorical_term. ⟦graph (translation X1); graph (translation X2)⟧ ⟹ graph (translation (A_Cmp X1 X2))› 3. ‹⋀X::'a allegorical_term. graph (translation X) ⟹ graph (translation (A_Cnv X))› 4. ‹⋀x::'a. graph (translation (A_Lbl x))› discuss goal 1*) apply ((auto simp:Let_def (*‹Let ?s ?f ≡ ?f ?s›*))[1]) (*discuss goal 2*) apply ((auto simp:Let_def (*‹Let ?s ?f ≡ ?f ?s›*))[1]) (*discuss goal 3*) apply ((auto simp:Let_def (*‹Let ?s ?f ≡ ?f ?s›*))[1]) (*discuss goal 4*) apply ((auto simp:Let_def (*‹Let ?s ?f ≡ ?f ?s›*))[1]) (*proven 4 subgoals*) . lemma graph_rule_translation[intro]: (* remark at the end of Def 15 *) "graph_rule (translation X, translation (A_Int X Y))" using verts_in_translation_finite[of X] (*‹finite (vertices (translation X))› ‹finite (edges (translation X))› ‹0 ∈ vertices (translation X)› ‹Suc 0 ∈ vertices (translation X)›*) verts_in_translation_finite[of "A_Int X Y"] (*‹finite (vertices (translation (A_Int X Y)))› ‹finite (edges (translation (A_Int X Y)))› ‹0 ∈ vertices (translation (A_Int X Y))› ‹Suc 0 ∈ vertices (translation (A_Int X Y))›*) translation_graph[of X] (*‹graph (translation (X::'a allegorical_term))›*) translation_graph[of "A_Int X Y"] (*‹graph (translation (A_Int X Y))›*) by (auto simp:Let_def (*‹Let (?s::?'a::type) (?f::?'a::type ⇒ ?'b::type) ≡ ?f ?s›*) subgraph_def2 (*‹⟦graph (?G₁::(?'a::type, ?'b::type) labeled_graph); graph (?G₂::(?'a::type, ?'b::type) labeled_graph)⟧ ⟹ subgraph ?G₁ ?G₂ = (vertices ?G₁ ⊆ vertices ?G₂ ∧ edges ?G₁ ⊆ edges ?G₂)›*)) lemma graph_hom_translation[intro]: "graph_homomorphism (LG {} {0,1}) (translation X) (Id_on {0,1})" using verts_in_translation[of X] (*‹inv_translation (vertices (translation X))›*) unfolding inv_translation_def graph_homomorphism_def2 (*goal: ‹vertices (LG {} {0, 1}) = Domain (Id_on {0, 1}) ∧ univalent (Id_on {0, 1}) ∧ graph (LG {} {0, 1}) ∧ graph (translation X) ∧ graph_union (map_graph (Id_on {0, 1}) (LG {} {0, 1})) (translation X) = translation X›*) by auto lemma translation_right_to_left: assumes f:"graph_homomorphism (translation e) G f" "(0, x) ∈ f" "(1, y) ∈ f" shows "(x, y) ∈ :G:⟦e⟧" using f (*‹graph_homomorphism (translation e) G f› ‹(0, x) ∈ f› ‹(1, y) ∈ f›*) proof (induct e arbitrary:f x y) (*goals: 1. ‹⋀e1 e2 f x y. ⟦⋀f x y. ⟦graph_homomorphism (translation e1) G f; (0, x) ∈ f; (1, y) ∈ f⟧ ⟹ (x, y) ∈ :G:⟦e1⟧; ⋀f x y. ⟦graph_homomorphism (translation e2) G f; (0, x) ∈ f; (1, y) ∈ f⟧ ⟹ (x, y) ∈ :G:⟦e2⟧; graph_homomorphism (translation (A_Int e1 e2)) G f; (0, x) ∈ f; (1, y) ∈ f⟧ ⟹ (x, y) ∈ :G:⟦A_Int e1 e2⟧› 2. ‹⋀e1 e2 f x y. ⟦⋀f x y. ⟦graph_homomorphism (translation e1) G f; (0, x) ∈ f; (1, y) ∈ f⟧ ⟹ (x, y) ∈ :G:⟦e1⟧; ⋀f x y. ⟦graph_homomorphism (translation e2) G f; (0, x) ∈ f; (1, y) ∈ f⟧ ⟹ (x, y) ∈ :G:⟦e2⟧; graph_homomorphism (translation (A_Cmp e1 e2)) G f; (0, x) ∈ f; (1, y) ∈ f⟧ ⟹ (x, y) ∈ :G:⟦A_Cmp e1 e2⟧› 3. ‹⋀e f x y. ⟦⋀f x y. ⟦graph_homomorphism (translation e) G f; (0, x) ∈ f; (1, y) ∈ f⟧ ⟹ (x, y) ∈ :G:⟦e⟧; graph_homomorphism (translation (A_Cnv e)) G f; (0, x) ∈ f; (1, y) ∈ f⟧ ⟹ (x, y) ∈ :G:⟦A_Cnv e⟧› 4. ‹⋀x f xa y. ⟦graph_homomorphism (translation (A_Lbl x)) G f; (0, xa) ∈ f; (1, y) ∈ f⟧ ⟹ (xa, y) ∈ :G:⟦A_Lbl x⟧›*) case (A_Int e₁ e₂ f x y) (*‹⟦graph_homomorphism (translation e₁) G ?f; (0, ?x) ∈ ?f; (1, ?y) ∈ ?f⟧ ⟹ (?x, ?y) ∈ :G:⟦e₁⟧› ‹⟦graph_homomorphism (translation (e₂::'a allegorical_term)) (G::('a, 'b) labeled_graph) (?f::(nat × 'b) set); (0::nat, ?x::'b) ∈ ?f; (1::nat, ?y::'b) ∈ ?f⟧ ⟹ (?x, ?y) ∈ :G:⟦e₂⟧› ‹graph_homomorphism (translation (A_Int (e₁::'a::type allegorical_term) (e₂::'a::type allegorical_term))) (G::('a::type, 'b::type) labeled_graph) (f::(nat × 'b::type) set)› ‹(0, x) ∈ f› ‹(1, y) ∈ f›*) let ?f₁ = id let ?f₂ = "(λ x. if x < 2 then x else x + card (vertices (translation e₁)) - 2)" let ?G₁ = "translation e₁" let ?G₂ = "translation e₂" have f1: "(0, x) ∈ on_graph ?G₁ ?f₁ O f" "(1, y) ∈ on_graph ?G₁ ?f₁ O f" and f2: "(0, x) ∈ on_graph ?G₂ ?f₂ O f" "(1, y) ∈ on_graph ?G₂ ?f₂ O f" using A_Int.prems(2,3) (*‹(0, x) ∈ f› ‹(1, y) ∈ f›*) apply - (*goals: 1. ‹⟦(0, x) ∈ f; (1, y) ∈ f⟧ ⟹ (0, x) ∈ on_graph (translation e₁) id O f› 2. ‹⟦(0, x) ∈ f; (1, y) ∈ f⟧ ⟹ (1, y) ∈ on_graph (translation e₁) id O f› 3. ‹⟦(0, x) ∈ f; (1, y) ∈ f⟧ ⟹ (0, x) ∈ on_graph (translation e₂) (λx. if x < 2 then x else x + card (vertices (translation e₁)) - 2) O f› 4. ‹⟦(0, x) ∈ f; (1, y) ∈ f⟧ ⟹ (1, y) ∈ on_graph (translation e₂) (λx. if x < 2 then x else x + card (vertices (translation e₁)) - 2) O f› discuss goal 1*) apply ((auto simp:BNF_Def.Gr_def (*‹BNF_Def.Gr ?A ?f = {(a, ?f a) |a. a ∈ ?A}›*) relcomp_def (*‹(O) ≡ λr s. {(xa, x). ((λx xa. (x, xa) ∈ r) OO (λx xa. (x, xa) ∈ s)) xa x}›*))[1]) (*discuss goal 2*) apply ((auto simp:BNF_Def.Gr_def (*‹BNF_Def.Gr ?A ?f = {(a, ?f a) |a. a ∈ ?A}›*) relcomp_def (*‹(O) ≡ λr s. {(xa, x). ((λx xa. (x, xa) ∈ r) OO (λx xa. (x, xa) ∈ s)) xa x}›*))[1]) (*discuss goal 3*) apply ((auto simp:BNF_Def.Gr_def (*‹BNF_Def.Gr ?A ?f = {(a, ?f a) |a. a ∈ ?A}›*) relcomp_def (*‹(O) ≡ λr s. {(xa, x). ((λx xa. (x, xa) ∈ r) OO (λx xa. (x, xa) ∈ s)) xa x}›*))[1]) (*discuss goal 4*) apply ((auto simp:BNF_Def.Gr_def (*‹BNF_Def.Gr (?A::?'a set) (?f::?'a ⇒ ?'b) = {(a, ?f a) |a::?'a. a ∈ ?A}›*) relcomp_def (*‹(O) ≡ λ(r::(?'a × ?'b) set) s::(?'b × ?'c) set. {(xa::?'a, x::?'c). ((λ(x::?'a) xa::?'b. (x, xa) ∈ r) OO (λ(x::?'b) xa::?'c. (x, xa) ∈ s)) xa x}›*))[1]) (*proven 4 subgoals*) . from A_Int.prems(1) (*‹graph_homomorphism (translation (A_Int (e₁::'a::type allegorical_term) (e₂::'a::type allegorical_term))) (G::('a::type, 'b::type) labeled_graph) (f::(nat × 'b::type) set)›*) have uni: "graph_homomorphism (graph_union ?G₁ (map_graph_fn ?G₂ ?f₂)) G f" by (auto simp:Let_def (*‹Let ?s ?f ≡ ?f ?s›*)) from graph_homo_union_id(1)[OF uni translation_graph] (*‹graph_homomorphism (translation (e₁::'a allegorical_term)) (G::('a, 'b) labeled_graph) (Id_on (vertices (translation e₁)) O (f::(nat × 'b) set))›*) have h1: "graph_homomorphism ?G₁ (translation (A_Int e₁ e₂)) (on_graph ?G₁ id)" by (auto simp:Let_def (*‹Let ?s ?f ≡ ?f ?s›*) graph_homomorphism_def (*‹graph_homomorphism ?G₁ ?G₂ ?f = (vertices ?G₁ = Domain ?f ∧ graph ?G₁ ∧ graph ?G₂ ∧ ?f `` vertices ?G₁ ⊆ vertices ?G₂ ∧ univalent ?f ∧ edge_preserving ?f (edges ?G₁) (edges ?G₂))›*)) have "graph (map_graph_fn ?G₂ ?f₂)" by auto from graph_homo_union_id(2)[OF uni this] (*‹graph_homomorphism (map_graph_fn (translation (e₂::'a allegorical_term)) (λx::nat. if x < (2::nat) then x else x + card (vertices (translation (e₁::'a allegorical_term))) - (2::nat))) (G::('a, 'b) labeled_graph) (Id_on (vertices (map_graph_fn (translation e₂) (λx::nat. if x < (2::nat) then x else x + card (vertices (translation e₁)) - (2::nat)))) O (f::(nat × 'b) set))›*) have h2: "graph_homomorphism ?G₂ (translation (A_Int e₁ e₂)) (on_graph ?G₂ ?f₂)" by (auto simp:Let_def (*‹Let (?s::?'a::type) (?f::?'a::type ⇒ ?'b::type) ≡ ?f ?s›*) graph_homomorphism_def (*‹graph_homomorphism (?G₁::(?'a::type, ?'b::type) labeled_graph) (?G₂::(?'a::type, ?'c::type) labeled_graph) (?f::(?'b::type × ?'c::type) set) = (vertices ?G₁ = Domain ?f ∧ graph ?G₁ ∧ graph ?G₂ ∧ ?f `` vertices ?G₁ ⊆ vertices ?G₂ ∧ univalent ?f ∧ edge_preserving ?f (edges ?G₁) (edges ?G₂))›*)) from A_Int.hyps(1)[OF graph_homomorphism_composes [ OF h1 A_Int.prems ( 1 ) ] f1] (*‹(x, y) ∈ :G:⟦e₁⟧›*) A_Int.hyps(2)[OF graph_homomorphism_composes [ OF h2 A_Int.prems ( 1 ) ] f2] (*‹(x, y) ∈ :G:⟦e₂⟧›*) show "?case" (*goal: ‹(x, y) ∈ :G:⟦A_Int e₁ e₂⟧›*) by auto next (*goals: 1. ‹⋀e1 e2 f x y. ⟦⋀f x y. ⟦graph_homomorphism (translation e1) G f; (0, x) ∈ f; (1, y) ∈ f⟧ ⟹ (x, y) ∈ :G:⟦e1⟧; ⋀f x y. ⟦graph_homomorphism (translation e2) G f; (0, x) ∈ f; (1, y) ∈ f⟧ ⟹ (x, y) ∈ :G:⟦e2⟧; graph_homomorphism (translation (A_Cmp e1 e2)) G f; (0, x) ∈ f; (1, y) ∈ f⟧ ⟹ (x, y) ∈ :G:⟦A_Cmp e1 e2⟧› 2. ‹⋀e f x y. ⟦⋀f x y. ⟦graph_homomorphism (translation e) G f; (0, x) ∈ f; (1, y) ∈ f⟧ ⟹ (x, y) ∈ :G:⟦e⟧; graph_homomorphism (translation (A_Cnv e)) G f; (0, x) ∈ f; (1, y) ∈ f⟧ ⟹ (x, y) ∈ :G:⟦A_Cnv e⟧› 3. ‹⋀x f xa y. ⟦graph_homomorphism (translation (A_Lbl x)) G f; (0, xa) ∈ f; (1, y) ∈ f⟧ ⟹ (xa, y) ∈ :G:⟦A_Lbl x⟧›*) case (A_Cmp e₁ e₂ f x y) (*‹⟦graph_homomorphism (translation e₁) G ?f; (0, ?x) ∈ ?f; (1, ?y) ∈ ?f⟧ ⟹ (?x, ?y) ∈ :G:⟦e₁⟧› ‹⟦graph_homomorphism (translation (e₂::'a::type allegorical_term)) (G::('a::type, 'b::type) labeled_graph) (?f::(nat × 'b::type) set); (0::nat, ?x::'b::type) ∈ ?f; (1::nat, ?y::'b::type) ∈ ?f⟧ ⟹ (?x, ?y) ∈ :G:⟦e₂⟧› ‹graph_homomorphism (translation (A_Cmp e₁ e₂)) G f› ‹(0::nat, x::'b) ∈ (f::(nat × 'b) set)› ‹(1, y) ∈ f›*) let ?f₁ = "(λ x. if x=0 then 0 else x+card(vertices (translation e₂))-1)" let ?f₂ = "(λ x. if x=0 then card (vertices (translation e₂)) else x)" let ?G₁ = "translation e₁" let ?G₂ = "translation e₂" let ?v = "card (vertices (translation e₂))" from A_Cmp.prems(1) (*‹graph_homomorphism (translation (A_Cmp e₁ e₂)) G f›*) have "?v ∈ Domain f" by (auto simp:Let_def (*‹Let ?s ?f ≡ ?f ?s›*) graph_homomorphism_def (*‹graph_homomorphism ?G₁ ?G₂ ?f = (vertices ?G₁ = Domain ?f ∧ graph ?G₁ ∧ graph ?G₂ ∧ ?f `` vertices ?G₁ ⊆ vertices ?G₂ ∧ univalent ?f ∧ edge_preserving ?f (edges ?G₁) (edges ?G₂))›*)) then obtain v where v: "(?v,v) ∈ f" (*goal: ‹(⋀v. (card (vertices (translation e₂)), v) ∈ f ⟹ thesis) ⟹ thesis›*) by auto have f1: "(0, x) ∈ on_graph ?G₁ ?f₁ O f" "(1, v) ∈ on_graph ?G₁ ?f₁ O f" and f2: "(0, v) ∈ on_graph ?G₂ ?f₂ O f" "(1, y) ∈ on_graph ?G₂ ?f₂ O f" using A_Cmp.prems(2,3) (*‹(0::nat, x::'b) ∈ (f::(nat × 'b) set)› ‹(1, y) ∈ f›*) v (*‹(card (vertices (translation (e₂::'a allegorical_term))), v::'b) ∈ (f::(nat × 'b) set)›*) apply - (*goals: 1. ‹⟦(0::nat, x::'b) ∈ (f::(nat × 'b) set); (1::nat, y::'b) ∈ f; (card (vertices (translation (e₂::'a allegorical_term))), v::'b) ∈ f⟧ ⟹ (0::nat, x) ∈ on_graph (translation (e₁::'a allegorical_term)) (λx::nat. if x = (0::nat) then 0::nat else x + card (vertices (translation e₂)) - (1::nat)) O f› 2. ‹⟦(0::nat, x::'b) ∈ (f::(nat × 'b) set); (1::nat, y::'b) ∈ f; (card (vertices (translation (e₂::'a allegorical_term))), v::'b) ∈ f⟧ ⟹ (1::nat, v) ∈ on_graph (translation (e₁::'a allegorical_term)) (λx::nat. if x = (0::nat) then 0::nat else x + card (vertices (translation e₂)) - (1::nat)) O f› 3. ‹⟦(0::nat, x::'b) ∈ (f::(nat × 'b) set); (1::nat, y::'b) ∈ f; (card (vertices (translation (e₂::'a allegorical_term))), v::'b) ∈ f⟧ ⟹ (0::nat, v) ∈ on_graph (translation e₂) (λx::nat. if x = (0::nat) then card (vertices (translation e₂)) else x) O f› 4. ‹⟦(0::nat, x::'b) ∈ (f::(nat × 'b) set); (1::nat, y::'b) ∈ f; (card (vertices (translation (e₂::'a allegorical_term))), v::'b) ∈ f⟧ ⟹ (1::nat, y) ∈ on_graph (translation e₂) (λx::nat. if x = (0::nat) then card (vertices (translation e₂)) else x) O f› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . from A_Cmp.prems(1) (*‹graph_homomorphism (translation (A_Cmp (e₁::'a allegorical_term) (e₂::'a allegorical_term))) (G::('a, 'b) labeled_graph) (f::(nat × 'b) set)›*) have uni: "graph_homomorphism (graph_union (map_graph_fn ?G₁ ?f₁) (map_graph_fn ?G₂ ?f₂)) G f" by (auto simp:Let_def (*‹Let ?s ?f ≡ ?f ?s›*)) have "graph (map_graph_fn ?G₁ ?f₁)" by auto from graph_homo_union_id(1)[OF uni this] (*‹graph_homomorphism (map_graph_fn (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1)) G (Id_on (vertices (map_graph_fn (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))) O f)›*) have h1: "graph_homomorphism ?G₁ (translation (A_Cmp e₁ e₂)) (on_graph ?G₁ ?f₁)" by (auto simp:Let_def (*‹Let ?s ?f ≡ ?f ?s›*) graph_homomorphism_def2 (*‹graph_homomorphism ?G₁ ?G₂ ?f = (vertices ?G₁ = Domain ?f ∧ univalent ?f ∧ graph ?G₁ ∧ graph ?G₂ ∧ graph_union (map_graph ?f ?G₁) ?G₂ = ?G₂)›*)) have "graph (map_graph_fn ?G₂ ?f₂)" by auto from graph_homo_union_id(2)[OF uni this] (*‹graph_homomorphism (map_graph_fn (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x)) G (Id_on (vertices (map_graph_fn (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x))) O f)›*) have h2: "graph_homomorphism ?G₂ (translation (A_Cmp e₁ e₂)) (on_graph ?G₂ ?f₂)" by (auto simp:Let_def (*‹Let ?s ?f ≡ ?f ?s›*) graph_homomorphism_def2 (*‹graph_homomorphism ?G₁ ?G₂ ?f = (vertices ?G₁ = Domain ?f ∧ univalent ?f ∧ graph ?G₁ ∧ graph ?G₂ ∧ graph_union (map_graph ?f ?G₁) ?G₂ = ?G₂)›*)) from A_Cmp.hyps(1)[OF graph_homomorphism_composes [ OF h1 A_Cmp.prems ( 1 ) ] f1] (*‹(x, v) ∈ :G:⟦e₁⟧›*) A_Cmp.hyps(2)[OF graph_homomorphism_composes [ OF h2 A_Cmp.prems ( 1 ) ] f2] (*‹(v::'b, y::'b) ∈ :G::('a, 'b) labeled_graph:⟦e₂::'a allegorical_term⟧›*) show "?case" (*goal: ‹(x, y) ∈ :G:⟦A_Cmp e₁ e₂⟧›*) by auto next (*goals: 1. ‹⋀(e::'a::type allegorical_term) (f::(nat × 'b::type) set) (x::'b::type) y::'b::type. ⟦⋀(f::(nat × 'b::type) set) (x::'b::type) y::'b::type. ⟦graph_homomorphism (translation e) (G::('a::type, 'b::type) labeled_graph) f; (0::nat, x) ∈ f; (1::nat, y) ∈ f⟧ ⟹ (x, y) ∈ :G:⟦e⟧; graph_homomorphism (translation (A_Cnv e)) G f; (0::nat, x) ∈ f; (1::nat, y) ∈ f⟧ ⟹ (x, y) ∈ :G:⟦A_Cnv e⟧› 2. ‹⋀(x::'a::type) (f::(nat × 'b::type) set) (xa::'b::type) y::'b::type. ⟦graph_homomorphism (translation (A_Lbl x)) (G::('a::type, 'b::type) labeled_graph) f; (0::nat, xa) ∈ f; (1::nat, y) ∈ f⟧ ⟹ (xa, y) ∈ :G:⟦A_Lbl x⟧›*) case (A_Cnv e f x y) (*‹⟦graph_homomorphism (translation e) G ?f; (0, ?x) ∈ ?f; (1, ?y) ∈ ?f⟧ ⟹ (?x, ?y) ∈ :G:⟦e⟧› ‹graph_homomorphism (translation (A_Cnv e)) G f› ‹(0, x) ∈ f› ‹(1, y) ∈ f›*) let ?f = "(λ x. if x < 2 then 1 - x else x)" let ?G = "translation e" have i: "graph_homomorphism ?G (map_graph_fn ?G ?f) (on_graph ?G ?f)" using A_Cnv (*‹⟦graph_homomorphism (translation e) G ?f; (0, ?x) ∈ ?f; (1, ?y) ∈ ?f⟧ ⟹ (?x, ?y) ∈ :G:⟦e⟧› ‹graph_homomorphism (translation (A_Cnv e)) G f› ‹(0, x) ∈ f› ‹(1::nat, y::'b) ∈ (f::(nat × 'b) set)›*) by auto have "(0, y) ∈ on_graph ?G ?f O f" "(1, x) ∈ on_graph ?G ?f O f" using A_Cnv.prems(3,2) (*‹(1, y) ∈ f› ‹(0, x) ∈ f›*) apply - (*goals: 1. ‹⟦(1, y) ∈ f; (0, x) ∈ f⟧ ⟹ (0, y) ∈ on_graph (translation e) (λx. if x < 2 then 1 - x else x) O f› 2. ‹⟦(1, y) ∈ f; (0, x) ∈ f⟧ ⟹ (1, x) ∈ on_graph (translation e) (λx. if x < 2 then 1 - x else x) O f› discuss goal 1*) apply ((auto simp:BNF_Def.Gr_def (*‹BNF_Def.Gr ?A ?f = {(a, ?f a) |a. a ∈ ?A}›*) relcomp_def (*‹(O) ≡ λr s. {(xa, x). ((λx xa. (x, xa) ∈ r) OO (λx xa. (x, xa) ∈ s)) xa x}›*))[1]) (*discuss goal 2*) apply ((auto simp:BNF_Def.Gr_def (*‹BNF_Def.Gr ?A ?f = {(a, ?f a) |a. a ∈ ?A}›*) relcomp_def (*‹(O) ≡ λr s. {(xa, x). ((λx xa. (x, xa) ∈ r) OO (λx xa. (x, xa) ∈ s)) xa x}›*))[1]) (*proven 2 subgoals*) . from A_Cnv.hyps(1)[OF graph_homomorphism_composes [ OF i ] this] (*‹graph_homomorphism (map_graph_fn (translation e) (λx. if x < 2 then 1 - x else x)) G f ⟹ (y, x) ∈ :G:⟦e⟧›*) A_Cnv.prems(1) (*‹graph_homomorphism (translation (A_Cnv e)) G f›*) show "?case" (*goal: ‹(x, y) ∈ :G:⟦A_Cnv e⟧›*) by auto next (*goal: ‹⋀x f xa y. ⟦graph_homomorphism (translation (A_Lbl x)) G f; (0, xa) ∈ f; (1, y) ∈ f⟧ ⟹ (xa, y) ∈ :G:⟦A_Lbl x⟧›*) case (A_Lbl l f x y) (*‹graph_homomorphism (translation (A_Lbl l)) G f› ‹(0, x) ∈ f› ‹(1, y) ∈ f›*) hence "edge_preserving f {(l,0,1)} (edges G)" unfolding graph_homomorphism_def (*goal: ‹edge_preserving f {(l, 0, 1)} (edges G)›*) by auto with A_Lbl(2,3) (*‹(0, x) ∈ f› ‹(1, y) ∈ f›*) show "?case" (*goal: ‹(x, y) ∈ :G:⟦A_Lbl l⟧›*) by (auto simp:getRel_def (*‹getRel ?l ?G = {(x, y). (?l, x, y) ∈ edges ?G}›*) edge_preserving_def (*‹edge_preserving ?h ?e1.0 ?e2.0 ≡ ∀(k, v1, v2)∈?e1.0. ∀v1' v2'. (v1, v1') ∈ ?h ∧ (v2, v2') ∈ ?h ⟶ (k, v1', v2') ∈ ?e2.0›*)) qed lemma translation_homomorphism: assumes "graph_homomorphism (translation e) G f" shows "f `` {0} × f `` {1} ⊆ :G:⟦e⟧" ":G:⟦e⟧ ≠ {}" using translation_right_to_left[OF assms] (*‹⟦(0::nat, ?x::'b) ∈ (f::(nat × 'b) set); (1::nat, ?y::'b) ∈ f⟧ ⟹ (?x, ?y) ∈ :G::('a, 'b) labeled_graph:⟦e::'a allegorical_term⟧›*) assms[unfolded graph_homomorphism_def2] (*‹vertices (translation e) = Domain f ∧ univalent f ∧ graph (translation e) ∧ graph G ∧ graph_union (map_graph f (translation e)) G = G›*) verts_in_translation_finite[of e] (*‹finite (vertices (translation (e::'a allegorical_term)))› ‹finite (edges (translation e))› ‹0 ∈ vertices (translation e)› ‹Suc 0 ∈ vertices (translation e)›*) apply - (*goals: 1. ‹⟦⋀x y. ⟦(0, x) ∈ f; (1, y) ∈ f⟧ ⟹ (x, y) ∈ :G:⟦e⟧; vertices (translation e) = Domain f ∧ univalent f ∧ graph (translation e) ∧ graph G ∧ graph_union (map_graph f (translation e)) G = G; finite (vertices (translation e)); finite (edges (translation e)); 0 ∈ vertices (translation e); Suc 0 ∈ vertices (translation e)⟧ ⟹ f `` {0} × f `` {1} ⊆ :G:⟦e⟧› 2. ‹⟦⋀x y. ⟦(0, x) ∈ f; (1, y) ∈ f⟧ ⟹ (x, y) ∈ :G:⟦e⟧; vertices (translation e) = Domain f ∧ univalent f ∧ graph (translation e) ∧ graph G ∧ graph_union (map_graph f (translation e)) G = G; finite (vertices (translation e)); finite (edges (translation e)); 0 ∈ vertices (translation e); Suc 0 ∈ vertices (translation e)⟧ ⟹ :G:⟦e⟧ ≠ {}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) by ((auto)[1]) (*proven 2 subgoals*) text ‹Lemma 5.› lemma translation: assumes "graph G" shows "(x, y) ∈ :G:⟦e⟧ ⟷ (∃ f. graph_homomorphism (translation e) G f ∧ (0,x) ∈ f ∧ (1,y) ∈ f)" (is "?lhs = ?rhs") proof (standard) (*goals: 1. ‹(x, y) ∈ :G:⟦e⟧ ⟹ ∃f. graph_homomorphism (translation e) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f› 2. ‹∃f. graph_homomorphism (translation e) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f ⟹ (x, y) ∈ :G:⟦e⟧›*) have [dest]: "y + card (vertices (translation (e::'a allegorical_term))) - 2 < 2 ⟹ (y::nat) < 2" for y and e using inv_tr_card_min[OF verts_in_translation, of e] (*‹2 ≤ card (vertices (translation e))›*) by linarith { fix y fix e :: "'a allegorical_term" assume "y + card (vertices (translation e)) - 2 ∈ vertices (translation e)" (*‹(y::nat) + card (vertices (translation (e::'a allegorical_term))) - (2::nat) ∈ vertices (translation e)›*) hence "y + card (vertices (translation e)) - 2 < card (vertices (translation e))" using verts_in_translation[of e, unfolded inv_translation_def] (*‹{0..<card (vertices (translation e))} = vertices (translation e) ∧ {0, 1} ⊆ vertices (translation e)›*) by auto hence "y < 2" using inv_tr_card_min[OF verts_in_translation, of e] (*‹2 ≤ card (vertices (translation e))›*) by auto } note [dest !] = this (*‹?ya2 + card (vertices (translation ?ea2)) - 2 ∈ vertices (translation ?ea2) ⟹ ?ya2 < 2›*) { fix y fix e :: "'a allegorical_term" assume "y + card (vertices (translation e)) - Suc 0 ∈ vertices (translation e)" (*‹(y::nat) + card (vertices (translation (e::'a allegorical_term))) - Suc (0::nat) ∈ vertices (translation e)›*) hence "y + card (vertices (translation e)) - Suc 0 ∈ {0..<card (vertices (translation e))}" using verts_in_translation[of e, unfolded inv_translation_def] (*‹{0..<card (vertices (translation e))} = vertices (translation e) ∧ {0, 1} ⊆ vertices (translation e)›*) by simp hence "y = 0" using inv_tr_card_min[OF verts_in_translation, of e] (*‹2 ≤ card (vertices (translation e))›*) by auto } note [dest !] = this (*‹?ya2 + card (vertices (translation ?ea2)) - Suc 0 ∈ vertices (translation ?ea2) ⟹ ?ya2 = 0›*) { fix y fix e :: "'a allegorical_term" assume "card (vertices (translation e)) ∈ vertices (translation e)" (*‹card (vertices (translation (e::'a allegorical_term))) ∈ vertices (translation e)›*) hence "card (vertices (translation e)) ∈ {0..<card (vertices (translation e))}" using verts_in_translation[of e, unfolded inv_translation_def] (*‹{0::nat..<card (vertices (translation (e::'a allegorical_term)))} = vertices (translation e) ∧ {0::nat, 1::nat} ⊆ vertices (translation e)›*) by auto hence False by auto } note [dest !] = this (*‹card (vertices (translation (?ea2::'a::type allegorical_term))) ∈ vertices (translation ?ea2) ⟹ False›*) { fix y fix e :: "'a allegorical_term" assume "y + card (vertices (translation e)) ≤ Suc 0" (*‹(y::nat) + card (vertices (translation (e::'a allegorical_term))) ≤ Suc (0::nat)›*) hence " card (vertices (translation e)) ≤ Suc 0" by auto hence False using inv_tr_card_min[OF verts_in_translation [ of e ]] (*‹2 ≤ card (vertices (translation e))›*) by auto } note [dest !] = this (*‹?ya2 + card (vertices (translation ?ea2)) ≤ Suc 0 ⟹ False›*) assume "?lhs" (*‹(x::'b, y::'b) ∈ :G::('a, 'b) labeled_graph:⟦e::'a allegorical_term⟧›*) then show "?rhs" proof (induct e arbitrary:x y) (*goals: 1. ‹⋀e1 e2 x y. ⟦⋀x y. (x, y) ∈ :G:⟦e1⟧ ⟹ ∃f. graph_homomorphism (translation e1) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f; ⋀x y. (x, y) ∈ :G:⟦e2⟧ ⟹ ∃f. graph_homomorphism (translation e2) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f; (x, y) ∈ :G:⟦A_Int e1 e2⟧⟧ ⟹ ∃f. graph_homomorphism (translation (A_Int e1 e2)) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f› 2. ‹⋀e1 e2 x y. ⟦⋀x y. (x, y) ∈ :G:⟦e1⟧ ⟹ ∃f. graph_homomorphism (translation e1) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f; ⋀x y. (x, y) ∈ :G:⟦e2⟧ ⟹ ∃f. graph_homomorphism (translation e2) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f; (x, y) ∈ :G:⟦A_Cmp e1 e2⟧⟧ ⟹ ∃f. graph_homomorphism (translation (A_Cmp e1 e2)) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f› 3. ‹⋀e x y. ⟦⋀x y. (x, y) ∈ :G:⟦e⟧ ⟹ ∃f. graph_homomorphism (translation e) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f; (x, y) ∈ :G:⟦A_Cnv e⟧⟧ ⟹ ∃f. graph_homomorphism (translation (A_Cnv e)) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f› 4. ‹⋀x xa y. (xa, y) ∈ :G:⟦A_Lbl x⟧ ⟹ ∃f. graph_homomorphism (translation (A_Lbl x)) G f ∧ (0, xa) ∈ f ∧ (1, y) ∈ f›*) case (A_Int e₁ e₂) (*‹(?x, ?y) ∈ :G:⟦e₁⟧ ⟹ ∃f. graph_homomorphism (translation e₁) G f ∧ (0, ?x) ∈ f ∧ (1, ?y) ∈ f› ‹(?x::'b, ?y::'b) ∈ :G::('a, 'b) labeled_graph:⟦e₂::'a allegorical_term⟧ ⟹ ∃f::(nat × 'b) set. graph_homomorphism (translation e₂) G f ∧ (0::nat, ?x) ∈ f ∧ (1::nat, ?y) ∈ f› ‹(x::'b, y::'b) ∈ :G::('a, 'b) labeled_graph:⟦A_Int (e₁::'a allegorical_term) (e₂::'a allegorical_term)⟧›*) from A_Int (*‹(?x, ?y) ∈ :G:⟦e₁⟧ ⟹ ∃f. graph_homomorphism (translation e₁) G f ∧ (0, ?x) ∈ f ∧ (1, ?y) ∈ f› ‹(?x, ?y) ∈ :G:⟦e₂⟧ ⟹ ∃f. graph_homomorphism (translation e₂) G f ∧ (0, ?x) ∈ f ∧ (1, ?y) ∈ f› ‹(x, y) ∈ :G:⟦A_Int e₁ e₂⟧›*) have assm: "(x, y) ∈ :G:⟦e₁⟧" "(x, y) ∈ :G:⟦e₂⟧" apply - (*goals: 1. ‹⟦⋀x y. (x, y) ∈ :G:⟦e₁⟧ ⟹ ∃f. graph_homomorphism (translation e₁) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f; ⋀x y. (x, y) ∈ :G:⟦e₂⟧ ⟹ ∃f. graph_homomorphism (translation e₂) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f; (x, y) ∈ :G:⟦A_Int e₁ e₂⟧⟧ ⟹ (x, y) ∈ :G:⟦e₁⟧› 2. ‹⟦⋀x y. (x, y) ∈ :G:⟦e₁⟧ ⟹ ∃f. graph_homomorphism (translation e₁) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f; ⋀x y. (x, y) ∈ :G:⟦e₂⟧ ⟹ ∃f. graph_homomorphism (translation e₂) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f; (x, y) ∈ :G:⟦A_Int e₁ e₂⟧⟧ ⟹ (x, y) ∈ :G:⟦e₂⟧› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . from A_Int(1)[OF assm ( 1 )] (*‹∃f. graph_homomorphism (translation e₁) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f›*) obtain f₁ where "f₁": "graph_homomorphism (translation e₁) G f₁" "(0, x) ∈ f₁" "(1, y) ∈ f₁" (*goal: ‹(⋀f₁. ⟦graph_homomorphism (translation e₁) G f₁; (0, x) ∈ f₁; (1, y) ∈ f₁⟧ ⟹ thesis) ⟹ thesis›*) by auto from A_Int(2)[OF assm ( 2 )] (*‹∃f. graph_homomorphism (translation e₂) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f›*) obtain f₂ where "f₂": "graph_homomorphism (translation e₂) G f₂" "(0, x) ∈ f₂" "(1, y) ∈ f₂" (*goal: ‹(⋀f₂::(nat × 'b) set. ⟦graph_homomorphism (translation (e₂::'a allegorical_term)) (G::('a, 'b) labeled_graph) f₂; (0::nat, x::'b) ∈ f₂; (1::nat, y::'b) ∈ f₂⟧ ⟹ thesis::bool) ⟹ thesis›*) by auto from "f₁" (*‹graph_homomorphism (translation e₁) G f₁› ‹(0, x) ∈ f₁› ‹(1, y) ∈ f₁›*) "f₂" (*‹graph_homomorphism (translation e₂) G f₂› ‹(0, x) ∈ f₂› ‹(1, y) ∈ f₂›*) have v: "Domain f₁ = vertices (translation e₁)" "Domain f₂ = vertices (translation e₂)" unfolding graph_homomorphism_def (*goals: 1. ‹Domain f₁ = vertices (translation e₁)› 2. ‹Domain f₂ = vertices (translation e₂)›*) apply - (*goals: 1. ‹⟦vertices (translation (e₁::'a allegorical_term)) = Domain (f₁::(nat × 'b) set) ∧ graph (translation e₁) ∧ graph (G::('a, 'b) labeled_graph) ∧ f₁ `` vertices (translation e₁) ⊆ vertices G ∧ univalent f₁ ∧ edge_preserving f₁ (edges (translation e₁)) (edges G); (0::nat, x::'b) ∈ f₁; (1::nat, y::'b) ∈ f₁; vertices (translation (e₂::'a allegorical_term)) = Domain (f₂::(nat × 'b) set) ∧ graph (translation e₂) ∧ graph G ∧ f₂ `` vertices (translation e₂) ⊆ vertices G ∧ univalent f₂ ∧ edge_preserving f₂ (edges (translation e₂)) (edges G); (0::nat, x) ∈ f₂; (1::nat, y) ∈ f₂⟧ ⟹ Domain f₁ = vertices (translation e₁)› 2. ‹⟦vertices (translation (e₁::'a allegorical_term)) = Domain (f₁::(nat × 'b) set) ∧ graph (translation e₁) ∧ graph (G::('a, 'b) labeled_graph) ∧ f₁ `` vertices (translation e₁) ⊆ vertices G ∧ univalent f₁ ∧ edge_preserving f₁ (edges (translation e₁)) (edges G); (0::nat, x::'b) ∈ f₁; (1::nat, y::'b) ∈ f₁; vertices (translation (e₂::'a allegorical_term)) = Domain (f₂::(nat × 'b) set) ∧ graph (translation e₂) ∧ graph G ∧ f₂ `` vertices (translation e₂) ⊆ vertices G ∧ univalent f₂ ∧ edge_preserving f₂ (edges (translation e₂)) (edges G); (0::nat, x) ∈ f₂; (1::nat, y) ∈ f₂⟧ ⟹ Domain f₂ = vertices (translation e₂)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . let ?f₂ = "(λ x. if x < 2 then x else x + card (vertices (translation e₁)) - 2)" let ?tr₂ = "on_graph (translation e₂) ?f₂" have inj2: "inj_on ?f₂ (vertices (translation e₂))" unfolding inj_on_def (*goal: ‹∀x∈vertices (translation e₂). ∀y∈vertices (translation e₂). (if x < 2 then x else x + card (vertices (translation e₁)) - 2) = (if y < 2 then y else y + card (vertices (translation e₁)) - 2) ⟶ x = y›*) by auto have "(0,0) ∈ ?tr₂¯" "(1,1) ∈ ?tr₂¯" (*goals: 1. ‹(0, 0) ∈ (on_graph (translation e₂) (λx. if x < 2 then x else x + card (vertices (translation e₁)) - 2))¯› 2. ‹(1, 1) ∈ (on_graph (translation e₂) (λx. if x < 2 then x else x + card (vertices (translation e₁)) - 2))¯› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . from this[THEN relcompI] (*‹(0, ?c) ∈ ?s ⟹ (0, ?c) ∈ (on_graph (translation e₂) (λx. if x < 2 then x else x + card (vertices (translation e₁)) - 2))¯ O ?s› ‹(1, ?c) ∈ ?s ⟹ (1, ?c) ∈ (on_graph (translation e₂) (λx. if x < 2 then x else x + card (vertices (translation e₁)) - 2))¯ O ?s›*) "f₂"(2,3) (*‹(0, x) ∈ f₂› ‹(1, y) ∈ f₂›*) have zero_one: "(0,x) ∈ ?tr₂¯ O f₂" "(1,y) ∈ ?tr₂¯ O f₂" apply - (*goals: 1. ‹⟦⋀c s. (0, c) ∈ s ⟹ (0, c) ∈ (on_graph (translation e₂) (λx. if x < 2 then x else x + card (vertices (translation e₁)) - 2))¯ O s; ⋀c s. (1, c) ∈ s ⟹ (1, c) ∈ (on_graph (translation e₂) (λx. if x < 2 then x else x + card (vertices (translation e₁)) - 2))¯ O s; (0, x) ∈ f₂; (1, y) ∈ f₂⟧ ⟹ (0, x) ∈ (on_graph (translation e₂) (λx. if x < 2 then x else x + card (vertices (translation e₁)) - 2))¯ O f₂› 2. ‹⟦⋀c s. (0, c) ∈ s ⟹ (0, c) ∈ (on_graph (translation e₂) (λx. if x < 2 then x else x + card (vertices (translation e₁)) - 2))¯ O s; ⋀c s. (1, c) ∈ s ⟹ (1, c) ∈ (on_graph (translation e₂) (λx. if x < 2 then x else x + card (vertices (translation e₁)) - 2))¯ O s; (0, x) ∈ f₂; (1, y) ∈ f₂⟧ ⟹ (1, y) ∈ (on_graph (translation e₂) (λx. if x < 2 then x else x + card (vertices (translation e₁)) - 2))¯ O f₂› discuss goal 1*) apply ((auto)[1]) (*top goal: ‹⟦⋀(c::?'c6) s::(nat × ?'c6) set. (0::nat, c) ∈ s ⟹ (0::nat, c) ∈ (on_graph (translation (e₂::'a allegorical_term)) (λx::nat. if x < (2::nat) then x else x + card (vertices (translation (e₁::'a allegorical_term))) - (2::nat)))¯ O s; ⋀(c::?'c8) s::(nat × ?'c8) set. (1::nat, c) ∈ s ⟹ (1::nat, c) ∈ (on_graph (translation e₂) (λx::nat. if x < (2::nat) then x else x + card (vertices (translation e₁)) - (2::nat)))¯ O s; (0::nat, x::'b) ∈ (f₂::(nat × 'b) set); (1::nat, y::'b) ∈ f₂⟧ ⟹ (0::nat, x) ∈ (on_graph (translation e₂) (λx::nat. if x < (2::nat) then x else x + card (vertices (translation e₁)) - (2::nat)))¯ O f₂› and 1 goal remains*) apply ((assumption)[1]) (*discuss goal 2*) by ((auto)[1]) (*proven 2 subgoals*) { fix yb and zb assume "(yb + card (vertices (translation e₁)) - 2, zb) ∈ f₁" (*‹((yb::nat) + card (vertices (translation (e₁::'a allegorical_term))) - (2::nat), zb::'b) ∈ (f₁::(nat × 'b) set)›*) hence "yb + card (vertices (translation e₁)) - 2 ∈ vertices (translation e₁)" using v (*‹Domain f₁ = vertices (translation e₁)› ‹Domain f₂ = vertices (translation e₂)›*) by auto } note in_f[dest !] = this (*‹(?yb2 + card (vertices (translation e₁)) - 2, ?zb2) ∈ f₁ ⟹ ?yb2 + card (vertices (translation e₁)) - 2 ∈ vertices (translation e₁)›*) have d_a: "Domain f₁ ∩ Domain (?tr₂¯ O f₂) = {0,1}" using zero_one (*‹(0::nat, x::'b::type) ∈ (on_graph (translation (e₂::'a::type allegorical_term)) (λx::nat. if x < (2::nat) then x else x + card (vertices (translation (e₁::'a::type allegorical_term))) - (2::nat)))¯ O (f₂::(nat × 'b::type) set)› ‹(1, y) ∈ (on_graph (translation e₂) (λx. if x < 2 then x else x + card (vertices (translation e₁)) - 2))¯ O f₂›*) by (auto simp:v (*‹Domain (f₁::(nat × 'b) set) = vertices (translation (e₁::'a allegorical_term))› ‹Domain (f₂::(nat × 'b) set) = vertices (translation (e₂::'a allegorical_term))›*)) have d_b: "Domain (f₁ ∩ ?tr₂¯ O f₂) = {0,1}" using zero_one (*‹(0, x) ∈ (on_graph (translation e₂) (λx. if x < 2 then x else x + card (vertices (translation e₁)) - 2))¯ O f₂› ‹(1::nat, y::'b) ∈ (on_graph (translation (e₂::'a allegorical_term)) (λx::nat. if x < (2::nat) then x else x + card (vertices (translation (e₁::'a allegorical_term))) - (2::nat)))¯ O (f₂::(nat × 'b) set)›*) "f₁"(2,3) (*‹(0, x) ∈ f₁› ‹(1, y) ∈ f₁›*) by auto note cmp2 = graph_homomorphism_composes[OF graph_homo_inv [ OF translation_graph inj2 ] f₂ ( 1 )] (*‹graph_homomorphism (map_graph_fn (translation (e₂::'a allegorical_term)) (λx::nat. if x < (2::nat) then x else x + card (vertices (translation (e₁::'a allegorical_term))) - (2::nat))) (G::('a, 'b) labeled_graph) ((on_graph (translation e₂) (λx::nat. if x < (2::nat) then x else x + card (vertices (translation e₁)) - (2::nat)))¯ O (f₂::(nat × 'b) set))›*) have "graph_homomorphism (translation (A_Int e₁ e₂)) G (f₁ ∪ ?tr₂¯ O f₂)" using graph_homo_union[OF f₁ ( 1 ) cmp2 d_a [ folded d_b ]] (*‹graph_homomorphism (graph_union (translation e₁) (map_graph_fn (translation e₂) (λx. if x < 2 then x else x + card (vertices (translation e₁)) - 2))) G (f₁ ∪ (on_graph (translation e₂) (λx. if x < 2 then x else x + card (vertices (translation e₁)) - 2))¯ O f₂)›*) by (auto simp:Let_def (*‹Let (?s::?'a::type) (?f::?'a::type ⇒ ?'b::type) ≡ ?f ?s›*)) thus "?case" (*goal: ‹∃f. graph_homomorphism (translation (A_Int e₁ e₂)) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f›*) using zero_one[THEN UnI2 [ of _ _ "f₁" ]] (*‹(0, x) ∈ f₁ ∪ (on_graph (translation e₂) (λx. if x < 2 then x else x + card (vertices (translation e₁)) - 2))¯ O f₂› ‹(1, y) ∈ f₁ ∪ (on_graph (translation e₂) (λx. if x < 2 then x else x + card (vertices (translation e₁)) - 2))¯ O f₂›*) by blast next (*goals: 1. ‹⋀e1 e2 x y. ⟦⋀x y. (x, y) ∈ :G:⟦e1⟧ ⟹ ∃f. graph_homomorphism (translation e1) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f; ⋀x y. (x, y) ∈ :G:⟦e2⟧ ⟹ ∃f. graph_homomorphism (translation e2) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f; (x, y) ∈ :G:⟦A_Cmp e1 e2⟧⟧ ⟹ ∃f. graph_homomorphism (translation (A_Cmp e1 e2)) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f› 2. ‹⋀e x y. ⟦⋀x y. (x, y) ∈ :G:⟦e⟧ ⟹ ∃f. graph_homomorphism (translation e) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f; (x, y) ∈ :G:⟦A_Cnv e⟧⟧ ⟹ ∃f. graph_homomorphism (translation (A_Cnv e)) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f› 3. ‹⋀x xa y. (xa, y) ∈ :G:⟦A_Lbl x⟧ ⟹ ∃f. graph_homomorphism (translation (A_Lbl x)) G f ∧ (0, xa) ∈ f ∧ (1, y) ∈ f›*) case (A_Cmp e₁ e₂) (*‹(?x, ?y) ∈ :G:⟦e₁⟧ ⟹ ∃f. graph_homomorphism (translation e₁) G f ∧ (0, ?x) ∈ f ∧ (1, ?y) ∈ f› ‹(?x::'b, ?y::'b) ∈ :G::('a, 'b) labeled_graph:⟦e₂::'a allegorical_term⟧ ⟹ ∃f::(nat × 'b) set. graph_homomorphism (translation e₂) G f ∧ (0::nat, ?x) ∈ f ∧ (1::nat, ?y) ∈ f› ‹(x::'b, y::'b) ∈ :G::('a, 'b) labeled_graph:⟦A_Cmp (e₁::'a allegorical_term) (e₂::'a allegorical_term)⟧›*) from A_Cmp (*‹(?x, ?y) ∈ :G:⟦e₁⟧ ⟹ ∃f. graph_homomorphism (translation e₁) G f ∧ (0, ?x) ∈ f ∧ (1, ?y) ∈ f› ‹(?x, ?y) ∈ :G:⟦e₂⟧ ⟹ ∃f. graph_homomorphism (translation e₂) G f ∧ (0, ?x) ∈ f ∧ (1, ?y) ∈ f› ‹(x, y) ∈ :G:⟦A_Cmp e₁ e₂⟧›*) obtain z where assm: "(x, z) ∈ :G:⟦e₁⟧" "(z, y) ∈ :G:⟦e₂⟧" (*goal: ‹(⋀z. ⟦(x, z) ∈ :G:⟦e₁⟧; (z, y) ∈ :G:⟦e₂⟧⟧ ⟹ thesis) ⟹ thesis›*) by auto from A_Cmp(1)[OF assm ( 1 )] (*‹∃f::(nat × 'b::type) set. graph_homomorphism (translation (e₁::'a::type allegorical_term)) (G::('a::type, 'b::type) labeled_graph) f ∧ (0::nat, x::'b::type) ∈ f ∧ (1::nat, z::'b::type) ∈ f›*) obtain f₁ where "f₁": "graph_homomorphism (translation e₁) G f₁" "(0, x) ∈ f₁" "(1, z) ∈ f₁" (*goal: ‹(⋀f₁. ⟦graph_homomorphism (translation e₁) G f₁; (0, x) ∈ f₁; (1, z) ∈ f₁⟧ ⟹ thesis) ⟹ thesis›*) by auto from A_Cmp(2)[OF assm ( 2 )] (*‹∃f. graph_homomorphism (translation e₂) G f ∧ (0, z) ∈ f ∧ (1, y) ∈ f›*) obtain f₂ where "f₂": "graph_homomorphism (translation e₂) G f₂" "(0, z) ∈ f₂" "(1, y) ∈ f₂" (*goal: ‹(⋀f₂::(nat × 'b) set. ⟦graph_homomorphism (translation (e₂::'a allegorical_term)) (G::('a, 'b) labeled_graph) f₂; (0::nat, z::'b) ∈ f₂; (1::nat, y::'b) ∈ f₂⟧ ⟹ thesis::bool) ⟹ thesis›*) by auto from "f₁" (*‹graph_homomorphism (translation e₁) G f₁› ‹(0, x) ∈ f₁› ‹(1, z) ∈ f₁›*) "f₂" (*‹graph_homomorphism (translation e₂) G f₂› ‹(0, z) ∈ f₂› ‹(1, y) ∈ f₂›*) have v: "Domain f₁ = vertices (translation e₁)" "Domain f₂ = vertices (translation e₂)" unfolding graph_homomorphism_def (*goals: 1. ‹Domain f₁ = vertices (translation e₁)› 2. ‹Domain f₂ = vertices (translation e₂)›*) apply - (*goals: 1. ‹⟦vertices (translation e₁) = Domain f₁ ∧ graph (translation e₁) ∧ graph G ∧ f₁ `` vertices (translation e₁) ⊆ vertices G ∧ univalent f₁ ∧ edge_preserving f₁ (edges (translation e₁)) (edges G); (0, x) ∈ f₁; (1, z) ∈ f₁; vertices (translation e₂) = Domain f₂ ∧ graph (translation e₂) ∧ graph G ∧ f₂ `` vertices (translation e₂) ⊆ vertices G ∧ univalent f₂ ∧ edge_preserving f₂ (edges (translation e₂)) (edges G); (0, z) ∈ f₂; (1, y) ∈ f₂⟧ ⟹ Domain f₁ = vertices (translation e₁)› 2. ‹⟦vertices (translation e₁) = Domain f₁ ∧ graph (translation e₁) ∧ graph G ∧ f₁ `` vertices (translation e₁) ⊆ vertices G ∧ univalent f₁ ∧ edge_preserving f₁ (edges (translation e₁)) (edges G); (0, x) ∈ f₁; (1, z) ∈ f₁; vertices (translation e₂) = Domain f₂ ∧ graph (translation e₂) ∧ graph G ∧ f₂ `` vertices (translation e₂) ⊆ vertices G ∧ univalent f₂ ∧ edge_preserving f₂ (edges (translation e₂)) (edges G); (0, z) ∈ f₂; (1, y) ∈ f₂⟧ ⟹ Domain f₂ = vertices (translation e₂)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . let ?f₁ = "(λ x. if x=0 then 0 else x+card(vertices (translation e₂))-1)" let ?f₂ = "(λ x. if x=0 then card (vertices (translation e₂)) else x)" let ?tr₁ = "on_graph (translation e₁) ?f₁" let ?tr₂ = "on_graph (translation e₂) ?f₂" have inj1: "inj_on ?f₁ (vertices (translation e₁))" unfolding inj_on_def (*goal: ‹∀x∈vertices (translation e₁). ∀y∈vertices (translation e₁). (if x = 0 then 0 else x + card (vertices (translation e₂)) - 1) = (if y = 0 then 0 else y + card (vertices (translation e₂)) - 1) ⟶ x = y›*) by auto have inj2: "inj_on ?f₂ (vertices (translation e₂))" unfolding inj_on_def (*goal: ‹∀x::nat∈vertices (translation (e₂::'a allegorical_term)). ∀y::nat∈vertices (translation e₂). (if x = (0::nat) then card (vertices (translation e₂)) else x) = (if y = (0::nat) then card (vertices (translation e₂)) else y) ⟶ x = y›*) by auto have "(card (vertices (translation e₂)),0) ∈ ?tr₂¯" "(1,1) ∈ ?tr₂¯" "(0,0) ∈ ?tr₁¯" "(card (vertices (translation e₂)),1) ∈ ?tr₁¯" (*goals: 1. ‹(card (vertices (translation e₂)), 0) ∈ (on_graph (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x))¯› 2. ‹(1, 1) ∈ (on_graph (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x))¯› 3. ‹(0, 0) ∈ (on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯› 4. ‹(card (vertices (translation e₂)), 1) ∈ (on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . from this[THEN relcompI] (*‹(0::nat, ?c::?'c) ∈ (?s::(nat × ?'c) set) ⟹ (card (vertices (translation (e₂::'a allegorical_term))), ?c) ∈ (on_graph (translation e₂) (λx::nat. if x = (0::nat) then card (vertices (translation e₂)) else x))¯ O ?s› ‹(1, ?c) ∈ ?s ⟹ (1, ?c) ∈ (on_graph (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x))¯ O ?s› ‹(0, ?c) ∈ ?s ⟹ (0, ?c) ∈ (on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯ O ?s› ‹(1, ?c) ∈ ?s ⟹ (card (vertices (translation e₂)), ?c) ∈ (on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯ O ?s›*) "f₂"(2,3) (*‹(0, z) ∈ f₂› ‹(1, y) ∈ f₂›*) "f₁"(2,3) (*‹(0, x) ∈ f₁› ‹(1, z) ∈ f₁›*) have zero_one: "(card (vertices (translation e₂)),z) ∈ ?tr₁¯ O f₁" "(0,x) ∈ ?tr₁¯ O f₁" "(card (vertices (translation e₂)),z) ∈ ?tr₂¯ O f₂" "(1,y) ∈ ?tr₂¯ O f₂" apply - (*goals: 1. ‹⟦⋀c s. (0, c) ∈ s ⟹ (card (vertices (translation e₂)), c) ∈ (on_graph (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x))¯ O s; ⋀c s. (1, c) ∈ s ⟹ (1, c) ∈ (on_graph (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x))¯ O s; ⋀c s. (0, c) ∈ s ⟹ (0, c) ∈ (on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯ O s; ⋀c s. (1, c) ∈ s ⟹ (card (vertices (translation e₂)), c) ∈ (on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯ O s; (0, z) ∈ f₂; (1, y) ∈ f₂; (0, x) ∈ f₁; (1, z) ∈ f₁⟧ ⟹ (card (vertices (translation e₂)), z) ∈ (on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯ O f₁› 2. ‹⟦⋀c s. (0, c) ∈ s ⟹ (card (vertices (translation e₂)), c) ∈ (on_graph (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x))¯ O s; ⋀c s. (1, c) ∈ s ⟹ (1, c) ∈ (on_graph (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x))¯ O s; ⋀c s. (0, c) ∈ s ⟹ (0, c) ∈ (on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯ O s; ⋀c s. (1, c) ∈ s ⟹ (card (vertices (translation e₂)), c) ∈ (on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯ O s; (0, z) ∈ f₂; (1, y) ∈ f₂; (0, x) ∈ f₁; (1, z) ∈ f₁⟧ ⟹ (0, x) ∈ (on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯ O f₁› 3. ‹⟦⋀c s. (0, c) ∈ s ⟹ (card (vertices (translation e₂)), c) ∈ (on_graph (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x))¯ O s; ⋀c s. (1, c) ∈ s ⟹ (1, c) ∈ (on_graph (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x))¯ O s; ⋀c s. (0, c) ∈ s ⟹ (0, c) ∈ (on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯ O s; ⋀c s. (1, c) ∈ s ⟹ (card (vertices (translation e₂)), c) ∈ (on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯ O s; (0, z) ∈ f₂; (1, y) ∈ f₂; (0, x) ∈ f₁; (1, z) ∈ f₁⟧ ⟹ (card (vertices (translation e₂)), z) ∈ (on_graph (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x))¯ O f₂› 4. ‹⟦⋀c s. (0, c) ∈ s ⟹ (card (vertices (translation e₂)), c) ∈ (on_graph (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x))¯ O s; ⋀c s. (1, c) ∈ s ⟹ (1, c) ∈ (on_graph (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x))¯ O s; ⋀c s. (0, c) ∈ s ⟹ (0, c) ∈ (on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯ O s; ⋀c s. (1, c) ∈ s ⟹ (card (vertices (translation e₂)), c) ∈ (on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯ O s; (0, z) ∈ f₂; (1, y) ∈ f₂; (0, x) ∈ f₁; (1, z) ∈ f₁⟧ ⟹ (1, y) ∈ (on_graph (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x))¯ O f₂› discuss goal 1*) apply ((auto)[1]) (*top goal: ‹⟦⋀c s. (0, c) ∈ s ⟹ (card (vertices (translation e₂)), c) ∈ (on_graph (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x))¯ O s; ⋀c s. (1, c) ∈ s ⟹ (1, c) ∈ (on_graph (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x))¯ O s; ⋀c s. (0, c) ∈ s ⟹ (0, c) ∈ (on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯ O s; ⋀c s. (1, c) ∈ s ⟹ (card (vertices (translation e₂)), c) ∈ (on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯ O s; (0, z) ∈ f₂; (1, y) ∈ f₂; (0, x) ∈ f₁; (1, z) ∈ f₁⟧ ⟹ (card (vertices (translation e₂)), z) ∈ (on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯ O f₁› and 3 goals remain*) apply ((assumption)[1]) (*discuss goal 2*) apply ((auto)[1]) (*top goal: ‹⟦⋀(c::?'c24) s::(nat × ?'c24) set. (0::nat, c) ∈ s ⟹ (card (vertices (translation (e₂::'a allegorical_term))), c) ∈ (on_graph (translation e₂) (λx::nat. if x = (0::nat) then card (vertices (translation e₂)) else x))¯ O s; ⋀(c::?'c26) s::(nat × ?'c26) set. (1::nat, c) ∈ s ⟹ (1::nat, c) ∈ (on_graph (translation e₂) (λx::nat. if x = (0::nat) then card (vertices (translation e₂)) else x))¯ O s; ⋀(c::?'c28) s::(nat × ?'c28) set. (0::nat, c) ∈ s ⟹ (0::nat, c) ∈ (on_graph (translation (e₁::'a allegorical_term)) (λx::nat. if x = (0::nat) then 0::nat else x + card (vertices (translation e₂)) - (1::nat)))¯ O s; ⋀(c::?'c30) s::(nat × ?'c30) set. (1::nat, c) ∈ s ⟹ (card (vertices (translation e₂)), c) ∈ (on_graph (translation e₁) (λx::nat. if x = (0::nat) then 0::nat else x + card (vertices (translation e₂)) - (1::nat)))¯ O s; (0::nat, z::'b) ∈ (f₂::(nat × 'b) set); (1::nat, y::'b) ∈ f₂; (0::nat, x::'b) ∈ (f₁::(nat × 'b) set); (1::nat, z) ∈ f₁⟧ ⟹ (0::nat, x) ∈ (on_graph (translation e₁) (λx::nat. if x = (0::nat) then 0::nat else x + card (vertices (translation e₂)) - (1::nat)))¯ O f₁› and 2 goals remain*) apply ((assumption)[1]) (*discuss goal 3*) apply ((auto)[1]) (*top goal: ‹⟦⋀(c::?'c12) s::(nat × ?'c12) set. (0::nat, c) ∈ s ⟹ (card (vertices (translation (e₂::'a allegorical_term))), c) ∈ (on_graph (translation e₂) (λx::nat. if x = (0::nat) then card (vertices (translation e₂)) else x))¯ O s; ⋀(c::?'c14) s::(nat × ?'c14) set. (1::nat, c) ∈ s ⟹ (1::nat, c) ∈ (on_graph (translation e₂) (λx::nat. if x = (0::nat) then card (vertices (translation e₂)) else x))¯ O s; ⋀(c::?'c16) s::(nat × ?'c16) set. (0::nat, c) ∈ s ⟹ (0::nat, c) ∈ (on_graph (translation (e₁::'a allegorical_term)) (λx::nat. if x = (0::nat) then 0::nat else x + card (vertices (translation e₂)) - (1::nat)))¯ O s; ⋀(c::?'c18) s::(nat × ?'c18) set. (1::nat, c) ∈ s ⟹ (card (vertices (translation e₂)), c) ∈ (on_graph (translation e₁) (λx::nat. if x = (0::nat) then 0::nat else x + card (vertices (translation e₂)) - (1::nat)))¯ O s; (0::nat, z::'b) ∈ (f₂::(nat × 'b) set); (1::nat, y::'b) ∈ f₂; (0::nat, x::'b) ∈ (f₁::(nat × 'b) set); (1::nat, z) ∈ f₁⟧ ⟹ (card (vertices (translation e₂)), z) ∈ (on_graph (translation e₂) (λx::nat. if x = (0::nat) then card (vertices (translation e₂)) else x))¯ O f₂› and 1 goal remains*) apply ((assumption)[1]) (*discuss goal 4*) by ((auto)[1]) (*proven 4 subgoals*) have [simp]: "ye ∈ vertices (translation e₂) ⟹ (if ye = 0 then card (vertices (translation e₂)) else ye) = (if yd = 0 then 0 else yd + card (vertices (translation e₂)) - 1) ⟷ ye = 0 ∧ yd = 1" for ye and yd using v (*‹Domain f₁ = vertices (translation e₁)› ‹Domain f₂ = vertices (translation e₂)›*) inv_tr_card_min[OF verts_in_translation, of "e₂"] (*‹(2::nat) ≤ card (vertices (translation (e₂::'a allegorical_term)))›*) apply ((cases "ye=0")[1]) (*goals: 1. ‹⟦ye ∈ vertices (translation e₂); Domain f₁ = vertices (translation e₁); Domain f₂ = vertices (translation e₂); 2 ≤ card (vertices (translation e₂)); ye = 0⟧ ⟹ ((if ye = 0 then card (vertices (translation e₂)) else ye) = (if yd = 0 then 0 else yd + card (vertices (translation e₂)) - 1)) = (ye = 0 ∧ yd = 1)› 2. ‹⟦ye ∈ vertices (translation e₂); Domain f₁ = vertices (translation e₁); Domain f₂ = vertices (translation e₂); 2 ≤ card (vertices (translation e₂)); ye ≠ 0⟧ ⟹ ((if ye = 0 then card (vertices (translation e₂)) else ye) = (if yd = 0 then 0 else yd + card (vertices (translation e₂)) - 1)) = (ye = 0 ∧ yd = 1)› discuss goal 1*) apply ((cases "yd=0")[1]) (*goals: 1. ‹⟦(ye::nat) ∈ vertices (translation (e₂::'a::type allegorical_term)); Domain (f₁::(nat × 'b::type) set) = vertices (translation (e₁::'a::type allegorical_term)); Domain (f₂::(nat × 'b::type) set) = vertices (translation e₂); (2::nat) ≤ card (vertices (translation e₂)); ye = (0::nat); (yd::nat) = (0::nat)⟧ ⟹ ((if ye = (0::nat) then card (vertices (translation e₂)) else ye) = (if yd = (0::nat) then 0::nat else yd + card (vertices (translation e₂)) - (1::nat))) = (ye = (0::nat) ∧ yd = (1::nat))› 2. ‹⟦(ye::nat) ∈ vertices (translation (e₂::'a::type allegorical_term)); Domain (f₁::(nat × 'b::type) set) = vertices (translation (e₁::'a::type allegorical_term)); Domain (f₂::(nat × 'b::type) set) = vertices (translation e₂); (2::nat) ≤ card (vertices (translation e₂)); ye = (0::nat); (yd::nat) ≠ (0::nat)⟧ ⟹ ((if ye = (0::nat) then card (vertices (translation e₂)) else ye) = (if yd = (0::nat) then 0::nat else yd + card (vertices (translation e₂)) - (1::nat))) = (ye = (0::nat) ∧ yd = (1::nat))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply ((cases "yd=0")[1]) (*goals: 1. ‹⟦ye ∈ vertices (translation e₂); Domain f₁ = vertices (translation e₁); Domain f₂ = vertices (translation e₂); 2 ≤ card (vertices (translation e₂)); ye ≠ 0; yd = 0⟧ ⟹ ((if ye = 0 then card (vertices (translation e₂)) else ye) = (if yd = 0 then 0 else yd + card (vertices (translation e₂)) - 1)) = (ye = 0 ∧ yd = 1)› 2. ‹⟦ye ∈ vertices (translation e₂); Domain f₁ = vertices (translation e₁); Domain f₂ = vertices (translation e₂); 2 ≤ card (vertices (translation e₂)); ye ≠ 0; yd ≠ 0⟧ ⟹ ((if ye = 0 then card (vertices (translation e₂)) else ye) = (if yd = 0 then 0 else yd + card (vertices (translation e₂)) - 1)) = (ye = 0 ∧ yd = 1)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) . have d_a: "Domain (?tr₁¯ O f₁) ∩ Domain (?tr₂¯ O f₂) = {card (vertices (translation e₂))}" using zero_one (*‹(card (vertices (translation e₂)), z) ∈ (on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯ O f₁› ‹(0, x) ∈ (on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯ O f₁› ‹(card (vertices (translation e₂)), z) ∈ (on_graph (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x))¯ O f₂› ‹(1::nat, y::'b::type) ∈ (on_graph (translation (e₂::'a::type allegorical_term)) (λx::nat. if x = (0::nat) then card (vertices (translation e₂)) else x))¯ O (f₂::(nat × 'b::type) set)›*) using [simproc del : defined_all] (*‹TERM _›*) by (auto simp: v (*‹Domain f₁ = vertices (translation e₁)› ‹Domain f₂ = vertices (translation e₂)›*)) have d_b: "Domain (?tr₁¯ O f₁ ∩ ?tr₂¯ O f₂) = {card (vertices (translation e₂))}" using zero_one (*‹(card (vertices (translation (e₂::'a allegorical_term))), z::'b) ∈ (on_graph (translation (e₁::'a allegorical_term)) (λx::nat. if x = (0::nat) then 0::nat else x + card (vertices (translation e₂)) - (1::nat)))¯ O (f₁::(nat × 'b) set)› ‹(0, x) ∈ (on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯ O f₁› ‹(card (vertices (translation e₂)), z) ∈ (on_graph (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x))¯ O f₂› ‹(1::nat, y::'b::type) ∈ (on_graph (translation (e₂::'a::type allegorical_term)) (λx::nat. if x = (0::nat) then card (vertices (translation e₂)) else x))¯ O (f₂::(nat × 'b::type) set)›*) "f₁"(2,3) (*‹(0, x) ∈ f₁› ‹(1, z) ∈ f₁›*) using [simproc del : defined_all] (*‹TERM _›*) by auto note cmp1 = graph_homomorphism_composes[OF graph_homo_inv [ OF translation_graph inj1 ] f₁ ( 1 )] (*‹graph_homomorphism (map_graph_fn (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1)) G ((on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯ O f₁)›*) note cmp2 = graph_homomorphism_composes[OF graph_homo_inv [ OF translation_graph inj2 ] f₂ ( 1 )] (*‹graph_homomorphism (map_graph_fn (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x)) G ((on_graph (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x))¯ O f₂)›*) have "graph_homomorphism (translation (A_Cmp e₁ e₂)) G (?tr₁¯ O f₁ ∪ ?tr₂¯ O f₂)" unfolding Let_def translation.simps (*goal: ‹graph_homomorphism (graph_union (map_graph_fn (translation (e₁::'a allegorical_term)) (λx::nat. if x = (0::nat) then 0::nat else x + card (vertices (translation (e₂::'a allegorical_term))) - (1::nat))) (map_graph_fn (translation e₂) (λx::nat. if x = (0::nat) then card (vertices (translation e₂)) else x))) (G::('a, 'b) labeled_graph) ((on_graph (translation e₁) (λx::nat. if x = (0::nat) then 0::nat else x + card (vertices (translation e₂)) - (1::nat)))¯ O (f₁::(nat × 'b) set) ∪ (on_graph (translation e₂) (λx::nat. if x = (0::nat) then card (vertices (translation e₂)) else x))¯ O (f₂::(nat × 'b) set))›*) by (rule graph_homo_union[OF cmp1 cmp2 d_a[folded d_b]] (*‹graph_homomorphism (graph_union (map_graph_fn (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1)) (map_graph_fn (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x))) G ((on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯ O f₁ ∪ (on_graph (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x))¯ O f₂)›*)) thus "?case" (*goal: ‹∃f::(nat × 'b) set. graph_homomorphism (translation (A_Cmp (e₁::'a allegorical_term) (e₂::'a allegorical_term))) (G::('a, 'b) labeled_graph) f ∧ (0::nat, x::'b) ∈ f ∧ (1::nat, y::'b) ∈ f›*) using zero_one (*‹(card (vertices (translation e₂)), z) ∈ (on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯ O f₁› ‹(0, x) ∈ (on_graph (translation e₁) (λx. if x = 0 then 0 else x + card (vertices (translation e₂)) - 1))¯ O f₁› ‹(card (vertices (translation e₂)), z) ∈ (on_graph (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x))¯ O f₂› ‹(1, y) ∈ (on_graph (translation e₂) (λx. if x = 0 then card (vertices (translation e₂)) else x))¯ O f₂›*) by blast next (*goals: 1. ‹⋀e x y. ⟦⋀x y. (x, y) ∈ :G:⟦e⟧ ⟹ ∃f. graph_homomorphism (translation e) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f; (x, y) ∈ :G:⟦A_Cnv e⟧⟧ ⟹ ∃f. graph_homomorphism (translation (A_Cnv e)) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f› 2. ‹⋀x xa y. (xa, y) ∈ :G:⟦A_Lbl x⟧ ⟹ ∃f. graph_homomorphism (translation (A_Lbl x)) G f ∧ (0, xa) ∈ f ∧ (1, y) ∈ f›*) case (A_Cnv e) (*‹(?x, ?y) ∈ :G:⟦e⟧ ⟹ ∃f. graph_homomorphism (translation e) G f ∧ (0, ?x) ∈ f ∧ (1, ?y) ∈ f› ‹(x, y) ∈ :G:⟦A_Cnv e⟧›*) let ?G = "translation (A_Cnv e)" from A_Cnv (*‹(?x::'b, ?y::'b) ∈ :G::('a, 'b) labeled_graph:⟦e::'a allegorical_term⟧ ⟹ ∃f::(nat × 'b) set. graph_homomorphism (translation e) G f ∧ (0::nat, ?x) ∈ f ∧ (1::nat, ?y) ∈ f› ‹(x::'b::type, y::'b::type) ∈ :G::('a::type, 'b::type) labeled_graph:⟦A_Cnv (e::'a::type allegorical_term)⟧›*) obtain f where f: "graph_homomorphism (translation e) G f" "(0, y) ∈ f" "(1, x) ∈ f" (*goal: ‹(⋀f. ⟦graph_homomorphism (translation e) G f; (0, y) ∈ f; (1, x) ∈ f⟧ ⟹ thesis) ⟹ thesis›*) by auto hence v: "Domain f = vertices (translation e)" unfolding graph_homomorphism_def (*goal: ‹Domain f = vertices (translation e)›*) by auto define n where "n ≡ card (vertices (translation e))" from verts_in_translation (*‹inv_translation (vertices (translation ?X))›*) f (*‹graph_homomorphism (translation e) G f› ‹(0, y) ∈ f› ‹(1::nat, x::'b) ∈ (f::(nat × 'b) set)›*) inv_tr_card_min[OF verts_in_translation] (*‹2 ≤ card (vertices (translation ?X1))›*) v(1) (*‹Domain f = vertices (translation e)›*) have n: "vertices (translation e) = {0..<n}" "{0..<n} ∩ {x. x < 2} = {1,0}" "Domain f = {0..<n}" "{0..<n} ∩ {x. ¬ x < 2} = {2..<n}" and n2: "n ≥ 2" apply - (*goals: 1. ‹⟦⋀X::?'a40 allegorical_term. inv_translation (vertices (translation X)); graph_homomorphism (translation (e::'a allegorical_term)) (G::('a, 'b) labeled_graph) (f::(nat × 'b) set); (0::nat, y::'b) ∈ f; (1::nat, x::'b) ∈ f; ⋀X::?'a46 allegorical_term. (2::nat) ≤ card (vertices (translation X)); Domain f = vertices (translation e)⟧ ⟹ vertices (translation e) = {0::nat..<n::nat}› 2. ‹⟦⋀X::?'a31 allegorical_term. inv_translation (vertices (translation X)); graph_homomorphism (translation (e::'a allegorical_term)) (G::('a, 'b) labeled_graph) (f::(nat × 'b) set); (0::nat, y::'b) ∈ f; (1::nat, x::'b) ∈ f; ⋀X::?'a37 allegorical_term. (2::nat) ≤ card (vertices (translation X)); Domain f = vertices (translation e)⟧ ⟹ {0::nat..<n::nat} ∩ {x::nat. x < (2::nat)} = {1::nat, 0::nat}› 3. ‹⟦⋀X::?'a22 allegorical_term. inv_translation (vertices (translation X)); graph_homomorphism (translation (e::'a allegorical_term)) (G::('a, 'b) labeled_graph) (f::(nat × 'b) set); (0::nat, y::'b) ∈ f; (1::nat, x::'b) ∈ f; ⋀X::?'a28 allegorical_term. (2::nat) ≤ card (vertices (translation X)); Domain f = vertices (translation e)⟧ ⟹ Domain f = {0::nat..<n::nat}› 4. ‹⟦⋀X::?'a13 allegorical_term. inv_translation (vertices (translation X)); graph_homomorphism (translation (e::'a allegorical_term)) (G::('a, 'b) labeled_graph) (f::(nat × 'b) set); (0::nat, y::'b) ∈ f; (1::nat, x::'b) ∈ f; ⋀X::?'a19 allegorical_term. (2::nat) ≤ card (vertices (translation X)); Domain f = vertices (translation e)⟧ ⟹ {0::nat..<n::nat} ∩ {x::nat. ¬ x < (2::nat)} = {2::nat..<n}› 5. ‹⟦⋀X::?'a4 allegorical_term. inv_translation (vertices (translation X)); graph_homomorphism (translation (e::'a allegorical_term)) (G::('a, 'b) labeled_graph) (f::(nat × 'b) set); (0::nat, y::'b) ∈ f; (1::nat, x::'b) ∈ f; ⋀X::?'a10 allegorical_term. (2::nat) ≤ card (vertices (translation X)); Domain f = vertices (translation e)⟧ ⟹ (2::nat) ≤ (n::nat)› discuss goal 1*) apply ((auto simp:n_def (*‹n ≡ card (vertices (translation e))›*) inv_translation_def (*‹inv_translation ?r ≡ {0..<card ?r} = ?r ∧ {0, 1} ⊆ ?r›*))[1]) (*discuss goal 2*) apply ((auto simp:n_def (*‹n ≡ card (vertices (translation e))›*) inv_translation_def (*‹inv_translation ?r ≡ {0..<card ?r} = ?r ∧ {0, 1} ⊆ ?r›*))[1]) (*discuss goal 3*) apply ((auto simp:n_def (*‹n ≡ card (vertices (translation e))›*) inv_translation_def (*‹inv_translation ?r ≡ {0..<card ?r} = ?r ∧ {0, 1} ⊆ ?r›*))[1]) (*discuss goal 4*) apply ((auto simp:n_def (*‹n::nat ≡ card (vertices (translation (e::'a allegorical_term)))›*) inv_translation_def (*‹inv_translation (?r::nat set) ≡ {0::nat..<card ?r} = ?r ∧ {0::nat, 1::nat} ⊆ ?r›*))[1]) (*discuss goal 5*) apply ((auto simp:n_def (*‹n ≡ card (vertices (translation e))›*) inv_translation_def (*‹inv_translation ?r ≡ {0..<card ?r} = ?r ∧ {0, 1} ⊆ ?r›*))[1]) (*proven 5 subgoals*) . then have [simp]: "insert (Suc 0) {2..<n} = {1..<n}" "insert 0 {Suc 0..<n} = {0..<n}" using [simproc del : defined_all] (*‹TERM _›*) apply - (*goals: 1. ‹⟦vertices (translation e) = {0..<n}; {0..<n} ∩ {x. x < 2} = {1, 0}; Domain f = {0..<n}; {0..<n} ∩ {x. ¬ x < 2} = {2..<n}; 2 ≤ n⟧ ⟹ insert (Suc 0) {2..<n} = {1..<n}› 2. ‹⟦vertices (translation e) = {0..<n}; {0..<n} ∩ {x. x < 2} = {1, 0}; Domain f = {0..<n}; {0..<n} ∩ {x. ¬ x < 2} = {2..<n}; 2 ≤ n⟧ ⟹ insert 0 {Suc 0..<n} = {0..<n}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . let ?f = "on_graph ?G (λ x. if x < 2 then 1 - x else x)" have h: "graph_homomorphism ?G G (?f O f)" proof (rule graph_homomorphism_composes[OF _ f(1)] (*‹graph_homomorphism ?a (translation e) ?x ⟹ graph_homomorphism ?a G (?x O f)›*), rule graph_homomorphismI (*‹⟦vertices ?s = Domain ?h; ?h `` vertices ?s ⊆ vertices ?t; univalent ?h; edge_preserving ?h (edges ?s) (edges ?t); graph ?s; graph ?t⟧ ⟹ graph_homomorphism ?s ?t ?h›*)) (*goals: 1. ‹vertices (translation (A_Cnv (e::'a::type allegorical_term))) = Domain (on_graph (translation (A_Cnv e)) (λx::nat. if x < (2::nat) then (1::nat) - x else x))› 2. ‹on_graph (translation (A_Cnv (e::'a::type allegorical_term))) (λx::nat. if x < (2::nat) then (1::nat) - x else x) `` vertices (translation (A_Cnv e)) ⊆ vertices (translation e)› 3. ‹univalent (on_graph (translation (A_Cnv (e::'a::type allegorical_term))) (λx::nat. if x < (2::nat) then (1::nat) - x else x))› 4. ‹edge_preserving (on_graph (translation (A_Cnv (e::'a::type allegorical_term))) (λx::nat. if x < (2::nat) then (1::nat) - x else x)) (edges (translation (A_Cnv e))) (edges (translation e))› 5. ‹graph (translation (A_Cnv (e::'a::type allegorical_term)))› 6. ‹graph (translation (e::'a::type allegorical_term))›*) show "vertices ?G = Domain ?f" by (auto simp:Domain_int_univ (*‹Domain (?A × UNIV ∩ ?f) = ?A ∩ Domain ?f›*)) show "?f `` vertices ?G ⊆ vertices (translation e)" using n2 (*‹2 ≤ n›*) by auto show "univalent ?f" by auto show "edge_preserving ?f (edges (translation (A_Cnv e))) (edges (translation e))" apply (rule edge_preserving_on_graphI (*‹(⋀l x y. ⟦(l, x, y) ∈ edges ?X; x ∈ vertices ?X; y ∈ vertices ?X⟧ ⟹ (l, ?f x, ?f y) ∈ ?Y) ⟹ edge_preserving (on_graph ?X ?f) (edges ?X) ?Y›*)) (*goal: ‹edge_preserving (on_graph (translation (A_Cnv e)) (λx. if x < 2 then 1 - x else x)) (edges (translation (A_Cnv e))) (edges (translation e))›*) by (auto simp: BNF_Def.Gr_def (*‹BNF_Def.Gr (?A::?'a set) (?f::?'a ⇒ ?'b) = {(a, ?f a) |a::?'a. a ∈ ?A}›*)) qed (auto intro:assms (*‹graph G›*)) (*solves the remaining goals: 1. ‹graph (translation (A_Cnv (e::'a allegorical_term)))› 2. ‹graph (translation (e::'a allegorical_term))›*) have xy: "(0, x) ∈ ?f O f" "(1, y) ∈ ?f O f" using n2 (*‹2 ≤ n›*) f(2,3) (*‹(0, y) ∈ f› ‹(1, x) ∈ f›*) n(1,2) (*‹vertices (translation e) = {0..<n}› ‹{0::nat..<n::nat} ∩ {x::nat. x < (2::nat)} = {1::nat, 0::nat}›*) apply - (*goals: 1. ‹⟦2 ≤ n; (0, y) ∈ f; (1, x) ∈ f; vertices (translation e) = {0..<n}; {0..<n} ∩ {x. x < 2} = {1, 0}⟧ ⟹ (0, x) ∈ on_graph (translation (A_Cnv e)) (λx. if x < 2 then 1 - x else x) O f› 2. ‹⟦2 ≤ n; (0, y) ∈ f; (1, x) ∈ f; vertices (translation e) = {0..<n}; {0..<n} ∩ {x. x < 2} = {1, 0}⟧ ⟹ (1, y) ∈ on_graph (translation (A_Cnv e)) (λx. if x < 2 then 1 - x else x) O f› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . with h (*‹graph_homomorphism (translation (A_Cnv e)) G (on_graph (translation (A_Cnv e)) (λx. if x < 2 then 1 - x else x) O f)›*) show "?case" (*goal: ‹∃f::(nat × 'b) set. graph_homomorphism (translation (A_Cnv (e::'a allegorical_term))) (G::('a, 'b) labeled_graph) f ∧ (0::nat, x::'b) ∈ f ∧ (1::nat, y::'b) ∈ f›*) by auto next (*goal: ‹⋀x xa y. (xa, y) ∈ :G:⟦A_Lbl x⟧ ⟹ ∃f. graph_homomorphism (translation (A_Lbl x)) G f ∧ (0, xa) ∈ f ∧ (1, y) ∈ f›*) case (A_Lbl l) (*‹(x, y) ∈ :G:⟦A_Lbl l⟧›*) let ?f = "{(0,x),(1,y)}" have xy: "x ∈ vertices G" "y ∈ vertices G" using assms (*‹graph G›*) A_Lbl (*‹(x, y) ∈ :G:⟦A_Lbl l⟧›*) apply - (*goals: 1. ‹⟦graph G; (x, y) ∈ :G:⟦A_Lbl l⟧⟧ ⟹ x ∈ vertices G› 2. ‹⟦graph G; (x, y) ∈ :G:⟦A_Lbl l⟧⟧ ⟹ y ∈ vertices G› discuss goal 1*) apply ((auto simp:getRel_def (*‹getRel ?l ?G = {(x, y). (?l, x, y) ∈ edges ?G}›*))[1]) (*discuss goal 2*) apply ((auto simp:getRel_def (*‹getRel ?l ?G = {(x, y). (?l, x, y) ∈ edges ?G}›*))[1]) (*proven 2 subgoals*) . have "graph_homomorphism (translation (A_Lbl l)) G ?f ∧ (0, x) ∈ ?f ∧ (1, y) ∈ ?f" using assms (*‹graph G›*) A_Lbl (*‹(x, y) ∈ :G:⟦A_Lbl l⟧›*) xy (*‹x ∈ vertices G› ‹y ∈ vertices G›*) unfolding graph_homomorphism_def2 (*goal: ‹(vertices (translation (A_Lbl l)) = Domain {(0, x), (1, y)} ∧ univalent {(0, x), (1, y)} ∧ graph (translation (A_Lbl l)) ∧ graph G ∧ graph_union (map_graph {(0, x), (1, y)} (translation (A_Lbl l))) G = G) ∧ (0, x) ∈ {(0, x), (1, y)} ∧ (1, y) ∈ {(0, x), (1, y)}›*) by (auto simp:univalent_def (*‹univalent ?R = (∀x y z. (x, y) ∈ ?R ∧ (x, z) ∈ ?R ⟶ z = y)›*) getRel_def (*‹getRel ?l ?G = {(x, y). (?l, x, y) ∈ edges ?G}›*) on_triple_def (*‹on_triple ?R ≡ {((l, s, t), l', s', t'). l = l' ∧ (s, s') ∈ ?R ∧ (t, t') ∈ ?R}›*) Image_def (*‹?r `` ?s = {y. ∃x∈?s. (x, y) ∈ ?r}›*) graph_union_def (*‹graph_union ?G₁ ?G₂ = LG (edges ?G₁ ∪ edges ?G₂) (vertices ?G₁ ∪ vertices ?G₂)›*) insert_absorb (*‹?a ∈ ?A ⟹ insert ?a ?A = ?A›*)) then show "?case" (*goal: ‹∃f. graph_homomorphism (translation (A_Lbl l)) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f›*) by auto qed qed (insert translation_right_to_left (*‹⟦graph_homomorphism (translation ?e) ?G ?f; (0, ?x) ∈ ?f; (1, ?y) ∈ ?f⟧ ⟹ (?x, ?y) ∈ :?G:⟦?e⟧›*), auto) (*solved the remaining goal: ‹∃f. graph_homomorphism (translation e) G f ∧ (0, x) ∈ f ∧ (1, y) ∈ f ⟹ (x, y) ∈ :G:⟦e⟧›*) abbreviation transl_rule :: "'a sentence ⇒ ('a, nat) labeled_graph × ('a, nat) labeled_graph" where "transl_rule R ≡ (translation (fst R),translation (snd R))" text ‹Lemma 6.› lemma maintained_holds_iff: assumes "graph G" shows "maintained (translation e⇩L,translation (A_Int e⇩L e⇩R)) G ⟷ G ⊨ e⇩L ⊑ e⇩R" (is "?rhs = ?lhs") proof (standard) (*goals: 1. ‹maintained (translation (e⇩L::'a allegorical_term), translation (A_Int e⇩L (e⇩R::'a allegorical_term))) (G::('a, 'b) labeled_graph) ⟹ G ⊨ e⇩L ⊑ e⇩R› 2. ‹(G::('a, 'b) labeled_graph) ⊨ (e⇩L::'a allegorical_term) ⊑ (e⇩R::'a allegorical_term) ⟹ maintained (translation e⇩L, translation (A_Int e⇩L e⇩R)) G›*) assume lhs: "?lhs" (*‹(G::('a, 'b) labeled_graph) ⊨ (e⇩L::'a allegorical_term) ⊑ (e⇩R::'a allegorical_term)›*) show "?rhs" unfolding maintained_def (*goal: ‹∀f. graph_homomorphism (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) G f ⟶ extensible (translation e⇩L, translation (A_Int e⇩L e⇩R)) G f›*) proof (clarify) (*goal: ‹⋀f. graph_homomorphism (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) G f ⟹ extensible (translation e⇩L, translation (A_Int e⇩L e⇩R)) G f›*) fix f assume f: "graph_homomorphism (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) G f" (*‹graph_homomorphism (fst (translation (e⇩L::'a allegorical_term), translation (A_Int e⇩L (e⇩R::'a allegorical_term)))) (G::('a, 'b) labeled_graph) (f::(nat × 'b) set)›*) then obtain x and y where f2: "(0,x) ∈ f" "(1,y) ∈ f" (*goal: ‹(⋀x y. ⟦(0, x) ∈ f; (1, y) ∈ f⟧ ⟹ thesis) ⟹ thesis›*) unfolding graph_homomorphism_def (*goal: ‹(⋀x y. ⟦(0, x) ∈ f; (1, y) ∈ f⟧ ⟹ thesis) ⟹ thesis›*) by (metis DomainE (*‹⟦?a ∈ Domain ?r; ⋀b. (?a, b) ∈ ?r ⟹ ?P⟧ ⟹ ?P›*) One_nat_def (*‹1 = Suc 0›*) prod.sel( (*‹fst (?x1.0, ?x2.0) = ?x1.0›*) 1) verts_in_translation_finite( (*‹0 ∈ vertices (translation ?X)› ‹Suc 0 ∈ vertices (translation ?X)›*) 3,4)) with f (*‹graph_homomorphism (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) G f›*) have "(x,y) ∈ :G:⟦fst (e⇩L ⊑ e⇩R)⟧" unfolding translation[OF assms] (*goal: ‹∃f::(nat × 'b::type) set. graph_homomorphism (translation (fst ((e⇩L::'a::type allegorical_term) ⊑ (e⇩R::'a::type allegorical_term)))) (G::('a::type, 'b::type) labeled_graph) f ∧ (0::nat, x::'b::type) ∈ f ∧ (1::nat, y::'b::type) ∈ f›*) by auto with lhs (*‹G ⊨ e⇩L ⊑ e⇩R›*) have "(x,y) ∈ :G:⟦snd (e⇩L ⊑ e⇩R)⟧" by auto then obtain g where g: "graph_homomorphism (translation (A_Int e⇩L e⇩R)) G g" and g2: "(0, x) ∈ g" "(1, y) ∈ g" (*goal: ‹(⋀g. ⟦graph_homomorphism (translation (A_Int e⇩L e⇩R)) G g; (0, x) ∈ g; (1, y) ∈ g⟧ ⟹ thesis) ⟹ thesis›*) unfolding translation[OF assms] (*goal: ‹(⋀g. ⟦graph_homomorphism (translation (A_Int e⇩L e⇩R)) G g; (0, x) ∈ g; (1, y) ∈ g⟧ ⟹ thesis) ⟹ thesis›*) by auto have v: "vertices (translation (A_Int e⇩L e⇩R)) = Domain g" "vertices (translation e⇩L) = Domain f" using f (*‹graph_homomorphism (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) G f›*) g (*‹graph_homomorphism (translation (A_Int e⇩L e⇩R)) G g›*) unfolding graph_homomorphism_def (*goals: 1. ‹vertices (translation (A_Int e⇩L e⇩R)) = Domain g› 2. ‹vertices (translation e⇩L) = Domain f›*) apply - (*goals: 1. ‹⟦vertices (fst (translation (e⇩L::'a allegorical_term), translation (A_Int e⇩L (e⇩R::'a allegorical_term)))) = Domain (f::(nat × 'b) set) ∧ graph (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) ∧ graph (G::('a, 'b) labeled_graph) ∧ f `` vertices (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) ⊆ vertices G ∧ univalent f ∧ edge_preserving f (edges (fst (translation e⇩L, translation (A_Int e⇩L e⇩R)))) (edges G); vertices (translation (A_Int e⇩L e⇩R)) = Domain (g::(nat × 'b) set) ∧ graph (translation (A_Int e⇩L e⇩R)) ∧ graph G ∧ g `` vertices (translation (A_Int e⇩L e⇩R)) ⊆ vertices G ∧ univalent g ∧ edge_preserving g (edges (translation (A_Int e⇩L e⇩R))) (edges G)⟧ ⟹ vertices (translation (A_Int e⇩L e⇩R)) = Domain g› 2. ‹⟦vertices (fst (translation (e⇩L::'a allegorical_term), translation (A_Int e⇩L (e⇩R::'a allegorical_term)))) = Domain (f::(nat × 'b) set) ∧ graph (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) ∧ graph (G::('a, 'b) labeled_graph) ∧ f `` vertices (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) ⊆ vertices G ∧ univalent f ∧ edge_preserving f (edges (fst (translation e⇩L, translation (A_Int e⇩L e⇩R)))) (edges G); vertices (translation (A_Int e⇩L e⇩R)) = Domain (g::(nat × 'b) set) ∧ graph (translation (A_Int e⇩L e⇩R)) ∧ graph G ∧ g `` vertices (translation (A_Int e⇩L e⇩R)) ⊆ vertices G ∧ univalent g ∧ edge_preserving g (edges (translation (A_Int e⇩L e⇩R))) (edges G)⟧ ⟹ vertices (translation e⇩L) = Domain f› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . from subgraph_subset[of "translation e⇩L" "translation (A_Int e⇩L e⇩R)"] (*‹subgraph (translation (e⇩L::'a allegorical_term)) (translation (A_Int e⇩L (e⇩R::'a allegorical_term))) ⟹ vertices (translation e⇩L) ⊆ vertices (translation (A_Int e⇩L e⇩R))› ‹subgraph (translation e⇩L) (translation (A_Int e⇩L e⇩R)) ⟹ edges (restrict (translation e⇩L)) ⊆ edges (translation (A_Int e⇩L e⇩R))›*) graph_rule_translation[of e⇩L e⇩R] (*‹graph_rule (translation e⇩L, translation (A_Int e⇩L e⇩R))›*) have dom_sub: "Domain f ⊆ Domain g" using v (*‹vertices (translation (A_Int (e⇩L::'a allegorical_term) (e⇩R::'a allegorical_term))) = Domain (g::(nat × 'b) set)› ‹vertices (translation e⇩L) = Domain f›*) unfolding prod.sel (*goal: ‹Domain f ⊆ Domain g›*) by argo hence dom_le: "card (Domain f) ≤ card (Domain g)" by (metis card.infinite (*‹infinite ?A ⟹ card ?A = 0›*) card_mono (*‹⟦finite ?B; ?A ⊆ ?B⟧ ⟹ card ?A ≤ card ?B›*) inv_tr_card_min (*‹inv_translation ?r ⟹ 2 ≤ card ?r›*) not_less (*‹(¬ ?x < ?y) = (?y ≤ ?x)›*) rel_simps( (*‹0 < numeral ?n›*) 51) v( (*‹vertices (translation (A_Int e⇩L e⇩R)) = Domain g›*) 1) verts_in_translation (*‹inv_translation (vertices (translation ?X))›*)) have c_f: "card (Domain f) ≥ 2" using inv_tr_card_min[OF verts_in_translation] (*‹2 ≤ card (vertices (translation ?X1))›*) v (*‹vertices (translation (A_Int e⇩L e⇩R)) = Domain g› ‹vertices (translation e⇩L) = Domain f›*) by metis from f[unfolded graph_homomorphism_def] (*‹vertices (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) = Domain f ∧ graph (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) ∧ graph G ∧ f `` vertices (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) ⊆ vertices G ∧ univalent f ∧ edge_preserving f (edges (fst (translation e⇩L, translation (A_Int e⇩L e⇩R)))) (edges G)›*) have ep_f: "edge_preserving f (edges (translation e⇩L)) (edges G)" and uni_f: "univalent f" apply - (*goals: 1. ‹vertices (fst (translation (e⇩L::'a allegorical_term), translation (A_Int e⇩L (e⇩R::'a allegorical_term)))) = Domain (f::(nat × 'b) set) ∧ graph (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) ∧ graph (G::('a, 'b) labeled_graph) ∧ f `` vertices (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) ⊆ vertices G ∧ univalent f ∧ edge_preserving f (edges (fst (translation e⇩L, translation (A_Int e⇩L e⇩R)))) (edges G) ⟹ edge_preserving f (edges (translation e⇩L)) (edges G)› 2. ‹vertices (fst (translation (e⇩L::'a allegorical_term), translation (A_Int e⇩L (e⇩R::'a allegorical_term)))) = Domain (f::(nat × 'b) set) ∧ graph (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) ∧ graph (G::('a, 'b) labeled_graph) ∧ f `` vertices (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) ⊆ vertices G ∧ univalent f ∧ edge_preserving f (edges (fst (translation e⇩L, translation (A_Int e⇩L e⇩R)))) (edges G) ⟹ univalent f› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . let ?f = "(λx. if x < 2 then x else x + card (vertices (translation e⇩L)) - 2)" define GR where "GR = map_graph_fn (translation e⇩R) ?f" from g[unfolded graph_homomorphism_def] (*‹vertices (translation (A_Int e⇩L e⇩R)) = Domain g ∧ graph (translation (A_Int e⇩L e⇩R)) ∧ graph G ∧ g `` vertices (translation (A_Int e⇩L e⇩R)) ⊆ vertices G ∧ univalent g ∧ edge_preserving g (edges (translation (A_Int e⇩L e⇩R))) (edges G)›*) have "edge_preserving g (edges (translation (A_Int e⇩L e⇩R))) (edges G)" and uni_g: "univalent g" apply - (*goals: 1. ‹vertices (translation (A_Int e⇩L e⇩R)) = Domain g ∧ graph (translation (A_Int e⇩L e⇩R)) ∧ graph G ∧ g `` vertices (translation (A_Int e⇩L e⇩R)) ⊆ vertices G ∧ univalent g ∧ edge_preserving g (edges (translation (A_Int e⇩L e⇩R))) (edges G) ⟹ edge_preserving g (edges (translation (A_Int e⇩L e⇩R))) (edges G)› 2. ‹vertices (translation (A_Int e⇩L e⇩R)) = Domain g ∧ graph (translation (A_Int e⇩L e⇩R)) ∧ graph G ∧ g `` vertices (translation (A_Int e⇩L e⇩R)) ⊆ vertices G ∧ univalent g ∧ edge_preserving g (edges (translation (A_Int e⇩L e⇩R))) (edges G) ⟹ univalent g› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . from edge_preserving_subset[OF subset_refl _ this ( 1 )] (*‹(?E₁::('a::type × nat × nat) set) ⊆ edges (translation (A_Int (e⇩L::'a::type allegorical_term) (e⇩R::'a::type allegorical_term))) ⟹ edge_preserving (g::(nat × 'b::type) set) ?E₁ (edges (G::('a::type, 'b::type) labeled_graph))›*) have ep_g: "edge_preserving g (edges GR) (edges G)" by (auto simp:Let_def (*‹Let ?s ?f ≡ ?f ?s›*) GR_def (*‹GR = map_graph_fn (translation e⇩R) (λx. if x < 2 then x else x + card (vertices (translation e⇩L)) - 2)›*)) { fix a assume a: "a ∈ vertices (translation e⇩R)" (*‹(a::nat) ∈ vertices (translation (e⇩R::'a allegorical_term))›*) hence "?f a ∈ vertices (translation (A_Int e⇩L e⇩R))" by (auto simp:Let_def (*‹Let (?s::?'a) (?f::?'a ⇒ ?'b) ≡ ?f ?s›*)) from this[unfolded v] (*‹(if a < 2 then a else a + card (Domain f) - 2) ∈ Domain g›*) verts_in_translation[of "A_Int e⇩L e⇩R", unfolded inv_translation_def v] (*‹{0..<card (Domain g)} = Domain g ∧ {0, 1} ⊆ Domain g›*) have "¬ a < 2 ⟹ a + card (Domain f) - 2 < card (Domain g)" by auto } note [intro !] = this (*‹⟦?a2 ∈ vertices (translation e⇩R); ¬ ?a2 < 2⟧ ⟹ ?a2 + card (Domain f) - 2 < card (Domain g)›*) have [intro !]: " ¬ aa < 2 ⟹ card (Domain f) ≤ aa + card (Domain f) - 2" for aa by simp from v(2) (*‹vertices (translation e⇩L) = Domain f›*) restrictD[OF translation_graph [ of e⇩L ]] (*‹edges (translation e⇩L) ⊆ {(l, v1, v2). v1 ∈ vertices (translation e⇩L) ∧ v2 ∈ vertices (translation e⇩L)}›*) have df[dest]: "xa ∉ Domain f ⟹ (l,xa,xb) ∈ edges (translation e⇩L) ⟹ False" "xa ∉ Domain f ⟹ (l,xb,xa) ∈ edges (translation e⇩L) ⟹ False" for xa and l and xb unfolding edge_preserving (*goals: 1. ‹⟦xa ∉ Domain f; (l, xa, xb) ∈ edges (translation e⇩L)⟧ ⟹ False› 2. ‹⟦xa ∉ Domain f; (l, xb, xa) ∈ edges (translation e⇩L)⟧ ⟹ False›*) apply - (*goals: 1. ‹⟦xa ∉ Domain f; (l, xa, xb) ∈ edges (translation e⇩L); vertices (translation e⇩L) = Domain f; edges (translation e⇩L) ⊆ {(l, v1, v2). v1 ∈ vertices (translation e⇩L) ∧ v2 ∈ vertices (translation e⇩L)}⟧ ⟹ False› 2. ‹⟦xa ∉ Domain f; (l, xb, xa) ∈ edges (translation e⇩L); vertices (translation e⇩L) = Domain f; edges (translation e⇩L) ⊆ {(l, v1, v2). v1 ∈ vertices (translation e⇩L) ∧ v2 ∈ vertices (translation e⇩L)}⟧ ⟹ False› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . { fix l and xa and xb and ya assume assm: "(l,xa,xb) ∈ edges GR" (*‹(l::'a, xa::nat, xb::nat) ∈ edges (GR::('a, nat) labeled_graph)›*) with c_f (*‹(2::nat) ≤ card (Domain (f::(nat × 'b) set))›*) dom_le (*‹card (Domain f) ≤ card (Domain g)›*) have "xa ∈ {0,1} ∪ {card (Domain f)..<card (Domain g)}" "xb ∈ {0,1} ∪ {card (Domain f)..<card (Domain g)}" unfolding GR_def v (*goals: 1. ‹xa ∈ {0, 1} ∪ {card (Domain f)..<card (Domain g)}› 2. ‹xb ∈ {0, 1} ∪ {card (Domain f)..<card (Domain g)}›*) apply - (*goals: 1. ‹⟦2 ≤ card (Domain f); card (Domain f) ≤ card (Domain g); (l, xa, xb) ∈ edges (map_graph_fn (translation e⇩R) (λx. if x < 2 then x else x + card (Domain f) - 2))⟧ ⟹ xa ∈ {0, 1} ∪ {card (Domain f)..<card (Domain g)}› 2. ‹⟦2 ≤ card (Domain f); card (Domain f) ≤ card (Domain g); (l, xa, xb) ∈ edges (map_graph_fn (translation e⇩R) (λx. if x < 2 then x else x + card (Domain f) - 2))⟧ ⟹ xb ∈ {0, 1} ∪ {card (Domain f)..<card (Domain g)}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . hence minb: "xa ∈ {0,1} ∨ xa ≥ card (Domain f)" "xb ∈ {0,1} ∨ xb ≥ card (Domain f)" apply - (*goals: 1. ‹⟦xa ∈ {0, 1} ∪ {card (Domain f)..<card (Domain g)}; xb ∈ {0, 1} ∪ {card (Domain f)..<card (Domain g)}⟧ ⟹ xa ∈ {0, 1} ∨ card (Domain f) ≤ xa› 2. ‹⟦xa ∈ {0, 1} ∪ {card (Domain f)..<card (Domain g)}; xb ∈ {0, 1} ∪ {card (Domain f)..<card (Domain g)}⟧ ⟹ xb ∈ {0, 1} ∨ card (Domain f) ≤ xb› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . { fix z and xa assume minb: "xa ∈ {0,1} ∨ xa ≥ card (Domain f)" and z: "(xa,z) ∈ f" (*‹(xa::nat) ∈ {0::nat, 1::nat} ∨ card (Domain (f::(nat × 'b) set)) ≤ xa› ‹(xa::nat, z::'b) ∈ (f::(nat × 'b) set)›*) from z (*‹(xa, z) ∈ f›*) verts_in_translation[of e⇩L, unfolded inv_translation_def v] (*‹{0..<card (Domain f)} = Domain f ∧ {0, 1} ⊆ Domain f›*) have "xa < card(Domain f)" by auto with minb (*‹xa ∈ {0, 1} ∨ card (Domain f) ≤ xa›*) verts_in_translation[of "A_Int e⇩L e⇩R", unfolded inv_translation_def v] (*‹{0::nat..<card (Domain (g::(nat × 'b) set))} = Domain g ∧ {0::nat, 1::nat} ⊆ Domain g›*) have x: "xa ∈ {0,1} ∧ xa ∈ Domain g" by auto then obtain v where g: "(xa,v) ∈ g" (*goal: ‹(⋀v. (xa, v) ∈ g ⟹ thesis) ⟹ thesis›*) by auto consider "xa = 0 ∧ z = x" | "xa = 1 ∧ z = y" (*goal: ‹⟦xa = 0 ∧ z = x ⟹ thesis; xa = 1 ∧ z = y ⟹ thesis⟧ ⟹ thesis›*) using x (*‹xa ∈ {0, 1} ∧ xa ∈ Domain g›*) f2[THEN univalentD [ OF uni_f ]] (*‹(0, ?z) ∈ f ⟹ ?z = x› ‹(1, ?z) ∈ f ⟹ ?z = y›*) z (*‹(xa, z) ∈ f›*) by auto hence "v = z" using g (*‹(xa, v) ∈ g›*) g2[THEN univalentD [ OF uni_g ]] (*‹(0, ?z) ∈ g ⟹ ?z = x› ‹(1::nat, ?z::'b) ∈ (g::(nat × 'b) set) ⟹ ?z = (y::'b)›*) by metis hence "(xa,z) ∈ g" using g (*‹(xa, v) ∈ g›*) by auto } note minb[THEN this] (*‹(xa, ?z2) ∈ f ⟹ (xa, ?z2) ∈ g› ‹(xb, ?z2) ∈ f ⟹ (xb, ?z2) ∈ g›*) } with f2 (*‹(0::nat, x::'b::type) ∈ (f::(nat × 'b::type) set)› ‹(1::nat, y::'b::type) ∈ (f::(nat × 'b::type) set)›*) g2[THEN univalentD [ OF uni_g ]] (*‹(0, ?z) ∈ g ⟹ ?z = x› ‹(1, ?z) ∈ g ⟹ ?z = y›*) have dg: "(l,xa,xb) ∈ edges GR ⟹ (xa,ya) ∈ f ⟹ (xa,ya) ∈ g" "(l,xb,xa) ∈ edges GR ⟹ (xa,ya) ∈ f ⟹ (xa,ya) ∈ g" for xa and l and xb and ya unfolding edge_preserving (*goals: 1. ‹⟦(l::'a, xa::nat, xb::nat) ∈ edges (GR::('a, nat) labeled_graph); (xa, ya::'b) ∈ (f::(nat × 'b) set)⟧ ⟹ (xa, ya) ∈ (g::(nat × 'b) set)› 2. ‹⟦(l::'a, xb::nat, xa::nat) ∈ edges (GR::('a, nat) labeled_graph); (xa, ya::'b) ∈ (f::(nat × 'b) set)⟧ ⟹ (xa, ya) ∈ (g::(nat × 'b) set)›*) apply - (*goals: 1. ‹⟦(l, xa, xb) ∈ edges GR; (xa, ya) ∈ f; (0, x) ∈ f; (1, y) ∈ f; ⋀z. (0, z) ∈ g ⟹ z = x; ⋀z. (1, z) ∈ g ⟹ z = y; ⋀l xa xb z. ⟦(l, xa, xb) ∈ edges GR; (xa, z) ∈ f⟧ ⟹ (xa, z) ∈ g; ⋀l xa xb z. ⟦(l, xa, xb) ∈ edges GR; (xb, z) ∈ f⟧ ⟹ (xb, z) ∈ g⟧ ⟹ (xa, ya) ∈ g› 2. ‹⟦(l, xb, xa) ∈ edges GR; (xa, ya) ∈ f; (0, x) ∈ f; (1, y) ∈ f; ⋀z. (0, z) ∈ g ⟹ z = x; ⋀z. (1, z) ∈ g ⟹ z = y; ⋀l xa xb z. ⟦(l, xa, xb) ∈ edges GR; (xa, z) ∈ f⟧ ⟹ (xa, z) ∈ g; ⋀l xa xb z. ⟦(l, xa, xb) ∈ edges GR; (xb, z) ∈ f⟧ ⟹ (xb, z) ∈ g⟧ ⟹ (xa, ya) ∈ g› discuss goal 1*) apply ((msorry)[1]) (*discuss goal 2*) apply ((msorry)[1]) (*proven 2 subgoals*) . have "vertices (translation e⇩L) ⊆ vertices (translation (A_Int e⇩L e⇩R))" apply (rule subgraph_subset (*‹subgraph (?G₁::(?'a, ?'b) labeled_graph) (?G₂::(?'a, ?'b) labeled_graph) ⟹ vertices ?G₁ ⊆ vertices ?G₂› ‹subgraph (?G₁::(?'a, ?'b) labeled_graph) (?G₂::(?'a, ?'b) labeled_graph) ⟹ edges (restrict ?G₁) ⊆ edges ?G₂›*)) (*goal: ‹vertices (translation e⇩L) ⊆ vertices (translation (A_Int e⇩L e⇩R))›*) apply (insert graph_rule_translation (*‹graph_rule (translation ?X, translation (A_Int ?X ?Y))›*)) (*goal: ‹subgraph (translation (e⇩L::'a::type allegorical_term)) (translation (A_Int e⇩L (e⇩R::'a::type allegorical_term)))›*) by auto hence subdom: "Domain f ⊆ Domain g" unfolding v (*goal: ‹Domain (f::(nat × 'b) set) ⊆ Domain (g::(nat × 'b) set)›*) . let ?g = "f ∪ (Id_on (UNIV - Domain f) O g)" have [simp]: "Domain ?g = Domain g" using subdom (*‹Domain f ⊆ Domain g›*) unfolding Domain_Un_eq (*goal: ‹Domain f ∪ Domain (Id_on (UNIV - Domain f) O g) = Domain g›*) by auto have ih: "graph_homomorphism (translation (A_Int e⇩L e⇩R)) G ?g" proof (rule graph_homomorphismI (*‹⟦vertices ?s = Domain ?h; ?h `` vertices ?s ⊆ vertices ?t; univalent ?h; edge_preserving ?h (edges ?s) (edges ?t); graph ?s; graph ?t⟧ ⟹ graph_homomorphism ?s ?t ?h›*)) (*goals: 1. ‹vertices (translation (A_Int (e⇩L::'a allegorical_term) (e⇩R::'a allegorical_term))) = Domain ((f::(nat × 'b) set) ∪ Id_on (UNIV - Domain f) O (g::(nat × 'b) set))› 2. ‹((f::(nat × 'b) set) ∪ Id_on (UNIV - Domain f) O (g::(nat × 'b) set)) `` vertices (translation (A_Int (e⇩L::'a allegorical_term) (e⇩R::'a allegorical_term))) ⊆ vertices (G::('a, 'b) labeled_graph)› 3. ‹univalent ((f::(nat × 'b) set) ∪ Id_on (UNIV - Domain f) O (g::(nat × 'b) set))› 4. ‹edge_preserving ((f::(nat × 'b) set) ∪ Id_on (UNIV - Domain f) O (g::(nat × 'b) set)) (edges (translation (A_Int (e⇩L::'a allegorical_term) (e⇩R::'a allegorical_term)))) (edges (G::('a, 'b) labeled_graph))› 5. ‹graph (translation (A_Int (e⇩L::'a allegorical_term) (e⇩R::'a allegorical_term)))› 6. ‹graph (G::('a, 'b) labeled_graph)›*) show "?g `` vertices (translation (A_Int e⇩L e⇩R)) ⊆ vertices G" using g[unfolded graph_homomorphism_def] (*‹vertices (translation (A_Int e⇩L e⇩R)) = Domain g ∧ graph (translation (A_Int e⇩L e⇩R)) ∧ graph G ∧ g `` vertices (translation (A_Int e⇩L e⇩R)) ⊆ vertices G ∧ univalent g ∧ edge_preserving g (edges (translation (A_Int e⇩L e⇩R))) (edges G)›*) f[unfolded graph_homomorphism_def] (*‹vertices (fst (translation (e⇩L::'a::type allegorical_term), translation (A_Int e⇩L (e⇩R::'a::type allegorical_term)))) = Domain (f::(nat × 'b::type) set) ∧ graph (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) ∧ graph (G::('a::type, 'b::type) labeled_graph) ∧ f `` vertices (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) ⊆ vertices G ∧ univalent f ∧ edge_preserving f (edges (fst (translation e⇩L, translation (A_Int e⇩L e⇩R)))) (edges G)›*) by (auto simp: v (*‹vertices (translation (A_Int e⇩L e⇩R)) = Domain g› ‹vertices (translation e⇩L) = Domain f›*) simp del:translation.simps (*‹translation (A_Lbl ?l) = LG {(?l, 0, 1)} {0, 1}› ‹translation (A_Cnv ?e) = map_graph_fn (translation ?e) (λx. if x < 2 then 1 - x else x)› ‹translation (A_Cmp ?e₁ ?e₂) = (let G₁ = translation ?e₁; G₂ = translation ?e₂ in graph_union (map_graph_fn G₁ (λx. if x = 0 then 0 else x + card (vertices G₂) - 1)) (map_graph_fn G₂ (λx. if x = 0 then card (vertices G₂) else x)))› ‹translation (A_Int ?e₁ ?e₂) = (let G₁ = translation ?e₁; G₂ = translation ?e₂ in graph_union G₁ (map_graph_fn G₂ (λx. if x < 2 then x else x + card (vertices G₁) - 2)))›*)) show "edge_preserving ?g (edges (translation (A_Int e⇩L e⇩R))) (edges G)" unfolding Let_def translation.simps graph_union_edges (*goal: ‹edge_preserving (f ∪ Id_on (UNIV - Domain f) O g) (edges (translation e⇩L) ∪ edges (map_graph_fn (translation e⇩R) (λx. if x < 2 then x else x + card (vertices (translation e⇩L)) - 2))) (edges G)›*) proof (standard) (*goals: 1. ‹edge_preserving ((f::(nat × 'b) set) ∪ Id_on (UNIV - Domain f) O (g::(nat × 'b) set)) (edges (translation (e⇩L::'a allegorical_term))) (edges (G::('a, 'b) labeled_graph))› 2. ‹edge_preserving ((f::(nat × 'b) set) ∪ Id_on (UNIV - Domain f) O (g::(nat × 'b) set)) (edges (map_graph_fn (translation (e⇩R::'a allegorical_term)) (λx::nat. if x < (2::nat) then x else x + card (vertices (translation (e⇩L::'a allegorical_term))) - (2::nat)))) (edges (G::('a, 'b) labeled_graph))›*) show "edge_preserving ?g (edges (translation e⇩L)) (edges G)" using edge_preserving_atomic[OF ep_f] (*‹⟦(?v1.0, ?v1') ∈ f; (?v2.0, ?v2') ∈ f; (?k, ?v1.0, ?v2.0) ∈ edges (translation e⇩L)⟧ ⟹ (?k, ?v1', ?v2') ∈ edges G›*) unfolding edge_preserving (*goal: ‹on_triple (f ∪ Id_on (UNIV - Domain f) O g) `` edges (translation e⇩L) ⊆ edges G›*) by auto have "edge_preserving ?g (edges GR) (edges G)" using edge_preserving_atomic[OF ep_g] (*‹⟦(?v1.0, ?v1') ∈ g; (?v2.0, ?v2') ∈ g; (?k, ?v1.0, ?v2.0) ∈ edges GR⟧ ⟹ (?k, ?v1', ?v2') ∈ edges G›*) dg (*‹⟦(?l, ?xa, ?xb) ∈ edges GR; (?xa, ?ya) ∈ f⟧ ⟹ (?xa, ?ya) ∈ g› ‹⟦(?l::'a, ?xb::nat, ?xa::nat) ∈ edges (GR::('a, nat) labeled_graph); (?xa, ?ya::'b) ∈ (f::(nat × 'b) set)⟧ ⟹ (?xa, ?ya) ∈ (g::(nat × 'b) set)›*) unfolding edge_preserving (*goal: ‹on_triple (f ∪ Id_on (UNIV - Domain f) O g) `` edges GR ⊆ edges G›*) apply auto (*goals: 1. ‹⋀a aa b ab ba. ⟦⋀v1 v1' v2 v2' k. ⟦(v1, v1') ∈ g; (v2, v2') ∈ g; (k, v1, v2) ∈ edges GR⟧ ⟹ (k, v1', v2') ∈ edges G; ⋀l xa xb ya. ⟦(l, xa, xb) ∈ edges GR; (xa, ya) ∈ f⟧ ⟹ (xa, ya) ∈ g; ⋀l xb xa ya. ⟦(l, xb, xa) ∈ edges GR; (xa, ya) ∈ f⟧ ⟹ (xa, ya) ∈ g; (a, ab, ba) ∈ edges GR; (ab, aa) ∈ f; (ba, b) ∈ f⟧ ⟹ (a, aa, b) ∈ edges G› 2. ‹⋀a aa ab z xa. ⟦⋀v1 v1' v2 v2' k. ⟦(v1, v1') ∈ g; (v2, v2') ∈ g; (k, v1, v2) ∈ edges GR⟧ ⟹ (k, v1', v2') ∈ edges G; ⋀l xa xb ya. ⟦(l, xa, xb) ∈ edges GR; (xa, ya) ∈ f⟧ ⟹ (xa, ya) ∈ g; ⋀l xb xa ya. ⟦(l, xb, xa) ∈ edges GR; (xa, ya) ∈ f⟧ ⟹ (xa, ya) ∈ g; (a, ab, xa) ∈ edges GR; (ab, aa) ∈ f; (xa, z) ∈ g; xa ∉ Domain f⟧ ⟹ (a, aa, z) ∈ edges G› 3. ‹⋀a b ba z xa. ⟦⋀v1 v1' v2 v2' k. ⟦(v1, v1') ∈ g; (v2, v2') ∈ g; (k, v1, v2) ∈ edges GR⟧ ⟹ (k, v1', v2') ∈ edges G; ⋀l xa xb ya. ⟦(l, xa, xb) ∈ edges GR; (xa, ya) ∈ f⟧ ⟹ (xa, ya) ∈ g; ⋀l xb xa ya. ⟦(l, xb, xa) ∈ edges GR; (xa, ya) ∈ f⟧ ⟹ (xa, ya) ∈ g; (a, xa, ba) ∈ edges GR; (xa, z) ∈ g; xa ∉ Domain f; (ba, b) ∈ f⟧ ⟹ (a, z, b) ∈ edges G› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*discuss goal 3*) apply blast (*proven 3 subgoals*) . thus "edge_preserving ?g (edges (map_graph_fn (translation e⇩R) ?f)) (edges G)" by (auto simp:GR_def (*‹(GR::('a::type, nat) labeled_graph) = map_graph_fn (translation (e⇩R::'a::type allegorical_term)) (λx::nat. if x < (2::nat) then x else x + card (vertices (translation (e⇩L::'a::type allegorical_term))) - (2::nat))›*)) qed qed (insert f[unfolded graph_homomorphism_def] (*‹vertices (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) = Domain f ∧ graph (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) ∧ graph G ∧ f `` vertices (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) ⊆ vertices G ∧ univalent f ∧ edge_preserving f (edges (fst (translation e⇩L, translation (A_Int e⇩L e⇩R)))) (edges G)›*) g[unfolded graph_homomorphism_def] (*‹vertices (translation (A_Int e⇩L e⇩R)) = Domain g ∧ graph (translation (A_Int e⇩L e⇩R)) ∧ graph G ∧ g `` vertices (translation (A_Int e⇩L e⇩R)) ⊆ vertices G ∧ univalent g ∧ edge_preserving g (edges (translation (A_Int e⇩L e⇩R))) (edges G)›*), auto simp:Let_def (*‹Let ?s ?f ≡ ?f ?s›*)) (*solves the remaining goals: 1. ‹vertices (translation (A_Int e⇩L e⇩R)) = Domain (f ∪ Id_on (UNIV - Domain f) O g)› 2. ‹univalent (f ∪ Id_on (UNIV - Domain f) O g)› 3. ‹graph (translation (A_Int e⇩L e⇩R))› 4. ‹graph G›*) have ie: "agree_on (translation e⇩L) f ?g" unfolding agree_on_def (*goal: ‹∀v∈vertices (translation e⇩L). f `` {v} = (f ∪ Id_on (UNIV - Domain f) O g) `` {v}›*) by (auto simp:v (*‹vertices (translation (A_Int e⇩L e⇩R)) = Domain g› ‹vertices (translation e⇩L) = Domain f›*)) from ie (*‹agree_on (translation e⇩L) f (f ∪ Id_on (UNIV - Domain f) O g)›*) ih (*‹graph_homomorphism (translation (A_Int (e⇩L::'a allegorical_term) (e⇩R::'a allegorical_term))) (G::('a, 'b) labeled_graph) ((f::(nat × 'b) set) ∪ Id_on (UNIV - Domain f) O (g::(nat × 'b) set))›*) show "extensible (translation e⇩L, translation (A_Int e⇩L e⇩R)) G f" unfolding extensible_def prod.sel (*goal: ‹∃g. graph_homomorphism (translation (A_Int e⇩L e⇩R)) G g ∧ agree_on (translation e⇩L) f g›*) by auto qed next (*goal: ‹maintained (translation e⇩L, translation (A_Int e⇩L e⇩R)) G ⟹ G ⊨ e⇩L ⊑ e⇩R›*) assume rhs: "?rhs" (*‹maintained (translation (e⇩L::'a allegorical_term), translation (A_Int e⇩L (e⇩R::'a allegorical_term))) (G::('a, 'b) labeled_graph)›*) { fix x and y assume "(x,y) ∈ :G:⟦e⇩L⟧" (*‹(x::'b, y::'b) ∈ :G::('a, 'b) labeled_graph:⟦e⇩L::'a allegorical_term⟧›*) with translation[OF assms] (*‹((?x, ?y) ∈ :G:⟦?e⟧) = (∃f. graph_homomorphism (translation ?e) G f ∧ (0, ?x) ∈ f ∧ (1, ?y) ∈ f)›*) obtain f where f: "graph_homomorphism (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) G f" "(0, x) ∈ f" "(1, y) ∈ f" (*goal: ‹(⋀f. ⟦graph_homomorphism (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) G f; (0, x) ∈ f; (1, y) ∈ f⟧ ⟹ thesis) ⟹ thesis›*) by auto with rhs[unfolded maintained_def, rule_format, OF f ( 1 ), unfolded extensible_def] (*‹∃g. graph_homomorphism (snd (translation e⇩L, translation (A_Int e⇩L e⇩R))) G g ∧ agree_on (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) f g›*) obtain g where g: "graph_homomorphism (translation (A_Int e⇩L e⇩R)) G g" "agree_on (translation e⇩L) f g" (*goal: ‹(⋀g::(nat × 'b::type) set. ⟦graph_homomorphism (translation (A_Int (e⇩L::'a::type allegorical_term) (e⇩R::'a::type allegorical_term))) (G::('a::type, 'b::type) labeled_graph) g; agree_on (translation e⇩L) (f::(nat × 'b::type) set) g⟧ ⟹ thesis::bool) ⟹ thesis›*) by auto hence "(x,y) ∈ :G:⟦A_Int e⇩L e⇩R⟧" using f (*‹graph_homomorphism (fst (translation e⇩L, translation (A_Int e⇩L e⇩R))) G f› ‹(0::nat, x::'b::type) ∈ (f::(nat × 'b::type) set)› ‹(1, y) ∈ f›*) unfolding agree_on_def translation[OF assms] (*goal: ‹∃f::(nat × 'b) set. graph_homomorphism (translation (A_Int (e⇩L::'a allegorical_term) (e⇩R::'a allegorical_term))) (G::('a, 'b) labeled_graph) f ∧ (0::nat, x::'b) ∈ f ∧ (1::nat, y::'b) ∈ f›*) by auto } thus "?lhs" by auto qed lemma translation_self[intro]: "(0, 1) ∈ :translation e:⟦e⟧" proof (induct e) (*goals: 1. ‹⋀e1 e2. ⟦(0, 1) ∈ :translation e1:⟦e1⟧; (0, 1) ∈ :translation e2:⟦e2⟧⟧ ⟹ (0, 1) ∈ :translation (A_Int e1 e2):⟦A_Int e1 e2⟧› 2. ‹⋀e1 e2. ⟦(0, 1) ∈ :translation e1:⟦e1⟧; (0, 1) ∈ :translation e2:⟦e2⟧⟧ ⟹ (0, 1) ∈ :translation (A_Cmp e1 e2):⟦A_Cmp e1 e2⟧› 3. ‹⋀e. (0, 1) ∈ :translation e:⟦e⟧ ⟹ (0, 1) ∈ :translation (A_Cnv e):⟦A_Cnv e⟧› 4. ‹⋀x. (0, 1) ∈ :translation (A_Lbl x):⟦A_Lbl x⟧›*) case (A_Int e1 e2) (*‹(0, 1) ∈ :translation e1:⟦e1⟧› ‹(0, 1) ∈ :translation e2:⟦e2⟧›*) let ?f = "(λx. if x < 2 then x else x + card (vertices (translation e1)) - 2)" have f: "(?f 0,?f 1) ∈:map_graph_fn (translation e2) ?f:⟦e2⟧" using map_graph_in[OF translation_graph A_Int ( 2 ), of ?f] (*‹(if 0 < 2 then 0 else 0 + card (vertices (translation e1)) - 2, if 1 < 2 then 1 else 1 + card (vertices (translation e1)) - 2) ∈ :map_graph_fn (translation e2) (λx. if x < 2 then x else x + card (vertices (translation e1)) - 2):⟦e2⟧›*) by auto let ?G = "graph_union (translation e1) (map_graph_fn (translation e2) ?f)" have "{(0,1)} ⊆ :(translation e1):⟦e1⟧" using A_Int (*‹(0, 1) ∈ :translation e1:⟦e1⟧› ‹(0, 1) ∈ :translation e2:⟦e2⟧›*) by auto moreover have "{(0,1)} ⊆ :map_graph_fn (translation e2) ?f:⟦e2⟧" using f (*‹(if 0 < 2 then 0 else 0 + card (vertices (translation e1)) - 2, if 1 < 2 then 1 else 1 + card (vertices (translation e1)) - 2) ∈ :map_graph_fn (translation e2) (λx. if x < 2 then x else x + card (vertices (translation e1)) - 2):⟦e2⟧›*) by auto moreover have ":map_graph_fn (translation e2) ?f:⟦e2⟧ ⊆ :?G:⟦e2⟧" ":translation e1:⟦e1⟧ ⊆ :?G:⟦e1⟧" using graph_union_semantics (*‹(:?A:⟦?e⟧) ∪ (:?B:⟦?e⟧) ⊆ :graph_union ?A ?B:⟦?e⟧›*) apply - (*goals: 1. ‹(⋀A e B. (:A:⟦e⟧) ∪ (:B:⟦e⟧) ⊆ :graph_union A B:⟦e⟧) ⟹ :map_graph_fn (translation e2) (λx. if x < 2 then x else x + card (vertices (translation e1)) - 2):⟦e2⟧ ⊆ :graph_union (translation e1) (map_graph_fn (translation e2) (λx. if x < 2 then x else x + card (vertices (translation e1)) - 2)):⟦e2⟧› 2. ‹(⋀A e B. (:A:⟦e⟧) ∪ (:B:⟦e⟧) ⊆ :graph_union A B:⟦e⟧) ⟹ :translation e1:⟦e1⟧ ⊆ :graph_union (translation e1) (map_graph_fn (translation e2) (λx. if x < 2 then x else x + card (vertices (translation e1)) - 2)):⟦e1⟧› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) . ultimately show "?case" (*goal: ‹(0, 1) ∈ :translation (A_Int e1 e2):⟦A_Int e1 e2⟧›*) by (auto simp:Let_def (*‹Let ?s ?f ≡ ?f ?s›*)) next (*goals: 1. ‹⋀e1 e2. ⟦(0, 1) ∈ :translation e1:⟦e1⟧; (0, 1) ∈ :translation e2:⟦e2⟧⟧ ⟹ (0, 1) ∈ :translation (A_Cmp e1 e2):⟦A_Cmp e1 e2⟧› 2. ‹⋀e. (0, 1) ∈ :translation e:⟦e⟧ ⟹ (0, 1) ∈ :translation (A_Cnv e):⟦A_Cnv e⟧› 3. ‹⋀x. (0, 1) ∈ :translation (A_Lbl x):⟦A_Lbl x⟧›*) case (A_Cmp e1 e2) (*‹(0::nat, 1::nat) ∈ :translation (e1::'a allegorical_term):⟦e1⟧› ‹(0, 1) ∈ :translation e2:⟦e2⟧›*) let ?f1 = "λx. if x = 0 then 0 else x + card (vertices (translation e2)) - 1" have f1: "(?f1 0,?f1 1) ∈:map_graph_fn (translation e1) ?f1:⟦e1⟧" using map_graph_in[OF translation_graph A_Cmp ( 1 ), of ?f1] (*‹(if (0::nat) = (0::nat) then 0::nat else (0::nat) + card (vertices (translation (e2::'a allegorical_term))) - (1::nat), if (1::nat) = (0::nat) then 0::nat else (1::nat) + card (vertices (translation e2)) - (1::nat)) ∈ :map_graph_fn (translation (e1::'a allegorical_term)) (λx::nat. if x = (0::nat) then 0::nat else x + card (vertices (translation e2)) - (1::nat)):⟦e1⟧›*) by auto let ?f2 = "λx. if x = 0 then card (vertices (translation e2)) else x" have f2: "(?f2 0,?f2 1) ∈:map_graph_fn (translation e2) ?f2:⟦e2⟧" using map_graph_in[OF translation_graph A_Cmp ( 2 ), of ?f2] (*‹(if (0::nat) = (0::nat) then card (vertices (translation (e2::'a allegorical_term))) else (0::nat), if (1::nat) = (0::nat) then card (vertices (translation e2)) else (1::nat)) ∈ :map_graph_fn (translation e2) (λx::nat. if x = (0::nat) then card (vertices (translation e2)) else x):⟦e2⟧›*) by auto let ?G = "graph_union (map_graph_fn (translation e1) ?f1) (map_graph_fn (translation e2) ?f2)" have "{(0,1)} = {(0,card (vertices (translation e2)))} O {(card (vertices (translation e2)),1)}" by auto also (*calculation: ‹{(0, 1)} = {(0, card (vertices (translation e2)))} O {(card (vertices (translation e2)), 1)}›*) have "{(0,card (vertices (translation e2)))} ⊆ :map_graph_fn (translation e1) ?f1:⟦e1⟧" using f1 (*‹(if 0 = 0 then 0 else 0 + card (vertices (translation e2)) - 1, if 1 = 0 then 0 else 1 + card (vertices (translation e2)) - 1) ∈ :map_graph_fn (translation e1) (λx. if x = 0 then 0 else x + card (vertices (translation e2)) - 1):⟦e1⟧›*) by auto also (*calculation: ‹(⋀x y. x ⊆ y ⟹ x O {(card (vertices (translation e2)), 1)} ⊆ y O {(card (vertices (translation e2)), 1)}) ⟹ {(0, 1)} ⊆ (:map_graph_fn (translation e1) (λx. if x = 0 then 0 else x + card (vertices (translation e2)) - 1):⟦e1⟧) O {(card (vertices (translation e2)), 1)}›*) have ":map_graph_fn (translation e1) ?f1:⟦e1⟧ ⊆ :?G:⟦e1⟧" using graph_union_semantics (*‹(:?A:⟦?e⟧) ∪ (:?B:⟦?e⟧) ⊆ :graph_union ?A ?B:⟦?e⟧›*) by auto also (*calculation: ‹⟦⋀(x::(nat × nat) set) y::(nat × nat) set. x ⊆ y ⟹ x O {(card (vertices (translation (e2::'a allegorical_term))), 1::?'c3)} ⊆ y O {(card (vertices (translation e2)), 1::?'c3)}; ⋀(x::(nat × nat) set) y::(nat × nat) set. x ⊆ y ⟹ x O {(card (vertices (translation e2)), 1::?'c3)} ⊆ y O {(card (vertices (translation e2)), 1::?'c3)}⟧ ⟹ {(0::nat, 1::?'c3)} ⊆ (:graph_union (map_graph_fn (translation (e1::'a allegorical_term)) (λx::nat. if x = (0::nat) then 0::nat else x + card (vertices (translation e2)) - (1::nat))) (map_graph_fn (translation e2) (λx::nat. if x = (0::nat) then card (vertices (translation e2)) else x)):⟦e1⟧) O {(card (vertices (translation e2)), 1::?'c3)}›*) have "{(card (vertices (translation e2)),1)} ⊆ :map_graph_fn (translation e2) ?f2:⟦e2⟧" using f2 (*‹(if 0 = 0 then card (vertices (translation e2)) else 0, if 1 = 0 then card (vertices (translation e2)) else 1) ∈ :map_graph_fn (translation e2) (λx. if x = 0 then card (vertices (translation e2)) else x):⟦e2⟧›*) by auto also (*calculation: ‹⟦⋀x y. x ⊆ y ⟹ x O {(card (vertices (translation e2)), 1)} ⊆ y O {(card (vertices (translation e2)), 1)}; ⋀x y. x ⊆ y ⟹ x O {(card (vertices (translation e2)), 1)} ⊆ y O {(card (vertices (translation e2)), 1)}; ⋀x y. x ⊆ y ⟹ (:graph_union (map_graph_fn (translation e1) (λx. if x = 0 then 0 else x + card (vertices (translation e2)) - 1)) (map_graph_fn (translation e2) (λx. if x = 0 then card (vertices (translation e2)) else x)):⟦e1⟧) O x ⊆ (:graph_union (map_graph_fn (translation e1) (λx. if x = 0 then 0 else x + card (vertices (translation e2)) - 1)) (map_graph_fn (translation e2) (λx. if x = 0 then card (vertices (translation e2)) else x)):⟦e1⟧) O y⟧ ⟹ {(0, 1)} ⊆ (:graph_union (map_graph_fn (translation e1) (λx. if x = 0 then 0 else x + card (vertices (translation e2)) - 1)) (map_graph_fn (translation e2) (λx. if x = 0 then card (vertices (translation e2)) else x)):⟦e1⟧) O (:map_graph_fn (translation e2) (λx. if x = 0 then card (vertices (translation e2)) else x):⟦e2⟧)›*) have ":map_graph_fn (translation e2) ?f2:⟦e2⟧ ⊆ :?G:⟦e2⟧" using graph_union_semantics (*‹(:?A:⟦?e⟧) ∪ (:?B:⟦?e⟧) ⊆ :graph_union ?A ?B:⟦?e⟧›*) by blast also (*calculation: ‹⟦⋀(x::(nat × nat) set) y::(nat × nat) set. x ⊆ y ⟹ x O {(card (vertices (translation (e2::'a allegorical_term))), 1::nat)} ⊆ y O {(card (vertices (translation e2)), 1::nat)}; ⋀(x::(nat × nat) set) y::(nat × nat) set. x ⊆ y ⟹ x O {(card (vertices (translation e2)), 1::nat)} ⊆ y O {(card (vertices (translation e2)), 1::nat)}; ⋀(x::(nat × nat) set) y::(nat × nat) set. x ⊆ y ⟹ (:graph_union (map_graph_fn (translation (e1::'a allegorical_term)) (λx::nat. if x = (0::nat) then 0::nat else x + card (vertices (translation e2)) - (1::nat))) (map_graph_fn (translation e2) (λx::nat. if x = (0::nat) then card (vertices (translation e2)) else x)):⟦e1⟧) O x ⊆ (:graph_union (map_graph_fn (translation e1) (λx::nat. if x = (0::nat) then 0::nat else x + card (vertices (translation e2)) - (1::nat))) (map_graph_fn (translation e2) (λx::nat. if x = (0::nat) then card (vertices (translation e2)) else x)):⟦e1⟧) O y; ⋀(x::(nat × nat) set) y::(nat × nat) set. x ⊆ y ⟹ (:graph_union (map_graph_fn (translation e1) (λx::nat. if x = (0::nat) then 0::nat else x + card (vertices (translation e2)) - (1::nat))) (map_graph_fn (translation e2) (λx::nat. if x = (0::nat) then card (vertices (translation e2)) else x)):⟦e1⟧) O x ⊆ (:graph_union (map_graph_fn (translation e1) (λx::nat. if x = (0::nat) then 0::nat else x + card (vertices (translation e2)) - (1::nat))) (map_graph_fn (translation e2) (λx::nat. if x = (0::nat) then card (vertices (translation e2)) else x)):⟦e1⟧) O y⟧ ⟹ {(0::nat, 1::nat)} ⊆ (:graph_union (map_graph_fn (translation e1) (λx::nat. if x = (0::nat) then 0::nat else x + card (vertices (translation e2)) - (1::nat))) (map_graph_fn (translation e2) (λx::nat. if x = (0::nat) then card (vertices (translation e2)) else x)):⟦e1⟧) O (:graph_union (map_graph_fn (translation e1) (λx::nat. if x = (0::nat) then 0::nat else x + card (vertices (translation e2)) - (1::nat))) (map_graph_fn (translation e2) (λx::nat. if x = (0::nat) then card (vertices (translation e2)) else x)):⟦e2⟧)›*) have "(:?G:⟦e1⟧) O (:?G:⟦e2⟧) = :translation (A_Cmp e1 e2):⟦A_Cmp e1 e2⟧" by (auto simp:Let_def (*‹Let ?s ?f ≡ ?f ?s›*)) finally (*calculation: ‹⟦⋀x y. x ⊆ y ⟹ x O {(card (vertices (translation e2)), 1)} ⊆ y O {(card (vertices (translation e2)), 1)}; ⋀x y. x ⊆ y ⟹ x O {(card (vertices (translation e2)), 1)} ⊆ y O {(card (vertices (translation e2)), 1)}; ⋀x y. x ⊆ y ⟹ (:graph_union (map_graph_fn (translation e1) (λx. if x = 0 then 0 else x + card (vertices (translation e2)) - 1)) (map_graph_fn (translation e2) (λx. if x = 0 then card (vertices (translation e2)) else x)):⟦e1⟧) O x ⊆ (:graph_union (map_graph_fn (translation e1) (λx. if x = 0 then 0 else x + card (vertices (translation e2)) - 1)) (map_graph_fn (translation e2) (λx. if x = 0 then card (vertices (translation e2)) else x)):⟦e1⟧) O y; ⋀x y. x ⊆ y ⟹ (:graph_union (map_graph_fn (translation e1) (λx. if x = 0 then 0 else x + card (vertices (translation e2)) - 1)) (map_graph_fn (translation e2) (λx. if x = 0 then card (vertices (translation e2)) else x)):⟦e1⟧) O x ⊆ (:graph_union (map_graph_fn (translation e1) (λx. if x = 0 then 0 else x + card (vertices (translation e2)) - 1)) (map_graph_fn (translation e2) (λx. if x = 0 then card (vertices (translation e2)) else x)):⟦e1⟧) O y⟧ ⟹ {(0, 1)} ⊆ :translation (A_Cmp e1 e2):⟦A_Cmp e1 e2⟧›*) show "?case" (*goal: ‹(0::nat, 1::nat) ∈ :translation (A_Cmp (e1::'a allegorical_term) (e2::'a allegorical_term)):⟦A_Cmp e1 e2⟧›*) by auto next (*goals: 1. ‹⋀e. (0, 1) ∈ :translation e:⟦e⟧ ⟹ (0, 1) ∈ :translation (A_Cnv e):⟦A_Cnv e⟧› 2. ‹⋀x. (0, 1) ∈ :translation (A_Lbl x):⟦A_Lbl x⟧›*) case (A_Cnv e) (*‹(0, 1) ∈ :translation e:⟦e⟧›*) from map_graph_in[OF translation_graph this, of "(λx. if x < (2::nat) then 1 - x else x)"] (*‹(if 0 < 2 then 1 - 0 else 0, if 1 < 2 then 1 - 1 else 1) ∈ :map_graph_fn (translation e) (λx. if x < 2 then 1 - x else x):⟦e⟧›*) show "?case" (*goal: ‹(0, 1) ∈ :translation (A_Cnv e):⟦A_Cnv e⟧›*) using map_graph_in[OF translation_graph] (*‹(?a::nat, ?b::nat) ∈ :translation (?X1::?'a allegorical_term):⟦?e::?'a allegorical_term⟧ ⟹ ((?f::nat ⇒ ?'c) ?a, ?f ?b) ∈ :map_graph_fn (translation ?X1) ?f:⟦?e⟧›*) by auto qed (simp add:getRel_def (*‹getRel ?l ?G = {(x, y). (?l, x, y) ∈ edges ?G}›*)) (*solved the remaining goal: ‹⋀x. (0, 1) ∈ :translation (A_Lbl x):⟦A_Lbl x⟧›*) text ‹Lemma 6 is only used on rules of the form @{term "e⇩L ⊑ e⇩R"}. The requirement of G being a graph can be dropped for one direction.› lemma maintained_holds[intro]: assumes ":G:⟦e⇩L⟧ ⊆ :G:⟦e⇩R⟧" shows "maintained (transl_rule (e⇩L ⊑ e⇩R)) G" proof (cases "graph G") (*goals: 1. ‹graph G ⟹ maintained (transl_rule (e⇩L ⊑ e⇩R)) G› 2. ‹G ≠ restrict G ⟹ maintained (transl_rule (e⇩L ⊑ e⇩R)) G›*) case True (*‹graph G›*) thus "?thesis" (*goal: ‹maintained (transl_rule (e⇩L ⊑ e⇩R)) G›*) using assms (*‹:G::('b, 'a) labeled_graph:⟦e⇩L::'b allegorical_term⟧ ⊆ :G:⟦e⇩R::'b allegorical_term⟧›*) sentence_iff (*‹?G ⊨ ?e₁ ⊑ ?e₂ = (:?G:⟦?e₁⟧ ⊆ :?G:⟦?e₂⟧)›*) maintained_holds_iff (*‹graph ?G ⟹ maintained (translation ?e⇩L, translation (A_Int ?e⇩L ?e⇩R)) ?G = ?G ⊨ ?e⇩L ⊑ ?e⇩R›*) prod.sel (*‹fst (?x1.0::?'a::type, ?x2.0::?'b::type) = ?x1.0› ‹snd (?x1.0, ?x2.0) = ?x2.0›*) by metis next (*goal: ‹G ≠ restrict G ⟹ maintained (transl_rule (e⇩L ⊑ e⇩R)) G›*) case False (*‹(G::('b, 'a) labeled_graph) ≠ restrict G›*) thus "?thesis" (*goal: ‹maintained (transl_rule ((e⇩L::'b allegorical_term) ⊑ (e⇩R::'b allegorical_term))) (G::('b, 'a) labeled_graph)›*) by (auto simp:maintained_def (*‹maintained ?R ?G ≡ ∀f. graph_homomorphism (fst ?R) ?G f ⟶ extensible ?R ?G f›*) graph_homomorphism_def (*‹graph_homomorphism ?G₁ ?G₂ ?f = (vertices ?G₁ = Domain ?f ∧ graph ?G₁ ∧ graph ?G₂ ∧ ?f `` vertices ?G₁ ⊆ vertices ?G₂ ∧ univalent ?f ∧ edge_preserving ?f (edges ?G₁) (edges ?G₂))›*)) qed lemma maintained_holds_subset_iff[simp]: assumes "graph G" shows "maintained (transl_rule (e⇩L ⊑ e⇩R)) G ⟷ (:G:⟦e⇩L⟧ ⊆ :G:⟦e⇩R⟧)" using assms (*‹graph G›*) maintained_holds_iff (*‹graph ?G ⟹ maintained (translation ?e⇩L, translation (A_Int ?e⇩L ?e⇩R)) ?G = ?G ⊨ ?e⇩L ⊑ ?e⇩R›*) sentence_iff (*‹?G ⊨ ?e₁ ⊑ ?e₂ = (:?G:⟦?e₁⟧ ⊆ :?G:⟦?e₂⟧)›*) prod.sel (*‹fst (?x1.0, ?x2.0) = ?x1.0› ‹snd (?x1.0::?'aa::type, ?x2.0::?'a::type) = ?x2.0›*) by metis end
{ "path": "afp-2025-02-12/thys/Graph_Saturation/RuleSemanticsConnection.thy", "repo": "afp-2025-02-12", "sha": "64cb5533c7b4ed1d90f5996833b8edcfac5d1a3c01ff7c3a730e2c28cec57b28" }
theory AList_Extra imports "HOL-Library.AList" List_util begin lemma list_all2_rel_prod_updateI: assumes "list_all2 (rel_prod (=) R) xs ys" and "R xval yval" shows "list_all2 (rel_prod (=) R) (AList.update k xval xs) (AList.update k yval ys)" using assms(1,1,2) (*‹list_all2 (rel_prod (=) (R::'b ⇒ 'c ⇒ bool)) (xs::('a × 'b) list) (ys::('a × 'c) list)› ‹list_all2 (rel_prod (=) (R::'b::type ⇒ 'c::type ⇒ bool)) (xs::('a::type × 'b::type) list) (ys::('a::type × 'c::type) list)› ‹R xval yval›*) apply (induction xs ys rule: list.rel_induct (*‹⟦list_all2 (?R::?'a ⇒ ?'b ⇒ bool) (?x::?'a list) (?y::?'b list); (?Q::?'a list ⇒ ?'b list ⇒ bool) [] []; ⋀(a21::?'a) (a22::?'a list) (b21::?'b) b22::?'b list. ⟦?R a21 b21; ?Q a22 b22⟧ ⟹ ?Q (a21 # a22) (b21 # b22)⟧ ⟹ ?Q ?x ?y›*)) (*goals: 1. ‹⟦list_all2 (rel_prod (=) R) [] []; R xval yval⟧ ⟹ list_all2 (rel_prod (=) R) (AList.update k xval []) (AList.update k yval [])› 2. ‹⋀a21 a22 b21 b22. ⟦rel_prod (=) R a21 b21; ⟦list_all2 (rel_prod (=) R) a22 b22; R xval yval⟧ ⟹ list_all2 (rel_prod (=) R) (AList.update k xval a22) (AList.update k yval b22); list_all2 (rel_prod (=) R) (a21 # a22) (b21 # b22); R xval yval⟧ ⟹ list_all2 (rel_prod (=) R) (AList.update k xval (a21 # a22)) (AList.update k yval (b21 # b22))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma length_map_entry[simp]: "length (AList.map_entry k f al) = length al" apply (induction al) (*goals: 1. ‹length (AList.map_entry k f []) = length []› 2. ‹⋀a al. length (AList.map_entry k f al) = length al ⟹ length (AList.map_entry k f (a # al)) = length (a # al)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma map_entry_id0[simp]: "AList.map_entry k id = id" proof (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹⋀x. AList.map_entry k id x = id x›*) fix xs show "AList.map_entry k id xs = id xs" apply (induction xs) (*goals: 1. ‹AList.map_entry k id [] = id []› 2. ‹⋀a xs. AList.map_entry k id xs = id xs ⟹ AList.map_entry k id (a # xs) = id (a # xs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed lemma map_entry_id: "AList.map_entry k id xs = xs" by simp lemma map_entry_map_of_Some_conv: "map_of xs k = Some v ⟹ AList.map_entry k f xs = AList.update k (f v) xs" apply (induction xs) (*goals: 1. ‹map_of [] k = Some v ⟹ AList.map_entry k f [] = AList.update k (f v) []› 2. ‹⋀a xs. ⟦map_of xs k = Some v ⟹ AList.map_entry k f xs = AList.update k (f v) xs; map_of (a # xs) k = Some v⟧ ⟹ AList.map_entry k f (a # xs) = AList.update k (f v) (a # xs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma map_entry_map_of_None_conv: "map_of xs k = None ⟹ AList.map_entry k f xs = xs" apply (induction xs) (*goals: 1. ‹map_of [] k = None ⟹ AList.map_entry k f [] = []› 2. ‹⋀a xs. ⟦map_of xs k = None ⟹ AList.map_entry k f xs = xs; map_of (a # xs) k = None⟧ ⟹ AList.map_entry k f (a # xs) = a # xs› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma list_all2_rel_prod_map_entry: assumes "list_all2 (rel_prod (=) R) xs ys" and "⋀xval yval. map_of xs k = Some xval ⟹ map_of ys k = Some yval ⟹ R (f xval) (g yval)" shows "list_all2 (rel_prod (=) R) (AList.map_entry k f xs) (AList.map_entry k g ys)" using assms(1)[THEN rel_option_map_of, of k] (*‹rel_option R (map_of xs k) (map_of ys k)›*) proof (cases rule: option.rel_cases (*‹⟦rel_option (?R::?'a ⇒ ?'b ⇒ bool) (?a::?'a option) (?b::?'b option); ⟦?a = None; ?b = None⟧ ⟹ ?thesis::bool; ⋀(x::?'a) y::?'b. ⟦?a = Some x; ?b = Some y; ?R x y⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) (*goals: 1. ‹⟦map_of xs k = None; map_of ys k = None⟧ ⟹ list_all2 (rel_prod (=) R) (AList.map_entry k f xs) (AList.map_entry k g ys)› 2. ‹⋀x y. ⟦map_of xs k = Some x; map_of ys k = Some y; R x y⟧ ⟹ list_all2 (rel_prod (=) R) (AList.map_entry k f xs) (AList.map_entry k g ys)›*) case None (*‹map_of xs k = None› ‹map_of ys k = None›*) thus "?thesis" (*goal: ‹list_all2 (rel_prod (=) R) (AList.map_entry k f xs) (AList.map_entry k g ys)›*) using assms(1) (*‹list_all2 (rel_prod (=) R) xs ys›*) by (simp add: map_entry_map_of_None_conv (*‹map_of ?xs ?k = None ⟹ AList.map_entry ?k ?f ?xs = ?xs›*)) next (*goal: ‹⋀x y. ⟦map_of xs k = Some x; map_of ys k = Some y; R x y⟧ ⟹ list_all2 (rel_prod (=) R) (AList.map_entry k f xs) (AList.map_entry k g ys)›*) case (Some xval yval) (*‹map_of xs k = Some xval› ‹map_of ys k = Some yval› ‹R xval yval›*) then show "?thesis" (*goal: ‹list_all2 (rel_prod (=) R) (AList.map_entry k f xs) (AList.map_entry k g ys)›*) using assms(1,2) (*‹list_all2 (rel_prod (=) R) xs ys› ‹⟦map_of xs k = Some ?xval; map_of ys k = Some ?yval⟧ ⟹ R (f ?xval) (g ?yval)›*) by (auto simp add: map_entry_map_of_Some_conv (*‹map_of ?xs ?k = Some ?v ⟹ AList.map_entry ?k ?f ?xs = AList.update ?k (?f ?v) ?xs›*) intro!: list_all2_rel_prod_updateI (*‹⟦list_all2 (rel_prod (=) ?R) ?xs ?ys; ?R ?xval ?yval⟧ ⟹ list_all2 (rel_prod (=) ?R) (AList.update ?k ?xval ?xs) (AList.update ?k ?yval ?ys)›*)) qed lemmas list_all2_rel_prod_map_entry1 = list_all2_rel_prod_map_entry[where g = id, simplified] lemmas list_all2_rel_prod_map_entry2 = list_all2_rel_prod_map_entry[where f = id, simplified] lemma list_all_updateI: assumes "list_all P xs" and "P (k, v)" shows "list_all P (AList.update k v xs)" using assms (*‹list_all P xs› ‹P (k, v)›*) apply (induction xs) (*goals: 1. ‹⟦list_all (P::'a::type × 'b::type ⇒ bool) []; P (k::'a::type, v::'b::type)⟧ ⟹ list_all P (AList.update k v [])› 2. ‹⋀(a::'a::type × 'b::type) xs::('a::type × 'b::type) list. ⟦⟦list_all (P::'a::type × 'b::type ⇒ bool) xs; P (k::'a::type, v::'b::type)⟧ ⟹ list_all P (AList.update k v xs); list_all P (a # xs); P (k, v)⟧ ⟹ list_all P (AList.update k v (a # xs))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma set_update: "set (AList.update k v xs) ⊆ {(k, v)} ∪ set xs" apply (induction xs) (*goals: 1. ‹set (AList.update (k::'a) (v::'b) []) ⊆ {(k, v)} ∪ set []› 2. ‹⋀(a::'a × 'b) xs::('a × 'b) list. set (AList.update (k::'a) (v::'b) xs) ⊆ {(k, v)} ∪ set xs ⟹ set (AList.update k v (a # xs)) ⊆ {(k, v)} ∪ set (a # xs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . end
{ "path": "afp-2025-02-12/thys/Interpreter_Optimizations/AList_Extra.thy", "repo": "afp-2025-02-12", "sha": "969f4d5792811789df2a8a81739a91908100d90858c2c4cb3c83a7170cf676a4" }
section ‹Set Cover› theory Approx_SC_Hoare imports "HOL-Hoare.Hoare_Logic" Complex_Main (* "HOL-Analysis.Harmonic_Numbers" *) begin text ‹This is a formalization of the set cover algorithm and proof in the book by Kleinberg and Tardos \<^cite>‹"KleinbergT06"›.› definition harm :: "nat ⇒ 'a :: real_normed_field" where "harm n = (∑k=1..n. inverse (of_nat k))" (* For simplicity defined locally instead of importing HOL-Analysis.Harmonic_Numbers. Only the definition, no theorems are needed. *) locale Set_Cover = (* Set Cover *) fixes w :: "nat ⇒ real" and m :: nat and S :: "nat ⇒ 'a set" assumes S_finite: "∀i ∈ {1..m}. finite (S i)" and w_nonneg: "∀i. 0 ≤ w i" begin definition U :: "'a set" where "U = (⋃i ∈ {1..m}. S i)" lemma S_subset: "∀i ∈ {1..m}. S i ⊆ U" using U_def (*‹U = ⋃ (S ` {1..m})›*) by blast lemma U_finite: "finite U" unfolding U_def (*goal: ‹finite (⋃ (S ` {1..m}))›*) using S_finite (*‹∀i∈{1..m}. finite (S i)›*) by blast lemma empty_cover: "m = 0 ⟹ U = {}" using U_def (*‹U = ⋃ (S ` {1..m})›*) by simp definition sc :: "nat set ⇒ 'a set ⇒ bool" where "sc C X ⟷ C ⊆ {1..m} ∧ (⋃i ∈ C. S i) = X" definition cost :: "'a set ⇒ nat ⇒ real" where "cost R i = w i / card (S i ∩ R)" lemma cost_nonneg: "0 ≤ cost R i" using w_nonneg (*‹∀i::nat. (0::real) ≤ (w::nat ⇒ real) i›*) by (simp add: cost_def (*‹cost ?R ?i = w ?i / real (card (S ?i ∩ ?R))›*)) text ‹‹cost R i = 0› if ‹card (S i ∩ R) = 0›! Needs to be accounted for separately in ‹min_arg›.› fun min_arg :: "'a set ⇒ nat ⇒ nat" where "min_arg R 0 = 1" | "min_arg R (Suc x) = (let j = min_arg R x in if S j ∩ R = {} ∨ (S (Suc x) ∩ R ≠ {} ∧ cost R (Suc x) < cost R j) then (Suc x) else j)" lemma min_in_range: "k > 0 ⟹ min_arg R k ∈ {1..k}" apply (induction k) (*goals: 1. ‹0 < 0 ⟹ min_arg R 0 ∈ {1..0}› 2. ‹⋀k. ⟦0 < k ⟹ min_arg R k ∈ {1..k}; 0 < Suc k⟧ ⟹ min_arg R (Suc k) ∈ {1..Suc k}› discuss goal 1*) apply (force simp: Let_def (*‹Let ?s ?f ≡ ?f ?s›*)) (*discuss goal 2*) apply (force simp: Let_def (*‹Let (?s::?'a) (?f::?'a ⇒ ?'b) ≡ ?f ?s›*)) (*proven 2 subgoals*) . lemma min_empty: "S (min_arg R k) ∩ R = {} ⟹ ∀i ∈ {1..k}. S i ∩ R = {}" proof (induction k) (*goals: 1. ‹S (min_arg R 0) ∩ R = {} ⟹ ∀i∈{1..0}. S i ∩ R = {}› 2. ‹⋀k. ⟦S (min_arg R k) ∩ R = {} ⟹ ∀i∈{1..k}. S i ∩ R = {}; S (min_arg R (Suc k)) ∩ R = {}⟧ ⟹ ∀i∈{1..Suc k}. S i ∩ R = {}›*) case (Suc k) (*‹S (min_arg R k) ∩ R = {} ⟹ ∀i∈{1..k}. S i ∩ R = {}› ‹(S::nat ⇒ 'a::type set) (min_arg (R::'a::type set) (Suc (k::nat))) ∩ R = {}›*) from Suc.prems (*‹S (min_arg R (Suc k)) ∩ R = {}›*) have prem: "S (min_arg R k) ∩ R = {}" by (auto simp: Let_def (*‹Let ?s ?f ≡ ?f ?s›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) with Suc.IH (*‹S (min_arg R k) ∩ R = {} ⟹ ∀i∈{1..k}. S i ∩ R = {}›*) have IH: "∀i ∈ {1..k}. S i ∩ R = {}" . show "?case" (*goal: ‹∀i::nat∈{1::nat..Suc (k::nat)}. (S::nat ⇒ 'a set) i ∩ (R::'a set) = {}›*) proof (standard) (*goal: ‹⋀i. i ∈ {1..Suc k} ⟹ S i ∩ R = {}›*) fix i assume "i ∈ {1..Suc k}" (*‹(i::nat) ∈ {1::nat..Suc (k::nat)}›*) show "S i ∩ R = {}" proof (cases ‹i = Suc k›) (*goals: 1. ‹i = Suc k ⟹ S i ∩ R = {}› 2. ‹i ≠ Suc k ⟹ S i ∩ R = {}›*) case True (*‹i = Suc k›*) with Suc.prems (*‹S (min_arg R (Suc k)) ∩ R = {}›*) prem (*‹S (min_arg R k) ∩ R = {}›*) show "?thesis" (*goal: ‹S i ∩ R = {}›*) by simp next (*goal: ‹(i::nat) ≠ Suc (k::nat) ⟹ (S::nat ⇒ 'a set) i ∩ (R::'a set) = {}›*) case False (*‹i ≠ Suc k›*) with IH (*‹∀i∈{1..k}. S i ∩ R = {}›*) ‹i ∈ {1..Suc k}› (*‹i ∈ {1..Suc k}›*) show "?thesis" (*goal: ‹(S::nat ⇒ 'a set) (i::nat) ∩ (R::'a set) = {}›*) by simp qed qed qed (simp) (*solved the remaining goal: ‹S (min_arg R 0) ∩ R = {} ⟹ ∀i∈{1..0}. S i ∩ R = {}›*) lemma min_correct: "⟦ i ∈ {1..k}; S i ∩ R ≠ {} ⟧ ⟹ cost R (min_arg R k) ≤ cost R i" proof (induction k) (*goals: 1. ‹⟦(i::nat) ∈ {1::nat..0::nat}; (S::nat ⇒ 'a set) i ∩ (R::'a set) ≠ {}⟧ ⟹ cost R (min_arg R (0::nat)) ≤ cost R i› 2. ‹⋀k::nat. ⟦⟦(i::nat) ∈ {1::nat..k}; (S::nat ⇒ 'a set) i ∩ (R::'a set) ≠ {}⟧ ⟹ cost R (min_arg R k) ≤ cost R i; i ∈ {1::nat..Suc k}; S i ∩ R ≠ {}⟧ ⟹ cost R (min_arg R (Suc k)) ≤ cost R i›*) case (Suc k) (*‹⟦i ∈ {1..k}; S i ∩ R ≠ {}⟧ ⟹ cost R (min_arg R k) ≤ cost R i› ‹i ∈ {1..Suc k}› ‹S i ∩ R ≠ {}›*) show "?case" (*goal: ‹cost R (min_arg R (Suc k)) ≤ cost R i›*) proof (cases ‹i = Suc k›) (*goals: 1. ‹(i::nat) = Suc (k::nat) ⟹ cost (R::'a::type set) (min_arg R (Suc k)) ≤ cost R i› 2. ‹(i::nat) ≠ Suc (k::nat) ⟹ cost (R::'a::type set) (min_arg R (Suc k)) ≤ cost R i›*) case True (*‹i = Suc k›*) with Suc.prems (*‹(i::nat) ∈ {1::nat..Suc (k::nat)}› ‹S i ∩ R ≠ {}›*) show "?thesis" (*goal: ‹cost R (min_arg R (Suc k)) ≤ cost R i›*) by (auto simp: Let_def (*‹Let (?s::?'a) (?f::?'a ⇒ ?'b) ≡ ?f ?s›*)) next (*goal: ‹i ≠ Suc k ⟹ cost R (min_arg R (Suc k)) ≤ cost R i›*) case False (*‹(i::nat) ≠ Suc (k::nat)›*) with Suc.prems (*‹(i::nat) ∈ {1::nat..Suc (k::nat)}› ‹S i ∩ R ≠ {}›*) Suc.IH (*‹⟦i ∈ {1..k}; S i ∩ R ≠ {}⟧ ⟹ cost R (min_arg R k) ≤ cost R i›*) have IH: "cost R (min_arg R k) ≤ cost R i" by simp from Suc.prems (*‹i ∈ {1..Suc k}› ‹S i ∩ R ≠ {}›*) False (*‹i ≠ Suc k›*) min_empty[of R k] (*‹S (min_arg R k) ∩ R = {} ⟹ ∀i∈{1..k}. S i ∩ R = {}›*) have "S (min_arg R k) ∩ R ≠ {}" by force with IH (*‹cost R (min_arg R k) ≤ cost R i›*) show "?thesis" (*goal: ‹cost R (min_arg R (Suc k)) ≤ cost R i›*) by (auto simp: Let_def (*‹Let ?s ?f ≡ ?f ?s›*)) qed qed (simp) (*solved the remaining goal: ‹⟦i ∈ {1..0}; S i ∩ R ≠ {}⟧ ⟹ cost R (min_arg R 0) ≤ cost R i›*) text ‹Correctness holds quite trivially for both m = 0 and m > 0 (assuming a set cover can be found at all, otherwise algorithm would not terminate).› lemma set_cover_correct: "VARS (R :: 'a set) (C :: nat set) (i :: nat) {True} R := U; C := {}; WHILE R ≠ {} INV {R ⊆ U ∧ sc C (U - R)} DO i := min_arg R m; R := R - S i; C := C ∪ {i} OD {sc C U}" proof (vcg, goal_cases) (*goals: 1. ‹⋀(R::'a set) (C::nat set) i::nat. True ⟹ U ⊆ U ∧ sc {} (U - U)› 2. ‹⋀(R::'a set) (C::nat set) i::nat. (R ⊆ U ∧ sc C (U - R)) ∧ R ≠ {} ⟹ R - (S::nat ⇒ 'a set) (min_arg R (m::nat)) ⊆ U ∧ sc (C ∪ {min_arg R m}) (U - (R - S (min_arg R m)))› 3. ‹⋀(R::'a set) (C::nat set) i::nat. (R ⊆ U ∧ sc C (U - R)) ∧ ¬ R ≠ {} ⟹ sc C U›*) case 2 (*‹(R_ ⊆ U ∧ sc C_ (U - R_)) ∧ R_ ≠ {}›*) show "?case" (*goal: ‹R_ - S (min_arg R_ m) ⊆ U ∧ sc (C_ ∪ {min_arg R_ m}) (U - (R_ - S (min_arg R_ m)))›*) proof (cases m) (*goals: 1. ‹(m::nat) = (0::nat) ⟹ (R_::'a set) - (S::nat ⇒ 'a set) (min_arg R_ m) ⊆ U ∧ sc ((C_::nat set) ∪ {min_arg R_ m}) (U - (R_ - S (min_arg R_ m)))› 2. ‹⋀nat::nat. (m::nat) = Suc nat ⟹ (R_::'a set) - (S::nat ⇒ 'a set) (min_arg R_ m) ⊆ U ∧ sc ((C_::nat set) ∪ {min_arg R_ m}) (U - (R_ - S (min_arg R_ m)))›*) case 0 (*‹m = 0›*) from empty_cover[OF this] (*‹U = {}›*) "2" (*‹(R_ ⊆ U ∧ sc C_ (U - R_)) ∧ R_ ≠ {}›*) show "?thesis" (*goal: ‹(R_::'a set) - (S::nat ⇒ 'a set) (min_arg R_ (m::nat)) ⊆ U ∧ sc ((C_::nat set) ∪ {min_arg R_ m}) (U - (R_ - S (min_arg R_ m)))›*) by (auto simp: sc_def (*‹sc ?C ?X = (?C ⊆ {1..m} ∧ ⋃ (S ` ?C) = ?X)›*)) next (*goal: ‹⋀nat. m = Suc nat ⟹ R_ - S (min_arg R_ m) ⊆ U ∧ sc (C_ ∪ {min_arg R_ m}) (U - (R_ - S (min_arg R_ m)))›*) case Suc (*‹m = Suc nat_›*) then have "m > 0" by simp from min_in_range[OF this] (*‹min_arg (?R::'a set) (m::nat) ∈ {1::nat..m}›*) "2" (*‹(R_ ⊆ U ∧ sc C_ (U - R_)) ∧ R_ ≠ {}›*) show "?thesis" (*goal: ‹R_ - S (min_arg R_ m) ⊆ U ∧ sc (C_ ∪ {min_arg R_ m}) (U - (R_ - S (min_arg R_ m)))›*) using S_subset (*‹∀i∈{1..m}. S i ⊆ U›*) by (auto simp: sc_def (*‹sc ?C ?X = (?C ⊆ {1..m} ∧ ⋃ (S ` ?C) = ?X)›*)) qed qed (auto simp: sc_def (*‹sc ?C ?X = (?C ⊆ {1..m} ∧ ⋃ (S ` ?C) = ?X)›*)) (*solves the remaining goals: 1. ‹⋀R C i. True ⟹ U ⊆ U ∧ sc {} (U - U)› 2. ‹⋀R C i. (R ⊆ U ∧ sc C (U - R)) ∧ ¬ R ≠ {} ⟹ sc C U›*) definition c_exists :: "nat set ⇒ 'a set ⇒ bool" where "c_exists C R = (∃c. sum w C = sum c (U - R) ∧ (∀i. 0 ≤ c i) ∧ (∀k ∈ {1..m}. sum c (S k ∩ (U - R)) ≤ (∑j = card (S k ∩ R) + 1..card (S k). inverse j) * w k))" definition inv :: "nat set ⇒ 'a set ⇒ bool" where "inv C R ⟷ sc C (U - R) ∧ R ⊆ U ∧ c_exists C R" lemma invI: assumes "sc C (U - R)" "R ⊆ U" "∃c. sum w C = sum c (U - R) ∧ (∀i. 0 ≤ c i) ∧ (∀k ∈ {1..m}. sum c (S k ∩ (U - R)) ≤ (∑j = card (S k ∩ R) + 1..card (S k). inverse j) * w k)" shows "inv C R" using assms (*‹sc C (U - R)› ‹R ⊆ U› ‹∃c. sum w C = sum c (U - R) ∧ (∀i. 0 ≤ c i) ∧ (∀k∈{1..m}. sum c (S k ∩ (U - R)) ≤ (∑j = card (S k ∩ R) + 1..card (S k). inverse (real j)) * w k)›*) by (auto simp: inv_def (*‹local.inv ?C ?R = (sc ?C (U - ?R) ∧ ?R ⊆ U ∧ c_exists ?C ?R)›*) c_exists_def (*‹c_exists ?C ?R = (∃c. sum w ?C = sum c (U - ?R) ∧ (∀i. 0 ≤ c i) ∧ (∀k∈{1..m}. sum c (S k ∩ (U - ?R)) ≤ (∑j = card (S k ∩ ?R) + 1..card (S k). inverse (real j)) * w k))›*)) lemma invD: assumes "inv C R" shows "sc C (U - R)" "R ⊆ U" "∃c. sum w C = sum c (U - R) ∧ (∀i. 0 ≤ c i) ∧ (∀k ∈ {1..m}. sum c (S k ∩ (U - R)) ≤ (∑j = card (S k ∩ R) + 1..card (S k). inverse j) * w k)" using assms (*‹local.inv C R›*) apply - (*goals: 1. ‹local.inv C R ⟹ sc C (U - R)› 2. ‹local.inv C R ⟹ R ⊆ U› 3. ‹local.inv C R ⟹ ∃c. sum w C = sum c (U - R) ∧ (∀i. 0 ≤ c i) ∧ (∀k∈{1..m}. sum c (S k ∩ (U - R)) ≤ (∑j = card (S k ∩ R) + 1..card (S k). inverse (real j)) * w k)› discuss goal 1*) apply ((auto simp: inv_def (*‹local.inv ?C ?R = (sc ?C (U - ?R) ∧ ?R ⊆ U ∧ c_exists ?C ?R)›*) c_exists_def (*‹c_exists ?C ?R = (∃c. sum w ?C = sum c (U - ?R) ∧ (∀i. 0 ≤ c i) ∧ (∀k∈{1..m}. sum c (S k ∩ (U - ?R)) ≤ (∑j = card (S k ∩ ?R) + 1..card (S k). inverse (real j)) * w k))›*))[1]) (*discuss goal 2*) apply ((auto simp: inv_def (*‹local.inv ?C ?R = (sc ?C (U - ?R) ∧ ?R ⊆ U ∧ c_exists ?C ?R)›*) c_exists_def (*‹c_exists ?C ?R = (∃c. sum w ?C = sum c (U - ?R) ∧ (∀i. 0 ≤ c i) ∧ (∀k∈{1..m}. sum c (S k ∩ (U - ?R)) ≤ (∑j = card (S k ∩ ?R) + 1..card (S k). inverse (real j)) * w k))›*))[1]) (*discuss goal 3*) apply ((auto simp: inv_def (*‹local.inv ?C ?R = (sc ?C (U - ?R) ∧ ?R ⊆ U ∧ c_exists ?C ?R)›*) c_exists_def (*‹c_exists ?C ?R = (∃c. sum w ?C = sum c (U - ?R) ∧ (∀i. 0 ≤ c i) ∧ (∀k∈{1..m}. sum c (S k ∩ (U - ?R)) ≤ (∑j = card (S k ∩ ?R) + 1..card (S k). inverse (real j)) * w k))›*))[1]) (*proven 3 subgoals*) . lemma inv_init: "inv {} U" proof (rule invI (*‹⟦sc (?C::nat set) (U - (?R::'a set)); ?R ⊆ U; ∃c::'a ⇒ real. sum (w::nat ⇒ real) ?C = sum c (U - ?R) ∧ (∀i::'a. (0::real) ≤ c i) ∧ (∀k::nat∈{1::nat..m::nat}. sum c ((S::nat ⇒ 'a set) k ∩ (U - ?R)) ≤ (∑j::nat = card (S k ∩ ?R) + (1::nat)..card (S k). inverse (real j)) * w k)⟧ ⟹ local.inv ?C ?R›*), goal_cases) (*goals: 1. ‹sc {} (U - U)› 2. ‹U ⊆ U› 3. ‹∃c. sum w {} = sum c (U - U) ∧ (∀i. 0 ≤ c i) ∧ (∀k∈{1..m}. sum c (S k ∩ (U - U)) ≤ (∑j = card (S k ∩ U) + 1..card (S k). inverse (real j)) * w k)›*) case 3 (*no hyothesis introduced yet*) let ?c = "(λ_. 0) :: 'a ⇒ real" have "sum w {} = sum ?c (U - U)" by simp moreover { have "∀k ∈ {1..m}. 0 ≤ (∑j = card (S k ∩ U) + 1..card (S k). inverse j) * w k" by (simp add: sum_nonneg (*‹(⋀x. x ∈ ?A ⟹ 0 ≤ ?f x) ⟹ 0 ≤ sum ?f ?A›*) w_nonneg (*‹∀i. 0 ≤ w i›*)) then have "(∀k∈{1..m}. sum ?c (S k ∩ (U - U)) ≤ (∑j = card (S k ∩ U) + 1..card (S k). inverse j) * w k)" by simp } ultimately show "?case" (*goal: ‹∃c::'a::type ⇒ real. sum (w::nat ⇒ real) {} = sum c (U - U) ∧ (∀i::'a::type. (0::real) ≤ c i) ∧ (∀k::nat∈{1::nat..m::nat}. sum c ((S::nat ⇒ 'a::type set) k ∩ (U - U)) ≤ (∑j::nat = card (S k ∩ U) + (1::nat)..card (S k). inverse (real j)) * w k)›*) by blast qed (simp_all add: sc_def) (*solves the remaining goals: 1. ‹sc {} (U - U)› 2. ‹U ⊆ U›*) lemma inv_step: assumes "inv C R" "R ≠ {}" defines [simp]: "i ≡ min_arg R m" shows "inv (C ∪ {i}) (R - (S i))" proof (cases m) (*goals: 1. ‹(m::nat) = (0::nat) ⟹ local.inv ((C::nat set) ∪ {i::nat}) ((R::'a set) - (S::nat ⇒ 'a set) i)› 2. ‹⋀nat::nat. (m::nat) = Suc nat ⟹ local.inv ((C::nat set) ∪ {i::nat}) ((R::'a set) - (S::nat ⇒ 'a set) i)›*) case 0 (*‹(m::nat) = (0::nat)›*) from empty_cover[OF this] (*‹U = {}›*) invD(2)[OF assms ( 1 )] (*‹R ⊆ U›*) have "R = {}" by blast then show "?thesis" (*goal: ‹local.inv (C ∪ {i}) (R - S i)›*) using assms(2) (*‹R ≠ {}›*) by simp next (*goal: ‹⋀nat. m = Suc nat ⟹ local.inv (C ∪ {i}) (R - S i)›*) case Suc (*‹m = Suc nat_›*) then have "0 < m" by simp note hyp = invD[OF assms ( 1 )] (*‹sc C (U - R)› ‹R ⊆ U› ‹∃c. sum w C = sum c (U - R) ∧ (∀i. 0 ≤ c i) ∧ (∀k∈{1..m}. sum c (S k ∩ (U - R)) ≤ (∑j = card (S k ∩ R) + 1..card (S k). inverse (real j)) * w k)›*) show "?thesis" (*goal: ‹local.inv ((C::nat set) ∪ {i::nat}) ((R::'a set) - (S::nat ⇒ 'a set) i)›*) proof (rule invI (*‹⟦sc ?C (U - ?R); ?R ⊆ U; ∃c. sum w ?C = sum c (U - ?R) ∧ (∀i. 0 ≤ c i) ∧ (∀k∈{1..m}. sum c (S k ∩ (U - ?R)) ≤ (∑j = card (S k ∩ ?R) + 1..card (S k). inverse (real j)) * w k)⟧ ⟹ local.inv ?C ?R›*), goal_cases) (*goals: 1. ‹sc (C ∪ {i}) (U - (R - S i))› 2. ‹R - S i ⊆ U› 3. ‹∃c. sum w (C ∪ {i}) = sum c (U - (R - S i)) ∧ (∀i. 0 ≤ c i) ∧ (∀k∈{1..m}. sum c (S k ∩ (U - (R - S i))) ≤ (∑j = card (S k ∩ (R - S i)) + 1..card (S k). inverse (real j)) * w k)›*) case 1 (*no hyothesis introduced yet*) have "i ∈ {1..m}" using min_in_range[OF ‹0 < m›] (*‹min_arg ?R m ∈ {1..m}›*) by simp with hyp(1) (*‹sc C (U - R)›*) S_subset (*‹∀i∈{1..m}. S i ⊆ U›*) show "?case" (*goal: ‹sc (C ∪ {i}) (U - (R - S i))›*) by (auto simp: sc_def (*‹sc ?C ?X = (?C ⊆ {1..m} ∧ ⋃ (S ` ?C) = ?X)›*)) next (*goals: 1. ‹R - S i ⊆ U› 2. ‹∃c. sum w (C ∪ {i}) = sum c (U - (R - S i)) ∧ (∀i. 0 ≤ c i) ∧ (∀k∈{1..m}. sum c (S k ∩ (U - (R - S i))) ≤ (∑j = card (S k ∩ (R - S i)) + 1..card (S k). inverse (real j)) * w k)›*) case 2 (*no hyothesis introduced yet*) from hyp(2) (*‹R ⊆ U›*) show "?case" (*goal: ‹R - S i ⊆ U›*) by auto next (*goal: ‹∃c. sum w (C ∪ {i}) = sum c (U - (R - S i)) ∧ (∀i. 0 ≤ c i) ∧ (∀k∈{1..m}. sum c (S k ∩ (U - (R - S i))) ≤ (∑j = card (S k ∩ (R - S i)) + 1..card (S k). inverse (real j)) * w k)›*) case 3 (*no hyothesis introduced yet*) have "∃i ∈ {1..m}. S i ∩ R ≠ {}" using assms(2) (*‹R ≠ {}›*) U_def (*‹U = ⋃ ((S::nat ⇒ 'a::type set) ` {1::nat..m::nat})›*) hyp(2) (*‹R ⊆ U›*) by blast then have "S i ∩ R ≠ {}" using min_empty (*‹S (min_arg ?R ?k) ∩ ?R = {} ⟹ ∀i∈{1..?k}. S i ∩ ?R = {}›*) by auto then have "0 < card (S i ∩ R)" using S_finite (*‹∀i∈{1..m}. finite (S i)›*) min_in_range[OF ‹0 < m›] (*‹min_arg ?R m ∈ {1..m}›*) by auto from hyp(3) (*‹∃c. sum w C = sum c (U - R) ∧ (∀i. 0 ≤ c i) ∧ (∀k∈{1..m}. sum c (S k ∩ (U - R)) ≤ (∑j = card (S k ∩ R) + 1..card (S k). inverse (real j)) * w k)›*) obtain c where "sum w C = sum c (U - R)" "∀i. 0 ≤ c i" and SUM: "∀k∈{1..m}. sum c (S k ∩ (U - R)) ≤ (∑j = card (S k ∩ R) + 1..card (S k). inverse j) * w k" (*goal: ‹(⋀c. ⟦sum w C = sum c (U - R); ∀i. 0 ≤ c i; ∀k∈{1..m}. sum c (S k ∩ (U - R)) ≤ (∑j = card (S k ∩ R) + 1..card (S k). inverse (real j)) * w k⟧ ⟹ thesis) ⟹ thesis›*) by blast let ?c = "(λx. if x ∈ S i ∩ R then cost R i else c x)" have "finite (U - R)" "finite (S i ∩ R)" "(U - R) ∩ (S i ∩ R) = {}" using U_finite (*‹finite U›*) S_finite (*‹∀i::nat∈{1::nat..m::nat}. finite ((S::nat ⇒ 'a set) i)›*) min_in_range[OF ‹0 < m›] (*‹min_arg ?R m ∈ {1..m}›*) apply - (*goals: 1. ‹⟦finite U; ∀i∈{1..m}. finite (S i); ⋀R. min_arg R m ∈ {1..m}⟧ ⟹ finite (U - R)› 2. ‹⟦finite U; ∀i∈{1..m}. finite (S i); ⋀R. min_arg R m ∈ {1..m}⟧ ⟹ finite (S i ∩ R)› 3. ‹⟦finite U; ∀i∈{1..m}. finite (S i); ⋀R. min_arg R m ∈ {1..m}⟧ ⟹ (U - R) ∩ (S i ∩ R) = {}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . then have "sum ?c (U - R ∪ (S i ∩ R)) = sum ?c (U - R) + sum ?c (S i ∩ R)" by (rule sum.union_disjoint (*‹⟦finite ?A; finite ?B; ?A ∩ ?B = {}⟧ ⟹ sum ?g (?A ∪ ?B) = sum ?g ?A + sum ?g ?B›*)) moreover have U_split: "U - (R - S i) = U - R ∪ (S i ∩ R)" using hyp(2) (*‹R ⊆ U›*) by blast moreover { have "sum ?c (S i ∩ R) = card (S i ∩ R) * cost R i" by simp also (*calculation: ‹(∑x∈S i ∩ R. if x ∈ S i ∩ R then cost R i else c x) = real (card (S i ∩ R)) * cost R i›*) have "... = w i" unfolding cost_def (*goal: ‹real (card (S i ∩ R)) * (w i / real (card (S i ∩ R))) = w i›*) using ‹0 < card (S i ∩ R)› (*‹0 < card (S i ∩ R)›*) by simp finally (*calculation: ‹(∑x::'a∈S i ∩ R. if x ∈ (S::nat ⇒ 'a set) (i::nat) ∩ (R::'a set) then cost R i else (c::'a ⇒ real) x) = (w::nat ⇒ real) i›*) have "sum ?c (S i ∩ R) = w i" . } ultimately have "sum ?c (U - (R - S i)) = sum ?c (U - R) + w i" by simp moreover { have "C ∩ {i} = {}" using hyp(1) (*‹sc C (U - R)›*) ‹S i ∩ R ≠ {}› (*‹S i ∩ R ≠ {}›*) by (auto simp: sc_def (*‹sc ?C ?X = (?C ⊆ {1..m} ∧ ⋃ (S ` ?C) = ?X)›*)) from sum.union_disjoint[OF _ _ this] (*‹⟦finite C; finite {i}⟧ ⟹ sum ?g (C ∪ {i}) = sum ?g C + sum ?g {i}›*) have "sum w (C ∪ {i}) = sum w C + w i" using hyp(1) (*‹sc C (U - R)›*) by (auto simp: sc_def (*‹sc (?C::nat set) (?X::'a set) = (?C ⊆ {1::nat..m::nat} ∧ ⋃ ((S::nat ⇒ 'a set) ` ?C) = ?X)›*) intro: finite_subset (*‹⟦(?A::?'a set) ⊆ (?B::?'a set); finite ?B⟧ ⟹ finite ?A›*)) } ultimately have 1: "sum w (C ∪ {i}) = sum ?c (U - (R - S i))" using ‹sum w C = sum c (U - R)› (*‹sum w C = sum c (U - R)›*) by simp have 2: "∀i. 0 ≤ ?c i" using ‹∀i. 0 ≤ c i› (*‹∀i. 0 ≤ c i›*) cost_nonneg (*‹0 ≤ cost ?R ?i›*) by simp have 3: "∀k∈{1..m}. sum ?c (S k ∩ (U - (R - S i))) ≤ (∑j = card (S k ∩ (R - S i)) + 1..card (S k). inverse j) * w k" proof (standard) (*goal: ‹⋀k. k ∈ {1..m} ⟹ (∑x∈S k ∩ (U - (R - S i)). if x ∈ S i ∩ R then cost R i else c x) ≤ (∑j = card (S k ∩ (R - S i)) + 1..card (S k). inverse (real j)) * w k›*) fix k assume "k ∈ {1..m}" (*‹(k::nat) ∈ {1::nat..m::nat}›*) let ?rem = "S k ∩ R" let ?add = "S k ∩ S i ∩ R" let ?cov = "S k ∩ (U - R)" have "sum ?c (S k ∩ (U - (R - S i))) = sum ?c (S k ∩ (U - R ∪ (S i ∩ R)))" unfolding U_split (*goal: ‹(∑x∈S k ∩ (U - R ∪ S i ∩ R). if x ∈ S i ∩ R then cost R i else c x) = (∑x∈S k ∩ (U - R ∪ S i ∩ R). if x ∈ S i ∩ R then cost R i else c x)›*) by standard also (*calculation: ‹(∑x::'a∈S (k::nat) ∩ (U - (R - S i)). if x ∈ (S::nat ⇒ 'a set) (i::nat) ∩ (R::'a set) then cost R i else (c::'a ⇒ real) x) = (∑x::'a∈S k ∩ (U - R ∪ S i ∩ R). if x ∈ S i ∩ R then cost R i else c x)›*) have "... = sum ?c (?cov ∪ ?add)" by (simp add: Int_Un_distrib (*‹?A ∩ (?B ∪ ?C) = ?A ∩ ?B ∪ ?A ∩ ?C›*) Int_assoc (*‹?A ∩ ?B ∩ ?C = ?A ∩ (?B ∩ ?C)›*)) also (*calculation: ‹(∑x∈S k ∩ (U - (R - S i)). if x ∈ S i ∩ R then cost R i else c x) = (∑x∈S k ∩ (U - R) ∪ S k ∩ S i ∩ R. if x ∈ S i ∩ R then cost R i else c x)›*) have "... = sum ?c ?cov + sum ?c ?add" apply (rule sum.union_disjoint (*‹⟦finite ?A; finite ?B; ?A ∩ ?B = {}⟧ ⟹ sum ?g (?A ∪ ?B) = sum ?g ?A + sum ?g ?B›*)) (*goals: 1. ‹finite (S k ∩ (U - R))› 2. ‹finite (S k ∩ S i ∩ R)› 3. ‹S k ∩ (U - R) ∩ (S k ∩ S i ∩ R) = {}› discuss goal 1*) apply ((insert S_finite (*‹∀i∈{1..m}. finite (S i)›*) ‹k ∈ _›)[1]) (*top goal: ‹finite (S k ∩ (U - R))› and 2 goals remain*) apply ((auto)[1]) (*discuss goal 2*) apply ((insert S_finite (*‹∀i∈{1..m}. finite (S i)›*) ‹k ∈ _›)[1]) (*top goal: ‹finite (S k ∩ S i ∩ R)› and 1 goal remains*) apply ((auto)[1]) (*discuss goal 3*) apply ((insert S_finite (*‹∀i∈{1..m}. finite (S i)›*) ‹k ∈ _›)[1]) (*goal: ‹S k ∩ (U - R) ∩ (S k ∩ S i ∩ R) = {}›*) apply ((auto)[1]) (*proven 3 subgoals*) . finally (*calculation: ‹(∑x∈S k ∩ (U - (R - S i)). if x ∈ S i ∩ R then cost R i else c x) = (∑x∈S k ∩ (U - R). if x ∈ S i ∩ R then cost R i else c x) + (∑x∈S k ∩ S i ∩ R. if x ∈ S i ∩ R then cost R i else c x)›*) have lhs: "sum ?c (S k ∩ (U - (R - S i))) = sum ?c ?cov + sum ?c ?add" . have "S k ∩ (R - S i) = ?rem - ?add" by blast then have "card (S k ∩ (R - S i)) = card (?rem - ?add)" by simp also (*calculation: ‹card (S k ∩ (R - S i)) = card (S k ∩ R - S k ∩ S i ∩ R)›*) have "... = card ?rem - card ?add" using S_finite (*‹∀i::nat∈{1::nat..m::nat}. finite ((S::nat ⇒ 'a set) i)›*) ‹k ∈ _› (*‹k ∈ {1..m}›*) by (auto intro: card_Diff_subset (*‹⟦finite ?B; ?B ⊆ ?A⟧ ⟹ card (?A - ?B) = card ?A - card ?B›*)) finally (*calculation: ‹card (S k ∩ (R - S i)) = card (S k ∩ R) - card (S k ∩ S i ∩ R)›*) have rhs: "card (S k ∩ (R - S i)) + 1 = card ?rem - card ?add + 1" by simp have "sum ?c ?add = card ?add * cost R i" by simp also (*calculation: ‹(∑x::'a∈S (k::nat) ∩ S i ∩ R. if x ∈ (S::nat ⇒ 'a set) (i::nat) ∩ (R::'a set) then cost R i else (c::'a ⇒ real) x) = real (card (S k ∩ S i ∩ R)) * cost R i›*) have "... ≤ card ?add * cost R k" proof (cases "?rem = {}") (*goals: 1. ‹S k ∩ R = {} ⟹ real (card (S k ∩ S i ∩ R)) * cost R i ≤ real (card (S k ∩ S i ∩ R)) * cost R k› 2. ‹S k ∩ R ≠ {} ⟹ real (card (S k ∩ S i ∩ R)) * cost R i ≤ real (card (S k ∩ S i ∩ R)) * cost R k›*) case True (*‹S k ∩ R = {}›*) then have "card ?add = 0" by (auto simp: card_eq_0_iff (*‹(card ?A = 0) = (?A = {} ∨ infinite ?A)›*)) then show "?thesis" (*goal: ‹real (card (S k ∩ S i ∩ R)) * cost R i ≤ real (card (S k ∩ S i ∩ R)) * cost R k›*) by simp next (*goal: ‹S k ∩ R ≠ {} ⟹ real (card (S k ∩ S i ∩ R)) * cost R i ≤ real (card (S k ∩ S i ∩ R)) * cost R k›*) case False (*‹S k ∩ R ≠ {}›*) from min_correct[OF ‹k ∈ _› this] (*‹cost R (min_arg R m) ≤ cost R k›*) have "cost R i ≤ cost R k" by simp then show "?thesis" (*goal: ‹real (card (S k ∩ S i ∩ R)) * cost R i ≤ real (card (S k ∩ S i ∩ R)) * cost R k›*) by (simp add: mult_left_mono (*‹⟦?a ≤ ?b; 0 ≤ ?c⟧ ⟹ ?c * ?a ≤ ?c * ?b›*)) qed also (*calculation: ‹(∑x∈S k ∩ S i ∩ R. if x ∈ S i ∩ R then cost R i else c x) ≤ real (card (S k ∩ S i ∩ R)) * cost R k›*) have "... = card ?add * inverse (card ?rem) * w k" by (simp add: cost_def (*‹cost ?R ?i = w ?i / real (card (S ?i ∩ ?R))›*) divide_inverse_commute (*‹?a / ?b = inverse ?b * ?a›*)) also (*calculation: ‹(∑x∈S k ∩ S i ∩ R. if x ∈ S i ∩ R then cost R i else c x) ≤ real (card (S k ∩ S i ∩ R)) * inverse (real (card (S k ∩ R))) * w k›*) have "... = (∑j ∈ {card ?rem - card ?add + 1 .. card ?rem}. inverse (card ?rem)) * w k" proof (-) (*goal: ‹real (card (S k ∩ S i ∩ R)) * inverse (real (card (S k ∩ R))) * w k = (∑j = card (S k ∩ R) - card (S k ∩ S i ∩ R) + 1..card (S k ∩ R). inverse (real (card (S k ∩ R)))) * w k›*) have "card ?add ≤ card ?rem" using S_finite (*‹∀i∈{1..m}. finite (S i)›*) ‹k ∈ _› (*‹k ∈ {1..m}›*) by (blast intro: card_mono (*‹⟦finite ?B; ?A ⊆ ?B⟧ ⟹ card ?A ≤ card ?B›*)) then show "?thesis" (*goal: ‹real (card (S k ∩ S i ∩ R)) * inverse (real (card (S k ∩ R))) * w k = (∑j = card (S k ∩ R) - card (S k ∩ S i ∩ R) + 1..card (S k ∩ R). inverse (real (card (S k ∩ R)))) * w k›*) by (simp add: sum_distrib_left (*‹(?r::?'a) * sum (?f::?'b ⇒ ?'a) (?A::?'b set) = (∑n::?'b∈?A. ?r * ?f n)›*)) qed also (*calculation: ‹(∑x∈S k ∩ S i ∩ R. if x ∈ S i ∩ R then cost R i else c x) ≤ (∑j = card (S k ∩ R) - card (S k ∩ S i ∩ R) + 1..card (S k ∩ R). inverse (real (card (S k ∩ R)))) * w k›*) have "... ≤ (∑j ∈ {card ?rem - card ?add + 1 .. card ?rem}. inverse j) * w k" proof (-) (*goal: ‹(∑j = card (S k ∩ R) - card (S k ∩ S i ∩ R) + 1..card (S k ∩ R). inverse (real (card (S k ∩ R)))) * w k ≤ (∑j = card (S k ∩ R) - card (S k ∩ S i ∩ R) + 1..card (S k ∩ R). inverse (real j)) * w k›*) have "∀j ∈ {card ?rem - card ?add + 1 .. card ?rem}. inverse (card ?rem) ≤ inverse j" by force then have "(∑j ∈ {card ?rem - card ?add + 1 .. card ?rem}. inverse (card ?rem)) ≤ (∑j ∈ {card ?rem - card ?add + 1 .. card ?rem}. inverse j)" by (blast intro: sum_mono (*‹(⋀i. i ∈ ?K ⟹ ?f i ≤ ?g i) ⟹ sum ?f ?K ≤ sum ?g ?K›*)) with w_nonneg (*‹∀i. 0 ≤ w i›*) show "?thesis" (*goal: ‹(∑j = card (S k ∩ R) - card (S k ∩ S i ∩ R) + 1..card (S k ∩ R). inverse (real (card (S k ∩ R)))) * w k ≤ (∑j = card (S k ∩ R) - card (S k ∩ S i ∩ R) + 1..card (S k ∩ R). inverse (real j)) * w k›*) by (blast intro: mult_right_mono (*‹⟦?a ≤ ?b; 0 ≤ ?c⟧ ⟹ ?a * ?c ≤ ?b * ?c›*)) qed finally (*calculation: ‹(∑x∈S k ∩ S i ∩ R. if x ∈ S i ∩ R then cost R i else c x) ≤ (∑j = card (S k ∩ R) - card (S k ∩ S i ∩ R) + 1..card (S k ∩ R). inverse (real j)) * w k›*) have "sum ?c ?add ≤ (∑j ∈ {card ?rem - card ?add + 1 .. card ?rem}. inverse j) * w k" . moreover from SUM (*‹∀k∈{1..m}. sum c (S k ∩ (U - R)) ≤ (∑j = card (S k ∩ R) + 1..card (S k). inverse (real j)) * w k›*) have "sum ?c ?cov ≤ (∑j ∈ {card ?rem + 1 .. card (S k)}. inverse j) * w k" using ‹k ∈ {1..m}› (*‹(k::nat) ∈ {1::nat..m::nat}›*) by simp ultimately have "sum ?c (S k ∩ (U - (R - S i))) ≤ ((∑j ∈ {card ?rem - card ?add + 1 .. card ?rem}. inverse j) + (∑j ∈ {card ?rem + 1 .. card (S k)}. inverse j)) * w k" unfolding lhs (*goal: ‹(∑x∈S k ∩ (U - R). if x ∈ S i ∩ R then cost R i else c x) + (∑x∈S k ∩ S i ∩ R. if x ∈ S i ∩ R then cost R i else c x) ≤ ((∑j = card (S k ∩ R) - card (S k ∩ S i ∩ R) + 1..card (S k ∩ R). inverse (real j)) + (∑j = card (S k ∩ R) + 1..card (S k). inverse (real j))) * w k›*) by argo also (*calculation: ‹(∑x∈S k ∩ (U - (R - S i)). if x ∈ S i ∩ R then cost R i else c x) ≤ ((∑j = card (S k ∩ R) - card (S k ∩ S i ∩ R) + 1..card (S k ∩ R). inverse (real j)) + (∑j = card (S k ∩ R) + 1..card (S k). inverse (real j))) * w k›*) have "... = (∑j ∈ {card ?rem - card ?add + 1 .. card (S k)}. inverse j) * w k" proof (-) (*goal: ‹((∑j::nat = card ((S::nat ⇒ 'a::type set) (k::nat) ∩ (R::'a::type set)) - card (S k ∩ S (i::nat) ∩ R) + (1::nat)..card (S k ∩ R). inverse (real j)) + (∑j::nat = card (S k ∩ R) + (1::nat)..card (S k). inverse (real j))) * (w::nat ⇒ real) k = (∑j::nat = card (S k ∩ R) - card (S k ∩ S i ∩ R) + (1::nat)..card (S k). inverse (real j)) * w k›*) have sum_split: "b ∈ {a .. c} ⟹ sum f {a .. c} = sum f {a .. b} + sum f {Suc b .. c}" for f :: "nat ⇒ real" and a :: nat and b :: nat and c :: nat proof (-) (*goal: ‹b ∈ {a..c} ⟹ sum f {a..c} = sum f {a..b} + sum f {Suc b..c}›*) assume "b ∈ {a .. c}" (*‹(b::nat) ∈ {a::nat..c::nat}›*) then have "{a .. b} ∪ {Suc b .. c} = {a .. c}" by force moreover have "{a .. b} ∩ {Suc b .. c} = {}" using ‹b ∈ {a .. c}› (*‹b ∈ {a..c}›*) by auto ultimately show "?thesis" (*goal: ‹sum f {a..c} = sum f {a..b} + sum f {Suc b..c}›*) by (metis finite_atLeastAtMost (*‹finite {?l..?u}›*) sum.union_disjoint (*‹⟦finite ?A; finite ?B; ?A ∩ ?B = {}⟧ ⟹ sum ?g (?A ∪ ?B) = sum ?g ?A + sum ?g ?B›*)) qed have "(∑j ∈ {card ?rem - card ?add + 1 .. card (S k)}. inverse j) = (∑j ∈ {card ?rem - card ?add + 1 .. card ?rem}. inverse j) + (∑j ∈ {card ?rem + 1 .. card (S k)}. inverse j)" proof (cases ‹?add = {}›) (*goals: 1. ‹S k ∩ S i ∩ R = {} ⟹ (∑j = card (S k ∩ R) - card (S k ∩ S i ∩ R) + 1..card (S k). inverse (real j)) = (∑j = card (S k ∩ R) - card (S k ∩ S i ∩ R) + 1..card (S k ∩ R). inverse (real j)) + (∑j = card (S k ∩ R) + 1..card (S k). inverse (real j))› 2. ‹S k ∩ S i ∩ R ≠ {} ⟹ (∑j = card (S k ∩ R) - card (S k ∩ S i ∩ R) + 1..card (S k). inverse (real j)) = (∑j = card (S k ∩ R) - card (S k ∩ S i ∩ R) + 1..card (S k ∩ R). inverse (real j)) + (∑j = card (S k ∩ R) + 1..card (S k). inverse (real j))›*) case False (*‹S k ∩ S i ∩ R ≠ {}›*) then have "0 < card ?add" "0 < card ?rem" using S_finite (*‹∀i::nat∈{1::nat..m::nat}. finite ((S::nat ⇒ 'a set) i)›*) ‹k ∈ _› (*‹k ∈ {1..m}›*) apply - (*goals: 1. ‹⟦S k ∩ S i ∩ R ≠ {}; ∀i∈{1..m}. finite (S i); k ∈ {1..m}⟧ ⟹ 0 < card (S k ∩ S i ∩ R)› 2. ‹⟦S k ∩ S i ∩ R ≠ {}; ∀i∈{1..m}. finite (S i); k ∈ {1..m}⟧ ⟹ 0 < card (S k ∩ R)› discuss goal 1*) apply fastforce (*discuss goal 2*) apply fastforce (*proven 2 subgoals*) . then have "Suc (card ?rem - card ?add) ≤ card ?rem" by simp moreover have "card ?rem ≤ card (S k)" using S_finite (*‹∀i∈{1..m}. finite (S i)›*) ‹k ∈ _› (*‹k ∈ {1..m}›*) by (simp add: card_mono (*‹⟦finite (?B::?'a set); (?A::?'a set) ⊆ ?B⟧ ⟹ card ?A ≤ card ?B›*)) ultimately show "?thesis" (*goal: ‹(∑j = card (S k ∩ R) - card (S k ∩ S i ∩ R) + 1..card (S k). inverse (real j)) = (∑j = card (S k ∩ R) - card (S k ∩ S i ∩ R) + 1..card (S k ∩ R). inverse (real j)) + (∑j = card (S k ∩ R) + 1..card (S k). inverse (real j))›*) by (auto intro: sum_split (*‹?b ∈ {?a..?c} ⟹ sum ?f {?a..?c} = sum ?f {?a..?b} + sum ?f {Suc ?b..?c}›*)) qed (simp) (*solved the remaining goal: ‹S k ∩ S i ∩ R = {} ⟹ (∑j = card (S k ∩ R) - card (S k ∩ S i ∩ R) + 1..card (S k). inverse (real j)) = (∑j = card (S k ∩ R) - card (S k ∩ S i ∩ R) + 1..card (S k ∩ R). inverse (real j)) + (∑j = card (S k ∩ R) + 1..card (S k). inverse (real j))›*) then show "?thesis" (*goal: ‹((∑j::nat = card ((S::nat ⇒ 'a set) (k::nat) ∩ (R::'a set)) - card (S k ∩ S (i::nat) ∩ R) + (1::nat)..card (S k ∩ R). inverse (real j)) + (∑j::nat = card (S k ∩ R) + (1::nat)..card (S k). inverse (real j))) * (w::nat ⇒ real) k = (∑j::nat = card (S k ∩ R) - card (S k ∩ S i ∩ R) + (1::nat)..card (S k). inverse (real j)) * w k›*) by algebra qed finally (*calculation: ‹(∑x∈S k ∩ (U - (R - S i)). if x ∈ S i ∩ R then cost R i else c x) ≤ (∑j = card (S k ∩ R) - card (S k ∩ S i ∩ R) + 1..card (S k). inverse (real j)) * w k›*) show "sum ?c (S k ∩ (U - (R - S i))) ≤ (∑j ∈ {card (S k ∩ (R - S i)) + 1 .. card (S k)}. inverse j) * w k" unfolding rhs (*goal: ‹(∑x∈S k ∩ (U - (R - S i)). if x ∈ S i ∩ R then cost R i else c x) ≤ (∑j = card (S k ∩ R) - card (S k ∩ S i ∩ R) + 1..card (S k). inverse (real j)) * w k›*) . qed from "1" (*‹sum w (C ∪ {i}) = (∑x∈U - (R - S i). if x ∈ S i ∩ R then cost R i else c x)›*) "2" (*‹∀ia. 0 ≤ (if ia ∈ S i ∩ R then cost R i else c ia)›*) "3" (*‹∀k∈{1..m}. (∑x∈S k ∩ (U - (R - S i)). if x ∈ S i ∩ R then cost R i else c x) ≤ (∑j = card (S k ∩ (R - S i)) + 1..card (S k). inverse (real j)) * w k›*) show "?case" (*goal: ‹∃c::'a::type ⇒ real. sum (w::nat ⇒ real) ((C::nat set) ∪ {i::nat}) = sum c (U - ((R::'a::type set) - (S::nat ⇒ 'a::type set) i)) ∧ (∀i::'a::type. (0::real) ≤ c i) ∧ (∀k::nat∈{1::nat..m::nat}. sum c (S k ∩ (U - (R - S i))) ≤ (∑j::nat = card (S k ∩ (R - S i)) + (1::nat)..card (S k). inverse (real j)) * w k)›*) by blast qed qed lemma cover_sum: fixes c :: "'a ⇒ real" assumes "sc C V" "∀i. 0 ≤ c i" shows "sum c V ≤ (∑i ∈ C. sum c (S i))" proof (-) (*goal: ‹sum c V ≤ (∑i∈C. sum c (S i))›*) from assms(1) (*‹sc C V›*) have "finite C" by (auto simp: sc_def (*‹sc ?C ?X = (?C ⊆ {1..m} ∧ ⋃ (S ` ?C) = ?X)›*) finite_subset (*‹⟦?A ⊆ ?B; finite ?B⟧ ⟹ finite ?A›*)) then show "?thesis" (*goal: ‹sum c V ≤ (∑i∈C. sum c (S i))›*) using assms(1) (*‹sc C V›*) proof (induction C arbitrary: V rule: finite_induct) (*goals: 1. ‹⋀V. sc {} V ⟹ sum c V ≤ (∑i∈{}. sum c (S i))› 2. ‹⋀x F V. ⟦finite F; x ∉ F; ⋀V. sc F V ⟹ sum c V ≤ (∑i∈F. sum c (S i)); sc (insert x F) V⟧ ⟹ sum c V ≤ (∑i∈insert x F. sum c (S i))›*) case (insert i C) (*‹finite C› ‹i ∉ C› ‹sc (C::nat set) (?V::'a set) ⟹ sum (c::'a ⇒ real) ?V ≤ (∑i::nat∈C. sum c ((S::nat ⇒ 'a set) i))› ‹sc (insert i C) V›*) have V_split: "(⋃ (S ` insert i C)) = (⋃ (S ` C)) ∪ S i" by auto have finite: "finite (⋃ (S ` C))" "finite (S i)" using insert (*‹finite C› ‹i ∉ C› ‹sc C ?V ⟹ sum c ?V ≤ (∑i∈C. sum c (S i))› ‹sc (insert i C) V›*) S_finite (*‹∀i∈{1..m}. finite (S i)›*) apply - (*goals: 1. ‹⟦finite C; i ∉ C; ⋀V. sc C V ⟹ sum c V ≤ (∑i∈C. sum c (S i)); sc (insert i C) V; ∀i∈{1..m}. finite (S i)⟧ ⟹ finite (⋃ (S ` C))› 2. ‹⟦finite C; i ∉ C; ⋀V. sc C V ⟹ sum c V ≤ (∑i∈C. sum c (S i)); sc (insert i C) V; ∀i∈{1..m}. finite (S i)⟧ ⟹ finite (S i)› discuss goal 1*) apply ((auto simp: sc_def (*‹sc ?C ?X = (?C ⊆ {1..m} ∧ ⋃ (S ` ?C) = ?X)›*))[1]) (*discuss goal 2*) apply ((auto simp: sc_def (*‹sc ?C ?X = (?C ⊆ {1..m} ∧ ⋃ (S ` ?C) = ?X)›*))[1]) (*proven 2 subgoals*) . have "sum c (S i) - sum c (⋃ (S ` C) ∩ S i) ≤ sum c (S i)" using assms(2) (*‹∀i. 0 ≤ c i›*) by (simp add: sum_nonneg (*‹(⋀x. x ∈ ?A ⟹ 0 ≤ ?f x) ⟹ 0 ≤ sum ?f ?A›*)) then have "sum c (⋃ (S ` insert i C)) ≤ sum c (⋃ (S ` C)) + sum c (S i)" unfolding V_split (*goal: ‹sum c (⋃ (S ` C) ∪ S i) ≤ sum c (⋃ (S ` C)) + sum c (S i)›*) using sum_Un[OF finite, of c] (*‹sum c (⋃ (S ` C) ∪ S i) = sum c (⋃ (S ` C)) + sum c (S i) - sum c (⋃ (S ` C) ∩ S i)›*) by linarith moreover have "(∑i∈insert i C. sum c (S i)) = (∑i ∈ C. sum c (S i)) + sum c (S i)" by (simp add: insert.hyps (*‹finite (C::nat set)› ‹(i::nat) ∉ (C::nat set)›*)) ultimately show "?case" (*goal: ‹sum c V ≤ (∑i∈insert i C. sum c (S i))›*) using insert (*‹finite C› ‹(i::nat) ∉ (C::nat set)› ‹sc C ?V ⟹ sum c ?V ≤ (∑i∈C. sum c (S i))› ‹sc (insert i C) V›*) by (fastforce simp: sc_def (*‹sc ?C ?X = (?C ⊆ {1..m} ∧ ⋃ (S ` ?C) = ?X)›*)) qed (simp add: sc_def (*‹sc ?C ?X = (?C ⊆ {1..m} ∧ ⋃ (S ` ?C) = ?X)›*)) (*solved the remaining goal: ‹⋀V. sc {} V ⟹ sum c V ≤ (∑i∈{}. sum c (S i))›*) qed abbreviation H :: "nat ⇒ real" where "H ≡ harm" definition d_star :: nat ("d⇧*") where "d⇧* ≡ Max (card ` (S ` {1..m}))" lemma set_cover_bound: assumes "inv C {}" "sc C' U" shows "sum w C ≤ H d⇧* * sum w C'" proof (-) (*goal: ‹sum (w::nat ⇒ real) (C::nat set) ≤ harm d⇧* * sum w (C'::nat set)›*) from invD(3)[OF assms ( 1 )] (*‹∃c::'a ⇒ real. sum (w::nat ⇒ real) (C::nat set) = sum c (U - {}) ∧ (∀i::'a. (0::real) ≤ c i) ∧ (∀k::nat∈{1::nat..m::nat}. sum c ((S::nat ⇒ 'a set) k ∩ (U - {})) ≤ (∑j::nat = card (S k ∩ {}) + (1::nat)..card (S k). inverse (real j)) * w k)›*) obtain c where "sum w C = sum c U" "∀i. 0 ≤ c i" and H_bound: "∀k ∈ {1..m}. sum c (S k) ≤ H (card (S k)) * w k" (*goal: ‹(⋀c. ⟦sum w C = sum c U; ∀i. 0 ≤ c i; ∀k∈{1..m}. sum c (S k) ≤ harm (card (S k)) * w k⟧ ⟹ thesis) ⟹ thesis›*) by (auto simp: harm_def (*‹harm (?n::nat) = (∑k::nat = 1::nat..?n. inverse (of_nat k))›*) Int_absorb2 (*‹(?A::?'a set) ⊆ (?B::?'a set) ⟹ ?A ∩ ?B = ?A›*) S_subset (*‹∀i::nat∈{1::nat..m::nat}. (S::nat ⇒ 'a set) i ⊆ U›*)) have "∀k ∈ {1..m}. card (S k) ≤ d⇧*" by (auto simp: d_star_def (*‹d⇧* ≡ Max (card ` S ` {1..m})›*)) then have "∀k ∈ {1..m}. H (card (S k)) ≤ H d⇧*" by (auto simp: harm_def (*‹harm ?n = (∑k = 1..?n. inverse (of_nat k))›*) intro!: sum_mono2 (*‹⟦finite ?B; ?A ⊆ ?B; ⋀b. b ∈ ?B - ?A ⟹ 0 ≤ ?f b⟧ ⟹ sum ?f ?A ≤ sum ?f ?B›*)) with H_bound (*‹∀k∈{1..m}. sum c (S k) ≤ harm (card (S k)) * w k›*) have "∀k ∈ {1..m}. sum c (S k) ≤ H d⇧* * w k" by (metis atLeastAtMost_iff (*‹(?i ∈ {?l..?u}) = (?l ≤ ?i ∧ ?i ≤ ?u)›*) atLeastatMost_empty_iff (*‹({?a..?b} = {}) = (¬ ?a ≤ ?b)›*) empty_iff (*‹(?c ∈ {}) = False›*) mult_right_mono (*‹⟦?a ≤ ?b; 0 ≤ ?c⟧ ⟹ ?a * ?c ≤ ?b * ?c›*) w_nonneg (*‹∀i. 0 ≤ w i›*)) moreover have "C' ⊆ {1..m}" using assms(2) (*‹sc C' U›*) by (simp add: sc_def (*‹sc ?C ?X = (?C ⊆ {1..m} ∧ ⋃ (S ` ?C) = ?X)›*)) ultimately have "∀i ∈ C'. sum c (S i) ≤ H d⇧* * w i" by blast then have "(∑i ∈ C'. sum c (S i)) ≤ H d⇧* * sum w C'" by (auto simp: sum_distrib_left (*‹?r * sum ?f ?A = (∑n∈?A. ?r * ?f n)›*) intro: sum_mono (*‹(⋀i. i ∈ ?K ⟹ ?f i ≤ ?g i) ⟹ sum ?f ?K ≤ sum ?g ?K›*)) have "sum w C = sum c U" by fact also (*calculation: ‹sum w C = sum c U›*) have "... ≤ (∑i ∈ C'. sum c (S i))" apply (rule cover_sum[OF assms(2)] (*‹∀i. 0 ≤ ?c i ⟹ sum ?c U ≤ (∑i∈C'. sum ?c (S i))›*)) (*goal: ‹sum c U ≤ (∑i∈C'. sum c (S i))›*) by fact also (*calculation: ‹sum w C ≤ (∑i∈C'. sum c (S i))›*) have "... ≤ H d⇧* * sum w C'" by fact finally (*calculation: ‹sum w C ≤ harm d⇧* * sum w C'›*) show "?thesis" (*goal: ‹sum (w::nat ⇒ real) (C::nat set) ≤ harm d⇧* * sum w (C'::nat set)›*) . qed theorem set_cover_approx: "VARS (R :: 'a set) (C :: nat set) (i :: nat) {True} R := U; C := {}; WHILE R ≠ {} INV {inv C R} DO i := min_arg R m; R := R - S i; C := C ∪ {i} OD {sc C U ∧ (∀C'. sc C' U ⟶ sum w C ≤ H d⇧* * sum w C')}" proof (vcg, goal_cases) (*goals: 1. ‹⋀(R::'a set) (C::nat set) i::nat. True ⟹ local.inv {} U› 2. ‹⋀(R::'a set) (C::nat set) i::nat. local.inv C R ∧ R ≠ {} ⟹ local.inv (C ∪ {min_arg R (m::nat)}) (R - (S::nat ⇒ 'a set) (min_arg R m))› 3. ‹⋀(R::'a set) (C::nat set) i::nat. local.inv C R ∧ ¬ R ≠ {} ⟹ sc C U ∧ (∀C'::nat set. sc C' U ⟶ sum (w::nat ⇒ real) C ≤ harm d⇧* * sum w C')›*) case 1 (*‹True›*) show "?case" (*goal: ‹local.inv {} U›*) by (rule inv_init (*‹local.inv {} U›*)) next (*goals: 1. ‹⋀R C i. local.inv C R ∧ R ≠ {} ⟹ local.inv (C ∪ {min_arg R m}) (R - S (min_arg R m))› 2. ‹⋀R C i. local.inv C R ∧ ¬ R ≠ {} ⟹ sc C U ∧ (∀C'. sc C' U ⟶ sum w C ≤ harm d⇧* * sum w C')›*) case 2 (*‹local.inv C_ R_ ∧ R_ ≠ {}›*) thus "?case" (*goal: ‹local.inv (C_ ∪ {min_arg R_ m}) (R_ - S (min_arg R_ m))›*) using inv_step (*‹⟦local.inv (?C::nat set) (?R::'a::type set); ?R ≠ {}⟧ ⟹ local.inv (?C ∪ {min_arg ?R (m::nat)}) (?R - (S::nat ⇒ 'a::type set) (min_arg ?R m))›*) apply standard (*goals: 1. ‹⟦local.inv C_ R_; R_ ≠ {}⟧ ⟹ local.inv C_ R_› 2. ‹⟦local.inv C_ R_; R_ ≠ {}⟧ ⟹ R_ ≠ {}› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) next (*goal: ‹⋀R C i. local.inv C R ∧ ¬ R ≠ {} ⟹ sc C U ∧ (∀C'. sc C' U ⟶ sum w C ≤ harm d⇧* * sum w C')›*) case (3 R C i) (*‹local.inv C R ∧ ¬ R ≠ {}›*) then have "sc C U" unfolding inv_def (*goal: ‹sc (C::nat set) U›*) by auto with "3" (*‹local.inv C R ∧ ¬ R ≠ {}›*) show "?case" (*goal: ‹sc C U ∧ (∀C'. sc C' U ⟶ sum w C ≤ harm d⇧* * sum w C')›*) by (auto intro: set_cover_bound (*‹⟦local.inv ?C {}; sc ?C' U⟧ ⟹ sum w ?C ≤ harm d⇧* * sum w ?C'›*)) qed end (* Set Cover *) end (* Theory *)
{ "path": "afp-2025-02-12/thys/Approximation_Algorithms/Approx_SC_Hoare.thy", "repo": "afp-2025-02-12", "sha": "e4d8ce1344a4336cbc7277ec1d991d975d455a6f0c51d11b35ffdb11f497ff55" }
section ‹The Same Vote Model› theory Same_Vote imports Voting begin context quorum_process begin subsection ‹Model definition› (******************************************************************************) text ‹The system state remains the same as in the Voting model, but the voting event is changed.› definition safe :: "v_state ⇒ round ⇒ val ⇒ bool" where safe_def': "safe s r v ≡ ∀r' < r. ∀Q ∈ Quorum. ∀w. (votes s r') ` Q = {Some w} ⟶ v = w" text ‹This definition of @{term safe} is easier to reason about in Isabelle.› lemma safe_def: "safe s r v = (∀r' < r. ∀Q w. quorum_for Q w (votes s r') ⟶ v = w)" by (auto simp add: safe_def' (*‹safe ?s ?r ?v ≡ ∀r'<?r. ∀Q∈Quorum. ∀w. votes ?s r' ` Q = {Some w} ⟶ ?v = w›*) quorum_for_def' (*‹quorum_for ?Q ?v ?v_f ≡ ?Q ∈ Quorum ∧ ?v_f ` ?Q = {Some ?v}›*) Ball_def (*‹Ball ?A ?P = (∀x. x ∈ ?A ⟶ ?P x)›*)) definition sv_round :: "round ⇒ process set ⇒ val ⇒ (process, val)map ⇒ (v_state × v_state) set" where "sv_round r S v r_decisions = {(s, s'). ― ‹guards› r = next_round s ∧ (S ≠ {} ⟶ safe s r v) ∧ d_guard r_decisions (const_map v S) ∧ ― ‹actions› s' = s⦇ next_round := Suc r , votes := (votes s)(r := const_map v S) , decisions := (decisions s ++ r_decisions) ⦈ }" definition sv_trans :: "(v_state × v_state) set" where "sv_trans = (⋃r S v D. sv_round r S v D) ∪ Id" definition sv_TS :: "v_state TS" where "sv_TS = ⦇ init = v_init, trans = sv_trans ⦈" lemmas sv_TS_defs = sv_TS_def v_init_def sv_trans_def subsection ‹Refinement› (******************************************************************************) lemma safe_imp_no_defection: "safe s (next_round s) v ⟹ no_defection s (const_map v S) (next_round s)" by (auto simp add: safe_def (*‹safe ?s ?r ?v = (∀r'<?r. ∀Q w. quorum_for Q w (votes ?s r') ⟶ ?v = w)›*) no_defection_def (*‹no_defection ?s ?round_votes ?r = (∀r'<?r. ∀a Q v. quorum_for Q v (votes ?s r') ∧ a ∈ Q ⟶ ?round_votes a ∈ {None, Some v})›*) restrict_map_def (*‹?m |` ?A = (λx. if x ∈ ?A then ?m x else None)›*) const_map_def (*‹const_map ?v ?S ≡ (λ_. Some ?v) |` ?S›*)) lemma const_map_quorum_locked: "S ∈ Quorum ⟹ locked_in_vf (const_map v S) v" by (auto simp add: locked_in_vf_def (*‹locked_in_vf ?v_f ?v ≡ ∃Q. quorum_for Q ?v ?v_f›*) const_map_def (*‹const_map ?v ?S ≡ (λ_. Some ?v) |` ?S›*) quorum_for_def (*‹quorum_for ?Q ?v ?v_f = (?Q ∈ Quorum ∧ (∀p∈?Q. ?v_f p = Some ?v))›*)) lemma sv_round_refines: "{Id} v_round r (const_map v S) r_decisions, sv_round r S v r_decisions {> Id}" by (auto simp add: PO_rhoare_defs (*‹{?pre::(?'s::type × ?'t::type) set} ?Ra::(?'s::type × ?'s::type) set, ?Rc::(?'t::type × ?'t::type) set {> ?post::(?'s::type × ?'t::type) set} ≡ ?pre O ?Rc ⊆ ?Ra O ?post› ‹(?r::(?'a::type × ?'c::type) set) O (?s::(?'c::type × ?'b::type) set) = {(x::?'a::type, z::?'b::type). ∃y::?'c::type. (x, y) ∈ ?r ∧ (y, z) ∈ ?s}›*) sv_round_def (*‹sv_round (?r::nat) (?S::process set) (?v::val) (?r_decisions::process ⇒ val option) = {(s::v_state, s'::v_state). ?r = next_round s ∧ (?S ≠ {} ⟶ safe s ?r ?v) ∧ d_guard ?r_decisions (const_map ?v ?S) ∧ s' = s⦇next_round := Suc ?r, votes := (votes s)(?r := const_map ?v ?S), decisions := decisions s ++ ?r_decisions⦈}›*) v_round_def (*‹v_round (?r::nat) (?r_votes::process ⇒ val option) (?r_decisions::process ⇒ val option) = {(s::v_state, s'::v_state). ?r = next_round s ∧ no_defection s ?r_votes ?r ∧ d_guard ?r_decisions ?r_votes ∧ s' = s⦇next_round := Suc ?r, votes := (votes s)(?r := ?r_votes), decisions := decisions s ++ ?r_decisions⦈}›*) no_defection_empty (*‹no_defection (?s::v_state) (λx::process. None) (?r'::nat)›*) dest!: safe_imp_no_defection (*‹safe (?s::v_state) (next_round ?s) (?v::val) ⟹ no_defection ?s (const_map ?v (?S::process set)) (next_round ?s)›*) const_map_quorum_locked (*‹(?S::process set) ∈ (Quorum::process set set) ⟹ locked_in_vf (const_map (?v::val) ?S) ?v›*)) lemma Same_Vote_Refines: "PO_refines Id v_TS sv_TS" by (auto simp add: PO_refines_def (*‹PO_refines ?R ?Ta ?Tc ≡ init ?Tc ⊆ ?R `` init ?Ta ∧ {?R} TS.trans ?Ta, TS.trans ?Tc {> ?R}›*) sv_TS_def (*‹sv_TS = ⦇init = v_init, trans = sv_trans⦈›*) sv_trans_def (*‹sv_trans = (⋃r S v. ⋃ (range (sv_round r S v)))⁼›*) v_TS_defs (*‹v_TS = ⦇init = v_init, trans = v_trans⦈› ‹v_init = {⦇next_round = 0, votes = λr a. None, decisions = λx. None⦈}› ‹v_trans = (⋃r v_f. ⋃ (range (v_round r v_f)))⁼›*) intro!: sv_round_refines (*‹{Id} v_round ?r (const_map ?v ?S) ?r_decisions, sv_round ?r ?S ?v ?r_decisions {> Id}›*) relhoare_refl (*‹{Id} ?R, ?R {> Id}›*)) subsection ‹Invariants› (******************************************************************************) definition SV_inv3 where "SV_inv3 = {s. ∀r a b v w. votes s r a = Some v ∧ votes s r b = Some w ⟶ v = w }" lemmas SV_inv3I = SV_inv3_def [THEN setc_def_to_intro, rule_format] lemmas SV_inv3E [elim] = SV_inv3_def [THEN setc_def_to_elim, rule_format] lemmas SV_inv3D = SV_inv3_def [THEN setc_def_to_dest, rule_format] subsubsection ‹Proof of invariants› (******************************************************************************) lemma SV_inv3_v_round: "{SV_inv3} sv_round r S v D {> SV_inv3}" apply (clarsimp simp add: PO_hoare_defs (*‹{?pre} ?R {> ?post} ≡ ?R `` ?pre ⊆ ?post› ‹?r `` ?s = {y. ∃x∈?s. (x, y) ∈ ?r}›*) intro!: SV_inv3I (*‹(⋀r a b v w. votes ?x r a = Some v ∧ votes ?x r b = Some w ⟹ v = w) ⟹ ?x ∈ majorities.SV_inv3›*)) (*goal: ‹{majorities.SV_inv3} sv_round r S v D {> majorities.SV_inv3}›*) by (force simp add: sv_round_def (*‹sv_round ?r ?S ?v ?r_decisions = {(s, s'). ?r = next_round s ∧ (?S ≠ {} ⟶ safe s ?r ?v) ∧ d_guard ?r_decisions (const_map ?v ?S) ∧ s' = s⦇next_round := Suc ?r, votes := (votes s)(?r := const_map ?v ?S), decisions := decisions s ++ ?r_decisions⦈}›*) const_map_def (*‹const_map ?v ?S ≡ (λ_. Some ?v) |` ?S›*) restrict_map_def (*‹?m |` ?A = (λx. if x ∈ ?A then ?m x else None)›*) SV_inv3_def (*‹majorities.SV_inv3 = {s. ∀r a b v w. votes s r a = Some v ∧ votes s r b = Some w ⟶ v = w}›*)) lemmas SV_inv3_event_pres = SV_inv3_v_round lemma SV_inv3_inductive: "init sv_TS ⊆ SV_inv3" "{SV_inv3} trans sv_TS {> SV_inv3}" (*goals: 1. ‹init sv_TS ⊆ majorities.SV_inv3› 2. ‹{majorities.SV_inv3} TS.trans sv_TS {> majorities.SV_inv3}› discuss goal 1*) apply (simp add: sv_TS_defs (*‹sv_TS = ⦇init = v_init, trans = sv_trans⦈› ‹v_init = {⦇next_round = 0, votes = λr a. None, decisions = λx. None⦈}› ‹sv_trans = (⋃r S v. ⋃ (range (sv_round r S v)))⁼›*) SV_inv3_def (*‹majorities.SV_inv3 = {s. ∀r a b v w. votes s r a = Some v ∧ votes s r b = Some w ⟶ v = w}›*)) (*discuss goal 2*) apply (auto simp add: sv_TS_defs (*‹sv_TS = ⦇init = v_init, trans = sv_trans⦈› ‹v_init = {⦇next_round = 0, votes = λr a. None, decisions = λx. None⦈}› ‹sv_trans = (⋃r S v. ⋃ (range (sv_round r S v)))⁼›*) SV_inv3_event_pres (*‹{majorities.SV_inv3} sv_round ?r ?S ?v ?D {> majorities.SV_inv3}›*)) (*proven 2 subgoals*) . lemma SV_inv3_invariant: "reach sv_TS ⊆ SV_inv3" by (auto intro!: inv_rule_basic (*‹⟦init (?T::(?'a, ?'b) TS_scheme) ⊆ (?P::?'a set); {?P} TS.trans ?T {> ?P}⟧ ⟹ reach ?T ⊆ ?P›*) SV_inv3_inductive (*‹init sv_TS ⊆ majorities.SV_inv3› ‹{majorities.SV_inv3} TS.trans sv_TS {> majorities.SV_inv3}›*) del: subsetI (*‹(⋀x::?'a. x ∈ (?A::?'a set) ⟹ x ∈ (?B::?'a set)) ⟹ ?A ⊆ ?B›*)) text ‹ This is a different characterization of @{term safe}, due to Lampson~\<^cite>‹"lampson_abcds_2001"›: @{term "safe' s r v = (∀r'< r. (∃Q ∈ Quorum. ∀a ∈ Q. ∀w. votes s r' a = Some w ⟶ w = v))"} It is, however, strictly stronger than our characterization, since we do not at this point assume the "completeness" of our quorum system (for any set S, either S or the complement of S is a quorum), and the following is thus not provable: @{term "s ∈ SV_inv3 ⟹ safe' s = safe s"}. › subsubsection ‹Transfer of abstract invariants› (******************************************************************************) lemma SV_inv1_inductive: "init sv_TS ⊆ Vinv1" "{Vinv1} trans sv_TS {> Vinv1}" (*goals: 1. ‹init sv_TS ⊆ Vinv1› 2. ‹{Vinv1} TS.trans sv_TS {> Vinv1}› discuss goal 1*) apply (rule abs_INV_init_transfer[OF Same_Vote_Refines Vinv1_inductive(1), simplified] (*‹init sv_TS ⊆ Vinv1›*)) (*discuss goal 2*) apply (rule abs_INV_trans_transfer[OF Same_Vote_Refines Vinv1_inductive(2), simplified] (*‹{Vinv1} TS.trans sv_TS {> Vinv1}›*)) (*proven 2 subgoals*) . lemma SV_inv1_invariant: "reach sv_TS ⊆ Vinv1" by (rule abs_INV_transfer[OF Same_Vote_Refines Vinv1_invariant, simplified] (*‹reach sv_TS ⊆ Vinv1›*)) lemma SV_inv2_inductive: "init sv_TS ⊆ Vinv2" "{Vinv2 ∩ Vinv1} trans sv_TS {> Vinv2}" (*goals: 1. ‹init sv_TS ⊆ Vinv2› 2. ‹{Vinv2 ∩ Vinv1} TS.trans sv_TS {> Vinv2}› discuss goal 1*) apply (rule abs_INV_init_transfer[OF Same_Vote_Refines Vinv2_inductive(1), simplified] (*‹init sv_TS ⊆ Vinv2›*)) (*discuss goal 2*) apply (rule abs_INV_trans_transfer[OF Same_Vote_Refines Vinv2_inductive(2), simplified] (*‹{Vinv2 ∩ Vinv1} TS.trans sv_TS {> Vinv2}›*)) (*proven 2 subgoals*) . lemma SV_inv2_invariant: "reach sv_TS ⊆ Vinv2" by (rule abs_INV_transfer[OF Same_Vote_Refines Vinv2_invariant, simplified] (*‹reach sv_TS ⊆ Vinv2›*)) subsubsection ‹Additional invariants› (******************************************************************************) text ‹With Same Voting, the voted values are safe in the next round.› definition SV_inv4 :: "v_state set" where "SV_inv4 = {s. ∀v a r. votes s r a = Some v ⟶ safe s (Suc r) v }" lemmas SV_inv4I = SV_inv4_def [THEN setc_def_to_intro, rule_format] lemmas SV_inv4E [elim] = SV_inv4_def [THEN setc_def_to_elim, rule_format] lemmas SV_inv4D = SV_inv4_def [THEN setc_def_to_dest, rule_format] lemma SV_inv4_sv_round: "{SV_inv4 ∩ (Vinv1 ∩ Vinv2)} sv_round r S v D {> SV_inv4}" proof (clarsimp simp add: PO_hoare_defs (*‹{?pre} ?R {> ?post} ≡ ?R `` ?pre ⊆ ?post› ‹?r `` ?s = {y. ∃x∈?s. (x, y) ∈ ?r}›*) intro!: SV_inv4I (*‹(⋀v a r. votes ?x r a = Some v ⟹ safe ?x (Suc r) v) ⟹ ?x ∈ SV_inv4›*)) (*goal: ‹⋀x va a ra xa. ⟦votes x ra a = Some va; (xa, x) ∈ sv_round r S v D; xa ∈ SV_inv4; xa ∈ Vinv1; xa ∈ Vinv2⟧ ⟹ safe x (Suc ra) va›*) fix s and v' and a and r' and s' assume step: "(s, s') ∈ sv_round r S v D" and invs: "s ∈ SV_inv4" "s ∈ Vinv1" "s ∈ Vinv2" and vote: "votes s' r' a = Some v'" (*‹(s::v_state, s'::v_state) ∈ sv_round (r::nat) (S::process set) (v::val) (D::process ⇒ val option)› ‹(s::v_state) ∈ SV_inv4› ‹(s::v_state) ∈ Vinv1› ‹(s::v_state) ∈ Vinv2› ‹votes (s'::v_state) (r'::nat) (a::process) = Some (v'::val)›*) thus "safe s' (Suc r') v'" proof (cases "r=r'") (*goals: 1. ‹⟦(s::v_state, s'::v_state) ∈ sv_round (r::nat) (S::process set) (v::val) (D::process ⇒ val option); s ∈ SV_inv4; s ∈ Vinv1; s ∈ Vinv2; votes s' (r'::nat) (a::process) = Some (v'::val); r = r'⟧ ⟹ safe s' (Suc r') v'› 2. ‹⟦(s::v_state, s'::v_state) ∈ sv_round (r::nat) (S::process set) (v::val) (D::process ⇒ val option); s ∈ SV_inv4; s ∈ Vinv1; s ∈ Vinv2; votes s' (r'::nat) (a::process) = Some (v'::val); r ≠ r'⟧ ⟹ safe s' (Suc r') v'›*) case True (*‹(r::nat) = (r'::nat)›*) moreover hence safe: "safe s' r' v'" using step (*‹(s, s') ∈ sv_round r S v D›*) vote (*‹votes s' r' a = Some v'›*) by (force simp add: sv_round_def (*‹sv_round ?r ?S ?v ?r_decisions = {(s, s'). ?r = next_round s ∧ (?S ≠ {} ⟶ safe s ?r ?v) ∧ d_guard ?r_decisions (const_map ?v ?S) ∧ s' = s⦇next_round := Suc ?r, votes := (votes s)(?r := const_map ?v ?S), decisions := decisions s ++ ?r_decisions⦈}›*) const_map_is_Some (*‹(const_map ?y ?A ?x = Some ?z) = (?z = ?y ∧ ?x ∈ ?A)›*) safe_def (*‹safe ?s ?r ?v = (∀r'<?r. ∀Q w. quorum_for Q w (votes ?s r') ⟶ ?v = w)›*) quorum_for_def (*‹quorum_for ?Q ?v ?v_f = (?Q ∈ Quorum ∧ (∀p∈?Q. ?v_f p = Some ?v))›*)) ultimately show "?thesis" (*goal: ‹safe s' (Suc r') v'›*) using step (*‹(s::v_state, s'::v_state) ∈ sv_round (r::nat) (S::process set) (v::val) (D::process ⇒ val option)›*) vote (*‹votes s' r' a = Some v'›*) by (force simp add: safe_def (*‹safe ?s ?r ?v = (∀r'<?r. ∀Q w. quorum_for Q w (votes ?s r') ⟶ ?v = w)›*) less_Suc_eq (*‹(?m < Suc ?n) = (?m < ?n ∨ ?m = ?n)›*) sv_round_def (*‹sv_round ?r ?S ?v ?r_decisions = {(s, s'). ?r = next_round s ∧ (?S ≠ {} ⟶ safe s ?r ?v) ∧ d_guard ?r_decisions (const_map ?v ?S) ∧ s' = s⦇next_round := Suc ?r, votes := (votes s)(?r := const_map ?v ?S), decisions := decisions s ++ ?r_decisions⦈}›*) quorum_for_def (*‹quorum_for ?Q ?v ?v_f = (?Q ∈ Quorum ∧ (∀p∈?Q. ?v_f p = Some ?v))›*) const_map_is_Some (*‹(const_map ?y ?A ?x = Some ?z) = (?z = ?y ∧ ?x ∈ ?A)›*) dest: quorum_non_empty (*‹?Q ∈ Quorum ⟹ ?Q ≠ {}›*)) qed (clarsimp simp add: sv_round_def (*‹sv_round ?r ?S ?v ?r_decisions = {(s, s'). ?r = next_round s ∧ (?S ≠ {} ⟶ safe s ?r ?v) ∧ d_guard ?r_decisions (const_map ?v ?S) ∧ s' = s⦇next_round := Suc ?r, votes := (votes s)(?r := const_map ?v ?S), decisions := decisions s ++ ?r_decisions⦈}›*) safe_def (*‹safe ?s ?r ?v = (∀r'<?r. ∀Q w. quorum_for Q w (votes ?s r') ⟶ ?v = w)›*) Vinv2_def (*‹Vinv2 = {s. ∀r. no_defection s (votes s r) r}›*) Vinv1_def (*‹Vinv1 = {s. ∀r≥next_round s. votes s r = (λx. None)}›*) SV_inv4_def (*‹SV_inv4 = {s. ∀v a r. votes s r a = Some v ⟶ safe s (Suc r) v}›*) intro: Quorum_not_empty (*‹∃Q. Q ∈ Quorum›*)) (*solved the remaining goal: ‹⟦(s::v_state, s'::v_state) ∈ sv_round (r::nat) (S::process set) (v::val) (D::process ⇒ val option); s ∈ SV_inv4; s ∈ Vinv1; s ∈ Vinv2; votes s' (r'::nat) (a::process) = Some (v'::val); r ≠ r'⟧ ⟹ safe s' (Suc r') v'›*) qed lemmas SV_inv4_event_pres = SV_inv4_sv_round lemma SV_inv4_inductive: "init sv_TS ⊆ SV_inv4" "{SV_inv4 ∩ (Vinv1 ∩ Vinv2)} trans sv_TS {> SV_inv4}" (*goals: 1. ‹init sv_TS ⊆ SV_inv4› 2. ‹{SV_inv4 ∩ (Vinv1 ∩ Vinv2)} TS.trans sv_TS {> SV_inv4}› discuss goal 1*) apply (simp add: sv_TS_defs (*‹sv_TS = ⦇init = v_init, trans = sv_trans⦈› ‹v_init = {⦇next_round = 0, votes = λr a. None, decisions = λx. None⦈}› ‹sv_trans = (⋃r S v. ⋃ (range (sv_round r S v)))⁼›*) SV_inv4_def (*‹SV_inv4 = {s. ∀v a r. votes s r a = Some v ⟶ safe s (Suc r) v}›*)) (*discuss goal 2*) apply (auto simp add: sv_TS_defs (*‹sv_TS = ⦇init = v_init, trans = sv_trans⦈› ‹v_init = {⦇next_round = 0::nat, votes = λ(r::nat) a::process. None, decisions = λx::process. None⦈}› ‹sv_trans = (⋃(r::nat) (S::process set) v::val. ⋃ (range (sv_round r S v)))⁼›*) SV_inv4_event_pres (*‹{SV_inv4 ∩ (Vinv1 ∩ Vinv2)} sv_round (?r::nat) (?S::process set) (?v::val) (?D::process ⇒ val option) {> SV_inv4}›*)) (*proven 2 subgoals*) . lemma SV_inv4_invariant: "reach sv_TS ⊆ SV_inv4" apply (rule inv_rule_incr (*‹⟦init ?T ⊆ ?I; {?I ∩ ?J} TS.trans ?T {> ?I}; reach ?T ⊆ ?J⟧ ⟹ reach ?T ⊆ ?I›*)) (*goal: ‹reach sv_TS ⊆ SV_inv4›*) by (auto intro: SV_inv4_inductive (*‹init sv_TS ⊆ SV_inv4› ‹{SV_inv4 ∩ (Vinv1 ∩ Vinv2)} TS.trans sv_TS {> SV_inv4}›*) SV_inv2_invariant (*‹reach sv_TS ⊆ Vinv2›*) SV_inv1_invariant (*‹reach sv_TS ⊆ Vinv1›*) del: subsetI (*‹(⋀x. x ∈ ?A ⟹ x ∈ ?B) ⟹ ?A ⊆ ?B›*)) end (* context quorum_process *) end
{ "path": "afp-2025-02-12/thys/Consensus_Refined/Same_Vote.thy", "repo": "afp-2025-02-12", "sha": "b0e1b5d73151b7a30c5d6078291c362258d98b4f692e4ef235499453e6efbdc5" }
(* Title: JinjaDCI/Compiler/Compiler1.thy Author: Tobias Nipkow, Susannah Mansky Copyright TUM 2003, UIUC 2019-20 Based on the Jinja theory Compiler/Compiler1.thy by Tobias Nipkow *) section ‹ Compilation Stage 1 › theory Compiler1 imports PCompiler J1 Hidden begin text‹ Replacing variable names by indices. › primrec compE₁ :: "vname list ⇒ expr ⇒ expr₁" and compEs₁ :: "vname list ⇒ expr list ⇒ expr₁ list" where "compE₁ Vs (new C) = new C" | "compE₁ Vs (Cast C e) = Cast C (compE₁ Vs e)" | "compE₁ Vs (Val v) = Val v" | "compE₁ Vs (e₁ «bop» e₂) = (compE₁ Vs e₁) «bop» (compE₁ Vs e₂)" | "compE₁ Vs (Var V) = Var(last_index Vs V)" | "compE₁ Vs (V:=e) = (last_index Vs V):= (compE₁ Vs e)" | "compE₁ Vs (e∙F{D}) = (compE₁ Vs e)∙F{D}" | "compE₁ Vs (C∙⇩sF{D}) = C∙⇩sF{D}" | "compE₁ Vs (e₁∙F{D}:=e₂) = (compE₁ Vs e₁)∙F{D} := (compE₁ Vs e₂)" | "compE₁ Vs (C∙⇩sF{D}:=e₂) = C∙⇩sF{D} := (compE₁ Vs e₂)" | "compE₁ Vs (e∙M(es)) = (compE₁ Vs e)∙M(compEs₁ Vs es)" | "compE₁ Vs (C∙⇩sM(es)) = C∙⇩sM(compEs₁ Vs es)" | "compE₁ Vs {V:T; e} = {(size Vs):T; compE₁ (Vs@[V]) e}" | "compE₁ Vs (e₁;;e₂) = (compE₁ Vs e₁);;(compE₁ Vs e₂)" | "compE₁ Vs (if (e) e₁ else e₂) = if (compE₁ Vs e) (compE₁ Vs e₁) else (compE₁ Vs e₂)" | "compE₁ Vs (while (e) c) = while (compE₁ Vs e) (compE₁ Vs c)" | "compE₁ Vs (throw e) = throw (compE₁ Vs e)" | "compE₁ Vs (try e₁ catch(C V) e₂) = try(compE₁ Vs e₁) catch(C (size Vs)) (compE₁ (Vs@[V]) e₂)" | "compE₁ Vs (INIT C (Cs,b) ← e) = INIT C (Cs,b) ← (compE₁ Vs e)" | "compE₁ Vs (RI(C,e);Cs ← e') = RI(C,(compE₁ Vs e));Cs ← (compE₁ Vs e')" | "compEs₁ Vs [] = []" | "compEs₁ Vs (e#es) = compE₁ Vs e # compEs₁ Vs es" lemma [simp]: "compEs₁ Vs es = map (compE₁ Vs) es" (*<*)apply (induct es type:list) (*goals: 1. ‹compEs₁ Vs [] = map (compE₁ Vs) []› 2. ‹⋀a list. compEs₁ Vs list = map (compE₁ Vs) list ⟹ compEs₁ Vs (a # list) = map (compE₁ Vs) (a # list)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) .(*>*) lemma [simp]: "⋀Vs. sub_RI (compE₁ Vs e) = sub_RI e" and [simp]: "⋀Vs. sub_RIs (compEs₁ Vs es) = sub_RIs es" proof (induct rule: sub_RI_sub_RIs_induct (*‹⟦⋀x. ?P1.0 (new x); ⋀x1 x2. ?P1.0 x2 ⟹ ?P1.0 (Cast x1 x2); ⋀x. ?P1.0 (Val x); ⋀x1 x2 x3. ⟦?P1.0 x1; ?P1.0 x3⟧ ⟹ ?P1.0 (x1 «x2» x3); ⋀x. ?P1.0 (Var x); ⋀x1 x2. ?P1.0 x2 ⟹ ?P1.0 (x1:=x2); ⋀x1 x2 x3. ?P1.0 x1 ⟹ ?P1.0 (x1∙x2{x3}); ⋀x1 x2 x3. ?P1.0 (x1∙⇩sx2{x3}); ⋀x1 x2 x3 x4. ⟦?P1.0 x1; ?P1.0 x4⟧ ⟹ ?P1.0 (x1∙x2{x3} := x4); ⋀x1 x2 x3 x4. ?P1.0 x4 ⟹ ?P1.0 (x1∙⇩sx2{x3} := x4); ⋀x1 x2 x3. ⟦?P1.0 x1; ?P2.0 x3⟧ ⟹ ?P1.0 (x1∙x2(x3)); ⋀x1 x2 x3. ?P2.0 x3 ⟹ ?P1.0 (x1∙⇩sx2(x3)); ⋀x1 x2 x3. ?P1.0 x3 ⟹ ?P1.0 {x1:x2; x3}; ⋀x1 x2. ⟦?P1.0 x1; ?P1.0 x2⟧ ⟹ ?P1.0 (x1;; x2); ⋀x1 x2 x3. ⟦?P1.0 x1; ?P1.0 x2; ?P1.0 x3⟧ ⟹ ?P1.0 (if (x1) x2 else x3); ⋀x1 x2. ⟦?P1.0 x1; ?P1.0 x2⟧ ⟹ ?P1.0 (while (x1) x2); ⋀x. ?P1.0 x ⟹ ?P1.0 (throw x); ⋀x1 x2 x3 x4. ⟦?P1.0 x1; ?P1.0 x4⟧ ⟹ ?P1.0 (try x1 catch(x2 x3) x4); ⋀x1 x2 x3 x4. ?P1.0 x4 ⟹ ?P1.0 (INIT x1 (x2,x3) ← x4); ⋀x1 x2 x3 x4. ⟦?P1.0 x2; ?P1.0 x4⟧ ⟹ ?P1.0 (RI (x1,x2) ; x3 ← x4); ?P2.0 []; ⋀x1 x2. ⟦?P1.0 x1; ?P2.0 x2⟧ ⟹ ?P2.0 (x1 # x2)⟧ ⟹ ?P1.0 ?exp› ‹⟦⋀x. ?P1.0 (new x); ⋀x1 x2. ?P1.0 x2 ⟹ ?P1.0 (Cast x1 x2); ⋀x. ?P1.0 (Val x); ⋀x1 x2 x3. ⟦?P1.0 x1; ?P1.0 x3⟧ ⟹ ?P1.0 (x1 «x2» x3); ⋀x. ?P1.0 (Var x); ⋀x1 x2. ?P1.0 x2 ⟹ ?P1.0 (x1:=x2); ⋀x1 x2 x3. ?P1.0 x1 ⟹ ?P1.0 (x1∙x2{x3}); ⋀x1 x2 x3. ?P1.0 (x1∙⇩sx2{x3}); ⋀x1 x2 x3 x4. ⟦?P1.0 x1; ?P1.0 x4⟧ ⟹ ?P1.0 (x1∙x2{x3} := x4); ⋀x1 x2 x3 x4. ?P1.0 x4 ⟹ ?P1.0 (x1∙⇩sx2{x3} := x4); ⋀x1 x2 x3. ⟦?P1.0 x1; ?P2.0 x3⟧ ⟹ ?P1.0 (x1∙x2(x3)); ⋀x1 x2 x3. ?P2.0 x3 ⟹ ?P1.0 (x1∙⇩sx2(x3)); ⋀x1 x2 x3. ?P1.0 x3 ⟹ ?P1.0 {x1:x2; x3}; ⋀x1 x2. ⟦?P1.0 x1; ?P1.0 x2⟧ ⟹ ?P1.0 (x1;; x2); ⋀x1 x2 x3. ⟦?P1.0 x1; ?P1.0 x2; ?P1.0 x3⟧ ⟹ ?P1.0 (if (x1) x2 else x3); ⋀x1 x2. ⟦?P1.0 x1; ?P1.0 x2⟧ ⟹ ?P1.0 (while (x1) x2); ⋀x. ?P1.0 x ⟹ ?P1.0 (throw x); ⋀x1 x2 x3 x4. ⟦?P1.0 x1; ?P1.0 x4⟧ ⟹ ?P1.0 (try x1 catch(x2 x3) x4); ⋀x1 x2 x3 x4. ?P1.0 x4 ⟹ ?P1.0 (INIT x1 (x2,x3) ← x4); ⋀x1 x2 x3 x4. ⟦?P1.0 x2; ?P1.0 x4⟧ ⟹ ?P1.0 (RI (x1,x2) ; x3 ← x4); ?P2.0 []; ⋀x1 x2. ⟦?P1.0 x1; ?P2.0 x2⟧ ⟹ ?P2.0 (x1 # x2)⟧ ⟹ ?P2.0 ?exp_list›*)) (*goals: 1. ‹⋀x Vs. sub_RI (compE₁ Vs (new x)) = sub_RI (new x)› 2. ‹⋀x1 x2 Vs. (⋀Vs. sub_RI (compE₁ Vs x2) = sub_RI x2) ⟹ sub_RI (compE₁ Vs (Cast x1 x2)) = sub_RI (Cast x1 x2)› 3. ‹⋀x Vs. sub_RI (compE₁ Vs (Val x)) = sub_RI (Val x)› 4. ‹⋀x1 x2 x3 Vs. ⟦⋀Vs. sub_RI (compE₁ Vs x1) = sub_RI x1; ⋀Vs. sub_RI (compE₁ Vs x3) = sub_RI x3⟧ ⟹ sub_RI (compE₁ Vs (x1 «x2» x3)) = sub_RI (x1 «x2» x3)› 5. ‹⋀x Vs. sub_RI (compE₁ Vs (Var x)) = sub_RI (Var x)› 6. ‹⋀x1 x2 Vs. (⋀Vs. sub_RI (compE₁ Vs x2) = sub_RI x2) ⟹ sub_RI (compE₁ Vs (x1:=x2)) = sub_RI (x1:=x2)› 7. ‹⋀x1 x2 x3 Vs. (⋀Vs. sub_RI (compE₁ Vs x1) = sub_RI x1) ⟹ sub_RI (compE₁ Vs (x1∙x2{x3})) = sub_RI (x1∙x2{x3})› 8. ‹⋀x1 x2 x3 Vs. sub_RI (compE₁ Vs (x1∙⇩sx2{x3})) = sub_RI (x1∙⇩sx2{x3})› 9. ‹⋀x1 x2 x3 x4 Vs. ⟦⋀Vs. sub_RI (compE₁ Vs x1) = sub_RI x1; ⋀Vs. sub_RI (compE₁ Vs x4) = sub_RI x4⟧ ⟹ sub_RI (compE₁ Vs (x1∙x2{x3} := x4)) = sub_RI (x1∙x2{x3} := x4)› 10. ‹⋀x1 x2 x3 x4 Vs. (⋀Vs. sub_RI (compE₁ Vs x4) = sub_RI x4) ⟹ sub_RI (compE₁ Vs (x1∙⇩sx2{x3} := x4)) = sub_RI (x1∙⇩sx2{x3} := x4)› 11. ‹⋀x1 x2 x3 Vs. ⟦⋀Vs. sub_RI (compE₁ Vs x1) = sub_RI x1; ⋀Vs. sub_RIs (compEs₁ Vs x3) = sub_RIs x3⟧ ⟹ sub_RI (compE₁ Vs (x1∙x2(x3))) = sub_RI (x1∙x2(x3))› 12. ‹⋀x1 x2 x3 Vs. (⋀Vs. sub_RIs (compEs₁ Vs x3) = sub_RIs x3) ⟹ sub_RI (compE₁ Vs (x1∙⇩sx2(x3))) = sub_RI (x1∙⇩sx2(x3))› 13. ‹⋀x1 x2 x3 Vs. (⋀Vs. sub_RI (compE₁ Vs x3) = sub_RI x3) ⟹ sub_RI (compE₁ Vs {x1:x2; x3}) = sub_RI {x1:x2; x3}› 14. ‹⋀x1 x2 Vs. ⟦⋀Vs. sub_RI (compE₁ Vs x1) = sub_RI x1; ⋀Vs. sub_RI (compE₁ Vs x2) = sub_RI x2⟧ ⟹ sub_RI (compE₁ Vs (x1;; x2)) = sub_RI (x1;; x2)› 15. ‹⋀x1 x2 x3 Vs. ⟦⋀Vs. sub_RI (compE₁ Vs x1) = sub_RI x1; ⋀Vs. sub_RI (compE₁ Vs x2) = sub_RI x2; ⋀Vs. sub_RI (compE₁ Vs x3) = sub_RI x3⟧ ⟹ sub_RI (compE₁ Vs (if (x1) x2 else x3)) = sub_RI (if (x1) x2 else x3)› 16. ‹⋀x1 x2 Vs. ⟦⋀Vs. sub_RI (compE₁ Vs x1) = sub_RI x1; ⋀Vs. sub_RI (compE₁ Vs x2) = sub_RI x2⟧ ⟹ sub_RI (compE₁ Vs (while (x1) x2)) = sub_RI (while (x1) x2)› 17. ‹⋀x Vs. (⋀Vs. sub_RI (compE₁ Vs x) = sub_RI x) ⟹ sub_RI (compE₁ Vs (throw x)) = sub_RI (throw x)› 18. ‹⋀x1 x2 x3 x4 Vs. ⟦⋀Vs. sub_RI (compE₁ Vs x1) = sub_RI x1; ⋀Vs. sub_RI (compE₁ Vs x4) = sub_RI x4⟧ ⟹ sub_RI (compE₁ Vs (try x1 catch(x2 x3) x4)) = sub_RI (try x1 catch(x2 x3) x4)› 19. ‹⋀x1 x2 x3 x4 Vs. (⋀Vs. sub_RI (compE₁ Vs x4) = sub_RI x4) ⟹ sub_RI (compE₁ Vs (INIT x1 (x2,x3) ← x4)) = sub_RI (INIT x1 (x2,x3) ← x4)› 20. ‹⋀x1 x2 x3 x4 Vs. ⟦⋀Vs. sub_RI (compE₁ Vs x2) = sub_RI x2; ⋀Vs. sub_RI (compE₁ Vs x4) = sub_RI x4⟧ ⟹ sub_RI (compE₁ Vs (RI (x1,x2) ; x3 ← x4)) = sub_RI (RI (x1,x2) ; x3 ← x4)› 21. ‹⋀Vs. sub_RIs (compEs₁ Vs []) = sub_RIs []› 22. ‹⋀x1 x2 Vs. ⟦⋀Vs. sub_RI (compE₁ Vs x1) = sub_RI x1; ⋀Vs. sub_RIs (compEs₁ Vs x2) = sub_RIs x2⟧ ⟹ sub_RIs (compEs₁ Vs (x1 # x2)) = sub_RIs (x1 # x2)›*) qed (auto) (*solves the remaining goals: 1. ‹⋀x Vs. sub_RI (compE₁ Vs (new x)) = sub_RI (new x)› 2. ‹⋀x1 x2 Vs. (⋀Vs. sub_RI (compE₁ Vs x2) = sub_RI x2) ⟹ sub_RI (compE₁ Vs (Cast x1 x2)) = sub_RI (Cast x1 x2)› 3. ‹⋀x Vs. sub_RI (compE₁ Vs (Val x)) = sub_RI (Val x)› 4. ‹⋀x1 x2 x3 Vs. ⟦⋀Vs. sub_RI (compE₁ Vs x1) = sub_RI x1; ⋀Vs. sub_RI (compE₁ Vs x3) = sub_RI x3⟧ ⟹ sub_RI (compE₁ Vs (x1 «x2» x3)) = sub_RI (x1 «x2» x3)› 5. ‹⋀x Vs. sub_RI (compE₁ Vs (Var x)) = sub_RI (Var x)› 6. ‹⋀x1 x2 Vs. (⋀Vs. sub_RI (compE₁ Vs x2) = sub_RI x2) ⟹ sub_RI (compE₁ Vs (x1:=x2)) = sub_RI (x1:=x2)› 7. ‹⋀x1 x2 x3 Vs. (⋀Vs. sub_RI (compE₁ Vs x1) = sub_RI x1) ⟹ sub_RI (compE₁ Vs (x1∙x2{x3})) = sub_RI (x1∙x2{x3})› 8. ‹⋀x1 x2 x3 Vs. sub_RI (compE₁ Vs (x1∙⇩sx2{x3})) = sub_RI (x1∙⇩sx2{x3})› 9. ‹⋀x1 x2 x3 x4 Vs. ⟦⋀Vs. sub_RI (compE₁ Vs x1) = sub_RI x1; ⋀Vs. sub_RI (compE₁ Vs x4) = sub_RI x4⟧ ⟹ sub_RI (compE₁ Vs (x1∙x2{x3} := x4)) = sub_RI (x1∙x2{x3} := x4)› 10. ‹⋀x1 x2 x3 x4 Vs. (⋀Vs. sub_RI (compE₁ Vs x4) = sub_RI x4) ⟹ sub_RI (compE₁ Vs (x1∙⇩sx2{x3} := x4)) = sub_RI (x1∙⇩sx2{x3} := x4)› 11. ‹⋀x1 x2 x3 Vs. ⟦⋀Vs. sub_RI (compE₁ Vs x1) = sub_RI x1; ⋀Vs. sub_RIs (compEs₁ Vs x3) = sub_RIs x3⟧ ⟹ sub_RI (compE₁ Vs (x1∙x2(x3))) = sub_RI (x1∙x2(x3))› 12. ‹⋀x1 x2 x3 Vs. (⋀Vs. sub_RIs (compEs₁ Vs x3) = sub_RIs x3) ⟹ sub_RI (compE₁ Vs (x1∙⇩sx2(x3))) = sub_RI (x1∙⇩sx2(x3))› 13. ‹⋀x1 x2 x3 Vs. (⋀Vs. sub_RI (compE₁ Vs x3) = sub_RI x3) ⟹ sub_RI (compE₁ Vs {x1:x2; x3}) = sub_RI {x1:x2; x3}› 14. ‹⋀x1 x2 Vs. ⟦⋀Vs. sub_RI (compE₁ Vs x1) = sub_RI x1; ⋀Vs. sub_RI (compE₁ Vs x2) = sub_RI x2⟧ ⟹ sub_RI (compE₁ Vs (x1;; x2)) = sub_RI (x1;; x2)› 15. ‹⋀x1 x2 x3 Vs. ⟦⋀Vs. sub_RI (compE₁ Vs x1) = sub_RI x1; ⋀Vs. sub_RI (compE₁ Vs x2) = sub_RI x2; ⋀Vs. sub_RI (compE₁ Vs x3) = sub_RI x3⟧ ⟹ sub_RI (compE₁ Vs (if (x1) x2 else x3)) = sub_RI (if (x1) x2 else x3)› 16. ‹⋀x1 x2 Vs. ⟦⋀Vs. sub_RI (compE₁ Vs x1) = sub_RI x1; ⋀Vs. sub_RI (compE₁ Vs x2) = sub_RI x2⟧ ⟹ sub_RI (compE₁ Vs (while (x1) x2)) = sub_RI (while (x1) x2)› 17. ‹⋀x Vs. (⋀Vs. sub_RI (compE₁ Vs x) = sub_RI x) ⟹ sub_RI (compE₁ Vs (throw x)) = sub_RI (throw x)› 18. ‹⋀x1 x2 x3 x4 Vs. ⟦⋀Vs. sub_RI (compE₁ Vs x1) = sub_RI x1; ⋀Vs. sub_RI (compE₁ Vs x4) = sub_RI x4⟧ ⟹ sub_RI (compE₁ Vs (try x1 catch(x2 x3) x4)) = sub_RI (try x1 catch(x2 x3) x4)› 19. ‹⋀x1 x2 x3 x4 Vs. (⋀Vs. sub_RI (compE₁ Vs x4) = sub_RI x4) ⟹ sub_RI (compE₁ Vs (INIT x1 (x2,x3) ← x4)) = sub_RI (INIT x1 (x2,x3) ← x4)› 20. ‹⋀x1 x2 x3 x4 Vs. ⟦⋀Vs. sub_RI (compE₁ Vs x2) = sub_RI x2; ⋀Vs. sub_RI (compE₁ Vs x4) = sub_RI x4⟧ ⟹ sub_RI (compE₁ Vs (RI (x1,x2) ; x3 ← x4)) = sub_RI (RI (x1,x2) ; x3 ← x4)› 21. ‹⋀Vs. sub_RIs (compEs₁ Vs []) = sub_RIs []› 22. ‹⋀x1 x2 Vs. ⟦⋀Vs. sub_RI (compE₁ Vs x1) = sub_RI x1; ⋀Vs. sub_RIs (compEs₁ Vs x2) = sub_RIs x2⟧ ⟹ sub_RIs (compEs₁ Vs (x1 # x2)) = sub_RIs (x1 # x2)›*) primrec fin₁:: "expr ⇒ expr₁" where "fin₁(Val v) = Val v" | "fin₁(throw e) = throw(fin₁ e)" lemma comp_final: "final e ⟹ compE₁ Vs e = fin₁ e" (*<*)apply (erule finalE (*‹⟦final ?e; ⋀v. ?e = Val v ⟹ ?R; ⋀a. ?e = Throw a ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹⋀v. e = Val v ⟹ compE₁ Vs e = fin₁ e› 2. ‹⋀a. e = Throw a ⟹ compE₁ Vs e = fin₁ e› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) .(*>*) lemma [simp]: "⋀Vs. max_vars (compE₁ Vs e) = max_vars e" and "⋀Vs. max_varss (compEs₁ Vs es) = max_varss es" (*<*)apply (induct e and es rule: max_vars.induct max_varss.induct) (*goals: 1. ‹⋀(x::char list) Vs::char list list. max_vars (compE₁ Vs (new x)) = max_vars (new x)› 2. ‹⋀(x1::char list) (x2::char list exp) Vs::char list list. (⋀Vs::char list list. max_vars (compE₁ Vs x2) = max_vars x2) ⟹ max_vars (compE₁ Vs (Cast x1 x2)) = max_vars (Cast x1 x2)› 3. ‹⋀(x::val) Vs::char list list. max_vars (compE₁ Vs (Val x)) = max_vars (Val x)› 4. ‹⋀(x1::char list exp) (x2::bop) (x3::char list exp) Vs::char list list. ⟦⋀Vs::char list list. max_vars (compE₁ Vs x1) = max_vars x1; ⋀Vs::char list list. max_vars (compE₁ Vs x3) = max_vars x3⟧ ⟹ max_vars (compE₁ Vs (x1 «x2» x3)) = max_vars (x1 «x2» x3)› 5. ‹⋀(x::char list) Vs::char list list. max_vars (compE₁ Vs (Var x)) = max_vars (Var x)› 6. ‹⋀(x1::char list) (x2::char list exp) Vs::char list list. (⋀Vs::char list list. max_vars (compE₁ Vs x2) = max_vars x2) ⟹ max_vars (compE₁ Vs (x1:=x2)) = max_vars (x1:=x2)› 7. ‹⋀(x1::char list exp) (x2::char list) (x3::char list) Vs::char list list. (⋀Vs::char list list. max_vars (compE₁ Vs x1) = max_vars x1) ⟹ max_vars (compE₁ Vs (x1∙x2{x3})) = max_vars (x1∙x2{x3})› 8. ‹⋀(x1::char list) (x2::char list) (x3::char list) Vs::char list list. max_vars (compE₁ Vs (x1∙⇩sx2{x3})) = max_vars (x1∙⇩sx2{x3})› 9. ‹⋀(x1::char list exp) (x2::char list) (x3::char list) (x4::char list exp) Vs::char list list. ⟦⋀Vs::char list list. max_vars (compE₁ Vs x1) = max_vars x1; ⋀Vs::char list list. max_vars (compE₁ Vs x4) = max_vars x4⟧ ⟹ max_vars (compE₁ Vs (x1∙x2{x3} := x4)) = max_vars (x1∙x2{x3} := x4)› 10. ‹⋀(x1::char list) (x2::char list) (x3::char list) (x4::char list exp) Vs::char list list. (⋀Vs::char list list. max_vars (compE₁ Vs x4) = max_vars x4) ⟹ max_vars (compE₁ Vs (x1∙⇩sx2{x3} := x4)) = max_vars (x1∙⇩sx2{x3} := x4)› 11. ‹⋀(x1::char list exp) (x2::char list) (x3::char list exp list) Vs::char list list. ⟦⋀Vs::char list list. max_vars (compE₁ Vs x1) = max_vars x1; ⋀Vs::char list list. max_varss (compEs₁ Vs x3) = max_varss x3⟧ ⟹ max_vars (compE₁ Vs (x1∙x2(x3))) = max_vars (x1∙x2(x3))› 12. ‹⋀(x1::char list) (x2::char list) (x3::char list exp list) Vs::char list list. (⋀Vs::char list list. max_varss (compEs₁ Vs x3) = max_varss x3) ⟹ max_vars (compE₁ Vs (x1∙⇩sx2(x3))) = max_vars (x1∙⇩sx2(x3))› 13. ‹⋀(x1::char list) (x2::ty) (x3::char list exp) Vs::char list list. (⋀Vs::char list list. max_vars (compE₁ Vs x3) = max_vars x3) ⟹ max_vars (compE₁ Vs {x1:x2; x3}) = max_vars {x1:x2; x3}› 14. ‹⋀(x1::char list exp) (x2::char list exp) Vs::char list list. ⟦⋀Vs::char list list. max_vars (compE₁ Vs x1) = max_vars x1; ⋀Vs::char list list. max_vars (compE₁ Vs x2) = max_vars x2⟧ ⟹ max_vars (compE₁ Vs (x1;; x2)) = max_vars (x1;; x2)› 15. ‹⋀(x1::char list exp) (x2::char list exp) (x3::char list exp) Vs::char list list. ⟦⋀Vs::char list list. max_vars (compE₁ Vs x1) = max_vars x1; ⋀Vs::char list list. max_vars (compE₁ Vs x2) = max_vars x2; ⋀Vs::char list list. max_vars (compE₁ Vs x3) = max_vars x3⟧ ⟹ max_vars (compE₁ Vs (if (x1) x2 else x3)) = max_vars (if (x1) x2 else x3)› 16. ‹⋀(x1::char list exp) (x2::char list exp) Vs::char list list. ⟦⋀Vs::char list list. max_vars (compE₁ Vs x1) = max_vars x1; ⋀Vs::char list list. max_vars (compE₁ Vs x2) = max_vars x2⟧ ⟹ max_vars (compE₁ Vs (while (x1) x2)) = max_vars (while (x1) x2)› 17. ‹⋀(x::char list exp) Vs::char list list. (⋀Vs::char list list. max_vars (compE₁ Vs x) = max_vars x) ⟹ max_vars (compE₁ Vs (throw x)) = max_vars (throw x)› 18. ‹⋀(x1::char list exp) (x2::char list) (x3::char list) (x4::char list exp) Vs::char list list. ⟦⋀Vs::char list list. max_vars (compE₁ Vs x1) = max_vars x1; ⋀Vs::char list list. max_vars (compE₁ Vs x4) = max_vars x4⟧ ⟹ max_vars (compE₁ Vs (try x1 catch(x2 x3) x4)) = max_vars (try x1 catch(x2 x3) x4)› 19. ‹⋀(x1::char list) (x2::char list list) (x3::bool) (x4::char list exp) Vs::char list list. (⋀Vs::char list list. max_vars (compE₁ Vs x4) = max_vars x4) ⟹ max_vars (compE₁ Vs (INIT x1 (x2,x3) ← x4)) = max_vars (INIT x1 (x2,x3) ← x4)› 20. ‹⋀(x1::char list) (x2::char list exp) (x3::char list list) (x4::char list exp) Vs::char list list. ⟦⋀Vs::char list list. max_vars (compE₁ Vs x2) = max_vars x2; ⋀Vs::char list list. max_vars (compE₁ Vs x4) = max_vars x4⟧ ⟹ max_vars (compE₁ Vs (RI (x1,x2) ; x3 ← x4)) = max_vars (RI (x1,x2) ; x3 ← x4)› 21. ‹⋀Vs::char list list. max_varss (compEs₁ Vs []) = max_varss []› 22. ‹⋀(x1::char list exp) (x2::char list exp list) Vs::char list list. ⟦⋀Vs::char list list. max_vars (compE₁ Vs x1) = max_vars x1; ⋀Vs::char list list. max_varss (compEs₁ Vs x2) = max_varss x2⟧ ⟹ max_varss (compEs₁ Vs (x1 # x2)) = max_varss (x1 # x2)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*discuss goal 4*) apply simp (*discuss goal 5*) apply simp (*discuss goal 6*) apply simp (*discuss goal 7*) apply simp (*discuss goal 8*) apply simp (*discuss goal 9*) apply simp (*discuss goal 10*) apply simp (*discuss goal 11*) apply simp (*discuss goal 12*) apply simp (*discuss goal 13*) apply simp (*discuss goal 14*) apply simp (*discuss goal 15*) apply simp (*discuss goal 16*) apply simp (*discuss goal 17*) apply simp (*discuss goal 18*) apply simp (*discuss goal 19*) apply simp (*discuss goal 20*) apply simp (*discuss goal 21*) apply simp (*discuss goal 22*) apply simp (*proven 22 subgoals*) .(*>*) text‹ Compiling programs: › definition compP₁ :: "J_prog ⇒ J₁_prog" where "compP₁ ≡ compP (λb (pns,body). compE₁ (case b of NonStatic ⇒ this#pns | Static ⇒ pns) body)" (*<*) declare compP₁_def[simp] (*>*) end
{ "path": "afp-2025-02-12/thys/JinjaDCI/Compiler/Compiler1.thy", "repo": "afp-2025-02-12", "sha": "803c5dd2b4660baf44fadaecf9da862e310d0456c6c38ddd2181245d4389bc63" }
(* Title: JinjaThreads/Common/WellForm.thy Author: Tobias Nipkow, Andreas Lochbihler Based on the Jinja theory Common/WellForm.thy by Tobias Nipkow *) section ‹Generic Well-formedness of programs› theory WellForm imports SystemClasses ExternalCall begin text ‹\noindent This theory defines global well-formedness conditions for programs but does not look inside method bodies. Hence it works for both Jinja and JVM programs. Well-typing of expressions is defined elsewhere (in theory ‹WellType›). Because JinjaThreads does not have method overloading, its policy for method overriding is the classical one: \emph{covariant in the result type but contravariant in the argument types.} This means the result type of the overriding method becomes more specific, the argument types become more general. › type_synonym 'm wf_mdecl_test = "'m prog ⇒ cname ⇒ 'm mdecl ⇒ bool" definition wf_fdecl :: "'m prog ⇒ fdecl ⇒ bool" where "wf_fdecl P ≡ λ(F,T,fm). is_type P T" definition wf_mdecl :: "'m wf_mdecl_test ⇒ 'm prog ⇒ cname ⇒ 'm mdecl' ⇒ bool" where "wf_mdecl wf_md P C ≡ λ(M,Ts,T,m). (∀T∈set Ts. is_type P T) ∧ is_type P T ∧ (case m of Native ⇒ C∙M(Ts) :: T | ⌊mb⌋ ⇒ wf_md P C (M,Ts,T,mb))" fun wf_overriding :: "'m prog ⇒ cname ⇒ 'm mdecl' ⇒ bool" where "wf_overriding P D (M,Ts,T,m) = (∀D' Ts' T' m'. P ⊢ D sees M:Ts' → T' = m' in D' ⟶ P ⊢ Ts' [≤] Ts ∧ P ⊢ T ≤ T')" definition wf_cdecl :: "'m wf_mdecl_test ⇒ 'm prog ⇒ 'm cdecl ⇒ bool" where "wf_cdecl wf_md P ≡ λ(C,(D,fs,ms)). (∀f∈set fs. wf_fdecl P f) ∧ distinct_fst fs ∧ (∀m∈set ms. wf_mdecl wf_md P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class P D ∧ ¬ P ⊢ D ≼⇧* C ∧ (∀m∈set ms. wf_overriding P D m)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms))" definition wf_prog :: "'m wf_mdecl_test ⇒ 'm prog ⇒ bool" where "wf_prog wf_md P ⟷ wf_syscls P ∧ distinct_fst (classes P) ∧ (∀c ∈ set (classes P). wf_cdecl wf_md P c)" lemma wf_prog_def2: "wf_prog wf_md P ⟷ wf_syscls P ∧ (∀C rest. class P C = ⌊rest⌋ ⟶ wf_cdecl wf_md P (C, rest)) ∧ distinct_fst (classes P)" apply (cases P) (*goal: ‹wf_prog wf_md P = (wf_syscls P ∧ (∀C rest. class P C = ⌊rest⌋ ⟶ wf_cdecl wf_md P (C, rest)) ∧ distinct_fst (classes P))›*) by (auto simp add: wf_prog_def (*‹wf_prog ?wf_md ?P = (wf_syscls ?P ∧ distinct_fst (classes ?P) ∧ (∀c∈set (classes ?P). wf_cdecl ?wf_md ?P c))›*) dest: map_of_SomeD (*‹map_of ?xs ?k = ⌊?y⌋ ⟹ (?k, ?y) ∈ set ?xs›*) map_of_SomeI (*‹⟦distinct_fst ?kxs; (?k, ?x) ∈ set ?kxs⟧ ⟹ map_of ?kxs ?k = ⌊?x⌋›*)) subsection‹Well-formedness lemmas› lemma wf_prog_wf_syscls: "wf_prog wf_md P ⟹ wf_syscls P" by (simp add: wf_prog_def (*‹wf_prog ?wf_md ?P = (wf_syscls ?P ∧ distinct_fst (classes ?P) ∧ (∀c∈set (classes ?P). wf_cdecl ?wf_md ?P c))›*)) lemma class_wf: "⟦class P C = Some c; wf_prog wf_md P⟧ ⟹ wf_cdecl wf_md P (C,c)" apply (cases P) (*goal: ‹⟦class (P::'a prog) (C::String.literal) = ⌊c::'a option class⌋; wf_prog (wf_md::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) P⟧ ⟹ wf_cdecl wf_md P (C, c)›*) by (fastforce dest: map_of_SomeD (*‹map_of ?xs ?k = ⌊?y⌋ ⟹ (?k, ?y) ∈ set ?xs›*) simp add: wf_prog_def (*‹wf_prog ?wf_md ?P = (wf_syscls ?P ∧ distinct_fst (classes ?P) ∧ (∀c∈set (classes ?P). wf_cdecl ?wf_md ?P c))›*)) lemma [simp]: assumes "wf_prog wf_md P" shows class_Object: "∃C fs ms. class P Object = Some (C,fs,ms)" and class_Thread: "∃C fs ms. class P Thread = Some (C,fs,ms)" using wf_prog_wf_syscls[OF assms] (*‹wf_syscls (P::'a::type prog)›*) apply - (*goals: 1. ‹wf_syscls P ⟹ ∃C fs ms. class P Object = ⌊(C, fs, ms)⌋› 2. ‹wf_syscls P ⟹ ∃C fs ms. class P Thread = ⌊(C, fs, ms)⌋› discuss goal 1*) apply (rule wf_syscls_class_Object (*‹wf_syscls ?P ⟹ ∃C fs ms. class ?P Object = ⌊(C, fs, ms)⌋›*) wf_syscls_class_Thread (*‹wf_syscls ?P ⟹ ∃C fs ms. class ?P Thread = ⌊(C, fs, ms)⌋›*)) (*top goal: ‹wf_syscls P ⟹ ∃C fs ms. class P Object = ⌊(C, fs, ms)⌋› and 1 goal remains*) apply ((msorry)[1]) (*discuss goal 2*) apply ((msorry)[1]) (*proven 2 subgoals*) . lemma [simp]: assumes "wf_prog wf_md P" shows is_class_Object: "is_class P Object" and is_class_Thread: "is_class P Thread" using wf_prog_wf_syscls[OF assms] (*‹wf_syscls (P::'a::type prog)›*) apply - (*goals: 1. ‹wf_syscls P ⟹ is_class P Object› 2. ‹wf_syscls P ⟹ is_class P Thread› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma xcpt_subcls_Throwable: "⟦ C ∈ sys_xcpts; wf_prog wf_md P ⟧ ⟹ P ⊢ C ≼⇧* Throwable" by (simp add: wf_prog_wf_syscls (*‹wf_prog ?wf_md ?P ⟹ wf_syscls ?P›*) wf_syscls_xcpt_subcls_Throwable (*‹⟦?C ∈ sys_xcpts; wf_syscls ?P⟧ ⟹ ?P ⊢ ?C ≼⇧* Throwable›*)) lemma is_class_Throwable: "wf_prog wf_md P ⟹ is_class P Throwable" apply (rule wf_prog_wf_syscls (*‹wf_prog ?wf_md ?P ⟹ wf_syscls ?P›*) wf_syscls_is_class_Throwable (*‹wf_syscls ?P ⟹ is_class ?P Throwable›*)) (*goal: ‹wf_prog wf_md P ⟹ is_class P Throwable›*) by (rule wf_prog_wf_syscls (*‹wf_prog ?wf_md ?P ⟹ wf_syscls ?P›*) wf_syscls_is_class_Throwable (*‹wf_syscls ?P ⟹ is_class ?P Throwable›*)) lemma is_class_sub_Throwable: "⟦ wf_prog wf_md P; P ⊢ C ≼⇧* Throwable ⟧ ⟹ is_class P C" apply (rule wf_syscls_is_class_sub_Throwable[OF wf_prog_wf_syscls] (*‹⟦wf_prog ?wf_md1 ?P; ?P ⊢ ?C ≼⇧* Throwable⟧ ⟹ is_class ?P ?C›*)) (*goals: 1. ‹⟦wf_prog (wf_md::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) (P::'a prog); P ⊢ (C::String.literal) ≼⇧* Throwable⟧ ⟹ wf_prog (?wf_md1::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) P› 2. ‹⟦wf_prog (wf_md::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) (P::'a prog); P ⊢ (C::String.literal) ≼⇧* Throwable⟧ ⟹ P ⊢ C ≼⇧* Throwable› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) lemma is_class_xcpt: "⟦ C ∈ sys_xcpts; wf_prog wf_md P ⟧ ⟹ is_class P C" apply (rule wf_syscls_is_class_xcpt[OF _ wf_prog_wf_syscls] (*‹⟦?C ∈ sys_xcpts; wf_prog ?wf_md1 ?P⟧ ⟹ is_class ?P ?C›*)) (*goals: 1. ‹⟦C ∈ sys_xcpts; wf_prog wf_md P⟧ ⟹ C ∈ sys_xcpts› 2. ‹⟦C ∈ sys_xcpts; wf_prog wf_md P⟧ ⟹ wf_prog ?wf_md1 P› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) context heap_base begin lemma wf_preallocatedE: assumes "wf_prog wf_md P" and "preallocated h" and "C ∈ sys_xcpts" obtains "typeof_addr h (addr_of_sys_xcpt C) = ⌊Class_type C⌋" "P ⊢ C ≼⇧* Throwable" proof (-) (*goal: ‹(⟦typeof_addr h (addr_of_sys_xcpt C) = ⌊Class_type C⌋; P ⊢ C ≼⇧* Throwable⟧ ⟹ thesis) ⟹ thesis›*) from ‹preallocated h› (*‹preallocated h›*) ‹C ∈ sys_xcpts› (*‹C ∈ sys_xcpts›*) have "typeof_addr h (addr_of_sys_xcpt C) = ⌊Class_type C⌋" by (rule typeof_addr_sys_xcp (*‹⟦preallocated ?h; ?C ∈ sys_xcpts⟧ ⟹ typeof_addr ?h (addr_of_sys_xcpt ?C) = ⌊Class_type ?C⌋›*)) moreover from ‹C ∈ sys_xcpts› (*‹(C::String.literal) ∈ sys_xcpts›*) ‹wf_prog wf_md P› (*‹wf_prog wf_md P›*) have "P ⊢ C ≼⇧* Throwable" by (rule xcpt_subcls_Throwable (*‹⟦(?C::String.literal) ∈ sys_xcpts; wf_prog (?wf_md::?'a prog ⇒ String.literal ⇒ ?'a mdecl ⇒ bool) (?P::?'a prog)⟧ ⟹ ?P ⊢ ?C ≼⇧* Throwable›*)) ultimately show thesis by (rule that (*‹⟦typeof_addr h (addr_of_sys_xcpt C) = ⌊Class_type C⌋; P ⊢ C ≼⇧* Throwable⟧ ⟹ thesis›*)) qed lemma wf_preallocatedD: assumes "wf_prog wf_md P" and "preallocated h" and "C ∈ sys_xcpts" shows "typeof_addr h (addr_of_sys_xcpt C) = ⌊Class_type C⌋ ∧ P ⊢ C ≼⇧* Throwable" using assms (*‹wf_prog wf_md P› ‹preallocated h› ‹C ∈ sys_xcpts›*) apply (rule wf_preallocatedE (*‹⟦wf_prog ?wf_md ?P; preallocated ?h; ?C ∈ sys_xcpts; ⟦typeof_addr ?h (addr_of_sys_xcpt ?C) = ⌊Class_type ?C⌋; ?P ⊢ ?C ≼⇧* Throwable⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) (*goal: ‹typeof_addr h (addr_of_sys_xcpt C) = ⌊Class_type C⌋ ∧ P ⊢ C ≼⇧* Throwable›*) by blast end lemma (in heap_conf) hconf_start_heap: "wf_prog wf_md P ⟹ hconf start_heap" unfolding start_heap_def start_heap_data_def initialization_list_def sys_xcpts_list_def (*goal: ‹wf_prog wf_md P ⟹ hconf (fst (foldl create_initial_object (empty_heap, [], True) [Thread, NullPointer, ClassCast, OutOfMemory, ArrayIndexOutOfBounds, ArrayStore, NegativeArraySize, ArithmeticException, IllegalMonitorState, IllegalThreadState, InterruptedException]))›*) using hconf_empty (*‹hconf empty_heap›*) apply - (*goal: ‹wf_prog wf_md P ⟹ hconf (fst (foldl create_initial_object (empty_heap, [], True) [Thread, NullPointer, ClassCast, OutOfMemory, ArrayIndexOutOfBounds, ArrayStore, NegativeArraySize, ArithmeticException, IllegalMonitorState, IllegalThreadState, InterruptedException]))›*) by ((simp add: create_initial_object_simps (*‹create_initial_object (?h, ?ads, ?b) ?C = (if ?b then let HA = allocate ?h (Class_type ?C) in if HA = {} then (?h, ?ads, False) else let (h', a'') = SOME ha. ha ∈ HA in (h', ?ads @ [a''], True) else (?h, ?ads, False))›*) del: hconf_empty (*‹hconf empty_heap›*), clarsimp split: prod.split (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))›*) elim!: not_empty_pairE (*‹⟦?A ≠ {}; ⋀a b. (a, b) ∈ ?A ⟹ ?thesis⟧ ⟹ ?thesis›*) simp del: hconf_empty (*‹hconf empty_heap›*), drule (1) allocate_Eps (*‹⟦(?h'', ?a'') ∈ allocate ?h ?hT; (SOME ha. ha ∈ allocate ?h ?hT) = (?h', ?a')⟧ ⟹ (?h', ?a') ∈ allocate ?h ?hT›*), drule (1) hconf_allocate_mono (*‹⟦(?h'::'heap, ?a::'addr) ∈ (allocate::'heap ⇒ htype ⇒ ('heap × 'addr) set) (?h::'heap) (?hT::htype); (hconf::'heap ⇒ bool) ?h; is_htype (P::'m prog) ?hT⟧ ⟹ hconf ?h'›*), simp add: is_class_xcpt (*‹⟦?C ∈ sys_xcpts; wf_prog ?wf_md ?P⟧ ⟹ is_class ?P ?C›*))+) lemma subcls1_wfD: "⟦ P ⊢ C ≺¹ D; wf_prog wf_md P ⟧ ⟹ D ≠ C ∧ ¬ (subcls1 P)⁺⁺ D C" apply (frule tranclp.r_into_trancl[where r="subcls1 P"] (*‹P ⊢ ?a ≺¹ ?b ⟹ (subcls1 P)⁺⁺ ?a ?b›*)) (*goal: ‹⟦P ⊢ C ≺¹ D; wf_prog wf_md P⟧ ⟹ D ≠ C ∧ ¬ (subcls1 P)⁺⁺ D C›*) apply (drule subcls1D (*‹(?P::?'a::type prog) ⊢ (?C::String.literal) ≺¹ (?D::String.literal) ⟹ ?C ≠ Object ∧ (∃(fs::fdecl list) ms::?'a::type option mdecl list. class ?P ?C = ⌊(?D, fs, ms)⌋)›*)) (*goal: ‹⟦P ⊢ C ≺¹ D; wf_prog wf_md P; (subcls1 P)⁺⁺ C D⟧ ⟹ D ≠ C ∧ ¬ (subcls1 P)⁺⁺ D C›*) apply clarify (*goal: ‹⟦wf_prog wf_md P; (subcls1 P)⁺⁺ C D; C ≠ Object ∧ (∃fs ms. class P C = ⌊(D, fs, ms)⌋)⟧ ⟹ D ≠ C ∧ ¬ (subcls1 P)⁺⁺ D C›*) apply (drule (1) class_wf (*‹⟦class (?P::?'a::type prog) (?C::String.literal) = ⌊?c::?'a::type option class⌋; wf_prog (?wf_md::?'a::type prog ⇒ String.literal ⇒ ?'a::type mdecl ⇒ bool) ?P⟧ ⟹ wf_cdecl ?wf_md ?P (?C, ?c)›*)) (*goal: ‹⋀fs ms. ⟦wf_prog wf_md P; (subcls1 P)⁺⁺ C D; C ≠ Object; class P C = ⌊(D, fs, ms)⌋⟧ ⟹ D ≠ C ∧ ¬ (subcls1 P)⁺⁺ D C›*) apply (unfold wf_cdecl_def (*‹wf_cdecl ?wf_md ?P ≡ λ(C, D, fs, ms). (∀f∈set fs. wf_fdecl ?P f) ∧ distinct_fst fs ∧ (∀m∈set ms. wf_mdecl ?wf_md ?P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class ?P D ∧ ¬ ?P ⊢ D ≼⇧* C ∧ (∀m∈set ms. wf_overriding ?P D m)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms))›*)) (*goal: ‹⋀fs ms. ⟦wf_prog wf_md P; (subcls1 P)⁺⁺ C D; C ≠ Object; wf_cdecl wf_md P (C, D, fs, ms)⟧ ⟹ D ≠ C ∧ ¬ (subcls1 P)⁺⁺ D C›*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹⋀(fs::fdecl list) ms::'a option mdecl list. ⟦wf_prog (wf_md::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) (P::'a prog); (subcls1 P)⁺⁺ (C::String.literal) (D::String.literal); C ≠ Object; case (C, D, fs, ms) of (C::String.literal, D::String.literal, fs::fdecl list, ms::'a option mdecl list) ⇒ (∀f::fdecl∈set fs. wf_fdecl P f) ∧ distinct_fst fs ∧ (∀m::'a option mdecl∈set ms. wf_mdecl wf_md P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class P D ∧ ¬ P ⊢ D ≼⇧* C ∧ (∀m::'a option mdecl∈set ms. wf_overriding P D m)) ∧ (C = Thread ⟶ (∃m::'a option. (run, [], Void, m) ∈ set ms))⟧ ⟹ D ≠ C› 2. ‹⋀(fs::fdecl list) ms::'a option mdecl list. ⟦wf_prog (wf_md::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) (P::'a prog); (subcls1 P)⁺⁺ (C::String.literal) (D::String.literal); C ≠ Object; case (C, D, fs, ms) of (C::String.literal, D::String.literal, fs::fdecl list, ms::'a option mdecl list) ⇒ (∀f::fdecl∈set fs. wf_fdecl P f) ∧ distinct_fst fs ∧ (∀m::'a option mdecl∈set ms. wf_mdecl wf_md P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class P D ∧ ¬ P ⊢ D ≼⇧* C ∧ (∀m::'a option mdecl∈set ms. wf_overriding P D m)) ∧ (C = Thread ⟶ (∃m::'a option. (run, [], Void, m) ∈ set ms))⟧ ⟹ ¬ (subcls1 P)⁺⁺ D C› discuss goal 1*) apply force (*discuss goal 2*) apply (unfold reflclp_tranclp[symmetric, where r="subcls1 P"] (*‹subcls P = (subcls1 P)⁺⁺⁼⁼›*)) (*goal: ‹⋀fs ms. ⟦wf_prog wf_md P; (subcls1 P)⁺⁺ C D; C ≠ Object; case (C, D, fs, ms) of (C, D, fs, ms) ⇒ (∀f∈set fs. wf_fdecl P f) ∧ distinct_fst fs ∧ (∀m∈set ms. wf_mdecl wf_md P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class P D ∧ ¬ P ⊢ D ≼⇧* C ∧ (∀m∈set ms. wf_overriding P D m)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms))⟧ ⟹ ¬ (subcls1 P)⁺⁺ D C›*) apply blast (*proven 2 subgoals*) . lemma wf_cdecl_supD: "⟦wf_cdecl wf_md P (C,D,r); C ≠ Object⟧ ⟹ is_class P D" (*<*)by (auto simp: wf_cdecl_def (*‹wf_cdecl ?wf_md ?P ≡ λ(C, D, fs, ms). (∀f∈set fs. wf_fdecl ?P f) ∧ distinct_fst fs ∧ (∀m∈set ms. wf_mdecl ?wf_md ?P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class ?P D ∧ ¬ ?P ⊢ D ≼⇧* C ∧ (∀m∈set ms. wf_overriding ?P D m)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms))›*))(*>*) lemma subcls_asym: "⟦ wf_prog wf_md P; (subcls1 P)⁺⁺ C D ⟧ ⟹ ¬ (subcls1 P)⁺⁺ D C" (*<*) apply (erule tranclp.cases (*‹⟦?r⁺⁺ ?a1.0 ?a2.0; ⋀a b. ⟦?a1.0 = a; ?a2.0 = b; ?r a b⟧ ⟹ ?P; ⋀a b c. ⟦?a1.0 = a; ?a2.0 = c; ?r⁺⁺ a b; ?r b c⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹⋀a b. ⟦wf_prog wf_md P; C = a; D = b; P ⊢ a ≺¹ b⟧ ⟹ ¬ (subcls1 P)⁺⁺ D C› 2. ‹⋀a b c. ⟦wf_prog wf_md P; C = a; D = c; (subcls1 P)⁺⁺ a b; P ⊢ b ≺¹ c⟧ ⟹ ¬ (subcls1 P)⁺⁺ D C› discuss goal 1*) apply (fast dest!: subcls1_wfD (*‹⟦(?P::?'a prog) ⊢ (?C::String.literal) ≺¹ (?D::String.literal); wf_prog (?wf_md::?'a prog ⇒ String.literal ⇒ ?'a mdecl ⇒ bool) ?P⟧ ⟹ ?D ≠ ?C ∧ ¬ (subcls1 ?P)⁺⁺ ?D ?C›*)) (*discuss goal 2*) apply (fast dest!: subcls1_wfD (*‹⟦?P ⊢ ?C ≺¹ ?D; wf_prog ?wf_md ?P⟧ ⟹ ?D ≠ ?C ∧ ¬ (subcls1 ?P)⁺⁺ ?D ?C›*) intro: tranclp_trans (*‹⟦?r⁺⁺ ?x ?y; ?r⁺⁺ ?y ?z⟧ ⟹ ?r⁺⁺ ?x ?z›*)) (*proven 2 subgoals*) . (*>*) lemma subcls_irrefl: "⟦ wf_prog wf_md P; (subcls1 P)⁺⁺ C D⟧ ⟹ C ≠ D" (*<*) apply (erule tranclp_trans_induct (*‹⟦?r⁺⁺ ?x ?y; ⋀x y. ?r x y ⟹ ?P x y; ⋀x y z. ⟦?r⁺⁺ x y; ?P x y; ?r⁺⁺ y z; ?P y z⟧ ⟹ ?P x z⟧ ⟹ ?P ?x ?y›*)) (*goals: 1. ‹⋀x y. ⟦wf_prog wf_md P; P ⊢ x ≺¹ y⟧ ⟹ x ≠ y› 2. ‹⋀x y z. ⟦wf_prog wf_md P; (subcls1 P)⁺⁺ x y; x ≠ y; (subcls1 P)⁺⁺ y z; y ≠ z⟧ ⟹ x ≠ z› discuss goal 1*) apply ((auto dest: subcls1_wfD (*‹⟦?P ⊢ ?C ≺¹ ?D; wf_prog ?wf_md ?P⟧ ⟹ ?D ≠ ?C ∧ ¬ (subcls1 ?P)⁺⁺ ?D ?C›*) subcls_asym (*‹⟦wf_prog ?wf_md ?P; (subcls1 ?P)⁺⁺ ?C ?D⟧ ⟹ ¬ (subcls1 ?P)⁺⁺ ?D ?C›*))[1]) (*discuss goal 2*) apply ((auto dest: subcls1_wfD (*‹⟦?P ⊢ ?C ≺¹ ?D; wf_prog ?wf_md ?P⟧ ⟹ ?D ≠ ?C ∧ ¬ (subcls1 ?P)⁺⁺ ?D ?C›*) subcls_asym (*‹⟦wf_prog ?wf_md ?P; (subcls1 ?P)⁺⁺ ?C ?D⟧ ⟹ ¬ (subcls1 ?P)⁺⁺ ?D ?C›*))[1]) (*proven 2 subgoals*) . (*>*) lemma acyclicP_def: "acyclicP r ⟷ (∀x. ¬ r^++ x x)" unfolding acyclic_def trancl_def (*goal: ‹(∀x. (x, x) ∉ {(x, y). (λx xa. (x, xa) ∈ {(x, y). r x y})⁺⁺ x y}) = (∀x. ¬ r⁺⁺ x x)›*) by auto lemma acyclic_subcls1: "wf_prog wf_md P ⟹ acyclicP (subcls1 P)" apply (unfold acyclicP_def (*‹acyclicP ?r = (∀x. ¬ ?r⁺⁺ x x)›*)) (*goal: ‹wf_prog wf_md P ⟹ acyclicP (subcls1 P)›*) by (fast dest: subcls_irrefl (*‹⟦wf_prog (?wf_md::?'a prog ⇒ String.literal ⇒ ?'a mdecl ⇒ bool) (?P::?'a prog); (subcls1 ?P)⁺⁺ (?C::String.literal) (?D::String.literal)⟧ ⟹ ?C ≠ ?D›*)) lemma finite_conversep: "finite {(x, y). r¯¯ x y} = finite {(x, y). r x y}" apply (subst finite_converse[unfolded converse_unfold, symmetric] (*‹finite ?r = finite {(y, x). (x, y) ∈ ?r}›*)) (*goal: ‹finite {(x, y). r¯¯ x y} = finite {(x, y). r x y}›*) by simp lemma acyclicP_wf_subcls1: "acyclicP (subcls1 P) ⟹ wfP ((subcls1 P)¯¯)" unfolding wfP_def (*goal: ‹acyclicP (subcls1 P) ⟹ wf {(x, y). (subcls1 P)¯¯ x y}›*) apply (rule finite_acyclic_wf (*‹⟦finite ?r; acyclic ?r⟧ ⟹ wf ?r›*)) (*goals: 1. ‹acyclicP (subcls1 P) ⟹ finite {(x, y). (subcls1 P)¯¯ x y}› 2. ‹acyclicP (subcls1 P) ⟹ acyclicP (subcls1 P)¯¯› discuss goal 1*) apply (simp only: finite_conversep (*‹finite {(x, y). ?r¯¯ x y} = finite {(x, y). ?r x y}›*) finite_subcls1 (*‹finite {(C, D). ?P ⊢ C ≺¹ D}›*) acyclicP_converse (*‹acyclicP ?r¯¯ = acyclicP ?r›*)) (*discuss goal 2*) apply (simp only: finite_conversep (*‹finite {(x, y). ?r¯¯ x y} = finite {(x, y). ?r x y}›*) finite_subcls1 (*‹finite {(C, D). ?P ⊢ C ≺¹ D}›*) acyclicP_converse (*‹acyclicP ?r¯¯ = acyclicP ?r›*)) (*proven 2 subgoals*) . lemma wf_subcls1: "wf_prog wf_md P ⟹ wfP ((subcls1 P)¯¯)" apply (rule acyclicP_wf_subcls1 (*‹acyclicP (subcls1 ?P) ⟹ wfp (subcls1 ?P)¯¯›*)) (*goal: ‹wf_prog wf_md P ⟹ wfp (subcls1 P)¯¯›*) by (rule acyclic_subcls1 (*‹wf_prog ?wf_md ?P ⟹ acyclicP (subcls1 ?P)›*)) lemma single_valued_subcls1: "wf_prog wf_md G ⟹ single_valuedp (subcls1 G)" (*<*) by (auto simp:wf_prog_def (*‹wf_prog ?wf_md ?P = (wf_syscls ?P ∧ distinct_fst (classes ?P) ∧ (∀c∈set (classes ?P). wf_cdecl ?wf_md ?P c))›*) distinct_fst_def (*‹distinct_fst ≡ distinct ∘ map fst›*) single_valuedp_def (*‹single_valuedp ?r = (∀x y. ?r x y ⟶ (∀z. ?r x z ⟶ y = z))›*) dest!:subcls1D (*‹?P ⊢ ?C ≺¹ ?D ⟹ ?C ≠ Object ∧ (∃fs ms. class ?P ?C = ⌊(?D, fs, ms)⌋)›*)) (*>*) lemma subcls_induct: "⟦ wf_prog wf_md P; ⋀C. ∀D. (subcls1 P)⁺⁺ C D ⟶ Q D ⟹ Q C ⟧ ⟹ Q C" (*<*) (is "?A ⟹ PROP ?P ⟹ _") proof (-) (*goal: ‹⟦wf_prog (wf_md::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) (P::'a prog); ⋀C::String.literal. ∀D::String.literal. (subcls1 P)⁺⁺ C D ⟶ (Q::String.literal ⇒ bool) D ⟹ Q C⟧ ⟹ Q (C::String.literal)›*) assume p: "PROP ?P" (*‹∀D::String.literal. (subcls1 (P::'a prog))⁺⁺ (?C::String.literal) D ⟶ (Q::String.literal ⇒ bool) D ⟹ Q ?C›*) assume "?A" (*‹wf_prog (wf_md::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) (P::'a prog)›*) thus "?thesis" (*goal: ‹Q C›*) apply - (*goal: ‹Q C›*) apply (drule wf_subcls1 (*‹wf_prog ?wf_md ?P ⟹ wfp (subcls1 ?P)¯¯›*)) (*goal: ‹wf_prog wf_md P ⟹ Q C›*) apply (drule wfP_trancl (*‹wfp ?r ⟹ wfp ?r⁺⁺›*)) (*goal: ‹wfp (subcls1 P)¯¯ ⟹ Q C›*) apply (simp only: tranclp_converse (*‹?r¯¯⁺⁺ = ?r⁺⁺¯¯›*)) (*goal: ‹wfp (subcls1 P)¯¯⁺⁺ ⟹ Q C›*) apply (erule_tac a = C in wfP_induct (*‹⟦wfp ?r; ⋀x. ∀y. ?r y x ⟶ ?P y ⟹ ?P x⟧ ⟹ ?P ?a›*)) (*goal: ‹wfp (subcls1 P)⁺⁺¯¯ ⟹ Q C›*) apply (rule p (*‹∀D. (subcls1 P)⁺⁺ ?C D ⟶ Q D ⟹ Q ?C›*)) (*goal: ‹⋀x::String.literal. ∀y::String.literal. (subcls1 (P::'a prog))⁺⁺¯¯ y x ⟶ (Q::String.literal ⇒ bool) y ⟹ Q x›*) by auto qed (*>*) lemma subcls1_induct_aux: "⟦ is_class P C; wf_prog wf_md P; Q Object; ⋀C D fs ms. ⟦ C ≠ Object; is_class P C; class P C = Some (D,fs,ms) ∧ wf_cdecl wf_md P (C,D,fs,ms) ∧ P ⊢ C ≺¹ D ∧ is_class P D ∧ Q D⟧ ⟹ Q C ⟧ ⟹ Q C" (*<*) (is "?A ⟹ ?B ⟹ ?C ⟹ PROP ?P ⟹ _") proof (-) (*goal: ‹⟦is_class P C; wf_prog wf_md P; Q Object; ⋀C D fs ms. ⟦C ≠ Object; is_class P C; class P C = ⌊(D, fs, ms)⌋ ∧ wf_cdecl wf_md P (C, D, fs, ms) ∧ P ⊢ C ≺¹ D ∧ is_class P D ∧ Q D⟧ ⟹ Q C⟧ ⟹ Q C›*) assume p: "PROP ?P" (*‹⟦(?C::String.literal) ≠ Object; is_class (P::'a prog) ?C; class P ?C = ⌊(?D::String.literal, ?fs::fdecl list, ?ms::'a option mdecl list)⌋ ∧ wf_cdecl (wf_md::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) P (?C, ?D, ?fs, ?ms) ∧ P ⊢ ?C ≺¹ ?D ∧ is_class P ?D ∧ (Q::String.literal ⇒ bool) ?D⟧ ⟹ Q ?C›*) assume "?A" "?B" "?C" (*‹is_class (P::'a prog) (C::String.literal)› ‹wf_prog (wf_md::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) (P::'a prog)› ‹(Q::String.literal ⇒ bool) Object›*) thus "?thesis" (*goal: ‹Q C›*) apply - (*goal: ‹Q C›*) apply (unfold is_class_def (*‹is_class ?P ?C ≡ class ?P ?C ≠ None›*)) (*goal: ‹⟦is_class P C; wf_prog wf_md P; Q Object⟧ ⟹ Q C›*) apply (rule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goal: ‹⟦class P C ≠ None; wf_prog wf_md P; Q Object⟧ ⟹ Q C›*) prefer 2 (*top goal: ‹⟦class P C ≠ None; wf_prog wf_md P; Q Object⟧ ⟹ ?P3› and 2 goals remain*) apply assumption (*top goal: ‹⟦class P C ≠ None; wf_prog wf_md P; Q Object⟧ ⟹ ?P3› and 2 goals remain*) prefer 2 (*top goal: ‹⟦class P C ≠ None; wf_prog wf_md P; Q Object; ?Q3⟧ ⟹ Q C› and 1 goal remains*) apply assumption (*top goal: ‹⟦class P C ≠ None; wf_prog wf_md P; Q Object; ?Q3⟧ ⟹ Q C› and 1 goal remains*) apply (erule thin_rl (*‹⟦PROP ?V::prop; PROP ?W::prop⟧ ⟹ PROP ?W›*)) (*goal: ‹⟦class (P::'a::type prog) (C::String.literal) ≠ None; wf_prog (wf_md::'a::type prog ⇒ String.literal ⇒ 'a::type mdecl ⇒ bool) P; (Q::String.literal ⇒ bool) Object⟧ ⟹ class P C ≠ None ⟶ Q C›*) apply (rule subcls_induct (*‹⟦wf_prog ?wf_md ?P; ⋀C. ∀D. (subcls1 ?P)⁺⁺ C D ⟶ ?Q D ⟹ ?Q C⟧ ⟹ ?Q ?C›*)) (*goal: ‹⟦wf_prog wf_md P; Q Object⟧ ⟹ class P C ≠ None ⟶ Q C›*) apply assumption (*top goal: ‹⟦wf_prog wf_md P; Q Object⟧ ⟹ wf_prog ?wf_md9 ?P9› and 1 goal remains*) apply (rule impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goal: ‹⋀C. ⟦wf_prog wf_md P; Q Object; ∀D. (subcls1 P)⁺⁺ C D ⟶ class P D ≠ None ⟶ Q D⟧ ⟹ class P C ≠ None ⟶ Q C›*) apply (case_tac "C = Object") (*goal: ‹⋀C. ⟦wf_prog wf_md P; Q Object; ∀D. (subcls1 P)⁺⁺ C D ⟶ class P D ≠ None ⟶ Q D; class P C ≠ None⟧ ⟹ Q C›*) apply fast (*top goal: ‹⋀C. ⟦wf_prog wf_md P; Q Object; ∀D. (subcls1 P)⁺⁺ C D ⟶ class P D ≠ None ⟶ Q D; class P C ≠ None; C = Object⟧ ⟹ Q C› and 1 goal remains*) apply safe (*goal: ‹⋀C. ⟦wf_prog wf_md P; Q Object; ∀D. (subcls1 P)⁺⁺ C D ⟶ class P D ≠ None ⟶ Q D; class P C ≠ None; C ≠ Object⟧ ⟹ Q C›*) apply (frule (1) class_wf (*‹⟦class ?P ?C = ⌊?c⌋; wf_prog ?wf_md ?P⟧ ⟹ wf_cdecl ?wf_md ?P (?C, ?c)›*)) (*goal: ‹⋀C a aa b. ⟦wf_prog wf_md P; Q Object; ∀D. (subcls1 P)⁺⁺ C D ⟶ class P D ≠ None ⟶ Q D; C ≠ Object; class P C = ⌊(a, aa, b)⌋⟧ ⟹ Q C›*) apply (frule (1) wf_cdecl_supD (*‹⟦wf_cdecl ?wf_md ?P (?C, ?D, ?r); ?C ≠ Object⟧ ⟹ is_class ?P ?D›*)) (*goal: ‹⋀C a aa b. ⟦wf_prog wf_md P; Q Object; ∀D. (subcls1 P)⁺⁺ C D ⟶ class P D ≠ None ⟶ Q D; C ≠ Object; class P C = ⌊(a, aa, b)⌋; wf_cdecl wf_md P (C, a, aa, b)⟧ ⟹ Q C›*) apply (subgoal_tac "P ⊢ C ≺¹ a") (*goal: ‹⋀C a aa b. ⟦wf_prog wf_md P; Q Object; ∀D. (subcls1 P)⁺⁺ C D ⟶ class P D ≠ None ⟶ Q D; C ≠ Object; class P C = ⌊(a, aa, b)⌋; wf_cdecl wf_md P (C, a, aa, b); is_class P a⟧ ⟹ Q C›*) apply (erule_tac [2] subcls1I (*‹⟦class (?P::?'m prog) (?C::String.literal) = ⌊(?D::String.literal, ?rest::fdecl list × ?'m option mdecl list)⌋; ?C ≠ Object⟧ ⟹ ?P ⊢ ?C ≺¹ ?D›*)) (*top goal: ‹⋀(C::String.literal) (a::String.literal) (aa::fdecl list) b::'a option mdecl list. ⟦wf_prog (wf_md::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) (P::'a prog); (Q::String.literal ⇒ bool) Object; ∀D::String.literal. (subcls1 P)⁺⁺ C D ⟶ class P D ≠ None ⟶ Q D; C ≠ Object; class P C = ⌊(a, aa, b)⌋; wf_cdecl wf_md P (C, a, aa, b); is_class P a; P ⊢ C ≺¹ a⟧ ⟹ Q C› and 1 goal remains*) apply (rule p (*‹⟦?C ≠ Object; is_class P ?C; class P ?C = ⌊(?D, ?fs, ?ms)⌋ ∧ wf_cdecl wf_md P (?C, ?D, ?fs, ?ms) ∧ P ⊢ ?C ≺¹ ?D ∧ is_class P ?D ∧ Q ?D⟧ ⟹ Q ?C›*)) (*top goal: ‹⋀C a aa b. ⟦wf_prog wf_md P; Q Object; ∀D. (subcls1 P)⁺⁺ C D ⟶ class P D ≠ None ⟶ Q D; C ≠ Object; class P C = ⌊(a, aa, b)⌋; wf_cdecl wf_md P (C, a, aa, b); is_class P a; P ⊢ C ≺¹ a⟧ ⟹ Q C› and 1 goal remains*) apply (unfold is_class_def (*‹is_class ?P ?C ≡ class ?P ?C ≠ None›*)) (*top goal: ‹⋀C a aa b. ⟦wf_prog wf_md P; Q Object; ∀D. (subcls1 P)⁺⁺ C D ⟶ class P D ≠ None ⟶ Q D; C ≠ Object; class P C = ⌊(a, aa, b)⌋; wf_cdecl wf_md P (C, a, aa, b); is_class P a; P ⊢ C ≺¹ a⟧ ⟹ C ≠ Object› and 3 goals remain*) by auto qed (*>*) lemma subcls1_induct [consumes 2, case_names Object Subcls]: "⟦ wf_prog wf_md P; is_class P C; Q Object; ⋀C D. ⟦C ≠ Object; P ⊢ C ≺¹ D; is_class P D; Q D⟧ ⟹ Q C ⟧ ⟹ Q C" (*<*) apply (erule subcls1_induct_aux (*‹⟦is_class ?P ?C; wf_prog ?wf_md ?P; ?Q Object; ⋀C D fs ms. ⟦C ≠ Object; is_class ?P C; class ?P C = ⌊(D, fs, ms)⌋ ∧ wf_cdecl ?wf_md ?P (C, D, fs, ms) ∧ ?P ⊢ C ≺¹ D ∧ is_class ?P D ∧ ?Q D⟧ ⟹ ?Q C⟧ ⟹ ?Q ?C›*)) (*goals: 1. ‹⟦wf_prog wf_md P; Q Object; ⋀C D. ⟦C ≠ Object; P ⊢ C ≺¹ D; is_class P D; Q D⟧ ⟹ Q C⟧ ⟹ wf_prog ?wf_md P› 2. ‹⟦wf_prog wf_md P; Q Object; ⋀C D. ⟦C ≠ Object; P ⊢ C ≺¹ D; is_class P D; Q D⟧ ⟹ Q C⟧ ⟹ Q Object› 3. ‹⋀C D fs ms. ⟦wf_prog wf_md P; Q Object; ⋀C D. ⟦C ≠ Object; P ⊢ C ≺¹ D; is_class P D; Q D⟧ ⟹ Q C; C ≠ Object; is_class P C; class P C = ⌊(D, fs, ms)⌋ ∧ wf_cdecl ?wf_md P (C, D, fs, ms) ∧ P ⊢ C ≺¹ D ∧ is_class P D ∧ Q D⟧ ⟹ Q C› discuss goal 1*) apply assumption (*discuss goal 2*) apply assumption (*discuss goal 3*) apply blast (*proven 3 subgoals*) . (*>*) lemma subcls_C_Object: "⟦ is_class P C; wf_prog wf_md P ⟧ ⟹ P ⊢ C ≼⇧* Object" (*<*) apply (erule (1) subcls1_induct (*‹⟦wf_prog ?wf_md ?P; is_class ?P ?C; ?Q Object; ⋀C D. ⟦C ≠ Object; ?P ⊢ C ≺¹ D; is_class ?P D; ?Q D⟧ ⟹ ?Q C⟧ ⟹ ?Q ?C›*)) (*goals: 1. ‹is_class P C ⟹ P ⊢ Object ≼⇧* Object› 2. ‹⋀Ca D. ⟦is_class P C; Ca ≠ Object; P ⊢ Ca ≺¹ D; is_class P D; P ⊢ D ≼⇧* Object⟧ ⟹ P ⊢ Ca ≼⇧* Object› discuss goal 1*) apply fast (*discuss goal 2*) apply (erule (1) converse_rtranclp_into_rtranclp (*‹⟦?r ?a ?b; ?r⇧*⇧* ?b ?c⟧ ⟹ ?r⇧*⇧* ?a ?c›*)) (*proven 2 subgoals*) . (*>*) lemma converse_subcls_is_class: assumes wf: "wf_prog wf_md P" shows "⟦ P ⊢ C ≼⇧* D; is_class P C ⟧ ⟹ is_class P D" proof (induct rule: rtranclp_induct (*‹⟦?r⇧*⇧* ?a ?b; ?P ?a; ⋀y z. ⟦?r⇧*⇧* ?a y; ?r y z; ?P y⟧ ⟹ ?P z⟧ ⟹ ?P ?b›*)) (*goals: 1. ‹is_class P C ⟹ is_class P C› 2. ‹⋀y z. ⟦P ⊢ C ≼⇧* y; P ⊢ y ≺¹ z; is_class P C ⟹ is_class P y; is_class P C⟧ ⟹ is_class P z›*) assume "is_class P C" (*‹is_class (P::'a prog) (C::String.literal)›*) thus "is_class P C" . next (*goal: ‹⋀y z. ⟦P ⊢ C ≼⇧* y; P ⊢ y ≺¹ z; is_class P C ⟹ is_class P y; is_class P C⟧ ⟹ is_class P z›*) fix D and E assume PDE: "P ⊢ D ≺¹ E" and IH: "is_class P C ⟹ is_class P D" and iPC: "is_class P C" (*‹(P::'a prog) ⊢ (D::String.literal) ≺¹ (E::String.literal)› ‹is_class (P::'a prog) (C::String.literal) ⟹ is_class P (D::String.literal)› ‹is_class (P::'a prog) (C::String.literal)›*) have "is_class P D" by (rule IH[OF iPC] (*‹is_class P D›*)) with PDE (*‹P ⊢ D ≺¹ E›*) obtain fsD and MsD where classD: "class P D = ⌊(E, fsD, MsD)⌋" (*goal: ‹(⋀fsD MsD. class P D = ⌊(E, fsD, MsD)⌋ ⟹ thesis) ⟹ thesis›*) by (auto simp add: is_class_def (*‹is_class ?P ?C ≡ class ?P ?C ≠ None›*) elim!: subcls1.cases (*‹⟦?P ⊢ ?a1.0 ≺¹ ?a2.0; ⋀C D rest. ⟦?a1.0 = C; ?a2.0 = D; class ?P C = ⌊(D, rest)⌋; C ≠ Object⟧ ⟹ ?Pa⟧ ⟹ ?Pa›*)) thus "is_class P E" using wf (*‹wf_prog wf_md P›*) PDE (*‹P ⊢ D ≺¹ E›*) by (auto elim!: subcls1.cases (*‹⟦(?P::?'m prog) ⊢ (?a1.0::String.literal) ≺¹ (?a2.0::String.literal); ⋀(C::String.literal) (D::String.literal) rest::fdecl list × ?'m option mdecl list. ⟦?a1.0 = C; ?a2.0 = D; class ?P C = ⌊(D, rest)⌋; C ≠ Object⟧ ⟹ ?Pa::bool⟧ ⟹ ?Pa›*) dest: class_wf (*‹⟦class (?P::?'a prog) (?C::String.literal) = ⌊?c::?'a option class⌋; wf_prog (?wf_md::?'a prog ⇒ String.literal ⇒ ?'a mdecl ⇒ bool) ?P⟧ ⟹ wf_cdecl ?wf_md ?P (?C, ?c)›*) simp: wf_cdecl_def (*‹wf_cdecl (?wf_md::?'m prog ⇒ String.literal ⇒ ?'m mdecl ⇒ bool) (?P::?'m prog) ≡ λ(C::String.literal, D::String.literal, fs::fdecl list, ms::?'m option mdecl list). (∀f::fdecl∈set fs. wf_fdecl ?P f) ∧ distinct_fst fs ∧ (∀m::?'m option mdecl∈set ms. wf_mdecl ?wf_md ?P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class ?P D ∧ ¬ ?P ⊢ D ≼⇧* C ∧ (∀m::?'m option mdecl∈set ms. wf_overriding ?P D m)) ∧ (C = Thread ⟶ (∃m::?'m option. (run, [], Void, m) ∈ set ms))›*)) qed lemma is_class_is_subcls: "wf_prog m P ⟹ is_class P C = P ⊢ C ≼⇧* Object" (*<*)by (fastforce simp:is_class_def (*‹is_class ?P ?C ≡ class ?P ?C ≠ None›*) elim: subcls_C_Object (*‹⟦is_class ?P ?C; wf_prog ?wf_md ?P⟧ ⟹ ?P ⊢ ?C ≼⇧* Object›*) converse_rtranclpE (*‹⟦?r⇧*⇧* ?x ?z; ?x = ?z ⟹ ?P; ⋀y. ⟦?r ?x y; ?r⇧*⇧* y ?z⟧ ⟹ ?P⟧ ⟹ ?P›*) subcls1I (*‹⟦class ?P ?C = ⌊(?D, ?rest)⌋; ?C ≠ Object⟧ ⟹ ?P ⊢ ?C ≺¹ ?D›*) dest: subcls1D (*‹?P ⊢ ?C ≺¹ ?D ⟹ ?C ≠ Object ∧ (∃fs ms. class ?P ?C = ⌊(?D, fs, ms)⌋)›*)) (*>*) lemma subcls_antisym: "⟦wf_prog m P; P ⊢ C ≼⇧* D; P ⊢ D ≼⇧* C⟧ ⟹ C = D" apply (drule acyclic_subcls1 (*‹wf_prog ?wf_md ?P ⟹ acyclicP (subcls1 ?P)›*)) (*goal: ‹⟦wf_prog m P; P ⊢ C ≼⇧* D; P ⊢ D ≼⇧* C⟧ ⟹ C = D›*) apply (drule acyclic_impl_antisym_rtrancl (*‹acyclic ?r ⟹ antisym (?r⇧*) › * )) (*goal: ‹⟦P ⊢ C ≼⇧* D; P ⊢ D ≼⇧* C; acyclicP (subcls1 P)⟧ ⟹ C = D›*) apply (drule antisymD (*‹⟦antisym ?r; (?x, ?y) ∈ ?r; (?y, ?x) ∈ ?r⟧ ⟹ ?x = ?y›*)) (*goals: 1. ‹⟦P ⊢ C ≼⇧* D; P ⊢ D ≼⇧* C⟧ ⟹ (?x4, ?y4) ∈ {(x, y). P ⊢ x ≺¹ y}⇧*› 2. ‹⟦P ⊢ C ≼⇧* D; P ⊢ D ≼⇧* C⟧ ⟹ (?y4, ?x4) ∈ {(x, y). P ⊢ x ≺¹ y}⇧*› 3. ‹⟦P ⊢ C ≼⇧* D; P ⊢ D ≼⇧* C; ?x4 = ?y4⟧ ⟹ C = D› discuss goal 1*) apply ((unfold Transitive_Closure.rtrancl_def (*‹rtrancl ≡ λr. {(xa, x). (λx xa. (x, xa) ∈ r)⇧*⇧* xa x}›*))[1]) (*top goal: ‹⟦P ⊢ C ≼⇧* D; P ⊢ D ≼⇧* C⟧ ⟹ (?x4, ?y4) ∈ {(x, y). P ⊢ x ≺¹ y}⇧*› and 2 goals remain*) apply ((auto)[1]) (*discuss goal 2*) apply ((unfold Transitive_Closure.rtrancl_def (*‹rtrancl ≡ λr. {(xa, x). (λx xa. (x, xa) ∈ r)⇧*⇧* xa x}›*))[1]) (*top goal: ‹⟦(P::'a prog) ⊢ (C::String.literal) ≼⇧* (D::String.literal); P ⊢ D ≼⇧* C⟧ ⟹ (D, C) ∈ {(x::String.literal, y::String.literal). P ⊢ x ≺¹ y}⇧*› and 1 goal remains*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . lemma is_type_pTs: "⟦ wf_prog wf_md P; class P C = ⌊(S,fs,ms)⌋; (M,Ts,T,m) ∈ set ms ⟧ ⟹ set Ts ⊆ types P" by (fastforce dest: class_wf (*‹⟦class ?P ?C = ⌊?c⌋; wf_prog ?wf_md ?P⟧ ⟹ wf_cdecl ?wf_md ?P (?C, ?c)›*) simp add: wf_cdecl_def (*‹wf_cdecl ?wf_md ?P ≡ λ(C, D, fs, ms). (∀f∈set fs. wf_fdecl ?P f) ∧ distinct_fst fs ∧ (∀m∈set ms. wf_mdecl ?wf_md ?P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class ?P D ∧ ¬ ?P ⊢ D ≼⇧* C ∧ (∀m∈set ms. wf_overriding ?P D m)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms))›*) wf_mdecl_def (*‹wf_mdecl ?wf_md ?P ?C ≡ λ(M, Ts, T, m). (∀T∈set Ts. is_type ?P T) ∧ is_type ?P T ∧ (case m of None ⇒ ?C∙M(Ts) :: T | ⌊mb⌋ ⇒ ?wf_md ?P ?C (M, Ts, T, mb))›*)) lemma widen_asym_1: assumes wfP: "wf_prog wf_md P" shows "P ⊢ C ≤ D ⟹ C = D ∨ ¬ (P ⊢ D ≤ C)" proof (erule widen.induct (*‹⟦?P ⊢ ?x1.0 ≤ ?x2.0; ⋀T. ?Pa T T; ⋀C D. ?P ⊢ C ≼⇧* D ⟹ ?Pa (Class C) (Class D); ⋀C. ?Pa NT (Class C); ⋀A. ?Pa NT (A⌊⌉); ⋀A. ?Pa (A⌊⌉) (Class Object); ⋀A B. ⟦?P ⊢ A ≤ B; ?Pa A B⟧ ⟹ ?Pa (A⌊⌉) (B⌊⌉)⟧ ⟹ ?Pa ?x1.0 ?x2.0›*)) (*goals: 1. ‹⋀T. T = T ∨ ¬ P ⊢ T ≤ T› 2. ‹⋀C D. P ⊢ C ≼⇧* D ⟹ Class C = Class D ∨ ¬ P ⊢ Class D ≤ Class C› 3. ‹⋀C. NT = Class C ∨ ¬ P ⊢ Class C ≤ NT› 4. ‹⋀A. NT = A⌊⌉ ∨ ¬ P ⊢ A⌊⌉ ≤ NT› 5. ‹⋀A. A⌊⌉ = Class Object ∨ ¬ P ⊢ Class Object ≤ A⌊⌉› 6. ‹⋀A B. ⟦P ⊢ A ≤ B; A = B ∨ ¬ P ⊢ B ≤ A⟧ ⟹ A⌊⌉ = B⌊⌉ ∨ ¬ P ⊢ B⌊⌉ ≤ A⌊⌉›*) fix T show "T = T ∨ ¬ (P ⊢ T ≤ T)" by simp next (*goals: 1. ‹⋀(C::String.literal) D::String.literal. (P::'a prog) ⊢ C ≼⇧* D ⟹ Class C = Class D ∨ ¬ P ⊢ Class D ≤ Class C› 2. ‹⋀C::String.literal. NT = Class C ∨ ¬ (P::'a prog) ⊢ Class C ≤ NT› 3. ‹⋀A::ty. NT = A⌊⌉ ∨ ¬ (P::'a prog) ⊢ A⌊⌉ ≤ NT› 4. ‹⋀A::ty. A⌊⌉ = Class Object ∨ ¬ (P::'a prog) ⊢ Class Object ≤ A⌊⌉› 5. ‹⋀(A::ty) B::ty. ⟦(P::'a prog) ⊢ A ≤ B; A = B ∨ ¬ P ⊢ B ≤ A⟧ ⟹ A⌊⌉ = B⌊⌉ ∨ ¬ P ⊢ B⌊⌉ ≤ A⌊⌉›*) fix C and D assume CscD: "P ⊢ C ≼⇧* D" (*‹(P::'a prog) ⊢ (C::String.literal) ≼⇧* (D::String.literal)›*) then have CpscD: "C = D ∨ (C ≠ D ∧ (subcls1 P)⁺⁺ C D)" by (simp add: rtranclpD (*‹(?R::?'a ⇒ ?'a ⇒ bool)⇧*⇧* (?a::?'a) (?b::?'a) ⟹ ?a = ?b ∨ ?a ≠ ?b ∧ ?R⁺⁺ ?a ?b›*)) { assume "P ⊢ D ≼⇧* C" (*‹(P::'a prog) ⊢ (D::String.literal) ≼⇧* (C::String.literal)›*) then have DpscC: "D = C ∨ (D ≠ C ∧ (subcls1 P)⁺⁺ D C)" by (simp add: rtranclpD (*‹(?R::?'a::type ⇒ ?'a::type ⇒ bool)⇧*⇧* (?a::?'a::type) (?b::?'a::type) ⟹ ?a = ?b ∨ ?a ≠ ?b ∧ ?R⁺⁺ ?a ?b›*)) { assume "(subcls1 P)⁺⁺ D C" (*‹(subcls1 (P::'a prog))⁺⁺ (D::String.literal) (C::String.literal)›*) with wfP (*‹wf_prog wf_md P›*) have CnscD: "¬ (subcls1 P)⁺⁺ C D" by (rule subcls_asym (*‹⟦wf_prog ?wf_md ?P; (subcls1 ?P)⁺⁺ ?C ?D⟧ ⟹ ¬ (subcls1 ?P)⁺⁺ ?D ?C›*)) with CpscD (*‹C = D ∨ C ≠ D ∧ (subcls1 P)⁺⁺ C D›*) have "C = D" by simp } with DpscC (*‹D = C ∨ D ≠ C ∧ (subcls1 P)⁺⁺ D C›*) have "C = D" by blast } hence "Class C = Class D ∨ ¬ (P ⊢ D ≼⇧* C)" by blast thus "Class C = Class D ∨ ¬ P ⊢ Class D ≤ Class C" by simp next (*goals: 1. ‹⋀C. NT = Class C ∨ ¬ P ⊢ Class C ≤ NT› 2. ‹⋀A. NT = A⌊⌉ ∨ ¬ P ⊢ A⌊⌉ ≤ NT› 3. ‹⋀A. A⌊⌉ = Class Object ∨ ¬ P ⊢ Class Object ≤ A⌊⌉› 4. ‹⋀A B. ⟦P ⊢ A ≤ B; A = B ∨ ¬ P ⊢ B ≤ A⟧ ⟹ A⌊⌉ = B⌊⌉ ∨ ¬ P ⊢ B⌊⌉ ≤ A⌊⌉›*) fix C show "NT = Class C ∨ ¬ P ⊢ Class C ≤ NT" by simp next (*goals: 1. ‹⋀A. NT = A⌊⌉ ∨ ¬ P ⊢ A⌊⌉ ≤ NT› 2. ‹⋀A. A⌊⌉ = Class Object ∨ ¬ P ⊢ Class Object ≤ A⌊⌉› 3. ‹⋀A B. ⟦P ⊢ A ≤ B; A = B ∨ ¬ P ⊢ B ≤ A⟧ ⟹ A⌊⌉ = B⌊⌉ ∨ ¬ P ⊢ B⌊⌉ ≤ A⌊⌉›*) fix A { assume "P ⊢ A⌊⌉ ≤ NT" (*‹(P::'a prog) ⊢ A::ty⌊⌉ ≤ NT›*) hence "A⌊⌉ = NT" by fastforce hence False by simp } hence "¬ (P ⊢ A⌊⌉ ≤ NT)" by blast thus "NT = A⌊⌉ ∨ ¬ P ⊢ A⌊⌉ ≤ NT" by simp next (*goals: 1. ‹⋀A::ty. A⌊⌉ = Class Object ∨ ¬ (P::'a::type prog) ⊢ Class Object ≤ A⌊⌉› 2. ‹⋀(A::ty) B::ty. ⟦(P::'a::type prog) ⊢ A ≤ B; A = B ∨ ¬ P ⊢ B ≤ A⟧ ⟹ A⌊⌉ = B⌊⌉ ∨ ¬ P ⊢ B⌊⌉ ≤ A⌊⌉›*) fix A show "A⌊⌉ = Class Object ∨ ¬ P ⊢ Class Object ≤ A⌊⌉" by (auto dest: Object_widen (*‹?P ⊢ Class Object ≤ ?T ⟹ ?T = Class Object›*)) next (*goal: ‹⋀(A::ty) B::ty. ⟦(P::'a prog) ⊢ A ≤ B; A = B ∨ ¬ P ⊢ B ≤ A⟧ ⟹ A⌊⌉ = B⌊⌉ ∨ ¬ P ⊢ B⌊⌉ ≤ A⌊⌉›*) fix A and B assume AsU: "P ⊢ A ≤ B" and BnpscA: "A = B ∨ ¬ P ⊢ B ≤ A" (*‹(P::'a prog) ⊢ (A::ty) ≤ (B::ty)› ‹(A::ty) = (B::ty) ∨ ¬ (P::'a prog) ⊢ B ≤ A›*) { assume "P ⊢ B⌊⌉ ≤ A⌊⌉" (*‹(P::'a prog) ⊢ B::ty⌊⌉ ≤ A::ty⌊⌉›*) hence "P ⊢ B ≤ A" by (auto dest: Array_Array_widen (*‹?P ⊢ ?T⌊⌉ ≤ ?U⌊⌉ ⟹ ?P ⊢ ?T ≤ ?U›*)) with BnpscA (*‹A = B ∨ ¬ P ⊢ B ≤ A›*) have "A = B" by blast hence "A⌊⌉ = B⌊⌉" by simp } thus "A⌊⌉ = B⌊⌉ ∨ ¬ P ⊢ B⌊⌉ ≤ A⌊⌉" by blast qed lemma widen_asym: "⟦ wf_prog wf_md P; P ⊢ C ≤ D; C ≠ D ⟧ ⟹ ¬ (P ⊢ D ≤ C)" proof (-) (*goal: ‹⟦wf_prog wf_md P; P ⊢ C ≤ D; C ≠ D⟧ ⟹ ¬ P ⊢ D ≤ C›*) assume wfP: "wf_prog wf_md P" and CsD: "P ⊢ C ≤ D" and CneqD: "C ≠ D" (*‹wf_prog (wf_md::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) (P::'a prog)› ‹(P::'a prog) ⊢ (C::ty) ≤ (D::ty)› ‹(C::ty) ≠ (D::ty)›*) from wfP (*‹wf_prog wf_md P›*) CsD (*‹P ⊢ C ≤ D›*) have "C = D ∨ ¬ (P ⊢ D ≤ C)" by (rule widen_asym_1 (*‹⟦wf_prog ?wf_md ?P; ?P ⊢ ?C ≤ ?D⟧ ⟹ ?C = ?D ∨ ¬ ?P ⊢ ?D ≤ ?C›*)) with CneqD (*‹C ≠ D›*) show "?thesis" (*goal: ‹¬ P ⊢ D ≤ C›*) by simp qed lemma widen_antisym: "⟦ wf_prog m P; P ⊢ T ≤ U; P ⊢ U ≤ T ⟧ ⟹ T = U" by (auto dest: widen_asym (*‹⟦wf_prog ?wf_md ?P; ?P ⊢ ?C ≤ ?D; ?C ≠ ?D⟧ ⟹ ¬ ?P ⊢ ?D ≤ ?C›*)) lemma widen_C_Object: "⟦ wf_prog wf_md P; is_class P C ⟧ ⟹ P ⊢ Class C ≤ Class Object" by (simp add: subcls_C_Object (*‹⟦is_class ?P ?C; wf_prog ?wf_md ?P⟧ ⟹ ?P ⊢ ?C ≼⇧* Object›*)) lemma is_refType_widen_Object: assumes wfP: "wf_prog wfmc P" shows "⟦ is_type P A; is_refT A ⟧ ⟹ P ⊢ A ≤ Class Object" apply (induct A) (*goals: 1. ‹⟦is_type P Void; is_refT Void⟧ ⟹ P ⊢ Void ≤ Class Object› 2. ‹⟦is_type P Boolean; is_refT Boolean⟧ ⟹ P ⊢ Boolean ≤ Class Object› 3. ‹⟦is_type P Integer; is_refT Integer⟧ ⟹ P ⊢ Integer ≤ Class Object› 4. ‹⟦is_type P NT; is_refT NT⟧ ⟹ P ⊢ NT ≤ Class Object› 5. ‹⋀x. ⟦is_type P (Class x); is_refT (Class x)⟧ ⟹ P ⊢ Class x ≤ Class Object› 6. ‹⋀A. ⟦⟦is_type P A; is_refT A⟧ ⟹ P ⊢ A ≤ Class Object; is_type P (A⌊⌉); is_refT (A⌊⌉)⟧ ⟹ P ⊢ A⌊⌉ ≤ Class Object› discuss goal 1*) apply ((auto elim: refTE (*‹⟦is_refT ?a; ?a = NT ⟹ ?P; ⋀C. ?a = Class C ⟹ ?P; ⋀A. ?a = A⌊⌉ ⟹ ?P⟧ ⟹ ?P›*) intro: subcls_C_Object[OF _ wfP] (*‹is_class P ?C ⟹ P ⊢ ?C ≼⇧* Object›*) widen_array_object (*‹?P ⊢ ?A⌊⌉ ≤ Class Object›*))[1]) (*discuss goal 2*) apply ((auto elim: refTE (*‹⟦is_refT (?a::ty); ?a = NT ⟹ ?P::bool; ⋀C::String.literal. ?a = Class C ⟹ ?P; ⋀A::ty. ?a = A⌊⌉ ⟹ ?P⟧ ⟹ ?P›*) intro: subcls_C_Object[OF _ wfP] (*‹is_class (P::'a::type prog) (?C::String.literal) ⟹ P ⊢ ?C ≼⇧* Object›*) widen_array_object (*‹(?P::?'m::type prog) ⊢ ?A::ty⌊⌉ ≤ Class Object›*))[1]) (*discuss goal 3*) apply ((auto elim: refTE (*‹⟦is_refT ?a; ?a = NT ⟹ ?P; ⋀C. ?a = Class C ⟹ ?P; ⋀A. ?a = A⌊⌉ ⟹ ?P⟧ ⟹ ?P›*) intro: subcls_C_Object[OF _ wfP] (*‹is_class P ?C ⟹ P ⊢ ?C ≼⇧* Object›*) widen_array_object (*‹?P ⊢ ?A⌊⌉ ≤ Class Object›*))[1]) (*discuss goal 4*) apply ((auto elim: refTE (*‹⟦is_refT ?a; ?a = NT ⟹ ?P; ⋀C. ?a = Class C ⟹ ?P; ⋀A. ?a = A⌊⌉ ⟹ ?P⟧ ⟹ ?P›*) intro: subcls_C_Object[OF _ wfP] (*‹is_class P ?C ⟹ P ⊢ ?C ≼⇧* Object›*) widen_array_object (*‹?P ⊢ ?A⌊⌉ ≤ Class Object›*))[1]) (*discuss goal 5*) apply ((auto elim: refTE (*‹⟦is_refT ?a; ?a = NT ⟹ ?P; ⋀C. ?a = Class C ⟹ ?P; ⋀A. ?a = A⌊⌉ ⟹ ?P⟧ ⟹ ?P›*) intro: subcls_C_Object[OF _ wfP] (*‹is_class P ?C ⟹ P ⊢ ?C ≼⇧* Object›*) widen_array_object (*‹?P ⊢ ?A⌊⌉ ≤ Class Object›*))[1]) (*discuss goal 6*) apply ((auto elim: refTE (*‹⟦is_refT ?a; ?a = NT ⟹ ?P; ⋀C. ?a = Class C ⟹ ?P; ⋀A. ?a = A⌊⌉ ⟹ ?P⟧ ⟹ ?P›*) intro: subcls_C_Object[OF _ wfP] (*‹is_class P ?C ⟹ P ⊢ ?C ≼⇧* Object›*) widen_array_object (*‹?P ⊢ ?A⌊⌉ ≤ Class Object›*))[1]) (*proven 6 subgoals*) . lemma is_lub_unique: assumes wf: "wf_prog wf_md P" shows "⟦ P ⊢ lub(U, V) = T; P ⊢ lub(U, V) = T' ⟧ ⟹ T = T'" by (auto elim!: is_lub.cases (*‹⟦?P ⊢ lub(?U, ?V) = ?T; ⟦?P ⊢ ?U ≤ ?T; ?P ⊢ ?V ≤ ?T; ⋀T'. ⟦?P ⊢ ?U ≤ T'; ?P ⊢ ?V ≤ T'⟧ ⟹ ?P ⊢ ?T ≤ T'⟧ ⟹ ?Pa⟧ ⟹ ?Pa›*) intro: widen_antisym[OF wf] (*‹⟦P ⊢ ?T ≤ ?U; P ⊢ ?U ≤ ?T⟧ ⟹ ?T = ?U›*)) subsection‹Well-formedness and method lookup› lemma sees_wf_mdecl: "⟦ wf_prog wf_md P; P ⊢ C sees M:Ts→T = m in D ⟧ ⟹ wf_mdecl wf_md P D (M,Ts,T,m)" (*<*) apply (drule visible_method_exists (*‹?P ⊢ ?C sees ?M: ?Ts→?T = ?m in ?D ⟹ ∃D' fs ms. class ?P ?D = ⌊(D', fs, ms)⌋ ∧ map_of ms ?M = ⌊(?Ts, ?T, ?m)⌋›*)) (*goal: ‹⟦wf_prog wf_md P; P ⊢ C sees M: Ts→T = m in D⟧ ⟹ wf_mdecl wf_md P D (M, Ts, T, m)›*) apply clarify (*goal: ‹⟦wf_prog wf_md P; ∃D' fs ms. class P D = ⌊(D', fs, ms)⌋ ∧ map_of ms M = ⌊(Ts, T, m)⌋⟧ ⟹ wf_mdecl wf_md P D (M, Ts, T, m)›*) apply (drule class_wf (*‹⟦class ?P ?C = ⌊?c⌋; wf_prog ?wf_md ?P⟧ ⟹ wf_cdecl ?wf_md ?P (?C, ?c)›*)) (*goals: 1. ‹⋀D' fs ms. ⟦wf_prog wf_md P; map_of ms M = ⌊(Ts, T, m)⌋⟧ ⟹ wf_prog (?wf_md6 D' fs ms) P› 2. ‹⋀D' fs ms. ⟦wf_prog wf_md P; map_of ms M = ⌊(Ts, T, m)⌋; wf_cdecl (?wf_md6 D' fs ms) P (D, D', fs, ms)⟧ ⟹ wf_mdecl wf_md P D (M, Ts, T, m)› discuss goal 1*) apply assumption (*discuss goal 2*) apply (drule map_of_SomeD (*‹map_of ?xs ?k = ⌊?y⌋ ⟹ (?k, ?y) ∈ set ?xs›*)) (*goal: ‹⋀D' fs ms. ⟦wf_prog wf_md P; map_of ms M = ⌊(Ts, T, m)⌋; wf_cdecl wf_md P (D, D', fs, ms)⟧ ⟹ wf_mdecl wf_md P D (M, Ts, T, m)›*) apply (auto simp add: wf_cdecl_def (*‹wf_cdecl ?wf_md ?P ≡ λ(C, D, fs, ms). (∀f∈set fs. wf_fdecl ?P f) ∧ distinct_fst fs ∧ (∀m∈set ms. wf_mdecl ?wf_md ?P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class ?P D ∧ ¬ ?P ⊢ D ≼⇧* C ∧ (∀m∈set ms. wf_overriding ?P D m)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms))›*)) (*proven 2 subgoals*) . (*>*) lemma sees_method_mono [rule_format (no_asm)]: "⟦ P ⊢ C' ≼⇧* C; wf_prog wf_md P ⟧ ⟹ ∀D Ts T m. P ⊢ C sees M:Ts→T = m in D ⟶ (∃D' Ts' T' m'. P ⊢ C' sees M:Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T)" apply (drule rtranclpD (*‹?R⇧*⇧* ?a ?b ⟹ ?a = ?b ∨ ?a ≠ ?b ∧ ?R⁺⁺ ?a ?b›*)) (*goal: ‹⟦P ⊢ C' ≼⇧* C; wf_prog wf_md P⟧ ⟹ ∀D Ts T m. P ⊢ C sees M: Ts→T = m in D ⟶ (∃D' Ts' T' m'. P ⊢ C' sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T)›*) apply (erule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goal: ‹⟦wf_prog wf_md P; C' = C ∨ C' ≠ C ∧ (subcls1 P)⁺⁺ C' C⟧ ⟹ ∀D Ts T m. P ⊢ C sees M: Ts→T = m in D ⟶ (∃D' Ts' T' m'. P ⊢ C' sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T)›*) apply (fastforce intro: widen_refl (*‹?P ⊢ ?T ≤ ?T›*) widens_refl (*‹?P ⊢ ?Ts [≤] ?Ts›*)) (*top goal: ‹⟦wf_prog (wf_md::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) (P::'a prog); (C'::String.literal) = (C::String.literal)⟧ ⟹ ∀(D::String.literal) (Ts::ty list) (T::ty) m::'a option. P ⊢ C sees (M::String.literal): Ts→T = m in D ⟶ (∃(D'::String.literal) (Ts'::ty list) (T'::ty) m'::'a option. P ⊢ C' sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T)› and 1 goal remains*) apply (erule conjE (*‹⟦?P ∧ ?Q; ⟦?P; ?Q⟧ ⟹ ?R⟧ ⟹ ?R›*)) (*goal: ‹⟦wf_prog wf_md P; C' ≠ C ∧ (subcls1 P)⁺⁺ C' C⟧ ⟹ ∀D Ts T m. P ⊢ C sees M: Ts→T = m in D ⟶ (∃D' Ts' T' m'. P ⊢ C' sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T)›*) apply (erule tranclp_trans_induct (*‹⟦?r⁺⁺ ?x ?y; ⋀x y. ?r x y ⟹ ?P x y; ⋀x y z. ⟦?r⁺⁺ x y; ?P x y; ?r⁺⁺ y z; ?P y z⟧ ⟹ ?P x z⟧ ⟹ ?P ?x ?y›*)) (*goal: ‹⟦wf_prog wf_md P; C' ≠ C; (subcls1 P)⁺⁺ C' C⟧ ⟹ ∀D Ts T m. P ⊢ C sees M: Ts→T = m in D ⟶ (∃D' Ts' T' m'. P ⊢ C' sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T)›*) prefer 2 (*top goal: ‹⋀x y z. ⟦wf_prog wf_md P; C' ≠ C; (subcls1 P)⁺⁺ x y; ∀D Ts T m. P ⊢ y sees M: Ts→T = m in D ⟶ (∃D' Ts' T' m'. P ⊢ x sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T); (subcls1 P)⁺⁺ y z; ∀D Ts T m. P ⊢ z sees M: Ts→T = m in D ⟶ (∃D' Ts' T' m'. P ⊢ y sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T)⟧ ⟹ ∀D Ts T m. P ⊢ z sees M: Ts→T = m in D ⟶ (∃D' Ts' T' m'. P ⊢ x sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T)› and 1 goal remains*) apply clarify (*top goal: ‹⋀x y z. ⟦wf_prog wf_md P; C' ≠ C; (subcls1 P)⁺⁺ x y; ∀D Ts T m. P ⊢ y sees M: Ts→T = m in D ⟶ (∃D' Ts' T' m'. P ⊢ x sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T); (subcls1 P)⁺⁺ y z; ∀D Ts T m. P ⊢ z sees M: Ts→T = m in D ⟶ (∃D' Ts' T' m'. P ⊢ y sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T)⟧ ⟹ ∀D Ts T m. P ⊢ z sees M: Ts→T = m in D ⟶ (∃D' Ts' T' m'. P ⊢ x sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T)› and 1 goal remains*) apply (drule spec (*‹∀x. ?P x ⟹ ?P ?x›*), drule spec (*‹∀x. ?P x ⟹ ?P ?x›*), drule spec (*‹∀x. ?P x ⟹ ?P ?x›*), drule spec (*‹∀x::?'a. (?P::?'a ⇒ bool) x ⟹ ?P (?x::?'a)›*), erule (1) impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀x y z D Ts T m. ⟦wf_prog wf_md P; C' ≠ C; (subcls1 P)⁺⁺ x y; ∀D Ts T m. P ⊢ y sees M: Ts→T = m in D ⟶ (∃D' Ts' T' m'. P ⊢ x sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T); (subcls1 P)⁺⁺ y z; ∀D Ts T m. P ⊢ z sees M: Ts→T = m in D ⟶ (∃D' Ts' T' m'. P ⊢ y sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T); P ⊢ z sees M: Ts→T = m in D⟧ ⟹ ∃D' Ts' T' m'. P ⊢ x sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T› and 1 goal remains*) apply clarify (*top goal: ‹⋀x y z D Ts T m. ⟦wf_prog wf_md P; C' ≠ C; (subcls1 P)⁺⁺ x y; ∀D Ts T m. P ⊢ y sees M: Ts→T = m in D ⟶ (∃D' Ts' T' m'. P ⊢ x sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T); (subcls1 P)⁺⁺ y z; P ⊢ z sees M: Ts→T = m in D; ∃D' Ts' T' m'. P ⊢ y sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T⟧ ⟹ ∃D' Ts' T' m'. P ⊢ x sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T› and 1 goal remains*) apply (fast elim: widen_trans (*‹⟦?P ⊢ ?S ≤ ?U; ?P ⊢ ?U ≤ ?T⟧ ⟹ ?P ⊢ ?S ≤ ?T›*) widens_trans (*‹⟦?P ⊢ ?Ss [≤] ?Ts; ?P ⊢ ?Ts [≤] ?Us⟧ ⟹ ?P ⊢ ?Ss [≤] ?Us›*)) (*top goal: ‹⋀x y z D Ts T m D' Ts' T' m'. ⟦wf_prog wf_md P; C' ≠ C; (subcls1 P)⁺⁺ x y; ∀D Ts T m. P ⊢ y sees M: Ts→T = m in D ⟶ (∃D' Ts' T' m'. P ⊢ x sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T); (subcls1 P)⁺⁺ y z; P ⊢ z sees M: Ts→T = m in D; P ⊢ y sees M: Ts'→T' = m' in D'; P ⊢ Ts [≤] Ts'; P ⊢ T' ≤ T⟧ ⟹ ∃D' Ts' T' m'. P ⊢ x sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T› and 1 goal remains*) apply clarify (*goal: ‹⋀x y. ⟦wf_prog wf_md P; C' ≠ C; P ⊢ x ≺¹ y⟧ ⟹ ∀D Ts T m. P ⊢ y sees M: Ts→T = m in D ⟶ (∃D' Ts' T' m'. P ⊢ x sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T)›*) apply (drule subcls1D (*‹?P ⊢ ?C ≺¹ ?D ⟹ ?C ≠ Object ∧ (∃fs ms. class ?P ?C = ⌊(?D, fs, ms)⌋)›*)) (*goal: ‹⋀(x::String.literal) (y::String.literal) (D::String.literal) (Ts::ty list) (T::ty) m::'a::type option. ⟦wf_prog (wf_md::'a::type prog ⇒ String.literal ⇒ 'a::type mdecl ⇒ bool) (P::'a::type prog); (C'::String.literal) ≠ (C::String.literal); P ⊢ x ≺¹ y; P ⊢ y sees (M::String.literal): Ts→T = m in D⟧ ⟹ ∃(D'::String.literal) (Ts'::ty list) (T'::ty) m'::'a::type option. P ⊢ x sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T›*) apply clarify (*goal: ‹⋀x y D Ts T m. ⟦wf_prog wf_md P; C' ≠ C; P ⊢ y sees M: Ts→T = m in D; x ≠ Object ∧ (∃fs ms. class P x = ⌊(y, fs, ms)⌋)⟧ ⟹ ∃D' Ts' T' m'. P ⊢ x sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T›*) apply (clarsimp simp:Method_def (*‹?P ⊢ ?C sees ?M: ?Ts→?T = ?m in ?D ≡ ∃Mm. ?P ⊢ ?C sees_methods Mm ∧ Mm ?M = ⌊((?Ts, ?T, ?m), ?D)⌋›*)) (*goal: ‹⋀(x::String.literal) (y::String.literal) (D::String.literal) (Ts::ty list) (T::ty) (m::'a option) (fs::fdecl list) ms::'a option mdecl list. ⟦wf_prog (wf_md::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) (P::'a prog); (C'::String.literal) ≠ (C::String.literal); P ⊢ y sees (M::String.literal): Ts→T = m in D; x ≠ Object; class P x = ⌊(y, fs, ms)⌋⟧ ⟹ ∃(D'::String.literal) (Ts'::ty list) (T'::ty) m'::'a option. P ⊢ x sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T›*) apply (frule (2) sees_methods_rec (*‹⟦class ?P ?C = ⌊(?D, ?fs, ?ms)⌋; ?C ≠ Object; ?P ⊢ ?D sees_methods ?Mm; ?Mm' = ?Mm ++ (map_option (λm. (m, ?C)) ∘ map_of ?ms)⟧ ⟹ ?P ⊢ ?C sees_methods ?Mm'›*)) (*goal: ‹⋀x y D Ts T m fs ms Mm. ⟦wf_prog wf_md P; C' ≠ C; x ≠ Object; class P x = ⌊(y, fs, ms)⌋; P ⊢ y sees_methods Mm; Mm M = ⌊((Ts, T, m), D)⌋⟧ ⟹ ∃D' Ts' T'. (∃m' Mm. P ⊢ x sees_methods Mm ∧ Mm M = ⌊((Ts', T', m'), D')⌋) ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T›*) apply (rule refl (*‹?t = ?t›*)) (*top goal: ‹⋀(x::String.literal) (y::String.literal) (D::String.literal) (Ts::ty list) (T::ty) (m::'a option) (fs::fdecl list) (ms::'a option mdecl list) Mm::String.literal ⇒ ((ty list × ty × 'a option) × String.literal) option. ⟦wf_prog (wf_md::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) (P::'a prog); (C'::String.literal) ≠ (C::String.literal); x ≠ Object; class P x = ⌊(y, fs, ms)⌋; P ⊢ y sees_methods Mm; Mm (M::String.literal) = ⌊((Ts, T, m), D)⌋⟧ ⟹ (?Mm'87::String.literal ⇒ String.literal ⇒ String.literal ⇒ ty list ⇒ ty ⇒ 'a option ⇒ fdecl list ⇒ 'a option mdecl list ⇒ (String.literal ⇒ ((ty list × ty × 'a option) × String.literal) option) ⇒ String.literal ⇒ ((ty list × ty × 'a option) × String.literal) option) x y D Ts T m fs ms Mm = Mm ++ (map_option (λm::ty list × ty × 'a option. (m, x)) ∘ map_of ms)› and 1 goal remains*) apply (case_tac "map_of ms M") (*goal: ‹⋀x y D Ts T m fs ms Mm. ⟦wf_prog wf_md P; C' ≠ C; x ≠ Object; class P x = ⌊(y, fs, ms)⌋; P ⊢ y sees_methods Mm; Mm M = ⌊((Ts, T, m), D)⌋; P ⊢ x sees_methods Mm ++ (map_option (λm. (m, x)) ∘ map_of ms)⟧ ⟹ ∃D' Ts' T'. (∃m' Mm. P ⊢ x sees_methods Mm ∧ Mm M = ⌊((Ts', T', m'), D')⌋) ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T›*) apply (rule_tac x = D in exI (*‹(?P::?'a ⇒ bool) (?x::?'a) ⟹ ∃x::?'a. ?P x›*)) (*top goal: ‹⋀x y D Ts T m fs ms Mm. ⟦wf_prog wf_md P; C' ≠ C; x ≠ Object; class P x = ⌊(y, fs, ms)⌋; P ⊢ y sees_methods Mm; Mm M = ⌊((Ts, T, m), D)⌋; P ⊢ x sees_methods Mm ++ (map_option (λm. (m, x)) ∘ map_of ms); map_of ms M = None⟧ ⟹ ∃D' Ts' T'. (∃m' Mm. P ⊢ x sees_methods Mm ∧ Mm M = ⌊((Ts', T', m'), D')⌋) ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T› and 1 goal remains*) apply (rule_tac x = Ts in exI (*‹?P ?x ⟹ ∃x. ?P x›*)) (*top goal: ‹⋀x y D Ts T m fs ms Mm. ⟦wf_prog wf_md P; C' ≠ C; x ≠ Object; class P x = ⌊(y, fs, ms)⌋; P ⊢ y sees_methods Mm; Mm M = ⌊((Ts, T, m), D)⌋; P ⊢ x sees_methods Mm ++ (map_option (λm. (m, x)) ∘ map_of ms); map_of ms M = None⟧ ⟹ ∃Ts' T'. (∃m' Mm. P ⊢ x sees_methods Mm ∧ Mm M = ⌊((Ts', T', m'), D)⌋) ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T› and 1 goal remains*) apply (rule_tac x = T in exI (*‹?P ?x ⟹ ∃x. ?P x›*)) (*top goal: ‹⋀x y D Ts T m fs ms Mm. ⟦wf_prog wf_md P; C' ≠ C; x ≠ Object; class P x = ⌊(y, fs, ms)⌋; P ⊢ y sees_methods Mm; Mm M = ⌊((Ts, T, m), D)⌋; P ⊢ x sees_methods Mm ++ (map_option (λm. (m, x)) ∘ map_of ms); map_of ms M = None⟧ ⟹ ∃T'. (∃m' Mm. P ⊢ x sees_methods Mm ∧ Mm M = ⌊((Ts, T', m'), D)⌋) ∧ P ⊢ Ts [≤] Ts ∧ P ⊢ T' ≤ T› and 1 goal remains*) apply (clarsimp simp add: widens_refl (*‹?P ⊢ ?Ts [≤] ?Ts›*)) (*top goal: ‹⋀(x::String.literal) (y::String.literal) (D::String.literal) (Ts::ty list) (T::ty) (m::'a option) (fs::fdecl list) (ms::'a option mdecl list) Mm::String.literal ⇒ ((ty list × ty × 'a option) × String.literal) option. ⟦wf_prog (wf_md::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) (P::'a prog); (C'::String.literal) ≠ (C::String.literal); x ≠ Object; class P x = ⌊(y, fs, ms)⌋; P ⊢ y sees_methods Mm; Mm (M::String.literal) = ⌊((Ts, T, m), D)⌋; P ⊢ x sees_methods Mm ++ (map_option (λm::ty list × ty × 'a option. (m, x)) ∘ map_of ms); map_of ms M = None⟧ ⟹ (∃(m'::'a option) Mm::String.literal ⇒ ((ty list × ty × 'a option) × String.literal) option. P ⊢ x sees_methods Mm ∧ Mm M = ⌊((Ts, T, m'), D)⌋) ∧ P ⊢ Ts [≤] Ts ∧ P ⊢ T ≤ T› and 1 goal remains*) apply (rule_tac x = m in exI (*‹(?P::?'a::type ⇒ bool) (?x::?'a::type) ⟹ ∃x::?'a::type. ?P x›*)) (*top goal: ‹⋀x y D Ts T m fs ms Mm. ⟦wf_prog wf_md P; C' ≠ C; x ≠ Object; class P x = ⌊(y, fs, ms)⌋; P ⊢ y sees_methods Mm; Mm M = ⌊((Ts, T, m), D)⌋; P ⊢ x sees_methods Mm ++ (map_option (λm. (m, x)) ∘ map_of ms); map_of ms M = None⟧ ⟹ ∃m' Mm. P ⊢ x sees_methods Mm ∧ Mm M = ⌊((Ts, T, m'), D)⌋› and 1 goal remains*) apply (fastforce simp add:map_add_def (*‹?m1.0 ++ ?m2.0 = (λx. case ?m2.0 x of None ⇒ ?m1.0 x | ⌊y⌋ ⇒ ⌊y⌋)›*) split:option.split (*‹?P (case ?option of None ⇒ ?f1.0 | ⌊x⌋ ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = ⌊x2⌋ ⟶ ?P (?f2.0 x2)))›*)) (*top goal: ‹⋀(x::String.literal) (y::String.literal) (D::String.literal) (Ts::ty list) (T::ty) (m::'a::type option) (fs::fdecl list) (ms::'a::type option mdecl list) Mm::String.literal ⇒ ((ty list × ty × 'a::type option) × String.literal) option. ⟦wf_prog (wf_md::'a::type prog ⇒ String.literal ⇒ 'a::type mdecl ⇒ bool) (P::'a::type prog); (C'::String.literal) ≠ (C::String.literal); x ≠ Object; class P x = ⌊(y, fs, ms)⌋; P ⊢ y sees_methods Mm; Mm (M::String.literal) = ⌊((Ts, T, m), D)⌋; P ⊢ x sees_methods Mm ++ (map_option (λm::ty list × ty × 'a::type option. (m, x)) ∘ map_of ms); map_of ms M = None⟧ ⟹ ∃Mm::String.literal ⇒ ((ty list × ty × 'a::type option) × String.literal) option. P ⊢ x sees_methods Mm ∧ Mm M = ⌊((Ts, T, m), D)⌋› and 1 goal remains*) apply clarsimp (*goal: ‹⋀x y D Ts T m fs ms Mm a. ⟦wf_prog wf_md P; C' ≠ C; x ≠ Object; class P x = ⌊(y, fs, ms)⌋; P ⊢ y sees_methods Mm; Mm M = ⌊((Ts, T, m), D)⌋; P ⊢ x sees_methods Mm ++ (map_option (λm. (m, x)) ∘ map_of ms); map_of ms M = ⌊a⌋⟧ ⟹ ∃D' Ts' T'. (∃m' Mm. P ⊢ x sees_methods Mm ∧ Mm M = ⌊((Ts', T', m'), D')⌋) ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T›*) apply (rename_tac Ts' T' m') (*goal: ‹⋀x y D Ts T m fs ms Mm a aa b. ⟦wf_prog wf_md P; C' ≠ C; x ≠ Object; class P x = ⌊(y, fs, ms)⌋; P ⊢ y sees_methods Mm; Mm M = ⌊((Ts, T, m), D)⌋; P ⊢ x sees_methods Mm ++ (map_option (λm. (m, x)) ∘ map_of ms); map_of ms M = ⌊(a, aa, b)⌋⟧ ⟹ ∃D' Ts' T'. (∃m' Mm. P ⊢ x sees_methods Mm ∧ Mm M = ⌊((Ts', T', m'), D')⌋) ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T›*) apply (drule (1) class_wf (*‹⟦class ?P ?C = ⌊?c⌋; wf_prog ?wf_md ?P⟧ ⟹ wf_cdecl ?wf_md ?P (?C, ?c)›*)) (*goal: ‹⋀x y D Ts T m fs ms Mm Ts' T' m'. ⟦wf_prog wf_md P; C' ≠ C; x ≠ Object; class P x = ⌊(y, fs, ms)⌋; P ⊢ y sees_methods Mm; Mm M = ⌊((Ts, T, m), D)⌋; P ⊢ x sees_methods Mm ++ (map_option (λm. (m, x)) ∘ map_of ms); map_of ms M = ⌊(Ts', T', m')⌋⟧ ⟹ ∃D' Ts' T'. (∃m' Mm. P ⊢ x sees_methods Mm ∧ Mm M = ⌊((Ts', T', m'), D')⌋) ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T›*) apply (unfold wf_cdecl_def (*‹wf_cdecl (?wf_md::?'m prog ⇒ String.literal ⇒ ?'m mdecl ⇒ bool) (?P::?'m prog) ≡ λ(C::String.literal, D::String.literal, fs::fdecl list, ms::?'m option mdecl list). (∀f::fdecl∈set fs. wf_fdecl ?P f) ∧ distinct_fst fs ∧ (∀m::?'m option mdecl∈set ms. wf_mdecl ?wf_md ?P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class ?P D ∧ ¬ ?P ⊢ D ≼⇧* C ∧ (∀m::?'m option mdecl∈set ms. wf_overriding ?P D m)) ∧ (C = Thread ⟶ (∃m::?'m option. (run, [], Void, m) ∈ set ms))›*) Method_def (*‹(?P::?'m prog) ⊢ (?C::String.literal) sees (?M::String.literal): (?Ts::ty list)→(?T::ty) = (?m::?'m option) in (?D::String.literal) ≡ ∃Mm::String.literal ⇒ ((ty list × ty × ?'m option) × String.literal) option. ?P ⊢ ?C sees_methods Mm ∧ Mm ?M = ⌊((?Ts, ?T, ?m), ?D)⌋›*)) (*goal: ‹⋀x y D Ts T m fs ms Mm Ts' T' m'. ⟦wf_prog wf_md P; C' ≠ C; x ≠ Object; P ⊢ y sees_methods Mm; Mm M = ⌊((Ts, T, m), D)⌋; P ⊢ x sees_methods Mm ++ (map_option (λm. (m, x)) ∘ map_of ms); map_of ms M = ⌊(Ts', T', m')⌋; wf_cdecl wf_md P (x, y, fs, ms)⟧ ⟹ ∃D' Ts' T'. (∃m' Mm. P ⊢ x sees_methods Mm ∧ Mm M = ⌊((Ts', T', m'), D')⌋) ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T›*) apply (frule map_of_SomeD (*‹map_of ?xs ?k = ⌊?y⌋ ⟹ (?k, ?y) ∈ set ?xs›*)) (*goal: ‹⋀(x::String.literal) (y::String.literal) (D::String.literal) (Ts::ty list) (T::ty) (m::'a::type option) (fs::fdecl list) (ms::'a::type option mdecl list) (Mm::String.literal ⇒ ((ty list × ty × 'a::type option) × String.literal) option) (Ts'::ty list) (T'::ty) m'::'a::type option. ⟦wf_prog (wf_md::'a::type prog ⇒ String.literal ⇒ 'a::type mdecl ⇒ bool) (P::'a::type prog); (C'::String.literal) ≠ (C::String.literal); x ≠ Object; P ⊢ y sees_methods Mm; Mm (M::String.literal) = ⌊((Ts, T, m), D)⌋; P ⊢ x sees_methods Mm ++ (map_option (λm::ty list × ty × 'a::type option. (m, x)) ∘ map_of ms); map_of ms M = ⌊(Ts', T', m')⌋; case (x, y, fs, ms) of (C::String.literal, D::String.literal, fs::fdecl list, ms::'a::type option mdecl list) ⇒ (∀f::fdecl∈set fs. wf_fdecl P f) ∧ distinct_fst fs ∧ (∀m::'a::type option mdecl∈set ms. wf_mdecl wf_md P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class P D ∧ ¬ P ⊢ D ≼⇧* C ∧ (∀m::'a::type option mdecl∈set ms. wf_overriding P D m)) ∧ (C = Thread ⟶ (∃m::'a::type option. (run, [], Void, m) ∈ set ms))⟧ ⟹ ∃(D'::String.literal) (Ts'::ty list) T'::ty. (∃(m'::'a::type option) Mm::String.literal ⇒ ((ty list × ty × 'a::type option) × String.literal) option. P ⊢ x sees_methods Mm ∧ Mm M = ⌊((Ts', T', m'), D')⌋) ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T›*) apply clarsimp (*goal: ‹⋀x y D Ts T m fs ms Mm Ts' T' m'. ⟦wf_prog wf_md P; C' ≠ C; x ≠ Object; P ⊢ y sees_methods Mm; Mm M = ⌊((Ts, T, m), D)⌋; P ⊢ x sees_methods Mm ++ (map_option (λm. (m, x)) ∘ map_of ms); map_of ms M = ⌊(Ts', T', m')⌋; case (x, y, fs, ms) of (C, D, fs, ms) ⇒ (∀f∈set fs. wf_fdecl P f) ∧ distinct_fst fs ∧ (∀m∈set ms. wf_mdecl wf_md P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class P D ∧ ¬ P ⊢ D ≼⇧* C ∧ (∀m∈set ms. wf_overriding P D m)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms)); (M, Ts', T', m') ∈ set ms⟧ ⟹ ∃D' Ts' T'. (∃m' Mm. P ⊢ x sees_methods Mm ∧ Mm M = ⌊((Ts', T', m'), D')⌋) ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T›*) apply ((drule (1) bspec (*‹⟦∀x∈?A. ?P x; ?x ∈ ?A⟧ ⟹ ?P ?x›*))+) (*goal: ‹⋀x y D Ts T m fs ms Mm Ts' T' m'. ⟦wf_prog wf_md P; C' ≠ C; x ≠ Object; P ⊢ y sees_methods Mm; Mm M = ⌊((Ts, T, m), D)⌋; P ⊢ x sees_methods Mm ++ (map_option (λm. (m, x)) ∘ map_of ms); map_of ms M = ⌊(Ts', T', m')⌋; (M, Ts', T', m') ∈ set ms; ∀x∈set fs. wf_fdecl P x; distinct_fst fs; ∀xa∈set ms. wf_mdecl wf_md P x xa; distinct_fst ms; is_class P y; ¬ P ⊢ y ≼⇧* x; ∀x∈set ms. wf_overriding P y x; x = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms)⟧ ⟹ ∃D' Ts' T'. (∃m' Mm. P ⊢ x sees_methods Mm ∧ Mm M = ⌊((Ts', T', m'), D')⌋) ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T›*) apply clarsimp (*goal: ‹⋀x y D Ts T m fs ms Mm Ts' T' m'. ⟦wf_prog wf_md P; C' ≠ C; x ≠ Object; P ⊢ y sees_methods Mm; Mm M = ⌊((Ts, T, m), D)⌋; P ⊢ x sees_methods Mm ++ (map_option (λm. (m, x)) ∘ map_of ms); map_of ms M = ⌊(Ts', T', m')⌋; (M, Ts', T', m') ∈ set ms; ∀x∈set fs. wf_fdecl P x; distinct_fst fs; distinct_fst ms; is_class P y; ¬ P ⊢ y ≼⇧* x; x = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms); wf_mdecl wf_md P x (M, Ts', T', m'); wf_overriding P y (M, Ts', T', m')⟧ ⟹ ∃D' Ts' T'. (∃m' Mm. P ⊢ x sees_methods Mm ∧ Mm M = ⌊((Ts', T', m'), D')⌋) ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T›*) apply (erule_tac x=D in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*goal: ‹⋀x y D Ts T m fs ms Mm Ts' T' m'. ⟦wf_prog wf_md P; C' ≠ C; x ≠ Object; P ⊢ y sees_methods Mm; Mm M = ⌊((Ts, T, m), D)⌋; P ⊢ x sees_methods Mm ++ (map_option (λm. (m, x)) ∘ map_of ms); map_of ms M = ⌊(Ts', T', m')⌋; (M, Ts', T', m') ∈ set ms; ∀x∈set fs. wf_fdecl P x; distinct_fst fs; distinct_fst ms; is_class P y; ¬ P ⊢ y ≼⇧* x; x = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms); wf_mdecl wf_md P x (M, Ts', T', m'); ∀D' Ts'a T'a. (∃m'. P ⊢ y sees M: Ts'a→T'a = m' in D') ⟶ P ⊢ Ts'a [≤] Ts' ∧ P ⊢ T' ≤ T'a⟧ ⟹ ∃D' Ts' T'. (∃m' Mm. P ⊢ x sees_methods Mm ∧ Mm M = ⌊((Ts', T', m'), D')⌋) ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T›*) apply (erule_tac x=Ts in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*goal: ‹⋀(x::String.literal) (y::String.literal) (D::String.literal) (Ts::ty list) (T::ty) (m::'a option) (fs::fdecl list) (ms::'a option mdecl list) (Mm::String.literal ⇒ ((ty list × ty × 'a option) × String.literal) option) (Ts'::ty list) (T'::ty) m'::'a option. ⟦wf_prog (wf_md::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) (P::'a prog); (C'::String.literal) ≠ (C::String.literal); x ≠ Object; P ⊢ y sees_methods Mm; Mm (M::String.literal) = ⌊((Ts, T, m), D)⌋; P ⊢ x sees_methods Mm ++ (map_option (λm::ty list × ty × 'a option. (m, x)) ∘ map_of ms); map_of ms M = ⌊(Ts', T', m')⌋; (M, Ts', T', m') ∈ set ms; ∀x::fdecl∈set fs. wf_fdecl P x; distinct_fst fs; distinct_fst ms; is_class P y; ¬ P ⊢ y ≼⇧* x; x = Thread ⟶ (∃m::'a option. (run, [], Void, m) ∈ set ms); wf_mdecl wf_md P x (M, Ts', T', m'); ∀(Ts'a::ty list) T'a::ty. (∃m'::'a option. P ⊢ y sees M: Ts'a→T'a = m' in D) ⟶ P ⊢ Ts'a [≤] Ts' ∧ P ⊢ T' ≤ T'a⟧ ⟹ ∃(D'::String.literal) (Ts'::ty list) T'::ty. (∃(m'::'a option) Mm::String.literal ⇒ ((ty list × ty × 'a option) × String.literal) option. P ⊢ x sees_methods Mm ∧ Mm M = ⌊((Ts', T', m'), D')⌋) ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T›*) apply (rotate_tac -1) (*goal: ‹⋀x y D Ts T m fs ms Mm Ts' T' m'. ⟦wf_prog wf_md P; C' ≠ C; x ≠ Object; P ⊢ y sees_methods Mm; Mm M = ⌊((Ts, T, m), D)⌋; P ⊢ x sees_methods Mm ++ (map_option (λm. (m, x)) ∘ map_of ms); map_of ms M = ⌊(Ts', T', m')⌋; (M, Ts', T', m') ∈ set ms; ∀x∈set fs. wf_fdecl P x; distinct_fst fs; distinct_fst ms; is_class P y; ¬ P ⊢ y ≼⇧* x; x = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms); wf_mdecl wf_md P x (M, Ts', T', m'); ∀T'a. (∃m'. P ⊢ y sees M: Ts→T'a = m' in D) ⟶ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T'a⟧ ⟹ ∃D' Ts' T'. (∃m' Mm. P ⊢ x sees_methods Mm ∧ Mm M = ⌊((Ts', T', m'), D')⌋) ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T›*) apply (erule_tac x=T in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*goal: ‹⋀(x::String.literal) (y::String.literal) (D::String.literal) (Ts::ty list) (T::ty) (m::'a option) (fs::fdecl list) (ms::'a option mdecl list) (Mm::String.literal ⇒ ((ty list × ty × 'a option) × String.literal) option) (Ts'::ty list) (T'::ty) m'::'a option. ⟦∀T'a::ty. (∃m'::'a option. (P::'a prog) ⊢ y sees (M::String.literal): Ts→T'a = m' in D) ⟶ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T'a; wf_prog (wf_md::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) P; (C'::String.literal) ≠ (C::String.literal); x ≠ Object; P ⊢ y sees_methods Mm; Mm M = ⌊((Ts, T, m), D)⌋; P ⊢ x sees_methods Mm ++ (map_option (λm::ty list × ty × 'a option. (m, x)) ∘ map_of ms); map_of ms M = ⌊(Ts', T', m')⌋; (M, Ts', T', m') ∈ set ms; ∀x::fdecl∈set fs. wf_fdecl P x; distinct_fst fs; distinct_fst ms; is_class P y; ¬ P ⊢ y ≼⇧* x; x = Thread ⟶ (∃m::'a option. (run, [], Void, m) ∈ set ms); wf_mdecl wf_md P x (M, Ts', T', m')⟧ ⟹ ∃(D'::String.literal) (Ts'::ty list) T'::ty. (∃(m'::'a option) Mm::String.literal ⇒ ((ty list × ty × 'a option) × String.literal) option. P ⊢ x sees_methods Mm ∧ Mm M = ⌊((Ts', T', m'), D')⌋) ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T›*) by (fastforce simp:map_add_def (*‹?m1.0 ++ ?m2.0 = (λx. case ?m2.0 x of None ⇒ ?m1.0 x | ⌊y⌋ ⇒ ⌊y⌋)›*) Method_def (*‹?P ⊢ ?C sees ?M: ?Ts→?T = ?m in ?D ≡ ∃Mm. ?P ⊢ ?C sees_methods Mm ∧ Mm ?M = ⌊((?Ts, ?T, ?m), ?D)⌋›*) split:option.split (*‹?P (case ?option of None ⇒ ?f1.0 | ⌊x⌋ ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = ⌊x2⌋ ⟶ ?P (?f2.0 x2)))›*)) (*>*) lemma sees_method_mono2: "⟦ P ⊢ C' ≼⇧* C; wf_prog wf_md P; P ⊢ C sees M:Ts→T = m in D; P ⊢ C' sees M:Ts'→T' = m' in D' ⟧ ⟹ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T" (*<*)by (blast dest:sees_method_mono (*‹⟦?P ⊢ ?C' ≼⇧* ?C; wf_prog ?wf_md ?P; ?P ⊢ ?C sees ?M: ?Ts→?T = ?m in ?D⟧ ⟹ ∃D' Ts' T' m'. ?P ⊢ ?C' sees ?M: Ts'→T' = m' in D' ∧ ?P ⊢ ?Ts [≤] Ts' ∧ ?P ⊢ T' ≤ ?T›*) sees_method_fun (*‹⟦?P ⊢ ?C sees ?M: ?TS→?T = ?m in ?D; ?P ⊢ ?C sees ?M: ?TS'→?T' = ?m' in ?D'⟧ ⟹ ?TS' = ?TS ∧ ?T' = ?T ∧ ?m' = ?m ∧ ?D' = ?D›*))(*>*) lemma mdecls_visible: assumes wf: "wf_prog wf_md P" and "class": "is_class P C" shows "⋀D fs ms. class P C = Some(D,fs,ms) ⟹ ∃Mm. P ⊢ C sees_methods Mm ∧ (∀(M,Ts,T,m) ∈ set ms. Mm M = Some((Ts,T,m),C))" using wf (*‹wf_prog wf_md P›*) "class" (*‹is_class P C›*) proof (induct rule:subcls1_induct (*‹⟦wf_prog (?wf_md::?'a prog ⇒ String.literal ⇒ ?'a mdecl ⇒ bool) (?P::?'a prog); is_class ?P (?C::String.literal); (?Q::String.literal ⇒ bool) Object; ⋀(C::String.literal) D::String.literal. ⟦C ≠ Object; ?P ⊢ C ≺¹ D; is_class ?P D; ?Q D⟧ ⟹ ?Q C⟧ ⟹ ?Q ?C›*)) (*goals: 1. ‹⋀(D::String.literal) (fs::fdecl list) ms::'a::type option mdecl list. class (P::'a::type prog) Object = ⌊(D, fs, ms)⌋ ⟹ ∃Mm::String.literal ⇒ ((ty list × ty × 'a::type option) × String.literal) option. P ⊢ Object sees_methods Mm ∧ (∀(M::String.literal, Ts::ty list, T::ty, m::'a::type option)∈set ms. Mm M = ⌊((Ts, T, m), Object)⌋)› 2. ‹⋀(C::String.literal) (D::String.literal) (Da::String.literal) (fs::fdecl list) ms::'a::type option mdecl list. ⟦C ≠ Object; (P::'a::type prog) ⊢ C ≺¹ D; is_class P D; ⋀(Da::String.literal) (fs::fdecl list) ms::'a::type option mdecl list. class P D = ⌊(Da, fs, ms)⌋ ⟹ ∃Mm::String.literal ⇒ ((ty list × ty × 'a::type option) × String.literal) option. P ⊢ D sees_methods Mm ∧ (∀(M::String.literal, Ts::ty list, T::ty, m::'a::type option)∈set ms. Mm M = ⌊((Ts, T, m), D)⌋); class P C = ⌊(Da, fs, ms)⌋⟧ ⟹ ∃Mm::String.literal ⇒ ((ty list × ty × 'a::type option) × String.literal) option. P ⊢ C sees_methods Mm ∧ (∀(M::String.literal, Ts::ty list, T::ty, m::'a::type option)∈set ms. Mm M = ⌊((Ts, T, m), C)⌋)›*) case Object (*‹class P Object = ⌊(D, fs, ms)⌋›*) with wf (*‹wf_prog wf_md P›*) have "distinct_fst ms" by (auto dest: class_wf (*‹⟦class ?P ?C = ⌊?c⌋; wf_prog ?wf_md ?P⟧ ⟹ wf_cdecl ?wf_md ?P (?C, ?c)›*) simp add: wf_cdecl_def (*‹wf_cdecl ?wf_md ?P ≡ λ(C, D, fs, ms). (∀f∈set fs. wf_fdecl ?P f) ∧ distinct_fst fs ∧ (∀m∈set ms. wf_mdecl ?wf_md ?P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class ?P D ∧ ¬ ?P ⊢ D ≼⇧* C ∧ (∀m∈set ms. wf_overriding ?P D m)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms))›*)) with Object (*‹class P Object = ⌊(D, fs, ms)⌋›*) show "?case" (*goal: ‹∃Mm. P ⊢ Object sees_methods Mm ∧ (∀a∈set ms. case a of (M, Ts, T, m) ⇒ Mm M = ⌊((Ts, T, m), Object)⌋)›*) by (fastforce intro!: sees_methods_Object (*‹⟦class ?P Object = ⌊(?D, ?fs, ?ms)⌋; ?Mm = map_option (λm. (m, Object)) ∘ map_of ?ms⟧ ⟹ ?P ⊢ Object sees_methods ?Mm›*) map_of_SomeI (*‹⟦distinct_fst ?kxs; (?k, ?x) ∈ set ?kxs⟧ ⟹ map_of ?kxs ?k = ⌊?x⌋›*)) next (*goal: ‹⋀C D Da fs ms. ⟦C ≠ Object; P ⊢ C ≺¹ D; is_class P D; ⋀Da fs ms. class P D = ⌊(Da, fs, ms)⌋ ⟹ ∃Mm. P ⊢ D sees_methods Mm ∧ (∀(M, Ts, T, m)∈set ms. Mm M = ⌊((Ts, T, m), D)⌋); class P C = ⌊(Da, fs, ms)⌋⟧ ⟹ ∃Mm. P ⊢ C sees_methods Mm ∧ (∀(M, Ts, T, m)∈set ms. Mm M = ⌊((Ts, T, m), C)⌋)›*) case Subcls (*‹C_ ≠ Object› ‹P ⊢ C_ ≺¹ D_› ‹is_class P D_› ‹class P D_ = ⌊(?D, ?fs, ?ms)⌋ ⟹ ∃Mm. P ⊢ D_ sees_methods Mm ∧ (∀a∈set ?ms. case a of (M, Ts, T, m) ⇒ Mm M = ⌊((Ts, T, m), D_)⌋)› ‹class P C_ = ⌊(D, fs, ms)⌋›*) with wf (*‹wf_prog wf_md P›*) have "distinct_fst ms" by (auto dest: class_wf (*‹⟦class ?P ?C = ⌊?c⌋; wf_prog ?wf_md ?P⟧ ⟹ wf_cdecl ?wf_md ?P (?C, ?c)›*) simp add: wf_cdecl_def (*‹wf_cdecl ?wf_md ?P ≡ λ(C, D, fs, ms). (∀f∈set fs. wf_fdecl ?P f) ∧ distinct_fst fs ∧ (∀m∈set ms. wf_mdecl ?wf_md ?P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class ?P D ∧ ¬ ?P ⊢ D ≼⇧* C ∧ (∀m∈set ms. wf_overriding ?P D m)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms))›*)) with Subcls (*‹(C_::String.literal) ≠ Object› ‹(P::'a::type prog) ⊢ (C_::String.literal) ≺¹ (D_::String.literal)› ‹is_class P D_› ‹class P D_ = ⌊(?D, ?fs, ?ms)⌋ ⟹ ∃Mm. P ⊢ D_ sees_methods Mm ∧ (∀a∈set ?ms. case a of (M, Ts, T, m) ⇒ Mm M = ⌊((Ts, T, m), D_)⌋)› ‹class P C_ = ⌊(D, fs, ms)⌋›*) show "?case" (*goal: ‹∃Mm::String.literal ⇒ ((ty list × ty × 'a option) × String.literal) option. (P::'a prog) ⊢ (C_::String.literal) sees_methods Mm ∧ (∀a::'a option mdecl∈set (ms::'a option mdecl list). case a of (M::String.literal, Ts::ty list, T::ty, m::'a option) ⇒ Mm M = ⌊((Ts, T, m), C_)⌋)›*) by (fastforce elim:sees_methods_rec (*‹⟦class ?P ?C = ⌊(?D, ?fs, ?ms)⌋; ?C ≠ Object; ?P ⊢ ?D sees_methods ?Mm; ?Mm' = ?Mm ++ (map_option (λm. (m, ?C)) ∘ map_of ?ms)⟧ ⟹ ?P ⊢ ?C sees_methods ?Mm'›*) dest:subcls1D (*‹?P ⊢ ?C ≺¹ ?D ⟹ ?C ≠ Object ∧ (∃fs ms. class ?P ?C = ⌊(?D, fs, ms)⌋)›*) map_of_SomeI (*‹⟦distinct_fst ?kxs; (?k, ?x) ∈ set ?kxs⟧ ⟹ map_of ?kxs ?k = ⌊?x⌋›*) simp:is_class_def (*‹is_class ?P ?C ≡ class ?P ?C ≠ None›*)) qed lemma mdecl_visible: assumes wf: "wf_prog wf_md P" and C: "class P C = ⌊(S,fs,ms)⌋" and m: "(M,Ts,T,m) ∈ set ms" shows "P ⊢ C sees M:Ts→T = m in C" proof (-) (*goal: ‹P ⊢ C sees M: Ts→T = m in C›*) from C (*‹class (P::'a prog) (C::String.literal) = ⌊(S::String.literal, fs::fdecl list, ms::'a option mdecl list)⌋›*) have "is_class P C" by (auto simp:is_class_def (*‹is_class ?P ?C ≡ class ?P ?C ≠ None›*)) with assms (*‹wf_prog (wf_md::'a::type prog ⇒ String.literal ⇒ 'a::type mdecl ⇒ bool) (P::'a::type prog)› ‹class P C = ⌊(S, fs, ms)⌋› ‹(M, Ts, T, m) ∈ set ms›*) show "?thesis" (*goal: ‹P ⊢ C sees M: Ts→T = m in C›*) by (bestsimp simp:Method_def (*‹?P ⊢ ?C sees ?M: ?Ts→?T = ?m in ?D ≡ ∃Mm. ?P ⊢ ?C sees_methods Mm ∧ Mm ?M = ⌊((?Ts, ?T, ?m), ?D)⌋›*) dest:mdecls_visible (*‹⟦wf_prog ?wf_md ?P; is_class ?P ?C; class ?P ?C = ⌊(?D, ?fs, ?ms)⌋⟧ ⟹ ∃Mm. ?P ⊢ ?C sees_methods Mm ∧ (∀(M, Ts, T, m)∈set ?ms. Mm M = ⌊((Ts, T, m), ?C)⌋)›*)) qed lemma sees_wf_native: "⟦ wf_prog wf_md P; P ⊢ C sees M:Ts→T=Native in D ⟧ ⟹ D∙M(Ts) :: T" apply (drule (1) sees_wf_mdecl (*‹⟦wf_prog ?wf_md ?P; ?P ⊢ ?C sees ?M: ?Ts→?T = ?m in ?D⟧ ⟹ wf_mdecl ?wf_md ?P ?D (?M, ?Ts, ?T, ?m)›*)) (*goal: ‹⟦wf_prog (wf_md::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) (P::'a prog); P ⊢ (C::String.literal) sees (M::String.literal): (Ts::ty list)→(T::ty) = Native in (D::String.literal)⟧ ⟹ D∙M(Ts) :: T›*) by (simp add: wf_mdecl_def (*‹wf_mdecl (?wf_md::?'m prog ⇒ String.literal ⇒ ?'m mdecl ⇒ bool) (?P::?'m prog) (?C::String.literal) ≡ λ(M::String.literal, Ts::ty list, T::ty, m::?'m option). (∀T::ty∈set Ts. is_type ?P T) ∧ is_type ?P T ∧ (case m of None ⇒ ?C∙M(Ts) :: T | ⌊mb::?'m⌋ ⇒ ?wf_md ?P ?C (M, Ts, T, mb))›*)) lemma Call_lemma: "⟦ P ⊢ C sees M:Ts→T = m in D; P ⊢ C' ≼⇧* C; wf_prog wf_md P ⟧ ⟹ ∃D' Ts' T' m'. P ⊢ C' sees M:Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T ∧ P ⊢ C' ≼⇧* D' ∧ is_type P T' ∧ (∀T∈set Ts'. is_type P T) ∧ (m' ≠ Native ⟶ wf_md P D' (M,Ts',T',the m'))" apply (frule (2) sees_method_mono (*‹⟦?P ⊢ ?C' ≼⇧* ?C; wf_prog ?wf_md ?P; ?P ⊢ ?C sees ?M: ?Ts→?T = ?m in ?D⟧ ⟹ ∃D' Ts' T' m'. ?P ⊢ ?C' sees ?M: Ts'→T' = m' in D' ∧ ?P ⊢ ?Ts [≤] Ts' ∧ ?P ⊢ T' ≤ ?T›*)) (*goal: ‹⟦P ⊢ C sees M: Ts→T = m in D; P ⊢ C' ≼⇧* C; wf_prog wf_md P⟧ ⟹ ∃D' Ts' T' m'. P ⊢ C' sees M: Ts'→T' = m' in D' ∧ P ⊢ Ts [≤] Ts' ∧ P ⊢ T' ≤ T ∧ P ⊢ C' ≼⇧* D' ∧ is_type P T' ∧ (∀T∈set Ts'. is_type P T) ∧ (m' ≠ None ⟶ wf_md P D' (M, Ts', T', the m'))›*) by (fastforce intro:sees_method_decl_above (*‹(?P::?'a prog) ⊢ (?C::String.literal) sees (?M::String.literal): (?Ts::ty list)→(?T::ty) = (?m::?'a option) in (?D::String.literal) ⟹ ?P ⊢ ?C ≼⇧* ?D›*) dest:sees_wf_mdecl (*‹⟦wf_prog (?wf_md::?'a prog ⇒ String.literal ⇒ ?'a mdecl ⇒ bool) (?P::?'a prog); ?P ⊢ (?C::String.literal) sees (?M::String.literal): (?Ts::ty list)→(?T::ty) = (?m::?'a option) in (?D::String.literal)⟧ ⟹ wf_mdecl ?wf_md ?P ?D (?M, ?Ts, ?T, ?m)›*) simp: wf_mdecl_def (*‹wf_mdecl (?wf_md::?'m prog ⇒ String.literal ⇒ ?'m mdecl ⇒ bool) (?P::?'m prog) (?C::String.literal) ≡ λ(M::String.literal, Ts::ty list, T::ty, m::?'m option). (∀T::ty∈set Ts. is_type ?P T) ∧ is_type ?P T ∧ (case m of None ⇒ ?C∙M(Ts) :: T | ⌊mb::?'m⌋ ⇒ ?wf_md ?P ?C (M, Ts, T, mb))›*)) lemma sub_Thread_sees_run: assumes wf: "wf_prog wf_md P" and PCThread: "P ⊢ C ≼⇧* Thread" shows "∃D mthd. P ⊢ C sees run: []→Void = ⌊mthd⌋ in D" proof (-) (*goal: ‹∃D mthd. P ⊢ C sees run: []→Void = ⌊mthd⌋ in D›*) from class_Thread[OF wf] (*‹∃C fs ms. class P Thread = ⌊(C, fs, ms)⌋›*) obtain T' and fsT and MsT where classT: "class P Thread = ⌊(T', fsT, MsT)⌋" (*goal: ‹(⋀T' fsT MsT. class P Thread = ⌊(T', fsT, MsT)⌋ ⟹ thesis) ⟹ thesis›*) by blast hence wfcThread: "wf_cdecl wf_md P (Thread, T', fsT, MsT)" using wf (*‹wf_prog wf_md P›*) by (rule class_wf (*‹⟦class (?P::?'a prog) (?C::String.literal) = ⌊?c::?'a option class⌋; wf_prog (?wf_md::?'a prog ⇒ String.literal ⇒ ?'a mdecl ⇒ bool) ?P⟧ ⟹ wf_cdecl ?wf_md ?P (?C, ?c)›*)) then obtain mrunT where runThread: "(run, [], Void, mrunT) ∈ set MsT" (*goal: ‹(⋀mrunT. (run, [], Void, mrunT) ∈ set MsT ⟹ thesis) ⟹ thesis›*) by (auto simp add: wf_cdecl_def (*‹wf_cdecl ?wf_md ?P ≡ λ(C, D, fs, ms). (∀f∈set fs. wf_fdecl ?P f) ∧ distinct_fst fs ∧ (∀m∈set ms. wf_mdecl ?wf_md ?P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class ?P D ∧ ¬ ?P ⊢ D ≼⇧* C ∧ (∀m∈set ms. wf_overriding ?P D m)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms))›*)) moreover have "∃MmT. P ⊢ Thread sees_methods MmT ∧ (∀(M,Ts,T,m) ∈ set MsT. MmT M = Some((Ts,T,m),Thread))" by (rule mdecls_visible[OF wf is_class_Thread[OF wf] classT] (*‹∃Mm. P ⊢ Thread sees_methods Mm ∧ (∀(M, Ts, T, m)∈set MsT. Mm M = ⌊((Ts, T, m), Thread)⌋)›*)) then obtain MmT where ThreadMmT: "P ⊢ Thread sees_methods MmT" and MmT: "∀(M,Ts,T,m) ∈ set MsT. MmT M = Some((Ts,T,m),Thread)" (*goal: ‹(⋀MmT. ⟦P ⊢ Thread sees_methods MmT; ∀(M, Ts, T, m)∈set MsT. MmT M = ⌊((Ts, T, m), Thread)⌋⟧ ⟹ thesis) ⟹ thesis›*) by blast ultimately obtain mthd where "MmT run = ⌊(([], Void, mthd), Thread)⌋" (*goal: ‹(⋀mthd::'a::type option. (MmT::String.literal ⇒ ((ty list × ty × 'a::type option) × String.literal) option) run = ⌊(([], Void, mthd), Thread)⌋ ⟹ thesis::bool) ⟹ thesis›*) by fastforce with ThreadMmT (*‹P ⊢ Thread sees_methods MmT›*) have Tseesrun: "P ⊢ Thread sees run: []→Void = mthd in Thread" by (auto simp add: Method_def (*‹?P ⊢ ?C sees ?M: ?Ts→?T = ?m in ?D ≡ ∃Mm. ?P ⊢ ?C sees_methods Mm ∧ Mm ?M = ⌊((?Ts, ?T, ?m), ?D)⌋›*)) from sees_method_mono[OF PCThread wf Tseesrun] (*‹∃D' Ts' T' m'. P ⊢ C sees run: Ts'→T' = m' in D' ∧ P ⊢ [] [≤] Ts' ∧ P ⊢ T' ≤ Void›*) obtain D' and m' where "P ⊢ C sees run: []→Void = m' in D'" (*goal: ‹(⋀(m'::'a::type option) D'::String.literal. (P::'a::type prog) ⊢ (C::String.literal) sees run: []→Void = m' in D' ⟹ thesis::bool) ⟹ thesis›*) by auto moreover have "m' ≠ None" proof (standard) (*goal: ‹m' = None ⟹ False›*) assume "m' = None" (*‹(m'::'a option) = None›*) with wf (*‹wf_prog (wf_md::'a::type prog ⇒ String.literal ⇒ 'a::type mdecl ⇒ bool) (P::'a::type prog)›*) ‹P ⊢ C sees run: []→Void = m' in D'› (*‹P ⊢ C sees run: []→Void = m' in D'›*) have "D'∙run([]) :: Void" by (auto intro: sees_wf_native (*‹⟦wf_prog (?wf_md::?'a prog ⇒ String.literal ⇒ ?'a mdecl ⇒ bool) (?P::?'a prog); ?P ⊢ (?C::String.literal) sees (?M::String.literal): (?Ts::ty list)→(?T::ty) = Native in (?D::String.literal)⟧ ⟹ ?D∙?M(?Ts) :: ?T›*)) thus False apply cases (*goals: 1. ‹⟦(D'::String.literal) = Thread; run = start⟧ ⟹ False› 2. ‹⟦(D'::String.literal) = Thread; run = join⟧ ⟹ False› 3. ‹⟦(D'::String.literal) = Thread; run = interrupt⟧ ⟹ False› 4. ‹⟦(D'::String.literal) = Object; run = wait⟧ ⟹ False› 5. ‹⟦(D'::String.literal) = Object; run = notify⟧ ⟹ False› 6. ‹⟦(D'::String.literal) = Object; run = notifyAll⟧ ⟹ False› 7. ‹⟦(D'::String.literal) = Object; run = yield⟧ ⟹ False› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*proven 7 subgoals*) . qed ultimately show "?thesis" (*goal: ‹∃D mthd. P ⊢ C sees run: []→Void = ⌊mthd⌋ in D›*) by auto qed lemma wf_prog_lift: assumes wf: "wf_prog (λP C bd. A P C bd) P" and rule: "⋀wf_md C M Ts C T m. ⟦ wf_prog wf_md P; P ⊢ C sees M:Ts→T = ⌊m⌋ in C; is_class P C; set Ts ⊆ types P; A P C (M,Ts,T,m) ⟧ ⟹ B P C (M,Ts,T,m)" shows "wf_prog (λP C bd. B P C bd) P" proof (cases P) (*goal: ‹⋀x. P = Program x ⟹ wf_prog B P›*) case (Program P') (*‹P = Program P'›*) thus "?thesis" (*goal: ‹wf_prog B P›*) using wf (*‹wf_prog A P›*) apply (clarsimp simp add: wf_prog_def (*‹wf_prog ?wf_md ?P = (wf_syscls ?P ∧ distinct_fst (classes ?P) ∧ (∀c∈set (classes ?P). wf_cdecl ?wf_md ?P c))›*) wf_cdecl_def (*‹wf_cdecl ?wf_md ?P ≡ λ(C, D, fs, ms). (∀f∈set fs. wf_fdecl ?P f) ∧ distinct_fst fs ∧ (∀m∈set ms. wf_mdecl ?wf_md ?P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class ?P D ∧ ¬ ?P ⊢ D ≼⇧* C ∧ (∀m∈set ms. wf_overriding ?P D m)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms))›*)) (*goal: ‹wf_prog (B::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) (P::'a prog)›*) apply (drule (1) bspec (*‹⟦∀x::?'a∈?A::?'a set. (?P::?'a ⇒ bool) x; (?x::?'a) ∈ ?A⟧ ⟹ ?P ?x›*)) (*goal: ‹⋀a aa ab b. ⟦P = Program P'; (a, aa, ab, b) ∈ set P'; wf_syscls (Program P'); distinct_fst P'; ∀x∈set P'. case x of (C, D, fs, ms) ⇒ (∀x∈set fs. wf_fdecl (Program P') x) ∧ distinct_fst fs ∧ (∀x∈set ms. wf_mdecl A (Program P') C x) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class (Program P') D ∧ ¬ Program P' ⊢ D ≼⇧* C ∧ (∀x∈set ms. wf_overriding (Program P') D x)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms))⟧ ⟹ (∀x∈set ab. wf_fdecl (Program P') x) ∧ distinct_fst ab ∧ (∀x∈set b. wf_mdecl B (Program P') a x) ∧ distinct_fst b ∧ (a ≠ Object ⟶ is_class (Program P') aa ∧ ¬ Program P' ⊢ aa ≼⇧* a ∧ (∀x∈set b. wf_overriding (Program P') aa x)) ∧ (a = Thread ⟶ (∃m. (run, [], Void, m) ∈ set b))›*) apply (rename_tac C D fs ms) (*goal: ‹⋀a aa ab b. ⟦P = Program P'; (a, aa, ab, b) ∈ set P'; wf_syscls (Program P'); distinct_fst P'; case (a, aa, ab, b) of (C, D, fs, ms) ⇒ (∀x∈set fs. wf_fdecl (Program P') x) ∧ distinct_fst fs ∧ (∀x∈set ms. wf_mdecl A (Program P') C x) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class (Program P') D ∧ ¬ Program P' ⊢ D ≼⇧* C ∧ (∀x∈set ms. wf_overriding (Program P') D x)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms))⟧ ⟹ (∀x∈set ab. wf_fdecl (Program P') x) ∧ distinct_fst ab ∧ (∀x∈set b. wf_mdecl B (Program P') a x) ∧ distinct_fst b ∧ (a ≠ Object ⟶ is_class (Program P') aa ∧ ¬ Program P' ⊢ aa ≼⇧* a ∧ (∀x∈set b. wf_overriding (Program P') aa x)) ∧ (a = Thread ⟶ (∃m. (run, [], Void, m) ∈ set b))›*) apply (subgoal_tac "is_class P C") (*goals: 1. ‹⋀C D fs ms. ⟦P = Program P'; (C, D, fs, ms) ∈ set P'; wf_syscls (Program P'); distinct_fst P'; case (C, D, fs, ms) of (C, D, fs, ms) ⇒ (∀x∈set fs. wf_fdecl (Program P') x) ∧ distinct_fst fs ∧ (∀x∈set ms. wf_mdecl A (Program P') C x) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class (Program P') D ∧ ¬ Program P' ⊢ D ≼⇧* C ∧ (∀x∈set ms. wf_overriding (Program P') D x)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms)); is_class P C⟧ ⟹ (∀x∈set fs. wf_fdecl (Program P') x) ∧ distinct_fst fs ∧ (∀x∈set ms. wf_mdecl B (Program P') C x) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class (Program P') D ∧ ¬ Program P' ⊢ D ≼⇧* C ∧ (∀x∈set ms. wf_overriding (Program P') D x)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms))› 2. ‹⋀C D fs ms. ⟦P = Program P'; (C, D, fs, ms) ∈ set P'; wf_syscls (Program P'); distinct_fst P'; case (C, D, fs, ms) of (C, D, fs, ms) ⇒ (∀x∈set fs. wf_fdecl (Program P') x) ∧ distinct_fst fs ∧ (∀x∈set ms. wf_mdecl A (Program P') C x) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class (Program P') D ∧ ¬ Program P' ⊢ D ≼⇧* C ∧ (∀x∈set ms. wf_overriding (Program P') D x)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms))⟧ ⟹ is_class P C› discuss goal 1*) apply (clarsimp simp add: Program (*‹P = Program P'›*) wf_mdecl_def (*‹wf_mdecl ?wf_md ?P ?C ≡ λ(M, Ts, T, m). (∀T∈set Ts. is_type ?P T) ∧ is_type ?P T ∧ (case m of None ⇒ ?C∙M(Ts) :: T | ⌊mb⌋ ⇒ ?wf_md ?P ?C (M, Ts, T, mb))›*) split del: option.split (*‹?P (case ?option of None ⇒ ?f1.0 | ⌊x⌋ ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = ⌊x2⌋ ⟶ ?P (?f2.0 x2)))›*)) (*top goal: ‹⋀(C::String.literal) (D::String.literal) (fs::fdecl list) ms::'a::type option mdecl list. ⟦(P::'a::type prog) = Program (P'::'a::type option cdecl list); (C, D, fs, ms) ∈ set P'; wf_syscls (Program P'); distinct_fst P'; case (C, D, fs, ms) of (C::String.literal, D::String.literal, fs::fdecl list, ms::'a::type option mdecl list) ⇒ (∀x::fdecl∈set fs. wf_fdecl (Program P') x) ∧ distinct_fst fs ∧ (∀x::'a::type option mdecl∈set ms. wf_mdecl (A::'a::type prog ⇒ String.literal ⇒ 'a::type mdecl ⇒ bool) (Program P') C x) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class (Program P') D ∧ ¬ Program P' ⊢ D ≼⇧* C ∧ (∀x::'a::type option mdecl∈set ms. wf_overriding (Program P') D x)) ∧ (C = Thread ⟶ (∃m::'a::type option. (run, [], Void, m) ∈ set ms)); is_class P C⟧ ⟹ (∀x::fdecl∈set fs. wf_fdecl (Program P') x) ∧ distinct_fst fs ∧ (∀x::'a::type option mdecl∈set ms. wf_mdecl (B::'a::type prog ⇒ String.literal ⇒ 'a::type mdecl ⇒ bool) (Program P') C x) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class (Program P') D ∧ ¬ Program P' ⊢ D ≼⇧* C ∧ (∀x::'a::type option mdecl∈set ms. wf_overriding (Program P') D x)) ∧ (C = Thread ⟶ (∃m::'a::type option. (run, [], Void, m) ∈ set ms))› and 1 goal remains*) apply (drule (1) bspec (*‹⟦∀x::?'a∈?A::?'a set. (?P::?'a ⇒ bool) x; (?x::?'a) ∈ ?A⟧ ⟹ ?P ?x›*)) (*top goal: ‹⋀C D fs ms a aa ab b. ⟦is_class (Program P') C; (C, D, fs, ms) ∈ set P'; wf_syscls (Program P'); distinct_fst P'; ∀x∈set fs. wf_fdecl (Program P') x; distinct_fst fs; ∀x∈set ms. case x of (M, Ts, ab) ⇒ (∀x∈set Ts. is_type (Program P') x) ∧ (case ab of (T, m) ⇒ ((∃y. m = ⌊y⌋) ∨ is_type (Program P') T ∧ C∙M(Ts) :: T) ∧ (∀x2. m = ⌊x2⌋ ⟶ is_type (Program P') T ∧ A (Program P') C (M, Ts, T, x2))); distinct_fst ms; C ≠ Object ⟶ is_class (Program P') D ∧ ¬ Program P' ⊢ D ≼⇧* C ∧ (∀x∈set ms. wf_overriding (Program P') D x); C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms); (a, aa, ab, b) ∈ set ms⟧ ⟹ (∀x∈set aa. is_type (Program P') x) ∧ is_type (Program P') ab ∧ (case b of None ⇒ C∙a(aa) :: ab | ⌊mb⌋ ⇒ B (Program P') C (a, aa, ab, mb))› and 1 goal remains*) apply clarsimp (*top goal: ‹⋀(C::String.literal) (D::String.literal) (fs::fdecl list) (ms::'a option mdecl list) (a::String.literal) (aa::ty list) (ab::ty) b::'a option. ⟦is_class (Program (P'::'a option cdecl list)) C; (C, D, fs, ms) ∈ set P'; wf_syscls (Program P'); distinct_fst P'; ∀x::fdecl∈set fs. wf_fdecl (Program P') x; distinct_fst fs; distinct_fst ms; C ≠ Object ⟶ is_class (Program P') D ∧ ¬ Program P' ⊢ D ≼⇧* C ∧ (∀x::'a option mdecl∈set ms. wf_overriding (Program P') D x); C = Thread ⟶ (∃m::'a option. (run, [], Void, m) ∈ set ms); (a, aa, ab, b) ∈ set ms; case (a, aa, ab, b) of (M::String.literal, Ts::ty list, ab::ty × 'a option) ⇒ (∀x::ty∈set Ts. is_type (Program P') x) ∧ (case ab of (T::ty, m::'a option) ⇒ ((∃y::'a. m = ⌊y⌋) ∨ is_type (Program P') T ∧ C∙M(Ts) :: T) ∧ (∀x2::'a. m = ⌊x2⌋ ⟶ is_type (Program P') T ∧ (A::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) (Program P') C (M, Ts, T, x2)))⟧ ⟹ (∀x::ty∈set aa. is_type (Program P') x) ∧ is_type (Program P') ab ∧ (case b of None ⇒ C∙a(aa) :: ab | ⌊mb::'a⌋ ⇒ (B::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) (Program P') C (a, aa, ab, mb))› and 1 goal remains*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹⋀(C::String.literal) (D::String.literal) (fs::fdecl list) (ms::'a option mdecl list) (a::String.literal) (aa::ty list) (ab::ty) b::'a option. ⟦is_class (Program (P'::'a option cdecl list)) C; (C, D, fs, ms) ∈ set P'; wf_syscls (Program P'); distinct_fst P'; ∀x::fdecl∈set fs. wf_fdecl (Program P') x; distinct_fst fs; distinct_fst ms; C ≠ Object ⟶ is_class (Program P') D ∧ ¬ Program P' ⊢ D ≼⇧* C ∧ (∀x::'a option mdecl∈set ms. wf_overriding (Program P') D x); C = Thread ⟶ (∃m::'a option. (run, [], Void, m) ∈ set ms); (a, aa, ab, b) ∈ set ms; ∀x::ty∈set aa. is_type (Program P') x; (∃y::'a. b = ⌊y⌋) ∨ is_type (Program P') ab ∧ C∙a(aa) :: ab; ∀x2::'a. b = ⌊x2⌋ ⟶ is_type (Program P') ab ∧ (A::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) (Program P') C (a, aa, ab, x2)⟧ ⟹ b = None ⟶ is_type (Program P') ab ∧ C∙a(aa) :: ab› 2. ‹⋀(C::String.literal) (D::String.literal) (fs::fdecl list) (ms::'a option mdecl list) (a::String.literal) (aa::ty list) (ab::ty) b::'a option. ⟦is_class (Program (P'::'a option cdecl list)) C; (C, D, fs, ms) ∈ set P'; wf_syscls (Program P'); distinct_fst P'; ∀x::fdecl∈set fs. wf_fdecl (Program P') x; distinct_fst fs; distinct_fst ms; C ≠ Object ⟶ is_class (Program P') D ∧ ¬ Program P' ⊢ D ≼⇧* C ∧ (∀x::'a option mdecl∈set ms. wf_overriding (Program P') D x); C = Thread ⟶ (∃m::'a option. (run, [], Void, m) ∈ set ms); (a, aa, ab, b) ∈ set ms; ∀x::ty∈set aa. is_type (Program P') x; (∃y::'a. b = ⌊y⌋) ∨ is_type (Program P') ab ∧ C∙a(aa) :: ab; ∀x2::'a. b = ⌊x2⌋ ⟶ is_type (Program P') ab ∧ (A::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) (Program P') C (a, aa, ab, x2)⟧ ⟹ ∀x2::'a. b = ⌊x2⌋ ⟶ (B::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) (Program P') C (a, aa, ab, x2)› discuss goal 1*) apply clarsimp (*discuss goal 2*) apply clarsimp (*top goal: ‹⋀C D fs ms a aa ab b. ⟦is_class (Program P') C; (C, D, fs, ms) ∈ set P'; wf_syscls (Program P'); distinct_fst P'; ∀x∈set fs. wf_fdecl (Program P') x; distinct_fst fs; distinct_fst ms; C ≠ Object ⟶ is_class (Program P') D ∧ ¬ Program P' ⊢ D ≼⇧* C ∧ (∀x∈set ms. wf_overriding (Program P') D x); C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms); (a, aa, ab, b) ∈ set ms; ∀x∈set aa. is_type (Program P') x; (∃y. b = ⌊y⌋) ∨ is_type (Program P') ab ∧ C∙a(aa) :: ab; ∀x2. b = ⌊x2⌋ ⟶ is_type (Program P') ab ∧ A (Program P') C (a, aa, ab, x2)⟧ ⟹ ∀x2. b = ⌊x2⌋ ⟶ B (Program P') C (a, aa, ab, x2)› and 1 goal remains*) apply (frule (1) map_of_SomeI (*‹⟦distinct_fst ?kxs; (?k, ?x) ∈ set ?kxs⟧ ⟹ map_of ?kxs ?k = ⌊?x⌋›*)) (*top goal: ‹⋀C D fs ms a aa ab x2. ⟦is_class (Program P') C; (C, D, fs, ms) ∈ set P'; wf_syscls (Program P'); distinct_fst P'; ∀x∈set fs. wf_fdecl (Program P') x; distinct_fst fs; distinct_fst ms; C ≠ Object ⟶ is_class (Program P') D ∧ ¬ Program P' ⊢ D ≼⇧* C ∧ (∀x∈set ms. wf_overriding (Program P') D x); C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms); (a, aa, ab, ⌊x2⌋) ∈ set ms; ∀x∈set aa. is_type (Program P') x; is_type (Program P') ab; A (Program P') C (a, aa, ab, x2)⟧ ⟹ B (Program P') C (a, aa, ab, x2)› and 1 goal remains*) apply (rule rule[OF wf, unfolded Program] (*‹⟦Program P' ⊢ ?Ca sees ?M: ?Ts→?T = ⌊?m⌋ in ?Ca; is_class (Program P') ?Ca; set ?Ts ⊆ types (Program P'); A (Program P') ?Ca (?M, ?Ts, ?T, ?m)⟧ ⟹ B (Program P') ?Ca (?M, ?Ts, ?T, ?m)›*)) (*goals: 1. ‹⋀C D fs ms a aa ab x2. ⟦is_class (Program P') C; (C, D, fs, ms) ∈ set P'; wf_syscls (Program P'); distinct_fst P'; ∀x∈set fs. wf_fdecl (Program P') x; distinct_fst fs; distinct_fst ms; C ≠ Object ⟶ is_class (Program P') D ∧ ¬ Program P' ⊢ D ≼⇧* C ∧ (∀x∈set ms. wf_overriding (Program P') D x); C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms); (a, aa, ab, ⌊x2⌋) ∈ set ms; ∀x∈set aa. is_type (Program P') x; is_type (Program P') ab; A (Program P') C (a, aa, ab, x2); map_of P' C = ⌊(D, fs, ms)⌋⟧ ⟹ Program P' ⊢ C sees a: aa→ab = ⌊x2⌋ in C› 2. ‹⋀C D fs ms a aa ab x2. ⟦is_class (Program P') C; (C, D, fs, ms) ∈ set P'; wf_syscls (Program P'); distinct_fst P'; ∀x∈set fs. wf_fdecl (Program P') x; distinct_fst fs; distinct_fst ms; C ≠ Object ⟶ is_class (Program P') D ∧ ¬ Program P' ⊢ D ≼⇧* C ∧ (∀x∈set ms. wf_overriding (Program P') D x); C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms); (a, aa, ab, ⌊x2⌋) ∈ set ms; ∀x∈set aa. is_type (Program P') x; is_type (Program P') ab; A (Program P') C (a, aa, ab, x2); map_of P' C = ⌊(D, fs, ms)⌋⟧ ⟹ is_class (Program P') C› 3. ‹⋀C D fs ms a aa ab x2. ⟦is_class (Program P') C; (C, D, fs, ms) ∈ set P'; wf_syscls (Program P'); distinct_fst P'; ∀x∈set fs. wf_fdecl (Program P') x; distinct_fst fs; distinct_fst ms; C ≠ Object ⟶ is_class (Program P') D ∧ ¬ Program P' ⊢ D ≼⇧* C ∧ (∀x∈set ms. wf_overriding (Program P') D x); C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms); (a, aa, ab, ⌊x2⌋) ∈ set ms; ∀x∈set aa. is_type (Program P') x; is_type (Program P') ab; A (Program P') C (a, aa, ab, x2); map_of P' C = ⌊(D, fs, ms)⌋⟧ ⟹ set aa ⊆ types (Program P')› 4. ‹⋀C D fs ms a aa ab x2. ⟦is_class (Program P') C; (C, D, fs, ms) ∈ set P'; wf_syscls (Program P'); distinct_fst P'; ∀x∈set fs. wf_fdecl (Program P') x; distinct_fst fs; distinct_fst ms; C ≠ Object ⟶ is_class (Program P') D ∧ ¬ Program P' ⊢ D ≼⇧* C ∧ (∀x∈set ms. wf_overriding (Program P') D x); C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms); (a, aa, ab, ⌊x2⌋) ∈ set ms; ∀x∈set aa. is_type (Program P') x; is_type (Program P') ab; A (Program P') C (a, aa, ab, x2); map_of P' C = ⌊(D, fs, ms)⌋⟧ ⟹ A (Program P') C (a, aa, ab, x2)› discuss goal 1*) apply (clarsimp simp add: is_class_def (*‹is_class ?P ?C ≡ class ?P ?C ≠ None›*)) (*top goal: ‹⋀(C::String.literal) (D::String.literal) (fs::fdecl list) (ms::'a option mdecl list) (a::String.literal) (aa::ty list) (ab::ty) x2::'a. ⟦is_class (Program (P'::'a option cdecl list)) C; (C, D, fs, ms) ∈ set P'; wf_syscls (Program P'); distinct_fst P'; ∀x::fdecl∈set fs. wf_fdecl (Program P') x; distinct_fst fs; distinct_fst ms; C ≠ Object ⟶ is_class (Program P') D ∧ ¬ Program P' ⊢ D ≼⇧* C ∧ (∀x::'a option mdecl∈set ms. wf_overriding (Program P') D x); C = Thread ⟶ (∃m::'a option. (run, [], Void, m) ∈ set ms); (a, aa, ab, ⌊x2⌋) ∈ set ms; ∀x::ty∈set aa. is_type (Program P') x; is_type (Program P') ab; (A::'a prog ⇒ String.literal ⇒ 'a mdecl ⇒ bool) (Program P') C (a, aa, ab, x2); map_of P' C = ⌊(D, fs, ms)⌋⟧ ⟹ Program P' ⊢ C sees a: aa→ab = ⌊x2⌋ in C› and 4 goals remain*) apply (rule mdecl_visible[OF wf[unfolded Program]] (*‹⟦class (Program P') ?C = ⌊(?S, ?fs, ?ms)⌋; (?M, ?Ts, ?T, ?m) ∈ set ?ms⟧ ⟹ Program P' ⊢ ?C sees ?M: ?Ts→?T = ?m in ?C›*)) (*goals: 1. ‹⋀C D fs ms a aa ab x2. ⟦(C, D, fs, ms) ∈ set P'; wf_syscls (Program P'); distinct_fst P'; ∀x∈set fs. wf_fdecl (Program P') x; distinct_fst fs; distinct_fst ms; C ≠ Object ⟶ (∃a aa b. map_of P' D = ⌊(a, aa, b)⌋) ∧ ¬ Program P' ⊢ D ≼⇧* C ∧ (∀x∈set ms. wf_overriding (Program P') D x); C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms); (a, aa, ab, ⌊x2⌋) ∈ set ms; ∀x∈set aa. is_type (Program P') x; is_type (Program P') ab; A (Program P') C (a, aa, ab, x2); map_of P' C = ⌊(D, fs, ms)⌋⟧ ⟹ class (Program P') C = ⌊(?S90 C D fs ms a aa ab x2, ?fs90 C D fs ms a aa ab x2, ?ms90 C D fs ms a aa ab x2)⌋› 2. ‹⋀C D fs ms a aa ab x2. ⟦(C, D, fs, ms) ∈ set P'; wf_syscls (Program P'); distinct_fst P'; ∀x∈set fs. wf_fdecl (Program P') x; distinct_fst fs; distinct_fst ms; C ≠ Object ⟶ (∃a aa b. map_of P' D = ⌊(a, aa, b)⌋) ∧ ¬ Program P' ⊢ D ≼⇧* C ∧ (∀x∈set ms. wf_overriding (Program P') D x); C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms); (a, aa, ab, ⌊x2⌋) ∈ set ms; ∀x∈set aa. is_type (Program P') x; is_type (Program P') ab; A (Program P') C (a, aa, ab, x2); map_of P' C = ⌊(D, fs, ms)⌋⟧ ⟹ (a, aa, ab, ⌊x2⌋) ∈ set (?ms90 C D fs ms a aa ab x2)› discuss goal 1*) apply (fastforce intro: is_type_pTs [OF wf, unfolded Program] (*‹⟦class (Program P') ?C = ⌊(?S, ?fs, ?ms)⌋; (?M, ?Ts, ?T, ?m) ∈ set ?ms⟧ ⟹ set ?Ts ⊆ types (Program P')›*)) (*discuss goal 2*) apply (fastforce intro: is_type_pTs [OF wf, unfolded Program] (*‹⟦class (Program P') ?C = ⌊(?S, ?fs, ?ms)⌋; (?M, ?Ts, ?T, ?m) ∈ set ?ms⟧ ⟹ set ?Ts ⊆ types (Program P')›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply (fastforce intro: is_type_pTs [OF wf, unfolded Program] (*‹⟦class (Program P') ?C = ⌊(?S, ?fs, ?ms)⌋; (?M, ?Ts, ?T, ?m) ∈ set ?ms⟧ ⟹ set ?Ts ⊆ types (Program P')›*)) (*discuss goal 3*) apply (fastforce intro: is_type_pTs [OF wf, unfolded Program] (*‹⟦class (Program P') ?C = ⌊(?S, ?fs, ?ms)⌋; (?M, ?Ts, ?T, ?m) ∈ set ?ms⟧ ⟹ set ?Ts ⊆ types (Program P')›*)) (*discuss goal 4*) apply (fastforce intro: is_type_pTs [OF wf, unfolded Program] (*‹⟦class (Program P') ?C = ⌊(?S, ?fs, ?ms)⌋; (?M, ?Ts, ?T, ?m) ∈ set ?ms⟧ ⟹ set ?Ts ⊆ types (Program P')›*)) (*proven 4 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply (simp add: is_class_def (*‹is_class ?P ?C ≡ class ?P ?C ≠ None›*)) (*goal: ‹⋀C D fs ms. ⟦P = Program P'; (C, D, fs, ms) ∈ set P'; wf_syscls (Program P'); distinct_fst P'; case (C, D, fs, ms) of (C, D, fs, ms) ⇒ (∀x∈set fs. wf_fdecl (Program P') x) ∧ distinct_fst fs ∧ (∀x∈set ms. wf_mdecl A (Program P') C x) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class (Program P') D ∧ ¬ Program P' ⊢ D ≼⇧* C ∧ (∀x∈set ms. wf_overriding (Program P') D x)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms))⟧ ⟹ is_class P C›*) apply (drule weak_map_of_SomeI (*‹(?k, ?x) ∈ set ?l ⟹ ∃x. map_of ?l ?k = ⌊x⌋›*)) (*goal: ‹⋀C D fs ms. ⟦P = Program P'; (C, D, fs, ms) ∈ set P'; wf_syscls (Program P'); distinct_fst P'; (∀x∈set fs. wf_fdecl (Program P') x) ∧ distinct_fst fs ∧ (∀x∈set ms. wf_mdecl A (Program P') C x) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ (∃a aa b. map_of P' D = ⌊(a, aa, b)⌋) ∧ ¬ Program P' ⊢ D ≼⇧* C ∧ (∀x∈set ms. wf_overriding (Program P') D x)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms))⟧ ⟹ ∃a aa b. map_of P' C = ⌊(a, aa, b)⌋›*) apply (simp add: Program (*‹P = Program P'›*)) (*proven 2 subgoals*) . qed subsection‹Well-formedness and field lookup› lemma wf_Fields_Ex: "⟦ wf_prog wf_md P; is_class P C ⟧ ⟹ ∃FDTs. P ⊢ C has_fields FDTs" (*<*) apply (frule class_Object (*‹wf_prog (?wf_md::?'a::type prog ⇒ String.literal ⇒ ?'a::type mdecl ⇒ bool) (?P::?'a::type prog) ⟹ ∃(C::String.literal) (fs::fdecl list) ms::?'a::type option mdecl list. class ?P Object = ⌊(C, fs, ms)⌋›*)) (*goal: ‹⟦wf_prog wf_md P; is_class P C⟧ ⟹ ∃FDTs. P ⊢ C has_fields FDTs›*) apply (erule (1) subcls1_induct (*‹⟦wf_prog ?wf_md ?P; is_class ?P ?C; ?Q Object; ⋀C D. ⟦C ≠ Object; ?P ⊢ C ≺¹ D; is_class ?P D; ?Q D⟧ ⟹ ?Q C⟧ ⟹ ?Q ?C›*)) (*goals: 1. ‹⟦is_class P C; ∃C fs ms. class P Object = ⌊(C, fs, ms)⌋⟧ ⟹ ∃FDTs. P ⊢ Object has_fields FDTs› 2. ‹⋀Ca D. ⟦is_class P C; ∃C fs ms. class P Object = ⌊(C, fs, ms)⌋; Ca ≠ Object; P ⊢ Ca ≺¹ D; is_class P D; ∃FDTs. P ⊢ D has_fields FDTs⟧ ⟹ ∃FDTs. P ⊢ Ca has_fields FDTs› discuss goal 1*) apply (blast intro:has_fields_Object (*‹⟦class ?P Object = ⌊(?D, ?fs, ?ms)⌋; ?FDTs = map (λ(F, T). ((F, Object), T)) ?fs⟧ ⟹ ?P ⊢ Object has_fields ?FDTs›*)) (*discuss goal 2*) apply (blast intro:has_fields_rec (*‹⟦class ?P ?C = ⌊(?D, ?fs, ?ms)⌋; ?C ≠ Object; ?P ⊢ ?D has_fields ?FDTs; ?FDTs' = map (λ(F, Tm). ((F, ?C), Tm)) ?fs @ ?FDTs⟧ ⟹ ?P ⊢ ?C has_fields ?FDTs'›*) dest:subcls1D (*‹?P ⊢ ?C ≺¹ ?D ⟹ ?C ≠ Object ∧ (∃fs ms. class ?P ?C = ⌊(?D, fs, ms)⌋)›*)) (*proven 2 subgoals*) . (*>*) lemma has_fields_types: "⟦ P ⊢ C has_fields FDTs; (FD, T, fm) ∈ set FDTs; wf_prog wf_md P ⟧ ⟹ is_type P T" (*<*) apply (induct rule:Fields.induct (*‹⟦?P ⊢ ?x1.0 has_fields ?x2.0; ⋀C D fs ms FDTs FDTs'. ⟦class ?P C = ⌊(D, fs, ms)⌋; C ≠ Object; ?P ⊢ D has_fields FDTs; ?Pa D FDTs; FDTs' = map (λ(F, Tm). ((F, C), Tm)) fs @ FDTs⟧ ⟹ ?Pa C FDTs'; ⋀D fs ms FDTs. ⟦class ?P Object = ⌊(D, fs, ms)⌋; FDTs = map (λ(F, T). ((F, Object), T)) fs⟧ ⟹ ?Pa Object FDTs⟧ ⟹ ?Pa ?x1.0 ?x2.0›*)) (*goals: 1. ‹⋀C D fs ms FDTs FDTs'. ⟦class P C = ⌊(D, fs, ms)⌋; C ≠ Object; P ⊢ D has_fields FDTs; ⟦(FD, T, fm) ∈ set FDTs; wf_prog wf_md P⟧ ⟹ is_type P T; FDTs' = map (λ(F, Tm). ((F, C), Tm)) fs @ FDTs; (FD, T, fm) ∈ set FDTs'; wf_prog wf_md P⟧ ⟹ is_type P T› 2. ‹⋀D fs ms FDTs. ⟦class P Object = ⌊(D, fs, ms)⌋; FDTs = map (λ(F, T). ((F, Object), T)) fs; (FD, T, fm) ∈ set FDTs; wf_prog wf_md P⟧ ⟹ is_type P T› discuss goal 1*) apply (fastforce dest!: class_wf (*‹⟦class ?P ?C = ⌊?c⌋; wf_prog ?wf_md ?P⟧ ⟹ wf_cdecl ?wf_md ?P (?C, ?c)›*) simp: wf_cdecl_def (*‹wf_cdecl ?wf_md ?P ≡ λ(C, D, fs, ms). (∀f∈set fs. wf_fdecl ?P f) ∧ distinct_fst fs ∧ (∀m∈set ms. wf_mdecl ?wf_md ?P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class ?P D ∧ ¬ ?P ⊢ D ≼⇧* C ∧ (∀m∈set ms. wf_overriding ?P D m)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms))›*) wf_fdecl_def (*‹wf_fdecl ?P ≡ λ(F, T, fm). is_type ?P T›*)) (*discuss goal 2*) apply (fastforce dest!: class_wf (*‹⟦class ?P ?C = ⌊?c⌋; wf_prog ?wf_md ?P⟧ ⟹ wf_cdecl ?wf_md ?P (?C, ?c)›*) simp: wf_cdecl_def (*‹wf_cdecl ?wf_md ?P ≡ λ(C, D, fs, ms). (∀f∈set fs. wf_fdecl ?P f) ∧ distinct_fst fs ∧ (∀m∈set ms. wf_mdecl ?wf_md ?P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class ?P D ∧ ¬ ?P ⊢ D ≼⇧* C ∧ (∀m∈set ms. wf_overriding ?P D m)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms))›*) wf_fdecl_def (*‹wf_fdecl ?P ≡ λ(F, T, fm). is_type ?P T›*)) (*proven 2 subgoals*) . (*>*) lemma sees_field_is_type: "⟦ P ⊢ C sees F:T (fm) in D; wf_prog wf_md P ⟧ ⟹ is_type P T" by (fastforce simp: sees_field_def (*‹(?P::?'m::type prog) ⊢ (?C::String.literal) sees (?F::String.literal):(?T::ty) ((?fm::fmod)) in (?D::String.literal) ≡ ∃FDTs::((String.literal × String.literal) × ty × fmod) list. ?P ⊢ ?C has_fields FDTs ∧ map_of (map (λ((F::String.literal, D::String.literal), Tm::ty × fmod). (F, D, Tm)) FDTs) ?F = ⌊(?D, ?T, ?fm)⌋›*) elim: has_fields_types (*‹⟦(?P::?'a::type prog) ⊢ (?C::String.literal) has_fields (?FDTs::((String.literal × String.literal) × ty × fmod) list); (?FD::String.literal × String.literal, ?T::ty, ?fm::fmod) ∈ set ?FDTs; wf_prog (?wf_md::?'a::type prog ⇒ String.literal ⇒ ?'a::type mdecl ⇒ bool) ?P⟧ ⟹ is_type ?P ?T›*) map_of_SomeD[OF map_of_remap_SomeD] (*‹map_of (map (λ((k::?'c1::type, k'::?'a1::type), x::?'a::type). (k, k', x)) (?xs::((?'c1::type × ?'a1::type) × ?'a::type) list)) (?k1::?'c1::type) = ⌊(?k'1::?'a1::type, ?y::?'a::type)⌋ ⟹ ((?k1, ?k'1), ?y) ∈ set ?xs›*)) lemma wf_has_field_mono2: assumes wf: "wf_prog wf_md P" and has: "P ⊢ C has F:T (fm) in E" shows "⟦ P ⊢ C ≼⇧* D; P ⊢ D ≼⇧* E ⟧ ⟹ P ⊢ D has F:T (fm) in E" proof (induct rule: rtranclp_induct (*‹⟦?r⇧*⇧* ?a ?b; ?P ?a; ⋀y z. ⟦?r⇧*⇧* ?a y; ?r y z; ?P y⟧ ⟹ ?P z⟧ ⟹ ?P ?b›*)) (*goals: 1. ‹P ⊢ C ≼⇧* E ⟹ P ⊢ C has F:T (fm) in E› 2. ‹⋀y z. ⟦P ⊢ C ≼⇧* y; P ⊢ y ≺¹ z; P ⊢ y ≼⇧* E ⟹ P ⊢ y has F:T (fm) in E; P ⊢ z ≼⇧* E⟧ ⟹ P ⊢ z has F:T (fm) in E›*) case base (*‹P ⊢ C ≼⇧* E›*) show "?case" (*goal: ‹P ⊢ C has F:T (fm) in E›*) using has (*‹P ⊢ C has F:T (fm) in E›*) . next (*goal: ‹⋀y z. ⟦P ⊢ C ≼⇧* y; P ⊢ y ≺¹ z; P ⊢ y ≼⇧* E ⟹ P ⊢ y has F:T (fm) in E; P ⊢ z ≼⇧* E⟧ ⟹ P ⊢ z has F:T (fm) in E›*) case (step D D') (*‹P ⊢ C ≼⇧* D› ‹P ⊢ D ≺¹ D'› ‹P ⊢ D ≼⇧* E ⟹ P ⊢ D has F:T (fm) in E› ‹P ⊢ D' ≼⇧* E›*) note DsubD' = ‹P ⊢ D ≺¹ D'› (*‹P ⊢ D ≺¹ D'›*) from DsubD' (*‹P ⊢ D ≺¹ D'›*) obtain rest where classD: "class P D = ⌊(D', rest)⌋" and DObj: "D ≠ Object" (*goal: ‹(⋀rest. ⟦class P D = ⌊(D', rest)⌋; D ≠ Object⟧ ⟹ thesis) ⟹ thesis›*) by (auto elim!: subcls1.cases (*‹⟦?P ⊢ ?a1.0 ≺¹ ?a2.0; ⋀C D rest. ⟦?a1.0 = C; ?a2.0 = D; class ?P C = ⌊(D, rest)⌋; C ≠ Object⟧ ⟹ ?Pa⟧ ⟹ ?Pa›*)) from DsubD' (*‹P ⊢ D ≺¹ D'›*) ‹P ⊢ D' ≼⇧* E› (*‹P ⊢ D' ≼⇧* E›*) have DsubE: "P ⊢ D ≼⇧* E" and DsubE2: "(subcls1 P)^++ D E" apply - (*goals: 1. ‹⟦P ⊢ D ≺¹ D'; P ⊢ D' ≼⇧* E⟧ ⟹ P ⊢ D ≼⇧* E› 2. ‹⟦P ⊢ D ≺¹ D'; P ⊢ D' ≼⇧* E⟧ ⟹ (subcls1 P)⁺⁺ D E› discuss goal 1*) apply (rule converse_rtranclp_into_rtranclp (*‹⟦?r ?a ?b; ?r⇧*⇧* ?b ?c⟧ ⟹ ?r⇧*⇧* ?a ?c›*) rtranclp_into_tranclp2 (*‹⟦?r ?a ?b; ?r⇧*⇧* ?b ?c⟧ ⟹ ?r⁺⁺ ?a ?c›*)) (*goals: 1. ‹⟦(P::'a prog) ⊢ (D::String.literal) ≺¹ (D'::String.literal); P ⊢ D' ≼⇧* (E::String.literal)⟧ ⟹ P ⊢ D ≺¹ (?b4::String.literal)› 2. ‹⟦(P::'a prog) ⊢ (D::String.literal) ≺¹ (D'::String.literal); P ⊢ D' ≼⇧* (E::String.literal)⟧ ⟹ P ⊢ (?b4::String.literal) ≼⇧* E› discuss goal 1*) apply ((msorry)[1]) (*discuss goal 2*) apply ((msorry)[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply ((msorry)[1]) (*proven 2 subgoals*) . from wf (*‹wf_prog wf_md P›*) DsubE2 (*‹(subcls1 (P::'a prog))⁺⁺ (D::String.literal) (E::String.literal)›*) have DnE: "D ≠ E" by (rule subcls_irrefl (*‹⟦wf_prog ?wf_md ?P; (subcls1 ?P)⁺⁺ ?C ?D⟧ ⟹ ?C ≠ ?D›*)) from DsubE (*‹P ⊢ D ≼⇧* E›*) have hasD: "P ⊢ D has F:T (fm) in E" by (rule ‹P ⊢ D ≼⇧* E ⟹ P ⊢ D has F:T (fm) in E›) then obtain FDTs where hasf: "P ⊢ D has_fields FDTs" and FE: "map_of FDTs (F, E) = ⌊(T, fm)⌋" (*goal: ‹(⋀FDTs::((String.literal × String.literal) × ty × fmod) list. ⟦(P::'a prog) ⊢ (D::String.literal) has_fields FDTs; map_of FDTs (F::String.literal, E::String.literal) = ⌊(T::ty, fm::fmod)⌋⟧ ⟹ thesis::bool) ⟹ thesis›*) unfolding has_field_def (*goal: ‹(⋀FDTs::((String.literal × String.literal) × ty × fmod) list. ⟦(P::'a prog) ⊢ (D::String.literal) has_fields FDTs; map_of FDTs (F::String.literal, E::String.literal) = ⌊(T::ty, fm::fmod)⌋⟧ ⟹ thesis::bool) ⟹ thesis›*) by blast from hasf (*‹(P::'a prog) ⊢ (D::String.literal) has_fields (FDTs::((String.literal × String.literal) × ty × fmod) list)›*) show "?case" (*goal: ‹P ⊢ D' has F:T (fm) in E›*) proof (cases) (*goals: 1. ‹⋀D fs ms FDTsa. ⟦class P D = ⌊(D, fs, ms)⌋; D ≠ Object; P ⊢ D has_fields FDTsa; FDTs = map (λ(F, y). ((F, D), y)) fs @ FDTsa⟧ ⟹ P ⊢ D' has F:T (fm) in E› 2. ‹⋀D fs ms. ⟦D = Object; class P Object = ⌊(D, fs, ms)⌋; FDTs = map (λ(F, y). ((F, Object), y)) fs⟧ ⟹ P ⊢ D' has F:T (fm) in E›*) case has_fields_Object (*‹(D::String.literal) = Object› ‹class P Object = ⌊(D_, fs_, ms_)⌋› ‹FDTs = map (λ(F, y). ((F, Object), y)) fs_›*) with DObj (*‹D ≠ Object›*) show "?thesis" (*goal: ‹P ⊢ D' has F:T (fm) in E›*) by simp next (*goal: ‹⋀D fs ms FDTsa. ⟦class P D = ⌊(D, fs, ms)⌋; D ≠ Object; P ⊢ D has_fields FDTsa; FDTs = map (λ(F, y). ((F, D), y)) fs @ FDTsa⟧ ⟹ P ⊢ D' has F:T (fm) in E›*) case (has_fields_rec DD' fs ms FDTs') (*‹class P D = ⌊(DD', fs, ms)⌋› ‹D ≠ Object› ‹(P::'a prog) ⊢ (DD'::String.literal) has_fields (FDTs'::((String.literal × String.literal) × ty × fmod) list)› ‹(FDTs::((String.literal × String.literal) × ty × fmod) list) = map (λ(F::String.literal, y::ty × fmod). ((F, D::String.literal), y)) (fs::fdecl list) @ (FDTs'::((String.literal × String.literal) × ty × fmod) list)›*) with classD (*‹class (P::'a prog) (D::String.literal) = ⌊(D'::String.literal, rest::fdecl list × 'a option mdecl list)⌋›*) have [simp]: "DD' = D'" "rest = (fs, ms)" and hasf': "P ⊢ D' has_fields FDTs'" and FDTs: "FDTs = map (λ(F, Tm). ((F, D), Tm)) fs @ FDTs'" apply - (*goals: 1. ‹⟦class P D = ⌊(D', rest)⌋; class P D = ⌊(DD', fs, ms)⌋; D ≠ Object; P ⊢ DD' has_fields FDTs'; FDTs = map (λ(F, y). ((F, D), y)) fs @ FDTs'⟧ ⟹ DD' = D'› 2. ‹⟦class P D = ⌊(D', rest)⌋; class P D = ⌊(DD', fs, ms)⌋; D ≠ Object; P ⊢ DD' has_fields FDTs'; FDTs = map (λ(F, y). ((F, D), y)) fs @ FDTs'⟧ ⟹ rest = (fs, ms)› 3. ‹⟦class P D = ⌊(D', rest)⌋; class P D = ⌊(DD', fs, ms)⌋; D ≠ Object; P ⊢ DD' has_fields FDTs'; FDTs = map (λ(F, y). ((F, D), y)) fs @ FDTs'⟧ ⟹ P ⊢ D' has_fields FDTs'› 4. ‹⟦class P D = ⌊(D', rest)⌋; class P D = ⌊(DD', fs, ms)⌋; D ≠ Object; P ⊢ DD' has_fields FDTs'; FDTs = map (λ(F, y). ((F, D), y)) fs @ FDTs'⟧ ⟹ FDTs = map (λ(F, Tm). ((F, D), Tm)) fs @ FDTs'› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . from FDTs (*‹(FDTs::((String.literal × String.literal) × ty × fmod) list) = map (λ(F::String.literal, Tm::ty × fmod). ((F, D::String.literal), Tm)) (fs::fdecl list) @ (FDTs'::((String.literal × String.literal) × ty × fmod) list)›*) FE (*‹map_of (FDTs::((String.literal × String.literal) × ty × fmod) list) (F::String.literal, E::String.literal) = ⌊(T::ty, fm::fmod)⌋›*) DnE (*‹D ≠ E›*) hasf' (*‹P ⊢ D' has_fields FDTs'›*) show "?thesis" (*goal: ‹P ⊢ D' has F:T (fm) in E›*) by (auto dest: map_of_SomeD (*‹map_of ?xs ?k = ⌊?y⌋ ⟹ (?k, ?y) ∈ set ?xs›*) simp add: has_field_def (*‹?P ⊢ ?C has ?F:?T (?fm) in ?D ≡ ∃FDTs. ?P ⊢ ?C has_fields FDTs ∧ map_of FDTs (?F, ?D) = ⌊(?T, ?fm)⌋›*)) qed qed lemma wf_has_field_idemp: "⟦ wf_prog wf_md P; P ⊢ C has F:T (fm) in D ⟧ ⟹ P ⊢ D has F:T (fm) in D" apply (frule has_field_decl_above (*‹?P ⊢ ?C has ?F:?T (?fm) in ?D ⟹ ?P ⊢ ?C ≼⇧* ?D›*)) (*goal: ‹⟦wf_prog wf_md P; P ⊢ C has F:T (fm) in D⟧ ⟹ P ⊢ D has F:T (fm) in D›*) apply (erule (2) wf_has_field_mono2 (*‹⟦wf_prog ?wf_md ?P; ?P ⊢ ?C has ?F:?T (?fm) in ?E; ?P ⊢ ?C ≼⇧* ?D; ?P ⊢ ?D ≼⇧* ?E⟧ ⟹ ?P ⊢ ?D has ?F:?T (?fm) in ?E›*)) (*goal: ‹⟦wf_prog wf_md P; P ⊢ C has F:T (fm) in D; P ⊢ C ≼⇧* D⟧ ⟹ P ⊢ D has F:T (fm) in D›*) by (rule rtranclp.rtrancl_refl (*‹?r⇧*⇧* ?a ?a›*)) lemma map_of_remap_conv: "⟦ distinct_fst fs; map_of (map (λ(F, y). ((F, D), y)) fs) (F, D) = ⌊T⌋ ⟧ ⟹ map_of (map (λ((F, D), T). (F, D, T)) (map (λ(F, y). ((F, D), y)) fs)) F = ⌊(D, T)⌋" apply (induct fs) (*goals: 1. ‹⟦distinct_fst []; map_of (map (λ(F, y). ((F, D), y)) []) (F, D) = ⌊T⌋⟧ ⟹ map_of (map (λ((F, D), T). (F, D, T)) (map (λ(F, y). ((F, D), y)) [])) F = ⌊(D, T)⌋› 2. ‹⋀a fs. ⟦⟦distinct_fst fs; map_of (map (λ(F, y). ((F, D), y)) fs) (F, D) = ⌊T⌋⟧ ⟹ map_of (map (λ((F, D), T). (F, D, T)) (map (λ(F, y). ((F, D), y)) fs)) F = ⌊(D, T)⌋; distinct_fst (a # fs); map_of (map (λ(F, y). ((F, D), y)) (a # fs)) (F, D) = ⌊T⌋⟧ ⟹ map_of (map (λ((F, D), T). (F, D, T)) (map (λ(F, y). ((F, D), y)) (a # fs))) F = ⌊(D, T)⌋› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma has_field_idemp_sees_field: assumes wf: "wf_prog wf_md P" and has: "P ⊢ D has F:T (fm) in D" shows "P ⊢ D sees F:T (fm) in D" proof (-) (*goal: ‹P ⊢ D sees F:T (fm) in D›*) from has (*‹P ⊢ D has F:T (fm) in D›*) obtain FDTs where hasf: "P ⊢ D has_fields FDTs" and FD: "map_of FDTs (F, D) = ⌊(T, fm)⌋" (*goal: ‹(⋀FDTs. ⟦P ⊢ D has_fields FDTs; map_of FDTs (F, D) = ⌊(T, fm)⌋⟧ ⟹ thesis) ⟹ thesis›*) unfolding has_field_def (*goal: ‹(⋀FDTs. ⟦P ⊢ D has_fields FDTs; map_of FDTs (F, D) = ⌊(T, fm)⌋⟧ ⟹ thesis) ⟹ thesis›*) by blast from hasf (*‹P ⊢ D has_fields FDTs›*) have "map_of (map (λ((F, D), T). (F, D, T)) FDTs) F = ⌊(D, T, fm)⌋" proof (cases) (*goals: 1. ‹⋀Da fs ms FDTsa. ⟦class P D = ⌊(Da, fs, ms)⌋; D ≠ Object; P ⊢ Da has_fields FDTsa; FDTs = map (λ(F, y). ((F, D), y)) fs @ FDTsa⟧ ⟹ map_of (map (λ((F, D), T). (F, D, T)) FDTs) F = ⌊(D, T, fm)⌋› 2. ‹⋀Da fs ms. ⟦D = Object; class P Object = ⌊(Da, fs, ms)⌋; FDTs = map (λ(F, y). ((F, Object), y)) fs⟧ ⟹ map_of (map (λ((F, D), T). (F, D, T)) FDTs) F = ⌊(D, T, fm)⌋›*) case (has_fields_Object D' fs ms) (*‹(D::String.literal) = Object› ‹class P Object = ⌊(D', fs, ms)⌋› ‹FDTs = map (λ(F, y). ((F, Object), y)) fs›*) from ‹class P Object = ⌊(D', fs, ms)⌋› (*‹class P Object = ⌊(D', fs, ms)⌋›*) wf (*‹wf_prog wf_md P›*) have "wf_cdecl wf_md P (Object, D', fs, ms)" by (rule class_wf (*‹⟦class ?P ?C = ⌊?c⌋; wf_prog ?wf_md ?P⟧ ⟹ wf_cdecl ?wf_md ?P (?C, ?c)›*)) hence "distinct_fst fs" by (simp add: wf_cdecl_def (*‹wf_cdecl (?wf_md::?'m prog ⇒ String.literal ⇒ ?'m mdecl ⇒ bool) (?P::?'m prog) ≡ λ(C::String.literal, D::String.literal, fs::fdecl list, ms::?'m option mdecl list). (∀f::fdecl∈set fs. wf_fdecl ?P f) ∧ distinct_fst fs ∧ (∀m::?'m option mdecl∈set ms. wf_mdecl ?wf_md ?P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class ?P D ∧ ¬ ?P ⊢ D ≼⇧* C ∧ (∀m::?'m option mdecl∈set ms. wf_overriding ?P D m)) ∧ (C = Thread ⟶ (∃m::?'m option. (run, [], Void, m) ∈ set ms))›*)) with FD (*‹map_of FDTs (F, D) = ⌊(T, fm)⌋›*) has_fields_Object (*‹(D::String.literal) = Object› ‹class P Object = ⌊(D', fs, ms)⌋› ‹FDTs = map (λ(F, y). ((F, Object), y)) fs›*) show "?thesis" (*goal: ‹map_of (map (λ((F, D), T). (F, D, T)) FDTs) F = ⌊(D, T, fm)⌋›*) by (auto intro: map_of_remap_conv (*‹⟦distinct_fst ?fs; map_of (map (λ(F, y). ((F, ?D), y)) ?fs) (?F, ?D) = ⌊?T⌋⟧ ⟹ map_of (map (λ((F, D), T). (F, D, T)) (map (λ(F, y). ((F, ?D), y)) ?fs)) ?F = ⌊(?D, ?T)⌋›*) simp del: map_map (*‹map ?f (map ?g ?xs) = map (?f ∘ ?g) ?xs›*)) next (*goal: ‹⋀Da fs ms FDTsa. ⟦class P D = ⌊(Da, fs, ms)⌋; D ≠ Object; P ⊢ Da has_fields FDTsa; FDTs = map (λ(F, y). ((F, D), y)) fs @ FDTsa⟧ ⟹ map_of (map (λ((F, D), T). (F, D, T)) FDTs) F = ⌊(D, T, fm)⌋›*) case (has_fields_rec D' fs ms FDTs') (*‹class P D = ⌊(D', fs, ms)⌋› ‹(D::String.literal) ≠ Object› ‹P ⊢ D' has_fields FDTs'› ‹FDTs = map (λ(F, y). ((F, D), y)) fs @ FDTs'›*) hence [simp]: "FDTs = map (λ(F, Tm). ((F, D), Tm)) fs @ FDTs'" and classD: "class P D = ⌊(D', fs, ms)⌋" and DnObj: "D ≠ Object" and hasf': "P ⊢ D' has_fields FDTs'" apply - (*goals: 1. ‹⟦class P D = ⌊(D', fs, ms)⌋; D ≠ Object; P ⊢ D' has_fields FDTs'; FDTs = map (λ(F, y). ((F, D), y)) fs @ FDTs'⟧ ⟹ FDTs = map (λ(F, Tm). ((F, D), Tm)) fs @ FDTs'› 2. ‹⟦class P D = ⌊(D', fs, ms)⌋; D ≠ Object; P ⊢ D' has_fields FDTs'; FDTs = map (λ(F, y). ((F, D), y)) fs @ FDTs'⟧ ⟹ class P D = ⌊(D', fs, ms)⌋› 3. ‹⟦class P D = ⌊(D', fs, ms)⌋; D ≠ Object; P ⊢ D' has_fields FDTs'; FDTs = map (λ(F, y). ((F, D), y)) fs @ FDTs'⟧ ⟹ D ≠ Object› 4. ‹⟦class P D = ⌊(D', fs, ms)⌋; D ≠ Object; P ⊢ D' has_fields FDTs'; FDTs = map (λ(F, y). ((F, D), y)) fs @ FDTs'⟧ ⟹ P ⊢ D' has_fields FDTs'› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . from ‹class P D = ⌊(D', fs, ms)⌋› (*‹class P D = ⌊(D', fs, ms)⌋›*) wf (*‹wf_prog wf_md P›*) have "wf_cdecl wf_md P (D, D', fs, ms)" by (rule class_wf (*‹⟦class ?P ?C = ⌊?c⌋; wf_prog ?wf_md ?P⟧ ⟹ wf_cdecl ?wf_md ?P (?C, ?c)›*)) hence "distinct_fst fs" by (simp add: wf_cdecl_def (*‹wf_cdecl ?wf_md ?P ≡ λ(C, D, fs, ms). (∀f∈set fs. wf_fdecl ?P f) ∧ distinct_fst fs ∧ (∀m∈set ms. wf_mdecl ?wf_md ?P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class ?P D ∧ ¬ ?P ⊢ D ≼⇧* C ∧ (∀m∈set ms. wf_overriding ?P D m)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms))›*)) moreover have "map_of FDTs' (F, D) = None" proof (rule ccontr (*‹(¬ (?P::bool) ⟹ False) ⟹ ?P›*)) (*goal: ‹map_of FDTs' (F, D) ≠ None ⟹ False›*) assume "map_of FDTs' (F, D) ≠ None" (*‹map_of (FDTs'::((String.literal × String.literal) × ty × fmod) list) (F::String.literal, D::String.literal) ≠ None›*) then obtain T' and fm' where "map_of FDTs' (F, D) = ⌊(T', fm')⌋" (*goal: ‹(⋀T' fm'. map_of FDTs' (F, D) = ⌊(T', fm')⌋ ⟹ thesis) ⟹ thesis›*) by auto with hasf' (*‹P ⊢ D' has_fields FDTs'›*) have "P ⊢ D' ≼⇧* D" by (auto dest!: map_of_SomeD (*‹map_of (?xs::(?'b × ?'a) list) (?k::?'b) = ⌊?y::?'a⌋ ⟹ (?k, ?y) ∈ set ?xs›*) intro: has_fields_decl_above (*‹⟦(?P::?'a prog) ⊢ (?C::String.literal) has_fields (?FDTs::((String.literal × String.literal) × ty × fmod) list); ((?F::String.literal, ?D::String.literal), ?Tm::ty × fmod) ∈ set ?FDTs⟧ ⟹ ?P ⊢ ?C ≼⇧* ?D›*)) with classD (*‹class (P::'a prog) (D::String.literal) = ⌊(D'::String.literal, fs::fdecl list, ms::'a option mdecl list)⌋›*) DnObj (*‹D ≠ Object›*) have "(subcls1 P)^++ D D" by (auto intro: subcls1.intros (*‹⟦class ?P ?C = ⌊(?D, ?rest)⌋; ?C ≠ Object⟧ ⟹ ?P ⊢ ?C ≺¹ ?D›*) rtranclp_into_tranclp2 (*‹⟦?r ?a ?b; ?r⇧*⇧* ?b ?c⟧ ⟹ ?r⁺⁺ ?a ?c›*)) with wf (*‹wf_prog wf_md P›*) show False by (auto dest: subcls_irrefl (*‹⟦wf_prog ?wf_md ?P; (subcls1 ?P)⁺⁺ ?C ?D⟧ ⟹ ?C ≠ ?D›*)) qed ultimately show "?thesis" (*goal: ‹map_of (map (λ((F, D), T). (F, D, T)) FDTs) F = ⌊(D, T, fm)⌋›*) using FD (*‹map_of FDTs (F, D) = ⌊(T, fm)⌋›*) hasf' (*‹(P::'a prog) ⊢ (D'::String.literal) has_fields (FDTs'::((String.literal × String.literal) × ty × fmod) list)›*) by (auto simp add: map_add_Some_iff (*‹((?m ++ ?n) ?k = ⌊?x⌋) = (?n ?k = ⌊?x⌋ ∨ ?n ?k = None ∧ ?m ?k = ⌊?x⌋)›*) intro: map_of_remap_conv (*‹⟦distinct_fst ?fs; map_of (map (λ(F, y). ((F, ?D), y)) ?fs) (?F, ?D) = ⌊?T⌋⟧ ⟹ map_of (map (λ((F, D), T). (F, D, T)) (map (λ(F, y). ((F, ?D), y)) ?fs)) ?F = ⌊(?D, ?T)⌋›*) simp del: map_map (*‹map ?f (map ?g ?xs) = map (?f ∘ ?g) ?xs›*)) qed with hasf (*‹(P::'a prog) ⊢ (D::String.literal) has_fields (FDTs::((String.literal × String.literal) × ty × fmod) list)›*) show "?thesis" (*goal: ‹P ⊢ D sees F:T (fm) in D›*) unfolding sees_field_def (*goal: ‹∃FDTs::((String.literal × String.literal) × ty × fmod) list. (P::'a::type prog) ⊢ (D::String.literal) has_fields FDTs ∧ map_of (map (λ((F::String.literal, D::String.literal), Tm::ty × fmod). (F, D, Tm)) FDTs) (F::String.literal) = ⌊(D, T::ty, fm::fmod)⌋›*) by blast qed lemma has_fields_distinct: assumes wf: "wf_prog wf_md P" and "P ⊢ C has_fields FDTs" shows "distinct (map fst FDTs)" using ‹P ⊢ C has_fields FDTs› (*‹P ⊢ C has_fields FDTs›*) proof (induct) (*goals: 1. ‹⋀C D fs ms FDTs FDTs'. ⟦class P C = ⌊(D, fs, ms)⌋; C ≠ Object; P ⊢ D has_fields FDTs; distinct (map fst FDTs); FDTs' = map (λ(F, Tm). ((F, C), Tm)) fs @ FDTs⟧ ⟹ distinct (map fst FDTs')› 2. ‹⋀D fs ms FDTs. ⟦class P Object = ⌊(D, fs, ms)⌋; FDTs = map (λ(F, T). ((F, Object), T)) fs⟧ ⟹ distinct (map fst FDTs)›*) case (has_fields_Object D fs ms FDTs) (*‹class P Object = ⌊(D, fs, ms)⌋› ‹FDTs = map (λ(F, T). ((F, Object), T)) fs›*) have eq: "map (fst ∘ (λ(F, y). ((F, Object), y))) fs = map ((λF. (F, Object)) ∘ fst) fs" by auto from ‹class P Object = ⌊(D, fs, ms)⌋› (*‹class P Object = ⌊(D, fs, ms)⌋›*) wf (*‹wf_prog wf_md P›*) have "wf_cdecl wf_md P (Object, D, fs, ms)" by (rule class_wf (*‹⟦class ?P ?C = ⌊?c⌋; wf_prog ?wf_md ?P⟧ ⟹ wf_cdecl ?wf_md ?P (?C, ?c)›*)) hence "distinct (map fst fs)" by (simp add: wf_cdecl_def (*‹wf_cdecl ?wf_md ?P ≡ λ(C, D, fs, ms). (∀f∈set fs. wf_fdecl ?P f) ∧ distinct_fst fs ∧ (∀m∈set ms. wf_mdecl ?wf_md ?P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class ?P D ∧ ¬ ?P ⊢ D ≼⇧* C ∧ (∀m∈set ms. wf_overriding ?P D m)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms))›*) distinct_fst_def (*‹distinct_fst ≡ distinct ∘ map fst›*)) hence "distinct (map (fst ∘ (λ(F, y). ((F, Object), y))) fs)" unfolding eq distinct_map (*goal: ‹distinct fs ∧ inj_on ((λF. (F, Object)) ∘ fst) (set fs)›*) by (auto intro: comp_inj_on (*‹⟦inj_on (?f::?'a ⇒ ?'b) (?A::?'a set); inj_on (?g::?'b ⇒ ?'c) (?f ` ?A)⟧ ⟹ inj_on (?g ∘ ?f) ?A›*) inj_onI (*‹(⋀(x::?'a) y::?'a. ⟦x ∈ (?A::?'a set); y ∈ ?A; (?f::?'a ⇒ ?'b) x = ?f y⟧ ⟹ x = y) ⟹ inj_on ?f ?A›*)) thus "?case" (*goal: ‹distinct (map fst FDTs)›*) using ‹FDTs = map (λ(F, T). ((F, Object), T)) fs› (*‹FDTs = map (λ(F, T). ((F, Object), T)) fs›*) by simp next (*goal: ‹⋀(C::String.literal) (D::String.literal) (fs::fdecl list) (ms::'a option mdecl list) (FDTs::((String.literal × String.literal) × ty × fmod) list) FDTs'::((String.literal × String.literal) × ty × fmod) list. ⟦class (P::'a prog) C = ⌊(D, fs, ms)⌋; C ≠ Object; P ⊢ D has_fields FDTs; distinct (map fst FDTs); FDTs' = map (λ(F::String.literal, Tm::ty × fmod). ((F, C), Tm)) fs @ FDTs⟧ ⟹ distinct (map fst FDTs')›*) case (has_fields_rec C D fs ms FDTs FDTs') (*‹class P C = ⌊(D, fs, ms)⌋› ‹C ≠ Object› ‹(P::'a prog) ⊢ (D::String.literal) has_fields (FDTs::((String.literal × String.literal) × ty × fmod) list)› ‹distinct (map fst FDTs)› ‹FDTs' = map (λ(F, Tm). ((F, C), Tm)) fs @ FDTs›*) have eq: "map (fst ∘ (λ(F, y). ((F, C), y))) fs = map ((λF. (F, C)) ∘ fst) fs" by auto from ‹class P C = ⌊(D, fs, ms)⌋› (*‹class P C = ⌊(D, fs, ms)⌋›*) wf (*‹wf_prog wf_md P›*) have "wf_cdecl wf_md P (C, D, fs, ms)" by (rule class_wf (*‹⟦class ?P ?C = ⌊?c⌋; wf_prog ?wf_md ?P⟧ ⟹ wf_cdecl ?wf_md ?P (?C, ?c)›*)) hence "distinct (map fst fs)" by (simp add: wf_cdecl_def (*‹wf_cdecl ?wf_md ?P ≡ λ(C, D, fs, ms). (∀f∈set fs. wf_fdecl ?P f) ∧ distinct_fst fs ∧ (∀m∈set ms. wf_mdecl ?wf_md ?P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class ?P D ∧ ¬ ?P ⊢ D ≼⇧* C ∧ (∀m∈set ms. wf_overriding ?P D m)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms))›*) distinct_fst_def (*‹distinct_fst ≡ distinct ∘ map fst›*)) hence "distinct (map (fst ∘ (λ(F, y). ((F, C), y))) fs)" unfolding eq distinct_map (*goal: ‹distinct fs ∧ inj_on ((λF. (F, C)) ∘ fst) (set fs)›*) by (auto intro: comp_inj_on (*‹⟦inj_on (?f::?'a::type ⇒ ?'b::type) (?A::?'a::type set); inj_on (?g::?'b::type ⇒ ?'c::type) (?f ` ?A)⟧ ⟹ inj_on (?g ∘ ?f) ?A›*) inj_onI (*‹(⋀(x::?'a::type) y::?'a::type. ⟦x ∈ (?A::?'a::type set); y ∈ ?A; (?f::?'a::type ⇒ ?'b::type) x = ?f y⟧ ⟹ x = y) ⟹ inj_on ?f ?A›*)) moreover from ‹class P C = ⌊(D, fs, ms)⌋› (*‹class P C = ⌊(D, fs, ms)⌋›*) ‹C ≠ Object› (*‹C ≠ Object›*) have "P ⊢ C ≺¹ D" by (rule subcls1.intros (*‹⟦class (?P::?'m::type prog) (?C::String.literal) = ⌊(?D::String.literal, ?rest::fdecl list × ?'m::type option mdecl list)⌋; ?C ≠ Object⟧ ⟹ ?P ⊢ ?C ≺¹ ?D›*)) with ‹P ⊢ D has_fields FDTs› (*‹P ⊢ D has_fields FDTs›*) have "(fst ∘ (λ(F, y). ((F, C), y))) ` set fs ∩ fst ` set FDTs = {}" by (auto dest: subcls_notin_has_fields (*‹⟦?P ⊢ ?C has_fields ?FDTs; ((?F, ?D), ?Tm) ∈ set ?FDTs⟧ ⟹ ¬ (subcls1 ?P)⁺⁺ ?D ?C›*)) ultimately show "?case" (*goal: ‹distinct (map fst (FDTs'::((String.literal × String.literal) × ty × fmod) list))›*) using ‹FDTs' = map (λ(F, T). ((F, C), T)) fs @ FDTs› (*‹FDTs' = map (λ(F, T). ((F, C), T)) fs @ FDTs›*) ‹distinct (map fst FDTs)› (*‹distinct (map fst (FDTs::((String.literal × String.literal) × ty × fmod) list))›*) by simp qed subsection ‹Code generation› code_pred (modes: i ⇒ i ⇒ i ⇒ bool) [inductify] wf_overriding . text ‹ Separate subclass acycilicity from class declaration check. Otherwise, cyclic class hierarchies might lead to non-termination as @{term "Methods"} recurses over the class hierarchy. › definition acyclic_class_hierarchy :: "'m prog ⇒ bool" where "acyclic_class_hierarchy P ⟷ (∀(C, D, fs, ml) ∈ set (classes P). C ≠ Object ⟶ ¬ P ⊢ D ≼⇧* C)" definition wf_cdecl' :: "'m wf_mdecl_test ⇒ 'm prog ⇒ 'm cdecl ⇒ bool" where "wf_cdecl' wf_md P = (λ(C,(D,fs,ms)). (∀f∈set fs. wf_fdecl P f) ∧ distinct_fst fs ∧ (∀m∈set ms. wf_mdecl wf_md P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class P D ∧ (∀m∈set ms. wf_overriding P D m)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms)))" lemma acyclic_class_hierarchy_code [code]: "acyclic_class_hierarchy P ⟷ (∀(C, D, fs, ml) ∈ set (classes P). C ≠ Object ⟶ ¬ subcls' P D C)" by (simp add: acyclic_class_hierarchy_def (*‹acyclic_class_hierarchy ?P = (∀(C, D, fs, ml)∈set (classes ?P). C ≠ Object ⟶ ¬ ?P ⊢ D ≼⇧* C)›*) subcls'_def (*‹subcls' = subcls›*)) lemma wf_cdecl'_code [code]: "wf_cdecl' wf_md P = (λ(C,(D,fs,ms)). (∀f∈set fs. wf_fdecl P f) ∧ distinct_fst fs ∧ (∀m∈set ms. wf_mdecl wf_md P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class P D ∧ (∀m∈set ms. wf_overriding P D m)) ∧ (C = Thread ⟶ ((run, [], Void) ∈ set (map (λ(M, Ts, T, b). (M, Ts, T)) ms))))" by (auto simp add: wf_cdecl'_def (*‹wf_cdecl' ?wf_md ?P = (λ(C, D, fs, ms). (∀f∈set fs. wf_fdecl ?P f) ∧ distinct_fst fs ∧ (∀m∈set ms. wf_mdecl ?wf_md ?P C m) ∧ distinct_fst ms ∧ (C ≠ Object ⟶ is_class ?P D ∧ (∀m∈set ms. wf_overriding ?P D m)) ∧ (C = Thread ⟶ (∃m. (run, [], Void, m) ∈ set ms)))›*) intro!: ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*) intro: rev_image_eqI (*‹⟦?x ∈ ?A; ?b = ?f ?x⟧ ⟹ ?b ∈ ?f ` ?A›*)) declare set_append [symmetric, code_unfold] lemma wf_prog_code [code]: "wf_prog wf_md P ⟷ acyclic_class_hierarchy P ∧ wf_syscls P ∧ distinct_fst (classes P) ∧ (∀c ∈ set (classes P). wf_cdecl' wf_md P c)" unfolding wf_prog_def wf_cdecl_def wf_cdecl'_def acyclic_class_hierarchy_def split_def (*goal: ‹(wf_syscls P ∧ distinct_fst (classes P) ∧ (∀p∈set (classes P). Ball (set (fst (snd (snd p)))) (wf_fdecl P) ∧ distinct_fst (fst (snd (snd p))) ∧ Ball (set (snd (snd (snd p)))) (wf_mdecl wf_md P (fst p)) ∧ distinct_fst (snd (snd (snd p))) ∧ (fst p ≠ Object ⟶ is_class P (fst (snd p)) ∧ ¬ P ⊢ fst (snd p) ≼⇧* fst p ∧ Ball (set (snd (snd (snd p)))) (wf_overriding P (fst (snd p)))) ∧ (fst p = Thread ⟶ (∃m. (run, [], Void, m) ∈ set (snd (snd (snd p))))))) = ((∀p∈set (classes P). fst p ≠ Object ⟶ ¬ P ⊢ fst (snd p) ≼⇧* fst p) ∧ wf_syscls P ∧ distinct_fst (classes P) ∧ (∀c∈set (classes P). Ball (set (fst (snd (snd c)))) (wf_fdecl P) ∧ distinct_fst (fst (snd (snd c))) ∧ Ball (set (snd (snd (snd c)))) (wf_mdecl wf_md P (fst c)) ∧ distinct_fst (snd (snd (snd c))) ∧ (fst c ≠ Object ⟶ is_class P (fst (snd c)) ∧ Ball (set (snd (snd (snd c)))) (wf_overriding P (fst (snd c)))) ∧ (fst c = Thread ⟶ (∃m. (run, [], Void, m) ∈ set (snd (snd (snd c)))))))›*) by blast end
{ "path": "afp-2025-02-12/thys/JinjaThreads/Common/WellForm.thy", "repo": "afp-2025-02-12", "sha": "c066da78761cfd37e45351a2aabbc9ee5c899072fe1e869912b5b2d35b5331b8" }
(* Title: HOL/HOLCF/One.thy Author: Oscar Slotosch *) section ‹The unit domain› theory One imports Lift begin type_synonym one = "unit lift" translations (type) "one" ↽ (type) "unit lift" definition ONE :: "one" where "ONE ≡ Def ()" text ‹Exhaustion and Elimination for type \<^typ>‹one›› lemma Exh_one: "t = ⊥ ∨ t = ONE" apply (induct t) (*goals: 1. ‹⊥ = ⊥ ∨ ⊥ = ONE› 2. ‹⋀a. Def a = ⊥ ∨ Def a = ONE› discuss goal 1*) apply (simp add: ONE_def (*‹ONE ≡ Def ()›*)) (*discuss goal 2*) apply (simp add: ONE_def (*‹ONE ≡ Def ()›*)) (*proven 2 subgoals*) . lemma oneE [case_names bottom ONE]: "⟦p = ⊥ ⟹ Q; p = ONE ⟹ Q⟧ ⟹ Q" apply (induct p) (*goals: 1. ‹⟦⊥ = ⊥ ⟹ Q; ⊥ = ONE ⟹ Q⟧ ⟹ Q› 2. ‹⋀a. ⟦Def a = ⊥ ⟹ Q; Def a = ONE ⟹ Q⟧ ⟹ Q› discuss goal 1*) apply (simp add: ONE_def (*‹ONE ≡ Def ()›*)) (*discuss goal 2*) apply (simp add: ONE_def (*‹ONE ≡ Def ()›*)) (*proven 2 subgoals*) . lemma one_induct [case_names bottom ONE]: "P ⊥ ⟹ P ONE ⟹ P x" apply (cases x rule: oneE (*‹⟦?p = ⊥ ⟹ ?Q; ?p = ONE ⟹ ?Q⟧ ⟹ ?Q›*)) (*goals: 1. ‹⟦P ⊥; P ONE; x = ⊥⟧ ⟹ P x› 2. ‹⟦P ⊥; P ONE; x = ONE⟧ ⟹ P x› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma dist_below_one [simp]: "ONE \<notsqsubseteq> ⊥" by (simp add: ONE_def (*‹ONE ≡ Def ()›*)) lemma below_ONE [simp]: "x ⊑ ONE" apply (induct x rule: one_induct (*‹⟦(?P::one ⇒ bool) ⊥; ?P ONE⟧ ⟹ ?P (?x::one)›*)) (*goals: 1. ‹⊥ ⊑ ONE› 2. ‹ONE ⊑ ONE› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma ONE_below_iff [simp]: "ONE ⊑ x ⟷ x = ONE" apply (induct x rule: one_induct (*‹⟦(?P::one ⇒ bool) ⊥; ?P ONE⟧ ⟹ ?P (?x::one)›*)) (*goals: 1. ‹(ONE ⊑ ⊥) = (⊥ = ONE)› 2. ‹(ONE ⊑ ONE) = (ONE = ONE)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma ONE_defined [simp]: "ONE ≠ ⊥" by (simp add: ONE_def (*‹ONE ≡ Def ()›*)) lemma one_neq_iffs [simp]: "x ≠ ONE ⟷ x = ⊥" "ONE ≠ x ⟷ x = ⊥" "x ≠ ⊥ ⟷ x = ONE" "⊥ ≠ x ⟷ x = ONE" apply (induct x rule: one_induct (*‹⟦?P ⊥; ?P ONE⟧ ⟹ ?P ?x›*)) (*goals: 1. ‹(⊥ ≠ ONE) = (⊥ = ⊥)› 2. ‹(ONE ≠ ⊥) = (⊥ = ⊥)› 3. ‹(⊥ ≠ ⊥) = (⊥ = ONE)› 4. ‹(⊥ ≠ ⊥) = (⊥ = ONE)› 5. ‹(ONE ≠ ONE) = (ONE = ⊥)› 6. ‹(ONE ≠ ONE) = (ONE = ⊥)› 7. ‹(ONE ≠ ⊥) = (ONE = ONE)› 8. ‹(⊥ ≠ ONE) = (ONE = ONE)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*discuss goal 4*) apply simp (*discuss goal 5*) apply simp (*discuss goal 6*) apply simp (*discuss goal 7*) apply simp (*discuss goal 8*) apply simp (*proven 8 subgoals*) . lemma compact_ONE: "compact ONE" by (rule compact_chfin (*‹compact (?x::?'a)›*)) text ‹Case analysis function for type \<^typ>‹one›› definition one_case :: "'a::pcpo → one → 'a" where "one_case = (Λ a x. seq⋅x⋅a)" translations "case x of XCONST ONE ⇒ t" ⇌ "CONST one_case⋅t⋅x" "case x of XCONST ONE :: 'a ⇒ t" ⇀ "CONST one_case⋅t⋅x" "Λ (XCONST ONE). t" ⇌ "CONST one_case⋅t" lemma one_case1 [simp]: "(case ⊥ of ONE ⇒ t) = ⊥" by (simp add: one_case_def (*‹one_case = (Λ a x. seq⋅x⋅a)›*)) lemma one_case2 [simp]: "(case ONE of ONE ⇒ t) = t" by (simp add: one_case_def (*‹one_case = (Λ a x. seq⋅x⋅a)›*)) lemma one_case3 [simp]: "(case x of ONE ⇒ ONE) = x" apply (induct x rule: one_induct (*‹⟦(?P::one ⇒ bool) ⊥; ?P ONE⟧ ⟹ ?P (?x::one)›*)) (*goals: 1. ‹(case ⊥ of ONE ⇒ ONE) = ⊥› 2. ‹(case ONE of ONE ⇒ ONE) = ONE› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . end
{ "path": "Isabelle2024/src/HOL/HOLCF/One.thy", "repo": "Isabelle2024", "sha": "d0364857dc9132187e84b08a6e455d6cc30c4ab5ffd0cf33c3930bb3b997fef4" }
(* Title: Jive Data and Store Model Author: Norbert Schirmer <schirmer at informatik.tu-muenchen.de> and Nicole Rauch <rauch at informatik.uni-kl.de>, 2005 Maintainer: Nicole Rauch <rauch at informatik.uni-kl.de> License: LGPL *) section ‹The Direct Subtype Relation of Java Types› theory DirectSubtypes imports "../Isabelle/JavaType" begin text ‹ In this theory, we formalize the direct subtype relations of the Java types (as defined in Sec. \ref{java_typeid_definitions}) that appear in the program to be verified. Thus, this theory has to be generated for each program. \label{direct_subtype_relations} › text ‹We have the following type hierarchy: \begin{center} \includegraphics[width=13cm]{TypeHierarchy} \end{center} We need to describe all direct subtype relations of this type hierarchy. As you can see in the picture, all unnecessary direct subtype relations can be ignored, e.g. the subclass relation between CounterImpl and Object, because it is added transitively by the widening relation of types (see Sec. \ref{widening_subtypes}). › text ‹ We have to specify the direct subtype relation between \begin{itemize} \item each ``leaf'' class or interface and its subtype \texttt{NullT} \item each ``root'' class or interface and its supertype \texttt{Object} \item each two types that are direct subtypes as specified in the code by \texttt{extends} or \texttt{implements} \item each array type of a primitive type and its subtype \texttt{NullT} \item each array type of a primitive type and its supertype \texttt{Object} \item each array type of a ``leaf'' class or interface and its subtype \texttt{NullT} \item the array type \texttt{Object[]} and its supertype \texttt{Object} \item two array types if their element types are in a subtype hierarchy \end{itemize} › definition direct_subtype :: "(Javatype * Javatype) set" where "direct_subtype = { (NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception)) }" text ‹This lemma is used later in the Simplifier.› lemma direct_subtype: "(NullT, AClassT Dummy) ∈ direct_subtype" "(NullT, CClassT UndoCounter) ∈ direct_subtype" "(NullT, CClassT NullPointerException) ∈ direct_subtype" "(NullT, CClassT ClassCastException) ∈ direct_subtype" "(AClassT Dummy, CClassT Object) ∈ direct_subtype" "(InterfaceT Counter, CClassT Object) ∈ direct_subtype" "(CClassT Exception, CClassT Object) ∈ direct_subtype" "(CClassT UndoCounter, CClassT CounterImpl) ∈ direct_subtype" "(CClassT CounterImpl, InterfaceT Counter) ∈ direct_subtype" "(CClassT NullPointerException, CClassT Exception) ∈ direct_subtype" "(CClassT ClassCastException, CClassT Exception) ∈ direct_subtype" "(NullT, ArrT BoolAT) ∈ direct_subtype" "(NullT, ArrT IntgAT) ∈ direct_subtype" "(NullT, ArrT ShortAT) ∈ direct_subtype" "(NullT, ArrT ByteAT) ∈ direct_subtype" "(ArrT BoolAT, CClassT Object) ∈ direct_subtype" "(ArrT IntgAT, CClassT Object) ∈ direct_subtype" "(ArrT ShortAT, CClassT Object) ∈ direct_subtype" "(ArrT ByteAT, CClassT Object) ∈ direct_subtype" "(NullT, ArrT (AClassAT Dummy)) ∈ direct_subtype" "(NullT, ArrT (CClassAT UndoCounter)) ∈ direct_subtype" "(NullT, ArrT (CClassAT NullPointerException)) ∈ direct_subtype" "(NullT, ArrT (CClassAT ClassCastException)) ∈ direct_subtype" "(ArrT (CClassAT Object), CClassT Object) ∈ direct_subtype" "(ArrT (AClassAT Dummy), ArrT (CClassAT Object)) ∈ direct_subtype" "(ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)) ∈ direct_subtype" "(ArrT (InterfaceAT Counter), ArrT (CClassAT Object)) ∈ direct_subtype" "(ArrT (CClassAT Exception), ArrT (CClassAT Object)) ∈ direct_subtype" "(ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)) ∈ direct_subtype" "(ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)) ∈ direct_subtype" "(ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception)) ∈ direct_subtype" (*goals: 1. ‹(NullT, AClassT Dummy) ∈ direct_subtype› 2. ‹(NullT, CClassT UndoCounter) ∈ direct_subtype› 3. ‹(NullT, CClassT NullPointerException) ∈ direct_subtype› 4. ‹(NullT, CClassT ClassCastException) ∈ direct_subtype› 5. ‹(AClassT Dummy, CClassT Object) ∈ direct_subtype› 6. ‹(InterfaceT Counter, CClassT Object) ∈ direct_subtype› 7. ‹(CClassT Exception, CClassT Object) ∈ direct_subtype› 8. ‹(CClassT UndoCounter, CClassT CounterImpl) ∈ direct_subtype› 9. ‹(CClassT CounterImpl, InterfaceT Counter) ∈ direct_subtype› 10. ‹(CClassT NullPointerException, CClassT Exception) ∈ direct_subtype› 11. ‹(CClassT ClassCastException, CClassT Exception) ∈ direct_subtype› 12. ‹(NullT, ArrT BoolAT) ∈ direct_subtype› 13. ‹(NullT, ArrT IntgAT) ∈ direct_subtype› 14. ‹(NullT, ArrT ShortAT) ∈ direct_subtype› 15. ‹(NullT, ArrT ByteAT) ∈ direct_subtype› 16. ‹(ArrT BoolAT, CClassT Object) ∈ direct_subtype› 17. ‹(ArrT IntgAT, CClassT Object) ∈ direct_subtype› 18. ‹(ArrT ShortAT, CClassT Object) ∈ direct_subtype› 19. ‹(ArrT ByteAT, CClassT Object) ∈ direct_subtype› 20. ‹(NullT, ArrT (AClassAT Dummy)) ∈ direct_subtype› 21. ‹(NullT, ArrT (CClassAT UndoCounter)) ∈ direct_subtype› 22. ‹(NullT, ArrT (CClassAT NullPointerException)) ∈ direct_subtype› 23. ‹(NullT, ArrT (CClassAT ClassCastException)) ∈ direct_subtype› 24. ‹(ArrT (CClassAT Object), CClassT Object) ∈ direct_subtype› 25. ‹(ArrT (AClassAT Dummy), ArrT (CClassAT Object)) ∈ direct_subtype› 26. ‹(ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)) ∈ direct_subtype› 27. ‹(ArrT (InterfaceAT Counter), ArrT (CClassAT Object)) ∈ direct_subtype› 28. ‹(ArrT (CClassAT Exception), ArrT (CClassAT Object)) ∈ direct_subtype› 29. ‹(ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)) ∈ direct_subtype› 30. ‹(ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)) ∈ direct_subtype› 31. ‹(ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception)) ∈ direct_subtype› discuss goal 1*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 2*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 3*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 4*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 5*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 6*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 7*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 8*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 9*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 10*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 11*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 12*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 13*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 14*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 15*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 16*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 17*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 18*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 19*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 20*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 21*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 22*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 23*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 24*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 25*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 26*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 27*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 28*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 29*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 30*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*discuss goal 31*) apply (simp add: direct_subtype_def (*‹direct_subtype = {(NullT, AClassT Dummy), (NullT, CClassT UndoCounter), (NullT, CClassT NullPointerException), (NullT, CClassT ClassCastException), (AClassT Dummy, CClassT Object), (InterfaceT Counter, CClassT Object), (CClassT Exception, CClassT Object), (CClassT UndoCounter, CClassT CounterImpl), (CClassT CounterImpl, InterfaceT Counter), (CClassT NullPointerException, CClassT Exception), (CClassT ClassCastException, CClassT Exception), (NullT, ArrT BoolAT), (NullT, ArrT IntgAT), (NullT, ArrT ShortAT), (NullT, ArrT ByteAT), (ArrT BoolAT, CClassT Object), (ArrT IntgAT, CClassT Object), (ArrT ShortAT, CClassT Object), (ArrT ByteAT, CClassT Object), (NullT, ArrT (AClassAT Dummy)), (NullT, ArrT (CClassAT UndoCounter)), (NullT, ArrT (CClassAT NullPointerException)), (NullT, ArrT (CClassAT ClassCastException)), (ArrT (CClassAT Object), CClassT Object), (ArrT (AClassAT Dummy), ArrT (CClassAT Object)), (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), (ArrT (InterfaceAT Counter), ArrT (CClassAT Object)), (ArrT (CClassAT Exception), ArrT (CClassAT Object)), (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)), (ArrT (CClassAT ClassCastException), ArrT (CClassAT Exception))}›*)) (*proven 31 subgoals*) . end
{ "path": "afp-2025-02-12/thys/JiveDataStoreModel/Isa_Counter/DirectSubtypes.thy", "repo": "afp-2025-02-12", "sha": "5c10db58f0ef21f5ea7851d144118d181f21b7958604469c6bd0331158f80a9f" }
section‹Tag-Based Encodings› theory T imports T_G_Prelim begin subsection‹The tag translation› text‹The extension of the function symbols with type tags and type witnesses:› datatype ('fsym,'tp) efsym = Oldf 'fsym | Tag 'tp | Wit 'tp context ProblemIkTpart begin text‹``TE'' stands for ``tag encoding''› fun TE_wtFsym where "TE_wtFsym (Oldf f) ⟷ wtFsym f" |"TE_wtFsym (Tag σ) ⟷ True" |"TE_wtFsym (Wit σ) ⟷ ¬ isRes σ" fun TE_arOf where "TE_arOf (Oldf f) = arOf f" |"TE_arOf (Tag σ) = [σ]" |"TE_arOf (Wit σ) = []" fun TE_resOf where "TE_resOf (Oldf f) = resOf f" |"TE_resOf (Tag σ) = σ" |"TE_resOf (Wit σ) = σ" lemma countable_TE_wtFsym: "countable (Collect TE_wtFsym)" (is "countable ?K") proof (-) (*goal: ‹countable (Collect TE_wtFsym)›*) let ?F = "λ ef. case ef of Oldf f ⇒ Inl f | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)" let ?U = "(UNIV::'tp set) <+> (UNIV::'tp set)" let ?L = "(Collect wtFsym) <+> ?U" have "inj_on ?F ?K" unfolding inj_on_def (*goal: ‹∀x∈Collect TE_wtFsym. ∀y∈Collect TE_wtFsym. (case x of Oldf x ⇒ Inl x | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)) = (case y of Oldf x ⇒ Inl x | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)) ⟶ x = y›*) apply clarify (*goal: ‹∀x∈Collect TE_wtFsym. ∀y∈Collect TE_wtFsym. (case x of Oldf x ⇒ Inl x | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)) = (case y of Oldf x ⇒ Inl x | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)) ⟶ x = y›*) apply (case_tac x) (*goals: 1. ‹⋀x y x1. ⟦TE_wtFsym x; TE_wtFsym y; (case x of Oldf x ⇒ Inl x | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)) = (case y of Oldf x ⇒ Inl x | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)); x = Oldf x1⟧ ⟹ x = y› 2. ‹⋀x y x2. ⟦TE_wtFsym x; TE_wtFsym y; (case x of Oldf x ⇒ Inl x | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)) = (case y of Oldf x ⇒ Inl x | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)); x = Tag x2⟧ ⟹ x = y› 3. ‹⋀x y x3. ⟦TE_wtFsym x; TE_wtFsym y; (case x of Oldf x ⇒ Inl x | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)) = (case y of Oldf x ⇒ Inl x | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)); x = Wit x3⟧ ⟹ x = y› discuss goal 1*) apply simp (*top goal: ‹⋀x y x1. ⟦TE_wtFsym x; TE_wtFsym y; (case x of Oldf x ⇒ Inl x | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)) = (case y of Oldf x ⇒ Inl x | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)); x = Oldf x1⟧ ⟹ x = y› and 2 goals remain*) apply (case_tac y) (*goals: 1. ‹⋀(x::('fsym, 'tp) efsym) (y::('fsym, 'tp) efsym) (x1::'fsym) x1a::'fsym. ⟦(wtFsym::'fsym ⇒ bool) x1; TE_wtFsym y; Inl x1 = (case y of Oldf (x::'fsym) ⇒ Inl x | Tag (σ::'tp) ⇒ Inr (Inl σ) | Wit (σ::'tp) ⇒ Inr (Inr σ)); x = Oldf x1; y = Oldf x1a⟧ ⟹ Oldf x1 = y› 2. ‹⋀(x::('fsym, 'tp) efsym) (y::('fsym, 'tp) efsym) (x1::'fsym) x2::'tp. ⟦(wtFsym::'fsym ⇒ bool) x1; TE_wtFsym y; Inl x1 = (case y of Oldf (x::'fsym) ⇒ Inl x | Tag (σ::'tp) ⇒ Inr (Inl σ) | Wit (σ::'tp) ⇒ Inr (Inr σ)); x = Oldf x1; y = Tag x2⟧ ⟹ Oldf x1 = y› 3. ‹⋀(x::('fsym, 'tp) efsym) (y::('fsym, 'tp) efsym) (x1::'fsym) x3::'tp. ⟦(wtFsym::'fsym ⇒ bool) x1; TE_wtFsym y; Inl x1 = (case y of Oldf (x::'fsym) ⇒ Inl x | Tag (σ::'tp) ⇒ Inr (Inl σ) | Wit (σ::'tp) ⇒ Inr (Inr σ)); x = Oldf x1; y = Wit x3⟧ ⟹ Oldf x1 = y› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) (*discuss goal 2*) apply simp (*top goal: ‹⋀x y x2. ⟦TE_wtFsym x; TE_wtFsym y; (case x of Oldf x ⇒ Inl x | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)) = (case y of Oldf x ⇒ Inl x | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)); x = Tag x2⟧ ⟹ x = y› and 1 goal remains*) apply (case_tac y) (*goals: 1. ‹⋀x y x2 x1. ⟦TE_wtFsym y; Inr (Inl x2) = (case y of Oldf x ⇒ Inl x | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)); x = Tag x2; y = Oldf x1⟧ ⟹ Tag x2 = y› 2. ‹⋀x y x2 x2a. ⟦TE_wtFsym y; Inr (Inl x2) = (case y of Oldf x ⇒ Inl x | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)); x = Tag x2; y = Tag x2a⟧ ⟹ Tag x2 = y› 3. ‹⋀x y x2 x3. ⟦TE_wtFsym y; Inr (Inl x2) = (case y of Oldf x ⇒ Inl x | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)); x = Tag x2; y = Wit x3⟧ ⟹ Tag x2 = y› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) (*discuss goal 3*) apply simp (*goal: ‹⋀x y x3. ⟦TE_wtFsym x; TE_wtFsym y; (case x of Oldf x ⇒ Inl x | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)) = (case y of Oldf x ⇒ Inl x | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)); x = Wit x3⟧ ⟹ x = y›*) apply (case_tac y) (*goals: 1. ‹⋀x y x3 x1. ⟦¬ isRes x3; TE_wtFsym y; Inr (Inr x3) = (case y of Oldf x ⇒ Inl x | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)); x = Wit x3; y = Oldf x1⟧ ⟹ Wit x3 = y› 2. ‹⋀x y x3 x2. ⟦¬ isRes x3; TE_wtFsym y; Inr (Inr x3) = (case y of Oldf x ⇒ Inl x | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)); x = Wit x3; y = Tag x2⟧ ⟹ Wit x3 = y› 3. ‹⋀x y x3 x3a. ⟦¬ isRes x3; TE_wtFsym y; Inr (Inr x3) = (case y of Oldf x ⇒ Inl x | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)); x = Wit x3; y = Wit x3a⟧ ⟹ Wit x3 = y› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) (*proven 3 subgoals*) . moreover have "?F ` ?K ⊆ ?L" apply clarify (*goal: ‹(λef. case ef of Oldf f ⇒ Inl f | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)) ` Collect TE_wtFsym ⊆ Collect wtFsym <+> UNIV <+> UNIV›*) apply (case_tac ef) (*goals: 1. ‹⋀x ef x1. ⟦TE_wtFsym ef; ef = Oldf x1⟧ ⟹ (case ef of Oldf f ⇒ Inl f | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)) ∈ Collect wtFsym <+> UNIV <+> UNIV› 2. ‹⋀x ef x2. ⟦TE_wtFsym ef; ef = Tag x2⟧ ⟹ (case ef of Oldf f ⇒ Inl f | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)) ∈ Collect wtFsym <+> UNIV <+> UNIV› 3. ‹⋀x ef x3. ⟦TE_wtFsym ef; ef = Wit x3⟧ ⟹ (case ef of Oldf f ⇒ Inl f | Tag σ ⇒ Inr (Inl σ) | Wit σ ⇒ Inr (Inr σ)) ∈ Collect wtFsym <+> UNIV <+> UNIV› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . ultimately have "|?K| ≤o |?L|" unfolding card_of_ordLeq[symmetric] (*goal: ‹∃f. inj_on f (Collect TE_wtFsym) ∧ f ` Collect TE_wtFsym ⊆ Collect wtFsym <+> UNIV <+> UNIV›*) by auto moreover have "countable ?L" using countable_wtFsym (*‹countable {f::'fsym. (wtFsym::'fsym ⇒ bool) f}›*) countable_tp (*‹countable UNIV›*) by (metis countable_Plus (*‹⟦countable ?A; countable ?B⟧ ⟹ countable (?A <+> ?B)›*)) ultimately show "?thesis" (*goal: ‹countable (Collect TE_wtFsym)›*) by (rule countable_ordLeq (*‹⟦|?A| ≤o |?B|; countable ?B⟧ ⟹ countable ?A›*)) qed end (* context ProblemIkTpart *) sublocale ProblemIkTpart < TE? : Signature where wtFsym = TE_wtFsym and arOf = TE_arOf and resOf = TE_resOf apply standard (*goal: ‹Signature TYPE('tp) TE_wtFsym wtPsym›*) using countable_tp (*‹countable UNIV›*) countable_TE_wtFsym (*‹countable (Collect TE_wtFsym)›*) countable_wtPsym (*‹countable {p. wtPsym p}›*) apply - (*goals: 1. ‹⟦countable UNIV; countable (Collect TE_wtFsym); countable {p. wtPsym p}⟧ ⟹ countable UNIV› 2. ‹⟦countable UNIV; countable (Collect TE_wtFsym); countable {p. wtPsym p}⟧ ⟹ countable (Collect TE_wtFsym)› 3. ‹⟦countable UNIV; countable (Collect TE_wtFsym); countable {p. wtPsym p}⟧ ⟹ countable {p. wtPsym p}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . context ProblemIkTpart begin (* encoding of non-naked terms *) fun tNN where "tNN (Var x) = (if unprot (tpOfV x) ∨ protFw (tpOfV x) then Var x else Fn (Tag (tpOfV x)) [Var x])" | "tNN (Fn f Tl) = (if unprot (resOf f) ∨ protFw (resOf f) then Fn (Oldf f) (map tNN Tl) else Fn (Tag (resOf f)) [Fn (Oldf f) (map tNN Tl)])" fun tT where "tT (Var x) = (if unprot (tpOfV x) then Var x else Fn (Tag (tpOfV x)) [Var x])" | "tT t = tNN t" fun tL where "tL (Pos (Eq T1 T2)) = Pos (Eq (tT T1) (tT T2))" | "tL (Neg (Eq T1 T2)) = Neg (Eq (tNN T1) (tNN T2))" | "tL (Pos (Pr p Tl)) = Pos (Pr p (map tNN Tl))" | "tL (Neg (Pr p Tl)) = Neg (Pr p (map tNN Tl))" definition "tC ≡ map tL" (* The extra axioms: *) (* The function axioms: *) (* Lefthand side: *) definition "rOfFax f = Fn (Oldf f) (getTvars (arOf f))" (* Righthand side: *) definition "lOfFax f = Fn (Tag (resOf f)) [rOfFax f]" definition "Fax ≡ {[Pos (Eq (lOfFax f) (rOfFax f))] | f. wtFsym f}" (* The witness axioms: *) (* Lefthand side: *) definition "rOfWax σ = Fn (Wit σ) []" (* Righthand side: *) definition "lOfWax σ = Fn (Tag σ) [rOfWax σ]" definition "Wax ≡ {[Pos (Eq (lOfWax σ) (rOfWax σ))] | σ. ¬ isRes σ ∧ protFw σ}" definition "tPB = tC ` Φ ∪ Fax ∪ Wax" (* Well-typedness of the translation: *) lemma tpOf_tNN[simp]: "TE.tpOf (tNN T) = Ik.tpOf T" apply (induct T) (*goals: 1. ‹⋀x::Preliminaries.var. TE.tpOf (tNN (Var x)) = Ik.tpOf (Var x)› 2. ‹⋀(f::'fsym) Tl::'fsym trm list. list_all (λa::'fsym trm. TE.tpOf (tNN a) = Ik.tpOf a) Tl ⟹ TE.tpOf (tNN (Fn f Tl)) = Ik.tpOf (Fn f Tl)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma tpOf_t[simp]: "TE.tpOf (tT T) = Ik.tpOf T" apply (cases T) (*goals: 1. ‹⋀x1. T = Var x1 ⟹ TE.tpOf (tT T) = Ik.tpOf T› 2. ‹⋀x21 x22. T = Fn x21 x22 ⟹ TE.tpOf (tT T) = Ik.tpOf T› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma wt_tNN[simp]: "Ik.wt T ⟹ TE.wt (tNN T)" apply (induct T) (*goals: 1. ‹⋀x::Preliminaries.var. Ik.wt (Var x) ⟹ TE.wt (tNN (Var x))› 2. ‹⋀(f::'fsym::type) Tl::'fsym::type trm list. ⟦list_all (λa::'fsym::type trm. Ik.wt a ⟶ TE.wt (tNN a)) Tl; Ik.wt (Fn f Tl)⟧ ⟹ TE.wt (tNN (Fn f Tl))› discuss goal 1*) apply ((auto simp add: list_all_iff (*‹list_all ?P ?x = Ball (set ?x) ?P›*))[1]) (*discuss goal 2*) apply ((auto simp add: list_all_iff (*‹list_all (?P::?'a ⇒ bool) (?x::?'a list) = Ball (set ?x) ?P›*))[1]) (*proven 2 subgoals*) . lemma wt_t[simp]: "Ik.wt T ⟹ TE.wt (tT T)" apply (cases T) (*goals: 1. ‹⋀x1. ⟦Ik.wt T; T = Var x1⟧ ⟹ TE.wt (tT T)› 2. ‹⋀x21 x22. ⟦Ik.wt T; T = Fn x21 x22⟧ ⟹ TE.wt (tT T)› discuss goal 1*) apply ((auto simp add: list_all_iff (*‹list_all ?P ?x = Ball (set ?x) ?P›*))[1]) (*discuss goal 2*) apply ((auto simp add: list_all_iff (*‹list_all ?P ?x = Ball (set ?x) ?P›*))[1]) (*proven 2 subgoals*) . lemma wtL_tL[simp]: "Ik.wtL l ⟹ TE.wtL (tL l)" apply (cases l) (*goals: 1. ‹⋀x1::('fsym::type, 'psym::type) atm. ⟦Ik.wtL (l::('fsym::type, 'psym::type) lit); l = Pos x1⟧ ⟹ TE.wtL (tL l)› 2. ‹⋀x2::('fsym::type, 'psym::type) atm. ⟦Ik.wtL (l::('fsym::type, 'psym::type) lit); l = Neg x2⟧ ⟹ TE.wtL (tL l)› discuss goal 1*) apply (rename_tac [!] atm) (*top goal: ‹⋀x1. ⟦Ik.wtL l; l = Pos x1⟧ ⟹ TE.wtL (tL l)› and 1 goal remains*) apply ((case_tac [!] atm)[1]) (*goals: 1. ‹⋀atm x11 x12. ⟦Ik.wtL l; l = Pos atm; atm = Eq x11 x12⟧ ⟹ TE.wtL (tL l)› 2. ‹⋀atm x21 x22. ⟦Ik.wtL l; l = Pos atm; atm = Pr x21 x22⟧ ⟹ TE.wtL (tL l)› discuss goal 1*) apply ((auto simp add: list_all_iff (*‹list_all ?P ?x = Ball (set ?x) ?P›*))[1]) (*discuss goal 2*) apply ((auto simp add: list_all_iff (*‹list_all ?P ?x = Ball (set ?x) ?P›*))[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply ((case_tac [!] atm)[1]) (*goals: 1. ‹⋀atm x11 x12. ⟦Ik.wtL l; l = Neg atm; atm = Eq x11 x12⟧ ⟹ TE.wtL (tL l)› 2. ‹⋀atm x21 x22. ⟦Ik.wtL l; l = Neg atm; atm = Pr x21 x22⟧ ⟹ TE.wtL (tL l)› discuss goal 1*) apply ((auto simp add: list_all_iff (*‹list_all ?P ?x = Ball (set ?x) ?P›*))[1]) (*discuss goal 2*) apply ((auto simp add: list_all_iff (*‹list_all ?P ?x = Ball (set ?x) ?P›*))[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma wtC_tC[simp]: "Ik.wtC c ⟹ TE.wtC (tC c)" unfolding tC_def Ik.wtC_def TE.wtC_def (*goal: ‹list_all Ik.wtL c ⟹ list_all TE.wtL (map tL c)›*) apply (induct c) (*goals: 1. ‹list_all Ik.wtL [] ⟹ list_all TE.wtL (map tL [])› 2. ‹⋀(a::('fsym, 'psym) lit) c::('fsym, 'psym) lit list. ⟦list_all Ik.wtL c ⟹ list_all TE.wtL (map tL c); list_all Ik.wtL (a # c)⟧ ⟹ list_all TE.wtL (map tL (a # c))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma tpOf_rOfFax[simp]: "TE.tpOf (rOfFax f) = resOf f" unfolding rOfFax_def (*goal: ‹TE.tpOf (Fn (Oldf (f::'fsym)) (TE.getTvars ((arOf::'fsym ⇒ 'tp list) f))) = (resOf::'fsym ⇒ 'tp) f›*) by simp lemma tpOf_lOfFax[simp]: "TE.tpOf (lOfFax f) = resOf f" unfolding lOfFax_def (*goal: ‹TE.tpOf (Fn (Tag (resOf f)) [rOfFax f]) = resOf f›*) by simp lemma tpOf_rOfWax[simp]: "TE.tpOf (rOfWax σ) = σ" unfolding rOfWax_def (*goal: ‹TE.tpOf (Fn (Wit σ) []) = σ›*) by simp lemma tpOf_lOfWax[simp]: "TE.tpOf (lOfWax σ) = σ" unfolding lOfWax_def (*goal: ‹TE.tpOf (Fn (Tag σ) [rOfWax σ]) = σ›*) by simp lemma wt_rOfFax[simp]: "wtFsym f ⟹ TE.wt (rOfFax f)" unfolding rOfFax_def (*goal: ‹wtFsym f ⟹ TE.wt (Fn (Oldf f) (TE.getTvars (arOf f)))›*) by simp lemma wt_lOfFax[simp]: "wtFsym f ⟹ TE.wt (lOfFax f)" unfolding lOfFax_def (*goal: ‹wtFsym f ⟹ TE.wt (Fn (Tag (resOf f)) [rOfFax f])›*) by simp lemma wt_rOfWax[simp]: "¬ isRes σ ⟹ TE.wt (rOfWax σ)" unfolding rOfWax_def (*goal: ‹¬ isRes (σ::'tp) ⟹ TE.wt (Fn (Wit σ) [])›*) by simp lemma wt_lOfWax[simp]: "¬ isRes σ ⟹ TE.wt (lOfWax σ)" unfolding lOfWax_def (*goal: ‹¬ isRes σ ⟹ TE.wt (Fn (Tag σ) [rOfWax σ])›*) by simp lemma wtPB_Fax[simp]: "TE.wtPB Fax" unfolding Fax_def TE.wtPB_def TE.wtC_def (*goal: ‹∀c∈{[Pos (Eq (lOfFax f) (rOfFax f))] |f. wtFsym f}. list_all TE.wtL c›*) by auto lemma wtPB_Wax[simp]: "TE.wtPB Wax" unfolding Wax_def TE.wtPB_def TE.wtC_def (*goal: ‹∀c∈{[Pos (Eq (lOfWax σ) (rOfWax σ))] |σ. ¬ isRes σ ∧ protFw σ}. list_all TE.wtL c›*) by auto lemma wtPB_tC_Φ[simp]: "TE.wtPB (tC ` Φ)" using "Ik.wt_Φ" (*‹Ik.wtPB Φ›*) unfolding Ik.wtPB_def TE.wtPB_def (*goal: ‹Ball (tC ` Φ) TE.wtC›*) by auto lemma wtPB_tPB[simp]: "TE.wtPB tPB" sorry (* *) lemma wt_Tag: assumes "TE.wt (Fn (Tag σ) Tl)" shows "∃ T. Tl = [T] ∧ TE.wt T ∧ tpOf T = σ" using assms (*‹TE.wt (Fn (Tag σ) Tl)›*) apply simp (*goal: ‹∃T. Tl = [T] ∧ TE.wt T ∧ TE.tpOf T = σ›*) by (metis (opaque_lifting, no_types) list.inject (*‹((?x21.0::?'a) # (?x22.0::?'a list) = (?y21.0::?'a) # (?y22.0::?'a list)) = (?x21.0 = ?y21.0 ∧ ?x22.0 = ?y22.0)›*) list_all_simps( (*‹list_all (?P::?'a ⇒ bool) ((?x::?'a) # (?xs::?'a list)) = (?P ?x ∧ list_all ?P ?xs)›*) 1) map_eq_Cons_conv (*‹(map (?f::?'b ⇒ ?'a) (?xs::?'b list) = (?y::?'a) # (?ys::?'a list)) = (∃(z::?'b) zs::?'b list. ?xs = z # zs ∧ ?f z = ?y ∧ map ?f zs = ?ys)›*) neq_Nil_conv (*‹((?xs::?'a list) ≠ []) = (∃(y::?'a) ys::?'a list. ?xs = y # ys)›*)) lemma tpOf_Tag: "TE.tpOf (Fn (Tag σ) Tl) = σ" by simp lemma wt_Wit: assumes "TE.wt (Fn (Wit σ) Tl)" shows "Tl = []" using assms (*‹TE.wt (Fn (Wit σ) Tl)›*) by simp lemma tpOf_Wit: "TE.tpOf (Fn (Wit σ) Tl) = σ" by simp end (* context ProblemIkTpart *) subsection‹Soundness› context ModelIkTpart begin (* The identity-tag extension of a given structure of the original signature *) fun TE_intF where "TE_intF (Oldf f) al = intF f al" |"TE_intF (Tag σ) al = hd al" |"TE_intF (Wit σ) al = pickT σ" (* note: for tags, we only care about al being the singleton list [a], and hence the interpretation returns a; for witnesses, we only care about al being [] *) end (* context ModelIkTpart *) sublocale ModelIkTpart < TE? : Struct where wtFsym = TE_wtFsym and arOf = TE_arOf and resOf = TE_resOf and intF = TE_intF proof (standard) (*goals: 1. ‹⋀f al. ⟦TE_wtFsym f; list_all2 intT (TE_arOf f) al⟧ ⟹ intT (TE_resOf f) (TE_intF f al)› 2. ‹intP = intP›*) fix ef and al assume "TE_wtFsym ef" and "list_all2 intT (TE_arOf ef) al" (*‹TE_wtFsym (ef::('fsym, 'tp) efsym)› ‹list_all2 (intT::'tp ⇒ univ ⇒ bool) (TE_arOf (ef::('fsym, 'tp) efsym)) (al::univ list)›*) thus "intT (TE_resOf ef) (TE_intF ef al)" using intF (*‹⟦wtFsym ?f; list_all2 intT (arOf ?f) ?al⟧ ⟹ intT (resOf ?f) (intF ?f ?al)›*) apply (cases ef) (*goals: 1. ‹⋀x1. ⟦TE_wtFsym ef; list_all2 intT (TE_arOf ef) al; ⋀f al. ⟦wtFsym f; list_all2 intT (arOf f) al⟧ ⟹ intT (resOf f) (intF f al); ef = Oldf x1⟧ ⟹ intT (TE_resOf ef) (TE_intF ef al)› 2. ‹⋀x2. ⟦TE_wtFsym ef; list_all2 intT (TE_arOf ef) al; ⋀f al. ⟦wtFsym f; list_all2 intT (arOf f) al⟧ ⟹ intT (resOf f) (intF f al); ef = Tag x2⟧ ⟹ intT (TE_resOf ef) (TE_intF ef al)› 3. ‹⋀x3. ⟦TE_wtFsym ef; list_all2 intT (TE_arOf ef) al; ⋀f al. ⟦wtFsym f; list_all2 intT (arOf f) al⟧ ⟹ intT (resOf f) (intF f al); ef = Wit x3⟧ ⟹ intT (TE_resOf ef) (TE_intF ef al)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . qed (auto) (*solved the remaining goal: ‹intP = intP›*) context ModelIkTpart begin lemma tNN_int[simp]: "TE.int ξ (tNN T) = Ik.int ξ T" proof (induct T) (*goals: 1. ‹⋀x. TE.int ξ (tNN (Var x)) = Ik.int ξ (Var x)› 2. ‹⋀f Tl. list_all (λa. TE.int ξ (tNN a) = Ik.int ξ a) Tl ⟹ TE.int ξ (tNN (Fn f Tl)) = Ik.int ξ (Fn f Tl)›*) case (Fn f Tl) (*‹list_all (λa::'fsym::type trm. TE.int (ξ::Preliminaries.var ⇒ univ) (tNN a) = Ik.int ξ a) (Tl::'fsym::type trm list)›*) hence 0: "map (TE.int ξ ∘ tNN) Tl = map (Ik.int ξ) Tl" unfolding list_eq_iff list_all_iff (*goal: ‹length (map (TE.int ξ ∘ tNN) Tl) = length (map (Ik.int ξ) Tl) ∧ (∀i<length (map (TE.int ξ ∘ tNN) Tl). map (TE.int ξ ∘ tNN) Tl ! i = map (Ik.int ξ) Tl ! i)›*) by auto show "?case" (*goal: ‹TE.int ξ (tNN (Fn f Tl)) = Ik.int ξ (Fn f Tl)›*) by (simp add: 0 (*‹map (TE.int ξ ∘ tNN) Tl = map (Ik.int ξ) Tl›*)) qed (auto) (*solved the remaining goal: ‹⋀x. TE.int ξ (tNN (Var x)) = Ik.int ξ (Var x)›*) lemma map_tNN_int[simp]: "map (TE.int ξ ∘ tNN) Tl = map (Ik.int ξ) Tl" unfolding list_eq_iff list_all_iff (*goal: ‹length (map (TE.int ξ ∘ tNN) Tl) = length (map (Ik.int ξ) Tl) ∧ (∀i<length (map (TE.int ξ ∘ tNN) Tl). map (TE.int ξ ∘ tNN) Tl ! i = map (Ik.int ξ) Tl ! i)›*) by auto lemma t_int[simp]: "TE.int ξ (tT T) = Ik.int ξ T" apply (cases T) (*goals: 1. ‹⋀x1. T = Var x1 ⟹ TE.int ξ (tT T) = Ik.int ξ T› 2. ‹⋀x21 x22. T = Fn x21 x22 ⟹ TE.int ξ (tT T) = Ik.int ξ T› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma map_t_int[simp]: "map (TE.int ξ ∘ tT) Tl = map (Ik.int ξ) Tl" unfolding list_eq_iff list_all_iff (*goal: ‹length (map (TE.int ξ ∘ tT) Tl) = length (map (Ik.int ξ) Tl) ∧ (∀i<length (map (TE.int ξ ∘ tT) Tl). map (TE.int ξ ∘ tT) Tl ! i = map (Ik.int ξ) Tl ! i)›*) by auto lemma tL_satL[simp]: "TE.satL ξ (tL l) ⟷ Ik.satL ξ l" apply (cases l) (*goals: 1. ‹⋀x1::('fsym, 'psym) atm. (l::('fsym, 'psym) lit) = Pos x1 ⟹ TE.satL (ξ::Preliminaries.var ⇒ univ) (tL l) = Ik.satL ξ l› 2. ‹⋀x2::('fsym, 'psym) atm. (l::('fsym, 'psym) lit) = Neg x2 ⟹ TE.satL (ξ::Preliminaries.var ⇒ univ) (tL l) = Ik.satL ξ l› discuss goal 1*) apply (rename_tac [!] atm) (*top goal: ‹⋀x1. l = Pos x1 ⟹ TE.satL ξ (tL l) = Ik.satL ξ l› and 1 goal remains*) apply ((case_tac [!] atm)[1]) (*goals: 1. ‹⋀(atm::('fsym, 'psym) atm) (x11::'fsym trm) x12::'fsym trm. ⟦(l::('fsym, 'psym) lit) = Pos atm; atm = Eq x11 x12⟧ ⟹ TE.satL (ξ::Preliminaries.var ⇒ univ) (tL l) = Ik.satL ξ l› 2. ‹⋀(atm::('fsym, 'psym) atm) (x21::'psym) x22::'fsym trm list. ⟦(l::('fsym, 'psym) lit) = Pos atm; atm = Pr x21 x22⟧ ⟹ TE.satL (ξ::Preliminaries.var ⇒ univ) (tL l) = Ik.satL ξ l› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply ((case_tac [!] atm)[1]) (*goals: 1. ‹⋀atm x11 x12. ⟦l = Neg atm; atm = Eq x11 x12⟧ ⟹ TE.satL ξ (tL l) = Ik.satL ξ l› 2. ‹⋀atm x21 x22. ⟦l = Neg atm; atm = Pr x21 x22⟧ ⟹ TE.satL ξ (tL l) = Ik.satL ξ l› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma tC_satC[simp]: "TE.satC ξ (tC c) ⟷ Ik.satC ξ c" unfolding TE.satC_def Ik.satC_def tC_def (*goal: ‹list_ex (TE.satL ξ) (map tL c) = list_ex (Ik.satL ξ) c›*) apply (induct c) (*goals: 1. ‹list_ex (TE.satL (ξ::Preliminaries.var ⇒ univ)) (map tL []) = list_ex (Ik.satL ξ) []› 2. ‹⋀(a::('fsym::type, 'psym::type) lit) c::('fsym::type, 'psym::type) lit list. list_ex (TE.satL (ξ::Preliminaries.var ⇒ univ)) (map tL c) = list_ex (Ik.satL ξ) c ⟹ list_ex (TE.satL ξ) (map tL (a # c)) = list_ex (Ik.satL ξ) (a # c)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma tC_Φ_satPB[simp]: "TE.satPB ξ (tC ` Φ) ⟷ Ik.satPB ξ Φ" unfolding TE.satPB_def Ik.satPB_def (*goal: ‹(∀c∈tC ` Φ. TE.satC ξ c) = (∀c∈Φ. Ik.satC ξ c)›*) by auto lemma Fax_Wax_satPB: "TE.satPB ξ (Fax) ∧ TE.satPB ξ (Wax)" unfolding TE.satPB_def TE.satC_def Fax_def Wax_def (*goal: ‹(∀c∈{[Pos (Eq (lOfFax f) (rOfFax f))] |f. wtFsym f}. list_ex (TE.satL ξ) c) ∧ (∀c∈{[Pos (Eq (lOfWax σ) (rOfWax σ))] |σ. ¬ isRes σ ∧ protFw σ}. list_ex (TE.satL ξ) c)›*) by (auto simp add: lOfFax_def (*‹lOfFax ?f = Fn (Tag (resOf ?f)) [rOfFax ?f]›*) rOfFax_def (*‹rOfFax ?f = Fn (Oldf ?f) (TE.getTvars (arOf ?f))›*) lOfWax_def (*‹lOfWax ?σ = Fn (Tag ?σ) [rOfWax ?σ]›*) rOfWax_def (*‹rOfWax ?σ = Fn (Wit ?σ) []›*)) lemmas Fax_satPB[simp] = Fax_Wax_satPB[THEN conjunct1] lemmas Wax_satPB[simp] = Fax_Wax_satPB[THEN conjunct2] lemma soundness: "TE.SAT tPB" unfolding TE.SAT_def tPB_def (*goal: ‹∀ξ. TE.wtE ξ ⟶ TE.satPB ξ (tC ` Φ ∪ Fax ∪ Wax)›*) using SAT (*‹Ik.SAT (Φ::('fsym, 'psym) lit list set)›*) unfolding Ik.SAT_def (*goal: ‹∀ξ. TE.wtE ξ ⟶ TE.satPB ξ (tC ` Φ ∪ Fax ∪ Wax)›*) by auto theorem T_soundness: "Model TE_wtFsym wtPsym TE_arOf TE_resOf parOf tPB intT TE_intF intP" apply standard (*goal: ‹CM.Model TE_wtFsym wtPsym TE_arOf TE_resOf parOf tPB intT TE_intF intP›*) using wtPB_tPB (*‹TE.wtPB tPB›*) soundness (*‹TE.SAT tPB›*) apply - (*goals: 1. ‹⟦TE.wtPB tPB; TE.SAT tPB⟧ ⟹ TE.wtPB tPB› 2. ‹⟦TE.wtPB tPB; TE.SAT tPB⟧ ⟹ TE.SAT tPB› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . end (* context ModelIkTpart *) (* Soundness theorem in sublocale form: Given a problem (with indicated type partition) and a model for it, we obtain a model of the tag-extended (TE) problem: *) sublocale ModelIkTpart < TE? : Model where wtFsym = TE_wtFsym and arOf = TE_arOf and resOf = TE_resOf and Φ = tPB and intF = TE_intF apply standard (*goal: ‹CM.Model TE_wtFsym (wtPsym::'psym::type ⇒ bool) TE_arOf TE_resOf (parOf::'psym::type ⇒ 'tp::type list) tPB (intT::'tp::type ⇒ univ ⇒ bool) TE_intF (intP::'psym::type ⇒ univ list ⇒ bool)›*) using wtPB_tPB (*‹TE.wtPB tPB›*) soundness (*‹TE.SAT tPB›*) apply - (*goals: 1. ‹⟦TE.wtPB tPB; TE.SAT tPB⟧ ⟹ TE.wtPB tPB› 2. ‹⟦TE.wtPB tPB; TE.SAT tPB⟧ ⟹ TE.SAT tPB› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . subsection‹Completeness› (* iimg B f transforms f into a function f' having the same B-range as f and such that it is the identity on its B-image, namely, ∀ b ∈ B. f' (f' a) = f' a; also, it holds that ∀ b ∈ B. f' (f b) = f b *) definition "iimg B f a ≡ if a ∈ f ` B then a else f a" lemma inImage_iimg[simp]: "a ∈ f ` B ⟹ iimg B f a = a" unfolding iimg_def (*goal: ‹a ∈ f ` B ⟹ (if a ∈ f ` B then a else f a) = a›*) by auto lemma not_inImage_iimg[simp]: "a ∉ f ` B ⟹ iimg B f a = f a" unfolding iimg_def (*goal: ‹a ∉ f ` B ⟹ (if a ∈ f ` B then a else f a) = f a›*) by auto lemma iimg[simp]: "a ∈ B ⟹ iimg B f (f a) = f a" apply (cases "a ∈ f ` B") (*goals: 1. ‹⟦a ∈ B; a ∈ f ` B⟧ ⟹ iimg B f (f a) = f a› 2. ‹⟦a ∈ B; a ∉ f ` B⟧ ⟹ iimg B f (f a) = f a› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . (* Problem with type partition and model of its tag-encoding translation: *) locale ProblemIkTpart_TEModel = Ik? : ProblemIkTpart wtFsym wtPsym arOf resOf parOf Φ infTp prot protFw + TE? : Model "ProblemIkTpart.TE_wtFsym wtFsym resOf" wtPsym "ProblemIkTpart.TE_arOf arOf" "ProblemIkTpart.TE_resOf resOf" parOf tPB eintT eintF eintP for wtFsym :: "'fsym ⇒ bool" and wtPsym :: "'psym ⇒ bool" and arOf :: "'fsym ⇒ 'tp list" and resOf and parOf and Φ and infTp and prot and protFw and eintT and eintF and eintP context ProblemIkTpart_TEModel begin (* new tag semantics (taking as input elements, instead of singleton lists): *) definition "ntsem σ ≡ if unprot σ ∨ protFw σ then id else iimg {b. eintT σ b} (eintF (Tag σ) o singl)" lemma unprot_ntsem[simp]: "unprot σ ∨ protFw σ ⟹ ntsem σ a = a" unfolding ntsem_def (*goal: ‹unprot (σ::'tp::type) ∨ (protFw::'tp::type ⇒ bool) σ ⟹ (if unprot σ ∨ protFw σ then id else iimg {b::univ. (eintT::'tp::type ⇒ univ ⇒ bool) σ b} ((eintF::('fsym::type, 'tp::type) efsym ⇒ univ list ⇒ univ) (Tag σ) ∘ singl)) (a::univ) = a›*) by simp lemma protFw_ntsem[simp]: "protFw σ ⟹ ntsem σ a = a" unfolding ntsem_def (*goal: ‹protFw σ ⟹ (if unprot σ ∨ protFw σ then id else iimg {b. eintT σ b} (eintF (Tag σ) ∘ singl)) a = a›*) by simp lemma inImage_ntsem[simp]: "a ∈ (eintF (Tag σ) o singl) ` {b. eintT σ b} ⟹ ntsem σ a = a" unfolding ntsem_def (*goal: ‹a ∈ (eintF (Tag σ) ∘ singl) ` {b. eintT σ b} ⟹ (if unprot σ ∨ protFw σ then id else iimg {b. eintT σ b} (eintF (Tag σ) ∘ singl)) a = a›*) by simp lemma not_unprot_inImage_ntsem[simp]: assumes "¬ unprot σ" and "¬ protFw σ" and "a ∉ (eintF (Tag σ) o singl) ` {b. eintT σ b}" shows "ntsem σ a = eintF (Tag σ) [a]" using assms (*‹¬ unprot (σ::'tp)› ‹¬ protFw σ› ‹a ∉ (eintF (Tag σ) ∘ singl) ` {b. eintT σ b}›*) unfolding ntsem_def (*goal: ‹(if unprot σ ∨ protFw σ then id else iimg {b. eintT σ b} (eintF (Tag σ) ∘ singl)) a = eintF (Tag σ) [a]›*) by (simp add: singl_def (*‹singl ?a = [?a]›*)) (* crucial: *) lemma ntsem[simp]: "eintT σ b ⟹ ntsem σ (eintF (Tag σ) [b]) = eintF (Tag σ) [b]" unfolding singl_def[symmetric] (*goal: ‹eintT σ b ⟹ ntsem σ (eintF (Tag σ) (singl b)) = eintF (Tag σ) (singl b)›*) by simp lemma eintT_ntsem: assumes a: "eintT σ a" shows "eintT σ (ntsem σ a)" proof (cases "unprot σ ∨ protFw σ") (*goals: 1. ‹unprot σ ∨ protFw σ ⟹ eintT σ (ntsem σ a)› 2. ‹¬ (unprot σ ∨ protFw σ) ⟹ eintT σ (ntsem σ a)›*) case False (*‹¬ (unprot σ ∨ protFw σ)›*) note unprot = False (*‹¬ (unprot σ ∨ protFw σ)›*) show "?thesis" (*goal: ‹eintT σ (ntsem σ a)›*) proof (cases "a ∈ (eintF (Tag σ) o singl) ` {b. eintT σ b}") (*goals: 1. ‹a ∈ (eintF (Tag σ) ∘ singl) ` {b. eintT σ b} ⟹ eintT σ (ntsem σ a)› 2. ‹a ∉ (eintF (Tag σ) ∘ singl) ` {b. eintT σ b} ⟹ eintT σ (ntsem σ a)›*) case False (*‹a ∉ (eintF (Tag σ) ∘ singl) ` {b. eintT σ b}›*) hence 1: "ntsem σ a = eintF (Tag σ) [a]" using unprot (*‹¬ (unprot (σ::'tp) ∨ (protFw::'tp ⇒ bool) σ)›*) by simp show "?thesis" (*goal: ‹eintT σ (ntsem σ a)›*) unfolding "1" (*goal: ‹eintT σ (eintF (Tag σ) [a])›*) using a (*‹eintT σ a›*) TE.intF (*‹⟦TE_wtFsym ?f; list_all2 eintT (TE_arOf ?f) ?al⟧ ⟹ eintT (TE_resOf ?f) (eintF ?f ?al)›*) by (metis TE_arOf.simps (*‹TE_arOf (Oldf (?f::'fsym)) = (arOf::'fsym ⇒ 'tp list) ?f› ‹TE_arOf (Tag (?σ::'tp)) = [?σ]› ‹TE_arOf (Wit (?σ::'tp)) = []›*) TE_resOf.simps (*‹TE_resOf (Oldf (?f::'fsym)) = (resOf::'fsym ⇒ 'tp) ?f› ‹TE_resOf (Tag (?σ::'tp)) = ?σ› ‹TE_resOf (Wit (?σ::'tp)) = ?σ›*) TE_wtFsym.simps (*‹TE_wtFsym (Oldf (?f::'fsym)) = (wtFsym::'fsym ⇒ bool) ?f› ‹TE_wtFsym (Tag (?σ::'tp)) = True› ‹TE_wtFsym (Wit (?σ::'tp)) = (¬ isRes ?σ)›*) list_all2_Cons (*‹list_all2 (?P::?'a ⇒ ?'b ⇒ bool) ((?x::?'a) # (?xs::?'a list)) ((?y::?'b) # (?ys::?'b list)) = (?P ?x ?y ∧ list_all2 ?P ?xs ?ys)›*) list_all2_Nil (*‹list_all2 (?P::?'a ⇒ ?'b ⇒ bool) [] (?ys::?'b list) = (?ys = [])›*)) qed (insert a (*‹eintT σ a›*), auto) (*solved the remaining goal: ‹(a::univ) ∈ ((eintF::('fsym::type, 'tp::type) efsym ⇒ univ list ⇒ univ) (Tag (σ::'tp::type)) ∘ singl) ` {b::univ. (eintT::'tp::type ⇒ univ ⇒ bool) σ b} ⟹ eintT σ (ntsem σ a)›*) qed (insert a (*‹eintT σ a›*), simp) (*solved the remaining goal: ‹unprot (σ::'tp::type) ∨ (protFw::'tp::type ⇒ bool) σ ⟹ (eintT::'tp::type ⇒ univ ⇒ bool) σ (ntsem σ (a::univ))›*) (* The reduct structure of a given structure in the tag-extended signature: *) definition "intT σ a ≡ if unprot σ then eintT σ a else if protFw σ then eintT σ a ∧ eintF (Tag σ) [a] = a else eintT σ a ∧ a ∈ (eintF (Tag σ) o singl) ` {b. eintT σ b}" definition "intF f al ≡ if unprot (resOf f) ∨ protFw (resOf f) then eintF (Oldf f) (map2 ntsem (arOf f) al) else eintF (Tag (resOf f)) [eintF (Oldf f) (map2 ntsem (arOf f) al)]" definition "intP p al ≡ eintP p (map2 ntsem (parOf p) al)" (* Semantic rephrasings of the fact that the (tagged problem) model satisfies Fax and Wax *) lemma TE_Tag: (* fixme: messy proof *) assumes f: "wtFsym f" and al: "list_all2 eintT (arOf f) al" shows "eintF (Tag (resOf f)) [eintF (Oldf f) al] = eintF (Oldf f) al" proof (-) (*goal: ‹eintF (Tag (resOf f)) [eintF (Oldf f) al] = eintF (Oldf f) al›*) define xl where "xl = getVars (arOf f)" have l[simp]: "length xl = length al" "length al = length (arOf f)" unfolding xl_def (*goals: 1. ‹length (TE.getVars (arOf f)) = length al› 2. ‹length al = length (arOf f)›*) using al (*‹list_all2 eintT (arOf f) al›*) unfolding list_all2_iff (*goals: 1. ‹length (TE.getVars (arOf f)) = length al› 2. ‹length al = length (arOf f)›*) apply - (*goals: 1. ‹length (arOf f) = length al ∧ (∀(x, y)∈set (zip (arOf f) al). eintT x y) ⟹ length (TE.getVars (arOf f)) = length al› 2. ‹length (arOf f) = length al ∧ (∀(x, y)∈set (zip (arOf f) al). eintT x y) ⟹ length al = length (arOf f)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have 1[simp]: "⋀ i. i < length (arOf f) ⟹ tpOfV (xl!i) = (arOf f)!i" unfolding xl_def (*goal: ‹⋀i. i < length (arOf f) ⟹ TE.tpOfV (TE.getVars (arOf f) ! i) = arOf f ! i›*) by auto have xl[simp]: "distinct xl" unfolding xl_def (*goal: ‹distinct (TE.getVars (arOf f))›*) using distinct_getVars (*‹distinct (TE.getVars ?σl)›*) by auto define ξ where "ξ = pickE xl al" have "ξ": "TE.wtE ξ" unfolding "ξ_def" (*goal: ‹wtE (pickE xl al)›*) apply (rule wtE_pickE (*‹⟦length ?xl = length ?al; distinct ?xl; ⋀i. i < length ?xl ⟹ eintT (TE.tpOfV (?xl ! i)) (?al ! i)⟧ ⟹ wtE (pickE ?xl ?al)›*)) (*goal: ‹wtE (pickE xl al)›*) using al (*‹list_all2 eintT (arOf f) al›*) list_all2_nthD (*‹⟦list_all2 ?P ?xs ?ys; ?p < length ?xs⟧ ⟹ ?P (?xs ! ?p) (?ys ! ?p)›*) apply - (*goals: 1. ‹⟦list_all2 eintT (arOf f) al; ⋀P xs ys p. ⟦list_all2 P xs ys; p < length xs⟧ ⟹ P (xs ! p) (ys ! p)⟧ ⟹ length xl = length al› 2. ‹⟦list_all2 eintT (arOf f) al; ⋀P xs ys p. ⟦list_all2 P xs ys; p < length xs⟧ ⟹ P (xs ! p) (ys ! p)⟧ ⟹ distinct xl› 3. ‹⋀i. ⟦i < length xl; list_all2 eintT (arOf f) al; ⋀P xs ys p. ⟦list_all2 P xs ys; p < length xs⟧ ⟹ P (xs ! p) (ys ! p)⟧ ⟹ eintT (TE.tpOfV (xl ! i)) (al ! i)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . have [simp]: "⋀ i. i < length (arOf f) ⟹ ξ (xl ! i) = al ! i" using al (*‹list_all2 eintT (arOf f) al›*) unfolding "ξ_def" (*goal: ‹⋀i. i < length (arOf f) ⟹ pickE xl al (xl ! i) = al ! i›*) by (auto simp: list_all2_length (*‹list_all2 ?P ?xs ?ys = (length ?xs = length ?ys ∧ (∀i<length ?xs. ?P (?xs ! i) (?ys ! i)))›*) intro: pickE (*‹⟦length ?xl = length ?al; distinct ?xl; ⋀i. i < length ?xl ⟹ eintT (TE.tpOfV (?xl ! i)) (?al ! i); ?i < length ?xl⟧ ⟹ pickE ?xl ?al (?xl ! ?i) = ?al ! ?i›*)) have 0: "map (TE.int ξ) (getTvars (arOf f)) = al" apply (rule nth_equalityI (*‹⟦length ?xs = length ?ys; ⋀i. i < length ?xs ⟹ ?xs ! i = ?ys ! i⟧ ⟹ ?xs = ?ys›*)) (*goal: ‹map (int ξ) (TE.getTvars (arOf f)) = al›*) using al (*‹list_all2 eintT (arOf f) al›*) (*goals: 1. ‹length (map (int ξ) (TE.getTvars (arOf f))) = length al› 2. ‹⋀i. i < length (map (int ξ) (TE.getTvars (arOf f))) ⟹ map (int ξ) (TE.getTvars (arOf f)) ! i = al ! i› discuss goal 1*) apply ((auto simp: list_all2_length (*‹list_all2 (?P::?'a::type ⇒ ?'b::type ⇒ bool) (?xs::?'a::type list) (?ys::?'b::type list) = (length ?xs = length ?ys ∧ (∀i<length ?xs. ?P (?xs ! i) (?ys ! i)))›*) getTvars_def (*‹TE.getTvars (?σl::'tp::type list) ≡ map Var (TE.getVars ?σl)›*) xl_def[symmetric] (*‹TE.getVars ((arOf::'fsym::type ⇒ 'tp::type list) (f::'fsym::type)) = (xl::Preliminaries.var list)›*))[1]) (*discuss goal 2*) apply ((auto simp: list_all2_length (*‹list_all2 (?P::?'a::type ⇒ ?'b::type ⇒ bool) (?xs::?'a::type list) (?ys::?'b::type list) = (length ?xs = length ?ys ∧ (∀i<length ?xs. ?P (?xs ! i) (?ys ! i)))›*) getTvars_def (*‹TE.getTvars (?σl::'tp::type list) ≡ map Var (TE.getVars ?σl)›*) xl_def[symmetric] (*‹TE.getVars ((arOf::'fsym::type ⇒ 'tp::type list) (f::'fsym::type)) = (xl::Preliminaries.var list)›*))[1]) (*proven 2 subgoals*) . have "TE.satPB ξ Fax" using "TE.sat_Φ"[OF ξ] (*‹satPB ξ tPB›*) unfolding tPB_def (*goal: ‹satPB ξ Fax›*) by simp hence "TE.satC ξ [Pos (Eq (lOfFax f) (rOfFax f))]" unfolding TE.satPB_def Fax_def (*goal: ‹satC ξ [Pos (Eq (lOfFax f) (rOfFax f))]›*) using f (*‹wtFsym f›*) by auto hence "TE.satA ξ (Eq (lOfFax f) (rOfFax f))" unfolding TE.satC_def (*goal: ‹satA ξ (Eq (lOfFax f) (rOfFax f))›*) by simp thus "?thesis" (*goal: ‹eintF (Tag (resOf f)) [eintF (Oldf f) al] = eintF (Oldf f) al›*) using al (*‹list_all2 eintT (arOf f) al›*) by (simp add: lOfFax_def (*‹lOfFax (?f::'fsym::type) = Fn (Tag ((resOf::'fsym::type ⇒ 'tp::type) ?f)) [rOfFax ?f]›*) rOfFax_def (*‹rOfFax (?f::'fsym::type) = Fn (Oldf ?f) (TE.getTvars ((arOf::'fsym::type ⇒ 'tp::type list) ?f))›*) 0 (*‹map (int (ξ::Preliminaries.var ⇒ univ)) (TE.getTvars ((arOf::'fsym::type ⇒ 'tp::type list) (f::'fsym::type))) = (al::univ list)›*)) qed lemma TE_Wit: assumes σ: "¬ isRes σ" "protFw σ" shows "eintF (Tag σ) [eintF (Wit σ) []] = eintF (Wit σ) []" proof (-) (*goal: ‹(eintF::('fsym, 'tp) efsym ⇒ univ list ⇒ univ) (Tag (σ::'tp)) [eintF (Wit σ) []] = eintF (Wit σ) []›*) define ξ where "ξ = pickE [] []" have "ξ": "TE.wtE ξ" unfolding "ξ_def" (*goal: ‹wtE (pickE [] [])›*) apply (rule wtE_pickE (*‹⟦length ?xl = length ?al; distinct ?xl; ⋀i. i < length ?xl ⟹ eintT (TE.tpOfV (?xl ! i)) (?al ! i)⟧ ⟹ wtE (pickE ?xl ?al)›*)) (*goals: 1. ‹length [] = length []› 2. ‹distinct []› 3. ‹⋀i. i < length [] ⟹ eintT (TE.tpOfV ([] ! i)) ([] ! i)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . have "TE.satPB ξ Wax" using "TE.sat_Φ"[OF ξ] (*‹satPB ξ tPB›*) unfolding tPB_def (*goal: ‹satPB ξ Wax›*) by simp hence "TE.satC ξ [Pos (Eq (lOfWax σ) (rOfWax σ))]" unfolding TE.satPB_def Wax_def (*goal: ‹satC ξ [Pos (Eq (lOfWax σ) (rOfWax σ))]›*) using "σ" (*‹¬ isRes (σ::'tp::type)› ‹protFw σ›*) by auto hence "TE.satA ξ (Eq (lOfWax σ) (rOfWax σ))" unfolding TE.satC_def (*goal: ‹satA ξ (Eq (lOfWax σ) (rOfWax σ))›*) by auto thus "?thesis" (*goal: ‹eintF (Tag σ) [eintF (Wit σ) []] = eintF (Wit σ) []›*) unfolding TE.satA.simps lOfWax_def rOfWax_def (*goal: ‹(eintF::('fsym, 'tp) efsym ⇒ univ list ⇒ univ) (Tag (σ::'tp)) [eintF (Wit σ) []] = eintF (Wit σ) []›*) by simp qed lemma NE_intT_forget: "NE (intT σ)" proof (-) (*goal: ‹∃a. intT σ a›*) obtain b where b: "eintT σ b" (*goal: ‹(⋀b. eintT σ b ⟹ thesis) ⟹ thesis›*) using TE.NE_intT (*‹∃a. eintT ?σ a›*) by blast show "?thesis" (*goal: ‹∃a::univ. intT (σ::'tp) a›*) proof (cases "unprot σ") (*goals: 1. ‹unprot σ ⟹ ∃a. intT σ a› 2. ‹¬ unprot σ ⟹ ∃a. intT σ a›*) case True (*‹unprot σ›*) thus "?thesis" (*goal: ‹∃a::univ. intT (σ::'tp) a›*) using b (*‹(eintT::'tp ⇒ univ ⇒ bool) (σ::'tp) (b::univ)›*) unfolding intT_def (*goal: ‹∃a::univ. if unprot (σ::'tp::type) then (eintT::'tp::type ⇒ univ ⇒ bool) σ a else if (protFw::'tp::type ⇒ bool) σ then eintT σ a ∧ (eintF::('fsym::type, 'tp::type) efsym ⇒ univ list ⇒ univ) (Tag σ) [a] = a else eintT σ a ∧ a ∈ (eintF (Tag σ) ∘ singl) ` {b::univ. eintT σ b}›*) by auto next (*goal: ‹¬ unprot σ ⟹ ∃a. intT σ a›*) case False (*‹¬ unprot σ›*) note unprot = False (*‹¬ unprot σ›*) show "?thesis" (*goal: ‹∃a. intT σ a›*) proof (cases "protFw σ") (*goals: 1. ‹protFw σ ⟹ ∃a. intT σ a› 2. ‹¬ protFw σ ⟹ ∃a. intT σ a›*) case True (*‹protFw σ›*) note protFw = True (*‹protFw σ›*) show "?thesis" (*goal: ‹∃a::univ. intT (σ::'tp) a›*) proof (cases "isRes σ") (*goals: 1. ‹isRes σ ⟹ ∃a. intT σ a› 2. ‹¬ isRes σ ⟹ ∃a. intT σ a›*) case True (*‹isRes (σ::'tp)›*) then obtain f where f: "wtFsym f" and "σ": "σ = resOf f" (*goal: ‹(⋀f. ⟦wtFsym f; σ = resOf f⟧ ⟹ thesis) ⟹ thesis›*) unfolding isRes_def (*goal: ‹(⋀f. ⟦wtFsym f; σ = resOf f⟧ ⟹ thesis) ⟹ thesis›*) by auto define al where "al = map pickT (arOf f)" have al: "list_all2 eintT (arOf f) al" unfolding al_def list_all2_map2 (*goal: ‹list_all2 (λx y. eintT x (pickT y)) (arOf f) (arOf f)›*) unfolding list_all2_length (*goal: ‹length (arOf f) = length (arOf f) ∧ (∀i<length (arOf f). eintT (arOf f ! i) (pickT (arOf f ! i)))›*) by auto define a where "a = eintF (Oldf f) al" have "eintT σ a" unfolding a_def "σ" (*goal: ‹(eintT::'tp::type ⇒ univ ⇒ bool) ((resOf::'fsym::type ⇒ 'tp::type) (f::'fsym::type)) ((eintF::('fsym::type, 'tp::type) efsym ⇒ univ list ⇒ univ) (Oldf f) (al::univ list))›*) using f (*‹wtFsym f›*) al (*‹list_all2 eintT (arOf f) al›*) by (metis TE_arOf.simps (*‹TE_arOf (Oldf ?f) = arOf ?f› ‹TE_arOf (Tag ?σ) = [?σ]› ‹TE_arOf (Wit ?σ) = []›*) TE_resOf.simps (*‹TE_resOf (Oldf ?f) = resOf ?f› ‹TE_resOf (Tag ?σ) = ?σ› ‹TE_resOf (Wit ?σ) = ?σ›*) TE_wtFsym.simps (*‹TE_wtFsym (Oldf ?f) = wtFsym ?f› ‹TE_wtFsym (Tag ?σ) = True› ‹TE_wtFsym (Wit ?σ) = (¬ isRes ?σ)›*) TE.intF (*‹⟦TE_wtFsym ?f; list_all2 eintT (TE_arOf ?f) ?al⟧ ⟹ eintT (TE_resOf ?f) (eintF ?f ?al)›*)) moreover have "eintF (Tag σ) [a] = a" unfolding "σ" a_def (*goal: ‹eintF (Tag (resOf f)) [eintF (Oldf f) al] = eintF (Oldf f) al›*) using TE_Tag[OF f al] (*‹eintF (Tag (resOf f)) [eintF (Oldf f) al] = eintF (Oldf f) al›*) . ultimately show "?thesis" (*goal: ‹∃a. intT σ a›*) using unprot (*‹¬ unprot σ›*) protFw (*‹protFw σ›*) unfolding intT_def (*goal: ‹∃a. if unprot σ then eintT σ a else if protFw σ then eintT σ a ∧ eintF (Tag σ) [a] = a else eintT σ a ∧ a ∈ (eintF (Tag σ) ∘ singl) ` {b. eintT σ b}›*) by auto next (*goal: ‹¬ isRes σ ⟹ ∃a. intT σ a›*) case False (*‹¬ isRes σ›*) define a where "a = eintF (Wit σ) []" have "eintT σ a" unfolding a_def (*goal: ‹eintT σ (eintF (Wit σ) [])›*) by (metis False (*‹¬ isRes σ›*) TE_arOf.simps (*‹TE_arOf (Oldf ?f) = arOf ?f› ‹TE_arOf (Tag ?σ) = [?σ]› ‹TE_arOf (Wit ?σ) = []›*) TE_resOf.simps (*‹TE_resOf (Oldf ?f) = resOf ?f› ‹TE_resOf (Tag ?σ) = ?σ› ‹TE_resOf (Wit ?σ) = ?σ›*) TE_wtFsym.simps (*‹TE_wtFsym (Oldf ?f) = wtFsym ?f› ‹TE_wtFsym (Tag ?σ) = True› ‹TE_wtFsym (Wit ?σ) = (¬ isRes ?σ)›*) TE.intF (*‹⟦TE_wtFsym ?f; list_all2 eintT (TE_arOf ?f) ?al⟧ ⟹ eintT (TE_resOf ?f) (eintF ?f ?al)›*) list_all2_NilR (*‹list_all2 ?R ?xs [] = (?xs = [])›*)) moreover have "eintF (Tag σ) [a] = a" unfolding a_def (*goal: ‹eintF (Tag σ) [eintF (Wit σ) []] = eintF (Wit σ) []›*) using TE_Wit[OF False protFw] (*‹eintF (Tag σ) [eintF (Wit σ) []] = eintF (Wit σ) []›*) . ultimately show "?thesis" (*goal: ‹∃a. intT σ a›*) using unprot (*‹¬ unprot σ›*) protFw (*‹(protFw::'tp ⇒ bool) (σ::'tp)›*) unfolding intT_def (*goal: ‹∃a. if unprot σ then eintT σ a else if protFw σ then eintT σ a ∧ eintF (Tag σ) [a] = a else eintT σ a ∧ a ∈ (eintF (Tag σ) ∘ singl) ` {b. eintT σ b}›*) by auto qed next (*goal: ‹¬ protFw σ ⟹ ∃a. intT σ a›*) case False (*‹¬ protFw σ›*) hence "eintT σ (eintF (Tag σ) [b])" using b (*‹eintT σ b›*) list_all2_Cons (*‹list_all2 ?P (?x # ?xs) (?y # ?ys) = (?P ?x ?y ∧ list_all2 ?P ?xs ?ys)›*) list_all2_NilL (*‹list_all2 ?R [] ?ys = (?ys = [])›*) by (metis TE.intF (*‹⟦TE_wtFsym ?f; list_all2 eintT (TE_arOf ?f) ?al⟧ ⟹ eintT (TE_resOf ?f) (eintF ?f ?al)›*) TE_arOf.simps (*‹TE_arOf (Oldf ?f) = arOf ?f› ‹TE_arOf (Tag ?σ) = [?σ]› ‹TE_arOf (Wit ?σ) = []›*) TE_resOf.simps (*‹TE_resOf (Oldf ?f) = resOf ?f› ‹TE_resOf (Tag ?σ) = ?σ› ‹TE_resOf (Wit ?σ) = ?σ›*) TE_wtFsym.simps (*‹TE_wtFsym (Oldf ?f) = wtFsym ?f› ‹TE_wtFsym (Tag ?σ) = True› ‹TE_wtFsym (Wit ?σ) = (¬ isRes ?σ)›*)) hence "intT σ (eintF (Tag σ) [b])" unfolding intT_def singl_def[abs_def] (*goal: ‹if unprot σ then eintT σ (eintF (Tag σ) [b]) else if protFw σ then eintT σ (eintF (Tag σ) [b]) ∧ eintF (Tag σ) [eintF (Tag σ) [b]] = eintF (Tag σ) [b] else eintT σ (eintF (Tag σ) [b]) ∧ eintF (Tag σ) [b] ∈ (eintF (Tag σ) ∘ (λa. [a])) ` {b. eintT σ b}›*) using b (*‹eintT σ b›*) False (*‹¬ protFw σ›*) by auto thus "?thesis" (*goal: ‹∃a. intT σ a›*) by blast qed qed qed lemma wt_intF: assumes f: "wtFsym f" and al: "list_all2 intT (arOf f) al" shows "intT (resOf f) (intF f al)" proof (-) (*goal: ‹intT (resOf f) (intF f al)›*) let ?t = "eintF (Tag (resOf f))" let ?t'al = "map2 ntsem (arOf f) al" have al: "list_all2 eintT (arOf f) al" using al (*‹list_all2 intT (arOf f) al›*) unfolding list_all2_length intT_def (*goal: ‹length (arOf f) = length al ∧ (∀i<length (arOf f). eintT (arOf f ! i) (al ! i))›*) by metis have 0: "list_all2 eintT (arOf f) ?t'al" proof (rule listAll2_map2I (*‹⟦length ?xs = length ?ys; ⋀i. i < length ?xs ⟹ ?R (?xs ! i) (?f (?xs ! i) (?ys ! i))⟧ ⟹ list_all2 ?R ?xs (map2 ?f ?xs ?ys)›*)) (*goals: 1. ‹length (arOf f) = length al› 2. ‹⋀i. i < length (arOf f) ⟹ eintT (arOf f ! i) (ntsem (arOf f ! i) (al ! i))›*) show l: "length (arOf f) = length al" using al (*‹list_all2 eintT (arOf f) al›*) unfolding list_all2_length (*goal: ‹length (arOf f) = length al›*) by simp fix i assume "i < length (arOf f)" (*‹(i::nat) < length ((arOf::'fsym ⇒ 'tp list) (f::'fsym))›*) hence 1: "eintT (arOf f ! i) (al ! i)" using al (*‹list_all2 (eintT::'tp::type ⇒ univ ⇒ bool) ((arOf::'fsym::type ⇒ 'tp::type list) (f::'fsym::type)) (al::univ list)›*) unfolding list_all2_length (*goal: ‹eintT (arOf f ! i) (al ! i)›*) by simp show "eintT (arOf f ! i) (ntsem (arOf f ! i) (al ! i))" using eintT_ntsem[OF 1] (*‹eintT (arOf f ! i) (ntsem (arOf f ! i) (al ! i))›*) . qed hence 1: "eintT (resOf f) (eintF (Oldf f) ?t'al)" by (metis TE_arOf.simps (*‹TE_arOf (Oldf ?f) = arOf ?f› ‹TE_arOf (Tag ?σ) = [?σ]› ‹TE_arOf (Wit ?σ) = []›*) TE_resOf.simps (*‹TE_resOf (Oldf ?f) = resOf ?f› ‹TE_resOf (Tag ?σ) = ?σ› ‹TE_resOf (Wit ?σ) = ?σ›*) TE_wtFsym.simps (*‹TE_wtFsym (Oldf ?f) = wtFsym ?f› ‹TE_wtFsym (Tag ?σ) = True› ‹TE_wtFsym (Wit ?σ) = (¬ isRes ?σ)›*) f (*‹wtFsym f›*) TE.intF (*‹⟦TE_wtFsym ?f; list_all2 eintT (TE_arOf ?f) ?al⟧ ⟹ eintT (TE_resOf ?f) (eintF ?f ?al)›*)) show "?thesis" (*goal: ‹intT (resOf f) (intF f al)›*) proof (cases "unprot (resOf f)") (*goals: 1. ‹unprot (resOf f) ⟹ intT (resOf f) (intF f al)› 2. ‹¬ unprot (resOf f) ⟹ intT (resOf f) (intF f al)›*) case True (*‹unprot (resOf f)›*) thus "?thesis" (*goal: ‹intT ((resOf::'fsym::type ⇒ 'tp::type) (f::'fsym::type)) (intF f (al::univ list))›*) unfolding intF_def intT_def (*goal: ‹if unprot (resOf f) then eintT (resOf f) (if unprot (resOf f) ∨ protFw (resOf f) then eintF (Oldf f) (map2 ntsem (arOf f) al) else eintF (Tag (resOf f)) [eintF (Oldf f) (map2 ntsem (arOf f) al)]) else if protFw (resOf f) then eintT (resOf f) (if unprot (resOf f) ∨ protFw (resOf f) then eintF (Oldf f) (map2 ntsem (arOf f) al) else eintF (Tag (resOf f)) [eintF (Oldf f) (map2 ntsem (arOf f) al)]) ∧ eintF (Tag (resOf f)) [if unprot (resOf f) ∨ protFw (resOf f) then eintF (Oldf f) (map2 ntsem (arOf f) al) else eintF (Tag (resOf f)) [eintF (Oldf f) (map2 ntsem (arOf f) al)]] = (if unprot (resOf f) ∨ protFw (resOf f) then eintF (Oldf f) (map2 ntsem (arOf f) al) else eintF (Tag (resOf f)) [eintF (Oldf f) (map2 ntsem (arOf f) al)]) else eintT (resOf f) (if unprot (resOf f) ∨ protFw (resOf f) then eintF (Oldf f) (map2 ntsem (arOf f) al) else eintF (Tag (resOf f)) [eintF (Oldf f) (map2 ntsem (arOf f) al)]) ∧ (if unprot (resOf f) ∨ protFw (resOf f) then eintF (Oldf f) (map2 ntsem (arOf f) al) else eintF (Tag (resOf f)) [eintF (Oldf f) (map2 ntsem (arOf f) al)]) ∈ (eintF (Tag (resOf f)) ∘ singl) ` {b. eintT (resOf f) b}›*) by (simp add: 1 (*‹eintT (resOf f) (eintF (Oldf f) (map2 ntsem (arOf f) al))›*)) next (*goal: ‹¬ unprot (resOf f) ⟹ intT (resOf f) (intF f al)›*) case False (*‹¬ unprot (resOf f)›*) note unprot = False (*‹¬ unprot (resOf f)›*) show "?thesis" (*goal: ‹intT (resOf f) (intF f al)›*) proof (cases "protFw (resOf f)") (*goals: 1. ‹protFw (resOf f) ⟹ intT (resOf f) (intF f al)› 2. ‹¬ protFw (resOf f) ⟹ intT (resOf f) (intF f al)›*) case True (*‹protFw (resOf f)›*) thus "?thesis" (*goal: ‹intT ((resOf::'fsym::type ⇒ 'tp::type) (f::'fsym::type)) (intF f (al::univ list))›*) using unprot (*‹¬ unprot (resOf f)›*) TE_Tag[OF f 0] (*‹eintF (Tag (resOf f)) [eintF (Oldf f) (map2 ntsem (arOf f) al)] = eintF (Oldf f) (map2 ntsem (arOf f) al)›*) "1" (*‹(eintT::'tp ⇒ univ ⇒ bool) ((resOf::'fsym ⇒ 'tp) (f::'fsym)) ((eintF::('fsym, 'tp) efsym ⇒ univ list ⇒ univ) (Oldf f) (map2 ntsem ((arOf::'fsym ⇒ 'tp list) f) (al::univ list)))›*) unfolding intF_def intT_def (*goal: ‹if unprot (resOf f) then eintT (resOf f) (if unprot (resOf f) ∨ protFw (resOf f) then eintF (Oldf f) (map2 ntsem (arOf f) al) else eintF (Tag (resOf f)) [eintF (Oldf f) (map2 ntsem (arOf f) al)]) else if protFw (resOf f) then eintT (resOf f) (if unprot (resOf f) ∨ protFw (resOf f) then eintF (Oldf f) (map2 ntsem (arOf f) al) else eintF (Tag (resOf f)) [eintF (Oldf f) (map2 ntsem (arOf f) al)]) ∧ eintF (Tag (resOf f)) [if unprot (resOf f) ∨ protFw (resOf f) then eintF (Oldf f) (map2 ntsem (arOf f) al) else eintF (Tag (resOf f)) [eintF (Oldf f) (map2 ntsem (arOf f) al)]] = (if unprot (resOf f) ∨ protFw (resOf f) then eintF (Oldf f) (map2 ntsem (arOf f) al) else eintF (Tag (resOf f)) [eintF (Oldf f) (map2 ntsem (arOf f) al)]) else eintT (resOf f) (if unprot (resOf f) ∨ protFw (resOf f) then eintF (Oldf f) (map2 ntsem (arOf f) al) else eintF (Tag (resOf f)) [eintF (Oldf f) (map2 ntsem (arOf f) al)]) ∧ (if unprot (resOf f) ∨ protFw (resOf f) then eintF (Oldf f) (map2 ntsem (arOf f) al) else eintF (Tag (resOf f)) [eintF (Oldf f) (map2 ntsem (arOf f) al)]) ∈ (eintF (Tag (resOf f)) ∘ singl) ` {b. eintT (resOf f) b}›*) by simp next (*goal: ‹¬ protFw (resOf f) ⟹ intT (resOf f) (intF f al)›*) case False (*‹¬ protFw (resOf f)›*) have "eintT (resOf f) (intF f al)" using intF_def (*‹intF ?f ?al ≡ if unprot (resOf ?f) ∨ protFw (resOf ?f) then eintF (Oldf ?f) (map2 ntsem (arOf ?f) ?al) else eintF (Tag (resOf ?f)) [eintF (Oldf ?f) (map2 ntsem (arOf ?f) ?al)]›*) "0" (*‹list_all2 eintT (arOf f) (map2 ntsem (arOf f) al)›*) "1" (*‹eintT (resOf f) (eintF (Oldf f) (map2 ntsem (arOf f) al))›*) TE_Tag (*‹⟦wtFsym ?f; list_all2 eintT (arOf ?f) ?al⟧ ⟹ eintF (Tag (resOf ?f)) [eintF (Oldf ?f) ?al] = eintF (Oldf ?f) ?al›*) f (*‹wtFsym f›*) by auto moreover have "intF f al ∈ (eintF (Tag (resOf f)) o singl) ` {b. eintT (resOf f) b}" unfolding intF_def (*goal: ‹(if unprot (resOf f) ∨ protFw (resOf f) then eintF (Oldf f) (map2 ntsem (arOf f) al) else eintF (Tag (resOf f)) [eintF (Oldf f) (map2 ntsem (arOf f) al)]) ∈ (eintF (Tag (resOf f)) ∘ singl) ` {b. eintT (resOf f) b}›*) using "1" (*‹eintT (resOf f) (eintF (Oldf f) (map2 ntsem (arOf f) al))›*) unprot (*‹¬ unprot (resOf f)›*) False (*‹¬ protFw (resOf f)›*) by (auto simp add: singl_def (*‹singl ?a = [?a]›*)) ultimately show "?thesis" (*goal: ‹intT (resOf f) (intF f al)›*) using False (*‹¬ protFw (resOf f)›*) unfolding intT_def (*goal: ‹if unprot (resOf f) then eintT (resOf f) (intF f al) else if protFw (resOf f) then eintT (resOf f) (intF f al) ∧ eintF (Tag (resOf f)) [intF f al] = intF f al else eintT (resOf f) (intF f al) ∧ intF f al ∈ (eintF (Tag (resOf f)) ∘ singl) ` {b. eintT (resOf f) b}›*) by simp qed qed qed lemma Struct: "Struct wtFsym wtPsym arOf resOf intT intF intP" apply standard (*goal: ‹Ik.SStruct intT intF intP›*) using NE_intT_forget (*‹∃a. intT ?σ a›*) wt_intF (*‹⟦wtFsym ?f; list_all2 intT (arOf ?f) ?al⟧ ⟹ intT (resOf ?f) (intF ?f ?al)›*) apply - (*goals: 1. ‹⋀σ. ⟦⋀σ. ∃a. intT σ a; ⋀f al. ⟦wtFsym f; list_all2 intT (arOf f) al⟧ ⟹ intT (resOf f) (intF f al)⟧ ⟹ ∃a. intT σ a› 2. ‹⋀f al. ⟦wtFsym f; list_all2 intT (arOf f) al; ⋀σ. ∃a. intT σ a; ⋀f al. ⟦wtFsym f; list_all2 intT (arOf f) al⟧ ⟹ intT (resOf f) (intF f al)⟧ ⟹ intT (resOf f) (intF f al)› 3. ‹⟦⋀σ. ∃a. intT σ a; ⋀f al. ⟦wtFsym f; list_all2 intT (arOf f) al⟧ ⟹ intT (resOf f) (intF f al)⟧ ⟹ intP = intP› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . end (* context ProblemIkTpart_TEModel *) sublocale ProblemIkTpart_TEModel < Ik? : Struct where intT = intT and intF = intF and intP = intP using Struct (*‹Ik.SStruct intT intF intP›*) . context ProblemIkTpart_TEModel begin (* The inverse of the tag function (required for translating environments backwards)*) definition "invt σ a ≡ if unprot σ ∨ protFw σ then a else (SOME b. eintT σ b ∧ eintF (Tag σ) [b] = a)" lemma unprot_invt[simp]: "unprot σ ∨ protFw σ ⟹ invt σ a = a" unfolding invt_def (*goal: ‹unprot (σ::'tp) ∨ (protFw::'tp ⇒ bool) σ ⟹ (if unprot σ ∨ protFw σ then a::univ else SOME b::univ. (eintT::'tp ⇒ univ ⇒ bool) σ b ∧ (eintF::('fsym, 'tp) efsym ⇒ univ list ⇒ univ) (Tag σ) [b] = a) = a›*) by auto lemma invt_invt_inImage: assumes σ: "¬ unprot σ" "¬ protFw σ" and a: "a ∈ (eintF (Tag σ) o singl) ` {b. eintT σ b}" shows "eintT σ (invt σ a) ∧ eintF (Tag σ) [invt σ a] = a" proof (-) (*goal: ‹eintT σ (invt σ a) ∧ eintF (Tag σ) [invt σ a] = a›*) obtain b where "eintT σ b" and "eintF (Tag σ) [b] = a" (*goal: ‹(⋀b. ⟦eintT σ b; eintF (Tag σ) [b] = a⟧ ⟹ thesis) ⟹ thesis›*) using a (*‹a ∈ (eintF (Tag σ) ∘ singl) ` {b. eintT σ b}›*) unfolding image_def singl_def[symmetric] (*goal: ‹(⋀b::univ. ⟦(eintT::'tp ⇒ univ ⇒ bool) (σ::'tp) b; (eintF::('fsym, 'tp) efsym ⇒ univ list ⇒ univ) (Tag σ) (singl b) = (a::univ)⟧ ⟹ thesis::bool) ⟹ thesis›*) by auto thus "?thesis" (*goal: ‹eintT σ (invt σ a) ∧ eintF (Tag σ) [invt σ a] = a›*) using "σ" (*‹¬ unprot σ› ‹¬ protFw σ›*) unfolding invt_def (*goal: ‹eintT σ (if unprot σ ∨ protFw σ then a else SOME b. eintT σ b ∧ eintF (Tag σ) [b] = a) ∧ eintF (Tag σ) [if unprot σ ∨ protFw σ then a else SOME b. eintT σ b ∧ eintF (Tag σ) [b] = a] = a›*) apply simp (*goal: ‹eintT σ (if unprot σ ∨ protFw σ then a else SOME b. eintT σ b ∧ eintF (Tag σ) [b] = a) ∧ eintF (Tag σ) [if unprot σ ∨ protFw σ then a else SOME b. eintT σ b ∧ eintF (Tag σ) [b] = a] = a›*) apply (rule someI_ex (*‹∃x. ?P x ⟹ ?P (SOME x. ?P x)›*)) (*goal: ‹⟦eintT σ b; eintF (Tag σ) [b] = a; ¬ unprot σ; ¬ protFw σ⟧ ⟹ eintT σ (SOME b. eintT σ b ∧ eintF (Tag σ) [b] = a) ∧ eintF (Tag σ) [SOME b. eintT σ b ∧ eintF (Tag σ) [b] = a] = a›*) by auto qed lemmas invt[simp] = invt_invt_inImage[THEN conjunct1] lemmas invt_inImage[simp] = invt_invt_inImage[THEN conjunct2] (* We translate the environments of the tag-extended-problem model to environments of its original-signature reduct: *) term invt definition "eenv ξ x ≡ invt (tpOfV x) (ξ x)" lemma wt_eenv: assumes ξ: "Ik.wtE ξ" shows "TE.wtE (eenv ξ)" unfolding TE.wtE_def (*goal: ‹∀x. eintT (TE.tpOfV x) (eenv ξ x)›*) proof (safe) (*goal: ‹⋀x. eintT (TE.tpOfV x) (eenv ξ x)›*) fix x let ?σ = "TE.tpOfV x" show "eintT ?σ (eenv ξ x)" proof (cases "unprot ?σ") (*goals: 1. ‹unprot (TE.tpOfV x) ⟹ eintT (TE.tpOfV x) (eenv ξ x)› 2. ‹¬ unprot (TE.tpOfV x) ⟹ eintT (TE.tpOfV x) (eenv ξ x)›*) case True (*‹unprot (TE.tpOfV x)›*) note unprot = True (*‹unprot (TE.tpOfV x)›*) thus "?thesis" (*goal: ‹eintT (TE.tpOfV x) (eenv ξ x)›*) unfolding eenv_def (*goal: ‹eintT (TE.tpOfV x) (invt (TE.tpOfV x) (ξ x))›*) by (metis ξ (*‹Ik.wtE (ξ::Preliminaries.var ⇒ univ)›*) Ik.wtTE_intT (*‹Ik.wtE (?ξ::Preliminaries.var ⇒ univ) ⟹ intT (TE.tpOfV (?x::Preliminaries.var)) (?ξ ?x)›*) intT_def (*‹intT (?σ::'tp) (?a::univ) ≡ if unprot ?σ then (eintT::'tp ⇒ univ ⇒ bool) ?σ ?a else if (protFw::'tp ⇒ bool) ?σ then eintT ?σ ?a ∧ (eintF::('fsym, 'tp) efsym ⇒ univ list ⇒ univ) (Tag ?σ) [?a] = ?a else eintT ?σ ?a ∧ ?a ∈ (eintF (Tag ?σ) ∘ singl) ` {b::univ. eintT ?σ b}›*) unprot_invt (*‹unprot (?σ::'tp) ∨ (protFw::'tp ⇒ bool) ?σ ⟹ invt ?σ (?a::univ) = ?a›*)) next (*goal: ‹¬ unprot (TE.tpOfV x) ⟹ eintT (TE.tpOfV x) (eenv ξ x)›*) case False (*‹¬ unprot (TE.tpOfV x)›*) note unprot = False (*‹¬ unprot (TE.tpOfV x)›*) show "?thesis" (*goal: ‹eintT (TE.tpOfV x) (eenv ξ x)›*) proof (cases "protFw ?σ") (*goals: 1. ‹protFw (TE.tpOfV x) ⟹ eintT (TE.tpOfV x) (eenv ξ x)› 2. ‹¬ protFw (TE.tpOfV x) ⟹ eintT (TE.tpOfV x) (eenv ξ x)›*) case True (*‹protFw (TE.tpOfV x)›*) thus "?thesis" (*goal: ‹eintT (TE.tpOfV x) (eenv ξ x)›*) unfolding eenv_def (*goal: ‹eintT (TE.tpOfV x) (invt (TE.tpOfV x) (ξ x))›*) using unprot (*‹¬ unprot (TE.tpOfV (x::Preliminaries.var))›*) "ξ" (*‹Ik.wtE ξ›*) by (metis Ik.wtTE_intT (*‹Ik.wtE ?ξ ⟹ intT (TE.tpOfV ?x) (?ξ ?x)›*) intT_def (*‹intT ?σ ?a ≡ if unprot ?σ then eintT ?σ ?a else if protFw ?σ then eintT ?σ ?a ∧ eintF (Tag ?σ) [?a] = ?a else eintT ?σ ?a ∧ ?a ∈ (eintF (Tag ?σ) ∘ singl) ` {b. eintT ?σ b}›*) unprot_invt (*‹unprot ?σ ∨ protFw ?σ ⟹ invt ?σ ?a = ?a›*)) next (*goal: ‹¬ protFw (TE.tpOfV x) ⟹ eintT (TE.tpOfV x) (eenv ξ x)›*) case False (*‹¬ (protFw::'tp ⇒ bool) (TE.tpOfV (x::Preliminaries.var))›*) thus "?thesis" (*goal: ‹(eintT::'tp ⇒ univ ⇒ bool) (TE.tpOfV (x::Preliminaries.var)) (eenv (ξ::Preliminaries.var ⇒ univ) x)›*) unfolding eenv_def (*goal: ‹(eintT::'tp ⇒ univ ⇒ bool) (TE.tpOfV (x::Preliminaries.var)) (invt (TE.tpOfV x) ((ξ::Preliminaries.var ⇒ univ) x))›*) using unprot (*‹¬ unprot (TE.tpOfV x)›*) "ξ" (*‹Ik.wtE ξ›*) by (metis (no_types) ξ (*‹Ik.wtE ξ›*) Ik.wtE_def (*‹Ik.wtE ?ξ ≡ ∀x. intT (TE.tpOfV x) (?ξ x)›*) intT_def (*‹intT ?σ ?a ≡ if unprot ?σ then eintT ?σ ?a else if protFw ?σ then eintT ?σ ?a ∧ eintF (Tag ?σ) [?a] = ?a else eintT ?σ ?a ∧ ?a ∈ (eintF (Tag ?σ) ∘ singl) ` {b. eintT ?σ b}›*) invt (*‹⟦¬ unprot ?σ; ¬ protFw ?σ; ?a ∈ (eintF (Tag ?σ) ∘ singl) ` {b. eintT ?σ b}⟧ ⟹ eintT ?σ (invt ?σ ?a)›*)) qed qed qed lemma int_tNN[simp]: assumes T: "Ik.Ik.wt T" and ξ: "Ik.wtE ξ" shows "TE.int (eenv ξ) (tNN T) = Ik.int ξ T" using T (*‹Ik.wt T›*) proof (induct T) (*goals: 1. ‹⋀x. Ik.wt (Var x) ⟹ TE.int (eenv ξ) (tNN (Var x)) = Ik.int ξ (Var x)› 2. ‹⋀f Tl. ⟦list_all (λa. Ik.wt a ⟶ TE.int (eenv ξ) (tNN a) = Ik.int ξ a) Tl; Ik.wt (Fn f Tl)⟧ ⟹ TE.int (eenv ξ) (tNN (Fn f Tl)) = Ik.int ξ (Fn f Tl)›*) case (Var x) (*‹Ik.wt (Var x)›*) let ?σ = "TE.tpOfV x" show "?case" (*goal: ‹TE.int (eenv ξ) (tNN (Var x)) = Ik.int ξ (Var x)›*) proof (cases "unprot ?σ") (*goals: 1. ‹unprot (TE.tpOfV x) ⟹ TE.int (eenv ξ) (tNN (Var x)) = Ik.int ξ (Var x)› 2. ‹¬ unprot (TE.tpOfV x) ⟹ TE.int (eenv ξ) (tNN (Var x)) = Ik.int ξ (Var x)›*) case False (*‹¬ unprot (TE.tpOfV x)›*) note unprot = False (*‹¬ unprot (TE.tpOfV x)›*) show "?thesis" (*goal: ‹TE.int (eenv ξ) (tNN (Var x)) = Ik.int ξ (Var x)›*) proof (cases "protFw ?σ") (*goals: 1. ‹protFw (TE.tpOfV x) ⟹ TE.int (eenv ξ) (tNN (Var x)) = Ik.int ξ (Var x)› 2. ‹¬ protFw (TE.tpOfV x) ⟹ TE.int (eenv ξ) (tNN (Var x)) = Ik.int ξ (Var x)›*) case True (*‹protFw (TE.tpOfV x)›*) thus "?thesis" (*goal: ‹TE.int (eenv ξ) (tNN (Var x)) = Ik.int ξ (Var x)›*) using unprot (*‹¬ unprot (TE.tpOfV x)›*) "ξ" (*‹Ik.wtE ξ›*) unfolding eenv_def Ik.wtE_def intT_def (*goal: ‹TE.int (λa. invt (TE.tpOfV a) (ξ a)) (tNN (Var x)) = Ik.int ξ (Var x)›*) by simp next (*goal: ‹¬ protFw (TE.tpOfV x) ⟹ TE.int (eenv ξ) (tNN (Var x)) = Ik.int ξ (Var x)›*) case False (*‹¬ protFw (TE.tpOfV x)›*) hence "ξ x ∈ (eintF (Tag ?σ) ∘ singl) ` {b. eintT ?σ b}" using "ξ" (*‹Ik.wtE (ξ::Preliminaries.var ⇒ univ)›*) unprot (*‹¬ unprot (TE.tpOfV x)›*) unfolding wtE_def intT_def singl_def[abs_def] (*goal: ‹ξ x ∈ (eintF (Tag (TE.tpOfV x)) ∘ (λa. [a])) ` {b. eintT (TE.tpOfV x) b}›*) by (simp cong del: image_cong_simp (*‹⟦?M = ?N; ⋀x. x ∈ ?N =simp=> ?f x = ?g x⟧ ⟹ ?f ` ?M = ?g ` ?N›*)) thus "?thesis" (*goal: ‹TE.int (eenv ξ) (tNN (Var x)) = Ik.int ξ (Var x)›*) using unprot (*‹¬ unprot (TE.tpOfV x)›*) unfolding eenv_def (*goal: ‹TE.int (λa. invt (TE.tpOfV a) (ξ a)) (tNN (Var x)) = Ik.int ξ (Var x)›*) using False (*‹¬ protFw (TE.tpOfV x)›*) by simp qed qed (unfold eenv_def (*‹eenv (?ξ::Preliminaries.var ⇒ univ) (?x::Preliminaries.var) ≡ invt (TE.tpOfV ?x) (?ξ ?x)›*), simp) (*solved the remaining goal: ‹unprot (TE.tpOfV x) ⟹ TE.int (eenv ξ) (tNN (Var x)) = Ik.int ξ (Var x)›*) next (*goal: ‹⋀f Tl. ⟦list_all (λa. Ik.wt a ⟶ TE.int (eenv ξ) (tNN a) = Ik.int ξ a) Tl; Ik.wt (Fn f Tl)⟧ ⟹ TE.int (eenv ξ) (tNN (Fn f Tl)) = Ik.int ξ (Fn f Tl)›*) case (Fn f Tl) (*‹list_all (λa. Ik.wt a ⟶ TE.int (eenv ξ) (tNN a) = Ik.int ξ a) Tl› ‹Ik.wt (Fn f Tl)›*) let ?eξ = "eenv ξ" let ?ar = "arOf f" let ?r = "resOf f" have l: "length ?ar = length Tl" using Fn (*‹list_all (λa. Ik.wt a ⟶ TE.int (eenv ξ) (tNN a) = Ik.int ξ a) Tl› ‹Ik.wt (Fn f Tl)›*) by simp have 0: "map2 ntsem ?ar (map (Ik.int ξ) Tl) = map (TE.int ?eξ ∘ tNN) Tl" (is "?L = ?R") proof (rule nth_equalityI (*‹⟦length (?xs::?'a list) = length (?ys::?'a list); ⋀i::nat. i < length ?xs ⟹ ?xs ! i = ?ys ! i⟧ ⟹ ?xs = ?ys›*)) (*goals: 1. ‹length (map2 ntsem (arOf f) (map (Ik.int ξ) Tl)) = length (map (TE.int (eenv ξ) ∘ tNN) Tl)› 2. ‹⋀i. i < length (map2 ntsem (arOf f) (map (Ik.int ξ) Tl)) ⟹ map2 ntsem (arOf f) (map (Ik.int ξ) Tl) ! i = map (TE.int (eenv ξ) ∘ tNN) Tl ! i›*) fix i assume "i < length ?L" (*‹(i::nat) < length (map2 ntsem ((arOf::'fsym ⇒ 'tp list) (f::'fsym)) (map (Ik.int (ξ::Preliminaries.var ⇒ univ)) (Tl::'fsym trm list)))›*) hence i: "i < length ?ar" using l (*‹length (arOf f) = length Tl›*) by simp hence 1: "TE.int (eenv ξ) (tNN (Tl!i)) = Ik.int ξ (Tl!i)" using Fn (*‹list_all (λa. Ik.wt a ⟶ TE.int (eenv ξ) (tNN a) = Ik.int ξ a) Tl› ‹Ik.wt (Fn f Tl)›*) by (auto simp: list_all_length (*‹list_all (?P::?'a ⇒ bool) (?xs::?'a list) = (∀n<length ?xs. ?P (?xs ! n))›*)) have 2: "?ar ! i = Ik.Ik.tpOf (Tl!i)" using Fn (*‹list_all (λa. Ik.wt a ⟶ TE.int (eenv ξ) (tNN a) = Ik.int ξ a) Tl› ‹Ik.wt (Fn (f::'fsym) (Tl::'fsym trm list))›*) i (*‹i < length (arOf f)›*) by simp have 3: "intT (?ar ! i) (Ik.int ξ (Tl ! i))" unfolding "2" (*goal: ‹intT (Ik.tpOf ((Tl::'fsym::type trm list) ! (i::nat))) (Ik.int (ξ::Preliminaries.var ⇒ univ) (Tl ! i))›*) apply (rule wt_int (*‹⟦Ik.wtE ?ξ; Ik.wt ?T⟧ ⟹ intT (Ik.tpOf ?T) (Ik.int ?ξ ?T)›*)) (*goal: ‹intT (Ik.tpOf (Tl ! i)) (Ik.int ξ (Tl ! i))›*) using Fn (*‹list_all (λa. Ik.wt a ⟶ TE.int (eenv ξ) (tNN a) = Ik.int ξ a) Tl› ‹Ik.wt (Fn f Tl)›*) "ξ" (*‹Ik.wtE ξ›*) i (*‹(i::nat) < length ((arOf::'fsym::type ⇒ 'tp::type list) (f::'fsym::type))›*) apply - (*goals: 1. ‹⟦list_all (λa. Ik.wt a ⟶ TE.int (eenv ξ) (tNN a) = Ik.int ξ a) Tl; Ik.wt (Fn f Tl); Ik.wtE ξ; i < length (arOf f)⟧ ⟹ Ik.wtE ξ› 2. ‹⟦list_all (λa. Ik.wt a ⟶ TE.int (eenv ξ) (tNN a) = Ik.int ξ a) Tl; Ik.wt (Fn f Tl); Ik.wtE ξ; i < length (arOf f)⟧ ⟹ Ik.wt (Tl ! i)› discuss goal 1*) apply ((auto simp: list_all_length (*‹list_all (?P::?'a ⇒ bool) (?xs::?'a list) = (∀n<length ?xs. ?P (?xs ! n))›*))[1]) (*discuss goal 2*) apply ((auto simp: list_all_length (*‹list_all ?P ?xs = (∀n<length ?xs. ?P (?xs ! n))›*))[1]) (*proven 2 subgoals*) . show "?L!i = ?R!i" apply (cases "unprot (?ar ! i) ∨ protFw (?ar ! i)") (*goal: ‹map2 ntsem (arOf f) (map (Ik.int ξ) Tl) ! i = map (TE.int (eenv ξ) ∘ tNN) Tl ! i›*) using i (*‹i < length (arOf f)›*) "1" (*‹TE.int (eenv (ξ::Preliminaries.var ⇒ univ)) (tNN ((Tl::'fsym::type trm list) ! (i::nat))) = Ik.int ξ (Tl ! i)›*) l (*‹length (arOf f) = length Tl›*) "3" (*‹intT ((arOf::'fsym ⇒ 'tp list) (f::'fsym) ! (i::nat)) (Ik.int (ξ::Preliminaries.var ⇒ univ) ((Tl::'fsym trm list) ! i))›*) unfolding intT_def (*goals: 1. ‹unprot (arOf f ! i) ∨ protFw (arOf f ! i) ⟹ map2 ntsem (arOf f) (map (Ik.int ξ) Tl) ! i = map (TE.int (eenv ξ) ∘ tNN) Tl ! i› 2. ‹¬ (unprot (arOf f ! i) ∨ protFw (arOf f ! i)) ⟹ map2 ntsem (arOf f) (map (Ik.int ξ) Tl) ! i = map (TE.int (eenv ξ) ∘ tNN) Tl ! i›*) apply - (*goals: 1. ‹⟦unprot (arOf f ! i) ∨ protFw (arOf f ! i); i < length (arOf f); TE.int (eenv ξ) (tNN (Tl ! i)) = Ik.int ξ (Tl ! i); length (arOf f) = length Tl; if unprot (arOf f ! i) then eintT (arOf f ! i) (Ik.int ξ (Tl ! i)) else if protFw (arOf f ! i) then eintT (arOf f ! i) (Ik.int ξ (Tl ! i)) ∧ eintF (Tag (arOf f ! i)) [Ik.int ξ (Tl ! i)] = Ik.int ξ (Tl ! i) else eintT (arOf f ! i) (Ik.int ξ (Tl ! i)) ∧ Ik.int ξ (Tl ! i) ∈ (eintF (Tag (arOf f ! i)) ∘ singl) ` {b. eintT (arOf f ! i) b}⟧ ⟹ map2 ntsem (arOf f) (map (Ik.int ξ) Tl) ! i = map (TE.int (eenv ξ) ∘ tNN) Tl ! i› 2. ‹⟦¬ (unprot (arOf f ! i) ∨ protFw (arOf f ! i)); i < length (arOf f); TE.int (eenv ξ) (tNN (Tl ! i)) = Ik.int ξ (Tl ! i); length (arOf f) = length Tl; if unprot (arOf f ! i) then eintT (arOf f ! i) (Ik.int ξ (Tl ! i)) else if protFw (arOf f ! i) then eintT (arOf f ! i) (Ik.int ξ (Tl ! i)) ∧ eintF (Tag (arOf f ! i)) [Ik.int ξ (Tl ! i)] = Ik.int ξ (Tl ! i) else eintT (arOf f ! i) (Ik.int ξ (Tl ! i)) ∧ Ik.int ξ (Tl ! i) ∈ (eintF (Tag (arOf f ! i)) ∘ singl) ` {b. eintT (arOf f ! i) b}⟧ ⟹ map2 ntsem (arOf f) (map (Ik.int ξ) Tl) ! i = map (TE.int (eenv ξ) ∘ tNN) Tl ! i› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed (insert l (*‹length (arOf f) = length Tl›*), auto) (*solved the remaining goal: ‹length (map2 ntsem (arOf f) (map (Ik.int ξ) Tl)) = length (map (TE.int (eenv ξ) ∘ tNN) Tl)›*) show "?case" (*goal: ‹TE.int (eenv (ξ::Preliminaries.var ⇒ univ)) (tNN (Fn (f::'fsym::type) (Tl::'fsym::type trm list))) = Ik.int ξ (Fn f Tl)›*) apply (cases "unprot ?r ∨ protFw ?r") (*goal: ‹TE.int (eenv ξ) (tNN (Fn f Tl)) = Ik.int ξ (Fn f Tl)›*) using [unfold_abs_def = false] (*‹TERM _›*) unfolding Ik.int.simps TE.int.simps tT.simps (*goals: 1. ‹unprot (resOf f) ∨ protFw (resOf f) ⟹ TE.int (eenv ξ) (tNN (Fn f Tl)) = intF f (map (Ik.int ξ) Tl)› 2. ‹¬ (unprot (resOf f) ∨ protFw (resOf f)) ⟹ TE.int (eenv ξ) (tNN (Fn f Tl)) = intF f (map (Ik.int ξ) Tl)›*) unfolding intF_def (*goals: 1. ‹unprot (resOf f) ∨ protFw (resOf f) ⟹ TE.int (eenv ξ) (tNN (Fn f Tl)) = (if unprot (resOf f) ∨ protFw (resOf f) then eintF (Oldf f) (map2 ntsem (arOf f) (map (Ik.int ξ) Tl)) else eintF (Tag (resOf f)) [eintF (Oldf f) (map2 ntsem (arOf f) (map (Ik.int ξ) Tl))])› 2. ‹¬ (unprot (resOf f) ∨ protFw (resOf f)) ⟹ TE.int (eenv ξ) (tNN (Fn f Tl)) = (if unprot (resOf f) ∨ protFw (resOf f) then eintF (Oldf f) (map2 ntsem (arOf f) (map (Ik.int ξ) Tl)) else eintF (Tag (resOf f)) [eintF (Oldf f) (map2 ntsem (arOf f) (map (Ik.int ξ) Tl))])›*) using Fn (*‹list_all (λa. Ik.wt a ⟶ TE.int (eenv ξ) (tNN a) = Ik.int ξ a) Tl› ‹Ik.wt (Fn f Tl)›*) "0" (*‹map2 ntsem (arOf f) (map (Ik.int ξ) Tl) = map (TE.int (eenv ξ) ∘ tNN) Tl›*) apply - (*goals: 1. ‹⟦unprot ((resOf::'fsym ⇒ 'tp) (f::'fsym)) ∨ (protFw::'tp ⇒ bool) (resOf f); list_all (λa::'fsym trm. Ik.wt a ⟶ TE.int (eenv (ξ::Preliminaries.var ⇒ univ)) (tNN a) = Ik.int ξ a) (Tl::'fsym trm list); Ik.wt (Fn f Tl); map2 ntsem ((arOf::'fsym ⇒ 'tp list) f) (map (Ik.int ξ) Tl) = map (TE.int (eenv ξ) ∘ tNN) Tl⟧ ⟹ TE.int (eenv ξ) (tNN (Fn f Tl)) = (if unprot (resOf f) ∨ protFw (resOf f) then (eintF::('fsym, 'tp) efsym ⇒ univ list ⇒ univ) (Oldf f) (map2 ntsem (arOf f) (map (Ik.int ξ) Tl)) else eintF (Tag (resOf f)) [eintF (Oldf f) (map2 ntsem (arOf f) (map (Ik.int ξ) Tl))])› 2. ‹⟦¬ (unprot ((resOf::'fsym ⇒ 'tp) (f::'fsym)) ∨ (protFw::'tp ⇒ bool) (resOf f)); list_all (λa::'fsym trm. Ik.wt a ⟶ TE.int (eenv (ξ::Preliminaries.var ⇒ univ)) (tNN a) = Ik.int ξ a) (Tl::'fsym trm list); Ik.wt (Fn f Tl); map2 ntsem ((arOf::'fsym ⇒ 'tp list) f) (map (Ik.int ξ) Tl) = map (TE.int (eenv ξ) ∘ tNN) Tl⟧ ⟹ TE.int (eenv ξ) (tNN (Fn f Tl)) = (if unprot (resOf f) ∨ protFw (resOf f) then (eintF::('fsym, 'tp) efsym ⇒ univ list ⇒ univ) (Oldf f) (map2 ntsem (arOf f) (map (Ik.int ξ) Tl)) else eintF (Tag (resOf f)) [eintF (Oldf f) (map2 ntsem (arOf f) (map (Ik.int ξ) Tl))])› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed lemma map_int_tNN[simp]: assumes Tl: "list_all Ik.Ik.wt Tl" and ξ: "Ik.wtE ξ" shows "map2 ntsem (map Ik.Ik.tpOf Tl) (map (Ik.int ξ) Tl) = map (TE.int (eenv ξ) ∘ tNN) Tl" proof (-) (*goal: ‹map2 ntsem (map Ik.tpOf Tl) (map (Ik.int ξ) Tl) = map (TE.int (eenv ξ) ∘ tNN) Tl›*) { fix i assume i: "i < length Tl" (*‹(i::nat) < length (Tl::'fsym trm list)›*) hence wt: "Ik.Ik.wt (Tl!i)" using Tl (*‹list_all Ik.wt Tl›*) unfolding list_all_length (*goal: ‹Ik.wt (Tl ! i)›*) by simp have "intT (Ik.Ik.tpOf (Tl!i)) (Ik.int ξ (Tl!i))" using Ik.wt_int[OF ξ wt] (*‹intT (Ik.tpOf (Tl ! i)) (Ik.int ξ (Tl ! i))›*) . } thus "?thesis" (*goal: ‹map2 ntsem (map Ik.tpOf Tl) (map (Ik.int ξ) Tl) = map (TE.int (eenv ξ) ∘ tNN) Tl›*) using [unfold_abs_def = false] (*‹TERM _›*) using assms (*‹list_all Ik.wt (Tl::'fsym trm list)› ‹Ik.wtE ξ›*) unfolding intT_def list_all_length (*goal: ‹map2 ntsem (map Ik.tpOf Tl) (map (Ik.int ξ) Tl) = map (TE.int (eenv ξ) ∘ tNN) Tl›*) unfolding list_eq_iff (*goal: ‹length (map2 ntsem (map Ik.tpOf Tl) (map (Ik.int ξ) Tl)) = length (map (TE.int (eenv ξ) ∘ tNN) Tl) ∧ (∀i<length (map2 ntsem (map Ik.tpOf Tl) (map (Ik.int ξ) Tl)). map2 ntsem (map Ik.tpOf Tl) (map (Ik.int ξ) Tl) ! i = map (TE.int (eenv ξ) ∘ tNN) Tl ! i)›*) apply clarsimp (*goal: ‹length (map2 ntsem (map Ik.tpOf Tl) (map (Ik.int ξ) Tl)) = length (map (TE.int (eenv ξ) ∘ tNN) Tl) ∧ (∀i<length (map2 ntsem (map Ik.tpOf Tl) (map (Ik.int ξ) Tl)). map2 ntsem (map Ik.tpOf Tl) (map (Ik.int ξ) Tl) ! i = map (TE.int (eenv ξ) ∘ tNN) Tl ! i)›*) by (metis inImage_ntsem (*‹?a ∈ (eintF (Tag ?σ) ∘ singl) ` {b. eintT ?σ b} ⟹ ntsem ?σ ?a = ?a›*) unprot_ntsem (*‹unprot ?σ ∨ protFw ?σ ⟹ ntsem ?σ ?a = ?a›*)) qed lemma int_t[simp]: assumes T: "Ik.Ik.wt T" and ξ: "Ik.wtE ξ" shows "TE.int (eenv ξ) (tT T) = Ik.int ξ T" using T (*‹Ik.wt T›*) proof (induct T) (*goals: 1. ‹⋀x::Preliminaries.var. Ik.wt (Var x) ⟹ TE.int (eenv (ξ::Preliminaries.var ⇒ univ)) (tT (Var x)) = Ik.int ξ (Var x)› 2. ‹⋀(f::'fsym) Tl::'fsym trm list. ⟦list_all (λa::'fsym trm. Ik.wt a ⟶ TE.int (eenv (ξ::Preliminaries.var ⇒ univ)) (tT a) = Ik.int ξ a) Tl; Ik.wt (Fn f Tl)⟧ ⟹ TE.int (eenv ξ) (tT (Fn f Tl)) = Ik.int ξ (Fn f Tl)›*) case (Var x) (*‹Ik.wt (Var x)›*) let ?σ = "tpOfV x" show "?case" (*goal: ‹TE.int (eenv ξ) (tT (Var x)) = Ik.int ξ (Var x)›*) proof (cases "unprot ?σ") (*goals: 1. ‹unprot (TE.tpOfV x) ⟹ TE.int (eenv ξ) (tT (Var x)) = Ik.int ξ (Var x)› 2. ‹¬ unprot (TE.tpOfV x) ⟹ TE.int (eenv ξ) (tT (Var x)) = Ik.int ξ (Var x)›*) case False (*‹¬ unprot (TE.tpOfV x)›*) note unprot = False (*‹¬ unprot (TE.tpOfV x)›*) show "?thesis" (*goal: ‹TE.int (eenv ξ) (tT (Var x)) = Ik.int ξ (Var x)›*) proof (cases "protFw ?σ") (*goals: 1. ‹protFw (TE.tpOfV x) ⟹ TE.int (eenv ξ) (tT (Var x)) = Ik.int ξ (Var x)› 2. ‹¬ protFw (TE.tpOfV x) ⟹ TE.int (eenv ξ) (tT (Var x)) = Ik.int ξ (Var x)›*) case True (*‹protFw (TE.tpOfV x)›*) thus "?thesis" (*goal: ‹TE.int (eenv ξ) (tT (Var x)) = Ik.int ξ (Var x)›*) using unprot (*‹¬ unprot (TE.tpOfV x)›*) "ξ" (*‹Ik.wtE ξ›*) unfolding eenv_def Ik.wtE_def intT_def (*goal: ‹TE.int (λa. invt (TE.tpOfV a) (ξ a)) (tT (Var x)) = Ik.int ξ (Var x)›*) by simp next (*goal: ‹¬ protFw (TE.tpOfV x) ⟹ TE.int (eenv ξ) (tT (Var x)) = Ik.int ξ (Var x)›*) case False (*‹¬ (protFw::'tp ⇒ bool) (TE.tpOfV (x::Preliminaries.var))›*) hence "ξ x ∈ (eintF (Tag ?σ) ∘ singl) ` {b. eintT ?σ b}" using "ξ" (*‹Ik.wtE (ξ::Preliminaries.var ⇒ univ)›*) unprot (*‹¬ unprot (TE.tpOfV x)›*) unfolding wtE_def intT_def singl_def[abs_def] (*goal: ‹ξ x ∈ (eintF (Tag (TE.tpOfV x)) ∘ (λa. [a])) ` {b. eintT (TE.tpOfV x) b}›*) by (simp cong del: image_cong_simp (*‹⟦?M = ?N; ⋀x. x ∈ ?N =simp=> ?f x = ?g x⟧ ⟹ ?f ` ?M = ?g ` ?N›*)) thus "?thesis" (*goal: ‹TE.int (eenv ξ) (tT (Var x)) = Ik.int ξ (Var x)›*) using unprot (*‹¬ unprot (TE.tpOfV x)›*) unfolding eenv_def (*goal: ‹TE.int (λa. invt (TE.tpOfV a) (ξ a)) (tT (Var x)) = Ik.int ξ (Var x)›*) using False (*‹¬ protFw (TE.tpOfV x)›*) by simp qed qed (unfold eenv_def (*‹eenv (?ξ::Preliminaries.var ⇒ univ) (?x::Preliminaries.var) ≡ invt (TE.tpOfV ?x) (?ξ ?x)›*), simp) (*solved the remaining goal: ‹unprot (TE.tpOfV x) ⟹ TE.int (eenv ξ) (tT (Var x)) = Ik.int ξ (Var x)›*) next (*goal: ‹⋀f Tl. ⟦list_all (λa. Ik.wt a ⟶ TE.int (eenv ξ) (tT a) = Ik.int ξ a) Tl; Ik.wt (Fn f Tl)⟧ ⟹ TE.int (eenv ξ) (tT (Fn f Tl)) = Ik.int ξ (Fn f Tl)›*) case (Fn f Tl) (*‹list_all (λa. Ik.wt a ⟶ TE.int (eenv ξ) (tT a) = Ik.int ξ a) Tl› ‹Ik.wt (Fn f Tl)›*) let ?eξ = "eenv ξ" let ?ar = "arOf f" let ?r = "resOf f" have l: "length ?ar = length Tl" using Fn (*‹list_all (λa::'fsym::type trm. Ik.wt a ⟶ TE.int (eenv (ξ::Preliminaries.var ⇒ univ)) (tT a) = Ik.int ξ a) (Tl::'fsym::type trm list)› ‹Ik.wt (Fn f Tl)›*) by simp have ar: "?ar = map Ik.Ik.tpOf Tl" using Fn (*‹list_all (λa. Ik.wt a ⟶ TE.int (eenv ξ) (tT a) = Ik.int ξ a) Tl› ‹Ik.wt (Fn f Tl)›*) by simp have 0: "map2 ntsem ?ar (map (Ik.int ξ) Tl) = map (TE.int ?eξ ∘ tNN) Tl" unfolding ar (*goal: ‹map2 ntsem (map Ik.tpOf Tl) (map (Ik.int ξ) Tl) = map (TE.int (eenv ξ) ∘ tNN) Tl›*) apply (rule map_int_tNN[OF _ ξ] (*‹list_all Ik.wt ?Tl ⟹ map2 ntsem (map Ik.tpOf ?Tl) (map (Ik.int ξ) ?Tl) = map (TE.int (eenv ξ) ∘ tNN) ?Tl›*)) (*goal: ‹map2 ntsem (map Ik.tpOf Tl) (map (Ik.int ξ) Tl) = map (TE.int (eenv ξ) ∘ tNN) Tl›*) using Fn (*‹list_all (λa. Ik.wt a ⟶ TE.int (eenv ξ) (tT a) = Ik.int ξ a) Tl› ‹Ik.wt (Fn f Tl)›*) by simp show "?case" (*goal: ‹TE.int (eenv (ξ::Preliminaries.var ⇒ univ)) (tT (Fn (f::'fsym::type) (Tl::'fsym::type trm list))) = Ik.int ξ (Fn f Tl)›*) apply (cases "unprot ?r ∨ protFw ?r") (*goal: ‹TE.int (eenv ξ) (tT (Fn f Tl)) = Ik.int ξ (Fn f Tl)›*) using [unfold_abs_def = false] (*‹TERM _›*) unfolding Ik.int.simps TE.int.simps tT.simps (*goals: 1. ‹unprot (resOf f) ∨ protFw (resOf f) ⟹ TE.int (eenv ξ) (tNN (Fn f Tl)) = intF f (map (Ik.int ξ) Tl)› 2. ‹¬ (unprot (resOf f) ∨ protFw (resOf f)) ⟹ TE.int (eenv ξ) (tNN (Fn f Tl)) = intF f (map (Ik.int ξ) Tl)›*) unfolding intF_def (*goals: 1. ‹unprot (resOf f) ∨ protFw (resOf f) ⟹ TE.int (eenv ξ) (tNN (Fn f Tl)) = (if unprot (resOf f) ∨ protFw (resOf f) then eintF (Oldf f) (map2 ntsem (arOf f) (map (Ik.int ξ) Tl)) else eintF (Tag (resOf f)) [eintF (Oldf f) (map2 ntsem (arOf f) (map (Ik.int ξ) Tl))])› 2. ‹¬ (unprot (resOf f) ∨ protFw (resOf f)) ⟹ TE.int (eenv ξ) (tNN (Fn f Tl)) = (if unprot (resOf f) ∨ protFw (resOf f) then eintF (Oldf f) (map2 ntsem (arOf f) (map (Ik.int ξ) Tl)) else eintF (Tag (resOf f)) [eintF (Oldf f) (map2 ntsem (arOf f) (map (Ik.int ξ) Tl))])›*) using Fn (*‹list_all (λa::'fsym trm. Ik.wt a ⟶ TE.int (eenv (ξ::Preliminaries.var ⇒ univ)) (tT a) = Ik.int ξ a) (Tl::'fsym trm list)› ‹Ik.wt (Fn f Tl)›*) "0" (*‹map2 ntsem (arOf f) (map (Ik.int ξ) Tl) = map (TE.int (eenv ξ) ∘ tNN) Tl›*) apply - (*goals: 1. ‹⟦unprot ((resOf::'fsym::type ⇒ 'tp::type) (f::'fsym::type)) ∨ (protFw::'tp::type ⇒ bool) (resOf f); list_all (λa::'fsym::type trm. Ik.wt a ⟶ TE.int (eenv (ξ::Preliminaries.var ⇒ univ)) (tT a) = Ik.int ξ a) (Tl::'fsym::type trm list); Ik.wt (Fn f Tl); map2 ntsem ((arOf::'fsym::type ⇒ 'tp::type list) f) (map (Ik.int ξ) Tl) = map (TE.int (eenv ξ) ∘ tNN) Tl⟧ ⟹ TE.int (eenv ξ) (tNN (Fn f Tl)) = (if unprot (resOf f) ∨ protFw (resOf f) then (eintF::('fsym::type, 'tp::type) efsym ⇒ univ list ⇒ univ) (Oldf f) (map2 ntsem (arOf f) (map (Ik.int ξ) Tl)) else eintF (Tag (resOf f)) [eintF (Oldf f) (map2 ntsem (arOf f) (map (Ik.int ξ) Tl))])› 2. ‹⟦¬ (unprot ((resOf::'fsym::type ⇒ 'tp::type) (f::'fsym::type)) ∨ (protFw::'tp::type ⇒ bool) (resOf f)); list_all (λa::'fsym::type trm. Ik.wt a ⟶ TE.int (eenv (ξ::Preliminaries.var ⇒ univ)) (tT a) = Ik.int ξ a) (Tl::'fsym::type trm list); Ik.wt (Fn f Tl); map2 ntsem ((arOf::'fsym::type ⇒ 'tp::type list) f) (map (Ik.int ξ) Tl) = map (TE.int (eenv ξ) ∘ tNN) Tl⟧ ⟹ TE.int (eenv ξ) (tNN (Fn f Tl)) = (if unprot (resOf f) ∨ protFw (resOf f) then (eintF::('fsym::type, 'tp::type) efsym ⇒ univ list ⇒ univ) (Oldf f) (map2 ntsem (arOf f) (map (Ik.int ξ) Tl)) else eintF (Tag (resOf f)) [eintF (Oldf f) (map2 ntsem (arOf f) (map (Ik.int ξ) Tl))])› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed lemma map_int_t[simp]: assumes Tl: "list_all Ik.Ik.wt Tl" and ξ: "Ik.wtE ξ" shows "map2 ntsem (map Ik.Ik.tpOf Tl) (map (Ik.int ξ) Tl) = map (TE.int (eenv ξ) ∘ tT) Tl" proof (-) (*goal: ‹map2 ntsem (map Ik.tpOf Tl) (map (Ik.int ξ) Tl) = map (TE.int (eenv ξ) ∘ tT) Tl›*) { fix i assume i: "i < length Tl" (*‹(i::nat) < length (Tl::'fsym trm list)›*) hence wt: "Ik.Ik.wt (Tl!i)" using Tl (*‹list_all Ik.wt Tl›*) unfolding list_all_length (*goal: ‹Ik.wt (Tl ! i)›*) by simp have "intT (Ik.Ik.tpOf (Tl!i)) (Ik.int ξ (Tl!i))" using wt_int[OF ξ wt] (*‹intT (Ik.tpOf (Tl ! i)) (Ik.int ξ (Tl ! i))›*) . } thus "?thesis" (*goal: ‹map2 ntsem (map Ik.tpOf Tl) (map (Ik.int ξ) Tl) = map (TE.int (eenv ξ) ∘ tT) Tl›*) using [unfold_abs_def = false] (*‹TERM _›*) using assms (*‹list_all Ik.wt Tl› ‹Ik.wtE ξ›*) unfolding intT_def list_all_length (*goal: ‹map2 ntsem (map Ik.tpOf (Tl::'fsym trm list)) (map (Ik.int (ξ::Preliminaries.var ⇒ univ)) Tl) = map (TE.int (eenv ξ) ∘ tT) Tl›*) unfolding list_eq_iff (*goal: ‹length (map2 ntsem (map Ik.tpOf (Tl::'fsym trm list)) (map (Ik.int (ξ::Preliminaries.var ⇒ univ)) Tl)) = length (map (TE.int (eenv ξ) ∘ tT) Tl) ∧ (∀i<length (map2 ntsem (map Ik.tpOf Tl) (map (Ik.int ξ) Tl)). map2 ntsem (map Ik.tpOf Tl) (map (Ik.int ξ) Tl) ! i = map (TE.int (eenv ξ) ∘ tT) Tl ! i)›*) apply clarsimp (*goal: ‹length (map2 ntsem (map Ik.tpOf Tl) (map (Ik.int ξ) Tl)) = length (map (TE.int (eenv ξ) ∘ tT) Tl) ∧ (∀i<length (map2 ntsem (map Ik.tpOf Tl) (map (Ik.int ξ) Tl)). map2 ntsem (map Ik.tpOf Tl) (map (Ik.int ξ) Tl) ! i = map (TE.int (eenv ξ) ∘ tT) Tl ! i)›*) by (metis inImage_ntsem (*‹?a ∈ (eintF (Tag ?σ) ∘ singl) ` {b. eintT ?σ b} ⟹ ntsem ?σ ?a = ?a›*) unprot_ntsem (*‹unprot ?σ ∨ protFw ?σ ⟹ ntsem ?σ ?a = ?a›*)) qed lemma satL_tL[simp]: assumes l: "Ik.Ik.wtL l" and ξ: "Ik.wtE ξ" shows "TE.satL (eenv ξ) (tL l) ⟷ Ik.satL ξ l" using assms (*‹Ik.wtL l› ‹Ik.wtE ξ›*) apply (cases l) (*goals: 1. ‹⋀x1::('fsym, 'psym) atm. ⟦Ik.wtL (l::('fsym, 'psym) lit); Ik.wtE (ξ::Preliminaries.var ⇒ univ); l = Pos x1⟧ ⟹ TE.satL (eenv ξ) (tL l) = Ik.satL ξ l› 2. ‹⋀x2::('fsym, 'psym) atm. ⟦Ik.wtL (l::('fsym, 'psym) lit); Ik.wtE (ξ::Preliminaries.var ⇒ univ); l = Neg x2⟧ ⟹ TE.satL (eenv ξ) (tL l) = Ik.satL ξ l› discuss goal 1*) apply (rename_tac [!] atm) (*top goal: ‹⋀x1. ⟦Ik.wtL l; Ik.wtE ξ; l = Pos x1⟧ ⟹ TE.satL (eenv ξ) (tL l) = Ik.satL ξ l› and 1 goal remains*) apply ((case_tac [!] atm)[1]) (*goals: 1. ‹⋀atm x11 x12. ⟦Ik.wtL l; Ik.wtE ξ; l = Pos atm; atm = Eq x11 x12⟧ ⟹ TE.satL (eenv ξ) (tL l) = Ik.satL ξ l› 2. ‹⋀atm x21 x22. ⟦Ik.wtL l; Ik.wtE ξ; l = Pos atm; atm = Pr x21 x22⟧ ⟹ TE.satL (eenv ξ) (tL l) = Ik.satL ξ l› discuss goal 1*) apply ((auto simp add: intP_def (*‹intP ?p ?al ≡ eintP ?p (map2 ntsem (parOf ?p) ?al)›*))[1]) (*discuss goal 2*) apply ((auto simp add: intP_def (*‹intP ?p ?al ≡ eintP ?p (map2 ntsem (parOf ?p) ?al)›*))[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply ((case_tac [!] atm)[1]) (*goals: 1. ‹⋀atm x11 x12. ⟦Ik.wtL l; Ik.wtE ξ; l = Neg atm; atm = Eq x11 x12⟧ ⟹ TE.satL (eenv ξ) (tL l) = Ik.satL ξ l› 2. ‹⋀atm x21 x22. ⟦Ik.wtL l; Ik.wtE ξ; l = Neg atm; atm = Pr x21 x22⟧ ⟹ TE.satL (eenv ξ) (tL l) = Ik.satL ξ l› discuss goal 1*) apply ((auto simp add: intP_def (*‹intP ?p ?al ≡ eintP ?p (map2 ntsem (parOf ?p) ?al)›*))[1]) (*discuss goal 2*) apply ((auto simp add: intP_def (*‹intP ?p ?al ≡ eintP ?p (map2 ntsem (parOf ?p) ?al)›*))[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma satC_tC[simp]: assumes l: "Ik.Ik.wtC c" and ξ: "Ik.wtE ξ" shows "TE.satC (eenv ξ) (tC c) ⟷ Ik.satC ξ c" unfolding TE.satC_def Ik.satC_def (*goal: ‹list_ex (TE.satL (eenv ξ)) (tC c) = list_ex (Ik.satL ξ) c›*) using assms (*‹Ik.wtC c› ‹Ik.wtE ξ›*) apply (induct c) (*goals: 1. ‹⟦Ik.wtC []; Ik.wtE ξ⟧ ⟹ list_ex (TE.satL (eenv ξ)) (tC []) = list_ex (Ik.satL ξ) []› 2. ‹⋀a c. ⟦⟦Ik.wtC c; Ik.wtE ξ⟧ ⟹ list_ex (TE.satL (eenv ξ)) (tC c) = list_ex (Ik.satL ξ) c; Ik.wtC (a # c); Ik.wtE ξ⟧ ⟹ list_ex (TE.satL (eenv ξ)) (tC (a # c)) = list_ex (Ik.satL ξ) (a # c)› discuss goal 1*) apply ((auto simp add: Ik.Ik.wtC_def (*‹Ik.wtC ≡ list_all Ik.wtL›*) tC_def (*‹tC ≡ map tL›*))[1]) (*discuss goal 2*) apply ((auto simp add: Ik.Ik.wtC_def (*‹Ik.wtC ≡ list_all Ik.wtL›*) tC_def (*‹tC ≡ map tL›*))[1]) (*proven 2 subgoals*) . lemma satPB_tPB[simp]: assumes ξ: "Ik.wtE ξ" shows "TE.satPB (eenv ξ) (tC ` Φ) ⟷ Ik.satPB ξ Φ" using "Ik.wt_Φ" (*‹Ik.wtPB (Φ::('fsym, 'psym) lit list set)›*) assms (*‹Ik.wtE ξ›*) unfolding TE.satPB_def Ik.satPB_def (*goal: ‹(∀c::(('fsym::type, 'tp::type) efsym, 'psym::type) lit list∈tC ` (Φ::('fsym::type, 'psym::type) lit list set). TE.satC (eenv (ξ::Preliminaries.var ⇒ univ)) c) = (∀c::('fsym::type, 'psym::type) lit list∈Φ. Ik.satC ξ c)›*) by (auto simp add: Ik.Ik.wtPB_def (*‹Ik.wtPB (?Φ::('fsym::type, 'psym::type) lit list set) ≡ Ball ?Φ Ik.wtC›*)) lemma completeness: "Ik.SAT Φ" unfolding Ik.SAT_def (*goal: ‹∀ξ. Ik.wtE ξ ⟶ Ik.satPB ξ Φ›*) proof (safe) (*goal: ‹⋀ξ. Ik.wtE ξ ⟹ Ik.satPB ξ Φ›*) fix ξ assume "ξ": "Ik.wtE ξ" (*‹Ik.wtE (ξ::Preliminaries.var ⇒ univ)›*) hence "TE.wtE (eenv ξ)" by (rule wt_eenv (*‹Ik.wtE ?ξ ⟹ TE.wtE (eenv ?ξ)›*)) hence "TE.satPB (eenv ξ) tPB" by (rule TE.sat_Φ (*‹TE.wtE ?ξ ⟹ TE.satPB ?ξ tPB›*)) hence "TE.satPB (eenv ξ) (tC ` Φ)" unfolding tPB_def (*goal: ‹TE.satPB (eenv ξ) (tC ` Φ)›*) by simp thus "Ik.satPB ξ Φ" using "ξ" (*‹Ik.wtE ξ›*) by simp qed lemma T_completeness: "Model wtFsym wtPsym arOf resOf parOf Φ intT intF intP" apply standard (*goal: ‹Ik.MModel intT intF intP›*) by (rule completeness (*‹Ik.SAT Φ›*)) end (* context ProblemIkTpart_TEModel *) (* Completeness theorem in sublocale form: Given a problem (with indicated type partition) and a model for its tag-translated problem, we obtain a model of the original problem: *) sublocale ProblemIkTpart_TEModel < O? : Model where intT = intT and intF = intF and intP = intP using T_completeness (*‹Ik.MModel intT intF intP›*) . subsection‹The result of the tag translation is an infiniteness-augmented problem› (* Note that basic fact, merely stating that the translation is well-defined between infiniteness-augmented problems, is only proved at this late stage since it requires completeness. This is an interesting dependency, not spotted in the paper. *) sublocale ProblemIkTpart < TE? : Problem where wtFsym = TE_wtFsym and arOf = TE_arOf and resOf = TE_resOf and Φ = tPB apply standard (*goal: ‹Problem TE_wtFsym wtPsym TE_arOf TE_resOf parOf tPB›*) by auto sublocale ProblemIkTpart < TE? : ProblemIk where wtFsym = TE_wtFsym and arOf = TE_arOf and resOf = TE_resOf and Φ = tPB proof (standard) (*goal: ‹⋀σ intT intF intP a. ⟦infTp σ; TE.MModel intT intF intP⟧ ⟹ infinite {a. intT σ a}›*) fix σ and eintT and eintF and eintP and a assume "σ": "infTp σ" (*‹(infTp::'tp ⇒ bool) (σ::'tp)›*) assume M: "Model TE_wtFsym wtPsym TE_arOf TE_resOf parOf tPB eintT eintF eintP" (*‹TE.MModel (eintT::'tp ⇒ univ ⇒ bool) (eintF::('fsym, 'tp) efsym ⇒ univ list ⇒ univ) (eintP::'psym ⇒ univ list ⇒ bool)›*) let ?TE_intT = "ProblemIkTpart_TEModel.intT prot protFw eintT eintF" let ?TE_intF = "ProblemIkTpart_TEModel.intF arOf resOf prot protFw eintT eintF" let ?TE_intP = "ProblemIkTpart_TEModel.intP parOf prot protFw eintT eintF eintP" have 0: "ProblemIkTpart_TEModel wtFsym wtPsym arOf resOf parOf Φ infTp prot protFw eintT eintF eintP" using M (*‹TE.MModel (eintT::'tp ⇒ univ ⇒ bool) (eintF::('fsym, 'tp) efsym ⇒ univ list ⇒ univ) (eintP::'psym ⇒ univ list ⇒ bool)›*) unfolding ProblemIkTpart_TEModel_def (*goal: ‹ProblemIkTpart wtFsym wtPsym arOf resOf parOf Φ infTp prot protFw ∧ TE.MModel eintT eintF eintP›*) apply safe (*goal: ‹ProblemIkTpart wtFsym wtPsym arOf resOf parOf Φ infTp prot protFw ∧ TE.MModel eintT eintF eintP›*) by standard hence MM: "Ik.MModel ?TE_intT ?TE_intF ?TE_intP" by (rule ProblemIkTpart_TEModel.T_completeness (*‹ProblemIkTpart_TEModel ?wtFsym ?wtPsym ?arOf ?resOf ?parOf ?Φ ?infTp ?prot ?protFw ?eintT ?eintF ?eintP ⟹ CM.Model ?wtFsym ?wtPsym ?arOf ?resOf ?parOf ?Φ (ProblemIkTpart_TEModel.intT ?prot ?protFw ?eintT ?eintF) (ProblemIkTpart_TEModel.intF ?arOf ?resOf ?prot ?protFw ?eintT ?eintF) (ProblemIkTpart_TEModel.intP ?parOf ?prot ?protFw ?eintT ?eintF ?eintP)›*)) have "infinite {a. ?TE_intT σ a}" using infTp[OF σ MM] (*‹infinite {a::univ. ProblemIkTpart_TEModel.intT (prot::'tp ⇒ bool) (protFw::'tp ⇒ bool) (eintT::'tp ⇒ univ ⇒ bool) (eintF::('fsym, 'tp) efsym ⇒ univ list ⇒ univ) (σ::'tp) a}›*) . moreover have "{a. ?TE_intT σ a} ⊆ {a. eintT σ a}" using ProblemIkTpart_TEModel.intT_def[OF 0] (*‹ProblemIkTpart_TEModel.intT (prot::'tp::type ⇒ bool) (protFw::'tp::type ⇒ bool) (eintT::'tp::type ⇒ univ ⇒ bool) (eintF::('fsym::type, 'tp::type) efsym ⇒ univ list ⇒ univ) (?σ::'tp::type) (?a::univ) ≡ if unprot ?σ then eintT ?σ ?a else if protFw ?σ then eintT ?σ ?a ∧ eintF (Tag ?σ) [?a] = ?a else eintT ?σ ?a ∧ ?a ∈ (eintF (Tag ?σ) ∘ singl) ` {b::univ. eintT ?σ b}›*) by auto ultimately show "infinite {a. eintT σ a}" using infinite_super (*‹⟦?S ⊆ ?T; infinite ?S⟧ ⟹ infinite ?T›*) by blast qed subsection‹The verification of the first monotonicity calculus criterion for the tagged problem› context ProblemIkTpart begin lemma nvT_t[simp]: "¬ unprot σ ⟹ (∀ x ∈ TE.nvT (tT T). tpOfV x ≠ σ)" apply (induct T) (*goals: 1. ‹⋀x::Preliminaries.var. ¬ unprot (σ::'tp) ⟹ ∀x::Preliminaries.var∈nvT (tT (Var x)). TE.tpOfV x ≠ σ› 2. ‹⋀(f::'fsym) Tl::'fsym trm list. ⟦list_all (λa::'fsym trm. ¬ unprot (σ::'tp) ⟶ (∀x::Preliminaries.var∈nvT (tT a). TE.tpOfV x ≠ σ)) Tl; ¬ unprot σ⟧ ⟹ ∀x::Preliminaries.var∈nvT (tT (Fn f Tl)). TE.tpOfV x ≠ σ› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma nvL_tL[simp]: "¬ unprot σ ⟹ (∀ x ∈ TE.nvL (tL l). tpOfV x ≠ σ)" apply (cases l) (*goals: 1. ‹⋀x1. ⟦¬ unprot σ; l = Pos x1⟧ ⟹ ∀x∈nvL (tL l). TE.tpOfV x ≠ σ› 2. ‹⋀x2. ⟦¬ unprot σ; l = Neg x2⟧ ⟹ ∀x∈nvL (tL l). TE.tpOfV x ≠ σ› discuss goal 1*) apply (rename_tac [!] atm) (*top goal: ‹⋀x1. ⟦¬ unprot σ; l = Pos x1⟧ ⟹ ∀x∈nvL (tL l). TE.tpOfV x ≠ σ› and 1 goal remains*) apply ((case_tac [!] atm)[1]) (*goals: 1. ‹⋀atm x11 x12. ⟦¬ unprot σ; l = Pos atm; atm = Eq x11 x12⟧ ⟹ ∀x∈nvL (tL l). TE.tpOfV x ≠ σ› 2. ‹⋀atm x21 x22. ⟦¬ unprot σ; l = Pos atm; atm = Pr x21 x22⟧ ⟹ ∀x∈nvL (tL l). TE.tpOfV x ≠ σ› discuss goal 1*) apply ((auto)[1]) (*goals: 1. ‹⋀x11 x12 x. ⟦¬ unprot (TE.tpOfV x); l = Pos (Eq x11 x12); σ = TE.tpOfV x; x ∈ nvT (tT x11)⟧ ⟹ False› 2. ‹⋀x11 x12 x. ⟦¬ unprot (TE.tpOfV x); l = Pos (Eq x11 x12); σ = TE.tpOfV x; x ∈ nvT (tT x12)⟧ ⟹ False› discuss goal 1*) apply (metis nvT_t (*‹¬ unprot (?σ::'tp::type) ⟹ ∀x::Preliminaries.var∈nvT (tT (?T::'fsym::type trm)). TE.tpOfV x ≠ ?σ›*)) (*discuss goal 2*) apply (metis nvT_t (*‹¬ unprot (?σ::'tp::type) ⟹ ∀x::Preliminaries.var∈nvT (tT (?T::'fsym::type trm)). TE.tpOfV x ≠ ?σ›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply ((case_tac [!] atm)[1]) (*goals: 1. ‹⋀atm x11 x12. ⟦¬ unprot σ; l = Neg atm; atm = Eq x11 x12⟧ ⟹ ∀x∈nvL (tL l). TE.tpOfV x ≠ σ› 2. ‹⋀atm x21 x22. ⟦¬ unprot σ; l = Neg atm; atm = Pr x21 x22⟧ ⟹ ∀x∈nvL (tL l). TE.tpOfV x ≠ σ› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma nvC_tC[simp]: "¬ unprot σ ⟹ (∀ x ∈ TE.nvC (tC c). tpOfV x ≠ σ)" unfolding tC_def TE.nvC_def (*goal: ‹¬ unprot σ ⟹ ∀x∈⋃ (set (map nvL (map tL c))). TE.tpOfV x ≠ σ›*) apply (induct c) (*goals: 1. ‹¬ unprot σ ⟹ ∀x∈⋃ (set (map nvL (map tL []))). TE.tpOfV x ≠ σ› 2. ‹⋀a c. ⟦¬ unprot σ ⟹ ∀x∈⋃ (set (map nvL (map tL c))). TE.tpOfV x ≠ σ; ¬ unprot σ⟧ ⟹ ∀x∈⋃ (set (map nvL (map tL (a # c)))). TE.tpOfV x ≠ σ› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*goals: 1. ‹⋀(a::('fsym, 'a) lit) x::Preliminaries.var. ⟦¬ unprot (TE.tpOfV x); (σ::'tp) = TE.tpOfV x; x ∈ nvL (tL a)⟧ ⟹ False› 2. ‹⋀(c::('fsym, 'a) lit list) (x::Preliminaries.var) xa::('fsym, 'a) lit. ⟦¬ unprot (TE.tpOfV x); (σ::'tp) = TE.tpOfV x; xa ∈ set c; x ∈ nvL (tL xa)⟧ ⟹ False› discuss goal 1*) apply (metis (full_types) nvL_tL (*‹¬ unprot ?σ ⟹ ∀x∈nvL (tL ?l). TE.tpOfV x ≠ ?σ›*)) (*discuss goal 2*) apply (metis (full_types) nvL_tL (*‹¬ unprot ?σ ⟹ ∀x∈nvL (tL ?l). TE.tpOfV x ≠ ?σ›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma unprot_nvT_t[simp]: "unprot (tpOfV x) ⟹ x ∈ TE.nvT (tT T) ⟷ x ∈ TE.nvT T" apply (induct T) (*goals: 1. ‹⋀xa::Preliminaries.var. unprot (TE.tpOfV (x::Preliminaries.var)) ⟹ (x ∈ nvT (tT (Var xa))) = (x ∈ nvT (Var xa))› 2. ‹⋀(f::'fsym) Tl::'fsym trm list. ⟦list_all (λa::'fsym trm. unprot (TE.tpOfV (x::Preliminaries.var)) ⟶ (x ∈ nvT (tT a)) = (x ∈ nvT a)) Tl; unprot (TE.tpOfV x)⟧ ⟹ (x ∈ nvT (tT (Fn f Tl))) = (x ∈ nvT (Fn f Tl))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma tpL_nvT_tL[simp]: "unprot (tpOfV x) ⟹ x ∈ TE.nvL (tL l) ⟷ x ∈ TE.nvL l" apply (cases l) (*goals: 1. ‹⋀x1. ⟦unprot (TE.tpOfV x); l = Pos x1⟧ ⟹ (x ∈ nvL (tL l)) = (x ∈ nvL l)› 2. ‹⋀x2. ⟦unprot (TE.tpOfV x); l = Neg x2⟧ ⟹ (x ∈ nvL (tL l)) = (x ∈ nvL l)› discuss goal 1*) apply (rename_tac [!] atm) (*top goal: ‹⋀x1. ⟦unprot (TE.tpOfV x); l = Pos x1⟧ ⟹ (x ∈ nvL (tL l)) = (x ∈ nvL l)› and 1 goal remains*) apply ((case_tac [!] atm)[1]) (*goals: 1. ‹⋀atm x11 x12. ⟦unprot (TE.tpOfV x); l = Pos atm; atm = Eq x11 x12⟧ ⟹ (x ∈ nvL (tL l)) = (x ∈ nvL l)› 2. ‹⋀atm x21 x22. ⟦unprot (TE.tpOfV x); l = Pos atm; atm = Pr x21 x22⟧ ⟹ (x ∈ nvL (tL l)) = (x ∈ nvL l)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply ((case_tac [!] atm)[1]) (*goals: 1. ‹⋀atm x11 x12. ⟦unprot (TE.tpOfV x); l = Neg atm; atm = Eq x11 x12⟧ ⟹ (x ∈ nvL (tL l)) = (x ∈ nvL l)› 2. ‹⋀atm x21 x22. ⟦unprot (TE.tpOfV x); l = Neg atm; atm = Pr x21 x22⟧ ⟹ (x ∈ nvL (tL l)) = (x ∈ nvL l)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma unprot_nvC_tC[simp]: "unprot (tpOfV x) ⟹ x ∈ TE.nvC (tC c) ⟷ x ∈ TE.nvC c" unfolding tC_def TE.nvC_def (*goal: ‹unprot (TE.tpOfV x) ⟹ (x ∈ ⋃ (set (map nvL (map tL c)))) = (x ∈ ⋃ (set (map nvL c)))›*) apply (induct c) (*goals: 1. ‹unprot (TE.tpOfV x) ⟹ (x ∈ ⋃ (set (map nvL (map tL [])))) = (x ∈ ⋃ (set (map nvL [])))› 2. ‹⋀a c. ⟦unprot (TE.tpOfV x) ⟹ (x ∈ ⋃ (set (map nvL (map tL c)))) = (x ∈ ⋃ (set (map nvL c))); unprot (TE.tpOfV x)⟧ ⟹ (x ∈ ⋃ (set (map nvL (map tL (a # c))))) = (x ∈ ⋃ (set (map nvL (a # c))))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . (* The added axioms are monotonic *) lemma nv_OfFax[simp]: "x ∉ TE.nvT (lOfFax f)" "x ∉ TE.nvT (rOfFax f)" unfolding lOfFax_def rOfFax_def lOfWax_def rOfWax_def (*goals: 1. ‹x ∉ nvT (Fn (Tag (resOf f)) [Fn (Oldf f) (TE.getTvars (arOf f))])› 2. ‹x ∉ nvT (Fn (Oldf f) (TE.getTvars (arOf f)))›*) (*goals: 1. ‹x ∉ nvT (Fn (Tag (resOf f)) [Fn (Oldf f) (TE.getTvars (arOf f))])› 2. ‹x ∉ nvT (Fn (Oldf f) (TE.getTvars (arOf f)))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma nv_OfWax[simp]: "x ∉ TE.nvT (lOfWax σ')" "x ∉ TE.nvT (rOfWax σ')" unfolding lOfFax_def rOfFax_def lOfWax_def rOfWax_def (*goals: 1. ‹x ∉ nvT (Fn (Tag σ') [Fn (Wit σ') []])› 2. ‹x ∉ nvT (Fn (Wit σ') [])›*) (*goals: 1. ‹x ∉ nvT (Fn (Tag σ') [Fn (Wit σ') []])› 2. ‹x ∉ nvT (Fn (Wit σ') [])› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma nvC_Fax: "c ∈ Fax ⟹ TE.nvC c = {}" unfolding Fax_def TE.nvC_def (*goal: ‹c ∈ {[Pos (Eq (lOfFax f) (rOfFax f))] |f. wtFsym f} ⟹ ⋃ (set (map nvL c)) = {}›*) by auto lemma mcalc_Fax: "c ∈ Fax ⟹ TE.mcalc σ c" using nvC_Fax (*‹?c ∈ Fax ⟹ nvC ?c = {}›*) unfolding TE.mcalc_iff (*goal: ‹c ∈ Fax ⟹ infTp σ ∨ (∀x∈nvC c. TE.tpOfV x ≠ σ)›*) by auto lemma nvC_Wax: "c ∈ Wax ⟹ TE.nvC c = {}" unfolding Wax_def TE.nvC_def (*goal: ‹c ∈ {[Pos (Eq (lOfWax σ) (rOfWax σ))] |σ. ¬ isRes σ ∧ protFw σ} ⟹ ⋃ (set (map nvL c)) = {}›*) by auto lemma mcalc_Wax: "c ∈ Wax ⟹ TE.mcalc σ c" using nvC_Wax[of c] (*‹c ∈ Wax ⟹ nvC c = {}›*) by simp end (* context ProblemIkTpart *) sublocale ProblemIkTpart < TE?: ProblemIkMcalc where wtFsym = TE_wtFsym and arOf = TE_arOf and resOf = TE_resOf and Φ = tPB proof (standard) (*goal: ‹⋀σ c. c ∈ tPB ⟹ σ ⊢ c›*) fix σ and c assume "c ∈ tPB" (*‹(c::(('fsym, 'tp) efsym, 'psym) lit list) ∈ tPB›*) thus "TE.mcalc σ c" unfolding tPB_def (*goal: ‹σ ⊢ c›*) proof (safe) (*goals: 1. ‹⋀x. ⟦x ∈ Φ; c = tC x⟧ ⟹ σ ⊢ tC x› 2. ‹c ∈ Fax ⟹ σ ⊢ c› 3. ‹c ∈ Wax ⟹ σ ⊢ c›*) fix d assume d: "d ∈ Φ" (*‹(d::('fsym, 'psym) lit list) ∈ (Φ::('fsym, 'psym) lit list set)›*) thus "TE.mcalc σ (tC d)" using unprot_mcalc[OF _ d] (*‹unprot (?σ::'tp::type) ⟹ ?σ ⊢ (d::('fsym::type, 'psym::type) lit list)›*) unfolding TE.mcalc_iff (*goal: ‹infTp σ ∨ (∀x∈nvC (tC d). TE.tpOfV x ≠ σ)›*) apply (cases "unprot σ") (*goals: 1. ‹⟦d ∈ Φ; ⋀σ. unprot σ ⟹ infTp σ ∨ (∀x∈nvC d. TE.tpOfV x ≠ σ); unprot σ⟧ ⟹ infTp σ ∨ (∀x∈nvC (tC d). TE.tpOfV x ≠ σ)› 2. ‹⟦d ∈ Φ; ⋀σ. unprot σ ⟹ infTp σ ∨ (∀x∈nvC d. TE.tpOfV x ≠ σ); ¬ unprot σ⟧ ⟹ infTp σ ∨ (∀x∈nvC (tC d). TE.tpOfV x ≠ σ)› discuss goal 1*) apply ((auto)[1]) (*top goal: ‹⟦d ∈ Φ; ⋀σ. unprot σ ⟹ infTp σ ∨ (∀x∈nvC d. TE.tpOfV x ≠ σ); unprot σ⟧ ⟹ infTp σ ∨ (∀x∈nvC (tC d). TE.tpOfV x ≠ σ)› and 1 goal remains*) apply force (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed (insert mcalc_Fax (*‹(?c::(('fsym, 'tp) efsym, ?'a) lit list) ∈ Fax ⟹ (?σ::'tp) ⊢ ?c›*) mcalc_Wax (*‹(?c::((?'a, 'tp) efsym, ?'b) lit list) ∈ Wax ⟹ (?σ::'tp) ⊢ ?c›*), (blast)+) (*solves the remaining goals: 1. ‹c ∈ Fax ⟹ σ ⊢ c› 2. ‹c ∈ Wax ⟹ σ ⊢ c›*) qed (* We already know that ProblemIkMcalc < MonotProblem, so by transitivity we obtain the following main theorem, stating that the tag translation yields a monotonic problem *) context ProblemIkTpart begin theorem T_monotonic: "MonotProblem TE_wtFsym wtPsym TE_arOf TE_resOf parOf tPB" by standard end (* context ProblemIkTpart *) sublocale ProblemIkTpart < TE?: MonotProblem where wtFsym = TE_wtFsym and arOf = TE_arOf and resOf = TE_resOf and Φ = tPB using T_monotonic (*‹MonotProblem TE_wtFsym (wtPsym::'psym ⇒ bool) TE_arOf TE_resOf (parOf::'psym ⇒ 'tp list) tPB›*) . end
{ "path": "afp-2025-02-12/thys/Sort_Encodings/T.thy", "repo": "afp-2025-02-12", "sha": "85ba2bcd9cb3e9894237d93346ed729d8d5528d84741f6ffdbaf454163aeede6" }
(*<*) (* * Copyright 2015, NICTA * * This software may be distributed and modified according to the terms of * the BSD 2-Clause license. Note that NO WARRANTY is provided. * See "LICENSE_BSD2.txt" for details. * * @TAG(NICTA_BSD) *) theory Local_Invariants_Lemmas imports Local_Invariants begin declare subst_all [simp del] [[simproc del: defined_all]] (*>*) section‹Local invariants lemma bucket› subsection‹ Location facts› (* FIXME loads more in StrongTricolour. These might be mostly about non-interference, in which case it might make sense to split those proofs off into a separate theory? *) context mut_m begin lemma hs_get_roots_loop_locs_subseteq_hs_get_roots_locs: "hs_get_roots_loop_locs ⊆ hs_get_roots_locs" unfolding hs_get_roots_loop_locs_def hs_get_roots_locs_def (*goal: ‹prefixed ''hs_get_roots_loop'' ⊆ prefixed ''hs_get_roots_''›*) by (fastforce intro: append_prefixD (*‹prefix (?xs @ ?ys) ?zs ⟹ prefix ?xs ?zs›*)) lemma hs_pending_locs_subseteq_hs_pending_loaded_locs: "hs_pending_locs ⊆ hs_pending_loaded_locs" unfolding hs_pending_locs_def hs_pending_loaded_locs_def (*goal: ‹prefixed ''hs_'' - {hs_load_pending, local.hs_pending} ⊆ prefixed ''hs_'' - {hs_load_pending}›*) by (fastforce intro: append_prefixD (*‹prefix ((?xs::?'a list) @ (?ys::?'a list)) (?zs::?'a list) ⟹ prefix ?xs ?zs›*)) lemma ht_loaded_locs_subseteq_hs_pending_loaded_locs: "ht_loaded_locs ⊆ hs_pending_loaded_locs" unfolding ht_loaded_locs_def hs_pending_loaded_locs_def (*goal: ‹prefixed ''hs_'' - {hs_load_pending, local.hs_pending, hs_mfence, hs_load_ht} ⊆ prefixed ''hs_'' - {hs_load_pending}›*) by (fastforce intro: append_prefixD (*‹prefix (?xs @ ?ys) ?zs ⟹ prefix ?xs ?zs›*)) lemma hs_noop_locs_subseteq_hs_pending_loaded_locs: "hs_noop_locs ⊆ hs_pending_loaded_locs" unfolding hs_noop_locs_def hs_pending_loaded_locs_def loc_defs (*goal: ‹prefixed ''hs_noop_'' ⊆ prefixed ''hs_'' - {''hs_load_pending''}›*) by (fastforce intro: append_prefixD (*‹prefix (?xs @ ?ys) ?zs ⟹ prefix ?xs ?zs›*)) lemma hs_noop_locs_subseteq_hs_pending_locs: "hs_noop_locs ⊆ hs_pending_locs" unfolding hs_noop_locs_def hs_pending_locs_def loc_defs (*goal: ‹prefixed ''hs_noop_'' ⊆ prefixed ''hs_'' - {''hs_load_pending'', ''hs_pending''}›*) by (fastforce intro: append_prefixD (*‹prefix ((?xs::?'a list) @ (?ys::?'a list)) (?zs::?'a list) ⟹ prefix ?xs ?zs›*)) lemma hs_noop_locs_subseteq_ht_loaded_locs: "hs_noop_locs ⊆ ht_loaded_locs" unfolding hs_noop_locs_def ht_loaded_locs_def loc_defs (*goal: ‹prefixed ''hs_noop_'' ⊆ prefixed ''hs_'' - {''hs_load_pending'', ''hs_pending'', ''hs_mfence'', ''hs_load_ht''}›*) by (fastforce intro: append_prefixD (*‹prefix ((?xs::?'a::type list) @ (?ys::?'a::type list)) (?zs::?'a::type list) ⟹ prefix ?xs ?zs›*)) lemma hs_get_roots_locs_subseteq_hs_pending_loaded_locs: "hs_get_roots_locs ⊆ hs_pending_loaded_locs" unfolding hs_get_roots_locs_def hs_pending_loaded_locs_def loc_defs (*goal: ‹prefixed ''hs_get_roots_'' ⊆ prefixed ''hs_'' - {''hs_load_pending''}›*) by (fastforce intro: append_prefixD (*‹prefix (?xs @ ?ys) ?zs ⟹ prefix ?xs ?zs›*)) lemma hs_get_roots_locs_subseteq_hs_pending_locs: "hs_get_roots_locs ⊆ hs_pending_locs" unfolding hs_get_roots_locs_def hs_pending_locs_def loc_defs (*goal: ‹prefixed ''hs_get_roots_'' ⊆ prefixed ''hs_'' - {''hs_load_pending'', ''hs_pending''}›*) by (fastforce intro: append_prefixD (*‹prefix ((?xs::?'a list) @ (?ys::?'a list)) (?zs::?'a list) ⟹ prefix ?xs ?zs›*)) lemma hs_get_roots_locs_subseteq_ht_loaded_locs: "hs_get_roots_locs ⊆ ht_loaded_locs" unfolding hs_get_roots_locs_def ht_loaded_locs_def loc_defs (*goal: ‹prefixed ''hs_get_roots_'' ⊆ prefixed ''hs_'' - {''hs_load_pending'', ''hs_pending'', ''hs_mfence'', ''hs_load_ht''}›*) by (fastforce intro: append_prefixD (*‹prefix ((?xs::?'a list) @ (?ys::?'a list)) (?zs::?'a list) ⟹ prefix ?xs ?zs›*)) lemma hs_get_work_locs_subseteq_hs_pending_loaded_locs: "hs_get_work_locs ⊆ hs_pending_loaded_locs" unfolding hs_get_work_locs_def hs_pending_loaded_locs_def loc_defs (*goal: ‹prefixed ''hs_get_work_'' ⊆ prefixed ''hs_'' - {''hs_load_pending''}›*) by (fastforce intro: append_prefixD (*‹prefix (?xs @ ?ys) ?zs ⟹ prefix ?xs ?zs›*)) lemma hs_get_work_locs_subseteq_hs_pending_locs: "hs_get_work_locs ⊆ hs_pending_locs" unfolding hs_get_work_locs_def hs_pending_locs_def loc_defs (*goal: ‹prefixed ''hs_get_work_'' ⊆ prefixed ''hs_'' - {''hs_load_pending'', ''hs_pending''}›*) by (fastforce intro: append_prefixD (*‹prefix (?xs @ ?ys) ?zs ⟹ prefix ?xs ?zs›*)) lemma hs_get_work_locs_subseteq_ht_loaded_locs: "hs_get_work_locs ⊆ ht_loaded_locs" unfolding hs_get_work_locs_def ht_loaded_locs_def loc_defs (*goal: ‹prefixed ''hs_get_work_'' ⊆ prefixed ''hs_'' - {''hs_load_pending'', ''hs_pending'', ''hs_mfence'', ''hs_load_ht''}›*) by (fastforce intro: append_prefixD (*‹prefix (?xs @ ?ys) ?zs ⟹ prefix ?xs ?zs›*)) end declare mut_m.hs_get_roots_loop_locs_subseteq_hs_get_roots_locs[locset_cache] mut_m.hs_pending_locs_subseteq_hs_pending_loaded_locs[locset_cache] mut_m.ht_loaded_locs_subseteq_hs_pending_loaded_locs[locset_cache] mut_m.hs_noop_locs_subseteq_hs_pending_loaded_locs[locset_cache] mut_m.hs_noop_locs_subseteq_hs_pending_locs[locset_cache] mut_m.hs_noop_locs_subseteq_ht_loaded_locs[locset_cache] mut_m.hs_get_roots_locs_subseteq_hs_pending_loaded_locs[locset_cache] mut_m.hs_get_roots_locs_subseteq_hs_pending_locs[locset_cache] mut_m.hs_get_roots_locs_subseteq_ht_loaded_locs[locset_cache] mut_m.hs_get_work_locs_subseteq_hs_pending_loaded_locs[locset_cache] mut_m.hs_get_work_locs_subseteq_hs_pending_locs[locset_cache] mut_m.hs_get_work_locs_subseteq_ht_loaded_locs[locset_cache] context gc begin lemma get_roots_UN_get_work_locs_subseteq_ghost_honorary_grey_empty_locs: "get_roots_UN_get_work_locs ⊆ ghost_honorary_grey_empty_locs" unfolding get_roots_UN_get_work_locs_def ghost_honorary_grey_empty_locs_def hs_get_roots_locs_def hs_get_work_locs_def loc_defs (*goal: ‹prefixed ''mark_loop_get_roots'' - {''mark_loop_get_roots_init_type''} ∪ (prefixed ''mark_loop_get_work'' - {''mark_loop_get_work_init_type''}) ⊆ - {''mark_loop_mo_co_unlock'', ''mark_loop_mo_co_won'', ''mark_loop_mo_co_W''}›*) by (fastforce intro: append_prefixD (*‹prefix (?xs @ ?ys) ?zs ⟹ prefix ?xs ?zs›*)) lemma hs_get_roots_locs_subseteq_hp_IdleMarkSweep_locs: "hs_get_roots_locs ⊆ hp_IdleMarkSweep_locs" by (auto simp: hs_get_roots_locs_def (*‹hs_get_roots_locs = prefixed ''mark_loop_get_roots'' - {mark_loop_get_roots_init_type}›*) hp_IdleMarkSweep_locs_def (*‹hp_IdleMarkSweep_locs = {idle_noop_mfence, idle_noop_init_type, mark_end} ∪ sweep_locs ∪ (mark_loop_locs - {mark_loop_get_roots_init_type})›*) mark_loop_locs_def (*‹mark_loop_locs = prefixed ''mark_loop''›*) intro: append_prefixD (*‹prefix (?xs @ ?ys) ?zs ⟹ prefix ?xs ?zs›*)) lemma hs_get_work_locs_subseteq_hp_IdleMarkSweep_locs: "hs_get_work_locs ⊆ hp_IdleMarkSweep_locs" apply (simp add: hs_get_work_locs_def (*‹hs_get_work_locs = prefixed ''mark_loop_get_work'' - {mark_loop_get_work_init_type}›*) hp_IdleMarkSweep_locs_def (*‹hp_IdleMarkSweep_locs = {idle_noop_mfence, idle_noop_init_type, mark_end} ∪ sweep_locs ∪ (mark_loop_locs - {mark_loop_get_roots_init_type})›*) mark_loop_locs_def (*‹mark_loop_locs = prefixed ''mark_loop''›*) loc_defs (*‹sweep_idle ≡ ''sweep_idle''› ‹sweep_loop_ref_done ≡ ''sweep_loop_ref_done''› ‹sweep_loop_free ≡ ''sweep_loop_free''› ‹sweep_loop_check ≡ ''sweep_loop_check''› ‹sweep_loop_load_mark ≡ ''sweep_loop_load_mark''› ‹sweep_loop_choose_ref ≡ ''sweep_loop_choose_ref''› ‹sweep_loop ≡ ''sweep_loop''› ‹sweep_refs ≡ ''sweep_refs''› ‹sweep_load_fM ≡ ''sweep_load_fM''› ‹mark_end ≡ ''mark_end''› ‹mark_loop_get_work_load_W ≡ ''mark_loop_get_work_load_W''› ‹mark_loop_get_work_done_loop_rendezvous ≡ ''mark_loop_get_work_done_loop_rendezvous''› and more 93 facts*)) (*goal: ‹hs_get_work_locs ⊆ hp_IdleMarkSweep_locs›*) apply ((clarsimp)[1]) (*goal: ‹prefixed ''mark_loop_get_work'' - {''mark_loop_get_work_init_type''} ⊆ insert ''idle_noop_mfence'' (insert ''idle_noop_init_type'' (insert ''mark_end'' (sweep_locs ∪ (prefixed ''mark_loop'' - {''mark_loop_get_roots_init_type''}))))›*) apply ((drule mp (*‹⟦?P ⟶ ?Q; ?P⟧ ⟹ ?Q›*))[1]) (*goals: 1. ‹⋀x. ⟦x ≠ ''idle_noop_mfence''; x ≠ ''idle_noop_init_type''; x ≠ ''mark_end''; x ≠ ''mark_loop_get_work_init_type''; prefix ''mark_loop_get_work'' x⟧ ⟹ prefix ''mark_loop'' x› 2. ‹⋀x. ⟦x ≠ ''idle_noop_mfence''; x ≠ ''idle_noop_init_type''; x ≠ ''mark_end''; x ≠ ''mark_loop_get_work_init_type''; prefix ''mark_loop_get_work'' x; x = ''mark_loop_get_roots_init_type''⟧ ⟹ x ∈ sweep_locs› discuss goal 1*) apply ((auto intro: append_prefixD (*‹prefix (?xs @ ?ys) ?zs ⟹ prefix ?xs ?zs›*))[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . end declare gc.get_roots_UN_get_work_locs_subseteq_ghost_honorary_grey_empty_locs[locset_cache] gc.hs_get_roots_locs_subseteq_hp_IdleMarkSweep_locs[locset_cache] gc.hs_get_work_locs_subseteq_hp_IdleMarkSweep_locs[locset_cache] subsection‹ ‹obj_fields_marked_inv› › context gc begin lemma obj_fields_marked_eq_imp: "eq_imp (λr'. gc_field_set ❙⊗ gc_tmp_ref ❙⊗ (λs. map_option obj_fields (sys_heap s r')) ❙⊗ (λs. map_option obj_mark (sys_heap s r')) ❙⊗ sys_fM ❙⊗ tso_pending_mutate gc) obj_fields_marked" unfolding eq_imp_def obj_fields_marked_def obj_at_field_on_heap_def obj_at_def (*goal: ‹∀s s'. (∀x. (gc_field_set s, gc_tmp_ref s, map_option obj_fields (sys_heap s x), map_option obj_mark (sys_heap s x), sys_fM s, filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s)) = (gc_field_set s', gc_tmp_ref s', map_option obj_fields (sys_heap s' x), map_option obj_mark (sys_heap s' x), sys_fM s', filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'))) ⟶ (∀x. x ∈ (- gc_field_set) s ⟶ (case map_option obj_fields (sys_heap s (gc_tmp_ref s)) of None ⇒ False | Some fs ⇒ case fs x of None ⇒ True | Some r' ⇒ case sys_heap s r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s)) = (∀x. x ∈ (- gc_field_set) s' ⟶ (case map_option obj_fields (sys_heap s' (gc_tmp_ref s')) of None ⇒ False | Some fs ⇒ case fs x of None ⇒ True | Some r' ⇒ case sys_heap s' r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'))›*) apply (clarsimp simp: all_conj_distrib (*‹(∀x. ?P x ∧ ?Q x) = ((∀x. ?P x) ∧ (∀x. ?Q x))›*)) (*goal: ‹∀s s'. (∀x. (gc_field_set s, gc_tmp_ref s, map_option obj_fields (sys_heap s x), map_option obj_mark (sys_heap s x), sys_fM s, filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s)) = (gc_field_set s', gc_tmp_ref s', map_option obj_fields (sys_heap s' x), map_option obj_mark (sys_heap s' x), sys_fM s', filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'))) ⟶ (∀x. x ∈ (- gc_field_set) s ⟶ (case map_option obj_fields (sys_heap s (gc_tmp_ref s)) of None ⇒ False | Some fs ⇒ case fs x of None ⇒ True | Some r' ⇒ case sys_heap s r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s)) = (∀x. x ∈ (- gc_field_set) s' ⟶ (case map_option obj_fields (sys_heap s' (gc_tmp_ref s')) of None ⇒ False | Some fs ⇒ case fs x of None ⇒ True | Some r' ⇒ case sys_heap s' r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'))›*) apply (rule iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*)) (*goals: 1. ‹⋀s s'. ⟦gc_field_set s = gc_field_set s'; gc_tmp_ref s = gc_tmp_ref s'; ∀x. map_option obj_fields (sys_heap s x) = map_option obj_fields (sys_heap s' x); ∀x. map_option obj_mark (sys_heap s x) = map_option obj_mark (sys_heap s' x); sys_fM s = sys_fM s'; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'); ∀x. x ∉ gc_field_set s' ⟶ (case sys_heap s' (gc_tmp_ref s') of None ⇒ False | Some xa ⇒ ((λfs. case fs x of None ⇒ True | Some r' ⇒ case sys_heap s r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s) ∘ obj_fields) xa)⟧ ⟹ ∀x. x ∉ gc_field_set s' ⟶ (case sys_heap s' (gc_tmp_ref s') of None ⇒ False | Some xa ⇒ ((λfs. case fs x of None ⇒ True | Some r' ⇒ case sys_heap s' r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s') ∘ obj_fields) xa)› 2. ‹⋀s s'. ⟦gc_field_set s = gc_field_set s'; gc_tmp_ref s = gc_tmp_ref s'; ∀x. map_option obj_fields (sys_heap s x) = map_option obj_fields (sys_heap s' x); ∀x. map_option obj_mark (sys_heap s x) = map_option obj_mark (sys_heap s' x); sys_fM s = sys_fM s'; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'); ∀x. x ∉ gc_field_set s' ⟶ (case sys_heap s' (gc_tmp_ref s') of None ⇒ False | Some xa ⇒ ((λfs. case fs x of None ⇒ True | Some r' ⇒ case sys_heap s' r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s') ∘ obj_fields) xa)⟧ ⟹ ∀x. x ∉ gc_field_set s' ⟶ (case sys_heap s' (gc_tmp_ref s') of None ⇒ False | Some xa ⇒ ((λfs. case fs x of None ⇒ True | Some r' ⇒ case sys_heap s r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s) ∘ obj_fields) xa)› discuss goal 1*) apply (clarsimp split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) (*top goal: ‹⋀s s'. ⟦gc_field_set s = gc_field_set s'; gc_tmp_ref s = gc_tmp_ref s'; ∀x. map_option obj_fields (sys_heap s x) = map_option obj_fields (sys_heap s' x); ∀x. map_option obj_mark (sys_heap s x) = map_option obj_mark (sys_heap s' x); sys_fM s = sys_fM s'; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'); ∀x. x ∉ gc_field_set s' ⟶ (case sys_heap s' (gc_tmp_ref s') of None ⇒ False | Some xa ⇒ ((λfs. case fs x of None ⇒ True | Some r' ⇒ case sys_heap s r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s) ∘ obj_fields) xa)⟧ ⟹ ∀x. x ∉ gc_field_set s' ⟶ (case sys_heap s' (gc_tmp_ref s') of None ⇒ False | Some xa ⇒ ((λfs. case fs x of None ⇒ True | Some r' ⇒ case sys_heap s' r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s') ∘ obj_fields) xa)› and 1 goal remains*) apply (intro allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*) conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*) impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goals: 1. ‹⋀s s' x. ⟦∀x. ((∃y. sys_heap s' (gc_tmp_ref s') = Some y) ∨ x ∈ gc_field_set s') ∧ (∀x2. sys_heap s' (gc_tmp_ref s') = Some x2 ⟶ (∀x2a. (obj_fields x2 x = Some x2a ⟶ (∃y. sys_heap s x2a = Some y) ∨ x ∈ gc_field_set s') ∧ (obj_fields x2 x = Some x2a ⟶ (∀x2. sys_heap s x2a = Some x2 ⟶ x ∈ gc_field_set s' ∨ obj_mark x2 = sys_fM s')))); gc_field_set s = gc_field_set s'; gc_tmp_ref s = gc_tmp_ref s'; ∀x. map_option obj_fields (sys_heap s x) = map_option obj_fields (sys_heap s' x); ∀x. map_option obj_mark (sys_heap s x) = map_option obj_mark (sys_heap s' x); sys_fM s = sys_fM s'; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'); sys_heap s' (gc_tmp_ref s') = None⟧ ⟹ x ∈ gc_field_set s'› 2. ‹⋀s s' x x2 x2a. ⟦∀x. ((∃y. sys_heap s' (gc_tmp_ref s') = Some y) ∨ x ∈ gc_field_set s') ∧ (∀x2. sys_heap s' (gc_tmp_ref s') = Some x2 ⟶ (∀x2a. (obj_fields x2 x = Some x2a ⟶ (∃y. sys_heap s x2a = Some y) ∨ x ∈ gc_field_set s') ∧ (obj_fields x2 x = Some x2a ⟶ (∀x2. sys_heap s x2a = Some x2 ⟶ x ∈ gc_field_set s' ∨ obj_mark x2 = sys_fM s')))); gc_field_set s = gc_field_set s'; gc_tmp_ref s = gc_tmp_ref s'; ∀x. map_option obj_fields (sys_heap s x) = map_option obj_fields (sys_heap s' x); ∀x. map_option obj_mark (sys_heap s x) = map_option obj_mark (sys_heap s' x); sys_fM s = sys_fM s'; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'); sys_heap s' x2a = None; obj_fields x2 x = Some x2a; sys_heap s' (gc_tmp_ref s') = Some x2⟧ ⟹ x ∈ gc_field_set s'› 3. ‹⋀s s' x x2 x2a x2b. ⟦∀x. ((∃y. sys_heap s' (gc_tmp_ref s') = Some y) ∨ x ∈ gc_field_set s') ∧ (∀x2. sys_heap s' (gc_tmp_ref s') = Some x2 ⟶ (∀x2a. (obj_fields x2 x = Some x2a ⟶ (∃y. sys_heap s x2a = Some y) ∨ x ∈ gc_field_set s') ∧ (obj_fields x2 x = Some x2a ⟶ (∀x2. sys_heap s x2a = Some x2 ⟶ x ∈ gc_field_set s' ∨ obj_mark x2 = sys_fM s')))); gc_field_set s = gc_field_set s'; gc_tmp_ref s = gc_tmp_ref s'; ∀x. map_option obj_fields (sys_heap s x) = map_option obj_fields (sys_heap s' x); ∀x. map_option obj_mark (sys_heap s x) = map_option obj_mark (sys_heap s' x); sys_fM s = sys_fM s'; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'); sys_heap s' x2a = Some x2b; obj_fields x2 x = Some x2a; sys_heap s' (gc_tmp_ref s') = Some x2; x ∉ gc_field_set s'⟧ ⟹ obj_mark x2b = sys_fM s'› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*top goal: ‹⋀s s' x x2 x2a. ⟦∀x. ((∃y. sys_heap s' (gc_tmp_ref s') = Some y) ∨ x ∈ gc_field_set s') ∧ (∀x2. sys_heap s' (gc_tmp_ref s') = Some x2 ⟶ (∀x2a. (obj_fields x2 x = Some x2a ⟶ (∃y. sys_heap s x2a = Some y) ∨ x ∈ gc_field_set s') ∧ (obj_fields x2 x = Some x2a ⟶ (∀x2. sys_heap s x2a = Some x2 ⟶ x ∈ gc_field_set s' ∨ obj_mark x2 = sys_fM s')))); gc_field_set s = gc_field_set s'; gc_tmp_ref s = gc_tmp_ref s'; ∀x. map_option obj_fields (sys_heap s x) = map_option obj_fields (sys_heap s' x); ∀x. map_option obj_mark (sys_heap s x) = map_option obj_mark (sys_heap s' x); sys_fM s = sys_fM s'; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'); sys_heap s' x2a = None; obj_fields x2 x = Some x2a; sys_heap s' (gc_tmp_ref s') = Some x2⟧ ⟹ x ∈ gc_field_set s'› and 2 goals remain*) apply (metis (no_types, opaque_lifting) option.distinct( (*‹None ≠ Some ?x2.0›*) 1) option.map_disc_iff (*‹(map_option ?f ?a = None) = (?a = None)›*)) (*discuss goal 3*) apply simp (*top goal: ‹⋀s s' x x2 x2a x2b. ⟦∀x. ((∃y. sys_heap s' (gc_tmp_ref s') = Some y) ∨ x ∈ gc_field_set s') ∧ (∀x2. sys_heap s' (gc_tmp_ref s') = Some x2 ⟶ (∀x2a. (obj_fields x2 x = Some x2a ⟶ (∃y. sys_heap s x2a = Some y) ∨ x ∈ gc_field_set s') ∧ (obj_fields x2 x = Some x2a ⟶ (∀x2. sys_heap s x2a = Some x2 ⟶ x ∈ gc_field_set s' ∨ obj_mark x2 = sys_fM s')))); gc_field_set s = gc_field_set s'; gc_tmp_ref s = gc_tmp_ref s'; ∀x. map_option obj_fields (sys_heap s x) = map_option obj_fields (sys_heap s' x); ∀x. map_option obj_mark (sys_heap s x) = map_option obj_mark (sys_heap s' x); sys_fM s = sys_fM s'; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'); sys_heap s' x2a = Some x2b; obj_fields x2 x = Some x2a; sys_heap s' (gc_tmp_ref s') = Some x2; x ∉ gc_field_set s'⟧ ⟹ obj_mark x2b = sys_fM s'› and 1 goal remains*) apply (metis (no_types, lifting) option.distinct( (*‹None ≠ Some ?x2.0›*) 1) option.map_sel (*‹?a ≠ None ⟹ the (map_option ?f ?a) = ?f (the ?a)›*) option.sel (*‹the (Some ?x2.0) = ?x2.0›*)) (*proven 3 subgoals*) (*discuss goal 2*) apply (clarsimp split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) (*goal: ‹⋀(s::'b process_name ⇒ ('c, 'b, 'd, 'a) Model.local_state) s'::'b process_name ⇒ ('c, 'b, 'd, 'a) Model.local_state. ⟦gc_field_set s = gc_field_set s'; gc_tmp_ref s = gc_tmp_ref s'; ∀x::'a. map_option obj_fields (sys_heap s x) = map_option obj_fields (sys_heap s' x); ∀x::'a. map_option obj_mark (sys_heap s x) = map_option obj_mark (sys_heap s' x); sys_fM s = sys_fM s'; filter (λs::('c, 'd, 'a) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s) = filter (λs::('c, 'd, 'a) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'); ∀x::'c. x ∉ gc_field_set s' ⟶ (case sys_heap s' (gc_tmp_ref s') of None ⇒ False | Some (xa::('c, 'd, 'a) object) ⇒ ((λfs::'c ⇒ 'a option. case fs x of None ⇒ True | Some (r'::'a) ⇒ case sys_heap s' r' of None ⇒ False | Some (obj::('c, 'd, 'a) object) ⇒ obj_mark obj = sys_fM s') ∘ obj_fields) xa)⟧ ⟹ ∀x::'c. x ∉ gc_field_set s' ⟶ (case sys_heap s' (gc_tmp_ref s') of None ⇒ False | Some (xa::('c, 'd, 'a) object) ⇒ ((λfs::'c ⇒ 'a option. case fs x of None ⇒ True | Some (r'::'a) ⇒ case sys_heap s r' of None ⇒ False | Some (obj::('c, 'd, 'a) object) ⇒ obj_mark obj = sys_fM s) ∘ obj_fields) xa)›*) apply (intro allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*) conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*) impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goals: 1. ‹⋀s s' x. ⟦∀x. ((∃y. sys_heap s' (gc_tmp_ref s') = Some y) ∨ x ∈ gc_field_set s') ∧ (∀x2. sys_heap s' (gc_tmp_ref s') = Some x2 ⟶ (∀x2a. (obj_fields x2 x = Some x2a ⟶ (∃y. sys_heap s' x2a = Some y) ∨ x ∈ gc_field_set s') ∧ (obj_fields x2 x = Some x2a ⟶ (∀x2. sys_heap s' x2a = Some x2 ⟶ x ∈ gc_field_set s' ∨ obj_mark x2 = sys_fM s')))); gc_field_set s = gc_field_set s'; gc_tmp_ref s = gc_tmp_ref s'; ∀x. map_option obj_fields (sys_heap s x) = map_option obj_fields (sys_heap s' x); ∀x. map_option obj_mark (sys_heap s x) = map_option obj_mark (sys_heap s' x); sys_fM s = sys_fM s'; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'); sys_heap s' (gc_tmp_ref s') = None⟧ ⟹ x ∈ gc_field_set s'› 2. ‹⋀s s' x x2 x2a. ⟦∀x. ((∃y. sys_heap s' (gc_tmp_ref s') = Some y) ∨ x ∈ gc_field_set s') ∧ (∀x2. sys_heap s' (gc_tmp_ref s') = Some x2 ⟶ (∀x2a. (obj_fields x2 x = Some x2a ⟶ (∃y. sys_heap s' x2a = Some y) ∨ x ∈ gc_field_set s') ∧ (obj_fields x2 x = Some x2a ⟶ (∀x2. sys_heap s' x2a = Some x2 ⟶ x ∈ gc_field_set s' ∨ obj_mark x2 = sys_fM s')))); gc_field_set s = gc_field_set s'; gc_tmp_ref s = gc_tmp_ref s'; ∀x. map_option obj_fields (sys_heap s x) = map_option obj_fields (sys_heap s' x); ∀x. map_option obj_mark (sys_heap s x) = map_option obj_mark (sys_heap s' x); sys_fM s = sys_fM s'; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'); sys_heap s x2a = None; obj_fields x2 x = Some x2a; sys_heap s' (gc_tmp_ref s') = Some x2⟧ ⟹ x ∈ gc_field_set s'› 3. ‹⋀s s' x x2 x2a x2b. ⟦∀x. ((∃y. sys_heap s' (gc_tmp_ref s') = Some y) ∨ x ∈ gc_field_set s') ∧ (∀x2. sys_heap s' (gc_tmp_ref s') = Some x2 ⟶ (∀x2a. (obj_fields x2 x = Some x2a ⟶ (∃y. sys_heap s' x2a = Some y) ∨ x ∈ gc_field_set s') ∧ (obj_fields x2 x = Some x2a ⟶ (∀x2. sys_heap s' x2a = Some x2 ⟶ x ∈ gc_field_set s' ∨ obj_mark x2 = sys_fM s')))); gc_field_set s = gc_field_set s'; gc_tmp_ref s = gc_tmp_ref s'; ∀x. map_option obj_fields (sys_heap s x) = map_option obj_fields (sys_heap s' x); ∀x. map_option obj_mark (sys_heap s x) = map_option obj_mark (sys_heap s' x); sys_fM s = sys_fM s'; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'); sys_heap s x2a = Some x2b; obj_fields x2 x = Some x2a; sys_heap s' (gc_tmp_ref s') = Some x2; x ∉ gc_field_set s'⟧ ⟹ obj_mark x2b = sys_fM s'› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*top goal: ‹⋀s s' x x2 x2a. ⟦∀x. ((∃y. sys_heap s' (gc_tmp_ref s') = Some y) ∨ x ∈ gc_field_set s') ∧ (∀x2. sys_heap s' (gc_tmp_ref s') = Some x2 ⟶ (∀x2a. (obj_fields x2 x = Some x2a ⟶ (∃y. sys_heap s' x2a = Some y) ∨ x ∈ gc_field_set s') ∧ (obj_fields x2 x = Some x2a ⟶ (∀x2. sys_heap s' x2a = Some x2 ⟶ x ∈ gc_field_set s' ∨ obj_mark x2 = sys_fM s')))); gc_field_set s = gc_field_set s'; gc_tmp_ref s = gc_tmp_ref s'; ∀x. map_option obj_fields (sys_heap s x) = map_option obj_fields (sys_heap s' x); ∀x. map_option obj_mark (sys_heap s x) = map_option obj_mark (sys_heap s' x); sys_fM s = sys_fM s'; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'); sys_heap s x2a = None; obj_fields x2 x = Some x2a; sys_heap s' (gc_tmp_ref s') = Some x2⟧ ⟹ x ∈ gc_field_set s'› and 1 goal remains*) apply (metis (no_types, opaque_lifting) option.distinct( (*‹None ≠ Some (?x2.0::?'a)›*) 1) option.map_disc_iff (*‹(map_option (?f::?'a ⇒ ?'b) (?a::?'a option) = None) = (?a = None)›*)) (*discuss goal 3*) apply simp (*goal: ‹⋀(s::'b::type process_name ⇒ ('c, 'b, 'd, 'a) Model.local_state) (s'::'b::type process_name ⇒ ('c, 'b, 'd, 'a) Model.local_state) (x::'c::type) (x2::('c, 'd, 'a) object) (x2a::'a::type) x2b::('c, 'd, 'a) object. ⟦∀x::'c::type. ((∃y::('c, 'd, 'a) object. sys_heap s' (gc_tmp_ref s') = Some y) ∨ x ∈ gc_field_set s') ∧ (∀x2::('c, 'd, 'a) object. sys_heap s' (gc_tmp_ref s') = Some x2 ⟶ (∀x2a::'a::type. (obj_fields x2 x = Some x2a ⟶ (∃y::('c, 'd, 'a) object. sys_heap s' x2a = Some y) ∨ x ∈ gc_field_set s') ∧ (obj_fields x2 x = Some x2a ⟶ (∀x2::('c, 'd, 'a) object. sys_heap s' x2a = Some x2 ⟶ x ∈ gc_field_set s' ∨ obj_mark x2 = sys_fM s')))); gc_field_set s = gc_field_set s'; gc_tmp_ref s = gc_tmp_ref s'; ∀x::'a::type. map_option obj_fields (sys_heap s x) = map_option obj_fields (sys_heap s' x); ∀x::'a::type. map_option obj_mark (sys_heap s x) = map_option obj_mark (sys_heap s' x); sys_fM s = sys_fM s'; filter (λs::('c::type, 'd::type, 'a::type) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s) = filter (λs::('c::type, 'd::type, 'a::type) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'); sys_heap s x2a = Some x2b; obj_fields x2 x = Some x2a; sys_heap s' (gc_tmp_ref s') = Some x2; x ∉ gc_field_set s'⟧ ⟹ obj_mark x2b = sys_fM s'›*) apply (metis (no_types, lifting) option.distinct( (*‹None ≠ Some ?x2.0›*) 1) option.map_sel (*‹?a ≠ None ⟹ the (map_option ?f ?a) = ?f (the ?a)›*) option.sel (*‹the (Some ?x2.0) = ?x2.0›*)) (*proven 3 subgoals*) (*proven 2 subgoals*) . lemma obj_fields_marked_UNIV[iff]: "obj_fields_marked (s(gc := (s gc)⦇ field_set := UNIV ⦈))" unfolding obj_fields_marked_def (*goal: ‹∀x. x ∈ (- gc_field_set) (s(gc := s gc⦇field_set := UNIV⦈)) ⟶ obj_at_field_on_heap (λr. marked r (s(gc := s gc⦇field_set := UNIV⦈))) (gc_tmp_ref (s(gc := s gc⦇field_set := UNIV⦈))) x (s(gc := s gc⦇field_set := UNIV⦈))›*) by (simp add: fun_upd_apply (*‹(?f(?x := ?y)) ?z = (if ?z = ?x then ?y else ?f ?z)›*)) lemma obj_fields_marked_invL_eq_imp: "eq_imp (λr' s. (AT s gc, s↓ gc, map_option obj_fields (sys_heap s↓ r'), map_option obj_mark (sys_heap s↓ r'), sys_fM s↓, sys_W s↓, tso_pending_mutate gc s↓)) obj_fields_marked_invL" unfolding eq_imp_def inv obj_at_def obj_at_field_on_heap_def (*goal: ‹∀(s::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state) s'::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state. (∀x::'a::type. (AT s gc, s↓ gc, map_option obj_fields (sys_heap s↓ x), map_option obj_mark (sys_heap s↓ x), sys_fM s↓, sys_W s↓, filter (λs::('b::type, 'c::type, 'a::type) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓)) = (AT s' gc, s'↓ gc, map_option obj_fields (sys_heap s'↓ x), map_option obj_mark (sys_heap s'↓ x), sys_fM s'↓, sys_W s'↓, filter (λs::('b::type, 'c::type, 'a::type) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓))) ⟶ ((atS gc obj_fields_marked_locs s ⟶ obj_fields_marked s↓ ∧ gc_tmp_ref s↓ ∈ gc_W s↓) ∧ (atS gc obj_fields_marked_good_ref_locs s ⟶ (case map_option obj_fields (sys_heap s↓ (gc_tmp_ref s↓)) of None ⇒ False | Some (fs::'b::type ⇒ 'a::type option) ⇒ case fs (gc_field s↓) of None ⇒ True | Some (r'::'a::type) ⇒ gc_ref s↓ = Some r' ∨ (case sys_heap s↓ r' of None ⇒ False | Some (obj::('b, 'c, 'a) object) ⇒ obj_mark obj = sys_fM s↓))) ∧ (atS gc mark_loop_mo_locs s ⟶ (∀x::'a::type. gc_ref s↓ ≠ None ∧ (gc_the_ref s↓ reaches x) s↓ ⟶ (case sys_heap s↓ x of None ⇒ False | Some (obj::('b, 'c, 'a) object) ⇒ True))) ∧ (at gc mark_loop_fields s ⟶ gc_tmp_ref s↓ ∈ gc_W s↓) ∧ (at gc mark_loop_mark_field_done s ⟶ gc_ref s↓ ≠ None ⟶ (case sys_heap s↓ (gc_the_ref s↓) of None ⇒ False | Some (obj::('b, 'c, 'a) object) ⇒ obj_mark obj = sys_fM s↓)) ∧ (at gc mark_loop_blacken s ⟶ gc_field_set s↓ = {}) ∧ (atS gc ghost_honorary_grey_empty_locs s ⟶ gc_ghost_honorary_grey s↓ = {})) = ((atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s'↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓) ∧ (atS gc obj_fields_marked_good_ref_locs s' ⟶ (case map_option obj_fields (sys_heap s'↓ (gc_tmp_ref s'↓)) of None ⇒ False | Some (fs::'b::type ⇒ 'a::type option) ⇒ case fs (gc_field s'↓) of None ⇒ True | Some (r'::'a::type) ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s'↓ r' of None ⇒ False | Some (obj::('b, 'c, 'a) object) ⇒ obj_mark obj = sys_fM s'↓))) ∧ (atS gc mark_loop_mo_locs s' ⟶ (∀x::'a::type. gc_ref s'↓ ≠ None ∧ (gc_the_ref s'↓ reaches x) s'↓ ⟶ (case sys_heap s'↓ x of None ⇒ False | Some (obj::('b, 'c, 'a) object) ⇒ True))) ∧ (at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓) ∧ (at gc mark_loop_mark_field_done s' ⟶ gc_ref s'↓ ≠ None ⟶ (case sys_heap s'↓ (gc_the_ref s'↓) of None ⇒ False | Some (obj::('b, 'c, 'a) object) ⇒ obj_mark obj = sys_fM s'↓)) ∧ (at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}) ∧ (atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}))›*) apply (clarsimp simp: all_conj_distrib (*‹(∀x. ?P x ∧ ?Q x) = ((∀x. ?P x) ∧ (∀x. ?Q x))›*) cong: option.case_cong (*‹⟦?option = ?option'; ?option' = None ⟹ ?f1.0 = ?g1.0; ⋀x2. ?option' = Some x2 ⟹ ?f2.0 x2 = ?g2.0 x2⟧ ⟹ (case ?option of None ⇒ ?f1.0 | Some x2 ⇒ ?f2.0 x2) = (case ?option' of None ⇒ ?g1.0 | Some x2 ⇒ ?g2.0 x2)›*)) (*goal: ‹∀s s'. (∀x. (AT s gc, s↓ gc, map_option obj_fields (sys_heap s↓ x), map_option obj_mark (sys_heap s↓ x), sys_fM s↓, sys_W s↓, filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓)) = (AT s' gc, s'↓ gc, map_option obj_fields (sys_heap s'↓ x), map_option obj_mark (sys_heap s'↓ x), sys_fM s'↓, sys_W s'↓, filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓))) ⟶ ((atS gc obj_fields_marked_locs s ⟶ obj_fields_marked s↓ ∧ gc_tmp_ref s↓ ∈ gc_W s↓) ∧ (atS gc obj_fields_marked_good_ref_locs s ⟶ (case map_option obj_fields (sys_heap s↓ (gc_tmp_ref s↓)) of None ⇒ False | Some fs ⇒ case fs (gc_field s↓) of None ⇒ True | Some r' ⇒ gc_ref s↓ = Some r' ∨ (case sys_heap s↓ r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s↓))) ∧ (atS gc mark_loop_mo_locs s ⟶ (∀x. gc_ref s↓ ≠ None ∧ (gc_the_ref s↓ reaches x) s↓ ⟶ (case sys_heap s↓ x of None ⇒ False | Some obj ⇒ True))) ∧ (at gc mark_loop_fields s ⟶ gc_tmp_ref s↓ ∈ gc_W s↓) ∧ (at gc mark_loop_mark_field_done s ⟶ gc_ref s↓ ≠ None ⟶ (case sys_heap s↓ (gc_the_ref s↓) of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s↓)) ∧ (at gc mark_loop_blacken s ⟶ gc_field_set s↓ = {}) ∧ (atS gc ghost_honorary_grey_empty_locs s ⟶ gc_ghost_honorary_grey s↓ = {})) = ((atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s'↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓) ∧ (atS gc obj_fields_marked_good_ref_locs s' ⟶ (case map_option obj_fields (sys_heap s'↓ (gc_tmp_ref s'↓)) of None ⇒ False | Some fs ⇒ case fs (gc_field s'↓) of None ⇒ True | Some r' ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s'↓ r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓))) ∧ (atS gc mark_loop_mo_locs s' ⟶ (∀x. gc_ref s'↓ ≠ None ∧ (gc_the_ref s'↓ reaches x) s'↓ ⟶ (case sys_heap s'↓ x of None ⇒ False | Some obj ⇒ True))) ∧ (at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓) ∧ (at gc mark_loop_mark_field_done s' ⟶ gc_ref s'↓ ≠ None ⟶ (case sys_heap s'↓ (gc_the_ref s'↓) of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓)) ∧ (at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}) ∧ (atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}))›*) apply (rule iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*)) (*goal: ‹⋀s s'. ⟦AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓)⟧ ⟹ ((atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓) ∧ (atS gc obj_fields_marked_good_ref_locs s' ⟶ (case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some r' ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s↓ r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓))) ∧ (atS gc mark_loop_mo_locs s' ⟶ (∀x. (∃y. gc_ref s'↓ = Some y) ∧ (the (gc_ref s'↓) reaches x) s↓ ⟶ (case sys_heap s↓ x of None ⇒ False | Some obj ⇒ True))) ∧ (at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓) ∧ (at gc mark_loop_mark_field_done s' ⟶ (∃y. gc_ref s'↓ = Some y) ⟶ (case sys_heap s↓ (the (gc_ref s'↓)) of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓)) ∧ (at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}) ∧ (atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {})) = ((atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s'↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓) ∧ (atS gc obj_fields_marked_good_ref_locs s' ⟶ (case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some r' ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s'↓ r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓))) ∧ (atS gc mark_loop_mo_locs s' ⟶ (∀x. (∃y. gc_ref s'↓ = Some y) ∧ (the (gc_ref s'↓) reaches x) s'↓ ⟶ (case sys_heap s'↓ x of None ⇒ False | Some obj ⇒ True))) ∧ (at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓) ∧ (at gc mark_loop_mark_field_done s' ⟶ (∃y. gc_ref s'↓ = Some y) ⟶ (case sys_heap s'↓ (the (gc_ref s'↓)) of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓)) ∧ (at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}) ∧ (atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}))›*) apply (intro conjI (*‹⟦?P::bool; ?Q::bool⟧ ⟹ ?P ∧ ?Q›*) impI (*‹(?P::bool ⟹ ?Q::bool) ⟹ ?P ⟶ ?Q›*); clarsimp) (*top goal: ‹⋀s s'. ⟦AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); (atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓) ∧ (atS gc obj_fields_marked_good_ref_locs s' ⟶ (case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some r' ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s↓ r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓))) ∧ (atS gc mark_loop_mo_locs s' ⟶ (∀x. (∃y. gc_ref s'↓ = Some y) ∧ (the (gc_ref s'↓) reaches x) s↓ ⟶ (case sys_heap s↓ x of None ⇒ False | Some obj ⇒ True))) ∧ (at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓) ∧ (at gc mark_loop_mark_field_done s' ⟶ (∃y. gc_ref s'↓ = Some y) ⟶ (case sys_heap s↓ (the (gc_ref s'↓)) of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓)) ∧ (at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}) ∧ (atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {})⟧ ⟹ (atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s'↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓) ∧ (atS gc obj_fields_marked_good_ref_locs s' ⟶ (case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some r' ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s'↓ r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓))) ∧ (atS gc mark_loop_mo_locs s' ⟶ (∀x. (∃y. gc_ref s'↓ = Some y) ∧ (the (gc_ref s'↓) reaches x) s'↓ ⟶ (case sys_heap s'↓ x of None ⇒ False | Some obj ⇒ True))) ∧ (at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓) ∧ (at gc mark_loop_mark_field_done s' ⟶ (∃y. gc_ref s'↓ = Some y) ⟶ (case sys_heap s'↓ (the (gc_ref s'↓)) of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓)) ∧ (at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}) ∧ (atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {})› and 1 goal remains*) apply (subst eq_impD[OF obj_fields_marked_eq_imp] (*‹∀x::?'a::type. (gc_field_set (?s::?'b1::type process_name ⇒ (?'c1, ?'b1, ?'d1, ?'a) Model.local_state), gc_tmp_ref ?s, map_option obj_fields (sys_heap ?s x), map_option obj_mark (sys_heap ?s x), sys_fM ?s, filter (λs::(?'c1::type, ?'d1::type, ?'a::type) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc ?s)) = (gc_field_set (?s'::?'b1::type process_name ⇒ (?'c1, ?'b1, ?'d1, ?'a) Model.local_state), gc_tmp_ref ?s', map_option obj_fields (sys_heap ?s' x), map_option obj_mark (sys_heap ?s' x), sys_fM ?s', filter (λs::(?'c1::type, ?'d1::type, ?'a::type) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc ?s')) ⟹ obj_fields_marked ?s = obj_fields_marked ?s'›*); force) (*top goal: ‹⋀s s'. ⟦AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); atS gc obj_fields_marked_locs s'; obj_fields_marked s↓; gc_tmp_ref s'↓ ∈ gc_W s'↓; atS gc obj_fields_marked_good_ref_locs s' ⟶ (case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some r' ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s↓ r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓)); atS gc mark_loop_mo_locs s' ⟶ (∀x. (∃y. gc_ref s'↓ = Some y) ∧ (the (gc_ref s'↓) reaches x) s↓ ⟶ (case sys_heap s↓ x of None ⇒ False | Some obj ⇒ True)); at gc mark_loop_mark_field_done s' ⟶ (∃y. gc_ref s'↓ = Some y) ⟶ (case sys_heap s↓ (the (gc_ref s'↓)) of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓); at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}⟧ ⟹ obj_fields_marked s'↓› and 4 goals remain*) apply (clarsimp split: option.split_asm (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) (*top goal: ‹⋀s s'. ⟦AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); atS gc obj_fields_marked_good_ref_locs s'; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some r' ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s↓ r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓); atS gc mark_loop_mo_locs s' ⟶ (∀x. (∃y. gc_ref s'↓ = Some y) ∧ (the (gc_ref s'↓) reaches x) s↓ ⟶ (case sys_heap s↓ x of None ⇒ False | Some obj ⇒ True)); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; at gc mark_loop_mark_field_done s' ⟶ (∃y. gc_ref s'↓ = Some y) ⟶ (case sys_heap s↓ (the (gc_ref s'↓)) of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓); at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}⟧ ⟹ case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some r' ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s'↓ r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓)› and 3 goals remain*) apply (metis (no_types, lifting) None_eq_map_option_iff (*‹(None = map_option ?f ?x) = (?x = None)›*) option.simps( (*‹Some ?x2.0 ≠ None›*) 3)) (*top goal: ‹⋀(s::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state) (s'::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state) (x2::('b, 'c, 'a) object) (x2a::'a) x2b::('b, 'c, 'a) object. ⟦obj_mark x2b = sys_fM s'↓; atS gc mark_loop_mo_locs s' ⟶ (∀x::'a. (∃y::('b, 'c, 'a) object. sys_heap s↓ x = Some y) ∨ gc_ref s'↓ = None ∨ ¬ (the (gc_ref s'↓) reaches x) s↓); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s↓ (the (gc_ref s'↓)) = None; at gc mark_loop_mark_field_done s' ⟶ gc_ref s'↓ = None; at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}; AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x::'a. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x::'a. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs::('b, 'c, 'a) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs::('b, 'c, 'a) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); atS gc obj_fields_marked_good_ref_locs s'; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s'↓ (gc_tmp_ref s'↓) = Some x2; obj_fields x2 (gc_field s'↓) = Some x2a; sys_heap s↓ x2a = Some x2b; sys_heap s'↓ x2a = None⟧ ⟹ gc_ref s'↓ = Some x2a› and 6 goals remain*) apply (metis (no_types, lifting) option.distinct( (*‹None ≠ Some ?x2.0›*) 1) option.map_sel (*‹?a ≠ None ⟹ the (map_option ?f ?a) = ?f (the ?a)›*) option.sel (*‹the (Some ?x2.0) = ?x2.0›*)) (*top goal: ‹⋀s s' x2 x2a x2b x2c. ⟦obj_mark x2b = sys_fM s'↓; atS gc mark_loop_mo_locs s' ⟶ (∀x. (∃y. sys_heap s↓ x = Some y) ∨ gc_ref s'↓ = None ∨ ¬ (the (gc_ref s'↓) reaches x) s↓); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s↓ (the (gc_ref s'↓)) = None; at gc mark_loop_mark_field_done s' ⟶ gc_ref s'↓ = None; at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}; AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); atS gc obj_fields_marked_good_ref_locs s'; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s'↓ (gc_tmp_ref s'↓) = Some x2; obj_fields x2 (gc_field s'↓) = Some x2a; sys_heap s↓ x2a = Some x2b; sys_heap s'↓ x2a = Some x2c; obj_mark x2c = (¬ sys_fM s'↓)⟧ ⟹ gc_ref s'↓ = Some x2a› and 5 goals remain*) apply (metis (no_types, lifting) None_eq_map_option_iff (*‹(None = map_option ?f ?x) = (?x = None)›*) option.simps( (*‹Some ?x2.0 ≠ None›*) 3)) (*top goal: ‹⋀s s' x2 x2a x2b x2c. ⟦obj_mark x2c = sys_fM s'↓; atS gc mark_loop_mo_locs s' ⟶ (∀x. (∃y. sys_heap s↓ x = Some y) ∨ gc_ref s'↓ = None ∨ ¬ (the (gc_ref s'↓) reaches x) s↓); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s↓ (the (gc_ref s'↓)) = Some x2a; at gc mark_loop_mark_field_done s' ⟶ (∃y. gc_ref s'↓ = Some y) ⟶ obj_mark x2a = sys_fM s'↓; at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}; AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); atS gc obj_fields_marked_good_ref_locs s'; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s'↓ (gc_tmp_ref s'↓) = Some x2; obj_fields x2 (gc_field s'↓) = Some x2b; sys_heap s↓ x2b = Some x2c; sys_heap s'↓ x2b = None⟧ ⟹ gc_ref s'↓ = Some x2b› and 4 goals remain*) apply (metis (no_types, lifting) option.distinct( (*‹None ≠ Some ?x2.0›*) 1) option.map_sel (*‹?a ≠ None ⟹ the (map_option ?f ?a) = ?f (the ?a)›*) option.sel (*‹the (Some ?x2.0) = ?x2.0›*)) (*top goal: ‹⋀s s' x2 x2a x2b x2c x2d. ⟦obj_mark x2c = sys_fM s'↓; atS gc mark_loop_mo_locs s' ⟶ (∀x. (∃y. sys_heap s↓ x = Some y) ∨ gc_ref s'↓ = None ∨ ¬ (the (gc_ref s'↓) reaches x) s↓); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s↓ (the (gc_ref s'↓)) = Some x2a; at gc mark_loop_mark_field_done s' ⟶ (∃y. gc_ref s'↓ = Some y) ⟶ obj_mark x2a = sys_fM s'↓; at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}; AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); atS gc obj_fields_marked_good_ref_locs s'; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s'↓ (gc_tmp_ref s'↓) = Some x2; obj_fields x2 (gc_field s'↓) = Some x2b; sys_heap s↓ x2b = Some x2c; sys_heap s'↓ x2b = Some x2d; obj_mark x2d = (¬ sys_fM s'↓)⟧ ⟹ gc_ref s'↓ = Some x2b› and 3 goals remain*) apply (subst (asm) (2) eq_impD[OF reaches_eq_imp] (*‹∀x. ⋃ (ran ` obj_fields ` set_option (sys_heap ?s x)) = ⋃ (ran ` obj_fields ` set_option (sys_heap ?s' x)) ⟹ (?x1 reaches ?y1) ?s = (?x1 reaches ?y1) ?s'›*)) (*top goal: ‹⋀s s' x y. ⟦AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); atS gc mark_loop_mo_locs s'; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; atS gc obj_fields_marked_good_ref_locs s' ⟶ (case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some r' ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s↓ r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓)); ∀x. (y reaches x) s↓ ⟶ (case sys_heap s↓ x of None ⇒ False | Some obj ⇒ True); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; at gc mark_loop_mark_field_done s' ⟶ (case sys_heap s↓ y of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓); at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}; (y reaches x) s'↓; gc_ref s'↓ = Some y⟧ ⟹ case sys_heap s'↓ x of None ⇒ False | Some obj ⇒ True› and 2 goals remain*) prefer 2 (*top goal: ‹⋀s s' x y. ⟦AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); atS gc mark_loop_mo_locs s'; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; atS gc obj_fields_marked_good_ref_locs s' ⟶ (case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some r' ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s↓ r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓)); ∀x. (y reaches x) s↓ ⟶ (case sys_heap s↓ x of None ⇒ False | Some obj ⇒ True); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; at gc mark_loop_mark_field_done s' ⟶ (case sys_heap s↓ y of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓); at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}; (y reaches x) (?s'225 s s' x y); gc_ref s'↓ = Some y⟧ ⟹ case sys_heap s'↓ x of None ⇒ False | Some obj ⇒ True› and 3 goals remain*) apply (drule spec (*‹∀x. ?P x ⟹ ?P ?x›*), drule mp (*‹⟦?P ⟶ ?Q; ?P⟧ ⟹ ?Q›*), assumption) (*top goal: ‹⋀(s::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state) (s'::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state) (x::'a) y::'a. ⟦AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x::'a. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x::'a. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs::('b, 'c, 'a) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs::('b, 'c, 'a) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); atS gc mark_loop_mo_locs s'; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; atS gc obj_fields_marked_good_ref_locs s' ⟶ (case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some (x2::('b, 'c, 'a) object) ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some (r'::'a) ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s↓ r' of None ⇒ False | Some (obj::('b, 'c, 'a) object) ⇒ obj_mark obj = sys_fM s'↓)); ∀x::'a. (y reaches x) s↓ ⟶ (case sys_heap s↓ x of None ⇒ False | Some (obj::('b, 'c, 'a) object) ⇒ True); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; at gc mark_loop_mark_field_done s' ⟶ (case sys_heap s↓ y of None ⇒ False | Some (obj::('b, 'c, 'a) object) ⇒ obj_mark obj = sys_fM s'↓); at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}; (y reaches x) ((?s'225::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state ⇒ (('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state ⇒ 'a ⇒ 'a ⇒ 'd process_name ⇒ ('b, 'd, 'c, 'a) Model.local_state) s s' x y); gc_ref s'↓ = Some y⟧ ⟹ case sys_heap s'↓ x of None ⇒ False | Some (obj::('b, 'c, 'a) object) ⇒ True› and 3 goals remain*) apply (metis (no_types) option.disc_eq_case( (*‹(?option ≠ None) = (case ?option of None ⇒ False | Some uu_ ⇒ True)›*) 2) option.map_disc_iff (*‹(map_option ?f ?a = None) = (?a = None)›*)) (*top goal: ‹⋀s s' x y. ⟦AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); atS gc mark_loop_mo_locs s'; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; atS gc obj_fields_marked_good_ref_locs s' ⟶ (case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some r' ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s↓ r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓)); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; at gc mark_loop_mark_field_done s' ⟶ (case sys_heap s↓ y of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓); at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}; (y reaches x) s↓; gc_ref s'↓ = Some y; case sys_heap s↓ x of None ⇒ False | Some obj ⇒ True⟧ ⟹ case sys_heap s'↓ x of None ⇒ False | Some obj ⇒ True› and 3 goals remain*) apply (metis option.set_map (*‹set_option (map_option ?f ?v) = ?f ` set_option ?v›*)) (*top goal: ‹⋀s s' x y. ⟦gc_ref s'↓ = Some y; AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); atS gc mark_loop_mo_locs s'; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; atS gc obj_fields_marked_good_ref_locs s' ⟶ (case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some r' ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s↓ r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓)); ∀x. (y reaches x) s↓ ⟶ (case sys_heap s↓ x of None ⇒ False | Some obj ⇒ True); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; at gc mark_loop_mark_field_done s' ⟶ (case sys_heap s↓ y of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓); at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}⟧ ⟹ ∀x. ⋃ (ran ` obj_fields ` set_option (sys_heap s'↓ x)) = ⋃ (ran ` obj_fields ` set_option (sys_heap s↓ x))› and 2 goals remain*) apply (clarsimp split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) (*top goal: ‹⋀s s' y. ⟦AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); at gc mark_loop_mark_field_done s'; gc_ref s'↓ = Some y; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; atS gc obj_fields_marked_good_ref_locs s' ⟶ (case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some r' ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s↓ r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓)); atS gc mark_loop_mo_locs s' ⟶ (∀x. (y reaches x) s↓ ⟶ (case sys_heap s↓ x of None ⇒ False | Some obj ⇒ True)); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; case sys_heap s↓ y of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓; at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}⟧ ⟹ case sys_heap s'↓ y of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓› and 1 goal remains*) apply (metis (no_types, opaque_lifting) atS_simps( (*‹atS ?p {?l} ?s = at ?p ?l ?s›*) 2) atS_un (*‹atS ?p (?l ∪ ?l') ?s = (atS ?p ?l ?s ∨ atS ?p ?l' ?s)›*) obj_fields_marked_good_ref_locs_def (*‹obj_fields_marked_good_ref_locs = mark_loop_mo_locs ∪ {mark_loop_mark_field_done}›*)) (*top goal: ‹⋀s s' y x2. ⟦at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}; AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); at gc mark_loop_mark_field_done s'; gc_ref s'↓ = Some y; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s'↓ (gc_tmp_ref s'↓) = None; ¬ atS gc obj_fields_marked_good_ref_locs s'; atS gc mark_loop_mo_locs s' ⟶ (∀x. (∃y. sys_heap s↓ x = Some y) ∨ ¬ (y reaches x) s↓); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s↓ y = Some x2; obj_mark x2 = sys_fM s'↓⟧ ⟹ (∃ya. sys_heap s'↓ y = Some ya) ∧ (∀x2. sys_heap s'↓ y = Some x2 ⟶ obj_mark x2 = sys_fM s'↓)› and 4 goals remain*) apply (metis (no_types, opaque_lifting) map_option_eq_Some (*‹(map_option ?f ?xo = Some ?y) = (∃z. ?xo = Some z ∧ ?f z = ?y)›*) option.inject (*‹(Some ?x2.0 = Some ?y2.0) = (?x2.0 = ?y2.0)›*) option.simps( (*‹map_option ?f (Some ?x2.0) = Some (?f ?x2.0)›*) 9)) (*top goal: ‹⋀s s' y x2 x2a. ⟦atS gc mark_loop_mo_locs s' ⟶ (∀x. (∃y. sys_heap s↓ x = Some y) ∨ ¬ (y reaches x) s↓); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s↓ y = Some x2a; obj_mark x2a = sys_fM s'↓; at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}; AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); at gc mark_loop_mark_field_done s'; gc_ref s'↓ = Some y; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s'↓ (gc_tmp_ref s'↓) = Some x2; obj_fields x2 (gc_field s'↓) = None⟧ ⟹ (∃ya. sys_heap s'↓ y = Some ya) ∧ (∀x2. sys_heap s'↓ y = Some x2 ⟶ obj_mark x2 = sys_fM s'↓)› and 3 goals remain*) apply (metis (no_types, opaque_lifting) map_option_eq_Some (*‹(map_option ?f ?xo = Some ?y) = (∃z. ?xo = Some z ∧ ?f z = ?y)›*) option.inject (*‹(Some ?x2.0 = Some ?y2.0) = (?x2.0 = ?y2.0)›*) option.simps( (*‹map_option ?f (Some ?x2.0) = Some (?f ?x2.0)›*) 9)) (*top goal: ‹⋀(s::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state) (s'::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state) (y::'a) (x2::('b, 'c, 'a) object) (x2a::('b, 'c, 'a) object) x2b::'a. ⟦atS gc mark_loop_mo_locs s' ⟶ (∀x::'a. (∃y::('b, 'c, 'a) object. sys_heap s↓ x = Some y) ∨ ¬ (y reaches x) s↓); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s↓ y = Some x2a; obj_mark x2a = sys_fM s'↓; at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}; AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x::'a. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x::'a. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs::('b, 'c, 'a) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs::('b, 'c, 'a) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); at gc mark_loop_mark_field_done s'; gc_ref s'↓ = Some y; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s'↓ (gc_tmp_ref s'↓) = Some x2; obj_fields x2 (gc_field s'↓) = Some x2b; sys_heap s↓ x2b = None; atS gc obj_fields_marked_good_ref_locs s' ⟶ y = x2b⟧ ⟹ (∃ya::('b, 'c, 'a) object. sys_heap s'↓ y = Some ya) ∧ (∀x2::('b, 'c, 'a) object. sys_heap s'↓ y = Some x2 ⟶ obj_mark x2 = sys_fM s'↓)› and 2 goals remain*) apply (metis (no_types, opaque_lifting) map_option_eq_Some (*‹(map_option (?f::?'b::type ⇒ ?'a::type) (?xo::?'b::type option) = Some (?y::?'a::type)) = (∃z::?'b::type. ?xo = Some z ∧ ?f z = ?y)›*) option.inject (*‹(Some (?x2.0::?'a::type) = Some (?y2.0::?'a::type)) = (?x2.0 = ?y2.0)›*) option.simps( (*‹map_option (?f::?'a::type ⇒ ?'b::type) (Some (?x2.0::?'a::type)) = Some (?f ?x2.0)›*) 9)) (*top goal: ‹⋀s s' y x2 x2a x2b x2c. ⟦atS gc mark_loop_mo_locs s' ⟶ (∀x. (∃y. sys_heap s↓ x = Some y) ∨ ¬ (y reaches x) s↓); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s↓ y = Some x2a; obj_mark x2a = sys_fM s'↓; at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}; AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); at gc mark_loop_mark_field_done s'; gc_ref s'↓ = Some y; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s'↓ (gc_tmp_ref s'↓) = Some x2; obj_fields x2 (gc_field s'↓) = Some x2b; sys_heap s↓ x2b = Some x2c; atS gc obj_fields_marked_good_ref_locs s' ⟶ y = x2b ∨ obj_mark x2c = sys_fM s'↓⟧ ⟹ (∃ya. sys_heap s'↓ y = Some ya) ∧ (∀x2. sys_heap s'↓ y = Some x2 ⟶ obj_mark x2 = sys_fM s'↓)› and 1 goal remains*) apply (intro conjI (*‹⟦?P::bool; ?Q::bool⟧ ⟹ ?P ∧ ?Q›*) impI (*‹(?P::bool ⟹ ?Q::bool) ⟹ ?P ⟶ ?Q›*); clarsimp) (*goal: ‹⋀s s'. ⟦AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); (atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s'↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓) ∧ (atS gc obj_fields_marked_good_ref_locs s' ⟶ (case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some r' ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s'↓ r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓))) ∧ (atS gc mark_loop_mo_locs s' ⟶ (∀x. (∃y. gc_ref s'↓ = Some y) ∧ (the (gc_ref s'↓) reaches x) s'↓ ⟶ (case sys_heap s'↓ x of None ⇒ False | Some obj ⇒ True))) ∧ (at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓) ∧ (at gc mark_loop_mark_field_done s' ⟶ (∃y. gc_ref s'↓ = Some y) ⟶ (case sys_heap s'↓ (the (gc_ref s'↓)) of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓)) ∧ (at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}) ∧ (atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {})⟧ ⟹ (atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓) ∧ (atS gc obj_fields_marked_good_ref_locs s' ⟶ (case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some r' ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s↓ r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓))) ∧ (atS gc mark_loop_mo_locs s' ⟶ (∀x. (∃y. gc_ref s'↓ = Some y) ∧ (the (gc_ref s'↓) reaches x) s↓ ⟶ (case sys_heap s↓ x of None ⇒ False | Some obj ⇒ True))) ∧ (at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓) ∧ (at gc mark_loop_mark_field_done s' ⟶ (∃y. gc_ref s'↓ = Some y) ⟶ (case sys_heap s↓ (the (gc_ref s'↓)) of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓)) ∧ (at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}) ∧ (atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {})›*) apply (subst eq_impD[OF obj_fields_marked_eq_imp] (*‹∀x. (gc_field_set ?s, gc_tmp_ref ?s, map_option obj_fields (sys_heap ?s x), map_option obj_mark (sys_heap ?s x), sys_fM ?s, filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc ?s)) = (gc_field_set ?s', gc_tmp_ref ?s', map_option obj_fields (sys_heap ?s' x), map_option obj_mark (sys_heap ?s' x), sys_fM ?s', filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc ?s')) ⟹ obj_fields_marked ?s = obj_fields_marked ?s'›*); force) (*top goal: ‹⋀s s'. ⟦AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); atS gc obj_fields_marked_locs s'; obj_fields_marked s'↓; gc_tmp_ref s'↓ ∈ gc_W s'↓; atS gc obj_fields_marked_good_ref_locs s' ⟶ (case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some r' ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s'↓ r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓)); atS gc mark_loop_mo_locs s' ⟶ (∀x. (∃y. gc_ref s'↓ = Some y) ∧ (the (gc_ref s'↓) reaches x) s'↓ ⟶ (case sys_heap s'↓ x of None ⇒ False | Some obj ⇒ True)); at gc mark_loop_mark_field_done s' ⟶ (∃y. gc_ref s'↓ = Some y) ⟶ (case sys_heap s'↓ (the (gc_ref s'↓)) of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓); at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}⟧ ⟹ obj_fields_marked s↓› and 3 goals remain*) apply (clarsimp split: option.split_asm (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) (*top goal: ‹⋀s s'. ⟦AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); atS gc obj_fields_marked_good_ref_locs s'; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s'↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some r' ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s'↓ r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓); atS gc mark_loop_mo_locs s' ⟶ (∀x. (∃y. gc_ref s'↓ = Some y) ∧ (the (gc_ref s'↓) reaches x) s'↓ ⟶ (case sys_heap s'↓ x of None ⇒ False | Some obj ⇒ True)); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; at gc mark_loop_mark_field_done s' ⟶ (∃y. gc_ref s'↓ = Some y) ⟶ (case sys_heap s'↓ (the (gc_ref s'↓)) of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓); at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}⟧ ⟹ case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some r' ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s↓ r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓)› and 2 goals remain*) apply (metis (no_types, lifting) None_eq_map_option_iff (*‹(None = map_option (?f::?'b ⇒ ?'a) (?x::?'b option)) = (?x = None)›*) option.simps( (*‹Some (?x2.0::?'a) ≠ None›*) 3)) (*top goal: ‹⋀s s' x2 x2a x2b. ⟦obj_mark x2b = sys_fM s'↓; atS gc mark_loop_mo_locs s' ⟶ (∀x. (∃y. sys_heap s'↓ x = Some y) ∨ gc_ref s'↓ = None ∨ ¬ (the (gc_ref s'↓) reaches x) s'↓); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s'↓ (the (gc_ref s'↓)) = None; at gc mark_loop_mark_field_done s' ⟶ gc_ref s'↓ = None; at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}; AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); atS gc obj_fields_marked_good_ref_locs s'; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s'↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s'↓ (gc_tmp_ref s'↓) = Some x2; obj_fields x2 (gc_field s'↓) = Some x2a; sys_heap s'↓ x2a = Some x2b; sys_heap s↓ x2a = None⟧ ⟹ gc_ref s'↓ = Some x2a› and 5 goals remain*) apply (metis (no_types, lifting) option.distinct( (*‹None ≠ Some ?x2.0›*) 1) option.map_sel (*‹?a ≠ None ⟹ the (map_option ?f ?a) = ?f (the ?a)›*) option.sel (*‹the (Some ?x2.0) = ?x2.0›*)) (*top goal: ‹⋀(s::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state) (s'::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state) (x2::('b, 'c, 'a) object) (x2a::'a) (x2b::('b, 'c, 'a) object) x2c::('b, 'c, 'a) object. ⟦obj_mark x2b = sys_fM s'↓; atS gc mark_loop_mo_locs s' ⟶ (∀x::'a. (∃y::('b, 'c, 'a) object. sys_heap s'↓ x = Some y) ∨ gc_ref s'↓ = None ∨ ¬ (the (gc_ref s'↓) reaches x) s'↓); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s'↓ (the (gc_ref s'↓)) = None; at gc mark_loop_mark_field_done s' ⟶ gc_ref s'↓ = None; at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}; AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x::'a. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x::'a. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs::('b, 'c, 'a) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs::('b, 'c, 'a) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); atS gc obj_fields_marked_good_ref_locs s'; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s'↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s'↓ (gc_tmp_ref s'↓) = Some x2; obj_fields x2 (gc_field s'↓) = Some x2a; sys_heap s'↓ x2a = Some x2b; sys_heap s↓ x2a = Some x2c; obj_mark x2c = (¬ sys_fM s'↓)⟧ ⟹ gc_ref s'↓ = Some x2a› and 4 goals remain*) apply (metis (no_types, lifting) None_eq_map_option_iff (*‹(None = map_option ?f ?x) = (?x = None)›*) option.simps( (*‹Some ?x2.0 ≠ None›*) 3)) (*top goal: ‹⋀s s' x2 x2a x2b x2c. ⟦obj_mark x2c = sys_fM s'↓; atS gc mark_loop_mo_locs s' ⟶ (∀x. (∃y. sys_heap s'↓ x = Some y) ∨ gc_ref s'↓ = None ∨ ¬ (the (gc_ref s'↓) reaches x) s'↓); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s'↓ (the (gc_ref s'↓)) = Some x2a; at gc mark_loop_mark_field_done s' ⟶ (∃y. gc_ref s'↓ = Some y) ⟶ obj_mark x2a = sys_fM s'↓; at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}; AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); atS gc obj_fields_marked_good_ref_locs s'; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s'↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s'↓ (gc_tmp_ref s'↓) = Some x2; obj_fields x2 (gc_field s'↓) = Some x2b; sys_heap s'↓ x2b = Some x2c; sys_heap s↓ x2b = None⟧ ⟹ gc_ref s'↓ = Some x2b› and 3 goals remain*) apply (metis (no_types, lifting) option.distinct( (*‹None ≠ Some (?x2.0::?'a)›*) 1) option.map_sel (*‹(?a::?'a option) ≠ None ⟹ the (map_option (?f::?'a ⇒ ?'b) ?a) = ?f (the ?a)›*) option.sel (*‹the (Some (?x2.0::?'a)) = ?x2.0›*)) (*top goal: ‹⋀(s::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state) (s'::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state) (x2::('b, 'c, 'a) object) (x2a::('b, 'c, 'a) object) (x2b::'a) (x2c::('b, 'c, 'a) object) x2d::('b, 'c, 'a) object. ⟦obj_mark x2c = sys_fM s'↓; atS gc mark_loop_mo_locs s' ⟶ (∀x::'a. (∃y::('b, 'c, 'a) object. sys_heap s'↓ x = Some y) ∨ gc_ref s'↓ = None ∨ ¬ (the (gc_ref s'↓) reaches x) s'↓); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s'↓ (the (gc_ref s'↓)) = Some x2a; at gc mark_loop_mark_field_done s' ⟶ (∃y::'a. gc_ref s'↓ = Some y) ⟶ obj_mark x2a = sys_fM s'↓; at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}; AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x::'a. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x::'a. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs::('b, 'c, 'a) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs::('b, 'c, 'a) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); atS gc obj_fields_marked_good_ref_locs s'; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s'↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s'↓ (gc_tmp_ref s'↓) = Some x2; obj_fields x2 (gc_field s'↓) = Some x2b; sys_heap s'↓ x2b = Some x2c; sys_heap s↓ x2b = Some x2d; obj_mark x2d = (¬ sys_fM s'↓)⟧ ⟹ gc_ref s'↓ = Some x2b› and 2 goals remain*) apply (subst (asm) (2) eq_impD[OF reaches_eq_imp] (*‹∀x. ⋃ (ran ` obj_fields ` set_option (sys_heap ?s x)) = ⋃ (ran ` obj_fields ` set_option (sys_heap ?s' x)) ⟹ (?x1 reaches ?y1) ?s = (?x1 reaches ?y1) ?s'›*)) (*top goal: ‹⋀s s' x y. ⟦AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); atS gc mark_loop_mo_locs s'; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s'↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; atS gc obj_fields_marked_good_ref_locs s' ⟶ (case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some r' ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s'↓ r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓)); ∀x. (y reaches x) s'↓ ⟶ (case sys_heap s'↓ x of None ⇒ False | Some obj ⇒ True); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; at gc mark_loop_mark_field_done s' ⟶ (case sys_heap s'↓ y of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓); at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}; (y reaches x) s↓; gc_ref s'↓ = Some y⟧ ⟹ case sys_heap s↓ x of None ⇒ False | Some obj ⇒ True› and 1 goal remains*) prefer 2 (*top goal: ‹⋀(s::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state) (s'::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state) (x::'a) y::'a. ⟦AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x::'a. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x::'a. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs::('b, 'c, 'a) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs::('b, 'c, 'a) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); atS gc mark_loop_mo_locs s'; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s'↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; atS gc obj_fields_marked_good_ref_locs s' ⟶ (case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some (x2::('b, 'c, 'a) object) ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some (r'::'a) ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s'↓ r' of None ⇒ False | Some (obj::('b, 'c, 'a) object) ⇒ obj_mark obj = sys_fM s'↓)); ∀x::'a. (y reaches x) s'↓ ⟶ (case sys_heap s'↓ x of None ⇒ False | Some (obj::('b, 'c, 'a) object) ⇒ True); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; at gc mark_loop_mark_field_done s' ⟶ (case sys_heap s'↓ y of None ⇒ False | Some (obj::('b, 'c, 'a) object) ⇒ obj_mark obj = sys_fM s'↓); at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}; (y reaches x) ((?s'538::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state ⇒ (('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state ⇒ 'a ⇒ 'a ⇒ 'd process_name ⇒ ('b, 'd, 'c, 'a) Model.local_state) s s' x y); gc_ref s'↓ = Some y⟧ ⟹ case sys_heap s↓ x of None ⇒ False | Some (obj::('b, 'c, 'a) object) ⇒ True› and 2 goals remain*) apply (drule spec (*‹∀x. ?P x ⟹ ?P ?x›*), drule mp (*‹⟦?P ⟶ ?Q; ?P⟧ ⟹ ?Q›*), assumption) (*top goal: ‹⋀(s::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state) (s'::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state) (x::'a) y::'a. ⟦AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x::'a. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x::'a. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs::('b, 'c, 'a) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs::('b, 'c, 'a) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); atS gc mark_loop_mo_locs s'; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s'↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; atS gc obj_fields_marked_good_ref_locs s' ⟶ (case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some (x2::('b, 'c, 'a) object) ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some (r'::'a) ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s'↓ r' of None ⇒ False | Some (obj::('b, 'c, 'a) object) ⇒ obj_mark obj = sys_fM s'↓)); ∀x::'a. (y reaches x) s'↓ ⟶ (case sys_heap s'↓ x of None ⇒ False | Some (obj::('b, 'c, 'a) object) ⇒ True); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; at gc mark_loop_mark_field_done s' ⟶ (case sys_heap s'↓ y of None ⇒ False | Some (obj::('b, 'c, 'a) object) ⇒ obj_mark obj = sys_fM s'↓); at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}; (y reaches x) ((?s'538::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state ⇒ (('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state ⇒ 'a ⇒ 'a ⇒ 'd process_name ⇒ ('b, 'd, 'c, 'a) Model.local_state) s s' x y); gc_ref s'↓ = Some y⟧ ⟹ case sys_heap s↓ x of None ⇒ False | Some (obj::('b, 'c, 'a) object) ⇒ True› and 2 goals remain*) apply (metis (no_types, lifting) None_eq_map_option_iff (*‹(None = map_option ?f ?x) = (?x = None)›*) option.case_eq_if (*‹(case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (if ?option = None then ?f1.0 else ?f2.0 (the ?option))›*)) (*top goal: ‹⋀s s' x y. ⟦AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); atS gc mark_loop_mo_locs s'; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s'↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; atS gc obj_fields_marked_good_ref_locs s' ⟶ (case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some r' ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s'↓ r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓)); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; at gc mark_loop_mark_field_done s' ⟶ (case sys_heap s'↓ y of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓); at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}; (y reaches x) s'↓; gc_ref s'↓ = Some y; case sys_heap s'↓ x of None ⇒ False | Some obj ⇒ True⟧ ⟹ case sys_heap s↓ x of None ⇒ False | Some obj ⇒ True› and 2 goals remain*) apply (metis option.set_map (*‹set_option (map_option ?f ?v) = ?f ` set_option ?v›*)) (*top goal: ‹⋀s s' x y. ⟦gc_ref s'↓ = Some y; AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); atS gc mark_loop_mo_locs s'; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s'↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; atS gc obj_fields_marked_good_ref_locs s' ⟶ (case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some r' ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s'↓ r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓)); ∀x. (y reaches x) s'↓ ⟶ (case sys_heap s'↓ x of None ⇒ False | Some obj ⇒ True); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; at gc mark_loop_mark_field_done s' ⟶ (case sys_heap s'↓ y of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓); at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}⟧ ⟹ ∀x. ⋃ (ran ` obj_fields ` set_option (sys_heap s↓ x)) = ⋃ (ran ` obj_fields ` set_option (sys_heap s'↓ x))› and 1 goal remains*) apply (clarsimp split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) (*goal: ‹⋀s s' y. ⟦AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); at gc mark_loop_mark_field_done s'; gc_ref s'↓ = Some y; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s'↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; atS gc obj_fields_marked_good_ref_locs s' ⟶ (case sys_heap s'↓ (gc_tmp_ref s'↓) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (gc_field s'↓) of None ⇒ True | Some r' ⇒ gc_ref s'↓ = Some r' ∨ (case sys_heap s'↓ r' of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓)); atS gc mark_loop_mo_locs s' ⟶ (∀x. (y reaches x) s'↓ ⟶ (case sys_heap s'↓ x of None ⇒ False | Some obj ⇒ True)); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; case sys_heap s'↓ y of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓; at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}⟧ ⟹ case sys_heap s↓ y of None ⇒ False | Some obj ⇒ obj_mark obj = sys_fM s'↓›*) apply (metis (no_types, opaque_lifting) atS_simps( (*‹atS ?p {?l} ?s = at ?p ?l ?s›*) 2) atS_un (*‹atS ?p (?l ∪ ?l') ?s = (atS ?p ?l ?s ∨ atS ?p ?l' ?s)›*) obj_fields_marked_good_ref_locs_def (*‹obj_fields_marked_good_ref_locs = mark_loop_mo_locs ∪ {mark_loop_mark_field_done}›*)) (*top goal: ‹⋀s s' y x2. ⟦at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}; AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); at gc mark_loop_mark_field_done s'; gc_ref s'↓ = Some y; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s'↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s'↓ (gc_tmp_ref s'↓) = None; ¬ atS gc obj_fields_marked_good_ref_locs s'; atS gc mark_loop_mo_locs s' ⟶ (∀x. (∃y. sys_heap s'↓ x = Some y) ∨ ¬ (y reaches x) s'↓); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s'↓ y = Some x2; obj_mark x2 = sys_fM s'↓⟧ ⟹ (∃ya. sys_heap s↓ y = Some ya) ∧ (∀x2. sys_heap s↓ y = Some x2 ⟶ obj_mark x2 = sys_fM s'↓)› and 3 goals remain*) apply (metis (no_types, opaque_lifting) map_option_eq_Some (*‹(map_option ?f ?xo = Some ?y) = (∃z. ?xo = Some z ∧ ?f z = ?y)›*) option.inject (*‹(Some ?x2.0 = Some ?y2.0) = (?x2.0 = ?y2.0)›*) option.simps( (*‹map_option ?f (Some ?x2.0) = Some (?f ?x2.0)›*) 9)) (*top goal: ‹⋀s s' y x2 x2a. ⟦atS gc mark_loop_mo_locs s' ⟶ (∀x. (∃y. sys_heap s'↓ x = Some y) ∨ ¬ (y reaches x) s'↓); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s'↓ y = Some x2a; obj_mark x2a = sys_fM s'↓; at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}; AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); at gc mark_loop_mark_field_done s'; gc_ref s'↓ = Some y; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s'↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s'↓ (gc_tmp_ref s'↓) = Some x2; obj_fields x2 (gc_field s'↓) = None⟧ ⟹ (∃ya. sys_heap s↓ y = Some ya) ∧ (∀x2. sys_heap s↓ y = Some x2 ⟶ obj_mark x2 = sys_fM s'↓)› and 2 goals remain*) apply (metis (no_types, opaque_lifting) map_option_eq_Some (*‹(map_option ?f ?xo = Some ?y) = (∃z. ?xo = Some z ∧ ?f z = ?y)›*) option.inject (*‹(Some ?x2.0 = Some ?y2.0) = (?x2.0 = ?y2.0)›*) option.simps( (*‹map_option ?f (Some ?x2.0) = Some (?f ?x2.0)›*) 9)) (*top goal: ‹⋀s s' y x2 x2a x2b. ⟦atS gc mark_loop_mo_locs s' ⟶ (∀x. (∃y. sys_heap s'↓ x = Some y) ∨ ¬ (y reaches x) s'↓); at gc mark_loop_fields s' ⟶ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s'↓ y = Some x2a; obj_mark x2a = sys_fM s'↓; at gc mark_loop_blacken s' ⟶ gc_field_set s'↓ = {}; atS gc ghost_honorary_grey_empty_locs s' ⟶ gc_ghost_honorary_grey s'↓ = {}; AT s gc = AT s' gc; s↓ gc = s'↓ gc; ∀x. map_option obj_fields (sys_heap s↓ x) = map_option obj_fields (sys_heap s'↓ x); ∀x. map_option obj_mark (sys_heap s↓ x) = map_option obj_mark (sys_heap s'↓ x); sys_fM s↓ = sys_fM s'↓; sys_W s↓ = sys_W s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s'↓); at gc mark_loop_mark_field_done s'; gc_ref s'↓ = Some y; atS gc obj_fields_marked_locs s' ⟶ obj_fields_marked s'↓ ∧ gc_tmp_ref s'↓ ∈ gc_W s'↓; sys_heap s'↓ (gc_tmp_ref s'↓) = Some x2; obj_fields x2 (gc_field s'↓) = Some x2b; sys_heap s'↓ x2b = None; atS gc obj_fields_marked_good_ref_locs s' ⟶ y = x2b⟧ ⟹ (∃ya. sys_heap s↓ y = Some ya) ∧ (∀x2. sys_heap s↓ y = Some x2 ⟶ obj_mark x2 = sys_fM s'↓)› and 1 goal remains*) by (metis (no_types, opaque_lifting) map_option_eq_Some (*‹(map_option ?f ?xo = Some ?y) = (∃z. ?xo = Some z ∧ ?f z = ?y)›*) option.inject (*‹(Some ?x2.0 = Some ?y2.0) = (?x2.0 = ?y2.0)›*) option.simps( (*‹map_option ?f (Some ?x2.0) = Some (?f ?x2.0)›*) 9)) lemma obj_fields_marked_mark_field_done[iff]: "⟦ obj_at_field_on_heap (λr. marked r s) (gc_tmp_ref s) (gc_field s) s; obj_fields_marked s ⟧ ⟹ obj_fields_marked (s(gc := (s gc)⦇field_set := gc_field_set s - {gc_field s}⦈))" unfolding obj_fields_marked_def obj_at_field_on_heap_def (*goal: ‹⟦case map_option obj_fields (sys_heap s (gc_tmp_ref s)) of None ⇒ False | Some fs ⇒ case fs (gc_field s) of None ⇒ True | Some r' ⇒ marked r' s; ∀x. x ∈ (- gc_field_set) s ⟶ (case map_option obj_fields (sys_heap s (gc_tmp_ref s)) of None ⇒ False | Some fs ⇒ case fs x of None ⇒ True | Some r' ⇒ marked r' s)⟧ ⟹ ∀x. x ∈ (- gc_field_set) (s(gc := s gc⦇field_set := gc_field_set s - {gc_field s}⦈)) ⟶ (case map_option obj_fields (sys_heap (s(gc := s gc⦇field_set := gc_field_set s - {gc_field s}⦈)) (gc_tmp_ref (s(gc := s gc⦇field_set := gc_field_set s - {gc_field s}⦈)))) of None ⇒ False | Some fs ⇒ case fs x of None ⇒ True | Some r' ⇒ marked r' (s(gc := s gc⦇field_set := gc_field_set s - {gc_field s}⦈)))›*) by (fastforce simp: fun_upd_apply (*‹(?f(?x := ?y)) ?z = (if ?z = ?x then ?y else ?f ?z)›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) obj_at_splits (*‹?Q (obj_at ?P ?r ?s) = ((sys_heap ?s ?r = None ⟶ ?Q False) ∧ (∀obj. sys_heap ?s ?r = Some obj ⟶ ?Q (?P obj)))› ‹?Q (obj_at ?P ?r ?s) = (¬ (sys_heap ?s ?r = None ∧ ¬ ?Q False ∨ (∃obj. sys_heap ?s ?r = Some obj ∧ ¬ ?Q (?P obj))))›*)) end lemmas gc_obj_fields_marked_inv_fun_upd[simp] = eq_imp_fun_upd[OF gc.obj_fields_marked_eq_imp, simplified eq_imp_simps, rule_format] lemmas gc_obj_fields_marked_invL_niE[nie] = iffD1[OF gc.obj_fields_marked_invL_eq_imp[simplified eq_imp_simps, rule_format, unfolded conj_explode], rotated -1] subsection‹ mark object › context mark_object begin lemma mark_object_invL_eq_imp: "eq_imp (λ(_::unit) s. (AT s p, s↓ p, sys_heap s↓, sys_fM s↓, sys_mem_store_buffers p s↓)) mark_object_invL" unfolding eq_imp_def (*goal: ‹∀(s::(('field, 'payload, 'ref) response, char list, 'mut process_name, 'mut process_name × ('field, 'mut, 'payload, 'ref) request_op, ('field, 'mut, 'payload, 'ref) Model.local_state) system_state) s'::(('field, 'payload, 'ref) response, char list, 'mut process_name, 'mut process_name × ('field, 'mut, 'payload, 'ref) request_op, ('field, 'mut, 'payload, 'ref) Model.local_state) system_state. (∀x::unit. (AT s (p::'mut::type process_name), s↓ p, sys_heap s↓, sys_fM s↓, sys_mem_store_buffers p s↓) = (AT s' p, s'↓ p, sys_heap s'↓, sys_fM s'↓, sys_mem_store_buffers p s'↓)) ⟶ mark_object_invL s = mark_object_invL s'›*) apply clarsimp (*goal: ‹∀s s'. (∀x. (AT s p, s↓ p, sys_heap s↓, sys_fM s↓, sys_mem_store_buffers p s↓) = (AT s' p, s'↓ p, sys_heap s'↓, sys_fM s'↓, sys_mem_store_buffers p s'↓)) ⟶ mark_object_invL s = mark_object_invL s'›*) apply (rename_tac s s') (*goal: ‹⋀s s'. ⟦AT s p = AT s' p; s↓ p = s'↓ p; sys_heap s↓ = sys_heap s'↓; sys_fM s↓ = sys_fM s'↓; sys_mem_store_buffers p s↓ = sys_mem_store_buffers p s'↓⟧ ⟹ mark_object_invL s = mark_object_invL s'›*) apply (cut_tac s="s↓" and s'="s'↓" in eq_impD[OF p_ph_enabled_eq_imp] (*‹∀x. ?s p = ?s' p ⟹ p_ph_enabled ?s = p_ph_enabled ?s'›*)) (*goals: 1. ‹⋀s s'. ⟦AT s p = AT s' p; s↓ p = s'↓ p; sys_heap s↓ = sys_heap s'↓; sys_fM s↓ = sys_fM s'↓; sys_mem_store_buffers p s↓ = sys_mem_store_buffers p s'↓⟧ ⟹ ∀x. s↓ p = s'↓ p› 2. ‹⋀s s'. ⟦AT s p = AT s' p; s↓ p = s'↓ p; sys_heap s↓ = sys_heap s'↓; sys_fM s↓ = sys_fM s'↓; sys_mem_store_buffers p s↓ = sys_mem_store_buffers p s'↓; p_ph_enabled s↓ = p_ph_enabled s'↓⟧ ⟹ mark_object_invL s = mark_object_invL s'› discuss goal 1*) apply simp (*discuss goal 2*) apply (clarsimp simp: mark_object_invL_def (*‹mark_object_invL = (λs. (at p (l @ ''_mo_null'') s ⟶ True) ∧ (at p (l @ ''_mo_mark'') s ⟶ ref (s↓ p) ≠ None ∧ obj_at (λs. True) ((the ∘ (λs. ref (s p))) s↓) s↓) ∧ (at p (l @ ''_mo_fM'') s ⟶ (ref (s↓ p) ≠ None ∧ obj_at (λs. True) ((the ∘ (λs. ref (s p))) s↓) s↓) ∧ (p_ph_enabled s↓ ⟶ mark (s↓ p) ≠ None ∧ (obj_at (λobj. Some (obj_mark obj) = mark (s↓ p)) ((the ∘ (λs. ref (s p))) s↓) s↓ ∨ marked ((the ∘ (λs. ref (s p))) s↓) s↓))) ∧ (at p (l @ ''_mo_mtest'') s ⟶ (ref (s↓ p) ≠ None ∧ obj_at (λs. True) ((the ∘ (λs. ref (s p))) s↓) s↓) ∧ (p_ph_enabled s↓ ⟶ (mark (s↓ p) ≠ None ∧ (obj_at (λobj. Some (obj_mark obj) = mark (s↓ p)) ((the ∘ (λs. ref (s p))) s↓) s↓ ∨ marked ((the ∘ (λs. ref (s p))) s↓) s↓)) ∧ fM (s↓ p) = sys_fM s↓)) ∧ (at p (l @ ''_mo_phase'') s ⟶ (ref (s↓ p) ≠ None ∧ obj_at (λs. True) ((the ∘ (λs. ref (s p))) s↓) s↓) ∧ mark (s↓ p) ≠ (Some ∘ (λs. fM (s p))) s↓ ∧ (p_ph_enabled s↓ ⟶ (mark (s↓ p) ≠ None ∧ (obj_at (λobj. Some (obj_mark obj) = mark (s↓ p)) ((the ∘ (λs. ref (s p))) s↓) s↓ ∨ marked ((the ∘ (λs. ref (s p))) s↓) s↓)) ∧ fM (s↓ p) = sys_fM s↓)) ∧ (at p (l @ ''_mo_ptest'') s ⟶ (ref (s↓ p) ≠ None ∧ obj_at (λs. True) ((the ∘ (λs. ref (s p))) s↓) s↓) ∧ mark (s↓ p) ≠ (Some ∘ (λs. fM (s p))) s↓ ∧ (p_ph_enabled s↓ ⟶ (mark (s↓ p) ≠ None ∧ (obj_at (λobj. Some (obj_mark obj) = mark (s↓ p)) ((the ∘ (λs. ref (s p))) s↓) s↓ ∨ marked ((the ∘ (λs. ref (s p))) s↓) s↓)) ∧ fM (s↓ p) = sys_fM s↓)) ∧ (at p (l @ ''_mo_co_lock'') s ⟶ (ref (s↓ p) ≠ None ∧ obj_at (λs. True) ((the ∘ (λs. ref (s p))) s↓) s↓) ∧ (mark (s↓ p) ≠ None ∧ (obj_at (λobj. Some (obj_mark obj) = mark (s↓ p)) ((the ∘ (λs. ref (s p))) s↓) s↓ ∨ marked ((the ∘ (λs. ref (s p))) s↓) s↓)) ∧ fM (s↓ p) = sys_fM s↓ ∧ mark (s↓ p) ≠ (Some ∘ (λs. fM (s p))) s↓ ∧ filter is_mw_Mark (sys_mem_store_buffers p s↓) = []) ∧ (at p (l @ ''_mo_co_cmark'') s ⟶ (ref (s↓ p) ≠ None ∧ obj_at (λs. True) ((the ∘ (λs. ref (s p))) s↓) s↓) ∧ (mark (s↓ p) ≠ None ∧ (obj_at (λobj. Some (obj_mark obj) = mark (s↓ p)) ((the ∘ (λs. ref (s p))) s↓) s↓ ∨ marked ((the ∘ (λs. ref (s p))) s↓) s↓)) ∧ fM (s↓ p) = sys_fM s↓ ∧ mark (s↓ p) ≠ (Some ∘ (λs. fM (s p))) s↓ ∧ filter is_mw_Mark (sys_mem_store_buffers p s↓) = []) ∧ (at p (l @ ''_mo_co_ctest'') s ⟶ (ref (s↓ p) ≠ None ∧ obj_at (λs. True) ((the ∘ (λs. ref (s p))) s↓) s↓) ∧ (mark (s↓ p) ≠ None ∧ (obj_at (λobj. Some (obj_mark obj) = mark (s↓ p)) ((the ∘ (λs. ref (s p))) s↓) s↓ ∨ marked ((the ∘ (λs. ref (s p))) s↓) s↓)) ∧ fM (s↓ p) = sys_fM s↓ ∧ mark (s↓ p) ≠ (Some ∘ (λs. fM (s p))) s↓ ∧ obj_at (λobj. Some (obj_mark obj) = cas_mark (s↓ p)) ((the ∘ (λs. ref (s p))) s↓) s↓ ∧ filter is_mw_Mark (sys_mem_store_buffers p s↓) = []) ∧ (at p (l @ ''_mo_co_mark'') s ⟶ cas_mark (s↓ p) = mark (s↓ p) ∧ (ref (s↓ p) ≠ None ∧ obj_at (λs. True) ((the ∘ (λs. ref (s p))) s↓) s↓) ∧ fM (s↓ p) = sys_fM s↓ ∧ white ((the ∘ (λs. ref (s p))) s↓) s↓ ∧ filter is_mw_Mark (sys_mem_store_buffers p s↓) = []) ∧ (at p (l @ ''_mo_co_unlock'') s ⟶ (if cas_mark (s↓ p) = mark (s↓ p) then ghost_honorary_grey (s↓ p) = {(the ∘ (λs. ref (s p))) s↓} else ghost_honorary_grey (s↓ p) = {}) ∧ (ref (s↓ p) ≠ None ∧ obj_at (λs. True) ((the ∘ (λs. ref (s p))) s↓) s↓) ∧ fM (s↓ p) = sys_fM s↓ ∧ (cas_mark (s↓ p) ≠ mark (s↓ p) ∨ filter is_mw_Mark (sys_mem_store_buffers p s↓) = [] ⟶ marked ((the ∘ (λs. ref (s p))) s↓) s↓) ∧ filter is_mw_Mark (sys_mem_store_buffers p s↓) ∈ {[], [mw_Mark ((the ∘ (λs. ref (s p))) s↓) (fM (s↓ p))]}) ∧ (at p (l @ ''_mo_co_won'') s ⟶ (if cas_mark (s↓ p) = mark (s↓ p) then ghost_honorary_grey (s↓ p) = {(the ∘ (λs. ref (s p))) s↓} else ghost_honorary_grey (s↓ p) = {}) ∧ (ref (s↓ p) ≠ None ∧ obj_at (λs. True) ((the ∘ (λs. ref (s p))) s↓) s↓) ∧ fM (s↓ p) = sys_fM s↓ ∧ marked ((the ∘ (λs. ref (s p))) s↓) s↓ ∧ filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers p s↓) = []) ∧ (at p (l @ ''_mo_co_W'') s ⟶ ghost_honorary_grey (s↓ p) = {(the ∘ (λs. ref (s p))) s↓} ∧ (ref (s↓ p) ≠ None ∧ obj_at (λs. True) ((the ∘ (λs. ref (s p))) s↓) s↓) ∧ fM (s↓ p) = sys_fM s↓ ∧ marked ((the ∘ (λs. ref (s p))) s↓) s↓ ∧ filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers p s↓) = []))›*) obj_at_def (*‹obj_at ?P ?r ≡ λs. case sys_heap s ?r of None ⇒ False | Some obj ⇒ ?P obj›*) white_def (*‹white ?r ?s ≡ obj_at (λobj. obj_mark obj ≠ sys_fM ?s) ?r ?s›*) cong: option.case_cong (*‹⟦?option = ?option'; ?option' = None ⟹ ?f1.0 = ?g1.0; ⋀x2. ?option' = Some x2 ⟹ ?f2.0 x2 = ?g2.0 x2⟧ ⟹ (case ?option of None ⇒ ?f1.0 | Some x2 ⇒ ?f2.0 x2) = (case ?option' of None ⇒ ?g1.0 | Some x2 ⇒ ?g2.0 x2)›*)) (*proven 2 subgoals*) . lemmas mark_object_invL_niE[nie] = iffD1[OF mark_object_invL_eq_imp[simplified eq_imp_simps, rule_format, unfolded conj_explode], rotated -1] end lemma mut_m_mark_object_invL_eq_imp: "eq_imp (λr s. (AT s (mutator m), s↓ (mutator m), sys_heap s↓ r, sys_fM s↓, sys_phase s↓, tso_pending_mutate (mutator m) s↓)) (mut_m.mark_object_invL m)" apply (clarsimp simp: eq_imp_def (*‹eq_imp ?f ?g ≡ ∀s s'. (∀x. ?f x s = ?f x s') ⟶ ?g s = ?g s'›*) mut_m.mark_object_invL_def (*‹mut_m.mark_object_invL ?m = (λs. (atS (mutator ?m) mut_m.hs_get_roots_loop_locs s ⟶ refs (s↓ (mutator ?m)) ⊆ roots (s↓ (mutator ?m)) ∧ (∀x. x ∈ roots (s↓ (mutator ?m)) - refs (s↓ (mutator ?m)) ⟶ marked x s↓)) ∧ (atS (mutator ?m) mut_m.hs_get_roots_loop_mo_locs s ⟶ ref (s↓ (mutator ?m)) ≠ None ∧ (the ∘ (λs. ref (s (mutator ?m)))) s↓ ∈ roots (s↓ (mutator ?m))) ∧ (at (mutator ?m) mut_m.hs_get_roots_loop_done s ⟶ marked ((the ∘ (λs. ref (s (mutator ?m)))) s↓) s↓) ∧ (at (mutator ?m) mut_m.hs_get_roots_loop_mo_ptest s ⟶ phase (s↓ (mutator ?m)) ≠ ph_Idle) ∧ (at (mutator ?m) mut_m.hs_get_roots_done s ⟶ (∀x. x ∈ roots (s↓ (mutator ?m)) ⟶ marked x s↓)) ∧ (atS (mutator ?m) mut_m.mo_valid_ref_locs s ⟶ (new_ref (s↓ (mutator ?m)) ≠ None ⟶ (the ∘ (λs. new_ref (s (mutator ?m)))) s↓ ∈ roots (s↓ (mutator ?m))) ∧ tmp_ref (s↓ (mutator ?m)) ∈ roots (s↓ (mutator ?m))) ∧ (at (mutator ?m) mut_m.store_del_mo_null s ⟶ ref (s↓ (mutator ?m)) ≠ None ⟶ (the ∘ (λs. ref (s (mutator ?m)))) s↓ ∈ ghost_honorary_root (s↓ (mutator ?m))) ∧ (atS (mutator ?m) mut_m.ghost_honorary_root_nonempty_locs s ⟶ (the ∘ (λs. ref (s (mutator ?m)))) s↓ ∈ ghost_honorary_root (s↓ (mutator ?m))) ∧ (atS (mutator ?m) mut_m.not_idle_locs s ⟶ phase (s↓ (mutator ?m)) ≠ ph_Idle ⟶ ghost_hs_phase (s↓ (mutator ?m)) ≠ hp_Idle) ∧ (atS (mutator ?m) mut_m.hs_not_hp_Idle_locs s ⟶ ghost_hs_phase (s↓ (mutator ?m)) ≠ hp_Idle) ∧ (atS (mutator ?m) mut_m.mo_ptest_locs s ⟶ phase (s↓ (mutator ?m)) = ph_Idle ⟶ ghost_hs_phase (s↓ (mutator ?m)) ∈ {hp_Idle, hp_IdleInit} ∨ ghost_hs_phase (s↓ (mutator ?m)) = hp_IdleMarkSweep ∧ sys_phase s↓ = ph_Idle) ∧ (atS (mutator ?m) mut_m.ghost_honorary_grey_empty_locs s ⟶ ghost_honorary_grey (s↓ (mutator ?m)) = {}) ∧ (at (mutator ?m) mut_m.store_ins s ⟶ (ghost_hs_phase (s↓ (mutator ?m)) ∈ {hp_InitMark, hp_Mark} ∨ ghost_hs_phase (s↓ (mutator ?m)) = hp_IdleMarkSweep ∧ sys_phase s↓ ≠ ph_Idle) ∧ new_ref (s↓ (mutator ?m)) ≠ None ⟶ marked ((the ∘ (λs. new_ref (s (mutator ?m)))) s↓) s↓) ∧ (atS (mutator ?m) mut_m.ins_barrier_locs s ⟶ ((ghost_hs_phase (s↓ (mutator ?m)) = hp_Mark ∨ ghost_hs_phase (s↓ (mutator ?m)) = hp_IdleMarkSweep ∧ sys_phase s↓ ≠ ph_Idle) ∧ (∀opt_r'. mw_Mutate (tmp_ref (s↓ (mutator ?m))) (field (s↓ (mutator ?m))) opt_r' ∉ set (sys_mem_store_buffers (mutator ?m) s↓)) ⟶ obj_at_field_on_heap (λr'. marked r' s↓) (tmp_ref (s↓ (mutator ?m))) (field (s↓ (mutator ?m))) s↓) ∧ ref (s↓ (mutator ?m)) = new_ref (s↓ (mutator ?m))) ∧ (atS (mutator ?m) mut_m.del_barrier1_locs s ⟶ (ghost_hs_phase (s↓ (mutator ?m)) = hp_Mark ∨ ghost_hs_phase (s↓ (mutator ?m)) = hp_IdleMarkSweep ∧ sys_phase s↓ ≠ ph_Idle) ∧ (∀opt_r'. mw_Mutate (tmp_ref (s↓ (mutator ?m))) (field (s↓ (mutator ?m))) opt_r' ∉ set (sys_mem_store_buffers (mutator ?m) s↓)) ⟶ obj_at_field_on_heap (λr. ref (s↓ (mutator ?m)) = Some r ∨ marked r s↓) (tmp_ref (s↓ (mutator ?m))) (field (s↓ (mutator ?m))) s↓) ∧ (at (mutator ?m) mut_m.lop_store_ins s ⟶ (ghost_hs_phase (s↓ (mutator ?m)) = hp_Mark ∨ ghost_hs_phase (s↓ (mutator ?m)) = hp_IdleMarkSweep ∧ sys_phase s↓ ≠ ph_Idle) ∧ ref (s↓ (mutator ?m)) ≠ None ⟶ marked ((the ∘ (λs. ref (s (mutator ?m)))) s↓) s↓) ∧ (at (mutator ?m) mut_m.mut_load s ⟶ tmp_ref (s↓ (mutator ?m)) ∈ roots (s↓ (mutator ?m))) ∧ (atS (mutator ?m) mut_m.ghost_honorary_root_empty_locs s ⟶ ghost_honorary_root (s↓ (mutator ?m)) = {}))›*) fun_eq_iff[symmetric] (*‹(∀x. ?f x = ?g x) = (?f = ?g)›*) obj_at_field_on_heap_def (*‹obj_at_field_on_heap ?P ?r ?f ≡ λs. case map_option obj_fields (sys_heap s ?r) of None ⇒ False | Some fs ⇒ case fs ?f of None ⇒ True | Some r' ⇒ ?P r'›*) cong: option.case_cong (*‹⟦?option = ?option'; ?option' = None ⟹ ?f1.0 = ?g1.0; ⋀x2. ?option' = Some x2 ⟹ ?f2.0 x2 = ?g2.0 x2⟧ ⟹ (case ?option of None ⇒ ?f1.0 | Some x2 ⇒ ?f2.0 x2) = (case ?option' of None ⇒ ?g1.0 | Some x2 ⇒ ?g2.0 x2)›*)) (*goal: ‹eq_imp (λr s. (AT s (mutator m), s↓ (mutator m), sys_heap s↓ r, sys_fM s↓, sys_phase s↓, filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s↓))) (mut_m.mark_object_invL m)›*) apply (rename_tac s s') (*goal: ‹⋀(s::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state) s'::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state. ⟦AT s (mutator (m::'d)) = AT s' (mutator m); s↓ (mutator m) = s'↓ (mutator m); sys_heap s↓ = sys_heap s'↓; sys_fM s↓ = sys_fM s'↓; sys_phase s↓ = sys_phase s'↓; filter (λs::('b, 'c, 'a) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s↓) = filter (λs::('b, 'c, 'a) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s'↓)⟧ ⟹ ((atS (mutator m) mut_m.hs_get_roots_loop_locs s' ⟶ refs (s'↓ (mutator m)) ⊆ roots (s'↓ (mutator m)) ∧ (∀x::'a. x ∈ roots (s'↓ (mutator m)) ∧ x ∉ refs (s'↓ (mutator m)) ⟶ obj_at (λobj::('b, 'c, 'a) object. obj_mark obj = sys_fM s'↓) x s↓)) ∧ (atS (mutator m) mut_m.hs_get_roots_loop_mo_locs s' ⟶ (∃y::'a. ref (s'↓ (mutator m)) = Some y) ∧ the (ref (s'↓ (mutator m))) ∈ roots (s'↓ (mutator m))) ∧ (at (mutator m) mut_m.hs_get_roots_loop_done s' ⟶ obj_at (λobj::('b, 'c, 'a) object. obj_mark obj = sys_fM s'↓) (the (ref (s'↓ (mutator m)))) s↓) ∧ (at (mutator m) mut_m.hs_get_roots_loop_mo_ptest s' ⟶ phase (s'↓ (mutator m)) ≠ ph_Idle) ∧ (at (mutator m) mut_m.hs_get_roots_done s' ⟶ (∀x::'a. x ∈ roots (s'↓ (mutator m)) ⟶ obj_at (λobj::('b, 'c, 'a) object. obj_mark obj = sys_fM s'↓) x s↓)) ∧ (atS (mutator m) mut_m.mo_valid_ref_locs s' ⟶ ((∃y::'a. new_ref (s'↓ (mutator m)) = Some y) ⟶ the (new_ref (s'↓ (mutator m))) ∈ roots (s'↓ (mutator m))) ∧ tmp_ref (s'↓ (mutator m)) ∈ roots (s'↓ (mutator m))) ∧ (at (mutator m) mut_m.store_del_mo_null s' ⟶ (∃y::'a. ref (s'↓ (mutator m)) = Some y) ⟶ the (ref (s'↓ (mutator m))) ∈ ghost_honorary_root (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.ghost_honorary_root_nonempty_locs s' ⟶ the (ref (s'↓ (mutator m))) ∈ ghost_honorary_root (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.not_idle_locs s' ⟶ phase (s'↓ (mutator m)) ≠ ph_Idle ⟶ ghost_hs_phase (s'↓ (mutator m)) ≠ hp_Idle) ∧ (atS (mutator m) mut_m.hs_not_hp_Idle_locs s' ⟶ ghost_hs_phase (s'↓ (mutator m)) ≠ hp_Idle) ∧ (atS (mutator m) mut_m.mo_ptest_locs s' ⟶ phase (s'↓ (mutator m)) = ph_Idle ⟶ ghost_hs_phase (s'↓ (mutator m)) = hp_Idle ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleInit ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ = ph_Idle) ∧ (atS (mutator m) mut_m.ghost_honorary_grey_empty_locs s' ⟶ ghost_honorary_grey (s'↓ (mutator m)) = {}) ∧ (at (mutator m) mut_m.store_ins s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_InitMark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∃y::'a. new_ref (s'↓ (mutator m)) = Some y) ⟶ obj_at (λobj::('b, 'c, 'a) object. obj_mark obj = sys_fM s'↓) (the (new_ref (s'↓ (mutator m)))) s↓) ∧ (atS (mutator m) mut_m.ins_barrier_locs s' ⟶ ((ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∀opt_r'::'a option. mw_Mutate (tmp_ref (s'↓ (mutator m))) (field (s'↓ (mutator m))) opt_r' ∉ set (sys_mem_store_buffers (mutator m) s↓)) ⟶ (case sys_heap s'↓ (tmp_ref (s'↓ (mutator m))) of None ⇒ False | Some (x2::('b, 'c, 'a) object) ⇒ case obj_fields x2 (field (s'↓ (mutator m))) of None ⇒ True | Some (r'::'a) ⇒ obj_at (λobj::('b, 'c, 'a) object. obj_mark obj = sys_fM s'↓) r' s↓)) ∧ ref (s'↓ (mutator m)) = new_ref (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.del_barrier1_locs s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∀opt_r'::'a option. mw_Mutate (tmp_ref (s'↓ (mutator m))) (field (s'↓ (mutator m))) opt_r' ∉ set (sys_mem_store_buffers (mutator m) s↓)) ⟶ (case sys_heap s'↓ (tmp_ref (s'↓ (mutator m))) of None ⇒ False | Some (x2::('b, 'c, 'a) object) ⇒ case obj_fields x2 (field (s'↓ (mutator m))) of None ⇒ True | Some (r'::'a) ⇒ ref (s'↓ (mutator m)) = Some r' ∨ obj_at (λobj::('b, 'c, 'a) object. obj_mark obj = sys_fM s'↓) r' s↓)) ∧ (at (mutator m) mut_m.lop_store_ins s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∃y::'a. ref (s'↓ (mutator m)) = Some y) ⟶ obj_at (λobj::('b, 'c, 'a) object. obj_mark obj = sys_fM s'↓) (the (ref (s'↓ (mutator m)))) s↓) ∧ (at (mutator m) mut_m.mut_load s' ⟶ tmp_ref (s'↓ (mutator m)) ∈ roots (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.ghost_honorary_root_empty_locs s' ⟶ ghost_honorary_root (s'↓ (mutator m)) = {})) = ((atS (mutator m) mut_m.hs_get_roots_loop_locs s' ⟶ refs (s'↓ (mutator m)) ⊆ roots (s'↓ (mutator m)) ∧ (∀x::'a. x ∈ roots (s'↓ (mutator m)) ∧ x ∉ refs (s'↓ (mutator m)) ⟶ marked x s'↓)) ∧ (atS (mutator m) mut_m.hs_get_roots_loop_mo_locs s' ⟶ (∃y::'a. ref (s'↓ (mutator m)) = Some y) ∧ the (ref (s'↓ (mutator m))) ∈ roots (s'↓ (mutator m))) ∧ (at (mutator m) mut_m.hs_get_roots_loop_done s' ⟶ marked (the (ref (s'↓ (mutator m)))) s'↓) ∧ (at (mutator m) mut_m.hs_get_roots_loop_mo_ptest s' ⟶ phase (s'↓ (mutator m)) ≠ ph_Idle) ∧ (at (mutator m) mut_m.hs_get_roots_done s' ⟶ (∀x::'a. x ∈ roots (s'↓ (mutator m)) ⟶ marked x s'↓)) ∧ (atS (mutator m) mut_m.mo_valid_ref_locs s' ⟶ ((∃y::'a. new_ref (s'↓ (mutator m)) = Some y) ⟶ the (new_ref (s'↓ (mutator m))) ∈ roots (s'↓ (mutator m))) ∧ tmp_ref (s'↓ (mutator m)) ∈ roots (s'↓ (mutator m))) ∧ (at (mutator m) mut_m.store_del_mo_null s' ⟶ (∃y::'a. ref (s'↓ (mutator m)) = Some y) ⟶ the (ref (s'↓ (mutator m))) ∈ ghost_honorary_root (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.ghost_honorary_root_nonempty_locs s' ⟶ the (ref (s'↓ (mutator m))) ∈ ghost_honorary_root (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.not_idle_locs s' ⟶ phase (s'↓ (mutator m)) ≠ ph_Idle ⟶ ghost_hs_phase (s'↓ (mutator m)) ≠ hp_Idle) ∧ (atS (mutator m) mut_m.hs_not_hp_Idle_locs s' ⟶ ghost_hs_phase (s'↓ (mutator m)) ≠ hp_Idle) ∧ (atS (mutator m) mut_m.mo_ptest_locs s' ⟶ phase (s'↓ (mutator m)) = ph_Idle ⟶ ghost_hs_phase (s'↓ (mutator m)) = hp_Idle ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleInit ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ = ph_Idle) ∧ (atS (mutator m) mut_m.ghost_honorary_grey_empty_locs s' ⟶ ghost_honorary_grey (s'↓ (mutator m)) = {}) ∧ (at (mutator m) mut_m.store_ins s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_InitMark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∃y::'a. new_ref (s'↓ (mutator m)) = Some y) ⟶ marked (the (new_ref (s'↓ (mutator m)))) s'↓) ∧ (atS (mutator m) mut_m.ins_barrier_locs s' ⟶ ((ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∀opt_r'::'a option. mw_Mutate (tmp_ref (s'↓ (mutator m))) (field (s'↓ (mutator m))) opt_r' ∉ set (sys_mem_store_buffers (mutator m) s'↓)) ⟶ (case sys_heap s'↓ (tmp_ref (s'↓ (mutator m))) of None ⇒ False | Some (x2::('b, 'c, 'a) object) ⇒ case obj_fields x2 (field (s'↓ (mutator m))) of None ⇒ True | Some (r'::'a) ⇒ marked r' s'↓)) ∧ ref (s'↓ (mutator m)) = new_ref (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.del_barrier1_locs s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∀opt_r'::'a option. mw_Mutate (tmp_ref (s'↓ (mutator m))) (field (s'↓ (mutator m))) opt_r' ∉ set (sys_mem_store_buffers (mutator m) s'↓)) ⟶ (case sys_heap s'↓ (tmp_ref (s'↓ (mutator m))) of None ⇒ False | Some (x2::('b, 'c, 'a) object) ⇒ case obj_fields x2 (field (s'↓ (mutator m))) of None ⇒ True | Some (r'::'a) ⇒ ref (s'↓ (mutator m)) = Some r' ∨ marked r' s'↓)) ∧ (at (mutator m) mut_m.lop_store_ins s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∃y::'a. ref (s'↓ (mutator m)) = Some y) ⟶ marked (the (ref (s'↓ (mutator m)))) s'↓) ∧ (at (mutator m) mut_m.mut_load s' ⟶ tmp_ref (s'↓ (mutator m)) ∈ roots (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.ghost_honorary_root_empty_locs s' ⟶ ghost_honorary_root (s'↓ (mutator m)) = {}))›*) apply (subgoal_tac "∀r. marked r s↓ ⟷ marked r s'↓") (*goals: 1. ‹⋀s s'. ⟦AT s (mutator m) = AT s' (mutator m); s↓ (mutator m) = s'↓ (mutator m); sys_heap s↓ = sys_heap s'↓; sys_fM s↓ = sys_fM s'↓; sys_phase s↓ = sys_phase s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s'↓); ∀r. marked r s↓ = marked r s'↓⟧ ⟹ ((atS (mutator m) mut_m.hs_get_roots_loop_locs s' ⟶ refs (s'↓ (mutator m)) ⊆ roots (s'↓ (mutator m)) ∧ (∀x. x ∈ roots (s'↓ (mutator m)) ∧ x ∉ refs (s'↓ (mutator m)) ⟶ obj_at (λobj. obj_mark obj = sys_fM s'↓) x s↓)) ∧ (atS (mutator m) mut_m.hs_get_roots_loop_mo_locs s' ⟶ (∃y. ref (s'↓ (mutator m)) = Some y) ∧ the (ref (s'↓ (mutator m))) ∈ roots (s'↓ (mutator m))) ∧ (at (mutator m) mut_m.hs_get_roots_loop_done s' ⟶ obj_at (λobj. obj_mark obj = sys_fM s'↓) (the (ref (s'↓ (mutator m)))) s↓) ∧ (at (mutator m) mut_m.hs_get_roots_loop_mo_ptest s' ⟶ phase (s'↓ (mutator m)) ≠ ph_Idle) ∧ (at (mutator m) mut_m.hs_get_roots_done s' ⟶ (∀x. x ∈ roots (s'↓ (mutator m)) ⟶ obj_at (λobj. obj_mark obj = sys_fM s'↓) x s↓)) ∧ (atS (mutator m) mut_m.mo_valid_ref_locs s' ⟶ ((∃y. new_ref (s'↓ (mutator m)) = Some y) ⟶ the (new_ref (s'↓ (mutator m))) ∈ roots (s'↓ (mutator m))) ∧ tmp_ref (s'↓ (mutator m)) ∈ roots (s'↓ (mutator m))) ∧ (at (mutator m) mut_m.store_del_mo_null s' ⟶ (∃y. ref (s'↓ (mutator m)) = Some y) ⟶ the (ref (s'↓ (mutator m))) ∈ ghost_honorary_root (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.ghost_honorary_root_nonempty_locs s' ⟶ the (ref (s'↓ (mutator m))) ∈ ghost_honorary_root (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.not_idle_locs s' ⟶ phase (s'↓ (mutator m)) ≠ ph_Idle ⟶ ghost_hs_phase (s'↓ (mutator m)) ≠ hp_Idle) ∧ (atS (mutator m) mut_m.hs_not_hp_Idle_locs s' ⟶ ghost_hs_phase (s'↓ (mutator m)) ≠ hp_Idle) ∧ (atS (mutator m) mut_m.mo_ptest_locs s' ⟶ phase (s'↓ (mutator m)) = ph_Idle ⟶ ghost_hs_phase (s'↓ (mutator m)) = hp_Idle ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleInit ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ = ph_Idle) ∧ (atS (mutator m) mut_m.ghost_honorary_grey_empty_locs s' ⟶ ghost_honorary_grey (s'↓ (mutator m)) = {}) ∧ (at (mutator m) mut_m.store_ins s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_InitMark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∃y. new_ref (s'↓ (mutator m)) = Some y) ⟶ obj_at (λobj. obj_mark obj = sys_fM s'↓) (the (new_ref (s'↓ (mutator m)))) s↓) ∧ (atS (mutator m) mut_m.ins_barrier_locs s' ⟶ ((ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∀opt_r'. mw_Mutate (tmp_ref (s'↓ (mutator m))) (field (s'↓ (mutator m))) opt_r' ∉ set (sys_mem_store_buffers (mutator m) s↓)) ⟶ (case sys_heap s'↓ (tmp_ref (s'↓ (mutator m))) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (field (s'↓ (mutator m))) of None ⇒ True | Some r' ⇒ obj_at (λobj. obj_mark obj = sys_fM s'↓) r' s↓)) ∧ ref (s'↓ (mutator m)) = new_ref (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.del_barrier1_locs s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∀opt_r'. mw_Mutate (tmp_ref (s'↓ (mutator m))) (field (s'↓ (mutator m))) opt_r' ∉ set (sys_mem_store_buffers (mutator m) s↓)) ⟶ (case sys_heap s'↓ (tmp_ref (s'↓ (mutator m))) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (field (s'↓ (mutator m))) of None ⇒ True | Some r' ⇒ ref (s'↓ (mutator m)) = Some r' ∨ obj_at (λobj. obj_mark obj = sys_fM s'↓) r' s↓)) ∧ (at (mutator m) mut_m.lop_store_ins s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∃y. ref (s'↓ (mutator m)) = Some y) ⟶ obj_at (λobj. obj_mark obj = sys_fM s'↓) (the (ref (s'↓ (mutator m)))) s↓) ∧ (at (mutator m) mut_m.mut_load s' ⟶ tmp_ref (s'↓ (mutator m)) ∈ roots (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.ghost_honorary_root_empty_locs s' ⟶ ghost_honorary_root (s'↓ (mutator m)) = {})) = ((atS (mutator m) mut_m.hs_get_roots_loop_locs s' ⟶ refs (s'↓ (mutator m)) ⊆ roots (s'↓ (mutator m)) ∧ (∀x. x ∈ roots (s'↓ (mutator m)) ∧ x ∉ refs (s'↓ (mutator m)) ⟶ marked x s'↓)) ∧ (atS (mutator m) mut_m.hs_get_roots_loop_mo_locs s' ⟶ (∃y. ref (s'↓ (mutator m)) = Some y) ∧ the (ref (s'↓ (mutator m))) ∈ roots (s'↓ (mutator m))) ∧ (at (mutator m) mut_m.hs_get_roots_loop_done s' ⟶ marked (the (ref (s'↓ (mutator m)))) s'↓) ∧ (at (mutator m) mut_m.hs_get_roots_loop_mo_ptest s' ⟶ phase (s'↓ (mutator m)) ≠ ph_Idle) ∧ (at (mutator m) mut_m.hs_get_roots_done s' ⟶ (∀x. x ∈ roots (s'↓ (mutator m)) ⟶ marked x s'↓)) ∧ (atS (mutator m) mut_m.mo_valid_ref_locs s' ⟶ ((∃y. new_ref (s'↓ (mutator m)) = Some y) ⟶ the (new_ref (s'↓ (mutator m))) ∈ roots (s'↓ (mutator m))) ∧ tmp_ref (s'↓ (mutator m)) ∈ roots (s'↓ (mutator m))) ∧ (at (mutator m) mut_m.store_del_mo_null s' ⟶ (∃y. ref (s'↓ (mutator m)) = Some y) ⟶ the (ref (s'↓ (mutator m))) ∈ ghost_honorary_root (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.ghost_honorary_root_nonempty_locs s' ⟶ the (ref (s'↓ (mutator m))) ∈ ghost_honorary_root (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.not_idle_locs s' ⟶ phase (s'↓ (mutator m)) ≠ ph_Idle ⟶ ghost_hs_phase (s'↓ (mutator m)) ≠ hp_Idle) ∧ (atS (mutator m) mut_m.hs_not_hp_Idle_locs s' ⟶ ghost_hs_phase (s'↓ (mutator m)) ≠ hp_Idle) ∧ (atS (mutator m) mut_m.mo_ptest_locs s' ⟶ phase (s'↓ (mutator m)) = ph_Idle ⟶ ghost_hs_phase (s'↓ (mutator m)) = hp_Idle ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleInit ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ = ph_Idle) ∧ (atS (mutator m) mut_m.ghost_honorary_grey_empty_locs s' ⟶ ghost_honorary_grey (s'↓ (mutator m)) = {}) ∧ (at (mutator m) mut_m.store_ins s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_InitMark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∃y. new_ref (s'↓ (mutator m)) = Some y) ⟶ marked (the (new_ref (s'↓ (mutator m)))) s'↓) ∧ (atS (mutator m) mut_m.ins_barrier_locs s' ⟶ ((ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∀opt_r'. mw_Mutate (tmp_ref (s'↓ (mutator m))) (field (s'↓ (mutator m))) opt_r' ∉ set (sys_mem_store_buffers (mutator m) s'↓)) ⟶ (case sys_heap s'↓ (tmp_ref (s'↓ (mutator m))) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (field (s'↓ (mutator m))) of None ⇒ True | Some r' ⇒ marked r' s'↓)) ∧ ref (s'↓ (mutator m)) = new_ref (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.del_barrier1_locs s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∀opt_r'. mw_Mutate (tmp_ref (s'↓ (mutator m))) (field (s'↓ (mutator m))) opt_r' ∉ set (sys_mem_store_buffers (mutator m) s'↓)) ⟶ (case sys_heap s'↓ (tmp_ref (s'↓ (mutator m))) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (field (s'↓ (mutator m))) of None ⇒ True | Some r' ⇒ ref (s'↓ (mutator m)) = Some r' ∨ marked r' s'↓)) ∧ (at (mutator m) mut_m.lop_store_ins s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∃y. ref (s'↓ (mutator m)) = Some y) ⟶ marked (the (ref (s'↓ (mutator m)))) s'↓) ∧ (at (mutator m) mut_m.mut_load s' ⟶ tmp_ref (s'↓ (mutator m)) ∈ roots (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.ghost_honorary_root_empty_locs s' ⟶ ghost_honorary_root (s'↓ (mutator m)) = {}))› 2. ‹⋀s s'. ⟦AT s (mutator m) = AT s' (mutator m); s↓ (mutator m) = s'↓ (mutator m); sys_heap s↓ = sys_heap s'↓; sys_fM s↓ = sys_fM s'↓; sys_phase s↓ = sys_phase s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s'↓)⟧ ⟹ ∀r. marked r s↓ = marked r s'↓› discuss goal 1*) apply (subgoal_tac "∀r. valid_null_ref r s↓ ⟷ valid_null_ref r s'↓") (*goals: 1. ‹⋀s s'. ⟦AT s (mutator m) = AT s' (mutator m); s↓ (mutator m) = s'↓ (mutator m); sys_heap s↓ = sys_heap s'↓; sys_fM s↓ = sys_fM s'↓; sys_phase s↓ = sys_phase s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s'↓); ∀r. marked r s↓ = marked r s'↓; ∀r. valid_null_ref r s↓ = valid_null_ref r s'↓⟧ ⟹ ((atS (mutator m) mut_m.hs_get_roots_loop_locs s' ⟶ refs (s'↓ (mutator m)) ⊆ roots (s'↓ (mutator m)) ∧ (∀x. x ∈ roots (s'↓ (mutator m)) ∧ x ∉ refs (s'↓ (mutator m)) ⟶ obj_at (λobj. obj_mark obj = sys_fM s'↓) x s↓)) ∧ (atS (mutator m) mut_m.hs_get_roots_loop_mo_locs s' ⟶ (∃y. ref (s'↓ (mutator m)) = Some y) ∧ the (ref (s'↓ (mutator m))) ∈ roots (s'↓ (mutator m))) ∧ (at (mutator m) mut_m.hs_get_roots_loop_done s' ⟶ obj_at (λobj. obj_mark obj = sys_fM s'↓) (the (ref (s'↓ (mutator m)))) s↓) ∧ (at (mutator m) mut_m.hs_get_roots_loop_mo_ptest s' ⟶ phase (s'↓ (mutator m)) ≠ ph_Idle) ∧ (at (mutator m) mut_m.hs_get_roots_done s' ⟶ (∀x. x ∈ roots (s'↓ (mutator m)) ⟶ obj_at (λobj. obj_mark obj = sys_fM s'↓) x s↓)) ∧ (atS (mutator m) mut_m.mo_valid_ref_locs s' ⟶ ((∃y. new_ref (s'↓ (mutator m)) = Some y) ⟶ the (new_ref (s'↓ (mutator m))) ∈ roots (s'↓ (mutator m))) ∧ tmp_ref (s'↓ (mutator m)) ∈ roots (s'↓ (mutator m))) ∧ (at (mutator m) mut_m.store_del_mo_null s' ⟶ (∃y. ref (s'↓ (mutator m)) = Some y) ⟶ the (ref (s'↓ (mutator m))) ∈ ghost_honorary_root (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.ghost_honorary_root_nonempty_locs s' ⟶ the (ref (s'↓ (mutator m))) ∈ ghost_honorary_root (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.not_idle_locs s' ⟶ phase (s'↓ (mutator m)) ≠ ph_Idle ⟶ ghost_hs_phase (s'↓ (mutator m)) ≠ hp_Idle) ∧ (atS (mutator m) mut_m.hs_not_hp_Idle_locs s' ⟶ ghost_hs_phase (s'↓ (mutator m)) ≠ hp_Idle) ∧ (atS (mutator m) mut_m.mo_ptest_locs s' ⟶ phase (s'↓ (mutator m)) = ph_Idle ⟶ ghost_hs_phase (s'↓ (mutator m)) = hp_Idle ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleInit ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ = ph_Idle) ∧ (atS (mutator m) mut_m.ghost_honorary_grey_empty_locs s' ⟶ ghost_honorary_grey (s'↓ (mutator m)) = {}) ∧ (at (mutator m) mut_m.store_ins s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_InitMark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∃y. new_ref (s'↓ (mutator m)) = Some y) ⟶ obj_at (λobj. obj_mark obj = sys_fM s'↓) (the (new_ref (s'↓ (mutator m)))) s↓) ∧ (atS (mutator m) mut_m.ins_barrier_locs s' ⟶ ((ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∀opt_r'. mw_Mutate (tmp_ref (s'↓ (mutator m))) (field (s'↓ (mutator m))) opt_r' ∉ set (sys_mem_store_buffers (mutator m) s↓)) ⟶ (case sys_heap s'↓ (tmp_ref (s'↓ (mutator m))) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (field (s'↓ (mutator m))) of None ⇒ True | Some r' ⇒ obj_at (λobj. obj_mark obj = sys_fM s'↓) r' s↓)) ∧ ref (s'↓ (mutator m)) = new_ref (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.del_barrier1_locs s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∀opt_r'. mw_Mutate (tmp_ref (s'↓ (mutator m))) (field (s'↓ (mutator m))) opt_r' ∉ set (sys_mem_store_buffers (mutator m) s↓)) ⟶ (case sys_heap s'↓ (tmp_ref (s'↓ (mutator m))) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (field (s'↓ (mutator m))) of None ⇒ True | Some r' ⇒ ref (s'↓ (mutator m)) = Some r' ∨ obj_at (λobj. obj_mark obj = sys_fM s'↓) r' s↓)) ∧ (at (mutator m) mut_m.lop_store_ins s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∃y. ref (s'↓ (mutator m)) = Some y) ⟶ obj_at (λobj. obj_mark obj = sys_fM s'↓) (the (ref (s'↓ (mutator m)))) s↓) ∧ (at (mutator m) mut_m.mut_load s' ⟶ tmp_ref (s'↓ (mutator m)) ∈ roots (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.ghost_honorary_root_empty_locs s' ⟶ ghost_honorary_root (s'↓ (mutator m)) = {})) = ((atS (mutator m) mut_m.hs_get_roots_loop_locs s' ⟶ refs (s'↓ (mutator m)) ⊆ roots (s'↓ (mutator m)) ∧ (∀x. x ∈ roots (s'↓ (mutator m)) ∧ x ∉ refs (s'↓ (mutator m)) ⟶ marked x s'↓)) ∧ (atS (mutator m) mut_m.hs_get_roots_loop_mo_locs s' ⟶ (∃y. ref (s'↓ (mutator m)) = Some y) ∧ the (ref (s'↓ (mutator m))) ∈ roots (s'↓ (mutator m))) ∧ (at (mutator m) mut_m.hs_get_roots_loop_done s' ⟶ marked (the (ref (s'↓ (mutator m)))) s'↓) ∧ (at (mutator m) mut_m.hs_get_roots_loop_mo_ptest s' ⟶ phase (s'↓ (mutator m)) ≠ ph_Idle) ∧ (at (mutator m) mut_m.hs_get_roots_done s' ⟶ (∀x. x ∈ roots (s'↓ (mutator m)) ⟶ marked x s'↓)) ∧ (atS (mutator m) mut_m.mo_valid_ref_locs s' ⟶ ((∃y. new_ref (s'↓ (mutator m)) = Some y) ⟶ the (new_ref (s'↓ (mutator m))) ∈ roots (s'↓ (mutator m))) ∧ tmp_ref (s'↓ (mutator m)) ∈ roots (s'↓ (mutator m))) ∧ (at (mutator m) mut_m.store_del_mo_null s' ⟶ (∃y. ref (s'↓ (mutator m)) = Some y) ⟶ the (ref (s'↓ (mutator m))) ∈ ghost_honorary_root (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.ghost_honorary_root_nonempty_locs s' ⟶ the (ref (s'↓ (mutator m))) ∈ ghost_honorary_root (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.not_idle_locs s' ⟶ phase (s'↓ (mutator m)) ≠ ph_Idle ⟶ ghost_hs_phase (s'↓ (mutator m)) ≠ hp_Idle) ∧ (atS (mutator m) mut_m.hs_not_hp_Idle_locs s' ⟶ ghost_hs_phase (s'↓ (mutator m)) ≠ hp_Idle) ∧ (atS (mutator m) mut_m.mo_ptest_locs s' ⟶ phase (s'↓ (mutator m)) = ph_Idle ⟶ ghost_hs_phase (s'↓ (mutator m)) = hp_Idle ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleInit ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ = ph_Idle) ∧ (atS (mutator m) mut_m.ghost_honorary_grey_empty_locs s' ⟶ ghost_honorary_grey (s'↓ (mutator m)) = {}) ∧ (at (mutator m) mut_m.store_ins s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_InitMark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∃y. new_ref (s'↓ (mutator m)) = Some y) ⟶ marked (the (new_ref (s'↓ (mutator m)))) s'↓) ∧ (atS (mutator m) mut_m.ins_barrier_locs s' ⟶ ((ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∀opt_r'. mw_Mutate (tmp_ref (s'↓ (mutator m))) (field (s'↓ (mutator m))) opt_r' ∉ set (sys_mem_store_buffers (mutator m) s'↓)) ⟶ (case sys_heap s'↓ (tmp_ref (s'↓ (mutator m))) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (field (s'↓ (mutator m))) of None ⇒ True | Some r' ⇒ marked r' s'↓)) ∧ ref (s'↓ (mutator m)) = new_ref (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.del_barrier1_locs s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∀opt_r'. mw_Mutate (tmp_ref (s'↓ (mutator m))) (field (s'↓ (mutator m))) opt_r' ∉ set (sys_mem_store_buffers (mutator m) s'↓)) ⟶ (case sys_heap s'↓ (tmp_ref (s'↓ (mutator m))) of None ⇒ False | Some x2 ⇒ case obj_fields x2 (field (s'↓ (mutator m))) of None ⇒ True | Some r' ⇒ ref (s'↓ (mutator m)) = Some r' ∨ marked r' s'↓)) ∧ (at (mutator m) mut_m.lop_store_ins s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∃y. ref (s'↓ (mutator m)) = Some y) ⟶ marked (the (ref (s'↓ (mutator m)))) s'↓) ∧ (at (mutator m) mut_m.mut_load s' ⟶ tmp_ref (s'↓ (mutator m)) ∈ roots (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.ghost_honorary_root_empty_locs s' ⟶ ghost_honorary_root (s'↓ (mutator m)) = {}))› 2. ‹⋀s s'. ⟦AT s (mutator m) = AT s' (mutator m); s↓ (mutator m) = s'↓ (mutator m); sys_heap s↓ = sys_heap s'↓; sys_fM s↓ = sys_fM s'↓; sys_phase s↓ = sys_phase s'↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s↓) = filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s'↓); ∀r. marked r s↓ = marked r s'↓⟧ ⟹ ∀r. valid_null_ref r s↓ = valid_null_ref r s'↓› discuss goal 1*) apply (subgoal_tac "∀r f opt_r'. mw_Mutate r f opt_r' ∉ set (sys_mem_store_buffers (mutator m) s↓) ⟷ mw_Mutate r f opt_r' ∉ set (sys_mem_store_buffers (mutator m) s'↓)") (*goals: 1. ‹⋀(s::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state) s'::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state. ⟦AT s (mutator (m::'d)) = AT s' (mutator m); s↓ (mutator m) = s'↓ (mutator m); sys_heap s↓ = sys_heap s'↓; sys_fM s↓ = sys_fM s'↓; sys_phase s↓ = sys_phase s'↓; filter (λs::('b, 'c, 'a) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s↓) = filter (λs::('b, 'c, 'a) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s'↓); ∀r::'a. marked r s↓ = marked r s'↓; ∀r::'a option. valid_null_ref r s↓ = valid_null_ref r s'↓; ∀(r::'a) (f::'b) opt_r'::'a option. (mw_Mutate r f opt_r' ∉ set (sys_mem_store_buffers (mutator m) s↓)) = (mw_Mutate r f opt_r' ∉ set (sys_mem_store_buffers (mutator m) s'↓))⟧ ⟹ ((atS (mutator m) mut_m.hs_get_roots_loop_locs s' ⟶ refs (s'↓ (mutator m)) ⊆ roots (s'↓ (mutator m)) ∧ (∀x::'a. x ∈ roots (s'↓ (mutator m)) ∧ x ∉ refs (s'↓ (mutator m)) ⟶ obj_at (λobj::('b, 'c, 'a) object. obj_mark obj = sys_fM s'↓) x s↓)) ∧ (atS (mutator m) mut_m.hs_get_roots_loop_mo_locs s' ⟶ (∃y::'a. ref (s'↓ (mutator m)) = Some y) ∧ the (ref (s'↓ (mutator m))) ∈ roots (s'↓ (mutator m))) ∧ (at (mutator m) mut_m.hs_get_roots_loop_done s' ⟶ obj_at (λobj::('b, 'c, 'a) object. obj_mark obj = sys_fM s'↓) (the (ref (s'↓ (mutator m)))) s↓) ∧ (at (mutator m) mut_m.hs_get_roots_loop_mo_ptest s' ⟶ phase (s'↓ (mutator m)) ≠ ph_Idle) ∧ (at (mutator m) mut_m.hs_get_roots_done s' ⟶ (∀x::'a. x ∈ roots (s'↓ (mutator m)) ⟶ obj_at (λobj::('b, 'c, 'a) object. obj_mark obj = sys_fM s'↓) x s↓)) ∧ (atS (mutator m) mut_m.mo_valid_ref_locs s' ⟶ ((∃y::'a. new_ref (s'↓ (mutator m)) = Some y) ⟶ the (new_ref (s'↓ (mutator m))) ∈ roots (s'↓ (mutator m))) ∧ tmp_ref (s'↓ (mutator m)) ∈ roots (s'↓ (mutator m))) ∧ (at (mutator m) mut_m.store_del_mo_null s' ⟶ (∃y::'a. ref (s'↓ (mutator m)) = Some y) ⟶ the (ref (s'↓ (mutator m))) ∈ ghost_honorary_root (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.ghost_honorary_root_nonempty_locs s' ⟶ the (ref (s'↓ (mutator m))) ∈ ghost_honorary_root (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.not_idle_locs s' ⟶ phase (s'↓ (mutator m)) ≠ ph_Idle ⟶ ghost_hs_phase (s'↓ (mutator m)) ≠ hp_Idle) ∧ (atS (mutator m) mut_m.hs_not_hp_Idle_locs s' ⟶ ghost_hs_phase (s'↓ (mutator m)) ≠ hp_Idle) ∧ (atS (mutator m) mut_m.mo_ptest_locs s' ⟶ phase (s'↓ (mutator m)) = ph_Idle ⟶ ghost_hs_phase (s'↓ (mutator m)) = hp_Idle ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleInit ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ = ph_Idle) ∧ (atS (mutator m) mut_m.ghost_honorary_grey_empty_locs s' ⟶ ghost_honorary_grey (s'↓ (mutator m)) = {}) ∧ (at (mutator m) mut_m.store_ins s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_InitMark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∃y::'a. new_ref (s'↓ (mutator m)) = Some y) ⟶ obj_at (λobj::('b, 'c, 'a) object. obj_mark obj = sys_fM s'↓) (the (new_ref (s'↓ (mutator m)))) s↓) ∧ (atS (mutator m) mut_m.ins_barrier_locs s' ⟶ ((ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∀opt_r'::'a option. mw_Mutate (tmp_ref (s'↓ (mutator m))) (field (s'↓ (mutator m))) opt_r' ∉ set (sys_mem_store_buffers (mutator m) s↓)) ⟶ (case sys_heap s'↓ (tmp_ref (s'↓ (mutator m))) of None ⇒ False | Some (x2::('b, 'c, 'a) object) ⇒ case obj_fields x2 (field (s'↓ (mutator m))) of None ⇒ True | Some (r'::'a) ⇒ obj_at (λobj::('b, 'c, 'a) object. obj_mark obj = sys_fM s'↓) r' s↓)) ∧ ref (s'↓ (mutator m)) = new_ref (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.del_barrier1_locs s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∀opt_r'::'a option. mw_Mutate (tmp_ref (s'↓ (mutator m))) (field (s'↓ (mutator m))) opt_r' ∉ set (sys_mem_store_buffers (mutator m) s↓)) ⟶ (case sys_heap s'↓ (tmp_ref (s'↓ (mutator m))) of None ⇒ False | Some (x2::('b, 'c, 'a) object) ⇒ case obj_fields x2 (field (s'↓ (mutator m))) of None ⇒ True | Some (r'::'a) ⇒ ref (s'↓ (mutator m)) = Some r' ∨ obj_at (λobj::('b, 'c, 'a) object. obj_mark obj = sys_fM s'↓) r' s↓)) ∧ (at (mutator m) mut_m.lop_store_ins s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∃y::'a. ref (s'↓ (mutator m)) = Some y) ⟶ obj_at (λobj::('b, 'c, 'a) object. obj_mark obj = sys_fM s'↓) (the (ref (s'↓ (mutator m)))) s↓) ∧ (at (mutator m) mut_m.mut_load s' ⟶ tmp_ref (s'↓ (mutator m)) ∈ roots (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.ghost_honorary_root_empty_locs s' ⟶ ghost_honorary_root (s'↓ (mutator m)) = {})) = ((atS (mutator m) mut_m.hs_get_roots_loop_locs s' ⟶ refs (s'↓ (mutator m)) ⊆ roots (s'↓ (mutator m)) ∧ (∀x::'a. x ∈ roots (s'↓ (mutator m)) ∧ x ∉ refs (s'↓ (mutator m)) ⟶ marked x s'↓)) ∧ (atS (mutator m) mut_m.hs_get_roots_loop_mo_locs s' ⟶ (∃y::'a. ref (s'↓ (mutator m)) = Some y) ∧ the (ref (s'↓ (mutator m))) ∈ roots (s'↓ (mutator m))) ∧ (at (mutator m) mut_m.hs_get_roots_loop_done s' ⟶ marked (the (ref (s'↓ (mutator m)))) s'↓) ∧ (at (mutator m) mut_m.hs_get_roots_loop_mo_ptest s' ⟶ phase (s'↓ (mutator m)) ≠ ph_Idle) ∧ (at (mutator m) mut_m.hs_get_roots_done s' ⟶ (∀x::'a. x ∈ roots (s'↓ (mutator m)) ⟶ marked x s'↓)) ∧ (atS (mutator m) mut_m.mo_valid_ref_locs s' ⟶ ((∃y::'a. new_ref (s'↓ (mutator m)) = Some y) ⟶ the (new_ref (s'↓ (mutator m))) ∈ roots (s'↓ (mutator m))) ∧ tmp_ref (s'↓ (mutator m)) ∈ roots (s'↓ (mutator m))) ∧ (at (mutator m) mut_m.store_del_mo_null s' ⟶ (∃y::'a. ref (s'↓ (mutator m)) = Some y) ⟶ the (ref (s'↓ (mutator m))) ∈ ghost_honorary_root (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.ghost_honorary_root_nonempty_locs s' ⟶ the (ref (s'↓ (mutator m))) ∈ ghost_honorary_root (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.not_idle_locs s' ⟶ phase (s'↓ (mutator m)) ≠ ph_Idle ⟶ ghost_hs_phase (s'↓ (mutator m)) ≠ hp_Idle) ∧ (atS (mutator m) mut_m.hs_not_hp_Idle_locs s' ⟶ ghost_hs_phase (s'↓ (mutator m)) ≠ hp_Idle) ∧ (atS (mutator m) mut_m.mo_ptest_locs s' ⟶ phase (s'↓ (mutator m)) = ph_Idle ⟶ ghost_hs_phase (s'↓ (mutator m)) = hp_Idle ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleInit ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ = ph_Idle) ∧ (atS (mutator m) mut_m.ghost_honorary_grey_empty_locs s' ⟶ ghost_honorary_grey (s'↓ (mutator m)) = {}) ∧ (at (mutator m) mut_m.store_ins s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_InitMark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∃y::'a. new_ref (s'↓ (mutator m)) = Some y) ⟶ marked (the (new_ref (s'↓ (mutator m)))) s'↓) ∧ (atS (mutator m) mut_m.ins_barrier_locs s' ⟶ ((ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∀opt_r'::'a option. mw_Mutate (tmp_ref (s'↓ (mutator m))) (field (s'↓ (mutator m))) opt_r' ∉ set (sys_mem_store_buffers (mutator m) s'↓)) ⟶ (case sys_heap s'↓ (tmp_ref (s'↓ (mutator m))) of None ⇒ False | Some (x2::('b, 'c, 'a) object) ⇒ case obj_fields x2 (field (s'↓ (mutator m))) of None ⇒ True | Some (r'::'a) ⇒ marked r' s'↓)) ∧ ref (s'↓ (mutator m)) = new_ref (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.del_barrier1_locs s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∀opt_r'::'a option. mw_Mutate (tmp_ref (s'↓ (mutator m))) (field (s'↓ (mutator m))) opt_r' ∉ set (sys_mem_store_buffers (mutator m) s'↓)) ⟶ (case sys_heap s'↓ (tmp_ref (s'↓ (mutator m))) of None ⇒ False | Some (x2::('b, 'c, 'a) object) ⇒ case obj_fields x2 (field (s'↓ (mutator m))) of None ⇒ True | Some (r'::'a) ⇒ ref (s'↓ (mutator m)) = Some r' ∨ marked r' s'↓)) ∧ (at (mutator m) mut_m.lop_store_ins s' ⟶ (ghost_hs_phase (s'↓ (mutator m)) = hp_Mark ∨ ghost_hs_phase (s'↓ (mutator m)) = hp_IdleMarkSweep ∧ sys_phase s'↓ ≠ ph_Idle) ∧ (∃y::'a. ref (s'↓ (mutator m)) = Some y) ⟶ marked (the (ref (s'↓ (mutator m)))) s'↓) ∧ (at (mutator m) mut_m.mut_load s' ⟶ tmp_ref (s'↓ (mutator m)) ∈ roots (s'↓ (mutator m))) ∧ (atS (mutator m) mut_m.ghost_honorary_root_empty_locs s' ⟶ ghost_honorary_root (s'↓ (mutator m)) = {}))› 2. ‹⋀(s::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state) s'::(('b, 'c, 'a) response, char list, 'd process_name, 'd process_name × ('b, 'd, 'c, 'a) request_op, ('b, 'd, 'c, 'a) Model.local_state) system_state. ⟦AT s (mutator (m::'d)) = AT s' (mutator m); s↓ (mutator m) = s'↓ (mutator m); sys_heap s↓ = sys_heap s'↓; sys_fM s↓ = sys_fM s'↓; sys_phase s↓ = sys_phase s'↓; filter (λs::('b, 'c, 'a) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s↓) = filter (λs::('b, 'c, 'a) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s'↓); ∀r::'a. marked r s↓ = marked r s'↓; ∀r::'a option. valid_null_ref r s↓ = valid_null_ref r s'↓⟧ ⟹ ∀(r::'a) (f::'b) opt_r'::'a option. (mw_Mutate r f opt_r' ∉ set (sys_mem_store_buffers (mutator m) s↓)) = (mw_Mutate r f opt_r' ∉ set (sys_mem_store_buffers (mutator m) s'↓))› discuss goal 1*) apply (clarsimp cong: option.case_cong (*‹⟦?option = ?option'; ?option' = None ⟹ ?f1.0 = ?g1.0; ⋀x2. ?option' = Some x2 ⟹ ?f2.0 x2 = ?g2.0 x2⟧ ⟹ (case ?option of None ⇒ ?f1.0 | Some x2 ⇒ ?f2.0 x2) = (case ?option' of None ⇒ ?g1.0 | Some x2 ⇒ ?g2.0 x2)›*)) (*discuss goal 2*) apply (metis (mono_tags, lifting) filter_set (*‹Set.filter (?P::?'a::type ⇒ bool) (set (?xs::?'a::type list)) = set (filter ?P ?xs)›*) member_filter (*‹((?x::?'a::type) ∈ Set.filter (?P::?'a::type ⇒ bool) (?A::?'a::type set)) = (?x ∈ ?A ∧ ?P ?x)›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply (clarsimp simp: obj_at_def (*‹obj_at ?P ?r ≡ λs. case sys_heap s ?r of None ⇒ False | Some obj ⇒ ?P obj›*) valid_null_ref_def (*‹valid_null_ref ?r ≡ case ?r of None ⇒ λs. True | Some r' ⇒ obj_at (λs. True) r'›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply (clarsimp simp: obj_at_def (*‹obj_at (?P::(?'field, ?'payload, ?'ref) object ⇒ bool) (?r::?'ref) ≡ λs::?'mut process_name ⇒ (?'field, ?'mut, ?'payload, ?'ref) Model.local_state. case sys_heap s ?r of None ⇒ False | Some (obj::(?'field, ?'payload, ?'ref) object) ⇒ ?P obj›*) valid_null_ref_def (*‹valid_null_ref (?r::?'ref option) ≡ case ?r of None ⇒ λs::?'mut process_name ⇒ (?'field, ?'mut, ?'payload, ?'ref) Model.local_state. True | Some (r'::?'ref) ⇒ obj_at (λs::(?'field, ?'payload, ?'ref) object. True) r'›*) split: option.splits (*‹(?P::?'b ⇒ bool) (case ?option::?'a option of None ⇒ ?f1.0::?'b | Some (x::?'a) ⇒ (?f2.0::?'a ⇒ ?'b) x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2::?'a. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹(?P::?'b ⇒ bool) (case ?option::?'a option of None ⇒ ?f1.0::?'b | Some (x::?'a) ⇒ (?f2.0::?'a ⇒ ?'b) x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2::?'a. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) (*proven 2 subgoals*) . lemmas mut_m_mark_object_invL_niE[nie] = iffD1[OF mut_m_mark_object_invL_eq_imp[simplified eq_imp_simps, rule_format, unfolded conj_explode], rotated -1] (*<*) end (*>*)
{ "path": "afp-2025-02-12/thys/ConcurrentGC/Local_Invariants_Lemmas.thy", "repo": "afp-2025-02-12", "sha": "bd2136eabd7116f4a5cb3c62cf92063cf30244585bbd0f1afd07d0519136f5b0" }
theory MLSS_Logic imports Main begin section ‹Propositional formulae› text ‹ This theory contains syntax and semantics of propositional formulae. › datatype (atoms: 'a) fm = is_Atom: Atom 'a | And "'a fm" "'a fm" | Or "'a fm" "'a fm" | Neg "'a fm" fun "interp" :: "('model ⇒ 'a ⇒ bool) ⇒ 'model ⇒ 'a fm ⇒ bool" where "interp I⇩a M (Atom a) = I⇩a M a" | "interp I⇩a M (And φ₁ φ₂) = (interp I⇩a M φ₁ ∧ interp I⇩a M φ₂)" | "interp I⇩a M (Or φ₁ φ₂) = (interp I⇩a M φ₁ ∨ interp I⇩a M φ₂)" | "interp I⇩a M (Neg φ) = (¬ interp I⇩a M φ)" locale ATOM = fixes I⇩a :: "'model ⇒ 'a ⇒ bool" begin abbreviation I where "I ≡ interp I⇩a" end definition "Atoms A ≡ {a |a. Atom a ∈ A}" lemma Atoms_Un[simp]: "Atoms (A ∪ B) = Atoms A ∪ Atoms B" unfolding Atoms_def (*goal: ‹{a |a::'a::type. Atom a ∈ (A::'a::type fm set) ∪ (B::'a::type fm set)} = {a |a::'a::type. Atom a ∈ A} ∪ {a |a::'a::type. Atom a ∈ B}›*) by auto lemma Atoms_mono: "A ⊆ B ⟹ Atoms A ⊆ Atoms B" unfolding Atoms_def (*goal: ‹A ⊆ B ⟹ {a |a. Atom a ∈ A} ⊆ {a |a. Atom a ∈ B}›*) by auto end
{ "path": "afp-2025-02-12/thys/MLSS_Decision_Proc/MLSS_Logic.thy", "repo": "afp-2025-02-12", "sha": "5164f2593af2e1cd74eb4ec71a29bcd6ae9cd238b68367869274a0df1ecda30f" }
(* File: Master_Theorem_Examples.thy Author: Manuel Eberl <manuel@pruvisto.org> Examples for the application of the Master theorem and related proof methods. *) section ‹Examples› theory Master_Theorem_Examples imports Complex_Main Akra_Bazzi_Method Akra_Bazzi_Approximation begin subsection ‹Merge sort› (* A merge sort cost function that is parametrised with the recombination costs *) function merge_sort_cost :: "(nat ⇒ real) ⇒ nat ⇒ real" where "merge_sort_cost t 0 = 0" | "merge_sort_cost t 1 = 1" | "n ≥ 2 ⟹ merge_sort_cost t n = merge_sort_cost t (nat ⌊real n / 2⌋) + merge_sort_cost t (nat ⌈real n / 2⌉) + t n" by force simp_all termination by akra_bazzi_termination simp_all lemma merge_sort_nonneg[simp]: "(⋀n. t n ≥ 0) ⟹ merge_sort_cost t x ≥ 0" apply (induction t x rule: merge_sort_cost.induct (*‹⟦⋀t. ?P t 0; ⋀t. ?P t 1; ⋀n t. ⟦2 ≤ n; ?P t (nat ⌊real n / 2⌋); ?P t (nat ⌈real n / 2⌉)⟧ ⟹ ?P t n⟧ ⟹ ?P ?a0.0 ?a1.0›*)) (*goals: 1. ‹⋀t. (⋀n. 0 ≤ t n) ⟹ 0 ≤ merge_sort_cost t 0› 2. ‹⋀t. (⋀n. 0 ≤ t n) ⟹ 0 ≤ merge_sort_cost t 1› 3. ‹⋀n t. ⟦2 ≤ n; (⋀n. 0 ≤ t n) ⟹ 0 ≤ merge_sort_cost t (nat ⌊real n / 2⌋); (⋀n. 0 ≤ t n) ⟹ 0 ≤ merge_sort_cost t (nat ⌈real n / 2⌉); ⋀n. 0 ≤ t n⟧ ⟹ 0 ≤ merge_sort_cost t n› discuss goal 1*) apply (simp del: One_nat_def (*‹1 = Suc 0›*)) (*discuss goal 2*) apply (simp del: One_nat_def (*‹1 = Suc 0›*)) (*discuss goal 3*) apply (simp del: One_nat_def (*‹1 = Suc 0›*)) (*proven 3 subgoals*) . lemma "t ∈ Θ(λn. real n) ⟹ (⋀n. t n ≥ 0) ⟹ merge_sort_cost t ∈ Θ(λn. real n * ln (real n))" apply (master_theorem 2.3) (*goals: 1. ‹⋀x. ⟦t ∈ Θ(real); ⋀n. 0 ≤ t n; 0 ≤ x; x < 2⟧ ⟹ 0 ≤ merge_sort_cost t x› 2. ‹⋀x. ⟦t ∈ Θ(real); ⋀n. 0 ≤ t n; 2 ≤ x⟧ ⟹ merge_sort_cost t x = t x + (merge_sort_cost t (nat ⌊real x / 2⌋) + merge_sort_cost t (nat ⌈real x / 2⌉))› 3. ‹⋀x. ⟦t ∈ Θ(real); ⋀n. 0 ≤ t n; 2 ≤ x⟧ ⟹ 0 ≤ t x› 4. ‹⟦t ∈ Θ(real); ⋀n. 0 ≤ t n⟧ ⟹ t ∈ Θ(real)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*discuss goal 4*) apply simp (*proven 4 subgoals*) . subsection ‹Karatsuba multiplication› function karatsuba_cost :: "nat ⇒ real" where "karatsuba_cost 0 = 0" | "karatsuba_cost 1 = 1" | "n ≥ 2 ⟹ karatsuba_cost n = 3 * karatsuba_cost (nat ⌈real n / 2⌉) + real n" by force simp_all termination by akra_bazzi_termination simp_all lemma karatsuba_cost_nonneg[simp]: "karatsuba_cost n ≥ 0" apply (induction n rule: karatsuba_cost.induct (*‹⟦?P 0; ?P 1; ⋀n. ⟦2 ≤ n; ?P (nat ⌈real n / 2⌉)⟧ ⟹ ?P n⟧ ⟹ ?P ?a0.0›*)) (*goals: 1. ‹0 ≤ karatsuba_cost 0› 2. ‹0 ≤ karatsuba_cost 1› 3. ‹⋀n. ⟦2 ≤ n; 0 ≤ karatsuba_cost (nat ⌈real n / 2⌉)⟧ ⟹ 0 ≤ karatsuba_cost n› discuss goal 1*) apply (simp del: One_nat_def (*‹1 = Suc 0›*)) (*discuss goal 2*) apply (simp del: One_nat_def (*‹1 = Suc 0›*)) (*discuss goal 3*) apply (simp del: One_nat_def (*‹1 = Suc 0›*)) (*proven 3 subgoals*) . lemma "karatsuba_cost ∈ O(λn. real n powr log 2 3)" apply (master_theorem 1 p': 1) (*goals: 1. ‹⋀x. ⟦0 ≤ x; x < 2⟧ ⟹ 0 ≤ karatsuba_cost x› 2. ‹⋀x. 2 ≤ x ⟹ karatsuba_cost x = real x + 3 * karatsuba_cost (nat ⌈real x / 2⌉)› 3. ‹⋀x. 2 ≤ x ⟹ 0 ≤ real x› 4. ‹real ∈ O(λx. real x powr 1)› 5. ‹3 * (1 / 2) powr log 2 3 = 1› discuss goal 1*) apply (simp add: powr_divide (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ (?x / ?y) powr ?a = ?x powr ?a / ?y powr ?a›*)) (*discuss goal 2*) apply (simp add: powr_divide (*‹⟦(0::real) ≤ (?x::real); (0::real) ≤ (?y::real)⟧ ⟹ (?x / ?y) powr (?a::real) = ?x powr ?a / ?y powr ?a›*)) (*discuss goal 3*) apply (simp add: powr_divide (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ (?x / ?y) powr ?a = ?x powr ?a / ?y powr ?a›*)) (*discuss goal 4*) apply (simp add: powr_divide (*‹⟦(0::real) ≤ (?x::real); (0::real) ≤ (?y::real)⟧ ⟹ (?x / ?y) powr (?a::real) = ?x powr ?a / ?y powr ?a›*)) (*discuss goal 5*) apply (simp add: powr_divide (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ (?x / ?y) powr ?a = ?x powr ?a / ?y powr ?a›*)) (*proven 5 subgoals*) . lemma karatsuba_cost_pos: "n ≥ 1 ⟹ karatsuba_cost n > 0" apply (induction n rule: karatsuba_cost.induct (*‹⟦?P 0; ?P 1; ⋀n. ⟦2 ≤ n; ?P (nat ⌈real n / 2⌉)⟧ ⟹ ?P n⟧ ⟹ ?P ?a0.0›*)) (*goals: 1. ‹1 ≤ 0 ⟹ 0 < karatsuba_cost 0› 2. ‹1 ≤ 1 ⟹ 0 < karatsuba_cost 1› 3. ‹⋀n. ⟦2 ≤ n; 1 ≤ nat ⌈real n / 2⌉ ⟹ 0 < karatsuba_cost (nat ⌈real n / 2⌉); 1 ≤ n⟧ ⟹ 0 < karatsuba_cost n› discuss goal 1*) apply ((auto intro!: add_nonneg_pos (*‹⟦0 ≤ ?a; 0 < ?b⟧ ⟹ 0 < ?a + ?b›*) simp del: One_nat_def (*‹1 = Suc 0›*))[1]) (*discuss goal 2*) apply ((auto intro!: add_nonneg_pos (*‹⟦0 ≤ ?a; 0 < ?b⟧ ⟹ 0 < ?a + ?b›*) simp del: One_nat_def (*‹1 = Suc 0›*))[1]) (*discuss goal 3*) apply ((auto intro!: add_nonneg_pos (*‹⟦0 ≤ ?a; 0 < ?b⟧ ⟹ 0 < ?a + ?b›*) simp del: One_nat_def (*‹1 = Suc 0›*))[1]) (*proven 3 subgoals*) . lemma "karatsuba_cost ∈ Θ(λn. real n powr log 2 3)" using karatsuba_cost_pos (*‹(1::nat) ≤ (?n::nat) ⟹ (0::real) < karatsuba_cost ?n›*) apply (master_theorem 1 p': 1) (*goals: 1. ‹⋀x::nat. ⟦⋀n::nat. (1::nat) ≤ n ⟹ (0::real) < karatsuba_cost n; (0::nat) ≤ x; x < (2::nat)⟧ ⟹ (0::real) ≤ karatsuba_cost x› 2. ‹⋀x::nat. ⟦⋀n::nat. (1::nat) ≤ n ⟹ (0::real) < karatsuba_cost n; (2::nat) ≤ x⟧ ⟹ karatsuba_cost x = real x + (3::real) * karatsuba_cost (nat ⌈real x / (2::real)⌉)› 3. ‹⋀x::nat. ⟦⋀n::nat. (1::nat) ≤ n ⟹ (0::real) < karatsuba_cost n; (2::nat) ≤ x⟧ ⟹ (0::real) ≤ real x› 4. ‹(⋀n::nat. (1::nat) ≤ n ⟹ (0::real) < karatsuba_cost n) ⟹ real ∈ O(real)› 5. ‹(⋀n::nat. (1::nat) ≤ n ⟹ (0::real) < karatsuba_cost n) ⟹ ∀⇩F x::nat in sequentially. (0::real) < karatsuba_cost x› 6. ‹(⋀n::nat. (1::nat) ≤ n ⟹ (0::real) < karatsuba_cost n) ⟹ (3::real) * ((1::real) / (2::real)) powr log (2::real) (3::real) = (1::real)› discuss goal 1*) apply ((auto simp add: powr_divide (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ (?x / ?y) powr ?a = ?x powr ?a / ?y powr ?a›*) eventually_at_top_linorder (*‹eventually ?P at_top = (∃N. ∀n≥N. ?P n)›*))[1]) (*discuss goal 2*) apply ((auto simp add: powr_divide (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ (?x / ?y) powr ?a = ?x powr ?a / ?y powr ?a›*) eventually_at_top_linorder (*‹eventually ?P at_top = (∃N. ∀n≥N. ?P n)›*))[1]) (*discuss goal 3*) apply ((auto simp add: powr_divide (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ (?x / ?y) powr ?a = ?x powr ?a / ?y powr ?a›*) eventually_at_top_linorder (*‹eventually ?P at_top = (∃N. ∀n≥N. ?P n)›*))[1]) (*discuss goal 4*) apply ((auto simp add: powr_divide (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ (?x / ?y) powr ?a = ?x powr ?a / ?y powr ?a›*) eventually_at_top_linorder (*‹eventually ?P at_top = (∃N. ∀n≥N. ?P n)›*))[1]) (*discuss goal 5*) apply ((auto simp add: powr_divide (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ (?x / ?y) powr ?a = ?x powr ?a / ?y powr ?a›*) eventually_at_top_linorder (*‹eventually ?P at_top = (∃N. ∀n≥N. ?P n)›*))[1]) (*discuss goal 6*) apply ((auto simp add: powr_divide (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ (?x / ?y) powr ?a = ?x powr ?a / ?y powr ?a›*) eventually_at_top_linorder (*‹eventually ?P at_top = (∃N. ∀n≥N. ?P n)›*))[1]) (*proven 6 subgoals*) . subsection ‹Strassen matrix multiplication› function strassen_cost :: "nat ⇒ real" where "strassen_cost 0 = 0" | "strassen_cost 1 = 1" | "n ≥ 2 ⟹ strassen_cost n = 7 * strassen_cost (nat ⌈real n / 2⌉) + real (n^2)" by force simp_all termination by akra_bazzi_termination simp_all lemma strassen_cost_nonneg[simp]: "strassen_cost n ≥ 0" apply (induction n rule: strassen_cost.induct (*‹⟦?P 0; ?P 1; ⋀n. ⟦2 ≤ n; ?P (nat ⌈real n / 2⌉)⟧ ⟹ ?P n⟧ ⟹ ?P ?a0.0›*)) (*goals: 1. ‹(0::real) ≤ strassen_cost (0::nat)› 2. ‹(0::real) ≤ strassen_cost (1::nat)› 3. ‹⋀n::nat. ⟦(2::nat) ≤ n; (0::real) ≤ strassen_cost (nat ⌈real n / (2::real)⌉)⟧ ⟹ (0::real) ≤ strassen_cost n› discuss goal 1*) apply (simp del: One_nat_def (*‹1 = Suc 0›*)) (*discuss goal 2*) apply (simp del: One_nat_def (*‹1 = Suc 0›*)) (*discuss goal 3*) apply (simp del: One_nat_def (*‹1 = Suc 0›*)) (*proven 3 subgoals*) . lemma "strassen_cost ∈ O(λn. real n powr log 2 7)" apply (master_theorem 1 p': 2) (*goals: 1. ‹⋀x. ⟦0 ≤ x; x < 2⟧ ⟹ 0 ≤ strassen_cost x› 2. ‹⋀x. 2 ≤ x ⟹ strassen_cost x = real (x²) + 7 * strassen_cost (nat ⌈real x / 2⌉)› 3. ‹⋀x. 2 ≤ x ⟹ 0 ≤ real (x²)› 4. ‹(λn. (real n)²) ∈ O(λx. real x powr 2)› 5. ‹7 * (1 / 2) powr log 2 7 = 1› discuss goal 1*) apply ((auto simp: powr_divide (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ (?x / ?y) powr ?a = ?x powr ?a / ?y powr ?a›*) eventually_at_top_linorder (*‹eventually ?P at_top = (∃N. ∀n≥N. ?P n)›*))[1]) (*discuss goal 2*) apply ((auto simp: powr_divide (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ (?x / ?y) powr ?a = ?x powr ?a / ?y powr ?a›*) eventually_at_top_linorder (*‹eventually ?P at_top = (∃N. ∀n≥N. ?P n)›*))[1]) (*discuss goal 3*) apply ((auto simp: powr_divide (*‹⟦(0::real) ≤ (?x::real); (0::real) ≤ (?y::real)⟧ ⟹ (?x / ?y) powr (?a::real) = ?x powr ?a / ?y powr ?a›*) eventually_at_top_linorder (*‹eventually (?P::?'a ⇒ bool) at_top = (∃N::?'a. ∀n≥N. ?P n)›*))[1]) (*discuss goal 4*) apply ((auto simp: powr_divide (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ (?x / ?y) powr ?a = ?x powr ?a / ?y powr ?a›*) eventually_at_top_linorder (*‹eventually ?P at_top = (∃N. ∀n≥N. ?P n)›*))[1]) (*discuss goal 5*) apply ((auto simp: powr_divide (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ (?x / ?y) powr ?a = ?x powr ?a / ?y powr ?a›*) eventually_at_top_linorder (*‹eventually ?P at_top = (∃N. ∀n≥N. ?P n)›*))[1]) (*proven 5 subgoals*) . lemma strassen_cost_pos: "n ≥ 1 ⟹ strassen_cost n > 0" apply (cases n rule: strassen_cost.cases (*‹⟦?x = 0 ⟹ ?P; ?x = 1 ⟹ ?P; ⋀n. ⟦2 ≤ n; ?x = n⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹⟦1 ≤ n; n = 0⟧ ⟹ 0 < strassen_cost n› 2. ‹⟦1 ≤ n; n = 1⟧ ⟹ 0 < strassen_cost n› 3. ‹⋀na. ⟦1 ≤ n; 2 ≤ na; n = na⟧ ⟹ 0 < strassen_cost n› discuss goal 1*) apply (simp add: add_nonneg_pos (*‹⟦0 ≤ ?a; 0 < ?b⟧ ⟹ 0 < ?a + ?b›*) del: One_nat_def (*‹1 = Suc 0›*)) (*discuss goal 2*) apply (simp add: add_nonneg_pos (*‹⟦0 ≤ ?a; 0 < ?b⟧ ⟹ 0 < ?a + ?b›*) del: One_nat_def (*‹1 = Suc 0›*)) (*discuss goal 3*) apply (simp add: add_nonneg_pos (*‹⟦0 ≤ ?a; 0 < ?b⟧ ⟹ 0 < ?a + ?b›*) del: One_nat_def (*‹1 = Suc 0›*)) (*proven 3 subgoals*) . lemma "strassen_cost ∈ Θ(λn. real n powr log 2 7)" using strassen_cost_pos (*‹1 ≤ ?n ⟹ 0 < strassen_cost ?n›*) apply (master_theorem 1 p': 2) (*goals: 1. ‹⋀x::nat. ⟦⋀n::nat. (1::nat) ≤ n ⟹ (0::real) < strassen_cost n; (0::nat) ≤ x; x < (2::nat)⟧ ⟹ (0::real) ≤ strassen_cost x› 2. ‹⋀x::nat. ⟦⋀n::nat. (1::nat) ≤ n ⟹ (0::real) < strassen_cost n; (2::nat) ≤ x⟧ ⟹ strassen_cost x = real (x²) + (7::real) * strassen_cost (nat ⌈real x / (2::real)⌉)› 3. ‹⋀x::nat. ⟦⋀n::nat. (1::nat) ≤ n ⟹ (0::real) < strassen_cost n; (2::nat) ≤ x⟧ ⟹ (0::real) ≤ real (x²)› 4. ‹(⋀n::nat. (1::nat) ≤ n ⟹ (0::real) < strassen_cost n) ⟹ (λn::nat. (real n)²) ∈ O(λx::nat. (real x)²)› 5. ‹(⋀n::nat. (1::nat) ≤ n ⟹ (0::real) < strassen_cost n) ⟹ ∀⇩F x::nat in sequentially. (0::real) < strassen_cost x› 6. ‹(⋀n::nat. (1::nat) ≤ n ⟹ (0::real) < strassen_cost n) ⟹ (7::real) * ((1::real) / (2::real)) powr log (2::real) (7::real) = (1::real)› discuss goal 1*) apply ((auto simp: powr_divide (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ (?x / ?y) powr ?a = ?x powr ?a / ?y powr ?a›*) eventually_at_top_linorder (*‹eventually ?P at_top = (∃N. ∀n≥N. ?P n)›*))[1]) (*discuss goal 2*) apply ((auto simp: powr_divide (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ (?x / ?y) powr ?a = ?x powr ?a / ?y powr ?a›*) eventually_at_top_linorder (*‹eventually ?P at_top = (∃N. ∀n≥N. ?P n)›*))[1]) (*discuss goal 3*) apply ((auto simp: powr_divide (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ (?x / ?y) powr ?a = ?x powr ?a / ?y powr ?a›*) eventually_at_top_linorder (*‹eventually ?P at_top = (∃N. ∀n≥N. ?P n)›*))[1]) (*discuss goal 4*) apply ((auto simp: powr_divide (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ (?x / ?y) powr ?a = ?x powr ?a / ?y powr ?a›*) eventually_at_top_linorder (*‹eventually ?P at_top = (∃N. ∀n≥N. ?P n)›*))[1]) (*discuss goal 5*) apply ((auto simp: powr_divide (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ (?x / ?y) powr ?a = ?x powr ?a / ?y powr ?a›*) eventually_at_top_linorder (*‹eventually ?P at_top = (∃N. ∀n≥N. ?P n)›*))[1]) (*discuss goal 6*) apply ((auto simp: powr_divide (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ (?x / ?y) powr ?a = ?x powr ?a / ?y powr ?a›*) eventually_at_top_linorder (*‹eventually ?P at_top = (∃N. ∀n≥N. ?P n)›*))[1]) (*proven 6 subgoals*) . subsection ‹Deterministic select› (* This is not possible with the standard Master theorem from literature *) function select_cost :: "nat ⇒ real" where "n ≤ 20 ⟹ select_cost n = 0" | "n > 20 ⟹ select_cost n = select_cost (nat ⌊real n / 5⌋) + select_cost (nat ⌊7 * real n / 10⌋ + 6) + 12 * real n / 5" by force simp_all termination by akra_bazzi_termination simp_all lemma "select_cost ∈ Θ(λn. real n)" apply (master_theorem 3) (*goals: 1. ‹⋀x::nat. ⟦(0::nat) ≤ x; x < Suc (20::nat)⟧ ⟹ (0::real) ≤ select_cost x› 2. ‹⋀x::nat. Suc (20::nat) ≤ x ⟹ select_cost x = (12::real) * real x / (5::real) + (select_cost (nat ⌊real x / (5::real)⌋) + select_cost (nat ⌊(7::real) * real x / (10::real)⌋ + (6::nat)))› 3. ‹⋀x::nat. Suc (20::nat) ≤ x ⟹ (0::real) ≤ (12::real) * real x / (5::real)› 4. ‹(0::real) ≤ (7::real) / (10::real) * real (Suc (20::nat)) + (6::real)› 5. ‹(6::real) < ((1::real) - (7::real) / (10::real)) * real (Suc (20::nat))› 6. ‹(λn::nat. (12::real) * real n / (5::real)) ∈ Θ(real)› 7. ‹((1::real) / (5::real)) powr (1::real) + ((7::real) / (10::real)) powr (1::real) < (1::real)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*proven 7 subgoals*) . subsection ‹Decreasing function› function dec_cost :: "nat ⇒ real" where "n ≤ 2 ⟹ dec_cost n = 1" | "n > 2 ⟹ dec_cost n = 0.5*dec_cost (nat ⌊real n / 2⌋) + 1 / real n" by force simp_all termination by akra_bazzi_termination simp_all lemma "dec_cost ∈ Θ(λx::nat. ln x / x)" apply (master_theorem 2.3) (*goals: 1. ‹⋀x. ⟦0 ≤ x; x < Suc 2⟧ ⟹ 0 ≤ dec_cost x› 2. ‹⋀x. Suc 2 ≤ x ⟹ dec_cost x = 1 / real x + 5 / 10 * dec_cost (nat ⌊real x / 2⌋)› 3. ‹⋀x. Suc 2 ≤ x ⟹ 0 ≤ 1 / real x› 4. ‹(λn. 1 / real n) ∈ Θ(λx. 1 / real x)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*discuss goal 4*) apply simp (*proven 4 subgoals*) . subsection ‹Example taken from Drmota and Szpakowski› function drmota1 :: "nat ⇒ real" where "n < 20 ⟹ drmota1 n = 1" | "n ≥ 20 ⟹ drmota1 n = 2 * drmota1 (nat ⌊real n/2⌋) + 8/9 * drmota1 (nat ⌊3*real n/4⌋) + real n^2 / ln (real n)" by force simp_all termination by akra_bazzi_termination simp_all lemma "drmota1 ∈ Θ(λn::real. n^2 * ln (ln n))" apply (master_theorem 2.2) (*goals: 1. ‹⋀x::nat. ⟦(0::nat) ≤ x; x < (20::nat)⟧ ⟹ (0::real) ≤ drmota1 x› 2. ‹⋀x::nat. (20::nat) ≤ x ⟹ drmota1 x = (real x)² / ln (real x) + ((2::real) * drmota1 (nat ⌊real x / (2::real)⌋) + (8::real) / (9::real) * drmota1 (nat ⌊(3::real) * real x / (4::real)⌋))› 3. ‹⋀x::nat. (20::nat) ≤ x ⟹ (0::real) ≤ (real x)² / ln (real x)› 4. ‹(λn::nat. (real n)² / ln (real n)) ∈ Θ(λx::nat. (real x)² / ln (real x))› 5. ‹(2::real) * ((1::real) / (2::real)) powr (2::real) + (8::real) / (9::real) * ((3::real) / (4::real)) powr (2::real) = (1::real)› discuss goal 1*) apply (simp add: power_divide (*‹(?a / ?b) ^ ?n = ?a ^ ?n / ?b ^ ?n›*)) (*discuss goal 2*) apply (simp add: power_divide (*‹(?a / ?b) ^ ?n = ?a ^ ?n / ?b ^ ?n›*)) (*discuss goal 3*) apply (simp add: power_divide (*‹(?a / ?b) ^ ?n = ?a ^ ?n / ?b ^ ?n›*)) (*discuss goal 4*) apply (simp add: power_divide (*‹((?a::?'a) / (?b::?'a)) ^ (?n::nat) = ?a ^ ?n / ?b ^ ?n›*)) (*discuss goal 5*) apply (simp add: power_divide (*‹(?a / ?b) ^ ?n = ?a ^ ?n / ?b ^ ?n›*)) (*proven 5 subgoals*) . function drmota2 :: "nat ⇒ real" where "n < 20 ⟹ drmota2 n = 1" | "n ≥ 20 ⟹ drmota2 n = 1/3 * drmota2 (nat ⌊real n/3 + 1/2⌋) + 2/3 * drmota2 (nat ⌊2*real n/3 - 1/2⌋) + 1" by force simp_all termination by akra_bazzi_termination simp_all lemma "drmota2 ∈ Θ(λx. ln (real x))" apply master_theorem (*goals: 1. ‹⋀x. ⟦0 ≤ x; x < 20⟧ ⟹ 0 ≤ drmota2 x› 2. ‹⋀x. 20 ≤ x ⟹ drmota2 x = 1 + (1 / 3 * drmota2 (nat ⌊real x / 3 + 1 / 2⌋) + 2 / 3 * drmota2 (nat ⌊2 * real x / 3 - 1 / 2⌋))› 3. ‹⋀x. 20 ≤ x ⟹ 0 ≤ 1› 4. ‹0 ≤ 1 / 3 * 20 + 1 / 2› 5. ‹0 ≤ 2 / 3 * 20 - 1 / 2› 6. ‹0 < 1 / 2 + (1 - 2 / 3) * 20› 7. ‹(λn. 1) ∈ Θ(λx. 1)› 8. ‹1 / 3 * (1 / 3) powr 0 + 2 / 3 * (2 / 3) powr 0 = 1› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*discuss goal 4*) apply simp (*discuss goal 5*) apply simp (*discuss goal 6*) apply simp (*discuss goal 7*) apply simp (*discuss goal 8*) apply simp (*proven 8 subgoals*) . (* Average phrase length of Boncelet arithmetic coding. See Drmota and Szpankowski. *) lemma boncelet_phrase_length: fixes p δ :: real assumes p: "p > 0" "p < 1" and δ: "δ > 0" "δ < 1" "2*p + δ < 2" fixes d :: "nat ⇒ real" defines "q ≡ 1 - p" assumes d_nonneg: "⋀n. d n ≥ 0" assumes d_rec: "⋀n. n ≥ 2 ⟹ d n = 1 + p * d (nat ⌊p * real n + δ⌋) + q * d (nat ⌊q * real n - δ⌋)" shows "d ∈ Θ(λx. ln x)" using assms (*‹0 < p› ‹p < 1› ‹0 < δ› ‹(δ::real) < (1::real)› ‹(2::real) * (p::real) + (δ::real) < (2::real)› ‹q ≡ 1 - p› ‹0 ≤ d ?n› ‹2 ≤ ?n ⟹ d ?n = 1 + p * d (nat ⌊p * real ?n + δ⌋) + q * d (nat ⌊q * real ?n - δ⌋)›*) apply (master_theorem recursion: d_rec) (*goals: 1. ‹⋀x. ⟦0 < p; p < 1; 0 < δ; δ < 1; 2 * p + δ < 2; q ≡ 1 - p; ⋀n. 0 ≤ d n; ⋀n. 2 ≤ n ⟹ d n = 1 + p * d (nat ⌊p * real n + δ⌋) + q * d (nat ⌊q * real n - δ⌋); 0 ≤ x; x < 2⟧ ⟹ 0 ≤ d x› 2. ‹⋀x. ⟦0 < p; p < 1; 0 < δ; δ < 1; 2 * p + δ < 2; q ≡ 1 - p; ⋀n. 0 ≤ d n; ⋀n. 2 ≤ n ⟹ d n = 1 + p * d (nat ⌊p * real n + δ⌋) + q * d (nat ⌊q * real n - δ⌋); 2 ≤ x⟧ ⟹ d x = 1 + (p * d (nat ⌊p * real x + δ⌋) + q * d (nat ⌊q * real x - δ⌋))› 3. ‹⋀x. ⟦0 < p; p < 1; 0 < δ; δ < 1; 2 * p + δ < 2; q ≡ 1 - p; ⋀n. 0 ≤ d n; ⋀n. 2 ≤ n ⟹ d n = 1 + p * d (nat ⌊p * real n + δ⌋) + q * d (nat ⌊q * real n - δ⌋); 2 ≤ x⟧ ⟹ 0 ≤ 1› 4. ‹⟦0 < p; p < 1; 0 < δ; δ < 1; 2 * p + δ < 2; q ≡ 1 - p; ⋀n. 0 ≤ d n; ⋀n. 2 ≤ n ⟹ d n = 1 + p * d (nat ⌊p * real n + δ⌋) + q * d (nat ⌊q * real n - δ⌋)⟧ ⟹ 0 ≤ p› 5. ‹⟦0 < p; p < 1; 0 < δ; δ < 1; 2 * p + δ < 2; q ≡ 1 - p; ⋀n. 0 ≤ d n; ⋀n. 2 ≤ n ⟹ d n = 1 + p * d (nat ⌊p * real n + δ⌋) + q * d (nat ⌊q * real n - δ⌋)⟧ ⟹ 0 ≤ q› 6. ‹⟦0 < p; p < 1; 0 < δ; δ < 1; 2 * p + δ < 2; q ≡ 1 - p; ⋀n. 0 ≤ d n; ⋀n. 2 ≤ n ⟹ d n = 1 + p * d (nat ⌊p * real n + δ⌋) + q * d (nat ⌊q * real n - δ⌋)⟧ ⟹ 0 < p ∨ 0 < q› 7. ‹⟦0 < p; p < 1; 0 < δ; δ < 1; 2 * p + δ < 2; q ≡ 1 - p; ⋀n. 0 ≤ d n; ⋀n. 2 ≤ n ⟹ d n = 1 + p * d (nat ⌊p * real n + δ⌋) + q * d (nat ⌊q * real n - δ⌋)⟧ ⟹ p ∈ {0<..<1}› 8. ‹⟦0 < p; p < 1; 0 < δ; δ < 1; 2 * p + δ < 2; q ≡ 1 - p; ⋀n. 0 ≤ d n; ⋀n. 2 ≤ n ⟹ d n = 1 + p * d (nat ⌊p * real n + δ⌋) + q * d (nat ⌊q * real n - δ⌋)⟧ ⟹ q ∈ {0<..<1}› 9. ‹⟦0 < p; p < 1; 0 < δ; δ < 1; 2 * p + δ < 2; q ≡ 1 - p; ⋀n. 0 ≤ d n; ⋀n. 2 ≤ n ⟹ d n = 1 + p * d (nat ⌊p * real n + δ⌋) + q * d (nat ⌊q * real n - δ⌋)⟧ ⟹ 0 < p› 10. ‹⟦0 < p; p < 1; 0 < δ; δ < 1; 2 * p + δ < 2; q ≡ 1 - p; ⋀n. 0 ≤ d n; ⋀n. 2 ≤ n ⟹ d n = 1 + p * d (nat ⌊p * real n + δ⌋) + q * d (nat ⌊q * real n - δ⌋)⟧ ⟹ p < 1› 11. ‹⟦0 < p; p < 1; 0 < δ; δ < 1; 2 * p + δ < 2; q ≡ 1 - p; ⋀n. 0 ≤ d n; ⋀n. 2 ≤ n ⟹ d n = 1 + p * d (nat ⌊p * real n + δ⌋) + q * d (nat ⌊q * real n - δ⌋)⟧ ⟹ 0 ≤ p * 2 + δ› 12. ‹⟦0 < p; p < 1; 0 < δ; δ < 1; 2 * p + δ < 2; q ≡ 1 - p; ⋀n. 0 ≤ d n; ⋀n. 2 ≤ n ⟹ d n = 1 + p * d (nat ⌊p * real n + δ⌋) + q * d (nat ⌊q * real n - δ⌋)⟧ ⟹ δ < (1 - p) * 2› 13. ‹⟦0 < p; p < 1; 0 < δ; δ < 1; 2 * p + δ < 2; q ≡ 1 - p; ⋀n. 0 ≤ d n; ⋀n. 2 ≤ n ⟹ d n = 1 + p * d (nat ⌊p * real n + δ⌋) + q * d (nat ⌊q * real n - δ⌋)⟧ ⟹ 0 < q› 14. ‹⟦0 < p; p < 1; 0 < δ; δ < 1; 2 * p + δ < 2; q ≡ 1 - p; ⋀n. 0 ≤ d n; ⋀n. 2 ≤ n ⟹ d n = 1 + p * d (nat ⌊p * real n + δ⌋) + q * d (nat ⌊q * real n - δ⌋)⟧ ⟹ q < 1› 15. ‹⟦0 < p; p < 1; 0 < δ; δ < 1; 2 * p + δ < 2; q ≡ 1 - p; ⋀n. 0 ≤ d n; ⋀n. 2 ≤ n ⟹ d n = 1 + p * d (nat ⌊p * real n + δ⌋) + q * d (nat ⌊q * real n - δ⌋)⟧ ⟹ 0 ≤ q * 2 - δ› 16. ‹⟦0 < p; p < 1; 0 < δ; δ < 1; 2 * p + δ < 2; q ≡ 1 - p; ⋀n. 0 ≤ d n; ⋀n. 2 ≤ n ⟹ d n = 1 + p * d (nat ⌊p * real n + δ⌋) + q * d (nat ⌊q * real n - δ⌋)⟧ ⟹ 0 < δ + (1 - q) * 2› 17. ‹⟦0 < p; p < 1; 0 < δ; δ < 1; 2 * p + δ < 2; q ≡ 1 - p; ⋀n. 0 ≤ d n; ⋀n. 2 ≤ n ⟹ d n = 1 + p * d (nat ⌊p * real n + δ⌋) + q * d (nat ⌊q * real n - δ⌋)⟧ ⟹ (λn. 1) ∈ Θ(λx. 1)› 18. ‹⟦0 < p; p < 1; 0 < δ; δ < 1; 2 * p + δ < 2; q ≡ 1 - p; ⋀n. 0 ≤ d n; ⋀n. 2 ≤ n ⟹ d n = 1 + p * d (nat ⌊p * real n + δ⌋) + q * d (nat ⌊q * real n - δ⌋)⟧ ⟹ p * p powr 0 + q * q powr 0 = 1› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*discuss goal 4*) apply simp (*discuss goal 5*) apply simp (*discuss goal 6*) apply simp (*discuss goal 7*) apply simp (*discuss goal 8*) apply simp (*discuss goal 9*) apply simp (*discuss goal 10*) apply simp (*discuss goal 11*) apply simp (*discuss goal 12*) apply simp (*discuss goal 13*) apply simp (*discuss goal 14*) apply simp (*discuss goal 15*) apply simp (*discuss goal 16*) apply simp (*discuss goal 17*) apply simp (*discuss goal 18*) apply simp (*proven 18 subgoals*) . subsection ‹Transcendental exponents› (* Certain number-theoretic conjectures would imply that if all the parameters are rational, the Akra-Bazzi parameter is either rational or transcendental. That makes this case probably transcendental *) function foo_cost :: "nat ⇒ real" where "n < 200 ⟹ foo_cost n = 0" | "n ≥ 200 ⟹ foo_cost n = foo_cost (nat ⌊real n / 3⌋) + foo_cost (nat ⌊3 * real n / 4⌋ + 42) + real n" by force simp_all termination by akra_bazzi_termination simp_all lemma foo_cost_nonneg [simp]: "foo_cost n ≥ 0" apply (induction n rule: foo_cost.induct (*‹⟦⋀n::nat. n < (200::nat) ⟹ (?P::nat ⇒ bool) n; ⋀n::nat. ⟦(200::nat) ≤ n; ?P (nat ⌊real n / (3::real)⌋); ?P (nat ⌊(3::real) * real n / (4::real)⌋ + (42::nat))⟧ ⟹ ?P n⟧ ⟹ ?P (?a0.0::nat)›*)) (*goals: 1. ‹⋀n. n < 200 ⟹ 0 ≤ foo_cost n› 2. ‹⋀n. ⟦200 ≤ n; 0 ≤ foo_cost (nat ⌊real n / 3⌋); 0 ≤ foo_cost (nat ⌊3 * real n / 4⌋ + 42)⟧ ⟹ 0 ≤ foo_cost n› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma "foo_cost ∈ Θ(λn. real n powr akra_bazzi_exponent [1,1] [1/3,3/4])" proof (master_theorem 1 p': 1) (*goals: 1. ‹⋀x. ⟦0 ≤ x; x < 200⟧ ⟹ 0 ≤ foo_cost x› 2. ‹⋀x. 200 ≤ x ⟹ foo_cost x = real x + (foo_cost (nat ⌊real x / 3⌋) + foo_cost (nat ⌊3 * real x / 4⌋ + 42))› 3. ‹⋀x. 200 ≤ x ⟹ 0 ≤ real x› 4. ‹real ∈ O(real)› 5. ‹1 < (1 / 3) powr 1 + (3 / 4) powr 1› 6. ‹∀⇩F x in sequentially. 0 < foo_cost x›*) have "∀n≥200. foo_cost n > 0" by (simp add: add_nonneg_pos (*‹⟦0 ≤ ?a; 0 < ?b⟧ ⟹ 0 < ?a + ?b›*)) thus "eventually (λn. foo_cost n > 0) at_top" unfolding eventually_at_top_linorder (*goal: ‹∃N. ∀n≥N. 0 < foo_cost n›*) by blast qed (simp_all) (*solves the remaining goals: 1. ‹⋀x. ⟦0 ≤ x; x < 200⟧ ⟹ 0 ≤ foo_cost x› 2. ‹⋀x. 200 ≤ x ⟹ foo_cost x = real x + (foo_cost (nat ⌊real x / 3⌋) + foo_cost (nat ⌊3 * real x / 4⌋ + 42))› 3. ‹⋀x. 200 ≤ x ⟹ 0 ≤ real x› 4. ‹real ∈ O(real)› 5. ‹1 < (1 / 3) powr 1 + (3 / 4) powr 1›*) lemma "akra_bazzi_exponent [1,1] [1/3,3/4] ∈ {1.1519623..1.1519624}" by (msorry) subsection ‹Functions in locale contexts› locale det_select = fixes b :: real assumes b: "b > 0" "b < 7/10" begin function select_cost' :: "nat ⇒ real" where "n ≤ 20 ⟹ select_cost' n = 0" | "n > 20 ⟹ select_cost' n = select_cost' (nat ⌊real n / 5⌋) + select_cost' (nat ⌊b * real n⌋ + 6) + 6 * real n + 5" by force simp_all termination using b by akra_bazzi_termination simp_all lemma "a ≥ 0 ⟹ select_cost' ∈ Θ(λn. real n)" using b (*‹0 < b› ‹b < 7 / 10›*) apply (master_theorem 3) (*goals: 1. ‹⋀x::nat. ⟦(0::'a) ≤ (a::'a); (0::real) < (b::real); b < (7::real) / (10::real); (0::nat) ≤ x; x < Suc (20::nat)⟧ ⟹ (0::real) ≤ select_cost' x› 2. ‹⋀x::nat. ⟦(0::'a) ≤ (a::'a); (0::real) < (b::real); b < (7::real) / (10::real); Suc (20::nat) ≤ x⟧ ⟹ select_cost' x = (6::real) * real x + (5::real) + (select_cost' (nat ⌊real x / (5::real)⌋) + select_cost' (nat ⌊b * real x⌋ + (6::nat)))› 3. ‹⋀x::nat. ⟦(0::'a) ≤ (a::'a); (0::real) < (b::real); b < (7::real) / (10::real); Suc (20::nat) ≤ x⟧ ⟹ (0::real) ≤ (6::real) * real x + (5::real)› 4. ‹⟦(0::'a) ≤ (a::'a); (0::real) < (b::real); b < (7::real) / (10::real)⟧ ⟹ b ∈ {0::real<..<1::real}› 5. ‹⟦(0::'a) ≤ (a::'a); (0::real) < (b::real); b < (7::real) / (10::real)⟧ ⟹ (0::real) < b› 6. ‹⟦(0::'a) ≤ (a::'a); (0::real) < (b::real); b < (7::real) / (10::real)⟧ ⟹ b < (1::real)› 7. ‹⟦(0::'a) ≤ (a::'a); (0::real) < (b::real); b < (7::real) / (10::real)⟧ ⟹ (0::real) ≤ b * real (Suc (20::nat)) + (6::real)› 8. ‹⟦(0::'a) ≤ (a::'a); (0::real) < (b::real); b < (7::real) / (10::real)⟧ ⟹ (6::real) < ((1::real) - b) * real (Suc (20::nat))› 9. ‹⟦(0::'a) ≤ (a::'a); (0::real) < (b::real); b < (7::real) / (10::real)⟧ ⟹ (λn::nat. (6::real) * real n + (5::real)) ∈ Θ(real)› 10. ‹⟦(0::'a) ≤ (a::'a); (0::real) < (b::real); b < (7::real) / (10::real)⟧ ⟹ ((1::real) / (5::real)) powr (1::real) + b powr (1::real) < (1::real)› discuss goal 1*) apply force (*discuss goal 2*) apply force (*discuss goal 3*) apply force (*discuss goal 4*) apply force (*discuss goal 5*) apply force (*discuss goal 6*) apply force (*discuss goal 7*) apply force (*discuss goal 8*) apply force (*discuss goal 9*) apply force (*discuss goal 10*) apply force (*proven 10 subgoals*) . end subsection ‹Non-curried functions› (* Note: either a or b could be seen as recursion variables. *) function baz_cost :: "nat × nat ⇒ real" where "n ≤ 2 ⟹ baz_cost (a, n) = 0" | "n > 2 ⟹ baz_cost (a, n) = 3 * baz_cost (a, nat ⌊real n / 2⌋) + real a" by force simp_all termination by akra_bazzi_termination simp_all lemma baz_cost_nonneg [simp]: "a ≥ 0 ⟹ baz_cost (a, n) ≥ 0" apply (induction a n rule: baz_cost.induct[split_format (complete)] (*‹⟦⋀n a. n ≤ 2 ⟹ ?P a n; ⋀n a. ⟦2 < n; ?P a (nat ⌊real n / 2⌋)⟧ ⟹ ?P a n⟧ ⟹ ?P ?a0a ?a0b›*)) (*goals: 1. ‹⋀(n::nat) a::nat. ⟦n ≤ (2::nat); (0::nat) ≤ a⟧ ⟹ (0::real) ≤ baz_cost (a, n)› 2. ‹⋀(n::nat) a::nat. ⟦(2::nat) < n; (0::nat) ≤ a ⟹ (0::real) ≤ baz_cost (a, nat ⌊real n / (2::real)⌋); (0::nat) ≤ a⟧ ⟹ (0::real) ≤ baz_cost (a, n)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma assumes "a > 0" shows "(λx. baz_cost (a, x)) ∈ Θ(λx. x powr log 2 3)" proof (master_theorem 1 p': 0) (*goals: 1. ‹⋀x::nat. ⟦(0::nat) ≤ x; x < Suc (2::nat)⟧ ⟹ (0::real) ≤ baz_cost (a::nat, x)› 2. ‹⋀x::nat. Suc (2::nat) ≤ x ⟹ baz_cost (a::nat, x) = real a + (3::real) * baz_cost (a, nat ⌊real x / (2::real)⌋)› 3. ‹⋀x::nat. Suc (2::nat) ≤ x ⟹ (0::real) ≤ real (a::nat)› 4. ‹(λn::nat. real (a::nat)) ∈ O(λx::nat. 1::real)› 5. ‹∀⇩F x::nat in sequentially. (0::real) < baz_cost (a::nat, x)› 6. ‹(3::real) * ((1::real) / (2::real)) powr log (2::real) (3::real) = (1::real)›*) from assms (*‹0 < a›*) have "∀x≥3. baz_cost (a, x) > 0" by (auto intro: add_nonneg_pos (*‹⟦0 ≤ ?a; 0 < ?b⟧ ⟹ 0 < ?a + ?b›*)) thus "eventually (λx. baz_cost (a, x) > 0) at_top" by (force simp: eventually_at_top_linorder (*‹eventually ?P at_top = (∃N. ∀n≥N. ?P n)›*)) qed (insert assms (*‹0 < a›*), simp_all add: powr_divide) (*solves the remaining goals: 1. ‹⋀x. ⟦0 ≤ x; x < Suc 2⟧ ⟹ 0 ≤ baz_cost (a, x)› 2. ‹⋀x. Suc 2 ≤ x ⟹ baz_cost (a, x) = real a + 3 * baz_cost (a, nat ⌊real x / 2⌋)› 3. ‹⋀x. Suc 2 ≤ x ⟹ 0 ≤ real a› 4. ‹(λn. real a) ∈ O(λx. 1)› 5. ‹3 * (1 / 2) powr log 2 3 = 1›*) (* Non-"Akra-Bazzi" variables may even be modified without impacting the termination proof. However, the Akra-Bazzi theorem and the Master theorem itself do not apply anymore, because bar_cost cannot be seen as a recursive function with one parameter *) function bar_cost :: "nat × nat ⇒ real" where "n ≤ 2 ⟹ bar_cost (a, n) = 0" | "n > 2 ⟹ bar_cost (a, n) = 3 * bar_cost (2 * a, nat ⌊real n / 2⌋) + real a" by force simp_all termination by akra_bazzi_termination simp_all subsection ‹Ham-sandwich trees› (* f(n) = f(n/4) + f(n/2) + 1 *) function ham_sandwich_cost :: "nat ⇒ real" where "n < 4 ⟹ ham_sandwich_cost n = 1" | "n ≥ 4 ⟹ ham_sandwich_cost n = ham_sandwich_cost (nat ⌊n/4⌋) + ham_sandwich_cost (nat ⌊n/2⌋) + 1" by force simp_all termination by akra_bazzi_termination simp_all lemma ham_sandwich_cost_pos [simp]: "ham_sandwich_cost n > 0" apply (induction n rule: ham_sandwich_cost.induct (*‹⟦⋀n. n < 4 ⟹ ?P n; ⋀n. ⟦4 ≤ n; ?P (nat ⌊real n / 4⌋); ?P (nat ⌊real n / 2⌋)⟧ ⟹ ?P n⟧ ⟹ ?P ?a0.0›*)) (*goals: 1. ‹⋀n. n < 4 ⟹ 0 < ham_sandwich_cost n› 2. ‹⋀n. ⟦4 ≤ n; 0 < ham_sandwich_cost (nat ⌊real n / 4⌋); 0 < ham_sandwich_cost (nat ⌊real n / 2⌋)⟧ ⟹ 0 < ham_sandwich_cost n› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . text ‹The golden ratio› definition "φ = ((1 + sqrt 5) / 2 :: real)" lemma φ_pos [simp]: "φ > 0" and φ_nonneg [simp]: "φ ≥ 0" and φ_nonzero [simp]: "φ ≠ 0" proof (-) (*goals: 1. ‹0 < φ› 2. ‹0 ≤ φ› 3. ‹φ ≠ 0›*) show "φ > 0" unfolding "φ_def" (*goal: ‹(0::real) < ((1::real) + sqrt (5::real)) / (2::real)›*) by (simp add: add_pos_nonneg (*‹⟦(0::?'a::ordered_comm_monoid_add) < (?a::?'a::ordered_comm_monoid_add); (0::?'a::ordered_comm_monoid_add) ≤ (?b::?'a::ordered_comm_monoid_add)⟧ ⟹ (0::?'a::ordered_comm_monoid_add) < ?a + ?b›*)) thus "φ ≥ 0" "φ ≠ 0" apply - (*goals: 1. ‹(0::real) < φ ⟹ (0::real) ≤ φ› 2. ‹(0::real) < φ ⟹ φ ≠ (0::real)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . qed lemma "ham_sandwich_cost ∈ Θ(λn. n powr (log 2 φ))" proof (master_theorem 1 p': 0) (*goals: 1. ‹⋀x::nat. ⟦(0::nat) ≤ x; x < (4::nat)⟧ ⟹ (0::real) ≤ ham_sandwich_cost x› 2. ‹⋀x::nat. (4::nat) ≤ x ⟹ ham_sandwich_cost x = (1::real) + (ham_sandwich_cost (nat ⌊real x / (4::real)⌋) + ham_sandwich_cost (nat ⌊real x / (2::real)⌋))› 3. ‹⋀x::nat. (4::nat) ≤ x ⟹ (0::real) ≤ (1::real)› 4. ‹(0::real) < ((1::real) - (1::real) / (4::real)) * (4::real)› 5. ‹(λn::nat. 1::real) ∈ O(λx::nat. 1::real)› 6. ‹∀⇩F x::nat in sequentially. (0::real) < ham_sandwich_cost x› 7. ‹((1::real) / (4::real)) powr log (2::real) φ + ((1::real) / (2::real)) powr log (2::real) φ = (1::real)›*) have "(1 / 4) powr log 2 φ + (1 / 2) powr log 2 φ = inverse (2 powr log 2 φ)^2 + inverse (2 powr log 2 φ)" by (simp add: powr_divide (*‹⟦(0::real) ≤ (?x::real); (0::real) ≤ (?y::real)⟧ ⟹ (?x / ?y) powr (?a::real) = ?x powr ?a / ?y powr ?a›*) field_simps (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)› ‹(?a::?'a) * (?b::?'a) * (?c::?'a) = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)› ‹(?a::?'a) - (?b::?'a) - (?c::?'a) = ?a - (?b + ?c)› ‹(?a::?'a) + ((?b::?'a) - (?c::?'a)) = ?a + ?b - ?c› ‹((?a::?'a) - (?b::?'a) = (?c::?'a)) = (?a = ?c + ?b)› ‹((?a::?'a) = (?c::?'a) - (?b::?'a)) = (?a + ?b = ?c)› ‹(?a::?'a) - ((?b::?'a) - (?c::?'a)) = ?a + ?c - ?b› ‹(?a::?'a) - (?b::?'a) + (?c::?'a) = ?a + ?c - ?b› and more 77 facts*) powr_powr (*‹((?x::real) powr (?a::real)) powr (?b::real) = ?x powr (?a * ?b)›*) power2_eq_square (*‹(?a::?'a)² = ?a * ?a›*) powr_mult[symmetric] (*‹⟦(0::real) ≤ (?x::real); (0::real) ≤ (?y::real)⟧ ⟹ ?x powr (?a::real) * ?y powr ?a = (?x * ?y) powr ?a›*) del: powr_log_cancel (*‹⟦(0::real) < (?a::real); ?a ≠ (1::real); (0::real) < (?x::real)⟧ ⟹ ?a powr log ?a ?x = ?x›*)) also (*calculation: ‹(1 / 4) powr log 2 φ + (1 / 2) powr log 2 φ = (inverse (2 powr log 2 φ))² + inverse (2 powr log 2 φ)›*) have "... = inverse (φ^2) + inverse φ" by (simp add: power2_eq_square (*‹(?a::?'a::monoid_mult)² = ?a * ?a›*)) also (*calculation: ‹(1 / 4) powr log 2 φ + (1 / 2) powr log 2 φ = inverse (φ²) + inverse φ›*) have "φ + 1 = φ*φ" by (simp add: φ_def (*‹φ = ((1::real) + sqrt (5::real)) / (2::real)›*) field_simps (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)› ‹(?a::?'a) * (?b::?'a) * (?c::?'a) = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)› ‹(?a::?'a) - (?b::?'a) - (?c::?'a) = ?a - (?b + ?c)› ‹(?a::?'a) + ((?b::?'a) - (?c::?'a)) = ?a + ?b - ?c› ‹((?a::?'a) - (?b::?'a) = (?c::?'a)) = (?a = ?c + ?b)› ‹((?a::?'a) = (?c::?'a) - (?b::?'a)) = (?a + ?b = ?c)› ‹(?a::?'a) - ((?b::?'a) - (?c::?'a)) = ?a + ?c - ?b› ‹(?a::?'a) - (?b::?'a) + (?c::?'a) = ?a + ?c - ?b› and more 77 facts*)) hence "inverse (φ^2) + inverse φ = 1" by (simp add: field_simps (*‹(?a::?'a::semigroup_add) + (?b::?'a::semigroup_add) + (?c::?'a::semigroup_add) = ?a + (?b + ?c)› ‹(?a::?'a::ab_semigroup_add) + (?b::?'a::ab_semigroup_add) = ?b + ?a› ‹(?b::?'a::ab_semigroup_add) + ((?a::?'a::ab_semigroup_add) + (?c::?'a::ab_semigroup_add)) = ?a + (?b + ?c)› ‹(?a::?'a::semigroup_mult) * (?b::?'a::semigroup_mult) * (?c::?'a::semigroup_mult) = ?a * (?b * ?c)› ‹(?a::?'a::ab_semigroup_mult) * (?b::?'a::ab_semigroup_mult) = ?b * ?a› ‹(?b::?'a::ab_semigroup_mult) * ((?a::?'a::ab_semigroup_mult) * (?c::?'a::ab_semigroup_mult)) = ?a * (?b * ?c)› ‹(?a::?'a::cancel_ab_semigroup_add) - (?b::?'a::cancel_ab_semigroup_add) - (?c::?'a::cancel_ab_semigroup_add) = ?a - (?b + ?c)› ‹(?a::?'a::group_add) + ((?b::?'a::group_add) - (?c::?'a::group_add)) = ?a + ?b - ?c› ‹((?a::?'a::group_add) - (?b::?'a::group_add) = (?c::?'a::group_add)) = (?a = ?c + ?b)› ‹((?a::?'a::group_add) = (?c::?'a::group_add) - (?b::?'a::group_add)) = (?a + ?b = ?c)› ‹(?a::?'a::group_add) - ((?b::?'a::group_add) - (?c::?'a::group_add)) = ?a + ?c - ?b› ‹(?a::?'a::ab_group_add) - (?b::?'a::ab_group_add) + (?c::?'a::ab_group_add) = ?a + ?c - ?b› and more 77 facts*) power2_eq_square (*‹(?a::?'a::monoid_mult)² = ?a * ?a›*)) finally (*calculation: ‹(1 / 4) powr log 2 φ + (1 / 2) powr log 2 φ = 1›*) show "(1 / 4) powr log 2 φ + (1 / 2) powr log 2 φ = 1" by simp qed (simp_all) (*solves the remaining goals: 1. ‹⋀x. ⟦0 ≤ x; x < 4⟧ ⟹ 0 ≤ ham_sandwich_cost x› 2. ‹⋀x. 4 ≤ x ⟹ ham_sandwich_cost x = 1 + (ham_sandwich_cost (nat ⌊real x / 4⌋) + ham_sandwich_cost (nat ⌊real x / 2⌋))› 3. ‹⋀x. 4 ≤ x ⟹ 0 ≤ 1› 4. ‹0 < (1 - 1 / 4) * 4› 5. ‹(λn. 1) ∈ O(λx. 1)› 6. ‹∀⇩F x in sequentially. 0 < ham_sandwich_cost x›*) end
{ "path": "afp-2025-02-12/thys/Akra_Bazzi/Master_Theorem_Examples.thy", "repo": "afp-2025-02-12", "sha": "c32b07d24a0d951e55ca46d62f82044f9f5e5ddbc8dd9f0aa270c9e78871a9b5" }
(* File: Algebraic_Auxiliaries.thy Authors: Daniel Stüwe Miscellaneous facts about algebra and number theory *) section ‹Auxiliary Material› theory Algebraic_Auxiliaries imports "HOL-Algebra.Algebra" "HOL-Computational_Algebra.Squarefree" "HOL-Number_Theory.Number_Theory" begin hide_const (open) Divisibility.prime lemma sum_of_bool_eq_card: assumes "finite S" shows "(∑a ∈ S. of_bool (P a)) = real (card {a ∈ S . P a })" proof (-) (*goal: ‹(∑a::'a∈(S::'a set). of_bool ((P::'a ⇒ bool) a)) = real (card {a::'a ∈ S. P a})›*) have "(∑a ∈ S. of_bool (P a) :: real) = (∑a ∈ {x∈S. P x}. 1)" using assms (*‹finite S›*) apply (intro sum.mono_neutral_cong_right (*‹⟦finite ?T; ?S ⊆ ?T; ∀i∈?T - ?S. ?g i = 0; ⋀x. x ∈ ?S ⟹ ?g x = ?h x⟧ ⟹ sum ?g ?T = sum ?h ?S›*)) (*goals: 1. ‹finite S ⟹ finite S› 2. ‹finite S ⟹ {x ∈ S. P x} ⊆ S› 3. ‹finite S ⟹ ∀i∈S - {x ∈ S. P x}. of_bool (P i) = 0› 4. ‹⋀x. ⟦finite S; x ∈ {x ∈ S. P x}⟧ ⟹ of_bool (P x) = 1› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . thus "?thesis" (*goal: ‹(∑a∈S. of_bool (P a)) = real (card {a ∈ S. P a})›*) by simp qed lemma mod_natE: fixes a n b :: nat assumes "a mod n = b" shows "∃ l. a = n * l + b" using assms (*‹a mod n = b›*) mod_mult_div_eq[of a n] (*‹a mod n + n * (a div n) = a›*) by (metis add.commute (*‹?a + ?b = ?b + ?a›*)) lemma (in group) r_coset_is_image: "H #> a = (λ x. x ⊗ a) ` H" unfolding r_coset_def image_def (*goal: ‹⋃ {y. ∃x∈H. y = {x ⊗ a}} = {y. ∃x∈H. y = x ⊗ a}›*) by blast lemma (in group) FactGroup_order: assumes "subgroup H G" "finite H" shows "order G = order (G Mod H) * card H" using lagrange (*‹subgroup ?H G ⟹ card (rcosets ?H) * card ?H = order G›*) assms (*‹subgroup (H::'a set) G› ‹finite H›*) unfolding FactGroup_def order_def (*goal: ‹card (carrier G) = card (carrier ⦇carrier = rcosets H, monoid.mult = (<#>), one = H⦈) * card H›*) by simp corollary (in group) FactGroup_order_div: assumes "subgroup H G" "finite H" shows "order (G Mod H) = order G div card H" using assms (*‹subgroup H G› ‹finite H›*) FactGroup_order (*‹⟦subgroup ?H G; finite ?H⟧ ⟹ order G = order (G Mod ?H) * card ?H›*) subgroupE(2)[OF ‹subgroup H G›] (*‹(H::'a set) ≠ {}›*) by (auto simp: order_def (*‹order ?S = card (carrier ?S)›*)) lemma group_hom_imp_group_hom_image: assumes "group_hom G G h" shows "group_hom G (G⦇carrier := h ` carrier G⦈) h" using group_hom.axioms[OF assms] (*‹Group.group G› ‹Group.group (G::('a, 'b) monoid_scheme)› ‹group_hom_axioms (G::('a, 'b) monoid_scheme) G (h::'a ⇒ 'a)›*) group_hom.img_is_subgroup[OF assms] (*‹subgroup (h ` carrier G) G›*) group.subgroup_imp_group (*‹⟦Group.group ?G; subgroup ?H ?G⟧ ⟹ Group.group (?G⦇carrier := ?H⦈)›*) by (auto intro!: group_hom.intro (*‹⟦Group.group ?G; Group.group ?H; group_hom_axioms ?G ?H ?h⟧ ⟹ group_hom ?G ?H ?h›*) simp: group_hom_axioms_def (*‹group_hom_axioms ?G ?H ?h ≡ ?h ∈ hom ?G ?H›*) hom_def (*‹hom ?G ?H = {h ∈ carrier ?G → carrier ?H. ∀x∈carrier ?G. ∀y∈carrier ?G. h (x ⊗⇘?G⇙ y) = h x ⊗⇘?H⇙ h y}›*)) theorem homomorphism_thm: assumes "group_hom G G h" shows "G Mod kernel G (G⦇carrier := h ` carrier G⦈) h ≅ G ⦇carrier := h ` carrier G⦈" apply (intro group_hom.FactGroup_iso (*‹⟦group_hom ?G ?H ?h; ?h ` carrier ?G = carrier ?H⟧ ⟹ ?G Mod kernel ?G ?H ?h ≅ ?H›*) group_hom_imp_group_hom_image (*‹group_hom ?G ?G ?h ⟹ group_hom ?G (?G⦇carrier := ?h ` carrier ?G⦈) ?h›*) assms (*‹group_hom G G h›*)) (*goal: ‹G Mod kernel G (G⦇carrier := h ` carrier G⦈) h ≅ G⦇carrier := h ` carrier G⦈›*) by simp lemma is_iso_imp_same_card: assumes "H ≅ G " shows "order H = order G" proof (-) (*goal: ‹order (H::('a, 'b) monoid_scheme) = order (G::('c, 'd) monoid_scheme)›*) from assms (*‹H ≅ G›*) obtain h where "bij_betw h (carrier H) (carrier G)" (*goal: ‹(⋀h. bij_betw h (carrier H) (carrier G) ⟹ thesis) ⟹ thesis›*) unfolding is_iso_def iso_def (*goal: ‹(⋀h. bij_betw h (carrier H) (carrier G) ⟹ thesis) ⟹ thesis›*) by blast then show "?thesis" (*goal: ‹order H = order G›*) unfolding order_def (*goal: ‹card (carrier H) = card (carrier G)›*) by (rule bij_betw_same_card (*‹bij_betw (?f::?'a::type ⇒ ?'b::type) (?A::?'a::type set) (?B::?'b::type set) ⟹ card ?A = card ?B›*)) qed corollary homomorphism_thm_order: assumes "group_hom G G h" shows "order (G⦇carrier := h ` carrier G⦈) * card (kernel G (G⦇carrier := h ` carrier G⦈) h) = order G " proof (-) (*goal: ‹order (G⦇carrier := h ` carrier G⦈) * card (kernel G (G⦇carrier := h ` carrier G⦈) h) = order G›*) have "order (G⦇carrier := h ` carrier G⦈) = order (G Mod (kernel G (G⦇carrier := h ` carrier G⦈) h))" using is_iso_imp_same_card[OF homomorphism_thm] (*‹group_hom ?G1 ?G1 ?h1 ⟹ order (?G1 Mod kernel ?G1 (?G1⦇carrier := ?h1 ` carrier ?G1⦈) ?h1) = order (?G1⦇carrier := ?h1 ` carrier ?G1⦈)›*) ‹group_hom G G h› (*‹group_hom G G h›*) by fastforce moreover have "group G" using ‹group_hom G G h› (*‹group_hom G G h›*) group_hom.axioms (*‹group_hom (?G::(?'a, ?'b) monoid_scheme) (?H::(?'c, ?'d) monoid_scheme) (?h::?'a ⇒ ?'c) ⟹ Group.group ?G› ‹group_hom ?G ?H ?h ⟹ Group.group ?H› ‹group_hom ?G ?H ?h ⟹ group_hom_axioms ?G ?H ?h›*) by blast ultimately show "?thesis" (*goal: ‹order (G⦇carrier := h ` carrier G⦈) * card (kernel G (G⦇carrier := h ` carrier G⦈) h) = order G›*) using ‹group_hom G G h› (*‹group_hom G G h›*) group_hom_imp_group_hom_image[OF ‹group_hom G G h›] (*‹group_hom G (G⦇carrier := h ` carrier G⦈) h›*) unfolding FactGroup_def (*goal: ‹order (G⦇carrier := h ` carrier G⦈) * card (kernel G (G⦇carrier := h ` carrier G⦈) h) = order G›*) by (simp add: group.lagrange (*‹⟦Group.group (?G::(?'a, ?'b) monoid_scheme); subgroup (?H::?'a set) ?G⟧ ⟹ card (rcosets⇘?G⇙ ?H) * card ?H = order ?G›*) group_hom.subgroup_kernel (*‹group_hom (?G::(?'a, ?'b) monoid_scheme) (?H::(?'c, ?'d) monoid_scheme) (?h::?'a ⇒ ?'c) ⟹ subgroup (kernel ?G ?H ?h) ?G›*) order_def (*‹order (?S::(?'a, ?'b) monoid_scheme) = card (carrier ?S)›*)) qed lemma (in group_hom) kernel_subset: "kernel G H h ⊆ carrier G" using subgroup_kernel (*‹subgroup (kernel G H h) G›*) G.subgroupE(1) (*‹subgroup ?H G ⟹ ?H ⊆ carrier G›*) by blast lemma (in group) proper_subgroup_imp_bound_on_card: assumes "H ⊂ carrier G" "subgroup H G" "finite (carrier G)" shows "card H ≤ order G div 2" proof (-) (*goal: ‹card H ≤ order G div 2›*) from ‹finite (carrier G)› (*‹finite (carrier G)›*) have "finite (rcosets H)" by (simp add: RCOSETS_def (*‹rcosets⇘?G⇙ ?H = (⋃a∈carrier ?G. {?H #>⇘?G⇙ a})›*)) note subgroup.subgroup_in_rcosets[OF ‹subgroup H G› is_group] (*‹H ∈ rcosets H›*) then obtain J where "J ≠ H" "J ∈ rcosets H" (*goal: ‹(⋀J. ⟦J ≠ H; J ∈ rcosets H⟧ ⟹ thesis) ⟹ thesis›*) using rcosets_part_G[OF ‹subgroup H G›] (*‹⋃ (rcosets H) = carrier G›*) ‹H ⊂ carrier G› (*‹H ⊂ carrier G›*) by (metis Sup_le_iff (*‹(Sup ?A ≤ ?b) = (∀a∈?A. a ≤ ?b)›*) inf.absorb_iff2 (*‹(?b ≤ ?a) = (inf ?a ?b = ?b)›*) inf.idem (*‹inf ?a ?a = ?a›*) inf.strict_order_iff (*‹(?a < ?b) = (?a = inf ?a ?b ∧ ?a ≠ ?b)›*)) then have "2 ≤ card (rcosets H)" using ‹H ∈ rcosets H› (*‹H ∈ rcosets H›*) card_mono[OF ‹finite (rcosets H)›, of "{H, J}"] (*‹{H, J} ⊆ rcosets H ⟹ card {H, J} ≤ card (rcosets H)›*) by simp then show "?thesis" (*goal: ‹card H ≤ order G div 2›*) using mult_le_mono[of 2 "card (rcosets H)" "card H" "card H"] (*‹⟦2 ≤ card (rcosets H); card H ≤ card H⟧ ⟹ 2 * card H ≤ card (rcosets H) * card H›*) unfolding lagrange[OF ‹subgroup H G›] (*goal: ‹card (H::'a set) ≤ order G div (2::nat)›*) by force qed lemma cong_exp_trans[trans]: "[a ^ b = c] (mod n) ⟹ [a = d] (mod n) ⟹ [d ^ b = c] (mod n)" "[c = a ^ b] (mod n) ⟹ [a = d] (mod n) ⟹ [c = d ^ b] (mod n)" using cong_pow (*‹[?b = ?c] (mod ?a) ⟹ [?b ^ ?n = ?c ^ ?n] (mod ?a)›*) cong_sym (*‹[?b = ?c] (mod ?a) ⟹ [?c = ?b] (mod ?a)›*) cong_trans (*‹⟦[?b = ?c] (mod ?a); [?c = ?d] (mod ?a)⟧ ⟹ [?b = ?d] (mod ?a)›*) apply - (*goals: 1. ‹⟦[a ^ b = c] (mod n); [a = d] (mod n); ⋀b c a n. [b = c] (mod a) ⟹ [b ^ n = c ^ n] (mod a); ⋀b c a. [b = c] (mod a) ⟹ [c = b] (mod a); ⋀b c a d. ⟦[b = c] (mod a); [c = d] (mod a)⟧ ⟹ [b = d] (mod a)⟧ ⟹ [d ^ b = c] (mod n)› 2. ‹⟦[c = a ^ b] (mod n); [a = d] (mod n); ⋀b c a n. [b = c] (mod a) ⟹ [b ^ n = c ^ n] (mod a); ⋀b c a. [b = c] (mod a) ⟹ [c = b] (mod a); ⋀b c a d. ⟦[b = c] (mod a); [c = d] (mod a)⟧ ⟹ [b = d] (mod a)⟧ ⟹ [c = d ^ b] (mod n)› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) . lemma cong_exp_mod[simp]: "[(a mod n) ^ b = c] (mod n) ⟷ [a ^ b = c] (mod n)" "[c = (a mod n) ^ b] (mod n) ⟷ [c = a ^ b] (mod n)" (*goals: 1. ‹[(a mod n) ^ b = c] (mod n) = [a ^ b = c] (mod n)› 2. ‹[c = (a mod n) ^ b] (mod n) = [c = a ^ b] (mod n)› discuss goal 1*) apply ((auto simp add: cong_def (*‹[?b = ?c] (mod ?a) = (?b mod ?a = ?c mod ?a)›*) mod_simps (*‹(?a mod ?c + ?b) mod ?c = (?a + ?b) mod ?c› ‹(?a + ?b mod ?c) mod ?c = (?a + ?b) mod ?c› ‹(∑i∈?A. ?f i mod ?a) mod ?a = sum ?f ?A mod ?a› ‹?a mod ?c * ?b mod ?c = ?a * ?b mod ?c› ‹?a * (?b mod ?c) mod ?c = ?a * ?b mod ?c› ‹(∏i∈?A. ?f i mod ?a) mod ?a = prod ?f ?A mod ?a› ‹(?a mod ?b) ^ ?n mod ?b = ?a ^ ?n mod ?b› ‹- (?a mod ?b) mod ?b = - ?a mod ?b› ‹(?a mod ?c - ?b) mod ?c = (?a - ?b) mod ?c› ‹(?a - ?b mod ?c) mod ?c = (?a - ?b) mod ?c› ‹Suc (?m mod ?n) mod ?n = Suc ?m mod ?n› ‹Suc (Suc (?m mod ?n)) mod ?n = Suc (Suc ?m) mod ?n›*))[1]) (*discuss goal 2*) apply ((auto simp add: cong_def (*‹[?b = ?c] (mod ?a) = (?b mod ?a = ?c mod ?a)›*) mod_simps (*‹(?a mod ?c + ?b) mod ?c = (?a + ?b) mod ?c› ‹(?a + ?b mod ?c) mod ?c = (?a + ?b) mod ?c› ‹(∑i∈?A. ?f i mod ?a) mod ?a = sum ?f ?A mod ?a› ‹?a mod ?c * ?b mod ?c = ?a * ?b mod ?c› ‹?a * (?b mod ?c) mod ?c = ?a * ?b mod ?c› ‹(∏i∈?A. ?f i mod ?a) mod ?a = prod ?f ?A mod ?a› ‹(?a mod ?b) ^ ?n mod ?b = ?a ^ ?n mod ?b› ‹- (?a mod ?b) mod ?b = - ?a mod ?b› ‹(?a mod ?c - ?b) mod ?c = (?a - ?b) mod ?c› ‹(?a - ?b mod ?c) mod ?c = (?a - ?b) mod ?c› ‹Suc (?m mod ?n) mod ?n = Suc ?m mod ?n› ‹Suc (Suc (?m mod ?n)) mod ?n = Suc (Suc ?m) mod ?n›*))[1]) (*proven 2 subgoals*) . lemma cong_mult_mod[simp]: "[(a mod n) * b = c] (mod n) ⟷ [a * b = c] (mod n)" "[a * (b mod n) = c] (mod n) ⟷ [a * b = c] (mod n)" (*goals: 1. ‹[(a::'a) mod (n::'a) * (b::'a) = c::'a] (mod n) = [a * b = c] (mod n)› 2. ‹[(a::'a) * ((b::'a) mod (n::'a)) = c::'a] (mod n) = [a * b = c] (mod n)› discuss goal 1*) apply ((auto simp add: cong_def (*‹[?b = ?c] (mod ?a) = (?b mod ?a = ?c mod ?a)›*) mod_simps (*‹(?a mod ?c + ?b) mod ?c = (?a + ?b) mod ?c› ‹(?a + ?b mod ?c) mod ?c = (?a + ?b) mod ?c› ‹(∑i∈?A. ?f i mod ?a) mod ?a = sum ?f ?A mod ?a› ‹?a mod ?c * ?b mod ?c = ?a * ?b mod ?c› ‹?a * (?b mod ?c) mod ?c = ?a * ?b mod ?c› ‹(∏i∈?A. ?f i mod ?a) mod ?a = prod ?f ?A mod ?a› ‹(?a mod ?b) ^ ?n mod ?b = ?a ^ ?n mod ?b› ‹- (?a mod ?b) mod ?b = - ?a mod ?b› ‹(?a mod ?c - ?b) mod ?c = (?a - ?b) mod ?c› ‹(?a - ?b mod ?c) mod ?c = (?a - ?b) mod ?c› ‹Suc (?m mod ?n) mod ?n = Suc ?m mod ?n› ‹Suc (Suc (?m mod ?n)) mod ?n = Suc (Suc ?m) mod ?n›*))[1]) (*discuss goal 2*) apply ((auto simp add: cong_def (*‹[?b = ?c] (mod ?a) = (?b mod ?a = ?c mod ?a)›*) mod_simps (*‹(?a mod ?c + ?b) mod ?c = (?a + ?b) mod ?c› ‹(?a + ?b mod ?c) mod ?c = (?a + ?b) mod ?c› ‹(∑i∈?A. ?f i mod ?a) mod ?a = sum ?f ?A mod ?a› ‹?a mod ?c * ?b mod ?c = ?a * ?b mod ?c› ‹?a * (?b mod ?c) mod ?c = ?a * ?b mod ?c› ‹(∏i∈?A. ?f i mod ?a) mod ?a = prod ?f ?A mod ?a› ‹(?a mod ?b) ^ ?n mod ?b = ?a ^ ?n mod ?b› ‹- (?a mod ?b) mod ?b = - ?a mod ?b› ‹(?a mod ?c - ?b) mod ?c = (?a - ?b) mod ?c› ‹(?a - ?b mod ?c) mod ?c = (?a - ?b) mod ?c› ‹Suc (?m mod ?n) mod ?n = Suc ?m mod ?n› ‹Suc (Suc (?m mod ?n)) mod ?n = Suc (Suc ?m) mod ?n›*))[1]) (*proven 2 subgoals*) . lemma cong_add_mod[simp]: "[(a mod n) + b = c] (mod n) ⟷ [a + b = c] (mod n)" "[a + (b mod n) = c] (mod n) ⟷ [a + b = c] (mod n)" "[∑i∈A. f i mod n = c] (mod n) ⟷ [∑i∈A. f i = c] (mod n)" sorry lemma cong_add_trans[trans]: "[a = b + x] (mod n) ⟹ [x = y] (mod n) ⟹ [a = b + y] (mod n)" "[a = x + b] (mod n) ⟹ [x = y] (mod n) ⟹ [a = y + b] (mod n)" "[b + x = a] (mod n) ⟹ [x = y] (mod n) ⟹ [b + y = a] (mod n)" "[x + b = a] (mod n) ⟹ [x = y] (mod n) ⟹ [y + b = a] (mod n)" unfolding cong_def (*goals: 1. ‹⟦a mod n = (b + x) mod n; x mod n = y mod n⟧ ⟹ a mod n = (b + y) mod n› 2. ‹⟦a mod n = (x + b) mod n; x mod n = y mod n⟧ ⟹ a mod n = (y + b) mod n› 3. ‹⟦(b + x) mod n = a mod n; x mod n = y mod n⟧ ⟹ (b + y) mod n = a mod n› 4. ‹⟦(x + b) mod n = a mod n; x mod n = y mod n⟧ ⟹ (y + b) mod n = a mod n›*) using mod_simps(1,2) (*‹(?a mod ?c + ?b) mod ?c = (?a + ?b) mod ?c› ‹(?a + ?b mod ?c) mod ?c = (?a + ?b) mod ?c›*) by ((metis)+) lemma cong_mult_trans[trans]: "[a = b * x] (mod n) ⟹ [x = y] (mod n) ⟹ [a = b * y] (mod n)" "[a = x * b] (mod n) ⟹ [x = y] (mod n) ⟹ [a = y * b] (mod n)" "[b * x = a] (mod n) ⟹ [x = y] (mod n) ⟹ [b * y = a] (mod n)" "[x * b = a] (mod n) ⟹ [x = y] (mod n) ⟹ [y * b = a] (mod n)" unfolding cong_def (*goals: 1. ‹⟦a mod n = b * x mod n; x mod n = y mod n⟧ ⟹ a mod n = b * y mod n› 2. ‹⟦a mod n = x * b mod n; x mod n = y mod n⟧ ⟹ a mod n = y * b mod n› 3. ‹⟦b * x mod n = a mod n; x mod n = y mod n⟧ ⟹ b * y mod n = a mod n› 4. ‹⟦x * b mod n = a mod n; x mod n = y mod n⟧ ⟹ y * b mod n = a mod n›*) using mod_simps(4,5) (*‹?a mod ?c * ?b mod ?c = ?a * ?b mod ?c› ‹?a * (?b mod ?c) mod ?c = ?a * ?b mod ?c›*) by ((metis)+) lemma cong_diff_trans[trans]: "[a = b - x] (mod n) ⟹ [x = y] (mod n) ⟹ [a = b - y] (mod n)" "[a = x - b] (mod n) ⟹ [x = y] (mod n) ⟹ [a = y - b] (mod n)" "[b - x = a] (mod n) ⟹ [x = y] (mod n) ⟹ [b - y = a] (mod n)" "[x - b = a] (mod n) ⟹ [x = y] (mod n) ⟹ [y - b = a] (mod n)" for a :: "'a :: {unique_euclidean_semiring, euclidean_ring_cancel}" unfolding cong_def (*goals: 1. ‹⟦a mod n = (b - x) mod n; x mod n = y mod n⟧ ⟹ a mod n = (b - y) mod n› 2. ‹⟦a mod n = (x - b) mod n; x mod n = y mod n⟧ ⟹ a mod n = (y - b) mod n› 3. ‹⟦(b - x) mod n = a mod n; x mod n = y mod n⟧ ⟹ (b - y) mod n = a mod n› 4. ‹⟦(x - b) mod n = a mod n; x mod n = y mod n⟧ ⟹ (y - b) mod n = a mod n›*) (*goals: 1. ‹⟦a mod n = (b - x) mod n; x mod n = y mod n⟧ ⟹ a mod n = (b - y) mod n› 2. ‹⟦a mod n = (x - b) mod n; x mod n = y mod n⟧ ⟹ a mod n = (y - b) mod n› 3. ‹⟦(b - x) mod n = a mod n; x mod n = y mod n⟧ ⟹ (b - y) mod n = a mod n› 4. ‹⟦(x - b) mod n = a mod n; x mod n = y mod n⟧ ⟹ (y - b) mod n = a mod n› discuss goal 1*) apply (metis mod_diff_eq (*‹(?a mod ?c - ?b mod ?c) mod ?c = (?a - ?b) mod ?c›*)) (*discuss goal 2*) apply (metis mod_diff_eq (*‹(?a mod ?c - ?b mod ?c) mod ?c = (?a - ?b) mod ?c›*)) (*discuss goal 3*) apply (metis mod_diff_eq (*‹(?a mod ?c - ?b mod ?c) mod ?c = (?a - ?b) mod ?c›*)) (*discuss goal 4*) apply (metis mod_diff_eq (*‹(?a mod ?c - ?b mod ?c) mod ?c = (?a - ?b) mod ?c›*)) (*proven 4 subgoals*) . lemma eq_imp_eq_mod_int: "a = b ⟹ [a = b] (mod m)" for a b :: int by simp lemma eq_imp_eq_mod_nat: "a = b ⟹ [a = b] (mod m)" for a b :: nat by simp lemma cong_pow_I: "a = b ⟹ [x^a = x^b](mod n)" by simp lemma gre1I: "(n = 0 ⟹ False) ⟹ (1 :: nat) ≤ n" by presburger lemma gre1I_nat: "(n = 0 ⟹ False) ⟹ (Suc 0 :: nat) ≤ n" by presburger lemma totient_less_not_prime: assumes "¬ prime n" "1 < n" shows "totient n < n - 1" sorry lemma power2_diff_nat: "x ≥ y ⟹ (x - y)² = x² + y² - 2 * x * y" for x y :: nat apply (simp add: algebra_simps (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)› ‹(?a::?'a) * (?b::?'a) * (?c::?'a) = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)› ‹(?a::?'a) - (?b::?'a) - (?c::?'a) = ?a - (?b + ?c)› ‹(?a::?'a) + ((?b::?'a) - (?c::?'a)) = ?a + ?b - ?c› ‹((?a::?'a) - (?b::?'a) = (?c::?'a)) = (?a = ?c + ?b)› ‹((?a::?'a) = (?c::?'a) - (?b::?'a)) = (?a + ?b = ?c)› ‹(?a::?'a) - ((?b::?'a) - (?c::?'a)) = ?a + ?c - ?b› ‹(?a::?'a) - (?b::?'a) + (?c::?'a) = ?a + ?c - ?b› and more 15 facts*) power2_eq_square (*‹(?a::?'a)² = ?a * ?a›*) mult_2_right (*‹(?z::?'a) * (2::?'a) = ?z + ?z›*)) (*goal: ‹y ≤ x ⟹ (x - y)² = x² + y² - 2 * x * y›*) by (meson Nat.diff_diff_right (*‹?k ≤ ?j ⟹ ?i - (?j - ?k) = ?i + ?k - ?j›*) le_add2 (*‹?n ≤ ?m + ?n›*) le_trans (*‹⟦?i ≤ ?j; ?j ≤ ?k⟧ ⟹ ?i ≤ ?k›*) mult_le_mono (*‹⟦?i ≤ ?j; ?k ≤ ?l⟧ ⟹ ?i * ?k ≤ ?j * ?l›*) order_refl (*‹?x ≤ ?x›*)) lemma square_inequality: "1 < n ⟹ (n + n) ≤ (n * n)" for n :: nat by (metis Suc_eq_plus1_left (*‹Suc ?n = 1 + ?n›*) Suc_leI (*‹?m < ?n ⟹ Suc ?m ≤ ?n›*) mult_le_mono1 (*‹?i ≤ ?j ⟹ ?i * ?k ≤ ?j * ?k›*) semiring_normalization_rules( (*‹?m + ?m = (1 + 1) * ?m›*) 4)) lemma square_one_cong_one: assumes "[x = 1](mod n)" shows "[x^2 = 1](mod n)" using assms (*‹[x = 1] (mod n)›*) cong_pow (*‹[?b::?'a::unique_euclidean_semiring = ?c::?'a::unique_euclidean_semiring] (mod ?a::?'a::unique_euclidean_semiring) ⟹ [?b ^ (?n::nat) = ?c ^ ?n] (mod ?a)›*) by fastforce lemma cong_square_alt_int: "prime p ⟹ [a * a = 1] (mod p) ⟹ [a = 1] (mod p) ∨ [a = p - 1] (mod p)" for a p :: "'a :: {normalization_semidom, linordered_idom, unique_euclidean_ring}" using dvd_add_triv_right_iff[of p "a - (p - 1)"] (*‹(p dvd a - (p - 1) + p) = (p dvd a - (p - 1))›*) by (auto simp add: cong_iff_dvd_diff (*‹[?a = ?b] (mod ?m) = (?m dvd ?a - ?b)›*) square_diff_one_factored (*‹?x * ?x - 1 = (?x + 1) * (?x - 1)›*) dest!: prime_dvd_multD (*‹⟦prime ?p; ?p dvd ?a * ?b⟧ ⟹ ?p dvd ?a ∨ ?p dvd ?b›*)) lemma cong_square_alt: "prime p ⟹ [a * a = 1] (mod p) ⟹ [a = 1] (mod p) ∨ [a = p - 1] (mod p)" for a p :: nat using cong_square_alt_int[of "int p" "int a"] (*‹⟦prime (int (p::nat)); [int (a::nat) * int a = 1::int] (mod int p)⟧ ⟹ [int a = 1::int] (mod int p) ∨ [int a = int p - (1::int)] (mod int p)›*) prime_nat_int_transfer[of p] (*‹prime (int (p::nat)) = prime p›*) prime_gt_1_nat[of p] (*‹prime p ⟹ 1 < p›*) by (simp flip: cong_int_iff (*‹[int ?m = int ?q] (mod int ?n) = [?m = ?q] (mod ?n)›*) add: of_nat_diff (*‹?n ≤ ?m ⟹ of_nat (?m - ?n) = of_nat ?m - of_nat ?n›*)) lemma square_minus_one_cong_one: fixes n x :: nat assumes "1 < n" "[x = n - 1](mod n)" shows "[x^2 = 1](mod n)" proof (-) (*goal: ‹[(x::nat)² = 1::nat] (mod n::nat)›*) have "[x^2 = (n - 1) * (n - 1)] (mod n)" using cong_mult[OF assms ( 2 ) assms ( 2 )] (*‹[x * x = (n - 1) * (n - 1)] (mod n)›*) by (simp add: algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 15 facts*) power2_eq_square (*‹?a² = ?a * ?a›*)) also (*calculation: ‹[(x::nat)² = ((n::nat) - (1::nat)) * (n - (1::nat))] (mod n)›*) have "[(n - 1) * (n - 1) = Suc (n * n) - (n + n)] (mod n)" using power2_diff_nat[of 1 n] (*‹1 ≤ n ⟹ (n - 1)² = n² + 1² - 2 * n * 1›*) ‹1 < n› (*‹1 < n›*) by (simp add: algebra_simps (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)› ‹(?a::?'a) * (?b::?'a) * (?c::?'a) = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)› ‹(?a::?'a) - (?b::?'a) - (?c::?'a) = ?a - (?b + ?c)› ‹(?a::?'a) + ((?b::?'a) - (?c::?'a)) = ?a + ?b - ?c› ‹((?a::?'a) - (?b::?'a) = (?c::?'a)) = (?a = ?c + ?b)› ‹((?a::?'a) = (?c::?'a) - (?b::?'a)) = (?a + ?b = ?c)› ‹(?a::?'a) - ((?b::?'a) - (?c::?'a)) = ?a + ?c - ?b› ‹(?a::?'a) - (?b::?'a) + (?c::?'a) = ?a + ?c - ?b› and more 15 facts*) power2_eq_square (*‹(?a::?'a)² = ?a * ?a›*)) also (*calculation: ‹[x² = Suc (n * n) - (n + n)] (mod n)›*) have "[Suc (n * n) - (n + n) = Suc (n * n)] (mod n)" proof (-) (*goal: ‹[Suc ((n::nat) * n) - (n + n) = Suc (n * n)] (mod n)›*) have "n * n + 0 * n = n * n" by linarith moreover have "n * n - (n + n) + (n + n) = n * n" using square_inequality[OF ‹1 < n›] (*‹n + n ≤ n * n›*) le_add_diff_inverse2 (*‹?b ≤ ?a ⟹ ?a - ?b + ?b = ?a›*) by blast moreover have "(Suc 0 + 1) * n = n + n" by simp ultimately show "?thesis" (*goal: ‹[Suc (n * n) - (n + n) = Suc (n * n)] (mod n)›*) using square_inequality[OF ‹1 < n›] (*‹n + n ≤ n * n›*) by (metis (no_types) Suc_diff_le (*‹?n ≤ ?m ⟹ Suc ?m - ?n = Suc (?m - ?n)›*) add_Suc (*‹Suc ?m + ?n = Suc (?m + ?n)›*) cong_iff_lin_nat (*‹[?a = ?b] (mod ?m) = (∃k1 k2. ?b + k1 * ?m = ?a + k2 * ?m)›*)) qed also (*calculation: ‹[(x::nat)² = Suc ((n::nat) * n)] (mod n)›*) have "[Suc (n * n) = 1] (mod n)" using cong_to_1'_nat (*‹[?a::nat = 1::nat] (mod ?n::nat) = (?a = (0::nat) ∧ ?n = (1::nat) ∨ (∃m::nat. ?a = (1::nat) + m * ?n))›*) by auto finally (*calculation: ‹[x² = 1] (mod n)›*) show "?thesis" (*goal: ‹[(x::nat)² = 1::nat] (mod n::nat)›*) . qed lemma odd_prime_gt_2_int: "2 < p" if "odd p" "prime p" for p :: int using prime_ge_2_int[OF ‹prime p›] (*‹(2::int) ≤ (p::int)›*) ‹odd p› (*‹odd (p::int)›*) apply (cases "p = 2") (*goals: 1. ‹⟦2 ≤ p; odd p; p = 2⟧ ⟹ 2 < p› 2. ‹⟦2 ≤ p; odd p; p ≠ 2⟧ ⟹ 2 < p› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma odd_prime_gt_2_nat: "2 < p" if "odd p" "prime p" for p :: nat using prime_ge_2_nat[OF ‹prime p›] (*‹2 ≤ p›*) ‹odd p› (*‹odd (p::nat)›*) apply (cases "p = 2") (*goals: 1. ‹⟦(2::nat) ≤ (p::nat); odd p; p = (2::nat)⟧ ⟹ (2::nat) < p› 2. ‹⟦(2::nat) ≤ (p::nat); odd p; p ≠ (2::nat)⟧ ⟹ (2::nat) < p› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma gt_one_imp_gt_one_power_if_coprime: "1 ≤ x ⟹ 1 < n ⟹ coprime x n ⟹ 1 ≤ x ^ (n - 1) mod n" apply (rule gre1I (*‹(?n = 0 ⟹ False) ⟹ 1 ≤ ?n›*)) (*goal: ‹⟦1 ≤ x; 1 < n; coprime x n⟧ ⟹ 1 ≤ x ^ (n - 1) mod n›*) by (auto simp: coprime_commute (*‹coprime ?b ?a = coprime ?a ?b›*) dest: coprime_absorb_left (*‹?x dvd ?y ⟹ coprime ?x ?y = is_unit ?x›*)) lemma residue_one_dvd: "a mod n = 1 ⟹ n dvd a - 1" for a n :: nat by (fastforce intro!: cong_to_1_nat (*‹[?a::nat = 1::nat] (mod ?n::nat) ⟹ ?n dvd ?a - (1::nat)›*) simp: cong_def (*‹[?b::?'a::unique_euclidean_semiring = ?c::?'a::unique_euclidean_semiring] (mod ?a::?'a::unique_euclidean_semiring) = (?b mod ?a = ?c mod ?a)›*)) lemma coprimeI_power_mod: fixes x r n :: nat assumes "x ^ r mod n = 1" "r ≠ 0" "n ≠ 0" shows "coprime x n" proof (-) (*goal: ‹coprime x n›*) have "coprime (x ^ r mod n) n" using coprime_1_right (*‹coprime (?a::?'a) (1::?'a)›*) ‹x ^ r mod n = 1› (*‹x ^ r mod n = 1›*) by (simp add: coprime_commute (*‹coprime ?b ?a = coprime ?a ?b›*)) thus "?thesis" (*goal: ‹coprime x n›*) using ‹r ≠ 0› (*‹r ≠ 0›*) ‹n ≠ 0› (*‹(n::nat) ≠ (0::nat)›*) by simp qed (* MOVE - EXTRA *) lemma prime_dvd_choose: assumes "0 < k" "k < p" "prime p" shows "p dvd (p choose k)" proof (-) (*goal: ‹(p::nat) dvd p choose (k::nat)›*) have "k ≤ p" using ‹k < p› (*‹(k::nat) < (p::nat)›*) by auto have "p dvd fact p" using ‹prime p› (*‹prime p›*) by (simp add: prime_dvd_fact_iff (*‹prime ?p ⟹ (?p dvd fact ?n) = (?p ≤ ?n)›*)) moreover have "¬ p dvd fact k * fact (p - k)" unfolding prime_dvd_mult_iff[OF ‹prime p›] prime_dvd_fact_iff[OF ‹prime p›] (*goal: ‹¬ ((p::nat) ≤ (k::nat) ∨ p ≤ p - k)›*) using assms (*‹0 < k› ‹(k::nat) < (p::nat)› ‹prime p›*) by simp ultimately show "?thesis" (*goal: ‹p dvd p choose k›*) unfolding binomial_fact_lemma[OF ‹k ≤ p›, symmetric] (*goal: ‹(p::nat) dvd p choose (k::nat)›*) using assms (*‹0 < k› ‹k < p› ‹prime (p::nat)›*) prime_dvd_multD (*‹⟦prime (?p::?'a); ?p dvd (?a::?'a) * (?b::?'a)⟧ ⟹ ?p dvd ?a ∨ ?p dvd ?b›*) by blast qed lemma cong_eq_0_I: "(∀i∈A. [f i mod n = 0] (mod n)) ⟹ [∑i∈A. f i = 0] (mod n)" using cong_sum (*‹(⋀x. x ∈ ?A ⟹ [?f x = ?g x] (mod ?a)) ⟹ [sum ?f ?A = sum ?g ?A] (mod ?a)›*) by fastforce lemma power_mult_cong: assumes "[x^n = a](mod m)" "[y^n = b](mod m)" shows "[(x*y)^n = a*b](mod m)" using assms (*‹[x ^ n = a] (mod m)› ‹[y ^ n = b] (mod m)›*) cong_mult[of "x^n" a m "y^n" b] (*‹⟦[x ^ n = a] (mod m); [y ^ n = b] (mod m)⟧ ⟹ [x ^ n * y ^ n = a * b] (mod m)›*) power_mult_distrib (*‹((?a::?'a) * (?b::?'a)) ^ (?n::nat) = ?a ^ ?n * ?b ^ ?n›*) by metis lemma fixes n :: nat assumes "n > 1" shows odd_pow_cong: "odd m ⟹ [(n - 1) ^ m = n - 1] (mod n)" and even_pow_cong: "even m ⟹ [(n - 1) ^ m = 1] (mod n)" proof (induction m) (*goals: 1. ‹odd (0::nat) ⟹ [((n::nat) - (1::nat)) ^ (0::nat) = n - (1::nat)] (mod n)› 2. ‹even (0::nat) ⟹ [((n::nat) - (1::nat)) ^ (0::nat) = 1::nat] (mod n)› 3. ‹⋀m::nat. ⟦odd m ⟹ [((n::nat) - (1::nat)) ^ m = n - (1::nat)] (mod n); even m ⟹ [(n - (1::nat)) ^ m = 1::nat] (mod n); odd (Suc m)⟧ ⟹ [(n - (1::nat)) ^ Suc m = n - (1::nat)] (mod n)› 4. ‹⋀m::nat. ⟦odd m ⟹ [((n::nat) - (1::nat)) ^ m = n - (1::nat)] (mod n); even m ⟹ [(n - (1::nat)) ^ m = 1::nat] (mod n); even (Suc m)⟧ ⟹ [(n - (1::nat)) ^ Suc m = 1::nat] (mod n)›*) case (Suc m) (*‹odd m ⟹ [(n - 1) ^ m = n - 1] (mod n)› ‹even m ⟹ [(n - 1) ^ m = 1] (mod n)›*) case 1 (*‹odd (Suc m)›*) with Suc (*‹odd (m::nat) ⟹ [((n::nat) - (1::nat)) ^ m = n - (1::nat)] (mod n)› ‹even (m::nat) ⟹ [((n::nat) - (1::nat)) ^ m = 1::nat] (mod n)›*) have IH: "[(n - 1) ^ m = 1] (mod n)" by auto show "?case" (*goal: ‹[(n - 1) ^ Suc m = n - 1] (mod n)›*) using ‹1 < n› (*‹1 < n›*) cong_mult[OF cong_refl IH] (*‹[?b * (n - 1) ^ m = ?b * 1] (mod n)›*) by simp next (*goals: 1. ‹odd 0 ⟹ [(n - 1) ^ 0 = n - 1] (mod n)› 2. ‹even 0 ⟹ [(n - 1) ^ 0 = 1] (mod n)› 3. ‹⋀m. ⟦odd m ⟹ [(n - 1) ^ m = n - 1] (mod n); even m ⟹ [(n - 1) ^ m = 1] (mod n); even (Suc m)⟧ ⟹ [(n - 1) ^ Suc m = 1] (mod n)›*) case (Suc m) (*‹odd m ⟹ [(n - 1) ^ m = n - 1] (mod n)› ‹even m ⟹ [(n - 1) ^ m = 1] (mod n)›*) case 2 (*‹even (Suc m)›*) with Suc (*‹odd m ⟹ [(n - 1) ^ m = n - 1] (mod n)› ‹even m ⟹ [(n - 1) ^ m = 1] (mod n)›*) have IH: "[(n - 1) ^ m = n - 1] (mod n)" by auto show "?case" (*goal: ‹[(n - 1) ^ Suc m = 1] (mod n)›*) using cong_mult[OF cong_refl IH, of "(n - 1)"] (*‹[(n - 1) * (n - 1) ^ m = (n - 1) * (n - 1)] (mod n)›*) square_minus_one_cong_one[OF ‹1 < n›, of "n - 1"] (*‹[(n::nat) - (1::nat) = n - (1::nat)] (mod n) ⟹ [(n - (1::nat))² = 1::nat] (mod n)›*) by (auto simp: power2_eq_square (*‹(?a::?'a)² = ?a * ?a›*) intro: cong_trans (*‹⟦[?b::?'a = ?c::?'a] (mod ?a::?'a); [?c = ?d::?'a] (mod ?a)⟧ ⟹ [?b = ?d] (mod ?a)›*)) qed (simp_all) (*solves the remaining goals: 1. ‹odd (0::nat) ⟹ [((n::nat) - (1::nat)) ^ (0::nat) = n - (1::nat)] (mod n)› 2. ‹even (0::nat) ⟹ [((n::nat) - (1::nat)) ^ (0::nat) = 1::nat] (mod n)›*) lemma cong_mult_uneq': fixes a :: "'a::{unique_euclidean_ring, ring_gcd}" assumes "coprime d a" shows "[b ≠ c] (mod a) ⟹ [d = e] (mod a) ⟹ [b * d ≠ c * e] (mod a)" using cong_mult_rcancel[OF assms] (*‹[?a * d = ?b * d] (mod a) = [?a = ?b] (mod a)›*) using cong_trans[of "b*d" "c*e" a "c*d"] (*‹⟦[b * d = c * e] (mod a); [c * e = c * d] (mod a)⟧ ⟹ [b * d = c * d] (mod a)›*) using cong_scalar_left (*‹[?b = ?c] (mod ?a) ⟹ [?d * ?b = ?d * ?c] (mod ?a)›*) cong_sym (*‹[?b = ?c] (mod ?a) ⟹ [?c = ?b] (mod ?a)›*) by blast lemma p_coprime_right_nat: "prime p ⟹ coprime a p = (¬ p dvd a)" for p a :: nat by (meson coprime_absorb_left (*‹?x dvd ?y ⟹ coprime ?x ?y = is_unit ?x›*) coprime_commute (*‹coprime ?b ?a = coprime ?a ?b›*) not_prime_unit (*‹is_unit ?x ⟹ ¬ prime ?x›*) prime_imp_coprime_nat (*‹⟦prime ?p; ¬ ?p dvd ?n⟧ ⟹ coprime ?p ?n›*)) lemma squarefree_mult_imp_coprime: assumes "squarefree (a * b :: 'a :: semiring_gcd)" shows "coprime a b" proof (rule coprimeI (*‹(⋀c. ⟦c dvd ?a; c dvd ?b⟧ ⟹ is_unit c) ⟹ coprime ?a ?b›*)) (*goal: ‹⋀c. ⟦c dvd a; c dvd b⟧ ⟹ is_unit c›*) fix l assume "l dvd a" "l dvd b" (*‹(l::'a) dvd (a::'a)› ‹(l::'a) dvd (b::'a)›*) then obtain a' and b' where "a = l * a'" "b = l * b'" (*goal: ‹(⋀a' b'. ⟦a = l * a'; b = l * b'⟧ ⟹ thesis) ⟹ thesis›*) by (auto elim!: dvdE (*‹⟦(?b::?'a::dvd) dvd (?a::?'a::dvd); ⋀k::?'a::dvd. ?a = ?b * k ⟹ ?P::bool⟧ ⟹ ?P›*)) with assms (*‹squarefree (a * b)›*) have "squarefree (l² * (a' * b'))" by (simp add: power2_eq_square (*‹?a² = ?a * ?a›*) mult_ac (*‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)›*)) thus "l dvd 1" apply (rule squarefreeD (*‹⟦squarefree ?n; ?x² dvd ?n⟧ ⟹ ?x dvd 1›*)) (*goal: ‹is_unit l›*) by auto qed lemma prime_divisor_exists_strong: fixes m :: int assumes "m > 1" "¬prime m" shows "∃n k. m = n * k ∧ 1 < n ∧ n < m ∧ 1 < k ∧ k < m" proof (-) (*goal: ‹∃n k. m = n * k ∧ 1 < n ∧ n < m ∧ 1 < k ∧ k < m›*) from assms (*‹1 < m› ‹¬ prime m›*) obtain n and k where nk: "n * k > 1" "n ≥ 0" "m = n * k" "n ≠ 1" "n ≠ 0" "k ≠ 1" (*goal: ‹(⋀n k. ⟦1 < n * k; 0 ≤ n; m = n * k; n ≠ 1; n ≠ 0; k ≠ 1⟧ ⟹ thesis) ⟹ thesis›*) using assms (*‹1 < m› ‹¬ prime m›*) unfolding prime_int_iff dvd_def (*goal: ‹(⋀(n::int) k::int. ⟦(1::int) < n * k; (0::int) ≤ n; (m::int) = n * k; n ≠ (1::int); n ≠ (0::int); k ≠ (1::int)⟧ ⟹ thesis::bool) ⟹ thesis›*) by auto from nk (*‹(1::int) < (n::int) * (k::int)› ‹0 ≤ n› ‹m = n * k› ‹n ≠ 1› ‹n ≠ 0› ‹k ≠ 1›*) have "n > 1" by linarith from nk (*‹1 < n * k› ‹0 ≤ n› ‹m = n * k› ‹n ≠ 1› ‹n ≠ 0› ‹k ≠ 1›*) assms (*‹1 < m› ‹¬ prime (m::int)›*) have "n * k > 0" by simp with ‹n ≥ 0› (*‹0 ≤ n›*) have "k > 0" using zero_less_mult_pos (*‹⟦0 < ?a * ?b; 0 < ?a⟧ ⟹ 0 < ?b›*) by force with ‹k ≠ 1› (*‹k ≠ 1›*) have "k > 1" by linarith from nk (*‹1 < n * k› ‹(0::int) ≤ (n::int)› ‹m = n * k› ‹n ≠ 1› ‹n ≠ 0› ‹k ≠ 1›*) have "n > 1" by linarith from ‹k > 1› (*‹1 < k›*) nk (*‹1 < n * k› ‹0 ≤ n› ‹m = n * k› ‹(n::int) ≠ (1::int)› ‹(n::int) ≠ (0::int)› ‹k ≠ 1›*) have "n < m" "k < m" apply - (*goals: 1. ‹⟦(1::int) < (k::int); (1::int) < (n::int) * k; (0::int) ≤ n; (m::int) = n * k; n ≠ (1::int); n ≠ (0::int); k ≠ (1::int)⟧ ⟹ n < m› 2. ‹⟦(1::int) < (k::int); (1::int) < (n::int) * k; (0::int) ≤ n; (m::int) = n * k; n ≠ (1::int); n ≠ (0::int); k ≠ (1::int)⟧ ⟹ k < m› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . with nk (*‹1 < n * k› ‹(0::int) ≤ (n::int)› ‹(m::int) = (n::int) * (k::int)› ‹(n::int) ≠ (1::int)› ‹n ≠ 0› ‹k ≠ 1›*) ‹k > 1› (*‹1 < k›*) ‹n > 1› (*‹1 < n›*) show "?thesis" (*goal: ‹∃n k. m = n * k ∧ 1 < n ∧ n < m ∧ 1 < k ∧ k < m›*) by blast qed lemma prime_divisor_exists_strong_nat: fixes m :: nat assumes "1 < m" "¬prime m" shows "∃p k. m = p * k ∧ 1 < p ∧ p < m ∧ 1 < k ∧ k < m ∧ prime p" proof (-) (*goal: ‹∃p k. m = p * k ∧ 1 < p ∧ p < m ∧ 1 < k ∧ k < m ∧ prime p›*) obtain p where p_def: "prime p" "p dvd m" "p ≠ m" "1 < p" (*goal: ‹(⋀p. ⟦prime p; p dvd m; p ≠ m; 1 < p⟧ ⟹ thesis) ⟹ thesis›*) using assms (*‹(1::nat) < (m::nat)› ‹¬ prime m›*) prime_prime_factor (*‹prime ?n = (?n ≠ 1 ∧ (∀p. prime p ∧ p dvd ?n ⟶ p = ?n))›*) prime_gt_1_nat (*‹prime ?p ⟹ 1 < ?p›*) by blast moreover define k where "k = m div p" with ‹p dvd m› (*‹p dvd m›*) have "m = p * k" by simp moreover have "p < m" using ‹p ≠ m› (*‹p ≠ m›*) dvd_imp_le[OF ‹p dvd m›] (*‹0 < m ⟹ p ≤ m›*) ‹m > 1› (*‹1 < m›*) by simp moreover have "1 < k" "k < m" using ‹1 < m› (*‹1 < m›*) ‹1 < p› (*‹1 < p›*) ‹p ≠ m› (*‹p ≠ m›*) unfolding ‹m = p * k› (*goals: 1. ‹1 < k› 2. ‹k < p * k›*) apply - (*goals: 1. ‹⟦(1::nat) < (p::nat) * (k::nat); (1::nat) < p; p ≠ p * k⟧ ⟹ (1::nat) < k› 2. ‹⟦(1::nat) < (p::nat) * (k::nat); (1::nat) < p; p ≠ p * k⟧ ⟹ k < p * k› discuss goal 1*) apply (force intro: Suc_lessI (*‹⟦?m < ?n; Suc ?m ≠ ?n⟧ ⟹ Suc ?m < ?n›*) Nat.gr0I (*‹(?n = 0 ⟹ False) ⟹ 0 < ?n›*)) (*discuss goal 2*) apply (force intro: Suc_lessI (*‹⟦?m < ?n; Suc ?m ≠ ?n⟧ ⟹ Suc ?m < ?n›*) Nat.gr0I (*‹(?n = 0 ⟹ False) ⟹ 0 < ?n›*)) (*proven 2 subgoals*) . ultimately show "?thesis" (*goal: ‹∃p k. m = p * k ∧ 1 < p ∧ p < m ∧ 1 < k ∧ k < m ∧ prime p›*) using ‹1 < m› (*‹1 < m›*) by blast qed (* TODO Remove *) lemma prime_factorization_eqI: assumes "⋀p. p ∈# P ⟹ prime p" "prod_mset P = n" shows "prime_factorization n = P" using prime_factorization_prod_mset_primes[of P] (*‹(⋀p::'a. p ∈# (P::'a multiset) ⟹ prime p) ⟹ prime_factorization (∏⇩# P) = P›*) assms (*‹?p ∈# P ⟹ prime ?p› ‹∏⇩# P = n›*) by simp lemma prime_factorization_prime_elem: assumes "prime_elem p" shows "prime_factorization p = {#normalize p#}" proof (-) (*goal: ‹prime_factorization p = {#normalize p#}›*) have "prime_factorization p = prime_factorization (normalize p)" by (metis normalize_idem (*‹normalize (normalize ?a) = normalize ?a›*) prime_factorization_cong (*‹normalize ?x = normalize ?y ⟹ prime_factorization ?x = prime_factorization ?y›*)) also (*calculation: ‹prime_factorization (p::'a) = prime_factorization (normalize p)›*) have "… = {#normalize p#}" apply (rule prime_factorization_prime (*‹prime ?p ⟹ prime_factorization ?p = {#?p#}›*)) (*goal: ‹prime_factorization (normalize p) = {#normalize p#}›*) by (use assms in auto) finally (*calculation: ‹prime_factorization p = {#normalize p#}›*) show "?thesis" (*goal: ‹prime_factorization p = {#normalize p#}›*) . qed lemma size_prime_factorization_eq_Suc_0_iff [simp]: fixes n :: "'a :: factorial_semiring_multiplicative" shows "size (prime_factorization n) = Suc 0 ⟷ prime_elem n" proof (standard) (*goals: 1. ‹size (prime_factorization n) = Suc 0 ⟹ prime_elem n› 2. ‹prime_elem n ⟹ size (prime_factorization n) = Suc 0›*) assume size: "size (prime_factorization n) = Suc 0" (*‹size (prime_factorization (n::'a)) = Suc (0::nat)›*) hence [simp]: "n ≠ 0" by auto from size (*‹size (prime_factorization n) = Suc 0›*) obtain p where "*": "prime_factorization n = {#p#}" (*goal: ‹(⋀p. prime_factorization n = {#p#} ⟹ thesis) ⟹ thesis›*) by (auto elim!: size_mset_SucE (*‹⟦size ?A = Suc ?n; ⋀a B. ⟦?A = {#a#} + B; size B = ?n⟧ ⟹ ?P⟧ ⟹ ?P›*)) hence p: "p ∈ prime_factors n" by auto have "prime_elem (normalize p)" using p (*‹p ∈# prime_factorization n›*) by (auto simp: in_prime_factors_iff (*‹(?p ∈# prime_factorization ?x) = (?x ≠ 0 ∧ ?p dvd ?x ∧ prime ?p)›*)) also (*calculation: ‹prime_elem (normalize (p::'a))›*) have "p = prod_mset (prime_factorization n)" using "*" (*‹prime_factorization n = {#p#}›*) by simp also (*calculation: ‹prime_elem (normalize (∏⇩# (prime_factorization n)))›*) have "normalize … = normalize n" apply (rule prod_mset_prime_factorization_weak (*‹?x ≠ 0 ⟹ normalize (∏⇩# (prime_factorization ?x)) = normalize ?x›*)) (*goal: ‹normalize (∏⇩# (prime_factorization (n::'a))) = normalize n›*) by auto finally (*calculation: ‹prime_elem (normalize n)›*) show "prime_elem n" by simp qed (auto simp: prime_factorization_prime_elem (*‹prime_elem (?p::?'a) ⟹ prime_factorization ?p = {#normalize ?p#}›*)) (*solved the remaining goal: ‹prime_elem n ⟹ size (prime_factorization n) = Suc 0›*) (* END TODO *) (* TODO Move *) lemma squarefree_prime_elem [simp, intro]: fixes p :: "'a :: algebraic_semidom" assumes "prime_elem p" shows "squarefree p" proof (rule squarefreeI (*‹(⋀x::?'a. x² dvd (?n::?'a) ⟹ x dvd (1::?'a)) ⟹ squarefree ?n›*)) (*goal: ‹⋀x. x² dvd p ⟹ is_unit x›*) fix x assume "x² dvd p" (*‹(x::'a)² dvd (p::'a)›*) show "is_unit x" proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹¬ is_unit x ⟹ False›*) assume "¬is_unit x" (*‹¬ is_unit (x::'a)›*) hence "¬is_unit (x²)" by (simp add: is_unit_power_iff (*‹is_unit (?a ^ ?n) = (is_unit ?a ∨ ?n = 0)›*)) from assms (*‹prime_elem p›*) this (*‹¬ is_unit (x²)›*) ‹x² dvd p› (*‹x² dvd p›*) have "prime_elem (x²)" by (rule prime_elem_mono (*‹⟦prime_elem ?p; ¬ is_unit ?q; ?q dvd ?p⟧ ⟹ prime_elem ?q›*)) thus False by (simp add: prime_elem_power_iff (*‹prime_elem (?p ^ ?n) = (prime_elem ?p ∧ ?n = 1)›*)) qed qed lemma squarefree_prime [simp, intro]: "prime p ⟹ squarefree p" sorry lemma not_squarefree_primepow: assumes "primepow n" shows "squarefree n ⟷ prime n" using assms (*‹primepow n›*) by (auto simp: primepow_def (*‹primepow (?n::?'a) = (∃(p::?'a) k::nat. prime p ∧ (0::nat) < k ∧ ?n = p ^ k)›*) squarefree_power_iff (*‹squarefree ((?n::?'a) ^ (?m::nat)) = (?m = (0::nat) ∨ is_unit ?n ∨ squarefree ?n ∧ ?m = (1::nat))›*) prime_power_iff (*‹prime ((?p::?'a) ^ (?n::nat)) = (prime ?p ∧ ?n = (1::nat))›*)) lemma prime_factorization_normalize [simp]: "prime_factorization (normalize n) = prime_factorization n" apply (rule prime_factorization_cong (*‹normalize ?x = normalize ?y ⟹ prime_factorization ?x = prime_factorization ?y›*)) (*goal: ‹prime_factorization (normalize (n::'a)) = prime_factorization n›*) by auto lemma one_prime_factor_iff_primepow: fixes n :: "'a :: factorial_semiring_multiplicative" shows "card (prime_factors n) = Suc 0 ⟷ primepow (normalize n)" proof (standard) (*goals: 1. ‹card (prime_factors n) = Suc 0 ⟹ primepow (normalize n)› 2. ‹primepow (normalize n) ⟹ card (prime_factors n) = Suc 0›*) assume "primepow (normalize n)" (*‹primepow (normalize (n::'a))›*) then obtain p and k where pk: "prime p" "normalize n = p ^ k" "k > 0" (*goal: ‹(⋀p k. ⟦prime p; normalize n = p ^ k; 0 < k⟧ ⟹ thesis) ⟹ thesis›*) by (auto simp: primepow_def (*‹primepow ?n = (∃p k. prime p ∧ 0 < k ∧ ?n = p ^ k)›*)) hence "card (prime_factors (normalize n)) = Suc 0" apply (subst pk (*‹prime p› ‹normalize n = p ^ k› ‹0 < k›*)) (*goal: ‹card (prime_factors (normalize (n::'a))) = Suc (0::nat)›*) by (simp add: prime_factors_power (*‹0 < ?n ⟹ prime_factors (?x ^ ?n) = prime_factors ?x›*) prime_factorization_prime (*‹prime ?p ⟹ prime_factorization ?p = {#?p#}›*)) thus "card (prime_factors n) = Suc 0" by simp next (*goal: ‹card (prime_factors n) = Suc 0 ⟹ primepow (normalize n)›*) assume "*": "card (prime_factors n) = Suc 0" (*‹card (prime_factors (n::'a)) = Suc (0::nat)›*) from "*" (*‹card (prime_factors n) = Suc 0›*) have "(∏p∈prime_factors n. p ^ multiplicity p n) = normalize n" apply (intro prod_prime_factors (*‹?x ≠ 0 ⟹ (∏p∈prime_factors ?x. p ^ multiplicity p ?x) = normalize ?x›*)) (*goal: ‹(∏p∈prime_factors n. p ^ multiplicity p n) = normalize n›*) by auto also (*calculation: ‹(∏p::'a::factorial_semiring_multiplicative∈prime_factors n. p ^ multiplicity p (n::'a::factorial_semiring_multiplicative)) = normalize n›*) from "*" (*‹card (prime_factors n) = Suc 0›*) have "card (prime_factors n) = 1" by simp then obtain p where p: "prime_factors n = {p}" (*goal: ‹(⋀p. prime_factors n = {p} ⟹ thesis) ⟹ thesis›*) by (elim card_1_singletonE (*‹⟦card (?A::?'a::type set) = (1::nat); ⋀x::?'a::type. ?A = {x} ⟹ ?thesis::bool⟧ ⟹ ?thesis›*)) finally (*calculation: ‹(∏p∈{p}. p ^ multiplicity p n) = normalize n›*) have "normalize n = p ^ multiplicity p n" by simp moreover from p (*‹prime_factors n = {p}›*) have "prime p" "multiplicity p n > 0" apply - (*goals: 1. ‹prime_factors n = {p} ⟹ prime p› 2. ‹prime_factors n = {p} ⟹ 0 < multiplicity p n› discuss goal 1*) apply ((auto simp: prime_factors_multiplicity (*‹prime_factors ?n = {p. prime p ∧ 0 < multiplicity p ?n}›*))[1]) (*discuss goal 2*) apply ((auto simp: prime_factors_multiplicity (*‹prime_factors ?n = {p. prime p ∧ 0 < multiplicity p ?n}›*))[1]) (*proven 2 subgoals*) . ultimately show "primepow (normalize n)" unfolding primepow_def (*goal: ‹∃p k. prime p ∧ 0 < k ∧ normalize n = p ^ k›*) by blast qed lemma squarefree_imp_prod_prime_factors_eq: fixes x :: "'a :: factorial_semiring_multiplicative" assumes "squarefree x" shows "∏(prime_factors x) = normalize x" proof (-) (*goal: ‹∏(prime_factors (x::'a)) = normalize x›*) from assms (*‹squarefree (x::'a)›*) have [simp]: "x ≠ 0" by auto have "(∏p∈prime_factors x. p ^ multiplicity p x) = normalize x" apply (intro prod_prime_factors (*‹?x ≠ 0 ⟹ (∏p∈prime_factors ?x. p ^ multiplicity p ?x) = normalize ?x›*)) (*goal: ‹(∏p∈prime_factors x. p ^ multiplicity p x) = normalize x›*) by auto also (*calculation: ‹(∏p::'a::factorial_semiring_multiplicative∈prime_factors x. p ^ multiplicity p (x::'a::factorial_semiring_multiplicative)) = normalize x›*) have "(∏p∈prime_factors x. p ^ multiplicity p x) = (∏p∈prime_factors x. p)" using assms (*‹squarefree x›*) apply (intro prod.cong (*‹⟦?A = ?B; ⋀x. x ∈ ?B ⟹ ?g x = ?h x⟧ ⟹ prod ?g ?A = prod ?h ?B›*) refl (*‹?t = ?t›*)) (*goal: ‹(∏p∈prime_factors x. p ^ multiplicity p x) = ∏(prime_factors x)›*) by (auto simp: squarefree_factorial_semiring' (*‹(?n::?'a) ≠ (0::?'a) ⟹ squarefree ?n = (∀p::?'a∈#prime_factorization ?n. multiplicity p ?n = (1::nat))›*)) finally (*calculation: ‹∏(prime_factors x) = normalize x›*) show "?thesis" (*goal: ‹∏(prime_factors x) = normalize x›*) by simp qed (* END TODO *) end
{ "path": "afp-2025-02-12/thys/Probabilistic_Prime_Tests/Algebraic_Auxiliaries.thy", "repo": "afp-2025-02-12", "sha": "7ac0539a36576565393103bde5a966cbedf712ff7e230fa0f942a596e10fd874" }
(*<*) (* * Copyright 2015, NICTA * * This software may be distributed and modified according to the terms of * the BSD 2-Clause license. Note that NO WARRANTY is provided. * See "LICENSE_BSD2.txt" for details. * * @TAG(NICTA_BSD) *) theory Phases imports Global_Invariants_Lemmas Local_Invariants_Lemmas Tactics begin (*>*) section‹Handshake phases› text‹ Reasoning about phases, handshakes. Tie the garbage collector's control location to the value of @{const "gc_phase"}. › lemma (in gc) phase_invL_eq_imp: "eq_imp (λ(_::unit) s. (AT s gc, s↓ gc, tso_pending_phase gc s↓)) phase_invL" by (clarsimp simp: eq_imp_def (*‹eq_imp ?f ?g ≡ ∀s s'. (∀x. ?f x s = ?f x s') ⟶ ?g s = ?g s'›*) inv (*‹tso_lock_invL = (λs. (atS gc tso_lock_locs s ⟶ sys_mem_lock s↓ = Some gc) ∧ (atS gc (- tso_lock_locs) s ⟶ sys_mem_lock s↓ ≠ Some gc))› ‹handshake_invL = (λs. (atS gc hs_noop_locs s ⟶ sys_hs_type s↓ = ht_NOOP) ∧ (atS gc hs_get_roots_locs s ⟶ sys_hs_type s↓ = ht_GetRoots) ∧ (atS gc hs_get_work_locs s ⟶ sys_hs_type s↓ = ht_GetWork) ∧ (atS gc hs_mut_in_muts_locs s ⟶ gc_mut s↓ ∈ gc_muts s↓) ∧ (atS gc hs_init_loop_locs s ⟶ (∀x. x ∉ gc_muts s↓ ⟶ sys_hs_pending x s↓ ∨ sys_ghost_hs_in_sync x s↓)) ∧ (atS gc hs_init_loop_not_done_locs s ⟶ (∀x. x ∈ gc_muts s↓ ⟶ ¬ sys_hs_pending x s↓ ∧ ¬ sys_ghost_hs_in_sync x s↓)) ∧ (atS gc hs_init_loop_done_locs s ⟶ (sys_hs_pending (gc_mut s↓) s↓ ∨ sys_ghost_hs_in_sync (gc_mut s↓) s↓) ∧ (∀x. x ∈ gc_muts s↓ ∧ x ≠ gc_mut s↓ ⟶ ¬ sys_hs_pending x s↓ ∧ ¬ sys_ghost_hs_in_sync x s↓)) ∧ (atS gc hs_done_locs s ⟶ (∀x. sys_hs_pending x s↓ ∨ sys_ghost_hs_in_sync x s↓)) ∧ (atS gc hs_done_loop_locs s ⟶ (∀x. x ∉ gc_muts s↓ ⟶ ¬ sys_hs_pending x s↓)) ∧ (atS gc hs_none_pending_locs s ⟶ (∀x. ¬ sys_hs_pending x s↓)) ∧ (atS gc hs_in_sync_locs s ⟶ (∀x. sys_ghost_hs_in_sync x s↓)) ∧ (atS gc hs_out_of_sync_locs s ⟶ (∀x. ¬ sys_hs_pending x s↓ ∧ ¬ sys_ghost_hs_in_sync x s↓)) ∧ (atS gc hp_Idle_locs s ⟶ sys_ghost_hs_phase s↓ = hp_Idle) ∧ (atS gc hp_IdleInit_locs s ⟶ sys_ghost_hs_phase s↓ = hp_IdleInit) ∧ (atS gc hp_InitMark_locs s ⟶ sys_ghost_hs_phase s↓ = hp_InitMark) ∧ (atS gc hp_IdleMarkSweep_locs s ⟶ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep) ∧ (atS gc hp_Mark_locs s ⟶ sys_ghost_hs_phase s↓ = hp_Mark))› ‹phase_invL = (λs. (atS gc idle_locs s ⟶ gc_phase s↓ = ph_Idle) ∧ (atS gc init_locs s ⟶ gc_phase s↓ = ph_Init) ∧ (atS gc mark_locs s ⟶ gc_phase s↓ = ph_Mark) ∧ (atS gc sweep_locs s ⟶ gc_phase s↓ = ph_Sweep) ∧ (atS gc no_pending_phase_locs s ⟶ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []))› ‹fM_fA_invL = (λs. (atS gc fM_eq_locs s ⟶ gc_fM s↓ = sys_fM s↓) ∧ (at gc idle_store_fM s ⟶ gc_fM s↓ ≠ sys_fM s↓) ∧ (at gc idle_flip_noop_mfence s ⟶ sys_fM s↓ ≠ gc_fM s↓ ⟶ filter is_mw_fM (sys_mem_store_buffers gc s↓) ≠ []) ∧ (atS gc fM_tso_empty_locs s ⟶ filter is_mw_fM (sys_mem_store_buffers gc s↓) = []) ∧ (atS gc fA_eq_locs s ⟶ gc_fM s↓ = sys_fA s↓) ∧ (atS gc fA_neq_locs s ⟶ gc_fM s↓ ≠ sys_fA s↓) ∧ (at gc mark_noop_mfence s ⟶ gc_fM s↓ ≠ sys_fA s↓ ⟶ filter is_mw_fA (sys_mem_store_buffers gc s↓) ≠ []) ∧ (atS gc fA_tso_empty_locs s ⟶ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []))› ‹gc_mark.mark_object_invL = (λs. (at gc mark_loop_mo_mark s ⟶ (∃y. gc_ref s↓ = Some y) ∧ obj_at (λobj. True) (the (gc_ref s↓)) s↓) ∧ (at gc mark_loop_mo_fM s ⟶ (∃y. gc_ref s↓ = Some y) ∧ obj_at (λobj. True) (the (gc_ref s↓)) s↓ ∧ (∃y. gc_mark s↓ = Some y) ∧ (obj_at (λobj. Some (obj_mark obj) = gc_mark s↓) (the (gc_ref s↓)) s↓ ∨ marked (the (gc_ref s↓)) s↓)) ∧ (at gc mark_loop_mo_mtest s ⟶ (∃y. gc_ref s↓ = Some y) ∧ obj_at (λobj. True) (the (gc_ref s↓)) s↓ ∧ (∃y. gc_mark s↓ = Some y) ∧ (obj_at (λobj. Some (obj_mark obj) = gc_mark s↓) (the (gc_ref s↓)) s↓ ∨ marked (the (gc_ref s↓)) s↓) ∧ gc_fM s↓ = sys_fM s↓) ∧ (at gc mark_loop_mo_phase s ⟶ (∃y. gc_ref s↓ = Some y) ∧ obj_at (λobj. True) (the (gc_ref s↓)) s↓ ∧ gc_mark s↓ ≠ Some (gc_fM s↓) ∧ (∃y. gc_mark s↓ = Some y) ∧ (obj_at (λobj. Some (obj_mark obj) = gc_mark s↓) (the (gc_ref s↓)) s↓ ∨ marked (the (gc_ref s↓)) s↓) ∧ gc_fM s↓ = sys_fM s↓) ∧ (at gc mark_loop_mo_ptest s ⟶ (∃y. gc_ref s↓ = Some y) ∧ obj_at (λobj. True) (the (gc_ref s↓)) s↓ ∧ gc_mark s↓ ≠ Some (gc_fM s↓) ∧ (∃y. gc_mark s↓ = Some y) ∧ (obj_at (λobj. Some (obj_mark obj) = gc_mark s↓) (the (gc_ref s↓)) s↓ ∨ marked (the (gc_ref s↓)) s↓) ∧ gc_fM s↓ = sys_fM s↓) ∧ (at gc mark_loop_mo_co_lock s ⟶ (∃y. gc_ref s↓ = Some y) ∧ obj_at (λobj. True) (the (gc_ref s↓)) s↓ ∧ (∃y. gc_mark s↓ = Some y) ∧ (obj_at (λobj. Some (obj_mark obj) = gc_mark s↓) (the (gc_ref s↓)) s↓ ∨ marked (the (gc_ref s↓)) s↓) ∧ gc_fM s↓ = sys_fM s↓ ∧ gc_mark s↓ ≠ Some (gc_fM s↓) ∧ filter is_mw_Mark (sys_mem_store_buffers gc s↓) = []) ∧ (at gc mark_loop_mo_co_cmark s ⟶ (∃y. gc_ref s↓ = Some y) ∧ obj_at (λobj. True) (the (gc_ref s↓)) s↓ ∧ (∃y. gc_mark s↓ = Some y) ∧ (obj_at (λobj. Some (obj_mark obj) = gc_mark s↓) (the (gc_ref s↓)) s↓ ∨ marked (the (gc_ref s↓)) s↓) ∧ gc_fM s↓ = sys_fM s↓ ∧ gc_mark s↓ ≠ Some (gc_fM s↓) ∧ filter is_mw_Mark (sys_mem_store_buffers gc s↓) = []) ∧ (at gc mark_loop_mo_co_ctest s ⟶ (∃y. gc_ref s↓ = Some y) ∧ obj_at (λobj. True) (the (gc_ref s↓)) s↓ ∧ (∃y. gc_mark s↓ = Some y) ∧ (obj_at (λobj. Some (obj_mark obj) = gc_mark s↓) (the (gc_ref s↓)) s↓ ∨ marked (the (gc_ref s↓)) s↓) ∧ gc_fM s↓ = sys_fM s↓ ∧ gc_mark s↓ ≠ Some (gc_fM s↓) ∧ obj_at (λobj. Some (obj_mark obj) = gc_cas_mark s↓) (the (gc_ref s↓)) s↓ ∧ filter is_mw_Mark (sys_mem_store_buffers gc s↓) = []) ∧ (at gc mark_loop_mo_co_mark s ⟶ gc_cas_mark s↓ = gc_mark s↓ ∧ (∃y. gc_ref s↓ = Some y) ∧ obj_at (λobj. True) (the (gc_ref s↓)) s↓ ∧ gc_fM s↓ = sys_fM s↓ ∧ white (the (gc_ref s↓)) s↓ ∧ filter is_mw_Mark (sys_mem_store_buffers gc s↓) = []) ∧ (at gc mark_loop_mo_co_unlock s ⟶ (if gc_cas_mark s↓ = gc_mark s↓ then gc_ghost_honorary_grey s↓ = {gc_the_ref s↓} else gc_ghost_honorary_grey s↓ = {}) ∧ (∃y. gc_ref s↓ = Some y) ∧ obj_at (λobj. True) (the (gc_ref s↓)) s↓ ∧ gc_fM s↓ = sys_fM s↓ ∧ ((gc_cas_mark s↓ = gc_mark s↓ ⟶ filter is_mw_Mark (sys_mem_store_buffers gc s↓) = []) ⟶ marked (the (gc_ref s↓)) s↓) ∧ (filter is_mw_Mark (sys_mem_store_buffers gc s↓) = [] ∨ filter is_mw_Mark (sys_mem_store_buffers gc s↓) = [mw_Mark (the (gc_ref s↓)) (gc_fM s↓)])) ∧ (at gc mark_loop_mo_co_won s ⟶ (if gc_cas_mark s↓ = gc_mark s↓ then gc_ghost_honorary_grey s↓ = {gc_the_ref s↓} else gc_ghost_honorary_grey s↓ = {}) ∧ (∃y. gc_ref s↓ = Some y) ∧ obj_at (λobj. True) (the (gc_ref s↓)) s↓ ∧ gc_fM s↓ = sys_fM s↓ ∧ marked (the (gc_ref s↓)) s↓ ∧ filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = []) ∧ (at gc mark_loop_mo_co_W s ⟶ gc_ghost_honorary_grey s↓ = {the (gc_ref s↓)} ∧ (∃y. gc_ref s↓ = Some y) ∧ obj_at (λobj. True) (the (gc_ref s↓)) s↓ ∧ gc_fM s↓ = sys_fM s↓ ∧ marked (the (gc_ref s↓)) s↓ ∧ filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers gc s↓) = []))› ‹gc_W_empty_invL = (λs. (atS gc get_roots_UN_get_work_locs s ⟶ (∀x. mut_m.gc_W_empty_mut_inv x s↓)) ∧ (at gc mark_loop_get_roots_load_W s ⟶ sys_W s↓ = {} ⟶ no_grey_refs s↓) ∧ (at gc mark_loop_get_work_load_W s ⟶ sys_W s↓ = {} ⟶ no_grey_refs s↓) ∧ (at gc mark_loop s ⟶ gc_W s↓ = {} ⟶ no_grey_refs s↓) ∧ (atS gc no_grey_refs_locs s ⟶ no_grey_refs s↓) ∧ (atS gc gc_W_empty_locs s ⟶ gc_W s↓ = {}))› ‹sweep_loop_invL = (λs. (at gc sweep_loop_check s ⟶ (gc_mark s↓ ≠ None ⟶ obj_at (λobj. Some (obj_mark obj) = gc_mark s↓) (gc_tmp_ref s↓) s↓) ∧ (gc_mark s↓ = None ∧ obj_at (λs. True) (gc_tmp_ref s↓) s↓ ⟶ marked (gc_tmp_ref s↓) s↓)) ∧ (at gc sweep_loop_free s ⟶ gc_mark s↓ ≠ None ∧ (the ∘ gc_mark) s↓ ≠ gc_fM s↓ ∧ obj_at (λobj. Some (obj_mark obj) = gc_mark s↓) (gc_tmp_ref s↓) s↓) ∧ (at gc sweep_loop_ref_done s ⟶ obj_at (λs. True) (gc_tmp_ref s↓) s↓ ⟶ marked (gc_tmp_ref s↓) s↓) ∧ (atS gc sweep_loop_locs s ⟶ (∀x. x ∉ gc_refs s↓ ∧ obj_at (λs. True) x s↓ ⟶ marked x s↓)) ∧ (atS gc black_heap_locs s ⟶ (∀x. obj_at (λs. True) x s↓ ⟶ marked x s↓)) ∧ (atS gc sweep_loop_not_choose_ref_locs s ⟶ gc_tmp_ref s↓ ∈ gc_refs s↓))› ‹obj_fields_marked_invL = (λs. (atS gc obj_fields_marked_locs s ⟶ obj_fields_marked s↓ ∧ gc_tmp_ref s↓ ∈ gc_W s↓) ∧ (atS gc obj_fields_marked_good_ref_locs s ⟶ obj_at_field_on_heap (λr. gc_ref s↓ = Some r ∨ marked r s↓) (gc_tmp_ref s↓) (gc_field s↓) s↓) ∧ (atS gc mark_loop_mo_locs s ⟶ (∀x. gc_ref s↓ ≠ None ∧ (gc_the_ref s↓ reaches x) s↓ ⟶ obj_at (λs. True) x s↓)) ∧ (at gc mark_loop_fields s ⟶ gc_tmp_ref s↓ ∈ gc_W s↓) ∧ (at gc mark_loop_mark_field_done s ⟶ gc_ref s↓ ≠ None ⟶ marked (gc_the_ref s↓) s↓) ∧ (at gc mark_loop_blacken s ⟶ gc_field_set s↓ = {}) ∧ (atS gc ghost_honorary_grey_empty_locs s ⟶ gc_ghost_honorary_grey s↓ = {}))›*)) lemmas gc_phase_invL_niE[nie] = iffD1[OF gc.phase_invL_eq_imp[simplified eq_imp_simps, rule_format, unfolded conj_explode], rotated -1] lemma (in gc) phase_invL[intro]: "⦃ phase_invL ❙∧ LSTP phase_rel_inv ⦄ gc ⦃ phase_invL ⦄" apply vcg_jackhammer (*goal: ‹⦃λs. phase_invL s ∧ phase_rel_inv s↓⦄ gc ⦃phase_invL⦄›*) by (fastforce dest!: phase_rel_invD (*‹phase_rel_inv ?s ⟹ (∀m. sys_ghost_hs_in_sync m ?s, sys_ghost_hs_phase ?s, gc_phase ?s, sys_phase ?s, filter is_mw_Phase (sys_mem_store_buffers gc ?s)) ∈ phase_rel›*) simp: phase_rel_def (*‹phase_rel = {(in_sync, hp, ph, ph, []) |in_sync hp ph. handshake_phase_rel hp in_sync ph} ∪ {True} × {(hp_IdleInit, ph_Init, ph_Idle, [mw_Phase ph_Init]), (hp_InitMark, ph_Mark, ph_Init, [mw_Phase ph_Mark]), (hp_IdleMarkSweep, ph_Sweep, ph_Mark, [mw_Phase ph_Sweep]), (hp_IdleMarkSweep, ph_Idle, ph_Mark, [mw_Phase ph_Sweep, mw_Phase ph_Idle]), (hp_IdleMarkSweep, ph_Idle, ph_Sweep, [mw_Phase ph_Idle])}›*)) lemma (in sys) gc_phase_invL[intro]: notes fun_upd_apply[simp] notes if_splits[split] shows "⦃ gc.phase_invL ⦄ sys" by (vcg_chainsaw gc.phase_invL_def) lemma (in mut_m) gc_phase_invL[intro]: "⦃ gc.phase_invL ⦄ mutator m" by (vcg_chainsaw gc.phase_invL_def[inv]) lemma (in gc) phase_rel_inv[intro]: "⦃ handshake_invL ❙∧ phase_invL ❙∧ LSTP phase_rel_inv ⦄ gc ⦃ LSTP phase_rel_inv ⦄" unfolding phase_rel_inv_def (*goal: ‹⦃λs. handshake_invL s ∧ phase_invL s ∧ (All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel⦄ gc ⦃λs. (All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel⦄›*) apply (vcg_jackhammer (no_thin_post_inv)) (*goals: 1. ‹⋀s s'. ⟦at gc sweep_idle s; at sys sys.tso_store s; s'↓ = s↓(gc := s↓ gc⦇phase := ph_Idle⦈, sys := s↓ sys⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := sys_mem_store_buffers gc s↓ @ [mw_Phase ph_Idle])⦈); taken gc sweep_idle s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; (All (ghost_hs_in_sync (s↓ sys)), hp_IdleMarkSweep, ph_Sweep, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel; gc_phase s↓ = ph_Sweep; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep⟧ ⟹ (All (ghost_hs_in_sync (s↓ sys)), hp_IdleMarkSweep, ph_Idle, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓) @ [mw_Phase ph_Idle]) ∈ phase_rel› 2. ‹⋀s s'. ⟦at gc mark_end s; at sys sys.tso_store s; s'↓ = s↓(gc := s↓ gc⦇phase := ph_Sweep⦈, sys := s↓ sys⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := sys_mem_store_buffers gc s↓ @ [mw_Phase ph_Sweep])⦈); taken gc mark_end s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; (All (ghost_hs_in_sync (s↓ sys)), hp_IdleMarkSweep, ph_Mark, sys_phase s↓, []) ∈ phase_rel; gc_phase s↓ = ph_Mark; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep⟧ ⟹ (All (ghost_hs_in_sync (s↓ sys)), hp_IdleMarkSweep, ph_Sweep, sys_phase s↓, [mw_Phase ph_Sweep]) ∈ phase_rel› 3. ‹⋀s s'. ⟦at gc mark_loop_get_work_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_GetWork, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_IdleMarkSweep⦈); taken gc mark_loop_get_work_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; (All (ghost_hs_in_sync (s↓ sys)), hp_IdleMarkSweep, ph_Mark, sys_phase s↓, []) ∈ phase_rel; gc_phase s↓ = ph_Mark; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep⟧ ⟹ (False, hp_IdleMarkSweep, ph_Mark, sys_phase s↓, []) ∈ phase_rel› 4. ‹⋀s s'. ⟦at gc mark_loop_mo_phase s; at sys sys.tso_load s; s'↓ = s↓(gc := s↓ gc⦇phase := sys_phase s↓⦈, sys := s↓ sys); taken gc mark_loop_mo_phase s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; (All (ghost_hs_in_sync (s↓ sys)), hp_IdleMarkSweep, ph_Mark, sys_phase s↓, []) ∈ phase_rel; not_blocked (s↓ sys) gc; gc_phase s↓ = ph_Mark; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep⟧ ⟹ (All (ghost_hs_in_sync (s↓ sys)), hp_IdleMarkSweep, sys_phase s↓, sys_phase s↓, []) ∈ phase_rel› 5. ‹⋀s s'. ⟦at gc mark_loop_get_roots_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_GetRoots, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_IdleMarkSweep⦈); taken gc mark_loop_get_roots_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; (All (ghost_hs_in_sync (s↓ sys)), hp_Mark, ph_Mark, sys_phase s↓, []) ∈ phase_rel; gc_phase s↓ = ph_Mark; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_Mark⟧ ⟹ (False, hp_IdleMarkSweep, ph_Mark, sys_phase s↓, []) ∈ phase_rel› 6. ‹⋀s s'. ⟦at gc mark_noop_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_NOOP, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_Mark⦈); taken gc mark_noop_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; (All (ghost_hs_in_sync (s↓ sys)), hp_InitMark, ph_Mark, sys_phase s↓, []) ∈ phase_rel; gc_phase s↓ = ph_Mark; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_InitMark⟧ ⟹ (False, hp_Mark, ph_Mark, sys_phase s↓, []) ∈ phase_rel› 7. ‹⋀s s'. ⟦at gc init_phase_mark s; at sys sys.tso_store s; s'↓ = s↓(gc := s↓ gc⦇phase := ph_Mark⦈, sys := s↓ sys⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := sys_mem_store_buffers gc s↓ @ [mw_Phase ph_Mark])⦈); taken gc init_phase_mark s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; (All (ghost_hs_in_sync (s↓ sys)), hp_InitMark, ph_Init, sys_phase s↓, []) ∈ phase_rel; gc_phase s↓ = ph_Init; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_InitMark⟧ ⟹ (All (ghost_hs_in_sync (s↓ sys)), hp_InitMark, ph_Mark, sys_phase s↓, [mw_Phase ph_Mark]) ∈ phase_rel› 8. ‹⋀s s'. ⟦at gc init_noop_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_NOOP, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_InitMark⦈); taken gc init_noop_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; (All (ghost_hs_in_sync (s↓ sys)), hp_IdleInit, ph_Init, sys_phase s↓, []) ∈ phase_rel; gc_phase s↓ = ph_Init; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleInit⟧ ⟹ (False, hp_InitMark, ph_Init, sys_phase s↓, []) ∈ phase_rel› 9. ‹⋀s s'. ⟦at gc idle_phase_init s; at sys sys.tso_store s; s'↓ = s↓(gc := s↓ gc⦇phase := ph_Init⦈, sys := s↓ sys⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := sys_mem_store_buffers gc s↓ @ [mw_Phase ph_Init])⦈); taken gc idle_phase_init s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; (All (ghost_hs_in_sync (s↓ sys)), hp_IdleInit, ph_Idle, sys_phase s↓, []) ∈ phase_rel; gc_phase s↓ = ph_Idle; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleInit⟧ ⟹ (All (ghost_hs_in_sync (s↓ sys)), hp_IdleInit, ph_Init, sys_phase s↓, [mw_Phase ph_Init]) ∈ phase_rel› 10. ‹⋀s s'. ⟦at gc idle_flip_noop_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_NOOP, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_IdleInit⦈); taken gc idle_flip_noop_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; (All (ghost_hs_in_sync (s↓ sys)), hp_Idle, ph_Idle, sys_phase s↓, []) ∈ phase_rel; gc_phase s↓ = ph_Idle; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_Idle⟧ ⟹ (False, hp_IdleInit, ph_Idle, sys_phase s↓, []) ∈ phase_rel› 11. ‹⋀s s'. ⟦at gc idle_noop_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_NOOP, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_Idle⦈); taken gc idle_noop_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; (All (ghost_hs_in_sync (s↓ sys)), hp_IdleMarkSweep, ph_Idle, sys_phase s↓, []) ∈ phase_rel; gc_phase s↓ = ph_Idle; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep⟧ ⟹ (False, hp_Idle, ph_Idle, sys_phase s↓, []) ∈ phase_rel› discuss goal 1*) apply (simp add: phase_rel_def (*‹phase_rel = {(in_sync, hp, ph, ph, []) |in_sync hp ph. handshake_phase_rel hp in_sync ph} ∪ {True} × {(hp_IdleInit, ph_Init, ph_Idle, [mw_Phase ph_Init]), (hp_InitMark, ph_Mark, ph_Init, [mw_Phase ph_Mark]), (hp_IdleMarkSweep, ph_Sweep, ph_Mark, [mw_Phase ph_Sweep]), (hp_IdleMarkSweep, ph_Idle, ph_Mark, [mw_Phase ph_Sweep, mw_Phase ph_Idle]), (hp_IdleMarkSweep, ph_Idle, ph_Sweep, [mw_Phase ph_Idle])}›*)) (*top goal: ‹⋀s s'. ⟦at gc sweep_idle s; at sys sys.tso_store s; s'↓ = s↓(gc := s↓ gc⦇phase := ph_Idle⦈, sys := s↓ sys⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := sys_mem_store_buffers gc s↓ @ [mw_Phase ph_Idle])⦈); taken gc sweep_idle s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; (All (ghost_hs_in_sync (s↓ sys)), hp_IdleMarkSweep, ph_Sweep, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel; gc_phase s↓ = ph_Sweep; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep⟧ ⟹ (All (ghost_hs_in_sync (s↓ sys)), hp_IdleMarkSweep, ph_Idle, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓) @ [mw_Phase ph_Idle]) ∈ phase_rel› and 10 goals remain*) apply blast (*discuss goal 2*) apply (simp add: phase_rel_def (*‹phase_rel = {(in_sync, hp, ph, ph, []) |in_sync hp ph. handshake_phase_rel hp in_sync ph} ∪ {True} × {(hp_IdleInit, ph_Init, ph_Idle, [mw_Phase ph_Init]), (hp_InitMark, ph_Mark, ph_Init, [mw_Phase ph_Mark]), (hp_IdleMarkSweep, ph_Sweep, ph_Mark, [mw_Phase ph_Sweep]), (hp_IdleMarkSweep, ph_Idle, ph_Mark, [mw_Phase ph_Sweep, mw_Phase ph_Idle]), (hp_IdleMarkSweep, ph_Idle, ph_Sweep, [mw_Phase ph_Idle])}›*)) (*discuss goal 3*) apply (simp add: phase_rel_def (*‹phase_rel = {(in_sync, hp, ph, ph, []) |in_sync hp ph. handshake_phase_rel hp in_sync ph} ∪ {True} × {(hp_IdleInit, ph_Init, ph_Idle, [mw_Phase ph_Init]), (hp_InitMark, ph_Mark, ph_Init, [mw_Phase ph_Mark]), (hp_IdleMarkSweep, ph_Sweep, ph_Mark, [mw_Phase ph_Sweep]), (hp_IdleMarkSweep, ph_Idle, ph_Mark, [mw_Phase ph_Sweep, mw_Phase ph_Idle]), (hp_IdleMarkSweep, ph_Idle, ph_Sweep, [mw_Phase ph_Idle])}›*)) (*top goal: ‹⋀s s'. ⟦at gc mark_loop_get_work_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_GetWork, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_IdleMarkSweep⦈); taken gc mark_loop_get_work_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; (All (ghost_hs_in_sync (s↓ sys)), hp_IdleMarkSweep, ph_Mark, sys_phase s↓, []) ∈ phase_rel; gc_phase s↓ = ph_Mark; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep⟧ ⟹ (False, hp_IdleMarkSweep, ph_Mark, sys_phase s↓, []) ∈ phase_rel› and 8 goals remain*) apply blast (*discuss goal 4*) apply (simp add: phase_rel_def (*‹phase_rel = {(in_sync, hp, ph, ph, []) |in_sync hp ph. handshake_phase_rel hp in_sync ph} ∪ {True} × {(hp_IdleInit, ph_Init, ph_Idle, [mw_Phase ph_Init]), (hp_InitMark, ph_Mark, ph_Init, [mw_Phase ph_Mark]), (hp_IdleMarkSweep, ph_Sweep, ph_Mark, [mw_Phase ph_Sweep]), (hp_IdleMarkSweep, ph_Idle, ph_Mark, [mw_Phase ph_Sweep, mw_Phase ph_Idle]), (hp_IdleMarkSweep, ph_Idle, ph_Sweep, [mw_Phase ph_Idle])}›*)) (*discuss goal 5*) apply (simp add: phase_rel_def (*‹phase_rel = {(in_sync, hp, ph, ph, []) |(in_sync::bool) (hp::hs_phase) ph::gc_phase. handshake_phase_rel hp in_sync ph} ∪ {True} × {(hp_IdleInit, ph_Init, ph_Idle, [mw_Phase ph_Init]), (hp_InitMark, ph_Mark, ph_Init, [mw_Phase ph_Mark]), (hp_IdleMarkSweep, ph_Sweep, ph_Mark, [mw_Phase ph_Sweep]), (hp_IdleMarkSweep, ph_Idle, ph_Mark, [mw_Phase ph_Sweep, mw_Phase ph_Idle]), (hp_IdleMarkSweep, ph_Idle, ph_Sweep, [mw_Phase ph_Idle])}›*)) (*top goal: ‹⋀s s'. ⟦at gc mark_loop_get_roots_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_GetRoots, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_IdleMarkSweep⦈); taken gc mark_loop_get_roots_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; (All (ghost_hs_in_sync (s↓ sys)), hp_Mark, ph_Mark, sys_phase s↓, []) ∈ phase_rel; gc_phase s↓ = ph_Mark; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_Mark⟧ ⟹ (False, hp_IdleMarkSweep, ph_Mark, sys_phase s↓, []) ∈ phase_rel› and 6 goals remain*) apply blast (*discuss goal 6*) apply (simp add: phase_rel_def (*‹phase_rel = {(in_sync, hp, ph, ph, []) |in_sync hp ph. handshake_phase_rel hp in_sync ph} ∪ {True} × {(hp_IdleInit, ph_Init, ph_Idle, [mw_Phase ph_Init]), (hp_InitMark, ph_Mark, ph_Init, [mw_Phase ph_Mark]), (hp_IdleMarkSweep, ph_Sweep, ph_Mark, [mw_Phase ph_Sweep]), (hp_IdleMarkSweep, ph_Idle, ph_Mark, [mw_Phase ph_Sweep, mw_Phase ph_Idle]), (hp_IdleMarkSweep, ph_Idle, ph_Sweep, [mw_Phase ph_Idle])}›*)) (*top goal: ‹⋀s s'. ⟦at gc mark_noop_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_NOOP, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_Mark⦈); taken gc mark_noop_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; (All (ghost_hs_in_sync (s↓ sys)), hp_InitMark, ph_Mark, sys_phase s↓, []) ∈ phase_rel; gc_phase s↓ = ph_Mark; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_InitMark⟧ ⟹ (False, hp_Mark, ph_Mark, sys_phase s↓, []) ∈ phase_rel› and 5 goals remain*) apply blast (*discuss goal 7*) apply (simp add: phase_rel_def (*‹phase_rel = {(in_sync, hp, ph, ph, []) |(in_sync::bool) (hp::hs_phase) ph::gc_phase. handshake_phase_rel hp in_sync ph} ∪ {True} × {(hp_IdleInit, ph_Init, ph_Idle, [mw_Phase ph_Init]), (hp_InitMark, ph_Mark, ph_Init, [mw_Phase ph_Mark]), (hp_IdleMarkSweep, ph_Sweep, ph_Mark, [mw_Phase ph_Sweep]), (hp_IdleMarkSweep, ph_Idle, ph_Mark, [mw_Phase ph_Sweep, mw_Phase ph_Idle]), (hp_IdleMarkSweep, ph_Idle, ph_Sweep, [mw_Phase ph_Idle])}›*)) (*discuss goal 8*) apply (simp add: phase_rel_def (*‹phase_rel = {(in_sync, hp, ph, ph, []) |in_sync hp ph. handshake_phase_rel hp in_sync ph} ∪ {True} × {(hp_IdleInit, ph_Init, ph_Idle, [mw_Phase ph_Init]), (hp_InitMark, ph_Mark, ph_Init, [mw_Phase ph_Mark]), (hp_IdleMarkSweep, ph_Sweep, ph_Mark, [mw_Phase ph_Sweep]), (hp_IdleMarkSweep, ph_Idle, ph_Mark, [mw_Phase ph_Sweep, mw_Phase ph_Idle]), (hp_IdleMarkSweep, ph_Idle, ph_Sweep, [mw_Phase ph_Idle])}›*)) (*top goal: ‹⋀s s'. ⟦at gc init_noop_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_NOOP, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_InitMark⦈); taken gc init_noop_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; (All (ghost_hs_in_sync (s↓ sys)), hp_IdleInit, ph_Init, sys_phase s↓, []) ∈ phase_rel; gc_phase s↓ = ph_Init; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleInit⟧ ⟹ (False, hp_InitMark, ph_Init, sys_phase s↓, []) ∈ phase_rel› and 3 goals remain*) apply blast (*discuss goal 9*) apply (simp add: phase_rel_def (*‹phase_rel = {(in_sync, hp, ph, ph, []) |in_sync hp ph. handshake_phase_rel hp in_sync ph} ∪ {True} × {(hp_IdleInit, ph_Init, ph_Idle, [mw_Phase ph_Init]), (hp_InitMark, ph_Mark, ph_Init, [mw_Phase ph_Mark]), (hp_IdleMarkSweep, ph_Sweep, ph_Mark, [mw_Phase ph_Sweep]), (hp_IdleMarkSweep, ph_Idle, ph_Mark, [mw_Phase ph_Sweep, mw_Phase ph_Idle]), (hp_IdleMarkSweep, ph_Idle, ph_Sweep, [mw_Phase ph_Idle])}›*)) (*discuss goal 10*) apply (simp add: phase_rel_def (*‹phase_rel = {(in_sync, hp, ph, ph, []) |in_sync hp ph. handshake_phase_rel hp in_sync ph} ∪ {True} × {(hp_IdleInit, ph_Init, ph_Idle, [mw_Phase ph_Init]), (hp_InitMark, ph_Mark, ph_Init, [mw_Phase ph_Mark]), (hp_IdleMarkSweep, ph_Sweep, ph_Mark, [mw_Phase ph_Sweep]), (hp_IdleMarkSweep, ph_Idle, ph_Mark, [mw_Phase ph_Sweep, mw_Phase ph_Idle]), (hp_IdleMarkSweep, ph_Idle, ph_Sweep, [mw_Phase ph_Idle])}›*)) (*top goal: ‹⋀s s'. ⟦at gc idle_flip_noop_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_NOOP, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_IdleInit⦈); taken gc idle_flip_noop_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; (All (ghost_hs_in_sync (s↓ sys)), hp_Idle, ph_Idle, sys_phase s↓, []) ∈ phase_rel; gc_phase s↓ = ph_Idle; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_Idle⟧ ⟹ (False, hp_IdleInit, ph_Idle, sys_phase s↓, []) ∈ phase_rel› and 1 goal remains*) apply blast (*discuss goal 11*) apply (simp add: phase_rel_def (*‹phase_rel = {(in_sync, hp, ph, ph, []) |(in_sync::bool) (hp::hs_phase) ph::gc_phase. handshake_phase_rel hp in_sync ph} ∪ {True} × {(hp_IdleInit, ph_Init, ph_Idle, [mw_Phase ph_Init]), (hp_InitMark, ph_Mark, ph_Init, [mw_Phase ph_Mark]), (hp_IdleMarkSweep, ph_Sweep, ph_Mark, [mw_Phase ph_Sweep]), (hp_IdleMarkSweep, ph_Idle, ph_Mark, [mw_Phase ph_Sweep, mw_Phase ph_Idle]), (hp_IdleMarkSweep, ph_Idle, ph_Sweep, [mw_Phase ph_Idle])}›*)) (*goal: ‹⋀s s'. ⟦at gc idle_noop_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_NOOP, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_Idle⦈); taken gc idle_noop_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; (All (ghost_hs_in_sync (s↓ sys)), hp_IdleMarkSweep, ph_Idle, sys_phase s↓, []) ∈ phase_rel; gc_phase s↓ = ph_Idle; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep⟧ ⟹ (False, hp_Idle, ph_Idle, sys_phase s↓, []) ∈ phase_rel›*) apply blast (*proven 11 subgoals*) . lemma (in sys) phase_rel_inv[intro]: notes gc.phase_invL_def[inv] notes phase_rel_inv_def[inv] notes fun_upd_apply[simp] shows "⦃ LSTP (phase_rel_inv ❙∧ tso_store_inv) ⦄ sys ⦃ LSTP phase_rel_inv ⦄" apply (vcg_jackhammer (no_thin_post_inv)) (*goal: ‹⦃λs. phase_rel_inv s↓ ∧ tso_store_inv s↓⦄ sys ⦃λs. phase_rel_inv s↓⦄›*) proof (vcg_name_cases) (*goal: ‹⋀s s' p w ws. ⟦at sys tso_dequeue_store_buffer s; s'↓ = s↓(sys := do_store_action w (s↓ sys)⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(p := ws)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''∈- {sys}. GST s' p'' = GST s p''; (All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel; tso_store_inv s↓; sys_mem_store_buffers p s↓ = w # ws; not_blocked (s↓ sys) p; p ≠ sys⟧ ⟹ (gc = p ⟶ (All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_phase s↓, phase (do_store_action w (s↓ sys)), filter is_mw_Phase ws) ∈ phase_rel) ∧ (gc ≠ p ⟶ (All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_phase s↓, phase (do_store_action w (s↓ sys)), filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel)›*) case (tso_dequeue_store_buffer s s' p w ws) (*‹at sys tso_dequeue_store_buffer s› ‹s'↓ = s↓(sys := do_store_action w (s↓ sys)⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(p := ws)⦈)› ‹taken sys tso_dequeue_store_buffer s'› ‹∀p''∈- {sys}. GST s' p'' = GST s p''› ‹(All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel› ‹tso_store_inv s↓› ‹sys_mem_store_buffers p s↓ = w # ws› ‹not_blocked (s↓ sys) p› ‹p ≠ sys›*) then show "?case" (*goal: ‹(gc = p ⟶ (All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_phase s↓, phase (do_store_action w (s↓ sys)), filter is_mw_Phase ws) ∈ phase_rel) ∧ (gc ≠ p ⟶ (All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_phase s↓, phase (do_store_action w (s↓ sys)), filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel)›*) apply (simp add: phase_rel_def (*‹phase_rel = {(in_sync, hp, ph, ph, []) |in_sync hp ph. handshake_phase_rel hp in_sync ph} ∪ {True} × {(hp_IdleInit, ph_Init, ph_Idle, [mw_Phase ph_Init]), (hp_InitMark, ph_Mark, ph_Init, [mw_Phase ph_Mark]), (hp_IdleMarkSweep, ph_Sweep, ph_Mark, [mw_Phase ph_Sweep]), (hp_IdleMarkSweep, ph_Idle, ph_Mark, [mw_Phase ph_Sweep, mw_Phase ph_Idle]), (hp_IdleMarkSweep, ph_Idle, ph_Sweep, [mw_Phase ph_Idle])}›*) p_not_sys (*‹(?p ≠ sys) = (?p = gc ∨ (∃m. ?p = mutator m))›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) (*goal: ‹(gc = p ⟶ (All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_phase s↓, phase (do_store_action w (s↓ sys)), filter is_mw_Phase ws) ∈ phase_rel) ∧ (gc ≠ p ⟶ (All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_phase s↓, phase (do_store_action w (s↓ sys)), filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel)›*) apply ((elim disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*))[1]) (*goals: 1. ‹⟦at sys tso_dequeue_store_buffer (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state); (s'::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = s↓(sys := do_store_action (w::('a, 'b, 'c) mem_store_action) (s↓ sys)⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(p::'d process_name := ws::('a, 'b, 'c) mem_store_action list)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''::'d process_name∈- {sys}. GST s' p'' = GST s p''; tso_store_inv s↓; sys_mem_store_buffers p s↓ = w # ws; not_blocked (s↓ sys) p; All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ sys_phase s↓ = ph_Idle ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Init]; p = gc⟧ ⟹ (gc = p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase ws = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase ws = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase ws = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase ws = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓)) ∧ (gc ≠ p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓))› 2. ‹⟦at sys tso_dequeue_store_buffer (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state); (s'::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = s↓(sys := do_store_action (w::('a, 'b, 'c) mem_store_action) (s↓ sys)⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(p::'d process_name := ws::('a, 'b, 'c) mem_store_action list)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''::'d process_name∈- {sys}. GST s' p'' = GST s p''; tso_store_inv s↓; sys_mem_store_buffers p s↓ = w # ws; not_blocked (s↓ sys) p; All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ sys_phase s↓ = ph_Idle ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Init]; ∃m::'d. p = mutator m⟧ ⟹ (gc = p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase ws = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase ws = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase ws = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase ws = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓)) ∧ (gc ≠ p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓))› 3. ‹⟦at sys tso_dequeue_store_buffer (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state); (s'::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = s↓(sys := do_store_action (w::('a, 'b, 'c) mem_store_action) (s↓ sys)⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(p::'d process_name := ws::('a, 'b, 'c) mem_store_action list)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''::'d process_name∈- {sys}. GST s' p'' = GST s p''; tso_store_inv s↓; sys_mem_store_buffers p s↓ = w # ws; not_blocked (s↓ sys) p; p = gc; All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ sys_phase s↓ = ph_Init ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Mark]⟧ ⟹ (gc = p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase ws = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase ws = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase ws = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase ws = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓)) ∧ (gc ≠ p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓))› 4. ‹⟦at sys tso_dequeue_store_buffer (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state); (s'::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = s↓(sys := do_store_action (w::('a, 'b, 'c) mem_store_action) (s↓ sys)⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(p::'d process_name := ws::('a, 'b, 'c) mem_store_action list)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''::'d process_name∈- {sys}. GST s' p'' = GST s p''; tso_store_inv s↓; sys_mem_store_buffers p s↓ = w # ws; not_blocked (s↓ sys) p; p = gc; All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ sys_phase s↓ = ph_Mark ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep]⟧ ⟹ (gc = p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase ws = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase ws = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase ws = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase ws = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓)) ∧ (gc ≠ p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓))› 5. ‹⟦at sys tso_dequeue_store_buffer (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state); (s'::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = s↓(sys := do_store_action (w::('a, 'b, 'c) mem_store_action) (s↓ sys)⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(p::'d process_name := ws::('a, 'b, 'c) mem_store_action list)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''::'d process_name∈- {sys}. GST s' p'' = GST s p''; tso_store_inv s↓; sys_mem_store_buffers p s↓ = w # ws; not_blocked (s↓ sys) p; p = gc; All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ sys_phase s↓ = ph_Mark ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep, mw_Phase ph_Idle]⟧ ⟹ (gc = p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase ws = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase ws = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase ws = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase ws = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓)) ∧ (gc ≠ p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓))› 6. ‹⟦at sys tso_dequeue_store_buffer (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state); (s'::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = s↓(sys := do_store_action (w::('a, 'b, 'c) mem_store_action) (s↓ sys)⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(p::'d process_name := ws::('a, 'b, 'c) mem_store_action list)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''::'d process_name∈- {sys}. GST s' p'' = GST s p''; tso_store_inv s↓; sys_mem_store_buffers p s↓ = w # ws; not_blocked (s↓ sys) p; p = gc; All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ sys_phase s↓ = ph_Sweep ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Idle]⟧ ⟹ (gc = p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase ws = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase ws = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase ws = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase ws = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓)) ∧ (gc ≠ p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓))› 7. ‹⟦at sys tso_dequeue_store_buffer (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state); (s'::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = s↓(sys := do_store_action (w::('a, 'b, 'c) mem_store_action) (s↓ sys)⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(p::'d process_name := ws::('a, 'b, 'c) mem_store_action list)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''::'d process_name∈- {sys}. GST s' p'' = GST s p''; tso_store_inv s↓; sys_mem_store_buffers p s↓ = w # ws; not_blocked (s↓ sys) p; p = gc; sys_phase s↓ = gc_phase s↓ ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓)⟧ ⟹ (gc = p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase ws = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase ws = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase ws = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase ws = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓)) ∧ (gc ≠ p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓))› 8. ‹⟦at sys tso_dequeue_store_buffer (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state); (s'::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = s↓(sys := do_store_action (w::('a, 'b, 'c) mem_store_action) (s↓ sys)⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(p::'d process_name := ws::('a, 'b, 'c) mem_store_action list)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''::'d process_name∈- {sys}. GST s' p'' = GST s p''; tso_store_inv s↓; sys_mem_store_buffers p s↓ = w # ws; not_blocked (s↓ sys) p; ∃m::'d. p = mutator m; All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ sys_phase s↓ = ph_Init ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Mark]⟧ ⟹ (gc = p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase ws = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase ws = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase ws = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase ws = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓)) ∧ (gc ≠ p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓))› 9. ‹⟦at sys tso_dequeue_store_buffer (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state); (s'::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = s↓(sys := do_store_action (w::('a, 'b, 'c) mem_store_action) (s↓ sys)⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(p::'d process_name := ws::('a, 'b, 'c) mem_store_action list)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''::'d process_name∈- {sys}. GST s' p'' = GST s p''; tso_store_inv s↓; sys_mem_store_buffers p s↓ = w # ws; not_blocked (s↓ sys) p; ∃m::'d. p = mutator m; All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ sys_phase s↓ = ph_Mark ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep]⟧ ⟹ (gc = p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase ws = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase ws = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase ws = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase ws = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓)) ∧ (gc ≠ p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓))› 10. ‹⟦at sys tso_dequeue_store_buffer (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state); (s'::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = s↓(sys := do_store_action (w::('a, 'b, 'c) mem_store_action) (s↓ sys)⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(p::'d process_name := ws::('a, 'b, 'c) mem_store_action list)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''::'d process_name∈- {sys}. GST s' p'' = GST s p''; tso_store_inv s↓; sys_mem_store_buffers p s↓ = w # ws; not_blocked (s↓ sys) p; ∃m::'d. p = mutator m; All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ sys_phase s↓ = ph_Mark ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep, mw_Phase ph_Idle]⟧ ⟹ (gc = p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase ws = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase ws = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase ws = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase ws = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓)) ∧ (gc ≠ p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓))› 11. ‹⟦at sys tso_dequeue_store_buffer (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state); (s'::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = s↓(sys := do_store_action (w::('a, 'b, 'c) mem_store_action) (s↓ sys)⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(p::'d process_name := ws::('a, 'b, 'c) mem_store_action list)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''::'d process_name∈- {sys}. GST s' p'' = GST s p''; tso_store_inv s↓; sys_mem_store_buffers p s↓ = w # ws; not_blocked (s↓ sys) p; ∃m::'d. p = mutator m; All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ sys_phase s↓ = ph_Sweep ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Idle]⟧ ⟹ (gc = p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase ws = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase ws = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase ws = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase ws = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓)) ∧ (gc ≠ p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓))› 12. ‹⟦at sys tso_dequeue_store_buffer (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state); (s'::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = s↓(sys := do_store_action (w::('a, 'b, 'c) mem_store_action) (s↓ sys)⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(p::'d process_name := ws::('a, 'b, 'c) mem_store_action list)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''::'d process_name∈- {sys}. GST s' p'' = GST s p''; tso_store_inv s↓; sys_mem_store_buffers p s↓ = w # ws; not_blocked (s↓ sys) p; ∃m::'d. p = mutator m; sys_phase s↓ = gc_phase s↓ ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓)⟧ ⟹ (gc = p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase ws = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase ws = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase ws = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase ws = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase ws = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓)) ∧ (gc ≠ p ⟶ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_phase s↓ = ph_Init ∧ (sys_phase s↓ = ph_Idle ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Idle) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Init] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_phase s↓ = ph_Mark ∧ (sys_phase s↓ = ph_Init ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Init) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Mark] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Sweep ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Mark ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Mark) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Sweep, mw_Phase ph_Idle] ∨ All (ghost_hs_in_sync (s↓ sys)) ∧ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_phase s↓ = ph_Idle ∧ (sys_phase s↓ = ph_Sweep ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase ph_Sweep) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [mw_Phase ph_Idle] ∨ (sys_phase s↓ = gc_phase s↓ ∧ (∀ph'::gc_phase. w ≠ mw_Phase ph') ∨ w = mw_Phase (gc_phase s↓)) ∧ filter is_mw_Phase (sys_mem_store_buffers gc s↓) = [] ∧ handshake_phase_rel (sys_ghost_hs_phase s↓) (All (ghost_hs_in_sync (s↓ sys))) (gc_phase s↓))› discuss goal 1*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 3*) apply ((auto split: if_splits (*‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 4*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 5*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 6*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 7*) apply ((auto split: if_splits (*‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 8*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 9*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 10*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 11*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 12*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 12 subgoals*) . qed lemma (in mut_m) phase_rel_inv[intro]: "⦃ handshake_invL ❙∧ LSTP (handshake_phase_inv ❙∧ phase_rel_inv) ⦄ mutator m ⦃ LSTP phase_rel_inv ⦄" unfolding phase_rel_inv_def (*goal: ‹⦃λs. handshake_invL s ∧ handshake_phase_inv s↓ ∧ (All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel⦄ mutator m ⦃λs. (All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel⦄›*) proof (vcg_jackhammer (no_thin_post_inv), vcg_name_cases) (*goals: 1. ‹⋀s s'. ⟦at (mutator m) hs_get_work_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_work_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''; handshake_phase_inv s↓; (All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel; sys_hs_type s↓ = ht_GetWork; mut_hs_type s↓ = ht_GetWork; sys_hs_pending m s↓; mut_hs_pending s↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s↓) = []⟧ ⟹ (All ((ghost_hs_in_sync (s↓ sys))(m := True)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel› 2. ‹⋀s s'. ⟦at (mutator m) hs_get_roots_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}, ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_roots_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''; handshake_phase_inv s↓; (All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel; sys_hs_type s↓ = ht_GetRoots; mut_hs_type s↓ = ht_GetRoots; sys_hs_pending m s↓; mut_hs_pending s↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s↓) = []⟧ ⟹ (All ((ghost_hs_in_sync (s↓ sys))(m := True)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel› 3. ‹⋀s s'. ⟦at (mutator m) hs_noop_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_noop_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''; handshake_phase_inv s↓; (All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel; sys_hs_type s↓ = ht_NOOP; mut_hs_type s↓ = ht_NOOP; sys_hs_pending m s↓; mut_hs_pending s↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s↓) = []⟧ ⟹ (All ((ghost_hs_in_sync (s↓ sys))(m := True)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel›*) case (hs_noop_done s s') (*‹at (mutator (m::'mut)) hs_noop_done (s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state)› ‹at sys sys.sys_hs_mut_done s› ‹(s'::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state)↓ = (s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state)↓(mutator (m::'mut::type) := s↓ (mutator m)⦇ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈)› ‹taken (mutator (m::'mut)) hs_noop_done (s'::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state)› ‹∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''› ‹handshake_phase_inv (s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state)↓› ‹(All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel› ‹sys_hs_type (s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state)↓ = ht_NOOP› ‹mut_hs_type s↓ = ht_NOOP› ‹sys_hs_pending m s↓› ‹mut_hs_pending s↓› ‹filter (λs::('a::type, 'b::type, 'c::type) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator (m::'mut::type)) (s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state)↓) = []›*) then show "?case" (*goal: ‹(All ((ghost_hs_in_sync (s↓ sys))(m := True)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel›*) by (auto dest!: handshake_phase_invD (*‹handshake_phase_inv ?s ⟹ (sys_ghost_hs_in_sync m ?s, sys_hs_type ?s, sys_ghost_hs_phase ?s, mut_ghost_hs_phase ?s) ∈ hp_step_rel ∧ (sys_hs_pending m ?s ⟶ ¬ sys_ghost_hs_in_sync m ?s)›*) simp: handshake_phase_rel_def (*‹handshake_phase_rel ?hp ?in_sync ?ph = (case ?hp of hp_Idle ⇒ ?ph = ph_Idle | hp_IdleInit ⇒ ?ph = ph_Idle ∨ ?in_sync ∧ ?ph = ph_Init | hp_InitMark ⇒ ?ph = ph_Init ∨ ?in_sync ∧ ?ph = ph_Mark | hp_Mark ⇒ ?ph = ph_Mark | hp_IdleMarkSweep ⇒ ?ph = ph_Mark ∨ ?in_sync ∧ ?ph ∈ {ph_Idle, ph_Sweep})›*) phase_rel_def (*‹phase_rel = {(in_sync, hp, ph, ph, []) |in_sync hp ph. handshake_phase_rel hp in_sync ph} ∪ {True} × {(hp_IdleInit, ph_Init, ph_Idle, [mw_Phase ph_Init]), (hp_InitMark, ph_Mark, ph_Init, [mw_Phase ph_Mark]), (hp_IdleMarkSweep, ph_Sweep, ph_Mark, [mw_Phase ph_Sweep]), (hp_IdleMarkSweep, ph_Idle, ph_Mark, [mw_Phase ph_Sweep, mw_Phase ph_Idle]), (hp_IdleMarkSweep, ph_Idle, ph_Sweep, [mw_Phase ph_Idle])}›*) hp_step_rel_def (*‹hp_step_rel = {True} × ({(ht_NOOP, hp, hp) |hp. hp ∈ {hp_Idle, hp_IdleInit, hp_InitMark, hp_Mark}} ∪ {(ht_GetRoots, hp_IdleMarkSweep, hp_IdleMarkSweep), (ht_GetWork, hp_IdleMarkSweep, hp_IdleMarkSweep)}) ∪ {False} × {(ht_NOOP, hp_Idle, hp_IdleMarkSweep), (ht_NOOP, hp_IdleInit, hp_Idle), (ht_NOOP, hp_InitMark, hp_IdleInit), (ht_NOOP, hp_Mark, hp_InitMark), (ht_GetRoots, hp_IdleMarkSweep, hp_Mark), (ht_GetWork, hp_IdleMarkSweep, hp_IdleMarkSweep)}›*) split: hs_phase.splits (*‹?P (case ?hs_phase of hp_Idle ⇒ ?f1.0 | hp_IdleInit ⇒ ?f2.0 | hp_InitMark ⇒ ?f3.0 | hp_Mark ⇒ ?f4.0 | hp_IdleMarkSweep ⇒ ?f5.0) = ((?hs_phase = hp_Idle ⟶ ?P ?f1.0) ∧ (?hs_phase = hp_IdleInit ⟶ ?P ?f2.0) ∧ (?hs_phase = hp_InitMark ⟶ ?P ?f3.0) ∧ (?hs_phase = hp_Mark ⟶ ?P ?f4.0) ∧ (?hs_phase = hp_IdleMarkSweep ⟶ ?P ?f5.0))› ‹?P (case ?hs_phase of hp_Idle ⇒ ?f1.0 | hp_IdleInit ⇒ ?f2.0 | hp_InitMark ⇒ ?f3.0 | hp_Mark ⇒ ?f4.0 | hp_IdleMarkSweep ⇒ ?f5.0) = (¬ (?hs_phase = hp_Idle ∧ ¬ ?P ?f1.0 ∨ ?hs_phase = hp_IdleInit ∧ ¬ ?P ?f2.0 ∨ ?hs_phase = hp_InitMark ∧ ¬ ?P ?f3.0 ∨ ?hs_phase = hp_Mark ∧ ¬ ?P ?f4.0 ∨ ?hs_phase = hp_IdleMarkSweep ∧ ¬ ?P ?f5.0))›*)) next (*goals: 1. ‹⋀s s'. ⟦at (mutator m) hs_get_work_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_work_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''; handshake_phase_inv s↓; (All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel; sys_hs_type s↓ = ht_GetWork; mut_hs_type s↓ = ht_GetWork; sys_hs_pending m s↓; mut_hs_pending s↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s↓) = []⟧ ⟹ (All ((ghost_hs_in_sync (s↓ sys))(m := True)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel› 2. ‹⋀s s'. ⟦at (mutator m) hs_get_roots_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}, ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_roots_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''; handshake_phase_inv s↓; (All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel; sys_hs_type s↓ = ht_GetRoots; mut_hs_type s↓ = ht_GetRoots; sys_hs_pending m s↓; mut_hs_pending s↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s↓) = []⟧ ⟹ (All ((ghost_hs_in_sync (s↓ sys))(m := True)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel›*) case (hs_get_roots_done s s') (*‹at (mutator m) hs_get_roots_done s› ‹at sys sys.sys_hs_mut_done s› ‹(s'::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state)↓ = (s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state)↓(mutator (m::'mut) := s↓ (mutator m)⦇W := {}, ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈)› ‹taken (mutator m) hs_get_roots_done s'› ‹∀p''::'mut process_name∈- {mutator (m::'mut), sys}. GST (s'::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state) p'' = GST (s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state) p''› ‹handshake_phase_inv s↓› ‹(All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel› ‹sys_hs_type s↓ = ht_GetRoots› ‹mut_hs_type (s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state)↓ = ht_GetRoots› ‹sys_hs_pending m s↓› ‹mut_hs_pending s↓› ‹filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s↓) = []›*) then show "?case" (*goal: ‹(All ((ghost_hs_in_sync (s↓ sys))(m := True)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel›*) by ((auto dest!: handshake_phase_invD (*‹handshake_phase_inv ?s ⟹ (sys_ghost_hs_in_sync m ?s, sys_hs_type ?s, sys_ghost_hs_phase ?s, mut_ghost_hs_phase ?s) ∈ hp_step_rel ∧ (sys_hs_pending m ?s ⟶ ¬ sys_ghost_hs_in_sync m ?s)›*) simp: handshake_phase_rel_def (*‹handshake_phase_rel ?hp ?in_sync ?ph = (case ?hp of hp_Idle ⇒ ?ph = ph_Idle | hp_IdleInit ⇒ ?ph = ph_Idle ∨ ?in_sync ∧ ?ph = ph_Init | hp_InitMark ⇒ ?ph = ph_Init ∨ ?in_sync ∧ ?ph = ph_Mark | hp_Mark ⇒ ?ph = ph_Mark | hp_IdleMarkSweep ⇒ ?ph = ph_Mark ∨ ?in_sync ∧ ?ph ∈ {ph_Idle, ph_Sweep})›*) phase_rel_def (*‹phase_rel = {(in_sync, hp, ph, ph, []) |in_sync hp ph. handshake_phase_rel hp in_sync ph} ∪ {True} × {(hp_IdleInit, ph_Init, ph_Idle, [mw_Phase ph_Init]), (hp_InitMark, ph_Mark, ph_Init, [mw_Phase ph_Mark]), (hp_IdleMarkSweep, ph_Sweep, ph_Mark, [mw_Phase ph_Sweep]), (hp_IdleMarkSweep, ph_Idle, ph_Mark, [mw_Phase ph_Sweep, mw_Phase ph_Idle]), (hp_IdleMarkSweep, ph_Idle, ph_Sweep, [mw_Phase ph_Idle])}›*) hp_step_rel_def (*‹hp_step_rel = {True} × ({(ht_NOOP, hp, hp) |hp. hp ∈ {hp_Idle, hp_IdleInit, hp_InitMark, hp_Mark}} ∪ {(ht_GetRoots, hp_IdleMarkSweep, hp_IdleMarkSweep), (ht_GetWork, hp_IdleMarkSweep, hp_IdleMarkSweep)}) ∪ {False} × {(ht_NOOP, hp_Idle, hp_IdleMarkSweep), (ht_NOOP, hp_IdleInit, hp_Idle), (ht_NOOP, hp_InitMark, hp_IdleInit), (ht_NOOP, hp_Mark, hp_InitMark), (ht_GetRoots, hp_IdleMarkSweep, hp_Mark), (ht_GetWork, hp_IdleMarkSweep, hp_IdleMarkSweep)}›*) split: hs_phase.splits (*‹?P (case ?hs_phase of hp_Idle ⇒ ?f1.0 | hp_IdleInit ⇒ ?f2.0 | hp_InitMark ⇒ ?f3.0 | hp_Mark ⇒ ?f4.0 | hp_IdleMarkSweep ⇒ ?f5.0) = ((?hs_phase = hp_Idle ⟶ ?P ?f1.0) ∧ (?hs_phase = hp_IdleInit ⟶ ?P ?f2.0) ∧ (?hs_phase = hp_InitMark ⟶ ?P ?f3.0) ∧ (?hs_phase = hp_Mark ⟶ ?P ?f4.0) ∧ (?hs_phase = hp_IdleMarkSweep ⟶ ?P ?f5.0))› ‹?P (case ?hs_phase of hp_Idle ⇒ ?f1.0 | hp_IdleInit ⇒ ?f2.0 | hp_InitMark ⇒ ?f3.0 | hp_Mark ⇒ ?f4.0 | hp_IdleMarkSweep ⇒ ?f5.0) = (¬ (?hs_phase = hp_Idle ∧ ¬ ?P ?f1.0 ∨ ?hs_phase = hp_IdleInit ∧ ¬ ?P ?f2.0 ∨ ?hs_phase = hp_InitMark ∧ ¬ ?P ?f3.0 ∨ ?hs_phase = hp_Mark ∧ ¬ ?P ?f4.0 ∨ ?hs_phase = hp_IdleMarkSweep ∧ ¬ ?P ?f5.0))›*))[1]) next (*goal: ‹⋀s s'. ⟦at (mutator m) hs_get_work_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_work_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''; handshake_phase_inv s↓; (All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel; sys_hs_type s↓ = ht_GetWork; mut_hs_type s↓ = ht_GetWork; sys_hs_pending m s↓; mut_hs_pending s↓; filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s↓) = []⟧ ⟹ (All ((ghost_hs_in_sync (s↓ sys))(m := True)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel›*) case (hs_get_work_done s s') (*‹at (mutator (m::'mut::type)) hs_get_work_done (s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state)› ‹at sys sys.sys_hs_mut_done s› ‹s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈)› ‹taken (mutator m) hs_get_work_done s'› ‹∀p''::'mut process_name∈- {mutator (m::'mut), sys}. GST (s'::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state) p'' = GST (s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state) p''› ‹handshake_phase_inv s↓› ‹(All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel› ‹sys_hs_type s↓ = ht_GetWork› ‹mut_hs_type s↓ = ht_GetWork› ‹sys_hs_pending (m::'mut::type) (s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state)↓› ‹mut_hs_pending s↓› ‹filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s↓) = []›*) then show "?case" (*goal: ‹(All ((ghost_hs_in_sync (s↓ sys))(m := True)), sys_ghost_hs_phase s↓, gc_phase s↓, sys_phase s↓, filter is_mw_Phase (sys_mem_store_buffers gc s↓)) ∈ phase_rel›*) by (msorry) qed text‹ Connect @{const "sys_ghost_hs_phase"} with locations in the GC. › lemma gc_handshake_invL_eq_imp: "eq_imp (λ(_::unit) s. (AT s gc, s↓ gc, sys_ghost_hs_phase s↓, hs_pending (s↓ sys), ghost_hs_in_sync (s↓ sys), sys_hs_type s↓)) gc.handshake_invL" by (simp add: gc.handshake_invL_def (*‹gc.handshake_invL = (λs. (atS gc gc.hs_noop_locs s ⟶ sys_hs_type s↓ = ht_NOOP) ∧ (atS gc gc.hs_get_roots_locs s ⟶ sys_hs_type s↓ = ht_GetRoots) ∧ (atS gc gc.hs_get_work_locs s ⟶ sys_hs_type s↓ = ht_GetWork) ∧ (atS gc gc.hs_mut_in_muts_locs s ⟶ gc_mut s↓ ∈ gc_muts s↓) ∧ (atS gc gc.hs_init_loop_locs s ⟶ (∀x. x ∉ gc_muts s↓ ⟶ sys_hs_pending x s↓ ∨ sys_ghost_hs_in_sync x s↓)) ∧ (atS gc gc.hs_init_loop_not_done_locs s ⟶ (∀x. x ∈ gc_muts s↓ ⟶ ¬ sys_hs_pending x s↓ ∧ ¬ sys_ghost_hs_in_sync x s↓)) ∧ (atS gc gc.hs_init_loop_done_locs s ⟶ (sys_hs_pending (gc_mut s↓) s↓ ∨ sys_ghost_hs_in_sync (gc_mut s↓) s↓) ∧ (∀x. x ∈ gc_muts s↓ ∧ x ≠ gc_mut s↓ ⟶ ¬ sys_hs_pending x s↓ ∧ ¬ sys_ghost_hs_in_sync x s↓)) ∧ (atS gc gc.hs_done_locs s ⟶ (∀x. sys_hs_pending x s↓ ∨ sys_ghost_hs_in_sync x s↓)) ∧ (atS gc gc.hs_done_loop_locs s ⟶ (∀x. x ∉ gc_muts s↓ ⟶ ¬ sys_hs_pending x s↓)) ∧ (atS gc gc.hs_none_pending_locs s ⟶ (∀x. ¬ sys_hs_pending x s↓)) ∧ (atS gc gc.hs_in_sync_locs s ⟶ (∀x. sys_ghost_hs_in_sync x s↓)) ∧ (atS gc gc.hs_out_of_sync_locs s ⟶ (∀x. ¬ sys_hs_pending x s↓ ∧ ¬ sys_ghost_hs_in_sync x s↓)) ∧ (atS gc gc.hp_Idle_locs s ⟶ sys_ghost_hs_phase s↓ = hp_Idle) ∧ (atS gc gc.hp_IdleInit_locs s ⟶ sys_ghost_hs_phase s↓ = hp_IdleInit) ∧ (atS gc gc.hp_InitMark_locs s ⟶ sys_ghost_hs_phase s↓ = hp_InitMark) ∧ (atS gc gc.hp_IdleMarkSweep_locs s ⟶ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep) ∧ (atS gc gc.hp_Mark_locs s ⟶ sys_ghost_hs_phase s↓ = hp_Mark))›*) eq_imp_def (*‹eq_imp ?f ?g ≡ ∀s s'. (∀x. ?f x s = ?f x s') ⟶ ?g s = ?g s'›*)) lemmas gc_handshake_invL_niE[nie] = iffD1[OF gc_handshake_invL_eq_imp[simplified eq_imp_simps, rule_format, unfolded conj_explode], rotated -1] lemma (in sys) gc_handshake_invL[intro]: "⦃ gc.handshake_invL ⦄ sys" by (vcg_chainsaw gc.handshake_invL_def) lemma (in sys) handshake_phase_inv[intro]: "⦃ LSTP handshake_phase_inv ⦄ sys" unfolding handshake_phase_inv_def (*goal: ‹⦃(λs. ∀x. (sys_ghost_hs_in_sync x s↓, sys_hs_type s↓, sys_ghost_hs_phase s↓, ghost_hs_phase (s↓ (mutator x))) ∈ hp_step_rel ∧ (sys_hs_pending x s↓ ⟶ ¬ sys_ghost_hs_in_sync x s↓))⦄ sys›*) by (vcg_jackhammer (no_thin_post_inv)) lemma (in gc) handshake_invL[intro]: notes fun_upd_apply[simp] shows "⦃ handshake_invL ⦄ gc" apply vcg_jackhammer (*goals: 1. ‹⋀s s' x. ⟦at gc mark_loop_get_work_done_loop_rendezvous s; at sys sys.sys_hs_gc_done s; s'↓ = s↓(gc := s↓ gc⦇muts := gc_muts s↓ - {uu_. uu_ = gc_mut s↓ ∧ ¬ sys_hs_pending (gc_mut s↓) s↓}⦈, sys := s↓ sys); taken gc mark_loop_get_work_done_loop_rendezvous s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; sys_hs_type s↓ = ht_GetWork; ∀x. sys_hs_pending x s↓ ∨ sys_ghost_hs_in_sync x s↓; ∀x. x ∉ gc_muts s↓ ⟶ ¬ sys_hs_pending x s↓; sys_ghost_hs_phase s↓ = hp_IdleMarkSweep; x ∈ gc_muts s↓ ⟶ x = gc_mut s↓ ∧ ¬ sys_hs_pending (gc_mut s↓) s↓; sys_hs_pending x s↓⟧ ⟹ False› 2. ‹⋀s s' x. ⟦at gc mark_loop_get_work_init_loop_done s; s'↓ = s↓(gc := s↓ gc⦇muts := gc_muts s↓ - {gc_mut s↓}⦈); taken gc mark_loop_get_work_init_loop_done s'; ∀p''∈- {gc}. GST s' p'' = GST s p''; sys_hs_type s↓ = ht_GetWork; gc_mut s↓ ∈ gc_muts s↓; ∀x. x ∉ gc_muts s↓ ⟶ sys_hs_pending x s↓ ∨ sys_ghost_hs_in_sync x s↓; sys_ghost_hs_phase s↓ = hp_IdleMarkSweep; sys_hs_pending (gc_mut s↓) s↓ ∨ sys_ghost_hs_in_sync (gc_mut s↓) s↓; ∀x. x ∈ gc_muts s↓ ∧ x ≠ gc_mut s↓ ⟶ ¬ sys_hs_pending x s↓ ∧ ¬ sys_ghost_hs_in_sync x s↓; x ∈ gc_muts s↓ ⟶ x = gc_mut s↓; ¬ sys_ghost_hs_in_sync x s↓⟧ ⟹ sys_hs_pending x s↓› 3. ‹⋀s s' x. ⟦at gc mark_loop_get_roots_done_loop_rendezvous s; at sys sys.sys_hs_gc_done s; s'↓ = s↓(gc := s↓ gc⦇muts := gc_muts s↓ - {uu_. uu_ = gc_mut s↓ ∧ ¬ sys_hs_pending (gc_mut s↓) s↓}⦈, sys := s↓ sys); taken gc mark_loop_get_roots_done_loop_rendezvous s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; sys_hs_type s↓ = ht_GetRoots; ∀x. sys_hs_pending x s↓ ∨ sys_ghost_hs_in_sync x s↓; ∀x. x ∉ gc_muts s↓ ⟶ ¬ sys_hs_pending x s↓; sys_ghost_hs_phase s↓ = hp_IdleMarkSweep; x ∈ gc_muts s↓ ⟶ x = gc_mut s↓ ∧ ¬ sys_hs_pending (gc_mut s↓) s↓; sys_hs_pending x s↓⟧ ⟹ False› 4. ‹⋀s s' x. ⟦at gc mark_loop_get_roots_init_loop_done s; s'↓ = s↓(gc := s↓ gc⦇muts := gc_muts s↓ - {gc_mut s↓}⦈); taken gc mark_loop_get_roots_init_loop_done s'; ∀p''∈- {gc}. GST s' p'' = GST s p''; sys_hs_type s↓ = ht_GetRoots; gc_mut s↓ ∈ gc_muts s↓; ∀x. x ∉ gc_muts s↓ ⟶ sys_hs_pending x s↓ ∨ sys_ghost_hs_in_sync x s↓; sys_ghost_hs_phase s↓ = hp_IdleMarkSweep; sys_hs_pending (gc_mut s↓) s↓ ∨ sys_ghost_hs_in_sync (gc_mut s↓) s↓; ∀x. x ∈ gc_muts s↓ ∧ x ≠ gc_mut s↓ ⟶ ¬ sys_hs_pending x s↓ ∧ ¬ sys_ghost_hs_in_sync x s↓; x ∈ gc_muts s↓ ⟶ x = gc_mut s↓; ¬ sys_ghost_hs_in_sync x s↓⟧ ⟹ sys_hs_pending x s↓› 5. ‹⋀s s' x. ⟦at gc mark_noop_done_loop_rendezvous s; at sys sys.sys_hs_gc_done s; s'↓ = s↓(gc := s↓ gc⦇muts := gc_muts s↓ - {uu_. uu_ = gc_mut s↓ ∧ ¬ sys_hs_pending (gc_mut s↓) s↓}⦈, sys := s↓ sys); taken gc mark_noop_done_loop_rendezvous s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; sys_hs_type s↓ = ht_NOOP; ∀x. sys_hs_pending x s↓ ∨ sys_ghost_hs_in_sync x s↓; ∀x. x ∉ gc_muts s↓ ⟶ ¬ sys_hs_pending x s↓; sys_ghost_hs_phase s↓ = hp_Mark; x ∈ gc_muts s↓ ⟶ x = gc_mut s↓ ∧ ¬ sys_hs_pending (gc_mut s↓) s↓; sys_hs_pending x s↓⟧ ⟹ False› 6. ‹⋀s s' x. ⟦at gc mark_noop_init_loop_done s; s'↓ = s↓(gc := s↓ gc⦇muts := gc_muts s↓ - {gc_mut s↓}⦈); taken gc mark_noop_init_loop_done s'; ∀p''∈- {gc}. GST s' p'' = GST s p''; sys_hs_type s↓ = ht_NOOP; gc_mut s↓ ∈ gc_muts s↓; ∀x. x ∉ gc_muts s↓ ⟶ sys_hs_pending x s↓ ∨ sys_ghost_hs_in_sync x s↓; sys_ghost_hs_phase s↓ = hp_Mark; sys_hs_pending (gc_mut s↓) s↓ ∨ sys_ghost_hs_in_sync (gc_mut s↓) s↓; ∀x. x ∈ gc_muts s↓ ∧ x ≠ gc_mut s↓ ⟶ ¬ sys_hs_pending x s↓ ∧ ¬ sys_ghost_hs_in_sync x s↓; x ∈ gc_muts s↓ ⟶ x = gc_mut s↓; ¬ sys_ghost_hs_in_sync x s↓⟧ ⟹ sys_hs_pending x s↓› 7. ‹⋀s s' x. ⟦at gc init_noop_done_loop_rendezvous s; at sys sys.sys_hs_gc_done s; s'↓ = s↓(gc := s↓ gc⦇muts := gc_muts s↓ - {uu_. uu_ = gc_mut s↓ ∧ ¬ sys_hs_pending (gc_mut s↓) s↓}⦈, sys := s↓ sys); taken gc init_noop_done_loop_rendezvous s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; sys_hs_type s↓ = ht_NOOP; ∀x. sys_hs_pending x s↓ ∨ sys_ghost_hs_in_sync x s↓; ∀x. x ∉ gc_muts s↓ ⟶ ¬ sys_hs_pending x s↓; sys_ghost_hs_phase s↓ = hp_InitMark; x ∈ gc_muts s↓ ⟶ x = gc_mut s↓ ∧ ¬ sys_hs_pending (gc_mut s↓) s↓; sys_hs_pending x s↓⟧ ⟹ False› 8. ‹⋀s s' x. ⟦at gc init_noop_init_loop_done s; s'↓ = s↓(gc := s↓ gc⦇muts := gc_muts s↓ - {gc_mut s↓}⦈); taken gc init_noop_init_loop_done s'; ∀p''∈- {gc}. GST s' p'' = GST s p''; sys_hs_type s↓ = ht_NOOP; gc_mut s↓ ∈ gc_muts s↓; ∀x. x ∉ gc_muts s↓ ⟶ sys_hs_pending x s↓ ∨ sys_ghost_hs_in_sync x s↓; sys_ghost_hs_phase s↓ = hp_InitMark; sys_hs_pending (gc_mut s↓) s↓ ∨ sys_ghost_hs_in_sync (gc_mut s↓) s↓; ∀x. x ∈ gc_muts s↓ ∧ x ≠ gc_mut s↓ ⟶ ¬ sys_hs_pending x s↓ ∧ ¬ sys_ghost_hs_in_sync x s↓; x ∈ gc_muts s↓ ⟶ x = gc_mut s↓; ¬ sys_ghost_hs_in_sync x s↓⟧ ⟹ sys_hs_pending x s↓› 9. ‹⋀s s' x. ⟦at gc idle_flip_noop_done_loop_rendezvous s; at sys sys.sys_hs_gc_done s; s'↓ = s↓(gc := s↓ gc⦇muts := gc_muts s↓ - {uu_. uu_ = gc_mut s↓ ∧ ¬ sys_hs_pending (gc_mut s↓) s↓}⦈, sys := s↓ sys); taken gc idle_flip_noop_done_loop_rendezvous s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; sys_hs_type s↓ = ht_NOOP; ∀x. sys_hs_pending x s↓ ∨ sys_ghost_hs_in_sync x s↓; ∀x. x ∉ gc_muts s↓ ⟶ ¬ sys_hs_pending x s↓; sys_ghost_hs_phase s↓ = hp_IdleInit; x ∈ gc_muts s↓ ⟶ x = gc_mut s↓ ∧ ¬ sys_hs_pending (gc_mut s↓) s↓; sys_hs_pending x s↓⟧ ⟹ False› 10. ‹⋀s s' x. ⟦at gc idle_flip_noop_init_loop_done s; s'↓ = s↓(gc := s↓ gc⦇muts := gc_muts s↓ - {gc_mut s↓}⦈); taken gc idle_flip_noop_init_loop_done s'; ∀p''∈- {gc}. GST s' p'' = GST s p''; sys_hs_type s↓ = ht_NOOP; gc_mut s↓ ∈ gc_muts s↓; ∀x. x ∉ gc_muts s↓ ⟶ sys_hs_pending x s↓ ∨ sys_ghost_hs_in_sync x s↓; sys_ghost_hs_phase s↓ = hp_IdleInit; sys_hs_pending (gc_mut s↓) s↓ ∨ sys_ghost_hs_in_sync (gc_mut s↓) s↓; ∀x. x ∈ gc_muts s↓ ∧ x ≠ gc_mut s↓ ⟶ ¬ sys_hs_pending x s↓ ∧ ¬ sys_ghost_hs_in_sync x s↓; x ∈ gc_muts s↓ ⟶ x = gc_mut s↓; ¬ sys_ghost_hs_in_sync x s↓⟧ ⟹ sys_hs_pending x s↓› 11. ‹⋀s s' x. ⟦at gc idle_noop_done_loop_rendezvous s; at sys sys.sys_hs_gc_done s; s'↓ = s↓(gc := s↓ gc⦇muts := gc_muts s↓ - {uu_. uu_ = gc_mut s↓ ∧ ¬ sys_hs_pending (gc_mut s↓) s↓}⦈, sys := s↓ sys); taken gc idle_noop_done_loop_rendezvous s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; sys_hs_type s↓ = ht_NOOP; ∀x. sys_hs_pending x s↓ ∨ sys_ghost_hs_in_sync x s↓; ∀x. x ∉ gc_muts s↓ ⟶ ¬ sys_hs_pending x s↓; sys_ghost_hs_phase s↓ = hp_Idle; x ∈ gc_muts s↓ ⟶ x = gc_mut s↓ ∧ ¬ sys_hs_pending (gc_mut s↓) s↓; sys_hs_pending x s↓⟧ ⟹ False› 12. ‹⋀s s' x. ⟦at gc idle_noop_init_loop_done s; s'↓ = s↓(gc := s↓ gc⦇muts := gc_muts s↓ - {gc_mut s↓}⦈); taken gc idle_noop_init_loop_done s'; ∀p''∈- {gc}. GST s' p'' = GST s p''; sys_hs_type s↓ = ht_NOOP; gc_mut s↓ ∈ gc_muts s↓; ∀x. x ∉ gc_muts s↓ ⟶ sys_hs_pending x s↓ ∨ sys_ghost_hs_in_sync x s↓; sys_ghost_hs_phase s↓ = hp_Idle; sys_hs_pending (gc_mut s↓) s↓ ∨ sys_ghost_hs_in_sync (gc_mut s↓) s↓; ∀x. x ∈ gc_muts s↓ ∧ x ≠ gc_mut s↓ ⟶ ¬ sys_hs_pending x s↓ ∧ ¬ sys_ghost_hs_in_sync x s↓; x ∈ gc_muts s↓ ⟶ x = gc_mut s↓; ¬ sys_ghost_hs_in_sync x s↓⟧ ⟹ sys_hs_pending x s↓› discuss goal 1*) apply fastforce (*discuss goal 2*) apply fastforce (*discuss goal 3*) apply fastforce (*discuss goal 4*) apply fastforce (*discuss goal 5*) apply fastforce (*discuss goal 6*) apply fastforce (*discuss goal 7*) apply fastforce (*discuss goal 8*) apply fastforce (*discuss goal 9*) apply fastforce (*discuss goal 10*) apply fastforce (*discuss goal 11*) apply fastforce (*discuss goal 12*) apply fastforce (*proven 12 subgoals*) . lemma (in gc) handshake_phase_inv[intro]: notes fun_upd_apply[simp] shows "⦃ handshake_invL ❙∧ LSTP handshake_phase_inv ⦄ gc ⦃ LSTP handshake_phase_inv ⦄" unfolding handshake_phase_inv_def (*goal: ‹⦃λs. handshake_invL s ∧ (∀x. (sys_ghost_hs_in_sync x s↓, sys_hs_type s↓, sys_ghost_hs_phase s↓, ghost_hs_phase (s↓ (mutator x))) ∈ hp_step_rel ∧ (sys_hs_pending x s↓ ⟶ ¬ sys_ghost_hs_in_sync x s↓))⦄ gc ⦃λs. ∀x. (sys_ghost_hs_in_sync x s↓, sys_hs_type s↓, sys_ghost_hs_phase s↓, ghost_hs_phase (s↓ (mutator x))) ∈ hp_step_rel ∧ (sys_hs_pending x s↓ ⟶ ¬ sys_ghost_hs_in_sync x s↓)⦄›*) apply (vcg_jackhammer (no_thin_post_inv)) (*goals: 1. ‹⋀s s' x. ⟦at gc mark_loop_get_work_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_GetWork, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_IdleMarkSweep⦈); taken gc mark_loop_get_work_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; ∀x. (True, sys_hs_type s↓, hp_IdleMarkSweep, ghost_hs_phase (s↓ (mutator x))) ∈ hp_step_rel; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep⟧ ⟹ (False, ht_GetWork, hp_IdleMarkSweep, ghost_hs_phase (s↓ (mutator x))) ∈ hp_step_rel› 2. ‹⋀s s' x. ⟦at gc mark_loop_get_roots_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_GetRoots, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_IdleMarkSweep⦈); taken gc mark_loop_get_roots_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; ∀x. (True, sys_hs_type s↓, hp_Mark, ghost_hs_phase (s↓ (mutator x))) ∈ hp_step_rel; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_Mark⟧ ⟹ (False, ht_GetRoots, hp_IdleMarkSweep, ghost_hs_phase (s↓ (mutator x))) ∈ hp_step_rel› 3. ‹⋀s s' x. ⟦at gc mark_noop_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_NOOP, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_Mark⦈); taken gc mark_noop_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; ∀x. (True, sys_hs_type s↓, hp_InitMark, ghost_hs_phase (s↓ (mutator x))) ∈ hp_step_rel; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_InitMark⟧ ⟹ (False, ht_NOOP, hp_Mark, ghost_hs_phase (s↓ (mutator x))) ∈ hp_step_rel› 4. ‹⋀s s' x. ⟦at gc init_noop_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_NOOP, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_InitMark⦈); taken gc init_noop_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; ∀x. (True, sys_hs_type s↓, hp_IdleInit, ghost_hs_phase (s↓ (mutator x))) ∈ hp_step_rel; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleInit⟧ ⟹ (False, ht_NOOP, hp_InitMark, ghost_hs_phase (s↓ (mutator x))) ∈ hp_step_rel› 5. ‹⋀s s' x. ⟦at gc idle_flip_noop_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_NOOP, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_IdleInit⦈); taken gc idle_flip_noop_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; ∀x. (True, sys_hs_type s↓, hp_Idle, ghost_hs_phase (s↓ (mutator x))) ∈ hp_step_rel; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_Idle⟧ ⟹ (False, ht_NOOP, hp_IdleInit, ghost_hs_phase (s↓ (mutator x))) ∈ hp_step_rel› 6. ‹⋀s s' x. ⟦at gc idle_noop_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_NOOP, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_Idle⦈); taken gc idle_noop_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; ∀x. (True, sys_hs_type s↓, hp_IdleMarkSweep, ghost_hs_phase (s↓ (mutator x))) ∈ hp_step_rel; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep⟧ ⟹ (False, ht_NOOP, hp_Idle, ghost_hs_phase (s↓ (mutator x))) ∈ hp_step_rel› discuss goal 1*) apply ((auto simp: handshake_phase_inv_def (*‹handshake_phase_inv = (λs. ∀x. (sys_ghost_hs_in_sync x s, sys_hs_type s, sys_ghost_hs_phase s, ghost_hs_phase (s (mutator x))) ∈ hp_step_rel ∧ (sys_hs_pending x s ⟶ ¬ sys_ghost_hs_in_sync x s))›*) hp_step_rel_def (*‹hp_step_rel = {True} × ({(ht_NOOP, hp, hp) |hp. hp ∈ {hp_Idle, hp_IdleInit, hp_InitMark, hp_Mark}} ∪ {(ht_GetRoots, hp_IdleMarkSweep, hp_IdleMarkSweep), (ht_GetWork, hp_IdleMarkSweep, hp_IdleMarkSweep)}) ∪ {False} × {(ht_NOOP, hp_Idle, hp_IdleMarkSweep), (ht_NOOP, hp_IdleInit, hp_Idle), (ht_NOOP, hp_InitMark, hp_IdleInit), (ht_NOOP, hp_Mark, hp_InitMark), (ht_GetRoots, hp_IdleMarkSweep, hp_Mark), (ht_GetWork, hp_IdleMarkSweep, hp_IdleMarkSweep)}›*))[1]) (*discuss goal 2*) apply ((auto simp: handshake_phase_inv_def (*‹handshake_phase_inv = (λs::?'mut process_name ⇒ (?'field, ?'mut, ?'payload, ?'ref) Model.local_state. ∀x::?'mut. (sys_ghost_hs_in_sync x s, sys_hs_type s, sys_ghost_hs_phase s, ghost_hs_phase (s (mutator x))) ∈ hp_step_rel ∧ (sys_hs_pending x s ⟶ ¬ sys_ghost_hs_in_sync x s))›*) hp_step_rel_def (*‹hp_step_rel = {True} × ({(ht_NOOP, hp, hp) |hp::hs_phase. hp ∈ {hp_Idle, hp_IdleInit, hp_InitMark, hp_Mark}} ∪ {(ht_GetRoots, hp_IdleMarkSweep, hp_IdleMarkSweep), (ht_GetWork, hp_IdleMarkSweep, hp_IdleMarkSweep)}) ∪ {False} × {(ht_NOOP, hp_Idle, hp_IdleMarkSweep), (ht_NOOP, hp_IdleInit, hp_Idle), (ht_NOOP, hp_InitMark, hp_IdleInit), (ht_NOOP, hp_Mark, hp_InitMark), (ht_GetRoots, hp_IdleMarkSweep, hp_Mark), (ht_GetWork, hp_IdleMarkSweep, hp_IdleMarkSweep)}›*))[1]) (*discuss goal 3*) apply ((auto simp: handshake_phase_inv_def (*‹handshake_phase_inv = (λs::?'mut process_name ⇒ (?'field, ?'mut, ?'payload, ?'ref) Model.local_state. ∀x::?'mut. (sys_ghost_hs_in_sync x s, sys_hs_type s, sys_ghost_hs_phase s, ghost_hs_phase (s (mutator x))) ∈ hp_step_rel ∧ (sys_hs_pending x s ⟶ ¬ sys_ghost_hs_in_sync x s))›*) hp_step_rel_def (*‹hp_step_rel = {True} × ({(ht_NOOP, hp, hp) |hp::hs_phase. hp ∈ {hp_Idle, hp_IdleInit, hp_InitMark, hp_Mark}} ∪ {(ht_GetRoots, hp_IdleMarkSweep, hp_IdleMarkSweep), (ht_GetWork, hp_IdleMarkSweep, hp_IdleMarkSweep)}) ∪ {False} × {(ht_NOOP, hp_Idle, hp_IdleMarkSweep), (ht_NOOP, hp_IdleInit, hp_Idle), (ht_NOOP, hp_InitMark, hp_IdleInit), (ht_NOOP, hp_Mark, hp_InitMark), (ht_GetRoots, hp_IdleMarkSweep, hp_Mark), (ht_GetWork, hp_IdleMarkSweep, hp_IdleMarkSweep)}›*))[1]) (*discuss goal 4*) apply ((auto simp: handshake_phase_inv_def (*‹handshake_phase_inv = (λs. ∀x. (sys_ghost_hs_in_sync x s, sys_hs_type s, sys_ghost_hs_phase s, ghost_hs_phase (s (mutator x))) ∈ hp_step_rel ∧ (sys_hs_pending x s ⟶ ¬ sys_ghost_hs_in_sync x s))›*) hp_step_rel_def (*‹hp_step_rel = {True} × ({(ht_NOOP, hp, hp) |hp. hp ∈ {hp_Idle, hp_IdleInit, hp_InitMark, hp_Mark}} ∪ {(ht_GetRoots, hp_IdleMarkSweep, hp_IdleMarkSweep), (ht_GetWork, hp_IdleMarkSweep, hp_IdleMarkSweep)}) ∪ {False} × {(ht_NOOP, hp_Idle, hp_IdleMarkSweep), (ht_NOOP, hp_IdleInit, hp_Idle), (ht_NOOP, hp_InitMark, hp_IdleInit), (ht_NOOP, hp_Mark, hp_InitMark), (ht_GetRoots, hp_IdleMarkSweep, hp_Mark), (ht_GetWork, hp_IdleMarkSweep, hp_IdleMarkSweep)}›*))[1]) (*discuss goal 5*) apply ((auto simp: handshake_phase_inv_def (*‹handshake_phase_inv = (λs. ∀x. (sys_ghost_hs_in_sync x s, sys_hs_type s, sys_ghost_hs_phase s, ghost_hs_phase (s (mutator x))) ∈ hp_step_rel ∧ (sys_hs_pending x s ⟶ ¬ sys_ghost_hs_in_sync x s))›*) hp_step_rel_def (*‹hp_step_rel = {True} × ({(ht_NOOP, hp, hp) |hp. hp ∈ {hp_Idle, hp_IdleInit, hp_InitMark, hp_Mark}} ∪ {(ht_GetRoots, hp_IdleMarkSweep, hp_IdleMarkSweep), (ht_GetWork, hp_IdleMarkSweep, hp_IdleMarkSweep)}) ∪ {False} × {(ht_NOOP, hp_Idle, hp_IdleMarkSweep), (ht_NOOP, hp_IdleInit, hp_Idle), (ht_NOOP, hp_InitMark, hp_IdleInit), (ht_NOOP, hp_Mark, hp_InitMark), (ht_GetRoots, hp_IdleMarkSweep, hp_Mark), (ht_GetWork, hp_IdleMarkSweep, hp_IdleMarkSweep)}›*))[1]) (*discuss goal 6*) apply ((auto simp: handshake_phase_inv_def (*‹handshake_phase_inv = (λs::?'mut process_name ⇒ (?'field, ?'mut, ?'payload, ?'ref) Model.local_state. ∀x::?'mut. (sys_ghost_hs_in_sync x s, sys_hs_type s, sys_ghost_hs_phase s, ghost_hs_phase (s (mutator x))) ∈ hp_step_rel ∧ (sys_hs_pending x s ⟶ ¬ sys_ghost_hs_in_sync x s))›*) hp_step_rel_def (*‹hp_step_rel = {True} × ({(ht_NOOP, hp, hp) |hp::hs_phase. hp ∈ {hp_Idle, hp_IdleInit, hp_InitMark, hp_Mark}} ∪ {(ht_GetRoots, hp_IdleMarkSweep, hp_IdleMarkSweep), (ht_GetWork, hp_IdleMarkSweep, hp_IdleMarkSweep)}) ∪ {False} × {(ht_NOOP, hp_Idle, hp_IdleMarkSweep), (ht_NOOP, hp_IdleInit, hp_Idle), (ht_NOOP, hp_InitMark, hp_IdleInit), (ht_NOOP, hp_Mark, hp_InitMark), (ht_GetRoots, hp_IdleMarkSweep, hp_Mark), (ht_GetWork, hp_IdleMarkSweep, hp_IdleMarkSweep)}›*))[1]) (*proven 6 subgoals*) . text‹ Local handshake phase invariant for the mutators. › lemma (in mut_m) handshake_invL_eq_imp: "eq_imp (λ(_::unit) s. (AT s (mutator m), s↓ (mutator m), sys_hs_type s↓, sys_hs_pending m s↓, mem_store_buffers (s↓ sys) (mutator m))) handshake_invL" unfolding eq_imp_def handshake_invL_def (*goal: ‹∀s s'. (∀x. (AT s (mutator m), s↓ (mutator m), sys_hs_type s↓, sys_hs_pending m s↓, sys_mem_store_buffers (mutator m) s↓) = (AT s' (mutator m), s'↓ (mutator m), sys_hs_type s'↓, sys_hs_pending m s'↓, sys_mem_store_buffers (mutator m) s'↓)) ⟶ ((atS (mutator m) hs_noop_locs s ⟶ sys_hs_type s↓ = ht_NOOP) ∧ (atS (mutator m) hs_get_roots_locs s ⟶ sys_hs_type s↓ = ht_GetRoots) ∧ (atS (mutator m) hs_get_work_locs s ⟶ sys_hs_type s↓ = ht_GetWork) ∧ (atS (mutator m) ht_loaded_locs s ⟶ mut_hs_pending s↓ ⟶ mut_hs_type s↓ = sys_hs_type s↓) ∧ (atS (mutator m) hs_pending_loaded_locs s ⟶ mut_hs_pending s↓ ⟶ sys_hs_pending m s↓) ∧ (atS (mutator m) hs_pending_locs s ⟶ mut_hs_pending s↓) ∧ (atS (mutator m) no_pending_mutations_locs s ⟶ filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s↓) = [])) = ((atS (mutator m) hs_noop_locs s' ⟶ sys_hs_type s'↓ = ht_NOOP) ∧ (atS (mutator m) hs_get_roots_locs s' ⟶ sys_hs_type s'↓ = ht_GetRoots) ∧ (atS (mutator m) hs_get_work_locs s' ⟶ sys_hs_type s'↓ = ht_GetWork) ∧ (atS (mutator m) ht_loaded_locs s' ⟶ mut_hs_pending s'↓ ⟶ mut_hs_type s'↓ = sys_hs_type s'↓) ∧ (atS (mutator m) hs_pending_loaded_locs s' ⟶ mut_hs_pending s'↓ ⟶ sys_hs_pending m s'↓) ∧ (atS (mutator m) hs_pending_locs s' ⟶ mut_hs_pending s'↓) ∧ (atS (mutator m) no_pending_mutations_locs s' ⟶ filter (λs. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s'↓) = []))›*) by simp lemmas mut_m_handshake_invL_niE[nie] = iffD1[OF mut_m.handshake_invL_eq_imp[simplified eq_imp_simps, rule_format, unfolded conj_explode], rotated -1] lemma (in mut_m) handshake_invL[intro]: "⦃ handshake_invL ⦄ mutator m" by vcg_jackhammer lemma (in mut_m') handshake_invL[intro]: "⦃ handshake_invL ⦄ mutator m'" by vcg_chainsaw lemma (in gc) mut_handshake_invL[intro]: notes fun_upd_apply[simp] shows "⦃ handshake_invL ❙∧ mut_m.handshake_invL m ⦄ gc ⦃ mut_m.handshake_invL m ⦄" by (vcg_chainsaw mut_m.handshake_invL_def) lemma (in sys) mut_handshake_invL[intro]: notes if_splits[split] notes fun_upd_apply[simp] shows "⦃ mut_m.handshake_invL m ⦄ sys" by (vcg_chainsaw mut_m.handshake_invL_def) lemma (in mut_m) gc_handshake_invL[intro]: notes fun_upd_apply[simp] shows "⦃ handshake_invL ❙∧ gc.handshake_invL ⦄ mutator m ⦃ gc.handshake_invL ⦄" by (msorry) lemma (in mut_m) handshake_phase_inv[intro]: notes fun_upd_apply[simp] shows "⦃ handshake_invL ❙∧ LSTP handshake_phase_inv ⦄ mutator m ⦃ LSTP handshake_phase_inv ⦄" unfolding handshake_phase_inv_def (*goal: ‹⦃λs. handshake_invL s ∧ (∀x. (sys_ghost_hs_in_sync x s↓, sys_hs_type s↓, sys_ghost_hs_phase s↓, ghost_hs_phase (s↓ (mutator x))) ∈ hp_step_rel ∧ (sys_hs_pending x s↓ ⟶ ¬ sys_ghost_hs_in_sync x s↓))⦄ mutator m ⦃λs. ∀x. (sys_ghost_hs_in_sync x s↓, sys_hs_type s↓, sys_ghost_hs_phase s↓, ghost_hs_phase (s↓ (mutator x))) ∈ hp_step_rel ∧ (sys_hs_pending x s↓ ⟶ ¬ sys_ghost_hs_in_sync x s↓)⦄›*) apply (vcg_jackhammer (no_thin_post_inv)) (*goals: 1. ‹⋀(s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state) s'::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state. ⟦at (mutator (m::'mut)) hs_get_work_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_work_done s'; ∀p''::'mut process_name∈- {mutator m, sys}. GST s' p'' = GST s p''; ∀x::'mut. (sys_ghost_hs_in_sync x s↓, ht_GetWork, sys_ghost_hs_phase s↓, ghost_hs_phase (s↓ (mutator x))) ∈ hp_step_rel ∧ (sys_hs_pending x s↓ ⟶ ¬ sys_ghost_hs_in_sync x s↓); sys_hs_type s↓ = ht_GetWork; mut_hs_type s↓ = ht_GetWork; sys_hs_pending m s↓; mut_hs_pending s↓; filter (λs::('a, 'b, 'c) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s↓) = []⟧ ⟹ (True, ht_GetWork, sys_ghost_hs_phase s↓, mut_ghost_hs_phase s↓) ∈ hp_step_rel› 2. ‹⋀(s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state) s'::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state. ⟦at (mutator (m::'mut)) hs_get_roots_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}, ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_roots_done s'; ∀p''::'mut process_name∈- {mutator m, sys}. GST s' p'' = GST s p''; ∀x::'mut. (sys_ghost_hs_in_sync x s↓, ht_GetRoots, sys_ghost_hs_phase s↓, ghost_hs_phase (s↓ (mutator x))) ∈ hp_step_rel ∧ (sys_hs_pending x s↓ ⟶ ¬ sys_ghost_hs_in_sync x s↓); sys_hs_type s↓ = ht_GetRoots; mut_hs_type s↓ = ht_GetRoots; sys_hs_pending m s↓; mut_hs_pending s↓; filter (λs::('a, 'b, 'c) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s↓) = []⟧ ⟹ (True, ht_GetRoots, sys_ghost_hs_phase s↓, hs_step (mut_ghost_hs_phase s↓)) ∈ hp_step_rel› 3. ‹⋀(s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state) s'::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state. ⟦at (mutator (m::'mut)) hs_noop_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_noop_done s'; ∀p''::'mut process_name∈- {mutator m, sys}. GST s' p'' = GST s p''; ∀x::'mut. (sys_ghost_hs_in_sync x s↓, ht_NOOP, sys_ghost_hs_phase s↓, ghost_hs_phase (s↓ (mutator x))) ∈ hp_step_rel ∧ (sys_hs_pending x s↓ ⟶ ¬ sys_ghost_hs_in_sync x s↓); sys_hs_type s↓ = ht_NOOP; mut_hs_type s↓ = ht_NOOP; sys_hs_pending m s↓; mut_hs_pending s↓; filter (λs::('a, 'b, 'c) mem_store_action. is_mw_Mutate s ∨ is_mw_Mutate_Payload s) (sys_mem_store_buffers (mutator m) s↓) = []⟧ ⟹ (True, ht_NOOP, sys_ghost_hs_phase s↓, hs_step (mut_ghost_hs_phase s↓)) ∈ hp_step_rel› discuss goal 1*) apply ((auto simp: hp_step_rel_def (*‹hp_step_rel = {True} × ({(ht_NOOP, hp, hp) |hp. hp ∈ {hp_Idle, hp_IdleInit, hp_InitMark, hp_Mark}} ∪ {(ht_GetRoots, hp_IdleMarkSweep, hp_IdleMarkSweep), (ht_GetWork, hp_IdleMarkSweep, hp_IdleMarkSweep)}) ∪ {False} × {(ht_NOOP, hp_Idle, hp_IdleMarkSweep), (ht_NOOP, hp_IdleInit, hp_Idle), (ht_NOOP, hp_InitMark, hp_IdleInit), (ht_NOOP, hp_Mark, hp_InitMark), (ht_GetRoots, hp_IdleMarkSweep, hp_Mark), (ht_GetWork, hp_IdleMarkSweep, hp_IdleMarkSweep)}›*))[1]) (*discuss goal 2*) apply ((auto simp: hp_step_rel_def (*‹hp_step_rel = {True} × ({(ht_NOOP, hp, hp) |hp. hp ∈ {hp_Idle, hp_IdleInit, hp_InitMark, hp_Mark}} ∪ {(ht_GetRoots, hp_IdleMarkSweep, hp_IdleMarkSweep), (ht_GetWork, hp_IdleMarkSweep, hp_IdleMarkSweep)}) ∪ {False} × {(ht_NOOP, hp_Idle, hp_IdleMarkSweep), (ht_NOOP, hp_IdleInit, hp_Idle), (ht_NOOP, hp_InitMark, hp_IdleInit), (ht_NOOP, hp_Mark, hp_InitMark), (ht_GetRoots, hp_IdleMarkSweep, hp_Mark), (ht_GetWork, hp_IdleMarkSweep, hp_IdleMarkSweep)}›*))[1]) (*discuss goal 3*) apply ((auto simp: hp_step_rel_def (*‹hp_step_rel = {True} × ({(ht_NOOP, hp, hp) |hp. hp ∈ {hp_Idle, hp_IdleInit, hp_InitMark, hp_Mark}} ∪ {(ht_GetRoots, hp_IdleMarkSweep, hp_IdleMarkSweep), (ht_GetWork, hp_IdleMarkSweep, hp_IdleMarkSweep)}) ∪ {False} × {(ht_NOOP, hp_Idle, hp_IdleMarkSweep), (ht_NOOP, hp_IdleInit, hp_Idle), (ht_NOOP, hp_InitMark, hp_IdleInit), (ht_NOOP, hp_Mark, hp_InitMark), (ht_GetRoots, hp_IdleMarkSweep, hp_Mark), (ht_GetWork, hp_IdleMarkSweep, hp_IdleMarkSweep)}›*))[1]) (*proven 3 subgoals*) . text‹ Validity of @{const "sys_fM"} wrt @{const "gc_fM"} and the handshake phase. Effectively we use @{const "gc_fM"} as ghost state. We also include the TSO lock to rule out the GC having any pending marks during the @{const "hp_Idle"} handshake phase. › lemma gc_fM_fA_invL_eq_imp: "eq_imp (λ(_::unit) s. (AT s gc, s↓ gc, sys_fA s↓, sys_fM s↓, sys_mem_store_buffers gc s↓)) gc.fM_fA_invL" by (simp add: gc.fM_fA_invL_def (*‹gc.fM_fA_invL = (λs. (atS gc gc.fM_eq_locs s ⟶ gc_fM s↓ = sys_fM s↓) ∧ (at gc gc.idle_store_fM s ⟶ gc_fM s↓ ≠ sys_fM s↓) ∧ (at gc gc.idle_flip_noop_mfence s ⟶ sys_fM s↓ ≠ gc_fM s↓ ⟶ filter is_mw_fM (sys_mem_store_buffers gc s↓) ≠ []) ∧ (atS gc gc.fM_tso_empty_locs s ⟶ filter is_mw_fM (sys_mem_store_buffers gc s↓) = []) ∧ (atS gc gc.fA_eq_locs s ⟶ gc_fM s↓ = sys_fA s↓) ∧ (atS gc gc.fA_neq_locs s ⟶ gc_fM s↓ ≠ sys_fA s↓) ∧ (at gc gc.mark_noop_mfence s ⟶ gc_fM s↓ ≠ sys_fA s↓ ⟶ filter is_mw_fA (sys_mem_store_buffers gc s↓) ≠ []) ∧ (atS gc gc.fA_tso_empty_locs s ⟶ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []))›*) eq_imp_def (*‹eq_imp ?f ?g ≡ ∀s s'. (∀x. ?f x s = ?f x s') ⟶ ?g s = ?g s'›*)) lemmas gc_fM_fA_invL_niE[nie] = iffD1[OF gc_fM_fA_invL_eq_imp[simplified eq_imp_simps, rule_format, unfolded conj_explode], rotated -1] context gc begin lemma fM_fA_invL[intro]: "⦃ fM_fA_invL ⦄ gc" by vcg_jackhammer lemma fM_rel_inv[intro]: notes fun_upd_apply[simp] shows "⦃ fM_fA_invL ❙∧ handshake_invL ❙∧ tso_lock_invL ❙∧ LSTP fM_rel_inv ⦄ gc ⦃ LSTP fM_rel_inv ⦄" by (msorry) lemma fA_rel_inv[intro]: notes fun_upd_apply[simp] shows "⦃ fM_fA_invL ❙∧ handshake_invL ❙∧ LSTP fA_rel_inv ⦄ gc ⦃ LSTP fA_rel_inv ⦄" by (msorry) end context mut_m begin lemma gc_fM_fA_invL[intro]: "⦃ gc.fM_fA_invL ⦄ mutator m" by (vcg_chainsaw gc.fM_fA_invL_def) lemma fM_rel_inv[intro]: notes fun_upd_apply[simp] shows "⦃ LSTP fM_rel_inv ⦄ mutator m" unfolding fM_rel_inv_def (*goal: ‹⦃(λs::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state. (All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_fM s↓, sys_fM s↓, filter is_mw_fM (sys_mem_store_buffers gc s↓), sys_mem_lock s↓ = Some gc) ∈ fM_rel)⦄ mutator (m::'mut)›*) apply ((vcg_jackhammer (no_thin_post_inv))[1]) (*goals: 1. ‹⋀s s'. ⟦(All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_fM s↓, sys_fM s↓, filter is_mw_fM (sys_mem_store_buffers gc s↓), sys_mem_lock s↓ = Some gc) ∈ fM_rel; at (mutator m) hs_get_work_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_work_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''⟧ ⟹ (All ((ghost_hs_in_sync (s↓ sys))(m := True)), sys_ghost_hs_phase s↓, gc_fM s↓, sys_fM s↓, filter is_mw_fM (sys_mem_store_buffers gc s↓), sys_mem_lock s↓ = Some gc) ∈ fM_rel› 2. ‹⋀s s'. ⟦(All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_fM s↓, sys_fM s↓, filter is_mw_fM (sys_mem_store_buffers gc s↓), sys_mem_lock s↓ = Some gc) ∈ fM_rel; at (mutator m) hs_get_roots_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}, ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_roots_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''⟧ ⟹ (All ((ghost_hs_in_sync (s↓ sys))(m := True)), sys_ghost_hs_phase s↓, gc_fM s↓, sys_fM s↓, filter is_mw_fM (sys_mem_store_buffers gc s↓), sys_mem_lock s↓ = Some gc) ∈ fM_rel› 3. ‹⋀s s'. ⟦(All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_fM s↓, sys_fM s↓, filter is_mw_fM (sys_mem_store_buffers gc s↓), sys_mem_lock s↓ = Some gc) ∈ fM_rel; at (mutator m) hs_noop_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_noop_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''⟧ ⟹ (All ((ghost_hs_in_sync (s↓ sys))(m := True)), sys_ghost_hs_phase s↓, gc_fM s↓, sys_fM s↓, filter is_mw_fM (sys_mem_store_buffers gc s↓), sys_mem_lock s↓ = Some gc) ∈ fM_rel› discuss goal 1*) apply (simp add: fM_rel_def (*‹fM_rel = {(in_sync, hp, fM, fM, [], l) |(fM::bool) (hp::hs_phase) (in_sync::bool) l::bool. hp = hp_Idle ⟶ ¬ in_sync} ∪ {(in_sync, hp_Idle, fM, fM', [], l) |(fM::bool) (fM'::bool) (in_sync::bool) l::bool. in_sync} ∪ {(in_sync, hp_Idle, ¬ fM, fM, [mw_fM (¬ fM)], False) |(fM::bool) in_sync::bool. in_sync}›*)) (*top goal: ‹⋀s s'. ⟦(All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_fM s↓, sys_fM s↓, filter is_mw_fM (sys_mem_store_buffers gc s↓), sys_mem_lock s↓ = Some gc) ∈ fM_rel; at (mutator m) hs_get_work_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_work_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''⟧ ⟹ (All ((ghost_hs_in_sync (s↓ sys))(m := True)), sys_ghost_hs_phase s↓, gc_fM s↓, sys_fM s↓, filter is_mw_fM (sys_mem_store_buffers gc s↓), sys_mem_lock s↓ = Some gc) ∈ fM_rel› and 2 goals remain*) apply ((elim disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*))[1]) (*goals: 1. ‹⋀s s'. ⟦at (mutator m) hs_get_work_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_work_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_fM s↓ = gc_fM s↓ ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ (sys_ghost_hs_phase s↓ = hp_Idle ⟶ (∃x. ¬ sys_ghost_hs_in_sync x s↓))⟧ ⟹ sys_fM s↓ = gc_fM s↓ ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ (sys_ghost_hs_phase s↓ = hp_Idle ⟶ (∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓))) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ gc_fM s↓ = (¬ sys_fM s↓) ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [mw_fM (¬ sys_fM s↓)] ∧ sys_mem_lock s↓ ≠ Some gc ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True))› 2. ‹⋀s s'. ⟦at (mutator m) hs_get_work_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_work_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ All (ghost_hs_in_sync (s↓ sys))⟧ ⟹ sys_fM s↓ = gc_fM s↓ ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ (sys_ghost_hs_phase s↓ = hp_Idle ⟶ (∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓))) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ gc_fM s↓ = (¬ sys_fM s↓) ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [mw_fM (¬ sys_fM s↓)] ∧ sys_mem_lock s↓ ≠ Some gc ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True))› 3. ‹⋀s s'. ⟦at (mutator m) hs_get_work_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_work_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_Idle ∧ gc_fM s↓ = (¬ sys_fM s↓) ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [mw_fM (¬ sys_fM s↓)] ∧ sys_mem_lock s↓ ≠ Some gc ∧ All (ghost_hs_in_sync (s↓ sys))⟧ ⟹ sys_fM s↓ = gc_fM s↓ ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ (sys_ghost_hs_phase s↓ = hp_Idle ⟶ (∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓))) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ gc_fM s↓ = (¬ sys_fM s↓) ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [mw_fM (¬ sys_fM s↓)] ∧ sys_mem_lock s↓ ≠ Some gc ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True))› discuss goal 1*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 3*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 3 subgoals*) (*discuss goal 2*) apply (simp add: fM_rel_def (*‹fM_rel = {(in_sync, hp, fM, fM, [], l) |fM hp in_sync l. hp = hp_Idle ⟶ ¬ in_sync} ∪ {(in_sync, hp_Idle, fM, fM', [], l) |fM fM' in_sync l. in_sync} ∪ {(in_sync, hp_Idle, ¬ fM, fM, [mw_fM (¬ fM)], False) |fM in_sync. in_sync}›*)) (*top goal: ‹⋀s s'. ⟦(All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_fM s↓, sys_fM s↓, filter is_mw_fM (sys_mem_store_buffers gc s↓), sys_mem_lock s↓ = Some gc) ∈ fM_rel; at (mutator m) hs_get_roots_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}, ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_roots_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''⟧ ⟹ (All ((ghost_hs_in_sync (s↓ sys))(m := True)), sys_ghost_hs_phase s↓, gc_fM s↓, sys_fM s↓, filter is_mw_fM (sys_mem_store_buffers gc s↓), sys_mem_lock s↓ = Some gc) ∈ fM_rel› and 1 goal remains*) apply ((elim disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*))[1]) (*goals: 1. ‹⋀(s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state) s'::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state. ⟦at (mutator (m::'mut)) hs_get_roots_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}, ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_roots_done s'; ∀p''::'mut process_name∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_fM s↓ = gc_fM s↓ ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ (sys_ghost_hs_phase s↓ = hp_Idle ⟶ (∃x::'mut. ¬ sys_ghost_hs_in_sync x s↓))⟧ ⟹ sys_fM s↓ = gc_fM s↓ ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ (sys_ghost_hs_phase s↓ = hp_Idle ⟶ (∃x::'mut. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓))) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ gc_fM s↓ = (¬ sys_fM s↓) ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [mw_fM (¬ sys_fM s↓)] ∧ sys_mem_lock s↓ ≠ Some gc ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True))› 2. ‹⋀(s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state) s'::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state. ⟦at (mutator (m::'mut)) hs_get_roots_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}, ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_roots_done s'; ∀p''::'mut process_name∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ All (ghost_hs_in_sync (s↓ sys))⟧ ⟹ sys_fM s↓ = gc_fM s↓ ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ (sys_ghost_hs_phase s↓ = hp_Idle ⟶ (∃x::'mut. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓))) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ gc_fM s↓ = (¬ sys_fM s↓) ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [mw_fM (¬ sys_fM s↓)] ∧ sys_mem_lock s↓ ≠ Some gc ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True))› 3. ‹⋀(s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state) s'::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state. ⟦at (mutator (m::'mut)) hs_get_roots_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}, ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_roots_done s'; ∀p''::'mut process_name∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_Idle ∧ gc_fM s↓ = (¬ sys_fM s↓) ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [mw_fM (¬ sys_fM s↓)] ∧ sys_mem_lock s↓ ≠ Some gc ∧ All (ghost_hs_in_sync (s↓ sys))⟧ ⟹ sys_fM s↓ = gc_fM s↓ ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ (sys_ghost_hs_phase s↓ = hp_Idle ⟶ (∃x::'mut. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓))) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ gc_fM s↓ = (¬ sys_fM s↓) ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [mw_fM (¬ sys_fM s↓)] ∧ sys_mem_lock s↓ ≠ Some gc ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True))› discuss goal 1*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 3*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 3 subgoals*) (*discuss goal 3*) apply (simp add: fM_rel_def (*‹fM_rel = {(in_sync, hp, fM, fM, [], l) |fM hp in_sync l. hp = hp_Idle ⟶ ¬ in_sync} ∪ {(in_sync, hp_Idle, fM, fM', [], l) |fM fM' in_sync l. in_sync} ∪ {(in_sync, hp_Idle, ¬ fM, fM, [mw_fM (¬ fM)], False) |fM in_sync. in_sync}›*)) (*goal: ‹⋀(s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state) s'::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state. ⟦(All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, gc_fM s↓, sys_fM s↓, filter is_mw_fM (sys_mem_store_buffers gc s↓), sys_mem_lock s↓ = Some gc) ∈ fM_rel; at (mutator (m::'mut::type)) hs_noop_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_noop_done s'; ∀p''::'mut::type process_name∈- {mutator m, sys}. GST s' p'' = GST s p''⟧ ⟹ (All ((ghost_hs_in_sync (s↓ sys))(m := True)), sys_ghost_hs_phase s↓, gc_fM s↓, sys_fM s↓, filter is_mw_fM (sys_mem_store_buffers gc s↓), sys_mem_lock s↓ = Some gc) ∈ fM_rel›*) apply ((elim disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*))[1]) (*goals: 1. ‹⋀(s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state) s'::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state. ⟦at (mutator (m::'mut::type)) hs_noop_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_noop_done s'; ∀p''::'mut::type process_name∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_fM s↓ = gc_fM s↓ ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ (sys_ghost_hs_phase s↓ = hp_Idle ⟶ (∃x::'mut::type. ¬ sys_ghost_hs_in_sync x s↓))⟧ ⟹ sys_fM s↓ = gc_fM s↓ ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ (sys_ghost_hs_phase s↓ = hp_Idle ⟶ (∃x::'mut::type. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓))) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ gc_fM s↓ = (¬ sys_fM s↓) ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [mw_fM (¬ sys_fM s↓)] ∧ sys_mem_lock s↓ ≠ Some gc ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True))› 2. ‹⋀(s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state) s'::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state. ⟦at (mutator (m::'mut::type)) hs_noop_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_noop_done s'; ∀p''::'mut::type process_name∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ All (ghost_hs_in_sync (s↓ sys))⟧ ⟹ sys_fM s↓ = gc_fM s↓ ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ (sys_ghost_hs_phase s↓ = hp_Idle ⟶ (∃x::'mut::type. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓))) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ gc_fM s↓ = (¬ sys_fM s↓) ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [mw_fM (¬ sys_fM s↓)] ∧ sys_mem_lock s↓ ≠ Some gc ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True))› 3. ‹⋀(s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state) s'::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state. ⟦at (mutator (m::'mut::type)) hs_noop_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_noop_done s'; ∀p''::'mut::type process_name∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_Idle ∧ gc_fM s↓ = (¬ sys_fM s↓) ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [mw_fM (¬ sys_fM s↓)] ∧ sys_mem_lock s↓ ≠ Some gc ∧ All (ghost_hs_in_sync (s↓ sys))⟧ ⟹ sys_fM s↓ = gc_fM s↓ ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ (sys_ghost_hs_phase s↓ = hp_Idle ⟶ (∃x::'mut::type. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓))) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ gc_fM s↓ = (¬ sys_fM s↓) ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [mw_fM (¬ sys_fM s↓)] ∧ sys_mem_lock s↓ ≠ Some gc ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True))› discuss goal 1*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto split: if_splits (*‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 3*) apply ((auto split: if_splits (*‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 3 subgoals*) (*proven 3 subgoals*) . lemma fA_rel_inv[intro]: notes fun_upd_apply[simp] shows "⦃ LSTP fA_rel_inv ⦄ mutator m" unfolding fA_rel_inv_def (*goal: ‹⦃(λs. (All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, sys_fA s↓, gc_fM s↓, filter is_mw_fA (sys_mem_store_buffers gc s↓)) ∈ fA_rel)⦄ mutator m›*) apply ((vcg_jackhammer (no_thin_post_inv))[1]) (*goals: 1. ‹⋀s s'. ⟦(All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, sys_fA s↓, gc_fM s↓, filter is_mw_fA (sys_mem_store_buffers gc s↓)) ∈ fA_rel; at (mutator m) hs_get_work_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_work_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''⟧ ⟹ (All ((ghost_hs_in_sync (s↓ sys))(m := True)), sys_ghost_hs_phase s↓, sys_fA s↓, gc_fM s↓, filter is_mw_fA (sys_mem_store_buffers gc s↓)) ∈ fA_rel› 2. ‹⋀s s'. ⟦(All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, sys_fA s↓, gc_fM s↓, filter is_mw_fA (sys_mem_store_buffers gc s↓)) ∈ fA_rel; at (mutator m) hs_get_roots_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}, ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_roots_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''⟧ ⟹ (All ((ghost_hs_in_sync (s↓ sys))(m := True)), sys_ghost_hs_phase s↓, sys_fA s↓, gc_fM s↓, filter is_mw_fA (sys_mem_store_buffers gc s↓)) ∈ fA_rel› 3. ‹⋀s s'. ⟦(All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, sys_fA s↓, gc_fM s↓, filter is_mw_fA (sys_mem_store_buffers gc s↓)) ∈ fA_rel; at (mutator m) hs_noop_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_noop_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''⟧ ⟹ (All ((ghost_hs_in_sync (s↓ sys))(m := True)), sys_ghost_hs_phase s↓, sys_fA s↓, gc_fM s↓, filter is_mw_fA (sys_mem_store_buffers gc s↓)) ∈ fA_rel› discuss goal 1*) apply (simp add: fA_rel_def (*‹fA_rel = {(in_sync, hp_Idle, fA, fM, []) |fA fM in_sync. ¬ in_sync ⟶ fA = fM} ∪ {(in_sync, hp_IdleInit, fA, ¬ fA, []) |fA in_sync. True} ∪ {(in_sync, hp_InitMark, fA, ¬ fA, [mw_fA (¬ fA)]) |fA in_sync. in_sync} ∪ {(in_sync, hp_InitMark, fA, fM, []) |fA fM in_sync. ¬ in_sync ⟶ fA ≠ fM} ∪ {(in_sync, hp_Mark, fA, fA, []) |fA in_sync. True} ∪ {(in_sync, hp_IdleMarkSweep, fA, fA, []) |fA in_sync. True}›*)) (*top goal: ‹⋀s s'. ⟦(All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, sys_fA s↓, gc_fM s↓, filter is_mw_fA (sys_mem_store_buffers gc s↓)) ∈ fA_rel; at (mutator m) hs_get_work_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_work_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''⟧ ⟹ (All ((ghost_hs_in_sync (s↓ sys))(m := True)), sys_ghost_hs_phase s↓, sys_fA s↓, gc_fM s↓, filter is_mw_fA (sys_mem_store_buffers gc s↓)) ∈ fA_rel› and 2 goals remain*) apply ((elim disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*))[1]) (*goals: 1. ‹⋀s s'. ⟦at (mutator m) hs_get_work_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_work_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. ¬ sys_ghost_hs_in_sync x s↓) ⟶ sys_fA s↓ = gc_fM s↓)⟧ ⟹ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = gc_fM s↓) ∨ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ sys_fA s↓)] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = (¬ gc_fM s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› 2. ‹⋀s s'. ⟦at (mutator m) hs_get_work_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_work_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []⟧ ⟹ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = gc_fM s↓) ∨ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ sys_fA s↓)] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = (¬ gc_fM s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› 3. ‹⋀s s'. ⟦at (mutator m) hs_get_work_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_work_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ sys_fA s↓)] ∧ All (ghost_hs_in_sync (s↓ sys))⟧ ⟹ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = gc_fM s↓) ∨ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ sys_fA s↓)] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = (¬ gc_fM s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› 4. ‹⋀s s'. ⟦at (mutator m) hs_get_work_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_work_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. ¬ sys_ghost_hs_in_sync x s↓) ⟶ sys_fA s↓ = (¬ gc_fM s↓))⟧ ⟹ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = gc_fM s↓) ∨ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ sys_fA s↓)] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = (¬ gc_fM s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› 5. ‹⋀s s'. ⟦at (mutator m) hs_get_work_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_work_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []⟧ ⟹ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = gc_fM s↓) ∨ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ sys_fA s↓)] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = (¬ gc_fM s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› 6. ‹⋀s s'. ⟦at (mutator m) hs_get_work_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_work_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []⟧ ⟹ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = gc_fM s↓) ∨ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ sys_fA s↓)] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = (¬ gc_fM s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› discuss goal 1*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto split: if_splits (*‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 3*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 4*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 5*) apply ((auto split: if_splits (*‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 6*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 6 subgoals*) (*discuss goal 2*) apply (simp add: fA_rel_def (*‹fA_rel = {(in_sync, hp_Idle, fA, fM, []) |(fA::bool) (fM::bool) in_sync::bool. ¬ in_sync ⟶ fA = fM} ∪ {(in_sync, hp_IdleInit, fA, ¬ fA, []) |(fA::bool) in_sync::bool. True} ∪ {(in_sync, hp_InitMark, fA, ¬ fA, [mw_fA (¬ fA)]) |(fA::bool) in_sync::bool. in_sync} ∪ {(in_sync, hp_InitMark, fA, fM, []) |(fA::bool) (fM::bool) in_sync::bool. ¬ in_sync ⟶ fA ≠ fM} ∪ {(in_sync, hp_Mark, fA, fA, []) |(fA::bool) in_sync::bool. True} ∪ {(in_sync, hp_IdleMarkSweep, fA, fA, []) |(fA::bool) in_sync::bool. True}›*)) (*top goal: ‹⋀(s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state) s'::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state. ⟦(All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, sys_fA s↓, gc_fM s↓, filter is_mw_fA (sys_mem_store_buffers gc s↓)) ∈ fA_rel; at (mutator (m::'mut)) hs_get_roots_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}, ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_roots_done s'; ∀p''::'mut process_name∈- {mutator m, sys}. GST s' p'' = GST s p''⟧ ⟹ (All ((ghost_hs_in_sync (s↓ sys))(m := True)), sys_ghost_hs_phase s↓, sys_fA s↓, gc_fM s↓, filter is_mw_fA (sys_mem_store_buffers gc s↓)) ∈ fA_rel› and 1 goal remains*) apply ((elim disjE (*‹⟦(?P::bool) ∨ (?Q::bool); ?P ⟹ ?R::bool; ?Q ⟹ ?R⟧ ⟹ ?R›*))[1]) (*goals: 1. ‹⋀(s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state) s'::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state. ⟦at (mutator (m::'mut::type)) hs_get_roots_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}, ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_roots_done s'; ∀p''::'mut::type process_name∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x::'mut::type. ¬ sys_ghost_hs_in_sync x s↓) ⟶ sys_fA s↓ = gc_fM s↓)⟧ ⟹ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x::'mut::type. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = gc_fM s↓) ∨ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ sys_fA s↓)] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x::'mut::type. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = (¬ gc_fM s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› 2. ‹⋀(s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state) s'::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state. ⟦at (mutator (m::'mut::type)) hs_get_roots_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}, ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_roots_done s'; ∀p''::'mut::type process_name∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []⟧ ⟹ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x::'mut::type. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = gc_fM s↓) ∨ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ sys_fA s↓)] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x::'mut::type. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = (¬ gc_fM s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› 3. ‹⋀(s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state) s'::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state. ⟦at (mutator (m::'mut::type)) hs_get_roots_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}, ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_roots_done s'; ∀p''::'mut::type process_name∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ sys_fA s↓)] ∧ All (ghost_hs_in_sync (s↓ sys))⟧ ⟹ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x::'mut::type. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = gc_fM s↓) ∨ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ sys_fA s↓)] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x::'mut::type. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = (¬ gc_fM s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› 4. ‹⋀(s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state) s'::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state. ⟦at (mutator (m::'mut::type)) hs_get_roots_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}, ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_roots_done s'; ∀p''::'mut::type process_name∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x::'mut::type. ¬ sys_ghost_hs_in_sync x s↓) ⟶ sys_fA s↓ = (¬ gc_fM s↓))⟧ ⟹ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x::'mut::type. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = gc_fM s↓) ∨ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ sys_fA s↓)] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x::'mut::type. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = (¬ gc_fM s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› 5. ‹⋀(s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state) s'::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state. ⟦at (mutator (m::'mut::type)) hs_get_roots_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}, ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_roots_done s'; ∀p''::'mut::type process_name∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []⟧ ⟹ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x::'mut::type. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = gc_fM s↓) ∨ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ sys_fA s↓)] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x::'mut::type. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = (¬ gc_fM s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› 6. ‹⋀(s::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state) s'::(('a, 'b, 'c) response, char list, 'mut process_name, 'mut process_name × ('a, 'mut, 'b, 'c) request_op, ('a, 'mut, 'b, 'c) Model.local_state) system_state. ⟦at (mutator (m::'mut::type)) hs_get_roots_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇W := {}, ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), W := sys_W s↓ ∪ mut_W s↓, ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_get_roots_done s'; ∀p''::'mut::type process_name∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []⟧ ⟹ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x::'mut::type. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = gc_fM s↓) ∨ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ sys_fA s↓)] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x::'mut::type. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = (¬ gc_fM s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› discuss goal 1*) apply ((auto split: if_splits (*‹(?P::?'a::type ⇒ bool) (if ?Q::bool then ?x::?'a::type else (?y::?'a::type)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹(?P::?'a::type ⇒ bool) (if ?Q::bool then ?x::?'a::type else (?y::?'a::type)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 3*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 4*) apply ((auto split: if_splits (*‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 5*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 6*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 6 subgoals*) (*discuss goal 3*) apply (simp add: fA_rel_def (*‹fA_rel = {(in_sync, hp_Idle, fA, fM, []) |fA fM in_sync. ¬ in_sync ⟶ fA = fM} ∪ {(in_sync, hp_IdleInit, fA, ¬ fA, []) |fA in_sync. True} ∪ {(in_sync, hp_InitMark, fA, ¬ fA, [mw_fA (¬ fA)]) |fA in_sync. in_sync} ∪ {(in_sync, hp_InitMark, fA, fM, []) |fA fM in_sync. ¬ in_sync ⟶ fA ≠ fM} ∪ {(in_sync, hp_Mark, fA, fA, []) |fA in_sync. True} ∪ {(in_sync, hp_IdleMarkSweep, fA, fA, []) |fA in_sync. True}›*)) (*goal: ‹⋀s s'. ⟦(All (ghost_hs_in_sync (s↓ sys)), sys_ghost_hs_phase s↓, sys_fA s↓, gc_fM s↓, filter is_mw_fA (sys_mem_store_buffers gc s↓)) ∈ fA_rel; at (mutator m) hs_noop_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_noop_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''⟧ ⟹ (All ((ghost_hs_in_sync (s↓ sys))(m := True)), sys_ghost_hs_phase s↓, sys_fA s↓, gc_fM s↓, filter is_mw_fA (sys_mem_store_buffers gc s↓)) ∈ fA_rel›*) apply ((elim disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*))[1]) (*goals: 1. ‹⋀s s'. ⟦at (mutator m) hs_noop_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_noop_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. ¬ sys_ghost_hs_in_sync x s↓) ⟶ sys_fA s↓ = gc_fM s↓)⟧ ⟹ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = gc_fM s↓) ∨ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ sys_fA s↓)] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = (¬ gc_fM s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› 2. ‹⋀s s'. ⟦at (mutator m) hs_noop_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_noop_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []⟧ ⟹ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = gc_fM s↓) ∨ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ sys_fA s↓)] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = (¬ gc_fM s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› 3. ‹⋀s s'. ⟦at (mutator m) hs_noop_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_noop_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ sys_fA s↓)] ∧ All (ghost_hs_in_sync (s↓ sys))⟧ ⟹ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = gc_fM s↓) ∨ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ sys_fA s↓)] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = (¬ gc_fM s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› 4. ‹⋀s s'. ⟦at (mutator m) hs_noop_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_noop_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. ¬ sys_ghost_hs_in_sync x s↓) ⟶ sys_fA s↓ = (¬ gc_fM s↓))⟧ ⟹ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = gc_fM s↓) ∨ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ sys_fA s↓)] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = (¬ gc_fM s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› 5. ‹⋀s s'. ⟦at (mutator m) hs_noop_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_noop_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []⟧ ⟹ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = gc_fM s↓) ∨ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ sys_fA s↓)] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = (¬ gc_fM s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› 6. ‹⋀s s'. ⟦at (mutator m) hs_noop_done s; at sys sys.sys_hs_mut_done s; s'↓ = s↓(mutator m := s↓ (mutator m)⦇ghost_hs_phase := hs_step (mut_ghost_hs_phase s↓)⦈, sys := s↓ sys⦇hs_pending := (local_state.hs_pending (s↓ sys))(m := False), ghost_hs_in_sync := (ghost_hs_in_sync (s↓ sys))(m := True)⦈); taken (mutator m) hs_noop_done s'; ∀p''∈- {mutator m, sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []⟧ ⟹ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = gc_fM s↓) ∨ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ sys_fA s↓)] ∧ All ((ghost_hs_in_sync (s↓ sys))(m := True)) ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. x ≠ m ∧ (x ≠ m ⟶ ¬ sys_ghost_hs_in_sync x s↓)) ⟶ sys_fA s↓ = (¬ gc_fM s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› discuss goal 1*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 3*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 4*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 5*) apply ((auto split: if_splits (*‹(?P::?'a::type ⇒ bool) (if ?Q::bool then ?x::?'a::type else (?y::?'a::type)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹(?P::?'a::type ⇒ bool) (if ?Q::bool then ?x::?'a::type else (?y::?'a::type)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 6*) apply ((auto split: if_splits (*‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 6 subgoals*) (*proven 3 subgoals*) . end context gc begin lemma fA_neq_locs_diff_fA_tso_empty_locs: "fA_neq_locs - fA_tso_empty_locs = {}" apply (simp add: fA_neq_locs_def (*‹fA_neq_locs = {idle_phase_init, idle_store_fM, mark_load_fM, mark_store_fA} ∪ prefixed ''idle_flip_noop'' ∪ init_locs›*) fA_tso_empty_locs_def (*‹fA_tso_empty_locs = - {mark_noop_mfence}›*) locset_cache (*‹sweep_idle ∉ tso_lock_locs› ‹sweep_loop_ref_done ∉ tso_lock_locs› ‹sweep_loop_free ∉ tso_lock_locs› ‹sweep_loop_check ∉ tso_lock_locs› ‹sweep_loop_load_mark ∉ tso_lock_locs› ‹sweep_loop_choose_ref ∉ tso_lock_locs› ‹sweep_loop ∉ tso_lock_locs› ‹sweep_refs ∉ tso_lock_locs› ‹sweep_load_fM ∉ tso_lock_locs› ‹mark_end ∉ tso_lock_locs› ‹mark_loop_get_work_load_W ∉ tso_lock_locs› ‹mark_loop_get_work_done_loop_rendezvous ∉ tso_lock_locs› and more 5438 facts*)) (*goal: ‹fA_neq_locs - fA_tso_empty_locs = {}›*) by (simp add: loc_defs (*‹sweep_idle ≡ ''sweep_idle''› ‹sweep_loop_ref_done ≡ ''sweep_loop_ref_done''› ‹sweep_loop_free ≡ ''sweep_loop_free''› ‹sweep_loop_check ≡ ''sweep_loop_check''› ‹sweep_loop_load_mark ≡ ''sweep_loop_load_mark''› ‹sweep_loop_choose_ref ≡ ''sweep_loop_choose_ref''› ‹sweep_loop ≡ ''sweep_loop''› ‹sweep_refs ≡ ''sweep_refs''› ‹sweep_load_fM ≡ ''sweep_load_fM''› ‹mark_end ≡ ''mark_end''› ‹mark_loop_get_work_load_W ≡ ''mark_loop_get_work_load_W''› ‹mark_loop_get_work_done_loop_rendezvous ≡ ''mark_loop_get_work_done_loop_rendezvous''› and more 93 facts*)) end context sys begin lemma gc_fM_fA_invL[intro]: "⦃ gc.fM_fA_invL ❙∧ LSTP (fA_rel_inv ❙∧ fM_rel_inv ❙∧ tso_store_inv) ⦄ sys ⦃ gc.fM_fA_invL ⦄" apply (vcg_chainsaw (no_thin) gc.fM_fA_invL_def; (simp add: p_not_sys (*‹((?p::?'a::type process_name) ≠ sys) = (?p = gc ∨ (∃m::?'a::type. ?p = mutator m))›*))?; (erule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*))?; clarsimp split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) (*goal: ‹⦃λs. gc.fM_fA_invL s ∧ fA_rel_inv s↓ ∧ fM_rel_inv s↓ ∧ tso_store_inv s↓⦄ sys ⦃gc.fM_fA_invL⦄›*) proof (vcg_name_cases sys gc) (*goals: 1. ‹⋀s s' ws. ⟦at sys tso_dequeue_store_buffer s; AT s' = (AT s)(sys := {sys_hs_mut_done, sys_hs_mut, sys_hs_mut_pending, sys_hs_gc_load_W, sys_hs_gc_done, sys_hs_gc_mut_reqs, sys_hs_gc_set_type, sys_free, Proofs_Basis.sys.alloc, tso_dequeue_store_buffer, tso_unlock, tso_lock, tso_mfence, tso_store, tso_load}); s'↓ = s↓(sys := s↓ sys⦇fM := ¬ sys_fM s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''∈- {sys}. GST s' p'' = GST s p''; fA_rel_inv s↓; sys_mem_store_buffers gc s↓ = mw_fM (¬ sys_fM s↓) # ws; fM_rel_inv s↓; tso_store_inv s↓; not_blocked (s↓ sys) gc; ¬ atS gc gc.fM_tso_empty_locs s; atS gc gc.fA_eq_locs s ⟶ sys_fM s↓ = sys_fA s↓; atS gc gc.fA_neq_locs s ⟶ sys_fM s↓ = (¬ sys_fA s↓); at gc gc.mark_noop_mfence s ⟶ sys_fM s↓ = (¬ sys_fA s↓) ⟶ filter is_mw_fA ws ≠ []; atS gc gc.fA_tso_empty_locs s ⟶ filter is_mw_fA ws = []; atS gc gc.fM_eq_locs s; gc_fM s↓ = sys_fM s↓⟧ ⟹ False› 2. ‹⋀s s' ws. ⟦gc_fM s↓ = (¬ sys_fA s↓); filter is_mw_fA ws = []; sys_fM s↓ = sys_fA s↓ ∨ sys_fA s↓ = (¬ sys_fM s↓); filter is_mw_fM ws = []; at sys tso_dequeue_store_buffer s; AT s' = (AT s)(sys := {sys_hs_mut_done, sys_hs_mut, sys_hs_mut_pending, sys_hs_gc_load_W, sys_hs_gc_done, sys_hs_gc_mut_reqs, sys_hs_gc_set_type, sys_free, Proofs_Basis.sys.alloc, tso_dequeue_store_buffer, tso_unlock, tso_lock, tso_mfence, tso_store, tso_load}); s'↓ = s↓(sys := s↓ sys⦇fM := sys_fA s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''∈- {sys}. GST s' p'' = GST s p''; fA_rel_inv s↓; sys_mem_store_buffers gc s↓ = mw_fM (sys_fA s↓) # ws; fM_rel_inv s↓; tso_store_inv s↓; not_blocked (s↓ sys) gc; at gc gc.idle_store_fM s ⟶ sys_fA s↓ = sys_fM s↓; gc.mark_noop_mfence ∉ AT s gc; at gc gc.idle_flip_noop_mfence s⟧ ⟹ False› 3. ‹⋀s s' ws. ⟦at sys tso_dequeue_store_buffer s; AT s' = (AT s)(sys := {sys_hs_mut_done, sys_hs_mut, sys_hs_mut_pending, sys_hs_gc_load_W, sys_hs_gc_done, sys_hs_gc_mut_reqs, sys_hs_gc_set_type, sys_free, Proofs_Basis.sys.alloc, tso_dequeue_store_buffer, tso_unlock, tso_lock, tso_mfence, tso_store, tso_load}); s'↓ = s↓(sys := s↓ sys⦇fA := ¬ sys_fA s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''∈- {sys}. GST s' p'' = GST s p''; fA_rel_inv s↓; sys_mem_store_buffers gc s↓ = mw_fA (¬ sys_fA s↓) # ws; fM_rel_inv s↓; tso_store_inv s↓; not_blocked (s↓ sys) gc; atS gc gc.fM_eq_locs s ⟶ sys_fA s↓ = sys_fM s↓; atS gc gc.fM_tso_empty_locs s ⟶ filter is_mw_fM ws = []; ¬ atS gc gc.fA_neq_locs s; ¬ atS gc gc.fA_tso_empty_locs s; atS gc gc.fA_eq_locs s; gc_fM s↓ = sys_fA s↓⟧ ⟹ False› 4. ‹⋀s s' ws. ⟦at sys tso_dequeue_store_buffer s; AT s' = (AT s)(sys := {sys_hs_mut_done, sys_hs_mut, sys_hs_mut_pending, sys_hs_gc_load_W, sys_hs_gc_done, sys_hs_gc_mut_reqs, sys_hs_gc_set_type, sys_free, Proofs_Basis.sys.alloc, tso_dequeue_store_buffer, tso_unlock, tso_lock, tso_mfence, tso_store, tso_load}); s'↓ = s↓(sys := s↓ sys⦇fA := ¬ sys_fA s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''∈- {sys}. GST s' p'' = GST s p''; fA_rel_inv s↓; sys_mem_store_buffers gc s↓ = mw_fA (¬ sys_fA s↓) # ws; fM_rel_inv s↓; tso_store_inv s↓; not_blocked (s↓ sys) gc; atS gc gc.fM_eq_locs s ⟶ (¬ sys_fA s↓) = sys_fM s↓; at gc gc.idle_store_fM s ⟶ sys_fA s↓ = sys_fM s↓; at gc gc.idle_flip_noop_mfence s ⟶ sys_fM s↓ = sys_fA s↓ ⟶ filter is_mw_fM ws ≠ []; atS gc gc.fM_tso_empty_locs s ⟶ filter is_mw_fM ws = []; ¬ atS gc gc.fA_eq_locs s; ¬ atS gc gc.fA_tso_empty_locs s; atS gc gc.fA_neq_locs s; gc_fM s↓ = (¬ sys_fA s↓)⟧ ⟹ False› 5. ‹⋀s s' ws. ⟦gc_fM s↓ = sys_fM s↓; filter is_mw_fM ws = []; sys_fM s↓ = (¬ sys_fA s↓) ∨ sys_fM s↓ = sys_fA s↓; filter is_mw_fA ws = []; at sys tso_dequeue_store_buffer s; AT s' = (AT s)(sys := {sys_hs_mut_done, sys_hs_mut, sys_hs_mut_pending, sys_hs_gc_load_W, sys_hs_gc_done, sys_hs_gc_mut_reqs, sys_hs_gc_set_type, sys_free, Proofs_Basis.sys.alloc, tso_dequeue_store_buffer, tso_unlock, tso_lock, tso_mfence, tso_store, tso_load}); s'↓ = s↓(sys := s↓ sys⦇fA := ¬ sys_fM s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''∈- {sys}. GST s' p'' = GST s p''; fA_rel_inv s↓; sys_mem_store_buffers gc s↓ = mw_fA (¬ sys_fM s↓) # ws; fM_rel_inv s↓; tso_store_inv s↓; not_blocked (s↓ sys) gc; gc.idle_store_fM ∉ AT s gc; at gc gc.mark_noop_mfence s⟧ ⟹ False›*) case (tso_dequeue_store_buffer_mark_noop_mfence s s' ws) (*‹gc_fM s↓ = sys_fM s↓› ‹filter is_mw_fM ws = []› ‹sys_fM s↓ = (¬ sys_fA s↓) ∨ sys_fM s↓ = sys_fA s↓› ‹filter is_mw_fA (ws::('a, 'b, 'c) mem_store_action list) = []› ‹at sys tso_dequeue_store_buffer s› ‹AT s' = (AT s)(sys := {sys_hs_mut_done, sys_hs_mut, sys_hs_mut_pending, sys_hs_gc_load_W, sys_hs_gc_done, sys_hs_gc_mut_reqs, sys_hs_gc_set_type, sys_free, Proofs_Basis.sys.alloc, tso_dequeue_store_buffer, tso_unlock, tso_lock, tso_mfence, tso_store, tso_load})› ‹s'↓ = s↓(sys := s↓ sys⦇fA := ¬ sys_fM s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈)› ‹taken sys tso_dequeue_store_buffer s'› ‹∀p''∈- {sys}. GST s' p'' = GST s p''› ‹fA_rel_inv s↓› ‹sys_mem_store_buffers gc s↓ = mw_fA (¬ sys_fM s↓) # ws› ‹fM_rel_inv (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓› ‹tso_store_inv s↓› ‹not_blocked (s↓ sys) gc› ‹gc.idle_store_fM ∉ AT (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state) gc› ‹at gc gc.mark_noop_mfence s›*) then show "?case" (*goal: ‹False›*) by (clarsimp simp: fA_rel_inv_def (*‹fA_rel_inv = (λs. (∀x. sys_ghost_hs_in_sync x s, sys_ghost_hs_phase s, sys_fA s, gc_fM s, filter is_mw_fA (sys_mem_store_buffers gc s)) ∈ fA_rel)›*) fA_rel_def (*‹fA_rel = {(in_sync, hp_Idle, fA, fM, []) |fA fM in_sync. ¬ in_sync ⟶ fA = fM} ∪ {(in_sync, hp_IdleInit, fA, ¬ fA, []) |fA in_sync. True} ∪ {(in_sync, hp_InitMark, fA, ¬ fA, [mw_fA (¬ fA)]) |fA in_sync. in_sync} ∪ {(in_sync, hp_InitMark, fA, fM, []) |fA fM in_sync. ¬ in_sync ⟶ fA ≠ fM} ∪ {(in_sync, hp_Mark, fA, fA, []) |fA in_sync. True} ∪ {(in_sync, hp_IdleMarkSweep, fA, fA, []) |fA in_sync. True}›*)) next (*goals: 1. ‹⋀s s' ws. ⟦at sys tso_dequeue_store_buffer s; AT s' = (AT s)(sys := {sys_hs_mut_done, sys_hs_mut, sys_hs_mut_pending, sys_hs_gc_load_W, sys_hs_gc_done, sys_hs_gc_mut_reqs, sys_hs_gc_set_type, sys_free, Proofs_Basis.sys.alloc, tso_dequeue_store_buffer, tso_unlock, tso_lock, tso_mfence, tso_store, tso_load}); s'↓ = s↓(sys := s↓ sys⦇fM := ¬ sys_fM s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''∈- {sys}. GST s' p'' = GST s p''; fA_rel_inv s↓; sys_mem_store_buffers gc s↓ = mw_fM (¬ sys_fM s↓) # ws; fM_rel_inv s↓; tso_store_inv s↓; not_blocked (s↓ sys) gc; ¬ atS gc gc.fM_tso_empty_locs s; atS gc gc.fA_eq_locs s ⟶ sys_fM s↓ = sys_fA s↓; atS gc gc.fA_neq_locs s ⟶ sys_fM s↓ = (¬ sys_fA s↓); at gc gc.mark_noop_mfence s ⟶ sys_fM s↓ = (¬ sys_fA s↓) ⟶ filter is_mw_fA ws ≠ []; atS gc gc.fA_tso_empty_locs s ⟶ filter is_mw_fA ws = []; atS gc gc.fM_eq_locs s; gc_fM s↓ = sys_fM s↓⟧ ⟹ False› 2. ‹⋀s s' ws. ⟦gc_fM s↓ = (¬ sys_fA s↓); filter is_mw_fA ws = []; sys_fM s↓ = sys_fA s↓ ∨ sys_fA s↓ = (¬ sys_fM s↓); filter is_mw_fM ws = []; at sys tso_dequeue_store_buffer s; AT s' = (AT s)(sys := {sys_hs_mut_done, sys_hs_mut, sys_hs_mut_pending, sys_hs_gc_load_W, sys_hs_gc_done, sys_hs_gc_mut_reqs, sys_hs_gc_set_type, sys_free, Proofs_Basis.sys.alloc, tso_dequeue_store_buffer, tso_unlock, tso_lock, tso_mfence, tso_store, tso_load}); s'↓ = s↓(sys := s↓ sys⦇fM := sys_fA s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''∈- {sys}. GST s' p'' = GST s p''; fA_rel_inv s↓; sys_mem_store_buffers gc s↓ = mw_fM (sys_fA s↓) # ws; fM_rel_inv s↓; tso_store_inv s↓; not_blocked (s↓ sys) gc; at gc gc.idle_store_fM s ⟶ sys_fA s↓ = sys_fM s↓; gc.mark_noop_mfence ∉ AT s gc; at gc gc.idle_flip_noop_mfence s⟧ ⟹ False› 3. ‹⋀s s' ws. ⟦at sys tso_dequeue_store_buffer s; AT s' = (AT s)(sys := {sys_hs_mut_done, sys_hs_mut, sys_hs_mut_pending, sys_hs_gc_load_W, sys_hs_gc_done, sys_hs_gc_mut_reqs, sys_hs_gc_set_type, sys_free, Proofs_Basis.sys.alloc, tso_dequeue_store_buffer, tso_unlock, tso_lock, tso_mfence, tso_store, tso_load}); s'↓ = s↓(sys := s↓ sys⦇fA := ¬ sys_fA s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''∈- {sys}. GST s' p'' = GST s p''; fA_rel_inv s↓; sys_mem_store_buffers gc s↓ = mw_fA (¬ sys_fA s↓) # ws; fM_rel_inv s↓; tso_store_inv s↓; not_blocked (s↓ sys) gc; atS gc gc.fM_eq_locs s ⟶ sys_fA s↓ = sys_fM s↓; atS gc gc.fM_tso_empty_locs s ⟶ filter is_mw_fM ws = []; ¬ atS gc gc.fA_neq_locs s; ¬ atS gc gc.fA_tso_empty_locs s; atS gc gc.fA_eq_locs s; gc_fM s↓ = sys_fA s↓⟧ ⟹ False› 4. ‹⋀s s' ws. ⟦at sys tso_dequeue_store_buffer s; AT s' = (AT s)(sys := {sys_hs_mut_done, sys_hs_mut, sys_hs_mut_pending, sys_hs_gc_load_W, sys_hs_gc_done, sys_hs_gc_mut_reqs, sys_hs_gc_set_type, sys_free, Proofs_Basis.sys.alloc, tso_dequeue_store_buffer, tso_unlock, tso_lock, tso_mfence, tso_store, tso_load}); s'↓ = s↓(sys := s↓ sys⦇fA := ¬ sys_fA s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''∈- {sys}. GST s' p'' = GST s p''; fA_rel_inv s↓; sys_mem_store_buffers gc s↓ = mw_fA (¬ sys_fA s↓) # ws; fM_rel_inv s↓; tso_store_inv s↓; not_blocked (s↓ sys) gc; atS gc gc.fM_eq_locs s ⟶ (¬ sys_fA s↓) = sys_fM s↓; at gc gc.idle_store_fM s ⟶ sys_fA s↓ = sys_fM s↓; at gc gc.idle_flip_noop_mfence s ⟶ sys_fM s↓ = sys_fA s↓ ⟶ filter is_mw_fM ws ≠ []; atS gc gc.fM_tso_empty_locs s ⟶ filter is_mw_fM ws = []; ¬ atS gc gc.fA_eq_locs s; ¬ atS gc gc.fA_tso_empty_locs s; atS gc gc.fA_neq_locs s; gc_fM s↓ = (¬ sys_fA s↓)⟧ ⟹ False›*) case (tso_dequeue_store_buffer_fA_neq_locs s s' ws) (*‹at sys tso_dequeue_store_buffer s› ‹AT s' = (AT s)(sys := {sys_hs_mut_done, sys_hs_mut, sys_hs_mut_pending, sys_hs_gc_load_W, sys_hs_gc_done, sys_hs_gc_mut_reqs, sys_hs_gc_set_type, sys_free, Proofs_Basis.sys.alloc, tso_dequeue_store_buffer, tso_unlock, tso_lock, tso_mfence, tso_store, tso_load})› ‹s'↓ = s↓(sys := s↓ sys⦇fA := ¬ sys_fA s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈)› ‹taken sys tso_dequeue_store_buffer s'› ‹∀p''∈- {sys}. GST s' p'' = GST s p''› ‹fA_rel_inv (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓› ‹sys_mem_store_buffers gc s↓ = mw_fA (¬ sys_fA s↓) # ws› ‹fM_rel_inv (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓› ‹tso_store_inv s↓› ‹not_blocked (s↓ sys) gc› ‹atS gc gc.fM_eq_locs s ⟶ (¬ sys_fA s↓) = sys_fM s↓› ‹at gc gc.idle_store_fM s ⟶ sys_fA s↓ = sys_fM s↓› ‹at gc gc.idle_flip_noop_mfence s ⟶ sys_fM s↓ = sys_fA s↓ ⟶ filter is_mw_fM ws ≠ []› ‹atS gc gc.fM_tso_empty_locs s ⟶ filter is_mw_fM ws = []› ‹¬ atS gc gc.fA_eq_locs s› ‹¬ atS gc gc.fA_tso_empty_locs s› ‹atS gc gc.fA_neq_locs s› ‹gc_fM s↓ = (¬ sys_fA s↓)›*) then show "?case" (*goal: ‹False›*) apply (clarsimp simp: fA_rel_inv_def (*‹fA_rel_inv = (λs. (∀x. sys_ghost_hs_in_sync x s, sys_ghost_hs_phase s, sys_fA s, gc_fM s, filter is_mw_fA (sys_mem_store_buffers gc s)) ∈ fA_rel)›*) fA_rel_def (*‹fA_rel = {(in_sync, hp_Idle, fA, fM, []) |fA fM in_sync. ¬ in_sync ⟶ fA = fM} ∪ {(in_sync, hp_IdleInit, fA, ¬ fA, []) |fA in_sync. True} ∪ {(in_sync, hp_InitMark, fA, ¬ fA, [mw_fA (¬ fA)]) |fA in_sync. in_sync} ∪ {(in_sync, hp_InitMark, fA, fM, []) |fA fM in_sync. ¬ in_sync ⟶ fA ≠ fM} ∪ {(in_sync, hp_Mark, fA, fA, []) |fA in_sync. True} ∪ {(in_sync, hp_IdleMarkSweep, fA, fA, []) |fA in_sync. True}›*) fM_rel_inv_def (*‹fM_rel_inv = (λs. (∀x. sys_ghost_hs_in_sync x s, sys_ghost_hs_phase s, gc_fM s, sys_fM s, filter is_mw_fM (sys_mem_store_buffers gc s), sys_mem_lock s = Some gc) ∈ fM_rel)›*) fM_rel_def (*‹fM_rel = {(in_sync, hp, fM, fM, [], l) |fM hp in_sync l. hp = hp_Idle ⟶ ¬ in_sync} ∪ {(in_sync, hp_Idle, fM, fM', [], l) |fM fM' in_sync l. in_sync} ∪ {(in_sync, hp_Idle, ¬ fM, fM, [mw_fM (¬ fM)], False) |fM in_sync. in_sync}›*)) (*goal: ‹False›*) by (drule (1) atS_dests( (*‹⟦¬ atS ?p ?ls ?s; atS ?p ?ls' ?s⟧ ⟹ atS ?p (?ls' - ?ls) ?s›*) 3), fastforce simp: atS_simps (*‹¬ atS ?p {} ?s› ‹atS ?p {?l} ?s = at ?p ?l ?s› ‹⟦at ?p ?l ?s; ?l ∈ ?ls⟧ ⟹ atS ?p ?ls ?s› ‹∀l. at ?p l ?s ⟶ l ∉ ?ls ⟹ ¬ atS ?p ?ls ?s›*) gc.fA_neq_locs_diff_fA_tso_empty_locs (*‹gc.fA_neq_locs - gc.fA_tso_empty_locs = {}›*)) next (*goals: 1. ‹⋀s s' ws. ⟦at sys tso_dequeue_store_buffer s; AT s' = (AT s)(sys := {sys_hs_mut_done, sys_hs_mut, sys_hs_mut_pending, sys_hs_gc_load_W, sys_hs_gc_done, sys_hs_gc_mut_reqs, sys_hs_gc_set_type, sys_free, Proofs_Basis.sys.alloc, tso_dequeue_store_buffer, tso_unlock, tso_lock, tso_mfence, tso_store, tso_load}); s'↓ = s↓(sys := s↓ sys⦇fM := ¬ sys_fM s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''∈- {sys}. GST s' p'' = GST s p''; fA_rel_inv s↓; sys_mem_store_buffers gc s↓ = mw_fM (¬ sys_fM s↓) # ws; fM_rel_inv s↓; tso_store_inv s↓; not_blocked (s↓ sys) gc; ¬ atS gc gc.fM_tso_empty_locs s; atS gc gc.fA_eq_locs s ⟶ sys_fM s↓ = sys_fA s↓; atS gc gc.fA_neq_locs s ⟶ sys_fM s↓ = (¬ sys_fA s↓); at gc gc.mark_noop_mfence s ⟶ sys_fM s↓ = (¬ sys_fA s↓) ⟶ filter is_mw_fA ws ≠ []; atS gc gc.fA_tso_empty_locs s ⟶ filter is_mw_fA ws = []; atS gc gc.fM_eq_locs s; gc_fM s↓ = sys_fM s↓⟧ ⟹ False› 2. ‹⋀s s' ws. ⟦gc_fM s↓ = (¬ sys_fA s↓); filter is_mw_fA ws = []; sys_fM s↓ = sys_fA s↓ ∨ sys_fA s↓ = (¬ sys_fM s↓); filter is_mw_fM ws = []; at sys tso_dequeue_store_buffer s; AT s' = (AT s)(sys := {sys_hs_mut_done, sys_hs_mut, sys_hs_mut_pending, sys_hs_gc_load_W, sys_hs_gc_done, sys_hs_gc_mut_reqs, sys_hs_gc_set_type, sys_free, Proofs_Basis.sys.alloc, tso_dequeue_store_buffer, tso_unlock, tso_lock, tso_mfence, tso_store, tso_load}); s'↓ = s↓(sys := s↓ sys⦇fM := sys_fA s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''∈- {sys}. GST s' p'' = GST s p''; fA_rel_inv s↓; sys_mem_store_buffers gc s↓ = mw_fM (sys_fA s↓) # ws; fM_rel_inv s↓; tso_store_inv s↓; not_blocked (s↓ sys) gc; at gc gc.idle_store_fM s ⟶ sys_fA s↓ = sys_fM s↓; gc.mark_noop_mfence ∉ AT s gc; at gc gc.idle_flip_noop_mfence s⟧ ⟹ False› 3. ‹⋀s s' ws. ⟦at sys tso_dequeue_store_buffer s; AT s' = (AT s)(sys := {sys_hs_mut_done, sys_hs_mut, sys_hs_mut_pending, sys_hs_gc_load_W, sys_hs_gc_done, sys_hs_gc_mut_reqs, sys_hs_gc_set_type, sys_free, Proofs_Basis.sys.alloc, tso_dequeue_store_buffer, tso_unlock, tso_lock, tso_mfence, tso_store, tso_load}); s'↓ = s↓(sys := s↓ sys⦇fA := ¬ sys_fA s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''∈- {sys}. GST s' p'' = GST s p''; fA_rel_inv s↓; sys_mem_store_buffers gc s↓ = mw_fA (¬ sys_fA s↓) # ws; fM_rel_inv s↓; tso_store_inv s↓; not_blocked (s↓ sys) gc; atS gc gc.fM_eq_locs s ⟶ sys_fA s↓ = sys_fM s↓; atS gc gc.fM_tso_empty_locs s ⟶ filter is_mw_fM ws = []; ¬ atS gc gc.fA_neq_locs s; ¬ atS gc gc.fA_tso_empty_locs s; atS gc gc.fA_eq_locs s; gc_fM s↓ = sys_fA s↓⟧ ⟹ False›*) case (tso_dequeue_store_buffer_fA_eq_locs s s' ws) (*‹at sys tso_dequeue_store_buffer s› ‹AT s' = (AT s)(sys := {sys_hs_mut_done, sys_hs_mut, sys_hs_mut_pending, sys_hs_gc_load_W, sys_hs_gc_done, sys_hs_gc_mut_reqs, sys_hs_gc_set_type, sys_free, Proofs_Basis.sys.alloc, tso_dequeue_store_buffer, tso_unlock, tso_lock, tso_mfence, tso_store, tso_load})› ‹s'↓ = s↓(sys := s↓ sys⦇fA := ¬ sys_fA s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈)› ‹taken sys tso_dequeue_store_buffer s'› ‹∀p''∈- {sys}. GST s' p'' = GST s p''› ‹fA_rel_inv (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓› ‹sys_mem_store_buffers gc s↓ = mw_fA (¬ sys_fA s↓) # ws› ‹fM_rel_inv s↓› ‹tso_store_inv s↓› ‹not_blocked ((s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ sys) gc› ‹atS gc gc.fM_eq_locs s ⟶ sys_fA s↓ = sys_fM s↓› ‹atS gc gc.fM_tso_empty_locs s ⟶ filter is_mw_fM ws = []› ‹¬ atS gc gc.fA_neq_locs s› ‹¬ atS gc gc.fA_tso_empty_locs (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)› ‹atS gc gc.fA_eq_locs s› ‹gc_fM (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = sys_fA s↓›*) then show "?case" (*goal: ‹False›*) by (clarsimp simp: fA_rel_inv_def (*‹fA_rel_inv = (λs::?'mut process_name ⇒ (?'field, ?'mut, ?'payload, ?'ref) Model.local_state. (∀x::?'mut. sys_ghost_hs_in_sync x s, sys_ghost_hs_phase s, sys_fA s, gc_fM s, filter is_mw_fA (sys_mem_store_buffers gc s)) ∈ fA_rel)›*) fA_rel_def (*‹fA_rel = {(in_sync, hp_Idle, fA, fM, []) |(fA::bool) (fM::bool) in_sync::bool. ¬ in_sync ⟶ fA = fM} ∪ {(in_sync, hp_IdleInit, fA, ¬ fA, []) |(fA::bool) in_sync::bool. True} ∪ {(in_sync, hp_InitMark, fA, ¬ fA, [mw_fA (¬ fA)]) |(fA::bool) in_sync::bool. in_sync} ∪ {(in_sync, hp_InitMark, fA, fM, []) |(fA::bool) (fM::bool) in_sync::bool. ¬ in_sync ⟶ fA ≠ fM} ∪ {(in_sync, hp_Mark, fA, fA, []) |(fA::bool) in_sync::bool. True} ∪ {(in_sync, hp_IdleMarkSweep, fA, fA, []) |(fA::bool) in_sync::bool. True}›*)) next (*goals: 1. ‹⋀(s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state) (s'::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state) ws::('a, 'b, 'c) mem_store_action list. ⟦at sys tso_dequeue_store_buffer s; AT s' = (AT s)(sys := {sys_hs_mut_done, sys_hs_mut, sys_hs_mut_pending, sys_hs_gc_load_W, sys_hs_gc_done, sys_hs_gc_mut_reqs, sys_hs_gc_set_type, sys_free, Proofs_Basis.sys.alloc, tso_dequeue_store_buffer, tso_unlock, tso_lock, tso_mfence, tso_store, tso_load}); s'↓ = s↓(sys := s↓ sys⦇fM := ¬ sys_fM s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''::'d process_name∈- {sys}. GST s' p'' = GST s p''; fA_rel_inv s↓; sys_mem_store_buffers gc s↓ = mw_fM (¬ sys_fM s↓) # ws; fM_rel_inv s↓; tso_store_inv s↓; not_blocked (s↓ sys) gc; ¬ atS gc gc.fM_tso_empty_locs s; atS gc gc.fA_eq_locs s ⟶ sys_fM s↓ = sys_fA s↓; atS gc gc.fA_neq_locs s ⟶ sys_fM s↓ = (¬ sys_fA s↓); at gc gc.mark_noop_mfence s ⟶ sys_fM s↓ = (¬ sys_fA s↓) ⟶ filter is_mw_fA ws ≠ []; atS gc gc.fA_tso_empty_locs s ⟶ filter is_mw_fA ws = []; atS gc gc.fM_eq_locs s; gc_fM s↓ = sys_fM s↓⟧ ⟹ False› 2. ‹⋀(s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state) (s'::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state) ws::('a, 'b, 'c) mem_store_action list. ⟦gc_fM s↓ = (¬ sys_fA s↓); filter is_mw_fA ws = []; sys_fM s↓ = sys_fA s↓ ∨ sys_fA s↓ = (¬ sys_fM s↓); filter is_mw_fM ws = []; at sys tso_dequeue_store_buffer s; AT s' = (AT s)(sys := {sys_hs_mut_done, sys_hs_mut, sys_hs_mut_pending, sys_hs_gc_load_W, sys_hs_gc_done, sys_hs_gc_mut_reqs, sys_hs_gc_set_type, sys_free, Proofs_Basis.sys.alloc, tso_dequeue_store_buffer, tso_unlock, tso_lock, tso_mfence, tso_store, tso_load}); s'↓ = s↓(sys := s↓ sys⦇fM := sys_fA s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''::'d process_name∈- {sys}. GST s' p'' = GST s p''; fA_rel_inv s↓; sys_mem_store_buffers gc s↓ = mw_fM (sys_fA s↓) # ws; fM_rel_inv s↓; tso_store_inv s↓; not_blocked (s↓ sys) gc; at gc gc.idle_store_fM s ⟶ sys_fA s↓ = sys_fM s↓; gc.mark_noop_mfence ∉ AT s gc; at gc gc.idle_flip_noop_mfence s⟧ ⟹ False›*) case (tso_dequeue_store_buffer_idle_flip_noop_mfence s s' ws) (*‹gc_fM s↓ = (¬ sys_fA s↓)› ‹filter is_mw_fA ws = []› ‹sys_fM s↓ = sys_fA s↓ ∨ sys_fA s↓ = (¬ sys_fM s↓)› ‹filter is_mw_fM (ws::('a, 'b, 'c) mem_store_action list) = []› ‹at sys tso_dequeue_store_buffer (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)› ‹AT s' = (AT s)(sys := {sys_hs_mut_done, sys_hs_mut, sys_hs_mut_pending, sys_hs_gc_load_W, sys_hs_gc_done, sys_hs_gc_mut_reqs, sys_hs_gc_set_type, sys_free, Proofs_Basis.sys.alloc, tso_dequeue_store_buffer, tso_unlock, tso_lock, tso_mfence, tso_store, tso_load})› ‹s'↓ = s↓(sys := s↓ sys⦇fM := sys_fA s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈)› ‹taken sys tso_dequeue_store_buffer s'› ‹∀p''::'d process_name∈- {sys}. GST (s'::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state) p'' = GST (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state) p''› ‹fA_rel_inv s↓› ‹sys_mem_store_buffers gc s↓ = mw_fM (sys_fA s↓) # ws› ‹fM_rel_inv s↓› ‹tso_store_inv s↓› ‹not_blocked ((s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ sys) gc› ‹at gc gc.idle_store_fM s ⟶ sys_fA s↓ = sys_fM s↓› ‹gc.mark_noop_mfence ∉ AT s gc› ‹at gc gc.idle_flip_noop_mfence s›*) then show "?case" (*goal: ‹False›*) by (clarsimp simp: fM_rel_inv_def (*‹fM_rel_inv = (λs. (∀x. sys_ghost_hs_in_sync x s, sys_ghost_hs_phase s, gc_fM s, sys_fM s, filter is_mw_fM (sys_mem_store_buffers gc s), sys_mem_lock s = Some gc) ∈ fM_rel)›*) fM_rel_def (*‹fM_rel = {(in_sync, hp, fM, fM, [], l) |fM hp in_sync l. hp = hp_Idle ⟶ ¬ in_sync} ∪ {(in_sync, hp_Idle, fM, fM', [], l) |fM fM' in_sync l. in_sync} ∪ {(in_sync, hp_Idle, ¬ fM, fM, [mw_fM (¬ fM)], False) |fM in_sync. in_sync}›*)) next (*goal: ‹⋀s s' ws. ⟦at sys tso_dequeue_store_buffer s; AT s' = (AT s)(sys := {sys_hs_mut_done, sys_hs_mut, sys_hs_mut_pending, sys_hs_gc_load_W, sys_hs_gc_done, sys_hs_gc_mut_reqs, sys_hs_gc_set_type, sys_free, Proofs_Basis.sys.alloc, tso_dequeue_store_buffer, tso_unlock, tso_lock, tso_mfence, tso_store, tso_load}); s'↓ = s↓(sys := s↓ sys⦇fM := ¬ sys_fM s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''∈- {sys}. GST s' p'' = GST s p''; fA_rel_inv s↓; sys_mem_store_buffers gc s↓ = mw_fM (¬ sys_fM s↓) # ws; fM_rel_inv s↓; tso_store_inv s↓; not_blocked (s↓ sys) gc; ¬ atS gc gc.fM_tso_empty_locs s; atS gc gc.fA_eq_locs s ⟶ sys_fM s↓ = sys_fA s↓; atS gc gc.fA_neq_locs s ⟶ sys_fM s↓ = (¬ sys_fA s↓); at gc gc.mark_noop_mfence s ⟶ sys_fM s↓ = (¬ sys_fA s↓) ⟶ filter is_mw_fA ws ≠ []; atS gc gc.fA_tso_empty_locs s ⟶ filter is_mw_fA ws = []; atS gc gc.fM_eq_locs s; gc_fM s↓ = sys_fM s↓⟧ ⟹ False›*) case (tso_dequeue_store_buffer_fM_eq_locs s s' ws) (*‹at sys tso_dequeue_store_buffer s› ‹AT (s'::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state) = (AT (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state))(sys := {sys_hs_mut_done, sys_hs_mut, sys_hs_mut_pending, sys_hs_gc_load_W, sys_hs_gc_done, sys_hs_gc_mut_reqs, sys_hs_gc_set_type, sys_free, Proofs_Basis.sys.alloc, tso_dequeue_store_buffer, tso_unlock, tso_lock, tso_mfence, tso_store, tso_load})› ‹s'↓ = s↓(sys := s↓ sys⦇fM := ¬ sys_fM s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈)› ‹taken sys tso_dequeue_store_buffer s'› ‹∀p''∈- {sys}. GST s' p'' = GST s p''› ‹fA_rel_inv s↓› ‹sys_mem_store_buffers gc (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = mw_fM (¬ sys_fM s↓) # (ws::('a::type, 'b::type, 'c::type) mem_store_action list)› ‹fM_rel_inv s↓› ‹tso_store_inv s↓› ‹not_blocked (s↓ sys) gc› ‹¬ atS gc gc.fM_tso_empty_locs s› ‹atS gc gc.fA_eq_locs s ⟶ sys_fM s↓ = sys_fA s↓› ‹atS gc gc.fA_neq_locs s ⟶ sys_fM s↓ = (¬ sys_fA s↓)› ‹at gc gc.mark_noop_mfence (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state) ⟶ sys_fM s↓ = (¬ sys_fA s↓) ⟶ filter is_mw_fA (ws::('a::type, 'b::type, 'c::type) mem_store_action list) ≠ []› ‹atS gc gc.fA_tso_empty_locs s ⟶ filter is_mw_fA ws = []› ‹atS gc gc.fM_eq_locs s› ‹gc_fM s↓ = sys_fM s↓›*) then show "?case" (*goal: ‹False›*) by (clarsimp simp: fM_rel_inv_def (*‹fM_rel_inv = (λs. (∀x. sys_ghost_hs_in_sync x s, sys_ghost_hs_phase s, gc_fM s, sys_fM s, filter is_mw_fM (sys_mem_store_buffers gc s), sys_mem_lock s = Some gc) ∈ fM_rel)›*) fM_rel_def (*‹fM_rel = {(in_sync, hp, fM, fM, [], l) |fM hp in_sync l. hp = hp_Idle ⟶ ¬ in_sync} ∪ {(in_sync, hp_Idle, fM, fM', [], l) |fM fM' in_sync l. in_sync} ∪ {(in_sync, hp_Idle, ¬ fM, fM, [mw_fM (¬ fM)], False) |fM in_sync. in_sync}›*)) qed lemma fM_rel_inv[intro]: notes fun_upd_apply[simp] shows "⦃ LSTP (fM_rel_inv ❙∧ tso_store_inv) ⦄ sys ⦃ LSTP fM_rel_inv ⦄" apply (vcg_jackhammer (no_thin_post_inv)) (*goal: ‹⦃λs::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state. fM_rel_inv s↓ ∧ tso_store_inv s↓⦄ sys ⦃λs::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state. fM_rel_inv s↓⦄›*) apply (clarsimp simp: do_store_action_def (*‹do_store_action ?wact = (λs. case ?wact of mw_Mark r gc_mark ⇒ s⦇heap := (heap s)(r := map_option (obj_mark_update (λ_. gc_mark)) (heap s r))⦈ | mw_Mutate r f new_r ⇒ s⦇heap := (heap s)(r := map_option (λobj. obj⦇obj_fields := (obj_fields obj)(f := new_r)⦈) (heap s r))⦈ | mw_Mutate_Payload r f pl ⇒ s⦇heap := (heap s)(r := map_option (λobj. obj⦇obj_payload := (obj_payload obj)(f := pl)⦈) (heap s r))⦈ | mw_fA gc_mark ⇒ s⦇fA := gc_mark⦈ | mw_fM gc_mark ⇒ s⦇fM := gc_mark⦈ | mw_Phase gc_phase ⇒ s⦇phase := gc_phase⦈)›*) fM_rel_inv_def (*‹fM_rel_inv = (λs. (∀x. sys_ghost_hs_in_sync x s, sys_ghost_hs_phase s, gc_fM s, sys_fM s, filter is_mw_fM (sys_mem_store_buffers gc s), sys_mem_lock s = Some gc) ∈ fM_rel)›*) fM_rel_def (*‹fM_rel = {(in_sync, hp, fM, fM, [], l) |fM hp in_sync l. hp = hp_Idle ⟶ ¬ in_sync} ∪ {(in_sync, hp_Idle, fM, fM', [], l) |fM fM' in_sync l. in_sync} ∪ {(in_sync, hp_Idle, ¬ fM, fM, [mw_fM (¬ fM)], False) |fM in_sync. in_sync}›*) p_not_sys (*‹(?p ≠ sys) = (?p = gc ∨ (∃m. ?p = mutator m))›*) split: mem_store_action.splits (*‹?P (case ?mem_store_action of mw_Mark x xa ⇒ ?f1.0 x xa | mw_Mutate x xa xb ⇒ ?f2.0 x xa xb | mw_Mutate_Payload x xa xb ⇒ ?f3.0 x xa xb | mw_fA x ⇒ ?f4.0 x | mw_fM x ⇒ ?f5.0 x | mw_Phase x ⇒ ?f6.0 x) = ((∀x11 x12. ?mem_store_action = mw_Mark x11 x12 ⟶ ?P (?f1.0 x11 x12)) ∧ (∀x21 x22 x23. ?mem_store_action = mw_Mutate x21 x22 x23 ⟶ ?P (?f2.0 x21 x22 x23)) ∧ (∀x31 x32 x33. ?mem_store_action = mw_Mutate_Payload x31 x32 x33 ⟶ ?P (?f3.0 x31 x32 x33)) ∧ (∀x4. ?mem_store_action = mw_fA x4 ⟶ ?P (?f4.0 x4)) ∧ (∀x5. ?mem_store_action = mw_fM x5 ⟶ ?P (?f5.0 x5)) ∧ (∀x6. ?mem_store_action = mw_Phase x6 ⟶ ?P (?f6.0 x6)))› ‹?P (case ?mem_store_action of mw_Mark x xa ⇒ ?f1.0 x xa | mw_Mutate x xa xb ⇒ ?f2.0 x xa xb | mw_Mutate_Payload x xa xb ⇒ ?f3.0 x xa xb | mw_fA x ⇒ ?f4.0 x | mw_fM x ⇒ ?f5.0 x | mw_Phase x ⇒ ?f6.0 x) = (¬ ((∃x11 x12. ?mem_store_action = mw_Mark x11 x12 ∧ ¬ ?P (?f1.0 x11 x12)) ∨ (∃x21 x22 x23. ?mem_store_action = mw_Mutate x21 x22 x23 ∧ ¬ ?P (?f2.0 x21 x22 x23)) ∨ (∃x31 x32 x33. ?mem_store_action = mw_Mutate_Payload x31 x32 x33 ∧ ¬ ?P (?f3.0 x31 x32 x33)) ∨ (∃x4. ?mem_store_action = mw_fA x4 ∧ ¬ ?P (?f4.0 x4)) ∨ (∃x5. ?mem_store_action = mw_fM x5 ∧ ¬ ?P (?f5.0 x5)) ∨ (∃x6. ?mem_store_action = mw_Phase x6 ∧ ¬ ?P (?f6.0 x6))))›*)) (*goal: ‹⋀s s' p w ws. ⟦at sys tso_dequeue_store_buffer s; s'↓ = s↓(sys := do_store_action w (s↓ sys)⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(p := ws)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''∈- {sys}. GST s' p'' = GST s p''; fM_rel_inv s↓; tso_store_inv s↓; sys_mem_store_buffers p s↓ = w # ws; not_blocked (s↓ sys) p; p ≠ sys⟧ ⟹ fM_rel_inv (s↓(sys := do_store_action w (s↓ sys)⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(p := ws)⦈))›*) apply (intro allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*) conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*) impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goals: 1. ‹⋀s s' p ws x5. ⟦taken sys tso_dequeue_store_buffer s'; ∀p''∈- {sys}. GST s' p'' = GST s p''; sys_fM s↓ = gc_fM s↓ ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ (sys_ghost_hs_phase s↓ = hp_Idle ⟶ (∃x. ¬ sys_ghost_hs_in_sync x s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ All (ghost_hs_in_sync (s↓ sys)) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ gc_fM s↓ = (¬ sys_fM s↓) ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [mw_fM (¬ sys_fM s↓)] ∧ sys_mem_lock s↓ ≠ Some gc ∧ All (ghost_hs_in_sync (s↓ sys)); tso_store_inv s↓; sys_mem_store_buffers p s↓ = mw_fM x5 # ws; not_blocked (s↓ sys) p; p = gc ∨ (∃m. p = mutator m); at sys tso_dequeue_store_buffer s; s'↓ = s↓(sys := s↓ sys⦇fM := x5, mem_store_buffers := (mem_store_buffers (s↓ sys))(p := ws)⦈); gc = p⟧ ⟹ x5 = gc_fM s↓ ∧ filter is_mw_fM ws = [] ∧ (sys_ghost_hs_phase s↓ = hp_Idle ⟶ (∃x. ¬ sys_ghost_hs_in_sync x s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fM ws = [] ∧ All (ghost_hs_in_sync (s↓ sys)) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ gc_fM s↓ = (¬ x5) ∧ filter is_mw_fM ws = [mw_fM (¬ x5)] ∧ sys_mem_lock s↓ ≠ Some gc ∧ All (ghost_hs_in_sync (s↓ sys))› 2. ‹⋀s s' p ws x5. ⟦taken sys tso_dequeue_store_buffer s'; ∀p''∈- {sys}. GST s' p'' = GST s p''; sys_fM s↓ = gc_fM s↓ ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ (sys_ghost_hs_phase s↓ = hp_Idle ⟶ (∃x. ¬ sys_ghost_hs_in_sync x s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ All (ghost_hs_in_sync (s↓ sys)) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ gc_fM s↓ = (¬ sys_fM s↓) ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [mw_fM (¬ sys_fM s↓)] ∧ sys_mem_lock s↓ ≠ Some gc ∧ All (ghost_hs_in_sync (s↓ sys)); tso_store_inv s↓; sys_mem_store_buffers p s↓ = mw_fM x5 # ws; not_blocked (s↓ sys) p; p = gc ∨ (∃m. p = mutator m); at sys tso_dequeue_store_buffer s; s'↓ = s↓(sys := s↓ sys⦇fM := x5, mem_store_buffers := (mem_store_buffers (s↓ sys))(p := ws)⦈); gc ≠ p⟧ ⟹ x5 = gc_fM s↓ ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ (sys_ghost_hs_phase s↓ = hp_Idle ⟶ (∃x. ¬ sys_ghost_hs_in_sync x s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [] ∧ All (ghost_hs_in_sync (s↓ sys)) ∨ sys_ghost_hs_phase s↓ = hp_Idle ∧ gc_fM s↓ = (¬ x5) ∧ filter is_mw_fM (sys_mem_store_buffers gc s↓) = [mw_fM (¬ x5)] ∧ sys_mem_lock s↓ ≠ Some gc ∧ All (ghost_hs_in_sync (s↓ sys))› discuss goal 1*) apply clarsimp (*discuss goal 2*) apply clarsimp (*proven 2 subgoals*) . lemma fA_rel_inv[intro]: notes fun_upd_apply[simp] shows "⦃ LSTP (fA_rel_inv ❙∧ tso_store_inv) ⦄ sys ⦃ LSTP fA_rel_inv ⦄" apply (vcg_jackhammer (no_thin_post_inv)) (*goal: ‹⦃λs::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state. fA_rel_inv s↓ ∧ tso_store_inv s↓⦄ sys ⦃λs::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state. fA_rel_inv s↓⦄›*) apply (clarsimp simp: do_store_action_def (*‹do_store_action ?wact = (λs. case ?wact of mw_Mark r gc_mark ⇒ s⦇heap := (heap s)(r := map_option (obj_mark_update (λ_. gc_mark)) (heap s r))⦈ | mw_Mutate r f new_r ⇒ s⦇heap := (heap s)(r := map_option (λobj. obj⦇obj_fields := (obj_fields obj)(f := new_r)⦈) (heap s r))⦈ | mw_Mutate_Payload r f pl ⇒ s⦇heap := (heap s)(r := map_option (λobj. obj⦇obj_payload := (obj_payload obj)(f := pl)⦈) (heap s r))⦈ | mw_fA gc_mark ⇒ s⦇fA := gc_mark⦈ | mw_fM gc_mark ⇒ s⦇fM := gc_mark⦈ | mw_Phase gc_phase ⇒ s⦇phase := gc_phase⦈)›*) fA_rel_inv_def (*‹fA_rel_inv = (λs. (∀x. sys_ghost_hs_in_sync x s, sys_ghost_hs_phase s, sys_fA s, gc_fM s, filter is_mw_fA (sys_mem_store_buffers gc s)) ∈ fA_rel)›*) fA_rel_def (*‹fA_rel = {(in_sync, hp_Idle, fA, fM, []) |fA fM in_sync. ¬ in_sync ⟶ fA = fM} ∪ {(in_sync, hp_IdleInit, fA, ¬ fA, []) |fA in_sync. True} ∪ {(in_sync, hp_InitMark, fA, ¬ fA, [mw_fA (¬ fA)]) |fA in_sync. in_sync} ∪ {(in_sync, hp_InitMark, fA, fM, []) |fA fM in_sync. ¬ in_sync ⟶ fA ≠ fM} ∪ {(in_sync, hp_Mark, fA, fA, []) |fA in_sync. True} ∪ {(in_sync, hp_IdleMarkSweep, fA, fA, []) |fA in_sync. True}›*) p_not_sys (*‹(?p ≠ sys) = (?p = gc ∨ (∃m. ?p = mutator m))›*) split: mem_store_action.splits (*‹?P (case ?mem_store_action of mw_Mark x xa ⇒ ?f1.0 x xa | mw_Mutate x xa xb ⇒ ?f2.0 x xa xb | mw_Mutate_Payload x xa xb ⇒ ?f3.0 x xa xb | mw_fA x ⇒ ?f4.0 x | mw_fM x ⇒ ?f5.0 x | mw_Phase x ⇒ ?f6.0 x) = ((∀x11 x12. ?mem_store_action = mw_Mark x11 x12 ⟶ ?P (?f1.0 x11 x12)) ∧ (∀x21 x22 x23. ?mem_store_action = mw_Mutate x21 x22 x23 ⟶ ?P (?f2.0 x21 x22 x23)) ∧ (∀x31 x32 x33. ?mem_store_action = mw_Mutate_Payload x31 x32 x33 ⟶ ?P (?f3.0 x31 x32 x33)) ∧ (∀x4. ?mem_store_action = mw_fA x4 ⟶ ?P (?f4.0 x4)) ∧ (∀x5. ?mem_store_action = mw_fM x5 ⟶ ?P (?f5.0 x5)) ∧ (∀x6. ?mem_store_action = mw_Phase x6 ⟶ ?P (?f6.0 x6)))› ‹?P (case ?mem_store_action of mw_Mark x xa ⇒ ?f1.0 x xa | mw_Mutate x xa xb ⇒ ?f2.0 x xa xb | mw_Mutate_Payload x xa xb ⇒ ?f3.0 x xa xb | mw_fA x ⇒ ?f4.0 x | mw_fM x ⇒ ?f5.0 x | mw_Phase x ⇒ ?f6.0 x) = (¬ ((∃x11 x12. ?mem_store_action = mw_Mark x11 x12 ∧ ¬ ?P (?f1.0 x11 x12)) ∨ (∃x21 x22 x23. ?mem_store_action = mw_Mutate x21 x22 x23 ∧ ¬ ?P (?f2.0 x21 x22 x23)) ∨ (∃x31 x32 x33. ?mem_store_action = mw_Mutate_Payload x31 x32 x33 ∧ ¬ ?P (?f3.0 x31 x32 x33)) ∨ (∃x4. ?mem_store_action = mw_fA x4 ∧ ¬ ?P (?f4.0 x4)) ∨ (∃x5. ?mem_store_action = mw_fM x5 ∧ ¬ ?P (?f5.0 x5)) ∨ (∃x6. ?mem_store_action = mw_Phase x6 ∧ ¬ ?P (?f6.0 x6))))›*)) (*goal: ‹⋀s s' p w ws. ⟦at sys tso_dequeue_store_buffer s; s'↓ = s↓(sys := do_store_action w (s↓ sys)⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(p := ws)⦈); taken sys tso_dequeue_store_buffer s'; ∀p''∈- {sys}. GST s' p'' = GST s p''; fA_rel_inv s↓; tso_store_inv s↓; sys_mem_store_buffers p s↓ = w # ws; not_blocked (s↓ sys) p; p ≠ sys⟧ ⟹ fA_rel_inv (s↓(sys := do_store_action w (s↓ sys)⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(p := ws)⦈))›*) apply (intro allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*) conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*) impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goals: 1. ‹⋀s s' p ws x4. ⟦taken sys tso_dequeue_store_buffer s'; ∀p''∈- {sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. ¬ sys_ghost_hs_in_sync x s↓) ⟶ sys_fA s↓ = gc_fM s↓) ∨ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ sys_fA s↓)] ∧ All (ghost_hs_in_sync (s↓ sys)) ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. ¬ sys_ghost_hs_in_sync x s↓) ⟶ sys_fA s↓ = (¬ gc_fM s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; tso_store_inv s↓; sys_mem_store_buffers p s↓ = mw_fA x4 # ws; not_blocked (s↓ sys) p; p = gc ∨ (∃m. p = mutator m); at sys tso_dequeue_store_buffer s; s'↓ = s↓(sys := s↓ sys⦇fA := x4, mem_store_buffers := (mem_store_buffers (s↓ sys))(p := ws)⦈); gc = p⟧ ⟹ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA ws = [] ∧ ((∃x. ¬ sys_ghost_hs_in_sync x s↓) ⟶ x4 = gc_fM s↓) ∨ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ x4) ∧ filter is_mw_fA ws = [] ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ x4) ∧ filter is_mw_fA ws = [mw_fA (¬ x4)] ∧ All (ghost_hs_in_sync (s↓ sys)) ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA ws = [] ∧ ((∃x. ¬ sys_ghost_hs_in_sync x s↓) ⟶ x4 = (¬ gc_fM s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = x4 ∧ filter is_mw_fA ws = [] ∨ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = x4 ∧ filter is_mw_fA ws = []› 2. ‹⋀s s' p ws x4. ⟦taken sys tso_dequeue_store_buffer s'; ∀p''∈- {sys}. GST s' p'' = GST s p''; sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. ¬ sys_ghost_hs_in_sync x s↓) ⟶ sys_fA s↓ = gc_fM s↓) ∨ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ sys_fA s↓) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ sys_fA s↓)] ∧ All (ghost_hs_in_sync (s↓ sys)) ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. ¬ sys_ghost_hs_in_sync x s↓) ⟶ sys_fA s↓ = (¬ gc_fM s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = sys_fA s↓ ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; tso_store_inv s↓; sys_mem_store_buffers p s↓ = mw_fA x4 # ws; not_blocked (s↓ sys) p; p = gc ∨ (∃m. p = mutator m); at sys tso_dequeue_store_buffer s; s'↓ = s↓(sys := s↓ sys⦇fA := x4, mem_store_buffers := (mem_store_buffers (s↓ sys))(p := ws)⦈); gc ≠ p⟧ ⟹ sys_ghost_hs_phase s↓ = hp_Idle ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. ¬ sys_ghost_hs_in_sync x s↓) ⟶ x4 = gc_fM s↓) ∨ sys_ghost_hs_phase s↓ = hp_IdleInit ∧ gc_fM s↓ = (¬ x4) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ gc_fM s↓ = (¬ x4) ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [mw_fA (¬ x4)] ∧ All (ghost_hs_in_sync (s↓ sys)) ∨ sys_ghost_hs_phase s↓ = hp_InitMark ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∧ ((∃x. ¬ sys_ghost_hs_in_sync x s↓) ⟶ x4 = (¬ gc_fM s↓)) ∨ sys_ghost_hs_phase s↓ = hp_Mark ∧ gc_fM s↓ = x4 ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = [] ∨ sys_ghost_hs_phase s↓ = hp_IdleMarkSweep ∧ gc_fM s↓ = x4 ∧ filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› discuss goal 1*) apply clarsimp (*discuss goal 2*) apply clarsimp (*proven 2 subgoals*) . end subsubsection‹sys phase inv› context mut_m begin lemma sys_phase_inv[intro]: notes if_split_asm[split del] notes fun_upd_apply[simp] shows "⦃ handshake_invL ❙∧ mark_object_invL ❙∧ mut_get_roots.mark_object_invL m ❙∧ mut_store_del.mark_object_invL m ❙∧ mut_store_ins.mark_object_invL m ❙∧ LSTP (fA_rel_inv ❙∧ fM_rel_inv ❙∧ handshake_phase_inv ❙∧ mutators_phase_inv ❙∧ phase_rel_inv ❙∧ sys_phase_inv ❙∧ valid_refs_inv) ⦄ mutator m ⦃ LSTP sys_phase_inv ⦄" proof( (vcg_jackhammer (no_thin_post_inv) ; clarsimp simp: fA_rel_inv_def fM_rel_inv_def sys_phase_inv_aux_case heap_colours_colours split: hs_phase.splits if_splits ) , vcg_name_cases ) case (alloc s s' rb) then show ?case by (clarsimp simp: fA_rel_def fM_rel_def no_black_refs_def dest!: handshake_phase_invD phase_rel_invD split: hs_phase.splits) next case (store_ins_mo_co_mark0 s s' y) then show ?case by (fastforce simp: fA_rel_def fM_rel_def hp_step_rel_def dest!: handshake_phase_invD phase_rel_invD) next case (store_ins_mo_co_mark s s' y) then show ?case apply - apply (drule spec[where x=m]) apply (rule conjI) apply (clarsimp simp: hp_step_rel_def phase_rel_def conj_disj_distribR[symmetric] dest!: handshake_phase_invD phase_rel_invD) apply (elim disjE, simp_all add: no_grey_refs_not_rootD; fail) apply (clarsimp simp: hp_step_rel_def phase_rel_def dest!: handshake_phase_invD phase_rel_invD) apply (elim disjE, simp_all add: no_grey_refs_not_rootD)[1] apply clarsimp apply (elim disjE, simp_all add: no_grey_refs_not_rootD filter_empty_conv)[1] apply fastforce done next case (store_del_mo_co_mark0 s s' y) then show ?case apply (clarsimp simp: hp_step_rel_def dest!: handshake_phase_invD phase_rel_invD) apply (metis (no_types, lifting) mut_m.no_grey_refs_not_rootD mutator_phase_inv_aux.simps(5)) done next case (store_del_mo_co_mark s s' y) then show ?case apply - apply (drule spec[where x=m]) apply (rule conjI) apply (clarsimp simp: hp_step_rel_def phase_rel_def conj_disj_distribR[symmetric] no_grey_refs_not_rootD dest!: handshake_phase_invD phase_rel_invD; fail) apply (clarsimp simp: hp_step_rel_def phase_rel_def dest!: handshake_phase_invD phase_rel_invD) apply (elim disjE, simp_all add: no_grey_refs_not_rootD) apply clarsimp apply (elim disjE, simp_all add: no_grey_refs_not_rootD filter_empty_conv) apply fastforce done next case (hs_get_roots_done s s') then show ?case apply (clarsimp simp: hp_step_rel_def phase_rel_def filter_empty_conv dest!: handshake_phase_invD phase_rel_invD) apply auto done next case (hs_get_roots_loop_mo_co_mark s s' y) then show ?case apply - apply (drule spec[where x=m]) apply (rule conjI) apply (clarsimp simp: hp_step_rel_def phase_rel_def conj_disj_distribR[symmetric] dest!: handshake_phase_invD phase_rel_invD; fail) apply (clarsimp simp: hp_step_rel_def phase_rel_def dest!: handshake_phase_invD phase_rel_invD) apply (elim disjE, simp_all add: no_grey_refs_not_rootD) apply clarsimp apply (elim disjE, simp_all add: no_grey_refs_not_rootD filter_empty_conv)[1] apply fastforce done next case (hs_get_work_done s s') then show ?case apply (clarsimp simp: hp_step_rel_def phase_rel_def filter_empty_conv dest!: handshake_phase_invD phase_rel_invD) apply auto done qed (clarsimp simp: hp_step_rel_def dest!: handshake_phase_invD phase_rel_invD)+ end lemma (in gc) sys_phase_inv[intro]: notes fun_upd_apply[simp] shows "⦃ fM_fA_invL ❙∧ gc_W_empty_invL ❙∧ handshake_invL ❙∧ obj_fields_marked_invL ❙∧ phase_invL ❙∧ sweep_loop_invL ❙∧ LSTP (phase_rel_inv ❙∧ sys_phase_inv ❙∧ valid_W_inv ❙∧ tso_store_inv) ⦄ gc ⦃ LSTP sys_phase_inv ⦄" proof (vcg_jackhammer (no_thin_post_inv), vcg_name_cases) (*goals: 1. ‹⋀s s'. ⟦at gc mark_loop_get_work_load_W s; at sys sys.sys_hs_gc_load_W s; s'↓ = s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈); taken gc mark_loop_get_work_load_W s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_W s↓ = {} ⟶ no_grey_refs s↓; sys_fA s↓ = sys_fM s↓; ∀x. mut_m.gc_W_empty_mut_inv x s↓; sys_hs_type s↓ = ht_GetWork; gc_phase s↓ = ph_Mark; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; gc_W s↓ = {}; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep; sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓; mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓⟧ ⟹ (sys_phase s↓ = ph_Idle ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈))) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈)))› 2. ‹⋀s s'. ⟦at gc mark_loop_blacken s; s'↓ = s↓(gc := s↓ gc⦇W := gc_W s↓ - {gc_tmp_ref s↓}⦈); taken gc mark_loop_blacken s'; ∀p''∈- {gc}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; gc_field_set s↓ = {}; sys_fA s↓ = sys_fM s↓; gc_phase s↓ = ph_Mark; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep; sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓; mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓; obj_fields_marked s↓; gc_tmp_ref s↓ ∈ gc_W s↓⟧ ⟹ (sys_phase s↓ = ph_Idle ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := gc_W s↓ - {gc_tmp_ref s↓}⦈))) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := gc_W s↓ - {gc_tmp_ref s↓}⦈)))› 3. ‹⋀s s'. ⟦at gc mark_loop_mo_co_W s; s'↓ = s↓(gc := s↓ gc⦇W := insert (the (gc_ref s↓)) (gc_W s↓), ghost_honorary_grey := {}⦈); taken gc mark_loop_mo_co_W s'; ∀p''∈- {gc}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_fA s↓ = sys_fM s↓; obj_at_field_on_heap (λr. gc_ref s↓ = Some r ∨ marked r s↓) (gc_tmp_ref s↓) (gc_field s↓) s↓; ∀x. (∃y. gc_ref s↓ = Some y) ∧ (the (gc_ref s↓) reaches x) s↓ ⟶ obj_at (λs. True) x s↓; gc_phase s↓ = ph_Mark; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep; sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓; mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓; obj_fields_marked s↓; gc_tmp_ref s↓ ∈ gc_W s↓⟧ ⟹ (sys_phase s↓ = ph_Idle ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := insert (the (gc_ref s↓)) (gc_W s↓), ghost_honorary_grey := {}⦈))) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := insert (the (gc_ref s↓)) (gc_W s↓), ghost_honorary_grey := {}⦈)))› 4. ‹⋀s s'. ⟦at gc mark_loop_mo_co_mark s; at sys sys.tso_store s; s'↓ = s↓(gc := s↓ gc⦇ghost_honorary_grey := {the (gc_ref s↓)}⦈, sys := s↓ sys⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := sys_mem_store_buffers gc s↓ @ [mw_Mark (the (gc_ref s↓)) (sys_fM s↓)])⦈); taken gc mark_loop_mo_co_mark s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_fA s↓ = sys_fM s↓; obj_at_field_on_heap (λr. gc_ref s↓ = Some r ∨ marked r s↓) (gc_tmp_ref s↓) (gc_field s↓) s↓; ∀x. (∃y. gc_ref s↓ = Some y) ∧ (the (gc_ref s↓) reaches x) s↓ ⟶ obj_at (λs. True) x s↓; gc_phase s↓ = ph_Mark; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep; sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓; mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓; obj_fields_marked s↓; gc_tmp_ref s↓ ∈ gc_W s↓⟧ ⟹ (sys_phase s↓ = ph_Idle ⟶ no_grey_refs (s↓(gc := s↓ gc⦇ghost_honorary_grey := {the (gc_ref s↓)}⦈))) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs (s↓(gc := s↓ gc⦇ghost_honorary_grey := {the (gc_ref s↓)}⦈)))› 5. ‹⋀s s'. ⟦at gc mark_loop_get_roots_load_W s; at sys sys.sys_hs_gc_load_W s; s'↓ = s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈); taken gc mark_loop_get_roots_load_W s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_W s↓ = {} ⟶ no_grey_refs s↓; sys_fA s↓ = sys_fM s↓; ∀x. mut_m.gc_W_empty_mut_inv x s↓; sys_hs_type s↓ = ht_GetRoots; gc_phase s↓ = ph_Mark; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; gc_W s↓ = {}; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep; sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓; mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓⟧ ⟹ (sys_phase s↓ = ph_Idle ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈))) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈)))› 6. ‹⋀s s'. ⟦at gc mark_loop_get_roots_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_GetRoots, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_IdleMarkSweep⦈); taken gc mark_loop_get_roots_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_fA s↓ = sys_fM s↓; gc_phase s↓ = ph_Mark; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; gc_W s↓ = {}; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_Mark⟧ ⟹ (sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓)› 7. ‹⋀s s'. ⟦at gc idle_noop_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_NOOP, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_Idle⦈); taken gc idle_noop_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_fA s↓ = sys_fM s↓; gc_phase s↓ = ph_Idle; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; no_grey_refs s↓; gc_W s↓ = {}; ∀x. obj_at (λs. True) x s↓ ⟶ marked x s↓; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep⟧ ⟹ black_heap s↓›*) case (mark_loop_get_work_load_W s s') (*‹at gc mark_loop_get_work_load_W s› ‹at sys sys.sys_hs_gc_load_W s› ‹s'↓ = s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈)› ‹taken gc mark_loop_get_work_load_W s'› ‹∀p''∈- {gc, sys}. GST s' p'' = GST s p''› ‹phase_rel_inv (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓› ‹valid_W_inv (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓› ‹tso_store_inv s↓› ‹sys_W (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = {} ⟶ no_grey_refs s↓› ‹sys_fA (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = sys_fM s↓› ‹∀x. mut_m.gc_W_empty_mut_inv x s↓› ‹sys_hs_type s↓ = ht_GetWork› ‹gc_phase s↓ = ph_Mark› ‹filter is_mw_fM (sys_mem_store_buffers gc s↓) = []› ‹filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []› ‹gc_fM (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = sys_fM s↓› ‹gc_W s↓ = {}› ‹gc_ghost_honorary_grey s↓ = {}› ‹filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› ‹∀x::'d. ¬ sys_hs_pending x (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓› ‹All (ghost_hs_in_sync ((s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ sys))› ‹sys_ghost_hs_phase s↓ = hp_IdleMarkSweep› ‹sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓› ‹mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓›*) then show "?case" (*goal: ‹(sys_phase (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = ph_Idle ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈))) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈)))›*) by (msorry) next (*goals: 1. ‹⋀s s'. ⟦at gc mark_loop_blacken s; s'↓ = s↓(gc := s↓ gc⦇W := gc_W s↓ - {gc_tmp_ref s↓}⦈); taken gc mark_loop_blacken s'; ∀p''∈- {gc}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; gc_field_set s↓ = {}; sys_fA s↓ = sys_fM s↓; gc_phase s↓ = ph_Mark; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep; sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓; mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓; obj_fields_marked s↓; gc_tmp_ref s↓ ∈ gc_W s↓⟧ ⟹ (sys_phase s↓ = ph_Idle ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := gc_W s↓ - {gc_tmp_ref s↓}⦈))) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := gc_W s↓ - {gc_tmp_ref s↓}⦈)))› 2. ‹⋀s s'. ⟦at gc mark_loop_mo_co_W s; s'↓ = s↓(gc := s↓ gc⦇W := insert (the (gc_ref s↓)) (gc_W s↓), ghost_honorary_grey := {}⦈); taken gc mark_loop_mo_co_W s'; ∀p''∈- {gc}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_fA s↓ = sys_fM s↓; obj_at_field_on_heap (λr. gc_ref s↓ = Some r ∨ marked r s↓) (gc_tmp_ref s↓) (gc_field s↓) s↓; ∀x. (∃y. gc_ref s↓ = Some y) ∧ (the (gc_ref s↓) reaches x) s↓ ⟶ obj_at (λs. True) x s↓; gc_phase s↓ = ph_Mark; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep; sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓; mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓; obj_fields_marked s↓; gc_tmp_ref s↓ ∈ gc_W s↓⟧ ⟹ (sys_phase s↓ = ph_Idle ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := insert (the (gc_ref s↓)) (gc_W s↓), ghost_honorary_grey := {}⦈))) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := insert (the (gc_ref s↓)) (gc_W s↓), ghost_honorary_grey := {}⦈)))› 3. ‹⋀s s'. ⟦at gc mark_loop_mo_co_mark s; at sys sys.tso_store s; s'↓ = s↓(gc := s↓ gc⦇ghost_honorary_grey := {the (gc_ref s↓)}⦈, sys := s↓ sys⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := sys_mem_store_buffers gc s↓ @ [mw_Mark (the (gc_ref s↓)) (sys_fM s↓)])⦈); taken gc mark_loop_mo_co_mark s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_fA s↓ = sys_fM s↓; obj_at_field_on_heap (λr. gc_ref s↓ = Some r ∨ marked r s↓) (gc_tmp_ref s↓) (gc_field s↓) s↓; ∀x. (∃y. gc_ref s↓ = Some y) ∧ (the (gc_ref s↓) reaches x) s↓ ⟶ obj_at (λs. True) x s↓; gc_phase s↓ = ph_Mark; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep; sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓; mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓; obj_fields_marked s↓; gc_tmp_ref s↓ ∈ gc_W s↓⟧ ⟹ (sys_phase s↓ = ph_Idle ⟶ no_grey_refs (s↓(gc := s↓ gc⦇ghost_honorary_grey := {the (gc_ref s↓)}⦈))) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs (s↓(gc := s↓ gc⦇ghost_honorary_grey := {the (gc_ref s↓)}⦈)))› 4. ‹⋀s s'. ⟦at gc mark_loop_get_roots_load_W s; at sys sys.sys_hs_gc_load_W s; s'↓ = s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈); taken gc mark_loop_get_roots_load_W s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_W s↓ = {} ⟶ no_grey_refs s↓; sys_fA s↓ = sys_fM s↓; ∀x. mut_m.gc_W_empty_mut_inv x s↓; sys_hs_type s↓ = ht_GetRoots; gc_phase s↓ = ph_Mark; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; gc_W s↓ = {}; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep; sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓; mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓⟧ ⟹ (sys_phase s↓ = ph_Idle ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈))) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈)))› 5. ‹⋀s s'. ⟦at gc mark_loop_get_roots_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_GetRoots, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_IdleMarkSweep⦈); taken gc mark_loop_get_roots_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_fA s↓ = sys_fM s↓; gc_phase s↓ = ph_Mark; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; gc_W s↓ = {}; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_Mark⟧ ⟹ (sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓)› 6. ‹⋀s s'. ⟦at gc idle_noop_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_NOOP, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_Idle⦈); taken gc idle_noop_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_fA s↓ = sys_fM s↓; gc_phase s↓ = ph_Idle; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; no_grey_refs s↓; gc_W s↓ = {}; ∀x. obj_at (λs. True) x s↓ ⟶ marked x s↓; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep⟧ ⟹ black_heap s↓›*) case (mark_loop_blacken s s') (*‹at gc mark_loop_blacken s› ‹s'↓ = s↓(gc := s↓ gc⦇W := gc_W s↓ - {gc_tmp_ref s↓}⦈)› ‹taken gc mark_loop_blacken (s'::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)› ‹∀p''∈- {gc}. GST s' p'' = GST s p''› ‹phase_rel_inv s↓› ‹valid_W_inv s↓› ‹tso_store_inv s↓› ‹gc_field_set (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = {}› ‹sys_fA s↓ = sys_fM s↓› ‹gc_phase s↓ = ph_Mark› ‹filter is_mw_fM (sys_mem_store_buffers gc s↓) = []› ‹filter is_mw_Phase (sys_mem_store_buffers gc (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓) = []› ‹gc_fM (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = sys_fM s↓› ‹gc_ghost_honorary_grey s↓ = {}› ‹filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› ‹∀x. ¬ sys_hs_pending x s↓› ‹All (ghost_hs_in_sync ((s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ sys))› ‹sys_ghost_hs_phase s↓ = hp_IdleMarkSweep› ‹sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓› ‹mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓› ‹obj_fields_marked s↓› ‹gc_tmp_ref (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ ∈ gc_W s↓›*) then show "?case" (*goal: ‹(sys_phase s↓ = ph_Idle ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := gc_W s↓ - {gc_tmp_ref s↓}⦈))) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := gc_W s↓ - {gc_tmp_ref s↓}⦈)))›*) by (meson no_grey_refsD( (*‹no_grey_refs (?s::?'a::type process_name ⇒ (?'b, ?'a, ?'c, ?'d) Model.local_state) ⟹ (?r::?'d::type) ∉ W (?s (?p::?'a::type process_name))›*) 1)) next (*goals: 1. ‹⋀s s'. ⟦at gc mark_loop_mo_co_W s; s'↓ = s↓(gc := s↓ gc⦇W := insert (the (gc_ref s↓)) (gc_W s↓), ghost_honorary_grey := {}⦈); taken gc mark_loop_mo_co_W s'; ∀p''∈- {gc}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_fA s↓ = sys_fM s↓; obj_at_field_on_heap (λr. gc_ref s↓ = Some r ∨ marked r s↓) (gc_tmp_ref s↓) (gc_field s↓) s↓; ∀x. (∃y. gc_ref s↓ = Some y) ∧ (the (gc_ref s↓) reaches x) s↓ ⟶ obj_at (λs. True) x s↓; gc_phase s↓ = ph_Mark; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep; sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓; mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓; obj_fields_marked s↓; gc_tmp_ref s↓ ∈ gc_W s↓⟧ ⟹ (sys_phase s↓ = ph_Idle ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := insert (the (gc_ref s↓)) (gc_W s↓), ghost_honorary_grey := {}⦈))) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := insert (the (gc_ref s↓)) (gc_W s↓), ghost_honorary_grey := {}⦈)))› 2. ‹⋀s s'. ⟦at gc mark_loop_mo_co_mark s; at sys sys.tso_store s; s'↓ = s↓(gc := s↓ gc⦇ghost_honorary_grey := {the (gc_ref s↓)}⦈, sys := s↓ sys⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := sys_mem_store_buffers gc s↓ @ [mw_Mark (the (gc_ref s↓)) (sys_fM s↓)])⦈); taken gc mark_loop_mo_co_mark s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_fA s↓ = sys_fM s↓; obj_at_field_on_heap (λr. gc_ref s↓ = Some r ∨ marked r s↓) (gc_tmp_ref s↓) (gc_field s↓) s↓; ∀x. (∃y. gc_ref s↓ = Some y) ∧ (the (gc_ref s↓) reaches x) s↓ ⟶ obj_at (λs. True) x s↓; gc_phase s↓ = ph_Mark; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep; sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓; mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓; obj_fields_marked s↓; gc_tmp_ref s↓ ∈ gc_W s↓⟧ ⟹ (sys_phase s↓ = ph_Idle ⟶ no_grey_refs (s↓(gc := s↓ gc⦇ghost_honorary_grey := {the (gc_ref s↓)}⦈))) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs (s↓(gc := s↓ gc⦇ghost_honorary_grey := {the (gc_ref s↓)}⦈)))› 3. ‹⋀s s'. ⟦at gc mark_loop_get_roots_load_W s; at sys sys.sys_hs_gc_load_W s; s'↓ = s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈); taken gc mark_loop_get_roots_load_W s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_W s↓ = {} ⟶ no_grey_refs s↓; sys_fA s↓ = sys_fM s↓; ∀x. mut_m.gc_W_empty_mut_inv x s↓; sys_hs_type s↓ = ht_GetRoots; gc_phase s↓ = ph_Mark; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; gc_W s↓ = {}; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep; sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓; mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓⟧ ⟹ (sys_phase s↓ = ph_Idle ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈))) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈)))› 4. ‹⋀s s'. ⟦at gc mark_loop_get_roots_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_GetRoots, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_IdleMarkSweep⦈); taken gc mark_loop_get_roots_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_fA s↓ = sys_fM s↓; gc_phase s↓ = ph_Mark; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; gc_W s↓ = {}; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_Mark⟧ ⟹ (sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓)› 5. ‹⋀s s'. ⟦at gc idle_noop_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_NOOP, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_Idle⦈); taken gc idle_noop_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_fA s↓ = sys_fM s↓; gc_phase s↓ = ph_Idle; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; no_grey_refs s↓; gc_W s↓ = {}; ∀x. obj_at (λs. True) x s↓ ⟶ marked x s↓; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep⟧ ⟹ black_heap s↓›*) case (mark_loop_mo_co_W s s') (*‹at gc mark_loop_mo_co_W s› ‹s'↓ = s↓(gc := s↓ gc⦇W := insert (the (gc_ref s↓)) (gc_W s↓), ghost_honorary_grey := {}⦈)› ‹taken gc mark_loop_mo_co_W s'› ‹∀p''∈- {gc}. GST s' p'' = GST s p''› ‹phase_rel_inv s↓› ‹valid_W_inv s↓› ‹tso_store_inv s↓› ‹sys_fA (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = sys_fM s↓› ‹obj_at_field_on_heap (λr. gc_ref s↓ = Some r ∨ marked r s↓) (gc_tmp_ref s↓) (gc_field s↓) s↓› ‹∀x::'c::type. (∃y::'c::type. gc_ref (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = Some y) ∧ (the (gc_ref s↓) reaches x) s↓ ⟶ obj_at (λs::('a, 'b, 'c) object. True) x s↓› ‹gc_phase s↓ = ph_Mark› ‹filter is_mw_fM (sys_mem_store_buffers gc s↓) = []› ‹filter is_mw_Phase (sys_mem_store_buffers gc (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓) = []› ‹gc_fM s↓ = sys_fM s↓› ‹filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› ‹∀x. ¬ sys_hs_pending x s↓› ‹All (ghost_hs_in_sync (s↓ sys))› ‹sys_ghost_hs_phase s↓ = hp_IdleMarkSweep› ‹sys_phase (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = ph_Idle ⟶ no_grey_refs s↓› ‹mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓› ‹obj_fields_marked s↓› ‹gc_tmp_ref (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ ∈ gc_W s↓›*) then show "?case" (*goal: ‹(sys_phase s↓ = ph_Idle ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := insert (the (gc_ref s↓)) (gc_W s↓), ghost_honorary_grey := {}⦈))) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := insert (the (gc_ref s↓)) (gc_W s↓), ghost_honorary_grey := {}⦈)))›*) by (meson no_grey_refsD( (*‹no_grey_refs ?s ⟹ ?r ∉ W (?s ?p)›*) 1)) next (*goals: 1. ‹⋀s s'. ⟦at gc mark_loop_mo_co_mark s; at sys sys.tso_store s; s'↓ = s↓(gc := s↓ gc⦇ghost_honorary_grey := {the (gc_ref s↓)}⦈, sys := s↓ sys⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := sys_mem_store_buffers gc s↓ @ [mw_Mark (the (gc_ref s↓)) (sys_fM s↓)])⦈); taken gc mark_loop_mo_co_mark s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_fA s↓ = sys_fM s↓; obj_at_field_on_heap (λr. gc_ref s↓ = Some r ∨ marked r s↓) (gc_tmp_ref s↓) (gc_field s↓) s↓; ∀x. (∃y. gc_ref s↓ = Some y) ∧ (the (gc_ref s↓) reaches x) s↓ ⟶ obj_at (λs. True) x s↓; gc_phase s↓ = ph_Mark; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep; sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓; mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓; obj_fields_marked s↓; gc_tmp_ref s↓ ∈ gc_W s↓⟧ ⟹ (sys_phase s↓ = ph_Idle ⟶ no_grey_refs (s↓(gc := s↓ gc⦇ghost_honorary_grey := {the (gc_ref s↓)}⦈))) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs (s↓(gc := s↓ gc⦇ghost_honorary_grey := {the (gc_ref s↓)}⦈)))› 2. ‹⋀s s'. ⟦at gc mark_loop_get_roots_load_W s; at sys sys.sys_hs_gc_load_W s; s'↓ = s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈); taken gc mark_loop_get_roots_load_W s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_W s↓ = {} ⟶ no_grey_refs s↓; sys_fA s↓ = sys_fM s↓; ∀x. mut_m.gc_W_empty_mut_inv x s↓; sys_hs_type s↓ = ht_GetRoots; gc_phase s↓ = ph_Mark; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; gc_W s↓ = {}; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep; sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓; mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓⟧ ⟹ (sys_phase s↓ = ph_Idle ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈))) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈)))› 3. ‹⋀s s'. ⟦at gc mark_loop_get_roots_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_GetRoots, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_IdleMarkSweep⦈); taken gc mark_loop_get_roots_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_fA s↓ = sys_fM s↓; gc_phase s↓ = ph_Mark; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; gc_W s↓ = {}; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_Mark⟧ ⟹ (sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓)› 4. ‹⋀s s'. ⟦at gc idle_noop_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_NOOP, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_Idle⦈); taken gc idle_noop_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_fA s↓ = sys_fM s↓; gc_phase s↓ = ph_Idle; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; no_grey_refs s↓; gc_W s↓ = {}; ∀x. obj_at (λs. True) x s↓ ⟶ marked x s↓; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep⟧ ⟹ black_heap s↓›*) case (mark_loop_mo_co_mark s s') (*‹at gc mark_loop_mo_co_mark s› ‹at sys sys.tso_store (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)› ‹s'↓ = s↓(gc := s↓ gc⦇ghost_honorary_grey := {the (gc_ref s↓)}⦈, sys := s↓ sys⦇mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := sys_mem_store_buffers gc s↓ @ [mw_Mark (the (gc_ref s↓)) (sys_fM s↓)])⦈)› ‹taken gc mark_loop_mo_co_mark s'› ‹∀p''∈- {gc, sys}. GST s' p'' = GST s p''› ‹phase_rel_inv s↓› ‹valid_W_inv (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓› ‹tso_store_inv s↓› ‹sys_fA s↓ = sys_fM s↓› ‹obj_at_field_on_heap (λr. gc_ref s↓ = Some r ∨ marked r s↓) (gc_tmp_ref s↓) (gc_field s↓) s↓› ‹∀x::'c. (∃y::'c. gc_ref (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = Some y) ∧ (the (gc_ref s↓) reaches x) s↓ ⟶ obj_at (λs::('a, 'b, 'c) object. True) x s↓› ‹gc_phase s↓ = ph_Mark› ‹filter is_mw_fM (sys_mem_store_buffers gc s↓) = []› ‹filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []› ‹gc_fM s↓ = sys_fM s↓› ‹gc_ghost_honorary_grey (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = {}› ‹filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› ‹∀x::'d. ¬ sys_hs_pending x (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓› ‹All (ghost_hs_in_sync (s↓ sys))› ‹sys_ghost_hs_phase s↓ = hp_IdleMarkSweep› ‹sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓› ‹mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓› ‹obj_fields_marked s↓› ‹gc_tmp_ref (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ ∈ gc_W s↓›*) then show "?case" (*goal: ‹(sys_phase s↓ = ph_Idle ⟶ no_grey_refs (s↓(gc := s↓ gc⦇ghost_honorary_grey := {the (gc_ref s↓)}⦈))) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs (s↓(gc := s↓ gc⦇ghost_honorary_grey := {the (gc_ref s↓)}⦈)))›*) by (meson no_grey_refsD( (*‹no_grey_refs ?s ⟹ ?r ∉ W (?s ?p)›*) 1)) next (*goals: 1. ‹⋀(s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state) s'::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state. ⟦at gc mark_loop_get_roots_load_W s; at sys sys.sys_hs_gc_load_W s; s'↓ = s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈); taken gc mark_loop_get_roots_load_W s'; ∀p''::'d process_name∈- {gc, sys}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_W s↓ = {} ⟶ no_grey_refs s↓; sys_fA s↓ = sys_fM s↓; ∀x::'d. mut_m.gc_W_empty_mut_inv x s↓; sys_hs_type s↓ = ht_GetRoots; gc_phase s↓ = ph_Mark; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; gc_W s↓ = {}; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x::'d. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep; sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓; mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓⟧ ⟹ (sys_phase s↓ = ph_Idle ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈))) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈)))› 2. ‹⋀(s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state) s'::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state. ⟦at gc mark_loop_get_roots_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_GetRoots, ghost_hs_in_sync := λs::'d. False, ghost_hs_phase := hp_IdleMarkSweep⦈); taken gc mark_loop_get_roots_init_type s'; ∀p''::'d process_name∈- {gc, sys}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_fA s↓ = sys_fM s↓; gc_phase s↓ = ph_Mark; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; gc_W s↓ = {}; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x::'d. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_Mark⟧ ⟹ (sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓)› 3. ‹⋀(s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state) s'::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state. ⟦at gc idle_noop_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_NOOP, ghost_hs_in_sync := λs::'d. False, ghost_hs_phase := hp_Idle⦈); taken gc idle_noop_init_type s'; ∀p''::'d process_name∈- {gc, sys}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_fA s↓ = sys_fM s↓; gc_phase s↓ = ph_Idle; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; no_grey_refs s↓; gc_W s↓ = {}; ∀x::'c. obj_at (λs::('a, 'b, 'c) object. True) x s↓ ⟶ marked x s↓; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x::'d. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep⟧ ⟹ black_heap s↓›*) case (mark_loop_get_roots_load_W s s') (*‹at gc mark_loop_get_roots_load_W s› ‹at sys sys.sys_hs_gc_load_W (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)› ‹s'↓ = s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈)› ‹taken gc mark_loop_get_roots_load_W s'› ‹∀p''∈- {gc, sys}. GST s' p'' = GST s p''› ‹phase_rel_inv s↓› ‹valid_W_inv s↓› ‹tso_store_inv (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓› ‹sys_W s↓ = {} ⟶ no_grey_refs s↓› ‹sys_fA (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = sys_fM s↓› ‹∀x. mut_m.gc_W_empty_mut_inv x s↓› ‹sys_hs_type (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = ht_GetRoots› ‹gc_phase s↓ = ph_Mark› ‹filter is_mw_fM (sys_mem_store_buffers gc s↓) = []› ‹filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []› ‹gc_fM (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = sys_fM s↓› ‹gc_W s↓ = {}› ‹gc_ghost_honorary_grey s↓ = {}› ‹filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› ‹∀x::'d::type. ¬ sys_hs_pending x (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓› ‹All (ghost_hs_in_sync (s↓ sys))› ‹sys_ghost_hs_phase (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = hp_IdleMarkSweep› ‹sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓› ‹mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓) ⟶ no_grey_refs s↓›*) then show "?case" (*goal: ‹(sys_phase s↓ = ph_Idle ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈))) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs (s↓(gc := s↓ gc⦇W := sys_W s↓⦈, sys := s↓ sys⦇W := {}⦈)))›*) by (msorry) next (*goals: 1. ‹⋀(s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state) s'::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state. ⟦at gc mark_loop_get_roots_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_GetRoots, ghost_hs_in_sync := λs::'d. False, ghost_hs_phase := hp_IdleMarkSweep⦈); taken gc mark_loop_get_roots_init_type s'; ∀p''::'d process_name∈- {gc, sys}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_fA s↓ = sys_fM s↓; gc_phase s↓ = ph_Mark; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; gc_W s↓ = {}; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x::'d. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_Mark⟧ ⟹ (sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓)› 2. ‹⋀(s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state) s'::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state. ⟦at gc idle_noop_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_NOOP, ghost_hs_in_sync := λs::'d. False, ghost_hs_phase := hp_Idle⦈); taken gc idle_noop_init_type s'; ∀p''::'d process_name∈- {gc, sys}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_fA s↓ = sys_fM s↓; gc_phase s↓ = ph_Idle; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; no_grey_refs s↓; gc_W s↓ = {}; ∀x::'c. obj_at (λs::('a, 'b, 'c) object. True) x s↓ ⟶ marked x s↓; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x::'d. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep⟧ ⟹ black_heap s↓›*) case (mark_loop_get_roots_init_type s s') (*‹at gc mark_loop_get_roots_init_type s› ‹at sys sys.sys_hs_gc_set_type s› ‹s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_GetRoots, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_IdleMarkSweep⦈)› ‹taken gc mark_loop_get_roots_init_type s'› ‹∀p''∈- {gc, sys}. GST s' p'' = GST s p''› ‹phase_rel_inv s↓› ‹valid_W_inv s↓› ‹tso_store_inv s↓› ‹sys_fA s↓ = sys_fM s↓› ‹gc_phase s↓ = ph_Mark› ‹filter is_mw_fM (sys_mem_store_buffers gc s↓) = []› ‹filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []› ‹gc_fM s↓ = sys_fM s↓› ‹gc_W s↓ = {}› ‹gc_ghost_honorary_grey s↓ = {}› ‹filter is_mw_fA (sys_mem_store_buffers gc s↓) = []› ‹∀x. ¬ sys_hs_pending x s↓› ‹All (ghost_hs_in_sync (s↓ sys))› ‹sys_ghost_hs_phase s↓ = hp_Mark›*) then show "?case" (*goal: ‹(sys_phase s↓ = ph_Idle ⟶ no_grey_refs s↓) ∧ (mw_Phase ph_Idle ∈ set (sys_mem_store_buffers gc s↓) ⟶ no_grey_refs s↓)›*) by (fastforce dest!: phase_rel_invD (*‹phase_rel_inv ?s ⟹ (∀m. sys_ghost_hs_in_sync m ?s, sys_ghost_hs_phase ?s, gc_phase ?s, sys_phase ?s, filter is_mw_Phase (sys_mem_store_buffers gc ?s)) ∈ phase_rel›*) simp: phase_rel_def (*‹phase_rel = {(in_sync, hp, ph, ph, []) |in_sync hp ph. handshake_phase_rel hp in_sync ph} ∪ {True} × {(hp_IdleInit, ph_Init, ph_Idle, [mw_Phase ph_Init]), (hp_InitMark, ph_Mark, ph_Init, [mw_Phase ph_Mark]), (hp_IdleMarkSweep, ph_Sweep, ph_Mark, [mw_Phase ph_Sweep]), (hp_IdleMarkSweep, ph_Idle, ph_Mark, [mw_Phase ph_Sweep, mw_Phase ph_Idle]), (hp_IdleMarkSweep, ph_Idle, ph_Sweep, [mw_Phase ph_Idle])}›*) no_grey_refsD (*‹no_grey_refs ?s ⟹ ?r ∉ W (?s ?p)› ‹no_grey_refs ?s ⟹ ?r ∉ WL ?p ?s› ‹no_grey_refs ?s ⟹ ?r ∉ ghost_honorary_grey (?s ?p)›*) filter_empty_conv (*‹(filter ?P ?xs = []) = (∀x∈set ?xs. ¬ ?P x)›*)) next (*goal: ‹⋀s s'. ⟦at gc idle_noop_init_type s; at sys sys.sys_hs_gc_set_type s; s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_NOOP, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_Idle⦈); taken gc idle_noop_init_type s'; ∀p''∈- {gc, sys}. GST s' p'' = GST s p''; phase_rel_inv s↓; valid_W_inv s↓; tso_store_inv s↓; sys_fA s↓ = sys_fM s↓; gc_phase s↓ = ph_Idle; filter is_mw_fM (sys_mem_store_buffers gc s↓) = []; filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []; gc_fM s↓ = sys_fM s↓; no_grey_refs s↓; gc_W s↓ = {}; ∀x. obj_at (λs. True) x s↓ ⟶ marked x s↓; gc_ghost_honorary_grey s↓ = {}; filter is_mw_fA (sys_mem_store_buffers gc s↓) = []; ∀x. ¬ sys_hs_pending x s↓; All (ghost_hs_in_sync (s↓ sys)); sys_ghost_hs_phase s↓ = hp_IdleMarkSweep⟧ ⟹ black_heap s↓›*) case (idle_noop_init_type s s') (*‹at gc idle_noop_init_type s› ‹at sys sys.sys_hs_gc_set_type s› ‹s'↓ = s↓(sys := s↓ sys⦇hs_type := ht_NOOP, ghost_hs_in_sync := λs. False, ghost_hs_phase := hp_Idle⦈)› ‹taken gc idle_noop_init_type s'› ‹∀p''∈- {gc, sys}. GST s' p'' = GST s p''› ‹phase_rel_inv s↓› ‹valid_W_inv s↓› ‹tso_store_inv s↓› ‹sys_fA s↓ = sys_fM s↓› ‹gc_phase s↓ = ph_Idle› ‹filter is_mw_fM (sys_mem_store_buffers gc (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓) = []› ‹filter is_mw_Phase (sys_mem_store_buffers gc s↓) = []› ‹gc_fM s↓ = sys_fM s↓› ‹no_grey_refs (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓› ‹gc_W (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓ = {}› ‹∀x. obj_at (λs. True) x s↓ ⟶ marked x s↓› ‹gc_ghost_honorary_grey s↓ = {}› ‹filter is_mw_fA (sys_mem_store_buffers gc (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓) = []› ‹∀x. ¬ sys_hs_pending x s↓› ‹All (ghost_hs_in_sync (s↓ sys))› ‹sys_ghost_hs_phase s↓ = hp_IdleMarkSweep›*) then show "?case" (*goal: ‹black_heap (s::(('a, 'b, 'c) response, char list, 'd process_name, 'd process_name × ('a, 'd, 'b, 'c) request_op, ('a, 'd, 'b, 'c) Model.local_state) system_state)↓›*) using black_heap_no_greys (*‹⟦no_grey_refs ?s; ∀r. marked r ?s ∨ ¬ obj_at (λs. True) r ?s⟧ ⟹ black_heap ?s›*) by blast qed lemma no_grey_refs_no_marks[simp]: "⟦ no_grey_refs s; valid_W_inv s ⟧ ⟹ ¬sys_mem_store_buffers p s = mw_Mark r fl # ws" unfolding no_grey_refs_def (*goal: ‹⟦∀x. ¬ grey x s; valid_W_inv s⟧ ⟹ sys_mem_store_buffers p s ≠ mw_Mark r fl # ws›*) by (metis greyI( (*‹?r ∈ ghost_honorary_grey (?s ?p) ⟹ grey ?r ?s›*) 1) list.set_intros( (*‹?x21.0 ∈ set (?x21.0 # ?x22.0)›*) 1) valid_W_invE( (*‹⟦mw_Mark ?r ?fl ∈ set (sys_mem_store_buffers ?p ?s); valid_W_inv ?s⟧ ⟹ ?r ∈ ghost_honorary_grey (?s ?p)›*) 5)) (* FIXME suggests redundancy in valid_W_inv rules: by (meson greyI(1) valid_W_invD(1)) *) context sys begin lemma black_heap_dequeue_mark[iff]: "⟦ sys_mem_store_buffers p s = mw_Mark r fl # ws; black_heap s; valid_W_inv s ⟧ ⟹ black_heap (s(sys := s sys⦇heap := (sys_heap s)(r := map_option (obj_mark_update (λ_. fl)) (sys_heap s r)), mem_store_buffers := (mem_store_buffers (s sys))(p := ws)⦈))" unfolding black_heap_def (*goal: ‹⟦sys_mem_store_buffers p s = mw_Mark r fl # ws; ∀x. obj_at (λs. True) x s ⟶ black x s; valid_W_inv s⟧ ⟹ ∀x. obj_at (λs. True) x (s(sys := s sys⦇heap := (sys_heap s)(r := map_option (obj_mark_update (λ_. fl)) (sys_heap s r)), mem_store_buffers := (mem_store_buffers (s sys))(p := ws)⦈)) ⟶ black x (s(sys := s sys⦇heap := (sys_heap s)(r := map_option (obj_mark_update (λ_. fl)) (sys_heap s r)), mem_store_buffers := (mem_store_buffers (s sys))(p := ws)⦈))›*) by (metis colours_distinct( (*‹white ?r ?s ⟹ ¬ black ?r ?s›*) 4) valid_W_invD( (*‹⟦sys_mem_store_buffers ?p ?s = mw_Mark ?r ?fl # ?ws; valid_W_inv ?s⟧ ⟹ ?fl = sys_fM ?s ∧ ?r ∈ ghost_honorary_grey (?s ?p) ∧ sys_mem_lock ?s = Some ?p ∧ white ?r ?s ∧ filter is_mw_Mark ?ws = []›*) 1) white_valid_ref (*‹white ?r ?s ⟹ obj_at (λs. True) ?r ?s›*)) lemma white_heap_dequeue_fM[iff]: "black_heap s↓ ⟹ white_heap (s↓(sys := s↓ sys⦇fM := ¬ sys_fM s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈))" unfolding black_heap_def white_heap_def black_def white_def (*goal: ‹∀x. obj_at (λs. True) x s↓ ⟶ marked x s↓ ∧ ¬ grey x s↓ ⟹ ∀x. obj_at (λs. True) x (s↓(sys := s↓ sys⦇fM := ¬ sys_fM s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈)) ⟶ obj_at (λobj. obj_mark obj ≠ sys_fM (s↓(sys := s↓ sys⦇fM := ¬ sys_fM s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈))) x (s↓(sys := s↓ sys⦇fM := ¬ sys_fM s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈))›*) by clarsimp (* FIXME rules? *) lemma black_heap_dequeue_fM[iff]: "⟦ white_heap s↓; no_grey_refs s↓ ⟧ ⟹ black_heap (s↓(sys := s↓ sys⦇fM := ¬ sys_fM s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈))" unfolding black_heap_def white_heap_def no_grey_refs_def (*goal: ‹⟦∀x. obj_at (λs. True) x s↓ ⟶ white x s↓; ∀x. ¬ grey x s↓⟧ ⟹ ∀x. obj_at (λs. True) x (s↓(sys := s↓ sys⦇fM := ¬ sys_fM s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈)) ⟶ black x (s↓(sys := s↓ sys⦇fM := ¬ sys_fM s↓, mem_store_buffers := (mem_store_buffers (s↓ sys))(gc := ws)⦈))›*) by auto lemma sys_phase_inv[intro]: notes if_split_asm[split del] notes fun_upd_apply[simp] shows "⦃ LSTP (fA_rel_inv ❙∧ fM_rel_inv ❙∧ handshake_phase_inv ❙∧ mutators_phase_inv ❙∧ phase_rel_inv ❙∧ sys_phase_inv ❙∧ tso_store_inv ❙∧ valid_W_inv) ⦄ sys ⦃ LSTP sys_phase_inv ⦄" proof(vcg_jackhammer (no_thin_post_inv) , clarsimp simp: fA_rel_inv_def fM_rel_inv_def p_not_sys , vcg_name_cases) case (tso_dequeue_store_buffer s s' p w ws) then show ?case apply (clarsimp simp: do_store_action_def sys_phase_inv_aux_case split: mem_store_action.splits hs_phase.splits if_splits) apply (clarsimp simp: fA_rel_def fM_rel_def; erule disjE; clarsimp simp: fA_rel_def fM_rel_def)+ apply (metis (mono_tags, lifting) filter.simps(2) list.discI tso_store_invD(4)) apply auto done qed end (*<*) end (*>*)
{ "path": "afp-2025-02-12/thys/ConcurrentGC/Phases.thy", "repo": "afp-2025-02-12", "sha": "6b41b8c9e0546234c6b0ac66d84c124ae9c939ed9d9fd090bdc5148f19b6aff0" }
(* Title: The Calculus of Communicating Systems Author/Maintainer: Jesper Bengtson (jebe@itu.dk), 2012 *) theory Strong_Bisim imports Strong_Sim begin lemma monotonic: fixes P :: ccs and A :: "(ccs × ccs) set" and Q :: ccs and B :: "(ccs × ccs) set" assumes "P ↝[A] Q" and "A ⊆ B" shows "P ↝[B] Q" using assms (*‹P ↝[A] Q› ‹A ⊆ B›*) by (fastforce simp add: simulation_def (*‹?P ↝[?Rel] ?Q ≡ ∀a Q'. ?Q ⟼a ≺ Q' ⟶ (∃P'. ?P ⟼a ≺ P' ∧ (P', Q') ∈ ?Rel)›*)) lemma monoCoinduct: "⋀x y xa xb P Q. x ≤ y ⟹ (Q ↝[{(xb, xa). x xb xa}] P) ⟶ (Q ↝[{(xb, xa). y xb xa}] P)" apply auto (*goal: ‹⋀x y xa xb P Q. x ≤ y ⟹ Q ↝[{(xb, xa). x xb xa}] P ⟶ Q ↝[{(xb, xa). y xb xa}] P›*) apply (rule monotonic (*‹⟦?P ↝[?A] ?Q; ?A ⊆ ?B⟧ ⟹ ?P ↝[?B] ?Q›*)) (*goal: ‹⋀(x::ccs ⇒ ccs ⇒ bool) (y::ccs ⇒ ccs ⇒ bool) (P::ccs) Q::ccs. ⟦x ≤ y; Q ↝[{(xa::ccs, y::ccs). x xa y}] P⟧ ⟹ Q ↝[{(x::ccs, ya::ccs). y x ya}] P›*) by (auto dest: le_funE (*‹⟦?f ≤ ?g; ?f ?x ≤ ?g ?x ⟹ ?P⟧ ⟹ ?P›*)) coinductive_set bisim :: "(ccs × ccs) set" where "⟦P ↝[bisim] Q; (Q, P) ∈ bisim⟧ ⟹ (P, Q) ∈ bisim" monos monoCoinduct abbreviation bisimJudge ("_ ∼ _" [70, 70] 65) where "P ∼ Q ≡ (P, Q) ∈ bisim" lemma bisimCoinductAux[consumes 1]: fixes P :: "ccs" and Q :: "ccs" and X :: "(ccs × ccs) set" assumes "(P, Q) ∈ X" and "⋀P Q. (P, Q) ∈ X ⟹ P ↝[(X ∪ bisim)] Q ∧ (Q, P) ∈ X" shows "P ∼ Q" proof (-) (*goal: ‹P ∼ Q›*) have "X ∪ bisim = {(P, Q). (P, Q) ∈ X ∨ (P, Q) ∈ bisim}" by auto with assms (*‹(P::ccs, Q::ccs) ∈ (X::(ccs × ccs) set)› ‹(?P, ?Q) ∈ X ⟹ ?P ↝[(X ∪ bisim)] ?Q ∧ (?Q, ?P) ∈ X›*) show "?thesis" (*goal: ‹P ∼ Q›*) apply coinduct (*goal: ‹P ∼ Q›*) by simp qed lemma bisimCoinduct[consumes 1, case_names cSim cSym]: fixes P :: "ccs" and Q :: "ccs" and X :: "(ccs × ccs) set" assumes "(P, Q) ∈ X" and "⋀R S. (R, S) ∈ X ⟹ R ↝[(X ∪ bisim)] S" and "⋀R S. (R, S) ∈ X ⟹ (S, R) ∈ X" shows "P ∼ Q" proof (-) (*goal: ‹P ∼ Q›*) have "X ∪ bisim = {(P, Q). (P, Q) ∈ X ∨ (P, Q) ∈ bisim}" by auto with assms (*‹(P, Q) ∈ X› ‹(?R, ?S) ∈ X ⟹ ?R ↝[(X ∪ bisim)] ?S› ‹(?R, ?S) ∈ X ⟹ (?S, ?R) ∈ X›*) show "?thesis" (*goal: ‹P ∼ Q›*) apply coinduct (*goal: ‹P ∼ Q›*) by simp qed lemma bisimWeakCoinductAux[consumes 1]: fixes P :: "ccs" and Q :: "ccs" and X :: "(ccs × ccs) set" assumes "(P, Q) ∈ X" and "⋀R S. (R, S) ∈ X ⟹ R ↝[X] S ∧ (S, R) ∈ X" shows "P ∼ Q" using assms (*‹(P, Q) ∈ X› ‹(?R::ccs, ?S::ccs) ∈ (X::(ccs × ccs) set) ⟹ ?R ↝[X] ?S ∧ (?S, ?R) ∈ X›*) apply (coinduct rule: bisimCoinductAux) (*goal: ‹(P::ccs) ∼ (Q::ccs)›*) by (blast intro: monotonic (*‹⟦?P ↝[?A] ?Q; ?A ⊆ ?B⟧ ⟹ ?P ↝[?B] ?Q›*)) lemma bisimWeakCoinduct[consumes 1, case_names cSim cSym]: fixes P :: "ccs" and Q :: "ccs" and X :: "(ccs × ccs) set" assumes "(P, Q) ∈ X" and "⋀P Q. (P, Q) ∈ X ⟹ P ↝[X] Q" and "⋀P Q. (P, Q) ∈ X ⟹ (Q, P) ∈ X" shows "P ∼ Q" proof (-) (*goal: ‹P ∼ Q›*) have "X ∪ bisim = {(P, Q). (P, Q) ∈ X ∨ (P, Q) ∈ bisim}" by auto with assms (*‹(P::ccs, Q::ccs) ∈ (X::(ccs × ccs) set)› ‹(?P::ccs, ?Q::ccs) ∈ (X::(ccs × ccs) set) ⟹ ?P ↝[X] ?Q› ‹(?P, ?Q) ∈ X ⟹ (?Q, ?P) ∈ X›*) show "?thesis" (*goal: ‹P ∼ Q›*) apply (coinduct rule: bisimCoinduct) (*goals: 1. ‹⋀R S. ⟦⋀P Q. (P, Q) ∈ X ⟹ P ↝[X] Q; ⋀P Q. (P, Q) ∈ X ⟹ (Q, P) ∈ X; X ∪ bisim = {(P, Q). (P, Q) ∈ X ∨ P ∼ Q}; (R, S) ∈ X⟧ ⟹ R ↝[(X ∪ bisim)] S› 2. ‹⋀R S. ⟦⋀P Q. (P, Q) ∈ X ⟹ P ↝[X] Q; ⋀P Q. (P, Q) ∈ X ⟹ (Q, P) ∈ X; X ∪ bisim = {(P, Q). (P, Q) ∈ X ∨ P ∼ Q}; (R, S) ∈ X⟧ ⟹ (S, R) ∈ X› discuss goal 1*) apply (blast intro: monotonic (*‹⟦?P ↝[?A] ?Q; ?A ⊆ ?B⟧ ⟹ ?P ↝[?B] ?Q›*)) (*discuss goal 2*) apply (blast intro: monotonic (*‹⟦(?P::ccs) ↝[(?A::(ccs × ccs) set)] (?Q::ccs); ?A ⊆ (?B::(ccs × ccs) set)⟧ ⟹ ?P ↝[?B] ?Q›*)) (*proven 2 subgoals*) . qed lemma bisimE: fixes P :: "ccs" and Q :: "ccs" assumes "P ∼ Q" shows "P ↝[bisim] Q" and "Q ∼ P" using assms (*‹P ∼ Q›*) apply - (*goals: 1. ‹P ∼ Q ⟹ P ↝[bisim] Q› 2. ‹P ∼ Q ⟹ Q ∼ P› discuss goal 1*) apply ((auto simp add: intro: bisim.cases (*‹⟦?a1.0 ∼ ?a2.0; ⋀P Q. ⟦?a1.0 = P; ?a2.0 = Q; P ↝[bisim] Q; Q ∼ P⟧ ⟹ ?P⟧ ⟹ ?P›*))[1]) (*discuss goal 2*) apply ((auto simp add: intro: bisim.cases (*‹⟦?a1.0 ∼ ?a2.0; ⋀P Q. ⟦?a1.0 = P; ?a2.0 = Q; P ↝[bisim] Q; Q ∼ P⟧ ⟹ ?P⟧ ⟹ ?P›*))[1]) (*proven 2 subgoals*) . lemma bisimI: fixes P :: "ccs" and Q :: "ccs" assumes "P ↝[bisim] Q" and "Q ∼ P" shows "P ∼ Q" using assms (*‹P ↝[bisim] Q› ‹(Q::ccs) ∼ (P::ccs)›*) by (auto intro: bisim.intros (*‹⟦?P ↝[bisim] ?Q; ?Q ∼ ?P⟧ ⟹ ?P ∼ ?Q›*)) lemma reflexive: fixes P :: ccs shows "P ∼ P" proof (-) (*goal: ‹P ∼ P›*) have "(P, P) ∈ Id" by blast thus "?thesis" (*goal: ‹P ∼ P›*) apply (coinduct rule: bisimCoinduct) (*goals: 1. ‹⋀R S. (R, S) ∈ Id ⟹ R ↝[(Id ∪ bisim)] S› 2. ‹⋀R S. (R, S) ∈ Id ⟹ (S, R) ∈ Id› discuss goal 1*) apply ((auto intro: reflexive (*‹Id ⊆ ?Rel ⟹ ?P ↝[?Rel] ?P›*))[1]) (*discuss goal 2*) apply ((auto intro: reflexive (*‹Id ⊆ ?Rel ⟹ ?P ↝[?Rel] ?P›*))[1]) (*proven 2 subgoals*) . qed lemma symmetric: fixes P :: ccs and Q :: ccs assumes "P ∼ Q" shows "Q ∼ P" using assms (*‹P ∼ Q›*) by (rule bisimE (*‹?P ∼ ?Q ⟹ ?P ↝[bisim] ?Q› ‹?P ∼ ?Q ⟹ ?Q ∼ ?P›*)) lemma transitive: fixes P :: ccs and Q :: ccs and R :: ccs assumes "P ∼ Q" and "Q ∼ R" shows "P ∼ R" proof (-) (*goal: ‹P ∼ R›*) from assms (*‹P ∼ Q› ‹Q ∼ R›*) have "(P, R) ∈ bisim O bisim" by auto thus "?thesis" (*goal: ‹P ∼ R›*) apply (coinduct rule: bisimCoinduct) (*goals: 1. ‹⋀R S. (R, S) ∈ bisim O bisim ⟹ R ↝[(bisim O bisim ∪ bisim)] S› 2. ‹⋀R S. (R, S) ∈ bisim O bisim ⟹ (S, R) ∈ bisim O bisim› discuss goal 1*) apply ((auto intro: transitive (*‹⟦(?P::ccs) ↝[(?Rel::(ccs × ccs) set)] (?Q::ccs); ?Q ↝[(?Rel'::(ccs × ccs) set)] (?R::ccs); ?Rel O ?Rel' ⊆ (?Rel''::(ccs × ccs) set)⟧ ⟹ ?P ↝[?Rel''] ?R›*) dest: bisimE (*‹(?P::ccs) ∼ (?Q::ccs) ⟹ ?P ↝[bisim] ?Q› ‹(?P::ccs) ∼ (?Q::ccs) ⟹ ?Q ∼ ?P›*))[1]) (*discuss goal 2*) apply ((auto intro: transitive (*‹⟦?P ↝[?Rel] ?Q; ?Q ↝[?Rel'] ?R; ?Rel O ?Rel' ⊆ ?Rel''⟧ ⟹ ?P ↝[?Rel''] ?R›*) dest: bisimE (*‹?P ∼ ?Q ⟹ ?P ↝[bisim] ?Q› ‹?P ∼ ?Q ⟹ ?Q ∼ ?P›*))[1]) (*proven 2 subgoals*) . qed lemma bisimTransCoinduct[consumes 1, case_names cSim cSym]: fixes P :: ccs and Q :: ccs assumes "(P, Q) ∈ X" and rSim: "⋀R S. (R, S) ∈ X ⟹ R ↝[(bisim O X O bisim)] S" and rSym: "⋀R S. (R, S) ∈ X ⟹ (S, R) ∈ X" shows "P ∼ Q" proof (-) (*goal: ‹P ∼ Q›*) from ‹(P, Q) ∈ X› (*‹(P, Q) ∈ X›*) have "(P, Q) ∈ bisim O X O bisim" by (auto intro: reflexive (*‹?P ∼ ?P›*)) thus "?thesis" (*goal: ‹P ∼ Q›*) proof (coinduct rule: bisimWeakCoinduct) (*goals: 1. ‹⋀P Q. (P, Q) ∈ bisim O X O bisim ⟹ P ↝[(bisim O X O bisim)] Q› 2. ‹⋀P Q. (P, Q) ∈ bisim O X O bisim ⟹ (Q, P) ∈ bisim O X O bisim›*) case (cSim P Q) (*‹(P, Q) ∈ bisim O X O bisim›*) from ‹(P, Q) ∈ bisim O X O bisim› (*‹(P, Q) ∈ bisim O X O bisim›*) obtain R and S where "P ∼ R" and "(R, S) ∈ X" and "S ∼ Q" (*goal: ‹(⋀R S. ⟦P ∼ R; (R, S) ∈ X; S ∼ Q⟧ ⟹ thesis) ⟹ thesis›*) by auto from ‹P ∼ R› (*‹P ∼ R›*) have "P ↝[bisim] R" by (rule bisimE (*‹?P ∼ ?Q ⟹ ?P ↝[bisim] ?Q› ‹?P ∼ ?Q ⟹ ?Q ∼ ?P›*)) moreover from ‹(R, S) ∈ X› (*‹(R, S) ∈ X›*) have "R ↝[(bisim O X O bisim)] S" by (rule rSim (*‹(?R, ?S) ∈ X ⟹ ?R ↝[(bisim O X O bisim)] ?S›*)) moreover have "bisim O (bisim O X O bisim) ⊆ bisim O X O bisim" by (auto intro: transitive (*‹⟦?P ∼ ?Q; ?Q ∼ ?R⟧ ⟹ ?P ∼ ?R›*)) ultimately have "P ↝[(bisim O X O bisim)] S" by (rule Strong_Sim.transitive (*‹⟦?P ↝[?Rel] ?Q; ?Q ↝[?Rel'] ?R; ?Rel O ?Rel' ⊆ ?Rel''⟧ ⟹ ?P ↝[?Rel''] ?R›*)) moreover from ‹S ∼ Q› (*‹S ∼ Q›*) have "S ↝[bisim] Q" by (rule bisimE (*‹?P ∼ ?Q ⟹ ?P ↝[bisim] ?Q› ‹?P ∼ ?Q ⟹ ?Q ∼ ?P›*)) moreover have "(bisim O X O bisim) O bisim ⊆ bisim O X O bisim" by (auto intro: transitive (*‹⟦(?P::ccs) ∼ (?Q::ccs); ?Q ∼ (?R::ccs)⟧ ⟹ ?P ∼ ?R›*)) ultimately show "?case" (*goal: ‹P ↝[(bisim O X O bisim)] Q›*) by (rule Strong_Sim.transitive (*‹⟦?P ↝[?Rel] ?Q; ?Q ↝[?Rel'] ?R; ?Rel O ?Rel' ⊆ ?Rel''⟧ ⟹ ?P ↝[?Rel''] ?R›*)) next (*goal: ‹⋀P Q. (P, Q) ∈ bisim O X O bisim ⟹ (Q, P) ∈ bisim O X O bisim›*) case (cSym P Q) (*‹(P, Q) ∈ bisim O X O bisim›*) thus "?case" (*goal: ‹(Q, P) ∈ bisim O X O bisim›*) by (auto dest: symmetric (*‹?P ∼ ?Q ⟹ ?Q ∼ ?P›*) rSym (*‹(?R, ?S) ∈ X ⟹ (?S, ?R) ∈ X›*)) qed qed end
{ "path": "afp-2025-02-12/thys/CCS/Strong_Bisim.thy", "repo": "afp-2025-02-12", "sha": "c4dfbeef3e8dd843e71499f205988a41ec0dc6405de4fc61d9c9dc5d1aff9cc0" }
(* Title: Map Function on Two Parallel Lists Author: Anders Schlichtkrull <andschl at dtu.dk>, 2017 Maintainer: Anders Schlichtkrull <andschl at dtu.dk> *) section ‹Map Function on Two Parallel Lists› theory Map2 imports Main begin text ‹ This theory defines a map function that applies a (curried) binary function elementwise to two parallel lists. The definition is taken from @{url "https://www.isa-afp.org/browser_info/current/AFP/Jinja/Listn.html"}. › abbreviation map2 :: "('a ⇒ 'b ⇒ 'c) ⇒ 'a list ⇒ 'b list ⇒ 'c list" where "map2 f xs ys ≡ map (case_prod f) (zip xs ys)" lemma map2_empty_iff[simp]: "map2 f xs ys = [] ⟷ xs = [] ∨ ys = []" by (metis Nil_is_map_conv (*‹([] = map ?f ?xs) = (?xs = [])›*) list.exhaust (*‹⟦?y = [] ⟹ ?P; ⋀x21 x22. ?y = x21 # x22 ⟹ ?P⟧ ⟹ ?P›*) list.simps( (*‹?x21.0 # ?x22.0 ≠ []›*) 3) zip.simps( (*‹zip ?xs [] = []›*) 1) zip_Cons_Cons (*‹zip (?x # ?xs) (?y # ?ys) = (?x, ?y) # zip ?xs ?ys›*) zip_Nil (*‹zip [] ?ys = []›*)) lemma image_map2: "length t = length s ⟹ g ` set (map2 f t s) = set (map2 (λa b. g (f a b)) t s)" by auto lemma map2_tl: "length t = length s ⟹ map2 f (tl t) (tl s) = tl (map2 f t s)" by (metis (no_types, lifting) hd_Cons_tl (*‹?xs ≠ [] ⟹ hd ?xs # tl ?xs = ?xs›*) list.sel( (*‹tl (?x21.0 # ?x22.0) = ?x22.0›*) 3) map2_empty_iff (*‹(Map2.map2 ?f ?xs ?ys = []) = (?xs = [] ∨ ?ys = [])›*) map_tl (*‹map ?f (tl ?xs) = tl (map ?f ?xs)›*) tl_Nil (*‹(tl ?xs = []) = (?xs = [] ∨ (∃x. ?xs = [x]))›*) zip_Cons_Cons (*‹zip (?x # ?xs) (?y # ?ys) = (?x, ?y) # zip ?xs ?ys›*)) lemma map_zip_assoc: "map f (zip (zip xs ys) zs) = map (λ(x, y, z). f ((x, y), z)) (zip xs (zip ys zs))" apply (induct zs arbitrary: xs ys) (*goals: 1. ‹⋀xs ys. map f (zip (zip xs ys) []) = Map2.map2 (λx (y, z). f ((x, y), z)) xs (zip ys [])› 2. ‹⋀a zs xs ys. (⋀xs ys. map f (zip (zip xs ys) zs) = Map2.map2 (λx (y, z). f ((x, y), z)) xs (zip ys zs)) ⟹ map f (zip (zip xs ys) (a # zs)) = Map2.map2 (λx (y, z). f ((x, y), z)) xs (zip ys (a # zs))› discuss goal 1*) apply ((auto simp add: zip.simps( (*‹zip (?xs::?'a::type list) ((?y::?'b::type) # (?ys::?'b::type list)) = (case ?xs of [] ⇒ [] | (z::?'a::type) # (zs::?'a::type list) ⇒ (z, ?y) # zip zs ?ys)›*) 2) split: list.splits (*‹(?P::?'b::type ⇒ bool) (case ?list::?'a::type list of [] ⇒ ?f1.0::?'b::type | (x::?'a::type) # (xa::?'a::type list) ⇒ (?f2.0::?'a::type ⇒ ?'a::type list ⇒ ?'b::type) x xa) = ((?list = [] ⟶ ?P ?f1.0) ∧ (∀(x21::?'a::type) x22::?'a::type list. ?list = x21 # x22 ⟶ ?P (?f2.0 x21 x22)))› ‹(?P::?'b::type ⇒ bool) (case ?list::?'a::type list of [] ⇒ ?f1.0::?'b::type | (x::?'a::type) # (xa::?'a::type list) ⇒ (?f2.0::?'a::type ⇒ ?'a::type list ⇒ ?'b::type) x xa) = (¬ (?list = [] ∧ ¬ ?P ?f1.0 ∨ (∃(x21::?'a::type) x22::?'a::type list. ?list = x21 # x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*))[1]) (*discuss goal 2*) apply ((auto simp add: zip.simps( (*‹zip (?xs::?'a list) ((?y::?'b) # (?ys::?'b list)) = (case ?xs of [] ⇒ [] | (z::?'a) # (zs::?'a list) ⇒ (z, ?y) # zip zs ?ys)›*) 2) split: list.splits (*‹(?P::?'b ⇒ bool) (case ?list::?'a list of [] ⇒ ?f1.0::?'b | (x::?'a) # (xa::?'a list) ⇒ (?f2.0::?'a ⇒ ?'a list ⇒ ?'b) x xa) = ((?list = [] ⟶ ?P ?f1.0) ∧ (∀(x21::?'a) x22::?'a list. ?list = x21 # x22 ⟶ ?P (?f2.0 x21 x22)))› ‹(?P::?'b ⇒ bool) (case ?list::?'a list of [] ⇒ ?f1.0::?'b | (x::?'a) # (xa::?'a list) ⇒ (?f2.0::?'a ⇒ ?'a list ⇒ ?'b) x xa) = (¬ (?list = [] ∧ ¬ ?P ?f1.0 ∨ (∃(x21::?'a) x22::?'a list. ?list = x21 # x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*))[1]) (*proven 2 subgoals*) . lemma set_map2_ex: assumes "length t = length s" shows "set (map2 f s t) = {x. ∃i < length t. x = f (s ! i) (t ! i)}" proof (rule; rule) (*goals: 1. ‹⋀x. x ∈ set (Map2.map2 f s t) ⟹ x ∈ {x. ∃i<length t. x = f (s ! i) (t ! i)}› 2. ‹⋀x. x ∈ {x. ∃i<length t. x = f (s ! i) (t ! i)} ⟹ x ∈ set (Map2.map2 f s t)›*) fix x assume "x ∈ set (map2 f s t)" (*‹(x::'c) ∈ set (Map2.map2 (f::'b ⇒ 'a ⇒ 'c) (s::'b list) (t::'a list))›*) then obtain i where i_p: "i < length (map2 f s t) ∧ x = map2 f s t ! i" (*goal: ‹(⋀i. i < length (Map2.map2 f s t) ∧ x = Map2.map2 f s t ! i ⟹ thesis) ⟹ thesis›*) by (metis in_set_conv_nth (*‹(?x ∈ set ?xs) = (∃i<length ?xs. ?xs ! i = ?x)›*)) from i_p (*‹i < length (Map2.map2 f s t) ∧ x = Map2.map2 f s t ! i›*) have "i < length t" by auto moreover from this (*‹(i::nat) < length (t::'a::type list)›*) i_p (*‹i < length (Map2.map2 f s t) ∧ x = Map2.map2 f s t ! i›*) have "x = f (s ! i) (t ! i)" using assms (*‹length (t::'a::type list) = length (s::'b::type list)›*) by auto ultimately show "x ∈ {x. ∃i < length t. x = f (s ! i) (t ! i)}" using assms (*‹length t = length s›*) by auto next (*goal: ‹⋀x. x ∈ {x. ∃i<length t. x = f (s ! i) (t ! i)} ⟹ x ∈ set (Map2.map2 f s t)›*) fix x assume "x ∈ {x. ∃i < length t. x = f (s ! i) (t ! i)}" (*‹(x::'c) ∈ {x::'c. ∃i<length (t::'a list). x = (f::'b ⇒ 'a ⇒ 'c) ((s::'b list) ! i) (t ! i)}›*) then obtain i where i_p: "i < length t ∧ x = f (s ! i) (t ! i)" (*goal: ‹(⋀i::nat. i < length (t::'a list) ∧ (x::'c) = (f::'b ⇒ 'a ⇒ 'c) ((s::'b list) ! i) (t ! i) ⟹ thesis::bool) ⟹ thesis›*) by auto then have "i < length (map2 f s t)" using assms (*‹length t = length s›*) by auto moreover from i_p (*‹(i::nat) < length (t::'a list) ∧ (x::'c) = (f::'b ⇒ 'a ⇒ 'c) ((s::'b list) ! i) (t ! i)›*) have "x = map2 f s t ! i" using assms (*‹length (t::'a list) = length (s::'b list)›*) by auto ultimately show "x ∈ set (map2 f s t)" by (metis in_set_conv_nth (*‹(?x ∈ set ?xs) = (∃i<length ?xs. ?xs ! i = ?x)›*)) qed end
{ "path": "afp-2025-02-12/thys/Ordered_Resolution_Prover/Map2.thy", "repo": "afp-2025-02-12", "sha": "559a1a66db962fd6d0cfc5fbf4348ebf7a18cd04e6a4df59bb173650ceaaf10f" }
(*<*) theory Infinite_Proof_Soundness imports Finite_Proof_Soundness "HOL-Library.BNF_Corec" begin (* Reference: A Generic Cyclic Theorem Prover by James Brotherston, Nikos Gorogiannis, and Rasmus L. Petersen *) (*>*) section ‹Soundness of Infinite Proof Trees› context begin private definition "num P xs ≡ LEAST n. list_all (Not o P) (stake n xs) ∧ P (xs!!n)" private lemma num: assumes ev: "ev (λxs. P (shd xs)) xs" defines "n ≡ num P xs" shows "(list_all (Not o P) (stake n xs) ∧ P (xs!!n)) ∧ (∀m. list_all (Not o P) (stake m xs) ∧ P (xs!!m) ⟶ n ≤ m)" unfolding n_def num_def (*goal: ‹(list_all (Not ∘ P) (stake (LEAST n. list_all (Not ∘ P) (stake n xs) ∧ P (xs !! n)) xs) ∧ P (xs !! (LEAST n. list_all (Not ∘ P) (stake n xs) ∧ P (xs !! n)))) ∧ (∀m. list_all (Not ∘ P) (stake m xs) ∧ P (xs !! m) ⟶ (LEAST n. list_all (Not ∘ P) (stake n xs) ∧ P (xs !! n)) ≤ m)›*) proof (intro conjI[OF LeastI_ex] (*‹⟦∃x. ?P1 x; ?Q⟧ ⟹ ?P1 (Least ?P1) ∧ ?Q›*) allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*) impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*) Least_le (*‹?P ?k ⟹ (LEAST x. ?P x) ≤ ?k›*)) (*goals: 1. ‹∃x. list_all (Not ∘ P) (stake x xs) ∧ P (xs !! x)› 2. ‹⋀m. list_all (Not ∘ P) (stake m xs) ∧ P (xs !! m) ⟹ ∃x. list_all (Not ∘ P) (stake m xs)› 3. ‹⋀m. list_all (Not ∘ P) (stake m xs) ∧ P (xs !! m) ⟹ P (xs !! m)›*) from ev (*‹ev (λxs. P (shd xs)) xs›*) show "∃n. list_all (Not o P) (stake n xs) ∧ P (xs !! n)" apply (induct rule: ev_induct_strong (*‹⟦ev ?φ ?x; ⋀xs. ?φ xs ⟹ ?P xs; ⋀xs. ⟦ev ?φ (stl xs); ¬ ?φ xs; ?P (stl xs)⟧ ⟹ ?P xs⟧ ⟹ ?P ?x›*)) (*goals: 1. ‹⋀xs. P (shd xs) ⟹ ∃n. list_all (Not ∘ P) (stake n xs) ∧ P (xs !! n)› 2. ‹⋀xs. ⟦ev (λxs. P (shd xs)) (stl xs); ¬ P (shd xs); ∃n. list_all (Not ∘ P) (stake n (stl xs)) ∧ P (stl xs !! n)⟧ ⟹ ∃n. list_all (Not ∘ P) (stake n xs) ∧ P (xs !! n)› discuss goal 1*) apply ((auto intro: exI[of _ 0] (*‹?P 0 ⟹ ∃x. ?P x›*) exI[of _ "Suc _"] (*‹?P (Suc ?uu4) ⟹ ∃x. ?P x›*))[1]) (*discuss goal 2*) apply ((auto intro: exI[of _ 0] (*‹?P 0 ⟹ ∃x. ?P x›*) exI[of _ "Suc _"] (*‹?P (Suc ?uu4) ⟹ ∃x. ?P x›*))[1]) (*proven 2 subgoals*) . qed (simp_all add: o_def) (*solves the remaining goals: 1. ‹⋀m. list_all (Not ∘ P) (stake m xs) ∧ P (xs !! m) ⟹ ∃x. list_all (Not ∘ P) (stake m xs)› 2. ‹⋀m. list_all (Not ∘ P) (stake m xs) ∧ P (xs !! m) ⟹ P (xs !! m)›*) private lemma num_stl[simp]: assumes "ev (λxs. P (shd xs)) xs" and "¬ P (shd xs)" shows "num P xs = Suc (num P (stl xs))" unfolding num_def (*goal: ‹(LEAST n. list_all (Not ∘ P) (stake n xs) ∧ P (xs !! n)) = Suc (LEAST n. list_all (Not ∘ P) (stake n (stl xs)) ∧ P (stl xs !! n))›*) apply (rule trans[OF Least_Suc[of _ "num P xs"]] (*‹⟦?P1 (num P xs); ¬ ?P1 0; Suc (LEAST m. ?P1 (Suc m)) = ?t⟧ ⟹ (LEAST n. ?P1 n) = ?t›*)) (*goals: 1. ‹list_all (Not ∘ P) (stake (num P xs) xs) ∧ P (xs !! num P xs)› 2. ‹¬ (list_all (Not ∘ P) (stake 0 xs) ∧ P (xs !! 0))› 3. ‹Suc (LEAST m. list_all (Not ∘ P) (stake (Suc m) xs) ∧ P (xs !! Suc m)) = Suc (LEAST n. list_all (Not ∘ P) (stake n (stl xs)) ∧ P (stl xs !! n))› discuss goal 1*) apply ((auto simp: num[OF assms(1)] (*‹(list_all (Not ∘ P) (stake (num P xs) xs) ∧ P (xs !! num P xs)) ∧ (∀m. list_all (Not ∘ P) (stake m xs) ∧ P (xs !! m) ⟶ num P xs ≤ m)›*) assms( (*‹¬ P (shd xs)›*) 2))[1]) (*discuss goal 2*) apply ((auto simp: num[OF assms(1)] (*‹(list_all (Not ∘ (P::'a ⇒ bool)) (stake (num P (xs::'a stream)) xs) ∧ P (xs !! num P xs)) ∧ (∀m::nat. list_all (Not ∘ P) (stake m xs) ∧ P (xs !! m) ⟶ num P xs ≤ m)›*) assms( (*‹¬ (P::'a ⇒ bool) (shd (xs::'a stream))›*) 2))[1]) (*discuss goal 3*) apply ((auto simp: num[OF assms(1)] (*‹(list_all (Not ∘ P) (stake (num P xs) xs) ∧ P (xs !! num P xs)) ∧ (∀m. list_all (Not ∘ P) (stake m xs) ∧ P (xs !! m) ⟶ num P xs ≤ m)›*) assms( (*‹¬ P (shd xs)›*) 2))[1]) (*proven 3 subgoals*) . corecursive decr0 where "decr0 Ord minSoFar js = (if ¬ (ev (λjs. (shd js, minSoFar) ∈ Ord ∧ shd js ≠ minSoFar)) js then undefined else if ((shd js, minSoFar) ∈ Ord ∧ shd js ≠ minSoFar) then shd js ## decr0 Ord (shd js) js else decr0 Ord minSoFar (stl js))" by (relation "measure (λ(Ord,m,js). num (λj. (j, m) ∈ Ord ∧ j ≠ m) js)") auto end lemmas well_order_on_defs = well_order_on_def linear_order_on_def partial_order_on_def preorder_on_def trans_def antisym_def refl_on_def lemma sdrop_length_shift[simp]: "sdrop (length xs) (xs @- s) = s" by (simp add: sdrop_shift (*‹sdrop ?i (?w @- ?s) = drop ?i ?w @- sdrop (?i - length ?w) ?s›*)) lemma ev_iff_shift: "ev φ xs ⟷ (∃xl xs2. xs = xl @- xs2 ∧ φ xs2)" by (meson ev.base (*‹?φ ?xs ⟹ ev ?φ ?xs›*) ev_imp_shift (*‹ev ?φ ?xs ⟹ ∃xl xs2. ?xs = xl @- xs2 ∧ ?φ xs2›*) ev_shift (*‹ev ?φ ?xs ⟹ ev ?φ (?xl @- ?xs)›*)) locale Infinite_Soundness = RuleSystem_Defs eff rules for eff :: "'rule ⇒ 'sequent ⇒ 'sequent fset ⇒ bool" and rules :: "'rule stream" + fixes "structure" :: "'structure set" and sat :: "'structure ⇒ 'sequent ⇒ bool" and δ :: "'sequent ⇒ 'rule ⇒ 'sequent ⇒ ('marker × bool × 'marker) set" and Ord :: "'ord rel" and σ :: "'marker × 'structure ⇒ 'ord" assumes Ord: "well_order Ord" and descent: (* The original paper has an error in stating this: quantifies existentially instead of universally over r *) "⋀r s sl S. ⟦r ∈ R; eff r s sl; S ∈ structure; ¬ sat S s⟧ ⟹ ∃s' S'. s' |∈| sl ∧ S' ∈ structure ∧ ¬ sat S' s' ∧ (∀v v' b. (v,b,v') ∈ δ s r s' ⟶ (σ(v',S'), σ(v,S)) ∈ Ord ∧ (b ⟶ σ(v',S') ≠ σ(v,S)))" (* The descent property subsumes local_soundness: *) sublocale Infinite_Soundness < Soundness where eff = eff and rules = rules and "structure" = "structure" and sat = sat apply standard (*goal: ‹Soundness eff rules structure sat›*) by (blast dest: descent (*‹⟦?r ∈ R; eff ?r ?s ?sl; ?S ∈ structure; ¬ sat ?S ?s⟧ ⟹ ∃s' S'. s' |∈| ?sl ∧ S' ∈ structure ∧ ¬ sat S' s' ∧ (∀v v' b. (v, b, v') ∈ δ ?s ?r s' ⟶ (σ (v', S'), σ (v, ?S)) ∈ Ord ∧ (b ⟶ σ (v', S') ≠ σ (v, ?S)))›*)) context Infinite_Soundness begin (* The notion of a trace of markers following a path: to make the original paper definition into a rigorous one, we include the trace of "progressing bits" as well: *) coinductive follow :: "bool stream ⇒ 'marker stream ⇒ ('sequent,'rule)step stream ⇒ bool" where "⟦M' = shd Ms; s' = fst (shd steps); (M,b,M') ∈ δ s r s'; follow bs Ms steps⟧ ⟹ follow (SCons b bs) (SCons M Ms) (SCons (s,r) steps)" (* Now infinite progress simply means "always eventually the bit is True": *) definition infDecr :: "bool stream ⇒ bool" where "infDecr ≡ alw (ev (λbs. shd bs))" (* Good trees: *) definition good :: "('sequent,'rule)dtree ⇒ bool" where "good t ≡ ∀steps. ipath t steps ⟶ ev (λsteps'. ∃bs Ms. follow bs Ms steps' ∧ infDecr bs) steps" (* Note the mixture of temporal connectives and standard HOL quantifiers: an advantage of the shallow embedding of LTL *) (* Trivially, finite trees are particular cases of good trees, since they have no infinite paths: *) lemma tfinite_good: "tfinite t ⟹ good t" using ftree_no_ipath (*‹tfinite ?t ⟹ ¬ ipath ?t ?steps›*) unfolding good_def (*goal: ‹tfinite (t::('sequent × 'rule) tree) ⟹ ∀steps::('sequent × 'rule) stream. ipath t steps ⟶ ev (λsteps'::('sequent × 'rule) stream. ∃(bs::bool stream) Ms::'marker stream. follow bs Ms steps' ∧ infDecr bs) steps›*) by auto context fixes inv :: "'sequent × 'a ⇒ bool" and pred :: "'sequent × 'a ⇒ 'rule ⇒ 'sequent × 'a ⇒ bool" begin primcorec konigDtree :: "('sequent,'rule) dtree ⇒ 'a ⇒ (('sequent,'rule) step × 'a) stream" where "shd (konigDtree t a) = (root t, a)" |"stl (konigDtree t a) = (let s = fst (root t); r = snd (root t); (s',a') = (SOME (s',a'). s' |∈| fimage (fst o root) (cont t) ∧ pred (s,a) r (s',a') ∧ inv (s',a')); t' = (SOME t'. t' |∈| cont t ∧ s' = fst (root t')) in konigDtree t' a' )" lemma stl_konigDtree: fixes t defines "s ≡ fst (root t)" and "r ≡ snd (root t)" assumes s': "s' |∈| fimage (fst o root) (cont t)" and "pred (s,a) r (s',a'')" and "inv (s',a'')" shows "∃t' a'. t' |∈| cont t ∧ pred (s,a) r (fst (root t'),a') ∧ inv (fst (root t'),a') ∧ stl (konigDtree t a) = konigDtree t' a'" proof (-) (*goal: ‹∃t' a'. t' |∈| cont t ∧ pred (s, a) r (fst (tree.root t'), a') ∧ inv (fst (tree.root t'), a') ∧ stl (konigDtree t a) = konigDtree t' a'›*) define P where "P ≡ λ(s',a'). s' |∈| fimage (fst o root) (cont t) ∧ pred (s,a) r (s',a') ∧ inv (s',a')" define s'a' where "s'a' ≡ SOME (s',a'). P (s',a')" let ?s' = "fst s'a'" let ?a' = "snd s'a'" define t' where "t' ≡ SOME (t'::('sequent,'rule)dtree). t' |∈| cont t ∧ ?s' = fst (root t')" have "P (s',a'')" using assms (*‹s ≡ fst (tree.root t)› ‹r ≡ snd (tree.root t)› ‹s' |∈| (fst ∘ tree.root) |`| cont t› ‹pred (s, a) r (s', a'')› ‹inv (s', a'')›*) unfolding P_def (*goal: ‹case (s'::'sequent, a''::'a) of (s'::'sequent, a'::'a) ⇒ s' |∈| (fst ∘ tree.root) |`| cont (t::('sequent × 'rule) tree) ∧ (pred::'sequent × 'a ⇒ 'rule ⇒ 'sequent × 'a ⇒ bool) (s::'sequent, a::'a) (r::'rule) (s', a') ∧ (inv::'sequent × 'a ⇒ bool) (s', a')›*) by auto hence P: "P (?s',?a')" using someI[of P] (*‹(P::'sequent × 'a ⇒ bool) (?x::'sequent × 'a) ⟹ P (Eps P)›*) unfolding s'a'_def (*goal: ‹P (fst (SOME (s', a'). P (s', a')), snd (SOME (s', a'). P (s', a')))›*) by auto hence "∃t'. t' |∈| cont t ∧ ?s' = fst (root t')" unfolding P_def (*goal: ‹∃t'::('sequent × 'rule) tree. t' |∈| cont (t::('sequent × 'rule) tree) ∧ fst (s'a'::'sequent × 'a) = fst (tree.root t')›*) by auto hence t': "t' |∈| cont t" and s': "?s' = fst (root t')" using someI_ex[of "λt'. t' |∈| cont t ∧ ?s' = fst (root t')"] (*‹∃x. x |∈| cont t ∧ fst s'a' = fst (tree.root x) ⟹ (SOME x. x |∈| cont t ∧ fst s'a' = fst (tree.root x)) |∈| cont t ∧ fst s'a' = fst (tree.root (SOME x. x |∈| cont t ∧ fst s'a' = fst (tree.root x)))›*) unfolding t'_def (*goals: 1. ‹(SOME t'. t' |∈| cont t ∧ fst s'a' = fst (tree.root t')) |∈| cont t› 2. ‹fst s'a' = fst (tree.root (SOME t'. t' |∈| cont t ∧ fst s'a' = fst (tree.root t')))›*) apply - (*goals: 1. ‹⟦∃t'::('sequent × 'rule) tree. t' |∈| cont (t::('sequent × 'rule) tree) ∧ fst (s'a'::'sequent × 'a) = fst (tree.root t'); ∃x::('sequent × 'rule) tree. x |∈| cont t ∧ fst s'a' = fst (tree.root x) ⟹ (SOME x::('sequent × 'rule) tree. x |∈| cont t ∧ fst s'a' = fst (tree.root x)) |∈| cont t ∧ fst s'a' = fst (tree.root (SOME x::('sequent × 'rule) tree. x |∈| cont t ∧ fst s'a' = fst (tree.root x)))⟧ ⟹ (SOME t'::('sequent × 'rule) tree. t' |∈| cont t ∧ fst s'a' = fst (tree.root t')) |∈| cont t› 2. ‹⟦∃t'::('sequent × 'rule) tree. t' |∈| cont (t::('sequent × 'rule) tree) ∧ fst (s'a'::'sequent × 'a) = fst (tree.root t'); ∃x::('sequent × 'rule) tree. x |∈| cont t ∧ fst s'a' = fst (tree.root x) ⟹ (SOME x::('sequent × 'rule) tree. x |∈| cont t ∧ fst s'a' = fst (tree.root x)) |∈| cont t ∧ fst s'a' = fst (tree.root (SOME x::('sequent × 'rule) tree. x |∈| cont t ∧ fst s'a' = fst (tree.root x)))⟧ ⟹ fst s'a' = fst (tree.root (SOME t'::('sequent × 'rule) tree. t' |∈| cont t ∧ fst s'a' = fst (tree.root t')))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . show "?thesis" (*goal: ‹∃t' a'. t' |∈| cont t ∧ pred (s, a) r (fst (tree.root t'), a') ∧ inv (fst (tree.root t'), a') ∧ stl (konigDtree t a) = konigDtree t' a'›*) using t' (*‹(t'::('sequent × 'rule) tree) |∈| cont (t::('sequent × 'rule) tree)›*) P (*‹P (fst s'a', snd s'a')›*) s' (*‹fst s'a' = fst (tree.root t')›*) assms (*‹s ≡ fst (tree.root t)› ‹r ≡ snd (tree.root t)› ‹s' |∈| (fst ∘ tree.root) |`| cont t› ‹pred (s, a) r (s', a'')› ‹inv (s', a'')›*) P_def (*‹P::'sequent × 'a ⇒ bool ≡ λ(s'::'sequent, a'::'a). s' |∈| (fst ∘ tree.root) |`| cont (t::('sequent × 'rule) tree) ∧ (pred::'sequent × 'a ⇒ 'rule ⇒ 'sequent × 'a ⇒ bool) (s::'sequent, a::'a) (r::'rule) (s', a') ∧ (inv::'sequent × 'a ⇒ bool) (s', a')›*) s'a'_def (*‹s'a' ≡ SOME (s', a'). P (s', a')›*) t'_def (*‹t' ≡ SOME t'. t' |∈| cont t ∧ fst s'a' = fst (tree.root t')›*) apply (intro exI[of _ t'] (*‹?P t' ⟹ ∃x. ?P x›*) exI[of _ ?a'] (*‹?P (snd s'a') ⟹ ∃x. ?P x›*)) (*goal: ‹∃t' a'. t' |∈| cont t ∧ pred (s, a) r (fst (tree.root t'), a') ∧ inv (fst (tree.root t'), a') ∧ stl (konigDtree t a) = konigDtree t' a'›*) by auto qed declare konigDtree.simps(2)[simp del] lemma konigDtree: assumes 1: "⋀r s sl a. ⟦r ∈ R; eff r s sl; inv (s,a)⟧ ⟹ ∃s' a'. s' |∈| sl ∧ inv (s',a') ∧ pred (s,a) r (s',a')" and 2: "wf t" "inv (fst (root t), a)" shows "alw (λstepas. let ((s,r),a) = shd stepas; ((s',_),a') = shd (stl stepas) in inv (s,a) ∧ pred (s,a) r (s',a')) (konigDtree t a)" using assms (*‹⟦(?r1::'rule) ∈ R; (eff::'rule ⇒ 'sequent ⇒ 'sequent fset ⇒ bool) ?r1 (?s1::'sequent) (?sl1::'sequent fset); (inv::'sequent × 'a ⇒ bool) (?s1, ?a1::'a)⟧ ⟹ ∃(s'::'sequent) a'::'a. s' |∈| ?sl1 ∧ inv (s', a') ∧ (pred::'sequent × 'a ⇒ 'rule ⇒ 'sequent × 'a ⇒ bool) (?s1, ?a1) ?r1 (s', a')› ‹local.wf t› ‹(inv::'sequent × 'a ⇒ bool) (fst (tree.root (t::('sequent × 'rule) tree)), a::'a)›*) proof (coinduction arbitrary: t a) (*goal: ‹⋀t a. ⟦∀r s sl a. r ∈ R ⟶ eff r s sl ⟶ inv (s, a) ⟶ (∃s' a'. s' |∈| sl ∧ inv (s', a') ∧ pred (s, a) r (s', a')); local.wf t; inv (fst (tree.root t), a)⟧ ⟹ ∃xs. konigDtree t a = xs ∧ (let ((s, r), a) = shd xs; ((s', uu_), a') = shd (stl xs) in inv (s, a) ∧ pred (s, a) r (s', a')) ∧ ((∃t a. stl xs = konigDtree t a ∧ (∀r s sl a. r ∈ R ⟶ eff r s sl ⟶ inv (s, a) ⟶ (∃s' a'. s' |∈| sl ∧ inv (s', a') ∧ pred (s, a) r (s', a'))) ∧ local.wf t ∧ inv (fst (tree.root t), a)) ∨ alw (λstepas. let ((s, r), a) = shd stepas; ((s', uu_), a') = shd (stl stepas) in inv (s, a) ∧ pred (s, a) r (s', a')) (stl xs))›*) case (alw t a) (*‹∀r s sl a. r ∈ R ⟶ eff r s sl ⟶ inv (s, a) ⟶ (∃s' a'. s' |∈| sl ∧ inv (s', a') ∧ pred (s, a) r (s', a'))› ‹local.wf t› ‹inv (fst (tree.root t), a)›*) then obtain s' and a' where "s' |∈| (fst ∘ root) |`| cont t" "inv (s', a')" "pred (fst (root t), a) (snd (root t)) (s', a')" (*goal: ‹(⋀s' a'. ⟦s' |∈| (fst ∘ tree.root) |`| cont t; inv (s', a'); pred (fst (tree.root t), a) (snd (tree.root t)) (s', a')⟧ ⟹ thesis) ⟹ thesis›*) apply (auto elim!: wf.cases (*‹⟦local.wf ?a; ⋀t. ⟦?a = t; snd (tree.root t) ∈ R; effStep (tree.root t) ((fst ∘ tree.root) |`| cont t); ⋀t'. t' |∈| cont t ⟹ local.wf t'⟧ ⟹ ?P⟧ ⟹ ?P›*) dest!: spec[of _ "snd (root t)"] (*‹∀x. ?P x ⟹ ?P (snd (tree.root t))›*) spec[of _ "fst (root t)"] (*‹∀x. ?P x ⟹ ?P (fst (tree.root t))›*) spec[of _ "(fst ∘ root) |`| cont t"] (*‹∀x. ?P x ⟹ ?P ((fst ∘ tree.root) |`| cont t)›*) spec[of _ a] (*‹∀x. ?P x ⟹ ?P a›*)) (*goal: ‹(⋀s' a'. ⟦s' |∈| (fst ∘ tree.root) |`| cont t; inv (s', a'); pred (fst (tree.root t), a) (snd (tree.root t)) (s', a')⟧ ⟹ thesis) ⟹ thesis›*) by fastforce with alw (*‹∀(r::'rule::type) (s::'sequent::type) (sl::'sequent::type fset) a::'a::type. r ∈ R ⟶ (eff::'rule::type ⇒ 'sequent::type ⇒ 'sequent::type fset ⇒ bool) r s sl ⟶ (inv::'sequent::type × 'a::type ⇒ bool) (s, a) ⟶ (∃(s'::'sequent::type) a'::'a::type. s' |∈| sl ∧ inv (s', a') ∧ (pred::'sequent::type × 'a::type ⇒ 'rule::type ⇒ 'sequent::type × 'a::type ⇒ bool) (s, a) r (s', a'))› ‹local.wf t› ‹inv (fst (tree.root t), a)›*) stl_konigDtree[of s' t a a'] (*‹⟦s' |∈| (fst ∘ tree.root) |`| cont t; pred (fst (tree.root t), a) (snd (tree.root t)) (s', a'); inv (s', a')⟧ ⟹ ∃t' a'. t' |∈| cont t ∧ pred (fst (tree.root t), a) (snd (tree.root t)) (fst (tree.root t'), a') ∧ inv (fst (tree.root t'), a') ∧ stl (konigDtree t a) = konigDtree t' a'›*) show "?case" (*goal: ‹∃xs. konigDtree t a = xs ∧ (let ((s, r), a) = shd xs; ((s', uu_), a') = shd (stl xs) in inv (s, a) ∧ pred (s, a) r (s', a')) ∧ ((∃t a. stl xs = konigDtree t a ∧ (∀r s sl a. r ∈ R ⟶ eff r s sl ⟶ inv (s, a) ⟶ (∃s' a'. s' |∈| sl ∧ inv (s', a') ∧ pred (s, a) r (s', a'))) ∧ local.wf t ∧ inv (fst (tree.root t), a)) ∨ alw (λstepas. let ((s, r), a) = shd stepas; ((s', uu_), a') = shd (stl stepas) in inv (s, a) ∧ pred (s, a) r (s', a')) (stl xs))›*) apply (auto split: prod.splits (*‹(?P::?'c ⇒ bool) (case ?prod::?'a × ?'b of (x::?'a, xa::?'b) ⇒ (?f::?'a ⇒ ?'b ⇒ ?'c) x xa) = (∀(x1::?'a) x2::?'b. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹(?P::?'c ⇒ bool) (case ?prod::?'a × ?'b of (x::?'a, xa::?'b) ⇒ (?f::?'a ⇒ ?'b ⇒ ?'c) x xa) = (∄(x1::?'a) x2::?'b. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*) elim!: wf.cases (*‹⟦local.wf (?a::('sequent × 'rule) tree); ⋀t::('sequent × 'rule) tree. ⟦?a = t; snd (tree.root t) ∈ R; effStep (tree.root t) ((fst ∘ tree.root) |`| cont t); ⋀t'::('sequent × 'rule) tree. t' |∈| cont t ⟹ local.wf t'⟧ ⟹ ?P::bool⟧ ⟹ ?P›*)) (*goal: ‹∃xs::(('sequent × 'rule) × 'a) stream. konigDtree (t::('sequent × 'rule) tree) (a::'a) = xs ∧ (let ((s::'sequent, r::'rule), a::'a) = shd xs; ((s'::'sequent, uu_::'rule), a'::'a) = shd (stl xs) in (inv::'sequent × 'a ⇒ bool) (s, a) ∧ (pred::'sequent × 'a ⇒ 'rule ⇒ 'sequent × 'a ⇒ bool) (s, a) r (s', a')) ∧ ((∃(t::('sequent × 'rule) tree) a::'a. stl xs = konigDtree t a ∧ (∀(r::'rule) (s::'sequent) (sl::'sequent fset) a::'a. r ∈ R ⟶ (eff::'rule ⇒ 'sequent ⇒ 'sequent fset ⇒ bool) r s sl ⟶ inv (s, a) ⟶ (∃(s'::'sequent) a'::'a. s' |∈| sl ∧ inv (s', a') ∧ pred (s, a) r (s', a'))) ∧ local.wf t ∧ inv (fst (tree.root t), a)) ∨ alw (λstepas::(('sequent × 'rule) × 'a) stream. let ((s::'sequent, r::'rule), a::'a) = shd stepas; ((s'::'sequent, uu_::'rule), a'::'a) = shd (stl stepas) in inv (s, a) ∧ pred (s, a) r (s', a')) (stl xs))›*) by fastforce qed lemma konigDtree_ipath: assumes "⋀r s sl a. ⟦r ∈ R; eff r s sl; inv (s,a)⟧ ⟹ ∃s' a'. s' |∈| sl ∧ inv (s',a') ∧ pred (s,a) r (s',a')" and "wf t" and "inv (fst (root t), a)" shows "ipath t (smap fst (konigDtree t a))" using assms (*‹⟦(?r1::'rule) ∈ R; (eff::'rule ⇒ 'sequent ⇒ 'sequent fset ⇒ bool) ?r1 (?s1::'sequent) (?sl1::'sequent fset); (inv::'sequent × 'a ⇒ bool) (?s1, ?a1::'a)⟧ ⟹ ∃(s'::'sequent) a'::'a. s' |∈| ?sl1 ∧ inv (s', a') ∧ (pred::'sequent × 'a ⇒ 'rule ⇒ 'sequent × 'a ⇒ bool) (?s1, ?a1) ?r1 (s', a')› ‹local.wf t› ‹inv (fst (tree.root t), a)›*) proof (coinduction arbitrary: t a) (*goal: ‹⋀(t::('sequent::type × 'rule::type) tree) a::'a::type. ⟦∀(r::'rule::type) (s::'sequent::type) (sl::'sequent::type fset) a::'a::type. r ∈ R ⟶ (eff::'rule::type ⇒ 'sequent::type ⇒ 'sequent::type fset ⇒ bool) r s sl ⟶ (inv::'sequent::type × 'a::type ⇒ bool) (s, a) ⟶ (∃(s'::'sequent::type) a'::'a::type. s' |∈| sl ∧ inv (s', a') ∧ (pred::'sequent::type × 'a::type ⇒ 'rule::type ⇒ 'sequent::type × 'a::type ⇒ bool) (s, a) r (s', a')); local.wf t; inv (fst (tree.root t), a)⟧ ⟹ ∃(ta::('sequent::type × 'rule::type) tree) (steps::('sequent::type × 'rule::type) stream) t'::('sequent::type × 'rule::type) tree. t = ta ∧ smap fst (konigDtree t a) = steps ∧ tree.root ta = shd steps ∧ t' |∈| cont ta ∧ ((∃(t::('sequent::type × 'rule::type) tree) a::'a::type. t' = t ∧ stl steps = smap fst (konigDtree t a) ∧ (∀(r::'rule::type) (s::'sequent::type) (sl::'sequent::type fset) a::'a::type. r ∈ R ⟶ eff r s sl ⟶ inv (s, a) ⟶ (∃(s'::'sequent::type) a'::'a::type. s' |∈| sl ∧ inv (s', a') ∧ pred (s, a) r (s', a'))) ∧ local.wf t ∧ inv (fst (tree.root t), a)) ∨ ipath t' (stl steps))›*) case (ipath t a) (*‹∀r s sl a. r ∈ R ⟶ eff r s sl ⟶ inv (s, a) ⟶ (∃s' a'. s' |∈| sl ∧ inv (s', a') ∧ pred (s, a) r (s', a'))› ‹local.wf (t::('sequent::type × 'rule::type) tree)› ‹(inv::'sequent × 'a ⇒ bool) (fst (tree.root (t::('sequent × 'rule) tree)), a::'a)›*) then obtain s' and a' where "s' |∈| (fst ∘ root) |`| cont t" "inv (s', a')" "pred (fst (root t), a) (snd (root t)) (s', a')" (*goal: ‹(⋀(s'::'sequent::type) a'::'a::type. ⟦s' |∈| (fst ∘ tree.root) |`| cont (t::('sequent::type × 'rule::type) tree); (inv::'sequent::type × 'a::type ⇒ bool) (s', a'); (pred::'sequent::type × 'a::type ⇒ 'rule::type ⇒ 'sequent::type × 'a::type ⇒ bool) (fst (tree.root t), a::'a::type) (snd (tree.root t)) (s', a')⟧ ⟹ thesis::bool) ⟹ thesis›*) apply (auto elim!: wf.cases (*‹⟦local.wf (?a::('sequent × 'rule) tree); ⋀t::('sequent × 'rule) tree. ⟦?a = t; snd (tree.root t) ∈ R; effStep (tree.root t) ((fst ∘ tree.root) |`| cont t); ⋀t'::('sequent × 'rule) tree. t' |∈| cont t ⟹ local.wf t'⟧ ⟹ ?P::bool⟧ ⟹ ?P›*) dest!: spec[of _ "snd (root t)"] (*‹∀x::'rule. (?P::'rule ⇒ bool) x ⟹ ?P (snd (tree.root (t::('sequent × 'rule) tree)))›*) spec[of _ "fst (root t)"] (*‹∀x::'sequent. (?P::'sequent ⇒ bool) x ⟹ ?P (fst (tree.root (t::('sequent × 'rule) tree)))›*) spec[of _ "(fst ∘ root) |`| cont t"] (*‹∀x::'sequent fset. (?P::'sequent fset ⇒ bool) x ⟹ ?P ((fst ∘ tree.root) |`| cont (t::('sequent × 'rule) tree))›*) spec[of _ a] (*‹∀x::'a. (?P::'a ⇒ bool) x ⟹ ?P (a::'a)›*)) (*goal: ‹(⋀s' a'. ⟦s' |∈| (fst ∘ tree.root) |`| cont t; inv (s', a'); pred (fst (tree.root t), a) (snd (tree.root t)) (s', a')⟧ ⟹ thesis) ⟹ thesis›*) by fastforce with ipath (*‹∀r s sl a. r ∈ R ⟶ eff r s sl ⟶ inv (s, a) ⟶ (∃s' a'. s' |∈| sl ∧ inv (s', a') ∧ pred (s, a) r (s', a'))› ‹local.wf t› ‹inv (fst (tree.root t), a)›*) stl_konigDtree[of s' t a a'] (*‹⟦s' |∈| (fst ∘ tree.root) |`| cont t; pred (fst (tree.root t), a) (snd (tree.root t)) (s', a'); inv (s', a')⟧ ⟹ ∃t' a'. t' |∈| cont t ∧ pred (fst (tree.root t), a) (snd (tree.root t)) (fst (tree.root t'), a') ∧ inv (fst (tree.root t'), a') ∧ stl (konigDtree t a) = konigDtree t' a'›*) show "?case" (*goal: ‹∃(t::('sequent::type × 'rule::type) tree) (steps::('sequent::type × 'rule::type) stream) t'::('sequent::type × 'rule::type) tree. (t::('sequent::type × 'rule::type) tree) = t ∧ smap fst (konigDtree t (a::'a::type)) = steps ∧ tree.root t = shd steps ∧ t' |∈| cont t ∧ ((∃(t::('sequent::type × 'rule::type) tree) a::'a::type. t' = t ∧ stl steps = smap fst (konigDtree t a) ∧ (∀(r::'rule::type) (s::'sequent::type) (sl::'sequent::type fset) a::'a::type. r ∈ R ⟶ (eff::'rule::type ⇒ 'sequent::type ⇒ 'sequent::type fset ⇒ bool) r s sl ⟶ (inv::'sequent::type × 'a::type ⇒ bool) (s, a) ⟶ (∃(s'::'sequent::type) a'::'a::type. s' |∈| sl ∧ inv (s', a') ∧ (pred::'sequent::type × 'a::type ⇒ 'rule::type ⇒ 'sequent::type × 'a::type ⇒ bool) (s, a) r (s', a'))) ∧ local.wf t ∧ inv (fst (tree.root t), a)) ∨ ipath t' (stl steps))›*) apply (auto split: prod.splits (*‹(?P::?'c::type ⇒ bool) (case ?prod::?'a::type × ?'b::type of (x::?'a::type, xa::?'b::type) ⇒ (?f::?'a::type ⇒ ?'b::type ⇒ ?'c::type) x xa) = (∀(x1::?'a::type) x2::?'b::type. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹(?P::?'c::type ⇒ bool) (case ?prod::?'a::type × ?'b::type of (x::?'a::type, xa::?'b::type) ⇒ (?f::?'a::type ⇒ ?'b::type ⇒ ?'c::type) x xa) = (∄(x1::?'a::type) x2::?'b::type. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*) elim!: wf.cases (*‹⟦local.wf (?a::('sequent::type × 'rule::type) tree); ⋀t::('sequent::type × 'rule::type) tree. ⟦?a = t; snd (tree.root t) ∈ R; effStep (tree.root t) ((fst ∘ tree.root) |`| cont t); ⋀t'::('sequent::type × 'rule::type) tree. t' |∈| cont t ⟹ local.wf t'⟧ ⟹ ?P::bool⟧ ⟹ ?P›*)) (*goal: ‹∃(t::('sequent::type × 'rule::type) tree) (steps::('sequent::type × 'rule::type) stream) t'::('sequent::type × 'rule::type) tree. (t::('sequent::type × 'rule::type) tree) = t ∧ smap fst (konigDtree t (a::'a::type)) = steps ∧ tree.root t = shd steps ∧ t' |∈| cont t ∧ ((∃(t::('sequent::type × 'rule::type) tree) a::'a::type. t' = t ∧ stl steps = smap fst (konigDtree t a) ∧ (∀(r::'rule::type) (s::'sequent::type) (sl::'sequent::type fset) a::'a::type. r ∈ R ⟶ (eff::'rule::type ⇒ 'sequent::type ⇒ 'sequent::type fset ⇒ bool) r s sl ⟶ (inv::'sequent::type × 'a::type ⇒ bool) (s, a) ⟶ (∃(s'::'sequent::type) a'::'a::type. s' |∈| sl ∧ inv (s', a') ∧ (pred::'sequent::type × 'a::type ⇒ 'rule::type ⇒ 'sequent::type × 'a::type ⇒ bool) (s, a) r (s', a'))) ∧ local.wf t ∧ inv (fst (tree.root t), a)) ∨ ipath t' (stl steps))›*) by force qed end (* context *) lemma follow_stl_smap_fst[simp]: "follow bs Ms (smap fst stepSs) ⟹ follow (stl bs) (stl Ms) (smap fst (stl stepSs))" apply (erule follow.cases (*‹⟦follow ?a1.0 ?a2.0 ?a3.0; ⋀M' Ms s' steps M b s r bs. ⟦?a1.0 = b ## bs; ?a2.0 = M ## Ms; ?a3.0 = (s, r) ## steps; M' = shd Ms; s' = fst (shd steps); (M, b, M') ∈ δ s r s'; follow bs Ms steps⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goal: ‹follow bs Ms (smap fst stepSs) ⟹ follow (stl bs) (stl Ms) (smap fst (stl stepSs))›*) by (auto simp del: stream.map_sel (*‹shd (smap ?f ?a) = ?f (shd ?a)› ‹stl (smap ?f ?a) = smap ?f (stl ?a)›*) simp add: stream.map_sel[symmetric] (*‹?f (shd ?a) = shd (smap ?f ?a)› ‹smap ?f (stl ?a) = stl (smap ?f ?a)›*)) lemma epath_stl_smap_fst[simp]: "epath (smap fst stepSs) ⟹ epath (smap fst (stl stepSs))" apply (erule epath.cases (*‹⟦epath ?a; ⋀steps sl. ⟦?a = steps; snd (shd steps) ∈ R; fst (shd (stl steps)) |∈| sl; effStep (shd steps) sl; epath (stl steps)⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goal: ‹epath (smap fst stepSs) ⟹ epath (smap fst (stl stepSs))›*) by (auto simp del: stream.map_sel (*‹shd (smap ?f ?a) = ?f (shd ?a)› ‹stl (smap ?f ?a) = smap ?f (stl ?a)›*) simp add: stream.map_sel[symmetric] (*‹?f (shd ?a) = shd (smap ?f ?a)› ‹smap ?f (stl ?a) = stl (smap ?f ?a)›*)) lemma infDecr_tl[simp]: "infDecr bs ⟹ infDecr (stl bs)" unfolding infDecr_def (*goal: ‹alw (ev shd) bs ⟹ alw (ev shd) (stl bs)›*) by auto (* Proof of the main theorem: *) fun descent where "descent (s,S) r (s',S') = (∀v v' b. (v,b,v') ∈ δ s r s' ⟶ (σ(v',S'), σ(v,S)) ∈ Ord ∧ (b ⟶ σ(v',S') ≠ σ(v,S)))" lemma descentE[elim]: assumes "descent (s,S) r (s',S')" and "(v,b,v') ∈ δ s r s'" shows "(σ(v',S'), σ(v,S)) ∈ Ord ∧ (b ⟶ σ(v',S') ≠ σ(v,S))" using assms (*‹descent (s, S) r (s', S')› ‹(v, b, v') ∈ δ s r s'›*) by auto definition "konigDown ≡ konigDtree (λ(s,S). S ∈ structure ∧ ¬ sat S s) descent" lemma konigDown: assumes "wf t" and "S ∈ structure" and "¬ sat S (fst (root t))" shows "alw (λstepSs. let ((s,r),S) = shd stepSs; ((s',_),S') = shd (stl stepSs) in S ∈ structure ∧ ¬ sat S s ∧ descent (s,S) r (s',S')) (konigDown t S)" using konigDtree[of "λ(s,S). S ∈ structure ∧ ¬ sat S s" descent, unfolded konigDown_def [ symmetric ]] (*‹⟦⋀r s sl a. ⟦r ∈ R; eff r s sl; case (s, a) of (s, S) ⇒ S ∈ structure ∧ ¬ sat S s⟧ ⟹ ∃s' a'. s' |∈| sl ∧ (case (s', a') of (s, S) ⇒ S ∈ structure ∧ ¬ sat S s) ∧ descent (s, a) r (s', a'); local.wf ?t; case (fst (tree.root ?t), ?a) of (s, S) ⇒ S ∈ structure ∧ ¬ sat S s⟧ ⟹ alw (λstepas. let ((s, r), a) = shd stepas; ((s', uu_), a') = shd (stl stepas) in (case (s, a) of (s, S) ⇒ S ∈ structure ∧ ¬ sat S s) ∧ descent (s, a) r (s', a')) (konigDown ?t ?a)›*) using assms (*‹local.wf t› ‹(S::'structure) ∈ (structure::'structure set)› ‹¬ sat S (fst (tree.root t))›*) descent (*‹⟦?r ∈ R; eff ?r ?s ?sl; ?S ∈ structure; ¬ sat ?S ?s⟧ ⟹ ∃s' S'. s' |∈| ?sl ∧ S' ∈ structure ∧ ¬ sat S' s' ∧ (∀v v' b. (v, b, v') ∈ δ ?s ?r s' ⟶ (σ (v', S'), σ (v, ?S)) ∈ Ord ∧ (b ⟶ σ (v', S') ≠ σ (v, ?S)))›*) by auto lemma konigDown_ipath: assumes "wf t" and "S ∈ structure" and "¬ sat S (fst (root t))" shows "ipath t (smap fst (konigDown t S))" using konigDtree_ipath[of "λ(s,S). S ∈ structure ∧ ¬ sat S s" descent, unfolded konigDown_def [ symmetric ]] (*‹⟦⋀r s sl a. ⟦r ∈ R; eff r s sl; case (s, a) of (s, S) ⇒ S ∈ structure ∧ ¬ sat S s⟧ ⟹ ∃s' a'. s' |∈| sl ∧ (case (s', a') of (s, S) ⇒ S ∈ structure ∧ ¬ sat S s) ∧ descent (s, a) r (s', a'); local.wf ?t; case (fst (tree.root ?t), ?a) of (s, S) ⇒ S ∈ structure ∧ ¬ sat S s⟧ ⟹ ipath ?t (smap fst (konigDown ?t ?a))›*) using assms (*‹local.wf (t::('sequent × 'rule) tree)› ‹S ∈ structure› ‹¬ sat S (fst (tree.root t))›*) descent (*‹⟦?r ∈ R; eff ?r ?s ?sl; ?S ∈ structure; ¬ sat ?S ?s⟧ ⟹ ∃s' S'. s' |∈| ?sl ∧ S' ∈ structure ∧ ¬ sat S' s' ∧ (∀v v' b. (v, b, v') ∈ δ ?s ?r s' ⟶ (σ (v', S'), σ (v, ?S)) ∈ Ord ∧ (b ⟶ σ (v', S') ≠ σ (v, ?S)))›*) by auto context fixes t S assumes w: "wf t" and t: "good t" and S: "S ∈ structure" "¬ sat S (fst (root t))" begin lemma alw_ev_Ord: obtains ks where "alw (λks. (shd (stl ks), shd ks) ∈ Ord) ks" and "alw (ev (λks. shd (stl ks) ≠ shd ks)) ks" proof (-) (*goal: ‹(⋀ks. ⟦alw (λks. (shd (stl ks), shd ks) ∈ Ord) ks; alw (ev (λks. shd (stl ks) ≠ shd ks)) ks⟧ ⟹ thesis) ⟹ thesis›*) define P where "P ≡ λstepSs. let ((s,r),S) = shd stepSs; ((s',_),S') = shd (stl stepSs) in S ∈ structure ∧ ¬ sat S s ∧ descent (s,S) r (s',S')" have "alw P (konigDown t S)" using konigDown[OF w S] (*‹alw (λstepSs. let ((s, r), S) = shd stepSs; ((s', uu_), S') = shd (stl stepSs) in S ∈ structure ∧ ¬ sat S s ∧ descent (s, S) r (s', S')) (konigDown t S)›*) unfolding P_def (*goal: ‹alw (λstepSs::(('sequent × 'rule) × 'structure) stream. let ((s::'sequent, r::'rule), S::'structure) = shd stepSs; ((s'::'sequent, uu_::'rule), S'::'structure) = shd (stl stepSs) in S ∈ (structure::'structure set) ∧ ¬ (sat::'structure ⇒ 'sequent ⇒ bool) S s ∧ descent (s, S) r (s', S')) (konigDown (t::('sequent × 'rule) tree) (S::'structure))›*) by auto obtain srs and steps and bs and Ms where 0: "smap fst (konigDown t S) = srs @- steps" and f: "follow bs Ms steps" and i: "infDecr bs" (*goal: ‹(⋀(srs::('sequent::type × 'rule::type) list) (steps::('sequent::type × 'rule::type) stream) (bs::bool stream) Ms::'marker::type stream. ⟦smap fst (konigDown (t::('sequent::type × 'rule::type) tree) (S::'structure::type)) = srs @- steps; follow bs Ms steps; infDecr bs⟧ ⟹ thesis::bool) ⟹ thesis›*) using konigDown_ipath[OF w S] (*‹ipath (t::('sequent × 'rule) tree) (smap fst (konigDown t (S::'structure)))›*) t (*‹good t›*) unfolding good_def ev_iff_shift (*goal: ‹(⋀srs steps bs Ms. ⟦smap fst (konigDown t S) = srs @- steps; follow bs Ms steps; infDecr bs⟧ ⟹ thesis) ⟹ thesis›*) by auto define stepSs where "stepSs = sdrop (length srs) (konigDown t S)" have steps: "steps = smap fst stepSs" unfolding stepSs_def sdrop_smap[symmetric] "0" (*goal: ‹steps = sdrop (length srs) (srs @- steps)›*) by simp have e: "epath steps" using wf_ipath_epath[OF w konigDown_ipath [ OF w S ]] (*‹epath (smap fst (konigDown t S))›*) "0" (*‹smap fst (konigDown t S) = srs @- steps›*) epath_shift (*‹epath (?srs @- ?steps) ⟹ epath ?steps›*) by simp have "alw P (konigDown t S)" using konigDown[OF w S] (*‹alw (λstepSs. let ((s, r), S) = shd stepSs; ((s', uu_), S') = shd (stl stepSs) in S ∈ structure ∧ ¬ sat S s ∧ descent (s, S) r (s', S')) (konigDown t S)›*) unfolding P_def (*goal: ‹alw (λstepSs::(('sequent × 'rule) × 'structure) stream. let ((s::'sequent, r::'rule), S::'structure) = shd stepSs; ((s'::'sequent, uu_::'rule), S'::'structure) = shd (stl stepSs) in S ∈ (structure::'structure set) ∧ ¬ (sat::'structure ⇒ 'sequent ⇒ bool) S s ∧ descent (s, S) r (s', S')) (konigDown (t::('sequent × 'rule) tree) (S::'structure))›*) by auto hence P: "alw P stepSs" using alw_sdrop (*‹alw (?φ::?'a stream ⇒ bool) (?xs::?'a stream) ⟹ alw ?φ (sdrop (?n::nat) ?xs)›*) unfolding stepSs_def (*goal: ‹alw P (sdrop (length srs) (konigDown t S))›*) by auto let ?ks = "smap σ (szip Ms (smap snd stepSs))" show "?thesis" (*goal: ‹thesis›*) proof (rule that[of ?ks] (*‹⟦alw (λks. (shd (stl ks), shd ks) ∈ Ord) (smap σ (szip Ms (smap snd stepSs))); alw (ev (λks. shd (stl ks) ≠ shd ks)) (smap σ (szip Ms (smap snd stepSs)))⟧ ⟹ thesis›*)) (*goals: 1. ‹alw (λks. (shd (stl ks), shd ks) ∈ Ord) (smap σ (szip Ms (smap snd stepSs)))› 2. ‹alw (ev (λks. shd (stl ks) ≠ shd ks)) (smap σ (szip Ms (smap snd stepSs)))›*) show "alw (λks. (shd (stl ks), shd ks) ∈ Ord) ?ks" using e (*‹epath steps›*) f (*‹follow bs Ms steps›*) P (*‹alw P stepSs›*) unfolding steps (*goal: ‹alw (λks. (shd (stl ks), shd ks) ∈ Ord) (smap σ (szip Ms (smap snd stepSs)))›*) proof (coinduction arbitrary: bs Ms stepSs rule: alw_coinduct) (*goals: 1. ‹⋀bs Ms stepSs. ⟦epath (smap fst stepSs); follow bs Ms (smap fst stepSs); alw P stepSs⟧ ⟹ (shd (stl (smap σ (szip Ms (smap snd stepSs)))), shd (smap σ (szip Ms (smap snd stepSs)))) ∈ Ord› 2. ‹⋀bs Ms stepSs. ⟦epath (smap fst stepSs); follow bs Ms (smap fst stepSs); alw P stepSs; ¬ alw (λks. (shd (stl ks), shd ks) ∈ Ord) (stl (smap σ (szip Ms (smap snd stepSs))))⟧ ⟹ ∃bs Msa stepSsa. stl (smap σ (szip Ms (smap snd stepSs))) = smap σ (szip Msa (smap snd stepSsa)) ∧ epath (smap fst stepSsa) ∧ follow bs Msa (smap fst stepSsa) ∧ alw P stepSsa›*) case (alw bs Ms stepSs) (*‹epath (smap fst stepSs)› ‹follow bs Ms (smap fst stepSs)› ‹alw P stepSs›*) let ?steps = "smap fst stepSs" let ?Ss = "smap snd stepSs" let ?MSs = "szip Ms (smap snd stepSs)" let ?s = "fst (shd ?steps)" let ?s' = "fst (shd (stl ?steps))" let ?r = "snd (shd ?steps)" let ?S = "snd (shd stepSs)" let ?S' = "snd (shd (stl stepSs))" let ?M = "shd Ms" let ?M' = "shd (stl Ms)" let ?b = "shd bs" have 1: "(?M, ?b, ?M') ∈ δ ?s ?r ?s'" using ‹follow bs Ms (smap fst stepSs)› (*‹follow (bs::bool stream) (Ms::'marker stream) (smap fst (stepSs::(('sequent × 'rule) × 'structure) stream))›*) apply (cases rule: follow.cases (*‹⟦follow ?a1.0 ?a2.0 ?a3.0; ⋀M' Ms s' steps M b s r bs. ⟦?a1.0 = b ## bs; ?a2.0 = M ## Ms; ?a3.0 = (s, r) ## steps; M' = shd Ms; s' = fst (shd steps); (M, b, M') ∈ δ s r s'; follow bs Ms steps⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goal: ‹(shd Ms, shd bs, shd (stl Ms)) ∈ δ (fst (shd (smap fst stepSs))) (snd (shd (smap fst stepSs))) (fst (shd (stl (smap fst stepSs))))›*) by auto have 2: "descent (?s,?S) ?r (?s',?S')" using ‹alw P stepSs› (*‹alw P stepSs›*) unfolding P_def (*goal: ‹descent (fst (shd (smap fst stepSs)), snd (shd stepSs)) (snd (shd (smap fst stepSs))) (fst (shd (stl (smap fst stepSs))), snd (shd (stl stepSs)))›*) apply (cases rule: alw.cases (*‹⟦alw ?φ ?a; ⋀xs. ⟦?a = xs; ?φ xs; alw ?φ (stl xs)⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goal: ‹descent (fst (shd (smap fst (stepSs::(('sequent × 'rule) × 'structure) stream))), snd (shd stepSs)) (snd (shd (smap fst stepSs))) (fst (shd (stl (smap fst stepSs))), snd (shd (stl stepSs)))›*) by auto have "(σ(?M',?S'), σ(?M,?S)) ∈ Ord" using descentE[OF 2 1] (*‹(σ (shd (stl Ms), snd (shd (stl stepSs))), σ (shd Ms, snd (shd stepSs))) ∈ Ord ∧ (shd bs ⟶ σ (shd (stl Ms), snd (shd (stl stepSs))) ≠ σ (shd Ms, snd (shd stepSs)))›*) by simp thus "?case" (*goal: ‹(shd (stl (smap σ (szip Ms (smap snd stepSs)))), shd (smap σ (szip Ms (smap snd stepSs)))) ∈ Ord›*) by simp next (*goal: ‹⋀bs Ms stepSs. ⟦epath (smap fst stepSs); follow bs Ms (smap fst stepSs); alw P stepSs; ¬ alw (λks. (shd (stl ks), shd ks) ∈ Ord) (stl (smap σ (szip Ms (smap snd stepSs))))⟧ ⟹ ∃bs Msa stepSsa. stl (smap σ (szip Ms (smap snd stepSs))) = smap σ (szip Msa (smap snd stepSsa)) ∧ epath (smap fst stepSsa) ∧ follow bs Msa (smap fst stepSsa) ∧ alw P stepSsa›*) case (stl bs Ms stepSs) (*‹epath (smap fst stepSs)› ‹follow (bs::bool stream) (Ms::'marker stream) (smap fst (stepSs::(('sequent × 'rule) × 'structure) stream))› ‹alw P stepSs› ‹¬ alw (λks. (shd (stl ks), shd ks) ∈ Ord) (stl (smap σ (szip Ms (smap snd stepSs))))›*) thus "?case" (*goal: ‹∃bs Ms stepSs. stl (smap σ (szip Ms (smap snd stepSs))) = smap σ (szip Ms (smap snd stepSs)) ∧ epath (smap fst stepSs) ∧ follow bs Ms (smap fst stepSs) ∧ alw P stepSs›*) apply (intro exI[of _ "stl bs"] (*‹(?P::bool stream ⇒ bool) (stl (bs::bool stream)) ⟹ ∃x::bool stream. ?P x›*) exI[of _ "stl Ms"] (*‹(?P::'marker stream ⇒ bool) (stl (Ms::'marker stream)) ⟹ ∃x::'marker stream. ?P x›*) exI[of _ "stl stepSs"] (*‹(?P::(('sequent × 'rule) × 'structure) stream ⇒ bool) (stl (stepSs::(('sequent × 'rule) × 'structure) stream)) ⟹ ∃x::(('sequent × 'rule) × 'structure) stream. ?P x›*)) (*goal: ‹∃bs Ms stepSs. stl (smap σ (szip Ms (smap snd stepSs))) = smap σ (szip Ms (smap snd stepSs)) ∧ epath (smap fst stepSs) ∧ follow bs Ms (smap fst stepSs) ∧ alw P stepSs›*) by (auto elim: epath.cases (*‹⟦epath ?a; ⋀steps sl. ⟦?a = steps; snd (shd steps) ∈ R; fst (shd (stl steps)) |∈| sl; effStep (shd steps) sl; epath (stl steps)⟧ ⟹ ?P⟧ ⟹ ?P›*)) qed next (*goal: ‹alw (ev (λks. shd (stl ks) ≠ shd ks)) (smap σ (szip Ms (smap snd stepSs)))›*) show "alw (ev (λks. shd (stl ks) ≠ shd ks)) ?ks" using e (*‹epath (steps::('sequent × 'rule) stream)›*) f (*‹follow bs Ms steps›*) P (*‹alw P stepSs›*) i (*‹infDecr bs›*) unfolding steps (*goal: ‹alw (ev (λks. shd (stl ks) ≠ shd ks)) (smap σ (szip Ms (smap snd stepSs)))›*) proof (coinduction arbitrary: bs Ms stepSs rule: alw_coinduct) (*goals: 1. ‹⋀bs Ms stepSs. ⟦epath (smap fst stepSs); follow bs Ms (smap fst stepSs); alw P stepSs; infDecr bs⟧ ⟹ ev (λks. shd (stl ks) ≠ shd ks) (smap σ (szip Ms (smap snd stepSs)))› 2. ‹⋀bs Ms stepSs. ⟦epath (smap fst stepSs); follow bs Ms (smap fst stepSs); alw P stepSs; infDecr bs; ¬ alw (ev (λks. shd (stl ks) ≠ shd ks)) (stl (smap σ (szip Ms (smap snd stepSs))))⟧ ⟹ ∃bs Msa stepSsa. stl (smap σ (szip Ms (smap snd stepSs))) = smap σ (szip Msa (smap snd stepSsa)) ∧ epath (smap fst stepSsa) ∧ follow bs Msa (smap fst stepSsa) ∧ alw P stepSsa ∧ infDecr bs›*) case (alw bs Ms stepSs) (*‹epath (smap fst stepSs)› ‹follow bs Ms (smap fst stepSs)› ‹alw P stepSs› ‹infDecr bs›*) let ?steps = "smap fst stepSs" let ?Ss = "smap snd stepSs" let ?MSs = "szip Ms (smap snd stepSs)" let ?s = "fst (shd ?steps)" let ?s' = "fst (shd (stl ?steps))" let ?r = "snd (shd ?steps)" let ?S = "snd (shd stepSs)" let ?S' = "snd (shd (stl stepSs))" let ?M = "shd Ms" let ?M' = "shd (stl Ms)" let ?b = "shd bs" have 1: "(?M, ?b, ?M') ∈ δ ?s ?r ?s'" using ‹follow bs Ms (smap fst stepSs)› (*‹follow bs Ms (smap fst stepSs)›*) apply (cases rule: follow.cases (*‹⟦follow ?a1.0 ?a2.0 ?a3.0; ⋀M' Ms s' steps M b s r bs. ⟦?a1.0 = b ## bs; ?a2.0 = M ## Ms; ?a3.0 = (s, r) ## steps; M' = shd Ms; s' = fst (shd steps); (M, b, M') ∈ δ s r s'; follow bs Ms steps⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goal: ‹(shd (Ms::'marker stream), shd (bs::bool stream), shd (stl Ms)) ∈ (δ::'sequent ⇒ 'rule ⇒ 'sequent ⇒ ('marker × bool × 'marker) set) (fst (shd (smap fst (stepSs::(('sequent × 'rule) × 'structure) stream)))) (snd (shd (smap fst stepSs))) (fst (shd (stl (smap fst stepSs))))›*) by auto have 2: "descent (?s,?S) ?r (?s',?S')" using ‹alw P stepSs› (*‹alw P stepSs›*) unfolding P_def (*goal: ‹descent (fst (shd (smap fst stepSs)), snd (shd stepSs)) (snd (shd (smap fst stepSs))) (fst (shd (stl (smap fst stepSs))), snd (shd (stl stepSs)))›*) apply (cases rule: alw.cases (*‹⟦alw ?φ ?a; ⋀xs. ⟦?a = xs; ?φ xs; alw ?φ (stl xs)⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goal: ‹descent (fst (shd (smap fst (stepSs::(('sequent × 'rule) × 'structure) stream))), snd (shd stepSs)) (snd (shd (smap fst stepSs))) (fst (shd (stl (smap fst stepSs))), snd (shd (stl stepSs)))›*) by auto have "(σ(?M',?S'), σ(?M,?S)) ∈ Ord" using descentE[OF 2 1] (*‹(σ (shd (stl Ms), snd (shd (stl stepSs))), σ (shd Ms, snd (shd stepSs))) ∈ Ord ∧ (shd bs ⟶ σ (shd (stl Ms), snd (shd (stl stepSs))) ≠ σ (shd Ms, snd (shd stepSs)))›*) by simp have "ev shd bs" using ‹infDecr bs› (*‹infDecr bs›*) unfolding infDecr_def (*goal: ‹ev shd (bs::bool stream)›*) by auto thus "?case" (*goal: ‹ev (λks. shd (stl ks) ≠ shd ks) (smap σ (szip Ms (smap snd stepSs)))›*) using ‹epath ?steps› (*‹epath (smap fst stepSs)›*) ‹follow bs Ms ?steps› (*‹follow (bs::bool stream) (Ms::'marker stream) (smap fst (stepSs::(('sequent × 'rule) × 'structure) stream))›*) ‹alw P stepSs› (*‹alw P stepSs›*) proof (induction arbitrary: Ms stepSs) (*goals: 1. ‹⋀xs Ms stepSs. ⟦shd xs; epath (smap fst stepSs); follow xs Ms (smap fst stepSs); alw P stepSs⟧ ⟹ ev (λks. shd (stl ks) ≠ shd ks) (smap σ (szip Ms (smap snd stepSs)))› 2. ‹⋀xs Ms stepSs. ⟦ev shd (stl xs); ⋀Ms stepSs. ⟦epath (smap fst stepSs); follow (stl xs) Ms (smap fst stepSs); alw P stepSs⟧ ⟹ ev (λks. shd (stl ks) ≠ shd ks) (smap σ (szip Ms (smap snd stepSs))); epath (smap fst stepSs); follow xs Ms (smap fst stepSs); alw P stepSs⟧ ⟹ ev (λks. shd (stl ks) ≠ shd ks) (smap σ (szip Ms (smap snd stepSs)))›*) case (base bs Ms stepSs) (*‹shd bs› ‹epath (smap fst stepSs)› ‹follow (bs::bool stream) (Ms::'marker stream) (smap fst (stepSs::(('sequent × 'rule) × 'structure) stream))› ‹alw P stepSs›*) let ?steps = "smap fst stepSs" let ?Ss = "smap snd stepSs" let ?MSs = "szip Ms (smap snd stepSs)" let ?s = "fst (shd ?steps)" let ?s' = "fst (shd (stl ?steps))" let ?r = "snd (shd ?steps)" let ?S = "snd (shd stepSs)" let ?S' = "snd (shd (stl stepSs))" let ?M = "shd Ms" let ?M' = "shd (stl Ms)" let ?b = "shd bs" have 1: "(?M, ?b, ?M') ∈ δ ?s ?r ?s'" using ‹follow bs Ms (smap fst stepSs)› (*‹follow bs Ms (smap fst stepSs)›*) apply (cases rule: follow.cases (*‹⟦follow ?a1.0 ?a2.0 ?a3.0; ⋀M' Ms s' steps M b s r bs. ⟦?a1.0 = b ## bs; ?a2.0 = M ## Ms; ?a3.0 = (s, r) ## steps; M' = shd Ms; s' = fst (shd steps); (M, b, M') ∈ δ s r s'; follow bs Ms steps⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goal: ‹(shd Ms, shd bs, shd (stl Ms)) ∈ δ (fst (shd (smap fst stepSs))) (snd (shd (smap fst stepSs))) (fst (shd (stl (smap fst stepSs))))›*) by auto have 2: "descent (?s,?S) ?r (?s',?S')" using ‹alw P stepSs› (*‹alw P stepSs›*) unfolding P_def (*goal: ‹descent (fst (shd (smap fst stepSs)), snd (shd stepSs)) (snd (shd (smap fst stepSs))) (fst (shd (stl (smap fst stepSs))), snd (shd (stl stepSs)))›*) apply (cases rule: alw.cases (*‹⟦alw ?φ ?a; ⋀xs. ⟦?a = xs; ?φ xs; alw ?φ (stl xs)⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goal: ‹descent (fst (shd (smap fst stepSs)), snd (shd stepSs)) (snd (shd (smap fst stepSs))) (fst (shd (stl (smap fst stepSs))), snd (shd (stl stepSs)))›*) by auto have "σ(?M',?S') ≠ σ(?M,?S)" using descentE[OF 2 1] (*‹(σ (shd (stl Ms), snd (shd (stl stepSs))), σ (shd Ms, snd (shd stepSs))) ∈ Ord ∧ (shd bs ⟶ σ (shd (stl Ms), snd (shd (stl stepSs))) ≠ σ (shd Ms, snd (shd stepSs)))›*) ‹shd bs› (*‹shd bs›*) by simp thus "?case" (*goal: ‹ev (λks::'ord stream. shd (stl ks) ≠ shd ks) (smap (σ::'marker × 'structure ⇒ 'ord) (szip (Ms::'marker stream) (smap snd (stepSs::(('sequent × 'rule) × 'structure) stream))))›*) by auto next (*goal: ‹⋀xs Ms stepSs. ⟦ev shd (stl xs); ⋀Ms stepSs. ⟦epath (smap fst stepSs); follow (stl xs) Ms (smap fst stepSs); alw P stepSs⟧ ⟹ ev (λks. shd (stl ks) ≠ shd ks) (smap σ (szip Ms (smap snd stepSs))); epath (smap fst stepSs); follow xs Ms (smap fst stepSs); alw P stepSs⟧ ⟹ ev (λks. shd (stl ks) ≠ shd ks) (smap σ (szip Ms (smap snd stepSs)))›*) case (step bs Ms stepSs) (*‹ev shd (stl (bs::bool stream))› ‹⟦epath (smap fst (?stepSs2::(('sequent × 'rule) × 'structure) stream)); follow (stl (bs::bool stream)) (?Ms2::'marker stream) (smap fst ?stepSs2); alw (P::(('sequent × 'rule) × 'structure) stream ⇒ bool) ?stepSs2⟧ ⟹ ev (λks::'ord stream. shd (stl ks) ≠ shd ks) (smap (σ::'marker × 'structure ⇒ 'ord) (szip ?Ms2 (smap snd ?stepSs2)))› ‹epath (smap fst stepSs)› ‹follow (bs::bool stream) (Ms::'marker stream) (smap fst (stepSs::(('sequent × 'rule) × 'structure) stream))› ‹alw (P::(('sequent::type × 'rule::type) × 'structure::type) stream ⇒ bool) (stepSs::(('sequent::type × 'rule::type) × 'structure::type) stream)›*) have "ev (λks. shd (stl ks) ≠ shd ks) (smap σ (szip (stl Ms) (smap snd (stl stepSs))))" using step(3-5) (*‹epath (smap fst stepSs)› ‹follow bs Ms (smap fst stepSs)› ‹alw P stepSs›*) step(2)[of "stl stepSs" "stl Ms"] (*‹⟦epath (smap fst (stl stepSs)); follow (stl bs) (stl Ms) (smap fst (stl stepSs)); alw P (stl stepSs)⟧ ⟹ ev (λks. shd (stl ks) ≠ shd ks) (smap σ (szip (stl Ms) (smap snd (stl stepSs))))›*) by auto thus "?case" (*goal: ‹ev (λks. shd (stl ks) ≠ shd ks) (smap σ (szip Ms (smap snd stepSs)))›*) by auto qed next (*goal: ‹⋀bs Ms stepSs. ⟦epath (smap fst stepSs); follow bs Ms (smap fst stepSs); alw P stepSs; infDecr bs; ¬ alw (ev (λks. shd (stl ks) ≠ shd ks)) (stl (smap σ (szip Ms (smap snd stepSs))))⟧ ⟹ ∃bs Msa stepSsa. stl (smap σ (szip Ms (smap snd stepSs))) = smap σ (szip Msa (smap snd stepSsa)) ∧ epath (smap fst stepSsa) ∧ follow bs Msa (smap fst stepSsa) ∧ alw P stepSsa ∧ infDecr bs›*) case (stl bs Ms stepSs) (*‹epath (smap fst stepSs)› ‹follow bs Ms (smap fst stepSs)› ‹alw P stepSs› ‹infDecr bs› ‹¬ alw (ev (λks. shd (stl ks) ≠ shd ks)) (stl (smap σ (szip Ms (smap snd stepSs))))›*) thus "?case" (*goal: ‹∃bs Ms stepSs. stl (smap σ (szip Ms (smap snd stepSs))) = smap σ (szip Ms (smap snd stepSs)) ∧ epath (smap fst stepSs) ∧ follow bs Ms (smap fst stepSs) ∧ alw P stepSs ∧ infDecr bs›*) apply (intro exI[of _ "stl bs"] (*‹?P (stl bs) ⟹ ∃x. ?P x›*) exI[of _ "stl Ms"] (*‹?P (stl Ms) ⟹ ∃x. ?P x›*) exI[of _ "stl stepSs"] (*‹?P (stl stepSs) ⟹ ∃x. ?P x›*)) (*goal: ‹∃bs Ms stepSs. stl (smap σ (szip Ms (smap snd stepSs))) = smap σ (szip Ms (smap snd stepSs)) ∧ epath (smap fst stepSs) ∧ follow bs Ms (smap fst stepSs) ∧ alw P stepSs ∧ infDecr bs›*) by (auto elim: epath.cases (*‹⟦epath ?a; ⋀steps sl. ⟦?a = steps; snd (shd steps) ∈ R; fst (shd (stl steps)) |∈| sl; effStep (shd steps) sl; epath (stl steps)⟧ ⟹ ?P⟧ ⟹ ?P›*)) qed qed qed definition "ks ≡ SOME ks. alw (λks. (shd (stl ks), shd ks) ∈ Ord) ks ∧ alw (ev (λks. shd (stl ks) ≠ shd ks)) ks" lemma alw_ks: "alw (λks. (shd (stl ks), shd ks) ∈ Ord) ks" and alw_ev_ks: "alw (ev (λks. shd (stl ks) ≠ shd ks)) ks" unfolding ks_def (*goals: 1. ‹alw (λks. (shd (stl ks), shd ks) ∈ Ord) (SOME ks. alw (λks. (shd (stl ks), shd ks) ∈ Ord) ks ∧ alw (ev (λks. shd (stl ks) ≠ shd ks)) ks)› 2. ‹alw (ev (λks. shd (stl ks) ≠ shd ks)) (SOME ks. alw (λks. (shd (stl ks), shd ks) ∈ Ord) ks ∧ alw (ev (λks. shd (stl ks) ≠ shd ks)) ks)›*) using alw_ev_Ord (*‹(⋀ks. ⟦alw (λks. (shd (stl ks), shd ks) ∈ Ord) ks; alw (ev (λks. shd (stl ks) ≠ shd ks)) ks⟧ ⟹ ?thesis) ⟹ ?thesis›*) someI_ex[of "λks. alw (λks. (shd (stl ks), shd ks) ∈ Ord) ks ∧ alw (ev (λks. shd (stl ks) ≠ shd ks)) ks"] (*‹∃x. alw (λks. (shd (stl ks), shd ks) ∈ Ord) x ∧ alw (ev (λks. shd (stl ks) ≠ shd ks)) x ⟹ alw (λks. (shd (stl ks), shd ks) ∈ Ord) (SOME x. alw (λks. (shd (stl ks), shd ks) ∈ Ord) x ∧ alw (ev (λks. shd (stl ks) ≠ shd ks)) x) ∧ alw (ev (λks. shd (stl ks) ≠ shd ks)) (SOME x. alw (λks. (shd (stl ks), shd ks) ∈ Ord) x ∧ alw (ev (λks. shd (stl ks) ≠ shd ks)) x)›*) apply - (*goals: 1. ‹⟦⋀thesis. (⋀ks. ⟦alw (λks. (shd (stl ks), shd ks) ∈ Ord) ks; alw (ev (λks. shd (stl ks) ≠ shd ks)) ks⟧ ⟹ thesis) ⟹ thesis; ∃x. alw (λks. (shd (stl ks), shd ks) ∈ Ord) x ∧ alw (ev (λks. shd (stl ks) ≠ shd ks)) x ⟹ alw (λks. (shd (stl ks), shd ks) ∈ Ord) (SOME x. alw (λks. (shd (stl ks), shd ks) ∈ Ord) x ∧ alw (ev (λks. shd (stl ks) ≠ shd ks)) x) ∧ alw (ev (λks. shd (stl ks) ≠ shd ks)) (SOME x. alw (λks. (shd (stl ks), shd ks) ∈ Ord) x ∧ alw (ev (λks. shd (stl ks) ≠ shd ks)) x)⟧ ⟹ alw (λks. (shd (stl ks), shd ks) ∈ Ord) (SOME ks. alw (λks. (shd (stl ks), shd ks) ∈ Ord) ks ∧ alw (ev (λks. shd (stl ks) ≠ shd ks)) ks)› 2. ‹⟦⋀thesis. (⋀ks. ⟦alw (λks. (shd (stl ks), shd ks) ∈ Ord) ks; alw (ev (λks. shd (stl ks) ≠ shd ks)) ks⟧ ⟹ thesis) ⟹ thesis; ∃x. alw (λks. (shd (stl ks), shd ks) ∈ Ord) x ∧ alw (ev (λks. shd (stl ks) ≠ shd ks)) x ⟹ alw (λks. (shd (stl ks), shd ks) ∈ Ord) (SOME x. alw (λks. (shd (stl ks), shd ks) ∈ Ord) x ∧ alw (ev (λks. shd (stl ks) ≠ shd ks)) x) ∧ alw (ev (λks. shd (stl ks) ≠ shd ks)) (SOME x. alw (λks. (shd (stl ks), shd ks) ∈ Ord) x ∧ alw (ev (λks. shd (stl ks) ≠ shd ks)) x)⟧ ⟹ alw (ev (λks. shd (stl ks) ≠ shd ks)) (SOME ks. alw (λks. (shd (stl ks), shd ks) ∈ Ord) ks ∧ alw (ev (λks. shd (stl ks) ≠ shd ks)) ks)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . abbreviation decr where "decr ≡ decr0 Ord" lemmas decr_simps = decr0.code[of Ord] context fixes js assumes a: "alw (λjs. (shd (stl js), shd js) ∈ Ord) js" and ae: "alw (ev (λjs. shd (stl js) ≠ shd js)) js" begin lemma decr_ev: assumes m: "(shd js, m) ∈ Ord" shows "ev (λjs. (shd js, m) ∈ Ord ∧ shd js ≠ m) js" (is "ev (λjs. ?φ m js) js") proof (-) (*goal: ‹ev (λjs. (shd js, m) ∈ Ord ∧ shd js ≠ m) js›*) have "ev (λjs. shd (stl js) ≠ shd js) js" using ae (*‹alw (ev (λjs. shd (stl js) ≠ shd js)) js›*) by auto thus "?thesis" (*goal: ‹ev (λjs. (shd js, m) ∈ Ord ∧ shd js ≠ m) js›*) using a (*‹alw (λjs. (shd (stl js), shd js) ∈ Ord) js›*) m (*‹(shd js, m) ∈ Ord›*) proof (induction) (*goals: 1. ‹⋀xs. ⟦shd (stl xs) ≠ shd xs; alw (λjs. (shd (stl js), shd js) ∈ Ord) xs; (shd xs, m) ∈ Ord⟧ ⟹ ev (λjs. (shd js, m) ∈ Ord ∧ shd js ≠ m) xs› 2. ‹⋀xs. ⟦ev (λjs. shd (stl js) ≠ shd js) (stl xs); ⟦alw (λjs. (shd (stl js), shd js) ∈ Ord) (stl xs); (shd (stl xs), m) ∈ Ord⟧ ⟹ ev (λjs. (shd js, m) ∈ Ord ∧ shd js ≠ m) (stl xs); alw (λjs. (shd (stl js), shd js) ∈ Ord) xs; (shd xs, m) ∈ Ord⟧ ⟹ ev (λjs. (shd js, m) ∈ Ord ∧ shd js ≠ m) xs›*) case (base ls) (*‹shd (stl ls) ≠ shd ls› ‹alw (λjs. (shd (stl js), shd js) ∈ Ord) ls› ‹(shd ls, m) ∈ Ord›*) hence "ev (?φ (shd ls)) ls" by auto moreover have "⋀js. ?φ (shd ls) js ⟹ ?φ m js" using ‹(shd ls, m) ∈ Ord› (*‹(shd ls, m) ∈ Ord›*) Ord (*‹well_order Ord›*) unfolding well_order_on_defs (*goal: ‹⋀js. (shd js, shd ls) ∈ Ord ∧ shd js ≠ shd ls ⟹ (shd js, m) ∈ Ord ∧ shd js ≠ m›*) by blast ultimately show "?case" (*goal: ‹ev (λjs. (shd js, m) ∈ Ord ∧ shd js ≠ m) ls›*) using ev_mono[of "?φ (shd ls)" _ "?φ m"] (*‹⟦ev (λa. (shd a, shd ls) ∈ Ord ∧ shd a ≠ shd ls) ?xs; ⋀xs. (shd xs, shd ls) ∈ Ord ∧ shd xs ≠ shd ls ⟹ (shd xs, m) ∈ Ord ∧ shd xs ≠ m⟧ ⟹ ev (λa. (shd a, m) ∈ Ord ∧ shd a ≠ m) ?xs›*) by auto qed (auto) (*solved the remaining goal: ‹⋀xs. ⟦ev (λjs. shd (stl js) ≠ shd js) (stl xs); ⟦alw (λjs. (shd (stl js), shd js) ∈ Ord) (stl xs); (shd (stl xs), m) ∈ Ord⟧ ⟹ ev (λjs. (shd js, m) ∈ Ord ∧ shd js ≠ m) (stl xs); alw (λjs. (shd (stl js), shd js) ∈ Ord) xs; (shd xs, m) ∈ Ord⟧ ⟹ ev (λjs. (shd js, m) ∈ Ord ∧ shd js ≠ m) xs›*) qed lemma decr_simps_diff[simp]: assumes m: "(shd js, m) ∈ Ord" and "shd js ≠ m" shows "decr m js = shd js ## decr (shd js) js" using decr_ev[OF m] (*‹ev (λjs. (shd js, m) ∈ Ord ∧ shd js ≠ m) js›*) assms (*‹(shd js, m) ∈ Ord› ‹shd js ≠ m›*) apply (subst decr_simps (*‹decr ?minSoFar ?js = (if ¬ ev (λjs. (shd js, ?minSoFar) ∈ Ord ∧ shd js ≠ ?minSoFar) ?js then undefined else if (shd ?js, ?minSoFar) ∈ Ord ∧ shd ?js ≠ ?minSoFar then shd ?js ## decr (shd ?js) ?js else decr ?minSoFar (stl ?js))›*)) (*goal: ‹decr m js = shd js ## decr (shd js) js›*) by simp lemma decr_simps_eq[simp]: "decr (shd js) js = decr (shd js) (stl js)" proof (-) (*goal: ‹decr (shd js) js = decr (shd js) (stl js)›*) have m: "(shd js, shd js) ∈ Ord" using Ord (*‹well_order Ord›*) unfolding well_order_on_def linear_order_on_def partial_order_on_def preorder_on_def refl_on_def (*goal: ‹(shd js, shd js) ∈ Ord›*) by auto show "?thesis" (*goal: ‹decr (shd (js::'ord stream)) js = decr (shd js) (stl js)›*) using decr_ev[OF m] (*‹ev (λjsa. (shd jsa, shd js) ∈ Ord ∧ shd jsa ≠ shd js) js›*) apply (subst decr_simps (*‹decr (?minSoFar::'ord) (?js::'ord stream) = (if ¬ ev (λjs::'ord stream. (shd js, ?minSoFar) ∈ (Ord::('ord × 'ord) set) ∧ shd js ≠ ?minSoFar) ?js then undefined else if (shd ?js, ?minSoFar) ∈ Ord ∧ shd ?js ≠ ?minSoFar then shd ?js ## decr (shd ?js) ?js else decr ?minSoFar (stl ?js))›*)) (*goal: ‹decr (shd js) js = decr (shd js) (stl js)›*) by simp qed end (* context *) lemma stl_decr: assumes a: "alw (λjs. (shd (stl js), shd js) ∈ Ord) js" and ae: "alw (ev (λjs. shd (stl js) ≠ shd js)) js" and m: "(shd js, m) ∈ Ord" shows "∃js1 js2. js = js1 @- js2 ∧ set js1 ⊆ {m} ∧ (shd js2, m) ∈ Ord ∧ shd js2 ≠ m ∧ shd (decr m js) = shd js2 ∧ stl (decr m js) = decr (shd js2) js2" (is "∃js1 js2. ?φ js js1 js2") using decr_ev[OF assms] (*‹ev (λjs::'ord stream. (shd js, m::'ord) ∈ (Ord::('ord × 'ord) set) ∧ shd js ≠ m) (js::'ord stream)›*) m (*‹(shd js, m) ∈ Ord›*) a (*‹alw (λjs. (shd (stl js), shd js) ∈ Ord) js›*) ae (*‹alw (ev (λjs. shd (stl js) ≠ shd js)) js›*) proof (induction rule: ev_induct_strong (*‹⟦ev (?φ::?'a stream ⇒ bool) (?x::?'a stream); ⋀xs::?'a stream. ?φ xs ⟹ (?P::?'a stream ⇒ bool) xs; ⋀xs::?'a stream. ⟦ev ?φ (stl xs); ¬ ?φ xs; ?P (stl xs)⟧ ⟹ ?P xs⟧ ⟹ ?P ?x›*)) (*goals: 1. ‹⋀xs. ⟦(shd xs, m) ∈ Ord ∧ shd xs ≠ m; (shd xs, m) ∈ Ord; alw (λjs. (shd (stl js), shd js) ∈ Ord) xs; alw (ev (λjs. shd (stl js) ≠ shd js)) xs⟧ ⟹ ∃js1 js2. xs = js1 @- js2 ∧ set js1 ⊆ {m} ∧ (shd js2, m) ∈ Ord ∧ shd js2 ≠ m ∧ shd (decr m xs) = shd js2 ∧ stl (decr m xs) = decr (shd js2) js2› 2. ‹⋀xs. ⟦ev (λjs. (shd js, m) ∈ Ord ∧ shd js ≠ m) (stl xs); ¬ ((shd xs, m) ∈ Ord ∧ shd xs ≠ m); ⟦(shd (stl xs), m) ∈ Ord; alw (λjs. (shd (stl js), shd js) ∈ Ord) (stl xs); alw (ev (λjs. shd (stl js) ≠ shd js)) (stl xs)⟧ ⟹ ∃js1 js2. stl xs = js1 @- js2 ∧ set js1 ⊆ {m} ∧ (shd js2, m) ∈ Ord ∧ shd js2 ≠ m ∧ shd (decr m (stl xs)) = shd js2 ∧ stl (decr m (stl xs)) = decr (shd js2) js2; (shd xs, m) ∈ Ord; alw (λjs. (shd (stl js), shd js) ∈ Ord) xs; alw (ev (λjs. shd (stl js) ≠ shd js)) xs⟧ ⟹ ∃js1 js2. xs = js1 @- js2 ∧ set js1 ⊆ {m} ∧ (shd js2, m) ∈ Ord ∧ shd js2 ≠ m ∧ shd (decr m xs) = shd js2 ∧ stl (decr m xs) = decr (shd js2) js2›*) case (base js) (*‹(shd js, m) ∈ Ord ∧ shd js ≠ m› ‹(shd js, m) ∈ Ord› ‹alw (λjs. (shd (stl js), shd js) ∈ Ord) js› ‹alw (ev (λjs. shd (stl js) ≠ shd js)) js›*) thus "?case" (*goal: ‹∃js1 js2. js = js1 @- js2 ∧ set js1 ⊆ {m} ∧ (shd js2, m) ∈ Ord ∧ shd js2 ≠ m ∧ shd (decr m js) = shd js2 ∧ stl (decr m js) = decr (shd js2) js2›*) apply (intro exI[of _ "[]"] (*‹?P [] ⟹ ∃x. ?P x›*) exI[of _ js] (*‹?P js ⟹ ∃x. ?P x›*)) (*goal: ‹∃js1 js2. js = js1 @- js2 ∧ set js1 ⊆ {m} ∧ (shd js2, m) ∈ Ord ∧ shd js2 ≠ m ∧ shd (decr m js) = shd js2 ∧ stl (decr m js) = decr (shd js2) js2›*) by auto next (*goal: ‹⋀xs::'ord stream. ⟦ev (λjs::'ord stream. (shd js, m::'ord) ∈ (Ord::('ord × 'ord) set) ∧ shd js ≠ m) (stl xs); ¬ ((shd xs, m) ∈ Ord ∧ shd xs ≠ m); ⟦(shd (stl xs), m) ∈ Ord; alw (λjs::'ord stream. (shd (stl js), shd js) ∈ Ord) (stl xs); alw (ev (λjs::'ord stream. shd (stl js) ≠ shd js)) (stl xs)⟧ ⟹ ∃(js1::'ord list) js2::'ord stream. stl xs = js1 @- js2 ∧ set js1 ⊆ {m} ∧ (shd js2, m) ∈ Ord ∧ shd js2 ≠ m ∧ shd (decr m (stl xs)) = shd js2 ∧ stl (decr m (stl xs)) = decr (shd js2) js2; (shd xs, m) ∈ Ord; alw (λjs::'ord stream. (shd (stl js), shd js) ∈ Ord) xs; alw (ev (λjs::'ord stream. shd (stl js) ≠ shd js)) xs⟧ ⟹ ∃(js1::'ord list) js2::'ord stream. xs = js1 @- js2 ∧ set js1 ⊆ {m} ∧ (shd js2, m) ∈ Ord ∧ shd js2 ≠ m ∧ shd (decr m xs) = shd js2 ∧ stl (decr m xs) = decr (shd js2) js2›*) case (step js) (*‹ev (λjs. (shd js, m) ∈ Ord ∧ shd js ≠ m) (stl js)› ‹¬ ((shd js, m) ∈ Ord ∧ shd js ≠ m)› ‹⟦(shd (stl js), m) ∈ Ord; alw (λjs. (shd (stl js), shd js) ∈ Ord) (stl js); alw (ev (λjs. shd (stl js) ≠ shd js)) (stl js)⟧ ⟹ ∃js1 js2. stl js = js1 @- js2 ∧ set js1 ⊆ {m} ∧ (shd js2, m) ∈ Ord ∧ shd js2 ≠ m ∧ shd (decr m (stl js)) = shd js2 ∧ stl (decr m (stl js)) = decr (shd js2) js2› ‹(shd (js::'ord stream), m::'ord) ∈ (Ord::('ord × 'ord) set)› ‹alw (λjs. (shd (stl js), shd js) ∈ Ord) js› ‹alw (ev (λjs::'ord::type stream. shd (stl js) ≠ shd js)) (js::'ord::type stream)›*) then obtain js1 and js2 where 1: "?φ (stl js) js1 js2" and [simp]: "shd js = m" (*goal: ‹(⋀js1 js2. ⟦stl js = js1 @- js2 ∧ set js1 ⊆ {m} ∧ (shd js2, m) ∈ Ord ∧ shd js2 ≠ m ∧ shd (decr m (stl js)) = shd js2 ∧ stl (decr m (stl js)) = decr (shd js2) js2; shd js = m⟧ ⟹ thesis) ⟹ thesis›*) by auto thus "?case" (*goal: ‹∃js1 js2. js = js1 @- js2 ∧ set js1 ⊆ {m} ∧ (shd js2, m) ∈ Ord ∧ shd js2 ≠ m ∧ shd (decr m js) = shd js2 ∧ stl (decr m js) = decr (shd js2) js2›*) apply (intro exI[of _ "shd js # js1"] (*‹?P (shd js # js1) ⟹ ∃x. ?P x›*) exI[of _ js2] (*‹?P js2 ⟹ ∃x. ?P x›*)) (*goal: ‹∃(js1::'ord list) js2::'ord stream. (js::'ord stream) = js1 @- js2 ∧ set js1 ⊆ {m::'ord} ∧ (shd js2, m) ∈ (Ord::('ord × 'ord) set) ∧ shd js2 ≠ m ∧ shd (decr m js) = shd js2 ∧ stl (decr m js) = decr (shd js2) js2›*) apply simp (*goal: ‹⟦stl js = js1 @- js2 ∧ set js1 ⊆ {m} ∧ (shd js2, m) ∈ Ord ∧ shd js2 ≠ m ∧ shd (decr m (stl js)) = shd js2 ∧ stl (decr m (stl js)) = decr (shd js2) js2; shd js = m⟧ ⟹ js = (shd js # js1) @- js2 ∧ set (shd js # js1) ⊆ {m} ∧ (shd js2, m) ∈ Ord ∧ shd js2 ≠ m ∧ shd (decr m js) = shd js2 ∧ stl (decr m js) = decr (shd js2) js2›*) by (metis (lifting) decr_simps_eq (*‹⟦alw (λjs::'ord stream. (shd (stl js), shd js) ∈ (Ord::('ord × 'ord) set)) (?js::'ord stream); alw (ev (λjs::'ord stream. shd (stl js) ≠ shd js)) ?js⟧ ⟹ decr (shd ?js) ?js = decr (shd ?js) (stl ?js)›*) step( (*‹¬ ((shd (js::'ord stream), m::'ord) ∈ (Ord::('ord × 'ord) set) ∧ shd js ≠ m)› ‹(shd (js::'ord stream), m::'ord) ∈ (Ord::('ord × 'ord) set)› ‹alw (λjs::'ord stream. (shd (stl js), shd js) ∈ (Ord::('ord × 'ord) set)) (js::'ord stream)› ‹alw (ev (λjs::'ord stream. shd (stl js) ≠ shd js)) (js::'ord stream)›*) 2,4,5,6) stream.collapse (*‹shd (?stream::?'a stream) ## stl ?stream = ?stream›*)) qed corollary stl_decr_shd: assumes a: "alw (λjs. (shd (stl js), shd js) ∈ Ord) js" and ae: "alw (ev (λjs. shd (stl js) ≠ shd js)) js" shows "∃js1 js2. js = js1 @- js2 ∧ set js1 ⊆ {shd js} ∧ (shd js2, shd js) ∈ Ord ∧ shd js2 ≠ shd js ∧ shd (decr (shd js) js) = shd js2 ∧ stl (decr (shd js) js) = decr (shd js2) js2" using Ord (*‹well_order (Ord::('ord × 'ord) set)›*) unfolding well_order_on_defs (*goal: ‹∃(js1::'ord::type list) js2::'ord::type stream. (js::'ord::type stream) = js1 @- js2 ∧ set js1 ⊆ {shd js} ∧ (shd js2, shd js) ∈ (Ord::('ord::type × 'ord::type) set) ∧ shd js2 ≠ shd js ∧ shd (decr (shd js) js) = shd js2 ∧ stl (decr (shd js) js) = decr (shd js2) js2›*) apply (intro stl_decr[OF assms] (*‹(shd js, ?m) ∈ Ord ⟹ ∃js1 js2. js = js1 @- js2 ∧ set js1 ⊆ {?m} ∧ (shd js2, ?m) ∈ Ord ∧ shd js2 ≠ ?m ∧ shd (decr ?m js) = shd js2 ∧ stl (decr ?m js) = decr (shd js2) js2›*)) (*goal: ‹∃js1 js2. js = js1 @- js2 ∧ set js1 ⊆ {shd js} ∧ (shd js2, shd js) ∈ Ord ∧ shd js2 ≠ shd js ∧ shd (decr (shd js) js) = shd js2 ∧ stl (decr (shd js) js) = decr (shd js2) js2›*) by blast lemma decr: assumes a: "alw (λjs. (shd (stl js), shd js) ∈ Ord) js" (is "?a js") and ae: "alw (ev (λjs. shd (stl js) ≠ shd js)) js" (is "?ae js") shows "alw (λjs. (shd (stl js), shd js) ∈ Ord ∧ shd (stl js) ≠ shd js) (decr (shd js) js)" (is "alw ?φ _") proof (-) (*goal: ‹alw (λjs. (shd (stl js), shd js) ∈ Ord ∧ shd (stl js) ≠ shd js) (decr (shd js) js)›*) let ?ξ = "λls js. ls = decr (shd js) js ∧ ?a js ∧ ?ae js" { fix ls assume "∃js. ?ξ ls js" (*‹∃js::'ord stream. (ls::'ord stream) = decr (shd js) js ∧ alw (λjs::'ord stream. (shd (stl js), shd js) ∈ (Ord::('ord × 'ord) set)) js ∧ alw (ev (λjs::'ord stream. shd (stl js) ≠ shd js)) js›*) hence "alw ?φ ls" proof (elim alw_coinduct (*‹⟦?X ?x; ⋀x. ?X x ⟹ ?φ x; ⋀x. ⟦?X x; ¬ alw ?φ (stl x)⟧ ⟹ ?X (stl x)⟧ ⟹ alw ?φ ?x›*)) (*goals: 1. ‹⋀x::'ord stream. ∃js::'ord stream. x = decr (shd js) js ∧ alw (λjs::'ord stream. (shd (stl js), shd js) ∈ (Ord::('ord × 'ord) set)) js ∧ alw (ev (λjs::'ord stream. shd (stl js) ≠ shd js)) js ⟹ (shd (stl x), shd x) ∈ Ord ∧ shd (stl x) ≠ shd x› 2. ‹⋀x::'ord stream. ⟦∃js::'ord stream. x = decr (shd js) js ∧ alw (λjs::'ord stream. (shd (stl js), shd js) ∈ (Ord::('ord × 'ord) set)) js ∧ alw (ev (λjs::'ord stream. shd (stl js) ≠ shd js)) js; ¬ alw (λjs::'ord stream. (shd (stl js), shd js) ∈ Ord ∧ shd (stl js) ≠ shd js) (stl x)⟧ ⟹ ∃js::'ord stream. stl x = decr (shd js) js ∧ alw (λjs::'ord stream. (shd (stl js), shd js) ∈ Ord) js ∧ alw (ev (λjs::'ord stream. shd (stl js) ≠ shd js)) js›*) fix ls assume "∃js. ?ξ ls js" (*‹∃js::'ord stream. (ls::'ord stream) = decr (shd js) js ∧ alw (λjs::'ord stream. (shd (stl js), shd js) ∈ (Ord::('ord × 'ord) set)) js ∧ alw (ev (λjs::'ord stream. shd (stl js) ≠ shd js)) js›*) then obtain js where 1: "?ξ ls js" (*goal: ‹(⋀js. ls = decr (shd js) js ∧ alw (λjs. (shd (stl js), shd js) ∈ Ord) js ∧ alw (ev (λjs. shd (stl js) ≠ shd js)) js ⟹ thesis) ⟹ thesis›*) by auto then obtain js1 and js2 where js: "js = js1 @- js2 ∧ set js1 ⊆ {shd js} ∧ (shd js2, shd js) ∈ Ord ∧ shd js2 ≠ shd js ∧ shd ls = shd js2 ∧ stl ls = decr (shd js2) js2" (*goal: ‹(⋀js1 js2. js = js1 @- js2 ∧ set js1 ⊆ {shd js} ∧ (shd js2, shd js) ∈ Ord ∧ shd js2 ≠ shd js ∧ shd ls = shd js2 ∧ stl ls = decr (shd js2) js2 ⟹ thesis) ⟹ thesis›*) using stl_decr_shd (*‹⟦alw (λjs::'ord stream. (shd (stl js), shd js) ∈ (Ord::('ord × 'ord) set)) (?js::'ord stream); alw (ev (λjs::'ord stream. shd (stl js) ≠ shd js)) ?js⟧ ⟹ ∃(js1::'ord list) js2::'ord stream. ?js = js1 @- js2 ∧ set js1 ⊆ {shd ?js} ∧ (shd js2, shd ?js) ∈ Ord ∧ shd js2 ≠ shd ?js ∧ shd (decr (shd ?js) ?js) = shd js2 ∧ stl (decr (shd ?js) ?js) = decr (shd js2) js2›*) by blast then obtain js3 and js4 where js2: "js2 = js3 @- js4 ∧ set js3 ⊆ {shd js2} ∧ (shd js4, shd js2) ∈ Ord ∧ shd js4 ≠ shd js2 ∧ shd (decr (shd js2) js2) = shd js4 ∧ stl ((decr (shd js2) js2)) = decr (shd js4) js4" (*goal: ‹(⋀js3 js4. js2 = js3 @- js4 ∧ set js3 ⊆ {shd js2} ∧ (shd js4, shd js2) ∈ Ord ∧ shd js4 ≠ shd js2 ∧ shd (decr (shd js2) js2) = shd js4 ∧ stl (decr (shd js2) js2) = decr (shd js4) js4 ⟹ thesis) ⟹ thesis›*) using stl_decr_shd[of js2] (*‹⟦alw (λjs. (shd (stl js), shd js) ∈ Ord) js2; alw (ev (λjs. shd (stl js) ≠ shd js)) js2⟧ ⟹ ∃js1 js2a. js2 = js1 @- js2a ∧ set js1 ⊆ {shd js2} ∧ (shd js2a, shd js2) ∈ Ord ∧ shd js2a ≠ shd js2 ∧ shd (decr (shd js2) js2) = shd js2a ∧ stl (decr (shd js2) js2) = decr (shd js2a) js2a›*) a (*‹alw (λjs::'ord stream. (shd (stl js), shd js) ∈ (Ord::('ord × 'ord) set)) (js::'ord stream)›*) ae (*‹alw (ev (λjs. shd (stl js) ≠ shd js)) js›*) using "1" (*‹ls = decr (shd js) js ∧ alw (λjs. (shd (stl js), shd js) ∈ Ord) js ∧ alw (ev (λjs. shd (stl js) ≠ shd js)) js›*) alw_shift (*‹alw (?φ::?'a::type stream ⇒ bool) ((?xl::?'a::type list) @- (?xs::?'a::type stream)) ⟹ alw ?φ ?xs›*) by blast show "?φ ls" using "1" (*‹ls = decr (shd js) js ∧ alw (λjs. (shd (stl js), shd js) ∈ Ord) js ∧ alw (ev (λjs. shd (stl js) ≠ shd js)) js›*) js (*‹js = js1 @- js2 ∧ set js1 ⊆ {shd js} ∧ (shd js2, shd js) ∈ Ord ∧ shd js2 ≠ shd js ∧ shd ls = shd js2 ∧ stl ls = decr (shd js2) js2›*) js2 (*‹js2 = js3 @- js4 ∧ set js3 ⊆ {shd js2} ∧ (shd js4, shd js2) ∈ Ord ∧ shd js4 ≠ shd js2 ∧ shd (decr (shd js2) js2) = shd js4 ∧ stl (decr (shd js2) js2) = decr (shd js4) js4›*) by metis qed (metis (no_types, lifting) alw_shift (*‹alw (?φ::?'a::type stream ⇒ bool) ((?xl::?'a::type list) @- (?xs::?'a::type stream)) ⟹ alw ?φ ?xs›*) stl_decr_shd (*‹⟦alw (λjs::'ord::type stream. (shd (stl js), shd js) ∈ (Ord::('ord::type × 'ord::type) set)) (?js::'ord::type stream); alw (ev (λjs::'ord::type stream. shd (stl js) ≠ shd js)) ?js⟧ ⟹ ∃(js1::'ord::type list) js2::'ord::type stream. ?js = js1 @- js2 ∧ set js1 ⊆ {shd ?js} ∧ (shd js2, shd ?js) ∈ Ord ∧ shd js2 ≠ shd ?js ∧ shd (decr (shd ?js) ?js) = shd js2 ∧ stl (decr (shd ?js) ?js) = decr (shd js2) js2›*)) (*solved the remaining goal: ‹⋀x. ⟦∃js. x = decr (shd js) js ∧ alw (λjs. (shd (stl js), shd js) ∈ Ord) js ∧ alw (ev (λjs. shd (stl js) ≠ shd js)) js; ¬ alw (λjs. (shd (stl js), shd js) ∈ Ord ∧ shd (stl js) ≠ shd js) (stl x)⟧ ⟹ ∃js. stl x = decr (shd js) js ∧ alw (λjs. (shd (stl js), shd js) ∈ Ord) js ∧ alw (ev (λjs. shd (stl js) ≠ shd js)) js›*) } thus "?thesis" (*goal: ‹alw (λjs. (shd (stl js), shd js) ∈ Ord ∧ shd (stl js) ≠ shd js) (decr (shd js) js)›*) using assms (*‹alw (λjs::'ord stream. (shd (stl js), shd js) ∈ (Ord::('ord × 'ord) set)) (js::'ord stream)› ‹alw (ev (λjs. shd (stl js) ≠ shd js)) js›*) by blast qed lemma alw_snth: assumes "alw (λxs. P (shd (stl xs)) (shd xs)) xs" shows "P (xs!!(Suc n)) (xs!! n)" using assms (*‹alw (λxs::'a stream. (P::'a ⇒ 'a ⇒ bool) (shd (stl xs)) (shd xs)) (xs::'a stream)›*) apply (induction n) (*goals: 1. ‹alw (λxs. P (shd (stl xs)) (shd xs)) xs ⟹ P (xs !! Suc 0) (xs !! 0)› 2. ‹⋀n. ⟦alw (λxs. P (shd (stl xs)) (shd xs)) xs ⟹ P (xs !! Suc n) (xs !! n); alw (λxs. P (shd (stl xs)) (shd xs)) xs⟧ ⟹ P (xs !! Suc (Suc n)) (xs !! Suc n)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*goal: ‹⋀n. ⟦alw (λxs. P (shd (stl xs)) (shd xs)) xs ⟹ P (xs !! Suc n) (xs !! n); alw (λxs. P (shd (stl xs)) (shd xs)) xs⟧ ⟹ P (xs !! Suc (Suc n)) (xs !! Suc n)›*) apply (metis (mono_tags) alw.cases (*‹⟦alw (?φ::?'a stream ⇒ bool) (?a::?'a stream); ⋀xs::?'a stream. ⟦?a = xs; ?φ xs; alw ?φ (stl xs)⟧ ⟹ ?P::bool⟧ ⟹ ?P›*) alw_iff_sdrop (*‹alw (?P::?'a stream ⇒ bool) (?ω::?'a stream) = (∀m::nat. ?P (sdrop m ?ω))›*) sdrop_simps( (*‹shd (sdrop (?n::nat) (?s::?'a stream)) = ?s !! ?n›*) 1) sdrop_stl (*‹sdrop (?n::nat) (stl (?s::?'a stream)) = stl (sdrop ?n ?s)›*)) (*proven 2 subgoals*) . lemma F: False proof (-) (*goal: ‹False›*) define ls where "ls = decr (shd ks) ks" have 0: "alw (λjs. (shd (stl js), shd js) ∈ Ord ∧ shd (stl js) ≠ shd js) ls" using decr[OF alw_ks alw_ev_ks] (*‹alw (λjs. (shd (stl js), shd js) ∈ Ord ∧ shd (stl js) ≠ shd js) (decr (shd ks) ks)›*) unfolding ls_def (*goal: ‹alw (λjs. (shd (stl js), shd js) ∈ Ord ∧ shd (stl js) ≠ shd js) (decr (shd ks) ks)›*) . define Q where "Q = range (snth ls)" let ?wf = Wellfounded.wf have Q: "Q ≠ {}" unfolding Q_def (*goal: ‹range ((!!) ls) ≠ {}›*) by auto have 1: "?wf (Ord - Id)" using Ord (*‹well_order Ord›*) unfolding well_order_on_def (*goal: ‹Wellfounded.wf ((Ord::('ord × 'ord) set) - Id)›*) by auto obtain q where q: "q ∈ Q" and 2: "∀q'. (q',q) ∈ Ord - Id ⟶ q' ∉ Q" (*goal: ‹(⋀q. ⟦q ∈ Q; ∀q'. (q', q) ∈ Ord - Id ⟶ q' ∉ Q⟧ ⟹ thesis) ⟹ thesis›*) using wfE_min[OF 1] (*‹⟦?x ∈ ?Q; ⋀z. ⟦z ∈ ?Q; ⋀y. (y, z) ∈ Ord - Id ⟹ y ∉ ?Q⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) Q (*‹Q ≠ {}›*) by auto obtain n where "ls!!n = q" (*goal: ‹(⋀n. ls !! n = q ⟹ thesis) ⟹ thesis›*) using q (*‹q ∈ Q›*) unfolding Q_def (*goal: ‹(⋀n. ls !! n = q ⟹ thesis) ⟹ thesis›*) by auto hence "(ls!!(Suc n),q) ∈ Ord - Id" using alw_snth[OF 0] (*‹(ls !! Suc ?n, ls !! ?n) ∈ Ord ∧ ls !! Suc ?n ≠ ls !! ?n›*) by auto thus False using "2" (*‹∀q'::'ord. (q', q::'ord) ∈ (Ord::('ord × 'ord) set) - Id ⟶ q' ∉ (Q::'ord set)›*) Q_def (*‹(Q::'ord set) = range ((!!) (ls::'ord stream))›*) by blast qed end (* context *) (* Main theorem: *) theorem infinite_soundness: assumes "wf t" and "good t" and "S ∈ structure" shows "sat S (fst (root t))" using F[OF assms] (*‹¬ sat S (fst (tree.root t)) ⟹ False›*) by auto end (* context Infinite_Soundness *) section ‹Soundness of Cyclic Proof Trees› (* Cyclic trees *) datatype (discs_sels) ('sequent, 'rule, 'link) ctree = Link 'link | cNode "('sequent,'rule) step" "('sequent, 'rule, 'link) ctree fset" corecursive treeOf where "treeOf pointsTo ct = (if ∃l l'. pointsTo l = Link l' ― ‹makes sense only if backward links point to normal nodes, not to backwards links:› then undefined else (case ct of Link l ⇒ treeOf pointsTo (pointsTo l) |cNode step cts ⇒ Node step (fimage (treeOf pointsTo) cts) ) )" by (relation "measure (λ(p,t). case t of Link l' => Suc 0 | _ => 0)") (auto split: ctree.splits) declare treeOf.code[simp] context Infinite_Soundness begin context fixes pointsTo :: "'link ⇒ ('sequent, 'rule, 'link)ctree" assumes pointsTo: "∀l l'. pointsTo l ≠ Link l'" begin function seqOf where "seqOf (Link l) = seqOf (pointsTo l)" | "seqOf (cNode (s,r) _) = s" by pat_completeness auto termination by (relation "measure (λt. case t of Link l' => Suc 0 | _ => 0)") (auto split: ctree.splits simp: pointsTo) (* Note: Here, "inductive" instead of "coinductive" would not do! *) coinductive cwf where Node[intro!]: "cwf (pointsTo l) ⟹ cwf (Link l)" | cNode[intro]: "⟦r ∈ R; eff r s (fimage seqOf cts); ⋀ct'. ct' |∈| cts ⟹ cwf ct'⟧ ⟹ cwf (cNode (s,r) cts)" definition "cgood ct ≡ good (treeOf pointsTo ct)" lemma cwf_Link: "cwf (Link l) ⟷ cwf (pointsTo l)" by (auto elim: cwf.cases (*‹⟦cwf ?a; ⋀l. ⟦?a = Link l; cwf (pointsTo l)⟧ ⟹ ?P; ⋀r s cts. ⟦?a = cNode (s, r) cts; r ∈ R; eff r s (seqOf |`| cts); ⋀ct'. ct' |∈| cts ⟹ cwf ct'⟧ ⟹ ?P⟧ ⟹ ?P›*)) lemma cwf_cNode_seqOf: "cwf (cNode (s, r) cts) ⟹ eff r s (fimage seqOf cts)" by (auto elim: cwf.cases (*‹⟦cwf ?a; ⋀l. ⟦?a = Link l; cwf (pointsTo l)⟧ ⟹ ?P; ⋀r s cts. ⟦?a = cNode (s, r) cts; r ∈ R; eff r s (seqOf |`| cts); ⋀ct'. ct' |∈| cts ⟹ cwf ct'⟧ ⟹ ?P⟧ ⟹ ?P›*)) lemma treeOf_seqOf[simp]: "fst ∘ root ∘ treeOf pointsTo = seqOf" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹fst ∘ tree.root ∘ treeOf (pointsTo::'link ⇒ ('sequent, 'rule, 'link) ctree) = seqOf›*) proof (unfold o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*)) (*goal: ‹⋀x. fst (tree.root (treeOf pointsTo x)) = seqOf x›*) fix ct show "fst (root (treeOf pointsTo ct)) = seqOf ct" apply induct (*goals: 1. ‹⋀x::(?'a, (?'a, ?'c) ssig_tree_v0) sig_tree_v0. (⋀xa::(?'a, ?'c) ssig_tree_v0. xa ∈ set2_sig_tree_v0 x ⟹ fst (tree.root (treeOf (pointsTo::'link ⇒ ('sequent, 'rule, 'link) ctree) (ct::('sequent, 'rule, 'link) ctree))) = seqOf ct) ⟹ fst (tree.root (treeOf pointsTo ct)) = seqOf ct› 2. ‹⋀x::?'c. fst (tree.root (treeOf (pointsTo::'link ⇒ ('sequent, 'rule, 'link) ctree) (ct::('sequent, 'rule, 'link) ctree))) = seqOf ct› 3. ‹⋀x::?'a tree. fst (tree.root (treeOf (pointsTo::'link ⇒ ('sequent, 'rule, 'link) ctree) (ct::('sequent, 'rule, 'link) ctree))) = seqOf ct› discuss goal 1*) apply ((auto split: ctree.splits (*‹?P (case ?ctree of Link x ⇒ ?f1.0 x | cNode x xa ⇒ ?f2.0 x xa) = ((∀x1. ?ctree = Link x1 ⟶ ?P (?f1.0 x1)) ∧ (∀x21 x22. ?ctree = cNode x21 x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?ctree of Link x ⇒ ?f1.0 x | cNode x xa ⇒ ?f2.0 x xa) = (¬ ((∃x1. ?ctree = Link x1 ∧ ¬ ?P (?f1.0 x1)) ∨ (∃x21 x22. ?ctree = cNode x21 x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*) simp: pointsTo (*‹∀l l'. pointsTo l ≠ Link l'›*))[1]) (*discuss goal 2*) apply ((auto split: ctree.splits (*‹?P (case ?ctree of Link x ⇒ ?f1.0 x | cNode x xa ⇒ ?f2.0 x xa) = ((∀x1. ?ctree = Link x1 ⟶ ?P (?f1.0 x1)) ∧ (∀x21 x22. ?ctree = cNode x21 x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?ctree of Link x ⇒ ?f1.0 x | cNode x xa ⇒ ?f2.0 x xa) = (¬ ((∃x1. ?ctree = Link x1 ∧ ¬ ?P (?f1.0 x1)) ∨ (∃x21 x22. ?ctree = cNode x21 x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*) simp: pointsTo (*‹∀l l'. pointsTo l ≠ Link l'›*))[1]) (*discuss goal 3*) apply ((auto split: ctree.splits (*‹?P (case ?ctree of Link x ⇒ ?f1.0 x | cNode x xa ⇒ ?f2.0 x xa) = ((∀x1. ?ctree = Link x1 ⟶ ?P (?f1.0 x1)) ∧ (∀x21 x22. ?ctree = cNode x21 x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?ctree of Link x ⇒ ?f1.0 x | cNode x xa ⇒ ?f2.0 x xa) = (¬ ((∃x1. ?ctree = Link x1 ∧ ¬ ?P (?f1.0 x1)) ∨ (∃x21 x22. ?ctree = cNode x21 x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*) simp: pointsTo (*‹∀l l'. pointsTo l ≠ Link l'›*))[1]) (*proven 3 subgoals*) . qed lemma wf_treeOf: assumes "cwf ct" shows "wf (treeOf pointsTo ct)" proof (-) (*goal: ‹local.wf (treeOf (pointsTo::'link ⇒ ('sequent, 'rule, 'link) ctree) (ct::('sequent, 'rule, 'link) ctree))›*) { fix t let ?φ = "λct t. cwf ct ∧ t = treeOf pointsTo ct" assume "∃ct. ?φ ct t" (*‹∃ct::('sequent, 'rule, 'link) ctree. cwf ct ∧ (t::('sequent × 'rule) tree) = treeOf (pointsTo::'link ⇒ ('sequent, 'rule, 'link) ctree) ct›*) hence "wf t" apply (elim wf.coinduct (*‹⟦(?X::('sequent::type × 'rule::type) tree ⇒ bool) (?x::('sequent::type × 'rule::type) tree); ⋀x::('sequent::type × 'rule::type) tree. ?X x ⟹ ∃t::('sequent::type × 'rule::type) tree. x = t ∧ snd (tree.root t) ∈ R ∧ effStep (tree.root t) ((fst ∘ tree.root) |`| cont t) ∧ (∀x::('sequent::type × 'rule::type) tree. x |∈| cont t ⟶ ?X x ∨ local.wf x)⟧ ⟹ local.wf ?x›*)) (*goal: ‹local.wf (t::('sequent::type × 'rule::type) tree)›*) proof (safe) (*goal: ‹⋀x ct. cwf ct ⟹ ∃t. treeOf pointsTo ct = t ∧ snd (tree.root t) ∈ R ∧ effStep (tree.root t) ((fst ∘ tree.root) |`| cont t) ∧ (∀x. x |∈| cont t ⟶ (∃ct. cwf ct ∧ x = treeOf pointsTo ct) ∨ local.wf x)›*) fix ct let ?t = "treeOf pointsTo ct" assume ct: "cwf ct" (*‹cwf (ct::('sequent, 'rule, 'link) ctree)›*) show " ∃t. treeOf pointsTo ct = t ∧ snd (root t) ∈ R ∧ effStep (root t) (fimage (fst ∘ root) (cont t)) ∧ (∀t'. t' |∈| cont t ⟶ (∃ct'. ?φ ct' t') ∨ wf t')" proof (rule exI[of _ ?t] (*‹?P (treeOf pointsTo ct) ⟹ ∃x. ?P x›*), safe) (*goals: 1. ‹snd (tree.root (treeOf pointsTo ct)) ∈ R› 2. ‹effStep (tree.root (treeOf pointsTo ct)) ((fst ∘ tree.root) |`| cont (treeOf pointsTo ct))› 3. ‹⋀t'. ⟦t' |∈| cont (treeOf pointsTo ct); ¬ local.wf t'⟧ ⟹ ∃ct'. cwf ct' ∧ t' = treeOf pointsTo ct'›*) show "snd (root ?t) ∈ R" using pointsTo (*‹∀(l::'link) l'::'link. (pointsTo::'link ⇒ ('sequent, 'rule, 'link) ctree) l ≠ Link l'›*) ct (*‹cwf ct›*) by (auto elim: cwf.cases (*‹⟦cwf (?a::('sequent, 'rule, 'link) ctree); ⋀l::'link. ⟦?a = Link l; cwf ((pointsTo::'link ⇒ ('sequent, 'rule, 'link) ctree) l)⟧ ⟹ ?P::bool; ⋀(r::'rule) (s::'sequent) cts::('sequent, 'rule, 'link) ctree fset. ⟦?a = cNode (s, r) cts; r ∈ R; (eff::'rule ⇒ 'sequent ⇒ 'sequent fset ⇒ bool) r s (seqOf |`| cts); ⋀ct'::('sequent, 'rule, 'link) ctree. ct' |∈| cts ⟹ cwf ct'⟧ ⟹ ?P⟧ ⟹ ?P›*) split: ctree.splits (*‹(?P::?'a ⇒ bool) (case ?ctree::(?'sequent, ?'rule, ?'link) ctree of Link (x::?'link) ⇒ (?f1.0::?'link ⇒ ?'a) x | cNode (x::?'sequent × ?'rule) (xa::(?'sequent, ?'rule, ?'link) ctree fset) ⇒ (?f2.0::?'sequent × ?'rule ⇒ (?'sequent, ?'rule, ?'link) ctree fset ⇒ ?'a) x xa) = ((∀x1::?'link. ?ctree = Link x1 ⟶ ?P (?f1.0 x1)) ∧ (∀(x21::?'sequent × ?'rule) x22::(?'sequent, ?'rule, ?'link) ctree fset. ?ctree = cNode x21 x22 ⟶ ?P (?f2.0 x21 x22)))› ‹(?P::?'a ⇒ bool) (case ?ctree::(?'sequent, ?'rule, ?'link) ctree of Link (x::?'link) ⇒ (?f1.0::?'link ⇒ ?'a) x | cNode (x::?'sequent × ?'rule) (xa::(?'sequent, ?'rule, ?'link) ctree fset) ⇒ (?f2.0::?'sequent × ?'rule ⇒ (?'sequent, ?'rule, ?'link) ctree fset ⇒ ?'a) x xa) = (¬ ((∃x1::?'link. ?ctree = Link x1 ∧ ¬ ?P (?f1.0 x1)) ∨ (∃(x21::?'sequent × ?'rule) x22::(?'sequent, ?'rule, ?'link) ctree fset. ?ctree = cNode x21 x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*) simp: cwf_Link (*‹cwf (Link (?l::'link)) = cwf ((pointsTo::'link ⇒ ('sequent, 'rule, 'link) ctree) ?l)›*)) show "effStep (root ?t) (fimage (fst ∘ root) (cont ?t))" using pointsTo (*‹∀l l'. pointsTo l ≠ Link l'›*) ct (*‹cwf ct›*) by (auto elim: cwf.cases (*‹⟦cwf ?a; ⋀l. ⟦?a = Link l; cwf (pointsTo l)⟧ ⟹ ?P; ⋀r s cts. ⟦?a = cNode (s, r) cts; r ∈ R; eff r s (seqOf |`| cts); ⋀ct'. ct' |∈| cts ⟹ cwf ct'⟧ ⟹ ?P⟧ ⟹ ?P›*) split: ctree.splits (*‹?P (case ?ctree of Link x ⇒ ?f1.0 x | cNode x xa ⇒ ?f2.0 x xa) = ((∀x1. ?ctree = Link x1 ⟶ ?P (?f1.0 x1)) ∧ (∀x21 x22. ?ctree = cNode x21 x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?ctree of Link x ⇒ ?f1.0 x | cNode x xa ⇒ ?f2.0 x xa) = (¬ ((∃x1. ?ctree = Link x1 ∧ ¬ ?P (?f1.0 x1)) ∨ (∃x21 x22. ?ctree = cNode x21 x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*) simp: cwf_Link (*‹cwf (Link ?l) = cwf (pointsTo ?l)›*)) { fix t' assume t': "t' |∈| cont ?t" (*‹(t'::('sequent × 'rule) tree) |∈| cont (treeOf (pointsTo::'link ⇒ ('sequent, 'rule, 'link) ctree) (ct::('sequent, 'rule, 'link) ctree))›*) show "∃ct'. ?φ ct' t'" proof (cases ct) (*goals: 1. ‹⋀x1::'link::type. (ct::('sequent::type, 'rule::type, 'link::type) ctree) = Link x1 ⟹ ∃ct'::('sequent::type, 'rule::type, 'link::type) ctree. cwf ct' ∧ (t'::('sequent::type × 'rule::type) tree) = treeOf (pointsTo::'link::type ⇒ ('sequent::type, 'rule::type, 'link::type) ctree) ct'› 2. ‹⋀(x21::'sequent::type × 'rule::type) x22::('sequent::type, 'rule::type, 'link::type) ctree fset. (ct::('sequent::type, 'rule::type, 'link::type) ctree) = cNode x21 x22 ⟹ ∃ct'::('sequent::type, 'rule::type, 'link::type) ctree. cwf ct' ∧ (t'::('sequent::type × 'rule::type) tree) = treeOf (pointsTo::'link::type ⇒ ('sequent::type, 'rule::type, 'link::type) ctree) ct'›*) case (Link l) (*‹ct = Link l›*) then obtain s and r and cts where pl: "pointsTo l = cNode (s,r) cts" (*goal: ‹(⋀(s::'sequent) (r::'rule) cts::('sequent, 'rule, 'link) ctree fset. (pointsTo::'link ⇒ ('sequent, 'rule, 'link) ctree) (l::'link) = cNode (s, r) cts ⟹ thesis::bool) ⟹ thesis›*) using pointsTo (*‹∀l l'. pointsTo l ≠ Link l'›*) apply (cases "pointsTo l") (*goals: 1. ‹⋀x1. ⟦⋀s r cts. pointsTo l = cNode (s, r) cts ⟹ thesis; ct = Link l; ∀l l'. pointsTo l ≠ Link l'; pointsTo l = Link x1⟧ ⟹ thesis› 2. ‹⋀x21 x22. ⟦⋀s r cts. pointsTo l = cNode (s, r) cts ⟹ thesis; ct = Link l; ∀l l'. pointsTo l ≠ Link l'; pointsTo l = cNode x21 x22⟧ ⟹ thesis› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . obtain ct' where ct': "ct' |∈| cts" and "t' = treeOf pointsTo ct'" (*goal: ‹(⋀ct'. ⟦ct' |∈| cts; t' = treeOf pointsTo ct'⟧ ⟹ thesis) ⟹ thesis›*) using t' (*‹t' |∈| cont (treeOf pointsTo ct)›*) by (auto simp: Link (*‹ct = Link l›*) pl (*‹pointsTo l = cNode (s, r) cts›*) pointsTo (*‹∀l l'. pointsTo l ≠ Link l'›*) split: ctree.splits (*‹?P (case ?ctree of Link x ⇒ ?f1.0 x | cNode x xa ⇒ ?f2.0 x xa) = ((∀x1. ?ctree = Link x1 ⟶ ?P (?f1.0 x1)) ∧ (∀x21 x22. ?ctree = cNode x21 x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?ctree of Link x ⇒ ?f1.0 x | cNode x xa ⇒ ?f2.0 x xa) = (¬ ((∃x1. ?ctree = Link x1 ∧ ¬ ?P (?f1.0 x1)) ∨ (∃x21 x22. ?ctree = cNode x21 x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*)) moreover have "cwf ct'" using ct' (*‹(ct'::('sequent::type, 'rule::type, 'link::type) ctree) |∈| (cts::('sequent::type, 'rule::type, 'link::type) ctree fset)›*) ct (*‹cwf ct›*) pl (*‹(pointsTo::'link ⇒ ('sequent, 'rule, 'link) ctree) (l::'link) = cNode (s::'sequent, r::'rule) (cts::('sequent, 'rule, 'link) ctree fset)›*) unfolding Link (*goal: ‹cwf ct'›*) by (auto simp: cwf_Link (*‹cwf (Link ?l) = cwf (pointsTo ?l)›*) elim: cwf.cases (*‹⟦cwf ?a; ⋀l. ⟦?a = Link l; cwf (pointsTo l)⟧ ⟹ ?P; ⋀r s cts. ⟦?a = cNode (s, r) cts; r ∈ R; eff r s (seqOf |`| cts); ⋀ct'. ct' |∈| cts ⟹ cwf ct'⟧ ⟹ ?P⟧ ⟹ ?P›*)) ultimately show "?thesis" (*goal: ‹∃ct'. cwf ct' ∧ t' = treeOf pointsTo ct'›*) by blast next (*goal: ‹⋀x21 x22. ct = cNode x21 x22 ⟹ ∃ct'. cwf ct' ∧ t' = treeOf pointsTo ct'›*) case (cNode step cts) (*‹(ct::('sequent, 'rule, 'link) ctree) = cNode (step::'sequent × 'rule) (cts::('sequent, 'rule, 'link) ctree fset)›*) then obtain s and r where cNode: "ct = cNode (s,r) cts" (*goal: ‹(⋀(s::'sequent) r::'rule. (ct::('sequent, 'rule, 'link) ctree) = cNode (s, r) (cts::('sequent, 'rule, 'link) ctree fset) ⟹ thesis::bool) ⟹ thesis›*) apply (cases step) (*goal: ‹(⋀s r. ct = cNode (s, r) cts ⟹ thesis) ⟹ thesis›*) by auto obtain ct' where ct': "ct' |∈| cts" and "t' = treeOf pointsTo ct'" (*goal: ‹(⋀ct'. ⟦ct' |∈| cts; t' = treeOf pointsTo ct'⟧ ⟹ thesis) ⟹ thesis›*) using t' (*‹t' |∈| cont (treeOf pointsTo ct)›*) by (auto simp: cNode (*‹ct = cNode (s, r) cts›*) pointsTo (*‹∀l l'. pointsTo l ≠ Link l'›*) split: ctree.splits (*‹?P (case ?ctree of Link x ⇒ ?f1.0 x | cNode x xa ⇒ ?f2.0 x xa) = ((∀x1. ?ctree = Link x1 ⟶ ?P (?f1.0 x1)) ∧ (∀x21 x22. ?ctree = cNode x21 x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?ctree of Link x ⇒ ?f1.0 x | cNode x xa ⇒ ?f2.0 x xa) = (¬ ((∃x1. ?ctree = Link x1 ∧ ¬ ?P (?f1.0 x1)) ∨ (∃x21 x22. ?ctree = cNode x21 x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*)) moreover have "cwf ct'" using ct' (*‹ct' |∈| cts›*) ct (*‹cwf ct›*) unfolding cNode (*goal: ‹cwf (ct'::('sequent::type, 'rule::type, 'link::type) ctree)›*) by (auto simp: cwf_Link (*‹cwf (Link ?l) = cwf (pointsTo ?l)›*) elim: cwf.cases (*‹⟦cwf ?a; ⋀l. ⟦?a = Link l; cwf (pointsTo l)⟧ ⟹ ?P; ⋀r s cts. ⟦?a = cNode (s, r) cts; r ∈ R; eff r s (seqOf |`| cts); ⋀ct'. ct' |∈| cts ⟹ cwf ct'⟧ ⟹ ?P⟧ ⟹ ?P›*)) ultimately show "?thesis" (*goal: ‹∃ct'. cwf ct' ∧ t' = treeOf pointsTo ct'›*) by blast qed } qed qed } thus "?thesis" (*goal: ‹local.wf (treeOf pointsTo ct)›*) using assms (*‹cwf ct›*) by blast qed theorem cyclic_soundness: assumes "cwf ct" and "cgood ct" and "S ∈ structure" shows "sat S (seqOf ct)" using infinite_soundness (*‹⟦local.wf (?t::('sequent × 'rule) tree); good ?t; (?S::'structure) ∈ (structure::'structure set)⟧ ⟹ (sat::'structure ⇒ 'sequent ⇒ bool) ?S (fst (tree.root ?t))›*) wf_treeOf (*‹cwf ?ct ⟹ local.wf (treeOf pointsTo ?ct)›*) assms (*‹cwf (ct::('sequent, 'rule, 'link) ctree)› ‹cgood ct› ‹S ∈ structure›*) unfolding cgood_def treeOf_seqOf[symmetric] comp_def (*goal: ‹sat S (fst (tree.root (treeOf pointsTo ct)))›*) by blast end (* context *) end (* context Infinite_Soundness *) section ‹Appendix: The definition of treeOf under more flexible assumptions about pointsTo› definition rels where "rels pointsTo ≡ {((pointsTo, pointsTo l'), (pointsTo, Link l')) | l'. True}" definition rel :: "(('link ⇒ ('sequent, 'rule, 'link) ctree) × ('sequent, 'rule, 'link) ctree) rel" where "rel ≡ ⋃ (rels ` {pointsTo. wf {(l, l'). pointsTo l' = Link l}})" lemma wf_rels[simp]: assumes "wf {(l,l'). (pointsTo :: 'link ⇒ ('sequent, 'rule, 'link)ctree) l' = Link l}" (is "wf ?w") shows "wf (rels pointsTo)" using wf_map_prod_image (*‹⟦wf ?r; inj ?f⟧ ⟹ wf (map_prod ?f ?f ` ?r)›*) proof (-) (*goal: ‹(⋀r f. ⟦wf r; inj f⟧ ⟹ wf (map_prod f f ` r)) ⟹ wf (rels pointsTo)›*) define r1 :: "(('link ⇒ ('sequent, 'rule, 'link) ctree) × ('sequent, 'rule, 'link) ctree) rel" where "r1 = {((pointsTo,pointsTo l'), (pointsTo, Link l'::('sequent, 'rule, 'link) ctree)) | l'. (∀l''. pointsTo l' ≠ Link l'')}" define r2 :: "(('link ⇒ ('sequent, 'rule, 'link) ctree) × ('sequent, 'rule, 'link) ctree) rel" where "r2 = image (map_prod (map_prod id Link) (map_prod id Link)) (inv_image ?w snd)" have 0: "rels pointsTo ⊆ r1 ∪ r2" unfolding rels_def r1_def r2_def (*goal: ‹{((pointsTo, pointsTo l'), pointsTo, Link l') |l'. True} ⊆ {((pointsTo, pointsTo l'), pointsTo, Link l') |l'. ∀l''. pointsTo l' ≠ Link l''} ∪ map_prod (map_prod id Link) (map_prod id Link) ` inv_image {(l, l'). pointsTo l' = Link l} snd›*) unfolding inv_image_def image_Collect (*goal: ‹{((pointsTo::'link::type ⇒ ('sequent::type, 'rule::type, 'link::type) ctree, pointsTo l'), pointsTo, Link l') |l'::'link::type. True} ⊆ {((pointsTo, pointsTo l'), pointsTo, Link l') |l'::'link::type. ∀l''::'link::type. pointsTo l' ≠ Link l''} ∪ {map_prod (map_prod id Link) (map_prod id Link) x |x::(('link::type ⇒ ('sequent::type, 'rule::type, 'link::type) ctree) × 'link::type) × ('link::type ⇒ ('sequent::type, 'rule::type, 'link::type) ctree) × 'link::type. case x of (x::('link::type ⇒ ('sequent::type, 'rule::type, 'link::type) ctree) × 'link::type, y::('link::type ⇒ ('sequent::type, 'rule::type, 'link::type) ctree) × 'link::type) ⇒ (snd x, snd y) ∈ {(l::'link::type, l'::'link::type). pointsTo l' = Link l}}›*) by auto let ?m = "measure (λ(tOfL,t). case t of Link l' => Suc 0 | _ => 0)" have 1: "wf r1" unfolding r1_def (*goal: ‹wf {((pointsTo, pointsTo l'), pointsTo, Link l') |l'. ∀l''. pointsTo l' ≠ Link l''}›*) apply (rule wf_subset[of ?m] (*‹⟦wf (measure (λ(tOfL, t). case t of Link l' ⇒ Suc 0 | cNode prod fset ⇒ 0)); ?p ⊆ measure (λ(tOfL, t). case t of Link l' ⇒ Suc 0 | cNode prod fset ⇒ 0)⟧ ⟹ wf ?p›*)) (*goals: 1. ‹wf (measure (λ(tOfL, t). case t of Link l' ⇒ Suc 0 | cNode prod fset ⇒ 0))› 2. ‹{((pointsTo, pointsTo l'), pointsTo, Link l') |l'. ∀l''. pointsTo l' ≠ Link l''} ⊆ measure (λ(tOfL, t). case t of Link l' ⇒ Suc 0 | cNode prod fset ⇒ 0)› discuss goal 1*) apply ((auto split: ctree.splits (*‹?P (case ?ctree of Link x ⇒ ?f1.0 x | cNode x xa ⇒ ?f2.0 x xa) = ((∀x1. ?ctree = Link x1 ⟶ ?P (?f1.0 x1)) ∧ (∀x21 x22. ?ctree = cNode x21 x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?ctree of Link x ⇒ ?f1.0 x | cNode x xa ⇒ ?f2.0 x xa) = (¬ ((∃x1. ?ctree = Link x1 ∧ ¬ ?P (?f1.0 x1)) ∨ (∃x21 x22. ?ctree = cNode x21 x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*))[1]) (*discuss goal 2*) apply ((auto split: ctree.splits (*‹?P (case ?ctree of Link x ⇒ ?f1.0 x | cNode x xa ⇒ ?f2.0 x xa) = ((∀x1. ?ctree = Link x1 ⟶ ?P (?f1.0 x1)) ∧ (∀x21 x22. ?ctree = cNode x21 x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?ctree of Link x ⇒ ?f1.0 x | cNode x xa ⇒ ?f2.0 x xa) = (¬ ((∃x1. ?ctree = Link x1 ∧ ¬ ?P (?f1.0 x1)) ∨ (∃x21 x22. ?ctree = cNode x21 x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*))[1]) (*proven 2 subgoals*) . have 2: "wf r2" using assms (*‹wf {(l, l'). pointsTo l' = Link l}›*) unfolding r2_def (*goal: ‹wf (map_prod (map_prod id Link) (map_prod id Link) ` inv_image {(l, l'). pointsTo l' = Link l} snd)›*) apply (intro wf_map_prod_image (*‹⟦wf ?r; inj ?f⟧ ⟹ wf (map_prod ?f ?f ` ?r)›*) wf_inv_image (*‹wf ?r ⟹ wf (inv_image ?r ?f)›*)) (*goals: 1. ‹wf {(l, l'). pointsTo l' = Link l} ⟹ wf {(l, l'). pointsTo l' = Link l}› 2. ‹wf {(l, l'). pointsTo l' = Link l} ⟹ inj (map_prod id Link)› discuss goal 1*) apply ((auto simp: inj_on_def (*‹inj_on (?f::?'a::type ⇒ ?'b::type) (?A::?'a::type set) = (∀x::?'a::type∈?A. ∀y::?'a::type∈?A. ?f x = ?f y ⟶ x = y)›*))[1]) (*discuss goal 2*) apply ((auto simp: inj_on_def (*‹inj_on (?f::?'a::type ⇒ ?'b::type) (?A::?'a::type set) = (∀x::?'a::type∈?A. ∀y::?'a::type∈?A. ?f x = ?f y ⟶ x = y)›*))[1]) (*proven 2 subgoals*) . have 3: "Domain r1 ∩ Range r2 = {}" unfolding r1_def r2_def (*goal: ‹Domain {((pointsTo, pointsTo l'), pointsTo, Link l') |l'. ∀l''. pointsTo l' ≠ Link l''} ∩ Range (map_prod (map_prod id Link) (map_prod id Link) ` inv_image {(l, l'). pointsTo l' = Link l} snd) = {}›*) by auto show "?thesis" (*goal: ‹wf (rels pointsTo)›*) using "1" (*‹wf r1›*) "2" (*‹wf r2›*) "3" (*‹Domain r1 ∩ Range r2 = {}›*) apply (intro wf_subset[OF _ 0] (*‹wf (r1 ∪ r2) ⟹ wf (rels pointsTo)›*) wf_Un (*‹⟦wf ?r; wf ?s; Domain ?r ∩ Range ?s = {}⟧ ⟹ wf (?r ∪ ?s)›*)) (*goals: 1. ‹⟦wf (r1::((('link ⇒ ('sequent, 'rule, 'link) ctree) × ('sequent, 'rule, 'link) ctree) × ('link ⇒ ('sequent, 'rule, 'link) ctree) × ('sequent, 'rule, 'link) ctree) set); wf (r2::((('link ⇒ ('sequent, 'rule, 'link) ctree) × ('sequent, 'rule, 'link) ctree) × ('link ⇒ ('sequent, 'rule, 'link) ctree) × ('sequent, 'rule, 'link) ctree) set); Domain r1 ∩ Range r2 = {}⟧ ⟹ wf r1› 2. ‹⟦wf (r1::((('link ⇒ ('sequent, 'rule, 'link) ctree) × ('sequent, 'rule, 'link) ctree) × ('link ⇒ ('sequent, 'rule, 'link) ctree) × ('sequent, 'rule, 'link) ctree) set); wf (r2::((('link ⇒ ('sequent, 'rule, 'link) ctree) × ('sequent, 'rule, 'link) ctree) × ('link ⇒ ('sequent, 'rule, 'link) ctree) × ('sequent, 'rule, 'link) ctree) set); Domain r1 ∩ Range r2 = {}⟧ ⟹ wf r2› 3. ‹⟦wf (r1::((('link ⇒ ('sequent, 'rule, 'link) ctree) × ('sequent, 'rule, 'link) ctree) × ('link ⇒ ('sequent, 'rule, 'link) ctree) × ('sequent, 'rule, 'link) ctree) set); wf (r2::((('link ⇒ ('sequent, 'rule, 'link) ctree) × ('sequent, 'rule, 'link) ctree) × ('link ⇒ ('sequent, 'rule, 'link) ctree) × ('sequent, 'rule, 'link) ctree) set); Domain r1 ∩ Range r2 = {}⟧ ⟹ Domain r1 ∩ Range r2 = {}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . qed lemma rel: "wf rel" unfolding rel_def (*goal: ‹wf (⋃ (rels ` {pointsTo. wf {(l, l'). pointsTo l' = Link l}}))›*) apply (rule wf_UN (*‹⟦⋀i. i ∈ ?I ⟹ wf (?r i); ⋀i j. ⟦i ∈ ?I; j ∈ ?I; ?r i ≠ ?r j⟧ ⟹ Domain (?r i) ∩ Range (?r j) = {}⟧ ⟹ wf (⋃ (?r ` ?I))›*)) (*goal: ‹wf (⋃ (rels ` {pointsTo. wf {(l, l'). pointsTo l' = Link l}}))›*) subgoal for by (auto intro: wf_UN (*‹⟦⋀i. i ∈ ?I ⟹ wf (?r i); ⋀i j. ⟦i ∈ ?I; j ∈ ?I; ?r i ≠ ?r j⟧ ⟹ Domain (?r i) ∩ Range (?r j) = {}⟧ ⟹ wf (⋃ (?r ` ?I))›*)) unfolding rels_def (*goal: ‹⋀i j. ⟦i ∈ {pointsTo. wf {(l, l'). pointsTo l' = Link l}}; j ∈ {pointsTo. wf {(l, l'). pointsTo l' = Link l}}; {((i, i l'), i, Link l') |l'. True} ≠ {((j, j l'), j, Link l') |l'. True}⟧ ⟹ Domain {((i, i l'), i, Link l') |l'. True} ∩ Range {((j, j l'), j, Link l') |l'. True} = {}›*) by auto corecursive treeOf' where "treeOf' pointsTo ct = (if ¬ wf {(l',l). pointsTo l = Link l'} ― ‹makes sense only if backward links point to normal nodes, not to backwards links:› then undefined else (case ct of Link l ⇒ treeOf' pointsTo (pointsTo l) |cNode step cts ⇒ Node step (fimage (treeOf' pointsTo) cts) ) )" apply(relation rel) using rel unfolding rel_def rels_def[abs_def] by auto (*<*) end (*>*)
{ "path": "afp-2025-02-12/thys/Abstract_Soundness/Infinite_Proof_Soundness.thy", "repo": "afp-2025-02-12", "sha": "6a84ee2239a43b96a47066d3fb36e91f652cf9088e7c3ef573a86f929ca968f9" }
section ‹Result› theory Result imports Soundness Completeness begin theorem prover_soundness_completeness: fixes A B :: ‹fm list› defines ‹t ≡ prover (A, B)› shows ‹tfinite t ∧ wf t ⟷ (∀(E :: _ ⇒ tm) F G. sc (E, F, G) (A, B))› using assms (*‹t ≡ prover (A, B)›*) prover_soundness (*‹⟦tfinite ?t; Prover.wf ?t⟧ ⟹ sc (?E, ?F, ?G) (fst (tree.root ?t))›*) prover_completeness (*‹∀E F G. sc (E, F, G) (?A, ?B) ⟹ fst (tree.root (prover (?A, ?B))) = (?A, ?B) ∧ Prover.wf (prover (?A, ?B)) ∧ tfinite (prover (?A, ?B))›*) unfolding prover_def (*goal: ‹(tfinite t ∧ Prover.wf t) = (∀E F G. sc (E, F, G) (A, B))›*) by fastforce corollary fixes p :: fm defines ‹t ≡ prover ([], [p])› shows ‹tfinite t ∧ wf t ⟷ (∀(E :: _ ⇒ tm) F G. ⟦E, F, G⟧ p)› using assms (*‹t::((fm list × fm list) × rule) tree ≡ prover ([], [p::fm])›*) prover_soundness_completeness (*‹(tfinite (prover (?A, ?B)) ∧ Prover.wf (prover (?A, ?B))) = (∀E F G. sc (E, F, G) (?A, ?B))›*) by simp end
{ "path": "afp-2025-02-12/thys/FOL_Seq_Calc3/Result.thy", "repo": "afp-2025-02-12", "sha": "2fb2e3cdf071fd35c5b652f8c0c7706bd1814ea322e242c4996bc069c87a02bb" }
section ‹Operational Semantics› theory RG_Tran imports RG_Com begin subsection ‹Semantics of Component Programs› subsubsection ‹Environment transitions› type_synonym 'a conf = "(('a com) option) × 'a" inductive_set etran :: "('a conf × 'a conf) set" and etran' :: "'a conf ⇒ 'a conf ⇒ bool" ("_ -e→ _" [81,81] 80) where "P -e→ Q ≡ (P,Q) ∈ etran" | Env: "(P, s) -e→ (P, t)" lemma etranE: "c -e→ c' ⟹ (⋀P s t. c = (P, s) ⟹ c' = (P, t) ⟹ Q) ⟹ Q" apply (induct c) (*goal: ‹⟦c -e→ c'; ⋀P s t. ⟦c = (P, s); c' = (P, t)⟧ ⟹ Q⟧ ⟹ Q›*) apply (induct c') (*goal: ‹⋀(a::'a com option) b::'a. ⟦(a, b) -e→ (c'::'a com option × 'a); ⋀(P::'a com option) (s::'a) t::'a. ⟦(a, b) = (P, s); c' = (P, t)⟧ ⟹ Q::bool⟧ ⟹ Q›*) apply (erule etran.cases (*‹⟦(?a1.0::?'a com option, ?a2.0::?'a) -e→ (?a3.0::?'a com option, ?a4.0::?'a); ⋀(P::?'a com option) (s::?'a) t::?'a. ⟦?a1.0 = P; ?a2.0 = s; ?a3.0 = P; ?a4.0 = t⟧ ⟹ ?P::bool⟧ ⟹ ?P›*)) (*goal: ‹⋀(a::'a com option) (b::'a) (aa::'a com option) ba::'a. ⟦(aa, ba) -e→ (a, b); ⋀(P::'a com option) (s::'a) t::'a. ⟦(aa, ba) = (P, s); (a, b) = (P, t)⟧ ⟹ Q::bool⟧ ⟹ Q›*) by blast subsubsection ‹Component transitions› inductive_set ctran :: "('a conf × 'a conf) set" and ctran' :: "'a conf ⇒ 'a conf ⇒ bool" ("_ -c→ _" [81,81] 80) and ctrans :: "'a conf ⇒ 'a conf ⇒ bool" ("_ -c*→ _" [81,81] 80) where "P -c→ Q ≡ (P,Q) ∈ ctran" | "P -c*→ Q ≡ (P,Q) ∈ ctran⇧*" | Basic: "(Some(Basic f), s) -c→ (None, f s)" | Seq1: "(Some P0, s) -c→ (None, t) ⟹ (Some(Seq P0 P1), s) -c→ (Some P1, t)" | Seq2: "(Some P0, s) -c→ (Some P2, t) ⟹ (Some(Seq P0 P1), s) -c→ (Some(Seq P2 P1), t)" | CondT: "s∈b ⟹ (Some(Cond b P1 P2), s) -c→ (Some P1, s)" | CondF: "s∉b ⟹ (Some(Cond b P1 P2), s) -c→ (Some P2, s)" | WhileF: "s∉b ⟹ (Some(While b P), s) -c→ (None, s)" | WhileT: "s∈b ⟹ (Some(While b P), s) -c→ (Some(Seq P (While b P)), s)" | Await: "⟦s∈b; (Some P, s) -c*→ (None, t)⟧ ⟹ (Some(Await b P), s) -c→ (None, t)" monos "rtrancl_mono" subsection ‹Semantics of Parallel Programs› type_synonym 'a par_conf = "('a par_com) × 'a" inductive_set par_etran :: "('a par_conf × 'a par_conf) set" and par_etran' :: "['a par_conf,'a par_conf] ⇒ bool" ("_ -pe→ _" [81,81] 80) where "P -pe→ Q ≡ (P,Q) ∈ par_etran" | ParEnv: "(Ps, s) -pe→ (Ps, t)" inductive_set par_ctran :: "('a par_conf × 'a par_conf) set" and par_ctran' :: "['a par_conf,'a par_conf] ⇒ bool" ("_ -pc→ _" [81,81] 80) where "P -pc→ Q ≡ (P,Q) ∈ par_ctran" | ParComp: "⟦i<length Ps; (Ps!i, s) -c→ (r, t)⟧ ⟹ (Ps, s) -pc→ (Ps[i:=r], t)" lemma par_ctranE: "c -pc→ c' ⟹ (⋀i Ps s r t. c = (Ps, s) ⟹ c' = (Ps[i := r], t) ⟹ i < length Ps ⟹ (Ps ! i, s) -c→ (r, t) ⟹ P) ⟹ P" apply (induct c) (*goal: ‹⟦(c::'a com option list × 'a) -pc→ (c'::'a com option list × 'a); ⋀(i::nat) (Ps::'a com option list) (s::'a) (r::'a com option) t::'a. ⟦c = (Ps, s); c' = (Ps[i := r], t); i < length Ps; (Ps ! i, s) -c→ (r, t)⟧ ⟹ P::bool⟧ ⟹ P›*) apply (induct c') (*goal: ‹⋀a b. ⟦(a, b) -pc→ c'; ⋀i Ps s r t. ⟦(a, b) = (Ps, s); c' = (Ps[i := r], t); i < length Ps; (Ps ! i, s) -c→ (r, t)⟧ ⟹ P⟧ ⟹ P›*) apply (erule par_ctran.cases (*‹⟦(?a1.0, ?a2.0) -pc→ (?a3.0, ?a4.0); ⋀i Ps s r t. ⟦?a1.0 = Ps; ?a2.0 = s; ?a3.0 = Ps[i := r]; ?a4.0 = t; i < length Ps; (Ps ! i, s) -c→ (r, t)⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goal: ‹⋀(a::'a com option list) (b::'a) (aa::'a com option list) ba::'a. ⟦(aa, ba) -pc→ (a, b); ⋀(i::nat) (Ps::'a com option list) (s::'a) (r::'a com option) t::'a. ⟦(aa, ba) = (Ps, s); (a, b) = (Ps[i := r], t); i < length Ps; (Ps ! i, s) -c→ (r, t)⟧ ⟹ P::bool⟧ ⟹ P›*) by blast subsection ‹Computations› subsubsection ‹Sequential computations› type_synonym 'a confs = "'a conf list" inductive_set cptn :: "'a confs set" where CptnOne: "[(P,s)] ∈ cptn" | CptnEnv: "(P, t)#xs ∈ cptn ⟹ (P,s)#(P,t)#xs ∈ cptn" | CptnComp: "⟦(P,s) -c→ (Q,t); (Q, t)#xs ∈ cptn ⟧ ⟹ (P,s)#(Q,t)#xs ∈ cptn" definition cp :: "('a com) option ⇒ 'a ⇒ ('a confs) set" where "cp P s ≡ {l. l!0=(P,s) ∧ l ∈ cptn}" subsubsection ‹Parallel computations› type_synonym 'a par_confs = "'a par_conf list" inductive_set par_cptn :: "'a par_confs set" where ParCptnOne: "[(P,s)] ∈ par_cptn" | ParCptnEnv: "(P,t)#xs ∈ par_cptn ⟹ (P,s)#(P,t)#xs ∈ par_cptn" | ParCptnComp: "⟦ (P,s) -pc→ (Q,t); (Q,t)#xs ∈ par_cptn ⟧ ⟹ (P,s)#(Q,t)#xs ∈ par_cptn" definition par_cp :: "'a par_com ⇒ 'a ⇒ ('a par_confs) set" where "par_cp P s ≡ {l. l!0=(P,s) ∧ l ∈ par_cptn}" subsection‹Modular Definition of Computation› definition lift :: "'a com ⇒ 'a conf ⇒ 'a conf" where "lift Q ≡ λ(P, s). (if P=None then (Some Q,s) else (Some(Seq (the P) Q), s))" inductive_set cptn_mod :: "('a confs) set" where CptnModOne: "[(P, s)] ∈ cptn_mod" | CptnModEnv: "(P, t)#xs ∈ cptn_mod ⟹ (P, s)#(P, t)#xs ∈ cptn_mod" | CptnModNone: "⟦(Some P, s) -c→ (None, t); (None, t)#xs ∈ cptn_mod ⟧ ⟹ (Some P,s)#(None, t)#xs ∈cptn_mod" | CptnModCondT: "⟦(Some P0, s)#ys ∈ cptn_mod; s ∈ b ⟧ ⟹ (Some(Cond b P0 P1), s)#(Some P0, s)#ys ∈ cptn_mod" | CptnModCondF: "⟦(Some P1, s)#ys ∈ cptn_mod; s ∉ b ⟧ ⟹ (Some(Cond b P0 P1), s)#(Some P1, s)#ys ∈ cptn_mod" | CptnModSeq1: "⟦(Some P0, s)#xs ∈ cptn_mod; zs=map (lift P1) xs ⟧ ⟹ (Some(Seq P0 P1), s)#zs ∈ cptn_mod" | CptnModSeq2: "⟦(Some P0, s)#xs ∈ cptn_mod; fst(last ((Some P0, s)#xs)) = None; (Some P1, snd(last ((Some P0, s)#xs)))#ys ∈ cptn_mod; zs=(map (lift P1) xs)@ys ⟧ ⟹ (Some(Seq P0 P1), s)#zs ∈ cptn_mod" | CptnModWhile1: "⟦ (Some P, s)#xs ∈ cptn_mod; s ∈ b; zs=map (lift (While b P)) xs ⟧ ⟹ (Some(While b P), s)#(Some(Seq P (While b P)), s)#zs ∈ cptn_mod" | CptnModWhile2: "⟦ (Some P, s)#xs ∈ cptn_mod; fst(last ((Some P, s)#xs))=None; s ∈ b; zs=(map (lift (While b P)) xs)@ys; (Some(While b P), snd(last ((Some P, s)#xs)))#ys ∈ cptn_mod⟧ ⟹ (Some(While b P), s)#(Some(Seq P (While b P)), s)#zs ∈ cptn_mod" subsection ‹Equivalence of Both Definitions.› lemma last_length: "((a#xs)!(length xs))=last (a#xs)" apply (induct xs) (*goals: 1. ‹[a] ! length [] = last [a]› 2. ‹⋀aa xs. (a # xs) ! length xs = last (a # xs) ⟹ (a # aa # xs) ! length (aa # xs) = last (a # aa # xs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma div_seq [rule_format]: "list ∈ cptn_mod ⟹ (∀s P Q zs. list=(Some (Seq P Q), s)#zs ⟶ (∃xs. (Some P, s)#xs ∈ cptn_mod ∧ (zs=(map (lift Q) xs) ∨ ( fst(((Some P, s)#xs)!length xs)=None ∧ (∃ys. (Some Q, snd(((Some P, s)#xs)!length xs))#ys ∈ cptn_mod ∧ zs=(map (lift (Q)) xs)@ys)))))" apply (erule cptn_mod.induct (*‹⟦?x ∈ cptn_mod; ⋀P s. ?P [(P, s)]; ⋀P t xs s. ⟦(P, t) # xs ∈ cptn_mod; ?P ((P, t) # xs)⟧ ⟹ ?P ((P, s) # (P, t) # xs); ⋀P s t xs. ⟦(Some P, s) -c→ (None, t); (None, t) # xs ∈ cptn_mod; ?P ((None, t) # xs)⟧ ⟹ ?P ((Some P, s) # (None, t) # xs); ⋀P0 s ys b P1. ⟦(Some P0, s) # ys ∈ cptn_mod; ?P ((Some P0, s) # ys); s ∈ b⟧ ⟹ ?P ((Some (Cond b P0 P1), s) # (Some P0, s) # ys); ⋀P1 s ys b P0. ⟦(Some P1, s) # ys ∈ cptn_mod; ?P ((Some P1, s) # ys); s ∉ b⟧ ⟹ ?P ((Some (Cond b P0 P1), s) # (Some P1, s) # ys); ⋀P0 s xs zs P1. ⟦(Some P0, s) # xs ∈ cptn_mod; ?P ((Some P0, s) # xs); zs = map (lift P1) xs⟧ ⟹ ?P ((Some (Seq P0 P1), s) # zs); ⋀P0 s xs P1 ys zs. ⟦(Some P0, s) # xs ∈ cptn_mod; ?P ((Some P0, s) # xs); fst (last ((Some P0, s) # xs)) = None; (Some P1, snd (last ((Some P0, s) # xs))) # ys ∈ cptn_mod; ?P ((Some P1, snd (last ((Some P0, s) # xs))) # ys); zs = map (lift P1) xs @ ys⟧ ⟹ ?P ((Some (Seq P0 P1), s) # zs); ⋀P s xs b zs. ⟦(Some P, s) # xs ∈ cptn_mod; ?P ((Some P, s) # xs); s ∈ b; zs = map (lift (While b P)) xs⟧ ⟹ ?P ((Some (While b P), s) # (Some (Seq P (While b P)), s) # zs); ⋀P s xs b zs ys. ⟦(Some P, s) # xs ∈ cptn_mod; ?P ((Some P, s) # xs); fst (last ((Some P, s) # xs)) = None; s ∈ b; zs = map (lift (While b P)) xs @ ys; (Some (While b P), snd (last ((Some P, s) # xs))) # ys ∈ cptn_mod; ?P ((Some (While b P), snd (last ((Some P, s) # xs))) # ys)⟧ ⟹ ?P ((Some (While b P), s) # (Some (Seq P (While b P)), s) # zs)⟧ ⟹ ?P ?x›*)) (*goals: 1. ‹⋀P s. ∀sa Pa Q zs. [(P, s)] = (Some (Seq Pa Q), sa) # zs ⟶ (∃xs. (Some Pa, sa) # xs ∈ cptn_mod ∧ (zs = map (lift Q) xs ∨ fst (((Some Pa, sa) # xs) ! length xs) = None ∧ (∃ys. (Some Q, snd (((Some Pa, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zs = map (lift Q) xs @ ys)))› 2. ‹⋀P t xs s. ⟦(P, t) # xs ∈ cptn_mod; ∀s Pa Q zs. (P, t) # xs = (Some (Seq Pa Q), s) # zs ⟶ (∃xs. (Some Pa, s) # xs ∈ cptn_mod ∧ (zs = map (lift Q) xs ∨ fst (((Some Pa, s) # xs) ! length xs) = None ∧ (∃ys. (Some Q, snd (((Some Pa, s) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zs = map (lift Q) xs @ ys)))⟧ ⟹ ∀sa Pa Q zs. (P, s) # (P, t) # xs = (Some (Seq Pa Q), sa) # zs ⟶ (∃xs. (Some Pa, sa) # xs ∈ cptn_mod ∧ (zs = map (lift Q) xs ∨ fst (((Some Pa, sa) # xs) ! length xs) = None ∧ (∃ys. (Some Q, snd (((Some Pa, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zs = map (lift Q) xs @ ys)))› 3. ‹⋀P s t xs. ⟦(Some P, s) -c→ (None, t); (None, t) # xs ∈ cptn_mod; ∀s P Q zs. (None, t) # xs = (Some (Seq P Q), s) # zs ⟶ (∃xs. (Some P, s) # xs ∈ cptn_mod ∧ (zs = map (lift Q) xs ∨ fst (((Some P, s) # xs) ! length xs) = None ∧ (∃ys. (Some Q, snd (((Some P, s) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zs = map (lift Q) xs @ ys)))⟧ ⟹ ∀sa Pa Q zs. (Some P, s) # (None, t) # xs = (Some (Seq Pa Q), sa) # zs ⟶ (∃xs. (Some Pa, sa) # xs ∈ cptn_mod ∧ (zs = map (lift Q) xs ∨ fst (((Some Pa, sa) # xs) ! length xs) = None ∧ (∃ys. (Some Q, snd (((Some Pa, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zs = map (lift Q) xs @ ys)))› 4. ‹⋀P0 s ys b P1. ⟦(Some P0, s) # ys ∈ cptn_mod; ∀sa P Q zs. (Some P0, s) # ys = (Some (Seq P Q), sa) # zs ⟶ (∃xs. (Some P, sa) # xs ∈ cptn_mod ∧ (zs = map (lift Q) xs ∨ fst (((Some P, sa) # xs) ! length xs) = None ∧ (∃ys. (Some Q, snd (((Some P, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zs = map (lift Q) xs @ ys))); s ∈ b⟧ ⟹ ∀sa P Q zs. (Some (Cond b P0 P1), s) # (Some P0, s) # ys = (Some (Seq P Q), sa) # zs ⟶ (∃xs. (Some P, sa) # xs ∈ cptn_mod ∧ (zs = map (lift Q) xs ∨ fst (((Some P, sa) # xs) ! length xs) = None ∧ (∃ys. (Some Q, snd (((Some P, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zs = map (lift Q) xs @ ys)))› 5. ‹⋀P1 s ys b P0. ⟦(Some P1, s) # ys ∈ cptn_mod; ∀sa P Q zs. (Some P1, s) # ys = (Some (Seq P Q), sa) # zs ⟶ (∃xs. (Some P, sa) # xs ∈ cptn_mod ∧ (zs = map (lift Q) xs ∨ fst (((Some P, sa) # xs) ! length xs) = None ∧ (∃ys. (Some Q, snd (((Some P, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zs = map (lift Q) xs @ ys))); s ∉ b⟧ ⟹ ∀sa P Q zs. (Some (Cond b P0 P1), s) # (Some P1, s) # ys = (Some (Seq P Q), sa) # zs ⟶ (∃xs. (Some P, sa) # xs ∈ cptn_mod ∧ (zs = map (lift Q) xs ∨ fst (((Some P, sa) # xs) ! length xs) = None ∧ (∃ys. (Some Q, snd (((Some P, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zs = map (lift Q) xs @ ys)))› 6. ‹⋀P0 s xs zs P1. ⟦(Some P0, s) # xs ∈ cptn_mod; ∀sa P Q zs. (Some P0, s) # xs = (Some (Seq P Q), sa) # zs ⟶ (∃xs. (Some P, sa) # xs ∈ cptn_mod ∧ (zs = map (lift Q) xs ∨ fst (((Some P, sa) # xs) ! length xs) = None ∧ (∃ys. (Some Q, snd (((Some P, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zs = map (lift Q) xs @ ys))); zs = map (lift P1) xs⟧ ⟹ ∀sa P Q zsa. (Some (Seq P0 P1), s) # zs = (Some (Seq P Q), sa) # zsa ⟶ (∃xs. (Some P, sa) # xs ∈ cptn_mod ∧ (zsa = map (lift Q) xs ∨ fst (((Some P, sa) # xs) ! length xs) = None ∧ (∃ys. (Some Q, snd (((Some P, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zsa = map (lift Q) xs @ ys)))› 7. ‹⋀P0 s xs P1 ys zs. ⟦(Some P0, s) # xs ∈ cptn_mod; ∀sa P Q zs. (Some P0, s) # xs = (Some (Seq P Q), sa) # zs ⟶ (∃xs. (Some P, sa) # xs ∈ cptn_mod ∧ (zs = map (lift Q) xs ∨ fst (((Some P, sa) # xs) ! length xs) = None ∧ (∃ys. (Some Q, snd (((Some P, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zs = map (lift Q) xs @ ys))); fst (last ((Some P0, s) # xs)) = None; (Some P1, snd (last ((Some P0, s) # xs))) # ys ∈ cptn_mod; ∀sa P Q zs. (Some P1, snd (last ((Some P0, s) # xs))) # ys = (Some (Seq P Q), sa) # zs ⟶ (∃xs. (Some P, sa) # xs ∈ cptn_mod ∧ (zs = map (lift Q) xs ∨ fst (((Some P, sa) # xs) ! length xs) = None ∧ (∃ys. (Some Q, snd (((Some P, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zs = map (lift Q) xs @ ys))); zs = map (lift P1) xs @ ys⟧ ⟹ ∀sa P Q zsa. (Some (Seq P0 P1), s) # zs = (Some (Seq P Q), sa) # zsa ⟶ (∃xs. (Some P, sa) # xs ∈ cptn_mod ∧ (zsa = map (lift Q) xs ∨ fst (((Some P, sa) # xs) ! length xs) = None ∧ (∃ys. (Some Q, snd (((Some P, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zsa = map (lift Q) xs @ ys)))› 8. ‹⋀P s xs b zs. ⟦(Some P, s) # xs ∈ cptn_mod; ∀sa Pa Q zs. (Some P, s) # xs = (Some (Seq Pa Q), sa) # zs ⟶ (∃xs. (Some Pa, sa) # xs ∈ cptn_mod ∧ (zs = map (lift Q) xs ∨ fst (((Some Pa, sa) # xs) ! length xs) = None ∧ (∃ys. (Some Q, snd (((Some Pa, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zs = map (lift Q) xs @ ys))); s ∈ b; zs = map (lift (While b P)) xs⟧ ⟹ ∀sa Pa Q zsa. (Some (While b P), s) # (Some (Seq P (While b P)), s) # zs = (Some (Seq Pa Q), sa) # zsa ⟶ (∃xs. (Some Pa, sa) # xs ∈ cptn_mod ∧ (zsa = map (lift Q) xs ∨ fst (((Some Pa, sa) # xs) ! length xs) = None ∧ (∃ys. (Some Q, snd (((Some Pa, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zsa = map (lift Q) xs @ ys)))› 9. ‹⋀P s xs b zs ys. ⟦(Some P, s) # xs ∈ cptn_mod; ∀sa Pa Q zs. (Some P, s) # xs = (Some (Seq Pa Q), sa) # zs ⟶ (∃xs. (Some Pa, sa) # xs ∈ cptn_mod ∧ (zs = map (lift Q) xs ∨ fst (((Some Pa, sa) # xs) ! length xs) = None ∧ (∃ys. (Some Q, snd (((Some Pa, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zs = map (lift Q) xs @ ys))); fst (last ((Some P, s) # xs)) = None; s ∈ b; zs = map (lift (While b P)) xs @ ys; (Some (While b P), snd (last ((Some P, s) # xs))) # ys ∈ cptn_mod; ∀sa Pa Q zs. (Some (While b P), snd (last ((Some P, s) # xs))) # ys = (Some (Seq Pa Q), sa) # zs ⟶ (∃xs. (Some Pa, sa) # xs ∈ cptn_mod ∧ (zs = map (lift Q) xs ∨ fst (((Some Pa, sa) # xs) ! length xs) = None ∧ (∃ys. (Some Q, snd (((Some Pa, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zs = map (lift Q) xs @ ys)))⟧ ⟹ ∀sa Pa Q zsa. (Some (While b P), s) # (Some (Seq P (While b P)), s) # zs = (Some (Seq Pa Q), sa) # zsa ⟶ (∃xs. (Some Pa, sa) # xs ∈ cptn_mod ∧ (zsa = map (lift Q) xs ∨ fst (((Some Pa, sa) # xs) ! length xs) = None ∧ (∃ys. (Some Q, snd (((Some Pa, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zsa = map (lift Q) xs @ ys)))› discuss goal 1*) apply simp (*top goal: ‹⋀(P::'a com option) s::'a. ∀(sa::'a) (Pa::'a com) (Q::'a com) zs::('a com option × 'a) list. [(P, s)] = (Some (Seq Pa Q), sa) # zs ⟶ (∃xs::('a com option × 'a) list. (Some Pa, sa) # xs ∈ cptn_mod ∧ (zs = map (lift Q) xs ∨ fst (((Some Pa, sa) # xs) ! length xs) = None ∧ (∃ys::('a com option × 'a) list. (Some Q, snd (((Some Pa, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zs = map (lift Q) xs @ ys)))› and 8 goals remain*) apply clarify (*top goal: ‹⋀P s. ∀Pa Q. P = Some (Seq Pa Q) ⟶ (∃xs. (Some Pa, s) # xs ∈ cptn_mod ∧ (xs = [] ∨ fst (((Some Pa, s) # xs) ! length xs) = None ∧ [(Some Q, snd (((Some Pa, s) # xs) ! length xs))] ∈ cptn_mod ∧ xs = []))› and 8 goals remain*) apply (force intro:CptnModOne (*‹[(?P, ?s)] ∈ cptn_mod›*)) (*discuss goal 2*) apply simp (*top goal: ‹⋀P t xs s. ⟦(P, t) # xs ∈ cptn_mod; ∀s Pa Q zs. (P, t) # xs = (Some (Seq Pa Q), s) # zs ⟶ (∃xs. (Some Pa, s) # xs ∈ cptn_mod ∧ (zs = map (lift Q) xs ∨ fst (((Some Pa, s) # xs) ! length xs) = None ∧ (∃ys. (Some Q, snd (((Some Pa, s) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zs = map (lift Q) xs @ ys)))⟧ ⟹ ∀sa Pa Q zs. (P, s) # (P, t) # xs = (Some (Seq Pa Q), sa) # zs ⟶ (∃xs. (Some Pa, sa) # xs ∈ cptn_mod ∧ (zs = map (lift Q) xs ∨ fst (((Some Pa, sa) # xs) ! length xs) = None ∧ (∃ys. (Some Q, snd (((Some Pa, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zs = map (lift Q) xs @ ys)))› and 7 goals remain*) apply clarify (*top goal: ‹⋀P t xs s. ⟦(P, t) # xs ∈ cptn_mod; ∀Pa Q. P = Some (Seq Pa Q) ⟶ (∃xsa. (Some Pa, t) # xsa ∈ cptn_mod ∧ (xs = map (lift Q) xsa ∨ fst (((Some Pa, t) # xsa) ! length xsa) = None ∧ (∃ys. (Some Q, snd (((Some Pa, t) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ xs = map (lift Q) xsa @ ys)))⟧ ⟹ ∀Pa Q. P = Some (Seq Pa Q) ⟶ (∃xsa. (Some Pa, s) # xsa ∈ cptn_mod ∧ ((Some (Seq Pa Q), t) # xs = map (lift Q) xsa ∨ fst (((Some Pa, s) # xsa) ! length xsa) = None ∧ (∃ys. (Some Q, snd (((Some Pa, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ (Some (Seq Pa Q), t) # xs = map (lift Q) xsa @ ys)))› and 7 goals remain*) apply (erule_tac x=Pa in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀(P::'a com option) (t::'a) (xs::('a com option × 'a) list) (s::'a) (Pa::'a com) Q::'a com. ⟦(Some (Seq Pa Q), t) # xs ∈ cptn_mod; ∀(P::'a com) Qa::'a com. Some (Seq Pa Q) = Some (Seq P Qa) ⟶ (∃xsa::('a com option × 'a) list. (Some P, t) # xsa ∈ cptn_mod ∧ (xs = map (lift Qa) xsa ∨ fst (((Some P, t) # xsa) ! length xsa) = None ∧ (∃ys::('a com option × 'a) list. (Some Qa, snd (((Some P, t) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ xs = map (lift Qa) xsa @ ys)))⟧ ⟹ ∃xsa::('a com option × 'a) list. (Some Pa, s) # xsa ∈ cptn_mod ∧ ((Some (Seq Pa Q), t) # xs = map (lift Q) xsa ∨ fst (((Some Pa, s) # xsa) ! length xsa) = None ∧ (∃ys::('a com option × 'a) list. (Some Q, snd (((Some Pa, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ (Some (Seq Pa Q), t) # xs = map (lift Q) xsa @ ys))› and 7 goals remain*) apply (erule_tac x=Q in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀P t xs s Pa Q. ⟦(Some (Seq Pa Q), t) # xs ∈ cptn_mod; ∀Qa. Some (Seq Pa Q) = Some (Seq Pa Qa) ⟶ (∃xsa. (Some Pa, t) # xsa ∈ cptn_mod ∧ (xs = map (lift Qa) xsa ∨ fst (((Some Pa, t) # xsa) ! length xsa) = None ∧ (∃ys. (Some Qa, snd (((Some Pa, t) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ xs = map (lift Qa) xsa @ ys)))⟧ ⟹ ∃xsa. (Some Pa, s) # xsa ∈ cptn_mod ∧ ((Some (Seq Pa Q), t) # xs = map (lift Q) xsa ∨ fst (((Some Pa, s) # xsa) ! length xsa) = None ∧ (∃ys. (Some Q, snd (((Some Pa, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ (Some (Seq Pa Q), t) # xs = map (lift Q) xsa @ ys))› and 7 goals remain*) apply simp (*top goal: ‹⋀(P::'a com option) (t::'a) (xs::('a com option × 'a) list) (s::'a) (Pa::'a com) Q::'a com. ⟦(Some (Seq Pa Q), t) # xs ∈ cptn_mod; Some (Seq Pa Q) = Some (Seq Pa Q) ⟶ (∃xsa::('a com option × 'a) list. (Some Pa, t) # xsa ∈ cptn_mod ∧ (xs = map (lift Q) xsa ∨ fst (((Some Pa, t) # xsa) ! length xsa) = None ∧ (∃ys::('a com option × 'a) list. (Some Q, snd (((Some Pa, t) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ xs = map (lift Q) xsa @ ys)))⟧ ⟹ ∃xsa::('a com option × 'a) list. (Some Pa, s) # xsa ∈ cptn_mod ∧ ((Some (Seq Pa Q), t) # xs = map (lift Q) xsa ∨ fst (((Some Pa, s) # xsa) ! length xsa) = None ∧ (∃ys::('a com option × 'a) list. (Some Q, snd (((Some Pa, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ (Some (Seq Pa Q), t) # xs = map (lift Q) xsa @ ys))› and 7 goals remain*) apply clarify (*top goal: ‹⋀t xs s Pa Q. ⟦(Some (Seq Pa Q), t) # xs ∈ cptn_mod; ∃xsa. (Some Pa, t) # xsa ∈ cptn_mod ∧ (xs = map (lift Q) xsa ∨ fst (((Some Pa, t) # xsa) ! length xsa) = None ∧ (∃ys. (Some Q, snd (((Some Pa, t) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ xs = map (lift Q) xsa @ ys))⟧ ⟹ ∃xsa. (Some Pa, s) # xsa ∈ cptn_mod ∧ ((Some (Seq Pa Q), t) # xs = map (lift Q) xsa ∨ fst (((Some Pa, s) # xsa) ! length xsa) = None ∧ (∃ys. (Some Q, snd (((Some Pa, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ (Some (Seq Pa Q), t) # xs = map (lift Q) xsa @ ys))› and 7 goals remain*) apply (erule disjE (*‹⟦(?P::bool) ∨ (?Q::bool); ?P ⟹ ?R::bool; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹⋀(t::'a) (xs::('a com option × 'a) list) (s::'a) (Pa::'a com) (Q::'a com) xsa::('a com option × 'a) list. ⟦(Some (Seq Pa Q), t) # xs ∈ cptn_mod; (Some Pa, t) # xsa ∈ cptn_mod; xs = map (lift Q) xsa⟧ ⟹ ∃xsa::('a com option × 'a) list. (Some Pa, s) # xsa ∈ cptn_mod ∧ ((Some (Seq Pa Q), t) # xs = map (lift Q) xsa ∨ fst (((Some Pa, s) # xsa) ! length xsa) = None ∧ (∃ys::('a com option × 'a) list. (Some Q, snd (((Some Pa, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ (Some (Seq Pa Q), t) # xs = map (lift Q) xsa @ ys))› 2. ‹⋀(t::'a) (xs::('a com option × 'a) list) (s::'a) (Pa::'a com) (Q::'a com) xsa::('a com option × 'a) list. ⟦(Some (Seq Pa Q), t) # xs ∈ cptn_mod; (Some Pa, t) # xsa ∈ cptn_mod; fst (((Some Pa, t) # xsa) ! length xsa) = None ∧ (∃ys::('a com option × 'a) list. (Some Q, snd (((Some Pa, t) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ xs = map (lift Q) xsa @ ys)⟧ ⟹ ∃xsa::('a com option × 'a) list. (Some Pa, s) # xsa ∈ cptn_mod ∧ ((Some (Seq Pa Q), t) # xs = map (lift Q) xsa ∨ fst (((Some Pa, s) # xsa) ! length xsa) = None ∧ (∃ys::('a com option × 'a) list. (Some Q, snd (((Some Pa, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ (Some (Seq Pa Q), t) # xs = map (lift Q) xsa @ ys))› discuss goal 1*) apply (rule_tac x="(Some Pa,t)#xsa" in exI (*‹?P ?x ⟹ ∃x. ?P x›*)) (*top goal: ‹⋀t xs s Pa Q xsa. ⟦(Some (Seq Pa Q), t) # xs ∈ cptn_mod; (Some Pa, t) # xsa ∈ cptn_mod; xs = map (lift Q) xsa⟧ ⟹ ∃xsa. (Some Pa, s) # xsa ∈ cptn_mod ∧ ((Some (Seq Pa Q), t) # xs = map (lift Q) xsa ∨ fst (((Some Pa, s) # xsa) ! length xsa) = None ∧ (∃ys. (Some Q, snd (((Some Pa, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ (Some (Seq Pa Q), t) # xs = map (lift Q) xsa @ ys))› and 8 goals remain*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹⋀t xs s Pa Q xsa. ⟦(Some (Seq Pa Q), t) # xs ∈ cptn_mod; (Some Pa, t) # xsa ∈ cptn_mod; xs = map (lift Q) xsa⟧ ⟹ (Some Pa, s) # (Some Pa, t) # xsa ∈ cptn_mod› 2. ‹⋀t xs s Pa Q xsa. ⟦(Some (Seq Pa Q), t) # xs ∈ cptn_mod; (Some Pa, t) # xsa ∈ cptn_mod; xs = map (lift Q) xsa⟧ ⟹ (Some (Seq Pa Q), t) # xs = map (lift Q) ((Some Pa, t) # xsa) ∨ fst (((Some Pa, s) # (Some Pa, t) # xsa) ! length ((Some Pa, t) # xsa)) = None ∧ (∃ys. (Some Q, snd (((Some Pa, s) # (Some Pa, t) # xsa) ! length ((Some Pa, t) # xsa))) # ys ∈ cptn_mod ∧ (Some (Seq Pa Q), t) # xs = map (lift Q) ((Some Pa, t) # xsa) @ ys)› discuss goal 1*) apply clarify (*top goal: ‹⋀t xs s Pa Q xsa. ⟦(Some (Seq Pa Q), t) # xs ∈ cptn_mod; (Some Pa, t) # xsa ∈ cptn_mod; xs = map (lift Q) xsa⟧ ⟹ (Some Pa, s) # (Some Pa, t) # xsa ∈ cptn_mod› and 9 goals remain*) apply (erule CptnModEnv (*‹(?P, ?t) # ?xs ∈ cptn_mod ⟹ (?P, ?s) # (?P, ?t) # ?xs ∈ cptn_mod›*)) (*discuss goal 2*) apply (rule disjI1 (*‹?P ⟹ ?P ∨ ?Q›*)) (*top goal: ‹⋀t xs s Pa Q xsa. ⟦(Some (Seq Pa Q), t) # xs ∈ cptn_mod; (Some Pa, t) # xsa ∈ cptn_mod; xs = map (lift Q) xsa⟧ ⟹ (Some (Seq Pa Q), t) # xs = map (lift Q) ((Some Pa, t) # xsa) ∨ fst (((Some Pa, s) # (Some Pa, t) # xsa) ! length ((Some Pa, t) # xsa)) = None ∧ (∃ys. (Some Q, snd (((Some Pa, s) # (Some Pa, t) # xsa) ! length ((Some Pa, t) # xsa))) # ys ∈ cptn_mod ∧ (Some (Seq Pa Q), t) # xs = map (lift Q) ((Some Pa, t) # xsa) @ ys)› and 8 goals remain*) apply (simp add:lift_def (*‹lift ?Q ≡ λ(P, s). if P = None then (Some ?Q, s) else (Some (Seq (the P) ?Q), s)›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply clarify (*top goal: ‹⋀t xs s Pa Q xsa. ⟦(Some (Seq Pa Q), t) # xs ∈ cptn_mod; (Some Pa, t) # xsa ∈ cptn_mod; fst (((Some Pa, t) # xsa) ! length xsa) = None ∧ (∃ys. (Some Q, snd (((Some Pa, t) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ xs = map (lift Q) xsa @ ys)⟧ ⟹ ∃xsa. (Some Pa, s) # xsa ∈ cptn_mod ∧ ((Some (Seq Pa Q), t) # xs = map (lift Q) xsa ∨ fst (((Some Pa, s) # xsa) ! length xsa) = None ∧ (∃ys. (Some Q, snd (((Some Pa, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ (Some (Seq Pa Q), t) # xs = map (lift Q) xsa @ ys))› and 7 goals remain*) apply (rule_tac x="(Some Pa,t)#xsa" in exI (*‹?P ?x ⟹ ∃x. ?P x›*)) (*top goal: ‹⋀(t::'a::type) (xs::('a::type com option × 'a::type) list) (s::'a::type) (Pa::'a::type com) (Q::'a::type com) (xsa::('a::type com option × 'a::type) list) ys::('a::type com option × 'a::type) list. ⟦(Some (Seq Pa Q), t) # map (lift Q) xsa @ ys ∈ cptn_mod; (Some Pa, t) # xsa ∈ cptn_mod; fst (((Some Pa, t) # xsa) ! length xsa) = None; (Some Q, snd (((Some Pa, t) # xsa) ! length xsa)) # ys ∈ cptn_mod⟧ ⟹ ∃xs::('a::type com option × 'a::type) list. (Some Pa, s) # xs ∈ cptn_mod ∧ ((Some (Seq Pa Q), t) # map (lift Q) xsa @ ys = map (lift Q) xs ∨ fst (((Some Pa, s) # xs) ! length xs) = None ∧ (∃ysa::('a::type com option × 'a::type) list. (Some Q, snd (((Some Pa, s) # xs) ! length xs)) # ysa ∈ cptn_mod ∧ (Some (Seq Pa Q), t) # map (lift Q) xsa @ ys = map (lift Q) xs @ ysa))› and 7 goals remain*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹⋀t xs s Pa Q xsa ys. ⟦(Some (Seq Pa Q), t) # map (lift Q) xsa @ ys ∈ cptn_mod; (Some Pa, t) # xsa ∈ cptn_mod; fst (((Some Pa, t) # xsa) ! length xsa) = None; (Some Q, snd (((Some Pa, t) # xsa) ! length xsa)) # ys ∈ cptn_mod⟧ ⟹ (Some Pa, s) # (Some Pa, t) # xsa ∈ cptn_mod› 2. ‹⋀t xs s Pa Q xsa ys. ⟦(Some (Seq Pa Q), t) # map (lift Q) xsa @ ys ∈ cptn_mod; (Some Pa, t) # xsa ∈ cptn_mod; fst (((Some Pa, t) # xsa) ! length xsa) = None; (Some Q, snd (((Some Pa, t) # xsa) ! length xsa)) # ys ∈ cptn_mod⟧ ⟹ (Some (Seq Pa Q), t) # map (lift Q) xsa @ ys = map (lift Q) ((Some Pa, t) # xsa) ∨ fst (((Some Pa, s) # (Some Pa, t) # xsa) ! length ((Some Pa, t) # xsa)) = None ∧ (∃ysa. (Some Q, snd (((Some Pa, s) # (Some Pa, t) # xsa) ! length ((Some Pa, t) # xsa))) # ysa ∈ cptn_mod ∧ (Some (Seq Pa Q), t) # map (lift Q) xsa @ ys = map (lift Q) ((Some Pa, t) # xsa) @ ysa)› discuss goal 1*) apply (erule CptnModEnv (*‹(?P, ?t) # ?xs ∈ cptn_mod ⟹ (?P, ?s) # (?P, ?t) # ?xs ∈ cptn_mod›*)) (*discuss goal 2*) apply (rule disjI2 (*‹?Q ⟹ ?P ∨ ?Q›*)) (*top goal: ‹⋀t xs s Pa Q xsa ys. ⟦(Some (Seq Pa Q), t) # map (lift Q) xsa @ ys ∈ cptn_mod; (Some Pa, t) # xsa ∈ cptn_mod; fst (((Some Pa, t) # xsa) ! length xsa) = None; (Some Q, snd (((Some Pa, t) # xsa) ! length xsa)) # ys ∈ cptn_mod⟧ ⟹ (Some (Seq Pa Q), t) # map (lift Q) xsa @ ys = map (lift Q) ((Some Pa, t) # xsa) ∨ fst (((Some Pa, s) # (Some Pa, t) # xsa) ! length ((Some Pa, t) # xsa)) = None ∧ (∃ysa. (Some Q, snd (((Some Pa, s) # (Some Pa, t) # xsa) ! length ((Some Pa, t) # xsa))) # ysa ∈ cptn_mod ∧ (Some (Seq Pa Q), t) # map (lift Q) xsa @ ys = map (lift Q) ((Some Pa, t) # xsa) @ ysa)› and 7 goals remain*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹⋀t xs s Pa Q xsa ys. ⟦(Some (Seq Pa Q), t) # map (lift Q) xsa @ ys ∈ cptn_mod; (Some Pa, t) # xsa ∈ cptn_mod; fst (((Some Pa, t) # xsa) ! length xsa) = None; (Some Q, snd (((Some Pa, t) # xsa) ! length xsa)) # ys ∈ cptn_mod⟧ ⟹ fst (((Some Pa, s) # (Some Pa, t) # xsa) ! length ((Some Pa, t) # xsa)) = None› 2. ‹⋀t xs s Pa Q xsa ys. ⟦(Some (Seq Pa Q), t) # map (lift Q) xsa @ ys ∈ cptn_mod; (Some Pa, t) # xsa ∈ cptn_mod; fst (((Some Pa, t) # xsa) ! length xsa) = None; (Some Q, snd (((Some Pa, t) # xsa) ! length xsa)) # ys ∈ cptn_mod⟧ ⟹ ∃ysa. (Some Q, snd (((Some Pa, s) # (Some Pa, t) # xsa) ! length ((Some Pa, t) # xsa))) # ysa ∈ cptn_mod ∧ (Some (Seq Pa Q), t) # map (lift Q) xsa @ ys = map (lift Q) ((Some Pa, t) # xsa) @ ysa› discuss goal 1*) apply (case_tac xsa) (*goals: 1. ‹⋀(t::'a) (xs::('a com option × 'a) list) (s::'a) (Pa::'a com) (Q::'a com) (xsa::('a com option × 'a) list) ys::('a com option × 'a) list. ⟦(Some (Seq Pa Q), t) # map (lift Q) xsa @ ys ∈ cptn_mod; (Some Pa, t) # xsa ∈ cptn_mod; fst (((Some Pa, t) # xsa) ! length xsa) = None; (Some Q, snd (((Some Pa, t) # xsa) ! length xsa)) # ys ∈ cptn_mod; xsa = []⟧ ⟹ fst (((Some Pa, s) # (Some Pa, t) # xsa) ! length ((Some Pa, t) # xsa)) = None› 2. ‹⋀(t::'a) (xs::('a com option × 'a) list) (s::'a) (Pa::'a com) (Q::'a com) (xsa::('a com option × 'a) list) (ys::('a com option × 'a) list) (a::'a com option × 'a) list::('a com option × 'a) list. ⟦(Some (Seq Pa Q), t) # map (lift Q) xsa @ ys ∈ cptn_mod; (Some Pa, t) # xsa ∈ cptn_mod; fst (((Some Pa, t) # xsa) ! length xsa) = None; (Some Q, snd (((Some Pa, t) # xsa) ! length xsa)) # ys ∈ cptn_mod; xsa = a # list⟧ ⟹ fst (((Some Pa, s) # (Some Pa, t) # xsa) ! length ((Some Pa, t) # xsa)) = None› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (rule_tac x="ys" in exI (*‹?P ?x ⟹ ∃x. ?P x›*)) (*top goal: ‹⋀t xs s Pa Q xsa ys. ⟦(Some (Seq Pa Q), t) # map (lift Q) xsa @ ys ∈ cptn_mod; (Some Pa, t) # xsa ∈ cptn_mod; fst (((Some Pa, t) # xsa) ! length xsa) = None; (Some Q, snd (((Some Pa, t) # xsa) ! length xsa)) # ys ∈ cptn_mod⟧ ⟹ ∃ysa. (Some Q, snd (((Some Pa, s) # (Some Pa, t) # xsa) ! length ((Some Pa, t) # xsa))) # ysa ∈ cptn_mod ∧ (Some (Seq Pa Q), t) # map (lift Q) xsa @ ys = map (lift Q) ((Some Pa, t) # xsa) @ ysa› and 7 goals remain*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹⋀t xs s Pa Q xsa ys. ⟦(Some (Seq Pa Q), t) # map (lift Q) xsa @ ys ∈ cptn_mod; (Some Pa, t) # xsa ∈ cptn_mod; fst (((Some Pa, t) # xsa) ! length xsa) = None; (Some Q, snd (((Some Pa, t) # xsa) ! length xsa)) # ys ∈ cptn_mod⟧ ⟹ (Some Q, snd (((Some Pa, s) # (Some Pa, t) # xsa) ! length ((Some Pa, t) # xsa))) # ys ∈ cptn_mod› 2. ‹⋀t xs s Pa Q xsa ys. ⟦(Some (Seq Pa Q), t) # map (lift Q) xsa @ ys ∈ cptn_mod; (Some Pa, t) # xsa ∈ cptn_mod; fst (((Some Pa, t) # xsa) ! length xsa) = None; (Some Q, snd (((Some Pa, t) # xsa) ! length xsa)) # ys ∈ cptn_mod⟧ ⟹ (Some (Seq Pa Q), t) # map (lift Q) xsa @ ys = map (lift Q) ((Some Pa, t) # xsa) @ ys› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp add:lift_def (*‹lift ?Q ≡ λ(P, s). if P = None then (Some ?Q, s) else (Some (Seq (the P) ?Q), s)›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 3*) apply simp (*top goal: ‹⋀(P::'a::type com) (s::'a::type) (t::'a::type) xs::('a::type com option × 'a::type) list. ⟦(Some P, s) -c→ (None, t); (None, t) # xs ∈ cptn_mod; ∀(s::'a::type) (P::'a::type com) (Q::'a::type com) zs::('a::type com option × 'a::type) list. (None, t) # xs = (Some (Seq P Q), s) # zs ⟶ (∃xs::('a::type com option × 'a::type) list. (Some P, s) # xs ∈ cptn_mod ∧ (zs = map (lift Q) xs ∨ fst (((Some P, s) # xs) ! length xs) = None ∧ (∃ys::('a::type com option × 'a::type) list. (Some Q, snd (((Some P, s) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zs = map (lift Q) xs @ ys)))⟧ ⟹ ∀(sa::'a::type) (Pa::'a::type com) (Q::'a::type com) zs::('a::type com option × 'a::type) list. (Some P, s) # (None, t) # xs = (Some (Seq Pa Q), sa) # zs ⟶ (∃xs::('a::type com option × 'a::type) list. (Some Pa, sa) # xs ∈ cptn_mod ∧ (zs = map (lift Q) xs ∨ fst (((Some Pa, sa) # xs) ! length xs) = None ∧ (∃ys::('a::type com option × 'a::type) list. (Some Q, snd (((Some Pa, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zs = map (lift Q) xs @ ys)))› and 6 goals remain*) apply clarify (*top goal: ‹⋀P s t xs. ⟦(Some P, s) -c→ (None, t); (None, t) # xs ∈ cptn_mod⟧ ⟹ ∀Pa Q. P = Seq Pa Q ⟶ (∃xsa. (Some Pa, s) # xsa ∈ cptn_mod ∧ ((None, t) # xs = map (lift Q) xsa ∨ fst (((Some Pa, s) # xsa) ! length xsa) = None ∧ (∃ys. (Some Q, snd (((Some Pa, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ (None, t) # xs = map (lift Q) xsa @ ys)))› and 6 goals remain*) apply (erule ctran.cases (*‹⟦?a1.0 -c→ ?a2.0; ⋀f s. ⟦?a1.0 = (Some (Basic f), s); ?a2.0 = (None, f s)⟧ ⟹ ?P; ⋀P0 s t P1. ⟦?a1.0 = (Some (Seq P0 P1), s); ?a2.0 = (Some P1, t); (Some P0, s) -c→ (None, t)⟧ ⟹ ?P; ⋀P0 s P2 t P1. ⟦?a1.0 = (Some (Seq P0 P1), s); ?a2.0 = (Some (Seq P2 P1), t); (Some P0, s) -c→ (Some P2, t)⟧ ⟹ ?P; ⋀s b P1 P2. ⟦?a1.0 = (Some (Cond b P1 P2), s); ?a2.0 = (Some P1, s); s ∈ b⟧ ⟹ ?P; ⋀s b P1 P2. ⟦?a1.0 = (Some (Cond b P1 P2), s); ?a2.0 = (Some P2, s); s ∉ b⟧ ⟹ ?P; ⋀s b P. ⟦?a1.0 = (Some (While b P), s); ?a2.0 = (None, s); s ∉ b⟧ ⟹ ?P; ⋀s b P. ⟦?a1.0 = (Some (While b P), s); ?a2.0 = (Some (Seq P (While b P)), s); s ∈ b⟧ ⟹ ?P; ⋀s b P t. ⟦?a1.0 = (Some (Await b P), s); ?a2.0 = (None, t); s ∈ b; (Some P, s) -c*→ (None, t)⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹⋀P s t xs Pa Q f sa. ⟦(None, t) # xs ∈ cptn_mod; (Some (Seq Pa Q), s) = (Some (Basic f), sa); (None, t) = (None, f sa)⟧ ⟹ ∃xsa. (Some Pa, s) # xsa ∈ cptn_mod ∧ ((None, t) # xs = map (lift Q) xsa ∨ fst (((Some Pa, s) # xsa) ! length xsa) = None ∧ (∃ys. (Some Q, snd (((Some Pa, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ (None, t) # xs = map (lift Q) xsa @ ys))› 2. ‹⋀P s t xs Pa Q P0 sa ta P1. ⟦(None, t) # xs ∈ cptn_mod; (Some (Seq Pa Q), s) = (Some (Seq P0 P1), sa); (None, t) = (Some P1, ta); (Some P0, sa) -c→ (None, ta)⟧ ⟹ ∃xsa. (Some Pa, s) # xsa ∈ cptn_mod ∧ ((None, t) # xs = map (lift Q) xsa ∨ fst (((Some Pa, s) # xsa) ! length xsa) = None ∧ (∃ys. (Some Q, snd (((Some Pa, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ (None, t) # xs = map (lift Q) xsa @ ys))› 3. ‹⋀P s t xs Pa Q P0 sa P2 ta P1. ⟦(None, t) # xs ∈ cptn_mod; (Some (Seq Pa Q), s) = (Some (Seq P0 P1), sa); (None, t) = (Some (Seq P2 P1), ta); (Some P0, sa) -c→ (Some P2, ta)⟧ ⟹ ∃xsa. (Some Pa, s) # xsa ∈ cptn_mod ∧ ((None, t) # xs = map (lift Q) xsa ∨ fst (((Some Pa, s) # xsa) ! length xsa) = None ∧ (∃ys. (Some Q, snd (((Some Pa, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ (None, t) # xs = map (lift Q) xsa @ ys))› 4. ‹⋀P s t xs Pa Q sa b P1 P2. ⟦(None, t) # xs ∈ cptn_mod; (Some (Seq Pa Q), s) = (Some (Cond b P1 P2), sa); (None, t) = (Some P1, sa); sa ∈ b⟧ ⟹ ∃xsa. (Some Pa, s) # xsa ∈ cptn_mod ∧ ((None, t) # xs = map (lift Q) xsa ∨ fst (((Some Pa, s) # xsa) ! length xsa) = None ∧ (∃ys. (Some Q, snd (((Some Pa, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ (None, t) # xs = map (lift Q) xsa @ ys))› 5. ‹⋀P s t xs Pa Q sa b P1 P2. ⟦(None, t) # xs ∈ cptn_mod; (Some (Seq Pa Q), s) = (Some (Cond b P1 P2), sa); (None, t) = (Some P2, sa); sa ∉ b⟧ ⟹ ∃xsa. (Some Pa, s) # xsa ∈ cptn_mod ∧ ((None, t) # xs = map (lift Q) xsa ∨ fst (((Some Pa, s) # xsa) ! length xsa) = None ∧ (∃ys. (Some Q, snd (((Some Pa, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ (None, t) # xs = map (lift Q) xsa @ ys))› 6. ‹⋀P s t xs Pa Q sa b Pb. ⟦(None, t) # xs ∈ cptn_mod; (Some (Seq Pa Q), s) = (Some (While b Pb), sa); (None, t) = (None, sa); sa ∉ b⟧ ⟹ ∃xsa. (Some Pa, s) # xsa ∈ cptn_mod ∧ ((None, t) # xs = map (lift Q) xsa ∨ fst (((Some Pa, s) # xsa) ! length xsa) = None ∧ (∃ys. (Some Q, snd (((Some Pa, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ (None, t) # xs = map (lift Q) xsa @ ys))› 7. ‹⋀P s t xs Pa Q sa b Pb. ⟦(None, t) # xs ∈ cptn_mod; (Some (Seq Pa Q), s) = (Some (While b Pb), sa); (None, t) = (Some (Seq Pb (While b Pb)), sa); sa ∈ b⟧ ⟹ ∃xsa. (Some Pa, s) # xsa ∈ cptn_mod ∧ ((None, t) # xs = map (lift Q) xsa ∨ fst (((Some Pa, s) # xsa) ! length xsa) = None ∧ (∃ys. (Some Q, snd (((Some Pa, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ (None, t) # xs = map (lift Q) xsa @ ys))› 8. ‹⋀P s t xs Pa Q sa b Pb ta. ⟦(None, t) # xs ∈ cptn_mod; (Some (Seq Pa Q), s) = (Some (Await b Pb), sa); (None, t) = (None, ta); sa ∈ b; (Some Pb, sa) -c*→ (None, ta)⟧ ⟹ ∃xsa. (Some Pa, s) # xsa ∈ cptn_mod ∧ ((None, t) # xs = map (lift Q) xsa ∨ fst (((Some Pa, s) # xsa) ! length xsa) = None ∧ (∃ys. (Some Q, snd (((Some Pa, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ (None, t) # xs = map (lift Q) xsa @ ys))› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*discuss goal 4*) apply simp (*discuss goal 5*) apply simp (*discuss goal 6*) apply simp (*discuss goal 7*) apply simp (*discuss goal 8*) apply simp (*proven 8 subgoals*) (*discuss goal 4*) apply simp (*discuss goal 5*) apply simp (*discuss goal 6*) apply simp (*top goal: ‹⋀P0 s xs zs P1. ⟦(Some P0, s) # xs ∈ cptn_mod; ∀sa P Q zs. (Some P0, s) # xs = (Some (Seq P Q), sa) # zs ⟶ (∃xs. (Some P, sa) # xs ∈ cptn_mod ∧ (zs = map (lift Q) xs ∨ fst (((Some P, sa) # xs) ! length xs) = None ∧ (∃ys. (Some Q, snd (((Some P, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zs = map (lift Q) xs @ ys))); zs = map (lift P1) xs⟧ ⟹ ∀sa P Q zsa. (Some (Seq P0 P1), s) # zs = (Some (Seq P Q), sa) # zsa ⟶ (∃xs. (Some P, sa) # xs ∈ cptn_mod ∧ (zsa = map (lift Q) xs ∨ fst (((Some P, sa) # xs) ! length xs) = None ∧ (∃ys. (Some Q, snd (((Some P, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zsa = map (lift Q) xs @ ys)))› and 3 goals remain*) apply clarify (*top goal: ‹⋀P0 s xs zs P1. ⟦(Some P0, s) # xs ∈ cptn_mod; ∀P Q. P0 = Seq P Q ⟶ (∃xsa. (Some P, s) # xsa ∈ cptn_mod ∧ (xs = map (lift Q) xsa ∨ fst (((Some P, s) # xsa) ! length xsa) = None ∧ (∃ys. (Some Q, snd (((Some P, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ xs = map (lift Q) xsa @ ys))); zs = map (lift P1) xs⟧ ⟹ ∃xsa. (Some P0, s) # xsa ∈ cptn_mod ∧ (map (lift P1) xs = map (lift P1) xsa ∨ fst (((Some P0, s) # xsa) ! length xsa) = None ∧ (∃ys. (Some P1, snd (((Some P0, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ map (lift P1) xs = map (lift P1) xsa @ ys))› and 3 goals remain*) apply (rule_tac x="xs" in exI (*‹(?P::?'a ⇒ bool) (?x::?'a) ⟹ ∃x::?'a. ?P x›*)) (*top goal: ‹⋀(P0::'a::type com) (s::'a::type) (xs::('a::type com option × 'a::type) list) (zs::('a::type com option × 'a::type) list) P1::'a::type com. ⟦(Some P0, s) # xs ∈ cptn_mod; ∀(P::'a::type com) Q::'a::type com. P0 = Seq P Q ⟶ (∃xsa::('a::type com option × 'a::type) list. (Some P, s) # xsa ∈ cptn_mod ∧ (xs = map (lift Q) xsa ∨ fst (((Some P, s) # xsa) ! length xsa) = None ∧ (∃ys::('a::type com option × 'a::type) list. (Some Q, snd (((Some P, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ xs = map (lift Q) xsa @ ys)))⟧ ⟹ ∃xsa::('a::type com option × 'a::type) list. (Some P0, s) # xsa ∈ cptn_mod ∧ (map (lift P1) xs = map (lift P1) xsa ∨ fst (((Some P0, s) # xsa) ! length xsa) = None ∧ (∃ys::('a::type com option × 'a::type) list. (Some P1, snd (((Some P0, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ map (lift P1) xs = map (lift P1) xsa @ ys))› and 3 goals remain*) apply simp (*discuss goal 7*) apply simp (*top goal: ‹⋀(P0::'a com) (s::'a) (xs::('a com option × 'a) list) (P1::'a com) (ys::('a com option × 'a) list) zs::('a com option × 'a) list. ⟦(Some P0, s) # xs ∈ cptn_mod; ∀(sa::'a) (P::'a com) (Q::'a com) zs::('a com option × 'a) list. (Some P0, s) # xs = (Some (Seq P Q), sa) # zs ⟶ (∃xs::('a com option × 'a) list. (Some P, sa) # xs ∈ cptn_mod ∧ (zs = map (lift Q) xs ∨ fst (((Some P, sa) # xs) ! length xs) = None ∧ (∃ys::('a com option × 'a) list. (Some Q, snd (((Some P, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zs = map (lift Q) xs @ ys))); fst (last ((Some P0, s) # xs)) = None; (Some P1, snd (last ((Some P0, s) # xs))) # ys ∈ cptn_mod; ∀(sa::'a) (P::'a com) (Q::'a com) zs::('a com option × 'a) list. (Some P1, snd (last ((Some P0, s) # xs))) # ys = (Some (Seq P Q), sa) # zs ⟶ (∃xs::('a com option × 'a) list. (Some P, sa) # xs ∈ cptn_mod ∧ (zs = map (lift Q) xs ∨ fst (((Some P, sa) # xs) ! length xs) = None ∧ (∃ys::('a com option × 'a) list. (Some Q, snd (((Some P, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zs = map (lift Q) xs @ ys))); zs = map (lift P1) xs @ ys⟧ ⟹ ∀(sa::'a) (P::'a com) (Q::'a com) zsa::('a com option × 'a) list. (Some (Seq P0 P1), s) # zs = (Some (Seq P Q), sa) # zsa ⟶ (∃xs::('a com option × 'a) list. (Some P, sa) # xs ∈ cptn_mod ∧ (zsa = map (lift Q) xs ∨ fst (((Some P, sa) # xs) ! length xs) = None ∧ (∃ys::('a com option × 'a) list. (Some Q, snd (((Some P, sa) # xs) ! length xs)) # ys ∈ cptn_mod ∧ zsa = map (lift Q) xs @ ys)))› and 2 goals remain*) apply clarify (*top goal: ‹⋀P0 s xs P1 ys zs. ⟦(Some P0, s) # xs ∈ cptn_mod; ∀P Q. P0 = Seq P Q ⟶ (∃xsa. (Some P, s) # xsa ∈ cptn_mod ∧ (xs = map (lift Q) xsa ∨ fst (((Some P, s) # xsa) ! length xsa) = None ∧ (∃ys. (Some Q, snd (((Some P, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ xs = map (lift Q) xsa @ ys))); fst (if xs = [] then (Some P0, s) else last xs) = None; (Some P1, snd (if xs = [] then (Some P0, s) else last xs)) # ys ∈ cptn_mod; ∀P Q. P1 = Seq P Q ⟶ (∃xsa. (Some P, snd (if xs = [] then (Some P0, s) else last xs)) # xsa ∈ cptn_mod ∧ (ys = map (lift Q) xsa ∨ fst (((Some P, snd (if xs = [] then (Some P0, s) else last xs)) # xsa) ! length xsa) = None ∧ (∃ysa. (Some Q, snd (((Some P, snd (if xs = [] then (Some P0, s) else last xs)) # xsa) ! length xsa)) # ysa ∈ cptn_mod ∧ ys = map (lift Q) xsa @ ysa))); zs = map (lift P1) xs @ ys⟧ ⟹ ∃xsa. (Some P0, s) # xsa ∈ cptn_mod ∧ (map (lift P1) xs @ ys = map (lift P1) xsa ∨ fst (((Some P0, s) # xsa) ! length xsa) = None ∧ (∃ysa. (Some P1, snd (((Some P0, s) # xsa) ! length xsa)) # ysa ∈ cptn_mod ∧ map (lift P1) xs @ ys = map (lift P1) xsa @ ysa))› and 2 goals remain*) apply (rule_tac x="xs" in exI (*‹(?P::?'a::type ⇒ bool) (?x::?'a::type) ⟹ ∃x::?'a::type. ?P x›*)) (*top goal: ‹⋀P0 s xs P1 ys zs. ⟦(Some P0, s) # xs ∈ cptn_mod; ∀P Q. P0 = Seq P Q ⟶ (∃xsa. (Some P, s) # xsa ∈ cptn_mod ∧ (xs = map (lift Q) xsa ∨ fst (((Some P, s) # xsa) ! length xsa) = None ∧ (∃ys. (Some Q, snd (((Some P, s) # xsa) ! length xsa)) # ys ∈ cptn_mod ∧ xs = map (lift Q) xsa @ ys))); fst (if xs = [] then (Some P0, s) else last xs) = None; (Some P1, snd (if xs = [] then (Some P0, s) else last xs)) # ys ∈ cptn_mod; ∀P Q. P1 = Seq P Q ⟶ (∃xsa. (Some P, snd (if xs = [] then (Some P0, s) else last xs)) # xsa ∈ cptn_mod ∧ (ys = map (lift Q) xsa ∨ fst (((Some P, snd (if xs = [] then (Some P0, s) else last xs)) # xsa) ! length xsa) = None ∧ (∃ysa. (Some Q, snd (((Some P, snd (if xs = [] then (Some P0, s) else last xs)) # xsa) ! length xsa)) # ysa ∈ cptn_mod ∧ ys = map (lift Q) xsa @ ysa)))⟧ ⟹ ∃xsa. (Some P0, s) # xsa ∈ cptn_mod ∧ (map (lift P1) xs @ ys = map (lift P1) xsa ∨ fst (((Some P0, s) # xsa) ! length xsa) = None ∧ (∃ysa. (Some P1, snd (((Some P0, s) # xsa) ! length xsa)) # ysa ∈ cptn_mod ∧ map (lift P1) xs @ ys = map (lift P1) xsa @ ysa))› and 2 goals remain*) apply (simp add: last_length (*‹(?a # ?xs) ! length ?xs = last (?a # ?xs)›*)) (*discuss goal 8*) apply simp (*discuss goal 9*) apply simp (*proven 9 subgoals*) . lemma cptn_onlyif_cptn_mod_aux [rule_format]: "∀s Q t xs.((Some a, s), Q, t) ∈ ctran ⟶ (Q, t) # xs ∈ cptn_mod ⟶ (Some a, s) # (Q, t) # xs ∈ cptn_mod" supply [[simproc del: defined_all]] apply(induct a) apply simp_all ― ‹basic› apply clarify apply(erule ctran.cases,simp_all) apply(rule CptnModNone,rule Basic,simp) apply clarify apply(erule ctran.cases,simp_all) ― ‹Seq1› apply(rule_tac xs="[(None,ta)]" in CptnModSeq2) apply(erule CptnModNone) apply(rule CptnModOne) apply simp apply simp apply(simp add:lift_def) ― ‹Seq2› apply(erule_tac x=sa in allE) apply(erule_tac x="Some P2" in allE) apply(erule allE,erule impE, assumption) apply(drule div_seq,simp) apply clarify apply(erule disjE) apply clarify apply(erule allE,erule impE, assumption) apply(erule_tac CptnModSeq1) apply(simp add:lift_def) apply clarify apply(erule allE,erule impE, assumption) apply(erule_tac CptnModSeq2) apply (simp add:last_length) apply (simp add:last_length) apply(simp add:lift_def) ― ‹Cond› apply clarify apply(erule ctran.cases,simp_all) apply(force elim: CptnModCondT) apply(force elim: CptnModCondF) ― ‹While› apply clarify apply(erule ctran.cases,simp_all) apply(rule CptnModNone,erule WhileF,simp) apply(drule div_seq,force) apply clarify apply (erule disjE) apply(force elim:CptnModWhile1) apply clarify apply(force simp add:last_length elim:CptnModWhile2) ― ‹await› apply clarify apply(erule ctran.cases,simp_all) apply(rule CptnModNone,erule Await,simp+) done lemma cptn_onlyif_cptn_mod [rule_format]: "c ∈ cptn ⟹ c ∈ cptn_mod" apply (erule cptn.induct (*‹⟦?x ∈ cptn; ⋀P s. ?P [(P, s)]; ⋀P t xs s. ⟦(P, t) # xs ∈ cptn; ?P ((P, t) # xs)⟧ ⟹ ?P ((P, s) # (P, t) # xs); ⋀P s Q t xs. ⟦(P, s) -c→ (Q, t); (Q, t) # xs ∈ cptn; ?P ((Q, t) # xs)⟧ ⟹ ?P ((P, s) # (Q, t) # xs)⟧ ⟹ ?P ?x›*)) (*goals: 1. ‹⋀P s. [(P, s)] ∈ cptn_mod› 2. ‹⋀P t xs s. ⟦(P, t) # xs ∈ cptn; (P, t) # xs ∈ cptn_mod⟧ ⟹ (P, s) # (P, t) # xs ∈ cptn_mod› 3. ‹⋀P s Q t xs. ⟦(P, s) -c→ (Q, t); (Q, t) # xs ∈ cptn; (Q, t) # xs ∈ cptn_mod⟧ ⟹ (P, s) # (Q, t) # xs ∈ cptn_mod› discuss goal 1*) apply (rule CptnModOne (*‹[(?P, ?s)] ∈ cptn_mod›*)) (*discuss goal 2*) apply (erule CptnModEnv (*‹(?P, ?t) # ?xs ∈ cptn_mod ⟹ (?P, ?s) # (?P, ?t) # ?xs ∈ cptn_mod›*)) (*discuss goal 3*) apply (case_tac P) (*goals: 1. ‹⋀P s Q t xs. ⟦(P, s) -c→ (Q, t); (Q, t) # xs ∈ cptn; (Q, t) # xs ∈ cptn_mod; P = None⟧ ⟹ (P, s) # (Q, t) # xs ∈ cptn_mod› 2. ‹⋀P s Q t xs a. ⟦(P, s) -c→ (Q, t); (Q, t) # xs ∈ cptn; (Q, t) # xs ∈ cptn_mod; P = Some a⟧ ⟹ (P, s) # (Q, t) # xs ∈ cptn_mod› discuss goal 1*) apply simp (*top goal: ‹⋀P s Q t xs. ⟦(P, s) -c→ (Q, t); (Q, t) # xs ∈ cptn; (Q, t) # xs ∈ cptn_mod; P = None⟧ ⟹ (P, s) # (Q, t) # xs ∈ cptn_mod› and 1 goal remains*) apply (erule ctran.cases (*‹⟦?a1.0 -c→ ?a2.0; ⋀f s. ⟦?a1.0 = (Some (Basic f), s); ?a2.0 = (None, f s)⟧ ⟹ ?P; ⋀P0 s t P1. ⟦?a1.0 = (Some (Seq P0 P1), s); ?a2.0 = (Some P1, t); (Some P0, s) -c→ (None, t)⟧ ⟹ ?P; ⋀P0 s P2 t P1. ⟦?a1.0 = (Some (Seq P0 P1), s); ?a2.0 = (Some (Seq P2 P1), t); (Some P0, s) -c→ (Some P2, t)⟧ ⟹ ?P; ⋀s b P1 P2. ⟦?a1.0 = (Some (Cond b P1 P2), s); ?a2.0 = (Some P1, s); s ∈ b⟧ ⟹ ?P; ⋀s b P1 P2. ⟦?a1.0 = (Some (Cond b P1 P2), s); ?a2.0 = (Some P2, s); s ∉ b⟧ ⟹ ?P; ⋀s b P. ⟦?a1.0 = (Some (While b P), s); ?a2.0 = (None, s); s ∉ b⟧ ⟹ ?P; ⋀s b P. ⟦?a1.0 = (Some (While b P), s); ?a2.0 = (Some (Seq P (While b P)), s); s ∈ b⟧ ⟹ ?P; ⋀s b P t. ⟦?a1.0 = (Some (Await b P), s); ?a2.0 = (None, t); s ∈ b; (Some P, s) -c*→ (None, t)⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹⋀P s Q t xs f sa. ⟦(Q, t) # xs ∈ cptn; (Q, t) # xs ∈ cptn_mod; P = None; (None, s) = (Some (Basic f), sa); (Q, t) = (None, f sa)⟧ ⟹ (None, s) # (Q, t) # xs ∈ cptn_mod› 2. ‹⋀P s Q t xs P0 sa ta P1. ⟦(Q, t) # xs ∈ cptn; (Q, t) # xs ∈ cptn_mod; P = None; (None, s) = (Some (Seq P0 P1), sa); (Q, t) = (Some P1, ta); (Some P0, sa) -c→ (None, ta)⟧ ⟹ (None, s) # (Q, t) # xs ∈ cptn_mod› 3. ‹⋀P s Q t xs P0 sa P2 ta P1. ⟦(Q, t) # xs ∈ cptn; (Q, t) # xs ∈ cptn_mod; P = None; (None, s) = (Some (Seq P0 P1), sa); (Q, t) = (Some (Seq P2 P1), ta); (Some P0, sa) -c→ (Some P2, ta)⟧ ⟹ (None, s) # (Q, t) # xs ∈ cptn_mod› 4. ‹⋀P s Q t xs sa b P1 P2. ⟦(Q, t) # xs ∈ cptn; (Q, t) # xs ∈ cptn_mod; P = None; (None, s) = (Some (Cond b P1 P2), sa); (Q, t) = (Some P1, sa); sa ∈ b⟧ ⟹ (None, s) # (Q, t) # xs ∈ cptn_mod› 5. ‹⋀P s Q t xs sa b P1 P2. ⟦(Q, t) # xs ∈ cptn; (Q, t) # xs ∈ cptn_mod; P = None; (None, s) = (Some (Cond b P1 P2), sa); (Q, t) = (Some P2, sa); sa ∉ b⟧ ⟹ (None, s) # (Q, t) # xs ∈ cptn_mod› 6. ‹⋀P s Q t xs sa b Pa. ⟦(Q, t) # xs ∈ cptn; (Q, t) # xs ∈ cptn_mod; P = None; (None, s) = (Some (While b Pa), sa); (Q, t) = (None, sa); sa ∉ b⟧ ⟹ (None, s) # (Q, t) # xs ∈ cptn_mod› 7. ‹⋀P s Q t xs sa b Pa. ⟦(Q, t) # xs ∈ cptn; (Q, t) # xs ∈ cptn_mod; P = None; (None, s) = (Some (While b Pa), sa); (Q, t) = (Some (Seq Pa (While b Pa)), sa); sa ∈ b⟧ ⟹ (None, s) # (Q, t) # xs ∈ cptn_mod› 8. ‹⋀P s Q t xs sa b Pa ta. ⟦(Q, t) # xs ∈ cptn; (Q, t) # xs ∈ cptn_mod; P = None; (None, s) = (Some (Await b Pa), sa); (Q, t) = (None, ta); sa ∈ b; (Some Pa, sa) -c*→ (None, ta)⟧ ⟹ (None, s) # (Q, t) # xs ∈ cptn_mod› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*discuss goal 4*) apply simp (*discuss goal 5*) apply simp (*discuss goal 6*) apply simp (*discuss goal 7*) apply simp (*discuss goal 8*) apply simp (*proven 8 subgoals*) (*discuss goal 2*) apply simp (*goal: ‹⋀P s Q t xs a. ⟦(P, s) -c→ (Q, t); (Q, t) # xs ∈ cptn; (Q, t) # xs ∈ cptn_mod; P = Some a⟧ ⟹ (P, s) # (Q, t) # xs ∈ cptn_mod›*) apply (force elim:cptn_onlyif_cptn_mod_aux (*‹⟦(Some ?a, ?s) -c→ (?Q, ?t); (?Q, ?t) # ?xs ∈ cptn_mod⟧ ⟹ (Some ?a, ?s) # (?Q, ?t) # ?xs ∈ cptn_mod›*)) (*proven 2 subgoals*) (*proven 3 subgoals*) . lemma lift_is_cptn: "c∈cptn ⟹ map (lift P) c ∈ cptn" apply (erule cptn.induct (*‹⟦?x ∈ cptn; ⋀P s. ?P [(P, s)]; ⋀P t xs s. ⟦(P, t) # xs ∈ cptn; ?P ((P, t) # xs)⟧ ⟹ ?P ((P, s) # (P, t) # xs); ⋀P s Q t xs. ⟦(P, s) -c→ (Q, t); (Q, t) # xs ∈ cptn; ?P ((Q, t) # xs)⟧ ⟹ ?P ((P, s) # (Q, t) # xs)⟧ ⟹ ?P ?x›*)) (*goals: 1. ‹⋀Pa s. map (lift P) [(Pa, s)] ∈ cptn› 2. ‹⋀Pa t xs s. ⟦(Pa, t) # xs ∈ cptn; map (lift P) ((Pa, t) # xs) ∈ cptn⟧ ⟹ map (lift P) ((Pa, s) # (Pa, t) # xs) ∈ cptn› 3. ‹⋀Pa s Q t xs. ⟦(Pa, s) -c→ (Q, t); (Q, t) # xs ∈ cptn; map (lift P) ((Q, t) # xs) ∈ cptn⟧ ⟹ map (lift P) ((Pa, s) # (Q, t) # xs) ∈ cptn› discuss goal 1*) apply (force simp add:lift_def (*‹lift (?Q::?'a::type com) ≡ λ(P::?'a::type com option, s::?'a::type). if P = None then (Some ?Q, s) else (Some (Seq (the P) ?Q), s)›*) CptnOne (*‹[(?P::?'a::type com option, ?s::?'a::type)] ∈ cptn›*)) (*discuss goal 2*) apply (force intro:CptnEnv (*‹(?P, ?t) # ?xs ∈ cptn ⟹ (?P, ?s) # (?P, ?t) # ?xs ∈ cptn›*) simp add:lift_def (*‹lift ?Q ≡ λ(P, s). if P = None then (Some ?Q, s) else (Some (Seq (the P) ?Q), s)›*)) (*discuss goal 3*) apply (force simp add:lift_def (*‹lift ?Q ≡ λ(P, s). if P = None then (Some ?Q, s) else (Some (Seq (the P) ?Q), s)›*) intro:CptnComp (*‹⟦(?P, ?s) -c→ (?Q, ?t); (?Q, ?t) # ?xs ∈ cptn⟧ ⟹ (?P, ?s) # (?Q, ?t) # ?xs ∈ cptn›*) Seq2 (*‹(Some ?P0.0, ?s) -c→ (Some ?P2.0, ?t) ⟹ (Some (Seq ?P0.0 ?P1.0), ?s) -c→ (Some (Seq ?P2.0 ?P1.0), ?t)›*) Seq1 (*‹(Some ?P0.0, ?s) -c→ (None, ?t) ⟹ (Some (Seq ?P0.0 ?P1.0), ?s) -c→ (Some ?P1.0, ?t)›*) elim:ctran.cases (*‹⟦?a1.0 -c→ ?a2.0; ⋀f s. ⟦?a1.0 = (Some (Basic f), s); ?a2.0 = (None, f s)⟧ ⟹ ?P; ⋀P0 s t P1. ⟦?a1.0 = (Some (Seq P0 P1), s); ?a2.0 = (Some P1, t); (Some P0, s) -c→ (None, t)⟧ ⟹ ?P; ⋀P0 s P2 t P1. ⟦?a1.0 = (Some (Seq P0 P1), s); ?a2.0 = (Some (Seq P2 P1), t); (Some P0, s) -c→ (Some P2, t)⟧ ⟹ ?P; ⋀s b P1 P2. ⟦?a1.0 = (Some (Cond b P1 P2), s); ?a2.0 = (Some P1, s); s ∈ b⟧ ⟹ ?P; ⋀s b P1 P2. ⟦?a1.0 = (Some (Cond b P1 P2), s); ?a2.0 = (Some P2, s); s ∉ b⟧ ⟹ ?P; ⋀s b P. ⟦?a1.0 = (Some (While b P), s); ?a2.0 = (None, s); s ∉ b⟧ ⟹ ?P; ⋀s b P. ⟦?a1.0 = (Some (While b P), s); ?a2.0 = (Some (Seq P (While b P)), s); s ∈ b⟧ ⟹ ?P; ⋀s b P t. ⟦?a1.0 = (Some (Await b P), s); ?a2.0 = (None, t); s ∈ b; (Some P, s) -c*→ (None, t)⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*proven 3 subgoals*) . lemma cptn_append_is_cptn [rule_format]: "∀b a. b#c1∈cptn ⟶ a#c2∈cptn ⟶ (b#c1)!length c1=a ⟶ b#c1@c2∈cptn" apply (induct c1) (*goals: 1. ‹∀b a. [b] ∈ cptn ⟶ a # c2 ∈ cptn ⟶ [b] ! length [] = a ⟶ b # [] @ c2 ∈ cptn› 2. ‹⋀a c1. ∀b a. b # c1 ∈ cptn ⟶ a # c2 ∈ cptn ⟶ (b # c1) ! length c1 = a ⟶ b # c1 @ c2 ∈ cptn ⟹ ∀b aa. b # a # c1 ∈ cptn ⟶ aa # c2 ∈ cptn ⟶ (b # a # c1) ! length (a # c1) = aa ⟶ b # (a # c1) @ c2 ∈ cptn› discuss goal 1*) apply simp (*discuss goal 2*) apply clarify (*goal: ‹⋀a c1. ∀b a. b # c1 ∈ cptn ⟶ a # c2 ∈ cptn ⟶ (b # c1) ! length c1 = a ⟶ b # c1 @ c2 ∈ cptn ⟹ ∀b aa. b # a # c1 ∈ cptn ⟶ aa # c2 ∈ cptn ⟶ (b # a # c1) ! length (a # c1) = aa ⟶ b # (a # c1) @ c2 ∈ cptn›*) apply (erule cptn.cases (*‹⟦?a ∈ cptn; ⋀P s. ?a = [(P, s)] ⟹ ?P; ⋀P t xs s. ⟦?a = (P, s) # (P, t) # xs; (P, t) # xs ∈ cptn⟧ ⟹ ?P; ⋀P s Q t xs. ⟦?a = (P, s) # (Q, t) # xs; (P, s) -c→ (Q, t); (Q, t) # xs ∈ cptn⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹⋀a b c1 aa ba ab bb P s. ⟦∀b a. b # c1 ∈ cptn ⟶ a # c2 ∈ cptn ⟶ (b # c1) ! length c1 = a ⟶ b # c1 @ c2 ∈ cptn; (ab, bb) # c2 ∈ cptn; ((aa, ba) # (a, b) # c1) ! length ((a, b) # c1) = (ab, bb); (aa, ba) # (a, b) # c1 = [(P, s)]⟧ ⟹ (aa, ba) # ((a, b) # c1) @ c2 ∈ cptn› 2. ‹⋀a b c1 aa ba ab bb P t xs s. ⟦∀b a. b # c1 ∈ cptn ⟶ a # c2 ∈ cptn ⟶ (b # c1) ! length c1 = a ⟶ b # c1 @ c2 ∈ cptn; (ab, bb) # c2 ∈ cptn; ((aa, ba) # (a, b) # c1) ! length ((a, b) # c1) = (ab, bb); (aa, ba) # (a, b) # c1 = (P, s) # (P, t) # xs; (P, t) # xs ∈ cptn⟧ ⟹ (aa, ba) # ((a, b) # c1) @ c2 ∈ cptn› 3. ‹⋀a b c1 aa ba ab bb P s Q t xs. ⟦∀b a. b # c1 ∈ cptn ⟶ a # c2 ∈ cptn ⟶ (b # c1) ! length c1 = a ⟶ b # c1 @ c2 ∈ cptn; (ab, bb) # c2 ∈ cptn; ((aa, ba) # (a, b) # c1) ! length ((a, b) # c1) = (ab, bb); (aa, ba) # (a, b) # c1 = (P, s) # (Q, t) # xs; (P, s) -c→ (Q, t); (Q, t) # xs ∈ cptn⟧ ⟹ (aa, ba) # ((a, b) # c1) @ c2 ∈ cptn› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*top goal: ‹⋀a b c1 aa ba ab bb P t xs s. ⟦∀b a. b # c1 ∈ cptn ⟶ a # c2 ∈ cptn ⟶ (b # c1) ! length c1 = a ⟶ b # c1 @ c2 ∈ cptn; (ab, bb) # c2 ∈ cptn; ((aa, ba) # (a, b) # c1) ! length ((a, b) # c1) = (ab, bb); (aa, ba) # (a, b) # c1 = (P, s) # (P, t) # xs; (P, t) # xs ∈ cptn⟧ ⟹ (aa, ba) # ((a, b) # c1) @ c2 ∈ cptn› and 1 goal remains*) apply (force intro:CptnEnv (*‹(?P, ?t) # ?xs ∈ cptn ⟹ (?P, ?s) # (?P, ?t) # ?xs ∈ cptn›*)) (*discuss goal 3*) apply simp (*goal: ‹⋀(a::'a com option) (b::'a) (c1::('a com option × 'a) list) (aa::'a com option) (ba::'a) (ab::'a com option) (bb::'a) (P::'a com option) (s::'a) (Q::'a com option) (t::'a) xs::('a com option × 'a) list. ⟦∀(b::'a com option × 'a) a::'a com option × 'a. b # c1 ∈ cptn ⟶ a # (c2::('a com option × 'a) list) ∈ cptn ⟶ (b # c1) ! length c1 = a ⟶ b # c1 @ c2 ∈ cptn; (ab, bb) # c2 ∈ cptn; ((aa, ba) # (a, b) # c1) ! length ((a, b) # c1) = (ab, bb); (aa, ba) # (a, b) # c1 = (P, s) # (Q, t) # xs; (P, s) -c→ (Q, t); (Q, t) # xs ∈ cptn⟧ ⟹ (aa, ba) # ((a, b) # c1) @ c2 ∈ cptn›*) apply (force elim:CptnComp (*‹⟦(?P, ?s) -c→ (?Q, ?t); (?Q, ?t) # ?xs ∈ cptn⟧ ⟹ (?P, ?s) # (?Q, ?t) # ?xs ∈ cptn›*)) (*proven 3 subgoals*) (*proven 2 subgoals*) . lemma last_lift: "⟦xs≠[]; fst(xs!(length xs - (Suc 0)))=None⟧ ⟹ fst((map (lift P) xs)!(length (map (lift P) xs)- (Suc 0)))=(Some P)" apply (cases "(xs ! (length xs - (Suc 0)))") (*goal: ‹⟦xs ≠ []; fst (xs ! (length xs - Suc 0)) = None⟧ ⟹ fst (map (lift P) xs ! (length (map (lift P) xs) - Suc 0)) = Some P›*) by (simp add:lift_def (*‹lift ?Q ≡ λ(P, s). if P = None then (Some ?Q, s) else (Some (Seq (the P) ?Q), s)›*)) lemma last_fst [rule_format]: "P((a#x)!length x) ⟶ ¬P a ⟶ P (x!(length x - (Suc 0)))" apply (induct x) (*goals: 1. ‹P ([a] ! length []) ⟶ ¬ P a ⟶ P ([] ! (length [] - Suc 0))› 2. ‹⋀aa x. P ((a # x) ! length x) ⟶ ¬ P a ⟶ P (x ! (length x - Suc 0)) ⟹ P ((a # aa # x) ! length (aa # x)) ⟶ ¬ P a ⟶ P ((aa # x) ! (length (aa # x) - Suc 0))› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma last_fst_esp: "fst(((Some a,s)#xs)!(length xs))=None ⟹ fst(xs!(length xs - (Suc 0)))=None" apply (erule last_fst (*‹⟦?P ((?a # ?x) ! length ?x); ¬ ?P ?a⟧ ⟹ ?P (?x ! (length ?x - Suc 0))›*)) (*goal: ‹fst (((Some a, s) # xs) ! length xs) = None ⟹ fst (xs ! (length xs - Suc 0)) = None›*) by simp lemma last_snd: "xs≠[] ⟹ snd(((map (lift P) xs))!(length (map (lift P) xs) - (Suc 0)))=snd(xs!(length xs - (Suc 0)))" apply (cases "(xs ! (length xs - (Suc 0)))") (*goal: ‹xs ≠ [] ⟹ snd (map (lift P) xs ! (length (map (lift P) xs) - Suc 0)) = snd (xs ! (length xs - Suc 0))›*) by (simp add:lift_def (*‹lift ?Q ≡ λ(P, s). if P = None then (Some ?Q, s) else (Some (Seq (the P) ?Q), s)›*)) lemma Cons_lift: "(Some (Seq P Q), s) # (map (lift Q) xs) = map (lift Q) ((Some P, s) # xs)" by (simp add:lift_def (*‹lift ?Q ≡ λ(P, s). if P = None then (Some ?Q, s) else (Some (Seq (the P) ?Q), s)›*)) lemma Cons_lift_append: "(Some (Seq P Q), s) # (map (lift Q) xs) @ ys = map (lift Q) ((Some P, s) # xs)@ ys " by (simp add:lift_def (*‹lift ?Q ≡ λ(P, s). if P = None then (Some ?Q, s) else (Some (Seq (the P) ?Q), s)›*)) lemma lift_nth: "i<length xs ⟹ map (lift Q) xs ! i = lift Q (xs! i)" by (simp add:lift_def (*‹lift ?Q ≡ λ(P, s). if P = None then (Some ?Q, s) else (Some (Seq (the P) ?Q), s)›*)) lemma snd_lift: "i< length xs ⟹ snd(lift Q (xs ! i))= snd (xs ! i)" apply (cases "xs!i") (*goal: ‹i < length xs ⟹ snd (lift Q (xs ! i)) = snd (xs ! i)›*) by (simp add:lift_def (*‹lift (?Q::?'a::type com) ≡ λ(P::?'a::type com option, s::?'a::type). if P = None then (Some ?Q, s) else (Some (Seq (the P) ?Q), s)›*)) lemma cptn_if_cptn_mod: "c ∈ cptn_mod ⟹ c ∈ cptn" apply (erule cptn_mod.induct (*‹⟦?x ∈ cptn_mod; ⋀P s. ?P [(P, s)]; ⋀P t xs s. ⟦(P, t) # xs ∈ cptn_mod; ?P ((P, t) # xs)⟧ ⟹ ?P ((P, s) # (P, t) # xs); ⋀P s t xs. ⟦(Some P, s) -c→ (None, t); (None, t) # xs ∈ cptn_mod; ?P ((None, t) # xs)⟧ ⟹ ?P ((Some P, s) # (None, t) # xs); ⋀P0 s ys b P1. ⟦(Some P0, s) # ys ∈ cptn_mod; ?P ((Some P0, s) # ys); s ∈ b⟧ ⟹ ?P ((Some (Cond b P0 P1), s) # (Some P0, s) # ys); ⋀P1 s ys b P0. ⟦(Some P1, s) # ys ∈ cptn_mod; ?P ((Some P1, s) # ys); s ∉ b⟧ ⟹ ?P ((Some (Cond b P0 P1), s) # (Some P1, s) # ys); ⋀P0 s xs zs P1. ⟦(Some P0, s) # xs ∈ cptn_mod; ?P ((Some P0, s) # xs); zs = map (lift P1) xs⟧ ⟹ ?P ((Some (Seq P0 P1), s) # zs); ⋀P0 s xs P1 ys zs. ⟦(Some P0, s) # xs ∈ cptn_mod; ?P ((Some P0, s) # xs); fst (last ((Some P0, s) # xs)) = None; (Some P1, snd (last ((Some P0, s) # xs))) # ys ∈ cptn_mod; ?P ((Some P1, snd (last ((Some P0, s) # xs))) # ys); zs = map (lift P1) xs @ ys⟧ ⟹ ?P ((Some (Seq P0 P1), s) # zs); ⋀P s xs b zs. ⟦(Some P, s) # xs ∈ cptn_mod; ?P ((Some P, s) # xs); s ∈ b; zs = map (lift (While b P)) xs⟧ ⟹ ?P ((Some (While b P), s) # (Some (Seq P (While b P)), s) # zs); ⋀P s xs b zs ys. ⟦(Some P, s) # xs ∈ cptn_mod; ?P ((Some P, s) # xs); fst (last ((Some P, s) # xs)) = None; s ∈ b; zs = map (lift (While b P)) xs @ ys; (Some (While b P), snd (last ((Some P, s) # xs))) # ys ∈ cptn_mod; ?P ((Some (While b P), snd (last ((Some P, s) # xs))) # ys)⟧ ⟹ ?P ((Some (While b P), s) # (Some (Seq P (While b P)), s) # zs)⟧ ⟹ ?P ?x›*)) (*goals: 1. ‹⋀P s. [(P, s)] ∈ cptn› 2. ‹⋀P t xs s. ⟦(P, t) # xs ∈ cptn_mod; (P, t) # xs ∈ cptn⟧ ⟹ (P, s) # (P, t) # xs ∈ cptn› 3. ‹⋀P s t xs. ⟦(Some P, s) -c→ (None, t); (None, t) # xs ∈ cptn_mod; (None, t) # xs ∈ cptn⟧ ⟹ (Some P, s) # (None, t) # xs ∈ cptn› 4. ‹⋀P0 s ys b P1. ⟦(Some P0, s) # ys ∈ cptn_mod; (Some P0, s) # ys ∈ cptn; s ∈ b⟧ ⟹ (Some (Cond b P0 P1), s) # (Some P0, s) # ys ∈ cptn› 5. ‹⋀P1 s ys b P0. ⟦(Some P1, s) # ys ∈ cptn_mod; (Some P1, s) # ys ∈ cptn; s ∉ b⟧ ⟹ (Some (Cond b P0 P1), s) # (Some P1, s) # ys ∈ cptn› 6. ‹⋀P0 s xs zs P1. ⟦(Some P0, s) # xs ∈ cptn_mod; (Some P0, s) # xs ∈ cptn; zs = map (lift P1) xs⟧ ⟹ (Some (Seq P0 P1), s) # zs ∈ cptn› 7. ‹⋀P0 s xs P1 ys zs. ⟦(Some P0, s) # xs ∈ cptn_mod; (Some P0, s) # xs ∈ cptn; fst (last ((Some P0, s) # xs)) = None; (Some P1, snd (last ((Some P0, s) # xs))) # ys ∈ cptn_mod; (Some P1, snd (last ((Some P0, s) # xs))) # ys ∈ cptn; zs = map (lift P1) xs @ ys⟧ ⟹ (Some (Seq P0 P1), s) # zs ∈ cptn› 8. ‹⋀P s xs b zs. ⟦(Some P, s) # xs ∈ cptn_mod; (Some P, s) # xs ∈ cptn; s ∈ b; zs = map (lift (While b P)) xs⟧ ⟹ (Some (While b P), s) # (Some (Seq P (While b P)), s) # zs ∈ cptn› 9. ‹⋀P s xs b zs ys. ⟦(Some P, s) # xs ∈ cptn_mod; (Some P, s) # xs ∈ cptn; fst (last ((Some P, s) # xs)) = None; s ∈ b; zs = map (lift (While b P)) xs @ ys; (Some (While b P), snd (last ((Some P, s) # xs))) # ys ∈ cptn_mod; (Some (While b P), snd (last ((Some P, s) # xs))) # ys ∈ cptn⟧ ⟹ (Some (While b P), s) # (Some (Seq P (While b P)), s) # zs ∈ cptn› discuss goal 1*) apply (rule CptnOne (*‹[(?P, ?s)] ∈ cptn›*)) (*discuss goal 2*) apply (erule CptnEnv (*‹(?P::?'a com option, ?t::?'a) # (?xs::(?'a com option × ?'a) list) ∈ cptn ⟹ (?P, ?s::?'a) # (?P, ?t) # ?xs ∈ cptn›*)) (*discuss goal 3*) apply (erule CptnComp (*‹⟦(?P::?'a com option, ?s::?'a) -c→ (?Q::?'a com option, ?t::?'a); (?Q, ?t) # (?xs::(?'a com option × ?'a) list) ∈ cptn⟧ ⟹ (?P, ?s) # (?Q, ?t) # ?xs ∈ cptn›*)) (*top goal: ‹⋀P s t xs. ⟦(Some P, s) -c→ (None, t); (None, t) # xs ∈ cptn_mod; (None, t) # xs ∈ cptn⟧ ⟹ (Some P, s) # (None, t) # xs ∈ cptn› and 6 goals remain*) apply simp (*discuss goal 4*) apply (rule CptnComp (*‹⟦(?P, ?s) -c→ (?Q, ?t); (?Q, ?t) # ?xs ∈ cptn⟧ ⟹ (?P, ?s) # (?Q, ?t) # ?xs ∈ cptn›*)) (*goals: 1. ‹⋀P0 s ys b P1. ⟦(Some P0, s) # ys ∈ cptn_mod; (Some P0, s) # ys ∈ cptn; s ∈ b⟧ ⟹ (Some (Cond b P0 P1), s) -c→ (Some P0, s)› 2. ‹⋀P0 s ys b P1. ⟦(Some P0, s) # ys ∈ cptn_mod; (Some P0, s) # ys ∈ cptn; s ∈ b⟧ ⟹ (Some P0, s) # ys ∈ cptn› discuss goal 1*) apply (erule CondT (*‹(?s::?'a) ∈ (?b::?'a set) ⟹ (Some (Cond ?b (?P1.0::?'a com) (?P2.0::?'a com)), ?s) -c→ (Some ?P1.0, ?s)›*)) (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 5*) apply (rule CptnComp (*‹⟦(?P, ?s) -c→ (?Q, ?t); (?Q, ?t) # ?xs ∈ cptn⟧ ⟹ (?P, ?s) # (?Q, ?t) # ?xs ∈ cptn›*)) (*goals: 1. ‹⋀P1 s ys b P0. ⟦(Some P1, s) # ys ∈ cptn_mod; (Some P1, s) # ys ∈ cptn; s ∉ b⟧ ⟹ (Some (Cond b P0 P1), s) -c→ (Some P1, s)› 2. ‹⋀P1 s ys b P0. ⟦(Some P1, s) # ys ∈ cptn_mod; (Some P1, s) # ys ∈ cptn; s ∉ b⟧ ⟹ (Some P1, s) # ys ∈ cptn› discuss goal 1*) apply (erule CondF (*‹?s ∉ ?b ⟹ (Some (Cond ?b ?P1.0 ?P2.0), ?s) -c→ (Some ?P2.0, ?s)›*)) (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 6*) apply (erule cptn.cases (*‹⟦?a ∈ cptn; ⋀P s. ?a = [(P, s)] ⟹ ?P; ⋀P t xs s. ⟦?a = (P, s) # (P, t) # xs; (P, t) # xs ∈ cptn⟧ ⟹ ?P; ⋀P s Q t xs. ⟦?a = (P, s) # (Q, t) # xs; (P, s) -c→ (Q, t); (Q, t) # xs ∈ cptn⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹⋀(P0::'a com) (s::'a) (xs::('a com option × 'a) list) (zs::('a com option × 'a) list) (P1::'a com) (P::'a com option) sa::'a. ⟦(Some P0, s) # xs ∈ cptn_mod; zs = map (lift P1) xs; (Some P0, s) # xs = [(P, sa)]⟧ ⟹ (Some (Seq P0 P1), s) # zs ∈ cptn› 2. ‹⋀(P0::'a com) (s::'a) (xs::('a com option × 'a) list) (zs::('a com option × 'a) list) (P1::'a com) (P::'a com option) (t::'a) (xsa::('a com option × 'a) list) sa::'a. ⟦(Some P0, s) # xs ∈ cptn_mod; zs = map (lift P1) xs; (Some P0, s) # xs = (P, sa) # (P, t) # xsa; (P, t) # xsa ∈ cptn⟧ ⟹ (Some (Seq P0 P1), s) # zs ∈ cptn› 3. ‹⋀(P0::'a com) (s::'a) (xs::('a com option × 'a) list) (zs::('a com option × 'a) list) (P1::'a com) (P::'a com option) (sa::'a) (Q::'a com option) (t::'a) xsa::('a com option × 'a) list. ⟦(Some P0, s) # xs ∈ cptn_mod; zs = map (lift P1) xs; (Some P0, s) # xs = (P, sa) # (Q, t) # xsa; (P, sa) -c→ (Q, t); (Q, t) # xsa ∈ cptn⟧ ⟹ (Some (Seq P0 P1), s) # zs ∈ cptn› discuss goal 1*) apply simp (*top goal: ‹⋀P0 s xs zs P1 P sa. ⟦(Some P0, s) # xs ∈ cptn_mod; zs = map (lift P1) xs; (Some P0, s) # xs = [(P, sa)]⟧ ⟹ (Some (Seq P0 P1), s) # zs ∈ cptn› and 5 goals remain*) apply (rule CptnOne (*‹[(?P, ?s)] ∈ cptn›*)) (*discuss goal 2*) apply simp (*top goal: ‹⋀(P0::'a com) (s::'a) (xs::('a com option × 'a) list) (zs::('a com option × 'a) list) (P1::'a com) (P::'a com option) (t::'a) (xsa::('a com option × 'a) list) sa::'a. ⟦(Some P0, s) # xs ∈ cptn_mod; zs = map (lift P1) xs; (Some P0, s) # xs = (P, sa) # (P, t) # xsa; (P, t) # xsa ∈ cptn⟧ ⟹ (Some (Seq P0 P1), s) # zs ∈ cptn› and 4 goals remain*) apply clarify (*top goal: ‹⋀P0 s xs zs P1 t xsa. ⟦(Some P0, s) # (Some P0, t) # xsa ∈ cptn_mod; zs = lift P1 (Some P0, t) # map (lift P1) xsa; xs = (Some P0, t) # xsa; (Some P0, t) # xsa ∈ cptn⟧ ⟹ (Some (Seq P0 P1), s) # lift P1 (Some P0, t) # map (lift P1) xsa ∈ cptn› and 4 goals remain*) apply (drule_tac P=P1 in lift_is_cptn (*‹(?c::(?'a com option × ?'a) list) ∈ cptn ⟹ map (lift (?P::?'a com)) ?c ∈ cptn›*)) (*top goal: ‹⋀(P0::'a com) (s::'a) (xs::('a com option × 'a) list) (zs::('a com option × 'a) list) (P1::'a com) (t::'a) xsa::('a com option × 'a) list. ⟦(Some P0, s) # (Some P0, t) # xsa ∈ cptn_mod; (Some P0, t) # xsa ∈ cptn⟧ ⟹ (Some (Seq P0 P1), s) # lift P1 (Some P0, t) # map (lift P1) xsa ∈ cptn› and 4 goals remain*) apply (simp add:lift_def (*‹lift (?Q::?'a::type com) ≡ λ(P::?'a::type com option, s::?'a::type). if P = None then (Some ?Q, s) else (Some (Seq (the P) ?Q), s)›*)) (*top goal: ‹⋀P0 s xs zs P1 t xsa. ⟦(Some P0, s) # (Some P0, t) # xsa ∈ cptn_mod; map (lift P1) ((Some P0, t) # xsa) ∈ cptn⟧ ⟹ (Some (Seq P0 P1), s) # lift P1 (Some P0, t) # map (lift P1) xsa ∈ cptn› and 4 goals remain*) apply (rule CptnEnv (*‹(?P, ?t) # ?xs ∈ cptn ⟹ (?P, ?s) # (?P, ?t) # ?xs ∈ cptn›*)) (*top goal: ‹⋀(P0::'a com) (s::'a) (P1::'a com) (t::'a) xsa::('a com option × 'a) list. ⟦(Some P0, s) # (Some P0, t) # xsa ∈ cptn_mod; (Some (Seq P0 P1), t) # map (λ(P::'a com option, s::'a). if P = None then (Some P1, s) else (Some (Seq (the P) P1), s)) xsa ∈ cptn⟧ ⟹ (Some (Seq P0 P1), s) # (Some (Seq P0 P1), t) # map (λ(P::'a com option, s::'a). if P = None then (Some P1, s) else (Some (Seq (the P) P1), s)) xsa ∈ cptn› and 4 goals remain*) apply simp (*discuss goal 3*) apply simp (*top goal: ‹⋀P0 s xs zs P1 P sa Q t xsa. ⟦(Some P0, s) # xs ∈ cptn_mod; zs = map (lift P1) xs; (Some P0, s) # xs = (P, sa) # (Q, t) # xsa; (P, sa) -c→ (Q, t); (Q, t) # xsa ∈ cptn⟧ ⟹ (Some (Seq P0 P1), s) # zs ∈ cptn› and 3 goals remain*) apply clarify (*top goal: ‹⋀P0 s xs zs P1 Q t xsa. ⟦(Some P0, s) # (Q, t) # xsa ∈ cptn_mod; zs = lift P1 (Q, t) # map (lift P1) xsa; xs = (Q, t) # xsa; (Some P0, s) -c→ (Q, t); (Q, t) # xsa ∈ cptn⟧ ⟹ (Some (Seq P0 P1), s) # lift P1 (Q, t) # map (lift P1) xsa ∈ cptn› and 3 goals remain*) apply (simp add:lift_def (*‹lift ?Q ≡ λ(P, s). if P = None then (Some ?Q, s) else (Some (Seq (the P) ?Q), s)›*)) (*top goal: ‹⋀P0 s xs zs P1 Q t xsa. ⟦(Some P0, s) # (Q, t) # xsa ∈ cptn_mod; (Some P0, s) -c→ (Q, t); (Q, t) # xsa ∈ cptn⟧ ⟹ (Some (Seq P0 P1), s) # lift P1 (Q, t) # map (lift P1) xsa ∈ cptn› and 3 goals remain*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹⋀P0 s P1 Q t xsa. ⟦(Some P0, s) # (Q, t) # xsa ∈ cptn_mod; (Some P0, s) -c→ (Q, t); (Q, t) # xsa ∈ cptn⟧ ⟹ Q = None ⟶ (Some (Seq P0 P1), s) # (Some P1, t) # map (λ(P, s). if P = None then (Some P1, s) else (Some (Seq (the P) P1), s)) xsa ∈ cptn› 2. ‹⋀P0 s P1 Q t xsa. ⟦(Some P0, s) # (Q, t) # xsa ∈ cptn_mod; (Some P0, s) -c→ (Q, t); (Q, t) # xsa ∈ cptn⟧ ⟹ (∃y. Q = Some y) ⟶ (Some (Seq P0 P1), s) # (Some (Seq (the Q) P1), t) # map (λ(P, s). if P = None then (Some P1, s) else (Some (Seq (the P) P1), s)) xsa ∈ cptn› discuss goal 1*) apply clarify (*top goal: ‹⋀P0 s P1 Q t xsa. ⟦(Some P0, s) # (Q, t) # xsa ∈ cptn_mod; (Some P0, s) -c→ (Q, t); (Q, t) # xsa ∈ cptn⟧ ⟹ Q = None ⟶ (Some (Seq P0 P1), s) # (Some P1, t) # map (λ(P, s). if P = None then (Some P1, s) else (Some (Seq (the P) P1), s)) xsa ∈ cptn› and 4 goals remain*) apply (rule CptnComp (*‹⟦(?P, ?s) -c→ (?Q, ?t); (?Q, ?t) # ?xs ∈ cptn⟧ ⟹ (?P, ?s) # (?Q, ?t) # ?xs ∈ cptn›*)) (*goals: 1. ‹⋀P0 s P1 Q t xsa. ⟦(Some P0, s) # (None, t) # xsa ∈ cptn_mod; (Some P0, s) -c→ (None, t); (None, t) # xsa ∈ cptn⟧ ⟹ (Some (Seq P0 P1), s) -c→ (Some P1, t)› 2. ‹⋀P0 s P1 Q t xsa. ⟦(Some P0, s) # (None, t) # xsa ∈ cptn_mod; (Some P0, s) -c→ (None, t); (None, t) # xsa ∈ cptn⟧ ⟹ (Some P1, t) # map (λ(P, s). if P = None then (Some P1, s) else (Some (Seq (the P) P1), s)) xsa ∈ cptn› discuss goal 1*) apply (rule Seq1 (*‹(Some (?P0.0::?'a com), ?s::?'a) -c→ (None, ?t::?'a) ⟹ (Some (Seq ?P0.0 (?P1.0::?'a com)), ?s) -c→ (Some ?P1.0, ?t)›*)) (*top goal: ‹⋀P0 s P1 Q t xsa. ⟦(Some P0, s) # (None, t) # xsa ∈ cptn_mod; (Some P0, s) -c→ (None, t); (None, t) # xsa ∈ cptn⟧ ⟹ (Some (Seq P0 P1), s) -c→ (Some P1, t)› and 5 goals remain*) apply simp (*discuss goal 2*) apply (drule_tac P=P1 in lift_is_cptn (*‹?c ∈ cptn ⟹ map (lift ?P) ?c ∈ cptn›*)) (*top goal: ‹⋀P0 s P1 Q t xsa. ⟦(Some P0, s) # (None, t) # xsa ∈ cptn_mod; (Some P0, s) -c→ (None, t); (None, t) # xsa ∈ cptn⟧ ⟹ (Some P1, t) # map (λ(P, s). if P = None then (Some P1, s) else (Some (Seq (the P) P1), s)) xsa ∈ cptn› and 4 goals remain*) apply (simp add:lift_def (*‹lift (?Q::?'a com) ≡ λ(P::?'a com option, s::?'a). if P = None then (Some ?Q, s) else (Some (Seq (the P) ?Q), s)›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply clarify (*top goal: ‹⋀(P0::'a com) (s::'a) (P1::'a com) (Q::'a com option) (t::'a) xsa::('a com option × 'a) list. ⟦(Some P0, s) # (Q, t) # xsa ∈ cptn_mod; (Some P0, s) -c→ (Q, t); (Q, t) # xsa ∈ cptn⟧ ⟹ (∃y::'a com. Q = Some y) ⟶ (Some (Seq P0 P1), s) # (Some (Seq (the Q) P1), t) # map (λ(P::'a com option, s::'a). if P = None then (Some P1, s) else (Some (Seq (the P) P1), s)) xsa ∈ cptn› and 3 goals remain*) apply (rule CptnComp (*‹⟦(?P, ?s) -c→ (?Q, ?t); (?Q, ?t) # ?xs ∈ cptn⟧ ⟹ (?P, ?s) # (?Q, ?t) # ?xs ∈ cptn›*)) (*goals: 1. ‹⋀P0 s P1 Q t xsa y. ⟦(Some P0, s) # (Some y, t) # xsa ∈ cptn_mod; (Some P0, s) -c→ (Some y, t); (Some y, t) # xsa ∈ cptn⟧ ⟹ (Some (Seq P0 P1), s) -c→ (Some (Seq (the (Some y)) P1), t)› 2. ‹⋀P0 s P1 Q t xsa y. ⟦(Some P0, s) # (Some y, t) # xsa ∈ cptn_mod; (Some P0, s) -c→ (Some y, t); (Some y, t) # xsa ∈ cptn⟧ ⟹ (Some (Seq (the (Some y)) P1), t) # map (λ(P, s). if P = None then (Some P1, s) else (Some (Seq (the P) P1), s)) xsa ∈ cptn› discuss goal 1*) apply (rule Seq2 (*‹(Some ?P0.0, ?s) -c→ (Some ?P2.0, ?t) ⟹ (Some (Seq ?P0.0 ?P1.0), ?s) -c→ (Some (Seq ?P2.0 ?P1.0), ?t)›*)) (*top goal: ‹⋀P0 s P1 Q t xsa y. ⟦(Some P0, s) # (Some y, t) # xsa ∈ cptn_mod; (Some P0, s) -c→ (Some y, t); (Some y, t) # xsa ∈ cptn⟧ ⟹ (Some (Seq P0 P1), s) -c→ (Some (Seq (the (Some y)) P1), t)› and 4 goals remain*) apply simp (*discuss goal 2*) apply (drule_tac P=P1 in lift_is_cptn (*‹(?c::(?'a::type com option × ?'a::type) list) ∈ cptn ⟹ map (lift (?P::?'a::type com)) ?c ∈ cptn›*)) (*top goal: ‹⋀P0 s P1 Q t xsa y. ⟦(Some P0, s) # (Some y, t) # xsa ∈ cptn_mod; (Some P0, s) -c→ (Some y, t); (Some y, t) # xsa ∈ cptn⟧ ⟹ (Some (Seq (the (Some y)) P1), t) # map (λ(P, s). if P = None then (Some P1, s) else (Some (Seq (the P) P1), s)) xsa ∈ cptn› and 3 goals remain*) apply (simp add:lift_def (*‹lift ?Q ≡ λ(P, s). if P = None then (Some ?Q, s) else (Some (Seq (the P) ?Q), s)›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 3 subgoals*) (*discuss goal 7*) apply simp (*top goal: ‹⋀P0 s xs P1 ys zs. ⟦(Some P0, s) # xs ∈ cptn_mod; (Some P0, s) # xs ∈ cptn; fst (last ((Some P0, s) # xs)) = None; (Some P1, snd (last ((Some P0, s) # xs))) # ys ∈ cptn_mod; (Some P1, snd (last ((Some P0, s) # xs))) # ys ∈ cptn; zs = map (lift P1) xs @ ys⟧ ⟹ (Some (Seq P0 P1), s) # zs ∈ cptn› and 2 goals remain*) apply (rule cptn_append_is_cptn (*‹⟦?b # ?c1.0 ∈ cptn; ?a # ?c2.0 ∈ cptn; (?b # ?c1.0) ! length ?c1.0 = ?a⟧ ⟹ ?b # ?c1.0 @ ?c2.0 ∈ cptn›*)) (*goals: 1. ‹⋀P0 s xs P1 ys zs. ⟦(Some P0, s) # xs ∈ cptn_mod; (Some P0, s) # xs ∈ cptn; fst (if xs = [] then (Some P0, s) else last xs) = None; (Some P1, snd (if xs = [] then (Some P0, s) else last xs)) # ys ∈ cptn_mod; (Some P1, snd (if xs = [] then (Some P0, s) else last xs)) # ys ∈ cptn; zs = map (lift P1) xs @ ys⟧ ⟹ (Some (Seq P0 P1), s) # map (lift P1) xs ∈ cptn› 2. ‹⋀P0 s xs P1 ys zs. ⟦(Some P0, s) # xs ∈ cptn_mod; (Some P0, s) # xs ∈ cptn; fst (if xs = [] then (Some P0, s) else last xs) = None; (Some P1, snd (if xs = [] then (Some P0, s) else last xs)) # ys ∈ cptn_mod; (Some P1, snd (if xs = [] then (Some P0, s) else last xs)) # ys ∈ cptn; zs = map (lift P1) xs @ ys⟧ ⟹ ?a69 P0 s xs P1 ys zs # ys ∈ cptn› 3. ‹⋀P0 s xs P1 ys zs. ⟦(Some P0, s) # xs ∈ cptn_mod; (Some P0, s) # xs ∈ cptn; fst (if xs = [] then (Some P0, s) else last xs) = None; (Some P1, snd (if xs = [] then (Some P0, s) else last xs)) # ys ∈ cptn_mod; (Some P1, snd (if xs = [] then (Some P0, s) else last xs)) # ys ∈ cptn; zs = map (lift P1) xs @ ys⟧ ⟹ ((Some (Seq P0 P1), s) # map (lift P1) xs) ! length (map (lift P1) xs) = ?a69 P0 s xs P1 ys zs› discuss goal 1*) apply (drule_tac P=P1 in lift_is_cptn (*‹?c ∈ cptn ⟹ map (lift ?P) ?c ∈ cptn›*)) (*top goal: ‹⋀P0 s xs P1 ys zs. ⟦(Some P0, s) # xs ∈ cptn_mod; (Some P0, s) # xs ∈ cptn; fst (if xs = [] then (Some P0, s) else last xs) = None; (Some P1, snd (if xs = [] then (Some P0, s) else last xs)) # ys ∈ cptn_mod; (Some P1, snd (if xs = [] then (Some P0, s) else last xs)) # ys ∈ cptn; zs = map (lift P1) xs @ ys⟧ ⟹ (Some (Seq P0 P1), s) # map (lift P1) xs ∈ cptn› and 4 goals remain*) apply (simp add:lift_def (*‹lift (?Q::?'a::type com) ≡ λ(P::?'a::type com option, s::?'a::type). if P = None then (Some ?Q, s) else (Some (Seq (the P) ?Q), s)›*)) (*discuss goal 2*) apply simp (*discuss goal 3*) apply (simp split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) (*top goal: ‹⋀P0 s xs P1 ys zs. ⟦(Some P0, s) # xs ∈ cptn_mod; (Some P0, s) # xs ∈ cptn; fst (if xs = [] then (Some P0, s) else last xs) = None; (Some P1, snd (if xs = [] then (Some P0, s) else last xs)) # ys ∈ cptn_mod; (Some P1, snd (if xs = [] then (Some P0, s) else last xs)) # ys ∈ cptn; zs = map (lift P1) xs @ ys⟧ ⟹ ((Some (Seq P0 P1), s) # map (lift P1) xs) ! length (map (lift P1) xs) = (Some P1, snd (if xs = [] then (Some P0, s) else last xs))› and 2 goals remain*) apply (frule_tac P=P1 in last_lift (*‹⟦?xs ≠ []; fst (?xs ! (length ?xs - Suc 0)) = None⟧ ⟹ fst (map (lift ?P) ?xs ! (length (map (lift ?P) ?xs) - Suc 0)) = Some ?P›*)) (*goals: 1. ‹⋀P0 s xs P1 ys zs. ⟦(Some P1, snd (last xs)) # ys ∈ cptn_mod; (Some P1, snd (last xs)) # ys ∈ cptn; zs = map (lift P1) xs @ ys; (Some P0, s) # xs ∈ cptn_mod; (Some P0, s) # xs ∈ cptn; xs ≠ []; fst (last xs) = None⟧ ⟹ fst (xs ! (length xs - Suc 0)) = None› 2. ‹⋀P0 s xs P1 ys zs. ⟦(Some P1, snd (last xs)) # ys ∈ cptn_mod; (Some P1, snd (last xs)) # ys ∈ cptn; zs = map (lift P1) xs @ ys; (Some P0, s) # xs ∈ cptn_mod; (Some P0, s) # xs ∈ cptn; xs ≠ []; fst (last xs) = None; fst (map (lift P1) xs ! (length (map (lift P1) xs) - Suc 0)) = Some P1⟧ ⟹ lift P1 (xs ! (length xs - Suc 0)) = (Some P1, snd (last xs))› discuss goal 1*) apply (rule last_fst_esp (*‹fst (((Some ?a, ?s) # ?xs) ! length ?xs) = None ⟹ fst (?xs ! (length ?xs - Suc 0)) = None›*)) (*top goal: ‹⋀P0 s xs P1 ys zs. ⟦(Some P1, snd (last xs)) # ys ∈ cptn_mod; (Some P1, snd (last xs)) # ys ∈ cptn; zs = map (lift P1) xs @ ys; (Some P0, s) # xs ∈ cptn_mod; (Some P0, s) # xs ∈ cptn; xs ≠ []; fst (last xs) = None⟧ ⟹ fst (xs ! (length xs - Suc 0)) = None› and 3 goals remain*) apply (simp add:last_length (*‹(?a # ?xs) ! length ?xs = last (?a # ?xs)›*)) (*discuss goal 2*) apply (simp add:Cons_lift (*‹(Some (Seq ?P ?Q), ?s) # map (lift ?Q) ?xs = map (lift ?Q) ((Some ?P, ?s) # ?xs)›*) lift_def (*‹lift ?Q ≡ λ(P, s). if P = None then (Some ?Q, s) else (Some (Seq (the P) ?Q), s)›*) split_def (*‹case_prod = (λc p. c (fst p) (snd p))›*) last_conv_nth (*‹?xs ≠ [] ⟹ last ?xs = ?xs ! (length ?xs - 1)›*)) (*proven 2 subgoals*) (*proven 3 subgoals*) (*discuss goal 8*) apply simp (*top goal: ‹⋀P s xs b zs. ⟦(Some P, s) # xs ∈ cptn_mod; (Some P, s) # xs ∈ cptn; s ∈ b; zs = map (lift (While b P)) xs⟧ ⟹ (Some (While b P), s) # (Some (Seq P (While b P)), s) # zs ∈ cptn› and 1 goal remains*) apply (rule CptnComp (*‹⟦(?P, ?s) -c→ (?Q, ?t); (?Q, ?t) # ?xs ∈ cptn⟧ ⟹ (?P, ?s) # (?Q, ?t) # ?xs ∈ cptn›*)) (*goals: 1. ‹⋀P s xs b zs. ⟦(Some P, s) # xs ∈ cptn_mod; (Some P, s) # xs ∈ cptn; s ∈ b; zs = map (lift (While b P)) xs⟧ ⟹ (Some (While b P), s) -c→ (Some (Seq P (While b P)), s)› 2. ‹⋀P s xs b zs. ⟦(Some P, s) # xs ∈ cptn_mod; (Some P, s) # xs ∈ cptn; s ∈ b; zs = map (lift (While b P)) xs⟧ ⟹ (Some (Seq P (While b P)), s) # map (lift (While b P)) xs ∈ cptn› discuss goal 1*) apply (rule WhileT (*‹?s ∈ ?b ⟹ (Some (While ?b ?P), ?s) -c→ (Some (Seq ?P (While ?b ?P)), ?s)›*)) (*top goal: ‹⋀(P::'a com) (s::'a) (xs::('a com option × 'a) list) (b::'a set) zs::('a com option × 'a) list. ⟦(Some P, s) # xs ∈ cptn_mod; (Some P, s) # xs ∈ cptn; s ∈ b; zs = map (lift (While b P)) xs⟧ ⟹ (Some (While b P), s) -c→ (Some (Seq P (While b P)), s)› and 2 goals remain*) apply simp (*discuss goal 2*) apply (drule_tac P="While b P" in lift_is_cptn (*‹?c ∈ cptn ⟹ map (lift ?P) ?c ∈ cptn›*)) (*top goal: ‹⋀P s xs b zs. ⟦(Some P, s) # xs ∈ cptn_mod; (Some P, s) # xs ∈ cptn; s ∈ b; zs = map (lift (While b P)) xs⟧ ⟹ (Some (Seq P (While b P)), s) # map (lift (While b P)) xs ∈ cptn› and 1 goal remains*) apply (simp add:lift_def (*‹lift ?Q ≡ λ(P, s). if P = None then (Some ?Q, s) else (Some (Seq (the P) ?Q), s)›*)) (*proven 2 subgoals*) (*discuss goal 9*) apply simp (*goal: ‹⋀P s xs b zs ys. ⟦(Some P, s) # xs ∈ cptn_mod; (Some P, s) # xs ∈ cptn; fst (last ((Some P, s) # xs)) = None; s ∈ b; zs = map (lift (While b P)) xs @ ys; (Some (While b P), snd (last ((Some P, s) # xs))) # ys ∈ cptn_mod; (Some (While b P), snd (last ((Some P, s) # xs))) # ys ∈ cptn⟧ ⟹ (Some (While b P), s) # (Some (Seq P (While b P)), s) # zs ∈ cptn›*) apply (rule CptnComp (*‹⟦(?P, ?s) -c→ (?Q, ?t); (?Q, ?t) # ?xs ∈ cptn⟧ ⟹ (?P, ?s) # (?Q, ?t) # ?xs ∈ cptn›*)) (*goals: 1. ‹⋀P s xs b zs ys. ⟦(Some P, s) # xs ∈ cptn_mod; (Some P, s) # xs ∈ cptn; fst (if xs = [] then (Some P, s) else last xs) = None; s ∈ b; zs = map (lift (While b P)) xs @ ys; (Some (While b P), snd (if xs = [] then (Some P, s) else last xs)) # ys ∈ cptn_mod; (Some (While b P), snd (if xs = [] then (Some P, s) else last xs)) # ys ∈ cptn⟧ ⟹ (Some (While b P), s) -c→ (Some (Seq P (While b P)), s)› 2. ‹⋀P s xs b zs ys. ⟦(Some P, s) # xs ∈ cptn_mod; (Some P, s) # xs ∈ cptn; fst (if xs = [] then (Some P, s) else last xs) = None; s ∈ b; zs = map (lift (While b P)) xs @ ys; (Some (While b P), snd (if xs = [] then (Some P, s) else last xs)) # ys ∈ cptn_mod; (Some (While b P), snd (if xs = [] then (Some P, s) else last xs)) # ys ∈ cptn⟧ ⟹ (Some (Seq P (While b P)), s) # map (lift (While b P)) xs @ ys ∈ cptn› discuss goal 1*) apply (rule WhileT (*‹?s ∈ ?b ⟹ (Some (While ?b ?P), ?s) -c→ (Some (Seq ?P (While ?b ?P)), ?s)›*)) (*top goal: ‹⋀P s xs b zs ys. ⟦(Some P, s) # xs ∈ cptn_mod; (Some P, s) # xs ∈ cptn; fst (if xs = [] then (Some P, s) else last xs) = None; s ∈ b; zs = map (lift (While b P)) xs @ ys; (Some (While b P), snd (if xs = [] then (Some P, s) else last xs)) # ys ∈ cptn_mod; (Some (While b P), snd (if xs = [] then (Some P, s) else last xs)) # ys ∈ cptn⟧ ⟹ (Some (While b P), s) -c→ (Some (Seq P (While b P)), s)› and 1 goal remains*) apply simp (*discuss goal 2*) apply (rule cptn_append_is_cptn (*‹⟦(?b::?'a::type com option × ?'a::type) # (?c1.0::(?'a::type com option × ?'a::type) list) ∈ cptn; (?a::?'a::type com option × ?'a::type) # (?c2.0::(?'a::type com option × ?'a::type) list) ∈ cptn; (?b # ?c1.0) ! length ?c1.0 = ?a⟧ ⟹ ?b # ?c1.0 @ ?c2.0 ∈ cptn›*)) (*goals: 1. ‹⋀P s xs b zs ys. ⟦(Some P, s) # xs ∈ cptn_mod; (Some P, s) # xs ∈ cptn; fst (if xs = [] then (Some P, s) else last xs) = None; s ∈ b; zs = map (lift (While b P)) xs @ ys; (Some (While b P), snd (if xs = [] then (Some P, s) else last xs)) # ys ∈ cptn_mod; (Some (While b P), snd (if xs = [] then (Some P, s) else last xs)) # ys ∈ cptn⟧ ⟹ (Some (Seq P (While b P)), s) # map (lift (While b P)) xs ∈ cptn› 2. ‹⋀P s xs b zs ys. ⟦(Some P, s) # xs ∈ cptn_mod; (Some P, s) # xs ∈ cptn; fst (if xs = [] then (Some P, s) else last xs) = None; s ∈ b; zs = map (lift (While b P)) xs @ ys; (Some (While b P), snd (if xs = [] then (Some P, s) else last xs)) # ys ∈ cptn_mod; (Some (While b P), snd (if xs = [] then (Some P, s) else last xs)) # ys ∈ cptn⟧ ⟹ ?a107 P s xs b zs ys # ys ∈ cptn› 3. ‹⋀P s xs b zs ys. ⟦(Some P, s) # xs ∈ cptn_mod; (Some P, s) # xs ∈ cptn; fst (if xs = [] then (Some P, s) else last xs) = None; s ∈ b; zs = map (lift (While b P)) xs @ ys; (Some (While b P), snd (if xs = [] then (Some P, s) else last xs)) # ys ∈ cptn_mod; (Some (While b P), snd (if xs = [] then (Some P, s) else last xs)) # ys ∈ cptn⟧ ⟹ ((Some (Seq P (While b P)), s) # map (lift (While b P)) xs) ! length (map (lift (While b P)) xs) = ?a107 P s xs b zs ys› discuss goal 1*) apply (drule_tac P="While b P" in lift_is_cptn (*‹?c ∈ cptn ⟹ map (lift ?P) ?c ∈ cptn›*)) (*top goal: ‹⋀(P::'a com) (s::'a) (xs::('a com option × 'a) list) (b::'a set) (zs::('a com option × 'a) list) ys::('a com option × 'a) list. ⟦(Some P, s) # xs ∈ cptn_mod; (Some P, s) # xs ∈ cptn; fst (if xs = [] then (Some P, s) else last xs) = None; s ∈ b; zs = map (lift (While b P)) xs @ ys; (Some (While b P), snd (if xs = [] then (Some P, s) else last xs)) # ys ∈ cptn_mod; (Some (While b P), snd (if xs = [] then (Some P, s) else last xs)) # ys ∈ cptn⟧ ⟹ (Some (Seq P (While b P)), s) # map (lift (While b P)) xs ∈ cptn› and 2 goals remain*) apply (simp add:lift_def (*‹lift ?Q ≡ λ(P, s). if P = None then (Some ?Q, s) else (Some (Seq (the P) ?Q), s)›*)) (*discuss goal 2*) apply simp (*discuss goal 3*) apply (simp split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) (*goal: ‹⋀P s xs b zs ys. ⟦(Some P, s) # xs ∈ cptn_mod; (Some P, s) # xs ∈ cptn; fst (if xs = [] then (Some P, s) else last xs) = None; s ∈ b; zs = map (lift (While b P)) xs @ ys; (Some (While b P), snd (if xs = [] then (Some P, s) else last xs)) # ys ∈ cptn_mod; (Some (While b P), snd (if xs = [] then (Some P, s) else last xs)) # ys ∈ cptn⟧ ⟹ ((Some (Seq P (While b P)), s) # map (lift (While b P)) xs) ! length (map (lift (While b P)) xs) = (Some (While b P), snd (if xs = [] then (Some P, s) else last xs))›*) apply (frule_tac P="While b P" in last_lift (*‹⟦?xs ≠ []; fst (?xs ! (length ?xs - Suc 0)) = None⟧ ⟹ fst (map (lift ?P) ?xs ! (length (map (lift ?P) ?xs) - Suc 0)) = Some ?P›*)) (*goals: 1. ‹⋀P s xs b zs ys. ⟦s ∈ b; zs = map (lift (While b P)) xs @ ys; (Some (While b P), snd (last xs)) # ys ∈ cptn_mod; (Some (While b P), snd (last xs)) # ys ∈ cptn; (Some P, s) # xs ∈ cptn_mod; (Some P, s) # xs ∈ cptn; xs ≠ []; fst (last xs) = None⟧ ⟹ fst (xs ! (length xs - Suc 0)) = None› 2. ‹⋀P s xs b zs ys. ⟦s ∈ b; zs = map (lift (While b P)) xs @ ys; (Some (While b P), snd (last xs)) # ys ∈ cptn_mod; (Some (While b P), snd (last xs)) # ys ∈ cptn; (Some P, s) # xs ∈ cptn_mod; (Some P, s) # xs ∈ cptn; xs ≠ []; fst (last xs) = None; fst (map (lift (While b P)) xs ! (length (map (lift (While b P)) xs) - Suc 0)) = Some (While b P)⟧ ⟹ lift (While b P) (xs ! (length xs - Suc 0)) = (Some (While b P), snd (last xs))› discuss goal 1*) apply (rule last_fst_esp (*‹fst (((Some ?a, ?s) # ?xs) ! length ?xs) = None ⟹ fst (?xs ! (length ?xs - Suc 0)) = None›*)) (*top goal: ‹⋀P s xs b zs ys. ⟦s ∈ b; zs = map (lift (While b P)) xs @ ys; (Some (While b P), snd (last xs)) # ys ∈ cptn_mod; (Some (While b P), snd (last xs)) # ys ∈ cptn; (Some P, s) # xs ∈ cptn_mod; (Some P, s) # xs ∈ cptn; xs ≠ []; fst (last xs) = None⟧ ⟹ fst (xs ! (length xs - Suc 0)) = None› and 1 goal remains*) apply (simp add:last_length (*‹((?a::?'a) # (?xs::?'a list)) ! length ?xs = last (?a # ?xs)›*)) (*discuss goal 2*) apply (simp add:Cons_lift (*‹(Some (Seq (?P::?'a::type com) (?Q::?'a::type com)), ?s::?'a::type) # map (lift ?Q) (?xs::(?'a::type com option × ?'a::type) list) = map (lift ?Q) ((Some ?P, ?s) # ?xs)›*) lift_def (*‹lift (?Q::?'a::type com) ≡ λ(P::?'a::type com option, s::?'a::type). if P = None then (Some ?Q, s) else (Some (Seq (the P) ?Q), s)›*) split_def (*‹case_prod = (λ(c::?'a::type ⇒ ?'b::type ⇒ ?'c::type) p::?'a::type × ?'b::type. c (fst p) (snd p))›*) last_conv_nth (*‹(?xs::?'a::type list) ≠ [] ⟹ last ?xs = ?xs ! (length ?xs - (1::nat))›*)) (*proven 2 subgoals*) (*proven 3 subgoals*) (*proven 2 subgoals*) (*proven 9 subgoals*) . theorem cptn_iff_cptn_mod: "(c ∈ cptn) = (c ∈ cptn_mod)" apply (rule iffI (*‹⟦?P::bool ⟹ ?Q::bool; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*)) (*goals: 1. ‹(c::('a::type com option × 'a::type) list) ∈ cptn ⟹ c ∈ cptn_mod› 2. ‹(c::('a::type com option × 'a::type) list) ∈ cptn_mod ⟹ c ∈ cptn› discuss goal 1*) apply (erule cptn_onlyif_cptn_mod (*‹(?c::(?'a com option × ?'a) list) ∈ cptn ⟹ ?c ∈ cptn_mod›*)) (*discuss goal 2*) apply (erule cptn_if_cptn_mod (*‹?c ∈ cptn_mod ⟹ ?c ∈ cptn›*)) (*proven 2 subgoals*) . section ‹Validity of Correctness Formulas› subsection ‹Validity for Component Programs.› type_synonym 'a rgformula = "'a com × 'a set × ('a × 'a) set × ('a × 'a) set × 'a set" definition assum :: "('a set × ('a × 'a) set) ⇒ ('a confs) set" where "assum ≡ λ(pre, rely). {c. snd(c!0) ∈ pre ∧ (∀i. Suc i<length c ⟶ c!i -e→ c!(Suc i) ⟶ (snd(c!i), snd(c!Suc i)) ∈ rely)}" definition comm :: "(('a × 'a) set × 'a set) ⇒ ('a confs) set" where "comm ≡ λ(guar, post). {c. (∀i. Suc i<length c ⟶ c!i -c→ c!(Suc i) ⟶ (snd(c!i), snd(c!Suc i)) ∈ guar) ∧ (fst (last c) = None ⟶ snd (last c) ∈ post)}" definition com_validity :: "'a com ⇒ 'a set ⇒ ('a × 'a) set ⇒ ('a × 'a) set ⇒ 'a set ⇒ bool" ("⊨ _ sat [_, _, _, _]" [60,0,0,0,0] 45) where "⊨ P sat [pre, rely, guar, post] ≡ ∀s. cp (Some P) s ∩ assum(pre, rely) ⊆ comm(guar, post)" subsection ‹Validity for Parallel Programs.› definition All_None :: "(('a com) option) list ⇒ bool" where "All_None xs ≡ ∀c∈set xs. c=None" definition par_assum :: "('a set × ('a × 'a) set) ⇒ ('a par_confs) set" where "par_assum ≡ λ(pre, rely). {c. snd(c!0) ∈ pre ∧ (∀i. Suc i<length c ⟶ c!i -pe→ c!Suc i ⟶ (snd(c!i), snd(c!Suc i)) ∈ rely)}" definition par_comm :: "(('a × 'a) set × 'a set) ⇒ ('a par_confs) set" where "par_comm ≡ λ(guar, post). {c. (∀i. Suc i<length c ⟶ c!i -pc→ c!Suc i ⟶ (snd(c!i), snd(c!Suc i)) ∈ guar) ∧ (All_None (fst (last c)) ⟶ snd( last c) ∈ post)}" definition par_com_validity :: "'a par_com ⇒ 'a set ⇒ ('a × 'a) set ⇒ ('a × 'a) set ⇒ 'a set ⇒ bool" ("⊨ _ SAT [_, _, _, _]" [60,0,0,0,0] 45) where "⊨ Ps SAT [pre, rely, guar, post] ≡ ∀s. par_cp Ps s ∩ par_assum(pre, rely) ⊆ par_comm(guar, post)" subsection ‹Compositionality of the Semantics› subsubsection ‹Definition of the conjoin operator› definition same_length :: "'a par_confs ⇒ ('a confs) list ⇒ bool" where "same_length c clist ≡ (∀i<length clist. length(clist!i)=length c)" definition same_state :: "'a par_confs ⇒ ('a confs) list ⇒ bool" where "same_state c clist ≡ (∀i <length clist. ∀j<length c. snd(c!j) = snd((clist!i)!j))" definition same_program :: "'a par_confs ⇒ ('a confs) list ⇒ bool" where "same_program c clist ≡ (∀j<length c. fst(c!j) = map (λx. fst(nth x j)) clist)" definition compat_label :: "'a par_confs ⇒ ('a confs) list ⇒ bool" where "compat_label c clist ≡ (∀j. Suc j<length c ⟶ (c!j -pc→ c!Suc j ∧ (∃i<length clist. (clist!i)!j -c→ (clist!i)! Suc j ∧ (∀l<length clist. l≠i ⟶ (clist!l)!j -e→ (clist!l)! Suc j))) ∨ (c!j -pe→ c!Suc j ∧ (∀i<length clist. (clist!i)!j -e→ (clist!i)! Suc j)))" definition conjoin :: "'a par_confs ⇒ ('a confs) list ⇒ bool" ("_ ∝ _" [65,65] 64) where "c ∝ clist ≡ (same_length c clist) ∧ (same_state c clist) ∧ (same_program c clist) ∧ (compat_label c clist)" subsubsection ‹Some previous lemmas› lemma list_eq_if [rule_format]: "∀ys. xs=ys ⟶ (length xs = length ys) ⟶ (∀i<length xs. xs!i=ys!i)" apply (induct xs) (*goals: 1. ‹∀ys. [] = ys ⟶ length [] = length ys ⟶ (∀i<length []. [] ! i = ys ! i)› 2. ‹⋀a xs. ∀ys. xs = ys ⟶ length xs = length ys ⟶ (∀i<length xs. xs ! i = ys ! i) ⟹ ∀ys. a # xs = ys ⟶ length (a # xs) = length ys ⟶ (∀i<length (a # xs). (a # xs) ! i = ys ! i)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma list_eq: "(length xs = length ys ∧ (∀i<length xs. xs!i=ys!i)) = (xs=ys)" apply (rule iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*)) (*goals: 1. ‹length xs = length ys ∧ (∀i<length xs. xs ! i = ys ! i) ⟹ xs = ys› 2. ‹xs = ys ⟹ length xs = length ys ∧ (∀i<length xs. xs ! i = ys ! i)› discuss goal 1*) apply clarify (*top goal: ‹length (xs::'a list) = length (ys::'a list) ∧ (∀i<length xs. xs ! i = ys ! i) ⟹ xs = ys› and 1 goal remains*) apply (erule nth_equalityI (*‹⟦length (?xs::?'a::type list) = length (?ys::?'a::type list); ⋀i::nat. i < length ?xs ⟹ ?xs ! i = ?ys ! i⟧ ⟹ ?xs = ?ys›*)) (*top goal: ‹⟦length xs = length ys; ∀i<length xs. xs ! i = ys ! i⟧ ⟹ xs = ys› and 1 goal remains*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma nth_tl: "⟦ ys!0=a; ys≠[] ⟧ ⟹ ys=(a#(tl ys))" apply (cases ys) (*goals: 1. ‹⟦ys ! 0 = a; ys ≠ []; ys = []⟧ ⟹ ys = a # tl ys› 2. ‹⋀aa list. ⟦ys ! 0 = a; ys ≠ []; ys = aa # list⟧ ⟹ ys = a # tl ys› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma nth_tl_if [rule_format]: "ys≠[] ⟶ ys!0=a ⟶ P ys ⟶ P (a#(tl ys))" apply (induct ys) (*goals: 1. ‹[] ≠ [] ⟶ [] ! (0::nat) = (a::'a::type) ⟶ (P::'a::type list ⇒ bool) [] ⟶ P (a # tl [])› 2. ‹⋀(aa::'a::type) ys::'a::type list. ys ≠ [] ⟶ ys ! (0::nat) = (a::'a::type) ⟶ (P::'a::type list ⇒ bool) ys ⟶ P (a # tl ys) ⟹ aa # ys ≠ [] ⟶ (aa # ys) ! (0::nat) = a ⟶ P (aa # ys) ⟶ P (a # tl (aa # ys))› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma nth_tl_onlyif [rule_format]: "ys≠[] ⟶ ys!0=a ⟶ P (a#(tl ys)) ⟶ P ys" apply (induct ys) (*goals: 1. ‹[] ≠ [] ⟶ [] ! 0 = a ⟶ P (a # tl []) ⟶ P []› 2. ‹⋀aa ys. ys ≠ [] ⟶ ys ! 0 = a ⟶ P (a # tl ys) ⟶ P ys ⟹ aa # ys ≠ [] ⟶ (aa # ys) ! 0 = a ⟶ P (a # tl (aa # ys)) ⟶ P (aa # ys)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . lemma seq_not_eq1: "Seq c1 c2≠c1" apply (induct c1) (*goals: 1. ‹⋀x::'a::type ⇒ 'a::type. Seq (Basic x) (c2::'a::type com) ≠ Basic x› 2. ‹⋀(c11::'a::type com) c12::'a::type com. ⟦Seq c11 (c2::'a::type com) ≠ c11; Seq c12 c2 ≠ c12⟧ ⟹ Seq (Seq c11 c12) c2 ≠ Seq c11 c12› 3. ‹⋀(x1a::'a::type set) (c11::'a::type com) c12::'a::type com. ⟦Seq c11 (c2::'a::type com) ≠ c11; Seq c12 c2 ≠ c12⟧ ⟹ Seq (Cond x1a c11 c12) c2 ≠ Cond x1a c11 c12› 4. ‹⋀(x1a::'a::type set) c1::'a::type com. Seq c1 (c2::'a::type com) ≠ c1 ⟹ Seq (While x1a c1) c2 ≠ While x1a c1› 5. ‹⋀(x1a::'a::type set) c1::'a::type com. Seq c1 (c2::'a::type com) ≠ c1 ⟹ Seq (Await x1a c1) c2 ≠ Await x1a c1› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . lemma seq_not_eq2: "Seq c1 c2≠c2" apply (induct c2) (*goals: 1. ‹⋀x. Seq c1 (Basic x) ≠ Basic x› 2. ‹⋀c21 c22. ⟦Seq c1 c21 ≠ c21; Seq c1 c22 ≠ c22⟧ ⟹ Seq c1 (Seq c21 c22) ≠ Seq c21 c22› 3. ‹⋀x1a c21 c22. ⟦Seq c1 c21 ≠ c21; Seq c1 c22 ≠ c22⟧ ⟹ Seq c1 (Cond x1a c21 c22) ≠ Cond x1a c21 c22› 4. ‹⋀x1a c2. Seq c1 c2 ≠ c2 ⟹ Seq c1 (While x1a c2) ≠ While x1a c2› 5. ‹⋀x1a c2. Seq c1 c2 ≠ c2 ⟹ Seq c1 (Await x1a c2) ≠ Await x1a c2› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . lemma if_not_eq1: "Cond b c1 c2 ≠c1" apply (induct c1) (*goals: 1. ‹⋀x. Cond b (Basic x) c2 ≠ Basic x› 2. ‹⋀c11 c12. ⟦Cond b c11 c2 ≠ c11; Cond b c12 c2 ≠ c12⟧ ⟹ Cond b (Seq c11 c12) c2 ≠ Seq c11 c12› 3. ‹⋀x1a c11 c12. ⟦Cond b c11 c2 ≠ c11; Cond b c12 c2 ≠ c12⟧ ⟹ Cond b (Cond x1a c11 c12) c2 ≠ Cond x1a c11 c12› 4. ‹⋀x1a c1. Cond b c1 c2 ≠ c1 ⟹ Cond b (While x1a c1) c2 ≠ While x1a c1› 5. ‹⋀x1a c1. Cond b c1 c2 ≠ c1 ⟹ Cond b (Await x1a c1) c2 ≠ Await x1a c1› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . lemma if_not_eq2: "Cond b c1 c2≠c2" apply (induct c2) (*goals: 1. ‹⋀x. Cond b c1 (Basic x) ≠ Basic x› 2. ‹⋀c21 c22. ⟦Cond b c1 c21 ≠ c21; Cond b c1 c22 ≠ c22⟧ ⟹ Cond b c1 (Seq c21 c22) ≠ Seq c21 c22› 3. ‹⋀x1a c21 c22. ⟦Cond b c1 c21 ≠ c21; Cond b c1 c22 ≠ c22⟧ ⟹ Cond b c1 (Cond x1a c21 c22) ≠ Cond x1a c21 c22› 4. ‹⋀x1a c2. Cond b c1 c2 ≠ c2 ⟹ Cond b c1 (While x1a c2) ≠ While x1a c2› 5. ‹⋀x1a c2. Cond b c1 c2 ≠ c2 ⟹ Cond b c1 (Await x1a c2) ≠ Await x1a c2› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . lemmas seq_and_if_not_eq [simp] = seq_not_eq1 seq_not_eq2 seq_not_eq1 [THEN not_sym] seq_not_eq2 [THEN not_sym] if_not_eq1 if_not_eq2 if_not_eq1 [THEN not_sym] if_not_eq2 [THEN not_sym] lemma prog_not_eq_in_ctran_aux: assumes c: "(P,s) -c→ (Q,t)" shows "P≠Q" using c (*‹(P::'a::type com option, s::'a::type) -c→ (Q::'a::type com option, t::'a::type)›*) apply (induct x1 ≡ "(P,s)" x2 ≡ "(Q,t)" arbitrary: P s Q t) (*goals: 1. ‹⋀f s. Some (Basic f) ≠ None› 2. ‹⋀P0 s t P1. ⟦(Some P0, s) -c→ (None, t); Some P0 ≠ None⟧ ⟹ Some (Seq P0 P1) ≠ Some P1› 3. ‹⋀P0 s P2 t P1. ⟦(Some P0, s) -c→ (Some P2, t); Some P0 ≠ Some P2⟧ ⟹ Some (Seq P0 P1) ≠ Some (Seq P2 P1)› 4. ‹⋀s b P1 P2. s ∈ b ⟹ Some (Cond b P1 P2) ≠ Some P1› 5. ‹⋀s b P1 P2. s ∉ b ⟹ Some (Cond b P1 P2) ≠ Some P2› 6. ‹⋀s b P. s ∉ b ⟹ Some (While b P) ≠ None› 7. ‹⋀s b P. s ∈ b ⟹ Some (While b P) ≠ Some (Seq P (While b P))› 8. ‹⋀s b P t. ⟦s ∈ b; ((Some P, s), None, t) ∈ (ctran ∩ {(b, a). ∀x xa. b = (x, xa) ⟶ (∀xa xb. a = (xa, xb) ⟶ x ≠ xa)})⇧*⟧ ⟹ Some (Await b P) ≠ None› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*proven 8 subgoals*) . lemma prog_not_eq_in_ctran [simp]: "¬ (P,s) -c→ (P,t)" apply clarify (*goal: ‹((P, s), P, t) ∉ ctran›*) apply (drule prog_not_eq_in_ctran_aux (*‹(?P::?'a com option, ?s::?'a) -c→ (?Q::?'a com option, ?t::?'a) ⟹ ?P ≠ ?Q›*)) (*goal: ‹(P, s) -c→ (P, t) ⟹ False›*) by simp lemma prog_not_eq_in_par_ctran_aux [rule_format]: "(P,s) -pc→ (Q,t) ⟹ (P≠Q)" apply (erule par_ctran.induct (*‹⟦(?x1.0, ?x2.0) -pc→ (?x3.0, ?x4.0); ⋀i Ps s r t. ⟦i < length Ps; (Ps ! i, s) -c→ (r, t)⟧ ⟹ ?P Ps s (Ps[i := r]) t⟧ ⟹ ?P ?x1.0 ?x2.0 ?x3.0 ?x4.0›*)) (*goal: ‹(P, s) -pc→ (Q, t) ⟹ P ≠ Q›*) apply (drule prog_not_eq_in_ctran_aux (*‹(?P, ?s) -c→ (?Q, ?t) ⟹ ?P ≠ ?Q›*)) (*goal: ‹⋀i Ps s r t. ⟦i < length Ps; (Ps ! i, s) -c→ (r, t)⟧ ⟹ Ps ≠ Ps[i := r]›*) apply clarify (*goal: ‹⋀(i::nat) (Ps::'a com option list) (s::'a) (r::'a com option) t::'a. ⟦i < length Ps; Ps ! i ≠ r⟧ ⟹ Ps ≠ Ps[i := r]›*) apply (drule list_eq_if (*‹⟦?xs = ?ys; length ?xs = length ?ys; ?i < length ?xs⟧ ⟹ ?xs ! ?i = ?ys ! ?i›*)) (*goals: 1. ‹⋀i Ps s r t. ⟦i < length Ps; Ps ! i ≠ r⟧ ⟹ length Ps = length (Ps[i := r])› 2. ‹⋀i Ps s r t. ⟦i < length Ps; Ps ! i ≠ r⟧ ⟹ ?i5 i Ps s r t < length Ps› 3. ‹⋀i Ps s r t. ⟦i < length Ps; Ps ! i ≠ r; Ps ! ?i5 i Ps s r t = Ps[i := r] ! ?i5 i Ps s r t⟧ ⟹ False› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply force (*proven 3 subgoals*) . lemma prog_not_eq_in_par_ctran [simp]: "¬ (P,s) -pc→ (P,t)" apply clarify (*goal: ‹((P::'a com option list, s::'a), P, t::'a) ∉ par_ctran›*) apply (drule prog_not_eq_in_par_ctran_aux (*‹(?P::?'a::type com option list, ?s::?'a::type) -pc→ (?Q::?'a::type com option list, ?t::?'a::type) ⟹ ?P ≠ ?Q›*)) (*goal: ‹(P, s) -pc→ (P, t) ⟹ False›*) by simp lemma tl_in_cptn: "⟦ a#xs ∈cptn; xs≠[] ⟧ ⟹ xs∈cptn" by (force elim: cptn.cases (*‹⟦?a ∈ cptn; ⋀P s. ?a = [(P, s)] ⟹ ?P; ⋀P t xs s. ⟦?a = (P, s) # (P, t) # xs; (P, t) # xs ∈ cptn⟧ ⟹ ?P; ⋀P s Q t xs. ⟦?a = (P, s) # (Q, t) # xs; (P, s) -c→ (Q, t); (Q, t) # xs ∈ cptn⟧ ⟹ ?P⟧ ⟹ ?P›*)) lemma tl_zero[rule_format]: "P (ys!Suc j) ⟶ Suc j<length ys ⟶ ys≠[] ⟶ P (tl(ys)!j)" apply (induct ys) (*goals: 1. ‹P ([] ! Suc j) ⟶ Suc j < length [] ⟶ [] ≠ [] ⟶ P (tl [] ! j)› 2. ‹⋀a ys. P (ys ! Suc j) ⟶ Suc j < length ys ⟶ ys ≠ [] ⟶ P (tl ys ! j) ⟹ P ((a # ys) ! Suc j) ⟶ Suc j < length (a # ys) ⟶ a # ys ≠ [] ⟶ P (tl (a # ys) ! j)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . subsection ‹The Semantics is Compositional› lemma aux_if [rule_format]: "∀xs s clist. (length clist = length xs ∧ (∀i<length xs. (xs!i,s)#clist!i ∈ cptn) ∧ ((xs, s)#ys ∝ map (λi. (fst i,s)#snd i) (zip xs clist)) ⟶ (xs, s)#ys ∈ par_cptn)" apply (induct ys) (*goal: ‹∀xs s clist. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ⟶ (xs, s) # ys ∈ par_cptn›*) apply clarify (*top goal: ‹∀(xs::'a com option list) (s::'a) clist::('a com option × 'a) list list. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ [(xs, s)] ∝ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ⟶ [(xs, s)] ∈ par_cptn› and 1 goal remains*) apply (rule ParCptnOne (*‹[(?P, ?s)] ∈ par_cptn›*)) (*top goal: ‹⋀xs s clist. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; [(xs, s)] ∝ map (λi. (fst i, s) # snd i) (zip xs clist)⟧ ⟹ [(xs, s)] ∈ par_cptn› and 1 goal remains*) apply clarify (*goal: ‹⋀a ys. ∀xs s clist. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ⟶ (xs, s) # ys ∈ par_cptn ⟹ ∀xs s clist. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ (xs, s) # a # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ⟶ (xs, s) # a # ys ∈ par_cptn›*) apply (simp add:conjoin_def (*‹?c ∝ ?clist ≡ same_length ?c ?clist ∧ same_state ?c ?clist ∧ same_program ?c ?clist ∧ compat_label ?c ?clist›*) compat_label_def (*‹compat_label ?c ?clist ≡ ∀j. Suc j < length ?c ⟶ ?c ! j -pc→ ?c ! Suc j ∧ (∃i<length ?clist. ?clist ! i ! j -c→ ?clist ! i ! Suc j ∧ (∀l<length ?clist. l ≠ i ⟶ ?clist ! l ! j -e→ ?clist ! l ! Suc j)) ∨ ?c ! j -pe→ ?c ! Suc j ∧ (∀i<length ?clist. ?clist ! i ! j -e→ ?clist ! i ! Suc j)›*)) (*goal: ‹⋀a b ys xs s clist. ⟦∀xs s clist. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; (xs, s) # (a, b) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist)⟧ ⟹ (xs, s) # (a, b) # ys ∈ par_cptn›*) apply clarify (*goal: ‹⋀a b ys xs s clist. ⟦∀xs s. (∃clist. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_program ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_program ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<Suc (length ys). ((xs, s) # (a, b) # ys) ! j -pc→ ((a, b) # ys) ! j ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # (a, b) # ys) ! j -pe→ ((a, b) # ys) ! j ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))⟧ ⟹ (xs, s) # (a, b) # ys ∈ par_cptn›*) apply (erule_tac x="0" and P="λj. H j ⟶ (P j ∨ Q j)" for H P Q in all_dupE (*‹⟦∀x. ?P x; ⟦?P ?x; ∀x. ?P x⟧ ⟹ ?R⟧ ⟹ ?R›*), simp) (*goal: ‹⋀(a::'a com option list) (b::'a) (ys::('a com option list × 'a) list) (xs::'a com option list) (s::'a) clist::('a com option × 'a) list list. ⟦∀(xs::'a com option list) s::'a. (∃clist::('a com option × 'a) list list. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)) ∧ same_program ((xs, s) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l::nat. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i::nat. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (a, b) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (a, b) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (a, b) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); ∀j<Suc (length ys). ((xs, s) # (a, b) # ys) ! j -pc→ ((a, b) # ys) ! j ∧ (∃i<length xs. map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # (a, b) # ys) ! j -pe→ ((a, b) # ys) ! j ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j)⟧ ⟹ (xs, s) # (a, b) # ys ∈ par_cptn›*) apply (erule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goal: ‹⋀a b ys xs s clist. ⟦∀xs s. (∃clist. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_program ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (a, b) ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! 0 -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc 0 ∧ (∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0)) ∨ (xs, s) -pe→ (a, b) ∧ (∀i<length xs. (xs ! i, s) -e→ clist ! i ! 0); ∀x<Suc (length ys). ((xs, s) # (a, b) # ys) ! x -pc→ ((a, b) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (a, b) # ys) ! x -pe→ ((a, b) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x)⟧ ⟹ (xs, s) # (a, b) # ys ∈ par_cptn›*) apply clarify (*top goal: ‹⋀a b ys xs s clist. ⟦∀xs s. (∃clist. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_program ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (a, b) # ys) ! x -pc→ ((a, b) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (a, b) # ys) ! x -pe→ ((a, b) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (a, b) ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! 0 -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc 0 ∧ (∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0))⟧ ⟹ (xs, s) # (a, b) # ys ∈ par_cptn› and 1 goal remains*) apply simp (*top goal: ‹⋀a b ys xs s clist i. ⟦∀xs s. (∃clist. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_program ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (a, b) # ys) ! x -pc→ ((a, b) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (a, b) # ys) ! x -pe→ ((a, b) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (a, b); i < length xs; map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! 0 -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0⟧ ⟹ (xs, s) # (a, b) # ys ∈ par_cptn› and 1 goal remains*) apply (subgoal_tac "a=(xs[i:=(fst(clist!i!0))])") (*top goal: ‹⋀(a::'a com option list) (b::'a) (ys::('a com option list × 'a) list) (xs::'a com option list) (s::'a) (clist::('a com option × 'a) list list) i::nat. ⟦∀(xs::'a com option list) s::'a. (∃clist::('a com option × 'a) list list. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)) ∧ same_program ((xs, s) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l::nat. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i::nat. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (a, b) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (a, b) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (a, b) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (a, b) # ys) ! x -pc→ ((a, b) # ys) ! x ∧ (∃i<length xs. map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (a, b) # ys) ! x -pe→ ((a, b) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (a, b); i < length xs; (xs ! i, s) -c→ clist ! i ! (0::nat); ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! (0::nat)⟧ ⟹ (xs, s) # (a, b) # ys ∈ par_cptn› and 1 goal remains*) apply (subgoal_tac "b=snd(clist!i!0)", simp) (*top goal: ‹⋀a b ys xs s clist i. ⟦∀xs s. (∃clist. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_program ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (a, b) # ys) ! x -pc→ ((a, b) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (a, b) # ys) ! x -pe→ ((a, b) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (a, b); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; a = xs[i := fst (clist ! i ! 0)]⟧ ⟹ (xs, s) # (a, b) # ys ∈ par_cptn› and 2 goals remain*) prefer 2 (*top goal: ‹⋀a b ys xs s clist i. ⟦∀xs s. (∃clist. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_program ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (a, b) # ys) ! x -pc→ ((a, b) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (a, b) # ys) ! x -pe→ ((a, b) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (a, b); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; a = xs[i := fst (clist ! i ! 0)]⟧ ⟹ b = snd (clist ! i ! 0)› and 3 goals remain*) apply (simp add: same_state_def (*‹same_state ?c ?clist ≡ ∀i<length ?clist. ∀j<length ?c. snd (?c ! j) = snd (?clist ! i ! j)›*)) (*top goal: ‹⋀(a::'a com option list) (b::'a) (ys::('a com option list × 'a) list) (xs::'a com option list) (s::'a) (clist::('a com option × 'a) list list) i::nat. ⟦∀(xs::'a com option list) s::'a. (∃clist::('a com option × 'a) list list. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)) ∧ same_program ((xs, s) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l::nat. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i::nat. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (a, b) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (a, b) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (a, b) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (a, b) # ys) ! x -pc→ ((a, b) # ys) ! x ∧ (∃i<length xs. map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (a, b) # ys) ! x -pe→ ((a, b) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (a, b); i < length xs; (xs ! i, s) -c→ clist ! i ! (0::nat); ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! (0::nat); a = xs[i := fst (clist ! i ! (0::nat))]⟧ ⟹ b = snd (clist ! i ! (0::nat))› and 3 goals remain*) apply (erule_tac x=i in allE (*‹⟦∀x::?'a. (?P::?'a ⇒ bool) x; ?P (?x::?'a) ⟹ ?R::bool⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption, erule_tac x=1 and P="λj. (H j) ⟶ (snd (d j))=(snd (e j))" for H d e in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), simp) (*top goal: ‹⋀(a::'a::type com option list) (b::'a::type) (ys::('a::type com option list × 'a::type) list) (xs::'a::type com option list) (s::'a::type) (clist::('a::type com option × 'a::type) list list) i::nat. ⟦∀(xs::'a::type com option list) s::'a::type. (∃clist::('a::type com option × 'a::type) list list. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist)) ∧ (∀i::nat. i < length xs ∧ i < length clist ⟶ (∀j<Suc (length ys). snd (((xs, s) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j))) ∧ same_program ((xs, s) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l::nat. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i::nat. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], b) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist)); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], b) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], b) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], b) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! (0::nat))], b) # ys) ! x ∧ (∃i<length xs. map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], b) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! (0::nat))], b) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! (0::nat))], b); i < length xs; (xs ! i, s) -c→ clist ! i ! (0::nat); ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! (0::nat); a = xs[i := fst (clist ! i ! (0::nat))]⟧ ⟹ b = snd (clist ! i ! (0::nat))› and 3 goals remain*) prefer 2 (*top goal: ‹⋀a b ys xs s clist i. ⟦∀xs s. (∃clist. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_program ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (a, b) # ys) ! x -pc→ ((a, b) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (a, b) # ys) ! x -pe→ ((a, b) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (a, b); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0⟧ ⟹ a = xs[i := fst (clist ! i ! 0)]› and 2 goals remain*) apply (simp add:same_program_def (*‹same_program ?c ?clist ≡ ∀j<length ?c. fst (?c ! j) = map (λx. fst (x ! j)) ?clist›*)) (*top goal: ‹⋀a b ys xs s clist i. ⟦∀xs s. (∃clist. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_program ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (a, b) # ys) ! x -pc→ ((a, b) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (a, b) # ys) ! x -pe→ ((a, b) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (a, b); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0⟧ ⟹ a = xs[i := fst (clist ! i ! 0)]› and 2 goals remain*) apply (erule_tac x=1 and P="λj. H j ⟶ (fst (s j))=(t j)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), simp) (*top goal: ‹⋀a b ys xs s clist i. ⟦∀xs s. (∃clist. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀j<Suc (Suc (length ys)). fst (((xs, s) # (a, b) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist); ∀x<Suc (length ys). ((xs, s) # (a, b) # ys) ! x -pc→ ((a, b) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (a, b) # ys) ! x -pe→ ((a, b) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (a, b); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0⟧ ⟹ a = xs[i := fst (clist ! i ! 0)]› and 2 goals remain*) apply (rule nth_equalityI (*‹⟦length ?xs = length ?ys; ⋀i. i < length ?xs ⟹ ?xs ! i = ?ys ! i⟧ ⟹ ?xs = ?ys›*), simp) (*top goal: ‹⋀(a::'a com option list) (b::'a) (ys::('a com option list × 'a) list) (xs::'a com option list) (s::'a) (clist::('a com option × 'a) list list) i::nat. ⟦∀(xs::'a com option list) s::'a. (∃clist::('a com option × 'a) list list. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map ((λx::('a com option × 'a) list. fst (x ! j)) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l::nat. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i::nat. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (map ((λx::('a com option × 'a) list. fst (x ! Suc (0::nat))) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clist), b) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (map ((λx::('a com option × 'a) list. fst (x ! Suc (0::nat))) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clist), b) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (map ((λx::('a com option × 'a) list. fst (x ! Suc (0::nat))) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x -pc→ ((map ((λx::('a com option × 'a) list. fst (x ! Suc (0::nat))) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x ∧ (∃i<length xs. map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (map ((λx::('a com option × 'a) list. fst (x ! Suc (0::nat))) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x -pe→ ((map ((λx::('a com option × 'a) list. fst (x ! Suc (0::nat))) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (map ((λx::('a com option × 'a) list. fst (x ! Suc (0::nat))) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clist), b); i < length xs; (xs ! i, s) -c→ clist ! i ! (0::nat); ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! (0::nat); a = map ((λx::('a com option × 'a) list. fst (x ! Suc (0::nat))) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clist)⟧ ⟹ map ((λx::('a com option × 'a) list. fst (x ! Suc (0::nat))) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clist) = xs[i := fst (clist ! i ! (0::nat))]› and 2 goals remain*) apply clarify (*top goal: ‹⋀a b ys xs s clist i ia. ⟦∀xs s. (∃clist. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist), b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist), b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x -pc→ ((map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x -pe→ ((map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist), b); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; a = map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist); ia < length (map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist))⟧ ⟹ map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist) ! ia = xs[i := fst (clist ! i ! 0)] ! ia› and 2 goals remain*) apply (case_tac "i=ia", simp, simp) (*top goal: ‹⋀(a::'a com option list) (b::'a) (ys::('a com option list × 'a) list) (xs::'a com option list) (s::'a) (clist::('a com option × 'a) list list) (i::nat) ia::nat. ⟦∀(xs::'a com option list) s::'a. (∃clist::('a com option × 'a) list list. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map ((λx::('a com option × 'a) list. fst (x ! j)) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l::nat. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i::nat. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (map ((λx::('a com option × 'a) list. fst (x ! Suc (0::nat))) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clist), b) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (map ((λx::('a com option × 'a) list. fst (x ! Suc (0::nat))) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clist), b) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (map ((λx::('a com option × 'a) list. fst (x ! Suc (0::nat))) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x -pc→ ((map ((λx::('a com option × 'a) list. fst (x ! Suc (0::nat))) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x ∧ (∃i<length xs. map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (map ((λx::('a com option × 'a) list. fst (x ! Suc (0::nat))) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x -pe→ ((map ((λx::('a com option × 'a) list. fst (x ! Suc (0::nat))) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (map ((λx::('a com option × 'a) list. fst (x ! Suc (0::nat))) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clist), b); i < length xs; (xs ! i, s) -c→ clist ! i ! (0::nat); ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! (0::nat); ia < length (map ((λx::('a com option × 'a) list. fst (x ! Suc (0::nat))) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clist))⟧ ⟹ map ((λx::('a com option × 'a) list. fst (x ! Suc (0::nat))) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clist) ! ia = xs[i := fst (clist ! i ! (0::nat))] ! ia› and 2 goals remain*) apply (erule_tac x=ia and P="λj. H j ⟶ I j ⟶ J j" for H I J in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀b ys xs s clist i ia. ⟦∀xs s. (∃clist. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist), b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist), b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x -pc→ ((map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x -pe→ ((map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist), b); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; ia < length xs; i ≠ ia⟧ ⟹ fst (clist ! ia ! 0) = xs ! ia› and 2 goals remain*) apply (drule_tac t=i in not_sym (*‹?t ≠ ?s ⟹ ?s ≠ ?t›*), simp) (*top goal: ‹⋀(b::'a::type) (ys::('a::type com option list × 'a::type) list) (xs::'a::type com option list) (s::'a::type) (clist::('a::type com option × 'a::type) list list) (i::nat) ia::nat. ⟦∀(xs::'a::type com option list) s::'a::type. (∃clist::('a::type com option × 'a::type) list list. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map ((λx::('a::type com option × 'a::type) list. fst (x ! j)) ∘ (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l::nat. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i::nat. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (map ((λx::('a::type com option × 'a::type) list. fst (x ! Suc (0::nat))) ∘ (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i)) (zip xs clist), b) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (map ((λx::('a::type com option × 'a::type) list. fst (x ! Suc (0::nat))) ∘ (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i)) (zip xs clist), b) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (map ((λx::('a::type com option × 'a::type) list. fst (x ! Suc (0::nat))) ∘ (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x -pc→ ((map ((λx::('a::type com option × 'a::type) list. fst (x ! Suc (0::nat))) ∘ (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x ∧ (∃i<length xs. map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (map ((λx::('a::type com option × 'a::type) list. fst (x ! Suc (0::nat))) ∘ (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x -pe→ ((map ((λx::('a::type com option × 'a::type) list. fst (x ! Suc (0::nat))) ∘ (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (map ((λx::('a::type com option × 'a::type) list. fst (x ! Suc (0::nat))) ∘ (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i)) (zip xs clist), b); i < length xs; (xs ! i, s) -c→ clist ! i ! (0::nat); ia < length xs; i ≠ ia; ia < length xs ⟶ ia ≠ i ⟶ (xs ! ia, s) -e→ clist ! ia ! (0::nat)⟧ ⟹ fst (clist ! ia ! (0::nat)) = xs ! ia› and 2 goals remain*) apply (erule etranE (*‹⟦?c -e→ ?c'; ⋀P s t. ⟦?c = (P, s); ?c' = (P, t)⟧ ⟹ ?Q⟧ ⟹ ?Q›*), simp) (*top goal: ‹⋀b ys xs s clist i ia. ⟦∀xs s. (∃clist. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist), b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist), b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x -pc→ ((map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x -pe→ ((map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist), b) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (map ((λx. fst (x ! Suc 0)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist), b); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ia < length xs; (xs ! ia, s) -e→ clist ! ia ! 0; ia ≠ i⟧ ⟹ fst (clist ! ia ! 0) = xs ! ia› and 2 goals remain*) apply (rule ParCptnComp (*‹⟦(?P, ?s) -pc→ (?Q, ?t); (?Q, ?t) # ?xs ∈ par_cptn⟧ ⟹ (?P, ?s) # (?Q, ?t) # ?xs ∈ par_cptn›*)) (*top goal: ‹⋀a b ys xs s clist i. ⟦∀xs s. (∃clist. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_program ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; a = xs[i := fst (clist ! i ! 0)]; b = snd (clist ! i ! 0)⟧ ⟹ (xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys ∈ par_cptn› and 1 goal remains*) apply (erule ParComp (*‹⟦?i < length ?Ps; (?Ps ! ?i, ?s) -c→ (?r, ?t)⟧ ⟹ (?Ps, ?s) -pc→ (?Ps[?i := ?r], ?t)›*), simp) (*top goal: ‹⋀a b ys xs s clist i. ⟦∀xs s. (∃clist. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_program ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; a = xs[i := fst (clist ! i ! 0)]; b = snd (clist ! i ! 0)⟧ ⟹ (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0))› and 2 goals remain*) apply (erule_tac x="xs[i := fst (clist ! i ! 0)]" in allE (*‹⟦∀x::?'a::type. (?P::?'a::type ⇒ bool) x; ?P (?x::?'a::type) ⟹ ?R::bool⟧ ⟹ ?R›*)) (*top goal: ‹⋀a b ys xs s clist i. ⟦∀xs s. (∃clist. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_program ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; a = xs[i := fst (clist ! i ! 0)]; b = snd (clist ! i ! 0)⟧ ⟹ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys ∈ par_cptn› and 1 goal remains*) apply (erule_tac x="snd (clist ! i ! 0)" in allE (*‹⟦∀x::?'a::type. (?P::?'a::type ⇒ bool) x; ?P (?x::?'a::type) ⟹ ?R::bool⟧ ⟹ ?R›*)) (*top goal: ‹⋀(a::'a com option list) (b::'a) (ys::('a com option list × 'a) list) (xs::'a com option list) (s::'a) (clist::('a com option × 'a) list list) i::nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x ∧ (∃i<length xs. map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))); i < length xs; (xs ! i, s) -c→ clist ! i ! (0::nat); ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! (0::nat); a = xs[i := fst (clist ! i ! (0::nat))]; b = snd (clist ! i ! (0::nat)); ∀s::'a. (∃clista::('a com option × 'a) list list. length clista = length (xs[i := fst (clist ! i ! (0::nat))]) ∧ (∀ia<length (xs[i := fst (clist ! i ! (0::nat))]). (xs[i := fst (clist ! i ! (0::nat))] ! ia, s) # clista ! ia ∈ cptn) ∧ same_length ((xs[i := fst (clist ! i ! (0::nat))], s) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip (xs[i := fst (clist ! i ! (0::nat))]) clista)) ∧ same_state ((xs[i := fst (clist ! i ! (0::nat))], s) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip (xs[i := fst (clist ! i ! (0::nat))]) clista)) ∧ same_program ((xs[i := fst (clist ! i ! (0::nat))], s) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip (xs[i := fst (clist ! i ! (0::nat))]) clista)) ∧ (∀j<length ys. ((xs[i := fst (clist ! i ! (0::nat))], s) # ys) ! j -pc→ ys ! j ∧ (∃ia<length (xs[i := fst (clist ! i ! (0::nat))]). ia < length clista ∧ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip (xs[i := fst (clist ! i ! (0::nat))]) clista) ! ia ! j -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip (xs[i := fst (clist ! i ! (0::nat))]) clista) ! ia ! Suc j ∧ (∀l::nat. l < length (xs[i := fst (clist ! i ! (0::nat))]) ∧ l < length clista ⟶ l ≠ ia ⟶ ((xs[i := fst (clist ! i ! (0::nat))] ! l, s) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs[i := fst (clist ! i ! (0::nat))], s) # ys) ! j -pe→ ys ! j ∧ (∀ia::nat. ia < length (xs[i := fst (clist ! i ! (0::nat))]) ∧ ia < length clista ⟶ ((xs[i := fst (clist ! i ! (0::nat))] ! ia, s) # clista ! ia) ! j -e→ clista ! ia ! j))) ⟶ (xs[i := fst (clist ! i ! (0::nat))], s) # ys ∈ par_cptn⟧ ⟹ (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys ∈ par_cptn› and 1 goal remains*) apply (erule mp (*‹⟦(?P::bool) ⟶ (?Q::bool); ?P⟧ ⟹ ?Q›*)) (*top goal: ‹⋀a b ys xs s clist i. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; a = xs[i := fst (clist ! i ! 0)]; b = snd (clist ! i ! 0); (∃clista. length clista = length (xs[i := fst (clist ! i ! 0)]) ∧ (∀ia<length (xs[i := fst (clist ! i ! 0)]). (xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # clista ! ia ∈ cptn) ∧ same_length ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) clista)) ∧ same_state ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) clista)) ∧ same_program ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) clista)) ∧ (∀j<length ys. ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j ∧ (∃ia<length (xs[i := fst (clist ! i ! 0)]). ia < length clista ∧ map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) clista) ! ia ! j -c→ map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) clista) ! ia ! Suc j ∧ (∀l. l < length (xs[i := fst (clist ! i ! 0)]) ∧ l < length clista ⟶ l ≠ ia ⟶ ((xs[i := fst (clist ! i ! 0)] ! l, snd (clist ! i ! 0)) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ∧ (∀ia. ia < length (xs[i := fst (clist ! i ! 0)]) ∧ ia < length clista ⟶ ((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # clista ! ia) ! j -e→ clista ! ia ! j))) ⟶ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys ∈ par_cptn⟧ ⟹ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys ∈ par_cptn› and 1 goal remains*) apply (rule_tac x="map tl clist" in exI (*‹?P ?x ⟹ ∃x. ?P x›*), simp) (*top goal: ‹⋀a b ys xs s clist i. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; a = xs[i := fst (clist ! i ! 0)]; b = snd (clist ! i ! 0)⟧ ⟹ ∃clista. length clista = length (xs[i := fst (clist ! i ! 0)]) ∧ (∀ia<length (xs[i := fst (clist ! i ! 0)]). (xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # clista ! ia ∈ cptn) ∧ same_length ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) clista)) ∧ same_state ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) clista)) ∧ same_program ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) clista)) ∧ (∀j<length ys. ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j ∧ (∃ia<length (xs[i := fst (clist ! i ! 0)]). ia < length clista ∧ map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) clista) ! ia ! j -c→ map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) clista) ! ia ! Suc j ∧ (∀l. l < length (xs[i := fst (clist ! i ! 0)]) ∧ l < length clista ⟶ l ≠ ia ⟶ ((xs[i := fst (clist ! i ! 0)] ! l, snd (clist ! i ! 0)) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ∧ (∀ia. ia < length (xs[i := fst (clist ! i ! 0)]) ∧ ia < length clista ⟶ ((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # clista ! ia) ! j -e→ clista ! ia ! j))› and 1 goal remains*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*), clarify) (*top goal: ‹⋀a b ys xs s clist i. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; a = xs[i := fst (clist ! i ! 0)]; b = snd (clist ! i ! 0)⟧ ⟹ (∀ia<length xs. (xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia) ∈ cptn) ∧ same_length ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist))) ∧ same_state ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist))) ∧ same_program ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist))) ∧ (∀j<length ys. ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j ∧ (∃ia<length xs. map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist)) ! ia ! j -c→ map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist)) ! ia ! Suc j ∧ (∀l<length xs. l ≠ ia ⟶ ((xs[i := fst (clist ! i ! 0)] ! l, snd (clist ! i ! 0)) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ∧ (∀ia<length xs. ((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j -e→ tl (clist ! ia) ! j))› and 1 goal remains*) apply (case_tac "i=ia", simp) (*top goal: ‹⋀(a::'a com option list) (b::'a) (ys::('a com option list × 'a) list) (xs::'a com option list) (s::'a) (clist::('a com option × 'a) list list) (i::nat) ia::nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x ∧ (∃i<length xs. map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))); i < length xs; (xs ! i, s) -c→ clist ! i ! (0::nat); ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! (0::nat); ia < length xs⟧ ⟹ (xs[i := fst (clist ! i ! (0::nat))] ! ia, snd (clist ! i ! (0::nat))) # tl (clist ! ia) ∈ cptn› and 2 goals remain*) apply (rule nth_tl_if (*‹⟦?ys ≠ []; ?ys ! 0 = ?a; ?P ?ys⟧ ⟹ ?P (?a # tl ?ys)›*)) (*top goal: ‹⋀ys xs s clist i ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! x -pc→ ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! x -pe→ ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)); (xs ! ia, s) -c→ clist ! ia ! 0; ∀l<length xs. l ≠ ia ⟶ (xs ! l, s) -e→ clist ! l ! 0; ia < length xs; i = ia⟧ ⟹ clist ! ia ! 0 # tl (clist ! ia) ∈ cptn› and 3 goals remain*) apply (force simp add:same_length_def (*‹same_length ?c ?clist ≡ ∀i<length ?clist. length (?clist ! i) = length ?c›*) length_Suc_conv (*‹(length ?xs = Suc ?n) = (∃y ys. ?xs = y # ys ∧ length ys = ?n)›*)) (*top goal: ‹⋀ys xs s clist i ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! x -pc→ ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! x -pe→ ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)); (xs ! ia, s) -c→ clist ! ia ! 0; ∀l<length xs. l ≠ ia ⟶ (xs ! l, s) -e→ clist ! l ! 0; ia < length xs; i = ia⟧ ⟹ clist ! ia ≠ []› and 5 goals remain*) apply simp (*top goal: ‹⋀ys xs s clist i ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! x -pc→ ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! x -pe→ ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)); (xs ! ia, s) -c→ clist ! ia ! 0; ∀l<length xs. l ≠ ia ⟶ (xs ! l, s) -e→ clist ! l ! 0; ia < length xs; i = ia⟧ ⟹ clist ! ia ! 0 = clist ! ia ! 0› and 4 goals remain*) apply (erule allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption, erule tl_in_cptn (*‹⟦?a # ?xs ∈ cptn; ?xs ≠ []⟧ ⟹ ?xs ∈ cptn›*)) (*top goal: ‹⋀ys xs s clist i ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! x -pc→ ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! x -pe→ ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)); (xs ! ia, s) -c→ clist ! ia ! 0; ∀l<length xs. l ≠ ia ⟶ (xs ! l, s) -e→ clist ! l ! 0; ia < length xs; i = ia⟧ ⟹ clist ! ia ∈ cptn› and 3 goals remain*) apply (force simp add:same_length_def (*‹same_length ?c ?clist ≡ ∀i<length ?clist. length (?clist ! i) = length ?c›*) length_Suc_conv (*‹(length ?xs = Suc ?n) = (∃y ys. ?xs = y # ys ∧ length ys = ?n)›*)) (*top goal: ‹⋀ys xs s clist i ia. ⟦length clist = length xs; same_length ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! x -pc→ ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! x -pe→ ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)); (xs ! ia, s) -c→ clist ! ia ! 0; ∀l<length xs. l ≠ ia ⟶ (xs ! l, s) -e→ clist ! l ! 0; ia < length xs; i = ia⟧ ⟹ clist ! ia ≠ []› and 3 goals remain*) apply (rule nth_tl_if (*‹⟦?ys ≠ []; ?ys ! 0 = ?a; ?P ?ys⟧ ⟹ ?P (?a # tl ?ys)›*)) (*top goal: ‹⋀a b ys xs s clist i ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; ia < length xs; i ≠ ia⟧ ⟹ (xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia) ∈ cptn› and 2 goals remain*) apply (force simp add:same_length_def (*‹same_length ?c ?clist ≡ ∀i<length ?clist. length (?clist ! i) = length ?c›*) length_Suc_conv (*‹(length ?xs = Suc ?n) = (∃y ys. ?xs = y # ys ∧ length ys = ?n)›*)) (*top goal: ‹⋀a b ys xs s clist i ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; ia < length xs; i ≠ ia⟧ ⟹ clist ! ia ≠ []› and 4 goals remain*) apply (simp add:same_state_def (*‹same_state (?c::(?'a com option list × ?'a) list) (?clist::(?'a com option × ?'a) list list) ≡ ∀i<length ?clist. ∀j<length ?c. snd (?c ! j) = snd (?clist ! i ! j)›*)) (*top goal: ‹⋀a b ys xs s clist i ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; ia < length xs; i ≠ ia⟧ ⟹ clist ! ia ! 0 = (xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0))› and 3 goals remain*) apply (erule_tac x=ia in allE (*‹⟦∀x::?'a. (?P::?'a ⇒ bool) x; ?P (?x::?'a) ⟹ ?R::bool⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption, erule_tac x=1 and P="λj. H j ⟶ (snd (d j))=(snd (e j))" for H d e in allE (*‹⟦∀x::?'a. (?P::?'a ⇒ bool) x; ?P (?x::?'a) ⟹ ?R::bool⟧ ⟹ ?R›*)) (*top goal: ‹⋀(ys::('a com option list × 'a) list) (xs::'a com option list) (s::'a) (clist::('a com option × 'a) list list) (i::nat) ia::nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x ∧ (∃i<length xs. map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))); i < length xs; (xs ! i, s) -c→ clist ! i ! (0::nat); ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! (0::nat); ia < length xs; i ≠ ia⟧ ⟹ clist ! ia ! (0::nat) = (xs ! ia, snd (clist ! i ! (0::nat)))› and 3 goals remain*) apply (erule_tac x=ia and P="λj. H j ⟶ I j ⟶ J j" for H I J in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀ys xs s clist i ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; ia < length xs; i ≠ ia; 1 < Suc (Suc (length ys)) ⟶ snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! 1) = snd (((xs ! ia, s) # clist ! ia) ! 1)⟧ ⟹ clist ! ia ! 0 = (xs ! ia, snd (clist ! i ! 0))› and 3 goals remain*) apply (drule_tac t=i in not_sym (*‹?t ≠ ?s ⟹ ?s ≠ ?t›*), simp) (*top goal: ‹⋀ys xs s clist i ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ia < length xs; i ≠ ia; 1 < Suc (Suc (length ys)) ⟶ snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! 1) = snd (((xs ! ia, s) # clist ! ia) ! 1); ia < length xs ⟶ ia ≠ i ⟶ (xs ! ia, s) -e→ clist ! ia ! 0⟧ ⟹ clist ! ia ! 0 = (xs ! ia, snd (clist ! i ! 0))› and 3 goals remain*) apply (erule etranE (*‹⟦(?c::?'a com option × ?'a) -e→ (?c'::?'a com option × ?'a); ⋀(P::?'a com option) (s::?'a) t::?'a. ⟦?c = (P, s); ?c' = (P, t)⟧ ⟹ ?Q::bool⟧ ⟹ ?Q›*), simp) (*top goal: ‹⋀ys xs s clist i ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! ia ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! ia ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! ia ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! ia ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! ia ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ia < length xs; snd (clist ! i ! 0) = snd (clist ! ia ! 0); (xs ! ia, s) -e→ clist ! ia ! 0; ia ≠ i⟧ ⟹ clist ! ia ! 0 = (xs ! ia, snd (clist ! ia ! 0))› and 3 goals remain*) apply (erule allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption, erule tl_in_cptn (*‹⟦?a # ?xs ∈ cptn; ?xs ≠ []⟧ ⟹ ?xs ∈ cptn›*)) (*top goal: ‹⋀a b ys xs s clist i ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; ia < length xs; i ≠ ia⟧ ⟹ clist ! ia ∈ cptn› and 2 goals remain*) apply (force simp add:same_length_def (*‹same_length ?c ?clist ≡ ∀i<length ?clist. length (?clist ! i) = length ?c›*) length_Suc_conv (*‹(length ?xs = Suc ?n) = (∃y ys. ?xs = y # ys ∧ length ys = ?n)›*)) (*top goal: ‹⋀a b ys xs s clist i ia. ⟦length clist = length xs; same_length ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; ia < length xs; i ≠ ia⟧ ⟹ clist ! ia ≠ []› and 2 goals remain*) apply (simp add:same_length_def (*‹same_length ?c ?clist ≡ ∀i<length ?clist. length (?clist ! i) = length ?c›*) same_state_def (*‹same_state ?c ?clist ≡ ∀i<length ?clist. ∀j<length ?c. snd (?c ! j) = snd (?clist ! i ! j)›*)) (*top goal: ‹⋀(a::'a::type com option list) (b::'a::type) (ys::('a::type com option list × 'a::type) list) (xs::'a::type com option list) (s::'a::type) (clist::('a::type com option × 'a::type) list list) i::nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x ∧ (∃i<length xs. map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))); i < length xs; (xs ! i, s) -c→ clist ! i ! (0::nat); ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! (0::nat); a = xs[i := fst (clist ! i ! (0::nat))]; b = snd (clist ! i ! (0::nat))⟧ ⟹ same_length ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) (map (λia::'a::type com option × ('a::type com option × 'a::type) list. (fst ia, snd (clist ! i ! (0::nat))) # snd ia) (zip (xs[i := fst (clist ! i ! (0::nat))]) (map tl clist))) ∧ same_state ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) (map (λia::'a::type com option × ('a::type com option × 'a::type) list. (fst ia, snd (clist ! i ! (0::nat))) # snd ia) (zip (xs[i := fst (clist ! i ! (0::nat))]) (map tl clist))) ∧ same_program ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) (map (λia::'a::type com option × ('a::type com option × 'a::type) list. (fst ia, snd (clist ! i ! (0::nat))) # snd ia) (zip (xs[i := fst (clist ! i ! (0::nat))]) (map tl clist))) ∧ (∀j<length ys. ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! j -pc→ ys ! j ∧ (∃ia<length xs. map (λia::'a::type com option × ('a::type com option × 'a::type) list. (fst ia, snd (clist ! i ! (0::nat))) # snd ia) (zip (xs[i := fst (clist ! i ! (0::nat))]) (map tl clist)) ! ia ! j -c→ map (λia::'a::type com option × ('a::type com option × 'a::type) list. (fst ia, snd (clist ! i ! (0::nat))) # snd ia) (zip (xs[i := fst (clist ! i ! (0::nat))]) (map tl clist)) ! ia ! Suc j ∧ (∀l<length xs. l ≠ ia ⟶ ((xs[i := fst (clist ! i ! (0::nat))] ! l, snd (clist ! i ! (0::nat))) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! j -pe→ ys ! j ∧ (∀ia<length xs. ((xs[i := fst (clist ! i ! (0::nat))] ! ia, snd (clist ! i ! (0::nat))) # tl (clist ! ia)) ! j -e→ tl (clist ! ia) ! j))› and 1 goal remains*) apply (rule conjI (*‹⟦?P::bool; ?Q::bool⟧ ⟹ ?P ∧ ?Q›*)) (*top goal: ‹⋀a b ys xs s clist i. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; a = xs[i := fst (clist ! i ! 0)]; b = snd (clist ! i ! 0)⟧ ⟹ (∀ia<length xs. ∀j<Suc (length ys). snd (((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j)) ∧ same_program ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist))) ∧ (∀j<length ys. ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j ∧ (∃ia<length xs. map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist)) ! ia ! j -c→ map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist)) ! ia ! Suc j ∧ (∀l<length xs. l ≠ ia ⟶ ((xs[i := fst (clist ! i ! 0)] ! l, snd (clist ! i ! 0)) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ∧ (∀ia<length xs. ((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j -e→ tl (clist ! ia) ! j))› and 1 goal remains*) apply clarify (*top goal: ‹⋀(a::'a com option list) (b::'a) (ys::('a com option list × 'a) list) (xs::'a com option list) (s::'a) (clist::('a com option × 'a) list list) i::nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x ∧ (∃i<length xs. map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))); i < length xs; (xs ! i, s) -c→ clist ! i ! (0::nat); ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! (0::nat); a = xs[i := fst (clist ! i ! (0::nat))]; b = snd (clist ! i ! (0::nat))⟧ ⟹ ∀ia<length xs. ∀j<Suc (length ys). snd (((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! j) = snd (((xs[i := fst (clist ! i ! (0::nat))] ! ia, snd (clist ! i ! (0::nat))) # tl (clist ! ia)) ! j)› and 2 goals remain*) apply (case_tac j, simp, simp) (*top goal: ‹⋀a b ys xs s clist i ia j. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; ia < length xs; j < Suc (length ys)⟧ ⟹ snd (((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j)› and 2 goals remain*) apply (erule_tac x=ia in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption, erule_tac x="Suc(Suc nat)" and P="λj. H j ⟶ (snd (d j))=(snd (e j))" for H d e in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), simp) (*top goal: ‹⋀(ys::('a com option list × 'a) list) (xs::'a com option list) (s::'a) (clist::('a com option × 'a) list list) (i::nat) (ia::nat) (j::nat) nat::nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x ∧ (∃i<length xs. map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))); i < length xs; (xs ! i, s) -c→ clist ! i ! (0::nat); ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! (0::nat); ia < length xs; nat < length ys; j = Suc nat⟧ ⟹ snd (ys ! nat) = snd (tl (clist ! ia) ! nat)› and 2 goals remain*) apply (force simp add:same_length_def (*‹same_length ?c ?clist ≡ ∀i<length ?clist. length (?clist ! i) = length ?c›*) length_Suc_conv (*‹(length ?xs = Suc ?n) = (∃y ys. ?xs = y # ys ∧ length ys = ?n)›*)) (*top goal: ‹⋀ys xs s clist i ia j nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; ia < length xs; nat < length ys; j = Suc nat; snd (ys ! nat) = snd (clist ! ia ! Suc nat)⟧ ⟹ snd (clist ! ia ! Suc nat) = snd (tl (clist ! ia) ! nat)› and 2 goals remain*) apply (rule conjI (*‹⟦?P::bool; ?Q::bool⟧ ⟹ ?P ∧ ?Q›*)) (*top goal: ‹⋀a b ys xs s clist i. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; a = xs[i := fst (clist ! i ! 0)]; b = snd (clist ! i ! 0)⟧ ⟹ same_program ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist))) ∧ (∀j<length ys. ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j ∧ (∃ia<length xs. map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist)) ! ia ! j -c→ map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist)) ! ia ! Suc j ∧ (∀l<length xs. l ≠ ia ⟶ ((xs[i := fst (clist ! i ! 0)] ! l, snd (clist ! i ! 0)) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ∧ (∀ia<length xs. ((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j -e→ tl (clist ! ia) ! j))› and 1 goal remains*) apply (simp add:same_program_def (*‹same_program ?c ?clist ≡ ∀j<length ?c. fst (?c ! j) = map (λx. fst (x ! j)) ?clist›*)) (*top goal: ‹⋀a b ys xs s clist i. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; a = xs[i := fst (clist ! i ! 0)]; b = snd (clist ! i ! 0)⟧ ⟹ same_program ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist)))› and 2 goals remain*) apply clarify (*top goal: ‹⋀(a::'a com option list) (b::'a) (ys::('a com option list × 'a) list) (xs::'a com option list) (s::'a) (clist::('a com option × 'a) list list) i::nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); ∀j<Suc (Suc (length ys)). fst (((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! j) = map ((λx::('a com option × 'a) list. fst (x ! j)) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clist); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x ∧ (∃i<length xs. map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))); i < length xs; (xs ! i, s) -c→ clist ! i ! (0::nat); ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! (0::nat); a = xs[i := fst (clist ! i ! (0::nat))]; b = snd (clist ! i ! (0::nat))⟧ ⟹ ∀j<Suc (length ys). fst (((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! j) = map ((λx::('a com option × 'a) list. fst (x ! j)) ∘ (λia::'a com option × ('a com option × 'a) list. (fst ia, snd (clist ! i ! (0::nat))) # snd ia)) (zip (xs[i := fst (clist ! i ! (0::nat))]) (map tl clist))› and 2 goals remain*) apply (case_tac j, simp) (*top goal: ‹⋀a b ys xs s clist i j. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); ∀j<Suc (Suc (length ys)). fst (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < Suc (length ys)⟧ ⟹ fst (((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λia. (fst ia, snd (clist ! i ! 0)) # snd ia)) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist))› and 2 goals remain*) apply (rule nth_equalityI (*‹⟦length (?xs::?'a::type list) = length (?ys::?'a::type list); ⋀i::nat. i < length ?xs ⟹ ?xs ! i = ?ys ! i⟧ ⟹ ?xs = ?ys›*), simp) (*top goal: ‹⋀ys xs s clist i j. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); ∀j<Suc (Suc (length ys)). fst (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j = 0⟧ ⟹ xs[i := fst (clist ! i ! 0)] = map ((λx. fst (x ! 0)) ∘ (λia. (fst ia, snd (clist ! i ! 0)) # snd ia)) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist))› and 3 goals remain*) apply clarify (*top goal: ‹⋀ys xs s clist i j ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); ∀j<Suc (Suc (length ys)). fst (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j = 0; ia < length (xs[i := fst (clist ! i ! 0)])⟧ ⟹ xs[i := fst (clist ! i ! 0)] ! ia = map ((λx. fst (x ! 0)) ∘ (λia. (fst ia, snd (clist ! i ! 0)) # snd ia)) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist)) ! ia› and 3 goals remain*) apply (case_tac "i=ia", simp, simp) (*top goal: ‹⋀(ys::('a com option list × 'a) list) (xs::'a com option list) (s::'a) (clist::('a com option × 'a) list list) (i::nat) (j::nat) ia::nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); ∀j<Suc (Suc (length ys)). fst (((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! j) = map ((λx::('a com option × 'a) list. fst (x ! j)) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clist); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x ∧ (∃i<length xs. map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))); i < length xs; (xs ! i, s) -c→ clist ! i ! (0::nat); ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! (0::nat); ia < length (xs[i := fst (clist ! i ! (0::nat))])⟧ ⟹ xs[i := fst (clist ! i ! (0::nat))] ! ia = map ((λx::('a com option × 'a) list. fst (x ! (0::nat))) ∘ (λia::'a com option × ('a com option × 'a) list. (fst ia, snd (clist ! i ! (0::nat))) # snd ia)) (zip (xs[i := fst (clist ! i ! (0::nat))]) (map tl clist)) ! ia› and 3 goals remain*) apply (erule_tac x="Suc(Suc nat)" and P="λj. H j ⟶ (fst (s j))=(t j)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), simp) (*top goal: ‹⋀a b ys xs s clist i j nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); ∀j<Suc (Suc (length ys)). fst (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < Suc (length ys); j = Suc nat⟧ ⟹ fst (((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λia. (fst ia, snd (clist ! i ! 0)) # snd ia)) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist))› and 2 goals remain*) apply (rule nth_equalityI (*‹⟦length ?xs = length ?ys; ⋀i. i < length ?xs ⟹ ?xs ! i = ?ys ! i⟧ ⟹ ?xs = ?ys›*), simp, simp) (*top goal: ‹⋀ys xs s clist i j nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; nat < length ys; j = Suc nat; fst (ys ! nat) = map ((λx. fst (x ! Suc (Suc nat))) ∘ (λi. (fst i, s) # snd i)) (zip xs clist)⟧ ⟹ map ((λx. fst (x ! Suc (Suc nat))) ∘ (λi. (fst i, s) # snd i)) (zip xs clist) = map ((λx. fst (x ! Suc nat)) ∘ (λia. (fst ia, snd (clist ! i ! 0)) # snd ia)) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist))› and 2 goals remain*) apply (force simp add:length_Suc_conv (*‹(length ?xs = Suc ?n) = (∃y ys. ?xs = y # ys ∧ length ys = ?n)›*)) (*top goal: ‹⋀ys xs s clist i j nat ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; nat < length ys; j = Suc nat; fst (ys ! nat) = map ((λx. fst (x ! Suc (Suc nat))) ∘ (λi. (fst i, s) # snd i)) (zip xs clist); ia < length xs⟧ ⟹ fst (clist ! ia ! Suc nat) = fst (tl (clist ! ia) ! nat)› and 2 goals remain*) apply (rule allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*), rule impI (*‹(?P::bool ⟹ ?Q::bool) ⟹ ?P ⟶ ?Q›*)) (*top goal: ‹⋀a b ys xs s clist i. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; a = xs[i := fst (clist ! i ! 0)]; b = snd (clist ! i ! 0)⟧ ⟹ ∀j<length ys. ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j ∧ (∃ia<length xs. map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist)) ! ia ! j -c→ map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist)) ! ia ! Suc j ∧ (∀l<length xs. l ≠ ia ⟶ ((xs[i := fst (clist ! i ! 0)] ! l, snd (clist ! i ! 0)) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ∧ (∀ia<length xs. ((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j -e→ tl (clist ! ia) ! j)› and 1 goal remains*) apply (erule_tac x="Suc j" and P="λj. H j ⟶ (I j ∨ J j)" for H I J in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), simp) (*top goal: ‹⋀a b ys xs s clist i j. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pc→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x -pe→ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; a = xs[i := fst (clist ! i ! 0)]; b = snd (clist ! i ! 0); j < length ys⟧ ⟹ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j ∧ (∃ia<length xs. map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist)) ! ia ! j -c→ map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist)) ! ia ! Suc j ∧ (∀l<length xs. l ≠ ia ⟶ ((xs[i := fst (clist ! i ! 0)] ! l, snd (clist ! i ! 0)) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ∧ (∀ia<length xs. ((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j -e→ tl (clist ! ia) ! j)› and 1 goal remains*) apply (erule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀a b ys xs s clist i j. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; a = xs[i := fst (clist ! i ! 0)]; b = snd (clist ! i ! 0); j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc (Suc j) ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j)⟧ ⟹ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j ∧ (∃ia<length xs. map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist)) ! ia ! j -c→ map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist)) ! ia ! Suc j ∧ (∀l<length xs. l ≠ ia ⟶ ((xs[i := fst (clist ! i ! 0)] ! l, snd (clist ! i ! 0)) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ∧ (∀ia<length xs. ((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j -e→ tl (clist ! ia) ! j)› and 1 goal remains*) apply clarify (*top goal: ‹⋀a b ys xs s clist i j. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; a = xs[i := fst (clist ! i ! 0)]; b = snd (clist ! i ! 0); j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc (Suc j) ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j))⟧ ⟹ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j ∧ (∃ia<length xs. map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist)) ! ia ! j -c→ map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist)) ! ia ! Suc j ∧ (∀l<length xs. l ≠ ia ⟶ ((xs[i := fst (clist ! i ! 0)] ! l, snd (clist ! i ! 0)) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ∧ (∀ia<length xs. ((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j -e→ tl (clist ! ia) ! j)› and 2 goals remain*) apply (rule_tac x=ia in exI (*‹?P ?x ⟹ ∃x. ?P x›*), simp) (*top goal: ‹⋀a b ys xs s clist i j ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; map (λi. (fst i, s) # snd i) (zip xs clist) ! ia ! Suc j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! ia ! Suc (Suc j); ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ¬ (((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ∧ (∀ia<length xs. ((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j -e→ tl (clist ! ia) ! j))⟧ ⟹ ∃ia<length xs. map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist)) ! ia ! j -c→ map (λia. (fst ia, snd (clist ! i ! 0)) # snd ia) (zip (xs[i := fst (clist ! i ! 0)]) (map tl clist)) ! ia ! Suc j ∧ (∀l<length xs. l ≠ ia ⟶ ((xs[i := fst (clist ! i ! 0)] ! l, snd (clist ! i ! 0)) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)› and 2 goals remain*) apply (case_tac "i=ia", simp) (*top goal: ‹⋀ys xs s clist i j ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃ia<length xs. (((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j, tl (clist ! ia) ! j) ∉ etran)⟧ ⟹ ((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j -c→ tl (clist ! ia) ! j ∧ (∀l<length xs. l ≠ ia ⟶ ((xs[i := fst (clist ! i ! 0)] ! l, snd (clist ! i ! 0)) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)› and 2 goals remain*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*top goal: ‹⋀ys xs s clist i j ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)); (xs ! ia, s) -c→ clist ! ia ! 0; ∀l<length xs. l ≠ ia ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs[ia := fst (clist ! ia ! 0)] ! i, snd (clist ! ia ! 0)) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); i = ia⟧ ⟹ (clist ! ia ! 0 # tl (clist ! ia)) ! j -c→ tl (clist ! ia) ! j ∧ (∀l<length xs. l ≠ ia ⟶ ((xs ! l, snd (clist ! ia ! 0)) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)› and 3 goals remain*) apply (force simp add: length_Suc_conv (*‹(length ?xs = Suc ?n) = (∃y ys. ?xs = y # ys ∧ length ys = ?n)›*)) (*top goal: ‹⋀ys xs s clist i j ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)); (xs ! ia, s) -c→ clist ! ia ! 0; ∀l<length xs. l ≠ ia ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs[ia := fst (clist ! ia ! 0)] ! i, snd (clist ! ia ! 0)) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); i = ia⟧ ⟹ (clist ! ia ! 0 # tl (clist ! ia)) ! j -c→ tl (clist ! ia) ! j› and 4 goals remain*) apply clarify (*top goal: ‹⋀ys xs s clist i j ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)); (xs ! ia, s) -c→ clist ! ia ! 0; ∀l<length xs. l ≠ ia ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs[ia := fst (clist ! ia ! 0)] ! i, snd (clist ! ia ! 0)) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); i = ia⟧ ⟹ ∀l<length xs. l ≠ ia ⟶ ((xs ! l, snd (clist ! ia ! 0)) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j› and 3 goals remain*) apply (erule_tac x=l and P="λj. H j ⟶ I j ⟶ J j" for H I J in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption) (*top goal: ‹⋀ys xs s clist i j ia l. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)); (xs ! ia, s) -c→ clist ! ia ! 0; ∀l<length xs. l ≠ ia ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs[ia := fst (clist ! ia ! 0)] ! i, snd (clist ! ia ! 0)) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length xs; l ≠ ia⟧ ⟹ ((xs ! l, snd (clist ! ia ! 0)) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j› and 3 goals remain*) apply (erule_tac x=l and P="λj. H j ⟶ I j ⟶ J j" for H I J in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption) (*top goal: ‹⋀ys xs s clist i j ia l. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)); (xs ! ia, s) -c→ clist ! ia ! 0; j < length ys; ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs[ia := fst (clist ! ia ! 0)] ! i, snd (clist ! ia ! 0)) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length xs; l ≠ ia; l ≠ ia ⟶ (xs ! l, s) -e→ clist ! l ! 0⟧ ⟹ ((xs ! l, snd (clist ! ia ! 0)) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j› and 3 goals remain*) apply simp (*top goal: ‹⋀ys xs s clist i j ia l. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)); (xs ! ia, s) -c→ clist ! ia ! 0; j < length ys; ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs[ia := fst (clist ! ia ! 0)] ! i, snd (clist ! ia ! 0)) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length xs; l ≠ ia; l < length xs ⟶ l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; (xs ! l, s) -e→ clist ! l ! 0⟧ ⟹ ((xs ! l, snd (clist ! ia ! 0)) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j› and 3 goals remain*) apply (case_tac j, simp) (*top goal: ‹⋀ys xs s clist j ia l. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)); (xs ! ia, s) -c→ clist ! ia ! 0; j < length ys; ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs[ia := fst (clist ! ia ! 0)] ! i, snd (clist ! ia ! 0)) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length xs; l ≠ ia; clist ! l ! j -e→ clist ! l ! Suc j; (xs ! l, s) -e→ clist ! l ! 0⟧ ⟹ ((xs ! l, snd (clist ! ia ! 0)) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j› and 3 goals remain*) apply (rule tl_zero (*‹⟦(?P::?'a::type ⇒ bool) ((?ys::?'a::type list) ! Suc (?j::nat)); Suc ?j < length ?ys; ?ys ≠ []⟧ ⟹ ?P (tl ?ys ! ?j)›*)) (*top goal: ‹⋀ys xs s clist j ia l. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)); (xs ! ia, s) -c→ clist ! ia ! 0; ys ≠ []; (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) -pc→ ys ! 0; ia < length xs; clist ! ia ! 0 -c→ clist ! ia ! Suc 0; (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) -pe→ ys ! 0 ⟶ (∃i<length xs. ((xs[ia := fst (clist ! ia ! 0)] ! i, snd (clist ! ia ! 0)), tl (clist ! i) ! 0) ∉ etran); l < length xs; l ≠ ia; clist ! l ! 0 -e→ clist ! l ! Suc 0; (xs ! l, s) -e→ clist ! l ! 0; j = 0⟧ ⟹ (xs ! l, snd (clist ! ia ! 0)) -e→ tl (clist ! l) ! 0› and 4 goals remain*) apply (erule_tac x=l in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption, erule_tac x=1 and P="λj. (H j) ⟶ (snd (d j))=(snd (e j))" for H d e in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), simp) (*top goal: ‹⋀(ys::('a com option list × 'a) list) (xs::'a com option list) (s::'a) (clist::('a com option × 'a) list list) (j::nat) (ia::nat) l::nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[ia := fst (clist ! ia ! (0::nat))], snd (clist ! ia ! (0::nat))) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! (0::nat))], snd (clist ! ia ! (0::nat))) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! (0::nat))], snd (clist ! ia ! (0::nat))); (xs ! ia, s) -c→ clist ! ia ! (0::nat); ys ≠ []; (xs[ia := fst (clist ! ia ! (0::nat))], snd (clist ! ia ! (0::nat))) -pc→ ys ! (0::nat); ia < length xs; clist ! ia ! (0::nat) -c→ clist ! ia ! Suc (0::nat); (xs[ia := fst (clist ! ia ! (0::nat))], snd (clist ! ia ! (0::nat))) -pe→ ys ! (0::nat) ⟶ (∃i<length xs. ((xs[ia := fst (clist ! ia ! (0::nat))] ! i, snd (clist ! ia ! (0::nat))), tl (clist ! i) ! (0::nat)) ∉ etran); l < length xs; l ≠ ia; clist ! l ! (0::nat) -e→ clist ! l ! Suc (0::nat); (xs ! l, s) -e→ clist ! l ! (0::nat); j = (0::nat)⟧ ⟹ (xs ! l, snd (clist ! ia ! (0::nat))) -e→ clist ! l ! Suc (0::nat)› and 6 goals remain*) apply (force elim:etranE (*‹⟦(?c::?'a com option × ?'a) -e→ (?c'::?'a com option × ?'a); ⋀(P::?'a com option) (s::?'a) t::?'a. ⟦?c = (P, s); ?c' = (P, t)⟧ ⟹ ?Q::bool⟧ ⟹ ?Q›*) intro:Env (*‹(?P::?'a com option, ?s::?'a) -e→ (?P, ?t::?'a)›*)) (*top goal: ‹⋀ys xs s clist j ia l. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! l ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! 0)], snd (clist ! l ! 0)); (xs ! ia, s) -c→ clist ! ia ! 0; ys ≠ []; (xs[ia := fst (clist ! ia ! 0)], snd (clist ! l ! 0)) -pc→ ys ! 0; ia < length xs; clist ! ia ! 0 -c→ clist ! ia ! Suc 0; (xs[ia := fst (clist ! ia ! 0)], snd (clist ! l ! 0)) -pe→ ys ! 0 ⟶ (∃i<length xs. ((xs[ia := fst (clist ! ia ! 0)] ! i, snd (clist ! l ! 0)), tl (clist ! i) ! 0) ∉ etran); l < length xs; l ≠ ia; clist ! l ! 0 -e→ clist ! l ! Suc 0; (xs ! l, s) -e→ clist ! l ! 0; j = 0; snd (clist ! ia ! 0) = snd (clist ! l ! 0)⟧ ⟹ (xs ! l, snd (clist ! l ! 0)) -e→ clist ! l ! Suc 0› and 6 goals remain*) apply force (*top goal: ‹⋀ys xs s clist j ia l. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)); (xs ! ia, s) -c→ clist ! ia ! 0; ys ≠ []; (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) -pc→ ys ! 0; ia < length xs; clist ! ia ! 0 -c→ clist ! ia ! Suc 0; (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) -pe→ ys ! 0 ⟶ (∃i<length xs. ((xs[ia := fst (clist ! ia ! 0)] ! i, snd (clist ! ia ! 0)), tl (clist ! i) ! 0) ∉ etran); l < length xs; l ≠ ia; clist ! l ! 0 -e→ clist ! l ! Suc 0; (xs ! l, s) -e→ clist ! l ! 0; j = 0⟧ ⟹ Suc 0 < length (clist ! l)› and 5 goals remain*) apply force (*top goal: ‹⋀(ys::('a::type com option list × 'a::type) list) (xs::'a::type com option list) (s::'a::type) (clist::('a::type com option × 'a::type) list list) (j::nat) (ia::nat) l::nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[ia := fst (clist ! ia ! (0::nat))], snd (clist ! ia ! (0::nat))) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! (0::nat))], snd (clist ! ia ! (0::nat))) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! (0::nat))], snd (clist ! ia ! (0::nat))); (xs ! ia, s) -c→ clist ! ia ! (0::nat); ys ≠ []; (xs[ia := fst (clist ! ia ! (0::nat))], snd (clist ! ia ! (0::nat))) -pc→ ys ! (0::nat); ia < length xs; clist ! ia ! (0::nat) -c→ clist ! ia ! Suc (0::nat); (xs[ia := fst (clist ! ia ! (0::nat))], snd (clist ! ia ! (0::nat))) -pe→ ys ! (0::nat) ⟶ (∃i<length xs. ((xs[ia := fst (clist ! ia ! (0::nat))] ! i, snd (clist ! ia ! (0::nat))), tl (clist ! i) ! (0::nat)) ∉ etran); l < length xs; l ≠ ia; clist ! l ! (0::nat) -e→ clist ! l ! Suc (0::nat); (xs ! l, s) -e→ clist ! l ! (0::nat); j = (0::nat)⟧ ⟹ clist ! l ≠ []› and 4 goals remain*) apply simp (*top goal: ‹⋀ys xs s clist j ia l nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)); (xs ! ia, s) -c→ clist ! ia ! 0; j < length ys; ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ((xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs[ia := fst (clist ! ia ! 0)] ! i, snd (clist ! ia ! 0)) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length xs; l ≠ ia; clist ! l ! j -e→ clist ! l ! Suc j; (xs ! l, s) -e→ clist ! l ! 0; j = Suc nat⟧ ⟹ ((xs ! l, snd (clist ! ia ! 0)) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j› and 3 goals remain*) apply (rule tl_zero (*‹⟦?P (?ys ! Suc ?j); Suc ?j < length ?ys; ?ys ≠ []⟧ ⟹ ?P (tl ?ys ! ?j)›*)) (*top goal: ‹⋀(ys::('a com option list × 'a) list) (xs::'a com option list) (s::'a) (clist::('a com option × 'a) list list) (j::nat) (ia::nat) (l::nat) nat::nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[ia := fst (clist ! ia ! (0::nat))], snd (clist ! ia ! (0::nat))) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! (0::nat))], snd (clist ! ia ! (0::nat))) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! (0::nat))], snd (clist ! ia ! (0::nat))); (xs ! ia, s) -c→ clist ! ia ! (0::nat); Suc nat < length ys; ys ! nat -pc→ ys ! Suc nat; ia < length xs; clist ! ia ! Suc nat -c→ clist ! ia ! Suc (Suc nat); ys ! nat -pe→ ys ! Suc nat ⟶ (∃i<length xs. (tl (clist ! i) ! nat, tl (clist ! i) ! Suc nat) ∉ etran); l < length xs; l ≠ ia; clist ! l ! Suc nat -e→ clist ! l ! Suc (Suc nat); (xs ! l, s) -e→ clist ! l ! (0::nat); j = Suc nat⟧ ⟹ tl (clist ! l) ! nat -e→ tl (clist ! l) ! Suc nat› and 3 goals remain*) apply (erule tl_zero (*‹⟦?P (?ys ! Suc ?j); Suc ?j < length ?ys; ?ys ≠ []⟧ ⟹ ?P (tl ?ys ! ?j)›*)) (*top goal: ‹⋀ys xs s clist j ia l nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)); (xs ! ia, s) -c→ clist ! ia ! 0; Suc nat < length ys; ys ! nat -pc→ ys ! Suc nat; ia < length xs; clist ! ia ! Suc nat -c→ clist ! ia ! Suc (Suc nat); ys ! nat -pe→ ys ! Suc nat ⟶ (∃i<length xs. (tl (clist ! i) ! nat, tl (clist ! i) ! Suc nat) ∉ etran); l < length xs; l ≠ ia; clist ! l ! Suc nat -e→ clist ! l ! Suc (Suc nat); (xs ! l, s) -e→ clist ! l ! 0; j = Suc nat⟧ ⟹ tl (clist ! l) ! nat -e→ clist ! l ! Suc (Suc nat)› and 5 goals remain*) apply force (*top goal: ‹⋀(ys::('a::type com option list × 'a::type) list) (xs::'a::type com option list) (s::'a::type) (clist::('a::type com option × 'a::type) list list) (j::nat) (ia::nat) (l::nat) nat::nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[ia := fst (clist ! ia ! (0::nat))], snd (clist ! ia ! (0::nat))) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! (0::nat))], snd (clist ! ia ! (0::nat))) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! (0::nat))], snd (clist ! ia ! (0::nat))); (xs ! ia, s) -c→ clist ! ia ! (0::nat); Suc nat < length ys; ys ! nat -pc→ ys ! Suc nat; ia < length xs; clist ! ia ! Suc nat -c→ clist ! ia ! Suc (Suc nat); ys ! nat -pe→ ys ! Suc nat ⟶ (∃i<length xs. (tl (clist ! i) ! nat, tl (clist ! i) ! Suc nat) ∉ etran); l < length xs; l ≠ ia; (xs ! l, s) -e→ clist ! l ! (0::nat); j = Suc nat⟧ ⟹ Suc nat < length (clist ! l)› and 6 goals remain*) apply force (*top goal: ‹⋀ys xs s clist j ia l nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)); (xs ! ia, s) -c→ clist ! ia ! 0; Suc nat < length ys; ys ! nat -pc→ ys ! Suc nat; ia < length xs; clist ! ia ! Suc nat -c→ clist ! ia ! Suc (Suc nat); ys ! nat -pe→ ys ! Suc nat ⟶ (∃i<length xs. (tl (clist ! i) ! nat, tl (clist ! i) ! Suc nat) ∉ etran); l < length xs; l ≠ ia; (xs ! l, s) -e→ clist ! l ! 0; j = Suc nat⟧ ⟹ clist ! l ≠ []› and 5 goals remain*) apply force (*top goal: ‹⋀ys xs s clist j ia l nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)); (xs ! ia, s) -c→ clist ! ia ! 0; Suc nat < length ys; ys ! nat -pc→ ys ! Suc nat; ia < length xs; clist ! ia ! Suc nat -c→ clist ! ia ! Suc (Suc nat); ys ! nat -pe→ ys ! Suc nat ⟶ (∃i<length xs. (tl (clist ! i) ! nat, tl (clist ! i) ! Suc nat) ∉ etran); l < length xs; l ≠ ia; clist ! l ! Suc nat -e→ clist ! l ! Suc (Suc nat); (xs ! l, s) -e→ clist ! l ! 0; j = Suc nat⟧ ⟹ Suc (Suc nat) < length (clist ! l)› and 4 goals remain*) apply force (*top goal: ‹⋀ys xs s clist j ia l nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[ia := fst (clist ! ia ! 0)], snd (clist ! ia ! 0)); (xs ! ia, s) -c→ clist ! ia ! 0; Suc nat < length ys; ys ! nat -pc→ ys ! Suc nat; ia < length xs; clist ! ia ! Suc nat -c→ clist ! ia ! Suc (Suc nat); ys ! nat -pe→ ys ! Suc nat ⟶ (∃i<length xs. (tl (clist ! i) ! nat, tl (clist ! i) ! Suc nat) ∉ etran); l < length xs; l ≠ ia; clist ! l ! Suc nat -e→ clist ! l ! Suc (Suc nat); (xs ! l, s) -e→ clist ! l ! 0; j = Suc nat⟧ ⟹ clist ! l ≠ []› and 3 goals remain*) apply (rule conjI (*‹⟦?P::bool; ?Q::bool⟧ ⟹ ?P ∧ ?Q›*), simp) (*top goal: ‹⋀ys xs s clist i j ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃ia<length xs. (((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j, tl (clist ! ia) ! j) ∉ etran); i ≠ ia⟧ ⟹ ((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j -c→ tl (clist ! ia) ! j ∧ (∀l<length xs. l ≠ ia ⟶ ((xs[i := fst (clist ! i ! 0)] ! l, snd (clist ! i ! 0)) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)› and 2 goals remain*) apply (rule nth_tl_if (*‹⟦(?ys::?'a list) ≠ []; ?ys ! (0::nat) = (?a::?'a); (?P::?'a list ⇒ bool) ?ys⟧ ⟹ ?P (?a # tl ?ys)›*)) (*top goal: ‹⋀ys xs s clist i j ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃ia<length xs. (((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j, tl (clist ! ia) ! j) ∉ etran); i ≠ ia⟧ ⟹ ((xs ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j -c→ tl (clist ! ia) ! j› and 3 goals remain*) apply force (*top goal: ‹⋀ys xs s clist i j ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃ia<length xs. (((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j, tl (clist ! ia) ! j) ∉ etran); i ≠ ia⟧ ⟹ clist ! ia ≠ []› and 5 goals remain*) apply (erule_tac x=ia in allE (*‹⟦∀x::?'a::type. (?P::?'a::type ⇒ bool) x; ?P (?x::?'a::type) ⟹ ?R::bool⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption, erule_tac x=1 and P="λj. H j ⟶ (snd (d j))=(snd (e j))" for H d e in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀ys xs s clist i j ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃ia<length xs. (((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j, tl (clist ! ia) ! j) ∉ etran); i ≠ ia⟧ ⟹ clist ! ia ! 0 = (xs ! ia, snd (clist ! i ! 0))› and 4 goals remain*) apply (erule_tac x=ia and P="λj. H j ⟶ I j ⟶ J j" for H I J in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀ys xs s clist i j ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃ia<length xs. (((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j, tl (clist ! ia) ! j) ∉ etran); i ≠ ia; 1 < Suc (Suc (length ys)) ⟶ snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! 1) = snd (((xs ! ia, s) # clist ! ia) ! 1)⟧ ⟹ clist ! ia ! 0 = (xs ! ia, snd (clist ! i ! 0))› and 4 goals remain*) apply (drule_tac t=i in not_sym (*‹?t ≠ ?s ⟹ ?s ≠ ?t›*), simp) (*top goal: ‹⋀ys xs s clist i j ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃ia<length xs. (((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j, tl (clist ! ia) ! j) ∉ etran); i ≠ ia; 1 < Suc (Suc (length ys)) ⟶ snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! 1) = snd (((xs ! ia, s) # clist ! ia) ! 1); ia < length xs ⟶ ia ≠ i ⟶ (xs ! ia, s) -e→ clist ! ia ! 0⟧ ⟹ clist ! ia ! 0 = (xs ! ia, snd (clist ! i ! 0))› and 4 goals remain*) apply (erule etranE (*‹⟦?c -e→ ?c'; ⋀P s t. ⟦?c = (P, s); ?c' = (P, t)⟧ ⟹ ?Q⟧ ⟹ ?Q›*), simp) (*top goal: ‹⋀ys xs s clist i j ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! ia ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! ia ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! ia ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[i := fst (clist ! i ! 0)], snd (clist ! ia ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃ib<length xs. (((xs[i := fst (clist ! i ! 0)] ! ib, snd (clist ! ia ! 0)) # tl (clist ! ib)) ! j, tl (clist ! ib) ! j) ∉ etran); snd (clist ! i ! 0) = snd (clist ! ia ! 0); (xs ! ia, s) -e→ clist ! ia ! 0; ia ≠ i⟧ ⟹ clist ! ia ! 0 = (xs ! ia, snd (clist ! ia ! 0))› and 4 goals remain*) apply (erule tl_zero (*‹⟦?P (?ys ! Suc ?j); Suc ?j < length ?ys; ?ys ≠ []⟧ ⟹ ?P (tl ?ys ! ?j)›*)) (*top goal: ‹⋀ys xs s clist i j ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃ia<length xs. (((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j, tl (clist ! ia) ! j) ∉ etran); i ≠ ia⟧ ⟹ clist ! ia ! j -c→ tl (clist ! ia) ! j› and 3 goals remain*) apply force (*top goal: ‹⋀ys xs s clist i j ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃ia<length xs. (((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j, tl (clist ! ia) ! j) ∉ etran); i ≠ ia⟧ ⟹ Suc j < length (clist ! ia)› and 4 goals remain*) apply force (*top goal: ‹⋀ys xs s clist i j ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃ia<length xs. (((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j, tl (clist ! ia) ! j) ∉ etran); i ≠ ia⟧ ⟹ clist ! ia ≠ []› and 3 goals remain*) apply clarify (*top goal: ‹⋀ys xs s clist i j ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃ia<length xs. (((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j, tl (clist ! ia) ! j) ∉ etran); i ≠ ia⟧ ⟹ ∀l<length xs. l ≠ ia ⟶ ((xs[i := fst (clist ! i ! 0)] ! l, snd (clist ! i ! 0)) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j› and 2 goals remain*) apply (case_tac "i=l", simp) (*top goal: ‹⋀ys xs s clist i j ia l. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃ia<length xs. (((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j, tl (clist ! ia) ! j) ∉ etran); i ≠ ia; l < length xs; l ≠ ia⟧ ⟹ ((xs[i := fst (clist ! i ! 0)] ! l, snd (clist ! i ! 0)) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j› and 2 goals remain*) apply (rule nth_tl_if (*‹⟦?ys ≠ []; ?ys ! 0 = ?a; ?P ?ys⟧ ⟹ ?P (?a # tl ?ys)›*)) (*top goal: ‹⋀ys xs s clist i j ia l. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)); (xs ! l, s) -c→ clist ! l ! 0; ∀la<length xs. la ≠ l ⟶ (xs ! la, s) -e→ clist ! la ! 0; j < length ys; ((xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs[l := fst (clist ! l ! 0)] ! i, snd (clist ! l ! 0)) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length xs; l ≠ ia; i = l⟧ ⟹ (clist ! l ! 0 # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j› and 3 goals remain*) apply (erule_tac x=l and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), force) (*top goal: ‹⋀ys xs s clist i j ia l. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)); (xs ! l, s) -c→ clist ! l ! 0; ∀la<length xs. la ≠ l ⟶ (xs ! la, s) -e→ clist ! la ! 0; j < length ys; ((xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs[l := fst (clist ! l ! 0)] ! i, snd (clist ! l ! 0)) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length xs; l ≠ ia; i = l⟧ ⟹ clist ! l ≠ []› and 5 goals remain*) apply simp (*top goal: ‹⋀ys xs s clist i j ia l. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)); (xs ! l, s) -c→ clist ! l ! 0; ∀la<length xs. la ≠ l ⟶ (xs ! la, s) -e→ clist ! la ! 0; j < length ys; ((xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs[l := fst (clist ! l ! 0)] ! i, snd (clist ! l ! 0)) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length xs; l ≠ ia; i = l⟧ ⟹ clist ! l ! 0 = clist ! l ! 0› and 4 goals remain*) apply (erule_tac P="λj. H j ⟶ I j ⟶ J j" for H I J in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule impE (*‹⟦(?P::bool) ⟶ (?Q::bool); ?P; ?Q ⟹ ?R::bool⟧ ⟹ ?R›*), assumption, erule impE (*‹⟦(?P::bool) ⟶ (?Q::bool); ?P; ?Q ⟹ ?R::bool⟧ ⟹ ?R›*), assumption) (*top goal: ‹⋀ys xs s clist i j ia l. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)); (xs ! l, s) -c→ clist ! l ! 0; ∀la<length xs. la ≠ l ⟶ (xs ! la, s) -e→ clist ! la ! 0; j < length ys; ((xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs[l := fst (clist ! l ! 0)] ! i, snd (clist ! l ! 0)) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length xs; l ≠ ia; i = l⟧ ⟹ clist ! l ! j -e→ tl (clist ! l) ! j› and 3 goals remain*) apply (erule tl_zero (*‹⟦?P (?ys ! Suc ?j); Suc ?j < length ?ys; ?ys ≠ []⟧ ⟹ ?P (tl ?ys ! ?j)›*), force) (*top goal: ‹⋀ys xs s clist i j ia l. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)); (xs ! l, s) -c→ clist ! l ! 0; ∀la<length xs. la ≠ l ⟶ (xs ! la, s) -e→ clist ! la ! 0; j < length ys; ((xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ((xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs[l := fst (clist ! l ! 0)] ! i, snd (clist ! l ! 0)) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length xs; l ≠ ia; i = l; clist ! l ! j -e→ clist ! l ! Suc j⟧ ⟹ clist ! l ! j -e→ tl (clist ! l) ! j› and 3 goals remain*) apply (erule_tac x=l and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), force) (*top goal: ‹⋀ys xs s clist i j ia l. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j); same_program ((xs, s) # (xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)); (xs ! l, s) -c→ clist ! l ! 0; ∀la<length xs. la ≠ l ⟶ (xs ! la, s) -e→ clist ! la ! 0; j < length ys; ((xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ((xs[l := fst (clist ! l ! 0)], snd (clist ! l ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs[l := fst (clist ! l ! 0)] ! i, snd (clist ! l ! 0)) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length xs; l ≠ ia; i = l⟧ ⟹ clist ! l ≠ []› and 3 goals remain*) apply (rule nth_tl_if (*‹⟦?ys ≠ []; ?ys ! 0 = ?a; ?P ?ys⟧ ⟹ ?P (?a # tl ?ys)›*)) (*top goal: ‹⋀ys xs s clist i j ia l. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃ia<length xs. (((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j, tl (clist ! ia) ! j) ∉ etran); i ≠ ia; l < length xs; l ≠ ia; i ≠ l⟧ ⟹ ((xs[i := fst (clist ! i ! 0)] ! l, snd (clist ! i ! 0)) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j› and 2 goals remain*) apply (erule_tac x=l and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), force) (*top goal: ‹⋀ys xs s clist i j ia l. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃ia<length xs. (((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j, tl (clist ! ia) ! j) ∉ etran); i ≠ ia; l < length xs; l ≠ ia; i ≠ l⟧ ⟹ clist ! l ≠ []› and 4 goals remain*) apply (erule_tac x=l in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule impE (*‹⟦(?P::bool) ⟶ (?Q::bool); ?P; ?Q ⟹ ?R::bool⟧ ⟹ ?R›*), assumption, erule_tac x=1 and P="λj. H j ⟶ (snd (d j))=(snd (e j))" for H d e in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀ys xs s clist i j ia l. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃ia<length xs. (((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j, tl (clist ! ia) ! j) ∉ etran); i ≠ ia; l < length xs; l ≠ ia; i ≠ l⟧ ⟹ clist ! l ! 0 = (xs[i := fst (clist ! i ! 0)] ! l, snd (clist ! i ! 0))› and 3 goals remain*) apply (erule_tac x=l and P="λj. H j ⟶ I j ⟶ J j" for H I J in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption, simp) (*top goal: ‹⋀ys xs s clist i j ia l. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃ia<length xs. (((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j, tl (clist ! ia) ! j) ∉ etran); i ≠ ia; l < length xs; l ≠ ia; i ≠ l; 1 < Suc (Suc (length ys)) ⟶ snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! 1) = snd (((xs ! l, s) # clist ! l) ! 1)⟧ ⟹ clist ! l ! 0 = (xs[i := fst (clist ! i ! 0)] ! l, snd (clist ! i ! 0))› and 3 goals remain*) apply (erule etranE (*‹⟦?c -e→ ?c'; ⋀P s t. ⟦?c = (P, s); ?c' = (P, t)⟧ ⟹ ?Q⟧ ⟹ ?Q›*), simp) (*top goal: ‹⋀ys xs s clist i j ia l. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! l ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! l ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! l ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[i := fst (clist ! i ! 0)], snd (clist ! l ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃ia<length xs. (((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! l ! 0)) # tl (clist ! ia)) ! j, tl (clist ! ia) ! j) ∉ etran); i ≠ ia; l < length xs; l ≠ ia; i ≠ l; snd (clist ! i ! 0) = snd (clist ! l ! 0); (xs ! l, s) -e→ clist ! l ! 0⟧ ⟹ clist ! l ! 0 = (xs ! l, snd (clist ! l ! 0))› and 3 goals remain*) apply (rule tl_zero (*‹⟦?P (?ys ! Suc ?j); Suc ?j < length ?ys; ?ys ≠ []⟧ ⟹ ?P (tl ?ys ! ?j)›*)) (*top goal: ‹⋀ys xs s clist i j ia l. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃ia<length xs. (((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j, tl (clist ! ia) ! j) ∉ etran); i ≠ ia; l < length xs; l ≠ ia; i ≠ l⟧ ⟹ clist ! l ! j -e→ tl (clist ! l) ! j› and 2 goals remain*) apply force (*top goal: ‹⋀ys xs s clist i j ia l. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃ia<length xs. (((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j, tl (clist ! ia) ! j) ∉ etran); i ≠ ia; l < length xs; l ≠ ia; i ≠ l⟧ ⟹ clist ! l ! j -e→ clist ! l ! Suc j› and 4 goals remain*) apply force (*top goal: ‹⋀ys xs s clist i j ia l. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃ia<length xs. (((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j, tl (clist ! ia) ! j) ∉ etran); i ≠ ia; l < length xs; l ≠ ia; i ≠ l⟧ ⟹ Suc j < length (clist ! l)› and 3 goals remain*) apply (erule_tac x=l and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), force) (*top goal: ‹⋀ys xs s clist i j ia l. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pc→ ys ! j; ia < length xs; clist ! ia ! j -c→ clist ! ia ! Suc j; ∀l<length xs. l ≠ ia ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ⟶ (∃ia<length xs. (((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j, tl (clist ! ia) ! j) ∉ etran); i ≠ ia; l < length xs; l ≠ ia; i ≠ l⟧ ⟹ clist ! l ≠ []› and 2 goals remain*) apply (rule disjI2 (*‹?Q::bool ⟹ (?P::bool) ∨ ?Q›*)) (*top goal: ‹⋀(a::'a com option list) (b::'a) (ys::('a com option list × 'a) list) (xs::'a com option list) (s::'a) (clist::('a com option × 'a) list list) (i::nat) j::nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))); i < length xs; (xs ! i, s) -c→ clist ! i ! (0::nat); ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! (0::nat); a = xs[i := fst (clist ! i ! (0::nat))]; b = snd (clist ! i ! (0::nat)); j < length ys; ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! j -pe→ ys ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j)⟧ ⟹ ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! j -pc→ ys ! j ∧ (∃ia<length xs. map (λia::'a com option × ('a com option × 'a) list. (fst ia, snd (clist ! i ! (0::nat))) # snd ia) (zip (xs[i := fst (clist ! i ! (0::nat))]) (map tl clist)) ! ia ! j -c→ map (λia::'a com option × ('a com option × 'a) list. (fst ia, snd (clist ! i ! (0::nat))) # snd ia) (zip (xs[i := fst (clist ! i ! (0::nat))]) (map tl clist)) ! ia ! Suc j ∧ (∀l<length xs. l ≠ ia ⟶ ((xs[i := fst (clist ! i ! (0::nat))] ! l, snd (clist ! i ! (0::nat))) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! j -pe→ ys ! j ∧ (∀ia<length xs. ((xs[i := fst (clist ! i ! (0::nat))] ! ia, snd (clist ! i ! (0::nat))) # tl (clist ! ia)) ! j -e→ tl (clist ! ia) ! j)› and 1 goal remains*) apply (case_tac j, simp) (*top goal: ‹⋀a b ys xs s clist i j. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; a = xs[i := fst (clist ! i ! 0)]; b = snd (clist ! i ! 0); j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j)⟧ ⟹ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ∧ (∀ia<length xs. ((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j -e→ tl (clist ! ia) ! j)› and 1 goal remains*) apply clarify (*top goal: ‹⋀a b ys xs s clist i j. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; a = xs[i := fst (clist ! i ! 0)]; b = snd (clist ! i ! 0); ys ≠ []; (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) -pe→ ys ! 0 ∧ (∀i<length xs. clist ! i ! 0 -e→ clist ! i ! Suc 0); j = 0⟧ ⟹ ∀ia<length xs. (xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) -e→ tl (clist ! ia) ! 0› and 2 goals remain*) apply (rule tl_zero (*‹⟦?P (?ys ! Suc ?j); Suc ?j < length ?ys; ?ys ≠ []⟧ ⟹ ?P (tl ?ys ! ?j)›*)) (*top goal: ‹⋀a b ys xs s clist i j ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; ys ≠ []; (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) -pe→ ys ! 0; ∀i<length xs. clist ! i ! 0 -e→ clist ! i ! Suc 0; ia < length xs⟧ ⟹ (xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) -e→ tl (clist ! ia) ! 0› and 2 goals remain*) apply (erule_tac x=ia and P="λj. H j ⟶ I j∈etran" for H I in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption) (*top goal: ‹⋀a b ys xs s clist i j ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; ys ≠ []; (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) -pe→ ys ! 0; ∀i<length xs. clist ! i ! 0 -e→ clist ! i ! Suc 0; ia < length xs⟧ ⟹ (xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) -e→ clist ! ia ! Suc 0› and 4 goals remain*) apply (case_tac "i=ia", simp, simp) (*top goal: ‹⋀a b ys xs s clist i j ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; ys ≠ []; (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) -pe→ ys ! 0; ia < length xs; clist ! ia ! 0 -e→ clist ! ia ! Suc 0⟧ ⟹ (xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) -e→ clist ! ia ! Suc 0› and 4 goals remain*) apply (erule_tac x=ia in allE (*‹⟦∀x::?'a. (?P::?'a ⇒ bool) x; ?P (?x::?'a) ⟹ ?R::bool⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption, erule_tac x=1 and P="λj. H j ⟶ (snd (d j))=(snd (e j))" for H d e in allE (*‹⟦∀x::?'a. (?P::?'a ⇒ bool) x; ?P (?x::?'a) ⟹ ?R::bool⟧ ⟹ ?R›*)) (*top goal: ‹⋀ys xs s clist i ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; ys ≠ []; (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) -pe→ ys ! 0; ia < length xs; clist ! ia ! 0 -e→ clist ! ia ! Suc 0; i ≠ ia⟧ ⟹ (xs ! ia, snd (clist ! i ! 0)) -e→ clist ! ia ! Suc 0› and 4 goals remain*) apply (erule_tac x=ia and P="λj. H j ⟶ I j ⟶ J j" for H I J in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption, simp) (*top goal: ‹⋀ys xs s clist i ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; ys ≠ []; (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) -pe→ ys ! 0; ia < length xs; clist ! ia ! 0 -e→ clist ! ia ! Suc 0; i ≠ ia; 1 < Suc (Suc (length ys)) ⟶ snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! 1) = snd (((xs ! ia, s) # clist ! ia) ! 1)⟧ ⟹ (xs ! ia, snd (clist ! i ! 0)) -e→ clist ! ia ! Suc 0› and 4 goals remain*) apply (force elim:etranE (*‹⟦(?c::?'a com option × ?'a) -e→ (?c'::?'a com option × ?'a); ⋀(P::?'a com option) (s::?'a) t::?'a. ⟦?c = (P, s); ?c' = (P, t)⟧ ⟹ ?Q::bool⟧ ⟹ ?Q›*) intro:Env (*‹(?P::?'a com option, ?s::?'a) -e→ (?P, ?t::?'a)›*)) (*top goal: ‹⋀(ys::('a com option list × 'a) list) (xs::'a com option list) (s::'a) (clist::('a com option × 'a) list list) (i::nat) ia::nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_program ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! ia ! (0::nat))) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! ia ! (0::nat))); i < length xs; (xs ! i, s) -c→ clist ! i ! (0::nat); ys ≠ []; (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! ia ! (0::nat))) -pe→ ys ! (0::nat); ia < length xs; clist ! ia ! (0::nat) -e→ clist ! ia ! Suc (0::nat); i ≠ ia; snd (clist ! i ! (0::nat)) = snd (clist ! ia ! (0::nat)); (xs ! ia, s) -e→ clist ! ia ! (0::nat)⟧ ⟹ (xs ! ia, snd (clist ! ia ! (0::nat))) -e→ clist ! ia ! Suc (0::nat)› and 4 goals remain*) apply force (*top goal: ‹⋀a b ys xs s clist i j ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; ys ≠ []; (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) -pe→ ys ! 0; ∀i<length xs. clist ! i ! 0 -e→ clist ! i ! Suc 0; ia < length xs⟧ ⟹ Suc 0 < length (clist ! ia)› and 3 goals remain*) apply (erule_tac x=ia and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x::?'a. (?P::?'a ⇒ bool) x; ?P (?x::?'a) ⟹ ?R::bool⟧ ⟹ ?R›*), force) (*top goal: ‹⋀a b ys xs s clist i j ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; ys ≠ []; (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) -pe→ ys ! 0; ∀i<length xs. clist ! i ! 0 -e→ clist ! i ! Suc 0; ia < length xs⟧ ⟹ clist ! ia ≠ []› and 2 goals remain*) apply simp (*top goal: ‹⋀a b ys xs s clist i j nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; a = xs[i := fst (clist ! i ! 0)]; b = snd (clist ! i ! 0); j < length ys; ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); j = Suc nat⟧ ⟹ ((xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j -pe→ ys ! j ∧ (∀ia<length xs. ((xs[i := fst (clist ! i ! 0)] ! ia, snd (clist ! i ! 0)) # tl (clist ! ia)) ! j -e→ tl (clist ! ia) ! j)› and 1 goal remains*) apply clarify (*top goal: ‹⋀(a::'a com option list) (b::'a) (ys::('a com option list × 'a) list) (xs::'a com option list) (s::'a) (clist::('a com option × 'a) list list) (i::nat) (j::nat) nat::nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))); i < length xs; (xs ! i, s) -c→ clist ! i ! (0::nat); ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! (0::nat); a = xs[i := fst (clist ! i ! (0::nat))]; b = snd (clist ! i ! (0::nat)); Suc nat < length ys; ys ! nat -pe→ ys ! Suc nat ∧ (∀i<length xs. clist ! i ! Suc nat -e→ clist ! i ! Suc (Suc nat)); j = Suc nat⟧ ⟹ ∀i<length xs. tl (clist ! i) ! nat -e→ tl (clist ! i) ! Suc nat› and 1 goal remains*) apply (rule tl_zero (*‹⟦?P (?ys ! Suc ?j); Suc ?j < length ?ys; ?ys ≠ []⟧ ⟹ ?P (tl ?ys ! ?j)›*)) (*top goal: ‹⋀a b ys xs s clist i j nat ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; Suc nat < length ys; ys ! nat -pe→ ys ! Suc nat; ∀i<length xs. clist ! i ! Suc nat -e→ clist ! i ! Suc (Suc nat); ia < length xs⟧ ⟹ tl (clist ! ia) ! nat -e→ tl (clist ! ia) ! Suc nat› and 1 goal remains*) apply (rule tl_zero (*‹⟦?P (?ys ! Suc ?j); Suc ?j < length ?ys; ?ys ≠ []⟧ ⟹ ?P (tl ?ys ! ?j)›*), force) (*top goal: ‹⋀(a::'a::type com option list) (b::'a::type) (ys::('a::type com option list × 'a::type) list) (xs::'a::type com option list) (s::'a::type) (clist::('a::type com option × 'a::type) list list) (i::nat) (j::nat) (nat::nat) ia::nat. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! (0::nat))], snd (clist ! i ! (0::nat))); i < length xs; (xs ! i, s) -c→ clist ! i ! (0::nat); ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! (0::nat); Suc nat < length ys; ys ! nat -pe→ ys ! Suc nat; ∀i<length xs. clist ! i ! Suc nat -e→ clist ! i ! Suc (Suc nat); ia < length xs⟧ ⟹ tl (clist ! ia) ! nat -e→ clist ! ia ! Suc (Suc nat)› and 3 goals remain*) apply force (*top goal: ‹⋀a b ys xs s clist i j nat ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; Suc nat < length ys; ys ! nat -pe→ ys ! Suc nat; ∀i<length xs. clist ! i ! Suc nat -e→ clist ! i ! Suc (Suc nat); ia < length xs⟧ ⟹ Suc nat < length (clist ! ia)› and 4 goals remain*) apply (erule_tac x=ia and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), force) (*top goal: ‹⋀a b ys xs s clist i j nat ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; Suc nat < length ys; ys ! nat -pe→ ys ! Suc nat; ∀i<length xs. clist ! i ! Suc nat -e→ clist ! i ! Suc (Suc nat); ia < length xs⟧ ⟹ clist ! ia ≠ []› and 3 goals remain*) apply force (*top goal: ‹⋀a b ys xs s clist i j nat ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; Suc nat < length ys; ys ! nat -pe→ ys ! Suc nat; ∀i<length xs. clist ! i ! Suc nat -e→ clist ! i ! Suc (Suc nat); ia < length xs⟧ ⟹ Suc (Suc nat) < length (clist ! ia)› and 2 goals remain*) apply (erule_tac x=ia and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), force) (*top goal: ‹⋀a b ys xs s clist i j nat ia. ⟦length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀ia<length xs. ∀j<Suc (Suc (length ys)). snd (((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) ! j) = snd (((xs ! ia, s) # clist ! ia) ! j); same_program ((xs, s) # (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); (xs, s) -pc→ (xs[i := fst (clist ! i ! 0)], snd (clist ! i ! 0)); i < length xs; (xs ! i, s) -c→ clist ! i ! 0; ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ clist ! l ! 0; Suc nat < length ys; ys ! nat -pe→ ys ! Suc nat; ∀i<length xs. clist ! i ! Suc nat -e→ clist ! i ! Suc (Suc nat); ia < length xs⟧ ⟹ clist ! ia ≠ []› and 1 goal remains*) apply clarify (*goal: ‹⋀a b ys xs s clist. ⟦∀xs s. (∃clist. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_program ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (a, b) # ys) ! x -pc→ ((a, b) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (a, b) # ys) ! x -pe→ ((a, b) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pe→ (a, b) ∧ (∀i<length xs. (xs ! i, s) -e→ clist ! i ! 0)⟧ ⟹ (xs, s) # (a, b) # ys ∈ par_cptn›*) apply (erule par_etran.cases (*‹⟦(?a1.0, ?a2.0) -pe→ (?a3.0, ?a4.0); ⋀Ps s t. ⟦?a1.0 = Ps; ?a2.0 = s; ?a3.0 = Ps; ?a4.0 = t⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goal: ‹⋀(a::'a::type com option list) (b::'a::type) (ys::('a::type com option list × 'a::type) list) (xs::'a::type com option list) (s::'a::type) clist::('a::type com option × 'a::type) list list. ⟦∀(xs::'a::type com option list) s::'a::type. (∃clist::('a::type com option × 'a::type) list list. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist)) ∧ same_program ((xs, s) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l::nat. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i::nat. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (a, b) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (a, b) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (a, b) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (a, b) # ys) ! x -pc→ ((a, b) # ys) ! x ∧ (∃i<length xs. map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (a, b) # ys) ! x -pe→ ((a, b) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); (xs, s) -pe→ (a, b); ∀i<length xs. (xs ! i, s) -e→ clist ! i ! (0::nat)⟧ ⟹ (xs, s) # (a, b) # ys ∈ par_cptn›*) apply simp (*goal: ‹⋀a b ys xs s clist Ps sa t. ⟦∀xs s. (∃clist. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_program ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; same_length ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_state ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); same_program ((xs, s) # (a, b) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)); ∀x<Suc (length ys). ((xs, s) # (a, b) # ys) ! x -pc→ ((a, b) # ys) ! x ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! x -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc x ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((xs, s) # (a, b) # ys) ! x -pe→ ((a, b) # ys) ! x ∧ (∀i<length xs. ((xs ! i, s) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length xs. (xs ! i, s) -e→ clist ! i ! 0; xs = Ps; s = sa; a = Ps; b = t⟧ ⟹ (xs, s) # (a, b) # ys ∈ par_cptn›*) apply (rule ParCptnEnv (*‹(?P, ?t) # ?xs ∈ par_cptn ⟹ (?P, ?s) # (?P, ?t) # ?xs ∈ par_cptn›*)) (*goal: ‹⋀a b ys xs s clist Ps sa t. ⟦∀xs s. (∃clist. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_program ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; same_length ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); same_state ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; xs = Ps; s = sa; a = Ps; b = t⟧ ⟹ (Ps, sa) # (Ps, t) # ys ∈ par_cptn›*) apply (erule_tac x="Ps" in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*goal: ‹⋀a b ys xs s clist Ps sa t. ⟦∀xs s. (∃clist. length clist = length xs ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn) ∧ same_length ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_state ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ same_program ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (xs, s) # ys ∈ par_cptn; length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; same_length ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); same_state ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; xs = Ps; s = sa; a = Ps; b = t⟧ ⟹ (Ps, t) # ys ∈ par_cptn›*) apply (erule_tac x="t" in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*goal: ‹⋀a b ys xs s clist Ps sa t. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; same_length ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); same_state ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; xs = Ps; s = sa; a = Ps; b = t; ∀s. (∃clist. length clist = length Ps ∧ (∀i<length Ps. (Ps ! i, s) # clist ! i ∈ cptn) ∧ same_length ((Ps, s) # ys) (map (λi. (fst i, s) # snd i) (zip Ps clist)) ∧ same_state ((Ps, s) # ys) (map (λi. (fst i, s) # snd i) (zip Ps clist)) ∧ same_program ((Ps, s) # ys) (map (λi. (fst i, s) # snd i) (zip Ps clist)) ∧ (∀j<length ys. ((Ps, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length Ps. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip Ps clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip Ps clist) ! i ! Suc j ∧ (∀l. l < length Ps ∧ l < length clist ⟶ l ≠ i ⟶ ((Ps ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((Ps, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length Ps ∧ i < length clist ⟶ ((Ps ! i, s) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (Ps, s) # ys ∈ par_cptn⟧ ⟹ (Ps, t) # ys ∈ par_cptn›*) apply (erule mp (*‹⟦?P ⟶ ?Q; ?P⟧ ⟹ ?Q›*)) (*goal: ‹⋀(a::'a com option list) (b::'a) (ys::('a com option list × 'a) list) (xs::'a com option list) (s::'a) (clist::('a com option × 'a) list list) (Ps::'a com option list) (sa::'a) t::'a. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; same_length ((Ps, sa) # (Ps, t) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist)); same_state ((Ps, sa) # (Ps, t) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist)); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! (0::nat); xs = Ps; s = sa; a = Ps; b = t; (∃clist::('a com option × 'a) list list. length clist = length Ps ∧ (∀i<length Ps. (Ps ! i, t) # clist ! i ∈ cptn) ∧ same_length ((Ps, t) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, t) # snd i) (zip Ps clist)) ∧ same_state ((Ps, t) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, t) # snd i) (zip Ps clist)) ∧ same_program ((Ps, t) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, t) # snd i) (zip Ps clist)) ∧ (∀j<length ys. ((Ps, t) # ys) ! j -pc→ ys ! j ∧ (∃i<length Ps. i < length clist ∧ map (λi::'a com option × ('a com option × 'a) list. (fst i, t) # snd i) (zip Ps clist) ! i ! j -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, t) # snd i) (zip Ps clist) ! i ! Suc j ∧ (∀l::nat. l < length Ps ∧ l < length clist ⟶ l ≠ i ⟶ ((Ps ! l, t) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((Ps, t) # ys) ! j -pe→ ys ! j ∧ (∀i::nat. i < length Ps ∧ i < length clist ⟶ ((Ps ! i, t) # clist ! i) ! j -e→ clist ! i ! j))) ⟶ (Ps, t) # ys ∈ par_cptn⟧ ⟹ (Ps, t) # ys ∈ par_cptn›*) apply (rule_tac x="map tl clist" in exI (*‹?P ?x ⟹ ∃x. ?P x›*), simp) (*goal: ‹⋀a b ys xs s clist Ps sa t. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; same_length ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); same_state ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; xs = Ps; s = sa; a = Ps; b = t⟧ ⟹ ∃clist. length clist = length Ps ∧ (∀i<length Ps. (Ps ! i, t) # clist ! i ∈ cptn) ∧ same_length ((Ps, t) # ys) (map (λi. (fst i, t) # snd i) (zip Ps clist)) ∧ same_state ((Ps, t) # ys) (map (λi. (fst i, t) # snd i) (zip Ps clist)) ∧ same_program ((Ps, t) # ys) (map (λi. (fst i, t) # snd i) (zip Ps clist)) ∧ (∀j<length ys. ((Ps, t) # ys) ! j -pc→ ys ! j ∧ (∃i<length Ps. i < length clist ∧ map (λi. (fst i, t) # snd i) (zip Ps clist) ! i ! j -c→ map (λi. (fst i, t) # snd i) (zip Ps clist) ! i ! Suc j ∧ (∀l. l < length Ps ∧ l < length clist ⟶ l ≠ i ⟶ ((Ps ! l, t) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((Ps, t) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length Ps ∧ i < length clist ⟶ ((Ps ! i, t) # clist ! i) ! j -e→ clist ! i ! j))›*) apply (rule conjI (*‹⟦?P::bool; ?Q::bool⟧ ⟹ ?P ∧ ?Q›*)) (*goal: ‹⋀(a::'a com option list) (b::'a) (ys::('a com option list × 'a) list) (xs::'a com option list) (s::'a) (clist::('a com option × 'a) list list) (Ps::'a com option list) (sa::'a) t::'a. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; same_length ((Ps, sa) # (Ps, t) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist)); same_state ((Ps, sa) # (Ps, t) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist)); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! (0::nat); xs = Ps; s = sa; a = Ps; b = t⟧ ⟹ (∀i<length Ps. (Ps ! i, t) # tl (clist ! i) ∈ cptn) ∧ same_length ((Ps, t) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, t) # snd i) (zip Ps (map tl clist))) ∧ same_state ((Ps, t) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, t) # snd i) (zip Ps (map tl clist))) ∧ same_program ((Ps, t) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, t) # snd i) (zip Ps (map tl clist))) ∧ (∀j<length ys. ((Ps, t) # ys) ! j -pc→ ys ! j ∧ (∃i<length Ps. map (λi::'a com option × ('a com option × 'a) list. (fst i, t) # snd i) (zip Ps (map tl clist)) ! i ! j -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, t) # snd i) (zip Ps (map tl clist)) ! i ! Suc j ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, t) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((Ps, t) # ys) ! j -pe→ ys ! j ∧ (∀i<length Ps. ((Ps ! i, t) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j))›*) apply clarify (*top goal: ‹⋀a b ys xs s clist Ps sa t. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; same_length ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); same_state ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; xs = Ps; s = sa; a = Ps; b = t⟧ ⟹ ∀i<length Ps. (Ps ! i, t) # tl (clist ! i) ∈ cptn› and 1 goal remains*) apply (erule_tac x=i and P="λj. H j ⟶ I j ∈ cptn" for H I in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), simp) (*top goal: ‹⋀a b ys xs s clist Ps sa t i. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; same_length ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); same_state ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; i < length Ps⟧ ⟹ (Ps ! i, t) # tl (clist ! i) ∈ cptn› and 1 goal remains*) apply (erule cptn.cases (*‹⟦?a ∈ cptn; ⋀P s. ?a = [(P, s)] ⟹ ?P; ⋀P t xs s. ⟦?a = (P, s) # (P, t) # xs; (P, t) # xs ∈ cptn⟧ ⟹ ?P; ⋀P s Q t xs. ⟦?a = (P, s) # (Q, t) # xs; (P, s) -c→ (Q, t); (Q, t) # xs ∈ cptn⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*top goal: ‹⋀ys clist Ps sa t i. ⟦length clist = length Ps; same_length ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); same_state ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; i < length Ps; (Ps ! i, sa) # clist ! i ∈ cptn⟧ ⟹ (Ps ! i, t) # tl (clist ! i) ∈ cptn› and 1 goal remains*) apply (simp add:same_length_def (*‹same_length ?c ?clist ≡ ∀i<length ?clist. length (?clist ! i) = length ?c›*)) (*top goal: ‹⋀ys clist Ps sa t i P s. ⟦length clist = length Ps; same_length ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); same_state ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; i < length Ps; (Ps ! i, sa) # clist ! i = [(P, s)]⟧ ⟹ (Ps ! i, t) # tl (clist ! i) ∈ cptn› and 3 goals remain*) apply (erule_tac x=i and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x::?'a::type. (?P::?'a::type ⇒ bool) x; ?P (?x::?'a::type) ⟹ ?R::bool⟧ ⟹ ?R›*), force) (*top goal: ‹⋀ys clist Ps sa t i. ⟦length clist = length Ps; ∀i<length Ps. length (clist ! i) = Suc (length ys); same_state ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; i < length Ps; clist ! i = []⟧ ⟹ [(Ps ! i, t)] ∈ cptn› and 3 goals remain*) apply (simp add:same_state_def (*‹same_state ?c ?clist ≡ ∀i<length ?clist. ∀j<length ?c. snd (?c ! j) = snd (?clist ! i ! j)›*)) (*top goal: ‹⋀ys clist Ps sa t i P ta xs s. ⟦length clist = length Ps; same_length ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); same_state ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; i < length Ps; (Ps ! i, sa) # clist ! i = (P, s) # (P, ta) # xs; (P, ta) # xs ∈ cptn⟧ ⟹ (Ps ! i, t) # tl (clist ! i) ∈ cptn› and 2 goals remain*) apply (erule_tac x=i in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption, erule_tac x=1 and P="λj. H j ⟶ (snd (d j))=(snd (e j))" for H d e in allE (*‹⟦∀x::?'a. (?P::?'a ⇒ bool) x; ?P (?x::?'a) ⟹ ?R::bool⟧ ⟹ ?R›*), simp) (*top goal: ‹⋀ys clist Ps sa t i ta xs. ⟦length clist = length Ps; same_length ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; i < length Ps; clist ! i = (Ps ! i, ta) # xs; (Ps ! i, ta) # xs ∈ cptn⟧ ⟹ (Ps ! i, t) # xs ∈ cptn› and 2 goals remain*) apply (erule_tac x=i and P="λj. H j ⟶ J j ∈etran" for H J in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), simp) (*top goal: ‹⋀ys clist Ps sa t i P s Q ta xs. ⟦length clist = length Ps; same_length ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); same_state ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; i < length Ps; (Ps ! i, sa) # clist ! i = (P, s) # (Q, ta) # xs; (P, s) -c→ (Q, ta); (Q, ta) # xs ∈ cptn⟧ ⟹ (Ps ! i, t) # tl (clist ! i) ∈ cptn› and 1 goal remains*) apply (erule etranE (*‹⟦?c -e→ ?c'; ⋀P s t. ⟦?c = (P, s); ?c' = (P, t)⟧ ⟹ ?Q⟧ ⟹ ?Q›*), simp) (*top goal: ‹⋀(ys::('a com option list × 'a) list) (clist::('a com option × 'a) list list) (Ps::'a com option list) (sa::'a) (t::'a) (i::nat) (Q::'a com option) (ta::'a) xs::('a com option × 'a) list. ⟦length clist = length Ps; same_length ((Ps, sa) # (Ps, t) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist)); same_state ((Ps, sa) # (Ps, t) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist)); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); i < length Ps; clist ! i = (Q, ta) # xs; (Ps ! i, sa) -c→ (Q, ta); (Q, ta) # xs ∈ cptn; (Ps ! i, sa) -e→ (Q, ta)⟧ ⟹ (Ps ! i, t) # xs ∈ cptn› and 1 goal remains*) apply (simp add:same_state_def (*‹same_state ?c ?clist ≡ ∀i<length ?clist. ∀j<length ?c. snd (?c ! j) = snd (?clist ! i ! j)›*) same_length_def (*‹same_length ?c ?clist ≡ ∀i<length ?clist. length (?clist ! i) = length ?c›*)) (*goal: ‹⋀a b ys xs s clist Ps sa t. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; same_length ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); same_state ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; xs = Ps; s = sa; a = Ps; b = t⟧ ⟹ same_length ((Ps, t) # ys) (map (λi. (fst i, t) # snd i) (zip Ps (map tl clist))) ∧ same_state ((Ps, t) # ys) (map (λi. (fst i, t) # snd i) (zip Ps (map tl clist))) ∧ same_program ((Ps, t) # ys) (map (λi. (fst i, t) # snd i) (zip Ps (map tl clist))) ∧ (∀j<length ys. ((Ps, t) # ys) ! j -pc→ ys ! j ∧ (∃i<length Ps. map (λi. (fst i, t) # snd i) (zip Ps (map tl clist)) ! i ! j -c→ map (λi. (fst i, t) # snd i) (zip Ps (map tl clist)) ! i ! Suc j ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, t) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((Ps, t) # ys) ! j -pe→ ys ! j ∧ (∀i<length Ps. ((Ps ! i, t) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j))›*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*), clarify) (*goal: ‹⋀(a::'a::type com option list) (b::'a::type) (ys::('a::type com option list × 'a::type) list) (xs::'a::type com option list) (s::'a::type) (clist::('a::type com option × 'a::type) list list) (Ps::'a::type com option list) (sa::'a::type) t::'a::type. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! (0::nat); xs = Ps; s = sa; a = Ps; b = t⟧ ⟹ (∀i<length Ps. ∀j<Suc (length ys). snd (((Ps, t) # ys) ! j) = snd (((Ps ! i, t) # tl (clist ! i)) ! j)) ∧ same_program ((Ps, t) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, t) # snd i) (zip Ps (map tl clist))) ∧ (∀j<length ys. ((Ps, t) # ys) ! j -pc→ ys ! j ∧ (∃i<length Ps. map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, t) # snd i) (zip Ps (map tl clist)) ! i ! j -c→ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, t) # snd i) (zip Ps (map tl clist)) ! i ! Suc j ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, t) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((Ps, t) # ys) ! j -pe→ ys ! j ∧ (∀i<length Ps. ((Ps ! i, t) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j))›*) apply (case_tac j, simp, simp) (*top goal: ‹⋀a b ys xs s clist Ps sa t i j. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; i < length Ps; j < Suc (length ys)⟧ ⟹ snd (((Ps, t) # ys) ! j) = snd (((Ps ! i, t) # tl (clist ! i)) ! j)› and 1 goal remains*) apply (erule_tac x=i in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption, erule_tac x="Suc(Suc nat)" and P="λj. H j ⟶ (snd (d j))=(snd (e j))" for H d e in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), simp) (*top goal: ‹⋀ys clist Ps sa t i j nat. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; i < length Ps; nat < length ys; j = Suc nat⟧ ⟹ snd (ys ! nat) = snd (tl (clist ! i) ! nat)› and 1 goal remains*) apply (rule tl_zero (*‹⟦?P (?ys ! Suc ?j); Suc ?j < length ?ys; ?ys ≠ []⟧ ⟹ ?P (tl ?ys ! ?j)›*)) (*top goal: ‹⋀ys clist Ps sa t i j nat. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; i < length Ps; nat < length ys; j = Suc nat; snd (ys ! nat) = snd (clist ! i ! Suc nat)⟧ ⟹ snd (clist ! i ! Suc nat) = snd (tl (clist ! i) ! nat)› and 1 goal remains*) apply simp (*top goal: ‹⋀ys clist Ps sa t i j nat. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; i < length Ps; nat < length ys; j = Suc nat; snd (ys ! nat) = snd (clist ! i ! Suc nat)⟧ ⟹ snd (clist ! i ! Suc nat) = snd (clist ! i ! Suc nat)› and 3 goals remain*) apply force (*top goal: ‹⋀ys clist Ps sa t i j nat. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; i < length Ps; nat < length ys; j = Suc nat; snd (ys ! nat) = snd (clist ! i ! Suc nat)⟧ ⟹ Suc nat < length (clist ! i)› and 2 goals remain*) apply (erule_tac x=i and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), force) (*top goal: ‹⋀ys clist Ps sa t i j nat. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; i < length Ps; nat < length ys; j = Suc nat; snd (ys ! nat) = snd (clist ! i ! Suc nat)⟧ ⟹ clist ! i ≠ []› and 1 goal remains*) apply (rule conjI (*‹⟦?P::bool; ?Q::bool⟧ ⟹ ?P ∧ ?Q›*)) (*goal: ‹⋀a b ys xs s clist Ps sa t. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; xs = Ps; s = sa; a = Ps; b = t⟧ ⟹ same_program ((Ps, t) # ys) (map (λi. (fst i, t) # snd i) (zip Ps (map tl clist))) ∧ (∀j<length ys. ((Ps, t) # ys) ! j -pc→ ys ! j ∧ (∃i<length Ps. map (λi. (fst i, t) # snd i) (zip Ps (map tl clist)) ! i ! j -c→ map (λi. (fst i, t) # snd i) (zip Ps (map tl clist)) ! i ! Suc j ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, t) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((Ps, t) # ys) ! j -pe→ ys ! j ∧ (∀i<length Ps. ((Ps ! i, t) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j))›*) apply (simp add:same_program_def (*‹same_program ?c ?clist ≡ ∀j<length ?c. fst (?c ! j) = map (λx. fst (x ! j)) ?clist›*)) (*top goal: ‹⋀a b ys xs s clist Ps sa t. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; xs = Ps; s = sa; a = Ps; b = t⟧ ⟹ same_program ((Ps, t) # ys) (map (λi. (fst i, t) # snd i) (zip Ps (map tl clist)))› and 1 goal remains*) apply clarify (*top goal: ‹⋀a b ys xs s clist Ps sa t. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); ∀j<Suc (Suc (length ys)). fst (((Ps, sa) # (Ps, t) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, sa) # snd i)) (zip Ps clist); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; xs = Ps; s = sa; a = Ps; b = t⟧ ⟹ ∀j<Suc (length ys). fst (((Ps, t) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, t) # snd i)) (zip Ps (map tl clist))› and 1 goal remains*) apply (case_tac j, simp) (*top goal: ‹⋀a b ys xs s clist Ps sa t j. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); ∀j<Suc (Suc (length ys)). fst (((Ps, sa) # (Ps, t) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, sa) # snd i)) (zip Ps clist); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; j < Suc (length ys)⟧ ⟹ fst (((Ps, t) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, t) # snd i)) (zip Ps (map tl clist))› and 1 goal remains*) apply (rule nth_equalityI (*‹⟦length ?xs = length ?ys; ⋀i. i < length ?xs ⟹ ?xs ! i = ?ys ! i⟧ ⟹ ?xs = ?ys›*), simp) (*top goal: ‹⋀(ys::('a com option list × 'a) list) (clist::('a com option × 'a) list list) (Ps::'a com option list) (sa::'a) (t::'a) j::nat. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); ∀j<Suc (Suc (length ys)). fst (((Ps, sa) # (Ps, t) # ys) ! j) = map ((λx::('a com option × 'a) list. fst (x ! j)) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i)) (zip Ps clist); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! (0::nat); j = (0::nat)⟧ ⟹ Ps = map ((λx::('a com option × 'a) list. fst (x ! (0::nat))) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, t) # snd i)) (zip Ps (map tl clist))› and 2 goals remain*) apply clarify (*top goal: ‹⋀ys clist Ps sa t j i. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); ∀j<Suc (Suc (length ys)). fst (((Ps, sa) # (Ps, t) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, sa) # snd i)) (zip Ps clist); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; j = 0; i < length Ps⟧ ⟹ Ps ! i = map ((λx. fst (x ! 0)) ∘ (λi. (fst i, t) # snd i)) (zip Ps (map tl clist)) ! i› and 2 goals remain*) apply simp (*top goal: ‹⋀ys clist Ps sa t j i. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); ∀j<Suc (Suc (length ys)). fst (((Ps, sa) # (Ps, t) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, sa) # snd i)) (zip Ps clist); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; i < length Ps⟧ ⟹ Ps ! i = map ((λx. fst (x ! 0)) ∘ (λi. (fst i, t) # snd i)) (zip Ps (map tl clist)) ! i› and 2 goals remain*) apply (erule_tac x="Suc(Suc nat)" and P="λj. H j ⟶ (fst (s j))=(t j)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), simp) (*top goal: ‹⋀a b ys xs s clist Ps sa t j nat. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); ∀j<Suc (Suc (length ys)). fst (((Ps, sa) # (Ps, t) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, sa) # snd i)) (zip Ps clist); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; j < Suc (length ys); j = Suc nat⟧ ⟹ fst (((Ps, t) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, t) # snd i)) (zip Ps (map tl clist))› and 1 goal remains*) apply (rule nth_equalityI (*‹⟦length ?xs = length ?ys; ⋀i. i < length ?xs ⟹ ?xs ! i = ?ys ! i⟧ ⟹ ?xs = ?ys›*), simp, simp) (*top goal: ‹⋀(ys::('a::type com option list × 'a::type) list) (clist::('a::type com option × 'a::type) list list) (Ps::'a::type com option list) (sa::'a::type) (t::'a::type) (j::nat) nat::nat. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! (0::nat); nat < length ys; j = Suc nat; fst (ys ! nat) = map ((λx::('a::type com option × 'a::type) list. fst (x ! Suc (Suc nat))) ∘ (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, sa) # snd i)) (zip Ps clist)⟧ ⟹ map ((λx::('a::type com option × 'a::type) list. fst (x ! Suc (Suc nat))) ∘ (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, sa) # snd i)) (zip Ps clist) = map ((λx::('a::type com option × 'a::type) list. fst (x ! Suc nat)) ∘ (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, t) # snd i)) (zip Ps (map tl clist))› and 1 goal remains*) apply (force simp add:length_Suc_conv (*‹(length ?xs = Suc ?n) = (∃y ys. ?xs = y # ys ∧ length ys = ?n)›*)) (*top goal: ‹⋀ys clist Ps sa t j nat i. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; nat < length ys; j = Suc nat; fst (ys ! nat) = map ((λx. fst (x ! Suc (Suc nat))) ∘ (λi. (fst i, sa) # snd i)) (zip Ps clist); i < length Ps⟧ ⟹ fst (clist ! i ! Suc nat) = fst (tl (clist ! i) ! nat)› and 1 goal remains*) apply (rule allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*), rule impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goal: ‹⋀a b ys xs s clist Ps sa t. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; xs = Ps; s = sa; a = Ps; b = t⟧ ⟹ ∀j<length ys. ((Ps, t) # ys) ! j -pc→ ys ! j ∧ (∃i<length Ps. map (λi. (fst i, t) # snd i) (zip Ps (map tl clist)) ! i ! j -c→ map (λi. (fst i, t) # snd i) (zip Ps (map tl clist)) ! i ! Suc j ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, t) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((Ps, t) # ys) ! j -pe→ ys ! j ∧ (∀i<length Ps. ((Ps ! i, t) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j)›*) apply (erule_tac x="Suc j" and P="λj. H j ⟶ (I j ∨ J j)" for H I J in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), simp) (*goal: ‹⋀(a::'a com option list) (b::'a) (ys::('a com option list × 'a) list) (xs::'a com option list) (s::'a) (clist::('a com option × 'a) list list) (Ps::'a com option list) (sa::'a) (t::'a) j::nat. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist)); ∀x<Suc (length ys). ((Ps, sa) # (Ps, t) # ys) ! x -pc→ ((Ps, t) # ys) ! x ∧ (∃i<length Ps. map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist) ! i ! x -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc x ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, sa) # clist ! l) ! x -e→ clist ! l ! x)) ∨ ((Ps, sa) # (Ps, t) # ys) ! x -pe→ ((Ps, t) # ys) ! x ∧ (∀i<length Ps. ((Ps ! i, sa) # clist ! i) ! x -e→ clist ! i ! x); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! (0::nat); xs = Ps; s = sa; a = Ps; b = t; j < length ys⟧ ⟹ ((Ps, t) # ys) ! j -pc→ ys ! j ∧ (∃i<length Ps. map (λi::'a com option × ('a com option × 'a) list. (fst i, t) # snd i) (zip Ps (map tl clist)) ! i ! j -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, t) # snd i) (zip Ps (map tl clist)) ! i ! Suc j ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, t) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((Ps, t) # ys) ! j -pe→ ys ! j ∧ (∀i<length Ps. ((Ps ! i, t) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j)›*) apply (erule disjE (*‹⟦(?P::bool) ∨ (?Q::bool); ?P ⟹ ?R::bool; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goal: ‹⋀a b ys xs s clist Ps sa t j. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; xs = Ps; s = sa; a = Ps; b = t; j < length ys; ((Ps, t) # ys) ! j -pc→ ys ! j ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc j -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc (Suc j) ∧ (∀l<length Ps. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((Ps, t) # ys) ! j -pe→ ys ! j ∧ (∀i<length Ps. clist ! i ! j -e→ clist ! i ! Suc j)⟧ ⟹ ((Ps, t) # ys) ! j -pc→ ys ! j ∧ (∃i<length Ps. map (λi. (fst i, t) # snd i) (zip Ps (map tl clist)) ! i ! j -c→ map (λi. (fst i, t) # snd i) (zip Ps (map tl clist)) ! i ! Suc j ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, t) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((Ps, t) # ys) ! j -pe→ ys ! j ∧ (∀i<length Ps. ((Ps ! i, t) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j)›*) apply clarify (*top goal: ‹⋀a b ys xs s clist Ps sa t j. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; xs = Ps; s = sa; a = Ps; b = t; j < length ys; ((Ps, t) # ys) ! j -pc→ ys ! j ∧ (∃i<length Ps. map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc j -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc (Suc j) ∧ (∀l<length Ps. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j))⟧ ⟹ ((Ps, t) # ys) ! j -pc→ ys ! j ∧ (∃i<length Ps. map (λi. (fst i, t) # snd i) (zip Ps (map tl clist)) ! i ! j -c→ map (λi. (fst i, t) # snd i) (zip Ps (map tl clist)) ! i ! Suc j ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, t) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((Ps, t) # ys) ! j -pe→ ys ! j ∧ (∀i<length Ps. ((Ps ! i, t) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j)› and 1 goal remains*) apply (rule_tac x=i in exI (*‹?P ?x ⟹ ∃x. ?P x›*), simp) (*top goal: ‹⋀a b ys xs s clist Ps sa t j i. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; j < length ys; ((Ps, t) # ys) ! j -pc→ ys ! j; i < length Ps; map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc j -c→ map (λi. (fst i, sa) # snd i) (zip Ps clist) ! i ! Suc (Suc j); ∀l<length Ps. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ¬ (((Ps, t) # ys) ! j -pe→ ys ! j ∧ (∀i<length Ps. ((Ps ! i, t) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j))⟧ ⟹ ∃i<length Ps. map (λi. (fst i, t) # snd i) (zip Ps (map tl clist)) ! i ! j -c→ map (λi. (fst i, t) # snd i) (zip Ps (map tl clist)) ! i ! Suc j ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, t) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)› and 1 goal remains*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*top goal: ‹⋀ys clist Ps sa t j i. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; j < length ys; ((Ps, t) # ys) ! j -pc→ ys ! j; i < length Ps; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length Ps. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((Ps, t) # ys) ! j -pe→ ys ! j ⟶ (∃i<length Ps. (((Ps ! i, t) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran)⟧ ⟹ ((Ps ! i, t) # tl (clist ! i)) ! j -c→ tl (clist ! i) ! j ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, t) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)› and 1 goal remains*) apply (erule_tac x=i and P="λi. H i ⟶ J i ∈etran" for H J in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption) (*top goal: ‹⋀ys clist Ps sa t j i. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; j < length ys; ((Ps, t) # ys) ! j -pc→ ys ! j; i < length Ps; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length Ps. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((Ps, t) # ys) ! j -pe→ ys ! j ⟶ (∃i<length Ps. (((Ps ! i, t) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran)⟧ ⟹ ((Ps ! i, t) # tl (clist ! i)) ! j -c→ tl (clist ! i) ! j› and 2 goals remain*) apply (erule etranE (*‹⟦?c -e→ ?c'; ⋀P s t. ⟦?c = (P, s); ?c' = (P, t)⟧ ⟹ ?Q⟧ ⟹ ?Q›*), simp) (*top goal: ‹⋀ys clist Ps sa t j i. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); j < length ys; ((Ps, t) # ys) ! j -pc→ ys ! j; i < length Ps; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length Ps. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((Ps, t) # ys) ! j -pe→ ys ! j ⟶ (∃i<length Ps. (((Ps ! i, t) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); (Ps ! i, sa) -e→ clist ! i ! 0⟧ ⟹ ((Ps ! i, t) # tl (clist ! i)) ! j -c→ tl (clist ! i) ! j› and 2 goals remain*) apply (erule_tac x=i in allE (*‹⟦∀x::?'a. (?P::?'a ⇒ bool) x; ?P (?x::?'a) ⟹ ?R::bool⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption, erule_tac x=1 and P="λj. H j ⟶ (snd (d j))=(snd (e j))" for H d e in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), simp) (*top goal: ‹⋀(ys::('a::type com option list × 'a::type) list) (clist::('a::type com option × 'a::type) list list) (Ps::'a::type com option list) (sa::'a::type) (t::'a::type) (j::nat) (i::nat) (P::'a::type com option) ta::'a::type. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, sa) # snd i) (zip Ps clist)); j < length ys; ((Ps, t) # ys) ! j -pc→ ys ! j; i < length Ps; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length Ps. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((Ps, t) # ys) ! j -pe→ ys ! j ⟶ (∃i<length Ps. (((Ps ! i, t) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); Ps ! i = P; clist ! i ! (0::nat) = (P, ta)⟧ ⟹ ((P, t) # tl (clist ! i)) ! j -c→ tl (clist ! i) ! j› and 2 goals remain*) apply (rule nth_tl_if (*‹⟦?ys ≠ []; ?ys ! 0 = ?a; ?P ?ys⟧ ⟹ ?P (?a # tl ?ys)›*)) (*top goal: ‹⋀ys clist Ps sa t j i P ta. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); same_program ((Ps, sa) # (Ps, ta) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); j < length ys; ((Ps, ta) # ys) ! j -pc→ ys ! j; i < length Ps; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length Ps. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((Ps, ta) # ys) ! j -pe→ ys ! j ⟶ (∃i<length Ps. (((Ps ! i, ta) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); Ps ! i = P; clist ! i ! 0 = (P, ta); t = ta⟧ ⟹ ((P, ta) # tl (clist ! i)) ! j -c→ tl (clist ! i) ! j› and 2 goals remain*) apply (erule_tac x=i and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), force) (*top goal: ‹⋀ys clist Ps sa t j i P ta. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); same_program ((Ps, sa) # (Ps, ta) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); j < length ys; ((Ps, ta) # ys) ! j -pc→ ys ! j; i < length Ps; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length Ps. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((Ps, ta) # ys) ! j -pe→ ys ! j ⟶ (∃i<length Ps. (((Ps ! i, ta) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); Ps ! i = P; clist ! i ! 0 = (P, ta); t = ta⟧ ⟹ clist ! i ≠ []› and 4 goals remain*) apply simp (*top goal: ‹⋀ys clist Ps sa t j i P ta. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); same_program ((Ps, sa) # (Ps, ta) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); j < length ys; ((Ps, ta) # ys) ! j -pc→ ys ! j; i < length Ps; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length Ps. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((Ps, ta) # ys) ! j -pe→ ys ! j ⟶ (∃i<length Ps. (((Ps ! i, ta) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); Ps ! i = P; clist ! i ! 0 = (P, ta); t = ta⟧ ⟹ clist ! i ! 0 = (P, ta)› and 3 goals remain*) apply (erule tl_zero (*‹⟦?P (?ys ! Suc ?j); Suc ?j < length ?ys; ?ys ≠ []⟧ ⟹ ?P (tl ?ys ! ?j)›*), force) (*top goal: ‹⋀(ys::('a com option list × 'a) list) (clist::('a com option × 'a) list list) (Ps::'a com option list) (sa::'a) (t::'a) (j::nat) (i::nat) (P::'a com option) ta::'a. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); same_program ((Ps, sa) # (Ps, ta) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist)); j < length ys; ((Ps, ta) # ys) ! j -pc→ ys ! j; i < length Ps; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length Ps. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((Ps, ta) # ys) ! j -pe→ ys ! j ⟶ (∃i<length Ps. (((Ps ! i, ta) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); Ps ! i = P; clist ! i ! (0::nat) = (P, ta); t = ta⟧ ⟹ clist ! i ! j -c→ tl (clist ! i) ! j› and 2 goals remain*) apply (erule_tac x=i and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x::?'a. (?P::?'a ⇒ bool) x; ?P (?x::?'a) ⟹ ?R::bool⟧ ⟹ ?R›*), force) (*top goal: ‹⋀ys clist Ps sa t j i P ta. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); same_program ((Ps, sa) # (Ps, ta) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); j < length ys; ((Ps, ta) # ys) ! j -pc→ ys ! j; i < length Ps; ∀l<length Ps. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((Ps, ta) # ys) ! j -pe→ ys ! j ⟶ (∃i<length Ps. (((Ps ! i, ta) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); Ps ! i = P; clist ! i ! 0 = (P, ta); t = ta⟧ ⟹ clist ! i ≠ []› and 2 goals remain*) apply clarify (*top goal: ‹⋀(ys::('a com option list × 'a) list) (clist::('a com option × 'a) list list) (Ps::'a com option list) (sa::'a) (t::'a) (j::nat) i::nat. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist)); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! (0::nat); j < length ys; ((Ps, t) # ys) ! j -pc→ ys ! j; i < length Ps; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length Ps. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((Ps, t) # ys) ! j -pe→ ys ! j ⟶ (∃i<length Ps. (((Ps ! i, t) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran)⟧ ⟹ ∀l<length Ps. l ≠ i ⟶ ((Ps ! l, t) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j› and 1 goal remains*) apply (erule_tac x=l and P="λi. H i ⟶ J i ∈etran" for H J in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption) (*top goal: ‹⋀ys clist Ps sa t j i l. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; j < length ys; ((Ps, t) # ys) ! j -pc→ ys ! j; i < length Ps; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length Ps. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((Ps, t) # ys) ! j -pe→ ys ! j ⟶ (∃i<length Ps. (((Ps ! i, t) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length Ps; l ≠ i⟧ ⟹ ((Ps ! l, t) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j› and 1 goal remains*) apply (erule etranE (*‹⟦?c -e→ ?c'; ⋀P s t. ⟦?c = (P, s); ?c' = (P, t)⟧ ⟹ ?Q⟧ ⟹ ?Q›*), simp) (*top goal: ‹⋀ys clist Ps sa t j i l. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); j < length ys; ((Ps, t) # ys) ! j -pc→ ys ! j; i < length Ps; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length Ps. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((Ps, t) # ys) ! j -pe→ ys ! j ⟶ (∃i<length Ps. (((Ps ! i, t) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length Ps; l ≠ i; (Ps ! l, sa) -e→ clist ! l ! 0⟧ ⟹ ((Ps ! l, t) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j› and 1 goal remains*) apply (erule_tac x=l in allE (*‹⟦∀x::?'a::type. (?P::?'a::type ⇒ bool) x; ?P (?x::?'a::type) ⟹ ?R::bool⟧ ⟹ ?R›*), erule impE (*‹⟦(?P::bool) ⟶ (?Q::bool); ?P; ?Q ⟹ ?R::bool⟧ ⟹ ?R›*), assumption, erule_tac x=1 and P="λj. H j ⟶ (snd (d j))=(snd (e j))" for H d e in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), simp) (*top goal: ‹⋀ys clist Ps sa t j i l P ta. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); j < length ys; ((Ps, t) # ys) ! j -pc→ ys ! j; i < length Ps; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length Ps. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((Ps, t) # ys) ! j -pe→ ys ! j ⟶ (∃i<length Ps. (((Ps ! i, t) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length Ps; l ≠ i; Ps ! l = P; clist ! l ! 0 = (P, ta)⟧ ⟹ ((P, t) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j› and 1 goal remains*) apply (rule nth_tl_if (*‹⟦?ys ≠ []; ?ys ! 0 = ?a; ?P ?ys⟧ ⟹ ?P (?a # tl ?ys)›*)) (*top goal: ‹⋀ys clist Ps sa t j i l P ta. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); same_program ((Ps, sa) # (Ps, ta) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); j < length ys; ((Ps, ta) # ys) ! j -pc→ ys ! j; i < length Ps; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length Ps. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((Ps, ta) # ys) ! j -pe→ ys ! j ⟶ (∃i<length Ps. (((Ps ! i, ta) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length Ps; l ≠ i; Ps ! l = P; clist ! l ! 0 = (P, ta); t = ta⟧ ⟹ ((P, ta) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j› and 1 goal remains*) apply (erule_tac x=l and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), force) (*top goal: ‹⋀ys clist Ps sa t j i l P ta. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); same_program ((Ps, sa) # (Ps, ta) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); j < length ys; ((Ps, ta) # ys) ! j -pc→ ys ! j; i < length Ps; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length Ps. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((Ps, ta) # ys) ! j -pe→ ys ! j ⟶ (∃i<length Ps. (((Ps ! i, ta) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length Ps; l ≠ i; Ps ! l = P; clist ! l ! 0 = (P, ta); t = ta⟧ ⟹ clist ! l ≠ []› and 3 goals remain*) apply simp (*top goal: ‹⋀ys clist Ps sa t j i l P ta. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); same_program ((Ps, sa) # (Ps, ta) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); j < length ys; ((Ps, ta) # ys) ! j -pc→ ys ! j; i < length Ps; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length Ps. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((Ps, ta) # ys) ! j -pe→ ys ! j ⟶ (∃i<length Ps. (((Ps ! i, ta) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length Ps; l ≠ i; Ps ! l = P; clist ! l ! 0 = (P, ta); t = ta⟧ ⟹ clist ! l ! 0 = (P, ta)› and 2 goals remain*) apply (rule tl_zero (*‹⟦?P (?ys ! Suc ?j); Suc ?j < length ?ys; ?ys ≠ []⟧ ⟹ ?P (tl ?ys ! ?j)›*), force) (*top goal: ‹⋀(ys::('a com option list × 'a) list) (clist::('a com option × 'a) list list) (Ps::'a com option list) (sa::'a) (t::'a) (j::nat) (i::nat) (l::nat) (P::'a com option) ta::'a. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); same_program ((Ps, sa) # (Ps, ta) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist)); j < length ys; ((Ps, ta) # ys) ! j -pc→ ys ! j; i < length Ps; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length Ps. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((Ps, ta) # ys) ! j -pe→ ys ! j ⟶ (∃i<length Ps. (((Ps ! i, ta) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length Ps; l ≠ i; Ps ! l = P; clist ! l ! (0::nat) = (P, ta); t = ta⟧ ⟹ clist ! l ! j -e→ tl (clist ! l) ! j› and 1 goal remains*) apply force (*top goal: ‹⋀ys clist Ps sa t j i l P ta. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); same_program ((Ps, sa) # (Ps, ta) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); j < length ys; ((Ps, ta) # ys) ! j -pc→ ys ! j; i < length Ps; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length Ps. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((Ps, ta) # ys) ! j -pe→ ys ! j ⟶ (∃i<length Ps. (((Ps ! i, ta) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length Ps; l ≠ i; Ps ! l = P; clist ! l ! 0 = (P, ta); t = ta⟧ ⟹ Suc j < length (clist ! l)› and 2 goals remain*) apply (erule_tac x=l and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x::?'a::type. (?P::?'a::type ⇒ bool) x; ?P (?x::?'a::type) ⟹ ?R::bool⟧ ⟹ ?R›*), force) (*top goal: ‹⋀ys clist Ps sa t j i l P ta. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); same_program ((Ps, sa) # (Ps, ta) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); j < length ys; ((Ps, ta) # ys) ! j -pc→ ys ! j; i < length Ps; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length Ps. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((Ps, ta) # ys) ! j -pe→ ys ! j ⟶ (∃i<length Ps. (((Ps ! i, ta) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length Ps; l ≠ i; Ps ! l = P; clist ! l ! 0 = (P, ta); t = ta⟧ ⟹ clist ! l ≠ []› and 1 goal remains*) apply (rule disjI2 (*‹?Q ⟹ ?P ∨ ?Q›*)) (*goal: ‹⋀a b ys xs s clist Ps sa t j. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; xs = Ps; s = sa; a = Ps; b = t; j < length ys; ((Ps, t) # ys) ! j -pe→ ys ! j ∧ (∀i<length Ps. clist ! i ! j -e→ clist ! i ! Suc j)⟧ ⟹ ((Ps, t) # ys) ! j -pc→ ys ! j ∧ (∃i<length Ps. map (λi. (fst i, t) # snd i) (zip Ps (map tl clist)) ! i ! j -c→ map (λi. (fst i, t) # snd i) (zip Ps (map tl clist)) ! i ! Suc j ∧ (∀l<length Ps. l ≠ i ⟶ ((Ps ! l, t) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((Ps, t) # ys) ! j -pe→ ys ! j ∧ (∀i<length Ps. ((Ps ! i, t) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j)›*) apply simp (*goal: ‹⋀a b ys xs s clist Ps sa t j. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; xs = Ps; s = sa; a = Ps; b = t; j < length ys; ((Ps, t) # ys) ! j -pe→ ys ! j ∧ (∀i<length Ps. clist ! i ! j -e→ clist ! i ! Suc j)⟧ ⟹ ((Ps, t) # ys) ! j -pe→ ys ! j ∧ (∀i<length Ps. ((Ps ! i, t) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j)›*) apply clarify (*goal: ‹⋀(a::'a com option list) (b::'a) (ys::('a com option list × 'a) list) (xs::'a com option list) (s::'a) (clist::('a com option × 'a) list list) (Ps::'a com option list) (sa::'a) (t::'a) j::nat. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist)); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! (0::nat); xs = Ps; s = sa; a = Ps; b = t; j < length ys; ((Ps, t) # ys) ! j -pe→ ys ! j ∧ (∀i<length Ps. clist ! i ! j -e→ clist ! i ! Suc j)⟧ ⟹ ∀i<length Ps. ((Ps ! i, t) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j›*) apply (case_tac j, simp) (*goal: ‹⋀a b ys xs s clist Ps sa t j i. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; j < length ys; ((Ps, t) # ys) ! j -pe→ ys ! j; ∀i<length Ps. clist ! i ! j -e→ clist ! i ! Suc j; i < length Ps⟧ ⟹ ((Ps ! i, t) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j›*) apply (rule tl_zero (*‹⟦?P (?ys ! Suc ?j); Suc ?j < length ?ys; ?ys ≠ []⟧ ⟹ ?P (tl ?ys ! ?j)›*)) (*top goal: ‹⋀(ys::('a::type com option list × 'a::type) list) (clist::('a::type com option × 'a::type) list list) (Ps::'a::type com option list) (sa::'a::type) (t::'a::type) (j::nat) i::nat. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, sa) # snd i) (zip Ps clist)); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! (0::nat); ys ≠ []; (Ps, t) -pe→ ys ! (0::nat); ∀i<length Ps. clist ! i ! (0::nat) -e→ clist ! i ! Suc (0::nat); i < length Ps; j = (0::nat)⟧ ⟹ (Ps ! i, t) -e→ tl (clist ! i) ! (0::nat)› and 1 goal remains*) apply (erule_tac x=i and P="λi. H i ⟶ J i ∈etran" for H J in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption) (*top goal: ‹⋀ys clist Ps sa t j i. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; ys ≠ []; (Ps, t) -pe→ ys ! 0; ∀i<length Ps. clist ! i ! 0 -e→ clist ! i ! Suc 0; i < length Ps; j = 0⟧ ⟹ (Ps ! i, t) -e→ clist ! i ! Suc 0› and 3 goals remain*) apply (erule_tac x=i and P="λi. H i ⟶ J i ∈etran" for H J in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption) (*top goal: ‹⋀ys clist Ps sa t j i. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ys ≠ []; (Ps, t) -pe→ ys ! 0; ∀i<length Ps. clist ! i ! 0 -e→ clist ! i ! Suc 0; i < length Ps; j = 0; (Ps ! i, sa) -e→ clist ! i ! 0⟧ ⟹ (Ps ! i, t) -e→ clist ! i ! Suc 0› and 3 goals remain*) apply (force elim:etranE (*‹⟦?c -e→ ?c'; ⋀P s t. ⟦?c = (P, s); ?c' = (P, t)⟧ ⟹ ?Q⟧ ⟹ ?Q›*) intro:Env (*‹(?P, ?s) -e→ (?P, ?t)›*)) (*top goal: ‹⋀ys clist Ps sa t j i. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ys ≠ []; (Ps, t) -pe→ ys ! 0; i < length Ps; j = 0; (Ps ! i, sa) -e→ clist ! i ! 0; clist ! i ! 0 -e→ clist ! i ! Suc 0⟧ ⟹ (Ps ! i, t) -e→ clist ! i ! Suc 0› and 3 goals remain*) apply force (*top goal: ‹⋀ys clist Ps sa t j i. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; ys ≠ []; (Ps, t) -pe→ ys ! 0; ∀i<length Ps. clist ! i ! 0 -e→ clist ! i ! Suc 0; i < length Ps; j = 0⟧ ⟹ Suc 0 < length (clist ! i)› and 2 goals remain*) apply (erule_tac x=i and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), force) (*top goal: ‹⋀ys clist Ps sa t j i. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; ys ≠ []; (Ps, t) -pe→ ys ! 0; ∀i<length Ps. clist ! i ! 0 -e→ clist ! i ! Suc 0; i < length Ps; j = 0⟧ ⟹ clist ! i ≠ []› and 1 goal remains*) apply simp (*goal: ‹⋀(a::'a com option list) (b::'a) (ys::('a com option list × 'a) list) (xs::'a com option list) (s::'a) (clist::('a com option × 'a) list list) (Ps::'a com option list) (sa::'a) (t::'a) (j::nat) (i::nat) nat::nat. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist)); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! (0::nat); j < length ys; ((Ps, t) # ys) ! j -pe→ ys ! j; ∀i<length Ps. clist ! i ! j -e→ clist ! i ! Suc j; i < length Ps; j = Suc nat⟧ ⟹ ((Ps ! i, t) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j›*) apply (rule tl_zero (*‹⟦?P (?ys ! Suc ?j); Suc ?j < length ?ys; ?ys ≠ []⟧ ⟹ ?P (tl ?ys ! ?j)›*)) (*goal: ‹⋀ys clist Ps sa t j i nat. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; Suc nat < length ys; ys ! nat -pe→ ys ! Suc nat; ∀i<length Ps. clist ! i ! Suc nat -e→ clist ! i ! Suc (Suc nat); i < length Ps; j = Suc nat⟧ ⟹ tl (clist ! i) ! nat -e→ tl (clist ! i) ! Suc nat›*) apply (rule tl_zero (*‹⟦?P (?ys ! Suc ?j); Suc ?j < length ?ys; ?ys ≠ []⟧ ⟹ ?P (tl ?ys ! ?j)›*), force) (*top goal: ‹⋀ys clist Ps sa t j i nat. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; Suc nat < length ys; ys ! nat -pe→ ys ! Suc nat; ∀i<length Ps. clist ! i ! Suc nat -e→ clist ! i ! Suc (Suc nat); i < length Ps; j = Suc nat⟧ ⟹ tl (clist ! i) ! nat -e→ clist ! i ! Suc (Suc nat)› and 2 goals remain*) apply force (*top goal: ‹⋀ys clist Ps sa t j i nat. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; Suc nat < length ys; ys ! nat -pe→ ys ! Suc nat; ∀i<length Ps. clist ! i ! Suc nat -e→ clist ! i ! Suc (Suc nat); i < length Ps; j = Suc nat⟧ ⟹ Suc nat < length (clist ! i)› and 3 goals remain*) apply (erule_tac x=i and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), force) (*top goal: ‹⋀ys clist Ps sa t j i nat. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi. (fst i, sa) # snd i) (zip Ps clist)); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! 0; Suc nat < length ys; ys ! nat -pe→ ys ! Suc nat; ∀i<length Ps. clist ! i ! Suc nat -e→ clist ! i ! Suc (Suc nat); i < length Ps; j = Suc nat⟧ ⟹ clist ! i ≠ []› and 2 goals remain*) apply force (*top goal: ‹⋀(ys::('a com option list × 'a) list) (clist::('a com option × 'a) list list) (Ps::'a com option list) (sa::'a) (t::'a) (j::nat) (i::nat) nat::nat. ⟦length clist = length Ps; ∀i<length Ps. (Ps ! i, sa) # clist ! i ∈ cptn; ∀i<length Ps. length (clist ! i) = Suc (length ys); ∀i<length Ps. ∀j<Suc (Suc (length ys)). snd (((Ps, sa) # (Ps, t) # ys) ! j) = snd (((Ps ! i, sa) # clist ! i) ! j); same_program ((Ps, sa) # (Ps, t) # ys) (map (λi::'a com option × ('a com option × 'a) list. (fst i, sa) # snd i) (zip Ps clist)); ∀i<length Ps. (Ps ! i, sa) -e→ clist ! i ! (0::nat); Suc nat < length ys; ys ! nat -pe→ ys ! Suc nat; ∀i<length Ps. clist ! i ! Suc nat -e→ clist ! i ! Suc (Suc nat); i < length Ps; j = Suc nat⟧ ⟹ Suc (Suc nat) < length (clist ! i)› and 1 goal remains*) by (erule_tac x=i and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), force) lemma aux_onlyif [rule_format]: "∀xs s. (xs, s)#ys ∈ par_cptn ⟶ (∃clist. (length clist = length xs) ∧ (xs, s)#ys ∝ map (λi. (fst i,s)#(snd i)) (zip xs clist) ∧ (∀i<length xs. (xs!i,s)#(clist!i) ∈ cptn))" supply [[simproc del: defined_all]] apply(induct ys) apply(clarify) apply(rule_tac x="map (λi. []) [0..<length xs]" in exI) apply(simp add: conjoin_def same_length_def same_state_def same_program_def compat_label_def) apply(rule conjI) apply(rule nth_equalityI,simp,simp) apply(force intro: cptn.intros) apply(clarify) apply(erule par_cptn.cases,simp) apply simp apply(erule_tac x="xs" in allE) apply(erule_tac x="t" in allE,simp) apply clarify apply(rule_tac x="(map (λj. (P!j, t)#(clist!j)) [0..<length P])" in exI,simp) apply(rule conjI) prefer 2 apply clarify apply(rule CptnEnv,simp) apply(simp add:conjoin_def same_length_def same_state_def) apply (rule conjI) apply clarify apply(case_tac j,simp,simp) apply(rule conjI) apply(simp add:same_program_def) apply clarify apply(case_tac j,simp) apply(rule nth_equalityI,simp,simp) apply simp apply(rule nth_equalityI,simp,simp) apply(simp add:compat_label_def) apply clarify apply(case_tac j,simp) apply(simp add:ParEnv) apply clarify apply(simp add:Env) apply simp apply(erule_tac x=nat in allE,erule impE, assumption) apply(erule disjE,simp) apply clarify apply(rule_tac x=i in exI,simp) apply force apply(erule par_ctran.cases,simp) apply(erule_tac x="Ps[i:=r]" in allE) apply(erule_tac x="ta" in allE,simp) apply clarify apply(rule_tac x="(map (λj. (Ps!j, ta)#(clist!j)) [0..<length Ps]) [i:=((r, ta)#(clist!i))]" in exI,simp) apply(rule conjI) prefer 2 apply clarify apply(case_tac "i=ia",simp) apply(erule CptnComp) apply(erule_tac x=ia and P="λj. H j ⟶ (I j ∈ cptn)" for H I in allE,simp) apply simp apply(erule_tac x=ia in allE) apply(rule CptnEnv,simp) apply(simp add:conjoin_def) apply (rule conjI) apply(simp add:same_length_def) apply clarify apply(case_tac "i=ia",simp,simp) apply(rule conjI) apply(simp add:same_state_def) apply clarify apply(case_tac j, simp, simp (no_asm_simp)) apply(case_tac "i=ia",simp,simp) apply(rule conjI) apply(simp add:same_program_def) apply clarify apply(case_tac j,simp) apply(rule nth_equalityI,simp,simp) apply simp apply(rule nth_equalityI,simp,simp) apply(erule_tac x=nat and P="λj. H j ⟶ (fst (a j))=((b j))" for H a b in allE) apply(case_tac nat) apply clarify apply(case_tac "i=ia",simp,simp) apply clarify apply(case_tac "i=ia",simp,simp) apply(simp add:compat_label_def) apply clarify apply(case_tac j) apply(rule conjI,simp) apply(erule ParComp,assumption) apply clarify apply(rule_tac x=i in exI,simp) apply clarify apply(rule Env) apply simp apply(erule_tac x=nat and P="λj. H j ⟶ (P j ∨ Q j)" for H P Q in allE,simp) apply(erule disjE) apply clarify apply(rule_tac x=ia in exI,simp) apply(rule conjI) apply(case_tac "i=ia",simp,simp) apply clarify apply(case_tac "i=l",simp) apply(case_tac "l=ia",simp,simp) apply(erule_tac x=l in allE,erule impE,assumption,erule impE, assumption,simp) apply simp apply(erule_tac x=l in allE,erule impE,assumption,erule impE, assumption,simp) apply clarify apply(erule_tac x=ia and P="λj. H j ⟶ (P j)∈etran" for H P in allE, erule impE, assumption) apply(case_tac "i=ia",simp,simp) done lemma one_iff_aux: "xs≠[] ⟹ (∀ys. ((xs, s)#ys ∈ par_cptn) = (∃clist. length clist= length xs ∧ ((xs, s)#ys ∝ map (λi. (fst i,s)#(snd i)) (zip xs clist)) ∧ (∀i<length xs. (xs!i,s)#(clist!i) ∈ cptn))) = (par_cp (xs) s = {c. ∃clist. (length clist)=(length xs) ∧ (∀i<length clist. (clist!i) ∈ cp(xs!i) s) ∧ c ∝ clist})" apply (rule iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*)) (*goal: ‹xs ≠ [] ⟹ (∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn))) = (par_cp xs s = {c. ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ∈ cp (xs ! i) s) ∧ c ∝ clist})›*) apply (rule subset_antisym (*‹⟦?A ⊆ ?B; ?B ⊆ ?A⟧ ⟹ ?A = ?B›*)) (*top goal: ‹⟦(xs::'a::type com option list) ≠ []; ∀ys::('a::type com option list × 'a::type) list. ((xs, s::'a::type) # ys ∈ par_cptn) = (∃clist::('a::type com option × 'a::type) list list. length clist = length xs ∧ (xs, s) # ys ∝ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn))⟧ ⟹ par_cp xs s = {c::('a::type com option list × 'a::type) list. ∃clist::('a::type com option × 'a::type) list list. length clist = length xs ∧ (∀i<length clist. clist ! i ∈ cp (xs ! i) s) ∧ c ∝ clist}› and 1 goal remains*) apply (rule subsetI (*‹(⋀x. x ∈ ?A ⟹ x ∈ ?B) ⟹ ?A ⊆ ?B›*)) (*top goal: ‹⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn))⟧ ⟹ par_cp xs s ⊆ {c. ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ∈ cp (xs ! i) s) ∧ c ∝ clist}› and 2 goals remain*) apply clarify (*top goal: ‹⋀x. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); x ∈ par_cp xs s⟧ ⟹ x ∈ {c. ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ∈ cp (xs ! i) s) ∧ c ∝ clist}› and 2 goals remain*) apply (simp add:par_cp_def (*‹par_cp ?P ?s ≡ {l. l ! 0 = (?P, ?s) ∧ l ∈ par_cptn}›*) cp_def (*‹cp ?P ?s ≡ {l. l ! 0 = (?P, ?s) ∧ l ∈ cptn}›*)) (*top goal: ‹⋀x. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); x ∈ par_cp xs s⟧ ⟹ ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ∈ cp (xs ! i) s) ∧ x ∝ clist› and 2 goals remain*) apply (case_tac x) (*top goal: ‹⋀x. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); x ! 0 = (xs, s) ∧ x ∈ par_cptn⟧ ⟹ ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn) ∧ x ∝ clist› and 2 goals remain*) apply (force elim:par_cptn.cases (*‹⟦?a ∈ par_cptn; ⋀P s. ?a = [(P, s)] ⟹ ?P; ⋀P t xs s. ⟦?a = (P, s) # (P, t) # xs; (P, t) # xs ∈ par_cptn⟧ ⟹ ?P; ⋀P s Q t xs. ⟦?a = (P, s) # (Q, t) # xs; (P, s) -pc→ (Q, t); (Q, t) # xs ∈ par_cptn⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*top goal: ‹⋀x. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); x ! 0 = (xs, s) ∧ x ∈ par_cptn; x = []⟧ ⟹ ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn) ∧ x ∝ clist› and 3 goals remain*) apply simp (*top goal: ‹⋀x a list. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); x ! 0 = (xs, s) ∧ x ∈ par_cptn; x = a # list⟧ ⟹ ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn) ∧ x ∝ clist› and 2 goals remain*) apply (rename_tac a list) (*top goal: ‹⋀x list. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); ∃clist. length clist = length xs ∧ (xs, s) # list ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn); x = (xs, s) # list⟧ ⟹ ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn) ∧ (xs, s) # list ∝ clist› and 2 goals remain*) apply (erule_tac x="list" in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀(a::('a com option list × 'a) list) list::('a com option list × 'a) list. ⟦(xs::'a com option list) ≠ []; ∀ys::('a com option list × 'a) list. ((xs, s::'a) # ys ∈ par_cptn) = (∃clist::('a com option × 'a) list list. length clist = length xs ∧ (xs, s) # ys ∝ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); ∃clist::('a com option × 'a) list list. length clist = length xs ∧ (xs, s) # list ∝ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn); a = (xs, s) # list⟧ ⟹ ∃clist::('a com option × 'a) list list. length clist = length xs ∧ (∀i<length clist. clist ! i ! (0::nat) = (xs ! i, s) ∧ clist ! i ∈ cptn) ∧ (xs, s) # list ∝ clist› and 2 goals remain*) apply clarify (*top goal: ‹⋀a list. ⟦xs ≠ []; ∃clist. length clist = length xs ∧ (xs, s) # list ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn); a = (xs, s) # list; ((xs, s) # list ∈ par_cptn) = (∃clist. length clist = length xs ∧ (xs, s) # list ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn))⟧ ⟹ ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn) ∧ (xs, s) # list ∝ clist› and 2 goals remain*) apply simp (*top goal: ‹⋀(a::('a com option list × 'a) list) (list::('a com option list × 'a) list) clist::('a com option × 'a) list list. ⟦(xs::'a com option list) ≠ []; ((xs, s::'a) # list ∈ par_cptn) = (∃clist::('a com option × 'a) list list. length clist = length xs ∧ (xs, s) # list ∝ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); length clist = length xs; (xs, s) # list ∝ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist); ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn⟧ ⟹ ∃clist::('a com option × 'a) list list. length clist = length xs ∧ (∀i<length clist. clist ! i ! (0::nat) = (xs ! i, s) ∧ clist ! i ∈ cptn) ∧ (xs, s) # list ∝ clist› and 2 goals remain*) apply (rule_tac x="map (λi. (fst i, s) # snd i) (zip xs clist)" in exI (*‹?P ?x ⟹ ∃x. ?P x›*), simp) (*top goal: ‹⋀list clist. ⟦xs ≠ []; ((xs, s) # list ∈ par_cptn) = (∃clist. length clist = length xs ∧ (xs, s) # list ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); length clist = length xs; (xs, s) # list ∝ map (λi. (fst i, s) # snd i) (zip xs clist); ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn⟧ ⟹ ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn) ∧ (xs, s) # list ∝ clist› and 2 goals remain*) apply (rule subsetI (*‹(⋀x. x ∈ ?A ⟹ x ∈ ?B) ⟹ ?A ⊆ ?B›*)) (*top goal: ‹⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn))⟧ ⟹ {c. ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ∈ cp (xs ! i) s) ∧ c ∝ clist} ⊆ par_cp xs s› and 1 goal remains*) apply clarify (*top goal: ‹⋀x. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); x ∈ {c. ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ∈ cp (xs ! i) s) ∧ c ∝ clist}⟧ ⟹ x ∈ par_cp xs s› and 1 goal remains*) apply (case_tac x) (*top goal: ‹⋀x clist. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); length clist = length xs; ∀i<length clist. clist ! i ∈ cp (xs ! i) s; x ∝ clist⟧ ⟹ x ∈ par_cp xs s› and 1 goal remains*) apply (erule_tac x=0 in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀(x::('a com option list × 'a) list) clist::('a com option × 'a) list list. ⟦(xs::'a com option list) ≠ []; ∀ys::('a com option list × 'a) list. ((xs, s::'a) # ys ∈ par_cptn) = (∃clist::('a com option × 'a) list list. length clist = length xs ∧ (xs, s) # ys ∝ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); length clist = length xs; ∀i<length clist. clist ! i ∈ cp (xs ! i) s; x ∝ clist; x = []⟧ ⟹ x ∈ par_cp xs s› and 2 goals remain*) apply (simp add:cp_def (*‹cp ?P ?s ≡ {l. l ! 0 = (?P, ?s) ∧ l ∈ cptn}›*) conjoin_def (*‹?c ∝ ?clist ≡ same_length ?c ?clist ∧ same_state ?c ?clist ∧ same_program ?c ?clist ∧ compat_label ?c ?clist›*) same_length_def (*‹same_length ?c ?clist ≡ ∀i<length ?clist. length (?clist ! i) = length ?c›*) same_program_def (*‹same_program ?c ?clist ≡ ∀j<length ?c. fst (?c ! j) = map (λx. fst (x ! j)) ?clist›*) same_state_def (*‹same_state ?c ?clist ≡ ∀i<length ?clist. ∀j<length ?c. snd (?c ! j) = snd (?clist ! i ! j)›*) compat_label_def (*‹compat_label ?c ?clist ≡ ∀j. Suc j < length ?c ⟶ ?c ! j -pc→ ?c ! Suc j ∧ (∃i<length ?clist. ?clist ! i ! j -c→ ?clist ! i ! Suc j ∧ (∀l<length ?clist. l ≠ i ⟶ ?clist ! l ! j -e→ ?clist ! l ! Suc j)) ∨ ?c ! j -pe→ ?c ! Suc j ∧ (∀i<length ?clist. ?clist ! i ! j -e→ ?clist ! i ! Suc j)›*)) (*top goal: ‹⋀x clist. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); length clist = length xs; x ∝ clist; x = []; 0 < length clist ⟶ clist ! 0 ∈ cp (xs ! 0) s⟧ ⟹ x ∈ par_cp xs s› and 2 goals remain*) apply clarify (*top goal: ‹⋀x clist. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (∀i. i < length xs ∧ i < length clist ⟶ length (clist ! i) = length ys) ∧ (∀i. i < length xs ∧ i < length clist ⟶ (∀j<Suc (length ys). snd (((xs, s) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j))) ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); length clist = length xs; ∀i<length xs. clist ! i = []; x = []; [] ! 0 = (xs ! 0, s) ∧ [] ∈ cptn⟧ ⟹ [] ∈ par_cp xs s› and 2 goals remain*) apply (erule cptn.cases (*‹⟦?a ∈ cptn; ⋀P s. ?a = [(P, s)] ⟹ ?P; ⋀P t xs s. ⟦?a = (P, s) # (P, t) # xs; (P, t) # xs ∈ cptn⟧ ⟹ ?P; ⋀P s Q t xs. ⟦?a = (P, s) # (Q, t) # xs; (P, s) -c→ (Q, t); (Q, t) # xs ∈ cptn⟧ ⟹ ?P⟧ ⟹ ?P›*), force, force, force) (*top goal: ‹⋀x clist. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (∀i. i < length xs ∧ i < length clist ⟶ length (clist ! i) = length ys) ∧ (∀i. i < length xs ∧ i < length clist ⟶ (∀j<Suc (length ys). snd (((xs, s) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j))) ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); length clist = length xs; ∀i<length xs. clist ! i = []; [] ! 0 = (xs ! 0, s); [] ∈ cptn⟧ ⟹ [] ∈ par_cp xs s› and 2 goals remain*) apply (simp add:par_cp_def (*‹par_cp ?P ?s ≡ {l. l ! 0 = (?P, ?s) ∧ l ∈ par_cptn}›*) conjoin_def (*‹?c ∝ ?clist ≡ same_length ?c ?clist ∧ same_state ?c ?clist ∧ same_program ?c ?clist ∧ compat_label ?c ?clist›*) same_length_def (*‹same_length ?c ?clist ≡ ∀i<length ?clist. length (?clist ! i) = length ?c›*) same_program_def (*‹same_program ?c ?clist ≡ ∀j<length ?c. fst (?c ! j) = map (λx. fst (x ! j)) ?clist›*) same_state_def (*‹same_state ?c ?clist ≡ ∀i<length ?clist. ∀j<length ?c. snd (?c ! j) = snd (?clist ! i ! j)›*) compat_label_def (*‹compat_label ?c ?clist ≡ ∀j. Suc j < length ?c ⟶ ?c ! j -pc→ ?c ! Suc j ∧ (∃i<length ?clist. ?clist ! i ! j -c→ ?clist ! i ! Suc j ∧ (∀l<length ?clist. l ≠ i ⟶ ?clist ! l ! j -e→ ?clist ! l ! Suc j)) ∨ ?c ! j -pe→ ?c ! Suc j ∧ (∀i<length ?clist. ?clist ! i ! j -e→ ?clist ! i ! Suc j)›*)) (*top goal: ‹⋀x clist a list. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); length clist = length xs; ∀i<length clist. clist ! i ∈ cp (xs ! i) s; x ∝ clist; x = a # list⟧ ⟹ x ∈ par_cp xs s› and 1 goal remains*) apply clarify (*top goal: ‹⋀x clist a list. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (∀i. i < length xs ∧ i < length clist ⟶ length (clist ! i) = length ys) ∧ (∀i. i < length xs ∧ i < length clist ⟶ (∀j<Suc (length ys). snd (((xs, s) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j))) ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; (∀i<length xs. length (clist ! i) = Suc (length list)) ∧ (∀i<length xs. ∀j<Suc (length list). snd ((a # list) ! j) = snd (clist ! i ! j)) ∧ (∀j<Suc (length list). fst ((a # list) ! j) = map (λx. fst (x ! j)) clist) ∧ (∀j<length list. (a # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ (a # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j)); x = a # list⟧ ⟹ a = (xs, s) ∧ a # list ∈ par_cptn› and 1 goal remains*) apply (erule_tac x=0 and P="λj. H j ⟶ (length (s j) = t)" for H s t in all_dupE (*‹⟦∀x. ?P x; ⟦?P ?x; ∀x. ?P x⟧ ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀(x::('a com option list × 'a) list) (clist::('a com option × 'a) list list) (a::'a com option list) (b::'a) list::('a com option list × 'a) list. ⟦(xs::'a com option list) ≠ []; ∀ys::('a com option list × 'a) list. ((xs, s::'a) # ys ∈ par_cptn) = (∃clist::('a com option × 'a) list list. length clist = length xs ∧ (∀i::nat. i < length xs ∧ i < length clist ⟶ length (clist ! i) = length ys) ∧ (∀i::nat. i < length xs ∧ i < length clist ⟶ (∀j<Suc (length ys). snd (((xs, s) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j))) ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map ((λx::('a com option × 'a) list. fst (x ! j)) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l::nat. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i::nat. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. length (clist ! i) = Suc (length list); ∀i<length xs. ∀j<Suc (length list). snd (((a, b) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((a, b) # list) ! j) = map (λx::('a com option × 'a) list. fst (x ! j)) clist; ∀j<length list. ((a, b) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((a, b) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j)⟧ ⟹ (a, b) = (xs, s) ∧ (a, b) # list ∈ par_cptn› and 1 goal remains*) apply (subgoal_tac "a = xs") (*top goal: ‹⋀x clist a b list. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (∀i. i < length xs ∧ i < length clist ⟶ length (clist ! i) = length ys) ∧ (∀i. i < length xs ∧ i < length clist ⟶ (∀j<Suc (length ys). snd (((xs, s) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j))) ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((a, b) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((a, b) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((a, b) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((a, b) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); 0 < length xs ⟶ length (clist ! 0) = Suc (length list); ∀x<length xs. length (clist ! x) = Suc (length list)⟧ ⟹ (a, b) = (xs, s) ∧ (a, b) # list ∈ par_cptn› and 1 goal remains*) apply (subgoal_tac "b = s", simp) (*top goal: ‹⋀x clist a b list. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (∀i. i < length xs ∧ i < length clist ⟶ length (clist ! i) = length ys) ∧ (∀i. i < length xs ∧ i < length clist ⟶ (∀j<Suc (length ys). snd (((xs, s) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j))) ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((a, b) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((a, b) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((a, b) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((a, b) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); 0 < length xs ⟶ length (clist ! 0) = Suc (length list); ∀x<length xs. length (clist ! x) = Suc (length list); a = xs⟧ ⟹ (a, b) = (xs, s) ∧ (a, b) # list ∈ par_cptn› and 2 goals remain*) prefer 3 (*top goal: ‹⋀x clist a b list. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (∀i. i < length xs ∧ i < length clist ⟶ length (clist ! i) = length ys) ∧ (∀i. i < length xs ∧ i < length clist ⟶ (∀j<Suc (length ys). snd (((xs, s) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j))) ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((a, b) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((a, b) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((a, b) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((a, b) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); 0 < length xs ⟶ length (clist ! 0) = Suc (length list); ∀x<length xs. length (clist ! x) = Suc (length list)⟧ ⟹ a = xs› and 3 goals remain*) apply (erule_tac x=0 and P="λj. H j ⟶ (fst (s j))=((t j))" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀x clist a b list. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (∀i. i < length xs ∧ i < length clist ⟶ length (clist ! i) = length ys) ∧ (∀i. i < length xs ∧ i < length clist ⟶ (∀j<Suc (length ys). snd (((xs, s) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j))) ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((a, b) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((a, b) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((a, b) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((a, b) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); 0 < length xs ⟶ length (clist ! 0) = Suc (length list); ∀x<length xs. length (clist ! x) = Suc (length list)⟧ ⟹ a = xs› and 3 goals remain*) apply (simp add:cp_def (*‹cp ?P ?s ≡ {l. l ! 0 = (?P, ?s) ∧ l ∈ cptn}›*)) (*top goal: ‹⋀x clist a b list. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (∀i. i < length xs ∧ i < length clist ⟶ length (clist ! i) = length ys) ∧ (∀i. i < length xs ∧ i < length clist ⟶ (∀j<Suc (length ys). snd (((xs, s) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j))) ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((a, b) # list) ! j) = snd (clist ! i ! j); ∀j<length list. ((a, b) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((a, b) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); 0 < length xs ⟶ length (clist ! 0) = Suc (length list); ∀x<length xs. length (clist ! x) = Suc (length list); 0 < Suc (length list) ⟶ fst (((a, b) # list) ! 0) = map (λx. fst (x ! 0)) clist⟧ ⟹ a = xs› and 3 goals remain*) apply (rule nth_equalityI (*‹⟦length ?xs = length ?ys; ⋀i. i < length ?xs ⟹ ?xs ! i = ?ys ! i⟧ ⟹ ?xs = ?ys›*), simp, simp) (*top goal: ‹⋀clist a b list. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (∀i. i < length xs ∧ i < length clist ⟶ length (clist ! i) = length ys) ∧ (∀i. i < length xs ∧ i < length clist ⟶ (∀j<Suc (length ys). snd (((xs, s) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j))) ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. ∀j<Suc (length list). snd (((map (λx. fst (x ! 0)) clist, b) # list) ! j) = snd (clist ! i ! j); ∀j<length list. ((map (λx. fst (x ! 0)) clist, b) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((map (λx. fst (x ! 0)) clist, b) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); a = map (λx. fst (x ! 0)) clist⟧ ⟹ map (λx. fst (x ! 0)) clist = xs› and 3 goals remain*) prefer 2 (*top goal: ‹⋀x clist a b list. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (∀i. i < length xs ∧ i < length clist ⟶ length (clist ! i) = length ys) ∧ (∀i. i < length xs ∧ i < length clist ⟶ (∀j<Suc (length ys). snd (((xs, s) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j))) ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((a, b) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((a, b) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((a, b) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((a, b) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); 0 < length xs ⟶ length (clist ! 0) = Suc (length list); ∀x<length xs. length (clist ! x) = Suc (length list); a = xs⟧ ⟹ b = s› and 2 goals remain*) apply (erule_tac x=0 in allE (*‹⟦∀x::?'a. (?P::?'a ⇒ bool) x; ?P (?x::?'a) ⟹ ?R::bool⟧ ⟹ ?R›*)) (*top goal: ‹⋀x clist a b list. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (∀i. i < length xs ∧ i < length clist ⟶ length (clist ! i) = length ys) ∧ (∀i. i < length xs ∧ i < length clist ⟶ (∀j<Suc (length ys). snd (((xs, s) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j))) ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((a, b) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((a, b) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((a, b) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((a, b) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); 0 < length xs ⟶ length (clist ! 0) = Suc (length list); ∀x<length xs. length (clist ! x) = Suc (length list); a = xs⟧ ⟹ b = s› and 2 goals remain*) apply (simp add:cp_def (*‹cp ?P ?s ≡ {l. l ! 0 = (?P, ?s) ∧ l ∈ cptn}›*)) (*top goal: ‹⋀x clist a b list. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (∀i. i < length xs ∧ i < length clist ⟶ length (clist ! i) = length ys) ∧ (∀i. i < length xs ∧ i < length clist ⟶ (∀j<Suc (length ys). snd (((xs, s) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j))) ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); length clist = length xs; ∀i<length xs. ∀j<Suc (length list). snd (((a, b) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((a, b) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((a, b) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((a, b) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); 0 < length xs ⟶ length (clist ! 0) = Suc (length list); ∀x<length xs. length (clist ! x) = Suc (length list); a = xs; 0 < length xs ⟶ clist ! 0 ∈ cp (xs ! 0) s⟧ ⟹ b = s› and 2 goals remain*) apply (erule_tac x=0 and P="λj. H j ⟶ (∀i. T i ⟶ (snd (d j i))=(snd (e j i)))" for H T d e in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), simp) (*top goal: ‹⋀clist a b list. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (∀i. i < length xs ∧ i < length clist ⟶ length (clist ! i) = length ys) ∧ (∀i. i < length xs ∧ i < length clist ⟶ (∀j<Suc (length ys). snd (((xs, s) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j))) ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); length clist = length xs; ∀i<length xs. ∀j<Suc (length list). snd (((xs, b) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, b) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, b) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, b) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); a = xs; clist ! 0 ! 0 = (xs ! 0, s) ∧ clist ! 0 ∈ cptn⟧ ⟹ b = s› and 2 goals remain*) apply (erule_tac x=0 and P="λj. H j ⟶ (snd (d j))=(snd (e j))" for H d e in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), simp) (*top goal: ‹⋀clist a b list. ⟦xs ≠ []; ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (∀i. i < length xs ∧ i < length clist ⟶ length (clist ! i) = length ys) ∧ (∀i. i < length xs ∧ i < length clist ⟶ (∀j<Suc (length ys). snd (((xs, s) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j))) ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); length clist = length xs; ∀j<Suc (length list). fst (((xs, b) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, b) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, b) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); a = xs; clist ! 0 ! 0 = (xs ! 0, s) ∧ clist ! 0 ∈ cptn; ∀i<Suc (length list). snd (((xs, b) # list) ! i) = snd (clist ! 0 ! i)⟧ ⟹ b = s› and 2 goals remain*) apply (erule_tac x=list in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀(clist::('a::type com option × 'a::type) list list) (a::'a::type com option list) (b::'a::type) list::('a::type com option list × 'a::type) list. ⟦(xs::'a::type com option list) ≠ []; ∀ys::('a::type com option list × 'a::type) list. ((xs, s::'a::type) # ys ∈ par_cptn) = (∃clist::('a::type com option × 'a::type) list list. length clist = length xs ∧ (∀i::nat. i < length xs ∧ i < length clist ⟶ length (clist ! i) = length ys) ∧ (∀i::nat. i < length xs ∧ i < length clist ⟶ (∀j<Suc (length ys). snd (((xs, s) # ys) ! j) = snd (((xs ! i, s) # clist ! i) ! j))) ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map ((λx::('a::type com option × 'a::type) list. fst (x ! j)) ∘ (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. i < length clist ∧ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l::nat. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i::nat. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)); length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx::('a::type com option × 'a::type) list. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); a = xs; b = s⟧ ⟹ ∃clista::('a::type com option × 'a::type) list list. length clista = length xs ∧ (∀i::nat. i < length xs ∧ i < length clista ⟶ length (clista ! i) = length list) ∧ (∀i::nat. i < length xs ∧ i < length clista ⟶ (∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (((xs ! i, s) # clista ! i) ! j))) ∧ (∀j<Suc (length list). map (λx::('a::type com option × 'a::type) list. fst (x ! j)) clist = map ((λx::('a::type com option × 'a::type) list. fst (x ! j)) ∘ (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i)) (zip xs clista)) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. i < length clista ∧ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clista) ! i ! j -c→ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clista) ! i ! Suc j ∧ (∀l::nat. l < length xs ∧ l < length clista ⟶ l ≠ i ⟶ ((xs ! l, s) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i::nat. i < length xs ∧ i < length clista ⟶ ((xs ! i, s) # clista ! i) ! j -e→ clista ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clista ! i ∈ cptn)› and 1 goal remains*) apply (rule_tac x="map tl clist" in exI (*‹?P ?x ⟹ ∃x. ?P x›*), simp) (*top goal: ‹⋀clist a b list. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); a = xs; b = s; ((xs, s) # list ∈ par_cptn) = (∃clist. length clist = length xs ∧ (∀i. i < length xs ∧ i < length clist ⟶ length (clist ! i) = length list) ∧ (∀i. i < length xs ∧ i < length clist ⟶ (∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (((xs ! i, s) # clist ! i) ! j))) ∧ (∀j<Suc (length list). fst (((xs, s) # list) ! j) = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clist)) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. i < length clist ∧ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clist) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clist ⟶ l ≠ i ⟶ ((xs ! l, s) # clist ! l) ! j -e→ clist ! l ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i. i < length xs ∧ i < length clist ⟶ ((xs ! i, s) # clist ! i) ! j -e→ clist ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn))⟧ ⟹ ∃clista. length clista = length xs ∧ (∀i. i < length xs ∧ i < length clista ⟶ length (clista ! i) = length list) ∧ (∀i. i < length xs ∧ i < length clista ⟶ (∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (((xs ! i, s) # clista ! i) ! j))) ∧ (∀j<Suc (length list). map (λx. fst (x ! j)) clist = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clista)) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. i < length clista ∧ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clista ⟶ l ≠ i ⟶ ((xs ! l, s) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i. i < length xs ∧ i < length clista ⟶ ((xs ! i, s) # clista ! i) ! j -e→ clista ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clista ! i ∈ cptn)› and 1 goal remains*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*top goal: ‹⋀clist a b list. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); a = xs; b = s; ((xs, s) # list ∈ par_cptn) = (∃clista. length clista = length xs ∧ (∀i. i < length xs ∧ i < length clista ⟶ length (clista ! i) = length list) ∧ (∀i. i < length xs ∧ i < length clista ⟶ (∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (((xs ! i, s) # clista ! i) ! j))) ∧ (∀j<Suc (length list). map (λx. fst (x ! j)) clist = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clista)) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. i < length clista ∧ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clista ⟶ l ≠ i ⟶ ((xs ! l, s) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i. i < length xs ∧ i < length clista ⟶ ((xs ! i, s) # clista ! i) ! j -e→ clista ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clista ! i ∈ cptn))⟧ ⟹ (∀i<length xs. ∀j<Suc (length list). snd (clist ! i ! j) = snd (((xs ! i, s) # tl (clist ! i)) ! j)) ∧ (∀j<Suc (length list). map (λx. fst (x ! j)) clist = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs (map tl clist))) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. ((xs ! i, s) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j)) ∧ (∀i<length xs. (xs ! i, s) # tl (clist ! i) ∈ cptn)› and 1 goal remains*) apply clarify (*top goal: ‹⋀clist a b list. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); a = xs; b = s; ((xs, s) # list ∈ par_cptn) = (∃clista. length clista = length xs ∧ (∀i. i < length xs ∧ i < length clista ⟶ length (clista ! i) = length list) ∧ (∀i. i < length xs ∧ i < length clista ⟶ (∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (((xs ! i, s) # clista ! i) ! j))) ∧ (∀j<Suc (length list). map (λx. fst (x ! j)) clist = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clista)) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. i < length clista ∧ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clista ⟶ l ≠ i ⟶ ((xs ! l, s) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i. i < length xs ∧ i < length clista ⟶ ((xs ! i, s) # clista ! i) ! j -e→ clista ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clista ! i ∈ cptn))⟧ ⟹ ∀i<length xs. ∀j<Suc (length list). snd (clist ! i ! j) = snd (((xs ! i, s) # tl (clist ! i)) ! j)› and 2 goals remain*) apply (case_tac j, simp) (*top goal: ‹⋀(clist::('a com option × 'a) list list) (a::'a com option list) (b::'a) (list::('a com option list × 'a) list) (i::nat) j::nat. ⟦(xs::'a com option list) ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) (s::'a); ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx::('a com option × 'a) list. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); ((xs, s) # list ∈ par_cptn) = (∃clista::('a com option × 'a) list list. length clista = length xs ∧ (∀i::nat. i < length xs ∧ i < length clista ⟶ length (clista ! i) = length list) ∧ (∀i::nat. i < length xs ∧ i < length clista ⟶ (∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (((xs ! i, s) # clista ! i) ! j))) ∧ (∀j<Suc (length list). map (λx::('a com option × 'a) list. fst (x ! j)) clist = map ((λx::('a com option × 'a) list. fst (x ! j)) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clista)) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. i < length clista ∧ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clista) ! i ! j -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clista) ! i ! Suc j ∧ (∀l::nat. l < length xs ∧ l < length clista ⟶ l ≠ i ⟶ ((xs ! l, s) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i::nat. i < length xs ∧ i < length clista ⟶ ((xs ! i, s) # clista ! i) ! j -e→ clista ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clista ! i ∈ cptn)); i < length xs; j < Suc (length list)⟧ ⟹ snd (clist ! i ! j) = snd (((xs ! i, s) # tl (clist ! i)) ! j)› and 2 goals remain*) apply (erule_tac x=i in allE (*‹⟦∀x::?'a. (?P::?'a ⇒ bool) x; ?P (?x::?'a) ⟹ ?R::bool⟧ ⟹ ?R›*), erule impE (*‹⟦(?P::bool) ⟶ (?Q::bool); ?P; ?Q ⟹ ?R::bool⟧ ⟹ ?R›*), assumption, erule_tac x="0" and P="λj. H j ⟶ (snd (d j))=(snd (e j))" for H d e in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), simp) (*top goal: ‹⋀clist list i j. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); ((xs, s) # list ∈ par_cptn) = (∃clista. length clista = length xs ∧ (∀i. i < length xs ∧ i < length clista ⟶ length (clista ! i) = length list) ∧ (∀ia. ia < length xs ∧ ia < length clista ⟶ (∀j<Suc (length list). snd (clist ! i ! j) = snd (((xs ! ia, s) # clista ! ia) ! j))) ∧ (∀j<Suc (length list). map (λx. fst (x ! j)) clist = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clista)) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. i < length clista ∧ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clista ⟶ l ≠ i ⟶ ((xs ! l, s) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i. i < length xs ∧ i < length clista ⟶ ((xs ! i, s) # clista ! i) ! j -e→ clista ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clista ! i ∈ cptn)); i < length xs; j = 0⟧ ⟹ snd (clist ! i ! 0) = s› and 3 goals remain*) apply (erule_tac x=i in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption, erule_tac x="Suc nat" and P="λj. H j ⟶ (snd (d j))=(snd (e j))" for H d e in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀clist a b list i j nat. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); ((xs, s) # list ∈ par_cptn) = (∃clista. length clista = length xs ∧ (∀i. i < length xs ∧ i < length clista ⟶ length (clista ! i) = length list) ∧ (∀i. i < length xs ∧ i < length clista ⟶ (∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (((xs ! i, s) # clista ! i) ! j))) ∧ (∀j<Suc (length list). map (λx. fst (x ! j)) clist = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clista)) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. i < length clista ∧ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clista ⟶ l ≠ i ⟶ ((xs ! l, s) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i. i < length xs ∧ i < length clista ⟶ ((xs ! i, s) # clista ! i) ! j -e→ clista ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clista ! i ∈ cptn)); i < length xs; j < Suc (length list); j = Suc nat⟧ ⟹ snd (clist ! i ! j) = snd (((xs ! i, s) # tl (clist ! i)) ! j)› and 2 goals remain*) apply (erule_tac x=i and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀clist a b list i j nat. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); ((xs, s) # list ∈ par_cptn) = (∃clista. length clista = length xs ∧ (∀i. i < length xs ∧ i < length clista ⟶ length (clista ! i) = length list) ∧ (∀i. i < length xs ∧ i < length clista ⟶ (∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (((xs ! i, s) # clista ! i) ! j))) ∧ (∀j<Suc (length list). map (λx. fst (x ! j)) clist = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clista)) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. i < length clista ∧ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clista ⟶ l ≠ i ⟶ ((xs ! l, s) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i. i < length xs ∧ i < length clista ⟶ ((xs ! i, s) # clista ! i) ! j -e→ clista ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clista ! i ∈ cptn)); i < length xs; j < Suc (length list); j = Suc nat; Suc nat < Suc (length list) ⟶ snd (((xs, s) # list) ! Suc nat) = snd (clist ! i ! Suc nat)⟧ ⟹ snd (clist ! i ! j) = snd (((xs ! i, s) # tl (clist ! i)) ! j)› and 2 goals remain*) apply (case_tac "clist!i", simp, simp) (*top goal: ‹⋀clist a b list i j nat. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ((xs, s) # list ∈ par_cptn) = (∃clista. length clista = length xs ∧ (∀i. i < length xs ∧ i < length clista ⟶ length (clista ! i) = length list) ∧ (∀i. i < length xs ∧ i < length clista ⟶ (∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (((xs ! i, s) # clista ! i) ! j))) ∧ (∀j<Suc (length list). map (λx. fst (x ! j)) clist = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clista)) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. i < length clista ∧ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clista ⟶ l ≠ i ⟶ ((xs ! l, s) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i. i < length xs ∧ i < length clista ⟶ ((xs ! i, s) # clista ! i) ! j -e→ clista ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clista ! i ∈ cptn)); i < length xs; j < Suc (length list); j = Suc nat; Suc nat < Suc (length list) ⟶ snd (((xs, s) # list) ! Suc nat) = snd (clist ! i ! Suc nat); i < length xs ⟶ length (clist ! i) = Suc (length list)⟧ ⟹ snd (clist ! i ! j) = snd (((xs ! i, s) # tl (clist ! i)) ! j)› and 2 goals remain*) apply (rule conjI (*‹⟦?P::bool; ?Q::bool⟧ ⟹ ?P ∧ ?Q›*)) (*top goal: ‹⋀clist a b list. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); a = xs; b = s; ((xs, s) # list ∈ par_cptn) = (∃clista. length clista = length xs ∧ (∀i. i < length xs ∧ i < length clista ⟶ length (clista ! i) = length list) ∧ (∀i. i < length xs ∧ i < length clista ⟶ (∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (((xs ! i, s) # clista ! i) ! j))) ∧ (∀j<Suc (length list). map (λx. fst (x ! j)) clist = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clista)) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. i < length clista ∧ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clista ⟶ l ≠ i ⟶ ((xs ! l, s) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i. i < length xs ∧ i < length clista ⟶ ((xs ! i, s) # clista ! i) ! j -e→ clista ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clista ! i ∈ cptn))⟧ ⟹ (∀j<Suc (length list). map (λx. fst (x ! j)) clist = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs (map tl clist))) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. ((xs ! i, s) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j)) ∧ (∀i<length xs. (xs ! i, s) # tl (clist ! i) ∈ cptn)› and 1 goal remains*) apply clarify (*top goal: ‹⋀(clist::('a com option × 'a) list list) (a::'a com option list) (b::'a) list::('a com option list × 'a) list. ⟦(xs::'a com option list) ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) (s::'a); ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx::('a com option × 'a) list. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); a = xs; b = s; ((xs, s) # list ∈ par_cptn) = (∃clista::('a com option × 'a) list list. length clista = length xs ∧ (∀i::nat. i < length xs ∧ i < length clista ⟶ length (clista ! i) = length list) ∧ (∀i::nat. i < length xs ∧ i < length clista ⟶ (∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (((xs ! i, s) # clista ! i) ! j))) ∧ (∀j<Suc (length list). map (λx::('a com option × 'a) list. fst (x ! j)) clist = map ((λx::('a com option × 'a) list. fst (x ! j)) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clista)) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. i < length clista ∧ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clista) ! i ! j -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clista) ! i ! Suc j ∧ (∀l::nat. l < length xs ∧ l < length clista ⟶ l ≠ i ⟶ ((xs ! l, s) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i::nat. i < length xs ∧ i < length clista ⟶ ((xs ! i, s) # clista ! i) ! j -e→ clista ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clista ! i ∈ cptn))⟧ ⟹ ∀j<Suc (length list). map (λx::('a com option × 'a) list. fst (x ! j)) clist = map ((λx::('a com option × 'a) list. fst (x ! j)) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs (map tl clist))› and 2 goals remain*) apply (rule nth_equalityI (*‹⟦length ?xs = length ?ys; ⋀i. i < length ?xs ⟹ ?xs ! i = ?ys ! i⟧ ⟹ ?xs = ?ys›*), simp, simp) (*top goal: ‹⋀clist a b list j. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); ((xs, s) # list ∈ par_cptn) = (∃clista. length clista = length xs ∧ (∀i. i < length xs ∧ i < length clista ⟶ length (clista ! i) = length list) ∧ (∀i. i < length xs ∧ i < length clista ⟶ (∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (((xs ! i, s) # clista ! i) ! j))) ∧ (∀j<Suc (length list). map (λx. fst (x ! j)) clist = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clista)) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. i < length clista ∧ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clista ⟶ l ≠ i ⟶ ((xs ! l, s) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i. i < length xs ∧ i < length clista ⟶ ((xs ! i, s) # clista ! i) ! j -e→ clista ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clista ! i ∈ cptn)); j < Suc (length list)⟧ ⟹ map (λx. fst (x ! j)) clist = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs (map tl clist))› and 2 goals remain*) apply (case_tac j) (*top goal: ‹⋀(clist::('a com option × 'a) list list) (list::('a com option list × 'a) list) (j::nat) i::nat. ⟦(xs::'a com option list) ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) (s::'a); ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx::('a com option × 'a) list. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); ((xs, s) # list ∈ par_cptn) = (∃clista::('a com option × 'a) list list. length clista = length xs ∧ (∀i::nat. i < length xs ∧ i < length clista ⟶ length (clista ! i) = length list) ∧ (∀ia::nat. ia < length xs ∧ ia < length clista ⟶ (∀j<Suc (length list). snd (clist ! i ! j) = snd (((xs ! ia, s) # clista ! ia) ! j))) ∧ (∀j<Suc (length list). map (λx::('a com option × 'a) list. fst (x ! j)) clist = map ((λx::('a com option × 'a) list. fst (x ! j)) ∘ (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i)) (zip xs clista)) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. i < length clista ∧ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clista) ! i ! j -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clista) ! i ! Suc j ∧ (∀l::nat. l < length xs ∧ l < length clista ⟶ l ≠ i ⟶ ((xs ! l, s) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i::nat. i < length xs ∧ i < length clista ⟶ ((xs ! i, s) # clista ! i) ! j -e→ clista ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clista ! i ∈ cptn)); j < Suc (length list); i < length xs⟧ ⟹ fst (clist ! i ! j) = fst (((xs ! i, s) # tl (clist ! i)) ! j)› and 2 goals remain*) apply clarify (*top goal: ‹⋀clist list j i. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); ((xs, s) # list ∈ par_cptn) = (∃clista. length clista = length xs ∧ (∀i. i < length xs ∧ i < length clista ⟶ length (clista ! i) = length list) ∧ (∀ia. ia < length xs ∧ ia < length clista ⟶ (∀j<Suc (length list). snd (clist ! i ! j) = snd (((xs ! ia, s) # clista ! ia) ! j))) ∧ (∀j<Suc (length list). map (λx. fst (x ! j)) clist = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clista)) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. i < length clista ∧ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clista ⟶ l ≠ i ⟶ ((xs ! l, s) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i. i < length xs ∧ i < length clista ⟶ ((xs ! i, s) # clista ! i) ! j -e→ clista ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clista ! i ∈ cptn)); j < Suc (length list); i < length xs; j = 0⟧ ⟹ fst (clist ! i ! j) = fst (((xs ! i, s) # tl (clist ! i)) ! j)› and 3 goals remain*) apply (erule_tac x=i in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀clist list j i. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); ((xs, s) # list ∈ par_cptn) = (∃clista. length clista = length xs ∧ (∀i. i < length xs ∧ i < length clista ⟶ length (clista ! i) = length list) ∧ (∀ia. ia < length xs ∧ ia < length clista ⟶ (∀j<Suc (length list). snd (clist ! i ! j) = snd (((xs ! ia, s) # clista ! ia) ! j))) ∧ (∀j<Suc (length list). map (λx. fst (x ! j)) clist = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clista)) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. i < length clista ∧ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clista ⟶ l ≠ i ⟶ ((xs ! l, s) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i. i < length xs ∧ i < length clista ⟶ ((xs ! i, s) # clista ! i) ! j -e→ clista ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clista ! i ∈ cptn)); 0 < Suc (length list); i < length xs⟧ ⟹ fst (clist ! i ! 0) = fst (((xs ! i, s) # tl (clist ! i)) ! 0)› and 3 goals remain*) apply (simp add:cp_def (*‹cp ?P ?s ≡ {l. l ! 0 = (?P, ?s) ∧ l ∈ cptn}›*)) (*top goal: ‹⋀clist list j i. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); ((xs, s) # list ∈ par_cptn) = (∃clista. length clista = length xs ∧ (∀i. i < length xs ∧ i < length clista ⟶ length (clista ! i) = length list) ∧ (∀ia. ia < length xs ∧ ia < length clista ⟶ (∀j<Suc (length list). snd (clist ! i ! j) = snd (((xs ! ia, s) # clista ! ia) ! j))) ∧ (∀j<Suc (length list). map (λx. fst (x ! j)) clist = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clista)) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. i < length clista ∧ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clista ⟶ l ≠ i ⟶ ((xs ! l, s) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i. i < length xs ∧ i < length clista ⟶ ((xs ! i, s) # clista ! i) ! j -e→ clista ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clista ! i ∈ cptn)); 0 < Suc (length list); i < length xs; i < length xs ⟶ clist ! i ∈ cp (xs ! i) s⟧ ⟹ fst (clist ! i ! 0) = fst (((xs ! i, s) # tl (clist ! i)) ! 0)› and 3 goals remain*) apply clarify (*top goal: ‹⋀clist list j i nat. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); ((xs, s) # list ∈ par_cptn) = (∃clista. length clista = length xs ∧ (∀i. i < length xs ∧ i < length clista ⟶ length (clista ! i) = length list) ∧ (∀ia. ia < length xs ∧ ia < length clista ⟶ (∀j<Suc (length list). snd (clist ! i ! j) = snd (((xs ! ia, s) # clista ! ia) ! j))) ∧ (∀j<Suc (length list). map (λx. fst (x ! j)) clist = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clista)) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. i < length clista ∧ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clista ⟶ l ≠ i ⟶ ((xs ! l, s) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i. i < length xs ∧ i < length clista ⟶ ((xs ! i, s) # clista ! i) ! j -e→ clista ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clista ! i ∈ cptn)); j < Suc (length list); i < length xs; j = Suc nat⟧ ⟹ fst (clist ! i ! j) = fst (((xs ! i, s) # tl (clist ! i)) ! j)› and 2 goals remain*) apply simp (*top goal: ‹⋀clist list j i nat. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); ((xs, s) # list ∈ par_cptn) = (∃clista. length clista = length xs ∧ (∀i. i < length xs ∧ i < length clista ⟶ length (clista ! i) = length list) ∧ (∀ia. ia < length xs ∧ ia < length clista ⟶ (∀j<Suc (length list). snd (clist ! i ! j) = snd (((xs ! ia, s) # clista ! ia) ! j))) ∧ (∀j<Suc (length list). map (λx. fst (x ! j)) clist = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clista)) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. i < length clista ∧ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clista ⟶ l ≠ i ⟶ ((xs ! l, s) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i. i < length xs ∧ i < length clista ⟶ ((xs ! i, s) # clista ! i) ! j -e→ clista ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clista ! i ∈ cptn)); i < length xs; nat < length list⟧ ⟹ fst (clist ! i ! Suc nat) = fst (((xs ! i, s) # tl (clist ! i)) ! Suc nat)› and 2 goals remain*) apply (erule_tac x=i and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀clist list i nat. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); ((xs, s) # list ∈ par_cptn) = (∃clista. length clista = length xs ∧ (∀i. i < length xs ∧ i < length clista ⟶ length (clista ! i) = length list) ∧ (∀ia. ia < length xs ∧ ia < length clista ⟶ (∀j<Suc (length list). snd (clist ! i ! j) = snd (((xs ! ia, s) # clista ! ia) ! j))) ∧ (∀j<Suc (length list). map (λx. fst (x ! j)) clist = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clista)) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. i < length clista ∧ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clista ⟶ l ≠ i ⟶ ((xs ! l, s) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i. i < length xs ∧ i < length clista ⟶ ((xs ! i, s) # clista ! i) ! j -e→ clista ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clista ! i ∈ cptn)); i < length xs; nat < length list⟧ ⟹ fst (clist ! i ! Suc nat) = fst (tl (clist ! i) ! nat)› and 2 goals remain*) apply (case_tac "clist!i", simp, simp) (*top goal: ‹⋀clist list i nat. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ((xs, s) # list ∈ par_cptn) = (∃clista. length clista = length xs ∧ (∀i. i < length xs ∧ i < length clista ⟶ length (clista ! i) = length list) ∧ (∀ia. ia < length xs ∧ ia < length clista ⟶ (∀j<Suc (length list). snd (clist ! i ! j) = snd (((xs ! ia, s) # clista ! ia) ! j))) ∧ (∀j<Suc (length list). map (λx. fst (x ! j)) clist = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clista)) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. i < length clista ∧ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clista ⟶ l ≠ i ⟶ ((xs ! l, s) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i. i < length xs ∧ i < length clista ⟶ ((xs ! i, s) # clista ! i) ! j -e→ clista ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clista ! i ∈ cptn)); i < length xs; nat < length list; i < length xs ⟶ length (clist ! i) = Suc (length list)⟧ ⟹ fst (clist ! i ! Suc nat) = fst (tl (clist ! i) ! nat)› and 2 goals remain*) apply (thin_tac "H = (∃i. J i)" for H J) (*top goal: ‹⋀clist a b list. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); a = xs; b = s; ((xs, s) # list ∈ par_cptn) = (∃clista. length clista = length xs ∧ (∀i. i < length xs ∧ i < length clista ⟶ length (clista ! i) = length list) ∧ (∀i. i < length xs ∧ i < length clista ⟶ (∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (((xs ! i, s) # clista ! i) ! j))) ∧ (∀j<Suc (length list). map (λx. fst (x ! j)) clist = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs clista)) ∧ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. i < length clista ∧ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs clista) ! i ! Suc j ∧ (∀l. l < length xs ∧ l < length clista ⟶ l ≠ i ⟶ ((xs ! l, s) # clista ! l) ! j -e→ clista ! l ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i. i < length xs ∧ i < length clista ⟶ ((xs ! i, s) # clista ! i) ! j -e→ clista ! i ! j)) ∧ (∀i<length xs. (xs ! i, s) # clista ! i ∈ cptn))⟧ ⟹ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. ((xs ! i, s) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j)) ∧ (∀i<length xs. (xs ! i, s) # tl (clist ! i) ∈ cptn)› and 1 goal remains*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*top goal: ‹⋀clist a b list. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); a = xs; b = s⟧ ⟹ (∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. ((xs ! i, s) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j)) ∧ (∀i<length xs. (xs ! i, s) # tl (clist ! i) ∈ cptn)› and 1 goal remains*) apply clarify (*top goal: ‹⋀(clist::('a com option × 'a) list list) (a::'a com option list) (b::'a) list::('a com option list × 'a) list. ⟦(xs::'a com option list) ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) (s::'a); ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx::('a com option × 'a) list. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); a = xs; b = s⟧ ⟹ ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! j -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. ((xs ! i, s) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j)› and 2 goals remain*) apply (erule_tac x=j in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption, erule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀clist a b list j. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); j < length list; ¬ (((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. ((xs ! i, s) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j))⟧ ⟹ ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j))› and 2 goals remain*) apply clarify (*top goal: ‹⋀(clist::('a::type com option × 'a::type) list list) (a::'a::type com option list) (b::'a::type) (list::('a::type com option list × 'a::type) list) j::nat. ⟦(xs::'a::type com option list) ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) (s::'a::type); ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx::('a::type com option × 'a::type) list. fst (x ! j)) clist; ∀x<length xs. length (clist ! x) = Suc (length list); j < length list; ¬ (((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. ((xs ! i, s) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j)); ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j))⟧ ⟹ ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! j -c→ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j))› and 3 goals remain*) apply (rule_tac x=i in exI (*‹?P ?x ⟹ ∃x. ?P x›*), simp) (*top goal: ‹⋀clist a b list j i. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀x<length xs. length (clist ! x) = Suc (length list); j < length list; ¬ (((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. ((xs ! i, s) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j)); ((xs, s) # list) ! j -pc→ list ! j; i < length xs; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j⟧ ⟹ ∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)› and 3 goals remain*) apply (case_tac j, simp) (*top goal: ‹⋀clist list j i. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀x<length xs. length (clist ! x) = Suc (length list); j < length list; ((xs, s) # list) ! j -pe→ list ! j ⟶ (∃i<length xs. (((xs ! i, s) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); ((xs, s) # list) ! j -pc→ list ! j; i < length xs; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j⟧ ⟹ ((xs ! i, s) # tl (clist ! i)) ! j -c→ tl (clist ! i) ! j ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)› and 3 goals remain*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*top goal: ‹⋀clist list j i. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀x<length xs. length (clist ! x) = Suc (length list); list ≠ []; (xs, s) -pe→ list ! 0 ⟶ (∃i<length xs. ((xs ! i, s), tl (clist ! i) ! 0) ∉ etran); (xs, s) -pc→ list ! 0; i < length xs; clist ! i ! 0 -c→ clist ! i ! Suc 0; ∀l<length xs. l ≠ i ⟶ clist ! l ! 0 -e→ clist ! l ! Suc 0; j = 0⟧ ⟹ (xs ! i, s) -c→ tl (clist ! i) ! 0 ∧ (∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ tl (clist ! l) ! 0)› and 4 goals remain*) apply (erule_tac x=i in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀clist list j i. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀x<length xs. length (clist ! x) = Suc (length list); list ≠ []; (xs, s) -pe→ list ! 0 ⟶ (∃i<length xs. ((xs ! i, s), tl (clist ! i) ! 0) ∉ etran); (xs, s) -pc→ list ! 0; i < length xs; clist ! i ! 0 -c→ clist ! i ! Suc 0; ∀l<length xs. l ≠ i ⟶ clist ! l ! 0 -e→ clist ! l ! Suc 0; j = 0⟧ ⟹ (xs ! i, s) -c→ tl (clist ! i) ! 0› and 5 goals remain*) apply (simp add:cp_def (*‹cp ?P ?s ≡ {l. l ! 0 = (?P, ?s) ∧ l ∈ cptn}›*)) (*top goal: ‹⋀clist list j i. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀x<length xs. length (clist ! x) = Suc (length list); list ≠ []; (xs, s) -pe→ list ! 0 ⟶ (∃i<length xs. ((xs ! i, s), tl (clist ! i) ! 0) ∉ etran); (xs, s) -pc→ list ! 0; i < length xs; clist ! i ! 0 -c→ clist ! i ! Suc 0; ∀l<length xs. l ≠ i ⟶ clist ! l ! 0 -e→ clist ! l ! Suc 0; j = 0; i < length xs ⟶ clist ! i ∈ cp (xs ! i) s⟧ ⟹ (xs ! i, s) -c→ tl (clist ! i) ! 0› and 5 goals remain*) apply (erule_tac x=i and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x::?'a. (?P::?'a ⇒ bool) x; ?P (?x::?'a) ⟹ ?R::bool⟧ ⟹ ?R›*)) (*top goal: ‹⋀clist list j i. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀x<length xs. length (clist ! x) = Suc (length list); list ≠ []; (xs, s) -pe→ list ! 0 ⟶ (∃i<length xs. ((xs ! i, s), tl (clist ! i) ! 0) ∉ etran); (xs, s) -pc→ list ! 0; i < length xs; (xs ! i, s) -c→ clist ! i ! Suc 0; ∀l<length xs. l ≠ i ⟶ clist ! l ! 0 -e→ clist ! l ! Suc 0; j = 0; clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn⟧ ⟹ (xs ! i, s) -c→ tl (clist ! i) ! 0› and 5 goals remain*) apply (case_tac "clist!i", simp, simp) (*top goal: ‹⋀(clist::('a com option × 'a) list list) (list::('a com option list × 'a) list) (j::nat) i::nat. ⟦(xs::'a com option list) ≠ []; length clist = length xs; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s::'a) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx::('a com option × 'a) list. fst (x ! j)) clist; list ≠ []; (xs, s) -pe→ list ! (0::nat) ⟶ (∃i<length xs. ((xs ! i, s), tl (clist ! i) ! (0::nat)) ∉ etran); (xs, s) -pc→ list ! (0::nat); i < length xs; (xs ! i, s) -c→ clist ! i ! Suc (0::nat); ∀l<length xs. l ≠ i ⟶ clist ! l ! (0::nat) -e→ clist ! l ! Suc (0::nat); j = (0::nat); clist ! i ! (0::nat) = (xs ! i, s) ∧ clist ! i ∈ cptn; i < length xs ⟶ length (clist ! i) = Suc (length list)⟧ ⟹ (xs ! i, s) -c→ tl (clist ! i) ! (0::nat)› and 5 goals remain*) apply clarify (*top goal: ‹⋀(clist::('a com option × 'a) list list) (list::('a com option list × 'a) list) (j::nat) i::nat. ⟦(xs::'a com option list) ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) (s::'a); ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx::('a com option × 'a) list. fst (x ! j)) clist; ∀x<length xs. length (clist ! x) = Suc (length list); list ≠ []; (xs, s) -pe→ list ! (0::nat) ⟶ (∃i<length xs. ((xs ! i, s), tl (clist ! i) ! (0::nat)) ∉ etran); (xs, s) -pc→ list ! (0::nat); i < length xs; clist ! i ! (0::nat) -c→ clist ! i ! Suc (0::nat); ∀l<length xs. l ≠ i ⟶ clist ! l ! (0::nat) -e→ clist ! l ! Suc (0::nat); j = (0::nat)⟧ ⟹ ∀l<length xs. l ≠ i ⟶ (xs ! l, s) -e→ tl (clist ! l) ! (0::nat)› and 4 goals remain*) apply (erule_tac x=l in allE (*‹⟦∀x::?'a. (?P::?'a ⇒ bool) x; ?P (?x::?'a) ⟹ ?R::bool⟧ ⟹ ?R›*)) (*top goal: ‹⋀clist list j i l. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀x<length xs. length (clist ! x) = Suc (length list); list ≠ []; (xs, s) -pe→ list ! 0 ⟶ (∃i<length xs. ((xs ! i, s), tl (clist ! i) ! 0) ∉ etran); (xs, s) -pc→ list ! 0; i < length xs; clist ! i ! 0 -c→ clist ! i ! Suc 0; ∀l<length xs. l ≠ i ⟶ clist ! l ! 0 -e→ clist ! l ! Suc 0; l < length xs; l ≠ i⟧ ⟹ (xs ! l, s) -e→ tl (clist ! l) ! 0› and 4 goals remain*) apply (erule_tac x=l and P="λj. H j ⟶ I j ⟶ J j" for H I J in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀clist list j i l. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀x<length xs. length (clist ! x) = Suc (length list); list ≠ []; (xs, s) -pe→ list ! 0 ⟶ (∃i<length xs. ((xs ! i, s), tl (clist ! i) ! 0) ∉ etran); (xs, s) -pc→ list ! 0; i < length xs; clist ! i ! 0 -c→ clist ! i ! Suc 0; ∀l<length xs. l ≠ i ⟶ clist ! l ! 0 -e→ clist ! l ! Suc 0; l < length xs; l ≠ i; l < length xs ⟶ clist ! l ∈ cp (xs ! l) s⟧ ⟹ (xs ! l, s) -e→ tl (clist ! l) ! 0› and 4 goals remain*) apply clarify (*top goal: ‹⋀clist list j i l. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀x<length xs. length (clist ! x) = Suc (length list); list ≠ []; (xs, s) -pe→ list ! 0 ⟶ (∃i<length xs. ((xs ! i, s), tl (clist ! i) ! 0) ∉ etran); (xs, s) -pc→ list ! 0; i < length xs; clist ! i ! 0 -c→ clist ! i ! Suc 0; l < length xs; l ≠ i; l < length xs ⟶ clist ! l ∈ cp (xs ! l) s; l < length xs ⟶ l ≠ i ⟶ clist ! l ! 0 -e→ clist ! l ! Suc 0⟧ ⟹ (xs ! l, s) -e→ tl (clist ! l) ! 0› and 4 goals remain*) apply (simp add:cp_def (*‹cp (?P::?'a com option) (?s::?'a) ≡ {l::(?'a com option × ?'a) list. l ! (0::nat) = (?P, ?s) ∧ l ∈ cptn}›*)) (*top goal: ‹⋀(clist::('a::type com option × 'a::type) list list) (list::('a::type com option list × 'a::type) list) (j::nat) (i::nat) l::nat. ⟦(xs::'a::type com option list) ≠ []; length clist = length xs; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s::'a::type) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx::('a::type com option × 'a::type) list. fst (x ! j)) clist; ∀x<length xs. length (clist ! x) = Suc (length list); list ≠ []; (xs, s) -pe→ list ! (0::nat) ⟶ (∃i<length xs. ((xs ! i, s), tl (clist ! i) ! (0::nat)) ∉ etran); (xs, s) -pc→ list ! (0::nat); i < length xs; clist ! i ! (0::nat) -c→ clist ! i ! Suc (0::nat); l < length xs; l ≠ i; clist ! l ∈ cp (xs ! l) s; clist ! l ! (0::nat) -e→ clist ! l ! Suc (0::nat)⟧ ⟹ (xs ! l, s) -e→ tl (clist ! l) ! (0::nat)› and 4 goals remain*) apply (erule_tac x=l and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀clist list i l. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀x<length xs. length (clist ! x) = Suc (length list); list ≠ []; (xs, s) -pe→ list ! 0 ⟶ (∃i<length xs. ((xs ! i, s), tl (clist ! i) ! 0) ∉ etran); (xs, s) -pc→ list ! 0; i < length xs; clist ! i ! 0 -c→ clist ! i ! Suc 0; l < length xs; l ≠ i; clist ! l ! 0 = (xs ! l, s) ∧ clist ! l ∈ cptn; (xs ! l, s) -e→ clist ! l ! Suc 0⟧ ⟹ (xs ! l, s) -e→ tl (clist ! l) ! 0› and 4 goals remain*) apply (case_tac "clist!l", simp, simp) (*top goal: ‹⋀clist list i l. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; list ≠ []; (xs, s) -pe→ list ! 0 ⟶ (∃i<length xs. ((xs ! i, s), tl (clist ! i) ! 0) ∉ etran); (xs, s) -pc→ list ! 0; i < length xs; clist ! i ! 0 -c→ clist ! i ! Suc 0; l < length xs; l ≠ i; clist ! l ! 0 = (xs ! l, s) ∧ clist ! l ∈ cptn; (xs ! l, s) -e→ clist ! l ! Suc 0; l < length xs ⟶ length (clist ! l) = Suc (length list)⟧ ⟹ (xs ! l, s) -e→ tl (clist ! l) ! 0› and 4 goals remain*) apply simp (*top goal: ‹⋀clist list j i nat. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀x<length xs. length (clist ! x) = Suc (length list); j < length list; ((xs, s) # list) ! j -pe→ list ! j ⟶ (∃i<length xs. (((xs ! i, s) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); ((xs, s) # list) ! j -pc→ list ! j; i < length xs; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; j = Suc nat⟧ ⟹ ((xs ! i, s) # tl (clist ! i)) ! j -c→ tl (clist ! i) ! j ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)› and 3 goals remain*) apply (rule conjI (*‹⟦?P::bool; ?Q::bool⟧ ⟹ ?P ∧ ?Q›*)) (*top goal: ‹⋀(clist::('a::type com option × 'a::type) list list) (list::('a::type com option list × 'a::type) list) (j::nat) (i::nat) nat::nat. ⟦(xs::'a::type com option list) ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) (s::'a::type); ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx::('a::type com option × 'a::type) list. fst (x ! j)) clist; ∀x<length xs. length (clist ! x) = Suc (length list); Suc nat < length list; list ! nat -pe→ list ! Suc nat ⟶ (∃i<length xs. (tl (clist ! i) ! nat, tl (clist ! i) ! Suc nat) ∉ etran); list ! nat -pc→ list ! Suc nat; i < length xs; clist ! i ! Suc nat -c→ clist ! i ! Suc (Suc nat); ∀l<length xs. l ≠ i ⟶ clist ! l ! Suc nat -e→ clist ! l ! Suc (Suc nat); j = Suc nat⟧ ⟹ tl (clist ! i) ! nat -c→ tl (clist ! i) ! Suc nat ∧ (∀l<length xs. l ≠ i ⟶ tl (clist ! l) ! nat -e→ tl (clist ! l) ! Suc nat)› and 3 goals remain*) apply (erule_tac x=i and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀clist list j i nat. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀x<length xs. length (clist ! x) = Suc (length list); Suc nat < length list; list ! nat -pe→ list ! Suc nat ⟶ (∃i<length xs. (tl (clist ! i) ! nat, tl (clist ! i) ! Suc nat) ∉ etran); list ! nat -pc→ list ! Suc nat; i < length xs; clist ! i ! Suc nat -c→ clist ! i ! Suc (Suc nat); ∀l<length xs. l ≠ i ⟶ clist ! l ! Suc nat -e→ clist ! l ! Suc (Suc nat); j = Suc nat⟧ ⟹ tl (clist ! i) ! nat -c→ tl (clist ! i) ! Suc nat› and 4 goals remain*) apply (case_tac "clist!i", simp, simp) (*top goal: ‹⋀clist list j i nat. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; Suc nat < length list; list ! nat -pe→ list ! Suc nat ⟶ (∃i<length xs. (tl (clist ! i) ! nat, tl (clist ! i) ! Suc nat) ∉ etran); list ! nat -pc→ list ! Suc nat; i < length xs; clist ! i ! Suc nat -c→ clist ! i ! Suc (Suc nat); ∀l<length xs. l ≠ i ⟶ clist ! l ! Suc nat -e→ clist ! l ! Suc (Suc nat); j = Suc nat; i < length xs ⟶ length (clist ! i) = Suc (length list)⟧ ⟹ tl (clist ! i) ! nat -c→ tl (clist ! i) ! Suc nat› and 4 goals remain*) apply clarify (*top goal: ‹⋀clist list j i nat. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀x<length xs. length (clist ! x) = Suc (length list); Suc nat < length list; list ! nat -pe→ list ! Suc nat ⟶ (∃i<length xs. (tl (clist ! i) ! nat, tl (clist ! i) ! Suc nat) ∉ etran); list ! nat -pc→ list ! Suc nat; i < length xs; clist ! i ! Suc nat -c→ clist ! i ! Suc (Suc nat); ∀l<length xs. l ≠ i ⟶ clist ! l ! Suc nat -e→ clist ! l ! Suc (Suc nat); j = Suc nat⟧ ⟹ ∀l<length xs. l ≠ i ⟶ tl (clist ! l) ! nat -e→ tl (clist ! l) ! Suc nat› and 3 goals remain*) apply (erule_tac x=l and P="λj. H j ⟶ I j ⟶ J j" for H I J in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀clist list j i nat l. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀x<length xs. length (clist ! x) = Suc (length list); Suc nat < length list; list ! nat -pe→ list ! Suc nat ⟶ (∃i<length xs. (tl (clist ! i) ! nat, tl (clist ! i) ! Suc nat) ∉ etran); list ! nat -pc→ list ! Suc nat; i < length xs; clist ! i ! Suc nat -c→ clist ! i ! Suc (Suc nat); ∀l<length xs. l ≠ i ⟶ clist ! l ! Suc nat -e→ clist ! l ! Suc (Suc nat); l < length xs; l ≠ i⟧ ⟹ tl (clist ! l) ! nat -e→ tl (clist ! l) ! Suc nat› and 3 goals remain*) apply (erule_tac x=l and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀clist list j i nat l. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀x<length xs. length (clist ! x) = Suc (length list); Suc nat < length list; list ! nat -pe→ list ! Suc nat ⟶ (∃i<length xs. (tl (clist ! i) ! nat, tl (clist ! i) ! Suc nat) ∉ etran); list ! nat -pc→ list ! Suc nat; i < length xs; clist ! i ! Suc nat -c→ clist ! i ! Suc (Suc nat); l < length xs; l ≠ i; l < length xs ⟶ l ≠ i ⟶ clist ! l ! Suc nat -e→ clist ! l ! Suc (Suc nat)⟧ ⟹ tl (clist ! l) ! nat -e→ tl (clist ! l) ! Suc nat› and 3 goals remain*) apply (case_tac "clist!l", simp, simp) (*top goal: ‹⋀clist list j i nat l. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; Suc nat < length list; list ! nat -pe→ list ! Suc nat ⟶ (∃i<length xs. (tl (clist ! i) ! nat, tl (clist ! i) ! Suc nat) ∉ etran); list ! nat -pc→ list ! Suc nat; i < length xs; clist ! i ! Suc nat -c→ clist ! i ! Suc (Suc nat); l < length xs; l ≠ i; l < length xs ⟶ l ≠ i ⟶ clist ! l ! Suc nat -e→ clist ! l ! Suc (Suc nat); l < length xs ⟶ length (clist ! l) = Suc (length list)⟧ ⟹ tl (clist ! l) ! nat -e→ tl (clist ! l) ! Suc nat› and 3 goals remain*) apply clarify (*top goal: ‹⋀clist a b list j. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀x<length xs. length (clist ! x) = Suc (length list); j < length list; ¬ (((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. ((xs ! i, s) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j)); ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j)⟧ ⟹ ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j))› and 2 goals remain*) apply (erule_tac x=i in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀clist a b list j i. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀x<length xs. length (clist ! x) = Suc (length list); j < length list; ((xs, s) # list) ! j -pe→ list ! j; ∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j; ¬ (((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j))); i < length xs⟧ ⟹ ((xs ! i, s) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j› and 2 goals remain*) apply (simp add:cp_def (*‹cp ?P ?s ≡ {l. l ! 0 = (?P, ?s) ∧ l ∈ cptn}›*)) (*top goal: ‹⋀clist a b list j i. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀x<length xs. length (clist ! x) = Suc (length list); j < length list; ((xs, s) # list) ! j -pe→ list ! j; ∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j; ¬ (((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j))); i < length xs; i < length xs ⟶ clist ! i ∈ cp (xs ! i) s⟧ ⟹ ((xs ! i, s) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j› and 2 goals remain*) apply (erule_tac x=i and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀(clist::('a com option × 'a) list list) (list::('a com option list × 'a) list) (j::nat) i::nat. ⟦(xs::'a com option list) ≠ []; length clist = length xs; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s::'a) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx::('a com option × 'a) list. fst (x ! j)) clist; ∀x<length xs. length (clist ! x) = Suc (length list); j < length list; ((xs, s) # list) ! j -pe→ list ! j; ∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j; ((xs, s) # list) ! j -pc→ list ! j ⟶ (∀i::nat. map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! j -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! Suc j ⟶ i < length xs ⟶ (∃l<length xs. l ≠ i ∧ (((xs ! l, s) # tl (clist ! l)) ! j, tl (clist ! l) ! j) ∉ etran)); i < length xs; clist ! i ! (0::nat) = (xs ! i, s) ∧ clist ! i ∈ cptn⟧ ⟹ ((xs ! i, s) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j› and 2 goals remain*) apply (case_tac "clist!i", simp) (*top goal: ‹⋀clist list j i. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; j < length list; ((xs, s) # list) ! j -pe→ list ! j; ∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j; ((xs, s) # list) ! j -pc→ list ! j ⟶ (∀i. map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! Suc j ⟶ i < length xs ⟶ (∃l<length xs. l ≠ i ∧ (((xs ! l, s) # tl (clist ! l)) ! j, tl (clist ! l) ! j) ∉ etran)); i < length xs; clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; i < length xs ⟶ length (clist ! i) = Suc (length list)⟧ ⟹ ((xs ! i, s) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j› and 2 goals remain*) apply (rule nth_tl_if (*‹⟦?ys ≠ []; ?ys ! 0 = ?a; ?P ?ys⟧ ⟹ ?P (?a # tl ?ys)›*), simp, simp) (*top goal: ‹⋀(clist::('a com option × 'a) list list) (list::('a com option list × 'a) list) (j::nat) (i::nat) (a::'a com option × 'a) lista::('a com option × 'a) list. ⟦(xs::'a com option list) ≠ []; length clist = length xs; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s::'a) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx::('a com option × 'a) list. fst (x ! j)) clist; j < length list; ((xs, s) # list) ! j -pe→ list ! j; ∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j; ((xs, s) # list) ! j -pc→ list ! j ⟶ (∀i::nat. map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! j -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! Suc j ⟶ i < length xs ⟶ (∃l<length xs. l ≠ i ∧ (((xs ! l, s) # tl (clist ! l)) ! j, tl (clist ! l) ! j) ∉ etran)); i < length xs; clist ! i ! (0::nat) = (xs ! i, s) ∧ clist ! i ∈ cptn; i < length xs ⟶ length (clist ! i) = Suc (length list); clist ! i = a # lista⟧ ⟹ ((xs ! i, s) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j› and 2 goals remain*) apply (erule_tac x=i and P="λj. H j ⟶ (P j)∈etran" for H P in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption, simp) (*top goal: ‹⋀clist list j i a lista. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; j < length list; ((xs, s) # list) ! j -pe→ list ! j; ∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j; ((xs, s) # list) ! j -pc→ list ! j ⟶ (∀i. map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! Suc j ⟶ i < length xs ⟶ (∃l<length xs. l ≠ i ∧ (((xs ! l, s) # tl (clist ! l)) ! j, tl (clist ! l) ! j) ∉ etran)); i < length xs; clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; i < length xs ⟶ length (clist ! i) = Suc (length list); clist ! i = a # lista⟧ ⟹ clist ! i ! j -e→ tl (clist ! i) ! j› and 2 goals remain*) apply (simp add:cp_def (*‹cp ?P ?s ≡ {l. l ! 0 = (?P, ?s) ∧ l ∈ cptn}›*)) (*top goal: ‹⋀clist a b list. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); a = xs; b = s⟧ ⟹ ∀i<length xs. (xs ! i, s) # tl (clist ! i) ∈ cptn› and 1 goal remains*) apply clarify (*top goal: ‹⋀clist a b list. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); a = xs; b = s⟧ ⟹ ∀i<length xs. (xs ! i, s) # tl (clist ! i) ∈ cptn› and 1 goal remains*) apply (rule nth_tl_if (*‹⟦?ys ≠ []; ?ys ! 0 = ?a; ?P ?ys⟧ ⟹ ?P (?a # tl ?ys)›*)) (*top goal: ‹⋀(clist::('a com option × 'a) list list) (a::'a com option list) (b::'a) (list::('a com option list × 'a) list) i::nat. ⟦(xs::'a com option list) ≠ []; length clist = length xs; ∀i<length xs. clist ! i ! (0::nat) = (xs ! i, s::'a) ∧ clist ! i ∈ cptn; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx::('a com option × 'a) list. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); i < length xs⟧ ⟹ (xs ! i, s) # tl (clist ! i) ∈ cptn› and 1 goal remains*) apply (erule_tac x=i and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀clist a b list i. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); i < length xs⟧ ⟹ clist ! i ≠ []› and 3 goals remain*) apply (case_tac "clist!i", simp, simp) (*top goal: ‹⋀clist a b list i. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); i < length xs; i < length xs ⟶ length (clist ! i) = Suc (length list)⟧ ⟹ clist ! i ≠ []› and 3 goals remain*) apply force (*top goal: ‹⋀clist a b list i. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); i < length xs⟧ ⟹ clist ! i ! 0 = (xs ! i, s)› and 2 goals remain*) apply force (*top goal: ‹⋀clist a b list i. ⟦xs ≠ []; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. ∀j<Suc (length list). snd (((xs, s) # list) ! j) = snd (clist ! i ! j); ∀j<Suc (length list). fst (((xs, s) # list) ! j) = map (λx. fst (x ! j)) clist; ∀j<length list. ((xs, s) # list) ! j -pc→ list ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # list) ! j -pe→ list ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); ∀x<length xs. length (clist ! x) = Suc (length list); i < length xs⟧ ⟹ clist ! i ∈ cptn› and 1 goal remains*) apply clarify (*goal: ‹⟦xs ≠ []; par_cp xs s = {c. ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ∈ cp (xs ! i) s) ∧ c ∝ clist}⟧ ⟹ ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn))›*) apply (rule iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*)) (*goal: ‹⋀ys. ⟦xs ≠ []; par_cp xs s = {c. ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ∈ cp (xs ! i) s) ∧ c ∝ clist}⟧ ⟹ ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn))›*) apply (simp add:par_cp_def (*‹par_cp ?P ?s ≡ {l. l ! 0 = (?P, ?s) ∧ l ∈ par_cptn}›*)) (*top goal: ‹⋀ys. ⟦xs ≠ []; par_cp xs s = {c. ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ∈ cp (xs ! i) s) ∧ c ∝ clist}; (xs, s) # ys ∈ par_cptn⟧ ⟹ ∃clist. length clist = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)› and 1 goal remains*) apply (erule_tac c="(xs, s) # ys" in equalityCE (*‹⟦?A = ?B; ⟦?c ∈ ?A; ?c ∈ ?B⟧ ⟹ ?P; ⟦?c ∉ ?A; ?c ∉ ?B⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*top goal: ‹⋀ys::('a com option list × 'a) list. ⟦(xs::'a com option list) ≠ []; {l::('a com option list × 'a) list. l ! (0::nat) = (xs, s::'a) ∧ l ∈ par_cptn} = {c::('a com option list × 'a) list. ∃clist::('a com option × 'a) list list. length clist = length xs ∧ (∀i<length clist. clist ! i ∈ cp (xs ! i) s) ∧ c ∝ clist}; (xs, s) # ys ∈ par_cptn⟧ ⟹ ∃clist::('a com option × 'a) list list. length clist = length xs ∧ (xs, s) # ys ∝ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)› and 1 goal remains*) apply simp (*top goal: ‹⋀ys. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; (xs, s) # ys ∈ {l. l ! 0 = (xs, s) ∧ l ∈ par_cptn}; (xs, s) # ys ∈ {c. ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ∈ cp (xs ! i) s) ∧ c ∝ clist}⟧ ⟹ ∃clist. length clist = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)› and 2 goals remain*) apply clarify (*top goal: ‹⋀ys. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ∈ cp (xs ! i) s) ∧ (xs, s) # ys ∝ clist⟧ ⟹ ∃clist. length clist = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)› and 2 goals remain*) apply (rule_tac x="map tl clist" in exI (*‹?P ?x ⟹ ∃x. ?P x›*)) (*top goal: ‹⋀ys clist. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length clist. clist ! i ∈ cp (xs ! i) s; (xs, s) # ys ∝ clist⟧ ⟹ ∃clist. length clist = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)› and 2 goals remain*) apply simp (*top goal: ‹⋀ys clist. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length clist. clist ! i ∈ cp (xs ! i) s; (xs, s) # ys ∝ clist⟧ ⟹ length (map tl clist) = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ∧ (∀i<length xs. (xs ! i, s) # map tl clist ! i ∈ cptn)› and 2 goals remain*) apply (rule conjI (*‹⟦?P::bool; ?Q::bool⟧ ⟹ ?P ∧ ?Q›*)) (*top goal: ‹⋀ys clist. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; (xs, s) # ys ∝ clist⟧ ⟹ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ∧ (∀i<length xs. (xs ! i, s) # tl (clist ! i) ∈ cptn)› and 2 goals remain*) apply (simp add:conjoin_def (*‹?c ∝ ?clist ≡ same_length ?c ?clist ∧ same_state ?c ?clist ∧ same_program ?c ?clist ∧ compat_label ?c ?clist›*) cp_def (*‹cp ?P ?s ≡ {l. l ! 0 = (?P, ?s) ∧ l ∈ cptn}›*)) (*top goal: ‹⋀ys clist. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; (xs, s) # ys ∝ clist⟧ ⟹ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs (map tl clist))› and 3 goals remain*) apply (rule conjI (*‹⟦?P::bool; ?Q::bool⟧ ⟹ ?P ∧ ?Q›*)) (*top goal: ‹⋀ys clist. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; same_length ((xs, s) # ys) clist ∧ same_state ((xs, s) # ys) clist ∧ same_program ((xs, s) # ys) clist ∧ compat_label ((xs, s) # ys) clist⟧ ⟹ same_length ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs (map tl clist))) ∧ same_state ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs (map tl clist))) ∧ same_program ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs (map tl clist))) ∧ compat_label ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs (map tl clist)))› and 3 goals remain*) apply clarify (*top goal: ‹⋀ys clist. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; same_length ((xs, s) # ys) clist ∧ same_state ((xs, s) # ys) clist ∧ same_program ((xs, s) # ys) clist ∧ compat_label ((xs, s) # ys) clist⟧ ⟹ same_length ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs (map tl clist)))› and 4 goals remain*) apply (unfold same_length_def (*‹same_length ?c ?clist ≡ ∀i<length ?clist. length (?clist ! i) = length ?c›*)) (*top goal: ‹⋀ys clist. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; same_length ((xs, s) # ys) clist; same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; compat_label ((xs, s) # ys) clist⟧ ⟹ same_length ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs (map tl clist)))› and 4 goals remain*) apply clarify (*top goal: ‹⋀ys clist. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length clist. length (clist ! i) = length ((xs, s) # ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; compat_label ((xs, s) # ys) clist⟧ ⟹ ∀i<length (map (λi. (fst i, s) # snd i) (zip xs (map tl clist))). length (map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i) = length ((xs, s) # ys)› and 4 goals remain*) apply (erule_tac x=i and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), simp) (*top goal: ‹⋀ys clist i. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length clist. length (clist ! i) = length ((xs, s) # ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; compat_label ((xs, s) # ys) clist; i < length (map (λi. (fst i, s) # snd i) (zip xs (map tl clist)))⟧ ⟹ length (map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i) = length ((xs, s) # ys)› and 4 goals remain*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*top goal: ‹⋀ys clist. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; (∀i<length clist. length (clist ! i) = length ((xs, s) # ys)) ∧ same_state ((xs, s) # ys) clist ∧ same_program ((xs, s) # ys) clist ∧ compat_label ((xs, s) # ys) clist⟧ ⟹ same_state ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs (map tl clist))) ∧ same_program ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs (map tl clist))) ∧ compat_label ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs (map tl clist)))› and 3 goals remain*) apply (simp add:same_state_def (*‹same_state (?c::(?'a com option list × ?'a) list) (?clist::(?'a com option × ?'a) list list) ≡ ∀i<length ?clist. ∀j<length ?c. snd (?c ! j) = snd (?clist ! i ! j)›*)) (*top goal: ‹⋀ys clist. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; (∀i<length clist. length (clist ! i) = length ((xs, s) # ys)) ∧ same_state ((xs, s) # ys) clist ∧ same_program ((xs, s) # ys) clist ∧ compat_label ((xs, s) # ys) clist⟧ ⟹ same_state ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs (map tl clist)))› and 4 goals remain*) apply clarify (*top goal: ‹⋀ys clist. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; (∀i<length xs. length (clist ! i) = Suc (length ys)) ∧ (∀i<length xs. ∀j<Suc (length ys). snd (((xs, s) # ys) ! j) = snd (clist ! i ! j)) ∧ same_program ((xs, s) # ys) clist ∧ compat_label ((xs, s) # ys) clist⟧ ⟹ ∀i<length xs. ∀j<Suc (length ys). snd (clist ! i ! j) = snd (((xs ! i, s) # tl (clist ! i)) ! j)› and 4 goals remain*) apply (erule_tac x=i in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption, erule_tac x=j and P="λj. H j ⟶ (snd (d j))=(snd (e j))" for H d e in allE (*‹⟦∀x::?'a. (?P::?'a ⇒ bool) x; ?P (?x::?'a) ⟹ ?R::bool⟧ ⟹ ?R›*)) (*top goal: ‹⋀ys clist i j. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); ∀i<length xs. ∀j<Suc (length ys). snd (((xs, s) # ys) ! j) = snd (clist ! i ! j); same_program ((xs, s) # ys) clist; compat_label ((xs, s) # ys) clist; i < length xs; j < Suc (length ys)⟧ ⟹ snd (clist ! i ! j) = snd (((xs ! i, s) # tl (clist ! i)) ! j)› and 4 goals remain*) apply (case_tac j, simp) (*top goal: ‹⋀(ys::('a com option list × 'a) list) (clist::('a com option × 'a) list list) (i::nat) j::nat. ⟦(xs::'a com option list) ≠ []; (xs, s::'a) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! (0::nat) = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_program ((xs, s) # ys) clist; compat_label ((xs, s) # ys) clist; i < length xs; j < Suc (length ys); j < Suc (length ys) ⟶ snd (((xs, s) # ys) ! j) = snd (clist ! i ! j)⟧ ⟹ snd (clist ! i ! j) = snd (((xs ! i, s) # tl (clist ! i)) ! j)› and 4 goals remain*) apply (erule_tac x=i and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀ys clist i j nat. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_program ((xs, s) # ys) clist; compat_label ((xs, s) # ys) clist; i < length xs; j < Suc (length ys); j < Suc (length ys) ⟶ snd (((xs, s) # ys) ! j) = snd (clist ! i ! j); j = Suc nat⟧ ⟹ snd (clist ! i ! j) = snd (((xs ! i, s) # tl (clist ! i)) ! j)› and 4 goals remain*) apply (case_tac "clist!i", simp, simp) (*top goal: ‹⋀(ys::('a com option list × 'a) list) (clist::('a com option × 'a) list list) (i::nat) (j::nat) nat::nat. ⟦(xs::'a com option list) ≠ []; (xs, s::'a) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! (0::nat) = (xs ! i, s) ∧ clist ! i ∈ cptn; same_program ((xs, s) # ys) clist; compat_label ((xs, s) # ys) clist; i < length xs; j < Suc (length ys); j < Suc (length ys) ⟶ snd (((xs, s) # ys) ! j) = snd (clist ! i ! j); j = Suc nat; i < length xs ⟶ length (clist ! i) = Suc (length ys)⟧ ⟹ snd (clist ! i ! j) = snd (((xs ! i, s) # tl (clist ! i)) ! j)› and 4 goals remain*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*top goal: ‹⋀ys clist. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; (∀i<length clist. length (clist ! i) = length ((xs, s) # ys)) ∧ same_state ((xs, s) # ys) clist ∧ same_program ((xs, s) # ys) clist ∧ compat_label ((xs, s) # ys) clist⟧ ⟹ same_program ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs (map tl clist))) ∧ compat_label ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs (map tl clist)))› and 3 goals remain*) apply (simp add:same_program_def (*‹same_program ?c ?clist ≡ ∀j<length ?c. fst (?c ! j) = map (λx. fst (x ! j)) ?clist›*)) (*top goal: ‹⋀ys clist. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; (∀i<length clist. length (clist ! i) = length ((xs, s) # ys)) ∧ same_state ((xs, s) # ys) clist ∧ same_program ((xs, s) # ys) clist ∧ compat_label ((xs, s) # ys) clist⟧ ⟹ same_program ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs (map tl clist)))› and 4 goals remain*) apply clarify (*top goal: ‹⋀ys clist. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; (∀i<length xs. length (clist ! i) = Suc (length ys)) ∧ same_state ((xs, s) # ys) clist ∧ (∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map (λx. fst (x ! j)) clist) ∧ compat_label ((xs, s) # ys) clist⟧ ⟹ ∀j<Suc (length ys). map (λx. fst (x ! j)) clist = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs (map tl clist))› and 4 goals remain*) apply (rule nth_equalityI (*‹⟦length ?xs = length ?ys; ⋀i. i < length ?xs ⟹ ?xs ! i = ?ys ! i⟧ ⟹ ?xs = ?ys›*), simp, simp) (*top goal: ‹⋀ys clist j. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; ∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map (λx. fst (x ! j)) clist; compat_label ((xs, s) # ys) clist; j < Suc (length ys)⟧ ⟹ map (λx. fst (x ! j)) clist = map ((λx. fst (x ! j)) ∘ (λi. (fst i, s) # snd i)) (zip xs (map tl clist))› and 4 goals remain*) apply (case_tac j, simp) (*top goal: ‹⋀ys clist j i. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; ∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map (λx. fst (x ! j)) clist; compat_label ((xs, s) # ys) clist; j < Suc (length ys); i < length xs⟧ ⟹ fst (clist ! i ! j) = fst (((xs ! i, s) # tl (clist ! i)) ! j)› and 4 goals remain*) apply clarify (*top goal: ‹⋀ys clist j i nat. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; ∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map (λx. fst (x ! j)) clist; compat_label ((xs, s) # ys) clist; j < Suc (length ys); i < length xs; j = Suc nat⟧ ⟹ fst (clist ! i ! j) = fst (((xs ! i, s) # tl (clist ! i)) ! j)› and 4 goals remain*) apply (erule_tac x=i and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀(ys::('a::type com option list × 'a::type) list) (clist::('a::type com option × 'a::type) list list) (j::nat) (i::nat) nat::nat. ⟦(xs::'a::type com option list) ≠ []; (xs, s::'a::type) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! (0::nat) = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; ∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map (λx::('a::type com option × 'a::type) list. fst (x ! j)) clist; compat_label ((xs, s) # ys) clist; i < length xs; nat < length ys⟧ ⟹ fst (clist ! i ! Suc nat) = fst (((xs ! i, s) # tl (clist ! i)) ! Suc nat)› and 4 goals remain*) apply (case_tac "clist!i", simp, simp) (*top goal: ‹⋀ys clist j i nat. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; same_state ((xs, s) # ys) clist; ∀j<Suc (length ys). fst (((xs, s) # ys) ! j) = map (λx. fst (x ! j)) clist; compat_label ((xs, s) # ys) clist; i < length xs; nat < length ys; i < length xs ⟶ length (clist ! i) = Suc (length ys)⟧ ⟹ fst (clist ! i ! Suc nat) = fst (((xs ! i, s) # tl (clist ! i)) ! Suc nat)› and 4 goals remain*) apply clarify (*top goal: ‹⋀ys clist. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; (∀i<length clist. length (clist ! i) = length ((xs, s) # ys)) ∧ same_state ((xs, s) # ys) clist ∧ same_program ((xs, s) # ys) clist ∧ compat_label ((xs, s) # ys) clist⟧ ⟹ compat_label ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs (map tl clist)))› and 3 goals remain*) apply (simp add:compat_label_def (*‹compat_label ?c ?clist ≡ ∀j. Suc j < length ?c ⟶ ?c ! j -pc→ ?c ! Suc j ∧ (∃i<length ?clist. ?clist ! i ! j -c→ ?clist ! i ! Suc j ∧ (∀l<length ?clist. l ≠ i ⟶ ?clist ! l ! j -e→ ?clist ! l ! Suc j)) ∨ ?c ! j -pe→ ?c ! Suc j ∧ (∀i<length ?clist. ?clist ! i ! j -e→ ?clist ! i ! Suc j)›*)) (*top goal: ‹⋀ys clist. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length clist. length (clist ! i) = length ((xs, s) # ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; compat_label ((xs, s) # ys) clist⟧ ⟹ compat_label ((xs, s) # ys) (map (λi. (fst i, s) # snd i) (zip xs (map tl clist)))› and 3 goals remain*) apply (rule allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*), rule impI (*‹(?P::bool ⟹ ?Q::bool) ⟹ ?P ⟶ ?Q›*)) (*top goal: ‹⋀(ys::('a::type com option list × 'a::type) list) clist::('a::type com option × 'a::type) list list. ⟦(xs::'a::type com option list) ≠ []; (xs, s::'a::type) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! (0::nat) = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; ∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j)⟧ ⟹ ∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! j -c→ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i<length xs. ((xs ! i, s) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j)› and 3 goals remain*) apply (erule_tac x=j in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), erule impE (*‹⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R›*), assumption) (*top goal: ‹⋀ys clist j. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; ∀j<length ys. ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j); j < length ys⟧ ⟹ ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i<length xs. ((xs ! i, s) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j)› and 3 goals remain*) apply (erule disjE (*‹⟦(?P::bool) ∨ (?Q::bool); ?P ⟹ ?R::bool; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀ys clist j. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; j < length ys; ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j)⟧ ⟹ ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i<length xs. ((xs ! i, s) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j)› and 3 goals remain*) apply clarify (*top goal: ‹⋀ys clist j. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; j < length ys; ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. clist ! i ! j -c→ clist ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j))⟧ ⟹ ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i<length xs. ((xs ! i, s) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j)› and 4 goals remain*) apply (rule_tac x=i in exI (*‹?P ?x ⟹ ∃x. ?P x›*), simp) (*top goal: ‹⋀(ys::('a com option list × 'a) list) (clist::('a com option × 'a) list list) (j::nat) i::nat. ⟦(xs::'a com option list) ≠ []; (xs, s::'a) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! (0::nat) = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; j < length ys; ((xs, s) # ys) ! j -pc→ ys ! j; i < length xs; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ¬ (((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i<length xs. ((xs ! i, s) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j))⟧ ⟹ ∃i<length xs. map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! j -c→ map (λi::'a com option × ('a com option × 'a) list. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)› and 4 goals remain*) apply (rule conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*top goal: ‹⋀ys clist j i. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; j < length ys; ((xs, s) # ys) ! j -pc→ ys ! j; i < length xs; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs, s) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs ! i, s) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran)⟧ ⟹ ((xs ! i, s) # tl (clist ! i)) ! j -c→ tl (clist ! i) ! j ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)› and 4 goals remain*) apply (erule_tac x=i in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀ys clist j i. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; j < length ys; ((xs, s) # ys) ! j -pc→ ys ! j; i < length xs; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs, s) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs ! i, s) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran)⟧ ⟹ ((xs ! i, s) # tl (clist ! i)) ! j -c→ tl (clist ! i) ! j› and 5 goals remain*) apply (case_tac j, simp) (*top goal: ‹⋀ys clist j i. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; j < length ys; ((xs, s) # ys) ! j -pc→ ys ! j; i < length xs; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs, s) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs ! i, s) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); i < length xs ⟶ clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn⟧ ⟹ ((xs ! i, s) # tl (clist ! i)) ! j -c→ tl (clist ! i) ! j› and 5 goals remain*) apply (erule_tac x=i and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀ys clist j i. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; ys ≠ []; (xs, s) -pc→ ys ! 0; i < length xs; (xs ! i, s) -c→ clist ! i ! Suc 0; ∀l<length xs. l ≠ i ⟶ clist ! l ! 0 -e→ clist ! l ! Suc 0; (xs, s) -pe→ ys ! 0 ⟶ (∃i<length xs. ((xs ! i, s), tl (clist ! i) ! 0) ∉ etran); clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; j = 0⟧ ⟹ (xs ! i, s) -c→ tl (clist ! i) ! 0› and 6 goals remain*) apply (case_tac "clist!i", simp, simp) (*top goal: ‹⋀(ys::('a com option list × 'a) list) (clist::('a com option × 'a) list list) (j::nat) i::nat. ⟦(xs::'a com option list) ≠ []; (xs, s::'a) # ys ∈ par_cptn; length clist = length xs; same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; ys ≠ []; (xs, s) -pc→ ys ! (0::nat); i < length xs; (xs ! i, s) -c→ clist ! i ! Suc (0::nat); ∀l<length xs. l ≠ i ⟶ clist ! l ! (0::nat) -e→ clist ! l ! Suc (0::nat); (xs, s) -pe→ ys ! (0::nat) ⟶ (∃i<length xs. ((xs ! i, s), tl (clist ! i) ! (0::nat)) ∉ etran); clist ! i ! (0::nat) = (xs ! i, s) ∧ clist ! i ∈ cptn; j = (0::nat); i < length xs ⟶ length (clist ! i) = Suc (length ys)⟧ ⟹ (xs ! i, s) -c→ tl (clist ! i) ! (0::nat)› and 6 goals remain*) apply (erule_tac x=i and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x::?'a::type. (?P::?'a::type ⇒ bool) x; ?P (?x::?'a::type) ⟹ ?R::bool⟧ ⟹ ?R›*)) (*top goal: ‹⋀ys clist j i nat. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; j < length ys; ((xs, s) # ys) ! j -pc→ ys ! j; i < length xs; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs, s) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs ! i, s) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); i < length xs ⟶ clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; j = Suc nat⟧ ⟹ ((xs ! i, s) # tl (clist ! i)) ! j -c→ tl (clist ! i) ! j› and 5 goals remain*) apply (case_tac "clist!i", simp, simp) (*top goal: ‹⋀ys clist j i nat. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; j < length ys; ((xs, s) # ys) ! j -pc→ ys ! j; i < length xs; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs, s) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs ! i, s) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); i < length xs ⟶ clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; j = Suc nat; i < length xs ⟶ length (clist ! i) = Suc (length ys)⟧ ⟹ ((xs ! i, s) # tl (clist ! i)) ! j -c→ tl (clist ! i) ! j› and 5 goals remain*) apply clarify (*top goal: ‹⋀(ys::('a::type com option list × 'a::type) list) (clist::('a::type com option × 'a::type) list list) (j::nat) i::nat. ⟦(xs::'a::type com option list) ≠ []; (xs, s::'a::type) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! (0::nat) = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; j < length ys; ((xs, s) # ys) ! j -pc→ ys ! j; i < length xs; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs, s) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs ! i, s) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran)⟧ ⟹ ∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j› and 4 goals remain*) apply (erule_tac x=l and P="λj. H j ⟶ I j ⟶ J j" for H I J in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀ys clist j i l. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; j < length ys; ((xs, s) # ys) ! j -pc→ ys ! j; i < length xs; clist ! i ! j -c→ clist ! i ! Suc j; ∀l<length xs. l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; ((xs, s) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs ! i, s) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length xs; l ≠ i⟧ ⟹ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j› and 4 goals remain*) apply (erule_tac x=l and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀ys clist j i l. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; j < length ys; ((xs, s) # ys) ! j -pc→ ys ! j; i < length xs; clist ! i ! j -c→ clist ! i ! Suc j; ((xs, s) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs ! i, s) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length xs; l ≠ i; l < length xs ⟶ l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j⟧ ⟹ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j› and 4 goals remain*) apply (case_tac "clist!l", simp, simp) (*top goal: ‹⋀ys clist j i l. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; j < length ys; ((xs, s) # ys) ! j -pc→ ys ! j; i < length xs; clist ! i ! j -c→ clist ! i ! Suc j; ((xs, s) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs ! i, s) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length xs; l ≠ i; l < length xs ⟶ l ≠ i ⟶ clist ! l ! j -e→ clist ! l ! Suc j; l < length xs ⟶ length (clist ! l) = Suc (length ys)⟧ ⟹ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j› and 4 goals remain*) apply (erule_tac x=l in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), simp) (*top goal: ‹⋀ys clist j i l a list. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; j < length ys; ((xs, s) # ys) ! j -pc→ ys ! j; i < length xs; clist ! i ! j -c→ clist ! i ! Suc j; ((xs, s) # ys) ! j -pe→ ys ! j ⟶ (∃i<length xs. (((xs ! i, s) # tl (clist ! i)) ! j, tl (clist ! i) ! j) ∉ etran); l < length xs; l ≠ i; (a # list) ! j -e→ list ! j; length list = length ys; clist ! l = a # list⟧ ⟹ ((xs ! l, s) # list) ! j -e→ list ! j› and 4 goals remain*) apply (rule disjI2 (*‹?Q ⟹ ?P ∨ ?Q›*)) (*top goal: ‹⋀ys clist j. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; j < length ys; ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j)⟧ ⟹ ((xs, s) # ys) ! j -pc→ ys ! j ∧ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! j -c→ map (λi. (fst i, s) # snd i) (zip xs (map tl clist)) ! i ! Suc j ∧ (∀l<length xs. l ≠ i ⟶ ((xs ! l, s) # tl (clist ! l)) ! j -e→ tl (clist ! l) ! j)) ∨ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i<length xs. ((xs ! i, s) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j)› and 3 goals remain*) apply clarify (*top goal: ‹⋀(ys::('a::type com option list × 'a::type) list) (clist::('a::type com option × 'a::type) list list) j::nat. ⟦(xs::'a::type com option list) ≠ []; (xs, s::'a::type) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! (0::nat) = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; j < length ys; ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j)⟧ ⟹ ((xs, s) # ys) ! j -pe→ ys ! j ∧ (∀i<length xs. ((xs ! i, s) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j)› and 3 goals remain*) apply (rule tl_zero (*‹⟦?P (?ys ! Suc ?j); Suc ?j < length ?ys; ?ys ≠ []⟧ ⟹ ?P (tl ?ys ! ?j)›*)) (*top goal: ‹⋀ys clist j i. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; j < length ys; ((xs, s) # ys) ! j -pe→ ys ! j; ∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j; i < length xs⟧ ⟹ ((xs ! i, s) # tl (clist ! i)) ! j -e→ tl (clist ! i) ! j› and 3 goals remain*) apply (case_tac j, simp, simp) (*top goal: ‹⋀ys clist j i. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; j < length ys; ((xs, s) # ys) ! j -pe→ ys ! j; ∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j; i < length xs⟧ ⟹ ((xs ! i, s) # tl (clist ! i)) ! j -e→ clist ! i ! Suc j› and 5 goals remain*) apply (rule tl_zero (*‹⟦?P (?ys ! Suc ?j); Suc ?j < length ?ys; ?ys ≠ []⟧ ⟹ ?P (tl ?ys ! ?j)›*), force) (*top goal: ‹⋀ys clist j i nat. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; Suc nat < length ys; ys ! nat -pe→ ys ! Suc nat; ∀i<length xs. clist ! i ! Suc nat -e→ clist ! i ! Suc (Suc nat); i < length xs; j = Suc nat⟧ ⟹ tl (clist ! i) ! nat -e→ clist ! i ! Suc (Suc nat)› and 5 goals remain*) apply force (*top goal: ‹⋀ys clist j i nat. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; Suc nat < length ys; ys ! nat -pe→ ys ! Suc nat; ∀i<length xs. clist ! i ! Suc nat -e→ clist ! i ! Suc (Suc nat); i < length xs; j = Suc nat⟧ ⟹ Suc nat < length (clist ! i)› and 6 goals remain*) apply (erule_tac x=i and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), force) (*top goal: ‹⋀ys clist j i nat. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; Suc nat < length ys; ys ! nat -pe→ ys ! Suc nat; ∀i<length xs. clist ! i ! Suc nat -e→ clist ! i ! Suc (Suc nat); i < length xs; j = Suc nat⟧ ⟹ clist ! i ≠ []› and 5 goals remain*) apply force (*top goal: ‹⋀ys clist j i. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; j < length ys; ((xs, s) # ys) ! j -pe→ ys ! j; ∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j; i < length xs⟧ ⟹ Suc j < length (clist ! i)› and 4 goals remain*) apply (erule_tac x=i and P="λj. H j ⟶ (length (s j) = t)" for H s t in allE (*‹⟦∀x::?'a. (?P::?'a ⇒ bool) x; ?P (?x::?'a) ⟹ ?R::bool⟧ ⟹ ?R›*), force) (*top goal: ‹⋀(ys::('a com option list × 'a) list) (clist::('a com option × 'a) list list) (j::nat) i::nat. ⟦(xs::'a com option list) ≠ []; (xs, s::'a) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ! (0::nat) = (xs ! i, s) ∧ clist ! i ∈ cptn; ∀i<length xs. length (clist ! i) = Suc (length ys); same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; j < length ys; ((xs, s) # ys) ! j -pe→ ys ! j; ∀i<length xs. clist ! i ! j -e→ clist ! i ! Suc j; i < length xs⟧ ⟹ clist ! i ≠ []› and 3 goals remain*) apply clarify (*top goal: ‹⋀ys clist. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; (xs, s) # ys ∝ clist⟧ ⟹ ∀i<length xs. (xs ! i, s) # tl (clist ! i) ∈ cptn› and 2 goals remain*) apply (erule_tac x=i in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀(ys::('a::type com option list × 'a::type) list) (clist::('a::type com option × 'a::type) list list) i::nat. ⟦(xs::'a::type com option list) ≠ []; (xs, s::'a::type) # ys ∈ par_cptn; length clist = length xs; ∀i<length xs. clist ! i ∈ cp (xs ! i) s; (xs, s) # ys ∝ clist; i < length xs⟧ ⟹ (xs ! i, s) # tl (clist ! i) ∈ cptn› and 2 goals remain*) apply (simp add:cp_def (*‹cp ?P ?s ≡ {l. l ! 0 = (?P, ?s) ∧ l ∈ cptn}›*)) (*top goal: ‹⋀ys clist i. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; (xs, s) # ys ∝ clist; i < length xs; i < length xs ⟶ clist ! i ∈ cp (xs ! i) s⟧ ⟹ (xs ! i, s) # tl (clist ! i) ∈ cptn› and 2 goals remain*) apply (rule nth_tl_if (*‹⟦?ys ≠ []; ?ys ! 0 = ?a; ?P ?ys⟧ ⟹ ?P (?a # tl ?ys)›*)) (*top goal: ‹⋀ys clist i. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; (xs, s) # ys ∝ clist; i < length xs; clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn⟧ ⟹ (xs ! i, s) # tl (clist ! i) ∈ cptn› and 2 goals remain*) apply (simp add:conjoin_def (*‹?c ∝ ?clist ≡ same_length ?c ?clist ∧ same_state ?c ?clist ∧ same_program ?c ?clist ∧ compat_label ?c ?clist›*)) (*top goal: ‹⋀ys clist i. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; (xs, s) # ys ∝ clist; i < length xs; clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn⟧ ⟹ clist ! i ≠ []› and 4 goals remain*) apply clarify (*top goal: ‹⋀ys clist i. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; same_length ((xs, s) # ys) clist ∧ same_state ((xs, s) # ys) clist ∧ same_program ((xs, s) # ys) clist ∧ compat_label ((xs, s) # ys) clist; i < length xs; clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn⟧ ⟹ clist ! i ≠ []› and 4 goals remain*) apply (simp add:same_length_def (*‹same_length ?c ?clist ≡ ∀i<length ?clist. length (?clist ! i) = length ?c›*)) (*top goal: ‹⋀ys clist i. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; i < length xs; same_length ((xs, s) # ys) clist; clist ! i ! 0 = (xs ! i, s); clist ! i ∈ cptn; same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; compat_label ((xs, s) # ys) clist; clist ! i = []⟧ ⟹ False› and 4 goals remain*) apply (erule_tac x=i in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*), simp) (*top goal: ‹⋀ys clist i. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; i < length xs; ∀i<length xs. length (clist ! i) = Suc (length ys); [] ! 0 = (xs ! i, s); [] ∈ cptn; same_state ((xs, s) # ys) clist; same_program ((xs, s) # ys) clist; compat_label ((xs, s) # ys) clist; clist ! i = []⟧ ⟹ False› and 4 goals remain*) apply simp (*top goal: ‹⋀ys clist i. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; length clist = length xs; (xs, s) # ys ∝ clist; i < length xs; clist ! i ! 0 = (xs ! i, s) ∧ clist ! i ∈ cptn⟧ ⟹ clist ! i ! 0 = (xs ! i, s)› and 3 goals remain*) apply simp (*top goal: ‹⋀(ys::('a com option list × 'a) list) (clist::('a com option × 'a) list list) i::nat. ⟦(xs::'a com option list) ≠ []; (xs, s::'a) # ys ∈ par_cptn; length clist = length xs; (xs, s) # ys ∝ clist; i < length xs; clist ! i ! (0::nat) = (xs ! i, s) ∧ clist ! i ∈ cptn⟧ ⟹ clist ! i ∈ cptn› and 2 goals remain*) apply simp (*top goal: ‹⋀ys. ⟦xs ≠ []; (xs, s) # ys ∈ par_cptn; (xs, s) # ys ∉ {l. l ! 0 = (xs, s) ∧ l ∈ par_cptn}; (xs, s) # ys ∉ {c. ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ∈ cp (xs ! i) s) ∧ c ∝ clist}⟧ ⟹ ∃clist. length clist = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)› and 1 goal remains*) apply clarify (*goal: ‹⋀ys. ⟦xs ≠ []; par_cp xs s = {c. ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ∈ cp (xs ! i) s) ∧ c ∝ clist}; ∃clist. length clist = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)⟧ ⟹ (xs, s) # ys ∈ par_cptn›*) apply (erule_tac c="(xs, s) # ys" in equalityCE (*‹⟦(?A::?'a set) = (?B::?'a set); ⟦(?c::?'a) ∈ ?A; ?c ∈ ?B⟧ ⟹ ?P::bool; ⟦?c ∉ ?A; ?c ∉ ?B⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goal: ‹⋀(ys::('a::type com option list × 'a::type) list) clist::('a::type com option × 'a::type) list list. ⟦(xs::'a::type com option list) ≠ []; par_cp xs (s::'a::type) = {c::('a::type com option list × 'a::type) list. ∃clist::('a::type com option × 'a::type) list list. length clist = length xs ∧ (∀i<length clist. clist ! i ∈ cp (xs ! i) s) ∧ c ∝ clist}; length clist = length xs; (xs, s) # ys ∝ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist); ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn⟧ ⟹ (xs, s) # ys ∈ par_cptn›*) apply (simp add:par_cp_def (*‹par_cp ?P ?s ≡ {l. l ! 0 = (?P, ?s) ∧ l ∈ par_cptn}›*)) (*top goal: ‹⋀ys clist. ⟦xs ≠ []; length clist = length xs; (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist); ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; (xs, s) # ys ∈ par_cp xs s; (xs, s) # ys ∈ {c. ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ∈ cp (xs ! i) s) ∧ c ∝ clist}⟧ ⟹ (xs, s) # ys ∈ par_cptn› and 1 goal remains*) apply simp (*goal: ‹⋀(ys::('a::type com option list × 'a::type) list) clist::('a::type com option × 'a::type) list list. ⟦(xs::'a::type com option list) ≠ []; length clist = length xs; (xs, s::'a::type) # ys ∝ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist); ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; (xs, s) # ys ∉ par_cp xs s; (xs, s) # ys ∉ {c::('a::type com option list × 'a::type) list. ∃clist::('a::type com option × 'a::type) list list. length clist = length xs ∧ (∀i<length clist. clist ! i ∈ cp (xs ! i) s) ∧ c ∝ clist}⟧ ⟹ (xs, s) # ys ∈ par_cptn›*) apply (erule_tac x="map (λi. (fst i, s) # snd i) (zip xs clist)" in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*goal: ‹⋀ys clist. ⟦xs ≠ []; length clist = length xs; (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist); ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; (xs, s) # ys ∉ par_cp xs s; ∀clist. length clist = length xs ⟶ (∃i<length xs. clist ! i ∉ cp (xs ! i) s) ∨ ¬ (xs, s) # ys ∝ clist⟧ ⟹ (xs, s) # ys ∈ par_cptn›*) apply simp (*goal: ‹⋀ys clist. ⟦xs ≠ []; length clist = length xs; (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist); ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; (xs, s) # ys ∉ par_cp xs s; length (map (λi. (fst i, s) # snd i) (zip xs clist)) = length xs ⟶ (∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ∉ cp (xs ! i) s) ∨ ¬ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist)⟧ ⟹ (xs, s) # ys ∈ par_cptn›*) apply clarify (*goal: ‹⋀ys clist. ⟦xs ≠ []; length clist = length xs; (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist); ∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn; (xs, s) # ys ∉ par_cp xs s; ∃i<length xs. map (λi. (fst i, s) # snd i) (zip xs clist) ! i ∉ cp (xs ! i) s⟧ ⟹ (xs, s) # ys ∈ par_cptn›*) by (simp add:cp_def (*‹cp ?P ?s ≡ {l. l ! 0 = (?P, ?s) ∧ l ∈ cptn}›*)) theorem one: "xs≠[] ⟹ par_cp xs s = {c. ∃clist. (length clist)=(length xs) ∧ (∀i<length clist. (clist!i) ∈ cp(xs!i) s) ∧ c ∝ clist}" apply (frule one_iff_aux (*‹?xs ≠ [] ⟹ (∀ys. ((?xs, ?s) # ys ∈ par_cptn) = (∃clist. length clist = length ?xs ∧ (?xs, ?s) # ys ∝ map (λi. (fst i, ?s) # snd i) (zip ?xs clist) ∧ (∀i<length ?xs. (?xs ! i, ?s) # clist ! i ∈ cptn))) = (par_cp ?xs ?s = {c. ∃clist. length clist = length ?xs ∧ (∀i<length clist. clist ! i ∈ cp (?xs ! i) ?s) ∧ c ∝ clist})›*)) (*goal: ‹xs ≠ [] ⟹ par_cp xs s = {c. ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ∈ cp (xs ! i) s) ∧ c ∝ clist}›*) apply (drule sym (*‹(?s::?'a) = (?t::?'a) ⟹ ?t = ?s›*)) (*goal: ‹⟦xs ≠ []; (∀ys. ((xs, ?s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (xs, ?s) # ys ∝ map (λi. (fst i, ?s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, ?s) # clist ! i ∈ cptn))) = (par_cp xs ?s = {c. ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ∈ cp (xs ! i) ?s) ∧ c ∝ clist})⟧ ⟹ par_cp xs s = {c. ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ∈ cp (xs ! i) s) ∧ c ∝ clist}›*) apply (erule iffD2 (*‹⟦(?P::bool) = (?Q::bool); ?Q⟧ ⟹ ?P›*)) (*goal: ‹⟦xs ≠ []; (par_cp xs ?s = {c. ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ∈ cp (xs ! i) ?s) ∧ c ∝ clist}) = (∀ys. ((xs, ?s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (xs, ?s) # ys ∝ map (λi. (fst i, ?s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, ?s) # clist ! i ∈ cptn)))⟧ ⟹ par_cp xs s = {c. ∃clist. length clist = length xs ∧ (∀i<length clist. clist ! i ∈ cp (xs ! i) s) ∧ c ∝ clist}›*) apply clarify (*goal: ‹xs ≠ [] ⟹ ∀ys. ((xs, s) # ys ∈ par_cptn) = (∃clist. length clist = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn))›*) apply (rule iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*)) (*goals: 1. ‹⋀ys::('a::type com option list × 'a::type) list. ⟦(xs::'a::type com option list) ≠ []; (xs, s::'a::type) # ys ∈ par_cptn⟧ ⟹ ∃clist::('a::type com option × 'a::type) list list. length clist = length xs ∧ (xs, s) # ys ∝ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)› 2. ‹⋀ys::('a::type com option list × 'a::type) list. ⟦(xs::'a::type com option list) ≠ []; ∃clist::('a::type com option × 'a::type) list list. length clist = length xs ∧ (xs, s::'a::type) # ys ∝ map (λi::'a::type com option × ('a::type com option × 'a::type) list. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)⟧ ⟹ (xs, s) # ys ∈ par_cptn› discuss goal 1*) apply (erule aux_onlyif (*‹(?xs::?'a com option list, ?s::?'a) # (?ys::(?'a com option list × ?'a) list) ∈ par_cptn ⟹ ∃clist::(?'a com option × ?'a) list list. length clist = length ?xs ∧ (?xs, ?s) # ?ys ∝ map (λi::?'a com option × (?'a com option × ?'a) list. (fst i, ?s) # snd i) (zip ?xs clist) ∧ (∀i<length ?xs. (?xs ! i, ?s) # clist ! i ∈ cptn)›*)) (*discuss goal 2*) apply clarify (*goal: ‹⋀ys. ⟦xs ≠ []; ∃clist. length clist = length xs ∧ (xs, s) # ys ∝ map (λi. (fst i, s) # snd i) (zip xs clist) ∧ (∀i<length xs. (xs ! i, s) # clist ! i ∈ cptn)⟧ ⟹ (xs, s) # ys ∈ par_cptn›*) apply (force intro:aux_if (*‹length ?clist = length ?xs ∧ (∀i<length ?xs. (?xs ! i, ?s) # ?clist ! i ∈ cptn) ∧ (?xs, ?s) # ?ys ∝ map (λi. (fst i, ?s) # snd i) (zip ?xs ?clist) ⟹ (?xs, ?s) # ?ys ∈ par_cptn›*)) (*proven 2 subgoals*) . end
{ "path": "Isabelle2024/src/HOL/Hoare_Parallel/RG_Tran.thy", "repo": "Isabelle2024", "sha": "3bca39ddbedfada250c2911e1fc00f4906eea0c9b78c97fc7a3813cd5c7cfdd9" }
(* Author: René Thiemann License: LGPL *) section ‹Show Implemetation for Real Numbers via Rational Numbers› text ‹We just provide an implementation for show of real numbers where we assume that real numbers are implemented via rational numbers.› theory Show_Real_Impl imports Show_Real Show_Instances begin text ‹We now define @{const show_real}.› overloading show_real ≡ show_real begin definition show_real where "show_real x ≡ (if (∃ y. x = Ratreal y) then show (THE y. x = Ratreal y) else ''Irrational'')" end lemma show_real_code[code]: "show_real (Ratreal x) = show x" unfolding show_real_def (*goal: ‹(if ∃y::rat. Ratreal (x::rat) = Ratreal y then show (THE y::rat. Ratreal x = Ratreal y) else ''Irrational'') = show x›*) by auto end
{ "path": "afp-2025-02-12/thys/Show/Show_Real_Impl.thy", "repo": "afp-2025-02-12", "sha": "b143d6248421486ac8bbf5bd776f637e555ed6d192e302b557e4e3866485c6ce" }
section ‹Denotational semantics of Circus actions› theory Denotational_Semantics imports Circus_Actions Var_list begin text ‹In this section, we introduce the definitions of Circus actions denotational semantics. We provide the proof of well-formedness of every action. We also provide proofs concerning the monotonicity of operators over actions.› subsection ‹Skip› definition Skip :: "('θ::ev_eq,'σ) action" where "Skip ≡ action_of (R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬wait A' ∧ more A = more A'))" lemma Skip_is_action: "(R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬wait A' ∧ more A = more A')) ∈ {p. is_CSP_process p}" sorry lemmas Skip_is_CSP = Skip_is_action[simplified] lemma relation_of_Skip: "relation_of Skip = (R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬wait A' ∧ more A = more A'))" by (simp add: Skip_def (*‹Skip ≡ action_of (R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A'))›*) action_of_inverse (*‹?y ∈ {p. is_CSP_process p} ⟹ action.relation_of (action_of ?y) = ?y›*) Skip_is_CSP (*‹is_CSP_process (R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A'))›*)) definition CSP3::"(('θ::ev_eq,'σ) alphabet_rp) Healthiness_condition" where "CSP3 (P) ≡ relation_of Skip ;; P" definition CSP4::"(('θ::ev_eq,'σ) alphabet_rp) Healthiness_condition" where "CSP4 (P) ≡ P ;; relation_of Skip" lemma Skip_is_CSP3: "(relation_of Skip) is CSP3 healthy" apply (auto simp: relation_of_Skip (*‹action.relation_of Skip = R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A')›*) rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) CSP3_def (*‹CSP3 ?P ≡ action.relation_of Skip ;; ?P›*)) (*goals: 1. ‹⋀a b. ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (a, b) ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› 2. ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (aa, ba); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (aa, c)› discuss goal 1*) apply (split cond_splits) (*goals: 1. ‹⋀a b. ⟦(wait ∘ fst) (a, b); case (a, b) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› 2. ‹⋀a b. ⟦¬ (wait ∘ fst) (a, b); case (a, b) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› discuss goal 1*) apply simp (*top goal: ‹⋀a b. ⟦(wait ∘ fst) (a, b); case (a, b) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› and 2 goals remain*) apply (rule_tac b=b in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀a b. ⟦wait a; ¬ ok a ∧ tr a ≤ tr b ∨ ok b ∧ tr a = tr b ∧ wait b ∧ ref a = ref b ∧ alpha_rp.more a = alpha_rp.more b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (a, b)› 2. ‹⋀a b. ⟦wait a; ¬ ok a ∧ tr a ≤ tr b ∨ ok b ∧ tr a = tr b ∧ wait b ∧ ref a = ref b ∧ alpha_rp.more a = alpha_rp.more b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (b, b)› discuss goal 1*) apply (split cond_splits) (*top goal: ‹⋀a b. ⟦wait a; ¬ ok a ∧ tr a ≤ tr b ∨ ok b ∧ tr a = tr b ∧ wait b ∧ ref a = ref b ∧ alpha_rp.more a = alpha_rp.more b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (a, b)› and 3 goals remain*) apply simp (*discuss goal 2*) apply (split cond_splits) (*top goal: ‹⋀a b. ⟦wait a; ¬ ok a ∧ tr a ≤ tr b ∨ ok b ∧ tr a = tr b ∧ wait b ∧ ref a = ref b ∧ alpha_rp.more a = alpha_rp.more b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (b, b)› and 2 goals remain*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*top goal: ‹⋀a b. ⟦¬ (wait ∘ fst) (a, b); case (a, b) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› and 1 goal remains*) apply (rule_tac b=b in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀a b. ⟦¬ wait a; (ok a ∧ true (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ ok b ∧ tr b - tr a = [] ∧ ¬ wait b ∧ alpha_rp.more a = alpha_rp.more b) ∧ tr a ≤ tr b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (a, b)› 2. ‹⋀a b. ⟦¬ wait a; (ok a ∧ true (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ ok b ∧ tr b - tr a = [] ∧ ¬ wait b ∧ alpha_rp.more a = alpha_rp.more b) ∧ tr a ≤ tr b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (b, b)› discuss goal 1*) apply (split cond_splits) (*top goal: ‹⋀a b. ⟦¬ wait a; (ok a ∧ true (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ ok b ∧ tr b - tr a = [] ∧ ¬ wait b ∧ alpha_rp.more a = alpha_rp.more b) ∧ tr a ≤ tr b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (a, b)› and 2 goals remain*) apply simp (*discuss goal 2*) apply (split cond_splits) (*top goal: ‹⋀a b. ⟦¬ wait a; (ok a ∧ true (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ ok b ∧ tr b - tr a = [] ∧ ¬ wait b ∧ alpha_rp.more a = alpha_rp.more b) ∧ tr a ≤ tr b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (b, b)› and 1 goal remains*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply (split cond_splits) (*goal: ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (aa, ba); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (aa, c)›*) apply simp (*goal: ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (aa, ba); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A')) ∧ (¬ (wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))›*) apply (split cond_splits) (*goals: 1. ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c); (wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (wait aa ⟶ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ (¬ wait aa ⟶ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ tr aa ≤ tr c)› 2. ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c); ¬ (wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ (wait aa ⟶ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ (¬ wait aa ⟶ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ tr aa ≤ tr c)› discuss goal 1*) apply simp (*top goal: ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c); (wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (wait aa ⟶ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ (¬ wait aa ⟶ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ tr aa ≤ tr c)› and 1 goal remains*) apply (split cond_splits) (*goals: 1. ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ wait ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; (wait ∘ fst) (ba, c); case (ba, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› 2. ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ wait ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; ¬ (wait ∘ fst) (ba, c); case (ba, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› discuss goal 1*) apply simp (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ wait ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; (wait ∘ fst) (ba, c); case (ba, c) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› and 2 goals remain*) apply ((auto simp add: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*))[1]) (*discuss goal 2*) apply simp (*top goal: ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ wait ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; ¬ (wait ∘ fst) (ba, c); case (ba, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› and 1 goal remains*) apply ((auto simp add: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*))[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*goal: ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c); ¬ (wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ (wait aa ⟶ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ (¬ wait aa ⟶ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ tr aa ≤ tr c)›*) apply (split cond_splits) (*goals: 1. ‹⋀aa ba c. ⟦¬ wait aa; (wait ∘ fst) (ba, c); ok aa ∧ true (aa⦇tr := []⦈, ba⦇tr := tr ba - tr aa⦈) ⟶ ok ba ∧ tr ba - tr aa = [] ∧ ¬ wait ba ∧ alpha_rp.more aa = alpha_rp.more ba; tr aa ≤ tr ba; case (ba, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ tr aa ≤ tr c› 2. ‹⋀aa ba c. ⟦¬ wait aa; ¬ (wait ∘ fst) (ba, c); ok aa ∧ true (aa⦇tr := []⦈, ba⦇tr := tr ba - tr aa⦈) ⟶ ok ba ∧ tr ba - tr aa = [] ∧ ¬ wait ba ∧ alpha_rp.more aa = alpha_rp.more ba; tr aa ≤ tr ba; case (ba, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ tr aa ≤ tr c› discuss goal 1*) apply simp (*top goal: ‹⋀aa ba c. ⟦¬ wait aa; (wait ∘ fst) (ba, c); ok aa ∧ true (aa⦇tr := []⦈, ba⦇tr := tr ba - tr aa⦈) ⟶ ok ba ∧ tr ba - tr aa = [] ∧ ¬ wait ba ∧ alpha_rp.more aa = alpha_rp.more ba; tr aa ≤ tr ba; case (ba, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ tr aa ≤ tr c› and 1 goal remains*) apply ((auto simp add: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*))[1]) (*discuss goal 2*) apply simp (*goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦¬ wait aa; ¬ (wait ∘ fst) (ba, c); ok aa ∧ true (aa⦇tr := []⦈, ba⦇tr := tr ba - tr aa⦈) ⟶ ok ba ∧ tr ba - tr aa = [] ∧ ¬ wait ba ∧ alpha_rp.more aa = alpha_rp.more ba; tr aa ≤ tr ba; case (ba, c) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ tr aa ≤ tr c›*) apply ((auto simp add: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*))[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma Skip_is_CSP4: "(relation_of Skip) is CSP4 healthy" apply (auto simp: relation_of_Skip (*‹action.relation_of Skip = R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A')›*) rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) CSP4_def (*‹CSP4 ?P ≡ ?P ;; action.relation_of Skip›*)) (*goals: 1. ‹⋀a b. ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (a, b) ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› 2. ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (aa, ba); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (aa, c)› discuss goal 1*) apply (split cond_splits) (*goals: 1. ‹⋀a b. ⟦(wait ∘ fst) (a, b); case (a, b) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› 2. ‹⋀a b. ⟦¬ (wait ∘ fst) (a, b); case (a, b) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› discuss goal 1*) apply simp (*top goal: ‹⋀a b. ⟦(wait ∘ fst) (a, b); case (a, b) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› and 2 goals remain*) apply (rule_tac b=b in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀a b. ⟦wait a; ¬ ok a ∧ tr a ≤ tr b ∨ ok b ∧ tr a = tr b ∧ wait b ∧ ref a = ref b ∧ alpha_rp.more a = alpha_rp.more b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (a, b)› 2. ‹⋀a b. ⟦wait a; ¬ ok a ∧ tr a ≤ tr b ∨ ok b ∧ tr a = tr b ∧ wait b ∧ ref a = ref b ∧ alpha_rp.more a = alpha_rp.more b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (b, b)› discuss goal 1*) apply (split cond_splits) (*top goal: ‹⋀a b. ⟦wait a; ¬ ok a ∧ tr a ≤ tr b ∨ ok b ∧ tr a = tr b ∧ wait b ∧ ref a = ref b ∧ alpha_rp.more a = alpha_rp.more b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (a, b)› and 3 goals remain*) apply simp (*discuss goal 2*) apply (split cond_splits) (*top goal: ‹⋀a b. ⟦wait a; ¬ ok a ∧ tr a ≤ tr b ∨ ok b ∧ tr a = tr b ∧ wait b ∧ ref a = ref b ∧ alpha_rp.more a = alpha_rp.more b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (b, b)› and 2 goals remain*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*top goal: ‹⋀a b. ⟦¬ (wait ∘ fst) (a, b); case (a, b) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› and 1 goal remains*) apply (rule_tac b=b in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀a b. ⟦¬ wait a; (ok a ∧ true (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ ok b ∧ tr b - tr a = [] ∧ ¬ wait b ∧ alpha_rp.more a = alpha_rp.more b) ∧ tr a ≤ tr b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (a, b)› 2. ‹⋀a b. ⟦¬ wait a; (ok a ∧ true (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ ok b ∧ tr b - tr a = [] ∧ ¬ wait b ∧ alpha_rp.more a = alpha_rp.more b) ∧ tr a ≤ tr b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (b, b)› discuss goal 1*) apply (split cond_splits) (*top goal: ‹⋀a b. ⟦¬ wait a; (ok a ∧ true (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ ok b ∧ tr b - tr a = [] ∧ ¬ wait b ∧ alpha_rp.more a = alpha_rp.more b) ∧ tr a ≤ tr b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (a, b)› and 2 goals remain*) apply simp (*discuss goal 2*) apply (split cond_splits) (*top goal: ‹⋀a b. ⟦¬ wait a; (ok a ∧ true (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ ok b ∧ tr b - tr a = [] ∧ ¬ wait b ∧ alpha_rp.more a = alpha_rp.more b) ∧ tr a ≤ tr b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (b, b)› and 1 goal remains*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply (split cond_splits) (*goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (aa, ba); ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (aa, c)›*) apply simp (*goal: ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (aa, ba); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A')) ∧ (¬ (wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))›*) apply (split cond_splits) (*goals: 1. ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c); (wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (wait aa ⟶ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ (¬ wait aa ⟶ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ tr aa ≤ tr c)› 2. ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c); ¬ (wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ (wait aa ⟶ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ (¬ wait aa ⟶ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ tr aa ≤ tr c)› discuss goal 1*) apply simp (*top goal: ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c); (wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (wait aa ⟶ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ (¬ wait aa ⟶ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ tr aa ≤ tr c)› and 1 goal remains*) apply (split cond_splits) (*goals: 1. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ wait ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; (wait ∘ fst) (ba, c); case (ba, c) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› 2. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ wait ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; ¬ (wait ∘ fst) (ba, c); case (ba, c) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› discuss goal 1*) apply simp (*top goal: ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ wait ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; (wait ∘ fst) (ba, c); case (ba, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› and 2 goals remain*) apply ((auto simp add: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*))[1]) (*discuss goal 2*) apply simp (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ wait ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; ¬ (wait ∘ fst) (ba, c); case (ba, c) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› and 1 goal remains*) apply ((auto simp add: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*))[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*goal: ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c); ¬ (wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ (wait aa ⟶ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ (¬ wait aa ⟶ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ tr aa ≤ tr c)›*) apply (split cond_splits) (*goals: 1. ‹⋀aa ba c. ⟦¬ wait aa; (wait ∘ fst) (ba, c); ok aa ∧ true (aa⦇tr := []⦈, ba⦇tr := tr ba - tr aa⦈) ⟶ ok ba ∧ tr ba - tr aa = [] ∧ ¬ wait ba ∧ alpha_rp.more aa = alpha_rp.more ba; tr aa ≤ tr ba; case (ba, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ tr aa ≤ tr c› 2. ‹⋀aa ba c. ⟦¬ wait aa; ¬ (wait ∘ fst) (ba, c); ok aa ∧ true (aa⦇tr := []⦈, ba⦇tr := tr ba - tr aa⦈) ⟶ ok ba ∧ tr ba - tr aa = [] ∧ ¬ wait ba ∧ alpha_rp.more aa = alpha_rp.more ba; tr aa ≤ tr ba; case (ba, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ tr aa ≤ tr c› discuss goal 1*) apply simp (*top goal: ‹⋀aa ba c. ⟦¬ wait aa; (wait ∘ fst) (ba, c); ok aa ∧ true (aa⦇tr := []⦈, ba⦇tr := tr ba - tr aa⦈) ⟶ ok ba ∧ tr ba - tr aa = [] ∧ ¬ wait ba ∧ alpha_rp.more aa = alpha_rp.more ba; tr aa ≤ tr ba; case (ba, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ tr aa ≤ tr c› and 1 goal remains*) apply ((auto simp add: prefix_def (*‹?xs::?'a list ≤ ?ys::?'a list = (∃zs::?'a list. ?ys = ?xs @ zs)›*))[1]) (*discuss goal 2*) apply simp (*goal: ‹⋀aa ba c. ⟦¬ wait aa; ¬ (wait ∘ fst) (ba, c); ok aa ∧ true (aa⦇tr := []⦈, ba⦇tr := tr ba - tr aa⦈) ⟶ ok ba ∧ tr ba - tr aa = [] ∧ ¬ wait ba ∧ alpha_rp.more aa = alpha_rp.more ba; tr aa ≤ tr ba; case (ba, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ tr aa ≤ tr c›*) apply ((auto simp add: prefix_def (*‹?xs::?'a::type list ≤ ?ys::?'a::type list = (∃zs::?'a::type list. ?ys = ?xs @ zs)›*))[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma Skip_comp_absorb: "(relation_of Skip ;; relation_of Skip) = relation_of Skip" apply (auto simp: relation_of_Skip (*‹action.relation_of Skip = R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A')›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) true_def (*‹true ≡ λA. True›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*)) (*goals: 1. ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (aa, ba); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (aa, c)› 2. ‹⋀a b. ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (a, b) ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› discuss goal 1*) apply (clarsimp split: cond_splits (*‹?A ((?P ◃ ?b ▹ ?Q) ?x) = ((?b ?x ⟶ ?A (?P ?x)) ∧ (¬ ?b ?x ⟶ ?A (?Q ?x)))› ‹?A ((?P ◃ ?b ▹ ?Q) ?x) = (¬ (?b ?x ∧ ¬ ?A (?P ?x) ∨ ¬ ?b ?x ∧ ¬ ?A (?Q ?x)))›*)) (*goals: 1. ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ref aa = ref c ⟶ wait c ⟶ tr aa = tr c ⟶ ok c ⟶ alpha_rp.more aa ≠ alpha_rp.more c⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c› 2. ‹⋀aa ba c. ⟦wait aa; ¬ wait ba; ¬ ok aa; tr aa ≤ tr ba; ok ba ⟶ ok c ∧ tr c - tr ba = [] ∧ ¬ wait c ∧ alpha_rp.more ba = alpha_rp.more c; tr ba ≤ tr c; ref aa = ref c ⟶ wait c ⟶ tr aa = tr c ⟶ ok c ⟶ alpha_rp.more aa ≠ alpha_rp.more c⟧ ⟹ tr aa ≤ tr c› 3. ‹⋀aa ba c. ⟦¬ wait aa; wait ba; ¬ ok aa; tr aa ≤ tr ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c⟧ ⟹ tr aa ≤ tr c› 4. ‹⋀aa ba c. ⟦¬ wait aa; ¬ wait ba; ok aa ⟶ ok ba ∧ tr ba - tr aa = [] ∧ alpha_rp.more aa = alpha_rp.more ba; tr aa ≤ tr ba; ok ba ⟶ ok c ∧ tr c - tr ba = [] ∧ ¬ wait c ∧ alpha_rp.more ba = alpha_rp.more c; tr ba ≤ tr c⟧ ⟹ (ok aa ⟶ tr c - tr aa = []) ∧ tr aa ≤ tr c› discuss goal 1*) apply (case_tac "ok aa") (*goals: 1. ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ref aa = ref c ⟶ wait c ⟶ tr aa = tr c ⟶ ok c ⟶ alpha_rp.more aa ≠ alpha_rp.more c; ok aa⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c› 2. ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ref aa = ref c ⟶ wait c ⟶ tr aa = tr c ⟶ ok c ⟶ alpha_rp.more aa ≠ alpha_rp.more c; ¬ ok aa⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ref aa = ref c ⟶ wait c ⟶ tr aa = tr c ⟶ ok c ⟶ alpha_rp.more aa ≠ alpha_rp.more c; ¬ ok aa⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c› and 4 goals remain*) apply (erule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦wait aa; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ref aa = ref c ⟶ wait c ⟶ tr aa = tr c ⟶ ok c ⟶ alpha_rp.more aa ≠ alpha_rp.more c; ¬ ok aa; tr aa ≤ tr ba⟧ ⟹ tr aa ≤ tr c› 2. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦wait aa; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ref aa = ref c ⟶ wait c ⟶ tr aa = tr c ⟶ ok c ⟶ alpha_rp.more aa ≠ alpha_rp.more c; ¬ ok aa; ok ba ∧ tr aa = tr ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba⟧ ⟹ tr aa ≤ tr c› discuss goal 1*) apply (erule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹⋀aa ba c. ⟦wait aa; wait ba; ref aa = ref c ⟶ wait c ⟶ tr aa = tr c ⟶ ok c ⟶ alpha_rp.more aa ≠ alpha_rp.more c; ¬ ok aa; tr aa ≤ tr ba; ¬ ok ba ∧ tr ba ≤ tr c⟧ ⟹ tr aa ≤ tr c› 2. ‹⋀aa ba c. ⟦wait aa; wait ba; ref aa = ref c ⟶ wait c ⟶ tr aa = tr c ⟶ ok c ⟶ alpha_rp.more aa ≠ alpha_rp.more c; ¬ ok aa; tr aa ≤ tr ba; ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c⟧ ⟹ tr aa ≤ tr c› discuss goal 1*) apply (clarsimp simp: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*)) (*discuss goal 2*) apply (clarsimp simp: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply (erule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹⋀aa ba c. ⟦wait aa; wait ba; ref aa = ref c ⟶ wait c ⟶ tr aa = tr c ⟶ ok c ⟶ alpha_rp.more aa ≠ alpha_rp.more c; ¬ ok aa; ok ba ∧ tr aa = tr ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; ¬ ok ba ∧ tr ba ≤ tr c⟧ ⟹ tr aa ≤ tr c› 2. ‹⋀aa ba c. ⟦wait aa; wait ba; ref aa = ref c ⟶ wait c ⟶ tr aa = tr c ⟶ ok c ⟶ alpha_rp.more aa ≠ alpha_rp.more c; ¬ ok aa; ok ba ∧ tr aa = tr ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c⟧ ⟹ tr aa ≤ tr c› discuss goal 1*) apply (clarsimp simp: prefix_def (*‹?xs::?'a list ≤ ?ys::?'a list = (∃zs::?'a list. ?ys = ?xs @ zs)›*)) (*discuss goal 2*) apply (clarsimp simp: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*discuss goal 3*) apply (erule disjE (*‹⟦(?P::bool) ∨ (?Q::bool); ?P ⟹ ?R::bool; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹⋀aa ba c. ⟦¬ wait aa; wait ba; ¬ ok aa; tr aa ≤ tr ba; ¬ ok ba ∧ tr ba ≤ tr c⟧ ⟹ tr aa ≤ tr c› 2. ‹⋀aa ba c. ⟦¬ wait aa; wait ba; ¬ ok aa; tr aa ≤ tr ba; ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c⟧ ⟹ tr aa ≤ tr c› discuss goal 1*) apply (clarsimp simp: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*)) (*discuss goal 2*) apply (clarsimp simp: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*)) (*proven 2 subgoals*) (*discuss goal 4*) apply (case_tac "ok aa") (*goals: 1. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦¬ wait aa; ¬ wait ba; ok aa ⟶ ok ba ∧ tr ba - tr aa = [] ∧ alpha_rp.more aa = alpha_rp.more ba; tr aa ≤ tr ba; ok ba ⟶ ok c ∧ tr c - tr ba = [] ∧ ¬ wait c ∧ alpha_rp.more ba = alpha_rp.more c; tr ba ≤ tr c; ok aa⟧ ⟹ (ok aa ⟶ tr c - tr aa = []) ∧ tr aa ≤ tr c› 2. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦¬ wait aa; ¬ wait ba; ok aa ⟶ ok ba ∧ tr ba - tr aa = [] ∧ alpha_rp.more aa = alpha_rp.more ba; tr aa ≤ tr ba; ok ba ⟶ ok c ∧ tr c - tr ba = [] ∧ ¬ wait c ∧ alpha_rp.more ba = alpha_rp.more c; tr ba ≤ tr c; ¬ ok aa⟧ ⟹ (ok aa ⟶ tr c - tr aa = []) ∧ tr aa ≤ tr c› discuss goal 1*) apply simp (*top goal: ‹⋀aa ba c. ⟦¬ wait aa; ¬ wait ba; ok aa ⟶ ok ba ∧ tr ba - tr aa = [] ∧ alpha_rp.more aa = alpha_rp.more ba; tr aa ≤ tr ba; ok ba ⟶ ok c ∧ tr c - tr ba = [] ∧ ¬ wait c ∧ alpha_rp.more ba = alpha_rp.more c; tr ba ≤ tr c; ok aa⟧ ⟹ (ok aa ⟶ tr c - tr aa = []) ∧ tr aa ≤ tr c› and 2 goals remain*) apply (clarsimp simp: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*)) (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 4 subgoals*) (*discuss goal 2*) apply (clarsimp split: cond_splits (*‹?A ((?P ◃ ?b ▹ ?Q) ?x) = ((?b ?x ⟶ ?A (?P ?x)) ∧ (¬ ?b ?x ⟶ ?A (?Q ?x)))› ‹?A ((?P ◃ ?b ▹ ?Q) ?x) = (¬ (?b ?x ∧ ¬ ?A (?P ?x) ∨ ¬ ?b ?x ∧ ¬ ?A (?Q ?x)))›*)) (*goals: 1. ‹⋀a b. ⟦wait a; ¬ ok a ∧ tr a ≤ tr b ∨ ok b ∧ tr a = tr b ∧ wait b ∧ ref a = ref b ∧ alpha_rp.more a = alpha_rp.more b⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› 2. ‹⋀a b. ⟦¬ wait a; ok a ⟶ ok b ∧ tr b - tr a = [] ∧ ¬ wait b ∧ alpha_rp.more a = alpha_rp.more b; tr a ≤ tr b⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› discuss goal 1*) apply (rule_tac b=a in comp_intro (*‹⟦(?P::?'a × ?'b ⇒ bool) (?a::?'a, ?b::?'b); (?Q::?'b × ?'c ⇒ bool) (?b, ?c::?'c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀(a::('a, 'b) alpha_rp_scheme) b::('a, 'b) alpha_rp_scheme. ⟦wait a; ¬ ok a ∧ tr a ≤ tr b ∨ ok b ∧ tr a = tr b ∧ wait b ∧ ref a = ref b ∧ alpha_rp.more a = alpha_rp.more b⟧ ⟹ ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (a, a)› 2. ‹⋀(a::('a, 'b) alpha_rp_scheme) b::('a, 'b) alpha_rp_scheme. ⟦wait a; ¬ ok a ∧ tr a ≤ tr b ∨ ok b ∧ tr a = tr b ∧ wait b ∧ ref a = ref b ∧ alpha_rp.more a = alpha_rp.more b⟧ ⟹ ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (a, b)› discuss goal 1*) apply (clarsimp split: cond_splits (*‹?A ((?P ◃ ?b ▹ ?Q) ?x) = ((?b ?x ⟶ ?A (?P ?x)) ∧ (¬ ?b ?x ⟶ ?A (?Q ?x)))› ‹?A ((?P ◃ ?b ▹ ?Q) ?x) = (¬ (?b ?x ∧ ¬ ?A (?P ?x) ∨ ¬ ?b ?x ∧ ¬ ?A (?Q ?x)))›*)) (*discuss goal 2*) apply (clarsimp split: cond_splits (*‹?A ((?P ◃ ?b ▹ ?Q) ?x) = ((?b ?x ⟶ ?A (?P ?x)) ∧ (¬ ?b ?x ⟶ ?A (?Q ?x)))› ‹?A ((?P ◃ ?b ▹ ?Q) ?x) = (¬ (?b ?x ∧ ¬ ?A (?P ?x) ∨ ¬ ?b ?x ∧ ¬ ?A (?Q ?x)))›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply (rule_tac b=a in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀a b. ⟦¬ wait a; ok a ⟶ ok b ∧ tr b - tr a = [] ∧ ¬ wait b ∧ alpha_rp.more a = alpha_rp.more b; tr a ≤ tr b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (a, a)› 2. ‹⋀a b. ⟦¬ wait a; ok a ⟶ ok b ∧ tr b - tr a = [] ∧ ¬ wait b ∧ alpha_rp.more a = alpha_rp.more b; tr a ≤ tr b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (a, b)› discuss goal 1*) apply (clarsimp split: cond_splits (*‹?A ((?P ◃ ?b ▹ ?Q) ?x) = ((?b ?x ⟶ ?A (?P ?x)) ∧ (¬ ?b ?x ⟶ ?A (?Q ?x)))› ‹?A ((?P ◃ ?b ▹ ?Q) ?x) = (¬ (?b ?x ∧ ¬ ?A (?P ?x) ∨ ¬ ?b ?x ∧ ¬ ?A (?Q ?x)))›*)) (*discuss goal 2*) apply (clarsimp split: cond_splits (*‹(?A::bool ⇒ bool) (((?P::?'a × ?'a ⇒ bool) ◃ ?b::?'a × ?'a ⇒ bool ▹ (?Q::?'a × ?'a ⇒ bool)) (?x::?'a × ?'a)) = ((?b ?x ⟶ ?A (?P ?x)) ∧ (¬ ?b ?x ⟶ ?A (?Q ?x)))› ‹(?A::bool ⇒ bool) (((?P::?'a × ?'a ⇒ bool) ◃ ?b::?'a × ?'a ⇒ bool ▹ (?Q::?'a × ?'a ⇒ bool)) (?x::?'a × ?'a)) = (¬ (?b ?x ∧ ¬ ?A (?P ?x) ∨ ¬ ?b ?x ∧ ¬ ?A (?Q ?x)))›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . subsection ‹Stop› definition Stop :: "('θ::ev_eq,'σ) action" where "Stop ≡ action_of (R (true ⊢ λ(A, A'). tr A' = tr A ∧ wait A'))" lemma Stop_is_action: "(R (true ⊢ λ(A, A'). tr A' = tr A ∧ wait A')) ∈ {p. is_CSP_process p}" apply simp (*goal: ‹R (true ⊢ λ(A, A'). tr A' = tr A ∧ wait A') ∈ {p. is_CSP_process p}›*) apply (rule rd_is_CSP (*‹∀a b. ?r (a, b⦇ok := True⦈) ⟶ ?r (a, b⦇ok := False⦈) ⟹ is_CSP_process (R (?r ⊢ ?p))›*)) (*goal: ‹is_CSP_process (R (true ⊢ λ(A, A'). tr A' = tr A ∧ wait A'))›*) by auto lemmas Stop_is_CSP = Stop_is_action[simplified] lemma relation_of_Stop: "relation_of Stop = (R (true ⊢ λ(A, A'). tr A' = tr A ∧ wait A'))" by (simp add: Stop_def (*‹Stop ≡ action_of (R (true ⊢ λ(A, A'). tr A' = tr A ∧ wait A'))›*) action_of_inverse (*‹?y ∈ {p. is_CSP_process p} ⟹ action.relation_of (action_of ?y) = ?y›*) Stop_is_CSP (*‹is_CSP_process (R (true ⊢ λ(A, A'). tr A' = tr A ∧ wait A'))›*)) lemma Stop_is_CSP3: "(relation_of Stop) is CSP3 healthy" apply (auto simp: relation_of_Stop (*‹action.relation_of Stop = R (true ⊢ λ(A, A'). tr A' = tr A ∧ wait A')›*) relation_of_Skip (*‹action.relation_of Skip = R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A')›*) rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) CSP3_def (*‹CSP3 ?P ≡ action.relation_of Skip ;; ?P›*)) (*goals: 1. ‹⋀a b. ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (a, b) ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A'))) (a, b)› 2. ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (aa, ba); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (aa, c)› discuss goal 1*) apply (rule_tac b=a in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀a b. ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (a, b) ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (a, a)› 2. ‹⋀a b. ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (a, b) ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (a, b)› discuss goal 1*) apply (split cond_splits) (*top goal: ‹⋀a b. ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (a, b) ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (a, a)› and 2 goals remain*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply (split cond_splits) (*goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (aa, ba); ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (aa, c)›*) apply (split cond_splits) (*goals: 1. ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (ba, c); (wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ ((wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A')) ∧ (¬ (wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A'))› 2. ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (ba, c); ¬ (wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ ((wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A')) ∧ (¬ (wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A'))› discuss goal 1*) apply (split cond_splits) (*goals: 1. ‹⋀aa ba c. ⟦(wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'; (wait ∘ fst) (ba, c); case (ba, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ ((wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A')) ∧ (¬ (wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A'))› 2. ‹⋀aa ba c. ⟦(wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'; ¬ (wait ∘ fst) (ba, c); case (ba, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A'⟧ ⟹ ((wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A')) ∧ (¬ (wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A'))› discuss goal 1*) apply simp (*top goal: ‹⋀aa ba c. ⟦(wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'; (wait ∘ fst) (ba, c); case (ba, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ ((wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A')) ∧ (¬ (wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A'))› and 2 goals remain*) apply (case_tac "ok aa") (*goals: 1. ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ok aa⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› 2. ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ¬ ok aa⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*top goal: ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ¬ ok aa⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› and 2 goals remain*) apply (case_tac "tr aa ≤ tr ba") (*goals: 1. ‹⋀aa ba c. ⟦wait aa; tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ¬ ok aa; tr aa ≤ tr ba⟧ ⟹ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› 2. ‹⋀aa ba c. ⟦wait aa; tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ¬ ok aa; ¬ tr aa ≤ tr ba⟧ ⟹ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› discuss goal 1*) apply simp (*top goal: ‹⋀aa ba c. ⟦wait aa; tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ¬ ok aa; tr aa ≤ tr ba⟧ ⟹ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› and 3 goals remain*) apply (case_tac "ok ba") (*goals: 1. ‹⋀aa ba c. ⟦wait aa; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ¬ ok aa; tr aa ≤ tr ba; ok ba⟧ ⟹ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› 2. ‹⋀aa ba c. ⟦wait aa; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ¬ ok aa; tr aa ≤ tr ba; ¬ ok ba⟧ ⟹ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*top goal: ‹⋀aa ba c. ⟦wait aa; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ¬ ok aa; tr aa ≤ tr ba; ¬ ok ba⟧ ⟹ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› and 3 goals remain*) apply (case_tac "tr ba ≤ tr c") (*goals: 1. ‹⋀aa ba c. ⟦wait aa; wait ba; tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ¬ ok aa; tr aa ≤ tr ba; ¬ ok ba; tr ba ≤ tr c⟧ ⟹ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› 2. ‹⋀aa ba c. ⟦wait aa; wait ba; tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ¬ ok aa; tr aa ≤ tr ba; ¬ ok ba; ¬ tr ba ≤ tr c⟧ ⟹ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› discuss goal 1*) apply simp (*top goal: ‹⋀aa ba c. ⟦wait aa; wait ba; tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ¬ ok aa; tr aa ≤ tr ba; ¬ ok ba; tr ba ≤ tr c⟧ ⟹ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› and 4 goals remain*) apply (rule disjI1 (*‹?P ⟹ ?P ∨ ?Q›*)) (*top goal: ‹⋀aa ba c. ⟦wait aa; wait ba; ¬ ok aa; tr aa ≤ tr ba; ¬ ok ba; tr ba ≤ tr c⟧ ⟹ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› and 4 goals remain*) apply (simp add: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*)) (*top goal: ‹⋀aa ba c. ⟦wait aa; wait ba; ¬ ok aa; tr aa ≤ tr ba; ¬ ok ba; tr ba ≤ tr c⟧ ⟹ tr aa ≤ tr c› and 4 goals remain*) apply (erule exE (*‹⟦∃x. ?P x; ⋀x. ?P x ⟹ ?Q⟧ ⟹ ?Q›*)) (*top goal: ‹⋀aa ba c. ⟦wait aa; wait ba; ¬ ok aa; ∃zs. tr ba = tr aa @ zs; ¬ ok ba; ∃zs. tr c = tr ba @ zs⟧ ⟹ ∃zs. tr c = tr aa @ zs› and 4 goals remain*) apply (erule exE (*‹⟦∃x. ?P x; ⋀x. ?P x ⟹ ?Q⟧ ⟹ ?Q›*)) (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) (c::('a, 'b) alpha_rp_scheme) zs::'a list. ⟦wait aa; wait ba; ¬ ok aa; ¬ ok ba; ∃zs::'a list. tr c = tr ba @ zs; tr ba = tr aa @ zs⟧ ⟹ ∃zs::'a list. tr c = tr aa @ zs› and 4 goals remain*) apply (rule_tac x="zs@zsa" in exI (*‹(?P::?'a::type ⇒ bool) (?x::?'a::type) ⟹ ∃x::?'a::type. ?P x›*)) (*top goal: ‹⋀aa ba c zs zsa. ⟦wait aa; wait ba; ¬ ok aa; ¬ ok ba; tr ba = tr aa @ zs; tr c = tr ba @ zsa⟧ ⟹ ∃zs. tr c = tr aa @ zs› and 4 goals remain*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*top goal: ‹⋀aa ba c. ⟦(wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'; ¬ (wait ∘ fst) (ba, c); case (ba, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A'⟧ ⟹ ((wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A')) ∧ (¬ (wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A'))› and 1 goal remains*) apply (rule disjI1 (*‹?P ⟹ ?P ∨ ?Q›*)) (*top goal: ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba; ¬ wait ba; (ok ba ∧ true (ba⦇tr := []⦈, c⦇tr := tr c - tr ba⦈) ⟶ ok c ∧ tr c - tr ba = [] ∧ wait c) ∧ tr ba ≤ tr c⟧ ⟹ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› and 1 goal remains*) apply (simp add: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*)) (*top goal: ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba; ¬ wait ba; (ok ba ∧ true (ba⦇tr := []⦈, c⦇tr := tr c - tr ba⦈) ⟶ ok c ∧ tr c - tr ba = [] ∧ wait c) ∧ tr ba ≤ tr c⟧ ⟹ tr aa ≤ tr c› and 1 goal remains*) apply (erule conjE (*‹⟦?P ∧ ?Q; ⟦?P; ?Q⟧ ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ (∃zs. tr ba = tr aa @ zs); ¬ wait ba; (ok ba ∧ true (ba⦇tr := []⦈, c⦇tr := tr c - tr ba⦈) ⟶ ok c ∧ tr c - tr ba = [] ∧ wait c) ∧ (∃zs. tr c = tr ba @ zs)⟧ ⟹ ∃zs. tr c = tr aa @ zs› and 1 goal remains*) apply (erule exE (*‹⟦∃x. ?P x; ⋀x. ?P x ⟹ ?Q⟧ ⟹ ?Q›*)) (*top goal: ‹⋀aa ba c. ⟦wait aa; ¬ wait ba; (ok ba ∧ true (ba⦇tr := []⦈, c⦇tr := tr c - tr ba⦈) ⟶ ok c ∧ tr c - tr ba = [] ∧ wait c) ∧ (∃zs. tr c = tr ba @ zs); ¬ ok aa; ∃zs. tr ba = tr aa @ zs⟧ ⟹ ∃zs. tr c = tr aa @ zs› and 1 goal remains*) apply (erule conjE (*‹⟦?P ∧ ?Q; ⟦?P; ?Q⟧ ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) (c::('a, 'b) alpha_rp_scheme) zs::'a list. ⟦wait aa; ¬ wait ba; (ok ba ∧ true (ba⦇tr := []⦈, c⦇tr := tr c - tr ba⦈) ⟶ ok c ∧ tr c - tr ba = [] ∧ wait c) ∧ (∃zs::'a list. tr c = tr ba @ zs); ¬ ok aa; tr ba = tr aa @ zs⟧ ⟹ ∃zs::'a list. tr c = tr aa @ zs› and 1 goal remains*) apply (erule exE (*‹⟦∃x::?'a. (?P::?'a ⇒ bool) x; ⋀x::?'a. ?P x ⟹ ?Q::bool⟧ ⟹ ?Q›*)) (*top goal: ‹⋀aa ba c zs. ⟦wait aa; ¬ wait ba; ¬ ok aa; tr ba = tr aa @ zs; ok ba ∧ true (ba⦇tr := []⦈, c⦇tr := tr c - tr ba⦈) ⟶ ok c ∧ tr c - tr ba = [] ∧ wait c; ∃zs. tr c = tr ba @ zs⟧ ⟹ ∃zs. tr c = tr aa @ zs› and 1 goal remains*) apply (rule_tac x="zs@zsa" in exI (*‹(?P::?'a::type ⇒ bool) (?x::?'a::type) ⟹ ∃x::?'a::type. ?P x›*)) (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) (c::('a, 'b) alpha_rp_scheme) (zs::'a::ev_eq list) zsa::'a::ev_eq list. ⟦wait aa; ¬ wait ba; ¬ ok aa; tr ba = tr aa @ zs; ok ba ∧ true (ba⦇tr := []⦈, c⦇tr := tr c - tr ba⦈) ⟶ ok c ∧ tr c - tr ba = [] ∧ wait c; tr c = tr ba @ zsa⟧ ⟹ ∃zs::'a::ev_eq list. tr c = tr aa @ zs› and 1 goal remains*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*goal: ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (ba, c); ¬ (wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ ((wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A')) ∧ (¬ (wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A'))›*) apply (split cond_splits) (*goals: 1. ‹⋀aa ba c. ⟦¬ wait aa; (wait ∘ fst) (ba, c); ok aa ∧ true (aa⦇tr := []⦈, ba⦇tr := tr ba - tr aa⦈) ⟶ ok ba ∧ tr ba - tr aa = [] ∧ ¬ wait ba ∧ alpha_rp.more aa = alpha_rp.more ba; tr aa ≤ tr ba; case (ba, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ wait c) ∧ tr aa ≤ tr c› 2. ‹⋀aa ba c. ⟦¬ wait aa; ¬ (wait ∘ fst) (ba, c); ok aa ∧ true (aa⦇tr := []⦈, ba⦇tr := tr ba - tr aa⦈) ⟶ ok ba ∧ tr ba - tr aa = [] ∧ ¬ wait ba ∧ alpha_rp.more aa = alpha_rp.more ba; tr aa ≤ tr ba; case (ba, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A'⟧ ⟹ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ wait c) ∧ tr aa ≤ tr c› discuss goal 1*) apply (simp add: true_def (*‹true ≡ λA. True›*)) (*top goal: ‹⋀aa ba c. ⟦¬ wait aa; (wait ∘ fst) (ba, c); ok aa ∧ true (aa⦇tr := []⦈, ba⦇tr := tr ba - tr aa⦈) ⟶ ok ba ∧ tr ba - tr aa = [] ∧ ¬ wait ba ∧ alpha_rp.more aa = alpha_rp.more ba; tr aa ≤ tr ba; case (ba, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ wait c) ∧ tr aa ≤ tr c› and 1 goal remains*) apply (erule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹⋀aa ba c. ⟦¬ wait aa; wait ba; ¬ ok aa; tr aa ≤ tr ba; ¬ ok ba ∧ tr ba ≤ tr c⟧ ⟹ tr aa ≤ tr c› 2. ‹⋀aa ba c. ⟦¬ wait aa; wait ba; ¬ ok aa; tr aa ≤ tr ba; ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c⟧ ⟹ tr aa ≤ tr c› discuss goal 1*) apply (simp add: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*)) (*top goal: ‹⋀aa ba c. ⟦¬ wait aa; wait ba; ¬ ok aa; tr aa ≤ tr ba; ¬ ok ba ∧ tr ba ≤ tr c⟧ ⟹ tr aa ≤ tr c› and 2 goals remain*) apply (erule exE (*‹⟦∃x. ?P x; ⋀x. ?P x ⟹ ?Q⟧ ⟹ ?Q›*)) (*top goal: ‹⋀aa ba c. ⟦¬ wait aa; wait ba; ¬ ok aa; ∃zs. tr ba = tr aa @ zs; ¬ ok ba ∧ (∃zs. tr c = tr ba @ zs)⟧ ⟹ ∃zs. tr c = tr aa @ zs› and 2 goals remain*) apply (erule conjE (*‹⟦?P ∧ ?Q; ⟦?P; ?Q⟧ ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀aa ba c zs. ⟦¬ wait aa; wait ba; ¬ ok aa; ¬ ok ba ∧ (∃zs. tr c = tr ba @ zs); tr ba = tr aa @ zs⟧ ⟹ ∃zs. tr c = tr aa @ zs› and 2 goals remain*) apply (erule exE (*‹⟦∃x. ?P x; ⋀x. ?P x ⟹ ?Q⟧ ⟹ ?Q›*)) (*top goal: ‹⋀aa ba c zs. ⟦¬ wait aa; wait ba; ¬ ok aa; tr ba = tr aa @ zs; ¬ ok ba; ∃zs. tr c = tr ba @ zs⟧ ⟹ ∃zs. tr c = tr aa @ zs› and 2 goals remain*) apply (rule_tac x="zs@zsa" in exI (*‹?P ?x ⟹ ∃x. ?P x›*)) (*top goal: ‹⋀aa ba c zs zsa. ⟦¬ wait aa; wait ba; ¬ ok aa; tr ba = tr aa @ zs; ¬ ok ba; tr c = tr ba @ zsa⟧ ⟹ ∃zs. tr c = tr aa @ zs› and 2 goals remain*) apply simp (*discuss goal 2*) apply ((auto simp add: prefix_def (*‹?xs::?'a list ≤ ?ys::?'a list = (∃zs::?'a list. ?ys = ?xs @ zs)›*))[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply (simp add: true_def (*‹true ≡ λA. True›*)) (*goal: ‹⋀aa ba c. ⟦¬ wait aa; ¬ (wait ∘ fst) (ba, c); ok aa ∧ true (aa⦇tr := []⦈, ba⦇tr := tr ba - tr aa⦈) ⟶ ok ba ∧ tr ba - tr aa = [] ∧ ¬ wait ba ∧ alpha_rp.more aa = alpha_rp.more ba; tr aa ≤ tr ba; case (ba, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A'⟧ ⟹ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ wait c) ∧ tr aa ≤ tr c›*) apply ((auto simp add: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*))[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma Stop_is_CSP4: "(relation_of Stop) is CSP4 healthy" apply (auto simp: relation_of_Stop (*‹action.relation_of Stop = R (true ⊢ λ(A, A'). tr A' = tr A ∧ wait A')›*) relation_of_Skip (*‹action.relation_of Skip = R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A')›*) rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) CSP4_def (*‹CSP4 ?P ≡ ?P ;; action.relation_of Skip›*)) (*goals: 1. ‹⋀a b. ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (a, b) ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› 2. ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (aa, ba); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (aa, c)› discuss goal 1*) apply (rule_tac b=b in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀(a::('a, 'b) alpha_rp_scheme) b::('a, 'b) alpha_rp_scheme. ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (a, b) ⟹ ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (a, b)› 2. ‹⋀(a::('a, 'b) alpha_rp_scheme) b::('a, 'b) alpha_rp_scheme. ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (a, b) ⟹ ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (b, b)› discuss goal 1*) apply (split cond_splits) (*top goal: ‹⋀a b. ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (a, b) ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (a, b)› and 2 goals remain*) apply simp (*top goal: ‹⋀a b. ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (a, b) ⟹ ((wait ∘ fst) (a, b) ⟶ (case (a, b) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A')) ∧ (¬ (wait ∘ fst) (a, b) ⟶ (case (a, b) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A'))› and 2 goals remain*) apply (split cond_splits) (*goals: 1. ‹⋀a b. ⟦(wait ∘ fst) (a, b); case (a, b) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (wait a ⟶ ¬ ok a ∧ tr a ≤ tr b ∨ ok b ∧ tr a = tr b ∧ wait b ∧ ref a = ref b ∧ alpha_rp.more a = alpha_rp.more b) ∧ (¬ wait a ⟶ (ok a ∧ true (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ ok b ∧ tr b - tr a = [] ∧ wait b) ∧ tr a ≤ tr b)› 2. ‹⋀a b. ⟦¬ (wait ∘ fst) (a, b); case (a, b) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A'⟧ ⟹ (wait a ⟶ ¬ ok a ∧ tr a ≤ tr b ∨ ok b ∧ tr a = tr b ∧ wait b ∧ ref a = ref b ∧ alpha_rp.more a = alpha_rp.more b) ∧ (¬ wait a ⟶ (ok a ∧ true (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ ok b ∧ tr b - tr a = [] ∧ wait b) ∧ tr a ≤ tr b)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (split cond_splits) (*top goal: ‹⋀a b. ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (a, b) ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (b, b)› and 1 goal remains*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (split cond_splits) (*goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (aa, ba); ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (aa, c)›*) apply simp (*goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A')) (aa, ba); ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A')) ∧ (¬ (wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A'))›*) apply (split cond_splits) (*goals: 1. ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c); (wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (wait aa ⟶ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ (¬ wait aa ⟶ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ wait c) ∧ tr aa ≤ tr c)› 2. ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c); ¬ (wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A'⟧ ⟹ (wait aa ⟶ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ (¬ wait aa ⟶ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ wait c) ∧ tr aa ≤ tr c)› discuss goal 1*) apply simp (*top goal: ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c); (wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (wait aa ⟶ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ (¬ wait aa ⟶ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ wait c) ∧ tr aa ≤ tr c)› and 1 goal remains*) apply (split cond_splits) (*goals: 1. ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ wait ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; (wait ∘ fst) (ba, c); case (ba, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› 2. ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ wait ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; ¬ (wait ∘ fst) (ba, c); case (ba, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› discuss goal 1*) apply simp (*top goal: ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ wait ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; (wait ∘ fst) (ba, c); case (ba, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› and 2 goals remain*) apply (case_tac "ok aa") (*goals: 1. ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ok aa⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› 2. ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ¬ ok aa⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*top goal: ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ¬ ok aa⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› and 2 goals remain*) apply (case_tac "tr aa ≤ tr ba") (*goals: 1. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦wait aa; tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ¬ ok aa; tr aa ≤ tr ba⟧ ⟹ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› 2. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦wait aa; tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ¬ ok aa; ¬ tr aa ≤ tr ba⟧ ⟹ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› discuss goal 1*) apply simp (*top goal: ‹⋀aa ba c. ⟦wait aa; tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ¬ ok aa; tr aa ≤ tr ba⟧ ⟹ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› and 3 goals remain*) apply (case_tac "ok ba") (*goals: 1. ‹⋀aa ba c. ⟦wait aa; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ¬ ok aa; tr aa ≤ tr ba; ok ba⟧ ⟹ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› 2. ‹⋀aa ba c. ⟦wait aa; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ¬ ok aa; tr aa ≤ tr ba; ¬ ok ba⟧ ⟹ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*top goal: ‹⋀aa ba c. ⟦wait aa; wait ba; ¬ ok ba ∧ tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ¬ ok aa; tr aa ≤ tr ba; ¬ ok ba⟧ ⟹ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› and 3 goals remain*) apply (case_tac "tr ba ≤ tr c") (*goals: 1. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦wait aa; wait ba; tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ¬ ok aa; tr aa ≤ tr ba; ¬ ok ba; tr ba ≤ tr c⟧ ⟹ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› 2. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦wait aa; wait ba; tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ¬ ok aa; tr aa ≤ tr ba; ¬ ok ba; ¬ tr ba ≤ tr c⟧ ⟹ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› discuss goal 1*) apply simp (*top goal: ‹⋀aa ba c. ⟦wait aa; wait ba; tr ba ≤ tr c ∨ ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c; ¬ ok aa; tr aa ≤ tr ba; ¬ ok ba; tr ba ≤ tr c⟧ ⟹ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› and 4 goals remain*) apply (rule disjI1 (*‹?P ⟹ ?P ∨ ?Q›*)) (*top goal: ‹⋀aa ba c. ⟦wait aa; wait ba; ¬ ok aa; tr aa ≤ tr ba; ¬ ok ba; tr ba ≤ tr c⟧ ⟹ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› and 4 goals remain*) apply (simp add: prefix_def (*‹?xs::?'a::type list ≤ ?ys::?'a::type list = (∃zs::?'a::type list. ?ys = ?xs @ zs)›*)) (*top goal: ‹⋀aa ba c. ⟦wait aa; wait ba; ¬ ok aa; tr aa ≤ tr ba; ¬ ok ba; tr ba ≤ tr c⟧ ⟹ tr aa ≤ tr c› and 4 goals remain*) apply (erule exE (*‹⟦∃x. ?P x; ⋀x. ?P x ⟹ ?Q⟧ ⟹ ?Q›*)) (*top goal: ‹⋀aa ba c. ⟦wait aa; wait ba; ¬ ok aa; ∃zs. tr ba = tr aa @ zs; ¬ ok ba; ∃zs. tr c = tr ba @ zs⟧ ⟹ ∃zs. tr c = tr aa @ zs› and 4 goals remain*) apply (erule exE (*‹⟦∃x::?'a. (?P::?'a ⇒ bool) x; ⋀x::?'a. ?P x ⟹ ?Q::bool⟧ ⟹ ?Q›*)) (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) (c::('a, 'b) alpha_rp_scheme) zs::'a list. ⟦wait aa; wait ba; ¬ ok aa; ¬ ok ba; ∃zs::'a list. tr c = tr ba @ zs; tr ba = tr aa @ zs⟧ ⟹ ∃zs::'a list. tr c = tr aa @ zs› and 4 goals remain*) apply (rule_tac x="zs@zsa" in exI (*‹?P ?x ⟹ ∃x. ?P x›*)) (*top goal: ‹⋀aa ba c zs zsa. ⟦wait aa; wait ba; ¬ ok aa; ¬ ok ba; tr ba = tr aa @ zs; tr c = tr ba @ zsa⟧ ⟹ ∃zs. tr c = tr aa @ zs› and 4 goals remain*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*top goal: ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ wait ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; ¬ (wait ∘ fst) (ba, c); case (ba, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› and 1 goal remains*) apply (rule disjI1 (*‹?P ⟹ ?P ∨ ?Q›*)) (*top goal: ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba; ¬ wait ba; (ok ba ∧ true (ba⦇tr := []⦈, c⦇tr := tr c - tr ba⦈) ⟶ ok c ∧ tr c - tr ba = [] ∧ ¬ wait c ∧ alpha_rp.more ba = alpha_rp.more c) ∧ tr ba ≤ tr c⟧ ⟹ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› and 1 goal remains*) apply (simp add: prefix_def (*‹?xs::?'a list ≤ ?ys::?'a list = (∃zs::?'a list. ?ys = ?xs @ zs)›*)) (*top goal: ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba; ¬ wait ba; (ok ba ∧ true (ba⦇tr := []⦈, c⦇tr := tr c - tr ba⦈) ⟶ ok c ∧ tr c - tr ba = [] ∧ ¬ wait c ∧ alpha_rp.more ba = alpha_rp.more c) ∧ tr ba ≤ tr c⟧ ⟹ tr aa ≤ tr c› and 1 goal remains*) apply (erule conjE (*‹⟦?P ∧ ?Q; ⟦?P; ?Q⟧ ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ (∃zs. tr ba = tr aa @ zs); ¬ wait ba; (ok ba ∧ true (ba⦇tr := []⦈, c⦇tr := tr c - tr ba⦈) ⟶ ok c ∧ tr c - tr ba = [] ∧ ¬ wait c ∧ alpha_rp.more ba = alpha_rp.more c) ∧ (∃zs. tr c = tr ba @ zs)⟧ ⟹ ∃zs. tr c = tr aa @ zs› and 1 goal remains*) apply (erule exE (*‹⟦∃x. ?P x; ⋀x. ?P x ⟹ ?Q⟧ ⟹ ?Q›*)) (*top goal: ‹⋀aa ba c. ⟦wait aa; ¬ wait ba; (ok ba ∧ true (ba⦇tr := []⦈, c⦇tr := tr c - tr ba⦈) ⟶ ok c ∧ tr c - tr ba = [] ∧ ¬ wait c ∧ alpha_rp.more ba = alpha_rp.more c) ∧ (∃zs. tr c = tr ba @ zs); ¬ ok aa; ∃zs. tr ba = tr aa @ zs⟧ ⟹ ∃zs. tr c = tr aa @ zs› and 1 goal remains*) apply (erule conjE (*‹⟦?P ∧ ?Q; ⟦?P; ?Q⟧ ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀aa ba c zs. ⟦wait aa; ¬ wait ba; (ok ba ∧ true (ba⦇tr := []⦈, c⦇tr := tr c - tr ba⦈) ⟶ ok c ∧ tr c - tr ba = [] ∧ ¬ wait c ∧ alpha_rp.more ba = alpha_rp.more c) ∧ (∃zs. tr c = tr ba @ zs); ¬ ok aa; tr ba = tr aa @ zs⟧ ⟹ ∃zs. tr c = tr aa @ zs› and 1 goal remains*) apply (erule exE (*‹⟦∃x. ?P x; ⋀x. ?P x ⟹ ?Q⟧ ⟹ ?Q›*)) (*top goal: ‹⋀aa ba c zs. ⟦wait aa; ¬ wait ba; ¬ ok aa; tr ba = tr aa @ zs; ok ba ∧ true (ba⦇tr := []⦈, c⦇tr := tr c - tr ba⦈) ⟶ ok c ∧ tr c - tr ba = [] ∧ ¬ wait c ∧ alpha_rp.more ba = alpha_rp.more c; ∃zs. tr c = tr ba @ zs⟧ ⟹ ∃zs. tr c = tr aa @ zs› and 1 goal remains*) apply (rule_tac x="zs@zsa" in exI (*‹?P ?x ⟹ ∃x. ?P x›*)) (*top goal: ‹⋀aa ba c zs zsa. ⟦wait aa; ¬ wait ba; ¬ ok aa; tr ba = tr aa @ zs; ok ba ∧ true (ba⦇tr := []⦈, c⦇tr := tr c - tr ba⦈) ⟶ ok c ∧ tr c - tr ba = [] ∧ ¬ wait c ∧ alpha_rp.more ba = alpha_rp.more c; tr c = tr ba @ zsa⟧ ⟹ ∃zs. tr c = tr aa @ zs› and 1 goal remains*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*goal: ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c); ¬ (wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ wait A') ∧ tr A ≤ tr A'⟧ ⟹ (wait aa ⟶ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ (¬ wait aa ⟶ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ wait c) ∧ tr aa ≤ tr c)›*) apply (split cond_splits) (*goals: 1. ‹⋀aa ba c. ⟦¬ wait aa; (wait ∘ fst) (ba, c); ok aa ∧ true (aa⦇tr := []⦈, ba⦇tr := tr ba - tr aa⦈) ⟶ ok ba ∧ tr ba - tr aa = [] ∧ wait ba; tr aa ≤ tr ba; case (ba, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ wait c) ∧ tr aa ≤ tr c› 2. ‹⋀aa ba c. ⟦¬ wait aa; ¬ (wait ∘ fst) (ba, c); ok aa ∧ true (aa⦇tr := []⦈, ba⦇tr := tr ba - tr aa⦈) ⟶ ok ba ∧ tr ba - tr aa = [] ∧ wait ba; tr aa ≤ tr ba; case (ba, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ wait c) ∧ tr aa ≤ tr c› discuss goal 1*) apply (simp add: true_def (*‹true ≡ λA. True›*)) (*top goal: ‹⋀aa ba c. ⟦¬ wait aa; (wait ∘ fst) (ba, c); ok aa ∧ true (aa⦇tr := []⦈, ba⦇tr := tr ba - tr aa⦈) ⟶ ok ba ∧ tr ba - tr aa = [] ∧ wait ba; tr aa ≤ tr ba; case (ba, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ wait c) ∧ tr aa ≤ tr c› and 1 goal remains*) apply (erule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹⋀aa ba c. ⟦¬ wait aa; wait ba; ok aa ⟶ ok ba ∧ tr ba - tr aa = []; tr aa ≤ tr ba; ¬ ok ba ∧ tr ba ≤ tr c⟧ ⟹ (ok aa ⟶ ok c ∧ tr c - tr aa = [] ∧ wait c) ∧ tr aa ≤ tr c› 2. ‹⋀aa ba c. ⟦¬ wait aa; wait ba; ok aa ⟶ ok ba ∧ tr ba - tr aa = []; tr aa ≤ tr ba; ok c ∧ tr ba = tr c ∧ wait c ∧ ref ba = ref c ∧ alpha_rp.more ba = alpha_rp.more c⟧ ⟹ (ok aa ⟶ ok c ∧ tr c - tr aa = [] ∧ wait c) ∧ tr aa ≤ tr c› discuss goal 1*) apply (simp add: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*)) (*top goal: ‹⋀aa ba c. ⟦¬ wait aa; wait ba; ok aa ⟶ ok ba ∧ tr ba - tr aa = []; tr aa ≤ tr ba; ¬ ok ba ∧ tr ba ≤ tr c⟧ ⟹ (ok aa ⟶ ok c ∧ tr c - tr aa = [] ∧ wait c) ∧ tr aa ≤ tr c› and 2 goals remain*) apply (erule exE (*‹⟦∃x. ?P x; ⋀x. ?P x ⟹ ?Q⟧ ⟹ ?Q›*)) (*top goal: ‹⋀aa ba c. ⟦¬ wait aa; wait ba; ¬ ok aa; ∃zs. tr ba = tr aa @ zs; ¬ ok ba ∧ (∃zs. tr c = tr ba @ zs)⟧ ⟹ ∃zs. tr c = tr aa @ zs› and 2 goals remain*) apply (erule conjE (*‹⟦?P ∧ ?Q; ⟦?P; ?Q⟧ ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) (c::('a, 'b) alpha_rp_scheme) zs::'a list. ⟦¬ wait aa; wait ba; ¬ ok aa; ¬ ok ba ∧ (∃zs::'a list. tr c = tr ba @ zs); tr ba = tr aa @ zs⟧ ⟹ ∃zs::'a list. tr c = tr aa @ zs› and 2 goals remain*) apply (erule exE (*‹⟦∃x. ?P x; ⋀x. ?P x ⟹ ?Q⟧ ⟹ ?Q›*)) (*top goal: ‹⋀aa ba c zs. ⟦¬ wait aa; wait ba; ¬ ok aa; tr ba = tr aa @ zs; ¬ ok ba; ∃zs. tr c = tr ba @ zs⟧ ⟹ ∃zs. tr c = tr aa @ zs› and 2 goals remain*) apply (rule_tac x="zs@zsa" in exI (*‹?P ?x ⟹ ∃x. ?P x›*)) (*top goal: ‹⋀aa ba c zs zsa. ⟦¬ wait aa; wait ba; ¬ ok aa; tr ba = tr aa @ zs; ¬ ok ba; tr c = tr ba @ zsa⟧ ⟹ ∃zs. tr c = tr aa @ zs› and 2 goals remain*) apply simp (*discuss goal 2*) apply ((auto simp add: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*))[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply (simp add: true_def (*‹true ≡ λA::?'α. True›*)) (*goal: ‹⋀aa ba c. ⟦¬ wait aa; ¬ (wait ∘ fst) (ba, c); ok aa ∧ true (aa⦇tr := []⦈, ba⦇tr := tr ba - tr aa⦈) ⟶ ok ba ∧ tr ba - tr aa = [] ∧ wait ba; tr aa ≤ tr ba; case (ba, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ wait c) ∧ tr aa ≤ tr c›*) apply ((auto simp add: prefix_def (*‹?xs::?'a::type list ≤ ?ys::?'a::type list = (∃zs::?'a::type list. ?ys = ?xs @ zs)›*))[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . subsection ‹Chaos› definition Chaos :: "('θ::ev_eq,'σ) action" where "Chaos ≡ action_of (R(false ⊢ true))" lemma Chaos_is_action: "(R(false ⊢ true)) ∈ {p. is_CSP_process p}" apply simp (*goal: ‹R (false ⊢ true) ∈ {p. is_CSP_process p}›*) apply (rule rd_is_CSP (*‹∀(a::(?'a, ?'b) alpha_rp_scheme) b::(?'a, ?'b) alpha_rp_scheme. (?r::(?'a, ?'b) alpha_rp_scheme × (?'a, ?'b) alpha_rp_scheme ⇒ bool) (a, b⦇ok := True⦈) ⟶ ?r (a, b⦇ok := False⦈) ⟹ is_CSP_process (R (?r ⊢ ?p::(?'a, ?'b) alpha_rp_scheme × (?'a, ?'b) alpha_rp_scheme ⇒ bool))›*)) (*goal: ‹is_CSP_process (R (false ⊢ true))›*) by auto lemmas Chaos_is_CSP = Chaos_is_action[simplified] lemma relation_of_Chaos: "relation_of Chaos = (R(false ⊢ true))" by (simp add: Chaos_def (*‹Chaos ≡ action_of (R (false ⊢ true))›*) action_of_inverse (*‹?y ∈ {p. is_CSP_process p} ⟹ action.relation_of (action_of ?y) = ?y›*) Chaos_is_CSP (*‹is_CSP_process (R (false ⊢ true))›*)) subsection ‹State update actions› definition Pre ::"'σ relation ⇒ 'σ predicate" where "Pre sc ≡ λA. ∃ A'. sc (A, A')" definition state_update_before :: "'σ relation ⇒ ('θ::ev_eq,'σ) action ⇒ ('θ,'σ) action" where "state_update_before sc Ac = action_of(R ((λ(A, A'). (Pre sc) (more A)) ⊢ (λ(A, A'). sc (more A, more A') & ¬wait A' & tr A = tr A')) ;; relation_of Ac)" lemma state_update_before_is_action: "(R ((λ(A, A'). (Pre sc) (more A)) ⊢ (λ(A, A').sc (more A, more A') & ¬wait A' & tr A = tr A')) ;; relation_of Ac) ∈ {p. is_CSP_process p}" apply simp (*goal: ‹(R (λ(A, A'). Pre sc (alpha_rp.more A) ⊢ λ(A, A'). sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ tr A = tr A') ;; action.relation_of Ac) ∈ {p. is_CSP_process p}›*) apply (rule seq_CSP (*‹⟦?P::(?'a, ?'b) alpha_rp_scheme × (?'a, ?'b) alpha_rp_scheme ⇒ bool is CSP1 healthy; ?P is R healthy; is_CSP_process (?Q::(?'a, ?'b) alpha_rp_scheme × (?'a, ?'b) alpha_rp_scheme ⇒ bool)⟧ ⟹ is_CSP_process (?P ;; ?Q)›*)) (*goals: 1. ‹R (λ(A, A'). Pre sc (alpha_rp.more A) ⊢ λ(A, A'). sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ tr A = tr A') is CSP1 healthy› 2. ‹R (λ(A, A'). Pre sc (alpha_rp.more A) ⊢ λ(A, A'). sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ tr A = tr A') is R healthy› 3. ‹is_CSP_process (action.relation_of Ac)› discuss goal 1*) apply (rule rd_is_CSP1 (*‹R (?r ⊢ ?p) is CSP1 healthy›*)) (*discuss goal 2*) apply ((auto simp: R_idem2 (*‹R (R ?P) = R ?P›*) Healthy_def (*‹?P is ?H healthy ≡ ?P = ?H ?P›*) relation_of_CSP (*‹is_CSP_process (action.relation_of ?x)›*))[1]) (*discuss goal 3*) apply ((auto simp: R_idem2 (*‹R (R ?P) = R ?P›*) Healthy_def (*‹?P is ?H healthy ≡ ?P = ?H ?P›*) relation_of_CSP (*‹is_CSP_process (action.relation_of ?x)›*))[1]) (*proven 3 subgoals*) . lemmas state_update_before_is_CSP = state_update_before_is_action[simplified] lemma relation_of_state_update_before: "relation_of (state_update_before sc Ac) = (R ((λ(A, A'). (Pre sc) (more A)) ⊢ (λ(A, A'). sc (more A, more A') & ¬wait A' & tr A = tr A')) ;; relation_of Ac)" by (simp add: state_update_before_def (*‹state_update_before ?sc ?Ac = action_of (R (λ(A, A'). Pre ?sc (alpha_rp.more A) ⊢ λ(A, A'). ?sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ tr A = tr A') ;; action.relation_of ?Ac)›*) action_of_inverse (*‹?y ∈ {p. is_CSP_process p} ⟹ action.relation_of (action_of ?y) = ?y›*) state_update_before_is_CSP (*‹is_CSP_process (R (λ(A, A'). Pre ?sc (alpha_rp.more A) ⊢ λ(A, A'). ?sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ tr A = tr A') ;; action.relation_of ?Ac)›*)) lemma mono_state_update_before: "mono (state_update_before sc)" sorry lemma state_update_before_is_CSP3: "relation_of (state_update_before sc Ac) is CSP3 healthy" apply (auto simp: relation_of_state_update_before (*‹action.relation_of (state_update_before ?sc ?Ac) = (R (λ(A, A'). Pre ?sc (alpha_rp.more A) ⊢ λ(A, A'). ?sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ tr A = tr A') ;; action.relation_of ?Ac)›*) relation_of_Skip (*‹action.relation_of Skip = R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A')›*) rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) CSP3_def (*‹CSP3 ?P ≡ action.relation_of Skip ;; ?P›*)) (*goals: 1. ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ba); action.relation_of Ac (ba, c)⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of Ac) (aa, c)› 2. ‹⋀aa ab bb ca. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (aa, ab); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ab, bb); action.relation_of Ac (bb, ca)⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of Ac) (aa, ca)› discuss goal 1*) apply (rule_tac b=aa in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ba); action.relation_of Ac (ba, c)⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (aa, aa)› 2. ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ba); action.relation_of Ac (ba, c)⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of Ac) (aa, c)› discuss goal 1*) apply (split cond_splits) (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ Pre (sc::'b × 'b ⇒ bool) (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ba); action.relation_of (Ac::('a, 'b) action) (ba, c)⟧ ⟹ ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (aa, aa)› and 2 goals remain*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply (split cond_splits) (*goals: 1. ‹⋀aa ab bb ca. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ab, bb); action.relation_of Ac (bb, ca); (wait ∘ fst) (aa, ab); case (aa, ab) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of Ac) (aa, ca)› 2. ‹⋀aa ab bb ca. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ab, bb); action.relation_of Ac (bb, ca); ¬ (wait ∘ fst) (aa, ab); case (aa, ab) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of Ac) (aa, ca)› discuss goal 1*) apply simp (*top goal: ‹⋀aa ab bb ca. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ab, bb); action.relation_of Ac (bb, ca); (wait ∘ fst) (aa, ab); case (aa, ab) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of Ac) (aa, ca)› and 1 goal remains*) apply (split cond_splits) (*goals: 1. ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; (wait ∘ fst) (ab, bb); case (ab, bb) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of Ac) (aa, ca)› 2. ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; ¬ (wait ∘ fst) (ab, bb); case (ab, bb) of (A, A') ⇒ (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of Ac) (aa, ca)› discuss goal 1*) apply simp (*top goal: ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; (wait ∘ fst) (ab, bb); case (ab, bb) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of Ac) (aa, ca)› and 2 goals remain*) apply (rule_tac b=bb in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; wait ab; ¬ ok ab ∧ tr ab ≤ tr bb ∨ ok bb ∧ tr ab = tr bb ∧ wait bb ∧ ref ab = ref bb ∧ alpha_rp.more ab = alpha_rp.more bb⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, bb)› 2. ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; wait ab; ¬ ok ab ∧ tr ab ≤ tr bb ∨ ok bb ∧ tr ab = tr bb ∧ wait bb ∧ ref ab = ref bb ∧ alpha_rp.more ab = alpha_rp.more bb⟧ ⟹ action.relation_of Ac (bb, ca)› discuss goal 1*) apply (split cond_splits) (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦action.relation_of (Ac::('a, 'b) action) (bb, ca); wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; wait ab; ¬ ok ab ∧ tr ab ≤ tr bb ∨ ok bb ∧ tr ab = tr bb ∧ wait bb ∧ ref ab = ref bb ∧ alpha_rp.more ab = alpha_rp.more bb⟧ ⟹ ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ Pre (sc::'b × 'b ⇒ bool) (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, bb)› and 3 goals remain*) apply simp (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦action.relation_of (Ac::('a, 'b) action) (bb, ca); wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; wait ab; ¬ ok ab ∧ tr ab ≤ tr bb ∨ ok bb ∧ tr ab = tr bb ∧ wait bb ∧ ref ab = ref bb ∧ alpha_rp.more ab = alpha_rp.more bb⟧ ⟹ ((wait ∘ fst) (aa, bb) ⟶ (case (aa, bb) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A')) ∧ (¬ (wait ∘ fst) (aa, bb) ⟶ (case (aa, bb) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ (ok A ∧ Pre (sc::'b × 'b ⇒ bool) (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'))› and 3 goals remain*) apply (case_tac "ok aa") (*goals: 1. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦action.relation_of (Ac::('a::ev_eq, 'b::type) action) (bb, ca); wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; wait ab; ¬ ok ab ∧ tr ab ≤ tr bb ∨ ok bb ∧ tr ab = tr bb ∧ wait bb ∧ ref ab = ref bb ∧ alpha_rp.more ab = alpha_rp.more bb; ok aa⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr bb ∨ ok bb ∧ tr aa = tr bb ∧ wait bb ∧ ref aa = ref bb ∧ alpha_rp.more aa = alpha_rp.more bb› 2. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦action.relation_of (Ac::('a::ev_eq, 'b::type) action) (bb, ca); wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; wait ab; ¬ ok ab ∧ tr ab ≤ tr bb ∨ ok bb ∧ tr ab = tr bb ∧ wait bb ∧ ref ab = ref bb ∧ alpha_rp.more ab = alpha_rp.more bb; ¬ ok aa⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr bb ∨ ok bb ∧ tr aa = tr bb ∧ wait bb ∧ ref aa = ref bb ∧ alpha_rp.more aa = alpha_rp.more bb› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*top goal: ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; wait ab; ¬ ok ab ∧ tr ab ≤ tr bb ∨ ok bb ∧ tr ab = tr bb ∧ wait bb ∧ ref ab = ref bb ∧ alpha_rp.more ab = alpha_rp.more bb; ¬ ok aa⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr bb ∨ ok bb ∧ tr aa = tr bb ∧ wait bb ∧ ref aa = ref bb ∧ alpha_rp.more aa = alpha_rp.more bb› and 3 goals remain*) apply (case_tac "tr aa ≤ tr ab") (*goals: 1. ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); wait aa; tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; wait ab; ¬ ok ab ∧ tr ab ≤ tr bb ∨ ok bb ∧ tr ab = tr bb ∧ wait bb ∧ ref ab = ref bb ∧ alpha_rp.more ab = alpha_rp.more bb; ¬ ok aa; tr aa ≤ tr ab⟧ ⟹ tr aa ≤ tr bb ∨ ok bb ∧ tr aa = tr bb ∧ wait bb ∧ ref aa = ref bb ∧ alpha_rp.more aa = alpha_rp.more bb› 2. ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); wait aa; tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; wait ab; ¬ ok ab ∧ tr ab ≤ tr bb ∨ ok bb ∧ tr ab = tr bb ∧ wait bb ∧ ref ab = ref bb ∧ alpha_rp.more ab = alpha_rp.more bb; ¬ ok aa; ¬ tr aa ≤ tr ab⟧ ⟹ tr aa ≤ tr bb ∨ ok bb ∧ tr aa = tr bb ∧ wait bb ∧ ref aa = ref bb ∧ alpha_rp.more aa = alpha_rp.more bb› discuss goal 1*) apply simp (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦action.relation_of (Ac::('a, 'b) action) (bb, ca); wait aa; tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; wait ab; ¬ ok ab ∧ tr ab ≤ tr bb ∨ ok bb ∧ tr ab = tr bb ∧ wait bb ∧ ref ab = ref bb ∧ alpha_rp.more ab = alpha_rp.more bb; ¬ ok aa; tr aa ≤ tr ab⟧ ⟹ tr aa ≤ tr bb ∨ ok bb ∧ tr aa = tr bb ∧ wait bb ∧ ref aa = ref bb ∧ alpha_rp.more aa = alpha_rp.more bb› and 4 goals remain*) apply (case_tac "ok ab") (*goals: 1. ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); wait aa; wait ab; ¬ ok ab ∧ tr ab ≤ tr bb ∨ ok bb ∧ tr ab = tr bb ∧ wait bb ∧ ref ab = ref bb ∧ alpha_rp.more ab = alpha_rp.more bb; ¬ ok aa; tr aa ≤ tr ab; ok ab⟧ ⟹ tr aa ≤ tr bb ∨ ok bb ∧ tr aa = tr bb ∧ wait bb ∧ ref aa = ref bb ∧ alpha_rp.more aa = alpha_rp.more bb› 2. ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); wait aa; wait ab; ¬ ok ab ∧ tr ab ≤ tr bb ∨ ok bb ∧ tr ab = tr bb ∧ wait bb ∧ ref ab = ref bb ∧ alpha_rp.more ab = alpha_rp.more bb; ¬ ok aa; tr aa ≤ tr ab; ¬ ok ab⟧ ⟹ tr aa ≤ tr bb ∨ ok bb ∧ tr aa = tr bb ∧ wait bb ∧ ref aa = ref bb ∧ alpha_rp.more aa = alpha_rp.more bb› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*top goal: ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); wait aa; wait ab; ¬ ok ab ∧ tr ab ≤ tr bb ∨ ok bb ∧ tr ab = tr bb ∧ wait bb ∧ ref ab = ref bb ∧ alpha_rp.more ab = alpha_rp.more bb; ¬ ok aa; tr aa ≤ tr ab; ¬ ok ab⟧ ⟹ tr aa ≤ tr bb ∨ ok bb ∧ tr aa = tr bb ∧ wait bb ∧ ref aa = ref bb ∧ alpha_rp.more aa = alpha_rp.more bb› and 4 goals remain*) apply (case_tac "tr ab ≤ tr bb") (*goals: 1. ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); wait aa; wait ab; tr ab ≤ tr bb ∨ ok bb ∧ tr ab = tr bb ∧ wait bb ∧ ref ab = ref bb ∧ alpha_rp.more ab = alpha_rp.more bb; ¬ ok aa; tr aa ≤ tr ab; ¬ ok ab; tr ab ≤ tr bb⟧ ⟹ tr aa ≤ tr bb ∨ ok bb ∧ tr aa = tr bb ∧ wait bb ∧ ref aa = ref bb ∧ alpha_rp.more aa = alpha_rp.more bb› 2. ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); wait aa; wait ab; tr ab ≤ tr bb ∨ ok bb ∧ tr ab = tr bb ∧ wait bb ∧ ref ab = ref bb ∧ alpha_rp.more ab = alpha_rp.more bb; ¬ ok aa; tr aa ≤ tr ab; ¬ ok ab; ¬ tr ab ≤ tr bb⟧ ⟹ tr aa ≤ tr bb ∨ ok bb ∧ tr aa = tr bb ∧ wait bb ∧ ref aa = ref bb ∧ alpha_rp.more aa = alpha_rp.more bb› discuss goal 1*) apply simp (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦action.relation_of (Ac::('a, 'b) action) (bb, ca); wait aa; wait ab; tr ab ≤ tr bb ∨ ok bb ∧ tr ab = tr bb ∧ wait bb ∧ ref ab = ref bb ∧ alpha_rp.more ab = alpha_rp.more bb; ¬ ok aa; tr aa ≤ tr ab; ¬ ok ab; tr ab ≤ tr bb⟧ ⟹ tr aa ≤ tr bb ∨ ok bb ∧ tr aa = tr bb ∧ wait bb ∧ ref aa = ref bb ∧ alpha_rp.more aa = alpha_rp.more bb› and 5 goals remain*) apply (rule disjI1 (*‹?P ⟹ ?P ∨ ?Q›*)) (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦action.relation_of (Ac::('a::ev_eq, 'b::type) action) (bb, ca); wait aa; wait ab; ¬ ok aa; tr aa ≤ tr ab; ¬ ok ab; tr ab ≤ tr bb⟧ ⟹ tr aa ≤ tr bb ∨ ok bb ∧ tr aa = tr bb ∧ wait bb ∧ ref aa = ref bb ∧ alpha_rp.more aa = alpha_rp.more bb› and 5 goals remain*) apply (simp add: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*)) (*top goal: ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); wait aa; wait ab; ¬ ok aa; tr aa ≤ tr ab; ¬ ok ab; tr ab ≤ tr bb⟧ ⟹ tr aa ≤ tr bb› and 5 goals remain*) apply (erule exE (*‹⟦∃x. ?P x; ⋀x. ?P x ⟹ ?Q⟧ ⟹ ?Q›*)) (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦action.relation_of (Ac::('a, 'b) action) (bb, ca); wait aa; wait ab; ¬ ok aa; ∃zs::'a list. tr ab = tr aa @ zs; ¬ ok ab; ∃zs::'a list. tr bb = tr ab @ zs⟧ ⟹ ∃zs::'a list. tr bb = tr aa @ zs› and 5 goals remain*) apply (erule exE (*‹⟦∃x. ?P x; ⋀x. ?P x ⟹ ?Q⟧ ⟹ ?Q›*)) (*top goal: ‹⋀aa ab bb ca zs. ⟦action.relation_of Ac (bb, ca); wait aa; wait ab; ¬ ok aa; ¬ ok ab; ∃zs. tr bb = tr ab @ zs; tr ab = tr aa @ zs⟧ ⟹ ∃zs. tr bb = tr aa @ zs› and 5 goals remain*) apply (rule_tac x="zs@zsa" in exI (*‹?P ?x ⟹ ∃x. ?P x›*)) (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) (ca::('a, 'b) alpha_rp_scheme) (zs::'a list) zsa::'a list. ⟦action.relation_of (Ac::('a, 'b) action) (bb, ca); wait aa; wait ab; ¬ ok aa; ¬ ok ab; tr ab = tr aa @ zs; tr bb = tr ab @ zsa⟧ ⟹ ∃zs::'a list. tr bb = tr aa @ zs› and 5 goals remain*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦action.relation_of (Ac::('a, 'b) action) (bb, ca); wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; ¬ (wait ∘ fst) (ab, bb); case (ab, bb) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ (ok A ∧ Pre (sc::'b × 'b ⇒ bool) (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of Ac) (aa, ca)› and 1 goal remains*) apply (rule_tac b=bb in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); wait aa; ¬ ok aa ∧ tr aa ≤ tr ab; ¬ wait ab; (ok ab ∧ Pre sc (alpha_rp.more ab) ⟶ ok bb ∧ sc (alpha_rp.more ab, alpha_rp.more bb) ∧ ¬ wait bb ∧ [] = tr bb - tr ab) ∧ tr ab ≤ tr bb⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, bb)› 2. ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); wait aa; ¬ ok aa ∧ tr aa ≤ tr ab; ¬ wait ab; (ok ab ∧ Pre sc (alpha_rp.more ab) ⟶ ok bb ∧ sc (alpha_rp.more ab, alpha_rp.more bb) ∧ ¬ wait bb ∧ [] = tr bb - tr ab) ∧ tr ab ≤ tr bb⟧ ⟹ action.relation_of Ac (bb, ca)› discuss goal 1*) apply (split cond_splits) (*top goal: ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); wait aa; ¬ ok aa ∧ tr aa ≤ tr ab; ¬ wait ab; (ok ab ∧ Pre sc (alpha_rp.more ab) ⟶ ok bb ∧ sc (alpha_rp.more ab, alpha_rp.more bb) ∧ ¬ wait bb ∧ [] = tr bb - tr ab) ∧ tr ab ≤ tr bb⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, bb)› and 2 goals remain*) apply simp (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦action.relation_of (Ac::('a, 'b) action) (bb, ca); wait aa; ¬ ok aa ∧ tr aa ≤ tr ab; ¬ wait ab; (ok ab ∧ Pre (sc::'b × 'b ⇒ bool) (alpha_rp.more ab) ⟶ ok bb ∧ sc (alpha_rp.more ab, alpha_rp.more bb) ∧ ¬ wait bb ∧ [] = tr bb - tr ab) ∧ tr ab ≤ tr bb⟧ ⟹ ((wait ∘ fst) (aa, bb) ⟶ (case (aa, bb) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A')) ∧ (¬ (wait ∘ fst) (aa, bb) ⟶ (case (aa, bb) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'))› and 2 goals remain*) apply (rule disjI1 (*‹?P::bool ⟹ ?P ∨ (?Q::bool)›*)) (*top goal: ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); wait aa; ¬ ok aa ∧ tr aa ≤ tr ab; ¬ wait ab; (ok ab ∧ Pre sc (alpha_rp.more ab) ⟶ ok bb ∧ sc (alpha_rp.more ab, alpha_rp.more bb) ∧ ¬ wait bb ∧ [] = tr bb - tr ab) ∧ tr ab ≤ tr bb⟧ ⟹ tr aa ≤ tr bb ∨ ok bb ∧ tr aa = tr bb ∧ wait bb ∧ ref aa = ref bb ∧ alpha_rp.more aa = alpha_rp.more bb› and 2 goals remain*) apply (simp add: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*)) (*top goal: ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); wait aa; ¬ ok aa ∧ tr aa ≤ tr ab; ¬ wait ab; (ok ab ∧ Pre sc (alpha_rp.more ab) ⟶ ok bb ∧ sc (alpha_rp.more ab, alpha_rp.more bb) ∧ ¬ wait bb ∧ [] = tr bb - tr ab) ∧ tr ab ≤ tr bb⟧ ⟹ tr aa ≤ tr bb› and 2 goals remain*) apply (erule conjE (*‹⟦?P ∧ ?Q; ⟦?P; ?Q⟧ ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); wait aa; ¬ ok aa ∧ (∃zs. tr ab = tr aa @ zs); ¬ wait ab; (ok ab ∧ Pre sc (alpha_rp.more ab) ⟶ ok bb ∧ sc (alpha_rp.more ab, alpha_rp.more bb) ∧ ¬ wait bb ∧ [] = tr bb - tr ab) ∧ (∃zs. tr bb = tr ab @ zs)⟧ ⟹ ∃zs. tr bb = tr aa @ zs› and 2 goals remain*) apply (erule exE (*‹⟦∃x. ?P x; ⋀x. ?P x ⟹ ?Q⟧ ⟹ ?Q›*)) (*top goal: ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); wait aa; ¬ wait ab; (ok ab ∧ Pre sc (alpha_rp.more ab) ⟶ ok bb ∧ sc (alpha_rp.more ab, alpha_rp.more bb) ∧ ¬ wait bb ∧ [] = tr bb - tr ab) ∧ (∃zs. tr bb = tr ab @ zs); ¬ ok aa; ∃zs. tr ab = tr aa @ zs⟧ ⟹ ∃zs. tr bb = tr aa @ zs› and 2 goals remain*) apply (erule conjE (*‹⟦?P ∧ ?Q; ⟦?P; ?Q⟧ ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀aa ab bb ca zs. ⟦action.relation_of Ac (bb, ca); wait aa; ¬ wait ab; (ok ab ∧ Pre sc (alpha_rp.more ab) ⟶ ok bb ∧ sc (alpha_rp.more ab, alpha_rp.more bb) ∧ ¬ wait bb ∧ [] = tr bb - tr ab) ∧ (∃zs. tr bb = tr ab @ zs); ¬ ok aa; tr ab = tr aa @ zs⟧ ⟹ ∃zs. tr bb = tr aa @ zs› and 2 goals remain*) apply (erule exE (*‹⟦∃x. ?P x; ⋀x. ?P x ⟹ ?Q⟧ ⟹ ?Q›*)) (*top goal: ‹⋀aa ab bb ca zs. ⟦action.relation_of Ac (bb, ca); wait aa; ¬ wait ab; ¬ ok aa; tr ab = tr aa @ zs; ok ab ∧ Pre sc (alpha_rp.more ab) ⟶ ok bb ∧ sc (alpha_rp.more ab, alpha_rp.more bb) ∧ ¬ wait bb ∧ [] = tr bb - tr ab; ∃zs. tr bb = tr ab @ zs⟧ ⟹ ∃zs. tr bb = tr aa @ zs› and 2 goals remain*) apply (rule_tac x="zs@zsa" in exI (*‹(?P::?'a ⇒ bool) (?x::?'a) ⟹ ∃x::?'a. ?P x›*)) (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) (ca::('a, 'b) alpha_rp_scheme) (zs::'a::ev_eq list) zsa::'a::ev_eq list. ⟦action.relation_of (Ac::('a::ev_eq, 'b::type) action) (bb, ca); wait aa; ¬ wait ab; ¬ ok aa; tr ab = tr aa @ zs; ok ab ∧ Pre (sc::'b::type × 'b::type ⇒ bool) (alpha_rp.more ab) ⟶ ok bb ∧ sc (alpha_rp.more ab, alpha_rp.more bb) ∧ ¬ wait bb ∧ [] = tr bb - tr ab; tr bb = tr ab @ zsa⟧ ⟹ ∃zs::'a::ev_eq list. tr bb = tr aa @ zs› and 2 goals remain*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*goal: ‹⋀aa ab bb ca. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ab, bb); action.relation_of Ac (bb, ca); ¬ (wait ∘ fst) (aa, ab); case (aa, ab) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of Ac) (aa, ca)›*) apply (rule_tac b=bb in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀aa ab bb ca. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ab, bb); action.relation_of Ac (bb, ca); ¬ wait aa; (ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ alpha_rp.more aa = alpha_rp.more ab) ∧ tr aa ≤ tr ab⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, bb)› 2. ‹⋀aa ab bb ca. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ab, bb); action.relation_of Ac (bb, ca); ¬ wait aa; (ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ alpha_rp.more aa = alpha_rp.more ab) ∧ tr aa ≤ tr ab⟧ ⟹ action.relation_of Ac (bb, ca)› discuss goal 1*) apply (split cond_splits) (*top goal: ‹⋀aa ab bb ca. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ab, bb); action.relation_of Ac (bb, ca); ¬ wait aa; (ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ alpha_rp.more aa = alpha_rp.more ab) ∧ tr aa ≤ tr ab⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, bb)› and 1 goal remains*) apply simp (*top goal: ‹⋀aa ab bb ca. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ab, bb); action.relation_of Ac (bb, ca); ¬ wait aa; (ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ alpha_rp.more aa = alpha_rp.more ab) ∧ tr aa ≤ tr ab⟧ ⟹ ((wait ∘ fst) (aa, bb) ⟶ (case (aa, bb) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A')) ∧ (¬ (wait ∘ fst) (aa, bb) ⟶ (case (aa, bb) of (A, A') ⇒ (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'))› and 1 goal remains*) apply (split cond_splits) (*goals: 1. ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); ¬ wait aa; (wait ∘ fst) (ab, bb); ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ alpha_rp.more aa = alpha_rp.more ab; tr aa ≤ tr ab; case (ab, bb) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (ok aa ∧ Pre sc (alpha_rp.more aa) ⟶ ok bb ∧ sc (alpha_rp.more aa, alpha_rp.more bb) ∧ ¬ wait bb ∧ [] = tr bb - tr aa) ∧ tr aa ≤ tr bb› 2. ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); ¬ wait aa; ¬ (wait ∘ fst) (ab, bb); ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ alpha_rp.more aa = alpha_rp.more ab; tr aa ≤ tr ab; case (ab, bb) of (A, A') ⇒ (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'⟧ ⟹ (ok aa ∧ Pre sc (alpha_rp.more aa) ⟶ ok bb ∧ sc (alpha_rp.more aa, alpha_rp.more bb) ∧ ¬ wait bb ∧ [] = tr bb - tr aa) ∧ tr aa ≤ tr bb› discuss goal 1*) apply simp (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦action.relation_of (Ac::('a::ev_eq, 'b::type) action) (bb, ca); ¬ wait aa; (wait ∘ fst) (ab, bb); ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ alpha_rp.more aa = alpha_rp.more ab; tr aa ≤ tr ab; case (ab, bb) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (ok aa ∧ Pre (sc::'b::type × 'b::type ⇒ bool) (alpha_rp.more aa) ⟶ ok bb ∧ sc (alpha_rp.more aa, alpha_rp.more bb) ∧ ¬ wait bb ∧ [] = tr bb - tr aa) ∧ tr aa ≤ tr bb› and 2 goals remain*) apply (simp add: true_def (*‹true ≡ λA. True›*)) (*top goal: ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); ¬ wait aa; wait ab; ok aa ⟶ ¬ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈); tr aa ≤ tr ab; ¬ ok ab ∧ tr ab ≤ tr bb ∨ ok bb ∧ tr ab = tr bb ∧ wait bb ∧ ref ab = ref bb ∧ alpha_rp.more ab = alpha_rp.more bb⟧ ⟹ (ok aa ∧ Pre sc (alpha_rp.more aa) ⟶ ok bb ∧ sc (alpha_rp.more aa, alpha_rp.more bb) ∧ ¬ wait bb ∧ [] = tr bb - tr aa) ∧ tr aa ≤ tr bb› and 2 goals remain*) apply (erule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); ¬ wait aa; wait ab; ¬ ok aa; tr aa ≤ tr ab; ¬ ok ab ∧ tr ab ≤ tr bb⟧ ⟹ tr aa ≤ tr bb› 2. ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); ¬ wait aa; wait ab; ¬ ok aa; tr aa ≤ tr ab; ok bb ∧ tr ab = tr bb ∧ wait bb ∧ ref ab = ref bb ∧ alpha_rp.more ab = alpha_rp.more bb⟧ ⟹ tr aa ≤ tr bb› discuss goal 1*) apply (simp add: prefix_def (*‹?xs::?'a list ≤ ?ys::?'a list = (∃zs::?'a list. ?ys = ?xs @ zs)›*)) (*top goal: ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); ¬ wait aa; wait ab; ¬ ok aa; tr aa ≤ tr ab; ¬ ok ab ∧ tr ab ≤ tr bb⟧ ⟹ tr aa ≤ tr bb› and 3 goals remain*) apply (erule exE (*‹⟦∃x::?'a. (?P::?'a ⇒ bool) x; ⋀x::?'a. ?P x ⟹ ?Q::bool⟧ ⟹ ?Q›*)) (*top goal: ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); ¬ wait aa; wait ab; ¬ ok aa; ∃zs. tr ab = tr aa @ zs; ¬ ok ab ∧ (∃zs. tr bb = tr ab @ zs)⟧ ⟹ ∃zs. tr bb = tr aa @ zs› and 3 goals remain*) apply (erule conjE (*‹⟦?P ∧ ?Q; ⟦?P; ?Q⟧ ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀aa ab bb ca zs. ⟦action.relation_of Ac (bb, ca); ¬ wait aa; wait ab; ¬ ok aa; ¬ ok ab ∧ (∃zs. tr bb = tr ab @ zs); tr ab = tr aa @ zs⟧ ⟹ ∃zs. tr bb = tr aa @ zs› and 3 goals remain*) apply (erule exE (*‹⟦∃x. ?P x; ⋀x. ?P x ⟹ ?Q⟧ ⟹ ?Q›*)) (*top goal: ‹⋀aa ab bb ca zs. ⟦action.relation_of Ac (bb, ca); ¬ wait aa; wait ab; ¬ ok aa; tr ab = tr aa @ zs; ¬ ok ab; ∃zs. tr bb = tr ab @ zs⟧ ⟹ ∃zs. tr bb = tr aa @ zs› and 3 goals remain*) apply (rule_tac x="zs@zsa" in exI (*‹?P ?x ⟹ ∃x. ?P x›*)) (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) (ca::('a, 'b) alpha_rp_scheme) (zs::'a list) zsa::'a list. ⟦action.relation_of (Ac::('a, 'b) action) (bb, ca); ¬ wait aa; wait ab; ¬ ok aa; tr ab = tr aa @ zs; ¬ ok ab; tr bb = tr ab @ zsa⟧ ⟹ ∃zs::'a list. tr bb = tr aa @ zs› and 3 goals remain*) apply simp (*discuss goal 2*) apply ((auto simp add: prefix_def (*‹?xs::?'a list ≤ ?ys::?'a list = (∃zs::?'a list. ?ys = ?xs @ zs)›*))[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*top goal: ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); ¬ wait aa; ¬ (wait ∘ fst) (ab, bb); ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ alpha_rp.more aa = alpha_rp.more ab; tr aa ≤ tr ab; case (ab, bb) of (A, A') ⇒ (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'⟧ ⟹ (ok aa ∧ Pre sc (alpha_rp.more aa) ⟶ ok bb ∧ sc (alpha_rp.more aa, alpha_rp.more bb) ∧ ¬ wait bb ∧ [] = tr bb - tr aa) ∧ tr aa ≤ tr bb› and 1 goal remains*) apply (simp add: true_def (*‹true ≡ λA. True›*)) (*top goal: ‹⋀aa ab bb ca. ⟦action.relation_of Ac (bb, ca); ¬ wait aa; ¬ wait ab; ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ alpha_rp.more aa = alpha_rp.more ab; tr aa ≤ tr ab; (ok ab ∧ Pre sc (alpha_rp.more ab) ⟶ ok bb ∧ sc (alpha_rp.more ab, alpha_rp.more bb) ∧ ¬ wait bb ∧ [] = tr bb - tr ab) ∧ tr ab ≤ tr bb⟧ ⟹ (ok aa ∧ Pre sc (alpha_rp.more aa) ⟶ ok bb ∧ sc (alpha_rp.more aa, alpha_rp.more bb) ∧ ¬ wait bb ∧ [] = tr bb - tr aa) ∧ tr aa ≤ tr bb› and 1 goal remains*) apply ((auto simp add: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*))[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma state_update_before_is_CSP4: assumes A : "relation_of Ac is CSP4 healthy" shows "relation_of (state_update_before sc Ac) is CSP4 healthy" apply (auto simp: relation_of_state_update_before (*‹action.relation_of (state_update_before ?sc ?Ac) = (R (λ(A, A'). Pre ?sc (alpha_rp.more A) ⊢ λ(A, A'). ?sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ tr A = tr A') ;; action.relation_of ?Ac)›*) relation_of_Skip (*‹action.relation_of Skip = R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A')›*) rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) CSP4_def (*‹CSP4 ?P ≡ ?P ;; action.relation_of Skip›*)) (*goals: 1. ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ba); action.relation_of Ac (ba, c)⟧ ⟹ ((((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of Ac) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (aa, c)› 2. ‹⋀c ab bb ca. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ca, c); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ab, bb); action.relation_of Ac (bb, ca)⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of Ac) (ab, c)› discuss goal 1*) apply (rule_tac b=c in comp_intro (*‹⟦(?P::?'a × ?'b ⇒ bool) (?a::?'a, ?b::?'b); (?Q::?'b × ?'c ⇒ bool) (?b, ?c::?'c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ Pre (sc::'b × 'b ⇒ bool) (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ba); action.relation_of (Ac::('a, 'b) action) (ba, c)⟧ ⟹ (((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of Ac) (aa, c)› 2. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ Pre (sc::'b × 'b ⇒ bool) (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ba); action.relation_of (Ac::('a, 'b) action) (ba, c)⟧ ⟹ ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (c, c)› discuss goal 1*) apply (rule_tac b=ba in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ba); action.relation_of Ac (ba, c)⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ba)› 2. ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ba); action.relation_of Ac (ba, c)⟧ ⟹ action.relation_of Ac (ba, c)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (split cond_splits) (*top goal: ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ba); action.relation_of Ac (ba, c)⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (c, c)› and 1 goal remains*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (rule_tac b=bb in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀(c::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ca, c); ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ Pre (sc::'b × 'b ⇒ bool) (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ab, bb); action.relation_of (Ac::('a, 'b) action) (bb, ca)⟧ ⟹ ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ab, bb)› 2. ‹⋀(c::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ca, c); ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ Pre (sc::'b × 'b ⇒ bool) (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ab, bb); action.relation_of (Ac::('a, 'b) action) (bb, ca)⟧ ⟹ action.relation_of Ac (bb, c)› discuss goal 1*) apply simp (*discuss goal 2*) apply (subst A[simplified design_defs rp_defs CSP4_def relation_of_Skip] (*‹action.relation_of Ac = (action.relation_of Ac ;; (R3 ∘ R2 ∘ R1) (λ(A, A'). ok A ∧ true (A, A') ⟶ ok A' ∧ (case (A, A') of (A, A') ⇒ tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A')))›*)) (*goal: ‹⋀c ab bb ca. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ca, c); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre sc (alpha_rp.more A) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ab, bb); action.relation_of Ac (bb, ca)⟧ ⟹ action.relation_of Ac (bb, c)›*) apply (auto simp: rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) . definition state_update_after :: "'σ relation ⇒ ('θ::ev_eq,'σ) action ⇒ ('θ,'σ) action" where "state_update_after sc Ac = action_of(relation_of Ac ;; R (true ⊢ (λ(A, A'). sc (more A, more A') & ¬wait A' & tr A = tr A')))" lemma state_update_after_is_action: "(relation_of Ac ;; R (true ⊢ (λ(A, A'). sc (more A, more A') & ¬wait A' & tr A = tr A'))) ∈ {p. is_CSP_process p}" apply simp (*goal: ‹(action.relation_of Ac ;; R (true ⊢ λ(A, A'). sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ tr A = tr A')) ∈ {p. is_CSP_process p}›*) apply (rule seq_CSP (*‹⟦?P is CSP1 healthy; ?P is R healthy; is_CSP_process ?Q⟧ ⟹ is_CSP_process (?P ;; ?Q)›*)) (*goals: 1. ‹action.relation_of Ac is CSP1 healthy› 2. ‹action.relation_of Ac is R healthy› 3. ‹is_CSP_process (R (true ⊢ λ(A, A'). sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ tr A = tr A'))› discuss goal 1*) apply ((auto simp: relation_of_CSP[simplified is_CSP_process_def] (*‹action.relation_of (?x::(?'a, ?'b) action) is CSP1 healthy ∧ action.relation_of ?x is CSP2 healthy ∧ action.relation_of ?x is R healthy›*))[1]) (*discuss goal 2*) apply ((auto simp: relation_of_CSP[simplified is_CSP_process_def] (*‹action.relation_of (?x::(?'a, ?'b) action) is CSP1 healthy ∧ action.relation_of ?x is CSP2 healthy ∧ action.relation_of ?x is R healthy›*))[1]) (*discuss goal 3*) apply (rule rd_is_CSP (*‹∀a b. ?r (a, b⦇ok := True⦈) ⟶ ?r (a, b⦇ok := False⦈) ⟹ is_CSP_process (R (?r ⊢ ?p))›*)) (*goal: ‹is_CSP_process (R (true ⊢ λ(A, A'). sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ tr A = tr A'))›*) apply auto (*proven 3 subgoals*) . lemmas state_update_after_is_CSP = state_update_after_is_action[simplified] lemma relation_of_state_update_after: "relation_of (state_update_after sc Ac) = (relation_of Ac ;; R (true ⊢ (λ(A, A'). sc (more A, more A') & ¬wait A' & tr A = tr A')))" by (simp add: state_update_after_def (*‹state_update_after ?sc ?Ac = action_of (action.relation_of ?Ac ;; R (true ⊢ λ(A, A'). ?sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ tr A = tr A'))›*) action_of_inverse (*‹?y ∈ {p. is_CSP_process p} ⟹ action.relation_of (action_of ?y) = ?y›*) state_update_after_is_CSP (*‹is_CSP_process (action.relation_of ?Ac ;; R (true ⊢ λ(A, A'). ?sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ tr A = tr A'))›*)) lemma mono_state_update_after: "mono (state_update_after sc)" by (auto simp: mono_def (*‹mono ?f = (∀x y. x ≤ y ⟶ ?f x ≤ ?f y)›*) less_eq_action (*‹?P ≤ ?Q ≡ ?P ⊑ ?Q›*) ref_def (*‹?P ⊑ ?Q ≡ ∀A. (action.relation_of ?Q ⟶ action.relation_of ?P) A›*) relation_of_state_update_after (*‹action.relation_of (state_update_after ?sc ?Ac) = (action.relation_of ?Ac ;; R (true ⊢ λ(A, A'). ?sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ tr A = tr A'))›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*) rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) split: cond_splits (*‹?A ((?P ◃ ?b ▹ ?Q) ?x) = ((?b ?x ⟶ ?A (?P ?x)) ∧ (¬ ?b ?x ⟶ ?A (?Q ?x)))› ‹?A ((?P ◃ ?b ▹ ?Q) ?x) = (¬ (?b ?x ∧ ¬ ?A (?P ?x) ∨ ¬ ?b ?x ∧ ¬ ?A (?Q ?x)))›*) dest: relation_of_spec_f_f[simplified] (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧f⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧f⇩f (?a⦇tr := []⦈, ?b)›*) relation_of_spec_t_f[simplified] (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧t⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧t⇩f (?a⦇tr := []⦈, ?b)›*)) lemma state_update_after_is_CSP3: assumes A : "relation_of Ac is CSP3 healthy" shows "relation_of (state_update_after sc Ac) is CSP3 healthy" apply ((auto simp: relation_of_state_update_after (*‹action.relation_of (state_update_after ?sc ?Ac) = (action.relation_of ?Ac ;; R (true ⊢ λ(A, A'). ?sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ tr A = tr A'))›*) relation_of_Skip (*‹action.relation_of Skip = R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A')›*) rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) CSP3_def (*‹CSP3 ?P ≡ action.relation_of Skip ;; ?P›*))[1]) (*goals: 1. ‹⋀aa ba c. ⟦action.relation_of Ac (aa, ba); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) ;; action.relation_of Ac ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'))) (aa, c)› 2. ‹⋀aa ab bb ca. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (aa, ab); action.relation_of Ac (ab, bb); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (bb, ca)⟧ ⟹ (action.relation_of Ac ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'))) (aa, ca)› discuss goal 1*) apply ((rule_tac b=aa in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*))[1]) (*goals: 1. ‹⋀aa ba c. ⟦action.relation_of Ac (aa, ba); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (aa, aa)› 2. ‹⋀aa ba c. ⟦action.relation_of Ac (aa, ba); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ (action.relation_of Ac ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'))) (aa, c)› discuss goal 1*) apply ((split cond_splits)[1]) (*top goal: ‹⋀aa ba c. ⟦action.relation_of Ac (aa, ba); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (aa, aa)› and 2 goals remain*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply ((rule_tac b=bb in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*))[1]) (*goals: 1. ‹⋀aa ab bb ca. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (aa, ab); action.relation_of Ac (ab, bb); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (bb, ca)⟧ ⟹ action.relation_of Ac (aa, bb)› 2. ‹⋀aa ab bb ca. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (aa, ab); action.relation_of Ac (ab, bb); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (bb, ca)⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (bb, ca)› discuss goal 1*) apply ((subst A[simplified design_defs rp_defs CSP3_def relation_of_Skip] (*‹action.relation_of Ac = ((R3 ∘ R2 ∘ R1) (λ(A, A'). ok A ∧ true (A, A') ⟶ ok A' ∧ (case (A, A') of (A, A') ⇒ tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A')) ;; action.relation_of Ac)›*))[1]) (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (aa, ab); action.relation_of (Ac::('a, 'b) action) (ab, bb); ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ (sc::'b × 'b ⇒ bool) (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (bb, ca)⟧ ⟹ action.relation_of Ac (aa, bb)› and 1 goal remains*) apply ((auto simp: rp_defs (*‹R1 (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ λ(A::(?'θ, ?'σ) alpha_rp_scheme, A'::(?'θ, ?'σ) alpha_rp_scheme). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ λ(A::(?'θ, ?'σ) alpha_rp_scheme, A'::(?'θ, ?'σ) alpha_rp_scheme). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec (?b::bool) (?b'::bool) (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ λ(A::(?'θ, ?'σ) alpha_rp_scheme, A'::(?'θ, ?'σ) alpha_rp_scheme). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*))[1]) (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma state_update_after_is_CSP4: "relation_of (state_update_after sc Ac) is CSP4 healthy" apply (auto simp: relation_of_state_update_after (*‹action.relation_of (state_update_after ?sc ?Ac) = (action.relation_of ?Ac ;; R (true ⊢ λ(A, A'). ?sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ tr A = tr A'))›*) relation_of_Skip (*‹action.relation_of Skip = R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A')›*) rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) CSP4_def (*‹CSP4 ?P ≡ ?P ;; action.relation_of Skip›*)) (*goals: 1. ‹⋀aa ba c. ⟦action.relation_of Ac (aa, ba); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((action.relation_of Ac ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'))) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (aa, c)› 2. ‹⋀c ab bb ca. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ca, c); action.relation_of Ac (ab, bb); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (bb, ca)⟧ ⟹ (action.relation_of Ac ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'))) (ab, c)› discuss goal 1*) apply (rule_tac b=c in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀aa ba c. ⟦action.relation_of Ac (aa, ba); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ (action.relation_of Ac ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'))) (aa, c)› 2. ‹⋀aa ba c. ⟦action.relation_of Ac (aa, ba); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (c, c)› discuss goal 1*) apply (rule_tac b=ba in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀aa ba c. ⟦action.relation_of Ac (aa, ba); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ action.relation_of Ac (aa, ba)› 2. ‹⋀aa ba c. ⟦action.relation_of Ac (aa, ba); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ba, c)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (split cond_splits) (*top goal: ‹⋀aa ba c. ⟦action.relation_of Ac (aa, ba); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (c, c)› and 1 goal remains*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (split cond_splits) (*goals: 1. ‹⋀c ab bb ca. ⟦action.relation_of Ac (ab, bb); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (bb, ca); (wait ∘ fst) (ca, c); case (ca, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (action.relation_of Ac ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'))) (ab, c)› 2. ‹⋀c ab bb ca. ⟦action.relation_of Ac (ab, bb); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (bb, ca); ¬ (wait ∘ fst) (ca, c); case (ca, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ (action.relation_of Ac ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'))) (ab, c)› discuss goal 1*) apply simp (*top goal: ‹⋀c ab bb ca. ⟦action.relation_of Ac (ab, bb); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (bb, ca); (wait ∘ fst) (ca, c); case (ca, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (action.relation_of Ac ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'))) (ab, c)› and 1 goal remains*) apply (split cond_splits) (*goals: 1. ‹⋀(c::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦wait ca; ¬ ok ca ∧ tr ca ≤ tr c ∨ ok c ∧ tr ca = tr c ∧ wait c ∧ ref ca = ref c ∧ alpha_rp.more ca = alpha_rp.more c; action.relation_of (Ac::('a, 'b) action) (ab, bb); (wait ∘ fst) (bb, ca); case (bb, ca) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (action.relation_of Ac ;; ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ (sc::'b × 'b ⇒ bool) (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'))) (ab, c)› 2. ‹⋀(c::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦wait ca; ¬ ok ca ∧ tr ca ≤ tr c ∨ ok c ∧ tr ca = tr c ∧ wait c ∧ ref ca = ref c ∧ alpha_rp.more ca = alpha_rp.more c; action.relation_of (Ac::('a, 'b) action) (ab, bb); ¬ (wait ∘ fst) (bb, ca); case (bb, ca) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ (sc::'b × 'b ⇒ bool) (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'⟧ ⟹ (action.relation_of Ac ;; ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'))) (ab, c)› discuss goal 1*) apply simp (*top goal: ‹⋀c ab bb ca. ⟦wait ca; ¬ ok ca ∧ tr ca ≤ tr c ∨ ok c ∧ tr ca = tr c ∧ wait c ∧ ref ca = ref c ∧ alpha_rp.more ca = alpha_rp.more c; action.relation_of Ac (ab, bb); (wait ∘ fst) (bb, ca); case (bb, ca) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (action.relation_of Ac ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'))) (ab, c)› and 2 goals remain*) apply (rule_tac b=bb in comp_intro (*‹⟦(?P::?'a::type × ?'b::type ⇒ bool) (?a::?'a::type, ?b::?'b::type); (?Q::?'b::type × ?'c::type ⇒ bool) (?b, ?c::?'c::type)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀c ab bb ca. ⟦wait ca; ¬ ok ca ∧ tr ca ≤ tr c ∨ ok c ∧ tr ca = tr c ∧ wait c ∧ ref ca = ref c ∧ alpha_rp.more ca = alpha_rp.more c; action.relation_of Ac (ab, bb); wait bb; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ action.relation_of Ac (ab, bb)› 2. ‹⋀c ab bb ca. ⟦wait ca; ¬ ok ca ∧ tr ca ≤ tr c ∨ ok c ∧ tr ca = tr c ∧ wait c ∧ ref ca = ref c ∧ alpha_rp.more ca = alpha_rp.more c; action.relation_of Ac (ab, bb); wait bb; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (bb, c)› discuss goal 1*) apply simp (*discuss goal 2*) apply (split cond_splits) (*top goal: ‹⋀c ab bb ca. ⟦wait ca; ¬ ok ca ∧ tr ca ≤ tr c ∨ ok c ∧ tr ca = tr c ∧ wait c ∧ ref ca = ref c ∧ alpha_rp.more ca = alpha_rp.more c; action.relation_of Ac (ab, bb); wait bb; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (bb, c)› and 2 goals remain*) apply simp (*top goal: ‹⋀c ab bb ca. ⟦wait ca; ¬ ok ca ∧ tr ca ≤ tr c ∨ ok c ∧ tr ca = tr c ∧ wait c ∧ ref ca = ref c ∧ alpha_rp.more ca = alpha_rp.more c; action.relation_of Ac (ab, bb); wait bb; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ ((wait ∘ fst) (bb, c) ⟶ (case (bb, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A')) ∧ (¬ (wait ∘ fst) (bb, c) ⟶ (case (bb, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'))› and 2 goals remain*) apply (case_tac "ok bb") (*goals: 1. ‹⋀c ab bb ca. ⟦wait ca; ¬ ok ca ∧ tr ca ≤ tr c ∨ ok c ∧ tr ca = tr c ∧ wait c ∧ ref ca = ref c ∧ alpha_rp.more ca = alpha_rp.more c; action.relation_of Ac (ab, bb); wait bb; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca; ok bb⟧ ⟹ ¬ ok bb ∧ tr bb ≤ tr c ∨ ok c ∧ tr bb = tr c ∧ wait c ∧ ref bb = ref c ∧ alpha_rp.more bb = alpha_rp.more c› 2. ‹⋀c ab bb ca. ⟦wait ca; ¬ ok ca ∧ tr ca ≤ tr c ∨ ok c ∧ tr ca = tr c ∧ wait c ∧ ref ca = ref c ∧ alpha_rp.more ca = alpha_rp.more c; action.relation_of Ac (ab, bb); wait bb; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca; ¬ ok bb⟧ ⟹ ¬ ok bb ∧ tr bb ≤ tr c ∨ ok c ∧ tr bb = tr c ∧ wait c ∧ ref bb = ref c ∧ alpha_rp.more bb = alpha_rp.more c› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*top goal: ‹⋀c ab bb ca. ⟦wait ca; ¬ ok ca ∧ tr ca ≤ tr c ∨ ok c ∧ tr ca = tr c ∧ wait c ∧ ref ca = ref c ∧ alpha_rp.more ca = alpha_rp.more c; action.relation_of Ac (ab, bb); wait bb; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca; ¬ ok bb⟧ ⟹ ¬ ok bb ∧ tr bb ≤ tr c ∨ ok c ∧ tr bb = tr c ∧ wait c ∧ ref bb = ref c ∧ alpha_rp.more bb = alpha_rp.more c› and 2 goals remain*) apply (case_tac "tr bb ≤ tr c") (*goals: 1. ‹⋀c ab bb ca. ⟦wait ca; ¬ ok ca ∧ tr ca ≤ tr c ∨ ok c ∧ tr ca = tr c ∧ wait c ∧ ref ca = ref c ∧ alpha_rp.more ca = alpha_rp.more c; action.relation_of Ac (ab, bb); wait bb; tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca; ¬ ok bb; tr bb ≤ tr c⟧ ⟹ tr bb ≤ tr c ∨ ok c ∧ tr bb = tr c ∧ wait c ∧ ref bb = ref c ∧ alpha_rp.more bb = alpha_rp.more c› 2. ‹⋀c ab bb ca. ⟦wait ca; ¬ ok ca ∧ tr ca ≤ tr c ∨ ok c ∧ tr ca = tr c ∧ wait c ∧ ref ca = ref c ∧ alpha_rp.more ca = alpha_rp.more c; action.relation_of Ac (ab, bb); wait bb; tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca; ¬ ok bb; ¬ tr bb ≤ tr c⟧ ⟹ tr bb ≤ tr c ∨ ok c ∧ tr bb = tr c ∧ wait c ∧ ref bb = ref c ∧ alpha_rp.more bb = alpha_rp.more c› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*top goal: ‹⋀c ab bb ca. ⟦wait ca; ¬ ok ca ∧ tr ca ≤ tr c ∨ ok c ∧ tr ca = tr c ∧ wait c ∧ ref ca = ref c ∧ alpha_rp.more ca = alpha_rp.more c; action.relation_of Ac (ab, bb); wait bb; tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca; ¬ ok bb; ¬ tr bb ≤ tr c⟧ ⟹ tr bb ≤ tr c ∨ ok c ∧ tr bb = tr c ∧ wait c ∧ ref bb = ref c ∧ alpha_rp.more bb = alpha_rp.more c› and 2 goals remain*) apply (case_tac "ok ca") (*goals: 1. ‹⋀c ab bb ca. ⟦wait ca; ¬ ok ca ∧ tr ca ≤ tr c ∨ ok c ∧ tr ca = tr c ∧ wait c ∧ ref ca = ref c ∧ alpha_rp.more ca = alpha_rp.more c; action.relation_of Ac (ab, bb); wait bb; tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca; ¬ ok bb; ¬ tr bb ≤ tr c; ok ca⟧ ⟹ ok c ∧ tr bb = tr c ∧ wait c ∧ ref bb = ref c ∧ alpha_rp.more bb = alpha_rp.more c› 2. ‹⋀c ab bb ca. ⟦wait ca; ¬ ok ca ∧ tr ca ≤ tr c ∨ ok c ∧ tr ca = tr c ∧ wait c ∧ ref ca = ref c ∧ alpha_rp.more ca = alpha_rp.more c; action.relation_of Ac (ab, bb); wait bb; tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca; ¬ ok bb; ¬ tr bb ≤ tr c; ¬ ok ca⟧ ⟹ ok c ∧ tr bb = tr c ∧ wait c ∧ ref bb = ref c ∧ alpha_rp.more bb = alpha_rp.more c› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*top goal: ‹⋀(c::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦wait ca; ¬ ok ca ∧ tr ca ≤ tr c ∨ ok c ∧ tr ca = tr c ∧ wait c ∧ ref ca = ref c ∧ alpha_rp.more ca = alpha_rp.more c; action.relation_of (Ac::('a, 'b) action) (ab, bb); wait bb; tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca; ¬ ok bb; ¬ tr bb ≤ tr c; ¬ ok ca⟧ ⟹ ok c ∧ tr bb = tr c ∧ wait c ∧ ref bb = ref c ∧ alpha_rp.more bb = alpha_rp.more c› and 2 goals remain*) apply (case_tac "tr ca ≤ tr c") (*goals: 1. ‹⋀(c::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦wait ca; tr ca ≤ tr c ∨ ok c ∧ tr ca = tr c ∧ wait c ∧ ref ca = ref c ∧ alpha_rp.more ca = alpha_rp.more c; action.relation_of (Ac::('a, 'b) action) (ab, bb); wait bb; tr bb ≤ tr ca; ¬ ok bb; ¬ tr bb ≤ tr c; ¬ ok ca; tr ca ≤ tr c⟧ ⟹ ok c ∧ tr bb = tr c ∧ wait c ∧ ref bb = ref c ∧ alpha_rp.more bb = alpha_rp.more c› 2. ‹⋀(c::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦wait ca; tr ca ≤ tr c ∨ ok c ∧ tr ca = tr c ∧ wait c ∧ ref ca = ref c ∧ alpha_rp.more ca = alpha_rp.more c; action.relation_of (Ac::('a, 'b) action) (ab, bb); wait bb; tr bb ≤ tr ca; ¬ ok bb; ¬ tr bb ≤ tr c; ¬ ok ca; ¬ tr ca ≤ tr c⟧ ⟹ ok c ∧ tr bb = tr c ∧ wait c ∧ ref bb = ref c ∧ alpha_rp.more bb = alpha_rp.more c› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*top goal: ‹⋀c ab bb ca. ⟦wait ca; ¬ ok ca ∧ tr ca ≤ tr c ∨ ok c ∧ tr ca = tr c ∧ wait c ∧ ref ca = ref c ∧ alpha_rp.more ca = alpha_rp.more c; action.relation_of Ac (ab, bb); ¬ (wait ∘ fst) (bb, ca); case (bb, ca) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'⟧ ⟹ (action.relation_of Ac ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'))) (ab, c)› and 1 goal remains*) apply ((auto simp add: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*) comp_def (*‹?P ;; ?Q ≡ λr. r ∈ {p. ?P p} O {q. ?Q q}›*) true_def (*‹true ≡ λA. True›*) split: cond_splits (*‹?A ((?P ◃ ?b ▹ ?Q) ?x) = ((?b ?x ⟶ ?A (?P ?x)) ∧ (¬ ?b ?x ⟶ ?A (?Q ?x)))› ‹?A ((?P ◃ ?b ▹ ?Q) ?x) = (¬ (?b ?x ∧ ¬ ?A (?P ?x) ∨ ¬ ?b ?x ∧ ¬ ?A (?Q ?x)))›*))[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*goal: ‹⋀c ab bb ca. ⟦action.relation_of Ac (ab, bb); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (bb, ca); ¬ (wait ∘ fst) (ca, c); case (ca, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ (action.relation_of Ac ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'))) (ab, c)›*) apply ((auto simp add: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*) comp_def (*‹?P ;; ?Q ≡ λr. r ∈ {p. ?P p} O {q. ?Q q}›*) true_def (*‹true ≡ λA. True›*) split: cond_splits (*‹?A ((?P ◃ ?b ▹ ?Q) ?x) = ((?b ?x ⟶ ?A (?P ?x)) ∧ (¬ ?b ?x ⟶ ?A (?Q ?x)))› ‹?A ((?P ◃ ?b ▹ ?Q) ?x) = (¬ (?b ?x ∧ ¬ ?A (?P ?x) ∨ ¬ ?b ?x ∧ ¬ ?A (?Q ?x)))›*))[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) . subsection ‹Sequential composition› definition Seq::"('θ::ev_eq,'σ) action ⇒ ('θ,'σ) action ⇒ ('θ,'σ) action" (infixl "`;`" 24) where "P `;` Q ≡ action_of (relation_of P ;; relation_of Q)" lemma Seq_is_action: "(relation_of P ;; relation_of Q) ∈ {p. is_CSP_process p}" apply simp (*goal: ‹(action.relation_of P ;; action.relation_of Q) ∈ {p. is_CSP_process p}›*) by (rule seq_CSP[OF relation_of_CSP[THEN CSP_is_CSP1] relation_of_CSP[THEN CSP_is_R] relation_of_CSP] (*‹is_CSP_process (action.relation_of (?x3::(?'a1, ?'b) action) ;; action.relation_of (?x1::(?'a1, ?'b) action))›*)) lemmas Seq_is_CSP = Seq_is_action[simplified] lemma relation_of_Seq: "relation_of (P `;` Q) = (relation_of P ;; relation_of Q)" by (simp add: Seq_def (*‹?P `;` ?Q ≡ action_of (action.relation_of ?P ;; action.relation_of ?Q)›*) action_of_inverse (*‹?y ∈ {p. is_CSP_process p} ⟹ action.relation_of (action_of ?y) = ?y›*) Seq_is_CSP (*‹is_CSP_process (action.relation_of ?P ;; action.relation_of ?Q)›*)) lemma mono_Seq: "mono ((`;`) P)" by (auto simp: mono_def (*‹mono ?f = (∀x y. x ≤ y ⟶ ?f x ≤ ?f y)›*) less_eq_action (*‹?P ≤ ?Q ≡ ?P ⊑ ?Q›*) ref_def (*‹?P ⊑ ?Q ≡ ∀A. (action.relation_of ?Q ⟶ action.relation_of ?P) A›*) relation_of_Seq (*‹action.relation_of (?P `;` ?Q) = (action.relation_of ?P ;; action.relation_of ?Q)›*)) lemma CSP3_imp_left_Skip: assumes A: "relation_of P is CSP3 healthy" shows "(Skip `;` P) = P" apply (subst relation_of_inject[symmetric] (*‹((?x::(?'θ::ev_eq, ?'σ::type) action) = (?y::(?'θ::ev_eq, ?'σ::type) action)) = (action.relation_of ?x = action.relation_of ?y)›*)) (*goal: ‹(Skip `;` P) = P›*) by (simp add: relation_of_Seq (*‹action.relation_of ((?P::(?'a, ?'b) action) `;` (?Q::(?'a, ?'b) action)) = (action.relation_of ?P ;; action.relation_of ?Q)›*) A[simplified design_defs CSP3_def, symmetric] (*‹(action.relation_of Skip ;; action.relation_of (P::('a, 'b) action)) = action.relation_of P›*)) lemma CSP4_imp_right_Skip: assumes A: "relation_of P is CSP4 healthy" shows "(P `;` Skip) = P" apply (subst relation_of_inject[symmetric] (*‹(?x = ?y) = (action.relation_of ?x = action.relation_of ?y)›*)) (*goal: ‹(P `;` Skip) = P›*) by (simp add: relation_of_Seq (*‹action.relation_of (?P `;` ?Q) = (action.relation_of ?P ;; action.relation_of ?Q)›*) A[simplified design_defs CSP4_def, symmetric] (*‹(action.relation_of P ;; action.relation_of Skip) = action.relation_of P›*)) lemma Seq_assoc: "(A `;` (B `;` C)) = ((A `;` B) `;` C)" by (auto simp: relation_of_inject[symmetric] (*‹(?x = ?y) = (action.relation_of ?x = action.relation_of ?y)›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) relation_of_Seq (*‹action.relation_of (?P `;` ?Q) = (action.relation_of ?P ;; action.relation_of ?Q)›*) rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*)) lemma Skip_absorb: "(Skip `;` Skip) = Skip" by (auto simp: Skip_comp_absorb (*‹(action.relation_of Skip ;; action.relation_of Skip) = action.relation_of Skip›*) relation_of_inject[symmetric] (*‹((?x::(?'θ::ev_eq, ?'σ::type) action) = (?y::(?'θ::ev_eq, ?'σ::type) action)) = (action.relation_of ?x = action.relation_of ?y)›*) relation_of_Seq (*‹action.relation_of ((?P::(?'a::ev_eq, ?'b::type) action) `;` (?Q::(?'a::ev_eq, ?'b::type) action)) = (action.relation_of ?P ;; action.relation_of ?Q)›*)) subsection ‹Internal choice› definition Ndet::"('θ::ev_eq,'σ) action ⇒ ('θ,'σ) action ⇒ ('θ,'σ) action" (infixl "⊓" 18) where "P ⊓ Q ≡ action_of ((relation_of P) ∨ (relation_of Q))" lemma Ndet_is_action: "((relation_of P) ∨ (relation_of Q)) ∈ {p. is_CSP_process p}" apply simp (*goal: ‹(action.relation_of P ∨ action.relation_of Q) ∈ {p. is_CSP_process p}›*) apply (rule disj_CSP (*‹⟦is_CSP_process ?P; is_CSP_process ?Q⟧ ⟹ is_CSP_process (?P ∨ ?Q)›*)) (*goals: 1. ‹is_CSP_process (action.relation_of P)› 2. ‹is_CSP_process (action.relation_of Q)› discuss goal 1*) apply (simp add: relation_of_CSP (*‹is_CSP_process (action.relation_of ?x)›*)) (*discuss goal 2*) apply (simp add: relation_of_CSP (*‹is_CSP_process (action.relation_of (?x::(?'a, ?'b) action))›*)) (*proven 2 subgoals*) . lemmas Ndet_is_CSP = Ndet_is_action[simplified] lemma relation_of_Ndet: "relation_of (P ⊓ Q) = ((relation_of P) ∨ (relation_of Q))" by (simp add: Ndet_def (*‹(?P::(?'θ, ?'σ) action) ⊓ (?Q::(?'θ, ?'σ) action) ≡ action_of (action.relation_of ?P ∨ action.relation_of ?Q)›*) action_of_inverse (*‹(?y::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ∈ {p::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool. is_CSP_process p} ⟹ action.relation_of (action_of ?y) = ?y›*) Ndet_is_CSP (*‹is_CSP_process (action.relation_of (?P::(?'a, ?'b) action) ∨ action.relation_of (?Q::(?'a, ?'b) action))›*)) lemma mono_Ndet: "mono ((⊓) P)" by (auto simp: mono_def (*‹mono ?f = (∀x y. x ≤ y ⟶ ?f x ≤ ?f y)›*) less_eq_action (*‹?P ≤ ?Q ≡ ?P ⊑ ?Q›*) ref_def (*‹?P ⊑ ?Q ≡ ∀A. (action.relation_of ?Q ⟶ action.relation_of ?P) A›*) relation_of_Ndet (*‹action.relation_of (?P ⊓ ?Q) = (action.relation_of ?P ∨ action.relation_of ?Q)›*)) subsection ‹External choice› definition Det::"('θ::ev_eq,'σ) action ⇒ ('θ,'σ) action ⇒ ('θ,'σ) action" (infixl "□" 18) where "P □ Q ≡ action_of(R((¬((relation_of P)⇧f⇩f) ∧ ¬((relation_of Q)⇧f⇩f)) ⊢ (((relation_of P)⇧t⇩f ∧ ((relation_of Q)⇧t⇩f)) ◃ λ(A, A'). tr A = tr A' ∧ wait A' ▹ ((relation_of P)⇧t⇩f ∨ ((relation_of Q)⇧t⇩f)))))" lemma Det_is_action: "(R((¬((relation_of P)⇧f⇩f) ∧ ¬((relation_of Q)⇧f⇩f)) ⊢ (((relation_of P)⇧t⇩f ∧ ((relation_of Q)⇧t⇩f)) ◃ λ(A, A'). tr A = tr A' ∧ wait A' ▹ ((relation_of P)⇧t⇩f ∨ ((relation_of Q)⇧t⇩f))))) ∈ {p. is_CSP_process p}" apply (simp add: spec_def (*‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*)) (*goal: ‹R (¬ action.relation_of P⇧f⇩f ∧ ¬ action.relation_of Q⇧f⇩f ⊢ action.relation_of P⇧t⇩f ∧ action.relation_of Q⇧t⇩f ◃ λ(A, A'). tr A = tr A' ∧ wait A' ▹ action.relation_of P⇧t⇩f ∨ action.relation_of Q⇧t⇩f) ∈ {p. is_CSP_process p}›*) apply (rule rd_is_CSP (*‹∀a b. ?r (a, b⦇ok := True⦈) ⟶ ?r (a, b⦇ok := False⦈) ⟹ is_CSP_process (R (?r ⊢ ?p))›*)) (*goal: ‹is_CSP_process (R ((λA::('a, 'b) alpha_rp_scheme × ('a, 'b) alpha_rp_scheme. ¬ (case A of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ action.relation_of (P::('a, 'b) action) (A⦇wait := False⦈, A'⦇ok := False⦈))) ∧ (λA::('a, 'b) alpha_rp_scheme × ('a, 'b) alpha_rp_scheme. ¬ (case A of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ action.relation_of (Q::('a, 'b) action) (A⦇wait := False⦈, A'⦇ok := False⦈))) ⊢ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). action.relation_of P (A⦇wait := False⦈, A'⦇ok := True⦈)) ∧ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). action.relation_of Q (A⦇wait := False⦈, A'⦇ok := True⦈)) ◃ λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). tr A = tr A' ∧ wait A' ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). action.relation_of P (A⦇wait := False⦈, A'⦇ok := True⦈)) ∨ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). action.relation_of Q (A⦇wait := False⦈, A'⦇ok := True⦈))))›*) by auto lemmas Det_is_CSP = Det_is_action[simplified] lemma relation_of_Det: "relation_of (P □ Q) = (R((¬((relation_of P)⇧f⇩f) ∧ ¬((relation_of Q)⇧f⇩f)) ⊢ (((relation_of P)⇧t⇩f ∧ ((relation_of Q)⇧t⇩f)) ◃ λ(A, A'). tr A = tr A' ∧ wait A' ▹ ((relation_of P)⇧t⇩f ∨ ((relation_of Q)⇧t⇩f)))))" apply (unfold Det_def (*‹?P □ ?Q ≡ action_of (R (¬ action.relation_of ?P⇧f⇩f ∧ ¬ action.relation_of ?Q⇧f⇩f ⊢ action.relation_of ?P⇧t⇩f ∧ action.relation_of ?Q⇧t⇩f ◃ λ(A, A'). tr A = tr A' ∧ wait A' ▹ action.relation_of ?P⇧t⇩f ∨ action.relation_of ?Q⇧t⇩f))›*)) (*goal: ‹action.relation_of ((P::('a, 'b) action) □ (Q::('a, 'b) action)) = R (¬ action.relation_of P⇧f⇩f ∧ ¬ action.relation_of Q⇧f⇩f ⊢ action.relation_of P⇧t⇩f ∧ action.relation_of Q⇧t⇩f ◃ λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). tr A = tr A' ∧ wait A' ▹ action.relation_of P⇧t⇩f ∨ action.relation_of Q⇧t⇩f)›*) apply (rule action_of_inverse (*‹?y ∈ {p. is_CSP_process p} ⟹ action.relation_of (action_of ?y) = ?y›*)) (*goal: ‹action.relation_of (action_of (R (¬ action.relation_of (P::('a::ev_eq, 'b::type) action)⇧f⇩f ∧ ¬ action.relation_of (Q::('a::ev_eq, 'b::type) action)⇧f⇩f ⊢ action.relation_of P⇧t⇩f ∧ action.relation_of Q⇧t⇩f ◃ λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). tr A = tr A' ∧ wait A' ▹ action.relation_of P⇧t⇩f ∨ action.relation_of Q⇧t⇩f))) = R (¬ action.relation_of P⇧f⇩f ∧ ¬ action.relation_of Q⇧f⇩f ⊢ action.relation_of P⇧t⇩f ∧ action.relation_of Q⇧t⇩f ◃ λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). tr A = tr A' ∧ wait A' ▹ action.relation_of P⇧t⇩f ∨ action.relation_of Q⇧t⇩f)›*) by (rule Det_is_action (*‹R (¬ action.relation_of ?P⇧f⇩f ∧ ¬ action.relation_of ?Q⇧f⇩f ⊢ action.relation_of ?P⇧t⇩f ∧ action.relation_of ?Q⇧t⇩f ◃ λ(A, A'). tr A = tr A' ∧ wait A' ▹ action.relation_of ?P⇧t⇩f ∨ action.relation_of ?Q⇧t⇩f) ∈ {p. is_CSP_process p}›*)) lemma mono_Det: "mono ((□) P)" by (auto simp: mono_def (*‹mono ?f = (∀x y. x ≤ y ⟶ ?f x ≤ ?f y)›*) less_eq_action (*‹?P ≤ ?Q ≡ ?P ⊑ ?Q›*) ref_def (*‹?P ⊑ ?Q ≡ ∀A. (action.relation_of ?Q ⟶ action.relation_of ?P) A›*) relation_of_Det (*‹action.relation_of (?P □ ?Q) = R (¬ action.relation_of ?P⇧f⇩f ∧ ¬ action.relation_of ?Q⇧f⇩f ⊢ action.relation_of ?P⇧t⇩f ∧ action.relation_of ?Q⇧t⇩f ◃ λ(A, A'). tr A = tr A' ∧ wait A' ▹ action.relation_of ?P⇧t⇩f ∨ action.relation_of ?Q⇧t⇩f)›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*) rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) split: cond_splits (*‹?A ((?P ◃ ?b ▹ ?Q) ?x) = ((?b ?x ⟶ ?A (?P ?x)) ∧ (¬ ?b ?x ⟶ ?A (?Q ?x)))› ‹?A ((?P ◃ ?b ▹ ?Q) ?x) = (¬ (?b ?x ∧ ¬ ?A (?P ?x) ∨ ¬ ?b ?x ∧ ¬ ?A (?Q ?x)))›*) dest: relation_of_spec_f_f[simplified] (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧f⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧f⇩f (?a⦇tr := []⦈, ?b)›*) relation_of_spec_t_f[simplified] (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧t⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧t⇩f (?a⦇tr := []⦈, ?b)›*)) subsection ‹Reactive design assignment› definition "rd_assign s = action_of (R (true ⊢ λ(A, A'). ref A' = ref A ∧ tr A' = tr A ∧ ¬wait A' ∧ more A' = s))" lemma rd_assign_is_action: "(R (true ⊢ λ(A, A'). ref A' = ref A ∧ tr A' = tr A ∧ ¬wait A' ∧ more A' = s)) ∈ {p. is_CSP_process p}" sorry lemmas rd_assign_is_CSP = rd_assign_is_action[simplified] lemma relation_of_rd_assign: "relation_of (rd_assign s) = (R (true ⊢ λ(A, A'). ref A' = ref A ∧ tr A' = tr A ∧ ¬wait A' ∧ more A' = s))" by (simp add: rd_assign_def (*‹rd_assign ?s = action_of (R (true ⊢ λ(A, A'). ref A' = ref A ∧ tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = ?s))›*) action_of_inverse (*‹?y ∈ {p. is_CSP_process p} ⟹ action.relation_of (action_of ?y) = ?y›*) rd_assign_is_CSP (*‹is_CSP_process (R (true ⊢ λ(A, A'). ref A' = ref A ∧ tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = ?s))›*)) subsection ‹Local state external choice› definition Loc::"'σ ⇒ ('θ::ev_eq,'σ) action ⇒ 'σ ⇒ ('θ,'σ) action ⇒ ('θ,'σ) action" ("'(()loc _ ∙ _ ') \<boxplus> '(()loc _ ∙ _ ')") where "(loc s1 ∙ P) \<boxplus> (loc s2 ∙ Q) ≡ ((rd_assign s1)`;`P) □ ((rd_assign s2)`;` Q)" subsection ‹Schema expression› definition Schema :: "'σ relation ⇒ ('θ::ev_eq,'σ) action" where "Schema sc ≡ action_of(R ((λ(A, A'). (Pre sc) (more A)) ⊢ (λ(A, A'). sc (more A, more A') ∧ ¬wait A' ∧ tr A = tr A')))" lemma Schema_is_action: "(R ((λ(A, A'). (Pre sc) (more A)) ⊢ (λ(A, A'). sc (more A, more A') & ¬wait A' & tr A = tr A'))) ∈ {p. is_CSP_process p}" sorry lemmas Schema_is_CSP = Schema_is_action[simplified] lemma relation_of_Schema: "relation_of (Schema sc) = (R ((λ(A, A'). (Pre sc) (more A)) ⊢ (λ(A, A'). sc (more A, more A') ∧ ¬wait A' ∧ tr A = tr A')))" by (simp add: Schema_def (*‹Schema ?sc ≡ action_of (R (λ(A, A'). Pre ?sc (alpha_rp.more A) ⊢ λ(A, A'). ?sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ tr A = tr A'))›*) action_of_inverse (*‹?y ∈ {p. is_CSP_process p} ⟹ action.relation_of (action_of ?y) = ?y›*) Schema_is_CSP (*‹is_CSP_process (R (λ(A, A'). Pre ?sc (alpha_rp.more A) ⊢ λ(A, A'). ?sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ tr A = tr A'))›*)) lemma Schema_is_state_update_before: "Schema u = state_update_before u Skip" apply (subst relation_of_inject[symmetric] (*‹(?x = ?y) = (action.relation_of ?x = action.relation_of ?y)›*)) (*goal: ‹Schema u = state_update_before u Skip›*) apply (auto simp: relation_of_Schema (*‹action.relation_of (Schema (?sc::?'b × ?'b ⇒ bool)) = R (λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). Pre ?sc (alpha_rp.more A) ⊢ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). ?sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ tr A = tr A')›*) relation_of_state_update_before (*‹action.relation_of (state_update_before (?sc::?'b × ?'b ⇒ bool) (?Ac::(?'a, ?'b) action)) = (R (λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). Pre ?sc (alpha_rp.more A) ⊢ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). ?sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ tr A = tr A') ;; action.relation_of ?Ac)›*) relation_of_Skip (*‹action.relation_of Skip = R (true ⊢ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A')›*) rp_defs (*‹R1 (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ λ(A::(?'θ, ?'σ) alpha_rp_scheme, A'::(?'θ, ?'σ) alpha_rp_scheme). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ λ(A::(?'θ, ?'σ) alpha_rp_scheme, A'::(?'θ, ?'σ) alpha_rp_scheme). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec (?b::bool) (?b'::bool) (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ λ(A::(?'θ, ?'σ) alpha_rp_scheme, A'::(?'θ, ?'σ) alpha_rp_scheme). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) fun_eq_iff (*‹((?f::?'a ⇒ ?'b) = (?g::?'a ⇒ ?'b)) = (∀x::?'a. ?f x = ?g x)›*) design_defs (*‹(?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool ⊢ ?Q::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). A = A')› ‹J ≡ λ(A::?'a alpha_d_scheme, A'::?'a alpha_d_scheme). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P::?'α × ?'α ⇒ bool is ?H::(?'α × ?'α ⇒ bool) ⇒ ?'α × ?'α ⇒ bool healthy ≡ ?P = ?H ?P› ‹H1 (?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ ok ∘ fst ⟶ ?P› ‹H2 (?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ ?P ;; J› ‹H3 (?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ ?P ;; Πd› ‹H4 (?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ (?P ;; true) ⟷ true› ‹σf (?D::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ?D (A, A'⦇ok := False⦈)› ‹σt (?D::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ok A› ‹OKAY' ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ok A'›*)) (*goals: 1. ‹⋀a b. ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre u (alpha_rp.more A) ⟶ ok A' ∧ u (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (a, b) ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre u (alpha_rp.more A) ⟶ ok A' ∧ u (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› 2. ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre u (alpha_rp.more A) ⟶ ok A' ∧ u (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ba); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre u (alpha_rp.more A) ⟶ ok A' ∧ u (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, c)› discuss goal 1*) apply (split cond_splits) (*goals: 1. ‹⋀a b. ⟦(wait ∘ fst) (a, b); case (a, b) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre u (alpha_rp.more A) ⟶ ok A' ∧ u (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› 2. ‹⋀a b. ⟦¬ (wait ∘ fst) (a, b); case (a, b) of (A, A') ⇒ (ok A ∧ Pre u (alpha_rp.more A) ⟶ ok A' ∧ u (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre u (alpha_rp.more A) ⟶ ok A' ∧ u (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› discuss goal 1*) apply simp (*top goal: ‹⋀a b. ⟦(wait ∘ fst) (a, b); case (a, b) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre u (alpha_rp.more A) ⟶ ok A' ∧ u (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› and 2 goals remain*) apply (rule comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀a b. ⟦wait a; ¬ ok a ∧ tr a ≤ tr b ∨ ok b ∧ tr a = tr b ∧ wait b ∧ ref a = ref b ∧ alpha_rp.more a = alpha_rp.more b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre u (alpha_rp.more A) ⟶ ok A' ∧ u (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (a, ?b26 a b)› 2. ‹⋀a b. ⟦wait a; ¬ ok a ∧ tr a ≤ tr b ∨ ok b ∧ tr a = tr b ∧ wait b ∧ ref a = ref b ∧ alpha_rp.more a = alpha_rp.more b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (?b26 a b, b)› discuss goal 1*) apply (split cond_splits) (*top goal: ‹⋀a b. ⟦wait a; ¬ ok a ∧ tr a ≤ tr b ∨ ok b ∧ tr a = tr b ∧ wait b ∧ ref a = ref b ∧ alpha_rp.more a = alpha_rp.more b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre u (alpha_rp.more A) ⟶ ok A' ∧ u (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (a, ?b26 a b)› and 3 goals remain*) apply simp (*discuss goal 2*) apply (split cond_splits) (*top goal: ‹⋀a b. ⟦wait a; ¬ ok a ∧ tr a ≤ tr b ∨ ok b ∧ tr a = tr b ∧ wait b ∧ ref a = ref b ∧ alpha_rp.more a = alpha_rp.more b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (b, b)› and 2 goals remain*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*top goal: ‹⋀a b. ⟦¬ (wait ∘ fst) (a, b); case (a, b) of (A, A') ⇒ (ok A ∧ Pre u (alpha_rp.more A) ⟶ ok A' ∧ u (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre u (alpha_rp.more A) ⟶ ok A' ∧ u (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› and 1 goal remains*) apply (rule comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀a b. ⟦¬ wait a; (ok a ∧ Pre u (alpha_rp.more a) ⟶ ok b ∧ u (alpha_rp.more a, alpha_rp.more b) ∧ ¬ wait b ∧ [] = tr b - tr a) ∧ tr a ≤ tr b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre u (alpha_rp.more A) ⟶ ok A' ∧ u (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (a, ?b37 a b)› 2. ‹⋀a b. ⟦¬ wait a; (ok a ∧ Pre u (alpha_rp.more a) ⟶ ok b ∧ u (alpha_rp.more a, alpha_rp.more b) ∧ ¬ wait b ∧ [] = tr b - tr a) ∧ tr a ≤ tr b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (?b37 a b, b)› discuss goal 1*) apply (split cond_splits) (*top goal: ‹⋀(a::('a, 'b) alpha_rp_scheme) b::('a, 'b) alpha_rp_scheme. ⟦¬ wait a; (ok a ∧ Pre (u::'b × 'b ⇒ bool) (alpha_rp.more a) ⟶ ok b ∧ u (alpha_rp.more a, alpha_rp.more b) ∧ ¬ wait b ∧ [] = tr b - tr a) ∧ tr a ≤ tr b⟧ ⟹ ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ Pre u (alpha_rp.more A) ⟶ ok A' ∧ u (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (a, (?b37::('a, 'b) alpha_rp_scheme ⇒ ('a, 'b) alpha_rp_scheme ⇒ ('a, 'b) alpha_rp_scheme) a b)› and 2 goals remain*) apply simp (*discuss goal 2*) apply (split cond_splits) (*top goal: ‹⋀a b. ⟦¬ wait a; (ok a ∧ Pre u (alpha_rp.more a) ⟶ ok b ∧ u (alpha_rp.more a, alpha_rp.more b) ∧ ¬ wait b ∧ [] = tr b - tr a) ∧ tr a ≤ tr b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (b, b)› and 1 goal remains*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply (split cond_splits) (*goal: ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre u (alpha_rp.more A) ⟶ ok A' ∧ u (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ba); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ Pre u (alpha_rp.more A) ⟶ ok A' ∧ u (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, c)›*) apply simp (*goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ Pre (u::'b × 'b ⇒ bool) (alpha_rp.more A) ⟶ ok A' ∧ u (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ba); ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A')) ∧ (¬ (wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ (ok A ∧ Pre u (alpha_rp.more A) ⟶ ok A' ∧ u (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'))›*) apply (split cond_splits) (*goals: 1. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c); (wait ∘ fst) (aa, ba); case (aa, ba) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (wait aa ⟶ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ (¬ wait aa ⟶ (ok aa ∧ Pre (u::'b × 'b ⇒ bool) (alpha_rp.more aa) ⟶ ok c ∧ u (alpha_rp.more aa, alpha_rp.more c) ∧ ¬ wait c ∧ [] = tr c - tr aa) ∧ tr aa ≤ tr c)› 2. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c); ¬ (wait ∘ fst) (aa, ba); case (aa, ba) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ (ok A ∧ Pre (u::'b × 'b ⇒ bool) (alpha_rp.more A) ⟶ ok A' ∧ u (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'⟧ ⟹ (wait aa ⟶ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ (¬ wait aa ⟶ (ok aa ∧ Pre u (alpha_rp.more aa) ⟶ ok c ∧ u (alpha_rp.more aa, alpha_rp.more c) ∧ ¬ wait c ∧ [] = tr c - tr aa) ∧ tr aa ≤ tr c)› discuss goal 1*) apply simp (*top goal: ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c); (wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (wait aa ⟶ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ (¬ wait aa ⟶ (ok aa ∧ Pre u (alpha_rp.more aa) ⟶ ok c ∧ u (alpha_rp.more aa, alpha_rp.more c) ∧ ¬ wait c ∧ [] = tr c - tr aa) ∧ tr aa ≤ tr c)› and 1 goal remains*) apply (split cond_splits) (*goals: 1. ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ wait ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; (wait ∘ fst) (ba, c); case (ba, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› 2. ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ wait ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; ¬ (wait ∘ fst) (ba, c); case (ba, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› discuss goal 1*) apply simp (*top goal: ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ wait ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; (wait ∘ fst) (ba, c); case (ba, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› and 2 goals remain*) apply ((auto simp: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*))[1]) (*discuss goal 2*) apply simp (*top goal: ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ wait ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; ¬ (wait ∘ fst) (ba, c); case (ba, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› and 1 goal remains*) apply ((auto simp: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*))[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*goal: ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c); ¬ (wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ (ok A ∧ Pre u (alpha_rp.more A) ⟶ ok A' ∧ u (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'⟧ ⟹ (wait aa ⟶ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ (¬ wait aa ⟶ (ok aa ∧ Pre u (alpha_rp.more aa) ⟶ ok c ∧ u (alpha_rp.more aa, alpha_rp.more c) ∧ ¬ wait c ∧ [] = tr c - tr aa) ∧ tr aa ≤ tr c)›*) apply (split cond_splits) (*goals: 1. ‹⋀aa ba c. ⟦¬ wait aa; (wait ∘ fst) (ba, c); ok aa ∧ Pre u (alpha_rp.more aa) ⟶ ok ba ∧ u (alpha_rp.more aa, alpha_rp.more ba) ∧ ¬ wait ba ∧ [] = tr ba - tr aa; tr aa ≤ tr ba; case (ba, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (ok aa ∧ Pre u (alpha_rp.more aa) ⟶ ok c ∧ u (alpha_rp.more aa, alpha_rp.more c) ∧ ¬ wait c ∧ [] = tr c - tr aa) ∧ tr aa ≤ tr c› 2. ‹⋀aa ba c. ⟦¬ wait aa; ¬ (wait ∘ fst) (ba, c); ok aa ∧ Pre u (alpha_rp.more aa) ⟶ ok ba ∧ u (alpha_rp.more aa, alpha_rp.more ba) ∧ ¬ wait ba ∧ [] = tr ba - tr aa; tr aa ≤ tr ba; case (ba, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ (ok aa ∧ Pre u (alpha_rp.more aa) ⟶ ok c ∧ u (alpha_rp.more aa, alpha_rp.more c) ∧ ¬ wait c ∧ [] = tr c - tr aa) ∧ tr aa ≤ tr c› discuss goal 1*) apply simp (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦¬ wait aa; (wait ∘ fst) (ba, c); ok aa ∧ Pre (u::'b × 'b ⇒ bool) (alpha_rp.more aa) ⟶ ok ba ∧ u (alpha_rp.more aa, alpha_rp.more ba) ∧ ¬ wait ba ∧ [] = tr ba - tr aa; tr aa ≤ tr ba; case (ba, c) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (ok aa ∧ Pre u (alpha_rp.more aa) ⟶ ok c ∧ u (alpha_rp.more aa, alpha_rp.more c) ∧ ¬ wait c ∧ [] = tr c - tr aa) ∧ tr aa ≤ tr c› and 1 goal remains*) apply ((auto simp: prefix_def (*‹?xs::?'a list ≤ ?ys::?'a list = (∃zs::?'a list. ?ys = ?xs @ zs)›*))[1]) (*discuss goal 2*) apply simp (*goal: ‹⋀aa ba c. ⟦¬ wait aa; ¬ (wait ∘ fst) (ba, c); ok aa ∧ Pre u (alpha_rp.more aa) ⟶ ok ba ∧ u (alpha_rp.more aa, alpha_rp.more ba) ∧ ¬ wait ba ∧ [] = tr ba - tr aa; tr aa ≤ tr ba; case (ba, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ (ok aa ∧ Pre u (alpha_rp.more aa) ⟶ ok c ∧ u (alpha_rp.more aa, alpha_rp.more c) ∧ ¬ wait c ∧ [] = tr c - tr aa) ∧ tr aa ≤ tr c›*) apply ((auto simp: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*))[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . subsection ‹Parallel composition› type_synonym 'σ local_state = "('σ × ('σ ⇒ 'σ ⇒ 'σ))" fun MergeSt :: "'σ local_state ⇒ 'σ local_state ⇒ ('θ,'σ) relation_rp" where "MergeSt (s1,s1') (s2,s2') = ((λ(S, S'). (s1' s1) (more S) = more S');; (λ(S::('θ,'σ) alphabet_rp, S'). (s2' s2) (more S) = more S'))" definition listCons ::"'θ ⇒ 'θ list list ⇒ 'θ list list" ("_ ## _") where "a ## l = ((map (Cons a)) l)" fun ParMergel :: "'θ::ev_eq list ⇒ 'θ list ⇒ 'θ set ⇒ 'θ list list" where "ParMergel [] [] cs = [[]]" | "ParMergel [] (b#tr2) cs = (if (filter_chan_set b cs) then [[]] else (b ## (ParMergel [] tr2 cs)))" | "ParMergel (a#tr1) [] cs = (if (filter_chan_set a cs) then [[]] else (a ## (ParMergel tr1 [] cs)))" | "ParMergel (a#tr1) (b#tr2) cs = (if (filter_chan_set a cs) then (if (ev_eq a b) then (a ## (ParMergel tr1 tr2 cs)) else (if (filter_chan_set b cs) then [[]] else (b ## (ParMergel (a#tr1) tr2 cs)))) else (if (filter_chan_set b cs) then (a ## (ParMergel tr1 (b#tr2) cs)) else (a ## (ParMergel tr1 (b#tr2) cs)) @ (b ## (ParMergel (a#tr1) tr2 cs))))" definition ParMerge::"'θ::ev_eq list ⇒ 'θ list ⇒ 'θ set ⇒ 'θ list set" where "ParMerge tr1 tr2 cs = set (ParMergel tr1 tr2 cs)" lemma set_Cons1: "tr1 ∈ set l ⟹ a # tr1 ∈ (#) a ` set l" by auto lemma tr_in_set_eq: "(tr1 ∈ (#) b ` set l) = (tr1 ≠ [] ∧ hd tr1 = b ∧ tl tr1 ∈ set l)" apply (induct l) (*goals: 1. ‹(tr1 ∈ (#) b ` set []) = (tr1 ≠ [] ∧ hd tr1 = b ∧ tl tr1 ∈ set [])› 2. ‹⋀a l. (tr1 ∈ (#) b ` set l) = (tr1 ≠ [] ∧ hd tr1 = b ∧ tl tr1 ∈ set l) ⟹ (tr1 ∈ (#) b ` set (a # l)) = (tr1 ≠ [] ∧ hd tr1 = b ∧ tl tr1 ∈ set (a # l))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . definition M_par::"(('θ::ev_eq), 'σ) alpha_rp_scheme ⇒ ('σ ⇒ 'σ ⇒ 'σ) ⇒ ('θ, 'σ) alpha_rp_scheme ⇒ ('σ ⇒ 'σ ⇒ 'σ) ⇒ ('θ set) ⇒ ('θ, 'σ) relation_rp" where "M_par s1 x1 s2 x2 cs = ((λ(S, S'). ((diff_tr S' S) ∈ ParMerge (diff_tr s1 S) (diff_tr s2 S) cs & ev_eq (tr_filter (tr s1) cs) (tr_filter (tr s2) cs))) ∧ ((λ(S, S'). (wait s1 ∨ wait s2) ∧ ref S' ⊆ ((((ref s1)∪(ref s2))∩cs)∪(((ref s1)∩(ref s2))-cs))) ◃ wait o snd ▹ ((λ(S, S'). (¬wait s1 ∨ ¬wait s2)) ∧ MergeSt ((more s1), x1) ((more s2), x2))))" definition Par::"('θ::ev_eq,'σ) action ⇒ ('σ ⇒ 'σ ⇒ 'σ) ⇒ 'θ set ⇒ ('σ ⇒ 'σ ⇒ 'σ) ⇒ ('θ,'σ) action ⇒ ('θ,'σ) action" ("_ ⟦ _ | _ | _ ⟧ _") where "A1 ⟦ ns1 | cs | ns2 ⟧ A2 ≡ (action_of (R ((λ (S, S'). ¬ (∃ tr1 tr2. ((relation_of A1)⇧f⇩f ;; (λ (S, S'). tr1 = (tr S))) (S, S') ∧ (spec False (wait S) (relation_of A2) ;; (λ (S, _). tr2 = (tr S))) (S, S') ∧ ((tr_filter tr1 cs) = (tr_filter tr2 cs))) ∧ ¬ (∃ tr1 tr2. (spec False (wait S) (relation_of A1);;(λ(S, _). tr1 = tr S)) (S, S') ∧ ((relation_of A2)⇧f⇩f ;; (λ(S, S'). tr2 = (tr S))) (S, S') ∧ ((tr_filter tr1 cs) = (tr_filter tr2 cs)))) ⊢ (λ (S, S'). (∃ s1 s2. ((λ (A, A'). (relation_of A1)⇧t⇩f (A, s1) ∧ ((relation_of A2)⇧t⇩f (A, s2)));; M_par s1 ns1 s2 ns2 cs) (S, S'))))))" lemma Par_is_action: "(R ((λ (S, S'). ¬ (∃ tr1 tr2. ((relation_of A1)⇧f⇩f ;; (λ (S, S'). tr1 = (tr S))) (S, S') ∧ (spec False (wait S) (relation_of A2) ;; (λ (S, S'). tr2 = (tr S))) (S, S') ∧ ((tr_filter tr1 cs) = (tr_filter tr2 cs))) ∧ ¬ (∃ tr1 tr2. (spec False (wait S) (relation_of A1);;(λ(S, _). tr1 = tr S)) (S, S') ∧ ((relation_of A2)⇧f⇩f ;; (λ (S, S'). tr2 = (tr S))) (S, S') ∧ ((tr_filter tr1 cs) = (tr_filter tr2 cs)))) ⊢ (λ (S, S'). (∃ s1 s2. ((λ (A, A'). (relation_of A1)⇧t⇩f (A, s1) ∧ ((relation_of A2)⇧t⇩f (A, s2)));; M_par s1 ns1 s2 ns2 cs) (S, S'))))) ∈ {p. is_CSP_process p}" apply simp (*goal: ‹R (λ(S, S'). (∄tr1 tr2. (action.relation_of A1⇧f⇩f ;; (λ(S, S'). tr1 = tr S)) (S, S') ∧ (spec False (wait S) (action.relation_of A2) ;; (λ(S, S'). tr2 = tr S)) (S, S') ∧ tr_filter tr1 cs = tr_filter tr2 cs) ∧ (∄tr1 tr2. (spec False (wait S) (action.relation_of A1) ;; (λ(S, uu_). tr1 = tr S)) (S, S') ∧ (action.relation_of A2⇧f⇩f ;; (λ(S, S'). tr2 = tr S)) (S, S') ∧ tr_filter tr1 cs = tr_filter tr2 cs) ⊢ λ(S, S'). ∃s1 s2. ((λ(A, A'). action.relation_of A1⇧t⇩f (A, s1) ∧ action.relation_of A2⇧t⇩f (A, s2)) ;; M_par s1 ns1 s2 ns2 cs) (S, S')) ∈ {p. is_CSP_process p}›*) apply (rule rd_is_CSP (*‹∀a b. ?r (a, b⦇ok := True⦈) ⟶ ?r (a, b⦇ok := False⦈) ⟹ is_CSP_process (R (?r ⊢ ?p))›*)) (*goal: ‹is_CSP_process (R (λ(S, S'). (∀tr1. (action.relation_of A1⇧f⇩f ;; (λ(S, S'). tr1 = tr S)) (S, S') ⟶ (∀tr2. (spec False (wait S) (action.relation_of A2) ;; (λ(S, S'). tr2 = tr S)) (S, S') ⟶ tr_filter tr1 cs ≠ tr_filter tr2 cs)) ∧ (∀tr1. (spec False (wait S) (action.relation_of A1) ;; (λ(S, uu_). tr1 = tr S)) (S, S') ⟶ (∀tr2. (action.relation_of A2⇧f⇩f ;; (λ(S, S'). tr2 = tr S)) (S, S') ⟶ tr_filter tr1 cs ≠ tr_filter tr2 cs)) ⊢ λ(S, S'). ∃s1 s2. ((λ(A, A'). action.relation_of A1⇧t⇩f (A, s1) ∧ action.relation_of A2⇧t⇩f (A, s2)) ;; M_par s1 ns1 s2 ns2 cs) (S, S')))›*) by blast lemmas Par_is_CSP = Par_is_action[simplified] lemma relation_of_Par: "relation_of (A1 ⟦ ns1 | cs | ns2 ⟧ A2) = (R ((λ (S, S'). ¬ (∃ tr1 tr2. ((relation_of A1)⇧f⇩f ;; (λ (S, S'). tr1 = (tr S))) (S, S') ∧ (spec False (wait S) (relation_of A2) ;; (λ (S, S'). tr2 = (tr S))) (S, S') ∧ ((tr_filter tr1 cs) = (tr_filter tr2 cs))) ∧ ¬ (∃ tr1 tr2. (spec False (wait S) (relation_of A1);;(λ(S, _). tr1 = tr S)) (S, S') ∧ ((relation_of A2)⇧f⇩f ;; (λ (S, S'). tr2 = (tr S))) (S, S') ∧ ((tr_filter tr1 cs) = (tr_filter tr2 cs)))) ⊢ (λ (S, S'). (∃ s1 s2. ((λ (A, A'). (relation_of A1)⇧t⇩f (A, s1) ∧ ((relation_of A2)⇧t⇩f (A, s2)));; M_par s1 ns1 s2 ns2 cs) (S, S')))))" apply (unfold Par_def (*‹?A1.0 ⟦ ?ns1.0 | ?cs | ?ns2.0 ⟧ ?A2.0 ≡ action_of (R (λ(S, S'). (∄tr1 tr2. (action.relation_of ?A1.0⇧f⇩f ;; (λ(S, S'). tr1 = tr S)) (S, S') ∧ (spec False (wait S) (action.relation_of ?A2.0) ;; (λ(S, uu_). tr2 = tr S)) (S, S') ∧ tr_filter tr1 ?cs = tr_filter tr2 ?cs) ∧ (∄tr1 tr2. (spec False (wait S) (action.relation_of ?A1.0) ;; (λ(S, uu_). tr1 = tr S)) (S, S') ∧ (action.relation_of ?A2.0⇧f⇩f ;; (λ(S, S'). tr2 = tr S)) (S, S') ∧ tr_filter tr1 ?cs = tr_filter tr2 ?cs) ⊢ λ(S, S'). ∃s1 s2. ((λ(A, A'). action.relation_of ?A1.0⇧t⇩f (A, s1) ∧ action.relation_of ?A2.0⇧t⇩f (A, s2)) ;; M_par s1 ?ns1.0 s2 ?ns2.0 ?cs) (S, S')))›*)) (*goal: ‹action.relation_of A1 ⟦ ns1 | cs | ns2 ⟧ A2 = R (λ(S, S'). (∄tr1 tr2. (action.relation_of A1⇧f⇩f ;; (λ(S, S'). tr1 = tr S)) (S, S') ∧ (spec False (wait S) (action.relation_of A2) ;; (λ(S, S'). tr2 = tr S)) (S, S') ∧ tr_filter tr1 cs = tr_filter tr2 cs) ∧ (∄tr1 tr2. (spec False (wait S) (action.relation_of A1) ;; (λ(S, uu_). tr1 = tr S)) (S, S') ∧ (action.relation_of A2⇧f⇩f ;; (λ(S, S'). tr2 = tr S)) (S, S') ∧ tr_filter tr1 cs = tr_filter tr2 cs) ⊢ λ(S, S'). ∃s1 s2. ((λ(A, A'). action.relation_of A1⇧t⇩f (A, s1) ∧ action.relation_of A2⇧t⇩f (A, s2)) ;; M_par s1 ns1 s2 ns2 cs) (S, S'))›*) apply (rule action_of_inverse (*‹(?y::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ∈ {p::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool. is_CSP_process p} ⟹ action.relation_of (action_of ?y) = ?y›*)) (*goal: ‹action.relation_of (action_of (R (λ(S::('a, 'b) alpha_rp_scheme, S'::('a, 'b) alpha_rp_scheme). (∄(tr1::'a list) tr2::'a list. (action.relation_of (A1::('a, 'b) action)⇧f⇩f ;; (λ(S::('a, 'b) alpha_rp_scheme, S'::('a, 'b) alpha_rp_scheme). tr1 = tr S)) (S, S') ∧ (spec False (wait S) (action.relation_of (A2::('a, 'b) action)) ;; (λ(S::('a, 'b) alpha_rp_scheme, uu_::('a, 'b) alpha_rp_scheme). tr2 = tr S)) (S, S') ∧ tr_filter tr1 (cs::'a set) = tr_filter tr2 cs) ∧ (∄(tr1::'a list) tr2::'a list. (spec False (wait S) (action.relation_of A1) ;; (λ(S::('a, 'b) alpha_rp_scheme, uu_::('a, 'b) alpha_rp_scheme). tr1 = tr S)) (S, S') ∧ (action.relation_of A2⇧f⇩f ;; (λ(S::('a, 'b) alpha_rp_scheme, S'::('a, 'b) alpha_rp_scheme). tr2 = tr S)) (S, S') ∧ tr_filter tr1 cs = tr_filter tr2 cs) ⊢ λ(S::('a, 'b) alpha_rp_scheme, S'::('a, 'b) alpha_rp_scheme). ∃(s1::('a, 'b) alpha_rp_scheme) s2::('a, 'b) alpha_rp_scheme. ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). action.relation_of A1⇧t⇩f (A, s1) ∧ action.relation_of A2⇧t⇩f (A, s2)) ;; M_par s1 (ns1::'b ⇒ 'b ⇒ 'b) s2 (ns2::'b ⇒ 'b ⇒ 'b) cs) (S, S')))) = R (λ(S::('a, 'b) alpha_rp_scheme, S'::('a, 'b) alpha_rp_scheme). (∄(tr1::'a list) tr2::'a list. (action.relation_of A1⇧f⇩f ;; (λ(S::('a, 'b) alpha_rp_scheme, S'::('a, 'b) alpha_rp_scheme). tr1 = tr S)) (S, S') ∧ (spec False (wait S) (action.relation_of A2) ;; (λ(S::('a, 'b) alpha_rp_scheme, S'::('a, 'b) alpha_rp_scheme). tr2 = tr S)) (S, S') ∧ tr_filter tr1 cs = tr_filter tr2 cs) ∧ (∄(tr1::'a list) tr2::'a list. (spec False (wait S) (action.relation_of A1) ;; (λ(S::('a, 'b) alpha_rp_scheme, uu_::('a, 'b) alpha_rp_scheme). tr1 = tr S)) (S, S') ∧ (action.relation_of A2⇧f⇩f ;; (λ(S::('a, 'b) alpha_rp_scheme, S'::('a, 'b) alpha_rp_scheme). tr2 = tr S)) (S, S') ∧ tr_filter tr1 cs = tr_filter tr2 cs) ⊢ λ(S::('a, 'b) alpha_rp_scheme, S'::('a, 'b) alpha_rp_scheme). ∃(s1::('a, 'b) alpha_rp_scheme) s2::('a, 'b) alpha_rp_scheme. ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). action.relation_of A1⇧t⇩f (A, s1) ∧ action.relation_of A2⇧t⇩f (A, s2)) ;; M_par s1 ns1 s2 ns2 cs) (S, S'))›*) by (rule Par_is_action (*‹R (λ(S, S'). (∄tr1 tr2. (action.relation_of ?A1.0⇧f⇩f ;; (λ(S, S'). tr1 = tr S)) (S, S') ∧ (spec False (wait S) (action.relation_of ?A2.0) ;; (λ(S, S'). tr2 = tr S)) (S, S') ∧ tr_filter tr1 ?cs = tr_filter tr2 ?cs) ∧ (∄tr1 tr2. (spec False (wait S) (action.relation_of ?A1.0) ;; (λ(S, uu_). tr1 = tr S)) (S, S') ∧ (action.relation_of ?A2.0⇧f⇩f ;; (λ(S, S'). tr2 = tr S)) (S, S') ∧ tr_filter tr1 ?cs = tr_filter tr2 ?cs) ⊢ λ(S, S'). ∃s1 s2. ((λ(A, A'). action.relation_of ?A1.0⇧t⇩f (A, s1) ∧ action.relation_of ?A2.0⇧t⇩f (A, s2)) ;; M_par s1 ?ns1.0 s2 ?ns2.0 ?cs) (S, S')) ∈ {p. is_CSP_process p}›*)) lemma mono_Par: "mono (λQ. P ⟦ ns1 | cs | ns2 ⟧ Q)" apply (auto simp: mono_def (*‹mono ?f = (∀x y. x ≤ y ⟶ ?f x ≤ ?f y)›*) less_eq_action (*‹?P ≤ ?Q ≡ ?P ⊑ ?Q›*) ref_def (*‹?P ⊑ ?Q ≡ ∀A. (action.relation_of ?Q ⟶ action.relation_of ?P) A›*) relation_of_Par (*‹action.relation_of ?A1.0 ⟦ ?ns1.0 | ?cs | ?ns2.0 ⟧ ?A2.0 = R (λ(S, S'). (∄tr1 tr2. (action.relation_of ?A1.0⇧f⇩f ;; (λ(S, S'). tr1 = tr S)) (S, S') ∧ (spec False (wait S) (action.relation_of ?A2.0) ;; (λ(S, S'). tr2 = tr S)) (S, S') ∧ tr_filter tr1 ?cs = tr_filter tr2 ?cs) ∧ (∄tr1 tr2. (spec False (wait S) (action.relation_of ?A1.0) ;; (λ(S, uu_). tr1 = tr S)) (S, S') ∧ (action.relation_of ?A2.0⇧f⇩f ;; (λ(S, S'). tr2 = tr S)) (S, S') ∧ tr_filter tr1 ?cs = tr_filter tr2 ?cs) ⊢ λ(S, S'). ∃s1 s2. ((λ(A, A'). action.relation_of ?A1.0⇧t⇩f (A, s1) ∧ action.relation_of ?A2.0⇧t⇩f (A, s2)) ;; M_par s1 ?ns1.0 s2 ?ns2.0 ?cs) (S, S'))›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) split: cond_splits (*‹?A ((?P ◃ ?b ▹ ?Q) ?x) = ((?b ?x ⟶ ?A (?P ?x)) ∧ (¬ ?b ?x ⟶ ?A (?Q ?x)))› ‹?A ((?P ◃ ?b ▹ ?Q) ?x) = (¬ (?b ?x ∧ ¬ ?A (?P ?x) ∨ ¬ ?b ?x ∧ ¬ ?A (?Q ?x)))›*)) (*goals: 1. ‹⋀x y a b ba bb. ⟦∀a b. (action.relation_of y ⟶ action.relation_of x) (a, b); ¬ wait a; tr a ≤ tr b; ok a; ∀tr1. ((λ(A, A'). action.relation_of P (A⦇wait := False⦈, A'⦇ok := False⦈)) ;; (λ(S, S'). tr1 = tr S)) (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ (∀tr2. ((λ(A, A'). action.relation_of x (A⦇wait := False⦈, A'⦇ok := False⦈)) ;; (λ(S, S'). tr2 = tr S)) (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ tr_filter tr1 cs ≠ tr_filter tr2 cs); action.relation_of P (a⦇tr := [], wait := False⦈, ba⦇ok := False⦈); action.relation_of y (a⦇tr := [], wait := False⦈, bb⦇ok := False⦈); tr_filter (tr ba) cs = tr_filter (tr bb) cs⟧ ⟹ ok b› 2. ‹⋀x y a b ba bb. ⟦∀a b. (action.relation_of y ⟶ action.relation_of x) (a, b); ¬ wait a; tr a ≤ tr b; ok a; ∀tr1. ((λ(A, A'). action.relation_of P (A⦇wait := False⦈, A'⦇ok := False⦈)) ;; (λ(S, S'). tr1 = tr S)) (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ (∀tr2. ((λ(A, A'). action.relation_of x (A⦇wait := False⦈, A'⦇ok := False⦈)) ;; (λ(S, S'). tr2 = tr S)) (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ tr_filter tr1 cs ≠ tr_filter tr2 cs); action.relation_of P (a⦇tr := [], wait := False⦈, ba⦇ok := False⦈); action.relation_of y (a⦇tr := [], wait := False⦈, bb⦇ok := False⦈); tr_filter (tr ba) cs = tr_filter (tr bb) cs⟧ ⟹ ∃s1 s2. ((λ(A, A'). action.relation_of P (A⦇wait := False⦈, s1⦇ok := True⦈) ∧ action.relation_of x (A⦇wait := False⦈, s2⦇ok := True⦈)) ;; M_par s1 ns1 s2 ns2 cs) (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈)› 3. ‹⋀x y a b s1 s2 ba. ⟦∀a b. (action.relation_of y ⟶ action.relation_of x) (a, b); ¬ wait a; tr a ≤ tr b; ok a; ∀tr1. ((λ(A, A'). action.relation_of P (A⦇wait := False⦈, A'⦇ok := False⦈)) ;; (λ(S, S'). tr1 = tr S)) (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ (∀tr2. ((λ(A, A'). action.relation_of x (A⦇wait := False⦈, A'⦇ok := False⦈)) ;; (λ(S, S'). tr2 = tr S)) (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ tr_filter tr1 cs ≠ tr_filter tr2 cs); ok b; M_par s1 ns1 s2 ns2 cs (ba, b⦇tr := tr b - tr a⦈); action.relation_of P (a⦇tr := [], wait := False⦈, s1⦇ok := True⦈); action.relation_of y (a⦇tr := [], wait := False⦈, s2⦇ok := True⦈)⟧ ⟹ ∃s1 s2. ((λ(A, A'). action.relation_of P (A⦇wait := False⦈, s1⦇ok := True⦈) ∧ action.relation_of x (A⦇wait := False⦈, s2⦇ok := True⦈)) ;; M_par s1 ns1 s2 ns2 cs) (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈)› discuss goal 1*) apply ((auto simp: rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) dest: relation_of_spec_f_f[simplified] (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧f⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧f⇩f (?a⦇tr := []⦈, ?b)›*) relation_of_spec_t_f[simplified] (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧t⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧t⇩f (?a⦇tr := []⦈, ?b)›*))[1]) (*discuss goal 2*) apply (erule_tac x="tr ba" in allE (*‹⟦∀x::?'a. (?P::?'a ⇒ bool) x; ?P (?x::?'a) ⟹ ?R::bool⟧ ⟹ ?R›*)) (*top goal: ‹⋀x y a b ba bb. ⟦∀a b. (action.relation_of y ⟶ action.relation_of x) (a, b); ¬ wait a; tr a ≤ tr b; ok a; ∀tr1. ((λ(A, A'). action.relation_of P (A⦇wait := False⦈, A'⦇ok := False⦈)) ;; (λ(S, S'). tr1 = tr S)) (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ (∀tr2. ((λ(A, A'). action.relation_of x (A⦇wait := False⦈, A'⦇ok := False⦈)) ;; (λ(S, S'). tr2 = tr S)) (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ tr_filter tr1 cs ≠ tr_filter tr2 cs); action.relation_of P (a⦇tr := [], wait := False⦈, ba⦇ok := False⦈); action.relation_of y (a⦇tr := [], wait := False⦈, bb⦇ok := False⦈); tr_filter (tr ba) cs = tr_filter (tr bb) cs⟧ ⟹ ∃s1 s2. ((λ(A, A'). action.relation_of P (A⦇wait := False⦈, s1⦇ok := True⦈) ∧ action.relation_of x (A⦇wait := False⦈, s2⦇ok := True⦈)) ;; M_par s1 ns1 s2 ns2 cs) (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈)› and 1 goal remains*) apply auto (*top goal: ‹⋀x y a b ba bb. ⟦∀a b. (action.relation_of y ⟶ action.relation_of x) (a, b); ¬ wait a; tr a ≤ tr b; ok a; action.relation_of P (a⦇tr := [], wait := False⦈, ba⦇ok := False⦈); action.relation_of y (a⦇tr := [], wait := False⦈, bb⦇ok := False⦈); tr_filter (tr ba) cs = tr_filter (tr bb) cs; ((λ(A, A'). action.relation_of P (A⦇wait := False⦈, A'⦇ok := False⦈)) ;; (λ(S, S'). tr ba = tr S)) (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ (∀tr2. ((λ(A, A'). action.relation_of x (A⦇wait := False⦈, A'⦇ok := False⦈)) ;; (λ(S, S'). tr2 = tr S)) (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ tr_filter (tr ba) cs ≠ tr_filter tr2 cs)⟧ ⟹ ∃s1 s2. ((λ(A, A'). action.relation_of P (A⦇wait := False⦈, s1⦇ok := True⦈) ∧ action.relation_of x (A⦇wait := False⦈, s2⦇ok := True⦈)) ;; M_par s1 ns1 s2 ns2 cs) (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈)› and 1 goal remains*) apply (erule notE (*‹⟦¬ (?P::bool); ?P⟧ ⟹ ?R::bool›*)) (*top goal: ‹⋀x y a b ba bb. ⟦∀a b. (action.relation_of y ⟶ action.relation_of x) (a, b); ¬ wait a; tr a ≤ tr b; ok a; action.relation_of P (a⦇tr := [], wait := False⦈, ba⦇ok := False⦈); action.relation_of y (a⦇tr := [], wait := False⦈, bb⦇ok := False⦈); tr_filter (tr ba) cs = tr_filter (tr bb) cs; ∀tr2. ((λ(A, A'). action.relation_of x (A⦇wait := False⦈, A'⦇ok := False⦈)) ;; (λ(S, S'). tr2 = tr S)) (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ tr_filter (tr bb) cs ≠ tr_filter tr2 cs⟧ ⟹ ∃s1 s2. ((λ(A, A'). action.relation_of P (A⦇wait := False⦈, s1⦇ok := True⦈) ∧ action.relation_of x (A⦇wait := False⦈, s2⦇ok := True⦈)) ;; M_par s1 ns1 s2 ns2 cs) (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈)› and 1 goal remains*) apply (auto dest: relation_of_spec_f_f (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧f⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧f⇩f (?a⦇tr := []⦈, ?b)›*) relation_of_spec_t_f (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧t⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧t⇩f (?a⦇tr := []⦈, ?b)›*)) (*discuss goal 3*) apply ((auto simp: rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) dest: relation_of_spec_f_f[simplified] (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧f⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧f⇩f (?a⦇tr := []⦈, ?b)›*) relation_of_spec_t_f[simplified] (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧t⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧t⇩f (?a⦇tr := []⦈, ?b)›*))[1]) (*proven 3 subgoals*) . subsection ‹Local parallel block› definition ParLoc::"'σ ⇒ ('σ ⇒ 'σ ⇒ 'σ) ⇒ ('θ::ev_eq, 'σ) action ⇒ 'θ set ⇒ 'σ ⇒ ('σ ⇒ 'σ ⇒ 'σ) ⇒ ('θ,'σ) action ⇒ ('θ,'σ) action" ("'(()par _ | _ ∙ _ ') ⟦ _ ⟧ '(()par _ | _ ∙ _ ')") where "(par s1 | ns1 ∙ P) ⟦ cs ⟧ (par s2 | ns2 ∙ Q) ≡ ((rd_assign s1)`;`P) ⟦ ns1 | cs | ns2 ⟧ ((rd_assign s2)`;` Q)" subsection ‹Assignment› definition ASSIGN::"('v, 'σ) var_list ⇒ ('σ ⇒ 'v) ⇒ ('θ::ev_eq, 'σ) action" where "ASSIGN x e ≡ action_of (R (true ⊢ (λ (S, S'). tr S' = tr S ∧ ¬wait S' ∧ (more S' = (update x (λ_. (e (more S)))) (more S)))))" syntax "_assign"::"id ⇒ ('σ ⇒ 'v) ⇒ ('θ, 'σ) action" ("_ `:=` _") translations "y `:=` vv" => "CONST ASSIGN (VAR y) vv" lemma Assign_is_action: "(R (true ⊢ (λ (S, S'). tr S' = tr S ∧ ¬wait S' ∧ (more S' = (update x (λ_. (e (more S)))) (more S))))) ∈ {p. is_CSP_process p}" apply simp (*goal: ‹R (true ⊢ λ(S, S'). tr S' = tr S ∧ ¬ wait S' ∧ alpha_rp.more S' = update x (λ_. e (alpha_rp.more S)) (alpha_rp.more S)) ∈ {p. is_CSP_process p}›*) apply (rule rd_is_CSP (*‹∀a b. ?r (a, b⦇ok := True⦈) ⟶ ?r (a, b⦇ok := False⦈) ⟹ is_CSP_process (R (?r ⊢ ?p))›*)) (*goal: ‹is_CSP_process (R (true ⊢ λ(S, S'). tr S' = tr S ∧ ¬ wait S' ∧ alpha_rp.more S' = update x (λ_. e (alpha_rp.more S)) (alpha_rp.more S)))›*) by blast lemmas Assign_is_CSP = Assign_is_action[simplified] lemma relation_of_Assign: "relation_of (ASSIGN x e) = (R (true ⊢ (λ (S, S'). tr S' = tr S ∧ ¬wait S' ∧ (more S' = (update x (λ_. (e (more S)))) (more S)))))" by (simp add: ASSIGN_def (*‹ASSIGN ?x ?e ≡ action_of (R (true ⊢ λ(S, S'). tr S' = tr S ∧ ¬ wait S' ∧ alpha_rp.more S' = update ?x (λ_. ?e (alpha_rp.more S)) (alpha_rp.more S)))›*) action_of_inverse (*‹?y ∈ {p. is_CSP_process p} ⟹ action.relation_of (action_of ?y) = ?y›*) Assign_is_CSP (*‹is_CSP_process (R (true ⊢ λ(S, S'). tr S' = tr S ∧ ¬ wait S' ∧ alpha_rp.more S' = update ?x (λ_. ?e (alpha_rp.more S)) (alpha_rp.more S)))›*)) lemma Assign_is_state_update_before: "ASSIGN x e = state_update_before (λ (s, s') . s' = (update x (λ_. (e s))) s) Skip" apply (subst relation_of_inject[symmetric] (*‹(?x = ?y) = (action.relation_of ?x = action.relation_of ?y)›*)) (*goal: ‹ASSIGN x e = state_update_before (λ(s, s'). s' = update x (λ_. e s) s) Skip›*) apply (auto simp: relation_of_Assign (*‹action.relation_of (ASSIGN ?x ?e) = R (true ⊢ λ(S, S'). tr S' = tr S ∧ ¬ wait S' ∧ alpha_rp.more S' = update ?x (λ_. ?e (alpha_rp.more S)) (alpha_rp.more S))›*) relation_of_state_update_before (*‹action.relation_of (state_update_before ?sc ?Ac) = (R (λ(A, A'). Pre ?sc (alpha_rp.more A) ⊢ λ(A, A'). ?sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ tr A = tr A') ;; action.relation_of ?Ac)›*) relation_of_Skip (*‹action.relation_of Skip = R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A')›*) rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) Pre_def (*‹Pre ?sc ≡ λA. ∃A'. ?sc (A, A')›*) update_def (*‹update ?f ?upd ≡ snd ?f (λl. ?upd (hd l) # tl l)›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*)) (*goals: 1. ‹⋀a b. ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = snd x (λl. e (alpha_rp.more A) # tl l) (alpha_rp.more A)) ∧ tr A ≤ tr A')) (a, b) ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ alpha_rp.more A' = snd x (λl. e (alpha_rp.more A) # tl l) (alpha_rp.more A) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› 2. ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ alpha_rp.more A' = snd x (λl. e (alpha_rp.more A) # tl l) (alpha_rp.more A) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ba); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = snd x (λl. e (alpha_rp.more A) # tl l) (alpha_rp.more A)) ∧ tr A ≤ tr A')) (aa, c)› discuss goal 1*) apply (split cond_splits) (*goals: 1. ‹⋀a b. ⟦(wait ∘ fst) (a, b); case (a, b) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ alpha_rp.more A' = snd x (λl. e (alpha_rp.more A) # tl l) (alpha_rp.more A) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› 2. ‹⋀a b. ⟦¬ (wait ∘ fst) (a, b); case (a, b) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = snd x (λl. e (alpha_rp.more A) # tl l) (alpha_rp.more A)) ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ alpha_rp.more A' = snd x (λl. e (alpha_rp.more A) # tl l) (alpha_rp.more A) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› discuss goal 1*) apply simp (*top goal: ‹⋀(a::('a, 'b) alpha_rp_scheme) b::('a, 'b) alpha_rp_scheme. ⟦(wait ∘ fst) (a, b); case (a, b) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ⟶ ok A' ∧ alpha_rp.more A' = snd (x::('b ⇒ 'c list) × (('c list ⇒ 'c list) ⇒ 'b ⇒ 'b)) (λl::'c list. (e::'b ⇒ 'c) (alpha_rp.more A) # tl l) (alpha_rp.more A) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› and 2 goals remain*) apply (rule_tac b=b in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀a b. ⟦wait a; ¬ ok a ∧ tr a ≤ tr b ∨ ok b ∧ tr a = tr b ∧ wait b ∧ ref a = ref b ∧ alpha_rp.more a = alpha_rp.more b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ alpha_rp.more A' = snd x (λl. e (alpha_rp.more A) # tl l) (alpha_rp.more A) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (a, b)› 2. ‹⋀a b. ⟦wait a; ¬ ok a ∧ tr a ≤ tr b ∨ ok b ∧ tr a = tr b ∧ wait b ∧ ref a = ref b ∧ alpha_rp.more a = alpha_rp.more b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (b, b)› discuss goal 1*) apply (split cond_splits) (*top goal: ‹⋀a b. ⟦wait a; ¬ ok a ∧ tr a ≤ tr b ∨ ok b ∧ tr a = tr b ∧ wait b ∧ ref a = ref b ∧ alpha_rp.more a = alpha_rp.more b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ alpha_rp.more A' = snd x (λl. e (alpha_rp.more A) # tl l) (alpha_rp.more A) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (a, b)› and 3 goals remain*) apply simp (*discuss goal 2*) apply (split cond_splits) (*top goal: ‹⋀a b. ⟦wait a; ¬ ok a ∧ tr a ≤ tr b ∨ ok b ∧ tr a = tr b ∧ wait b ∧ ref a = ref b ∧ alpha_rp.more a = alpha_rp.more b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (b, b)› and 2 goals remain*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*top goal: ‹⋀(a::('a, 'b) alpha_rp_scheme) b::('a, 'b) alpha_rp_scheme. ⟦¬ (wait ∘ fst) (a, b); case (a, b) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = snd (x::('b ⇒ 'c list) × (('c list ⇒ 'c list) ⇒ 'b ⇒ 'b)) (λl::'c list. (e::'b ⇒ 'c) (alpha_rp.more A) # tl l) (alpha_rp.more A)) ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ⟶ ok A' ∧ alpha_rp.more A' = snd x (λl::'c list. e (alpha_rp.more A) # tl l) (alpha_rp.more A) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'))) (a, b)› and 1 goal remains*) apply (rule_tac b=b in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀a b. ⟦¬ wait a; (ok a ∧ true (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ ok b ∧ tr b - tr a = [] ∧ ¬ wait b ∧ alpha_rp.more b = snd x (λl. e (alpha_rp.more a) # tl l) (alpha_rp.more a)) ∧ tr a ≤ tr b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ alpha_rp.more A' = snd x (λl. e (alpha_rp.more A) # tl l) (alpha_rp.more A) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (a, b)› 2. ‹⋀a b. ⟦¬ wait a; (ok a ∧ true (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ ok b ∧ tr b - tr a = [] ∧ ¬ wait b ∧ alpha_rp.more b = snd x (λl. e (alpha_rp.more a) # tl l) (alpha_rp.more a)) ∧ tr a ≤ tr b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (b, b)› discuss goal 1*) apply (split cond_splits) (*top goal: ‹⋀a b. ⟦¬ wait a; (ok a ∧ true (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ ok b ∧ tr b - tr a = [] ∧ ¬ wait b ∧ alpha_rp.more b = snd x (λl. e (alpha_rp.more a) # tl l) (alpha_rp.more a)) ∧ tr a ≤ tr b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ alpha_rp.more A' = snd x (λl. e (alpha_rp.more A) # tl l) (alpha_rp.more A) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (a, b)› and 2 goals remain*) apply simp (*top goal: ‹⋀(a::('a, 'b) alpha_rp_scheme) b::('a, 'b) alpha_rp_scheme. ⟦¬ wait a; (ok a ∧ true (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ ok b ∧ tr b - tr a = [] ∧ ¬ wait b ∧ alpha_rp.more b = snd (x::('b ⇒ 'c list) × (('c list ⇒ 'c list) ⇒ 'b ⇒ 'b)) (λl::'c list. (e::'b ⇒ 'c) (alpha_rp.more a) # tl l) (alpha_rp.more a)) ∧ tr a ≤ tr b⟧ ⟹ ((wait ∘ fst) (a, b) ⟶ (case (a, b) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A')) ∧ (¬ (wait ∘ fst) (a, b) ⟶ (case (a, b) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ (ok A ⟶ ok A' ∧ alpha_rp.more A' = snd x (λl::'c list. e (alpha_rp.more A) # tl l) (alpha_rp.more A) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'))› and 2 goals remain*) apply ((auto simp add: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*))[1]) (*discuss goal 2*) apply (split cond_splits) (*top goal: ‹⋀(a::('a, 'b) alpha_rp_scheme) b::('a, 'b) alpha_rp_scheme. ⟦¬ wait a; (ok a ∧ true (a⦇tr := []⦈, b⦇tr := tr b - tr a⦈) ⟶ ok b ∧ tr b - tr a = [] ∧ ¬ wait b ∧ alpha_rp.more b = snd (x::('b::type ⇒ 'c::type list) × (('c::type list ⇒ 'c::type list) ⇒ 'b::type ⇒ 'b::type)) (λl::'c::type list. (e::'b::type ⇒ 'c::type) (alpha_rp.more a) # tl l) (alpha_rp.more a)) ∧ tr a ≤ tr b⟧ ⟹ ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (b, b)› and 1 goal remains*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply (split cond_splits) (*goal: ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ alpha_rp.more A' = snd x (λl. e (alpha_rp.more A) # tl l) (alpha_rp.more A) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ba); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = snd x (λl. e (alpha_rp.more A) # tl l) (alpha_rp.more A)) ∧ tr A ≤ tr A')) (aa, c)›*) apply simp (*goal: ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ alpha_rp.more A' = snd x (λl. e (alpha_rp.more A) # tl l) (alpha_rp.more A) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ba); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c)⟧ ⟹ ((wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A')) ∧ (¬ (wait ∘ fst) (aa, c) ⟶ (case (aa, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = snd x (λl. e (alpha_rp.more A) # tl l) (alpha_rp.more A)) ∧ tr A ≤ tr A'))›*) apply (split cond_splits) (*goals: 1. ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c); (wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (wait aa ⟶ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ (¬ wait aa ⟶ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more c = snd x (λl. e (alpha_rp.more aa) # tl l) (alpha_rp.more aa)) ∧ tr aa ≤ tr c)› 2. ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c); ¬ (wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ (ok A ⟶ ok A' ∧ alpha_rp.more A' = snd x (λl. e (alpha_rp.more A) # tl l) (alpha_rp.more A) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'⟧ ⟹ (wait aa ⟶ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ (¬ wait aa ⟶ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more c = snd x (λl. e (alpha_rp.more aa) # tl l) (alpha_rp.more aa)) ∧ tr aa ≤ tr c)› discuss goal 1*) apply simp (*top goal: ‹⋀aa ba c. ⟦((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c); (wait ∘ fst) (aa, ba); case (aa, ba) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (wait aa ⟶ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ (¬ wait aa ⟶ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more c = snd x (λl. e (alpha_rp.more aa) # tl l) (alpha_rp.more aa)) ∧ tr aa ≤ tr c)› and 1 goal remains*) apply (split cond_splits) (*goals: 1. ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ wait ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; (wait ∘ fst) (ba, c); case (ba, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› 2. ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ wait ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; ¬ (wait ∘ fst) (ba, c); case (ba, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› discuss goal 1*) apply simp (*top goal: ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ wait ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; (wait ∘ fst) (ba, c); case (ba, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› and 2 goals remain*) apply ((auto simp add: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*))[1]) (*discuss goal 2*) apply simp (*top goal: ‹⋀aa ba c. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ba ∨ ok ba ∧ tr aa = tr ba ∧ wait ba ∧ ref aa = ref ba ∧ alpha_rp.more aa = alpha_rp.more ba; ¬ (wait ∘ fst) (ba, c); case (ba, c) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c› and 1 goal remains*) apply ((auto simp add: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*))[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A')) (ba, c); ¬ (wait ∘ fst) (aa, ba); case (aa, ba) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ (ok A ⟶ ok A' ∧ alpha_rp.more A' = snd (x::('b ⇒ 'c list) × (('c list ⇒ 'c list) ⇒ 'b ⇒ 'b)) (λl::'c list. (e::'b ⇒ 'c) (alpha_rp.more A) # tl l) (alpha_rp.more A) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'⟧ ⟹ (wait aa ⟶ ¬ ok aa ∧ tr aa ≤ tr c ∨ ok c ∧ tr aa = tr c ∧ wait c ∧ ref aa = ref c ∧ alpha_rp.more aa = alpha_rp.more c) ∧ (¬ wait aa ⟶ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more c = snd x (λl::'c list. e (alpha_rp.more aa) # tl l) (alpha_rp.more aa)) ∧ tr aa ≤ tr c)›*) apply (split cond_splits) (*goals: 1. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦¬ wait aa; (wait ∘ fst) (ba, c); ok aa ⟶ ok ba ∧ alpha_rp.more ba = snd (x::('b ⇒ 'c list) × (('c list ⇒ 'c list) ⇒ 'b ⇒ 'b)) (λl::'c list. (e::'b ⇒ 'c) (alpha_rp.more aa) # tl l) (alpha_rp.more aa) ∧ ¬ wait ba ∧ [] = tr ba - tr aa; tr aa ≤ tr ba; case (ba, c) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more c = snd x (λl::'c list. e (alpha_rp.more aa) # tl l) (alpha_rp.more aa)) ∧ tr aa ≤ tr c› 2. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦¬ wait aa; ¬ (wait ∘ fst) (ba, c); ok aa ⟶ ok ba ∧ alpha_rp.more ba = snd (x::('b ⇒ 'c list) × (('c list ⇒ 'c list) ⇒ 'b ⇒ 'b)) (λl::'c list. (e::'b ⇒ 'c) (alpha_rp.more aa) # tl l) (alpha_rp.more aa) ∧ ¬ wait ba ∧ [] = tr ba - tr aa; tr aa ≤ tr ba; case (ba, c) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more c = snd x (λl::'c list. e (alpha_rp.more aa) # tl l) (alpha_rp.more aa)) ∧ tr aa ≤ tr c› discuss goal 1*) apply simp (*top goal: ‹⋀aa ba c. ⟦¬ wait aa; (wait ∘ fst) (ba, c); ok aa ⟶ ok ba ∧ alpha_rp.more ba = snd x (λl. e (alpha_rp.more aa) # tl l) (alpha_rp.more aa) ∧ ¬ wait ba ∧ [] = tr ba - tr aa; tr aa ≤ tr ba; case (ba, c) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more c = snd x (λl. e (alpha_rp.more aa) # tl l) (alpha_rp.more aa)) ∧ tr aa ≤ tr c› and 1 goal remains*) apply ((auto simp add: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*))[1]) (*discuss goal 2*) apply simp (*goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ba::('a, 'b) alpha_rp_scheme) c::('a, 'b) alpha_rp_scheme. ⟦¬ wait aa; ¬ (wait ∘ fst) (ba, c); ok aa ⟶ ok ba ∧ alpha_rp.more ba = snd (x::('b ⇒ 'c list) × (('c list ⇒ 'c list) ⇒ 'b ⇒ 'b)) (λl::'c list. (e::'b ⇒ 'c) (alpha_rp.more aa) # tl l) (alpha_rp.more aa) ∧ ¬ wait ba ∧ [] = tr ba - tr aa; tr aa ≤ tr ba; case (ba, c) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A') ∧ tr A ≤ tr A'⟧ ⟹ (ok aa ∧ true (aa⦇tr := []⦈, c⦇tr := tr c - tr aa⦈) ⟶ ok c ∧ tr c - tr aa = [] ∧ ¬ wait c ∧ alpha_rp.more c = snd x (λl::'c list. e (alpha_rp.more aa) # tl l) (alpha_rp.more aa)) ∧ tr aa ≤ tr c›*) apply ((auto simp add: prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*))[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . subsection ‹Variable scope› definition Var::"('v, 'σ) var_list ⇒('θ, 'σ) action ⇒ ('θ::ev_eq,'σ) action" where "Var v A ≡ action_of( (R(true ⊢ (λ (A, A'). ∃ a. tr A' = tr A ∧ ¬wait A' ∧ more A' = (increase v a (more A)))));; (relation_of A;; (R(true ⊢ (λ (A, A'). tr A' = tr A ∧ ¬wait A' ∧ more A' = (decrease v (more A)))))))" syntax "_var"::"idt ⇒ ('θ, 'σ) action ⇒ ('θ, 'σ) action" ("var _ ∙ _" [1000] 999) translations "var y ∙ Act" => "CONST Var (VAR_LIST y) Act" lemma Var_is_action: "((R(true ⊢ (λ (A, A'). ∃ a. tr A' = tr A ∧ ¬wait A' ∧ more A' = (increase v a (more A)))));; (relation_of A;; (R(true ⊢ (λ (A, A'). tr A' = tr A ∧ ¬wait A' ∧ more A' = (decrease v (more A))))))) ∈ {p. is_CSP_process p}" apply simp (*goal: ‹(R (true ⊢ λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ∃a::'c. tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = increase (v::('b ⇒ 'c list) × (('c list ⇒ 'c list) ⇒ 'b ⇒ 'b)) a (alpha_rp.more A)) ;; action.relation_of (A::('a, 'b) action) ;; R (true ⊢ λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A))) ∈ {p::('a, 'b) alpha_rp_scheme × ('a, 'b) alpha_rp_scheme ⇒ bool. is_CSP_process p}›*) apply (rule seq_CSP (*‹⟦?P::(?'a, ?'b) alpha_rp_scheme × (?'a, ?'b) alpha_rp_scheme ⇒ bool is CSP1 healthy; ?P is R healthy; is_CSP_process (?Q::(?'a, ?'b) alpha_rp_scheme × (?'a, ?'b) alpha_rp_scheme ⇒ bool)⟧ ⟹ is_CSP_process (?P ;; ?Q)›*)) (*goals: 1. ‹R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) is CSP1 healthy› 2. ‹R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) is R healthy› 3. ‹is_CSP_process (action.relation_of A ;; R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)))› discuss goal 1*) apply ((auto simp: csp_defs (*‹CSP1 ?P ≡ ?P ∨ (λ(A, A'). ¬ ok A ∧ tr A ≤ tr A')› ‹J_csp ≡ λ(A, A'). (ok A ⟶ ok A') ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹CSP2 ?P ≡ ?P ;; J_csp› ‹is_CSP_process ?P ≡ ?P is CSP1 healthy ∧ ?P is CSP2 healthy ∧ ?P is R healthy›*) rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*) increase_def (*‹increase ?f ?val ≡ snd ?f ((#) ?val)›*) decrease_def (*‹decrease ?f ≡ snd ?f tl›*) split: cond_splits (*‹?A ((?P ◃ ?b ▹ ?Q) ?x) = ((?b ?x ⟶ ?A (?P ?x)) ∧ (¬ ?b ?x ⟶ ?A (?Q ?x)))› ‹?A ((?P ◃ ?b ▹ ?Q) ?x) = (¬ (?b ?x ∧ ¬ ?A (?P ?x) ∨ ¬ ?b ?x ∧ ¬ ?A (?Q ?x)))›*))[1]) (*discuss goal 2*) apply ((auto simp: csp_defs (*‹CSP1 (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ ?P ∨ (λ(A::(?'θ, ?'σ) alpha_rp_scheme, A'::(?'θ, ?'σ) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A')› ‹J_csp ≡ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). (ok A ⟶ ok A') ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹CSP2 (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ ?P ;; J_csp› ‹is_CSP_process (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ ?P is CSP1 healthy ∧ ?P is CSP2 healthy ∧ ?P is R healthy›*) rp_defs (*‹R1 (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ λ(A::(?'θ, ?'σ) alpha_rp_scheme, A'::(?'θ, ?'σ) alpha_rp_scheme). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ λ(A::(?'θ, ?'σ) alpha_rp_scheme, A'::(?'θ, ?'σ) alpha_rp_scheme). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec (?b::bool) (?b'::bool) (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ λ(A::(?'θ, ?'σ) alpha_rp_scheme, A'::(?'θ, ?'σ) alpha_rp_scheme). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) design_defs (*‹(?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool ⊢ ?Q::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). A = A')› ‹J ≡ λ(A::?'a alpha_d_scheme, A'::?'a alpha_d_scheme). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P::?'α × ?'α ⇒ bool is ?H::(?'α × ?'α ⇒ bool) ⇒ ?'α × ?'α ⇒ bool healthy ≡ ?P = ?H ?P› ‹H1 (?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ ok ∘ fst ⟶ ?P› ‹H2 (?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ ?P ;; J› ‹H3 (?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ ?P ;; Πd› ‹H4 (?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ (?P ;; true) ⟷ true› ‹σf (?D::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ?D (A, A'⦇ok := False⦈)› ‹σt (?D::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ok A› ‹OKAY' ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ok A'›*) fun_eq_iff (*‹((?f::?'a ⇒ ?'b) = (?g::?'a ⇒ ?'b)) = (∀x::?'a. ?f x = ?g x)›*) prefix_def (*‹?xs::?'a list ≤ ?ys::?'a list = (∃zs::?'a list. ?ys = ?xs @ zs)›*) increase_def (*‹increase (?f::(?'r ⇒ ?'a list) × ((?'a list ⇒ ?'a list) ⇒ ?'r ⇒ ?'r)) (?val::?'a) ≡ snd ?f ((#) ?val)›*) decrease_def (*‹decrease (?f::(?'r ⇒ ?'a list) × ((?'a list ⇒ ?'a list) ⇒ ?'r ⇒ ?'r)) ≡ snd ?f tl›*) split: cond_splits (*‹(?A::bool ⇒ bool) (((?P::?'a × ?'a ⇒ bool) ◃ ?b::?'a × ?'a ⇒ bool ▹ (?Q::?'a × ?'a ⇒ bool)) (?x::?'a × ?'a)) = ((?b ?x ⟶ ?A (?P ?x)) ∧ (¬ ?b ?x ⟶ ?A (?Q ?x)))› ‹(?A::bool ⇒ bool) (((?P::?'a × ?'a ⇒ bool) ◃ ?b::?'a × ?'a ⇒ bool ▹ (?Q::?'a × ?'a ⇒ bool)) (?x::?'a × ?'a)) = (¬ (?b ?x ∧ ¬ ?A (?P ?x) ∨ ¬ ?b ?x ∧ ¬ ?A (?Q ?x)))›*))[1]) (*discuss goal 3*) apply (rule seq_CSP (*‹⟦?P is CSP1 healthy; ?P is R healthy; is_CSP_process ?Q⟧ ⟹ is_CSP_process (?P ;; ?Q)›*)) (*goals: 1. ‹action.relation_of (A::('a, 'b) action) is CSP1 healthy› 2. ‹action.relation_of (A::('a, 'b) action) is R healthy› 3. ‹is_CSP_process (R (true ⊢ λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease (v::('b ⇒ 'c list) × (('c list ⇒ 'c list) ⇒ 'b ⇒ 'b)) (alpha_rp.more A)))› discuss goal 1*) apply ((auto simp: relation_of_CSP1 (*‹action.relation_of ?x is CSP1 healthy›*) relation_of_R (*‹action.relation_of ?x is R healthy›*))[1]) (*discuss goal 2*) apply ((auto simp: relation_of_CSP1 (*‹action.relation_of ?x is CSP1 healthy›*) relation_of_R (*‹action.relation_of ?x is R healthy›*))[1]) (*discuss goal 3*) apply (rule rd_is_CSP (*‹∀a b. ?r (a, b⦇ok := True⦈) ⟶ ?r (a, b⦇ok := False⦈) ⟹ is_CSP_process (R (?r ⊢ ?p))›*)) (*goal: ‹is_CSP_process (R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)))›*) apply ((auto simp: csp_defs (*‹CSP1 (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ ?P ∨ (λ(A::(?'θ, ?'σ) alpha_rp_scheme, A'::(?'θ, ?'σ) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A')› ‹J_csp ≡ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). (ok A ⟶ ok A') ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹CSP2 (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ ?P ;; J_csp› ‹is_CSP_process (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ ?P is CSP1 healthy ∧ ?P is CSP2 healthy ∧ ?P is R healthy›*) rp_defs (*‹R1 (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ λ(A::(?'θ, ?'σ) alpha_rp_scheme, A'::(?'θ, ?'σ) alpha_rp_scheme). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ λ(A::(?'θ, ?'σ) alpha_rp_scheme, A'::(?'θ, ?'σ) alpha_rp_scheme). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec (?b::bool) (?b'::bool) (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ λ(A::(?'θ, ?'σ) alpha_rp_scheme, A'::(?'θ, ?'σ) alpha_rp_scheme). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) design_defs (*‹(?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool ⊢ ?Q::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). A = A')› ‹J ≡ λ(A::?'a alpha_d_scheme, A'::?'a alpha_d_scheme). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P::?'α × ?'α ⇒ bool is ?H::(?'α × ?'α ⇒ bool) ⇒ ?'α × ?'α ⇒ bool healthy ≡ ?P = ?H ?P› ‹H1 (?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ ok ∘ fst ⟶ ?P› ‹H2 (?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ ?P ;; J› ‹H3 (?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ ?P ;; Πd› ‹H4 (?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ (?P ;; true) ⟷ true› ‹σf (?D::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ?D (A, A'⦇ok := False⦈)› ‹σt (?D::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ok A› ‹OKAY' ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ok A'›*) fun_eq_iff (*‹((?f::?'a ⇒ ?'b) = (?g::?'a ⇒ ?'b)) = (∀x::?'a. ?f x = ?g x)›*) prefix_def (*‹?xs::?'a list ≤ ?ys::?'a list = (∃zs::?'a list. ?ys = ?xs @ zs)›*) increase_def (*‹increase (?f::(?'r ⇒ ?'a list) × ((?'a list ⇒ ?'a list) ⇒ ?'r ⇒ ?'r)) (?val::?'a) ≡ snd ?f ((#) ?val)›*) decrease_def (*‹decrease (?f::(?'r ⇒ ?'a list) × ((?'a list ⇒ ?'a list) ⇒ ?'r ⇒ ?'r)) ≡ snd ?f tl›*) split: cond_splits (*‹(?A::bool ⇒ bool) (((?P::?'a × ?'a ⇒ bool) ◃ ?b::?'a × ?'a ⇒ bool ▹ (?Q::?'a × ?'a ⇒ bool)) (?x::?'a × ?'a)) = ((?b ?x ⟶ ?A (?P ?x)) ∧ (¬ ?b ?x ⟶ ?A (?Q ?x)))› ‹(?A::bool ⇒ bool) (((?P::?'a × ?'a ⇒ bool) ◃ ?b::?'a × ?'a ⇒ bool ▹ (?Q::?'a × ?'a ⇒ bool)) (?x::?'a × ?'a)) = (¬ (?b ?x ∧ ¬ ?A (?P ?x) ∨ ¬ ?b ?x ∧ ¬ ?A (?Q ?x)))›*))[1]) (*proven 3 subgoals*) (*proven 3 subgoals*) . lemmas Var_is_CSP = Var_is_action[simplified] lemma relation_of_Var: "relation_of (Var v A) = ((R(true ⊢ (λ (A, A'). ∃ a. tr A' = tr A ∧ ¬wait A' ∧ more A' = (increase v a (more A)))));; (relation_of A;; (R(true ⊢ (λ (A, A'). tr A' = tr A ∧ ¬wait A' ∧ more A' = (decrease v (more A)))))))" apply (simp only: Var_def (*‹Var ?v ?A ≡ action_of (R (true ⊢ λ(A, A'). ∃a. tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = increase ?v a (alpha_rp.more A)) ;; action.relation_of ?A ;; R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease ?v (alpha_rp.more A)))›*)) (*goal: ‹action.relation_of (Var v A) = (R (true ⊢ λ(A, A'). ∃a. tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = increase v a (alpha_rp.more A)) ;; action.relation_of A ;; R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)))›*) apply (rule action_of_inverse (*‹?y ∈ {p. is_CSP_process p} ⟹ action.relation_of (action_of ?y) = ?y›*)) (*goal: ‹action.relation_of (action_of (R (true ⊢ λ(A, A'). ∃a. tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = increase v a (alpha_rp.more A)) ;; action.relation_of A ;; R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)))) = (R (true ⊢ λ(A, A'). ∃a. tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = increase v a (alpha_rp.more A)) ;; action.relation_of A ;; R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)))›*) by (rule Var_is_action (*‹(R (true ⊢ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). ∃a::?'c. tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = increase (?v::(?'b ⇒ ?'c list) × ((?'c list ⇒ ?'c list) ⇒ ?'b ⇒ ?'b)) a (alpha_rp.more A)) ;; action.relation_of (?A::(?'a, ?'b) action) ;; R (true ⊢ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease ?v (alpha_rp.more A))) ∈ {p::(?'a, ?'b) alpha_rp_scheme × (?'a, ?'b) alpha_rp_scheme ⇒ bool. is_CSP_process p}›*)) lemma mono_Var : "mono (Var x)" by (auto simp: mono_def (*‹mono (?f::?'a ⇒ ?'b) = (∀(x::?'a) y::?'a. x ≤ y ⟶ ?f x ≤ ?f y)›*) less_eq_action (*‹(?P::(?'a, ?'b) action) ≤ (?Q::(?'a, ?'b) action) ≡ ?P ⊑ ?Q›*) ref_def (*‹(?P::(?'a, ?'b) action) ⊑ (?Q::(?'a, ?'b) action) ≡ ∀A::(?'a, ?'b) alpha_rp_scheme × (?'a, ?'b) alpha_rp_scheme. (action.relation_of ?Q ⟶ action.relation_of ?P) A›*) relation_of_Var (*‹action.relation_of (Var (?v::(?'b ⇒ ?'c list) × ((?'c list ⇒ ?'c list) ⇒ ?'b ⇒ ?'b)) (?A::(?'a, ?'b) action)) = (R (true ⊢ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). ∃a::?'c. tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = increase ?v a (alpha_rp.more A)) ;; action.relation_of ?A ;; R (true ⊢ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease ?v (alpha_rp.more A)))›*)) definition Let::"('v, 'σ) var_list ⇒('θ, 'σ) action ⇒ ('θ::ev_eq,'σ) action" where "Let v A ≡ action_of((relation_of A;; (R(true ⊢ (λ (A, A'). tr A' = tr A ∧ ¬wait A' ∧ more A' = (decrease v (more A)))))))" syntax "_let"::"idt ⇒ ('θ, 'σ) action ⇒ ('θ, 'σ) action" ("let _ ∙ _" [1000] 999) translations "let y ∙ Act" => "CONST Let (VAR_LIST y) Act" lemma Let_is_action: "(relation_of A;; (R(true ⊢ (λ (A, A'). tr A' = tr A ∧ ¬wait A' ∧ more A' = (decrease v (more A)))))) ∈ {p. is_CSP_process p}" apply simp (*goal: ‹(action.relation_of (A::('a, 'b) action) ;; R (true ⊢ λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease (v::('b ⇒ 'c list) × (('c list ⇒ 'c list) ⇒ 'b ⇒ 'b)) (alpha_rp.more A))) ∈ {p::('a, 'b) alpha_rp_scheme × ('a, 'b) alpha_rp_scheme ⇒ bool. is_CSP_process p}›*) apply (rule seq_CSP (*‹⟦?P is CSP1 healthy; ?P is R healthy; is_CSP_process ?Q⟧ ⟹ is_CSP_process (?P ;; ?Q)›*)) (*goals: 1. ‹action.relation_of A is CSP1 healthy› 2. ‹action.relation_of A is R healthy› 3. ‹is_CSP_process (R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)))› discuss goal 1*) apply ((auto simp: relation_of_CSP1 (*‹action.relation_of (?x::(?'a, ?'b) action) is CSP1 healthy›*) relation_of_R (*‹action.relation_of (?x::(?'a, ?'b) action) is R healthy›*))[1]) (*discuss goal 2*) apply ((auto simp: relation_of_CSP1 (*‹action.relation_of ?x is CSP1 healthy›*) relation_of_R (*‹action.relation_of ?x is R healthy›*))[1]) (*discuss goal 3*) apply (rule rd_is_CSP (*‹∀(a::(?'a, ?'b) alpha_rp_scheme) b::(?'a, ?'b) alpha_rp_scheme. (?r::(?'a, ?'b) alpha_rp_scheme × (?'a, ?'b) alpha_rp_scheme ⇒ bool) (a, b⦇ok := True⦈) ⟶ ?r (a, b⦇ok := False⦈) ⟹ is_CSP_process (R (?r ⊢ ?p::(?'a, ?'b) alpha_rp_scheme × (?'a, ?'b) alpha_rp_scheme ⇒ bool))›*)) (*goal: ‹is_CSP_process (R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)))›*) apply auto (*proven 3 subgoals*) . lemmas Let_is_CSP = Let_is_action[simplified] lemma relation_of_Let: "relation_of (Let v A) = (relation_of A;; (R(true ⊢ (λ (A, A'). tr A' = tr A ∧ ¬wait A' ∧ more A' = (decrease v (more A))))))" by (simp add: Let_def (*‹Denotational_Semantics.Let ?v ?A ≡ action_of (action.relation_of ?A ;; R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease ?v (alpha_rp.more A)))›*) action_of_inverse (*‹?y ∈ {p. is_CSP_process p} ⟹ action.relation_of (action_of ?y) = ?y›*) Let_is_CSP (*‹is_CSP_process (action.relation_of ?A ;; R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease ?v (alpha_rp.more A)))›*)) lemma mono_Let : "mono (Let x)" by (auto simp: mono_def (*‹mono ?f = (∀x y. x ≤ y ⟶ ?f x ≤ ?f y)›*) less_eq_action (*‹?P ≤ ?Q ≡ ?P ⊑ ?Q›*) ref_def (*‹?P ⊑ ?Q ≡ ∀A. (action.relation_of ?Q ⟶ action.relation_of ?P) A›*) relation_of_Let (*‹action.relation_of (Denotational_Semantics.Let ?v ?A) = (action.relation_of ?A ;; R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease ?v (alpha_rp.more A)))›*)) lemma Var_is_state_update_before: "Var v A = state_update_before (λ (s, s'). ∃ a. s' = increase v a s) (Let v A)" apply (subst relation_of_inject[symmetric] (*‹(?x = ?y) = (action.relation_of ?x = action.relation_of ?y)›*)) (*goal: ‹Var v A = state_update_before (λ(s, s'). ∃a. s' = increase v a s) (Denotational_Semantics.Let v A)›*) apply (auto simp: relation_of_Var (*‹action.relation_of (Var (?v::(?'b ⇒ ?'c list) × ((?'c list ⇒ ?'c list) ⇒ ?'b ⇒ ?'b)) (?A::(?'a, ?'b) action)) = (R (true ⊢ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). ∃a::?'c. tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = increase ?v a (alpha_rp.more A)) ;; action.relation_of ?A ;; R (true ⊢ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease ?v (alpha_rp.more A)))›*) relation_of_Let (*‹action.relation_of (Denotational_Semantics.Let (?v::(?'b ⇒ ?'c list) × ((?'c list ⇒ ?'c list) ⇒ ?'b ⇒ ?'b)) (?A::(?'a, ?'b) action)) = (action.relation_of ?A ;; R (true ⊢ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease ?v (alpha_rp.more A)))›*) relation_of_state_update_before (*‹action.relation_of (state_update_before (?sc::?'b × ?'b ⇒ bool) (?Ac::(?'a, ?'b) action)) = (R (λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). Pre ?sc (alpha_rp.more A) ⊢ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). ?sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ tr A = tr A') ;; action.relation_of ?Ac)›*) relation_of_Skip (*‹action.relation_of Skip = R (true ⊢ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A')›*) fun_eq_iff (*‹((?f::?'a ⇒ ?'b) = (?g::?'a ⇒ ?'b)) = (∀x::?'a. ?f x = ?g x)›*)) (*goals: 1. ‹⋀aa ab bb ca. ⟦R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) (aa, ab); action.relation_of A (ab, bb); R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) (bb, ca)⟧ ⟹ (R (λ(A, A'). Pre (λ(s, s'). ∃a. s' = increase v a s) (alpha_rp.more A) ⊢ λ(A, A'). (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ tr A = tr A') ;; action.relation_of A ;; R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A))) (aa, ca)› 2. ‹⋀aa ab bb ca. ⟦R (λ(A, A'). Pre (λ(s, s'). ∃a. s' = increase v a s) (alpha_rp.more A) ⊢ λ(A, A'). (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ tr A = tr A') (aa, ab); action.relation_of A (ab, bb); R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) (bb, ca)⟧ ⟹ (R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ;; action.relation_of A ;; R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A))) (aa, ca)› discuss goal 1*) apply ((auto simp: rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) Pre_def (*‹Pre ?sc ≡ λA. ∃A'. ?sc (A, A')›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*))[1]) (*top goal: ‹⋀aa ab bb ca. ⟦R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) (aa, ab); action.relation_of A (ab, bb); R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) (bb, ca)⟧ ⟹ (R (λ(A, A'). Pre (λ(s, s'). ∃a. s' = increase v a s) (alpha_rp.more A) ⊢ λ(A, A'). (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ tr A = tr A') ;; action.relation_of A ;; R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A))) (aa, ca)› and 1 goal remains*) apply (split cond_splits) (*goals: 1. ‹⋀aa ab bb ca. ⟦action.relation_of A (ab, bb); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca); (wait ∘ fst) (aa, ab); case (aa, ab) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ (∃A' a. A' = increase v a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)› 2. ‹⋀aa ab bb ca. ⟦action.relation_of A (ab, bb); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca); ¬ (wait ∘ fst) (aa, ab); case (aa, ab) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ (∃A' a. A' = increase v a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)› discuss goal 1*) apply simp (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦action.relation_of (A::('a, 'b) action) (ab, bb); ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease (v::('b ⇒ 'c list) × (('c list ⇒ 'c list) ⇒ 'b ⇒ 'b)) (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca); (wait ∘ fst) (aa, ab); case (aa, ab) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ (∃(A'::'b) a::'c. A' = increase v a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a::'c. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)› and 2 goals remain*) apply (split cond_splits) (*goals: 1. ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); (wait ∘ fst) (bb, ca); case (bb, ca) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ (∃A' a. A' = increase v a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)› 2. ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); ¬ (wait ∘ fst) (bb, ca); case (bb, ca) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ (∃A' a. A' = increase v a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)› discuss goal 1*) apply simp (*top goal: ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); (wait ∘ fst) (bb, ca); case (bb, ca) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ (∃A' a. A' = increase v a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)› and 3 goals remain*) apply (rule_tac b=ab in comp_intro (*‹⟦(?P::?'a × ?'b ⇒ bool) (?a::?'a, ?b::?'b); (?Q::?'b × ?'c ⇒ bool) (?b, ?c::?'c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of (A::('a, 'b) action) (ab, bb); wait bb; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ (∃(A'::'b) a::'c. A' = increase (v::('b ⇒ 'c list) × (('c list ⇒ 'c list) ⇒ 'b ⇒ 'b)) a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a::'c. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ab)› 2. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of (A::('a, 'b) action) (ab, bb); wait bb; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ (action.relation_of A ;; ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease (v::('b ⇒ 'c list) × (('c list ⇒ 'c list) ⇒ 'b ⇒ 'b)) (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (ab, ca)› discuss goal 1*) apply (split cond_splits) (*top goal: ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); wait bb; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ (∃A' a. A' = increase v a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ab)› and 4 goals remain*) apply simp (*discuss goal 2*) apply (rule_tac b=bb in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of (A::('a, 'b) action) (ab, bb); wait bb; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ action.relation_of A (ab, bb)› 2. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of (A::('a, 'b) action) (ab, bb); wait bb; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease (v::('b ⇒ 'c list) × (('c list ⇒ 'c list) ⇒ 'b ⇒ 'b)) (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca)› discuss goal 1*) apply simp (*discuss goal 2*) apply (split cond_splits) (*top goal: ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); wait bb; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca)› and 3 goals remain*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*top goal: ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); ¬ (wait ∘ fst) (bb, ca); case (bb, ca) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ (∃A' a. A' = increase v a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)› and 2 goals remain*) apply (rule_tac b=ab in comp_intro (*‹⟦(?P::?'a × ?'b ⇒ bool) (?a::?'a, ?b::?'b); (?Q::?'b × ?'c ⇒ bool) (?b, ?c::?'c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); ¬ wait bb; (ok bb ∧ true (bb⦇tr := []⦈, ca⦇tr := tr ca - tr bb⦈) ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ (∃A' a. A' = increase v a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ab)› 2. ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); ¬ wait bb; (ok bb ∧ true (bb⦇tr := []⦈, ca⦇tr := tr ca - tr bb⦈) ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ (action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (ab, ca)› discuss goal 1*) apply (split cond_splits) (*top goal: ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); ¬ wait bb; (ok bb ∧ true (bb⦇tr := []⦈, ca⦇tr := tr ca - tr bb⦈) ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ (∃A' a. A' = increase v a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ab)› and 3 goals remain*) apply simp (*discuss goal 2*) apply (rule_tac b=bb in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); ¬ wait bb; (ok bb ∧ true (bb⦇tr := []⦈, ca⦇tr := tr ca - tr bb⦈) ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ action.relation_of A (ab, bb)› 2. ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); ¬ wait bb; (ok bb ∧ true (bb⦇tr := []⦈, ca⦇tr := tr ca - tr bb⦈) ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca)› discuss goal 1*) apply simp (*discuss goal 2*) apply (split cond_splits) (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of (A::('a, 'b) action) (ab, bb); ¬ wait bb; (ok bb ∧ true (bb⦇tr := []⦈, ca⦇tr := tr ca - tr bb⦈) ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease (v::('b ⇒ 'c list) × (('c list ⇒ 'c list) ⇒ 'b ⇒ 'b)) (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca)› and 2 goals remain*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*top goal: ‹⋀aa ab bb ca. ⟦action.relation_of A (ab, bb); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca); ¬ (wait ∘ fst) (aa, ab); case (aa, ab) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ (∃A' a. A' = increase v a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)› and 1 goal remains*) apply (split cond_splits) (*goals: 1. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); (wait ∘ fst) (bb, ca); ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)); tr aa ≤ tr ab; case (bb, ca) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ (∃A' a. A' = increase v a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)› 2. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); ¬ (wait ∘ fst) (bb, ca); ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)); tr aa ≤ tr ab; case (bb, ca) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ (∃A' a. A' = increase v a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)› discuss goal 1*) apply simp (*top goal: ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); (wait ∘ fst) (bb, ca); ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)); tr aa ≤ tr ab; case (bb, ca) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ (∃A' a. A' = increase v a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)› and 2 goals remain*) apply (rule_tac b=ab in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); wait bb; ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)); tr aa ≤ tr ab; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ (∃A' a. A' = increase v a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ab)› 2. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); wait bb; ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)); tr aa ≤ tr ab; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ (action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (ab, ca)› discuss goal 1*) apply (split cond_splits) (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦¬ wait aa; action.relation_of (A::('a, 'b) action) (ab, bb); wait bb; ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a::'c. alpha_rp.more ab = increase (v::('b ⇒ 'c list) × (('c list ⇒ 'c list) ⇒ 'b ⇒ 'b)) a (alpha_rp.more aa)); tr aa ≤ tr ab; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ (∃(A'::'b) a::'c. A' = increase v a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a::'c. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ab)› and 3 goals remain*) apply simp (*top goal: ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); wait bb; ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)); tr aa ≤ tr ab; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ ((wait ∘ fst) (aa, ab) ⟶ (case (aa, ab) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A')) ∧ (¬ (wait ∘ fst) (aa, ab) ⟶ (case (aa, ab) of (A, A') ⇒ (ok A ∧ (∃A' a. A' = increase v a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'))› and 3 goals remain*) apply (simp add: true_def (*‹true ≡ λA::?'α. True›*)) (*discuss goal 2*) apply (rule_tac b=bb in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); wait bb; ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)); tr aa ≤ tr ab; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ action.relation_of A (ab, bb)› 2. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); wait bb; ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)); tr aa ≤ tr ab; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca)› discuss goal 1*) apply simp (*discuss goal 2*) apply (split cond_splits) (*top goal: ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); wait bb; ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)); tr aa ≤ tr ab; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca)› and 2 goals remain*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*top goal: ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); ¬ (wait ∘ fst) (bb, ca); ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)); tr aa ≤ tr ab; case (bb, ca) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ (∃A' a. A' = increase v a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)› and 1 goal remains*) apply (rule_tac b=ab in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); ¬ wait bb; ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)); tr aa ≤ tr ab; (ok bb ∧ true (bb⦇tr := []⦈, ca⦇tr := tr ca - tr bb⦈) ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ (∃A' a. A' = increase v a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ab)› 2. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); ¬ wait bb; ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)); tr aa ≤ tr ab; (ok bb ∧ true (bb⦇tr := []⦈, ca⦇tr := tr ca - tr bb⦈) ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ (action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (ab, ca)› discuss goal 1*) apply (split cond_splits) (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦¬ wait aa; action.relation_of (A::('a, 'b) action) (ab, bb); ¬ wait bb; ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a::'c. alpha_rp.more ab = increase (v::('b ⇒ 'c list) × (('c list ⇒ 'c list) ⇒ 'b ⇒ 'b)) a (alpha_rp.more aa)); tr aa ≤ tr ab; (ok bb ∧ true (bb⦇tr := []⦈, ca⦇tr := tr ca - tr bb⦈) ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ (∃(A'::'b) a::'c. A' = increase v a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a::'c. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A')) (aa, ab)› and 2 goals remain*) apply simp (*top goal: ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); ¬ wait bb; ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)); tr aa ≤ tr ab; (ok bb ∧ true (bb⦇tr := []⦈, ca⦇tr := tr ca - tr bb⦈) ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ ((wait ∘ fst) (aa, ab) ⟶ (case (aa, ab) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A')) ∧ (¬ (wait ∘ fst) (aa, ab) ⟶ (case (aa, ab) of (A, A') ⇒ (ok A ∧ (∃A' a. A' = increase v a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'))› and 2 goals remain*) apply (simp add: true_def (*‹true ≡ λA. True›*)) (*discuss goal 2*) apply (rule_tac b=bb in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); ¬ wait bb; ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)); tr aa ≤ tr ab; (ok bb ∧ true (bb⦇tr := []⦈, ca⦇tr := tr ca - tr bb⦈) ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ action.relation_of A (ab, bb)› 2. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); ¬ wait bb; ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)); tr aa ≤ tr ab; (ok bb ∧ true (bb⦇tr := []⦈, ca⦇tr := tr ca - tr bb⦈) ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca)› discuss goal 1*) apply simp (*discuss goal 2*) apply (split cond_splits) (*top goal: ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); ¬ wait bb; ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)); tr aa ≤ tr ab; (ok bb ∧ true (bb⦇tr := []⦈, ca⦇tr := tr ca - tr bb⦈) ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca)› and 1 goal remains*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply ((auto simp: rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) Pre_def (*‹Pre ?sc ≡ λA. ∃A'. ?sc (A, A')›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*))[1]) (*goal: ‹⋀aa ab bb ca. ⟦R (λ(A, A'). Pre (λ(s, s'). ∃a. s' = increase v a s) (alpha_rp.more A) ⊢ λ(A, A'). (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ tr A = tr A') (aa, ab); action.relation_of A (ab, bb); R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) (bb, ca)⟧ ⟹ (R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ;; action.relation_of A ;; R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A))) (aa, ca)›*) apply (split cond_splits) (*goals: 1. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦action.relation_of (A::('a, 'b) action) (ab, bb); ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease (v::('b ⇒ 'c list) × (('c list ⇒ 'c list) ⇒ 'b ⇒ 'b)) (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca); (wait ∘ fst) (aa, ab); case (aa, ab) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a::'c. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)› 2. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦action.relation_of (A::('a, 'b) action) (ab, bb); ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease (v::('b ⇒ 'c list) × (('c list ⇒ 'c list) ⇒ 'b ⇒ 'b)) (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca); ¬ (wait ∘ fst) (aa, ab); case (aa, ab) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ (ok A ∧ (∃(A'::'b) a::'c. A' = increase v a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a::'c. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a::'c. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)› discuss goal 1*) apply simp (*top goal: ‹⋀aa ab bb ca. ⟦action.relation_of A (ab, bb); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca); (wait ∘ fst) (aa, ab); case (aa, ab) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)› and 1 goal remains*) apply (split cond_splits) (*goals: 1. ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); (wait ∘ fst) (bb, ca); case (bb, ca) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)› 2. ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); ¬ (wait ∘ fst) (bb, ca); case (bb, ca) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)› discuss goal 1*) apply simp (*top goal: ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); (wait ∘ fst) (bb, ca); case (bb, ca) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)› and 2 goals remain*) apply (rule_tac b=ab in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); wait bb; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A')) (aa, ab)› 2. ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); wait bb; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ (action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (ab, ca)› discuss goal 1*) apply (split cond_splits) (*top goal: ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); wait bb; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A')) (aa, ab)› and 3 goals remain*) apply simp (*discuss goal 2*) apply (rule_tac b=bb in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of (A::('a, 'b) action) (ab, bb); wait bb; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ action.relation_of A (ab, bb)› 2. ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of (A::('a, 'b) action) (ab, bb); wait bb; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease (v::('b ⇒ 'c list) × (('c list ⇒ 'c list) ⇒ 'b ⇒ 'b)) (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca)› discuss goal 1*) apply simp (*discuss goal 2*) apply (split cond_splits) (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of (A::('a::ev_eq, 'b::type) action) (ab, bb); wait bb; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease (v::('b::type ⇒ 'c::type list) × (('c::type list ⇒ 'c::type list) ⇒ 'b::type ⇒ 'b::type)) (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca)› and 2 goals remain*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*top goal: ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); ¬ (wait ∘ fst) (bb, ca); case (bb, ca) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)› and 1 goal remains*) apply (rule_tac b=ab in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); ¬ wait bb; (ok bb ∧ true (bb⦇tr := []⦈, ca⦇tr := tr ca - tr bb⦈) ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A')) (aa, ab)› 2. ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); ¬ wait bb; (ok bb ∧ true (bb⦇tr := []⦈, ca⦇tr := tr ca - tr bb⦈) ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ (action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (ab, ca)› discuss goal 1*) apply (split cond_splits) (*top goal: ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); ¬ wait bb; (ok bb ∧ true (bb⦇tr := []⦈, ca⦇tr := tr ca - tr bb⦈) ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A')) (aa, ab)› and 2 goals remain*) apply simp (*discuss goal 2*) apply (rule_tac b=bb in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); ¬ wait bb; (ok bb ∧ true (bb⦇tr := []⦈, ca⦇tr := tr ca - tr bb⦈) ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ action.relation_of A (ab, bb)› 2. ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); ¬ wait bb; (ok bb ∧ true (bb⦇tr := []⦈, ca⦇tr := tr ca - tr bb⦈) ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca)› discuss goal 1*) apply simp (*discuss goal 2*) apply (split cond_splits) (*top goal: ‹⋀aa ab bb ca. ⟦wait aa; ¬ ok aa ∧ tr aa ≤ tr ab ∨ ok ab ∧ tr aa = tr ab ∧ wait ab ∧ ref aa = ref ab ∧ alpha_rp.more aa = alpha_rp.more ab; action.relation_of A (ab, bb); ¬ wait bb; (ok bb ∧ true (bb⦇tr := []⦈, ca⦇tr := tr ca - tr bb⦈) ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca)› and 1 goal remains*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*goal: ‹⋀aa ab bb ca. ⟦action.relation_of A (ab, bb); ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca); ¬ (wait ∘ fst) (aa, ab); case (aa, ab) of (A, A') ⇒ (ok A ∧ (∃A' a. A' = increase v a (alpha_rp.more A)) ⟶ ok A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A)) ∧ ¬ wait A' ∧ [] = tr A' - tr A) ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)›*) apply (split cond_splits) (*goals: 1. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); (wait ∘ fst) (bb, ca); ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; case (bb, ca) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)› 2. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); ¬ (wait ∘ fst) (bb, ca); ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; case (bb, ca) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)› discuss goal 1*) apply simp (*top goal: ‹⋀(aa::('a, 'b) alpha_rp_scheme) (ab::('a, 'b) alpha_rp_scheme) (bb::('a, 'b) alpha_rp_scheme) ca::('a, 'b) alpha_rp_scheme. ⟦¬ wait aa; action.relation_of (A::('a, 'b) action) (ab, bb); (wait ∘ fst) (bb, ca); ok aa ∧ (∃(A'::'b) a::'c. A' = increase (v::('b ⇒ 'c list) × (('c list ⇒ 'c list) ⇒ 'b ⇒ 'b)) a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a::'c. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; case (bb, ca) of (A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme) ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'⟧ ⟹ (((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a::'c. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)› and 1 goal remains*) apply (rule_tac b=ab in comp_intro (*‹⟦(?P::?'a × ?'b ⇒ bool) (?a::?'a, ?b::?'b); (?Q::?'b × ?'c ⇒ bool) (?b, ?c::?'c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); wait bb; ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A')) (aa, ab)› 2. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); wait bb; ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ (action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (ab, ca)› discuss goal 1*) apply (split cond_splits) (*top goal: ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); wait bb; ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A')) (aa, ab)› and 2 goals remain*) apply simp (*top goal: ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); wait bb; ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ ((wait ∘ fst) (aa, ab) ⟶ (case (aa, ab) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A')) ∧ (¬ (wait ∘ fst) (aa, ab) ⟶ (case (aa, ab) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A'))› and 2 goals remain*) apply (case_tac "∃A' a. A' = increase v a (alpha_rp.more aa)") (*goals: 1. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); wait bb; ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca; ∃A' a. A' = increase v a (alpha_rp.more aa)⟧ ⟹ ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa))› 2. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); wait bb; ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca; ∄A' a. A' = increase v a (alpha_rp.more aa)⟧ ⟹ ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa))› discuss goal 1*) apply (simp add: true_def (*‹true ≡ λA. True›*)) (*discuss goal 2*) apply (simp add: true_def (*‹true ≡ λA. True›*)) (*top goal: ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); wait bb; ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca; ∄A' a. A' = increase v a (alpha_rp.more aa)⟧ ⟹ ok aa ∧ true (aa⦇tr := []⦈, ab⦇tr := tr ab - tr aa⦈) ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa))› and 2 goals remain*) apply (erule_tac x="increase v a (alpha_rp.more aa)" in allE (*‹⟦∀x::?'a::type. (?P::?'a::type ⇒ bool) x; ?P (?x::?'a::type) ⟹ ?R::bool⟧ ⟹ ?R›*)) (*top goal: ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); wait bb; tr aa ≤ tr ab; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca; ∀A' a. A' ≠ increase v a (alpha_rp.more aa)⟧ ⟹ ¬ ok aa› and 2 goals remain*) apply (erule_tac x="a" in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); wait bb; tr aa ≤ tr ab; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca; ∀ab. increase v a (alpha_rp.more aa) ≠ increase v ab (alpha_rp.more aa)⟧ ⟹ ¬ ok aa› and 2 goals remain*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (simp add: true_def (*‹true ≡ λA. True›*)) (*top goal: ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); wait bb; ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ (action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (ab, ca)› and 1 goal remains*) apply (rule_tac b=bb in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); wait bb; ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ action.relation_of A (ab, bb)› 2. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); wait bb; ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca)› discuss goal 1*) apply simp (*discuss goal 2*) apply (split cond_splits) (*top goal: ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); wait bb; ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; ¬ ok bb ∧ tr bb ≤ tr ca ∨ ok ca ∧ tr bb = tr ca ∧ wait ca ∧ ref bb = ref ca ∧ alpha_rp.more bb = alpha_rp.more ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca)› and 1 goal remains*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*goal: ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); ¬ (wait ∘ fst) (bb, ca); ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; case (bb, ca) of (A, A') ⇒ (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)›*) apply (simp add: true_def (*‹true ≡ λA::?'α. True›*)) (*goal: ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); ¬ wait bb; ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; (ok bb ∧ true (bb⦇tr := []⦈, ca⦇tr := tr ca - tr bb⦈) ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ (((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A')) ;; action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ∧ true (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (aa, ca)›*) apply (rule_tac b=ab in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); ¬ wait bb; ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; (ok bb ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A')) (aa, ab)› 2. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); ¬ wait bb; ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; (ok bb ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ (action.relation_of A ;; ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A'))) (ab, ca)› discuss goal 1*) apply (split cond_splits) (*top goal: ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); ¬ wait bb; ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; (ok bb ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A')) (aa, ab)› and 1 goal remains*) apply simp (*top goal: ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); ¬ wait bb; ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; (ok bb ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ ((wait ∘ fst) (aa, ab) ⟶ (case (aa, ab) of (A, A') ⇒ ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A')) ∧ (¬ (wait ∘ fst) (aa, ab) ⟶ (case (aa, ab) of (A, A') ⇒ (ok A ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ (∃a. alpha_rp.more A' = increase v a (alpha_rp.more A))) ∧ tr A ≤ tr A'))› and 1 goal remains*) apply (case_tac "∃A' a. A' = increase v a (alpha_rp.more aa)") (*goals: 1. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); ¬ wait bb; ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; (ok bb ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca; ∃A' a. A' = increase v a (alpha_rp.more aa)⟧ ⟹ ok aa ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa))› 2. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); ¬ wait bb; ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; (ok bb ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca; ∄A' a. A' = increase v a (alpha_rp.more aa)⟧ ⟹ ok aa ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa))› discuss goal 1*) apply (simp add: true_def (*‹true ≡ λA. True›*)) (*discuss goal 2*) apply (simp add: true_def (*‹true ≡ λA. True›*)) (*top goal: ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); ¬ wait bb; ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; (ok bb ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca; ∄A' a. A' = increase v a (alpha_rp.more aa)⟧ ⟹ ok aa ⟶ ok ab ∧ tr ab - tr aa = [] ∧ ¬ wait ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa))› and 1 goal remains*) apply (erule_tac x="increase v a (alpha_rp.more aa)" in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); ¬ wait bb; tr aa ≤ tr ab; (ok bb ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca; ∀A' a. A' ≠ increase v a (alpha_rp.more aa)⟧ ⟹ ¬ ok aa› and 1 goal remains*) apply (erule_tac x="a" in allE (*‹⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R›*)) (*top goal: ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); ¬ wait bb; tr aa ≤ tr ab; (ok bb ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca; ∀ab. increase v a (alpha_rp.more aa) ≠ increase v ab (alpha_rp.more aa)⟧ ⟹ ¬ ok aa› and 1 goal remains*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (rule_tac b=bb in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); ¬ wait bb; ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; (ok bb ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ action.relation_of A (ab, bb)› 2. ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); ¬ wait bb; ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; (ok bb ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca)› discuss goal 1*) apply simp (*discuss goal 2*) apply (split cond_splits) (*goal: ‹⋀aa ab bb ca. ⟦¬ wait aa; action.relation_of A (ab, bb); ¬ wait bb; ok aa ∧ (∃A' a. A' = increase v a (alpha_rp.more aa)) ⟶ ok ab ∧ (∃a. alpha_rp.more ab = increase v a (alpha_rp.more aa)) ∧ ¬ wait ab ∧ [] = tr ab - tr aa; tr aa ≤ tr ab; (ok bb ⟶ ok ca ∧ tr ca - tr bb = [] ∧ ¬ wait ca ∧ alpha_rp.more ca = decrease v (alpha_rp.more bb)) ∧ tr bb ≤ tr ca⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (ok A ⟶ ok A' ∧ tr A' - tr A = [] ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) ∧ tr A ≤ tr A')) (bb, ca)›*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma Let_is_state_update_after: "Let v A = state_update_after (λ (s, s'). s' = decrease v s) A" apply (subst relation_of_inject[symmetric] (*‹(?x = ?y) = (action.relation_of ?x = action.relation_of ?y)›*)) (*goal: ‹Denotational_Semantics.Let (v::('b ⇒ 'c list) × (('c list ⇒ 'c list) ⇒ 'b ⇒ 'b)) (A::('a, 'b) action) = state_update_after (λ(s::'b, s'::'b). s' = decrease v s) A›*) apply (auto simp: relation_of_Var (*‹action.relation_of (Var (?v::(?'b ⇒ ?'c list) × ((?'c list ⇒ ?'c list) ⇒ ?'b ⇒ ?'b)) (?A::(?'a, ?'b) action)) = (R (true ⊢ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). ∃a::?'c. tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = increase ?v a (alpha_rp.more A)) ;; action.relation_of ?A ;; R (true ⊢ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease ?v (alpha_rp.more A)))›*) relation_of_Let (*‹action.relation_of (Denotational_Semantics.Let (?v::(?'b ⇒ ?'c list) × ((?'c list ⇒ ?'c list) ⇒ ?'b ⇒ ?'b)) (?A::(?'a, ?'b) action)) = (action.relation_of ?A ;; R (true ⊢ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease ?v (alpha_rp.more A)))›*) relation_of_state_update_after (*‹action.relation_of (state_update_after (?sc::?'b × ?'b ⇒ bool) (?Ac::(?'a, ?'b) action)) = (action.relation_of ?Ac ;; R (true ⊢ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). ?sc (alpha_rp.more A, alpha_rp.more A') ∧ ¬ wait A' ∧ tr A = tr A'))›*) relation_of_Skip (*‹action.relation_of Skip = R (true ⊢ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A')›*) fun_eq_iff (*‹((?f::?'a ⇒ ?'b) = (?g::?'a ⇒ ?'b)) = (∀x::?'a. ?f x = ?g x)›*)) (*goals: 1. ‹⋀aa ba c. ⟦action.relation_of A (aa, ba); R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) (ba, c)⟧ ⟹ (action.relation_of A ;; R (true ⊢ λ(A, A'). alpha_rp.more A' = decrease v (alpha_rp.more A) ∧ ¬ wait A' ∧ tr A = tr A')) (aa, c)› 2. ‹⋀aa ba c. ⟦action.relation_of A (aa, ba); R (true ⊢ λ(A, A'). alpha_rp.more A' = decrease v (alpha_rp.more A) ∧ ¬ wait A' ∧ tr A = tr A') (ba, c)⟧ ⟹ (action.relation_of A ;; R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A))) (aa, c)› discuss goal 1*) apply ((auto simp: rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) Pre_def (*‹Pre ?sc ≡ λA. ∃A'. ?sc (A, A')›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*))[1]) (*top goal: ‹⋀aa ba c. ⟦action.relation_of A (aa, ba); R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A)) (ba, c)⟧ ⟹ (action.relation_of A ;; R (true ⊢ λ(A, A'). alpha_rp.more A' = decrease v (alpha_rp.more A) ∧ ¬ wait A' ∧ tr A = tr A')) (aa, c)› and 1 goal remains*) apply ((auto split: cond_splits (*‹(?A::bool ⇒ bool) (((?P::?'a × ?'a ⇒ bool) ◃ ?b::?'a × ?'a ⇒ bool ▹ (?Q::?'a × ?'a ⇒ bool)) (?x::?'a × ?'a)) = ((?b ?x ⟶ ?A (?P ?x)) ∧ (¬ ?b ?x ⟶ ?A (?Q ?x)))› ‹(?A::bool ⇒ bool) (((?P::?'a × ?'a ⇒ bool) ◃ ?b::?'a × ?'a ⇒ bool ▹ (?Q::?'a × ?'a ⇒ bool)) (?x::?'a × ?'a)) = (¬ (?b ?x ∧ ¬ ?A (?P ?x) ∨ ¬ ?b ?x ∧ ¬ ?A (?Q ?x)))›*))[1]) (*discuss goal 2*) apply ((auto simp: rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) Pre_def (*‹Pre ?sc ≡ λA. ∃A'. ?sc (A, A')›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*))[1]) (*goal: ‹⋀aa ba c. ⟦action.relation_of A (aa, ba); R (true ⊢ λ(A, A'). alpha_rp.more A' = decrease v (alpha_rp.more A) ∧ ¬ wait A' ∧ tr A = tr A') (ba, c)⟧ ⟹ (action.relation_of A ;; R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A' = decrease v (alpha_rp.more A))) (aa, c)›*) apply ((auto split: cond_splits (*‹(?A::bool ⇒ bool) (((?P::?'a × ?'a ⇒ bool) ◃ ?b::?'a × ?'a ⇒ bool ▹ (?Q::?'a × ?'a ⇒ bool)) (?x::?'a × ?'a)) = ((?b ?x ⟶ ?A (?P ?x)) ∧ (¬ ?b ?x ⟶ ?A (?Q ?x)))› ‹(?A::bool ⇒ bool) (((?P::?'a × ?'a ⇒ bool) ◃ ?b::?'a × ?'a ⇒ bool ▹ (?Q::?'a × ?'a ⇒ bool)) (?x::?'a × ?'a)) = (¬ (?b ?x ∧ ¬ ?A (?P ?x) ∨ ¬ ?b ?x ∧ ¬ ?A (?Q ?x)))›*))[1]) (*proven 2 subgoals*) . subsection ‹Guarded action› definition Guard::"'σ predicate ⇒ ('θ::ev_eq, 'σ) action ⇒ ('θ, 'σ) action" ("_ `&` _") where "g `&` P ≡ action_of(R (((g o more o fst) ⟶ ¬ ((relation_of P)⇧f⇩f)) ⊢ (((g o more o fst) ∧ ((relation_of P)⇧t⇩f)) ∨ ((¬(g o more o fst)) ∧ (λ (A, A'). tr A' = tr A ∧ wait A')))))" lemma Guard_is_action: "(R ( ((g o more o fst) ⟶ ¬ ((relation_of P)⇧f⇩f)) ⊢ (((g o more o fst) ∧ ((relation_of P)⇧t⇩f)) ∨ ((¬(g o more o fst)) ∧ (λ (A, A'). tr A' = tr A ∧ wait A'))))) ∈ {p. is_CSP_process p}" by (auto simp add: spec_def (*‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) intro: rd_is_CSP (*‹∀a b. ?r (a, b⦇ok := True⦈) ⟶ ?r (a, b⦇ok := False⦈) ⟹ is_CSP_process (R (?r ⊢ ?p))›*)) lemmas Guard_is_CSP = Guard_is_action[simplified] lemma relation_of_Guard: "relation_of (g `&` P) = (R (((g o more o fst) ⟶ ¬ ((relation_of P)⇧f⇩f)) ⊢ (((g o more o fst) ∧ ((relation_of P)⇧t⇩f)) ∨ ((¬(g o more o fst)) ∧ (λ (A, A'). tr A' = tr A ∧ wait A')))))" apply (unfold Guard_def (*‹?g `&` ?P ≡ action_of (R (?g ∘ alpha_rp.more ∘ fst ⟶ ¬ action.relation_of ?P⇧f⇩f ⊢ ?g ∘ alpha_rp.more ∘ fst ∧ action.relation_of ?P⇧t⇩f ∨ ¬ ?g ∘ alpha_rp.more ∘ fst ∧ (λ(A, A'). tr A' = tr A ∧ wait A')))›*)) (*goal: ‹action.relation_of g `&` P = R (g ∘ alpha_rp.more ∘ fst ⟶ ¬ action.relation_of P⇧f⇩f ⊢ g ∘ alpha_rp.more ∘ fst ∧ action.relation_of P⇧t⇩f ∨ ¬ g ∘ alpha_rp.more ∘ fst ∧ (λ(A, A'). tr A' = tr A ∧ wait A'))›*) apply (subst action_of_inverse (*‹?y ∈ {p. is_CSP_process p} ⟹ action.relation_of (action_of ?y) = ?y›*)) (*goals: 1. ‹R ((g::'b ⇒ bool) ∘ alpha_rp.more ∘ fst ⟶ ¬ action.relation_of (P::('a, 'b) action)⇧f⇩f ⊢ g ∘ alpha_rp.more ∘ fst ∧ action.relation_of P⇧t⇩f ∨ ¬ g ∘ alpha_rp.more ∘ fst ∧ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). tr A' = tr A ∧ wait A')) ∈ Collect is_CSP_process› 2. ‹R ((g::'b ⇒ bool) ∘ alpha_rp.more ∘ fst ⟶ ¬ action.relation_of (P::('a, 'b) action)⇧f⇩f ⊢ g ∘ alpha_rp.more ∘ fst ∧ action.relation_of P⇧t⇩f ∨ ¬ g ∘ alpha_rp.more ∘ fst ∧ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). tr A' = tr A ∧ wait A')) = R (g ∘ alpha_rp.more ∘ fst ⟶ ¬ action.relation_of P⇧f⇩f ⊢ g ∘ alpha_rp.more ∘ fst ∧ action.relation_of P⇧t⇩f ∨ ¬ g ∘ alpha_rp.more ∘ fst ∧ (λ(A::('a, 'b) alpha_rp_scheme, A'::('a, 'b) alpha_rp_scheme). tr A' = tr A ∧ wait A'))› discuss goal 1*) apply (simp only: Guard_is_action (*‹R (?g ∘ alpha_rp.more ∘ fst ⟶ ¬ action.relation_of ?P⇧f⇩f ⊢ ?g ∘ alpha_rp.more ∘ fst ∧ action.relation_of ?P⇧t⇩f ∨ ¬ ?g ∘ alpha_rp.more ∘ fst ∧ (λ(A, A'). tr A' = tr A ∧ wait A')) ∈ {p. is_CSP_process p}›*)) (*discuss goal 2*) apply (simp only: Guard_is_action (*‹R (?g ∘ alpha_rp.more ∘ fst ⟶ ¬ action.relation_of ?P⇧f⇩f ⊢ ?g ∘ alpha_rp.more ∘ fst ∧ action.relation_of ?P⇧t⇩f ∨ ¬ ?g ∘ alpha_rp.more ∘ fst ∧ (λ(A, A'). tr A' = tr A ∧ wait A')) ∈ {p. is_CSP_process p}›*)) (*proven 2 subgoals*) . lemma mono_Guard : "mono (Guard g)" apply (auto simp: mono_def (*‹mono ?f = (∀x y. x ≤ y ⟶ ?f x ≤ ?f y)›*) less_eq_action (*‹?P ≤ ?Q ≡ ?P ⊑ ?Q›*) ref_def (*‹?P ⊑ ?Q ≡ ∀A. (action.relation_of ?Q ⟶ action.relation_of ?P) A›*) rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*) relation_of_Guard (*‹action.relation_of ?g `&` ?P = R (?g ∘ alpha_rp.more ∘ fst ⟶ ¬ action.relation_of ?P⇧f⇩f ⊢ ?g ∘ alpha_rp.more ∘ fst ∧ action.relation_of ?P⇧t⇩f ∨ ¬ ?g ∘ alpha_rp.more ∘ fst ∧ (λ(A, A'). tr A' = tr A ∧ wait A'))›*) split: cond_splits (*‹?A ((?P ◃ ?b ▹ ?Q) ?x) = ((?b ?x ⟶ ?A (?P ?x)) ∧ (¬ ?b ?x ⟶ ?A (?Q ?x)))› ‹?A ((?P ◃ ?b ▹ ?Q) ?x) = (¬ (?b ?x ∧ ¬ ?A (?P ?x) ∨ ¬ ?b ?x ∧ ¬ ?A (?Q ?x)))›*)) (*goals: 1. ‹⋀x y a b. ⟦∀a b. (action.relation_of y ⟶ action.relation_of x) (a, b); ¬ wait a; tr a ≤ tr b; ok a; ¬ action.relation_of x (a⦇tr := [], wait := False⦈, b⦇tr := tr b - tr a, ok := False⦈); g (alpha_rp.more a); action.relation_of y (a⦇tr := [], wait := False⦈, b⦇tr := tr b - tr a, ok := False⦈)⟧ ⟹ ok b› 2. ‹⋀x y a b. ⟦∀a b. (action.relation_of y ⟶ action.relation_of x) (a, b); ¬ wait a; tr a ≤ tr b; ok a; ¬ action.relation_of x (a⦇tr := [], wait := False⦈, b⦇tr := tr b - tr a, ok := False⦈); g (alpha_rp.more a); action.relation_of y (a⦇tr := [], wait := False⦈, b⦇tr := tr b - tr a, ok := False⦈)⟧ ⟹ action.relation_of x (a⦇tr := [], wait := False⦈, b⦇tr := tr b - tr a, ok := True⦈)› 3. ‹⋀x y a b. ⟦∀a b. (action.relation_of y ⟶ action.relation_of x) (a, b); ¬ wait a; tr a ≤ tr b; ok a; ¬ action.relation_of x (a⦇tr := [], wait := False⦈, b⦇tr := tr b - tr a, ok := False⦈); g (alpha_rp.more a); action.relation_of y (a⦇tr := [], wait := False⦈, b⦇tr := tr b - tr a, ok := False⦈); ¬ action.relation_of x (a⦇tr := [], wait := False⦈, b⦇tr := tr b - tr a, ok := True⦈)⟧ ⟹ tr b - tr a = []› 4. ‹⋀x y a b. ⟦∀a b. (action.relation_of y ⟶ action.relation_of x) (a, b); ¬ wait a; tr a ≤ tr b; ok a; ¬ action.relation_of x (a⦇tr := [], wait := False⦈, b⦇tr := tr b - tr a, ok := False⦈); g (alpha_rp.more a); action.relation_of y (a⦇tr := [], wait := False⦈, b⦇tr := tr b - tr a, ok := False⦈); ¬ action.relation_of x (a⦇tr := [], wait := False⦈, b⦇tr := tr b - tr a, ok := True⦈)⟧ ⟹ wait b› 5. ‹⋀x y a b. ⟦∀a b. (action.relation_of y ⟶ action.relation_of x) (a, b); ¬ wait a; tr a ≤ tr b; ok a; ¬ action.relation_of x (a⦇tr := [], wait := False⦈, b⦇tr := tr b - tr a, ok := False⦈); ok b; g (alpha_rp.more a); action.relation_of y (a⦇tr := [], wait := False⦈, b⦇tr := tr b - tr a, ok := True⦈)⟧ ⟹ action.relation_of x (a⦇tr := [], wait := False⦈, b⦇tr := tr b - tr a, ok := True⦈)› 6. ‹⋀x y a b. ⟦∀a b. (action.relation_of y ⟶ action.relation_of x) (a, b); ¬ wait a; tr a ≤ tr b; ok a; ¬ action.relation_of x (a⦇tr := [], wait := False⦈, b⦇tr := tr b - tr a, ok := False⦈); ok b; g (alpha_rp.more a); action.relation_of y (a⦇tr := [], wait := False⦈, b⦇tr := tr b - tr a, ok := True⦈); ¬ action.relation_of x (a⦇tr := [], wait := False⦈, b⦇tr := tr b - tr a, ok := True⦈)⟧ ⟹ tr b - tr a = []› 7. ‹⋀x y a b. ⟦∀a b. (action.relation_of y ⟶ action.relation_of x) (a, b); ¬ wait a; tr a ≤ tr b; ok a; ¬ action.relation_of x (a⦇tr := [], wait := False⦈, b⦇tr := tr b - tr a, ok := False⦈); ok b; g (alpha_rp.more a); action.relation_of y (a⦇tr := [], wait := False⦈, b⦇tr := tr b - tr a, ok := True⦈); ¬ action.relation_of x (a⦇tr := [], wait := False⦈, b⦇tr := tr b - tr a, ok := True⦈)⟧ ⟹ wait b› discuss goal 1*) apply ((auto dest: relation_of_spec_f_f (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧f⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧f⇩f (?a⦇tr := []⦈, ?b)›*) relation_of_spec_t_f (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧t⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧t⇩f (?a⦇tr := []⦈, ?b)›*))[1]) (*discuss goal 2*) apply ((auto dest: relation_of_spec_f_f (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧f⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧f⇩f (?a⦇tr := []⦈, ?b)›*) relation_of_spec_t_f (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧t⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧t⇩f (?a⦇tr := []⦈, ?b)›*))[1]) (*discuss goal 3*) apply ((auto dest: relation_of_spec_f_f (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧f⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧f⇩f (?a⦇tr := []⦈, ?b)›*) relation_of_spec_t_f (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧t⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧t⇩f (?a⦇tr := []⦈, ?b)›*))[1]) (*discuss goal 4*) apply ((auto dest: relation_of_spec_f_f (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧f⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧f⇩f (?a⦇tr := []⦈, ?b)›*) relation_of_spec_t_f (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧t⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧t⇩f (?a⦇tr := []⦈, ?b)›*))[1]) (*discuss goal 5*) apply ((auto dest: relation_of_spec_f_f (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧f⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧f⇩f (?a⦇tr := []⦈, ?b)›*) relation_of_spec_t_f (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧t⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧t⇩f (?a⦇tr := []⦈, ?b)›*))[1]) (*discuss goal 6*) apply ((auto dest: relation_of_spec_f_f (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧f⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧f⇩f (?a⦇tr := []⦈, ?b)›*) relation_of_spec_t_f (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧t⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧t⇩f (?a⦇tr := []⦈, ?b)›*))[1]) (*discuss goal 7*) apply ((auto dest: relation_of_spec_f_f (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧f⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧f⇩f (?a⦇tr := []⦈, ?b)›*) relation_of_spec_t_f (*‹⟦∀a b. (action.relation_of ?y ⟶ action.relation_of ?x) (a, b); action.relation_of ?y⇧t⇩f (?a⦇tr := []⦈, ?b)⟧ ⟹ action.relation_of ?x⇧t⇩f (?a⦇tr := []⦈, ?b)›*))[1]) (*proven 7 subgoals*) . lemma false_Guard: "false `&` P = Stop" apply (subst relation_of_inject[symmetric] (*‹(?x = ?y) = (action.relation_of ?x = action.relation_of ?y)›*)) (*goal: ‹false `&` P = Stop›*) apply (subst relation_of_Stop (*‹action.relation_of Stop = R (true ⊢ λ(A, A'). tr A' = tr A ∧ wait A')›*)) (*goal: ‹action.relation_of false `&` P = action.relation_of Stop›*) apply (subst relation_of_Guard (*‹action.relation_of ?g `&` ?P = R (?g ∘ alpha_rp.more ∘ fst ⟶ ¬ action.relation_of ?P⇧f⇩f ⊢ ?g ∘ alpha_rp.more ∘ fst ∧ action.relation_of ?P⇧t⇩f ∨ ¬ ?g ∘ alpha_rp.more ∘ fst ∧ (λ(A, A'). tr A' = tr A ∧ wait A'))›*)) (*goal: ‹action.relation_of false `&` P = R (true ⊢ λ(A, A'). tr A' = tr A ∧ wait A')›*) by (simp add: fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) utp_defs (*‹true ≡ λA. True› ‹false ≡ λA. False› ‹?P ∧ ?Q ≡ λA. ?P A ∧ ?Q A› ‹?P ∨ ?Q ≡ λA. ?P A ∨ ?Q A› ‹¬ ?P ≡ λA. ¬ ?P A› ‹?P ⟶ ?Q ≡ λA. ?P A ⟶ ?Q A› ‹?P ⟷ ?Q ≡ λA. ?P A = ?Q A› ‹❙∃x. ?P x ≡ λA. ∃x. ?P x A› ‹❙∀x. ?P x ≡ λA. ∀x. ?P x A› ‹?P ◃ ?b ▹ ?Q ≡ ?b ∧ ?P ∨ ¬ ?b ∧ ?Q› ‹?P ;; ?Q ≡ λr. r ∈ {p. ?P p} O {q. ?Q q}› ‹Assign ?x ?a ≡ λ(A, A'). A' = assign ?x ?a A›*) csp_defs (*‹CSP1 ?P ≡ ?P ∨ (λ(A, A'). ¬ ok A ∧ tr A ≤ tr A')› ‹J_csp ≡ λ(A, A'). (ok A ⟶ ok A') ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹CSP2 ?P ≡ ?P ;; J_csp› ‹is_CSP_process ?P ≡ ?P is CSP1 healthy ∧ ?P is CSP2 healthy ∧ ?P is R healthy›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*) rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*)) lemma false_Guard1: "⋀ a b. g (alpha_rp.more a) = False ⟹ (relation_of (g `&` P)) (a, b) = (relation_of Stop) (a, b)" apply (subst relation_of_Guard (*‹action.relation_of ?g `&` ?P = R (?g ∘ alpha_rp.more ∘ fst ⟶ ¬ action.relation_of ?P⇧f⇩f ⊢ ?g ∘ alpha_rp.more ∘ fst ∧ action.relation_of ?P⇧t⇩f ∨ ¬ ?g ∘ alpha_rp.more ∘ fst ∧ (λ(A, A'). tr A' = tr A ∧ wait A'))›*)) (*goal: ‹⋀a b. g (alpha_rp.more a) = False ⟹ action.relation_of g `&` P (a, b) = action.relation_of Stop (a, b)›*) apply (subst relation_of_Stop (*‹action.relation_of Stop = R (true ⊢ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). tr A' = tr A ∧ wait A')›*)) (*goal: ‹⋀a b. g (alpha_rp.more a) = False ⟹ R (g ∘ alpha_rp.more ∘ fst ⟶ ¬ action.relation_of P⇧f⇩f ⊢ g ∘ alpha_rp.more ∘ fst ∧ action.relation_of P⇧t⇩f ∨ ¬ g ∘ alpha_rp.more ∘ fst ∧ (λ(A, A'). tr A' = tr A ∧ wait A')) (a, b) = action.relation_of Stop (a, b)›*) by (auto simp: fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) csp_defs (*‹CSP1 ?P ≡ ?P ∨ (λ(A, A'). ¬ ok A ∧ tr A ≤ tr A')› ‹J_csp ≡ λ(A, A'). (ok A ⟶ ok A') ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹CSP2 ?P ≡ ?P ;; J_csp› ‹is_CSP_process ?P ≡ ?P is CSP1 healthy ∧ ?P is CSP2 healthy ∧ ?P is R healthy›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*) rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) split: cond_splits (*‹?A ((?P ◃ ?b ▹ ?Q) ?x) = ((?b ?x ⟶ ?A (?P ?x)) ∧ (¬ ?b ?x ⟶ ?A (?Q ?x)))› ‹?A ((?P ◃ ?b ▹ ?Q) ?x) = (¬ (?b ?x ∧ ¬ ?A (?P ?x) ∨ ¬ ?b ?x ∧ ¬ ?A (?Q ?x)))›*)) lemma true_Guard: "true `&` P = P" apply (subst relation_of_inject[symmetric]) apply (subst relation_of_Guard) apply (subst CSP_is_rd[OF relation_of_CSP]) back back apply (simp add: fun_eq_iff utp_defs csp_defs design_defs rp_defs) done lemma true_Guard1: "⋀ a b. g (alpha_rp.more a) = True ⟹ (relation_of (g `&` P)) (a, b) = (relation_of P) (a, b)" apply (subst relation_of_Guard) apply (subst CSP_is_rd[OF relation_of_CSP]) back back apply (auto simp: fun_eq_iff csp_defs design_defs rp_defs split: cond_splits) done lemma Guard_is_state_update_before: "g `&` P = state_update_before (λ (s, s') . g s) P" apply (subst relation_of_inject[symmetric]) apply (auto simp: relation_of_Guard relation_of_state_update_before relation_of_Skip rp_defs fun_eq_iff Pre_def update_def design_defs) apply (rule_tac b=a in comp_intro) apply (split cond_splits, simp_all)+ apply (subst CSP_is_rd) apply (simp_all add: relation_of_CSP rp_defs design_defs fun_eq_iff) apply (split cond_splits, simp_all)+ apply (auto) apply (subst (asm) CSP_is_rd) apply (simp_all add: relation_of_CSP rp_defs design_defs fun_eq_iff) apply (split cond_splits, simp_all)+ apply (subst (asm) CSP_is_rd) apply (simp_all add: relation_of_CSP rp_defs design_defs fun_eq_iff) apply (split cond_splits, simp_all)+ apply (subst CSP_is_rd) apply (simp_all add: relation_of_CSP rp_defs design_defs fun_eq_iff) apply (split cond_splits, simp_all)+ apply (subst CSP_is_rd) apply (simp_all add: relation_of_CSP rp_defs design_defs fun_eq_iff) apply (split cond_splits, simp_all)+ apply (auto) defer apply (split cond_splits, simp_all)+ apply (subst (asm) CSP_is_rd) apply (simp_all add: relation_of_CSP rp_defs design_defs fun_eq_iff) apply (split cond_splits, simp_all)+ defer apply (rule disjI1) defer apply (case_tac "g (alpha_rp.more aa)", simp_all) apply (rule)+ apply (simp add: impl_def) defer oops subsection ‹Prefixed action› definition do where "do e ≡ (λ(A, A'). tr A = tr A' ∧ (e (more A)) ∉ (ref A')) ◃ wait o snd ▹ (λ(A, A'). tr A' = (tr A @[(e (more A))]))" definition do_I::"('σ ⇒'θ) ⇒ 'θ set ⇒ ('θ, 'σ) relation_rp" where "do_I c S ≡ ((λ(A, A'). tr A = tr A' & S ∩ (ref A') = {}) ◃ wait o snd ▹ (λ(A, A'). hd (tr A' - tr A) ∈ S & (c (more A) = (last (tr A')))))" (* definition do_I::"('v ⇒ 'θ) ⇒ ('v, 'σ) var_list ⇒ 'v set ⇒ ('θ, 'σ) relation_rp" where "do_I c x P ≡ ((λ(A, A'). tr A = tr A' ∧ (c`P) ∩ (ref A') = {}) ◃ wait o fst ▹ (λ(A, A'). hd (tr A' - tr A) ∈ (c`P) ∧ (c (select x (more A)) = (last (tr A')))))" *) definition iPrefix::"('σ ⇒'θ::ev_eq) ⇒ ('σ relation) ⇒ (('θ, 'σ) action ⇒ ('θ, 'σ) action) ⇒ ('σ ⇒ 'θ set) ⇒ ('θ, 'σ) action ⇒ ('θ, 'σ) action" where "iPrefix c i j S P ≡ action_of(R(true ⊢ (λ (A, A'). (do_I c (S (more A))) (A, A') & more A' = more A)))`;` P" definition oPrefix::"('σ ⇒'θ) ⇒ ('θ::ev_eq, 'σ) action ⇒ ('θ, 'σ) action" where "oPrefix c P ≡ action_of(R(true ⊢ (do c) ∧ (λ (A, A'). more A' = more A)))`;` P" definition Prefix0::"'θ ⇒ ('θ::ev_eq, 'σ) action ⇒ ('θ, 'σ) action" where "Prefix0 c P ≡ action_of(R(true ⊢ (do (λ _. c)) ∧ (λ (A, A'). more A' = more A)))`;` P" definition read::"('v ⇒ 'θ) ⇒ ('v, 'σ) var_list ⇒ ('θ::ev_eq, 'σ) action ⇒ ('θ, 'σ) action" where "read c x P ≡ iPrefix (λ A. c (select x A)) (λ (s, s'). ∃ a. s' = increase x a s) (Let x) (λ_. range c) P" definition read1::"('v ⇒ 'θ) ⇒ ('v, 'σ) var_list ⇒ ('σ ⇒ 'v set) ⇒ ('θ::ev_eq, 'σ) action ⇒ ('θ, 'σ) action" where "read1 c x S P ≡ iPrefix (λ A. c (select x A)) (λ (s, s'). ∃ a. a∈(S s) & s' = increase x a s) (Let x) (λs. c`(S s)) P" definition write1::"('v ⇒ 'θ) ⇒ ('σ ⇒ 'v) ⇒ ('θ::ev_eq, 'σ) action ⇒ ('θ, 'σ) action" where "write1 c a P ≡ oPrefix (λ A. c (a A)) P" definition write0::"'θ ⇒ ('θ::ev_eq, 'σ) action ⇒ ('θ, 'σ) action" where "write0 c P ≡ Prefix0 c P" syntax "_read" ::"[id, pttrn, ('θ, 'σ) action] => ('θ, 'σ) action" ("(_`?`_ /→ _)") "_readS" ::"[id, pttrn, 'θ set,('θ, 'σ) action] => ('θ, 'σ) action" ("(_`?`_`:`_ /→ _)") "_readSS" ::"[id, pttrn, 'σ => 'θ set,('θ, 'σ) action] => ('θ, 'σ) action" ("(_`?`_`∈`_ /→ _)") "_write" ::"[id, 'σ, ('θ, 'σ) action] => ('θ, 'σ) action" ("(_`!`_ /→ _)") "_writeS"::"['θ, ('θ, 'σ) action] => ('θ, 'σ) action" ("(_ /→ _)") translations "_read c p P" == "CONST read c (VAR_LIST p) P" "_readS c p b P" == "CONST read1 c (VAR_LIST p) (λ_. b) P" "_readSS c p b P" == "CONST read1 c (VAR_LIST p) b P" "_write c p P" == "CONST write1 c p P" "_writeS a P" == "CONST write0 a P" lemma Prefix_is_action: "(R(true ⊢ (do c) ∧ (λ (A, A'). more A' = more A))) ∈ {p. is_CSP_process p}" by (auto intro: rd_is_CSP (*‹∀a b. ?r (a, b⦇ok := True⦈) ⟶ ?r (a, b⦇ok := False⦈) ⟹ is_CSP_process (R (?r ⊢ ?p))›*)) lemma Prefix1_is_action: "(R(true ⊢ λ(A, A'). do_I c (S (alpha_rp.more A)) (A, A') ∧ alpha_rp.more A' = alpha_rp.more A)) ∈ {p. is_CSP_process p}" by (auto intro: rd_is_CSP (*‹∀a b. ?r (a, b⦇ok := True⦈) ⟶ ?r (a, b⦇ok := False⦈) ⟹ is_CSP_process (R (?r ⊢ ?p))›*)) lemma Prefix0_is_action: "(R(true ⊢ (do c) ∧ (λ (A, A'). more A' = more A))) ∈ {p. is_CSP_process p}" by (auto intro: rd_is_CSP (*‹∀a b. ?r (a, b⦇ok := True⦈) ⟶ ?r (a, b⦇ok := False⦈) ⟹ is_CSP_process (R (?r ⊢ ?p))›*)) lemmas Prefix_is_CSP = Prefix_is_action[simplified] lemmas Prefix1_is_CSP = Prefix1_is_action[simplified] lemmas Prefix0_is_CSP = Prefix0_is_action[simplified] lemma relation_of_iPrefix: "relation_of (iPrefix c i j S P) = ((R(true ⊢ (λ (A, A'). (do_I c (S (more A))) (A, A') & more A' = more A)));; relation_of P)" by (simp add: iPrefix_def (*‹iPrefix ?c ?i ?j ?S ?P ≡ action_of (R (true ⊢ λ(A, A'). do_I ?c (?S (alpha_rp.more A)) (A, A') ∧ alpha_rp.more A' = alpha_rp.more A)) `;` ?P›*) relation_of_Seq (*‹action.relation_of (?P `;` ?Q) = (action.relation_of ?P ;; action.relation_of ?Q)›*) action_of_inverse (*‹?y ∈ {p. is_CSP_process p} ⟹ action.relation_of (action_of ?y) = ?y›*) Prefix1_is_CSP (*‹is_CSP_process (R (true ⊢ λ(A, A'). do_I ?c (?S (alpha_rp.more A)) (A, A') ∧ alpha_rp.more A' = alpha_rp.more A))›*)) lemma relation_of_oPrefix: "relation_of (oPrefix c P) = ((R(true ⊢ (do c) ∧ (λ (A, A'). more A' = more A)));; relation_of P)" by (simp add: oPrefix_def (*‹oPrefix ?c ?P ≡ action_of (R (true ⊢ do ?c ∧ (λ(A, A'). alpha_rp.more A' = alpha_rp.more A))) `;` ?P›*) relation_of_Seq (*‹action.relation_of (?P `;` ?Q) = (action.relation_of ?P ;; action.relation_of ?Q)›*) action_of_inverse (*‹?y ∈ {p. is_CSP_process p} ⟹ action.relation_of (action_of ?y) = ?y›*) Prefix_is_CSP (*‹is_CSP_process (R (true ⊢ do ?c ∧ (λ(A, A'). alpha_rp.more A' = alpha_rp.more A)))›*)) lemma relation_of_Prefix0: "relation_of (Prefix0 c P) = ((R(true ⊢ (do (λ _. c)) ∧ (λ (A, A'). more A' = more A)));; relation_of P)" by (simp add: Prefix0_def (*‹Prefix0 (?c::?'θ) (?P::(?'θ, ?'σ) action) ≡ action_of (R (true ⊢ do (λ_::?'σ. ?c) ∧ (λ(A::(?'θ, ?'σ) alpha_rp_scheme, A'::(?'θ, ?'σ) alpha_rp_scheme). alpha_rp.more A' = alpha_rp.more A))) `;` ?P›*) relation_of_Seq (*‹action.relation_of ((?P::(?'a, ?'b) action) `;` (?Q::(?'a, ?'b) action)) = (action.relation_of ?P ;; action.relation_of ?Q)›*) action_of_inverse (*‹(?y::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ∈ {p::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool. is_CSP_process p} ⟹ action.relation_of (action_of ?y) = ?y›*) Prefix0_is_CSP (*‹is_CSP_process (R (true ⊢ do (?c::?'b ⇒ ?'a) ∧ (λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). alpha_rp.more A' = alpha_rp.more A)))›*)) lemma mono_iPrefix : "mono (iPrefix c i j s)" by (auto simp: mono_def (*‹mono ?f = (∀x y. x ≤ y ⟶ ?f x ≤ ?f y)›*) less_eq_action (*‹?P ≤ ?Q ≡ ?P ⊑ ?Q›*) ref_def (*‹?P ⊑ ?Q ≡ ∀A. (action.relation_of ?Q ⟶ action.relation_of ?P) A›*) relation_of_iPrefix (*‹action.relation_of (iPrefix ?c ?i ?j ?S ?P) = (R (true ⊢ λ(A, A'). do_I ?c (?S (alpha_rp.more A)) (A, A') ∧ alpha_rp.more A' = alpha_rp.more A) ;; action.relation_of ?P)›*)) lemma mono_oPrefix : "mono (oPrefix c)" by (auto simp: mono_def (*‹mono ?f = (∀x y. x ≤ y ⟶ ?f x ≤ ?f y)›*) less_eq_action (*‹?P ≤ ?Q ≡ ?P ⊑ ?Q›*) ref_def (*‹?P ⊑ ?Q ≡ ∀A. (action.relation_of ?Q ⟶ action.relation_of ?P) A›*) relation_of_oPrefix (*‹action.relation_of (oPrefix ?c ?P) = (R (true ⊢ do ?c ∧ (λ(A, A'). alpha_rp.more A' = alpha_rp.more A)) ;; action.relation_of ?P)›*)) lemma mono_Prefix0 : "mono(Prefix0 c)" by (auto simp: mono_def (*‹mono ?f = (∀x y. x ≤ y ⟶ ?f x ≤ ?f y)›*) less_eq_action (*‹?P ≤ ?Q ≡ ?P ⊑ ?Q›*) ref_def (*‹?P ⊑ ?Q ≡ ∀A. (action.relation_of ?Q ⟶ action.relation_of ?P) A›*) relation_of_Prefix0 (*‹action.relation_of (Prefix0 ?c ?P) = (R (true ⊢ do (λ_. ?c) ∧ (λ(A, A'). alpha_rp.more A' = alpha_rp.more A)) ;; action.relation_of ?P)›*)) subsection ‹Hiding› definition Hide::"('θ::ev_eq, 'σ) action ⇒ 'θ set ⇒ ('θ, 'σ) action" (infixl "\\" 18) where "P \\ cs ≡ action_of(R(λ(S, S'). ∃ s. (diff_tr S' S) = (tr_filter (s - (tr S)) cs) & (relation_of P)(S, S'⦇tr := s, ref := (ref S') ∪ cs ⦈));; (relation_of Skip))" definition "hid P cs == (R(λ(S, S'). ∃ s. (diff_tr S' S) = (tr_filter (s - (tr S)) cs) & (relation_of P)(S, S'⦇tr := s, ref := (ref S') ∪ cs ⦈)) ;; (relation_of Skip))" lemma hid_is_R: "hid P cs is R healthy" apply (simp add: hid_def (*‹hid ?P ?cs ≡ R (λ(S, S'). ∃s. diff_tr S' S = tr_filter (s - tr S) ?cs ∧ action.relation_of ?P (S, S'⦇tr := s, ref := ref S' ∪ ?cs⦈)) ;; action.relation_of Skip›*)) (*goal: ‹hid P cs is R healthy›*) apply (rule seq_R (*‹⟦?P::(?'a, ?'b) alpha_rp_scheme × (?'a, ?'b) alpha_rp_scheme ⇒ bool is R healthy; ?Q::(?'a, ?'b) alpha_rp_scheme × (?'a, ?'b) alpha_rp_scheme ⇒ bool is R healthy⟧ ⟹ ?P ;; ?Q is R healthy›*)) (*goals: 1. ‹R (λ(S, S'). ∃s. diff_tr S' S = tr_filter (s - tr S) cs ∧ action.relation_of P (S, S'⦇tr := s, ref := ref S' ∪ cs⦈)) is R healthy› 2. ‹action.relation_of Skip is R healthy› discuss goal 1*) apply (simp add: Healthy_def (*‹?P::?'α × ?'α ⇒ bool is ?H::(?'α × ?'α ⇒ bool) ⇒ ?'α × ?'α ⇒ bool healthy ≡ ?P = ?H ?P›*) R_idem2 (*‹R (R (?P::(?'a, ?'b) alpha_rp_scheme × (?'a, ?'b) alpha_rp_scheme ⇒ bool)) = R ?P›*)) (*discuss goal 2*) apply (rule CSP_is_R (*‹is_CSP_process ?P ⟹ ?P is R healthy›*)) (*goal: ‹action.relation_of Skip is R healthy›*) apply (rule relation_of_CSP (*‹is_CSP_process (action.relation_of ?x)›*)) (*proven 2 subgoals*) . lemma hid_Skip: "hid P cs = (hid P cs ;; relation_of Skip)" by (simp add: hid_def (*‹hid ?P ?cs ≡ R (λ(S, S'). ∃s. diff_tr S' S = tr_filter (s - tr S) ?cs ∧ action.relation_of ?P (S, S'⦇tr := s, ref := ref S' ∪ ?cs⦈)) ;; action.relation_of Skip›*) comp_assoc[symmetric] (*‹((?P ;; ?Q) ;; ?R) = (?P ;; ?Q ;; ?R)›*) Skip_comp_absorb (*‹(action.relation_of Skip ;; action.relation_of Skip) = action.relation_of Skip›*)) lemma hid_is_CSP1: "hid P cs is CSP1 healthy" apply (auto simp: design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*) CSP1_def (*‹CSP1 ?P ≡ ?P ∨ (λ(A, A'). ¬ ok A ∧ tr A ≤ tr A')›*) hid_def (*‹hid ?P ?cs ≡ R (λ(S, S'). ∃s. diff_tr S' S = tr_filter (s - tr S) ?cs ∧ action.relation_of ?P (S, S'⦇tr := s, ref := ref S' ∪ ?cs⦈)) ;; action.relation_of Skip›*) rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*)) (*goal: ‹hid P cs is CSP1 healthy›*) apply (rule_tac b="a" in comp_intro (*‹⟦?P (?a, ?b); ?Q (?b, ?c)⟧ ⟹ (?P ;; ?Q) (?a, ?c)›*)) (*goals: 1. ‹⋀a b. ⟦¬ ok a; tr a ≤ tr b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (∃s. diff_tr (A'⦇tr := tr A' - tr A⦈) (A⦇tr := []⦈) = tr_filter s cs ∧ action.relation_of P (A⦇tr := []⦈, A'⦇tr := s, ref := ref A' ∪ cs⦈)) ∧ tr A ≤ tr A')) (a, a)› 2. ‹⋀a b. ⟦¬ ok a; tr a ≤ tr b⟧ ⟹ action.relation_of Skip (a, b)› discuss goal 1*) apply (clarsimp split: cond_splits (*‹(?A::bool ⇒ bool) (((?P::?'a::type × ?'a::type ⇒ bool) ◃ ?b::?'a::type × ?'a::type ⇒ bool ▹ (?Q::?'a::type × ?'a::type ⇒ bool)) (?x::?'a::type × ?'a::type)) = ((?b ?x ⟶ ?A (?P ?x)) ∧ (¬ ?b ?x ⟶ ?A (?Q ?x)))› ‹(?A::bool ⇒ bool) (((?P::?'a::type × ?'a::type ⇒ bool) ◃ ?b::?'a::type × ?'a::type ⇒ bool ▹ (?Q::?'a::type × ?'a::type ⇒ bool)) (?x::?'a::type × ?'a::type)) = (¬ (?b ?x ∧ ¬ ?A (?P ?x) ∨ ¬ ?b ?x ∧ ¬ ?A (?Q ?x)))›*)) (*top goal: ‹⋀a b. ⟦¬ ok a; tr a ≤ tr b⟧ ⟹ ((λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A') ◃ wait ∘ fst ▹ (λ(A, A'). (∃s. diff_tr (A'⦇tr := tr A' - tr A⦈) (A⦇tr := []⦈) = tr_filter s cs ∧ action.relation_of P (A⦇tr := []⦈, A'⦇tr := s, ref := ref A' ∪ cs⦈)) ∧ tr A ≤ tr A')) (a, a)› and 1 goal remains*) apply (subst CSP_is_rd (*‹is_CSP_process ?P ⟹ ?P = R (¬ ?P⇧f⇩f ⊢ ?P⇧t⇩f)›*)) (*goals: 1. ‹⋀a b s. ⟦¬ ok a; tr a ≤ tr b; ¬ wait a⟧ ⟹ is_CSP_process (action.relation_of P)› 2. ‹⋀a b. ⟦¬ ok a; tr a ≤ tr b; ¬ wait a⟧ ⟹ ∃s. diff_tr (a⦇tr := []⦈) (a⦇tr := []⦈) = tr_filter s cs ∧ R (¬ action.relation_of P⇧f⇩f ⊢ action.relation_of P⇧t⇩f) (a⦇tr := []⦈, a⦇tr := s, ref := ref a ∪ cs⦈)› discuss goal 1*) apply ((auto simp: rp_defs (*‹R1 (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ λ(A::(?'θ, ?'σ) alpha_rp_scheme, A'::(?'θ, ?'σ) alpha_rp_scheme). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ λ(A::(?'θ, ?'σ) alpha_rp_scheme, A'::(?'θ, ?'σ) alpha_rp_scheme). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec (?b::bool) (?b'::bool) (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ λ(A::(?'θ, ?'σ) alpha_rp_scheme, A'::(?'θ, ?'σ) alpha_rp_scheme). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) relation_of_CSP (*‹is_CSP_process (action.relation_of (?x::(?'a, ?'b) action))›*) design_defs (*‹(?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool ⊢ ?Q::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). A = A')› ‹J ≡ λ(A::?'a alpha_d_scheme, A'::?'a alpha_d_scheme). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P::?'α × ?'α ⇒ bool is ?H::(?'α × ?'α ⇒ bool) ⇒ ?'α × ?'α ⇒ bool healthy ≡ ?P = ?H ?P› ‹H1 (?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ ok ∘ fst ⟶ ?P› ‹H2 (?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ ?P ;; J› ‹H3 (?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ ?P ;; Πd› ‹H4 (?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ (?P ;; true) ⟷ true› ‹σf (?D::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ?D (A, A'⦇ok := False⦈)› ‹σt (?D::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ok A› ‹OKAY' ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ok A'›*) fun_eq_iff (*‹((?f::?'a ⇒ ?'b) = (?g::?'a ⇒ ?'b)) = (∀x::?'a. ?f x = ?g x)›*) split: cond_splits (*‹(?A::bool ⇒ bool) (((?P::?'a × ?'a ⇒ bool) ◃ ?b::?'a × ?'a ⇒ bool ▹ (?Q::?'a × ?'a ⇒ bool)) (?x::?'a × ?'a)) = ((?b ?x ⟶ ?A (?P ?x)) ∧ (¬ ?b ?x ⟶ ?A (?Q ?x)))› ‹(?A::bool ⇒ bool) (((?P::?'a × ?'a ⇒ bool) ◃ ?b::?'a × ?'a ⇒ bool ▹ (?Q::?'a × ?'a ⇒ bool)) (?x::?'a × ?'a)) = (¬ (?b ?x ∧ ¬ ?A (?P ?x) ∨ ¬ ?b ?x ∧ ¬ ?A (?Q ?x)))›*))[1]) (*discuss goal 2*) apply ((auto simp: rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) relation_of_CSP (*‹is_CSP_process (action.relation_of ?x)›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) split: cond_splits (*‹?A ((?P ◃ ?b ▹ ?Q) ?x) = ((?b ?x ⟶ ?A (?P ?x)) ∧ (¬ ?b ?x ⟶ ?A (?Q ?x)))› ‹?A ((?P ◃ ?b ▹ ?Q) ?x) = (¬ (?b ?x ∧ ¬ ?A (?P ?x) ∨ ¬ ?b ?x ∧ ¬ ?A (?Q ?x)))›*))[1]) (*top goal: ‹⋀(a::('a, 'b) alpha_rp_scheme) b::('a, 'b) alpha_rp_scheme. ⟦¬ ok a; tr a ≤ tr b; ¬ wait a⟧ ⟹ ∃s::'a list. diff_tr (a⦇tr := []⦈) (a⦇tr := []⦈) = tr_filter s (cs::'a set) ∧ R (¬ action.relation_of (P::('a, 'b) action)⇧f⇩f ⊢ action.relation_of P⇧t⇩f) (a⦇tr := []⦈, a⦇tr := s, ref := ref a ∪ cs⦈)› and 1 goal remains*) apply ((auto simp: diff_tr_def (*‹diff_tr ?s1.0 ?s2.0 = tr ?s1.0 - tr ?s2.0›*) relation_of_Skip (*‹action.relation_of Skip = R (true ⊢ λ(A, A'). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A')›*) rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) design_defs (*‹(?P ⊢ ?Q) ≡ λ(A, A'). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A, A'). A = A')› ‹J ≡ λ(A, A'). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P is ?H healthy ≡ ?P = ?H ?P› ‹H1 ?P ≡ ok ∘ fst ⟶ ?P› ‹H2 ?P ≡ ?P ;; J› ‹H3 ?P ≡ ?P ;; Πd› ‹H4 ?P ≡ (?P ;; true) ⟷ true› ‹σf ?D ≡ λ(A, A'). ?D (A, A'⦇ok := False⦈)› ‹σt ?D ≡ λ(A, A'). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A, A'). ok A› ‹OKAY' ≡ λ(A, A'). ok A'›*) true_def (*‹true ≡ λA. True›*) split: cond_splits (*‹?A ((?P ◃ ?b ▹ ?Q) ?x) = ((?b ?x ⟶ ?A (?P ?x)) ∧ (¬ ?b ?x ⟶ ?A (?Q ?x)))› ‹?A ((?P ◃ ?b ▹ ?Q) ?x) = (¬ (?b ?x ∧ ¬ ?A (?P ?x) ∨ ¬ ?b ?x ∧ ¬ ?A (?Q ?x)))›*))[1]) (*top goal: ‹⋀a b. ⟦¬ ok a; tr a ≤ tr b; ¬ wait a⟧ ⟹ ∃s. diff_tr (a⦇tr := []⦈) (a⦇tr := []⦈) = tr_filter s cs› and 1 goal remains*) apply (rule_tac x="[]" in exI (*‹?P ?x ⟹ ∃x. ?P x›*)) (*top goal: ‹⋀a b. ⟦¬ ok a; tr a ≤ tr b; ¬ wait a⟧ ⟹ ∃s. [] = tr_filter s cs› and 1 goal remains*) apply auto (*proven 2 subgoals*) (*discuss goal 2*) apply ((auto simp: diff_tr_def (*‹diff_tr (?s1.0::(?'a, ?'b) alpha_rp_scheme) (?s2.0::(?'a, ?'c) alpha_rp_scheme) = tr ?s1.0 - tr ?s2.0›*) relation_of_Skip (*‹action.relation_of Skip = R (true ⊢ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). tr A' = tr A ∧ ¬ wait A' ∧ alpha_rp.more A = alpha_rp.more A')›*) rp_defs (*‹R1 (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ λ(A::(?'θ, ?'σ) alpha_rp_scheme, A'::(?'θ, ?'σ) alpha_rp_scheme). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ λ(A::(?'θ, ?'σ) alpha_rp_scheme, A'::(?'θ, ?'σ) alpha_rp_scheme). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A::(?'a, ?'b) alpha_rp_scheme, A'::(?'a, ?'b) alpha_rp_scheme). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec (?b::bool) (?b'::bool) (?P::(?'θ, ?'σ) alpha_rp_scheme × (?'θ, ?'σ) alpha_rp_scheme ⇒ bool) ≡ λ(A::(?'θ, ?'σ) alpha_rp_scheme, A'::(?'θ, ?'σ) alpha_rp_scheme). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*) design_defs (*‹(?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool ⊢ ?Q::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ok A ∧ ?P (A, A') ⟶ ok A' ∧ ?Q (A, A')› ‹Πd ≡ (true ⊢ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). A = A')› ‹J ≡ λ(A::?'a alpha_d_scheme, A'::?'a alpha_d_scheme). (ok A ⟶ ok A') ∧ alpha_d.more A = alpha_d.more A'› ‹?P::?'α × ?'α ⇒ bool is ?H::(?'α × ?'α ⇒ bool) ⇒ ?'α × ?'α ⇒ bool healthy ≡ ?P = ?H ?P› ‹H1 (?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ ok ∘ fst ⟶ ?P› ‹H2 (?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ ?P ;; J› ‹H3 (?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ ?P ;; Πd› ‹H4 (?P::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ (?P ;; true) ⟷ true› ‹σf (?D::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ?D (A, A'⦇ok := False⦈)› ‹σt (?D::?'α alpha_d_scheme × ?'α alpha_d_scheme ⇒ bool) ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ?D (A, A'⦇ok := True⦈)› ‹OKAY ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ok A› ‹OKAY' ≡ λ(A::?'α alpha_d_scheme, A'::?'α alpha_d_scheme). ok A'›*) true_def (*‹true ≡ λA::?'α. True›*) split: cond_splits (*‹(?A::bool ⇒ bool) (((?P::?'a × ?'a ⇒ bool) ◃ ?b::?'a × ?'a ⇒ bool ▹ (?Q::?'a × ?'a ⇒ bool)) (?x::?'a × ?'a)) = ((?b ?x ⟶ ?A (?P ?x)) ∧ (¬ ?b ?x ⟶ ?A (?Q ?x)))› ‹(?A::bool ⇒ bool) (((?P::?'a × ?'a ⇒ bool) ◃ ?b::?'a × ?'a ⇒ bool ▹ (?Q::?'a × ?'a ⇒ bool)) (?x::?'a × ?'a)) = (¬ (?b ?x ∧ ¬ ?A (?P ?x) ∨ ¬ ?b ?x ∧ ¬ ?A (?Q ?x)))›*))[1]) (*proven 2 subgoals*) . lemma hid_is_CSP2: "hid P cs is CSP2 healthy" apply (simp add: hid_def (*‹hid ?P ?cs ≡ R (λ(S, S'). ∃s. diff_tr S' S = tr_filter (s - tr S) ?cs ∧ action.relation_of ?P (S, S'⦇tr := s, ref := ref S' ∪ ?cs⦈)) ;; action.relation_of Skip›*)) (*goal: ‹hid P cs is CSP2 healthy›*) apply (rule seq_CSP2 (*‹?Q is CSP2 healthy ⟹ ?P ;; ?Q is CSP2 healthy›*)) (*goal: ‹R (λ(S, S'). ∃s. diff_tr S' S = tr_filter (s - tr S) cs ∧ action.relation_of P (S, S'⦇tr := s, ref := ref S' ∪ cs⦈)) ;; action.relation_of Skip is CSP2 healthy›*) apply (rule CSP_is_CSP2 (*‹is_CSP_process ?P ⟹ ?P is CSP2 healthy›*)) (*goal: ‹action.relation_of Skip is CSP2 healthy›*) by (rule relation_of_CSP (*‹is_CSP_process (action.relation_of (?x::(?'a, ?'b) action))›*)) lemma hid_is_CSP: "is_CSP_process (hid P cs)" by (auto simp: csp_defs (*‹CSP1 ?P ≡ ?P ∨ (λ(A, A'). ¬ ok A ∧ tr A ≤ tr A')› ‹J_csp ≡ λ(A, A'). (ok A ⟶ ok A') ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹CSP2 ?P ≡ ?P ;; J_csp› ‹is_CSP_process ?P ≡ ?P is CSP1 healthy ∧ ?P is CSP2 healthy ∧ ?P is R healthy›*) hid_is_CSP1 (*‹hid ?P ?cs is CSP1 healthy›*) hid_is_R (*‹hid ?P ?cs is R healthy›*) hid_is_CSP2 (*‹hid ?P ?cs is CSP2 healthy›*)) lemma Hide_is_action: "(R(λ(S, S'). ∃ s. (diff_tr S' S) = (tr_filter (s - (tr S)) cs) & (relation_of P)(S, S'⦇tr := s, ref := (ref S') ∪ cs ⦈));; (relation_of Skip)) ∈ {p. is_CSP_process p}" by (simp add: hid_is_CSP[simplified hid_def] (*‹is_CSP_process (R (λ(S::(?'a, ?'b) alpha_rp_scheme, S'::(?'a, ?'b) alpha_rp_scheme). ∃s::?'a::ev_eq list. diff_tr S' S = tr_filter (s - tr S) (?cs::?'a::ev_eq set) ∧ action.relation_of (?P::(?'a::ev_eq, ?'b::type) action) (S, S'⦇tr := s, ref := ref S' ∪ ?cs⦈)) ;; action.relation_of Skip)›*)) lemmas Hide_is_CSP = Hide_is_action[simplified] lemma relation_of_Hide: "relation_of (P \\ cs) = (R(λ(S, S'). ∃ s. (diff_tr S' S) = (tr_filter (s - (tr S)) cs) & (relation_of P)(S, S'⦇tr :=s, ref := (ref S') ∪ cs ⦈));; (relation_of Skip))" by (simp add: Hide_def (*‹?P \ ?cs ≡ action_of (R (λ(S, S'). ∃s. diff_tr S' S = tr_filter (s - tr S) ?cs ∧ action.relation_of ?P (S, S'⦇tr := s, ref := ref S' ∪ ?cs⦈)) ;; action.relation_of Skip)›*) action_of_inverse (*‹?y ∈ {p. is_CSP_process p} ⟹ action.relation_of (action_of ?y) = ?y›*) Hide_is_CSP (*‹is_CSP_process (R (λ(S, S'). ∃s. diff_tr S' S = tr_filter (s - tr S) ?cs ∧ action.relation_of ?P (S, S'⦇tr := s, ref := ref S' ∪ ?cs⦈)) ;; action.relation_of Skip)›*)) lemma mono_Hide : "mono(λ P. P \\ cs)" by (auto simp: mono_def (*‹mono ?f = (∀x y. x ≤ y ⟶ ?f x ≤ ?f y)›*) less_eq_action (*‹?P ≤ ?Q ≡ ?P ⊑ ?Q›*) ref_def (*‹?P ⊑ ?Q ≡ ∀A. (action.relation_of ?Q ⟶ action.relation_of ?P) A›*) prefix_def (*‹?xs ≤ ?ys = (∃zs. ?ys = ?xs @ zs)›*) utp_defs (*‹true ≡ λA. True› ‹false ≡ λA. False› ‹?P ∧ ?Q ≡ λA. ?P A ∧ ?Q A› ‹?P ∨ ?Q ≡ λA. ?P A ∨ ?Q A› ‹¬ ?P ≡ λA. ¬ ?P A› ‹?P ⟶ ?Q ≡ λA. ?P A ⟶ ?Q A› ‹?P ⟷ ?Q ≡ λA. ?P A = ?Q A› ‹❙∃x. ?P x ≡ λA. ∃x. ?P x A› ‹❙∀x. ?P x ≡ λA. ∀x. ?P x A› ‹?P ◃ ?b ▹ ?Q ≡ ?b ∧ ?P ∨ ¬ ?b ∧ ?Q› ‹?P ;; ?Q ≡ λr. r ∈ {p. ?P p} O {q. ?Q q}› ‹Assign ?x ?a ≡ λ(A, A'). A' = assign ?x ?a A›*) relation_of_Hide (*‹action.relation_of (?P \ ?cs) = (R (λ(S, S'). ∃s. diff_tr S' S = tr_filter (s - tr S) ?cs ∧ action.relation_of ?P (S, S'⦇tr := s, ref := ref S' ∪ ?cs⦈)) ;; action.relation_of Skip)›*) rp_defs (*‹R1 ?P ≡ λ(A, A'). ?P (A, A') ∧ tr A ≤ tr A'› ‹R2 ?P ≡ λ(A, A'). ?P (A⦇tr := []⦈, A'⦇tr := tr A' - tr A⦈) ∧ tr A ≤ tr A'› ‹Πrea ≡ λ(A, A'). ¬ ok A ∧ tr A ≤ tr A' ∨ ok A' ∧ tr A = tr A' ∧ wait A = wait A' ∧ ref A = ref A' ∧ alpha_rp.more A = alpha_rp.more A'› ‹R3 ?P ≡ Πrea ◃ wait ∘ fst ▹ ?P› ‹R ≡ R3 ∘ R2 ∘ R1› ‹spec ?b ?b' ?P ≡ λ(A, A'). ?P (A⦇wait := ?b'⦈, A'⦇ok := ?b⦈)›*)) subsection ‹Recursion› text ‹To represent the recursion operator "‹μ›" over actions, we use the universal least fix-point operator "@{const lfp}" defined in the HOL library for lattices. The operator "@{const lfp}" is inherited from the "Complete Lattice class" under some conditions. All theorems defined over this operator can be reused.› text ‹In the @{theory Circus.Circus_Actions} theory, we presented the proof that Circus actions form a complete lattice. The Knaster-Tarski Theorem (in its simplest formulation) states that any monotone function on a complete lattice has a least fixed-point. This is a consequence of the basic boundary properties of the complete lattice operations. Instantiating the complete lattice class allows one to inherit these properties with the definition of the least fixed-point for monotonic functions over Circus actions. › syntax "_MU"::"[idt, idt ⇒ ('θ, 'σ) action] ⇒ ('θ, 'σ) action" ("μ _ ∙ _") translations "_MU X P" == "CONST lfp (λ X. P)" (*<*) text‹Instead fo the following:› lemma is_action_REP_Mu: shows "is_CSP_process (relation_of (lfp P))" oops text‹... we refer to the proof of @{thm Sup_is_action} and its analogue who capture the essence of this proof at the level of the type instantiation.› text‹Monotonicity: STATUS: probably critical. Does not seem to be necessary for parameterless Circus.› lemma mono_Mu: assumes A : "mono P" and B : "⋀ X. mono (P X)" shows "mono (lfp P)" apply (subst lfp_unfold (*‹mono ?f ⟹ lfp ?f = ?f (lfp ?f)›*)) (*goals: 1. ‹mono P› 2. ‹mono (P (lfp P))› discuss goal 1*) apply ((auto simp: A (*‹mono P›*) B (*‹mono (P ?X)›*))[1]) (*discuss goal 2*) apply ((auto simp: A (*‹mono P›*) B (*‹mono (P ?X)›*))[1]) (*proven 2 subgoals*) . term Nat.Suc (*>*) end
{ "path": "afp-2025-02-12/thys/Circus/Denotational_Semantics.thy", "repo": "afp-2025-02-12", "sha": "6242356afbf5d62f50266e7010a41fb3e2975e1311a071f09c009dd702084723" }
(* Title: Tree Automata Author: Peter Lammich <peter dot lammich at uni-muenster.de> Maintainer: Peter Lammich <peter dot lammich at uni-muenster.de> *) section "Abstract Tree Automata Algorithms" theory AbsAlgo imports Ta Collections_Examples.Exploration Collections.CollectionsV1 begin no_notation fun_rel_syn (infixr "→" 60) text_raw ‹\label{sec:absalgo}› text ‹This theory defines tree automata algorithms on an abstract level, that is using non-executable datatypes and constructs like sets, set-collecting operations, etc. These algorithms are then refined to executable algorithms in Section~\ref{sec:taimpl}. › subsection ‹Word Problem› text ‹ First, a recursive version of the @{const accs}-predicate is defined. › fun r_match :: "'a set list ⇒ 'a list ⇒ bool" where "r_match [] [] ⟷ True" | "r_match (A#AS) (a#as) ⟷ a∈A ∧ r_match AS as" | "r_match _ _ ⟷ False" ― ‹@{const r_match} accepts two lists, if they have the same length and the elements in the second list are contained in the respective elements of the first list:› lemma r_match_alt: "r_match L l ⟷ length L = length l ∧ (∀i<length l. l!i ∈ L!i)" apply (induct L l rule: r_match.induct (*‹⟦?P [] []; ⋀A AS a as. ?P AS as ⟹ ?P (A # AS) (a # as); ⋀v va. ?P (v # va) []; ⋀v va. ?P [] (v # va)⟧ ⟹ ?P ?a0.0 ?a1.0›*)) (*goals: 1. ‹r_match [] [] = (length [] = length [] ∧ (∀i<length []. [] ! i ∈ [] ! i))› 2. ‹⋀A AS a as. r_match AS as = (length AS = length as ∧ (∀i<length as. as ! i ∈ AS ! i)) ⟹ r_match (A # AS) (a # as) = (length (A # AS) = length (a # as) ∧ (∀i<length (a # as). (a # as) ! i ∈ (A # AS) ! i))› 3. ‹⋀v va. r_match (v # va) [] = (length (v # va) = length [] ∧ (∀i<length []. [] ! i ∈ (v # va) ! i))› 4. ‹⋀v va. r_match [] (v # va) = (length [] = length (v # va) ∧ (∀i<length (v # va). (v # va) ! i ∈ [] ! i))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*top goal: ‹⋀(A::'a set) (AS::'a set list) (a::'a) as::'a list. r_match AS as = (length AS = length as ∧ (∀i<length as. as ! i ∈ AS ! i)) ⟹ r_match (A # AS) (a # as) = (length (A # AS) = length (a # as) ∧ (∀i<length (a # as). (a # as) ! i ∈ (A # AS) ! i))› and 2 goals remain*) apply (case_tac i) (*goals: 1. ‹⋀A AS a as i. ⟦r_match AS as; a ∈ A; length AS = length as; ∀i<length as. as ! i ∈ AS ! i; i < Suc (length as); i = 0⟧ ⟹ (a # as) ! i ∈ (A # AS) ! i› 2. ‹⋀A AS a as i nat. ⟦r_match AS as; a ∈ A; length AS = length as; ∀i<length as. as ! i ∈ AS ! i; i < Suc (length as); i = Suc nat⟧ ⟹ (a # as) ! i ∈ (A # AS) ! i› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) .<close> fun r_matchc where "r_matchc q l Qs (qr → lr qsr) ⟷ q=qr ∧ l=lr ∧ r_match Qs qsr" ― ‹recursive version of @{const accs}-predicate› fun faccs :: "('Q,'L) ta_rule set ⇒ 'L tree ⇒ 'Q set" where "faccs δ (NODE f ts) = ( let Qs = map (faccs δ) (ts) in {q. ∃r∈δ. r_matchc q f Qs r } )" lemma faccs_correct_aux: "q∈faccs δ n = accs δ n q" (is ?T1) "(map (faccs δ) ts = map (λt. { q . accs δ t q}) ts)" (is ?T2) proof (-) (*goals: 1. ‹(q ∈ faccs δ n) = accs δ n q› 2. ‹map (faccs δ) ts = map (λt. {q. accs δ t q}) ts›*) have "(∀q. q∈faccs δ n = accs δ n q) ∧ (map (faccs δ) ts = map (λt. { q . accs δ t q}) ts)" proof (induct rule: compat_tree_tree_list.induct (*‹⟦⋀x1 x2. ?P2.0 x2 ⟹ ?P1.0 (NODE x1 x2); ?P2.0 []; ⋀x1 x2. ⟦?P1.0 x1; ?P2.0 x2⟧ ⟹ ?P2.0 (x1 # x2)⟧ ⟹ ?P1.0 ?tree ∧ ?P2.0 ?tree_list›*)) (*goals: 1. ‹⋀x1 x2. map (faccs δ) x2 = map (λt. {q. accs δ t q}) x2 ⟹ ∀q. (q ∈ faccs δ (NODE x1 x2)) = accs δ (NODE x1 x2) q› 2. ‹map (faccs δ) [] = map (λt. {q. accs δ t q}) []› 3. ‹⋀x1 x2. ⟦∀q. (q ∈ faccs δ x1) = accs δ x1 q; map (faccs δ) x2 = map (λt. {q. accs δ t q}) x2⟧ ⟹ map (faccs δ) (x1 # x2) = map (λt. {q. accs δ t q}) (x1 # x2)›*) case (NODE f ts) (*‹map (faccs δ) ts = map (λt. {q. accs δ t q}) ts›*) thus "?case" (*goal: ‹∀q::'a. (q ∈ faccs (δ::('a, 'b) ta_rule set) (NODE (f::'b) (ts::'b tree list))) = accs δ (NODE f ts) q›*) apply (intro allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*) iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*)) (*goals: 1. ‹⋀q::'a::type. ⟦map (faccs (δ::('a::type, 'b::type) ta_rule set)) (ts::'b::type tree list) = map (λt::'b::type tree. {q::'a::type. accs δ t q}) ts; q ∈ faccs δ (NODE (f::'b::type) ts)⟧ ⟹ accs δ (NODE f ts) q› 2. ‹⋀q::'a::type. ⟦map (faccs (δ::('a::type, 'b::type) ta_rule set)) (ts::'b::type tree list) = map (λt::'b::type tree. {q::'a::type. accs δ t q}) ts; accs δ (NODE (f::'b::type) ts) q⟧ ⟹ q ∈ faccs δ (NODE f ts)› discuss goal 1*) apply simp (*top goal: ‹⋀q. ⟦map (faccs δ) ts = map (λt. {q. accs δ t q}) ts; q ∈ faccs δ (NODE f ts)⟧ ⟹ accs δ (NODE f ts) q› and 1 goal remains*) apply (erule bexE (*‹⟦∃x∈?A. ?P x; ⋀x. ⟦x ∈ ?A; ?P x⟧ ⟹ ?Q⟧ ⟹ ?Q›*)) (*top goal: ‹⋀q. ⟦∀x∈set ts. faccs δ x = Collect (accs δ x); ∃x∈δ. r_matchc q f (map (faccs δ) ts) x⟧ ⟹ accs δ (NODE f ts) q› and 1 goal remains*) apply (case_tac x) (*top goal: ‹⋀q x. ⟦∀x∈set ts. faccs δ x = Collect (accs δ x); x ∈ δ; r_matchc q f (map (faccs δ) ts) x⟧ ⟹ accs δ (NODE f ts) q› and 1 goal remains*) apply simp (*top goal: ‹⋀q x x1 x2 x3. ⟦∀x∈set ts. faccs δ x = Collect (accs δ x); x ∈ δ; r_matchc q f (map (faccs δ) ts) x; x = x1 → x2 x3⟧ ⟹ accs δ (NODE f ts) q› and 1 goal remains*) apply (rule accs.intros (*‹⟦?q → ?f ?qs ∈ ?δ; length ?ts = length ?qs; ⋀i. i < length ?qs ⟹ accs ?δ (?ts ! i) (?qs ! i)⟧ ⟹ accs ?δ (NODE ?f ?ts) ?q›*)) (*goals: 1. ‹⋀q x x3. ⟦∀x∈set ts. faccs δ x = Collect (accs δ x); q → f x3 ∈ δ; r_match (map (faccs δ) ts) x3; x = q → f x3⟧ ⟹ q → f ?qs13 q x x3 ∈ δ› 2. ‹⋀q x x3. ⟦∀x∈set ts. faccs δ x = Collect (accs δ x); q → f x3 ∈ δ; r_match (map (faccs δ) ts) x3; x = q → f x3⟧ ⟹ length ts = length (?qs13 q x x3)› 3. ‹⋀q x x3 i. ⟦∀x∈set ts. faccs δ x = Collect (accs δ x); q → f x3 ∈ δ; r_match (map (faccs δ) ts) x3; x = q → f x3; i < length (?qs13 q x x3)⟧ ⟹ accs δ (ts ! i) (?qs13 q x x3 ! i)› discuss goal 1*) apply assumption (*discuss goal 2*) apply ((unfold r_match_alt (*‹r_match ?L ?l = (length ?L = length ?l ∧ (∀i<length ?l. ?l ! i ∈ ?L ! i))›*))[1]) (*top goal: ‹⋀q x x3. ⟦∀x∈set ts. faccs δ x = Collect (accs δ x); q → f x3 ∈ δ; r_match (map (faccs δ) ts) x3; x = q → f x3⟧ ⟹ length ts = length x3› and 2 goals remain*) apply simp (*discuss goal 3*) apply ((unfold r_match_alt (*‹r_match ?L ?l = (length ?L = length ?l ∧ (∀i<length ?l. ?l ! i ∈ ?L ! i))›*))[1]) (*top goal: ‹⋀q x x3 i. ⟦∀x∈set ts. faccs δ x = Collect (accs δ x); q → f x3 ∈ δ; r_match (map (faccs δ) ts) x3; x = q → f x3; i < length x3⟧ ⟹ accs δ (ts ! i) (x3 ! i)› and 1 goal remains*) apply fastforce (*proven 3 subgoals*) (*discuss goal 2*) apply simp (*goal: ‹⋀q. ⟦map (faccs δ) ts = map (λt. {q. accs δ t q}) ts; accs δ (NODE f ts) q⟧ ⟹ q ∈ faccs δ (NODE f ts)›*) apply (erule accs.cases (*‹⟦accs ?a1.0 ?a2.0 ?a3.0; ⋀q f qs δ ts. ⟦?a1.0 = δ; ?a2.0 = NODE f ts; ?a3.0 = q; q → f qs ∈ δ; length ts = length qs; ⋀i. i < length qs ⟹ accs δ (ts ! i) (qs ! i)⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goal: ‹⋀q. ⟦∀x∈set ts. faccs δ x = Collect (accs δ x); accs δ (NODE f ts) q⟧ ⟹ ∃x∈δ. r_matchc q f (map (faccs δ) ts) x›*) apply auto (*goal: ‹⋀(q::'a) (qa::'a) (fa::'b) (qs::'a list) (δ'::('a, 'b) ta_rule set) ts::'b tree list. ⟦∀x::'b tree∈set (ts::'b tree list). faccs (δ::('a, 'b) ta_rule set) x = Collect (accs δ x); δ = δ'; NODE (f::'b) ts = NODE fa ts; q = qa; qa → fa qs ∈ δ'; length ts = length qs; ⋀i::nat. i < length qs ⟹ accs δ' (ts ! i) (qs ! i)⟧ ⟹ ∃x::('a, 'b) ta_rule∈δ. r_matchc q f (map (faccs δ) ts) x›*) apply (rule_tac x="qa → f qs" in bexI (*‹⟦?P ?x; ?x ∈ ?A⟧ ⟹ ∃x∈?A. ?P x›*)) (*goals: 1. ‹⋀(qa::'a) qs::'a list. ⟦∀x::'b tree∈set (ts::'b tree list). faccs (δ::('a, 'b) ta_rule set) x = Collect (accs δ x); qa → f::'b qs ∈ δ; length ts = length qs; ⋀i::nat. i < length qs ⟹ accs δ (ts ! i) (qs ! i)⟧ ⟹ r_matchc qa f (map (faccs δ) ts) qa → f qs› 2. ‹⋀(qa::'a) qs::'a list. ⟦∀x::'b tree∈set (ts::'b tree list). faccs (δ::('a, 'b) ta_rule set) x = Collect (accs δ x); qa → f::'b qs ∈ δ; length ts = length qs; ⋀i::nat. i < length qs ⟹ accs δ (ts ! i) (qs ! i)⟧ ⟹ qa → f qs ∈ δ› discuss goal 1*) apply simp (*top goal: ‹⋀qa qs. ⟦∀x∈set ts. faccs δ x = Collect (accs δ x); qa → f qs ∈ δ; length ts = length qs; ⋀i. i < length qs ⟹ accs δ (ts ! i) (qs ! i)⟧ ⟹ r_matchc qa f (map (faccs δ) ts) qa → f qs› and 1 goal remains*) apply (unfold r_match_alt (*‹r_match ?L ?l = (length ?L = length ?l ∧ (∀i<length ?l. ?l ! i ∈ ?L ! i))›*)) (*top goal: ‹⋀qa qs. ⟦∀x∈set ts. faccs δ x = Collect (accs δ x); qa → f qs ∈ δ; length ts = length qs; ⋀i. i < length qs ⟹ accs δ (ts ! i) (qs ! i)⟧ ⟹ r_match (map (faccs δ) ts) qs› and 1 goal remains*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) . qed (auto) (*solves the remaining goals: 1. ‹map (faccs (δ::('a::type, 'b::type) ta_rule set)) [] = map (λt::'b::type tree. {q::'a::type. accs δ t q}) []› 2. ‹⋀(x1::'b::type tree) x2::'b::type tree list. ⟦∀q::'a::type. (q ∈ faccs (δ::('a::type, 'b::type) ta_rule set) x1) = accs δ x1 q; map (faccs δ) x2 = map (λt::'b::type tree. {q::'a::type. accs δ t q}) x2⟧ ⟹ map (faccs δ) (x1 # x2) = map (λt::'b::type tree. {q::'a::type. accs δ t q}) (x1 # x2)›*) thus "?T1" "?T2" apply - (*goals: 1. ‹(∀q. (q ∈ faccs δ n) = accs δ n q) ∧ map (faccs δ) ts = map (λt. {q. accs δ t q}) ts ⟹ (q ∈ faccs δ n) = accs δ n q› 2. ‹(∀q. (q ∈ faccs δ n) = accs δ n q) ∧ map (faccs δ) ts = map (λt. {q. accs δ t q}) ts ⟹ map (faccs δ) ts = map (λt. {q. accs δ t q}) ts› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed theorem faccs_correct1: "q∈faccs δ n ⟹ accs δ n q" by (simp add: faccs_correct_aux (*‹(?q ∈ faccs ?δ ?n) = accs ?δ ?n ?q› ‹map (faccs ?δ) ?ts = map (λt. {q. accs ?δ t q}) ?ts›*)) theorem faccs_correct2: "accs δ n q ⟹ q∈faccs δ n" by (simp add: faccs_correct_aux (*‹((?q::?'a::type) ∈ faccs (?δ::(?'a::type, ?'b::type) ta_rule set) (?n::?'b::type tree)) = accs ?δ ?n ?q› ‹map (faccs (?δ::(?'a::type, ?'b::type) ta_rule set)) (?ts::?'b::type tree list) = map (λt::?'b::type tree. {q::?'a::type. accs ?δ t q}) ?ts›*)) lemmas faccs_correct = faccs_correct1 faccs_correct2 lemma faccs_alt: "faccs δ t = {q. accs δ t q}" by (auto intro: faccs_correct (*‹?q ∈ faccs ?δ ?n ⟹ accs ?δ ?n ?q› ‹accs ?δ ?n ?q ⟹ ?q ∈ faccs ?δ ?n›*)) subsection ‹Backward Reduction and Emptiness Check› subsubsection "Auxiliary Definitions" ― ‹Step function, that maps a set of states to those states that are reachable via one backward step.› inductive_set bacc_step :: "('Q,'L) ta_rule set ⇒ 'Q set ⇒ 'Q set" for δ Q where "⟦ r∈δ; set (rhsq r) ⊆ Q ⟧ ⟹ lhs r ∈ bacc_step δ Q" ― ‹If a set is closed under adding all states that are reachable from the set by one backward step, then this set contains all backward accessible states.› lemma b_accs_as_closed: assumes A: "bacc_step δ Q ⊆ Q" shows "b_accessible δ ⊆ Q" proof (rule subsetI (*‹(⋀x::?'a. x ∈ (?A::?'a set) ⟹ x ∈ (?B::?'a set)) ⟹ ?A ⊆ ?B›*)) (*goal: ‹⋀x. x ∈ b_accessible δ ⟹ x ∈ Q›*) fix q assume "q∈b_accessible δ" (*‹(q::'a) ∈ b_accessible (δ::('a, 'b) ta_rule set)›*) thus "q∈Q" proof (induct rule: b_accessible.induct (*‹⟦?x ∈ b_accessible ?δ; ⋀q l qs. ⟦q → l qs ∈ ?δ; ⋀x. x ∈ set qs ⟹ x ∈ b_accessible ?δ; ⋀x. x ∈ set qs ⟹ ?P x⟧ ⟹ ?P q⟧ ⟹ ?P ?x›*)) (*goal: ‹⋀(q::'a) (l::'b) qs::'a list. ⟦q → l qs ∈ (δ::('a, 'b) ta_rule set); ⋀x::'a. x ∈ set qs ⟹ x ∈ b_accessible δ; ⋀x::'a. x ∈ set qs ⟹ x ∈ (Q::'a set)⟧ ⟹ q ∈ Q›*) fix q and f and qs assume BC: "(q→f qs)∈δ" "!!x. x∈set qs ⟹ x∈b_accessible δ" "!!x. x∈set qs ⟹ x∈Q" (*‹q::'a → f::'b qs::'a list ∈ (δ::('a, 'b) ta_rule set)› ‹(?x::'a) ∈ set (qs::'a list) ⟹ ?x ∈ b_accessible (δ::('a, 'b) ta_rule set)› ‹(?x::'a) ∈ set (qs::'a list) ⟹ ?x ∈ (Q::'a set)›*) from bacc_step.intros[OF BC ( 1 )] (*‹set (rhsq q → f qs) ⊆ ?Q ⟹ lhs q → f qs ∈ bacc_step δ ?Q›*) BC(3) (*‹(?x::'a) ∈ set (qs::'a list) ⟹ ?x ∈ (Q::'a set)›*) have "q∈bacc_step δ Q" by auto with A (*‹bacc_step δ Q ⊆ Q›*) show "q∈Q" by blast qed qed subsubsection "Algorithms" text ‹ First, the basic workset algorithm is specified. Then, it is refined to contain a counter for each rule, that counts the number of undiscovered states on the RHS. For both levels of abstraction, a version that computes the backwards reduction, and a version that checks for emptiness is specified. Additionally, a version of the algorithm that computes a witness for non-emptiness is provided. Levels of abstraction: \begin{itemize} \item[‹α›] On this level, the state consists of a set of discovered states and a workset. \item[‹α'›] On this level, the state consists of a set of discovered states, a workset and a map from rules to number of undiscovered rhs states. This map can be used to make the discovery of rules that have to be considered more efficient. \end{itemize} › text_raw ‹\paragraph {‹α› - Level:}› ― ‹A state contains the set of discovered states and a workset› type_synonym ('Q,'L) br_state = "'Q set × 'Q set" ― ‹Set of states that are non-empty (accept a tree) after adding the state $q$ to the set of discovered states› definition br_dsq :: "('Q,'L) ta_rule set ⇒ 'Q ⇒ ('Q,'L) br_state ⇒ 'Q set" where "br_dsq δ q == λ(Q,W). { lhs r | r. r∈δ ∧ set (rhsq r) ⊆ (Q-(W-{q})) }" ― ‹Description of a step: One state is removed from the workset, and all new states that become non-empty due to this state are added to, both, the workset and the set of discovered states› inductive_set br_step :: "('Q,'L) ta_rule set ⇒ (('Q,'L) br_state × ('Q,'L) br_state) set" for δ where "⟦ q∈W; Q' = Q ∪ br_dsq δ q (Q,W); W' = W - {q} ∪ (br_dsq δ q (Q,W) - Q) ⟧ ⟹ ((Q,W),(Q',W'))∈br_step δ" ― ‹Termination condition for backwards reduction: The workset is empty› definition br_cond :: "('Q,'L) br_state set" where "br_cond == {(Q,W). W≠{}}" ― ‹Termination condition for emptiness check: The workset is empty or a non-empty initial state has been discovered› definition bre_cond :: "'Q set ⇒ ('Q,'L) br_state set" where "bre_cond Qi == {(Q,W). W≠{} ∧ (Qi∩Q={})}" ― ‹Set of all states that occur on the lhs of a constant-rule› definition br_iq :: "('Q,'L) ta_rule set ⇒ 'Q set" where "br_iq δ == { lhs r | r. r∈δ ∧ rhsq r = [] }" ― ‹Initial state for the iteration› definition br_initial :: "('Q,'L) ta_rule set ⇒ ('Q,'L) br_state" where "br_initial δ == (br_iq δ, br_iq δ)" ― ‹Invariant for the iteration: \begin{itemize} \item States on the workset have been discovered \item Only accessible states have been discovered \item If a state is non-empty due to a rule whose rhs-states have been discovered and processed (i.e. are in $Q-W$), then the lhs state of the rule has also been discovered. \item The set of discovered states is finite \end{itemize}› definition br_invar :: "('Q,'L) ta_rule set ⇒ ('Q,'L) br_state set" where "br_invar δ == {(Q,W). W⊆Q ∧ Q ⊆ b_accessible δ ∧ bacc_step δ (Q - W) ⊆ Q ∧ finite Q}" definition "br_algo δ == ⦇ wa_cond = br_cond, wa_step = br_step δ, wa_initial = {br_initial δ}, wa_invar = br_invar δ ⦈" definition "bre_algo Qi δ == ⦇ wa_cond = bre_cond Qi, wa_step = br_step δ, wa_initial = {br_initial δ}, wa_invar = br_invar δ ⦈" ― ‹Termination: Either a new state is added, or the workset decreases.› definition "br_termrel δ == ({(Q',Q). Q ⊂ Q' ∧ Q' ⊆ b_accessible δ}) <*lex*> finite_psubset" lemma bre_cond_imp_br_cond[intro, simp]: "bre_cond Qi ⊆ br_cond" by (auto simp add: br_cond_def (*‹br_cond ≡ {(Q, W). W ≠ {}}›*) bre_cond_def (*‹bre_cond ?Qi ≡ {(Q, W). W ≠ {} ∧ ?Qi ∩ Q = {}}›*)) lemma br_termrel_wf[simp, intro!]: "finite δ ⟹ wf (br_termrel δ)" sorryovered› lemma br_dsq_ss: assumes A: "(Q,W)∈br_invar δ" "W ≠ {}" "q∈W" shows "br_dsq δ q (Q,W) ⊆ b_accessible δ" proof (rule subsetI (*‹(⋀x::?'a. x ∈ (?A::?'a set) ⟹ x ∈ (?B::?'a set)) ⟹ ?A ⊆ ?B›*)) (*goal: ‹⋀x. x ∈ br_dsq δ q (Q, W) ⟹ x ∈ b_accessible δ›*) fix q' assume B: "q'∈br_dsq δ q (Q,W)" (*‹(q'::'a) ∈ br_dsq (δ::('a, 'b) ta_rule set) (q::'a) (Q::'a set, W::'a set)›*) then obtain r where R: "q' = lhs r" "r∈δ" and S: "set (rhsq r) ⊆ (Q-(W-{q}))" (*goal: ‹(⋀r. ⟦q' = lhs r; r ∈ δ; set (rhsq r) ⊆ Q - (W - {q})⟧ ⟹ thesis) ⟹ thesis›*) apply (unfold br_dsq_def (*‹br_dsq (?δ::(?'Q, ?'L) ta_rule set) (?q::?'Q) ≡ λ(Q::?'Q set, W::?'Q set). {lhs r |r::(?'Q, ?'L) ta_rule. r ∈ ?δ ∧ set (rhsq r) ⊆ Q - (W - {?q})}›*)) (*goal: ‹(⋀r. ⟦q' = lhs r; r ∈ δ; set (rhsq r) ⊆ Q - (W - {q})⟧ ⟹ thesis) ⟹ thesis›*) by auto note S (*‹set (rhsq (r::('a::type, 'b::type) ta_rule)) ⊆ (Q::'a::type set) - ((W::'a::type set) - {q::'a::type})›*) also (*calculation: ‹set (rhsq r) ⊆ Q - (W - {q})›*) have "(Q-(W-{q})) ⊆ b_accessible δ" using A(1,3) (*‹(Q, W) ∈ br_invar δ› ‹q ∈ W›*) by (auto simp add: br_invar_def (*‹br_invar ?δ ≡ {(Q, W). W ⊆ Q ∧ Q ⊆ b_accessible ?δ ∧ bacc_step ?δ (Q - W) ⊆ Q ∧ finite Q}›*)) finally (*calculation: ‹set (rhsq r) ⊆ b_accessible δ›*) show "q'∈b_accessible δ" using R (*‹q' = lhs r› ‹r ∈ δ›*) apply (cases r) (*goal: ‹q' ∈ b_accessible δ›*) by (auto intro: b_accessible.intros (*‹⟦?q → ?l ?qs ∈ ?δ; ⋀x. x ∈ set ?qs ⟹ x ∈ b_accessible ?δ⟧ ⟹ ?q ∈ b_accessible ?δ›*)) qed lemma br_step_in_termrel: assumes A: "Σ∈br_cond" "Σ∈br_invar δ" "(Σ,Σ')∈br_step δ" shows "(Σ', Σ)∈br_termrel δ" proof (-) (*goal: ‹(Σ', Σ) ∈ br_termrel δ›*) obtain Q and W and Q' and W' where [simp]: "Σ=(Q,W)" "Σ'=(Q',W')" (*goal: ‹(⋀(Q::'a set) (W::'a set) (Q'::'a set) W'::'a set. ⟦(Σ::'a set × 'a set) = (Q, W); (Σ'::'a set × 'a set) = (Q', W')⟧ ⟹ thesis::bool) ⟹ thesis›*) apply (cases Σ) (*goal: ‹(⋀Q W Q' W'. ⟦Σ = (Q, W); Σ' = (Q', W')⟧ ⟹ thesis) ⟹ thesis›*) apply (cases Σ') (*goal: ‹⋀a b. ⟦⋀Q W Q' W'. ⟦Σ = (Q, W); Σ' = (Q', W')⟧ ⟹ thesis; Σ = (a, b)⟧ ⟹ thesis›*) by auto obtain q where QIW: "q∈W" and ASSFMT[simp]: "Q' = Q ∪ br_dsq δ q (Q, W)" "W' = W - {q} ∪ (br_dsq δ q (Q, W) - Q)" (*goal: ‹(⋀q. ⟦q ∈ W; Q' = Q ∪ br_dsq δ q (Q, W); W' = W - {q} ∪ (br_dsq δ q (Q, W) - Q)⟧ ⟹ thesis) ⟹ thesis›*) by (auto intro: br_step.cases[OF A(3)[simplified]] (*‹(⋀(q::'a) (Wa::'a set) (Q'a::'a set) (Qa::'a set) W'a::'a set. ⟦(Q::'a set) = Qa; (W::'a set) = Wa; (Q'::'a set) = Q'a; (W'::'a set) = W'a; q ∈ Wa; Q'a = Qa ∪ br_dsq (δ::('a, 'b) ta_rule set) q (Qa, Wa); W'a = Wa - {q} ∪ (br_dsq δ q (Qa, Wa) - Qa)⟧ ⟹ ?P::bool) ⟹ ?P›*)) from A(2) (*‹Σ ∈ br_invar δ›*) have [simp]: "finite Q" by (auto simp add: br_invar_def (*‹br_invar ?δ ≡ {(Q, W). W ⊆ Q ∧ Q ⊆ b_accessible ?δ ∧ bacc_step ?δ (Q - W) ⊆ Q ∧ finite Q}›*)) from A(2)[unfolded br_invar_def] (*‹Σ ∈ {(Q, W). W ⊆ Q ∧ Q ⊆ b_accessible δ ∧ bacc_step δ (Q - W) ⊆ Q ∧ finite Q}›*) have [simp]: "finite W" by (auto simp add: finite_subset (*‹⟦?A ⊆ ?B; finite ?B⟧ ⟹ finite ?A›*)) from A(1) (*‹Σ ∈ br_cond›*) have WNE: "W≠{}" apply (unfold br_cond_def (*‹br_cond ≡ {(Q, W). W ≠ {}}›*)) (*goal: ‹W ≠ {}›*) by auto note DSQSS = br_dsq_ss[OF A ( 2 ) [ simplified ] WNE QIW] (*‹br_dsq δ q (Q, W) ⊆ b_accessible δ›*) { assume "br_dsq δ q (Q,W) - Q = {}" (*‹br_dsq (δ::('a, 'b) ta_rule set) (q::'a) (Q::'a set, W::'a set) - Q = {}›*) hence "?thesis" using QIW (*‹(q::'a) ∈ (W::'a set)›*) by (simp add: br_termrel_def (*‹br_termrel (?δ::(?'a, ?'c) ta_rule set) ≡ {(Q'::?'a set, Q::?'a set). Q ⊂ Q' ∧ Q' ⊆ b_accessible ?δ} <*lex*> finite_psubset›*) set_simps (*‹(?A::?'a set) ⊆ (?B::?'a set) ⟹ ?A - ?B = {}› ‹((?A::?'a set) - (?B::?'a set) = ?A) = (?A ∩ ?B = {})› ‹((?A::?'a set) - (?B::?'a set) ≠ ?A) = (?A ∩ ?B ≠ {})› ‹((?A::?'a set) - (?B::?'a set) ⊂ ?A) = (?A ∩ ?B ≠ {})› ‹(?A::?'a set) ⊆ (?B::?'a set) ⟹ ?A ∪ ?B = ?B› ‹(?B::?'a set) ⊆ (?A::?'a set) ⟹ ?A ∪ ?B = ?A›*)) } moreover { assume "br_dsq δ q (Q,W) - Q ≠ {}" (*‹br_dsq (δ::('a, 'b) ta_rule set) (q::'a) (Q::'a set, W::'a set) - Q ≠ {}›*) hence "Q ⊂ Q'" by auto moreover from DSQSS (*‹br_dsq (δ::('a::type, 'b::type) ta_rule set) (q::'a::type) (Q::'a::type set, W::'a::type set) ⊆ b_accessible δ›*) A(2)[unfolded br_invar_def] (*‹Σ ∈ {(Q, W). W ⊆ Q ∧ Q ⊆ b_accessible δ ∧ bacc_step δ (Q - W) ⊆ Q ∧ finite Q}›*) have "Q' ⊆ b_accessible δ" by auto ultimately have "?thesis" by (auto simp add: br_termrel_def (*‹br_termrel ?δ ≡ {(Q', Q). Q ⊂ Q' ∧ Q' ⊆ b_accessible ?δ} <*lex*> finite_psubset›*)) } ultimately show "?thesis" (*goal: ‹(Σ', Σ) ∈ br_termrel δ›*) by blast qed lemma br_invar_initial[simp]: "finite δ ⟹ (br_initial δ)∈br_invar δ" apply (auto simp add: br_initial_def (*‹br_initial ?δ ≡ (br_iq ?δ, br_iq ?δ)›*) br_invar_def (*‹br_invar ?δ ≡ {(Q, W). W ⊆ Q ∧ Q ⊆ b_accessible ?δ ∧ bacc_step ?δ (Q - W) ⊆ Q ∧ finite Q}›*) br_iq_def (*‹br_iq ?δ ≡ {lhs r |r. r ∈ ?δ ∧ rhsq r = []}›*)) (*goals: 1. ‹⋀r. ⟦finite δ; r ∈ δ; rhsq r = []⟧ ⟹ lhs r ∈ b_accessible δ› 2. ‹⋀x. ⟦finite δ; x ∈ bacc_step δ {}⟧ ⟹ ∃r. x = lhs r ∧ r ∈ δ ∧ rhsq r = []› discuss goal 1*) apply (case_tac r) (*top goal: ‹⋀r. ⟦finite δ; r ∈ δ; rhsq r = []⟧ ⟹ lhs r ∈ b_accessible δ› and 1 goal remains*) apply (fastforce intro: b_accessible.intros (*‹⟦?q::?'Q → ?l::?'L ?qs::?'Q list ∈ (?δ::(?'Q, ?'L) ta_rule set); ⋀x::?'Q. x ∈ set ?qs ⟹ x ∈ b_accessible ?δ⟧ ⟹ ?q ∈ b_accessible ?δ›*)) (*discuss goal 2*) apply (fastforce elim!: bacc_step.cases (*‹⟦?a ∈ bacc_step ?δ ?Q; ⋀r. ⟦?a = lhs r; r ∈ ?δ; set (rhsq r) ⊆ ?Q⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*proven 2 subgoals*) . lemma br_invar_step: assumes [simp]: "finite δ" assumes A: "Σ∈br_cond" "Σ∈br_invar δ" "(Σ,Σ')∈br_step δ" shows "Σ'∈br_invar δ" proof (-) (*goal: ‹Σ' ∈ br_invar δ›*) obtain Q and W and Q' and W' where SF[simp]: "Σ=(Q,W)" "Σ'=(Q',W')" (*goal: ‹(⋀Q W Q' W'. ⟦Σ = (Q, W); Σ' = (Q', W')⟧ ⟹ thesis) ⟹ thesis›*) apply (cases Σ) (*goal: ‹(⋀Q W Q' W'. ⟦Σ = (Q, W); Σ' = (Q', W')⟧ ⟹ thesis) ⟹ thesis›*) apply (cases Σ') (*goal: ‹⋀a b. ⟦⋀Q W Q' W'. ⟦Σ = (Q, W); Σ' = (Q', W')⟧ ⟹ thesis; Σ = (a, b)⟧ ⟹ thesis›*) by auto obtain q where QIW: "q∈W" and ASSFMT[simp]: "Q' = Q ∪ br_dsq δ q (Q, W)" "W' = W - {q} ∪ (br_dsq δ q (Q, W) - Q)" (*goal: ‹(⋀q::'a. ⟦q ∈ (W::'a set); (Q'::'a set) = (Q::'a set) ∪ br_dsq (δ::('a, 'b) ta_rule set) q (Q, W); (W'::'a set) = W - {q} ∪ (br_dsq δ q (Q, W) - Q)⟧ ⟹ thesis::bool) ⟹ thesis›*) by (auto intro: br_step.cases[OF A(3)[simplified]] (*‹(⋀q Wa Q'a Qa W'a. ⟦Q = Qa; W = Wa; Q' = Q'a; W' = W'a; q ∈ Wa; Q'a = Qa ∪ br_dsq δ q (Qa, Wa); W'a = Wa - {q} ∪ (br_dsq δ q (Qa, Wa) - Qa)⟧ ⟹ ?P) ⟹ ?P›*)) from A(1) (*‹(Σ::'a::type set × 'a::type set) ∈ br_cond›*) have WNE: "W≠{}" apply (unfold br_cond_def (*‹br_cond ≡ {(Q, W). W ≠ {}}›*)) (*goal: ‹W ≠ {}›*) by auto have DSQSS: "br_dsq δ q (Q,W) ⊆ b_accessible δ" using br_dsq_ss[OF A ( 2 ) [ simplified ] WNE QIW] (*‹br_dsq δ q (Q, W) ⊆ b_accessible δ›*) . show "?thesis" (*goal: ‹Σ' ∈ br_invar δ›*) apply (simp add: br_invar_def (*‹br_invar ?δ ≡ {(Q, W). W ⊆ Q ∧ Q ⊆ b_accessible ?δ ∧ bacc_step ?δ (Q - W) ⊆ Q ∧ finite Q}›*) del: ASSFMT (*‹Q' = Q ∪ br_dsq δ q (Q, W)› ‹W' = W - {q} ∪ (br_dsq δ q (Q, W) - Q)›*)) (*goal: ‹Σ' ∈ br_invar δ›*) proof (intro conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹W' ⊆ Q'› 2. ‹Q' ⊆ b_accessible δ› 3. ‹bacc_step δ (Q' - W') ⊆ Q'› 4. ‹finite Q'›*) from A(2) (*‹Σ ∈ br_invar δ›*) have "W ⊆ Q" by (simp add: br_invar_def (*‹br_invar ?δ ≡ {(Q, W). W ⊆ Q ∧ Q ⊆ b_accessible ?δ ∧ bacc_step ?δ (Q - W) ⊆ Q ∧ finite Q}›*)) thus "W' ⊆ Q'" by auto next (*goals: 1. ‹Q' ⊆ b_accessible δ› 2. ‹bacc_step δ (Q' - W') ⊆ Q'› 3. ‹finite Q'›*) from A(2) (*‹Σ ∈ br_invar δ›*) have "Q ⊆ b_accessible δ" by (simp add: br_invar_def (*‹br_invar ?δ ≡ {(Q, W). W ⊆ Q ∧ Q ⊆ b_accessible ?δ ∧ bacc_step ?δ (Q - W) ⊆ Q ∧ finite Q}›*)) with DSQSS (*‹br_dsq δ q (Q, W) ⊆ b_accessible δ›*) show "Q' ⊆ b_accessible δ" by auto next (*goals: 1. ‹bacc_step δ (Q' - W') ⊆ Q'› 2. ‹finite Q'›*) show "bacc_step δ (Q' - W') ⊆ Q'" apply (rule subsetI (*‹(⋀x. x ∈ ?A ⟹ x ∈ ?B) ⟹ ?A ⊆ ?B›*)) (*goal: ‹bacc_step (δ::('a, 'b) ta_rule set) ((Q'::'a set) - (W'::'a set)) ⊆ Q'›*) apply (erule bacc_step.cases (*‹⟦?a ∈ bacc_step ?δ ?Q; ⋀r. ⟦?a = lhs r; r ∈ ?δ; set (rhsq r) ⊆ ?Q⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goal: ‹⋀x. x ∈ bacc_step δ (Q' - W') ⟹ x ∈ Q'›*) by (auto simp add: br_dsq_def (*‹br_dsq ?δ ?q ≡ λ(Q, W). {lhs r |r. r ∈ ?δ ∧ set (rhsq r) ⊆ Q - (W - {?q})}›*)) next (*goal: ‹finite Q'›*) show "finite Q'" using A(2) (*‹(Σ::'a::type set × 'a::type set) ∈ br_invar (δ::('a::type, 'b::type) ta_rule set)›*) by (simp add: br_invar_def (*‹br_invar ?δ ≡ {(Q, W). W ⊆ Q ∧ Q ⊆ b_accessible ?δ ∧ bacc_step ?δ (Q - W) ⊆ Q ∧ finite Q}›*) br_dsq_def (*‹br_dsq ?δ ?q ≡ λ(Q, W). {lhs r |r. r ∈ ?δ ∧ set (rhsq r) ⊆ Q - (W - {?q})}›*)) qed qed lemma br_invar_final: "∀Σ. Σ∈wa_invar (br_algo δ) ∧ Σ∉wa_cond (br_algo δ) ⟶ fst Σ = b_accessible δ" apply (simp add: br_invar_def (*‹br_invar ?δ ≡ {(Q, W). W ⊆ Q ∧ Q ⊆ b_accessible ?δ ∧ bacc_step ?δ (Q - W) ⊆ Q ∧ finite Q}›*) br_cond_def (*‹br_cond ≡ {(Q, W). W ≠ {}}›*) br_algo_def (*‹br_algo ?δ ≡ ⦇wa_cond = br_cond, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*)) (*goal: ‹∀Σ. Σ ∈ wa_invar (br_algo δ) ∧ Σ ∉ wa_cond (br_algo δ) ⟶ fst Σ = b_accessible δ›*) by (auto intro: rev_subsetD[OF _ b_accs_as_closed] (*‹⟦?c ∈ b_accessible ?δ1; bacc_step ?δ1 ?B ⊆ ?B⟧ ⟹ ?c ∈ ?B›*)) (* shows "⟦(Q,W)∈br_invar δ; (Q,W)∉br_cond⟧ ⟹ Q = b_accessible δ" apply (simp add: br_invar_def br_cond_def) apply (auto intro: rev_subsetD[OF _ b_accs_as_closed]) done*) theorem br_while_algo: assumes FIN[simp]: "finite δ" shows "while_algo (br_algo δ)" apply unfold_locales (*goals: 1. ‹⋀s s'. ⟦s ∈ wa_invar (br_algo δ); s ∈ wa_cond (br_algo δ); (s, s') ∈ wa_step (br_algo δ)⟧ ⟹ s' ∈ wa_invar (br_algo δ)› 2. ‹wa_initial (br_algo δ) ⊆ wa_invar (br_algo δ)› 3. ‹wf {(s', s). s ∈ wa_invar (br_algo δ) ∧ s ∈ wa_cond (br_algo δ) ∧ (s, s') ∈ wa_step (br_algo δ)}› discuss goal 1*) apply (simp add: br_algo_def (*‹br_algo ?δ ≡ ⦇wa_cond = br_cond, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*) br_invar_step (*‹⟦finite ?δ; ?Σ ∈ br_cond; ?Σ ∈ br_invar ?δ; (?Σ, ?Σ') ∈ br_step ?δ⟧ ⟹ ?Σ' ∈ br_invar ?δ›*) br_invar_initial (*‹finite ?δ ⟹ br_initial ?δ ∈ br_invar ?δ›*) br_step_in_termrel (*‹⟦?Σ ∈ br_cond; ?Σ ∈ br_invar ?δ; (?Σ, ?Σ') ∈ br_step ?δ⟧ ⟹ (?Σ', ?Σ) ∈ br_termrel ?δ›*)) (*discuss goal 2*) apply (simp add: br_algo_def (*‹br_algo ?δ ≡ ⦇wa_cond = br_cond, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*) br_invar_step (*‹⟦finite ?δ; ?Σ ∈ br_cond; ?Σ ∈ br_invar ?δ; (?Σ, ?Σ') ∈ br_step ?δ⟧ ⟹ ?Σ' ∈ br_invar ?δ›*) br_invar_initial (*‹finite ?δ ⟹ br_initial ?δ ∈ br_invar ?δ›*) br_step_in_termrel (*‹⟦?Σ ∈ br_cond; ?Σ ∈ br_invar ?δ; (?Σ, ?Σ') ∈ br_step ?δ⟧ ⟹ (?Σ', ?Σ) ∈ br_termrel ?δ›*)) (*discuss goal 3*) apply (simp add: br_algo_def (*‹br_algo ?δ ≡ ⦇wa_cond = br_cond, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*) br_invar_step (*‹⟦finite ?δ; ?Σ ∈ br_cond; ?Σ ∈ br_invar ?δ; (?Σ, ?Σ') ∈ br_step ?δ⟧ ⟹ ?Σ' ∈ br_invar ?δ›*) br_invar_initial (*‹finite ?δ ⟹ br_initial ?δ ∈ br_invar ?δ›*) br_step_in_termrel (*‹⟦?Σ ∈ br_cond; ?Σ ∈ br_invar ?δ; (?Σ, ?Σ') ∈ br_step ?δ⟧ ⟹ (?Σ', ?Σ) ∈ br_termrel ?δ›*)) (*goal: ‹wf {(s'::'a::type set × 'a::type set, s::'a::type set × 'a::type set). s ∈ wa_invar (br_algo (δ::('a::type, 'b::type) ta_rule set)) ∧ s ∈ wa_cond (br_algo δ) ∧ (s, s') ∈ wa_step (br_algo δ)}›*) apply (rule_tac r="br_termrel δ" in wf_subset (*‹⟦wf ?r; ?p ⊆ ?r⟧ ⟹ wf ?p›*)) (*goals: 1. ‹wf (br_termrel δ)› 2. ‹{(s', s). s ∈ br_invar δ ∧ s ∈ br_cond ∧ (s, s') ∈ br_step δ} ⊆ br_termrel δ› discuss goal 1*) apply ((auto intro: br_step_in_termrel (*‹⟦?Σ ∈ br_cond; ?Σ ∈ br_invar ?δ; (?Σ, ?Σ') ∈ br_step ?δ⟧ ⟹ (?Σ', ?Σ) ∈ br_termrel ?δ›*))[1]) (*discuss goal 2*) apply ((auto intro: br_step_in_termrel (*‹⟦?Σ ∈ br_cond; ?Σ ∈ br_invar ?δ; (?Σ, ?Σ') ∈ br_step ?δ⟧ ⟹ (?Σ', ?Σ) ∈ br_termrel ?δ›*))[1]) (*proven 2 subgoals*) (*proven 3 subgoals*) . lemma bre_invar_final: "∀Σ. Σ∈wa_invar (bre_algo Qi δ) ∧ Σ∉wa_cond (bre_algo Qi δ) ⟶ ((Qi∩fst Σ={}) ⟷ (Qi ∩ b_accessible δ = {}))" apply (simp add: br_invar_def (*‹br_invar ?δ ≡ {(Q, W). W ⊆ Q ∧ Q ⊆ b_accessible ?δ ∧ bacc_step ?δ (Q - W) ⊆ Q ∧ finite Q}›*) bre_cond_def (*‹bre_cond ?Qi ≡ {(Q, W). W ≠ {} ∧ ?Qi ∩ Q = {}}›*) bre_algo_def (*‹bre_algo ?Qi ?δ ≡ ⦇wa_cond = bre_cond ?Qi, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*)) (*goal: ‹∀Σ. Σ ∈ wa_invar (bre_algo Qi δ) ∧ Σ ∉ wa_cond (bre_algo Qi δ) ⟶ (Qi ∩ fst Σ = {}) = (Qi ∩ b_accessible δ = {})›*) apply safe (*goals: 1. ‹⋀a b x. ⟦{} ⊆ a; a ⊆ b_accessible δ; bacc_step δ (a - {}) ⊆ a; finite a; Qi ∩ a = {}; x ∈ Qi; x ∈ b_accessible δ⟧ ⟹ x ∈ {}› 2. ‹⋀a b x. ⟦{} ⊆ a; a ⊆ b_accessible δ; bacc_step δ (a - {}) ⊆ a; finite a; Qi ∩ b_accessible δ = {}; x ∈ Qi; x ∈ a⟧ ⟹ x ∈ {}› 3. ‹⋀a b x xa. ⟦b ⊆ a; a ⊆ b_accessible δ; bacc_step δ (a - b) ⊆ a; finite a; x ∈ Qi; x ∈ a; x ∉ {}; Qi ∩ a = {}; xa ∈ Qi; xa ∈ b_accessible δ⟧ ⟹ xa ∈ {}› 4. ‹⋀a b x xa. ⟦b ⊆ a; a ⊆ b_accessible δ; bacc_step δ (a - b) ⊆ a; finite a; x ∈ Qi; x ∈ a; x ∉ {}; Qi ∩ b_accessible δ = {}; xa ∈ Qi; xa ∈ a⟧ ⟹ xa ∈ {}› discuss goal 1*) apply ((auto dest!: b_accs_as_closed (*‹bacc_step ?δ ?Q ⊆ ?Q ⟹ b_accessible ?δ ⊆ ?Q›*))[1]) (*discuss goal 2*) apply ((auto dest!: b_accs_as_closed (*‹bacc_step (?δ::(?'a, ?'b) ta_rule set) (?Q::?'a set) ⊆ ?Q ⟹ b_accessible ?δ ⊆ ?Q›*))[1]) (*discuss goal 3*) apply ((auto dest!: b_accs_as_closed (*‹bacc_step ?δ ?Q ⊆ ?Q ⟹ b_accessible ?δ ⊆ ?Q›*))[1]) (*discuss goal 4*) apply ((auto dest!: b_accs_as_closed (*‹bacc_step ?δ ?Q ⊆ ?Q ⟹ b_accessible ?δ ⊆ ?Q›*))[1]) (*proven 4 subgoals*) . theorem bre_while_algo: assumes FIN[simp]: "finite δ" shows "while_algo (bre_algo Qi δ)" apply unfold_locales (*goals: 1. ‹⋀(s::'a set × 'a set) s'::'a set × 'a set. ⟦s ∈ wa_invar (bre_algo (Qi::'a set) (δ::('a, 'b) ta_rule set)); s ∈ wa_cond (bre_algo Qi δ); (s, s') ∈ wa_step (bre_algo Qi δ)⟧ ⟹ s' ∈ wa_invar (bre_algo Qi δ)› 2. ‹wa_initial (bre_algo (Qi::'a set) (δ::('a, 'b) ta_rule set)) ⊆ wa_invar (bre_algo Qi δ)› 3. ‹wf {(s'::'a set × 'a set, s::'a set × 'a set). s ∈ wa_invar (bre_algo (Qi::'a set) (δ::('a, 'b) ta_rule set)) ∧ s ∈ wa_cond (bre_algo Qi δ) ∧ (s, s') ∈ wa_step (bre_algo Qi δ)}› discuss goal 1*) apply ((unfold bre_algo_def (*‹bre_algo (?Qi::?'a set) (?δ::(?'a, ?'b) ta_rule set) ≡ ⦇wa_cond = bre_cond ?Qi, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*))[1]) (*top goal: ‹⋀s s'. ⟦s ∈ wa_invar (bre_algo Qi δ); s ∈ wa_cond (bre_algo Qi δ); (s, s') ∈ wa_step (bre_algo Qi δ)⟧ ⟹ s' ∈ wa_invar (bre_algo Qi δ)› and 2 goals remain*) apply ((auto simp add: br_invar_initial (*‹finite (?δ::(?'a, ?'b) ta_rule set) ⟹ br_initial ?δ ∈ br_invar ?δ›*) br_step_in_termrel (*‹⟦(?Σ::?'a set × ?'a set) ∈ br_cond; ?Σ ∈ br_invar (?δ::(?'a, ?'b) ta_rule set); (?Σ, ?Σ'::?'a set × ?'a set) ∈ br_step ?δ⟧ ⟹ (?Σ', ?Σ) ∈ br_termrel ?δ›*) intro: br_invar_step (*‹⟦finite (?δ::(?'a, ?'b) ta_rule set); (?Σ::?'a set × ?'a set) ∈ br_cond; ?Σ ∈ br_invar ?δ; (?Σ, ?Σ'::?'a set × ?'a set) ∈ br_step ?δ⟧ ⟹ ?Σ' ∈ br_invar ?δ›*) dest: rev_subsetD[OF _ bre_cond_imp_br_cond] (*‹(?c::?'a1 set × ?'a1 set) ∈ bre_cond (?Qi1::?'a1 set) ⟹ ?c ∈ br_cond›*))[1]) (*discuss goal 2*) apply ((unfold bre_algo_def (*‹bre_algo ?Qi ?δ ≡ ⦇wa_cond = bre_cond ?Qi, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*))[1]) (*top goal: ‹wa_initial (bre_algo (Qi::'a::type set) (δ::('a::type, 'b::type) ta_rule set)) ⊆ wa_invar (bre_algo Qi δ)› and 1 goal remains*) apply ((auto simp add: br_invar_initial (*‹finite ?δ ⟹ br_initial ?δ ∈ br_invar ?δ›*) br_step_in_termrel (*‹⟦?Σ ∈ br_cond; ?Σ ∈ br_invar ?δ; (?Σ, ?Σ') ∈ br_step ?δ⟧ ⟹ (?Σ', ?Σ) ∈ br_termrel ?δ›*) intro: br_invar_step (*‹⟦finite ?δ; ?Σ ∈ br_cond; ?Σ ∈ br_invar ?δ; (?Σ, ?Σ') ∈ br_step ?δ⟧ ⟹ ?Σ' ∈ br_invar ?δ›*) dest: rev_subsetD[OF _ bre_cond_imp_br_cond] (*‹?c ∈ bre_cond ?Qi1 ⟹ ?c ∈ br_cond›*))[1]) (*discuss goal 3*) apply ((unfold bre_algo_def (*‹bre_algo (?Qi::?'a::type set) (?δ::(?'a::type, ?'b::type) ta_rule set) ≡ ⦇wa_cond = bre_cond ?Qi, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*))[1]) (*goal: ‹wf {(s', s). s ∈ wa_invar (bre_algo Qi δ) ∧ s ∈ wa_cond (bre_algo Qi δ) ∧ (s, s') ∈ wa_step (bre_algo Qi δ)}›*) apply ((auto simp add: br_invar_initial (*‹finite ?δ ⟹ br_initial ?δ ∈ br_invar ?δ›*) br_step_in_termrel (*‹⟦?Σ ∈ br_cond; ?Σ ∈ br_invar ?δ; (?Σ, ?Σ') ∈ br_step ?δ⟧ ⟹ (?Σ', ?Σ) ∈ br_termrel ?δ›*) intro: br_invar_step (*‹⟦finite ?δ; ?Σ ∈ br_cond; ?Σ ∈ br_invar ?δ; (?Σ, ?Σ') ∈ br_step ?δ⟧ ⟹ ?Σ' ∈ br_invar ?δ›*) dest: rev_subsetD[OF _ bre_cond_imp_br_cond] (*‹?c ∈ bre_cond ?Qi1 ⟹ ?c ∈ br_cond›*))[1]) (*goal: ‹wf {(s', s). s ∈ wa_invar ⦇wa_cond = bre_cond Qi, wa_step = br_step δ, wa_initial = {br_initial δ}, wa_invar = br_invar δ⦈ ∧ s ∈ wa_cond ⦇wa_cond = bre_cond Qi, wa_step = br_step δ, wa_initial = {br_initial δ}, wa_invar = br_invar δ⦈ ∧ (s, s') ∈ wa_step ⦇wa_cond = bre_cond Qi, wa_step = br_step δ, wa_initial = {br_initial δ}, wa_invar = br_invar δ⦈}›*) apply (rule_tac r="br_termrel δ" in wf_subset (*‹⟦wf ?r; ?p ⊆ ?r⟧ ⟹ wf ?p›*)) (*goals: 1. ‹wf (br_termrel (δ::('a, 'b) ta_rule set))› 2. ‹{(s'::'a set × 'a set, s::'a set × 'a set). s ∈ br_invar (δ::('a, 'b) ta_rule set) ∧ s ∈ bre_cond (Qi::'a set) ∧ (s, s') ∈ br_step δ} ⊆ br_termrel δ› discuss goal 1*) apply ((auto intro: br_step_in_termrel (*‹⟦?Σ ∈ br_cond; ?Σ ∈ br_invar ?δ; (?Σ, ?Σ') ∈ br_step ?δ⟧ ⟹ (?Σ', ?Σ) ∈ br_termrel ?δ›*) dest: rev_subsetD[OF _ bre_cond_imp_br_cond] (*‹?c ∈ bre_cond ?Qi1 ⟹ ?c ∈ br_cond›*))[1]) (*discuss goal 2*) apply ((auto intro: br_step_in_termrel (*‹⟦(?Σ::?'a set × ?'a set) ∈ br_cond; ?Σ ∈ br_invar (?δ::(?'a, ?'b) ta_rule set); (?Σ, ?Σ'::?'a set × ?'a set) ∈ br_step ?δ⟧ ⟹ (?Σ', ?Σ) ∈ br_termrel ?δ›*) dest: rev_subsetD[OF _ bre_cond_imp_br_cond] (*‹(?c::?'a1 set × ?'a1 set) ∈ bre_cond (?Qi1::?'a1 set) ⟹ ?c ∈ br_cond›*))[1]) (*proven 2 subgoals*) (*proven 3 subgoals*) . text_raw ‹\paragraph{‹α'› - Level}› text ‹ Here, an optimization is added: For each rule, the algorithm now maintains a counter that counts the number of undiscovered states on the rules RHS. Whenever a new state is discovered, this counter is decremented for all rules where the state occurs on the RHS. The LHS states of rules where the counter falls to 0 are added to the worklist. The idea is that decrementing the counter is more efficient than checking whether all states on the rule's RHS have been discovered. A similar algorithm is sketched in \<^cite>‹"tata2007"›(Exercise~1.18). › type_synonym ('Q,'L) br'_state = "'Q set × 'Q set × (('Q,'L) ta_rule ⇀ nat)" ― ‹Abstraction to @{text α}-level› definition br'_α :: "('Q,'L) br'_state ⇒ ('Q,'L) br_state" where "br'_α = (λ(Q,W,rcm). (Q,W))" definition br'_invar_add :: "('Q,'L) ta_rule set ⇒ ('Q,'L) br'_state set" where "br'_invar_add δ == {(Q,W,rcm). (∀r∈δ. rcm r = Some (card (set (rhsq r) - (Q - W)))) ∧ {lhs r | r. r∈δ ∧ the (rcm r) = 0} ⊆ Q }" definition br'_invar :: "('Q,'L) ta_rule set ⇒ ('Q,'L) br'_state set" where "br'_invar δ == br'_invar_add δ ∩ {Σ. br'_α Σ ∈ br_invar δ}" inductive_set br'_step :: "('Q,'L) ta_rule set ⇒ (('Q,'L) br'_state × ('Q,'L) br'_state) set" for δ where "⟦ q∈W; Q' = Q ∪ { lhs r | r. r∈δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1 }; W' = (W-{q}) ∪ ({ lhs r | r. r∈δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1 } - Q); !!r. r∈δ ⟹ rcm' r = ( if q ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r ) ⟧ ⟹ ((Q,W,rcm),(Q',W',rcm')) ∈ br'_step δ" definition br'_cond :: "('Q,'L) br'_state set" where "br'_cond == {(Q,W,rcm). W≠{}}" definition bre'_cond :: "'Q set ⇒ ('Q,'L) br'_state set" where "bre'_cond Qi == {(Q,W,rcm). W≠{} ∧ (Qi∩Q={})}" inductive_set br'_initial :: "('Q,'L) ta_rule set ⇒ ('Q,'L) br'_state set" for δ where "⟦ !!r. r∈δ ⟹ rcm r = Some (card (set (rhsq r))) ⟧ ⟹ (br_iq δ, br_iq δ, rcm)∈br'_initial δ" definition "br'_algo δ == ⦇ wa_cond=br'_cond, wa_step = br'_step δ, wa_initial = br'_initial δ, wa_invar = br'_invar δ ⦈" definition "bre'_algo Qi δ == ⦇ wa_cond=bre'_cond Qi, wa_step = br'_step δ, wa_initial = br'_initial δ, wa_invar = br'_invar δ ⦈" lemma br'_step_invar: assumes finite[simp]: "finite δ" assumes INV: "Σ∈br'_invar_add δ" "br'_α Σ ∈ br_invar δ" assumes STEP: "(Σ,Σ') ∈ br'_step δ" shows "Σ'∈br'_invar_add δ" proof (-) (*goal: ‹(Σ'::'a::type set × 'a::type set × (('a::type, 'b::type) ta_rule ⇒ nat option)) ∈ br'_invar_add (δ::('a::type, 'b::type) ta_rule set)›*) obtain Q and W and rcm where [simp]: "Σ=(Q,W,rcm)" (*goal: ‹(⋀(Q::'a set) (W::'a set) rcm::('a, 'b) ta_rule ⇒ nat option. (Σ::'a set × 'a set × (('a, 'b) ta_rule ⇒ nat option)) = (Q, W, rcm) ⟹ thesis::bool) ⟹ thesis›*) apply (cases Σ) (*goal: ‹(⋀Q W rcm. Σ = (Q, W, rcm) ⟹ thesis) ⟹ thesis›*) by auto obtain Q' and W' and rcm' where [simp]: "Σ'=(Q',W',rcm')" (*goal: ‹(⋀Q' W' rcm'. Σ' = (Q', W', rcm') ⟹ thesis) ⟹ thesis›*) apply (cases Σ') (*goal: ‹(⋀(Q'::'a set) (W'::'a set) rcm'::('a, 'b) ta_rule ⇒ nat option. (Σ'::'a set × 'a set × (('a, 'b) ta_rule ⇒ nat option)) = (Q', W', rcm') ⟹ thesis::bool) ⟹ thesis›*) by auto from STEP (*‹(Σ, Σ') ∈ br'_step δ›*) obtain q where STEPF: "q∈W" "Q' = Q ∪ { lhs r | r. r∈δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1 }" "W' = (W-{q}) ∪ ({ lhs r | r. r∈δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1 } - Q)" "!!r. r∈δ ⟹ rcm' r = ( if q ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r )" (*goal: ‹(⋀q. ⟦q ∈ W; Q' = Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1}; W' = W - {q} ∪ ({lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1} - Q); ⋀r. r ∈ δ ⟹ rcm' r = (if q ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r)⟧ ⟹ thesis) ⟹ thesis›*) by (auto elim: br'_step.cases (*‹⟦((?a1.0, ?a2.0, ?a3.0), ?a4.0, ?a5.0, ?a6.0) ∈ br'_step ?δ; ⋀q W Q' Q rcm W' rcm'. ⟦?a1.0 = Q; ?a2.0 = W; ?a3.0 = rcm; ?a4.0 = Q'; ?a5.0 = W'; ?a6.0 = rcm'; q ∈ W; Q' = Q ∪ {lhs r |r. r ∈ ?δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1}; W' = W - {q} ∪ ({lhs r |r. r ∈ ?δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1} - Q); ⋀r. r ∈ ?δ ⟹ rcm' r = (if q ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r)⟧ ⟹ ?P⟧ ⟹ ?P›*)) from INV[unfolded br'_invar_def br_invar_def br'_invar_add_def br'_α_def, simplified] (*‹(∀r∈δ. rcm r = Some (card (set (rhsq r) - (Q - W)))) ∧ {lhs r |r. r ∈ δ ∧ the (rcm r) = 0} ⊆ Q› ‹W ⊆ Q ∧ Q ⊆ b_accessible δ ∧ bacc_step δ (Q - W) ⊆ Q ∧ finite Q›*) have INV: "(∀r∈δ. rcm r = Some (card (set (rhsq r) - (Q - W))))" "{lhs r |r. r ∈ δ ∧ the (rcm r) = 0} ⊆ Q" "W ⊆ Q" "Q ⊆ b_accessible δ" "bacc_step δ (Q - W) ⊆ Q" "finite Q" apply - (*goals: 1. ‹⟦(∀r∈δ. rcm r = Some (card (set (rhsq r) - (Q - W)))) ∧ {lhs r |r. r ∈ δ ∧ the (rcm r) = 0} ⊆ Q; W ⊆ Q ∧ Q ⊆ b_accessible δ ∧ bacc_step δ (Q - W) ⊆ Q ∧ finite Q⟧ ⟹ ∀r∈δ. rcm r = Some (card (set (rhsq r) - (Q - W)))› 2. ‹⟦(∀r∈δ. rcm r = Some (card (set (rhsq r) - (Q - W)))) ∧ {lhs r |r. r ∈ δ ∧ the (rcm r) = 0} ⊆ Q; W ⊆ Q ∧ Q ⊆ b_accessible δ ∧ bacc_step δ (Q - W) ⊆ Q ∧ finite Q⟧ ⟹ {lhs r |r. r ∈ δ ∧ the (rcm r) = 0} ⊆ Q› 3. ‹⟦(∀r∈δ. rcm r = Some (card (set (rhsq r) - (Q - W)))) ∧ {lhs r |r. r ∈ δ ∧ the (rcm r) = 0} ⊆ Q; W ⊆ Q ∧ Q ⊆ b_accessible δ ∧ bacc_step δ (Q - W) ⊆ Q ∧ finite Q⟧ ⟹ W ⊆ Q› 4. ‹⟦(∀r∈δ. rcm r = Some (card (set (rhsq r) - (Q - W)))) ∧ {lhs r |r. r ∈ δ ∧ the (rcm r) = 0} ⊆ Q; W ⊆ Q ∧ Q ⊆ b_accessible δ ∧ bacc_step δ (Q - W) ⊆ Q ∧ finite Q⟧ ⟹ Q ⊆ b_accessible δ› 5. ‹⟦(∀r∈δ. rcm r = Some (card (set (rhsq r) - (Q - W)))) ∧ {lhs r |r. r ∈ δ ∧ the (rcm r) = 0} ⊆ Q; W ⊆ Q ∧ Q ⊆ b_accessible δ ∧ bacc_step δ (Q - W) ⊆ Q ∧ finite Q⟧ ⟹ bacc_step δ (Q - W) ⊆ Q› 6. ‹⟦(∀r∈δ. rcm r = Some (card (set (rhsq r) - (Q - W)))) ∧ {lhs r |r. r ∈ δ ∧ the (rcm r) = 0} ⊆ Q; W ⊆ Q ∧ Q ⊆ b_accessible δ ∧ bacc_step δ (Q - W) ⊆ Q ∧ finite Q⟧ ⟹ finite Q› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*proven 6 subgoals*) . { fix r assume A: "r∈δ" (*‹(r::('a, 'b) ta_rule) ∈ (δ::('a, 'b) ta_rule set)›*) with INV(1) (*‹∀r∈δ. rcm r = Some (card (set (rhsq r) - (Q - W)))›*) have RCMR: "rcm r = Some (card (set (rhsq r) - (Q - W)))" by auto have "rcm' r = Some (card (set (rhsq r) - (Q' - W')))" proof (cases "q∈set (rhsq r)") (*goals: 1. ‹q ∈ set (rhsq r) ⟹ rcm' r = Some (card (set (rhsq r) - (Q' - W')))› 2. ‹q ∉ set (rhsq r) ⟹ rcm' r = Some (card (set (rhsq r) - (Q' - W')))›*) case False (*‹q ∉ set (rhsq r)›*) with A (*‹(r::('a, 'b) ta_rule) ∈ (δ::('a, 'b) ta_rule set)›*) STEPF(4) (*‹(?r::('a::type, 'b::type) ta_rule) ∈ (δ::('a::type, 'b::type) ta_rule set) ⟹ (rcm'::('a::type, 'b::type) ta_rule ⇒ nat option) ?r = (if (q::'a::type) ∈ set (rhsq ?r) then Some (the ((rcm::('a::type, 'b::type) ta_rule ⇒ nat option) ?r) - (1::nat)) else rcm ?r)›*) have "rcm' r = rcm r" by auto moreover from STEPF (*‹(q::'a) ∈ (W::'a set)› ‹Q' = Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1}› ‹W' = W - {q} ∪ ({lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1} - Q)› ‹(?r::('a, 'b) ta_rule) ∈ (δ::('a, 'b) ta_rule set) ⟹ (rcm'::('a, 'b) ta_rule ⇒ nat option) ?r = (if (q::'a) ∈ set (rhsq ?r) then Some (the ((rcm::('a, 'b) ta_rule ⇒ nat option) ?r) - (1::nat)) else rcm ?r)›*) INV(3) (*‹W ⊆ Q›*) False (*‹q ∉ set (rhsq r)›*) have "set (rhsq r) - (Q-W) = set (rhsq r) - (Q'-W')" by auto ultimately show "?thesis" (*goal: ‹(rcm'::('a, 'b) ta_rule ⇒ nat option) (r::('a, 'b) ta_rule) = Some (card (set (rhsq r) - ((Q'::'a set) - (W'::'a set))))›*) by (simp add: RCMR (*‹rcm r = Some (card (set (rhsq r) - (Q - W)))›*)) next (*goal: ‹(q::'a::type) ∈ set (rhsq (r::('a::type, 'b::type) ta_rule)) ⟹ (rcm'::('a::type, 'b::type) ta_rule ⇒ nat option) r = Some (card (set (rhsq r) - ((Q'::'a::type set) - (W'::'a::type set))))›*) case True (*‹q ∈ set (rhsq r)›*) with A (*‹(r::('a, 'b) ta_rule) ∈ (δ::('a, 'b) ta_rule set)›*) STEPF(4) (*‹?r ∈ δ ⟹ rcm' ?r = (if q ∈ set (rhsq ?r) then Some (the (rcm ?r) - 1) else rcm ?r)›*) RCMR (*‹rcm r = Some (card (set (rhsq r) - (Q - W)))›*) have "rcm' r = Some ((card (set (rhsq r) - (Q - W))) - 1)" by simp moreover from STEPF (*‹q ∈ W› ‹Q' = Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1}› ‹W' = W - {q} ∪ ({lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1} - Q)› ‹(?r::('a, 'b) ta_rule) ∈ (δ::('a, 'b) ta_rule set) ⟹ (rcm'::('a, 'b) ta_rule ⇒ nat option) ?r = (if (q::'a) ∈ set (rhsq ?r) then Some (the ((rcm::('a, 'b) ta_rule ⇒ nat option) ?r) - (1::nat)) else rcm ?r)›*) INV(3) (*‹W ⊆ Q›*) True (*‹q ∈ set (rhsq r)›*) have "set (rhsq r) - (Q-W) = insert q (set (rhsq r) - (Q'-W'))" "q∉(set (rhsq r) - (Q'-W'))" apply - (*goals: 1. ‹⟦q ∈ W; Q' = Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1}; W' = W - {q} ∪ ({lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1} - Q); ⋀r. r ∈ δ ⟹ rcm' r = (if q ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r); W ⊆ Q; q ∈ set (rhsq r)⟧ ⟹ set (rhsq r) - (Q - W) = insert q (set (rhsq r) - (Q' - W'))› 2. ‹⟦q ∈ W; Q' = Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1}; W' = W - {q} ∪ ({lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1} - Q); ⋀r. r ∈ δ ⟹ rcm' r = (if q ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r); W ⊆ Q; q ∈ set (rhsq r)⟧ ⟹ q ∉ set (rhsq r) - (Q' - W')› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . ultimately show "?thesis" (*goal: ‹rcm' r = Some (card (set (rhsq r) - (Q' - W')))›*) by (simp add: RCMR (*‹rcm r = Some (card (set (rhsq r) - (Q - W)))›*) card_insert_disjoint' (*‹⟦finite ?A; ?x ∉ ?A⟧ ⟹ card (insert ?x ?A) - Suc 0 = card ?A›*)) qed } moreover { fix r assume A: "r∈δ" "the (rcm' r) = 0" (*‹(r::('a, 'b) ta_rule) ∈ (δ::('a, 'b) ta_rule set)› ‹the ((rcm'::('a, 'b) ta_rule ⇒ nat option) (r::('a, 'b) ta_rule)) = (0::nat)›*) have "lhs r ∈ Q'" proof (cases "q∈set (rhsq r)") (*goals: 1. ‹q ∈ set (rhsq r) ⟹ lhs r ∈ Q'› 2. ‹q ∉ set (rhsq r) ⟹ lhs r ∈ Q'›*) case True (*‹q ∈ set (rhsq r)›*) with A(1) (*‹r ∈ δ›*) STEPF(4) (*‹?r ∈ δ ⟹ rcm' ?r = (if q ∈ set (rhsq ?r) then Some (the (rcm ?r) - 1) else rcm ?r)›*) have "rcm' r = Some (the (rcm r) - 1)" by auto with A(2) (*‹the (rcm' r) = 0›*) have "the (rcm r) - 1 = 0" by auto hence "the (rcm r) ≤ 1" by auto with STEPF(2) (*‹Q' = Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1}›*) A(1) (*‹r ∈ δ›*) True (*‹q ∈ set (rhsq r)›*) show "?thesis" (*goal: ‹lhs r ∈ Q'›*) by auto next (*goal: ‹q ∉ set (rhsq r) ⟹ lhs r ∈ Q'›*) case False (*‹q ∉ set (rhsq r)›*) with A(1) (*‹r ∈ δ›*) STEPF(4) (*‹?r ∈ δ ⟹ rcm' ?r = (if q ∈ set (rhsq ?r) then Some (the (rcm ?r) - 1) else rcm ?r)›*) have "rcm' r = rcm r" by auto with A(2) (*‹the (rcm' r) = 0›*) have "the (rcm r) = 0" by auto with A(1) (*‹r ∈ δ›*) INV(2) (*‹{lhs r |r. r ∈ δ ∧ the (rcm r) = 0} ⊆ Q›*) have "lhs r ∈ Q" by auto with STEPF(2) (*‹Q' = Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1}›*) show "?thesis" (*goal: ‹lhs r ∈ Q'›*) by auto qed } ultimately show "?thesis" (*goal: ‹Σ' ∈ br'_invar_add δ›*) by (auto simp add: br'_invar_add_def (*‹br'_invar_add ?δ ≡ {(Q, W, rcm). (∀r∈?δ. rcm r = Some (card (set (rhsq r) - (Q - W)))) ∧ {lhs r |r. r ∈ ?δ ∧ the (rcm r) = 0} ⊆ Q}›*)) qed lemma br'_invar_initial: "br'_initial δ ⊆ br'_invar_add δ" apply safe (*goal: ‹br'_initial δ ⊆ br'_invar_add δ›*) apply (erule br'_initial.cases (*‹⟦(?a1.0, ?a2.0, ?a3.0) ∈ br'_initial ?δ; ⋀rcm. ⟦?a1.0 = br_iq ?δ; ?a2.0 = br_iq ?δ; ?a3.0 = rcm; ⋀r. r ∈ ?δ ⟹ rcm r = Some (card (set (rhsq r)))⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goal: ‹⋀a aa b. (a, aa, b) ∈ br'_initial δ ⟹ (a, aa, b) ∈ br'_invar_add δ›*) apply (unfold br'_invar_add_def (*‹br'_invar_add ?δ ≡ {(Q, W, rcm). (∀r∈?δ. rcm r = Some (card (set (rhsq r) - (Q - W)))) ∧ {lhs r |r. r ∈ ?δ ∧ the (rcm r) = 0} ⊆ Q}›*)) (*goal: ‹⋀a aa b rcm. ⟦a = br_iq δ; aa = br_iq δ; b = rcm; ⋀r. r ∈ δ ⟹ rcm r = Some (card (set (rhsq r)))⟧ ⟹ (a, aa, b) ∈ br'_invar_add δ›*) by (auto simp add: br_iq_def (*‹br_iq ?δ ≡ {lhs r |r. r ∈ ?δ ∧ rhsq r = []}›*)) lemma br'_rcm_aux': "⟦ (Q,W,rcm)∈br'_invar δ; q∈W ⟧ ⟹ {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} = {r∈δ. q∈set (rhsq r) ∧ set (rhsq r) ⊆ (Q - (W-{q}))}" proof (intro subsetI (*‹(⋀x::?'a::type. x ∈ (?A::?'a::type set) ⟹ x ∈ (?B::?'a::type set)) ⟹ ?A ⊆ ?B›*) equalityI (*‹⟦(?A::?'a::type set) ⊆ (?B::?'a::type set); ?B ⊆ ?A⟧ ⟹ ?A = ?B›*), goal_cases) (*goals: 1. ‹⋀x. ⟦(Q, W, rcm) ∈ br'_invar δ; q ∈ W; x ∈ {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}⟧ ⟹ x ∈ {r ∈ δ. q ∈ set (rhsq r) ∧ set (rhsq r) ⊆ Q - (W - {q})}› 2. ‹⋀x. ⟦(Q, W, rcm) ∈ br'_invar δ; q ∈ W; x ∈ {r ∈ δ. q ∈ set (rhsq r) ∧ set (rhsq r) ⊆ Q - (W - {q})}⟧ ⟹ x ∈ {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}›*) case prems: (1 r) (*‹(Q, W, rcm) ∈ br'_invar δ› ‹q ∈ W› ‹(r::('a, 'b) ta_rule) ∈ {r::('a, 'b) ta_rule ∈ δ::('a, 'b) ta_rule set. (q::'a) ∈ set (rhsq r) ∧ the ((rcm::('a, 'b) ta_rule ⇒ nat option) r) ≤ Suc (0::nat)}›*) hence B: "r∈δ" "q∈set (rhsq r)" "the (rcm r) ≤ Suc 0" apply - (*goals: 1. ‹⟦(Q, W, rcm) ∈ br'_invar δ; q ∈ W; r ∈ {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}⟧ ⟹ r ∈ δ› 2. ‹⟦(Q, W, rcm) ∈ br'_invar δ; q ∈ W; r ∈ {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}⟧ ⟹ q ∈ set (rhsq r)› 3. ‹⟦(Q, W, rcm) ∈ br'_invar δ; q ∈ W; r ∈ {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}⟧ ⟹ the (rcm r) ≤ Suc 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . from B(1,3) (*‹r ∈ δ› ‹the (rcm r) ≤ Suc 0›*) prems(1)[unfolded br'_invar_def br'_invar_add_def] (*‹(Q, W, rcm) ∈ {(Q, W, rcm). (∀r∈δ. rcm r = Some (card (set (rhsq r) - (Q - W)))) ∧ {lhs r |r. r ∈ δ ∧ the (rcm r) = 0} ⊆ Q} ∩ {Σ. br'_α Σ ∈ br_invar δ}›*) have CARD: "card (set (rhsq r) - (Q - W)) ≤ Suc 0" by auto from prems(1)[unfolded br'_invar_def br_invar_def br'_α_def] (*‹(Q, W, rcm) ∈ br'_invar_add δ ∩ {Σ. (case Σ of (Q, W, rcm) ⇒ (Q, W)) ∈ {(Q, W). W ⊆ Q ∧ Q ⊆ b_accessible δ ∧ bacc_step δ (Q - W) ⊆ Q ∧ finite Q}}›*) have WSQ: "W⊆Q" by auto have "set (rhsq r) - (Q - W) = {q}" proof (-) (*goal: ‹set (rhsq (r::('a, 'b) ta_rule)) - ((Q::'a set) - (W::'a set)) = {q::'a}›*) from B(2) (*‹q ∈ set (rhsq r)›*) prems(2) (*‹q ∈ W›*) have R1: "q∈set (rhsq r) - (Q - W)" by auto moreover { fix x assume A: "x≠q" "x∈set (rhsq r) - (Q - W)" (*‹(x::'a) ≠ (q::'a)› ‹(x::'a) ∈ set (rhsq (r::('a, 'b) ta_rule)) - ((Q::'a set) - (W::'a set))›*) with R1 (*‹(q::'a) ∈ set (rhsq (r::('a, 'b) ta_rule)) - ((Q::'a set) - (W::'a set))›*) have "{x,q} ⊆ set (rhsq r) - (Q - W)" by auto hence "card {x,q} ≤ card (set (rhsq r) - (Q - W))" by (auto simp add: card_mono (*‹⟦finite ?B; ?A ⊆ ?B⟧ ⟹ card ?A ≤ card ?B›*)) with CARD (*‹card (set (rhsq r) - (Q - W)) ≤ Suc 0›*) A(1) (*‹(x::'a) ≠ (q::'a)›*) have False by auto } ultimately show "?thesis" (*goal: ‹set (rhsq r) - (Q - W) = {q}›*) by auto qed with prems(2) (*‹q ∈ W›*) WSQ (*‹W ⊆ Q›*) have "set (rhsq r) ⊆ Q - (W - {q})" by auto thus "?case" (*goal: ‹r ∈ {r ∈ δ. q ∈ set (rhsq r) ∧ set (rhsq r) ⊆ Q - (W - {q})}›*) using B(1,2) (*‹r ∈ δ› ‹q ∈ set (rhsq r)›*) by auto next (*goal: ‹⋀x. ⟦(Q, W, rcm) ∈ br'_invar δ; q ∈ W; x ∈ {r ∈ δ. q ∈ set (rhsq r) ∧ set (rhsq r) ⊆ Q - (W - {q})}⟧ ⟹ x ∈ {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}›*) case prems: (2 r) (*‹(Q, W, rcm) ∈ br'_invar δ› ‹q ∈ W› ‹r ∈ {r ∈ δ. q ∈ set (rhsq r) ∧ set (rhsq r) ⊆ Q - (W - {q})}›*) hence B: "r∈δ" "q∈set (rhsq r)" "set (rhsq r) ⊆ Q - (W - {q})" apply - (*goals: 1. ‹⟦(Q, W, rcm) ∈ br'_invar δ; q ∈ W; r ∈ {r ∈ δ. q ∈ set (rhsq r) ∧ set (rhsq r) ⊆ Q - (W - {q})}⟧ ⟹ r ∈ δ› 2. ‹⟦(Q, W, rcm) ∈ br'_invar δ; q ∈ W; r ∈ {r ∈ δ. q ∈ set (rhsq r) ∧ set (rhsq r) ⊆ Q - (W - {q})}⟧ ⟹ q ∈ set (rhsq r)› 3. ‹⟦(Q, W, rcm) ∈ br'_invar δ; q ∈ W; r ∈ {r ∈ δ. q ∈ set (rhsq r) ∧ set (rhsq r) ⊆ Q - (W - {q})}⟧ ⟹ set (rhsq r) ⊆ Q - (W - {q})› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . with prems(1)[unfolded br'_invar_def br'_invar_add_def br'_α_def br_invar_def] (*‹(Q, W, rcm) ∈ {(Q, W, rcm). (∀r∈δ. rcm r = Some (card (set (rhsq r) - (Q - W)))) ∧ {lhs r |r. r ∈ δ ∧ the (rcm r) = 0} ⊆ Q} ∩ {Σ. (case Σ of (Q, W, rcm) ⇒ (Q, W)) ∈ {(Q, W). W ⊆ Q ∧ Q ⊆ b_accessible δ ∧ bacc_step δ (Q - W) ⊆ Q ∧ finite Q}}›*) have IC: "W⊆Q" "the (rcm r) = card (set (rhsq r) - (Q - W))" apply - (*goals: 1. ‹⟦(Q, W, rcm) ∈ {(Q, W, rcm). (∀r∈δ. rcm r = Some (card (set (rhsq r) - (Q - W)))) ∧ {lhs r |r. r ∈ δ ∧ the (rcm r) = 0} ⊆ Q} ∩ {Σ. (case Σ of (Q, W, rcm) ⇒ (Q, W)) ∈ {(Q, W). W ⊆ Q ∧ Q ⊆ b_accessible δ ∧ bacc_step δ (Q - W) ⊆ Q ∧ finite Q}}; r ∈ δ; q ∈ set (rhsq r); set (rhsq r) ⊆ Q - (W - {q})⟧ ⟹ W ⊆ Q› 2. ‹⟦(Q, W, rcm) ∈ {(Q, W, rcm). (∀r∈δ. rcm r = Some (card (set (rhsq r) - (Q - W)))) ∧ {lhs r |r. r ∈ δ ∧ the (rcm r) = 0} ⊆ Q} ∩ {Σ. (case Σ of (Q, W, rcm) ⇒ (Q, W)) ∈ {(Q, W). W ⊆ Q ∧ Q ⊆ b_accessible δ ∧ bacc_step δ (Q - W) ⊆ Q ∧ finite Q}}; r ∈ δ; q ∈ set (rhsq r); set (rhsq r) ⊆ Q - (W - {q})⟧ ⟹ the (rcm r) = card (set (rhsq r) - (Q - W))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have "set (rhsq r) - (Q - W) ⊆ {q}" using B(2,3) (*‹q ∈ set (rhsq r)› ‹set (rhsq (r::('a::type, 'b::type) ta_rule)) ⊆ (Q::'a::type set) - ((W::'a::type set) - {q::'a::type})›*) IC(1) (*‹W ⊆ Q›*) by auto from card_mono[OF _ this] (*‹finite {q} ⟹ card (set (rhsq r) - (Q - W)) ≤ card {q}›*) have "the (rcm r) ≤ Suc 0" by (simp add: IC( (*‹the (rcm r) = card (set (rhsq r) - (Q - W))›*) 2)) with B(1,2) (*‹r ∈ δ› ‹q ∈ set (rhsq r)›*) show "?case" (*goal: ‹r ∈ {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}›*) by auto qed lemma br'_rcm_aux: assumes A: "(Q,W,rcm)∈br'_invar δ" "q∈W" shows "{lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} = {lhs r | r. r∈δ ∧ q∈set (rhsq r) ∧ set (rhsq r) ⊆ (Q - (W-{q}))}" proof (-) (*goal: ‹{lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} = {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ set (rhsq r) ⊆ Q - (W - {q})}›*) have "{lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} = lhs ` {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}" by auto also (*calculation: ‹{lhs r |r::('a, 'b) ta_rule. r ∈ (δ::('a, 'b) ta_rule set) ∧ (q::'a) ∈ set (rhsq r) ∧ the ((rcm::('a, 'b) ta_rule ⇒ nat option) r) ≤ Suc (0::nat)} = lhs ` {r::('a, 'b) ta_rule ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc (0::nat)}›*) from br'_rcm_aux'[OF A] (*‹{r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} = {r ∈ δ. q ∈ set (rhsq r) ∧ set (rhsq r) ⊆ Q - (W - {q})}›*) have "… = lhs ` {r ∈ δ. q ∈ set (rhsq r) ∧ set (rhsq r) ⊆ Q - (W - {q})}" by simp also (*calculation: ‹{lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} = lhs ` {r ∈ δ. q ∈ set (rhsq r) ∧ set (rhsq r) ⊆ Q - (W - {q})}›*) have "… = {lhs r | r. r∈δ ∧ q∈set (rhsq r) ∧ set (rhsq r) ⊆ (Q - (W-{q}))}" by auto finally (*calculation: ‹{lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} = {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ set (rhsq r) ⊆ Q - (W - {q})}›*) show "?thesis" (*goal: ‹{lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} = {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ set (rhsq r) ⊆ Q - (W - {q})}›*) . qed lemma br'_invar_QcD: "(Q,W,rcm) ∈ br'_invar δ ⟹ {lhs r | r. r∈δ ∧ set (rhsq r) ⊆ (Q-W)} ⊆ Q" proof (safe) (*goal: ‹⋀x r. ⟦(Q, W, rcm) ∈ br'_invar δ; r ∈ δ; set (rhsq r) ⊆ Q - W⟧ ⟹ lhs r ∈ Q›*) fix r assume A: "(Q,W,rcm)∈br'_invar δ" "r∈δ" "set (rhsq r) ⊆ Q - W" (*‹(Q::'a set, W::'a set, rcm::('a, 'b) ta_rule ⇒ nat option) ∈ br'_invar (δ::('a, 'b) ta_rule set)› ‹(r::('a, 'b) ta_rule) ∈ (δ::('a, 'b) ta_rule set)› ‹set (rhsq (r::('a, 'b) ta_rule)) ⊆ (Q::'a set) - (W::'a set)›*) from A(1)[unfolded br'_invar_def br'_invar_add_def br'_α_def br_invar_def, simplified] (*‹(∀r∈δ. rcm r = Some (card (set (rhsq r) - (Q - W)))) ∧ {lhs r |r. r ∈ δ ∧ the (rcm r) = 0} ⊆ Q ∧ W ⊆ Q ∧ Q ⊆ b_accessible δ ∧ bacc_step δ (Q - W) ⊆ Q ∧ finite Q›*) have IC: "W ⊆ Q" "finite Q" "(∀r∈δ. rcm r = Some (card (set (rhsq r) - (Q - W))))" "{lhs r |r. r ∈ δ ∧ the (rcm r) = 0} ⊆ Q" apply - (*goals: 1. ‹(∀r∈δ. rcm r = Some (card (set (rhsq r) - (Q - W)))) ∧ {lhs r |r. r ∈ δ ∧ the (rcm r) = 0} ⊆ Q ∧ W ⊆ Q ∧ Q ⊆ b_accessible δ ∧ bacc_step δ (Q - W) ⊆ Q ∧ finite Q ⟹ W ⊆ Q› 2. ‹(∀r∈δ. rcm r = Some (card (set (rhsq r) - (Q - W)))) ∧ {lhs r |r. r ∈ δ ∧ the (rcm r) = 0} ⊆ Q ∧ W ⊆ Q ∧ Q ⊆ b_accessible δ ∧ bacc_step δ (Q - W) ⊆ Q ∧ finite Q ⟹ finite Q› 3. ‹(∀r∈δ. rcm r = Some (card (set (rhsq r) - (Q - W)))) ∧ {lhs r |r. r ∈ δ ∧ the (rcm r) = 0} ⊆ Q ∧ W ⊆ Q ∧ Q ⊆ b_accessible δ ∧ bacc_step δ (Q - W) ⊆ Q ∧ finite Q ⟹ ∀r∈δ. rcm r = Some (card (set (rhsq r) - (Q - W)))› 4. ‹(∀r∈δ. rcm r = Some (card (set (rhsq r) - (Q - W)))) ∧ {lhs r |r. r ∈ δ ∧ the (rcm r) = 0} ⊆ Q ∧ W ⊆ Q ∧ Q ⊆ b_accessible δ ∧ bacc_step δ (Q - W) ⊆ Q ∧ finite Q ⟹ {lhs r |r. r ∈ δ ∧ the (rcm r) = 0} ⊆ Q› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . from IC(3) (*‹∀r∈δ. rcm r = Some (card (set (rhsq r) - (Q - W)))›*) A(2,3) (*‹r ∈ δ› ‹set (rhsq r) ⊆ Q - W›*) have "the (rcm r) = 0" by auto with IC(4) (*‹{lhs r |r. r ∈ δ ∧ the (rcm r) = 0} ⊆ Q›*) A(2) (*‹r ∈ δ›*) show "lhs r ∈ Q" by auto qed lemma br'_rcm_aux2: "⟦ (Q,W,rcm)∈br'_invar δ; q∈W ⟧ ⟹ Q ∪ br_dsq δ q (Q,W) = Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}" apply (simp only: br'_rcm_aux (*‹⟦(?Q, ?W, ?rcm) ∈ br'_invar ?δ; ?q ∈ ?W⟧ ⟹ {lhs r |r. r ∈ ?δ ∧ ?q ∈ set (rhsq r) ∧ the (?rcm r) ≤ Suc 0} = {lhs r |r. r ∈ ?δ ∧ ?q ∈ set (rhsq r) ∧ set (rhsq r) ⊆ ?Q - (?W - {?q})}›*)) (*goal: ‹⟦(Q::'a set, W::'a set, rcm::('a, 'b) ta_rule ⇒ nat option) ∈ br'_invar (δ::('a, 'b) ta_rule set); (q::'a) ∈ W⟧ ⟹ Q ∪ br_dsq δ q (Q, W) = Q ∪ {lhs r |r::('a, 'b) ta_rule. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc (0::nat)}›*) apply (unfold br_dsq_def (*‹br_dsq ?δ ?q ≡ λ(Q, W). {lhs r |r. r ∈ ?δ ∧ set (rhsq r) ⊆ Q - (W - {?q})}›*)) (*goal: ‹⟦(Q::'a set, W::'a set, rcm::('a, 'b) ta_rule ⇒ nat option) ∈ br'_invar (δ::('a, 'b) ta_rule set); (q::'a) ∈ W⟧ ⟹ Q ∪ br_dsq δ q (Q, W) = Q ∪ {lhs r |r::('a, 'b) ta_rule. r ∈ δ ∧ q ∈ set (rhsq r) ∧ set (rhsq r) ⊆ Q - (W - {q})}›*) apply simp (*goal: ‹⟦(Q, W, rcm) ∈ br'_invar δ; q ∈ W⟧ ⟹ Q ∪ (case (Q, W) of (Q, W) ⇒ {lhs r |r. r ∈ δ ∧ set (rhsq r) ⊆ Q - (W - {q})}) = Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ set (rhsq r) ⊆ Q - (W - {q})}›*) apply (frule br'_invar_QcD (*‹(?Q, ?W, ?rcm) ∈ br'_invar ?δ ⟹ {lhs r |r. r ∈ ?δ ∧ set (rhsq r) ⊆ ?Q - ?W} ⊆ ?Q›*)) (*goal: ‹⟦(Q::'a set, W::'a set, rcm::('a, 'b) ta_rule ⇒ nat option) ∈ br'_invar (δ::('a, 'b) ta_rule set); (q::'a) ∈ W⟧ ⟹ Q ∪ {lhs r |r::('a, 'b) ta_rule. r ∈ δ ∧ set (rhsq r) ⊆ Q - (W - {q})} = Q ∪ {lhs r |r::('a, 'b) ta_rule. r ∈ δ ∧ q ∈ set (rhsq r) ∧ set (rhsq r) ⊆ Q - (W - {q})}›*) by auto lemma br'_rcm_aux3: "⟦ (Q,W,rcm)∈br'_invar δ; q∈W ⟧ ⟹ br_dsq δ q (Q,W) - Q = {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - Q" apply (simp only: br'_rcm_aux (*‹⟦(?Q, ?W, ?rcm) ∈ br'_invar ?δ; ?q ∈ ?W⟧ ⟹ {lhs r |r. r ∈ ?δ ∧ ?q ∈ set (rhsq r) ∧ the (?rcm r) ≤ Suc 0} = {lhs r |r. r ∈ ?δ ∧ ?q ∈ set (rhsq r) ∧ set (rhsq r) ⊆ ?Q - (?W - {?q})}›*)) (*goal: ‹⟦(Q, W, rcm) ∈ br'_invar δ; q ∈ W⟧ ⟹ br_dsq δ q (Q, W) - Q = {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - Q›*) apply (unfold br_dsq_def (*‹br_dsq (?δ::(?'Q, ?'L) ta_rule set) (?q::?'Q) ≡ λ(Q::?'Q set, W::?'Q set). {lhs r |r::(?'Q, ?'L) ta_rule. r ∈ ?δ ∧ set (rhsq r) ⊆ Q - (W - {?q})}›*)) (*goal: ‹⟦(Q, W, rcm) ∈ br'_invar δ; q ∈ W⟧ ⟹ br_dsq δ q (Q, W) - Q = {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ set (rhsq r) ⊆ Q - (W - {q})} - Q›*) apply simp (*goal: ‹⟦(Q, W, rcm) ∈ br'_invar δ; q ∈ W⟧ ⟹ (case (Q, W) of (Q, W) ⇒ {lhs r |r. r ∈ δ ∧ set (rhsq r) ⊆ Q - (W - {q})}) - Q = {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ set (rhsq r) ⊆ Q - (W - {q})} - Q›*) apply (frule br'_invar_QcD (*‹(?Q::?'a::type set, ?W::?'a::type set, ?rcm::(?'a::type, ?'b::type) ta_rule ⇒ nat option) ∈ br'_invar (?δ::(?'a::type, ?'b::type) ta_rule set) ⟹ {lhs r |r::(?'a::type, ?'b::type) ta_rule. r ∈ ?δ ∧ set (rhsq r) ⊆ ?Q - ?W} ⊆ ?Q›*)) (*goal: ‹⟦(Q::'a::type set, W::'a::type set, rcm::('a::type, 'b::type) ta_rule ⇒ nat option) ∈ br'_invar (δ::('a::type, 'b::type) ta_rule set); (q::'a::type) ∈ W⟧ ⟹ {lhs r |r::('a::type, 'b::type) ta_rule. r ∈ δ ∧ set (rhsq r) ⊆ Q - (W - {q})} - Q = {lhs r |r::('a::type, 'b::type) ta_rule. r ∈ δ ∧ q ∈ set (rhsq r) ∧ set (rhsq r) ⊆ Q - (W - {q})} - Q›*) by auto lemma br'_step_abs: "⟦ Σ∈br'_invar δ; (Σ,Σ') ∈ br'_step δ ⟧ ⟹ (br'_α Σ, br'_α Σ')∈br_step δ" apply (cases Σ) (*goal: ‹⟦Σ ∈ br'_invar δ; (Σ, Σ') ∈ br'_step δ⟧ ⟹ (br'_α Σ, br'_α Σ') ∈ br_step δ›*) apply (cases Σ') (*goal: ‹⋀a b c. ⟦Σ ∈ br'_invar δ; (Σ, Σ') ∈ br'_step δ; Σ = (a, b, c)⟧ ⟹ (br'_α Σ, br'_α Σ') ∈ br_step δ›*) apply simp (*goal: ‹⋀a b c aa ba ca. ⟦Σ ∈ br'_invar δ; (Σ, Σ') ∈ br'_step δ; Σ = (a, b, c); Σ' = (aa, ba, ca)⟧ ⟹ (br'_α Σ, br'_α Σ') ∈ br_step δ›*) apply (erule br'_step.cases (*‹⟦((?a1.0, ?a2.0, ?a3.0), ?a4.0, ?a5.0, ?a6.0) ∈ br'_step ?δ; ⋀q W Q' Q rcm W' rcm'. ⟦?a1.0 = Q; ?a2.0 = W; ?a3.0 = rcm; ?a4.0 = Q'; ?a5.0 = W'; ?a6.0 = rcm'; q ∈ W; Q' = Q ∪ {lhs r |r. r ∈ ?δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1}; W' = W - {q} ∪ ({lhs r |r. r ∈ ?δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1} - Q); ⋀r. r ∈ ?δ ⟹ rcm' r = (if q ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r)⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goal: ‹⋀a b c aa ba ca. ⟦(a, b, c) ∈ br'_invar δ; ((a, b, c), aa, ba, ca) ∈ br'_step δ; Σ = (a, b, c); Σ' = (aa, ba, ca)⟧ ⟹ (br'_α (a, b, c), br'_α (aa, ba, ca)) ∈ br_step δ›*) apply (simp add: br'_α_def (*‹br'_α = (λ(Q::?'Q set, W::?'Q set, rcm::(?'Q, ?'L) ta_rule ⇒ nat option). (Q, W))›*)) (*goal: ‹⋀a b c aa ba ca q W Q' Q rcm W' rcm'. ⟦(a, b, c) ∈ br'_invar δ; Σ = (a, b, c); Σ' = (aa, ba, ca); a = Q; b = W; c = rcm; aa = Q'; ba = W'; ca = rcm'; q ∈ W; Q' = Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1}; W' = W - {q} ∪ ({lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1} - Q); ⋀r. r ∈ δ ⟹ rcm' r = (if q ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r)⟧ ⟹ (br'_α (a, b, c), br'_α (aa, ba, ca)) ∈ br_step δ›*) apply (rule_tac q=q in br_step.intros (*‹⟦?q ∈ ?W; ?Q' = ?Q ∪ br_dsq ?δ ?q (?Q, ?W); ?W' = ?W - {?q} ∪ (br_dsq ?δ ?q (?Q, ?W) - ?Q)⟧ ⟹ ((?Q, ?W), ?Q', ?W') ∈ br_step ?δ›*)) (*goals: 1. ‹⋀a b c aa ba ca q W Q' Q rcm W' rcm'. ⟦(Q, W, rcm) ∈ br'_invar δ; Σ = (Q, W, rcm); Σ' = (Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}, W - {q} ∪ ({lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - Q), rcm'); a = Q; b = W; c = rcm; aa = Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}; ba = W - {q} ∪ ({lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - Q); ca = rcm'; q ∈ W; Q' = Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}; W' = W - {q} ∪ ({lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - Q); ⋀r. r ∈ δ ⟹ rcm' r = (if q ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r)⟧ ⟹ q ∈ W› 2. ‹⋀a b c aa ba ca q W Q' Q rcm W' rcm'. ⟦(Q, W, rcm) ∈ br'_invar δ; Σ = (Q, W, rcm); Σ' = (Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}, W - {q} ∪ ({lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - Q), rcm'); a = Q; b = W; c = rcm; aa = Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}; ba = W - {q} ∪ ({lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - Q); ca = rcm'; q ∈ W; Q' = Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}; W' = W - {q} ∪ ({lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - Q); ⋀r. r ∈ δ ⟹ rcm' r = (if q ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r)⟧ ⟹ Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} = Q ∪ br_dsq δ q (Q, W)› 3. ‹⋀a b c aa ba ca q W Q' Q rcm W' rcm'. ⟦(Q, W, rcm) ∈ br'_invar δ; Σ = (Q, W, rcm); Σ' = (Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}, W - {q} ∪ ({lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - Q), rcm'); a = Q; b = W; c = rcm; aa = Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}; ba = W - {q} ∪ ({lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - Q); ca = rcm'; q ∈ W; Q' = Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}; W' = W - {q} ∪ ({lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - Q); ⋀r. r ∈ δ ⟹ rcm' r = (if q ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r)⟧ ⟹ W - {q} ∪ ({lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - Q) = W - {q} ∪ (br_dsq δ q (Q, W) - Q)› discuss goal 1*) apply simp (*discuss goal 2*) apply (simp only: br'_rcm_aux2 (*‹⟦(?Q, ?W, ?rcm) ∈ br'_invar ?δ; ?q ∈ ?W⟧ ⟹ ?Q ∪ br_dsq ?δ ?q (?Q, ?W) = ?Q ∪ {lhs r |r. r ∈ ?δ ∧ ?q ∈ set (rhsq r) ∧ the (?rcm r) ≤ Suc 0}›*)) (*discuss goal 3*) apply (simp only: br'_rcm_aux3 (*‹⟦(?Q, ?W, ?rcm) ∈ br'_invar ?δ; ?q ∈ ?W⟧ ⟹ br_dsq ?δ ?q (?Q, ?W) - ?Q = {lhs r |r. r ∈ ?δ ∧ ?q ∈ set (rhsq r) ∧ the (?rcm r) ≤ Suc 0} - ?Q›*)) (*proven 3 subgoals*) . lemma br'_initial_abs: "br'_α`(br'_initial δ) = {br_initial δ}" by (force simp add: br_initial_def (*‹br_initial ?δ ≡ (br_iq ?δ, br_iq ?δ)›*) br'_α_def (*‹br'_α = (λ(Q, W, rcm). (Q, W))›*) elim: br'_initial.cases (*‹⟦(?a1.0, ?a2.0, ?a3.0) ∈ br'_initial ?δ; ⋀rcm. ⟦?a1.0 = br_iq ?δ; ?a2.0 = br_iq ?δ; ?a3.0 = rcm; ⋀r. r ∈ ?δ ⟹ rcm r = Some (card (set (rhsq r)))⟧ ⟹ ?P⟧ ⟹ ?P›*) intro: br'_initial.intros (*‹(⋀r. r ∈ ?δ ⟹ ?rcm r = Some (card (set (rhsq r)))) ⟹ (br_iq ?δ, br_iq ?δ, ?rcm) ∈ br'_initial ?δ›*)) lemma br'_cond_abs: "Σ∈br'_cond ⟷ (br'_α Σ) ∈ br_cond" apply (cases Σ) (*goal: ‹(Σ ∈ br'_cond) = (br'_α Σ ∈ br_cond)›*) by (simp add: br'_cond_def (*‹br'_cond ≡ {(Q, W, rcm). W ≠ {}}›*) br_cond_def (*‹br_cond ≡ {(Q, W). W ≠ {}}›*) br'_α_def (*‹br'_α = (λ(Q, W, rcm). (Q, W))›*) image_Collect (*‹?f ` {x. ?P x} = {?f x |x. ?P x}›*) br'_algo_def (*‹br'_algo ?δ ≡ ⦇wa_cond = br'_cond, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*) br_algo_def (*‹br_algo ?δ ≡ ⦇wa_cond = br_cond, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*)) lemma bre'_cond_abs: "Σ∈bre'_cond Qi ⟷ (br'_α Σ)∈bre_cond Qi" apply (cases Σ) (*goal: ‹(Σ ∈ bre'_cond Qi) = (br'_α Σ ∈ bre_cond Qi)›*) by (simp add: bre'_cond_def (*‹bre'_cond ?Qi ≡ {(Q, W, rcm). W ≠ {} ∧ ?Qi ∩ Q = {}}›*) bre_cond_def (*‹bre_cond ?Qi ≡ {(Q, W). W ≠ {} ∧ ?Qi ∩ Q = {}}›*) br'_α_def (*‹br'_α = (λ(Q, W, rcm). (Q, W))›*) image_Collect (*‹?f ` {x. ?P x} = {?f x |x. ?P x}›*) bre'_algo_def (*‹bre'_algo ?Qi ?δ ≡ ⦇wa_cond = bre'_cond ?Qi, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*) bre_algo_def (*‹bre_algo ?Qi ?δ ≡ ⦇wa_cond = bre_cond ?Qi, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*)) lemma br'_invar_abs: "br'_α`br'_invar δ ⊆ br_invar δ" by (auto simp add: br'_invar_def (*‹br'_invar ?δ ≡ br'_invar_add ?δ ∩ {Σ. br'_α Σ ∈ br_invar ?δ}›*)) theorem br'_pref_br: "wa_precise_refine (br'_algo δ) (br_algo δ) br'_α" apply unfold_locales (*goals: 1. ‹⋀s. ⟦s ∈ wa_invar (br'_algo δ); s ∈ wa_cond (br'_algo δ)⟧ ⟹ br'_α s ∈ wa_cond (br_algo δ)› 2. ‹⋀s s'. ⟦s ∈ wa_invar (br'_algo δ); s ∈ wa_cond (br'_algo δ); (s, s') ∈ wa_step (br'_algo δ)⟧ ⟹ (br'_α s, br'_α s') ∈ wa_step (br_algo δ)› 3. ‹br'_α ` wa_initial (br'_algo δ) ⊆ wa_initial (br_algo δ)› 4. ‹br'_α ` wa_invar (br'_algo δ) ⊆ wa_invar (br_algo δ)› 5. ‹∀s. s ∈ wa_invar (br'_algo δ) ∧ br'_α s ∈ wa_cond (br_algo δ) ⟶ s ∈ wa_cond (br'_algo δ)› discuss goal 1*) apply (simp add: br'_algo_def (*‹br'_algo ?δ ≡ ⦇wa_cond = br'_cond, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*) br_algo_def (*‹br_algo ?δ ≡ ⦇wa_cond = br_cond, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*)) (*top goal: ‹⋀s::'a set × 'a set × (('a, 'b) ta_rule ⇒ nat option). ⟦s ∈ wa_invar (br'_algo (δ::('a, 'b) ta_rule set)); s ∈ wa_cond (br'_algo δ)⟧ ⟹ br'_α s ∈ wa_cond (br_algo δ)› and 4 goals remain*) apply (simp add: br'_cond_abs (*‹(?Σ ∈ br'_cond) = (br'_α ?Σ ∈ br_cond)›*) br'_step_abs (*‹⟦?Σ ∈ br'_invar ?δ; (?Σ, ?Σ') ∈ br'_step ?δ⟧ ⟹ (br'_α ?Σ, br'_α ?Σ') ∈ br_step ?δ›*) br'_invar_abs (*‹br'_α ` br'_invar ?δ ⊆ br_invar ?δ›*) br'_initial_abs (*‹br'_α ` br'_initial ?δ = {br_initial ?δ}›*)) (*discuss goal 2*) apply (simp add: br'_algo_def (*‹br'_algo ?δ ≡ ⦇wa_cond = br'_cond, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*) br_algo_def (*‹br_algo ?δ ≡ ⦇wa_cond = br_cond, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*)) (*top goal: ‹⋀s s'. ⟦s ∈ wa_invar (br'_algo δ); s ∈ wa_cond (br'_algo δ); (s, s') ∈ wa_step (br'_algo δ)⟧ ⟹ (br'_α s, br'_α s') ∈ wa_step (br_algo δ)› and 3 goals remain*) apply (simp add: br'_cond_abs (*‹(?Σ ∈ br'_cond) = (br'_α ?Σ ∈ br_cond)›*) br'_step_abs (*‹⟦?Σ ∈ br'_invar ?δ; (?Σ, ?Σ') ∈ br'_step ?δ⟧ ⟹ (br'_α ?Σ, br'_α ?Σ') ∈ br_step ?δ›*) br'_invar_abs (*‹br'_α ` br'_invar ?δ ⊆ br_invar ?δ›*) br'_initial_abs (*‹br'_α ` br'_initial ?δ = {br_initial ?δ}›*)) (*discuss goal 3*) apply (simp add: br'_algo_def (*‹br'_algo (?δ::(?'a, ?'b) ta_rule set) ≡ ⦇wa_cond = br'_cond, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*) br_algo_def (*‹br_algo (?δ::(?'a, ?'b) ta_rule set) ≡ ⦇wa_cond = br_cond, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*)) (*top goal: ‹br'_α ` wa_initial (br'_algo δ) ⊆ wa_initial (br_algo δ)› and 2 goals remain*) apply (simp add: br'_cond_abs (*‹(?Σ ∈ br'_cond) = (br'_α ?Σ ∈ br_cond)›*) br'_step_abs (*‹⟦?Σ ∈ br'_invar ?δ; (?Σ, ?Σ') ∈ br'_step ?δ⟧ ⟹ (br'_α ?Σ, br'_α ?Σ') ∈ br_step ?δ›*) br'_invar_abs (*‹br'_α ` br'_invar ?δ ⊆ br_invar ?δ›*) br'_initial_abs (*‹br'_α ` br'_initial ?δ = {br_initial ?δ}›*)) (*discuss goal 4*) apply (simp add: br'_algo_def (*‹br'_algo (?δ::(?'a, ?'b) ta_rule set) ≡ ⦇wa_cond = br'_cond, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*) br_algo_def (*‹br_algo (?δ::(?'a, ?'b) ta_rule set) ≡ ⦇wa_cond = br_cond, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*)) (*top goal: ‹br'_α ` wa_invar (br'_algo δ) ⊆ wa_invar (br_algo δ)› and 1 goal remains*) apply (simp add: br'_cond_abs (*‹(?Σ ∈ br'_cond) = (br'_α ?Σ ∈ br_cond)›*) br'_step_abs (*‹⟦?Σ ∈ br'_invar ?δ; (?Σ, ?Σ') ∈ br'_step ?δ⟧ ⟹ (br'_α ?Σ, br'_α ?Σ') ∈ br_step ?δ›*) br'_invar_abs (*‹br'_α ` br'_invar ?δ ⊆ br_invar ?δ›*) br'_initial_abs (*‹br'_α ` br'_initial ?δ = {br_initial ?δ}›*)) (*discuss goal 5*) apply (simp add: br'_algo_def (*‹br'_algo (?δ::(?'a::type, ?'b::type) ta_rule set) ≡ ⦇wa_cond = br'_cond, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*) br_algo_def (*‹br_algo (?δ::(?'a::type, ?'b::type) ta_rule set) ≡ ⦇wa_cond = br_cond, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*)) (*goal: ‹∀s. s ∈ wa_invar (br'_algo δ) ∧ br'_α s ∈ wa_cond (br_algo δ) ⟶ s ∈ wa_cond (br'_algo δ)›*) apply (simp add: br'_cond_abs (*‹(?Σ ∈ br'_cond) = (br'_α ?Σ ∈ br_cond)›*) br'_step_abs (*‹⟦?Σ ∈ br'_invar ?δ; (?Σ, ?Σ') ∈ br'_step ?δ⟧ ⟹ (br'_α ?Σ, br'_α ?Σ') ∈ br_step ?δ›*) br'_invar_abs (*‹br'_α ` br'_invar ?δ ⊆ br_invar ?δ›*) br'_initial_abs (*‹br'_α ` br'_initial ?δ = {br_initial ?δ}›*)) (*proven 5 subgoals*) . interpretation br'_pref: wa_precise_refine "br'_algo δ" "br_algo δ" "br'_α" using br'_pref_br (*‹wa_precise_refine (br'_algo ?δ) (br_algo ?δ) br'_α›*) . theorem br'_while_algo: "finite δ ⟹ while_algo (br'_algo δ)" apply (rule br'_pref.wa_intro (*‹⟦while_algo (br_algo ?δ); wa_invar (br'_algo ?δ) = ?addi ∩ {s. br'_α s ∈ wa_invar (br_algo ?δ)}; ⋀s s'. ⟦s ∈ ?addi; s ∈ wa_cond (br'_algo ?δ); br'_α s ∈ wa_invar (br_algo ?δ); (s, s') ∈ wa_step (br'_algo ?δ)⟧ ⟹ s' ∈ ?addi; wa_initial (br'_algo ?δ) ⊆ ?addi⟧ ⟹ while_algo (br'_algo ?δ)›*)) (*goals: 1. ‹finite δ ⟹ while_algo (br_algo δ)› 2. ‹finite δ ⟹ wa_invar (br'_algo δ) = ?addi ∩ {s. br'_α s ∈ wa_invar (br_algo δ)}› 3. ‹⋀s s'. ⟦finite δ; s ∈ ?addi; s ∈ wa_cond (br'_algo δ); br'_α s ∈ wa_invar (br_algo δ); (s, s') ∈ wa_step (br'_algo δ)⟧ ⟹ s' ∈ ?addi› 4. ‹finite δ ⟹ wa_initial (br'_algo δ) ⊆ ?addi› discuss goal 1*) apply (simp add: br_while_algo (*‹finite ?δ ⟹ while_algo (br_algo ?δ)›*)) (*discuss goal 2*) apply (simp add: br'_algo_def (*‹br'_algo ?δ ≡ ⦇wa_cond = br'_cond, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*) br_algo_def (*‹br_algo ?δ ≡ ⦇wa_cond = br_cond, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*)) (*top goal: ‹finite δ ⟹ wa_invar (br'_algo δ) = ?addi ∩ {s. br'_α s ∈ wa_invar (br_algo δ)}› and 2 goals remain*) apply (simp add: br'_invar_def (*‹br'_invar ?δ ≡ br'_invar_add ?δ ∩ {Σ. br'_α Σ ∈ br_invar ?δ}›*)) (*discuss goal 3*) apply (simp add: br'_algo_def (*‹br'_algo ?δ ≡ ⦇wa_cond = br'_cond, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*) br_algo_def (*‹br_algo ?δ ≡ ⦇wa_cond = br_cond, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*)) (*top goal: ‹⋀s s'. ⟦finite δ; s ∈ br'_invar_add δ; s ∈ wa_cond (br'_algo δ); br'_α s ∈ wa_invar (br_algo δ); (s, s') ∈ wa_step (br'_algo δ)⟧ ⟹ s' ∈ br'_invar_add δ› and 1 goal remains*) apply (erule (3) br'_step_invar (*‹⟦finite ?δ; ?Σ ∈ br'_invar_add ?δ; br'_α ?Σ ∈ br_invar ?δ; (?Σ, ?Σ') ∈ br'_step ?δ⟧ ⟹ ?Σ' ∈ br'_invar_add ?δ›*)) (*discuss goal 4*) apply (simp add: br'_algo_def (*‹br'_algo ?δ ≡ ⦇wa_cond = br'_cond, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*) br_algo_def (*‹br_algo ?δ ≡ ⦇wa_cond = br_cond, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*)) (*goal: ‹finite δ ⟹ wa_initial (br'_algo δ) ⊆ br'_invar_add δ›*) apply (simp add: br'_invar_initial (*‹br'_initial ?δ ⊆ br'_invar_add ?δ›*)) (*proven 4 subgoals*) . lemma fst_br'_α: "fst (br'_α s) = fst s" apply (cases s) (*goal: ‹fst (br'_α s) = fst s›*) by (simp add: br'_α_def (*‹br'_α = (λ(Q::?'Q set, W::?'Q set, rcm::(?'Q, ?'L) ta_rule ⇒ nat option). (Q, W))›*)) lemmas br'_invar_final = br'_pref.transfer_correctness[OF br_invar_final, unfolded fst_br'_α] theorem bre'_pref_br: "wa_precise_refine (bre'_algo Qi δ) (bre_algo Qi δ) br'_α" apply unfold_locales (*goals: 1. ‹⋀s. ⟦s ∈ wa_invar (bre'_algo Qi δ); s ∈ wa_cond (bre'_algo Qi δ)⟧ ⟹ br'_α s ∈ wa_cond (bre_algo Qi δ)› 2. ‹⋀s s'. ⟦s ∈ wa_invar (bre'_algo Qi δ); s ∈ wa_cond (bre'_algo Qi δ); (s, s') ∈ wa_step (bre'_algo Qi δ)⟧ ⟹ (br'_α s, br'_α s') ∈ wa_step (bre_algo Qi δ)› 3. ‹br'_α ` wa_initial (bre'_algo Qi δ) ⊆ wa_initial (bre_algo Qi δ)› 4. ‹br'_α ` wa_invar (bre'_algo Qi δ) ⊆ wa_invar (bre_algo Qi δ)› 5. ‹∀s. s ∈ wa_invar (bre'_algo Qi δ) ∧ br'_α s ∈ wa_cond (bre_algo Qi δ) ⟶ s ∈ wa_cond (bre'_algo Qi δ)› discuss goal 1*) apply (simp add: bre'_algo_def (*‹bre'_algo ?Qi ?δ ≡ ⦇wa_cond = bre'_cond ?Qi, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*) bre_algo_def (*‹bre_algo ?Qi ?δ ≡ ⦇wa_cond = bre_cond ?Qi, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*)) (*top goal: ‹⋀s. ⟦s ∈ wa_invar (bre'_algo Qi δ); s ∈ wa_cond (bre'_algo Qi δ)⟧ ⟹ br'_α s ∈ wa_cond (bre_algo Qi δ)› and 4 goals remain*) apply (simp add: bre'_cond_abs (*‹((?Σ::?'a set × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option)) ∈ bre'_cond (?Qi::?'a set)) = (br'_α ?Σ ∈ bre_cond ?Qi)›*) br'_step_abs (*‹⟦(?Σ::?'a set × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option)) ∈ br'_invar (?δ::(?'a, ?'b) ta_rule set); (?Σ, ?Σ'::?'a set × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option)) ∈ br'_step ?δ⟧ ⟹ (br'_α ?Σ, br'_α ?Σ') ∈ br_step ?δ›*) br'_invar_abs (*‹br'_α ` br'_invar (?δ::(?'a, ?'b) ta_rule set) ⊆ br_invar ?δ›*) br'_initial_abs (*‹br'_α ` br'_initial (?δ::(?'a, ?'b) ta_rule set) = {br_initial ?δ}›*)) (*discuss goal 2*) apply (simp add: bre'_algo_def (*‹bre'_algo ?Qi ?δ ≡ ⦇wa_cond = bre'_cond ?Qi, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*) bre_algo_def (*‹bre_algo ?Qi ?δ ≡ ⦇wa_cond = bre_cond ?Qi, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*)) (*top goal: ‹⋀s s'. ⟦s ∈ wa_invar (bre'_algo Qi δ); s ∈ wa_cond (bre'_algo Qi δ); (s, s') ∈ wa_step (bre'_algo Qi δ)⟧ ⟹ (br'_α s, br'_α s') ∈ wa_step (bre_algo Qi δ)› and 3 goals remain*) apply (simp add: bre'_cond_abs (*‹(?Σ ∈ bre'_cond ?Qi) = (br'_α ?Σ ∈ bre_cond ?Qi)›*) br'_step_abs (*‹⟦?Σ ∈ br'_invar ?δ; (?Σ, ?Σ') ∈ br'_step ?δ⟧ ⟹ (br'_α ?Σ, br'_α ?Σ') ∈ br_step ?δ›*) br'_invar_abs (*‹br'_α ` br'_invar ?δ ⊆ br_invar ?δ›*) br'_initial_abs (*‹br'_α ` br'_initial ?δ = {br_initial ?δ}›*)) (*discuss goal 3*) apply (simp add: bre'_algo_def (*‹bre'_algo ?Qi ?δ ≡ ⦇wa_cond = bre'_cond ?Qi, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*) bre_algo_def (*‹bre_algo ?Qi ?δ ≡ ⦇wa_cond = bre_cond ?Qi, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*)) (*top goal: ‹br'_α ` wa_initial (bre'_algo Qi δ) ⊆ wa_initial (bre_algo Qi δ)› and 2 goals remain*) apply (simp add: bre'_cond_abs (*‹(?Σ ∈ bre'_cond ?Qi) = (br'_α ?Σ ∈ bre_cond ?Qi)›*) br'_step_abs (*‹⟦?Σ ∈ br'_invar ?δ; (?Σ, ?Σ') ∈ br'_step ?δ⟧ ⟹ (br'_α ?Σ, br'_α ?Σ') ∈ br_step ?δ›*) br'_invar_abs (*‹br'_α ` br'_invar ?δ ⊆ br_invar ?δ›*) br'_initial_abs (*‹br'_α ` br'_initial ?δ = {br_initial ?δ}›*)) (*discuss goal 4*) apply (simp add: bre'_algo_def (*‹bre'_algo ?Qi ?δ ≡ ⦇wa_cond = bre'_cond ?Qi, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*) bre_algo_def (*‹bre_algo ?Qi ?δ ≡ ⦇wa_cond = bre_cond ?Qi, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*)) (*top goal: ‹br'_α ` wa_invar (bre'_algo Qi δ) ⊆ wa_invar (bre_algo Qi δ)› and 1 goal remains*) apply (simp add: bre'_cond_abs (*‹((?Σ::?'a::type set × ?'a::type set × ((?'a::type, ?'b::type) ta_rule ⇒ nat option)) ∈ bre'_cond (?Qi::?'a::type set)) = (br'_α ?Σ ∈ bre_cond ?Qi)›*) br'_step_abs (*‹⟦(?Σ::?'a::type set × ?'a::type set × ((?'a::type, ?'b::type) ta_rule ⇒ nat option)) ∈ br'_invar (?δ::(?'a::type, ?'b::type) ta_rule set); (?Σ, ?Σ'::?'a::type set × ?'a::type set × ((?'a::type, ?'b::type) ta_rule ⇒ nat option)) ∈ br'_step ?δ⟧ ⟹ (br'_α ?Σ, br'_α ?Σ') ∈ br_step ?δ›*) br'_invar_abs (*‹br'_α ` br'_invar (?δ::(?'a::type, ?'b::type) ta_rule set) ⊆ br_invar ?δ›*) br'_initial_abs (*‹br'_α ` br'_initial (?δ::(?'a::type, ?'b::type) ta_rule set) = {br_initial ?δ}›*)) (*discuss goal 5*) apply (simp add: bre'_algo_def (*‹bre'_algo ?Qi ?δ ≡ ⦇wa_cond = bre'_cond ?Qi, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*) bre_algo_def (*‹bre_algo ?Qi ?δ ≡ ⦇wa_cond = bre_cond ?Qi, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*)) (*goal: ‹∀s::'a set × 'a set × (('a, 'b) ta_rule ⇒ nat option). s ∈ wa_invar (bre'_algo (Qi::'a set) (δ::('a, 'b) ta_rule set)) ∧ br'_α s ∈ wa_cond (bre_algo Qi δ) ⟶ s ∈ wa_cond (bre'_algo Qi δ)›*) apply (simp add: bre'_cond_abs (*‹((?Σ::?'a set × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option)) ∈ bre'_cond (?Qi::?'a set)) = (br'_α ?Σ ∈ bre_cond ?Qi)›*) br'_step_abs (*‹⟦(?Σ::?'a set × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option)) ∈ br'_invar (?δ::(?'a, ?'b) ta_rule set); (?Σ, ?Σ'::?'a set × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option)) ∈ br'_step ?δ⟧ ⟹ (br'_α ?Σ, br'_α ?Σ') ∈ br_step ?δ›*) br'_invar_abs (*‹br'_α ` br'_invar (?δ::(?'a, ?'b) ta_rule set) ⊆ br_invar ?δ›*) br'_initial_abs (*‹br'_α ` br'_initial (?δ::(?'a, ?'b) ta_rule set) = {br_initial ?δ}›*)) (*proven 5 subgoals*) . interpretation bre'_pref: wa_precise_refine "bre'_algo Qi δ" "bre_algo Qi δ" "br'_α" using bre'_pref_br (*‹wa_precise_refine (bre'_algo (?Qi::?'a set) (?δ::(?'a, ?'b) ta_rule set)) (bre_algo ?Qi ?δ) br'_α›*) . theorem bre'_while_algo: "finite δ ⟹ while_algo (bre'_algo Qi δ)" apply (rule bre'_pref.wa_intro (*‹⟦while_algo (bre_algo ?Qi ?δ); wa_invar (bre'_algo ?Qi ?δ) = ?addi ∩ {s. br'_α s ∈ wa_invar (bre_algo ?Qi ?δ)}; ⋀s s'. ⟦s ∈ ?addi; s ∈ wa_cond (bre'_algo ?Qi ?δ); br'_α s ∈ wa_invar (bre_algo ?Qi ?δ); (s, s') ∈ wa_step (bre'_algo ?Qi ?δ)⟧ ⟹ s' ∈ ?addi; wa_initial (bre'_algo ?Qi ?δ) ⊆ ?addi⟧ ⟹ while_algo (bre'_algo ?Qi ?δ)›*)) (*goals: 1. ‹finite δ ⟹ while_algo (bre_algo Qi δ)› 2. ‹finite δ ⟹ wa_invar (bre'_algo Qi δ) = ?addi ∩ {s. br'_α s ∈ wa_invar (bre_algo Qi δ)}› 3. ‹⋀s s'. ⟦finite δ; s ∈ ?addi; s ∈ wa_cond (bre'_algo Qi δ); br'_α s ∈ wa_invar (bre_algo Qi δ); (s, s') ∈ wa_step (bre'_algo Qi δ)⟧ ⟹ s' ∈ ?addi› 4. ‹finite δ ⟹ wa_initial (bre'_algo Qi δ) ⊆ ?addi› discuss goal 1*) apply (simp add: bre_while_algo (*‹finite ?δ ⟹ while_algo (bre_algo ?Qi ?δ)›*)) (*discuss goal 2*) apply (simp add: bre'_algo_def (*‹bre'_algo ?Qi ?δ ≡ ⦇wa_cond = bre'_cond ?Qi, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*) bre_algo_def (*‹bre_algo ?Qi ?δ ≡ ⦇wa_cond = bre_cond ?Qi, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*)) (*top goal: ‹finite δ ⟹ wa_invar (bre'_algo Qi δ) = ?addi ∩ {s. br'_α s ∈ wa_invar (bre_algo Qi δ)}› and 2 goals remain*) apply (simp add: br'_invar_def (*‹br'_invar (?δ::(?'Q, ?'L) ta_rule set) ≡ br'_invar_add ?δ ∩ {Σ::?'Q set × ?'Q set × ((?'Q, ?'L) ta_rule ⇒ nat option). br'_α Σ ∈ br_invar ?δ}›*)) (*discuss goal 3*) apply (simp add: bre'_algo_def (*‹bre'_algo ?Qi ?δ ≡ ⦇wa_cond = bre'_cond ?Qi, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*) bre_algo_def (*‹bre_algo ?Qi ?δ ≡ ⦇wa_cond = bre_cond ?Qi, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*)) (*top goal: ‹⋀s s'. ⟦finite δ; s ∈ br'_invar_add δ; s ∈ wa_cond (bre'_algo Qi δ); br'_α s ∈ wa_invar (bre_algo Qi δ); (s, s') ∈ wa_step (bre'_algo Qi δ)⟧ ⟹ s' ∈ br'_invar_add δ› and 1 goal remains*) apply (erule (3) br'_step_invar (*‹⟦finite ?δ; ?Σ ∈ br'_invar_add ?δ; br'_α ?Σ ∈ br_invar ?δ; (?Σ, ?Σ') ∈ br'_step ?δ⟧ ⟹ ?Σ' ∈ br'_invar_add ?δ›*)) (*discuss goal 4*) apply (simp add: bre'_algo_def (*‹bre'_algo ?Qi ?δ ≡ ⦇wa_cond = bre'_cond ?Qi, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*) bre_algo_def (*‹bre_algo ?Qi ?δ ≡ ⦇wa_cond = bre_cond ?Qi, wa_step = br_step ?δ, wa_initial = {br_initial ?δ}, wa_invar = br_invar ?δ⦈›*)) (*goal: ‹finite δ ⟹ wa_initial (bre'_algo Qi δ) ⊆ br'_invar_add δ›*) apply (simp add: br'_invar_initial (*‹br'_initial ?δ ⊆ br'_invar_add ?δ›*)) (*proven 4 subgoals*) . lemmas bre'_invar_final = bre'_pref.transfer_correctness[OF bre_invar_final, unfolded fst_br'_α] text_raw ‹\paragraph{Implementing a Step}› text ‹ In this paragraph, it is shown how to implement a step of the br'-algorithm by iteration over the rules that have the discovered state on their RHS. › definition br'_inner_step :: "('Q,'L) ta_rule ⇒ ('Q,'L) br'_state ⇒ ('Q,'L) br'_state" where "br'_inner_step == λr (Q,W,rcm). let c=the (rcm r) in ( if c≤1 then insert (lhs r) Q else Q, if c≤1 ∧ (lhs r) ∉ Q then insert (lhs r) W else W, rcm ( r ↦ (c-(1::nat))) ) " definition br'_inner_invar :: "('Q,'L) ta_rule set ⇒ 'Q ⇒ ('Q,'L) br'_state ⇒ ('Q,'L) ta_rule set ⇒ ('Q,'L) br'_state ⇒ bool" where "br'_inner_invar rules q == λ(Q,W,rcm) it (Q',W',rcm'). Q' = Q ∪ { lhs r | r. r∈rules-it ∧ the (rcm r) ≤ 1 } ∧ W' = (W-{q}) ∪ ({ lhs r | r. r∈rules-it ∧ the (rcm r) ≤ 1 } - Q) ∧ (∀r. rcm' r = (if r∈rules-it then Some (the (rcm r) - 1) else rcm r)) " lemma br'_inner_invar_imp_final: "⟦ q∈W; br'_inner_invar {r∈δ. q∈set (rhsq r)} q (Q,W-{q},rcm) {} Σ' ⟧ ⟹ ((Q,W,rcm),Σ') ∈ br'_step δ" apply (unfold br'_inner_invar_def (*‹br'_inner_invar ?rules ?q ≡ λ(Q, W, rcm) it (Q', W', rcm'). Q' = Q ∪ {lhs r |r. r ∈ ?rules - it ∧ the (rcm r) ≤ 1} ∧ W' = W - {?q} ∪ ({lhs r |r. r ∈ ?rules - it ∧ the (rcm r) ≤ 1} - Q) ∧ (∀r. rcm' r = (if r ∈ ?rules - it then Some (the (rcm r) - 1) else rcm r))›*)) (*goal: ‹⟦q ∈ W; br'_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) {} Σ'⟧ ⟹ ((Q, W, rcm), Σ') ∈ br'_step δ›*) apply auto (*goal: ‹⟦q ∈ W; (case (Q, W - {q}, rcm) of (Q, W, rcm) ⇒ λit (Q', W', rcm'). Q' = Q ∪ {lhs r |r. r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it ∧ the (rcm r) ≤ 1} ∧ W' = W - {q} ∪ ({lhs r |r. r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it ∧ the (rcm r) ≤ 1} - Q) ∧ (∀r. rcm' r = (if r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it then Some (the (rcm r) - 1) else rcm r))) {} Σ'⟧ ⟹ ((Q, W, rcm), Σ') ∈ br'_step δ›*) apply (rule br'_step.intros (*‹⟦?q ∈ ?W; ?Q' = ?Q ∪ {lhs r |r. r ∈ ?δ ∧ ?q ∈ set (rhsq r) ∧ the (?rcm r) ≤ 1}; ?W' = ?W - {?q} ∪ ({lhs r |r. r ∈ ?δ ∧ ?q ∈ set (rhsq r) ∧ the (?rcm r) ≤ 1} - ?Q); ⋀r. r ∈ ?δ ⟹ ?rcm' r = (if ?q ∈ set (rhsq r) then Some (the (?rcm r) - 1) else ?rcm r)⟧ ⟹ ((?Q, ?W, ?rcm), ?Q', ?W', ?rcm') ∈ br'_step ?δ›*)) (*goals: 1. ‹⋀b. ⟦q ∈ W; Σ' = (Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}, W - {q} ∪ ({lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - Q), b); ∀r. b r = (if r ∈ δ ∧ q ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r)⟧ ⟹ ?q10 b ∈ W› 2. ‹⋀b. ⟦q ∈ W; Σ' = (Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}, W - {q} ∪ ({lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - Q), b); ∀r. b r = (if r ∈ δ ∧ q ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r)⟧ ⟹ Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} = Q ∪ {lhs r |r. r ∈ δ ∧ ?q10 b ∈ set (rhsq r) ∧ the (rcm r) ≤ 1}› 3. ‹⋀b. ⟦q ∈ W; Σ' = (Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}, W - {q} ∪ ({lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - Q), b); ∀r. b r = (if r ∈ δ ∧ q ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r)⟧ ⟹ W - {q} ∪ ({lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - Q) = W - {?q10 b} ∪ ({lhs r |r. r ∈ δ ∧ ?q10 b ∈ set (rhsq r) ∧ the (rcm r) ≤ 1} - Q)› 4. ‹⋀b r. ⟦q ∈ W; Σ' = (Q ∪ {lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}, W - {q} ∪ ({lhs r |r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - Q), b); ∀r. b r = (if r ∈ δ ∧ q ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r); r ∈ δ⟧ ⟹ b r = (if ?q10 b ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r)› discuss goal 1*) apply assumption (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . lemma br'_inner_invar_step: "⟦ q∈W; br'_inner_invar {r∈δ. q∈set (rhsq r)} q (Q,W-{q},rcm) it Σ'; r∈it; it⊆{r∈δ. q∈set (rhsq r)} ⟧ ⟹ br'_inner_invar {r∈δ. q∈set (rhsq r)} q (Q,W-{q},rcm) (it-{r}) (br'_inner_step r Σ') " apply (cases Σ') (*goal: ‹⟦q ∈ W; br'_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) it Σ'; r ∈ it; it ⊆ {r ∈ δ. q ∈ set (rhsq r)}⟧ ⟹ br'_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) (it - {r}) (br'_inner_step r Σ')›*) apply simp (*goal: ‹⋀a b c. ⟦q ∈ W; br'_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) it Σ'; r ∈ it; it ⊆ {r ∈ δ. q ∈ set (rhsq r)}; Σ' = (a, b, c)⟧ ⟹ br'_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) (it - {r}) (br'_inner_step r Σ')›*) apply (unfold br'_inner_invar_def (*‹br'_inner_invar ?rules ?q ≡ λ(Q, W, rcm) it (Q', W', rcm'). Q' = Q ∪ {lhs r |r. r ∈ ?rules - it ∧ the (rcm r) ≤ 1} ∧ W' = W - {?q} ∪ ({lhs r |r. r ∈ ?rules - it ∧ the (rcm r) ≤ 1} - Q) ∧ (∀r. rcm' r = (if r ∈ ?rules - it then Some (the (rcm r) - 1) else rcm r))›*) br'_inner_step_def (*‹br'_inner_step ≡ λr (Q, W, rcm). let c = the (rcm r) in (if c ≤ 1 then insert (lhs r) Q else Q, if c ≤ 1 ∧ lhs r ∉ Q then insert (lhs r) W else W, rcm(r ↦ c - 1))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*)) (*goal: ‹⋀(a::'a set) (b::'a set) c::('a, 'b) ta_rule ⇒ nat option. ⟦(q::'a) ∈ (W::'a set); br'_inner_invar {r::('a, 'b) ta_rule ∈ δ::('a, 'b) ta_rule set. q ∈ set (rhsq r)} q (Q::'a set, W - {q}, rcm::('a, 'b) ta_rule ⇒ nat option) (it::('a, 'b) ta_rule set) (a, b, c); (r::('a, 'b) ta_rule) ∈ it; it ⊆ {r::('a, 'b) ta_rule ∈ δ. q ∈ set (rhsq r)}; (Σ'::'a set × 'a set × (('a, 'b) ta_rule ⇒ nat option)) = (a, b, c)⟧ ⟹ br'_inner_invar {r::('a, 'b) ta_rule ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) (it - {r}) (br'_inner_step r (a, b, c))›*) by auto lemma br'_inner_invar_initial: "⟦ q∈W ⟧ ⟹ br'_inner_invar {r∈δ. q∈set (rhsq r)} q (Q,W-{q},rcm) {r∈δ. q∈set (rhsq r)} (Q,W-{q},rcm)" apply (simp add: br'_inner_invar_def (*‹br'_inner_invar ?rules ?q ≡ λ(Q, W, rcm) it (Q', W', rcm'). Q' = Q ∪ {lhs r |r. r ∈ ?rules - it ∧ the (rcm r) ≤ 1} ∧ W' = W - {?q} ∪ ({lhs r |r. r ∈ ?rules - it ∧ the (rcm r) ≤ 1} - Q) ∧ (∀r. rcm' r = (if r ∈ ?rules - it then Some (the (rcm r) - 1) else rcm r))›*)) (*goal: ‹q ∈ W ⟹ br'_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) {r ∈ δ. q ∈ set (rhsq r)} (Q, W - {q}, rcm)›*) by auto lemma br'_inner_step_proof: fixes αs :: "'Σ ⇒ ('Q,'L) br'_state" fixes cstep :: "('Q,'L) ta_rule ⇒ 'Σ ⇒ 'Σ" fixes Σh :: "'Σ" fixes cinvar :: "('Q,'L) ta_rule set ⇒ 'Σ ⇒ bool" assumes iterable_set: "set_iteratei α invar iteratei" assumes invar_initial: "cinvar {r∈δ. q∈set (rhsq r)} Σh" assumes invar_step: "!!it r Σ. ⟦ r∈it; it ⊆ {r∈δ. q∈set (rhsq r)}; cinvar it Σ ⟧ ⟹ cinvar (it-{r}) (cstep r Σ)" assumes step_desc: "!!it r Σ. ⟦ r∈it; it⊆{r∈δ. q∈set (rhsq r)}; cinvar it Σ ⟧ ⟹ αs (cstep r Σ) = br'_inner_step r (αs Σ)" assumes it_set_desc: "invar it_set" "α it_set = {r∈δ. q∈set (rhsq r)}" assumes QIW[simp]: "q∈W" assumes Σ_desc[simp]: "αs Σ = (Q,W,rcm)" assumes Σh_desc[simp]: "αs Σh = (Q,W-{q},rcm)" shows "(αs Σ, αs (iteratei it_set (λ_. True) cstep Σh))∈br'_step δ" proof (-) (*goal: ‹(αs Σ, αs (iteratei it_set (λ_. True) cstep Σh)) ∈ br'_step δ›*) interpret set_iteratei "α" invar iteratei by fact show "?thesis" (*goal: ‹(αs Σ, αs (iteratei it_set (λ_. True) cstep Σh)) ∈ br'_step δ›*) apply (rule_tac I="λit Σ. cinvar it Σ ∧ br'_inner_invar {r∈δ. q∈set (rhsq r)} q (Q,W-{q},rcm) it (αs Σ)" in iterate_rule_P (*‹⟦invar ?S; ?I (α ?S) ?σ0.0; ⋀x it σ. ⟦x ∈ it; it ⊆ α ?S; ?I it σ⟧ ⟹ ?I (it - {x}) (?f x σ); ⋀σ. ?I {} σ ⟹ ?P σ⟧ ⟹ ?P (iteratei ?S (λ_. True) ?f ?σ0.0)›*)) (*goals: 1. ‹invar it_set› 2. ‹cinvar (α it_set) Σh ∧ br'_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) (α it_set) (αs Σh)› 3. ‹⋀x it σ. ⟦x ∈ it; it ⊆ α it_set; cinvar it σ ∧ br'_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) it (αs σ)⟧ ⟹ cinvar (it - {x}) (cstep x σ) ∧ br'_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) (it - {x}) (αs (cstep x σ))› 4. ‹⋀σ. cinvar {} σ ∧ br'_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) {} (αs σ) ⟹ (αs Σ, αs σ) ∈ br'_step δ› discuss goal 1*) apply (simp add: it_set_desc (*‹invar it_set› ‹α it_set = {r ∈ δ. q ∈ set (rhsq r)}›*) invar_initial (*‹cinvar {r ∈ δ. q ∈ set (rhsq r)} Σh›*) br'_inner_invar_initial (*‹?q ∈ ?W ⟹ br'_inner_invar {r ∈ ?δ. ?q ∈ set (rhsq r)} ?q (?Q, ?W - {?q}, ?rcm) {r ∈ ?δ. ?q ∈ set (rhsq r)} (?Q, ?W - {?q}, ?rcm)›*) invar_step (*‹⟦?r ∈ ?it; ?it ⊆ {r ∈ δ. q ∈ set (rhsq r)}; cinvar ?it ?Σ⟧ ⟹ cinvar (?it - {?r}) (cstep ?r ?Σ)›*) step_desc (*‹⟦?r ∈ ?it; ?it ⊆ {r ∈ δ. q ∈ set (rhsq r)}; cinvar ?it ?Σ⟧ ⟹ αs (cstep ?r ?Σ) = br'_inner_step ?r (αs ?Σ)›*) br'_inner_invar_step (*‹⟦?q ∈ ?W; br'_inner_invar {r ∈ ?δ. ?q ∈ set (rhsq r)} ?q (?Q, ?W - {?q}, ?rcm) ?it ?Σ'; ?r ∈ ?it; ?it ⊆ {r ∈ ?δ. ?q ∈ set (rhsq r)}⟧ ⟹ br'_inner_invar {r ∈ ?δ. ?q ∈ set (rhsq r)} ?q (?Q, ?W - {?q}, ?rcm) (?it - {?r}) (br'_inner_step ?r ?Σ')›*)) (*discuss goal 2*) apply (simp add: it_set_desc (*‹(invar::'a ⇒ bool) (it_set::'a)› ‹(α::'a ⇒ ('Q, 'L) ta_rule set) (it_set::'a) = {r::('Q, 'L) ta_rule ∈ δ::('Q, 'L) ta_rule set. (q::'Q) ∈ set (rhsq r)}›*) invar_initial (*‹(cinvar::('Q, 'L) ta_rule set ⇒ 'Σ ⇒ bool) {r::('Q, 'L) ta_rule ∈ δ::('Q, 'L) ta_rule set. (q::'Q) ∈ set (rhsq r)} (Σh::'Σ)›*) br'_inner_invar_initial (*‹(?q::?'a) ∈ (?W::?'a set) ⟹ br'_inner_invar {r::(?'a, ?'b) ta_rule ∈ ?δ::(?'a, ?'b) ta_rule set. ?q ∈ set (rhsq r)} ?q (?Q::?'a set, ?W - {?q}, ?rcm::(?'a, ?'b) ta_rule ⇒ nat option) {r::(?'a, ?'b) ta_rule ∈ ?δ. ?q ∈ set (rhsq r)} (?Q, ?W - {?q}, ?rcm)›*) invar_step (*‹⟦(?r::('Q, 'L) ta_rule) ∈ (?it::('Q, 'L) ta_rule set); ?it ⊆ {r::('Q, 'L) ta_rule ∈ δ::('Q, 'L) ta_rule set. (q::'Q) ∈ set (rhsq r)}; (cinvar::('Q, 'L) ta_rule set ⇒ 'Σ ⇒ bool) ?it (?Σ::'Σ)⟧ ⟹ cinvar (?it - {?r}) ((cstep::('Q, 'L) ta_rule ⇒ 'Σ ⇒ 'Σ) ?r ?Σ)›*) step_desc (*‹⟦(?r::('Q, 'L) ta_rule) ∈ (?it::('Q, 'L) ta_rule set); ?it ⊆ {r::('Q, 'L) ta_rule ∈ δ::('Q, 'L) ta_rule set. (q::'Q) ∈ set (rhsq r)}; (cinvar::('Q, 'L) ta_rule set ⇒ 'Σ ⇒ bool) ?it (?Σ::'Σ)⟧ ⟹ (αs::'Σ ⇒ 'Q set × 'Q set × (('Q, 'L) ta_rule ⇒ nat option)) ((cstep::('Q, 'L) ta_rule ⇒ 'Σ ⇒ 'Σ) ?r ?Σ) = br'_inner_step ?r (αs ?Σ)›*) br'_inner_invar_step (*‹⟦(?q::?'a) ∈ (?W::?'a set); br'_inner_invar {r::(?'a, ?'b) ta_rule ∈ ?δ::(?'a, ?'b) ta_rule set. ?q ∈ set (rhsq r)} ?q (?Q::?'a set, ?W - {?q}, ?rcm::(?'a, ?'b) ta_rule ⇒ nat option) (?it::(?'a, ?'b) ta_rule set) (?Σ'::?'a set × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option)); (?r::(?'a, ?'b) ta_rule) ∈ ?it; ?it ⊆ {r::(?'a, ?'b) ta_rule ∈ ?δ. ?q ∈ set (rhsq r)}⟧ ⟹ br'_inner_invar {r::(?'a, ?'b) ta_rule ∈ ?δ. ?q ∈ set (rhsq r)} ?q (?Q, ?W - {?q}, ?rcm) (?it - {?r}) (br'_inner_step ?r ?Σ')›*)) (*discuss goal 3*) apply (simp add: it_set_desc (*‹(invar::'a ⇒ bool) (it_set::'a)› ‹(α::'a ⇒ ('Q, 'L) ta_rule set) (it_set::'a) = {r::('Q, 'L) ta_rule ∈ δ::('Q, 'L) ta_rule set. (q::'Q) ∈ set (rhsq r)}›*) invar_initial (*‹(cinvar::('Q, 'L) ta_rule set ⇒ 'Σ ⇒ bool) {r::('Q, 'L) ta_rule ∈ δ::('Q, 'L) ta_rule set. (q::'Q) ∈ set (rhsq r)} (Σh::'Σ)›*) br'_inner_invar_initial (*‹(?q::?'a) ∈ (?W::?'a set) ⟹ br'_inner_invar {r::(?'a, ?'b) ta_rule ∈ ?δ::(?'a, ?'b) ta_rule set. ?q ∈ set (rhsq r)} ?q (?Q::?'a set, ?W - {?q}, ?rcm::(?'a, ?'b) ta_rule ⇒ nat option) {r::(?'a, ?'b) ta_rule ∈ ?δ. ?q ∈ set (rhsq r)} (?Q, ?W - {?q}, ?rcm)›*) invar_step (*‹⟦(?r::('Q, 'L) ta_rule) ∈ (?it::('Q, 'L) ta_rule set); ?it ⊆ {r::('Q, 'L) ta_rule ∈ δ::('Q, 'L) ta_rule set. (q::'Q) ∈ set (rhsq r)}; (cinvar::('Q, 'L) ta_rule set ⇒ 'Σ ⇒ bool) ?it (?Σ::'Σ)⟧ ⟹ cinvar (?it - {?r}) ((cstep::('Q, 'L) ta_rule ⇒ 'Σ ⇒ 'Σ) ?r ?Σ)›*) step_desc (*‹⟦(?r::('Q, 'L) ta_rule) ∈ (?it::('Q, 'L) ta_rule set); ?it ⊆ {r::('Q, 'L) ta_rule ∈ δ::('Q, 'L) ta_rule set. (q::'Q) ∈ set (rhsq r)}; (cinvar::('Q, 'L) ta_rule set ⇒ 'Σ ⇒ bool) ?it (?Σ::'Σ)⟧ ⟹ (αs::'Σ ⇒ 'Q set × 'Q set × (('Q, 'L) ta_rule ⇒ nat option)) ((cstep::('Q, 'L) ta_rule ⇒ 'Σ ⇒ 'Σ) ?r ?Σ) = br'_inner_step ?r (αs ?Σ)›*) br'_inner_invar_step (*‹⟦(?q::?'a) ∈ (?W::?'a set); br'_inner_invar {r::(?'a, ?'b) ta_rule ∈ ?δ::(?'a, ?'b) ta_rule set. ?q ∈ set (rhsq r)} ?q (?Q::?'a set, ?W - {?q}, ?rcm::(?'a, ?'b) ta_rule ⇒ nat option) (?it::(?'a, ?'b) ta_rule set) (?Σ'::?'a set × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option)); (?r::(?'a, ?'b) ta_rule) ∈ ?it; ?it ⊆ {r::(?'a, ?'b) ta_rule ∈ ?δ. ?q ∈ set (rhsq r)}⟧ ⟹ br'_inner_invar {r::(?'a, ?'b) ta_rule ∈ ?δ. ?q ∈ set (rhsq r)} ?q (?Q, ?W - {?q}, ?rcm) (?it - {?r}) (br'_inner_step ?r ?Σ')›*)) (*discuss goal 4*) apply (simp add: it_set_desc (*‹invar it_set› ‹α it_set = {r ∈ δ. q ∈ set (rhsq r)}›*) invar_initial (*‹cinvar {r ∈ δ. q ∈ set (rhsq r)} Σh›*) br'_inner_invar_initial (*‹?q ∈ ?W ⟹ br'_inner_invar {r ∈ ?δ. ?q ∈ set (rhsq r)} ?q (?Q, ?W - {?q}, ?rcm) {r ∈ ?δ. ?q ∈ set (rhsq r)} (?Q, ?W - {?q}, ?rcm)›*) invar_step (*‹⟦?r ∈ ?it; ?it ⊆ {r ∈ δ. q ∈ set (rhsq r)}; cinvar ?it ?Σ⟧ ⟹ cinvar (?it - {?r}) (cstep ?r ?Σ)›*) step_desc (*‹⟦?r ∈ ?it; ?it ⊆ {r ∈ δ. q ∈ set (rhsq r)}; cinvar ?it ?Σ⟧ ⟹ αs (cstep ?r ?Σ) = br'_inner_step ?r (αs ?Σ)›*) br'_inner_invar_step (*‹⟦?q ∈ ?W; br'_inner_invar {r ∈ ?δ. ?q ∈ set (rhsq r)} ?q (?Q, ?W - {?q}, ?rcm) ?it ?Σ'; ?r ∈ ?it; ?it ⊆ {r ∈ ?δ. ?q ∈ set (rhsq r)}⟧ ⟹ br'_inner_invar {r ∈ ?δ. ?q ∈ set (rhsq r)} ?q (?Q, ?W - {?q}, ?rcm) (?it - {?r}) (br'_inner_step ?r ?Σ')›*)) (*goal: ‹⋀σ. cinvar {} σ ∧ br'_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) {} (αs σ) ⟹ (αs Σ, αs σ) ∈ br'_step δ›*) apply (rule br'_inner_invar_imp_final (*‹⟦?q ∈ ?W; br'_inner_invar {r ∈ ?δ. ?q ∈ set (rhsq r)} ?q (?Q, ?W - {?q}, ?rcm) {} ?Σ'⟧ ⟹ ((?Q, ?W, ?rcm), ?Σ') ∈ br'_step ?δ›*)) (*goals: 1. ‹⋀σ. cinvar {} σ ∧ br'_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) {} (αs σ) ⟹ ?q2 σ ∈ W› 2. ‹⋀σ. cinvar {} σ ∧ br'_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) {} (αs σ) ⟹ br'_inner_invar {r ∈ δ. ?q2 σ ∈ set (rhsq r)} (?q2 σ) (Q, W - {?q2 σ}, rcm) {} (αs σ)› discuss goal 1*) apply (rule QIW (*‹(q::'Q) ∈ (W::'Q set)›*)) (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 4 subgoals*) . qed text_raw ‹\paragraph{Computing Witnesses}› text ‹ The algorithm is now refined further, such that it stores, for each discovered state, a witness for non-emptiness, i.e. a tree that is accepted with the discovered state. › ― ‹A map from states to trees has the witness-property, if it maps states to trees that are accepted with that state:› definition "witness_prop δ m == ∀q t. m q = Some t ⟶ accs δ t q" ― ‹Construct a witness for the LHS of a rule, provided that the map contains witnesses for all states on the RHS:› definition construct_witness :: "('Q ⇀ 'L tree) ⇒ ('Q,'L) ta_rule ⇒ 'L tree" where "construct_witness Q r == NODE (rhsl r) (List.map (λq. the (Q q)) (rhsq r))" lemma witness_propD: "⟦witness_prop δ m; m q = Some t⟧ ⟹ accs δ t q" by (auto simp add: witness_prop_def (*‹witness_prop (?δ::(?'a::type, ?'b::type) ta_rule set) (?m::?'a::type ⇒ ?'b::type tree option) ≡ ∀(q::?'a::type) t::?'b::type tree. ?m q = Some t ⟶ accs ?δ t q›*)) lemma construct_witness_correct: "⟦ witness_prop δ Q; r∈δ; set (rhsq r) ⊆ dom Q ⟧ ⟹ accs δ (construct_witness Q r) (lhs r)" apply (unfold construct_witness_def (*‹construct_witness ?Q ?r ≡ NODE (rhsl ?r) (map (λq. the (?Q q)) (rhsq ?r))›*) witness_prop_def (*‹witness_prop ?δ ?m ≡ ∀q t. ?m q = Some t ⟶ accs ?δ t q›*)) (*goal: ‹⟦witness_prop δ Q; r ∈ δ; set (rhsq r) ⊆ dom Q⟧ ⟹ accs δ (construct_witness Q r) (lhs r)›*) apply (cases r) (*goal: ‹⟦∀q t. Q q = Some t ⟶ accs δ t q; r ∈ δ; set (rhsq r) ⊆ dom Q⟧ ⟹ accs δ (NODE (rhsl r) (map (λq. the (Q q)) (rhsq r))) (lhs r)›*) apply simp (*goal: ‹⋀x1 x2 x3. ⟦∀q t. Q q = Some t ⟶ accs δ t q; r ∈ δ; set (rhsq r) ⊆ dom Q; r = x1 → x2 x3⟧ ⟹ accs δ (NODE (rhsl r) (map (λq. the (Q q)) (rhsq r))) (lhs r)›*) apply (erule accs.intros (*‹⟦?q → ?f ?qs ∈ ?δ; length ?ts = length ?qs; ⋀i. i < length ?qs ⟹ accs ?δ (?ts ! i) (?qs ! i)⟧ ⟹ accs ?δ (NODE ?f ?ts) ?q›*)) (*goals: 1. ‹⋀x1 x2 x3. ⟦∀q t. Q q = Some t ⟶ accs δ t q; set x3 ⊆ dom Q; r = x1 → x2 x3⟧ ⟹ length (map (λq. the (Q q)) x3) = length x3› 2. ‹⋀x1 x2 x3 i. ⟦∀q t. Q q = Some t ⟶ accs δ t q; set x3 ⊆ dom Q; r = x1 → x2 x3; i < length x3⟧ ⟹ accs δ (map (λq. the (Q q)) x3 ! i) (x3 ! i)› discuss goal 1*) apply ((auto dest: nth_mem (*‹?n < length ?xs ⟹ ?xs ! ?n ∈ set ?xs›*))[1]) (*discuss goal 2*) apply ((auto dest: nth_mem (*‹?n < length ?xs ⟹ ?xs ! ?n ∈ set ?xs›*))[1]) (*proven 2 subgoals*) . lemma construct_witness_eq: "⟦ Q |` set (rhsq r) = Q' |` set (rhsq r) ⟧ ⟹ construct_witness Q r = construct_witness Q' r" apply (unfold construct_witness_def (*‹construct_witness ?Q ?r ≡ NODE (rhsl ?r) (map (λq. the (?Q q)) (rhsq ?r))›*)) (*goal: ‹Q |` set (rhsq r) = Q' |` set (rhsq r) ⟹ construct_witness Q r = construct_witness Q' r›*) apply auto (*goal: ‹(Q::'a ⇒ 'b tree option) |` set (rhsq (r::('a, 'b) ta_rule)) = (Q'::'a ⇒ 'b tree option) |` set (rhsq r) ⟹ NODE (rhsl r) (map (λq::'a. the (Q q)) (rhsq r)) = NODE (rhsl r) (map (λq::'a. the (Q' q)) (rhsq r))›*) apply (subgoal_tac "Q x = Q' x") (*goals: 1. ‹⋀x::'a. ⟦(Q::'a ⇒ 'b tree option) |` set (rhsq (r::('a, 'b) ta_rule)) = (Q'::'a ⇒ 'b tree option) |` set (rhsq r); x ∈ set (rhsq r); Q x = Q' x⟧ ⟹ the (Q x) = the (Q' x)› 2. ‹⋀x::'a. ⟦(Q::'a ⇒ 'b tree option) |` set (rhsq (r::('a, 'b) ta_rule)) = (Q'::'a ⇒ 'b tree option) |` set (rhsq r); x ∈ set (rhsq r)⟧ ⟹ Q x = Q' x› discuss goal 1*) apply simp (*discuss goal 2*) apply (drule_tac x=x in fun_cong (*‹?f = ?g ⟹ ?f ?x = ?g ?x›*)) (*goal: ‹⋀x. ⟦Q |` set (rhsq r) = Q' |` set (rhsq r); x ∈ set (rhsq r)⟧ ⟹ Q x = Q' x›*) apply auto (*proven 2 subgoals*) . text ‹ The set of discovered states is refined by a map from discovered states to their witnesses: › type_synonym ('Q,'L) brw_state = "('Q⇀'L tree) × 'Q set × (('Q,'L) ta_rule ⇀ nat)" definition brw_α :: "('Q,'L) brw_state ⇒ ('Q,'L) br'_state" where "brw_α = (λ(Q,W,rcm). (dom Q,W,rcm))" definition brw_invar_add :: "('Q,'L) ta_rule set ⇒ ('Q,'L) brw_state set" where "brw_invar_add δ == {(Q,W,rcm). witness_prop δ Q}" definition "brw_invar δ == brw_invar_add δ ∩ {s. brw_α s ∈ br'_invar δ}" (* TODO: This step description does not allow full flexibility, because we may want to construct new witnesses from other witnesses constructed in the same step! However, if we say t = construct_witness Q' r, may we run into cyclicity problems, where a cycle of witnesses may witness itself?. Hmm? As these cyclic witnesses would have to be infinite, they cannot exist? But, if we use a BFS search strategy, the current step description will compute minimal depth witnesses. The argumentation is, that: Initially, all witnesses of depth 1 (definitely minimal) are discovered A witness of depth n has children of length < n The states that are initially on the workset are all those with witnesses of depth 1. Thus, after they have been processed, all states with witnesses of depth 2 have been discovered. This argument can be iterated inductively. *) inductive_set brw_step :: "('Q,'L) ta_rule set ⇒ (('Q,'L) brw_state × ('Q,'L) brw_state) set" for δ where "⟦ q∈W; dsqr = { r∈δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1 }; dom Q' = dom Q ∪ lhs`dsqr; !!q t. Q' q = Some t ⟹ Q q = Some t ∨ (∃r∈dsqr. q=lhs r ∧ t=construct_witness Q r); W' = (W-{q}) ∪ (lhs`dsqr - dom Q); !!r. r∈δ ⟹ rcm' r = ( if q ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r ) ⟧ ⟹ ((Q,W,rcm),(Q',W',rcm')) ∈ brw_step δ" definition brw_cond :: "'Q set ⇒ ('Q,'L) brw_state set" where "brw_cond Qi == {(Q,W,rcm). W≠{} ∧ (Qi∩dom Q={})}" inductive_set brw_iq :: "('Q,'L) ta_rule set ⇒ ('Q ⇀ 'L tree) set" for δ where "⟦ ∀q t. Q q = Some t ⟶ (∃r∈δ. rhsq r = [] ∧ q = lhs r ∧ t = NODE (rhsl r) []); ∀r∈δ. rhsq r = [] ⟶ Q (lhs r) ≠ None ⟧ ⟹ Q ∈ brw_iq δ" inductive_set brw_initial :: "('Q,'L) ta_rule set ⇒ ('Q,'L) brw_state set" for δ where "⟦ !!r. r∈δ ⟹ rcm r = Some (card (set (rhsq r))); Q∈brw_iq δ ⟧ ⟹ (Q, br_iq δ, rcm)∈brw_initial δ" definition "brw_algo Qi δ == ⦇ wa_cond=brw_cond Qi, wa_step = brw_step δ, wa_initial = brw_initial δ, wa_invar = brw_invar δ ⦈" lemma brw_cond_abs: "Σ∈brw_cond Qi ⟷ (brw_α Σ)∈bre'_cond Qi" apply (cases Σ) (*goal: ‹(Σ ∈ brw_cond Qi) = (brw_α Σ ∈ bre'_cond Qi)›*) by (simp add: brw_cond_def (*‹brw_cond (?Qi::?'Q set) ≡ {(Q::?'Q ⇒ ?'L tree option, W::?'Q set, rcm::(?'Q, ?'L) ta_rule ⇒ nat option). W ≠ {} ∧ ?Qi ∩ dom Q = {}}›*) bre'_cond_def (*‹bre'_cond (?Qi::?'Q set) ≡ {(Q::?'Q set, W::?'Q set, rcm::(?'Q, ?'L) ta_rule ⇒ nat option). W ≠ {} ∧ ?Qi ∩ Q = {}}›*) brw_α_def (*‹brw_α = (λ(Q::?'Q ⇒ ?'L tree option, W::?'Q set, rcm::(?'Q, ?'L) ta_rule ⇒ nat option). (dom Q, W, rcm))›*)) lemma brw_initial_abs: "Σ∈brw_initial δ ⟹ brw_α Σ ∈ br'_initial δ" apply ((cases Σ)[1]) (*goal: ‹Σ ∈ brw_initial δ ⟹ brw_α Σ ∈ br'_initial δ›*) apply simp (*goal: ‹⋀a b c. ⟦Σ ∈ brw_initial δ; Σ = (a, b, c)⟧ ⟹ brw_α Σ ∈ br'_initial δ›*) apply ((erule brw_initial.cases (*‹⟦(?a1.0, ?a2.0, ?a3.0) ∈ brw_initial ?δ; ⋀rcm Q. ⟦?a1.0 = Q; ?a2.0 = br_iq ?δ; ?a3.0 = rcm; ⋀r. r ∈ ?δ ⟹ rcm r = Some (card (set (rhsq r))); Q ∈ brw_iq ?δ⟧ ⟹ ?P⟧ ⟹ ?P›*))[1]) (*goal: ‹⋀(a::'a::type ⇒ 'b::type tree option) (b::'a::type set) c::('a::type, 'b::type) ta_rule ⇒ nat option. ⟦(a, b, c) ∈ brw_initial (δ::('a::type, 'b::type) ta_rule set); (Σ::('a::type ⇒ 'b::type tree option) × 'a::type set × (('a::type, 'b::type) ta_rule ⇒ nat option)) = (a, b, c)⟧ ⟹ brw_α (a, b, c) ∈ br'_initial δ›*) apply ((erule brw_iq.cases (*‹⟦?a ∈ brw_iq ?δ; ⋀Q. ⟦?a = Q; ∀q t. Q q = Some t ⟶ (∃r∈?δ. rhsq r = [] ∧ q = lhs r ∧ t = NODE (rhsl r) []); ∀r∈?δ. rhsq r = [] ⟶ Q (lhs r) ≠ None⟧ ⟹ ?P⟧ ⟹ ?P›*))[1]) (*goal: ‹⋀a b c rcm Q. ⟦Σ = (a, b, c); a = Q; b = br_iq δ; c = rcm; ⋀r. r ∈ δ ⟹ rcm r = Some (card (set (rhsq r))); Q ∈ brw_iq δ⟧ ⟹ brw_α (a, b, c) ∈ br'_initial δ›*) apply ((auto simp add: brw_α_def (*‹brw_α = (λ(Q, W, rcm). (dom Q, W, rcm))›*))[1]) (*goal: ‹⋀a b c rcm Q Qa. ⟦Σ = (a, b, c); a = Q; b = br_iq δ; c = rcm; ⋀r. r ∈ δ ⟹ rcm r = Some (card (set (rhsq r))); Q = Qa; ∀q t. Qa q = Some t ⟶ (∃r∈δ. rhsq r = [] ∧ q = lhs r ∧ t = NODE (rhsl r) []); ∀r∈δ. rhsq r = [] ⟶ Qa (lhs r) ≠ None⟧ ⟹ brw_α (a, b, c) ∈ br'_initial δ›*) apply ((subgoal_tac "dom Qa = br_iq δ")[1]) (*goals: 1. ‹⋀rcm Qa. ⟦Σ = (Qa, br_iq δ, rcm); ⋀r. r ∈ δ ⟹ rcm r = Some (card (set (rhsq r))); ∀q t. Qa q = Some t ⟶ (∃r∈δ. rhsq r = [] ∧ q = lhs r ∧ t = NODE (rhsl r) []); ∀r∈δ. rhsq r = [] ⟶ (∃y. Qa (lhs r) = Some y); dom Qa = br_iq δ⟧ ⟹ (dom Qa, br_iq δ, rcm) ∈ br'_initial δ› 2. ‹⋀rcm Qa. ⟦Σ = (Qa, br_iq δ, rcm); ⋀r. r ∈ δ ⟹ rcm r = Some (card (set (rhsq r))); ∀q t. Qa q = Some t ⟶ (∃r∈δ. rhsq r = [] ∧ q = lhs r ∧ t = NODE (rhsl r) []); ∀r∈δ. rhsq r = [] ⟶ (∃y. Qa (lhs r) = Some y)⟧ ⟹ dom Qa = br_iq δ› discuss goal 1*) apply simp (*top goal: ‹⋀rcm Qa. ⟦Σ = (Qa, br_iq δ, rcm); ⋀r. r ∈ δ ⟹ rcm r = Some (card (set (rhsq r))); ∀q t. Qa q = Some t ⟶ (∃r∈δ. rhsq r = [] ∧ q = lhs r ∧ t = NODE (rhsl r) []); ∀r∈δ. rhsq r = [] ⟶ (∃y. Qa (lhs r) = Some y); dom Qa = br_iq δ⟧ ⟹ (dom Qa, br_iq δ, rcm) ∈ br'_initial δ› and 1 goal remains*) apply (rule br'_initial.intros (*‹(⋀r. r ∈ ?δ ⟹ ?rcm r = Some (card (set (rhsq r)))) ⟹ (br_iq ?δ, br_iq ?δ, ?rcm) ∈ br'_initial ?δ›*)) (*top goal: ‹⋀rcm Qa. ⟦Σ = (Qa, br_iq δ, rcm); ⋀r. r ∈ δ ⟹ rcm r = Some (card (set (rhsq r))); ∀q t. Qa q = Some t ⟶ (∃r∈δ. rhsq r = [] ∧ q = lhs r ∧ t = NODE (rhsl r) []); ∀r∈δ. rhsq r = [] ⟶ (∃y. Qa (lhs r) = Some y); dom Qa = br_iq δ⟧ ⟹ (br_iq δ, br_iq δ, rcm) ∈ br'_initial δ› and 1 goal remains*) apply ((auto)[1]) (*discuss goal 2*) apply ((force simp add: br_iq_def (*‹br_iq ?δ ≡ {lhs r |r. r ∈ ?δ ∧ rhsq r = []}›*))[1]) (*proven 2 subgoals*) . lemma brw_invar_initial: "brw_initial δ ⊆ brw_invar_add δ" apply safe (*goal: ‹brw_initial (δ::('a, 'b) ta_rule set) ⊆ brw_invar_add δ›*) apply (unfold brw_invar_add_def (*‹brw_invar_add (?δ::(?'Q, ?'L) ta_rule set) ≡ {(Q::?'Q ⇒ ?'L tree option, W::?'Q set, rcm::(?'Q, ?'L) ta_rule ⇒ nat option). witness_prop ?δ Q}›*)) (*goal: ‹⋀a aa b. (a, aa, b) ∈ brw_initial δ ⟹ (a, aa, b) ∈ brw_invar_add δ›*) apply (auto simp add: witness_prop_def (*‹witness_prop ?δ ?m ≡ ∀q t. ?m q = Some t ⟶ accs ?δ t q›*)) (*goal: ‹⋀a aa b. (a, aa, b) ∈ brw_initial δ ⟹ (a, aa, b) ∈ {(Q, W, rcm). witness_prop δ Q}›*) apply (erule brw_initial.cases (*‹⟦(?a1.0, ?a2.0, ?a3.0) ∈ brw_initial ?δ; ⋀rcm Q. ⟦?a1.0 = Q; ?a2.0 = br_iq ?δ; ?a3.0 = rcm; ⋀r. r ∈ ?δ ⟹ rcm r = Some (card (set (rhsq r))); Q ∈ brw_iq ?δ⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goal: ‹⋀a aa b q t. ⟦(a, aa, b) ∈ brw_initial δ; a q = Some t⟧ ⟹ accs δ t q›*) apply (erule brw_iq.cases (*‹⟦(?a::?'Q::type ⇒ ?'L::type tree option) ∈ brw_iq (?δ::(?'Q::type, ?'L::type) ta_rule set); ⋀Q::?'Q::type ⇒ ?'L::type tree option. ⟦?a = Q; ∀(q::?'Q::type) t::?'L::type tree. Q q = Some t ⟶ (∃r::(?'Q::type, ?'L::type) ta_rule∈?δ. rhsq r = [] ∧ q = lhs r ∧ t = NODE (rhsl r) []); ∀r::(?'Q::type, ?'L::type) ta_rule∈?δ. rhsq r = [] ⟶ Q (lhs r) ≠ None⟧ ⟹ ?P::bool⟧ ⟹ ?P›*)) (*goal: ‹⋀(a::'a ⇒ 'b tree option) (aa::'a set) (b::('a, 'b) ta_rule ⇒ nat option) (q::'a) (t::'b tree) (rcm::('a, 'b) ta_rule ⇒ nat option) Q::'a ⇒ 'b tree option. ⟦a q = Some t; a = Q; aa = br_iq (δ::('a, 'b) ta_rule set); b = rcm; ⋀r::('a, 'b) ta_rule. r ∈ δ ⟹ rcm r = Some (card (set (rhsq r))); Q ∈ brw_iq δ⟧ ⟹ accs δ t q›*) apply auto (*goal: ‹⋀a aa b q t rcm Q Qa. ⟦a q = Some t; a = Q; aa = br_iq δ; b = rcm; ⋀r. r ∈ δ ⟹ rcm r = Some (card (set (rhsq r))); Q = Qa; ∀q t. Qa q = Some t ⟶ (∃r∈δ. rhsq r = [] ∧ q = lhs r ∧ t = NODE (rhsl r) []); ∀r∈δ. rhsq r = [] ⟶ Qa (lhs r) ≠ None⟧ ⟹ accs δ t q›*) proof (goal_cases) (*goal: ‹⋀(q::'a) (t::'b tree) (rcm::('a, 'b) ta_rule ⇒ nat option) Qa::'a ⇒ 'b tree option. ⟦Qa q = Some t; ⋀r::('a, 'b) ta_rule. r ∈ (δ::('a, 'b) ta_rule set) ⟹ rcm r = Some (card (set (rhsq r))); ∀(q::'a) t::'b tree. Qa q = Some t ⟶ (∃r::('a, 'b) ta_rule∈δ. rhsq r = [] ∧ q = lhs r ∧ t = NODE (rhsl r) []); ∀r::('a, 'b) ta_rule∈δ. rhsq r = [] ⟶ (∃y::'b tree. Qa (lhs r) = Some y)⟧ ⟹ accs δ t q›*) case prems: (1 q t rcm Q) (*‹Q q = Some t› ‹(?r::('a::type, 'b::type) ta_rule) ∈ (δ::('a::type, 'b::type) ta_rule set) ⟹ (rcm::('a::type, 'b::type) ta_rule ⇒ nat option) ?r = Some (card (set (rhsq ?r)))› ‹∀q t. Q q = Some t ⟶ (∃r∈δ. rhsq r = [] ∧ q = lhs r ∧ t = NODE (rhsl r) [])› ‹∀r∈δ. rhsq r = [] ⟶ (∃y. Q (lhs r) = Some y)›*) from prems(3)[rule_format, OF prems ( 1 )] (*‹∃r::('a, 'b) ta_rule∈δ::('a, 'b) ta_rule set. rhsq r = [] ∧ (q::'a) = lhs r ∧ (t::'b tree) = NODE (rhsl r) []›*) obtain r where [simp]: "r∈δ" "rhsq r = []" "q=lhs r" "t=NODE (rhsl r) []" (*goal: ‹(⋀r. ⟦r ∈ δ; rhsq r = []; q = lhs r; t = NODE (rhsl r) []⟧ ⟹ thesis) ⟹ thesis›*) by blast have RF[simplified]: "r=((lhs r) → (rhsl r) (rhsq r))" apply (cases r) (*goal: ‹r = lhs r → rhsl r rhsq r›*) by simp show "?case" (*goal: ‹accs δ t q›*) apply simp (*goal: ‹accs δ t q›*) apply (rule accs.intros (*‹⟦?q → ?f ?qs ∈ ?δ; length ?ts = length ?qs; ⋀i. i < length ?qs ⟹ accs ?δ (?ts ! i) (?qs ! i)⟧ ⟹ accs ?δ (NODE ?f ?ts) ?q›*)) (*goals: 1. ‹lhs r → rhsl r ?qs1 ∈ δ› 2. ‹length [] = length ?qs1› 3. ‹⋀i. i < length ?qs1 ⟹ accs δ ([] ! i) (?qs1 ! i)› discuss goal 1*) apply (subst RF[symmetric] (*‹lhs r → rhsl r [] = r›*)) (*top goal: ‹lhs r → rhsl r ?qs1 ∈ δ› and 2 goals remain*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . qed lemma brw_step_abs: "⟦ (Σ,Σ')∈brw_step δ ⟧ ⟹ (brw_α Σ, brw_α Σ')∈br'_step δ" apply (cases Σ) (*goal: ‹(Σ, Σ') ∈ brw_step δ ⟹ (brw_α Σ, brw_α Σ') ∈ br'_step δ›*) apply (cases Σ') (*goal: ‹⋀(a::'a ⇒ 'b tree option) (b::'a set) c::('a, 'b) ta_rule ⇒ nat option. ⟦(Σ::('a ⇒ 'b tree option) × 'a set × (('a, 'b) ta_rule ⇒ nat option), Σ'::('a ⇒ 'b tree option) × 'a set × (('a, 'b) ta_rule ⇒ nat option)) ∈ brw_step (δ::('a, 'b) ta_rule set); Σ = (a, b, c)⟧ ⟹ (brw_α Σ, brw_α Σ') ∈ br'_step δ›*) apply simp (*goal: ‹⋀a b c aa ba ca. ⟦(Σ, Σ') ∈ brw_step δ; Σ = (a, b, c); Σ' = (aa, ba, ca)⟧ ⟹ (brw_α Σ, brw_α Σ') ∈ br'_step δ›*) apply (erule brw_step.cases (*‹⟦((?a1.0, ?a2.0, ?a3.0), ?a4.0, ?a5.0, ?a6.0) ∈ brw_step ?δ; ⋀q W dsqr rcm Q' Q W' rcm'. ⟦?a1.0 = Q; ?a2.0 = W; ?a3.0 = rcm; ?a4.0 = Q'; ?a5.0 = W'; ?a6.0 = rcm'; q ∈ W; dsqr = {r ∈ ?δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1}; dom Q' = dom Q ∪ lhs ` dsqr; ⋀q t. Q' q = Some t ⟹ Q q = Some t ∨ (∃r∈dsqr. q = lhs r ∧ t = construct_witness Q r); W' = W - {q} ∪ (lhs ` dsqr - dom Q); ⋀r. r ∈ ?δ ⟹ rcm' r = (if q ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r)⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goal: ‹⋀a b c aa ba ca. ⟦((a, b, c), aa, ba, ca) ∈ brw_step δ; Σ = (a, b, c); Σ' = (aa, ba, ca)⟧ ⟹ (brw_α (a, b, c), brw_α (aa, ba, ca)) ∈ br'_step δ›*) apply (simp add: brw_α_def (*‹brw_α = (λ(Q, W, rcm). (dom Q, W, rcm))›*)) (*goal: ‹⋀a b c aa ba ca q W dsqr rcm Q' Q W' rcm'. ⟦Σ = (a, b, c); Σ' = (aa, ba, ca); a = Q; b = W; c = rcm; aa = Q'; ba = W'; ca = rcm'; q ∈ W; dsqr = {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ 1}; dom Q' = dom Q ∪ lhs ` dsqr; ⋀q t. Q' q = Some t ⟹ Q q = Some t ∨ (∃r∈dsqr. q = lhs r ∧ t = construct_witness Q r); W' = W - {q} ∪ (lhs ` dsqr - dom Q); ⋀r. r ∈ δ ⟹ rcm' r = (if q ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r)⟧ ⟹ (brw_α (a, b, c), brw_α (aa, ba, ca)) ∈ br'_step δ›*) apply hypsubst (*goal: ‹⋀a b c aa ba ca q W dsqr rcm Q' Q W' rcm'. ⟦Σ = (Q, W, rcm); Σ' = (Q', W - {q} ∪ (lhs ` {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - dom Q), rcm'); a = Q; b = W; c = rcm; aa = Q'; ba = W - {q} ∪ (lhs ` {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - dom Q); ca = rcm'; q ∈ W; dsqr = {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}; dom Q' = dom Q ∪ lhs ` {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}; ⋀qa t. Q' qa = Some t ⟹ Q qa = Some t ∨ (∃r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0 ∧ qa = lhs r ∧ t = construct_witness Q r); W' = W - {q} ∪ (lhs ` {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - dom Q); ⋀r. r ∈ δ ⟹ rcm' r = (if q ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r)⟧ ⟹ ((dom Q, W, rcm), dom Q ∪ lhs ` {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}, W - {q} ∪ (lhs ` {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - dom Q), rcm') ∈ br'_step δ›*) apply (rule br'_step.intros (*‹⟦?q ∈ ?W; ?Q' = ?Q ∪ {lhs r |r. r ∈ ?δ ∧ ?q ∈ set (rhsq r) ∧ the (?rcm r) ≤ 1}; ?W' = ?W - {?q} ∪ ({lhs r |r. r ∈ ?δ ∧ ?q ∈ set (rhsq r) ∧ the (?rcm r) ≤ 1} - ?Q); ⋀r. r ∈ ?δ ⟹ ?rcm' r = (if ?q ∈ set (rhsq r) then Some (the (?rcm r) - 1) else ?rcm r)⟧ ⟹ ((?Q, ?W, ?rcm), ?Q', ?W', ?rcm') ∈ br'_step ?δ›*)) (*goals: 1. ‹⋀a b c aa ba ca q W dsqr rcm Q' Q W' rcm'. ⟦Σ = (Q, W, rcm); Σ' = (Q', W - {q} ∪ (lhs ` {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - dom Q), rcm'); q ∈ W; dom Q' = dom Q ∪ lhs ` {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}; ⋀qa t. Q' qa = Some t ⟹ Q qa = Some t ∨ (∃r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0 ∧ qa = lhs r ∧ t = construct_witness Q r); ⋀r. r ∈ δ ⟹ rcm' r = (if q ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r)⟧ ⟹ ?q14 a b c aa ba ca q W dsqr rcm Q' Q W' rcm' ∈ W› 2. ‹⋀a b c aa ba ca q W dsqr rcm Q' Q W' rcm'. ⟦Σ = (Q, W, rcm); Σ' = (Q', W - {q} ∪ (lhs ` {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - dom Q), rcm'); q ∈ W; dom Q' = dom Q ∪ lhs ` {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}; ⋀qa t. Q' qa = Some t ⟹ Q qa = Some t ∨ (∃r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0 ∧ qa = lhs r ∧ t = construct_witness Q r); ⋀r. r ∈ δ ⟹ rcm' r = (if q ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r)⟧ ⟹ dom Q ∪ lhs ` {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} = dom Q ∪ {lhs r |r. r ∈ δ ∧ ?q14 a b c aa ba ca q W dsqr rcm Q' Q W' rcm' ∈ set (rhsq r) ∧ the (rcm r) ≤ 1}› 3. ‹⋀a b c aa ba ca q W dsqr rcm Q' Q W' rcm'. ⟦Σ = (Q, W, rcm); Σ' = (Q', W - {q} ∪ (lhs ` {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - dom Q), rcm'); q ∈ W; dom Q' = dom Q ∪ lhs ` {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}; ⋀qa t. Q' qa = Some t ⟹ Q qa = Some t ∨ (∃r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0 ∧ qa = lhs r ∧ t = construct_witness Q r); ⋀r. r ∈ δ ⟹ rcm' r = (if q ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r)⟧ ⟹ W - {q} ∪ (lhs ` {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - dom Q) = W - {?q14 a b c aa ba ca q W dsqr rcm Q' Q W' rcm'} ∪ ({lhs r |r. r ∈ δ ∧ ?q14 a b c aa ba ca q W dsqr rcm Q' Q W' rcm' ∈ set (rhsq r) ∧ the (rcm r) ≤ 1} - dom Q)› 4. ‹⋀a b c aa ba ca q W dsqr rcm Q' Q W' rcm' r. ⟦Σ = (Q, W, rcm); Σ' = (Q', W - {q} ∪ (lhs ` {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} - dom Q), rcm'); q ∈ W; dom Q' = dom Q ∪ lhs ` {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0}; ⋀qa t. Q' qa = Some t ⟹ Q qa = Some t ∨ (∃r. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0 ∧ qa = lhs r ∧ t = construct_witness Q r); ⋀r. r ∈ δ ⟹ rcm' r = (if q ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r); r ∈ δ⟧ ⟹ rcm' r = (if ?q14 a b c aa ba ca q W dsqr rcm Q' Q W' rcm' ∈ set (rhsq r) then Some (the (rcm r) - 1) else rcm r)› discuss goal 1*) apply assumption (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . lemma brw_step_invar: assumes FIN[simp]: "finite δ" assumes INV: "Σ∈brw_invar_add δ" and BR'INV: "brw_α Σ ∈ br'_invar δ" assumes STEP: "(Σ,Σ') ∈ brw_step δ" shows "Σ'∈brw_invar_add δ" proof (-) (*goal: ‹Σ' ∈ brw_invar_add δ›*) obtain Q and W and rcm and Q' and W' and rcm' where [simp]: "Σ=(Q,W,rcm)" "Σ'=(Q',W',rcm')" (*goal: ‹(⋀Q W rcm Q' W' rcm'. ⟦Σ = (Q, W, rcm); Σ' = (Q', W', rcm')⟧ ⟹ thesis) ⟹ thesis›*) apply (cases Σ) (*goal: ‹(⋀Q W rcm Q' W' rcm'. ⟦Σ = (Q, W, rcm); Σ' = (Q', W', rcm')⟧ ⟹ thesis) ⟹ thesis›*) apply (cases Σ') (*goal: ‹⋀a b c. ⟦⋀Q W rcm Q' W' rcm'. ⟦Σ = (Q, W, rcm); Σ' = (Q', W', rcm')⟧ ⟹ thesis; Σ = (a, b, c)⟧ ⟹ thesis›*) by force from INV (*‹Σ ∈ brw_invar_add δ›*) have WP: "witness_prop δ Q" by (simp add: brw_invar_add_def (*‹brw_invar_add ?δ ≡ {(Q, W, rcm). witness_prop ?δ Q}›*)) obtain qw and dsqr where SPROPS: "dsqr = {r ∈ δ. qw ∈ set (rhsq r) ∧ the (rcm r) ≤ 1}" "qw∈W" "dom Q' = dom Q ∪ lhs ` dsqr" "!!q t. Q' q = Some t ⟹ Q q = Some t ∨ (∃r∈dsqr. q=lhs r ∧ t=construct_witness Q r)" (*goal: ‹(⋀dsqr qw. ⟦dsqr = {r ∈ δ. qw ∈ set (rhsq r) ∧ the (rcm r) ≤ 1}; qw ∈ W; dom Q' = dom Q ∪ lhs ` dsqr; ⋀q t. Q' q = Some t ⟹ Q q = Some t ∨ (∃r∈dsqr. q = lhs r ∧ t = construct_witness Q r)⟧ ⟹ thesis) ⟹ thesis›*) by (auto intro: brw_step.cases[OF STEP[simplified]] (*‹(⋀q Wa dsqr rcma Q'a Qa W'a rcm'a. ⟦Q = Qa; W = Wa; rcm = rcma; Q' = Q'a; W' = W'a; rcm' = rcm'a; q ∈ Wa; dsqr = {r ∈ δ. q ∈ set (rhsq r) ∧ the (rcma r) ≤ 1}; dom Q'a = dom Qa ∪ lhs ` dsqr; ⋀q t. Q'a q = Some t ⟹ Qa q = Some t ∨ (∃r∈dsqr. q = lhs r ∧ t = construct_witness Qa r); W'a = Wa - {q} ∪ (lhs ` dsqr - dom Qa); ⋀r. r ∈ δ ⟹ rcm'a r = (if q ∈ set (rhsq r) then Some (the (rcma r) - 1) else rcma r)⟧ ⟹ ?P) ⟹ ?P›*)) from br'_rcm_aux'[OF BR'INV [ unfolded brw_α_def , simplified ] SPROPS ( 2 )] (*‹{r ∈ δ. qw ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} = {r ∈ δ. qw ∈ set (rhsq r) ∧ set (rhsq r) ⊆ dom Q - (W - {qw})}›*) have DSQR_ALT: "dsqr = {r ∈ δ. qw ∈ set (rhsq r) ∧ set (rhsq r) ⊆ dom Q - (W - {qw})}" by (simp add: SPROPS( (*‹dsqr = {r ∈ δ. qw ∈ set (rhsq r) ∧ the (rcm r) ≤ 1}›*) 1)) have "witness_prop δ Q'" apply (unfold witness_prop_def (*‹witness_prop ?δ ?m ≡ ∀q t. ?m q = Some t ⟶ accs ?δ t q›*)) (*goal: ‹witness_prop δ Q'›*) proof (safe) (*goal: ‹⋀(q::'a) t::'b tree. (Q'::'a ⇒ 'b tree option) q = Some t ⟹ accs (δ::('a, 'b) ta_rule set) t q›*) fix q and t assume A: "Q' q = Some t" (*‹(Q'::'a ⇒ 'b tree option) (q::'a) = Some (t::'b tree)›*) from SPROPS(4)[OF A] (*‹(Q::'a ⇒ 'b tree option) (q::'a) = Some (t::'b tree) ∨ (∃r::('a, 'b) ta_rule∈dsqr::('a, 'b) ta_rule set. q = lhs r ∧ t = construct_witness Q r)›*) have "Q q = Some t ∨ (∃r∈dsqr. q = lhs r ∧ t = construct_witness Q r)" . moreover { assume C: "Q q = Some t" (*‹(Q::'a ⇒ 'b tree option) (q::'a) = Some (t::'b tree)›*) from witness_propD[OF WP, OF C] (*‹accs δ t q›*) have "accs δ t q" . } moreover { fix r assume "r∈dsqr" and [simp]: "q=lhs r" "t=construct_witness Q r" (*‹(r::('a, 'b) ta_rule) ∈ (dsqr::('a, 'b) ta_rule set)› ‹(q::'a) = lhs (r::('a, 'b) ta_rule)› ‹(t::'b tree) = construct_witness (Q::'a ⇒ 'b tree option) (r::('a, 'b) ta_rule)›*) from ‹r∈dsqr› (*‹r ∈ dsqr›*) have 1: "r∈δ" "set (rhsq r) ⊆ dom Q" apply - (*goals: 1. ‹r ∈ dsqr ⟹ r ∈ δ› 2. ‹r ∈ dsqr ⟹ set (rhsq r) ⊆ dom Q› discuss goal 1*) apply ((auto simp add: DSQR_ALT (*‹(dsqr::('a, 'b) ta_rule set) = {r::('a, 'b) ta_rule ∈ δ::('a, 'b) ta_rule set. (qw::'a) ∈ set (rhsq r) ∧ set (rhsq r) ⊆ dom (Q::'a ⇒ 'b tree option) - ((W::'a set) - {qw})}›*))[1]) (*discuss goal 2*) apply ((auto simp add: DSQR_ALT (*‹dsqr = {r ∈ δ. qw ∈ set (rhsq r) ∧ set (rhsq r) ⊆ dom Q - (W - {qw})}›*))[1]) (*proven 2 subgoals*) . from construct_witness_correct[OF WP 1] (*‹accs δ (construct_witness Q r) (lhs r)›*) have "accs δ t q" by simp } ultimately show "accs δ t q" by blast qed thus "?thesis" (*goal: ‹Σ' ∈ brw_invar_add δ›*) by (simp add: brw_invar_add_def (*‹brw_invar_add ?δ ≡ {(Q, W, rcm). witness_prop ?δ Q}›*)) qed theorem brw_pref_bre': "wa_precise_refine (brw_algo Qi δ) (bre'_algo Qi δ) brw_α" apply unfold_locales (*goals: 1. ‹⋀s. ⟦s ∈ wa_invar (brw_algo Qi δ); s ∈ wa_cond (brw_algo Qi δ)⟧ ⟹ brw_α s ∈ wa_cond (bre'_algo Qi δ)› 2. ‹⋀s s'. ⟦s ∈ wa_invar (brw_algo Qi δ); s ∈ wa_cond (brw_algo Qi δ); (s, s') ∈ wa_step (brw_algo Qi δ)⟧ ⟹ (brw_α s, brw_α s') ∈ wa_step (bre'_algo Qi δ)› 3. ‹brw_α ` wa_initial (brw_algo Qi δ) ⊆ wa_initial (bre'_algo Qi δ)› 4. ‹brw_α ` wa_invar (brw_algo Qi δ) ⊆ wa_invar (bre'_algo Qi δ)› 5. ‹∀s. s ∈ wa_invar (brw_algo Qi δ) ∧ brw_α s ∈ wa_cond (bre'_algo Qi δ) ⟶ s ∈ wa_cond (brw_algo Qi δ)› discuss goal 1*) apply (simp add: brw_algo_def (*‹brw_algo (?Qi::?'a set) (?δ::(?'a, ?'b) ta_rule set) ≡ ⦇wa_cond = brw_cond ?Qi, wa_step = brw_step ?δ, wa_initial = brw_initial ?δ, wa_invar = brw_invar ?δ⦈›*) bre'_algo_def (*‹bre'_algo (?Qi::?'a set) (?δ::(?'a, ?'b) ta_rule set) ≡ ⦇wa_cond = bre'_cond ?Qi, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*)) (*top goal: ‹⋀s. ⟦s ∈ wa_invar (brw_algo Qi δ); s ∈ wa_cond (brw_algo Qi δ)⟧ ⟹ brw_α s ∈ wa_cond (bre'_algo Qi δ)› and 4 goals remain*) apply ((auto simp add: brw_cond_abs (*‹((?Σ::(?'a ⇒ ?'b tree option) × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option)) ∈ brw_cond (?Qi::?'a set)) = (brw_α ?Σ ∈ bre'_cond ?Qi)›*) brw_step_abs (*‹(?Σ::(?'a ⇒ ?'b tree option) × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option), ?Σ'::(?'a ⇒ ?'b tree option) × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option)) ∈ brw_step (?δ::(?'a, ?'b) ta_rule set) ⟹ (brw_α ?Σ, brw_α ?Σ') ∈ br'_step ?δ›*) brw_initial_abs (*‹(?Σ::(?'a ⇒ ?'b tree option) × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option)) ∈ brw_initial (?δ::(?'a, ?'b) ta_rule set) ⟹ brw_α ?Σ ∈ br'_initial ?δ›*) brw_invar_def (*‹brw_invar (?δ::(?'a, ?'b) ta_rule set) ≡ brw_invar_add ?δ ∩ {s::(?'a ⇒ ?'b tree option) × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option). brw_α s ∈ br'_invar ?δ}›*))[1]) (*discuss goal 2*) apply (simp add: brw_algo_def (*‹brw_algo ?Qi ?δ ≡ ⦇wa_cond = brw_cond ?Qi, wa_step = brw_step ?δ, wa_initial = brw_initial ?δ, wa_invar = brw_invar ?δ⦈›*) bre'_algo_def (*‹bre'_algo ?Qi ?δ ≡ ⦇wa_cond = bre'_cond ?Qi, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*)) (*top goal: ‹⋀s s'. ⟦s ∈ wa_invar (brw_algo Qi δ); s ∈ wa_cond (brw_algo Qi δ); (s, s') ∈ wa_step (brw_algo Qi δ)⟧ ⟹ (brw_α s, brw_α s') ∈ wa_step (bre'_algo Qi δ)› and 3 goals remain*) apply ((auto simp add: brw_cond_abs (*‹(?Σ ∈ brw_cond ?Qi) = (brw_α ?Σ ∈ bre'_cond ?Qi)›*) brw_step_abs (*‹(?Σ, ?Σ') ∈ brw_step ?δ ⟹ (brw_α ?Σ, brw_α ?Σ') ∈ br'_step ?δ›*) brw_initial_abs (*‹?Σ ∈ brw_initial ?δ ⟹ brw_α ?Σ ∈ br'_initial ?δ›*) brw_invar_def (*‹brw_invar ?δ ≡ brw_invar_add ?δ ∩ {s. brw_α s ∈ br'_invar ?δ}›*))[1]) (*discuss goal 3*) apply (simp add: brw_algo_def (*‹brw_algo ?Qi ?δ ≡ ⦇wa_cond = brw_cond ?Qi, wa_step = brw_step ?δ, wa_initial = brw_initial ?δ, wa_invar = brw_invar ?δ⦈›*) bre'_algo_def (*‹bre'_algo ?Qi ?δ ≡ ⦇wa_cond = bre'_cond ?Qi, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*)) (*top goal: ‹brw_α ` wa_initial (brw_algo (Qi::'a set) (δ::('a, 'b) ta_rule set)) ⊆ wa_initial (bre'_algo Qi δ)› and 2 goals remain*) apply ((auto simp add: brw_cond_abs (*‹((?Σ::(?'a ⇒ ?'b tree option) × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option)) ∈ brw_cond (?Qi::?'a set)) = (brw_α ?Σ ∈ bre'_cond ?Qi)›*) brw_step_abs (*‹(?Σ::(?'a ⇒ ?'b tree option) × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option), ?Σ'::(?'a ⇒ ?'b tree option) × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option)) ∈ brw_step (?δ::(?'a, ?'b) ta_rule set) ⟹ (brw_α ?Σ, brw_α ?Σ') ∈ br'_step ?δ›*) brw_initial_abs (*‹(?Σ::(?'a ⇒ ?'b tree option) × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option)) ∈ brw_initial (?δ::(?'a, ?'b) ta_rule set) ⟹ brw_α ?Σ ∈ br'_initial ?δ›*) brw_invar_def (*‹brw_invar (?δ::(?'a, ?'b) ta_rule set) ≡ brw_invar_add ?δ ∩ {s::(?'a ⇒ ?'b tree option) × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option). brw_α s ∈ br'_invar ?δ}›*))[1]) (*discuss goal 4*) apply (simp add: brw_algo_def (*‹brw_algo (?Qi::?'a::type set) (?δ::(?'a::type, ?'b::type) ta_rule set) ≡ ⦇wa_cond = brw_cond ?Qi, wa_step = brw_step ?δ, wa_initial = brw_initial ?δ, wa_invar = brw_invar ?δ⦈›*) bre'_algo_def (*‹bre'_algo (?Qi::?'a::type set) (?δ::(?'a::type, ?'b::type) ta_rule set) ≡ ⦇wa_cond = bre'_cond ?Qi, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*)) (*top goal: ‹brw_α ` wa_invar (brw_algo Qi δ) ⊆ wa_invar (bre'_algo Qi δ)› and 1 goal remains*) apply ((auto simp add: brw_cond_abs (*‹(?Σ ∈ brw_cond ?Qi) = (brw_α ?Σ ∈ bre'_cond ?Qi)›*) brw_step_abs (*‹(?Σ, ?Σ') ∈ brw_step ?δ ⟹ (brw_α ?Σ, brw_α ?Σ') ∈ br'_step ?δ›*) brw_initial_abs (*‹?Σ ∈ brw_initial ?δ ⟹ brw_α ?Σ ∈ br'_initial ?δ›*) brw_invar_def (*‹brw_invar ?δ ≡ brw_invar_add ?δ ∩ {s. brw_α s ∈ br'_invar ?δ}›*))[1]) (*discuss goal 5*) apply (simp add: brw_algo_def (*‹brw_algo ?Qi ?δ ≡ ⦇wa_cond = brw_cond ?Qi, wa_step = brw_step ?δ, wa_initial = brw_initial ?δ, wa_invar = brw_invar ?δ⦈›*) bre'_algo_def (*‹bre'_algo ?Qi ?δ ≡ ⦇wa_cond = bre'_cond ?Qi, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*)) (*goal: ‹∀s. s ∈ wa_invar (brw_algo Qi δ) ∧ brw_α s ∈ wa_cond (bre'_algo Qi δ) ⟶ s ∈ wa_cond (brw_algo Qi δ)›*) apply ((auto simp add: brw_cond_abs (*‹((?Σ::(?'a ⇒ ?'b tree option) × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option)) ∈ brw_cond (?Qi::?'a set)) = (brw_α ?Σ ∈ bre'_cond ?Qi)›*) brw_step_abs (*‹(?Σ::(?'a ⇒ ?'b tree option) × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option), ?Σ'::(?'a ⇒ ?'b tree option) × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option)) ∈ brw_step (?δ::(?'a, ?'b) ta_rule set) ⟹ (brw_α ?Σ, brw_α ?Σ') ∈ br'_step ?δ›*) brw_initial_abs (*‹(?Σ::(?'a ⇒ ?'b tree option) × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option)) ∈ brw_initial (?δ::(?'a, ?'b) ta_rule set) ⟹ brw_α ?Σ ∈ br'_initial ?δ›*) brw_invar_def (*‹brw_invar (?δ::(?'a, ?'b) ta_rule set) ≡ brw_invar_add ?δ ∩ {s::(?'a ⇒ ?'b tree option) × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option). brw_α s ∈ br'_invar ?δ}›*))[1]) (*proven 5 subgoals*) . interpretation brw_pref: wa_precise_refine "brw_algo Qi δ" "bre'_algo Qi δ" "brw_α" using brw_pref_bre' (*‹wa_precise_refine (brw_algo ?Qi ?δ) (bre'_algo ?Qi ?δ) brw_α›*) . theorem brw_while_algo: "finite δ ⟹ while_algo (brw_algo Qi δ)" apply (rule brw_pref.wa_intro (*‹⟦while_algo (bre'_algo ?Qi ?δ); wa_invar (brw_algo ?Qi ?δ) = ?addi ∩ {s. brw_α s ∈ wa_invar (bre'_algo ?Qi ?δ)}; ⋀s s'. ⟦s ∈ ?addi; s ∈ wa_cond (brw_algo ?Qi ?δ); brw_α s ∈ wa_invar (bre'_algo ?Qi ?δ); (s, s') ∈ wa_step (brw_algo ?Qi ?δ)⟧ ⟹ s' ∈ ?addi; wa_initial (brw_algo ?Qi ?δ) ⊆ ?addi⟧ ⟹ while_algo (brw_algo ?Qi ?δ)›*)) (*goals: 1. ‹finite (δ::('a, 'b) ta_rule set) ⟹ while_algo (bre'_algo (Qi::'a set) δ)› 2. ‹finite (δ::('a, 'b) ta_rule set) ⟹ wa_invar (brw_algo (Qi::'a set) δ) = (?addi::(('a ⇒ 'b tree option) × 'a set × (('a, 'b) ta_rule ⇒ nat option)) set) ∩ {s::('a ⇒ 'b tree option) × 'a set × (('a, 'b) ta_rule ⇒ nat option). brw_α s ∈ wa_invar (bre'_algo Qi δ)}› 3. ‹⋀(s::('a ⇒ 'b tree option) × 'a set × (('a, 'b) ta_rule ⇒ nat option)) s'::('a ⇒ 'b tree option) × 'a set × (('a, 'b) ta_rule ⇒ nat option). ⟦finite (δ::('a, 'b) ta_rule set); s ∈ (?addi::(('a ⇒ 'b tree option) × 'a set × (('a, 'b) ta_rule ⇒ nat option)) set); s ∈ wa_cond (brw_algo (Qi::'a set) δ); brw_α s ∈ wa_invar (bre'_algo Qi δ); (s, s') ∈ wa_step (brw_algo Qi δ)⟧ ⟹ s' ∈ ?addi› 4. ‹finite (δ::('a, 'b) ta_rule set) ⟹ wa_initial (brw_algo (Qi::'a set) δ) ⊆ (?addi::(('a ⇒ 'b tree option) × 'a set × (('a, 'b) ta_rule ⇒ nat option)) set)› discuss goal 1*) apply (simp add: bre'_while_algo (*‹finite ?δ ⟹ while_algo (bre'_algo ?Qi ?δ)›*)) (*discuss goal 2*) apply (simp add: brw_algo_def (*‹brw_algo ?Qi ?δ ≡ ⦇wa_cond = brw_cond ?Qi, wa_step = brw_step ?δ, wa_initial = brw_initial ?δ, wa_invar = brw_invar ?δ⦈›*) bre'_algo_def (*‹bre'_algo ?Qi ?δ ≡ ⦇wa_cond = bre'_cond ?Qi, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*)) (*top goal: ‹finite δ ⟹ wa_invar (brw_algo Qi δ) = ?addi ∩ {s. brw_α s ∈ wa_invar (bre'_algo Qi δ)}› and 2 goals remain*) apply (simp add: brw_invar_def (*‹brw_invar (?δ::(?'a, ?'b) ta_rule set) ≡ brw_invar_add ?δ ∩ {s::(?'a ⇒ ?'b tree option) × ?'a set × ((?'a, ?'b) ta_rule ⇒ nat option). brw_α s ∈ br'_invar ?δ}›*)) (*discuss goal 3*) apply (simp add: brw_algo_def (*‹brw_algo ?Qi ?δ ≡ ⦇wa_cond = brw_cond ?Qi, wa_step = brw_step ?δ, wa_initial = brw_initial ?δ, wa_invar = brw_invar ?δ⦈›*) bre'_algo_def (*‹bre'_algo ?Qi ?δ ≡ ⦇wa_cond = bre'_cond ?Qi, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*)) (*top goal: ‹⋀s s'. ⟦finite δ; s ∈ brw_invar_add δ; s ∈ wa_cond (brw_algo Qi δ); brw_α s ∈ wa_invar (bre'_algo Qi δ); (s, s') ∈ wa_step (brw_algo Qi δ)⟧ ⟹ s' ∈ brw_invar_add δ› and 1 goal remains*) apply ((auto intro: brw_step_invar (*‹⟦finite ?δ; ?Σ ∈ brw_invar_add ?δ; brw_α ?Σ ∈ br'_invar ?δ; (?Σ, ?Σ') ∈ brw_step ?δ⟧ ⟹ ?Σ' ∈ brw_invar_add ?δ›*) simp add: brw_invar_initial (*‹brw_initial ?δ ⊆ brw_invar_add ?δ›*))[1]) (*discuss goal 4*) apply (simp add: brw_algo_def (*‹brw_algo ?Qi ?δ ≡ ⦇wa_cond = brw_cond ?Qi, wa_step = brw_step ?δ, wa_initial = brw_initial ?δ, wa_invar = brw_invar ?δ⦈›*) bre'_algo_def (*‹bre'_algo ?Qi ?δ ≡ ⦇wa_cond = bre'_cond ?Qi, wa_step = br'_step ?δ, wa_initial = br'_initial ?δ, wa_invar = br'_invar ?δ⦈›*)) (*goal: ‹finite δ ⟹ wa_initial (brw_algo Qi δ) ⊆ brw_invar_add δ›*) apply ((auto intro: brw_step_invar (*‹⟦finite ?δ; ?Σ ∈ brw_invar_add ?δ; brw_α ?Σ ∈ br'_invar ?δ; (?Σ, ?Σ') ∈ brw_step ?δ⟧ ⟹ ?Σ' ∈ brw_invar_add ?δ›*) simp add: brw_invar_initial (*‹brw_initial ?δ ⊆ brw_invar_add ?δ›*))[1]) (*proven 4 subgoals*) . lemma fst_brw_α: "fst (brw_α s) = dom (fst s)" apply (cases s) (*goal: ‹fst (brw_α s) = dom (fst s)›*) by (simp add: brw_α_def (*‹brw_α = (λ(Q, W, rcm). (dom Q, W, rcm))›*)) theorem brw_invar_final: "∀sc. sc ∈ wa_invar (brw_algo Qi δ) ∧ sc ∉ wa_cond (brw_algo Qi δ) ⟶ (Qi ∩ dom (fst sc) = {}) = (Qi ∩ b_accessible δ = {}) ∧ (witness_prop δ (fst sc))" apply (intro conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*) allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*) impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goal: ‹∀sc. sc ∈ wa_invar (brw_algo Qi δ) ∧ sc ∉ wa_cond (brw_algo Qi δ) ⟶ (Qi ∩ dom (fst sc) = {}) = (Qi ∩ b_accessible δ = {}) ∧ witness_prop δ (fst sc)›*) using brw_pref.transfer_correctness[OF bre'_invar_final, unfolded fst_brw_α] (*‹∀sc. sc ∈ wa_invar (brw_algo ?Qi ?δ) ∧ sc ∉ wa_cond (brw_algo ?Qi ?δ) ⟶ (?Qi ∩ dom (fst sc) = {}) = (?Qi ∩ b_accessible ?δ = {})›*) (*goals: 1. ‹⋀sc::('a::type ⇒ 'b::type tree option) × 'a::type set × (('a::type, 'b::type) ta_rule ⇒ nat option). sc ∈ wa_invar (brw_algo (Qi::'a::type set) (δ::('a::type, 'b::type) ta_rule set)) ∧ sc ∉ wa_cond (brw_algo Qi δ) ⟹ (Qi ∩ dom (fst sc) = {}) = (Qi ∩ b_accessible δ = {})› 2. ‹⋀sc::('a::type ⇒ 'b::type tree option) × 'a::type set × (('a::type, 'b::type) ta_rule ⇒ nat option). sc ∈ wa_invar (brw_algo (Qi::'a::type set) (δ::('a::type, 'b::type) ta_rule set)) ∧ sc ∉ wa_cond (brw_algo Qi δ) ⟹ witness_prop δ (fst sc)› discuss goal 1*) apply blast (*discuss goal 2*) apply (auto simp add: brw_algo_def (*‹brw_algo ?Qi ?δ ≡ ⦇wa_cond = brw_cond ?Qi, wa_step = brw_step ?δ, wa_initial = brw_initial ?δ, wa_invar = brw_invar ?δ⦈›*) brw_invar_def (*‹brw_invar ?δ ≡ brw_invar_add ?δ ∩ {s. brw_α s ∈ br'_invar ?δ}›*) brw_invar_add_def (*‹brw_invar_add ?δ ≡ {(Q, W, rcm). witness_prop ?δ Q}›*)) (*proven 2 subgoals*) . text_raw ‹\paragraph{Implementing a Step}› inductive_set brw_inner_step :: "('Q,'L) ta_rule ⇒ (('Q,'L) brw_state × ('Q,'L) brw_state) set" for r where "⟦ c = the (rcm r); Σ = (Q,W,rcm); Σ'=(Q',W',rcm'); if c≤1 ∧ (lhs r) ∉ dom Q then Q' = Q(lhs r ↦ construct_witness Q r) else Q' = Q; if c≤1 ∧ (lhs r) ∉ dom Q then W' = insert (lhs r) W else W' = W; rcm' = rcm ( r ↦ (c-(1::nat))) ⟧ ⟹ (Σ,Σ')∈brw_inner_step r" definition brw_inner_invar :: "('Q,'L) ta_rule set ⇒ 'Q ⇒ ('Q,'L) brw_state ⇒ ('Q,'L) ta_rule set ⇒ ('Q,'L) brw_state ⇒ bool" where "brw_inner_invar rules q == λ(Q,W,rcm) it (Q',W',rcm'). (br'_inner_invar rules q (brw_α (Q,W,rcm)) it (brw_α (Q',W',rcm')) ∧ (Q'|`dom Q = Q) ∧ (let dsqr = { r∈rules - it. the (rcm r) ≤ 1 } in (∀q t. Q' q = Some t ⟶ (Q q = Some t ∨ (Q q = None ∧ (∃r∈dsqr. q=lhs r ∧ t=construct_witness Q r)) ) ))) " lemma brw_inner_step_abs: "(Σ,Σ')∈brw_inner_step r ⟹ br'_inner_step r (brw_α Σ) = brw_α Σ'" apply (erule brw_inner_step.cases (*‹⟦(?a1.0, ?a2.0) ∈ brw_inner_step ?r; ⋀c rcm Σ Q W Σ' Q' W' rcm'. ⟦?a1.0 = Σ; ?a2.0 = Σ'; c = the (rcm ?r); Σ = (Q, W, rcm); Σ' = (Q', W', rcm'); if c ≤ 1 ∧ lhs ?r ∉ dom Q then Q' = Q(lhs ?r ↦ construct_witness Q ?r) else Q' = Q; if c ≤ 1 ∧ lhs ?r ∉ dom Q then W' = insert (lhs ?r) W else W' = W; rcm' = rcm(?r ↦ c - 1)⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goal: ‹(Σ, Σ') ∈ brw_inner_step r ⟹ br'_inner_step r (brw_α Σ) = brw_α Σ'›*) apply (unfold br'_inner_step_def (*‹br'_inner_step ≡ λ(r::(?'Q, ?'L) ta_rule) (Q::?'Q set, W::?'Q set, rcm::(?'Q, ?'L) ta_rule ⇒ nat option). let c::nat = the (rcm r) in (if c ≤ (1::nat) then insert (lhs r) Q else Q, if c ≤ (1::nat) ∧ lhs r ∉ Q then insert (lhs r) W else W, rcm(r ↦ c - (1::nat)))›*) brw_α_def (*‹brw_α = (λ(Q::?'Q ⇒ ?'L tree option, W::?'Q set, rcm::(?'Q, ?'L) ta_rule ⇒ nat option). (dom Q, W, rcm))›*) Let_def (*‹Let (?s::?'a) (?f::?'a ⇒ ?'b) ≡ ?f ?s›*)) (*goal: ‹⋀c rcm Σ'' Q W Σ''' Q' W' rcm'. ⟦Σ = Σ''; Σ' = Σ'''; c = the (rcm r); Σ'' = (Q, W, rcm); Σ''' = (Q', W', rcm'); if c ≤ 1 ∧ lhs r ∉ dom Q then Q' = Q(lhs r ↦ construct_witness Q r) else Q' = Q; if c ≤ 1 ∧ lhs r ∉ dom Q then W' = insert (lhs r) W else W' = W; rcm' = rcm(r ↦ c - 1)⟧ ⟹ br'_inner_step r (brw_α Σ) = brw_α Σ'›*) by auto lemma brw_inner_invar_imp_final: "⟦ q∈W; brw_inner_invar {r∈δ. q∈set (rhsq r)} q (Q,W-{q},rcm) {} Σ' ⟧ ⟹ ((Q,W,rcm),Σ') ∈ brw_step δ" apply (unfold brw_inner_invar_def (*‹brw_inner_invar ?rules ?q ≡ λ(Q, W, rcm) it (Q', W', rcm'). br'_inner_invar ?rules ?q (brw_α (Q, W, rcm)) it (brw_α (Q', W', rcm')) ∧ Q' |` dom Q = Q ∧ (let dsqr = {r ∈ ?rules - it. the (rcm r) ≤ 1} in ∀q t. Q' q = Some t ⟶ Q q = Some t ∨ Q q = None ∧ (∃r∈dsqr. q = lhs r ∧ t = construct_witness Q r))›*) br'_inner_invar_def (*‹br'_inner_invar ?rules ?q ≡ λ(Q, W, rcm) it (Q', W', rcm'). Q' = Q ∪ {lhs r |r. r ∈ ?rules - it ∧ the (rcm r) ≤ 1} ∧ W' = W - {?q} ∪ ({lhs r |r. r ∈ ?rules - it ∧ the (rcm r) ≤ 1} - Q) ∧ (∀r. rcm' r = (if r ∈ ?rules - it then Some (the (rcm r) - 1) else rcm r))›*) brw_α_def (*‹brw_α = (λ(Q, W, rcm). (dom Q, W, rcm))›*)) (*goal: ‹⟦q ∈ W; brw_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) {} Σ'⟧ ⟹ ((Q, W, rcm), Σ') ∈ brw_step δ›*) apply (auto simp add: Let_def (*‹Let ?s ?f ≡ ?f ?s›*)) (*goal: ‹⟦q ∈ W; (case (Q, W - {q}, rcm) of (Q, W, rcm) ⇒ λit (Q', W', rcm'). (case case (Q, W, rcm) of (Q, W, rcm) ⇒ (dom Q, W, rcm) of (Q, W, rcm) ⇒ λit (Q', W', rcm'). Q' = Q ∪ {lhs r |r. r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it ∧ the (rcm r) ≤ 1} ∧ W' = W - {q} ∪ ({lhs r |r. r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it ∧ the (rcm r) ≤ 1} - Q) ∧ (∀r. rcm' r = (if r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it then Some (the (rcm r) - 1) else rcm r))) it (case (Q', W', rcm') of (Q, W, rcm) ⇒ (dom Q, W, rcm)) ∧ Q' |` dom Q = Q ∧ (let dsqr = {r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it. the (rcm r) ≤ 1} in ∀q t. Q' q = Some t ⟶ Q q = Some t ∨ Q q = None ∧ (∃r∈dsqr. q = lhs r ∧ t = construct_witness Q r))) {} Σ'⟧ ⟹ ((Q, W, rcm), Σ') ∈ brw_step δ›*) apply (rule brw_step.intros (*‹⟦?q ∈ ?W; ?dsqr = {r ∈ ?δ. ?q ∈ set (rhsq r) ∧ the (?rcm r) ≤ 1}; dom ?Q' = dom ?Q ∪ lhs ` ?dsqr; ⋀q t. ?Q' q = Some t ⟹ ?Q q = Some t ∨ (∃r∈?dsqr. q = lhs r ∧ t = construct_witness ?Q r); ?W' = ?W - {?q} ∪ (lhs ` ?dsqr - dom ?Q); ⋀r. r ∈ ?δ ⟹ ?rcm' r = (if ?q ∈ set (rhsq r) then Some (the (?rcm r) - 1) else ?rcm r)⟧ ⟹ ((?Q, ?W, ?rcm), ?Q', ?W', ?rcm') ∈ brw_step ?δ›*)) (*goals: 1. ‹⋀(x::'a ⇒ 'b tree option) b::('a, 'b) ta_rule ⇒ nat option. ⟦(q::'a) ∈ (W::'a set); (Σ'::('a ⇒ 'b tree option) × 'a set × (('a, 'b) ta_rule ⇒ nat option)) = (x, W - {q} ∪ ({lhs r |r::('a, 'b) ta_rule. r ∈ (δ::('a, 'b) ta_rule set) ∧ q ∈ set (rhsq r) ∧ the ((rcm::('a, 'b) ta_rule ⇒ nat option) r) ≤ Suc (0::nat)} - dom (Q::'a ⇒ 'b tree option)), b); dom x = dom Q ∪ {lhs r |r::('a, 'b) ta_rule. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc (0::nat)}; ∀r::('a, 'b) ta_rule. b r = (if r ∈ δ ∧ q ∈ set (rhsq r) then Some (the (rcm r) - (1::nat)) else rcm r); x |` dom Q = Q; ∀(qa::'a) t::'b tree. x qa = Some t ⟶ Q qa = Some t ∨ Q qa = None ∧ (∃r::('a, 'b) ta_rule. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc (0::nat) ∧ qa = lhs r ∧ t = construct_witness Q r)⟧ ⟹ (?q13::('a ⇒ 'b tree option) ⇒ (('a, 'b) ta_rule ⇒ nat option) ⇒ 'a) x b ∈ W› 2. ‹⋀(x::'a ⇒ 'b tree option) b::('a, 'b) ta_rule ⇒ nat option. ⟦(q::'a) ∈ (W::'a set); (Σ'::('a ⇒ 'b tree option) × 'a set × (('a, 'b) ta_rule ⇒ nat option)) = (x, W - {q} ∪ ({lhs r |r::('a, 'b) ta_rule. r ∈ (δ::('a, 'b) ta_rule set) ∧ q ∈ set (rhsq r) ∧ the ((rcm::('a, 'b) ta_rule ⇒ nat option) r) ≤ Suc (0::nat)} - dom (Q::'a ⇒ 'b tree option)), b); dom x = dom Q ∪ {lhs r |r::('a, 'b) ta_rule. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc (0::nat)}; ∀r::('a, 'b) ta_rule. b r = (if r ∈ δ ∧ q ∈ set (rhsq r) then Some (the (rcm r) - (1::nat)) else rcm r); x |` dom Q = Q; ∀(qa::'a) t::'b tree. x qa = Some t ⟶ Q qa = Some t ∨ Q qa = None ∧ (∃r::('a, 'b) ta_rule. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc (0::nat) ∧ qa = lhs r ∧ t = construct_witness Q r)⟧ ⟹ (?dsqr13::('a ⇒ 'b tree option) ⇒ (('a, 'b) ta_rule ⇒ nat option) ⇒ ('a, 'b) ta_rule set) x b = {r::('a, 'b) ta_rule ∈ δ. (?q13::('a ⇒ 'b tree option) ⇒ (('a, 'b) ta_rule ⇒ nat option) ⇒ 'a) x b ∈ set (rhsq r) ∧ the (rcm r) ≤ (1::nat)}› 3. ‹⋀(x::'a ⇒ 'b tree option) b::('a, 'b) ta_rule ⇒ nat option. ⟦(q::'a) ∈ (W::'a set); (Σ'::('a ⇒ 'b tree option) × 'a set × (('a, 'b) ta_rule ⇒ nat option)) = (x, W - {q} ∪ ({lhs r |r::('a, 'b) ta_rule. r ∈ (δ::('a, 'b) ta_rule set) ∧ q ∈ set (rhsq r) ∧ the ((rcm::('a, 'b) ta_rule ⇒ nat option) r) ≤ Suc (0::nat)} - dom (Q::'a ⇒ 'b tree option)), b); dom x = dom Q ∪ {lhs r |r::('a, 'b) ta_rule. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc (0::nat)}; ∀r::('a, 'b) ta_rule. b r = (if r ∈ δ ∧ q ∈ set (rhsq r) then Some (the (rcm r) - (1::nat)) else rcm r); x |` dom Q = Q; ∀(qa::'a) t::'b tree. x qa = Some t ⟶ Q qa = Some t ∨ Q qa = None ∧ (∃r::('a, 'b) ta_rule. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc (0::nat) ∧ qa = lhs r ∧ t = construct_witness Q r)⟧ ⟹ dom x = dom Q ∪ lhs ` (?dsqr13::('a ⇒ 'b tree option) ⇒ (('a, 'b) ta_rule ⇒ nat option) ⇒ ('a, 'b) ta_rule set) x b› 4. ‹⋀(x::'a ⇒ 'b tree option) (b::('a, 'b) ta_rule ⇒ nat option) (qa::'a) t::'b tree. ⟦(q::'a) ∈ (W::'a set); (Σ'::('a ⇒ 'b tree option) × 'a set × (('a, 'b) ta_rule ⇒ nat option)) = (x, W - {q} ∪ ({lhs r |r::('a, 'b) ta_rule. r ∈ (δ::('a, 'b) ta_rule set) ∧ q ∈ set (rhsq r) ∧ the ((rcm::('a, 'b) ta_rule ⇒ nat option) r) ≤ Suc (0::nat)} - dom (Q::'a ⇒ 'b tree option)), b); dom x = dom Q ∪ {lhs r |r::('a, 'b) ta_rule. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc (0::nat)}; ∀r::('a, 'b) ta_rule. b r = (if r ∈ δ ∧ q ∈ set (rhsq r) then Some (the (rcm r) - (1::nat)) else rcm r); x |` dom Q = Q; ∀(qa::'a) t::'b tree. x qa = Some t ⟶ Q qa = Some t ∨ Q qa = None ∧ (∃r::('a, 'b) ta_rule. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc (0::nat) ∧ qa = lhs r ∧ t = construct_witness Q r); x qa = Some t⟧ ⟹ Q qa = Some t ∨ (∃r::('a, 'b) ta_rule∈(?dsqr13::('a ⇒ 'b tree option) ⇒ (('a, 'b) ta_rule ⇒ nat option) ⇒ ('a, 'b) ta_rule set) x b. qa = lhs r ∧ t = construct_witness Q r)› 5. ‹⋀(x::'a ⇒ 'b tree option) b::('a, 'b) ta_rule ⇒ nat option. ⟦(q::'a) ∈ (W::'a set); (Σ'::('a ⇒ 'b tree option) × 'a set × (('a, 'b) ta_rule ⇒ nat option)) = (x, W - {q} ∪ ({lhs r |r::('a, 'b) ta_rule. r ∈ (δ::('a, 'b) ta_rule set) ∧ q ∈ set (rhsq r) ∧ the ((rcm::('a, 'b) ta_rule ⇒ nat option) r) ≤ Suc (0::nat)} - dom (Q::'a ⇒ 'b tree option)), b); dom x = dom Q ∪ {lhs r |r::('a, 'b) ta_rule. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc (0::nat)}; ∀r::('a, 'b) ta_rule. b r = (if r ∈ δ ∧ q ∈ set (rhsq r) then Some (the (rcm r) - (1::nat)) else rcm r); x |` dom Q = Q; ∀(qa::'a) t::'b tree. x qa = Some t ⟶ Q qa = Some t ∨ Q qa = None ∧ (∃r::('a, 'b) ta_rule. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc (0::nat) ∧ qa = lhs r ∧ t = construct_witness Q r)⟧ ⟹ W - {q} ∪ ({lhs r |r::('a, 'b) ta_rule. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc (0::nat)} - dom Q) = W - {(?q13::('a ⇒ 'b tree option) ⇒ (('a, 'b) ta_rule ⇒ nat option) ⇒ 'a) x b} ∪ (lhs ` (?dsqr13::('a ⇒ 'b tree option) ⇒ (('a, 'b) ta_rule ⇒ nat option) ⇒ ('a, 'b) ta_rule set) x b - dom Q)› 6. ‹⋀(x::'a ⇒ 'b tree option) (b::('a, 'b) ta_rule ⇒ nat option) r::('a, 'b) ta_rule. ⟦(q::'a) ∈ (W::'a set); (Σ'::('a ⇒ 'b tree option) × 'a set × (('a, 'b) ta_rule ⇒ nat option)) = (x, W - {q} ∪ ({lhs r |r::('a, 'b) ta_rule. r ∈ (δ::('a, 'b) ta_rule set) ∧ q ∈ set (rhsq r) ∧ the ((rcm::('a, 'b) ta_rule ⇒ nat option) r) ≤ Suc (0::nat)} - dom (Q::'a ⇒ 'b tree option)), b); dom x = dom Q ∪ {lhs r |r::('a, 'b) ta_rule. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc (0::nat)}; ∀r::('a, 'b) ta_rule. b r = (if r ∈ δ ∧ q ∈ set (rhsq r) then Some (the (rcm r) - (1::nat)) else rcm r); x |` dom Q = Q; ∀(qa::'a) t::'b tree. x qa = Some t ⟶ Q qa = Some t ∨ Q qa = None ∧ (∃r::('a, 'b) ta_rule. r ∈ δ ∧ q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc (0::nat) ∧ qa = lhs r ∧ t = construct_witness Q r); r ∈ δ⟧ ⟹ b r = (if (?q13::('a ⇒ 'b tree option) ⇒ (('a, 'b) ta_rule ⇒ nat option) ⇒ 'a) x b ∈ set (rhsq r) then Some (the (rcm r) - (1::nat)) else rcm r)› discuss goal 1*) apply assumption (*discuss goal 2*) apply (rule refl (*‹?t = ?t›*)) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*proven 6 subgoals*) . lemma brw_inner_invar_step: assumes INVI: "(Q,W,rcm)∈brw_invar δ" assumes A: "q∈W" "r∈it" "it⊆{r∈δ. q∈set (rhsq r)}" assumes INVH: "brw_inner_invar {r∈δ. q∈set (rhsq r)} q (Q,W-{q},rcm) it Σh" assumes STEP: "(Σh,Σ')∈brw_inner_step r" shows "brw_inner_invar {r∈δ. q∈set (rhsq r)} q (Q,W-{q},rcm) (it-{r}) Σ'" proof (-) (*goal: ‹brw_inner_invar {r::('a, 'b) ta_rule ∈ δ::('a, 'b) ta_rule set. (q::'a) ∈ set (rhsq r)} q (Q::'a ⇒ 'b tree option, (W::'a set) - {q}, rcm::('a, 'b) ta_rule ⇒ nat option) ((it::('a, 'b) ta_rule set) - {r::('a, 'b) ta_rule}) (Σ'::('a ⇒ 'b tree option) × 'a set × (('a, 'b) ta_rule ⇒ nat option))›*) from INVI (*‹(Q, W, rcm) ∈ brw_invar δ›*) have BR'_INV: "(dom Q,W,rcm)∈br'_invar δ" by (simp add: brw_invar_def (*‹brw_invar ?δ ≡ brw_invar_add ?δ ∩ {s. brw_α s ∈ br'_invar ?δ}›*) brw_α_def (*‹brw_α = (λ(Q, W, rcm). (dom Q, W, rcm))›*)) obtain c and Qh and Wh and rcmh and Q' and W' and rcm' where SIGMAF[simp]: "Σh=(Qh,Wh,rcmh)" "Σ'=(Q',W',rcm')" and CF[simp]: "c = the (rcmh r)" and SF: "if c≤1 ∧ (lhs r) ∉ dom Qh then Q' = Qh(lhs r ↦ (construct_witness Qh r)) else Q' = Qh" "if c≤1 ∧ (lhs r) ∉ dom Qh then W' = insert (lhs r) Wh else W' = Wh" "rcm' = rcmh ( r ↦ (c-(1::nat)))" (*goal: ‹(⋀Qh Wh rcmh Q' W' rcm' c. ⟦Σh = (Qh, Wh, rcmh); Σ' = (Q', W', rcm'); c = the (rcmh r); if c ≤ 1 ∧ lhs r ∉ dom Qh then Q' = Qh(lhs r ↦ construct_witness Qh r) else Q' = Qh; if c ≤ 1 ∧ lhs r ∉ dom Qh then W' = insert (lhs r) Wh else W' = Wh; rcm' = rcmh(r ↦ c - 1)⟧ ⟹ thesis) ⟹ thesis›*) by (blast intro: brw_inner_step.cases[OF STEP] (*‹(⋀(c::nat) (rcm::('a::type, 'b::type) ta_rule ⇒ nat option) (Σ::('a::type ⇒ 'b::type tree option) × 'a::type set × (('a::type, 'b::type) ta_rule ⇒ nat option)) (Q::'a::type ⇒ 'b::type tree option) (W::'a::type set) (Σ''::('a::type ⇒ 'b::type tree option) × 'a::type set × (('a::type, 'b::type) ta_rule ⇒ nat option)) (Q'::'a::type ⇒ 'b::type tree option) (W'::'a::type set) rcm'::('a::type, 'b::type) ta_rule ⇒ nat option. ⟦(Σh::('a::type ⇒ 'b::type tree option) × 'a::type set × (('a::type, 'b::type) ta_rule ⇒ nat option)) = Σ; (Σ'::('a::type ⇒ 'b::type tree option) × 'a::type set × (('a::type, 'b::type) ta_rule ⇒ nat option)) = Σ''; c = the (rcm (r::('a::type, 'b::type) ta_rule)); Σ = (Q, W, rcm); Σ'' = (Q', W', rcm'); if c ≤ (1::nat) ∧ lhs r ∉ dom Q then Q' = Q(lhs r ↦ construct_witness Q r) else Q' = Q; if c ≤ (1::nat) ∧ lhs r ∉ dom Q then W' = insert (lhs r) W else W' = W; rcm' = rcm(r ↦ c - (1::nat))⟧ ⟹ ?P::bool) ⟹ ?P›*)) let ?rules = "{r∈δ. q∈set (rhsq r)}" let ?dsqr = "λit. { r∈?rules - it. the (rcm r) ≤ 1 }" from INVH (*‹brw_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) it Σh›*) have INVHF: "br'_inner_invar ?rules q (dom Q, W-{q}, rcm) (it) (dom Qh,Wh,rcmh)" "Qh|`dom Q = Q" "(∀q t. Qh q = Some t ⟶ (Q q = Some t ∨ (Q q = None ∧ (∃r∈?dsqr it. q=lhs r ∧ t=construct_witness Q r)) ) )" apply - (*goals: 1. ‹brw_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) it Σh ⟹ br'_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (dom Q, W - {q}, rcm) it (dom Qh, Wh, rcmh)› 2. ‹brw_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) it Σh ⟹ Qh |` dom Q = Q› 3. ‹brw_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) it Σh ⟹ ∀qa t. Qh qa = Some t ⟶ Q qa = Some t ∨ Q qa = None ∧ (∃r∈{r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it. the (rcm r) ≤ 1}. qa = lhs r ∧ t = construct_witness Q r)› discuss goal 1*) apply ((auto simp add: brw_inner_invar_def (*‹brw_inner_invar ?rules ?q ≡ λ(Q, W, rcm) it (Q', W', rcm'). br'_inner_invar ?rules ?q (brw_α (Q, W, rcm)) it (brw_α (Q', W', rcm')) ∧ Q' |` dom Q = Q ∧ (let dsqr = {r ∈ ?rules - it. the (rcm r) ≤ 1} in ∀q t. Q' q = Some t ⟶ Q q = Some t ∨ Q q = None ∧ (∃r∈dsqr. q = lhs r ∧ t = construct_witness Q r))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) brw_α_def (*‹brw_α = (λ(Q, W, rcm). (dom Q, W, rcm))›*))[1]) (*discuss goal 2*) apply ((auto simp add: brw_inner_invar_def (*‹brw_inner_invar ?rules ?q ≡ λ(Q, W, rcm) it (Q', W', rcm'). br'_inner_invar ?rules ?q (brw_α (Q, W, rcm)) it (brw_α (Q', W', rcm')) ∧ Q' |` dom Q = Q ∧ (let dsqr = {r ∈ ?rules - it. the (rcm r) ≤ 1} in ∀q t. Q' q = Some t ⟶ Q q = Some t ∨ Q q = None ∧ (∃r∈dsqr. q = lhs r ∧ t = construct_witness Q r))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) brw_α_def (*‹brw_α = (λ(Q, W, rcm). (dom Q, W, rcm))›*))[1]) (*discuss goal 3*) apply ((auto simp add: brw_inner_invar_def (*‹brw_inner_invar ?rules ?q ≡ λ(Q, W, rcm) it (Q', W', rcm'). br'_inner_invar ?rules ?q (brw_α (Q, W, rcm)) it (brw_α (Q', W', rcm')) ∧ Q' |` dom Q = Q ∧ (let dsqr = {r ∈ ?rules - it. the (rcm r) ≤ 1} in ∀q t. Q' q = Some t ⟶ Q q = Some t ∨ Q q = None ∧ (∃r∈dsqr. q = lhs r ∧ t = construct_witness Q r))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) brw_α_def (*‹brw_α = (λ(Q, W, rcm). (dom Q, W, rcm))›*))[1]) (*proven 3 subgoals*) . from INVHF(1)[unfolded br'_inner_invar_def] (*‹(case (dom Q, W - {q}, rcm) of (Q, W, rcm) ⇒ λit (Q', W', rcm'). Q' = Q ∪ {lhs r |r. r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it ∧ the (rcm r) ≤ 1} ∧ W' = W - {q} ∪ ({lhs r |r. r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it ∧ the (rcm r) ≤ 1} - Q) ∧ (∀r. rcm' r = (if r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it then Some (the (rcm r) - 1) else rcm r))) it (dom Qh, Wh, rcmh)›*) have INV'HF: "dom Qh = dom Q ∪ lhs`?dsqr it" "(∀r. rcmh r = (if r ∈ ?rules - it then Some (the (rcm r) - 1) else rcm r))" apply - (*goals: 1. ‹(case (dom Q, W - {q}, rcm) of (Q, W, rcm) ⇒ λit (Q', W', rcm'). Q' = Q ∪ {lhs r |r. r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it ∧ the (rcm r) ≤ 1} ∧ W' = W - {q} ∪ ({lhs r |r. r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it ∧ the (rcm r) ≤ 1} - Q) ∧ (∀r. rcm' r = (if r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it then Some (the (rcm r) - 1) else rcm r))) it (dom Qh, Wh, rcmh) ⟹ dom Qh = dom Q ∪ lhs ` {r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it. the (rcm r) ≤ 1}› 2. ‹(case (dom Q, W - {q}, rcm) of (Q, W, rcm) ⇒ λit (Q', W', rcm'). Q' = Q ∪ {lhs r |r. r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it ∧ the (rcm r) ≤ 1} ∧ W' = W - {q} ∪ ({lhs r |r. r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it ∧ the (rcm r) ≤ 1} - Q) ∧ (∀r. rcm' r = (if r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it then Some (the (rcm r) - 1) else rcm r))) it (dom Qh, Wh, rcmh) ⟹ ∀r. rcmh r = (if r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it then Some (the (rcm r) - 1) else rcm r)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . from brw_inner_step_abs[OF STEP] (*‹br'_inner_step r (brw_α Σh) = brw_α Σ'›*) br'_inner_invar_step[OF A ( 1 ) INVHF ( 1 ) A ( 2 , 3 )] (*‹br'_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (dom Q, W - {q}, rcm) (it - {r}) (br'_inner_step r (dom Qh, Wh, rcmh))›*) have G1: "br'_inner_invar ?rules q (dom Q, W-{q}, rcm) (it-{r}) (dom Q',W',rcm')" by (simp add: brw_α_def (*‹brw_α = (λ(Q, W, rcm). (dom Q, W, rcm))›*)) moreover have "(∀q t. Q' q = Some t ⟶ (Q q = Some t ∨ ( Q q = None ∧ (∃r∈?dsqr (it-{r}). q=lhs r ∧ t=construct_witness Q r) ) ) )" (is "?G1") "Q'|`dom Q = Q" (is "?G2") proof (-) (*goals: 1. ‹∀(qa::'a) t::'b tree. (Q'::'a ⇒ 'b tree option) qa = Some t ⟶ (Q::'a ⇒ 'b tree option) qa = Some t ∨ Q qa = None ∧ (∃r::('a, 'b) ta_rule∈{ra::('a, 'b) ta_rule ∈ {r::('a, 'b) ta_rule ∈ δ::('a, 'b) ta_rule set. (q::'a) ∈ set (rhsq r)} - ((it::('a, 'b) ta_rule set) - {r::('a, 'b) ta_rule}). the ((rcm::('a, 'b) ta_rule ⇒ nat option) ra) ≤ (1::nat)}. qa = lhs r ∧ t = construct_witness Q r)› 2. ‹(Q'::'a ⇒ 'b tree option) |` dom (Q::'a ⇒ 'b tree option) = Q›*) { assume C: "¬ c≤1 ∨ lhs r ∈ dom Qh" (*‹¬ (c::nat) ≤ (1::nat) ∨ lhs (r::('a, 'b) ta_rule) ∈ dom (Qh::'a ⇒ 'b tree option)›*) with SF (*‹if (c::nat) ≤ (1::nat) ∧ lhs (r::('a::type, 'b::type) ta_rule) ∉ dom (Qh::'a::type ⇒ 'b::type tree option) then (Q'::'a::type ⇒ 'b::type tree option) = Qh(lhs r ↦ construct_witness Qh r) else Q' = Qh› ‹if c ≤ 1 ∧ lhs r ∉ dom Qh then W' = insert (lhs r) Wh else W' = Wh› ‹rcm' = rcmh(r ↦ c - 1)›*) have "Q'=Qh" by auto with INVHF(2,3) (*‹Qh |` dom Q = Q› ‹∀qa t. Qh qa = Some t ⟶ Q qa = Some t ∨ Q qa = None ∧ (∃r∈{r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it. the (rcm r) ≤ 1}. qa = lhs r ∧ t = construct_witness Q r)›*) have "?G1" "?G2" apply - (*goals: 1. ‹⟦(Qh::'a::type ⇒ 'b::type tree option) |` dom (Q::'a::type ⇒ 'b::type tree option) = Q; ∀(qa::'a::type) t::'b::type tree. Qh qa = Some t ⟶ Q qa = Some t ∨ Q qa = None ∧ (∃r::('a::type, 'b::type) ta_rule∈{r::('a::type, 'b::type) ta_rule ∈ {r::('a::type, 'b::type) ta_rule ∈ δ::('a::type, 'b::type) ta_rule set. (q::'a::type) ∈ set (rhsq r)} - (it::('a::type, 'b::type) ta_rule set). the ((rcm::('a::type, 'b::type) ta_rule ⇒ nat option) r) ≤ (1::nat)}. qa = lhs r ∧ t = construct_witness Q r); (Q'::'a::type ⇒ 'b::type tree option) = Qh⟧ ⟹ ∀(qa::'a::type) t::'b::type tree. Q' qa = Some t ⟶ Q qa = Some t ∨ Q qa = None ∧ (∃r::('a::type, 'b::type) ta_rule∈{ra::('a::type, 'b::type) ta_rule ∈ {r::('a::type, 'b::type) ta_rule ∈ δ. q ∈ set (rhsq r)} - (it - {r::('a::type, 'b::type) ta_rule}). the (rcm ra) ≤ (1::nat)}. qa = lhs r ∧ t = construct_witness Q r)› 2. ‹⟦(Qh::'a::type ⇒ 'b::type tree option) |` dom (Q::'a::type ⇒ 'b::type tree option) = Q; ∀(qa::'a::type) t::'b::type tree. Qh qa = Some t ⟶ Q qa = Some t ∨ Q qa = None ∧ (∃r::('a::type, 'b::type) ta_rule∈{r::('a::type, 'b::type) ta_rule ∈ {r::('a::type, 'b::type) ta_rule ∈ δ::('a::type, 'b::type) ta_rule set. (q::'a::type) ∈ set (rhsq r)} - (it::('a::type, 'b::type) ta_rule set). the ((rcm::('a::type, 'b::type) ta_rule ⇒ nat option) r) ≤ (1::nat)}. qa = lhs r ∧ t = construct_witness Q r); (Q'::'a::type ⇒ 'b::type tree option) = Qh⟧ ⟹ Q' |` dom Q = Q› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . } moreover { assume C: "c≤1" "lhs r∉ dom Qh" (*‹(c::nat) ≤ (1::nat)› ‹lhs (r::('a, 'b) ta_rule) ∉ dom (Qh::'a ⇒ 'b tree option)›*) with SF (*‹if c ≤ 1 ∧ lhs r ∉ dom Qh then Q' = Qh(lhs r ↦ construct_witness Qh r) else Q' = Qh› ‹if c ≤ 1 ∧ lhs r ∉ dom Qh then W' = insert (lhs r) Wh else W' = Wh› ‹rcm' = rcmh(r ↦ c - 1)›*) have Q'F: "Q'=Qh(lhs r ↦ (construct_witness Qh r))" by auto from C(2) (*‹lhs r ∉ dom Qh›*) INVHF(2) (*‹(Qh::'a ⇒ 'b tree option) |` dom (Q::'a ⇒ 'b tree option) = Q›*) INV'HF(1) (*‹dom Qh = dom Q ∪ lhs ` {r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it. the (rcm r) ≤ 1}›*) have G2: "?G2" by (auto simp add: Q'F (*‹Q' = Qh(lhs r ↦ construct_witness Qh r)›*)) from C(1) (*‹c ≤ 1›*) INV'HF (*‹dom Qh = dom Q ∪ lhs ` {r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it. the (rcm r) ≤ 1}› ‹∀r. rcmh r = (if r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it then Some (the (rcm r) - 1) else rcm r)›*) A (*‹q ∈ W› ‹r ∈ it› ‹(it::('a::type, 'b::type) ta_rule set) ⊆ {r::('a::type, 'b::type) ta_rule ∈ δ::('a::type, 'b::type) ta_rule set. (q::'a::type) ∈ set (rhsq r)}›*) have RI: "r∈?dsqr (it-{r})" and DSS: "dom Q ⊆ dom Qh" apply - (*goals: 1. ‹⟦c ≤ 1; dom Qh = dom Q ∪ lhs ` {r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it. the (rcm r) ≤ 1}; ∀r. rcmh r = (if r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it then Some (the (rcm r) - 1) else rcm r); q ∈ W; r ∈ it; it ⊆ {r ∈ δ. q ∈ set (rhsq r)}⟧ ⟹ r ∈ {ra ∈ {r ∈ δ. q ∈ set (rhsq r)} - (it - {r}). the (rcm ra) ≤ 1}› 2. ‹⟦c ≤ 1; dom Qh = dom Q ∪ lhs ` {r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it. the (rcm r) ≤ 1}; ∀r. rcmh r = (if r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it then Some (the (rcm r) - 1) else rcm r); q ∈ W; r ∈ it; it ⊆ {r ∈ δ. q ∈ set (rhsq r)}⟧ ⟹ dom Q ⊆ dom Qh› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . from br'_rcm_aux'[OF BR'_INV A ( 1 )] (*‹{r ∈ δ. q ∈ set (rhsq r) ∧ the (rcm r) ≤ Suc 0} = {r ∈ δ. q ∈ set (rhsq r) ∧ set (rhsq r) ⊆ dom Q - (W - {q})}›*) RI (*‹r ∈ {ra ∈ {r ∈ δ. q ∈ set (rhsq r)} - (it - {r}). the (rcm ra) ≤ 1}›*) have RDQ: "set (rhsq r) ⊆ dom Q" by auto with INVHF(2) (*‹Qh |` dom Q = Q›*) have "Qh |` set (rhsq r) = Q |` set (rhsq r)" by (blast intro: restrict_map_subset_eq (*‹⟦?m |` ?R = ?m'; ?R' ⊆ ?R⟧ ⟹ ?m |` ?R' = ?m' |` ?R'›*)) hence [simp]: "construct_witness Qh r = construct_witness Q r" by (blast dest: construct_witness_eq (*‹?Q |` set (rhsq ?r) = ?Q' |` set (rhsq ?r) ⟹ construct_witness ?Q ?r = construct_witness ?Q' ?r›*)) from DSS (*‹dom Q ⊆ dom Qh›*) C(2) (*‹lhs (r::('a, 'b) ta_rule) ∉ dom (Qh::'a ⇒ 'b tree option)›*) have [simp]: "Q (lhs r) = None" "Qh (lhs r) = None" apply - (*goals: 1. ‹⟦dom Q ⊆ dom Qh; lhs r ∉ dom Qh⟧ ⟹ Q (lhs r) = None› 2. ‹⟦dom Q ⊆ dom Qh; lhs r ∉ dom Qh⟧ ⟹ Qh (lhs r) = None› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have G1: "?G1" apply (intro allI (*‹(⋀x::?'a::type. (?P::?'a::type ⇒ bool) x) ⟹ ∀x::?'a::type. ?P x›*) impI (*‹(?P::bool ⟹ ?Q::bool) ⟹ ?P ⟶ ?Q›*)) (*goal: ‹∀qa t. Q' qa = Some t ⟶ Q qa = Some t ∨ Q qa = None ∧ (∃r∈{ra ∈ {r ∈ δ. q ∈ set (rhsq r)} - (it - {r}). the (rcm ra) ≤ 1}. qa = lhs r ∧ t = construct_witness Q r)›*) proof (goal_cases) (*goal: ‹⋀(qa::'a::type) t::'b::type tree. (Q'::'a::type ⇒ 'b::type tree option) qa = Some t ⟹ (Q::'a::type ⇒ 'b::type tree option) qa = Some t ∨ Q qa = None ∧ (∃r::('a::type, 'b::type) ta_rule∈{ra::('a::type, 'b::type) ta_rule ∈ {r::('a::type, 'b::type) ta_rule ∈ δ::('a::type, 'b::type) ta_rule set. (q::'a::type) ∈ set (rhsq r)} - ((it::('a::type, 'b::type) ta_rule set) - {r::('a::type, 'b::type) ta_rule}). the ((rcm::('a::type, 'b::type) ta_rule ⇒ nat option) ra) ≤ (1::nat)}. qa = lhs r ∧ t = construct_witness Q r)›*) case prems: (1 q t) (*‹(Q'::'a::type ⇒ 'b::type tree option) (q::'a::type) = Some (t::'b::type tree)›*) { assume [simp]: "q=lhs r" (*‹(q::'a) = lhs (r::('a, 'b) ta_rule)›*) from prems (*‹Q' q = Some t›*) Q'F (*‹Q' = Qh(lhs r ↦ construct_witness Qh r)›*) have [simp]: "t = (construct_witness Qh r)" by simp from RI (*‹r ∈ {ra ∈ {r ∈ δ. q ∈ set (rhsq r)} - (it - {r}). the (rcm ra) ≤ 1}›*) have "?case" by auto } moreover { assume "q≠lhs r" (*‹(q::'a) ≠ lhs (r::('a, 'b) ta_rule)›*) with Q'F (*‹Q' = Qh(lhs r ↦ construct_witness Qh r)›*) prems (*‹Q' q = Some t›*) have "Qh q = Some t" by auto with INVHF(3) (*‹∀qa t. Qh qa = Some t ⟶ Q qa = Some t ∨ Q qa = None ∧ (∃r∈{r ∈ {r ∈ δ. q ∈ set (rhsq r)} - it. the (rcm r) ≤ 1}. qa = lhs r ∧ t = construct_witness Q r)›*) have "?case" by auto } ultimately show "?case" (*goal: ‹Q q = Some t ∨ Q q = None ∧ (∃r∈{ra ∈ {r ∈ δ. q ∈ set (rhsq r)} - (it - {r}). the (rcm ra) ≤ 1}. q = lhs r ∧ t = construct_witness Q r)›*) by blast qed note G1 (*‹∀qa t. Q' qa = Some t ⟶ Q qa = Some t ∨ Q qa = None ∧ (∃r∈{ra ∈ {r ∈ δ. q ∈ set (rhsq r)} - (it - {r}). the (rcm ra) ≤ 1}. qa = lhs r ∧ t = construct_witness Q r)›*) G2 (*‹Q' |` dom Q = Q›*) } ultimately show "?G1" "?G2" apply - (*goals: 1. ‹⟦¬ c ≤ 1 ∨ lhs r ∈ dom Qh ⟹ ∀qa t. Q' qa = Some t ⟶ Q qa = Some t ∨ Q qa = None ∧ (∃r∈{ra ∈ {r ∈ δ. q ∈ set (rhsq r)} - (it - {r}). the (rcm ra) ≤ 1}. qa = lhs r ∧ t = construct_witness Q r); ¬ c ≤ 1 ∨ lhs r ∈ dom Qh ⟹ Q' |` dom Q = Q; ⟦c ≤ 1; lhs r ∉ dom Qh⟧ ⟹ ∀qa t. Q' qa = Some t ⟶ Q qa = Some t ∨ Q qa = None ∧ (∃r∈{ra ∈ {r ∈ δ. q ∈ set (rhsq r)} - (it - {r}). the (rcm ra) ≤ 1}. qa = lhs r ∧ t = construct_witness Q r); ⟦c ≤ 1; lhs r ∉ dom Qh⟧ ⟹ Q' |` dom Q = Q⟧ ⟹ ∀qa t. Q' qa = Some t ⟶ Q qa = Some t ∨ Q qa = None ∧ (∃r∈{ra ∈ {r ∈ δ. q ∈ set (rhsq r)} - (it - {r}). the (rcm ra) ≤ 1}. qa = lhs r ∧ t = construct_witness Q r)› 2. ‹⟦¬ c ≤ 1 ∨ lhs r ∈ dom Qh ⟹ ∀qa t. Q' qa = Some t ⟶ Q qa = Some t ∨ Q qa = None ∧ (∃r∈{ra ∈ {r ∈ δ. q ∈ set (rhsq r)} - (it - {r}). the (rcm ra) ≤ 1}. qa = lhs r ∧ t = construct_witness Q r); ¬ c ≤ 1 ∨ lhs r ∈ dom Qh ⟹ Q' |` dom Q = Q; ⟦c ≤ 1; lhs r ∉ dom Qh⟧ ⟹ ∀qa t. Q' qa = Some t ⟶ Q qa = Some t ∨ Q qa = None ∧ (∃r∈{ra ∈ {r ∈ δ. q ∈ set (rhsq r)} - (it - {r}). the (rcm ra) ≤ 1}. qa = lhs r ∧ t = construct_witness Q r); ⟦c ≤ 1; lhs r ∉ dom Qh⟧ ⟹ Q' |` dom Q = Q⟧ ⟹ Q' |` dom Q = Q› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) . qed ultimately show "?thesis" (*goal: ‹brw_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) (it - {r}) Σ'›*) apply (unfold brw_inner_invar_def (*‹brw_inner_invar ?rules ?q ≡ λ(Q, W, rcm) it (Q', W', rcm'). br'_inner_invar ?rules ?q (brw_α (Q, W, rcm)) it (brw_α (Q', W', rcm')) ∧ Q' |` dom Q = Q ∧ (let dsqr = {r ∈ ?rules - it. the (rcm r) ≤ 1} in ∀q t. Q' q = Some t ⟶ Q q = Some t ∨ Q q = None ∧ (∃r∈dsqr. q = lhs r ∧ t = construct_witness Q r))›*) Let_def (*‹Let ?s ?f ≡ ?f ?s›*) brw_α_def (*‹brw_α = (λ(Q, W, rcm). (dom Q, W, rcm))›*)) (*goal: ‹brw_inner_invar {r::('a, 'b) ta_rule ∈ δ::('a, 'b) ta_rule set. (q::'a) ∈ set (rhsq r)} q (Q::'a ⇒ 'b tree option, (W::'a set) - {q}, rcm::('a, 'b) ta_rule ⇒ nat option) ((it::('a, 'b) ta_rule set) - {r::('a, 'b) ta_rule}) (Σ'::('a ⇒ 'b tree option) × 'a set × (('a, 'b) ta_rule ⇒ nat option))›*) by auto qed lemma brw_inner_invar_initial: "⟦q∈W⟧ ⟹ brw_inner_invar {r∈δ. q∈set (rhsq r)} q (Q,W-{q},rcm) {r∈δ. q∈set (rhsq r)} (Q,W-{q},rcm)" by (simp add: brw_inner_invar_def (*‹brw_inner_invar ?rules ?q ≡ λ(Q, W, rcm) it (Q', W', rcm'). br'_inner_invar ?rules ?q (brw_α (Q, W, rcm)) it (brw_α (Q', W', rcm')) ∧ Q' |` dom Q = Q ∧ (let dsqr = {r ∈ ?rules - it. the (rcm r) ≤ 1} in ∀q t. Q' q = Some t ⟶ Q q = Some t ∨ Q q = None ∧ (∃r∈dsqr. q = lhs r ∧ t = construct_witness Q r))›*) br'_inner_invar_initial (*‹?q ∈ ?W ⟹ br'_inner_invar {r ∈ ?δ. ?q ∈ set (rhsq r)} ?q (?Q, ?W - {?q}, ?rcm) {r ∈ ?δ. ?q ∈ set (rhsq r)} (?Q, ?W - {?q}, ?rcm)›*) brw_α_def (*‹brw_α = (λ(Q, W, rcm). (dom Q, W, rcm))›*)) theorem brw_inner_step_proof: fixes αs :: "'Σ ⇒ ('Q,'L) brw_state" fixes cstep :: "('Q,'L) ta_rule ⇒ 'Σ ⇒ 'Σ" fixes Σh :: "'Σ" fixes cinvar :: "('Q,'L) ta_rule set ⇒ 'Σ ⇒ bool" assumes set_iterate: "set_iteratei α invar iteratei" assumes invar_start: "(αs Σ)∈brw_invar δ" assumes invar_initial: "cinvar {r∈δ. q∈set (rhsq r)} Σh" assumes invar_step: "!!it r Σ. ⟦ r∈it; it ⊆ {r∈δ. q∈set (rhsq r)}; cinvar it Σ ⟧ ⟹ cinvar (it-{r}) (cstep r Σ)" assumes step_desc: "!!it r Σ. ⟦ r∈it; it⊆{r∈δ. q∈set (rhsq r)}; cinvar it Σ ⟧ ⟹ (αs Σ, αs (cstep r Σ)) ∈ brw_inner_step r" assumes it_set_desc: "invar it_set" "α it_set = {r∈δ. q∈set (rhsq r)}" assumes QIW[simp]: "q∈W" assumes Σ_desc[simp]: "αs Σ = (Q,W,rcm)" assumes Σh_desc[simp]: "αs Σh = (Q,W-{q},rcm)" shows "(αs Σ, αs (iteratei it_set (λ_. True) cstep Σh))∈brw_step δ" proof (-) (*goal: ‹(αs Σ, αs (iteratei it_set (λ_. True) cstep Σh)) ∈ brw_step δ›*) interpret set_iteratei "α" invar iteratei by fact show "?thesis" (*goal: ‹(αs Σ, αs (iteratei it_set (λ_. True) cstep Σh)) ∈ brw_step δ›*) apply (rule_tac I="λit Σ. cinvar it Σ ∧ brw_inner_invar {r∈δ. q∈set (rhsq r)} q (Q,W-{q},rcm) it (αs Σ)" in iterate_rule_P (*‹⟦invar ?S; ?I (α ?S) ?σ0.0; ⋀x it σ. ⟦x ∈ it; it ⊆ α ?S; ?I it σ⟧ ⟹ ?I (it - {x}) (?f x σ); ⋀σ. ?I {} σ ⟹ ?P σ⟧ ⟹ ?P (iteratei ?S (λ_. True) ?f ?σ0.0)›*)) (*goals: 1. ‹invar it_set› 2. ‹cinvar (α it_set) Σh ∧ brw_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) (α it_set) (αs Σh)› 3. ‹⋀x it σ. ⟦x ∈ it; it ⊆ α it_set; cinvar it σ ∧ brw_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) it (αs σ)⟧ ⟹ cinvar (it - {x}) (cstep x σ) ∧ brw_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) (it - {x}) (αs (cstep x σ))› 4. ‹⋀σ. cinvar {} σ ∧ brw_inner_invar {r ∈ δ. q ∈ set (rhsq r)} q (Q, W - {q}, rcm) {} (αs σ) ⟹ (αs Σ, αs σ) ∈ brw_step δ› discuss goal 1*) apply ((auto simp add: it_set_desc (*‹invar it_set› ‹α it_set = {r ∈ δ. q ∈ set (rhsq r)}›*) invar_initial (*‹cinvar {r ∈ δ. q ∈ set (rhsq r)} Σh›*) brw_inner_invar_initial (*‹?q ∈ ?W ⟹ brw_inner_invar {r ∈ ?δ. ?q ∈ set (rhsq r)} ?q (?Q, ?W - {?q}, ?rcm) {r ∈ ?δ. ?q ∈ set (rhsq r)} (?Q, ?W - {?q}, ?rcm)›*) invar_step (*‹⟦?r ∈ ?it; ?it ⊆ {r ∈ δ. q ∈ set (rhsq r)}; cinvar ?it ?Σ⟧ ⟹ cinvar (?it - {?r}) (cstep ?r ?Σ)›*) step_desc (*‹⟦?r ∈ ?it; ?it ⊆ {r ∈ δ. q ∈ set (rhsq r)}; cinvar ?it ?Σ⟧ ⟹ (αs ?Σ, αs (cstep ?r ?Σ)) ∈ brw_inner_step ?r›*) brw_inner_invar_step[OF invar_start[simplified]] (*‹⟦?q ∈ W; ?r ∈ ?it; ?it ⊆ {r ∈ δ. ?q ∈ set (rhsq r)}; brw_inner_invar {r ∈ δ. ?q ∈ set (rhsq r)} ?q (Q, W - {?q}, rcm) ?it ?Σh; (?Σh, ?Σ') ∈ brw_inner_step ?r⟧ ⟹ brw_inner_invar {r ∈ δ. ?q ∈ set (rhsq r)} ?q (Q, W - {?q}, rcm) (?it - {?r}) ?Σ'›*) brw_inner_invar_imp_final[OF QIW] (*‹brw_inner_invar {r ∈ ?δ. q ∈ set (rhsq r)} q (?Q, W - {q}, ?rcm) {} ?Σ' ⟹ ((?Q, W, ?rcm), ?Σ') ∈ brw_step ?δ›*))[1]) (*discuss goal 2*) apply ((auto simp add: it_set_desc (*‹(invar::'a::type ⇒ bool) (it_set::'a::type)› ‹(α::'a::type ⇒ ('Q::type, 'L::type) ta_rule set) (it_set::'a::type) = {r::('Q::type, 'L::type) ta_rule ∈ δ::('Q::type, 'L::type) ta_rule set. (q::'Q::type) ∈ set (rhsq r)}›*) invar_initial (*‹(cinvar::('Q::type, 'L::type) ta_rule set ⇒ 'Σ::type ⇒ bool) {r::('Q::type, 'L::type) ta_rule ∈ δ::('Q::type, 'L::type) ta_rule set. (q::'Q::type) ∈ set (rhsq r)} (Σh::'Σ::type)›*) brw_inner_invar_initial (*‹(?q::?'a::type) ∈ (?W::?'a::type set) ⟹ brw_inner_invar {r::(?'a::type, ?'b::type) ta_rule ∈ ?δ::(?'a::type, ?'b::type) ta_rule set. ?q ∈ set (rhsq r)} ?q (?Q::?'a::type ⇒ ?'b::type tree option, ?W - {?q}, ?rcm::(?'a::type, ?'b::type) ta_rule ⇒ nat option) {r::(?'a::type, ?'b::type) ta_rule ∈ ?δ. ?q ∈ set (rhsq r)} (?Q, ?W - {?q}, ?rcm)›*) invar_step (*‹⟦(?r::('Q::type, 'L::type) ta_rule) ∈ (?it::('Q::type, 'L::type) ta_rule set); ?it ⊆ {r::('Q::type, 'L::type) ta_rule ∈ δ::('Q::type, 'L::type) ta_rule set. (q::'Q::type) ∈ set (rhsq r)}; (cinvar::('Q::type, 'L::type) ta_rule set ⇒ 'Σ::type ⇒ bool) ?it (?Σ::'Σ::type)⟧ ⟹ cinvar (?it - {?r}) ((cstep::('Q::type, 'L::type) ta_rule ⇒ 'Σ::type ⇒ 'Σ::type) ?r ?Σ)›*) step_desc (*‹⟦(?r::('Q::type, 'L::type) ta_rule) ∈ (?it::('Q::type, 'L::type) ta_rule set); ?it ⊆ {r::('Q::type, 'L::type) ta_rule ∈ δ::('Q::type, 'L::type) ta_rule set. (q::'Q::type) ∈ set (rhsq r)}; (cinvar::('Q::type, 'L::type) ta_rule set ⇒ 'Σ::type ⇒ bool) ?it (?Σ::'Σ::type)⟧ ⟹ ((αs::'Σ::type ⇒ ('Q::type ⇒ 'L::type tree option) × 'Q::type set × (('Q::type, 'L::type) ta_rule ⇒ nat option)) ?Σ, αs ((cstep::('Q::type, 'L::type) ta_rule ⇒ 'Σ::type ⇒ 'Σ::type) ?r ?Σ)) ∈ brw_inner_step ?r›*) brw_inner_invar_step[OF invar_start[simplified]] (*‹⟦(?q::'Q::type) ∈ (W::'Q::type set); (?r::('Q::type, 'L::type) ta_rule) ∈ (?it::('Q::type, 'L::type) ta_rule set); ?it ⊆ {r::('Q::type, 'L::type) ta_rule ∈ δ::('Q::type, 'L::type) ta_rule set. ?q ∈ set (rhsq r)}; brw_inner_invar {r::('Q::type, 'L::type) ta_rule ∈ δ. ?q ∈ set (rhsq r)} ?q (Q::'Q::type ⇒ 'L::type tree option, W - {?q}, rcm::('Q::type, 'L::type) ta_rule ⇒ nat option) ?it (?Σh::('Q::type ⇒ 'L::type tree option) × 'Q::type set × (('Q::type, 'L::type) ta_rule ⇒ nat option)); (?Σh, ?Σ'::('Q::type ⇒ 'L::type tree option) × 'Q::type set × (('Q::type, 'L::type) ta_rule ⇒ nat option)) ∈ brw_inner_step ?r⟧ ⟹ brw_inner_invar {r::('Q::type, 'L::type) ta_rule ∈ δ. ?q ∈ set (rhsq r)} ?q (Q, W - {?q}, rcm) (?it - {?r}) ?Σ'›*) brw_inner_invar_imp_final[OF QIW] (*‹brw_inner_invar {r::('Q::type, ?'b::type) ta_rule ∈ ?δ::('Q::type, ?'b::type) ta_rule set. (q::'Q::type) ∈ set (rhsq r)} q (?Q::'Q::type ⇒ ?'b::type tree option, (W::'Q::type set) - {q}, ?rcm::('Q::type, ?'b::type) ta_rule ⇒ nat option) {} (?Σ'::('Q::type ⇒ ?'b::type tree option) × 'Q::type set × (('Q::type, ?'b::type) ta_rule ⇒ nat option)) ⟹ ((?Q, W, ?rcm), ?Σ') ∈ brw_step ?δ›*))[1]) (*discuss goal 3*) apply ((auto simp add: it_set_desc (*‹invar it_set› ‹α it_set = {r ∈ δ. q ∈ set (rhsq r)}›*) invar_initial (*‹cinvar {r ∈ δ. q ∈ set (rhsq r)} Σh›*) brw_inner_invar_initial (*‹?q ∈ ?W ⟹ brw_inner_invar {r ∈ ?δ. ?q ∈ set (rhsq r)} ?q (?Q, ?W - {?q}, ?rcm) {r ∈ ?δ. ?q ∈ set (rhsq r)} (?Q, ?W - {?q}, ?rcm)›*) invar_step (*‹⟦?r ∈ ?it; ?it ⊆ {r ∈ δ. q ∈ set (rhsq r)}; cinvar ?it ?Σ⟧ ⟹ cinvar (?it - {?r}) (cstep ?r ?Σ)›*) step_desc (*‹⟦?r ∈ ?it; ?it ⊆ {r ∈ δ. q ∈ set (rhsq r)}; cinvar ?it ?Σ⟧ ⟹ (αs ?Σ, αs (cstep ?r ?Σ)) ∈ brw_inner_step ?r›*) brw_inner_invar_step[OF invar_start[simplified]] (*‹⟦?q ∈ W; ?r ∈ ?it; ?it ⊆ {r ∈ δ. ?q ∈ set (rhsq r)}; brw_inner_invar {r ∈ δ. ?q ∈ set (rhsq r)} ?q (Q, W - {?q}, rcm) ?it ?Σh; (?Σh, ?Σ') ∈ brw_inner_step ?r⟧ ⟹ brw_inner_invar {r ∈ δ. ?q ∈ set (rhsq r)} ?q (Q, W - {?q}, rcm) (?it - {?r}) ?Σ'›*) brw_inner_invar_imp_final[OF QIW] (*‹brw_inner_invar {r ∈ ?δ. q ∈ set (rhsq r)} q (?Q, W - {q}, ?rcm) {} ?Σ' ⟹ ((?Q, W, ?rcm), ?Σ') ∈ brw_step ?δ›*))[1]) (*discuss goal 4*) apply ((auto simp add: it_set_desc (*‹invar it_set› ‹α it_set = {r ∈ δ. q ∈ set (rhsq r)}›*) invar_initial (*‹cinvar {r ∈ δ. q ∈ set (rhsq r)} Σh›*) brw_inner_invar_initial (*‹?q ∈ ?W ⟹ brw_inner_invar {r ∈ ?δ. ?q ∈ set (rhsq r)} ?q (?Q, ?W - {?q}, ?rcm) {r ∈ ?δ. ?q ∈ set (rhsq r)} (?Q, ?W - {?q}, ?rcm)›*) invar_step (*‹⟦?r ∈ ?it; ?it ⊆ {r ∈ δ. q ∈ set (rhsq r)}; cinvar ?it ?Σ⟧ ⟹ cinvar (?it - {?r}) (cstep ?r ?Σ)›*) step_desc (*‹⟦?r ∈ ?it; ?it ⊆ {r ∈ δ. q ∈ set (rhsq r)}; cinvar ?it ?Σ⟧ ⟹ (αs ?Σ, αs (cstep ?r ?Σ)) ∈ brw_inner_step ?r›*) brw_inner_invar_step[OF invar_start[simplified]] (*‹⟦?q ∈ W; ?r ∈ ?it; ?it ⊆ {r ∈ δ. ?q ∈ set (rhsq r)}; brw_inner_invar {r ∈ δ. ?q ∈ set (rhsq r)} ?q (Q, W - {?q}, rcm) ?it ?Σh; (?Σh, ?Σ') ∈ brw_inner_step ?r⟧ ⟹ brw_inner_invar {r ∈ δ. ?q ∈ set (rhsq r)} ?q (Q, W - {?q}, rcm) (?it - {?r}) ?Σ'›*) brw_inner_invar_imp_final[OF QIW] (*‹brw_inner_invar {r ∈ ?δ. q ∈ set (rhsq r)} q (?Q, W - {q}, ?rcm) {} ?Σ' ⟹ ((?Q, W, ?rcm), ?Σ') ∈ brw_step ?δ›*))[1]) (*proven 4 subgoals*) . qed subsection ‹Product Automaton› text ‹ The forward-reduced product automaton can be described as a state-space exploration problem. In this section, the DFS-algorithm for state-space exploration (cf. Theory~@{theory Collections_Examples.Exploration} in the Isabelle Collections Framework) is refined to compute the product automaton. › type_synonym ('Q1,'Q2,'L) frp_state = "('Q1×'Q2) set × ('Q1×'Q2) list × (('Q1×'Q2),'L) ta_rule set" definition frp_α :: "('Q1,'Q2,'L) frp_state ⇒ ('Q1×'Q2) dfs_state" where "frp_α S == let (Q,W,δ)=S in (Q, W)" definition "frp_invar_add δ1 δ2 == { (Q,W,δd). δd = { r. r∈δ_prod δ1 δ2 ∧ lhs r ∈ Q - set W} }" definition frp_invar :: "('Q1, 'L) tree_automaton_rec ⇒ ('Q2, 'L) tree_automaton_rec ⇒ ('Q1,'Q2,'L) frp_state set" where "frp_invar T1 T2 == frp_invar_add (ta_rules T1) (ta_rules T2) ∩ { s. frp_α s ∈ dfs_invar (ta_initial T1 × ta_initial T2) (f_succ (δ_prod (ta_rules T1) (ta_rules T2))) }" inductive_set frp_step :: "('Q1,'L) ta_rule set ⇒ ('Q2,'L) ta_rule set ⇒ (('Q1,'Q2,'L) frp_state × ('Q1,'Q2,'L) frp_state) set" for δ1 δ2 where "⟦ W=(q1,q2)#Wtl; distinct Wn; set Wn = f_succ (δ_prod δ1 δ2) `` {(q1,q2)} - Q; W'=Wn@Wtl; Q'=Q ∪ f_succ (δ_prod δ1 δ2) `` {(q1,q2)}; δd'=δd ∪ {r∈δ_prod δ1 δ2. lhs r = (q1,q2) } ⟧ ⟹ ((Q,W,δd),(Q',W',δd'))∈frp_step δ1 δ2" inductive_set frp_initial :: "'Q1 set ⇒ 'Q2 set ⇒ ('Q1,'Q2,'L) frp_state set" for Q10 Q20 where "⟦ distinct W; set W = Q10×Q20 ⟧ ⟹ (Q10×Q20,W,{}) ∈ frp_initial Q10 Q20" definition frp_cond :: "('Q1,'Q2,'L) frp_state set" where "frp_cond == {(Q,W,δd). W≠[]}" definition "frp_algo T1 T2 == ⦇ wa_cond = frp_cond, wa_step = frp_step (ta_rules T1) (ta_rules T2), wa_initial = frp_initial (ta_initial T1) (ta_initial T2), wa_invar = frp_invar T1 T2 ⦈" ― ‹The algorithm refines the DFS-algorithm› theorem frp_pref_dfs: "wa_precise_refine (frp_algo T1 T2) (dfs_algo (ta_initial T1 × ta_initial T2) (f_succ (δ_prod (ta_rules T1) (ta_rules T2)))) frp_α" apply unfold_locales (*goals: 1. ‹⋀s. ⟦s ∈ wa_invar (frp_algo T1 T2); s ∈ wa_cond (frp_algo T1 T2)⟧ ⟹ frp_α s ∈ wa_cond (dfs_algo (ta_initial T1 × ta_initial T2) (f_succ (δ_prod (ta_rules T1) (ta_rules T2))))› 2. ‹⋀s s'. ⟦s ∈ wa_invar (frp_algo T1 T2); s ∈ wa_cond (frp_algo T1 T2); (s, s') ∈ wa_step (frp_algo T1 T2)⟧ ⟹ (frp_α s, frp_α s') ∈ wa_step (dfs_algo (ta_initial T1 × ta_initial T2) (f_succ (δ_prod (ta_rules T1) (ta_rules T2))))› 3. ‹frp_α ` wa_initial (frp_algo T1 T2) ⊆ wa_initial (dfs_algo (ta_initial T1 × ta_initial T2) (f_succ (δ_prod (ta_rules T1) (ta_rules T2))))› 4. ‹frp_α ` wa_invar (frp_algo T1 T2) ⊆ wa_invar (dfs_algo (ta_initial T1 × ta_initial T2) (f_succ (δ_prod (ta_rules T1) (ta_rules T2))))› 5. ‹∀s. s ∈ wa_invar (frp_algo T1 T2) ∧ frp_α s ∈ wa_cond (dfs_algo (ta_initial T1 × ta_initial T2) (f_succ (δ_prod (ta_rules T1) (ta_rules T2)))) ⟶ s ∈ wa_cond (frp_algo T1 T2)› discuss goal 1*) apply ((auto simp add: frp_algo_def (*‹frp_algo ?T1.0 ?T2.0 ≡ ⦇wa_cond = frp_cond, wa_step = frp_step (ta_rules ?T1.0) (ta_rules ?T2.0), wa_initial = frp_initial (ta_initial ?T1.0) (ta_initial ?T2.0), wa_invar = frp_invar ?T1.0 ?T2.0⦈›*) frp_α_def (*‹frp_α ?S ≡ let (Q, W, δ) = ?S in (Q, W)›*) frp_cond_def (*‹frp_cond ≡ {(Q, W, δd). W ≠ []}›*) dfs_algo_def (*‹dfs_algo ?Σi ?R ≡ ⦇wa_cond = dfs_cond, wa_step = dfs_step ?R, wa_initial = dfs_initial ?Σi, wa_invar = dfs_invar ?Σi ?R⦈›*) dfs_cond_def (*‹dfs_cond ≡ {(Σ, W). W ≠ []}›*) frp_invar_def (*‹frp_invar ?T1.0 ?T2.0 ≡ frp_invar_add (ta_rules ?T1.0) (ta_rules ?T2.0) ∩ {s. frp_α s ∈ dfs_invar (ta_initial ?T1.0 × ta_initial ?T2.0) (f_succ (δ_prod (ta_rules ?T1.0) (ta_rules ?T2.0)))}›*) elim!: frp_step.cases (*‹⟦((?a1.0, ?a2.0, ?a3.0), ?a4.0, ?a5.0, ?a6.0) ∈ frp_step ?δ1.0 ?δ2.0; ⋀W q1 q2 Wtl Wn Q W' Q' δd' δd. ⟦?a1.0 = Q; ?a2.0 = W; ?a3.0 = δd; ?a4.0 = Q'; ?a5.0 = W'; ?a6.0 = δd'; W = (q1, q2) # Wtl; distinct Wn; set Wn = f_succ (δ_prod ?δ1.0 ?δ2.0) `` {(q1, q2)} - Q; W' = Wn @ Wtl; Q' = Q ∪ f_succ (δ_prod ?δ1.0 ?δ2.0) `` {(q1, q2)}; δd' = δd ∪ {r ∈ δ_prod ?δ1.0 ?δ2.0. lhs r = (q1, q2)}⟧ ⟹ ?P⟧ ⟹ ?P›*) frp_initial.cases (*‹⟦(?a1.0, ?a2.0, ?a3.0) ∈ frp_initial ?Q10.0 ?Q20.0; ⋀W. ⟦?a1.0 = ?Q10.0 × ?Q20.0; ?a2.0 = W; ?a3.0 = {}; distinct W; set W = ?Q10.0 × ?Q20.0⟧ ⟹ ?P⟧ ⟹ ?P›*) intro: dfs_step.intros (*‹⟦?W = ?σ # ?Wtl; distinct ?Wn; set ?Wn = ?R `` {?σ} - ?Σ; ?W' = ?Wn @ ?Wtl; ?Σ' = ?R `` {?σ} ∪ ?Σ⟧ ⟹ ((?Σ, ?W), ?Σ', ?W') ∈ dfs_step ?R›*) dfs_initial.intros (*‹⟦distinct ?W; set ?W = ?Σi⟧ ⟹ (?Σi, ?W) ∈ dfs_initial ?Σi›*))[1]) (*discuss goal 2*) apply ((auto simp add: frp_algo_def (*‹frp_algo ?T1.0 ?T2.0 ≡ ⦇wa_cond = frp_cond, wa_step = frp_step (ta_rules ?T1.0) (ta_rules ?T2.0), wa_initial = frp_initial (ta_initial ?T1.0) (ta_initial ?T2.0), wa_invar = frp_invar ?T1.0 ?T2.0⦈›*) frp_α_def (*‹frp_α ?S ≡ let (Q, W, δ) = ?S in (Q, W)›*) frp_cond_def (*‹frp_cond ≡ {(Q, W, δd). W ≠ []}›*) dfs_algo_def (*‹dfs_algo ?Σi ?R ≡ ⦇wa_cond = dfs_cond, wa_step = dfs_step ?R, wa_initial = dfs_initial ?Σi, wa_invar = dfs_invar ?Σi ?R⦈›*) dfs_cond_def (*‹dfs_cond ≡ {(Σ, W). W ≠ []}›*) frp_invar_def (*‹frp_invar ?T1.0 ?T2.0 ≡ frp_invar_add (ta_rules ?T1.0) (ta_rules ?T2.0) ∩ {s. frp_α s ∈ dfs_invar (ta_initial ?T1.0 × ta_initial ?T2.0) (f_succ (δ_prod (ta_rules ?T1.0) (ta_rules ?T2.0)))}›*) elim!: frp_step.cases (*‹⟦((?a1.0, ?a2.0, ?a3.0), ?a4.0, ?a5.0, ?a6.0) ∈ frp_step ?δ1.0 ?δ2.0; ⋀W q1 q2 Wtl Wn Q W' Q' δd' δd. ⟦?a1.0 = Q; ?a2.0 = W; ?a3.0 = δd; ?a4.0 = Q'; ?a5.0 = W'; ?a6.0 = δd'; W = (q1, q2) # Wtl; distinct Wn; set Wn = f_succ (δ_prod ?δ1.0 ?δ2.0) `` {(q1, q2)} - Q; W' = Wn @ Wtl; Q' = Q ∪ f_succ (δ_prod ?δ1.0 ?δ2.0) `` {(q1, q2)}; δd' = δd ∪ {r ∈ δ_prod ?δ1.0 ?δ2.0. lhs r = (q1, q2)}⟧ ⟹ ?P⟧ ⟹ ?P›*) frp_initial.cases (*‹⟦(?a1.0, ?a2.0, ?a3.0) ∈ frp_initial ?Q10.0 ?Q20.0; ⋀W. ⟦?a1.0 = ?Q10.0 × ?Q20.0; ?a2.0 = W; ?a3.0 = {}; distinct W; set W = ?Q10.0 × ?Q20.0⟧ ⟹ ?P⟧ ⟹ ?P›*) intro: dfs_step.intros (*‹⟦?W = ?σ # ?Wtl; distinct ?Wn; set ?Wn = ?R `` {?σ} - ?Σ; ?W' = ?Wn @ ?Wtl; ?Σ' = ?R `` {?σ} ∪ ?Σ⟧ ⟹ ((?Σ, ?W), ?Σ', ?W') ∈ dfs_step ?R›*) dfs_initial.intros (*‹⟦distinct ?W; set ?W = ?Σi⟧ ⟹ (?Σi, ?W) ∈ dfs_initial ?Σi›*))[1]) (*discuss goal 3*) apply ((auto simp add: frp_algo_def (*‹frp_algo ?T1.0 ?T2.0 ≡ ⦇wa_cond = frp_cond, wa_step = frp_step (ta_rules ?T1.0) (ta_rules ?T2.0), wa_initial = frp_initial (ta_initial ?T1.0) (ta_initial ?T2.0), wa_invar = frp_invar ?T1.0 ?T2.0⦈›*) frp_α_def (*‹frp_α ?S ≡ let (Q, W, δ) = ?S in (Q, W)›*) frp_cond_def (*‹frp_cond ≡ {(Q, W, δd). W ≠ []}›*) dfs_algo_def (*‹dfs_algo ?Σi ?R ≡ ⦇wa_cond = dfs_cond, wa_step = dfs_step ?R, wa_initial = dfs_initial ?Σi, wa_invar = dfs_invar ?Σi ?R⦈›*) dfs_cond_def (*‹dfs_cond ≡ {(Σ, W). W ≠ []}›*) frp_invar_def (*‹frp_invar ?T1.0 ?T2.0 ≡ frp_invar_add (ta_rules ?T1.0) (ta_rules ?T2.0) ∩ {s. frp_α s ∈ dfs_invar (ta_initial ?T1.0 × ta_initial ?T2.0) (f_succ (δ_prod (ta_rules ?T1.0) (ta_rules ?T2.0)))}›*) elim!: frp_step.cases (*‹⟦((?a1.0, ?a2.0, ?a3.0), ?a4.0, ?a5.0, ?a6.0) ∈ frp_step ?δ1.0 ?δ2.0; ⋀W q1 q2 Wtl Wn Q W' Q' δd' δd. ⟦?a1.0 = Q; ?a2.0 = W; ?a3.0 = δd; ?a4.0 = Q'; ?a5.0 = W'; ?a6.0 = δd'; W = (q1, q2) # Wtl; distinct Wn; set Wn = f_succ (δ_prod ?δ1.0 ?δ2.0) `` {(q1, q2)} - Q; W' = Wn @ Wtl; Q' = Q ∪ f_succ (δ_prod ?δ1.0 ?δ2.0) `` {(q1, q2)}; δd' = δd ∪ {r ∈ δ_prod ?δ1.0 ?δ2.0. lhs r = (q1, q2)}⟧ ⟹ ?P⟧ ⟹ ?P›*) frp_initial.cases (*‹⟦(?a1.0, ?a2.0, ?a3.0) ∈ frp_initial ?Q10.0 ?Q20.0; ⋀W. ⟦?a1.0 = ?Q10.0 × ?Q20.0; ?a2.0 = W; ?a3.0 = {}; distinct W; set W = ?Q10.0 × ?Q20.0⟧ ⟹ ?P⟧ ⟹ ?P›*) intro: dfs_step.intros (*‹⟦?W = ?σ # ?Wtl; distinct ?Wn; set ?Wn = ?R `` {?σ} - ?Σ; ?W' = ?Wn @ ?Wtl; ?Σ' = ?R `` {?σ} ∪ ?Σ⟧ ⟹ ((?Σ, ?W), ?Σ', ?W') ∈ dfs_step ?R›*) dfs_initial.intros (*‹⟦distinct ?W; set ?W = ?Σi⟧ ⟹ (?Σi, ?W) ∈ dfs_initial ?Σi›*))[1]) (*discuss goal 4*) apply ((auto simp add: frp_algo_def (*‹frp_algo ?T1.0 ?T2.0 ≡ ⦇wa_cond = frp_cond, wa_step = frp_step (ta_rules ?T1.0) (ta_rules ?T2.0), wa_initial = frp_initial (ta_initial ?T1.0) (ta_initial ?T2.0), wa_invar = frp_invar ?T1.0 ?T2.0⦈›*) frp_α_def (*‹frp_α ?S ≡ let (Q, W, δ) = ?S in (Q, W)›*) frp_cond_def (*‹frp_cond ≡ {(Q, W, δd). W ≠ []}›*) dfs_algo_def (*‹dfs_algo ?Σi ?R ≡ ⦇wa_cond = dfs_cond, wa_step = dfs_step ?R, wa_initial = dfs_initial ?Σi, wa_invar = dfs_invar ?Σi ?R⦈›*) dfs_cond_def (*‹dfs_cond ≡ {(Σ, W). W ≠ []}›*) frp_invar_def (*‹frp_invar ?T1.0 ?T2.0 ≡ frp_invar_add (ta_rules ?T1.0) (ta_rules ?T2.0) ∩ {s. frp_α s ∈ dfs_invar (ta_initial ?T1.0 × ta_initial ?T2.0) (f_succ (δ_prod (ta_rules ?T1.0) (ta_rules ?T2.0)))}›*) elim!: frp_step.cases (*‹⟦((?a1.0, ?a2.0, ?a3.0), ?a4.0, ?a5.0, ?a6.0) ∈ frp_step ?δ1.0 ?δ2.0; ⋀W q1 q2 Wtl Wn Q W' Q' δd' δd. ⟦?a1.0 = Q; ?a2.0 = W; ?a3.0 = δd; ?a4.0 = Q'; ?a5.0 = W'; ?a6.0 = δd'; W = (q1, q2) # Wtl; distinct Wn; set Wn = f_succ (δ_prod ?δ1.0 ?δ2.0) `` {(q1, q2)} - Q; W' = Wn @ Wtl; Q' = Q ∪ f_succ (δ_prod ?δ1.0 ?δ2.0) `` {(q1, q2)}; δd' = δd ∪ {r ∈ δ_prod ?δ1.0 ?δ2.0. lhs r = (q1, q2)}⟧ ⟹ ?P⟧ ⟹ ?P›*) frp_initial.cases (*‹⟦(?a1.0, ?a2.0, ?a3.0) ∈ frp_initial ?Q10.0 ?Q20.0; ⋀W. ⟦?a1.0 = ?Q10.0 × ?Q20.0; ?a2.0 = W; ?a3.0 = {}; distinct W; set W = ?Q10.0 × ?Q20.0⟧ ⟹ ?P⟧ ⟹ ?P›*) intro: dfs_step.intros (*‹⟦?W = ?σ # ?Wtl; distinct ?Wn; set ?Wn = ?R `` {?σ} - ?Σ; ?W' = ?Wn @ ?Wtl; ?Σ' = ?R `` {?σ} ∪ ?Σ⟧ ⟹ ((?Σ, ?W), ?Σ', ?W') ∈ dfs_step ?R›*) dfs_initial.intros (*‹⟦distinct ?W; set ?W = ?Σi⟧ ⟹ (?Σi, ?W) ∈ dfs_initial ?Σi›*))[1]) (*discuss goal 5*) apply ((auto simp add: frp_algo_def (*‹frp_algo ?T1.0 ?T2.0 ≡ ⦇wa_cond = frp_cond, wa_step = frp_step (ta_rules ?T1.0) (ta_rules ?T2.0), wa_initial = frp_initial (ta_initial ?T1.0) (ta_initial ?T2.0), wa_invar = frp_invar ?T1.0 ?T2.0⦈›*) frp_α_def (*‹frp_α ?S ≡ let (Q, W, δ) = ?S in (Q, W)›*) frp_cond_def (*‹frp_cond ≡ {(Q, W, δd). W ≠ []}›*) dfs_algo_def (*‹dfs_algo ?Σi ?R ≡ ⦇wa_cond = dfs_cond, wa_step = dfs_step ?R, wa_initial = dfs_initial ?Σi, wa_invar = dfs_invar ?Σi ?R⦈›*) dfs_cond_def (*‹dfs_cond ≡ {(Σ, W). W ≠ []}›*) frp_invar_def (*‹frp_invar ?T1.0 ?T2.0 ≡ frp_invar_add (ta_rules ?T1.0) (ta_rules ?T2.0) ∩ {s. frp_α s ∈ dfs_invar (ta_initial ?T1.0 × ta_initial ?T2.0) (f_succ (δ_prod (ta_rules ?T1.0) (ta_rules ?T2.0)))}›*) elim!: frp_step.cases (*‹⟦((?a1.0, ?a2.0, ?a3.0), ?a4.0, ?a5.0, ?a6.0) ∈ frp_step ?δ1.0 ?δ2.0; ⋀W q1 q2 Wtl Wn Q W' Q' δd' δd. ⟦?a1.0 = Q; ?a2.0 = W; ?a3.0 = δd; ?a4.0 = Q'; ?a5.0 = W'; ?a6.0 = δd'; W = (q1, q2) # Wtl; distinct Wn; set Wn = f_succ (δ_prod ?δ1.0 ?δ2.0) `` {(q1, q2)} - Q; W' = Wn @ Wtl; Q' = Q ∪ f_succ (δ_prod ?δ1.0 ?δ2.0) `` {(q1, q2)}; δd' = δd ∪ {r ∈ δ_prod ?δ1.0 ?δ2.0. lhs r = (q1, q2)}⟧ ⟹ ?P⟧ ⟹ ?P›*) frp_initial.cases (*‹⟦(?a1.0, ?a2.0, ?a3.0) ∈ frp_initial ?Q10.0 ?Q20.0; ⋀W. ⟦?a1.0 = ?Q10.0 × ?Q20.0; ?a2.0 = W; ?a3.0 = {}; distinct W; set W = ?Q10.0 × ?Q20.0⟧ ⟹ ?P⟧ ⟹ ?P›*) intro: dfs_step.intros (*‹⟦?W = ?σ # ?Wtl; distinct ?Wn; set ?Wn = ?R `` {?σ} - ?Σ; ?W' = ?Wn @ ?Wtl; ?Σ' = ?R `` {?σ} ∪ ?Σ⟧ ⟹ ((?Σ, ?W), ?Σ', ?W') ∈ dfs_step ?R›*) dfs_initial.intros (*‹⟦distinct ?W; set ?W = ?Σi⟧ ⟹ (?Σi, ?W) ∈ dfs_initial ?Σi›*))[1]) (*proven 5 subgoals*) . interpretation frp_ref: wa_precise_refine "(frp_algo T1 T2)" "(dfs_algo (ta_initial T1 × ta_initial T2) (f_succ (δ_prod (ta_rules T1) (ta_rules T2))))" "frp_α" using frp_pref_dfs (*‹wa_precise_refine (frp_algo ?T1.0 ?T2.0) (dfs_algo (ta_initial ?T1.0 × ta_initial ?T2.0) (f_succ (δ_prod (ta_rules ?T1.0) (ta_rules ?T2.0)))) frp_α›*) .<close> theorem frp_while_algo: assumes TA: "tree_automaton T1" "tree_automaton T2" shows "while_algo (frp_algo T1 T2)" proof (-) (*goal: ‹while_algo (frp_algo T1 T2)›*) interpret t1: tree_automaton T1 by fact interpret t2: tree_automaton T2 by fact have finite: "finite ((f_succ (δ_prod (ta_rules T1) (ta_rules T2)))⇧* `` (ta_initial T1 × ta_initial T2))" proof (-) (*goal: ‹finite ((f_succ (δ_prod t1.δ t2.δ))⇧* `` (t1.Qi × t2.Qi))›*) have "((f_succ (δ_prod (ta_rules T1) (ta_rules T2)))⇧* `` (ta_initial T1 × ta_initial T2)) ⊆ ((ta_initial T1 × ta_initial T2) ∪ δ_states (δ_prod (ta_rules T1) (ta_rules T2)))" apply rule (*goal: ‹(f_succ (δ_prod t1.δ t2.δ))⇧* `` (t1.Qi × t2.Qi) ⊆ t1.Qi × t2.Qi ∪ δ_states (δ_prod t1.δ t2.δ)›*) apply (drule f_accessible_subset[unfolded f_accessible_def] (*‹?q ∈ (f_succ ?δ)⇧* `` ?Q ⟹ ?q ∈ ?Q ∪ δ_states ?δ›*)) (*goal: ‹⋀x. x ∈ (f_succ (δ_prod t1.δ t2.δ))⇧* `` (t1.Qi × t2.Qi) ⟹ x ∈ t1.Qi × t2.Qi ∪ δ_states (δ_prod t1.δ t2.δ)›*) by auto moreover have "finite …" by auto ultimately show "?thesis" (*goal: ‹finite ((f_succ (δ_prod t1.δ t2.δ))⇧* `` (t1.Qi × t2.Qi))›*) by (simp add: finite_subset (*‹⟦?A ⊆ ?B; finite ?B⟧ ⟹ finite ?A›*)) qed show "?thesis" (*goal: ‹while_algo (frp_algo T1 T2)›*) apply (rule frp_ref.wa_intro (*‹⟦while_algo (dfs_algo (ta_initial (?T1.0::(?'a, ?'b) tree_automaton_rec) × ta_initial (?T2.0::(?'c, ?'b) tree_automaton_rec)) (f_succ (δ_prod (ta_rules ?T1.0) (ta_rules ?T2.0)))); wa_invar (frp_algo ?T1.0 ?T2.0) = (?addi::((?'a × ?'c) set × (?'a × ?'c) list × (?'a × ?'c, ?'b) ta_rule set) set) ∩ {s::(?'a × ?'c) set × (?'a × ?'c) list × (?'a × ?'c, ?'b) ta_rule set. frp_α s ∈ wa_invar (dfs_algo (ta_initial ?T1.0 × ta_initial ?T2.0) (f_succ (δ_prod (ta_rules ?T1.0) (ta_rules ?T2.0))))}; ⋀(s::(?'a × ?'c) set × (?'a × ?'c) list × (?'a × ?'c, ?'b) ta_rule set) s'::(?'a × ?'c) set × (?'a × ?'c) list × (?'a × ?'c, ?'b) ta_rule set. ⟦s ∈ ?addi; s ∈ wa_cond (frp_algo ?T1.0 ?T2.0); frp_α s ∈ wa_invar (dfs_algo (ta_initial ?T1.0 × ta_initial ?T2.0) (f_succ (δ_prod (ta_rules ?T1.0) (ta_rules ?T2.0)))); (s, s') ∈ wa_step (frp_algo ?T1.0 ?T2.0)⟧ ⟹ s' ∈ ?addi; wa_initial (frp_algo ?T1.0 ?T2.0) ⊆ ?addi⟧ ⟹ while_algo (frp_algo ?T1.0 ?T2.0)›*)) (*goals: 1. ‹while_algo (dfs_algo (t1.Qi × t2.Qi) (f_succ (δ_prod t1.δ t2.δ)))› 2. ‹wa_invar (frp_algo T1 T2) = ?addi ∩ {s. frp_α s ∈ wa_invar (dfs_algo (t1.Qi × t2.Qi) (f_succ (δ_prod t1.δ t2.δ)))}› 3. ‹⋀s s'. ⟦s ∈ ?addi; s ∈ wa_cond (frp_algo T1 T2); frp_α s ∈ wa_invar (dfs_algo (t1.Qi × t2.Qi) (f_succ (δ_prod t1.δ t2.δ))); (s, s') ∈ wa_step (frp_algo T1 T2)⟧ ⟹ s' ∈ ?addi› 4. ‹wa_initial (frp_algo T1 T2) ⊆ ?addi› discuss goal 1*) apply (rule dfs_while_algo[OF finite] (*‹while_algo (dfs_algo (t1.Qi × t2.Qi) (f_succ (δ_prod t1.δ t2.δ)))›*)) (*discuss goal 2*) apply (simp add: frp_algo_def (*‹frp_algo ?T1.0 ?T2.0 ≡ ⦇wa_cond = frp_cond, wa_step = frp_step (ta_rules ?T1.0) (ta_rules ?T2.0), wa_initial = frp_initial (ta_initial ?T1.0) (ta_initial ?T2.0), wa_invar = frp_invar ?T1.0 ?T2.0⦈›*) dfs_algo_def (*‹dfs_algo ?Σi ?R ≡ ⦇wa_cond = dfs_cond, wa_step = dfs_step ?R, wa_initial = dfs_initial ?Σi, wa_invar = dfs_invar ?Σi ?R⦈›*) frp_invar_def (*‹frp_invar ?T1.0 ?T2.0 ≡ frp_invar_add (ta_rules ?T1.0) (ta_rules ?T2.0) ∩ {s. frp_α s ∈ dfs_invar (ta_initial ?T1.0 × ta_initial ?T2.0) (f_succ (δ_prod (ta_rules ?T1.0) (ta_rules ?T2.0)))}›*)) (*discuss goal 3*) apply ((auto simp add: dfs_algo_def (*‹dfs_algo ?Σi ?R ≡ ⦇wa_cond = dfs_cond, wa_step = dfs_step ?R, wa_initial = dfs_initial ?Σi, wa_invar = dfs_invar ?Σi ?R⦈›*) frp_algo_def (*‹frp_algo ?T1.0 ?T2.0 ≡ ⦇wa_cond = frp_cond, wa_step = frp_step (ta_rules ?T1.0) (ta_rules ?T2.0), wa_initial = frp_initial (ta_initial ?T1.0) (ta_initial ?T2.0), wa_invar = frp_invar ?T1.0 ?T2.0⦈›*) frp_α_def (*‹frp_α ?S ≡ let (Q, W, δ) = ?S in (Q, W)›*) dfs_α_def (*‹dfs_α ?S ≡ let (Σ, W) = ?S in (Σ, set W)›*) frp_invar_add_def (*‹frp_invar_add ?δ1.0 ?δ2.0 ≡ {(Q, W, δd). δd = {r ∈ δ_prod ?δ1.0 ?δ2.0. lhs r ∈ Q - set W}}›*) dfs_invar_def (*‹dfs_invar ?Σi ?R ≡ dfs_invar_add ∩ {s. dfs_α s ∈ sse_invar ?Σi ?R}›*) dfs_invar_add_def (*‹dfs_invar_add ≡ {(Σ, W). distinct W}›*) sse_invar_def (*‹sse_invar ?Σi ?R = {(Σ, W). W ⊆ Σ ∧ Σ ⊆ ?R⇧* `` ?Σi ∧ (∀σ∈?R⇧* `` ?Σi - Σ. ∃σh∈W. (σh, σ) ∈ (?R - UNIV × Σ)⇧*) } › * ) elim!: frp_step.cases (*‹⟦((?a1.0, ?a2.0, ?a3.0), ?a4.0, ?a5.0, ?a6.0) ∈ frp_step ?δ1.0 ?δ2.0; ⋀W q1 q2 Wtl Wn Q W' Q' δd' δd. ⟦?a1.0 = Q; ?a2.0 = W; ?a3.0 = δd; ?a4.0 = Q'; ?a5.0 = W'; ?a6.0 = δd'; W = (q1, q2) # Wtl; distinct Wn; set Wn = f_succ (δ_prod ?δ1.0 ?δ2.0) `` {(q1, q2)} - Q; W' = Wn @ Wtl; Q' = Q ∪ f_succ (δ_prod ?δ1.0 ?δ2.0) `` {(q1, q2)}; δd' = δd ∪ {r ∈ δ_prod ?δ1.0 ?δ2.0. lhs r = (q1, q2)}⟧ ⟹ ?P⟧ ⟹ ?P›*))[1]) (*discuss goal 4*) apply ((force simp add: frp_algo_def (*‹frp_algo ?T1.0 ?T2.0 ≡ ⦇wa_cond = frp_cond, wa_step = frp_step (ta_rules ?T1.0) (ta_rules ?T2.0), wa_initial = frp_initial (ta_initial ?T1.0) (ta_initial ?T2.0), wa_invar = frp_invar ?T1.0 ?T2.0⦈›*) frp_invar_add_def (*‹frp_invar_add ?δ1.0 ?δ2.0 ≡ {(Q, W, δd). δd = {r ∈ δ_prod ?δ1.0 ?δ2.0. lhs r ∈ Q - set W}}›*) elim!: frp_initial.cases (*‹⟦(?a1.0, ?a2.0, ?a3.0) ∈ frp_initial ?Q10.0 ?Q20.0; ⋀W. ⟦?a1.0 = ?Q10.0 × ?Q20.0; ?a2.0 = W; ?a3.0 = {}; distinct W; set W = ?Q10.0 × ?Q20.0⟧ ⟹ ?P⟧ ⟹ ?P›*))[1]) (*proven 4 subgoals*) . qed<close> theorem frp_inv_final: "∀s. s∈wa_invar (frp_algo T1 T2) ∧ s∉wa_cond (frp_algo T1 T2) ⟶ (case s of (Q,W,δd) ⇒ ⦇ ta_initial = ta_initial T1 × ta_initial T2, ta_rules = δd ⦈ = ta_fwd_reduce (ta_prod T1 T2))" apply (intro allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*) impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goal: ‹∀s. s ∈ wa_invar (frp_algo T1 T2) ∧ s ∉ wa_cond (frp_algo T1 T2) ⟶ (case s of (Q, W, δd) ⇒ ⦇ta_initial = ta_initial T1 × ta_initial T2, ta_rules = δd⦈ = ta_fwd_reduce (ta_prod T1 T2))›*) apply (case_tac s) (*goal: ‹⋀s. s ∈ wa_invar (frp_algo T1 T2) ∧ s ∉ wa_cond (frp_algo T1 T2) ⟹ case s of (Q, W, δd) ⇒ ⦇ta_initial = ta_initial T1 × ta_initial T2, ta_rules = δd⦈ = ta_fwd_reduce (ta_prod T1 T2)›*) apply simp (*goal: ‹⋀s a b c. ⟦s ∈ wa_invar (frp_algo T1 T2) ∧ s ∉ wa_cond (frp_algo T1 T2); s = (a, b, c)⟧ ⟹ case s of (Q, W, δd) ⇒ ⦇ta_initial = ta_initial T1 × ta_initial T2, ta_rules = δd⦈ = ta_fwd_reduce (ta_prod T1 T2)›*) proof (simp add: ta_reduce_def (*‹ta_reduce (?TA::(?'Q, ?'L) tree_automaton_rec) (?P::?'Q set) ≡ ⦇ta_initial = ta_initial ?TA ∩ ?P, ta_rules = reduce_rules (ta_rules ?TA) ?P⦈›*) ta_prod_def (*‹ta_prod (?TA1.0::(?'a, ?'c, ?'d) tree_automaton_rec_scheme) (?TA2.0::(?'b, ?'c, ?'e) tree_automaton_rec_scheme) ≡ ⦇ta_initial = ta_initial ?TA1.0 × ta_initial ?TA2.0, ta_rules = δ_prod (ta_rules ?TA1.0) (ta_rules ?TA2.0)⦈›*) frp_algo_def (*‹frp_algo (?T1.0::(?'a, ?'c) tree_automaton_rec) (?T2.0::(?'b, ?'c) tree_automaton_rec) ≡ ⦇wa_cond = frp_cond, wa_step = frp_step (ta_rules ?T1.0) (ta_rules ?T2.0), wa_initial = frp_initial (ta_initial ?T1.0) (ta_initial ?T2.0), wa_invar = frp_invar ?T1.0 ?T2.0⦈›*)) (*goal: ‹⋀s a b c. ⟦(a, b, c) ∈ frp_invar T1 T2 ∧ (a, b, c) ∉ frp_cond; s = (a, b, c)⟧ ⟹ c = reduce_rules (δ_prod (ta_rules T1) (ta_rules T2)) (f_accessible (δ_prod (ta_rules T1) (ta_rules T2)) (ta_initial T1 × ta_initial T2))›*) fix Q and W and δd assume A: "(Q,W,δd)∈frp_invar T1 T2 ∧ (Q,W,δd)∉frp_cond" (*‹(Q::('a × 'b) set, W::('a × 'b) list, δd::('a × 'b, 'c) ta_rule set) ∈ frp_invar (T1::('a, 'c) tree_automaton_rec) (T2::('b, 'c) tree_automaton_rec) ∧ (Q, W, δd) ∉ frp_cond›*) from frp_ref.transfer_correctness[OF dfs_invar_final, unfolded frp_algo_def, simplified, rule_format, OF A] (*‹fst (dfs_α (frp_α (Q, W, δd))) = (f_succ (δ_prod (ta_rules T1) (ta_rules T2)))⇧* `` (ta_initial T1 × ta_initial T2)›*) have [simp]: "Q = f_accessible (δ_prod (ta_rules T1) (ta_rules T2)) (ta_initial T1 × ta_initial T2)" by (simp add: f_accessible_def (*‹f_accessible (?δ::(?'a, ?'b) ta_rule set) (?Q0.0::?'a set) ≡ (f_succ ?δ)⇧* `` ?Q0.0›*) dfs_α_def (*‹dfs_α (?S::?'Σ set × ?'Σ list) ≡ let (Σ::?'Σ set, W::?'Σ list) = ?S in (Σ, set W)›*) frp_α_def (*‹frp_α (?S::(?'Q1.0 × ?'Q2.0) set × (?'Q1.0 × ?'Q2.0) list × (?'Q1.0 × ?'Q2.0, ?'L) ta_rule set) ≡ let (Q::(?'Q1.0 × ?'Q2.0) set, W::(?'Q1.0 × ?'Q2.0) list, δ::(?'Q1.0 × ?'Q2.0, ?'L) ta_rule set) = ?S in (Q, W)›*)) from A (*‹(Q, W, δd) ∈ frp_invar T1 T2 ∧ (Q, W, δd) ∉ frp_cond›*) show "δd = reduce_rules (δ_prod (ta_rules T1) (ta_rules T2)) (f_accessible (δ_prod (ta_rules T1) (ta_rules T2)) (ta_initial T1 × ta_initial T2))" apply (auto simp add: reduce_rules_def (*‹reduce_rules ?δ ?P ≡ ?δ ∩ {r. rule_states r ⊆ ?P}›*) f_accessible_def (*‹f_accessible ?δ ?Q0.0 ≡ (f_succ ?δ)⇧* `` ?Q0.0›*) frp_invar_def (*‹frp_invar ?T1.0 ?T2.0 ≡ frp_invar_add (ta_rules ?T1.0) (ta_rules ?T2.0) ∩ {s. frp_α s ∈ dfs_invar (ta_initial ?T1.0 × ta_initial ?T2.0) (f_succ (δ_prod (ta_rules ?T1.0) (ta_rules ?T2.0)))}›*) frp_invar_add_def (*‹frp_invar_add ?δ1.0 ?δ2.0 ≡ {(Q, W, δd). δd = {r ∈ δ_prod ?δ1.0 ?δ2.0. lhs r ∈ Q - set W}}›*) frp_α_def (*‹frp_α ?S ≡ let (Q, W, δ) = ?S in (Q, W)›*) frp_cond_def (*‹frp_cond ≡ {(Q, W, δd). W ≠ []}›*)) (*goal: ‹δd = reduce_rules (δ_prod (ta_rules T1) (ta_rules T2)) (f_accessible (δ_prod (ta_rules T1) (ta_rules T2)) (ta_initial T1 × ta_initial T2))›*) apply (case_tac x) (*goal: ‹⋀x a b aa ba. ⟦δd = {r ∈ δ_prod (ta_rules T1) (ta_rules T2). lhs r ∈ (f_succ (δ_prod (ta_rules T1) (ta_rules T2)))⇧* `` (ta_initial T1 × ta_initial T2)}; ((f_succ (δ_prod (ta_rules T1) (ta_rules T2)))⇧* `` (ta_initial T1 × ta_initial T2), []) ∈ dfs_invar (ta_initial T1 × ta_initial T2) (f_succ (δ_prod (ta_rules T1) (ta_rules T2))); W = []; x ∈ δ_prod (ta_rules T1) (ta_rules T2); ((a, b), lhs x) ∈ (f_succ (δ_prod (ta_rules T1) (ta_rules T2)))⇧*; a ∈ ta_initial T1; b ∈ ta_initial T2; (aa, ba) ∈ rule_states x⟧ ⟹ (aa, ba) ∈ (f_succ (δ_prod (ta_rules T1) (ta_rules T2)))⇧* `` (ta_initial T1 × ta_initial T2)›*) by (auto dest: rtrancl_into_rtrancl (*‹⟦(?a, ?b) ∈ ?r⇧*; (?b, ?c) ∈ ?r⟧ ⟹ (?a, ?c) ∈ ?r⇧*›*) intro: f_succ.intros (*‹⟦?q → ?l ?qs ∈ ?δ; ?q' ∈ set ?qs⟧ ⟹ (?q, ?q') ∈ f_succ ?δ›*)) qed end
{ "path": "afp-2025-02-12/thys/Tree-Automata/AbsAlgo.thy", "repo": "afp-2025-02-12", "sha": "38ff073ed89b7908d3ee90883458c5bfc121e7c19e6c87c5876ef0a878f251c8" }
(* Title: HOL/ex/Birthday_Paradox.thy Author: Lukas Bulwahn, TU Muenchen, 2007 *) section ‹A Formulation of the Birthday Paradox› theory Birthday_Paradox imports Main "HOL-Library.FuncSet" begin section ‹Cardinality› lemma card_product_dependent: assumes "finite S" assumes "∀x ∈ S. finite (T x)" shows "card {(x, y). x ∈ S ∧ y ∈ T x} = (∑x ∈ S. card (T x))" using card_SigmaI[OF assms, symmetric] (*‹(∑a∈S. card (T a)) = card (Sigma S T)›*) by (auto intro!: arg_cong[where f=card] (*‹?x = ?y ⟹ card ?x = card ?y›*) simp add: Sigma_def (*‹Sigma ?A ?B ≡ ⋃x∈?A. ⋃y∈?B x. {(x, y)}›*)) lemma card_extensional_funcset_inj_on: assumes "finite S" "finite T" "card S ≤ card T" shows "card {f ∈ extensional_funcset S T. inj_on f S} = fact (card T) div (fact (card T - card S))" using assms (*‹finite S› ‹finite (T::'b set)› ‹card S ≤ card T›*) proof (induct S arbitrary: T rule: finite_induct) (*goals: 1. ‹⋀T. ⟦finite T; card {} ≤ card T⟧ ⟹ card {f ∈ {} →⇩E T. inj_on f {}} = fact (card T) div fact (card T - card {})› 2. ‹⋀x F T. ⟦finite F; x ∉ F; ⋀T. ⟦finite T; card F ≤ card T⟧ ⟹ card {f ∈ F →⇩E T. inj_on f F} = fact (card T) div fact (card T - card F); finite T; card (insert x F) ≤ card T⟧ ⟹ card {f ∈ insert x F →⇩E T. inj_on f (insert x F)} = fact (card T) div fact (card T - card (insert x F))›*) case empty (*‹finite T› ‹card {} ≤ card T›*) from this (*‹finite T› ‹card {} ≤ card T›*) show "?case" (*goal: ‹card {f. f ∈ {} →⇩E T ∧ inj_on f {}} = fact (card T) div fact (card T - card {})›*) by (simp add: Collect_conv_if (*‹{x. x = ?a ∧ ?P x} = (if ?P ?a then {?a} else {})›*) PiE_empty_domain (*‹Pi⇩E {} ?T = {λx. undefined}›*)) next (*goal: ‹⋀x F T. ⟦finite F; x ∉ F; ⋀T. ⟦finite T; card F ≤ card T⟧ ⟹ card {f ∈ F →⇩E T. inj_on f F} = fact (card T) div fact (card T - card F); finite T; card (insert x F) ≤ card T⟧ ⟹ card {f ∈ insert x F →⇩E T. inj_on f (insert x F)} = fact (card T) div fact (card T - card (insert x F))›*) case (insert x S) (*‹finite S› ‹x ∉ S› ‹⟦finite ?T; card S ≤ card ?T⟧ ⟹ card {f. f ∈ S →⇩E ?T ∧ inj_on f S} = fact (card ?T) div fact (card ?T - card S)› ‹finite T› ‹card (insert x S) ≤ card T›*) { fix x from ‹finite T› (*‹finite (T::'b::type set)›*) have "finite (T - {x})" by auto from ‹finite S› (*‹finite S›*) this (*‹finite (T - {x})›*) have "finite (extensional_funcset S (T - {x}))" by (rule finite_PiE (*‹⟦finite ?S; ⋀i. i ∈ ?S ⟹ finite (?T i)⟧ ⟹ finite (Pi⇩E ?S ?T)›*)) moreover have "{f : extensional_funcset S (T - {x}). inj_on f S} ⊆ (extensional_funcset S (T - {x}))" by auto ultimately have "finite {f : extensional_funcset S (T - {x}). inj_on f S}" by (auto intro: finite_subset (*‹⟦?A ⊆ ?B; finite ?B⟧ ⟹ finite ?A›*)) } note finite_delete = this (*‹finite {f ∈ S →⇩E T - {?xa2}. inj_on f S}›*) from insert (*‹finite (S::'a set)› ‹(x::'a) ∉ (S::'a set)› ‹⟦finite ?T; card S ≤ card ?T⟧ ⟹ card {f. f ∈ S →⇩E ?T ∧ inj_on f S} = fact (card ?T) div fact (card ?T - card S)› ‹finite T› ‹card (insert x S) ≤ card T›*) have hyps: "∀y ∈ T. card ({g. g ∈ extensional_funcset S (T - {y}) ∧ inj_on g S}) = fact (card T - 1) div fact ((card T - 1) - card S)" (is "∀ _ ∈ T. _ = ?k") by auto from extensional_funcset_extend_domain_inj_on_eq[OF ‹x ∉ S›] (*‹{f ∈ insert x S →⇩E ?T. inj_on f (insert x S)} = (λ(y, g). g(x := y)) ` {(y, g). y ∈ ?T ∧ g ∈ S →⇩E ?T - {y} ∧ inj_on g S}›*) have "card {f. f ∈ extensional_funcset (insert x S) T ∧ inj_on f (insert x S)} = card ((λ(y, g). g(x := y)) ` {(y, g). y ∈ T ∧ g ∈ extensional_funcset S (T - {y}) ∧ inj_on g S})" by metis also (*calculation: ‹card {f ∈ insert x S →⇩E T. inj_on f (insert x S)} = card ((λ(y, g). g(x := y)) ` {(y, g). y ∈ T ∧ g ∈ S →⇩E T - {y} ∧ inj_on g S})›*) from extensional_funcset_extend_domain_inj_onI[OF ‹x ∉ S›, of T] (*‹inj_on (λ(y, g). g(x := y)) {(y, g). y ∈ T ∧ g ∈ S →⇩E T - {y} ∧ inj_on g S}›*) have "… = card {(y, g). y ∈ T ∧ g ∈ extensional_funcset S (T - {y}) ∧ inj_on g S}" by (simp add: card_image (*‹inj_on ?f ?A ⟹ card (?f ` ?A) = card ?A›*)) also (*calculation: ‹card {f ∈ insert x S →⇩E T. inj_on f (insert x S)} = card {(y, g). y ∈ T ∧ g ∈ S →⇩E T - {y} ∧ inj_on g S}›*) have "card {(y, g). y ∈ T ∧ g ∈ extensional_funcset S (T - {y}) ∧ inj_on g S} = card {(y, g). y ∈ T ∧ g ∈ {f ∈ extensional_funcset S (T - {y}). inj_on f S}}" by auto also (*calculation: ‹card {f ∈ insert x S →⇩E T. inj_on f (insert x S)} = card {(y, g). y ∈ T ∧ g ∈ {f ∈ S →⇩E T - {y}. inj_on f S}}›*) from ‹finite T› (*‹finite T›*) finite_delete (*‹finite {f ∈ S →⇩E T - {?xa2}. inj_on f S}›*) have "... = (∑y ∈ T. card {g. g ∈ extensional_funcset S (T - {y}) ∧ inj_on g S})" apply (subst card_product_dependent (*‹⟦finite ?S; ∀x∈?S. finite (?T x)⟧ ⟹ card {(x, y). x ∈ ?S ∧ y ∈ ?T x} = (∑x∈?S. card (?T x))›*)) (*goals: 1. ‹⟦finite T; ⋀xa. finite {f ∈ S →⇩E T - {xa}. inj_on f S}⟧ ⟹ finite T› 2. ‹⟦finite T; ⋀xa. finite {f ∈ S →⇩E T - {xa}. inj_on f S}⟧ ⟹ ∀x∈T. finite {f ∈ S →⇩E T - {x}. inj_on f S}› 3. ‹⟦finite T; ⋀xa. finite {f ∈ S →⇩E T - {xa}. inj_on f S}⟧ ⟹ (∑x∈T. card {f ∈ S →⇩E T - {x}. inj_on f S}) = (∑y∈T. card {g ∈ S →⇩E T - {y}. inj_on g S})› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . also (*calculation: ‹card {f ∈ insert x S →⇩E T. inj_on f (insert x S)} = (∑y∈T. card {g ∈ S →⇩E T - {y}. inj_on g S})›*) from hyps (*‹∀y::'b∈T::'b set. card {g::'a ⇒ 'b ∈ (S::'a set) →⇩E T - {y}. inj_on g S} = fact (card T - (1::nat)) div fact (card T - (1::nat) - card S)›*) have "... = (card T) * ?k" by auto also (*calculation: ‹card {f::'a ⇒ 'b ∈ insert (x::'a) (S::'a set) →⇩E (T::'b set). inj_on f (insert x S)} = card T * (fact (card T - (1::nat)) div fact (card T - (1::nat) - card S))›*) have "... = card T * fact (card T - 1) div fact (card T - card (insert x S))" using insert (*‹finite S› ‹x ∉ S› ‹⟦finite ?T; card S ≤ card ?T⟧ ⟹ card {f. f ∈ S →⇩E ?T ∧ inj_on f S} = fact (card ?T) div fact (card ?T - card S)› ‹finite T› ‹card (insert x S) ≤ card T›*) unfolding div_mult1_eq[of "card T" "fact (card T - 1)"] (*goal: ‹card T * (fact (card T - 1) div fact (card T - 1 - card S)) = card T * (fact (card T - 1) div fact (card T - card (insert x S))) + card T * (fact (card T - 1) mod fact (card T - card (insert x S))) div fact (card T - card (insert x S))›*) by (simp add: fact_mod (*‹?m ≤ ?n ⟹ fact ?n mod fact ?m = 0›*)) also (*calculation: ‹card {f ∈ insert x S →⇩E T. inj_on f (insert x S)} = card T * fact (card T - 1) div fact (card T - card (insert x S))›*) have "... = fact (card T) div fact (card T - card (insert x S))" using insert (*‹finite S› ‹x ∉ S› ‹⟦finite ?T; card S ≤ card ?T⟧ ⟹ card {f. f ∈ S →⇩E ?T ∧ inj_on f S} = fact (card ?T) div fact (card ?T - card S)› ‹finite T› ‹card (insert x S) ≤ card T›*) by (simp add: fact_reduce[of "card T"] (*‹0 < card T ⟹ fact (card T) = of_nat (card T) * fact (card T - 1)›*)) finally (*calculation: ‹card {f ∈ insert x S →⇩E T. inj_on f (insert x S)} = fact (card T) div fact (card T - card (insert x S))›*) show "?case" (*goal: ‹card {f. f ∈ insert x S →⇩E T ∧ inj_on f (insert x S)} = fact (card T) div fact (card T - card (insert x S))›*) . qed lemma card_extensional_funcset_not_inj_on: assumes "finite S" "finite T" "card S ≤ card T" shows "card {f ∈ extensional_funcset S T. ¬ inj_on f S} = (card T) ^ (card S) - (fact (card T)) div (fact (card T - card S))" proof (-) (*goal: ‹card {f ∈ S →⇩E T. ¬ inj_on f S} = card T ^ card S - fact (card T) div fact (card T - card S)›*) have subset: "{f : extensional_funcset S T. inj_on f S} <= extensional_funcset S T" by auto from finite_subset[OF subset] (*‹finite ((S::'a set) →⇩E (T::'b set)) ⟹ finite {f::'a ⇒ 'b ∈ S →⇩E T. inj_on f S}›*) assms (*‹finite S› ‹finite T› ‹card S ≤ card T›*) have finite: "finite {f : extensional_funcset S T. inj_on f S}" by (auto intro!: finite_PiE (*‹⟦finite ?S; ⋀i. i ∈ ?S ⟹ finite (?T i)⟧ ⟹ finite (Pi⇩E ?S ?T)›*)) have "{f ∈ extensional_funcset S T. ¬ inj_on f S} = extensional_funcset S T - {f ∈ extensional_funcset S T. inj_on f S}" by auto from assms (*‹finite S› ‹finite T› ‹card (S::'a set) ≤ card (T::'b set)›*) this (*‹{f ∈ S →⇩E T. ¬ inj_on f S} = (S →⇩E T) - {f ∈ S →⇩E T. inj_on f S}›*) finite (*‹finite {f ∈ S →⇩E T. inj_on f S}›*) subset (*‹{f ∈ S →⇩E T. inj_on f S} ⊆ S →⇩E T›*) show "?thesis" (*goal: ‹card {f ∈ S →⇩E T. ¬ inj_on f S} = card T ^ card S - fact (card T) div fact (card T - card S)›*) by (simp add: card_Diff_subset (*‹⟦finite ?B; ?B ⊆ ?A⟧ ⟹ card (?A - ?B) = card ?A - card ?B›*) card_PiE (*‹finite ?S ⟹ card (Pi⇩E ?S ?T) = (∏i∈?S. card (?T i))›*) card_extensional_funcset_inj_on (*‹⟦finite ?S; finite ?T; card ?S ≤ card ?T⟧ ⟹ card {f ∈ ?S →⇩E ?T. inj_on f ?S} = fact (card ?T) div fact (card ?T - card ?S)›*) prod_constant (*‹(∏x∈?A. ?y) = ?y ^ card ?A›*)) qed lemma prod_upto_nat_unfold: "prod f {m..(n::nat)} = (if n < m then 1 else (if n = 0 then f 0 else f n * prod f {m..(n - 1)}))" apply auto (*goal: ‹prod f {m..n} = (if n < m then 1 else if n = 0 then f 0 else f n * prod f {m..n - 1})›*) by (auto simp add: gr0_conv_Suc (*‹(0 < ?n) = (∃m. ?n = Suc m)›*) atLeastAtMostSuc_conv (*‹?m ≤ Suc ?n ⟹ {?m..Suc ?n} = insert (Suc ?n) {?m..?n}›*)) section ‹Birthday paradox› lemma birthday_paradox: assumes "card S = 23" "card T = 365" shows "2 * card {f ∈ extensional_funcset S T. ¬ inj_on f S} ≥ card (extensional_funcset S T)" proof (-) (*goal: ‹card (S →⇩E T) ≤ 2 * card {f ∈ S →⇩E T. ¬ inj_on f S}›*) from ‹card S = 23› (*‹card S = 23›*) ‹card T = 365› (*‹card T = 365›*) have "finite S" "finite T" "card S <= card T" apply - (*goals: 1. ‹⟦card S = 23; card T = 365⟧ ⟹ finite S› 2. ‹⟦card S = 23; card T = 365⟧ ⟹ finite T› 3. ‹⟦card S = 23; card T = 365⟧ ⟹ card S ≤ card T› discuss goal 1*) apply ((auto intro: card_ge_0_finite (*‹0 < card ?A ⟹ finite ?A›*))[1]) (*discuss goal 2*) apply ((auto intro: card_ge_0_finite (*‹0 < card ?A ⟹ finite ?A›*))[1]) (*discuss goal 3*) apply ((auto intro: card_ge_0_finite (*‹(0::nat) < card (?A::?'a::type set) ⟹ finite ?A›*))[1]) (*proven 3 subgoals*) . from assms (*‹card S = 23› ‹card T = 365›*) show "?thesis" (*goal: ‹card (S →⇩E T) ≤ 2 * card {f ∈ S →⇩E T. ¬ inj_on f S}›*) using card_PiE[OF ‹finite S›, of "λi. T"] (*‹card (S →⇩E T) = (∏i∈S. card T)›*) ‹finite S› (*‹finite (S::'a set)›*) card_extensional_funcset_not_inj_on[OF ‹finite S› ‹finite T› ‹card S <= card T›] (*‹card {f ∈ S →⇩E T. ¬ inj_on f S} = card T ^ card S - fact (card T) div fact (card T - card S)›*) by (simp add: fact_div_fact (*‹(?n::nat) ≤ (?m::nat) ⟹ fact ?m div fact ?n = ∏{?n + (1::nat)..?m}›*) prod_upto_nat_unfold (*‹prod (?f::nat ⇒ ?'a::comm_monoid_mult) {?m::nat..?n::nat} = (if ?n < ?m then 1::?'a::comm_monoid_mult else if ?n = (0::nat) then ?f (0::nat) else ?f ?n * prod ?f {?m..?n - (1::nat)})›*) prod_constant (*‹(∏x::?'b::type∈(?A::?'b::type set). (?y::?'a::comm_monoid_mult)) = ?y ^ card ?A›*)) qed end
{ "path": "Isabelle2024/src/HOL/ex/Birthday_Paradox.thy", "repo": "Isabelle2024", "sha": "1d737d6f2c7119b9b64efed0180d491c48b94f58b1959fdc0e5ce4a2dc9afd03" }
(* Title: Projections.thy Author: Jose Divasón <jose.divasonm at unirioja.es> Author: Jesús Aransay <jesus-maria.aransay at unirioja.es> *) section‹Projections› theory Projections imports Miscellaneous_QR begin subsection‹Definitions of vector projection and projection of a vector onto a set.› definition "proj v u = (v ∙ u / (u ∙ u)) *⇩R u" definition "proj_onto a S = (sum (λx. proj a x) S)" subsection‹Properties› lemma proj_onto_sum_rw: "sum (λx. (x ∙ v / (x ∙ x)) *⇩R x) A = sum (λx. (v ∙ x / (x ∙ x)) *⇩R x) A" apply (rule sum.cong (*‹⟦?A = ?B; ⋀x. x ∈ ?B ⟹ ?g x = ?h x⟧ ⟹ sum ?g ?A = sum ?h ?B›*)) (*goals: 1. ‹A = A› 2. ‹⋀x. x ∈ A ⟹ (x ∙ v / (x ∙ x)) *⇩R x = (v ∙ x / (x ∙ x)) *⇩R x› discuss goal 1*) apply ((auto simp add: inner_commute (*‹?x ∙ ?y = ?y ∙ ?x›*))[1]) (*discuss goal 2*) apply ((auto simp add: inner_commute (*‹?x ∙ ?y = ?y ∙ ?x›*))[1]) (*proven 2 subgoals*) . lemma vector_sub_project_orthogonal_proj: fixes b x :: "'a::euclidean_space" shows "inner b (x - proj x b) = 0" using vector_sub_project_orthogonal (*‹?b ∙ (?x - (?b ∙ ?x / (?b ∙ ?b)) *⇩R ?b) = 0›*) unfolding proj_def inner_commute[of x b] (*goal: ‹b ∙ (x - (b ∙ x / (b ∙ b)) *⇩R b) = 0›*) by auto lemma orthogonal_proj_set: assumes yC: "y∈C" and C: "finite C" and p: "pairwise orthogonal C" shows "orthogonal (a - proj_onto a C) y" proof (-) (*goal: ‹orthogonal ((a::'a) - proj_onto a (C::'a set)) (y::'a)›*) have Cy: "C = insert y (C - {y})" using yC (*‹y ∈ C›*) by blast have fth: "finite (C - {y})" using C (*‹finite C›*) by simp show "orthogonal (a - proj_onto a C) y" unfolding orthogonal_def (*goal: ‹(a - proj_onto a C) ∙ y = 0›*) unfolding proj_onto_def (*goal: ‹(a - sum (proj a) C) ∙ y = 0›*) unfolding proj_def[abs_def] (*goal: ‹(a - (∑u∈C. (a ∙ u / (u ∙ u)) *⇩R u)) ∙ y = 0›*) unfolding inner_diff (*goal: ‹(a::'a::real_inner) ∙ (y::'a::real_inner) - (∑u::'a::real_inner∈(C::'a::real_inner set). (a ∙ u / (u ∙ u)) *⇩R u) ∙ y = (0::real)›*) unfolding inner_sum_left (*goal: ‹a ∙ y - (∑x∈C. (a ∙ x / (x ∙ x)) *⇩R x ∙ y) = 0›*) unfolding right_minus_eq (*goal: ‹a ∙ y = (∑x∈C. (a ∙ x / (x ∙ x)) *⇩R x ∙ y)›*) unfolding sum.remove[OF C yC] (*goal: ‹(a::'a) ∙ (y::'a) = (a ∙ y / (y ∙ y)) *⇩R y ∙ y + (∑x::'a∈(C::'a set) - {y}. (a ∙ x / (x ∙ x)) *⇩R x ∙ y)›*) apply (clarsimp simp add: inner_commute[of y a] (*‹y ∙ a = a ∙ y›*)) (*goal: ‹a ∙ y = (a ∙ y / (y ∙ y)) *⇩R y ∙ y + (∑x∈C - {y}. (a ∙ x / (x ∙ x)) *⇩R x ∙ y)›*) apply (rule sum.neutral (*‹∀x∈?A. ?g x = 0 ⟹ sum ?g ?A = 0›*)) (*goal: ‹y ≠ 0 ⟹ (∑x∈C - {y}. a ∙ x * (x ∙ y) / (x ∙ x)) = 0›*) apply clarsimp (*goal: ‹y ≠ 0 ⟹ ∀x∈C - {y}. a ∙ x * (x ∙ y) / (x ∙ x) = 0›*) apply (rule p[unfolded pairwise_def orthogonal_def, rule_format] (*‹⟦?x ∈ C; ?y ∈ C; ?x ≠ ?y⟧ ⟹ ?x ∙ ?y = 0›*)) (*goal: ‹⋀x. ⟦y ≠ 0; x ∈ C; x ≠ y; a ∙ x ≠ 0; x ≠ 0⟧ ⟹ x ∙ y = 0›*) using yC (*‹y ∈ C›*) apply - (*goals: 1. ‹⋀x. ⟦y ≠ 0; x ∈ C; x ≠ y; a ∙ x ≠ 0; x ≠ 0; y ∈ C⟧ ⟹ x ∈ C› 2. ‹⋀x. ⟦y ≠ 0; x ∈ C; x ≠ y; a ∙ x ≠ 0; x ≠ 0; y ∈ C⟧ ⟹ y ∈ C› 3. ‹⋀x. ⟦y ≠ 0; x ∈ C; x ≠ y; a ∙ x ≠ 0; x ≠ 0; y ∈ C⟧ ⟹ x ≠ y› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . qed lemma pairwise_orthogonal_proj_set: assumes C: "finite C" and p: "pairwise orthogonal C" shows "pairwise orthogonal (insert (a - proj_onto a C) C)" apply (rule pairwise_orthogonal_insert[OF p] (*‹(⋀y. y ∈ C ⟹ orthogonal ?x y) ⟹ pairwise orthogonal (insert ?x C)›*)) (*goal: ‹pairwise orthogonal (insert (a - proj_onto a C) C)›*) by (auto simp add: orthogonal_proj_set (*‹⟦?y ∈ ?C; finite ?C; pairwise orthogonal ?C⟧ ⟹ orthogonal (?a - proj_onto ?a ?C) ?y›*) C (*‹finite C›*) p (*‹pairwise orthogonal C›*)) subsection‹Orthogonal Complement› definition "orthogonal_complement W = {x. ∀y ∈ W. orthogonal x y}" lemma in_orthogonal_complement_imp_orthogonal: assumes x: "y ∈ S" and "x ∈ orthogonal_complement S" shows "orthogonal x y" using assms (*‹y ∈ S› ‹x ∈ orthogonal_complement S›*) orthogonal_commute (*‹orthogonal (?x::?'a) (?y::?'a) = orthogonal ?y ?x›*) unfolding orthogonal_complement_def (*goal: ‹orthogonal x y›*) by blast lemma subspace_orthogonal_complement: "subspace (orthogonal_complement W)" unfolding subspace_def orthogonal_complement_def (*goal: ‹0 ∈ {x. Ball W (orthogonal x)} ∧ (∀x∈{x. Ball W (orthogonal x)}. ∀y∈{x. Ball W (orthogonal x)}. x + y ∈ {x. Ball W (orthogonal x)}) ∧ (∀c. ∀x∈{x. Ball W (orthogonal x)}. c *⇩R x ∈ {x. Ball W (orthogonal x)})›*) by (simp add: orthogonal_def (*‹orthogonal ?x ?y = (?x ∙ ?y = 0)›*) inner_left_distrib (*‹(?x + ?y) ∙ ?z = ?x ∙ ?z + ?y ∙ ?z›*)) lemma orthogonal_complement_mono: assumes A_in_B: "A ⊆ B" shows "orthogonal_complement B ⊆ orthogonal_complement A" proof (standard) (*goal: ‹⋀x::'a. x ∈ orthogonal_complement (B::'a set) ⟹ x ∈ orthogonal_complement (A::'a set)›*) fix x assume x: "x ∈ orthogonal_complement B" (*‹(x::'a) ∈ orthogonal_complement (B::'a set)›*) show "x ∈ orthogonal_complement A" using x (*‹x ∈ orthogonal_complement B›*) unfolding orthogonal_complement_def (*goal: ‹x ∈ {x. Ball A (orthogonal x)}›*) apply (simp add: orthogonal_def (*‹orthogonal ?x ?y = (?x ∙ ?y = 0)›*)) (*goal: ‹x ∈ {x. Ball A (orthogonal x)}›*) by (metis A_in_B (*‹(A::'a set) ⊆ (B::'a set)›*) in_mono (*‹(?A::?'a set) ⊆ (?B::?'a set) ⟹ (?x::?'a) ∈ ?A ⟶ ?x ∈ ?B›*)) qed lemma B_in_orthogonal_complement_of_orthogonal_complement: shows "B ⊆ orthogonal_complement (orthogonal_complement B)" by (auto simp add: orthogonal_complement_def (*‹orthogonal_complement ?W = {x. ∀y∈?W. orthogonal x y}›*) orthogonal_def (*‹orthogonal ?x ?y = (?x ∙ ?y = 0)›*) inner_commute (*‹?x ∙ ?y = ?y ∙ ?x›*)) lemma phytagorean_theorem_norm: assumes o: "orthogonal x y" shows "norm (x+y)^2=norm x^2 + norm y^2" proof (-) (*goal: ‹(norm (x + y))² = (norm x)² + (norm y)²›*) have "norm (x+y)^2 = (x+y) ∙ (x+y)" unfolding power2_norm_eq_inner (*goal: ‹(x + y) ∙ (x + y) = (x + y) ∙ (x + y)›*) by standard also (*calculation: ‹(norm (x + y))² = (x + y) ∙ (x + y)›*) have "... = ((x+y) ∙ x) + ((x+y) ∙ y)" unfolding inner_right_distrib (*goal: ‹(x + y) ∙ x + (x + y) ∙ y = (x + y) ∙ x + (x + y) ∙ y›*) by standard also (*calculation: ‹(norm ((x::'a::real_inner) + (y::'a::real_inner)))² = (x + y) ∙ x + (x + y) ∙ y›*) have "... = (x ∙ x) + (x ∙ y) + (y ∙ x) + (y ∙ y) " unfolding real_inner_class.inner_add_left (*goal: ‹x ∙ x + y ∙ x + (x ∙ y + y ∙ y) = x ∙ x + x ∙ y + y ∙ x + y ∙ y›*) by simp also (*calculation: ‹(norm (x + y))² = x ∙ x + x ∙ y + y ∙ x + y ∙ y›*) have "... = (x ∙ x) + (y ∙ y)" using o (*‹orthogonal (x::'a::real_inner) (y::'a::real_inner)›*) unfolding orthogonal_def (*goal: ‹(x::'a::real_inner) ∙ x + x ∙ (y::'a::real_inner) + y ∙ x + y ∙ y = x ∙ x + y ∙ y›*) by (metis monoid_add_class.add.right_neutral (*‹?a + 0 = ?a›*) inner_commute (*‹?x ∙ ?y = ?y ∙ ?x›*)) also (*calculation: ‹(norm (x + y))² = x ∙ x + y ∙ y›*) have "... = norm x^2 + norm y^2" unfolding power2_norm_eq_inner (*goal: ‹(x::'a) ∙ x + (y::'a) ∙ y = x ∙ x + y ∙ y›*) by standard finally (*calculation: ‹(norm (x + y))² = (norm x)² + (norm y)²›*) show "?thesis" (*goal: ‹(norm ((x::'a) + (y::'a)))² = (norm x)² + (norm y)²›*) . qed lemma in_orthogonal_complement_basis: fixes B::"'a::{euclidean_space} set" assumes S: "subspace S" and ind_B: "independent B" and B: "B ⊆ S" and span_B: "S ⊆ span B" shows "(v ∈ orthogonal_complement S) = (∀a∈B. orthogonal a v)" proof (unfold orthogonal_complement_def (*‹orthogonal_complement ?W = {x. ∀y∈?W. orthogonal x y}›*), auto) (*goals: 1. ‹⋀a. ⟦∀x∈S. orthogonal v x; a ∈ B⟧ ⟹ orthogonal a v› 2. ‹⋀x. ⟦∀a∈B. orthogonal a v; x ∈ S⟧ ⟹ orthogonal v x›*) fix a assume "∀x∈S. orthogonal v x" and "a ∈ B" (*‹∀x::'a∈S::'a set. orthogonal (v::'a) x› ‹(a::'a) ∈ (B::'a set)›*) thus "orthogonal a v" by (metis B (*‹B ⊆ S›*) orthogonal_commute (*‹orthogonal ?x ?y = orthogonal ?y ?x›*) rev_subsetD (*‹⟦?c ∈ ?A; ?A ⊆ ?B⟧ ⟹ ?c ∈ ?B›*)) next (*goal: ‹⋀x. ⟦∀a∈B. orthogonal a v; x ∈ S⟧ ⟹ orthogonal v x›*) fix x assume o: "∀a∈B. orthogonal a v" and x: "x ∈ S" (*‹∀a::'a∈B::'a set. orthogonal a (v::'a)› ‹(x::'a) ∈ (S::'a set)›*) have finite_B: "finite B" using independent_bound_general[OF ind_B] (*‹finite B ∧ card B ≤ dim B›*) by standard have span_B_eq: "S = span B" using B (*‹B ⊆ S›*) S (*‹subspace S›*) span_B (*‹(S::'a set) ⊆ span (B::'a set)›*) span_subspace (*‹⟦?A ⊆ ?B; ?B ⊆ span ?A; subspace ?B⟧ ⟹ span ?A = ?B›*) by blast obtain f where f: "(∑a∈B. f a *⇩R a) = x" (*goal: ‹(⋀f. (∑a∈B. f a *⇩R a) = x ⟹ thesis) ⟹ thesis›*) using span_finite[OF finite_B] (*‹span B = range (λu. ∑v∈B. u v *⇩R v)›*) using x (*‹x ∈ S›*) unfolding span_B_eq (*goal: ‹(⋀f::'a::euclidean_space ⇒ real. (∑a::'a::euclidean_space∈(B::'a::euclidean_space set). f a *⇩R a) = (x::'a::euclidean_space) ⟹ thesis::bool) ⟹ thesis›*) by force have "v ∙ x = v ∙ (∑a∈B. f a *⇩R a)" unfolding f (*goal: ‹v ∙ x = v ∙ x›*) by standard also (*calculation: ‹v ∙ x = v ∙ (∑a∈B. f a *⇩R a)›*) have "... = (∑a∈B. v ∙ (f a *⇩R a))" unfolding inner_sum_right (*goal: ‹(∑y∈B. v ∙ f y *⇩R y) = (∑a∈B. v ∙ f a *⇩R a)›*) by standard also (*calculation: ‹v ∙ x = (∑a∈B. v ∙ f a *⇩R a)›*) have "... = (∑a∈B. f a * (v ∙ a))" unfolding inner_scaleR_right (*goal: ‹(∑a∈B. f a * (v ∙ a)) = (∑a∈B. f a * (v ∙ a))›*) by standard also (*calculation: ‹v ∙ x = (∑a∈B. f a * (v ∙ a))›*) have "... = 0" using sum.neutral (*‹∀x∈?A. ?g x = 0 ⟹ sum ?g ?A = 0›*) o (*‹∀a∈B. orthogonal a v›*) by (simp add: orthogonal_def (*‹orthogonal ?x ?y = (?x ∙ ?y = 0)›*) inner_commute (*‹?x ∙ ?y = ?y ∙ ?x›*)) finally (*calculation: ‹v ∙ x = 0›*) show "orthogonal v x" unfolding orthogonal_def (*goal: ‹v ∙ x = 0›*) . qed text‹See @{url "https://people.math.osu.edu/husen.1/teaching/571/least_squares.pdf"}› text‹Part 1 of the Theorem 1.7 in the previous website, but the proof has been carried out in other way.› lemma v_minus_p_orthogonal_complement: fixes X::"'a::{euclidean_space} set" assumes subspace_S: "subspace S" and ind_X: "independent X" and X: "X ⊆ S" and span_X: "S ⊆ span X" and o: "pairwise orthogonal X" shows "(v - proj_onto v X) ∈ orthogonal_complement S" unfolding in_orthogonal_complement_basis[OF subspace_S ind_X X span_X] (*goal: ‹∀a∈X. orthogonal a (v - proj_onto v X)›*) proof (standard) (*goal: ‹⋀a. a ∈ X ⟹ orthogonal a (v - proj_onto v X)›*) fix a assume a: "a ∈ X" (*‹(a::'a) ∈ (X::'a set)›*) let ?p = "proj_onto v X" show "orthogonal a (v - ?p)" unfolding orthogonal_commute[of a "v-?p"] (*goal: ‹orthogonal ((v::'a) - proj_onto v (X::'a set)) (a::'a)›*) apply (rule orthogonal_proj_set[OF a _ o] (*‹finite X ⟹ orthogonal (?a - proj_onto ?a X) a›*)) (*goal: ‹orthogonal ((v::'a::euclidean_space) - proj_onto v (X::'a::euclidean_space set)) (a::'a::euclidean_space)›*) by (simp add: independent_bound_general[OF ind_X] (*‹finite X ∧ card X ≤ dim X›*)) qed text‹Part 2 of the Theorem 1.7 in the previous website.› lemma UNIV_orthogonal_complement_decomposition: fixes S::"'a::{euclidean_space} set" assumes s: "subspace S" shows "UNIV = S + (orthogonal_complement S)" apply (unfold set_plus_def (*‹?A + ?B = {c. ∃a∈?A. ∃b∈?B. c = a + b}›*)) (*goal: ‹UNIV = S + orthogonal_complement S›*) proof (auto) (*goal: ‹⋀x. ∃a∈S. ∃b∈orthogonal_complement S. x = a + b›*) fix v obtain X where ind_X: "independent X" and X: "X ⊆ S" and span_X: "S ⊆ span X" and o: "pairwise orthogonal X" (*goal: ‹(⋀X. ⟦independent X; X ⊆ S; S ⊆ span X; pairwise orthogonal X⟧ ⟹ thesis) ⟹ thesis›*) by (metis order_refl (*‹?x ≤ ?x›*) orthonormal_basis_subspace (*‹⟦subspace ?S; ⋀B. ⟦B ⊆ ?S; pairwise orthogonal B; ⋀x. x ∈ B ⟹ norm x = 1; independent B; card B = dim ?S; span B = ?S⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) s (*‹subspace S›*)) have finite_X: "finite X" by (metis independent_bound_general (*‹independent ?S ⟹ finite ?S ∧ card ?S ≤ dim ?S›*) ind_X (*‹independent X›*)) let ?p = "proj_onto v X" have "v=?p +(v-?p)" by simp moreover have "?p ∈ S" unfolding proj_onto_def proj_def[abs_def] (*goal: ‹(∑u::'a∈(X::'a set). ((v::'a) ∙ u / (u ∙ u)) *⇩R u) ∈ (S::'a set)›*) apply (rule subspace_sum[OF s] (*‹(⋀x. x ∈ ?B ⟹ ?f x ∈ S) ⟹ sum ?f ?B ∈ S›*)) (*goal: ‹(∑u::'a∈(X::'a set). ((v::'a) ∙ u / (u ∙ u)) *⇩R u) ∈ (S::'a set)›*) by (simp add: X (*‹X ⊆ S›*) s (*‹subspace S›*) rev_subsetD (*‹⟦?c ∈ ?A; ?A ⊆ ?B⟧ ⟹ ?c ∈ ?B›*) subspace_mul (*‹⟦subspace ?S; ?x ∈ ?S⟧ ⟹ ?c *⇩R ?x ∈ ?S›*)) moreover have "(v-?p) ∈ orthogonal_complement S" by (rule v_minus_p_orthogonal_complement[OF s ind_X X span_X o] (*‹?v - proj_onto ?v X ∈ orthogonal_complement S›*)) ultimately show "∃a∈S. ∃b∈orthogonal_complement S. v = a + b" by force qed subsection‹Normalization of vectors› definition normalize where "normalize x = ((1/norm x) *⇩R x)" definition normalize_set_of_vec where "normalize_set_of_vec X = normalize` X" lemma norm_normalize: assumes "x ≠ 0" shows "norm (normalize x) = 1" sorry lemma normalize_0: "(normalize x = 0) = (x = 0)" unfolding normalize_def (*goal: ‹(((1::real) / norm (x::'a)) *⇩R x = (0::'a)) = (x = (0::'a))›*) by auto lemma norm_normalize_set_of_vec: assumes "x ≠ 0" and "x ∈ normalize_set_of_vec X" shows "norm x = 1" using assms (*‹(x::'a) ≠ (0::'a)› ‹x ∈ normalize_set_of_vec X›*) norm_normalize (*‹?x ≠ 0 ⟹ norm (Projections.normalize ?x) = 1›*) normalize_0 (*‹(Projections.normalize ?x = 0) = (?x = 0)›*) unfolding normalize_set_of_vec_def (*goal: ‹norm (x::'a) = (1::real)›*) by blast end
{ "path": "afp-2025-02-12/thys/QR_Decomposition/Projections.thy", "repo": "afp-2025-02-12", "sha": "516dbca6c37c6064fb53f4126f89f8cad31d630b5162b20ce41e98903167dfce" }
section‹Shadowed Rules› theory Shadowed imports SimpleFw_Semantics begin subsection‹Removing Shadowed Rules› text‹Testing, not executable› text‹Assumes: @{term "simple_ruleset"}› fun rmshadow :: "'i::len simple_rule list ⇒ 'i simple_packet set ⇒ 'i simple_rule list" where "rmshadow [] _ = []" | "rmshadow ((SimpleRule m a)#rs) P = (if (∀p∈P. ¬ simple_matches m p) then rmshadow rs P else (SimpleRule m a) # (rmshadow rs {p ∈ P. ¬ simple_matches m p}))" subsubsection‹Soundness› lemma rmshadow_sound: "p ∈ P ⟹ simple_fw (rmshadow rs P) p = simple_fw rs p" proof (induction rs arbitrary: P) (*goals: 1. ‹⋀P. p ∈ P ⟹ simple_fw (rmshadow [] P) p = simple_fw [] p› 2. ‹⋀a rs P. ⟦⋀P. p ∈ P ⟹ simple_fw (rmshadow rs P) p = simple_fw rs p; p ∈ P⟧ ⟹ simple_fw (rmshadow (a # rs) P) p = simple_fw (a # rs) p›*) case Nil (*‹p ∈ P›*) thus "?case" (*goal: ‹simple_fw (rmshadow [] P) p = simple_fw [] p›*) by simp next (*goal: ‹⋀a rs P. ⟦⋀P. p ∈ P ⟹ simple_fw (rmshadow rs P) p = simple_fw rs p; p ∈ P⟧ ⟹ simple_fw (rmshadow (a # rs) P) p = simple_fw (a # rs) p›*) case (Cons r rs) (*‹p ∈ ?P ⟹ simple_fw (rmshadow rs ?P) p = simple_fw rs p› ‹p ∈ P›*) from Cons.IH (*‹(p::'a simple_packet) ∈ (?P::'a simple_packet set) ⟹ simple_fw (rmshadow (rs::'a simple_rule list) ?P) p = simple_fw rs p›*) Cons.prems (*‹(p::'a simple_packet) ∈ (P::'a simple_packet set)›*) have IH1: "simple_fw (rmshadow rs P) p = simple_fw rs p" by simp let ?P' = "{p ∈ P. ¬ simple_matches (match_sel r) p}" from Cons.IH (*‹(p::'a simple_packet) ∈ (?P::'a simple_packet set) ⟹ simple_fw (rmshadow (rs::'a simple_rule list) ?P) p = simple_fw rs p›*) Cons.prems (*‹p ∈ P›*) have IH2: "⋀m. p ∈ ?P' ⟹ simple_fw (rmshadow rs ?P') p = simple_fw rs p" by simp from Cons.prems (*‹p ∈ P›*) show "?case" (*goal: ‹simple_fw (rmshadow ((r::'a simple_rule) # (rs::'a simple_rule list)) (P::'a simple_packet set)) (p::'a simple_packet) = simple_fw (r # rs) p›*) apply (cases r) (*goal: ‹simple_fw (rmshadow (r # rs) P) p = simple_fw (r # rs) p›*) apply (rename_tac m a) (*goal: ‹⋀(x1::'a simple_match) x2::simple_action. ⟦(p::'a simple_packet) ∈ (P::'a simple_packet set); (r::'a::len simple_rule) = SimpleRule x1 x2⟧ ⟹ simple_fw (rmshadow (r # (rs::'a::len simple_rule list)) P) p = simple_fw (r # rs) p›*) apply simp (*goal: ‹⋀m a. ⟦p ∈ P; r = SimpleRule m a⟧ ⟹ simple_fw (rmshadow (r # rs) P) p = simple_fw (r # rs) p›*) apply (case_tac "∀p∈P. ¬ simple_matches m p") (*goals: 1. ‹⋀m a. ⟦p ∈ P; r = SimpleRule m a; ∀p∈P. ¬ simple_matches m p⟧ ⟹ ((∀p∈P. ¬ simple_matches m p) ⟶ simple_fw (rmshadow rs P) p = simple_fw (SimpleRule m a # rs) p) ∧ ((∃p∈P. simple_matches m p) ⟶ simple_fw (SimpleRule m a # rmshadow rs {p ∈ P. ¬ simple_matches m p}) p = simple_fw (SimpleRule m a # rs) p)› 2. ‹⋀m a. ⟦p ∈ P; r = SimpleRule m a; ¬ (∀p∈P. ¬ simple_matches m p)⟧ ⟹ ((∀p∈P. ¬ simple_matches m p) ⟶ simple_fw (rmshadow rs P) p = simple_fw (SimpleRule m a # rs) p) ∧ ((∃p∈P. simple_matches m p) ⟶ simple_fw (SimpleRule m a # rmshadow rs {p ∈ P. ¬ simple_matches m p}) p = simple_fw (SimpleRule m a # rs) p)› discuss goal 1*) apply (simp add: IH1 (*‹simple_fw (rmshadow rs P) p = simple_fw rs p›*) nomatch (*‹¬ simple_matches ?m ?p ⟹ simple_fw (SimpleRule ?m ?a # ?rs) ?p = simple_fw ?rs ?p›*)) (*discuss goal 2*) apply (case_tac "p ∈ ?P'") (*goals: 1. ‹⋀m a. ⟦p ∈ P; r = SimpleRule m a; ¬ (∀p∈P. ¬ simple_matches m p); p ∈ {p ∈ P. ¬ simple_matches (match_sel r) p}⟧ ⟹ ((∀p∈P. ¬ simple_matches m p) ⟶ simple_fw (rmshadow rs P) p = simple_fw (SimpleRule m a # rs) p) ∧ ((∃p∈P. simple_matches m p) ⟶ simple_fw (SimpleRule m a # rmshadow rs {p ∈ P. ¬ simple_matches m p}) p = simple_fw (SimpleRule m a # rs) p)› 2. ‹⋀m a. ⟦p ∈ P; r = SimpleRule m a; ¬ (∀p∈P. ¬ simple_matches m p); p ∉ {p ∈ P. ¬ simple_matches (match_sel r) p}⟧ ⟹ ((∀p∈P. ¬ simple_matches m p) ⟶ simple_fw (rmshadow rs P) p = simple_fw (SimpleRule m a # rs) p) ∧ ((∃p∈P. simple_matches m p) ⟶ simple_fw (SimpleRule m a # rmshadow rs {p ∈ P. ¬ simple_matches m p}) p = simple_fw (SimpleRule m a # rs) p)› discuss goal 1*) apply (frule IH2 (*‹p ∈ {p ∈ P. ¬ simple_matches (match_sel r) p} ⟹ simple_fw (rmshadow rs {p ∈ P. ¬ simple_matches (match_sel r) p}) p = simple_fw rs p›*)) (*top goal: ‹⋀m a. ⟦p ∈ P; r = SimpleRule m a; ¬ (∀p∈P. ¬ simple_matches m p); p ∈ {p ∈ P. ¬ simple_matches (match_sel r) p}⟧ ⟹ ((∀p∈P. ¬ simple_matches m p) ⟶ simple_fw (rmshadow rs P) p = simple_fw (SimpleRule m a # rs) p) ∧ ((∃p∈P. simple_matches m p) ⟶ simple_fw (SimpleRule m a # rmshadow rs {p ∈ P. ¬ simple_matches m p}) p = simple_fw (SimpleRule m a # rs) p)› and 1 goal remains*) apply (simp add: nomatch (*‹¬ simple_matches ?m ?p ⟹ simple_fw (SimpleRule ?m ?a # ?rs) ?p = simple_fw ?rs ?p›*) IH1 (*‹simple_fw (rmshadow rs P) p = simple_fw rs p›*)) (*discuss goal 2*) apply simp (*goal: ‹⋀m a. ⟦p ∈ P; r = SimpleRule m a; ¬ (∀p∈P. ¬ simple_matches m p); p ∉ {p ∈ P. ¬ simple_matches (match_sel r) p}⟧ ⟹ ((∀p∈P. ¬ simple_matches m p) ⟶ simple_fw (rmshadow rs P) p = simple_fw (SimpleRule m a # rs) p) ∧ ((∃p∈P. simple_matches m p) ⟶ simple_fw (SimpleRule m a # rmshadow rs {p ∈ P. ¬ simple_matches m p}) p = simple_fw (SimpleRule m a # rs) p)›*) apply (case_tac a) (*goals: 1. ‹⋀(m::'a simple_match) a::simple_action. ⟦(p::'a simple_packet) ∈ (P::'a simple_packet set); (r::'a simple_rule) = SimpleRule m a; ∃p::'a simple_packet∈P. simple_matches m p; simple_matches m p; a = Accept⟧ ⟹ ((∀p::'a simple_packet∈P. ¬ simple_matches m p) ⟶ simple_fw (rmshadow (rs::'a simple_rule list) P) p = simple_fw (SimpleRule m a # rs) p) ∧ simple_fw (SimpleRule m a # rmshadow rs {p::'a simple_packet ∈ P. ¬ simple_matches m p}) p = simple_fw (SimpleRule m a # rs) p› 2. ‹⋀(m::'a simple_match) a::simple_action. ⟦(p::'a simple_packet) ∈ (P::'a simple_packet set); (r::'a simple_rule) = SimpleRule m a; ∃p::'a simple_packet∈P. simple_matches m p; simple_matches m p; a = Drop⟧ ⟹ ((∀p::'a simple_packet∈P. ¬ simple_matches m p) ⟶ simple_fw (rmshadow (rs::'a simple_rule list) P) p = simple_fw (SimpleRule m a # rs) p) ∧ simple_fw (SimpleRule m a # rmshadow rs {p::'a simple_packet ∈ P. ¬ simple_matches m p}) p = simple_fw (SimpleRule m a # rs) p› discuss goal 1*) apply simp (*top goal: ‹⋀(m::'a simple_match) a::simple_action. ⟦(p::'a simple_packet) ∈ (P::'a simple_packet set); (r::'a::len simple_rule) = SimpleRule m a; ∃p::'a simple_packet∈P. simple_matches m p; simple_matches m p; a = Accept⟧ ⟹ ((∀p::'a simple_packet∈P. ¬ simple_matches m p) ⟶ simple_fw (rmshadow (rs::'a::len simple_rule list) P) p = simple_fw (SimpleRule m a # rs) p) ∧ simple_fw (SimpleRule m a # rmshadow rs {p::'a simple_packet ∈ P. ¬ simple_matches m p}) p = simple_fw (SimpleRule m a # rs) p› and 1 goal remains*) apply fast (*discuss goal 2*) apply simp (*goal: ‹⋀m a. ⟦p ∈ P; r = SimpleRule m a; ∃p∈P. simple_matches m p; simple_matches m p; a = Drop⟧ ⟹ ((∀p∈P. ¬ simple_matches m p) ⟶ simple_fw (rmshadow rs P) p = simple_fw (SimpleRule m a # rs) p) ∧ simple_fw (SimpleRule m a # rmshadow rs {p ∈ P. ¬ simple_matches m p}) p = simple_fw (SimpleRule m a # rs) p›*) apply fast (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . qed corollary rmshadow: fixes p :: "'i::len simple_packet" shows "simple_fw (rmshadow rs UNIV) p = simple_fw rs p" using rmshadow_sound[of p] (*‹p ∈ ?P ⟹ simple_fw (rmshadow ?rs ?P) p = simple_fw ?rs p›*) by simp text‹A different approach where we start with the empty set of packets and collect packets which are already ``matched-away''.› fun rmshadow' :: "'i::len simple_rule list ⇒ 'i simple_packet set ⇒ 'i simple_rule list" where "rmshadow' [] _ = []" | "rmshadow' ((SimpleRule m a)#rs) P = (if {p. simple_matches m p} ⊆ P then rmshadow' rs P else (SimpleRule m a) # (rmshadow' rs (P ∪ {p. simple_matches m p})))" lemma rmshadow'_sound: "p ∉ P ⟹ simple_fw (rmshadow' rs P) p = simple_fw rs p" proof (induction rs arbitrary: P) (*goals: 1. ‹⋀P. p ∉ P ⟹ simple_fw (rmshadow' [] P) p = simple_fw [] p› 2. ‹⋀a rs P. ⟦⋀P. p ∉ P ⟹ simple_fw (rmshadow' rs P) p = simple_fw rs p; p ∉ P⟧ ⟹ simple_fw (rmshadow' (a # rs) P) p = simple_fw (a # rs) p›*) case Nil (*‹(p::'a simple_packet) ∉ (P::'a simple_packet set)›*) thus "?case" (*goal: ‹simple_fw (rmshadow' [] P) p = simple_fw [] p›*) by simp next (*goal: ‹⋀a rs P. ⟦⋀P. p ∉ P ⟹ simple_fw (rmshadow' rs P) p = simple_fw rs p; p ∉ P⟧ ⟹ simple_fw (rmshadow' (a # rs) P) p = simple_fw (a # rs) p›*) case (Cons r rs) (*‹p ∉ ?P ⟹ simple_fw (rmshadow' rs ?P) p = simple_fw rs p› ‹p ∉ P›*) from Cons.IH (*‹p ∉ ?P ⟹ simple_fw (rmshadow' rs ?P) p = simple_fw rs p›*) Cons.prems (*‹p ∉ P›*) have IH1: "simple_fw (rmshadow' rs P) p = simple_fw rs p" by simp let ?P' = "{p. simple_matches (match_sel r) p}" from Cons.IH (*‹(p::'a simple_packet) ∉ (?P::'a simple_packet set) ⟹ simple_fw (rmshadow' (rs::'a::len simple_rule list) ?P) p = simple_fw rs p›*) Cons.prems (*‹(p::'a simple_packet) ∉ (P::'a simple_packet set)›*) have IH2: "⋀m. p ∉ (Collect (simple_matches m)) ⟹ simple_fw (rmshadow' rs (P ∪ Collect (simple_matches m))) p = simple_fw rs p" by simp have nomatch_m: "⋀m. p ∉ P ⟹ {p. simple_matches m p} ⊆ P ⟹ ¬ simple_matches m p" by blast from Cons.prems (*‹p ∉ P›*) show "?case" (*goal: ‹simple_fw (rmshadow' (r # rs) P) p = simple_fw (r # rs) p›*) apply (cases r) (*goal: ‹simple_fw (rmshadow' (r # rs) P) p = simple_fw (r # rs) p›*) apply (rename_tac m a) (*goal: ‹⋀x1 x2. ⟦p ∉ P; r = SimpleRule x1 x2⟧ ⟹ simple_fw (rmshadow' (r # rs) P) p = simple_fw (r # rs) p›*) apply simp (*goal: ‹⋀m a. ⟦p ∉ P; r = SimpleRule m a⟧ ⟹ simple_fw (rmshadow' (r # rs) P) p = simple_fw (r # rs) p›*) apply (case_tac "{p. simple_matches m p} ⊆ P") (*goals: 1. ‹⋀m a. ⟦p ∉ P; r = SimpleRule m a; {p. simple_matches m p} ⊆ P⟧ ⟹ (Collect (simple_matches m) ⊆ P ⟶ simple_fw (rmshadow' rs P) p = simple_fw (SimpleRule m a # rs) p) ∧ (¬ Collect (simple_matches m) ⊆ P ⟶ simple_fw (SimpleRule m a # rmshadow' rs (P ∪ Collect (simple_matches m))) p = simple_fw (SimpleRule m a # rs) p)› 2. ‹⋀m a. ⟦p ∉ P; r = SimpleRule m a; ¬ {p. simple_matches m p} ⊆ P⟧ ⟹ (Collect (simple_matches m) ⊆ P ⟶ simple_fw (rmshadow' rs P) p = simple_fw (SimpleRule m a # rs) p) ∧ (¬ Collect (simple_matches m) ⊆ P ⟶ simple_fw (SimpleRule m a # rmshadow' rs (P ∪ Collect (simple_matches m))) p = simple_fw (SimpleRule m a # rs) p)› discuss goal 1*) apply (simp add: IH1 (*‹simple_fw (rmshadow' rs P) p = simple_fw rs p›*)) (*top goal: ‹⋀m a. ⟦p ∉ P; r = SimpleRule m a; {p. simple_matches m p} ⊆ P⟧ ⟹ (Collect (simple_matches m) ⊆ P ⟶ simple_fw (rmshadow' rs P) p = simple_fw (SimpleRule m a # rs) p) ∧ (¬ Collect (simple_matches m) ⊆ P ⟶ simple_fw (SimpleRule m a # rmshadow' rs (P ∪ Collect (simple_matches m))) p = simple_fw (SimpleRule m a # rs) p)› and 1 goal remains*) apply (drule nomatch_m (*‹⟦p ∉ P; {p. simple_matches ?m1 p} ⊆ P⟧ ⟹ ¬ simple_matches ?m1 p›*)) (*goals: 1. ‹⋀m a. ⟦r = SimpleRule m a; {p. simple_matches m p} ⊆ P⟧ ⟹ {p. simple_matches (?m7 m a) p} ⊆ P› 2. ‹⋀m a. ⟦r = SimpleRule m a; {p. simple_matches m p} ⊆ P; ¬ simple_matches (?m7 m a) p⟧ ⟹ simple_fw rs p = simple_fw (SimpleRule m a # rs) p› discuss goal 1*) apply assumption (*discuss goal 2*) apply (simp add: nomatch (*‹¬ simple_matches ?m ?p ⟹ simple_fw (SimpleRule ?m ?a # ?rs) ?p = simple_fw ?rs ?p›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*goal: ‹⋀m a. ⟦p ∉ P; r = SimpleRule m a; ¬ {p. simple_matches m p} ⊆ P⟧ ⟹ (Collect (simple_matches m) ⊆ P ⟶ simple_fw (rmshadow' rs P) p = simple_fw (SimpleRule m a # rs) p) ∧ (¬ Collect (simple_matches m) ⊆ P ⟶ simple_fw (SimpleRule m a # rmshadow' rs (P ∪ Collect (simple_matches m))) p = simple_fw (SimpleRule m a # rs) p)›*) apply (case_tac a) (*goals: 1. ‹⋀(m::'a simple_match) a::simple_action. ⟦(p::'a simple_packet) ∉ (P::'a simple_packet set); (r::'a simple_rule) = SimpleRule m a; ¬ {p::'a simple_packet. simple_matches m p} ⊆ P; a = Accept⟧ ⟹ simple_fw (SimpleRule m a # rmshadow' (rs::'a simple_rule list) (P ∪ Collect (simple_matches m))) p = simple_fw (SimpleRule m a # rs) p› 2. ‹⋀(m::'a simple_match) a::simple_action. ⟦(p::'a simple_packet) ∉ (P::'a simple_packet set); (r::'a simple_rule) = SimpleRule m a; ¬ {p::'a simple_packet. simple_matches m p} ⊆ P; a = Drop⟧ ⟹ simple_fw (SimpleRule m a # rmshadow' (rs::'a simple_rule list) (P ∪ Collect (simple_matches m))) p = simple_fw (SimpleRule m a # rs) p› discuss goal 1*) apply simp (*top goal: ‹⋀m a. ⟦p ∉ P; r = SimpleRule m a; ¬ {p. simple_matches m p} ⊆ P; a = Accept⟧ ⟹ simple_fw (SimpleRule m a # rmshadow' rs (P ∪ Collect (simple_matches m))) p = simple_fw (SimpleRule m a # rs) p› and 1 goal remains*) apply (simp add: IH2 (*‹p ∉ Collect (simple_matches ?m1) ⟹ simple_fw (rmshadow' rs (P ∪ Collect (simple_matches ?m1))) p = simple_fw rs p›*)) (*discuss goal 2*) apply simp (*goal: ‹⋀(m::'a simple_match) a::simple_action. ⟦(p::'a simple_packet) ∉ (P::'a simple_packet set); (r::'a simple_rule) = SimpleRule m a; ¬ {p::'a simple_packet. simple_matches m p} ⊆ P; a = Drop⟧ ⟹ simple_fw (SimpleRule m a # rmshadow' (rs::'a simple_rule list) (P ∪ Collect (simple_matches m))) p = simple_fw (SimpleRule m a # rs) p›*) apply (simp add: IH2 (*‹(p::'a simple_packet) ∉ Collect (simple_matches (?m1::'a simple_match)) ⟹ simple_fw (rmshadow' (rs::'a simple_rule list) ((P::'a simple_packet set) ∪ Collect (simple_matches ?m1))) p = simple_fw rs p›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) . qed corollary fixes p :: "'i::len simple_packet" shows "simple_fw (rmshadow rs UNIV) p = simple_fw (rmshadow' rs {}) p" using rmshadow'_sound[of p] (*‹p ∉ ?P ⟹ simple_fw (rmshadow' ?rs ?P) p = simple_fw ?rs p›*) rmshadow_sound[of p] (*‹p ∈ ?P ⟹ simple_fw (rmshadow ?rs ?P) p = simple_fw ?rs p›*) by simp text‹Previous algorithm is not executable because we have no code for @{typ "'i::len simple_packet set"}. To get some code, some efficient set operations would be necessary. We either need union and subset or intersection and negation. Both subset and negation are complicated. Probably the BDDs which related work uses is really necessary. › (*Drafting set operations which might be necessary for an executable implementation. But BDDs might just be the thing here.*) context begin private type_synonym 'i simple_packet_set = "'i simple_match list" private definition simple_packet_set_toSet :: "'i::len simple_packet_set ⇒ 'i simple_packet set" where "simple_packet_set_toSet ms = {p. ∃m ∈ set ms. simple_matches m p}" private lemma simple_packet_set_toSet_alt: "simple_packet_set_toSet ms = (⋃ m ∈ set ms. {p. simple_matches m p})" unfolding simple_packet_set_toSet_def (*goal: ‹{p. ∃m∈set ms. simple_matches m p} = (⋃m∈set ms. {p. simple_matches m p})›*) by blast private definition simple_packet_set_union :: "'i::len simple_packet_set ⇒'i simple_match ⇒ 'i simple_packet_set" where "simple_packet_set_union ps m = m # ps" private lemma "simple_packet_set_toSet (simple_packet_set_union ps m) = simple_packet_set_toSet ps ∪ {p. simple_matches m p}" unfolding simple_packet_set_toSet_def simple_packet_set_union_def (*goal: ‹{p. ∃m∈set (m # ps). simple_matches m p} = {p. ∃m∈set ps. simple_matches m p} ∪ {p. simple_matches m p}›*) apply simp (*goal: ‹{p. ∃m∈set (m # ps). simple_matches m p} = {p. ∃m∈set ps. simple_matches m p} ∪ {p. simple_matches m p}›*) by blast (*either a sound but not complete executable implementation or a better idea to implement subset*) private lemma "(∃m' ∈ set ms. {i. match_iface iif i} ⊆ {i. match_iface (iiface m') i} ∧ {i. match_iface oif i} ⊆ {i. match_iface (oiface m') i} ∧ {ip. simple_match_ip sip ip} ⊆ {ip. simple_match_ip (src m') ip} ∧ {ip. simple_match_ip dip ip} ⊆ {ip. simple_match_ip (dst m') ip} ∧ {p. match_proto protocol p} ⊆ {p. match_proto (proto m') p} ∧ {p. simple_match_port sps p} ⊆ {p. simple_match_port (sports m') p} ∧ {p. simple_match_port dps p} ⊆ {p. simple_match_port (dports m') p} ) ⟹ {p. simple_matches ⦇iiface=iif, oiface=oif, src=sip, dst=dip, proto=protocol, sports=sps, dports=dps ⦈ p} ⊆ (simple_packet_set_toSet ms)" unfolding simple_packet_set_toSet_def simple_packet_set_union_def (*goal: ‹∃m'∈set ms. {i. match_iface iif i} ⊆ {i. match_iface (iiface m') i} ∧ {i. match_iface oif i} ⊆ {i. match_iface (oiface m') i} ∧ {ip. simple_match_ip sip ip} ⊆ {ip. simple_match_ip (src m') ip} ∧ {ip. simple_match_ip dip ip} ⊆ {ip. simple_match_ip (dst m') ip} ∧ {p. match_proto protocol p} ⊆ {p. match_proto (proto m') p} ∧ {p. simple_match_port sps p} ⊆ {p. simple_match_port (sports m') p} ∧ {p. simple_match_port dps p} ⊆ {p. simple_match_port (dports m') p} ⟹ {p. simple_matches ⦇iiface = iif, oiface = oif, src = sip, dst = dip, proto = protocol, sports = sps, dports = dps⦈ p} ⊆ {p. ∃m∈set ms. simple_matches m p}›*) apply (simp add: simple_matches.simps (*‹simple_matches ?m ?p = (match_iface (iiface ?m) (p_iiface ?p) ∧ match_iface (oiface ?m) (p_oiface ?p) ∧ simple_match_ip (src ?m) (p_src ?p) ∧ simple_match_ip (dst ?m) (p_dst ?p) ∧ match_proto (proto ?m) (p_proto ?p) ∧ simple_match_port (sports ?m) (p_sport ?p) ∧ simple_match_port (dports ?m) (p_dport ?p))›*)) (*goal: ‹∃m'∈set ms. {i. match_iface iif i} ⊆ {i. match_iface (iiface m') i} ∧ {i. match_iface oif i} ⊆ {i. match_iface (oiface m') i} ∧ {ip. simple_match_ip sip ip} ⊆ {ip. simple_match_ip (src m') ip} ∧ {ip. simple_match_ip dip ip} ⊆ {ip. simple_match_ip (dst m') ip} ∧ {p. match_proto protocol p} ⊆ {p. match_proto (proto m') p} ∧ {p. simple_match_port sps p} ⊆ {p. simple_match_port (sports m') p} ∧ {p. simple_match_port dps p} ⊆ {p. simple_match_port (dports m') p} ⟹ {p. simple_matches ⦇iiface = iif, oiface = oif, src = sip, dst = dip, proto = protocol, sports = sps, dports = dps⦈ p} ⊆ {p. ∃m∈set ms. simple_matches m p}›*) apply (simp add: Set.Collect_mono_iff (*‹(Collect ?P ⊆ Collect ?Q) = (∀x. ?P x ⟶ ?Q x)›*)) (*goal: ‹∃m'∈set ms. {i. match_iface iif i} ⊆ {i. match_iface (iiface m') i} ∧ {i. match_iface oif i} ⊆ {i. match_iface (oiface m') i} ∧ {ip. simple_match_ip sip ip} ⊆ {ip. simple_match_ip (src m') ip} ∧ {ip. simple_match_ip dip ip} ⊆ {ip. simple_match_ip (dst m') ip} ∧ {p. match_proto protocol p} ⊆ {p. match_proto (proto m') p} ∧ {p. simple_match_port sps p} ⊆ {p. simple_match_port (sports m') p} ∧ {p. simple_match_port dps p} ⊆ {p. simple_match_port (dports m') p} ⟹ {p. match_iface iif (p_iiface p) ∧ match_iface oif (p_oiface p) ∧ simple_match_ip sip (p_src p) ∧ simple_match_ip dip (p_dst p) ∧ match_proto protocol (p_proto p) ∧ simple_match_port sps (p_sport p) ∧ simple_match_port dps (p_dport p)} ⊆ {p. ∃m∈set ms. match_iface (iiface m) (p_iiface p) ∧ match_iface (oiface m) (p_oiface p) ∧ simple_match_ip (src m) (p_src p) ∧ simple_match_ip (dst m) (p_dst p) ∧ match_proto (proto m) (p_proto p) ∧ simple_match_port (sports m) (p_sport p) ∧ simple_match_port (dports m) (p_dport p)}›*) apply clarify (*goal: ‹∃m'::'a simple_match∈set (ms::'a simple_match list). (∀x::char list. match_iface (iif::iface) x ⟶ match_iface (iiface m') x) ∧ (∀x::char list. match_iface (oif::iface) x ⟶ match_iface (oiface m') x) ∧ (∀x::'a word. simple_match_ip (sip::'a word × nat) x ⟶ simple_match_ip (src m') x) ∧ (∀x::'a word. simple_match_ip (dip::'a word × nat) x ⟶ simple_match_ip (dst m') x) ∧ (∀x::8 word. match_proto (protocol::protocol) x ⟶ match_proto (proto m') x) ∧ (∀x::16 word. simple_match_port (sps::16 word × 16 word) x ⟶ simple_match_port (sports m') x) ∧ (∀x::16 word. simple_match_port (dps::16 word × 16 word) x ⟶ simple_match_port (dports m') x) ⟹ ∀x::'a simple_packet. match_iface iif (p_iiface x) ∧ match_iface oif (p_oiface x) ∧ simple_match_ip sip (p_src x) ∧ simple_match_ip dip (p_dst x) ∧ match_proto protocol (p_proto x) ∧ simple_match_port sps (p_sport x) ∧ simple_match_port dps (p_dport x) ⟶ (∃m::'a simple_match∈set ms. match_iface (iiface m) (p_iiface x) ∧ match_iface (oiface m) (p_oiface x) ∧ simple_match_ip (src m) (p_src x) ∧ simple_match_ip (dst m) (p_dst x) ∧ match_proto (proto m) (p_proto x) ∧ simple_match_port (sports m) (p_sport x) ∧ simple_match_port (dports m) (p_dport x))›*) by meson text‹subset or negation ... One efficient implementation would suffice.› private lemma "{p:: 'i::len simple_packet. simple_matches m p} ⊆ (simple_packet_set_toSet ms) ⟷ {p:: 'i::len simple_packet. simple_matches m p} ∩ (⋂ m ∈ set ms. {p. ¬ simple_matches m p}) = {}" (is "?l ⟷ ?r") proof (-) (*goal: ‹({p. simple_matches m p} ⊆ simple_packet_set_toSet ms) = ({p. simple_matches m p} ∩ (⋂m∈set ms. {p. ¬ simple_matches m p}) = {})›*) have "?l ⟷ {p. simple_matches m p} - (simple_packet_set_toSet ms) = {}" by blast also (*calculation: ‹({p. simple_matches m p} ⊆ simple_packet_set_toSet ms) = ({p. simple_matches m p} - simple_packet_set_toSet ms = {})›*) have "… ⟷ {p. simple_matches m p} - (⋃ m ∈ set ms. {p:: 'i::len simple_packet. simple_matches m p}) = {}" using simple_packet_set_toSet_alt (*‹simple_packet_set_toSet ?ms = (⋃m∈set ?ms. {p. simple_matches m p})›*) by blast also (*calculation: ‹({p. simple_matches m p} ⊆ simple_packet_set_toSet ms) = ({p. simple_matches m p} - (⋃m∈set ms. {p. simple_matches m p}) = {})›*) have "… ⟷ ?r" by blast finally (*calculation: ‹({p. simple_matches m p} ⊆ simple_packet_set_toSet ms) = ({p. simple_matches m p} ∩ (⋂m∈set ms. {p. ¬ simple_matches m p}) = {})›*) show "?thesis" (*goal: ‹({p. simple_matches m p} ⊆ simple_packet_set_toSet ms) = ({p. simple_matches m p} ∩ (⋂m∈set ms. {p. ¬ simple_matches m p}) = {})›*) . qed end end
{ "path": "afp-2025-02-12/thys/Simple_Firewall/Shadowed.thy", "repo": "afp-2025-02-12", "sha": "a8a5c7682f3fd797f3276824eb17763e7c694874f04b9e7773fc0cb88ebce948" }
section ‹Transition Systems and Trace Theory› theory Transition_System_Traces imports Transition_System_Extensions Traces begin lemma (in transition_system) words_infI_construct[rule_format, intro?]: assumes "∀ v. v ≤⇩F⇩I w ⟶ path v p" shows "run w p" using assms (*‹∀v. v ≤⇩F⇩I w ⟶ path v p›*) apply coinduct (*goal: ‹run w p›*) by auto lemma (in transition_system) words_infI_construct': assumes "⋀ k. ∃ v. v ≤⇩F⇩I w ∧ k < length v ∧ path v p" shows "run w p" proof (standard) (*goal: ‹⋀v. v ≤⇩F⇩I w ⟹ path v p›*) fix u assume 1: "u ≤⇩F⇩I w" (*‹(u::'transition list) ≤⇩F⇩I (w::'transition stream)›*) obtain v where 2: "v ≤⇩F⇩I w" "length u < length v" "path v p" (*goal: ‹(⋀v. ⟦v ≤⇩F⇩I w; length u < length v; path v p⟧ ⟹ thesis) ⟹ thesis›*) using assms(1) (*‹∃v. v ≤⇩F⇩I w ∧ ?k < length v ∧ path v p›*) by auto have 3: "length u ≤ length v" using "2"(2) (*‹length u < length v›*) by simp have 4: "u ≤ v" using prefix_fininf_length (*‹⟦?u ≤⇩F⇩I ?w; ?v ≤⇩F⇩I ?w; length ?u ≤ length ?v⟧ ⟹ ?u ≤ ?v›*) "1" (*‹u ≤⇩F⇩I w›*) "2"(1) (*‹v ≤⇩F⇩I w›*) "3" (*‹length u ≤ length v›*) by this show "path u p" using "4" (*‹u ≤ v›*) "2"(3) (*‹path v p›*) by auto qed lemma (in transition_system) words_infI_construct_chain[intro]: assumes "chain w" "⋀ k. path (w k) p" shows "run (limit w) p" proof (rule words_infI_construct' (*‹(⋀k::nat. ∃v::'transition::type list. v ≤⇩F⇩I (?w::'transition::type stream) ∧ k < length v ∧ path v (?p::'state::type)) ⟹ run ?w ?p›*)) (*goal: ‹⋀k. ∃v. v ≤⇩F⇩I limit w ∧ k < length v ∧ path v p›*) fix k obtain l where 1: "k < length (w l)" (*goal: ‹(⋀l. k < length (w l) ⟹ thesis) ⟹ thesis›*) using assms(1) (*‹chain w›*) by rule show "∃ v. v ≤⇩F⇩I limit w ∧ k < length v ∧ path v p" proof (intro exI (*‹?P ?x ⟹ ∃x. ?P x›*) conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹?v ≤⇩F⇩I limit w› 2. ‹k < length ?v› 3. ‹path ?v p›*) show "w l ≤⇩F⇩I limit w" using chain_prefix_limit (*‹chain ?w ⟹ ?w ?k ≤⇩F⇩I limit ?w›*) assms(1) (*‹chain w›*) by this show "k < length (w l)" using "1" (*‹k < length (w l)›*) by this show "path (w l) p" using assms(2) (*‹path (w ?k) p›*) by this qed qed lemma (in transition_system) words_fin_blocked: assumes "⋀ w. path w p ⟹ A ∩ set w = {} ⟹ A ∩ {a. enabled a (target w p)} ⊆ A ∩ {a. enabled a p}" assumes "path w p" "A ∩ {a. enabled a p} ∩ set w = {}" shows "A ∩ set w = {}" using assms (*‹⟦path (?w::'transition::type list) (p::'state::type); (A::'transition::type set) ∩ set ?w = {}⟧ ⟹ A ∩ {a::'transition::type. (enabled::'transition::type ⇒ 'state::type ⇒ bool) a (target ?w p)} ⊆ A ∩ {a::'transition::type. enabled a p}› ‹path (w::'transition::type list) (p::'state::type)› ‹A ∩ {a. enabled a p} ∩ set w = {}›*) apply (induct w rule: rev_induct (*‹⟦?P []; ⋀x xs. ?P xs ⟹ ?P (xs @ [x])⟧ ⟹ ?P ?xs›*)) (*goals: 1. ‹⟦⋀w. ⟦path w p; A ∩ set w = {}⟧ ⟹ A ∩ {a. enabled a (target w p)} ⊆ A ∩ {a. enabled a p}; path [] p; A ∩ {a. enabled a p} ∩ set [] = {}⟧ ⟹ A ∩ set [] = {}› 2. ‹⋀x xs. ⟦⟦⋀w. ⟦path w p; A ∩ set w = {}⟧ ⟹ A ∩ {a. enabled a (target w p)} ⊆ A ∩ {a. enabled a p}; path xs p; A ∩ {a. enabled a p} ∩ set xs = {}⟧ ⟹ A ∩ set xs = {}; ⋀w. ⟦path w p; A ∩ set w = {}⟧ ⟹ A ∩ {a. enabled a (target w p)} ⊆ A ∩ {a. enabled a p}; path (xs @ [x]) p; A ∩ {a. enabled a p} ∩ set (xs @ [x]) = {}⟧ ⟹ A ∩ set (xs @ [x]) = {}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . locale transition_system_traces = transition_system ex en + traces ind for ex :: "'action ⇒ 'state ⇒ 'state" and en :: "'action ⇒ 'state ⇒ bool" and ind :: "'action ⇒ 'action ⇒ bool" + assumes en: "ind a b ⟹ en a p ⟹ en b p ⟷ en b (ex a p)" assumes ex: "ind a b ⟹ en a p ⟹ en b p ⟹ ex b (ex a p) = ex a (ex b p)" begin lemma diamond_bottom: assumes "ind a b" assumes "en a p" "en b p" shows "en a (ex b p)" "en b (ex a p)" "ex b (ex a p) = ex a (ex b p)" using assms (*‹ind a b› ‹en a p› ‹en b p›*) independence_symmetric (*‹ind ?a ?b ⟹ ind ?b ?a›*) en (*‹⟦ind ?a ?b; en ?a ?p⟧ ⟹ en ?b ?p = en ?b (ex ?a ?p)›*) ex (*‹⟦(ind::'action ⇒ 'action ⇒ bool) (?a::'action) (?b::'action); (en::'action ⇒ 'state ⇒ bool) ?a (?p::'state); en ?b ?p⟧ ⟹ (ex::'action ⇒ 'state ⇒ 'state) ?b (ex ?a ?p) = ex ?a (ex ?b ?p)›*) apply - (*goals: 1. ‹⟦ind a b; en a p; en b p; ⋀a b. ind a b ⟹ ind b a; ⋀a b p. ⟦ind a b; en a p⟧ ⟹ en b p = en b (ex a p); ⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ ex b (ex a p) = ex a (ex b p)⟧ ⟹ en a (ex b p)› 2. ‹⟦ind a b; en a p; en b p; ⋀a b. ind a b ⟹ ind b a; ⋀a b p. ⟦ind a b; en a p⟧ ⟹ en b p = en b (ex a p); ⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ ex b (ex a p) = ex a (ex b p)⟧ ⟹ en b (ex a p)› 3. ‹⟦ind a b; en a p; en b p; ⋀a b. ind a b ⟹ ind b a; ⋀a b p. ⟦ind a b; en a p⟧ ⟹ en b p = en b (ex a p); ⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ ex b (ex a p) = ex a (ex b p)⟧ ⟹ ex b (ex a p) = ex a (ex b p)› discuss goal 1*) apply metis (*discuss goal 2*) apply metis (*discuss goal 3*) apply metis (*proven 3 subgoals*) . lemma diamond_right: assumes "ind a b" assumes "en a p" "en b (ex a p)" shows "en a (ex b p)" "en b p" "ex b (ex a p) = ex a (ex b p)" using assms (*‹ind a b› ‹(en::'action ⇒ 'state ⇒ bool) (a::'action) (p::'state)› ‹en b (ex a p)›*) independence_symmetric (*‹(ind::'action::type ⇒ 'action::type ⇒ bool) (?a::'action::type) (?b::'action::type) ⟹ ind ?b ?a›*) en (*‹⟦ind ?a ?b; en ?a ?p⟧ ⟹ en ?b ?p = en ?b (ex ?a ?p)›*) ex (*‹⟦ind ?a ?b; en ?a ?p; en ?b ?p⟧ ⟹ ex ?b (ex ?a ?p) = ex ?a (ex ?b ?p)›*) apply - (*goals: 1. ‹⟦ind a b; en a p; en b (ex a p); ⋀a b. ind a b ⟹ ind b a; ⋀a b p. ⟦ind a b; en a p⟧ ⟹ en b p = en b (ex a p); ⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ ex b (ex a p) = ex a (ex b p)⟧ ⟹ en a (ex b p)› 2. ‹⟦ind a b; en a p; en b (ex a p); ⋀a b. ind a b ⟹ ind b a; ⋀a b p. ⟦ind a b; en a p⟧ ⟹ en b p = en b (ex a p); ⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ ex b (ex a p) = ex a (ex b p)⟧ ⟹ en b p› 3. ‹⟦ind a b; en a p; en b (ex a p); ⋀a b. ind a b ⟹ ind b a; ⋀a b p. ⟦ind a b; en a p⟧ ⟹ en b p = en b (ex a p); ⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ ex b (ex a p) = ex a (ex b p)⟧ ⟹ ex b (ex a p) = ex a (ex b p)› discuss goal 1*) apply metis (*discuss goal 2*) apply metis (*discuss goal 3*) apply metis (*proven 3 subgoals*) . lemma diamond_left: assumes "ind a b" assumes "en a (ex b p)" "en b p" shows "en a p" "en b (ex a p)" "ex b (ex a p) = ex a (ex b p)" using assms (*‹(ind::'action ⇒ 'action ⇒ bool) (a::'action) (b::'action)› ‹en a (ex b p)› ‹en b p›*) independence_symmetric (*‹ind ?a ?b ⟹ ind ?b ?a›*) en (*‹⟦ind ?a ?b; en ?a ?p⟧ ⟹ en ?b ?p = en ?b (ex ?a ?p)›*) ex (*‹⟦ind ?a ?b; en ?a ?p; en ?b ?p⟧ ⟹ ex ?b (ex ?a ?p) = ex ?a (ex ?b ?p)›*) apply - (*goals: 1. ‹⟦ind a b; en a (ex b p); en b p; ⋀a b. ind a b ⟹ ind b a; ⋀a b p. ⟦ind a b; en a p⟧ ⟹ en b p = en b (ex a p); ⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ ex b (ex a p) = ex a (ex b p)⟧ ⟹ en a p› 2. ‹⟦ind a b; en a (ex b p); en b p; ⋀a b. ind a b ⟹ ind b a; ⋀a b p. ⟦ind a b; en a p⟧ ⟹ en b p = en b (ex a p); ⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ ex b (ex a p) = ex a (ex b p)⟧ ⟹ en b (ex a p)› 3. ‹⟦ind a b; en a (ex b p); en b p; ⋀a b. ind a b ⟹ ind b a; ⋀a b p. ⟦ind a b; en a p⟧ ⟹ en b p = en b (ex a p); ⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ ex b (ex a p) = ex a (ex b p)⟧ ⟹ ex b (ex a p) = ex a (ex b p)› discuss goal 1*) apply metis (*discuss goal 2*) apply metis (*discuss goal 3*) apply metis (*proven 3 subgoals*) . lemma eq_swap_word: assumes "w₁ =⇩S w₂" "path w₁ p" shows "path w₂ p" using assms (*‹w₁ =⇩S w₂› ‹path w₁ p›*) diamond_right (*‹⟦(ind::'action ⇒ 'action ⇒ bool) (?a::'action) (?b::'action); (en::'action ⇒ 'state ⇒ bool) ?a (?p::'state); en ?b ((ex::'action ⇒ 'state ⇒ 'state) ?a ?p)⟧ ⟹ en ?a (ex ?b ?p)› ‹⟦ind ?a ?b; en ?a ?p; en ?b (ex ?a ?p)⟧ ⟹ en ?b ?p› ‹⟦ind ?a ?b; en ?a ?p; en ?b (ex ?a ?p)⟧ ⟹ ex ?b (ex ?a ?p) = ex ?a (ex ?b ?p)›*) apply induct (*goal: ‹path w₂ p›*) by auto lemma eq_fin_word: assumes "w₁ =⇩F w₂" "path w₁ p" shows "path w₂ p" using assms (*‹(w₁::'action list) =⇩F (w₂::'action list)› ‹path w₁ p›*) eq_swap_word (*‹⟦?w₁ =⇩S ?w₂; path ?w₁ ?p⟧ ⟹ path ?w₂ ?p›*) apply induct (*goals: 1. ‹⟦path w₁ p; ⋀w₁ w₂ p. ⟦w₁ =⇩S w₂; path w₁ p⟧ ⟹ path w₂ p⟧ ⟹ path w₁ p› 2. ‹⋀y z. ⟦w₁ =⇩F y; y =⇩S z; ⟦path w₁ p; ⋀w₁ w₂ p. ⟦w₁ =⇩S w₂; path w₁ p⟧ ⟹ path w₂ p⟧ ⟹ path y p; path w₁ p; ⋀w₁ w₂ p. ⟦w₁ =⇩S w₂; path w₁ p⟧ ⟹ path w₂ p⟧ ⟹ path z p› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma le_fin_word: assumes "w₁ ≼⇩F w₂" "path w₂ p" shows "path w₁ p" using assms (*‹(w₁::'action list) ≼⇩F (w₂::'action list)› ‹path w₂ p›*) eq_fin_word (*‹⟦?w₁ =⇩F ?w₂; path ?w₁ ?p⟧ ⟹ path ?w₂ ?p›*) by blast lemma le_fininf_word: assumes "w₁ ≼⇩F⇩I w₂" "run w₂ p" shows "path w₁ p" using assms (*‹w₁ ≼⇩F⇩I w₂› ‹run w₂ p›*) le_fin_word (*‹⟦?w₁ ≼⇩F ?w₂; path ?w₂ ?p⟧ ⟹ path ?w₁ ?p›*) by blast lemma le_inf_word: assumes "w₂ ≼⇩I w₁" "run w₁ p" shows "run w₂ p" using assms (*‹(w₂::'action::type stream) ≼⇩I (w₁::'action::type stream)› ‹run (w₁::'action::type stream) (p::'state::type)›*) le_fininf_word (*‹⟦?w₁ ≼⇩F⇩I ?w₂; run ?w₂ ?p⟧ ⟹ path ?w₁ ?p›*) by (blast intro: words_infI_construct (*‹(⋀v. v ≤⇩F⇩I ?w ⟹ path v ?p) ⟹ run ?w ?p›*)) lemma eq_inf_word: assumes "w₁ =⇩I w₂" "run w₁ p" shows "run w₂ p" using assms (*‹(w₁::'action stream) =⇩I (w₂::'action stream)› ‹run w₁ p›*) le_inf_word (*‹⟦(?w₂::'action stream) ≼⇩I (?w₁::'action stream); run ?w₁ (?p::'state)⟧ ⟹ run ?w₂ ?p›*) by auto lemma eq_swap_execute: assumes "path w₁ p" "w₁ =⇩S w₂" shows "fold ex w₁ p = fold ex w₂ p" using assms(2,1) (*‹w₁ =⇩S w₂› ‹path w₁ p›*) diamond_right (*‹⟦ind ?a ?b; en ?a ?p; en ?b (ex ?a ?p)⟧ ⟹ en ?a (ex ?b ?p)› ‹⟦(ind::'action ⇒ 'action ⇒ bool) (?a::'action) (?b::'action); (en::'action ⇒ 'state ⇒ bool) ?a (?p::'state); en ?b ((ex::'action ⇒ 'state ⇒ 'state) ?a ?p)⟧ ⟹ en ?b ?p› ‹⟦(ind::'action ⇒ 'action ⇒ bool) (?a::'action) (?b::'action); (en::'action ⇒ 'state ⇒ bool) ?a (?p::'state); en ?b ((ex::'action ⇒ 'state ⇒ 'state) ?a ?p)⟧ ⟹ ex ?b (ex ?a ?p) = ex ?a (ex ?b ?p)›*) apply induct (*goal: ‹target (w₁::'action list) (p::'state) = target (w₂::'action list) p›*) by auto lemma eq_fin_execute: assumes "path w₁ p" "w₁ =⇩F w₂" shows "fold ex w₁ p = fold ex w₂ p" using assms(2,1) (*‹w₁ =⇩F w₂› ‹path w₁ p›*) eq_fin_word (*‹⟦?w₁ =⇩F ?w₂; path ?w₁ ?p⟧ ⟹ path ?w₂ ?p›*) eq_swap_execute (*‹⟦path ?w₁ ?p; ?w₁ =⇩S ?w₂⟧ ⟹ target ?w₁ ?p = target ?w₂ ?p›*) apply induct (*goals: 1. ‹⟦path w₁ p; ⋀w₁ w₂ p. ⟦w₁ =⇩F w₂; path w₁ p⟧ ⟹ path w₂ p; ⋀w₁ p w₂. ⟦path w₁ p; w₁ =⇩S w₂⟧ ⟹ target w₁ p = target w₂ p⟧ ⟹ target w₁ p = target w₁ p› 2. ‹⋀y z. ⟦w₁ =⇩F y; y =⇩S z; ⟦path w₁ p; ⋀w₁ w₂ p. ⟦w₁ =⇩F w₂; path w₁ p⟧ ⟹ path w₂ p; ⋀w₁ p w₂. ⟦path w₁ p; w₁ =⇩S w₂⟧ ⟹ target w₁ p = target w₂ p⟧ ⟹ target w₁ p = target y p; path w₁ p; ⋀w₁ w₂ p. ⟦w₁ =⇩F w₂; path w₁ p⟧ ⟹ path w₂ p; ⋀w₁ p w₂. ⟦path w₁ p; w₁ =⇩S w₂⟧ ⟹ target w₁ p = target w₂ p⟧ ⟹ target w₁ p = target z p› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma diamond_fin_word_step: assumes "Ind {a} (set v)" "en a p" "path v p" shows "path v (ex a p)" using diamond_bottom (*‹⟦ind ?a ?b; en ?a ?p; en ?b ?p⟧ ⟹ en ?a (ex ?b ?p)› ‹⟦ind ?a ?b; en ?a ?p; en ?b ?p⟧ ⟹ en ?b (ex ?a ?p)› ‹⟦ind ?a ?b; en ?a ?p; en ?b ?p⟧ ⟹ ex ?b (ex ?a ?p) = ex ?a (ex ?b ?p)›*) assms (*‹Ind {a::'action} (set (v::'action list))› ‹en a p› ‹path v p›*) apply (induct v arbitrary: p) (*goals: 1. ‹⋀p. ⟦⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ en a (ex b p); ⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ en b (ex a p); ⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ ex b (ex a p) = ex a (ex b p); Ind {a} (set []); en a p; path [] p⟧ ⟹ path [] (ex a p)› 2. ‹⋀aa v p. ⟦⋀p. ⟦⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ en a (ex b p); ⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ en b (ex a p); ⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ ex b (ex a p) = ex a (ex b p); Ind {a} (set v); en a p; path v p⟧ ⟹ path v (ex a p); ⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ en a (ex b p); ⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ en b (ex a p); ⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ ex b (ex a p) = ex a (ex b p); Ind {a} (set (aa # v)); en a p; path (aa # v) p⟧ ⟹ path (aa # v) (ex a p)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*goal: ‹⋀aa v p. ⟦⋀p. ⟦⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ en a (ex b p); ⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ en b (ex a p); ⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ ex b (ex a p) = ex a (ex b p); Ind {a} (set v); en a p; path v p⟧ ⟹ path v (ex a p); ⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ en a (ex b p); ⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ en b (ex a p); ⋀a b p. ⟦ind a b; en a p; en b p⟧ ⟹ ex b (ex a p) = ex a (ex b p); Ind {a} (set (aa # v)); en a p; path (aa # v) p⟧ ⟹ path (aa # v) (ex a p)›*) apply metis (*proven 2 subgoals*) . lemma diamond_inf_word_step: assumes "Ind {a} (sset w)" "en a p" "run w p" shows "run w (ex a p)" using diamond_fin_word_step (*‹⟦Ind {?a::'action} (set (?v::'action list)); (en::'action ⇒ 'state ⇒ bool) ?a (?p::'state); path ?v ?p⟧ ⟹ path ?v ((ex::'action ⇒ 'state ⇒ 'state) ?a ?p)›*) assms (*‹Ind {a::'action::type} (sset (w::'action::type stream))› ‹(en::'action::type ⇒ 'state::type ⇒ bool) (a::'action::type) (p::'state::type)› ‹run w p›*) by (fast intro: words_infI_construct (*‹(⋀v. v ≤⇩F⇩I ?w ⟹ path v ?p) ⟹ run ?w ?p›*)) lemma diamond_fin_word_inf_word: assumes "Ind (set v) (sset w)" "path v p" "run w p" shows "run w (fold ex v p)" using diamond_inf_word_step (*‹⟦Ind {?a::'action::type} (sset (?w::'action::type stream)); (en::'action::type ⇒ 'state::type ⇒ bool) ?a (?p::'state::type); run ?w ?p⟧ ⟹ run ?w ((ex::'action::type ⇒ 'state::type ⇒ 'state::type) ?a ?p)›*) assms (*‹Ind (set v) (sset w)› ‹path (v::'action list) (p::'state)› ‹run w p›*) apply (induct v arbitrary: p) (*goals: 1. ‹⋀p::'state. ⟦⋀(a::'action) (w::'action stream) p::'state. ⟦Ind {a} (sset w); (en::'action ⇒ 'state ⇒ bool) a p; run w p⟧ ⟹ run w ((ex::'action ⇒ 'state ⇒ 'state) a p); Ind (set []) (sset (w::'action stream)); path [] p; run w p⟧ ⟹ run w (target [] p)› 2. ‹⋀(a::'action) (v::'action list) p::'state. ⟦⋀p::'state. ⟦⋀(a::'action) (w::'action stream) p::'state. ⟦Ind {a} (sset w); (en::'action ⇒ 'state ⇒ bool) a p; run w p⟧ ⟹ run w ((ex::'action ⇒ 'state ⇒ 'state) a p); Ind (set v) (sset (w::'action stream)); path v p; run w p⟧ ⟹ run w (target v p); ⋀(a::'action) (w::'action stream) p::'state. ⟦Ind {a} (sset w); en a p; run w p⟧ ⟹ run w (ex a p); Ind (set (a # v)) (sset w); path (a # v) p; run w p⟧ ⟹ run w (target (a # v) p)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma diamond_fin_word_inf_word': assumes "Ind (set v) (sset w)" "path (u @ v) p" "run (u @- w) p" shows "run (u @- v @- w) p" using assms (*‹Ind (set v) (sset w)› ‹path (u @ v) p› ‹run (u @- w) p›*) diamond_fin_word_inf_word (*‹⟦Ind (set ?v) (sset ?w); path ?v ?p; run ?w ?p⟧ ⟹ run ?w (target ?v ?p)›*) by auto end end
{ "path": "afp-2025-02-12/thys/Partial_Order_Reduction/Transition_System_Traces.thy", "repo": "afp-2025-02-12", "sha": "720015277cab71aa99a0b940f12f20b283417506013468c45a720847cd427261" }
section ‹Tries via Functions› theory Trie_Fun imports Set_Specs begin text ‹A trie where each node maps a key to sub-tries via a function. Nice abstract model. Not efficient because of the function space.› datatype 'a trie = Nd bool "'a ⇒ 'a trie option" definition empty :: "'a trie" where [simp]: "empty = Nd False (λ_. None)" fun isin :: "'a trie ⇒ 'a list ⇒ bool" where "isin (Nd b m) [] = b" | "isin (Nd b m) (k # xs) = (case m k of None ⇒ False | Some t ⇒ isin t xs)" fun insert :: "'a list ⇒ 'a trie ⇒ 'a trie" where "insert [] (Nd b m) = Nd True m" | "insert (x#xs) (Nd b m) = (let s = (case m x of None ⇒ empty | Some t ⇒ t) in Nd b (m(x := Some(insert xs s))))" fun delete :: "'a list ⇒ 'a trie ⇒ 'a trie" where "delete [] (Nd b m) = Nd False m" | "delete (x#xs) (Nd b m) = Nd b (case m x of None ⇒ m | Some t ⇒ m(x := Some(delete xs t)))" text ‹Use (a tuned version of) @{const isin} as an abstraction function:› lemma isin_case: "isin (Nd b m) xs = (case xs of [] ⇒ b | x # ys ⇒ (case m x of None ⇒ False | Some t ⇒ isin t ys))" apply (cases xs) (*goals: 1. ‹(xs::'a list) = [] ⟹ isin (Nd (b::bool) (m::'a ⇒ 'a trie option)) xs = (case xs of [] ⇒ b | (x::'a) # (ys::'a list) ⇒ case m x of None ⇒ False | Some (t::'a trie) ⇒ isin t ys)› 2. ‹⋀(a::'a) list::'a list. (xs::'a list) = a # list ⟹ isin (Nd (b::bool) (m::'a ⇒ 'a trie option)) xs = (case xs of [] ⇒ b | (x::'a) # (ys::'a list) ⇒ case m x of None ⇒ False | Some (t::'a trie) ⇒ isin t ys)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . definition set :: "'a trie ⇒ 'a list set" where [simp]: "set t = {xs. isin t xs}" lemma isin_set: "isin t xs = (xs ∈ set t)" by simp lemma set_insert: "set (insert xs t) = set t ∪ {xs}" apply (induction xs t rule: insert.induct (*‹⟦⋀b m. ?P [] (Nd b m); ⋀x xs b m. (⋀xa. xa = (case m x of None ⇒ Trie_Fun.empty | Some t ⇒ t) ⟹ ?P xs xa) ⟹ ?P (x # xs) (Nd b m)⟧ ⟹ ?P ?a0.0 ?a1.0›*)) (*goals: 1. ‹⋀b m. Trie_Fun.set (Trie_Fun.insert [] (Nd b m)) = Trie_Fun.set (Nd b m) ∪ {[]}› 2. ‹⋀x xs b m. (⋀xa. xa = (case m x of None ⇒ Trie_Fun.empty | Some t ⇒ t) ⟹ Trie_Fun.set (Trie_Fun.insert xs xa) = Trie_Fun.set xa ∪ {xs}) ⟹ Trie_Fun.set (Trie_Fun.insert (x # xs) (Nd b m)) = Trie_Fun.set (Nd b m) ∪ {x # xs}› discuss goal 1*) apply ((auto simp: isin_case (*‹isin (Nd ?b ?m) ?xs = (case ?xs of [] ⇒ ?b | x # ys ⇒ case ?m x of None ⇒ False | Some t ⇒ isin t ys)›*) split!: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) list.splits (*‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = ((?list = [] ⟶ ?P ?f1.0) ∧ (∀x21 x22. ?list = x21 # x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = (¬ (?list = [] ∧ ¬ ?P ?f1.0 ∨ (∃x21 x22. ?list = x21 # x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*))[1]) (*discuss goal 2*) apply ((auto simp: isin_case (*‹isin (Nd ?b ?m) ?xs = (case ?xs of [] ⇒ ?b | x # ys ⇒ case ?m x of None ⇒ False | Some t ⇒ isin t ys)›*) split!: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) list.splits (*‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = ((?list = [] ⟶ ?P ?f1.0) ∧ (∀x21 x22. ?list = x21 # x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = (¬ (?list = [] ∧ ¬ ?P ?f1.0 ∨ (∃x21 x22. ?list = x21 # x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*))[1]) (*proven 2 subgoals*) . lemma set_delete: "set (delete xs t) = set t - {xs}" apply (induction xs t rule: delete.induct (*‹⟦⋀b m. ?P [] (Nd b m); ⋀x xs b m. (⋀x2. m x = Some x2 ⟹ ?P xs x2) ⟹ ?P (x # xs) (Nd b m)⟧ ⟹ ?P ?a0.0 ?a1.0›*)) (*goals: 1. ‹⋀(b::bool) m::'a::type ⇒ 'a::type trie option. Trie_Fun.set (delete [] (Nd b m)) = Trie_Fun.set (Nd b m) - {[]}› 2. ‹⋀(x::'a::type) (xs::'a::type list) (b::bool) m::'a::type ⇒ 'a::type trie option. (⋀x2::'a::type trie. m x = Some x2 ⟹ Trie_Fun.set (delete xs x2) = Trie_Fun.set x2 - {xs}) ⟹ Trie_Fun.set (delete (x # xs) (Nd b m)) = Trie_Fun.set (Nd b m) - {x # xs}› discuss goal 1*) apply ((auto simp: isin_case (*‹isin (Nd ?b ?m) ?xs = (case ?xs of [] ⇒ ?b | x # ys ⇒ case ?m x of None ⇒ False | Some t ⇒ isin t ys)›*) split!: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) list.splits (*‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = ((?list = [] ⟶ ?P ?f1.0) ∧ (∀x21 x22. ?list = x21 # x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = (¬ (?list = [] ∧ ¬ ?P ?f1.0 ∨ (∃x21 x22. ?list = x21 # x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*))[1]) (*discuss goal 2*) apply ((auto simp: isin_case (*‹isin (Nd ?b ?m) ?xs = (case ?xs of [] ⇒ ?b | x # ys ⇒ case ?m x of None ⇒ False | Some t ⇒ isin t ys)›*) split!: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) list.splits (*‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = ((?list = [] ⟶ ?P ?f1.0) ∧ (∀x21 x22. ?list = x21 # x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = (¬ (?list = [] ∧ ¬ ?P ?f1.0 ∨ (∃x21 x22. ?list = x21 # x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*))[1]) (*proven 2 subgoals*) . interpretation S: Set where empty = empty and isin = isin and insert = insert and delete = delete and set = set and invar = "λ_. True" proof (standard, goal_cases) (*goals: 1. ‹Trie_Fun.set Trie_Fun.empty = {}› 2. ‹⋀s x. True ⟹ isin s x = (x ∈ Trie_Fun.set s)› 3. ‹⋀s x. True ⟹ Trie_Fun.set (Trie_Fun.insert x s) = Trie_Fun.set s ∪ {x}› 4. ‹⋀s x. True ⟹ Trie_Fun.set (delete x s) = Trie_Fun.set s - {x}› 5. ‹True› 6. ‹⋀s x. True ⟹ True›*) case 1 (*no hyothesis introduced yet*) show "?case" (*goal: ‹Trie_Fun.set Trie_Fun.empty = {}›*) by (simp add: isin_case (*‹isin (Nd ?b ?m) ?xs = (case ?xs of [] ⇒ ?b | x # ys ⇒ case ?m x of None ⇒ False | Some t ⇒ isin t ys)›*) split: list.split (*‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = ((?list = [] ⟶ ?P ?f1.0) ∧ (∀x21 x22. ?list = x21 # x22 ⟶ ?P (?f2.0 x21 x22)))›*)) next (*goals: 1. ‹⋀s x. True ⟹ isin s x = (x ∈ Trie_Fun.set s)› 2. ‹⋀s x. True ⟹ Trie_Fun.set (Trie_Fun.insert x s) = Trie_Fun.set s ∪ {x}› 3. ‹⋀s x. True ⟹ Trie_Fun.set (delete x s) = Trie_Fun.set s - {x}› 4. ‹True› 5. ‹⋀s x. True ⟹ True›*) case 2 (*‹True›*) show "?case" (*goal: ‹isin s_ x_ = (x_ ∈ Trie_Fun.set s_)›*) by (rule isin_set (*‹isin ?t ?xs = (?xs ∈ Trie_Fun.set ?t)›*)) next (*goals: 1. ‹⋀s x. True ⟹ Trie_Fun.set (Trie_Fun.insert x s) = Trie_Fun.set s ∪ {x}› 2. ‹⋀s x. True ⟹ Trie_Fun.set (delete x s) = Trie_Fun.set s - {x}› 3. ‹True› 4. ‹⋀s x. True ⟹ True›*) case 3 (*‹True›*) show "?case" (*goal: ‹Trie_Fun.set (Trie_Fun.insert x_ s_) = Trie_Fun.set s_ ∪ {x_}›*) by (rule set_insert (*‹Trie_Fun.set (Trie_Fun.insert ?xs ?t) = Trie_Fun.set ?t ∪ {?xs}›*)) next (*goals: 1. ‹⋀s x. True ⟹ Trie_Fun.set (delete x s) = Trie_Fun.set s - {x}› 2. ‹True› 3. ‹⋀s x. True ⟹ True›*) case 4 (*‹True›*) show "?case" (*goal: ‹Trie_Fun.set (delete (x_::'a list) (s_::'a trie)) = Trie_Fun.set s_ - {x_}›*) by (rule set_delete (*‹Trie_Fun.set (delete ?xs ?t) = Trie_Fun.set ?t - {?xs}›*)) qed ((rule TrueI (*‹True›*))+) (*solves the remaining goals: 1. ‹True› 2. ‹⋀s x. True ⟹ True›*) end
{ "path": "Isabelle2024/src/HOL/Data_Structures/Trie_Fun.thy", "repo": "Isabelle2024", "sha": "93e76331845cb8a756a2d5576e7fcc04d369ff727bb1197a9b1b1cd448f0a089" }
(* File: Perfect_Fields/Perfect_Fields.thy Authors: Katharina Kreuzer (TU München) Manuel Eberl (University of Innsbruck) Typeclasses for fields of prime characteristic Frobenius endomorphism on a field type Fields with a surjective Frobenius endomorphism Typeclass for perfect fields and some basic results about them *) section ‹Perfect Fields› theory Perfect_Fields imports "HOL-Computational_Algebra.Computational_Algebra" "Berlekamp_Zassenhaus.Finite_Field" begin lemma (in vector_space) bij_betw_representation: assumes [simp]: "independent B" "finite B" shows "bij_betw (λv. ∑b∈B. scale (v b) b) (B →⇩E UNIV) (span B)" proof (rule bij_betwI (*‹⟦?f ∈ ?A → ?B; ?g ∈ ?B → ?A; ⋀x. x ∈ ?A ⟹ ?g (?f x) = x; ⋀y. y ∈ ?B ⟹ ?f (?g y) = y⟧ ⟹ bij_betw ?f ?A ?B›*)) (*goals: 1. ‹(λv. ∑b∈B. v b *s b) ∈ (B →⇩E UNIV) → local.span B› 2. ‹?g ∈ local.span B → B →⇩E UNIV› 3. ‹⋀x. x ∈ B →⇩E UNIV ⟹ ?g (∑b∈B. x b *s b) = x› 4. ‹⋀y. y ∈ local.span B ⟹ (∑b∈B. ?g y b *s b) = y›*) show "(λv. ∑b∈B. v b *s b) ∈ (B →⇩E UNIV) → local.span B" (is "?f ∈ _") by (auto intro: span_sum (*‹(⋀x. x ∈ ?A ⟹ ?f x ∈ local.span ?S) ⟹ sum ?f ?A ∈ local.span ?S›*) span_scale (*‹?x ∈ local.span ?S ⟹ ?c *s ?x ∈ local.span ?S›*) span_base (*‹?a ∈ ?S ⟹ ?a ∈ local.span ?S›*)) show "(λx. restrict (representation B x) B) ∈ local.span B → B →⇩E UNIV" (is "?g ∈ _") by auto show "?g (?f v) = v" if "v ∈ B →⇩E UNIV" for v proof (standard) (*goal: ‹⋀x. restrict (local.representation B (∑b∈B. v b *s b)) B x = v x›*) fix b :: 'b show "?g (?f v) b = v b" proof (cases "b ∈ B") (*goals: 1. ‹(b::'b::ab_group_add) ∈ (B::'b::ab_group_add set) ⟹ restrict (local.representation B (∑b::'b::ab_group_add∈B. (v::'b::ab_group_add ⇒ 'a::field) b *s b)) B b = v b› 2. ‹(b::'b::ab_group_add) ∉ (B::'b::ab_group_add set) ⟹ restrict (local.representation B (∑b::'b::ab_group_add∈B. (v::'b::ab_group_add ⇒ 'a::field) b *s b)) B b = v b›*) case b: True (*‹b ∈ B›*) have "?g (?f v) b = (∑i∈B. local.representation B (v i *s i) b)" using b (*‹b ∈ B›*) apply (subst representation_sum (*‹⟦local.independent ?basis; ⋀i. i ∈ ?I ⟹ ?v i ∈ local.span ?basis⟧ ⟹ local.representation ?basis (sum ?v ?I) = (λb. ∑i∈?I. local.representation ?basis (?v i) b)›*)) (*goals: 1. ‹b ∈ B ⟹ local.independent B› 2. ‹⋀i. ⟦b ∈ B; i ∈ B⟧ ⟹ v i *s i ∈ local.span B› 3. ‹b ∈ B ⟹ (λb∈B. ∑i∈B. local.representation B (v i *s i) b) b = (∑i∈B. local.representation B (v i *s i) b)› discuss goal 1*) apply ((auto intro: span_scale (*‹?x ∈ local.span ?S ⟹ ?c *s ?x ∈ local.span ?S›*) span_base (*‹?a ∈ ?S ⟹ ?a ∈ local.span ?S›*))[1]) (*discuss goal 2*) apply ((auto intro: span_scale (*‹?x ∈ local.span ?S ⟹ ?c *s ?x ∈ local.span ?S›*) span_base (*‹?a ∈ ?S ⟹ ?a ∈ local.span ?S›*))[1]) (*discuss goal 3*) apply ((auto intro: span_scale (*‹?x ∈ local.span ?S ⟹ ?c *s ?x ∈ local.span ?S›*) span_base (*‹?a ∈ ?S ⟹ ?a ∈ local.span ?S›*))[1]) (*proven 3 subgoals*) . also (*calculation: ‹restrict (local.representation B (∑b∈B. v b *s b)) B b = (∑i∈B. local.representation B (v i *s i) b)›*) have "… = (∑i∈B. v i * local.representation B i b)" apply (intro sum.cong (*‹⟦?A = ?B; ⋀x. x ∈ ?B ⟹ ?g x = ?h x⟧ ⟹ sum ?g ?A = sum ?h ?B›*)) (*goals: 1. ‹B = B› 2. ‹⋀x. x ∈ B ⟹ local.representation B (v x *s x) b = v x * local.representation B x b› discuss goal 1*) apply ((auto simp: representation_scale (*‹⟦local.independent ?basis; ?v ∈ local.span ?basis⟧ ⟹ local.representation ?basis (?r *s ?v) = (λb. ?r * local.representation ?basis ?v b)›*) span_base (*‹?a ∈ ?S ⟹ ?a ∈ local.span ?S›*))[1]) (*discuss goal 2*) apply ((auto simp: representation_scale (*‹⟦local.independent ?basis; ?v ∈ local.span ?basis⟧ ⟹ local.representation ?basis (?r *s ?v) = (λb. ?r * local.representation ?basis ?v b)›*) span_base (*‹?a ∈ ?S ⟹ ?a ∈ local.span ?S›*))[1]) (*proven 2 subgoals*) . also (*calculation: ‹restrict (local.representation (B::'b::ab_group_add set) (∑b::'b::ab_group_add∈B. (v::'b::ab_group_add ⇒ 'a::field) b *s b)) B (b::'b::ab_group_add) = (∑i::'b::ab_group_add∈B. v i * local.representation B i b)›*) have "… = (∑i∈{b}. v i * local.representation B i b)" apply (intro sum.mono_neutral_right (*‹⟦finite ?T; ?S ⊆ ?T; ∀i∈?T - ?S. ?g i = 0⟧ ⟹ sum ?g ?T = sum ?g ?S›*)) (*goals: 1. ‹finite B› 2. ‹{b} ⊆ B› 3. ‹∀i∈B - {b}. v i * local.representation B i b = 0› discuss goal 1*) apply ((auto simp: representation_basis (*‹⟦local.independent (?basis::'b set); (?b::'b) ∈ ?basis⟧ ⟹ local.representation ?basis ?b = (λv::'b. if v = ?b then 1::'a else (0::'a))›*) b (*‹(b::'b) ∈ (B::'b set)›*))[1]) (*discuss goal 2*) apply ((auto simp: representation_basis (*‹⟦local.independent ?basis; ?b ∈ ?basis⟧ ⟹ local.representation ?basis ?b = (λv. if v = ?b then 1 else 0)›*) b (*‹b ∈ B›*))[1]) (*discuss goal 3*) apply ((auto simp: representation_basis (*‹⟦local.independent ?basis; ?b ∈ ?basis⟧ ⟹ local.representation ?basis ?b = (λv. if v = ?b then 1 else 0)›*) b (*‹b ∈ B›*))[1]) (*proven 3 subgoals*) . also (*calculation: ‹restrict (local.representation B (∑b∈B. v b *s b)) B b = (∑i∈{b}. v i * local.representation B i b)›*) have "… = v b" by (simp add: representation_basis (*‹⟦local.independent ?basis; ?b ∈ ?basis⟧ ⟹ local.representation ?basis ?b = (λv. if v = ?b then 1 else 0)›*) b (*‹b ∈ B›*)) finally (*calculation: ‹restrict (local.representation B (∑b∈B. v b *s b)) B b = v b›*) show "?g (?f v) b = v b" . qed (use that in auto) (*solved the remaining goal: ‹(b::'b) ∉ (B::'b set) ⟹ restrict (local.representation B (∑b::'b∈B. (v::'b ⇒ 'a) b *s b)) B b = v b›*) qed show "?f (?g v) = v" if "v ∈ span B" for v using that (*‹(v::'b::ab_group_add) ∈ local.span (B::'b::ab_group_add set)›*) by (simp add: sum_representation_eq (*‹⟦local.independent ?basis; ?v ∈ local.span ?basis; finite ?B; ?basis ⊆ ?B⟧ ⟹ (∑b∈?B. local.representation ?basis ?v b *s b) = ?v›*)) qed lemma (in vector_space) card_span: assumes [simp]: "independent B" "finite B" shows "card (span B) = CARD('a) ^ card B" proof (-) (*goal: ‹card (local.span B) = CARD('a) ^ card B›*) have "card (B →⇩E (UNIV :: 'a set)) = card (span B)" apply (rule bij_betw_same_card (*‹bij_betw ?f ?A ?B ⟹ card ?A = card ?B›*)) (*goal: ‹card (B →⇩E UNIV) = card (local.span B)›*) apply (rule bij_betw_representation (*‹⟦local.independent ?B; finite ?B⟧ ⟹ bij_betw (λv. ∑b∈?B. v b *s b) (?B →⇩E UNIV) (local.span ?B)›*)) (*goals: 1. ‹local.independent B› 2. ‹finite B› discuss goal 1*) apply fact (*discuss goal 2*) apply fact (*proven 2 subgoals*) . thus "?thesis" (*goal: ‹card (local.span B) = CARD('a) ^ card B›*) by (simp add: card_PiE (*‹finite (?S::?'a set) ⟹ card (Pi⇩E ?S (?T::?'a ⇒ ?'b set)) = (∏i::?'a∈?S. card (?T i))›*) dim_span_eq_card_independent (*‹local.independent (?B::'b set) ⟹ local.dim (local.span ?B) = card ?B›*)) qed lemma (in zero_neq_one) CARD_neq_1: "CARD('a) ≠ Suc 0" proof (standard) (*goal: ‹CARD('a) = Suc 0 ⟹ False›*) assume "CARD('a) = Suc 0" (*‹CARD('a) = Suc (0::nat)›*) have "{0, 1} ⊆ (UNIV :: 'a set)" by simp also (*calculation: ‹{0, 1} ⊆ UNIV›*) have "is_singleton (UNIV :: 'a set)" by (simp add: is_singleton_altdef (*‹is_singleton ?A = (card ?A = 1)›*) ‹CARD('a) = _›) then obtain x :: 'a where "UNIV = {x}" (*goal: ‹(⋀x. UNIV = {x} ⟹ thesis) ⟹ thesis›*) by (elim is_singletonE (*‹⟦is_singleton (?A::?'a set); ⋀x::?'a. ?A = {x} ⟹ ?P::bool⟧ ⟹ ?P›*)) finally (*calculation: ‹{0, 1} ⊆ {x}›*) have "0 = (1 :: 'a)" by blast thus False using zero_neq_one (*‹0 ≠ 1›*) by contradiction qed theorem CARD_finite_field_is_CHAR_power: "∃n>0. CARD('a :: finite_field) = CHAR('a) ^ n" proof (-) (*goal: ‹∃n>0::nat. CARD('a::finite_field) = CHAR('a::finite_field) ^ n›*) define s :: "'a ring_char mod_ring ⇒ 'a ⇒ 'a" where "s = (λx y. of_int (to_int_mod_ring x) * y)" interpret vector_space s apply unfold_locales (*goals: 1. ‹⋀(a::'a ring_char mod_ring) (x::'a) y::'a. (s::'a ring_char mod_ring ⇒ 'a ⇒ 'a) a (x + y) = s a x + s a y› 2. ‹⋀(a::'a ring_char mod_ring) (b::'a ring_char mod_ring) x::'a. (s::'a ring_char mod_ring ⇒ 'a ⇒ 'a) (a + b) x = s a x + s b x› 3. ‹⋀(a::'a ring_char mod_ring) (b::'a ring_char mod_ring) x::'a. (s::'a ring_char mod_ring ⇒ 'a ⇒ 'a) a (s b x) = s (a * b) x› 4. ‹⋀x::'a. (s::'a ring_char mod_ring ⇒ 'a ⇒ 'a) (1::'a ring_char mod_ring) x = x› discuss goal 1*) apply ((auto simp: s_def (*‹s = (λx. (*) (of_int (to_int_mod_ring x)))›*) algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 15 facts*) to_int_mod_ring_add (*‹to_int_mod_ring (?x + ?y) = (to_int_mod_ring ?x + to_int_mod_ring ?y) mod int CARD(?'a)›*) to_int_mod_ring_mult (*‹to_int_mod_ring (?x * ?y) = to_int_mod_ring ?x * to_int_mod_ring ?y mod int CARD(?'a)›*))[1]) (*discuss goal 2*) apply ((auto simp: s_def (*‹s = (λx. (*) (of_int (to_int_mod_ring x)))›*) algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 15 facts*) to_int_mod_ring_add (*‹to_int_mod_ring (?x + ?y) = (to_int_mod_ring ?x + to_int_mod_ring ?y) mod int CARD(?'a)›*) to_int_mod_ring_mult (*‹to_int_mod_ring (?x * ?y) = to_int_mod_ring ?x * to_int_mod_ring ?y mod int CARD(?'a)›*))[1]) (*discuss goal 3*) apply ((auto simp: s_def (*‹s = (λx. (*) (of_int (to_int_mod_ring x)))›*) algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 15 facts*) to_int_mod_ring_add (*‹to_int_mod_ring (?x + ?y) = (to_int_mod_ring ?x + to_int_mod_ring ?y) mod int CARD(?'a)›*) to_int_mod_ring_mult (*‹to_int_mod_ring (?x * ?y) = to_int_mod_ring ?x * to_int_mod_ring ?y mod int CARD(?'a)›*))[1]) (*discuss goal 4*) apply ((auto simp: s_def (*‹s = (λx. (*) (of_int (to_int_mod_ring x)))›*) algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 15 facts*) to_int_mod_ring_add (*‹to_int_mod_ring (?x + ?y) = (to_int_mod_ring ?x + to_int_mod_ring ?y) mod int CARD(?'a)›*) to_int_mod_ring_mult (*‹to_int_mod_ring (?x * ?y) = to_int_mod_ring ?x * to_int_mod_ring ?y mod int CARD(?'a)›*))[1]) (*proven 4 subgoals*) . obtain B where B: "independent B" "span B = UNIV" (*goal: ‹(⋀B. ⟦local.independent B; local.span B = UNIV⟧ ⟹ thesis) ⟹ thesis›*) apply (rule basis_exists[of UNIV] (*‹(⋀B::'a set. ⟦B ⊆ UNIV; local.independent B; UNIV ⊆ local.span B; card B = local.dim UNIV⟧ ⟹ ?thesis::bool) ⟹ ?thesis›*)) (*goal: ‹(⋀B::'a::finite_field set. ⟦local.independent B; local.span B = UNIV⟧ ⟹ thesis::bool) ⟹ thesis›*) by auto have [simp]: "finite B" by simp have "card (span B) = CHAR('a) ^ card B" using B (*‹local.independent (B::'a set)› ‹local.span B = UNIV›*) apply (subst card_span (*‹⟦local.independent ?B; finite ?B⟧ ⟹ card (local.span ?B) = CARD('a ring_char mod_ring) ^ card ?B›*)) (*goals: 1. ‹⟦local.independent B; local.span B = UNIV⟧ ⟹ local.independent B› 2. ‹⟦local.independent B; local.span B = UNIV⟧ ⟹ finite B› 3. ‹⟦local.independent B; local.span B = UNIV⟧ ⟹ CARD('a ring_char mod_ring) ^ card B = CHAR('a) ^ card B› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . hence "*": "CARD('a) = CHAR('a) ^ card B" using B (*‹local.independent (B::'a set)› ‹local.span B = UNIV›*) by simp from "*" (*‹CARD('a) = CHAR('a) ^ card B›*) have "card B ≠ 0" by (auto simp: B( (*‹local.span B = UNIV›*) 2) CARD_neq_1 (*‹CARD(?'a) ≠ Suc 0›*)) with "*" (*‹CARD('a) = CHAR('a) ^ card B›*) show "?thesis" (*goal: ‹∃n>0. CARD('a) = CHAR('a) ^ n›*) by blast qed subsection ‹The Freshman's Dream in rings of non-zero characteristic› lemma (in comm_semiring_1) freshmans_dream: fixes x y :: 'a and n :: nat assumes "prime CHAR('a)" assumes n_def: "n = CHAR('a)" shows "(x + y) ^ n = x ^ n + y ^ n" proof (-) (*goal: ‹((x::'a) + (y::'a)) ^ (n::nat) = x ^ n + y ^ n›*) interpret comm_semiring_prime_char where apply standard (*goal: ‹class.comm_semiring_prime_char 1 (*) (+) 0›*) by (auto intro!: exI[of _ "CHAR('a)"] (*‹?P CHAR('a) ⟹ ∃x. ?P x›*) assms (*‹prime CHAR('a)› ‹n = CHAR('a)›*)) have "n > 0" unfolding n_def (*goal: ‹0 < CHAR('a)›*) by simp have "(x + y) ^ n = (∑k≤n. of_nat (n choose k) * x ^ k * y ^ (n - k))" by (rule binomial_ring (*‹(?a + ?b) ^ ?n = (∑k≤?n. of_nat (?n choose k) * ?a ^ k * ?b ^ (?n - k))›*)) also (*calculation: ‹(x + y) ^ n = (∑k≤n. of_nat (n choose k) * x ^ k * y ^ (n - k))›*) have "… = (∑k∈{0,n}. of_nat (n choose k) * x ^ k * y ^ (n - k))" proof (intro sum.mono_neutral_right (*‹⟦finite ?T; ?S ⊆ ?T; ∀i∈?T - ?S. ?g i = 0⟧ ⟹ sum ?g ?T = sum ?g ?S›*) ballI (*‹(⋀x. x ∈ ?A ⟹ ?P x) ⟹ ∀x∈?A. ?P x›*)) (*goals: 1. ‹finite {..n}› 2. ‹{0, n} ⊆ {..n}› 3. ‹⋀i. i ∈ {..n} - {0, n} ⟹ of_nat (n choose i) * x ^ i * y ^ (n - i) = 0›*) fix k assume "k ∈ {..n} - {0, n}" (*‹(k::nat) ∈ {..n::nat} - {0::nat, n}›*) hence k: "k > 0" "k < n" apply - (*goals: 1. ‹k ∈ {..n} - {0, n} ⟹ 0 < k› 2. ‹k ∈ {..n} - {0, n} ⟹ k < n› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have "CHAR('a) dvd (n choose k)" unfolding n_def (*goal: ‹CHAR('a) dvd CHAR('a) choose k›*) apply (rule dvd_choose_prime (*‹⟦?k < ?n; ?k ≠ 0; ?n ≠ 0; prime ?n⟧ ⟹ ?n dvd ?n choose ?k›*)) (*goals: 1. ‹k < CHAR('a)› 2. ‹k ≠ 0› 3. ‹CHAR('a) ≠ 0› 4. ‹prime CHAR('a)› discuss goal 1*) apply ((use k in ‹auto simp: n_def›)[1]) (*discuss goal 2*) apply ((use k in ‹auto simp: n_def›)[1]) (*discuss goal 3*) apply ((use k in ‹auto simp: n_def›)[1]) (*discuss goal 4*) apply ((use k in ‹auto simp: n_def›)[1]) (*proven 4 subgoals*) . hence "of_nat (n choose k) = (0 :: 'a)" using of_nat_eq_0_iff_char_dvd (*‹(of_nat ?n = 0) = (CHAR('a) dvd ?n)›*) by blast thus "of_nat (n choose k) * x ^ k * y ^ (n - k) = 0" by simp qed (auto) (*solves the remaining goals: 1. ‹finite {..n}› 2. ‹{0, n} ⊆ {..n}›*) finally (*calculation: ‹(x + y) ^ n = (∑k∈{0, n}. of_nat (n choose k) * x ^ k * y ^ (n - k))›*) show "?thesis" (*goal: ‹(x + y) ^ n = x ^ n + y ^ n›*) using ‹n > 0› (*‹0 < n›*) by (simp add: add_ac (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)›*)) qed lemma (in comm_semiring_1) freshmans_dream': assumes [simp]: "prime CHAR('a)" and "m = CHAR('a) ^ n" shows "(x + y :: 'a) ^ m = x ^ m + y ^ m" unfolding assms(2) (*goal: ‹(x + y) ^ CHAR('a) ^ n = x ^ CHAR('a) ^ n + y ^ CHAR('a) ^ n›*) proof (induction n) (*goals: 1. ‹((x::'a) + (y::'a)) ^ CHAR('a) ^ (0::nat) = x ^ CHAR('a) ^ (0::nat) + y ^ CHAR('a) ^ (0::nat)› 2. ‹⋀n::nat. ((x::'a) + (y::'a)) ^ CHAR('a) ^ n = x ^ CHAR('a) ^ n + y ^ CHAR('a) ^ n ⟹ (x + y) ^ CHAR('a) ^ Suc n = x ^ CHAR('a) ^ Suc n + y ^ CHAR('a) ^ Suc n›*) case (Suc n) (*‹((x::'a::type) + (y::'a::type)) ^ CHAR('a::type) ^ (n::nat) = x ^ CHAR('a::type) ^ n + y ^ CHAR('a::type) ^ n›*) have "(x + y) ^ (CHAR('a) ^ n * CHAR('a)) = ((x + y) ^ (CHAR('a) ^ n)) ^ CHAR('a)" by (rule power_mult (*‹?a ^ (?m * ?n) = (?a ^ ?m) ^ ?n›*)) thus "?case" (*goal: ‹((x::'a) + (y::'a)) ^ CHAR('a) ^ Suc (n::nat) = x ^ CHAR('a) ^ Suc n + y ^ CHAR('a) ^ Suc n›*) by (simp add: Suc.IH (*‹((x::'a) + (y::'a)) ^ CHAR('a) ^ (n::nat) = x ^ CHAR('a) ^ n + y ^ CHAR('a) ^ n›*) freshmans_dream (*‹⟦prime CHAR('a); (?n::nat) = CHAR('a)⟧ ⟹ ((?x::'a) + (?y::'a)) ^ ?n = ?x ^ ?n + ?y ^ ?n›*) Groups.mult_ac (*‹(?a::?'a) * (?b::?'a) * (?c::?'a) = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)›*) flip: power_mult (*‹(?a::'a) ^ ((?m::nat) * (?n::nat)) = (?a ^ ?m) ^ ?n›*)) qed (auto) (*solved the remaining goal: ‹(x + y) ^ CHAR('a) ^ 0 = x ^ CHAR('a) ^ 0 + y ^ CHAR('a) ^ 0›*) lemma (in comm_semiring_1) freshmans_dream_sum: fixes f :: "'b ⇒ 'a" assumes "prime CHAR('a)" and "n = CHAR('a)" shows "sum f A ^ n = sum (λi. f i ^ n) A" using assms (*‹prime CHAR('a)› ‹n = CHAR('a)›*) apply (induct A rule: infinite_finite_induct (*‹⟦⋀A. infinite A ⟹ ?P A; ?P {}; ⋀x F. ⟦finite F; x ∉ F; ?P F⟧ ⟹ ?P (insert x F)⟧ ⟹ ?P ?A›*)) (*goals: 1. ‹⋀A. ⟦infinite A; prime CHAR('a); n = CHAR('a)⟧ ⟹ sum f A ^ n = (∑i∈A. f i ^ n)› 2. ‹⟦prime CHAR('a); n = CHAR('a)⟧ ⟹ sum f {} ^ n = (∑i∈{}. f i ^ n)› 3. ‹⋀x F. ⟦finite F; x ∉ F; ⟦prime CHAR('a); n = CHAR('a)⟧ ⟹ sum f F ^ n = (∑i∈F. f i ^ n); prime CHAR('a); n = CHAR('a)⟧ ⟹ sum f (insert x F) ^ n = (∑i∈insert x F. f i ^ n)› discuss goal 1*) apply ((auto simp add: power_0_left (*‹(0::'a) ^ (?n::nat) = (if ?n = (0::nat) then 1::'a else (0::'a))›*) freshmans_dream (*‹⟦prime CHAR('a); (?n::nat) = CHAR('a)⟧ ⟹ ((?x::'a) + (?y::'a)) ^ ?n = ?x ^ ?n + ?y ^ ?n›*))[1]) (*discuss goal 2*) apply ((auto simp add: power_0_left (*‹(0::'a) ^ (?n::nat) = (if ?n = (0::nat) then 1::'a else (0::'a))›*) freshmans_dream (*‹⟦prime CHAR('a); (?n::nat) = CHAR('a)⟧ ⟹ ((?x::'a) + (?y::'a)) ^ ?n = ?x ^ ?n + ?y ^ ?n›*))[1]) (*discuss goal 3*) apply ((auto simp add: power_0_left (*‹0 ^ ?n = (if ?n = 0 then 1 else 0)›*) freshmans_dream (*‹⟦prime CHAR('a); ?n = CHAR('a)⟧ ⟹ (?x + ?y) ^ ?n = ?x ^ ?n + ?y ^ ?n›*))[1]) (*proven 3 subgoals*) . lemma (in comm_semiring_1) freshmans_dream_sum': fixes f :: "'b ⇒ 'a" assumes "prime CHAR('a)" "m = CHAR('a) ^ n" shows "sum f A ^ m = sum (λi. f i ^ m) A" using assms (*‹prime CHAR('a)› ‹m = CHAR('a) ^ n›*) apply (induction A rule: infinite_finite_induct (*‹⟦⋀A. infinite A ⟹ ?P A; ?P {}; ⋀x F. ⟦finite F; x ∉ F; ?P F⟧ ⟹ ?P (insert x F)⟧ ⟹ ?P ?A›*)) (*goals: 1. ‹⋀A. ⟦infinite A; prime CHAR('a); m = CHAR('a) ^ n⟧ ⟹ sum f A ^ m = (∑i∈A. f i ^ m)› 2. ‹⟦prime CHAR('a); m = CHAR('a) ^ n⟧ ⟹ sum f {} ^ m = (∑i∈{}. f i ^ m)› 3. ‹⋀x F. ⟦finite F; x ∉ F; ⟦prime CHAR('a); m = CHAR('a) ^ n⟧ ⟹ sum f F ^ m = (∑i∈F. f i ^ m); prime CHAR('a); m = CHAR('a) ^ n⟧ ⟹ sum f (insert x F) ^ m = (∑i∈insert x F. f i ^ m)› discuss goal 1*) apply ((auto simp: freshmans_dream' (*‹⟦prime CHAR('a); (?m::nat) = CHAR('a) ^ (?n::nat)⟧ ⟹ ((?x::'a) + (?y::'a)) ^ ?m = ?x ^ ?m + ?y ^ ?m›*) power_0_left (*‹(0::'a) ^ (?n::nat) = (if ?n = (0::nat) then 1::'a else (0::'a))›*))[1]) (*discuss goal 2*) apply ((auto simp: freshmans_dream' (*‹⟦prime CHAR('a); ?m = CHAR('a) ^ ?n⟧ ⟹ (?x + ?y) ^ ?m = ?x ^ ?m + ?y ^ ?m›*) power_0_left (*‹0 ^ ?n = (if ?n = 0 then 1 else 0)›*))[1]) (*discuss goal 3*) apply ((auto simp: freshmans_dream' (*‹⟦prime CHAR('a); ?m = CHAR('a) ^ ?n⟧ ⟹ (?x + ?y) ^ ?m = ?x ^ ?m + ?y ^ ?m›*) power_0_left (*‹0 ^ ?n = (if ?n = 0 then 1 else 0)›*))[1]) (*proven 3 subgoals*) . subsection ‹The Frobenius endomorphism› definition (in semiring_1) frob :: "'a ⇒ 'a" where "frob x = x ^ CHAR('a)" definition (in semiring_1) inv_frob :: "'a ⇒ 'a" where "inv_frob x = (if x ∈ {0, 1} then x else if x ∈ range frob then inv_into UNIV frob x else x)" lemma (in semiring_1) inv_frob_0 [simp]: "inv_frob 0 = 0" and inv_frob_1 [simp]: "inv_frob 1 = 1" (*goals: 1. ‹inv_frob 0 = 0› 2. ‹inv_frob 1 = 1› discuss goal 1*) apply (simp add: inv_frob_def (*‹inv_frob (?x::'a::type) = (if ?x ∈ {0::'a::type, 1::'a::type} then ?x else if ?x ∈ range frob then inv frob ?x else ?x)›*)) (*discuss goal 2*) apply (simp add: inv_frob_def (*‹inv_frob ?x = (if ?x ∈ {0, 1} then ?x else if ?x ∈ range frob then inv frob ?x else ?x)›*)) (*proven 2 subgoals*) . lemma (in semiring_prime_char) frob_0 [simp]: "frob (0 :: 'a) = 0" by (simp add: frob_def (*‹frob ?x = ?x ^ CHAR('a)›*) power_0_left (*‹0 ^ ?n = (if ?n = 0 then 1 else 0)›*)) lemma (in semiring_1) frob_1 [simp]: "frob 1 = 1" by (simp add: frob_def (*‹frob (?x::'a) = ?x ^ CHAR('a)›*)) lemma (in comm_semiring_1) frob_mult: "frob (x * y) = frob x * frob (y :: 'a)" by (simp add: frob_def (*‹frob ?x = ?x ^ CHAR('a)›*) power_mult_distrib (*‹(?a * ?b) ^ ?n = ?a ^ ?n * ?b ^ ?n›*)) lemma (in comm_semiring_1) frob_add: "prime CHAR('a) ⟹ frob (x + y :: 'a) = frob x + frob (y :: 'a)" by (simp add: frob_def (*‹frob ?x = ?x ^ CHAR('a)›*) freshmans_dream (*‹⟦prime CHAR('a); ?n = CHAR('a)⟧ ⟹ (?x + ?y) ^ ?n = ?x ^ ?n + ?y ^ ?n›*)) lemma (in comm_ring_1) frob_uminus: "prime CHAR('a) ⟹ frob (-x :: 'a) = -frob x" proof (-) (*goal: ‹prime CHAR('a::type) ⟹ frob (- (x::'a::type)) = - frob x›*) assume "prime CHAR('a)" (*‹prime CHAR('a)›*) hence "frob (-x) + frob x = 0" apply (subst frob_add [symmetric] (*‹prime CHAR('a) ⟹ frob (?x::'a) + frob (?y::'a) = frob (?x + ?y)›*)) (*goals: 1. ‹prime CHAR('a) ⟹ prime CHAR('a)› 2. ‹prime CHAR('a) ⟹ frob (- x + x) = 0› discuss goal 1*) apply ((auto simp: frob_def (*‹frob ?x = ?x ^ CHAR('a)›*) power_0_left (*‹0 ^ ?n = (if ?n = 0 then 1 else 0)›*))[1]) (*discuss goal 2*) apply ((auto simp: frob_def (*‹frob ?x = ?x ^ CHAR('a)›*) power_0_left (*‹0 ^ ?n = (if ?n = 0 then 1 else 0)›*))[1]) (*proven 2 subgoals*) . thus "?thesis" (*goal: ‹frob (- (x::'a)) = - frob x›*) by (simp add: add_eq_0_iff (*‹(?a + ?b = 0) = (?b = - ?a)›*)) qed lemma (in comm_ring_prime_char) frob_diff: "prime CHAR('a) ⟹ frob (x - y :: 'a) = frob x - frob (y :: 'a)" using frob_add[of x "-y"] (*‹prime CHAR('a) ⟹ frob (x + - y) = frob x + frob (- y)›*) by (simp add: frob_uminus (*‹prime CHAR('a) ⟹ frob (- (?x::'a)) = - frob ?x›*)) interpretation frob_sr: semiring_hom "frob :: 'a :: {comm_semiring_prime_char} ⇒ 'a" apply standard (*goals: 1. ‹frob (0::'a) = (0::'a)› 2. ‹⋀(x::'a) y::'a. frob (x + y) = frob x + frob y› 3. ‹frob (1::'a) = (1::'a)› 4. ‹⋀(x::'a) y::'a. frob (x * y) = frob x * frob y› discuss goal 1*) apply ((auto simp: frob_add (*‹prime CHAR(?'a) ⟹ frob (?x + ?y) = frob ?x + frob ?y›*) frob_mult (*‹frob (?x * ?y) = frob ?x * frob ?y›*))[1]) (*discuss goal 2*) apply ((auto simp: frob_add (*‹prime CHAR(?'a) ⟹ frob (?x + ?y) = frob ?x + frob ?y›*) frob_mult (*‹frob (?x * ?y) = frob ?x * frob ?y›*))[1]) (*discuss goal 3*) apply ((auto simp: frob_add (*‹prime CHAR(?'a) ⟹ frob (?x + ?y) = frob ?x + frob ?y›*) frob_mult (*‹frob (?x * ?y) = frob ?x * frob ?y›*))[1]) (*discuss goal 4*) apply ((auto simp: frob_add (*‹prime CHAR(?'a) ⟹ frob (?x + ?y) = frob ?x + frob ?y›*) frob_mult (*‹frob (?x * ?y) = frob ?x * frob ?y›*))[1]) (*proven 4 subgoals*) . interpretation frob: ring_hom "frob :: 'a :: {comm_ring_prime_char} ⇒ 'a" by standard auto interpretation frob: field_hom "frob :: 'a :: {field_prime_char} ⇒ 'a" by standard auto lemma frob_mod_ring' [simp]: "(x :: 'a :: prime_card mod_ring) ^ CARD('a) = x" by (metis CARD_mod_ring (*‹CARD(?'a mod_ring) = CARD(?'a)›*) finite_field_power_card_eq_same (*‹?x ^ CARD(?'a) = ?x›*)) lemma frob_mod_ring [simp]: "frob (x :: 'a :: prime_card mod_ring) = x" by (simp add: frob_def (*‹frob ?x = ?x ^ CHAR(?'a)›*)) context semiring_1_no_zero_divisors begin lemma frob_eq_0D: "frob (x :: 'a) = 0 ⟹ x = 0" by (auto simp: frob_def (*‹frob ?x = ?x ^ CHAR('a)›*)) lemma frob_eq_0_iff [simp]: "frob (x :: 'a) = 0 ⟷ x = 0 ∧ CHAR('a) > 0" by (auto simp: frob_def (*‹frob ?x = ?x ^ CHAR('a)›*)) end context idom_prime_char begin lemma inj_frob: "inj (frob :: 'a ⇒ 'a)" proof (standard) (*goal: ‹⋀x y. ⟦x ∈ UNIV; y ∈ UNIV; frob x = frob y⟧ ⟹ x = y›*) fix x :: 'a and y :: 'a assume "frob x = frob y" (*‹frob (x::'a) = frob (y::'a)›*) hence "frob (x - y) = 0" by (simp add: frob_diff (*‹prime CHAR('a) ⟹ frob ((?x::'a) - (?y::'a)) = frob ?x - frob ?y›*) del: frob_eq_0_iff (*‹(frob (?x::'a) = (0::'a)) = (?x = (0::'a) ∧ (0::nat) < CHAR('a))›*)) thus "x = y" by simp qed lemma frob_eq_frob_iff [simp]: "frob (x :: 'a) = frob y ⟷ x = y" using inj_frob (*‹inj frob›*) by (auto simp: inj_def (*‹inj ?f = (∀x y. ?f x = ?f y ⟶ x = y)›*)) lemma frob_eq_1_iff [simp]: "frob (x :: 'a) = 1 ⟷ x = 1" using frob_eq_frob_iff (*‹(frob ?x = frob ?y) = (?x = ?y)›*) by fastforce lemma inv_frob_frob [simp]: "inv_frob (frob (x :: 'a)) = x" by (simp add: inj_frob (*‹inj frob›*) inv_frob_def (*‹inv_frob ?x = (if ?x ∈ {0, 1} then ?x else if ?x ∈ range frob then inv frob ?x else ?x)›*)) lemma frob_inv_frob [simp]: assumes "x ∈ range frob" shows "frob (inv_frob x) = (x :: 'a)" using assms (*‹x ∈ range frob›*) by (auto simp: inj_frob (*‹inj frob›*) inv_frob_def (*‹inv_frob (?x::'a::type) = (if ?x ∈ {0::'a::type, 1::'a::type} then ?x else if ?x ∈ range frob then inv frob ?x else ?x)›*)) lemma inv_frob_eqI: "frob y = x ⟹ inv_frob x = y" using inv_frob_frob (*‹inv_frob (frob ?x) = ?x›*) local.frob_def (*‹frob ?x = ?x ^ CHAR('a)›*) by force lemma inv_frob_eq_0_iff [simp]: "inv_frob (x :: 'a) = 0 ⟷ x = 0" using inj_frob (*‹inj frob›*) by (auto simp: inv_frob_def (*‹inv_frob ?x = (if ?x ∈ {0, 1} then ?x else if ?x ∈ range frob then inv frob ?x else ?x)›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) end class surj_frob = field_prime_char + assumes surj_frob [simp]: "surj (frob :: 'a ⇒ 'a)" begin lemma in_range_frob [simp, intro]: "(x :: 'a) ∈ range frob" using surj_frob (*‹surj frob›*) by blast lemma inv_frob_eq_iff [simp]: "inv_frob (x :: 'a) = y ⟷ frob y = x" using frob_inv_frob (*‹?x ∈ range frob ⟹ frob (inv_frob ?x) = ?x›*) inv_frob_frob (*‹inv_frob (frob (?x::'a)) = ?x›*) by blast end context alg_closed_field begin lemma alg_closed_surj_frob: assumes "CHAR('a) > 0" shows "surj (frob :: 'a ⇒ 'a)" proof (-) (*goal: ‹surj frob›*) show "surj (frob :: 'a ⇒ 'a)" proof (safe) (*goals: 1. ‹⋀x xa. xa ∈ UNIV ⟹ frob xa ∈ UNIV› 2. ‹⋀x. x ∈ UNIV ⟹ x ∈ range frob›*) fix x :: 'a obtain y where "y ^ CHAR('a) = x" (*goal: ‹(⋀y. y ^ CHAR('a) = x ⟹ thesis) ⟹ thesis›*) using nth_root_exists (*‹0 < ?n ⟹ ∃y. y ^ ?n = ?x›*) CHAR_pos (*‹0 < CHAR(?'a)›*) assms (*‹0 < CHAR('a)›*) by blast hence "frob y = x" using CHAR_pos (*‹0 < CHAR(?'a)›*) by (simp add: frob_def (*‹frob ?x = ?x ^ CHAR('a)›*)) thus "x ∈ range frob" by (metis rangeI (*‹(?f::?'b ⇒ ?'a) (?x::?'b) ∈ range ?f›*)) qed (auto) (*solved the remaining goal: ‹⋀x xa. xa ∈ UNIV ⟹ frob xa ∈ UNIV›*) qed end text ‹ The following type class describes a field with a surjective Frobenius endomorphism that is effectively computable. This includes all finite fields. › class inv_frob = surj_frob + fixes inv_frob_code :: "'a ⇒ 'a" assumes inv_frob_code: "inv_frob x = inv_frob_code x" lemmas [code] = inv_frob_code context finite_field begin subclass surj_frob proof show "surj (frob :: 'a ⇒ 'a)" using inj_frob finite_UNIV by (simp add: finite_UNIV_inj_surj) qed end lemma inv_frob_mod_ring [simp]: "inv_frob (x :: 'a :: prime_card mod_ring) = x" by (auto simp: frob_def (*‹frob ?x = ?x ^ CHAR(?'a)›*)) instantiation mod_ring :: (prime_card) inv_frob begin definition inv_frob_code_mod_ring :: "'a mod_ring ⇒ 'a mod_ring" where "inv_frob_code_mod_ring x = x" instance by standard (auto simp: inv_frob_code_mod_ring_def) end subsection ‹Inverting the Frobenius endomorphism on polynomials› text ‹ If ‹K› is a field of prime characteristic ‹p› with a surjective Frobenius endomorphism, every polynomial ‹P› with ‹P' = 0› has a ‹p›-th root. To see that, let $\phi(a) = a^p$ denote the Frobenius endomorphism of ‹K› and its extension to ‹K[X]›. If ‹P' = 0› for some ‹P ∈ K[X]›, then ‹P› must be of the form \[P = a_0 + a_p x^p + a_{2p} x^{2p} + \ldots + a_{kp} x^{kp}\ .\] If we now set \[Q := \phi^{-1}(a_0) + \phi^{-1}(a_p) x + \phi^{-1}(a_{2p}) x^2 + \ldots + \phi^{-1}(a_{kp}) x^k\] we get $\phi(Q) = P$, i.e.\ $Q$ is the $p$-th root of $P(x)$. › lift_definition inv_frob_poly :: "'a :: field poly ⇒ 'a poly" is "λp i. if CHAR('a) = 0 then p i else inv_frob (p (i * CHAR('a)) :: 'a)" proof goal_cases case (1 f) show ?case proof (cases "CHAR('a) > 0") case True from 1 obtain N where N: "f i = 0" if "i ≥ N" for i using cofinite_eq_sequentially eventually_sequentially by auto have "inv_frob (f (i * CHAR('a))) = 0" if "i ≥ N" for i proof - have "f (i * CHAR('a)) = 0" proof (rule N) show "N ≤ i * CHAR('a)" using that True by (metis One_nat_def Suc_leI le_trans mult.right_neutral mult_le_mono2) qed thus "inv_frob (f (i * CHAR('a))) = 0" by (auto simp: power_0_left) qed thus ?thesis using True unfolding cofinite_eq_sequentially eventually_sequentially by auto qed (use 1 in auto) qed lemma coeff_inv_frob_poly [simp]: fixes p :: "'a :: field poly" assumes "CHAR('a) > 0" shows "poly.coeff (inv_frob_poly p) i = inv_frob (poly.coeff p (i * CHAR('a)))" using assms (*‹(0::nat) < CHAR('a)›*) apply transfer (*goal: ‹poly.coeff (inv_frob_poly p) i = inv_frob (poly.coeff p (i * CHAR('a)))›*) by auto lemma inv_frob_poly_0 [simp]: "inv_frob_poly 0 = 0" apply transfer (*goal: ‹inv_frob_poly (0::'a::field poly) = (0::'a::field poly)›*) by (auto simp: fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) power_0_left (*‹0 ^ ?n = (if ?n = 0 then 1 else 0)›*)) lemma inv_frob_poly_1 [simp]: "inv_frob_poly 1 = 1" apply transfer (*goal: ‹inv_frob_poly (1::'a::field poly) = (1::'a::field poly)›*) by (auto simp: fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) power_0_left (*‹0 ^ ?n = (if ?n = 0 then 1 else 0)›*)) lemma degree_inv_frob_poly_le: fixes p :: "'a :: field poly" assumes "CHAR('a) > 0" shows "Polynomial.degree (inv_frob_poly p) ≤ Polynomial.degree p div CHAR('a)" proof (intro degree_le (*‹∀i>?n. poly.coeff ?p i = 0 ⟹ degree ?p ≤ ?n›*) allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*) impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goal: ‹⋀i. degree p div CHAR('a) < i ⟹ poly.coeff (inv_frob_poly p) i = 0›*) fix i assume "Polynomial.degree p div CHAR('a) < i" (*‹degree (p::'a poly) div CHAR('a) < (i::nat)›*) hence "i * CHAR('a) > Polynomial.degree p" using assms (*‹0 < CHAR('a)›*) div_less_iff_less_mult (*‹(0::nat) < (?q::nat) ⟹ ((?m::nat) div ?q < (?n::nat)) = (?m < ?n * ?q)›*) by blast thus "Polynomial.coeff (inv_frob_poly p) i = 0" by (simp add: coeff_eq_0 (*‹degree ?p < ?n ⟹ poly.coeff ?p ?n = 0›*) power_0_left (*‹0 ^ ?n = (if ?n = 0 then 1 else 0)›*) assms (*‹0 < CHAR('a)›*)) qed context assumes "SORT_CONSTRAINT('a :: comm_ring_1)" assumes prime_char: "prime CHAR('a)" begin lemma poly_power_prime_char_as_sum_of_monoms: fixes h :: "'a poly" shows "h ^ CHAR('a) = (∑i≤Polynomial.degree h. Polynomial.monom (Polynomial.coeff h i ^ CHAR('a)) (CHAR('a)*i))" proof (-) (*goal: ‹h ^ CHAR('a) = (∑i≤degree h. Polynomial.monom (poly.coeff h i ^ CHAR('a)) (CHAR('a) * i))›*) have "h ^ CHAR('a) = (∑i≤Polynomial.degree h. Polynomial.monom (Polynomial.coeff h i) i) ^ CHAR('a)" by (simp add: poly_as_sum_of_monoms (*‹(∑i::nat≤degree ?p. Polynomial.monom (poly.coeff (?p::?'a poly) i) i) = ?p›*)) also (*calculation: ‹h ^ CHAR('a) = (∑i≤degree h. Polynomial.monom (poly.coeff h i) i) ^ CHAR('a)›*) have "... = (∑i≤Polynomial.degree h. (Polynomial.monom (Polynomial.coeff h i) i) ^ CHAR('a))" by (simp add: freshmans_dream_sum (*‹⟦prime CHAR(?'a); ?n = CHAR(?'a)⟧ ⟹ sum ?f ?A ^ ?n = (∑i∈?A. ?f i ^ ?n)›*) prime_char (*‹prime CHAR('a)›*)) also (*calculation: ‹(h::'a poly) ^ CHAR('a) = (∑i::nat≤degree h. Polynomial.monom (poly.coeff h i) i ^ CHAR('a))›*) have "... = (∑i≤Polynomial.degree h. Polynomial.monom (Polynomial.coeff h i ^ CHAR('a)) (CHAR('a)*i))" proof (rule sum.cong (*‹⟦?A = ?B; ⋀x. x ∈ ?B ⟹ ?g x = ?h x⟧ ⟹ sum ?g ?A = sum ?h ?B›*), rule) (*goal: ‹⋀x::nat. x ∈ {..degree (h::'a poly)} ⟹ Polynomial.monom (poly.coeff h x) x ^ CHAR('a) = Polynomial.monom (poly.coeff h x ^ CHAR('a)) (CHAR('a) * x)›*) fix x assume x: "x ∈ {..Polynomial.degree h}" (*‹(x::nat) ∈ {..degree (h::'a poly)}›*) show "Polynomial.monom (Polynomial.coeff h x) x ^ CHAR('a) = Polynomial.monom (Polynomial.coeff h x ^ CHAR('a)) (CHAR('a) * x)" apply (unfold poly_eq_iff (*‹(?p = ?q) = (∀n. poly.coeff ?p n = poly.coeff ?q n)›*)) (*goal: ‹Polynomial.monom (poly.coeff h x) x ^ CHAR('a) = Polynomial.monom (poly.coeff h x ^ CHAR('a)) (CHAR('a) * x)›*) by (auto simp add: monom_power (*‹Polynomial.monom (?a::?'a::comm_semiring_1) (?b::nat) ^ (?n::nat) = Polynomial.monom (?a ^ ?n) (?b * ?n)›*)) qed finally (*calculation: ‹(h::'a::comm_ring_1 poly) ^ CHAR('a::comm_ring_1) = (∑i::nat≤degree h. Polynomial.monom (poly.coeff h i ^ CHAR('a::comm_ring_1)) (CHAR('a::comm_ring_1) * i))›*) show "?thesis" (*goal: ‹(h::'a::comm_ring_1 poly) ^ CHAR('a::comm_ring_1) = (∑i::nat≤degree h. Polynomial.monom (poly.coeff h i ^ CHAR('a::comm_ring_1)) (CHAR('a::comm_ring_1) * i))›*) . qed lemma coeff_of_prime_char_power [simp]: fixes y :: "'a poly" shows "poly.coeff (y ^ CHAR('a)) (i * CHAR('a)) = poly.coeff y i ^ CHAR('a)" using prime_char (*‹prime CHAR('a)›*) apply (subst poly_power_prime_char_as_sum_of_monoms (*‹(?h::'a::comm_ring_1 poly) ^ CHAR('a::comm_ring_1) = (∑i::nat≤degree ?h. Polynomial.monom (poly.coeff ?h i ^ CHAR('a::comm_ring_1)) (CHAR('a::comm_ring_1) * i))›*)) (*goal: ‹poly.coeff ((y::'a::comm_ring_1 poly) ^ CHAR('a::comm_ring_1)) ((i::nat) * CHAR('a::comm_ring_1)) = poly.coeff y i ^ CHAR('a::comm_ring_1)›*) apply (subst Polynomial.coeff_sum (*‹poly.coeff (sum (?p::?'b ⇒ ?'a poly) (?A::?'b set)) (?i::nat) = (∑x::?'b∈?A. poly.coeff (?p x) ?i)›*)) (*goal: ‹prime CHAR('a) ⟹ poly.coeff (∑i≤degree y. Polynomial.monom (poly.coeff y i ^ CHAR('a)) (CHAR('a) * i)) (i * CHAR('a)) = poly.coeff y i ^ CHAR('a)›*) by (auto intro: le_degree (*‹poly.coeff ?p ?n ≠ 0 ⟹ ?n ≤ degree ?p›*) simp: power_0_left (*‹0 ^ ?n = (if ?n = 0 then 1 else 0)›*)) lemma coeff_of_prime_char_power': fixes y :: "'a poly" shows "poly.coeff (y ^ CHAR('a)) i = (if CHAR('a) dvd i then poly.coeff y (i div CHAR('a)) ^ CHAR('a) else 0)" proof (-) (*goal: ‹poly.coeff (y ^ CHAR('a)) i = (if CHAR('a) dvd i then poly.coeff y (i div CHAR('a)) ^ CHAR('a) else 0)›*) have "poly.coeff (y ^ CHAR('a)) i = (∑j≤Polynomial.degree y. Polynomial.coeff (Polynomial.monom (Polynomial.coeff y j ^ CHAR('a)) (CHAR('a) * j)) i)" apply (subst poly_power_prime_char_as_sum_of_monoms (*‹?h ^ CHAR('a) = (∑i≤degree ?h. Polynomial.monom (poly.coeff ?h i ^ CHAR('a)) (CHAR('a) * i))›*)) (*goal: ‹poly.coeff (y ^ CHAR('a)) i = (∑j≤degree y. poly.coeff (Polynomial.monom (poly.coeff y j ^ CHAR('a)) (CHAR('a) * j)) i)›*) apply (subst Polynomial.coeff_sum (*‹poly.coeff (sum ?p ?A) ?i = (∑x∈?A. poly.coeff (?p x) ?i)›*)) (*goal: ‹poly.coeff (∑i≤degree y. Polynomial.monom (poly.coeff y i ^ CHAR('a)) (CHAR('a) * i)) i = (∑j≤degree y. poly.coeff (Polynomial.monom (poly.coeff y j ^ CHAR('a)) (CHAR('a) * j)) i)›*) by auto also (*calculation: ‹poly.coeff (y ^ CHAR('a)) i = (∑j≤degree y. poly.coeff (Polynomial.monom (poly.coeff y j ^ CHAR('a)) (CHAR('a) * j)) i)›*) have "… = (∑j∈(if CHAR('a) dvd i ∧ i div CHAR('a) ≤ Polynomial.degree y then {i div CHAR('a)} else {}). Polynomial.coeff (Polynomial.monom (Polynomial.coeff y j ^ CHAR('a)) (CHAR('a) * j)) i)" apply (intro sum.mono_neutral_right (*‹⟦finite ?T; ?S ⊆ ?T; ∀i∈?T - ?S. ?g i = 0⟧ ⟹ sum ?g ?T = sum ?g ?S›*)) (*goals: 1. ‹finite {..degree y}› 2. ‹(if CHAR('a) dvd i ∧ i div CHAR('a) ≤ degree y then {i div CHAR('a)} else {}) ⊆ {..degree y}› 3. ‹∀ia∈{..degree y} - (if CHAR('a) dvd i ∧ i div CHAR('a) ≤ degree y then {i div CHAR('a)} else {}). poly.coeff (Polynomial.monom (poly.coeff y ia ^ CHAR('a)) (CHAR('a) * ia)) i = 0› discuss goal 1*) apply ((use prime_char in auto)[1]) (*discuss goal 2*) apply ((use prime_char in auto)[1]) (*discuss goal 3*) apply ((use prime_char in auto)[1]) (*proven 3 subgoals*) . also (*calculation: ‹poly.coeff (y ^ CHAR('a)) i = (∑j∈(if CHAR('a) dvd i ∧ i div CHAR('a) ≤ degree y then {i div CHAR('a)} else {}). poly.coeff (Polynomial.monom (poly.coeff y j ^ CHAR('a)) (CHAR('a) * j)) i)›*) have "… = (if CHAR('a) dvd i then poly.coeff y (i div CHAR('a)) ^ CHAR('a) else 0)" proof (cases "CHAR('a) dvd i ∧ i div CHAR('a) > Polynomial.degree y") (*goals: 1. ‹CHAR('a) dvd (i::nat) ∧ degree (y::'a poly) < i div CHAR('a) ⟹ (∑j::nat∈(if CHAR('a) dvd i ∧ i div CHAR('a) ≤ degree y then {i div CHAR('a)} else {}). poly.coeff (Polynomial.monom (poly.coeff y j ^ CHAR('a)) (CHAR('a) * j)) i) = (if CHAR('a) dvd i then poly.coeff y (i div CHAR('a)) ^ CHAR('a) else (0::'a))› 2. ‹¬ (CHAR('a) dvd (i::nat) ∧ degree (y::'a poly) < i div CHAR('a)) ⟹ (∑j::nat∈(if CHAR('a) dvd i ∧ i div CHAR('a) ≤ degree y then {i div CHAR('a)} else {}). poly.coeff (Polynomial.monom (poly.coeff y j ^ CHAR('a)) (CHAR('a) * j)) i) = (if CHAR('a) dvd i then poly.coeff y (i div CHAR('a)) ^ CHAR('a) else (0::'a))›*) case True (*‹CHAR('a) dvd i ∧ degree y < i div CHAR('a)›*) hence "Polynomial.coeff y (i div CHAR('a)) ^ CHAR('a) = 0" using prime_char (*‹prime CHAR('a)›*) by (simp add: coeff_eq_0 (*‹degree ?p < ?n ⟹ poly.coeff ?p ?n = 0›*) zero_power (*‹0 < ?n ⟹ 0 ^ ?n = 0›*) power_0_left (*‹0 ^ ?n = (if ?n = 0 then 1 else 0)›*)) thus "?thesis" (*goal: ‹(∑j∈(if CHAR('a) dvd i ∧ i div CHAR('a) ≤ degree y then {i div CHAR('a)} else {}). poly.coeff (Polynomial.monom (poly.coeff y j ^ CHAR('a)) (CHAR('a) * j)) i) = (if CHAR('a) dvd i then poly.coeff y (i div CHAR('a)) ^ CHAR('a) else 0)›*) by auto qed (auto) (*solved the remaining goal: ‹¬ (CHAR('a) dvd i ∧ degree y < i div CHAR('a)) ⟹ (∑j∈(if CHAR('a) dvd i ∧ i div CHAR('a) ≤ degree y then {i div CHAR('a)} else {}). poly.coeff (Polynomial.monom (poly.coeff y j ^ CHAR('a)) (CHAR('a) * j)) i) = (if CHAR('a) dvd i then poly.coeff y (i div CHAR('a)) ^ CHAR('a) else 0)›*) finally (*calculation: ‹poly.coeff (y ^ CHAR('a)) i = (if CHAR('a) dvd i then poly.coeff y (i div CHAR('a)) ^ CHAR('a) else 0)›*) show "?thesis" (*goal: ‹poly.coeff (y ^ CHAR('a)) i = (if CHAR('a) dvd i then poly.coeff y (i div CHAR('a)) ^ CHAR('a) else 0)›*) . qed end context assumes "SORT_CONSTRAINT('a :: field)" assumes pos_char: "CHAR('a) > 0" begin interpretation field_prime_char "(/)" inverse "(*)" "1 :: 'a" "(+)" 0 "(-)" uminus rewrites "semiring_1.frob 1 (*) (+) (0 :: 'a) = frob" and "semiring_1.inv_frob 1 (*) (+) (0 :: 'a) = inv_frob" and "semiring_1.semiring_char 1 (+) 0 TYPE('a) = CHAR('a)" proof (unfold_locales) (*goals: 1. ‹∃n>0. semiring_1.of_nat 1 (+) 0 n = 0› 2. ‹semiring_1.frob 1 (*) (+) 0 = frob› 3. ‹semiring_1.inv_frob 1 (*) (+) 0 = inv_frob› 4. ‹semiring_1.semiring_char 1 (+) 0 TYPE('a) = CHAR('a)›*) have "*": "class.semiring_1 (1 :: 'a) (*) (+) 0" by standard have [simp]: "semiring_1.of_nat (1 :: 'a) (+) 0 = of_nat" by (auto simp: of_nat_def (*‹of_nat (?n::nat) = ((+) (1::?'a::semiring_1) ^^ ?n) (0::?'a::semiring_1)›*) semiring_1.of_nat_def[OF *] (*‹semiring_1.of_nat (1::'a::field) (+) (0::'a::field) (?n::nat) = ((+) (1::'a::field) ^^ ?n) (0::'a::field)›*)) thus "∃n>0. semiring_1.of_nat (1 :: 'a) (+) 0 n = 0" apply (intro exI[of _ "CHAR('a)"] (*‹?P CHAR('a) ⟹ ∃x. ?P x›*)) (*goal: ‹∃n>0. semiring_1.of_nat 1 (+) 0 n = 0›*) by (use pos_char in auto) show "semiring_1.semiring_char 1 (+) 0 TYPE('a) = CHAR('a)" by (simp add: fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) semiring_char_def (*‹semiring_char ?uu = Gcd {n. of_nat n = 0}›*) semiring_1.semiring_char_def[OF *] (*‹semiring_1.semiring_char 1 (+) 0 ?uu = Gcd {n. semiring_1.of_nat 1 (+) 0 n = 0}›*)) show [simp]: "semiring_1.frob (1 :: 'a) (*) (+) 0 = frob" by (simp add: frob_def (*‹frob (?x::?'a) = ?x ^ CHAR(?'a)›*) semiring_1.frob_def[OF *] (*‹semiring_1.frob (1::'a) (*) (+) (0::'a) (?x::'a) = power.power (1::'a) (*) ?x (semiring_1.semiring_char (1::'a) (+) (0::'a) TYPE('a))›*) fun_eq_iff (*‹((?f::?'a ⇒ ?'b) = (?g::?'a ⇒ ?'b)) = (∀x::?'a. ?f x = ?g x)›*) power.power_def (*‹power.power (?one::?'a) (?times::?'a ⇒ ?'a ⇒ ?'a) ≡ λ(uu::?'a) uua::nat. rec_nat (λa::?'a. ?one) (λ(n::nat) (na::?'a ⇒ ?'a) a::?'a. ?times a (na a)) uua uu›*) power_def (*‹(^) ≡ λ(uu::?'a) uua::nat. rec_nat (λa::?'a. 1::?'a) (λ(n::nat) (na::?'a ⇒ ?'a) a::?'a. a * na a) uua uu›*) semiring_char_def (*‹semiring_char (?uu::?'a itself) = Gcd {n::nat. of_nat n = (0::?'a)}›*) semiring_1.semiring_char_def[OF *] (*‹semiring_1.semiring_char (1::'a) (+) (0::'a) (?uu::'a itself) = Gcd {n::nat. semiring_1.of_nat (1::'a) (+) (0::'a) n = (0::'a)}›*)) show "semiring_1.inv_frob (1 :: 'a) (*) (+) 0 = inv_frob" by (simp add: inv_frob_def (*‹inv_frob ?x = (if ?x ∈ {0, 1} then ?x else if ?x ∈ range frob then inv frob ?x else ?x)›*) semiring_1.inv_frob_def[OF *] (*‹semiring_1.inv_frob 1 (*) (+) 0 ?x = (if ?x ∈ {0, 1} then ?x else if ?x ∈ range (semiring_1.frob 1 (*) (+) 0) then inv (semiring_1.frob 1 (*) (+) 0) ?x else ?x)›*) fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*)) qed lemma inv_frob_poly_power': "inv_frob_poly (p ^ CHAR('a) :: 'a poly) = p" using prime_CHAR_semidom[OF pos_char] (*‹prime CHAR('a)›*) pos_char (*‹0 < CHAR('a)›*) by (auto simp: poly_eq_iff (*‹(?p = ?q) = (∀n. poly.coeff ?p n = poly.coeff ?q n)›*) simp flip: frob_def (*‹frob ?x = ?x ^ CHAR(?'a)›*)) lemma inv_frob_poly_power: fixes p :: "'a poly" assumes "is_nth_power CHAR('a) p" and "n = CHAR('a)" shows "inv_frob_poly p ^ CHAR('a) = p" proof (-) (*goal: ‹inv_frob_poly p ^ CHAR('a) = p›*) from assms(1) (*‹is_nth_power CHAR('a) p›*) obtain q where q: "p = q ^ CHAR('a)" (*goal: ‹(⋀q. p = q ^ CHAR('a) ⟹ thesis) ⟹ thesis›*) by (elim is_nth_powerE (*‹⟦is_nth_power ?n ?x; ⋀y. ?x = y ^ ?n ⟹ ?P⟧ ⟹ ?P›*)) thus "?thesis" (*goal: ‹inv_frob_poly p ^ CHAR('a) = p›*) using assms (*‹is_nth_power CHAR('a) (p::'a poly)› ‹n = CHAR('a)›*) by (simp add: q (*‹p = q ^ CHAR('a)›*) inv_frob_poly_power' (*‹inv_frob_poly (?p ^ CHAR('a)) = ?p›*)) qed theorem pderiv_eq_0_imp_nth_power: assumes "pderiv (p :: 'a poly) = 0" assumes [simp]: "surj (frob :: 'a ⇒ 'a)" shows "is_nth_power CHAR('a) p" proof (-) (*goal: ‹is_nth_power CHAR('a) p›*) have "*": "poly.coeff p n = 0" if n: "¬CHAR('a) dvd n" for n proof (cases "n = 0") (*goals: 1. ‹(n::nat) = (0::nat) ⟹ poly.coeff (p::'a::field poly) n = (0::'a::field)› 2. ‹(n::nat) ≠ (0::nat) ⟹ poly.coeff (p::'a::field poly) n = (0::'a::field)›*) case False (*‹(n::nat) ≠ (0::nat)›*) have "poly.coeff (pderiv p) (n - 1) = of_nat n * poly.coeff p n" using False (*‹n ≠ 0›*) by (auto simp: coeff_pderiv (*‹poly.coeff (pderiv ?p) ?n = of_nat (Suc ?n) * poly.coeff ?p (Suc ?n)›*)) with assms (*‹pderiv p = 0› ‹surj frob›*) n (*‹¬ CHAR('a::field) dvd (n::nat)›*) show "poly.coeff p n = 0" by (auto simp: of_nat_eq_0_iff_char_dvd (*‹(of_nat ?n = 0) = (CHAR(?'a) dvd ?n)›*)) qed (use that in auto) (*solved the remaining goal: ‹n = 0 ⟹ poly.coeff p n = 0›*) have "**": "inv_frob_poly p ^ CHAR('a) = p" proof (rule poly_eqI (*‹(⋀n. poly.coeff ?p n = poly.coeff ?q n) ⟹ ?p = ?q›*)) (*goal: ‹⋀n. poly.coeff (inv_frob_poly p ^ CHAR('a)) n = poly.coeff p n›*) fix n :: nat show "poly.coeff (inv_frob_poly p ^ CHAR('a)) n = poly.coeff p n" using "*" (*‹¬ CHAR('a) dvd ?n ⟹ poly.coeff p ?n = 0›*) CHAR_dvd_CARD[where ?'a = 'a] (*‹CHAR('a) dvd CARD('a)›*) apply (subst coeff_of_prime_char_power' (*‹prime CHAR(?'a) ⟹ poly.coeff (?y ^ CHAR(?'a)) ?i = (if CHAR(?'a) dvd ?i then poly.coeff ?y (?i div CHAR(?'a)) ^ CHAR(?'a) else 0)›*)) (*goals: 1. ‹⟦⋀n. ¬ CHAR('a) dvd n ⟹ poly.coeff p n = 0; CHAR('a) dvd CARD('a)⟧ ⟹ prime CHAR('a)› 2. ‹⟦⋀n. ¬ CHAR('a) dvd n ⟹ poly.coeff p n = 0; CHAR('a) dvd CARD('a)⟧ ⟹ (if CHAR('a) dvd n then poly.coeff (inv_frob_poly p) (n div CHAR('a)) ^ CHAR('a) else 0) = poly.coeff p n› discuss goal 1*) apply ((auto simp: poly_eq_iff (*‹(?p = ?q) = (∀n. poly.coeff ?p n = poly.coeff ?q n)›*) frob_def [symmetric] (*‹?x ^ CHAR(?'a) = frob ?x›*) coeff_of_prime_char_power'[where ?'a = 'a] (*‹prime CHAR('a) ⟹ poly.coeff (?y ^ CHAR('a)) ?i = (if CHAR('a) dvd ?i then poly.coeff ?y (?i div CHAR('a)) ^ CHAR('a) else 0)›*) simp flip: power_mult (*‹?a ^ (?m * ?n) = (?a ^ ?m) ^ ?n›*))[1]) (*discuss goal 2*) apply ((auto simp: poly_eq_iff (*‹((?p::?'a::zero poly) = (?q::?'a::zero poly)) = (∀n::nat. poly.coeff ?p n = poly.coeff ?q n)›*) frob_def [symmetric] (*‹(?x::?'a::semiring_1) ^ CHAR(?'a::semiring_1) = frob ?x›*) coeff_of_prime_char_power'[where ?'a = 'a] (*‹prime CHAR('a::field) ⟹ poly.coeff ((?y::'a::field poly) ^ CHAR('a::field)) (?i::nat) = (if CHAR('a::field) dvd ?i then poly.coeff ?y (?i div CHAR('a::field)) ^ CHAR('a::field) else (0::'a::field))›*) simp flip: power_mult (*‹(?a::?'a::monoid_mult) ^ ((?m::nat) * (?n::nat)) = (?a ^ ?m) ^ ?n›*))[1]) (*proven 2 subgoals*) . qed show "?thesis" (*goal: ‹is_nth_power CHAR('a) p›*) apply (subst **[symmetric] (*‹p = inv_frob_poly p ^ CHAR('a)›*)) (*goal: ‹is_nth_power CHAR('a) p›*) by auto qed end subsection ‹Code generation› text ‹ We now also make this notion of ``taking the ‹p›-th root of a polynomial'' executable. For this, we need an auxiliary function that takes a list $[x_0, \ldots, x_m]$ and returns the list of every ‹n›-th element, i.e.\ it throws away all elements except those $x_i$ where $i$ is a multiple of $n$. › (* TODO: Move this function to a library? *) fun take_every :: "nat ⇒ 'a list ⇒ 'a list" where "take_every _ [] = []" | "take_every n (x # xs) = x # take_every n (drop (n - 1) xs)" lemma take_every_0 [simp]: "take_every 0 xs = xs" apply (induction xs) (*goals: 1. ‹take_every 0 [] = []› 2. ‹⋀a xs. take_every 0 xs = xs ⟹ take_every 0 (a # xs) = a # xs› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma take_every_1 [simp]: "take_every (Suc 0) xs = xs" apply (induction xs) (*goals: 1. ‹take_every (Suc (0::nat)) [] = []› 2. ‹⋀(a::'a) xs::'a list. take_every (Suc (0::nat)) xs = xs ⟹ take_every (Suc (0::nat)) (a # xs) = a # xs› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma int_length_take_every: "n > 0 ⟹ int (length (take_every n xs)) = ceiling (length xs / n)" proof (induction n xs rule: take_every.induct (*‹⟦⋀uu_. ?P uu_ []; ⋀n x xs. ?P n (drop (n - 1) xs) ⟹ ?P n (x # xs)⟧ ⟹ ?P ?a0.0 ?a1.0›*)) (*goals: 1. ‹⋀uu_::nat. (0::nat) < uu_ ⟹ int (length (take_every uu_ [])) = ⌈real (length []) / real uu_⌉› 2. ‹⋀(n::nat) (x::'a::type) xs::'a::type list. ⟦(0::nat) < n ⟹ int (length (take_every n (drop (n - (1::nat)) xs))) = ⌈real (length (drop (n - (1::nat)) xs)) / real n⌉; (0::nat) < n⟧ ⟹ int (length (take_every n (x # xs))) = ⌈real (length (x # xs)) / real n⌉›*) case (2 n x xs) (*‹0 < n ⟹ int (length (take_every n (drop (n - 1) xs))) = ⌈real (length (drop (n - 1) xs)) / real n⌉› ‹0 < n›*) show "?case" (*goal: ‹int (length (take_every n (x # xs))) = ⌈real (length (x # xs)) / real n⌉›*) proof (cases "Suc (length xs) ≥ n") (*goals: 1. ‹n ≤ Suc (length xs) ⟹ int (length (take_every n (x # xs))) = ⌈real (length (x # xs)) / real n⌉› 2. ‹¬ n ≤ Suc (length xs) ⟹ int (length (take_every n (x # xs))) = ⌈real (length (x # xs)) / real n⌉›*) case True (*‹(n::nat) ≤ Suc (length (xs::'a list))›*) thus "?thesis" (*goal: ‹int (length (take_every n (x # xs))) = ⌈real (length (x # xs)) / real n⌉›*) using "2" (*‹0 < n ⟹ int (length (take_every n (drop (n - 1) xs))) = ⌈real (length (drop (n - 1) xs)) / real n⌉› ‹0 < n›*) by (auto simp: dvd_imp_le (*‹⟦?k dvd ?n; 0 < ?n⟧ ⟹ ?k ≤ ?n›*) of_nat_diff (*‹?n ≤ ?m ⟹ of_nat (?m - ?n) = of_nat ?m - of_nat ?n›*) diff_divide_distrib (*‹(?a - ?b) / ?c = ?a / ?c - ?b / ?c›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) next (*goal: ‹¬ n ≤ Suc (length xs) ⟹ int (length (take_every n (x # xs))) = ⌈real (length (x # xs)) / real n⌉›*) case False (*‹¬ (n::nat) ≤ Suc (length (xs::'a list))›*) hence "⌈(1 + real (length xs)) / real n⌉ = 1" apply (intro ceiling_unique (*‹⟦of_int (?z::int) - (1::?'a) < (?x::?'a); ?x ≤ of_int ?z⟧ ⟹ ⌈?x⌉ = ?z›*)) (*goals: 1. ‹¬ n ≤ Suc (length xs) ⟹ real_of_int 1 - 1 < (1 + real (length xs)) / real n› 2. ‹¬ n ≤ Suc (length xs) ⟹ (1 + real (length xs)) / real n ≤ real_of_int 1› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . thus "?thesis" (*goal: ‹int (length (take_every n (x # xs))) = ⌈real (length (x # xs)) / real n⌉›*) using False (*‹¬ n ≤ Suc (length xs)›*) by auto qed qed (auto) (*solved the remaining goal: ‹⋀uu_. 0 < uu_ ⟹ int (length (take_every uu_ [])) = ⌈real (length []) / real uu_⌉›*) lemma length_take_every: "n > 0 ⟹ length (take_every n xs) = nat (ceiling (length xs / n))" using int_length_take_every[of n xs] (*‹0 < n ⟹ int (length (take_every n xs)) = ⌈real (length xs) / real n⌉›*) by simp lemma take_every_nth [simp]: "n > 0 ⟹ i < length (take_every n xs) ⟹ take_every n xs ! i = xs ! (n * i)" proof (induction n xs arbitrary: i rule: take_every.induct) (*goals: 1. ‹⋀uu_ i. ⟦0 < uu_; i < length (take_every uu_ [])⟧ ⟹ take_every uu_ [] ! i = [] ! (uu_ * i)› 2. ‹⋀n x xs i. ⟦⋀i. ⟦0 < n; i < length (take_every n (drop (n - 1) xs))⟧ ⟹ take_every n (drop (n - 1) xs) ! i = drop (n - 1) xs ! (n * i); 0 < n; i < length (take_every n (x # xs))⟧ ⟹ take_every n (x # xs) ! i = (x # xs) ! (n * i)›*) case (2 n x xs i) (*‹⟦0 < n; ?i < length (take_every n (drop (n - 1) xs))⟧ ⟹ take_every n (drop (n - 1) xs) ! ?i = drop (n - 1) xs ! (n * ?i)› ‹0 < n› ‹i < length (take_every n (x # xs))›*) show "?case" (*goal: ‹take_every n (x # xs) ! i = (x # xs) ! (n * i)›*) proof (cases i) (*goals: 1. ‹(i::nat) = (0::nat) ⟹ take_every (n::nat) ((x::'a) # (xs::'a list)) ! i = (x # xs) ! (n * i)› 2. ‹⋀nat::nat. (i::nat) = Suc nat ⟹ take_every (n::nat) ((x::'a) # (xs::'a list)) ! i = (x # xs) ! (n * i)›*) case (Suc j) (*‹i = Suc j›*) have "n - Suc 0 ≤ length xs" using Suc (*‹(i::nat) = Suc (j::nat)›*) "2.prems" (*‹0 < n› ‹i < length (take_every n (x # xs))›*) nat_le_linear (*‹?m ≤ ?n ∨ ?n ≤ ?m›*) by force hence "drop (n - Suc 0) xs ! (n * j) = xs ! (n - 1 + n * j)" using Suc (*‹i = Suc j›*) apply (subst nth_drop (*‹?n ≤ length ?xs ⟹ drop ?n ?xs ! ?i = ?xs ! (?n + ?i)›*)) (*goals: 1. ‹⟦n - Suc 0 ≤ length xs; i = Suc j⟧ ⟹ n - Suc 0 ≤ length xs› 2. ‹⟦n - Suc 0 ≤ length xs; i = Suc j⟧ ⟹ xs ! (n - Suc 0 + n * j) = xs ! (n - 1 + n * j)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . also (*calculation: ‹drop (n - Suc 0) xs ! (n * j) = xs ! (n - 1 + n * j)›*) have "n - 1 + n * j = n + n * j - 1" using ‹n > 0› (*‹0 < n›*) by linarith finally (*calculation: ‹drop (n - Suc 0) xs ! (n * j) = xs ! (n + n * j - 1)›*) show "?thesis" (*goal: ‹take_every n (x # xs) ! i = (x # xs) ! (n * i)›*) using "2.IH"[of j] (*‹⟦0 < n; j < length (take_every n (drop (n - 1) xs))⟧ ⟹ take_every n (drop (n - 1) xs) ! j = drop (n - 1) xs ! (n * j)›*) "2.prems" (*‹(0::nat) < (n::nat)› ‹i < length (take_every n (x # xs))›*) Suc (*‹(i::nat) = Suc (j::nat)›*) by simp qed (auto) (*solved the remaining goal: ‹i = 0 ⟹ take_every n (x # xs) ! i = (x # xs) ! (n * i)›*) qed (auto) (*solved the remaining goal: ‹⋀(uu_::nat) i::nat. ⟦(0::nat) < uu_; i < length (take_every uu_ [])⟧ ⟹ take_every uu_ [] ! i = [] ! (uu_ * i)›*) lemma coeffs_eq_strip_whileI: assumes "⋀i. i < length xs ⟹ Polynomial.coeff p i = xs ! i" assumes "p ≠ 0 ⟹ length xs > Polynomial.degree p" shows "Polynomial.coeffs p = strip_while ((=) 0) xs" proof (rule coeffs_eqI (*‹⟦⋀n. poly.coeff ?p n = nth_default 0 ?xs n; no_trailing ((=) 0) ?xs⟧ ⟹ coeffs ?p = ?xs›*)) (*goals: 1. ‹⋀n. poly.coeff p n = nth_default 0 (strip_while ((=) 0) xs) n› 2. ‹no_trailing ((=) 0) (strip_while ((=) 0) xs)›*) fix n :: nat show "Polynomial.coeff p n = nth_default 0 (strip_while ((=) 0) xs) n" using assms (*‹?i < length xs ⟹ poly.coeff p ?i = xs ! ?i› ‹p ≠ 0 ⟹ degree p < length xs›*) by (metis coeff_0 (*‹poly.coeff 0 ?n = 0›*) coeff_Poly_eq (*‹poly.coeff (Poly ?xs) = nth_default 0 ?xs›*) coeffs_Poly (*‹coeffs (Poly ?as) = strip_while ((=) 0) ?as›*) le_degree (*‹poly.coeff ?p ?n ≠ 0 ⟹ ?n ≤ degree ?p›*) nth_default_coeffs_eq (*‹nth_default 0 (coeffs ?p) = poly.coeff ?p›*) nth_default_eq_dflt_iff (*‹(nth_default ?dflt ?xs ?k = ?dflt) = (?k < length ?xs ⟶ ?xs ! ?k = ?dflt)›*) nth_default_nth (*‹?n < length ?xs ⟹ nth_default ?dflt ?xs ?n = ?xs ! ?n›*) order_le_less_trans (*‹⟦?x ≤ ?y; ?y < ?z⟧ ⟹ ?x < ?z›*)) qed (auto) (*solved the remaining goal: ‹no_trailing ((=) 0) (strip_while ((=) 0) xs)›*) text ‹This implements the code equation for ‹inv_frob_poly›.› lemma inv_frob_poly_code [code]: "Polynomial.coeffs (inv_frob_poly (p :: 'a :: field_prime_char poly)) = (if CHAR('a) = 0 then Polynomial.coeffs p else map inv_frob (strip_while ((=) 0) (take_every CHAR('a) (Polynomial.coeffs p))))" (is "_ = If _ _ ?rhs") proof (cases "CHAR('a) = 0 ∨ p = 0") (*goals: 1. ‹CHAR('a) = 0 ∨ p = 0 ⟹ coeffs (inv_frob_poly p) = (if CHAR('a) = 0 then coeffs p else map inv_frob (strip_while ((=) 0) (take_every CHAR('a) (coeffs p))))› 2. ‹¬ (CHAR('a) = 0 ∨ p = 0) ⟹ coeffs (inv_frob_poly p) = (if CHAR('a) = 0 then coeffs p else map inv_frob (strip_while ((=) 0) (take_every CHAR('a) (coeffs p))))›*) case False (*‹¬ (CHAR('a) = 0 ∨ p = 0)›*) from False (*‹¬ (CHAR('a) = 0 ∨ p = 0)›*) have "p ≠ 0" by auto have "Polynomial.coeffs (inv_frob_poly p) = strip_while ((=) 0) (map inv_frob (take_every CHAR('a) (Polynomial.coeffs p)))" proof (rule coeffs_eq_strip_whileI (*‹⟦⋀i. i < length ?xs ⟹ poly.coeff ?p i = ?xs ! i; ?p ≠ 0 ⟹ degree ?p < length ?xs⟧ ⟹ coeffs ?p = strip_while ((=) 0) ?xs›*)) (*goals: 1. ‹⋀i::nat. i < length (map inv_frob (take_every CHAR('a::field_prime_char) (coeffs (p::'a::field_prime_char poly)))) ⟹ poly.coeff (inv_frob_poly p) i = map inv_frob (take_every CHAR('a::field_prime_char) (coeffs p)) ! i› 2. ‹inv_frob_poly (p::'a::field_prime_char poly) ≠ (0::'a::field_prime_char poly) ⟹ degree (inv_frob_poly p) < length (map inv_frob (take_every CHAR('a::field_prime_char) (coeffs p)))›*) fix i assume i: "i < length (map inv_frob (take_every CHAR('a) (Polynomial.coeffs p)))" (*‹(i::nat) < length (map inv_frob (take_every CHAR('a) (coeffs (p::'a poly))))›*) show "Polynomial.coeff (inv_frob_poly p) i = map inv_frob (take_every CHAR('a) (Polynomial.coeffs p)) ! i" proof (-) (*goal: ‹poly.coeff (inv_frob_poly p) i = map inv_frob (take_every CHAR('a) (coeffs p)) ! i›*) have "i < length (take_every CHAR('a) (Polynomial.coeffs p))" using i (*‹i < length (map inv_frob (take_every CHAR('a) (coeffs p)))›*) by simp also (*calculation: ‹i < length (take_every CHAR('a) (coeffs p))›*) have "length (take_every CHAR('a) (Polynomial.coeffs p)) = nat ⌈(Polynomial.degree p + 1) / real CHAR('a)⌉" using False (*‹¬ (CHAR('a) = 0 ∨ p = 0)›*) CHAR_pos[where ?'a = 'a] (*‹0 < CHAR('a)›*) by (simp add: length_take_every (*‹0 < ?n ⟹ length (take_every ?n ?xs) = nat ⌈real (length ?xs) / real ?n⌉›*) length_coeffs (*‹?p ≠ 0 ⟹ length (coeffs ?p) = degree ?p + 1›*)) finally (*calculation: ‹i < nat ⌈real (degree p + 1) / real CHAR('a)⌉›*) have "i < real (Polynomial.degree p + 1) / real CHAR('a)" by linarith hence "real i * real CHAR('a) < real (Polynomial.degree p + 1)" using False (*‹¬ (CHAR('a::field_prime_char) = (0::nat) ∨ (p::'a::field_prime_char poly) = (0::'a::field_prime_char poly))›*) CHAR_pos[where ?'a = 'a] (*‹0 < CHAR('a)›*) by (simp add: field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 69 facts*)) hence "i * CHAR('a) ≤ Polynomial.degree p" unfolding of_nat_mult[symmetric] (*goal: ‹i * CHAR('a) ≤ degree p›*) by linarith hence "Polynomial.coeffs p ! (i * CHAR('a)) = Polynomial.coeff p (i * CHAR('a))" using False (*‹¬ (CHAR('a::field_prime_char) = (0::nat) ∨ (p::'a::field_prime_char poly) = (0::'a::field_prime_char poly))›*) apply (intro coeffs_nth (*‹⟦?p ≠ 0; ?n ≤ degree ?p⟧ ⟹ coeffs ?p ! ?n = poly.coeff ?p ?n›*)) (*goals: 1. ‹⟦i * CHAR('a) ≤ degree p; ¬ (CHAR('a) = 0 ∨ p = 0)⟧ ⟹ p ≠ 0› 2. ‹⟦i * CHAR('a) ≤ degree p; ¬ (CHAR('a) = 0 ∨ p = 0)⟧ ⟹ i * CHAR('a) ≤ degree p› discuss goal 1*) apply ((auto simp: length_take_every (*‹0 < ?n ⟹ length (take_every ?n ?xs) = nat ⌈real (length ?xs) / real ?n⌉›*))[1]) (*discuss goal 2*) apply ((auto simp: length_take_every (*‹(0::nat) < (?n::nat) ⟹ length (take_every ?n (?xs::?'a list)) = nat ⌈real (length ?xs) / real ?n⌉›*))[1]) (*proven 2 subgoals*) . thus "?thesis" (*goal: ‹poly.coeff (inv_frob_poly p) i = map inv_frob (take_every CHAR('a) (coeffs p)) ! i›*) using False (*‹¬ (CHAR('a) = 0 ∨ p = 0)›*) i (*‹i < length (map inv_frob (take_every CHAR('a) (coeffs p)))›*) CHAR_pos[where ?'a = 'a] (*‹0 < CHAR('a)›*) by (auto simp: nth_default_def (*‹nth_default ?dflt ?xs ?n = (if ?n < length ?xs then ?xs ! ?n else ?dflt)›*) mult.commute (*‹?a * ?b = ?b * ?a›*)) qed next (*goal: ‹inv_frob_poly p ≠ 0 ⟹ degree (inv_frob_poly p) < length (map inv_frob (take_every CHAR('a) (coeffs p)))›*) assume nz: "inv_frob_poly p ≠ 0" (*‹inv_frob_poly (p::'a poly) ≠ (0::'a poly)›*) have "Polynomial.degree (inv_frob_poly p) ≤ Polynomial.degree p div CHAR('a)" apply (rule degree_inv_frob_poly_le (*‹0 < CHAR(?'a) ⟹ degree (inv_frob_poly ?p) ≤ degree ?p div CHAR(?'a)›*)) (*goal: ‹degree (inv_frob_poly (p::'a poly)) ≤ degree p div CHAR('a)›*) by (fact CHAR_pos (*‹0 < CHAR(?'a)›*)) also (*calculation: ‹degree (inv_frob_poly (p::'a::field_prime_char poly)) ≤ degree p div CHAR('a::field_prime_char)›*) have "… < nat ⌈(real (Polynomial.degree p) + 1) / real CHAR('a)⌉" using CHAR_pos[where ?'a = 'a] (*‹0 < CHAR('a)›*) by (metis div_less_iff_less_mult (*‹(0::nat) < (?q::nat) ⟹ ((?m::nat) div ?q < (?n::nat)) = (?m < ?n * ?q)›*) linorder_not_le (*‹(¬ (?x::?'a::linorder) ≤ (?y::?'a::linorder)) = (?y < ?x)›*) nat_le_real_less (*‹((?n::nat) ≤ (?m::nat)) = (real ?n < real ?m + (1::real))›*) of_nat_0_less_iff (*‹((0::?'a::linordered_nonzero_semiring) < of_nat (?n::nat)) = ((0::nat) < ?n)›*) of_nat_ceiling (*‹(?r::?'a::floor_ceiling) ≤ of_nat (nat ⌈?r⌉)›*) of_nat_mult (*‹of_nat ((?m::nat) * (?n::nat)) = of_nat ?m * of_nat ?n›*) pos_less_divide_eq (*‹(0::?'a::linordered_field) < (?c::?'a::linordered_field) ⟹ ((?a::?'a::linordered_field) < (?b::?'a::linordered_field) / ?c) = (?a * ?c < ?b)›*)) also (*calculation: ‹degree (inv_frob_poly p) < nat ⌈(real (degree p) + 1) / real CHAR('a)⌉›*) have "… = length (take_every CHAR('a) (Polynomial.coeffs p))" using CHAR_pos[where ?'a = 'a] (*‹0 < CHAR('a)›*) ‹p ≠ 0› (*‹p ≠ 0›*) by (simp add: length_take_every (*‹(0::nat) < (?n::nat) ⟹ length (take_every ?n (?xs::?'a::type list)) = nat ⌈real (length ?xs) / real ?n⌉›*) length_coeffs (*‹(?p::?'a::zero poly) ≠ (0::?'a::zero poly) ⟹ length (coeffs ?p) = degree ?p + (1::nat)›*) add_ac (*‹(?a::?'a::semigroup_add) + (?b::?'a::semigroup_add) + (?c::?'a::semigroup_add) = ?a + (?b + ?c)› ‹(?a::?'a::ab_semigroup_add) + (?b::?'a::ab_semigroup_add) = ?b + ?a› ‹(?b::?'a::ab_semigroup_add) + ((?a::?'a::ab_semigroup_add) + (?c::?'a::ab_semigroup_add)) = ?a + (?b + ?c)›*)) finally (*calculation: ‹degree (inv_frob_poly p) < length (take_every CHAR('a) (coeffs p))›*) show "length (map inv_frob (take_every CHAR('a) (Polynomial.coeffs p))) > Polynomial.degree (inv_frob_poly p)" by simp qed also (*calculation: ‹coeffs (inv_frob_poly (p::'a::field_prime_char poly)) = strip_while ((=) (0::'a::field_prime_char)) (map inv_frob (take_every CHAR('a::field_prime_char) (coeffs p)))›*) have "strip_while ((=) 0) (map inv_frob (take_every CHAR('a) (Polynomial.coeffs p))) = map inv_frob (strip_while ((=) 0 ∘ inv_frob) (take_every CHAR('a) (Polynomial.coeffs p)))" by (rule strip_while_map (*‹strip_while ?P (map ?f ?xs) = map ?f (strip_while (?P ∘ ?f) ?xs)›*)) also (*calculation: ‹coeffs (inv_frob_poly p) = map inv_frob (strip_while ((=) 0 ∘ inv_frob) (take_every CHAR('a) (coeffs p)))›*) have "(=) 0 ∘ inv_frob = (=) (0 :: 'a)" by (auto simp: fun_eq_iff (*‹((?f::?'a::type ⇒ ?'b::type) = (?g::?'a::type ⇒ ?'b::type)) = (∀x::?'a::type. ?f x = ?g x)›*)) finally (*calculation: ‹coeffs (inv_frob_poly (p::'a poly)) = map inv_frob (strip_while ((=) (0::'a)) (take_every CHAR('a) (coeffs p)))›*) show "?thesis" (*goal: ‹coeffs (inv_frob_poly p) = (if CHAR('a) = 0 then coeffs p else map inv_frob (strip_while ((=) 0) (take_every CHAR('a) (coeffs p))))›*) using False (*‹¬ (CHAR('a::field_prime_char) = (0::nat) ∨ (p::'a::field_prime_char poly) = (0::'a::field_prime_char poly))›*) by metis qed (auto) (*solved the remaining goal: ‹CHAR('a) = 0 ∨ p = 0 ⟹ coeffs (inv_frob_poly p) = (if CHAR('a) = 0 then coeffs p else map inv_frob (strip_while ((=) 0) (take_every CHAR('a) (coeffs p))))›*) subsection ‹Perfect fields› text ‹ We now introduce perfect fields. The textbook definition of a perfect field is that every irreducible polynomial is separable, i.e.\ if a polynomial $P$ has no non-trivial divisors then $\text{gcd}(P, P') = 0$. For technical reasons, this is somewhat difficult to express in Isabelle/HOL's typeclass system. We therefore use the following much simpler equivalent definition (and prove equivalence later): a field is perfect if it either has characteristic 0 or its Frobenius endomorphism is surjective. › class perfect_field = field + assumes perfect_field: "CHAR('a) = 0 ∨ surj (frob :: 'a ⇒ 'a)" context field_char_0 begin subclass perfect_field by standard auto end context surj_frob begin subclass perfect_field by standard auto end context alg_closed_field begin subclass perfect_field by standard (use alg_closed_surj_frob in auto) end theorem irreducible_imp_pderiv_nonzero: assumes "irreducible (p :: 'a :: perfect_field poly)" shows "pderiv p ≠ 0" proof (cases "CHAR('a) = 0") (*goals: 1. ‹CHAR('a::perfect_field) = (0::nat) ⟹ pderiv (p::'a::perfect_field poly) ≠ (0::'a::perfect_field poly)› 2. ‹CHAR('a::perfect_field) ≠ (0::nat) ⟹ pderiv (p::'a::perfect_field poly) ≠ (0::'a::perfect_field poly)›*) case True (*‹CHAR('a) = (0::nat)›*) interpret A: semiring_1 "1 :: 'a" "(*)" "(+)" "0 :: 'a" by standard have "*": "class.semiring_1 (1 :: 'a) (*) (+) 0" by standard interpret A: field_char_0 "(/)" inverse "(*)" "1 :: 'a" "(+)" 0 "(-)" uminus proof (standard) (*goal: ‹inj (semiring_1.of_nat (1::'a) (+) (0::'a))›*) have "inj (of_nat :: nat ⇒ 'a)" by (auto simp: inj_on_def (*‹inj_on ?f ?A = (∀x∈?A. ∀y∈?A. ?f x = ?f y ⟶ x = y)›*) of_nat_eq_iff_cong_CHAR (*‹(of_nat ?x = of_nat ?y) = [?x = ?y] (mod CHAR(?'a))›*) True (*‹CHAR('a) = 0›*)) also (*calculation: ‹inj of_nat›*) have "of_nat = semiring_1.of_nat (1 :: 'a) (+) 0" by (simp add: of_nat_def [abs_def] (*‹of_nat ≡ λn. ((+) 1 ^^ n) 0›*) semiring_1.of_nat_def [OF *, abs_def] (*‹semiring_1.of_nat 1 (+) 0 ≡ λn. ((+) 1 ^^ n) 0›*)) finally (*calculation: ‹inj (semiring_1.of_nat 1 (+) 0)›*) show "inj …" . qed show "?thesis" (*goal: ‹pderiv p ≠ 0›*) proof (standard) (*goal: ‹pderiv p = 0 ⟹ False›*) assume "pderiv p = 0" (*‹pderiv (p::'a poly) = (0::'a poly)›*) hence "**": "poly.coeff p (Suc n) = 0" for n by (auto simp: poly_eq_iff (*‹((?p::?'a poly) = (?q::?'a poly)) = (∀n::nat. poly.coeff ?p n = poly.coeff ?q n)›*) coeff_pderiv (*‹poly.coeff (pderiv (?p::?'a poly)) (?n::nat) = of_nat (Suc ?n) * poly.coeff ?p (Suc ?n)›*) of_nat_eq_0_iff_char_dvd (*‹(of_nat (?n::nat) = (0::?'a)) = (CHAR(?'a) dvd ?n)›*) True (*‹CHAR('a) = (0::nat)›*) simp del: of_nat_Suc (*‹of_nat (Suc (?m::nat)) = (1::?'a) + of_nat ?m›*)) have "poly.coeff p n = 0" if "n > 0" for n using "**"[of "n - 1"] (*‹poly.coeff p (Suc (n - 1)) = 0›*) that (*‹0 < n›*) apply (cases n) (*goals: 1. ‹⟦poly.coeff p (Suc (n - 1)) = 0; 0 < n; n = 0⟧ ⟹ poly.coeff p n = 0› 2. ‹⋀nat. ⟦poly.coeff p (Suc (n - 1)) = 0; 0 < n; n = Suc nat⟧ ⟹ poly.coeff p n = 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . hence "Polynomial.degree p = 0" by force thus False using assms (*‹irreducible p›*) by force qed next (*goal: ‹CHAR('a) ≠ 0 ⟹ pderiv p ≠ 0›*) case False (*‹CHAR('a) ≠ 0›*) hence [simp]: "surj (frob :: 'a ⇒ 'a)" by (meson perfect_field (*‹CHAR(?'a) = 0 ∨ surj frob›*)) interpret A: field_prime_char "(/)" inverse "(*)" "1 :: 'a" "(+)" 0 "(-)" uminus proof (standard) (*goal: ‹∃n>0. semiring_1.of_nat 1 (+) 0 n = 0›*) have "*": "class.semiring_1 1 (*) (+) (0 :: 'a)" by standard have "semiring_1.of_nat 1 (+) (0 :: 'a) = of_nat" by (simp add: fun_eq_iff (*‹((?f::?'a ⇒ ?'b) = (?g::?'a ⇒ ?'b)) = (∀x::?'a. ?f x = ?g x)›*) of_nat_def (*‹of_nat (?n::nat) = ((+) (1::?'a) ^^ ?n) (0::?'a)›*) semiring_1.of_nat_def[OF *] (*‹semiring_1.of_nat (1::'a) (+) (0::'a) (?n::nat) = ((+) (1::'a) ^^ ?n) (0::'a)›*)) thus "∃n>0. semiring_1.of_nat 1 (+) 0 n = (0 :: 'a)" apply (intro exI[of _ "CHAR('a)"] (*‹?P CHAR('a) ⟹ ∃x. ?P x›*)) (*goal: ‹∃n>0. semiring_1.of_nat 1 (+) 0 n = 0›*) by (use False in auto) qed show "?thesis" (*goal: ‹pderiv (p::'a poly) ≠ (0::'a poly)›*) proof (standard) (*goal: ‹pderiv p = 0 ⟹ False›*) assume "pderiv p = 0" (*‹pderiv (p::'a poly) = (0::'a poly)›*) hence "is_nth_power CHAR('a) p" using pderiv_eq_0_imp_nth_power[of p] (*‹⟦(0::nat) < CHAR('a); pderiv (p::'a poly) = (0::'a poly); surj frob⟧ ⟹ is_nth_power CHAR('a) p›*) surj_frob (*‹surj frob›*) False (*‹CHAR('a) ≠ 0›*) by simp then obtain q where "p = q ^ CHAR('a)" (*goal: ‹(⋀q::'a::perfect_field poly. (p::'a::perfect_field poly) = q ^ CHAR('a::perfect_field) ⟹ thesis::bool) ⟹ thesis›*) by (elim is_nth_powerE (*‹⟦is_nth_power ?n ?x; ⋀y. ?x = y ^ ?n ⟹ ?P⟧ ⟹ ?P›*)) with assms (*‹irreducible p›*) show False by auto qed qed corollary irreducible_imp_separable: assumes "irreducible (p :: 'a :: perfect_field poly)" shows "coprime p (pderiv p)" proof (rule coprimeI (*‹(⋀c. ⟦c dvd ?a; c dvd ?b⟧ ⟹ is_unit c) ⟹ coprime ?a ?b›*)) (*goal: ‹⋀c. ⟦c dvd p; c dvd pderiv p⟧ ⟹ is_unit c›*) fix q assume q: "q dvd p" "q dvd pderiv p" (*‹(q::'a poly) dvd (p::'a poly)› ‹(q::'a poly) dvd pderiv (p::'a poly)›*) have "¬p dvd q" proof (standard) (*goal: ‹(p::'a poly) dvd (q::'a poly) ⟹ False›*) assume "p dvd q" (*‹(p::'a poly) dvd (q::'a poly)›*) hence "p dvd pderiv p" using q (*‹q dvd p› ‹q dvd pderiv p›*) dvd_trans (*‹⟦(?a::?'a) dvd (?b::?'a); ?b dvd (?c::?'a)⟧ ⟹ ?a dvd ?c›*) by blast hence "Polynomial.degree p ≤ Polynomial.degree (pderiv p)" apply (rule dvd_imp_degree_le (*‹⟦(?p::?'a poly) dvd (?q::?'a poly); ?q ≠ (0::?'a poly)⟧ ⟹ degree ?p ≤ degree ?q›*)) (*goal: ‹degree (p::'a::perfect_field poly) ≤ degree (pderiv p)›*) by (use assms irreducible_imp_pderiv_nonzero in auto) also (*calculation: ‹degree p ≤ degree (pderiv p)›*) have "… ≤ Polynomial.degree p - 1" using degree_pderiv_le (*‹degree (pderiv ?f) ≤ degree ?f - 1›*) by auto finally (*calculation: ‹degree p ≤ degree p - 1›*) have "Polynomial.degree p = 0" by simp with assms (*‹irreducible p›*) show False using irreducible_imp_pderiv_nonzero (*‹irreducible (?p::?'a::perfect_field poly) ⟹ pderiv ?p ≠ (0::?'a::perfect_field poly)›*) is_unit_iff_degree (*‹?p ≠ 0 ⟹ is_unit ?p = (degree ?p = 0)›*) by blast qed with ‹q dvd p› (*‹q dvd p›*) show "is_unit q" using assms (*‹irreducible p›*) comm_semiring_1_class.irreducibleD' (*‹⟦irreducible (?a::?'a); (?b::?'a) dvd ?a⟧ ⟹ ?a dvd ?b ∨ ?b dvd (1::?'a)›*) by blast qed end
{ "path": "afp-2025-02-12/thys/Perfect_Fields/Perfect_Fields.thy", "repo": "afp-2025-02-12", "sha": "a8e827d4e33309ea70a254db2ec83f05d37263a7321ee0b5bb316c2f3ae1c140" }
(* Anders Schlichtkrull & Jørgen Villadsen, DTU Compute, Denmark *) chapter ‹On Paraconsistency› text ‹ Paraconsistency concerns inference systems that do not explode given a contradiction. The Internet Encyclopedia of Philosophy has a survey article on paraconsistent logic. The following Isabelle theory formalizes a specific paraconsistent many-valued logic. › theory Paraconsistency imports Main begin text ‹ The details about our logic are in our article in a special issue on logical approaches to paraconsistency in the Journal of Applied Non-Classical Logics (Volume 15, Number 1, 2005). › section ‹Syntax and Semantics› subsection ‹Syntax of Propositional Logic› text ‹ Only the primed operators return indeterminate truth values. › type_synonym id = string datatype fm = Pro id | Truth | Neg' fm | Con' fm fm | Eql fm fm | Eql' fm fm abbreviation Falsity :: fm where "Falsity ≡ Neg' Truth" abbreviation Dis' :: "fm ⇒ fm ⇒ fm" where "Dis' p q ≡ Neg' (Con' (Neg' p) (Neg' q))" abbreviation Imp :: "fm ⇒ fm ⇒ fm" where "Imp p q ≡ Eql p (Con' p q)" abbreviation Imp' :: "fm ⇒ fm ⇒ fm" where "Imp' p q ≡ Eql' p (Con' p q)" abbreviation Box :: "fm ⇒ fm" where "Box p ≡ Eql p Truth" abbreviation Neg :: "fm ⇒ fm" where "Neg p ≡ Box (Neg' p)" abbreviation Con :: "fm ⇒ fm ⇒ fm" where "Con p q ≡ Box (Con' p q)" abbreviation Dis :: "fm ⇒ fm ⇒ fm" where "Dis p q ≡ Box (Dis' p q)" abbreviation Cla :: "fm ⇒ fm" where "Cla p ≡ Dis (Box p) (Eql p Falsity)" abbreviation Nab :: "fm ⇒ fm" where "Nab p ≡ Neg (Cla p)" subsection ‹Semantics of Propositional Logic› text ‹ There is a countably infinite number of indeterminate truth values. › datatype tv = Det bool | Indet nat abbreviation (input) eval_neg :: "tv ⇒ tv" where "eval_neg x ≡ ( case x of Det False ⇒ Det True | Det True ⇒ Det False | Indet n ⇒ Indet n )" fun eval :: "(id ⇒ tv) ⇒ fm ⇒ tv" where "eval i (Pro s) = i s" | "eval i Truth = Det True" | "eval i (Neg' p) = eval_neg (eval i p)" | "eval i (Con' p q) = ( if eval i p = eval i q then eval i p else if eval i p = Det True then eval i q else if eval i q = Det True then eval i p else Det False )" | "eval i (Eql p q) = ( if eval i p = eval i q then Det True else Det False )" | "eval i (Eql' p q) = ( if eval i p = eval i q then Det True else ( case (eval i p, eval i q) of (Det True, _) ⇒ eval i q | (_, Det True) ⇒ eval i p | (Det False, _) ⇒ eval_neg (eval i q) | (_, Det False) ⇒ eval_neg (eval i p) | _ ⇒ Det False ) )" lemma eval_equality_simplify: "eval i (Eql p q) = Det (eval i p = eval i q)" by simp theorem eval_equality: "eval i (Eql' p q) = ( if eval i p = eval i q then Det True else if eval i p = Det True then eval i q else if eval i q = Det True then eval i p else if eval i p = Det False then eval i (Neg' q) else if eval i q = Det False then eval i (Neg' p) else Det False )" apply (cases "eval i p") (*goals: 1. ‹⋀x1. eval i p = Det x1 ⟹ eval i (Eql' p q) = (if eval i p = eval i q then Det True else if eval i p = Det True then eval i q else if eval i q = Det True then eval i p else if eval i p = Det False then eval i (Neg' q) else if eval i q = Det False then eval i (Neg' p) else Det False)› 2. ‹⋀x2. eval i p = Indet x2 ⟹ eval i (Eql' p q) = (if eval i p = eval i q then Det True else if eval i p = Det True then eval i q else if eval i q = Det True then eval i p else if eval i p = Det False then eval i (Neg' q) else if eval i q = Det False then eval i (Neg' p) else Det False)› discuss goal 1*) apply (cases "eval i q") (*goals: 1. ‹⋀x1 x1a. ⟦eval i p = Det x1; eval i q = Det x1a⟧ ⟹ eval i (Eql' p q) = (if eval i p = eval i q then Det True else if eval i p = Det True then eval i q else if eval i q = Det True then eval i p else if eval i p = Det False then eval i (Neg' q) else if eval i q = Det False then eval i (Neg' p) else Det False)› 2. ‹⋀x1 x2. ⟦eval i p = Det x1; eval i q = Indet x2⟧ ⟹ eval i (Eql' p q) = (if eval i p = eval i q then Det True else if eval i p = Det True then eval i q else if eval i q = Det True then eval i p else if eval i p = Det False then eval i (Neg' q) else if eval i q = Det False then eval i (Neg' p) else Det False)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "eval i q") (*goals: 1. ‹⋀x2 x1. ⟦eval i p = Indet x2; eval i q = Det x1⟧ ⟹ eval i (Eql' p q) = (if eval i p = eval i q then Det True else if eval i p = Det True then eval i q else if eval i q = Det True then eval i p else if eval i p = Det False then eval i (Neg' q) else if eval i q = Det False then eval i (Neg' p) else Det False)› 2. ‹⋀x2 x2a. ⟦eval i p = Indet x2; eval i q = Indet x2a⟧ ⟹ eval i (Eql' p q) = (if eval i p = eval i q then Det True else if eval i p = Det True then eval i q else if eval i q = Det True then eval i p else if eval i p = Det False then eval i (Neg' q) else if eval i q = Det False then eval i (Neg' p) else Det False)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) . theorem eval_negation: "eval i (Neg' p) = ( if eval i p = Det False then Det True else if eval i p = Det True then Det False else eval i p )" apply (cases "eval i p") (*goals: 1. ‹⋀x1. eval i p = Det x1 ⟹ eval i (Neg' p) = (if eval i p = Det False then Det True else if eval i p = Det True then Det False else eval i p)› 2. ‹⋀x2. eval i p = Indet x2 ⟹ eval i (Neg' p) = (if eval i p = Det False then Det True else if eval i p = Det True then Det False else eval i p)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . corollary "eval i (Cla p) = eval i (Box (Dis' p (Neg' p)))" using eval_negation (*‹eval ?i (Neg' ?p) = (if eval ?i ?p = Det False then Det True else if eval ?i ?p = Det True then Det False else eval ?i ?p)›*) by simp lemma double_negation: "eval i p = eval i (Neg' (Neg' p))" using eval_negation (*‹eval ?i (Neg' ?p) = (if eval ?i ?p = Det False then Det True else if eval ?i ?p = Det True then Det False else eval ?i ?p)›*) by simp subsection ‹Validity and Consistency› text ‹ Validity gives the set of theorems and the logic has at least a theorem and a non-theorem. › definition valid :: "fm ⇒ bool" where "valid p ≡ ∀i. eval i p = Det True" proposition "valid Truth" and "¬ valid Falsity" unfolding valid_def (*goals: 1. ‹∀i. eval i Truth = Det True› 2. ‹¬ (∀i. eval i Falsity = Det True)›*) (*goals: 1. ‹∀i. eval i Truth = Det True› 2. ‹¬ (∀i. eval i Falsity = Det True)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . section ‹Truth Tables› subsection ‹String Functions› text ‹ The following functions support arbitrary unary and binary truth tables. › definition tv_pair_row :: "tv list ⇒ tv ⇒ (tv * tv) list" where "tv_pair_row tvs tv ≡ map (λx. (tv, x)) tvs" definition tv_pair_table :: "tv list ⇒ (tv * tv) list list" where "tv_pair_table tvs ≡ map (tv_pair_row tvs) tvs" definition map_row :: "(tv ⇒ tv ⇒ tv) ⇒ (tv * tv) list ⇒ tv list" where "map_row f tvtvs ≡ map (λ(x, y). f x y) tvtvs" definition map_table :: "(tv ⇒ tv ⇒ tv) ⇒ (tv * tv) list list ⇒ tv list list" where "map_table f tvtvss ≡ map (map_row f) tvtvss" definition unary_truth_table :: "fm ⇒ tv list ⇒ tv list" where "unary_truth_table p tvs ≡ map (λx. eval ((λs. undefined)(''p'' := x)) p) tvs" definition binary_truth_table :: "fm ⇒ tv list ⇒ tv list list" where "binary_truth_table p tvs ≡ map_table (λx y. eval ((λs. undefined)(''p'' := x, ''q'' := y)) p) (tv_pair_table tvs)" definition digit_of_nat :: "nat ⇒ char" where "digit_of_nat n ≡ (if n = 1 then (CHR ''1'') else if n = 2 then (CHR ''2'') else if n = 3 then (CHR ''3'') else if n = 4 then (CHR ''4'') else if n = 5 then (CHR ''5'') else if n = 6 then (CHR ''6'') else if n = 7 then (CHR ''7'') else if n = 8 then (CHR ''8'') else if n = 9 then (CHR ''9'') else (CHR ''0''))" fun string_of_nat :: "nat ⇒ string" where "string_of_nat n = (if n < 10 then [digit_of_nat n] else string_of_nat (n div 10) @ [digit_of_nat (n mod 10)])" fun string_tv :: "tv ⇒ string" where "string_tv (Det True) = ''*''" | "string_tv (Det False) = ''o''" | "string_tv (Indet n) = string_of_nat n" definition appends :: "string list ⇒ string" where "appends strs ≡ foldr append strs []" definition appends_nl :: "string list ⇒ string" where "appends_nl strs ≡ ''⏎ '' @ foldr (λs s'. s @ ''⏎ '' @ s') (butlast strs) (last strs) @ ''⏎''" definition string_table :: "tv list list ⇒ string list list" where "string_table tvss ≡ map (map string_tv) tvss" definition string_table_string :: "string list list ⇒ string" where "string_table_string strss ≡ appends_nl (map appends strss)" definition unary :: "fm ⇒ tv list ⇒ string" where "unary p tvs ≡ appends_nl (map string_tv (unary_truth_table p tvs))" definition binary :: "fm ⇒ tv list ⇒ string" where "binary p tvs ≡ string_table_string (string_table (binary_truth_table p tvs))" subsection ‹Main Truth Tables› text ‹ The omitted Cla (for Classic) is discussed later; Nab (for Nabla) is simply the negation of it. › proposition (* Box Truth Table *) "unary (Box (Pro ''p'')) [Det True, Det False, Indet 1] = '' * o o ''" by code_simp proposition (* Con' Truth Table *) "binary (Con' (Pro ''p'') (Pro ''q'')) [Det True, Det False, Indet 1, Indet 2] = '' *o12 oooo 1o1o 2oo2 ''" by code_simp proposition (* Dis' Truth Table *) "binary (Dis' (Pro ''p'') (Pro ''q'')) [Det True, Det False, Indet 1, Indet 2] = '' **** *o12 *11* *2*2 ''" by code_simp proposition (* Neg' Truth Table *) "unary (Neg' (Pro ''p'')) [Det True, Det False, Indet 1] = '' o * 1 ''" by code_simp proposition (* Eql' Truth Table *) "binary (Eql' (Pro ''p'') (Pro ''q'')) [Det True, Det False, Indet 1, Indet 2] = '' *o12 o*12 11*o 22o* ''" by code_simp proposition (* Imp' Truth Table *) "binary (Imp' (Pro ''p'') (Pro ''q'')) [Det True, Det False, Indet 1, Indet 2] = '' *o12 **** *1*1 *22* ''" by code_simp proposition (* Neg Truth Table *) "unary (Neg (Pro ''p'')) [Det True, Det False, Indet 1] = '' o * o ''" by code_simp proposition (* Eql Truth Table *) "binary (Eql (Pro ''p'') (Pro ''q'')) [Det True, Det False, Indet 1, Indet 2] = '' *ooo o*oo oo*o ooo* ''" by code_simp proposition (* Imp Truth Table *) "binary (Imp (Pro ''p'') (Pro ''q'')) [Det True, Det False, Indet 1, Indet 2] = '' *ooo **** *o*o *oo* ''" by code_simp proposition (* Nab Truth Table *) "unary (Nab (Pro ''p'')) [Det True, Det False, Indet 1] = '' o o * ''" by code_simp proposition (* Con Truth Table *) "binary (Con (Pro ''p'') (Pro ''q'')) [Det True, Det False, Indet 1, Indet 2] = '' *ooo oooo oooo oooo ''" by code_simp proposition (* Dis Truth Table *) "binary (Dis (Pro ''p'') (Pro ''q'')) [Det True, Det False, Indet 1, Indet 2] = '' **** *ooo *oo* *o*o ''" by code_simp section ‹Basic Theorems› subsection ‹Selected Theorems and Non-Theorems› text ‹ Many of the following theorems and non-theorems use assumptions and meta-variables. › proposition "valid (Cla (Box p))" and "¬ valid (Nab (Box p))" unfolding valid_def (*goals: 1. ‹∀i. eval i (Cla (Box p)) = Det True› 2. ‹¬ (∀i. eval i (Nab (Box p)) = Det True)›*) (*goals: 1. ‹∀i. eval i (Cla (Box p)) = Det True› 2. ‹¬ (∀i. eval i (Nab (Box p)) = Det True)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . proposition "valid (Cla (Cla p))" and "¬ valid (Nab (Nab p))" unfolding valid_def (*goals: 1. ‹∀i. eval i (Cla (Cla p)) = Det True› 2. ‹¬ (∀i. eval i (Nab (Nab p)) = Det True)›*) (*goals: 1. ‹∀i. eval i (Cla (Cla p)) = Det True› 2. ‹¬ (∀i. eval i (Nab (Nab p)) = Det True)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . proposition "valid (Cla (Nab p))" and "¬ valid (Nab (Cla p))" unfolding valid_def (*goals: 1. ‹∀i. eval i (Cla (Nab p)) = Det True› 2. ‹¬ (∀i. eval i (Nab (Cla p)) = Det True)›*) (*goals: 1. ‹∀i. eval i (Cla (Nab p)) = Det True› 2. ‹¬ (∀i. eval i (Nab (Cla p)) = Det True)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . proposition "valid (Box p) ⟷ valid (Box (Box p))" unfolding valid_def (*goal: ‹(∀i. eval i (Box p) = Det True) = (∀i. eval i (Box (Box p)) = Det True)›*) by simp proposition "valid (Neg p) ⟷ valid (Neg' p)" unfolding valid_def (*goal: ‹(∀i::char list ⇒ tv. eval i (Neg (p::fm)) = Det True) = (∀i::char list ⇒ tv. eval i (Neg' p) = Det True)›*) by simp proposition "valid (Con p q) ⟷ valid (Con' p q)" unfolding valid_def (*goal: ‹(∀i. eval i (Con p q) = Det True) = (∀i. eval i (Con' p q) = Det True)›*) by simp proposition "valid (Dis p q) ⟷ valid (Dis' p q)" unfolding valid_def (*goal: ‹(∀i. eval i (Dis p q) = Det True) = (∀i. eval i (Dis' p q) = Det True)›*) by simp proposition "valid (Eql p q) ⟷ valid (Eql' p q)" unfolding valid_def (*goal: ‹(∀i. eval i (Eql p q) = Det True) = (∀i. eval i (Eql' p q) = Det True)›*) using eval.simps (*‹eval ?i (Pro ?s) = ?i ?s› ‹eval (?i::char list ⇒ tv) Truth = Det True› ‹eval ?i (Neg' ?p) = (case eval ?i ?p of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x)› ‹eval ?i (Con' ?p ?q) = (if eval ?i ?p = eval ?i ?q then eval ?i ?p else if eval ?i ?p = Det True then eval ?i ?q else if eval ?i ?q = Det True then eval ?i ?p else Det False)› ‹eval ?i (Eql ?p ?q) = (if eval ?i ?p = eval ?i ?q then Det True else Det False)› ‹eval ?i (Eql' ?p ?q) = (if eval ?i ?p = eval ?i ?q then Det True else case (eval ?i ?p, eval ?i ?q) of (Det True, xa) ⇒ eval ?i ?q | (Det False, Det True) ⇒ eval ?i ?p | (Det False, Det False) ⇒ case eval ?i ?q of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Det False, Indet nat) ⇒ case eval ?i ?q of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Indet nat, Det True) ⇒ eval ?i ?p | (Indet nat, Det False) ⇒ case eval ?i ?p of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Indet nat, Indet nata) ⇒ Det False)›*) tv.inject (*‹(Det ?x1.0 = Det ?y1.0) = (?x1.0 = ?y1.0)› ‹(Indet ?x2.0 = Indet ?y2.0) = (?x2.0 = ?y2.0)›*) eval_equality (*‹eval ?i (Eql' ?p ?q) = (if eval ?i ?p = eval ?i ?q then Det True else if eval ?i ?p = Det True then eval ?i ?q else if eval ?i ?q = Det True then eval ?i ?p else if eval ?i ?p = Det False then eval ?i (Neg' ?q) else if eval ?i ?q = Det False then eval ?i (Neg' ?p) else Det False)›*) eval_negation (*‹eval ?i (Neg' ?p) = (if eval ?i ?p = Det False then Det True else if eval ?i ?p = Det True then Det False else eval ?i ?p)›*) by (metis (full_types)) proposition "valid (Imp p q) ⟷ valid (Imp' p q)" unfolding valid_def (*goal: ‹(∀i. eval i (Imp p q) = Det True) = (∀i. eval i (Imp' p q) = Det True)›*) using eval.simps (*‹eval (?i::char list ⇒ tv) (Pro (?s::char list)) = ?i ?s› ‹eval ?i Truth = Det True› ‹eval ?i (Neg' ?p) = (case eval ?i ?p of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x)› ‹eval ?i (Con' ?p ?q) = (if eval ?i ?p = eval ?i ?q then eval ?i ?p else if eval ?i ?p = Det True then eval ?i ?q else if eval ?i ?q = Det True then eval ?i ?p else Det False)› ‹eval ?i (Eql ?p ?q) = (if eval ?i ?p = eval ?i ?q then Det True else Det False)› ‹eval ?i (Eql' ?p ?q) = (if eval ?i ?p = eval ?i ?q then Det True else case (eval ?i ?p, eval ?i ?q) of (Det True, xa) ⇒ eval ?i ?q | (Det False, Det True) ⇒ eval ?i ?p | (Det False, Det False) ⇒ case eval ?i ?q of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Det False, Indet nat) ⇒ case eval ?i ?q of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Indet nat, Det True) ⇒ eval ?i ?p | (Indet nat, Det False) ⇒ case eval ?i ?p of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Indet nat, Indet nata) ⇒ Det False)›*) tv.inject (*‹(Det ?x1.0 = Det ?y1.0) = (?x1.0 = ?y1.0)› ‹(Indet ?x2.0 = Indet ?y2.0) = (?x2.0 = ?y2.0)›*) eval_equality (*‹eval ?i (Eql' ?p ?q) = (if eval ?i ?p = eval ?i ?q then Det True else if eval ?i ?p = Det True then eval ?i ?q else if eval ?i ?q = Det True then eval ?i ?p else if eval ?i ?p = Det False then eval ?i (Neg' ?q) else if eval ?i ?q = Det False then eval ?i (Neg' ?p) else Det False)›*) eval_negation (*‹eval ?i (Neg' ?p) = (if eval ?i ?p = Det False then Det True else if eval ?i ?p = Det True then Det False else eval ?i ?p)›*) by (metis (full_types)) proposition "¬ valid (Pro ''p'')" unfolding valid_def (*goal: ‹¬ (∀i. eval i (Pro ''p'') = Det True)›*) by auto proposition "¬ valid (Neg' (Pro ''p''))" proof (-) (*goal: ‹¬ valid (Neg' (Pro ''p''))›*) have "eval (λs. Det True) (Neg' (Pro ''p'')) = Det False" by simp then show "?thesis" (*goal: ‹¬ valid (Neg' (Pro ''p''))›*) unfolding valid_def (*goal: ‹¬ (∀i. eval i (Neg' (Pro ''p'')) = Det True)›*) using tv.inject (*‹(Det ?x1.0 = Det ?y1.0) = (?x1.0 = ?y1.0)› ‹(Indet ?x2.0 = Indet ?y2.0) = (?x2.0 = ?y2.0)›*) by metis qed proposition assumes "valid p" shows "¬ valid (Neg' p)" using assms (*‹valid (p::fm)›*) unfolding valid_def (*goal: ‹¬ (∀i::char list ⇒ tv. eval i (Neg' (p::fm)) = Det True)›*) by simp proposition assumes "valid (Neg' p)" shows "¬ valid p" using assms (*‹valid (Neg' p)›*) unfolding valid_def (*goal: ‹¬ (∀i::char list ⇒ tv. eval i (p::fm) = Det True)›*) by force proposition "valid (Neg' (Neg' p)) ⟷ valid p" unfolding valid_def (*goal: ‹(∀i. eval i (Neg' (Neg' p)) = Det True) = (∀i. eval i p = Det True)›*) using double_negation (*‹eval ?i ?p = eval ?i (Neg' (Neg' ?p))›*) by simp theorem conjunction: "valid (Con' p q) ⟷ valid p ∧ valid q" unfolding valid_def (*goal: ‹(∀i. eval i (Con' p q) = Det True) = ((∀i. eval i p = Det True) ∧ (∀i. eval i q = Det True))›*) by auto corollary assumes "valid (Con' p q)" shows "valid p" and "valid q" using assms (*‹valid (Con' p q)›*) conjunction (*‹valid (Con' ?p ?q) = (valid ?p ∧ valid ?q)›*) apply - (*goals: 1. ‹⟦valid (Con' p q); ⋀p q. valid (Con' p q) = (valid p ∧ valid q)⟧ ⟹ valid p› 2. ‹⟦valid (Con' p q); ⋀p q. valid (Con' p q) = (valid p ∧ valid q)⟧ ⟹ valid q› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . proposition assumes "valid p" and "valid (Imp p q)" shows "valid q" using assms (*‹valid p› ‹valid (Imp p q)›*) eval.simps (*‹eval ?i (Pro ?s) = ?i ?s› ‹eval ?i Truth = Det True› ‹eval ?i (Neg' ?p) = (case eval ?i ?p of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x)› ‹eval ?i (Con' ?p ?q) = (if eval ?i ?p = eval ?i ?q then eval ?i ?p else if eval ?i ?p = Det True then eval ?i ?q else if eval ?i ?q = Det True then eval ?i ?p else Det False)› ‹eval (?i::char list ⇒ tv) (Eql (?p::fm) (?q::fm)) = (if eval ?i ?p = eval ?i ?q then Det True else Det False)› ‹eval ?i (Eql' ?p ?q) = (if eval ?i ?p = eval ?i ?q then Det True else case (eval ?i ?p, eval ?i ?q) of (Det True, xa) ⇒ eval ?i ?q | (Det False, Det True) ⇒ eval ?i ?p | (Det False, Det False) ⇒ case eval ?i ?q of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Det False, Indet nat) ⇒ case eval ?i ?q of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Indet nat, Det True) ⇒ eval ?i ?p | (Indet nat, Det False) ⇒ case eval ?i ?p of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Indet nat, Indet nata) ⇒ Det False)›*) tv.inject (*‹(Det (?x1.0::bool) = Det (?y1.0::bool)) = (?x1.0 = ?y1.0)› ‹(Indet ?x2.0 = Indet ?y2.0) = (?x2.0 = ?y2.0)›*) unfolding valid_def (*goal: ‹∀i. eval i q = Det True›*) by (metis (full_types)) proposition assumes "valid p" and "valid (Imp' p q)" shows "valid q" using assms (*‹valid p› ‹valid (Imp' p q)›*) eval.simps (*‹eval ?i (Pro ?s) = ?i ?s› ‹eval ?i Truth = Det True› ‹eval ?i (Neg' ?p) = (case eval ?i ?p of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x)› ‹eval ?i (Con' ?p ?q) = (if eval ?i ?p = eval ?i ?q then eval ?i ?p else if eval ?i ?p = Det True then eval ?i ?q else if eval ?i ?q = Det True then eval ?i ?p else Det False)› ‹eval ?i (Eql ?p ?q) = (if eval ?i ?p = eval ?i ?q then Det True else Det False)› ‹eval (?i::char list ⇒ tv) (Eql' (?p::fm) (?q::fm)) = (if eval ?i ?p = eval ?i ?q then Det True else case (eval ?i ?p, eval ?i ?q) of (Det True, xa::tv) ⇒ eval ?i ?q | (Det False, Det True) ⇒ eval ?i ?p | (Det False, Det False) ⇒ case eval ?i ?q of Det True ⇒ Det False | Det False ⇒ Det True | Indet (x::nat) ⇒ Indet x | (Det False, Indet (nat::nat)) ⇒ case eval ?i ?q of Det True ⇒ Det False | Det False ⇒ Det True | Indet (x::nat) ⇒ Indet x | (Indet (nat::nat), Det True) ⇒ eval ?i ?p | (Indet (nat::nat), Det False) ⇒ case eval ?i ?p of Det True ⇒ Det False | Det False ⇒ Det True | Indet (x::nat) ⇒ Indet x | (Indet (nat::nat), Indet (nata::nat)) ⇒ Det False)›*) tv.inject (*‹(Det ?x1.0 = Det ?y1.0) = (?x1.0 = ?y1.0)› ‹(Indet ?x2.0 = Indet ?y2.0) = (?x2.0 = ?y2.0)›*) eval_equality (*‹eval (?i::char list ⇒ tv) (Eql' (?p::fm) (?q::fm)) = (if eval ?i ?p = eval ?i ?q then Det True else if eval ?i ?p = Det True then eval ?i ?q else if eval ?i ?q = Det True then eval ?i ?p else if eval ?i ?p = Det False then eval ?i (Neg' ?q) else if eval ?i ?q = Det False then eval ?i (Neg' ?p) else Det False)›*) unfolding valid_def (*goal: ‹∀i. eval i q = Det True›*) by (metis (full_types)) subsection ‹Key Equalities› text ‹ The key equalities are part of the motivation for the semantic clauses. › proposition "valid (Eql p (Neg' (Neg' p)))" unfolding valid_def (*goal: ‹∀i. eval i (Eql p (Neg' (Neg' p))) = Det True›*) using double_negation (*‹eval ?i ?p = eval ?i (Neg' (Neg' ?p))›*) by simp proposition "valid (Eql Truth (Neg' Falsity))" unfolding valid_def (*goal: ‹∀i. eval i (Eql Truth (Neg' Falsity)) = Det True›*) by simp proposition "valid (Eql Falsity (Neg' Truth))" unfolding valid_def (*goal: ‹∀i. eval i (Eql Falsity Falsity) = Det True›*) by simp proposition "valid (Eql p (Con' p p))" unfolding valid_def (*goal: ‹∀i. eval i (Imp p p) = Det True›*) by simp proposition "valid (Eql p (Con' Truth p))" unfolding valid_def (*goal: ‹∀i::char list ⇒ tv. eval i (Eql (p::fm) (Con' Truth p)) = Det True›*) by simp proposition "valid (Eql p (Con' p Truth))" unfolding valid_def (*goal: ‹∀i::char list ⇒ tv. eval i (Imp (p::fm) Truth) = Det True›*) by simp proposition "valid (Eql Truth (Eql' p p))" unfolding valid_def (*goal: ‹∀i. eval i (Eql Truth (Eql' p p)) = Det True›*) by simp proposition "valid (Eql p (Eql' Truth p))" unfolding valid_def (*goal: ‹∀i. eval i (Eql p (Eql' Truth p)) = Det True›*) by simp proposition "valid (Eql p (Eql' p Truth))" unfolding valid_def (*goal: ‹∀i. eval i (Eql p (Eql' p Truth)) = Det True›*) proof (standard) (*goal: ‹⋀i. eval i (Eql p (Eql' p Truth)) = Det True›*) fix i show "eval i (Eql p (Eql' p Truth)) = Det True" apply (cases "eval i p") (*goals: 1. ‹⋀x1::bool. eval (i::char list ⇒ tv) (p::fm) = Det x1 ⟹ eval i (Eql p (Eql' p Truth)) = Det True› 2. ‹⋀x2::nat. eval (i::char list ⇒ tv) (p::fm) = Indet x2 ⟹ eval i (Eql p (Eql' p Truth)) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . qed proposition "valid (Eql (Neg' p) (Eql' Falsity p))" unfolding valid_def (*goal: ‹∀i. eval i (Eql (Neg' p) (Eql' Falsity p)) = Det True›*) proof (standard) (*goal: ‹⋀i. eval i (Eql (Neg' p) (Eql' Falsity p)) = Det True›*) fix i show "eval i (Eql (Neg' p) (Eql' (Neg' Truth) p)) = Det True" apply (cases "eval i p") (*goals: 1. ‹⋀x1. eval i p = Det x1 ⟹ eval i (Eql (Neg' p) (Eql' Falsity p)) = Det True› 2. ‹⋀x2. eval i p = Indet x2 ⟹ eval i (Eql (Neg' p) (Eql' Falsity p)) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . qed proposition "valid (Eql (Neg' p) (Eql' p Falsity))" unfolding valid_def (*goal: ‹∀i. eval i (Eql (Neg' p) (Eql' p Falsity)) = Det True›*) using eval.simps (*‹eval ?i (Pro ?s) = ?i ?s› ‹eval (?i::char list ⇒ tv) Truth = Det True› ‹eval ?i (Neg' ?p) = (case eval ?i ?p of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x)› ‹eval ?i (Con' ?p ?q) = (if eval ?i ?p = eval ?i ?q then eval ?i ?p else if eval ?i ?p = Det True then eval ?i ?q else if eval ?i ?q = Det True then eval ?i ?p else Det False)› ‹eval ?i (Eql ?p ?q) = (if eval ?i ?p = eval ?i ?q then Det True else Det False)› ‹eval ?i (Eql' ?p ?q) = (if eval ?i ?p = eval ?i ?q then Det True else case (eval ?i ?p, eval ?i ?q) of (Det True, xa) ⇒ eval ?i ?q | (Det False, Det True) ⇒ eval ?i ?p | (Det False, Det False) ⇒ case eval ?i ?q of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Det False, Indet nat) ⇒ case eval ?i ?q of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Indet nat, Det True) ⇒ eval ?i ?p | (Indet nat, Det False) ⇒ case eval ?i ?p of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Indet nat, Indet nata) ⇒ Det False)›*) eval_equality (*‹eval ?i (Eql' ?p ?q) = (if eval ?i ?p = eval ?i ?q then Det True else if eval ?i ?p = Det True then eval ?i ?q else if eval ?i ?q = Det True then eval ?i ?p else if eval ?i ?p = Det False then eval ?i (Neg' ?q) else if eval ?i ?q = Det False then eval ?i (Neg' ?p) else Det False)›*) eval_negation (*‹eval (?i::char list ⇒ tv) (Neg' (?p::fm)) = (if eval ?i ?p = Det False then Det True else if eval ?i ?p = Det True then Det False else eval ?i ?p)›*) by metis section ‹Further Non-Theorems› subsection ‹Smaller Domains and Paraconsistency› text ‹ Validity is relativized to a set of indeterminate truth values (called a domain). › definition domain :: "nat set ⇒ tv set" where "domain U ≡ {Det True, Det False} ∪ Indet ` U" theorem universal_domain: "domain {n. True} = {x. True}" proof (-) (*goal: ‹domain {n. True} = {x. True}›*) have "∀x. x = Det True ∨ x = Det False ∨ x ∈ range Indet" using range_eqI (*‹?b = ?f ?x ⟹ ?b ∈ range ?f›*) tv.exhaust (*‹⟦⋀x1. ?y = Det x1 ⟹ ?P; ⋀x2. ?y = Indet x2 ⟹ ?P⟧ ⟹ ?P›*) tv.inject (*‹(Det (?x1.0::bool) = Det (?y1.0::bool)) = (?x1.0 = ?y1.0)› ‹(Indet ?x2.0 = Indet ?y2.0) = (?x2.0 = ?y2.0)›*) by metis then show "?thesis" (*goal: ‹domain {n. True} = {x. True}›*) unfolding domain_def (*goal: ‹{Det True, Det False} ∪ Indet ` {n. True} = {x. True}›*) by blast qed definition valid_in :: "nat set ⇒ fm ⇒ bool" where "valid_in U p ≡ ∀i. range i ⊆ domain U ⟶ eval i p = Det True" abbreviation valid_boole :: "fm ⇒ bool" where "valid_boole p ≡ valid_in {} p" proposition "valid p ⟷ valid_in {n. True} p" unfolding valid_def valid_in_def (*goal: ‹(∀i. eval i p = Det True) = (∀i. range i ⊆ domain {n. True} ⟶ eval i p = Det True)›*) using universal_domain (*‹domain {n. True} = {x. True}›*) by simp theorem valid_valid_in: assumes "valid p" shows "valid_in U p" using assms (*‹valid p›*) unfolding valid_in_def valid_def (*goal: ‹∀i. range i ⊆ domain U ⟶ eval i p = Det True›*) by simp theorem transfer: assumes "¬ valid_in U p" shows "¬ valid p" using assms (*‹¬ valid_in U p›*) valid_valid_in (*‹valid ?p ⟹ valid_in ?U ?p›*) by blast proposition "valid_in U (Neg' (Neg' p)) ⟷ valid_in U p" unfolding valid_in_def (*goal: ‹(∀i. range i ⊆ domain U ⟶ eval i (Neg' (Neg' p)) = Det True) = (∀i. range i ⊆ domain U ⟶ eval i p = Det True)›*) using double_negation (*‹eval (?i::char list ⇒ tv) (?p::fm) = eval ?i (Neg' (Neg' ?p))›*) by simp theorem conjunction_in: "valid_in U (Con' p q) ⟷ valid_in U p ∧ valid_in U q" unfolding valid_in_def (*goal: ‹(∀i. range i ⊆ domain U ⟶ eval i (Con' p q) = Det True) = ((∀i. range i ⊆ domain U ⟶ eval i p = Det True) ∧ (∀i. range i ⊆ domain U ⟶ eval i q = Det True))›*) by auto corollary assumes "valid_in U (Con' p q)" shows "valid_in U p" and "valid_in U q" using assms (*‹valid_in U (Con' p q)›*) conjunction_in (*‹valid_in ?U (Con' ?p ?q) = (valid_in ?U ?p ∧ valid_in ?U ?q)›*) apply - (*goals: 1. ‹⟦valid_in U (Con' p q); ⋀U p q. valid_in U (Con' p q) = (valid_in U p ∧ valid_in U q)⟧ ⟹ valid_in U p› 2. ‹⟦valid_in U (Con' p q); ⋀U p q. valid_in U (Con' p q) = (valid_in U p ∧ valid_in U q)⟧ ⟹ valid_in U q› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . proposition assumes "valid_in U p" and "valid_in U (Imp p q)" shows "valid_in U q" using assms (*‹valid_in U p› ‹valid_in U (Imp p q)›*) eval.simps (*‹eval ?i (Pro ?s) = ?i ?s› ‹eval ?i Truth = Det True› ‹eval ?i (Neg' ?p) = (case eval ?i ?p of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x)› ‹eval (?i::char list ⇒ tv) (Con' (?p::fm) (?q::fm)) = (if eval ?i ?p = eval ?i ?q then eval ?i ?p else if eval ?i ?p = Det True then eval ?i ?q else if eval ?i ?q = Det True then eval ?i ?p else Det False)› ‹eval ?i (Eql ?p ?q) = (if eval ?i ?p = eval ?i ?q then Det True else Det False)› ‹eval ?i (Eql' ?p ?q) = (if eval ?i ?p = eval ?i ?q then Det True else case (eval ?i ?p, eval ?i ?q) of (Det True, xa) ⇒ eval ?i ?q | (Det False, Det True) ⇒ eval ?i ?p | (Det False, Det False) ⇒ case eval ?i ?q of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Det False, Indet nat) ⇒ case eval ?i ?q of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Indet nat, Det True) ⇒ eval ?i ?p | (Indet nat, Det False) ⇒ case eval ?i ?p of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Indet nat, Indet nata) ⇒ Det False)›*) tv.inject (*‹(Det (?x1.0::bool) = Det (?y1.0::bool)) = (?x1.0 = ?y1.0)› ‹(Indet ?x2.0 = Indet ?y2.0) = (?x2.0 = ?y2.0)›*) unfolding valid_in_def (*goal: ‹∀i::char list ⇒ tv. range i ⊆ domain (U::nat set) ⟶ eval i (q::fm) = Det True›*) by (metis (full_types)) proposition assumes "valid_in U p" and "valid_in U (Imp' p q)" shows "valid_in U q" using assms (*‹valid_in U p› ‹valid_in U (Imp' p q)›*) eval.simps (*‹eval (?i::char list ⇒ tv) (Pro (?s::char list)) = ?i ?s› ‹eval (?i::char list ⇒ tv) Truth = Det True› ‹eval ?i (Neg' ?p) = (case eval ?i ?p of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x)› ‹eval ?i (Con' ?p ?q) = (if eval ?i ?p = eval ?i ?q then eval ?i ?p else if eval ?i ?p = Det True then eval ?i ?q else if eval ?i ?q = Det True then eval ?i ?p else Det False)› ‹eval ?i (Eql ?p ?q) = (if eval ?i ?p = eval ?i ?q then Det True else Det False)› ‹eval ?i (Eql' ?p ?q) = (if eval ?i ?p = eval ?i ?q then Det True else case (eval ?i ?p, eval ?i ?q) of (Det True, xa) ⇒ eval ?i ?q | (Det False, Det True) ⇒ eval ?i ?p | (Det False, Det False) ⇒ case eval ?i ?q of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Det False, Indet nat) ⇒ case eval ?i ?q of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Indet nat, Det True) ⇒ eval ?i ?p | (Indet nat, Det False) ⇒ case eval ?i ?p of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Indet nat, Indet nata) ⇒ Det False)›*) tv.inject (*‹(Det ?x1.0 = Det ?y1.0) = (?x1.0 = ?y1.0)› ‹(Indet ?x2.0 = Indet ?y2.0) = (?x2.0 = ?y2.0)›*) eval_equality (*‹eval ?i (Eql' ?p ?q) = (if eval ?i ?p = eval ?i ?q then Det True else if eval ?i ?p = Det True then eval ?i ?q else if eval ?i ?q = Det True then eval ?i ?p else if eval ?i ?p = Det False then eval ?i (Neg' ?q) else if eval ?i ?q = Det False then eval ?i (Neg' ?p) else Det False)›*) unfolding valid_in_def (*goal: ‹∀i. range i ⊆ domain U ⟶ eval i q = Det True›*) by (metis (full_types)) abbreviation (input) Explosion :: "fm ⇒ fm ⇒ fm" where "Explosion p q ≡ Imp' (Con' p (Neg' p)) q" proposition "valid_boole (Explosion (Pro ''p'') (Pro ''q''))" unfolding valid_in_def (*goal: ‹∀i::char list ⇒ tv. range i ⊆ domain {} ⟶ eval i (Imp' (Con' (Pro ''p'') (Neg' (Pro ''p''))) (Pro ''q'')) = Det True›*) apply rule (*goal: ‹∀i. range i ⊆ domain {} ⟶ eval i (Imp' (Con' (Pro ''p'') (Neg' (Pro ''p''))) (Pro ''q'')) = Det True›*) proof (rule) (*goal: ‹⋀i::char list ⇒ tv. range i ⊆ domain {} ⟹ eval i (Imp' (Con' (Pro ''p'') (Neg' (Pro ''p''))) (Pro ''q'')) = Det True›*) fix i :: "id ⇒ tv" assume "range i ⊆ domain {}" (*‹range (i::char list ⇒ tv) ⊆ domain {}›*) then have "i ''p'' ∈ {Det True, Det False}" "i ''q'' ∈ {Det True, Det False}" unfolding domain_def (*goals: 1. ‹i ''p'' ∈ {Det True, Det False}› 2. ‹i ''q'' ∈ {Det True, Det False}›*) apply - (*goals: 1. ‹range i ⊆ {Det True, Det False} ∪ Indet ` {} ⟹ i ''p'' ∈ {Det True, Det False}› 2. ‹range i ⊆ {Det True, Det False} ∪ Indet ` {} ⟹ i ''q'' ∈ {Det True, Det False}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . then show "eval i (Explosion (Pro ''p'') (Pro ''q'')) = Det True" apply (cases "i ''p''") (*goals: 1. ‹⋀x1. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''p'' = Det x1⟧ ⟹ eval i (Imp' (Con' (Pro ''p'') (Neg' (Pro ''p''))) (Pro ''q'')) = Det True› 2. ‹⋀x2. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''p'' = Indet x2⟧ ⟹ eval i (Imp' (Con' (Pro ''p'') (Neg' (Pro ''p''))) (Pro ''q'')) = Det True› discuss goal 1*) apply (cases "i ''q''") (*goals: 1. ‹⋀(x1::bool) x1a::bool. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''p'' = Det x1; i ''q'' = Det x1a⟧ ⟹ eval i (Imp' (Con' (Pro ''p'') (Neg' (Pro ''p''))) (Pro ''q'')) = Det True› 2. ‹⋀(x1::bool) x2::nat. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''p'' = Det x1; i ''q'' = Indet x2⟧ ⟹ eval i (Imp' (Con' (Pro ''p'') (Neg' (Pro ''p''))) (Pro ''q'')) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''q''") (*goals: 1. ‹⋀(x2::nat) x1::bool. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''p'' = Indet x2; i ''q'' = Det x1⟧ ⟹ eval i (Imp' (Con' (Pro ''p'') (Neg' (Pro ''p''))) (Pro ''q'')) = Det True› 2. ‹⋀(x2::nat) x2a::nat. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''p'' = Indet x2; i ''q'' = Indet x2a⟧ ⟹ eval i (Imp' (Con' (Pro ''p'') (Neg' (Pro ''p''))) (Pro ''q'')) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) . qed lemma explosion_counterexample: "¬ valid_in {1} (Explosion (Pro ''p'') (Pro ''q''))" proof (-) (*goal: ‹¬ valid_in {1} (Imp' (Con' (Pro ''p'') (Neg' (Pro ''p''))) (Pro ''q''))›*) let ?i = "(λs. Indet 1)(''q'' := Det False)" have "range ?i ⊆ domain {1}" unfolding domain_def (*goal: ‹range ((λs. Indet 1)(''q'' := Det False)) ⊆ {Det True, Det False} ∪ Indet ` {1}›*) by (simp add: image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*)) moreover have "eval ?i (Explosion (Pro ''p'') (Pro ''q'')) = Indet 1" by simp moreover have "Indet 1 ≠ Det True" by simp ultimately show "?thesis" (*goal: ‹¬ valid_in {1} (Imp' (Con' (Pro ''p'') (Neg' (Pro ''p''))) (Pro ''q''))›*) unfolding valid_in_def (*goal: ‹¬ (∀i. range i ⊆ domain {1} ⟶ eval i (Imp' (Con' (Pro ''p'') (Neg' (Pro ''p''))) (Pro ''q'')) = Det True)›*) by metis qed theorem explosion_not_valid: "¬ valid (Explosion (Pro ''p'') (Pro ''q''))" using explosion_counterexample (*‹¬ valid_in {1} (Imp' (Con' (Pro ''p'') (Neg' (Pro ''p''))) (Pro ''q''))›*) transfer (*‹¬ valid_in ?U ?p ⟹ ¬ valid ?p›*) by simp proposition "¬ valid (Imp (Con' (Pro ''p'') (Neg' (Pro ''p''))) (Pro ''q''))" using explosion_counterexample (*‹¬ valid_in {1} (Imp' (Con' (Pro ''p'') (Neg' (Pro ''p''))) (Pro ''q''))›*) transfer (*‹¬ valid_in ?U ?p ⟹ ¬ valid ?p›*) eval.simps (*‹eval ?i (Pro ?s) = ?i ?s› ‹eval ?i Truth = Det True› ‹eval ?i (Neg' ?p) = (case eval ?i ?p of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x)› ‹eval ?i (Con' ?p ?q) = (if eval ?i ?p = eval ?i ?q then eval ?i ?p else if eval ?i ?p = Det True then eval ?i ?q else if eval ?i ?q = Det True then eval ?i ?p else Det False)› ‹eval ?i (Eql ?p ?q) = (if eval ?i ?p = eval ?i ?q then Det True else Det False)› ‹eval ?i (Eql' ?p ?q) = (if eval ?i ?p = eval ?i ?q then Det True else case (eval ?i ?p, eval ?i ?q) of (Det True, xa) ⇒ eval ?i ?q | (Det False, Det True) ⇒ eval ?i ?p | (Det False, Det False) ⇒ case eval ?i ?q of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Det False, Indet nat) ⇒ case eval ?i ?q of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Indet nat, Det True) ⇒ eval ?i ?p | (Indet nat, Det False) ⇒ case eval ?i ?p of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Indet nat, Indet nata) ⇒ Det False)›*) tv.simps (*‹(Det ?x1.0 = Det ?y1.0) = (?x1.0 = ?y1.0)› ‹(Indet ?x2.0 = Indet ?y2.0) = (?x2.0 = ?y2.0)› ‹Det ?x1.0 ≠ Indet ?x2.0› ‹Indet ?x2.0 ≠ Det ?x1.0› ‹(case Det ?x1.0 of Det x ⇒ ?f1.0 x | Indet x ⇒ ?f2.0 x) = ?f1.0 ?x1.0› ‹(case Indet ?x2.0 of Det x ⇒ ?f1.0 x | Indet x ⇒ ?f2.0 x) = ?f2.0 ?x2.0› ‹rec_tv ?f1.0 ?f2.0 (Det ?x1.0) = ?f1.0 ?x1.0› ‹rec_tv ?f1.0 ?f2.0 (Indet ?x2.0) = ?f2.0 ?x2.0›*) unfolding valid_in_def (*goal: ‹¬ valid (Imp (Con' (Pro ''p'') (Neg' (Pro ''p''))) (Pro ''q''))›*) proof (-) (*goal: ‹⟦¬ (∀i. range i ⊆ domain {1} ⟶ eval i (Imp' (Con' (Pro ''p'') (Neg' (Pro ''p''))) (Pro ''q'')) = Det True); ⋀U p. ¬ (∀i. range i ⊆ domain U ⟶ eval i p = Det True) ⟹ ¬ valid p; ⋀i s. eval i (Pro s) = i s; ⋀i. eval i Truth = Det True; ⋀i p. eval i (Neg' p) = (case eval i p of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x); ⋀i p q. eval i (Con' p q) = (if eval i p = eval i q then eval i p else if eval i p = Det True then eval i q else if eval i q = Det True then eval i p else Det False); ⋀i p q. eval i (Eql p q) = (if eval i p = eval i q then Det True else Det False); ⋀i p q. eval i (Eql' p q) = (if eval i p = eval i q then Det True else case (eval i p, eval i q) of (Det True, xa) ⇒ eval i q | (Det False, Det True) ⇒ eval i p | (Det False, Det False) ⇒ case eval i q of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Det False, Indet nat) ⇒ case eval i q of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Indet nat, Det True) ⇒ eval i p | (Indet nat, Det False) ⇒ case eval i p of Det True ⇒ Det False | Det False ⇒ Det True | Indet x ⇒ Indet x | (Indet nat, Indet nata) ⇒ Det False); ⋀x1 y1. (Det x1 = Det y1) = (x1 = y1); ⋀x2 y2. (Indet x2 = Indet y2) = (x2 = y2); ⋀x1 x2. Det x1 ≠ Indet x2; ⋀x2 x1. Indet x2 ≠ Det x1; ⋀f1 f2 x1. (case Det x1 of Det x ⇒ f1 x | Indet x ⇒ f2 x) = f1 x1; ⋀f1 f2 x2. (case Indet x2 of Det x ⇒ f1 x | Indet x ⇒ f2 x) = f2 x2; ⋀f1 f2 x1. rec_tv f1 f2 (Det x1) = f1 x1; ⋀f1 f2 x2. rec_tv f1 f2 (Indet x2) = f2 x2⟧ ⟹ ¬ valid (Imp (Con' (Pro ''p'') (Neg' (Pro ''p''))) (Pro ''q''))›*) assume "*": "¬ (∀i. range i ⊆ domain U ⟶ eval i p = Det True) ⟹ ¬ valid p" for U and p (*‹¬ (∀i::char list ⇒ tv. range i ⊆ domain (?U::nat set) ⟶ eval i (?p::fm) = Det True) ⟹ ¬ valid ?p›*) assume "¬ (∀i. range i ⊆ domain {1} ⟶ eval i (Explosion (Pro ''p'') (Pro ''q'')) = Det True)" (*‹¬ (∀i::char list ⇒ tv. range i ⊆ domain {1::nat} ⟶ eval i (Imp' (Con' (Pro ''p'') (Neg' (Pro ''p''))) (Pro ''q'')) = Det True)›*) then obtain i where "**": "range i ⊆ domain {1} ∧ eval i (Explosion (Pro ''p'') (Pro ''q'')) ≠ Det True" (*goal: ‹(⋀i. range i ⊆ domain {1} ∧ eval i (Imp' (Con' (Pro ''p'') (Neg' (Pro ''p''))) (Pro ''q'')) ≠ Det True ⟹ thesis) ⟹ thesis›*) by blast then have "eval i (Con' (Pro ''p'') (Neg' (Pro ''p''))) ≠ eval i (Con' (Con' (Pro ''p'') (Neg' (Pro ''p''))) (Pro ''q''))" by force then show "?thesis" (*goal: ‹¬ valid (Imp (Con' (Pro ''p'') (Neg' (Pro ''p''))) (Pro ''q''))›*) using "*" (*‹¬ (∀i. range i ⊆ domain ?U ⟶ eval i ?p = Det True) ⟹ ¬ valid ?p›*) "**" (*‹range i ⊆ domain {1} ∧ eval i (Imp' (Con' (Pro ''p'') (Neg' (Pro ''p''))) (Pro ''q'')) ≠ Det True›*) by (msorry) qed subsection ‹Example: Contraposition› text ‹ Contraposition is not valid. › abbreviation (input) Contraposition :: "fm ⇒ fm ⇒ fm" where "Contraposition p q ≡ Eql' (Imp' p q) (Imp' (Neg' q) (Neg' p))" proposition "valid_boole (Contraposition (Pro ''p'') (Pro ''q''))" unfolding valid_in_def (*goal: ‹∀i. range i ⊆ domain {} ⟶ eval i (Eql' (Imp' (Pro ''p'') (Pro ''q'')) (Imp' (Neg' (Pro ''q'')) (Neg' (Pro ''p'')))) = Det True›*) apply rule (*goal: ‹∀i::char list ⇒ tv. range i ⊆ domain {} ⟶ eval i (Eql' (Imp' (Pro ''p'') (Pro ''q'')) (Imp' (Neg' (Pro ''q'')) (Neg' (Pro ''p'')))) = Det True›*) proof (rule) (*goal: ‹⋀i. range i ⊆ domain {} ⟹ eval i (Eql' (Imp' (Pro ''p'') (Pro ''q'')) (Imp' (Neg' (Pro ''q'')) (Neg' (Pro ''p'')))) = Det True›*) fix i :: "id ⇒ tv" assume "range i ⊆ domain {}" (*‹range (i::char list ⇒ tv) ⊆ domain {}›*) then have "i ''p'' ∈ {Det True, Det False}" "i ''q'' ∈ {Det True, Det False}" unfolding domain_def (*goals: 1. ‹i ''p'' ∈ {Det True, Det False}› 2. ‹i ''q'' ∈ {Det True, Det False}›*) apply - (*goals: 1. ‹range i ⊆ {Det True, Det False} ∪ Indet ` {} ⟹ i ''p'' ∈ {Det True, Det False}› 2. ‹range i ⊆ {Det True, Det False} ∪ Indet ` {} ⟹ i ''q'' ∈ {Det True, Det False}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . then show "eval i (Contraposition (Pro ''p'') (Pro ''q'')) = Det True" apply (cases "i ''p''") (*goals: 1. ‹⋀x1. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''p'' = Det x1⟧ ⟹ eval i (Eql' (Imp' (Pro ''p'') (Pro ''q'')) (Imp' (Neg' (Pro ''q'')) (Neg' (Pro ''p'')))) = Det True› 2. ‹⋀x2. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''p'' = Indet x2⟧ ⟹ eval i (Eql' (Imp' (Pro ''p'') (Pro ''q'')) (Imp' (Neg' (Pro ''q'')) (Neg' (Pro ''p'')))) = Det True› discuss goal 1*) apply (cases "i ''q''") (*goals: 1. ‹⋀(x1::bool) x1a::bool. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''p'' = Det x1; i ''q'' = Det x1a⟧ ⟹ eval i (Eql' (Imp' (Pro ''p'') (Pro ''q'')) (Imp' (Neg' (Pro ''q'')) (Neg' (Pro ''p'')))) = Det True› 2. ‹⋀(x1::bool) x2::nat. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''p'' = Det x1; i ''q'' = Indet x2⟧ ⟹ eval i (Eql' (Imp' (Pro ''p'') (Pro ''q'')) (Imp' (Neg' (Pro ''q'')) (Neg' (Pro ''p'')))) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''q''") (*goals: 1. ‹⋀x2 x1. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''p'' = Indet x2; i ''q'' = Det x1⟧ ⟹ eval i (Eql' (Imp' (Pro ''p'') (Pro ''q'')) (Imp' (Neg' (Pro ''q'')) (Neg' (Pro ''p'')))) = Det True› 2. ‹⋀x2 x2a. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''p'' = Indet x2; i ''q'' = Indet x2a⟧ ⟹ eval i (Eql' (Imp' (Pro ''p'') (Pro ''q'')) (Imp' (Neg' (Pro ''q'')) (Neg' (Pro ''p'')))) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) . qed proposition "valid_in {1} (Contraposition (Pro ''p'') (Pro ''q''))" unfolding valid_in_def (*goal: ‹∀i::char list ⇒ tv. range i ⊆ domain {1::nat} ⟶ eval i (Eql' (Imp' (Pro ''p'') (Pro ''q'')) (Imp' (Neg' (Pro ''q'')) (Neg' (Pro ''p'')))) = Det True›*) apply rule (*goal: ‹∀i. range i ⊆ domain {1} ⟶ eval i (Eql' (Imp' (Pro ''p'') (Pro ''q'')) (Imp' (Neg' (Pro ''q'')) (Neg' (Pro ''p'')))) = Det True›*) proof (rule) (*goal: ‹⋀i. range i ⊆ domain {1} ⟹ eval i (Eql' (Imp' (Pro ''p'') (Pro ''q'')) (Imp' (Neg' (Pro ''q'')) (Neg' (Pro ''p'')))) = Det True›*) fix i :: "id ⇒ tv" assume "range i ⊆ domain {1}" (*‹range (i::char list ⇒ tv) ⊆ domain {1::nat}›*) then have "i ''p'' ∈ {Det True, Det False, Indet 1}" "i ''q'' ∈ {Det True, Det False, Indet 1}" unfolding domain_def (*goals: 1. ‹i ''p'' ∈ {Det True, Det False, Indet 1}› 2. ‹i ''q'' ∈ {Det True, Det False, Indet 1}›*) apply - (*goals: 1. ‹range i ⊆ {Det True, Det False} ∪ Indet ` {1} ⟹ i ''p'' ∈ {Det True, Det False, Indet 1}› 2. ‹range i ⊆ {Det True, Det False} ∪ Indet ` {1} ⟹ i ''q'' ∈ {Det True, Det False, Indet 1}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . then show "eval i (Contraposition (Pro ''p'') (Pro ''q'')) = Det True" apply (cases "i ''p''") (*goals: 1. ‹⋀x1. ⟦i ''p'' ∈ {Det True, Det False, Indet 1}; i ''q'' ∈ {Det True, Det False, Indet 1}; i ''p'' = Det x1⟧ ⟹ eval i (Eql' (Imp' (Pro ''p'') (Pro ''q'')) (Imp' (Neg' (Pro ''q'')) (Neg' (Pro ''p'')))) = Det True› 2. ‹⋀x2. ⟦i ''p'' ∈ {Det True, Det False, Indet 1}; i ''q'' ∈ {Det True, Det False, Indet 1}; i ''p'' = Indet x2⟧ ⟹ eval i (Eql' (Imp' (Pro ''p'') (Pro ''q'')) (Imp' (Neg' (Pro ''q'')) (Neg' (Pro ''p'')))) = Det True› discuss goal 1*) apply (cases "i ''q''") (*goals: 1. ‹⋀x1 x1a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1}; i ''q'' ∈ {Det True, Det False, Indet 1}; i ''p'' = Det x1; i ''q'' = Det x1a⟧ ⟹ eval i (Eql' (Imp' (Pro ''p'') (Pro ''q'')) (Imp' (Neg' (Pro ''q'')) (Neg' (Pro ''p'')))) = Det True› 2. ‹⋀x1 x2. ⟦i ''p'' ∈ {Det True, Det False, Indet 1}; i ''q'' ∈ {Det True, Det False, Indet 1}; i ''p'' = Det x1; i ''q'' = Indet x2⟧ ⟹ eval i (Eql' (Imp' (Pro ''p'') (Pro ''q'')) (Imp' (Neg' (Pro ''q'')) (Neg' (Pro ''p'')))) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''q''") (*goals: 1. ‹⋀x2 x1. ⟦i ''p'' ∈ {Det True, Det False, Indet 1}; i ''q'' ∈ {Det True, Det False, Indet 1}; i ''p'' = Indet x2; i ''q'' = Det x1⟧ ⟹ eval i (Eql' (Imp' (Pro ''p'') (Pro ''q'')) (Imp' (Neg' (Pro ''q'')) (Neg' (Pro ''p'')))) = Det True› 2. ‹⋀x2 x2a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1}; i ''q'' ∈ {Det True, Det False, Indet 1}; i ''p'' = Indet x2; i ''q'' = Indet x2a⟧ ⟹ eval i (Eql' (Imp' (Pro ''p'') (Pro ''q'')) (Imp' (Neg' (Pro ''q'')) (Neg' (Pro ''p'')))) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) . qed lemma contraposition_counterexample: "¬ valid_in {1, 2} (Contraposition (Pro ''p'') (Pro ''q''))" proof (-) (*goal: ‹¬ valid_in {1::nat, 2::nat} (Eql' (Imp' (Pro ''p'') (Pro ''q'')) (Imp' (Neg' (Pro ''q'')) (Neg' (Pro ''p''))))›*) let ?i = "(λs. Indet 1)(''q'' := Indet 2)" have "range ?i ⊆ domain {1, 2}" unfolding domain_def (*goal: ‹range ((λs. Indet 1)(''q'' := Indet 2)) ⊆ {Det True, Det False} ∪ Indet ` {1, 2}›*) by (simp add: image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*)) moreover have "eval ?i (Contraposition (Pro ''p'') (Pro ''q'')) = Det False" by simp moreover have "Det False ≠ Det True" by simp ultimately show "?thesis" (*goal: ‹¬ valid_in {1, 2} (Eql' (Imp' (Pro ''p'') (Pro ''q'')) (Imp' (Neg' (Pro ''q'')) (Neg' (Pro ''p''))))›*) unfolding valid_in_def (*goal: ‹¬ (∀i. range i ⊆ domain {1, 2} ⟶ eval i (Eql' (Imp' (Pro ''p'') (Pro ''q'')) (Imp' (Neg' (Pro ''q'')) (Neg' (Pro ''p'')))) = Det True)›*) by metis qed theorem contraposition_not_valid: "¬ valid (Contraposition (Pro ''p'') (Pro ''q''))" using contraposition_counterexample (*‹¬ valid_in {1, 2} (Eql' (Imp' (Pro ''p'') (Pro ''q'')) (Imp' (Neg' (Pro ''q'')) (Neg' (Pro ''p''))))›*) transfer (*‹¬ valid_in ?U ?p ⟹ ¬ valid ?p›*) by simp subsection ‹More Than Four Truth Values Needed› text ‹ Cla3 is valid for two indeterminate truth values but not for three indeterminate truth values. › lemma ranges: assumes "range i ⊆ domain U" shows "eval i p ∈ domain U" using assms (*‹range i ⊆ domain U›*) unfolding domain_def (*goal: ‹eval i p ∈ {Det True, Det False} ∪ Indet ` U›*) apply (induct p) (*goals: 1. ‹⋀x. range i ⊆ {Det True, Det False} ∪ Indet ` U ⟹ eval i (Pro x) ∈ {Det True, Det False} ∪ Indet ` U› 2. ‹range i ⊆ {Det True, Det False} ∪ Indet ` U ⟹ eval i Truth ∈ {Det True, Det False} ∪ Indet ` U› 3. ‹⋀p. ⟦range i ⊆ {Det True, Det False} ∪ Indet ` U ⟹ eval i p ∈ {Det True, Det False} ∪ Indet ` U; range i ⊆ {Det True, Det False} ∪ Indet ` U⟧ ⟹ eval i (Neg' p) ∈ {Det True, Det False} ∪ Indet ` U› 4. ‹⋀p1 p2. ⟦range i ⊆ {Det True, Det False} ∪ Indet ` U ⟹ eval i p1 ∈ {Det True, Det False} ∪ Indet ` U; range i ⊆ {Det True, Det False} ∪ Indet ` U ⟹ eval i p2 ∈ {Det True, Det False} ∪ Indet ` U; range i ⊆ {Det True, Det False} ∪ Indet ` U⟧ ⟹ eval i (Con' p1 p2) ∈ {Det True, Det False} ∪ Indet ` U› 5. ‹⋀p1 p2. ⟦range i ⊆ {Det True, Det False} ∪ Indet ` U ⟹ eval i p1 ∈ {Det True, Det False} ∪ Indet ` U; range i ⊆ {Det True, Det False} ∪ Indet ` U ⟹ eval i p2 ∈ {Det True, Det False} ∪ Indet ` U; range i ⊆ {Det True, Det False} ∪ Indet ` U⟧ ⟹ eval i (Eql p1 p2) ∈ {Det True, Det False} ∪ Indet ` U› 6. ‹⋀p1 p2. ⟦range i ⊆ {Det True, Det False} ∪ Indet ` U ⟹ eval i p1 ∈ {Det True, Det False} ∪ Indet ` U; range i ⊆ {Det True, Det False} ∪ Indet ` U ⟹ eval i p2 ∈ {Det True, Det False} ∪ Indet ` U; range i ⊆ {Det True, Det False} ∪ Indet ` U⟧ ⟹ eval i (Eql' p1 p2) ∈ {Det True, Det False} ∪ Indet ` U› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*proven 6 subgoals*) . proposition (* Cla Truth Table *) "unary (Cla (Pro ''p'')) [Det True, Det False, Indet 1] = '' * * o ''" by code_simp proposition "valid_boole (Cla p)" unfolding valid_in_def (*goal: ‹∀i. range i ⊆ domain {} ⟶ eval i (Cla p) = Det True›*) apply rule (*goal: ‹∀i::char list ⇒ tv. range i ⊆ domain {} ⟶ eval i (Cla (p::fm)) = Det True›*) proof (rule) (*goal: ‹⋀i. range i ⊆ domain {} ⟹ eval i (Cla p) = Det True›*) fix i :: "id ⇒ tv" assume "range i ⊆ domain {}" (*‹range (i::char list ⇒ tv) ⊆ domain {}›*) then have "eval i p ∈ {Det True, Det False}" using ranges[of i "{}"] (*‹range i ⊆ domain {} ⟹ eval i ?p ∈ domain {}›*) unfolding domain_def (*goal: ‹eval i p ∈ {Det True, Det False}›*) by auto then show "eval i (Cla p) = Det True" apply (cases "eval i p") (*goals: 1. ‹⋀x1::bool. ⟦eval (i::char list ⇒ tv) (p::fm) ∈ {Det True, Det False}; eval i p = Det x1⟧ ⟹ eval i (Cla p) = Det True› 2. ‹⋀x2::nat. ⟦eval (i::char list ⇒ tv) (p::fm) ∈ {Det True, Det False}; eval i p = Indet x2⟧ ⟹ eval i (Cla p) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . qed proposition "¬ valid_in {1} (Cla (Pro ''p''))" proof (-) (*goal: ‹¬ valid_in {1} (Cla (Pro ''p''))›*) let ?i = "λs. Indet 1" have "range ?i ⊆ domain {1}" unfolding domain_def (*goal: ‹range (λs. Indet 1) ⊆ {Det True, Det False} ∪ Indet ` {1}›*) by (simp add: image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*)) moreover have "eval ?i (Cla (Pro ''p'')) = Det False" by simp moreover have "Det False ≠ Det True" by simp ultimately show "?thesis" (*goal: ‹¬ valid_in {1} (Cla (Pro ''p''))›*) unfolding valid_in_def (*goal: ‹¬ (∀i. range i ⊆ domain {1} ⟶ eval i (Cla (Pro ''p'')) = Det True)›*) by metis qed abbreviation (input) Cla2 :: "fm ⇒ fm ⇒ fm" where "Cla2 p q ≡ Dis (Dis (Cla p) (Cla q)) (Eql p q)" proposition (* Cla2 Truth Table *) "binary (Cla2 (Pro ''p'') (Pro ''q'')) [Det True, Det False, Indet 1, Indet 2] = '' **** **** ***o **o* ''" by code_simp proposition "valid_boole (Cla2 p q)" unfolding valid_in_def (*goal: ‹∀i. range i ⊆ domain {} ⟶ eval i (Dis (Dis (Cla p) (Cla q)) (Eql p q)) = Det True›*) apply rule (*goal: ‹∀i::char list ⇒ tv. range i ⊆ domain {} ⟶ eval i (Dis (Dis (Cla (p::fm)) (Cla (q::fm))) (Eql p q)) = Det True›*) proof (rule) (*goal: ‹⋀i::char list ⇒ tv. range i ⊆ domain {} ⟹ eval i (Dis (Dis (Cla (p::fm)) (Cla (q::fm))) (Eql p q)) = Det True›*) fix i :: "id ⇒ tv" assume range: "range i ⊆ domain {}" (*‹range (i::char list ⇒ tv) ⊆ domain {}›*) then have "eval i p ∈ {Det True, Det False}" "eval i q ∈ {Det True, Det False}" using ranges[of i "{}"] (*‹range i ⊆ domain {} ⟹ eval i ?p ∈ domain {}›*) unfolding domain_def (*goals: 1. ‹eval (i::char list ⇒ tv) (p::fm) ∈ {Det True, Det False}› 2. ‹eval (i::char list ⇒ tv) (q::fm) ∈ {Det True, Det False}›*) apply - (*goals: 1. ‹⟦range i ⊆ {Det True, Det False} ∪ Indet ` {}; ⋀p. range i ⊆ {Det True, Det False} ∪ Indet ` {} ⟹ eval i p ∈ {Det True, Det False} ∪ Indet ` {}⟧ ⟹ eval i p ∈ {Det True, Det False}› 2. ‹⟦range i ⊆ {Det True, Det False} ∪ Indet ` {}; ⋀p. range i ⊆ {Det True, Det False} ∪ Indet ` {} ⟹ eval i p ∈ {Det True, Det False} ∪ Indet ` {}⟧ ⟹ eval i q ∈ {Det True, Det False}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . then show "eval i (Cla2 p q) = Det True" apply (cases "eval i p") (*goals: 1. ‹⋀x1. ⟦eval i p ∈ {Det True, Det False}; eval i q ∈ {Det True, Det False}; eval i p = Det x1⟧ ⟹ eval i (Dis (Dis (Cla p) (Cla q)) (Eql p q)) = Det True› 2. ‹⋀x2. ⟦eval i p ∈ {Det True, Det False}; eval i q ∈ {Det True, Det False}; eval i p = Indet x2⟧ ⟹ eval i (Dis (Dis (Cla p) (Cla q)) (Eql p q)) = Det True› discuss goal 1*) apply (cases "eval i q") (*goals: 1. ‹⋀x1 x1a. ⟦eval i p ∈ {Det True, Det False}; eval i q ∈ {Det True, Det False}; eval i p = Det x1; eval i q = Det x1a⟧ ⟹ eval i (Dis (Dis (Cla p) (Cla q)) (Eql p q)) = Det True› 2. ‹⋀x1 x2. ⟦eval i p ∈ {Det True, Det False}; eval i q ∈ {Det True, Det False}; eval i p = Det x1; eval i q = Indet x2⟧ ⟹ eval i (Dis (Dis (Cla p) (Cla q)) (Eql p q)) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "eval i q") (*goals: 1. ‹⋀x2 x1. ⟦eval i p ∈ {Det True, Det False}; eval i q ∈ {Det True, Det False}; eval i p = Indet x2; eval i q = Det x1⟧ ⟹ eval i (Dis (Dis (Cla p) (Cla q)) (Eql p q)) = Det True› 2. ‹⋀x2 x2a. ⟦eval i p ∈ {Det True, Det False}; eval i q ∈ {Det True, Det False}; eval i p = Indet x2; eval i q = Indet x2a⟧ ⟹ eval i (Dis (Dis (Cla p) (Cla q)) (Eql p q)) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) . qed proposition "valid_in {1} (Cla2 p q)" unfolding valid_in_def (*goal: ‹∀i. range i ⊆ domain {1} ⟶ eval i (Dis (Dis (Cla p) (Cla q)) (Eql p q)) = Det True›*) apply rule (*goal: ‹∀i. range i ⊆ domain {1} ⟶ eval i (Dis (Dis (Cla p) (Cla q)) (Eql p q)) = Det True›*) proof (rule) (*goal: ‹⋀i. range i ⊆ domain {1} ⟹ eval i (Dis (Dis (Cla p) (Cla q)) (Eql p q)) = Det True›*) fix i :: "id ⇒ tv" assume range: "range i ⊆ domain {1}" (*‹range (i::char list ⇒ tv) ⊆ domain {1::nat}›*) then have "eval i p ∈ {Det True, Det False, Indet 1}" "eval i q ∈ {Det True, Det False, Indet 1}" using ranges[of i "{1}"] (*‹range i ⊆ domain {1} ⟹ eval i ?p ∈ domain {1}›*) unfolding domain_def (*goals: 1. ‹eval i p ∈ {Det True, Det False, Indet 1}› 2. ‹eval i q ∈ {Det True, Det False, Indet 1}›*) apply - (*goals: 1. ‹⟦range (i::char list ⇒ tv) ⊆ {Det True, Det False} ∪ Indet ` {1::nat}; ⋀p::fm. range i ⊆ {Det True, Det False} ∪ Indet ` {1::nat} ⟹ eval i p ∈ {Det True, Det False} ∪ Indet ` {1::nat}⟧ ⟹ eval i (p::fm) ∈ {Det True, Det False, Indet (1::nat)}› 2. ‹⟦range (i::char list ⇒ tv) ⊆ {Det True, Det False} ∪ Indet ` {1::nat}; ⋀p::fm. range i ⊆ {Det True, Det False} ∪ Indet ` {1::nat} ⟹ eval i p ∈ {Det True, Det False} ∪ Indet ` {1::nat}⟧ ⟹ eval i (q::fm) ∈ {Det True, Det False, Indet (1::nat)}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . then show "eval i (Cla2 p q) = Det True" apply (cases "eval i p") (*goals: 1. ‹⋀x1. ⟦eval i p ∈ {Det True, Det False, Indet 1}; eval i q ∈ {Det True, Det False, Indet 1}; eval i p = Det x1⟧ ⟹ eval i (Dis (Dis (Cla p) (Cla q)) (Eql p q)) = Det True› 2. ‹⋀x2. ⟦eval i p ∈ {Det True, Det False, Indet 1}; eval i q ∈ {Det True, Det False, Indet 1}; eval i p = Indet x2⟧ ⟹ eval i (Dis (Dis (Cla p) (Cla q)) (Eql p q)) = Det True› discuss goal 1*) apply (cases "eval i q") (*goals: 1. ‹⋀x1 x1a. ⟦eval i p ∈ {Det True, Det False, Indet 1}; eval i q ∈ {Det True, Det False, Indet 1}; eval i p = Det x1; eval i q = Det x1a⟧ ⟹ eval i (Dis (Dis (Cla p) (Cla q)) (Eql p q)) = Det True› 2. ‹⋀x1 x2. ⟦eval i p ∈ {Det True, Det False, Indet 1}; eval i q ∈ {Det True, Det False, Indet 1}; eval i p = Det x1; eval i q = Indet x2⟧ ⟹ eval i (Dis (Dis (Cla p) (Cla q)) (Eql p q)) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "eval i q") (*goals: 1. ‹⋀x2 x1. ⟦eval i p ∈ {Det True, Det False, Indet 1}; eval i q ∈ {Det True, Det False, Indet 1}; eval i p = Indet x2; eval i q = Det x1⟧ ⟹ eval i (Dis (Dis (Cla p) (Cla q)) (Eql p q)) = Det True› 2. ‹⋀x2 x2a. ⟦eval i p ∈ {Det True, Det False, Indet 1}; eval i q ∈ {Det True, Det False, Indet 1}; eval i p = Indet x2; eval i q = Indet x2a⟧ ⟹ eval i (Dis (Dis (Cla p) (Cla q)) (Eql p q)) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) . qed proposition "¬ valid_in {1, 2} (Cla2 (Pro ''p'') (Pro ''q''))" proof (-) (*goal: ‹¬ valid_in {1, 2} (Dis (Dis (Cla (Pro ''p'')) (Cla (Pro ''q''))) (Eql (Pro ''p'') (Pro ''q'')))›*) let ?i = "(λs. Indet 1)(''q'' := Indet 2)" have "range ?i ⊆ domain {1, 2}" unfolding domain_def (*goal: ‹range ((λs. Indet 1)(''q'' := Indet 2)) ⊆ {Det True, Det False} ∪ Indet ` {1, 2}›*) by (simp add: image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*)) moreover have "eval ?i (Cla2 (Pro ''p'') (Pro ''q'')) = Det False" by simp moreover have "Det False ≠ Det True" by simp ultimately show "?thesis" (*goal: ‹¬ valid_in {1, 2} (Dis (Dis (Cla (Pro ''p'')) (Cla (Pro ''q''))) (Eql (Pro ''p'') (Pro ''q'')))›*) unfolding valid_in_def (*goal: ‹¬ (∀i. range i ⊆ domain {1, 2} ⟶ eval i (Dis (Dis (Cla (Pro ''p'')) (Cla (Pro ''q''))) (Eql (Pro ''p'') (Pro ''q''))) = Det True)›*) by metis qed abbreviation (input) Cla3 :: "fm ⇒ fm ⇒ fm ⇒ fm" where "Cla3 p q r ≡ Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))" proposition "valid_boole (Cla3 p q r)" unfolding valid_in_def (*goal: ‹∀i. range i ⊆ domain {} ⟶ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True›*) apply rule (*goal: ‹∀i. range i ⊆ domain {} ⟶ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True›*) proof (rule) (*goal: ‹⋀i::char list ⇒ tv. range i ⊆ domain {} ⟹ eval i (Dis (Dis (Cla (p::fm)) (Dis (Cla (q::fm)) (Cla (r::fm)))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True›*) fix i :: "id ⇒ tv" assume "range i ⊆ domain {}" (*‹range (i::char list ⇒ tv) ⊆ domain {}›*) then have "eval i p ∈ {Det True, Det False}" "eval i q ∈ {Det True, Det False}" "eval i r ∈ {Det True, Det False}" using ranges[of i "{}"] (*‹range (i::char list ⇒ tv) ⊆ domain {} ⟹ eval i (?p::fm) ∈ domain {}›*) unfolding domain_def (*goals: 1. ‹eval (i::char list ⇒ tv) (p::fm) ∈ {Det True, Det False}› 2. ‹eval (i::char list ⇒ tv) (q::fm) ∈ {Det True, Det False}› 3. ‹eval (i::char list ⇒ tv) (r::fm) ∈ {Det True, Det False}›*) apply - (*goals: 1. ‹⟦range i ⊆ {Det True, Det False} ∪ Indet ` {}; ⋀p. range i ⊆ {Det True, Det False} ∪ Indet ` {} ⟹ eval i p ∈ {Det True, Det False} ∪ Indet ` {}⟧ ⟹ eval i p ∈ {Det True, Det False}› 2. ‹⟦range i ⊆ {Det True, Det False} ∪ Indet ` {}; ⋀p. range i ⊆ {Det True, Det False} ∪ Indet ` {} ⟹ eval i p ∈ {Det True, Det False} ∪ Indet ` {}⟧ ⟹ eval i q ∈ {Det True, Det False}› 3. ‹⟦range i ⊆ {Det True, Det False} ∪ Indet ` {}; ⋀p. range i ⊆ {Det True, Det False} ∪ Indet ` {} ⟹ eval i p ∈ {Det True, Det False} ∪ Indet ` {}⟧ ⟹ eval i r ∈ {Det True, Det False}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . then show "eval i (Cla3 p q r) = Det True" apply (cases "eval i p") (*goals: 1. ‹⋀x1. ⟦eval i p ∈ {Det True, Det False}; eval i q ∈ {Det True, Det False}; eval i r ∈ {Det True, Det False}; eval i p = Det x1⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› 2. ‹⋀x2. ⟦eval i p ∈ {Det True, Det False}; eval i q ∈ {Det True, Det False}; eval i r ∈ {Det True, Det False}; eval i p = Indet x2⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› discuss goal 1*) apply (cases "eval i q") (*goals: 1. ‹⋀x1 x1a. ⟦eval i p ∈ {Det True, Det False}; eval i q ∈ {Det True, Det False}; eval i r ∈ {Det True, Det False}; eval i p = Det x1; eval i q = Det x1a⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› 2. ‹⋀x1 x2. ⟦eval i p ∈ {Det True, Det False}; eval i q ∈ {Det True, Det False}; eval i r ∈ {Det True, Det False}; eval i p = Det x1; eval i q = Indet x2⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› discuss goal 1*) apply (cases "eval i r") (*goals: 1. ‹⋀x1 x1a x1b. ⟦eval i p ∈ {Det True, Det False}; eval i q ∈ {Det True, Det False}; eval i r ∈ {Det True, Det False}; eval i p = Det x1; eval i q = Det x1a; eval i r = Det x1b⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› 2. ‹⋀x1 x1a x2. ⟦eval i p ∈ {Det True, Det False}; eval i q ∈ {Det True, Det False}; eval i r ∈ {Det True, Det False}; eval i p = Det x1; eval i q = Det x1a; eval i r = Indet x2⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "eval i r") (*goals: 1. ‹⋀x1 x2 x1a. ⟦eval i p ∈ {Det True, Det False}; eval i q ∈ {Det True, Det False}; eval i r ∈ {Det True, Det False}; eval i p = Det x1; eval i q = Indet x2; eval i r = Det x1a⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› 2. ‹⋀x1 x2 x2a. ⟦eval i p ∈ {Det True, Det False}; eval i q ∈ {Det True, Det False}; eval i r ∈ {Det True, Det False}; eval i p = Det x1; eval i q = Indet x2; eval i r = Indet x2a⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "eval i q") (*goals: 1. ‹⋀x2 x1. ⟦eval i p ∈ {Det True, Det False}; eval i q ∈ {Det True, Det False}; eval i r ∈ {Det True, Det False}; eval i p = Indet x2; eval i q = Det x1⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› 2. ‹⋀x2 x2a. ⟦eval i p ∈ {Det True, Det False}; eval i q ∈ {Det True, Det False}; eval i r ∈ {Det True, Det False}; eval i p = Indet x2; eval i q = Indet x2a⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› discuss goal 1*) apply (cases "eval i r") (*goals: 1. ‹⋀x2 x1 x1a. ⟦eval i p ∈ {Det True, Det False}; eval i q ∈ {Det True, Det False}; eval i r ∈ {Det True, Det False}; eval i p = Indet x2; eval i q = Det x1; eval i r = Det x1a⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› 2. ‹⋀x2 x1 x2a. ⟦eval i p ∈ {Det True, Det False}; eval i q ∈ {Det True, Det False}; eval i r ∈ {Det True, Det False}; eval i p = Indet x2; eval i q = Det x1; eval i r = Indet x2a⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "eval i r") (*goals: 1. ‹⋀x2 x2a x1. ⟦eval i p ∈ {Det True, Det False}; eval i q ∈ {Det True, Det False}; eval i r ∈ {Det True, Det False}; eval i p = Indet x2; eval i q = Indet x2a; eval i r = Det x1⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› 2. ‹⋀x2 x2a x2b. ⟦eval i p ∈ {Det True, Det False}; eval i q ∈ {Det True, Det False}; eval i r ∈ {Det True, Det False}; eval i p = Indet x2; eval i q = Indet x2a; eval i r = Indet x2b⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . qed proposition "valid_in {1} (Cla3 p q r)" unfolding valid_in_def (*goal: ‹∀i. range i ⊆ domain {1} ⟶ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True›*) apply rule (*goal: ‹∀i::char list ⇒ tv. range i ⊆ domain {1::nat} ⟶ eval i (Dis (Dis (Cla (p::fm)) (Dis (Cla (q::fm)) (Cla (r::fm)))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True›*) proof (rule) (*goal: ‹⋀i. range i ⊆ domain {1} ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True›*) fix i :: "id ⇒ tv" assume "range i ⊆ domain {1}" (*‹range (i::char list ⇒ tv) ⊆ domain {1::nat}›*) then have "eval i p ∈ {Det True, Det False, Indet 1}" "eval i q ∈ {Det True, Det False, Indet 1}" "eval i r ∈ {Det True, Det False, Indet 1}" using ranges[of i "{1}"] (*‹range (i::char list ⇒ tv) ⊆ domain {1::nat} ⟹ eval i (?p::fm) ∈ domain {1::nat}›*) unfolding domain_def (*goals: 1. ‹eval i p ∈ {Det True, Det False, Indet 1}› 2. ‹eval i q ∈ {Det True, Det False, Indet 1}› 3. ‹eval i r ∈ {Det True, Det False, Indet 1}›*) apply - (*goals: 1. ‹⟦range i ⊆ {Det True, Det False} ∪ Indet ` {1}; ⋀p. range i ⊆ {Det True, Det False} ∪ Indet ` {1} ⟹ eval i p ∈ {Det True, Det False} ∪ Indet ` {1}⟧ ⟹ eval i p ∈ {Det True, Det False, Indet 1}› 2. ‹⟦range i ⊆ {Det True, Det False} ∪ Indet ` {1}; ⋀p. range i ⊆ {Det True, Det False} ∪ Indet ` {1} ⟹ eval i p ∈ {Det True, Det False} ∪ Indet ` {1}⟧ ⟹ eval i q ∈ {Det True, Det False, Indet 1}› 3. ‹⟦range i ⊆ {Det True, Det False} ∪ Indet ` {1}; ⋀p. range i ⊆ {Det True, Det False} ∪ Indet ` {1} ⟹ eval i p ∈ {Det True, Det False} ∪ Indet ` {1}⟧ ⟹ eval i r ∈ {Det True, Det False, Indet 1}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . then show "eval i (Cla3 p q r) = Det True" apply (cases "eval i p") (*goals: 1. ‹⋀x1. ⟦eval i p ∈ {Det True, Det False, Indet 1}; eval i q ∈ {Det True, Det False, Indet 1}; eval i r ∈ {Det True, Det False, Indet 1}; eval i p = Det x1⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› 2. ‹⋀x2. ⟦eval i p ∈ {Det True, Det False, Indet 1}; eval i q ∈ {Det True, Det False, Indet 1}; eval i r ∈ {Det True, Det False, Indet 1}; eval i p = Indet x2⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› discuss goal 1*) apply (cases "eval i q") (*goals: 1. ‹⋀x1 x1a. ⟦eval i p ∈ {Det True, Det False, Indet 1}; eval i q ∈ {Det True, Det False, Indet 1}; eval i r ∈ {Det True, Det False, Indet 1}; eval i p = Det x1; eval i q = Det x1a⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› 2. ‹⋀x1 x2. ⟦eval i p ∈ {Det True, Det False, Indet 1}; eval i q ∈ {Det True, Det False, Indet 1}; eval i r ∈ {Det True, Det False, Indet 1}; eval i p = Det x1; eval i q = Indet x2⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› discuss goal 1*) apply (cases "eval i r") (*goals: 1. ‹⋀x1 x1a x1b. ⟦eval i p ∈ {Det True, Det False, Indet 1}; eval i q ∈ {Det True, Det False, Indet 1}; eval i r ∈ {Det True, Det False, Indet 1}; eval i p = Det x1; eval i q = Det x1a; eval i r = Det x1b⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› 2. ‹⋀x1 x1a x2. ⟦eval i p ∈ {Det True, Det False, Indet 1}; eval i q ∈ {Det True, Det False, Indet 1}; eval i r ∈ {Det True, Det False, Indet 1}; eval i p = Det x1; eval i q = Det x1a; eval i r = Indet x2⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "eval i r") (*goals: 1. ‹⋀(x1::bool) (x2::nat) x1a::bool. ⟦eval (i::char list ⇒ tv) (p::fm) ∈ {Det True, Det False, Indet (1::nat)}; eval i (q::fm) ∈ {Det True, Det False, Indet (1::nat)}; eval i (r::fm) ∈ {Det True, Det False, Indet (1::nat)}; eval i p = Det x1; eval i q = Indet x2; eval i r = Det x1a⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› 2. ‹⋀(x1::bool) (x2::nat) x2a::nat. ⟦eval (i::char list ⇒ tv) (p::fm) ∈ {Det True, Det False, Indet (1::nat)}; eval i (q::fm) ∈ {Det True, Det False, Indet (1::nat)}; eval i (r::fm) ∈ {Det True, Det False, Indet (1::nat)}; eval i p = Det x1; eval i q = Indet x2; eval i r = Indet x2a⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "eval i q") (*goals: 1. ‹⋀(x2::nat) x1::bool. ⟦eval (i::char list ⇒ tv) (p::fm) ∈ {Det True, Det False, Indet (1::nat)}; eval i (q::fm) ∈ {Det True, Det False, Indet (1::nat)}; eval i (r::fm) ∈ {Det True, Det False, Indet (1::nat)}; eval i p = Indet x2; eval i q = Det x1⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› 2. ‹⋀(x2::nat) x2a::nat. ⟦eval (i::char list ⇒ tv) (p::fm) ∈ {Det True, Det False, Indet (1::nat)}; eval i (q::fm) ∈ {Det True, Det False, Indet (1::nat)}; eval i (r::fm) ∈ {Det True, Det False, Indet (1::nat)}; eval i p = Indet x2; eval i q = Indet x2a⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› discuss goal 1*) apply (cases "eval i r") (*goals: 1. ‹⋀x2 x1 x1a. ⟦eval i p ∈ {Det True, Det False, Indet 1}; eval i q ∈ {Det True, Det False, Indet 1}; eval i r ∈ {Det True, Det False, Indet 1}; eval i p = Indet x2; eval i q = Det x1; eval i r = Det x1a⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› 2. ‹⋀x2 x1 x2a. ⟦eval i p ∈ {Det True, Det False, Indet 1}; eval i q ∈ {Det True, Det False, Indet 1}; eval i r ∈ {Det True, Det False, Indet 1}; eval i p = Indet x2; eval i q = Det x1; eval i r = Indet x2a⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "eval i r") (*goals: 1. ‹⋀x2 x2a x1. ⟦eval i p ∈ {Det True, Det False, Indet 1}; eval i q ∈ {Det True, Det False, Indet 1}; eval i r ∈ {Det True, Det False, Indet 1}; eval i p = Indet x2; eval i q = Indet x2a; eval i r = Det x1⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› 2. ‹⋀x2 x2a x2b. ⟦eval i p ∈ {Det True, Det False, Indet 1}; eval i q ∈ {Det True, Det False, Indet 1}; eval i r ∈ {Det True, Det False, Indet 1}; eval i p = Indet x2; eval i q = Indet x2a; eval i r = Indet x2b⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . qed proposition "valid_in {1, 2} (Cla3 p q r)" unfolding valid_in_def (*goal: ‹∀i. range i ⊆ domain {1, 2} ⟶ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True›*) apply rule (*goal: ‹∀i. range i ⊆ domain {1, 2} ⟶ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True›*) proof (rule) (*goal: ‹⋀i::char list ⇒ tv. range i ⊆ domain {1::nat, 2::nat} ⟹ eval i (Dis (Dis (Cla (p::fm)) (Dis (Cla (q::fm)) (Cla (r::fm)))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True›*) fix i :: "id ⇒ tv" assume "range i ⊆ domain {1, 2}" (*‹range (i::char list ⇒ tv) ⊆ domain {1::nat, 2::nat}›*) then have "eval i p ∈ {Det True, Det False, Indet 1, Indet 2}" "eval i q ∈ {Det True, Det False, Indet 1, Indet 2}" "eval i r ∈ {Det True, Det False, Indet 1, Indet 2}" using ranges[of i "{1, 2}"] (*‹range i ⊆ domain {1, 2} ⟹ eval i ?p ∈ domain {1, 2}›*) unfolding domain_def (*goals: 1. ‹eval i p ∈ {Det True, Det False, Indet 1, Indet 2}› 2. ‹eval i q ∈ {Det True, Det False, Indet 1, Indet 2}› 3. ‹eval i r ∈ {Det True, Det False, Indet 1, Indet 2}›*) apply - (*goals: 1. ‹⟦range i ⊆ {Det True, Det False} ∪ Indet ` {1, 2}; ⋀p. range i ⊆ {Det True, Det False} ∪ Indet ` {1, 2} ⟹ eval i p ∈ {Det True, Det False} ∪ Indet ` {1, 2}⟧ ⟹ eval i p ∈ {Det True, Det False, Indet 1, Indet 2}› 2. ‹⟦range i ⊆ {Det True, Det False} ∪ Indet ` {1, 2}; ⋀p. range i ⊆ {Det True, Det False} ∪ Indet ` {1, 2} ⟹ eval i p ∈ {Det True, Det False} ∪ Indet ` {1, 2}⟧ ⟹ eval i q ∈ {Det True, Det False, Indet 1, Indet 2}› 3. ‹⟦range i ⊆ {Det True, Det False} ∪ Indet ` {1, 2}; ⋀p. range i ⊆ {Det True, Det False} ∪ Indet ` {1, 2} ⟹ eval i p ∈ {Det True, Det False} ∪ Indet ` {1, 2}⟧ ⟹ eval i r ∈ {Det True, Det False, Indet 1, Indet 2}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . then show "eval i (Cla3 p q r) = Det True" apply (cases "eval i p") (*goals: 1. ‹⋀x1. ⟦eval i p ∈ {Det True, Det False, Indet 1, Indet 2}; eval i q ∈ {Det True, Det False, Indet 1, Indet 2}; eval i r ∈ {Det True, Det False, Indet 1, Indet 2}; eval i p = Det x1⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› 2. ‹⋀x2. ⟦eval i p ∈ {Det True, Det False, Indet 1, Indet 2}; eval i q ∈ {Det True, Det False, Indet 1, Indet 2}; eval i r ∈ {Det True, Det False, Indet 1, Indet 2}; eval i p = Indet x2⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› discuss goal 1*) apply (cases "eval i q") (*goals: 1. ‹⋀(x1::bool) x1a::bool. ⟦eval (i::char list ⇒ tv) (p::fm) ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat)}; eval i (q::fm) ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat)}; eval i (r::fm) ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat)}; eval i p = Det x1; eval i q = Det x1a⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› 2. ‹⋀(x1::bool) x2::nat. ⟦eval (i::char list ⇒ tv) (p::fm) ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat)}; eval i (q::fm) ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat)}; eval i (r::fm) ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat)}; eval i p = Det x1; eval i q = Indet x2⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› discuss goal 1*) apply (cases "eval i r") (*goals: 1. ‹⋀x1 x1a x1b. ⟦eval i p ∈ {Det True, Det False, Indet 1, Indet 2}; eval i q ∈ {Det True, Det False, Indet 1, Indet 2}; eval i r ∈ {Det True, Det False, Indet 1, Indet 2}; eval i p = Det x1; eval i q = Det x1a; eval i r = Det x1b⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› 2. ‹⋀x1 x1a x2. ⟦eval i p ∈ {Det True, Det False, Indet 1, Indet 2}; eval i q ∈ {Det True, Det False, Indet 1, Indet 2}; eval i r ∈ {Det True, Det False, Indet 1, Indet 2}; eval i p = Det x1; eval i q = Det x1a; eval i r = Indet x2⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "eval i r") (*goals: 1. ‹⋀(x1::bool) (x2::nat) x1a::bool. ⟦eval (i::char list ⇒ tv) (p::fm) ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat)}; eval i (q::fm) ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat)}; eval i (r::fm) ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat)}; eval i p = Det x1; eval i q = Indet x2; eval i r = Det x1a⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› 2. ‹⋀(x1::bool) (x2::nat) x2a::nat. ⟦eval (i::char list ⇒ tv) (p::fm) ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat)}; eval i (q::fm) ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat)}; eval i (r::fm) ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat)}; eval i p = Det x1; eval i q = Indet x2; eval i r = Indet x2a⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "eval i q") (*goals: 1. ‹⋀x2 x1. ⟦eval i p ∈ {Det True, Det False, Indet 1, Indet 2}; eval i q ∈ {Det True, Det False, Indet 1, Indet 2}; eval i r ∈ {Det True, Det False, Indet 1, Indet 2}; eval i p = Indet x2; eval i q = Det x1⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› 2. ‹⋀x2 x2a. ⟦eval i p ∈ {Det True, Det False, Indet 1, Indet 2}; eval i q ∈ {Det True, Det False, Indet 1, Indet 2}; eval i r ∈ {Det True, Det False, Indet 1, Indet 2}; eval i p = Indet x2; eval i q = Indet x2a⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› discuss goal 1*) apply (cases "eval i r") (*goals: 1. ‹⋀x2 x1 x1a. ⟦eval i p ∈ {Det True, Det False, Indet 1, Indet 2}; eval i q ∈ {Det True, Det False, Indet 1, Indet 2}; eval i r ∈ {Det True, Det False, Indet 1, Indet 2}; eval i p = Indet x2; eval i q = Det x1; eval i r = Det x1a⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› 2. ‹⋀x2 x1 x2a. ⟦eval i p ∈ {Det True, Det False, Indet 1, Indet 2}; eval i q ∈ {Det True, Det False, Indet 1, Indet 2}; eval i r ∈ {Det True, Det False, Indet 1, Indet 2}; eval i p = Indet x2; eval i q = Det x1; eval i r = Indet x2a⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "eval i r") (*goals: 1. ‹⋀x2 x2a x1. ⟦eval i p ∈ {Det True, Det False, Indet 1, Indet 2}; eval i q ∈ {Det True, Det False, Indet 1, Indet 2}; eval i r ∈ {Det True, Det False, Indet 1, Indet 2}; eval i p = Indet x2; eval i q = Indet x2a; eval i r = Det x1⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› 2. ‹⋀x2 x2a x2b. ⟦eval i p ∈ {Det True, Det False, Indet 1, Indet 2}; eval i q ∈ {Det True, Det False, Indet 1, Indet 2}; eval i r ∈ {Det True, Det False, Indet 1, Indet 2}; eval i p = Indet x2; eval i q = Indet x2a; eval i r = Indet x2b⟧ ⟹ eval i (Dis (Dis (Cla p) (Dis (Cla q) (Cla r))) (Dis (Eql p q) (Dis (Eql p r) (Eql q r)))) = Det True› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . qed proposition "¬ valid_in {1, 2, 3} (Cla3 (Pro ''p'') (Pro ''q'') (Pro ''r''))" proof (-) (*goal: ‹¬ valid_in {1::nat, 2::nat, 3::nat} (Dis (Dis (Cla (Pro ''p'')) (Dis (Cla (Pro ''q'')) (Cla (Pro ''r'')))) (Dis (Eql (Pro ''p'') (Pro ''q'')) (Dis (Eql (Pro ''p'') (Pro ''r'')) (Eql (Pro ''q'') (Pro ''r'')))))›*) let ?i = "(λs. Indet 1)(''q'' := Indet 2, ''r'' := Indet 3)" have "range ?i ⊆ domain {1, 2, 3}" unfolding domain_def (*goal: ‹range ((λs. Indet 1)(''q'' := Indet 2, ''r'' := Indet 3)) ⊆ {Det True, Det False} ∪ Indet ` {1, 2, 3}›*) by (simp add: image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*)) moreover have "eval ?i (Cla3 (Pro ''p'') (Pro ''q'') (Pro ''r'')) = Det False" by simp moreover have "Det False ≠ Det True" by simp ultimately show "?thesis" (*goal: ‹¬ valid_in {1, 2, 3} (Dis (Dis (Cla (Pro ''p'')) (Dis (Cla (Pro ''q'')) (Cla (Pro ''r'')))) (Dis (Eql (Pro ''p'') (Pro ''q'')) (Dis (Eql (Pro ''p'') (Pro ''r'')) (Eql (Pro ''q'') (Pro ''r'')))))›*) unfolding valid_in_def (*goal: ‹¬ (∀i. range i ⊆ domain {1, 2, 3} ⟶ eval i (Dis (Dis (Cla (Pro ''p'')) (Dis (Cla (Pro ''q'')) (Cla (Pro ''r'')))) (Dis (Eql (Pro ''p'') (Pro ''q'')) (Dis (Eql (Pro ''p'') (Pro ''r'')) (Eql (Pro ''q'') (Pro ''r''))))) = Det True)›*) by metis qed section ‹Further Meta-Theorems› subsection ‹Fundamental Definitions and Lemmas› text ‹ The function props collects the set of propositional symbols occurring in a formula. › fun props :: "fm ⇒ id set" where "props Truth = {}" | "props (Pro s) = {s}" | "props (Neg' p) = props p" | "props (Con' p q) = props p ∪ props q" | "props (Eql p q) = props p ∪ props q" | "props (Eql' p q) = props p ∪ props q" lemma relevant_props: assumes "∀s ∈ props p. i1 s = i2 s" shows "eval i1 p = eval i2 p" using assms (*‹∀s∈props p. i1 s = i2 s›*) apply (induct p) (*goals: 1. ‹⋀x. ∀s∈props (Pro x). i1 s = i2 s ⟹ eval i1 (Pro x) = eval i2 (Pro x)› 2. ‹∀s∈props Truth. i1 s = i2 s ⟹ eval i1 Truth = eval i2 Truth› 3. ‹⋀p. ⟦∀s∈props p. i1 s = i2 s ⟹ eval i1 p = eval i2 p; ∀s∈props (Neg' p). i1 s = i2 s⟧ ⟹ eval i1 (Neg' p) = eval i2 (Neg' p)› 4. ‹⋀p1 p2. ⟦∀s∈props p1. i1 s = i2 s ⟹ eval i1 p1 = eval i2 p1; ∀s∈props p2. i1 s = i2 s ⟹ eval i1 p2 = eval i2 p2; ∀s∈props (Con' p1 p2). i1 s = i2 s⟧ ⟹ eval i1 (Con' p1 p2) = eval i2 (Con' p1 p2)› 5. ‹⋀p1 p2. ⟦∀s∈props p1. i1 s = i2 s ⟹ eval i1 p1 = eval i2 p1; ∀s∈props p2. i1 s = i2 s ⟹ eval i1 p2 = eval i2 p2; ∀s∈props (Eql p1 p2). i1 s = i2 s⟧ ⟹ eval i1 (Eql p1 p2) = eval i2 (Eql p1 p2)› 6. ‹⋀p1 p2. ⟦∀s∈props p1. i1 s = i2 s ⟹ eval i1 p1 = eval i2 p1; ∀s∈props p2. i1 s = i2 s ⟹ eval i1 p2 = eval i2 p2; ∀s∈props (Eql' p1 p2). i1 s = i2 s⟧ ⟹ eval i1 (Eql' p1 p2) = eval i2 (Eql' p1 p2)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*discuss goal 4*) apply simp (*discuss goal 5*) apply simp (*discuss goal 6*) apply simp (*goal: ‹⋀p1 p2. ⟦∀s∈props p1. i1 s = i2 s ⟹ eval i1 p1 = eval i2 p1; ∀s∈props p2. i1 s = i2 s ⟹ eval i1 p2 = eval i2 p2; ∀s∈props (Eql' p1 p2). i1 s = i2 s⟧ ⟹ eval i1 (Eql' p1 p2) = eval i2 (Eql' p1 p2)›*) apply metis (*proven 6 subgoals*) . fun change_tv :: "(nat ⇒ nat) ⇒ tv ⇒ tv" where "change_tv f (Det b) = Det b" | "change_tv f (Indet n) = Indet (f n)" lemma change_tv_injection: assumes "inj f" shows "inj (change_tv f)" proof (-) (*goal: ‹inj (change_tv (f::nat ⇒ nat))›*) have "change_tv f tv1 = change_tv f tv2 ⟹ tv1 = tv2" for tv1 and tv2 using assms (*‹inj f›*) apply (cases tv1) (*goals: 1. ‹⋀x1. ⟦change_tv f tv1 = change_tv f tv2; inj f; tv1 = Det x1⟧ ⟹ tv1 = tv2› 2. ‹⋀x2. ⟦change_tv f tv1 = change_tv f tv2; inj f; tv1 = Indet x2⟧ ⟹ tv1 = tv2› discuss goal 1*) apply (cases tv2) (*goals: 1. ‹⋀x1 x1a. ⟦change_tv f tv1 = change_tv f tv2; inj f; tv1 = Det x1; tv2 = Det x1a⟧ ⟹ tv1 = tv2› 2. ‹⋀x1 x2. ⟦change_tv f tv1 = change_tv f tv2; inj f; tv1 = Det x1; tv2 = Indet x2⟧ ⟹ tv1 = tv2› discuss goal 1*) apply (simp add: inj_eq (*‹inj (?f::?'a ⇒ ?'b) ⟹ (?f (?x::?'a) = ?f (?y::?'a)) = (?x = ?y)›*)) (*discuss goal 2*) apply (simp add: inj_eq (*‹inj ?f ⟹ (?f ?x = ?f ?y) = (?x = ?y)›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply (cases tv2) (*goals: 1. ‹⋀x2 x1. ⟦change_tv f tv1 = change_tv f tv2; inj f; tv1 = Indet x2; tv2 = Det x1⟧ ⟹ tv1 = tv2› 2. ‹⋀x2 x2a. ⟦change_tv f tv1 = change_tv f tv2; inj f; tv1 = Indet x2; tv2 = Indet x2a⟧ ⟹ tv1 = tv2› discuss goal 1*) apply (simp add: inj_eq (*‹inj ?f ⟹ (?f ?x = ?f ?y) = (?x = ?y)›*)) (*discuss goal 2*) apply (simp add: inj_eq (*‹inj ?f ⟹ (?f ?x = ?f ?y) = (?x = ?y)›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) . then show "?thesis" (*goal: ‹inj (change_tv (f::nat ⇒ nat))›*) by (simp add: injI (*‹(⋀x y. ?f x = ?f y ⟹ x = y) ⟹ inj ?f›*)) qed definition change_int :: "(nat ⇒ nat) ⇒ (id ⇒ tv) ⇒ (id ⇒ tv)" where "change_int f i ≡ λs. change_tv f (i s)" lemma eval_change: assumes "inj f" shows "eval (change_int f i) p = change_tv f (eval i p)" proof (induct p) (*goals: 1. ‹⋀x::char list. eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (Pro x) = change_tv f (eval i (Pro x))› 2. ‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) Truth = change_tv f (eval i Truth)› 3. ‹⋀p::fm. eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) p = change_tv f (eval i p) ⟹ eval (change_int f i) (Neg' p) = change_tv f (eval i (Neg' p))› 4. ‹⋀(p1::fm) p2::fm. ⟦eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) p1 = change_tv f (eval i p1); eval (change_int f i) p2 = change_tv f (eval i p2)⟧ ⟹ eval (change_int f i) (Con' p1 p2) = change_tv f (eval i (Con' p1 p2))› 5. ‹⋀(p1::fm) p2::fm. ⟦eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) p1 = change_tv f (eval i p1); eval (change_int f i) p2 = change_tv f (eval i p2)⟧ ⟹ eval (change_int f i) (Eql p1 p2) = change_tv f (eval i (Eql p1 p2))› 6. ‹⋀(p1::fm) p2::fm. ⟦eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) p1 = change_tv f (eval i p1); eval (change_int f i) p2 = change_tv f (eval i p2)⟧ ⟹ eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))›*) fix p assume "eval (change_int f i) p = change_tv f (eval i p)" (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p::fm) = change_tv f (eval i p)›*) then have "eval_neg (eval (change_int f i) p) = eval_neg (change_tv f (eval i p))" by simp then have "eval_neg (eval (change_int f i) p) = change_tv f (eval_neg (eval i p))" apply (cases "eval i p") (*goals: 1. ‹⋀x1. ⟦(case eval (change_int f i) p of Det True ⇒ Det False | Det False ⇒ Det True | Indet n ⇒ Indet n) = (case change_tv f (eval i p) of Det True ⇒ Det False | Det False ⇒ Det True | Indet n ⇒ Indet n); eval i p = Det x1⟧ ⟹ (case eval (change_int f i) p of Det True ⇒ Det False | Det False ⇒ Det True | Indet n ⇒ Indet n) = change_tv f (case eval i p of Det True ⇒ Det False | Det False ⇒ Det True | Indet n ⇒ Indet n)› 2. ‹⋀x2. ⟦(case eval (change_int f i) p of Det True ⇒ Det False | Det False ⇒ Det True | Indet n ⇒ Indet n) = (case change_tv f (eval i p) of Det True ⇒ Det False | Det False ⇒ Det True | Indet n ⇒ Indet n); eval i p = Indet x2⟧ ⟹ (case eval (change_int f i) p of Det True ⇒ Det False | Det False ⇒ Det True | Indet n ⇒ Indet n) = change_tv f (case eval i p of Det True ⇒ Det False | Det False ⇒ Det True | Indet n ⇒ Indet n)› discuss goal 1*) apply (simp add: case_bool_if (*‹case_bool ≡ λx y P. if P then x else y›*)) (*discuss goal 2*) apply (simp add: case_bool_if (*‹case_bool ≡ λ(x::?'a) (y::?'a) P::bool. if P then x else y›*)) (*proven 2 subgoals*) . then show "eval (change_int f i) (Neg' p) = change_tv f (eval i (Neg' p))" by simp next (*goals: 1. ‹⋀x. eval (change_int f i) (Pro x) = change_tv f (eval i (Pro x))› 2. ‹eval (change_int f i) Truth = change_tv f (eval i Truth)› 3. ‹⋀p1 p2. ⟦eval (change_int f i) p1 = change_tv f (eval i p1); eval (change_int f i) p2 = change_tv f (eval i p2)⟧ ⟹ eval (change_int f i) (Con' p1 p2) = change_tv f (eval i (Con' p1 p2))› 4. ‹⋀p1 p2. ⟦eval (change_int f i) p1 = change_tv f (eval i p1); eval (change_int f i) p2 = change_tv f (eval i p2)⟧ ⟹ eval (change_int f i) (Eql p1 p2) = change_tv f (eval i (Eql p1 p2))› 5. ‹⋀p1 p2. ⟦eval (change_int f i) p1 = change_tv f (eval i p1); eval (change_int f i) p2 = change_tv f (eval i p2)⟧ ⟹ eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))›*) fix p1 and p2 assume ih1: "eval (change_int f i) p1 = change_tv f (eval i p1)" (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p1::fm) = change_tv f (eval i p1)›*) assume ih2: "eval (change_int f i) p2 = change_tv f (eval i p2)" (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p2::fm) = change_tv f (eval i p2)›*) show "eval (change_int f i) (Con' p1 p2) = change_tv f (eval i (Con' p1 p2))" proof (cases "eval i p1 = eval i p2") (*goals: 1. ‹eval i p1 = eval i p2 ⟹ eval (change_int f i) (Con' p1 p2) = change_tv f (eval i (Con' p1 p2))› 2. ‹eval i p1 ≠ eval i p2 ⟹ eval (change_int f i) (Con' p1 p2) = change_tv f (eval i (Con' p1 p2))›*) assume a: "eval i p1 = eval i p2" (*‹eval (i::char list ⇒ tv) (p1::fm) = eval i (p2::fm)›*) then have yes: "eval i (Con' p1 p2) = eval i p1" by auto from a (*‹eval i p1 = eval i p2›*) have "change_tv f (eval i p1) = change_tv f (eval i p2)" by auto then have "eval (change_int f i) p1 = eval (change_int f i) p2" using ih1 (*‹eval (change_int f i) p1 = change_tv f (eval i p1)›*) ih2 (*‹eval (change_int f i) p2 = change_tv f (eval i p2)›*) by auto then have "eval (change_int f i) (Con' p1 p2) = eval (change_int f i) p1" by auto then show "eval (change_int f i) (Con' p1 p2) = change_tv f (eval i (Con' p1 p2))" using yes (*‹eval i (Con' p1 p2) = eval i p1›*) ih1 (*‹eval (change_int f i) p1 = change_tv f (eval i p1)›*) by auto next (*goal: ‹eval i p1 ≠ eval i p2 ⟹ eval (change_int f i) (Con' p1 p2) = change_tv f (eval i (Con' p1 p2))›*) assume a': "eval i p1 ≠ eval i p2" (*‹eval (i::char list ⇒ tv) (p1::fm) ≠ eval i (p2::fm)›*) from a' (*‹eval i p1 ≠ eval i p2›*) have b': "eval (change_int f i) p1 ≠ eval (change_int f i) p2" using assms (*‹inj f›*) ih1 (*‹eval (change_int f i) p1 = change_tv f (eval i p1)›*) ih2 (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p2::fm) = change_tv f (eval i p2)›*) change_tv_injection (*‹inj (?f::nat ⇒ nat) ⟹ inj (change_tv ?f)›*) the_inv_f_f (*‹inj ?f ⟹ the_inv ?f (?f ?x) = ?x›*) by metis show "eval (change_int f i) (Con' p1 p2) = change_tv f (eval i (Con' p1 p2))" proof (cases "eval i p1 = Det True") (*goals: 1. ‹eval i p1 = Det True ⟹ eval (change_int f i) (Con' p1 p2) = change_tv f (eval i (Con' p1 p2))› 2. ‹eval i p1 ≠ Det True ⟹ eval (change_int f i) (Con' p1 p2) = change_tv f (eval i (Con' p1 p2))›*) assume a: "eval i p1 = Det True" (*‹eval (i::char list ⇒ tv) (p1::fm) = Det True›*) from a (*‹eval i p1 = Det True›*) a' (*‹eval (i::char list ⇒ tv) (p1::fm) ≠ eval i (p2::fm)›*) have "eval i (Con' p1 p2) = eval i p2" by auto then have c: "change_tv f (eval i (Con' p1 p2)) = change_tv f (eval i p2)" by auto from a (*‹eval i p1 = Det True›*) have b: "eval (change_int f i) p1 = Det True" using ih1 (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p1::fm) = change_tv f (eval i p1)›*) by auto from b (*‹eval (change_int f i) p1 = Det True›*) b' (*‹eval (change_int f i) p1 ≠ eval (change_int f i) p2›*) have "eval (change_int f i) (Con' p1 p2) = eval (change_int f i) p2" by auto then show "eval (change_int f i) (Con' p1 p2) = change_tv f (eval i (Con' p1 p2))" using c (*‹change_tv f (eval i (Con' p1 p2)) = change_tv f (eval i p2)›*) ih2 (*‹eval (change_int f i) p2 = change_tv f (eval i p2)›*) by auto next (*goal: ‹eval i p1 ≠ Det True ⟹ eval (change_int f i) (Con' p1 p2) = change_tv f (eval i (Con' p1 p2))›*) assume a'': "eval i p1 ≠ Det True" (*‹eval (i::char list ⇒ tv) (p1::fm) ≠ Det True›*) from a'' (*‹eval (i::char list ⇒ tv) (p1::fm) ≠ Det True›*) have b'': "eval (change_int f i) p1 ≠ Det True" using assms (*‹inj f›*) ih1 (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p1::fm) = change_tv f (eval i p1)›*) ih2 (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p2::fm) = change_tv f (eval i p2)›*) change_tv_injection (*‹inj ?f ⟹ inj (change_tv ?f)›*) the_inv_f_f (*‹inj ?f ⟹ the_inv ?f (?f ?x) = ?x›*) change_tv.simps (*‹change_tv (?f::nat ⇒ nat) (Det (?b::bool)) = Det ?b› ‹change_tv ?f (Indet ?n) = Indet (?f ?n)›*) by metis show "eval (change_int f i) (Con' p1 p2) = change_tv f (eval i (Con' p1 p2))" proof (cases "eval i p2 = Det True") (*goals: 1. ‹eval i p2 = Det True ⟹ eval (change_int f i) (Con' p1 p2) = change_tv f (eval i (Con' p1 p2))› 2. ‹eval i p2 ≠ Det True ⟹ eval (change_int f i) (Con' p1 p2) = change_tv f (eval i (Con' p1 p2))›*) assume a: "eval i p2 = Det True" (*‹eval (i::char list ⇒ tv) (p2::fm) = Det True›*) from a (*‹eval i p2 = Det True›*) a' (*‹eval i p1 ≠ eval i p2›*) a'' (*‹eval i p1 ≠ Det True›*) have "eval i (Con' p1 p2) = eval i p1" by auto then have c: "change_tv f (eval i (Con' p1 p2)) = change_tv f (eval i p1)" by auto from a (*‹eval i p2 = Det True›*) have b: "eval (change_int f i) p2 = Det True" using ih2 (*‹eval (change_int f i) p2 = change_tv f (eval i p2)›*) by auto from b (*‹eval (change_int f i) p2 = Det True›*) b' (*‹eval (change_int f i) p1 ≠ eval (change_int f i) p2›*) b'' (*‹eval (change_int f i) p1 ≠ Det True›*) have "eval (change_int f i) (Con' p1 p2) = eval (change_int f i) p1" by auto then show "eval (change_int f i) (Con' p1 p2) = change_tv f (eval i (Con' p1 p2))" using c (*‹change_tv f (eval i (Con' p1 p2)) = change_tv f (eval i p1)›*) ih1 (*‹eval (change_int f i) p1 = change_tv f (eval i p1)›*) by auto next (*goal: ‹eval i p2 ≠ Det True ⟹ eval (change_int f i) (Con' p1 p2) = change_tv f (eval i (Con' p1 p2))›*) assume a''': "eval i p2 ≠ Det True" (*‹eval (i::char list ⇒ tv) (p2::fm) ≠ Det True›*) from a' (*‹eval (i::char list ⇒ tv) (p1::fm) ≠ eval i (p2::fm)›*) a'' (*‹eval i p1 ≠ Det True›*) a''' (*‹eval (i::char list ⇒ tv) (p2::fm) ≠ Det True›*) have "eval i (Con' p1 p2) = Det False" by auto then have c: "change_tv f (eval i (Con' p1 p2)) = Det False" by auto from a''' (*‹eval i p2 ≠ Det True›*) have b''': "eval (change_int f i) p2 ≠ Det True" using assms (*‹inj f›*) ih1 (*‹eval (change_int f i) p1 = change_tv f (eval i p1)›*) ih2 (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p2::fm) = change_tv f (eval i p2)›*) change_tv_injection (*‹inj (?f::nat ⇒ nat) ⟹ inj (change_tv ?f)›*) the_inv_f_f (*‹inj (?f::?'a::type ⇒ ?'b::type) ⟹ the_inv ?f (?f (?x::?'a::type)) = ?x›*) change_tv.simps (*‹change_tv ?f (Det ?b) = Det ?b› ‹change_tv ?f (Indet ?n) = Indet (?f ?n)›*) by metis from b' (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p1::fm) ≠ eval (change_int f i) (p2::fm)›*) b'' (*‹eval (change_int f i) p1 ≠ Det True›*) b''' (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p2::fm) ≠ Det True›*) have "eval (change_int f i) (Con' p1 p2) = Det False" by auto then show "eval (change_int f i) (Con' p1 p2) = change_tv f (eval i (Con' p1 p2))" using c (*‹change_tv f (eval i (Con' p1 p2)) = Det False›*) by auto qed qed qed next (*goals: 1. ‹⋀x. eval (change_int f i) (Pro x) = change_tv f (eval i (Pro x))› 2. ‹eval (change_int f i) Truth = change_tv f (eval i Truth)› 3. ‹⋀p1 p2. ⟦eval (change_int f i) p1 = change_tv f (eval i p1); eval (change_int f i) p2 = change_tv f (eval i p2)⟧ ⟹ eval (change_int f i) (Eql p1 p2) = change_tv f (eval i (Eql p1 p2))› 4. ‹⋀p1 p2. ⟦eval (change_int f i) p1 = change_tv f (eval i p1); eval (change_int f i) p2 = change_tv f (eval i p2)⟧ ⟹ eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))›*) fix p1 and p2 assume ih1: "eval (change_int f i) p1 = change_tv f (eval i p1)" (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p1::fm) = change_tv f (eval i p1)›*) assume ih2: "eval (change_int f i) p2 = change_tv f (eval i p2)" (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p2::fm) = change_tv f (eval i p2)›*) have "Det (eval (change_int f i) p1 = eval (change_int f i) p2) = Det (change_tv f (eval i p1) = change_tv f (eval i p2))" using ih1 (*‹eval (change_int f i) p1 = change_tv f (eval i p1)›*) ih2 (*‹eval (change_int f i) p2 = change_tv f (eval i p2)›*) by simp also (*calculation: ‹Det (eval (change_int f i) p1 = eval (change_int f i) p2) = Det (change_tv f (eval i p1) = change_tv f (eval i p2))›*) have "... = Det ((eval i p1) = (eval i p2))" using assms (*‹inj f›*) change_tv_injection (*‹inj (?f::nat ⇒ nat) ⟹ inj (change_tv ?f)›*) by (simp add: inj_eq (*‹inj ?f ⟹ (?f ?x = ?f ?y) = (?x = ?y)›*)) also (*calculation: ‹Det (eval (change_int f i) p1 = eval (change_int f i) p2) = Det (eval i p1 = eval i p2)›*) have "... = change_tv f (Det (eval i p1 = eval i p2))" by simp finally (*calculation: ‹Det (eval (change_int f i) p1 = eval (change_int f i) p2) = change_tv f (Det (eval i p1 = eval i p2))›*) show "eval (change_int f i) (Eql p1 p2) = change_tv f (eval i (Eql p1 p2))" by simp next (*goals: 1. ‹⋀x. eval (change_int f i) (Pro x) = change_tv f (eval i (Pro x))› 2. ‹eval (change_int f i) Truth = change_tv f (eval i Truth)› 3. ‹⋀p1 p2. ⟦eval (change_int f i) p1 = change_tv f (eval i p1); eval (change_int f i) p2 = change_tv f (eval i p2)⟧ ⟹ eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))›*) fix p1 and p2 assume ih1: "eval (change_int f i) p1 = change_tv f (eval i p1)" (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p1::fm) = change_tv f (eval i p1)›*) assume ih2: "eval (change_int f i) p2 = change_tv f (eval i p2)" (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p2::fm) = change_tv f (eval i p2)›*) show "eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))" proof (cases "eval i p1 = eval i p2") (*goals: 1. ‹eval i p1 = eval i p2 ⟹ eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))› 2. ‹eval i p1 ≠ eval i p2 ⟹ eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))›*) assume a: "eval i p1 = eval i p2" (*‹eval (i::char list ⇒ tv) (p1::fm) = eval i (p2::fm)›*) then have yes: "eval i (Eql' p1 p2) = Det True" by auto from a (*‹eval i p1 = eval i p2›*) have "change_tv f (eval i p1) = change_tv f (eval i p2)" by auto then have "eval (change_int f i) p1 = eval (change_int f i) p2" using ih1 (*‹eval (change_int f i) p1 = change_tv f (eval i p1)›*) ih2 (*‹eval (change_int f i) p2 = change_tv f (eval i p2)›*) by auto then have "eval (change_int f i) (Eql' p1 p2) = Det True" by auto then show "eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))" using yes (*‹eval i (Eql' p1 p2) = Det True›*) ih1 (*‹eval (change_int f i) p1 = change_tv f (eval i p1)›*) by auto next (*goal: ‹eval (i::char list ⇒ tv) (p1::fm) ≠ eval i (p2::fm) ⟹ eval (change_int (f::nat ⇒ nat) i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))›*) assume a': "eval i p1 ≠ eval i p2" (*‹eval (i::char list ⇒ tv) (p1::fm) ≠ eval i (p2::fm)›*) show "eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))" proof (cases "eval i p1 = Det True") (*goals: 1. ‹eval i p1 = Det True ⟹ eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))› 2. ‹eval i p1 ≠ Det True ⟹ eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))›*) assume a: "eval i p1 = Det True" (*‹eval (i::char list ⇒ tv) (p1::fm) = Det True›*) from a (*‹eval i p1 = Det True›*) a' (*‹eval (i::char list ⇒ tv) (p1::fm) ≠ eval i (p2::fm)›*) have yes: "eval i (Eql' p1 p2) = eval i p2" by auto from a (*‹eval i p1 = Det True›*) have "change_tv f (eval i p1) = Det True" by auto then have b: "eval (change_int f i) p1 = Det True" using ih1 (*‹eval (change_int f i) p1 = change_tv f (eval i p1)›*) by auto from a' (*‹eval (i::char list ⇒ tv) (p1::fm) ≠ eval i (p2::fm)›*) have b': "eval (change_int f i) p1 ≠ eval (change_int f i) p2" using assms (*‹inj f›*) ih1 (*‹eval (change_int f i) p1 = change_tv f (eval i p1)›*) ih2 (*‹eval (change_int f i) p2 = change_tv f (eval i p2)›*) change_tv_injection (*‹inj (?f::nat ⇒ nat) ⟹ inj (change_tv ?f)›*) the_inv_f_f (*‹inj ?f ⟹ the_inv ?f (?f ?x) = ?x›*) change_tv.simps (*‹change_tv ?f (Det ?b) = Det ?b› ‹change_tv ?f (Indet ?n) = Indet (?f ?n)›*) by metis from b (*‹eval (change_int f i) p1 = Det True›*) b' (*‹eval (change_int f i) p1 ≠ eval (change_int f i) p2›*) have "eval (change_int f i) (Eql' p1 p2) = eval (change_int f i) p2" by auto then show "eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))" using ih2 (*‹eval (change_int f i) p2 = change_tv f (eval i p2)›*) yes (*‹eval i (Eql' p1 p2) = eval i p2›*) by auto next (*goal: ‹eval i p1 ≠ Det True ⟹ eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))›*) assume a'': "eval i p1 ≠ Det True" (*‹eval (i::char list ⇒ tv) (p1::fm) ≠ Det True›*) show "eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))" proof (cases "eval i p2 = Det True") (*goals: 1. ‹eval i p2 = Det True ⟹ eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))› 2. ‹eval i p2 ≠ Det True ⟹ eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))›*) assume a: "eval i p2 = Det True" (*‹eval (i::char list ⇒ tv) (p2::fm) = Det True›*) from a (*‹eval i p2 = Det True›*) a' (*‹eval i p1 ≠ eval i p2›*) a'' (*‹eval i p1 ≠ Det True›*) have yes: "eval i (Eql' p1 p2) = eval i p1" using eval_equality[of i p1 p2] (*‹eval i (Eql' p1 p2) = (if eval i p1 = eval i p2 then Det True else if eval i p1 = Det True then eval i p2 else if eval i p2 = Det True then eval i p1 else if eval i p1 = Det False then eval i (Neg' p2) else if eval i p2 = Det False then eval i (Neg' p1) else Det False)›*) by auto from a (*‹eval i p2 = Det True›*) have "change_tv f (eval i p2) = Det True" by auto then have b: "eval (change_int f i) p2 = Det True" using ih2 (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p2::fm) = change_tv f (eval i p2)›*) by auto from a' (*‹eval i p1 ≠ eval i p2›*) have b': "eval (change_int f i) p1 ≠ eval (change_int f i) p2" using assms (*‹inj f›*) ih1 (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p1::fm) = change_tv f (eval i p1)›*) ih2 (*‹eval (change_int f i) p2 = change_tv f (eval i p2)›*) change_tv_injection (*‹inj (?f::nat ⇒ nat) ⟹ inj (change_tv ?f)›*) the_inv_f_f (*‹inj ?f ⟹ the_inv ?f (?f ?x) = ?x›*) change_tv.simps (*‹change_tv ?f (Det ?b) = Det ?b› ‹change_tv ?f (Indet ?n) = Indet (?f ?n)›*) by metis from a'' (*‹eval i p1 ≠ Det True›*) have b'': "eval (change_int f i) p1 ≠ Det True" using b (*‹eval (change_int f i) p2 = Det True›*) b' (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p1::fm) ≠ eval (change_int f i) (p2::fm)›*) by auto from b (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p2::fm) = Det True›*) b' (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p1::fm) ≠ eval (change_int f i) (p2::fm)›*) b'' (*‹eval (change_int f i) p1 ≠ Det True›*) have "eval (change_int f i) (Eql' p1 p2) = eval (change_int f i) p1" using eval_equality[of "change_int f i" p1 p2] (*‹eval (change_int f i) (Eql' p1 p2) = (if eval (change_int f i) p1 = eval (change_int f i) p2 then Det True else if eval (change_int f i) p1 = Det True then eval (change_int f i) p2 else if eval (change_int f i) p2 = Det True then eval (change_int f i) p1 else if eval (change_int f i) p1 = Det False then eval (change_int f i) (Neg' p2) else if eval (change_int f i) p2 = Det False then eval (change_int f i) (Neg' p1) else Det False)›*) by auto then show "eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))" using ih1 (*‹eval (change_int f i) p1 = change_tv f (eval i p1)›*) yes (*‹eval i (Eql' p1 p2) = eval i p1›*) by auto next (*goal: ‹eval i p2 ≠ Det True ⟹ eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))›*) assume a''': "eval i p2 ≠ Det True" (*‹eval (i::char list ⇒ tv) (p2::fm) ≠ Det True›*) show "eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))" proof (cases "eval i p1 = Det False") (*goals: 1. ‹eval (i::char list ⇒ tv) (p1::fm) = Det False ⟹ eval (change_int (f::nat ⇒ nat) i) (Eql' p1 (p2::fm)) = change_tv f (eval i (Eql' p1 p2))› 2. ‹eval (i::char list ⇒ tv) (p1::fm) ≠ Det False ⟹ eval (change_int (f::nat ⇒ nat) i) (Eql' p1 (p2::fm)) = change_tv f (eval i (Eql' p1 p2))›*) assume a: "eval i p1 = Det False" (*‹eval (i::char list ⇒ tv) (p1::fm) = Det False›*) from a (*‹eval i p1 = Det False›*) a' (*‹eval (i::char list ⇒ tv) (p1::fm) ≠ eval i (p2::fm)›*) a'' (*‹eval i p1 ≠ Det True›*) a''' (*‹eval (i::char list ⇒ tv) (p2::fm) ≠ Det True›*) have yes: "eval i (Eql' p1 p2) = eval i (Neg' p2)" using eval_equality[of i p1 p2] (*‹eval i (Eql' p1 p2) = (if eval i p1 = eval i p2 then Det True else if eval i p1 = Det True then eval i p2 else if eval i p2 = Det True then eval i p1 else if eval i p1 = Det False then eval i (Neg' p2) else if eval i p2 = Det False then eval i (Neg' p1) else Det False)›*) by auto from a (*‹eval i p1 = Det False›*) have "change_tv f (eval i p1) = Det False" by auto then have b: "eval (change_int f i) p1 = Det False" using ih1 (*‹eval (change_int f i) p1 = change_tv f (eval i p1)›*) by auto from a' (*‹eval i p1 ≠ eval i p2›*) have b': "eval (change_int f i) p1 ≠ eval (change_int f i) p2" using assms (*‹inj f›*) ih1 (*‹eval (change_int f i) p1 = change_tv f (eval i p1)›*) ih2 (*‹eval (change_int f i) p2 = change_tv f (eval i p2)›*) change_tv_injection (*‹inj ?f ⟹ inj (change_tv ?f)›*) the_inv_f_f (*‹inj ?f ⟹ the_inv ?f (?f ?x) = ?x›*) change_tv.simps (*‹change_tv (?f::nat ⇒ nat) (Det (?b::bool)) = Det ?b› ‹change_tv ?f (Indet ?n) = Indet (?f ?n)›*) by metis from a'' (*‹eval i p1 ≠ Det True›*) have b'': "eval (change_int f i) p1 ≠ Det True" using b (*‹eval (change_int f i) p1 = Det False›*) b' (*‹eval (change_int f i) p1 ≠ eval (change_int f i) p2›*) by auto from a''' (*‹eval i p2 ≠ Det True›*) have b''': "eval (change_int f i) p2 ≠ Det True" using b (*‹eval (change_int f i) p1 = Det False›*) b' (*‹eval (change_int f i) p1 ≠ eval (change_int f i) p2›*) b'' (*‹eval (change_int f i) p1 ≠ Det True›*) by (metis assms (*‹inj f›*) change_tv.simps( (*‹change_tv ?f (Det ?b) = Det ?b›*) 1) change_tv_injection (*‹inj ?f ⟹ inj (change_tv ?f)›*) inj_eq (*‹inj ?f ⟹ (?f ?x = ?f ?y) = (?x = ?y)›*) ih2 (*‹eval (change_int f i) p2 = change_tv f (eval i p2)›*)) from b (*‹eval (change_int f i) p1 = Det False›*) b' (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p1::fm) ≠ eval (change_int f i) (p2::fm)›*) b'' (*‹eval (change_int f i) p1 ≠ Det True›*) b''' (*‹eval (change_int f i) p2 ≠ Det True›*) have "eval (change_int f i) (Eql' p1 p2) = eval (change_int f i) (Neg' p2)" using eval_equality[of "change_int f i" p1 p2] (*‹eval (change_int f i) (Eql' p1 p2) = (if eval (change_int f i) p1 = eval (change_int f i) p2 then Det True else if eval (change_int f i) p1 = Det True then eval (change_int f i) p2 else if eval (change_int f i) p2 = Det True then eval (change_int f i) p1 else if eval (change_int f i) p1 = Det False then eval (change_int f i) (Neg' p2) else if eval (change_int f i) p2 = Det False then eval (change_int f i) (Neg' p1) else Det False)›*) by auto then show "eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))" using ih2 (*‹eval (change_int f i) p2 = change_tv f (eval i p2)›*) yes (*‹eval (i::char list ⇒ tv) (Eql' (p1::fm) (p2::fm)) = eval i (Neg' p2)›*) a (*‹eval i p1 = Det False›*) a' (*‹eval i p1 ≠ eval i p2›*) a''' (*‹eval i p2 ≠ Det True›*) b (*‹eval (change_int f i) p1 = Det False›*) b' (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p1::fm) ≠ eval (change_int f i) (p2::fm)›*) b''' (*‹eval (change_int f i) p2 ≠ Det True›*) eval_negation (*‹eval ?i (Neg' ?p) = (if eval ?i ?p = Det False then Det True else if eval ?i ?p = Det True then Det False else eval ?i ?p)›*) by metis next (*goal: ‹eval (i::char list ⇒ tv) (p1::fm) ≠ Det False ⟹ eval (change_int (f::nat ⇒ nat) i) (Eql' p1 (p2::fm)) = change_tv f (eval i (Eql' p1 p2))›*) assume a'''': "eval i p1 ≠ Det False" (*‹eval (i::char list ⇒ tv) (p1::fm) ≠ Det False›*) show "eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))" proof (cases "eval i p2 = Det False") (*goals: 1. ‹eval i p2 = Det False ⟹ eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))› 2. ‹eval i p2 ≠ Det False ⟹ eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))›*) assume a: "eval i p2 = Det False" (*‹eval (i::char list ⇒ tv) (p2::fm) = Det False›*) from a (*‹eval i p2 = Det False›*) a' (*‹eval i p1 ≠ eval i p2›*) a'' (*‹eval i p1 ≠ Det True›*) a''' (*‹eval i p2 ≠ Det True›*) a'''' (*‹eval i p1 ≠ Det False›*) have yes: "eval i (Eql' p1 p2) = eval i (Neg' p1)" using eval_equality[of i p1 p2] (*‹eval (i::char list ⇒ tv) (Eql' (p1::fm) (p2::fm)) = (if eval i p1 = eval i p2 then Det True else if eval i p1 = Det True then eval i p2 else if eval i p2 = Det True then eval i p1 else if eval i p1 = Det False then eval i (Neg' p2) else if eval i p2 = Det False then eval i (Neg' p1) else Det False)›*) by auto from a (*‹eval i p2 = Det False›*) have "change_tv f (eval i p2) = Det False" by auto then have b: "eval (change_int f i) p2 = Det False" using ih2 (*‹eval (change_int f i) p2 = change_tv f (eval i p2)›*) by auto from a' (*‹eval (i::char list ⇒ tv) (p1::fm) ≠ eval i (p2::fm)›*) have b': "eval (change_int f i) p1 ≠ eval (change_int f i) p2" using assms (*‹inj (f::nat ⇒ nat)›*) ih1 (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p1::fm) = change_tv f (eval i p1)›*) ih2 (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p2::fm) = change_tv f (eval i p2)›*) change_tv_injection (*‹inj ?f ⟹ inj (change_tv ?f)›*) the_inv_f_f (*‹inj ?f ⟹ the_inv ?f (?f ?x) = ?x›*) change_tv.simps (*‹change_tv ?f (Det ?b) = Det ?b› ‹change_tv ?f (Indet ?n) = Indet (?f ?n)›*) by metis from a'' (*‹eval i p1 ≠ Det True›*) have b'': "eval (change_int f i) p1 ≠ Det True" using change_tv.elims (*‹⟦change_tv (?x::nat ⇒ nat) (?xa::tv) = (?y::tv); ⋀(f::nat ⇒ nat) b::bool. ⟦?x = f; ?xa = Det b; ?y = Det b⟧ ⟹ ?P::bool; ⋀(f::nat ⇒ nat) n::nat. ⟦?x = f; ?xa = Indet n; ?y = Indet (f n)⟧ ⟹ ?P⟧ ⟹ ?P›*) ih1 (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p1::fm) = change_tv f (eval i p1)›*) tv.simps(4) (*‹Indet ?x2.0 ≠ Det ?x1.0›*) by auto from a''' (*‹eval i p2 ≠ Det True›*) have b''': "eval (change_int f i) p2 ≠ Det True" using b (*‹eval (change_int f i) p2 = Det False›*) b' (*‹eval (change_int f i) p1 ≠ eval (change_int f i) p2›*) b'' (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p1::fm) ≠ Det True›*) by (metis assms (*‹inj f›*) change_tv.simps( (*‹change_tv ?f (Det ?b) = Det ?b›*) 1) change_tv_injection (*‹inj ?f ⟹ inj (change_tv ?f)›*) inj_eq (*‹inj ?f ⟹ (?f ?x = ?f ?y) = (?x = ?y)›*) ih2 (*‹eval (change_int f i) p2 = change_tv f (eval i p2)›*)) from a'''' (*‹eval i p1 ≠ Det False›*) have b'''': "eval (change_int f i) p1 ≠ Det False" using b (*‹eval (change_int f i) p2 = Det False›*) b' (*‹eval (change_int f i) p1 ≠ eval (change_int f i) p2›*) by auto from b (*‹eval (change_int f i) p2 = Det False›*) b' (*‹eval (change_int f i) p1 ≠ eval (change_int f i) p2›*) b'' (*‹eval (change_int f i) p1 ≠ Det True›*) b''' (*‹eval (change_int f i) p2 ≠ Det True›*) b'''' (*‹eval (change_int f i) p1 ≠ Det False›*) have "eval (change_int f i) (Eql' p1 p2) = eval (change_int f i) (Neg' p1)" using eval_equality[of "change_int f i" p1 p2] (*‹eval (change_int f i) (Eql' p1 p2) = (if eval (change_int f i) p1 = eval (change_int f i) p2 then Det True else if eval (change_int f i) p1 = Det True then eval (change_int f i) p2 else if eval (change_int f i) p2 = Det True then eval (change_int f i) p1 else if eval (change_int f i) p1 = Det False then eval (change_int f i) (Neg' p2) else if eval (change_int f i) p2 = Det False then eval (change_int f i) (Neg' p1) else Det False)›*) by auto then show "eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))" using ih1 (*‹eval (change_int f i) p1 = change_tv f (eval i p1)›*) yes (*‹eval (i::char list ⇒ tv) (Eql' (p1::fm) (p2::fm)) = eval i (Neg' p1)›*) a (*‹eval i p2 = Det False›*) a' (*‹eval i p1 ≠ eval i p2›*) a''' (*‹eval (i::char list ⇒ tv) (p2::fm) ≠ Det True›*) a'''' (*‹eval i p1 ≠ Det False›*) b (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p2::fm) = Det False›*) b' (*‹eval (change_int f i) p1 ≠ eval (change_int f i) p2›*) b''' (*‹eval (change_int f i) p2 ≠ Det True›*) b'''' (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p1::fm) ≠ Det False›*) eval_negation (*‹eval (?i::char list ⇒ tv) (Neg' (?p::fm)) = (if eval ?i ?p = Det False then Det True else if eval ?i ?p = Det True then Det False else eval ?i ?p)›*) a'' (*‹eval i p1 ≠ Det True›*) b'' (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p1::fm) ≠ Det True›*) by metis next (*goal: ‹eval i p2 ≠ Det False ⟹ eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))›*) assume a''''': "eval i p2 ≠ Det False" (*‹eval (i::char list ⇒ tv) (p2::fm) ≠ Det False›*) from a' (*‹eval (i::char list ⇒ tv) (p1::fm) ≠ eval i (p2::fm)›*) a'' (*‹eval (i::char list ⇒ tv) (p1::fm) ≠ Det True›*) a''' (*‹eval i p2 ≠ Det True›*) a'''' (*‹eval i p1 ≠ Det False›*) a''''' (*‹eval i p2 ≠ Det False›*) have yes: "eval i (Eql' p1 p2) = Det False" using eval_equality[of i p1 p2] (*‹eval i (Eql' p1 p2) = (if eval i p1 = eval i p2 then Det True else if eval i p1 = Det True then eval i p2 else if eval i p2 = Det True then eval i p1 else if eval i p1 = Det False then eval i (Neg' p2) else if eval i p2 = Det False then eval i (Neg' p1) else Det False)›*) by auto from a''''' (*‹eval (i::char list ⇒ tv) (p2::fm) ≠ Det False›*) have "change_tv f (eval i p2) ≠ Det False" using change_tv_injection (*‹inj ?f ⟹ inj (change_tv ?f)›*) inj_eq (*‹inj ?f ⟹ (?f ?x = ?f ?y) = (?x = ?y)›*) assms (*‹inj f›*) change_tv.simps (*‹change_tv ?f (Det ?b) = Det ?b› ‹change_tv ?f (Indet ?n) = Indet (?f ?n)›*) by metis then have b: "eval (change_int f i) p2 ≠ Det False" using ih2 (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p2::fm) = change_tv f (eval i p2)›*) by auto from a' (*‹eval i p1 ≠ eval i p2›*) have b': "eval (change_int f i) p1 ≠ eval (change_int f i) p2" using assms (*‹inj f›*) ih1 (*‹eval (change_int f i) p1 = change_tv f (eval i p1)›*) ih2 (*‹eval (change_int f i) p2 = change_tv f (eval i p2)›*) change_tv_injection (*‹inj ?f ⟹ inj (change_tv ?f)›*) the_inv_f_f (*‹inj (?f::?'a ⇒ ?'b) ⟹ the_inv ?f (?f (?x::?'a)) = ?x›*) change_tv.simps (*‹change_tv ?f (Det ?b) = Det ?b› ‹change_tv (?f::nat ⇒ nat) (Indet (?n::nat)) = Indet (?f ?n)›*) by metis from a'' (*‹eval (i::char list ⇒ tv) (p1::fm) ≠ Det True›*) have b'': "eval (change_int f i) p1 ≠ Det True" using change_tv.elims (*‹⟦change_tv ?x ?xa = ?y; ⋀f b. ⟦?x = f; ?xa = Det b; ?y = Det b⟧ ⟹ ?P; ⋀f n. ⟦?x = f; ?xa = Indet n; ?y = Indet (f n)⟧ ⟹ ?P⟧ ⟹ ?P›*) ih1 (*‹eval (change_int f i) p1 = change_tv f (eval i p1)›*) tv.simps(4) (*‹Indet (?x2.0::nat) ≠ Det (?x1.0::bool)›*) by auto from a''' (*‹eval (i::char list ⇒ tv) (p2::fm) ≠ Det True›*) have b''': "eval (change_int f i) p2 ≠ Det True" using b (*‹eval (change_int f i) p2 ≠ Det False›*) b' (*‹eval (change_int f i) p1 ≠ eval (change_int f i) p2›*) b'' (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p1::fm) ≠ Det True›*) by (metis assms (*‹inj f›*) change_tv.simps( (*‹change_tv ?f (Det ?b) = Det ?b›*) 1) change_tv_injection (*‹inj ?f ⟹ inj (change_tv ?f)›*) the_inv_f_f (*‹inj ?f ⟹ the_inv ?f (?f ?x) = ?x›*) ih2 (*‹eval (change_int f i) p2 = change_tv f (eval i p2)›*)) from a'''' (*‹eval i p1 ≠ Det False›*) have b'''': "eval (change_int f i) p1 ≠ Det False" by (metis a'' (*‹eval i p1 ≠ Det True›*) change_tv.simps( (*‹change_tv ?f (Indet ?n) = Indet (?f ?n)›*) 2) ih1 (*‹eval (change_int f i) p1 = change_tv f (eval i p1)›*) string_tv.cases (*‹⟦?x = Det True ⟹ ?P; ?x = Det False ⟹ ?P; ⋀n. ?x = Indet n ⟹ ?P⟧ ⟹ ?P›*) tv.distinct( (*‹Det ?x1.0 ≠ Indet ?x2.0›*) 1)) from b (*‹eval (change_int f i) p2 ≠ Det False›*) b' (*‹eval (change_int f i) p1 ≠ eval (change_int f i) p2›*) b'' (*‹eval (change_int f i) p1 ≠ Det True›*) b''' (*‹eval (change_int f i) p2 ≠ Det True›*) b'''' (*‹eval (change_int f i) p1 ≠ Det False›*) have "eval (change_int f i) (Eql' p1 p2) = Det False" using eval_equality[of "change_int f i" p1 p2] (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (Eql' (p1::fm) (p2::fm)) = (if eval (change_int f i) p1 = eval (change_int f i) p2 then Det True else if eval (change_int f i) p1 = Det True then eval (change_int f i) p2 else if eval (change_int f i) p2 = Det True then eval (change_int f i) p1 else if eval (change_int f i) p1 = Det False then eval (change_int f i) (Neg' p2) else if eval (change_int f i) p2 = Det False then eval (change_int f i) (Neg' p1) else Det False)›*) by auto then show "eval (change_int f i) (Eql' p1 p2) = change_tv f (eval i (Eql' p1 p2))" using ih1 (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p1::fm) = change_tv f (eval i p1)›*) yes (*‹eval i (Eql' p1 p2) = Det False›*) a' (*‹eval (i::char list ⇒ tv) (p1::fm) ≠ eval i (p2::fm)›*) a''' (*‹eval i p2 ≠ Det True›*) a'''' (*‹eval (i::char list ⇒ tv) (p1::fm) ≠ Det False›*) b (*‹eval (change_int f i) p2 ≠ Det False›*) b' (*‹eval (change_int f i) p1 ≠ eval (change_int f i) p2›*) b''' (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p2::fm) ≠ Det True›*) b'''' (*‹eval (change_int f i) p1 ≠ Det False›*) a'' (*‹eval (i::char list ⇒ tv) (p1::fm) ≠ Det True›*) b'' (*‹eval (change_int (f::nat ⇒ nat) (i::char list ⇒ tv)) (p1::fm) ≠ Det True›*) by auto qed qed qed qed qed qed (simp_all add: change_int_def) (*solves the remaining goals: 1. ‹⋀x. eval (change_int f i) (Pro x) = change_tv f (eval i (Pro x))› 2. ‹eval (change_int f i) Truth = change_tv f (eval i Truth)›*) subsection ‹Only a Finite Number of Truth Values Needed› text ‹ Theorem ‹valid_in_valid› is a kind of the reverse of ‹valid_valid_in› (or its transfer variant). › abbreviation is_indet :: "tv ⇒ bool" where "is_indet tv ≡ (case tv of Det _ ⇒ False | Indet _ ⇒ True)" abbreviation get_indet :: "tv ⇒ nat" where "get_indet tv ≡ (case tv of Det _ ⇒ undefined | Indet n ⇒ n)" theorem valid_in_valid: assumes "card U ≥ card (props p)" and "valid_in U p" shows "valid p" proof (-) (*goal: ‹valid (p::fm)›*) have "finite U ⟹ card (props p) ≤ card U ⟹ valid_in U p ⟹ valid p" for U and p proof (-) (*goal: ‹⟦finite U; card (props p) ≤ card U; valid_in U p⟧ ⟹ valid p›*) assume assms: "finite U" "card (props p) ≤ card U" "valid_in U p" (*‹finite (U::nat set)› ‹card (props (p::fm)) ≤ card (U::nat set)› ‹valid_in (U::nat set) (p::fm)›*) show "valid p" unfolding valid_def (*goal: ‹∀i. eval i p = Det True›*) proof (standard) (*goal: ‹⋀i. eval i p = Det True›*) fix i obtain f where f_p: "(change_int f i) ` (props p) ⊆ (domain U) ∧ inj f" (*goal: ‹(⋀f. change_int f i ` props p ⊆ domain U ∧ inj f ⟹ thesis) ⟹ thesis›*) proof (-) (*goal: ‹(⋀f. change_int f i ` props p ⊆ domain U ∧ inj f ⟹ thesis) ⟹ thesis›*) have "finite U ⟹ card (props p) ≤ card U ⟹ ∃f. change_int f i ` props p ⊆ domain U ∧ inj f" for U and p proof (-) (*goal: ‹⟦finite U; card (props p) ≤ card U⟧ ⟹ ∃f. change_int f i ` props p ⊆ domain U ∧ inj f›*) assume assms: "finite U" "card (props p) ≤ card U" (*‹finite (U::nat set)› ‹card (props (p::fm)) ≤ card (U::nat set)›*) show "?thesis" (*goal: ‹∃f. change_int f i ` props p ⊆ domain U ∧ inj f›*) proof (-) (*goal: ‹∃f. change_int f i ` props p ⊆ domain U ∧ inj f›*) let ?X = "(get_indet ` ((i ` props p) ∩ {tv. is_indet tv}))" have d: "finite (props p)" apply (induct p) (*goals: 1. ‹⋀x. finite (props (Pro x))› 2. ‹finite (props Truth)› 3. ‹⋀p. finite (props p) ⟹ finite (props (Neg' p))› 4. ‹⋀p1 p2. ⟦finite (props p1); finite (props p2)⟧ ⟹ finite (props (Con' p1 p2))› 5. ‹⋀p1 p2. ⟦finite (props p1); finite (props p2)⟧ ⟹ finite (props (Eql p1 p2))› 6. ‹⋀p1 p2. ⟦finite (props p1); finite (props p2)⟧ ⟹ finite (props (Eql' p1 p2))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*proven 6 subgoals*) . then have cx: "card ?X ≤ card U" using assms (*‹finite U› ‹card (props p) ≤ card U›*) surj_card_le (*‹⟦finite ?A; ?B ⊆ ?f ` ?A⟧ ⟹ card ?B ≤ card ?A›*) Int_lower1 (*‹(?A::?'a::type set) ∩ (?B::?'a::type set) ⊆ ?A›*) card_image_le (*‹finite ?A ⟹ card (?f ` ?A) ≤ card ?A›*) finite_Int (*‹finite ?F ∨ finite ?G ⟹ finite (?F ∩ ?G)›*) finite_imageI (*‹finite ?F ⟹ finite (?h ` ?F)›*) le_trans (*‹⟦?i ≤ ?j; ?j ≤ ?k⟧ ⟹ ?i ≤ ?k›*) by metis have f: "finite ?X" using d (*‹finite (props (p::fm))›*) by simp obtain f where f_p: "(∀n ∈ ?X. f n ∈ U) ∧ (inj f)" (*goal: ‹(⋀f. (∀n∈get_indet ` (i ` props p ∩ Collect is_indet). f n ∈ U) ∧ inj f ⟹ thesis) ⟹ thesis›*) proof (-) (*goal: ‹(⋀f. (∀n∈get_indet ` (i ` props p ∩ Collect is_indet). f n ∈ U) ∧ inj f ⟹ thesis) ⟹ thesis›*) have "finite X ⟹ finite Y ⟹ card X ≤ card Y ⟹ ∃f. (∀n ∈ X. f n ∈ Y) ∧ inj f" for X :: "nat set" and Y :: "nat set" proof (-) (*goal: ‹⟦finite X; finite Y; card X ≤ card Y⟧ ⟹ ∃f. (∀n∈X. f n ∈ Y) ∧ inj f›*) assume assms: "finite X" "finite Y" "card X ≤ card Y" (*‹finite (X::nat set)› ‹finite (Y::nat set)› ‹card (X::nat set) ≤ card (Y::nat set)›*) show "?thesis" (*goal: ‹∃f::nat ⇒ nat. (∀n::nat∈X::nat set. f n ∈ (Y::nat set)) ∧ inj f›*) proof (-) (*goal: ‹∃f. (∀n∈X. f n ∈ Y) ∧ inj f›*) from assms (*‹finite X› ‹finite Y› ‹card X ≤ card Y›*) obtain Z where xyz: "Z ⊆ Y ∧ card Z = card X" (*goal: ‹(⋀Z::nat set. Z ⊆ (Y::nat set) ∧ card Z = card (X::nat set) ⟹ thesis::bool) ⟹ thesis›*) by (metis card_image (*‹inj_on ?f ?A ⟹ card (?f ` ?A) = card ?A›*) card_le_inj (*‹⟦finite ?A; finite ?B; card ?A ≤ card ?B⟧ ⟹ ∃f. f ` ?A ⊆ ?B ∧ inj_on f ?A›*)) then obtain f where "bij_betw f X Z" (*goal: ‹(⋀f. bij_betw f X Z ⟹ thesis) ⟹ thesis›*) by (metis assms( (*‹finite (X::nat set)›*) 1) assms( (*‹finite (Y::nat set)›*) 2) finite_same_card_bij (*‹⟦finite (?A::?'a set); finite (?B::?'b set); card ?A = card ?B⟧ ⟹ ∃h::?'a ⇒ ?'b. bij_betw h ?A ?B›*) infinite_super (*‹⟦(?S::?'a set) ⊆ (?T::?'a set); infinite ?S⟧ ⟹ infinite ?T›*)) then have f_p: "(∀n ∈ X. f n ∈ Y) ∧ inj_on f X" using bij_betwE (*‹bij_betw ?f ?A ?B ⟹ ∀a∈?A. ?f a ∈ ?B›*) bij_betw_imp_inj_on (*‹bij_betw ?f ?A ?B ⟹ inj_on ?f ?A›*) xyz (*‹Z ⊆ Y ∧ card Z = card X›*) by blast obtain f' where f': "f' = (λn. if n ∈ X then f n else n + Suc (Max Y + n))" (*goal: ‹(⋀f'. f' = (λn. if n ∈ X then f n else n + Suc (Max Y + n)) ⟹ thesis) ⟹ thesis›*) by simp have "inj f'" unfolding f' inj_on_def (*goal: ‹∀x∈UNIV. ∀y∈UNIV. (if x ∈ X then f x else x + Suc (Max Y + x)) = (if y ∈ X then f y else y + Suc (Max Y + y)) ⟶ x = y›*) using assms(2) (*‹finite Y›*) f_p (*‹(∀n∈X. f n ∈ Y) ∧ inj_on f X›*) le_add2 (*‹(?n::nat) ≤ (?m::nat) + ?n›*) trans_le_add2 (*‹?i ≤ ?j ⟹ ?i ≤ ?m + ?j›*) not_less_eq_eq (*‹(¬ (?m::nat) ≤ (?n::nat)) = (Suc ?n ≤ ?m)›*) apply - (*goal: ‹∀x∈UNIV. ∀y∈UNIV. (if x ∈ X then f x else x + Suc (Max Y + x)) = (if y ∈ X then f y else y + Suc (Max Y + y)) ⟶ x = y›*) by (msorry) moreover have "(∀n ∈ X. f' n ∈ Y)" unfolding f' (*goal: ‹∀n::nat∈X::nat set. (if n ∈ X then (f::nat ⇒ nat) n else n + Suc (Max (Y::nat set) + n)) ∈ Y›*) using f_p (*‹(∀n::nat∈X::nat set. (f::nat ⇒ nat) n ∈ (Y::nat set)) ∧ inj_on f X›*) by auto ultimately show "?thesis" (*goal: ‹∃f. (∀n∈X. f n ∈ Y) ∧ inj f›*) by metis qed qed then show "(⋀f. (∀n ∈ get_indet ` (i ` props p ∩ {tv. is_indet tv}). f n ∈ U) ∧ inj f ⟹ thesis) ⟹ thesis" using assms (*‹finite (U::nat set)› ‹card (props p) ≤ card U›*) cx (*‹card (get_indet ` ((i::char list ⇒ tv) ` props (p::fm) ∩ Collect is_indet)) ≤ card (U::nat set)›*) f (*‹finite (get_indet ` (i ` props p ∩ Collect is_indet))›*) unfolding inj_on_def (*goal: ‹(⋀f. (∀n∈get_indet ` (i ` props p ∩ Collect is_indet). f n ∈ U) ∧ (∀x∈UNIV. ∀y∈UNIV. f x = f y ⟶ x = y) ⟹ thesis) ⟹ thesis›*) by metis qed have "(change_int f i) ` (props p) ⊆ (domain U)" proof (standard) (*goal: ‹⋀x. x ∈ change_int f i ` props p ⟹ x ∈ domain U›*) fix x assume "x ∈ change_int f i ` props p" (*‹(x::tv) ∈ change_int (f::nat ⇒ nat) (i::char list ⇒ tv) ` props (p::fm)›*) then obtain s where s_p: "s ∈ props p ∧ change_int f i s = x" (*goal: ‹(⋀s. s ∈ props p ∧ change_int f i s = x ⟹ thesis) ⟹ thesis›*) by auto then have "change_int f i s ∈ {Det True, Det False} ∪ Indet ` U" proof (cases "change_int f i s ∈ {Det True, Det False}") (*goals: 1. ‹⟦s ∈ props p ∧ change_int f i s = x; change_int f i s ∈ {Det True, Det False}⟧ ⟹ change_int f i s ∈ {Det True, Det False} ∪ Indet ` U› 2. ‹⟦s ∈ props p ∧ change_int f i s = x; change_int f i s ∉ {Det True, Det False}⟧ ⟹ change_int f i s ∈ {Det True, Det False} ∪ Indet ` U›*) case True (*‹change_int f i s ∈ {Det True, Det False}›*) then show "?thesis" (*goal: ‹change_int f i s ∈ {Det True, Det False} ∪ Indet ` U›*) by auto next (*goal: ‹⟦s ∈ props p ∧ change_int f i s = x; change_int f i s ∉ {Det True, Det False}⟧ ⟹ change_int f i s ∈ {Det True, Det False} ∪ Indet ` U›*) case False (*‹change_int f i s ∉ {Det True, Det False}›*) then obtain n' where "change_int f i s = Indet n'" (*goal: ‹(⋀n'::nat. change_int (f::nat ⇒ nat) (i::char list ⇒ tv) (s::char list) = Indet n' ⟹ thesis::bool) ⟹ thesis›*) apply (cases "change_int f i s") (*goals: 1. ‹⋀x1. ⟦⋀n'. change_int f i s = Indet n' ⟹ thesis; change_int f i s ∉ {Det True, Det False}; change_int f i s = Det x1⟧ ⟹ thesis› 2. ‹⋀x2. ⟦⋀n'. change_int f i s = Indet n' ⟹ thesis; change_int f i s ∉ {Det True, Det False}; change_int f i s = Indet x2⟧ ⟹ thesis› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . then have p: "change_tv f (i s) = Indet n'" by (simp add: change_int_def (*‹change_int ?f ?i ≡ λs. change_tv ?f (?i s)›*)) moreover have "n' ∈ U" proof (-) (*goal: ‹n' ∈ U›*) obtain n'' where "f n'' = n'" (*goal: ‹(⋀n''. f n'' = n' ⟹ thesis) ⟹ thesis›*) using calculation (*‹change_tv (f::nat ⇒ nat) ((i::char list ⇒ tv) (s::char list)) = Indet (n'::nat)›*) change_tv.elims (*‹⟦change_tv (?x::nat ⇒ nat) (?xa::tv) = (?y::tv); ⋀(f::nat ⇒ nat) b::bool. ⟦?x = f; ?xa = Det b; ?y = Det b⟧ ⟹ ?P::bool; ⋀(f::nat ⇒ nat) n::nat. ⟦?x = f; ?xa = Indet n; ?y = Indet (f n)⟧ ⟹ ?P⟧ ⟹ ?P›*) by blast moreover have "s ∈ props p ∧ i s = (Indet n'')" using p (*‹change_tv (f::nat ⇒ nat) ((i::char list ⇒ tv) (s::char list)) = Indet (n'::nat)›*) calculation (*‹f n'' = n'›*) change_tv.simps (*‹change_tv ?f (Det ?b) = Det ?b› ‹change_tv ?f (Indet ?n) = Indet (?f ?n)›*) change_tv_injection (*‹inj ?f ⟹ inj (change_tv ?f)›*) the_inv_f_f (*‹inj ?f ⟹ the_inv ?f (?f ?x) = ?x›*) f_p (*‹(∀n::nat∈get_indet ` ((i::char list ⇒ tv) ` props (p::fm) ∩ Collect is_indet). (f::nat ⇒ nat) n ∈ (U::nat set)) ∧ inj f›*) s_p (*‹s ∈ props p ∧ change_int f i s = x›*) by metis then have "(Indet n'') ∈ i ` props p" using image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*) by metis then have "(Indet n'') ∈ i ` props p ∧ is_indet (Indet n'') ∧ get_indet (Indet n'') = n''" by auto then have "n'' ∈ ?X" using Int_Collect (*‹(?x ∈ ?A ∩ {x. ?P x}) = (?x ∈ ?A ∧ ?P ?x)›*) image_iff (*‹((?z::?'a::type) ∈ (?f::?'b::type ⇒ ?'a::type) ` (?A::?'b::type set)) = (∃x::?'b::type∈?A. ?z = ?f x)›*) by metis ultimately show "?thesis" (*goal: ‹(n'::nat) ∈ (U::nat set)›*) using f_p (*‹(∀n∈get_indet ` (i ` props p ∩ Collect is_indet). f n ∈ U) ∧ inj f›*) by auto qed ultimately have "change_tv f (i s) ∈ Indet ` U" by auto then have "change_int f i s ∈ Indet ` U" unfolding change_int_def (*goal: ‹change_tv f (i s) ∈ Indet ` U›*) by auto then show "?thesis" (*goal: ‹change_int f i s ∈ {Det True, Det False} ∪ Indet ` U›*) by auto qed then show "x ∈ domain U" unfolding domain_def (*goal: ‹x ∈ {Det True, Det False} ∪ Indet ` U›*) using s_p (*‹s ∈ props p ∧ change_int f i s = x›*) by simp qed then have "(change_int f i) ` (props p) ⊆ (domain U) ∧ (inj f)" unfolding domain_def (*goal: ‹change_int f i ` props p ⊆ {Det True, Det False} ∪ Indet ` U ∧ inj f›*) using f_p (*‹(∀n::nat∈get_indet ` ((i::char list ⇒ tv) ` props (p::fm) ∩ Collect is_indet). (f::nat ⇒ nat) n ∈ (U::nat set)) ∧ inj f›*) by simp then show "?thesis" (*goal: ‹∃f. change_int f i ` props p ⊆ domain U ∧ inj f›*) using f_p (*‹(∀n∈get_indet ` (i ` props p ∩ Collect is_indet). f n ∈ U) ∧ inj f›*) by metis qed qed then show "(⋀f. change_int f i ` props p ⊆ domain U ∧ inj f ⟹ thesis) ⟹ thesis" using assms (*‹finite U› ‹card (props p) ≤ card U› ‹valid_in U p›*) by metis qed obtain i2 where i2: "i2 = (λs. if s ∈ props p then (change_int f i) s else Det True)" (*goal: ‹(⋀i2::char list ⇒ tv. i2 = (λs::char list. if s ∈ props (p::fm) then change_int (f::nat ⇒ nat) (i::char list ⇒ tv) s else Det True) ⟹ thesis::bool) ⟹ thesis›*) by simp then have i2_p: "∀s ∈ props p. i2 s = (change_int f i) s" "∀s ∈ - props p. i2 s = Det True" apply - (*goals: 1. ‹i2 = (λs. if s ∈ props p then change_int f i s else Det True) ⟹ ∀s∈props p. i2 s = change_int f i s› 2. ‹i2 = (λs. if s ∈ props p then change_int f i s else Det True) ⟹ ∀s∈- props p. i2 s = Det True› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . then have "range i2 ⊆ (domain U)" using i2 (*‹i2 = (λs. if s ∈ props p then change_int f i s else Det True)›*) f_p (*‹change_int f i ` props p ⊆ domain U ∧ inj f›*) unfolding domain_def (*goal: ‹range i2 ⊆ {Det True, Det False} ∪ Indet ` U›*) by auto then have "eval i2 p = Det True" using assms (*‹finite (U::nat set)› ‹card (props (p::fm)) ≤ card (U::nat set)› ‹valid_in U p›*) unfolding valid_in_def (*goal: ‹eval i2 p = Det True›*) by auto then have "eval (change_int f i) p = Det True" using relevant_props[of p i2 "change_int f i"] (*‹∀s∈props p. i2 s = change_int f i s ⟹ eval i2 p = eval (change_int f i) p›*) i2_p (*‹∀s∈props p. i2 s = change_int f i s› ‹∀s∈- props p. i2 s = Det True›*) by auto then have "change_tv f (eval i p) = Det True" using eval_change (*‹inj ?f ⟹ eval (change_int ?f ?i) ?p = change_tv ?f (eval ?i ?p)›*) f_p (*‹change_int f i ` props p ⊆ domain U ∧ inj f›*) by auto then show "eval i p = Det True" apply (cases "eval i p") (*goals: 1. ‹⋀x1. ⟦change_tv f (eval i p) = Det True; eval i p = Det x1⟧ ⟹ eval i p = Det True› 2. ‹⋀x2. ⟦change_tv f (eval i p) = Det True; eval i p = Indet x2⟧ ⟹ eval i p = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . qed qed then show "?thesis" (*goal: ‹valid (p::fm)›*) using assms (*‹card (props p) ≤ card U› ‹valid_in U p›*) subsetI (*‹(⋀x. x ∈ ?A ⟹ x ∈ ?B) ⟹ ?A ⊆ ?B›*) sup_bot.comm_neutral (*‹sup ?a bot = ?a›*) image_is_empty (*‹(?f ` ?A = {}) = (?A = {})›*) subsetCE (*‹⟦?A ⊆ ?B; ?c ∉ ?A ⟹ ?P; ?c ∈ ?B ⟹ ?P⟧ ⟹ ?P›*) UnCI (*‹(?c ∉ ?B ⟹ ?c ∈ ?A) ⟹ ?c ∈ ?A ∪ ?B›*) valid_in_def (*‹valid_in ?U ?p ≡ ∀i. range i ⊆ domain ?U ⟶ eval i ?p = Det True›*) Un_insert_left (*‹insert ?a ?B ∪ ?C = insert ?a (?B ∪ ?C)›*) card.empty (*‹card {} = 0›*) card.infinite (*‹infinite ?A ⟹ card ?A = 0›*) finite.intros(1) (*‹finite {}›*) unfolding domain_def (*goal: ‹valid p›*) by metis qed theorem reduce: "valid p ⟷ valid_in {1..card (props p)} p" using valid_in_valid (*‹⟦card (props ?p) ≤ card ?U; valid_in ?U ?p⟧ ⟹ valid ?p›*) transfer (*‹¬ valid_in ?U ?p ⟹ ¬ valid ?p›*) by force section ‹Case Study› subsection ‹Abbreviations› text ‹ Entailment takes a list of assumptions. › abbreviation (input) Entail :: "fm list ⇒ fm ⇒ fm" where "Entail l p ≡ Imp (if l = [] then Truth else fold Con' (butlast l) (last l)) p" theorem entailment_not_chain: "¬ valid (Eql (Entail [Pro ''p'', Pro ''q''] (Pro ''r'')) (Box ((Imp' (Pro ''p'') (Imp' (Pro ''q'') (Pro ''r''))))))" proof (-) (*goal: ‹¬ valid (Eql (Imp (if [Pro ''p'', Pro ''q''] = [] then Truth else fold Con' (butlast [Pro ''p'', Pro ''q'']) (last [Pro ''p'', Pro ''q''])) (Pro ''r'')) (Box (Imp' (Pro ''p'') (Imp' (Pro ''q'') (Pro ''r'')))))›*) let ?i = "(λs. Indet 1)(''r'' := Det False)" have "eval ?i (Eql (Entail [Pro ''p'', Pro ''q''] (Pro ''r'')) (Box ((Imp' (Pro ''p'') (Imp' (Pro ''q'') (Pro ''r'')))))) = Det False" by simp moreover have "Det False ≠ Det True" by simp ultimately show "?thesis" (*goal: ‹¬ valid (Eql (Imp (if [Pro ''p'', Pro ''q''] = [] then Truth else fold Con' (butlast [Pro ''p'', Pro ''q'']) (last [Pro ''p'', Pro ''q''])) (Pro ''r'')) (Box (Imp' (Pro ''p'') (Imp' (Pro ''q'') (Pro ''r'')))))›*) unfolding valid_def (*goal: ‹¬ (∀i::char list ⇒ tv. eval i (Eql (Imp (if [Pro ''p'', Pro ''q''] = [] then Truth else fold Con' (butlast [Pro ''p'', Pro ''q'']) (last [Pro ''p'', Pro ''q''])) (Pro ''r'')) (Box (Imp' (Pro ''p'') (Imp' (Pro ''q'') (Pro ''r''))))) = Det True)›*) by metis qed abbreviation (input) B0 :: fm where "B0 ≡ Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r''))" abbreviation (input) B1 :: fm where "B1 ≡ Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')" abbreviation (input) B2 :: fm where "B2 ≡ Imp' (Pro ''r'') (Pro ''s'')" abbreviation (input) B3 :: fm where "B3 ≡ Imp' (Neg' (Pro ''s'')) (Neg' (Pro ''r''))" subsection ‹Results› text ‹ The paraconsistent logic is usable in contrast to classical logic. › theorem classical_logic_is_not_usable: "valid_boole (Entail [B0, B1] p)" unfolding valid_in_def (*goal: ‹∀i. range i ⊆ domain {} ⟶ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')])) p) = Det True›*) apply rule (*goal: ‹∀i. range i ⊆ domain {} ⟶ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')])) p) = Det True›*) proof (rule) (*goal: ‹⋀i. range i ⊆ domain {} ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')])) p) = Det True›*) fix i :: "id ⇒ tv" assume "range i ⊆ domain {}" (*‹range (i::char list ⇒ tv) ⊆ domain {}›*) then have "i ''p'' ∈ {Det True, Det False}" "i ''q'' ∈ {Det True, Det False}" "i ''r'' ∈ {Det True, Det False}" unfolding domain_def (*goals: 1. ‹i ''p'' ∈ {Det True, Det False}› 2. ‹i ''q'' ∈ {Det True, Det False}› 3. ‹i ''r'' ∈ {Det True, Det False}›*) apply - (*goals: 1. ‹range i ⊆ {Det True, Det False} ∪ Indet ` {} ⟹ i ''p'' ∈ {Det True, Det False}› 2. ‹range i ⊆ {Det True, Det False} ∪ Indet ` {} ⟹ i ''q'' ∈ {Det True, Det False}› 3. ‹range i ⊆ {Det True, Det False} ∪ Indet ` {} ⟹ i ''r'' ∈ {Det True, Det False}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . then show "eval i (Entail [B0, B1] p) = Det True" apply (cases "i ''p''") (*goals: 1. ‹⋀x1. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Det x1⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')])) p) = Det True› 2. ‹⋀x2. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Indet x2⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')])) p) = Det True› discuss goal 1*) apply (cases "i ''q''") (*goals: 1. ‹⋀x1 x1a. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Det x1; i ''q'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')])) p) = Det True› 2. ‹⋀x1 x2. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Det x1; i ''q'' = Indet x2⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')])) p) = Det True› discuss goal 1*) apply (cases "i ''r''") (*goals: 1. ‹⋀(x1::bool) (x1a::bool) x1b::bool. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Det x1; i ''q'' = Det x1a; i ''r'' = Det x1b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')])) (p::fm)) = Det True› 2. ‹⋀(x1::bool) (x1a::bool) x2::nat. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Det x1; i ''q'' = Det x1a; i ''r'' = Indet x2⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')])) (p::fm)) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''r''") (*goals: 1. ‹⋀x1 x2 x1a. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Det x1; i ''q'' = Indet x2; i ''r'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')])) p) = Det True› 2. ‹⋀x1 x2 x2a. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Det x1; i ''q'' = Indet x2; i ''r'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')])) p) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''q''") (*goals: 1. ‹⋀x2 x1. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Indet x2; i ''q'' = Det x1⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')])) p) = Det True› 2. ‹⋀x2 x2a. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Indet x2; i ''q'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')])) p) = Det True› discuss goal 1*) apply (cases "i ''r''") (*goals: 1. ‹⋀x2 x1 x1a. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Indet x2; i ''q'' = Det x1; i ''r'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')])) p) = Det True› 2. ‹⋀x2 x1 x2a. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Indet x2; i ''q'' = Det x1; i ''r'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')])) p) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''r''") (*goals: 1. ‹⋀x2 x2a x1. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Indet x2; i ''q'' = Indet x2a; i ''r'' = Det x1⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')])) p) = Det True› 2. ‹⋀x2 x2a x2b. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Indet x2; i ''q'' = Indet x2a; i ''r'' = Indet x2b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')])) p) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . qed corollary "valid_boole (Entail [B0, B1] (Pro ''r''))" by (rule classical_logic_is_not_usable (*‹valid_boole (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')])) ?p)›*)) corollary "valid_boole (Entail [B0, B1] (Neg' (Pro ''r'')))" by (rule classical_logic_is_not_usable (*‹valid_boole (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')])) (?p::fm))›*)) proposition "¬ valid (Entail [B0, B1] (Pro ''r''))" proof (-) (*goal: ‹¬ valid (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')])) (Pro ''r''))›*) let ?i = "(λs. Indet 1)(''r'' := Det False)" have "eval ?i (Entail [B0, B1] (Pro ''r'')) = Det False" by simp moreover have "Det False ≠ Det True" by simp ultimately show "?thesis" (*goal: ‹¬ valid (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')])) (Pro ''r''))›*) unfolding valid_def (*goal: ‹¬ (∀i. eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')])) (Pro ''r'')) = Det True)›*) by metis qed proposition "valid_boole (Entail [B0, Box B1] p)" unfolding valid_in_def (*goal: ‹∀i. range i ⊆ domain {} ⟶ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))])) p) = Det True›*) apply rule (*goal: ‹∀i. range i ⊆ domain {} ⟶ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))])) p) = Det True›*) proof (rule) (*goal: ‹⋀i. range i ⊆ domain {} ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))])) p) = Det True›*) fix i :: "id ⇒ tv" assume "range i ⊆ domain {}" (*‹range (i::char list ⇒ tv) ⊆ domain {}›*) then have "i ''p'' ∈ {Det True, Det False}" "i ''q'' ∈ {Det True, Det False}" "i ''r'' ∈ {Det True, Det False}" unfolding domain_def (*goals: 1. ‹i ''p'' ∈ {Det True, Det False}› 2. ‹i ''q'' ∈ {Det True, Det False}› 3. ‹i ''r'' ∈ {Det True, Det False}›*) apply - (*goals: 1. ‹range i ⊆ {Det True, Det False} ∪ Indet ` {} ⟹ i ''p'' ∈ {Det True, Det False}› 2. ‹range i ⊆ {Det True, Det False} ∪ Indet ` {} ⟹ i ''q'' ∈ {Det True, Det False}› 3. ‹range i ⊆ {Det True, Det False} ∪ Indet ` {} ⟹ i ''r'' ∈ {Det True, Det False}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . then show "eval i (Entail [B0, Box B1] p) = Det True" apply (cases "i ''p''") (*goals: 1. ‹⋀x1. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Det x1⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))])) p) = Det True› 2. ‹⋀x2. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Indet x2⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))])) p) = Det True› discuss goal 1*) apply (cases "i ''q''") (*goals: 1. ‹⋀x1 x1a. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Det x1; i ''q'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))])) p) = Det True› 2. ‹⋀x1 x2. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Det x1; i ''q'' = Indet x2⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))])) p) = Det True› discuss goal 1*) apply (cases "i ''r''") (*goals: 1. ‹⋀x1 x1a x1b. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Det x1; i ''q'' = Det x1a; i ''r'' = Det x1b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))])) p) = Det True› 2. ‹⋀x1 x1a x2. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Det x1; i ''q'' = Det x1a; i ''r'' = Indet x2⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))])) p) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''r''") (*goals: 1. ‹⋀x1 x2 x1a. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Det x1; i ''q'' = Indet x2; i ''r'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))])) p) = Det True› 2. ‹⋀x1 x2 x2a. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Det x1; i ''q'' = Indet x2; i ''r'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))])) p) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''q''") (*goals: 1. ‹⋀x2 x1. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Indet x2; i ''q'' = Det x1⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))])) p) = Det True› 2. ‹⋀x2 x2a. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Indet x2; i ''q'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))])) p) = Det True› discuss goal 1*) apply (cases "i ''r''") (*goals: 1. ‹⋀x2 x1 x1a. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Indet x2; i ''q'' = Det x1; i ''r'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))])) p) = Det True› 2. ‹⋀x2 x1 x2a. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Indet x2; i ''q'' = Det x1; i ''r'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))])) p) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''r''") (*goals: 1. ‹⋀x2 x2a x1. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Indet x2; i ''q'' = Indet x2a; i ''r'' = Det x1⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))])) p) = Det True› 2. ‹⋀x2 x2a x2b. ⟦i ''p'' ∈ {Det True, Det False}; i ''q'' ∈ {Det True, Det False}; i ''r'' ∈ {Det True, Det False}; i ''p'' = Indet x2; i ''q'' = Indet x2a; i ''r'' = Indet x2b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r''))])) p) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . qed proposition "¬ valid (Entail [B0, Box B1, Box B2] (Neg' (Pro ''p'')))" proof (-) (*goal: ‹¬ valid (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''p'')))›*) let ?i = "(λs. Indet 1)(''p'' := Det True)" have "eval ?i (Entail [B0, Box B1, Box B2] (Neg' (Pro ''p''))) = Det False" by simp moreover have "Det False ≠ Det True" by simp ultimately show "?thesis" (*goal: ‹¬ valid (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''p'')))›*) unfolding valid_def (*goal: ‹¬ (∀i. eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''p''))) = Det True)›*) by metis qed proposition "¬ valid (Entail [B0, Box B1, Box B2] (Neg' (Pro ''q'')))" proof (-) (*goal: ‹¬ valid (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''q'')))›*) let ?i = "(λs. Indet 1)(''q'' := Det True)" have "eval ?i (Entail [B0, Box B1, Box B2] (Neg' (Pro ''q''))) = Det False" by simp moreover have "Det False ≠ Det True" by simp ultimately show "?thesis" (*goal: ‹¬ valid (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''q'')))›*) unfolding valid_def (*goal: ‹¬ (∀i. eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''q''))) = Det True)›*) by metis qed proposition "¬ valid (Entail [B0, Box B1, Box B2] (Neg' (Pro ''s'')))" proof (-) (*goal: ‹¬ valid (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''s'')))›*) let ?i = "(λs. Indet 1)(''s'' := Det True)" have "eval ?i (Entail [B0, Box B1, Box B2] (Neg' (Pro ''s''))) = Det False" by simp moreover have "Det False ≠ Det True" by simp ultimately show "?thesis" (*goal: ‹¬ valid (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''s'')))›*) unfolding valid_def (*goal: ‹¬ (∀i. eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''s''))) = Det True)›*) by metis qed proposition "valid (Entail [B0, Box B1, Box B2] (Pro ''r''))" proof (-) (*goal: ‹valid (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r''))›*) have "{1..card (props (Entail [B0, Box B1, Box B2] (Pro ''r'')))} = {1, 2, 3, 4}" by code_simp moreover have "valid_in {1, 2, 3, 4} (Entail [B0, Box B1, Box B2] (Pro ''r''))" unfolding valid_in_def (*goal: ‹∀i. range i ⊆ domain {1, 2, 3, 4} ⟶ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True›*) apply rule (*goal: ‹∀i. range i ⊆ domain {1, 2, 3, 4} ⟶ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True›*) proof (rule) (*goal: ‹⋀i. range i ⊆ domain {1, 2, 3, 4} ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True›*) fix i :: "id ⇒ tv" assume "range i ⊆ domain {1, 2, 3, 4}" (*‹range (i::char list ⇒ tv) ⊆ domain {1::nat, 2::nat, 3::nat, 4::nat}›*) then have icase: "i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}" "i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}" "i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}" "i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}" unfolding domain_def (*goals: 1. ‹i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}› 2. ‹i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}› 3. ‹i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}› 4. ‹i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}›*) apply - (*goals: 1. ‹range i ⊆ {Det True, Det False} ∪ Indet ` {1, 2, 3, 4} ⟹ i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}› 2. ‹range i ⊆ {Det True, Det False} ∪ Indet ` {1, 2, 3, 4} ⟹ i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}› 3. ‹range i ⊆ {Det True, Det False} ∪ Indet ` {1, 2, 3, 4} ⟹ i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}› 4. ‹range i ⊆ {Det True, Det False} ∪ Indet ` {1, 2, 3, 4} ⟹ i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . show "eval i (Entail [B0, Box B1, Box B2] (Pro ''r'')) = Det True" using icase (*‹i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}› ‹i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}› ‹i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}› ‹i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}›*) apply (cases "i ''p''") (*goals: 1. ‹⋀x1::bool. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''q'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''r'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''s'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''p'' = Det x1⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› 2. ‹⋀x2::nat. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''q'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''r'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''s'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''p'' = Indet x2⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› discuss goal 1*) apply (cases "i ''q''") (*goals: 1. ‹⋀x1 x1a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› 2. ‹⋀x1 x2. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Indet x2⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› discuss goal 1*) apply (cases "i ''r''") (*goals: 1. ‹⋀x1 x1a x1b. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Det x1a; i ''r'' = Det x1b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› 2. ‹⋀x1 x1a x2. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Det x1a; i ''r'' = Indet x2⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› discuss goal 1*) apply (cases "i ''s''") (*goals: 1. ‹⋀x1 x1a x1b x1c. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Det x1a; i ''r'' = Det x1b; i ''s'' = Det x1c⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› 2. ‹⋀x1 x1a x1b x2. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Det x1a; i ''r'' = Det x1b; i ''s'' = Indet x2⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''s''") (*goals: 1. ‹⋀x1 x1a x2 x1b. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Det x1a; i ''r'' = Indet x2; i ''s'' = Det x1b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› 2. ‹⋀x1 x1a x2 x2a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Det x1a; i ''r'' = Indet x2; i ''s'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''r''") (*goals: 1. ‹⋀x1 x2 x1a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Indet x2; i ''r'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› 2. ‹⋀x1 x2 x2a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Indet x2; i ''r'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› discuss goal 1*) apply (cases "i ''s''") (*goals: 1. ‹⋀x1 x2 x1a x1b. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Indet x2; i ''r'' = Det x1a; i ''s'' = Det x1b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› 2. ‹⋀x1 x2 x1a x2a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Indet x2; i ''r'' = Det x1a; i ''s'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''s''") (*goals: 1. ‹⋀(x1::bool) (x2::nat) (x2a::nat) x1a::bool. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''q'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''r'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''s'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''p'' = Det x1; i ''q'' = Indet x2; i ''r'' = Indet x2a; i ''s'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› 2. ‹⋀(x1::bool) (x2::nat) (x2a::nat) x2b::nat. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''q'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''r'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''s'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''p'' = Det x1; i ''q'' = Indet x2; i ''r'' = Indet x2a; i ''s'' = Indet x2b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''q''") (*goals: 1. ‹⋀x2 x1. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Det x1⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› 2. ‹⋀x2 x2a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› discuss goal 1*) apply (cases "i ''r''") (*goals: 1. ‹⋀x2 x1 x1a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Det x1; i ''r'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› 2. ‹⋀x2 x1 x2a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Det x1; i ''r'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› discuss goal 1*) apply (cases "i ''s''") (*goals: 1. ‹⋀x2 x1 x1a x1b. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Det x1; i ''r'' = Det x1a; i ''s'' = Det x1b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› 2. ‹⋀x2 x1 x1a x2a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Det x1; i ''r'' = Det x1a; i ''s'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''s''") (*goals: 1. ‹⋀x2 x1 x2a x1a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Det x1; i ''r'' = Indet x2a; i ''s'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› 2. ‹⋀x2 x1 x2a x2b. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Det x1; i ''r'' = Indet x2a; i ''s'' = Indet x2b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''r''") (*goals: 1. ‹⋀x2 x2a x1. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Indet x2a; i ''r'' = Det x1⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› 2. ‹⋀x2 x2a x2b. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Indet x2a; i ''r'' = Indet x2b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› discuss goal 1*) apply (cases "i ''s''") (*goals: 1. ‹⋀x2 x2a x1 x1a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Indet x2a; i ''r'' = Det x1; i ''s'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› 2. ‹⋀x2 x2a x1 x2b. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Indet x2a; i ''r'' = Det x1; i ''s'' = Indet x2b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''s''") (*goals: 1. ‹⋀x2 x2a x2b x1. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Indet x2a; i ''r'' = Indet x2b; i ''s'' = Det x1⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› 2. ‹⋀x2 x2a x2b x2c. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Indet x2a; i ''r'' = Indet x2b; i ''s'' = Indet x2c⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r'')) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . qed ultimately show "?thesis" (*goal: ‹valid (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''r''))›*) using reduce (*‹valid (?p::fm) = valid_in {1::nat..card (props ?p)} ?p›*) by simp qed proposition "valid (Entail [B0, Box B1, Box B2] (Neg' (Pro ''r'')))" proof (-) (*goal: ‹valid (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r'')))›*) have "{1..card (props (Entail [B0, Box B1, Box B2] (Neg' (Pro ''r''))))} = {1, 2, 3, 4}" by code_simp moreover have "valid_in {1, 2, 3, 4} (Entail [B0, Box B1, Box B2] (Neg' (Pro ''r'')))" unfolding valid_in_def (*goal: ‹∀i. range i ⊆ domain {1, 2, 3, 4} ⟶ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True›*) apply rule (*goal: ‹∀i::char list ⇒ tv. range i ⊆ domain {1::nat, 2::nat, 3::nat, 4::nat} ⟶ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True›*) proof (rule) (*goal: ‹⋀i. range i ⊆ domain {1, 2, 3, 4} ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True›*) fix i :: "id ⇒ tv" assume "range i ⊆ domain {1, 2, 3, 4}" (*‹range (i::char list ⇒ tv) ⊆ domain {1::nat, 2::nat, 3::nat, 4::nat}›*) then have icase: "i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}" "i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}" "i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}" "i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}" unfolding domain_def (*goals: 1. ‹i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}› 2. ‹i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}› 3. ‹i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}› 4. ‹i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}›*) apply - (*goals: 1. ‹range i ⊆ {Det True, Det False} ∪ Indet ` {1, 2, 3, 4} ⟹ i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}› 2. ‹range i ⊆ {Det True, Det False} ∪ Indet ` {1, 2, 3, 4} ⟹ i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}› 3. ‹range i ⊆ {Det True, Det False} ∪ Indet ` {1, 2, 3, 4} ⟹ i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}› 4. ‹range i ⊆ {Det True, Det False} ∪ Indet ` {1, 2, 3, 4} ⟹ i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . show "eval i (Entail [B0, Box B1, Box B2] (Neg' (Pro ''r''))) = Det True" using icase (*‹i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}› ‹i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}› ‹i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}› ‹i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}›*) apply (cases "i ''p''") (*goals: 1. ‹⋀x1. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› 2. ‹⋀x2. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› discuss goal 1*) apply (cases "i ''q''") (*goals: 1. ‹⋀(x1::bool) x1a::bool. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''q'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''r'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''s'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''p'' = Det x1; i ''q'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› 2. ‹⋀(x1::bool) x2::nat. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''q'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''r'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''s'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''p'' = Det x1; i ''q'' = Indet x2⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› discuss goal 1*) apply (cases "i ''r''") (*goals: 1. ‹⋀x1 x1a x1b. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Det x1a; i ''r'' = Det x1b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› 2. ‹⋀x1 x1a x2. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Det x1a; i ''r'' = Indet x2⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› discuss goal 1*) apply (cases "i ''s''") (*goals: 1. ‹⋀x1 x1a x1b x1c. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Det x1a; i ''r'' = Det x1b; i ''s'' = Det x1c⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› 2. ‹⋀x1 x1a x1b x2. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Det x1a; i ''r'' = Det x1b; i ''s'' = Indet x2⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''s''") (*goals: 1. ‹⋀x1 x1a x2 x1b. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Det x1a; i ''r'' = Indet x2; i ''s'' = Det x1b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› 2. ‹⋀x1 x1a x2 x2a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Det x1a; i ''r'' = Indet x2; i ''s'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''r''") (*goals: 1. ‹⋀x1 x2 x1a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Indet x2; i ''r'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› 2. ‹⋀x1 x2 x2a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Indet x2; i ''r'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› discuss goal 1*) apply (cases "i ''s''") (*goals: 1. ‹⋀x1 x2 x1a x1b. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Indet x2; i ''r'' = Det x1a; i ''s'' = Det x1b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› 2. ‹⋀x1 x2 x1a x2a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Indet x2; i ''r'' = Det x1a; i ''s'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''s''") (*goals: 1. ‹⋀(x1::bool) (x2::nat) (x2a::nat) x1a::bool. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''q'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''r'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''s'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''p'' = Det x1; i ''q'' = Indet x2; i ''r'' = Indet x2a; i ''s'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› 2. ‹⋀(x1::bool) (x2::nat) (x2a::nat) x2b::nat. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''q'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''r'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''s'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''p'' = Det x1; i ''q'' = Indet x2; i ''r'' = Indet x2a; i ''s'' = Indet x2b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''q''") (*goals: 1. ‹⋀(x2::nat) x1::bool. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''q'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''r'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''s'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''p'' = Indet x2; i ''q'' = Det x1⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› 2. ‹⋀(x2::nat) x2a::nat. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''q'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''r'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''s'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''p'' = Indet x2; i ''q'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› discuss goal 1*) apply (cases "i ''r''") (*goals: 1. ‹⋀(x2::nat) (x1::bool) x1a::bool. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''q'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''r'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''s'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''p'' = Indet x2; i ''q'' = Det x1; i ''r'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› 2. ‹⋀(x2::nat) (x1::bool) x2a::nat. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''q'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''r'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''s'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''p'' = Indet x2; i ''q'' = Det x1; i ''r'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› discuss goal 1*) apply (cases "i ''s''") (*goals: 1. ‹⋀x2 x1 x1a x1b. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Det x1; i ''r'' = Det x1a; i ''s'' = Det x1b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› 2. ‹⋀x2 x1 x1a x2a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Det x1; i ''r'' = Det x1a; i ''s'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''s''") (*goals: 1. ‹⋀x2 x1 x2a x1a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Det x1; i ''r'' = Indet x2a; i ''s'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› 2. ‹⋀x2 x1 x2a x2b. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Det x1; i ''r'' = Indet x2a; i ''s'' = Indet x2b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''r''") (*goals: 1. ‹⋀x2 x2a x1. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Indet x2a; i ''r'' = Det x1⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› 2. ‹⋀x2 x2a x2b. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Indet x2a; i ''r'' = Indet x2b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› discuss goal 1*) apply (cases "i ''s''") (*goals: 1. ‹⋀(x2::nat) (x2a::nat) (x1::bool) x1a::bool. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''q'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''r'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''s'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''p'' = Indet x2; i ''q'' = Indet x2a; i ''r'' = Det x1; i ''s'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› 2. ‹⋀(x2::nat) (x2a::nat) (x1::bool) x2b::nat. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''q'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''r'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''s'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''p'' = Indet x2; i ''q'' = Indet x2a; i ''r'' = Det x1; i ''s'' = Indet x2b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''s''") (*goals: 1. ‹⋀(x2::nat) (x2a::nat) (x2b::nat) x1::bool. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''q'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''r'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''s'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''p'' = Indet x2; i ''q'' = Indet x2a; i ''r'' = Indet x2b; i ''s'' = Det x1⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› 2. ‹⋀(x2::nat) (x2a::nat) (x2b::nat) x2c::nat. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''q'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''r'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''s'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''p'' = Indet x2; i ''q'' = Indet x2a; i ''r'' = Indet x2b; i ''s'' = Indet x2c⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r''))) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . qed ultimately show "?thesis" (*goal: ‹valid (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Neg' (Pro ''r'')))›*) using reduce (*‹valid ?p = valid_in {1..card (props ?p)} ?p›*) by simp qed proposition "valid (Entail [B0, Box B1, Box B2] (Pro ''s''))" proof (-) (*goal: ‹valid (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s''))›*) have "{1..card (props (Entail [B0, Box B1, Box B2] (Pro ''s'')))} = {1, 2, 3, 4}" by code_simp moreover have "valid_in {1, 2, 3, 4} (Entail [B0, Box B1, Box B2] (Pro ''s''))" unfolding valid_in_def (*goal: ‹∀i. range i ⊆ domain {1, 2, 3, 4} ⟶ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True›*) apply rule (*goal: ‹∀i. range i ⊆ domain {1, 2, 3, 4} ⟶ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True›*) proof (rule) (*goal: ‹⋀i. range i ⊆ domain {1, 2, 3, 4} ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True›*) fix i :: "id ⇒ tv" assume "range i ⊆ domain {1, 2, 3, 4}" (*‹range (i::char list ⇒ tv) ⊆ domain {1::nat, 2::nat, 3::nat, 4::nat}›*) then have icase: "i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}" "i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}" "i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}" "i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}" unfolding domain_def (*goals: 1. ‹(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}› 2. ‹(i::char list ⇒ tv) ''q'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}› 3. ‹(i::char list ⇒ tv) ''r'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}› 4. ‹(i::char list ⇒ tv) ''s'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}›*) apply - (*goals: 1. ‹range (i::char list ⇒ tv) ⊆ {Det True, Det False} ∪ Indet ` {1::nat, 2::nat, 3::nat, 4::nat} ⟹ i ''p'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}› 2. ‹range (i::char list ⇒ tv) ⊆ {Det True, Det False} ∪ Indet ` {1::nat, 2::nat, 3::nat, 4::nat} ⟹ i ''q'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}› 3. ‹range (i::char list ⇒ tv) ⊆ {Det True, Det False} ∪ Indet ` {1::nat, 2::nat, 3::nat, 4::nat} ⟹ i ''r'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}› 4. ‹range (i::char list ⇒ tv) ⊆ {Det True, Det False} ∪ Indet ` {1::nat, 2::nat, 3::nat, 4::nat} ⟹ i ''s'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . show "eval i (Entail [B0, Box B1, Box B2] (Pro ''s'')) = Det True" using icase (*‹i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}› ‹i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}› ‹i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}› ‹i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}›*) apply (cases "i ''p''") (*goals: 1. ‹⋀x1. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› 2. ‹⋀x2. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› discuss goal 1*) apply (cases "i ''q''") (*goals: 1. ‹⋀x1 x1a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› 2. ‹⋀x1 x2. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Indet x2⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› discuss goal 1*) apply (cases "i ''r''") (*goals: 1. ‹⋀x1 x1a x1b. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Det x1a; i ''r'' = Det x1b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› 2. ‹⋀x1 x1a x2. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Det x1a; i ''r'' = Indet x2⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› discuss goal 1*) apply (cases "i ''s''") (*goals: 1. ‹⋀x1 x1a x1b x1c. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Det x1a; i ''r'' = Det x1b; i ''s'' = Det x1c⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› 2. ‹⋀x1 x1a x1b x2. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Det x1a; i ''r'' = Det x1b; i ''s'' = Indet x2⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''s''") (*goals: 1. ‹⋀x1 x1a x2 x1b. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Det x1a; i ''r'' = Indet x2; i ''s'' = Det x1b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› 2. ‹⋀x1 x1a x2 x2a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Det x1a; i ''r'' = Indet x2; i ''s'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''r''") (*goals: 1. ‹⋀x1 x2 x1a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Indet x2; i ''r'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› 2. ‹⋀x1 x2 x2a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Indet x2; i ''r'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› discuss goal 1*) apply (cases "i ''s''") (*goals: 1. ‹⋀x1 x2 x1a x1b. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Indet x2; i ''r'' = Det x1a; i ''s'' = Det x1b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› 2. ‹⋀x1 x2 x1a x2a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Det x1; i ''q'' = Indet x2; i ''r'' = Det x1a; i ''s'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''s''") (*goals: 1. ‹⋀(x1::bool) (x2::nat) (x2a::nat) x1a::bool. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''q'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''r'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''s'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''p'' = Det x1; i ''q'' = Indet x2; i ''r'' = Indet x2a; i ''s'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› 2. ‹⋀(x1::bool) (x2::nat) (x2a::nat) x2b::nat. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''q'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''r'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''s'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''p'' = Det x1; i ''q'' = Indet x2; i ''r'' = Indet x2a; i ''s'' = Indet x2b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''q''") (*goals: 1. ‹⋀x2 x1. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Det x1⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› 2. ‹⋀x2 x2a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› discuss goal 1*) apply (cases "i ''r''") (*goals: 1. ‹⋀x2 x1 x1a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Det x1; i ''r'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› 2. ‹⋀x2 x1 x2a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Det x1; i ''r'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› discuss goal 1*) apply (cases "i ''s''") (*goals: 1. ‹⋀(x2::nat) (x1::bool) (x1a::bool) x1b::bool. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''q'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''r'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''s'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''p'' = Indet x2; i ''q'' = Det x1; i ''r'' = Det x1a; i ''s'' = Det x1b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› 2. ‹⋀(x2::nat) (x1::bool) (x1a::bool) x2a::nat. ⟦(i::char list ⇒ tv) ''p'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''q'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''r'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''s'' ∈ {Det True, Det False, Indet (1::nat), Indet (2::nat), Indet (3::nat), Indet (4::nat)}; i ''p'' = Indet x2; i ''q'' = Det x1; i ''r'' = Det x1a; i ''s'' = Indet x2a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''s''") (*goals: 1. ‹⋀x2 x1 x2a x1a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Det x1; i ''r'' = Indet x2a; i ''s'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› 2. ‹⋀x2 x1 x2a x2b. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Det x1; i ''r'' = Indet x2a; i ''s'' = Indet x2b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''r''") (*goals: 1. ‹⋀x2 x2a x1. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Indet x2a; i ''r'' = Det x1⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› 2. ‹⋀x2 x2a x2b. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Indet x2a; i ''r'' = Indet x2b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› discuss goal 1*) apply (cases "i ''s''") (*goals: 1. ‹⋀x2 x2a x1 x1a. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Indet x2a; i ''r'' = Det x1; i ''s'' = Det x1a⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› 2. ‹⋀x2 x2a x1 x2b. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Indet x2a; i ''r'' = Det x1; i ''s'' = Indet x2b⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*discuss goal 2*) apply (cases "i ''s''") (*goals: 1. ‹⋀x2 x2a x2b x1. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Indet x2a; i ''r'' = Indet x2b; i ''s'' = Det x1⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› 2. ‹⋀x2 x2a x2b x2c. ⟦i ''p'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''q'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''r'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''s'' ∈ {Det True, Det False, Indet 1, Indet 2, Indet 3, Indet 4}; i ''p'' = Indet x2; i ''q'' = Indet x2a; i ''r'' = Indet x2b; i ''s'' = Indet x2c⟧ ⟹ eval i (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s'')) = Det True› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . qed ultimately show "?thesis" (*goal: ‹valid (Imp (if [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))] = [] then Truth else fold Con' (butlast [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))]) (last [Con' (Con' (Pro ''p'') (Pro ''q'')) (Neg' (Pro ''r'')), Box (Imp' (Con' (Pro ''p'') (Pro ''q'')) (Pro ''r'')), Box (Imp' (Pro ''r'') (Pro ''s''))])) (Pro ''s''))›*) using reduce (*‹valid (?p::fm) = valid_in {1::nat..card (props ?p)} ?p›*) by simp qed section ‹Acknowledgements› text ‹ Thanks to the Isabelle developers for making a superb system and for always being willing to help. › end ― ‹‹Paraconsistency› file›
{ "path": "afp-2025-02-12/thys/Paraconsistency/Paraconsistency.thy", "repo": "afp-2025-02-12", "sha": "af3973df4369703ac704b83ad1b265db0d488e4ac56346fa2e924c6f670ea5a1" }
subsection ‹Consistency› theory Guards imports StateModel CommCSL AbstractCommutativity begin text ‹A state is "consistent" iff: 1. All its permissions are full 2. Has unique guards iff has shared guard 3. The values in the fractional heaps are "reachable" wrt to the sequence and multiset of actions 4. Has exactly guards for the names in "scope"› definition reachable :: "('i, 'a, 'v) single_context ⇒ 'v ⇒ ('i, 'a) heap ⇒ bool" where "reachable scont v0 h ⟷ (∀sargs uargs. get_gs h = Some (pwrite, sargs) ∧ (∀k. get_gu h k = Some (uargs k)) ⟶ reachable_value (saction scont) (uaction scont) v0 sargs uargs (view scont (normalize (get_fh h))))" lemma reachableI: assumes "⋀sargs uargs. get_gs h = Some (pwrite, sargs) ∧ (∀k. get_gu h k = Some (uargs k)) ⟹ reachable_value (saction scont) (uaction scont) v0 sargs uargs (view scont (normalize (get_fh h)))" shows "reachable scont v0 h" by (metis assms (*‹get_gs h = Some (pwrite, ?sargs) ∧ (∀k. get_gu h k = Some (?uargs k)) ⟹ reachable_value (saction scont) (uaction scont) v0 ?sargs ?uargs (view scont (FractionalHeap.normalize (get_fh h)))›*) reachable_def (*‹reachable ?scont ?v0.0 ?h = (∀sargs uargs. get_gs ?h = Some (pwrite, sargs) ∧ (∀k. get_gu ?h k = Some (uargs k)) ⟶ reachable_value (saction ?scont) (uaction ?scont) ?v0.0 sargs uargs (view ?scont (FractionalHeap.normalize (get_fh ?h))))›*)) lemma reachableE: assumes "reachable scont v0 h" and "get_gs h = Some (pwrite, sargs)" and "⋀k. get_gu h k = Some (uargs k)" shows "reachable_value (saction scont) (uaction scont) v0 sargs uargs (view scont (normalize (get_fh h)))" by (meson assms (*‹reachable scont v0 h› ‹get_gs h = Some (pwrite, sargs)› ‹get_gu h ?k = Some (uargs ?k)›*) reachable_def (*‹reachable ?scont ?v0.0 ?h = (∀sargs uargs. get_gs ?h = Some (pwrite, sargs) ∧ (∀k. get_gu ?h k = Some (uargs k)) ⟶ reachable_value (saction ?scont) (uaction ?scont) ?v0.0 sargs uargs (view ?scont (FractionalHeap.normalize (get_fh ?h))))›*)) definition all_guards :: "('i, 'a) heap ⇒ bool" where "all_guards h ⟷ (∃v. get_gs h = Some (pwrite, v)) ∧ (∀k. get_gu h k ≠ None)" lemma no_guardI: assumes "get_gs h = None" and "⋀k. get_gu h k = None" shows "no_guard h" using assms(1) (*‹get_gs (h::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) = None›*) assms(2) (*‹get_gu h ?k = None›*) no_guard_def (*‹no_guard ?h = (get_gs ?h = None ∧ (∀k. get_gu ?h k = None))›*) by blast definition semi_consistent :: "('i, 'a, 'v) single_context ⇒ 'v ⇒ ('i, 'a) heap ⇒ bool" where "semi_consistent Γ v0 h ⟷ all_guards h ∧ reachable Γ v0 h" lemma semi_consistentE: assumes "semi_consistent Γ v0 h" shows "∃sargs uargs. get_gs h = Some (pwrite, sargs) ∧ (∀k. get_gu h k = Some (uargs k)) ∧ reachable_value (saction Γ) (uaction Γ) v0 sargs uargs (view Γ (normalize (get_fh h)))" proof (-) (*goal: ‹∃sargs uargs. get_gs h = Some (pwrite, sargs) ∧ (∀k. get_gu h k = Some (uargs k)) ∧ reachable_value (saction Γ) (uaction Γ) v0 sargs uargs (view Γ (FractionalHeap.normalize (get_fh h)))›*) let ?uargs = "λk. (SOME x. get_gu h k = Some x)" have "⋀k. get_gu h k = Some (?uargs k)" proof (-) (*goal: ‹⋀k::'a. get_gu (h::(nat ⇒ (prat × nat) option) × (prat × 'b multiset) option × ('a ⇒ 'b list option)) k = Some (SOME x::'b list. get_gu h k = Some x)›*) fix k have "∃x. get_gu h k = Some x" by (meson all_guards_def (*‹all_guards ?h = ((∃v. get_gs ?h = Some (pwrite, v)) ∧ (∀k. get_gu ?h k ≠ None))›*) assms (*‹semi_consistent Γ v0 h›*) option.exhaust_sel (*‹⟦?option = None ⟹ ?P; ?option = Some (the ?option) ⟹ ?P⟧ ⟹ ?P›*) semi_consistent_def (*‹semi_consistent ?Γ ?v0.0 ?h = (all_guards ?h ∧ reachable ?Γ ?v0.0 ?h)›*)) then show "get_gu h k = Some (?uargs k)" by fastforce qed moreover obtain sargs where "get_gs h = Some (pwrite, sargs)" (*goal: ‹(⋀sargs. get_gs h = Some (pwrite, sargs) ⟹ thesis) ⟹ thesis›*) by (meson all_guards_def (*‹all_guards (?h::(nat ⇒ (prat × nat) option) × (prat × ?'a multiset) option × (?'i ⇒ ?'a list option)) = ((∃v::?'a multiset. get_gs ?h = Some (pwrite, v)) ∧ (∀k::?'i. get_gu ?h k ≠ None))›*) assms (*‹semi_consistent (Γ::('a, 'b, 'c) single_context) (v0::'c) (h::(nat ⇒ (prat × nat) option) × (prat × 'b multiset) option × ('a ⇒ 'b list option))›*) semi_consistent_def (*‹semi_consistent (?Γ::(?'i, ?'a, ?'v) single_context) (?v0.0::?'v) (?h::(nat ⇒ (prat × nat) option) × (prat × ?'a multiset) option × (?'i ⇒ ?'a list option)) = (all_guards ?h ∧ reachable ?Γ ?v0.0 ?h)›*)) ultimately have "reachable_value (saction Γ) (uaction Γ) v0 sargs ?uargs (view Γ (normalize (get_fh h)))" by (meson assms (*‹semi_consistent Γ v0 h›*) reachableE (*‹⟦reachable ?scont ?v0.0 ?h; get_gs ?h = Some (pwrite, ?sargs); ⋀k. get_gu ?h k = Some (?uargs k)⟧ ⟹ reachable_value (saction ?scont) (uaction ?scont) ?v0.0 ?sargs ?uargs (view ?scont (FractionalHeap.normalize (get_fh ?h)))›*) semi_consistent_def (*‹semi_consistent ?Γ ?v0.0 ?h = (all_guards ?h ∧ reachable ?Γ ?v0.0 ?h)›*)) then show "?thesis" (*goal: ‹∃sargs uargs. get_gs h = Some (pwrite, sargs) ∧ (∀k. get_gu h k = Some (uargs k)) ∧ reachable_value (saction Γ) (uaction Γ) v0 sargs uargs (view Γ (FractionalHeap.normalize (get_fh h)))›*) using ‹⋀k. get_gu h k = Some (SOME x. get_gu h k = Some x)› (*‹get_gu h ?k = Some (SOME x. get_gu h ?k = Some x)›*) ‹get_gs h = Some (pwrite, sargs)› (*‹get_gs (h::(nat ⇒ (prat × nat) option) × (prat × 'b multiset) option × ('a ⇒ 'b list option)) = Some (pwrite, sargs::'b multiset)›*) by fastforce qed lemma semi_consistentI: assumes "all_guards h" and "reachable Γ v0 h" shows "semi_consistent Γ v0 h" by (simp add: assms( (*‹all_guards h›*) 1) assms( (*‹reachable Γ v0 h›*) 2) semi_consistent_def (*‹semi_consistent ?Γ ?v0.0 ?h = (all_guards ?h ∧ reachable ?Γ ?v0.0 ?h)›*)) lemma no_guard_then_smaller_same: assumes "Some h = Some a ⊕ Some b" and "no_guard h" shows "no_guard a" proof (rule no_guardI (*‹⟦get_gs (?h::(nat ⇒ (prat × nat) option) × (prat × ?'a multiset) option × (?'b ⇒ ?'a list option)) = None; ⋀k::?'b. get_gu ?h k = None⟧ ⟹ no_guard ?h›*)) (*goals: 1. ‹get_gs a = None› 2. ‹⋀k. get_gu a k = None›*) show "get_gs a = None" by (metis add_gs.elims (*‹⟦add_gs ?x ?xa = ?y; ⋀x. ⟦?x = None; ?xa = x; ?y = x⟧ ⟹ ?P; ⋀v. ⟦?x = Some v; ?xa = None; ?y = Some v⟧ ⟹ ?P; ⋀p p'. ⟦?x = Some p; ?xa = Some p'; ?y = Some (padd (fst p) (fst p'), snd p + snd p')⟧ ⟹ ?P⟧ ⟹ ?P›*) assms( (*‹Some h = Some a ⊕ Some b›*) 1) assms( (*‹no_guard h›*) 2) no_guard_def (*‹no_guard ?h = (get_gs ?h = None ∧ (∀k. get_gu ?h k = None))›*) option.simps( (*‹Some ?x2.0 ≠ None›*) 3) plus_extract( (*‹Some ?x = Some ?a ⊕ Some ?b ⟹ get_gs ?x = add_gs (get_gs ?a) (get_gs ?b)›*) 2)) fix k have "get_gu h k = None" by (meson assms( (*‹no_guard h›*) 2) no_guard_def (*‹no_guard ?h = (get_gs ?h = None ∧ (∀k. get_gu ?h k = None))›*)) then show "get_gu a k = None" by (metis assms( (*‹Some (h::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option)) = Some (a::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option)) ⊕ Some (b::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option))›*) 1) full_uguard_sum_same (*‹⟦get_gu (?a::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'b::type ⇒ ?'a::type list option)) (?k::?'b::type) = Some (?uargs::?'a::type list); Some (?h::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'b::type ⇒ ?'a::type list option)) = Some ?a ⊕ Some (?b::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'b::type ⇒ ?'a::type list option))⟧ ⟹ get_gu ?h ?k = Some ?uargs›*) option.exhaust (*‹⟦(?y::?'a::type option) = None ⟹ ?P::bool; ⋀x2::?'a::type. ?y = Some x2 ⟹ ?P⟧ ⟹ ?P›*)) qed lemma all_guardsI: assumes "⋀k. get_gu h k ≠ None" and "∃v. get_gs h = Some (pwrite, v)" shows "all_guards h" using all_guards_def (*‹all_guards (?h::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'i::type ⇒ ?'a::type list option)) = ((∃v::?'a::type multiset. get_gs ?h = Some (pwrite, v)) ∧ (∀k::?'i::type. get_gu ?h k ≠ None))›*) assms(1) (*‹get_gu h ?k ≠ None›*) assms(2) (*‹∃v. get_gs h = Some (pwrite, v)›*) by blast lemma all_guards_same: assumes "all_guards a" and "Some h = Some a ⊕ Some b" shows "all_guards h" proof (rule all_guardsI (*‹⟦⋀k. get_gu ?h k ≠ None; ∃v. get_gs ?h = Some (pwrite, v)⟧ ⟹ all_guards ?h›*)) (*goals: 1. ‹⋀k. get_gu h k ≠ None› 2. ‹∃v. get_gs h = Some (pwrite, v)›*) show "∃v. get_gs h = Some (pwrite, v)" using all_guards_def (*‹all_guards ?h = ((∃v. get_gs ?h = Some (pwrite, v)) ∧ (∀k. get_gu ?h k ≠ None))›*) assms(1) (*‹all_guards a›*) assms(2) (*‹Some h = Some a ⊕ Some b›*) full_sguard_sum_same (*‹⟦get_gs ?a = Some (pwrite, ?sargs); Some ?h = Some ?a ⊕ Some ?b⟧ ⟹ get_gs ?h = Some (pwrite, ?sargs)›*) by blast fix k have "get_gu a k ≠ None" by (meson all_guards_def (*‹all_guards (?h::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'i::type ⇒ ?'a::type list option)) = ((∃v::?'a::type multiset. get_gs ?h = Some (pwrite, v)) ∧ (∀k::?'i::type. get_gu ?h k ≠ None))›*) assms( (*‹all_guards (a::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option))›*) 1)) then show "get_gu h k ≠ None" apply (cases "get_gu b k") (*goals: 1. ‹⟦get_gu a k ≠ None; get_gu b k = None⟧ ⟹ get_gu h k ≠ None› 2. ‹⋀aa. ⟦get_gu a k ≠ None; get_gu b k = Some aa⟧ ⟹ get_gu h k ≠ None› discuss goal 1*) apply (metis assms( (*‹Some h = Some a ⊕ Some b›*) 2) full_uguard_sum_same (*‹⟦get_gu ?a ?k = Some ?uargs; Some ?h = Some ?a ⊕ Some ?b⟧ ⟹ get_gu ?h ?k = Some ?uargs›*) not_Some_eq (*‹(∀y. ?x ≠ Some y) = (?x = None)›*)) (*discuss goal 2*) apply (metis assms( (*‹Some h = Some a ⊕ Some b›*) 2) full_uguard_sum_same (*‹⟦get_gu ?a ?k = Some ?uargs; Some ?h = Some ?a ⊕ Some ?b⟧ ⟹ get_gu ?h ?k = Some ?uargs›*) option.discI (*‹?option = Some ?x2.0 ⟹ ?option ≠ None›*) plus_comm (*‹?a ⊕ ?b = ?b ⊕ ?a›*)) (*proven 2 subgoals*) . qed definition empty_unique where "empty_unique _ = None" definition remove_guards :: "('i, 'a) heap ⇒ ('i, 'a) heap" where "remove_guards h = (get_fh h, None, empty_unique)" lemma remove_guards_smaller: "h ≽ remove_guards h" proof (-) (*goal: ‹h ≽ remove_guards h›*) have "remove_guards h ## (Map.empty, get_gs h, get_gu h)" proof (rule compatibleI (*‹⟦compatible_fract_heaps (get_fh ?h) (get_fh ?h'); ⋀k. get_gu ?h k = None ∨ get_gu ?h' k = None; ⋀p p'. get_gs ?h = Some p ∧ get_gs ?h' = Some p' ⟹ pgte pwrite (padd (fst p) (fst p'))⟧ ⟹ ?h ## ?h'›*)) (*goals: 1. ‹compatible_fract_heaps (get_fh (remove_guards h)) (get_fh (λx. None, get_gs h, get_gu h))› 2. ‹⋀k. get_gu (remove_guards h) k = None ∨ get_gu (λx. None, get_gs h, get_gu h) k = None› 3. ‹⋀p p'. get_gs (remove_guards h) = Some p ∧ get_gs (λx. None, get_gs h, get_gu h) = Some p' ⟹ pgte pwrite (padd (fst p) (fst p'))›*) show "compatible_fract_heaps (get_fh (remove_guards h)) (get_fh (Map.empty, get_gs h, get_gu h))" using compatible_fract_heapsI (*‹⟦⋀l p p'. ?h l = Some p ∧ ?h' l = Some p' ⟹ pgte pwrite (padd (fst p) (fst p')); ⋀l p p'. ?h l = Some p ∧ ?h' l = Some p' ⟹ snd p = snd p'⟧ ⟹ compatible_fract_heaps ?h ?h'›*) by force show "⋀k. get_gu (remove_guards h) k = None ∨ get_gu (Map.empty, get_gs h, get_gu h) k = None" by (simp add: empty_unique_def (*‹empty_unique ?uu = None›*) remove_guards_def (*‹remove_guards ?h = (get_fh ?h, None, empty_unique)›*)) show "⋀p p'. get_gs (remove_guards h) = Some p ∧ get_gs (Map.empty, get_gs h, get_gu h) = Some p' ⟹ pgte pwrite (padd (fst p) (fst p'))" by (simp add: remove_guards_def (*‹remove_guards ?h = (get_fh ?h, None, empty_unique)›*)) qed then obtain x where "Some x = Some (remove_guards h) ⊕ Some (Map.empty, get_gs h, get_gu h)" (*goal: ‹(⋀x. Some x = Some (remove_guards h) ⊕ Some (λx. None, get_gs h, get_gu h) ⟹ thesis) ⟹ thesis›*) by auto moreover have "x = h" proof (rule heap_ext (*‹⟦get_fh ?a = get_fh ?b; get_gs ?a = get_gs ?b; get_gu ?a = get_gu ?b⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹get_fh x = get_fh h› 2. ‹get_gs x = get_gs h› 3. ‹get_gu x = get_gu h›*) show "get_fh x = get_fh h" by (metis add_fh_map_empty (*‹add_fh (?h::?'a::type ⇒ (prat × ?'b::type) option) (λx::?'a::type. None) = ?h›*) add_get_fh (*‹Some (?x::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'b::type ⇒ ?'a::type list option)) = Some (?a::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'b::type ⇒ ?'a::type list option)) ⊕ Some (?b::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'b::type ⇒ ?'a::type list option)) ⟹ get_fh ?x = add_fh (get_fh ?a) (get_fh ?b)›*) calculation (*‹Some (x::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option)) = Some (remove_guards (h::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option))) ⊕ Some (λx::nat. None, get_gs h, get_gu h)›*) fst_conv (*‹fst (?x1.0::?'a::type, ?x2.0::?'b::type) = ?x1.0›*) get_fh.elims (*‹⟦get_fh (?x::?'a::type × ?'b::type) = (?y::?'a::type); ⋀x::?'a::type × ?'b::type. ⟦?x = x; ?y = fst x⟧ ⟹ ?P::bool⟧ ⟹ ?P›*) remove_guards_def (*‹remove_guards (?h::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'i::type ⇒ ?'a::type list option)) = (get_fh ?h, None, empty_unique)›*)) show "get_gs x = get_gs h" by (metis calculation (*‹Some x = Some (remove_guards h) ⊕ Some (λx. None, get_gs h, get_gu h)›*) fst_eqD (*‹fst (?x, ?y) = ?a ⟹ ?x = ?a›*) get_gs.elims (*‹⟦get_gs ?x = ?y; ⋀x. ⟦?x = x; ?y = fst (snd x)⟧ ⟹ ?P⟧ ⟹ ?P›*) plus_comm (*‹?a ⊕ ?b = ?b ⊕ ?a›*) remove_guards_def (*‹remove_guards ?h = (get_fh ?h, None, empty_unique)›*) snd_eqD (*‹snd (?x, ?y) = ?a ⟹ ?y = ?a›*) sum_gs_one_none (*‹⟦Some ?x = Some ?a ⊕ Some ?b; get_gs ?b = None⟧ ⟹ get_gs ?x = get_gs ?a›*)) show "get_gu x = get_gu h" proof (rule ext (*‹(⋀x::?'a. (?f::?'a ⇒ ?'b) x = (?g::?'a ⇒ ?'b) x) ⟹ ?f = ?g›*)) (*goal: ‹⋀xa. get_gu x xa = get_gu h xa›*) fix k have "get_gu (remove_guards h) k = None" by (simp add: empty_unique_def (*‹empty_unique ?uu = None›*) remove_guards_def (*‹remove_guards ?h = (get_fh ?h, None, empty_unique)›*)) then show "get_gu x k = get_gu h k" by (metis (mono_tags, lifting) add_gu_def (*‹add_gu ?u1.0 ?u2.0 ?k = add_gu_single (?u1.0 ?k) (?u2.0 ?k)›*) add_gu_single.simps( (*‹add_gu_single None ?x = ?x›*) 1) calculation (*‹Some x = Some (remove_guards h) ⊕ Some (λx. None, get_gs h, get_gu h)›*) get_gu.elims (*‹⟦get_gu ?x = ?y; ⋀x. ⟦?x = x; ?y = snd (snd x)⟧ ⟹ ?P⟧ ⟹ ?P›*) plus_extract( (*‹Some ?x = Some ?a ⊕ Some ?b ⟹ get_gu ?x = add_gu (get_gu ?a) (get_gu ?b)›*) 3) snd_eqD (*‹snd (?x, ?y) = ?a ⟹ ?y = ?a›*)) qed qed ultimately show "?thesis" (*goal: ‹h ≽ remove_guards h›*) using larger_def (*‹?a ≽ ?b = (∃c. Some ?a = Some ?b ⊕ Some c)›*) by blast qed lemma no_guard_remove: assumes "Some a = Some b ⊕ Some c" and "no_guard c" shows "get_gs a = get_gs b" and "get_gu a = get_gu b" using assms(1) (*‹Some a = Some b ⊕ Some c›*) assms(2) (*‹no_guard c›*) no_guard_def (*‹no_guard ?h = (get_gs ?h = None ∧ (∀k. get_gu ?h k = None))›*) sum_gs_one_none (*‹⟦Some ?x = Some ?a ⊕ Some ?b; get_gs ?b = None⟧ ⟹ get_gs ?x = get_gs ?a›*) apply blast (*top goal: ‹get_gs a = get_gs b› and 1 goal remains*) proof (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹⋀x. get_gu a x = get_gu b x›*) fix k have "get_gu c k = None" by (meson assms( (*‹no_guard c›*) 2) no_guard_def (*‹no_guard ?h = (get_gs ?h = None ∧ (∀k. get_gu ?h k = None))›*)) then show "get_gu a k = get_gu b k" by (metis (no_types, lifting) add_gu_def (*‹add_gu ?u1.0 ?u2.0 ?k = add_gu_single (?u1.0 ?k) (?u2.0 ?k)›*) add_gu_single.simps( (*‹add_gu_single None ?x = ?x›*) 1) assms( (*‹Some a = Some b ⊕ Some c›*) 1) plus_comm (*‹?a ⊕ ?b = ?b ⊕ ?a›*) plus_extract( (*‹Some ?x = Some ?a ⊕ Some ?b ⟹ get_gu ?x = add_gu (get_gu ?a) (get_gu ?b)›*) 3)) qed lemma full_guard_comp_then_no: assumes "a ## b" and "all_guards a" shows "no_guard b" proof (rule no_guardI (*‹⟦get_gs (?h::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'b::type ⇒ ?'a::type list option)) = None; ⋀k::?'b::type. get_gu ?h k = None⟧ ⟹ no_guard ?h›*)) (*goals: 1. ‹get_gs b = None› 2. ‹⋀k. get_gu b k = None›*) show "⋀k. get_gu b k = None" by (meson all_guards_def (*‹all_guards ?h = ((∃v. get_gs ?h = Some (pwrite, v)) ∧ (∀k. get_gu ?h k ≠ None))›*) assms( (*‹a ## b›*) 1) assms( (*‹all_guards a›*) 2) compatible_def (*‹?h ## ?h' = (compatible_fract_heaps (get_fh ?h) (get_fh ?h') ∧ (∀k. get_gu ?h k = None ∨ get_gu ?h' k = None) ∧ (∀p p'. get_gs ?h = Some p ∧ get_gs ?h' = Some p' ⟶ pgte pwrite (padd (fst p) (fst p'))))›*)) show "get_gs b = None" proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹get_gs b ≠ None ⟹ False›*) assume "get_gs b ≠ None" (*‹get_gs (b::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) ≠ None›*) then obtain gb where "get_gs b = Some gb" (*goal: ‹(⋀gb. get_gs b = Some gb ⟹ thesis) ⟹ thesis›*) by blast moreover obtain v where "get_gs a = Some (pwrite, v)" (*goal: ‹(⋀v::'a multiset. get_gs (a::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) = Some (pwrite, v) ⟹ thesis::bool) ⟹ thesis›*) by (meson all_guards_def (*‹all_guards ?h = ((∃v. get_gs ?h = Some (pwrite, v)) ∧ (∀k. get_gu ?h k ≠ None))›*) assms( (*‹all_guards a›*) 2)) moreover have "pgt (padd pwrite (fst gb)) pwrite" using sum_larger (*‹pgt (padd ?a ?b) ?a›*) by auto ultimately show False by (metis assms( (*‹a ## b›*) 1) compatible_def (*‹?h ## ?h' = (compatible_fract_heaps (get_fh ?h) (get_fh ?h') ∧ (∀k. get_gu ?h k = None ∨ get_gu ?h' k = None) ∧ (∀p p'. get_gs ?h = Some p ∧ get_gs ?h' = Some p' ⟶ pgte pwrite (padd (fst p) (fst p'))))›*) fst_eqD (*‹fst (?x, ?y) = ?a ⟹ ?x = ?a›*) not_pgte_charact (*‹(¬ pgte ?a ?b) = pgt ?b ?a›*)) qed qed lemma sum_of_no_guards: assumes "no_guard a" and "no_guard b" and "Some x = Some a ⊕ Some b" shows "no_guard x" by (metis assms( (*‹no_guard a›*) 1) assms( (*‹no_guard b›*) 2) assms( (*‹Some x = Some a ⊕ Some b›*) 3) no_guard_def (*‹no_guard ?h = (get_gs ?h = None ∧ (∀k. get_gu ?h k = None))›*) no_guard_remove( (*‹⟦Some ?a = Some ?b ⊕ Some ?c; no_guard ?c⟧ ⟹ get_gs ?a = get_gs ?b›*) 1) no_guard_remove( (*‹⟦Some ?a = Some ?b ⊕ Some ?c; no_guard ?c⟧ ⟹ get_gu ?a = get_gu ?b›*) 2)) lemma no_guard_remove_guards: "no_guard (remove_guards h)" by (simp add: empty_unique_def (*‹empty_unique ?uu = None›*) no_guard_def (*‹no_guard ?h = (get_gs ?h = None ∧ (∀k. get_gu ?h k = None))›*) remove_guards_def (*‹remove_guards ?h = (get_fh ?h, None, empty_unique)›*)) lemma get_fh_remove_guards: "get_fh (remove_guards h) = get_fh h" by (simp add: remove_guards_def (*‹remove_guards ?h = (get_fh ?h, None, empty_unique)›*)) definition pair_sat :: "(store × ('i, 'a) heap) set ⇒ (store × ('i, 'a) heap) set ⇒ ('i, 'a, nat) assertion ⇒ bool" where "pair_sat S S' Q ⟷ (∀σ σ'. σ ∈ S ∧ σ' ∈ S' ⟶ σ, σ' ⊨ Q)" lemma pair_satI: assumes "⋀s h s' h'. (s, h) ∈ S ∧ (s', h') ∈ S' ⟹ (s, h), (s', h') ⊨ Q" shows "pair_sat S S' Q" by (simp add: assms (*‹(?s, ?h) ∈ S ∧ (?s', ?h') ∈ S' ⟹ (?s, ?h), (?s', ?h') ⊨ Q›*) pair_sat_def (*‹pair_sat ?S ?S' ?Q = (∀σ σ'. σ ∈ ?S ∧ σ' ∈ ?S' ⟶ σ, σ' ⊨ ?Q)›*)) lemma pair_sat_smallerI: assumes "⋀σ σ'. σ ∈ S ∧ σ' ∈ S' ⟹ σ, σ' ⊨ Q" shows "pair_sat S S' Q" by (simp add: assms (*‹?σ ∈ S ∧ ?σ' ∈ S' ⟹ ?σ, ?σ' ⊨ Q›*) pair_sat_def (*‹pair_sat ?S ?S' ?Q = (∀σ σ'. σ ∈ ?S ∧ σ' ∈ ?S' ⟶ σ, σ' ⊨ ?Q)›*)) lemma pair_satE: assumes "pair_sat S S' Q" and "(s, h) ∈ S ∧ (s', h') ∈ S'" shows "(s, h), (s', h') ⊨ Q" using assms(1) (*‹pair_sat S S' Q›*) assms(2) (*‹(s, h) ∈ S ∧ (s', h') ∈ S'›*) pair_sat_def (*‹pair_sat ?S ?S' ?Q = (∀σ σ'. σ ∈ ?S ∧ σ' ∈ ?S' ⟶ σ, σ' ⊨ ?Q)›*) by blast definition add_states :: "(store × ('i, 'a) heap) set ⇒ (store × ('i, 'a) heap) set ⇒ (store × ('i, 'a) heap) set" where "add_states S1 S2 = {(s, H) |s H h1 h2. Some H = Some h1 ⊕ Some h2 ∧ (s, h1) ∈ S1 ∧ (s, h2) ∈ S2}" lemma add_states_sat_star: assumes "pair_sat SA SA' A" and "pair_sat SB SB' B" shows "pair_sat (add_states SA SB) (add_states SA' SB') (Star A B)" proof (rule pair_satI (*‹(⋀s h s' h'. (s, h) ∈ ?S ∧ (s', h') ∈ ?S' ⟹ (s, h), (s', h') ⊨ ?Q) ⟹ pair_sat ?S ?S' ?Q›*)) (*goal: ‹⋀s h s' h'. (s, h) ∈ add_states SA SB ∧ (s', h') ∈ add_states SA' SB' ⟹ (s, h), (s', h') ⊨ A * B›*) fix s and h and s' and h' assume asm0: "(s, h) ∈ add_states SA SB ∧ (s', h') ∈ add_states SA' SB'" (*‹(s::char list ⇒ nat, h::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) ∈ add_states (SA::((char list ⇒ nat) × (nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) set) (SB::((char list ⇒ nat) × (nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) set) ∧ (s'::char list ⇒ nat, h'::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) ∈ add_states (SA'::((char list ⇒ nat) × (nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) set) (SB'::((char list ⇒ nat) × (nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) set)›*) then obtain ha and hb and ha' and hb' where "(s, ha) ∈ SA" "(s, hb) ∈ SB" "(s', ha') ∈ SA'" "(s', hb') ∈ SB'" "Some h = Some ha ⊕ Some hb" "Some h' = Some ha' ⊕ Some hb'" (*goal: ‹(⋀ha hb ha' hb'. ⟦(s, ha) ∈ SA; (s, hb) ∈ SB; (s', ha') ∈ SA'; (s', hb') ∈ SB'; Some h = Some ha ⊕ Some hb; Some h' = Some ha' ⊕ Some hb'⟧ ⟹ thesis) ⟹ thesis›*) using add_states_def[of SA SB] (*‹add_states SA SB = {uu_. ∃s H h1 h2. uu_ = (s, H) ∧ Some H = Some h1 ⊕ Some h2 ∧ (s, h1) ∈ SA ∧ (s, h2) ∈ SB}›*) add_states_def[of SA' SB'] (*‹add_states SA' SB' = {uu_. ∃s H h1 h2. uu_ = (s, H) ∧ Some H = Some h1 ⊕ Some h2 ∧ (s, h1) ∈ SA' ∧ (s, h2) ∈ SB'}›*) fst_eqD (*‹fst (?x, ?y) = ?a ⟹ ?x = ?a›*) mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*) snd_conv (*‹snd (?x1.0::?'aa, ?x2.0::?'a) = ?x2.0›*) by auto then show "(s, h), (s', h') ⊨ Star A B" by (meson assms( (*‹pair_sat SA SA' A›*) 1) assms( (*‹pair_sat SB SB' B›*) 2) hyper_sat.simps( (*‹((?s, ?h), (?s', ?h') ⊨ ?A * ?B) = (∃h1 h2 h1' h2'. Some ?h = Some h1 ⊕ Some h2 ∧ Some ?h' = Some h1' ⊕ Some h2' ∧ (?s, h1), (?s', h1') ⊨ ?A ∧ (?s, h2), (?s', h2') ⊨ ?B)›*) 4) pair_sat_def (*‹pair_sat ?S ?S' ?Q = (∀σ σ'. σ ∈ ?S ∧ σ' ∈ ?S' ⟶ σ, σ' ⊨ ?Q)›*)) qed lemma add_states_subset: assumes "S1 ⊆ S1'" shows "add_states S1 S2 ⊆ add_states S1' S2" proof (standard) (*goal: ‹⋀x::(char list ⇒ nat) × (nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option). x ∈ add_states (S1::((char list ⇒ nat) × (nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) set) (S2::((char list ⇒ nat) × (nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) set) ⟹ x ∈ add_states (S1'::((char list ⇒ nat) × (nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) set) S2›*) fix x assume "x ∈ add_states S1 S2" (*‹(x::(char list ⇒ nat) × (nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) ∈ add_states (S1::((char list ⇒ nat) × (nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) set) (S2::((char list ⇒ nat) × (nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) set)›*) then show "x ∈ add_states S1' S2" using add_states_def[of S1 S2] (*‹add_states S1 S2 = {uu_. ∃s H h1 h2. uu_ = (s, H) ∧ Some H = Some h1 ⊕ Some h2 ∧ (s, h1) ∈ S1 ∧ (s, h2) ∈ S2}›*) add_states_def[of S1' S2] (*‹add_states S1' S2 = {uu_. ∃s H h1 h2. uu_ = (s, H) ∧ Some H = Some h1 ⊕ Some h2 ∧ (s, h1) ∈ S1' ∧ (s, h2) ∈ S2}›*) assms (*‹S1 ⊆ S1'›*) mem_Collect_eq[of x] (*‹((x::(char list ⇒ nat) × (nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) ∈ Collect (?P::(char list ⇒ nat) × (nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option) ⇒ bool)) = ?P x›*) subsetD[of S1 S1'] (*‹⟦S1 ⊆ S1'; ?c ∈ S1⟧ ⟹ ?c ∈ S1'›*) by blast qed lemma add_states_comm: "add_states S1 S2 = add_states S2 S1" proof (-) (*goal: ‹add_states S1 S2 = add_states S2 S1›*) have "⋀S1 S2. add_states S1 S2 ⊆ add_states S2 S1" proof (-) (*goal: ‹⋀(S1::((char list ⇒ nat) × (nat ⇒ (prat × nat) option) × (prat × 'c::type multiset) option × ('d::type ⇒ 'c::type list option)) set) S2::((char list ⇒ nat) × (nat ⇒ (prat × nat) option) × (prat × 'c::type multiset) option × ('d::type ⇒ 'c::type list option)) set. add_states S1 S2 ⊆ add_states S2 S1›*) fix S1 and S2 show "add_states S1 S2 ⊆ add_states S2 S1" proof (standard) (*goal: ‹⋀x::(char list ⇒ nat) × (nat ⇒ (prat × nat) option) × (prat × 'e::type multiset) option × ('f::type ⇒ 'e::type list option). x ∈ add_states (S1::((char list ⇒ nat) × (nat ⇒ (prat × nat) option) × (prat × 'e::type multiset) option × ('f::type ⇒ 'e::type list option)) set) (S2::((char list ⇒ nat) × (nat ⇒ (prat × nat) option) × (prat × 'e::type multiset) option × ('f::type ⇒ 'e::type list option)) set) ⟹ x ∈ add_states S2 S1›*) fix x assume "x ∈ add_states S1 S2" (*‹(x::(char list ⇒ nat) × (nat ⇒ (prat × nat) option) × (prat × 'e multiset) option × ('f ⇒ 'e list option)) ∈ add_states (S1::((char list ⇒ nat) × (nat ⇒ (prat × nat) option) × (prat × 'e multiset) option × ('f ⇒ 'e list option)) set) (S2::((char list ⇒ nat) × (nat ⇒ (prat × nat) option) × (prat × 'e multiset) option × ('f ⇒ 'e list option)) set)›*) then obtain h1 and h2 where "Some (snd x) = Some h1 ⊕ Some h2" "(fst x, h1) ∈ S1" "(fst x, h2) ∈ S2" (*goal: ‹(⋀h1 h2. ⟦Some (snd x) = Some h1 ⊕ Some h2; (fst x, h1) ∈ S1; (fst x, h2) ∈ S2⟧ ⟹ thesis) ⟹ thesis›*) using add_states_def[of S1 S2] (*‹add_states S1 S2 = {uu_. ∃s H h1 h2. uu_ = (s, H) ∧ Some H = Some h1 ⊕ Some h2 ∧ (s, h1) ∈ S1 ∧ (s, h2) ∈ S2}›*) fst_conv (*‹fst (?x1.0, ?x2.0) = ?x1.0›*) mem_Collect_eq[of x] (*‹(x ∈ Collect ?P) = ?P x›*) snd_eqD (*‹snd (?x, ?y) = ?a ⟹ ?y = ?a›*) by auto moreover have "Some (snd x) = Some h2 ⊕ Some h1" by (simp add: calculation( (*‹Some (snd x) = Some h1 ⊕ Some h2›*) 1) plus_comm (*‹?a ⊕ ?b = ?b ⊕ ?a›*)) ultimately show "x ∈ add_states S2 S1" using add_states_def[of S2 S1] (*‹add_states S2 S1 = {uu_. ∃s H h1 h2. uu_ = (s, H) ∧ Some H = Some h1 ⊕ Some h2 ∧ (s, h1) ∈ S2 ∧ (s, h2) ∈ S1}›*) mem_Collect_eq[of x] (*‹(x ∈ Collect ?P) = ?P x›*) surjective_pairing[of x] (*‹x = (fst x, snd x)›*) by blast qed qed then show "?thesis" (*goal: ‹add_states S1 S2 = add_states S2 S1›*) by blast qed lemma magic_lemma: assumes "Some x1 = Some a1 ⊕ Some j1" and "Some x2 = Some a2 ⊕ Some j2" and "(s1, x1), (s2, x2) ⊨ Star A J" and "(s1, j1), (s2, j2) ⊨ J" and "precise J" shows "(s1, a1), (s2, a2) ⊨ A" proof (-) (*goal: ‹(s1, a1), (s2, a2) ⊨ A›*) obtain a1' and a2' and j1' and j2' where "Some x1 = Some a1' ⊕ Some j1'" "Some x2 = Some a2' ⊕ Some j2'" "(s1, j1'), (s2, j2') ⊨ J" "(s1, a1'), (s2, a2') ⊨ A" (*goal: ‹(⋀a1' j1' a2' j2'. ⟦Some x1 = Some a1' ⊕ Some j1'; Some x2 = Some a2' ⊕ Some j2'; (s1, j1'), (s2, j2') ⊨ J; (s1, a1'), (s2, a2') ⊨ A⟧ ⟹ thesis) ⟹ thesis›*) using assms(3) (*‹(s1::char list ⇒ nat, x1::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option)), (s2::char list ⇒ nat, x2::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option)) ⊨ A::('b::type, 'a::type, nat) assertion * J::('b::type, 'a::type, nat) assertion›*) hyper_sat.simps(4) (*‹((?s, ?h), (?s', ?h') ⊨ ?A * ?B) = (∃h1 h2 h1' h2'. Some ?h = Some h1 ⊕ Some h2 ∧ Some ?h' = Some h1' ⊕ Some h2' ∧ (?s, h1), (?s', h1') ⊨ ?A ∧ (?s, h2), (?s', h2') ⊨ ?B)›*) by blast have "j1 = j1' ∧ j2 = j2'" using assms(5) (*‹precise J›*) proof (rule preciseE (*‹⟦precise (?J::(?'a::type, ?'b::type, nat) assertion); (?H1.0::(nat ⇒ (prat × nat) option) × (prat × ?'b::type multiset) option × (?'a::type ⇒ ?'b::type list option)) ≽ (?h1.0::(nat ⇒ (prat × nat) option) × (prat × ?'b::type multiset) option × (?'a::type ⇒ ?'b::type list option)) ∧ ?H1.0 ≽ (?h1'::(nat ⇒ (prat × nat) option) × (prat × ?'b::type multiset) option × (?'a::type ⇒ ?'b::type list option)) ∧ (?H2.0::(nat ⇒ (prat × nat) option) × (prat × ?'b::type multiset) option × (?'a::type ⇒ ?'b::type list option)) ≽ (?h2.0::(nat ⇒ (prat × nat) option) × (prat × ?'b::type multiset) option × (?'a::type ⇒ ?'b::type list option)) ∧ ?H2.0 ≽ (?h2'::(nat ⇒ (prat × nat) option) × (prat × ?'b::type multiset) option × (?'a::type ⇒ ?'b::type list option)); (?s1.0::char list ⇒ nat, ?h1.0), (?s2.0::char list ⇒ nat, ?h2.0) ⊨ ?J ∧ (?s1.0, ?h1'), (?s2.0, ?h2') ⊨ ?J⟧ ⟹ ?h1' = ?h1.0 ∧ ?h2' = ?h2.0›*)) (*goals: 1. ‹(?H1.0::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) ≽ (j1'::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) ∧ ?H1.0 ≽ (j1::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) ∧ (?H2.0::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) ≽ (j2'::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) ∧ ?H2.0 ≽ (j2::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option))› 2. ‹(?s1.0::char list ⇒ nat, j1'::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)), (?s2.0::char list ⇒ nat, j2'::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) ⊨ (J::('b, 'a, nat) assertion) ∧ (?s1.0, j1::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)), (?s2.0, j2::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) ⊨ J›*) show "x1 ≽ j1' ∧ x1 ≽ j1 ∧ x2 ≽ j2' ∧ x2 ≽ j2" by (metis ‹Some x1 = Some a1' ⊕ Some j1'› ‹Some x2 = Some a2' ⊕ Some j2'› assms( (*‹Some x1 = Some a1 ⊕ Some j1›*) 1) assms( (*‹Some x2 = Some a2 ⊕ Some j2›*) 2) larger_def (*‹?a ≽ ?b = (∃c. Some ?a = Some ?b ⊕ Some c)›*) plus_comm (*‹?a ⊕ ?b = ?b ⊕ ?a›*)) show "(s1, j1'), (s2, j2') ⊨ J ∧ (s1, j1), (s2, j2) ⊨ J" by (simp add: ‹(s1, j1'), (s2, j2') ⊨ J› assms( (*‹(s1::char list ⇒ nat, j1::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option)), (s2::char list ⇒ nat, j2::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option)) ⊨ (J::('b::type, 'a::type, nat) assertion)›*) 4)) qed then have "a1 = a1' ∧ a2 = a2'" using ‹Some x1 = Some a1' ⊕ Some j1'› (*‹Some x1 = Some a1' ⊕ Some j1'›*) ‹Some x2 = Some a2' ⊕ Some j2'› (*‹Some (x2::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) = Some (a2'::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) ⊕ Some (j2'::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option))›*) addition_cancellative (*‹⟦Some ?a = Some ?b ⊕ Some ?c; Some ?a = Some ?b' ⊕ Some ?c⟧ ⟹ ?b = ?b'›*) assms(1) (*‹Some (x1::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) = Some (a1::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) ⊕ Some (j1::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option))›*) assms(2) (*‹Some x2 = Some a2 ⊕ Some j2›*) by blast then show "?thesis" (*goal: ‹(s1, a1), (s2, a2) ⊨ A›*) using ‹(s1, a1'), (s2, a2') ⊨ A› (*‹(s1, a1'), (s2, a2') ⊨ A›*) by blast qed lemma full_no_guard_same_normalize: assumes "full_ownership (get_fh h) ∧ no_guard h" and "full_ownership (get_fh h') ∧ no_guard h'" and "normalize (get_fh h) = normalize (get_fh h')" shows "h = h'" proof (rule heap_ext (*‹⟦get_fh ?a = get_fh ?b; get_gs ?a = get_gs ?b; get_gu ?a = get_gu ?b⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹get_fh h = get_fh h'› 2. ‹get_gs h = get_gs h'› 3. ‹get_gu h = get_gu h'›*) show "get_gu h = get_gu h'" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹get_gu h = get_gu h'›*) by (metis assms( (*‹full_ownership (get_fh h) ∧ no_guard h›*) 1) assms( (*‹full_ownership (get_fh h') ∧ no_guard h'›*) 2) no_guard_def (*‹no_guard ?h = (get_gs ?h = None ∧ (∀k. get_gu ?h k = None))›*)) show "get_gs h = get_gs h'" by (metis assms( (*‹full_ownership (get_fh h) ∧ no_guard h›*) 1) assms( (*‹full_ownership (get_fh h') ∧ no_guard h'›*) 2) no_guard_def (*‹no_guard ?h = (get_gs ?h = None ∧ (∀k. get_gu ?h k = None))›*)) show "get_fh h = get_fh h'" proof (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹⋀x. get_fh h x = get_fh h' x›*) fix l show "get_fh h l = get_fh h' l" apply (cases "get_fh h l") (*goals: 1. ‹get_fh h l = None ⟹ get_fh h l = get_fh h' l› 2. ‹⋀a. get_fh h l = Some a ⟹ get_fh h l = get_fh h' l› discuss goal 1*) apply (metis FractionalHeap.normalize_eq( (*‹(FractionalHeap.normalize (?h::?'b ⇒ (prat × ?'a) option) (?l::?'b) = None) = (?h ?l = None)›*) 1) assms( (*‹FractionalHeap.normalize (get_fh (h::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option))) = FractionalHeap.normalize (get_fh (h'::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)))›*) 3)) (*discuss goal 2*) apply (cases "get_fh h' l") (*goals: 1. ‹⋀a::prat × nat. ⟦get_fh (h::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) (l::nat) = Some a; get_fh (h'::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) l = None⟧ ⟹ get_fh h l = get_fh h' l› 2. ‹⋀(a::prat × nat) aa::prat × nat. ⟦get_fh (h::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) (l::nat) = Some a; get_fh (h'::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) l = Some aa⟧ ⟹ get_fh h l = get_fh h' l› discuss goal 1*) apply (metis FractionalHeap.normalize_eq( (*‹(FractionalHeap.normalize ?h ?l = None) = (?h ?l = None)›*) 1) assms( (*‹FractionalHeap.normalize (get_fh h) = FractionalHeap.normalize (get_fh h')›*) 3)) (*discuss goal 2*) apply (metis FractionalHeap.normalize_def (*‹FractionalHeap.normalize ?h ?l = apply_opt snd (?h ?l)›*) apply_opt.simps( (*‹apply_opt ?f (Some ?x) = Some (?f ?x)›*) 2) assms( (*‹full_ownership (get_fh h) ∧ no_guard h›*) 1) assms( (*‹full_ownership (get_fh h') ∧ no_guard h'›*) 2) assms( (*‹FractionalHeap.normalize (get_fh h) = FractionalHeap.normalize (get_fh h')›*) 3) full_ownership_def (*‹full_ownership ?h = (∀l p. ?h l = Some p ⟶ fst p = pwrite)›*) prod.collapse (*‹(fst ?prod, snd ?prod) = ?prod›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) . qed qed lemma get_fh_same_then_remove_guards_same: assumes "get_fh a = get_fh b" shows "remove_guards a = remove_guards b" by (metis assms (*‹get_fh a = get_fh b›*) remove_guards_def (*‹remove_guards ?h = (get_fh ?h, None, empty_unique)›*)) lemma remove_guards_sum: assumes "Some x = Some a ⊕ Some b" shows "Some (remove_guards x) = Some (remove_guards a) ⊕ Some (remove_guards b)" proof (-) (*goal: ‹Some (remove_guards (x::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option))) = Some (remove_guards (a::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option))) ⊕ Some (remove_guards (b::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)))›*) have "remove_guards a ## remove_guards b" by (metis (no_types, lifting) assms (*‹Some x = Some a ⊕ Some b›*) compatible_def (*‹?h ## ?h' = (compatible_fract_heaps (get_fh ?h) (get_fh ?h') ∧ (∀k. get_gu ?h k = None ∨ get_gu ?h' k = None) ∧ (∀p p'. get_gs ?h = Some p ∧ get_gs ?h' = Some p' ⟶ pgte pwrite (padd (fst p) (fst p'))))›*) compatible_eq (*‹(Some ?a ⊕ Some ?b = None) = (¬ ?a ## ?b)›*) get_fh_remove_guards (*‹get_fh (remove_guards ?h) = get_fh ?h›*) no_guard_def (*‹no_guard ?h = (get_gs ?h = None ∧ (∀k. get_gu ?h k = None))›*) no_guard_remove_guards (*‹no_guard (remove_guards ?h)›*) option.distinct( (*‹None ≠ Some ?x2.0›*) 1)) then obtain y where "Some y = Some (remove_guards a) ⊕ Some (remove_guards b)" (*goal: ‹(⋀y. Some y = Some (remove_guards a) ⊕ Some (remove_guards b) ⟹ thesis) ⟹ thesis›*) by auto moreover have "remove_guards x = y" by (metis (no_types, lifting) ‹remove_guards a ## remove_guards b› add_get_fh (*‹Some ?x = Some ?a ⊕ Some ?b ⟹ get_fh ?x = add_fh (get_fh ?a) (get_fh ?b)›*) assms (*‹Some x = Some a ⊕ Some b›*) calculation (*‹Some y = Some (remove_guards a) ⊕ Some (remove_guards b)›*) get_fh_remove_guards (*‹get_fh (remove_guards ?h) = get_fh ?h›*) get_gu.simps (*‹get_gu ?x = snd (snd ?x)›*) no_guard_def (*‹no_guard ?h = (get_gs ?h = None ∧ (∀k. get_gu ?h k = None))›*) no_guard_remove( (*‹⟦Some ?a = Some ?b ⊕ Some ?c; no_guard ?c⟧ ⟹ get_gs ?a = get_gs ?b›*) 1) no_guard_remove( (*‹⟦Some ?a = Some ?b ⊕ Some ?c; no_guard ?c⟧ ⟹ get_gu ?a = get_gu ?b›*) 2) no_guard_remove_guards (*‹no_guard (remove_guards ?h)›*) option.inject (*‹(Some ?x2.0 = Some ?y2.0) = (?x2.0 = ?y2.0)›*) plus.simps( (*‹Some ?h1.0 ⊕ Some ?h2.0 = (if ?h1.0 ## ?h2.0 then Some (add_fh (get_fh ?h1.0) (get_fh ?h2.0), add_gs (get_gs ?h1.0) (get_gs ?h2.0), add_gu (get_gu ?h1.0) (get_gu ?h2.0)) else None)›*) 3) plus_extract( (*‹Some ?x = Some ?a ⊕ Some ?b ⟹ get_gs ?x = add_gs (get_gs ?a) (get_gs ?b)›*) 2) remove_guards_def (*‹remove_guards ?h = (get_fh ?h, None, empty_unique)›*) snd_eqD (*‹snd (?x, ?y) = ?a ⟹ ?y = ?a›*)) ultimately show "?thesis" (*goal: ‹Some (remove_guards x) = Some (remove_guards a) ⊕ Some (remove_guards b)›*) by blast qed lemma no_guard_smaller: assumes "a ≽ b" shows "remove_guards a ≽ remove_guards b" using assms (*‹a ≽ b›*) larger_def (*‹(?a::(nat ⇒ (prat × nat) option) × (prat × ?'a multiset) option × (?'i ⇒ ?'a list option)) ≽ (?b::(nat ⇒ (prat × nat) option) × (prat × ?'a multiset) option × (?'i ⇒ ?'a list option)) = (∃c::(nat ⇒ (prat × nat) option) × (prat × ?'a multiset) option × (?'i ⇒ ?'a list option). Some ?a = Some ?b ⊕ Some c)›*) remove_guards_sum (*‹Some ?x = Some ?a ⊕ Some ?b ⟹ Some (remove_guards ?x) = Some (remove_guards ?a) ⊕ Some (remove_guards ?b)›*) by blast definition add_empty_guards :: "('i, 'a) heap ⇒ ('i, 'a) heap" where "add_empty_guards h = (get_fh h, Some (pwrite, {#}), (λ_. Some []))" lemma no_guard_map_empty_compatible: assumes "no_guard a" and "get_fh b = Map.empty" shows "a ## b" by (metis (no_types, lifting) assms( (*‹no_guard a›*) 1) assms( (*‹get_fh b = (λx. None)›*) 2) compatible_def (*‹?h ## ?h' = (compatible_fract_heaps (get_fh ?h) (get_fh ?h') ∧ (∀k. get_gu ?h k = None ∨ get_gu ?h' k = None) ∧ (∀p p'. get_gs ?h = Some p ∧ get_gs ?h' = Some p' ⟶ pgte pwrite (padd (fst p) (fst p'))))›*) compatible_fract_heapsI (*‹⟦⋀l p p'. ?h l = Some p ∧ ?h' l = Some p' ⟹ pgte pwrite (padd (fst p) (fst p')); ⋀l p p'. ?h l = Some p ∧ ?h' l = Some p' ⟹ snd p = snd p'⟧ ⟹ compatible_fract_heaps ?h ?h'›*) no_guard_def (*‹no_guard ?h = (get_gs ?h = None ∧ (∀k. get_gu ?h k = None))›*) option.simps( (*‹Some ?x2.0 ≠ None›*) 3)) lemma no_guard_add_empty_is_add: assumes "no_guard h" shows "Some (add_empty_guards h) = Some h ⊕ Some (Map.empty, Some (pwrite, {#}), (λ_. Some []))" proof (-) (*goal: ‹Some (add_empty_guards h) = Some h ⊕ Some (λx. None, Some (pwrite, {#}), λ_. Some [])›*) obtain x where "Some x = Some h ⊕ Some (Map.empty, Some (pwrite, {#}), (λ_. Some []))" (*goal: ‹(⋀x::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option). Some x = Some (h::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) ⊕ Some (λx::nat. None, Some (pwrite, {#}), λ_::'b. Some []) ⟹ thesis::bool) ⟹ thesis›*) by (simp add: assms (*‹no_guard h›*) no_guard_map_empty_compatible (*‹⟦no_guard ?a; get_fh ?b = (λx. None)⟧ ⟹ ?a ## ?b›*)) moreover have "add_empty_guards h = x" proof (rule heap_ext (*‹⟦get_fh ?a = get_fh ?b; get_gs ?a = get_gs ?b; get_gu ?a = get_gu ?b⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹get_fh (add_empty_guards h) = get_fh x› 2. ‹get_gs (add_empty_guards h) = get_gs x› 3. ‹get_gu (add_empty_guards h) = get_gu x›*) show "get_fh (add_empty_guards h) = get_fh x" by (metis add_empty_guards_def (*‹add_empty_guards ?h = (get_fh ?h, Some (pwrite, {#}), λ_. Some [])›*) add_fh_map_empty (*‹add_fh ?h (λx. None) = ?h›*) add_get_fh (*‹Some ?x = Some ?a ⊕ Some ?b ⟹ get_fh ?x = add_fh (get_fh ?a) (get_fh ?b)›*) calculation (*‹Some x = Some h ⊕ Some (λx. None, Some (pwrite, {#}), λ_. Some [])›*) fst_conv (*‹fst (?x1.0, ?x2.0) = ?x1.0›*) get_fh.elims (*‹⟦get_fh ?x = ?y; ⋀x. ⟦?x = x; ?y = fst x⟧ ⟹ ?P⟧ ⟹ ?P›*)) show "get_gs (add_empty_guards h) = get_gs x" by (metis add_empty_guards_def (*‹add_empty_guards ?h = (get_fh ?h, Some (pwrite, {#}), λ_. Some [])›*) assms (*‹no_guard h›*) calculation (*‹Some x = Some h ⊕ Some (λx. None, Some (pwrite, {#}), λ_. Some [])›*) get_gs.elims (*‹⟦get_gs ?x = ?y; ⋀x. ⟦?x = x; ?y = fst (snd x)⟧ ⟹ ?P⟧ ⟹ ?P›*) no_guard_remove( (*‹⟦Some ?a = Some ?b ⊕ Some ?c; no_guard ?c⟧ ⟹ get_gs ?a = get_gs ?b›*) 1) plus_comm (*‹?a ⊕ ?b = ?b ⊕ ?a›*) snd_eqD (*‹snd (?x, ?y) = ?a ⟹ ?y = ?a›*)) show "get_gu (add_empty_guards h) = get_gu x" by (metis add_empty_guards_def (*‹add_empty_guards ?h = (get_fh ?h, Some (pwrite, {#}), λ_. Some [])›*) assms (*‹no_guard h›*) calculation (*‹Some x = Some h ⊕ Some (λx. None, Some (pwrite, {#}), λ_. Some [])›*) get_gu.elims (*‹⟦get_gu ?x = ?y; ⋀x. ⟦?x = x; ?y = snd (snd x)⟧ ⟹ ?P⟧ ⟹ ?P›*) no_guard_remove( (*‹⟦Some ?a = Some ?b ⊕ Some ?c; no_guard ?c⟧ ⟹ get_gu ?a = get_gu ?b›*) 2) plus_comm (*‹?a ⊕ ?b = ?b ⊕ ?a›*) snd_eqD (*‹snd (?x, ?y) = ?a ⟹ ?y = ?a›*)) qed ultimately show "?thesis" (*goal: ‹Some (add_empty_guards (h::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option))) = Some h ⊕ Some (λx::nat. None, Some (pwrite, {#}), λ_::'b. Some [])›*) by blast qed lemma no_guard_and_sat_p_empty_guards: assumes "(s, h), (s', h') ⊨ A" and "no_guard h ∧ no_guard h'" shows "(s, add_empty_guards h), (s', add_empty_guards h') ⊨ Star A EmptyFullGuards" proof (-) (*goal: ‹(s::char list ⇒ nat, add_empty_guards (h::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option))), (s'::char list ⇒ nat, add_empty_guards (h'::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option))) ⊨ A::('b, 'a, nat) assertion * EmptyFullGuards›*) have "(s, (Map.empty, Some (pwrite, {#}), (λ_. Some []))), (s', (Map.empty, Some (pwrite, {#}), (λ_. Some []))) ⊨ EmptyFullGuards" by simp then show "?thesis" (*goal: ‹(s::char list ⇒ nat, add_empty_guards (h::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option))), (s'::char list ⇒ nat, add_empty_guards (h'::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option))) ⊨ A::('b, 'a, nat) assertion * EmptyFullGuards›*) using assms(1) (*‹(s::char list ⇒ nat, h::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)), (s'::char list ⇒ nat, h'::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) ⊨ (A::('b, 'a, nat) assertion)›*) assms(2) (*‹no_guard (h::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) ∧ no_guard (h'::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option))›*) hyper_sat.simps(4) (*‹((?s::char list ⇒ nat, ?h::(nat ⇒ (prat × nat) option) × (prat × ?'a multiset) option × (?'i ⇒ ?'a list option)), (?s'::char list ⇒ nat, ?h'::(nat ⇒ (prat × nat) option) × (prat × ?'a multiset) option × (?'i ⇒ ?'a list option)) ⊨ ?A::(?'i, ?'a, nat) assertion * ?B::(?'i, ?'a, nat) assertion) = (∃(h1::(nat ⇒ (prat × nat) option) × (prat × ?'a multiset) option × (?'i ⇒ ?'a list option)) (h2::(nat ⇒ (prat × nat) option) × (prat × ?'a multiset) option × (?'i ⇒ ?'a list option)) (h1'::(nat ⇒ (prat × nat) option) × (prat × ?'a multiset) option × (?'i ⇒ ?'a list option)) h2'::(nat ⇒ (prat × nat) option) × (prat × ?'a multiset) option × (?'i ⇒ ?'a list option). Some ?h = Some h1 ⊕ Some h2 ∧ Some ?h' = Some h1' ⊕ Some h2' ∧ (?s, h1), (?s', h1') ⊨ ?A ∧ (?s, h2), (?s', h2') ⊨ ?B)›*) no_guard_add_empty_is_add (*‹no_guard ?h ⟹ Some (add_empty_guards ?h) = Some ?h ⊕ Some (λx. None, Some (pwrite, {#}), λ_. Some [])›*) by blast qed lemma no_guard_add_empty_guards_sum: assumes "no_guard x" and "Some x = Some a ⊕ Some b" shows "Some (add_empty_guards x) = Some (add_empty_guards a) ⊕ Some b" using assms(1) (*‹no_guard (x::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option))›*) assms(2) (*‹Some (x::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option)) = Some (a::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option)) ⊕ Some (b::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option))›*) no_guard_add_empty_is_add[of a] (*‹no_guard a ⟹ Some (add_empty_guards a) = Some a ⊕ Some (λx. None, Some (pwrite, {#}), λ_. Some [])›*) no_guard_add_empty_is_add[of x] (*‹no_guard (x::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) ⟹ Some (add_empty_guards x) = Some x ⊕ Some (λx::nat. None, Some (pwrite, {#}), λ_::'b. Some [])›*) no_guard_then_smaller_same[of x a b] (*‹⟦Some x = Some a ⊕ Some b; no_guard x⟧ ⟹ no_guard a›*) plus_asso (*‹?a ⊕ ?b ⊕ ?c = ?a ⊕ (?b ⊕ ?c)›*) plus_comm (*‹?a ⊕ ?b = ?b ⊕ ?a›*) by (metis (no_types, lifting)) lemma semi_consistent_empty_no_guard_initial_value: assumes "no_guard h" shows "semi_consistent Γ (view Γ (FractionalHeap.normalize (get_fh h))) (add_empty_guards h)" proof (rule semi_consistentI (*‹⟦all_guards ?h; reachable ?Γ ?v0.0 ?h⟧ ⟹ semi_consistent ?Γ ?v0.0 ?h›*)) (*goals: 1. ‹all_guards (add_empty_guards h)› 2. ‹reachable Γ (view Γ (FractionalHeap.normalize (get_fh h))) (add_empty_guards h)›*) show "all_guards (add_empty_guards h)" by (simp add: add_empty_guards_def (*‹add_empty_guards ?h = (get_fh ?h, Some (pwrite, {#}), λ_. Some [])›*) all_guards_def (*‹all_guards ?h = ((∃v. get_gs ?h = Some (pwrite, v)) ∧ (∀k. get_gu ?h k ≠ None))›*)) show "reachable Γ (view Γ (FractionalHeap.normalize (get_fh h))) (add_empty_guards h)" proof (rule reachableI (*‹(⋀sargs uargs. get_gs ?h = Some (pwrite, sargs) ∧ (∀k. get_gu ?h k = Some (uargs k)) ⟹ reachable_value (saction ?scont) (uaction ?scont) ?v0.0 sargs uargs (view ?scont (FractionalHeap.normalize (get_fh ?h)))) ⟹ reachable ?scont ?v0.0 ?h›*)) (*goal: ‹⋀sargs uargs. get_gs (add_empty_guards h) = Some (pwrite, sargs) ∧ (∀k. get_gu (add_empty_guards h) k = Some (uargs k)) ⟹ reachable_value (saction Γ) (uaction Γ) (view Γ (FractionalHeap.normalize (get_fh h))) sargs uargs (view Γ (FractionalHeap.normalize (get_fh (add_empty_guards h))))›*) fix sargs and uargs assume asm0: "get_gs (add_empty_guards h) = Some (pwrite, sargs) ∧ (∀k. get_gu (add_empty_guards h) k = Some (uargs k))" (*‹get_gs (add_empty_guards (h::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option))) = Some (pwrite, sargs::'a multiset) ∧ (∀k::'b. get_gu (add_empty_guards h) k = Some ((uargs::'b ⇒ 'a list) k))›*) then have "sargs = {#} ∧ uargs = (λk. [])" by (metis add_empty_guards_def (*‹add_empty_guards ?h = (get_fh ?h, Some (pwrite, {#}), λ_. Some [])›*) fst_conv (*‹fst (?x1.0, ?x2.0) = ?x1.0›*) get_gs.simps (*‹get_gs ?x = fst (snd ?x)›*) get_gu.simps (*‹get_gu ?x = snd (snd ?x)›*) option.sel (*‹the (Some ?x2.0) = ?x2.0›*) snd_conv (*‹snd (?x1.0, ?x2.0) = ?x2.0›*)) then show "reachable_value (saction Γ) (uaction Γ) (view Γ (FractionalHeap.normalize (get_fh h))) sargs uargs (view Γ (FractionalHeap.normalize (get_fh (add_empty_guards h))))" by (simp add: Self (*‹reachable_value (?sact::?'v ⇒ ?'a ⇒ ?'v) (?uact::?'i ⇒ ?'v ⇒ ?'b ⇒ ?'v) (?v0.0::?'v) {#} (λk::?'i. []) ?v0.0›*) add_empty_guards_def (*‹add_empty_guards (?h::(nat ⇒ (prat × nat) option) × (prat × ?'a multiset) option × (?'i ⇒ ?'a list option)) = (get_fh ?h, Some (pwrite, {#}), λ_::?'i. Some [])›*)) qed qed lemma no_guards_remove_same: assumes "no_guard h" shows "h = remove_guards (add_empty_guards h)" by (metis add_empty_guards_def (*‹add_empty_guards (?h::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'i::type ⇒ ?'a::type list option)) = (get_fh ?h, Some (pwrite, {#}), λ_::?'i::type. Some [])›*) addition_cancellative (*‹⟦Some (?a::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'b::type ⇒ ?'a::type list option)) = Some (?b::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'b::type ⇒ ?'a::type list option)) ⊕ Some (?c::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'b::type ⇒ ?'a::type list option)); Some ?a = Some (?b'::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'b::type ⇒ ?'a::type list option)) ⊕ Some ?c⟧ ⟹ ?b = ?b'›*) assms (*‹no_guard (h::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option))›*) fst_conv (*‹fst (?x1.0::?'a::type, ?x2.0::?'b::type) = ?x1.0›*) get_fh.elims (*‹⟦get_fh (?x::?'a::type × ?'b::type) = (?y::?'a::type); ⋀x::?'a::type × ?'b::type. ⟦?x = x; ?y = fst x⟧ ⟹ ?P::bool⟧ ⟹ ?P›*) get_fh_remove_guards (*‹get_fh (remove_guards (?h::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'b::type ⇒ ?'a::type list option))) = get_fh ?h›*) no_guard_add_empty_is_add (*‹no_guard (?h::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'b::type ⇒ ?'a::type list option)) ⟹ Some (add_empty_guards ?h) = Some ?h ⊕ Some (λx::nat. None, Some (pwrite, {#}), λ_::?'b::type. Some [])›*) no_guard_remove_guards (*‹no_guard (remove_guards (?h::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'b::type ⇒ ?'a::type list option)))›*)) lemma no_guards_remove: "no_guard h ⟷ h = remove_guards h" by (metis get_fh_remove_guards (*‹get_fh (remove_guards ?h) = get_fh ?h›*) no_guard_remove_guards (*‹no_guard (remove_guards ?h)›*) no_guards_remove_same (*‹no_guard ?h ⟹ ?h = remove_guards (add_empty_guards ?h)›*) remove_guards_def (*‹remove_guards ?h = (get_fh ?h, None, empty_unique)›*)) definition add_sguard_to_no_guard :: "('i, 'a) heap ⇒ prat ⇒ 'a multiset ⇒ ('i, 'a) heap" where "add_sguard_to_no_guard h π ms = (get_fh h, Some (π, ms), (λ_. None))" lemma get_fh_add_sguard: "get_fh (add_sguard_to_no_guard h π ms) = get_fh h" by (simp add: add_sguard_to_no_guard_def (*‹add_sguard_to_no_guard ?h ?π ?ms = (get_fh ?h, Some (?π, ?ms), λ_. None)›*)) lemma add_sguard_as_sum: assumes "no_guard h" shows "Some (add_sguard_to_no_guard h π ms) = Some h ⊕ Some (Map.empty, Some (π, ms), (λ_. None))" proof (-) (*goal: ‹Some (add_sguard_to_no_guard (h::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) (π::prat) (ms::'a multiset)) = Some h ⊕ Some (λx::nat. None, Some (π, ms), λ_::'b. None)›*) obtain x where "Some x = Some h ⊕ Some (Map.empty, Some (π, ms), (λ_. None))" (*goal: ‹(⋀x. Some x = Some h ⊕ Some (λx. None, Some (π, ms), λ_. None) ⟹ thesis) ⟹ thesis›*) by (simp add: assms (*‹no_guard h›*) no_guard_map_empty_compatible (*‹⟦no_guard ?a; get_fh ?b = (λx. None)⟧ ⟹ ?a ## ?b›*)) moreover have "x = add_sguard_to_no_guard h π ms" proof (rule heap_ext (*‹⟦get_fh ?a = get_fh ?b; get_gs ?a = get_gs ?b; get_gu ?a = get_gu ?b⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹get_fh x = get_fh (add_sguard_to_no_guard h π ms)› 2. ‹get_gs x = get_gs (add_sguard_to_no_guard h π ms)› 3. ‹get_gu x = get_gu (add_sguard_to_no_guard h π ms)›*) show "get_fh x = get_fh (add_sguard_to_no_guard h π ms)" by (metis add_fh_map_empty (*‹add_fh ?h (λx. None) = ?h›*) add_get_fh (*‹Some ?x = Some ?a ⊕ Some ?b ⟹ get_fh ?x = add_fh (get_fh ?a) (get_fh ?b)›*) calculation (*‹Some x = Some h ⊕ Some (λx. None, Some (π, ms), λ_. None)›*) fst_conv (*‹fst (?x1.0, ?x2.0) = ?x1.0›*) get_fh.elims (*‹⟦get_fh ?x = ?y; ⋀x. ⟦?x = x; ?y = fst x⟧ ⟹ ?P⟧ ⟹ ?P›*) get_fh_add_sguard (*‹get_fh (add_sguard_to_no_guard ?h ?π ?ms) = get_fh ?h›*)) show "get_gs x = get_gs (add_sguard_to_no_guard h π ms)" by (metis add_sguard_to_no_guard_def (*‹add_sguard_to_no_guard ?h ?π ?ms = (get_fh ?h, Some (?π, ?ms), λ_. None)›*) assms (*‹no_guard h›*) calculation (*‹Some x = Some h ⊕ Some (λx. None, Some (π, ms), λ_. None)›*) get_gs.elims (*‹⟦get_gs ?x = ?y; ⋀x. ⟦?x = x; ?y = fst (snd x)⟧ ⟹ ?P⟧ ⟹ ?P›*) no_guard_def (*‹no_guard ?h = (get_gs ?h = None ∧ (∀k. get_gu ?h k = None))›*) plus_comm (*‹?a ⊕ ?b = ?b ⊕ ?a›*) snd_eqD (*‹snd (?x, ?y) = ?a ⟹ ?y = ?a›*) sum_gs_one_none (*‹⟦Some ?x = Some ?a ⊕ Some ?b; get_gs ?b = None⟧ ⟹ get_gs ?x = get_gs ?a›*)) show "get_gu x = get_gu (add_sguard_to_no_guard h π ms)" by (metis add_sguard_to_no_guard_def (*‹add_sguard_to_no_guard ?h ?π ?ms = (get_fh ?h, Some (?π, ?ms), λ_. None)›*) assms (*‹no_guard h›*) calculation (*‹Some x = Some h ⊕ Some (λx. None, Some (π, ms), λ_. None)›*) get_gu.simps (*‹get_gu ?x = snd (snd ?x)›*) no_guard_remove( (*‹⟦Some ?a = Some ?b ⊕ Some ?c; no_guard ?c⟧ ⟹ get_gu ?a = get_gu ?b›*) 2) plus_comm (*‹?a ⊕ ?b = ?b ⊕ ?a›*) snd_conv (*‹snd (?x1.0, ?x2.0) = ?x2.0›*)) qed ultimately show "?thesis" (*goal: ‹Some (add_sguard_to_no_guard h π ms) = Some h ⊕ Some (λx. None, Some (π, ms), λ_. None)›*) by blast qed definition add_uguard_to_no_guard :: "'i ⇒ ('i, 'a) heap ⇒ 'a list ⇒ ('i, 'a) heap" where "add_uguard_to_no_guard k h l = (get_fh h, None, (λ_. None)(k := Some l))" lemma get_fh_add_uguard: "get_fh (add_uguard_to_no_guard k h l) = get_fh h" by (simp add: add_uguard_to_no_guard_def (*‹add_uguard_to_no_guard (?k::?'i) (?h::(nat ⇒ (prat × nat) option) × (prat × ?'a multiset) option × (?'i ⇒ ?'a list option)) (?l::?'a list) = (get_fh ?h, None, [?k ↦ ?l])›*)) lemma prove_sum: assumes "a ## b" and "⋀x. Some x = Some a ⊕ Some b ⟹ x = y" shows "Some y = Some a ⊕ Some b" using assms(1) (*‹a ## b›*) assms(2) (*‹Some ?x = Some a ⊕ Some b ⟹ ?x = y›*) by fastforce lemma add_uguard_as_sum: assumes "no_guard h" shows "Some (add_uguard_to_no_guard k h l) = Some h ⊕ Some (Map.empty, None, (λ_. None)(k := Some l))" proof (rule prove_sum (*‹⟦?a ## ?b; ⋀x. Some x = Some ?a ⊕ Some ?b ⟹ x = ?y⟧ ⟹ Some ?y = Some ?a ⊕ Some ?b›*)) (*goals: 1. ‹h ## (λx. None, None, [k ↦ l])› 2. ‹⋀x. Some x = Some h ⊕ Some (λx. None, None, [k ↦ l]) ⟹ x = add_uguard_to_no_guard k h l›*) show "h ## (Map.empty, None, [k ↦ l])" by (simp add: assms (*‹no_guard (h::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option))›*) no_guard_map_empty_compatible (*‹⟦no_guard (?a::(nat ⇒ (prat × nat) option) × (prat × ?'a multiset) option × (?'b ⇒ ?'a list option)); get_fh (?b::(nat ⇒ (prat × nat) option) × (prat × ?'a multiset) option × (?'b ⇒ ?'a list option)) = (λx::nat. None)⟧ ⟹ ?a ## ?b›*)) fix x assume asm0: "Some x = Some h ⊕ Some (Map.empty, None, [k ↦ l])" (*‹Some (x::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) = Some (h::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) ⊕ Some (λx::nat. None, None, [k::'b ↦ l::'a list])›*) show "x = add_uguard_to_no_guard k h l" proof (rule heap_ext (*‹⟦get_fh ?a = get_fh ?b; get_gs ?a = get_gs ?b; get_gu ?a = get_gu ?b⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹get_fh x = get_fh (add_uguard_to_no_guard k h l)› 2. ‹get_gs x = get_gs (add_uguard_to_no_guard k h l)› 3. ‹get_gu x = get_gu (add_uguard_to_no_guard k h l)›*) show "get_fh x = get_fh (add_uguard_to_no_guard k h l)" by (metis add_fh_map_empty (*‹add_fh ?h (λx. None) = ?h›*) add_get_fh (*‹Some ?x = Some ?a ⊕ Some ?b ⟹ get_fh ?x = add_fh (get_fh ?a) (get_fh ?b)›*) asm0 (*‹Some x = Some h ⊕ Some (λx. None, None, [k ↦ l])›*) fst_conv (*‹fst (?x1.0, ?x2.0) = ?x1.0›*) get_fh.elims (*‹⟦get_fh ?x = ?y; ⋀x. ⟦?x = x; ?y = fst x⟧ ⟹ ?P⟧ ⟹ ?P›*) get_fh_add_uguard (*‹get_fh (add_uguard_to_no_guard ?k ?h ?l) = get_fh ?h›*)) show "get_gs x = get_gs (add_uguard_to_no_guard k h l)" by (metis add_uguard_to_no_guard_def (*‹add_uguard_to_no_guard ?k ?h ?l = (get_fh ?h, None, [?k ↦ ?l])›*) asm0 (*‹Some x = Some h ⊕ Some (λx. None, None, [k ↦ l])›*) assms (*‹no_guard h›*) get_gs.elims (*‹⟦get_gs ?x = ?y; ⋀x. ⟦?x = x; ?y = fst (snd x)⟧ ⟹ ?P⟧ ⟹ ?P›*) no_guard_def (*‹no_guard ?h = (get_gs ?h = None ∧ (∀k. get_gu ?h k = None))›*) plus_comm (*‹?a ⊕ ?b = ?b ⊕ ?a›*) snd_eqD (*‹snd (?x, ?y) = ?a ⟹ ?y = ?a›*) sum_gs_one_none (*‹⟦Some ?x = Some ?a ⊕ Some ?b; get_gs ?b = None⟧ ⟹ get_gs ?x = get_gs ?a›*)) show "get_gu x = get_gu (add_uguard_to_no_guard k h l)" by (metis add_uguard_to_no_guard_def (*‹add_uguard_to_no_guard ?k ?h ?l = (get_fh ?h, None, [?k ↦ ?l])›*) asm0 (*‹Some x = Some h ⊕ Some (λx. None, None, [k ↦ l])›*) assms (*‹no_guard h›*) get_gu.elims (*‹⟦get_gu ?x = ?y; ⋀x. ⟦?x = x; ?y = snd (snd x)⟧ ⟹ ?P⟧ ⟹ ?P›*) no_guard_remove( (*‹⟦Some ?a = Some ?b ⊕ Some ?c; no_guard ?c⟧ ⟹ get_gu ?a = get_gu ?b›*) 2) plus_comm (*‹?a ⊕ ?b = ?b ⊕ ?a›*) snd_eqD (*‹snd (?x, ?y) = ?a ⟹ ?y = ?a›*)) qed qed lemma no_guard_and_no_heap: assumes "Some h = Some p ⊕ Some g" and "no_guard p" and "get_fh g = Map.empty" shows "remove_guards h = p" proof (rule heap_ext (*‹⟦get_fh (?a::?'a::type × ?'b::type × ?'c::type) = get_fh (?b::?'a::type × ?'b::type × ?'c::type); get_gs ?a = get_gs ?b; get_gu ?a = get_gu ?b⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹get_fh (remove_guards (h::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option))) = get_fh (p::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option))› 2. ‹get_gs (remove_guards (h::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option))) = get_gs (p::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option))› 3. ‹get_gu (remove_guards (h::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option))) = get_gu (p::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option))›*) show "get_fh (remove_guards h) = get_fh p" proof (-) (*goal: ‹get_fh (remove_guards h) = get_fh p›*) have "get_fh (remove_guards h) = get_fh h" using get_fh_remove_guards (*‹get_fh (remove_guards (?h::(nat ⇒ (prat × nat) option) × (prat × ?'a multiset) option × (?'b ⇒ ?'a list option))) = get_fh ?h›*) by blast moreover have "get_fh h = add_fh (get_fh p) (get_fh g)" using add_get_fh (*‹Some ?x = Some ?a ⊕ Some ?b ⟹ get_fh ?x = add_fh (get_fh ?a) (get_fh ?b)›*) assms(1) (*‹Some h = Some p ⊕ Some g›*) by blast ultimately show "?thesis" (*goal: ‹get_fh (remove_guards h) = get_fh p›*) by (metis assms( (*‹Some h = Some p ⊕ Some g›*) 1) assms( (*‹get_fh g = (λx. None)›*) 3) ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*) get_fh.simps (*‹get_fh ?x = fst ?x›*) sum_second_none_get_fh (*‹⟦Some ?x = Some ?a ⊕ Some ?b; get_fh ?b ?l = None⟧ ⟹ get_fh ?x ?l = get_fh ?a ?l›*)) qed show "get_gs (remove_guards h) = get_gs p" by (metis assms( (*‹no_guard p›*) 2) no_guard_def (*‹no_guard ?h = (get_gs ?h = None ∧ (∀k. get_gu ?h k = None))›*) no_guard_remove_guards (*‹no_guard (remove_guards ?h)›*)) show "get_gu (remove_guards h) = get_gu p" by (metis ‹get_fh (remove_guards h) = get_fh p› assms( (*‹no_guard p›*) 2) get_fh_remove_guards (*‹get_fh (remove_guards ?h) = get_fh ?h›*) no_guards_remove (*‹no_guard ?h = (?h = remove_guards ?h)›*) remove_guards_def (*‹remove_guards ?h = (get_fh ?h, None, empty_unique)›*)) qed lemma decompose_guard_remove_easy: "Some h = Some (remove_guards h) ⊕ Some (Map.empty, get_gs h, get_gu h)" proof (rule prove_sum (*‹⟦(?a::(nat ⇒ (prat × nat) option) × (prat × ?'a multiset) option × (?'b ⇒ ?'a list option)) ## (?b::(nat ⇒ (prat × nat) option) × (prat × ?'a multiset) option × (?'b ⇒ ?'a list option)); ⋀x::(nat ⇒ (prat × nat) option) × (prat × ?'a multiset) option × (?'b ⇒ ?'a list option). Some x = Some ?a ⊕ Some ?b ⟹ x = (?y::(nat ⇒ (prat × nat) option) × (prat × ?'a multiset) option × (?'b ⇒ ?'a list option))⟧ ⟹ Some ?y = Some ?a ⊕ Some ?b›*)) (*goals: 1. ‹remove_guards h ## (λx. None, get_gs h, get_gu h)› 2. ‹⋀x. Some x = Some (remove_guards h) ⊕ Some (λx. None, get_gs h, get_gu h) ⟹ x = h›*) show "remove_guards h ## (Map.empty, get_gs h, get_gu h)" by (simp add: no_guard_map_empty_compatible (*‹⟦no_guard ?a; get_fh ?b = (λx. None)⟧ ⟹ ?a ## ?b›*) no_guard_remove_guards (*‹no_guard (remove_guards ?h)›*)) fix x assume asm0: "Some x = Some (remove_guards h) ⊕ Some (Map.empty, get_gs h, get_gu h)" (*‹Some (x::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) = Some (remove_guards (h::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option))) ⊕ Some (λx::nat. None, get_gs h, get_gu h)›*) show "x = h" proof (rule heap_ext (*‹⟦get_fh (?a::?'a × ?'b × ?'c) = get_fh (?b::?'a × ?'b × ?'c); get_gs ?a = get_gs ?b; get_gu ?a = get_gu ?b⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹get_fh x = get_fh h› 2. ‹get_gs x = get_gs h› 3. ‹get_gu x = get_gu h›*) show "get_fh x = get_fh h" by (metis add_fh_map_empty (*‹add_fh ?h (λx. None) = ?h›*) add_get_fh (*‹Some ?x = Some ?a ⊕ Some ?b ⟹ get_fh ?x = add_fh (get_fh ?a) (get_fh ?b)›*) asm0 (*‹Some x = Some (remove_guards h) ⊕ Some (λx. None, get_gs h, get_gu h)›*) fst_conv (*‹fst (?x1.0, ?x2.0) = ?x1.0›*) get_fh.elims (*‹⟦get_fh ?x = ?y; ⋀x. ⟦?x = x; ?y = fst x⟧ ⟹ ?P⟧ ⟹ ?P›*) get_fh_remove_guards (*‹get_fh (remove_guards ?h) = get_fh ?h›*)) show "get_gs x = get_gs h" by (metis asm0 (*‹Some x = Some (remove_guards h) ⊕ Some (λx. None, get_gs h, get_gu h)›*) fst_conv (*‹fst (?x1.0, ?x2.0) = ?x1.0›*) get_gs.simps (*‹get_gs ?x = fst (snd ?x)›*) no_guard_remove( (*‹⟦Some ?a = Some ?b ⊕ Some ?c; no_guard ?c⟧ ⟹ get_gs ?a = get_gs ?b›*) 1) no_guard_remove_guards (*‹no_guard (remove_guards ?h)›*) plus_comm (*‹?a ⊕ ?b = ?b ⊕ ?a›*) snd_conv (*‹snd (?x1.0, ?x2.0) = ?x2.0›*)) show "get_gu x = get_gu h" by (metis asm0 (*‹Some x = Some (remove_guards h) ⊕ Some (λx. None, get_gs h, get_gu h)›*) get_gu.elims (*‹⟦get_gu ?x = ?y; ⋀x. ⟦?x = x; ?y = snd (snd x)⟧ ⟹ ?P⟧ ⟹ ?P›*) no_guard_remove( (*‹⟦Some ?a = Some ?b ⊕ Some ?c; no_guard ?c⟧ ⟹ get_gu ?a = get_gu ?b›*) 2) no_guard_remove_guards (*‹no_guard (remove_guards ?h)›*) plus_comm (*‹?a ⊕ ?b = ?b ⊕ ?a›*) snd_eqD (*‹snd (?x, ?y) = ?a ⟹ ?y = ?a›*)) qed qed lemma all_guards_no_guard_propagates: assumes "all_guards x" and "Some x = Some a ⊕ Some b" and "no_guard a" shows "all_guards b" by (metis all_guards_def (*‹all_guards ?h = ((∃v. get_gs ?h = Some (pwrite, v)) ∧ (∀k. get_gu ?h k ≠ None))›*) assms( (*‹all_guards x›*) 1) assms( (*‹Some x = Some a ⊕ Some b›*) 2) assms( (*‹no_guard a›*) 3) no_guard_def (*‹no_guard ?h = (get_gs ?h = None ∧ (∀k. get_gu ?h k = None))›*) no_guard_remove( (*‹⟦Some ?a = Some ?b ⊕ Some ?c; no_guard ?c⟧ ⟹ get_gu ?a = get_gu ?b›*) 2) plus_comm (*‹?a ⊕ ?b = ?b ⊕ ?a›*) sum_gs_one_none (*‹⟦Some ?x = Some ?a ⊕ Some ?b; get_gs ?b = None⟧ ⟹ get_gs ?x = get_gs ?a›*)) lemma all_guards_exists_uargs: assumes "all_guards x" shows "∃uargs. ∀k. get_gu x k = Some (uargs k)" proof (-) (*goal: ‹∃uargs::'b::type ⇒ 'a::type list. ∀k::'b::type. get_gu (x::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option)) k = Some (uargs k)›*) let ?uargs = "λk. the (get_gu x k)" have "⋀k. get_gu x k = Some (?uargs k)" by (metis all_guards_def (*‹all_guards (?h::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'i::type ⇒ ?'a::type list option)) = ((∃v::?'a::type multiset. get_gs ?h = Some (pwrite, v)) ∧ (∀k::?'i::type. get_gu ?h k ≠ None))›*) assms (*‹all_guards (x::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option))›*) option.collapse (*‹(?option::?'a::type option) ≠ None ⟹ Some (the ?option) = ?option›*)) then show "?thesis" (*goal: ‹∃uargs. ∀k. get_gu x k = Some (uargs k)›*) by fastforce qed lemma all_guards_sum_known_one: assumes "Some x = Some a ⊕ Some b" and "all_guards x" and "⋀k. get_gu a k = None" and "get_gs a = Some (π, ms)" shows "∃π' msf uargs. (∀k. get_gu b k = Some (uargs k)) ∧ ((π = pwrite ∧ get_gs b = None ∧ msf = {#}) ∨ (pwrite = padd π π' ∧ get_gs b = Some (π', msf)))" proof (cases "π = pwrite") (*goals: 1. ‹π = pwrite ⟹ ∃π' msf uargs. (∀k. get_gu b k = Some (uargs k)) ∧ (π = pwrite ∧ get_gs b = None ∧ msf = {#} ∨ pwrite = padd π π' ∧ get_gs b = Some (π', msf))› 2. ‹π ≠ pwrite ⟹ ∃π' msf uargs. (∀k. get_gu b k = Some (uargs k)) ∧ (π = pwrite ∧ get_gs b = None ∧ msf = {#} ∨ pwrite = padd π π' ∧ get_gs b = Some (π', msf))›*) case True (*‹π = pwrite›*) then have "get_gs b = None" using add_gs.simps(2)[of "(π, ms)"] (*‹add_gs (Some (π, ms)) None = Some (π, ms)›*) add_gs_cancellative (*‹add_gs ?a ?x = add_gs ?b ?x ⟹ ?a = ?b›*) add_gs_comm (*‹add_gs (?a::(prat × ?'a multiset) option) (?b::(prat × ?'a multiset) option) = add_gs ?b ?a›*) assms(1) (*‹Some x = Some a ⊕ Some b›*) assms(4) (*‹get_gs a = Some (π, ms)›*) full_sguard_sum_same (*‹⟦get_gs ?a = Some (pwrite, ?sargs); Some ?h = Some ?a ⊕ Some ?b⟧ ⟹ get_gs ?h = Some (pwrite, ?sargs)›*) plus_extract(2)[of x a b] (*‹Some (x::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) = Some (a::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) ⊕ Some (b::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) ⟹ get_gs x = add_gs (get_gs a) (get_gs b)›*) by metis moreover obtain uargs where "⋀k. get_gu x k = Some (uargs k)" (*goal: ‹(⋀uargs. (⋀k. get_gu x k = Some (uargs k)) ⟹ thesis) ⟹ thesis›*) using all_guards_exists_uargs (*‹all_guards ?x ⟹ ∃uargs. ∀k. get_gu ?x k = Some (uargs k)›*) assms(2) (*‹all_guards (x::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option))›*) by blast moreover have "⋀k. get_gu b k = Some (uargs k)" proof (-) (*goal: ‹⋀k. get_gu b k = Some (uargs k)›*) fix k have "get_gu a k = None" using assms(3) (*‹get_gu a ?k = None›*) by auto then show "get_gu b k = Some (uargs k)" by (metis (no_types, opaque_lifting) add_gu_def (*‹add_gu ?u1.0 ?u2.0 ?k = add_gu_single (?u1.0 ?k) (?u2.0 ?k)›*) add_gu_single.simps( (*‹add_gu_single None ?x = ?x›*) 1) assms( (*‹Some x = Some a ⊕ Some b›*) 1) calculation( (*‹get_gu x ?k = Some (uargs ?k)›*) 2) plus_extract( (*‹Some ?x = Some ?a ⊕ Some ?b ⟹ get_gu ?x = add_gu (get_gu ?a) (get_gu ?b)›*) 3)) qed ultimately show "?thesis" (*goal: ‹∃π' msf uargs. (∀k. get_gu b k = Some (uargs k)) ∧ (π = pwrite ∧ get_gs b = None ∧ msf = {#} ∨ pwrite = padd π π' ∧ get_gs b = Some (π', msf))›*) using True (*‹(π::prat) = pwrite›*) by blast next (*goal: ‹π ≠ pwrite ⟹ ∃π' msf uargs. (∀k. get_gu b k = Some (uargs k)) ∧ (π = pwrite ∧ get_gs b = None ∧ msf = {#} ∨ pwrite = padd π π' ∧ get_gs b = Some (π', msf))›*) case False (*‹(π::prat) ≠ pwrite›*) then obtain π' and msf where "get_gs b = Some (π', msf)" (*goal: ‹(⋀π' msf. get_gs b = Some (π', msf) ⟹ thesis) ⟹ thesis›*) by (metis all_guards_def (*‹all_guards (?h::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'i::type ⇒ ?'a::type list option)) = ((∃v::?'a::type multiset. get_gs ?h = Some (pwrite, v)) ∧ (∀k::?'i::type. get_gu ?h k ≠ None))›*) assms( (*‹Some (x::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option)) = Some (a::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option)) ⊕ Some (b::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option))›*) 1) assms( (*‹all_guards (x::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option))›*) 2) assms( (*‹get_gs (a::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option)) = Some (π::prat, ms::'a::type multiset)›*) 4) fst_conv (*‹fst (?x1.0::?'a::type, ?x2.0::?'b::type) = ?x1.0›*) option.exhaust_sel (*‹⟦(?option::?'a::type option) = None ⟹ ?P::bool; ?option = Some (the ?option) ⟹ ?P⟧ ⟹ ?P›*) option.sel (*‹the (Some (?x2.0::?'a::type)) = ?x2.0›*) prod.exhaust_sel (*‹((?prod::?'a::type × ?'b::type) = (fst ?prod, snd ?prod) ⟹ ?P::bool) ⟹ ?P›*) sum_gs_one_none (*‹⟦Some (?x::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'b::type ⇒ ?'a::type list option)) = Some (?a::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'b::type ⇒ ?'a::type list option)) ⊕ Some (?b::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'b::type ⇒ ?'a::type list option)); get_gs ?b = None⟧ ⟹ get_gs ?x = get_gs ?a›*)) moreover obtain v where "get_gs x = Some (pwrite, v)" (*goal: ‹(⋀v. get_gs x = Some (pwrite, v) ⟹ thesis) ⟹ thesis›*) by (meson all_guards_def (*‹all_guards (?h::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'i::type ⇒ ?'a::type list option)) = ((∃v::?'a::type multiset. get_gs ?h = Some (pwrite, v)) ∧ (∀k::?'i::type. get_gu ?h k ≠ None))›*) assms( (*‹all_guards (x::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option))›*) 2)) ultimately have "pwrite = padd π π'" by (metis Pair_inject (*‹⟦(?a, ?b) = (?a', ?b'); ⟦?a = ?a'; ?b = ?b'⟧ ⟹ ?R⟧ ⟹ ?R›*) assms( (*‹Some x = Some a ⊕ Some b›*) 1) assms( (*‹get_gs a = Some (π, ms)›*) 4) option.inject (*‹(Some ?x2.0 = Some ?y2.0) = (?x2.0 = ?y2.0)›*) sum_gs_one_some (*‹⟦Some ?x = Some ?a ⊕ Some ?b; get_gs ?a = Some (?pa, ?ma); get_gs ?b = Some (?pb, ?mb)⟧ ⟹ get_gs ?x = Some (padd ?pa ?pb, ?ma + ?mb)›*)) then show "?thesis" (*goal: ‹∃π' msf uargs. (∀k. get_gu b k = Some (uargs k)) ∧ (π = pwrite ∧ get_gs b = None ∧ msf = {#} ∨ pwrite = padd π π' ∧ get_gs b = Some (π', msf))›*) by (metis (mono_tags, opaque_lifting) ‹get_gs b = Some (π', msf)› add_gu_def (*‹add_gu ?u1.0 ?u2.0 ?k = add_gu_single (?u1.0 ?k) (?u2.0 ?k)›*) add_gu_single.simps( (*‹add_gu_single None ?x = ?x›*) 1) all_guards_exists_uargs (*‹all_guards ?x ⟹ ∃uargs. ∀k. get_gu ?x k = Some (uargs k)›*) assms( (*‹Some x = Some a ⊕ Some b›*) 1) assms( (*‹all_guards x›*) 2) assms( (*‹get_gu a ?k = None›*) 3) plus_extract( (*‹Some ?x = Some ?a ⊕ Some ?b ⟹ get_gu ?x = add_gu (get_gu ?a) (get_gu ?b)›*) 3)) qed fun add_pwrite_option where "add_pwrite_option None = None" | "add_pwrite_option (Some x) = Some (pwrite, x)" definition denormalize :: "normal_heap ⇒ ('i, 'a) heap" where "denormalize H = ((λl. add_pwrite_option (H l)), None, (λ_. None))" lemma denormalize_properties: shows "no_guard (denormalize H)" and "full_ownership (get_fh (denormalize H))" and "normalize (get_fh (denormalize H)) = H" and "full_ownership (get_fh h) ∧ no_guard h ⟹ denormalize (normalize (get_fh h)) = h" and "full_ownership (get_fh h) ⟹ denormalize (normalize (get_fh h)) = remove_guards h" apply (simp add: denormalize_def (*‹denormalize ?H = (λl. add_pwrite_option (?H l), None, λ_. None)›*) no_guardI (*‹⟦get_gs ?h = None; ⋀k. get_gu ?h k = None⟧ ⟹ no_guard ?h›*)) (*top goal: ‹no_guard (denormalize H)› and 4 goals remain*) using full_ownershipI[of "get_fh (denormalize H)"] (*‹(⋀(l::nat) p::prat × nat. get_fh (denormalize (H::nat ⇒ nat option)) l = Some p ⟹ fst p = pwrite) ⟹ full_ownership (get_fh (denormalize H))›*) add_pwrite_option.elims (*‹⟦add_pwrite_option ?x = ?y; ⟦?x = None; ?y = None⟧ ⟹ ?P; ⋀x. ⟦?x = Some x; ?y = Some (pwrite, x)⟧ ⟹ ?P⟧ ⟹ ?P›*) denormalize_def (*‹denormalize (?H::nat ⇒ nat option) = (λl::nat. add_pwrite_option (?H l), None, λ_::?'i. None)›*) fst_conv (*‹fst (?x1.0, ?x2.0) = ?x1.0›*) get_fh.elims (*‹⟦get_fh ?x = ?y; ⋀x. ⟦?x = x; ?y = fst x⟧ ⟹ ?P⟧ ⟹ ?P›*) option.distinct(1) (*‹None ≠ Some (?x2.0::?'a)›*) option.sel (*‹the (Some (?x2.0::?'a)) = ?x2.0›*) proof (metis) (*goals: 1. ‹FractionalHeap.normalize (get_fh (denormalize H)) = H› 2. ‹full_ownership (get_fh h) ∧ no_guard h ⟹ denormalize (FractionalHeap.normalize (get_fh h)) = h› 3. ‹full_ownership (get_fh h) ⟹ denormalize (FractionalHeap.normalize (get_fh h)) = remove_guards h›*) show "normalize (get_fh (denormalize H)) = H" proof (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹⋀x. FractionalHeap.normalize (get_fh (denormalize H)) x = H x›*) fix l show "normalize (get_fh (denormalize H)) l = H l" by (metis FractionalHeap.normalize_eq( (*‹(FractionalHeap.normalize ?h ?l = None) = (?h ?l = None)›*) 1) FractionalHeap.normalize_eq( (*‹(FractionalHeap.normalize ?h ?l = Some ?v) = (∃p. ?h ?l = Some (p, ?v))›*) 2) add_pwrite_option.elims (*‹⟦add_pwrite_option ?x = ?y; ⟦?x = None; ?y = None⟧ ⟹ ?P; ⋀x. ⟦?x = Some x; ?y = Some (pwrite, x)⟧ ⟹ ?P⟧ ⟹ ?P›*) denormalize_def (*‹denormalize ?H = (λl. add_pwrite_option (?H l), None, λ_. None)›*) fst_conv (*‹fst (?x1.0, ?x2.0) = ?x1.0›*) get_fh.elims (*‹⟦get_fh ?x = ?y; ⋀x. ⟦?x = x; ?y = fst x⟧ ⟹ ?P⟧ ⟹ ?P›*)) qed show "full_ownership (get_fh h) ∧ no_guard h ⟹ denormalize (FractionalHeap.normalize (get_fh h)) = h" proof (-) (*goal: ‹full_ownership (get_fh h) ∧ no_guard h ⟹ denormalize (FractionalHeap.normalize (get_fh h)) = h›*) assume asm0: "full_ownership (get_fh h) ∧ no_guard h" (*‹full_ownership (get_fh (h::(nat ⇒ (prat × nat) option) × (prat × 'g multiset) option × ('h ⇒ 'g list option))) ∧ no_guard h›*) show "denormalize (FractionalHeap.normalize (get_fh h)) = h" proof (rule heap_ext (*‹⟦get_fh ?a = get_fh ?b; get_gs ?a = get_gs ?b; get_gu ?a = get_gu ?b⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹get_fh (denormalize (FractionalHeap.normalize (get_fh (h::(nat ⇒ (prat × nat) option) × (prat × 'g multiset) option × ('h ⇒ 'g list option))))) = get_fh h› 2. ‹get_gs (denormalize (FractionalHeap.normalize (get_fh (h::(nat ⇒ (prat × nat) option) × (prat × 'g multiset) option × ('h ⇒ 'g list option))))) = get_gs h› 3. ‹get_gu (denormalize (FractionalHeap.normalize (get_fh (h::(nat ⇒ (prat × nat) option) × (prat × 'g multiset) option × ('h ⇒ 'g list option))))) = get_gu h›*) show "get_fh (denormalize (FractionalHeap.normalize (get_fh h))) = get_fh h" proof (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹⋀x::nat. get_fh (denormalize (FractionalHeap.normalize (get_fh (h::(nat ⇒ (prat × nat) option) × (prat × 'g::type multiset) option × ('h::type ⇒ 'g::type list option))))) x = get_fh h x›*) fix x show "get_fh (denormalize (FractionalHeap.normalize (get_fh h))) x = get_fh h x" proof (cases "get_fh h x") (*goals: 1. ‹get_fh h x = None ⟹ get_fh (denormalize (FractionalHeap.normalize (get_fh h))) x = get_fh h x› 2. ‹⋀a. get_fh h x = Some a ⟹ get_fh (denormalize (FractionalHeap.normalize (get_fh h))) x = get_fh h x›*) case None (*‹get_fh (h::(nat ⇒ (prat × nat) option) × (prat × 'g::type multiset) option × ('h::type ⇒ 'g::type list option)) (x::nat) = None›*) then show "?thesis" (*goal: ‹get_fh (denormalize (FractionalHeap.normalize (get_fh h))) x = get_fh h x›*) by (metis FractionalHeap.normalize_eq( (*‹(FractionalHeap.normalize ?h ?l = None) = (?h ?l = None)›*) 1) add_pwrite_option.simps( (*‹add_pwrite_option None = None›*) 1) denormalize_def (*‹denormalize ?H = (λl. add_pwrite_option (?H l), None, λ_. None)›*) fst_conv (*‹fst (?x1.0, ?x2.0) = ?x1.0›*) get_fh.elims (*‹⟦get_fh ?x = ?y; ⋀x. ⟦?x = x; ?y = fst x⟧ ⟹ ?P⟧ ⟹ ?P›*)) next (*goal: ‹⋀a. get_fh h x = Some a ⟹ get_fh (denormalize (FractionalHeap.normalize (get_fh h))) x = get_fh h x›*) case (Some p) (*‹get_fh h x = Some p›*) then have "fst p = pwrite" by (meson asm0 (*‹full_ownership (get_fh h) ∧ no_guard h›*) full_ownership_def (*‹full_ownership ?h = (∀l p. ?h l = Some p ⟶ fst p = pwrite)›*)) then show "?thesis" (*goal: ‹get_fh (denormalize (FractionalHeap.normalize (get_fh h))) x = get_fh h x›*) by (metis FractionalHeap.normalize_eq( (*‹(FractionalHeap.normalize ?h ?l = Some ?v) = (∃p. ?h ?l = Some (p, ?v))›*) 2) Some (*‹get_fh h x = Some p›*) add_pwrite_option.simps( (*‹add_pwrite_option (Some ?x) = Some (pwrite, ?x)›*) 2) denormalize_def (*‹denormalize ?H = (λl. add_pwrite_option (?H l), None, λ_. None)›*) fst_conv (*‹fst (?x1.0, ?x2.0) = ?x1.0›*) get_fh.elims (*‹⟦get_fh ?x = ?y; ⋀x. ⟦?x = x; ?y = fst x⟧ ⟹ ?P⟧ ⟹ ?P›*) prod.collapse (*‹(fst ?prod, snd ?prod) = ?prod›*)) qed qed show "get_gs (denormalize (FractionalHeap.normalize (get_fh h))) = get_gs h" by (metis asm0 (*‹full_ownership (get_fh (h::(nat ⇒ (prat × nat) option) × (prat × 'g::type multiset) option × ('h::type ⇒ 'g::type list option))) ∧ no_guard h›*) denormalize_def (*‹denormalize (?H::nat ⇒ nat option) = (λl::nat. add_pwrite_option (?H l), None, λ_::?'i::type. None)›*) fst_conv (*‹fst (?x1.0::?'a::type, ?x2.0::?'b::type) = ?x1.0›*) get_gs.elims (*‹⟦get_gs (?x::?'a::type × ?'b::type × ?'c::type) = (?y::?'b::type); ⋀x::?'a::type × ?'b::type × ?'c::type. ⟦?x = x; ?y = fst (snd x)⟧ ⟹ ?P::bool⟧ ⟹ ?P›*) no_guard_def (*‹no_guard (?h::(nat ⇒ (prat × nat) option) × (prat × ?'a::type multiset) option × (?'i::type ⇒ ?'a::type list option)) = (get_gs ?h = None ∧ (∀k::?'i::type. get_gu ?h k = None))›*) snd_eqD (*‹snd (?x::?'b::type, ?y::?'a::type) = (?a::?'a::type) ⟹ ?y = ?a›*)) show "get_gu (denormalize (FractionalHeap.normalize (get_fh h))) = get_gu h" by (metis ‹get_fh (denormalize (FractionalHeap.normalize (get_fh h))) = get_fh h› ‹get_gs (denormalize (FractionalHeap.normalize (get_fh h))) = get_gs h› asm0 (*‹full_ownership (get_fh h) ∧ no_guard h›*) denormalize_def (*‹denormalize ?H = (λl. add_pwrite_option (?H l), None, λ_. None)›*) full_no_guard_same_normalize (*‹⟦full_ownership (get_fh ?h) ∧ no_guard ?h; full_ownership (get_fh ?h') ∧ no_guard ?h'; FractionalHeap.normalize (get_fh ?h) = FractionalHeap.normalize (get_fh ?h')⟧ ⟹ ?h = ?h'›*) get_gu.simps (*‹get_gu ?x = snd (snd ?x)›*) no_guard_def (*‹no_guard ?h = (get_gs ?h = None ∧ (∀k. get_gu ?h k = None))›*) snd_conv (*‹snd (?x1.0, ?x2.0) = ?x2.0›*)) qed qed assume asm0: "full_ownership (get_fh h)" (*‹full_ownership (get_fh (h::(nat ⇒ (prat × nat) option) × (prat × 'g multiset) option × ('h ⇒ 'g list option)))›*) show "denormalize (FractionalHeap.normalize (get_fh h)) = remove_guards h" proof (rule heap_ext (*‹⟦get_fh ?a = get_fh ?b; get_gs ?a = get_gs ?b; get_gu ?a = get_gu ?b⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹get_fh (denormalize (FractionalHeap.normalize (get_fh h))) = get_fh (remove_guards h)› 2. ‹get_gs (denormalize (FractionalHeap.normalize (get_fh h))) = get_gs (remove_guards h)› 3. ‹get_gu (denormalize (FractionalHeap.normalize (get_fh h))) = get_gu (remove_guards h)›*) show "get_fh (denormalize (FractionalHeap.normalize (get_fh h))) = get_fh (remove_guards h)" proof (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹⋀x. get_fh (denormalize (FractionalHeap.normalize (get_fh h))) x = get_fh (remove_guards h) x›*) fix x show "get_fh (denormalize (FractionalHeap.normalize (get_fh h))) x = get_fh (remove_guards h) x" proof (cases "get_fh h x") (*goals: 1. ‹get_fh h x = None ⟹ get_fh (denormalize (FractionalHeap.normalize (get_fh h))) x = get_fh (remove_guards h) x› 2. ‹⋀a. get_fh h x = Some a ⟹ get_fh (denormalize (FractionalHeap.normalize (get_fh h))) x = get_fh (remove_guards h) x›*) case None (*‹get_fh h x = None›*) then show "?thesis" (*goal: ‹get_fh (denormalize (FractionalHeap.normalize (get_fh h))) x = get_fh (remove_guards h) x›*) by (metis FractionalHeap.normalize_eq( (*‹(FractionalHeap.normalize ?h ?l = None) = (?h ?l = None)›*) 1) add_pwrite_option.simps( (*‹add_pwrite_option None = None›*) 1) denormalize_def (*‹denormalize ?H = (λl. add_pwrite_option (?H l), None, λ_. None)›*) fst_eqD (*‹fst (?x, ?y) = ?a ⟹ ?x = ?a›*) get_fh.elims (*‹⟦get_fh ?x = ?y; ⋀x. ⟦?x = x; ?y = fst x⟧ ⟹ ?P⟧ ⟹ ?P›*) get_fh_remove_guards (*‹get_fh (remove_guards ?h) = get_fh ?h›*)) next (*goal: ‹⋀a. get_fh h x = Some a ⟹ get_fh (denormalize (FractionalHeap.normalize (get_fh h))) x = get_fh (remove_guards h) x›*) case (Some p) (*‹get_fh (h::(nat ⇒ (prat × nat) option) × (prat × 'g multiset) option × ('h ⇒ 'g list option)) (x::nat) = Some (p::prat × nat)›*) then have "fst p = pwrite" by (meson asm0 (*‹full_ownership (get_fh h)›*) full_ownership_def (*‹full_ownership ?h = (∀l p. ?h l = Some p ⟶ fst p = pwrite)›*)) then show "?thesis" (*goal: ‹get_fh (denormalize (FractionalHeap.normalize (get_fh (h::(nat ⇒ (prat × nat) option) × (prat × 'g multiset) option × ('h ⇒ 'g list option))))) (x::nat) = get_fh (remove_guards h) x›*) by (metis FractionalHeap.normalize_eq( (*‹(FractionalHeap.normalize ?h ?l = Some ?v) = (∃p. ?h ?l = Some (p, ?v))›*) 2) Some (*‹get_fh h x = Some p›*) add_pwrite_option.simps( (*‹add_pwrite_option (Some ?x) = Some (pwrite, ?x)›*) 2) denormalize_def (*‹denormalize ?H = (λl. add_pwrite_option (?H l), None, λ_. None)›*) fst_conv (*‹fst (?x1.0, ?x2.0) = ?x1.0›*) get_fh.elims (*‹⟦get_fh ?x = ?y; ⋀x. ⟦?x = x; ?y = fst x⟧ ⟹ ?P⟧ ⟹ ?P›*) get_fh_remove_guards (*‹get_fh (remove_guards ?h) = get_fh ?h›*) prod.collapse (*‹(fst ?prod, snd ?prod) = ?prod›*)) qed qed show "get_gs (denormalize (FractionalHeap.normalize (get_fh h))) = get_gs (remove_guards h)" by (simp add: denormalize_def (*‹denormalize ?H = (λl. add_pwrite_option (?H l), None, λ_. None)›*) remove_guards_def (*‹remove_guards ?h = (get_fh ?h, None, empty_unique)›*)) show "get_gu (denormalize (FractionalHeap.normalize (get_fh h))) = get_gu (remove_guards h)" by (metis ‹get_fh (denormalize (FractionalHeap.normalize (get_fh h))) = get_fh (remove_guards h)› ‹get_gs (denormalize (FractionalHeap.normalize (get_fh h))) = get_gs (remove_guards h)› asm0 (*‹full_ownership (get_fh h)›*) denormalize_def (*‹denormalize ?H = (λl. add_pwrite_option (?H l), None, λ_. None)›*) full_no_guard_same_normalize (*‹⟦full_ownership (get_fh ?h) ∧ no_guard ?h; full_ownership (get_fh ?h') ∧ no_guard ?h'; FractionalHeap.normalize (get_fh ?h) = FractionalHeap.normalize (get_fh ?h')⟧ ⟹ ?h = ?h'›*) get_fh_remove_guards (*‹get_fh (remove_guards ?h) = get_fh ?h›*) get_gu.simps (*‹get_gu ?x = snd (snd ?x)›*) no_guard_def (*‹no_guard ?h = (get_gs ?h = None ∧ (∀k. get_gu ?h k = None))›*) no_guard_remove_guards (*‹no_guard (remove_guards ?h)›*) snd_conv (*‹snd (?x1.0, ?x2.0) = ?x2.0›*)) qed qed lemma no_guard_then_sat_star_uguard: assumes "no_guard h ∧ no_guard h'" and "(s, h), (s', h') ⊨ Q" shows "(s, add_uguard_to_no_guard k h (e s)), (s', add_uguard_to_no_guard k h' (e s')) ⊨ Star Q (UniqueGuard k e)" proof (-) (*goal: ‹(s, add_uguard_to_no_guard k h (e s)), (s', add_uguard_to_no_guard k h' (e s')) ⊨ Q * UniqueGuard k e›*) obtain "Some (add_uguard_to_no_guard k h (e s)) = Some h ⊕ Some (Map.empty, None, [k ↦ e s])" "Some (add_uguard_to_no_guard k h' (e s')) = Some h' ⊕ Some (Map.empty, None, [k ↦ e s'])" (*goal: ‹(⟦Some (add_uguard_to_no_guard k h (e s)) = Some h ⊕ Some (λx. None, None, [k ↦ e s]); Some (add_uguard_to_no_guard k h' (e s')) = Some h' ⊕ Some (λx. None, None, [k ↦ e s'])⟧ ⟹ thesis) ⟹ thesis›*) by (simp add: add_uguard_as_sum (*‹no_guard ?h ⟹ Some (add_uguard_to_no_guard ?k ?h ?l) = Some ?h ⊕ Some (λx. None, None, [?k ↦ ?l])›*) assms( (*‹no_guard h ∧ no_guard h'›*) 1)) moreover have "(s, (Map.empty, None, [k ↦ e s])), (s', (Map.empty, None, [k ↦ e s'])) ⊨ UniqueGuard k e" by simp ultimately show "?thesis" (*goal: ‹(s, add_uguard_to_no_guard k h (e s)), (s', add_uguard_to_no_guard k h' (e s')) ⊨ Q * UniqueGuard k e›*) using assms(2) (*‹(s, h), (s', h') ⊨ Q›*) by fastforce qed lemma no_guard_then_sat_star: assumes "no_guard h ∧ no_guard h'" and "(s, h), (s', h') ⊨ Q" shows "(s, add_sguard_to_no_guard h π (ms s)), (s', add_sguard_to_no_guard h' π (ms s')) ⊨ Star Q (SharedGuard π ms)" proof (-) (*goal: ‹(s, add_sguard_to_no_guard h π (ms s)), (s', add_sguard_to_no_guard h' π (ms s')) ⊨ Q * SharedGuard π ms›*) obtain "Some (add_sguard_to_no_guard h π (ms s)) = Some h ⊕ Some (Map.empty, Some (π, ms s), (λ_. None))" "Some (add_sguard_to_no_guard h' π (ms s')) = Some h' ⊕ Some (Map.empty, Some (π, ms s'), (λ_. None))" (*goal: ‹(⟦Some (add_sguard_to_no_guard h π (ms s)) = Some h ⊕ Some (λx. None, Some (π, ms s), λ_. None); Some (add_sguard_to_no_guard h' π (ms s')) = Some h' ⊕ Some (λx. None, Some (π, ms s'), λ_. None)⟧ ⟹ thesis) ⟹ thesis›*) using add_sguard_as_sum (*‹no_guard ?h ⟹ Some (add_sguard_to_no_guard ?h ?π ?ms) = Some ?h ⊕ Some (λx. None, Some (?π, ?ms), λ_. None)›*) assms(1) (*‹no_guard (h::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option)) ∧ no_guard (h'::(nat ⇒ (prat × nat) option) × (prat × 'a::type multiset) option × ('b::type ⇒ 'a::type list option))›*) by blast moreover have "(s, (Map.empty, Some (π, ms s), (λ_. None))), (s', (Map.empty, Some (π, ms s'), (λ_. None))) ⊨ SharedGuard π ms" by simp ultimately show "?thesis" (*goal: ‹(s::char list ⇒ nat, add_sguard_to_no_guard (h::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) (π::prat) ((ms::(char list ⇒ nat) ⇒ 'a multiset) s)), (s'::char list ⇒ nat, add_sguard_to_no_guard (h'::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) π (ms s')) ⊨ Q::('b, 'a, nat) assertion * SharedGuard π ms›*) using assms(2) (*‹(s::char list ⇒ nat, h::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)), (s'::char list ⇒ nat, h'::(nat ⇒ (prat × nat) option) × (prat × 'a multiset) option × ('b ⇒ 'a list option)) ⊨ (Q::('b, 'a, nat) assertion)›*) by fastforce qed end
{ "path": "afp-2025-02-12/thys/CommCSL/Guards.thy", "repo": "afp-2025-02-12", "sha": "b5c4b39200b75bab584638b34e3ed9c71b424b6e91bdd77603627830f31dc461" }
(* Title: Conflict analysis/Constraint Systems Author: Peter Lammich <peter.lammich@uni-muenster.de> Maintainer: Peter Lammich <peter.lammich@uni-muenster.de> *) section "Constraint Systems" theory ConstraintSystems imports Main AcquisitionHistory Normalization begin text_raw ‹\label{thy:ConstraintSystems}› text ‹ In this section we develop a constraint-system-based characterization of our analysis. › text ‹ Constraint systems are widely used in static program analysis. There least solution describes the desired analysis information. In its generic form, a constraint system $R$ is a set of inequations over a complete lattice $(L,\sqsubseteq)$ and a set of variables $V$. An inequation has the form $ R[v] \sqsupseteq {\sf rhs}$, where $R[v]\in V$ and ${\sf rhs}$ is a monotonic function over the variables. Note that for program analysis, there is usually one variable per control point. The variables are then named $R[v]$, where $v$ is a control point. By standard fixed-point theory, those constraint systems have a least solution. Outside the constraint system definition $R[v]$ usually refers to a component of that least solution. Usually a constraint system is generated from the program. For example, a constraint generation pattern could be the following: $$ \begin{array}{lcl} \multicolumn{3}{l}{\mbox{for $(u,{\sf Call}~q,v)\in E$:}} \\ S^k[v] & \supseteq & \{({\sf mon}(q)\cup M\cup M',\tilde P) \mid (M,P)\in S^k[u] \wedge (M',P')\in S^k[{\sf r}_q] \\&&\wedge~\tilde P \le P \uplus P' \wedge |\tilde P| \le 2 \} \\ \end{array} $$ For some parameter $k$ and a flowgraph with nodes $N$ and edges $E$, this generates a constraint system over the variables $\{ S^k[v] \mid v\in N \}$. One constraint is generated for each call edge. While we use a powerset lattice here, we can in general use any complete lattice. However, all the constraint systems needed for our conflict analysis are defined over powerset lattices $(\mathcal P('a), \subseteq)$ for some type $'a$. This admits a convenient formalization in Isabelle/HOL using inductively defined sets. We inductively define a relation between variables\footnote{Variables are identified by control nodes here} and the elements of their values in the least solution, i.e. the set $\{ (v,x) \mid x\in R[v] \}$. For example, the constraint generator pattern from above would become the following introduction rule in the inductive definition of the set ‹S_cs fg k›: @{text [display] "⟦(u,Call q,v)∈edges fg; (u,M,P)∈S_cs fg k; (return fg q,Ms,Ps)∈S_cs fg k; P'⊆#P+Ps; size P' ≤ k ⟧ ⟹ (v,mon fg q ∪ M ∪ Ms,P')∈S_cs fg k"} The main advantage of this approach is that one gets a concise formalization by using Isabelle's standard machinery, the main disadvantage is that this approach only works for powerset lattices ordered by $\subseteq$. › subsection "Same-level paths" subsubsection ‹Definition› text ‹ We define a constraint system that collects abstract information about same-level paths. In particular, we collect the set of used monitors and all multi-subsets of spawned threads that are not bigger than @{term k} elements, where @{term k} is a parameter that can be freely chosen. › text ‹ An element ‹(u,M,P)∈S_cs fg k› means that there is a same-level path from the entry node of the procedure of @{term u} to @{term u}, that uses the monitors @{term M} and spawns at least the threads in @{term P}. › inductive_set S_cs :: "('n,'p,'ba,'m,'more) flowgraph_rec_scheme ⇒ nat ⇒ ('n × 'm set × 'p multiset) set" for fg k where S_init: "(entry fg p,{},{#})∈S_cs fg k" | S_base: "⟦(u,Base a,v)∈edges fg; (u,M,P)∈S_cs fg k⟧ ⟹ (v,M,P)∈S_cs fg k" | S_call: "⟦(u,Call q,v)∈edges fg; (u,M,P)∈S_cs fg k; (return fg q,Ms,Ps)∈S_cs fg k; P'⊆#P+Ps; size P' ≤ k ⟧ ⟹ (v,mon fg q ∪ M ∪ Ms,P')∈S_cs fg k" | S_spawn: "⟦(u,Spawn q,v)∈edges fg; (u,M,P)∈S_cs fg k; P'⊆#{#q#}+P; size P' ≤ k⟧ ⟹ (v,M,P')∈S_cs fg k" text ‹ The intuition underlying this constraint system is the following: The @{thm [source] S_init}-constraint describes that the procedures entry node can be reached with the empty path, that has no monitors and spawns no procedures. The @{thm [source] S_base}-constraint describes that executing a base edge does not use monitors or spawn threads, so each path reaching the start node of the base edge also induces a path reaching the end node of the base edge with the same set of monitors and the same set of spawned threads. The @{thm [source] S_call}-constraint models the effect of a procedure call. If there is a path to the start node of a call edge and a same-level path through the procedure, this also induces a path to the end node of the call edge. This path uses the monitors of both path and spawns the threads that are spawned on both paths. Since we only record a limited subset of the spawned threads, we have to choose which of the threads are recorded. The @{thm [source] S_spawn}-constraint models the effect of a spawn edge. A path to the start node of the spawn edge induces a path to the end node that uses the same set of monitors and spawns the threads of the initial path plus the one spawned by the spawn edge. We again have to choose which of these threads are recorded. › subsubsection ‹Soundness and Precision› text ‹ Soundness of the constraint system ‹S_cs› means, that every same-level path has a corresponding entry in the constraint system. As usual the soundness proof works by induction over the length of execution paths. The base case (empty path) trivially follows from the @{thm [source] S_init} constraint. In the inductive case, we consider the edge that induces the last step of the path; for a return step, this is the corresponding call edge (cf. Lemma @{thm [source] flowgraph.trss_find_call'}). With the induction hypothesis, we get the soundness for the (shorter) prefix of the path, and depending on the last step we can choose a constraint that implies soundness for the whole path. › lemma (in flowgraph) S_sound: "!!p v c' P. ⟦(([entry fg p],{#}),w,([v],c'))∈trcl (trss fg); size P≤k; (λp. [entry fg p]) `# P ⊆# c' ⟧ ⟹ (v,mon_w fg w,P)∈S_cs fg k" proof (induct w rule: length_compl_rev_induct (*‹⟦?P []; ⋀l e. (⋀ll. length ll ≤ length l ⟹ ?P ll) ⟹ ?P (l @ [e])⟧ ⟹ ?P ?l›*)) (*goals: 1. ‹⋀p v c' P. ⟦(([entry fg p], {#}), [], [v], c') ∈ trcl (trss fg); size P ≤ k; {#[entry fg p]. p ∈# P#} ⊆# c'⟧ ⟹ (v, mon_w fg [], P) ∈ S_cs fg k› 2. ‹⋀l e p v c' P. ⟦⋀ll p v c' P. ⟦length ll ≤ length l; (([entry fg p], {#}), ll, [v], c') ∈ trcl (trss fg); size P ≤ k; {#[entry fg p]. p ∈# P#} ⊆# c'⟧ ⟹ (v, mon_w fg ll, P) ∈ S_cs fg k; (([entry fg p], {#}), l @ [e], [v], c') ∈ trcl (trss fg); size P ≤ k; {#[entry fg p]. p ∈# P#} ⊆# c'⟧ ⟹ (v, mon_w fg (l @ [e]), P) ∈ S_cs fg k›*) case Nil (*‹(([entry fg p], {#}), [], [v], c') ∈ trcl (trss fg)› ‹size P ≤ k› ‹{#[entry fg p]. p::'p::type ∈# P::'p::type multiset#} ⊆# (c'::'n::type list multiset)›*) thus "?case" (*goal: ‹(v, mon_w fg [], P) ∈ S_cs fg k›*) by (auto intro: S_init (*‹(entry (?fg::(?'n, ?'p, ?'ba, ?'m, ?'more) flowgraph_rec_scheme) (?p::?'p::type), {}, {#}) ∈ S_cs ?fg (?k::nat)›*)) next (*goal: ‹⋀l e p v c' P. ⟦⋀ll p v c' P. ⟦length ll ≤ length l; (([entry fg p], {#}), ll, [v], c') ∈ trcl (trss fg); size P ≤ k; {#[entry fg p]. p ∈# P#} ⊆# c'⟧ ⟹ (v, mon_w fg ll, P) ∈ S_cs fg k; (([entry fg p], {#}), l @ [e], [v], c') ∈ trcl (trss fg); size P ≤ k; {#[entry fg p]. p ∈# P#} ⊆# c'⟧ ⟹ (v, mon_w fg (l @ [e]), P) ∈ S_cs fg k›*) case (snoc w e) (*‹⟦length (?ll::('p, 'ba) label list) ≤ length (w::('p, 'ba) label list); (([entry fg (?p::'p)], {#}), ?ll, [?v::'n], ?c'::'n list multiset) ∈ trcl (trss fg); size (?P::'p multiset) ≤ (k::nat); {#[entry fg p]. p::'p ∈# ?P#} ⊆# ?c'⟧ ⟹ (?v, mon_w fg ?ll, ?P) ∈ S_cs fg k› ‹(([entry fg p], {#}), w @ [e], [v], c') ∈ trcl (trss fg)› ‹size P ≤ k› ‹{#[entry fg p]. p ∈# P#} ⊆# c'›*) then obtain sh and ch where SPLIT: "(([entry fg p],{#}),w,(sh,ch))∈trcl (trss fg)" "((sh,ch),e,([v],c'))∈trss fg" (*goal: ‹(⋀sh ch. ⟦(([entry fg p], {#}), w, sh, ch) ∈ trcl (trss fg); ((sh, ch), e, [v], c') ∈ trss fg⟧ ⟹ thesis) ⟹ thesis›*) by (fast dest: trcl_rev_uncons (*‹(?c, ?w @ [?e], ?c') ∈ trcl ?T ⟹ ∃ch. (?c, ?w, ch) ∈ trcl ?T ∧ (ch, ?e, ?c') ∈ ?T›*)) from SPLIT(2) (*‹((sh, ch), e, [v], c') ∈ trss fg›*) show "?case" (*goal: ‹(v, mon_w fg (w @ [e]), P) ∈ S_cs fg k›*) proof (cases rule: trss.cases (*‹⟦((?a1.0::?'n::type list, ?a2.0::?'n::type list multiset), ?a3.0::(?'p::type, ?'ba::type) label, ?a4.0::?'n::type list, ?a5.0::?'n::type list multiset) ∈ trss (?fg::(?'n, ?'p, ?'ba, ?'m, ?'more) flowgraph_rec_scheme); ⋀(u::?'n::type) (a::?'ba::type) (v::?'n::type) (r::?'n::type list) c::?'n::type list multiset. ⟦?a1.0 = u # r; ?a2.0 = c; ?a3.0 = LBase a; ?a4.0 = v # r; ?a5.0 = c; (u, Base a, v) ∈ edges ?fg⟧ ⟹ ?P::bool; ⋀(u::?'n::type) (p::?'p::type) (v::?'n::type) (c::?'n::type list multiset) r::?'n::type list. ⟦?a1.0 = u # r; ?a2.0 = c; ?a3.0 = LCall p; ?a4.0 = entry ?fg p # v # r; ?a5.0 = c; (u, Call p, v) ∈ edges ?fg; mon ?fg p ∩ mon_c ?fg c = {}⟧ ⟹ ?P; ⋀(p::?'p::type) (r::?'n::type list) c::?'n::type list multiset. ⟦?a1.0 = return ?fg p # r; ?a2.0 = c; ?a3.0 = LRet; ?a4.0 = r; ?a5.0 = c⟧ ⟹ ?P; ⋀(u::?'n::type) (p::?'p::type) (v::?'n::type) (r::?'n::type list) c::?'n::type list multiset. ⟦?a1.0 = u # r; ?a2.0 = c; ?a3.0 = LSpawn p; ?a4.0 = v # r; ?a5.0 = add_mset [entry ?fg p] c; (u, Spawn p, v) ∈ edges ?fg⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹⋀u a. ⟦sh = [u]; e = LBase a; c' = ch; (u, Base a, v) ∈ edges fg⟧ ⟹ (v, mon_w fg (w @ [e]), P) ∈ S_cs fg k› 2. ‹⋀p. ⟦sh = [return fg p, v]; e = LRet; c' = ch⟧ ⟹ (v, mon_w fg (w @ [e]), P) ∈ S_cs fg k› 3. ‹⋀u p. ⟦sh = [u]; e = LSpawn p; c' = add_mset [entry fg p] ch; (u, Spawn p, v) ∈ edges fg⟧ ⟹ (v, mon_w fg (w @ [e]), P) ∈ S_cs fg k›*) case trss_base (*‹sh = [u_]› ‹e = LBase a_› ‹c' = ch› ‹(u_, Base a_, v) ∈ edges fg›*) then obtain u and a where CASE: "e=LBase a" "sh=[u]" "ch=c'" "(u,Base a,v)∈edges fg" (*goal: ‹(⋀a u. ⟦e = LBase a; sh = [u]; ch = c'; (u, Base a, v) ∈ edges fg⟧ ⟹ thesis) ⟹ thesis›*) by auto with snoc.hyps[of w p u c', OF _ _ snoc.prems ( 2 , 3 )] (*‹⟦length w ≤ length w; (([entry fg p], {#}), w, [u], c') ∈ trcl (trss fg)⟧ ⟹ (u, mon_w fg w, P) ∈ S_cs fg k›*) SPLIT(1) (*‹(([entry fg p], {#}), w, sh, ch) ∈ trcl (trss fg)›*) have "(u,mon_w fg w,P)∈S_cs fg k" by blast moreover from CASE(1) (*‹e = LBase a›*) have "mon_e fg e = {}" by simp ultimately show "?thesis" (*goal: ‹(v::'n, mon_w fg ((w::('p, 'ba) label list) @ [e::('p, 'ba) label]), P::'p multiset) ∈ S_cs fg (k::nat)›*) using S_base[OF CASE ( 4 )] (*‹(u, ?M, ?P) ∈ S_cs fg ?k ⟹ (v, ?M, ?P) ∈ S_cs fg ?k›*) by (auto simp add: mon_w_unconc (*‹mon_w (?fg::(?'b, ?'c, ?'d, ?'a, ?'e) flowgraph_rec_scheme) ((?wa::(?'c::type, ?'f::type) label list) @ (?wb::(?'c::type, ?'f::type) label list)) = mon_w ?fg ?wa ∪ mon_w ?fg ?wb›*)) next (*goals: 1. ‹⋀p. ⟦sh = [return fg p, v]; e = LRet; c' = ch⟧ ⟹ (v, mon_w fg (w @ [e]), P) ∈ S_cs fg k› 2. ‹⋀u p. ⟦sh = [u]; e = LSpawn p; c' = add_mset [entry fg p] ch; (u, Spawn p, v) ∈ edges fg⟧ ⟹ (v, mon_w fg (w @ [e]), P) ∈ S_cs fg k›*) case trss_ret (*‹sh = [return fg p_, v]› ‹e = LRet› ‹c' = ch›*) then obtain q where CASE: "e=LRet" "sh=return fg q#[v]" "ch=c'" (*goal: ‹(⋀q::'p. ⟦(e::('p, 'ba) label) = LRet; (sh::'n list) = [return fg q, v::'n]; (ch::'n list multiset) = (c'::'n list multiset)⟧ ⟹ thesis::bool) ⟹ thesis›*) by auto with SPLIT(1) (*‹(([entry fg (p::'p)], {#}), w::('p, 'ba) label list, sh::'n list, ch::'n list multiset) ∈ trcl (trss fg)›*) have "(([entry fg p], {#}), w, [return fg q,v], c') ∈ trcl (trss fg)" by simp from trss_find_call'[OF this] (*‹(⋀uh ch waa wb. ⟦w = waa @ LCall q # wb; (([entry fg p], {#}), waa, [uh], ch) ∈ trcl (trss fg); (([uh], ch), LCall q, [entry fg q, v], ch) ∈ trss fg; (uh, Call q, v) ∈ edges fg; (([entry fg q], ch), wb, [return fg q], c') ∈ trcl (trss fg)⟧ ⟹ ?P) ⟹ ?P›*) obtain ut and ct and w1 and w2 where FC: "w=w1@LCall q#w2" "(([entry fg p],{#}),w1,([ut],ct))∈trcl (trss fg)" "(([ut],ct),LCall q,([entry fg q,v],ct))∈trss fg" "(ut,Call q,v)∈edges fg" "(([entry fg q],ct),w2,([return fg q],c'))∈trcl (trss fg)" (*goal: ‹(⋀w1 w2 ut ct. ⟦w = w1 @ LCall q # w2; (([entry fg p], {#}), w1, [ut], ct) ∈ trcl (trss fg); (([ut], ct), LCall q, [entry fg q, v], ct) ∈ trss fg; (ut, Call q, v) ∈ edges fg; (([entry fg q], ct), w2, [return fg q], c') ∈ trcl (trss fg)⟧ ⟹ thesis) ⟹ thesis›*) . from trss_drop_all_context[OF FC ( 5 )] (*‹(⋀csp. ⟦c' = csp + ct; (([entry fg q], {#}), w2, [return fg q], csp) ∈ trcl (trss fg)⟧ ⟹ ?P) ⟹ ?P›*) obtain csp' where SLP: "c'=ct+csp'" "(([entry fg q],{#}),w2,([return fg q],csp'))∈trcl (trss fg)" (*goal: ‹(⋀csp'. ⟦c' = ct + csp'; (([entry fg q], {#}), w2, [return fg q], csp') ∈ trcl (trss fg)⟧ ⟹ thesis) ⟹ thesis›*) by (auto simp add: union_ac (*‹?M + ?N + ?K = ?M + (?N + ?K)› ‹?M + ?N = ?N + ?M› ‹?M + (?N + ?K) = ?N + (?M + ?K)› ‹add_mset ?x (add_mset ?y ?M) = add_mset ?y (add_mset ?x ?M)›*)) from FC(1) (*‹w = w1 @ LCall q # w2›*) have LEN: "length w1 ≤ length w" "length w2 ≤ length w" apply - (*goals: 1. ‹(w::('p, 'ba) label list) = (w1::('p, 'ba) label list) @ LCall (q::'p) # (w2::('p, 'ba) label list) ⟹ length w1 ≤ length w› 2. ‹(w::('p, 'ba) label list) = (w1::('p, 'ba) label list) @ LCall (q::'p) # (w2::('p, 'ba) label list) ⟹ length w2 ≤ length w› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . from mset_map_split_orig_le (*‹⟦?f `# ?P ⊆# ?M1.0 + ?M2.0; ⋀P1 P2. ⟦?P = P1 + P2; ?f `# P1 ⊆# ?M1.0; ?f `# P2 ⊆# ?M2.0⟧ ⟹ ?Q⟧ ⟹ ?Q›*) SLP(1) (*‹(c'::'n::type list multiset) = (ct::'n::type list multiset) + (csp'::'n::type list multiset)›*) snoc.prems(3) (*‹{#[entry fg p]. p ∈# P#} ⊆# c'›*) obtain P1 and P2 where PSPLIT: "P=P1+P2" "(λp. [entry fg p]) `# P1 ⊆# ct" "(λp. [entry fg p]) `# P2 ⊆# csp'" (*goal: ‹(⋀(P1::'p multiset) P2::'p multiset. ⟦(P::'p multiset) = P1 + P2; {#[entry fg p]. p::'p ∈# P1#} ⊆# (ct::'n list multiset); {#[entry fg p]. p::'p ∈# P2#} ⊆# (csp'::'n list multiset)⟧ ⟹ thesis::bool) ⟹ thesis›*) by blast with snoc.prems(2) (*‹size (P::'p multiset) ≤ (k::nat)›*) have PSIZE: "size P1 ≤ k" "size P2 ≤ k" apply - (*goals: 1. ‹⟦size P ≤ k; P = P1 + P2; {#[entry fg p]. p ∈# P1#} ⊆# ct; {#[entry fg p]. p ∈# P2#} ⊆# csp'⟧ ⟹ size P1 ≤ k› 2. ‹⟦size P ≤ k; P = P1 + P2; {#[entry fg p]. p ∈# P1#} ⊆# ct; {#[entry fg p]. p ∈# P2#} ⊆# csp'⟧ ⟹ size P2 ≤ k› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . from snoc.hyps[OF LEN ( 1 ) FC ( 2 ) PSIZE ( 1 ) PSPLIT ( 2 )] (*‹(ut, mon_w fg w1, P1) ∈ S_cs fg k›*) snoc.hyps[OF LEN ( 2 ) SLP ( 2 ) PSIZE ( 2 ) PSPLIT ( 3 )] (*‹(return fg q, mon_w fg w2, P2) ∈ S_cs fg k›*) have IHAPP: "(ut, mon_w fg w1, P1) ∈ S_cs fg k" "(return fg q, mon_w fg w2, P2) ∈ S_cs fg k" apply - (*goals: 1. ‹⟦(ut, mon_w fg w1, P1) ∈ S_cs fg k; (return fg q, mon_w fg w2, P2) ∈ S_cs fg k⟧ ⟹ (ut, mon_w fg w1, P1) ∈ S_cs fg k› 2. ‹⟦(ut, mon_w fg w1, P1) ∈ S_cs fg k; (return fg q, mon_w fg w2, P2) ∈ S_cs fg k⟧ ⟹ (return fg q, mon_w fg w2, P2) ∈ S_cs fg k› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) from S_call[OF FC ( 4 ) IHAPP subset_mset.eq_refl [ OF PSPLIT ( 1 ) ] snoc.prems ( 2 )] (*‹(v, mon fg q ∪ mon_w fg w1 ∪ mon_w fg w2, P) ∈ S_cs fg k›*) FC(1) (*‹w = w1 @ LCall q # w2›*) CASE(1) (*‹e = LRet›*) show "(v, mon_w fg (w@[e]), P) ∈ S_cs fg k" by (auto simp add: mon_w_unconc (*‹mon_w ?fg (?wa @ ?wb) = mon_w ?fg ?wa ∪ mon_w ?fg ?wb›*) Un_ac (*‹?A ∪ ?B ∪ ?C = ?A ∪ (?B ∪ ?C)› ‹?A ∪ (?A ∪ ?B) = ?A ∪ ?B› ‹?A ∪ ?B = ?B ∪ ?A› ‹?A ∪ (?B ∪ ?C) = ?B ∪ (?A ∪ ?C)›*)) next (*goal: ‹⋀u p. ⟦sh = [u]; e = LSpawn p; c' = add_mset [entry fg p] ch; (u, Spawn p, v) ∈ edges fg⟧ ⟹ (v, mon_w fg (w @ [e]), P) ∈ S_cs fg k›*) case trss_spawn (*‹sh = [u_]› ‹e = LSpawn p_› ‹c' = add_mset [entry fg p_] ch› ‹(u_, Spawn p_, v) ∈ edges fg›*) then obtain u and q where CASE: "e=LSpawn q" "sh=[u]" "c'={#[entry fg q]#}+ch" "(u,Spawn q,v)∈edges fg" (*goal: ‹(⋀q u. ⟦e = LSpawn q; sh = [u]; c' = {#[entry fg q]#} + ch; (u, Spawn q, v) ∈ edges fg⟧ ⟹ thesis) ⟹ thesis›*) by auto from mset_map_split_orig_le (*‹⟦?f `# ?P ⊆# ?M1.0 + ?M2.0; ⋀P1 P2. ⟦?P = P1 + P2; ?f `# P1 ⊆# ?M1.0; ?f `# P2 ⊆# ?M2.0⟧ ⟹ ?Q⟧ ⟹ ?Q›*) CASE(3) (*‹(c'::'n list multiset) = {#[entry fg (q::'p)]#} + (ch::'n list multiset)›*) snoc.prems(3) (*‹{#[entry fg p]. p ∈# P#} ⊆# c'›*) obtain P1 and P2 where PSPLIT: "P=P1+P2" "(λp. [entry fg p]) `# P1 ⊆# {#[entry fg q]#}" "(λp. [entry fg p]) `# P2 ⊆# ch" (*goal: ‹(⋀P1 P2. ⟦P = P1 + P2; {#[entry fg p]. p ∈# P1#} ⊆# {#[entry fg q]#}; {#[entry fg p]. p ∈# P2#} ⊆# ch⟧ ⟹ thesis) ⟹ thesis›*) by blast with snoc.prems(2) (*‹size P ≤ k›*) have PSIZE: "size P2 ≤ k" by simp from snoc.hyps[OF _ _ PSIZE PSPLIT ( 3 )] (*‹⟦length ?ll ≤ length w; (([entry fg ?p], {#}), ?ll, [?v], ch) ∈ trcl (trss fg)⟧ ⟹ (?v, mon_w fg ?ll, P2) ∈ S_cs fg k›*) SPLIT(1) (*‹(([entry fg p], {#}), w, sh, ch) ∈ trcl (trss fg)›*) CASE(2) (*‹sh = [u]›*) have IHAPP: "(u,mon_w fg w,P2)∈S_cs fg k" by blast have PCOND: "P ⊆# {#q#}+P2" proof (-) (*goal: ‹P ⊆# {#q#} + P2›*) from PSPLIT(2) (*‹{#[entry fg p]. p ∈# P1#} ⊆# {#[entry fg q]#}›*) have "P1⊆#{#q#}" by (auto elim!: mset_le_single_cases (*‹⟦?M ⊆# {#?a#}; ?M = {#} ⟹ ?P; ?M = {#?a#} ⟹ ?P⟧ ⟹ ?P›*) mset_map_single_rightE (*‹⟦?f `# ?P = {#?y#}; ⋀x. ⟦?P = {#x#}; ?f x = ?y⟧ ⟹ ?Q⟧ ⟹ ?Q›*)) with PSPLIT(1) (*‹P = P1 + P2›*) show "?thesis" (*goal: ‹P ⊆# {#q#} + P2›*) by simp qed from S_spawn[OF CASE ( 4 ) IHAPP PCOND snoc.prems ( 2 )] (*‹(v, mon_w fg w, P) ∈ S_cs fg k›*) CASE(1) (*‹e = LSpawn q›*) show "(v, mon_w fg (w @ [e]), P) ∈ S_cs fg k" by (auto simp add: mon_w_unconc (*‹mon_w ?fg (?wa @ ?wb) = mon_w ?fg ?wa ∪ mon_w ?fg ?wb›*)) qed qed text ‹ Precision means that all entries appearing in the smallest solution of the constraint system are justified by some path in the operational characterization. For proving precision, one usually shows that a family of sets derived as an abstraction from the operational characterization solves all constraints. In our formalization of constraint systems as inductive sets this amounts to constructing for each constraint a justifying path for the entries described on the conclusion side of the implication -- under the assumption that corresponding paths exists for the entries mentioned in the antecedent. › lemma (in flowgraph) S_precise: "(v,M,P)∈S_cs fg k ⟹ ∃p c' w. (([entry fg p],{#}),w,([v],c'))∈trcl (trss fg) ∧ size P≤k ∧ (λp. [entry fg p]) `# P ⊆# c' ∧ M=mon_w fg w" proof (induct rule: S_cs.induct (*‹⟦(?x1.0, ?x2.0, ?x3.0) ∈ S_cs ?fg ?k; ⋀p. ?P (entry ?fg p) {} {#}; ⋀u a v M P. ⟦(u, Base a, v) ∈ edges ?fg; (u, M, P) ∈ S_cs ?fg ?k; ?P u M P⟧ ⟹ ?P v M P; ⋀u q v M P Ms Ps P'. ⟦(u, Call q, v) ∈ edges ?fg; (u, M, P) ∈ S_cs ?fg ?k; ?P u M P; (return ?fg q, Ms, Ps) ∈ S_cs ?fg ?k; ?P (return ?fg q) Ms Ps; P' ⊆# P + Ps; size P' ≤ ?k⟧ ⟹ ?P v (mon ?fg q ∪ M ∪ Ms) P'; ⋀u q v M P P'. ⟦(u, Spawn q, v) ∈ edges ?fg; (u, M, P) ∈ S_cs ?fg ?k; ?P u M P; P' ⊆# {#q#} + P; size P' ≤ ?k⟧ ⟹ ?P v M P'⟧ ⟹ ?P ?x1.0 ?x2.0 ?x3.0›*)) (*goals: 1. ‹⋀p::'p. ∃(pa::'p) (c'::'n list multiset) w::('p, 'ba) label list. (([entry fg pa], {#}), w, [entry fg p], c') ∈ trcl (trss fg) ∧ size {#} ≤ (k::nat) ∧ {#[entry fg p]. p::'p ∈# {#}#} ⊆# c' ∧ {} = mon_w fg w› 2. ‹⋀(u::'n) (a::'ba) (v::'n) (M::'m set) P::'p multiset. ⟦(u, Base a, v) ∈ edges fg; (u, M, P) ∈ S_cs fg (k::nat); ∃(p::'p) (c'::'n list multiset) w::('p, 'ba) label list. (([entry fg p], {#}), w, [u], c') ∈ trcl (trss fg) ∧ size P ≤ k ∧ {#[entry fg p]. p::'p ∈# P#} ⊆# c' ∧ M = mon_w fg w⟧ ⟹ ∃(p::'p) (c'::'n list multiset) w::('p, 'ba) label list. (([entry fg p], {#}), w, [v], c') ∈ trcl (trss fg) ∧ size P ≤ k ∧ {#[entry fg p]. p::'p ∈# P#} ⊆# c' ∧ M = mon_w fg w› 3. ‹⋀(u::'n) (q::'p) (v::'n) (M::'m set) (P::'p multiset) (Ms::'m set) (Ps::'p multiset) P'::'p multiset. ⟦(u, Call q, v) ∈ edges fg; (u, M, P) ∈ S_cs fg (k::nat); ∃(p::'p) (c'::'n list multiset) w::('p, 'ba) label list. (([entry fg p], {#}), w, [u], c') ∈ trcl (trss fg) ∧ size P ≤ k ∧ {#[entry fg p]. p::'p ∈# P#} ⊆# c' ∧ M = mon_w fg w; (return fg q, Ms, Ps) ∈ S_cs fg k; ∃(p::'p) (c'::'n list multiset) w::('p, 'ba) label list. (([entry fg p], {#}), w, [return fg q], c') ∈ trcl (trss fg) ∧ size Ps ≤ k ∧ {#[entry fg p]. p::'p ∈# Ps#} ⊆# c' ∧ Ms = mon_w fg w; P' ⊆# P + Ps; size P' ≤ k⟧ ⟹ ∃(p::'p) (c'::'n list multiset) w::('p, 'ba) label list. (([entry fg p], {#}), w, [v], c') ∈ trcl (trss fg) ∧ size P' ≤ k ∧ {#[entry fg p]. p::'p ∈# P'#} ⊆# c' ∧ mon fg q ∪ M ∪ Ms = mon_w fg w› 4. ‹⋀(u::'n) (q::'p) (v::'n) (M::'m set) (P::'p multiset) P'::'p multiset. ⟦(u, Spawn q, v) ∈ edges fg; (u, M, P) ∈ S_cs fg (k::nat); ∃(p::'p) (c'::'n list multiset) w::('p, 'ba) label list. (([entry fg p], {#}), w, [u], c') ∈ trcl (trss fg) ∧ size P ≤ k ∧ {#[entry fg p]. p::'p ∈# P#} ⊆# c' ∧ M = mon_w fg w; P' ⊆# {#q#} + P; size P' ≤ k⟧ ⟹ ∃(p::'p) (c'::'n list multiset) w::('p, 'ba) label list. (([entry fg p], {#}), w, [v], c') ∈ trcl (trss fg) ∧ size P' ≤ k ∧ {#[entry fg p]. p::'p ∈# P'#} ⊆# c' ∧ M = mon_w fg w›*) case (S_init p) (*no hyothesis introduced yet*) have "(([entry fg p],{#}),[],([entry fg p],{#}))∈trcl (trss fg)" by simp thus "?case" (*goal: ‹∃(pa::'p) (c'::'n list multiset) w::('p, 'ba) label list. (([entry fg pa], {#}), w, [entry fg (p::'p)], c') ∈ trcl (trss fg) ∧ size {#} ≤ (k::nat) ∧ {#[entry fg p]. p::'p ∈# {#}#} ⊆# c' ∧ {} = mon_w fg w›*) by fastforce next (*goals: 1. ‹⋀u a v M P. ⟦(u, Base a, v) ∈ edges fg; (u, M, P) ∈ S_cs fg k; ∃p c' w. (([entry fg p], {#}), w, [u], c') ∈ trcl (trss fg) ∧ size P ≤ k ∧ {#[entry fg p]. p ∈# P#} ⊆# c' ∧ M = mon_w fg w⟧ ⟹ ∃p c' w. (([entry fg p], {#}), w, [v], c') ∈ trcl (trss fg) ∧ size P ≤ k ∧ {#[entry fg p]. p ∈# P#} ⊆# c' ∧ M = mon_w fg w› 2. ‹⋀u q v M P Ms Ps P'. ⟦(u, Call q, v) ∈ edges fg; (u, M, P) ∈ S_cs fg k; ∃p c' w. (([entry fg p], {#}), w, [u], c') ∈ trcl (trss fg) ∧ size P ≤ k ∧ {#[entry fg p]. p ∈# P#} ⊆# c' ∧ M = mon_w fg w; (return fg q, Ms, Ps) ∈ S_cs fg k; ∃p c' w. (([entry fg p], {#}), w, [return fg q], c') ∈ trcl (trss fg) ∧ size Ps ≤ k ∧ {#[entry fg p]. p ∈# Ps#} ⊆# c' ∧ Ms = mon_w fg w; P' ⊆# P + Ps; size P' ≤ k⟧ ⟹ ∃p c' w. (([entry fg p], {#}), w, [v], c') ∈ trcl (trss fg) ∧ size P' ≤ k ∧ {#[entry fg p]. p ∈# P'#} ⊆# c' ∧ mon fg q ∪ M ∪ Ms = mon_w fg w› 3. ‹⋀u q v M P P'. ⟦(u, Spawn q, v) ∈ edges fg; (u, M, P) ∈ S_cs fg k; ∃p c' w. (([entry fg p], {#}), w, [u], c') ∈ trcl (trss fg) ∧ size P ≤ k ∧ {#[entry fg p]. p ∈# P#} ⊆# c' ∧ M = mon_w fg w; P' ⊆# {#q#} + P; size P' ≤ k⟧ ⟹ ∃p c' w. (([entry fg p], {#}), w, [v], c') ∈ trcl (trss fg) ∧ size P' ≤ k ∧ {#[entry fg p]. p ∈# P'#} ⊆# c' ∧ M = mon_w fg w›*) case (S_base u a v M P) (*‹(u, Base a, v) ∈ edges fg› ‹(u, M, P) ∈ S_cs fg k› ‹∃p c' w. (([entry fg p], {#}), w, [u], c') ∈ trcl (trss fg) ∧ size P ≤ k ∧ {#[entry fg p]. p ∈# P#} ⊆# c' ∧ M = mon_w fg w›*) then obtain p and c' and w where IHAPP: "(([entry fg p], {#}), w, [u], c') ∈ trcl (trss fg)" "size P ≤ k" "(λp. [entry fg p]) `# P ⊆# c'" "M = mon_w fg w" (*goal: ‹(⋀p w c'. ⟦(([entry fg p], {#}), w, [u], c') ∈ trcl (trss fg); size P ≤ k; {#[entry fg p]. p ∈# P#} ⊆# c'; M = mon_w fg w⟧ ⟹ thesis) ⟹ thesis›*) by blast note IHAPP(1) (*‹(([entry fg p], {#}), w, [u], c') ∈ trcl (trss fg)›*) also (*calculation: ‹(([entry fg p], {#}), w, [u], c') ∈ trcl (trss fg)›*) from S_base (*‹(u, Base a, v) ∈ edges fg› ‹(u, M, P) ∈ S_cs fg k› ‹∃p c' w. (([entry fg p], {#}), w, [u], c') ∈ trcl (trss fg) ∧ size P ≤ k ∧ {#[entry fg p]. p ∈# P#} ⊆# c' ∧ M = mon_w fg w›*) have "(([u],c'),LBase a,([v],c'))∈trss fg" by (auto intro: trss_base (*‹(?u, Base ?a, ?v) ∈ edges ?fg ⟹ ((?u # ?r, ?c), LBase ?a, ?v # ?r, ?c) ∈ trss ?fg›*)) finally (*calculation: ‹(([entry fg p], {#}), w @ [LBase a], [v], c') ∈ trcl (trss fg)›*) have "(([entry fg p], {#}), w @ [LBase a], [v], c') ∈ trcl (trss fg)" . moreover from IHAPP(4) (*‹M = mon_w fg w›*) have "M=mon_w fg (w @ [LBase a])" by (simp add: mon_w_unconc (*‹mon_w ?fg (?wa @ ?wb) = mon_w ?fg ?wa ∪ mon_w ?fg ?wb›*)) ultimately show "?case" (*goal: ‹∃p c' w. (([entry fg p], {#}), w, [v], c') ∈ trcl (trss fg) ∧ size P ≤ k ∧ {#[entry fg p]. p ∈# P#} ⊆# c' ∧ M = mon_w fg w›*) using IHAPP(2,3,4) (*‹size P ≤ k› ‹{#[entry fg p]. p::'p ∈# P::'p multiset#} ⊆# (c'::'n list multiset)› ‹M = mon_w fg w›*) by blast next (*goals: 1. ‹⋀u q v M P Ms Ps P'. ⟦(u, Call q, v) ∈ edges fg; (u, M, P) ∈ S_cs fg k; ∃p c' w. (([entry fg p], {#}), w, [u], c') ∈ trcl (trss fg) ∧ size P ≤ k ∧ {#[entry fg p]. p ∈# P#} ⊆# c' ∧ M = mon_w fg w; (return fg q, Ms, Ps) ∈ S_cs fg k; ∃p c' w. (([entry fg p], {#}), w, [return fg q], c') ∈ trcl (trss fg) ∧ size Ps ≤ k ∧ {#[entry fg p]. p ∈# Ps#} ⊆# c' ∧ Ms = mon_w fg w; P' ⊆# P + Ps; size P' ≤ k⟧ ⟹ ∃p c' w. (([entry fg p], {#}), w, [v], c') ∈ trcl (trss fg) ∧ size P' ≤ k ∧ {#[entry fg p]. p ∈# P'#} ⊆# c' ∧ mon fg q ∪ M ∪ Ms = mon_w fg w› 2. ‹⋀u q v M P P'. ⟦(u, Spawn q, v) ∈ edges fg; (u, M, P) ∈ S_cs fg k; ∃p c' w. (([entry fg p], {#}), w, [u], c') ∈ trcl (trss fg) ∧ size P ≤ k ∧ {#[entry fg p]. p ∈# P#} ⊆# c' ∧ M = mon_w fg w; P' ⊆# {#q#} + P; size P' ≤ k⟧ ⟹ ∃p c' w. (([entry fg p], {#}), w, [v], c') ∈ trcl (trss fg) ∧ size P' ≤ k ∧ {#[entry fg p]. p ∈# P'#} ⊆# c' ∧ M = mon_w fg w›*) case (S_call u q v M P Ms Ps P') (*‹(u, Call q, v) ∈ edges fg› ‹(u, M, P) ∈ S_cs fg k› ‹∃(p::'p) (c'::'n list multiset) w::('p, 'ba) label list. (([entry fg p], {#}), w, [u::'n], c') ∈ trcl (trss fg) ∧ size (P::'p multiset) ≤ (k::nat) ∧ {#[entry fg p]. p::'p ∈# P#} ⊆# c' ∧ (M::'m set) = mon_w fg w› ‹(return fg q, Ms, Ps) ∈ S_cs fg k› ‹∃p c' w. (([entry fg p], {#}), w, [return fg q], c') ∈ trcl (trss fg) ∧ size Ps ≤ k ∧ {#[entry fg p]. p ∈# Ps#} ⊆# c' ∧ Ms = mon_w fg w› ‹P' ⊆# P + Ps› ‹size P' ≤ k›*) then obtain p and csp1 and w1 where REACHING_PATH: "(([entry fg p], {#}), w1, [u], csp1) ∈ trcl (trss fg)" "size P ≤ k" "(λp. [entry fg p]) `# P ⊆# csp1" "M = mon_w fg w1" (*goal: ‹(⋀p w1 csp1. ⟦(([entry fg p], {#}), w1, [u], csp1) ∈ trcl (trss fg); size P ≤ k; {#[entry fg p]. p ∈# P#} ⊆# csp1; M = mon_w fg w1⟧ ⟹ thesis) ⟹ thesis›*) by blast from S_call (*‹(u, Call q, v) ∈ edges fg› ‹(u::'n, M::'m set, P::'p multiset) ∈ S_cs fg (k::nat)› ‹∃p c' w. (([entry fg p], {#}), w, [u], c') ∈ trcl (trss fg) ∧ size P ≤ k ∧ {#[entry fg p]. p ∈# P#} ⊆# c' ∧ M = mon_w fg w› ‹(return fg q, Ms, Ps) ∈ S_cs fg k› ‹∃p c' w. (([entry fg p], {#}), w, [return fg q], c') ∈ trcl (trss fg) ∧ size Ps ≤ k ∧ {#[entry fg p]. p ∈# Ps#} ⊆# c' ∧ Ms = mon_w fg w› ‹P' ⊆# P + Ps› ‹size P' ≤ k›*) obtain csp2 and w2 where SL_PATH: "(([entry fg q], {#}), w2, [return fg q], csp2) ∈ trcl (trss fg)" "size Ps ≤ k" "(λp. [entry fg p]) `# Ps ⊆# csp2" "Ms = mon_w fg w2" (*goal: ‹(⋀w2 csp2. ⟦(([entry fg q], {#}), w2, [return fg q], csp2) ∈ trcl (trss fg); size Ps ≤ k; {#[entry fg p]. p ∈# Ps#} ⊆# csp2; Ms = mon_w fg w2⟧ ⟹ thesis) ⟹ thesis›*) by (blast dest: trss_er_path_proc_const (*‹(([entry fg ?p], ?c), ?w, [return fg ?q], ?c') ∈ trcl (trss fg) ⟹ ?p = ?q›*)) from trss_c_no_mon[OF REACHING_PATH ( 1 )] (*‹mon_c fg (csp1::'n list multiset) = mon_c fg {#}›*) trss_c_no_mon[OF SL_PATH ( 1 )] (*‹mon_c fg csp2 = mon_c fg {#}›*) have NOMON: "mon_c fg csp1 = {}" "mon_c fg csp2 = {}" apply - (*goals: 1. ‹⟦mon_c fg csp1 = mon_c fg {#}; mon_c fg csp2 = mon_c fg {#}⟧ ⟹ mon_c fg csp1 = {}› 2. ‹⟦mon_c fg csp1 = mon_c fg {#}; mon_c fg csp2 = mon_c fg {#}⟧ ⟹ mon_c fg csp2 = {}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have "(([entry fg p], {#}), w1@LCall q#w2@[LRet],([v],csp1+csp2))∈trcl (trss fg)" proof (-) (*goal: ‹(([entry fg p], {#}), w1 @ LCall q # w2 @ [LRet], [v], csp1 + csp2) ∈ trcl (trss fg)›*) note REACHING_PATH(1) (*‹(([entry fg (p::'p)], {#}), w1::('p, 'ba) label list, [u::'n], csp1::'n list multiset) ∈ trcl (trss fg)›*) also (*calculation: ‹(([entry fg p], {#}), w1, [u], csp1) ∈ trcl (trss fg)›*) from trss_call[OF S_call ( 1 )] (*‹mon fg q ∩ mon_c fg ?c = {} ⟹ ((u # ?r, ?c), LCall q, entry fg q # v # ?r, ?c) ∈ trss fg›*) NOMON (*‹mon_c fg csp1 = {}› ‹mon_c fg csp2 = {}›*) have "(([u],csp1),LCall q,([entry fg q,v],csp1))∈trss fg" by auto also (*calculation: ‹(([entry fg (p::'p)], {#}), (w1::('p, 'ba) label list) @ [LCall (q::'p)], [entry fg q, v::'n], csp1::'n list multiset) ∈ trcl (trss fg)›*) from trss_add_context[OF trss_stack_comp [ OF SL_PATH ( 1 ) ]] (*‹mon_w fg w2 ∩ mon_c fg ?ce = {} ⟹ (([entry fg q] @ ?r1, {#} + ?ce), w2, [return fg q] @ ?r1, csp2 + ?ce) ∈ trcl (trss fg)›*) NOMON (*‹mon_c fg csp1 = {}› ‹mon_c fg csp2 = {}›*) have "(([entry fg q,v],csp1),w2,([return fg q,v],csp1+csp2))∈trcl (trss fg)" by (simp add: union_ac (*‹?M + ?N + ?K = ?M + (?N + ?K)› ‹?M + ?N = ?N + ?M› ‹?M + (?N + ?K) = ?N + (?M + ?K)› ‹add_mset ?x (add_mset ?y ?M) = add_mset ?y (add_mset ?x ?M)›*)) also (*calculation: ‹(([entry fg p], {#}), (w1 @ [LCall q]) @ w2, [return fg q, v], csp1 + csp2) ∈ trcl (trss fg)›*) have "(([return fg q,v],csp1+csp2),LRet,([v],csp1+csp2))∈trss fg" by (rule trss_ret (*‹((return ?fg ?p # ?r, ?c), LRet, ?r, ?c) ∈ trss ?fg›*)) finally (*calculation: ‹(([entry fg p], {#}), ((w1 @ [LCall q]) @ w2) @ [LRet], [v], csp1 + csp2) ∈ trcl (trss fg)›*) show "?thesis" (*goal: ‹(([entry fg p], {#}), w1 @ LCall q # w2 @ [LRet], [v], csp1 + csp2) ∈ trcl (trss fg)›*) by simp qed moreover from REACHING_PATH(4) (*‹M = mon_w fg w1›*) SL_PATH(4) (*‹Ms = mon_w fg w2›*) have "mon fg q ∪ M ∪ Ms = mon_w fg (w1@LCall q#w2@[LRet])" by (auto simp add: mon_w_unconc (*‹mon_w ?fg (?wa @ ?wb) = mon_w ?fg ?wa ∪ mon_w ?fg ?wb›*)) moreover have "(λp. [entry fg p]) `# (P') ⊆# csp1+csp2" (is "?f `# P' ⊆# _") proof (-) (*goal: ‹{#[entry fg p]. p ∈# P'#} ⊆# csp1 + csp2›*) from image_mset_subseteq_mono[OF S_call ( 6 )] (*‹?f `# P' ⊆# ?f `# (P + Ps)›*) have "?f `# P' ⊆# ?f `# P + ?f `# Ps" by auto also (*calculation: ‹{#[entry fg p]. p ∈# P'#} ⊆# {#[entry fg p]. p ∈# P#} + {#[entry fg p]. p ∈# Ps#}›*) from mset_subset_eq_mono_add[OF REACHING_PATH ( 3 ) SL_PATH ( 3 )] (*‹{#[entry fg p]. p ∈# P#} + {#[entry fg p]. p ∈# Ps#} ⊆# csp1 + csp2›*) have "… ⊆# csp1+csp2" . finally (*calculation: ‹{#[entry fg p]. p ∈# P'#} ⊆# csp1 + csp2›*) show "?thesis" (*goal: ‹{#[entry fg p]. p ∈# P'#} ⊆# csp1 + csp2›*) . qed moreover note S_call(7) (*‹size P' ≤ k›*) ultimately show "?case" (*goal: ‹∃p c' w. (([entry fg p], {#}), w, [v], c') ∈ trcl (trss fg) ∧ size P' ≤ k ∧ {#[entry fg p]. p ∈# P'#} ⊆# c' ∧ mon fg q ∪ M ∪ Ms = mon_w fg w›*) by blast next (*goal: ‹⋀u q v M P P'. ⟦(u, Spawn q, v) ∈ edges fg; (u, M, P) ∈ S_cs fg k; ∃p c' w. (([entry fg p], {#}), w, [u], c') ∈ trcl (trss fg) ∧ size P ≤ k ∧ {#[entry fg p]. p ∈# P#} ⊆# c' ∧ M = mon_w fg w; P' ⊆# {#q#} + P; size P' ≤ k⟧ ⟹ ∃p c' w. (([entry fg p], {#}), w, [v], c') ∈ trcl (trss fg) ∧ size P' ≤ k ∧ {#[entry fg p]. p ∈# P'#} ⊆# c' ∧ M = mon_w fg w›*) case (S_spawn u q v M P P') (*‹(u, Spawn q, v) ∈ edges fg› ‹(u, M, P) ∈ S_cs fg k› ‹∃p c' w. (([entry fg p], {#}), w, [u], c') ∈ trcl (trss fg) ∧ size P ≤ k ∧ {#[entry fg p]. p ∈# P#} ⊆# c' ∧ M = mon_w fg w› ‹P' ⊆# {#q#} + P› ‹size (P'::'p multiset) ≤ (k::nat)›*) then obtain p and c' and w where IHAPP: "(([entry fg p], {#}), w, [u], c') ∈ trcl (trss fg)" "size P ≤ k" "(λp. [entry fg p]) `# P ⊆# c'" "M = mon_w fg w" (*goal: ‹(⋀p w c'. ⟦(([entry fg p], {#}), w, [u], c') ∈ trcl (trss fg); size P ≤ k; {#[entry fg p]. p ∈# P#} ⊆# c'; M = mon_w fg w⟧ ⟹ thesis) ⟹ thesis›*) by blast note IHAPP(1) (*‹(([entry fg (p::'p)], {#}), w::('p, 'ba) label list, [u::'n], c'::'n list multiset) ∈ trcl (trss fg)›*) also (*calculation: ‹(([entry fg p], {#}), w, [u], c') ∈ trcl (trss fg)›*) from S_spawn(1) (*‹(u::'n, Spawn (q::'p), v::'n) ∈ edges fg›*) have "(([u],c'),LSpawn q,([v],add_mset [entry fg q] c'))∈trss fg" by (rule trss_spawn (*‹(?u, Spawn ?p, ?v) ∈ edges ?fg ⟹ ((?u # ?r, ?c), LSpawn ?p, ?v # ?r, add_mset [entry ?fg ?p] ?c) ∈ trss ?fg›*)) finally (*calculation: ‹(([entry fg p], {#}), w @ [LSpawn q], [v], add_mset [entry fg q] c') ∈ trcl (trss fg)›*) have "(([entry fg p], {#}), w @ [LSpawn q], [v], add_mset [entry fg q] c') ∈ trcl (trss fg)" . moreover from IHAPP(4) (*‹M = mon_w fg w›*) have "M=mon_w fg (w @ [LSpawn q])" by (simp add: mon_w_unconc (*‹mon_w ?fg (?wa @ ?wb) = mon_w ?fg ?wa ∪ mon_w ?fg ?wb›*)) moreover have "(λp. [entry fg p]) `# P' ⊆# {#[entry fg q]#} + c'" (is "?f `# _ ⊆# _") proof (-) (*goal: ‹{#[entry fg p]. p ∈# P'#} ⊆# {#[entry fg q]#} + c'›*) from image_mset_subseteq_mono[OF S_spawn ( 4 )] (*‹(?f::'p::type ⇒ ?'b::type) `# (P'::'p::type multiset) ⊆# ?f `# ({#q::'p::type#} + (P::'p::type multiset))›*) have "?f `# P' ⊆# {#[entry fg q]#} + ?f `# P" by auto also (*calculation: ‹{#[entry fg p]. p ∈# P'#} ⊆# {#[entry fg q]#} + {#[entry fg p]. p ∈# P#}›*) from mset_subset_eq_mono_add[OF _ IHAPP ( 3 )] (*‹?A ⊆# ?B ⟹ ?A + {#[entry fg p]. p ∈# P#} ⊆# ?B + c'›*) have "… ⊆# {#[entry fg q]#} + c'" by (auto intro: IHAPP( (*‹{#[entry fg p]. p ∈# P#} ⊆# c'›*) 3)) finally (*calculation: ‹{#[entry fg p]. p::'p ∈# P'::'p multiset#} ⊆# {#[entry fg (q::'p)]#} + (c'::'n list multiset)›*) show "?thesis" (*goal: ‹{#[entry fg p]. p ∈# P'#} ⊆# {#[entry fg q]#} + c'›*) . qed moreover note S_spawn(5) (*‹size P' ≤ k›*) ultimately show "?case" (*goal: ‹∃(p::'p::type) (c'::'n::type list multiset) w::('p::type, 'ba::type) label list. (([entry fg p], {#}), w, [v::'n::type], c') ∈ trcl (trss fg) ∧ size (P'::'p::type multiset) ≤ (k::nat) ∧ {#[entry fg p]. p::'p::type ∈# P'#} ⊆# c' ∧ (M::'m::type set) = mon_w fg w›*) by auto qed<close> theorem (in flowgraph) S_sound_precise: "(v,M,P)∈S_cs fg k ⟷ (∃p c' w. (([entry fg p],{#}),w,([v],c'))∈trcl (trss fg) ∧ size P≤k ∧ (λp. [entry fg p]) `# P ⊆# c' ∧ M=mon_w fg w)" using S_sound (*‹⟦(([entry fg ?p], {#}), ?w, [?v], ?c') ∈ trcl (trss fg); size ?P ≤ ?k; {#[entry fg p]. p ∈# ?P#} ⊆# ?c'⟧ ⟹ (?v, mon_w fg ?w, ?P) ∈ S_cs fg ?k›*) S_precise (*‹(?v, ?M, ?P) ∈ S_cs fg ?k ⟹ ∃p c' w. (([entry fg p], {#}), w, [?v], c') ∈ trcl (trss fg) ∧ size ?P ≤ ?k ∧ {#[entry fg p]. p ∈# ?P#} ⊆# c' ∧ ?M = mon_w fg w›*) by blast text ‹Next, we present specialized soundness and precision lemmas, that reason over a macrostep (@{term "ntrp fg"}) rather than a same-level path (@{term "trcl (trss fg)"}). They are tailored for the use in the soundness and precision proofs of the other constraint systems. › lemma (in flowgraph) S_sound_ntrp: assumes A: "(([u],{#}),eel,(sh,ch))∈ntrp fg" and CASE: "!!p u' v w. ⟦ eel=LOC (LCall p#w); (u,Call p,u')∈edges fg; sh=[v,u']; proc_of fg v = p; mon_c fg ch = {}; !!s. s ∈# ch ⟹ ∃p u v. s=[entry fg p] ∧ (u,Spawn p,v)∈edges fg ∧ initialproc fg p; !!P. (λp. [entry fg p]) `# P ⊆# ch ⟹ (v,mon_w fg w,P)∈S_cs fg (size P) ⟧ ⟹ Q" shows Q proof (-) (*goal: ‹Q::bool›*) from A (*‹(([u], {#}), eel, sh, ch) ∈ ntrp fg›*) obtain ee where EE: "eel=LOC ee" "(([u],{#}),ee,(sh,ch))∈ntrs fg" (*goal: ‹(⋀ee. ⟦eel = LOC ee; (([u], {#}), ee, sh, ch) ∈ ntrs fg⟧ ⟹ thesis) ⟹ thesis›*) by (auto elim: gtrp.cases (*‹⟦((?a1.0, ?a2.0), ?a3.0, ?a4.0, ?a5.0) ∈ gtrp ?S; ⋀s c e s' c'. ⟦?a1.0 = s; ?a2.0 = c; ?a3.0 = LOC e; ?a4.0 = s'; ?a5.0 = c'; ((s, c), e, s', c') ∈ ?S⟧ ⟹ ?P; ⋀s sl c e s' c'. ⟦?a1.0 = sl; ?a2.0 = add_mset s c; ?a3.0 = ENV e; ?a4.0 = sl; ?a5.0 = add_mset s' c'; ((s, add_mset sl c), e, s', add_mset sl c') ∈ ?S⟧ ⟹ ?P⟧ ⟹ ?P›*)) have CHFMT: "!!s. s ∈# ch ⟹ ∃p u v. s=[entry fg p] ∧ (u,Spawn p,v)∈edges fg ∧ initialproc fg p" by (auto intro: ntrs_c_cases_s[OF EE(2)] (*‹(⋀csp. ⟦ch = csp + {#}; ⋀s. s ∈# csp ⟹ ∃p u v. s = [entry fg p] ∧ (u, Spawn p, v) ∈ edges fg ∧ initialproc fg p⟧ ⟹ ?P) ⟹ ?P›*)) with c_of_initial_no_mon (*‹(⋀s. s ∈# ?csp ⟹ ∃p. s = [entry fg p] ∧ initialproc fg p) ⟹ mon_c fg ?csp = {}›*) have CHNOMON: "mon_c fg ch = {}" by blast from EE(2) (*‹(([u::'n], {#}), ee::('p, 'ba) label list, sh::'n list, ch::'n list multiset) ∈ ntrs fg›*) obtain p and u' and v and w where FIRSTSPLIT: "ee=LCall p#w" "(([u],{#}),LCall p,([entry fg p,u'],{#}))∈trss fg" "sh=[v,u']" "(([entry fg p],{#}),w,([v],ch))∈trcl (trss fg)" (*goal: ‹(⋀(p::'p) (w::('p, 'ba) label list) (u'::'n) v::'n. ⟦(ee::('p, 'ba) label list) = LCall p # w; (([u::'n], {#}), LCall p, [entry fg p, u'], {#}) ∈ trss fg; (sh::'n list) = [v, u']; (([entry fg p], {#}), w, [v], ch::'n list multiset) ∈ trcl (trss fg)⟧ ⟹ thesis::bool) ⟹ thesis›*) by (auto elim!: ntrs.cases[simplified] (*‹⟦((?a1.0, ?a2.0), ?a3.0, ?a4.0, ?a5.0) ∈ ntrs ?fg; ⋀u r ce p u' w v ce'. ⟦?a1.0 = u # r; ?a2.0 = ce; ?a3.0 = LCall p # w; ?a4.0 = v # u' # r; ?a5.0 = ce'; ((u # r, ce), LCall p, entry ?fg p # u' # r, ce) ∈ trss ?fg; (([entry ?fg p], ce), w, [v], ce') ∈ trcl (trss ?fg)⟧ ⟹ ?P⟧ ⟹ ?P›*)) from FIRSTSPLIT (*‹ee = LCall p # w› ‹(([u], {#}), LCall p, [entry fg p, u'], {#}) ∈ trss fg› ‹sh = [v, u']› ‹(([entry fg p], {#}), w, [v], ch) ∈ trcl (trss fg)›*) have EDGE: "(u,Call p,u')∈edges fg" by (auto elim!: trss.cases (*‹⟦((?a1.0, ?a2.0), ?a3.0, ?a4.0, ?a5.0) ∈ trss ?fg; ⋀u a v r c. ⟦?a1.0 = u # r; ?a2.0 = c; ?a3.0 = LBase a; ?a4.0 = v # r; ?a5.0 = c; (u, Base a, v) ∈ edges ?fg⟧ ⟹ ?P; ⋀u p v c r. ⟦?a1.0 = u # r; ?a2.0 = c; ?a3.0 = LCall p; ?a4.0 = entry ?fg p # v # r; ?a5.0 = c; (u, Call p, v) ∈ edges ?fg; mon ?fg p ∩ mon_c ?fg c = {}⟧ ⟹ ?P; ⋀p r c. ⟦?a1.0 = return ?fg p # r; ?a2.0 = c; ?a3.0 = LRet; ?a4.0 = r; ?a5.0 = c⟧ ⟹ ?P; ⋀u p v r c. ⟦?a1.0 = u # r; ?a2.0 = c; ?a3.0 = LSpawn p; ?a4.0 = v # r; ?a5.0 = add_mset [entry ?fg p] c; (u, Spawn p, v) ∈ edges ?fg⟧ ⟹ ?P⟧ ⟹ ?P›*)) from trss_bot_proc_const[where s = "[]" and s' = "[]", simplified, OF FIRSTSPLIT ( 4 )] (*‹proc_of fg (entry fg p) = proc_of fg v›*) have PROC_OF_V: "proc_of fg v = p" by simp have "!!P. (λp. [entry fg p]) `# P ⊆# ch ⟹ (v,mon_w fg w,P)∈S_cs fg (size P)" proof (-) (*goal: ‹⋀P. {#[entry fg p]. p ∈# P#} ⊆# ch ⟹ (v, mon_w fg w, P) ∈ S_cs fg (size P)›*) fix P assume "(λp. [entry fg p]) `# P ⊆# ch" (*‹{#[entry fg p]. p::'p ∈# P::'p multiset#} ⊆# (ch::'n list multiset)›*) from S_sound[OF FIRSTSPLIT ( 4 ) _ this, of "size P"] (*‹size P ≤ size P ⟹ (v, mon_w fg w, P) ∈ S_cs fg (size P)›*) show "?thesis P" (*goal: ‹(v::'n, mon_w fg (w::('p, 'ba) label list), P::'p multiset) ∈ S_cs fg (size P)›*) by simp qed with EE(1) (*‹(eel::('p, 'ba) label list el_step) = LOC (ee::('p, 'ba) label list)›*) FIRSTSPLIT(1,3) (*‹ee = LCall p # w› ‹sh = [v, u']›*) EDGE (*‹(u::'n::type, Call (p::'p::type), u'::'n::type) ∈ edges fg›*) PROC_OF_V (*‹proc_of fg v = p›*) CHNOMON (*‹mon_c fg ch = {}›*) CHFMT (*‹(?s::'n::type list) ∈# (ch::'n::type list multiset) ⟹ ∃(p::'p::type) (u::'n::type) v::'n::type. ?s = [entry fg p] ∧ (u, Spawn p, v) ∈ edges fg ∧ initialproc fg p›*) show Q apply (rule_tac CASE (*‹⟦eel = LOC (LCall ?p # ?w); (u, Call ?p, ?u') ∈ edges fg; sh = [?v, ?u']; proc_of fg ?v = ?p; mon_c fg ch = {}; ⋀s. s ∈# ch ⟹ ∃p u v. s = [entry fg p] ∧ (u, Spawn p, v) ∈ edges fg ∧ initialproc fg p; ⋀P. {#[entry fg p]. p ∈# P#} ⊆# ch ⟹ (?v, mon_w fg ?w, P) ∈ S_cs fg (size P)⟧ ⟹ Q›*)) (*goals: 1. ‹⟦eel = LOC ee; ee = LCall p # w; sh = [v, u']; (u, Call p, u') ∈ edges fg; proc_of fg v = p; mon_c fg ch = {}; ⋀s. s ∈# ch ⟹ ∃p u v. s = [entry fg p] ∧ (u, Spawn p, v) ∈ edges fg ∧ initialproc fg p; ⋀P. {#[entry fg p]. p ∈# P#} ⊆# ch ⟹ (v, mon_w fg w, P) ∈ S_cs fg (size P)⟧ ⟹ eel = LOC (LCall ?p10 # ?w10)› 2. ‹⟦eel = LOC ee; ee = LCall p # w; sh = [v, u']; (u, Call p, u') ∈ edges fg; proc_of fg v = p; mon_c fg ch = {}; ⋀s. s ∈# ch ⟹ ∃p u v. s = [entry fg p] ∧ (u, Spawn p, v) ∈ edges fg ∧ initialproc fg p; ⋀P. {#[entry fg p]. p ∈# P#} ⊆# ch ⟹ (v, mon_w fg w, P) ∈ S_cs fg (size P)⟧ ⟹ (u, Call ?p10, ?u'10) ∈ edges fg› 3. ‹⟦eel = LOC ee; ee = LCall p # w; sh = [v, u']; (u, Call p, u') ∈ edges fg; proc_of fg v = p; mon_c fg ch = {}; ⋀s. s ∈# ch ⟹ ∃p u v. s = [entry fg p] ∧ (u, Spawn p, v) ∈ edges fg ∧ initialproc fg p; ⋀P. {#[entry fg p]. p ∈# P#} ⊆# ch ⟹ (v, mon_w fg w, P) ∈ S_cs fg (size P)⟧ ⟹ sh = [?v10, ?u'10]› 4. ‹⟦eel = LOC ee; ee = LCall p # w; sh = [v, u']; (u, Call p, u') ∈ edges fg; proc_of fg v = p; mon_c fg ch = {}; ⋀s. s ∈# ch ⟹ ∃p u v. s = [entry fg p] ∧ (u, Spawn p, v) ∈ edges fg ∧ initialproc fg p; ⋀P. {#[entry fg p]. p ∈# P#} ⊆# ch ⟹ (v, mon_w fg w, P) ∈ S_cs fg (size P)⟧ ⟹ proc_of fg ?v10 = ?p10› 5. ‹⟦eel = LOC ee; ee = LCall p # w; sh = [v, u']; (u, Call p, u') ∈ edges fg; proc_of fg v = p; mon_c fg ch = {}; ⋀s. s ∈# ch ⟹ ∃p u v. s = [entry fg p] ∧ (u, Spawn p, v) ∈ edges fg ∧ initialproc fg p; ⋀P. {#[entry fg p]. p ∈# P#} ⊆# ch ⟹ (v, mon_w fg w, P) ∈ S_cs fg (size P)⟧ ⟹ mon_c fg ch = {}› 6. ‹⋀s. ⟦eel = LOC ee; ee = LCall p # w; sh = [v, u']; (u, Call p, u') ∈ edges fg; proc_of fg v = p; mon_c fg ch = {}; ⋀s. s ∈# ch ⟹ ∃p u v. s = [entry fg p] ∧ (u, Spawn p, v) ∈ edges fg ∧ initialproc fg p; ⋀P. {#[entry fg p]. p ∈# P#} ⊆# ch ⟹ (v, mon_w fg w, P) ∈ S_cs fg (size P); s ∈# ch⟧ ⟹ ∃p u v. s = [entry fg p] ∧ (u, Spawn p, v) ∈ edges fg ∧ initialproc fg p› 7. ‹⋀P. ⟦eel = LOC ee; ee = LCall p # w; sh = [v, u']; (u, Call p, u') ∈ edges fg; proc_of fg v = p; mon_c fg ch = {}; ⋀s. s ∈# ch ⟹ ∃p u v. s = [entry fg p] ∧ (u, Spawn p, v) ∈ edges fg ∧ initialproc fg p; ⋀P. {#[entry fg p]. p ∈# P#} ⊆# ch ⟹ (v, mon_w fg w, P) ∈ S_cs fg (size P); {#[entry fg p]. p ∈# P#} ⊆# ch⟧ ⟹ (?v10, mon_w fg ?w10, P) ∈ S_cs fg (size P)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*proven 7 subgoals*) . qed lemma (in flowgraph) S_precise_ntrp: assumes ENTRY: "(v,M,P)∈S_cs fg k" and P: "proc_of fg v = p" and EDGE: "(u,Call p,u')∈edges fg" shows "∃w ch. (([u],{#}),LOC (LCall p#w),([v,u'],ch))∈ntrp fg ∧ size P ≤ k ∧ M=mon_w fg w ∧ mon_n fg v = mon fg p ∧ (λp. [entry fg p]) `# P ⊆# ch ∧ mon_c fg ch={}" proof (-) (*goal: ‹∃w ch. (([u], {#}), LOC (LCall p # w), [v, u'], ch) ∈ ntrp fg ∧ size P ≤ k ∧ M = mon_w fg w ∧ mon_n fg v = mon fg p ∧ {#[entry fg p]. p ∈# P#} ⊆# ch ∧ mon_c fg ch = {}›*) from P (*‹proc_of fg v = p›*) S_precise[OF ENTRY, simplified] (*‹∃p c' w. (([entry fg p], {#}), w, [v], c') ∈ trcl (trss fg) ∧ size P ≤ k ∧ {#[entry fg p]. p ∈# P#} ⊆# c' ∧ M = mon_w fg w›*) trss_bot_proc_const[where s = "[]" and s' = "[]", simplified] (*‹(([?u], ?c), ?w, [?u'], ?c') ∈ trcl (trss fg) ⟹ proc_of fg ?u = proc_of fg ?u'›*) obtain wsl and ch where SLPATH: "(([entry fg p], {#}), wsl, [v], ch) ∈ trcl (trss fg)" "size P ≤ k" "(λp. [entry fg p]) `# P ⊆# ch" "M = mon_w fg wsl" (*goal: ‹(⋀(wsl::('p, 'ba) label list) ch::'n list multiset. ⟦(([entry fg (p::'p)], {#}), wsl, [v::'n], ch) ∈ trcl (trss fg); size (P::'p multiset) ≤ (k::nat); {#[entry fg p]. p::'p ∈# P#} ⊆# ch; (M::'m set) = mon_w fg wsl⟧ ⟹ thesis::bool) ⟹ thesis›*) by fastforce from mon_n_same_proc[OF trss_bot_proc_const [ where s = "[]" and s' = "[]" , simplified , OF SLPATH ( 1 ) ]] (*‹mon_n fg (entry fg p) = mon_n fg v›*) have MON_V: "mon_n fg v = mon fg p" by simp from trss_c_cases[OF SLPATH ( 1 ), simplified] (*‹((⋀s. s ∈# ch ⟹ ∃p. s = [entry fg p] ∧ (∃u v. (u, Spawn p, v) ∈ edges fg) ∧ initialproc fg p) ⟹ ?P) ⟹ ?P›*) have CHFMT: "⋀s. s ∈# ch ⟹ ∃p. s = [entry fg p] ∧ (∃u v. (u, Spawn p, v) ∈ edges fg) ∧ initialproc fg p" by blast with c_of_initial_no_mon (*‹(⋀s. s ∈# ?csp ⟹ ∃p. s = [entry fg p] ∧ initialproc fg p) ⟹ mon_c fg ?csp = {}›*) have CHNOMON: "mon_c fg ch = {}" by blast have FS: "(([u],{#}),LCall p#wsl,([v,u'],ch))∈ntrs fg" proof (rule ntrs_step[where r="[]", simplified] (*‹⟦(([?u], ?ce), LCall ?p, [entry ?fg ?p, ?u'], ?ce) ∈ trss ?fg; (([entry ?fg ?p], ?ce), ?w, [?v], ?ce') ∈ trcl (trss ?fg)⟧ ⟹ (([?u], ?ce), LCall ?p # ?w, [?v, ?u'], ?ce') ∈ ntrs ?fg›*)) (*goals: 1. ‹(([u], {#}), LCall p, [entry fg p, u'], {#}) ∈ trss fg› 2. ‹(([entry fg p], {#}), wsl, [v], ch) ∈ trcl (trss fg)›*) from EDGE (*‹(u, Call p, u') ∈ edges fg›*) show "(([u], {#}), LCall p, [entry fg p, u'], {#}) ∈ trss fg" by (auto intro: trss_call (*‹⟦(?u, Call ?p, ?v) ∈ edges ?fg; mon ?fg ?p ∩ mon_c ?fg ?c = {}⟧ ⟹ ((?u # ?r, ?c), LCall ?p, entry ?fg ?p # ?v # ?r, ?c) ∈ trss ?fg›*)) qed (rule SLPATH( (*‹(([entry fg p], {#}), wsl, [v], ch) ∈ trcl (trss fg)›*) 1)) (*solved the remaining goal: ‹(([entry fg p], {#}), wsl, [v], ch) ∈ trcl (trss fg)›*) hence FSP: "(([u],{#}),LOC (LCall p#wsl),([v,u'],ch))∈ntrp fg" by (blast intro: gtrp_loc (*‹((?s, ?c), ?e, ?s', ?c') ∈ ?S ⟹ ((?s, ?c), LOC ?e, ?s', ?c') ∈ gtrp ?S›*)) from FSP (*‹(([u], {#}), LOC (LCall p # wsl), [v, u'], ch) ∈ ntrp fg›*) SLPATH(2,3,4) (*‹size P ≤ k› ‹{#[entry fg p]. p::'p::type ∈# P::'p::type multiset#} ⊆# (ch::'n::type list multiset)› ‹M = mon_w fg wsl›*) CHNOMON (*‹mon_c fg (ch::'n list multiset) = {}›*) MON_V (*‹mon_n fg v = mon fg p›*) show "?thesis" (*goal: ‹∃w ch. (([u], {#}), LOC (LCall p # w), [v, u'], ch) ∈ ntrp fg ∧ size P ≤ k ∧ M = mon_w fg w ∧ mon_n fg v = mon fg p ∧ {#[entry fg p]. p ∈# P#} ⊆# ch ∧ mon_c fg ch = {}›*) by blast qed subsection "Single reaching path" text ‹ In this section we define a constraint system that collects abstract information of paths reaching a control node at @{term U}. The path starts with a single initial thread. The collected information are the monitors used by the steps of the initial thread, the monitors used by steps of other threads and the acquisition history of the path. To distinguish the steps of the initial thread from steps of other threads, we use the loc/env-semantics (cf. Section~\ref{sec:ThreadTracking:exp_local}). › subsubsection "Constraint system" text ‹ An element @{term "(u,Ml,Me,h)∈RU_cs fg U"} corresponds to a path from @{term "{#[u]#}"} to some configuration at @{term U}, that uses monitors from @{term Ml} in the steps of the initial thread, monitors from @{term Me} in the steps of other threads and has acquisition history @{term h}. Here, the correspondence between paths and entries included into the inductively defined set is not perfect but strong enough for our purposes: While each constraint system entry corresponds to a path, not each path corresponds to a constraint system entry. But for each path reaching a configuration at @{term U}, we find an entry with less or equal monitors and an acquisition history less or equal to the acquisition history of the path. › inductive_set RU_cs :: "('n,'p,'ba,'m,'more) flowgraph_rec_scheme ⇒ 'n set ⇒ ('n × 'm set × 'm set × ('m ⇒ 'm set)) set" for fg U where RU_init: "u∈U ⟹ (u,{},{},λx.{})∈RU_cs fg U" | RU_call: "⟦ (u,Call p,u')∈edges fg; proc_of fg v = p; (v,M,P)∈S_cs fg 0; (v,Ml,Me,h)∈RU_cs fg U; mon_n fg u ∩ Me = {} ⟧ ⟹ ( u, mon fg p ∪ M ∪ Ml, Me, ah_update h (mon fg p,M) (Ml∪Me)) ∈ RU_cs fg U" | RU_spawn: "⟦ (u,Call p,u')∈edges fg; proc_of fg v = p; (v,M,P)∈S_cs fg 1; q ∈# P; (entry fg q,Ml,Me,h)∈RU_cs fg U; (mon_n fg u ∪ mon fg p) ∩ (Ml ∪ Me)={} ⟧ ⟹ (u,mon fg p ∪ M, Ml ∪ Me, ah_update h (mon fg p,M) (Ml∪Me)) ∈ RU_cs fg U" text ‹ The constraint system works by tracking only a single thread. Initially, there is just one thread, and from this thread we reach a configuration at @{term U}. After a macrostep, we have the transformed initial thread and some spawned threads. The key idea is, that the actual node @{term U} is reached by just one of these threads. The steps of the other threads are useless for reaching @{term U}. Because of the nice properties of normalized paths, we can simply prune those steps from the path. The @{thm [source] RU_init}-constraint reflects that we can reach a control node from itself with the empty path. The @{thm [source] RU_call}-constraint describes the case that @{term U} is reached from the initial thread, and the @{thm [source] RU_spawn}-constraint describes the case that @{term U} is reached from one of the spawned threads. In the two latter cases, we have to check whether prepending the macrostep to the reaching path is allowed or not due to monitor restrictions. In the call case, the procedure of the initial node must not own monitors that are used in the environment steps of the appended reaching path (‹mon_n fg u ∩ Me = {}›). As we only test disjointness with the set of monitors used by the environment, reentrant monitors can be handled. In the spawn case, we have to check disjointness with both, the monitors of local and environment steps of the reaching path from the spawned thread, because from the perspective of the initial thread, all these steps are environment steps (‹(mon_n fg u ∪ mon fg p) ∩ (Ml ∪ Me)={}›). Note that in the call case, we do not need to explicitly check that the monitors used by the environment are disjoint from the monitors acquired by the called procedure because this already follows from the existence of a reaching path, as the starting point of this path already holds all these monitors. However, in the spawn case, we have to check for both the monitors of the start node and of the called procedure to be compatible with the already known reaching path from the entry node of the spawned thread. › subsubsection "Soundness and precision" text ‹The following lemma intuitively states: {\em If we can reach a configuration that is at @{term U} from some start configuration, then there is a single thread in the start configuration that can reach a configuration at @{term U} with a subword of the original path}. The proof follows from Lemma @{thm [source] flowgraph.ntr_reverse_split} rather directly. › lemma (in flowgraph) ntr_reverse_split_atU: assumes V: "valid fg c" and A: "atU U c'" and B: "(c,w,c')∈trcl (ntr fg)" shows "∃s w' c1'. s ∈# c ∧ w'≼w ∧ c1' ⊆# c' ∧ atU U c1' ∧ ({#s#},w',c1')∈trcl (ntr fg)" proof (-) (*goal: ‹∃s w' c1'. s ∈# c ∧ w' ≼ w ∧ c1' ⊆# c' ∧ atU U c1' ∧ ({#s#}, w', c1') ∈ trcl (ntr fg)›*) obtain ui and r and ce' where C'FMT: "c'={#ui#r#}+ce'" "ui∈U" (*goal: ‹(⋀ui r ce'. ⟦c' = {#ui # r#} + ce'; ui ∈ U⟧ ⟹ thesis) ⟹ thesis›*) apply (rule atU_fmt[OF A] (*‹(⋀ui r. ⟦ui # r ∈# c'; ui ∈ U⟧ ⟹ ?P) ⟹ ?P›*)) (*goal: ‹(⋀ui r ce'. ⟦c' = {#ui # r#} + ce'; ui ∈ U⟧ ⟹ thesis) ⟹ thesis›*) apply (simp only: mset_contains_eq (*‹(?m ∈# ?M) = ({#?m#} + (?M - {#?m#}) = ?M)›*)) (*goal: ‹⋀ui r. ⟦⋀ui r ce'. ⟦c' = {#ui # r#} + ce'; ui ∈ U⟧ ⟹ thesis; ui # r ∈# c'; ui ∈ U⟧ ⟹ thesis›*) by (blast dest: sym (*‹?s = ?t ⟹ ?t = ?s›*)) with ntr_reverse_split[OF _ V] (*‹(c, ?w, {#?s'#} + ?ce') ∈ trcl (ntr fg) ⟹ ∃s ce w1 w2 ce1' ce2'. c = {#s#} + ce ∧ ?ce' = ce1' + ce2' ∧ ?w ∈ w1 ⊗⇘αn fg⇙ w2 ∧ mon_s fg s ∩ (mon_c fg ce ∪ mon_ww fg w2) = {} ∧ mon_c fg ce ∩ (mon_s fg s ∪ mon_ww fg w1) = {} ∧ ({#s#}, w1, {#?s'#} + ce1') ∈ trcl (ntr fg) ∧ (ce, w2, ce2') ∈ trcl (ntr fg)›*) B (*‹(c::'n::type list multiset, w::('p::type, 'ba::type) label list list, c'::'n::type list multiset) ∈ trcl (ntr fg)›*) obtain s and ce and w1 and w2 and ce1' and ce2' where RSPLIT: "c={#s#}+ce" "ce'=ce1'+ce2'" "w∈w1⊗⇘αn fg⇙w2" "({#s#}, w1, {#ui#r#} + ce1') ∈ trcl (ntr fg)" (*goal: ‹(⋀s ce ce1' ce2' w1 w2. ⟦c = {#s#} + ce; ce' = ce1' + ce2'; w ∈ w1 ⊗⇘αn fg⇙ w2; ({#s#}, w1, {#ui # r#} + ce1') ∈ trcl (ntr fg)⟧ ⟹ thesis) ⟹ thesis›*) by blast with C'FMT (*‹c' = {#ui # r#} + ce'› ‹ui ∈ U›*) have "s ∈# c" "w1≼w" "{#ui#r#}+ce1' ⊆# c'" "atU U ({#ui#r#}+ce1')" apply - (*goals: 1. ‹⟦(c'::'n list multiset) = {#(ui::'n) # (r::'n list)#} + (ce'::'n list multiset); ui ∈ (U::'n set); (c::'n list multiset) = {#s::'n list#} + (ce::'n list multiset); ce' = (ce1'::'n list multiset) + (ce2'::'n list multiset); (w::('p, 'ba) label list list) ∈ (w1::('p, 'ba) label list list) ⊗⇘αn fg⇙ (w2::('p, 'ba) label list list); ({#s#}, w1, {#ui # r#} + ce1') ∈ trcl (ntr fg)⟧ ⟹ s ∈# c› 2. ‹⟦(c'::'n list multiset) = {#(ui::'n) # (r::'n list)#} + (ce'::'n list multiset); ui ∈ (U::'n set); (c::'n list multiset) = {#s::'n list#} + (ce::'n list multiset); ce' = (ce1'::'n list multiset) + (ce2'::'n list multiset); (w::('p, 'ba) label list list) ∈ (w1::('p, 'ba) label list list) ⊗⇘αn fg⇙ (w2::('p, 'ba) label list list); ({#s#}, w1, {#ui # r#} + ce1') ∈ trcl (ntr fg)⟧ ⟹ w1 ≼ w› 3. ‹⟦(c'::'n list multiset) = {#(ui::'n) # (r::'n list)#} + (ce'::'n list multiset); ui ∈ (U::'n set); (c::'n list multiset) = {#s::'n list#} + (ce::'n list multiset); ce' = (ce1'::'n list multiset) + (ce2'::'n list multiset); (w::('p, 'ba) label list list) ∈ (w1::('p, 'ba) label list list) ⊗⇘αn fg⇙ (w2::('p, 'ba) label list list); ({#s#}, w1, {#ui # r#} + ce1') ∈ trcl (ntr fg)⟧ ⟹ {#ui # r#} + ce1' ⊆# c'› 4. ‹⟦(c'::'n list multiset) = {#(ui::'n) # (r::'n list)#} + (ce'::'n list multiset); ui ∈ (U::'n set); (c::'n list multiset) = {#s::'n list#} + (ce::'n list multiset); ce' = (ce1'::'n list multiset) + (ce2'::'n list multiset); (w::('p, 'ba) label list list) ∈ (w1::('p, 'ba) label list list) ⊗⇘αn fg⇙ (w2::('p, 'ba) label list list); ({#s#}, w1, {#ui # r#} + ce1') ∈ trcl (ntr fg)⟧ ⟹ atU U ({#ui # r#} + ce1')› discuss goal 1*) apply ((auto dest: cil_ileq (*‹?w ∈ ?w1.0 ⊗⇘?α⇙ ?w2.0 ⟹ ?w1.0 ≼ ?w ∧ ?w2.0 ≼ ?w›*))[1]) (*discuss goal 2*) apply ((auto dest: cil_ileq (*‹?w ∈ ?w1.0 ⊗⇘?α⇙ ?w2.0 ⟹ ?w1.0 ≼ ?w ∧ ?w2.0 ≼ ?w›*))[1]) (*discuss goal 3*) apply ((auto dest: cil_ileq (*‹?w ∈ ?w1.0 ⊗⇘?α⇙ ?w2.0 ⟹ ?w1.0 ≼ ?w ∧ ?w2.0 ≼ ?w›*))[1]) (*discuss goal 4*) apply ((auto dest: cil_ileq (*‹?w ∈ ?w1.0 ⊗⇘?α⇙ ?w2.0 ⟹ ?w1.0 ≼ ?w ∧ ?w2.0 ≼ ?w›*))[1]) (*proven 4 subgoals*) . with RSPLIT(4) (*‹({#s#}, w1, {#ui # r#} + ce1') ∈ trcl (ntr fg)›*) show "?thesis" (*goal: ‹∃s w' c1'. s ∈# c ∧ w' ≼ w ∧ c1' ⊆# c' ∧ atU U c1' ∧ ({#s#}, w', c1') ∈ trcl (ntr fg)›*) by blast qed text ‹ The next lemma shows the soundness of the RU constraint system. The proof works by induction over the length of the reaching path. For the empty path, the proposition follows by the @{thm [source] RU_init}-constraint. For a non-empty path, we consider the first step. It has transformed the initial thread and may have spawned some other threads. From the resulting configuration, @{term U} is reached. Due to @{thm [source] "flowgraph.ntr_split"} we get two interleavable paths from the rest of the original path, one from the transformed initial thread and one from the spawned threads. We then distinguish two cases: if the first path reaches ‹U›, the proposition follows by the induction hypothesis and the @{thm [source] RU_call} constraint. Otherwise, we use @{thm [source] "flowgraph.ntr_reverse_split_atU"} to identify the thread that actually reaches @{term U} among all the spawned threads. Then we apply the induction hypothesis to the path of that thread and prepend the first step using the @{thm [source] RU_spawn}-constraint. The main complexity of the proof script below results from fiddling with the monitors and converting between the multiset-and loc/env-semantics. Also the arguments to show that the acquisition histories are sound approximations require some space. › lemma (in flowgraph) RU_sound: "!!u s' c'. ⟦(([u],{#}),w,(s',c'))∈trcl (ntrp fg); atU U (add_mset s' c')⟧ ⟹ ∃Ml Me h. (u,Ml,Me,h)∈RU_cs fg U ∧ Ml ⊆ mon_loc fg w ∧ Me ⊆ mon_env fg w ∧ h ≤ αah (map (αnl fg) w)" ― ‹The proof works by induction over the length of the reaching path› proof (induct w rule: length_compl_induct (*‹⟦?P []; ⋀e l. (⋀ll. length ll ≤ length l ⟹ ?P ll) ⟹ ?P (e # l)⟧ ⟹ ?P ?l›*)) (*goals: 1. ‹⋀u s' c'. ⟦(([u], {#}), [], s', c') ∈ trcl (ntrp fg); atU U (add_mset s' c')⟧ ⟹ ∃Ml Me h. (u, Ml, Me, h) ∈ RU_cs fg U ∧ Ml ⊆ mon_loc fg [] ∧ Me ⊆ mon_env fg [] ∧ h ≤ αah (map (αnl fg) [])› 2. ‹⋀e l u s' c'. ⟦⋀ll u s' c'. ⟦length ll ≤ length l; (([u], {#}), ll, s', c') ∈ trcl (ntrp fg); atU U (add_mset s' c')⟧ ⟹ ∃Ml Me h. (u, Ml, Me, h) ∈ RU_cs fg U ∧ Ml ⊆ mon_loc fg ll ∧ Me ⊆ mon_env fg ll ∧ h ≤ αah (map (αnl fg) ll); (([u], {#}), e # l, s', c') ∈ trcl (ntrp fg); atU U (add_mset s' c')⟧ ⟹ ∃Ml Me h. (u, Ml, Me, h) ∈ RU_cs fg U ∧ Ml ⊆ mon_loc fg (e # l) ∧ Me ⊆ mon_env fg (e # l) ∧ h ≤ αah (map (αnl fg) (e # l))›*) case Nil (*‹(([u], {#}), [], s', c') ∈ trcl (ntrp fg)› ‹atU U (add_mset s' c')›*) thus "?case" (*goal: ‹∃Ml Me h. (u, Ml, Me, h) ∈ RU_cs fg U ∧ Ml ⊆ mon_loc fg [] ∧ Me ⊆ mon_env fg [] ∧ h ≤ αah (map (αnl fg) [])›*) apply auto (*goal: ‹∃Ml Me h. (u, Ml, Me, h) ∈ RU_cs fg U ∧ Ml ⊆ mon_loc fg [] ∧ Me ⊆ mon_env fg [] ∧ h ≤ αah (map (αnl fg) [])›*) by (auto intro!: RU_init (*‹?u ∈ ?U ⟹ (?u, {}, {}, λx. {}) ∈ RU_cs ?fg ?U›*)) next (*goal: ‹⋀e l u s' c'. ⟦⋀ll u s' c'. ⟦length ll ≤ length l; (([u], {#}), ll, s', c') ∈ trcl (ntrp fg); atU U (add_mset s' c')⟧ ⟹ ∃Ml Me h. (u, Ml, Me, h) ∈ RU_cs fg U ∧ Ml ⊆ mon_loc fg ll ∧ Me ⊆ mon_env fg ll ∧ h ≤ αah (map (αnl fg) ll); (([u], {#}), e # l, s', c') ∈ trcl (ntrp fg); atU U (add_mset s' c')⟧ ⟹ ∃Ml Me h. (u, Ml, Me, h) ∈ RU_cs fg U ∧ Ml ⊆ mon_loc fg (e # l) ∧ Me ⊆ mon_env fg (e # l) ∧ h ≤ αah (map (αnl fg) (e # l))›*) case (Cons eel wwl) (*‹⟦length ?ll ≤ length wwl; (([?u], {#}), ?ll, ?s', ?c') ∈ trcl (ntrp fg); atU U (add_mset ?s' ?c')⟧ ⟹ ∃Ml Me h. (?u, Ml, Me, h) ∈ RU_cs fg U ∧ Ml ⊆ mon_loc fg ?ll ∧ Me ⊆ mon_env fg ?ll ∧ h ≤ αah (map (αnl fg) ?ll)› ‹(([u], {#}), eel # wwl, s', c') ∈ trcl (ntrp fg)› ‹atU U (add_mset s' c')›*) then obtain sh and ch where SPLIT: "(([u],{#}),eel,(sh,ch))∈ntrp fg" "((sh,ch),wwl,(s',c'))∈trcl (ntrp fg)" (*goal: ‹(⋀(sh::'n list) ch::'n list multiset. ⟦(([u::'n], {#}), eel::('p, 'ba) label list el_step, sh, ch) ∈ ntrp fg; ((sh, ch), wwl::('p, 'ba) label list el_step list, s'::'n list, c'::'n list multiset) ∈ trcl (ntrp fg)⟧ ⟹ thesis::bool) ⟹ thesis›*) by (fast dest: trcl_uncons (*‹(?c, ?a # ?w, ?c') ∈ trcl ?t ⟹ ∃ch. (?c, ?a, ch) ∈ ?t ∧ (ch, ?w, ?c') ∈ trcl ?t›*)) obtain p and u' and v and w where FS_FMT: "eel = LOC (LCall p # w)" "(u, Call p, u') ∈ edges fg" "sh = [v, u']" "proc_of fg v = p" "mon_c fg ch = {}" and CHFMT: "⋀s. s ∈# ch ⟹ ∃p u v. s=[entry fg p] ∧ (u,Spawn p,v)∈edges fg ∧ initialproc fg p" and S_ENTRY_PAT: "⋀P. (λp. [entry fg p]) `# P ⊆# ch ⟹ (v, mon_w fg w, P) ∈ S_cs fg (size P)" (*goal: ‹(⋀(p::'p::type) (w::('p::type, 'ba::type) label list) (u'::'n::type) v::'n::type. ⟦(eel::('p::type, 'ba::type) label list el_step) = LOC (LCall p # w); (u::'n::type, Call p, u') ∈ edges fg; (sh::'n::type list) = [v, u']; proc_of fg v = p; mon_c fg (ch::'n::type list multiset) = {}; ⋀s::'n::type list. s ∈# ch ⟹ ∃(p::'p::type) (u::'n::type) v::'n::type. s = [entry fg p] ∧ (u, Spawn p, v) ∈ edges fg ∧ initialproc fg p; ⋀P::'p::type multiset. {#[entry fg p]. p::'p::type ∈# P#} ⊆# ch ⟹ (v, mon_w fg w, P) ∈ S_cs fg (size P)⟧ ⟹ thesis::bool) ⟹ thesis›*) apply (rule S_sound_ntrp[OF SPLIT(1)] (*‹(⋀p u' v w. ⟦eel = LOC (LCall p # w); (u, Call p, u') ∈ edges fg; sh = [v, u']; proc_of fg v = p; mon_c fg ch = {}; ⋀s. s ∈# ch ⟹ ∃p u v. s = [entry fg p] ∧ (u, Spawn p, v) ∈ edges fg ∧ initialproc fg p; ⋀P. {#[entry fg p]. p ∈# P#} ⊆# ch ⟹ (v, mon_w fg w, P) ∈ S_cs fg (size P)⟧ ⟹ ?Q) ⟹ ?Q›*)) (*goal: ‹(⋀p w u' v. ⟦eel = LOC (LCall p # w); (u, Call p, u') ∈ edges fg; sh = [v, u']; proc_of fg v = p; mon_c fg ch = {}; ⋀s. s ∈# ch ⟹ ∃p u v. s = [entry fg p] ∧ (u, Spawn p, v) ∈ edges fg ∧ initialproc fg p; ⋀P. {#[entry fg p]. p ∈# P#} ⊆# ch ⟹ (v, mon_w fg w, P) ∈ S_cs fg (size P)⟧ ⟹ thesis) ⟹ thesis›*) by blast from ntrp_valid_preserve_s[OF SPLIT ( 1 )] (*‹valid fg {#[u]#} ⟹ valid fg (add_mset sh ch)›*) have HVALID: "valid fg ({#sh#} + ch)" by simp from ntrp_split[where ?c1.0 = "{#}", simplified, OF SPLIT ( 2 ) ntrp_valid_preserve_s [ OF SPLIT ( 1 ) ], simplified] (*‹∃(w1::('p, 'ba) label list el_step list) w2::('p, 'ba) label list list. (wwl::('p, 'ba) label list el_step list) ∈ w1 ⊗⇘αnl fg⇙ map ENV w2 ∧ (∃(c1'::'n list multiset) c2'::'n list multiset. (c'::'n list multiset) = c1' + c2' ∧ ((sh::'n list, {#}), w1, s'::'n list, c1') ∈ trcl (ntrp fg) ∧ (ch::'n list multiset, w2, c2') ∈ trcl (ntr fg) ∧ mon_ww fg (map le_rem_s w1) ∩ mon_c fg ch = {} ∧ mon_ww fg w2 ∩ mon_s fg sh = {})›*) obtain w1 and w2 and c1' and c2' where LESPLIT: "wwl∈w1⊗⇘αnl fg⇙ map ENV w2" "c' = c1' + c2'" "((sh, {#}), w1, s', c1') ∈ trcl (ntrp fg)" "(ch, w2, c2') ∈ trcl (ntr fg)" "mon_ww fg (map le_rem_s w1) ∩ mon_c fg ch = {}" "mon_ww fg w2 ∩ mon_s fg sh = {}" (*goal: ‹(⋀w1 w2 c1' c2'. ⟦wwl ∈ w1 ⊗⇘αnl fg⇙ map ENV w2; c' = c1' + c2'; ((sh, {#}), w1, s', c1') ∈ trcl (ntrp fg); (ch, w2, c2') ∈ trcl (ntr fg); mon_ww fg (map le_rem_s w1) ∩ mon_c fg ch = {}; mon_ww fg w2 ∩ mon_s fg sh = {}⟧ ⟹ thesis) ⟹ thesis›*) by blast from Cons.prems(2) (*‹atU (U::'n set) (add_mset (s'::'n list) (c'::'n list multiset))›*) LESPLIT(2) (*‹c' = c1' + c2'›*) have "atU U (({#s'#}+c1') + c2')" by (auto simp add: union_ac (*‹?M + ?N + ?K = ?M + (?N + ?K)› ‹?M + ?N = ?N + ?M› ‹?M + (?N + ?K) = ?N + (?M + ?K)› ‹add_mset ?x (add_mset ?y ?M) = add_mset ?y (add_mset ?x ?M)›*)) thus "?case" (*goal: ‹∃Ml Me h. (u, Ml, Me, h) ∈ RU_cs fg U ∧ Ml ⊆ mon_loc fg (eel # wwl) ∧ Me ⊆ mon_env fg (eel # wwl) ∧ h ≤ αah (map (αnl fg) (eel # wwl))›*) proof (cases rule: atU_union_cases (*‹⟦atU ?U (?c1.0 + ?c2.0); atU ?U ?c1.0 ⟹ ?P; atU ?U ?c2.0 ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹atU U ({#s'#} + c1') ⟹ ∃Ml Me h. (u, Ml, Me, h) ∈ RU_cs fg U ∧ Ml ⊆ mon_loc fg (eel # wwl) ∧ Me ⊆ mon_env fg (eel # wwl) ∧ h ≤ αah (map (αnl fg) (eel # wwl))› 2. ‹atU U c2' ⟹ ∃Ml Me h. (u, Ml, Me, h) ∈ RU_cs fg U ∧ Ml ⊆ mon_loc fg (eel # wwl) ∧ Me ⊆ mon_env fg (eel # wwl) ∧ h ≤ αah (map (αnl fg) (eel # wwl))›*) case left (*‹atU (U::'n set) ({#s'::'n list#} + (c1'::'n list multiset))›*) from cil_ileq[OF LESPLIT ( 1 )] (*‹w1 ≼ wwl ∧ map ENV w2 ≼ wwl›*) have ILEQ: "w1≼wwl" and LEN: "length w1 ≤ length wwl" apply - (*goals: 1. ‹(w1::('p, 'ba) label list el_step list) ≼ (wwl::('p, 'ba) label list el_step list) ∧ map ENV (w2::('p, 'ba) label list list) ≼ wwl ⟹ w1 ≼ wwl› 2. ‹(w1::('p, 'ba) label list el_step list) ≼ (wwl::('p, 'ba) label list el_step list) ∧ map ENV (w2::('p, 'ba) label list list) ≼ wwl ⟹ length w1 ≤ length wwl› discuss goal 1*) apply ((auto simp add: le_list_length (*‹?xs ≼ ?ys ⟹ length ?xs ≤ length ?ys›*))[1]) (*discuss goal 2*) apply ((auto simp add: le_list_length (*‹(?xs::?'a list) ≼ (?ys::?'a list) ⟹ length ?xs ≤ length ?ys›*))[1]) (*proven 2 subgoals*) . from FS_FMT(3) (*‹(sh::'n list) = [v::'n, u'::'n]›*) LESPLIT(3) (*‹((sh, {#}), w1, s', c1') ∈ trcl (ntrp fg)›*) ntrp_stack_decomp[of v "[]" "[u']" "{#}" w1 s' c1' fg, simplified] (*‹⟦(([v, u'], {#}), w1, s', c1') ∈ trcl (ntrp fg); ⋀va rr. ⟦s' = va # rr @ [u']; (([v], {#}), w1, va # rr, c1') ∈ trcl (ntrp fg)⟧ ⟹ ?P⟧ ⟹ ?P›*) obtain v' and rr where DECOMP: "s'=v'#rr@[u']" "(([v],{#}),w1,(v'#rr,c1'))∈trcl (ntrp fg)" (*goal: ‹(⋀v' rr. ⟦s' = v' # rr @ [u']; (([v], {#}), w1, v' # rr, c1') ∈ trcl (ntrp fg)⟧ ⟹ thesis) ⟹ thesis›*) by auto from atU_xchange_stack (*‹atU ?U (add_mset (?u # ?r) ?c) ⟹ atU ?U (add_mset (?u # ?r') ?c)›*) left (*‹atU (U::'n::type set) ({#s'::'n::type list#} + (c1'::'n::type list multiset))›*) DECOMP(1) (*‹s' = v' # rr @ [u']›*) have ATU: "atU U (add_mset (v'#rr) c1')" by fastforce from Cons.hyps[OF LEN DECOMP ( 2 ) ATU] (*‹∃Ml Me h. (v, Ml, Me, h) ∈ RU_cs fg U ∧ Ml ⊆ mon_loc fg w1 ∧ Me ⊆ mon_env fg w1 ∧ h ≤ αah (map (αnl fg) w1)›*) obtain Ml and Me and h where IHAPP: "(v,Ml,Me,h)∈RU_cs fg U" "Ml ⊆ mon_loc fg w1" "Me ⊆ mon_env fg w1" "h ≤ αah (map (αnl fg) w1)" (*goal: ‹(⋀Ml Me h. ⟦(v, Ml, Me, h) ∈ RU_cs fg U; Ml ⊆ mon_loc fg w1; Me ⊆ mon_env fg w1; h ≤ αah (map (αnl fg) w1)⟧ ⟹ thesis) ⟹ thesis›*) by blast from S_ENTRY_PAT[of "{#}", simplified] (*‹(v::'n::type, mon_w fg (w::('p::type, 'ba::type) label list), {#}) ∈ S_cs fg (0::nat)›*) have S_ENTRY: "(v, mon_w fg w, {#}) ∈ S_cs fg 0" . have MON_U_ME: "mon_n fg u ∩ Me = {}" proof (-) (*goal: ‹mon_n fg u ∩ Me = {}›*) from ntrp_mon_env_w_no_ctx[OF Cons.prems ( 1 )] (*‹mon_env fg (eel # wwl) ∩ mon_s fg [u] = {}›*) have "mon_env fg wwl ∩ mon_n fg u = {}" by auto with mon_env_ileq[OF ILEQ] (*‹mon_env ?fg w1 ⊆ mon_env ?fg wwl›*) IHAPP(3) (*‹Me ⊆ mon_env fg w1›*) show "?thesis" (*goal: ‹mon_n fg u ∩ Me = {}›*) by fast qed from RU_call[OF FS_FMT ( 2 , 4 ) S_ENTRY IHAPP ( 1 ) MON_U_ME] (*‹(u, mon fg p ∪ mon_w fg w ∪ Ml, Me, ah_update h (mon fg p, mon_w fg w) (Ml ∪ Me)) ∈ RU_cs fg U›*) have "(u, mon fg p ∪ mon_w fg w ∪ Ml, Me, ah_update h (mon fg p, mon_w fg w) (Ml ∪ Me)) ∈ RU_cs fg U" . moreover have "mon fg p ∪ mon_w fg w ∪ Ml ⊆ mon_loc fg (eel#wwl)" using mon_loc_ileq[OF ILEQ] (*‹mon_loc ?fg w1 ⊆ mon_loc ?fg wwl›*) IHAPP(2) (*‹(Ml::'m::type set) ⊆ mon_loc fg (w1::('p::type, 'ba::type) label list el_step list)›*) FS_FMT(1) (*‹eel = LOC (LCall p # w)›*) by fastforce moreover have "Me ⊆ mon_env fg (eel#wwl)" using mon_env_ileq[OF ILEQ, of fg] (*‹mon_env fg (w1::('p, 'ba) label list el_step list) ⊆ mon_env fg (wwl::('p, 'ba) label list el_step list)›*) IHAPP(3) (*‹Me ⊆ mon_env fg w1›*) by auto moreover have "ah_update h (mon fg p, mon_w fg w) (Ml ∪ Me) ≤ αah (map (αnl fg) (eel#wwl))" proof (simp add: ah_update_cons (*‹αah (?e # ?w) = ah_update (αah ?w) ?e (mon_pl ?w)›*)) (*goal: ‹ah_update h (mon fg p, mon_w fg w) (Ml ∪ Me) ≤ ah_update (αah (map (αnl fg) wwl)) (αnl fg eel) (mon_pl (map (αnl fg) wwl))›*) show "ah_update h (mon fg p, mon_w fg w) (Ml ∪ Me) ≤ ah_update (αah (map (αnl fg) wwl)) (αnl fg eel) (mon_pl (map (αnl fg) wwl))" proof (rule ah_update_mono (*‹⟦(?h::?'a ⇒ ?'a set) ≤ (?h'::?'a ⇒ ?'a set); (?F::?'a set × ?'a set) = (?F'::?'a set × ?'a set); (?M::?'a set) ⊆ (?M'::?'a set)⟧ ⟹ ah_update ?h ?F ?M ≤ ah_update ?h' ?F' ?M'›*)) (*goals: 1. ‹h ≤ αah (map (αnl fg) wwl)› 2. ‹(mon fg p, mon_w fg w) = αnl fg eel› 3. ‹Ml ∪ Me ⊆ mon_pl (map (αnl fg) wwl)›*) from IHAPP(4) (*‹h ≤ αah (map (αnl fg) w1)›*) have "h ≤ αah (map (αnl fg) w1)" . also (*calculation: ‹h ≤ αah (map (αnl fg) w1)›*) from "αah_ileq"[OF le_list_map [ OF ILEQ ]] (*‹αah (map ?f1 w1) ≤ αah (map ?f1 wwl)›*) have "αah (map (αnl fg) w1) ≤ αah (map (αnl fg) wwl)" . finally (*calculation: ‹h ≤ αah (map (αnl fg) wwl)›*) show "h ≤ αah (map (αnl fg) wwl)" . next (*goals: 1. ‹(mon fg p, mon_w fg w) = αnl fg eel› 2. ‹Ml ∪ Me ⊆ mon_pl (map (αnl fg) wwl)›*) from FS_FMT(1) (*‹eel = LOC (LCall p # w)›*) show "(mon fg p, mon_w fg w) = αnl fg eel" by auto next (*goal: ‹Ml ∪ Me ⊆ mon_pl (map (αnl fg) wwl)›*) from IHAPP(2,3) (*‹Ml ⊆ mon_loc fg w1› ‹Me ⊆ mon_env fg w1›*) have "(Ml ∪ Me) ⊆ mon_pl (map (αnl fg) w1)" by (auto simp add: mon_pl_of_αnl (*‹mon_pl (map (αnl (?fg::(?'d, ?'b, ?'e, ?'a, ?'f) flowgraph_rec_scheme)) (?w::(?'b::type, ?'c::type) label list el_step list)) = mon_loc ?fg ?w ∪ mon_env ?fg ?w›*)) also (*calculation: ‹Ml ∪ Me ⊆ mon_pl (map (αnl fg) w1)›*) from mon_pl_ileq[OF le_list_map [ OF ILEQ ]] (*‹mon_pl (map (?f1::('p, 'ba) label list el_step ⇒ ?'a set × ?'a set) (w1::('p, 'ba) label list el_step list)) ⊆ mon_pl (map ?f1 (wwl::('p, 'ba) label list el_step list))›*) have "… ⊆ mon_pl (map (αnl fg) wwl)" . finally (*calculation: ‹Ml ∪ Me ⊆ mon_pl (map (αnl fg) wwl)›*) show "(Ml ∪ Me) ⊆ mon_pl (map (αnl fg) wwl)" . qed qed ultimately show "?thesis" (*goal: ‹∃Ml Me h. (u, Ml, Me, h) ∈ RU_cs fg U ∧ Ml ⊆ mon_loc fg (eel # wwl) ∧ Me ⊆ mon_env fg (eel # wwl) ∧ h ≤ αah (map (αnl fg) (eel # wwl))›*) by blast next (*goal: ‹atU U c2' ⟹ ∃Ml Me h. (u, Ml, Me, h) ∈ RU_cs fg U ∧ Ml ⊆ mon_loc fg (eel # wwl) ∧ Me ⊆ mon_env fg (eel # wwl) ∧ h ≤ αah (map (αnl fg) (eel # wwl))›*) case right (*‹atU U c2'›*) from cil_ileq[OF LESPLIT ( 1 )] (*‹w1 ≼ wwl ∧ map ENV w2 ≼ wwl›*) le_list_length[of "map ENV w2" "wwl"] (*‹map ENV w2 ≼ wwl ⟹ length (map ENV w2) ≤ length wwl›*) have ILEQ: "map ENV w2≼wwl" and LEN: "length w2 ≤ length wwl" apply - (*goals: 1. ‹⟦w1 ≼ wwl ∧ map ENV w2 ≼ wwl; map ENV w2 ≼ wwl ⟹ length (map ENV w2) ≤ length wwl⟧ ⟹ map ENV w2 ≼ wwl› 2. ‹⟦w1 ≼ wwl ∧ map ENV w2 ≼ wwl; map ENV w2 ≼ wwl ⟹ length (map ENV w2) ≤ length wwl⟧ ⟹ length w2 ≤ length wwl› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . from HVALID (*‹valid fg ({#sh#} + ch)›*) have CHVALID: "valid fg ch" "mon_s fg sh ∩ mon_c fg ch = {}" apply - (*goals: 1. ‹valid fg ({#sh#} + ch) ⟹ valid fg ch› 2. ‹valid fg ({#sh#} + ch) ⟹ mon_s fg sh ∩ mon_c fg ch = {}› discuss goal 1*) apply ((auto simp add: valid_unconc (*‹valid ?fg (?c + ?c') = (valid ?fg ?c ∧ valid ?fg ?c' ∧ mon_c ?fg ?c ∩ mon_c ?fg ?c' = {})› ‹valid ?fg (add_mset ?x ?c') = (valid ?fg ?c' ∧ mon_s ?fg ?x ∩ mon_c ?fg ?c' = {})›*))[1]) (*discuss goal 2*) apply ((auto simp add: valid_unconc (*‹valid ?fg (?c + ?c') = (valid ?fg ?c ∧ valid ?fg ?c' ∧ mon_c ?fg ?c ∩ mon_c ?fg ?c' = {})› ‹valid ?fg (add_mset ?x ?c') = (valid ?fg ?c' ∧ mon_s ?fg ?x ∩ mon_c ?fg ?c' = {})›*))[1]) (*proven 2 subgoals*) . from ntr_reverse_split_atU[OF CHVALID ( 1 ) right LESPLIT ( 4 )] (*‹∃s w' c1'. s ∈# ch ∧ w' ≼ w2 ∧ c1' ⊆# c2' ∧ atU U c1' ∧ ({#s#}, w', c1') ∈ trcl (ntr fg)›*) obtain q and wr and cr' where RI: "[entry fg q] ∈# ch" "wr≼w2" "cr'⊆#c2'" "atU U cr'" "({#[entry fg q]#},wr,cr')∈trcl (ntr fg)" (*goal: ‹(⋀q wr cr'. ⟦[entry fg q] ∈# ch; wr ≼ w2; cr' ⊆# c2'; atU U cr'; ({#[entry fg q]#}, wr, cr') ∈ trcl (ntr fg)⟧ ⟹ thesis) ⟹ thesis›*) by (blast dest: CHFMT (*‹?s ∈# ch ⟹ ∃p u v. ?s = [entry fg p] ∧ (u, Spawn p, v) ∈ edges fg ∧ initialproc fg p›*)) from ntrs.gtr2gtrp[where c = "{#}", simplified, OF RI ( 5 )] (*‹(⋀s' ce' ww. ⟦cr' = add_mset s' ce'; wr = map le_rem_s ww; (([entry fg q], {#}), ww, s', ce') ∈ trcl (ntrp fg)⟧ ⟹ ?P) ⟹ ?P›*) obtain sr' and cre' and wwr where RI_NTRP: "cr'=add_mset sr' cre'" "wr=map le_rem_s wwr" "(([entry fg q],{#}),wwr,(sr',cre'))∈trcl (ntrp fg)" (*goal: ‹(⋀sr' cre' wwr. ⟦cr' = add_mset sr' cre'; wr = map le_rem_s wwr; (([entry fg q], {#}), wwr, sr', cre') ∈ trcl (ntrp fg)⟧ ⟹ thesis) ⟹ thesis›*) by blast from LEN (*‹length w2 ≤ length wwl›*) le_list_length[OF RI ( 2 )] (*‹length wr ≤ length w2›*) RI_NTRP(2) (*‹wr = map le_rem_s wwr›*) have LEN': "length wwr ≤ length wwl" by simp from Cons.hyps[OF LEN' RI_NTRP ( 3 )] (*‹atU U (add_mset sr' cre') ⟹ ∃Ml Me h. (entry fg q, Ml, Me, h) ∈ RU_cs fg U ∧ Ml ⊆ mon_loc fg wwr ∧ Me ⊆ mon_env fg wwr ∧ h ≤ αah (map (αnl fg) wwr)›*) RI_NTRP(1) (*‹(cr'::'n list multiset) = add_mset (sr'::'n list) (cre'::'n list multiset)›*) RI(4) (*‹atU U cr'›*) obtain Ml and Me and h where IHAPP: "(entry fg q, Ml, Me, h)∈RU_cs fg U" "Ml ⊆ mon_loc fg wwr" "Me ⊆ mon_env fg wwr" "h ≤ αah (map (αnl fg) wwr)" (*goal: ‹(⋀(Ml::'m::type set) (Me::'m::type set) h::'m::type ⇒ 'm::type set. ⟦(entry fg (q::'p::type), Ml, Me, h) ∈ RU_cs fg (U::'n::type set); Ml ⊆ mon_loc fg (wwr::('p::type, 'ba::type) label list el_step list); Me ⊆ mon_env fg wwr; h ≤ αah (map (αnl fg) wwr)⟧ ⟹ thesis::bool) ⟹ thesis›*) by auto from S_ENTRY_PAT[of "{#q#}", simplified] (*‹[entry fg q] ∈# ch ⟹ (v, mon_w fg w, {#q#}) ∈ S_cs fg (Suc 0)›*) RI(1) (*‹[entry fg q] ∈# ch›*) have S_ENTRY: "(v, mon_w fg w, {#q#}) ∈ S_cs fg 1" by auto have MON_MLE_ENV: "Ml ∪ Me ⊆ mon_env fg wwl" proof (-) (*goal: ‹Ml ∪ Me ⊆ mon_env fg wwl›*) from IHAPP(2,3) (*‹Ml ⊆ mon_loc fg wwr› ‹(Me::'m set) ⊆ mon_env fg (wwr::('p, 'ba) label list el_step list)›*) have "Ml ∪ Me ⊆ mon_loc fg wwr ∪ mon_env fg wwr" by auto also (*calculation: ‹Ml ∪ Me ⊆ mon_loc fg wwr ∪ mon_env fg wwr›*) from mon_ww_of_le_rem[symmetric] (*‹mon_loc ?fg ?w ∪ mon_env ?fg ?w = mon_ww ?fg (map le_rem_s ?w)›*) RI_NTRP(2) (*‹wr = map le_rem_s wwr›*) have "… = mon_ww fg wr" by fastforce also (*calculation: ‹Ml ∪ Me ⊆ mon_ww fg wr›*) from mon_env_ileq[OF ILEQ] (*‹mon_env (?fg::(?'d, 'p, ?'e, ?'c, ?'f) flowgraph_rec_scheme) (map ENV (w2::('p, 'ba) label list list)) ⊆ mon_env ?fg (wwl::('p, 'ba) label list el_step list)›*) mon_ww_ileq[OF RI ( 2 )] (*‹mon_ww ?fg wr ⊆ mon_ww ?fg w2›*) have "… ⊆ mon_env fg wwl" by fastforce finally (*calculation: ‹Ml ∪ Me ⊆ mon_env fg wwl›*) show "?thesis" (*goal: ‹Ml ∪ Me ⊆ mon_env fg wwl›*) . qed have MON_UP_MLE: "(mon_n fg u ∪ mon fg p) ∩ (Ml ∪ Me) = {}" proof (-) (*goal: ‹(mon_n fg u ∪ mon fg p) ∩ (Ml ∪ Me) = {}›*) from ntrp_mon_env_w_no_ctx[OF SPLIT ( 2 )] (*‹mon_env fg (wwl::('p, 'ba) label list el_step list) ∩ mon_s fg (sh::'n list) = {}›*) FS_FMT(3,4) (*‹sh = [v, u']› ‹proc_of fg v = p›*) edges_part[OF FS_FMT ( 2 )] (*‹proc_of fg u = proc_of fg u'›*) have "(mon_n fg u ∪ mon fg p) ∩ mon_env fg wwl = {}" by (auto simp add: mon_n_def (*‹mon_n ?fg ?n ≡ mon ?fg (proc_of ?fg ?n)›*)) with MON_MLE_ENV (*‹Ml ∪ Me ⊆ mon_env fg wwl›*) show "?thesis" (*goal: ‹(mon_n fg u ∪ mon fg p) ∩ (Ml ∪ Me) = {}›*) by auto qed from RU_spawn[OF FS_FMT ( 2 , 4 ) S_ENTRY _ IHAPP ( 1 ) MON_UP_MLE] (*‹(q::'p::type) ∈# {#q#} ⟹ (u::'n::type, mon fg (p::'p::type) ∪ mon_w fg (w::('p::type, 'ba::type) label list), (Ml::'m::type set) ∪ (Me::'m::type set), ah_update (h::'m::type ⇒ 'm::type set) (mon fg p, mon_w fg w) (Ml ∪ Me)) ∈ RU_cs fg (U::'n::type set)›*) have "(u, mon fg p ∪ mon_w fg w, Ml ∪ Me, ah_update h (mon fg p, mon_w fg w) (Ml ∪ Me)) ∈ RU_cs fg U" by simp moreover have "mon fg p ∪ mon_w fg w ⊆ mon_loc fg (eel#wwl)" using FS_FMT(1) (*‹eel = LOC (LCall p # w)›*) by fastforce moreover have "Ml ∪ Me ⊆ mon_env fg (eel#wwl)" using MON_MLE_ENV (*‹(Ml::'m::type set) ∪ (Me::'m::type set) ⊆ mon_env fg (wwl::('p::type, 'ba::type) label list el_step list)›*) by auto moreover have "ah_update h (mon fg p, mon_w fg w) (Ml ∪ Me) ≤ αah (map (αnl fg) (eel#wwl))" proof (simp add: ah_update_cons (*‹αah (?e # ?w) = ah_update (αah ?w) ?e (mon_pl ?w)›*)) (*goal: ‹ah_update h (mon fg p, mon_w fg w) (Ml ∪ Me) ≤ ah_update (αah (map (αnl fg) wwl)) (αnl fg eel) (mon_pl (map (αnl fg) wwl))›*) have MAP_HELPER: "map (αnl fg) wwr ≼ map (αnl fg) wwl" proof (-) (*goal: ‹map (αnl fg) wwr ≼ map (αnl fg) wwl›*) from RI_NTRP(2) (*‹(wr::('p::type, 'ba::type) label list list) = map le_rem_s (wwr::('p::type, 'ba::type) label list el_step list)›*) have "map (αnl fg) wwr = map (αn fg) wr" by (simp add: αn_αnl (*‹αn (?fg::(?'d, ?'a, ?'e, ?'c, ?'f) flowgraph_rec_scheme) ∘ le_rem_s = αnl ?fg›*)) also (*calculation: ‹map (αnl fg) wwr = map (αn fg) wr›*) from le_list_map[OF RI ( 2 )] (*‹map (?f::('p, 'ba) label list ⇒ ?'b) (wr::('p, 'ba) label list list) ≼ map ?f (w2::('p, 'ba) label list list)›*) have "… ≼ map (αn fg) w2" . also (*calculation: ‹map (αnl fg) wwr ≼ map (αn fg) w2›*) have "… = map (αnl fg) (map ENV w2)" by simp also (*calculation: ‹map (αnl fg) wwr ≼ map (αnl fg) (map ENV w2)›*) from le_list_map[OF ILEQ] (*‹map (?f::('p, 'ba) label list el_step ⇒ ?'b) (map ENV (w2::('p, 'ba) label list list)) ≼ map ?f (wwl::('p, 'ba) label list el_step list)›*) have "… ≼ map (αnl fg) wwl" . finally (*calculation: ‹map (αnl fg) wwr ≼ map (αnl fg) wwl›*) show "?thesis" (*goal: ‹map (αnl fg) wwr ≼ map (αnl fg) wwl›*) . qed show "ah_update h (mon fg p, mon_w fg w) (Ml ∪ Me) ≤ ah_update (αah (map (αnl fg) wwl)) (αnl fg eel) (mon_pl (map (αnl fg) wwl))" proof (rule ah_update_mono (*‹⟦(?h::?'a ⇒ ?'a set) ≤ (?h'::?'a ⇒ ?'a set); (?F::?'a set × ?'a set) = (?F'::?'a set × ?'a set); (?M::?'a set) ⊆ (?M'::?'a set)⟧ ⟹ ah_update ?h ?F ?M ≤ ah_update ?h' ?F' ?M'›*)) (*goals: 1. ‹h ≤ αah (map (αnl fg) wwl)› 2. ‹(mon fg p, mon_w fg w) = αnl fg eel› 3. ‹Ml ∪ Me ⊆ mon_pl (map (αnl fg) wwl)›*) from IHAPP(4) (*‹h ≤ αah (map (αnl fg) wwr)›*) have "h ≤ αah (map (αnl fg) wwr)" . also (*calculation: ‹h ≤ αah (map (αnl fg) wwr)›*) have "… ≤ αah (map (αnl fg) wwl)" by (rule αah_ileq[OF MAP_HELPER] (*‹αah (map (αnl fg) wwr) ≤ αah (map (αnl fg) wwl)›*)) finally (*calculation: ‹h ≤ αah (map (αnl fg) wwl)›*) show "h ≤ αah (map (αnl fg) wwl)" . next (*goals: 1. ‹(mon fg p, mon_w fg w) = αnl fg eel› 2. ‹Ml ∪ Me ⊆ mon_pl (map (αnl fg) wwl)›*) from FS_FMT(1) (*‹(eel::('p, 'ba) label list el_step) = LOC (LCall (p::'p) # (w::('p, 'ba) label list))›*) show "(mon fg p, mon_w fg w) = αnl fg eel" by simp next (*goal: ‹Ml ∪ Me ⊆ mon_pl (map (αnl fg) wwl)›*) from IHAPP(2,3) (*‹Ml ⊆ mon_loc fg wwr› ‹Me ⊆ mon_env fg wwr›*) mon_pl_ileq[OF MAP_HELPER] (*‹mon_pl (map (αnl fg) wwr) ⊆ mon_pl (map (αnl fg) wwl)›*) show "Ml ∪ Me ⊆ mon_pl (map (αnl fg) wwl)" by (auto simp add: mon_pl_of_αnl (*‹mon_pl (map (αnl ?fg) ?w) = mon_loc ?fg ?w ∪ mon_env ?fg ?w›*)) qed qed ultimately show "?thesis" (*goal: ‹∃Ml Me h. (u, Ml, Me, h) ∈ RU_cs fg U ∧ Ml ⊆ mon_loc fg (eel # wwl) ∧ Me ⊆ mon_env fg (eel # wwl) ∧ h ≤ αah (map (αnl fg) (eel # wwl))›*) by blast qed qed text ‹ Now we prove a statement about the precision of the least solution. As in the precision proof of the @{term "S_cs"} constraint system, we construct a path for the entry on the conclusion side of each constraint, assuming that there already exists paths for the entries mentioned in the antecedent. We show that each entry in the least solution corresponds exactly to some executable path, and is not just an under-approximation of a path; while for the soundness direction, we could only show that every executable path is under-approximated. The reason for this is that in effect, the constraint system prunes the steps of threads that are not needed to reach the control point. However, each pruned path is executable. › lemma (in flowgraph) RU_precise: "(u,Ml,Me,h)∈RU_cs fg U ⟹ ∃w s' c'. (([u],{#}),w,(s',c'))∈trcl (ntrp fg) ∧ atU U ({#s'#}+c') ∧ mon_loc fg w = Ml ∧ mon_env fg w = Me ∧ αah (map (αnl fg) w) = h" proof (induct rule: RU_cs.induct (*‹⟦(?x1.0::?'n, ?x2.0::?'m set, ?x3.0::?'m set, ?x4.0::?'m ⇒ ?'m set) ∈ RU_cs (?fg::(?'n, ?'p, ?'ba, ?'m, ?'more) flowgraph_rec_scheme) (?U::?'n set); ⋀u::?'n. u ∈ ?U ⟹ (?P::?'n ⇒ ?'m set ⇒ ?'m set ⇒ (?'m ⇒ ?'m set) ⇒ bool) u {} {} (λx::?'m. {}); ⋀(u::?'n) (p::?'p) (u'::?'n) (v::?'n) (M::?'m set) (P::?'p multiset) (Ml::?'m set) (Me::?'m set) h::?'m ⇒ ?'m set. ⟦(u, Call p, u') ∈ edges ?fg; proc_of ?fg v = p; (v, M, P) ∈ S_cs ?fg (0::nat); (v, Ml, Me, h) ∈ RU_cs ?fg ?U; ?P v Ml Me h; mon_n ?fg u ∩ Me = {}⟧ ⟹ ?P u (mon ?fg p ∪ M ∪ Ml) Me (ah_update h (mon ?fg p, M) (Ml ∪ Me)); ⋀(u::?'n) (p::?'p) (u'::?'n) (v::?'n) (M::?'m set) (P::?'p multiset) (q::?'p) (Ml::?'m set) (Me::?'m set) h::?'m ⇒ ?'m set. ⟦(u, Call p, u') ∈ edges ?fg; proc_of ?fg v = p; (v, M, P) ∈ S_cs ?fg (1::nat); q ∈# P; (entry ?fg q, Ml, Me, h) ∈ RU_cs ?fg ?U; ?P (entry ?fg q) Ml Me h; (mon_n ?fg u ∪ mon ?fg p) ∩ (Ml ∪ Me) = {}⟧ ⟹ ?P u (mon ?fg p ∪ M) (Ml ∪ Me) (ah_update h (mon ?fg p, M) (Ml ∪ Me))⟧ ⟹ ?P ?x1.0 ?x2.0 ?x3.0 ?x4.0›*)) (*goals: 1. ‹⋀u. u ∈ U ⟹ ∃w s' c'. (([u], {#}), w, s', c') ∈ trcl (ntrp fg) ∧ atU U ({#s'#} + c') ∧ mon_loc fg w = {} ∧ mon_env fg w = {} ∧ αah (map (αnl fg) w) = (λa. {})› 2. ‹⋀u p u' v M P Ml Me h. ⟦(u, Call p, u') ∈ edges fg; proc_of fg v = p; (v, M, P) ∈ S_cs fg 0; (v, Ml, Me, h) ∈ RU_cs fg U; ∃w s' c'. (([v], {#}), w, s', c') ∈ trcl (ntrp fg) ∧ atU U ({#s'#} + c') ∧ mon_loc fg w = Ml ∧ mon_env fg w = Me ∧ αah (map (αnl fg) w) = h; mon_n fg u ∩ Me = {}⟧ ⟹ ∃w s' c'. (([u], {#}), w, s', c') ∈ trcl (ntrp fg) ∧ atU U ({#s'#} + c') ∧ mon_loc fg w = mon fg p ∪ M ∪ Ml ∧ mon_env fg w = Me ∧ αah (map (αnl fg) w) = ah_update h (mon fg p, M) (Ml ∪ Me)› 3. ‹⋀u p u' v M P q Ml Me h. ⟦(u, Call p, u') ∈ edges fg; proc_of fg v = p; (v, M, P) ∈ S_cs fg 1; q ∈# P; (entry fg q, Ml, Me, h) ∈ RU_cs fg U; ∃w s' c'. (([entry fg q], {#}), w, s', c') ∈ trcl (ntrp fg) ∧ atU U ({#s'#} + c') ∧ mon_loc fg w = Ml ∧ mon_env fg w = Me ∧ αah (map (αnl fg) w) = h; (mon_n fg u ∪ mon fg p) ∩ (Ml ∪ Me) = {}⟧ ⟹ ∃w s' c'. (([u], {#}), w, s', c') ∈ trcl (ntrp fg) ∧ atU U ({#s'#} + c') ∧ mon_loc fg w = mon fg p ∪ M ∧ mon_env fg w = Ml ∪ Me ∧ αah (map (αnl fg) w) = ah_update h (mon fg p, M) (Ml ∪ Me)›*) case (RU_init u) (*‹u ∈ U›*) thus "?case" (*goal: ‹∃w s' c'. (([u], {#}), w, s', c') ∈ trcl (ntrp fg) ∧ atU U ({#s'#} + c') ∧ mon_loc fg w = {} ∧ mon_env fg w = {} ∧ αah (map (αnl fg) w) = (λa. {})›*) by (auto intro: exI[of _ "[]"] (*‹?P [] ⟹ ∃x. ?P x›*)) next (*goals: 1. ‹⋀u p u' v M P Ml Me h. ⟦(u, Call p, u') ∈ edges fg; proc_of fg v = p; (v, M, P) ∈ S_cs fg 0; (v, Ml, Me, h) ∈ RU_cs fg U; ∃w s' c'. (([v], {#}), w, s', c') ∈ trcl (ntrp fg) ∧ atU U ({#s'#} + c') ∧ mon_loc fg w = Ml ∧ mon_env fg w = Me ∧ αah (map (αnl fg) w) = h; mon_n fg u ∩ Me = {}⟧ ⟹ ∃w s' c'. (([u], {#}), w, s', c') ∈ trcl (ntrp fg) ∧ atU U ({#s'#} + c') ∧ mon_loc fg w = mon fg p ∪ M ∪ Ml ∧ mon_env fg w = Me ∧ αah (map (αnl fg) w) = ah_update h (mon fg p, M) (Ml ∪ Me)› 2. ‹⋀u p u' v M P q Ml Me h. ⟦(u, Call p, u') ∈ edges fg; proc_of fg v = p; (v, M, P) ∈ S_cs fg 1; q ∈# P; (entry fg q, Ml, Me, h) ∈ RU_cs fg U; ∃w s' c'. (([entry fg q], {#}), w, s', c') ∈ trcl (ntrp fg) ∧ atU U ({#s'#} + c') ∧ mon_loc fg w = Ml ∧ mon_env fg w = Me ∧ αah (map (αnl fg) w) = h; (mon_n fg u ∪ mon fg p) ∩ (Ml ∪ Me) = {}⟧ ⟹ ∃w s' c'. (([u], {#}), w, s', c') ∈ trcl (ntrp fg) ∧ atU U ({#s'#} + c') ∧ mon_loc fg w = mon fg p ∪ M ∧ mon_env fg w = Ml ∪ Me ∧ αah (map (αnl fg) w) = ah_update h (mon fg p, M) (Ml ∪ Me)›*) case (RU_call u p u' v M P Ml Me h) (*‹(u, Call p, u') ∈ edges fg› ‹proc_of fg (v::'n) = (p::'p)› ‹(v, M, P) ∈ S_cs fg 0› ‹(v, Ml, Me, h) ∈ RU_cs fg U› ‹∃w s' c'. (([v], {#}), w, s', c') ∈ trcl (ntrp fg) ∧ atU U ({#s'#} + c') ∧ mon_loc fg w = Ml ∧ mon_env fg w = Me ∧ αah (map (αnl fg) w) = h› ‹mon_n fg u ∩ Me = {}›*) then obtain w and s' and c' where IHAPP: "(([v], {#}), w, s', c') ∈ trcl (ntrp fg)" "atU U ({#s'#} + c')" "mon_loc fg w = Ml" "mon_env fg w = Me" "αah (map (αnl fg) w) = h" (*goal: ‹(⋀(w::('p, 'ba) label list el_step list) (s'::'n list) c'::'n list multiset. ⟦(([v::'n], {#}), w, s', c') ∈ trcl (ntrp fg); atU (U::'n set) ({#s'#} + c'); mon_loc fg w = (Ml::'m set); mon_env fg w = (Me::'m set); αah (map (αnl fg) w) = (h::'m ⇒ 'm set)⟧ ⟹ thesis::bool) ⟹ thesis›*) by blast from RU_call.hyps(2) (*‹proc_of fg (v::'n) = (p::'p)›*) S_precise[OF RU_call.hyps ( 3 ), simplified] (*‹∃p c' w. (([entry fg p], {#}), w, [v], c') ∈ trcl (trss fg) ∧ P = {#} ∧ {#[entry fg p]. p ∈# P#} ⊆# c' ∧ M = mon_w fg w›*) trss_bot_proc_const[where s = "[]" and s' = "[]", simplified] (*‹(([?u::'n], ?c::'n list multiset), ?w::('p, 'ba) label list, [?u'::'n], ?c'::'n list multiset) ∈ trcl (trss fg) ⟹ proc_of fg ?u = proc_of fg ?u'›*) obtain wsl and ch where SLPATH: "(([entry fg p], {#}), wsl, [v], ch) ∈ trcl (trss fg)" "M = mon_w fg wsl" (*goal: ‹(⋀(wsl::('p, 'ba) label list) ch::'n list multiset. ⟦(([entry fg (p::'p)], {#}), wsl, [v::'n], ch) ∈ trcl (trss fg); (M::'m set) = mon_w fg wsl⟧ ⟹ thesis::bool) ⟹ thesis›*) by fastforce from trss_c_cases[OF SLPATH ( 1 ), simplified] (*‹((⋀s. s ∈# ch ⟹ ∃p. s = [entry fg p] ∧ (∃u v. (u, Spawn p, v) ∈ edges fg) ∧ initialproc fg p) ⟹ ?P) ⟹ ?P›*) have CHFMT: "⋀s. s ∈# ch ⟹ ∃p. s = [entry fg p] ∧ (∃u v. (u, Spawn p, v) ∈ edges fg) ∧ initialproc fg p" by blast with c_of_initial_no_mon (*‹(⋀s. s ∈# ?csp ⟹ ∃p. s = [entry fg p] ∧ initialproc fg p) ⟹ mon_c fg ?csp = {}›*) have CHNOMON: "mon_c fg ch = {}" by blast have FS: "(([u],{#}),LCall p#wsl,([v,u'],ch))∈ntrs fg" proof (rule ntrs_step[where r="[]", simplified] (*‹⟦(([?u], ?ce), LCall ?p, [entry ?fg ?p, ?u'], ?ce) ∈ trss ?fg; (([entry ?fg ?p], ?ce), ?w, [?v], ?ce') ∈ trcl (trss ?fg)⟧ ⟹ (([?u], ?ce), LCall ?p # ?w, [?v, ?u'], ?ce') ∈ ntrs ?fg›*)) (*goals: 1. ‹(([u], {#}), LCall p, [entry fg p, u'], {#}) ∈ trss fg› 2. ‹(([entry fg p], {#}), wsl, [v], ch) ∈ trcl (trss fg)›*) from RU_call.hyps(1) (*‹(u, Call p, u') ∈ edges fg›*) show "(([u], {#}), LCall p, [entry fg p, u'], {#}) ∈ trss fg" by (auto intro: trss_call (*‹⟦(?u, Call ?p, ?v) ∈ edges ?fg; mon ?fg ?p ∩ mon_c ?fg ?c = {}⟧ ⟹ ((?u # ?r, ?c), LCall ?p, entry ?fg ?p # ?v # ?r, ?c) ∈ trss ?fg›*)) qed (rule SLPATH( (*‹(([entry fg (p::'p)], {#}), wsl::('p, 'ba) label list, [v::'n], ch::'n list multiset) ∈ trcl (trss fg)›*) 1)) (*solved the remaining goal: ‹(([entry fg p], {#}), wsl, [v], ch) ∈ trcl (trss fg)›*) hence FSP: "(([u],{#}),LOC (LCall p#wsl),([v,u'],ch))∈ntrp fg" by (blast intro: gtrp_loc (*‹((?s::?'s, ?c::?'s multiset), ?e::?'l, ?s'::?'s, ?c'::?'s multiset) ∈ (?S::((?'s × ?'s multiset) × ?'l × ?'s × ?'s multiset) set) ⟹ ((?s, ?c), LOC ?e, ?s', ?c') ∈ gtrp ?S›*)) also (*calculation: ‹(([u], {#}), LOC (LCall p # wsl), [v, u'], ch) ∈ ntrp fg›*) have "(([v, u'], ch), w, s' @ [u'], c' + ch) ∈ trcl (ntrp fg)" proof (rule ntrp_add_context[OF ntrp_stack_comp[OF IHAPP(1), where r="[u']"], where cn=ch, simplified] (*‹⟦mon_n fg u' ∩ mon_env fg w = {}; mon_ww fg (map le_rem_s w) ∩ mon_c fg ch = {}⟧ ⟹ (([v, u'], ch), w, s' @ [u'], c' + ch) ∈ trcl (ntrp fg)›*)) (*goals: 1. ‹mon_n fg u' ∩ mon_env fg w = {}› 2. ‹mon_ww fg (map le_rem_s w) ∩ mon_c fg ch = {}›*) from RU_call.hyps(1,6) (*‹(u, Call p, u') ∈ edges fg› ‹mon_n fg u ∩ Me = {}›*) IHAPP(4) (*‹mon_env fg w = Me›*) show "mon_n fg u' ∩ mon_env fg w = {}" by (auto simp add: mon_n_def (*‹mon_n ?fg ?n ≡ mon ?fg (proc_of ?fg ?n)›*) edges_part (*‹(?u, ?a, ?v) ∈ edges fg ⟹ proc_of fg ?u = proc_of fg ?v›*)) from CHNOMON (*‹mon_c fg ch = {}›*) show "mon_ww fg (map le_rem_s w) ∩ mon_c fg ch = {}" by auto qed finally (*calculation: ‹(([u::'n], {#}), LOC (LCall (p::'p) # (wsl::('p, 'ba) label list)) # (w::('p, 'ba) label list el_step list), (s'::'n list) @ [u'::'n], (c'::'n list multiset) + (ch::'n list multiset)) ∈ trcl (ntrp fg)›*) have "(([u], {#}), LOC (LCall p # wsl) # w, s' @ [u'], c' + ch) ∈ trcl (ntrp fg)" . moreover from IHAPP(2) (*‹atU U ({#s'#} + c')›*) have "atU U ({# s'@[u'] #}+(c'+ch))" by auto moreover have "mon_loc fg (LOC (LCall p # wsl) # w) = mon fg p ∪ M ∪ Ml" using SLPATH(2) (*‹(M::'m::type set) = mon_w fg (wsl::('p::type, 'ba::type) label list)›*) IHAPP(3) (*‹mon_loc fg w = Ml›*) by auto moreover have "mon_env fg (LOC (LCall p # wsl) # w) = Me" using IHAPP(4) (*‹mon_env fg w = Me›*) by auto moreover have "αah (map (αnl fg) (LOC (LCall p # wsl) # w)) = ah_update h (mon fg p, M) (Ml ∪ Me)" proof (-) (*goal: ‹αah (map (αnl fg) (LOC (LCall p # wsl) # w)) = ah_update h (mon fg p, M) (Ml ∪ Me)›*) have "αah (map (αnl fg) (LOC (LCall p # wsl) # w)) = ah_update (αah (map (αnl fg) w)) (mon fg p, mon_w fg wsl) (mon_pl (map (αnl fg) w))" by (auto simp add: ah_update_cons (*‹αah (?e # ?w) = ah_update (αah ?w) ?e (mon_pl ?w)›*)) also (*calculation: ‹αah (map (αnl fg) (LOC (LCall (p::'p::type) # (wsl::('p::type, 'ba::type) label list)) # (w::('p::type, 'ba::type) label list el_step list))) = ah_update (αah (map (αnl fg) w)) (mon fg p, mon_w fg wsl) (mon_pl (map (αnl fg) w))›*) have "… = ah_update h (mon fg p, M) (Ml ∪ Me)" proof (-) (*goal: ‹ah_update (αah (map (αnl fg) w)) (mon fg p, mon_w fg wsl) (mon_pl (map (αnl fg) w)) = ah_update h (mon fg p, M) (Ml ∪ Me)›*) from IHAPP(5) (*‹αah (map (αnl fg) (w::('p, 'ba) label list el_step list)) = (h::'m ⇒ 'm set)›*) have "αah (map (αnl fg) w) = h" . moreover from SLPATH(2) (*‹M = mon_w fg wsl›*) have "(mon fg p, mon_w fg wsl) = (mon fg p, M)" by (simp add: mon_pl_of_αnl (*‹mon_pl (map (αnl (?fg::(?'d, ?'b, ?'e, ?'a, ?'f) flowgraph_rec_scheme)) (?w::(?'b, ?'c) label list el_step list)) = mon_loc ?fg ?w ∪ mon_env ?fg ?w›*)) moreover from IHAPP(3,4) (*‹mon_loc fg w = Ml› ‹mon_env fg w = Me›*) have "mon_pl (map (αnl fg) w) = Ml ∪ Me" by (auto simp add: mon_pl_of_αnl (*‹mon_pl (map (αnl ?fg) ?w) = mon_loc ?fg ?w ∪ mon_env ?fg ?w›*)) ultimately show "?thesis" (*goal: ‹ah_update (αah (map (αnl fg) w)) (mon fg p, mon_w fg wsl) (mon_pl (map (αnl fg) w)) = ah_update h (mon fg p, M) (Ml ∪ Me)›*) by simp qed finally (*calculation: ‹αah (map (αnl fg) (LOC (LCall p # wsl) # w)) = ah_update h (mon fg p, M) (Ml ∪ Me)›*) show "?thesis" (*goal: ‹αah (map (αnl fg) (LOC (LCall (p::'p) # (wsl::('p, 'ba) label list)) # (w::('p, 'ba) label list el_step list))) = ah_update (h::'m ⇒ 'm set) (mon fg p, M::'m set) ((Ml::'m set) ∪ (Me::'m set))›*) . qed ultimately show "?case" (*goal: ‹∃w s' c'. (([u], {#}), w, s', c') ∈ trcl (ntrp fg) ∧ atU U ({#s'#} + c') ∧ mon_loc fg w = mon fg p ∪ M ∪ Ml ∧ mon_env fg w = Me ∧ αah (map (αnl fg) w) = ah_update h (mon fg p, M) (Ml ∪ Me)›*) by blast next (*goal: ‹⋀u p u' v M P q Ml Me h. ⟦(u, Call p, u') ∈ edges fg; proc_of fg v = p; (v, M, P) ∈ S_cs fg 1; q ∈# P; (entry fg q, Ml, Me, h) ∈ RU_cs fg U; ∃w s' c'. (([entry fg q], {#}), w, s', c') ∈ trcl (ntrp fg) ∧ atU U ({#s'#} + c') ∧ mon_loc fg w = Ml ∧ mon_env fg w = Me ∧ αah (map (αnl fg) w) = h; (mon_n fg u ∪ mon fg p) ∩ (Ml ∪ Me) = {}⟧ ⟹ ∃w s' c'. (([u], {#}), w, s', c') ∈ trcl (ntrp fg) ∧ atU U ({#s'#} + c') ∧ mon_loc fg w = mon fg p ∪ M ∧ mon_env fg w = Ml ∪ Me ∧ αah (map (αnl fg) w) = ah_update h (mon fg p, M) (Ml ∪ Me)›*) case (RU_spawn u p u' v M P q Ml Me h) (*‹(u::'n, Call (p::'p), u'::'n) ∈ edges fg› ‹proc_of fg v = p› ‹(v, M, P) ∈ S_cs fg 1› ‹(q::'p) ∈# (P::'p multiset)› ‹(entry fg (q::'p), Ml::'m set, Me::'m set, h::'m ⇒ 'm set) ∈ RU_cs fg (U::'n set)› ‹∃w s' c'. (([entry fg q], {#}), w, s', c') ∈ trcl (ntrp fg) ∧ atU U ({#s'#} + c') ∧ mon_loc fg w = Ml ∧ mon_env fg w = Me ∧ αah (map (αnl fg) w) = h› ‹(mon_n fg u ∪ mon fg p) ∩ (Ml ∪ Me) = {}›*) then obtain w and s' and c' where IHAPP: "(([entry fg q], {#}), w, s', c') ∈ trcl (ntrp fg)" "atU U ({#s'#} + c')" "mon_loc fg w = Ml" "mon_env fg w = Me" "αah (map (αnl fg) w) = h" (*goal: ‹(⋀(w::('p::type, 'ba::type) label list el_step list) (s'::'n::type list) c'::'n::type list multiset. ⟦(([entry fg (q::'p::type)], {#}), w, s', c') ∈ trcl (ntrp fg); atU (U::'n::type set) ({#s'#} + c'); mon_loc fg w = (Ml::'m::type set); mon_env fg w = (Me::'m::type set); αah (map (αnl fg) w) = (h::'m::type ⇒ 'm::type set)⟧ ⟹ thesis::bool) ⟹ thesis›*) by blast from RU_spawn.hyps(2) (*‹proc_of fg v = p›*) S_precise[OF RU_spawn.hyps ( 3 ), simplified] (*‹∃p c' w. (([entry fg p], {#}), w, [v], c') ∈ trcl (trss fg) ∧ size P ≤ Suc 0 ∧ {#[entry fg p]. p ∈# P#} ⊆# c' ∧ M = mon_w fg w›*) trss_bot_proc_const[where s = "[]" and s' = "[]", simplified] (*‹(([?u], ?c), ?w, [?u'], ?c') ∈ trcl (trss fg) ⟹ proc_of fg ?u = proc_of fg ?u'›*) obtain wsl and ch where SLPATH: "(([entry fg p], {#}), wsl, [v], ch) ∈ trcl (trss fg)" "M = mon_w fg wsl" "size P ≤ 1" "(λp. [entry fg p]) `# P ⊆# ch" (*goal: ‹(⋀wsl ch. ⟦(([entry fg p], {#}), wsl, [v], ch) ∈ trcl (trss fg); M = mon_w fg wsl; size P ≤ 1; {#[entry fg p]. p ∈# P#} ⊆# ch⟧ ⟹ thesis) ⟹ thesis›*) by fastforce with RU_spawn.hyps(4) (*‹q ∈# P›*) obtain che where PFMT: "P={#q#}" "ch = {#[entry fg q]#} + che" (*goal: ‹(⋀che. ⟦P = {#q#}; ch = {#[entry fg q]#} + che⟧ ⟹ thesis) ⟹ thesis›*) by (auto elim!: mset_size_le1_cases (*‹⟦size ?M ≤ Suc 0; ?M = {#} ⟹ ?P; ⋀m. ?M = {#m#} ⟹ ?P⟧ ⟹ ?P›*) mset_le_addE (*‹⟦?xs ⊆# ?ys; ⋀zs. ?ys = ?xs + zs ⟹ ?P⟧ ⟹ ?P›*)) from trss_c_cases[OF SLPATH ( 1 ), simplified] (*‹((⋀s. s ∈# ch ⟹ ∃p. s = [entry fg p] ∧ (∃u v. (u, Spawn p, v) ∈ edges fg) ∧ initialproc fg p) ⟹ ?P) ⟹ ?P›*) have CHFMT: "⋀s. s ∈# ch ⟹ ∃p. s = [entry fg p] ∧ (∃u v. (u, Spawn p, v) ∈ edges fg) ∧ initialproc fg p" by blast with c_of_initial_no_mon (*‹(⋀s::'n list. s ∈# (?csp::'n list multiset) ⟹ ∃p::'p. s = [entry fg p] ∧ initialproc fg p) ⟹ mon_c fg ?csp = {}›*) have CHNOMON: "mon_c fg ch = {}" by blast have FS: "(([u],{#}),LCall p#wsl,([v,u'],ch))∈ntrs fg" proof (rule ntrs_step[where r="[]", simplified] (*‹⟦(([?u], ?ce), LCall ?p, [entry ?fg ?p, ?u'], ?ce) ∈ trss ?fg; (([entry ?fg ?p], ?ce), ?w, [?v], ?ce') ∈ trcl (trss ?fg)⟧ ⟹ (([?u], ?ce), LCall ?p # ?w, [?v, ?u'], ?ce') ∈ ntrs ?fg›*)) (*goals: 1. ‹(([u], {#}), LCall p, [entry fg p, u'], {#}) ∈ trss fg› 2. ‹(([entry fg p], {#}), wsl, [v], ch) ∈ trcl (trss fg)›*) from RU_spawn.hyps(1) (*‹(u, Call p, u') ∈ edges fg›*) show "(([u], {#}), LCall p, [entry fg p, u'], {#}) ∈ trss fg" by (auto intro: trss_call (*‹⟦(?u, Call ?p, ?v) ∈ edges ?fg; mon ?fg ?p ∩ mon_c ?fg ?c = {}⟧ ⟹ ((?u # ?r, ?c), LCall ?p, entry ?fg ?p # ?v # ?r, ?c) ∈ trss ?fg›*)) qed (rule SLPATH( (*‹(([entry fg p], {#}), wsl, [v], ch) ∈ trcl (trss fg)›*) 1)) (*solved the remaining goal: ‹(([entry fg p], {#}), wsl, [v], ch) ∈ trcl (trss fg)›*) hence FSP: "(([u],{#}),LOC (LCall p#wsl),([v,u'],ch))∈ntrp fg" by (blast intro: gtrp_loc (*‹((?s, ?c), ?e, ?s', ?c') ∈ ?S ⟹ ((?s, ?c), LOC ?e, ?s', ?c') ∈ gtrp ?S›*)) also (*calculation: ‹(([u], {#}), LOC (LCall p # wsl), [v, u'], ch) ∈ ntrp fg›*) have "(([v, u'], ch), map ENV (map le_rem_s w), [v,u'], che+({#s'#}+c')) ∈ trcl (ntrp fg)" proof (-) (*goal: ‹(([v, u'], ch), map ENV (map le_rem_s w), [v, u'], che + ({#s'#} + c')) ∈ trcl (ntrp fg)›*) from IHAPP(3,4) (*‹mon_loc fg w = Ml› ‹mon_env fg w = Me›*) have "mon_ww fg (map le_rem_s w) ⊆ Ml ∪ Me" by (auto simp add: mon_ww_of_le_rem (*‹mon_ww ?fg (map le_rem_s ?w) = mon_loc ?fg ?w ∪ mon_env ?fg ?w›*)) with RU_spawn.hyps(1,2,7) (*‹(u, Call p, u') ∈ edges fg› ‹proc_of fg v = p› ‹(mon_n fg u ∪ mon fg p) ∩ (Ml ∪ Me) = {}›*) have "(mon_n fg v ∪ mon_n fg u') ∩ mon_ww fg (map le_rem_s w) = {}" by (auto simp add: mon_n_def (*‹mon_n ?fg ?n ≡ mon ?fg (proc_of ?fg ?n)›*) edges_part (*‹(?u, ?a, ?v) ∈ edges fg ⟹ proc_of fg ?u = proc_of fg ?v›*)) with ntr2ntrp[OF gtrp2gtr [ OF IHAPP ( 1 ) ], of "[v,u']" che] (*‹mon_c fg (add_mset [v::'n, u'::'n] (che::'n list multiset)) ∩ (mon_c fg {#[entry fg (q::'p)]#} ∪ mon_ww fg (map le_rem_s (w::('p, 'ba) label list el_step list))) = {} ⟹ (([v, u'], che + {#[entry fg q]#}), map ENV (map le_rem_s w), [v, u'], che + add_mset (s'::'n list) (c'::'n list multiset)) ∈ trcl (ntrp fg)›*) PFMT(2) (*‹ch = {#[entry fg q]#} + che›*) CHNOMON (*‹mon_c fg (ch::'n list multiset) = {}›*) show "?thesis" (*goal: ‹(([v::'n, u'::'n], ch::'n list multiset), map ENV (map le_rem_s (w::('p, 'ba) label list el_step list)), [v, u'], (che::'n list multiset) + ({#s'::'n list#} + (c'::'n list multiset))) ∈ trcl (ntrp fg)›*) by (auto simp add: union_ac (*‹?M + ?N + ?K = ?M + (?N + ?K)› ‹?M + ?N = ?N + ?M› ‹?M + (?N + ?K) = ?N + (?M + ?K)› ‹add_mset ?x (add_mset ?y ?M) = add_mset ?y (add_mset ?x ?M)›*) mon_c_unconc (*‹mon_c ?fg (?a + ?b) = mon_c ?fg ?a ∪ mon_c ?fg ?b› ‹mon_c ?fg (add_mset ?x ?b) = mon_s ?fg ?x ∪ mon_c ?fg ?b›*)) qed finally (*calculation: ‹(([u], {#}), LOC (LCall p # wsl) # map ENV (map le_rem_s w), [v, u'], che + ({#s'#} + c')) ∈ trcl (ntrp fg)›*) have "(([u], {#}), LOC (LCall p # wsl) # map ENV (map le_rem_s w), [v, u'], che + ({#s'#} + c')) ∈ trcl (ntrp fg)" . moreover from IHAPP(2) (*‹atU U ({#s'#} + c')›*) have "atU U ({#[v,u']#} + (che+({#s'#} + c')))" by auto moreover have "mon_loc fg (LOC (LCall p # wsl) # map ENV (map le_rem_s w)) = mon fg p ∪ M" using SLPATH(2) (*‹M = mon_w fg wsl›*) by (auto simp del: map_map (*‹map ?f (map ?g ?xs) = map (?f ∘ ?g) ?xs›*)) moreover have "mon_env fg (LOC (LCall p # wsl) # map ENV (map le_rem_s w)) = Ml ∪ Me" using IHAPP(3,4) (*‹mon_loc fg w = Ml› ‹mon_env fg w = Me›*) by (auto simp add: mon_ww_of_le_rem (*‹mon_ww (?fg::(?'b, ?'c, ?'d, ?'a, ?'e) flowgraph_rec_scheme) (map le_rem_s (?w::(?'c::type, ?'f::type) label list el_step list)) = mon_loc ?fg ?w ∪ mon_env ?fg ?w›*) simp del: map_map (*‹map (?f::?'b::type ⇒ ?'a::type) (map (?g::?'c::type ⇒ ?'b::type) (?xs::?'c::type list)) = map (?f ∘ ?g) ?xs›*)) moreover have "αah (map (αnl fg) (LOC (LCall p # wsl) # map ENV (map le_rem_s w))) = ah_update h (mon fg p, M) (Ml ∪ Me)" proof (-) (*goal: ‹αah (map (αnl fg) (LOC (LCall p # wsl) # map ENV (map le_rem_s w))) = ah_update h (mon fg p, M) (Ml ∪ Me)›*) have "αah (map (αnl fg) (LOC (LCall p # wsl) # map ENV (map le_rem_s w))) = ah_update (αah (map (αn fg) (map le_rem_s w))) (mon fg p, mon_w fg wsl) (mon_pl (map (αn fg) (map le_rem_s w)))" by (simp add: ah_update_cons (*‹αah (?e # ?w) = ah_update (αah ?w) ?e (mon_pl ?w)›*) o_assoc (*‹?f ∘ (?g ∘ ?h) = ?f ∘ ?g ∘ ?h›*)) also (*calculation: ‹αah (map (αnl fg) (LOC (LCall p # wsl) # map ENV (map le_rem_s w))) = ah_update (αah (map (αn fg) (map le_rem_s w))) (mon fg p, mon_w fg wsl) (mon_pl (map (αn fg) (map le_rem_s w)))›*) have "… = ah_update h (mon fg p, M) (Ml ∪ Me)" proof (-) (*goal: ‹ah_update (αah (map (αn fg) (map le_rem_s (w::('p, 'ba) label list el_step list)))) (mon fg (p::'p), mon_w fg (wsl::('p, 'ba) label list)) (mon_pl (map (αn fg) (map le_rem_s w))) = ah_update (h::'m ⇒ 'm set) (mon fg p, M::'m set) ((Ml::'m set) ∪ (Me::'m set))›*) from IHAPP(5) (*‹αah (map (αnl fg) w) = h›*) have "αah (map (αn fg) (map le_rem_s w)) = h" by (simp add: αn_αnl (*‹αn ?fg ∘ le_rem_s = αnl ?fg›*)) moreover from SLPATH(2) (*‹M = mon_w fg wsl›*) have "(mon fg p, mon_w fg wsl) = (mon fg p, M)" by simp moreover from IHAPP(3,4) (*‹mon_loc fg w = Ml› ‹mon_env fg w = Me›*) have "mon_pl (map (αn fg) (map le_rem_s w)) = Ml ∪ Me" by (auto simp add: mon_pl_of_αnl (*‹mon_pl (map (αnl ?fg) ?w) = mon_loc ?fg ?w ∪ mon_env ?fg ?w›*) αn_αnl (*‹αn ?fg ∘ le_rem_s = αnl ?fg›*)) ultimately show "?thesis" (*goal: ‹ah_update (αah (map (αn fg) (map le_rem_s (w::('p, 'ba) label list el_step list)))) (mon fg (p::'p), mon_w fg (wsl::('p, 'ba) label list)) (mon_pl (map (αn fg) (map le_rem_s w))) = ah_update (h::'m ⇒ 'm set) (mon fg p, M::'m set) ((Ml::'m set) ∪ (Me::'m set))›*) by simp qed finally (*calculation: ‹αah (map (αnl fg) (LOC (LCall (p::'p) # (wsl::('p, 'ba) label list)) # map ENV (map le_rem_s (w::('p, 'ba) label list el_step list)))) = ah_update (h::'m ⇒ 'm set) (mon fg p, M::'m set) ((Ml::'m set) ∪ (Me::'m set))›*) show "?thesis" (*goal: ‹αah (map (αnl fg) (LOC (LCall p # wsl) # map ENV (map le_rem_s w))) = ah_update h (mon fg p, M) (Ml ∪ Me)›*) . qed ultimately show "?case" (*goal: ‹∃(w::('p, 'ba) label list el_step list) (s'::'n list) c'::'n list multiset. (([u::'n], {#}), w, s', c') ∈ trcl (ntrp fg) ∧ atU (U::'n set) ({#s'#} + c') ∧ mon_loc fg w = mon fg (p::'p) ∪ (M::'m set) ∧ mon_env fg w = (Ml::'m set) ∪ (Me::'m set) ∧ αah (map (αnl fg) w) = ah_update (h::'m ⇒ 'm set) (mon fg p, M) (Ml ∪ Me)›*) by blast qed subsection "Simultaneously reaching path" text ‹ In this section, we define a constraint system that collects abstract information for paths starting at a single control node and reaching two program points simultaneously, one from a set @{term U} and one from a set @{term V}. › subsubsection "Constraint system" text ‹ An element @{term "(u,Ml,Me)∈RUV_cs fg U V"} means, that there is a path from @{term "{#[u]#}"} to some configuration that is simultaneously at @{term U} and at @{term V}. That path uses monitors from @{term Ml} in the first thread and monitors from @{term Me} in the other threads. › inductive_set RUV_cs :: "('n,'p,'ba,'m,'more) flowgraph_rec_scheme ⇒ 'n set ⇒ 'n set ⇒ ('n × 'm set × 'm set) set" for fg U V where RUV_call: "⟦ (u,Call p,u')∈edges fg; proc_of fg v = p; (v,M,P)∈S_cs fg 0; (v,Ml,Me)∈RUV_cs fg U V; mon_n fg u ∩ Me = {} ⟧ ⟹ (u,mon fg p ∪ M ∪ Ml,Me)∈RUV_cs fg U V" | RUV_spawn: "⟦ (u,Call p,u')∈edges fg; proc_of fg v = p; (v,M,P)∈S_cs fg 1; q ∈# P; (entry fg q,Ml,Me)∈RUV_cs fg U V; (mon_n fg u ∪ mon fg p) ∩ (Ml ∪ Me) = {} ⟧ ⟹ (u, mon fg p ∪ M, Ml∪Me)∈RUV_cs fg U V" | RUV_split_le: "⟦ (u,Call p,u')∈edges fg; proc_of fg v = p; (v,M,P)∈S_cs fg 1; q ∈# P; (v,Ml,Me,h)∈RU_cs fg U; (entry fg q,Ml',Me',h')∈RU_cs fg V; (mon_n fg u ∪ mon fg p) ∩ (Me∪Ml'∪Me')={}; h [*] h' ⟧ ⟹ (u, mon fg p ∪ M ∪ Ml, Me ∪ Ml' ∪ Me')∈RUV_cs fg U V" | RUV_split_el: "⟦ (u,Call p,u')∈edges fg; proc_of fg v = p; (v,M,P)∈S_cs fg 1; q ∈# P; (v,Ml,Me,h)∈RU_cs fg V; (entry fg q,Ml',Me',h')∈RU_cs fg U; (mon_n fg u ∪ mon fg p) ∩ (Me∪Ml'∪Me')={}; h [*] h' ⟧ ⟹ (u, mon fg p ∪ M ∪ Ml, Me ∪ Ml' ∪ Me')∈RUV_cs fg U V" | RUV_split_ee: "⟦ (u,Call p,u')∈edges fg; proc_of fg v = p; (v,M,P)∈S_cs fg 2; {#q#}+{#q'#} ⊆# P; (entry fg q,Ml,Me,h)∈RU_cs fg U; (entry fg q',Ml',Me',h')∈RU_cs fg V; (mon_n fg u ∪ mon fg p) ∩ (Ml∪Me∪Ml'∪Me') = {}; h [*] h' ⟧ ⟹ (u, mon fg p ∪ M, Ml∪Me∪Ml'∪Me')∈RUV_cs fg U V" text ‹ The idea underlying this constraint system is similar to the @{term RU_cs}-constraint system for reaching a single node set. Initially, we just track one thread. After a macrostep, we have a configuration consisting of the transformed initial thread and the spawned threads. From this configuration, we reach two nodes simultaneously, one in @{term U} and one in @{term V}. Each of these nodes is reached by just a single thread. The constraint system contains one constraint for each case how these threads are related to the initial and the spawned threads: \begin{description} \item[RUV\_call] Both, @{term U} and @{term V} are reached from the initial thread. \item[RUV\_spawn] Both, @{term U} and @{term V} are reached from a single spawned thread. \item[RUV\_split\_le] @{term U} is reached from the initial thread, @{term V} is reached from a spawned thread. \item[RUV\_split\_el] @{term V} is reached from the initial thread, @{term U} is reached from a spawned thread. \item[RUV\_split\_ee] Both, @{term U} and @{term V} are reached from different spawned threads. \end{description} In the latter three cases, we have to analyze the interleaving of two paths each reaching a single control node. This is done via the acquisition history information that we collected in the @{term RU_cs}-constraint system. Note that we do not need an initializing constraint for the empty path, as a single configuration cannot simultaneously be at two control nodes. › subsubsection ‹Soundness and precision› lemma (in flowgraph) RUV_sound: "!!u s' c'. ⟦ (([u],{#}),w,(s',c'))∈trcl (ntrp fg); atUV U V ({#s'#}+c') ⟧ ⟹ ∃Ml Me. (u,Ml,Me)∈RUV_cs fg U V ∧ Ml ⊆ mon_loc fg w ∧ Me ⊆ mon_env fg w" ― ‹The soundness proof is done by induction over the length of the reaching path› proof (induct w rule: length_compl_induct (*‹⟦?P []; ⋀e l. (⋀ll. length ll ≤ length l ⟹ ?P ll) ⟹ ?P (e # l)⟧ ⟹ ?P ?l›*)) (*goals: 1. ‹⋀(u::'n) (s'::'n list) c'::'n list multiset. ⟦(([u], {#}), [], s', c') ∈ trcl (ntrp fg); atUV (U::'n set) (V::'n set) ({#s'#} + c')⟧ ⟹ ∃(Ml::'m set) Me::'m set. (u, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg [] ∧ Me ⊆ mon_env fg []› 2. ‹⋀(e::('p, 'ba) label list el_step) (l::('p, 'ba) label list el_step list) (u::'n) (s'::'n list) c'::'n list multiset. ⟦⋀(ll::('p, 'ba) label list el_step list) (u::'n) (s'::'n list) c'::'n list multiset. ⟦length ll ≤ length l; (([u], {#}), ll, s', c') ∈ trcl (ntrp fg); atUV (U::'n set) (V::'n set) ({#s'#} + c')⟧ ⟹ ∃(Ml::'m set) Me::'m set. (u, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg ll ∧ Me ⊆ mon_env fg ll; (([u], {#}), e # l, s', c') ∈ trcl (ntrp fg); atUV U V ({#s'#} + c')⟧ ⟹ ∃(Ml::'m set) Me::'m set. (u, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg (e # l) ∧ Me ⊆ mon_env fg (e # l)›*) case Nil (*‹(([u], {#}), [], s', c') ∈ trcl (ntrp fg)› ‹atUV U V ({#s'#} + c')›*) hence False by simp thus "?case" (*goal: ‹∃(Ml::'m set) Me::'m set. (u::'n, Ml, Me) ∈ RUV_cs fg (U::'n set) (V::'n set) ∧ Ml ⊆ mon_loc fg [] ∧ Me ⊆ mon_env fg []›*) by standard next (*goal: ‹⋀(e::('p::type, 'ba::type) label list el_step) (l::('p::type, 'ba::type) label list el_step list) (u::'n::type) (s'::'n::type list) c'::'n::type list multiset. ⟦⋀(ll::('p::type, 'ba::type) label list el_step list) (u::'n::type) (s'::'n::type list) c'::'n::type list multiset. ⟦length ll ≤ length l; (([u], {#}), ll, s', c') ∈ trcl (ntrp fg); atUV (U::'n::type set) (V::'n::type set) ({#s'#} + c')⟧ ⟹ ∃(Ml::'m::type set) Me::'m::type set. (u, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg ll ∧ Me ⊆ mon_env fg ll; (([u], {#}), e # l, s', c') ∈ trcl (ntrp fg); atUV U V ({#s'#} + c')⟧ ⟹ ∃(Ml::'m::type set) Me::'m::type set. (u, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg (e # l) ∧ Me ⊆ mon_env fg (e # l)›*) case (Cons ee ww) (*‹⟦length (?ll::('p::type, 'ba::type) label list el_step list) ≤ length (ww::('p::type, 'ba::type) label list el_step list); (([?u::'n::type], {#}), ?ll, ?s'::'n::type list, ?c'::'n::type list multiset) ∈ trcl (ntrp fg); atUV (U::'n::type set) (V::'n::type set) ({#?s'#} + ?c')⟧ ⟹ ∃(Ml::'m::type set) Me::'m::type set. (?u, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg ?ll ∧ Me ⊆ mon_env fg ?ll› ‹(([u::'n], {#}), (ee::('p, 'ba) label list el_step) # (ww::('p, 'ba) label list el_step list), s'::'n list, c'::'n list multiset) ∈ trcl (ntrp fg)› ‹atUV U V ({#s'#} + c')›*) then obtain sh and ch where SPLIT: "(([u],{#}),ee,(sh,ch))∈ntrp fg" "((sh,ch),ww,(s',c'))∈trcl (ntrp fg)" (*goal: ‹(⋀(sh::'n list) ch::'n list multiset. ⟦(([u::'n], {#}), ee::('p, 'ba) label list el_step, sh, ch) ∈ ntrp fg; ((sh, ch), ww::('p, 'ba) label list el_step list, s'::'n list, c'::'n list multiset) ∈ trcl (ntrp fg)⟧ ⟹ thesis::bool) ⟹ thesis›*) by (fast dest: trcl_uncons (*‹(?c, ?a # ?w, ?c') ∈ trcl ?t ⟹ ∃ch. (?c, ?a, ch) ∈ ?t ∧ (ch, ?w, ?c') ∈ trcl ?t›*)) from ntrp_split[where ?c1.0 = "{#}", simplified, OF SPLIT ( 2 ) ntrp_valid_preserve_s [ OF SPLIT ( 1 ) ], simplified] (*‹∃w1 w2. ww ∈ w1 ⊗⇘αnl fg⇙ map ENV w2 ∧ (∃c1' c2'. c' = c1' + c2' ∧ ((sh, {#}), w1, s', c1') ∈ trcl (ntrp fg) ∧ (ch, w2, c2') ∈ trcl (ntr fg) ∧ mon_ww fg (map le_rem_s w1) ∩ mon_c fg ch = {} ∧ mon_ww fg w2 ∩ mon_s fg sh = {})›*) obtain w1 and w2 and c1' and c2' where LESPLIT: "ww ∈ w1 ⊗⇘αnl fg⇙ map ENV w2" "c' = c1' + c2'" "((sh, {#}), w1, s', c1') ∈ trcl (ntrp fg)" "(ch, w2, c2') ∈ trcl (ntr fg)" "mon_ww fg (map le_rem_s w1) ∩ mon_c fg ch = {}" "mon_ww fg w2 ∩ mon_s fg sh = {}" (*goal: ‹(⋀(w1::('p, 'ba) label list el_step list) (w2::('p, 'ba) label list list) (c1'::'n list multiset) c2'::'n list multiset. ⟦(ww::('p, 'ba) label list el_step list) ∈ w1 ⊗⇘αnl fg⇙ map ENV w2; (c'::'n list multiset) = c1' + c2'; ((sh::'n list, {#}), w1, s'::'n list, c1') ∈ trcl (ntrp fg); (ch::'n list multiset, w2, c2') ∈ trcl (ntr fg); mon_ww fg (map le_rem_s w1) ∩ mon_c fg ch = {}; mon_ww fg w2 ∩ mon_s fg sh = {}⟧ ⟹ thesis::bool) ⟹ thesis›*) by blast obtain p and u' and v and w where FS_FMT: "ee = LOC (LCall p # w)" "(u, Call p, u') ∈ edges fg" "sh = [v, u']" "proc_of fg v = p" "mon_c fg ch = {}" and CHFMT: "⋀s. s ∈# ch ⟹ ∃p u v. s = [entry fg p] ∧ (u, Spawn p, v) ∈ edges fg ∧ initialproc fg p" and S_ENTRY_PAT: "⋀P. (λp. [entry fg p]) `# P ⊆# ch ⟹ (v, mon_w fg w, P) ∈ S_cs fg (size P)" (*goal: ‹(⋀(p::'p) (w::('p, 'ba) label list) (u'::'n) v::'n. ⟦(ee::('p, 'ba) label list el_step) = LOC (LCall p # w); (u::'n, Call p, u') ∈ edges fg; (sh::'n list) = [v, u']; proc_of fg v = p; mon_c fg (ch::'n list multiset) = {}; ⋀s::'n list. s ∈# ch ⟹ ∃(p::'p) (u::'n) v::'n. s = [entry fg p] ∧ (u, Spawn p, v) ∈ edges fg ∧ initialproc fg p; ⋀P::'p multiset. {#[entry fg p]. p::'p ∈# P#} ⊆# ch ⟹ (v, mon_w fg w, P) ∈ S_cs fg (size P)⟧ ⟹ thesis::bool) ⟹ thesis›*) apply (rule S_sound_ntrp[OF SPLIT(1)] (*‹(⋀p u' v w. ⟦ee = LOC (LCall p # w); (u, Call p, u') ∈ edges fg; sh = [v, u']; proc_of fg v = p; mon_c fg ch = {}; ⋀s. s ∈# ch ⟹ ∃p u v. s = [entry fg p] ∧ (u, Spawn p, v) ∈ edges fg ∧ initialproc fg p; ⋀P. {#[entry fg p]. p ∈# P#} ⊆# ch ⟹ (v, mon_w fg w, P) ∈ S_cs fg (size P)⟧ ⟹ ?Q) ⟹ ?Q›*)) (*goal: ‹(⋀p w u' v. ⟦ee = LOC (LCall p # w); (u, Call p, u') ∈ edges fg; sh = [v, u']; proc_of fg v = p; mon_c fg ch = {}; ⋀s. s ∈# ch ⟹ ∃p u v. s = [entry fg p] ∧ (u, Spawn p, v) ∈ edges fg ∧ initialproc fg p; ⋀P. {#[entry fg p]. p ∈# P#} ⊆# ch ⟹ (v, mon_w fg w, P) ∈ S_cs fg (size P)⟧ ⟹ thesis) ⟹ thesis›*) by blast from ntrp_mon_env_w_no_ctx[OF SPLIT ( 2 )] (*‹mon_env fg ww ∩ mon_s fg sh = {}›*) FS_FMT(3,4) (*‹sh = [v, u']› ‹proc_of fg v = p›*) edges_part[OF FS_FMT ( 2 )] (*‹proc_of fg u = proc_of fg u'›*) have MON_PU: "mon_env fg ww ∩ (mon fg p ∪ mon_n fg u) = {}" by (auto simp add: mon_n_def (*‹mon_n ?fg ?n ≡ mon ?fg (proc_of ?fg ?n)›*)) from cil_ileq[OF LESPLIT ( 1 )] (*‹w1 ≼ ww ∧ map ENV w2 ≼ ww›*) mon_loc_ileq[of w1 ww fg] (*‹(w1::('p, 'ba) label list el_step list) ≼ (ww::('p, 'ba) label list el_step list) ⟹ mon_loc fg w1 ⊆ mon_loc fg ww›*) mon_env_ileq[of w1 ww fg] (*‹w1 ≼ ww ⟹ mon_env fg w1 ⊆ mon_env fg ww›*) have MON1_LEQ: "mon_loc fg w1 ⊆ mon_loc fg ww" "mon_env fg w1 ⊆ mon_env fg ww" apply - (*goals: 1. ‹⟦w1 ≼ ww ∧ map ENV w2 ≼ ww; w1 ≼ ww ⟹ mon_loc fg w1 ⊆ mon_loc fg ww; w1 ≼ ww ⟹ mon_env fg w1 ⊆ mon_env fg ww⟧ ⟹ mon_loc fg w1 ⊆ mon_loc fg ww› 2. ‹⟦w1 ≼ ww ∧ map ENV w2 ≼ ww; w1 ≼ ww ⟹ mon_loc fg w1 ⊆ mon_loc fg ww; w1 ≼ ww ⟹ mon_env fg w1 ⊆ mon_env fg ww⟧ ⟹ mon_env fg w1 ⊆ mon_env fg ww› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . from cil_ileq[OF LESPLIT ( 1 )] (*‹w1 ≼ ww ∧ map ENV w2 ≼ ww›*) mon_env_ileq[of "map ENV w2" ww fg] (*‹map ENV w2 ≼ ww ⟹ mon_env fg (map ENV w2) ⊆ mon_env fg ww›*) have MON2_LEQ: "mon_ww fg w2 ⊆ mon_env fg ww" by simp from LESPLIT(3) (*‹((sh, {#}), w1, s', c1') ∈ trcl (ntrp fg)›*) FS_FMT(3) (*‹sh = [v, u']›*) ntrp_stack_decomp[of v "[]" "[u']" "{#}" w1 s' c1', simplified] (*‹⟦(([v, u'], {#}), w1, s', c1') ∈ trcl (ntrp ?fg); ⋀va rr. ⟦s' = va # rr @ [u']; (([v], {#}), w1, va # rr, c1') ∈ trcl (ntrp ?fg)⟧ ⟹ ?P⟧ ⟹ ?P›*) obtain v' and rr where DECOMP_LOC: "s'=v'#rr@[u']" "(([v],{#}),w1,(v'#rr,c1'))∈trcl (ntrp fg)" (*goal: ‹(⋀v' rr. ⟦s' = v' # rr @ [u']; (([v], {#}), w1, v' # rr, c1') ∈ trcl (ntrp fg)⟧ ⟹ thesis) ⟹ thesis›*) apply simp (*goal: ‹(⋀v' rr. ⟦s' = v' # rr @ [u']; (([v], {#}), w1, v' # rr, c1') ∈ trcl (ntrp fg)⟧ ⟹ thesis) ⟹ thesis›*) by blast from Cons.prems(2) (*‹atUV U V ({#s'#} + c')›*) LESPLIT(2) (*‹c' = c1' + c2'›*) have "atUV U V (({#s'#}+c1') + c2')" by (simp add: union_ac (*‹?M + ?N + ?K = ?M + (?N + ?K)› ‹?M + ?N = ?N + ?M› ‹?M + (?N + ?K) = ?N + (?M + ?K)› ‹add_mset ?x (add_mset ?y ?M) = add_mset ?y (add_mset ?x ?M)›*)) thus "?case" (*goal: ‹∃Ml Me. (u, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg (ee # ww) ∧ Me ⊆ mon_env fg (ee # ww)›*) proof (cases rule: atUV_union_cases (*‹⟦atUV ?U ?V (?c1.0 + ?c2.0); atUV ?U ?V ?c1.0 ⟹ ?P; atUV ?U ?V ?c2.0 ⟹ ?P; ⟦atU ?U ?c1.0; atU ?V ?c2.0⟧ ⟹ ?P; ⟦atU ?V ?c1.0; atU ?U ?c2.0⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹atUV U V ({#s'#} + c1') ⟹ ∃Ml Me. (u, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg (ee # ww) ∧ Me ⊆ mon_env fg (ee # ww)› 2. ‹atUV U V c2' ⟹ ∃Ml Me. (u, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg (ee # ww) ∧ Me ⊆ mon_env fg (ee # ww)› 3. ‹⟦atU U ({#s'#} + c1'); atU V c2'⟧ ⟹ ∃Ml Me. (u, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg (ee # ww) ∧ Me ⊆ mon_env fg (ee # ww)› 4. ‹⟦atU V ({#s'#} + c1'); atU U c2'⟧ ⟹ ∃Ml Me. (u, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg (ee # ww) ∧ Me ⊆ mon_env fg (ee # ww)›*) case left (*‹atUV U V ({#s'#} + c1')›*) with DECOMP_LOC(1) (*‹s' = v' # rr @ [u']›*) have ATUV: "atUV U V ({# v'#rr #}+c1')" by simp from Cons.hyps[OF _ DECOMP_LOC ( 2 ) ATUV] (*‹length w1 ≤ length ww ⟹ ∃Ml Me. (v, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg w1 ∧ Me ⊆ mon_env fg w1›*) cil_length[OF LESPLIT ( 1 )] (*‹length ww = length w1 + length (map ENV w2)›*) obtain Ml and Me where IHAPP: "(v, Ml, Me) ∈ RUV_cs fg U V" "Ml ⊆ mon_loc fg w1" "Me ⊆ mon_env fg w1" (*goal: ‹(⋀(Ml::'m set) Me::'m set. ⟦(v::'n, Ml, Me) ∈ RUV_cs fg (U::'n set) (V::'n set); Ml ⊆ mon_loc fg (w1::('p, 'ba) label list el_step list); Me ⊆ mon_env fg w1⟧ ⟹ thesis::bool) ⟹ thesis›*) by auto from RUV_call[OF FS_FMT ( 2 , 4 ) S_ENTRY_PAT [ of "{#}" , simplified ] IHAPP ( 1 )] (*‹mon_n fg (u::'n::type) ∩ (Me::'m::type set) = {} ⟹ (u, mon fg (p::'p::type) ∪ mon_w fg (w::('p::type, 'ba::type) label list) ∪ (Ml::'m::type set), Me) ∈ RUV_cs fg (U::'n::type set) (V::'n::type set)›*) have "(u, mon fg p ∪ mon_w fg w ∪ Ml, Me) ∈ RUV_cs fg U V" using IHAPP(3) (*‹(Me::'m set) ⊆ mon_env fg (w1::('p, 'ba) label list el_step list)›*) MON_PU (*‹mon_env fg (ww::('p::type, 'ba::type) label list el_step list) ∩ (mon fg (p::'p::type) ∪ mon_n fg (u::'n::type)) = {}›*) MON1_LEQ (*‹mon_loc fg w1 ⊆ mon_loc fg ww› ‹mon_env fg w1 ⊆ mon_env fg ww›*) by fastforce moreover have "mon fg p ∪ mon_w fg w ∪ Ml ⊆ mon_loc fg (ee#ww)" using FS_FMT(1) (*‹ee = LOC (LCall p # w)›*) IHAPP(2) (*‹Ml ⊆ mon_loc fg w1›*) MON1_LEQ (*‹mon_loc fg (w1::('p, 'ba) label list el_step list) ⊆ mon_loc fg (ww::('p, 'ba) label list el_step list)› ‹mon_env fg w1 ⊆ mon_env fg ww›*) by auto moreover have "Me ⊆ mon_env fg (ee#ww)" using IHAPP(3) (*‹(Me::'m::type set) ⊆ mon_env fg (w1::('p::type, 'ba::type) label list el_step list)›*) MON1_LEQ (*‹mon_loc fg w1 ⊆ mon_loc fg ww› ‹mon_env fg w1 ⊆ mon_env fg ww›*) by auto ultimately show "?thesis" (*goal: ‹∃Ml Me. (u, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg (ee # ww) ∧ Me ⊆ mon_env fg (ee # ww)›*) by blast next (*goals: 1. ‹atUV (U::'n set) (V::'n set) (c2'::'n list multiset) ⟹ ∃(Ml::'m set) Me::'m set. (u::'n, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg ((ee::('p, 'ba) label list el_step) # (ww::('p, 'ba) label list el_step list)) ∧ Me ⊆ mon_env fg (ee # ww)› 2. ‹⟦atU (U::'n set) ({#s'::'n list#} + (c1'::'n list multiset)); atU (V::'n set) (c2'::'n list multiset)⟧ ⟹ ∃(Ml::'m set) Me::'m set. (u::'n, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg ((ee::('p, 'ba) label list el_step) # (ww::('p, 'ba) label list el_step list)) ∧ Me ⊆ mon_env fg (ee # ww)› 3. ‹⟦atU (V::'n set) ({#s'::'n list#} + (c1'::'n list multiset)); atU (U::'n set) (c2'::'n list multiset)⟧ ⟹ ∃(Ml::'m set) Me::'m set. (u::'n, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg ((ee::('p, 'ba) label list el_step) # (ww::('p, 'ba) label list el_step list)) ∧ Me ⊆ mon_env fg (ee # ww)›*) case right (*‹atUV U V c2'›*) then obtain s1' and s2' where R_STACKS: "{#s1'#}+{#s2'#} ⊆# c2'" "atU_s U s1'" "atU_s V s2'" (*goal: ‹(⋀s1' s2'. ⟦{#s1'#} + {#s2'#} ⊆# c2'; atU_s U s1'; atU_s V s2'⟧ ⟹ thesis) ⟹ thesis›*) apply (unfold atUV_def (*‹atUV ?U ?V ?c ≡ ∃su sv. {#su#} + {#sv#} ⊆# ?c ∧ atU_s ?U su ∧ atU_s ?V sv›*)) (*goal: ‹(⋀s1' s2'. ⟦{#s1'#} + {#s2'#} ⊆# c2'; atU_s U s1'; atU_s V s2'⟧ ⟹ thesis) ⟹ thesis›*) by auto then obtain ce2' where C2'FMT: "c2'={#s1'#}+({#s2'#}+ce2')" (*goal: ‹(⋀ce2'. c2' = {#s1'#} + ({#s2'#} + ce2') ⟹ thesis) ⟹ thesis›*) by (auto simp add: mset_subset_eq_exists_conv (*‹((?A::?'a multiset) ⊆# (?B::?'a multiset)) = (∃C::?'a multiset. ?B = ?A + C)›*) union_ac (*‹(?M::?'a multiset) + (?N::?'a multiset) + (?K::?'a multiset) = ?M + (?N + ?K)› ‹(?M::?'a multiset) + (?N::?'a multiset) = ?N + ?M› ‹(?M::?'a multiset) + ((?N::?'a multiset) + (?K::?'a multiset)) = ?N + (?M + ?K)› ‹add_mset (?x::?'a) (add_mset (?y::?'a) (?M::?'a multiset)) = add_mset ?y (add_mset ?x ?M)›*)) obtain q and ceh and w21 and w22 and ce21' and ce22' where REVSPLIT: "ch={#[entry fg q]#}+ceh" "add_mset s2' ce2' = ce21'+ce22'" "w2∈w21⊗⇘αn fg⇙w22" "mon fg q ∩ (mon_c fg ceh ∪ mon_ww fg w22)={}" "mon_c fg ceh ∩ (mon fg q ∪ mon_ww fg w21) = {}" "({#[entry fg q]#},w21,{#s1'#}+ce21')∈trcl (ntr fg)" "(ceh,w22,ce22')∈trcl (ntr fg)" (*goal: ‹(⋀q ceh ce21' ce22' w21 w22. ⟦ch = {#[entry fg q]#} + ceh; add_mset s2' ce2' = ce21' + ce22'; w2 ∈ w21 ⊗⇘αn fg⇙ w22; mon fg q ∩ (mon_c fg ceh ∪ mon_ww fg w22) = {}; mon_c fg ceh ∩ (mon fg q ∪ mon_ww fg w21) = {}; ({#[entry fg q]#}, w21, {#s1'#} + ce21') ∈ trcl (ntr fg); (ceh, w22, ce22') ∈ trcl (ntr fg)⟧ ⟹ thesis) ⟹ thesis›*) proof (-) (*goal: ‹(⋀q ceh ce21' ce22' w21 w22. ⟦ch = {#[entry fg q]#} + ceh; add_mset s2' ce2' = ce21' + ce22'; w2 ∈ w21 ⊗⇘αn fg⇙ w22; mon fg q ∩ (mon_c fg ceh ∪ mon_ww fg w22) = {}; mon_c fg ceh ∩ (mon fg q ∪ mon_ww fg w21) = {}; ({#[entry fg q]#}, w21, {#s1'#} + ce21') ∈ trcl (ntr fg); (ceh, w22, ce22') ∈ trcl (ntr fg)⟧ ⟹ thesis) ⟹ thesis›*) from ntr_reverse_split[of ch w2 s1' "{#s2'#}+ce2'"] (*‹⟦(ch::'n list multiset, w2::('p, 'ba) label list list, {#s1'::'n list#} + ({#s2'::'n list#} + (ce2'::'n list multiset))) ∈ trcl (ntr fg); valid fg ch⟧ ⟹ ∃(s::'n list) (ce::'n list multiset) (w1::('p, 'ba) label list list) (w2a::('p, 'ba) label list list) (ce1'::'n list multiset) ce2'a::'n list multiset. ch = {#s#} + ce ∧ {#s2'#} + ce2' = ce1' + ce2'a ∧ w2 ∈ w1 ⊗⇘αn fg⇙ w2a ∧ mon_s fg s ∩ (mon_c fg ce ∪ mon_ww fg w2a) = {} ∧ mon_c fg ce ∩ (mon_s fg s ∪ mon_ww fg w1) = {} ∧ ({#s#}, w1, {#s1'#} + ce1') ∈ trcl (ntr fg) ∧ (ce, w2a, ce2'a) ∈ trcl (ntr fg)›*) ntrp_valid_preserve_s[OF SPLIT ( 1 ), simplified] (*‹valid fg (add_mset sh ch)›*) C2'FMT (*‹(c2'::'n list multiset) = {#s1'::'n list#} + ({#s2'::'n list#} + (ce2'::'n list multiset))›*) LESPLIT(4) (*‹(ch, w2, c2') ∈ trcl (ntr fg)›*) obtain seh and ceh and w21 and w22 and ce21' and ce22' where "*": "ch={#seh#}+ceh" "{#s2'#}+ce2' = ce21'+ce22'" "w2∈w21⊗⇘αn fg⇙w22" "mon_s fg seh ∩ (mon_c fg ceh ∪ mon_ww fg w22)={}" "mon_c fg ceh ∩ (mon_s fg seh ∪ mon_ww fg w21) = {}" "({#seh#},w21,{#s1'#}+ce21')∈trcl (ntr fg)" "(ceh,w22,ce22')∈trcl (ntr fg)" (*goal: ‹(⋀seh ceh ce21' ce22' w21 w22. ⟦ch = {#seh#} + ceh; {#s2'#} + ce2' = ce21' + ce22'; w2 ∈ w21 ⊗⇘αn fg⇙ w22; mon_s fg seh ∩ (mon_c fg ceh ∪ mon_ww fg w22) = {}; mon_c fg ceh ∩ (mon_s fg seh ∪ mon_ww fg w21) = {}; ({#seh#}, w21, {#s1'#} + ce21') ∈ trcl (ntr fg); (ceh, w22, ce22') ∈ trcl (ntr fg)⟧ ⟹ thesis) ⟹ thesis›*) by (auto simp add: valid_unconc (*‹valid ?fg (?c + ?c') = (valid ?fg ?c ∧ valid ?fg ?c' ∧ mon_c ?fg ?c ∩ mon_c ?fg ?c' = {})› ‹valid ?fg (add_mset ?x ?c') = (valid ?fg ?c' ∧ mon_s ?fg ?x ∩ mon_c ?fg ?c' = {})›*)) from this(1) (*‹ch = {#seh#} + ceh›*) CHFMT[of seh] (*‹seh ∈# ch ⟹ ∃p u v. seh = [entry fg p] ∧ (u, Spawn p, v) ∈ edges fg ∧ initialproc fg p›*) obtain q where "seh=[entry fg q]" (*goal: ‹(⋀q. seh = [entry fg q] ⟹ thesis) ⟹ thesis›*) by auto with "*" (*‹ch = {#seh#} + ceh› ‹{#s2'#} + ce2' = ce21' + ce22'› ‹w2 ∈ w21 ⊗⇘αn fg⇙ w22› ‹mon_s fg seh ∩ (mon_c fg ceh ∪ mon_ww fg w22) = {}› ‹mon_c fg ceh ∩ (mon_s fg seh ∪ mon_ww fg w21) = {}› ‹({#seh::'n list#}, w21::('p, 'ba) label list list, {#s1'::'n list#} + (ce21'::'n list multiset)) ∈ trcl (ntr fg)› ‹(ceh, w22, ce22') ∈ trcl (ntr fg)›*) have "ch={#[entry fg q]#}+ceh" "add_mset s2' ce2' = ce21'+ce22'" "w2∈w21⊗⇘αn fg⇙w22" "mon fg q ∩ (mon_c fg ceh ∪ mon_ww fg w22)={}" "mon_c fg ceh ∩ (mon fg q ∪ mon_ww fg w21) = {}" "({#[entry fg q]#},w21,{#s1'#}+ce21')∈trcl (ntr fg)" "(ceh,w22,ce22')∈trcl (ntr fg)" apply - (*goals: 1. ‹⟦ch = {#seh#} + ceh; {#s2'#} + ce2' = ce21' + ce22'; w2 ∈ w21 ⊗⇘αn fg⇙ w22; mon_s fg seh ∩ (mon_c fg ceh ∪ mon_ww fg w22) = {}; mon_c fg ceh ∩ (mon_s fg seh ∪ mon_ww fg w21) = {}; ({#seh#}, w21, {#s1'#} + ce21') ∈ trcl (ntr fg); (ceh, w22, ce22') ∈ trcl (ntr fg); seh = [entry fg q]⟧ ⟹ ch = {#[entry fg q]#} + ceh› 2. ‹⟦ch = {#seh#} + ceh; {#s2'#} + ce2' = ce21' + ce22'; w2 ∈ w21 ⊗⇘αn fg⇙ w22; mon_s fg seh ∩ (mon_c fg ceh ∪ mon_ww fg w22) = {}; mon_c fg ceh ∩ (mon_s fg seh ∪ mon_ww fg w21) = {}; ({#seh#}, w21, {#s1'#} + ce21') ∈ trcl (ntr fg); (ceh, w22, ce22') ∈ trcl (ntr fg); seh = [entry fg q]⟧ ⟹ add_mset s2' ce2' = ce21' + ce22'› 3. ‹⟦ch = {#seh#} + ceh; {#s2'#} + ce2' = ce21' + ce22'; w2 ∈ w21 ⊗⇘αn fg⇙ w22; mon_s fg seh ∩ (mon_c fg ceh ∪ mon_ww fg w22) = {}; mon_c fg ceh ∩ (mon_s fg seh ∪ mon_ww fg w21) = {}; ({#seh#}, w21, {#s1'#} + ce21') ∈ trcl (ntr fg); (ceh, w22, ce22') ∈ trcl (ntr fg); seh = [entry fg q]⟧ ⟹ w2 ∈ w21 ⊗⇘αn fg⇙ w22› 4. ‹⟦ch = {#seh#} + ceh; {#s2'#} + ce2' = ce21' + ce22'; w2 ∈ w21 ⊗⇘αn fg⇙ w22; mon_s fg seh ∩ (mon_c fg ceh ∪ mon_ww fg w22) = {}; mon_c fg ceh ∩ (mon_s fg seh ∪ mon_ww fg w21) = {}; ({#seh#}, w21, {#s1'#} + ce21') ∈ trcl (ntr fg); (ceh, w22, ce22') ∈ trcl (ntr fg); seh = [entry fg q]⟧ ⟹ mon fg q ∩ (mon_c fg ceh ∪ mon_ww fg w22) = {}› 5. ‹⟦ch = {#seh#} + ceh; {#s2'#} + ce2' = ce21' + ce22'; w2 ∈ w21 ⊗⇘αn fg⇙ w22; mon_s fg seh ∩ (mon_c fg ceh ∪ mon_ww fg w22) = {}; mon_c fg ceh ∩ (mon_s fg seh ∪ mon_ww fg w21) = {}; ({#seh#}, w21, {#s1'#} + ce21') ∈ trcl (ntr fg); (ceh, w22, ce22') ∈ trcl (ntr fg); seh = [entry fg q]⟧ ⟹ mon_c fg ceh ∩ (mon fg q ∪ mon_ww fg w21) = {}› 6. ‹⟦ch = {#seh#} + ceh; {#s2'#} + ce2' = ce21' + ce22'; w2 ∈ w21 ⊗⇘αn fg⇙ w22; mon_s fg seh ∩ (mon_c fg ceh ∪ mon_ww fg w22) = {}; mon_c fg ceh ∩ (mon_s fg seh ∪ mon_ww fg w21) = {}; ({#seh#}, w21, {#s1'#} + ce21') ∈ trcl (ntr fg); (ceh, w22, ce22') ∈ trcl (ntr fg); seh = [entry fg q]⟧ ⟹ ({#[entry fg q]#}, w21, {#s1'#} + ce21') ∈ trcl (ntr fg)› 7. ‹⟦ch = {#seh#} + ceh; {#s2'#} + ce2' = ce21' + ce22'; w2 ∈ w21 ⊗⇘αn fg⇙ w22; mon_s fg seh ∩ (mon_c fg ceh ∪ mon_ww fg w22) = {}; mon_c fg ceh ∩ (mon_s fg seh ∪ mon_ww fg w21) = {}; ({#seh#}, w21, {#s1'#} + ce21') ∈ trcl (ntr fg); (ceh, w22, ce22') ∈ trcl (ntr fg); seh = [entry fg q]⟧ ⟹ (ceh, w22, ce22') ∈ trcl (ntr fg)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*proven 7 subgoals*) . thus thesis using that (*‹⟦ch = {#[entry fg ?q]#} + ?ceh; add_mset s2' ce2' = ?ce21' + ?ce22'; w2 ∈ ?w21.0 ⊗⇘αn fg⇙ ?w22.0; mon fg ?q ∩ (mon_c fg ?ceh ∪ mon_ww fg ?w22.0) = {}; mon_c fg ?ceh ∩ (mon fg ?q ∪ mon_ww fg ?w21.0) = {}; ({#[entry fg ?q]#}, ?w21.0, {#s1'#} + ?ce21') ∈ trcl (ntr fg); (?ceh, ?w22.0, ?ce22') ∈ trcl (ntr fg)⟧ ⟹ thesis›*) by blast qed from ntrs.gtr2gtrp[where c = "{#}", simplified, OF REVSPLIT ( 6 )] (*‹(⋀s' ce' ww. ⟦{#s1'#} + ce21' = add_mset s' ce'; w21 = map le_rem_s ww; (([entry fg q], {#}), ww, s', ce') ∈ trcl (ntrp fg)⟧ ⟹ ?P) ⟹ ?P›*) obtain sq' and csp_q and ww21 where R_CONV: "add_mset s1' ce21' = add_mset sq' csp_q" "w21 = map le_rem_s ww21" "(([entry fg q], {#}), ww21, sq', csp_q) ∈ trcl (ntrp fg)" (*goal: ‹(⋀sq' csp_q ww21. ⟦add_mset s1' ce21' = add_mset sq' csp_q; w21 = map le_rem_s ww21; (([entry fg q], {#}), ww21, sq', csp_q) ∈ trcl (ntrp fg)⟧ ⟹ thesis) ⟹ thesis›*) by auto from cil_ileq[OF REVSPLIT ( 3 )] (*‹(w21::('p, 'ba) label list list) ≼ (w2::('p, 'ba) label list list) ∧ (w22::('p, 'ba) label list list) ≼ w2›*) mon_ww_ileq[of w21 w2 fg] (*‹w21 ≼ w2 ⟹ mon_ww fg w21 ⊆ mon_ww fg w2›*) mon_ww_ileq[of w22 w2 fg] (*‹(w22::('p, 'ba) label list list) ≼ (w2::('p, 'ba) label list list) ⟹ mon_ww fg w22 ⊆ mon_ww fg w2›*) have MON2N_LEQ: "mon_ww fg w21 ⊆ mon_ww fg w2" "mon_ww fg w22 ⊆ mon_ww fg w2" apply - (*goals: 1. ‹⟦w21 ≼ w2 ∧ w22 ≼ w2; w21 ≼ w2 ⟹ mon_ww fg w21 ⊆ mon_ww fg w2; w22 ≼ w2 ⟹ mon_ww fg w22 ⊆ mon_ww fg w2⟧ ⟹ mon_ww fg w21 ⊆ mon_ww fg w2› 2. ‹⟦w21 ≼ w2 ∧ w22 ≼ w2; w21 ≼ w2 ⟹ mon_ww fg w21 ⊆ mon_ww fg w2; w22 ≼ w2 ⟹ mon_ww fg w22 ⊆ mon_ww fg w2⟧ ⟹ mon_ww fg w22 ⊆ mon_ww fg w2› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . from REVSPLIT(2) (*‹add_mset (s2'::'n::type list) (ce2'::'n::type list multiset) = (ce21'::'n::type list multiset) + (ce22'::'n::type list multiset)›*) show "?thesis" (*goal: ‹∃Ml Me. (u, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg (ee # ww) ∧ Me ⊆ mon_env fg (ee # ww)›*) proof (cases rule: mset_unplusm_dist_cases[case_names left' right'] (*‹⟦add_mset ?s ?A = ?B + ?C; ⟦?B = add_mset ?s (?B - {#?s#}); ?A = ?B - {#?s#} + ?C⟧ ⟹ ?P; ⟦?C = add_mset ?s (?C - {#?s#}); ?A = ?B + (?C - {#?s#})⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹⟦ce21' = add_mset s2' (ce21' - {#s2'#}); ce2' = ce21' - {#s2'#} + ce22'⟧ ⟹ ∃Ml Me. (u, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg (ee # ww) ∧ Me ⊆ mon_env fg (ee # ww)› 2. ‹⟦ce22' = add_mset s2' (ce22' - {#s2'#}); ce2' = ce21' + (ce22' - {#s2'#})⟧ ⟹ ∃Ml Me. (u, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg (ee # ww) ∧ Me ⊆ mon_env fg (ee # ww)›*) case left' (*‹ce21' = add_mset s2' (ce21' - {#s2'#})› ‹ce2' = ce21' - {#s2'#} + ce22'›*) have ATUV: "atUV U V ({#sq'#}+csp_q)" using right (*‹atUV (U::'n set) (V::'n set) (c2'::'n list multiset)›*) C2'FMT (*‹(c2'::'n list multiset) = {#s1'::'n list#} + ({#s2'::'n list#} + (ce2'::'n list multiset))›*) R_STACKS(2,3) (*‹atU_s (U::'n::type set) (s1'::'n::type list)› ‹atU_s V s2'›*) left'(1) (*‹ce21' = add_mset s2' (ce21' - {#s2'#})›*) by (metis R_CONV( (*‹add_mset s1' ce21' = add_mset sq' csp_q›*) 1) add_mset_add_single (*‹add_mset ?a ?A = ?A + {#?a#}›*) atUV_union (*‹atUV ?U ?V (?c1.0 + ?c2.0) = (atUV ?U ?V ?c1.0 ∨ atUV ?U ?V ?c2.0 ∨ atU ?U ?c1.0 ∧ atU ?V ?c2.0 ∨ atU ?V ?c1.0 ∧ atU ?U ?c2.0)›*) atU_add_mset (*‹atU ?U (add_mset ?c ?c2.0) = (atU_s ?U ?c ∨ atU ?U ?c2.0)›*) union_commute (*‹?M + ?N = ?N + ?M›*)) from Cons.hyps[OF _ R_CONV ( 3 ) ATUV] (*‹length (ww21::('p, 'ba) label list el_step list) ≤ length (ww::('p, 'ba) label list el_step list) ⟹ ∃(Ml::'m set) Me::'m set. (entry fg (q::'p), Ml, Me) ∈ RUV_cs fg (U::'n set) (V::'n set) ∧ Ml ⊆ mon_loc fg ww21 ∧ Me ⊆ mon_env fg ww21›*) cil_length[OF REVSPLIT ( 3 )] (*‹length w2 = length w21 + length w22›*) cil_length[OF LESPLIT ( 1 )] (*‹length ww = length w1 + length (map ENV w2)›*) R_CONV(2) (*‹w21 = map le_rem_s ww21›*) obtain Ml and Me where IHAPP: "(entry fg q, Ml, Me) ∈ RUV_cs fg U V" "Ml ⊆ mon_loc fg ww21" "Me ⊆ mon_env fg ww21" (*goal: ‹(⋀Ml Me. ⟦(entry fg q, Ml, Me) ∈ RUV_cs fg U V; Ml ⊆ mon_loc fg ww21; Me ⊆ mon_env fg ww21⟧ ⟹ thesis) ⟹ thesis›*) by auto from REVSPLIT(1) (*‹ch = {#[entry fg q]#} + ceh›*) S_ENTRY_PAT[of "{#q#}", simplified] (*‹[entry fg q] ∈# ch ⟹ (v, mon_w fg w, {#q#}) ∈ S_cs fg (Suc 0)›*) have S_ENTRY: "(v, mon_w fg w, {#q#}) ∈ S_cs fg 1" by simp have MON_COND: "(mon_n fg u ∪ mon fg p) ∩ (Ml ∪ Me) = {}" proof (-) (*goal: ‹(mon_n fg (u::'n) ∪ mon fg (p::'p)) ∩ ((Ml::'m set) ∪ (Me::'m set)) = {}›*) from R_CONV(2) (*‹w21 = map le_rem_s ww21›*) have "mon_ww fg w21 = mon_loc fg ww21 ∪ mon_env fg ww21" by (simp add: mon_ww_of_le_rem (*‹mon_ww ?fg (map le_rem_s ?w) = mon_loc ?fg ?w ∪ mon_env ?fg ?w›*)) with IHAPP(2,3) (*‹Ml ⊆ mon_loc fg ww21› ‹Me ⊆ mon_env fg ww21›*) MON2N_LEQ(1) (*‹mon_ww fg w21 ⊆ mon_ww fg w2›*) MON_PU (*‹mon_env fg ww ∩ (mon fg p ∪ mon_n fg u) = {}›*) MON2_LEQ (*‹mon_ww fg (w2::('p, 'ba) label list list) ⊆ mon_env fg (ww::('p, 'ba) label list el_step list)›*) show "?thesis" (*goal: ‹(mon_n fg u ∪ mon fg p) ∩ (Ml ∪ Me) = {}›*) by blast qed from RUV_spawn[OF FS_FMT ( 2 ) FS_FMT ( 4 ) S_ENTRY _ IHAPP ( 1 ) MON_COND] (*‹q ∈# {#q#} ⟹ (u, mon fg p ∪ mon_w fg w, Ml ∪ Me) ∈ RUV_cs fg U V›*) have "(u, mon fg p ∪ mon_w fg w, Ml ∪ Me) ∈ RUV_cs fg U V" by simp moreover have "mon fg p ∪ mon_w fg w ⊆ mon_loc fg (ee#ww)" using FS_FMT(1) (*‹ee = LOC (LCall p # w)›*) by auto moreover have "Ml ∪ Me ⊆ mon_env fg (ee#ww)" using IHAPP(2,3) (*‹Ml ⊆ mon_loc fg ww21› ‹(Me::'m set) ⊆ mon_env fg (ww21::('p, 'ba) label list el_step list)›*) R_CONV(2) (*‹(w21::('p::type, 'ba::type) label list list) = map le_rem_s (ww21::('p::type, 'ba::type) label list el_step list)›*) MON2N_LEQ(1) (*‹mon_ww fg w21 ⊆ mon_ww fg w2›*) MON2_LEQ (*‹mon_ww fg w2 ⊆ mon_env fg ww›*) by (auto simp add: mon_ww_of_le_rem (*‹mon_ww ?fg (map le_rem_s ?w) = mon_loc ?fg ?w ∪ mon_env ?fg ?w›*)) ultimately show "?thesis" (*goal: ‹∃Ml Me. (u, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg (ee # ww) ∧ Me ⊆ mon_env fg (ee # ww)›*) by blast next (*goal: ‹⟦ce22' = add_mset s2' (ce22' - {#s2'#}); ce2' = ce21' + (ce22' - {#s2'#})⟧ ⟹ ∃Ml Me. (u, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg (ee # ww) ∧ Me ⊆ mon_env fg (ee # ww)›*) case right' (*‹(ce22'::'n::type list multiset) = add_mset (s2'::'n::type list) (ce22' - {#s2'#})› ‹ce2' = ce21' + (ce22' - {#s2'#})›*) from R_STACKS(2,3) (*‹atU_s U s1'› ‹atU_s V s2'›*) have ATUV: "atU U (add_mset sq' csp_q)" "atU V ce22'" apply - (*goals: 1. ‹⟦atU_s U s1'; atU_s V s2'⟧ ⟹ atU U (add_mset sq' csp_q)› 2. ‹⟦atU_s U s1'; atU_s V s2'⟧ ⟹ atU V ce22'› discuss goal 1*) apply - (*top goal: ‹⟦atU_s U s1'; atU_s V s2'⟧ ⟹ atU U (add_mset sq' csp_q)› and 1 goal remains*) apply (subst R_CONV(1)[symmetric] (*‹add_mset sq' csp_q = add_mset s1' ce21'›*)) (*top goal: ‹⟦atU_s U s1'; atU_s V s2'⟧ ⟹ atU U (add_mset sq' csp_q)› and 1 goal remains*) apply simp (*discuss goal 2*) apply (subst right'( (*‹ce22' = add_mset s2' (ce22' - {#s2'#})›*) 1)) (*goal: ‹⟦atU_s U s1'; atU_s V s2'⟧ ⟹ atU V ce22'›*) apply simp (*proven 2 subgoals*) . obtain q' and w22' and ce22e' where REVSPLIT': "[entry fg q'] ∈# ceh" "w22'≼w22" "ce22e' ⊆# ce22'" "atU V ce22e'" "({#[entry fg q']#},w22',ce22e')∈trcl (ntr fg)" (*goal: ‹(⋀q' w22' ce22e'. ⟦[entry fg q'] ∈# ceh; w22' ≼ w22; ce22e' ⊆# ce22'; atU V ce22e'; ({#[entry fg q']#}, w22', ce22e') ∈ trcl (ntr fg)⟧ ⟹ thesis) ⟹ thesis›*) proof (-) (*goal: ‹(⋀q' w22' ce22e'. ⟦[entry fg q'] ∈# ceh; w22' ≼ w22; ce22e' ⊆# ce22'; atU V ce22e'; ({#[entry fg q']#}, w22', ce22e') ∈ trcl (ntr fg)⟧ ⟹ thesis) ⟹ thesis›*) from ntr_reverse_split_atU[OF _ ATUV ( 2 ) REVSPLIT ( 7 )] (*‹valid fg ceh ⟹ ∃s w' c1'. s ∈# ceh ∧ w' ≼ w22 ∧ c1' ⊆# ce22' ∧ atU V c1' ∧ ({#s#}, w', c1') ∈ trcl (ntr fg)›*) ntrp_valid_preserve_s[OF SPLIT ( 1 ), simplified] (*‹valid fg (add_mset sh ch)›*) REVSPLIT(1) (*‹ch = {#[entry fg q]#} + ceh›*) obtain sq'' and w22' and ce22e' where "*": "sq'' ∈# ceh" "w22'≼w22" "ce22e' ⊆# ce22'" "atU V ce22e'" "({#sq''#},w22',ce22e')∈trcl (ntr fg)" (*goal: ‹(⋀(sq''::'n list) (w22'::('p, 'ba) label list list) ce22e'::'n list multiset. ⟦sq'' ∈# (ceh::'n list multiset); w22' ≼ (w22::('p, 'ba) label list list); ce22e' ⊆# (ce22'::'n list multiset); atU (V::'n set) ce22e'; ({#sq''#}, w22', ce22e') ∈ trcl (ntr fg)⟧ ⟹ thesis::bool) ⟹ thesis›*) by (auto simp add: valid_unconc (*‹valid ?fg (?c + ?c') = (valid ?fg ?c ∧ valid ?fg ?c' ∧ mon_c ?fg ?c ∩ mon_c ?fg ?c' = {})› ‹valid ?fg (add_mset ?x ?c') = (valid ?fg ?c' ∧ mon_s ?fg ?x ∩ mon_c ?fg ?c' = {})›*)) from CHFMT[of sq''] (*‹sq'' ∈# ch ⟹ ∃p u v. sq'' = [entry fg p] ∧ (u, Spawn p, v) ∈ edges fg ∧ initialproc fg p›*) REVSPLIT(1) (*‹ch = {#[entry fg q]#} + ceh›*) this(1) (*‹(sq''::'n::type list) ∈# (ceh::'n::type list multiset)›*) obtain q' where "sq''=[entry fg q']" (*goal: ‹(⋀q'. sq'' = [entry fg q'] ⟹ thesis) ⟹ thesis›*) by auto with "*" (*‹(sq''::'n list) ∈# (ceh::'n list multiset)› ‹w22' ≼ w22› ‹ce22e' ⊆# ce22'› ‹atU V ce22e'› ‹({#sq''#}, w22', ce22e') ∈ trcl (ntr fg)›*) show thesis using that (*‹⟦[entry fg ?q'] ∈# ceh; ?w22' ≼ w22; ?ce22e' ⊆# ce22'; atU V ?ce22e'; ({#[entry fg ?q']#}, ?w22', ?ce22e') ∈ trcl (ntr fg)⟧ ⟹ thesis›*) by blast qed from ntrs.gtr2gtrp[where c = "{#}", simplified, OF REVSPLIT' ( 5 )] (*‹(⋀s' ce' ww. ⟦ce22e' = add_mset s' ce'; w22' = map le_rem_s ww; (([entry fg q'], {#}), ww, s', ce') ∈ trcl (ntrp fg)⟧ ⟹ ?P) ⟹ ?P›*) obtain sq'' and ce22ee' and ww22' where R_CONV': "ce22e' = add_mset sq'' ce22ee'" "w22'=map le_rem_s ww22'" "(([entry fg q'],{#}),ww22',(sq'',ce22ee'))∈trcl (ntrp fg)" (*goal: ‹(⋀sq'' ce22ee' ww22'. ⟦ce22e' = add_mset sq'' ce22ee'; w22' = map le_rem_s ww22'; (([entry fg q'], {#}), ww22', sq'', ce22ee') ∈ trcl (ntrp fg)⟧ ⟹ thesis) ⟹ thesis›*) by blast from RU_sound[OF R_CONV ( 3 ) ATUV ( 1 )] (*‹∃Ml Me h. (entry fg q, Ml, Me, h) ∈ RU_cs fg U ∧ Ml ⊆ mon_loc fg ww21 ∧ Me ⊆ mon_env fg ww21 ∧ h ≤ αah (map (αnl fg) ww21)›*) obtain Ml and Me and h where RU: "(entry fg q, Ml, Me, h) ∈ RU_cs fg U" "Ml ⊆ mon_loc fg ww21" "Me ⊆ mon_env fg ww21" "h ≤ αah (map (αnl fg) ww21)" (*goal: ‹(⋀Ml Me h. ⟦(entry fg q, Ml, Me, h) ∈ RU_cs fg U; Ml ⊆ mon_loc fg ww21; Me ⊆ mon_env fg ww21; h ≤ αah (map (αnl fg) ww21)⟧ ⟹ thesis) ⟹ thesis›*) by blast from RU_sound[OF R_CONV' ( 3 ), of V] (*‹atU V (add_mset sq'' ce22ee') ⟹ ∃Ml Me h. (entry fg q', Ml, Me, h) ∈ RU_cs fg V ∧ Ml ⊆ mon_loc fg ww22' ∧ Me ⊆ mon_env fg ww22' ∧ h ≤ αah (map (αnl fg) ww22')›*) REVSPLIT'(4) (*‹atU (V::'n::type set) (ce22e'::'n::type list multiset)›*) R_CONV'(1) (*‹ce22e' = add_mset sq'' ce22ee'›*) obtain Ml' and Me' and h' where RV: "(entry fg q', Ml', Me', h') ∈ RU_cs fg V" "Ml' ⊆ mon_loc fg ww22'" "Me' ⊆ mon_env fg ww22'" "h' ≤ αah (map (αnl fg) ww22')" (*goal: ‹(⋀Ml' Me' h'. ⟦(entry fg q', Ml', Me', h') ∈ RU_cs fg V; Ml' ⊆ mon_loc fg ww22'; Me' ⊆ mon_env fg ww22'; h' ≤ αah (map (αnl fg) ww22')⟧ ⟹ thesis) ⟹ thesis›*) by auto from S_ENTRY_PAT[of "{#q#}+{#q'#}", simplified] (*‹{#[entry fg (q'::'p)], [entry fg (q::'p)]#} ⊆# (ch::'n list multiset) ⟹ (v::'n, mon_w fg (w::('p, 'ba) label list), {#q', q#}) ∈ S_cs fg (Suc (Suc (0::nat)))›*) REVSPLIT(1) (*‹ch = {#[entry fg q]#} + ceh›*) REVSPLIT'(1) (*‹[entry fg q'] ∈# ceh›*) have S_ENTRY: "(v, mon_w fg w, {#q#} + {#q'#}) ∈ S_cs fg (2::nat)" by (simp add: numerals (*‹Numeral1 = 1› ‹2 = Suc (Suc 0)›*)) have "(u, mon fg p ∪ mon_w fg w, Ml ∪ Me ∪ Ml' ∪ Me') ∈ RUV_cs fg U V" proof (rule RUV_split_ee[OF FS_FMT(2,4) S_ENTRY _ RU(1) RV(1)] (*‹⟦{#q#} + {#q'#} ⊆# {#q#} + {#q'#}; (mon_n fg u ∪ mon fg p) ∩ (Ml ∪ Me ∪ Ml' ∪ Me') = {}; h [*] h'⟧ ⟹ (u, mon fg p ∪ mon_w fg w, Ml ∪ Me ∪ Ml' ∪ Me') ∈ RUV_cs fg U V›*)) (*goals: 1. ‹{#q#} + {#q'#} ⊆# {#q#} + {#q'#}› 2. ‹(mon_n fg u ∪ mon fg p) ∩ (Ml ∪ Me ∪ Ml' ∪ Me') = {}› 3. ‹h [*] h'›*) from MON_PU (*‹mon_env fg ww ∩ (mon fg p ∪ mon_n fg u) = {}›*) MON2_LEQ (*‹mon_ww fg w2 ⊆ mon_env fg ww›*) MON2N_LEQ (*‹mon_ww fg w21 ⊆ mon_ww fg w2› ‹mon_ww fg (w22::('p, 'ba) label list list) ⊆ mon_ww fg (w2::('p, 'ba) label list list)›*) R_CONV(2) (*‹(w21::('p, 'ba) label list list) = map le_rem_s (ww21::('p, 'ba) label list el_step list)›*) R_CONV'(2) (*‹w22' = map le_rem_s ww22'›*) mon_ww_ileq[OF REVSPLIT' ( 2 ), of fg] (*‹mon_ww fg w22' ⊆ mon_ww fg w22›*) RU(2,3) (*‹Ml ⊆ mon_loc fg ww21› ‹Me ⊆ mon_env fg ww21›*) RV(2,3) (*‹Ml' ⊆ mon_loc fg ww22'› ‹Me' ⊆ mon_env fg ww22'›*) show "(mon_n fg u ∪ mon fg p) ∩ (Ml ∪ Me ∪ Ml' ∪ Me') = {}" apply (simp add: mon_ww_of_le_rem (*‹mon_ww (?fg::(?'b, ?'c, ?'d, ?'a, ?'e) flowgraph_rec_scheme) (map le_rem_s (?w::(?'c, ?'f) label list el_step list)) = mon_loc ?fg ?w ∪ mon_env ?fg ?w›*)) (*goal: ‹(mon_n fg u ∪ mon fg p) ∩ (Ml ∪ Me ∪ Ml' ∪ Me') = {}›*) by blast next (*goals: 1. ‹{#q#} + {#q'#} ⊆# {#q#} + {#q'#}› 2. ‹h [*] h'›*) from ah_interleavable1[OF REVSPLIT ( 3 )] (*‹αah (map (αn fg) w21) [*] αah (map (αn fg) w22)›*) have "αah (map (αn fg) w21) [*] αah (map (αn fg) w22)" . thus "h [*] h'" proof (erule_tac ah_leq_il (*‹⟦?h1.0 [*] ?h2.0; ?h1' ≤ ?h1.0; ?h2' ≤ ?h2.0⟧ ⟹ ?h1' [*] ?h2'›*)) (*goals: 1. ‹h ≤ αah (map (αn fg) w21)› 2. ‹h' ≤ αah (map (αn fg) w22)›*) note RU(4) (*‹h ≤ αah (map (αnl fg) ww21)›*) also (*calculation: ‹h ≤ αah (map (αnl fg) ww21)›*) have "map (αnl fg) ww21 ≼ map (αn fg) w21" using R_CONV(2) (*‹w21 = map le_rem_s ww21›*) by (simp add: αn_αnl (*‹αn ?fg ∘ le_rem_s = αnl ?fg›*)) hence "αah (map (αnl fg) ww21) ≤ αah (map (αn fg) w21)" by (rule αah_ileq (*‹?w1.0 ≼ ?w2.0 ⟹ αah ?w1.0 ≤ αah ?w2.0›*)) finally (*calculation: ‹h ≤ αah (map (αn fg) w21)›*) show "h ≤ αah (map (αn fg) w21)" . next (*goal: ‹h' ≤ αah (map (αn fg) w22)›*) note RV(4) (*‹h' ≤ αah (map (αnl fg) ww22')›*) also (*calculation: ‹h' ≤ αah (map (αnl fg) ww22')›*) have "map (αnl fg) ww22' ≼ map (αn fg) w22" using R_CONV'(2) (*‹w22' = map le_rem_s ww22'›*) REVSPLIT'(2) (*‹(w22'::('p, 'ba) label list list) ≼ (w22::('p, 'ba) label list list)›*) by (simp add: αn_αnl[symmetric] (*‹αnl ?fg = αn ?fg ∘ le_rem_s›*) le_list_map (*‹?xs ≼ ?ys ⟹ map ?f ?xs ≼ map ?f ?ys›*) map_map[symmetric] (*‹map (?f ∘ ?g) ?xs = map ?f (map ?g ?xs)›*) del: map_map (*‹map ?f (map ?g ?xs) = map (?f ∘ ?g) ?xs›*)) hence "αah (map (αnl fg) ww22') ≤ αah (map (αn fg) w22)" by (rule αah_ileq (*‹?w1.0 ≼ ?w2.0 ⟹ αah ?w1.0 ≤ αah ?w2.0›*)) finally (*calculation: ‹h' ≤ αah (map (αn fg) w22)›*) show "h' ≤ αah (map (αn fg) w22)" . qed qed (simp) (*solved the remaining goal: ‹{#q#} + {#q'#} ⊆# {#q#} + {#q'#}›*) moreover have "mon fg p ∪ mon_w fg w ⊆ mon_loc fg (ee#ww)" using FS_FMT(1) (*‹ee = LOC (LCall p # w)›*) by auto moreover have "Ml ∪ Me ∪ Ml' ∪ Me' ⊆ mon_env fg (ee#ww)" using RV(2,3) (*‹Ml' ⊆ mon_loc fg ww22'› ‹Me' ⊆ mon_env fg ww22'›*) RU(2,3) (*‹Ml ⊆ mon_loc fg ww21› ‹Me ⊆ mon_env fg ww21›*) mon_ww_ileq[OF REVSPLIT' ( 2 ), of fg] (*‹mon_ww fg w22' ⊆ mon_ww fg w22›*) MON2N_LEQ (*‹mon_ww fg w21 ⊆ mon_ww fg w2› ‹mon_ww fg w22 ⊆ mon_ww fg w2›*) R_CONV(2) (*‹w21 = map le_rem_s ww21›*) R_CONV'(2) (*‹w22' = map le_rem_s ww22'›*) MON2_LEQ (*‹mon_ww fg w2 ⊆ mon_env fg ww›*) apply (simp add: mon_ww_of_le_rem (*‹mon_ww ?fg (map le_rem_s ?w) = mon_loc ?fg ?w ∪ mon_env ?fg ?w›*)) (*goal: ‹(Ml::'m::type set) ∪ (Me::'m::type set) ∪ (Ml'::'m::type set) ∪ (Me'::'m::type set) ⊆ mon_env fg ((ee::('p::type, 'ba::type) label list el_step) # (ww::('p::type, 'ba::type) label list el_step list))›*) by blast ultimately show "?thesis" (*goal: ‹∃Ml Me. (u, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg (ee # ww) ∧ Me ⊆ mon_env fg (ee # ww)›*) by blast qed next (*goals: 1. ‹⟦atU U ({#s'#} + c1'); atU V c2'⟧ ⟹ ∃Ml Me. (u, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg (ee # ww) ∧ Me ⊆ mon_env fg (ee # ww)› 2. ‹⟦atU V ({#s'#} + c1'); atU U c2'⟧ ⟹ ∃Ml Me. (u, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg (ee # ww) ∧ Me ⊆ mon_env fg (ee # ww)›*) case lr (*‹atU (U::'n set) ({#s'::'n list#} + (c1'::'n list multiset))› ‹atU (V::'n::type set) (c2'::'n::type list multiset)›*) from RU_sound[OF DECOMP_LOC ( 2 ), of U] (*‹atU U (add_mset (v' # rr) c1') ⟹ ∃Ml Me h. (v, Ml, Me, h) ∈ RU_cs fg U ∧ Ml ⊆ mon_loc fg w1 ∧ Me ⊆ mon_env fg w1 ∧ h ≤ αah (map (αnl fg) w1)›*) lr(1) (*‹atU (U::'n::type set) ({#s'::'n::type list#} + (c1'::'n::type list multiset))›*) DECOMP_LOC(1) (*‹s' = v' # rr @ [u']›*) obtain Ml and Me and h where RU: "(v, Ml, Me, h) ∈ RU_cs fg U" "Ml ⊆ mon_loc fg w1" "Me ⊆ mon_env fg w1" "h ≤ αah (map (αnl fg) w1)" (*goal: ‹(⋀Ml Me h. ⟦(v, Ml, Me, h) ∈ RU_cs fg U; Ml ⊆ mon_loc fg w1; Me ⊆ mon_env fg w1; h ≤ αah (map (αnl fg) w1)⟧ ⟹ thesis) ⟹ thesis›*) by auto obtain Ml' and Me' and h' and q' where RV: "[entry fg q'] ∈# ch" "(entry fg q', Ml', Me', h') ∈ RU_cs fg V" "Ml' ⊆ mon_ww fg w2" "Me' ⊆ mon_ww fg w2" "h' ≤ αah (map (αn fg) w2)" (*goal: ‹(⋀q' Ml' Me' h'. ⟦[entry fg q'] ∈# ch; (entry fg q', Ml', Me', h') ∈ RU_cs fg V; Ml' ⊆ mon_ww fg w2; Me' ⊆ mon_ww fg w2; h' ≤ αah (map (αn fg) w2)⟧ ⟹ thesis) ⟹ thesis›*) proof (-) (*goal: ‹(⋀(q'::'p) (Ml'::'m set) (Me'::'m set) h'::'m ⇒ 'm set. ⟦[entry fg q'] ∈# (ch::'n list multiset); (entry fg q', Ml', Me', h') ∈ RU_cs fg (V::'n set); Ml' ⊆ mon_ww fg (w2::('p, 'ba) label list list); Me' ⊆ mon_ww fg w2; h' ≤ αah (map (αn fg) w2)⟧ ⟹ thesis::bool) ⟹ thesis›*) obtain q' and w2' and c2i' where REVSPLIT: "[entry fg q'] ∈# ch" "w2'≼w2" "c2i' ⊆# c2'" "atU V c2i'" "({#[entry fg q']#},w2',c2i')∈trcl (ntr fg)" (*goal: ‹(⋀q' w2' c2i'. ⟦[entry fg q'] ∈# ch; w2' ≼ w2; c2i' ⊆# c2'; atU V c2i'; ({#[entry fg q']#}, w2', c2i') ∈ trcl (ntr fg)⟧ ⟹ thesis) ⟹ thesis›*) using ntr_reverse_split_atU[OF _ lr ( 2 ) LESPLIT ( 4 )] (*‹valid fg (ch::'n::type list multiset) ⟹ ∃(s::'n::type list) (w'::('p::type, 'ba::type) label list list) c1'::'n::type list multiset. s ∈# ch ∧ w' ≼ (w2::('p::type, 'ba::type) label list list) ∧ c1' ⊆# (c2'::'n::type list multiset) ∧ atU (V::'n::type set) c1' ∧ ({#s#}, w', c1') ∈ trcl (ntr fg)›*) ntrp_valid_preserve_s[OF SPLIT ( 1 ), simplified] (*‹valid fg (add_mset sh ch)›*) CHFMT (*‹?s ∈# ch ⟹ ∃p u v. ?s = [entry fg p] ∧ (u, Spawn p, v) ∈ edges fg ∧ initialproc fg p›*) apply (simp add: valid_unconc (*‹valid ?fg (?c + ?c') = (valid ?fg ?c ∧ valid ?fg ?c' ∧ mon_c ?fg ?c ∩ mon_c ?fg ?c' = {})› ‹valid ?fg (add_mset ?x ?c') = (valid ?fg ?c' ∧ mon_s ?fg ?x ∩ mon_c ?fg ?c' = {})›*)) (*goal: ‹(⋀q' w2' c2i'. ⟦[entry fg q'] ∈# ch; w2' ≼ w2; c2i' ⊆# c2'; atU V c2i'; ({#[entry fg q']#}, w2', c2i') ∈ trcl (ntr fg)⟧ ⟹ thesis) ⟹ thesis›*) by blast from ntrs.gtr2gtrp[where c = "{#}", simplified, OF REVSPLIT ( 5 )] (*‹(⋀s' ce' ww. ⟦c2i' = add_mset s' ce'; w2' = map le_rem_s ww; (([entry fg q'], {#}), ww, s', ce') ∈ trcl (ntrp fg)⟧ ⟹ ?P) ⟹ ?P›*) obtain s2i' and c2ie' and ww2' where R_CONV: "c2i'=add_mset s2i' c2ie'" "w2'=map le_rem_s ww2'" "(([entry fg q'], {#}), ww2', s2i', c2ie') ∈ trcl (ntrp fg)" (*goal: ‹(⋀s2i' c2ie' ww2'. ⟦c2i' = add_mset s2i' c2ie'; w2' = map le_rem_s ww2'; (([entry fg q'], {#}), ww2', s2i', c2ie') ∈ trcl (ntrp fg)⟧ ⟹ thesis) ⟹ thesis›*) . from RU_sound[OF R_CONV ( 3 ), of V] (*‹atU (V::'n set) (add_mset (s2i'::'n list) (c2ie'::'n list multiset)) ⟹ ∃(Ml::'m set) (Me::'m set) h::'m ⇒ 'm set. (entry fg (q'::'p), Ml, Me, h) ∈ RU_cs fg V ∧ Ml ⊆ mon_loc fg (ww2'::('p, 'ba) label list el_step list) ∧ Me ⊆ mon_env fg ww2' ∧ h ≤ αah (map (αnl fg) ww2')›*) REVSPLIT(4) (*‹atU V c2i'›*) R_CONV(1) (*‹c2i' = add_mset s2i' c2ie'›*) obtain Ml' and Me' and h' where RV: "(entry fg q', Ml', Me', h') ∈ RU_cs fg V" "Ml' ⊆ mon_loc fg ww2'" "Me' ⊆ mon_env fg ww2'" "h' ≤ αah (map (αnl fg) ww2')" (*goal: ‹(⋀Ml' Me' h'. ⟦(entry fg q', Ml', Me', h') ∈ RU_cs fg V; Ml' ⊆ mon_loc fg ww2'; Me' ⊆ mon_env fg ww2'; h' ≤ αah (map (αnl fg) ww2')⟧ ⟹ thesis) ⟹ thesis›*) by auto moreover have "mon_loc fg ww2' ⊆ mon_ww fg w2" "mon_env fg ww2' ⊆ mon_ww fg w2" using mon_ww_ileq[OF REVSPLIT ( 2 ), of fg] (*‹mon_ww fg w2' ⊆ mon_ww fg w2›*) R_CONV(2) (*‹(w2'::('p::type, 'ba::type) label list list) = map le_rem_s (ww2'::('p::type, 'ba::type) label list el_step list)›*) apply - (*goals: 1. ‹⟦mon_ww fg w2' ⊆ mon_ww fg w2; w2' = map le_rem_s ww2'⟧ ⟹ mon_loc fg ww2' ⊆ mon_ww fg w2› 2. ‹⟦mon_ww fg w2' ⊆ mon_ww fg w2; w2' = map le_rem_s ww2'⟧ ⟹ mon_env fg ww2' ⊆ mon_ww fg w2› discuss goal 1*) apply ((auto simp add: mon_ww_of_le_rem (*‹mon_ww ?fg (map le_rem_s ?w) = mon_loc ?fg ?w ∪ mon_env ?fg ?w›*))[1]) (*discuss goal 2*) apply ((auto simp add: mon_ww_of_le_rem (*‹mon_ww ?fg (map le_rem_s ?w) = mon_loc ?fg ?w ∪ mon_env ?fg ?w›*))[1]) (*proven 2 subgoals*) . moreover have "αah (map (αnl fg) ww2') ≤ αah (map (αn fg) w2)" using REVSPLIT(2) (*‹w2' ≼ w2›*) R_CONV(2) (*‹w2' = map le_rem_s ww2'›*) by (auto simp add: αn_αnl[symmetric] (*‹αnl ?fg = αn ?fg ∘ le_rem_s›*) le_list_map (*‹?xs ≼ ?ys ⟹ map ?f ?xs ≼ map ?f ?ys›*) map_map[symmetric] (*‹map (?f ∘ ?g) ?xs = map ?f (map ?g ?xs)›*) simp del: map_map (*‹map ?f (map ?g ?xs) = map (?f ∘ ?g) ?xs›*) intro: αah_ileq (*‹?w1.0 ≼ ?w2.0 ⟹ αah ?w1.0 ≤ αah ?w2.0›*) del: predicate2I (*‹(⋀x y. ?P x y ⟹ ?Q x y) ⟹ ?P ≤ ?Q›*)) ultimately show thesis using that (*‹⟦[entry fg (?q'::'p)] ∈# (ch::'n list multiset); (entry fg ?q', ?Ml'::'m set, ?Me'::'m set, ?h'::'m ⇒ 'm set) ∈ RU_cs fg (V::'n set); ?Ml' ⊆ mon_ww fg (w2::('p, 'ba) label list list); ?Me' ⊆ mon_ww fg w2; ?h' ≤ αah (map (αn fg) w2)⟧ ⟹ thesis::bool›*) REVSPLIT(1) (*‹[entry fg (q'::'p)] ∈# (ch::'n list multiset)›*) by (blast intro: order_trans (*‹⟦?x ≤ ?y; ?y ≤ ?z⟧ ⟹ ?x ≤ ?z›*)) qed from S_ENTRY_PAT[of "{#q'#}", simplified] (*‹[entry fg q'] ∈# ch ⟹ (v, mon_w fg w, {#q'#}) ∈ S_cs fg (Suc 0)›*) RV(1) (*‹[entry fg q'] ∈# ch›*) have S_ENTRY: "(v, mon_w fg w, {#q'#}) ∈ S_cs fg 1" by simp have "(u, mon fg p ∪ mon_w fg w ∪ Ml, Me ∪ Ml' ∪ Me') ∈ RUV_cs fg U V" proof (rule RUV_split_le[OF FS_FMT(2,4) S_ENTRY _ RU(1) RV(2)] (*‹⟦(q'::'p) ∈# {#q'#}; (mon_n fg (u::'n) ∪ mon fg (p::'p)) ∩ ((Me::'m set) ∪ (Ml'::'m set) ∪ (Me'::'m set)) = {}; (h::'m ⇒ 'm set) [*] (h'::'m ⇒ 'm set)⟧ ⟹ (u, mon fg p ∪ mon_w fg (w::('p, 'ba) label list) ∪ (Ml::'m set), Me ∪ Ml' ∪ Me') ∈ RUV_cs fg (U::'n set) (V::'n set)›*)) (*goals: 1. ‹q' ∈# {#q'#}› 2. ‹(mon_n fg u ∪ mon fg p) ∩ (Me ∪ Ml' ∪ Me') = {}› 3. ‹h [*] h'›*) from MON_PU (*‹mon_env fg ww ∩ (mon fg p ∪ mon_n fg u) = {}›*) MON1_LEQ (*‹mon_loc fg (w1::('p::type, 'ba::type) label list el_step list) ⊆ mon_loc fg (ww::('p::type, 'ba::type) label list el_step list)› ‹mon_env fg w1 ⊆ mon_env fg ww›*) MON2_LEQ (*‹mon_ww fg w2 ⊆ mon_env fg ww›*) RU(3) (*‹Me ⊆ mon_env fg w1›*) RV(3,4) (*‹Ml' ⊆ mon_ww fg w2› ‹Me' ⊆ mon_ww fg w2›*) show "(mon_n fg u ∪ mon fg p) ∩ (Me ∪ Ml' ∪ Me') = {}" by blast next (*goals: 1. ‹q' ∈# {#q'#}› 2. ‹h [*] h'›*) from ah_interleavable1[OF LESPLIT ( 1 )] (*‹αah (map (αnl fg) w1) [*] αah (map (αnl fg) (map ENV w2))›*) have "αah (map (αnl fg) w1) [*] αah (map (αn fg) w2)" by simp thus "h [*] h'" using RU(4) (*‹h ≤ αah (map (αnl fg) w1)›*) RV(5) (*‹h' ≤ αah (map (αn fg) w2)›*) by (auto elim: ah_leq_il (*‹⟦?h1.0 [*] ?h2.0; ?h1' ≤ ?h1.0; ?h2' ≤ ?h2.0⟧ ⟹ ?h1' [*] ?h2'›*)) qed (simp) (*solved the remaining goal: ‹q' ∈# {#q'#}›*) moreover have "mon fg p ∪ mon_w fg w ∪ Ml ⊆ mon_loc fg (ee # ww)" using FS_FMT(1) (*‹ee = LOC (LCall p # w)›*) MON1_LEQ (*‹mon_loc fg w1 ⊆ mon_loc fg ww› ‹mon_env fg w1 ⊆ mon_env fg ww›*) RU(2) (*‹Ml ⊆ mon_loc fg w1›*) apply simp (*goal: ‹mon fg p ∪ mon_w fg w ∪ Ml ⊆ mon_loc fg (ee # ww)›*) by blast moreover have "Me ∪ Ml' ∪ Me' ⊆ mon_env fg (ee # ww)" using MON1_LEQ (*‹mon_loc fg w1 ⊆ mon_loc fg ww› ‹mon_env fg w1 ⊆ mon_env fg ww›*) MON2_LEQ (*‹mon_ww fg (w2::('p, 'ba) label list list) ⊆ mon_env fg (ww::('p, 'ba) label list el_step list)›*) RU(3) (*‹Me ⊆ mon_env fg w1›*) RV(3,4) (*‹Ml' ⊆ mon_ww fg w2› ‹Me' ⊆ mon_ww fg w2›*) apply simp (*goal: ‹Me ∪ Ml' ∪ Me' ⊆ mon_env fg (ee # ww)›*) by blast ultimately show "?thesis" (*goal: ‹∃Ml Me. (u, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg (ee # ww) ∧ Me ⊆ mon_env fg (ee # ww)›*) by blast next (*goal: ‹⟦atU V ({#s'#} + c1'); atU U c2'⟧ ⟹ ∃Ml Me. (u, Ml, Me) ∈ RUV_cs fg U V ∧ Ml ⊆ mon_loc fg (ee # ww) ∧ Me ⊆ mon_env fg (ee # ww)›*) case rl (*‹atU V ({#s'#} + c1')› ‹atU U c2'›*) from RU_sound[OF DECOMP_LOC ( 2 ), of V] (*‹atU V (add_mset (v' # rr) c1') ⟹ ∃Ml Me h. (v, Ml, Me, h) ∈ RU_cs fg V ∧ Ml ⊆ mon_loc fg w1 ∧ Me ⊆ mon_env fg w1 ∧ h ≤ αah (map (αnl fg) w1)›*) rl(1) (*‹atU (V::'n set) ({#s'::'n list#} + (c1'::'n list multiset))›*) DECOMP_LOC(1) (*‹s' = v' # rr @ [u']›*) obtain Ml and Me and h where RV: "(v, Ml, Me, h) ∈ RU_cs fg V" "Ml ⊆ mon_loc fg w1" "Me ⊆ mon_env fg w1" "h ≤ αah (map (αnl fg) w1)" (*goal: ‹(⋀Ml Me h. ⟦(v, Ml, Me, h) ∈ RU_cs fg V; Ml ⊆ mon_loc fg w1; Me ⊆ mon_env fg w1; h ≤ αah (map (αnl fg) w1)⟧ ⟹ thesis) ⟹ thesis›*) by auto obtain Ml' and Me' and h' and q' where RU: "[entry fg q'] ∈# ch" "(entry fg q', Ml', Me', h') ∈ RU_cs fg U" "Ml' ⊆ mon_ww fg w2" "Me' ⊆ mon_ww fg w2" "h' ≤ αah (map (αn fg) w2)" (*goal: ‹(⋀q' Ml' Me' h'. ⟦[entry fg q'] ∈# ch; (entry fg q', Ml', Me', h') ∈ RU_cs fg U; Ml' ⊆ mon_ww fg w2; Me' ⊆ mon_ww fg w2; h' ≤ αah (map (αn fg) w2)⟧ ⟹ thesis) ⟹ thesis›*) proof (-) (*goal: ‹(⋀q' Ml' Me' h'. ⟦[entry fg q'] ∈# ch; (entry fg q', Ml', Me', h') ∈ RU_cs fg U; Ml' ⊆ mon_ww fg w2; Me' ⊆ mon_ww fg w2; h' ≤ αah (map (αn fg) w2)⟧ ⟹ thesis) ⟹ thesis›*) obtain q' and w2' and c2i' where REVSPLIT: "[entry fg q'] ∈# ch" "w2'≼w2" "c2i' ⊆# c2'" "atU U c2i'" "({#[entry fg q']#},w2',c2i')∈trcl (ntr fg)" (*goal: ‹(⋀q' w2' c2i'. ⟦[entry fg q'] ∈# ch; w2' ≼ w2; c2i' ⊆# c2'; atU U c2i'; ({#[entry fg q']#}, w2', c2i') ∈ trcl (ntr fg)⟧ ⟹ thesis) ⟹ thesis›*) using ntr_reverse_split_atU[OF _ rl ( 2 ) LESPLIT ( 4 )] (*‹valid fg ch ⟹ ∃s w' c1'. s ∈# ch ∧ w' ≼ w2 ∧ c1' ⊆# c2' ∧ atU U c1' ∧ ({#s#}, w', c1') ∈ trcl (ntr fg)›*) ntrp_valid_preserve_s[OF SPLIT ( 1 ), simplified] (*‹valid fg (add_mset sh ch)›*) CHFMT (*‹?s ∈# ch ⟹ ∃p u v. ?s = [entry fg p] ∧ (u, Spawn p, v) ∈ edges fg ∧ initialproc fg p›*) apply (simp add: valid_unconc (*‹valid ?fg (?c + ?c') = (valid ?fg ?c ∧ valid ?fg ?c' ∧ mon_c ?fg ?c ∩ mon_c ?fg ?c' = {})› ‹valid ?fg (add_mset ?x ?c') = (valid ?fg ?c' ∧ mon_s ?fg ?x ∩ mon_c ?fg ?c' = {})›*)) (*goal: ‹(⋀q' w2' c2i'. ⟦[entry fg q'] ∈# ch; w2' ≼ w2; c2i' ⊆# c2'; atU U c2i'; ({#[entry fg q']#}, w2', c2i') ∈ trcl (ntr fg)⟧ ⟹ thesis) ⟹ thesis›*) by blast from ntrs.gtr2gtrp[where c = "{#}", simplified, OF REVSPLIT ( 5 )] (*‹(⋀s' ce' ww. ⟦c2i' = add_mset s' ce'; w2' = map le_rem_s ww; (([entry fg q'], {#}), ww, s', ce') ∈ trcl (ntrp fg)⟧ ⟹ ?P) ⟹ ?P›*) obtain s2i' and c2ie' and ww2' where R_CONV: "c2i'=add_mset s2i' c2ie'" "w2'=map le_rem_s ww2'" "(([entry fg q'], {#}), ww2', s2i', c2ie') ∈ trcl (ntrp fg)" (*goal: ‹(⋀s2i' c2ie' ww2'. ⟦c2i' = add_mset s2i' c2ie'; w2' = map le_rem_s ww2'; (([entry fg q'], {#}), ww2', s2i', c2ie') ∈ trcl (ntrp fg)⟧ ⟹ thesis) ⟹ thesis›*) . from RU_sound[OF R_CONV ( 3 ), of U] (*‹atU U (add_mset s2i' c2ie') ⟹ ∃Ml Me h. (entry fg q', Ml, Me, h) ∈ RU_cs fg U ∧ Ml ⊆ mon_loc fg ww2' ∧ Me ⊆ mon_env fg ww2' ∧ h ≤ αah (map (αnl fg) ww2')›*) REVSPLIT(4) (*‹atU (U::'n set) (c2i'::'n list multiset)›*) R_CONV(1) (*‹c2i' = add_mset s2i' c2ie'›*) obtain Ml' and Me' and h' where RU: "(entry fg q', Ml', Me', h') ∈ RU_cs fg U" "Ml' ⊆ mon_loc fg ww2'" "Me' ⊆ mon_env fg ww2'" "h' ≤ αah (map (αnl fg) ww2')" (*goal: ‹(⋀Ml' Me' h'. ⟦(entry fg q', Ml', Me', h') ∈ RU_cs fg U; Ml' ⊆ mon_loc fg ww2'; Me' ⊆ mon_env fg ww2'; h' ≤ αah (map (αnl fg) ww2')⟧ ⟹ thesis) ⟹ thesis›*) by auto moreover have "mon_loc fg ww2' ⊆ mon_ww fg w2" "mon_env fg ww2' ⊆ mon_ww fg w2" using mon_ww_ileq[OF REVSPLIT ( 2 ), of fg] (*‹mon_ww fg w2' ⊆ mon_ww fg w2›*) R_CONV(2) (*‹w2' = map le_rem_s ww2'›*) apply - (*goals: 1. ‹⟦mon_ww fg w2' ⊆ mon_ww fg w2; w2' = map le_rem_s ww2'⟧ ⟹ mon_loc fg ww2' ⊆ mon_ww fg w2› 2. ‹⟦mon_ww fg w2' ⊆ mon_ww fg w2; w2' = map le_rem_s ww2'⟧ ⟹ mon_env fg ww2' ⊆ mon_ww fg w2› discuss goal 1*) apply ((auto simp add: mon_ww_of_le_rem (*‹mon_ww ?fg (map le_rem_s ?w) = mon_loc ?fg ?w ∪ mon_env ?fg ?w›*))[1]) (*discuss goal 2*) apply ((auto simp add: mon_ww_of_le_rem (*‹mon_ww ?fg (map le_rem_s ?w) = mon_loc ?fg ?w ∪ mon_env ?fg ?w›*))[1]) (*proven 2 subgoals*) . moreover have "αah (map (αnl fg) ww2') ≤ αah (map (αn fg) w2)" using REVSPLIT(2) (*‹w2' ≼ w2›*) R_CONV(2) (*‹w2' = map le_rem_s ww2'›*) by (auto simp add: αn_αnl[symmetric] (*‹αnl ?fg = αn ?fg ∘ le_rem_s›*) le_list_map (*‹?xs ≼ ?ys ⟹ map ?f ?xs ≼ map ?f ?ys›*) map_map[symmetric] (*‹map (?f ∘ ?g) ?xs = map ?f (map ?g ?xs)›*) simp del: map_map (*‹map ?f (map ?g ?xs) = map (?f ∘ ?g) ?xs›*) intro: αah_ileq (*‹?w1.0 ≼ ?w2.0 ⟹ αah ?w1.0 ≤ αah ?w2.0›*) del: predicate2I (*‹(⋀x y. ?P x y ⟹ ?Q x y) ⟹ ?P ≤ ?Q›*)) ultimately show thesis using that (*‹⟦[entry fg ?q'] ∈# ch; (entry fg ?q', ?Ml', ?Me', ?h') ∈ RU_cs fg U; ?Ml' ⊆ mon_ww fg w2; ?Me' ⊆ mon_ww fg w2; ?h' ≤ αah (map (αn fg) w2)⟧ ⟹ thesis›*) REVSPLIT(1) (*‹[entry fg q'] ∈# ch›*) by (blast intro: order_trans (*‹⟦?x ≤ ?y; ?y ≤ ?z⟧ ⟹ ?x ≤ ?z›*)) qed from S_ENTRY_PAT[of "{#q'#}", simplified] (*‹[entry fg q'] ∈# ch ⟹ (v, mon_w fg w, {#q'#}) ∈ S_cs fg (Suc 0)›*) RU(1) (*‹[entry fg q'] ∈# ch›*) have S_ENTRY: "(v, mon_w fg w, {#q'#}) ∈ S_cs fg 1" by simp have "(u, mon fg p ∪ mon_w fg w ∪ Ml, Me ∪ Ml' ∪ Me') ∈ RUV_cs fg U V" proof (rule RUV_split_el[OF FS_FMT(2,4) S_ENTRY _ RV(1) RU(2)] (*‹⟦q' ∈# {#q'#}; (mon_n fg u ∪ mon fg p) ∩ (Me ∪ Ml' ∪ Me') = {}; h [*] h'⟧ ⟹ (u, mon fg p ∪ mon_w fg w ∪ Ml, Me ∪ Ml' ∪ Me') ∈ RUV_cs fg U V›*)) (*goals: 1. ‹(q'::'p) ∈# {#q'#}› 2. ‹(mon_n fg (u::'n) ∪ mon fg (p::'p)) ∩ ((Me::'m set) ∪ (Ml'::'m set) ∪ (Me'::'m set)) = {}› 3. ‹(h::'m ⇒ 'm set) [*] (h'::'m ⇒ 'm set)›*) from MON_PU (*‹mon_env fg ww ∩ (mon fg p ∪ mon_n fg u) = {}›*) MON1_LEQ (*‹mon_loc fg w1 ⊆ mon_loc fg ww› ‹mon_env fg w1 ⊆ mon_env fg ww›*) MON2_LEQ (*‹mon_ww fg w2 ⊆ mon_env fg ww›*) RV(3) (*‹Me ⊆ mon_env fg w1›*) RU(3,4) (*‹Ml' ⊆ mon_ww fg w2› ‹Me' ⊆ mon_ww fg w2›*) show "(mon_n fg u ∪ mon fg p) ∩ (Me ∪ Ml' ∪ Me') = {}" by blast next (*goals: 1. ‹q' ∈# {#q'#}› 2. ‹h [*] h'›*) from ah_interleavable1[OF LESPLIT ( 1 )] (*‹αah (map (αnl fg) w1) [*] αah (map (αnl fg) (map ENV w2))›*) have "αah (map (αnl fg) w1) [*] αah (map (αn fg) w2)" by simp thus "h [*] h'" using RV(4) (*‹h ≤ αah (map (αnl fg) w1)›*) RU(5) (*‹h' ≤ αah (map (αn fg) w2)›*) by (auto elim: ah_leq_il (*‹⟦?h1.0 [*] ?h2.0; ?h1' ≤ ?h1.0; ?h2' ≤ ?h2.0⟧ ⟹ ?h1' [*] ?h2'›*)) qed (simp) (*solved the remaining goal: ‹(q'::'p) ∈# {#q'#}›*) moreover have "mon fg p ∪ mon_w fg w ∪ Ml ⊆ mon_loc fg (ee # ww)" using FS_FMT(1) (*‹ee = LOC (LCall p # w)›*) MON1_LEQ (*‹mon_loc fg w1 ⊆ mon_loc fg ww› ‹mon_env fg (w1::('p, 'ba) label list el_step list) ⊆ mon_env fg (ww::('p, 'ba) label list el_step list)›*) RV(2) (*‹(Ml::'m set) ⊆ mon_loc fg (w1::('p, 'ba) label list el_step list)›*) apply simp (*goal: ‹mon fg p ∪ mon_w fg w ∪ Ml ⊆ mon_loc fg (ee # ww)›*) by blast moreover have "Me ∪ Ml' ∪ Me' ⊆ mon_env fg (ee # ww)" using MON1_LEQ (*‹mon_loc fg w1 ⊆ mon_loc fg ww› ‹mon_env fg (w1::('p, 'ba) label list el_step list) ⊆ mon_env fg (ww::('p, 'ba) label list el_step list)›*) MON2_LEQ (*‹mon_ww fg w2 ⊆ mon_env fg ww›*) RV(3) (*‹Me ⊆ mon_env fg w1›*) RU(3,4) (*‹Ml' ⊆ mon_ww fg w2› ‹Me' ⊆ mon_ww fg w2›*) apply simp (*goal: ‹(Me::'m set) ∪ (Ml'::'m set) ∪ (Me'::'m set) ⊆ mon_env fg ((ee::('p, 'ba) label list el_step) # (ww::('p, 'ba) label list el_step list))›*) by blast ultimately show "?thesis" (*goal: ‹∃(Ml::'m set) Me::'m set. (u::'n, Ml, Me) ∈ RUV_cs fg (U::'n set) (V::'n set) ∧ Ml ⊆ mon_loc fg ((ee::('p, 'ba) label list el_step) # (ww::('p, 'ba) label list el_step list)) ∧ Me ⊆ mon_env fg (ee # ww)›*) by blast qed qed lemma (in flowgraph) RUV_precise: "(u,Ml,Me)∈RUV_cs fg U V ⟹ ∃w s' c'. (([u],{#}),w,(s',c'))∈trcl (ntrp fg) ∧ atUV U V ({#s'#}+c') ∧ mon_loc fg w = Ml ∧ mon_env fg w = Me" sorry end
{ "path": "afp-2025-02-12/thys/Program-Conflict-Analysis/ConstraintSystems.thy", "repo": "afp-2025-02-12", "sha": "2e0466eea88b074d00a31640566d764623ed91ac02d131e69ae2237e4940682b" }
section "Proof Terms and proof checker" theory ProofTerm imports Term Logic Term_Subst SortConstants EqualityProof begin (* Move *) type_synonym tyinst = "(variable × sort) × typ" type_synonym tinst = "(variable × typ) × term" datatype proofterm = PAxm "term" "tyinst list" | PBound nat | Abst "typ" proofterm | AbsP "term" proofterm | Appt proofterm "term" | AppP proofterm proofterm | OfClass "typ" "class" | Hyp "term" (* For debbuging, move to code gen or seperate theory? *) fun depth :: "proofterm ⇒ nat" where "depth (Abst _ P) = Suc (depth P)" | "depth (AbsP _ P) = Suc (depth P)" | "depth (Appt P _) = Suc (depth P)" | "depth (AppP P1 P2) = Suc (max (depth P1) (depth P2))" | "depth _ = 1" fun size :: "proofterm ⇒ nat" where "size (Abst _ P) = Suc (size P)" | "size (AbsP _ P) = Suc (size P)" | "size (Appt P _) = Suc (size P)" | "size (AppP P1 P2) = Suc (size P1 + size P2)" | "size _ = 1" lemma "depth P > 0" apply (induction P) (*goals: 1. ‹⋀x1 x2a. 0 < ProofTerm.depth (PAxm x1 x2a)› 2. ‹⋀x. 0 < ProofTerm.depth (PBound x)› 3. ‹⋀x1 P. 0 < ProofTerm.depth P ⟹ 0 < ProofTerm.depth (Abst x1 P)› 4. ‹⋀x1 P. 0 < ProofTerm.depth P ⟹ 0 < ProofTerm.depth (AbsP x1 P)› 5. ‹⋀P x2a. 0 < ProofTerm.depth P ⟹ 0 < ProofTerm.depth (Appt P x2a)› 6. ‹⋀P1 P2. ⟦0 < ProofTerm.depth P1; 0 < ProofTerm.depth P2⟧ ⟹ 0 < ProofTerm.depth (AppP P1 P2)› 7. ‹⋀x1 x2a. 0 < ProofTerm.depth (OfClass x1 x2a)› 8. ‹⋀x. 0 < ProofTerm.depth (Hyp x)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*proven 8 subgoals*) . lemma "size P > 0" apply (induction P) (*goals: 1. ‹⋀x1 x2a. 0 < ProofTerm.size (PAxm x1 x2a)› 2. ‹⋀x. 0 < ProofTerm.size (PBound x)› 3. ‹⋀x1 P. 0 < ProofTerm.size P ⟹ 0 < ProofTerm.size (Abst x1 P)› 4. ‹⋀x1 P. 0 < ProofTerm.size P ⟹ 0 < ProofTerm.size (AbsP x1 P)› 5. ‹⋀P x2a. 0 < ProofTerm.size P ⟹ 0 < ProofTerm.size (Appt P x2a)› 6. ‹⋀P1 P2. ⟦0 < ProofTerm.size P1; 0 < ProofTerm.size P2⟧ ⟹ 0 < ProofTerm.size (AppP P1 P2)› 7. ‹⋀x1 x2a. 0 < ProofTerm.size (OfClass x1 x2a)› 8. ‹⋀x. 0 < ProofTerm.size (Hyp x)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*proven 8 subgoals*) . lemma "size P ≥ depth P" apply (induction P) (*goals: 1. ‹⋀(x1::Core.term) x2a::((variable × String.literal set) × typ) list. ProofTerm.depth (PAxm x1 x2a) ≤ ProofTerm.size (PAxm x1 x2a)› 2. ‹⋀x::nat. ProofTerm.depth (PBound x) ≤ ProofTerm.size (PBound x)› 3. ‹⋀(x1::typ) P::proofterm. ProofTerm.depth P ≤ ProofTerm.size P ⟹ ProofTerm.depth (Abst x1 P) ≤ ProofTerm.size (Abst x1 P)› 4. ‹⋀(x1::Core.term) P::proofterm. ProofTerm.depth P ≤ ProofTerm.size P ⟹ ProofTerm.depth (AbsP x1 P) ≤ ProofTerm.size (AbsP x1 P)› 5. ‹⋀(P::proofterm) x2a::Core.term. ProofTerm.depth P ≤ ProofTerm.size P ⟹ ProofTerm.depth (Appt P x2a) ≤ ProofTerm.size (Appt P x2a)› 6. ‹⋀(P1::proofterm) P2::proofterm. ⟦ProofTerm.depth P1 ≤ ProofTerm.size P1; ProofTerm.depth P2 ≤ ProofTerm.size P2⟧ ⟹ ProofTerm.depth (AppP P1 P2) ≤ ProofTerm.size (AppP P1 P2)› 7. ‹⋀(x1::typ) x2a::String.literal. ProofTerm.depth (OfClass x1 x2a) ≤ ProofTerm.size (OfClass x1 x2a)› 8. ‹⋀x::Core.term. ProofTerm.depth (Hyp x) ≤ ProofTerm.size (Hyp x)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*proven 8 subgoals*) . fun partial_nth :: "'a list ⇒ nat ⇒ 'a option" where "partial_nth [] _ = None" | "partial_nth (x#xs) 0 = Some x" | "partial_nth (x#xs) (Suc n) = partial_nth xs n" definition [simp]: "partial_nth' xs n ≡ if n < length xs then Some (nth xs n) else None" lemma "partial_nth xs n ≡ partial_nth' xs n" apply (induction rule: partial_nth.induct (*‹⟦⋀uu_. ?P [] uu_; ⋀x xs. ?P (x # xs) 0; ⋀x xs n. ?P xs n ⟹ ?P (x # xs) (Suc n)⟧ ⟹ ?P ?a0.0 ?a1.0›*)) (*goals: 1. ‹⋀uu_. partial_nth [] uu_ = partial_nth' [] uu_› 2. ‹⋀x xs. partial_nth (x # xs) 0 = partial_nth' (x # xs) 0› 3. ‹⋀x xs n. partial_nth xs n = partial_nth' xs n ⟹ partial_nth (x # xs) (Suc n) = partial_nth' (x # xs) (Suc n)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . lemma partial_nth_Some_imp_elem: "partial_nth l n = Some x ⟹ x∈set l" apply (induction rule: partial_nth.induct (*‹⟦⋀uu_. ?P [] uu_; ⋀x xs. ?P (x # xs) 0; ⋀x xs n. ?P xs n ⟹ ?P (x # xs) (Suc n)⟧ ⟹ ?P ?a0.0 ?a1.0›*)) (*goals: 1. ‹⋀uu_. partial_nth [] uu_ = Some x ⟹ x ∈ set []› 2. ‹⋀xa xs. partial_nth (xa # xs) 0 = Some x ⟹ x ∈ set (xa # xs)› 3. ‹⋀xa xs n. ⟦partial_nth xs n = Some x ⟹ x ∈ set xs; partial_nth (xa # xs) (Suc n) = Some x⟧ ⟹ x ∈ set (xa # xs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . text‹The core of the proof checker› fun replay' :: "theory ⇒ (variable × typ) list ⇒ variable set ⇒ term list ⇒ proofterm ⇒ term option" where "replay' thy _ _ Hs (PAxm t Tis) = (if inst_ok thy Tis ∧ term_ok thy t then if t ∈ axioms thy then Some (forall_intro_vars (subst_typ' Tis t) []) else None else None)" | "replay' thy _ _ Hs (PBound n) = partial_nth Hs n" | "replay' thy vs ns Hs (Abst T p) = (if typ_ok thy T then (let (s',ns') = variant_variable (Free STR ''default'') ns in map_option (mk_all s' T) (replay' thy ((s', T) # vs) ns' Hs p)) else None)" | "replay' thy vs ns Hs (Appt p t) = (let rep = replay' thy vs ns Hs p in let t' = subst_bvs (map (λ(x,y) . Fv x y) vs) t in case (rep, typ_of t') of (Some (Ct s (Ty fun1 [Ty fun2 [τ, Ty propT1 Nil], Ty propT2 Nil]) $ b), Some τ') ⇒ if s = STR ''Pure.all'' ∧ fun1 = STR ''fun'' ∧ fun2 = STR ''fun'' ∧ propT1 = STR ''prop'' ∧ propT2 = STR ''prop'' ∧ τ=τ' ∧ term_ok thy t' then Some (b ∙ t') else None | _ ⇒ None)" | "replay' thy vs ns Hs (AbsP t p) = (let t' = subst_bvs (map (λ(x,y) . Fv x y) vs) t in let rep = replay' thy vs ns (t'#Hs) p in (if typ_of t' = Some propT ∧ term_ok thy t' then map_option (mk_imp t') rep else None))" | "replay' thy vs ns Hs (AppP p1 p2) = (let rep1 = Option.bind (replay' thy vs ns Hs p1) beta_eta_norm in let rep2 = Option.bind (replay' thy vs ns Hs p2) beta_eta_norm in (case (rep1, rep2) of ( Some (Ct imp (Ty fn1 [Ty prp1 [], Ty fn2 [Ty prp2 [], Ty prp3 []]]) $ A $ B), Some A') ⇒ if imp = STR ''Pure.imp'' ∧ fn1 = STR ''fun'' ∧ fn2 = STR ''fun'' ∧ prp1 = STR ''prop'' ∧ prp2 = STR ''prop'' ∧ prp3 = STR ''prop'' ∧ A=A' then Some B else None | _ ⇒ None))" | "replay' thy vs ns Hs (OfClass ty c) = (if has_sort (osig (sig thy)) ty {c} ∧ typ_ok thy ty then (case const_type (sig thy) (const_of_class c) of Some (Ty fun [Ty it [ity], Ty prop []]) ⇒ if ity = tvariable STR '''a'' ∧ fun = STR ''fun'' ∧ prop = STR ''prop'' ∧ it = STR ''itself'' then Some (mk_of_class ty c) else None | _ ⇒ None) else None)" | "replay' thy vs ns Hs (Hyp t) = (if t∈set Hs then Some t else None)" lemma fv_subst_bv1: "fv (subst_bv1 t lev u) = fv t ∪ (if loose_bvar1 t lev then fv u else {})" apply (induction t lev u rule: subst_bv1.induct (*‹⟦⋀i lev u. ?P (Bv i) lev u; ⋀T body lev u. ?P body (lev + 1) u ⟹ ?P (Abs T body) lev u; ⋀f t lev u. ⟦?P f lev u; ?P t lev u⟧ ⟹ ?P (f $ t) lev u; ⋀v va uu_ uv_. ?P (Ct v va) uu_ uv_; ⋀v va uu_ uv_. ?P (Fv v va) uu_ uv_⟧ ⟹ ?P ?a0.0 ?a1.0 ?a2.0›*)) (*goals: 1. ‹⋀(i::nat) (lev::nat) u::Core.term. fv (subst_bv1 (Bv i) lev u) = fv (Bv i) ∪ (if loose_bvar1 (Bv i) lev then fv u else {})› 2. ‹⋀(T::typ) (body::Core.term) (lev::nat) u::Core.term. fv (subst_bv1 body (lev + (1::nat)) u) = fv body ∪ (if loose_bvar1 body (lev + (1::nat)) then fv u else {}) ⟹ fv (subst_bv1 (Abs T body) lev u) = fv (Abs T body) ∪ (if loose_bvar1 (Abs T body) lev then fv u else {})› 3. ‹⋀(f::Core.term) (t::Core.term) (lev::nat) u::Core.term. ⟦fv (subst_bv1 f lev u) = fv f ∪ (if loose_bvar1 f lev then fv u else {}); fv (subst_bv1 t lev u) = fv t ∪ (if loose_bvar1 t lev then fv u else {})⟧ ⟹ fv (subst_bv1 (f $ t) lev u) = fv (f $ t) ∪ (if loose_bvar1 (f $ t) lev then fv u else {})› 4. ‹⋀(v::String.literal) (va::typ) (uu_::nat) uv_::Core.term. fv (subst_bv1 (Ct v va) uu_ uv_) = fv (Ct v va) ∪ (if loose_bvar1 (Ct v va) uu_ then fv uv_ else {})› 5. ‹⋀(v::variable) (va::typ) (uu_::nat) uv_::Core.term. fv (subst_bv1 (Fv v va) uu_ uv_) = fv (Fv v va) ∪ (if loose_bvar1 (Fv v va) uu_ then fv uv_ else {})› discuss goal 1*) apply ((auto simp add: incr_boundvars_def (*‹incr_boundvars ?inc ?t = incr_bv ?inc 0 ?t›*))[1]) (*discuss goal 2*) apply ((auto simp add: incr_boundvars_def (*‹incr_boundvars ?inc ?t = incr_bv ?inc 0 ?t›*))[1]) (*discuss goal 3*) apply ((auto simp add: incr_boundvars_def (*‹incr_boundvars ?inc ?t = incr_bv ?inc 0 ?t›*))[1]) (*discuss goal 4*) apply ((auto simp add: incr_boundvars_def (*‹incr_boundvars ?inc ?t = incr_bv ?inc 0 ?t›*))[1]) (*discuss goal 5*) apply ((auto simp add: incr_boundvars_def (*‹incr_boundvars ?inc ?t = incr_bv ?inc 0 ?t›*))[1]) (*proven 5 subgoals*) . (* Needs precondition, doable but diverges from previous checker*) corollary fv_subst_bvs_upper_bound: assumes "is_closed t" shows "fv (subst_bvs us t) ⊆ fv t ∪ (⋃x∈set us . (fv x))" unfolding subst_bvs_def (*goal: ‹fv (subst_bvs1 t 0 us) ⊆ fv t ∪ ⋃ (fv ` set us)›*) using assms (*‹is_closed t›*) by (simp add: is_open_def (*‹is_open ?t ≡ loose_bvar ?t 0›*) no_loose_bvar_imp_no_subst_bvs1 (*‹¬ loose_bvar ?t ?lev ⟹ subst_bvs1 ?t ?lev ?us = ?t›*)) lemma fv_subst_bvs1_upper_bound: "fv (subst_bvs1 t lev us) ⊆ fv t ∪ (⋃x∈set us . (fv x))" proof (induction t lev us rule: subst_bvs1.induct (*‹⟦⋀n lev args. ?P (Bv n) lev args; ⋀T body lev args. ?P body (lev + 1) args ⟹ ?P (Abs T body) lev args; ⋀f t lev args. ⟦?P f lev args; ?P t lev args⟧ ⟹ ?P (f $ t) lev args; ⋀v va uu_ uv_. ?P (Ct v va) uu_ uv_; ⋀v va uu_ uv_. ?P (Fv v va) uu_ uv_⟧ ⟹ ?P ?a0.0 ?a1.0 ?a2.0›*)) (*goals: 1. ‹⋀(n::nat) (lev::nat) args::Core.term list. fv (subst_bvs1 (Bv n) lev args) ⊆ fv (Bv n) ∪ ⋃ (fv ` set args)› 2. ‹⋀(T::typ) (body::Core.term) (lev::nat) args::Core.term list. fv (subst_bvs1 body (lev + (1::nat)) args) ⊆ fv body ∪ ⋃ (fv ` set args) ⟹ fv (subst_bvs1 (Abs T body) lev args) ⊆ fv (Abs T body) ∪ ⋃ (fv ` set args)› 3. ‹⋀(f::Core.term) (t::Core.term) (lev::nat) args::Core.term list. ⟦fv (subst_bvs1 f lev args) ⊆ fv f ∪ ⋃ (fv ` set args); fv (subst_bvs1 t lev args) ⊆ fv t ∪ ⋃ (fv ` set args)⟧ ⟹ fv (subst_bvs1 (f $ t) lev args) ⊆ fv (f $ t) ∪ ⋃ (fv ` set args)› 4. ‹⋀(v::String.literal) (va::typ) (uu_::nat) uv_::Core.term list. fv (subst_bvs1 (Ct v va) uu_ uv_) ⊆ fv (Ct v va) ∪ ⋃ (fv ` set uv_)› 5. ‹⋀(v::variable) (va::typ) (uu_::nat) uv_::Core.term list. fv (subst_bvs1 (Fv v va) uu_ uv_) ⊆ fv (Fv v va) ∪ ⋃ (fv ` set uv_)›*) case (1 n lev args) (*no hyothesis introduced yet*) then show "?case" (*goal: ‹fv (subst_bvs1 (Bv n) lev args) ⊆ fv (Bv n) ∪ ⋃ (fv ` set args)›*) proof (induction args arbitrary: n lev) (*goals: 1. ‹⋀(n::nat) lev::nat. fv (subst_bvs1 (Bv n) lev []) ⊆ fv (Bv n) ∪ ⋃ (fv ` set [])› 2. ‹⋀(a::Core.term) (args::Core.term list) (n::nat) lev::nat. (⋀(n::nat) lev::nat. fv (subst_bvs1 (Bv n) lev args) ⊆ fv (Bv n) ∪ ⋃ (fv ` set args)) ⟹ fv (subst_bvs1 (Bv n) lev (a # args)) ⊆ fv (Bv n) ∪ ⋃ (fv ` set (a # args))›*) case Nil (*no hyothesis introduced yet*) then show "?case" (*goal: ‹fv (subst_bvs1 (Bv n) lev []) ⊆ fv (Bv n) ∪ ⋃ (fv ` set [])›*) by simp next (*goal: ‹⋀a args n lev. (⋀n lev. fv (subst_bvs1 (Bv n) lev args) ⊆ fv (Bv n) ∪ ⋃ (fv ` set args)) ⟹ fv (subst_bvs1 (Bv n) lev (a # args)) ⊆ fv (Bv n) ∪ ⋃ (fv ` set (a # args))›*) case (Cons a args) (*‹fv (subst_bvs1 (Bv (?n::nat)) (?lev::nat) (args::Core.term list)) ⊆ fv (Bv ?n) ∪ ⋃ (fv ` set args)›*) then show "?case" (*goal: ‹fv (subst_bvs1 (Bv (n::nat)) (lev::nat) ((a::Core.term) # (args::Core.term list))) ⊆ fv (Bv n) ∪ ⋃ (fv ` set (a # args))›*) apply simp (*goal: ‹fv (subst_bvs1 (Bv n) lev (a # args)) ⊆ fv (Bv n) ∪ ⋃ (fv ` set (a # args))›*) by (metis SUP_upper (*‹?i ∈ ?A ⟹ ?f ?i ≤ Sup (?f ` ?A)›*) le_supI1 (*‹?x ≤ ?a ⟹ ?x ≤ sup ?a ?b›*) le_supI2 (*‹?x ≤ ?b ⟹ ?x ≤ sup ?a ?b›*) length_Suc_conv (*‹(length ?xs = Suc ?n) = (∃y ys. ?xs = y # ys ∧ length ys = ?n)›*) nth_mem (*‹?n < length ?xs ⟹ ?xs ! ?n ∈ set ?xs›*) set_ConsD (*‹?y ∈ set (?x # ?xs) ⟹ ?y = ?x ∨ ?y ∈ set ?xs›*) set_eq_subset (*‹(?A = ?B) = (?A ⊆ ?B ∧ ?B ⊆ ?A)›*)) qed qed (auto simp add: incr_boundvars_def (*‹incr_boundvars ?inc ?t = incr_bv ?inc 0 ?t›*)) (*solves the remaining goals: 1. ‹⋀T body lev args. fv (subst_bvs1 body (lev + 1) args) ⊆ fv body ∪ ⋃ (fv ` set args) ⟹ fv (subst_bvs1 (Abs T body) lev args) ⊆ fv (Abs T body) ∪ ⋃ (fv ` set args)› 2. ‹⋀f t lev args. ⟦fv (subst_bvs1 f lev args) ⊆ fv f ∪ ⋃ (fv ` set args); fv (subst_bvs1 t lev args) ⊆ fv t ∪ ⋃ (fv ` set args)⟧ ⟹ fv (subst_bvs1 (f $ t) lev args) ⊆ fv (f $ t) ∪ ⋃ (fv ` set args)› 3. ‹⋀v va uu_ uv_. fv (subst_bvs1 (Ct v va) uu_ uv_) ⊆ fv (Ct v va) ∪ ⋃ (fv ` set uv_)› 4. ‹⋀v va uu_ uv_. fv (subst_bvs1 (Fv v va) uu_ uv_) ⊆ fv (Fv v va) ∪ ⋃ (fv ` set uv_)›*) lemma typ_of_axiom: "wf_theory thy ⟹ t ∈ axioms thy ⟹ typ_of t = Some propT" apply (cases thy rule: theory_full_exhaust (*‹(⋀cto tao sorts axioms. ?Θ = ((cto, tao, sorts), axioms) ⟹ ?P) ⟹ ?P›*)) (*goal: ‹⟦wf_theory thy; t ∈ axioms thy⟧ ⟹ typ_of t = Some propT›*) by simp fun fv_Proof :: "proofterm ⇒ (variable × typ) set" where "fv_Proof (PAxm t _) = fv t" | "fv_Proof (PBound _) = empty" | "fv_Proof (Abst _ p) = fv_Proof p" | "fv_Proof (AbsP t p) = fv t ∪ fv_Proof p" | "fv_Proof (Appt p t) = fv_Proof p ∪ fv t" | "fv_Proof (AppP p1 p2) = fv_Proof p1 ∪ fv_Proof p2" | "fv_Proof (OfClass _ _) = empty" | "fv_Proof (Hyp t) = fv t" lemma typ_ok_Tv[simp]: "typ_ok thy (Tv idn S) = wf_sort (subclass (osig (sig thy))) S" by simp lemma typ_ok_contained_tvars_typ_ok: "typ_ok thy ty ⟹ (idn, S) ∈ tvsT ty ⟹ typ_ok thy (Tv idn S)" apply (induction ty) (*goals: 1. ‹⋀x1 x2. ⟦⋀x2a. ⟦x2a ∈ set x2; typ_ok thy x2a; (idn, S) ∈ tvsT x2a⟧ ⟹ typ_ok thy (Tv idn S); typ_ok thy (Ty x1 x2); (idn, S) ∈ tvsT (Ty x1 x2)⟧ ⟹ typ_ok thy (Tv idn S)› 2. ‹⋀x1 x2. ⟦typ_ok thy (Tv x1 x2); (idn, S) ∈ tvsT (Tv x1 x2)⟧ ⟹ typ_ok thy (Tv idn S)› discuss goal 1*) apply ((use split_list typ_ok_Ty in ‹all ‹fastforce split: option.splits››)[1]) (*discuss goal 2*) apply ((use split_list typ_ok_Ty in ‹all ‹fastforce split: option.splits››)[1]) (*proven 2 subgoals*) . lemma typ_ok_sig_contained_tvars_typ_ok_sig: "typ_ok_sig Σ ty ⟹ (idn, S) ∈ tvsT ty ⟹ typ_ok_sig Σ (Tv idn S)" apply (induction ty) (*goals: 1. ‹⋀x1 x2. ⟦⋀x2a. ⟦x2a ∈ set x2; typ_ok_sig Σ x2a; (idn, S) ∈ tvsT x2a⟧ ⟹ typ_ok_sig Σ (Tv idn S); typ_ok_sig Σ (Ty x1 x2); (idn, S) ∈ tvsT (Ty x1 x2)⟧ ⟹ typ_ok_sig Σ (Tv idn S)› 2. ‹⋀x1 x2. ⟦typ_ok_sig Σ (Tv x1 x2); (idn, S) ∈ tvsT (Tv x1 x2)⟧ ⟹ typ_ok_sig Σ (Tv idn S)› discuss goal 1*) apply ((use split_list typ_ok_sig_Ty in ‹all ‹fastforce split: option.splits››)[1]) (*discuss goal 2*) apply ((use split_list typ_ok_sig_Ty in ‹all ‹fastforce split: option.splits››)[1]) (*proven 2 subgoals*) . lemma term_ok'_contained_tvars_typ_ok_sig: "term_ok' Σ t ⟹ (idn, S) ∈ tvs t ⟹ typ_ok_sig Σ (Tv idn S)" proof (induction t) (*goals: 1. ‹⋀x1 x2. ⟦term_ok' Σ (Ct x1 x2); (idn, S) ∈ tvs (Ct x1 x2)⟧ ⟹ typ_ok_sig Σ (Tv idn S)› 2. ‹⋀x1 x2. ⟦term_ok' Σ (Fv x1 x2); (idn, S) ∈ tvs (Fv x1 x2)⟧ ⟹ typ_ok_sig Σ (Tv idn S)› 3. ‹⋀x. ⟦term_ok' Σ (Bv x); (idn, S) ∈ tvs (Bv x)⟧ ⟹ typ_ok_sig Σ (Tv idn S)› 4. ‹⋀x1 t. ⟦⟦term_ok' Σ t; (idn, S) ∈ tvs t⟧ ⟹ typ_ok_sig Σ (Tv idn S); term_ok' Σ (Abs x1 t); (idn, S) ∈ tvs (Abs x1 t)⟧ ⟹ typ_ok_sig Σ (Tv idn S)› 5. ‹⋀t1 t2. ⟦⟦term_ok' Σ t1; (idn, S) ∈ tvs t1⟧ ⟹ typ_ok_sig Σ (Tv idn S); ⟦term_ok' Σ t2; (idn, S) ∈ tvs t2⟧ ⟹ typ_ok_sig Σ (Tv idn S); term_ok' Σ (t1 $ t2); (idn, S) ∈ tvs (t1 $ t2)⟧ ⟹ typ_ok_sig Σ (Tv idn S)›*) case (Ct n T) (*‹term_ok' Σ (Ct n T)› ‹(idn, S) ∈ tvs (Ct n T)›*) hence "typ_ok_sig Σ T" by (auto split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) then show "?case" (*goal: ‹typ_ok_sig (Σ::(String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) (Tv (idn::variable) (S::String.literal set))›*) using typ_ok_sig_contained_tvars_typ_ok_sig (*‹⟦typ_ok_sig ?Σ ?ty; (?idn, ?S) ∈ tvsT ?ty⟧ ⟹ typ_ok_sig ?Σ (Tv ?idn ?S)›*) Ct (*‹term_ok' Σ (Ct n T)› ‹(idn, S) ∈ tvs (Ct n T)›*) by auto next (*goals: 1. ‹⋀x1 x2. ⟦term_ok' Σ (Fv x1 x2); (idn, S) ∈ tvs (Fv x1 x2)⟧ ⟹ typ_ok_sig Σ (Tv idn S)› 2. ‹⋀x. ⟦term_ok' Σ (Bv x); (idn, S) ∈ tvs (Bv x)⟧ ⟹ typ_ok_sig Σ (Tv idn S)› 3. ‹⋀x1 t. ⟦⟦term_ok' Σ t; (idn, S) ∈ tvs t⟧ ⟹ typ_ok_sig Σ (Tv idn S); term_ok' Σ (Abs x1 t); (idn, S) ∈ tvs (Abs x1 t)⟧ ⟹ typ_ok_sig Σ (Tv idn S)› 4. ‹⋀t1 t2. ⟦⟦term_ok' Σ t1; (idn, S) ∈ tvs t1⟧ ⟹ typ_ok_sig Σ (Tv idn S); ⟦term_ok' Σ t2; (idn, S) ∈ tvs t2⟧ ⟹ typ_ok_sig Σ (Tv idn S); term_ok' Σ (t1 $ t2); (idn, S) ∈ tvs (t1 $ t2)⟧ ⟹ typ_ok_sig Σ (Tv idn S)›*) case (Fv idn T) (*‹term_ok' Σ (Fv idn T)› ‹(idn, S) ∈ tvs (Fv idn T)›*) hence "typ_ok_sig Σ T" by (auto split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) then show "?case" (*goal: ‹typ_ok_sig Σ (Tv idn S)›*) using typ_ok_sig_contained_tvars_typ_ok_sig (*‹⟦typ_ok_sig ?Σ ?ty; (?idn, ?S) ∈ tvsT ?ty⟧ ⟹ typ_ok_sig ?Σ (Tv ?idn ?S)›*) Fv (*‹term_ok' Σ (Fv idn T)› ‹(idn, S) ∈ tvs (Fv idn T)›*) by auto next (*goals: 1. ‹⋀x. ⟦term_ok' Σ (Bv x); (idn, S) ∈ tvs (Bv x)⟧ ⟹ typ_ok_sig Σ (Tv idn S)› 2. ‹⋀x1 t. ⟦⟦term_ok' Σ t; (idn, S) ∈ tvs t⟧ ⟹ typ_ok_sig Σ (Tv idn S); term_ok' Σ (Abs x1 t); (idn, S) ∈ tvs (Abs x1 t)⟧ ⟹ typ_ok_sig Σ (Tv idn S)› 3. ‹⋀t1 t2. ⟦⟦term_ok' Σ t1; (idn, S) ∈ tvs t1⟧ ⟹ typ_ok_sig Σ (Tv idn S); ⟦term_ok' Σ t2; (idn, S) ∈ tvs t2⟧ ⟹ typ_ok_sig Σ (Tv idn S); term_ok' Σ (t1 $ t2); (idn, S) ∈ tvs (t1 $ t2)⟧ ⟹ typ_ok_sig Σ (Tv idn S)›*) case (Bv n) (*‹term_ok' Σ (Bv n)› ‹(idn, S) ∈ tvs (Bv n)›*) then show "?case" (*goal: ‹typ_ok_sig Σ (Tv idn S)›*) by auto next (*goals: 1. ‹⋀x1 t. ⟦⟦term_ok' Σ t; (idn, S) ∈ tvs t⟧ ⟹ typ_ok_sig Σ (Tv idn S); term_ok' Σ (Abs x1 t); (idn, S) ∈ tvs (Abs x1 t)⟧ ⟹ typ_ok_sig Σ (Tv idn S)› 2. ‹⋀t1 t2. ⟦⟦term_ok' Σ t1; (idn, S) ∈ tvs t1⟧ ⟹ typ_ok_sig Σ (Tv idn S); ⟦term_ok' Σ t2; (idn, S) ∈ tvs t2⟧ ⟹ typ_ok_sig Σ (Tv idn S); term_ok' Σ (t1 $ t2); (idn, S) ∈ tvs (t1 $ t2)⟧ ⟹ typ_ok_sig Σ (Tv idn S)›*) case (Abs T t) (*‹⟦term_ok' Σ t; (idn, S) ∈ tvs t⟧ ⟹ typ_ok_sig Σ (Tv idn S)› ‹term_ok' Σ (Abs T t)› ‹(idn, S) ∈ tvs (Abs T t)›*) hence "typ_ok_sig Σ T" by (auto split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) then show "?case" (*goal: ‹typ_ok_sig (Σ::(String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) (Tv (idn::variable) (S::String.literal set))›*) using typ_ok_sig_contained_tvars_typ_ok_sig (*‹⟦typ_ok_sig (?Σ::(String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) (?ty::typ); (?idn::variable, ?S::String.literal set) ∈ tvsT ?ty⟧ ⟹ typ_ok_sig ?Σ (Tv ?idn ?S)›*) Abs (*‹⟦term_ok' Σ t; (idn, S) ∈ tvs t⟧ ⟹ typ_ok_sig Σ (Tv idn S)› ‹term_ok' Σ (Abs T t)› ‹(idn, S) ∈ tvs (Abs T t)›*) by fastforce next (*goal: ‹⋀t1 t2. ⟦⟦term_ok' Σ t1; (idn, S) ∈ tvs t1⟧ ⟹ typ_ok_sig Σ (Tv idn S); ⟦term_ok' Σ t2; (idn, S) ∈ tvs t2⟧ ⟹ typ_ok_sig Σ (Tv idn S); term_ok' Σ (t1 $ t2); (idn, S) ∈ tvs (t1 $ t2)⟧ ⟹ typ_ok_sig Σ (Tv idn S)›*) case (App t1 t2) (*‹⟦term_ok' Σ t1; (idn, S) ∈ tvs t1⟧ ⟹ typ_ok_sig Σ (Tv idn S)› ‹⟦term_ok' Σ t2; (idn, S) ∈ tvs t2⟧ ⟹ typ_ok_sig Σ (Tv idn S)› ‹term_ok' Σ (t1 $ t2)› ‹(idn::variable, S::String.literal set) ∈ tvs ((t1::Core.term) $ (t2::Core.term))›*) then show "?case" (*goal: ‹typ_ok_sig Σ (Tv idn S)›*) by auto qed lemma term_ok_contained_tvars_typ_ok: "term_ok thy t ⟹ (idn, S) ∈ tvs t ⟹ typ_ok thy (Tv idn S)" using wt_term_def (*‹wt_term (?Σ::(String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) (?t::Core.term) ≡ wf_term ?Σ ?t ∧ (∃T::typ. ⊢⇩τ ?t : T)›*) typ_ok_def (*‹typ_ok ?Θ ?T ≡ wf_type (sig ?Θ) ?T›*) term_ok'_contained_tvars_typ_ok_sig (*‹⟦term_ok' ?Σ ?t; (?idn, ?S) ∈ tvs ?t⟧ ⟹ typ_ok_sig ?Σ (Tv ?idn ?S)›*) term_ok_def (*‹term_ok ?Θ ?t ≡ wt_term (sig ?Θ) ?t›*) by blast lemma typ_ok_subst_typ: "typ_ok thy T ⟹ ∀(_, ty) ∈ set insts . typ_ok thy ty ⟹ typ_ok thy (subst_typ insts T)" proof (induction insts T rule: subst_typ.induct (*‹⟦⋀insts a Ts. (⋀x. x ∈ set Ts ⟹ ?P insts x) ⟹ ?P insts (Ty a Ts); ⋀insts idn S. ?P insts (Tv idn S)⟧ ⟹ ?P ?a0.0 ?a1.0›*)) (*goals: 1. ‹⋀insts a Ts. ⟦⋀x. ⟦x ∈ set Ts; typ_ok thy x; ∀(uu_, y)∈set insts. typ_ok thy y⟧ ⟹ typ_ok thy (subst_typ insts x); typ_ok thy (Ty a Ts); ∀(uu_, y)∈set insts. typ_ok thy y⟧ ⟹ typ_ok thy (subst_typ insts (Ty a Ts))› 2. ‹⋀insts idn S. ⟦typ_ok thy (Tv idn S); ∀(uu_, y)∈set insts. typ_ok thy y⟧ ⟹ typ_ok thy (subst_typ insts (Tv idn S))›*) case (1 insts n Ts) (*‹⟦?x ∈ set Ts; typ_ok thy ?x; ∀a∈set insts. case a of (uu_, a) ⇒ typ_ok thy a⟧ ⟹ typ_ok thy (subst_typ insts ?x)› ‹typ_ok thy (Ty n Ts)› ‹∀a∈set insts. case a of (uu_, a) ⇒ typ_ok thy a›*) have "typ_ok thy x" if "x∈set Ts" for x by (metis (full_types) "1.prems" (*‹typ_ok thy (Ty n Ts)›*) (1) in_set_conv_decomp_first (*‹(?x ∈ set ?xs) = (∃ys zs. ?xs = ys @ ?x # zs ∧ ?x ∉ set ys)›*) list_all_append (*‹list_all ?P (?xs @ ?ys) = (list_all ?P ?xs ∧ list_all ?P ?ys)›*) list_all_simps( (*‹list_all ?P (?x # ?xs) = (?P ?x ∧ list_all ?P ?xs)›*) 1) that (*‹x ∈ set Ts›*) typ_ok_Ty (*‹typ_ok ?Θ (Ty ?n ?Ts) ⟹ list_all (typ_ok ?Θ) ?Ts›*)) hence "typ_ok thy (subst_typ insts x)" if "x∈set Ts" for x using that (*‹x ∈ set Ts›*) "1" (*‹⟦?x ∈ set Ts; typ_ok thy ?x; ∀a∈set insts. case a of (uu_, a) ⇒ typ_ok thy a⟧ ⟹ typ_ok thy (subst_typ insts ?x)› ‹typ_ok thy (Ty n Ts)› ‹∀a∈set insts. case a of (uu_, a) ⇒ typ_ok thy a›*) by simp then show "?case" (*goal: ‹typ_ok thy (subst_typ insts (Ty n Ts))›*) using "1.prems"(1) (*‹typ_ok thy (Ty n Ts)›*) by (auto simp add: list_all_iff (*‹list_all (?P::?'a ⇒ bool) (?x::?'a list) = Ball (set ?x) ?P›*) split: option.splits (*‹(?P::?'b ⇒ bool) (case ?option::?'a option of None ⇒ ?f1.0::?'b | Some (x::?'a) ⇒ (?f2.0::?'a ⇒ ?'b) x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2::?'a. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹(?P::?'b ⇒ bool) (case ?option::?'a option of None ⇒ ?f1.0::?'b | Some (x::?'a) ⇒ (?f2.0::?'a ⇒ ?'b) x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2::?'a. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) next (*goal: ‹⋀insts idn S. ⟦typ_ok thy (Tv idn S); ∀(uu_, y)∈set insts. typ_ok thy y⟧ ⟹ typ_ok thy (subst_typ insts (Tv idn S))›*) case (2 insts idn S) (*‹typ_ok thy (Tv idn S)› ‹∀a∈set insts. case a of (uu_, a) ⇒ typ_ok thy a›*) then show "?case" (*goal: ‹typ_ok thy (subst_typ insts (Tv idn S))›*) proof (cases "(idn, S) ∈ set (map fst insts)") (*goals: 1. ‹⟦typ_ok thy (Tv idn S); ∀a∈set insts. case a of (uu_, a) ⇒ typ_ok thy a; (idn, S) ∈ set (map fst insts)⟧ ⟹ typ_ok thy (subst_typ insts (Tv idn S))› 2. ‹⟦typ_ok thy (Tv idn S); ∀a∈set insts. case a of (uu_, a) ⇒ typ_ok thy a; (idn, S) ∉ set (map fst insts)⟧ ⟹ typ_ok thy (subst_typ insts (Tv idn S))›*) case True (*‹(idn, S) ∈ set (map fst insts)›*) obtain ty where ty: "lookup (λk. k=(idn,S)) insts = Some ty" (*goal: ‹(⋀ty. lookup (λk. k = (idn, S)) insts = Some ty ⟹ thesis) ⟹ thesis›*) by (metis (full_types) True (*‹(idn, S) ∈ set (map fst insts)›*) lookup_None_iff (*‹(lookup ?P ?xs = None) = (∄x. x ∈ set (map fst ?xs) ∧ ?P x)›*) not_Some_eq (*‹(∀y. ?x ≠ Some y) = (?x = None)›*)) hence "subst_typ insts (Tv idn S) = ty" by simp then show "?thesis" (*goal: ‹typ_ok (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (subst_typ (insts::((variable × String.literal set) × typ) list) (Tv (idn::variable) (S::String.literal set)))›*) using "2.prems"(2) (*‹∀a::(variable × String.literal set) × typ∈set (insts::((variable × String.literal set) × typ) list). case a of (uu_::variable × String.literal set, a::typ) ⇒ typ_ok (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) a›*) ty (*‹lookup (λk. k = (idn, S)) insts = Some ty›*) case_prodD (*‹case (?a, ?b) of (c, d) ⇒ ?f c d ⟹ ?f ?a ?b›*) lookup_present_eq_key' (*‹lookup (λx. x = ?k) ?al = Some ?v ⟹ (?k, ?v) ∈ set ?al›*) by fastforce next (*goal: ‹⟦typ_ok thy (Tv idn S); ∀a∈set insts. case a of (uu_, a) ⇒ typ_ok thy a; (idn, S) ∉ set (map fst insts)⟧ ⟹ typ_ok thy (subst_typ insts (Tv idn S))›*) case False (*‹(idn, S) ∉ set (map fst insts)›*) hence "subst_typ insts (Tv idn S) = Tv idn S" by (metis (mono_tags, lifting) lookup_None_iff (*‹(lookup ?P ?xs = None) = (∄x. x ∈ set (map fst ?xs) ∧ ?P x)›*) subst_typ.simps( (*‹subst_typ ?insts (Tv ?idn ?S) = the_default (Tv ?idn ?S) (lookup (λx. x = (?idn, ?S)) ?insts)›*) 2) the_default.simps( (*‹the_default ?a None = ?a›*) 1)) then show "?thesis" (*goal: ‹typ_ok (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (subst_typ (insts::((variable × String.literal set) × typ) list) (Tv (idn::variable) (S::String.literal set)))›*) using "2.prems"(1) (*‹typ_ok (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (Tv (idn::variable) (S::String.literal set))›*) by simp qed qed lemma typ_ok_sig_subst_typ: "typ_ok_sig Σ T ⟹ ∀(_, ty) ∈ set insts . typ_ok_sig Σ ty ⟹ typ_ok_sig Σ (subst_typ insts T)" proof (induction insts T rule: subst_typ.induct (*‹⟦⋀insts a Ts. (⋀x. x ∈ set Ts ⟹ ?P insts x) ⟹ ?P insts (Ty a Ts); ⋀insts idn S. ?P insts (Tv idn S)⟧ ⟹ ?P ?a0.0 ?a1.0›*)) (*goals: 1. ‹⋀insts a Ts. ⟦⋀x. ⟦x ∈ set Ts; typ_ok_sig Σ x; ∀(uu_, y)∈set insts. typ_ok_sig Σ y⟧ ⟹ typ_ok_sig Σ (subst_typ insts x); typ_ok_sig Σ (Ty a Ts); ∀(uu_, y)∈set insts. typ_ok_sig Σ y⟧ ⟹ typ_ok_sig Σ (subst_typ insts (Ty a Ts))› 2. ‹⋀insts idn S. ⟦typ_ok_sig Σ (Tv idn S); ∀(uu_, y)∈set insts. typ_ok_sig Σ y⟧ ⟹ typ_ok_sig Σ (subst_typ insts (Tv idn S))›*) case (1 insts n Ts) (*‹⟦?x ∈ set Ts; typ_ok_sig Σ ?x; ∀a∈set insts. case a of (uu_, a) ⇒ typ_ok_sig Σ a⟧ ⟹ typ_ok_sig Σ (subst_typ insts ?x)› ‹typ_ok_sig Σ (Ty n Ts)› ‹∀a∈set insts. case a of (uu_, a) ⇒ typ_ok_sig Σ a›*) have "typ_ok_sig Σ x" if "x∈set Ts" for x using "1.prems"(1) (*‹typ_ok_sig (Σ::(String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) (Ty (n::String.literal) (Ts::typ list))›*) split_list (*‹(?x::?'a) ∈ set (?xs::?'a list) ⟹ ∃(ys::?'a list) zs::?'a list. ?xs = ys @ ?x # zs›*) that (*‹x ∈ set Ts›*) typ_ok_sig_Ty (*‹typ_ok_sig ?Σ (Ty ?n ?Ts) ⟹ list_all (typ_ok_sig ?Σ) ?Ts›*) by fastforce hence "typ_ok_sig Σ (subst_typ insts x)" if "x∈set Ts" for x using that (*‹(x::typ) ∈ set (Ts::typ list)›*) "1" (*‹⟦?x ∈ set Ts; typ_ok_sig Σ ?x; ∀a∈set insts. case a of (uu_, a) ⇒ typ_ok_sig Σ a⟧ ⟹ typ_ok_sig Σ (subst_typ insts ?x)› ‹typ_ok_sig (Σ::(String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) (Ty (n::String.literal) (Ts::typ list))› ‹∀a∈set insts. case a of (uu_, a) ⇒ typ_ok_sig Σ a›*) by simp then show "?case" (*goal: ‹typ_ok_sig Σ (subst_typ insts (Ty n Ts))›*) using "1.prems"(1) (*‹typ_ok_sig Σ (Ty n Ts)›*) by (auto simp add: list_all_iff (*‹list_all ?P ?x = Ball (set ?x) ?P›*) split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) next (*goal: ‹⋀insts idn S. ⟦typ_ok_sig Σ (Tv idn S); ∀(uu_, y)∈set insts. typ_ok_sig Σ y⟧ ⟹ typ_ok_sig Σ (subst_typ insts (Tv idn S))›*) case (2 insts idn S) (*‹typ_ok_sig (Σ::(String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) (Tv (idn::variable) (S::String.literal set))› ‹∀a∈set insts. case a of (uu_, a) ⇒ typ_ok_sig Σ a›*) then show "?case" (*goal: ‹typ_ok_sig Σ (subst_typ insts (Tv idn S))›*) proof (cases "(idn, S) ∈ set (map fst insts)") (*goals: 1. ‹⟦typ_ok_sig (Σ::(String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) (Tv (idn::variable) (S::String.literal set)); ∀a::(variable × String.literal set) × typ∈set (insts::((variable × String.literal set) × typ) list). case a of (uu_::variable × String.literal set, a::typ) ⇒ typ_ok_sig Σ a; (idn, S) ∈ set (map fst insts)⟧ ⟹ typ_ok_sig Σ (subst_typ insts (Tv idn S))› 2. ‹⟦typ_ok_sig (Σ::(String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) (Tv (idn::variable) (S::String.literal set)); ∀a::(variable × String.literal set) × typ∈set (insts::((variable × String.literal set) × typ) list). case a of (uu_::variable × String.literal set, a::typ) ⇒ typ_ok_sig Σ a; (idn, S) ∉ set (map fst insts)⟧ ⟹ typ_ok_sig Σ (subst_typ insts (Tv idn S))›*) case True (*‹(idn, S) ∈ set (map fst insts)›*) obtain ty where ty: "lookup (λk. k=(idn,S)) insts = Some ty" (*goal: ‹(⋀ty. lookup (λk. k = (idn, S)) insts = Some ty ⟹ thesis) ⟹ thesis›*) by (metis (full_types) True (*‹(idn, S) ∈ set (map fst insts)›*) lookup_None_iff (*‹(lookup ?P ?xs = None) = (∄x. x ∈ set (map fst ?xs) ∧ ?P x)›*) not_Some_eq (*‹(∀y. ?x ≠ Some y) = (?x = None)›*)) hence "subst_typ insts (Tv idn S) = ty" by simp then show "?thesis" (*goal: ‹typ_ok_sig Σ (subst_typ insts (Tv idn S))›*) using "2.prems"(2) (*‹∀a∈set insts. case a of (uu_, a) ⇒ typ_ok_sig Σ a›*) ty (*‹lookup (λk. k = (idn, S)) insts = Some ty›*) case_prodD (*‹case (?a, ?b) of (c, d) ⇒ ?f c d ⟹ ?f ?a ?b›*) lookup_present_eq_key' (*‹lookup (λx::?'b::type. x = (?k::?'b::type)) (?al::(?'b::type × ?'a::type) list) = Some (?v::?'a::type) ⟹ (?k, ?v) ∈ set ?al›*) by fastforce next (*goal: ‹⟦typ_ok_sig (Σ::(String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) (Tv (idn::variable) (S::String.literal set)); ∀a::(variable × String.literal set) × typ∈set (insts::((variable × String.literal set) × typ) list). case a of (uu_::variable × String.literal set, a::typ) ⇒ typ_ok_sig Σ a; (idn, S) ∉ set (map fst insts)⟧ ⟹ typ_ok_sig Σ (subst_typ insts (Tv idn S))›*) case False (*‹(idn, S) ∉ set (map fst insts)›*) hence "subst_typ insts (Tv idn S) = Tv idn S" by (metis (mono_tags, lifting) lookup_None_iff (*‹(lookup ?P ?xs = None) = (∄x. x ∈ set (map fst ?xs) ∧ ?P x)›*) subst_typ.simps( (*‹subst_typ ?insts (Tv ?idn ?S) = the_default (Tv ?idn ?S) (lookup (λx. x = (?idn, ?S)) ?insts)›*) 2) the_default.simps( (*‹the_default ?a None = ?a›*) 1)) then show "?thesis" (*goal: ‹typ_ok_sig Σ (subst_typ insts (Tv idn S))›*) using "2.prems"(1) (*‹typ_ok_sig Σ (Tv idn S)›*) by simp qed qed lemma typ_ok_sig_imp_sortsT_ok_sig: "typ_ok_sig Σ T ⟹ S ∈ SortsT T ⟹ wf_sort (subclass (osig Σ)) S" apply (induction T) (*goals: 1. ‹⋀x1 x2. ⟦⋀x2a. ⟦x2a ∈ set x2; typ_ok_sig Σ x2a; S ∈ SortsT x2a⟧ ⟹ wf_sort (subclass (osig Σ)) S; typ_ok_sig Σ (Ty x1 x2); S ∈ SortsT (Ty x1 x2)⟧ ⟹ wf_sort (subclass (osig Σ)) S› 2. ‹⋀x1 x2. ⟦typ_ok_sig Σ (Tv x1 x2); S ∈ SortsT (Tv x1 x2)⟧ ⟹ wf_sort (subclass (osig Σ)) S› discuss goal 1*) apply ((use split_list in ‹all ‹fastforce simp add: wf_sort_def split: option.splits››)[1]) (*discuss goal 2*) apply ((use split_list in ‹all ‹fastforce simp add: wf_sort_def split: option.splits››)[1]) (*proven 2 subgoals*) . lemma term_ok'_imp_Sorts_ok_sig: "term_ok' Σ t ⟹ S ∈ Sorts t ⟹ wf_sort (subclass (osig Σ)) S" apply (induction t) (*goals: 1. ‹⋀x1 x2. ⟦term_ok' Σ (Ct x1 x2); S ∈ Sorts (Ct x1 x2)⟧ ⟹ wf_sort (subclass (osig Σ)) S› 2. ‹⋀x1 x2. ⟦term_ok' Σ (Fv x1 x2); S ∈ Sorts (Fv x1 x2)⟧ ⟹ wf_sort (subclass (osig Σ)) S› 3. ‹⋀x. ⟦term_ok' Σ (Bv x); S ∈ Sorts (Bv x)⟧ ⟹ wf_sort (subclass (osig Σ)) S› 4. ‹⋀x1 t. ⟦⟦term_ok' Σ t; S ∈ Sorts t⟧ ⟹ wf_sort (subclass (osig Σ)) S; term_ok' Σ (Abs x1 t); S ∈ Sorts (Abs x1 t)⟧ ⟹ wf_sort (subclass (osig Σ)) S› 5. ‹⋀t1 t2. ⟦⟦term_ok' Σ t1; S ∈ Sorts t1⟧ ⟹ wf_sort (subclass (osig Σ)) S; ⟦term_ok' Σ t2; S ∈ Sorts t2⟧ ⟹ wf_sort (subclass (osig Σ)) S; term_ok' Σ (t1 $ t2); S ∈ Sorts (t1 $ t2)⟧ ⟹ wf_sort (subclass (osig Σ)) S› discuss goal 1*) apply ((use typ_ok_sig_imp_sortsT_ok_sig in ‹(fastforce split: option.splits)+›)[1]) (*discuss goal 2*) apply ((use typ_ok_sig_imp_sortsT_ok_sig in ‹(fastforce split: option.splits)+›)[1]) (*discuss goal 3*) apply ((use typ_ok_sig_imp_sortsT_ok_sig in ‹(fastforce split: option.splits)+›)[1]) (*discuss goal 4*) apply ((use typ_ok_sig_imp_sortsT_ok_sig in ‹(fastforce split: option.splits)+›)[1]) (*discuss goal 5*) apply ((use typ_ok_sig_imp_sortsT_ok_sig in ‹(fastforce split: option.splits)+›)[1]) (*proven 5 subgoals*) . lemma replay'_sound_pre: assumes thy: "wf_theory thy" (* Assumptions *) assumes HS_invs: "⋀x. x∈set Hs ⟹ term_ok thy x" "⋀x. x∈set Hs ⟹ typ_of x = Some propT" (* Names used *) assumes ns_invs: "finite ns" "fst ` FV (set Hs) ⊆ ns" "fst ` fv_Proof P ⊆ ns" (* Fviables used *) assumes vs_invs: "fst ` set vs ⊆ ns" (* Checked proof can be replay'ed using proves*) assumes "replay' thy vs ns Hs P = Some res" shows "thy, (set Hs) ⊢ res" using assms (*‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite ns› ‹fst ` FV (set Hs) ⊆ ns› ‹fst ` fv_Proof P ⊆ ns› ‹fst ` set vs ⊆ ns› ‹replay' thy vs ns Hs P = Some res›*) proof (induction thy vs ns Hs P arbitrary: res rule: replay'.induct) (*goals: 1. ‹⋀thy uu_ uv_ Hs t Tis res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite uv_; fst ` FV (set Hs) ⊆ uv_; fst ` fv_Proof (PAxm t Tis) ⊆ uv_; fst ` set uu_ ⊆ uv_; replay' thy uu_ uv_ Hs (PAxm t Tis) = Some res⟧ ⟹ thy,set Hs ⊢ res› 2. ‹⋀thy uw_ ux_ Hs n res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ux_; fst ` FV (set Hs) ⊆ ux_; fst ` fv_Proof (PBound n) ⊆ ux_; fst ` set uw_ ⊆ ux_; replay' thy uw_ ux_ Hs (PBound n) = Some res⟧ ⟹ thy,set Hs ⊢ res› 3. ‹⋀thy vs ns Hs T p res. ⟦⋀x xa y res. ⟦typ_ok thy T; x = variant_variable (Free STR ''default'') ns; (xa, y) = x; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite y; fst ` FV (set Hs) ⊆ y; fst ` fv_Proof p ⊆ y; fst ` set ((xa, T) # vs) ⊆ y; replay' thy ((xa, T) # vs) y Hs p = Some res⟧ ⟹ thy,set Hs ⊢ res; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (Abst T p) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (Abst T p) = Some res⟧ ⟹ thy,set Hs ⊢ res› 4. ‹⋀thy vs ns Hs p t res. ⟦⋀res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p = Some res⟧ ⟹ thy,set Hs ⊢ res; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (Appt p t) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (Appt p t) = Some res⟧ ⟹ thy,set Hs ⊢ res› 5. ‹⋀thy vs ns Hs t p res. ⟦⋀x res. ⟦x = subst_bvs (map (λ(x, y). Fv x y) vs) t; wf_theory thy; ⋀xa. xa ∈ set (x # Hs) ⟹ term_ok thy xa; ⋀xa. xa ∈ set (x # Hs) ⟹ typ_of xa = Some propT; finite ns; fst ` FV (set (x # Hs)) ⊆ ns; fst ` fv_Proof p ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns (x # Hs) p = Some res⟧ ⟹ thy,set (x # Hs) ⊢ res; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AbsP t p) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (AbsP t p) = Some res⟧ ⟹ thy,set Hs ⊢ res› 6. ‹⋀thy vs ns Hs p1 p2 res. ⟦⋀res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p1 ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p1 = Some res⟧ ⟹ thy,set Hs ⊢ res; ⋀x res. ⟦x = Option.bind (replay' thy vs ns Hs p1) beta_eta_norm; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p2 ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p2 = Some res⟧ ⟹ thy,set Hs ⊢ res; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AppP p1 p2) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (AppP p1 p2) = Some res⟧ ⟹ thy,set Hs ⊢ res› 7. ‹⋀thy vs ns Hs ty c res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (OfClass ty c) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (OfClass ty c) = Some res⟧ ⟹ thy,set Hs ⊢ res› 8. ‹⋀thy vs ns Hs t res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (Hyp t) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (Hyp t) = Some res⟧ ⟹ thy,set Hs ⊢ res›*) case (1 thy uu uv Hs t Tis) (*‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹(?x::Core.term) ∈ set (Hs::Core.term list) ⟹ typ_of ?x = Some propT› ‹finite (uv::variable set)› ‹fst ` FV (set (Hs::Core.term list)) ⊆ (uv::variable set)› ‹fst ` fv_Proof (PAxm t Tis) ⊆ uv› ‹fst ` set uu ⊆ uv› ‹replay' thy uu uv Hs (PAxm t Tis) = Some res›*) hence ax: "t∈axioms thy" and insts: "inst_ok thy Tis" and t: "term_ok thy t" and res: "forall_intro_vars (subst_typ' Tis t) [] = res" apply - (*goals: 1. ‹⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite uv; fst ` FV (set Hs) ⊆ uv; fst ` fv_Proof (PAxm t Tis) ⊆ uv; fst ` set uu ⊆ uv; replay' thy uu uv Hs (PAxm t Tis) = Some res⟧ ⟹ t ∈ axioms thy› 2. ‹⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite uv; fst ` FV (set Hs) ⊆ uv; fst ` fv_Proof (PAxm t Tis) ⊆ uv; fst ` set uu ⊆ uv; replay' thy uu uv Hs (PAxm t Tis) = Some res⟧ ⟹ inst_ok thy Tis› 3. ‹⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite uv; fst ` FV (set Hs) ⊆ uv; fst ` fv_Proof (PAxm t Tis) ⊆ uv; fst ` set uu ⊆ uv; replay' thy uu uv Hs (PAxm t Tis) = Some res⟧ ⟹ term_ok thy t› 4. ‹⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite uv; fst ` FV (set Hs) ⊆ uv; fst ` fv_Proof (PAxm t Tis) ⊆ uv; fst ` set uu ⊆ uv; replay' thy uu uv Hs (PAxm t Tis) = Some res⟧ ⟹ forall_intro_vars (subst_typ' Tis t) [] = res› discuss goal 1*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 2*) apply ((auto split: if_splits (*‹(?P::?'a::type ⇒ bool) (if ?Q::bool then ?x::?'a::type else (?y::?'a::type)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹(?P::?'a::type ⇒ bool) (if ?Q::bool then ?x::?'a::type else (?y::?'a::type)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 3*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*discuss goal 4*) apply ((auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*))[1]) (*proven 4 subgoals*) . hence 1: "thy, {} ⊢ res" using res (*‹forall_intro_vars (subst_typ' (Tis::((variable × String.literal set) × typ) list) (t::Core.term)) [] = (res::Core.term)›*) "1.prems"(1) (*‹wf_theory thy›*) proved_terms_well_formed_pre (*‹?Θ,?Γ ⊢ ?p ⟹ typ_of ?p = Some propT ∧ term_ok ?Θ ?p›*) using axiom (*‹⟦wf_theory ?Θ; ?A ∈ axioms ?Θ; wf_inst ?Θ ?ρ⟧ ⟹ ?Θ,?Γ ⊢ tsubst ?A ?ρ›*) forall_intro_vars (*‹⟦wf_theory ?Θ; ?Θ,set ?Hs ⊢ ?B⟧ ⟹ ?Θ,set ?Hs ⊢ forall_intro_vars ?B ?Hs›*) inst_ok_imp_wf_inst (*‹inst_ok ?Θ ?insts ⟹ wf_inst ?Θ (λidn S. the_default (Tv idn S) (lookup (λx. x = (idn, S)) ?insts))›*) tsubst_simulates_subst_typ' (*‹subst_typ' (?insts::((variable × String.literal set) × typ) list) (?T::Core.term) = tsubst ?T (λ(idn::variable) S::String.literal set. the_default (Tv idn S) (lookup (λx::variable × String.literal set. x = (idn, S)) ?insts))›*) by (metis (no_types, lifting) empty_set (*‹{} = set []›*)) show "?case" (*goal: ‹thy,set Hs ⊢ res›*) using weaken_proves_set[of "set Hs", OF _ 1] (*‹⟦finite (set Hs); ∀A∈set Hs. term_ok thy A; ∀A∈set Hs. typ_of A = Some propT; finite {}⟧ ⟹ thy,{} ∪ set Hs ⊢ res›*) using "1.prems"(2) (*‹?x ∈ set Hs ⟹ term_ok thy ?x›*) "1.prems"(3) (*‹?x ∈ set Hs ⟹ typ_of ?x = Some propT›*) by auto next (*goals: 1. ‹⋀thy uw_ ux_ Hs n res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ux_; fst ` FV (set Hs) ⊆ ux_; fst ` fv_Proof (PBound n) ⊆ ux_; fst ` set uw_ ⊆ ux_; replay' thy uw_ ux_ Hs (PBound n) = Some res⟧ ⟹ thy,set Hs ⊢ res› 2. ‹⋀thy vs ns Hs T p res. ⟦⋀x xa y res. ⟦typ_ok thy T; x = variant_variable (Free STR ''default'') ns; (xa, y) = x; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite y; fst ` FV (set Hs) ⊆ y; fst ` fv_Proof p ⊆ y; fst ` set ((xa, T) # vs) ⊆ y; replay' thy ((xa, T) # vs) y Hs p = Some res⟧ ⟹ thy,set Hs ⊢ res; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (Abst T p) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (Abst T p) = Some res⟧ ⟹ thy,set Hs ⊢ res› 3. ‹⋀thy vs ns Hs p t res. ⟦⋀res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p = Some res⟧ ⟹ thy,set Hs ⊢ res; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (Appt p t) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (Appt p t) = Some res⟧ ⟹ thy,set Hs ⊢ res› 4. ‹⋀thy vs ns Hs t p res. ⟦⋀x res. ⟦x = subst_bvs (map (λ(x, y). Fv x y) vs) t; wf_theory thy; ⋀xa. xa ∈ set (x # Hs) ⟹ term_ok thy xa; ⋀xa. xa ∈ set (x # Hs) ⟹ typ_of xa = Some propT; finite ns; fst ` FV (set (x # Hs)) ⊆ ns; fst ` fv_Proof p ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns (x # Hs) p = Some res⟧ ⟹ thy,set (x # Hs) ⊢ res; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AbsP t p) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (AbsP t p) = Some res⟧ ⟹ thy,set Hs ⊢ res› 5. ‹⋀thy vs ns Hs p1 p2 res. ⟦⋀res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p1 ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p1 = Some res⟧ ⟹ thy,set Hs ⊢ res; ⋀x res. ⟦x = Option.bind (replay' thy vs ns Hs p1) beta_eta_norm; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p2 ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p2 = Some res⟧ ⟹ thy,set Hs ⊢ res; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AppP p1 p2) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (AppP p1 p2) = Some res⟧ ⟹ thy,set Hs ⊢ res› 6. ‹⋀thy vs ns Hs ty c res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (OfClass ty c) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (OfClass ty c) = Some res⟧ ⟹ thy,set Hs ⊢ res› 7. ‹⋀thy vs ns Hs t res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (Hyp t) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (Hyp t) = Some res⟧ ⟹ thy,set Hs ⊢ res›*) case (2 thy ux uy Hs n) (*‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite (uy::variable set)› ‹fst ` FV (set (Hs::Core.term list)) ⊆ (uy::variable set)› ‹fst ` fv_Proof (PBound (n::nat)) ⊆ (uy::variable set)› ‹fst ` set ux ⊆ uy› ‹replay' thy ux uy Hs (PBound n) = Some res›*) hence "res ∈ set Hs" using partial_nth_Some_imp_elem (*‹partial_nth ?l ?n = Some ?x ⟹ ?x ∈ set ?l›*) by simp then show "?case" (*goal: ‹thy,set Hs ⊢ res›*) using proves.assume (*‹⟦wf_term (sig ?Θ) ?A; ⊢⇩τ ?A : propT; ?A ∈ ?Γ⟧ ⟹ ?Θ,?Γ ⊢ ?A›*) "2" (*‹wf_theory (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set)› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite uy› ‹fst ` FV (set Hs) ⊆ uy› ‹fst ` fv_Proof (PBound (n::nat)) ⊆ (uy::variable set)› ‹fst ` set ux ⊆ uy› ‹replay' thy ux uy Hs (PBound n) = Some res›*) by (simp add: wt_term_def (*‹wt_term ?Σ ?t ≡ wf_term ?Σ ?t ∧ (∃T. ⊢⇩τ ?t : T)›*)) next (*goals: 1. ‹⋀thy vs ns Hs T p res. ⟦⋀x xa y res. ⟦typ_ok thy T; x = variant_variable (Free STR ''default'') ns; (xa, y) = x; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite y; fst ` FV (set Hs) ⊆ y; fst ` fv_Proof p ⊆ y; fst ` set ((xa, T) # vs) ⊆ y; replay' thy ((xa, T) # vs) y Hs p = Some res⟧ ⟹ thy,set Hs ⊢ res; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (Abst T p) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (Abst T p) = Some res⟧ ⟹ thy,set Hs ⊢ res› 2. ‹⋀thy vs ns Hs p t res. ⟦⋀res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p = Some res⟧ ⟹ thy,set Hs ⊢ res; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (Appt p t) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (Appt p t) = Some res⟧ ⟹ thy,set Hs ⊢ res› 3. ‹⋀thy vs ns Hs t p res. ⟦⋀x res. ⟦x = subst_bvs (map (λ(x, y). Fv x y) vs) t; wf_theory thy; ⋀xa. xa ∈ set (x # Hs) ⟹ term_ok thy xa; ⋀xa. xa ∈ set (x # Hs) ⟹ typ_of xa = Some propT; finite ns; fst ` FV (set (x # Hs)) ⊆ ns; fst ` fv_Proof p ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns (x # Hs) p = Some res⟧ ⟹ thy,set (x # Hs) ⊢ res; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AbsP t p) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (AbsP t p) = Some res⟧ ⟹ thy,set Hs ⊢ res› 4. ‹⋀thy vs ns Hs p1 p2 res. ⟦⋀res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p1 ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p1 = Some res⟧ ⟹ thy,set Hs ⊢ res; ⋀x res. ⟦x = Option.bind (replay' thy vs ns Hs p1) beta_eta_norm; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p2 ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p2 = Some res⟧ ⟹ thy,set Hs ⊢ res; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AppP p1 p2) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (AppP p1 p2) = Some res⟧ ⟹ thy,set Hs ⊢ res› 5. ‹⋀thy vs ns Hs ty c res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (OfClass ty c) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (OfClass ty c) = Some res⟧ ⟹ thy,set Hs ⊢ res› 6. ‹⋀thy vs ns Hs t res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (Hyp t) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (Hyp t) = Some res⟧ ⟹ thy,set Hs ⊢ res›*) case (3 thy vs ns Hs T p) (*‹⟦typ_ok (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (T::typ); (?x::variable × variable set) = variant_variable (Free STR ''default'') (ns::variable set); (?xa::variable, ?y::variable set) = ?x; wf_theory thy; ⋀x::Core.term. x ∈ set (Hs::Core.term list) ⟹ term_ok thy x; ⋀x::Core.term. x ∈ set Hs ⟹ typ_of x = Some propT; finite ?y; fst ` FV (set Hs) ⊆ ?y; fst ` fv_Proof (p::proofterm) ⊆ ?y; fst ` set ((?xa, T) # (vs::(variable × typ) list)) ⊆ ?y; replay' thy ((?xa, T) # vs) ?y Hs p = Some (?res::Core.term)⟧ ⟹ thy,set Hs ⊢ ?res› ‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite ns› ‹fst ` FV (set Hs) ⊆ ns› ‹fst ` fv_Proof (Abst T p) ⊆ ns› ‹fst ` set vs ⊆ ns› ‹replay' thy vs ns Hs (Abst T p) = Some res›*) obtain s' and ns' where names: "(s',ns') = variant_variable (Free STR ''default'') ns" (*goal: ‹(⋀s' ns'. (s', ns') = variant_variable (Free STR ''default'') ns ⟹ thesis) ⟹ thesis›*) by simp from this (*‹(s'::variable, ns'::variable set) = variant_variable (Free STR ''default'') (ns::variable set)›*) "3" (*‹⟦typ_ok thy T; ?x = variant_variable (Free STR ''default'') ns; (?xa, ?y) = ?x; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ?y; fst ` FV (set Hs) ⊆ ?y; fst ` fv_Proof p ⊆ ?y; fst ` set ((?xa, T) # vs) ⊆ ?y; replay' thy ((?xa, T) # vs) ?y Hs p = Some ?res⟧ ⟹ thy,set Hs ⊢ ?res› ‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite (ns::variable set)› ‹fst ` FV (set Hs) ⊆ ns› ‹fst ` fv_Proof (Abst T p) ⊆ ns› ‹fst ` set vs ⊆ ns› ‹replay' (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (vs::(variable × typ) list) (ns::variable set) (Hs::Core.term list) (Abst (T::typ) (p::proofterm)) = Some (res::Core.term)›*) obtain bres where bres: "replay' thy ((s', T) # vs) ns' Hs p = Some bres" (*goal: ‹(⋀bres. replay' thy ((s', T) # vs) ns' Hs p = Some bres ⟹ thesis) ⟹ thesis›*) by (auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*)) have "ns' = insert s' ns" using variant_variable_adds (*‹snd (variant_variable ?s ?S) = insert (fst (variant_variable ?s ?S)) ?S›*) names (*‹(s', ns') = variant_variable (Free STR ''default'') ns›*) by (metis fst_conv (*‹fst (?x1.0::?'a::type, ?x2.0::?'b::type) = ?x1.0›*) snd_conv (*‹snd (?x1.0::?'aa::type, ?x2.0::?'a::type) = ?x2.0›*)) have "s' ∉ ns" using "3.prems" (*‹wf_theory thy› ‹(?x::Core.term) ∈ set (Hs::Core.term list) ⟹ term_ok (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite ns› ‹fst ` FV (set Hs) ⊆ ns› ‹fst ` fv_Proof (Abst T p) ⊆ ns› ‹fst ` set (vs::(variable × typ) list) ⊆ (ns::variable set)› ‹replay' thy vs ns Hs (Abst T p) = Some res›*) variant_variable_fresh (*‹finite (?S::variable set) ⟹ fst (variant_variable (?s::variable) ?S) ∉ ?S›*) names (*‹(s', ns') = variant_variable (Free STR ''default'') ns›*) by (metis fst_conv (*‹fst (?x1.0, ?x2.0) = ?x1.0›*)) hence "s' ∉ fst ` FV (set Hs)" using "3.prems" (*‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite ns› ‹fst ` FV (set Hs) ⊆ ns› ‹fst ` fv_Proof (Abst T p) ⊆ ns› ‹fst ` set (vs::(variable × typ) list) ⊆ (ns::variable set)› ‹replay' thy vs ns Hs (Abst T p) = Some res›*) by blast hence free: "(s', T) ∉ FV (set Hs)" by force have typ_ok: "wf_type (sig thy) T" using names (*‹(s'::variable, ns'::variable set) = variant_variable (Free STR ''default'') (ns::variable set)›*) "3.prems" (*‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite ns› ‹fst ` FV (set Hs) ⊆ ns› ‹fst ` fv_Proof (Abst T p) ⊆ ns› ‹fst ` set vs ⊆ ns› ‹replay' (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (vs::(variable × typ) list) (ns::variable set) (Hs::Core.term list) (Abst (T::typ) (p::proofterm)) = Some (res::Core.term)›*) by (auto split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) have I: "thy, set Hs ⊢ bres" apply (rule "3.IH"[OF _ names] (*‹⟦typ_ok thy T; (?xa, ?y) = (s', ns'); wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ?y; fst ` FV (set Hs) ⊆ ?y; fst ` fv_Proof p ⊆ ?y; fst ` set ((?xa, T) # vs) ⊆ ?y; replay' thy ((?xa, T) # vs) ?y Hs p = Some ?res⟧ ⟹ thy,set Hs ⊢ ?res›*)) (*goal: ‹thy,set Hs ⊢ bres›*) using names (*‹(s', ns') = variant_variable (Free STR ''default'') ns›*) "3.prems" (*‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite (ns::variable set)› ‹fst ` FV (set Hs) ⊆ ns› ‹fst ` fv_Proof (Abst T p) ⊆ ns› ‹fst ` set vs ⊆ ns› ‹replay' thy vs ns Hs (Abst T p) = Some res›*) apply ((solves ‹simp split: if_splits›)+) (*top goal: ‹typ_ok thy T› and 9 goals remain*) using names (*‹(s', ns') = variant_variable (Free STR ''default'') ns›*) "3.prems" (*‹wf_theory thy› ‹(?x::Core.term) ∈ set (Hs::Core.term list) ⟹ term_ok (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite ns› ‹fst ` FV (set (Hs::Core.term list)) ⊆ (ns::variable set)› ‹fst ` fv_Proof (Abst T p) ⊆ ns› ‹fst ` set (vs::(variable × typ) list) ⊆ (ns::variable set)› ‹replay' thy vs ns Hs (Abst T p) = Some res›*) ‹ns' = insert s' ns› (*‹ns' = insert s' ns›*) apply fastforce (*top goal: ‹fst ` FV (set Hs) ⊆ ns'› and 3 goals remain*) using "3.prems"(7) (*‹fst ` set (vs::(variable × typ) list) ⊆ (ns::variable set)›*) ‹ns' = insert s' ns› (*‹(ns'::variable set) = insert (s'::variable) (ns::variable set)›*) apply ((auto)[1]) (*top goal: ‹fst ` fv_Proof p ⊆ ns'› and 2 goals remain*) using "3.prems"(8) (*‹replay' thy vs ns Hs (Abst T p) = Some res›*) ‹ns' = insert s' ns› (*‹ns' = insert s' ns›*) apply ((auto)[1]) (*top goal: ‹⋀a b. ⟦fst ` set vs ⊆ ns; ns' = insert s' ns; (a, b) ∈ fv_Proof p; a ∉ ns⟧ ⟹ a = s'› and 2 goals remain*) using "3.prems"(6) (*‹fst ` fv_Proof (Abst (T::typ) (p::proofterm)) ⊆ (ns::variable set)›*) apply fastforce (*top goal: ‹⋀(a::variable) b::typ. ⟦fst ` set (vs::(variable × typ) list) ⊆ (ns::variable set); (a, b) ∈ fv_Proof (p::proofterm); a ∉ ns; (if typ_ok_sig (sig (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set)) (T::typ) then let (s'::variable, ns'::variable set) = variant_variable (Free STR ''default'') ns in map_option (mk_all s' T) (replay' thy ((s', T) # vs) ns' (Hs::Core.term list) p) else None) = Some (res::Core.term); (ns'::variable set) = insert (s'::variable) ns⟧ ⟹ a = s'› and 2 goals remain*) using "3.prems"(7) (*‹fst ` set vs ⊆ ns›*) ‹ns' = insert s' ns› (*‹ns' = insert s' ns›*) apply ((auto)[1]) (*top goal: ‹fst ` set ((s'::variable, T::typ) # (vs::(variable × typ) list)) ⊆ (ns'::variable set)› and 1 goal remains*) using "3.prems"(8) (*‹replay' thy vs ns Hs (Abst T p) = Some res›*) ‹ns' = insert s' ns› (*‹ns' = insert s' ns›*) apply ((auto)[1]) (*goal: ‹replay' thy ((s', T) # vs) ns' Hs p = Some bres›*) using bres (*‹replay' thy ((s', T) # vs) ns' Hs p = Some bres›*) by fastforce have res: "res = mk_all s' T bres" using names (*‹(s', ns') = variant_variable (Free STR ''default'') ns›*) bres (*‹replay' thy ((s', T) # vs) ns' Hs p = Some bres›*) "3" (*‹⟦typ_ok thy T; ?x = variant_variable (Free STR ''default'') ns; (?xa, ?y) = ?x; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ?y; fst ` FV (set Hs) ⊆ ?y; fst ` fv_Proof p ⊆ ?y; fst ` set ((?xa, T) # vs) ⊆ ?y; replay' thy ((?xa, T) # vs) ?y Hs p = Some ?res⟧ ⟹ thy,set Hs ⊢ ?res› ‹wf_theory thy› ‹(?x::Core.term) ∈ set (Hs::Core.term list) ⟹ term_ok (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite ns› ‹fst ` FV (set (Hs::Core.term list)) ⊆ (ns::variable set)› ‹fst ` fv_Proof (Abst T p) ⊆ ns› ‹fst ` set vs ⊆ ns› ‹replay' thy vs ns Hs (Abst T p) = Some res›*) by (auto split: if_splits (*‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹(?P::?'a ⇒ bool) (if ?Q::bool then ?x::?'a else (?y::?'a)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) prod.splits (*‹(?P::?'c ⇒ bool) (case ?prod::?'a × ?'b of (x::?'a, xa::?'b) ⇒ (?f::?'a ⇒ ?'b ⇒ ?'c) x xa) = (∀(x1::?'a) x2::?'b. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹(?P::?'c ⇒ bool) (case ?prod::?'a × ?'b of (x::?'a, xa::?'b) ⇒ (?f::?'a ⇒ ?'b ⇒ ?'c) x xa) = (∄(x1::?'a) x2::?'b. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*)) show "?case" (*goal: ‹thy,set Hs ⊢ res›*) using proves.forall_intro[OF ‹wf_theory thy› I free typ_ok] (*‹thy,set Hs ⊢ mk_all s' T bres›*) res (*‹res = mk_all s' T bres›*) by simp next (*goals: 1. ‹⋀thy vs ns Hs p t res. ⟦⋀res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p = Some res⟧ ⟹ thy,set Hs ⊢ res; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (Appt p t) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (Appt p t) = Some res⟧ ⟹ thy,set Hs ⊢ res› 2. ‹⋀thy vs ns Hs t p res. ⟦⋀x res. ⟦x = subst_bvs (map (λ(x, y). Fv x y) vs) t; wf_theory thy; ⋀xa. xa ∈ set (x # Hs) ⟹ term_ok thy xa; ⋀xa. xa ∈ set (x # Hs) ⟹ typ_of xa = Some propT; finite ns; fst ` FV (set (x # Hs)) ⊆ ns; fst ` fv_Proof p ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns (x # Hs) p = Some res⟧ ⟹ thy,set (x # Hs) ⊢ res; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AbsP t p) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (AbsP t p) = Some res⟧ ⟹ thy,set Hs ⊢ res› 3. ‹⋀thy vs ns Hs p1 p2 res. ⟦⋀res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p1 ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p1 = Some res⟧ ⟹ thy,set Hs ⊢ res; ⋀x res. ⟦x = Option.bind (replay' thy vs ns Hs p1) beta_eta_norm; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p2 ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p2 = Some res⟧ ⟹ thy,set Hs ⊢ res; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AppP p1 p2) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (AppP p1 p2) = Some res⟧ ⟹ thy,set Hs ⊢ res› 4. ‹⋀thy vs ns Hs ty c res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (OfClass ty c) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (OfClass ty c) = Some res⟧ ⟹ thy,set Hs ⊢ res› 5. ‹⋀thy vs ns Hs t res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (Hyp t) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (Hyp t) = Some res⟧ ⟹ thy,set Hs ⊢ res›*) case (4 thy vs ns Hs p t) (*‹⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p = Some ?res⟧ ⟹ thy,set Hs ⊢ ?res› ‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite ns› ‹fst ` FV (set Hs) ⊆ ns› ‹fst ` fv_Proof (Appt (p::proofterm) (t::Core.term)) ⊆ (ns::variable set)› ‹fst ` set (vs::(variable × typ) list) ⊆ (ns::variable set)› ‹replay' thy vs ns Hs (Appt p t) = Some res›*) from ‹replay' thy vs ns Hs (Appt p t) = Some res› (*‹replay' thy vs ns Hs (Appt p t) = Some res›*) obtain rep and t' and b and s and fun1 and fun2 and propT1 and propT2 and τ and τ' where conds: "replay' thy vs ns Hs p = Some rep" "t' = subst_bvs (map (λ(x,y) . Fv x y) vs) t" "typ_of t' = Some τ'" "τ = τ'" "term_ok thy t'" "s= STR ''Pure.all'' ∧ fun1 = STR ''fun'' ∧ fun2 = STR ''fun'' ∧ propT1 = STR ''prop'' ∧ propT2 = STR ''prop''" "rep = Ct s (Ty fun1 [Ty fun2 [τ, Ty propT1 Nil], Ty propT2 Nil]) $ b" and res: "res = (b ∙ t')" (*goal: ‹(⋀(rep::Core.term) (t'::Core.term) (τ'::typ) (τ::typ) (s::String.literal) (fun1::String.literal) (fun2::String.literal) (propT1::String.literal) (propT2::String.literal) b::Core.term. ⟦replay' (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (vs::(variable × typ) list) (ns::variable set) (Hs::Core.term list) (p::proofterm) = Some rep; t' = subst_bvs (map (λ(x::variable, y::typ). Fv x y) vs) (t::Core.term); typ_of t' = Some τ'; τ = τ'; term_ok thy t'; s = STR ''Pure.all'' ∧ fun1 = STR ''fun'' ∧ fun2 = STR ''fun'' ∧ propT1 = STR ''prop'' ∧ propT2 = STR ''prop''; rep = Ct s (Ty fun1 [Ty fun2 [τ, constT propT1], constT propT2]) $ b; (res::Core.term) = b ∙ t'⟧ ⟹ thesis::bool) ⟹ thesis›*) by (auto split: term.splits (*‹?P (case ?term of Ct x xa ⇒ ?f1.0 x xa | Fv x xa ⇒ ?f2.0 x xa | Bv x ⇒ ?f3.0 x | Abs x xa ⇒ ?f4.0 x xa | x $ xa ⇒ ?f5.0 x xa) = ((∀x11 x12. ?term = Ct x11 x12 ⟶ ?P (?f1.0 x11 x12)) ∧ (∀x21 x22. ?term = Fv x21 x22 ⟶ ?P (?f2.0 x21 x22)) ∧ (∀x3. ?term = Bv x3 ⟶ ?P (?f3.0 x3)) ∧ (∀x41 x42. ?term = Abs x41 x42 ⟶ ?P (?f4.0 x41 x42)) ∧ (∀x51 x52. ?term = x51 $ x52 ⟶ ?P (?f5.0 x51 x52)))› ‹?P (case ?term of Ct x xa ⇒ ?f1.0 x xa | Fv x xa ⇒ ?f2.0 x xa | Bv x ⇒ ?f3.0 x | Abs x xa ⇒ ?f4.0 x xa | x $ xa ⇒ ?f5.0 x xa) = (¬ ((∃x11 x12. ?term = Ct x11 x12 ∧ ¬ ?P (?f1.0 x11 x12)) ∨ (∃x21 x22. ?term = Fv x21 x22 ∧ ¬ ?P (?f2.0 x21 x22)) ∨ (∃x3. ?term = Bv x3 ∧ ¬ ?P (?f3.0 x3)) ∨ (∃x41 x42. ?term = Abs x41 x42 ∧ ¬ ?P (?f4.0 x41 x42)) ∨ (∃x51 x52. ?term = x51 $ x52 ∧ ¬ ?P (?f5.0 x51 x52))))›*) typ.splits (*‹?P (case ?typ of Ty x xa ⇒ ?f1.0 x xa | Tv x xa ⇒ ?f2.0 x xa) = ((∀x11 x12. ?typ = Ty x11 x12 ⟶ ?P (?f1.0 x11 x12)) ∧ (∀x21 x22. ?typ = Tv x21 x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?typ of Ty x xa ⇒ ?f1.0 x xa | Tv x xa ⇒ ?f2.0 x xa) = (¬ ((∃x11 x12. ?typ = Ty x11 x12 ∧ ¬ ?P (?f1.0 x11 x12)) ∨ (∃x21 x22. ?typ = Tv x21 x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*) list.splits (*‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = ((?list = [] ⟶ ?P ?f1.0) ∧ (∀x21 x22. ?list = x21 # x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = (¬ (?list = [] ∧ ¬ ?P ?f1.0 ∨ (∃x21 x22. ?list = x21 # x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*) if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) simp add: Let_def (*‹Let ?s ?f ≡ ?f ?s›*)) have ctxt: "finite (set Hs)" "∀A ∈ set Hs . term_ok thy A" "∀A ∈ set Hs . typ_of A = Some propT" using "4" (*‹⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p = Some ?res⟧ ⟹ thy,set Hs ⊢ ?res› ‹wf_theory (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set)› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite ns› ‹fst ` FV (set Hs) ⊆ ns› ‹fst ` fv_Proof (Appt p t) ⊆ ns› ‹fst ` set (vs::(variable × typ) list) ⊆ (ns::variable set)› ‹replay' thy vs ns Hs (Appt p t) = Some res›*) apply - (*goals: 1. ‹⟦⋀res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p = Some res⟧ ⟹ thy,set Hs ⊢ res; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (Appt p t) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (Appt p t) = Some res⟧ ⟹ finite (set Hs)› 2. ‹⟦⋀res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p = Some res⟧ ⟹ thy,set Hs ⊢ res; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (Appt p t) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (Appt p t) = Some res⟧ ⟹ ∀A∈set Hs. term_ok thy A› 3. ‹⟦⋀res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p = Some res⟧ ⟹ thy,set Hs ⊢ res; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (Appt p t) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (Appt p t) = Some res⟧ ⟹ ∀A∈set Hs. typ_of A = Some propT› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . show "?case" (*goal: ‹thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set,set (Hs::Core.term list) ⊢ res::Core.term›*) using conds (*‹replay' thy vs ns Hs p = Some rep› ‹t' = subst_bvs (map (λ(x, y). Fv x y) vs) t› ‹typ_of t' = Some τ'› ‹(τ::typ) = (τ'::typ)› ‹term_ok thy t'› ‹s = STR ''Pure.all'' ∧ fun1 = STR ''fun'' ∧ fun2 = STR ''fun'' ∧ propT1 = STR ''prop'' ∧ propT2 = STR ''prop''› ‹rep = Ct s (Ty fun1 [Ty fun2 [τ, constT propT1], constT propT2]) $ b›*) "4.prems" (*‹wf_theory thy› ‹(?x::Core.term) ∈ set (Hs::Core.term list) ⟹ term_ok (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) ?x› ‹(?x::Core.term) ∈ set (Hs::Core.term list) ⟹ typ_of ?x = Some propT› ‹finite ns› ‹fst ` FV (set Hs) ⊆ ns› ‹fst ` fv_Proof (Appt p t) ⊆ ns› ‹fst ` set vs ⊆ ns› ‹replay' thy vs ns Hs (Appt p t) = Some res›*) ctxt (*‹finite (set Hs)› ‹∀A∈set Hs. term_ok thy A› ‹∀A∈set Hs. typ_of A = Some propT›*) by (auto simp add: res (*‹res = b ∙ t'›*) wt_term_def (*‹wt_term ?Σ ?t ≡ wf_term ?Σ ?t ∧ (∃T. ⊢⇩τ ?t : T)›*) simp del: FV_def (*‹FV ?S = ⋃ (fv ` ?S)›*) intro!: forall_elim'[OF "4.prems"(1) _ _ _ ctxt] (*‹⟦thy,set Hs ⊢ Ct STR ''Pure.all'' ((?τ → propT) → propT) $ ?B; ⊢⇩τ ?a : ?τ; wf_term (sig thy) ?a⟧ ⟹ thy,set Hs ⊢ ?B ∙ ?a›*) "4.IH" (*‹⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p = Some ?res⟧ ⟹ thy,set Hs ⊢ ?res›*)) next (*goals: 1. ‹⋀thy vs ns Hs t p res. ⟦⋀x res. ⟦x = subst_bvs (map (λ(x, y). Fv x y) vs) t; wf_theory thy; ⋀xa. xa ∈ set (x # Hs) ⟹ term_ok thy xa; ⋀xa. xa ∈ set (x # Hs) ⟹ typ_of xa = Some propT; finite ns; fst ` FV (set (x # Hs)) ⊆ ns; fst ` fv_Proof p ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns (x # Hs) p = Some res⟧ ⟹ thy,set (x # Hs) ⊢ res; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AbsP t p) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (AbsP t p) = Some res⟧ ⟹ thy,set Hs ⊢ res› 2. ‹⋀thy vs ns Hs p1 p2 res. ⟦⋀res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p1 ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p1 = Some res⟧ ⟹ thy,set Hs ⊢ res; ⋀x res. ⟦x = Option.bind (replay' thy vs ns Hs p1) beta_eta_norm; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p2 ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p2 = Some res⟧ ⟹ thy,set Hs ⊢ res; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AppP p1 p2) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (AppP p1 p2) = Some res⟧ ⟹ thy,set Hs ⊢ res› 3. ‹⋀thy vs ns Hs ty c res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (OfClass ty c) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (OfClass ty c) = Some res⟧ ⟹ thy,set Hs ⊢ res› 4. ‹⋀thy vs ns Hs t res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (Hyp t) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (Hyp t) = Some res⟧ ⟹ thy,set Hs ⊢ res›*) case (5 thy vs ns Hs t p) (*‹⟦?x = subst_bvs (map (λ(x, y). Fv x y) vs) t; wf_theory thy; ⋀x. x ∈ set (?x # Hs) ⟹ term_ok thy x; ⋀x. x ∈ set (?x # Hs) ⟹ typ_of x = Some propT; finite ns; fst ` FV (set (?x # Hs)) ⊆ ns; fst ` fv_Proof p ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns (?x # Hs) p = Some ?res⟧ ⟹ thy,set (?x # Hs) ⊢ ?res› ‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite ns› ‹fst ` FV (set (Hs::Core.term list)) ⊆ (ns::variable set)› ‹fst ` fv_Proof (AbsP t p) ⊆ ns› ‹fst ` set vs ⊆ ns› ‹replay' thy vs ns Hs (AbsP t p) = Some res›*) from this (*‹⟦?x = subst_bvs (map (λ(x, y). Fv x y) vs) t; wf_theory thy; ⋀x. x ∈ set (?x # Hs) ⟹ term_ok thy x; ⋀x. x ∈ set (?x # Hs) ⟹ typ_of x = Some propT; finite ns; fst ` FV (set (?x # Hs)) ⊆ ns; fst ` fv_Proof p ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns (?x # Hs) p = Some ?res⟧ ⟹ thy,set (?x # Hs) ⊢ ?res› ‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite (ns::variable set)› ‹fst ` FV (set Hs) ⊆ ns› ‹fst ` fv_Proof (AbsP t p) ⊆ ns› ‹fst ` set vs ⊆ ns› ‹replay' thy vs ns Hs (AbsP t p) = Some res›*) obtain t' and rep where conds: "subst_bvs (map (λ(x,y) . Fv x y) vs) t = t'" "replay' thy vs ns (t'#Hs) p = Some rep" "typ_of t' = Some propT" "term_ok thy t'" and res: "res = mk_imp t' rep" (*goal: ‹(⋀t' rep. ⟦subst_bvs (map (λ(x, y). Fv x y) vs) t = t'; replay' thy vs ns (t' # Hs) p = Some rep; typ_of t' = Some propT; term_ok thy t'; res = t' ⟼ rep⟧ ⟹ thesis) ⟹ thesis›*) by (auto split: term.splits (*‹?P (case ?term of Ct x xa ⇒ ?f1.0 x xa | Fv x xa ⇒ ?f2.0 x xa | Bv x ⇒ ?f3.0 x | Abs x xa ⇒ ?f4.0 x xa | x $ xa ⇒ ?f5.0 x xa) = ((∀x11 x12. ?term = Ct x11 x12 ⟶ ?P (?f1.0 x11 x12)) ∧ (∀x21 x22. ?term = Fv x21 x22 ⟶ ?P (?f2.0 x21 x22)) ∧ (∀x3. ?term = Bv x3 ⟶ ?P (?f3.0 x3)) ∧ (∀x41 x42. ?term = Abs x41 x42 ⟶ ?P (?f4.0 x41 x42)) ∧ (∀x51 x52. ?term = x51 $ x52 ⟶ ?P (?f5.0 x51 x52)))› ‹?P (case ?term of Ct x xa ⇒ ?f1.0 x xa | Fv x xa ⇒ ?f2.0 x xa | Bv x ⇒ ?f3.0 x | Abs x xa ⇒ ?f4.0 x xa | x $ xa ⇒ ?f5.0 x xa) = (¬ ((∃x11 x12. ?term = Ct x11 x12 ∧ ¬ ?P (?f1.0 x11 x12)) ∨ (∃x21 x22. ?term = Fv x21 x22 ∧ ¬ ?P (?f2.0 x21 x22)) ∨ (∃x3. ?term = Bv x3 ∧ ¬ ?P (?f3.0 x3)) ∨ (∃x41 x42. ?term = Abs x41 x42 ∧ ¬ ?P (?f4.0 x41 x42)) ∨ (∃x51 x52. ?term = x51 $ x52 ∧ ¬ ?P (?f5.0 x51 x52))))›*) typ.splits (*‹?P (case ?typ of Ty x xa ⇒ ?f1.0 x xa | Tv x xa ⇒ ?f2.0 x xa) = ((∀x11 x12. ?typ = Ty x11 x12 ⟶ ?P (?f1.0 x11 x12)) ∧ (∀x21 x22. ?typ = Tv x21 x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?typ of Ty x xa ⇒ ?f1.0 x xa | Tv x xa ⇒ ?f2.0 x xa) = (¬ ((∃x11 x12. ?typ = Ty x11 x12 ∧ ¬ ?P (?f1.0 x11 x12)) ∨ (∃x21 x22. ?typ = Tv x21 x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*) list.splits (*‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = ((?list = [] ⟶ ?P ?f1.0) ∧ (∀x21 x22. ?list = x21 # x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = (¬ (?list = [] ∧ ¬ ?P ?f1.0 ∨ (∃x21 x22. ?list = x21 # x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*) if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) simp add: Let_def (*‹Let ?s ?f ≡ ?f ?s›*)) show "?case" (*goal: ‹thy,set Hs ⊢ res›*) proof (cases "t'∈ set Hs") (*goals: 1. ‹t' ∈ set Hs ⟹ thy,set Hs ⊢ res› 2. ‹t' ∉ set Hs ⟹ thy,set Hs ⊢ res›*) case True (*‹t' ∈ set Hs›*) hence s: "set Hs = set (t' # Hs)" by auto hence s': "set Hs = insert t' (set Hs -{t'})" by auto have "thy,set (t' # Hs) ⊢ rep" apply (rule "5.IH" (*‹⟦?x = subst_bvs (map (λ(x, y). Fv x y) vs) t; wf_theory thy; ⋀x. x ∈ set (?x # Hs) ⟹ term_ok thy x; ⋀x. x ∈ set (?x # Hs) ⟹ typ_of x = Some propT; finite ns; fst ` FV (set (?x # Hs)) ⊆ ns; fst ` fv_Proof p ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns (?x # Hs) p = Some ?res⟧ ⟹ thy,set (?x # Hs) ⊢ ?res›*)) (*goal: ‹thy,set (t' # Hs) ⊢ rep›*) using conds(4) (*‹term_ok (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (t'::Core.term)›*) "5.prems" (*‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite (ns::variable set)› ‹fst ` FV (set Hs) ⊆ ns› ‹fst ` fv_Proof (AbsP t p) ⊆ ns› ‹fst ` set (vs::(variable × typ) list) ⊆ (ns::variable set)› ‹replay' thy vs ns Hs (AbsP t p) = Some res›*) True (*‹t' ∈ set Hs›*) apply - (*goals: 1. ‹⟦term_ok (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (t'::Core.term); wf_theory thy; ⋀x::Core.term. x ∈ set (Hs::Core.term list) ⟹ term_ok thy x; ⋀x::Core.term. x ∈ set Hs ⟹ typ_of x = Some propT; finite (ns::variable set); fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AbsP (t::Core.term) (p::proofterm)) ⊆ ns; fst ` set (vs::(variable × typ) list) ⊆ ns; replay' thy vs ns Hs (AbsP t p) = Some (res::Core.term); t' ∈ set Hs⟧ ⟹ t' = subst_bvs (map (λ(x::variable, y::typ). Fv x y) vs) t› 2. ‹⟦term_ok (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (t'::Core.term); wf_theory thy; ⋀x::Core.term. x ∈ set (Hs::Core.term list) ⟹ term_ok thy x; ⋀x::Core.term. x ∈ set Hs ⟹ typ_of x = Some propT; finite (ns::variable set); fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AbsP (t::Core.term) (p::proofterm)) ⊆ ns; fst ` set (vs::(variable × typ) list) ⊆ ns; replay' thy vs ns Hs (AbsP t p) = Some (res::Core.term); t' ∈ set Hs⟧ ⟹ wf_theory thy› 3. ‹⋀x::Core.term. ⟦x ∈ set ((t'::Core.term) # (Hs::Core.term list)); term_ok (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) t'; wf_theory thy; ⋀x::Core.term. x ∈ set Hs ⟹ term_ok thy x; ⋀x::Core.term. x ∈ set Hs ⟹ typ_of x = Some propT; finite (ns::variable set); fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AbsP (t::Core.term) (p::proofterm)) ⊆ ns; fst ` set (vs::(variable × typ) list) ⊆ ns; replay' thy vs ns Hs (AbsP t p) = Some (res::Core.term); t' ∈ set Hs⟧ ⟹ term_ok thy x› 4. ‹⋀x::Core.term. ⟦x ∈ set ((t'::Core.term) # (Hs::Core.term list)); term_ok (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) t'; wf_theory thy; ⋀x::Core.term. x ∈ set Hs ⟹ term_ok thy x; ⋀x::Core.term. x ∈ set Hs ⟹ typ_of x = Some propT; finite (ns::variable set); fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AbsP (t::Core.term) (p::proofterm)) ⊆ ns; fst ` set (vs::(variable × typ) list) ⊆ ns; replay' thy vs ns Hs (AbsP t p) = Some (res::Core.term); t' ∈ set Hs⟧ ⟹ typ_of x = Some propT› 5. ‹⟦term_ok (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (t'::Core.term); wf_theory thy; ⋀x::Core.term. x ∈ set (Hs::Core.term list) ⟹ term_ok thy x; ⋀x::Core.term. x ∈ set Hs ⟹ typ_of x = Some propT; finite (ns::variable set); fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AbsP (t::Core.term) (p::proofterm)) ⊆ ns; fst ` set (vs::(variable × typ) list) ⊆ ns; replay' thy vs ns Hs (AbsP t p) = Some (res::Core.term); t' ∈ set Hs⟧ ⟹ finite ns› 6. ‹⟦term_ok (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (t'::Core.term); wf_theory thy; ⋀x::Core.term. x ∈ set (Hs::Core.term list) ⟹ term_ok thy x; ⋀x::Core.term. x ∈ set Hs ⟹ typ_of x = Some propT; finite (ns::variable set); fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AbsP (t::Core.term) (p::proofterm)) ⊆ ns; fst ` set (vs::(variable × typ) list) ⊆ ns; replay' thy vs ns Hs (AbsP t p) = Some (res::Core.term); t' ∈ set Hs⟧ ⟹ fst ` FV (set (t' # Hs)) ⊆ ns› 7. ‹⟦term_ok (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (t'::Core.term); wf_theory thy; ⋀x::Core.term. x ∈ set (Hs::Core.term list) ⟹ term_ok thy x; ⋀x::Core.term. x ∈ set Hs ⟹ typ_of x = Some propT; finite (ns::variable set); fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AbsP (t::Core.term) (p::proofterm)) ⊆ ns; fst ` set (vs::(variable × typ) list) ⊆ ns; replay' thy vs ns Hs (AbsP t p) = Some (res::Core.term); t' ∈ set Hs⟧ ⟹ fst ` fv_Proof p ⊆ ns› 8. ‹⟦term_ok (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (t'::Core.term); wf_theory thy; ⋀x::Core.term. x ∈ set (Hs::Core.term list) ⟹ term_ok thy x; ⋀x::Core.term. x ∈ set Hs ⟹ typ_of x = Some propT; finite (ns::variable set); fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AbsP (t::Core.term) (p::proofterm)) ⊆ ns; fst ` set (vs::(variable × typ) list) ⊆ ns; replay' thy vs ns Hs (AbsP t p) = Some (res::Core.term); t' ∈ set Hs⟧ ⟹ fst ` set vs ⊆ ns› 9. ‹⟦term_ok (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (t'::Core.term); wf_theory thy; ⋀x::Core.term. x ∈ set (Hs::Core.term list) ⟹ term_ok thy x; ⋀x::Core.term. x ∈ set Hs ⟹ typ_of x = Some propT; finite (ns::variable set); fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AbsP (t::Core.term) (p::proofterm)) ⊆ ns; fst ` set (vs::(variable × typ) list) ⊆ ns; replay' thy vs ns Hs (AbsP t p) = Some (res::Core.term); t' ∈ set Hs⟧ ⟹ replay' thy vs ns (t' # Hs) p = Some (rep::Core.term)› discuss goal 1*) apply ((auto simp add: conds( (*‹subst_bvs (map (λ(x::variable, y::typ). Fv x y) (vs::(variable × typ) list)) (t::Core.term) = (t'::Core.term)›*) 1) conds(2)[symmetric] (*‹Some (rep::Core.term) = replay' (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (vs::(variable × typ) list) (ns::variable set) ((t'::Core.term) # (Hs::Core.term list)) (p::proofterm)›*) conds( (*‹typ_of (t'::Core.term) = Some propT›*) 3))[1]) (*discuss goal 2*) apply ((auto simp add: conds( (*‹subst_bvs (map (λ(x, y). Fv x y) vs) t = t'›*) 1) conds(2)[symmetric] (*‹Some rep = replay' thy vs ns (t' # Hs) p›*) conds( (*‹typ_of t' = Some propT›*) 3))[1]) (*discuss goal 3*) apply ((auto simp add: conds( (*‹subst_bvs (map (λ(x, y). Fv x y) vs) t = t'›*) 1) conds(2)[symmetric] (*‹Some rep = replay' thy vs ns (t' # Hs) p›*) conds( (*‹typ_of t' = Some propT›*) 3))[1]) (*discuss goal 4*) apply ((auto simp add: conds( (*‹subst_bvs (map (λ(x, y). Fv x y) vs) t = t'›*) 1) conds(2)[symmetric] (*‹Some rep = replay' thy vs ns (t' # Hs) p›*) conds( (*‹typ_of t' = Some propT›*) 3))[1]) (*discuss goal 5*) apply ((auto simp add: conds( (*‹subst_bvs (map (λ(x, y). Fv x y) vs) t = t'›*) 1) conds(2)[symmetric] (*‹Some rep = replay' thy vs ns (t' # Hs) p›*) conds( (*‹typ_of t' = Some propT›*) 3))[1]) (*discuss goal 6*) apply ((auto simp add: conds( (*‹subst_bvs (map (λ(x, y). Fv x y) vs) t = t'›*) 1) conds(2)[symmetric] (*‹Some rep = replay' thy vs ns (t' # Hs) p›*) conds( (*‹typ_of t' = Some propT›*) 3))[1]) (*discuss goal 7*) apply ((auto simp add: conds( (*‹subst_bvs (map (λ(x::variable, y::typ). Fv x y) (vs::(variable × typ) list)) (t::Core.term) = (t'::Core.term)›*) 1) conds(2)[symmetric] (*‹Some (rep::Core.term) = replay' (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (vs::(variable × typ) list) (ns::variable set) ((t'::Core.term) # (Hs::Core.term list)) (p::proofterm)›*) conds( (*‹typ_of (t'::Core.term) = Some propT›*) 3))[1]) (*discuss goal 8*) apply ((auto simp add: conds( (*‹subst_bvs (map (λ(x::variable, y::typ). Fv x y) (vs::(variable × typ) list)) (t::Core.term) = (t'::Core.term)›*) 1) conds(2)[symmetric] (*‹Some (rep::Core.term) = replay' (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (vs::(variable × typ) list) (ns::variable set) ((t'::Core.term) # (Hs::Core.term list)) (p::proofterm)›*) conds( (*‹typ_of (t'::Core.term) = Some propT›*) 3))[1]) (*discuss goal 9*) apply ((auto simp add: conds( (*‹subst_bvs (map (λ(x::variable, y::typ). Fv x y) (vs::(variable × typ) list)) (t::Core.term) = (t'::Core.term)›*) 1) conds(2)[symmetric] (*‹Some (rep::Core.term) = replay' (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (vs::(variable × typ) list) (ns::variable set) ((t'::Core.term) # (Hs::Core.term list)) (p::proofterm)›*) conds( (*‹typ_of (t'::Core.term) = Some propT›*) 3))[1]) (*proven 9 subgoals*) . hence "thy,set Hs - {t'} ⊢ t' ⟼ rep" using implies_intro (*‹⟦wf_theory ?Θ; ?Θ,?Γ ⊢ ?B; wf_term (sig ?Θ) ?A; ⊢⇩τ ?A : propT⟧ ⟹ ?Θ,?Γ - {?A} ⊢ ?A ⟼ ?B›*) "5.prems"(1) (*‹wf_theory thy›*) "5.prems"(4) (*‹finite (ns::variable set)›*) conds(3) (*‹typ_of t' = Some propT›*) conds(4) (*‹term_ok thy t'›*) s (*‹set (Hs::Core.term list) = set ((t'::Core.term) # Hs)›*) using has_typ_iff_typ_of (*‹⊢⇩τ ?t : ?ty = (typ_of ?t = Some ?ty)›*) term_ok'_imp_wf_term (*‹term_ok' ?Σ ?t ⟹ wf_term ?Σ ?t›*) term_okD1 (*‹term_ok ?Θ ?t ⟹ term_ok' (sig ?Θ) ?t›*) by presburger then show "?thesis" (*goal: ‹thy,set Hs ⊢ res›*) apply (subst res (*‹res = t' ⟼ rep›*)) (*goal: ‹thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set,set (Hs::Core.term list) ⊢ res::Core.term›*) apply (subst s' (*‹set Hs = insert t' (set Hs - {t'})›*)) (*goal: ‹thy,set Hs - {t'} ⊢ t' ⟼ rep ⟹ thy,set Hs ⊢ t' ⟼ rep›*) apply (rule weaken_proves (*‹⟦?Θ,?Γ ⊢ ?B; term_ok ?Θ ?A; typ_of ?A = Some propT; finite ?Γ⟧ ⟹ ?Θ,insert ?A ?Γ ⊢ ?B›*)) (*goal: ‹thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set,set (Hs::Core.term list) - {t'::Core.term} ⊢ t' ⟼ (rep::Core.term) ⟹ thy,insert t' (set Hs - {t'}) ⊢ t' ⟼ rep›*) using conds(3-4) (*‹typ_of t' = Some propT› ‹term_ok thy t'›*) apply - (*goals: 1. ‹⟦thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set,set (Hs::Core.term list) - {t'::Core.term} ⊢ t' ⟼ (rep::Core.term); typ_of t' = Some propT; term_ok thy t'⟧ ⟹ thy,set Hs - {t'} ⊢ t' ⟼ rep› 2. ‹⟦thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set,set (Hs::Core.term list) - {t'::Core.term} ⊢ t' ⟼ (rep::Core.term); typ_of t' = Some propT; term_ok thy t'⟧ ⟹ term_ok thy t'› 3. ‹⟦thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set,set (Hs::Core.term list) - {t'::Core.term} ⊢ t' ⟼ (rep::Core.term); typ_of t' = Some propT; term_ok thy t'⟧ ⟹ typ_of t' = Some propT› 4. ‹⟦thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set,set (Hs::Core.term list) - {t'::Core.term} ⊢ t' ⟼ (rep::Core.term); typ_of t' = Some propT; term_ok thy t'⟧ ⟹ finite (set Hs - {t'})› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*discuss goal 3*) apply blast (*discuss goal 4*) apply blast (*proven 4 subgoals*) . next (*goal: ‹t' ∉ set Hs ⟹ thy,set Hs ⊢ res›*) case False (*‹t' ∉ set Hs›*) hence s: "set Hs = insert t' (set Hs) - {t'}" by auto have "FV (set (map (λ(x,y) . Fv x y) vs)) = set vs" apply (induction vs) (*goals: 1. ‹FV (set (map (λa::variable × typ. case a of (x::variable, y::typ) ⇒ Fv x y) [])) = set []› 2. ‹⋀(a::variable × typ) vs::(variable × typ) list. FV (set (map (λa::variable × typ. case a of (x::variable, y::typ) ⇒ Fv x y) vs)) = set vs ⟹ FV (set (map (λa::variable × typ. case a of (x::variable, y::typ) ⇒ Fv x y) (a # vs))) = set (a # vs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . hence frees_bound: "fv t' ⊆ fv t ∪ set vs" using fv_subst_bvs1_upper_bound (*‹fv (subst_bvs1 ?t ?lev ?us) ⊆ fv ?t ∪ ⋃ (fv ` set ?us)›*) subst_bvs_def (*‹subst_bvs ?args ?t ≡ subst_bvs1 ?t 0 ?args›*) by (fastforce simp add: conds(1)[symmetric] (*‹t' = subst_bvs (map (λ(x, y). Fv x y) vs) t›*)) have pre: "thy,set (t' # Hs) ⊢ rep" apply (rule "5.IH" (*‹⟦(?x::Core.term) = subst_bvs (map (λ(x::variable, y::typ). Fv x y) (vs::(variable × typ) list)) (t::Core.term); wf_theory (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set); ⋀x::Core.term. x ∈ set (?x # (Hs::Core.term list)) ⟹ term_ok thy x; ⋀x::Core.term. x ∈ set (?x # Hs) ⟹ typ_of x = Some propT; finite (ns::variable set); fst ` FV (set (?x # Hs)) ⊆ ns; fst ` fv_Proof (p::proofterm) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns (?x # Hs) p = Some (?res::Core.term)⟧ ⟹ thy,set (?x # Hs) ⊢ ?res›*)) (*goal: ‹thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set,set ((t'::Core.term) # (Hs::Core.term list)) ⊢ rep::Core.term›*) using "5.prems"(5-8) (*‹fst ` FV (set Hs) ⊆ ns› ‹fst ` fv_Proof (AbsP t p) ⊆ ns› ‹fst ` set (vs::(variable × typ) list) ⊆ (ns::variable set)› ‹replay' thy vs ns Hs (AbsP t p) = Some res›*) conds(3-4) (*‹typ_of t' = Some propT› ‹term_ok thy t'›*) frees_bound (*‹fv t' ⊆ fv t ∪ set vs›*) apply - (*goals: 1. ‹⟦fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AbsP t p) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (AbsP t p) = Some res; typ_of t' = Some propT; term_ok thy t'; fv t' ⊆ fv t ∪ set vs⟧ ⟹ t' = subst_bvs (map (λ(x, y). Fv x y) vs) t› 2. ‹⟦fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AbsP t p) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (AbsP t p) = Some res; typ_of t' = Some propT; term_ok thy t'; fv t' ⊆ fv t ∪ set vs⟧ ⟹ wf_theory thy› 3. ‹⋀x. ⟦x ∈ set (t' # Hs); fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AbsP t p) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (AbsP t p) = Some res; typ_of t' = Some propT; term_ok thy t'; fv t' ⊆ fv t ∪ set vs⟧ ⟹ term_ok thy x› 4. ‹⋀x. ⟦x ∈ set (t' # Hs); fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AbsP t p) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (AbsP t p) = Some res; typ_of t' = Some propT; term_ok thy t'; fv t' ⊆ fv t ∪ set vs⟧ ⟹ typ_of x = Some propT› 5. ‹⟦fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AbsP t p) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (AbsP t p) = Some res; typ_of t' = Some propT; term_ok thy t'; fv t' ⊆ fv t ∪ set vs⟧ ⟹ finite ns› 6. ‹⟦fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AbsP t p) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (AbsP t p) = Some res; typ_of t' = Some propT; term_ok thy t'; fv t' ⊆ fv t ∪ set vs⟧ ⟹ fst ` FV (set (t' # Hs)) ⊆ ns› 7. ‹⟦fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AbsP t p) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (AbsP t p) = Some res; typ_of t' = Some propT; term_ok thy t'; fv t' ⊆ fv t ∪ set vs⟧ ⟹ fst ` fv_Proof p ⊆ ns› 8. ‹⟦fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AbsP t p) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (AbsP t p) = Some res; typ_of t' = Some propT; term_ok thy t'; fv t' ⊆ fv t ∪ set vs⟧ ⟹ fst ` set vs ⊆ ns› 9. ‹⟦fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AbsP t p) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (AbsP t p) = Some res; typ_of t' = Some propT; term_ok thy t'; fv t' ⊆ fv t ∪ set vs⟧ ⟹ replay' thy vs ns (t' # Hs) p = Some rep› discuss goal 1*) apply ((auto simp add: "5.prems" (*‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite ns›*) (1-4) conds( (*‹subst_bvs (map (λ(x, y). Fv x y) vs) t = t'›*) 1) conds( (*‹replay' thy vs ns (t' # Hs) p = Some rep›*) 2) image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*) simp del: term_ok_def (*‹term_ok ?Θ ?t ≡ wt_term (sig ?Θ) ?t›*))[1]) (*discuss goal 2*) apply ((auto simp add: "5.prems" (*‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite ns›*) (1-4) conds( (*‹subst_bvs (map (λ(x, y). Fv x y) vs) t = t'›*) 1) conds( (*‹replay' thy vs ns (t' # Hs) p = Some rep›*) 2) image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*) simp del: term_ok_def (*‹term_ok ?Θ ?t ≡ wt_term (sig ?Θ) ?t›*))[1]) (*discuss goal 3*) apply ((auto simp add: "5.prems" (*‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite ns›*) (1-4) conds( (*‹subst_bvs (map (λ(x, y). Fv x y) vs) t = t'›*) 1) conds( (*‹replay' thy vs ns (t' # Hs) p = Some rep›*) 2) image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*) simp del: term_ok_def (*‹term_ok ?Θ ?t ≡ wt_term (sig ?Θ) ?t›*))[1]) (*discuss goal 4*) apply ((auto simp add: "5.prems" (*‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite ns›*) (1-4) conds( (*‹subst_bvs (map (λ(x, y). Fv x y) vs) t = t'›*) 1) conds( (*‹replay' thy vs ns (t' # Hs) p = Some rep›*) 2) image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*) simp del: term_ok_def (*‹term_ok ?Θ ?t ≡ wt_term (sig ?Θ) ?t›*))[1]) (*discuss goal 5*) apply ((auto simp add: "5.prems" (*‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite ns›*) (1-4) conds( (*‹subst_bvs (map (λ(x, y). Fv x y) vs) t = t'›*) 1) conds( (*‹replay' thy vs ns (t' # Hs) p = Some rep›*) 2) image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*) simp del: term_ok_def (*‹term_ok ?Θ ?t ≡ wt_term (sig ?Θ) ?t›*))[1]) (*discuss goal 6*) apply ((auto simp add: "5.prems" (*‹wf_theory (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set)› ‹(?x::Core.term) ∈ set (Hs::Core.term list) ⟹ term_ok (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) ?x› ‹(?x::Core.term) ∈ set (Hs::Core.term list) ⟹ typ_of ?x = Some propT› ‹finite (ns::variable set)›*) (1-4) conds( (*‹subst_bvs (map (λ(x::variable, y::typ). Fv x y) (vs::(variable × typ) list)) (t::Core.term) = (t'::Core.term)›*) 1) conds( (*‹replay' (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (vs::(variable × typ) list) (ns::variable set) ((t'::Core.term) # (Hs::Core.term list)) (p::proofterm) = Some (rep::Core.term)›*) 2) image_subset_iff (*‹((?f::?'b ⇒ ?'a) ` (?A::?'b set) ⊆ (?B::?'a set)) = (∀x::?'b∈?A. ?f x ∈ ?B)›*) simp del: term_ok_def (*‹term_ok (?Θ::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (?t::Core.term) ≡ wt_term (sig ?Θ) ?t›*))[1]) (*discuss goal 7*) apply ((auto simp add: "5.prems" (*‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite ns›*) (1-4) conds( (*‹subst_bvs (map (λ(x, y). Fv x y) vs) t = t'›*) 1) conds( (*‹replay' thy vs ns (t' # Hs) p = Some rep›*) 2) image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*) simp del: term_ok_def (*‹term_ok ?Θ ?t ≡ wt_term (sig ?Θ) ?t›*))[1]) (*discuss goal 8*) apply ((auto simp add: "5.prems" (*‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite ns›*) (1-4) conds( (*‹subst_bvs (map (λ(x, y). Fv x y) vs) t = t'›*) 1) conds( (*‹replay' thy vs ns (t' # Hs) p = Some rep›*) 2) image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*) simp del: term_ok_def (*‹term_ok ?Θ ?t ≡ wt_term (sig ?Θ) ?t›*))[1]) (*discuss goal 9*) apply ((auto simp add: "5.prems" (*‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite ns›*) (1-4) conds( (*‹subst_bvs (map (λ(x, y). Fv x y) vs) t = t'›*) 1) conds( (*‹replay' thy vs ns (t' # Hs) p = Some rep›*) 2) image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*) simp del: term_ok_def (*‹term_ok ?Θ ?t ≡ wt_term (sig ?Θ) ?t›*))[1]) (*proven 9 subgoals*) . show "?thesis" (*goal: ‹thy,set Hs ⊢ res›*) apply (subst res (*‹(res::Core.term) = (t'::Core.term) ⟼ (rep::Core.term)›*)) (*goal: ‹thy,set Hs ⊢ res›*) apply (subst s (*‹set Hs = insert t' (set Hs) - {t'}›*)) (*goal: ‹thy,set Hs ⊢ t' ⟼ rep›*) apply (rule proves.implies_intro (*‹⟦wf_theory (?Θ::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set); ?Θ,?Γ::Core.term set ⊢ ?B::Core.term; wf_term (sig ?Θ) (?A::Core.term); ⊢⇩τ ?A : propT⟧ ⟹ ?Θ,?Γ - {?A} ⊢ ?A ⟼ ?B›*); use 5 conds in ‹(solves ‹simp add: wt_term_def›)?›) (*goal: ‹thy,insert t' (set Hs) - {t'} ⊢ t' ⟼ rep›*) using pre (*‹thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set,set ((t'::Core.term) # (Hs::Core.term list)) ⊢ rep::Core.term›*) by simp qed next (*goals: 1. ‹⋀thy vs ns Hs p1 p2 res. ⟦⋀res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p1 ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p1 = Some res⟧ ⟹ thy,set Hs ⊢ res; ⋀x res. ⟦x = Option.bind (replay' thy vs ns Hs p1) beta_eta_norm; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p2 ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p2 = Some res⟧ ⟹ thy,set Hs ⊢ res; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (AppP p1 p2) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (AppP p1 p2) = Some res⟧ ⟹ thy,set Hs ⊢ res› 2. ‹⋀thy vs ns Hs ty c res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (OfClass ty c) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (OfClass ty c) = Some res⟧ ⟹ thy,set Hs ⊢ res› 3. ‹⋀thy vs ns Hs t res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (Hyp t) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (Hyp t) = Some res⟧ ⟹ thy,set Hs ⊢ res›*) case (6 thy vs ns Hs p1 p2) (*‹⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p1 ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p1 = Some ?res⟧ ⟹ thy,set Hs ⊢ ?res› ‹⟦?x = Option.bind (replay' thy vs ns Hs p1) beta_eta_norm; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p2 ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p2 = Some ?res⟧ ⟹ thy,set Hs ⊢ ?res› ‹wf_theory thy› ‹(?x::Core.term) ∈ set (Hs::Core.term list) ⟹ term_ok (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite (ns::variable set)› ‹fst ` FV (set Hs) ⊆ ns› ‹fst ` fv_Proof (AppP p1 p2) ⊆ ns› ‹fst ` set (vs::(variable × typ) list) ⊆ (ns::variable set)› ‹replay' thy vs ns Hs (AppP p1 p2) = Some res›*) from ‹replay' thy vs ns Hs (AppP p1 p2) = Some res› (*‹replay' thy vs ns Hs (AppP p1 p2) = Some res›*) obtain fn1 and fn2 and prp1 and prp2 and prp3 and A and B and A' and imp where conds: "Option.bind (replay' thy vs ns Hs p1) beta_eta_norm = Some (Ct imp (Ty fn1 [Ty prp1 [], Ty fn2 [Ty prp2 [], Ty prp3 []]]) $ A $ B)" "Option.bind (replay' thy vs ns Hs p2) beta_eta_norm = Some A'" "imp = STR ''Pure.imp'' ∧ fn1 = STR ''fun'' ∧ fn2 = STR ''fun'' ∧ prp1 = STR ''prop'' ∧ prp2 = STR ''prop'' ∧ prp3 = STR ''prop'' ∧ A=A'" and res: "res = B" (*goal: ‹(⋀impa fn1 prp1 fn2 prp2 prp3 A B A'. ⟦Option.bind (replay' thy vs ns Hs p1) beta_eta_norm = Some (Ct impa (Ty fn1 [constT prp1, Ty fn2 [constT prp2, constT prp3]]) $ A $ B); Option.bind (replay' thy vs ns Hs p2) beta_eta_norm = Some A'; impa = STR ''Pure.imp'' ∧ fn1 = STR ''fun'' ∧ fn2 = STR ''fun'' ∧ prp1 = STR ''prop'' ∧ prp2 = STR ''prop'' ∧ prp3 = STR ''prop'' ∧ A = A'; res = B⟧ ⟹ thesis) ⟹ thesis›*) by (auto split: term.splits (*‹?P (case ?term of Ct x xa ⇒ ?f1.0 x xa | Fv x xa ⇒ ?f2.0 x xa | Bv x ⇒ ?f3.0 x | Abs x xa ⇒ ?f4.0 x xa | x $ xa ⇒ ?f5.0 x xa) = ((∀x11 x12. ?term = Ct x11 x12 ⟶ ?P (?f1.0 x11 x12)) ∧ (∀x21 x22. ?term = Fv x21 x22 ⟶ ?P (?f2.0 x21 x22)) ∧ (∀x3. ?term = Bv x3 ⟶ ?P (?f3.0 x3)) ∧ (∀x41 x42. ?term = Abs x41 x42 ⟶ ?P (?f4.0 x41 x42)) ∧ (∀x51 x52. ?term = x51 $ x52 ⟶ ?P (?f5.0 x51 x52)))› ‹?P (case ?term of Ct x xa ⇒ ?f1.0 x xa | Fv x xa ⇒ ?f2.0 x xa | Bv x ⇒ ?f3.0 x | Abs x xa ⇒ ?f4.0 x xa | x $ xa ⇒ ?f5.0 x xa) = (¬ ((∃x11 x12. ?term = Ct x11 x12 ∧ ¬ ?P (?f1.0 x11 x12)) ∨ (∃x21 x22. ?term = Fv x21 x22 ∧ ¬ ?P (?f2.0 x21 x22)) ∨ (∃x3. ?term = Bv x3 ∧ ¬ ?P (?f3.0 x3)) ∨ (∃x41 x42. ?term = Abs x41 x42 ∧ ¬ ?P (?f4.0 x41 x42)) ∨ (∃x51 x52. ?term = x51 $ x52 ∧ ¬ ?P (?f5.0 x51 x52))))›*) typ.splits (*‹?P (case ?typ of Ty x xa ⇒ ?f1.0 x xa | Tv x xa ⇒ ?f2.0 x xa) = ((∀x11 x12. ?typ = Ty x11 x12 ⟶ ?P (?f1.0 x11 x12)) ∧ (∀x21 x22. ?typ = Tv x21 x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?typ of Ty x xa ⇒ ?f1.0 x xa | Tv x xa ⇒ ?f2.0 x xa) = (¬ ((∃x11 x12. ?typ = Ty x11 x12 ∧ ¬ ?P (?f1.0 x11 x12)) ∨ (∃x21 x22. ?typ = Tv x21 x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*) list.splits (*‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = ((?list = [] ⟶ ?P ?f1.0) ∧ (∀x21 x22. ?list = x21 # x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = (¬ (?list = [] ∧ ¬ ?P ?f1.0 ∨ (∃x21 x22. ?list = x21 # x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*) if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*) simp add: Let_def (*‹Let ?s ?f ≡ ?f ?s›*)) obtain C where C: "Option.bind (replay' thy vs ns Hs p1) beta_eta_norm = Some (C ⟼ res)" (*goal: ‹(⋀C. Option.bind (replay' thy vs ns Hs p1) beta_eta_norm = Some (C ⟼ res) ⟹ thesis) ⟹ thesis›*) using conds (*‹Option.bind (replay' thy vs ns Hs p1) beta_eta_norm = Some (Ct imp (Ty fn1 [constT prp1, Ty fn2 [constT prp2, constT prp3]]) $ A $ B)› ‹Option.bind (replay' thy vs ns Hs p2) beta_eta_norm = Some A'› ‹imp = STR ''Pure.imp'' ∧ fn1 = STR ''fun'' ∧ fn2 = STR ''fun'' ∧ prp1 = STR ''prop'' ∧ prp2 = STR ''prop'' ∧ prp3 = STR ''prop'' ∧ A = A'›*) res (*‹res = B›*) by blast from this (*‹Option.bind (replay' thy vs ns Hs p1) beta_eta_norm = Some (C ⟼ res)›*) obtain pre and pre_C where pre: "replay' thy vs ns Hs p1 = Some pre" and pre_C: "replay' thy vs ns Hs p2 = Some pre_C" (*goal: ‹(⋀pre pre_C. ⟦replay' thy vs ns Hs p1 = Some pre; replay' thy vs ns Hs p2 = Some pre_C⟧ ⟹ thesis) ⟹ thesis›*) by (meson bind_eq_Some_conv (*‹(Option.bind (?f::?'b::type option) (?g::?'b::type ⇒ ?'a::type option) = Some (?x::?'a::type)) = (∃y::?'b::type. ?f = Some y ∧ ?g y = Some ?x)›*) conds( (*‹Option.bind (replay' (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (vs::(variable × typ) list) (ns::variable set) (Hs::Core.term list) (p2::proofterm)) beta_eta_norm = Some (A'::Core.term)›*) 2)) from pre (*‹replay' thy vs ns Hs p1 = Some pre›*) C (*‹Option.bind (replay' thy vs ns Hs p1) beta_eta_norm = Some (C ⟼ res)›*) have norm_pre: "beta_eta_norm pre = Some (C ⟼ res)" by simp from pre_C (*‹replay' thy vs ns Hs p2 = Some pre_C›*) pre (*‹replay' (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (vs::(variable × typ) list) (ns::variable set) (Hs::Core.term list) (p1::proofterm) = Some (pre::Core.term)›*) C (*‹Option.bind (replay' thy vs ns Hs p1) beta_eta_norm = Some (C ⟼ res)›*) conds (*‹Option.bind (replay' thy vs ns Hs p1) beta_eta_norm = Some (Ct imp (Ty fn1 [constT prp1, Ty fn2 [constT prp2, constT prp3]]) $ A $ B)› ‹Option.bind (replay' thy vs ns Hs p2) beta_eta_norm = Some A'› ‹imp = STR ''Pure.imp'' ∧ fn1 = STR ''fun'' ∧ fn2 = STR ''fun'' ∧ prp1 = STR ''prop'' ∧ prp2 = STR ''prop'' ∧ prp3 = STR ''prop'' ∧ A = A'›*) have norm_pre_C: "beta_eta_norm pre_C = Some C" by auto have "thy, set Hs ⊢ pre_C" apply (rule "6.IH" (*‹⟦?x = Option.bind (replay' thy vs ns Hs p1) beta_eta_norm; wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof p2 ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs p2 = Some ?res⟧ ⟹ thy,set Hs ⊢ ?res›*) (2)) (*goals: 1. ‹?x = Option.bind (replay' thy vs ns Hs p1) beta_eta_norm› 2. ‹wf_theory thy› 3. ‹⋀x. x ∈ set Hs ⟹ term_ok thy x› 4. ‹⋀x. x ∈ set Hs ⟹ typ_of x = Some propT› 5. ‹finite ns› 6. ‹fst ` FV (set Hs) ⊆ ns› 7. ‹fst ` fv_Proof p2 ⊆ ns› 8. ‹fst ` set vs ⊆ ns› 9. ‹replay' thy vs ns Hs p2 = Some pre_C› discuss goal 1*) apply ((use "6.prems" conds in ‹auto simp add: pre pre_C›)[1]) (*discuss goal 2*) apply ((use "6.prems" conds in ‹auto simp add: pre pre_C›)[1]) (*discuss goal 3*) apply ((use "6.prems" conds in ‹auto simp add: pre pre_C›)[1]) (*discuss goal 4*) apply ((use "6.prems" conds in ‹auto simp add: pre pre_C›)[1]) (*discuss goal 5*) apply ((use "6.prems" conds in ‹auto simp add: pre pre_C›)[1]) (*discuss goal 6*) apply ((use "6.prems" conds in ‹auto simp add: pre pre_C›)[1]) (*discuss goal 7*) apply ((use "6.prems" conds in ‹auto simp add: pre pre_C›)[1]) (*discuss goal 8*) apply ((use "6.prems" conds in ‹auto simp add: pre pre_C›)[1]) (*discuss goal 9*) apply ((use "6.prems" conds in ‹auto simp add: pre pre_C›)[1]) (*proven 9 subgoals*) . hence I1: "thy, set Hs ⊢ C" using beta_eta_norm_preserves_proves (*‹⟦wf_theory ?Θ; finite ?Γ; ?Θ,?Γ ⊢ ?t; beta_eta_norm ?t = Some ?u; ∀A∈?Γ. term_ok ?Θ A; ∀A∈?Γ. typ_of A = Some propT⟧ ⟹ ?Θ,?Γ ⊢ ?u›*) norm_pre_C (*‹beta_eta_norm (pre_C::Core.term) = Some (C::Core.term)›*) ‹wf_theory thy› (*‹wf_theory thy›*) using "6.prems"(2) (*‹?x ∈ set Hs ⟹ term_ok thy ?x›*) "6.prems"(3) (*‹?x ∈ set Hs ⟹ typ_of ?x = Some propT›*) by blast have "thy, set Hs ⊢ pre" apply (rule "6.IH" (*‹⟦wf_theory (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set); ⋀x::Core.term. x ∈ set (Hs::Core.term list) ⟹ term_ok thy x; ⋀x::Core.term. x ∈ set Hs ⟹ typ_of x = Some propT; finite (ns::variable set); fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (p1::proofterm) ⊆ ns; fst ` set (vs::(variable × typ) list) ⊆ ns; replay' thy vs ns Hs p1 = Some (?res::Core.term)⟧ ⟹ thy,set Hs ⊢ ?res›*) (1)) (*goals: 1. ‹wf_theory thy› 2. ‹⋀x. x ∈ set Hs ⟹ term_ok thy x› 3. ‹⋀x. x ∈ set Hs ⟹ typ_of x = Some propT› 4. ‹finite ns› 5. ‹fst ` FV (set Hs) ⊆ ns› 6. ‹fst ` fv_Proof p1 ⊆ ns› 7. ‹fst ` set vs ⊆ ns› 8. ‹replay' thy vs ns Hs p1 = Some pre› discuss goal 1*) apply ((use "6.prems" conds in ‹auto simp add: pre pre_C›)[1]) (*discuss goal 2*) apply ((use "6.prems" conds in ‹auto simp add: pre pre_C›)[1]) (*discuss goal 3*) apply ((use "6.prems" conds in ‹auto simp add: pre pre_C›)[1]) (*discuss goal 4*) apply ((use "6.prems" conds in ‹auto simp add: pre pre_C›)[1]) (*discuss goal 5*) apply ((use "6.prems" conds in ‹auto simp add: pre pre_C›)[1]) (*discuss goal 6*) apply ((use "6.prems" conds in ‹auto simp add: pre pre_C›)[1]) (*discuss goal 7*) apply ((use "6.prems" conds in ‹auto simp add: pre pre_C›)[1]) (*discuss goal 8*) apply ((use "6.prems" conds in ‹auto simp add: pre pre_C›)[1]) (*proven 8 subgoals*) . hence I2: "thy, set Hs ⊢ C ⟼ res" using beta_eta_norm_preserves_proves (*‹⟦wf_theory ?Θ; finite ?Γ; ?Θ,?Γ ⊢ ?t; beta_eta_norm ?t = Some ?u; ∀A∈?Γ. term_ok ?Θ A; ∀A∈?Γ. typ_of A = Some propT⟧ ⟹ ?Θ,?Γ ⊢ ?u›*) norm_pre (*‹beta_eta_norm pre = Some (C ⟼ res)›*) ‹wf_theory thy› (*‹wf_theory (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set)›*) using "6.prems"(2) (*‹?x ∈ set Hs ⟹ term_ok thy ?x›*) "6.prems"(3) (*‹?x ∈ set Hs ⟹ typ_of ?x = Some propT›*) by blast from I1 (*‹thy,set Hs ⊢ C›*) I2 (*‹thy,set Hs ⊢ C ⟼ res›*) have "thy, set Hs ∪ set Hs ⊢ res" using proves.implies_elim (*‹⟦?Θ,?Γ₁ ⊢ ?A ⟼ ?B; ?Θ,?Γ₂ ⊢ ?A⟧ ⟹ ?Θ,?Γ₁ ∪ ?Γ₂ ⊢ ?B›*) by blast thus "?case" (*goal: ‹thy,set Hs ⊢ res›*) by simp next (*goals: 1. ‹⋀thy vs ns Hs ty c res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (OfClass ty c) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (OfClass ty c) = Some res⟧ ⟹ thy,set Hs ⊢ res› 2. ‹⋀thy vs ns Hs t res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (Hyp t) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (Hyp t) = Some res⟧ ⟹ thy,set Hs ⊢ res›*) case (7 thy vs ns Hs ty c) (*‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹(?x::Core.term) ∈ set (Hs::Core.term list) ⟹ typ_of ?x = Some propT› ‹finite ns› ‹fst ` FV (set Hs) ⊆ ns› ‹fst ` fv_Proof (OfClass ty c) ⊆ ns› ‹fst ` set vs ⊆ ns› ‹replay' thy vs ns Hs (OfClass ty c) = Some res›*) from this (*‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite ns› ‹fst ` FV (set Hs) ⊆ ns› ‹fst ` fv_Proof (OfClass (ty::typ) (c::String.literal)) ⊆ (ns::variable set)› ‹fst ` set vs ⊆ ns› ‹replay' thy vs ns Hs (OfClass ty c) = Some res›*) obtain fun and it and ity and prop where conds: "has_sort (osig (sig thy)) ty {c}" "typ_ok thy ty" "const_type (sig thy) (const_of_class c) = Some (Ty fun [Ty it [ity], Ty prop []])" "ity = tvariable STR '''a''" "fun = STR ''fun''" "prop = STR ''prop''" "it = STR ''itself''" and res: "res = (mk_of_class ty c)" (*goal: ‹(⋀fun it ity prop. ⟦has_sort (osig (sig thy)) ty (insert c full_sort); typ_ok thy ty; const_type (sig thy) (const_of_class c) = Some (Ty fun [Ty it [ity], constT prop]); ity = Core.aT; fun = STR ''fun''; prop = STR ''prop''; it = STR ''itself''; res = mk_of_class ty c⟧ ⟹ thesis) ⟹ thesis›*) by (auto split: term.splits (*‹?P (case ?term of Ct x xa ⇒ ?f1.0 x xa | Fv x xa ⇒ ?f2.0 x xa | Bv x ⇒ ?f3.0 x | Abs x xa ⇒ ?f4.0 x xa | x $ xa ⇒ ?f5.0 x xa) = ((∀x11 x12. ?term = Ct x11 x12 ⟶ ?P (?f1.0 x11 x12)) ∧ (∀x21 x22. ?term = Fv x21 x22 ⟶ ?P (?f2.0 x21 x22)) ∧ (∀x3. ?term = Bv x3 ⟶ ?P (?f3.0 x3)) ∧ (∀x41 x42. ?term = Abs x41 x42 ⟶ ?P (?f4.0 x41 x42)) ∧ (∀x51 x52. ?term = x51 $ x52 ⟶ ?P (?f5.0 x51 x52)))› ‹?P (case ?term of Ct x xa ⇒ ?f1.0 x xa | Fv x xa ⇒ ?f2.0 x xa | Bv x ⇒ ?f3.0 x | Abs x xa ⇒ ?f4.0 x xa | x $ xa ⇒ ?f5.0 x xa) = (¬ ((∃x11 x12. ?term = Ct x11 x12 ∧ ¬ ?P (?f1.0 x11 x12)) ∨ (∃x21 x22. ?term = Fv x21 x22 ∧ ¬ ?P (?f2.0 x21 x22)) ∨ (∃x3. ?term = Bv x3 ∧ ¬ ?P (?f3.0 x3)) ∨ (∃x41 x42. ?term = Abs x41 x42 ∧ ¬ ?P (?f4.0 x41 x42)) ∨ (∃x51 x52. ?term = x51 $ x52 ∧ ¬ ?P (?f5.0 x51 x52))))›*) typ.splits (*‹?P (case ?typ of Ty x xa ⇒ ?f1.0 x xa | Tv x xa ⇒ ?f2.0 x xa) = ((∀x11 x12. ?typ = Ty x11 x12 ⟶ ?P (?f1.0 x11 x12)) ∧ (∀x21 x22. ?typ = Tv x21 x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?typ of Ty x xa ⇒ ?f1.0 x xa | Tv x xa ⇒ ?f2.0 x xa) = (¬ ((∃x11 x12. ?typ = Ty x11 x12 ∧ ¬ ?P (?f1.0 x11 x12)) ∨ (∃x21 x22. ?typ = Tv x21 x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*) list.splits (*‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = ((?list = [] ⟶ ?P ?f1.0) ∧ (∀x21 x22. ?list = x21 # x22 ⟶ ?P (?f2.0 x21 x22)))› ‹?P (case ?list of [] ⇒ ?f1.0 | x # xa ⇒ ?f2.0 x xa) = (¬ (?list = [] ∧ ¬ ?P ?f1.0 ∨ (∃x21 x22. ?list = x21 # x22 ∧ ¬ ?P (?f2.0 x21 x22))))›*) if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) from res (*‹res = mk_of_class ty c›*) have "res = mk_of_class ty c" by auto moreover have "thy,set Hs ⊢ mk_of_class ty c" apply (rule proves.of_class[where T=ty, OF "7.prems"(1)] (*‹⟦const_type (sig thy) (const_of_class ?c) = Some (itselfT Core.aT → propT); wf_type (sig thy) ty; has_sort (osig (sig thy)) ty (insert ?c full_sort)⟧ ⟹ thy,?Γ ⊢ mk_of_class ty ?c›*)) (*goals: 1. ‹const_type (sig thy) (const_of_class c) = Some (itselfT Core.aT → propT)› 2. ‹wf_type (sig thy) ty› 3. ‹has_sort (osig (sig thy)) ty (insert c full_sort)› discuss goal 1*) apply ((use conds in auto)[1]) (*discuss goal 2*) apply ((use conds in auto)[1]) (*discuss goal 3*) apply ((use conds in auto)[1]) (*proven 3 subgoals*) . ultimately show "?case" (*goal: ‹thy,set Hs ⊢ res›*) by simp next (*goal: ‹⋀thy vs ns Hs t res. ⟦wf_theory thy; ⋀x. x ∈ set Hs ⟹ term_ok thy x; ⋀x. x ∈ set Hs ⟹ typ_of x = Some propT; finite ns; fst ` FV (set Hs) ⊆ ns; fst ` fv_Proof (Hyp t) ⊆ ns; fst ` set vs ⊆ ns; replay' thy vs ns Hs (Hyp t) = Some res⟧ ⟹ thy,set Hs ⊢ res›*) case (8 thy ux uy Hs n) (*‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite uy› ‹fst ` FV (set Hs) ⊆ uy› ‹fst ` fv_Proof (Hyp (n::Core.term)) ⊆ (uy::variable set)› ‹fst ` set ux ⊆ uy› ‹replay' thy ux uy Hs (Hyp n) = Some res›*) hence "res ∈ set Hs" by (metis not_None_eq (*‹(?x ≠ None) = (∃y. ?x = Some y)›*) option.inject (*‹(Some ?x2.0 = Some ?y2.0) = (?x2.0 = ?y2.0)›*) replay'.simps( (*‹replay' ?thy ?vs ?ns ?Hs (Hyp ?t) = (if ?t ∈ set ?Hs then Some ?t else None)›*) 8)) then show "?case" (*goal: ‹thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set,set (Hs::Core.term list) ⊢ res::Core.term›*) using proves.assume (*‹⟦wf_term (sig ?Θ) ?A; ⊢⇩τ ?A : propT; ?A ∈ ?Γ⟧ ⟹ ?Θ,?Γ ⊢ ?A›*) "8" (*‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite (uy::variable set)› ‹fst ` FV (set Hs) ⊆ uy› ‹fst ` fv_Proof (Hyp n) ⊆ uy› ‹fst ` set ux ⊆ uy› ‹replay' thy ux uy Hs (Hyp n) = Some res›*) by (simp add: wt_term_def (*‹wt_term ?Σ ?t ≡ wf_term ?Σ ?t ∧ (∃T. ⊢⇩τ ?t : T)›*)) qed lemma finite_fv_Proof: "finite (fv_Proof P)" apply (induction P) (*goals: 1. ‹⋀(x1::Core.term) x2a::((variable × String.literal set) × typ) list. finite (fv_Proof (PAxm x1 x2a))› 2. ‹⋀x::nat. finite (fv_Proof (PBound x))› 3. ‹⋀(x1::typ) P::proofterm. finite (fv_Proof P) ⟹ finite (fv_Proof (Abst x1 P))› 4. ‹⋀(x1::Core.term) P::proofterm. finite (fv_Proof P) ⟹ finite (fv_Proof (AbsP x1 P))› 5. ‹⋀(P::proofterm) x2a::Core.term. finite (fv_Proof P) ⟹ finite (fv_Proof (Appt P x2a))› 6. ‹⋀(P1::proofterm) P2::proofterm. ⟦finite (fv_Proof P1); finite (fv_Proof P2)⟧ ⟹ finite (fv_Proof (AppP P1 P2))› 7. ‹⋀(x1::typ) x2a::String.literal. finite (fv_Proof (OfClass x1 x2a))› 8. ‹⋀x::Core.term. finite (fv_Proof (Hyp x))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*proven 8 subgoals*) . abbreviation "replay'' thy vs ns Hs P ≡ Option.bind (replay' thy vs ns Hs P) beta_eta_norm" lemma replay''_sound: assumes "wf_theory thy" (* Assumptions *) assumes HS_invs: "⋀x. x∈set Hs ⟹ term_ok thy x" "⋀x. x∈set Hs ⟹ typ_of x = Some propT" (* Names used *) assumes ns_invs: "finite ns" "fst ` FV (set Hs) ⊆ ns" "fst ` fv_Proof P ⊆ ns" (* Fviables used *) assumes vs_invs: "fst ` set vs ⊆ ns" (* Checked proof can be replayed using proves*) assumes "replay'' thy vs ns Hs P = Some res" shows "thy, (set Hs) ⊢ res" proof (-) (*goal: ‹thy,set Hs ⊢ res›*) obtain res' where res': "replay' thy vs ns Hs P = Some res'" (*goal: ‹(⋀res'. replay' thy vs ns Hs P = Some res' ⟹ thesis) ⟹ thesis›*) using replay'_sound_pre (*‹⟦wf_theory ?thy; ⋀x. x ∈ set ?Hs ⟹ term_ok ?thy x; ⋀x. x ∈ set ?Hs ⟹ typ_of x = Some propT; finite ?ns; fst ` FV (set ?Hs) ⊆ ?ns; fst ` fv_Proof ?P ⊆ ?ns; fst ` set ?vs ⊆ ?ns; replay' ?thy ?vs ?ns ?Hs ?P = Some ?res⟧ ⟹ ?thy,set ?Hs ⊢ ?res›*) assms (*‹wf_theory (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set)› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite ns› ‹fst ` FV (set (Hs::Core.term list)) ⊆ (ns::variable set)› ‹fst ` fv_Proof P ⊆ ns› ‹fst ` set vs ⊆ ns› ‹replay'' thy vs ns Hs P = Some res›*) bind_eq_Some_conv (*‹(Option.bind (?f::?'b option) (?g::?'b ⇒ ?'a option) = Some (?x::?'a)) = (∃y::?'b. ?f = Some y ∧ ?g y = Some ?x)›*) by metis moreover have "beta_eta_norm res' = Some res" using res' (*‹replay' thy vs ns Hs P = Some res'›*) assms(8) (*‹replay'' thy vs ns Hs P = Some res›*) by auto moreover have "thy, set Hs ⊢ res'" using res' (*‹replay' thy vs ns Hs P = Some res'›*) assms (*‹wf_theory thy› ‹?x ∈ set Hs ⟹ term_ok thy ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT› ‹finite ns› ‹fst ` FV (set (Hs::Core.term list)) ⊆ (ns::variable set)› ‹fst ` fv_Proof (P::proofterm) ⊆ (ns::variable set)› ‹fst ` set vs ⊆ ns› ‹replay'' (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (vs::(variable × typ) list) (ns::variable set) (Hs::Core.term list) (P::proofterm) = Some (res::Core.term)›*) replay'_sound_pre (*‹⟦wf_theory ?thy; ⋀x. x ∈ set ?Hs ⟹ term_ok ?thy x; ⋀x. x ∈ set ?Hs ⟹ typ_of x = Some propT; finite ?ns; fst ` FV (set ?Hs) ⊆ ?ns; fst ` fv_Proof ?P ⊆ ?ns; fst ` set ?vs ⊆ ?ns; replay' ?thy ?vs ?ns ?Hs ?P = Some ?res⟧ ⟹ ?thy,set ?Hs ⊢ ?res›*) by simp ultimately show "?thesis" (*goal: ‹thy,set Hs ⊢ res›*) using beta_eta_norm_preserves_proves (*‹⟦wf_theory (?Θ::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set); finite (?Γ::Core.term set); ?Θ,?Γ ⊢ ?t::Core.term; beta_eta_norm ?t = Some (?u::Core.term); ∀A::Core.term∈?Γ. term_ok ?Θ A; ∀A::Core.term∈?Γ. typ_of A = Some propT⟧ ⟹ ?Θ,?Γ ⊢ ?u›*) assms(1-3) (*‹wf_theory thy› ‹(?x::Core.term) ∈ set (Hs::Core.term list) ⟹ term_ok (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) ?x› ‹?x ∈ set Hs ⟹ typ_of ?x = Some propT›*) by blast qed lemma assumes "wf_theory thy" assumes "replay'' thy [] (fst ` fv_Proof P) [] P = Some res" shows "thy, set [] ⊢ res" using assms (*‹wf_theory thy› ‹replay'' thy [] (fst ` fv_Proof P) [] P = Some res›*) finite_fv_Proof (*‹finite (fv_Proof ?P)›*) replay'_sound_pre (*‹⟦wf_theory ?thy; ⋀x. x ∈ set ?Hs ⟹ term_ok ?thy x; ⋀x. x ∈ set ?Hs ⟹ typ_of x = Some propT; finite ?ns; fst ` FV (set ?Hs) ⊆ ?ns; fst ` fv_Proof ?P ⊆ ?ns; fst ` set ?vs ⊆ ?ns; replay' ?thy ?vs ?ns ?Hs ?P = Some ?res⟧ ⟹ ?thy,set ?Hs ⊢ ?res›*) replay''_sound[where vs = "[]" and ns = "fst ` fv_Proof P" and P = P and Hs = "[]"] (*‹⟦wf_theory ?thy; ⋀x. x ∈ set [] ⟹ term_ok ?thy x; ⋀x. x ∈ set [] ⟹ typ_of x = Some propT; finite (fst ` fv_Proof P); fst ` FV (set []) ⊆ fst ` fv_Proof P; fst ` fv_Proof P ⊆ fst ` fv_Proof P; fst ` set [] ⊆ fst ` fv_Proof P; replay'' ?thy [] (fst ` fv_Proof P) [] P = Some ?res⟧ ⟹ ?thy,set [] ⊢ ?res›*) by simp (* With open hyps, run *) fun hyps :: "proofterm ⇒ term list" where "hyps (Abst _ p) = hyps p" | "hyps (AbsP _ p) = hyps p" | "hyps (Appt p _) = hyps p" | "hyps (AppP p1 p2) = List.union (hyps p1) (hyps p2)" | "hyps (Hyp t) = [t]" | "hyps _ = []" lemma replay''_sound_pre_hyps: assumes "wf_theory thy" (* This can be checked independently before running replay'. Could also check during replay' in Hyp step... *) assumes "⋀x. x ∈ set (hyps P) ⟹ term_ok thy x" assumes "⋀x. x ∈ set (hyps P) ⟹ typ_of x = Some propT" assumes "replay'' thy [] (fst ` (fv_Proof P ∪ FV (set (hyps P)))) (hyps P) P = Some res" shows "thy, set (hyps P) ⊢ res" apply (rule replay''_sound[where vs="[]" and ns="(fst ` (fv_Proof P ∪ FV (set (hyps P))))" and P=P and Hs="hyps P"] (*‹⟦wf_theory (?thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set); ⋀x::Core.term. x ∈ set (hyps (P::proofterm)) ⟹ term_ok ?thy x; ⋀x::Core.term. x ∈ set (hyps P) ⟹ typ_of x = Some propT; finite (fst ` (fv_Proof P ∪ FV (set (hyps P)))); fst ` FV (set (hyps P)) ⊆ fst ` (fv_Proof P ∪ FV (set (hyps P))); fst ` fv_Proof P ⊆ fst ` (fv_Proof P ∪ FV (set (hyps P))); fst ` set [] ⊆ fst ` (fv_Proof P ∪ FV (set (hyps P))); replay'' ?thy [] (fst ` (fv_Proof P ∪ FV (set (hyps P)))) (hyps P) P = Some (?res::Core.term)⟧ ⟹ ?thy,set (hyps P) ⊢ ?res›*)) (*goals: 1. ‹wf_theory thy› 2. ‹⋀x. x ∈ set (hyps P) ⟹ term_ok thy x› 3. ‹⋀x. x ∈ set (hyps P) ⟹ typ_of x = Some propT› 4. ‹finite (fst ` (fv_Proof P ∪ FV (set (hyps P))))› 5. ‹fst ` FV (set (hyps P)) ⊆ fst ` (fv_Proof P ∪ FV (set (hyps P)))› 6. ‹fst ` fv_Proof P ⊆ fst ` (fv_Proof P ∪ FV (set (hyps P)))› 7. ‹fst ` set [] ⊆ fst ` (fv_Proof P ∪ FV (set (hyps P)))› 8. ‹replay'' thy [] (fst ` (fv_Proof P ∪ FV (set (hyps P)))) (hyps P) P = Some res› discuss goal 1*) apply (use assms finite_fv_Proof replay'_sound_pre in ‹solves simp›) (*discuss goal 2*) apply (use assms finite_fv_Proof replay'_sound_pre in ‹solves simp›) (*discuss goal 3*) apply (use assms finite_fv_Proof replay'_sound_pre in ‹solves simp›) (*discuss goal 4*) apply (use assms finite_fv_Proof replay'_sound_pre in ‹solves simp›) (*discuss goal 5*) apply blast (*discuss goal 6*) apply blast (*discuss goal 7*) apply (use assms finite_fv_Proof replay'_sound_pre in ‹solves simp›) (*discuss goal 8*) apply (use assms finite_fv_Proof replay'_sound_pre in ‹solves simp›) (*proven 8 subgoals*) . definition [simp]: "replay thy P ≡ (if ∀x∈set (hyps P) . term_ok thy x ∧ typ_of x = Some propT then replay'' thy [] (fst ` (fv_Proof P ∪ FV (set (hyps P)))) (hyps P) P else None)" lemma replay_sound_pre_hyps: assumes "wf_theory thy" assumes "replay thy P = Some res" shows "thy, set (hyps P) ⊢ res" using replay''_sound_pre_hyps (*‹⟦wf_theory ?thy; ⋀x. x ∈ set (hyps ?P) ⟹ term_ok ?thy x; ⋀x. x ∈ set (hyps ?P) ⟹ typ_of x = Some propT; replay'' ?thy [] (fst ` (fv_Proof ?P ∪ FV (set (hyps ?P)))) (hyps ?P) ?P = Some ?res⟧ ⟹ ?thy,set (hyps ?P) ⊢ ?res›*) assms (*‹wf_theory thy› ‹replay thy P = Some res›*) by (simp split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) definition "check_proof thy P res ≡ wf_theory thy ∧ replay thy P = Some res" lemma check_proof_sound: shows "check_proof thy P res ⟹ thy, set (hyps P) ⊢ res" using check_proof_def (*‹check_proof (?thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (?P::proofterm) (?res::Core.term) ≡ wf_theory ?thy ∧ replay ?thy ?P = Some ?res›*) replay_sound_pre_hyps (*‹⟦wf_theory ?thy; replay ?thy ?P = Some ?res⟧ ⟹ ?thy,set (hyps ?P) ⊢ ?res›*) by blast lemma check_proof_really_sound: assumes "check_proof thy P res" shows "thy, set (hyps P) ⊩ res" proof (-) (*goal: ‹thy,set (hyps P) ⊩ res›*) have "wf_theory thy" using assms (*‹check_proof (thy::((String.literal ⇒ typ option) × (String.literal ⇒ nat option) × (String.literal × String.literal) set × (String.literal ⇒ (String.literal ⇒ String.literal set list option) option)) × Core.term set) (P::proofterm) (res::Core.term)›*) check_proof_def (*‹check_proof ?thy ?P ?res ≡ wf_theory ?thy ∧ replay ?thy ?P = Some ?res›*) by blast moreover have "Some res = replay thy P" by (metis assms (*‹check_proof thy P res›*) check_proof_def (*‹check_proof ?thy ?P ?res ≡ wf_theory ?thy ∧ replay ?thy ?P = Some ?res›*)) moreover hence "∀x∈set (hyps P) . term_ok thy x ∧ typ_of x = Some propT" by (metis not_None_eq (*‹(?x ≠ None) = (∃y. ?x = Some y)›*) replay_def (*‹replay ?thy ?P ≡ if ∀x∈set (hyps ?P). term_ok ?thy x ∧ typ_of x = Some propT then replay'' ?thy [] (fst ` (fv_Proof ?P ∪ FV (set (hyps ?P)))) (hyps ?P) ?P else None›*)) ultimately show "?thesis" (*goal: ‹thy,set (hyps P) ⊩ res›*) by (meson assms (*‹check_proof thy P res›*) check_proof_sound (*‹check_proof ?thy ?P ?res ⟹ ?thy,set (hyps ?P) ⊢ ?res›*) has_typ_iff_typ_of (*‹⊢⇩τ ?t : ?ty = (typ_of ?t = Some ?ty)›*) proved_terms_well_formed( (*‹?Θ,?Γ ⊢ ?p ⟹ typ_of ?p = Some propT›*) 1) proves'_def (*‹?Θ,?Γ ⊩ ?t ≡ wf_theory ?Θ ∧ (∀h∈?Γ. wf_term (sig ?Θ) h ∧ ⊢⇩τ h : propT) ∧ ?Θ,?Γ ⊢ ?t›*) term_ok_def (*‹term_ok ?Θ ?t ≡ wt_term (sig ?Θ) ?t›*) wt_term_def (*‹wt_term ?Σ ?t ≡ wf_term ?Σ ?t ∧ (∃T. ⊢⇩τ ?t : T)›*)) qed end
{ "path": "afp-2025-02-12/thys/Metalogic_ProofChecker/ProofTerm.thy", "repo": "afp-2025-02-12", "sha": "3604a7d6832e1ef8eac85815fa69b2bec15e092492bba2832432ac58ea81ee39" }
chapter ‹Abstract Formulation of Gödel's Second Incompleteness Theorem› (*<*) theory Abstract_Second_Goedel imports Abstract_First_Goedel Derivability_Conditions begin (*>*) text ‹We assume all three derivability conditions, and assumptions behind Gödel formulas:› locale Goedel_Second_Assumptions = HBL1_2_3 var trm fmla Var FvarsT substT Fvars subst num eql cnj imp all exi prv bprv enc P + Goedel_Form var trm fmla Var num FvarsT substT Fvars subst eql cnj imp all exi fls prv bprv enc S P for var :: "'var set" and trm :: "'trm set" and fmla :: "'fmla set" and Var FvarsT substT Fvars subst and num and eql cnj imp all exi and prv bprv and enc ("⟨_⟩") and S and P and fls begin lemma P_G: "bprv (imp (PP ⟨φG⟩) (PP ⟨fls⟩))" proof (-) (*goal: ‹bprv (imp (PP ⟨φG⟩) (PP ⟨fls⟩))›*) have 0: "prv (imp φG (neg (PP ⟨φG⟩)))" using "prv_φG_eqv" (*‹(prv::'fmla ⇒ bool) (eqv φG (neg (PP ⟨φG⟩)))›*) apply - (*goal: ‹prv (imp φG (neg (PP ⟨φG⟩)))›*) apply (intro prv_imp_eqvEL (*‹⟦?φ1.0 ∈ fmla; ?φ2.0 ∈ fmla; prv (eqv ?φ1.0 ?φ2.0)⟧ ⟹ prv (imp ?φ1.0 ?φ2.0)›*)) (*goals: 1. ‹prv (eqv φG (neg (PP ⟨φG⟩))) ⟹ φG ∈ fmla› 2. ‹prv (eqv φG (neg (PP ⟨φG⟩))) ⟹ neg (PP ⟨φG⟩) ∈ fmla› 3. ‹prv (eqv φG (neg (PP ⟨φG⟩))) ⟹ prv (eqv φG (neg (PP ⟨φG⟩)))› discuss goal 1*) apply ((msorry)[1]) (*discuss goal 2*) apply ((msorry)[1]) (*discuss goal 3*) apply ((msorry)[1]) (*proven 3 subgoals*) . have 1: "bprv (PP ⟨imp φG (neg (PP ⟨φG⟩))⟩)" using HBL1_PP[OF _ _ 0] (*‹⟦imp φG (neg (PP ⟨φG⟩)) ∈ fmla; Fvars (imp φG (neg (PP ⟨φG⟩))) = {}⟧ ⟹ bprv (PP ⟨imp φG (neg (PP ⟨φG⟩))⟩)›*) by simp have 2: "bprv (imp (PP ⟨φG⟩) (PP ⟨neg (PP ⟨φG⟩)⟩))" using HBL2_imp2[OF _ _ _ _ 1] (*‹⟦φG ∈ fmla; neg (PP ⟨φG⟩) ∈ fmla; Fvars φG = {}; Fvars (neg (PP ⟨φG⟩)) = {}⟧ ⟹ bprv (imp (PP ⟨φG⟩) (PP ⟨neg (PP ⟨φG⟩)⟩))›*) by simp have 3: "bprv (imp (PP ⟨φG⟩) (PP ⟨PP ⟨φG⟩⟩))" using HBL3[OF φG] (*‹Fvars φG = {} ⟹ bprv (imp (PP ⟨φG⟩) (PP ⟨PP ⟨φG⟩⟩))›*) by simp have 23: "bprv (imp (PP ⟨φG⟩) (cnj (PP ⟨PP ⟨φG⟩⟩) (PP ⟨neg (PP ⟨φG⟩)⟩)))" using B.prv_imp_cnj[OF _ _ _ 3 2] (*‹⟦PP ⟨φG⟩ ∈ fmla; PP ⟨neg (PP ⟨φG⟩)⟩ ∈ fmla; PP ⟨PP ⟨φG⟩⟩ ∈ fmla⟧ ⟹ bprv (imp (PP ⟨φG⟩) (cnj (PP ⟨PP ⟨φG⟩⟩) (PP ⟨neg (PP ⟨φG⟩)⟩)))›*) by simp have 4: "bprv (imp (cnj (PP ⟨PP ⟨φG⟩⟩) (PP ⟨neg (PP ⟨φG⟩)⟩)) (PP ⟨fls⟩))" using HBL2[of "PP ⟨φG⟩" fls] (*‹⟦PP ⟨φG⟩ ∈ fmla; fls ∈ fmla; Fvars (PP ⟨φG⟩) = {}; Fvars fls = {}⟧ ⟹ bprv (imp (cnj (PP ⟨PP ⟨φG⟩⟩) (PP ⟨imp (PP ⟨φG⟩) fls⟩)) (PP ⟨fls⟩))›*) unfolding neg_def[symmetric] (*goal: ‹bprv (imp (cnj (PP ⟨PP ⟨φG⟩⟩) (PP ⟨neg (PP ⟨φG⟩)⟩)) (PP ⟨fls⟩))›*) by simp show "?thesis" (*goal: ‹bprv (imp (PP ⟨φG⟩) (PP ⟨fls⟩))›*) using B.prv_prv_imp_trans[OF _ _ _ 23 4] (*‹⟦PP ⟨φG⟩ ∈ fmla; cnj (PP ⟨PP ⟨φG⟩⟩) (PP ⟨neg (PP ⟨φG⟩)⟩) ∈ fmla; PP ⟨fls⟩ ∈ fmla⟧ ⟹ bprv (imp (PP ⟨φG⟩) (PP ⟨fls⟩))›*) by simp qed text ‹First the "direct", positive formulation:› lemma goedel_second_pos: assumes "prv (neg (PP ⟨fls⟩))" shows "prv fls" proof (-) (*goal: ‹prv fls›*) note PG = bprv_prv[OF _ _ P_G, simplified] (*‹(prv::'fmla ⇒ bool) ((imp::'fmla ⇒ 'fmla ⇒ 'fmla) (PP ⟨φG⟩) (PP ⟨fls::'fmla⟩))›*) have "prv (neg (PP ⟨φG⟩))" using PG (*‹prv (imp (PP ⟨φG⟩) (PP ⟨fls⟩))›*) assms (*‹prv (neg (PP ⟨fls⟩))›*) unfolding neg_def (*goal: ‹prv (imp (PP ⟨φG⟩) fls)›*) apply (rule prv_prv_imp_trans[rotated 3] (*‹⟦(prv::'fmla ⇒ bool) ((imp::'fmla ⇒ 'fmla ⇒ 'fmla) (?φ::'fmla) (?χ::'fmla)); prv (imp ?χ (?ψ::'fmla)); ?φ ∈ (fmla::'fmla set); ?χ ∈ fmla; ?ψ ∈ fmla⟧ ⟹ prv (imp ?φ ?ψ)›*)) (*goals: 1. ‹PP ⟨φG⟩ ∈ fmla› 2. ‹PP ⟨fls⟩ ∈ fmla› 3. ‹fls ∈ fmla› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . hence "prv φG" using "prv_φG_eqv" (*‹prv (eqv φG (neg (PP ⟨φG⟩)))›*) apply (rule prv_eqv_prv_rev[rotated 2] (*‹⟦(prv::'fmla ⇒ bool) (?φ::'fmla); prv (eqv (?χ::'fmla) ?φ); ?φ ∈ (fmla::'fmla set); ?χ ∈ fmla⟧ ⟹ prv ?χ›*)) (*goals: 1. ‹neg (PP ⟨φG⟩) ∈ fmla› 2. ‹φG ∈ fmla› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . thus "?thesis" (*goal: ‹prv fls›*) using goedel_first_theEasyHalf_pos (*‹(prv::'fmla ⇒ bool) φG ⟹ prv (fls::'fmla)›*) by simp qed text ‹Then the more standard, counterpositive formulation:› theorem goedel_second: "consistent ⟹ ¬ prv (neg (PP ⟨fls⟩))" using goedel_second_pos (*‹prv (neg (PP ⟨fls⟩)) ⟹ prv fls›*) unfolding consistent_def (*goal: ‹¬ prv fls ⟹ ¬ prv (neg (PP ⟨fls⟩))›*) by auto text ‹It is an immediate consequence of Gödel's Second HLB1, HLB2 that (assuming consistency) @{term "prv (neg (PP ⟨φ⟩))"} holds for no sentence, be it provable or not. The theory is omniscient about what it can prove (thanks to HLB1), but completely ignorant about what it cannot prove.› corollary not_prv_neg_PP: assumes c: "consistent" and [simp]: "φ ∈ fmla" "Fvars φ = {}" shows "¬ prv (neg (PP ⟨φ⟩))" proof (standard) (*goal: ‹prv (neg (PP ⟨φ⟩)) ⟹ False›*) assume 0: "prv (neg (PP ⟨φ⟩))" (*‹(prv::'fmla ⇒ bool) (neg (PP ⟨φ::'fmla⟩))›*) have "prv (imp fls φ)" by simp hence "bprv (PP ⟨imp fls φ⟩)" apply (intro HBL1_PP (*‹⟦?φ ∈ fmla; Fvars ?φ = {}; prv ?φ⟧ ⟹ bprv (PP ⟨?φ⟩)›*)) (*goals: 1. ‹prv (imp fls φ) ⟹ imp fls φ ∈ fmla› 2. ‹prv (imp fls φ) ⟹ Fvars (imp fls φ) = {}› 3. ‹prv (imp fls φ) ⟹ prv (imp fls φ)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . hence "bprv (imp (PP ⟨fls⟩) (PP ⟨φ⟩))" apply (intro HBL2_imp2 (*‹⟦?φ ∈ fmla; ?χ ∈ fmla; Fvars ?φ = {}; Fvars ?χ = {}; bprv (PP ⟨imp ?φ ?χ⟩)⟧ ⟹ bprv (imp (PP ⟨?φ⟩) (PP ⟨?χ⟩))›*)) (*goals: 1. ‹bprv (PP ⟨imp fls φ⟩) ⟹ fls ∈ fmla› 2. ‹bprv (PP ⟨imp fls φ⟩) ⟹ φ ∈ fmla› 3. ‹bprv (PP ⟨imp fls φ⟩) ⟹ Fvars fls = {}› 4. ‹bprv (PP ⟨imp fls φ⟩) ⟹ Fvars φ = {}› 5. ‹bprv (PP ⟨imp fls φ⟩) ⟹ bprv (PP ⟨imp fls φ⟩)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . hence "bprv (imp (neg (PP ⟨φ⟩)) (neg (PP ⟨fls⟩)))" apply (intro B.prv_imp_neg_rev (*‹⟦?φ ∈ fmla; ?χ ∈ fmla; bprv (imp ?φ ?χ)⟧ ⟹ bprv (imp (neg ?χ) (neg ?φ))›*)) (*goals: 1. ‹bprv (imp (PP ⟨fls⟩) (PP ⟨φ⟩)) ⟹ PP ⟨fls⟩ ∈ fmla› 2. ‹bprv (imp (PP ⟨fls⟩) (PP ⟨φ⟩)) ⟹ PP ⟨φ⟩ ∈ fmla› 3. ‹bprv (imp (PP ⟨fls⟩) (PP ⟨φ⟩)) ⟹ bprv (imp (PP ⟨fls⟩) (PP ⟨φ⟩))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . from prv_imp_mp[OF _ _ bprv_prv [ OF _ _ this , simplified ] 0, simplified] (*‹prv (neg (PP ⟨fls⟩))›*) have "prv (neg (PP ⟨fls⟩))" . thus False using goedel_second[OF c] (*‹¬ prv (neg (PP ⟨fls⟩))›*) by simp qed end ― ‹context @{locale Goedel_Second_Assumptions}› (*<*) end (*>*)
{ "path": "afp-2025-02-12/thys/Goedel_Incompleteness/Abstract_Second_Goedel.thy", "repo": "afp-2025-02-12", "sha": "9d5f6afcb43b5f690ad113b1b15c723683f313b60666c115137c62b04a4b952e" }
(* Author: Alexander Maletzky *) section ‹Direct Decompositions and Hilbert Functions› theory Hilbert_Function imports "HOL-Combinatorics.Permutations" Dube_Prelims Degree_Section begin subsection ‹Direct Decompositions› text ‹The main reason for defining ‹direct_decomp› in terms of lists rather than sets is that lemma ‹direct_decomp_direct_decomp› can be proved easier. At some point one could invest the time to re-define ‹direct_decomp› in terms of sets (possibly adding a couple of further assumptions to ‹direct_decomp_direct_decomp›).› definition direct_decomp :: "'a set ⇒ 'a::comm_monoid_add set list ⇒ bool" where "direct_decomp A ss ⟷ bij_betw sum_list (listset ss) A" lemma direct_decompI: "inj_on sum_list (listset ss) ⟹ sum_list ` listset ss = A ⟹ direct_decomp A ss" by (simp add: direct_decomp_def (*‹direct_decomp ?A ?ss = bij_betw sum_list (listset ?ss) ?A›*) bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*)) lemma direct_decompI_alt: "(⋀qs. qs ∈ listset ss ⟹ sum_list qs ∈ A) ⟹ (⋀a. a ∈ A ⟹ ∃!qs∈listset ss. a = sum_list qs) ⟹ direct_decomp A ss" apply (auto simp: direct_decomp_def (*‹direct_decomp (?A::?'a set) (?ss::?'a set list) = bij_betw sum_list (listset ?ss) ?A›*) intro!: bij_betwI' (*‹⟦⋀(x::?'a) y::?'a. ⟦x ∈ (?X::?'a set); y ∈ ?X⟧ ⟹ ((?f::?'a ⇒ ?'b) x = ?f y) = (x = y); ⋀x::?'a. x ∈ ?X ⟹ ?f x ∈ (?Y::?'b set); ⋀y::?'b. y ∈ ?Y ⟹ ∃x::?'a∈?X. y = ?f x⟧ ⟹ bij_betw ?f ?X ?Y›*)) (*goal: ‹⟦⋀qs. qs ∈ listset ss ⟹ sum_list qs ∈ A; ⋀a. a ∈ A ⟹ ∃!qs. qs ∈ listset ss ∧ a = sum_list qs⟧ ⟹ direct_decomp A ss›*) by blast lemma direct_decompD: assumes "direct_decomp A ss" shows "qs ∈ listset ss ⟹ sum_list qs ∈ A" and "inj_on sum_list (listset ss)" and "sum_list ` listset ss = A" using assms (*‹direct_decomp A ss›*) apply - (*goals: 1. ‹⟦qs ∈ listset ss; direct_decomp A ss⟧ ⟹ sum_list qs ∈ A› 2. ‹direct_decomp A ss ⟹ inj_on sum_list (listset ss)› 3. ‹direct_decomp A ss ⟹ sum_list ` listset ss = A› discuss goal 1*) apply ((auto simp: direct_decomp_def (*‹direct_decomp ?A ?ss = bij_betw sum_list (listset ?ss) ?A›*) bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*))[1]) (*discuss goal 2*) apply ((auto simp: direct_decomp_def (*‹direct_decomp ?A ?ss = bij_betw sum_list (listset ?ss) ?A›*) bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*))[1]) (*discuss goal 3*) apply ((auto simp: direct_decomp_def (*‹direct_decomp (?A::?'a set) (?ss::?'a set list) = bij_betw sum_list (listset ?ss) ?A›*) bij_betw_def (*‹bij_betw (?f::?'a ⇒ ?'b) (?A::?'a set) (?B::?'b set) = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*))[1]) (*proven 3 subgoals*) . lemma direct_decompE: assumes "direct_decomp A ss" and "a ∈ A" obtains qs where "qs ∈ listset ss" and "a = sum_list qs" using assms (*‹direct_decomp A ss› ‹a ∈ A›*) by (auto simp: direct_decomp_def (*‹direct_decomp ?A ?ss = bij_betw sum_list (listset ?ss) ?A›*) bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*)) lemma direct_decomp_unique: "direct_decomp A ss ⟹ qs ∈ listset ss ⟹ qs' ∈ listset ss ⟹ sum_list qs = sum_list qs' ⟹ qs = qs'" by (auto dest: direct_decompD (*‹⟦direct_decomp ?A ?ss; ?qs ∈ listset ?ss⟧ ⟹ sum_list ?qs ∈ ?A› ‹direct_decomp ?A ?ss ⟹ inj_on sum_list (listset ?ss)› ‹direct_decomp ?A ?ss ⟹ sum_list ` listset ?ss = ?A›*) simp: inj_on_def (*‹inj_on ?f ?A = (∀x∈?A. ∀y∈?A. ?f x = ?f y ⟶ x = y)›*)) lemma direct_decomp_singleton: "direct_decomp A [A]" proof (rule direct_decompI_alt (*‹⟦⋀qs. qs ∈ listset ?ss ⟹ sum_list qs ∈ ?A; ⋀a. a ∈ ?A ⟹ ∃!qs. qs ∈ listset ?ss ∧ a = sum_list qs⟧ ⟹ direct_decomp ?A ?ss›*)) (*goals: 1. ‹⋀qs::'a list. qs ∈ listset [A::'a set] ⟹ sum_list qs ∈ A› 2. ‹⋀a::'a. a ∈ (A::'a set) ⟹ ∃!qs::'a list. qs ∈ listset [A] ∧ a = sum_list qs›*) fix qs assume "qs ∈ listset [A]" (*‹(qs::'a list) ∈ listset [A::'a set]›*) then obtain q where "q ∈ A" and "qs = [q]" (*goal: ‹(⋀q. ⟦q ∈ A; qs = [q]⟧ ⟹ thesis) ⟹ thesis›*) by (rule listset_singletonE (*‹⟦(?ys::?'a list) ∈ listset [?A::?'a set]; ⋀a::?'a. ⟦a ∈ ?A; ?ys = [a]⟧ ⟹ ?thesis::bool⟧ ⟹ ?thesis›*)) thus "sum_list qs ∈ A" by simp next (*goal: ‹⋀a. a ∈ A ⟹ ∃!qs. qs ∈ listset [A] ∧ a = sum_list qs›*) fix a assume "a ∈ A" (*‹(a::'a) ∈ (A::'a set)›*) show "∃!qs∈listset [A]. a = sum_list qs" proof (intro ex1I (*‹⟦?P ?a; ⋀x. ?P x ⟹ x = ?a⟧ ⟹ ∃!x. ?P x›*) conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*) allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*) impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goals: 1. ‹?a ∈ listset [A]› 2. ‹a = sum_list ?a› 3. ‹⋀qs. qs ∈ listset [A] ∧ a = sum_list qs ⟹ qs = ?a›*) from ‹a ∈ A› (*‹a ∈ A›*) refl (*‹?t = ?t›*) show "[a] ∈ listset [A]" by (rule listset_singletonI (*‹⟦(?a::?'a) ∈ (?A::?'a set); (?ys::?'a list) = [?a]⟧ ⟹ ?ys ∈ listset [?A]›*)) next (*goals: 1. ‹a = sum_list [a]› 2. ‹⋀qs. qs ∈ listset [A] ∧ a = sum_list qs ⟹ qs = [a]›*) fix qs assume "qs ∈ listset [A] ∧ a = sum_list qs" (*‹(qs::'a list) ∈ listset [A::'a set] ∧ (a::'a) = sum_list qs›*) hence a: "a = sum_list qs" and "qs ∈ listset [A]" apply - (*goals: 1. ‹qs ∈ listset [A] ∧ a = sum_list qs ⟹ a = sum_list qs› 2. ‹qs ∈ listset [A] ∧ a = sum_list qs ⟹ qs ∈ listset [A]› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . from this(2) (*‹qs ∈ listset [A]›*) obtain b where qs: "qs = [b]" (*goal: ‹(⋀b. qs = [b] ⟹ thesis) ⟹ thesis›*) by (rule listset_singletonE (*‹⟦?ys ∈ listset [?A]; ⋀a. ⟦a ∈ ?A; ?ys = [a]⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) with a (*‹a = sum_list qs›*) show "qs = [a]" by simp qed (simp_all) (*solved the remaining goal: ‹(a::'a) = sum_list [a]›*) qed (* TODO: Move. *) lemma mset_bij: assumes "bij_betw f {..<length xs} {..<length ys}" and "⋀i. i < length xs ⟹ xs ! i = ys ! f i" shows "mset xs = mset ys" proof (-) (*goal: ‹mset (xs::'a::type list) = mset (ys::'a::type list)›*) from assms(1) (*‹bij_betw f {..<length xs} {..<length ys}›*) have 1: "inj_on f {0..<length xs}" and 2: "f ` {0..<length xs} = {0..<length ys}" apply - (*goals: 1. ‹bij_betw f {..<length xs} {..<length ys} ⟹ inj_on f {0..<length xs}› 2. ‹bij_betw f {..<length xs} {..<length ys} ⟹ f ` {0..<length xs} = {0..<length ys}› discuss goal 1*) apply (simp add: bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*) lessThan_atLeast0 (*‹{..<?n} = {0..<?n}›*)) (*discuss goal 2*) apply (simp add: bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*) lessThan_atLeast0 (*‹{..<?n} = {0..<?n}›*)) (*proven 2 subgoals*) . let ?f = "(!) ys ∘ f" have "xs = map ?f [0..<length xs]" unfolding list_eq_iff_nth_eq (*goal: ‹length (xs::'a list) = length (map ((!) (ys::'a list) ∘ (f::nat ⇒ nat)) [0::nat..<length xs]) ∧ (∀i<length xs. xs ! i = map ((!) ys ∘ f) [0::nat..<length xs] ! i)›*) proof (intro conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*) allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*) impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goals: 1. ‹length (xs::'a::type list) = length (map ((!) (ys::'a::type list) ∘ (f::nat ⇒ nat)) [0::nat..<length xs])› 2. ‹⋀i::nat. i < length (xs::'a::type list) ⟹ xs ! i = map ((!) (ys::'a::type list) ∘ (f::nat ⇒ nat)) [0::nat..<length xs] ! i›*) fix i assume "i < length xs" (*‹(i::nat) < length (xs::'a list)›*) hence "xs ! i = ys ! f i" by (rule assms( (*‹?i < length xs ⟹ xs ! ?i = ys ! f ?i›*) 2)) also (*calculation: ‹xs ! i = ys ! f i›*) from ‹i < length xs› (*‹i < length xs›*) have "… = map ((!) ys ∘ f) [0..<length xs] ! i" by simp finally (*calculation: ‹xs ! i = map ((!) ys ∘ f) [0..<length xs] ! i›*) show "xs ! i = map ((!) ys ∘ f) [0..<length xs] ! i" . qed (simp) (*solved the remaining goal: ‹length (xs::'a list) = length (map ((!) (ys::'a list) ∘ (f::nat ⇒ nat)) [0::nat..<length xs])›*) hence "mset xs = mset (map ?f [0..<length xs])" by (rule arg_cong (*‹?x = ?y ⟹ ?f ?x = ?f ?y›*)) also (*calculation: ‹mset (xs::'a list) = mset (map ((!) (ys::'a list) ∘ (f::nat ⇒ nat)) [0::nat..<length xs])›*) have "… = image_mset ((!) ys) (image_mset f (mset_set {0..<length xs}))" by (simp flip: image_mset.comp (*‹image_mset (?f::?'b ⇒ ?'c) ∘ image_mset (?g::?'a ⇒ ?'b) = image_mset (?f ∘ ?g)›*)) also (*calculation: ‹mset xs = image_mset ((!) ys) (image_mset f (mset_set {0..<length xs}))›*) from "1" (*‹inj_on f {0..<length xs}›*) have "… = image_mset ((!) ys) (mset_set {0..<length ys})" by (simp add: image_mset_mset_set (*‹inj_on (?f::?'a::type ⇒ ?'b::type) (?A::?'a::type set) ⟹ image_mset ?f (mset_set ?A) = mset_set (?f ` ?A)›*) 2 (*‹(f::nat ⇒ nat) ` {0::nat..<length (xs::'a::type list)} = {0::nat..<length (ys::'a::type list)}›*)) also (*calculation: ‹mset xs = image_mset ((!) ys) (mset_set {0..<length ys})›*) have "… = mset (map ((!) ys) [0..<length ys])" by simp finally (*calculation: ‹mset xs = mset (map ((!) ys) [0..<length ys])›*) show "mset xs = mset ys" by (simp only: map_nth (*‹map ((!) ?xs) [0..<length ?xs] = ?xs›*)) qed lemma direct_decomp_perm: assumes "direct_decomp A ss1" and "mset ss1 = mset ss2" shows "direct_decomp A ss2" proof (-) (*goal: ‹direct_decomp (A::'a set) (ss2::'a set list)›*) from assms(2) (*‹mset (ss1::'a set list) = mset (ss2::'a set list)›*) have len_ss1: "length ss1 = length ss2" using mset_eq_length (*‹mset ?xs = mset ?ys ⟹ length ?xs = length ?ys›*) by blast from assms(2) (*‹mset ss1 = mset ss2›*) obtain f where "f permutes {..<length ss2}" "permute_list f ss2 = ss1" (*goal: ‹(⋀f. ⟦f permutes {..<length ss2}; permute_list f ss2 = ss1⟧ ⟹ thesis) ⟹ thesis›*) by (rule mset_eq_permutation (*‹⟦mset ?xs = mset ?ys; ⋀p. ⟦p permutes {..<length ?ys}; permute_list p ?ys = ?xs⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) then have f_bij: "bij_betw f {..<length ss2} {..<length ss1}" and f: "⋀i. i < length ss2 ⟹ ss1 ! i = ss2 ! f i" apply - (*goals: 1. ‹⟦f permutes {..<length ss2}; permute_list f ss2 = ss1⟧ ⟹ bij_betw f {..<length ss2} {..<length ss1}› 2. ‹⋀i. ⟦i < length ss2; f permutes {..<length ss2}; permute_list f ss2 = ss1⟧ ⟹ ss1 ! i = ss2 ! f i› discuss goal 1*) apply ((auto simp add: permutes_imp_bij (*‹(?p::?'a::type ⇒ ?'a::type) permutes (?S::?'a::type set) ⟹ bij_betw ?p ?S ?S›*) permute_list_nth (*‹⟦(?f::nat ⇒ nat) permutes {..<length (?xs::?'a::type list)}; (?i::nat) < length ?xs⟧ ⟹ permute_list ?f ?xs ! ?i = ?xs ! ?f ?i›*))[1]) (*discuss goal 2*) apply ((auto simp add: permutes_imp_bij (*‹?p permutes ?S ⟹ bij_betw ?p ?S ?S›*) permute_list_nth (*‹⟦?f permutes {..<length ?xs}; ?i < length ?xs⟧ ⟹ permute_list ?f ?xs ! ?i = ?xs ! ?f ?i›*))[1]) (*proven 2 subgoals*) . define g where "g = inv_into {..<length ss2} f" from f_bij (*‹bij_betw f {..<length ss2} {..<length ss1}›*) have g_bij: "bij_betw g {..<length ss1} {..<length ss2}" unfolding g_def len_ss1 (*goal: ‹bij_betw (inv_into {..<length ss2} f) {..<length ss2} {..<length ss2}›*) by (rule bij_betw_inv_into (*‹bij_betw (?f::?'a ⇒ ?'b) (?A::?'a set) (?B::?'b set) ⟹ bij_betw (inv_into ?A ?f) ?B ?A›*)) have f_g: "f (g i) = i" if "i < length ss1" for i proof (-) (*goal: ‹f (g i) = i›*) from that (*‹i < length ss1›*) f_bij (*‹bij_betw f {..<length ss2} {..<length ss1}›*) have "i ∈ f ` {..<length ss2}" by (simp add: bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*) len_ss1 (*‹length ss1 = length ss2›*)) thus "?thesis" (*goal: ‹f (g i) = i›*) by (simp only: f_inv_into_f (*‹?y ∈ ?f ` ?A ⟹ ?f (inv_into ?A ?f ?y) = ?y›*) g_def (*‹g = inv_into {..<length ss2} f›*)) qed have g_f: "g (f i) = i" if "i < length ss2" for i proof (-) (*goal: ‹g (f i) = i›*) from f_bij (*‹bij_betw f {..<length ss2} {..<length ss1}›*) have "inj_on f {..<length ss2}" by (simp only: bij_betw_def (*‹bij_betw (?f::?'a ⇒ ?'b) (?A::?'a set) (?B::?'b set) = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*)) moreover from that (*‹i < length ss2›*) have "i ∈ {..<length ss2}" by simp ultimately show "?thesis" (*goal: ‹g (f i) = i›*) by (simp add: g_def (*‹g = inv_into {..<length ss2} f›*)) qed have g: "ss2 ! i = ss1 ! g i" if "i < length ss1" for i proof (-) (*goal: ‹ss2 ! i = ss1 ! g i›*) from that (*‹i < length ss1›*) have "i ∈ {..<length ss2}" by (simp add: len_ss1 (*‹length ss1 = length ss2›*)) hence "g i ∈ g ` {..<length ss2}" by (rule imageI (*‹(?x::?'a) ∈ (?A::?'a set) ⟹ (?f::?'a ⇒ ?'b) ?x ∈ ?f ` ?A›*)) also (*calculation: ‹g i ∈ g ` {..<length ss2}›*) from g_bij (*‹bij_betw g {..<length ss1} {..<length ss2}›*) have "… = {..<length ss2}" by (simp only: len_ss1 (*‹length ss1 = length ss2›*) bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*)) finally (*calculation: ‹g i ∈ {..<length ss2}›*) have "g i < length ss2" by simp hence "ss1 ! g i = ss2 ! f (g i)" by (rule f (*‹?i < length ss2 ⟹ ss1 ! ?i = ss2 ! f ?i›*)) with that (*‹(i::nat) < length (ss1::'a set list)›*) show "?thesis" (*goal: ‹ss2 ! i = ss1 ! g i›*) by (simp only: f_g (*‹?i < length ss1 ⟹ f (g ?i) = ?i›*)) qed show "?thesis" (*goal: ‹direct_decomp A ss2›*) proof (rule direct_decompI_alt (*‹⟦⋀qs. qs ∈ listset ?ss ⟹ sum_list qs ∈ ?A; ⋀a. a ∈ ?A ⟹ ∃!qs. qs ∈ listset ?ss ∧ a = sum_list qs⟧ ⟹ direct_decomp ?A ?ss›*)) (*goals: 1. ‹⋀qs. qs ∈ listset ss2 ⟹ sum_list qs ∈ A› 2. ‹⋀a. a ∈ A ⟹ ∃!qs. qs ∈ listset ss2 ∧ a = sum_list qs›*) fix qs2 assume "qs2 ∈ listset ss2" (*‹(qs2::'a list) ∈ listset (ss2::'a set list)›*) then obtain qs1 where qs1_in: "qs1 ∈ listset ss1" and len_qs1: "length qs1 = length qs2" and "*": "⋀i. i < length qs2 ⟹ qs1 ! i = qs2 ! f i" (*goal: ‹(⋀qs1. ⟦qs1 ∈ listset ss1; length qs1 = length qs2; ⋀i. i < length qs2 ⟹ qs1 ! i = qs2 ! f i⟧ ⟹ thesis) ⟹ thesis›*) using f_bij (*‹bij_betw f {..<length ss2} {..<length ss1}›*) f (*‹?i < length ss2 ⟹ ss1 ! ?i = ss2 ! f ?i›*) apply (rule listset_permE (*‹⟦?ys ∈ listset ?xs; bij_betw ?f {..<length ?xs} {..<length ?xs'}; ⋀i. i < length ?xs ⟹ ?xs' ! i = ?xs ! ?f i; ⋀ys'. ⟦ys' ∈ listset ?xs'; length ys' = length ?ys; ⋀i. i < length ?ys ⟹ ys' ! i = ?ys ! ?f i⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) (*goals: 1. ‹⋀i::nat. ⟦⋀qs1::'a list. ⟦qs1 ∈ listset (ss1::'a set list); length qs1 = length (qs2::'a list); ⋀i::nat. i < length qs2 ⟹ qs1 ! i = qs2 ! (f::nat ⇒ nat) i⟧ ⟹ thesis::bool; i < length (ss2::'a set list)⟧ ⟹ i < length ss2› 2. ‹⋀ys'::'a list. ⟦⋀qs1::'a list. ⟦qs1 ∈ listset (ss1::'a set list); length qs1 = length (qs2::'a list); ⋀i::nat. i < length qs2 ⟹ qs1 ! i = qs2 ! (f::nat ⇒ nat) i⟧ ⟹ thesis::bool; ys' ∈ listset ss1; length ys' = length qs2; ⋀i::nat. i < length qs2 ⟹ ys' ! i = qs2 ! f i⟧ ⟹ thesis› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) . from ‹qs2 ∈ listset ss2› (*‹qs2 ∈ listset ss2›*) have "length qs2 = length ss2" by (rule listsetD (*‹(?ys::?'a list) ∈ listset (?xs::?'a set list) ⟹ length ?ys = length ?xs› ‹⟦(?ys::?'a list) ∈ listset (?xs::?'a set list); (?i::nat) < length ?xs⟧ ⟹ ?ys ! ?i ∈ ?xs ! ?i›*)) with f_bij (*‹bij_betw f {..<length ss2} {..<length ss1}›*) have "bij_betw f {..<length qs1} {..<length qs2}" by (simp only: len_qs1 (*‹length qs1 = length qs2›*) len_ss1 (*‹length ss1 = length ss2›*)) hence "mset qs1 = mset qs2" using "*" (*‹?i < length qs2 ⟹ qs1 ! ?i = qs2 ! f ?i›*) apply (rule mset_bij (*‹⟦bij_betw ?f {..<length ?xs} {..<length ?ys}; ⋀i. i < length ?xs ⟹ ?xs ! i = ?ys ! ?f i⟧ ⟹ mset ?xs = mset ?ys›*)) (*goal: ‹mset qs1 = mset qs2›*) by (simp only: len_qs1 (*‹length (qs1::'a list) = length (qs2::'a list)›*)) hence "sum_list qs2 = sum_list qs1" by (simp flip: sum_mset_sum_list (*‹∑⇩# (mset ?xs) = sum_list ?xs›*)) also (*calculation: ‹sum_list qs2 = sum_list qs1›*) from assms(1) (*‹direct_decomp (A::'a set) (ss1::'a set list)›*) qs1_in (*‹(qs1::'a::comm_monoid_add list) ∈ listset (ss1::'a::comm_monoid_add set list)›*) have "… ∈ A" by (rule direct_decompD (*‹⟦direct_decomp ?A ?ss; ?qs ∈ listset ?ss⟧ ⟹ sum_list ?qs ∈ ?A› ‹direct_decomp ?A ?ss ⟹ inj_on sum_list (listset ?ss)› ‹direct_decomp ?A ?ss ⟹ sum_list ` listset ?ss = ?A›*)) finally (*calculation: ‹sum_list qs2 ∈ A›*) show "sum_list qs2 ∈ A" . next (*goal: ‹⋀a. a ∈ A ⟹ ∃!qs. qs ∈ listset ss2 ∧ a = sum_list qs›*) fix a assume "a ∈ A" (*‹(a::'a) ∈ (A::'a set)›*) with assms(1) (*‹direct_decomp (A::'a::comm_monoid_add set) (ss1::'a::comm_monoid_add set list)›*) obtain qs where a: "a = sum_list qs" and qs_in: "qs ∈ listset ss1" (*goal: ‹(⋀qs. ⟦a = sum_list qs; qs ∈ listset ss1⟧ ⟹ thesis) ⟹ thesis›*) by (rule direct_decompE (*‹⟦direct_decomp (?A::?'a::comm_monoid_add set) (?ss::?'a::comm_monoid_add set list); (?a::?'a::comm_monoid_add) ∈ ?A; ⋀qs::?'a::comm_monoid_add list. ⟦qs ∈ listset ?ss; ?a = sum_list qs⟧ ⟹ ?thesis::bool⟧ ⟹ ?thesis›*)) from qs_in (*‹qs ∈ listset ss1›*) obtain qs2 where qs2_in: "qs2 ∈ listset ss2" and len_qs2: "length qs2 = length qs" and 1: "⋀i. i < length qs ⟹ qs2 ! i = qs ! g i" (*goal: ‹(⋀qs2. ⟦qs2 ∈ listset ss2; length qs2 = length qs; ⋀i. i < length qs ⟹ qs2 ! i = qs ! g i⟧ ⟹ thesis) ⟹ thesis›*) using g_bij (*‹bij_betw g {..<length ss1} {..<length ss2}›*) g (*‹?i < length ss1 ⟹ ss2 ! ?i = ss1 ! g ?i›*) apply (rule listset_permE (*‹⟦?ys ∈ listset ?xs; bij_betw ?f {..<length ?xs} {..<length ?xs'}; ⋀i. i < length ?xs ⟹ ?xs' ! i = ?xs ! ?f i; ⋀ys'. ⟦ys' ∈ listset ?xs'; length ys' = length ?ys; ⋀i. i < length ?ys ⟹ ys' ! i = ?ys ! ?f i⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) (*goals: 1. ‹⋀i::nat. ⟦⋀qs2::'a list. ⟦qs2 ∈ listset (ss2::'a set list); length qs2 = length (qs::'a list); ⋀i::nat. i < length qs ⟹ qs2 ! i = qs ! (g::nat ⇒ nat) i⟧ ⟹ thesis::bool; i < length (ss1::'a set list)⟧ ⟹ i < length ss1› 2. ‹⋀ys'::'a list. ⟦⋀qs2::'a list. ⟦qs2 ∈ listset (ss2::'a set list); length qs2 = length (qs::'a list); ⋀i::nat. i < length qs ⟹ qs2 ! i = qs ! (g::nat ⇒ nat) i⟧ ⟹ thesis::bool; ys' ∈ listset ss2; length ys' = length qs; ⋀i::nat. i < length qs ⟹ ys' ! i = qs ! g i⟧ ⟹ thesis› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) . show "∃!qs∈listset ss2. a = sum_list qs" proof (intro ex1I (*‹⟦?P ?a; ⋀x. ?P x ⟹ x = ?a⟧ ⟹ ∃!x. ?P x›*) conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*) allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*) impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goals: 1. ‹?a ∈ listset ss2› 2. ‹a = sum_list ?a› 3. ‹⋀qs. qs ∈ listset ss2 ∧ a = sum_list qs ⟹ qs = ?a›*) from qs_in (*‹qs ∈ listset ss1›*) have len_qs: "length qs = length ss1" by (rule listsetD (*‹?ys ∈ listset ?xs ⟹ length ?ys = length ?xs› ‹⟦?ys ∈ listset ?xs; ?i < length ?xs⟧ ⟹ ?ys ! ?i ∈ ?xs ! ?i›*)) with g_bij (*‹bij_betw (g::nat ⇒ nat) {..<length (ss1::'a set list)} {..<length (ss2::'a set list)}›*) have g_bij2: "bij_betw g {..<length qs2} {..<length qs}" by (simp only: len_qs2 (*‹length qs2 = length qs›*) len_ss1 (*‹length ss1 = length ss2›*)) hence "mset qs2 = mset qs" using "1" (*‹?i < length qs ⟹ qs2 ! ?i = qs ! g ?i›*) apply (rule mset_bij (*‹⟦bij_betw (?f::nat ⇒ nat) {..<length (?xs::?'a::type list)} {..<length (?ys::?'a::type list)}; ⋀i::nat. i < length ?xs ⟹ ?xs ! i = ?ys ! ?f i⟧ ⟹ mset ?xs = mset ?ys›*)) (*goal: ‹mset qs2 = mset qs›*) by (simp only: len_qs2 (*‹length qs2 = length qs›*)) thus a2: "a = sum_list qs2" by (simp only: a (*‹(a::'a) = sum_list (qs::'a list)›*) flip: sum_mset_sum_list (*‹∑⇩# (mset (?xs::?'a list)) = sum_list ?xs›*)) fix qs' assume "qs' ∈ listset ss2 ∧ a = sum_list qs'" (*‹(qs'::'a list) ∈ listset (ss2::'a set list) ∧ (a::'a) = sum_list qs'›*) hence qs'_in: "qs' ∈ listset ss2" and a': "a = sum_list qs'" apply - (*goals: 1. ‹(qs'::'a::comm_monoid_add list) ∈ listset (ss2::'a::comm_monoid_add set list) ∧ (a::'a::comm_monoid_add) = sum_list qs' ⟹ qs' ∈ listset ss2› 2. ‹(qs'::'a::comm_monoid_add list) ∈ listset (ss2::'a::comm_monoid_add set list) ∧ (a::'a::comm_monoid_add) = sum_list qs' ⟹ a = sum_list qs'› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . from this(1) (*‹qs' ∈ listset ss2›*) obtain qs1 where qs1_in: "qs1 ∈ listset ss1" and len_qs1: "length qs1 = length qs'" and 2: "⋀i. i < length qs' ⟹ qs1 ! i = qs' ! f i" (*goal: ‹(⋀qs1. ⟦qs1 ∈ listset ss1; length qs1 = length qs'; ⋀i. i < length qs' ⟹ qs1 ! i = qs' ! f i⟧ ⟹ thesis) ⟹ thesis›*) using f_bij (*‹bij_betw f {..<length ss2} {..<length ss1}›*) f (*‹?i < length ss2 ⟹ ss1 ! ?i = ss2 ! f ?i›*) apply (rule listset_permE (*‹⟦(?ys::?'a list) ∈ listset (?xs::?'a set list); bij_betw (?f::nat ⇒ nat) {..<length ?xs} {..<length (?xs'::?'a set list)}; ⋀i::nat. i < length ?xs ⟹ ?xs' ! i = ?xs ! ?f i; ⋀ys'::?'a list. ⟦ys' ∈ listset ?xs'; length ys' = length ?ys; ⋀i::nat. i < length ?ys ⟹ ys' ! i = ?ys ! ?f i⟧ ⟹ ?thesis::bool⟧ ⟹ ?thesis›*)) (*goals: 1. ‹⋀i. ⟦⋀qs1. ⟦qs1 ∈ listset ss1; length qs1 = length qs'; ⋀i. i < length qs' ⟹ qs1 ! i = qs' ! f i⟧ ⟹ thesis; i < length ss2⟧ ⟹ i < length ss2› 2. ‹⋀ys'. ⟦⋀qs1. ⟦qs1 ∈ listset ss1; length qs1 = length qs'; ⋀i. i < length qs' ⟹ qs1 ! i = qs' ! f i⟧ ⟹ thesis; ys' ∈ listset ss1; length ys' = length qs'; ⋀i. i < length qs' ⟹ ys' ! i = qs' ! f i⟧ ⟹ thesis› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) . from ‹qs' ∈ listset ss2› (*‹qs' ∈ listset ss2›*) have "length qs' = length ss2" by (rule listsetD (*‹?ys ∈ listset ?xs ⟹ length ?ys = length ?xs› ‹⟦?ys ∈ listset ?xs; ?i < length ?xs⟧ ⟹ ?ys ! ?i ∈ ?xs ! ?i›*)) with f_bij (*‹bij_betw f {..<length ss2} {..<length ss1}›*) have "bij_betw f {..<length qs1} {..<length qs'}" by (simp only: len_qs1 (*‹length qs1 = length qs'›*) len_ss1 (*‹length ss1 = length ss2›*)) hence "mset qs1 = mset qs'" using "2" (*‹?i < length qs' ⟹ qs1 ! ?i = qs' ! f ?i›*) apply (rule mset_bij (*‹⟦bij_betw ?f {..<length ?xs} {..<length ?ys}; ⋀i. i < length ?xs ⟹ ?xs ! i = ?ys ! ?f i⟧ ⟹ mset ?xs = mset ?ys›*)) (*goal: ‹mset qs1 = mset qs'›*) by (simp only: len_qs1 (*‹length qs1 = length qs'›*)) hence "sum_list qs1 = sum_list qs'" by (simp flip: sum_mset_sum_list (*‹∑⇩# (mset (?xs::?'a list)) = sum_list ?xs›*)) hence "sum_list qs1 = sum_list qs" by (simp only: a (*‹a = sum_list qs›*) flip: a' (*‹a = sum_list qs'›*)) with assms(1) (*‹direct_decomp A ss1›*) qs1_in (*‹qs1 ∈ listset ss1›*) qs_in (*‹qs ∈ listset ss1›*) have "qs1 = qs" by (rule direct_decomp_unique (*‹⟦direct_decomp ?A ?ss; ?qs ∈ listset ?ss; ?qs' ∈ listset ?ss; sum_list ?qs = sum_list ?qs'⟧ ⟹ ?qs = ?qs'›*)) show "qs' = qs2" unfolding list_eq_iff_nth_eq (*goal: ‹length qs' = length qs2 ∧ (∀i<length qs'. qs' ! i = qs2 ! i)›*) proof (intro conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*) allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*) impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goals: 1. ‹length qs' = length qs2› 2. ‹⋀i. i < length qs' ⟹ qs' ! i = qs2 ! i›*) from qs'_in (*‹qs' ∈ listset ss2›*) have "length qs' = length ss2" by (rule listsetD (*‹?ys ∈ listset ?xs ⟹ length ?ys = length ?xs› ‹⟦?ys ∈ listset ?xs; ?i < length ?xs⟧ ⟹ ?ys ! ?i ∈ ?xs ! ?i›*)) thus eq: "length qs' = length qs2" by (simp only: len_qs2 (*‹length qs2 = length qs›*) len_qs (*‹length qs = length ss1›*) len_ss1 (*‹length ss1 = length ss2›*)) fix i assume "i < length qs'" (*‹(i::nat) < length (qs'::'a list)›*) hence "i < length qs2" by (simp only: eq (*‹length qs' = length qs2›*)) hence "i ∈ {..<length qs2}" and "i < length qs" and "i < length ss1" apply - (*goals: 1. ‹i < length qs2 ⟹ i ∈ {..<length qs2}› 2. ‹i < length qs2 ⟹ i < length qs› 3. ‹i < length qs2 ⟹ i < length ss1› discuss goal 1*) apply (simp add: len_qs2 (*‹length qs2 = length qs›*) len_qs (*‹length qs = length ss1›*)) (*discuss goal 2*) apply (simp add: len_qs2 (*‹length (qs2::'a list) = length (qs::'a list)›*) len_qs (*‹length (qs::'a list) = length (ss1::'a set list)›*)) (*discuss goal 3*) apply (simp add: len_qs2 (*‹length qs2 = length qs›*) len_qs (*‹length qs = length ss1›*)) (*proven 3 subgoals*) . from this(1) (*‹i ∈ {..<length qs2}›*) have "g i ∈ g ` {..<length qs2}" by (rule imageI (*‹?x ∈ ?A ⟹ ?f ?x ∈ ?f ` ?A›*)) also (*calculation: ‹g i ∈ g ` {..<length qs2}›*) from g_bij2 (*‹bij_betw (g::nat ⇒ nat) {..<length (qs2::'a list)} {..<length (qs::'a list)}›*) have "… = {..<length qs}" by (simp only: bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*)) finally (*calculation: ‹g i ∈ {..<length qs}›*) have "g i < length qs'" by (simp add: eq (*‹length qs' = length qs2›*) len_qs2 (*‹length qs2 = length qs›*)) from ‹i < length qs› (*‹i < length qs›*) have "qs2 ! i = qs ! g i" by (rule 1 (*‹?i < length qs ⟹ qs2 ! ?i = qs ! g ?i›*)) also (*calculation: ‹qs2 ! i = qs ! g i›*) have "… = qs1 ! g i" by (simp only: ‹qs1 = qs›) also (*calculation: ‹qs2 ! i = qs1 ! g i›*) from ‹g i < length qs'› (*‹g i < length qs'›*) have "… = qs' ! f (g i)" by (rule 2 (*‹(?i::nat) < length (qs'::'a::comm_monoid_add list) ⟹ (qs1::'a::comm_monoid_add list) ! ?i = qs' ! (f::nat ⇒ nat) ?i›*)) also (*calculation: ‹qs2 ! i = qs' ! f (g i)›*) from ‹i < length ss1› (*‹i < length ss1›*) have "… = qs' ! i" by (simp only: f_g (*‹?i < length ss1 ⟹ f (g ?i) = ?i›*)) finally (*calculation: ‹(qs2::'a list) ! (i::nat) = (qs'::'a list) ! i›*) show "qs' ! i = qs2 ! i" by (rule sym (*‹?s = ?t ⟹ ?t = ?s›*)) qed qed (fact) (*solved the remaining goal: ‹(qs2::'a list) ∈ listset (ss2::'a set list)›*) qed qed lemma direct_decomp_split_map: "direct_decomp A (map f ss) ⟹ direct_decomp A (map f (filter P ss) @ map f (filter (- P) ss))" proof (rule direct_decomp_perm (*‹⟦direct_decomp ?A ?ss1.0; mset ?ss1.0 = mset ?ss2.0⟧ ⟹ direct_decomp ?A ?ss2.0›*)) (*goals: 1. ‹direct_decomp A (map f ss) ⟹ direct_decomp A ?ss1.0› 2. ‹direct_decomp A (map f ss) ⟹ mset ?ss1.0 = mset (map f (filter P ss) @ map f (filter (- P) ss))›*) show "mset (map f ss) = mset (map f (filter P ss) @ map f (filter (- P) ss))" apply simp (*goal: ‹mset (map f ss) = mset (map f (filter P ss) @ map f (filter (- P) ss))›*) by (metis image_mset_union (*‹image_mset ?f (?M + ?N) = image_mset ?f ?M + image_mset ?f ?N›*) multiset_partition (*‹?M = filter_mset ?P ?M + {#x ∈# ?M. ¬ ?P x#}›*)) qed lemmas direct_decomp_split = direct_decomp_split_map[where f=id, simplified] lemma direct_decomp_direct_decomp: assumes "direct_decomp A (s # ss)" and "direct_decomp s rs" shows "direct_decomp A (ss @ rs)" (is "direct_decomp A ?ss") proof (rule direct_decompI_alt (*‹⟦⋀qs. qs ∈ listset ?ss ⟹ sum_list qs ∈ ?A; ⋀a. a ∈ ?A ⟹ ∃!qs. qs ∈ listset ?ss ∧ a = sum_list qs⟧ ⟹ direct_decomp ?A ?ss›*)) (*goals: 1. ‹⋀qs::'a::comm_monoid_add list. qs ∈ listset ((ss::'a::comm_monoid_add set list) @ (rs::'a::comm_monoid_add set list)) ⟹ sum_list qs ∈ (A::'a::comm_monoid_add set)› 2. ‹⋀a::'a::comm_monoid_add. a ∈ (A::'a::comm_monoid_add set) ⟹ ∃!qs::'a::comm_monoid_add list. qs ∈ listset ((ss::'a::comm_monoid_add set list) @ (rs::'a::comm_monoid_add set list)) ∧ a = sum_list qs›*) fix qs assume "qs ∈ listset ?ss" (*‹(qs::'a list) ∈ listset ((ss::'a set list) @ (rs::'a set list))›*) then obtain qs1 and qs2 where qs1: "qs1 ∈ listset ss" and qs2: "qs2 ∈ listset rs" and qs: "qs = qs1 @ qs2" (*goal: ‹(⋀qs1 qs2. ⟦qs1 ∈ listset ss; qs2 ∈ listset rs; qs = qs1 @ qs2⟧ ⟹ thesis) ⟹ thesis›*) by (rule listset_appendE (*‹⟦?ys ∈ listset (?xs1.0 @ ?xs2.0); ⋀ys1 ys2. ⟦ys1 ∈ listset ?xs1.0; ys2 ∈ listset ?xs2.0; ?ys = ys1 @ ys2⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) have "sum_list qs = sum_list ((sum_list qs2) # qs1)" by (simp add: qs (*‹qs = qs1 @ qs2›*) add.commute (*‹?a + ?b = ?b + ?a›*)) also (*calculation: ‹sum_list qs = sum_list (sum_list qs2 # qs1)›*) from assms(1) (*‹direct_decomp A (s # ss)›*) have "… ∈ A" proof (rule direct_decompD (*‹⟦direct_decomp ?A ?ss; ?qs ∈ listset ?ss⟧ ⟹ sum_list ?qs ∈ ?A› ‹direct_decomp ?A ?ss ⟹ inj_on sum_list (listset ?ss)› ‹direct_decomp ?A ?ss ⟹ sum_list ` listset ?ss = ?A›*)) (*goal: ‹sum_list qs2 # qs1 ∈ listset (s # ss)›*) from assms(2) (*‹direct_decomp s rs›*) qs2 (*‹(qs2::'a list) ∈ listset (rs::'a set list)›*) have "sum_list qs2 ∈ s" by (rule direct_decompD (*‹⟦direct_decomp ?A ?ss; ?qs ∈ listset ?ss⟧ ⟹ sum_list ?qs ∈ ?A› ‹direct_decomp ?A ?ss ⟹ inj_on sum_list (listset ?ss)› ‹direct_decomp ?A ?ss ⟹ sum_list ` listset ?ss = ?A›*)) thus "sum_list qs2 # qs1 ∈ listset (s # ss)" using qs1 (*‹(qs1::'a::comm_monoid_add list) ∈ listset (ss::'a::comm_monoid_add set list)›*) refl (*‹?t = ?t›*) by (rule listset_ConsI (*‹⟦?y ∈ ?x; ?ys' ∈ listset ?xs; ?ys = ?y # ?ys'⟧ ⟹ ?ys ∈ listset (?x # ?xs)›*)) qed finally (*calculation: ‹sum_list qs ∈ A›*) show "sum_list qs ∈ A" . next (*goal: ‹⋀a. a ∈ A ⟹ ∃!qs. qs ∈ listset (ss @ rs) ∧ a = sum_list qs›*) fix a assume "a ∈ A" (*‹(a::'a) ∈ (A::'a set)›*) with assms(1) (*‹direct_decomp A (s # ss)›*) obtain qs1 where qs1_in: "qs1 ∈ listset (s # ss)" and a: "a = sum_list qs1" (*goal: ‹(⋀qs1. ⟦qs1 ∈ listset (s # ss); a = sum_list qs1⟧ ⟹ thesis) ⟹ thesis›*) by (rule direct_decompE (*‹⟦direct_decomp (?A::?'a set) (?ss::?'a set list); (?a::?'a) ∈ ?A; ⋀qs::?'a list. ⟦qs ∈ listset ?ss; ?a = sum_list qs⟧ ⟹ ?thesis::bool⟧ ⟹ ?thesis›*)) from qs1_in (*‹qs1 ∈ listset (s # ss)›*) obtain qs11 and qs12 where "qs11 ∈ s" and qs12_in: "qs12 ∈ listset ss" and qs1: "qs1 = qs11 # qs12" (*goal: ‹(⋀(qs11::'a) qs12::'a list. ⟦qs11 ∈ (s::'a set); qs12 ∈ listset (ss::'a set list); (qs1::'a list) = qs11 # qs12⟧ ⟹ thesis::bool) ⟹ thesis›*) by (rule listset_ConsE (*‹⟦?ys ∈ listset (?x # ?xs); ⋀y ys'. ⟦y ∈ ?x; ys' ∈ listset ?xs; ?ys = y # ys'⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) from assms(2) (*‹direct_decomp s rs›*) this(1) (*‹qs11 ∈ s›*) obtain qs2 where qs2_in: "qs2 ∈ listset rs" and qs11: "qs11 = sum_list qs2" (*goal: ‹(⋀qs2::'a::comm_monoid_add list. ⟦qs2 ∈ listset (rs::'a::comm_monoid_add set list); (qs11::'a::comm_monoid_add) = sum_list qs2⟧ ⟹ thesis::bool) ⟹ thesis›*) by (rule direct_decompE (*‹⟦direct_decomp (?A::?'a set) (?ss::?'a set list); (?a::?'a) ∈ ?A; ⋀qs::?'a list. ⟦qs ∈ listset ?ss; ?a = sum_list qs⟧ ⟹ ?thesis::bool⟧ ⟹ ?thesis›*)) let ?qs = "qs12 @ qs2" show "∃!qs∈listset ?ss. a = sum_list qs" proof (intro ex1I (*‹⟦?P ?a; ⋀x. ?P x ⟹ x = ?a⟧ ⟹ ∃!x. ?P x›*) conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*) allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*) impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goals: 1. ‹?a ∈ listset (ss @ rs)› 2. ‹a = sum_list ?a› 3. ‹⋀qs. qs ∈ listset (ss @ rs) ∧ a = sum_list qs ⟹ qs = ?a›*) from qs12_in (*‹qs12 ∈ listset ss›*) qs2_in (*‹(qs2::'a list) ∈ listset (rs::'a set list)›*) refl (*‹(?t::?'a) = ?t›*) show "?qs ∈ listset ?ss" by (rule listset_appendI (*‹⟦?ys1.0 ∈ listset ?xs1.0; ?ys2.0 ∈ listset ?xs2.0; ?ys = ?ys1.0 @ ?ys2.0⟧ ⟹ ?ys ∈ listset (?xs1.0 @ ?xs2.0)›*)) show "a = sum_list ?qs" by (simp add: a (*‹a = sum_list qs1›*) qs1 (*‹qs1 = qs11 # qs12›*) qs11 (*‹qs11 = sum_list qs2›*) add.commute (*‹?a + ?b = ?b + ?a›*)) fix qs0 assume "qs0 ∈ listset ?ss ∧ a = sum_list qs0" (*‹(qs0::'a list) ∈ listset ((ss::'a set list) @ (rs::'a set list)) ∧ (a::'a) = sum_list qs0›*) hence qs0_in: "qs0 ∈ listset ?ss" and a2: "a = sum_list qs0" apply - (*goals: 1. ‹qs0 ∈ listset (ss @ rs) ∧ a = sum_list qs0 ⟹ qs0 ∈ listset (ss @ rs)› 2. ‹qs0 ∈ listset (ss @ rs) ∧ a = sum_list qs0 ⟹ a = sum_list qs0› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . from this(1) (*‹qs0 ∈ listset (ss @ rs)›*) obtain qs01 and qs02 where qs01_in: "qs01 ∈ listset ss" and qs02_in: "qs02 ∈ listset rs" and qs0: "qs0 = qs01 @ qs02" (*goal: ‹(⋀qs01 qs02. ⟦qs01 ∈ listset ss; qs02 ∈ listset rs; qs0 = qs01 @ qs02⟧ ⟹ thesis) ⟹ thesis›*) by (rule listset_appendE (*‹⟦?ys ∈ listset (?xs1.0 @ ?xs2.0); ⋀ys1 ys2. ⟦ys1 ∈ listset ?xs1.0; ys2 ∈ listset ?xs2.0; ?ys = ys1 @ ys2⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) note assms(1) (*‹direct_decomp A (s # ss)›*) moreover from "_" (*‹PROP ?psi ⟹ PROP ?psi›*) qs01_in (*‹qs01 ∈ listset ss›*) refl (*‹?t = ?t›*) have "(sum_list qs02) # qs01 ∈ listset (s # ss)" (is "?qs' ∈ _") proof (rule listset_ConsI (*‹⟦(?y::?'a::type) ∈ (?x::?'a::type set); (?ys'::?'a::type list) ∈ listset (?xs::?'a::type set list); (?ys::?'a::type list) = ?y # ?ys'⟧ ⟹ ?ys ∈ listset (?x # ?xs)›*)) (*goal: ‹sum_list qs02 ∈ s›*) from assms(2) (*‹direct_decomp (s::'a set) (rs::'a set list)›*) qs02_in (*‹qs02 ∈ listset rs›*) show "sum_list qs02 ∈ s" by (rule direct_decompD (*‹⟦direct_decomp ?A ?ss; ?qs ∈ listset ?ss⟧ ⟹ sum_list ?qs ∈ ?A› ‹direct_decomp ?A ?ss ⟹ inj_on sum_list (listset ?ss)› ‹direct_decomp ?A ?ss ⟹ sum_list ` listset ?ss = ?A›*)) qed moreover note qs1_in (*‹qs1 ∈ listset (s # ss)›*) moreover from a2 (*‹a = sum_list qs0›*) have "sum_list ?qs' = sum_list qs1" by (simp add: qs0 (*‹qs0 = qs01 @ qs02›*) a (*‹a = sum_list qs1›*) add.commute (*‹?a + ?b = ?b + ?a›*)) ultimately have "?qs' = qs11 # qs12" unfolding qs1 (*goal: ‹sum_list qs02 # qs01 = qs11 # qs12›*) by (rule direct_decomp_unique (*‹⟦direct_decomp ?A ?ss; ?qs ∈ listset ?ss; ?qs' ∈ listset ?ss; sum_list ?qs = sum_list ?qs'⟧ ⟹ ?qs = ?qs'›*)) hence "qs11 = sum_list qs02" and 1: "qs01 = qs12" apply - (*goals: 1. ‹sum_list qs02 # qs01 = qs11 # qs12 ⟹ qs11 = sum_list qs02› 2. ‹sum_list qs02 # qs01 = qs11 # qs12 ⟹ qs01 = qs12› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . from this(1) (*‹(qs11::'a::comm_monoid_add) = sum_list (qs02::'a::comm_monoid_add list)›*) have "sum_list qs02 = sum_list qs2" by (simp only: qs11 (*‹qs11 = sum_list qs2›*)) with assms(2) (*‹direct_decomp s rs›*) qs02_in (*‹qs02 ∈ listset rs›*) qs2_in (*‹qs2 ∈ listset rs›*) have "qs02 = qs2" by (rule direct_decomp_unique (*‹⟦direct_decomp ?A ?ss; ?qs ∈ listset ?ss; ?qs' ∈ listset ?ss; sum_list ?qs = sum_list ?qs'⟧ ⟹ ?qs = ?qs'›*)) thus "qs0 = qs12 @ qs2" by (simp only: 1 (*‹qs01 = qs12›*) qs0 (*‹qs0 = qs01 @ qs02›*)) qed qed lemma sum_list_map_times: "sum_list (map ((*) x) xs) = (x::'a::semiring_0) * sum_list xs" apply (induct xs) (*goals: 1. ‹sum_list (map ((*) x) []) = x * sum_list []› 2. ‹⋀a xs. sum_list (map ((*) x) xs) = x * sum_list xs ⟹ sum_list (map ((*) x) (a # xs)) = x * sum_list (a # xs)› discuss goal 1*) apply (simp add: algebra_simps (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)› ‹(?a::?'a) * (?b::?'a) * (?c::?'a) = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)› ‹(?a::?'a) - (?b::?'a) - (?c::?'a) = ?a - (?b + ?c)› ‹(?a::?'a) + ((?b::?'a) - (?c::?'a)) = ?a + ?b - ?c› ‹((?a::?'a) - (?b::?'a) = (?c::?'a)) = (?a = ?c + ?b)› ‹((?a::?'a) = (?c::?'a) - (?b::?'a)) = (?a + ?b = ?c)› ‹(?a::?'a) - ((?b::?'a) - (?c::?'a)) = ?a + ?c - ?b› ‹(?a::?'a) - (?b::?'a) + (?c::?'a) = ?a + ?c - ?b› and more 31 facts*)) (*discuss goal 2*) apply (simp add: algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 31 facts*)) (*proven 2 subgoals*) . lemma direct_decomp_image_times: assumes "direct_decomp (A::'a::semiring_0 set) ss" and "⋀a b. x * a = x * b ⟹ x ≠ 0 ⟹ a = b" shows "direct_decomp ((*) x ` A) (map ((`) ((*) x)) ss)" (is "direct_decomp ?A ?ss") proof (rule direct_decompI_alt (*‹⟦⋀qs. qs ∈ listset ?ss ⟹ sum_list qs ∈ ?A; ⋀a. a ∈ ?A ⟹ ∃!qs. qs ∈ listset ?ss ∧ a = sum_list qs⟧ ⟹ direct_decomp ?A ?ss›*)) (*goals: 1. ‹⋀qs::'a::semiring_0 list. qs ∈ listset (map ((`) ((*) (x::'a::semiring_0))) (ss::'a::semiring_0 set list)) ⟹ sum_list qs ∈ (*) x ` (A::'a::semiring_0 set)› 2. ‹⋀a::'a::semiring_0. a ∈ (*) (x::'a::semiring_0) ` (A::'a::semiring_0 set) ⟹ ∃!qs::'a::semiring_0 list. qs ∈ listset (map ((`) ((*) x)) (ss::'a::semiring_0 set list)) ∧ a = sum_list qs›*) fix qs assume "qs ∈ listset ?ss" (*‹(qs::'a list) ∈ listset (map ((`) ((*) (x::'a))) (ss::'a set list))›*) then obtain qs0 where qs0_in: "qs0 ∈ listset ss" and qs: "qs = map ((*) x) qs0" (*goal: ‹(⋀qs0. ⟦qs0 ∈ listset ss; qs = map ((*) x) qs0⟧ ⟹ thesis) ⟹ thesis›*) by (rule listset_map_imageE (*‹⟦?ys ∈ listset (map ((`) ?f) ?xs); ⋀ys'. ⟦ys' ∈ listset ?xs; ?ys = map ?f ys'⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) have "sum_list qs = x * sum_list qs0" by (simp only: qs (*‹qs = map ((*) x) qs0›*) sum_list_map_times (*‹sum_list (map ((*) ?x) ?xs) = ?x * sum_list ?xs›*)) moreover from assms(1) (*‹direct_decomp A ss›*) qs0_in (*‹qs0 ∈ listset ss›*) have "sum_list qs0 ∈ A" by (rule direct_decompD (*‹⟦direct_decomp ?A ?ss; ?qs ∈ listset ?ss⟧ ⟹ sum_list ?qs ∈ ?A› ‹direct_decomp ?A ?ss ⟹ inj_on sum_list (listset ?ss)› ‹direct_decomp ?A ?ss ⟹ sum_list ` listset ?ss = ?A›*)) ultimately show "sum_list qs ∈ (*) x ` A" by (rule image_eqI (*‹⟦?b = ?f ?x; ?x ∈ ?A⟧ ⟹ ?b ∈ ?f ` ?A›*)) next (*goal: ‹⋀a. a ∈ (*) x ` A ⟹ ∃!qs. qs ∈ listset (map ((`) ((*) x)) ss) ∧ a = sum_list qs›*) fix a assume "a ∈ ?A" (*‹(a::'a) ∈ (*) (x::'a) ` (A::'a set)›*) then obtain a' where "a' ∈ A" and a: "a = x * a'" (*goal: ‹(⋀a'::'a::semiring_0. ⟦a' ∈ (A::'a::semiring_0 set); (a::'a::semiring_0) = (x::'a::semiring_0) * a'⟧ ⟹ thesis::bool) ⟹ thesis›*) by standard from assms(1) (*‹direct_decomp A ss›*) this(1) (*‹a' ∈ A›*) obtain qs' where qs'_in: "qs' ∈ listset ss" and a': "a' = sum_list qs'" (*goal: ‹(⋀qs'. ⟦qs' ∈ listset ss; a' = sum_list qs'⟧ ⟹ thesis) ⟹ thesis›*) by (rule direct_decompE (*‹⟦direct_decomp (?A::?'a set) (?ss::?'a set list); (?a::?'a) ∈ ?A; ⋀qs::?'a list. ⟦qs ∈ listset ?ss; ?a = sum_list qs⟧ ⟹ ?thesis::bool⟧ ⟹ ?thesis›*)) define qs where "qs = map ((*) x) qs'" show "∃!qs∈listset ?ss. a = sum_list qs" proof (intro ex1I (*‹⟦?P ?a; ⋀x. ?P x ⟹ x = ?a⟧ ⟹ ∃!x. ?P x›*) conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*) allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*) impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goals: 1. ‹?a ∈ listset (map ((`) ((*) x)) ss)› 2. ‹a = sum_list ?a› 3. ‹⋀qs. qs ∈ listset (map ((`) ((*) x)) ss) ∧ a = sum_list qs ⟹ qs = ?a›*) from qs'_in (*‹qs' ∈ listset ss›*) qs_def (*‹qs = map ((*) x) qs'›*) show "qs ∈ listset ?ss" by (rule listset_map_imageI (*‹⟦?ys' ∈ listset ?xs; ?ys = map ?f ?ys'⟧ ⟹ ?ys ∈ listset (map ((`) ?f) ?xs)›*)) fix qs0 assume "qs0 ∈ listset ?ss ∧ a = sum_list qs0" (*‹(qs0::'a list) ∈ listset (map ((`) ((*) (x::'a))) (ss::'a set list)) ∧ (a::'a) = sum_list qs0›*) hence "qs0 ∈ listset ?ss" and a0: "a = sum_list qs0" apply - (*goals: 1. ‹qs0 ∈ listset (map ((`) ((*) x)) ss) ∧ a = sum_list qs0 ⟹ qs0 ∈ listset (map ((`) ((*) x)) ss)› 2. ‹qs0 ∈ listset (map ((`) ((*) x)) ss) ∧ a = sum_list qs0 ⟹ a = sum_list qs0› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . from this(1) (*‹(qs0::'a list) ∈ listset (map ((`) ((*) (x::'a))) (ss::'a set list))›*) obtain qs1 where qs1_in: "qs1 ∈ listset ss" and qs0: "qs0 = map ((*) x) qs1" (*goal: ‹(⋀qs1::'a list. ⟦qs1 ∈ listset (ss::'a set list); (qs0::'a list) = map ((*) (x::'a)) qs1⟧ ⟹ thesis::bool) ⟹ thesis›*) by (rule listset_map_imageE (*‹⟦?ys ∈ listset (map ((`) ?f) ?xs); ⋀ys'. ⟦ys' ∈ listset ?xs; ?ys = map ?f ys'⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) show "qs0 = qs" proof (cases "x = 0") (*goals: 1. ‹(x::'a::semiring_0) = (0::'a::semiring_0) ⟹ (qs0::'a::semiring_0 list) = (qs::'a::semiring_0 list)› 2. ‹(x::'a::semiring_0) ≠ (0::'a::semiring_0) ⟹ (qs0::'a::semiring_0 list) = (qs::'a::semiring_0 list)›*) case True (*‹(x::'a) = (0::'a)›*) from qs1_in (*‹qs1 ∈ listset ss›*) have "length qs1 = length ss" by (rule listsetD (*‹?ys ∈ listset ?xs ⟹ length ?ys = length ?xs› ‹⟦?ys ∈ listset ?xs; ?i < length ?xs⟧ ⟹ ?ys ! ?i ∈ ?xs ! ?i›*)) moreover from qs'_in (*‹qs' ∈ listset ss›*) have "length qs' = length ss" by (rule listsetD (*‹?ys ∈ listset ?xs ⟹ length ?ys = length ?xs› ‹⟦?ys ∈ listset ?xs; ?i < length ?xs⟧ ⟹ ?ys ! ?i ∈ ?xs ! ?i›*)) ultimately show "?thesis" (*goal: ‹qs0 = qs›*) by (simp add: qs_def (*‹qs = map ((*) x) qs'›*) qs0 (*‹qs0 = map ((*) x) qs1›*) list_eq_iff_nth_eq (*‹(?xs = ?ys) = (length ?xs = length ?ys ∧ (∀i<length ?xs. ?xs ! i = ?ys ! i))›*) True (*‹x = 0›*)) next (*goal: ‹x ≠ 0 ⟹ qs0 = qs›*) case False (*‹(x::'a) ≠ (0::'a)›*) have "x * sum_list qs1 = a" by (simp only: a0 (*‹a = sum_list qs0›*) qs0 (*‹qs0 = map ((*) x) qs1›*) sum_list_map_times (*‹sum_list (map ((*) ?x) ?xs) = ?x * sum_list ?xs›*)) also (*calculation: ‹x * sum_list qs1 = a›*) have "… = x * sum_list qs'" by (simp only: a' (*‹a' = sum_list qs'›*) a (*‹a = x * a'›*)) finally (*calculation: ‹x * sum_list qs1 = x * sum_list qs'›*) have "sum_list qs1 = sum_list qs'" using False (*‹x ≠ 0›*) by (rule assms( (*‹⟦x * ?a = x * ?b; x ≠ 0⟧ ⟹ ?a = ?b›*) 2)) with assms(1) (*‹direct_decomp A ss›*) qs1_in (*‹qs1 ∈ listset ss›*) qs'_in (*‹(qs'::'a list) ∈ listset (ss::'a set list)›*) have "qs1 = qs'" by (rule direct_decomp_unique (*‹⟦direct_decomp (?A::?'a set) (?ss::?'a set list); (?qs::?'a list) ∈ listset ?ss; (?qs'::?'a list) ∈ listset ?ss; sum_list ?qs = sum_list ?qs'⟧ ⟹ ?qs = ?qs'›*)) thus "?thesis" (*goal: ‹qs0 = qs›*) by (simp only: qs0 (*‹qs0 = map ((*) x) qs1›*) qs_def (*‹qs = map ((*) x) qs'›*)) qed qed (simp only: a (*‹a = x * a'›*) a' (*‹a' = sum_list qs'›*) qs_def (*‹qs = map ((*) x) qs'›*) sum_list_map_times (*‹sum_list (map ((*) ?x) ?xs) = ?x * sum_list ?xs›*)) (*solved the remaining goal: ‹a = sum_list qs›*) qed lemma direct_decomp_appendD: assumes "direct_decomp A (ss1 @ ss2)" shows "{} ∉ set ss2 ⟹ direct_decomp (sum_list ` listset ss1) ss1" (is "_ ⟹ ?thesis1") and "{} ∉ set ss1 ⟹ direct_decomp (sum_list ` listset ss2) ss2" (is "_ ⟹ ?thesis2") and "direct_decomp A [sum_list ` listset ss1, sum_list ` listset ss2]" (is "direct_decomp _ ?ss") proof (-) (*goals: 1. ‹{} ∉ set ss2 ⟹ direct_decomp (sum_list ` listset ss1) ss1› 2. ‹{} ∉ set ss1 ⟹ direct_decomp (sum_list ` listset ss2) ss2› 3. ‹direct_decomp A [sum_list ` listset ss1, sum_list ` listset ss2]›*) have rl: "direct_decomp (sum_list ` listset ts1) ts1" if "direct_decomp A (ts1 @ ts2)" and "{} ∉ set ts2" for ts1 and ts2 proof (intro direct_decompI (*‹⟦inj_on sum_list (listset ?ss); sum_list ` listset ?ss = ?A⟧ ⟹ direct_decomp ?A ?ss›*) inj_onI (*‹(⋀x y. ⟦x ∈ ?A; y ∈ ?A; ?f x = ?f y⟧ ⟹ x = y) ⟹ inj_on ?f ?A›*) refl (*‹?t = ?t›*)) (*goal: ‹⋀(x::'a list) y::'a list. ⟦x ∈ listset (ts1::'a set list); y ∈ listset ts1; sum_list x = sum_list y⟧ ⟹ x = y›*) fix qs1 and qs2 assume qs1: "qs1 ∈ listset ts1" and qs2: "qs2 ∈ listset ts1" (*‹(qs1::'a list) ∈ listset (ts1::'a set list)› ‹(qs2::'a list) ∈ listset (ts1::'a set list)›*) assume eq: "sum_list qs1 = sum_list qs2" (*‹sum_list (qs1::'a list) = sum_list (qs2::'a list)›*) from that(2) (*‹{} ∉ set (ts2::'a set list)›*) have "listset ts2 ≠ {}" by (simp add: listset_empty_iff (*‹(listset ?xs = {}) = ({} ∈ set ?xs)›*)) then obtain qs3 where qs3: "qs3 ∈ listset ts2" (*goal: ‹(⋀qs3. qs3 ∈ listset ts2 ⟹ thesis) ⟹ thesis›*) by blast note that(1) (*‹direct_decomp A (ts1 @ ts2)›*) moreover from qs1 (*‹qs1 ∈ listset ts1›*) qs3 (*‹qs3 ∈ listset ts2›*) refl (*‹(?t::?'a::type) = ?t›*) have "qs1 @ qs3 ∈ listset (ts1 @ ts2)" by (rule listset_appendI (*‹⟦?ys1.0 ∈ listset ?xs1.0; ?ys2.0 ∈ listset ?xs2.0; ?ys = ?ys1.0 @ ?ys2.0⟧ ⟹ ?ys ∈ listset (?xs1.0 @ ?xs2.0)›*)) moreover from qs2 (*‹qs2 ∈ listset ts1›*) qs3 (*‹qs3 ∈ listset ts2›*) refl (*‹?t = ?t›*) have "qs2 @ qs3 ∈ listset (ts1 @ ts2)" by (rule listset_appendI (*‹⟦?ys1.0 ∈ listset ?xs1.0; ?ys2.0 ∈ listset ?xs2.0; ?ys = ?ys1.0 @ ?ys2.0⟧ ⟹ ?ys ∈ listset (?xs1.0 @ ?xs2.0)›*)) moreover have "sum_list (qs1 @ qs3) = sum_list (qs2 @ qs3)" by (simp add: eq (*‹sum_list (qs1::'a::comm_monoid_add list) = sum_list (qs2::'a::comm_monoid_add list)›*)) ultimately have "qs1 @ qs3 = qs2 @ qs3" by (rule direct_decomp_unique (*‹⟦direct_decomp ?A ?ss; ?qs ∈ listset ?ss; ?qs' ∈ listset ?ss; sum_list ?qs = sum_list ?qs'⟧ ⟹ ?qs = ?qs'›*)) thus "qs1 = qs2" by simp qed { assume "{} ∉ set ss2" (*‹{} ∉ set (ss2::'a set list)›*) with assms (*‹direct_decomp A (ss1 @ ss2)›*) show "?thesis1" (*goal: ‹direct_decomp (sum_list ` listset ss1) ss1›*) by (rule rl (*‹⟦direct_decomp (A::'a set) ((?ts1.0::'a set list) @ (?ts2.0::'a set list)); {} ∉ set ?ts2.0⟧ ⟹ direct_decomp (sum_list ` listset ?ts1.0) ?ts1.0›*)) } { from assms (*‹direct_decomp A (ss1 @ ss2)›*) have "direct_decomp A (ss2 @ ss1)" apply (rule direct_decomp_perm (*‹⟦direct_decomp ?A ?ss1.0; mset ?ss1.0 = mset ?ss2.0⟧ ⟹ direct_decomp ?A ?ss2.0›*)) (*goal: ‹direct_decomp (A::'a set) ((ss2::'a set list) @ (ss1::'a set list))›*) by simp moreover assume "{} ∉ set ss1" (*‹{} ∉ set (ss1::'a set list)›*) ultimately show "?thesis2" (*goal: ‹direct_decomp (sum_list ` listset ss2) ss2›*) by (rule rl (*‹⟦direct_decomp A (?ts1.0 @ ?ts2.0); {} ∉ set ?ts2.0⟧ ⟹ direct_decomp (sum_list ` listset ?ts1.0) ?ts1.0›*)) } show "direct_decomp A ?ss" proof (rule direct_decompI_alt (*‹⟦⋀qs. qs ∈ listset ?ss ⟹ sum_list qs ∈ ?A; ⋀a. a ∈ ?A ⟹ ∃!qs. qs ∈ listset ?ss ∧ a = sum_list qs⟧ ⟹ direct_decomp ?A ?ss›*)) (*goals: 1. ‹⋀qs. qs ∈ listset [sum_list ` listset ss1, sum_list ` listset ss2] ⟹ sum_list qs ∈ A› 2. ‹⋀a. a ∈ A ⟹ ∃!qs. qs ∈ listset [sum_list ` listset ss1, sum_list ` listset ss2] ∧ a = sum_list qs›*) fix qs assume "qs ∈ listset ?ss" (*‹(qs::'a list) ∈ listset [sum_list ` listset (ss1::'a set list), sum_list ` listset (ss2::'a set list)]›*) then obtain q1 and q2 where q1: "q1 ∈ sum_list ` listset ss1" and q2: "q2 ∈ sum_list ` listset ss2" and qs: "qs = [q1, q2]" (*goal: ‹(⋀(q1::'a) q2::'a. ⟦q1 ∈ sum_list ` listset (ss1::'a set list); q2 ∈ sum_list ` listset (ss2::'a set list); (qs::'a list) = [q1, q2]⟧ ⟹ thesis::bool) ⟹ thesis›*) by (rule listset_doubletonE (*‹⟦(?ys::?'a list) ∈ listset [?A::?'a set, ?B::?'a set]; ⋀(a::?'a) b::?'a. ⟦a ∈ ?A; b ∈ ?B; ?ys = [a, b]⟧ ⟹ ?thesis::bool⟧ ⟹ ?thesis›*)) from q1 (*‹q1 ∈ sum_list ` listset ss1›*) obtain qs1 where qs1: "qs1 ∈ listset ss1" and q1: "q1 = sum_list qs1" (*goal: ‹(⋀qs1::'a list. ⟦qs1 ∈ listset (ss1::'a set list); (q1::'a) = sum_list qs1⟧ ⟹ thesis::bool) ⟹ thesis›*) by standard from q2 (*‹q2 ∈ sum_list ` listset ss2›*) obtain qs2 where qs2: "qs2 ∈ listset ss2" and q2: "q2 = sum_list qs2" (*goal: ‹(⋀qs2. ⟦qs2 ∈ listset ss2; q2 = sum_list qs2⟧ ⟹ thesis) ⟹ thesis›*) by standard from qs1 (*‹qs1 ∈ listset ss1›*) qs2 (*‹qs2 ∈ listset ss2›*) refl (*‹?t = ?t›*) have "qs1 @ qs2 ∈ listset (ss1 @ ss2)" by (rule listset_appendI (*‹⟦?ys1.0 ∈ listset ?xs1.0; ?ys2.0 ∈ listset ?xs2.0; ?ys = ?ys1.0 @ ?ys2.0⟧ ⟹ ?ys ∈ listset (?xs1.0 @ ?xs2.0)›*)) with assms (*‹direct_decomp (A::'a set) ((ss1::'a set list) @ (ss2::'a set list))›*) have "sum_list (qs1 @ qs2) ∈ A" by (rule direct_decompD (*‹⟦direct_decomp ?A ?ss; ?qs ∈ listset ?ss⟧ ⟹ sum_list ?qs ∈ ?A› ‹direct_decomp ?A ?ss ⟹ inj_on sum_list (listset ?ss)› ‹direct_decomp ?A ?ss ⟹ sum_list ` listset ?ss = ?A›*)) thus "sum_list qs ∈ A" by (simp add: qs (*‹qs = [q1, q2]›*) q1 (*‹q1 = sum_list qs1›*) q2 (*‹q2 = sum_list qs2›*)) next (*goal: ‹⋀a::'a. a ∈ (A::'a set) ⟹ ∃!qs::'a list. qs ∈ listset [sum_list ` listset (ss1::'a set list), sum_list ` listset (ss2::'a set list)] ∧ a = sum_list qs›*) fix a assume "a ∈ A" (*‹(a::'a) ∈ (A::'a set)›*) with assms (*‹direct_decomp A (ss1 @ ss2)›*) obtain qs0 where qs0_in: "qs0 ∈ listset (ss1 @ ss2)" and a: "a = sum_list qs0" (*goal: ‹(⋀qs0. ⟦qs0 ∈ listset (ss1 @ ss2); a = sum_list qs0⟧ ⟹ thesis) ⟹ thesis›*) by (rule direct_decompE (*‹⟦direct_decomp ?A ?ss; ?a ∈ ?A; ⋀qs. ⟦qs ∈ listset ?ss; ?a = sum_list qs⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) from this(1) (*‹qs0 ∈ listset (ss1 @ ss2)›*) obtain qs1 and qs2 where qs1: "qs1 ∈ listset ss1" and qs2: "qs2 ∈ listset ss2" and qs0: "qs0 = qs1 @ qs2" (*goal: ‹(⋀qs1 qs2. ⟦qs1 ∈ listset ss1; qs2 ∈ listset ss2; qs0 = qs1 @ qs2⟧ ⟹ thesis) ⟹ thesis›*) by (rule listset_appendE (*‹⟦?ys ∈ listset (?xs1.0 @ ?xs2.0); ⋀ys1 ys2. ⟦ys1 ∈ listset ?xs1.0; ys2 ∈ listset ?xs2.0; ?ys = ys1 @ ys2⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) from qs1 (*‹(qs1::'a list) ∈ listset (ss1::'a set list)›*) have len_qs1: "length qs1 = length ss1" by (rule listsetD (*‹?ys ∈ listset ?xs ⟹ length ?ys = length ?xs› ‹⟦?ys ∈ listset ?xs; ?i < length ?xs⟧ ⟹ ?ys ! ?i ∈ ?xs ! ?i›*)) define qs where "qs = [sum_list qs1, sum_list qs2]" show "∃!qs∈listset ?ss. a = sum_list qs" proof (intro ex1I (*‹⟦?P ?a; ⋀x. ?P x ⟹ x = ?a⟧ ⟹ ∃!x. ?P x›*) conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹(?a::'a::comm_monoid_add list) ∈ listset [sum_list ` listset (ss1::'a::comm_monoid_add set list), sum_list ` listset (ss2::'a::comm_monoid_add set list)]› 2. ‹(a::'a::comm_monoid_add) = sum_list (?a::'a::comm_monoid_add list)› 3. ‹⋀qs::'a::comm_monoid_add list. qs ∈ listset [sum_list ` listset (ss1::'a::comm_monoid_add set list), sum_list ` listset (ss2::'a::comm_monoid_add set list)] ∧ (a::'a::comm_monoid_add) = sum_list qs ⟹ qs = (?a::'a::comm_monoid_add list)›*) from qs1 (*‹qs1 ∈ listset ss1›*) have "sum_list qs1 ∈ sum_list ` listset ss1" by (rule imageI (*‹?x ∈ ?A ⟹ ?f ?x ∈ ?f ` ?A›*)) moreover from qs2 (*‹qs2 ∈ listset ss2›*) have "sum_list qs2 ∈ sum_list ` listset ss2" by (rule imageI (*‹?x ∈ ?A ⟹ ?f ?x ∈ ?f ` ?A›*)) ultimately show "qs ∈ listset ?ss" using qs_def (*‹qs = [sum_list qs1, sum_list qs2]›*) by (rule listset_doubletonI (*‹⟦?a ∈ ?A; ?b ∈ ?B; ?ys = [?a, ?b]⟧ ⟹ ?ys ∈ listset [?A, ?B]›*)) fix qs' assume "qs' ∈ listset ?ss ∧ a = sum_list qs'" (*‹(qs'::'a list) ∈ listset [sum_list ` listset (ss1::'a set list), sum_list ` listset (ss2::'a set list)] ∧ (a::'a) = sum_list qs'›*) hence "qs' ∈ listset ?ss" and a': "a = sum_list qs'" apply - (*goals: 1. ‹qs' ∈ listset [sum_list ` listset ss1, sum_list ` listset ss2] ∧ a = sum_list qs' ⟹ qs' ∈ listset [sum_list ` listset ss1, sum_list ` listset ss2]› 2. ‹qs' ∈ listset [sum_list ` listset ss1, sum_list ` listset ss2] ∧ a = sum_list qs' ⟹ a = sum_list qs'› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . from this(1) (*‹qs' ∈ listset [sum_list ` listset ss1, sum_list ` listset ss2]›*) obtain q1 and q2 where q1: "q1 ∈ sum_list ` listset ss1" and q2: "q2 ∈ sum_list ` listset ss2" and qs': "qs' = [q1, q2]" (*goal: ‹(⋀q1 q2. ⟦q1 ∈ sum_list ` listset ss1; q2 ∈ sum_list ` listset ss2; qs' = [q1, q2]⟧ ⟹ thesis) ⟹ thesis›*) by (rule listset_doubletonE (*‹⟦(?ys::?'a list) ∈ listset [?A::?'a set, ?B::?'a set]; ⋀(a::?'a) b::?'a. ⟦a ∈ ?A; b ∈ ?B; ?ys = [a, b]⟧ ⟹ ?thesis::bool⟧ ⟹ ?thesis›*)) from q1 (*‹q1 ∈ sum_list ` listset ss1›*) obtain qs1' where qs1': "qs1' ∈ listset ss1" and q1: "q1 = sum_list qs1'" (*goal: ‹(⋀qs1'. ⟦qs1' ∈ listset ss1; q1 = sum_list qs1'⟧ ⟹ thesis) ⟹ thesis›*) by standard from q2 (*‹q2 ∈ sum_list ` listset ss2›*) obtain qs2' where qs2': "qs2' ∈ listset ss2" and q2: "q2 = sum_list qs2'" (*goal: ‹(⋀qs2'::'a list. ⟦qs2' ∈ listset (ss2::'a set list); (q2::'a) = sum_list qs2'⟧ ⟹ thesis::bool) ⟹ thesis›*) by standard from qs1' (*‹qs1' ∈ listset ss1›*) have len_qs1': "length qs1' = length ss1" by (rule listsetD (*‹?ys ∈ listset ?xs ⟹ length ?ys = length ?xs› ‹⟦?ys ∈ listset ?xs; ?i < length ?xs⟧ ⟹ ?ys ! ?i ∈ ?xs ! ?i›*)) note assms (*‹direct_decomp A (ss1 @ ss2)›*) moreover from qs1' (*‹qs1' ∈ listset ss1›*) qs2' (*‹qs2' ∈ listset ss2›*) refl (*‹(?t::?'a) = ?t›*) have "qs1' @ qs2' ∈ listset (ss1 @ ss2)" by (rule listset_appendI (*‹⟦?ys1.0 ∈ listset ?xs1.0; ?ys2.0 ∈ listset ?xs2.0; ?ys = ?ys1.0 @ ?ys2.0⟧ ⟹ ?ys ∈ listset (?xs1.0 @ ?xs2.0)›*)) moreover note qs0_in (*‹(qs0::'a::comm_monoid_add list) ∈ listset ((ss1::'a::comm_monoid_add set list) @ (ss2::'a::comm_monoid_add set list))›*) moreover have "sum_list (qs1' @ qs2') = sum_list qs0" by (simp add: a' (*‹a = sum_list qs'›*) qs' (*‹qs' = [q1, q2]›*) flip: a (*‹a = sum_list qs0›*) q1 (*‹q1 = sum_list qs1'›*) q2 (*‹q2 = sum_list qs2'›*)) ultimately have "qs1' @ qs2' = qs0" by (rule direct_decomp_unique (*‹⟦direct_decomp ?A ?ss; ?qs ∈ listset ?ss; ?qs' ∈ listset ?ss; sum_list ?qs = sum_list ?qs'⟧ ⟹ ?qs = ?qs'›*)) also (*calculation: ‹qs1' @ qs2' = qs0›*) have "… = qs1 @ qs2" by fact finally (*calculation: ‹(qs1'::'a list) @ (qs2'::'a list) = (qs1::'a list) @ (qs2::'a list)›*) show "qs' = qs" by (simp add: qs_def (*‹qs = [sum_list qs1, sum_list qs2]›*) qs' (*‹qs' = [q1, q2]›*) q1 (*‹q1 = sum_list qs1'›*) q2 (*‹q2 = sum_list qs2'›*) len_qs1 (*‹length qs1 = length ss1›*) len_qs1' (*‹length qs1' = length ss1›*)) qed (simp add: qs_def (*‹qs = [sum_list qs1, sum_list qs2]›*) a (*‹a = sum_list qs0›*) qs0 (*‹qs0 = qs1 @ qs2›*)) (*solved the remaining goal: ‹a = sum_list qs›*) qed qed lemma direct_decomp_Cons_zeroI: assumes "direct_decomp A ss" shows "direct_decomp A ({0} # ss)" proof (rule direct_decompI_alt (*‹⟦⋀qs. qs ∈ listset ?ss ⟹ sum_list qs ∈ ?A; ⋀a. a ∈ ?A ⟹ ∃!qs. qs ∈ listset ?ss ∧ a = sum_list qs⟧ ⟹ direct_decomp ?A ?ss›*)) (*goals: 1. ‹⋀qs. qs ∈ listset ({0} # ss) ⟹ sum_list qs ∈ A› 2. ‹⋀a. a ∈ A ⟹ ∃!qs. qs ∈ listset ({0} # ss) ∧ a = sum_list qs›*) fix qs assume "qs ∈ listset ({0} # ss)" (*‹(qs::'a list) ∈ listset ({0::'a} # (ss::'a set list))›*) then obtain q and qs' where "q ∈ {0}" and "qs' ∈ listset ss" and "qs = q # qs'" (*goal: ‹(⋀q qs'. ⟦q ∈ {0}; qs' ∈ listset ss; qs = q # qs'⟧ ⟹ thesis) ⟹ thesis›*) by (rule listset_ConsE (*‹⟦?ys ∈ listset (?x # ?xs); ⋀y ys'. ⟦y ∈ ?x; ys' ∈ listset ?xs; ?ys = y # ys'⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) from this(1,3) (*‹q ∈ {0}› ‹(qs::'a list) = (q::'a) # (qs'::'a list)›*) have "sum_list qs = sum_list qs'" by simp also (*calculation: ‹sum_list (qs::'a list) = sum_list (qs'::'a list)›*) from assms (*‹direct_decomp (A::'a set) (ss::'a set list)›*) ‹qs' ∈ listset ss› (*‹qs' ∈ listset ss›*) have "… ∈ A" by (rule direct_decompD (*‹⟦direct_decomp (?A::?'a set) (?ss::?'a set list); (?qs::?'a list) ∈ listset ?ss⟧ ⟹ sum_list ?qs ∈ ?A› ‹direct_decomp (?A::?'a set) (?ss::?'a set list) ⟹ inj_on sum_list (listset ?ss)› ‹direct_decomp (?A::?'a set) (?ss::?'a set list) ⟹ sum_list ` listset ?ss = ?A›*)) finally (*calculation: ‹sum_list qs ∈ A›*) show "sum_list qs ∈ A" . next (*goal: ‹⋀a::'a::comm_monoid_add. a ∈ (A::'a::comm_monoid_add set) ⟹ ∃!qs::'a::comm_monoid_add list. qs ∈ listset ({0::'a::comm_monoid_add} # (ss::'a::comm_monoid_add set list)) ∧ a = sum_list qs›*) fix a assume "a ∈ A" (*‹(a::'a) ∈ (A::'a set)›*) with assms (*‹direct_decomp (A::'a::comm_monoid_add set) (ss::'a::comm_monoid_add set list)›*) obtain qs' where qs': "qs' ∈ listset ss" and a: "a = sum_list qs'" (*goal: ‹(⋀qs'. ⟦qs' ∈ listset ss; a = sum_list qs'⟧ ⟹ thesis) ⟹ thesis›*) by (rule direct_decompE (*‹⟦direct_decomp ?A ?ss; ?a ∈ ?A; ⋀qs. ⟦qs ∈ listset ?ss; ?a = sum_list qs⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) define qs where "qs = 0 # qs'" show "∃!qs. qs ∈ listset ({0} # ss) ∧ a = sum_list qs" proof (intro ex1I (*‹⟦?P ?a; ⋀x. ?P x ⟹ x = ?a⟧ ⟹ ∃!x. ?P x›*) conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹?a ∈ listset ({0} # ss)› 2. ‹a = sum_list ?a› 3. ‹⋀qs. qs ∈ listset ({0} # ss) ∧ a = sum_list qs ⟹ qs = ?a›*) from "_" (*‹PROP ?psi::prop ⟹ PROP ?psi›*) qs' (*‹qs' ∈ listset ss›*) qs_def (*‹qs = 0 # qs'›*) show "qs ∈ listset ({0} # ss)" apply (rule listset_ConsI (*‹⟦?y ∈ ?x; ?ys' ∈ listset ?xs; ?ys = ?y # ?ys'⟧ ⟹ ?ys ∈ listset (?x # ?xs)›*)) (*goal: ‹qs ∈ listset ({0} # ss)›*) by simp next (*goals: 1. ‹a = sum_list qs› 2. ‹⋀qsa. qsa ∈ listset ({0} # ss) ∧ a = sum_list qsa ⟹ qsa = qs›*) fix qs0 assume "qs0 ∈ listset ({0} # ss) ∧ a = sum_list qs0" (*‹(qs0::'a list) ∈ listset ({0::'a} # (ss::'a set list)) ∧ (a::'a) = sum_list qs0›*) hence "qs0 ∈ listset ({0} # ss)" and a0: "a = sum_list qs0" apply - (*goals: 1. ‹(qs0::'a list) ∈ listset ({0::'a} # (ss::'a set list)) ∧ (a::'a) = sum_list qs0 ⟹ qs0 ∈ listset ({0::'a} # ss)› 2. ‹(qs0::'a list) ∈ listset ({0::'a} # (ss::'a set list)) ∧ (a::'a) = sum_list qs0 ⟹ a = sum_list qs0› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . from this(1) (*‹qs0 ∈ listset ({0} # ss)›*) obtain q0 and qs0' where "q0 ∈ {0}" and qs0': "qs0' ∈ listset ss" and qs0: "qs0 = q0 # qs0'" (*goal: ‹(⋀q0 qs0'. ⟦q0 ∈ {0}; qs0' ∈ listset ss; qs0 = q0 # qs0'⟧ ⟹ thesis) ⟹ thesis›*) by (rule listset_ConsE (*‹⟦?ys ∈ listset (?x # ?xs); ⋀y ys'. ⟦y ∈ ?x; ys' ∈ listset ?xs; ?ys = y # ys'⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) from this(1,3) (*‹q0 ∈ {0}› ‹qs0 = q0 # qs0'›*) have "sum_list qs0' = sum_list qs'" by (simp add: a0 (*‹a = sum_list qs0›*) flip: a (*‹a = sum_list qs'›*)) with assms (*‹direct_decomp A ss›*) qs0' (*‹qs0' ∈ listset ss›*) qs' (*‹qs' ∈ listset ss›*) have "qs0' = qs'" by (rule direct_decomp_unique (*‹⟦direct_decomp ?A ?ss; ?qs ∈ listset ?ss; ?qs' ∈ listset ?ss; sum_list ?qs = sum_list ?qs'⟧ ⟹ ?qs = ?qs'›*)) with ‹q0 ∈ {0}› (*‹q0 ∈ {0}›*) show "qs0 = qs" by (simp add: qs_def (*‹qs = 0 # qs'›*) qs0 (*‹qs0 = q0 # qs0'›*)) qed (simp add: qs_def (*‹qs = 0 # qs'›*) a (*‹a = sum_list qs'›*)) (*solved the remaining goal: ‹a = sum_list qs›*) qed lemma direct_decomp_Cons_zeroD: assumes "direct_decomp A ({0} # ss)" shows "direct_decomp A ss" proof (-) (*goal: ‹direct_decomp A ss›*) have "direct_decomp {0} []" by (simp add: direct_decomp_def (*‹direct_decomp ?A ?ss = bij_betw sum_list (listset ?ss) ?A›*) bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*)) with assms (*‹direct_decomp A ({0} # ss)›*) have "direct_decomp A (ss @ [])" by (rule direct_decomp_direct_decomp (*‹⟦direct_decomp ?A (?s # ?ss); direct_decomp ?s ?rs⟧ ⟹ direct_decomp ?A (?ss @ ?rs)›*)) thus "?thesis" (*goal: ‹direct_decomp A ss›*) by simp qed lemma direct_decomp_Cons_subsetI: assumes "direct_decomp A (s # ss)" and "⋀s0. s0 ∈ set ss ⟹ 0 ∈ s0" shows "s ⊆ A" proof (standard) (*goal: ‹⋀x. x ∈ s ⟹ x ∈ A›*) fix x assume "x ∈ s" (*‹(x::'a) ∈ (s::'a set)›*) moreover from assms(2) (*‹?s0.0 ∈ set ss ⟹ 0 ∈ ?s0.0›*) have "map (λ_. 0) ss ∈ listset ss" apply (induct ss) (*goals: 1. ‹(⋀s0. s0 ∈ set [] ⟹ 0 ∈ s0) ⟹ map (λ_. 0) [] ∈ listset []› 2. ‹⋀a ss. ⟦(⋀s0. s0 ∈ set ss ⟹ 0 ∈ s0) ⟹ map (λ_. 0) ss ∈ listset ss; ⋀s0. s0 ∈ set (a # ss) ⟹ 0 ∈ s0⟧ ⟹ map (λ_. 0) (a # ss) ∈ listset (a # ss)› discuss goal 1*) apply ((auto simp del: listset.simps( (*‹listset (?A # ?As) = set_Cons ?A (listset ?As)›*) 2) intro: listset_ConsI (*‹⟦?y ∈ ?x; ?ys' ∈ listset ?xs; ?ys = ?y # ?ys'⟧ ⟹ ?ys ∈ listset (?x # ?xs)›*))[1]) (*discuss goal 2*) apply ((auto simp del: listset.simps( (*‹listset (?A # ?As) = set_Cons ?A (listset ?As)›*) 2) intro: listset_ConsI (*‹⟦?y ∈ ?x; ?ys' ∈ listset ?xs; ?ys = ?y # ?ys'⟧ ⟹ ?ys ∈ listset (?x # ?xs)›*))[1]) (*proven 2 subgoals*) . ultimately have "x # (map (λ_. 0) ss) ∈ listset (s # ss)" using refl (*‹?t = ?t›*) by (rule listset_ConsI (*‹⟦(?y::?'a) ∈ (?x::?'a set); (?ys'::?'a list) ∈ listset (?xs::?'a set list); (?ys::?'a list) = ?y # ?ys'⟧ ⟹ ?ys ∈ listset (?x # ?xs)›*)) with assms(1) (*‹direct_decomp A (s # ss)›*) have "sum_list (x # (map (λ_. 0) ss)) ∈ A" by (rule direct_decompD (*‹⟦direct_decomp ?A ?ss; ?qs ∈ listset ?ss⟧ ⟹ sum_list ?qs ∈ ?A› ‹direct_decomp ?A ?ss ⟹ inj_on sum_list (listset ?ss)› ‹direct_decomp ?A ?ss ⟹ sum_list ` listset ?ss = ?A›*)) thus "x ∈ A" by simp qed lemma direct_decomp_Int_zero: assumes "direct_decomp A ss" and "i < j" and "j < length ss" and "⋀s. s ∈ set ss ⟹ 0 ∈ s" shows "ss ! i ∩ ss ! j = {0}" proof (-) (*goal: ‹(ss::'a set list) ! (i::nat) ∩ ss ! (j::nat) = {0::'a}›*) from assms(2,3) (*‹(i::nat) < (j::nat)› ‹j < length ss›*) have "i < length ss" by (rule less_trans (*‹⟦?x < ?y; ?y < ?z⟧ ⟹ ?x < ?z›*)) hence i_in: "ss ! i ∈ set ss" by simp from assms(3) (*‹j < length ss›*) have j_in: "ss ! j ∈ set ss" by simp show "?thesis" (*goal: ‹ss ! i ∩ ss ! j = {0}›*) proof (standard) (*goals: 1. ‹(ss::'a set list) ! (i::nat) ∩ ss ! (j::nat) ⊆ {0::'a}› 2. ‹{0::'a} ⊆ (ss::'a set list) ! (i::nat) ∩ ss ! (j::nat)›*) show "ss ! i ∩ ss ! j ⊆ {0}" proof (standard) (*goal: ‹⋀x. x ∈ ss ! i ∩ ss ! j ⟹ x ∈ {0}›*) fix x assume "x ∈ ss ! i ∩ ss ! j" (*‹(x::'a) ∈ (ss::'a set list) ! (i::nat) ∩ ss ! (j::nat)›*) hence x_i: "x ∈ ss ! i" and x_j: "x ∈ ss ! j" apply - (*goals: 1. ‹x ∈ ss ! i ∩ ss ! j ⟹ x ∈ ss ! i› 2. ‹x ∈ ss ! i ∩ ss ! j ⟹ x ∈ ss ! j› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . have 1: "(map (λ_. 0) ss)[k := y] ∈ listset ss" if "k < length ss" and "y ∈ ss ! k" for k and y using assms(4) (*‹?s ∈ set ss ⟹ 0 ∈ ?s›*) that (*‹k < length ss› ‹y ∈ ss ! k›*) proof (induct ss arbitrary: k) (*goals: 1. ‹⋀k. ⟦⋀s. s ∈ set [] ⟹ 0 ∈ s; k < length []; y ∈ [] ! k⟧ ⟹ (map (λ_. 0) [])[k := y] ∈ listset []› 2. ‹⋀a ss k. ⟦⋀k. ⟦⋀s. s ∈ set ss ⟹ 0 ∈ s; k < length ss; y ∈ ss ! k⟧ ⟹ (map (λ_. 0) ss)[k := y] ∈ listset ss; ⋀s. s ∈ set (a # ss) ⟹ 0 ∈ s; k < length (a # ss); y ∈ (a # ss) ! k⟧ ⟹ (map (λ_. 0) (a # ss))[k := y] ∈ listset (a # ss)›*) case Nil (*‹?s ∈ set [] ⟹ 0 ∈ ?s› ‹k < length []› ‹y ∈ [] ! k›*) from Nil(2) (*‹k < length []›*) show "?case" (*goal: ‹(map (λ_. 0) [])[k := y] ∈ listset []›*) by simp next (*goal: ‹⋀a ss k. ⟦⋀k. ⟦⋀s. s ∈ set ss ⟹ 0 ∈ s; k < length ss; y ∈ ss ! k⟧ ⟹ (map (λ_. 0) ss)[k := y] ∈ listset ss; ⋀s. s ∈ set (a # ss) ⟹ 0 ∈ s; k < length (a # ss); y ∈ (a # ss) ! k⟧ ⟹ (map (λ_. 0) (a # ss))[k := y] ∈ listset (a # ss)›*) case (Cons s ss) (*‹⟦⋀s. s ∈ set ss ⟹ 0 ∈ s; ?k < length ss; y ∈ ss ! ?k⟧ ⟹ (map (λ_. 0) ss)[?k := y] ∈ listset ss› ‹?s ∈ set (s # ss) ⟹ 0 ∈ ?s› ‹k < length (s # ss)› ‹y ∈ (s # ss) ! k›*) have "*": "⋀s'. s' ∈ set ss ⟹ 0 ∈ s'" apply (rule Cons.prems (*‹(?s::'a set) ∈ set ((s::'a set) # (ss::'a set list)) ⟹ (0::'a) ∈ ?s› ‹(k::nat) < length ((s::'a set) # (ss::'a set list))› ‹(y::'a) ∈ ((s::'a set) # (ss::'a set list)) ! (k::nat)›*)) (*goal: ‹⋀s'::'a set. s' ∈ set (ss::'a set list) ⟹ (0::'a) ∈ s'›*) by simp show "?case" (*goal: ‹(map (λ_. 0) (s # ss))[k := y] ∈ listset (s # ss)›*) proof (cases k) (*goals: 1. ‹k = 0 ⟹ (map (λ_. 0) (s # ss))[k := y] ∈ listset (s # ss)› 2. ‹⋀nat. k = Suc nat ⟹ (map (λ_. 0) (s # ss))[k := y] ∈ listset (s # ss)›*) case k: 0 (*‹k = 0›*) with Cons.prems(3) (*‹(y::'a::comm_monoid_add) ∈ ((s::'a::comm_monoid_add set) # (ss::'a::comm_monoid_add set list)) ! (k::nat)›*) have "y ∈ s" by simp moreover from "*" (*‹?s' ∈ set ss ⟹ 0 ∈ ?s'›*) have "map (λ_. 0) ss ∈ listset ss" apply (induct ss) (*goals: 1. ‹(⋀s'. s' ∈ set [] ⟹ 0 ∈ s') ⟹ map (λ_. 0) [] ∈ listset []› 2. ‹⋀a ss. ⟦(⋀s'. s' ∈ set ss ⟹ 0 ∈ s') ⟹ map (λ_. 0) ss ∈ listset ss; ⋀s'. s' ∈ set (a # ss) ⟹ 0 ∈ s'⟧ ⟹ map (λ_. 0) (a # ss) ∈ listset (a # ss)› discuss goal 1*) apply ((auto simp del: listset.simps( (*‹listset (?A # ?As) = set_Cons ?A (listset ?As)›*) 2) intro: listset_ConsI (*‹⟦?y ∈ ?x; ?ys' ∈ listset ?xs; ?ys = ?y # ?ys'⟧ ⟹ ?ys ∈ listset (?x # ?xs)›*))[1]) (*discuss goal 2*) apply ((auto simp del: listset.simps( (*‹listset ((?A::?'a set) # (?As::?'a set list)) = set_Cons ?A (listset ?As)›*) 2) intro: listset_ConsI (*‹⟦(?y::?'a) ∈ (?x::?'a set); (?ys'::?'a list) ∈ listset (?xs::?'a set list); (?ys::?'a list) = ?y # ?ys'⟧ ⟹ ?ys ∈ listset (?x # ?xs)›*))[1]) (*proven 2 subgoals*) . moreover have "(map (λ_. 0) (s # ss))[k := y] = y # map (λ_. 0) ss" by (simp add: k (*‹k = 0›*)) ultimately show "?thesis" (*goal: ‹(map (λ_. 0) (s # ss))[k := y] ∈ listset (s # ss)›*) by (rule listset_ConsI (*‹⟦?y ∈ ?x; ?ys' ∈ listset ?xs; ?ys = ?y # ?ys'⟧ ⟹ ?ys ∈ listset (?x # ?xs)›*)) next (*goal: ‹⋀nat::nat. (k::nat) = Suc nat ⟹ (map (λ_::'a set. 0::'a) ((s::'a set) # (ss::'a set list)))[k := y::'a] ∈ listset (s # ss)›*) case k: (Suc k') (*‹k = Suc k'›*) have "0 ∈ s" apply (rule Cons.prems (*‹(?s::'a::comm_monoid_add set) ∈ set ((s::'a::comm_monoid_add set) # (ss::'a::comm_monoid_add set list)) ⟹ (0::'a::comm_monoid_add) ∈ ?s› ‹(k::nat) < length ((s::'a::comm_monoid_add set) # (ss::'a::comm_monoid_add set list))› ‹(y::'a::comm_monoid_add) ∈ ((s::'a::comm_monoid_add set) # (ss::'a::comm_monoid_add set list)) ! (k::nat)›*)) (*goal: ‹0 ∈ s›*) by simp moreover from "*" (*‹?s' ∈ set ss ⟹ 0 ∈ ?s'›*) have "(map (λ_. 0) ss)[k' := y] ∈ listset ss" proof (rule Cons.hyps (*‹⟦⋀s. s ∈ set ss ⟹ 0 ∈ s; ?k < length ss; y ∈ ss ! ?k⟧ ⟹ (map (λ_. 0) ss)[?k := y] ∈ listset ss›*)) (*goals: 1. ‹⋀s. s ∈ set ss ⟹ s ∈ set ss› 2. ‹k' < length ss› 3. ‹y ∈ ss ! k'›*) from Cons.prems(2) (*‹k < length (s # ss)›*) show "k' < length ss" by (simp add: k (*‹k = Suc k'›*)) next (*goals: 1. ‹⋀s::'a set. s ∈ set (ss::'a set list) ⟹ s ∈ set ss› 2. ‹(y::'a) ∈ (ss::'a set list) ! (k'::nat)›*) from Cons.prems(3) (*‹y ∈ (s # ss) ! k›*) show "y ∈ ss ! k'" by (simp add: k (*‹(k::nat) = Suc (k'::nat)›*)) qed moreover have "(map (λ_. 0) (s # ss))[k := y] = 0 # (map (λ_. 0) ss)[k' := y]" by (simp add: k (*‹k = Suc k'›*)) ultimately show "?thesis" (*goal: ‹(map (λ_. 0) (s # ss))[k := y] ∈ listset (s # ss)›*) by (rule listset_ConsI (*‹⟦?y ∈ ?x; ?ys' ∈ listset ?xs; ?ys = ?y # ?ys'⟧ ⟹ ?ys ∈ listset (?x # ?xs)›*)) qed qed have 2: "sum_list ((map (λ_. 0) ss)[k := y]) = y" if "k < length ss" for k and y :: 'a using that (*‹k < length ss›*) apply (induct ss arbitrary: k) (*goals: 1. ‹⋀k. k < length [] ⟹ sum_list ((map (λ_. 0) [])[k := y]) = y› 2. ‹⋀a ss k. ⟦⋀k. k < length ss ⟹ sum_list ((map (λ_. 0) ss)[k := y]) = y; k < length (a # ss)⟧ ⟹ sum_list ((map (λ_. 0) (a # ss))[k := y]) = y› discuss goal 1*) apply ((auto simp: add_ac (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)›*) split: nat.split (*‹?P (case ?nat of 0 ⇒ ?f1.0 | Suc x ⇒ ?f2.0 x) = ((?nat = 0 ⟶ ?P ?f1.0) ∧ (∀x2. ?nat = Suc x2 ⟶ ?P (?f2.0 x2)))›*))[1]) (*discuss goal 2*) apply ((auto simp: add_ac (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)›*) split: nat.split (*‹(?P::?'a ⇒ bool) (case ?nat::nat of 0::nat ⇒ ?f1.0::?'a | Suc (x::nat) ⇒ (?f2.0::nat ⇒ ?'a) x) = ((?nat = (0::nat) ⟶ ?P ?f1.0) ∧ (∀x2::nat. ?nat = Suc x2 ⟶ ?P (?f2.0 x2)))›*))[1]) (*proven 2 subgoals*) . define qs1 where "qs1 = (map (λ_. 0) ss)[i := x]" define qs2 where "qs2 = (map (λ_. 0) ss)[j := x]" note assms(1) (*‹direct_decomp A ss›*) moreover from ‹i < length ss› (*‹i < length ss›*) x_i (*‹(x::'a) ∈ (ss::'a set list) ! (i::nat)›*) have "qs1 ∈ listset ss" unfolding qs1_def (*goal: ‹(map (λ_. 0) ss)[i := x] ∈ listset ss›*) by (rule 1 (*‹⟦(?k::nat) < length (ss::'a set list); (?y::'a) ∈ ss ! ?k⟧ ⟹ (map (λ_::'a set. 0::'a) ss)[?k := ?y] ∈ listset ss›*)) moreover from assms(3) (*‹j < length ss›*) x_j (*‹x ∈ ss ! j›*) have "qs2 ∈ listset ss" unfolding qs2_def (*goal: ‹(map (λ_::'a set. 0::'a) (ss::'a set list))[j::nat := x::'a] ∈ listset ss›*) by (rule 1 (*‹⟦?k < length ss; ?y ∈ ss ! ?k⟧ ⟹ (map (λ_. 0) ss)[?k := ?y] ∈ listset ss›*)) thm sum_list_update moreover from ‹i < length ss› (*‹i < length ss›*) assms(3) (*‹j < length ss›*) have "sum_list qs1 = sum_list qs2" by (simp add: qs1_def (*‹qs1 = (map (λ_. 0) ss)[i := x]›*) qs2_def (*‹qs2 = (map (λ_. 0) ss)[j := x]›*) 2 (*‹?k < length ss ⟹ sum_list ((map (λ_. 0) ss)[?k := ?y]) = ?y›*)) ultimately have "qs1 = qs2" by (rule direct_decomp_unique (*‹⟦direct_decomp ?A ?ss; ?qs ∈ listset ?ss; ?qs' ∈ listset ?ss; sum_list ?qs = sum_list ?qs'⟧ ⟹ ?qs = ?qs'›*)) hence "qs1 ! i = qs2 ! i" by simp with ‹i < length ss› (*‹(i::nat) < length (ss::'a set list)›*) assms(2,3) (*‹i < j› ‹j < length ss›*) show "x ∈ {0}" by (simp add: qs1_def (*‹qs1 = (map (λ_. 0) ss)[i := x]›*) qs2_def (*‹qs2 = (map (λ_. 0) ss)[j := x]›*)) qed next (*goal: ‹{0} ⊆ ss ! i ∩ ss ! j›*) from i_in (*‹ss ! i ∈ set ss›*) have "0 ∈ ss ! i" by (rule assms( (*‹?s ∈ set ss ⟹ 0 ∈ ?s›*) 4)) moreover from j_in (*‹ss ! j ∈ set ss›*) have "0 ∈ ss ! j" by (rule assms( (*‹?s ∈ set ss ⟹ 0 ∈ ?s›*) 4)) ultimately show "{0} ⊆ ss ! i ∩ ss ! j" by simp qed qed corollary direct_decomp_pairwise_zero: assumes "direct_decomp A ss" and "⋀s. s ∈ set ss ⟹ 0 ∈ s" shows "pairwise (λs1 s2. s1 ∩ s2 = {0}) (set ss)" proof (rule pairwiseI (*‹(⋀x y. ⟦x ∈ ?S; y ∈ ?S; x ≠ y⟧ ⟹ ?R x y) ⟹ pairwise ?R ?S›*)) (*goal: ‹⋀(x::'a::comm_monoid_add set) y::'a::comm_monoid_add set. ⟦x ∈ set (ss::'a::comm_monoid_add set list); y ∈ set ss; x ≠ y⟧ ⟹ x ∩ y = {0::'a::comm_monoid_add}›*) fix s1 and s2 assume "s1 ∈ set ss" (*‹(s1::'a set) ∈ set (ss::'a set list)›*) then obtain i where "i < length ss" and s1: "s1 = ss ! i" (*goal: ‹(⋀i. ⟦i < length ss; s1 = ss ! i⟧ ⟹ thesis) ⟹ thesis›*) by (metis in_set_conv_nth (*‹(?x ∈ set ?xs) = (∃i<length ?xs. ?xs ! i = ?x)›*)) assume "s2 ∈ set ss" (*‹(s2::'a set) ∈ set (ss::'a set list)›*) then obtain j where "j < length ss" and s2: "s2 = ss ! j" (*goal: ‹(⋀j::nat. ⟦j < length (ss::'a::comm_monoid_add set list); (s2::'a::comm_monoid_add set) = ss ! j⟧ ⟹ thesis::bool) ⟹ thesis›*) by (metis in_set_conv_nth (*‹((?x::?'a::type) ∈ set (?xs::?'a::type list)) = (∃i<length ?xs. ?xs ! i = ?x)›*)) assume "s1 ≠ s2" (*‹(s1::'a set) ≠ (s2::'a set)›*) hence "i < j ∨ j < i" by (auto simp: s1 (*‹s1 = ss ! i›*) s2 (*‹s2 = ss ! j›*)) thus "s1 ∩ s2 = {0}" proof (standard) (*goals: 1. ‹(i::nat) < (j::nat) ⟹ (s1::'a set) ∩ (s2::'a set) = {0::'a}› 2. ‹(j::nat) < (i::nat) ⟹ (s1::'a set) ∩ (s2::'a set) = {0::'a}›*) assume "i < j" (*‹(i::nat) < (j::nat)›*) with assms(1) (*‹direct_decomp A ss›*) show "?thesis" (*goal: ‹s1 ∩ s2 = {0}›*) unfolding s1 s2 (*goal: ‹ss ! i ∩ ss ! j = {0}›*) using ‹j < length ss› (*‹j < length ss›*) assms(2) (*‹?s ∈ set ss ⟹ 0 ∈ ?s›*) by (rule direct_decomp_Int_zero (*‹⟦direct_decomp ?A ?ss; ?i < ?j; ?j < length ?ss; ⋀s. s ∈ set ?ss ⟹ 0 ∈ s⟧ ⟹ ?ss ! ?i ∩ ?ss ! ?j = {0}›*)) next (*goal: ‹j < i ⟹ s1 ∩ s2 = {0}›*) assume "j < i" (*‹(j::nat) < (i::nat)›*) with assms(1) (*‹direct_decomp A ss›*) have "s2 ∩ s1 = {0}" unfolding s1 s2 (*goal: ‹ss ! j ∩ ss ! i = {0}›*) using ‹i < length ss› (*‹i < length ss›*) assms(2) (*‹?s ∈ set ss ⟹ 0 ∈ ?s›*) by (rule direct_decomp_Int_zero (*‹⟦direct_decomp ?A ?ss; ?i < ?j; ?j < length ?ss; ⋀s. s ∈ set ?ss ⟹ 0 ∈ s⟧ ⟹ ?ss ! ?i ∩ ?ss ! ?j = {0}›*)) thus "?thesis" (*goal: ‹s1 ∩ s2 = {0}›*) by (simp only: Int_commute (*‹?A ∩ ?B = ?B ∩ ?A›*)) qed qed corollary direct_decomp_repeated_eq_zero: assumes "direct_decomp A ss" and "1 < count_list ss X" and "⋀s. s ∈ set ss ⟹ 0 ∈ s" shows "X = {0}" proof (-) (*goal: ‹X = {0}›*) from assms(2) (*‹1 < count_list ss X›*) obtain i and j where "i < j" and "j < length ss" and 1: "ss ! i = X" and 2: "ss ! j = X" (*goal: ‹(⋀i j. ⟦i < j; j < length ss; ss ! i = X; ss ! j = X⟧ ⟹ thesis) ⟹ thesis›*) by (rule count_list_gr_1_E (*‹⟦1 < count_list ?xs ?x; ⋀i j. ⟦i < j; j < length ?xs; ?xs ! i = ?x; ?xs ! j = ?x⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) from assms(1) (*‹direct_decomp A ss›*) this(1,2) (*‹i < j› ‹j < length ss›*) assms(3) (*‹?s ∈ set ss ⟹ 0 ∈ ?s›*) have "ss ! i ∩ ss ! j = {0}" by (rule direct_decomp_Int_zero (*‹⟦direct_decomp ?A ?ss; ?i < ?j; ?j < length ?ss; ⋀s. s ∈ set ?ss ⟹ 0 ∈ s⟧ ⟹ ?ss ! ?i ∩ ?ss ! ?j = {0}›*)) thus "?thesis" (*goal: ‹X = {0}›*) by (simp add: 1 (*‹ss ! i = X›*) 2 (*‹ss ! j = X›*)) qed corollary direct_decomp_map_Int_zero: assumes "direct_decomp A (map f ss)" and "s1 ∈ set ss" and "s2 ∈ set ss" and "s1 ≠ s2" and "⋀s. s ∈ set ss ⟹ 0 ∈ f s" shows "f s1 ∩ f s2 = {0}" proof (-) (*goal: ‹f s1 ∩ f s2 = {0}›*) from assms(2) (*‹s1 ∈ set ss›*) obtain i where "i < length ss" and s1: "s1 = ss ! i" (*goal: ‹(⋀i. ⟦i < length ss; s1 = ss ! i⟧ ⟹ thesis) ⟹ thesis›*) by (metis in_set_conv_nth (*‹((?x::?'a) ∈ set (?xs::?'a list)) = (∃i<length ?xs. ?xs ! i = ?x)›*)) from this(1) (*‹i < length ss›*) have i: "i < length (map f ss)" by simp from assms(3) (*‹s2 ∈ set ss›*) obtain j where "j < length ss" and s2: "s2 = ss ! j" (*goal: ‹(⋀j. ⟦j < length ss; s2 = ss ! j⟧ ⟹ thesis) ⟹ thesis›*) by (metis in_set_conv_nth (*‹(?x ∈ set ?xs) = (∃i<length ?xs. ?xs ! i = ?x)›*)) from this(1) (*‹j < length ss›*) have j: "j < length (map f ss)" by simp have "*": "0 ∈ s" if "s ∈ set (map f ss)" for s proof (-) (*goal: ‹0 ∈ s›*) from that (*‹s ∈ set (map f ss)›*) obtain s' where "s' ∈ set ss" and s: "s = f s'" (*goal: ‹(⋀s'. ⟦s' ∈ set ss; s = f s'⟧ ⟹ thesis) ⟹ thesis›*) unfolding set_map (*goal: ‹(⋀s'. ⟦s' ∈ set ss; s = f s'⟧ ⟹ thesis) ⟹ thesis›*) by standard from this(1) (*‹s' ∈ set ss›*) show "0 ∈ s" unfolding s (*goal: ‹0 ∈ f s'›*) by (rule assms( (*‹(?s::'b::type) ∈ set (ss::'b::type list) ⟹ (0::'a::comm_monoid_add) ∈ (f::'b::type ⇒ 'a::comm_monoid_add set) ?s›*) 5)) qed show "?thesis" (*goal: ‹(f::'b::type ⇒ 'a::comm_monoid_add set) (s1::'b::type) ∩ f (s2::'b::type) = {0::'a::comm_monoid_add}›*) proof (rule linorder_cases (*‹⟦?x < ?y ⟹ ?P; ?x = ?y ⟹ ?P; ?y < ?x ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹?x < ?y ⟹ f s1 ∩ f s2 = {0}› 2. ‹?x = ?y ⟹ f s1 ∩ f s2 = {0}› 3. ‹?y < ?x ⟹ f s1 ∩ f s2 = {0}›*) assume "i < j" (*‹(i::nat) < (j::nat)›*) with assms(1) (*‹direct_decomp A (map f ss)›*) have "(map f ss) ! i ∩ (map f ss) ! j = {0}" using j (*‹j < length (map f ss)›*) "*" (*‹?s ∈ set (map f ss) ⟹ 0 ∈ ?s›*) by (rule direct_decomp_Int_zero (*‹⟦direct_decomp (?A::?'a set) (?ss::?'a set list); (?i::nat) < (?j::nat); ?j < length ?ss; ⋀s::?'a set. s ∈ set ?ss ⟹ (0::?'a) ∈ s⟧ ⟹ ?ss ! ?i ∩ ?ss ! ?j = {0::?'a}›*)) with i (*‹i < length (map f ss)›*) j (*‹j < length (map f ss)›*) show "?thesis" (*goal: ‹f s1 ∩ f s2 = {0}›*) by (simp add: s1 (*‹(s1::'b) = (ss::'b list) ! (i::nat)›*) s2 (*‹(s2::'b) = (ss::'b list) ! (j::nat)›*)) next (*goals: 1. ‹i = j ⟹ f s1 ∩ f s2 = {0}› 2. ‹j < i ⟹ f s1 ∩ f s2 = {0}›*) assume "j < i" (*‹(j::nat) < (i::nat)›*) with assms(1) (*‹direct_decomp A (map f ss)›*) have "(map f ss) ! j ∩ (map f ss) ! i = {0}" using i (*‹i < length (map f ss)›*) "*" (*‹?s ∈ set (map f ss) ⟹ 0 ∈ ?s›*) by (rule direct_decomp_Int_zero (*‹⟦direct_decomp ?A ?ss; ?i < ?j; ?j < length ?ss; ⋀s. s ∈ set ?ss ⟹ 0 ∈ s⟧ ⟹ ?ss ! ?i ∩ ?ss ! ?j = {0}›*)) with i (*‹i < length (map f ss)›*) j (*‹j < length (map f ss)›*) show "?thesis" (*goal: ‹f s1 ∩ f s2 = {0}›*) by (simp add: s1 (*‹s1 = ss ! i›*) s2 (*‹s2 = ss ! j›*) Int_commute (*‹?A ∩ ?B = ?B ∩ ?A›*)) next (*goal: ‹i = j ⟹ f s1 ∩ f s2 = {0}›*) assume "i = j" (*‹(i::nat) = (j::nat)›*) with assms(4) (*‹s1 ≠ s2›*) show "?thesis" (*goal: ‹f s1 ∩ f s2 = {0}›*) by (simp add: s1 (*‹s1 = ss ! i›*) s2 (*‹s2 = ss ! j›*)) qed qed subsection ‹Direct Decompositions and Vector Spaces› definition (in vector_space) is_basis :: "'b set ⇒ 'b set ⇒ bool" where "is_basis V B ⟷ (B ⊆ V ∧ independent B ∧ V ⊆ span B ∧ card B = dim V)" definition (in vector_space) some_basis :: "'b set ⇒ 'b set" where "some_basis V = Eps (local.is_basis V)" hide_const (open) real_vector.is_basis real_vector.some_basis context vector_space begin lemma dim_empty [simp]: "dim {} = 0" using dim_span_eq_card_independent (*‹local.independent ?B ⟹ local.dim (local.span ?B) = card ?B›*) independent_empty (*‹local.independent {}›*) by fastforce lemma dim_zero [simp]: "dim {0} = 0" using dim_span_eq_card_independent (*‹local.independent ?B ⟹ local.dim (local.span ?B) = card ?B›*) independent_empty (*‹local.independent {}›*) by fastforce lemma independent_UnI: assumes "independent A" and "independent B" and "span A ∩ span B = {0}" shows "independent (A ∪ B)" proof (standard) (*goal: ‹local.dependent (A ∪ B) ⟹ False›*) from span_superset (*‹?S ⊆ local.span ?S›*) have "A ∩ B ⊆ span A ∩ span B" by blast hence "A ∩ B = {}" unfolding assms(3) (*goal: ‹A ∩ B = {}›*) using assms(1,2) (*‹local.independent A› ‹local.independent B›*) dependent_zero (*‹0 ∈ ?A ⟹ local.dependent ?A›*) by blast assume "dependent (A ∪ B)" (*‹local.dependent ((A::'b set) ∪ (B::'b set))›*) then obtain T and u and v where "finite T" and "T ⊆ A ∪ B" and eq: "(∑v∈T. u v *s v) = 0" and "v ∈ T" and "u v ≠ 0" (*goal: ‹(⋀T u v. ⟦finite T; T ⊆ A ∪ B; (∑v∈T. u v *s v) = 0; v ∈ T; u v ≠ 0⟧ ⟹ thesis) ⟹ thesis›*) unfolding dependent_explicit (*goal: ‹(⋀T u v. ⟦finite T; T ⊆ A ∪ B; (∑v∈T. u v *s v) = 0; v ∈ T; u v ≠ 0⟧ ⟹ thesis) ⟹ thesis›*) by blast define TA where "TA = T ∩ A" define TB where "TB = T ∩ B" from ‹T ⊆ A ∪ B› (*‹(T::'b set) ⊆ (A::'b set) ∪ (B::'b set)›*) have T: "T = TA ∪ TB" by (auto simp: TA_def (*‹TA = T ∩ A›*) TB_def (*‹TB = T ∩ B›*)) from ‹finite T› (*‹finite T›*) have "finite TA" and "TA ⊆ A" apply - (*goals: 1. ‹finite T ⟹ finite TA› 2. ‹finite T ⟹ TA ⊆ A› discuss goal 1*) apply (simp add: TA_def (*‹TA = T ∩ A›*)) (*discuss goal 2*) apply (simp add: TA_def (*‹TA = T ∩ A›*)) (*proven 2 subgoals*) . from ‹finite T› (*‹finite (T::'b set)›*) have "finite TB" and "TB ⊆ B" apply - (*goals: 1. ‹finite T ⟹ finite TB› 2. ‹finite T ⟹ TB ⊆ B› discuss goal 1*) apply (simp add: TB_def (*‹TB = T ∩ B›*)) (*discuss goal 2*) apply (simp add: TB_def (*‹(TB::'b set) = (T::'b set) ∩ (B::'b set)›*)) (*proven 2 subgoals*) . from ‹A ∩ B = {}› (*‹(A::'b set) ∩ (B::'b set) = {}›*) ‹TA ⊆ A› (*‹TA ⊆ A›*) this(2) (*‹TB ⊆ B›*) have "TA ∩ TB = {}" by blast have "0 = (∑v∈TA ∪ TB. u v *s v)" by (simp only: eq (*‹(∑v∈T. u v *s v) = 0›*) flip: T (*‹T = TA ∪ TB›*)) also (*calculation: ‹0 = (∑v∈TA ∪ TB. u v *s v)›*) have "… = (∑v∈TA. u v *s v) + (∑v∈TB. u v *s v)" apply (rule sum.union_disjoint (*‹⟦finite ?A; finite ?B; ?A ∩ ?B = {}⟧ ⟹ sum ?g (?A ∪ ?B) = sum ?g ?A + sum ?g ?B›*)) (*goals: 1. ‹finite TA› 2. ‹finite TB› 3. ‹TA ∩ TB = {}› discuss goal 1*) apply fact (*discuss goal 2*) apply fact (*discuss goal 3*) apply fact (*proven 3 subgoals*) . finally (*calculation: ‹0 = (∑v∈TA. u v *s v) + (∑v∈TB. u v *s v)›*) have "(∑v∈TA. u v *s v) = (∑v∈TB. (- u) v *s v)" (is "?x = ?y") by (simp add: sum_negf (*‹(∑x∈?A. - ?f x) = - sum ?f ?A›*) eq_neg_iff_add_eq_0 (*‹(?a = - ?b) = (?a + ?b = 0)›*)) from ‹finite TB› (*‹finite TB›*) ‹TB ⊆ B› (*‹TB ⊆ B›*) have "?y ∈ span B" by (auto simp: span_explicit (*‹local.span ?b = {∑a∈t. r a *s a |t r. finite t ∧ t ⊆ ?b}›*) simp del: uminus_apply (*‹(- ?A) ?x = - ?A ?x›*)) moreover from ‹finite TA› (*‹finite TA›*) ‹TA ⊆ A› (*‹TA ⊆ A›*) have "?x ∈ span A" by (auto simp: span_explicit (*‹local.span ?b = {∑a∈t. r a *s a |t r. finite t ∧ t ⊆ ?b}›*)) ultimately have "?y ∈ span A ∩ span B" by (simp add: ‹?x = ?y›) hence "?x = 0" and "?y = 0" apply - (*goals: 1. ‹(∑v∈TB. (- u) v *s v) ∈ local.span A ∩ local.span B ⟹ (∑v∈TA. u v *s v) = 0› 2. ‹(∑v∈TB. (- u) v *s v) ∈ local.span A ∩ local.span B ⟹ (∑v∈TB. (- u) v *s v) = 0› discuss goal 1*) apply (simp add: ‹?x = ?y› assms( (*‹local.span A ∩ local.span B = {0}›*) 3)) (*discuss goal 2*) apply (simp add: ‹?x = ?y› assms( (*‹local.span A ∩ local.span B = {0}›*) 3)) (*proven 2 subgoals*) . from ‹v ∈ T› (*‹v ∈ T›*) have "v ∈ TA ∪ TB" by (simp only: T (*‹T = TA ∪ TB›*)) hence "u v = 0" proof (standard) (*goals: 1. ‹v ∈ TA ⟹ u v = 0› 2. ‹v ∈ TB ⟹ u v = 0›*) assume "v ∈ TA" (*‹(v::'b) ∈ (TA::'b set)›*) with assms(1) (*‹local.independent (A::'b::ab_group_add set)›*) ‹finite TA› (*‹finite TA›*) ‹TA ⊆ A› (*‹(TA::'b set) ⊆ (A::'b set)›*) ‹?x = 0› (*‹(∑v∈TA. u v *s v) = 0›*) show "u v = 0" by (rule independentD (*‹⟦local.independent ?s; finite ?t; ?t ⊆ ?s; (∑v∈?t. ?u v *s v) = 0; ?v ∈ ?t⟧ ⟹ ?u ?v = 0›*)) next (*goal: ‹(v::'b) ∈ (TB::'b set) ⟹ (u::'b ⇒ 'a) v = (0::'a)›*) assume "v ∈ TB" (*‹(v::'b) ∈ (TB::'b set)›*) with assms(2) (*‹local.independent (B::'b set)›*) ‹finite TB› (*‹finite TB›*) ‹TB ⊆ B› (*‹(TB::'b set) ⊆ (B::'b set)›*) ‹?y = 0› (*‹(∑v∈TB. (- u) v *s v) = 0›*) have "(- u) v = 0" by (rule independentD (*‹⟦local.independent ?s; finite ?t; ?t ⊆ ?s; (∑v∈?t. ?u v *s v) = 0; ?v ∈ ?t⟧ ⟹ ?u ?v = 0›*)) thus "u v = 0" by simp qed with ‹u v ≠ 0› (*‹u v ≠ 0›*) show False by standard qed lemma subspace_direct_decomp: assumes "direct_decomp A ss" and "⋀s. s ∈ set ss ⟹ subspace s" shows "subspace A" proof (rule subspaceI (*‹⟦(0::'b) ∈ (?S::'b set); ⋀(x::'b) y::'b. ⟦x ∈ ?S; y ∈ ?S⟧ ⟹ x + y ∈ ?S; ⋀(c::'a) x::'b. x ∈ ?S ⟹ c *s x ∈ ?S⟧ ⟹ local.subspace ?S›*)) (*goals: 1. ‹0 ∈ A› 2. ‹⋀x y. ⟦x ∈ A; y ∈ A⟧ ⟹ x + y ∈ A› 3. ‹⋀c x. x ∈ A ⟹ c *s x ∈ A›*) let ?qs = "map (λ_. 0) ss" from assms(2) (*‹(?s::'b set) ∈ set (ss::'b set list) ⟹ local.subspace ?s›*) have "?qs ∈ listset ss" apply (induct ss) (*goals: 1. ‹(⋀s. s ∈ set [] ⟹ local.subspace s) ⟹ map (λ_. 0) [] ∈ listset []› 2. ‹⋀a ss. ⟦(⋀s. s ∈ set ss ⟹ local.subspace s) ⟹ map (λ_. 0) ss ∈ listset ss; ⋀s. s ∈ set (a # ss) ⟹ local.subspace s⟧ ⟹ map (λ_. 0) (a # ss) ∈ listset (a # ss)› discuss goal 1*) apply ((auto simp del: listset.simps( (*‹listset (?A # ?As) = set_Cons ?A (listset ?As)›*) 2) dest: subspace_0 (*‹local.subspace ?S ⟹ 0 ∈ ?S›*) intro: listset_ConsI (*‹⟦?y ∈ ?x; ?ys' ∈ listset ?xs; ?ys = ?y # ?ys'⟧ ⟹ ?ys ∈ listset (?x # ?xs)›*))[1]) (*discuss goal 2*) apply ((auto simp del: listset.simps( (*‹listset (?A # ?As) = set_Cons ?A (listset ?As)›*) 2) dest: subspace_0 (*‹local.subspace ?S ⟹ 0 ∈ ?S›*) intro: listset_ConsI (*‹⟦?y ∈ ?x; ?ys' ∈ listset ?xs; ?ys = ?y # ?ys'⟧ ⟹ ?ys ∈ listset (?x # ?xs)›*))[1]) (*proven 2 subgoals*) . with assms(1) (*‹direct_decomp A ss›*) have "sum_list ?qs ∈ A" by (rule direct_decompD (*‹⟦direct_decomp (?A::?'a::comm_monoid_add set) (?ss::?'a::comm_monoid_add set list); (?qs::?'a::comm_monoid_add list) ∈ listset ?ss⟧ ⟹ sum_list ?qs ∈ ?A› ‹direct_decomp (?A::?'a::comm_monoid_add set) (?ss::?'a::comm_monoid_add set list) ⟹ inj_on sum_list (listset ?ss)› ‹direct_decomp (?A::?'a::comm_monoid_add set) (?ss::?'a::comm_monoid_add set list) ⟹ sum_list ` listset ?ss = ?A›*)) thus "0 ∈ A" by simp next (*goals: 1. ‹⋀x y. ⟦x ∈ A; y ∈ A⟧ ⟹ x + y ∈ A› 2. ‹⋀c x. x ∈ A ⟹ c *s x ∈ A›*) fix p and q assume "p ∈ A" (*‹(p::'b) ∈ (A::'b set)›*) with assms(1) (*‹direct_decomp A ss›*) obtain ps where ps: "ps ∈ listset ss" and p: "p = sum_list ps" (*goal: ‹(⋀ps. ⟦ps ∈ listset ss; p = sum_list ps⟧ ⟹ thesis) ⟹ thesis›*) by (rule direct_decompE (*‹⟦direct_decomp (?A::?'a::comm_monoid_add set) (?ss::?'a::comm_monoid_add set list); (?a::?'a::comm_monoid_add) ∈ ?A; ⋀qs::?'a::comm_monoid_add list. ⟦qs ∈ listset ?ss; ?a = sum_list qs⟧ ⟹ ?thesis::bool⟧ ⟹ ?thesis›*)) assume "q ∈ A" (*‹(q::'b) ∈ (A::'b set)›*) with assms(1) (*‹direct_decomp A ss›*) obtain qs where qs: "qs ∈ listset ss" and q: "q = sum_list qs" (*goal: ‹(⋀qs. ⟦qs ∈ listset ss; q = sum_list qs⟧ ⟹ thesis) ⟹ thesis›*) by (rule direct_decompE (*‹⟦direct_decomp ?A ?ss; ?a ∈ ?A; ⋀qs. ⟦qs ∈ listset ?ss; ?a = sum_list qs⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) from ps (*‹ps ∈ listset ss›*) qs (*‹qs ∈ listset ss›*) have l: "length ps = length qs" by (simp only: listsetD (*‹?ys ∈ listset ?xs ⟹ length ?ys = length ?xs› ‹⟦?ys ∈ listset ?xs; ?i < length ?xs⟧ ⟹ ?ys ! ?i ∈ ?xs ! ?i›*)) from ps (*‹ps ∈ listset ss›*) qs (*‹(qs::'b::ab_group_add list) ∈ listset (ss::'b::ab_group_add set list)›*) have "map2 (+) ps qs ∈ listset ss" (is "?qs ∈ _") apply (rule listset_closed_map2 (*‹⟦(?ys1.0::?'a list) ∈ listset (?xs::?'a set list); (?ys2.0::?'a list) ∈ listset ?xs; ⋀(x::?'a set) (y1::?'a) y2::?'a. ⟦x ∈ set ?xs; y1 ∈ x; y2 ∈ x⟧ ⟹ (?f::?'a ⇒ ?'a ⇒ ?'a) y1 y2 ∈ x⟧ ⟹ map2 ?f ?ys1.0 ?ys2.0 ∈ listset ?xs›*)) (*goal: ‹map2 (+) ps qs ∈ listset ss›*) by (auto dest: assms( (*‹?s ∈ set ss ⟹ local.subspace ?s›*) 2) subspace_add (*‹⟦local.subspace ?S; ?x ∈ ?S; ?y ∈ ?S⟧ ⟹ ?x + ?y ∈ ?S›*)) with assms(1) (*‹direct_decomp A ss›*) have "sum_list ?qs ∈ A" by (rule direct_decompD (*‹⟦direct_decomp ?A ?ss; ?qs ∈ listset ?ss⟧ ⟹ sum_list ?qs ∈ ?A› ‹direct_decomp ?A ?ss ⟹ inj_on sum_list (listset ?ss)› ‹direct_decomp ?A ?ss ⟹ sum_list ` listset ?ss = ?A›*)) thus "p + q ∈ A" using l (*‹length ps = length qs›*) by (simp only: p (*‹(p::'b) = sum_list (ps::'b list)›*) q (*‹(q::'b) = sum_list (qs::'b list)›*) sum_list_map2_plus (*‹length (?xs::?'a list) = length (?ys::?'a list) ⟹ sum_list (map2 (+) ?xs ?ys) = sum_list ?xs + sum_list ?ys›*)) next (*goal: ‹⋀c x. x ∈ A ⟹ c *s x ∈ A›*) fix c and p assume "p ∈ A" (*‹(p::'b) ∈ (A::'b set)›*) with assms(1) (*‹direct_decomp A ss›*) obtain ps where "ps ∈ listset ss" and p: "p = sum_list ps" (*goal: ‹(⋀ps. ⟦ps ∈ listset ss; p = sum_list ps⟧ ⟹ thesis) ⟹ thesis›*) by (rule direct_decompE (*‹⟦direct_decomp ?A ?ss; ?a ∈ ?A; ⋀qs. ⟦qs ∈ listset ?ss; ?a = sum_list qs⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) from this(1) (*‹ps ∈ listset ss›*) have "map ((*s) c) ps ∈ listset ss" (is "?qs ∈ _") apply (rule listset_closed_map (*‹⟦?ys ∈ listset ?xs; ⋀x y. ⟦x ∈ set ?xs; y ∈ x⟧ ⟹ ?f y ∈ x⟧ ⟹ map ?f ?ys ∈ listset ?xs›*)) (*goal: ‹map ((*s) (c::'a::field)) (ps::'b::ab_group_add list) ∈ listset (ss::'b::ab_group_add set list)›*) by (auto dest: assms( (*‹?s ∈ set ss ⟹ local.subspace ?s›*) 2) subspace_scale (*‹⟦local.subspace ?S; ?x ∈ ?S⟧ ⟹ ?c *s ?x ∈ ?S›*)) with assms(1) (*‹direct_decomp A ss›*) have "sum_list ?qs ∈ A" by (rule direct_decompD (*‹⟦direct_decomp ?A ?ss; ?qs ∈ listset ?ss⟧ ⟹ sum_list ?qs ∈ ?A› ‹direct_decomp ?A ?ss ⟹ inj_on sum_list (listset ?ss)› ‹direct_decomp ?A ?ss ⟹ sum_list ` listset ?ss = ?A›*)) also (*calculation: ‹sum_list (map ((*s) (c::'a::field)) (ps::'b::ab_group_add list)) ∈ (A::'b::ab_group_add set)›*) have "sum_list ?qs = c *s sum_list ps" apply (induct ps) (*goals: 1. ‹sum_list (map ((*s) c) []) = c *s sum_list []› 2. ‹⋀a ps. sum_list (map ((*s) c) ps) = c *s sum_list ps ⟹ sum_list (map ((*s) c) (a # ps)) = c *s sum_list (a # ps)› discuss goal 1*) apply (simp add: scale_right_distrib (*‹?a *s (?x + ?y) = ?a *s ?x + ?a *s ?y›*)) (*discuss goal 2*) apply (simp add: scale_right_distrib (*‹?a *s (?x + ?y) = ?a *s ?x + ?a *s ?y›*)) (*proven 2 subgoals*) . finally (*calculation: ‹c *s sum_list ps ∈ A›*) show "c *s p ∈ A" by (simp only: p (*‹p = sum_list ps›*)) qed lemma is_basis_alt: "subspace V ⟹ is_basis V B ⟷ (independent B ∧ span B = V)" by (metis (full_types) is_basis_def (*‹is_basis (?V::'b set) (?B::'b set) = (?B ⊆ ?V ∧ local.independent ?B ∧ ?V ⊆ local.span ?B ∧ card ?B = local.dim ?V)›*) dim_eq_card (*‹⟦local.span (?B::'b set) = local.span (?V::'b set); local.independent ?B⟧ ⟹ local.dim ?V = card ?B›*) span_eq (*‹(local.span (?S::'b set) = local.span (?T::'b set)) = (?S ⊆ local.span ?T ∧ ?T ⊆ local.span ?S)›*) span_eq_iff (*‹(local.span (?s::'b set) = ?s) = local.subspace ?s›*)) lemma is_basis_finite: "is_basis V A ⟹ is_basis V B ⟹ finite A ⟷ finite B" unfolding is_basis_def (*goal: ‹⟦A ⊆ V ∧ local.independent A ∧ V ⊆ local.span A ∧ card A = local.dim V; B ⊆ V ∧ local.independent B ∧ V ⊆ local.span B ∧ card B = local.dim V⟧ ⟹ finite A = finite B›*) using independent_span_bound (*‹⟦finite (?T::'b::ab_group_add set); local.independent (?S::'b::ab_group_add set); ?S ⊆ local.span ?T⟧ ⟹ finite ?S ∧ card ?S ≤ card ?T›*) by auto lemma some_basis_is_basis: "is_basis V (some_basis V)" proof (-) (*goal: ‹is_basis (V::'b set) (some_basis V)›*) obtain B where "B ⊆ V" and "independent B" and "V ⊆ span B" and "card B = dim V" (*goal: ‹(⋀B. ⟦B ⊆ V; local.independent B; V ⊆ local.span B; card B = local.dim V⟧ ⟹ thesis) ⟹ thesis›*) by (rule basis_exists (*‹(⋀B. ⟦B ⊆ ?V; local.independent B; ?V ⊆ local.span B; card B = local.dim ?V⟧ ⟹ ?thesis) ⟹ ?thesis›*)) hence "is_basis V B" by (simp add: is_basis_def (*‹is_basis ?V ?B = (?B ⊆ ?V ∧ local.independent ?B ∧ ?V ⊆ local.span ?B ∧ card ?B = local.dim ?V)›*)) thus "?thesis" (*goal: ‹is_basis V (some_basis V)›*) unfolding some_basis_def (*goal: ‹is_basis V (Eps (is_basis V))›*) by (rule someI (*‹?P ?x ⟹ ?P (Eps ?P)›*)) qed corollary shows some_basis_subset: "some_basis V ⊆ V" and independent_some_basis: "independent (some_basis V)" and span_some_basis_supset: "V ⊆ span (some_basis V)" and card_some_basis: "card (some_basis V) = dim V" using some_basis_is_basis[of V] (*‹is_basis V (some_basis V)›*) apply - (*goals: 1. ‹is_basis (V::'b::ab_group_add set) (some_basis V) ⟹ some_basis V ⊆ V› 2. ‹is_basis (V::'b::ab_group_add set) (some_basis V) ⟹ local.independent (some_basis V)› 3. ‹is_basis (V::'b::ab_group_add set) (some_basis V) ⟹ V ⊆ local.span (some_basis V)› 4. ‹is_basis (V::'b::ab_group_add set) (some_basis V) ⟹ card (some_basis V) = local.dim V› discuss goal 1*) apply (simp add: is_basis_def (*‹is_basis ?V ?B = (?B ⊆ ?V ∧ local.independent ?B ∧ ?V ⊆ local.span ?B ∧ card ?B = local.dim ?V)›*)) (*discuss goal 2*) apply (simp add: is_basis_def (*‹is_basis ?V ?B = (?B ⊆ ?V ∧ local.independent ?B ∧ ?V ⊆ local.span ?B ∧ card ?B = local.dim ?V)›*)) (*discuss goal 3*) apply (simp add: is_basis_def (*‹is_basis ?V ?B = (?B ⊆ ?V ∧ local.independent ?B ∧ ?V ⊆ local.span ?B ∧ card ?B = local.dim ?V)›*)) (*discuss goal 4*) apply (simp add: is_basis_def (*‹is_basis ?V ?B = (?B ⊆ ?V ∧ local.independent ?B ∧ ?V ⊆ local.span ?B ∧ card ?B = local.dim ?V)›*)) (*proven 4 subgoals*) . lemma some_basis_not_zero: "0 ∉ some_basis V" using independent_some_basis (*‹local.independent (some_basis ?V)›*) dependent_zero (*‹0 ∈ ?A ⟹ local.dependent ?A›*) by blast lemma span_some_basis: "subspace V ⟹ span (some_basis V) = V" by (simp add: span_subspace (*‹⟦?A ⊆ ?B; ?B ⊆ local.span ?A; local.subspace ?B⟧ ⟹ local.span ?A = ?B›*) some_basis_subset (*‹some_basis ?V ⊆ ?V›*) span_some_basis_supset (*‹?V ⊆ local.span (some_basis ?V)›*)) lemma direct_decomp_some_basis_pairwise_disjnt: assumes "direct_decomp A ss" and "⋀s. s ∈ set ss ⟹ subspace s" shows "pairwise (λs1 s2. disjnt (some_basis s1) (some_basis s2)) (set ss)" proof (rule pairwiseI (*‹(⋀(x::?'a) y::?'a. ⟦x ∈ (?S::?'a set); y ∈ ?S; x ≠ y⟧ ⟹ (?R::?'a ⇒ ?'a ⇒ bool) x y) ⟹ pairwise ?R ?S›*)) (*goal: ‹⋀(x::'b set) y::'b set. ⟦x ∈ set (ss::'b set list); y ∈ set ss; x ≠ y⟧ ⟹ disjnt (some_basis x) (some_basis y)›*) fix s1 and s2 assume "s1 ∈ set ss" and "s2 ∈ set ss" and "s1 ≠ s2" (*‹(s1::'b set) ∈ set (ss::'b set list)› ‹(s2::'b set) ∈ set (ss::'b set list)› ‹(s1::'b set) ≠ (s2::'b set)›*) have "some_basis s1 ∩ some_basis s2 ⊆ s1 ∩ s2" using some_basis_subset (*‹some_basis ?V ⊆ ?V›*) by blast also (*calculation: ‹some_basis s1 ∩ some_basis s2 ⊆ s1 ∩ s2›*) from direct_decomp_pairwise_zero (*‹⟦direct_decomp ?A ?ss; ⋀s. s ∈ set ?ss ⟹ 0 ∈ s⟧ ⟹ pairwise (λs1 s2. s1 ∩ s2 = {0}) (set ?ss)›*) have "… = {0}" proof (rule pairwiseD (*‹⟦pairwise (?R::?'a ⇒ ?'a ⇒ bool) (?S::?'a set); (?x::?'a) ∈ ?S; (?y::?'a) ∈ ?S; ?x ≠ ?y⟧ ⟹ ?R ?x ?y›*)) (*goals: 1. ‹direct_decomp ?A1 ?ss1› 2. ‹⋀s. s ∈ set ?ss1 ⟹ 0 ∈ s› 3. ‹s1 ∈ set ?ss1› 4. ‹s2 ∈ set ?ss1› 5. ‹s1 ≠ s2›*) fix s assume "s ∈ set ss" (*‹(s::'b set) ∈ set (ss::'b set list)›*) hence "subspace s" by (rule assms( (*‹?s ∈ set ss ⟹ local.subspace ?s›*) 2)) thus "0 ∈ s" by (rule subspace_0 (*‹local.subspace ?S ⟹ 0 ∈ ?S›*)) qed ((fact)+) (*solves the remaining goals: 1. ‹direct_decomp ?A1 ss› 2. ‹s1 ∈ set ss› 3. ‹s2 ∈ set ss› 4. ‹s1 ≠ s2›*) finally (*calculation: ‹some_basis s1 ∩ some_basis s2 ⊆ {0}›*) have "some_basis s1 ∩ some_basis s2 ⊆ {0}" . with some_basis_not_zero (*‹0 ∉ some_basis ?V›*) show "disjnt (some_basis s1) (some_basis s2)" unfolding disjnt_def (*goal: ‹some_basis s1 ∩ some_basis s2 = {}›*) by blast qed lemma direct_decomp_span_some_basis: assumes "direct_decomp A ss" and "⋀s. s ∈ set ss ⟹ subspace s" shows "span (⋃(some_basis ` set ss)) = A" proof (-) (*goal: ‹local.span (⋃ (some_basis ` set ss)) = A›*) from assms(1) (*‹direct_decomp A ss›*) have eq0[symmetric]: "sum_list ` listset ss = A" by (rule direct_decompD (*‹⟦direct_decomp (?A::?'a set) (?ss::?'a set list); (?qs::?'a list) ∈ listset ?ss⟧ ⟹ sum_list ?qs ∈ ?A› ‹direct_decomp (?A::?'a set) (?ss::?'a set list) ⟹ inj_on sum_list (listset ?ss)› ‹direct_decomp (?A::?'a set) (?ss::?'a set list) ⟹ sum_list ` listset ?ss = ?A›*)) show "?thesis" (*goal: ‹local.span (⋃ (some_basis ` set ss)) = A›*) unfolding eq0 (*goal: ‹local.span (⋃ (some_basis ` set (ss::'b set list))) = sum_list ` listset ss›*) using assms(2) (*‹?s ∈ set ss ⟹ local.subspace ?s›*) proof (induct ss) (*goals: 1. ‹(⋀s. s ∈ set [] ⟹ local.subspace s) ⟹ local.span (⋃ (some_basis ` set [])) = sum_list ` listset []› 2. ‹⋀a ss. ⟦(⋀s. s ∈ set ss ⟹ local.subspace s) ⟹ local.span (⋃ (some_basis ` set ss)) = sum_list ` listset ss; ⋀s. s ∈ set (a # ss) ⟹ local.subspace s⟧ ⟹ local.span (⋃ (some_basis ` set (a # ss))) = sum_list ` listset (a # ss)›*) case Nil (*‹?s ∈ set [] ⟹ local.subspace ?s›*) show "?case" (*goal: ‹local.span (⋃ (some_basis ` set [])) = sum_list ` listset []›*) by simp next (*goal: ‹⋀a ss. ⟦(⋀s. s ∈ set ss ⟹ local.subspace s) ⟹ local.span (⋃ (some_basis ` set ss)) = sum_list ` listset ss; ⋀s. s ∈ set (a # ss) ⟹ local.subspace s⟧ ⟹ local.span (⋃ (some_basis ` set (a # ss))) = sum_list ` listset (a # ss)›*) case (Cons s ss) (*‹(⋀s. s ∈ set ss ⟹ local.subspace s) ⟹ local.span (⋃ (some_basis ` set ss)) = sum_list ` listset ss› ‹(?s::'b set) ∈ set ((s::'b set) # (ss::'b set list)) ⟹ local.subspace ?s›*) have "subspace s" apply (rule Cons.prems (*‹?s ∈ set (s # ss) ⟹ local.subspace ?s›*)) (*goal: ‹local.subspace s›*) by simp hence eq1: "span (some_basis s) = s" by (rule span_some_basis (*‹local.subspace ?V ⟹ local.span (some_basis ?V) = ?V›*)) have "⋀s'. s' ∈ set ss ⟹ subspace s'" apply (rule Cons.prems (*‹?s ∈ set (s # ss) ⟹ local.subspace ?s›*)) (*goal: ‹⋀s'::'b set. s' ∈ set (ss::'b set list) ⟹ local.subspace s'›*) by simp hence eq2: "span (⋃ (some_basis ` set ss)) = sum_list ` listset ss" by (rule Cons.hyps (*‹(⋀s. s ∈ set ss ⟹ local.subspace s) ⟹ local.span (⋃ (some_basis ` set ss)) = sum_list ` listset ss›*)) have "span (⋃ (some_basis ` set (s # ss))) = {x + y |x y. x ∈ s ∧ y ∈ sum_list ` listset ss}" by (simp add: span_Un (*‹local.span (?S ∪ ?T) = {x + y |x y. x ∈ local.span ?S ∧ y ∈ local.span ?T}›*) eq1 (*‹local.span (some_basis s) = s›*) eq2 (*‹local.span (⋃ (some_basis ` set ss)) = sum_list ` listset ss›*)) also (*calculation: ‹local.span (⋃ (some_basis ` set (s # ss))) = {x + y |x y. x ∈ s ∧ y ∈ sum_list ` listset ss}›*) have "… = sum_list ` listset (s # ss)" (is "?A = ?B") proof (standard) (*goals: 1. ‹{x + y |x y. x ∈ s ∧ y ∈ sum_list ` listset ss} ⊆ sum_list ` listset (s # ss)› 2. ‹sum_list ` listset (s # ss) ⊆ {x + y |x y. x ∈ s ∧ y ∈ sum_list ` listset ss}›*) show "?A ⊆ ?B" proof (standard) (*goal: ‹⋀x. x ∈ {x + y |x y. x ∈ s ∧ y ∈ sum_list ` listset ss} ⟹ x ∈ sum_list ` listset (s # ss)›*) fix a assume "a ∈ ?A" (*‹(a::'b) ∈ {x + y |(x::'b) y::'b. x ∈ (s::'b set) ∧ y ∈ sum_list ` listset (ss::'b set list)}›*) then obtain x and y where "x ∈ s" and "y ∈ sum_list ` listset ss" and a: "a = x + y" (*goal: ‹(⋀x y. ⟦x ∈ s; y ∈ sum_list ` listset ss; a = x + y⟧ ⟹ thesis) ⟹ thesis›*) by blast from this(2) (*‹(y::'b) ∈ sum_list ` listset (ss::'b set list)›*) obtain qs where "qs ∈ listset ss" and y: "y = sum_list qs" (*goal: ‹(⋀qs::'b::ab_group_add list. ⟦qs ∈ listset (ss::'b::ab_group_add set list); (y::'b::ab_group_add) = sum_list qs⟧ ⟹ thesis::bool) ⟹ thesis›*) by standard from ‹x ∈ s› (*‹x ∈ s›*) this(1) (*‹qs ∈ listset ss›*) refl (*‹?t = ?t›*) have "x # qs ∈ listset (s # ss)" by (rule listset_ConsI (*‹⟦(?y::?'a) ∈ (?x::?'a set); (?ys'::?'a list) ∈ listset (?xs::?'a set list); (?ys::?'a list) = ?y # ?ys'⟧ ⟹ ?ys ∈ listset (?x # ?xs)›*)) hence "sum_list (x # qs) ∈ ?B" by (rule imageI (*‹?x ∈ ?A ⟹ ?f ?x ∈ ?f ` ?A›*)) also (*calculation: ‹sum_list (x # qs) ∈ sum_list ` listset (s # ss)›*) have "sum_list (x # qs) = a" by (simp add: a (*‹a = x + y›*) y (*‹y = sum_list qs›*)) finally (*calculation: ‹a ∈ sum_list ` listset (s # ss)›*) show "a ∈ ?B" . qed next (*goal: ‹sum_list ` listset (s # ss) ⊆ {x + y |x y. x ∈ s ∧ y ∈ sum_list ` listset ss}›*) show "?B ⊆ ?A" proof (standard) (*goal: ‹⋀x. x ∈ sum_list ` listset (s # ss) ⟹ x ∈ {x + y |x y. x ∈ s ∧ y ∈ sum_list ` listset ss}›*) fix a assume "a ∈ ?B" (*‹(a::'b) ∈ sum_list ` listset ((s::'b set) # (ss::'b set list))›*) then obtain qs' where "qs' ∈ listset (s # ss)" and a: "a = sum_list qs'" (*goal: ‹(⋀qs'. ⟦qs' ∈ listset (s # ss); a = sum_list qs'⟧ ⟹ thesis) ⟹ thesis›*) by standard from this(1) (*‹qs' ∈ listset (s # ss)›*) obtain x and qs where "x ∈ s" and "qs ∈ listset ss" and qs': "qs' = x # qs" (*goal: ‹(⋀x qs. ⟦x ∈ s; qs ∈ listset ss; qs' = x # qs⟧ ⟹ thesis) ⟹ thesis›*) by (rule listset_ConsE (*‹⟦?ys ∈ listset (?x # ?xs); ⋀y ys'. ⟦y ∈ ?x; ys' ∈ listset ?xs; ?ys = y # ys'⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) from this(2) (*‹qs ∈ listset ss›*) have "sum_list qs ∈ sum_list ` listset ss" by (rule imageI (*‹?x ∈ ?A ⟹ ?f ?x ∈ ?f ` ?A›*)) moreover have "a = x + sum_list qs" by (simp add: a (*‹a = sum_list qs'›*) qs' (*‹qs' = x # qs›*)) ultimately show "a ∈ ?A" using ‹x ∈ s› (*‹x ∈ s›*) by blast qed qed finally (*calculation: ‹local.span (⋃ (some_basis ` set (s # ss))) = sum_list ` listset (s # ss)›*) show "?case" (*goal: ‹local.span (⋃ (some_basis ` set (s # ss))) = sum_list ` listset (s # ss)›*) . qed qed lemma direct_decomp_independent_some_basis: assumes "direct_decomp A ss" and "⋀s. s ∈ set ss ⟹ subspace s" shows "independent (⋃(some_basis ` set ss))" using assms (*‹direct_decomp A ss› ‹?s ∈ set ss ⟹ local.subspace ?s›*) proof (induct ss arbitrary: A) (*goals: 1. ‹⋀A. ⟦direct_decomp A []; ⋀s. s ∈ set [] ⟹ local.subspace s⟧ ⟹ local.independent (⋃ (some_basis ` set []))› 2. ‹⋀a ss A. ⟦⋀A. ⟦direct_decomp A ss; ⋀s. s ∈ set ss ⟹ local.subspace s⟧ ⟹ local.independent (⋃ (some_basis ` set ss)); direct_decomp A (a # ss); ⋀s. s ∈ set (a # ss) ⟹ local.subspace s⟧ ⟹ local.independent (⋃ (some_basis ` set (a # ss)))›*) case Nil (*‹direct_decomp A []› ‹?s ∈ set [] ⟹ local.subspace ?s›*) from independent_empty (*‹local.independent {}›*) show "?case" (*goal: ‹local.independent (⋃ (some_basis ` set []))›*) by simp next (*goal: ‹⋀(a::'b::ab_group_add set) (ss::'b::ab_group_add set list) A::'b::ab_group_add set. ⟦⋀A::'b::ab_group_add set. ⟦direct_decomp A ss; ⋀s::'b::ab_group_add set. s ∈ set ss ⟹ local.subspace s⟧ ⟹ local.independent (⋃ (some_basis ` set ss)); direct_decomp A (a # ss); ⋀s::'b::ab_group_add set. s ∈ set (a # ss) ⟹ local.subspace s⟧ ⟹ local.independent (⋃ (some_basis ` set (a # ss)))›*) case (Cons s ss) (*‹⟦direct_decomp (?A::'b set) (ss::'b set list); ⋀s::'b set. s ∈ set ss ⟹ local.subspace s⟧ ⟹ local.independent (⋃ (some_basis ` set ss))› ‹direct_decomp A (s # ss)› ‹?s ∈ set (s # ss) ⟹ local.subspace ?s›*) have 1: "⋀s'. s' ∈ set ss ⟹ subspace s'" apply (rule Cons.prems (*‹direct_decomp (A::'b set) ((s::'b set) # (ss::'b set list))› ‹(?s::'b set) ∈ set ((s::'b set) # (ss::'b set list)) ⟹ local.subspace ?s›*)) (*goal: ‹⋀s'. s' ∈ set ss ⟹ local.subspace s'›*) by simp have "subspace s" apply (rule Cons.prems (*‹direct_decomp A (s # ss)› ‹?s ∈ set (s # ss) ⟹ local.subspace ?s›*)) (*goal: ‹local.subspace s›*) by simp hence "0 ∈ s" and eq1: "span (some_basis s) = s" apply - (*goals: 1. ‹local.subspace s ⟹ 0 ∈ s› 2. ‹local.subspace s ⟹ local.span (some_basis s) = s› discuss goal 1*) apply ((msorry)[1]) (*discuss goal 2*) apply ((msorry)[1]) (*proven 2 subgoals*) . from Cons.prems(1) (*‹direct_decomp A (s # ss)›*) have "*": "direct_decomp A ([s] @ ss)" by simp moreover from ‹0 ∈ s› (*‹0 ∈ s›*) have "{} ∉ set [s]" by auto ultimately have 2: "direct_decomp (sum_list ` listset ss) ss" by (rule direct_decomp_appendD (*‹⟦direct_decomp ?A (?ss1.0 @ ?ss2.0); {} ∉ set ?ss2.0⟧ ⟹ direct_decomp (sum_list ` listset ?ss1.0) ?ss1.0› ‹⟦direct_decomp ?A (?ss1.0 @ ?ss2.0); {} ∉ set ?ss1.0⟧ ⟹ direct_decomp (sum_list ` listset ?ss2.0) ?ss2.0› ‹direct_decomp ?A (?ss1.0 @ ?ss2.0) ⟹ direct_decomp ?A [sum_list ` listset ?ss1.0, sum_list ` listset ?ss2.0]›*)) hence eq2: "span (⋃ (some_basis ` set ss)) = sum_list ` listset ss" using "1" (*‹?s' ∈ set ss ⟹ local.subspace ?s'›*) by (rule direct_decomp_span_some_basis (*‹⟦direct_decomp (?A::'b::ab_group_add set) (?ss::'b::ab_group_add set list); ⋀s::'b::ab_group_add set. s ∈ set ?ss ⟹ local.subspace s⟧ ⟹ local.span (⋃ (some_basis ` set ?ss)) = ?A›*)) note independent_some_basis[of s] (*‹local.independent (some_basis s)›*) moreover from "2" (*‹direct_decomp (sum_list ` listset ss) ss›*) "1" (*‹(?s'::'b set) ∈ set (ss::'b set list) ⟹ local.subspace ?s'›*) have "independent (⋃ (some_basis ` set ss))" by (rule Cons.hyps (*‹⟦direct_decomp ?A ss; ⋀s. s ∈ set ss ⟹ local.subspace s⟧ ⟹ local.independent (⋃ (some_basis ` set ss))›*)) moreover have "span (some_basis s) ∩ span (⋃ (some_basis ` set ss)) = {0}" proof (-) (*goal: ‹local.span (some_basis s) ∩ local.span (⋃ (some_basis ` set ss)) = {0}›*) from "*" (*‹direct_decomp (A::'b set) ([s::'b set] @ (ss::'b set list))›*) have "direct_decomp A [sum_list ` listset [s], sum_list ` listset ss]" by (rule direct_decomp_appendD (*‹⟦direct_decomp (?A::?'a::comm_monoid_add set) ((?ss1.0::?'a::comm_monoid_add set list) @ (?ss2.0::?'a::comm_monoid_add set list)); {} ∉ set ?ss2.0⟧ ⟹ direct_decomp (sum_list ` listset ?ss1.0) ?ss1.0› ‹⟦direct_decomp (?A::?'a::comm_monoid_add set) ((?ss1.0::?'a::comm_monoid_add set list) @ (?ss2.0::?'a::comm_monoid_add set list)); {} ∉ set ?ss1.0⟧ ⟹ direct_decomp (sum_list ` listset ?ss2.0) ?ss2.0› ‹direct_decomp (?A::?'a::comm_monoid_add set) ((?ss1.0::?'a::comm_monoid_add set list) @ (?ss2.0::?'a::comm_monoid_add set list)) ⟹ direct_decomp ?A [sum_list ` listset ?ss1.0, sum_list ` listset ?ss2.0]›*)) hence "direct_decomp A [s, sum_list ` listset ss]" by (simp add: image_image (*‹?f ` ?g ` ?A = (λx. ?f (?g x)) ` ?A›*)) moreover have "0 < (1::nat)" by simp moreover have "1 < length [s, sum_list ` listset ss]" by simp ultimately have "[s, sum_list ` listset ss] ! 0 ∩ [s, sum_list ` listset ss] ! 1 = {0}" apply (rule direct_decomp_Int_zero (*‹⟦direct_decomp ?A ?ss; ?i < ?j; ?j < length ?ss; ⋀s. s ∈ set ?ss ⟹ 0 ∈ s⟧ ⟹ ?ss ! ?i ∩ ?ss ! ?j = {0}›*)) (*goal: ‹[s, sum_list ` listset ss] ! 0 ∩ [s, sum_list ` listset ss] ! 1 = {0}›*) by (auto simp: ‹0 ∈ s› eq2[symmetric] (*‹sum_list ` listset (ss::'b set list) = local.span (⋃ (some_basis ` set ss))›*) span_zero (*‹(0::'b) ∈ local.span (?S::'b set)›*)) thus "?thesis" (*goal: ‹local.span (some_basis s) ∩ local.span (⋃ (some_basis ` set ss)) = {0}›*) by (simp add: eq1 (*‹local.span (some_basis s) = s›*) eq2 (*‹local.span (⋃ (some_basis ` set ss)) = sum_list ` listset ss›*)) qed ultimately have "independent (some_basis s ∪ (⋃ (some_basis ` set ss)))" by (rule independent_UnI (*‹⟦local.independent ?A; local.independent ?B; local.span ?A ∩ local.span ?B = {0}⟧ ⟹ local.independent (?A ∪ ?B)›*)) thus "?case" (*goal: ‹local.independent (⋃ (some_basis ` set (s # ss)))›*) by simp qed corollary direct_decomp_is_basis: assumes "direct_decomp A ss" and "⋀s. s ∈ set ss ⟹ subspace s" shows "is_basis A (⋃(some_basis ` set ss))" proof (-) (*goal: ‹is_basis A (⋃ (some_basis ` set ss))›*) from assms (*‹direct_decomp A ss› ‹?s ∈ set ss ⟹ local.subspace ?s›*) have "subspace A" by (rule subspace_direct_decomp (*‹⟦direct_decomp (?A::'b set) (?ss::'b set list); ⋀s::'b set. s ∈ set ?ss ⟹ local.subspace s⟧ ⟹ local.subspace ?A›*)) moreover from assms (*‹direct_decomp (A::'b::ab_group_add set) (ss::'b::ab_group_add set list)› ‹?s ∈ set ss ⟹ local.subspace ?s›*) have "span (⋃(some_basis ` set ss)) = A" by (rule direct_decomp_span_some_basis (*‹⟦direct_decomp ?A ?ss; ⋀s. s ∈ set ?ss ⟹ local.subspace s⟧ ⟹ local.span (⋃ (some_basis ` set ?ss)) = ?A›*)) moreover from assms (*‹direct_decomp A ss› ‹?s ∈ set ss ⟹ local.subspace ?s›*) have "independent (⋃(some_basis ` set ss))" by (rule direct_decomp_independent_some_basis (*‹⟦direct_decomp (?A::'b set) (?ss::'b set list); ⋀s::'b set. s ∈ set ?ss ⟹ local.subspace s⟧ ⟹ local.independent (⋃ (some_basis ` set ?ss))›*)) ultimately show "?thesis" (*goal: ‹is_basis A (⋃ (some_basis ` set ss))›*) by (simp add: is_basis_alt (*‹local.subspace ?V ⟹ is_basis ?V ?B = (local.independent ?B ∧ local.span ?B = ?V)›*)) qed lemma dim_direct_decomp: assumes "direct_decomp A ss" and "finite B" and "A ⊆ span B" and "⋀s. s ∈ set ss ⟹ subspace s" shows "dim A = (∑s∈set ss. dim s)" proof (-) (*goal: ‹local.dim A = sum local.dim (set ss)›*) from assms(1,4) (*‹direct_decomp A ss› ‹(?s::'b::ab_group_add set) ∈ set (ss::'b::ab_group_add set list) ⟹ local.subspace ?s›*) have "is_basis A (⋃(some_basis ` set ss))" (is "is_basis A ?B") by (rule direct_decomp_is_basis (*‹⟦direct_decomp ?A ?ss; ⋀s. s ∈ set ?ss ⟹ local.subspace s⟧ ⟹ is_basis ?A (⋃ (some_basis ` set ?ss))›*)) hence "dim A = card ?B" and "independent ?B" and "?B ⊆ A" apply - (*goals: 1. ‹is_basis (A::'b set) (⋃ (some_basis ` set (ss::'b set list))) ⟹ local.dim A = card (⋃ (some_basis ` set ss))› 2. ‹is_basis (A::'b set) (⋃ (some_basis ` set (ss::'b set list))) ⟹ local.independent (⋃ (some_basis ` set ss))› 3. ‹is_basis (A::'b set) (⋃ (some_basis ` set (ss::'b set list))) ⟹ ⋃ (some_basis ` set ss) ⊆ A› discuss goal 1*) apply (simp add: is_basis_def (*‹is_basis ?V ?B = (?B ⊆ ?V ∧ local.independent ?B ∧ ?V ⊆ local.span ?B ∧ card ?B = local.dim ?V)›*)) (*discuss goal 2*) apply (simp add: is_basis_def (*‹is_basis (?V::'b::ab_group_add set) (?B::'b::ab_group_add set) = (?B ⊆ ?V ∧ local.independent ?B ∧ ?V ⊆ local.span ?B ∧ card ?B = local.dim ?V)›*)) (*discuss goal 3*) apply (simp add: is_basis_def (*‹is_basis ?V ?B = (?B ⊆ ?V ∧ local.independent ?B ∧ ?V ⊆ local.span ?B ∧ card ?B = local.dim ?V)›*)) (*proven 3 subgoals*) . from this(3) (*‹⋃ (some_basis ` set ss) ⊆ A›*) assms(3) (*‹A ⊆ local.span B›*) have "?B ⊆ span B" by (rule subset_trans (*‹⟦?A ⊆ ?B; ?B ⊆ ?C⟧ ⟹ ?A ⊆ ?C›*)) with assms(2) (*‹finite B›*) ‹independent ?B› (*‹local.independent (⋃ (some_basis ` set ss))›*) have "finite ?B" using independent_span_bound (*‹⟦finite ?T; local.independent ?S; ?S ⊆ local.span ?T⟧ ⟹ finite ?S ∧ card ?S ≤ card ?T›*) by blast note ‹dim A = card ?B› (*‹local.dim A = card (⋃ (some_basis ` set ss))›*) also (*calculation: ‹local.dim (A::'b set) = card (⋃ (some_basis ` set (ss::'b set list)))›*) from finite_set (*‹finite (set ?xs)›*) have "card ?B = (∑s∈set ss. card (some_basis s))" proof (intro card_UN_disjoint (*‹⟦finite (?I::?'a set); ∀i::?'a∈?I. finite ((?A::?'a ⇒ ?'b set) i); ∀i::?'a∈?I. ∀j::?'a∈?I. i ≠ j ⟶ ?A i ∩ ?A j = {}⟧ ⟹ card (⋃ (?A ` ?I)) = (∑i::?'a∈?I. card (?A i))›*) ballI (*‹(⋀x::?'a. x ∈ (?A::?'a set) ⟹ (?P::?'a ⇒ bool) x) ⟹ ∀x::?'a∈?A. ?P x›*) impI (*‹(?P::bool ⟹ ?Q::bool) ⟹ ?P ⟶ ?Q›*)) (*goals: 1. ‹(⋀xs. finite (set xs)) ⟹ finite (set ss)› 2. ‹⋀s. ⟦⋀xs. finite (set xs); s ∈ set ss⟧ ⟹ finite (some_basis s)› 3. ‹⋀s j. ⟦⋀xs. finite (set xs); s ∈ set ss; j ∈ set ss; s ≠ j⟧ ⟹ some_basis s ∩ some_basis j = {}›*) fix s assume "s ∈ set ss" (*‹(s::'b set) ∈ set (ss::'b set list)›*) with ‹finite ?B› (*‹finite (⋃ (some_basis ` set ss))›*) show "finite (some_basis s)" by auto next (*goals: 1. ‹(⋀xs. finite (set xs)) ⟹ finite (set ss)› 2. ‹⋀s j. ⟦⋀xs. finite (set xs); s ∈ set ss; j ∈ set ss; s ≠ j⟧ ⟹ some_basis s ∩ some_basis j = {}›*) fix s1 and s2 have "pairwise (λs t. disjnt (some_basis s) (some_basis t)) (set ss)" using assms(1,4) (*‹direct_decomp (A::'b::ab_group_add set) (ss::'b::ab_group_add set list)› ‹?s ∈ set ss ⟹ local.subspace ?s›*) by (rule direct_decomp_some_basis_pairwise_disjnt (*‹⟦direct_decomp ?A ?ss; ⋀s. s ∈ set ?ss ⟹ local.subspace s⟧ ⟹ pairwise (λs1 s2. disjnt (some_basis s1) (some_basis s2)) (set ?ss)›*)) moreover assume "s1 ∈ set ss" and "s2 ∈ set ss" and "s1 ≠ s2" (*‹(s1::'b set) ∈ set (ss::'b set list)› ‹(s2::'b set) ∈ set (ss::'b set list)› ‹(s1::'b set) ≠ (s2::'b set)›*) thm pairwiseD ultimately have "disjnt (some_basis s1) (some_basis s2)" by (rule pairwiseD (*‹⟦pairwise (?R::?'a ⇒ ?'a ⇒ bool) (?S::?'a set); (?x::?'a) ∈ ?S; (?y::?'a) ∈ ?S; ?x ≠ ?y⟧ ⟹ ?R ?x ?y›*)) thus "some_basis s1 ∩ some_basis s2 = {}" by (simp only: disjnt_def (*‹disjnt (?A::?'a set) (?B::?'a set) = (?A ∩ ?B = {})›*)) qed also (*calculation: ‹local.dim A = (∑s∈set ss. card (some_basis s))›*) from refl (*‹?t = ?t›*) card_some_basis (*‹card (some_basis ?V) = local.dim ?V›*) have "… = (∑s∈set ss. dim s)" by (rule sum.cong (*‹⟦?A = ?B; ⋀x. x ∈ ?B ⟹ ?g x = ?h x⟧ ⟹ sum ?g ?A = sum ?h ?B›*)) finally (*calculation: ‹local.dim A = sum local.dim (set ss)›*) show "?thesis" (*goal: ‹local.dim A = sum local.dim (set ss)›*) . qed end (* vector_space *) subsection ‹Homogeneous Sets of Polynomials with Fixed Degree› lemma homogeneous_set_direct_decomp: assumes "direct_decomp A ss" and "⋀s. s ∈ set ss ⟹ homogeneous_set s" shows "homogeneous_set A" proof (rule homogeneous_setI (*‹(⋀a n. a ∈ ?A ⟹ hom_component a n ∈ ?A) ⟹ homogeneous_set ?A›*)) (*goal: ‹⋀a n. a ∈ A ⟹ hom_component a n ∈ A›*) fix a and n assume "a ∈ A" (*‹(a::('a ⇒₀ nat) ⇒₀ 'b) ∈ (A::(('a ⇒₀ nat) ⇒₀ 'b) set)›*) with assms(1) (*‹direct_decomp (A::(('a ⇒₀ nat) ⇒₀ 'b) set) (ss::(('a ⇒₀ nat) ⇒₀ 'b) set list)›*) obtain qs where "qs ∈ listset ss" and a: "a = sum_list qs" (*goal: ‹(⋀qs. ⟦qs ∈ listset ss; a = sum_list qs⟧ ⟹ thesis) ⟹ thesis›*) by (rule direct_decompE (*‹⟦direct_decomp ?A ?ss; ?a ∈ ?A; ⋀qs. ⟦qs ∈ listset ?ss; ?a = sum_list qs⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) have "hom_component a n = hom_component (sum_list qs) n" by (simp only: a (*‹a = sum_list qs›*)) also (*calculation: ‹hom_component (a::('a ⇒₀ nat) ⇒₀ 'b) (n::nat) = hom_component (sum_list (qs::(('a ⇒₀ nat) ⇒₀ 'b) list)) n›*) have "… = sum_list (map (λq. hom_component q n) qs)" apply (induct qs) (*goals: 1. ‹hom_component (sum_list []) n = (∑q←[]. hom_component q n)› 2. ‹⋀a qs. hom_component (sum_list qs) n = (∑q←qs. hom_component q n) ⟹ hom_component (sum_list (a # qs)) n = (∑q←a # qs. hom_component q n)› discuss goal 1*) apply (simp add: hom_component_plus (*‹hom_component (?p + ?q) ?n = hom_component ?p ?n + hom_component ?q ?n›*)) (*discuss goal 2*) apply (simp add: hom_component_plus (*‹hom_component (?p + ?q) ?n = hom_component ?p ?n + hom_component ?q ?n›*)) (*proven 2 subgoals*) . also (*calculation: ‹hom_component a n = (∑q←qs. hom_component q n)›*) from assms(1) (*‹direct_decomp A ss›*) have "… ∈ A" proof (rule direct_decompD (*‹⟦direct_decomp ?A ?ss; ?qs ∈ listset ?ss⟧ ⟹ sum_list ?qs ∈ ?A› ‹direct_decomp ?A ?ss ⟹ inj_on sum_list (listset ?ss)› ‹direct_decomp ?A ?ss ⟹ sum_list ` listset ?ss = ?A›*)) (*goal: ‹map (λq::('a::type ⇒₀ nat) ⇒₀ 'b::comm_monoid_add. hom_component q (n::nat)) (qs::(('a::type ⇒₀ nat) ⇒₀ 'b::comm_monoid_add) list) ∈ listset (ss::(('a::type ⇒₀ nat) ⇒₀ 'b::comm_monoid_add) set list)›*) show "map (λq. hom_component q n) qs ∈ listset ss" proof (rule listset_closed_map (*‹⟦?ys ∈ listset ?xs; ⋀x y. ⟦x ∈ set ?xs; y ∈ x⟧ ⟹ ?f y ∈ x⟧ ⟹ map ?f ?ys ∈ listset ?xs›*)) (*goals: 1. ‹qs ∈ listset ss› 2. ‹⋀x y. ⟦x ∈ set ss; y ∈ x⟧ ⟹ hom_component y n ∈ x›*) fix s and q assume "s ∈ set ss" (*‹(s::(('a ⇒₀ nat) ⇒₀ 'b) set) ∈ set (ss::(('a ⇒₀ nat) ⇒₀ 'b) set list)›*) hence "homogeneous_set s" by (rule assms( (*‹(?s::(('a ⇒₀ nat) ⇒₀ 'b) set) ∈ set (ss::(('a ⇒₀ nat) ⇒₀ 'b) set list) ⟹ homogeneous_set ?s›*) 2)) moreover assume "q ∈ s" (*‹(q::('a ⇒₀ nat) ⇒₀ 'b) ∈ (s::(('a ⇒₀ nat) ⇒₀ 'b) set)›*) ultimately show "hom_component q n ∈ s" by (rule homogeneous_setD (*‹⟦homogeneous_set ?A; ?a ∈ ?A⟧ ⟹ hom_component ?a ?n ∈ ?A›*)) qed (fact) (*solved the remaining goal: ‹qs ∈ listset ss›*) qed finally (*calculation: ‹hom_component a n ∈ A›*) show "hom_component a n ∈ A" . qed definition hom_deg_set :: "nat ⇒ (('x ⇒₀ nat) ⇒₀ 'a) set ⇒ (('x ⇒₀ nat) ⇒₀ 'a::zero) set" where "hom_deg_set z A = (λa. hom_component a z) ` A" lemma hom_deg_setD: assumes "p ∈ hom_deg_set z A" shows "homogeneous p" and "p ≠ 0 ⟹ poly_deg p = z" proof (-) (*goals: 1. ‹homogeneous p› 2. ‹p ≠ 0 ⟹ poly_deg p = z›*) from assms (*‹(p::('a::type ⇒₀ nat) ⇒₀ 'b::zero) ∈ hom_deg_set (z::nat) (A::(('a::type ⇒₀ nat) ⇒₀ 'b::zero) set)›*) obtain a where "a ∈ A" and p: "p = hom_component a z" (*goal: ‹(⋀a::('a::type ⇒₀ nat) ⇒₀ 'b::zero. ⟦a ∈ (A::(('a::type ⇒₀ nat) ⇒₀ 'b::zero) set); (p::('a::type ⇒₀ nat) ⇒₀ 'b::zero) = hom_component a (z::nat)⟧ ⟹ thesis::bool) ⟹ thesis›*) unfolding hom_deg_set_def (*goal: ‹(⋀a. ⟦a ∈ A; p = hom_component a z⟧ ⟹ thesis) ⟹ thesis›*) by standard show "*": "homogeneous p" by (simp only: p (*‹p = hom_component a z›*) homogeneous_hom_component (*‹homogeneous (hom_component ?p ?n)›*)) assume "p ≠ 0" (*‹(p::('a ⇒₀ nat) ⇒₀ 'b) ≠ (0::('a ⇒₀ nat) ⇒₀ 'b)›*) hence "keys p ≠ {}" by simp then obtain t where "t ∈ keys p" (*goal: ‹(⋀t. t ∈ keys p ⟹ thesis) ⟹ thesis›*) by blast with "*" (*‹homogeneous p›*) have "deg_pm t = poly_deg p" by (rule homogeneousD_poly_deg (*‹⟦homogeneous ?p; ?t ∈ keys ?p⟧ ⟹ deg_pm ?t = poly_deg ?p›*)) moreover from ‹t ∈ keys p› (*‹(t::'a::type ⇒₀ nat) ∈ keys (p::('a::type ⇒₀ nat) ⇒₀ 'b::zero)›*) have "deg_pm t = z" unfolding p (*goal: ‹deg_pm t = z›*) by (rule keys_hom_componentD (*‹?t ∈ keys (hom_component ?p ?n) ⟹ ?t ∈ keys ?p› ‹?t ∈ keys (hom_component ?p ?n) ⟹ deg_pm ?t = ?n›*)) ultimately show "poly_deg p = z" by simp qed lemma zero_in_hom_deg_set: assumes "0 ∈ A" shows "0 ∈ hom_deg_set z A" proof (-) (*goal: ‹0 ∈ hom_deg_set z A›*) have "0 = hom_component 0 z" by simp also (*calculation: ‹0 = hom_component 0 z›*) from assms (*‹0 ∈ A›*) have "… ∈ hom_deg_set z A" unfolding hom_deg_set_def (*goal: ‹hom_component (0::('a::type ⇒₀ nat) ⇒₀ 'b::zero) (z::nat) ∈ (λa::('a::type ⇒₀ nat) ⇒₀ 'b::zero. hom_component a z) ` (A::(('a::type ⇒₀ nat) ⇒₀ 'b::zero) set)›*) by (rule imageI (*‹?x ∈ ?A ⟹ ?f ?x ∈ ?f ` ?A›*)) finally (*calculation: ‹0 ∈ hom_deg_set z A›*) show "?thesis" (*goal: ‹0 ∈ hom_deg_set z A›*) . qed lemma hom_deg_set_closed_uminus: assumes "⋀a. a ∈ A ⟹ - a ∈ A" and "p ∈ hom_deg_set z A" shows "- p ∈ hom_deg_set z A" proof (-) (*goal: ‹- p ∈ hom_deg_set z A›*) from assms(2) (*‹p ∈ hom_deg_set z A›*) obtain a where "a ∈ A" and p: "p = hom_component a z" (*goal: ‹(⋀a. ⟦a ∈ A; p = hom_component a z⟧ ⟹ thesis) ⟹ thesis›*) unfolding hom_deg_set_def (*goal: ‹(⋀a::('a ⇒₀ nat) ⇒₀ 'b. ⟦a ∈ (A::(('a ⇒₀ nat) ⇒₀ 'b) set); (p::('a ⇒₀ nat) ⇒₀ 'b) = hom_component a (z::nat)⟧ ⟹ thesis::bool) ⟹ thesis›*) by standard from this(1) (*‹(a::('a ⇒₀ nat) ⇒₀ 'b) ∈ (A::(('a ⇒₀ nat) ⇒₀ 'b) set)›*) have "- a ∈ A" by (rule assms( (*‹(?a::('a ⇒₀ nat) ⇒₀ 'b) ∈ (A::(('a ⇒₀ nat) ⇒₀ 'b) set) ⟹ - ?a ∈ A›*) 1)) moreover have "- p = hom_component (- a) z" by (simp add: p (*‹(p::('a ⇒₀ nat) ⇒₀ 'b) = hom_component (a::('a ⇒₀ nat) ⇒₀ 'b) (z::nat)›*)) ultimately show "?thesis" (*goal: ‹- p ∈ hom_deg_set z A›*) unfolding hom_deg_set_def (*goal: ‹- p ∈ (λa. hom_component a z) ` A›*) by (rule rev_image_eqI (*‹⟦(?x::?'a) ∈ (?A::?'a set); (?b::?'b) = (?f::?'a ⇒ ?'b) ?x⟧ ⟹ ?b ∈ ?f ` ?A›*)) qed lemma hom_deg_set_closed_plus: assumes "⋀a1 a2. a1 ∈ A ⟹ a2 ∈ A ⟹ a1 + a2 ∈ A" and "p ∈ hom_deg_set z A" and "q ∈ hom_deg_set z A" shows "p + q ∈ hom_deg_set z A" proof (-) (*goal: ‹(p::('a ⇒₀ nat) ⇒₀ 'b) + (q::('a ⇒₀ nat) ⇒₀ 'b) ∈ hom_deg_set (z::nat) (A::(('a ⇒₀ nat) ⇒₀ 'b) set)›*) from assms(2) (*‹p ∈ hom_deg_set z A›*) obtain a1 where "a1 ∈ A" and p: "p = hom_component a1 z" (*goal: ‹(⋀a1::('a::type ⇒₀ nat) ⇒₀ 'b::monoid_add. ⟦a1 ∈ (A::(('a::type ⇒₀ nat) ⇒₀ 'b::monoid_add) set); (p::('a::type ⇒₀ nat) ⇒₀ 'b::monoid_add) = hom_component a1 (z::nat)⟧ ⟹ thesis::bool) ⟹ thesis›*) unfolding hom_deg_set_def (*goal: ‹(⋀a1. ⟦a1 ∈ A; p = hom_component a1 z⟧ ⟹ thesis) ⟹ thesis›*) by standard from assms(3) (*‹q ∈ hom_deg_set z A›*) obtain a2 where "a2 ∈ A" and q: "q = hom_component a2 z" (*goal: ‹(⋀a2::('a ⇒₀ nat) ⇒₀ 'b. ⟦a2 ∈ (A::(('a ⇒₀ nat) ⇒₀ 'b) set); (q::('a ⇒₀ nat) ⇒₀ 'b) = hom_component a2 (z::nat)⟧ ⟹ thesis::bool) ⟹ thesis›*) unfolding hom_deg_set_def (*goal: ‹(⋀a2. ⟦a2 ∈ A; q = hom_component a2 z⟧ ⟹ thesis) ⟹ thesis›*) by standard from ‹a1 ∈ A› (*‹a1 ∈ A›*) this(1) (*‹a2 ∈ A›*) have "a1 + a2 ∈ A" by (rule assms( (*‹⟦(?a1.0::('a::type ⇒₀ nat) ⇒₀ 'b::monoid_add) ∈ (A::(('a::type ⇒₀ nat) ⇒₀ 'b::monoid_add) set); (?a2.0::('a::type ⇒₀ nat) ⇒₀ 'b::monoid_add) ∈ A⟧ ⟹ ?a1.0 + ?a2.0 ∈ A›*) 1)) moreover have "p + q = hom_component (a1 + a2) z" by (simp only: p (*‹(p::('a::type ⇒₀ nat) ⇒₀ 'b::monoid_add) = hom_component (a1::('a::type ⇒₀ nat) ⇒₀ 'b::monoid_add) (z::nat)›*) q (*‹(q::('a::type ⇒₀ nat) ⇒₀ 'b::monoid_add) = hom_component (a2::('a::type ⇒₀ nat) ⇒₀ 'b::monoid_add) (z::nat)›*) hom_component_plus (*‹hom_component ((?p::(?'a::type ⇒₀ nat) ⇒₀ ?'b::monoid_add) + (?q::(?'a::type ⇒₀ nat) ⇒₀ ?'b::monoid_add)) (?n::nat) = hom_component ?p ?n + hom_component ?q ?n›*)) ultimately show "?thesis" (*goal: ‹(p::('a ⇒₀ nat) ⇒₀ 'b) + (q::('a ⇒₀ nat) ⇒₀ 'b) ∈ hom_deg_set (z::nat) (A::(('a ⇒₀ nat) ⇒₀ 'b) set)›*) unfolding hom_deg_set_def (*goal: ‹p + q ∈ (λa. hom_component a z) ` A›*) by (rule rev_image_eqI (*‹⟦?x ∈ ?A; ?b = ?f ?x⟧ ⟹ ?b ∈ ?f ` ?A›*)) qed lemma hom_deg_set_closed_minus: assumes "⋀a1 a2. a1 ∈ A ⟹ a2 ∈ A ⟹ a1 - a2 ∈ A" and "p ∈ hom_deg_set z A" and "q ∈ hom_deg_set z A" shows "p - q ∈ hom_deg_set z A" proof (-) (*goal: ‹p - q ∈ hom_deg_set z A›*) from assms(2) (*‹p ∈ hom_deg_set z A›*) obtain a1 where "a1 ∈ A" and p: "p = hom_component a1 z" (*goal: ‹(⋀a1. ⟦a1 ∈ A; p = hom_component a1 z⟧ ⟹ thesis) ⟹ thesis›*) unfolding hom_deg_set_def (*goal: ‹(⋀a1. ⟦a1 ∈ A; p = hom_component a1 z⟧ ⟹ thesis) ⟹ thesis›*) by standard from assms(3) (*‹q ∈ hom_deg_set z A›*) obtain a2 where "a2 ∈ A" and q: "q = hom_component a2 z" (*goal: ‹(⋀a2::('a::type ⇒₀ nat) ⇒₀ 'b::cancel_comm_monoid_add. ⟦a2 ∈ (A::(('a::type ⇒₀ nat) ⇒₀ 'b::cancel_comm_monoid_add) set); (q::('a::type ⇒₀ nat) ⇒₀ 'b::cancel_comm_monoid_add) = hom_component a2 (z::nat)⟧ ⟹ thesis::bool) ⟹ thesis›*) unfolding hom_deg_set_def (*goal: ‹(⋀a2. ⟦a2 ∈ A; q = hom_component a2 z⟧ ⟹ thesis) ⟹ thesis›*) by standard from ‹a1 ∈ A› (*‹a1 ∈ A›*) this(1) (*‹a2 ∈ A›*) have "a1 - a2 ∈ A" by (rule assms( (*‹⟦?a1.0 ∈ A; ?a2.0 ∈ A⟧ ⟹ ?a1.0 - ?a2.0 ∈ A›*) 1)) moreover have "p - q = hom_component (a1 - a2) z" by (simp only: p (*‹(p::('a ⇒₀ nat) ⇒₀ 'b) = hom_component (a1::('a ⇒₀ nat) ⇒₀ 'b) (z::nat)›*) q (*‹(q::('a ⇒₀ nat) ⇒₀ 'b) = hom_component (a2::('a ⇒₀ nat) ⇒₀ 'b) (z::nat)›*) hom_component_minus (*‹hom_component ((?p::(?'a ⇒₀ nat) ⇒₀ ?'b) - (?q::(?'a ⇒₀ nat) ⇒₀ ?'b)) (?n::nat) = hom_component ?p ?n - hom_component ?q ?n›*)) ultimately show "?thesis" (*goal: ‹p - q ∈ hom_deg_set z A›*) unfolding hom_deg_set_def (*goal: ‹p - q ∈ (λa. hom_component a z) ` A›*) by (rule rev_image_eqI (*‹⟦?x ∈ ?A; ?b = ?f ?x⟧ ⟹ ?b ∈ ?f ` ?A›*)) qed lemma hom_deg_set_closed_scalar: assumes "⋀a. a ∈ A ⟹ c ⋅ a ∈ A" and "p ∈ hom_deg_set z A" shows "(c::'a::semiring_0) ⋅ p ∈ hom_deg_set z A" proof (-) (*goal: ‹c ⋅ p ∈ hom_deg_set z A›*) from assms(2) (*‹p ∈ hom_deg_set z A›*) obtain a where "a ∈ A" and p: "p = hom_component a z" (*goal: ‹(⋀a. ⟦a ∈ A; p = hom_component a z⟧ ⟹ thesis) ⟹ thesis›*) unfolding hom_deg_set_def (*goal: ‹(⋀a::('b ⇒₀ nat) ⇒₀ 'a. ⟦a ∈ (A::(('b ⇒₀ nat) ⇒₀ 'a) set); (p::('b ⇒₀ nat) ⇒₀ 'a) = hom_component a (z::nat)⟧ ⟹ thesis::bool) ⟹ thesis›*) by standard from this(1) (*‹a ∈ A›*) have "c ⋅ a ∈ A" by (rule assms( (*‹(?a::('b::type ⇒₀ nat) ⇒₀ 'a::semiring_0) ∈ (A::(('b::type ⇒₀ nat) ⇒₀ 'a::semiring_0) set) ⟹ (c::'a::semiring_0) ⋅ ?a ∈ A›*) 1)) moreover have "c ⋅ p = hom_component (c ⋅ a) z" by (simp add: p (*‹(p::('b ⇒₀ nat) ⇒₀ 'a) = hom_component (a::('b ⇒₀ nat) ⇒₀ 'a) (z::nat)›*) punit.map_scale_eq_monom_mult (*‹(?c::?'b) ⋅ (?p::?'a ⇒₀ ?'b) = punit.monom_mult ?c (0::?'a) ?p›*) hom_component_monom_mult (*‹punit.monom_mult (?c::?'b) (?t::?'a ⇒₀ nat) (hom_component (?p::(?'a ⇒₀ nat) ⇒₀ ?'b) (?n::nat)) = hom_component (punit.monom_mult ?c ?t ?p) (deg_pm ?t + ?n)›*)) ultimately show "?thesis" (*goal: ‹(c::'a) ⋅ (p::('b ⇒₀ nat) ⇒₀ 'a) ∈ hom_deg_set (z::nat) (A::(('b ⇒₀ nat) ⇒₀ 'a) set)›*) unfolding hom_deg_set_def (*goal: ‹c ⋅ p ∈ (λa. hom_component a z) ` A›*) by (rule rev_image_eqI (*‹⟦?x ∈ ?A; ?b = ?f ?x⟧ ⟹ ?b ∈ ?f ` ?A›*)) qed lemma hom_deg_set_closed_sum: assumes "0 ∈ A" and "⋀a1 a2. a1 ∈ A ⟹ a2 ∈ A ⟹ a1 + a2 ∈ A" and "⋀i. i ∈ I ⟹ f i ∈ hom_deg_set z A" shows "sum f I ∈ hom_deg_set z A" using assms(3) (*‹?i ∈ I ⟹ f ?i ∈ hom_deg_set z A›*) proof (induct I rule: infinite_finite_induct (*‹⟦⋀A. infinite A ⟹ ?P A; ?P {}; ⋀x F. ⟦finite F; x ∉ F; ?P F⟧ ⟹ ?P (insert x F)⟧ ⟹ ?P ?A›*)) (*goals: 1. ‹⋀Aa. ⟦infinite Aa; ⋀i. i ∈ Aa ⟹ f i ∈ hom_deg_set z A⟧ ⟹ sum f Aa ∈ hom_deg_set z A› 2. ‹(⋀i. i ∈ {} ⟹ f i ∈ hom_deg_set z A) ⟹ sum f {} ∈ hom_deg_set z A› 3. ‹⋀x F. ⟦finite F; x ∉ F; (⋀i. i ∈ F ⟹ f i ∈ hom_deg_set z A) ⟹ sum f F ∈ hom_deg_set z A; ⋀i. i ∈ insert x F ⟹ f i ∈ hom_deg_set z A⟧ ⟹ sum f (insert x F) ∈ hom_deg_set z A›*) case (infinite I) (*‹infinite I› ‹?i ∈ I ⟹ f ?i ∈ hom_deg_set z A›*) with assms(1) (*‹0 ∈ A›*) show "?case" (*goal: ‹sum (f::'c ⇒ ('a ⇒₀ nat) ⇒₀ 'b) (I::'c set) ∈ hom_deg_set (z::nat) (A::(('a ⇒₀ nat) ⇒₀ 'b) set)›*) by (simp add: zero_in_hom_deg_set (*‹(0::(?'a ⇒₀ nat) ⇒₀ ?'b) ∈ (?A::((?'a ⇒₀ nat) ⇒₀ ?'b) set) ⟹ (0::(?'a ⇒₀ nat) ⇒₀ ?'b) ∈ hom_deg_set (?z::nat) ?A›*)) next (*goals: 1. ‹(⋀i::'c::type. i ∈ {} ⟹ (f::'c::type ⇒ ('a::type ⇒₀ nat) ⇒₀ 'b::comm_monoid_add) i ∈ hom_deg_set (z::nat) (A::(('a::type ⇒₀ nat) ⇒₀ 'b::comm_monoid_add) set)) ⟹ sum f {} ∈ hom_deg_set z A› 2. ‹⋀(x::'c::type) F::'c::type set. ⟦finite F; x ∉ F; (⋀i::'c::type. i ∈ F ⟹ (f::'c::type ⇒ ('a::type ⇒₀ nat) ⇒₀ 'b::comm_monoid_add) i ∈ hom_deg_set (z::nat) (A::(('a::type ⇒₀ nat) ⇒₀ 'b::comm_monoid_add) set)) ⟹ sum f F ∈ hom_deg_set z A; ⋀i::'c::type. i ∈ insert x F ⟹ f i ∈ hom_deg_set z A⟧ ⟹ sum f (insert x F) ∈ hom_deg_set z A›*) case empty (*‹?i ∈ {} ⟹ f ?i ∈ hom_deg_set z A›*) with assms(1) (*‹0 ∈ A›*) show "?case" (*goal: ‹sum f {} ∈ hom_deg_set z A›*) by (simp add: zero_in_hom_deg_set (*‹0 ∈ ?A ⟹ 0 ∈ hom_deg_set ?z ?A›*)) next (*goal: ‹⋀(x::'c) F::'c set. ⟦finite F; x ∉ F; (⋀i::'c. i ∈ F ⟹ (f::'c ⇒ ('a ⇒₀ nat) ⇒₀ 'b) i ∈ hom_deg_set (z::nat) (A::(('a ⇒₀ nat) ⇒₀ 'b) set)) ⟹ sum f F ∈ hom_deg_set z A; ⋀i::'c. i ∈ insert x F ⟹ f i ∈ hom_deg_set z A⟧ ⟹ sum f (insert x F) ∈ hom_deg_set z A›*) case (insert j I) (*‹finite I› ‹j ∉ I› ‹(⋀i. i ∈ I ⟹ f i ∈ hom_deg_set z A) ⟹ sum f I ∈ hom_deg_set z A› ‹?i ∈ insert j I ⟹ f ?i ∈ hom_deg_set z A›*) from insert.hyps(1,2) (*‹finite I› ‹j ∉ I›*) have "sum f (insert j I) = f j + sum f I" by simp also (*calculation: ‹sum f (insert j I) = f j + sum f I›*) from assms(2) (*‹⟦?a1.0 ∈ A; ?a2.0 ∈ A⟧ ⟹ ?a1.0 + ?a2.0 ∈ A›*) have "… ∈ hom_deg_set z A" proof (intro hom_deg_set_closed_plus (*‹⟦⋀a1 a2. ⟦a1 ∈ ?A; a2 ∈ ?A⟧ ⟹ a1 + a2 ∈ ?A; ?p ∈ hom_deg_set ?z ?A; ?q ∈ hom_deg_set ?z ?A⟧ ⟹ ?p + ?q ∈ hom_deg_set ?z ?A›*) insert.hyps (*‹finite I› ‹j ∉ I› ‹(⋀i. i ∈ I ⟹ f i ∈ hom_deg_set z A) ⟹ sum f I ∈ hom_deg_set z A›*)) (*goals: 1. ‹⋀a1 a2. ⟦⋀a1 a2. ⟦a1 ∈ A; a2 ∈ A⟧ ⟹ a1 + a2 ∈ A; a1 ∈ A; a2 ∈ A⟧ ⟹ a1 + a2 ∈ A› 2. ‹(⋀a1 a2. ⟦a1 ∈ A; a2 ∈ A⟧ ⟹ a1 + a2 ∈ A) ⟹ f j ∈ hom_deg_set z A› 3. ‹⋀i. ⟦⋀a1 a2. ⟦a1 ∈ A; a2 ∈ A⟧ ⟹ a1 + a2 ∈ A; i ∈ I⟧ ⟹ f i ∈ hom_deg_set z A›*) show "f j ∈ hom_deg_set z A" apply (rule insert.prems (*‹?i ∈ insert j I ⟹ f ?i ∈ hom_deg_set z A›*)) (*goal: ‹f j ∈ hom_deg_set z A›*) by simp next (*goals: 1. ‹⋀a1 a2. ⟦⋀a1 a2. ⟦a1 ∈ A; a2 ∈ A⟧ ⟹ a1 + a2 ∈ A; a1 ∈ A; a2 ∈ A⟧ ⟹ a1 + a2 ∈ A› 2. ‹⋀i. ⟦⋀a1 a2. ⟦a1 ∈ A; a2 ∈ A⟧ ⟹ a1 + a2 ∈ A; i ∈ I⟧ ⟹ f i ∈ hom_deg_set z A›*) fix i assume "i ∈ I" (*‹(i::'c) ∈ (I::'c set)›*) hence "i ∈ insert j I" by simp thus "f i ∈ hom_deg_set z A" by (rule insert.prems (*‹?i ∈ insert j I ⟹ f ?i ∈ hom_deg_set z A›*)) qed finally (*calculation: ‹sum f (insert j I) ∈ hom_deg_set z A›*) show "?case" (*goal: ‹sum f (insert j I) ∈ hom_deg_set z A›*) . qed lemma hom_deg_set_subset: "homogeneous_set A ⟹ hom_deg_set z A ⊆ A" by (auto dest: homogeneous_setD (*‹⟦homogeneous_set ?A; ?a ∈ ?A⟧ ⟹ hom_component ?a ?n ∈ ?A›*) simp: hom_deg_set_def (*‹hom_deg_set ?z ?A = (λa. hom_component a ?z) ` ?A›*)) lemma Polys_closed_hom_deg_set: assumes "A ⊆ P[X]" shows "hom_deg_set z A ⊆ P[X]" proof (standard) (*goal: ‹⋀x. x ∈ hom_deg_set z A ⟹ x ∈ P[X]›*) fix p assume "p ∈ hom_deg_set z A" (*‹(p::('a ⇒₀ nat) ⇒₀ 'b) ∈ hom_deg_set (z::nat) (A::(('a ⇒₀ nat) ⇒₀ 'b) set)›*) then obtain p' where "p' ∈ A" and p: "p = hom_component p' z" (*goal: ‹(⋀p'::('a ⇒₀ nat) ⇒₀ 'b. ⟦p' ∈ (A::(('a ⇒₀ nat) ⇒₀ 'b) set); (p::('a ⇒₀ nat) ⇒₀ 'b) = hom_component p' (z::nat)⟧ ⟹ thesis::bool) ⟹ thesis›*) unfolding hom_deg_set_def (*goal: ‹(⋀p'. ⟦p' ∈ A; p = hom_component p' z⟧ ⟹ thesis) ⟹ thesis›*) by standard from this(1) (*‹p' ∈ A›*) assms (*‹A ⊆ P[X]›*) have "p' ∈ P[X]" by standard have "keys p ⊆ keys p'" by (simp add: p (*‹p = hom_component p' z›*) keys_hom_component (*‹keys (hom_component ?p ?n) = {t ∈ keys ?p. deg_pm t = ?n}›*)) also (*calculation: ‹keys (p::('a ⇒₀ nat) ⇒₀ 'b) ⊆ keys (p'::('a ⇒₀ nat) ⇒₀ 'b)›*) from ‹p' ∈ P[X]› (*‹p' ∈ P[X]›*) have "… ⊆ .[X]" by (rule PolysD (*‹?p ∈ P[?X] ⟹ keys ?p ⊆ .[?X]› ‹?p ∈ P[?X] ⟹ indets ?p ⊆ ?X›*)) finally (*calculation: ‹keys (p::('a ⇒₀ nat) ⇒₀ 'b) ⊆ .[X::'a set]›*) show "p ∈ P[X]" by (rule PolysI (*‹keys ?p ⊆ .[?X] ⟹ ?p ∈ P[?X]›*)) qed lemma hom_deg_set_alt_homogeneous_set: assumes "homogeneous_set A" shows "hom_deg_set z A = {p ∈ A. homogeneous p ∧ (p = 0 ∨ poly_deg p = z)}" (is "?A = ?B") proof (standard) (*goals: 1. ‹hom_deg_set z A ⊆ {p ∈ A. homogeneous p ∧ (p = 0 ∨ poly_deg p = z)}› 2. ‹{p ∈ A. homogeneous p ∧ (p = 0 ∨ poly_deg p = z)} ⊆ hom_deg_set z A›*) show "?A ⊆ ?B" proof (standard) (*goal: ‹⋀x. x ∈ hom_deg_set z A ⟹ x ∈ {p ∈ A. homogeneous p ∧ (p = 0 ∨ poly_deg p = z)}›*) fix h assume "h ∈ ?A" (*‹(h::('a ⇒₀ nat) ⇒₀ 'b) ∈ hom_deg_set (z::nat) (A::(('a ⇒₀ nat) ⇒₀ 'b) set)›*) also (*calculation: ‹h ∈ hom_deg_set z A›*) from assms (*‹homogeneous_set A›*) have "… ⊆ A" by (rule hom_deg_set_subset (*‹homogeneous_set ?A ⟹ hom_deg_set ?z ?A ⊆ ?A›*)) finally (*calculation: ‹h ∈ A›*) show "h ∈ ?B" using ‹h ∈ ?A› (*‹(h::('a ⇒₀ nat) ⇒₀ 'b) ∈ hom_deg_set (z::nat) (A::(('a ⇒₀ nat) ⇒₀ 'b) set)›*) by (auto dest: hom_deg_setD (*‹?p ∈ hom_deg_set ?z ?A ⟹ homogeneous ?p› ‹⟦?p ∈ hom_deg_set ?z ?A; ?p ≠ 0⟧ ⟹ poly_deg ?p = ?z›*)) qed next (*goal: ‹{p ∈ A. homogeneous p ∧ (p = 0 ∨ poly_deg p = z)} ⊆ hom_deg_set z A›*) show "?B ⊆ ?A" proof (standard) (*goal: ‹⋀x. x ∈ {p ∈ A. homogeneous p ∧ (p = 0 ∨ poly_deg p = z)} ⟹ x ∈ hom_deg_set z A›*) fix h assume "h ∈ ?B" (*‹(h::('a ⇒₀ nat) ⇒₀ 'b) ∈ {p::('a ⇒₀ nat) ⇒₀ 'b ∈ A::(('a ⇒₀ nat) ⇒₀ 'b) set. homogeneous p ∧ (p = (0::('a ⇒₀ nat) ⇒₀ 'b) ∨ poly_deg p = (z::nat))}›*) hence "h ∈ A" and "homogeneous h" and "h = 0 ∨ poly_deg h = z" apply - (*goals: 1. ‹h ∈ {p ∈ A. homogeneous p ∧ (p = 0 ∨ poly_deg p = z)} ⟹ h ∈ A› 2. ‹h ∈ {p ∈ A. homogeneous p ∧ (p = 0 ∨ poly_deg p = z)} ⟹ homogeneous h› 3. ‹h ∈ {p ∈ A. homogeneous p ∧ (p = 0 ∨ poly_deg p = z)} ⟹ h = 0 ∨ poly_deg h = z› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) . from this(3) (*‹h = 0 ∨ poly_deg h = z›*) show "h ∈ ?A" proof (standard) (*goals: 1. ‹h = 0 ⟹ h ∈ hom_deg_set z A› 2. ‹poly_deg h = z ⟹ h ∈ hom_deg_set z A›*) assume "h = 0" (*‹(h::('a ⇒₀ nat) ⇒₀ 'b) = (0::('a ⇒₀ nat) ⇒₀ 'b)›*) with ‹h ∈ A› (*‹h ∈ A›*) have "0 ∈ A" by simp thus "?thesis" (*goal: ‹h ∈ hom_deg_set z A›*) unfolding ‹h = 0› (*goal: ‹0 ∈ hom_deg_set z A›*) by (rule zero_in_hom_deg_set (*‹0 ∈ ?A ⟹ 0 ∈ hom_deg_set ?z ?A›*)) next (*goal: ‹poly_deg h = z ⟹ h ∈ hom_deg_set z A›*) assume "poly_deg h = z" (*‹poly_deg (h::('a ⇒₀ nat) ⇒₀ 'b) = (z::nat)›*) with ‹homogeneous h› (*‹homogeneous h›*) have "h = hom_component h z" by (simp add: hom_component_of_homogeneous (*‹homogeneous ?p ⟹ hom_component ?p ?n = (?p when ?n = poly_deg ?p)›*)) with ‹h ∈ A› (*‹h ∈ A›*) show "?thesis" (*goal: ‹h ∈ hom_deg_set z A›*) unfolding hom_deg_set_def (*goal: ‹h ∈ (λa. hom_component a z) ` A›*) by (rule rev_image_eqI (*‹⟦?x ∈ ?A; ?b = ?f ?x⟧ ⟹ ?b ∈ ?f ` ?A›*)) qed qed qed lemma hom_deg_set_sum_list_listset: assumes "A = sum_list ` listset ss" shows "hom_deg_set z A = sum_list ` listset (map (hom_deg_set z) ss)" (is "?A = ?B") proof (standard) (*goals: 1. ‹hom_deg_set z A ⊆ sum_list ` listset (map (hom_deg_set z) ss)› 2. ‹sum_list ` listset (map (hom_deg_set z) ss) ⊆ hom_deg_set z A›*) show "?A ⊆ ?B" proof (standard) (*goal: ‹⋀x. x ∈ hom_deg_set z A ⟹ x ∈ sum_list ` listset (map (hom_deg_set z) ss)›*) fix h assume "h ∈ ?A" (*‹(h::('a ⇒₀ nat) ⇒₀ 'b) ∈ hom_deg_set (z::nat) (A::(('a ⇒₀ nat) ⇒₀ 'b) set)›*) then obtain a where "a ∈ A" and h: "h = hom_component a z" (*goal: ‹(⋀a. ⟦a ∈ A; h = hom_component a z⟧ ⟹ thesis) ⟹ thesis›*) unfolding hom_deg_set_def (*goal: ‹(⋀a. ⟦a ∈ A; h = hom_component a z⟧ ⟹ thesis) ⟹ thesis›*) by standard from this(1) (*‹a ∈ A›*) obtain qs where "qs ∈ listset ss" and a: "a = sum_list qs" (*goal: ‹(⋀qs. ⟦qs ∈ listset ss; a = sum_list qs⟧ ⟹ thesis) ⟹ thesis›*) unfolding assms (*goal: ‹(⋀qs. ⟦qs ∈ listset ss; a = sum_list qs⟧ ⟹ thesis) ⟹ thesis›*) by standard have "h = hom_component (sum_list qs) z" by (simp only: a (*‹a = sum_list qs›*) h (*‹h = hom_component a z›*)) also (*calculation: ‹h = hom_component (sum_list qs) z›*) have "… = sum_list (map (λq. hom_component q z) qs)" apply (induct qs) (*goals: 1. ‹hom_component (sum_list []) (z::nat) = (∑q::('a ⇒₀ nat) ⇒₀ 'b←[]. hom_component q z)› 2. ‹⋀(a::('a ⇒₀ nat) ⇒₀ 'b) qs::(('a ⇒₀ nat) ⇒₀ 'b) list. hom_component (sum_list qs) (z::nat) = (∑q::('a ⇒₀ nat) ⇒₀ 'b←qs. hom_component q z) ⟹ hom_component (sum_list (a # qs)) z = (∑q::('a ⇒₀ nat) ⇒₀ 'b←a # qs. hom_component q z)› discuss goal 1*) apply (simp add: hom_component_plus (*‹hom_component ((?p::(?'a ⇒₀ nat) ⇒₀ ?'b) + (?q::(?'a ⇒₀ nat) ⇒₀ ?'b)) (?n::nat) = hom_component ?p ?n + hom_component ?q ?n›*)) (*discuss goal 2*) apply (simp add: hom_component_plus (*‹hom_component ((?p::(?'a ⇒₀ nat) ⇒₀ ?'b) + (?q::(?'a ⇒₀ nat) ⇒₀ ?'b)) (?n::nat) = hom_component ?p ?n + hom_component ?q ?n›*)) (*proven 2 subgoals*) . also (*calculation: ‹h = (∑q←qs. hom_component q z)›*) have "… ∈ ?B" proof (rule imageI (*‹(?x::?'a) ∈ (?A::?'a set) ⟹ (?f::?'a ⇒ ?'b) ?x ∈ ?f ` ?A›*)) (*goal: ‹map (λq. hom_component q z) qs ∈ listset (map (hom_deg_set z) ss)›*) show "map (λq. hom_component q z) qs ∈ listset (map (hom_deg_set z) ss)" unfolding hom_deg_set_def (*goal: ‹map (λq::('a ⇒₀ nat) ⇒₀ 'b. hom_component q (z::nat)) (qs::(('a ⇒₀ nat) ⇒₀ 'b) list) ∈ listset (map ((`) (λa::('a ⇒₀ nat) ⇒₀ 'b. hom_component a z)) (ss::(('a ⇒₀ nat) ⇒₀ 'b) set list))›*) using ‹qs ∈ listset ss› (*‹qs ∈ listset ss›*) refl (*‹?t = ?t›*) by (rule listset_map_imageI (*‹⟦?ys' ∈ listset ?xs; ?ys = map ?f ?ys'⟧ ⟹ ?ys ∈ listset (map ((`) ?f) ?xs)›*)) qed finally (*calculation: ‹h ∈ sum_list ` listset (map (hom_deg_set z) ss)›*) show "h ∈ ?B" . qed next (*goal: ‹sum_list ` listset (map (hom_deg_set z) ss) ⊆ hom_deg_set z A›*) show "?B ⊆ ?A" proof (standard) (*goal: ‹⋀x. x ∈ sum_list ` listset (map (hom_deg_set z) ss) ⟹ x ∈ hom_deg_set z A›*) fix h assume "h ∈ ?B" (*‹(h::('a ⇒₀ nat) ⇒₀ 'b) ∈ sum_list ` listset (map (hom_deg_set (z::nat)) (ss::(('a ⇒₀ nat) ⇒₀ 'b) set list))›*) then obtain qs where "qs ∈ listset (map (hom_deg_set z) ss)" and h: "h = sum_list qs" (*goal: ‹(⋀qs::(('a ⇒₀ nat) ⇒₀ 'b) list. ⟦qs ∈ listset (map (hom_deg_set (z::nat)) (ss::(('a ⇒₀ nat) ⇒₀ 'b) set list)); (h::('a ⇒₀ nat) ⇒₀ 'b) = sum_list qs⟧ ⟹ thesis::bool) ⟹ thesis›*) by standard from this(1) (*‹qs ∈ listset (map (hom_deg_set z) ss)›*) obtain qs' where "qs' ∈ listset ss" and qs: "qs = map (λq. hom_component q z) qs'" (*goal: ‹(⋀qs'. ⟦qs' ∈ listset ss; qs = map (λq. hom_component q z) qs'⟧ ⟹ thesis) ⟹ thesis›*) unfolding hom_deg_set_def (*goal: ‹(⋀qs'. ⟦qs' ∈ listset ss; qs = map (λq. hom_component q z) qs'⟧ ⟹ thesis) ⟹ thesis›*) by (rule listset_map_imageE (*‹⟦?ys ∈ listset (map ((`) ?f) ?xs); ⋀ys'. ⟦ys' ∈ listset ?xs; ?ys = map ?f ys'⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) have "h = sum_list (map (λq. hom_component q z) qs')" by (simp only: h (*‹h = sum_list qs›*) qs (*‹qs = map (λq. hom_component q z) qs'›*)) also (*calculation: ‹(h::('a ⇒₀ nat) ⇒₀ 'b) = (∑q::('a ⇒₀ nat) ⇒₀ 'b←(qs'::(('a ⇒₀ nat) ⇒₀ 'b) list). hom_component q (z::nat))›*) have "… = hom_component (sum_list qs') z" apply (induct qs') (*goals: 1. ‹(∑q←[]. hom_component q z) = hom_component (sum_list []) z› 2. ‹⋀a qs'. (∑q←qs'. hom_component q z) = hom_component (sum_list qs') z ⟹ (∑q←a # qs'. hom_component q z) = hom_component (sum_list (a # qs')) z› discuss goal 1*) apply (simp add: hom_component_plus (*‹hom_component (?p + ?q) ?n = hom_component ?p ?n + hom_component ?q ?n›*)) (*discuss goal 2*) apply (simp add: hom_component_plus (*‹hom_component (?p + ?q) ?n = hom_component ?p ?n + hom_component ?q ?n›*)) (*proven 2 subgoals*) . finally (*calculation: ‹h = hom_component (sum_list qs') z›*) have "h = hom_component (sum_list qs') z" . moreover have "sum_list qs' ∈ A" unfolding assms (*goal: ‹sum_list qs' ∈ sum_list ` listset ss›*) using ‹qs' ∈ listset ss› (*‹qs' ∈ listset ss›*) by (rule imageI (*‹?x ∈ ?A ⟹ ?f ?x ∈ ?f ` ?A›*)) ultimately show "h ∈ ?A" unfolding hom_deg_set_def (*goal: ‹h ∈ (λa. hom_component a z) ` A›*) by (rule image_eqI (*‹⟦(?b::?'a) = (?f::?'b ⇒ ?'a) (?x::?'b); ?x ∈ (?A::?'b set)⟧ ⟹ ?b ∈ ?f ` ?A›*)) qed qed lemma direct_decomp_hom_deg_set: assumes "direct_decomp A ss" and "⋀s. s ∈ set ss ⟹ homogeneous_set s" shows "direct_decomp (hom_deg_set z A) (map (hom_deg_set z) ss)" proof (rule direct_decompI (*‹⟦inj_on sum_list (listset ?ss); sum_list ` listset ?ss = ?A⟧ ⟹ direct_decomp ?A ?ss›*)) (*goals: 1. ‹inj_on sum_list (listset (map (hom_deg_set (z::nat)) (ss::(('a ⇒₀ nat) ⇒₀ 'b) set list)))› 2. ‹sum_list ` listset (map (hom_deg_set (z::nat)) (ss::(('a ⇒₀ nat) ⇒₀ 'b) set list)) = hom_deg_set z (A::(('a ⇒₀ nat) ⇒₀ 'b) set)›*) from assms(1) (*‹direct_decomp A ss›*) have "sum_list ` listset ss = A" by (rule direct_decompD (*‹⟦direct_decomp (?A::?'a set) (?ss::?'a set list); (?qs::?'a list) ∈ listset ?ss⟧ ⟹ sum_list ?qs ∈ ?A› ‹direct_decomp (?A::?'a set) (?ss::?'a set list) ⟹ inj_on sum_list (listset ?ss)› ‹direct_decomp (?A::?'a set) (?ss::?'a set list) ⟹ sum_list ` listset ?ss = ?A›*)) from this[symmetric] (*‹A = sum_list ` listset ss›*) show "sum_list ` listset (map (hom_deg_set z) ss) = hom_deg_set z A" by (simp only: hom_deg_set_sum_list_listset (*‹(?A::((?'a ⇒₀ nat) ⇒₀ ?'b) set) = sum_list ` listset (?ss::((?'a ⇒₀ nat) ⇒₀ ?'b) set list) ⟹ hom_deg_set (?z::nat) ?A = sum_list ` listset (map (hom_deg_set ?z) ?ss)›*)) next (*goal: ‹inj_on sum_list (listset (map (hom_deg_set z) ss))›*) from assms(1) (*‹direct_decomp A ss›*) have "inj_on sum_list (listset ss)" by (rule direct_decompD (*‹⟦direct_decomp ?A ?ss; ?qs ∈ listset ?ss⟧ ⟹ sum_list ?qs ∈ ?A› ‹direct_decomp ?A ?ss ⟹ inj_on sum_list (listset ?ss)› ‹direct_decomp ?A ?ss ⟹ sum_list ` listset ?ss = ?A›*)) moreover have "listset (map (hom_deg_set z) ss) ⊆ listset ss" proof (rule listset_mono (*‹⟦length (?xs::?'a::type set list) = length (?ys::?'a::type set list); ⋀i::nat. i < length ?ys ⟹ ?xs ! i ⊆ ?ys ! i⟧ ⟹ listset ?xs ⊆ listset ?ys›*)) (*goals: 1. ‹length (map (hom_deg_set z) ss) = length ss› 2. ‹⋀i. i < length ss ⟹ map (hom_deg_set z) ss ! i ⊆ ss ! i›*) fix i assume "i < length ss" (*‹(i::nat) < length (ss::(('a ⇒₀ nat) ⇒₀ 'b) set list)›*) hence "map (hom_deg_set z) ss ! i = hom_deg_set z (ss ! i)" by simp also (*calculation: ‹map (hom_deg_set z) ss ! i = hom_deg_set z (ss ! i)›*) from ‹i < length ss› (*‹i < length ss›*) have "… ⊆ ss ! i" by (intro hom_deg_set_subset (*‹homogeneous_set ?A ⟹ hom_deg_set ?z ?A ⊆ ?A›*) assms( (*‹?s ∈ set ss ⟹ homogeneous_set ?s›*) 2) nth_mem (*‹?n < length ?xs ⟹ ?xs ! ?n ∈ set ?xs›*)) finally (*calculation: ‹map (hom_deg_set z) ss ! i ⊆ ss ! i›*) show "map (hom_deg_set z) ss ! i ⊆ ss ! i" . qed (simp) (*solved the remaining goal: ‹length (map (hom_deg_set (z::nat)) (ss::(('a::type ⇒₀ nat) ⇒₀ 'b::comm_monoid_add) set list)) = length ss›*) ultimately show "inj_on sum_list (listset (map (hom_deg_set z) ss))" by (rule inj_on_subset (*‹⟦inj_on ?f ?A; ?B ⊆ ?A⟧ ⟹ inj_on ?f ?B›*)) qed subsection ‹Interpreting Polynomial Rings as Vector Spaces over the Coefficient Field› text ‹There is no need to set up any further interpretation, since interpretation ‹phull› is exactly what we need.› lemma subspace_ideal: "phull.subspace (ideal (F::('b::comm_powerprod ⇒₀ 'a::field) set))" using ideal.span_zero (*‹0 ∈ ideal ?S›*) ideal.span_add (*‹⟦?x ∈ ideal ?S; ?y ∈ ideal ?S⟧ ⟹ ?x + ?y ∈ ideal ?S›*) proof (rule phull.subspaceI (*‹⟦0 ∈ ?S; ⋀x y. ⟦x ∈ ?S; y ∈ ?S⟧ ⟹ x + y ∈ ?S; ⋀c x. x ∈ ?S ⟹ c ⋅ x ∈ ?S⟧ ⟹ phull.subspace ?S›*)) (*goals: 1. ‹⋀(x::'b ⇒₀ 'a) y::'b ⇒₀ 'a. ⟦x ∈ ideal (F::('b ⇒₀ 'a) set); y ∈ ideal F⟧ ⟹ x ∈ ideal F› 2. ‹⋀(x::'b ⇒₀ 'a) y::'b ⇒₀ 'a. ⟦x ∈ ideal (F::('b ⇒₀ 'a) set); y ∈ ideal F⟧ ⟹ y ∈ ideal F› 3. ‹⋀(c::'a) x::'b ⇒₀ 'a. x ∈ ideal (F::('b ⇒₀ 'a) set) ⟹ c ⋅ x ∈ ideal F›*) fix c and p assume "p ∈ ideal F" (*‹(p::'b ⇒₀ 'a) ∈ ideal (F::('b ⇒₀ 'a) set)›*) thus "c ⋅ p ∈ ideal F" unfolding map_scale_eq_times (*goal: ‹monomial c 0 * p ∈ ideal F›*) by (rule ideal.span_scale (*‹?x ∈ ideal ?S ⟹ ?c * ?x ∈ ideal ?S›*)) qed lemma subspace_Polys: "phull.subspace (P[X]::(('x ⇒₀ nat) ⇒₀ 'a::field) set)" using zero_in_Polys (*‹0 ∈ P[?X]›*) Polys_closed_plus (*‹⟦?p ∈ P[?X]; ?q ∈ P[?X]⟧ ⟹ ?p + ?q ∈ P[?X]›*) Polys_closed_map_scale (*‹?p ∈ P[?X] ⟹ ?c ⋅ ?p ∈ P[?X]›*) apply (rule phull.subspaceI (*‹⟦0 ∈ ?S; ⋀x y. ⟦x ∈ ?S; y ∈ ?S⟧ ⟹ x + y ∈ ?S; ⋀c x. x ∈ ?S ⟹ c ⋅ x ∈ ?S⟧ ⟹ phull.subspace ?S›*)) (*goals: 1. ‹⋀x y. ⟦x ∈ P[X]; y ∈ P[X]⟧ ⟹ x ∈ P[X]› 2. ‹⋀x y. ⟦x ∈ P[X]; y ∈ P[X]⟧ ⟹ y ∈ P[X]› 3. ‹⋀c x. x ∈ P[X] ⟹ x ∈ P[X]› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) apply ((assumption)[1]) (*discuss goal 3*) . (*proven 3 subgoals*) lemma subspace_hom_deg_set: assumes "phull.subspace A" shows "phull.subspace (hom_deg_set z A)" (is "phull.subspace ?A") proof (rule phull.subspaceI (*‹⟦0 ∈ ?S; ⋀x y. ⟦x ∈ ?S; y ∈ ?S⟧ ⟹ x + y ∈ ?S; ⋀c x. x ∈ ?S ⟹ c ⋅ x ∈ ?S⟧ ⟹ phull.subspace ?S›*)) (*goals: 1. ‹0 ∈ hom_deg_set z A› 2. ‹⋀x y. ⟦x ∈ hom_deg_set z A; y ∈ hom_deg_set z A⟧ ⟹ x + y ∈ hom_deg_set z A› 3. ‹⋀c x. x ∈ hom_deg_set z A ⟹ c ⋅ x ∈ hom_deg_set z A›*) from assms (*‹phull.subspace (A::(('b::type ⇒₀ nat) ⇒₀ 'a::comm_ring_1) set)›*) have "0 ∈ A" by (rule phull.subspace_0 (*‹phull.subspace (?S::(?'b::type ⇒₀ ?'a::comm_ring_1) set) ⟹ (0::?'b::type ⇒₀ ?'a::comm_ring_1) ∈ ?S›*)) thus "0 ∈ ?A" by (rule zero_in_hom_deg_set (*‹0 ∈ ?A ⟹ 0 ∈ hom_deg_set ?z ?A›*)) next (*goals: 1. ‹⋀x y. ⟦x ∈ hom_deg_set z A; y ∈ hom_deg_set z A⟧ ⟹ x + y ∈ hom_deg_set z A› 2. ‹⋀c x. x ∈ hom_deg_set z A ⟹ c ⋅ x ∈ hom_deg_set z A›*) fix p and q assume "p ∈ ?A" and "q ∈ ?A" (*‹(p::('b ⇒₀ nat) ⇒₀ 'a) ∈ hom_deg_set (z::nat) (A::(('b ⇒₀ nat) ⇒₀ 'a) set)› ‹(q::('b ⇒₀ nat) ⇒₀ 'a) ∈ hom_deg_set (z::nat) (A::(('b ⇒₀ nat) ⇒₀ 'a) set)›*) with phull.subspace_add (*‹⟦phull.subspace ?S; ?x ∈ ?S; ?y ∈ ?S⟧ ⟹ ?x + ?y ∈ ?S›*) show "p + q ∈ ?A" apply (rule hom_deg_set_closed_plus (*‹⟦⋀a1 a2. ⟦a1 ∈ ?A; a2 ∈ ?A⟧ ⟹ a1 + a2 ∈ ?A; ?p ∈ hom_deg_set ?z ?A; ?q ∈ hom_deg_set ?z ?A⟧ ⟹ ?p + ?q ∈ hom_deg_set ?z ?A›*)) (*goals: 1. ‹⋀(a1::('b ⇒₀ nat) ⇒₀ 'a) a2::('b ⇒₀ nat) ⇒₀ 'a. ⟦a1 ∈ (A::(('b ⇒₀ nat) ⇒₀ 'a) set); a2 ∈ A⟧ ⟹ phull.subspace A› 2. ‹⋀(a1::('b ⇒₀ nat) ⇒₀ 'a) a2::('b ⇒₀ nat) ⇒₀ 'a. ⟦a1 ∈ (A::(('b ⇒₀ nat) ⇒₀ 'a) set); a2 ∈ A⟧ ⟹ a1 ∈ A› 3. ‹⋀(a1::('b ⇒₀ nat) ⇒₀ 'a) a2::('b ⇒₀ nat) ⇒₀ 'a. ⟦a1 ∈ (A::(('b ⇒₀ nat) ⇒₀ 'a) set); a2 ∈ A⟧ ⟹ a2 ∈ A› discuss goal 1*) apply (rule assms (*‹phull.subspace A›*)) (*discuss goal 2*) apply ((assumption)[1]) (*discuss goal 3*) . (*proven 3 subgoals*) next (*goal: ‹⋀(c::'a) x::('b ⇒₀ nat) ⇒₀ 'a. x ∈ hom_deg_set (z::nat) (A::(('b ⇒₀ nat) ⇒₀ 'a) set) ⟹ c ⋅ x ∈ hom_deg_set z A›*) fix c and p assume "p ∈ ?A" (*‹(p::('b ⇒₀ nat) ⇒₀ 'a) ∈ hom_deg_set (z::nat) (A::(('b ⇒₀ nat) ⇒₀ 'a) set)›*) with phull.subspace_scale (*‹⟦phull.subspace ?S; ?x ∈ ?S⟧ ⟹ ?c ⋅ ?x ∈ ?S›*) show "c ⋅ p ∈ ?A" apply (rule hom_deg_set_closed_scalar (*‹⟦⋀a. a ∈ ?A ⟹ ?c ⋅ a ∈ ?A; ?p ∈ hom_deg_set ?z ?A⟧ ⟹ ?c ⋅ ?p ∈ hom_deg_set ?z ?A›*)) (*goals: 1. ‹⋀a::('b ⇒₀ nat) ⇒₀ 'a. a ∈ (A::(('b ⇒₀ nat) ⇒₀ 'a) set) ⟹ phull.subspace A› 2. ‹⋀a::('b ⇒₀ nat) ⇒₀ 'a. a ∈ (A::(('b ⇒₀ nat) ⇒₀ 'a) set) ⟹ a ∈ A› discuss goal 1*) apply (rule assms (*‹phull.subspace A›*)) (*discuss goal 2*) . (*proven 2 subgoals*) qed lemma hom_deg_set_Polys_eq_span: "hom_deg_set z P[X] = phull.span (monomial (1::'a::field) ` deg_sect X z)" (is "?A = ?B") proof (standard) (*goals: 1. ‹hom_deg_set z P[X] ⊆ phull (monomial 1 ` deg_sect X z)› 2. ‹phull (monomial 1 ` deg_sect X z) ⊆ hom_deg_set z P[X]›*) show "?A ⊆ ?B" proof (standard) (*goal: ‹⋀x. x ∈ hom_deg_set z P[X] ⟹ x ∈ phull (monomial 1 ` deg_sect X z)›*) fix p assume "p ∈ ?A" (*‹(p::('b ⇒₀ nat) ⇒₀ 'a) ∈ hom_deg_set (z::nat) P[X::'b set]›*) also (*calculation: ‹p ∈ hom_deg_set z P[X]›*) from this (*‹p ∈ hom_deg_set z P[X]›*) have "… = {p ∈ P[X]. homogeneous p ∧ (p = 0 ∨ poly_deg p = z)}" by (simp only: hom_deg_set_alt_homogeneous_set[OF homogeneous_set_Polys] (*‹hom_deg_set ?z P[?X1] = {p ∈ P[?X1]. homogeneous p ∧ (p = 0 ∨ poly_deg p = ?z)}›*)) finally (*calculation: ‹p ∈ {p ∈ P[X]. homogeneous p ∧ (p = 0 ∨ poly_deg p = z)}›*) have "p ∈ P[X]" and "homogeneous p" and "p ≠ 0 ⟹ poly_deg p = z" apply - (*goals: 1. ‹p ∈ {p ∈ P[X]. homogeneous p ∧ (p = 0 ∨ poly_deg p = z)} ⟹ p ∈ P[X]› 2. ‹p ∈ {p ∈ P[X]. homogeneous p ∧ (p = 0 ∨ poly_deg p = z)} ⟹ homogeneous p› 3. ‹⟦p ≠ 0; p ∈ {p ∈ P[X]. homogeneous p ∧ (p = 0 ∨ poly_deg p = z)}⟧ ⟹ poly_deg p = z› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) . thus "p ∈ ?B" proof (induct p rule: poly_mapping_plus_induct (*‹⟦?P 0; ⋀p c t. ⟦c ≠ 0; t ∉ keys p; ?P p⟧ ⟹ ?P (monomial c t + p)⟧ ⟹ ?P ?p›*)) (*goals: 1. ‹⟦0 ∈ P[X]; homogeneous 0; 0 ≠ 0 ⟹ poly_deg 0 = z⟧ ⟹ 0 ∈ phull (monomial 1 ` deg_sect X z)› 2. ‹⋀p c t. ⟦c ≠ 0; t ∉ keys p; ⟦p ∈ P[X]; homogeneous p; p ≠ 0 ⟹ poly_deg p = z⟧ ⟹ p ∈ phull (monomial 1 ` deg_sect X z); monomial c t + p ∈ P[X]; homogeneous (monomial c t + p); monomial c t + p ≠ 0 ⟹ poly_deg (monomial c t + p) = z⟧ ⟹ monomial c t + p ∈ phull (monomial 1 ` deg_sect X z)›*) case 1 (*‹0 ∈ P[X]› ‹homogeneous 0› ‹(0::('b ⇒₀ nat) ⇒₀ 'a) ≠ (0::('b ⇒₀ nat) ⇒₀ 'a) ⟹ poly_deg (0::('b ⇒₀ nat) ⇒₀ 'a) = (z::nat)›*) from phull.span_zero (*‹0 ∈ phull ?S›*) show "?case" (*goal: ‹0 ∈ phull (monomial 1 ` deg_sect X z)›*) . next (*goal: ‹⋀p c t. ⟦c ≠ 0; t ∉ keys p; ⟦p ∈ P[X]; homogeneous p; p ≠ 0 ⟹ poly_deg p = z⟧ ⟹ p ∈ phull (monomial 1 ` deg_sect X z); monomial c t + p ∈ P[X]; homogeneous (monomial c t + p); monomial c t + p ≠ 0 ⟹ poly_deg (monomial c t + p) = z⟧ ⟹ monomial c t + p ∈ phull (monomial 1 ` deg_sect X z)›*) case (2 p c t) (*‹(c::'a::field) ≠ (0::'a::field)› ‹t ∉ keys p› ‹⟦p ∈ P[X]; homogeneous p; p ≠ 0 ⟹ poly_deg p = z⟧ ⟹ p ∈ phull (monomial 1 ` deg_sect X z)› ‹monomial (c::'a) (t::'b ⇒₀ nat) + (p::('b ⇒₀ nat) ⇒₀ 'a) ∈ P[X::'b set]› ‹homogeneous (monomial (c::'a::field) (t::'b::countable ⇒₀ nat) + (p::('b::countable ⇒₀ nat) ⇒₀ 'a::field))› ‹monomial c t + p ≠ 0 ⟹ poly_deg (monomial c t + p) = z›*) let ?m = "monomial c t" from "2"(1) (*‹c ≠ 0›*) have "t ∈ keys ?m" by simp hence "t ∈ keys (?m + p)" using "2"(2) (*‹t ∉ keys p›*) by (rule in_keys_plusI1 (*‹⟦?t ∈ keys ?p; ?t ∉ keys ?q⟧ ⟹ ?t ∈ keys (?p + ?q)›*)) hence "?m + p ≠ 0" by auto hence "poly_deg (monomial c t + p) = z" by (rule 2 (*‹c ≠ 0› ‹t ∉ keys p› ‹⟦p ∈ P[X]; homogeneous p; p ≠ 0 ⟹ poly_deg p = z⟧ ⟹ p ∈ phull (monomial 1 ` deg_sect X z)› ‹monomial c t + p ∈ P[X]› ‹homogeneous (monomial c t + p)› ‹monomial c t + p ≠ 0 ⟹ poly_deg (monomial c t + p) = z›*)) from "2"(4) (*‹monomial c t + p ∈ P[X]›*) have "keys (?m + p) ⊆ .[X]" by (rule PolysD (*‹?p ∈ P[?X] ⟹ keys ?p ⊆ .[?X]› ‹?p ∈ P[?X] ⟹ indets ?p ⊆ ?X›*)) with ‹t ∈ keys (?m + p)› (*‹t ∈ keys (monomial c t + p)›*) have "t ∈ .[X]" by standard hence "?m ∈ P[X]" by (rule Polys_closed_monomial (*‹?t ∈ .[?X] ⟹ monomial ?c ?t ∈ P[?X]›*)) have "t ∈ deg_sect X z" proof (rule deg_sectI (*‹⟦?t ∈ .[?X]; deg_pm ?t = ?d⟧ ⟹ ?t ∈ deg_sect ?X ?d›*)) (*goals: 1. ‹t ∈ .[X]› 2. ‹deg_pm t = z›*) from "2"(5) (*‹homogeneous (monomial c t + p)›*) ‹t ∈ keys (?m + p)› (*‹(t::'b::countable ⇒₀ nat) ∈ keys (monomial (c::'a::field) t + (p::('b::countable ⇒₀ nat) ⇒₀ 'a::field))›*) have "deg_pm t = poly_deg (?m + p)" by (rule homogeneousD_poly_deg (*‹⟦homogeneous ?p; ?t ∈ keys ?p⟧ ⟹ deg_pm ?t = poly_deg ?p›*)) also (*calculation: ‹deg_pm (t::'b ⇒₀ nat) = poly_deg (monomial (c::'a) t + (p::('b ⇒₀ nat) ⇒₀ 'a))›*) have "… = z" by fact finally (*calculation: ‹deg_pm (t::'b ⇒₀ nat) = (z::nat)›*) show "deg_pm t = z" . qed (fact) (*solved the remaining goal: ‹(t::'b::countable ⇒₀ nat) ∈ .[X::'b::countable set]›*) hence "monomial 1 t ∈ monomial 1 ` deg_sect X z" by (rule imageI (*‹?x ∈ ?A ⟹ ?f ?x ∈ ?f ` ?A›*)) hence "monomial 1 t ∈ ?B" by (rule phull.span_base (*‹?a ∈ ?S ⟹ ?a ∈ phull ?S›*)) hence "c ⋅ monomial 1 t ∈ ?B" by (rule phull.span_scale (*‹?x ∈ phull ?S ⟹ ?c ⋅ ?x ∈ phull ?S›*)) hence "?m ∈ ?B" by simp moreover have "p ∈ ?B" proof (rule 2 (*‹c ≠ 0› ‹t ∉ keys p› ‹⟦p ∈ P[X]; homogeneous p; p ≠ 0 ⟹ poly_deg p = z⟧ ⟹ p ∈ phull (monomial 1 ` deg_sect X z)› ‹monomial c t + p ∈ P[X]› ‹homogeneous (monomial c t + p)› ‹monomial c t + p ≠ 0 ⟹ poly_deg (monomial c t + p) = z›*)) (*goals: 1. ‹p ∈ P[X]› 2. ‹homogeneous p› 3. ‹p ≠ 0 ⟹ poly_deg p = z›*) from "2"(4) (*‹monomial c t + p ∈ P[X]›*) ‹?m ∈ P[X]› (*‹monomial c t ∈ P[X]›*) have "(?m + p) - ?m ∈ P[X]" by (rule Polys_closed_minus (*‹⟦?p ∈ P[?X]; ?q ∈ P[?X]⟧ ⟹ ?p - ?q ∈ P[?X]›*)) thus "p ∈ P[X]" by simp next (*goals: 1. ‹homogeneous p› 2. ‹p ≠ 0 ⟹ poly_deg p = z›*) have 1: "deg_pm s = z" if "s ∈ keys p" for s proof (-) (*goal: ‹deg_pm s = z›*) from that (*‹s ∈ keys p›*) "2"(2) (*‹t ∉ keys p›*) have "s ≠ t" by blast hence "s ∉ keys ?m" by simp with that (*‹s ∈ keys p›*) have "s ∈ keys (?m + p)" by (rule in_keys_plusI2 (*‹⟦?t ∈ keys ?q; ?t ∉ keys ?p⟧ ⟹ ?t ∈ keys (?p + ?q)›*)) with "2"(5) (*‹homogeneous (monomial c t + p)›*) have "deg_pm s = poly_deg (?m + p)" by (rule homogeneousD_poly_deg (*‹⟦homogeneous ?p; ?t ∈ keys ?p⟧ ⟹ deg_pm ?t = poly_deg ?p›*)) also (*calculation: ‹deg_pm (s::'b ⇒₀ nat) = poly_deg (monomial (c::'a) (t::'b ⇒₀ nat) + (p::('b ⇒₀ nat) ⇒₀ 'a))›*) have "… = z" by fact finally (*calculation: ‹deg_pm s = z›*) show "?thesis" (*goal: ‹deg_pm s = z›*) . qed show "homogeneous p" apply (rule homogeneousI (*‹(⋀s t. ⟦s ∈ keys ?p; t ∈ keys ?p⟧ ⟹ deg_pm s = deg_pm t) ⟹ homogeneous ?p›*)) (*goal: ‹homogeneous p›*) by (simp add: 1 (*‹?s1 ∈ keys p ⟹ deg_pm ?s1 = z›*)) assume "p ≠ 0" (*‹(p::('b ⇒₀ nat) ⇒₀ 'a) ≠ (0::('b ⇒₀ nat) ⇒₀ 'a)›*) show "poly_deg p = z" proof (rule antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹poly_deg p ≤ z› 2. ‹z ≤ poly_deg p›*) show "poly_deg p ≤ z" apply (rule poly_deg_leI (*‹(⋀t. t ∈ keys ?p ⟹ deg_pm t ≤ ?d) ⟹ poly_deg ?p ≤ ?d›*)) (*goal: ‹poly_deg p ≤ z›*) by (simp add: 1 (*‹?s1 ∈ keys p ⟹ deg_pm ?s1 = z›*)) next (*goal: ‹z ≤ poly_deg p›*) from ‹p ≠ 0› (*‹p ≠ 0›*) have "keys p ≠ {}" by simp then obtain s where "s ∈ keys p" (*goal: ‹(⋀s. s ∈ keys p ⟹ thesis) ⟹ thesis›*) by blast hence "z = deg_pm s" by (simp only: 1 (*‹?s1 ∈ keys p ⟹ deg_pm ?s1 = z›*)) also (*calculation: ‹z = deg_pm s›*) from ‹s ∈ keys p› (*‹s ∈ keys p›*) have "… ≤ poly_deg p" by (rule poly_deg_max_keys (*‹?t ∈ keys ?p ⟹ deg_pm ?t ≤ poly_deg ?p›*)) finally (*calculation: ‹(z::nat) ≤ poly_deg (p::('b ⇒₀ nat) ⇒₀ 'a)›*) show "z ≤ poly_deg p" . qed qed ultimately show "?case" (*goal: ‹monomial c t + p ∈ phull (monomial 1 ` deg_sect X z)›*) by (rule phull.span_add (*‹⟦?x ∈ phull ?S; ?y ∈ phull ?S⟧ ⟹ ?x + ?y ∈ phull ?S›*)) qed qed next (*goal: ‹phull (monomial (1::'a) ` deg_sect (X::'b set) (z::nat)) ⊆ hom_deg_set z P[X]›*) show "?B ⊆ ?A" proof (standard) (*goal: ‹⋀x. x ∈ phull (monomial 1 ` deg_sect X z) ⟹ x ∈ hom_deg_set z P[X]›*) fix p assume "p ∈ ?B" (*‹(p::('b ⇒₀ nat) ⇒₀ 'a) ∈ phull (monomial (1::'a) ` deg_sect (X::'b set) (z::nat))›*) then obtain M and u where "M ⊆ monomial 1 ` deg_sect X z" and "finite M" and p: "p = (∑m∈M. u m ⋅ m)" (*goal: ‹(⋀M u. ⟦M ⊆ monomial 1 ` deg_sect X z; finite M; p = (∑m∈M. u m ⋅ m)⟧ ⟹ thesis) ⟹ thesis›*) by (auto simp: phull.span_explicit (*‹phull ?b = {∑a∈t. r a ⋅ a |t r. finite t ∧ t ⊆ ?b}›*)) from this(1) (*‹M ⊆ monomial 1 ` deg_sect X z›*) obtain T where "T ⊆ deg_sect X z" and M: "M = monomial 1 ` T" and inj: "inj_on (monomial (1::'a)) T" (*goal: ‹(⋀T::('b::countable ⇒₀ nat) set. ⟦T ⊆ deg_sect (X::'b::countable set) (z::nat); (M::(('b::countable ⇒₀ nat) ⇒₀ 'a::field) set) = monomial (1::'a::field) ` T; inj_on (monomial (1::'a::field)) T⟧ ⟹ thesis::bool) ⟹ thesis›*) by (rule subset_imageE_inj (*‹⟦(?B::?'a set) ⊆ (?f::?'b ⇒ ?'a) ` (?A::?'b set); ⋀C::?'b set. ⟦C ⊆ ?A; ?B = ?f ` C; inj_on ?f C⟧ ⟹ ?thesis::bool⟧ ⟹ ?thesis›*)) define c where "c = (λt. u (monomial 1 t))" from inj (*‹inj_on (monomial 1) T›*) have "p = (∑t∈T. monomial (c t) t)" by (simp add: p (*‹p = (∑m∈M. u m ⋅ m)›*) M (*‹M = monomial 1 ` T›*) sum.reindex (*‹inj_on ?h ?A ⟹ sum ?g (?h ` ?A) = sum (?g ∘ ?h) ?A›*) c_def (*‹c = (λt. u (monomial 1 t))›*)) also (*calculation: ‹p = (∑t∈T. monomial (c t) t)›*) have "… ∈ ?A" proof (intro hom_deg_set_closed_sum (*‹⟦0 ∈ ?A; ⋀a1 a2. ⟦a1 ∈ ?A; a2 ∈ ?A⟧ ⟹ a1 + a2 ∈ ?A; ⋀i. i ∈ ?I ⟹ ?f i ∈ hom_deg_set ?z ?A⟧ ⟹ sum ?f ?I ∈ hom_deg_set ?z ?A›*) zero_in_Polys (*‹0 ∈ P[?X]›*) Polys_closed_plus (*‹⟦?p ∈ P[?X]; ?q ∈ P[?X]⟧ ⟹ ?p + ?q ∈ P[?X]›*)) (*goals: 1. ‹⋀(a1::('b ⇒₀ nat) ⇒₀ 'a) a2::('b ⇒₀ nat) ⇒₀ 'a. ⟦a1 ∈ P[X::'b set]; a2 ∈ P[X]⟧ ⟹ a1 ∈ P[X]› 2. ‹⋀(a1::('b ⇒₀ nat) ⇒₀ 'a) a2::('b ⇒₀ nat) ⇒₀ 'a. ⟦a1 ∈ P[X::'b set]; a2 ∈ P[X]⟧ ⟹ a2 ∈ P[X]› 3. ‹⋀i::'b ⇒₀ nat. i ∈ (T::('b ⇒₀ nat) set) ⟹ monomial ((c::('b ⇒₀ nat) ⇒ 'a) i) i ∈ hom_deg_set (z::nat) P[X::'b set]›*) fix t assume "t ∈ T" (*‹(t::'b ⇒₀ nat) ∈ (T::('b ⇒₀ nat) set)›*) hence "t ∈ deg_sect X z" using ‹T ⊆ deg_sect X z› (*‹T ⊆ deg_sect X z›*) by standard hence "t ∈ .[X]" and eq: "deg_pm t = z" apply - (*goals: 1. ‹t ∈ deg_sect X z ⟹ t ∈ .[X]› 2. ‹t ∈ deg_sect X z ⟹ deg_pm t = z› discuss goal 1*) apply (rule deg_sectD (*‹?t ∈ deg_sect ?X ?d ⟹ ?t ∈ .[?X]› ‹?t ∈ deg_sect ?X ?d ⟹ deg_pm ?t = ?d›*)) (*top goal: ‹t ∈ deg_sect X z ⟹ t ∈ .[X]› and 1 goal remains*) apply ((msorry)[1]) (*discuss goal 2*) apply ((msorry)[1]) (*proven 2 subgoals*) . from this(1) (*‹(t::'b::countable ⇒₀ nat) ∈ .[X::'b::countable set]›*) have "monomial (c t) t ∈ P[X]" (is "?m ∈ _") by (rule Polys_closed_monomial (*‹(?t::?'a ⇒₀ nat) ∈ .[?X::?'a set] ⟹ monomial (?c::?'b) ?t ∈ P[?X]›*)) thus "?m ∈ ?A" by (simp add: hom_deg_set_alt_homogeneous_set[OF homogeneous_set_Polys] (*‹hom_deg_set (?z::nat) P[?X1::?'a::type set] = {p::(?'a::type ⇒₀ nat) ⇒₀ ?'b::zero ∈ P[?X1]. homogeneous p ∧ (p = (0::(?'a::type ⇒₀ nat) ⇒₀ ?'b::zero) ∨ poly_deg p = ?z)}›*) poly_deg_monomial (*‹poly_deg (monomial (?c::?'c::zero) (?t::?'b::type ⇒₀ ?'a::add_linorder)) = (if ?c = (0::?'c::zero) then 0::?'a::add_linorder else deg_pm ?t)›*) monomial_0_iff (*‹(monomial (?c::?'b::zero) (?t::?'a::type) = (0::?'a::type ⇒₀ ?'b::zero)) = (?c = (0::?'b::zero))›*) eq (*‹deg_pm (t::'b::countable ⇒₀ nat) = (z::nat)›*)) qed finally (*calculation: ‹(p::('b ⇒₀ nat) ⇒₀ 'a) ∈ hom_deg_set (z::nat) P[X::'b set]›*) show "p ∈ ?A" . qed qed subsection ‹(Projective) Hilbert Function› interpretation phull: vector_space map_scale apply standard (*goal: ‹vector_space (⋅)›*) subgoal for by (fact map_scale_distrib_left (*‹(?k::?'b) ⋅ ((?s::?'a ⇒₀ ?'b) + (?t::?'a ⇒₀ ?'b)) = ?k ⋅ ?s + ?k ⋅ ?t›*)) subgoal for by (fact map_scale_distrib_right (*‹(?k + ?l) ⋅ ?t = ?k ⋅ ?t + ?l ⋅ ?t›*)) subgoal for by (fact map_scale_assoc (*‹?c ⋅ ?d ⋅ ?t = (?c * ?d) ⋅ ?t›*)) subgoal for by (fact map_scale_one_left (*‹1 ⋅ ?t = ?t›*)) . definition Hilbert_fun :: "(('x ⇒₀ nat) ⇒₀ 'a::field) set ⇒ nat ⇒ nat" where "Hilbert_fun A z = phull.dim (hom_deg_set z A)" lemma Hilbert_fun_empty [simp]: "Hilbert_fun {} = 0" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹Hilbert_fun {} = 0›*) by (simp add: Hilbert_fun_def (*‹Hilbert_fun ?A ?z = phull.dim (hom_deg_set ?z ?A)›*) hom_deg_set_def (*‹hom_deg_set ?z ?A = (λa. hom_component a ?z) ` ?A›*)) lemma Hilbert_fun_zero [simp]: "Hilbert_fun {0} = 0" apply (rule ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹Hilbert_fun {0} = 0›*) by (simp add: Hilbert_fun_def (*‹Hilbert_fun ?A ?z = phull.dim (hom_deg_set ?z ?A)›*) hom_deg_set_def (*‹hom_deg_set ?z ?A = (λa. hom_component a ?z) ` ?A›*)) lemma Hilbert_fun_direct_decomp: assumes "finite X" and "A ⊆ P[X]" and "direct_decomp (A::(('x::countable ⇒₀ nat) ⇒₀ 'a::field) set) ps" and "⋀s. s ∈ set ps ⟹ homogeneous_set s" and "⋀s. s ∈ set ps ⟹ phull.subspace s" shows "Hilbert_fun A z = (∑p∈set ps. Hilbert_fun p z)" proof (-) (*goal: ‹Hilbert_fun A z = (∑p∈set ps. Hilbert_fun p z)›*) from assms(3,4) (*‹direct_decomp (A::(('x ⇒₀ nat) ⇒₀ 'a) set) (ps::(('x ⇒₀ nat) ⇒₀ 'a) set list)› ‹?s ∈ set ps ⟹ homogeneous_set ?s›*) have dd: "direct_decomp (hom_deg_set z A) (map (hom_deg_set z) ps)" by (rule direct_decomp_hom_deg_set (*‹⟦direct_decomp ?A ?ss; ⋀s. s ∈ set ?ss ⟹ homogeneous_set s⟧ ⟹ direct_decomp (hom_deg_set ?z ?A) (map (hom_deg_set ?z) ?ss)›*)) have "Hilbert_fun A z = phull.dim (hom_deg_set z A)" by (fact Hilbert_fun_def (*‹Hilbert_fun ?A ?z = phull.dim (hom_deg_set ?z ?A)›*)) also (*calculation: ‹Hilbert_fun (A::(('x ⇒₀ nat) ⇒₀ 'a) set) (z::nat) = phull.dim (hom_deg_set z A)›*) from dd (*‹direct_decomp (hom_deg_set z A) (map (hom_deg_set z) ps)›*) have "… = sum phull.dim (set (map (hom_deg_set z) ps))" proof (rule phull.dim_direct_decomp (*‹⟦direct_decomp ?A ?ss; finite ?B; ?A ⊆ phull ?B; ⋀s. s ∈ set ?ss ⟹ phull.subspace s⟧ ⟹ phull.dim ?A = sum phull.dim (set ?ss)›*)) (*goals: 1. ‹finite ?B› 2. ‹hom_deg_set z A ⊆ phull ?B› 3. ‹⋀s. s ∈ set (map (hom_deg_set z) ps) ⟹ phull.subspace s›*) from assms(1) (*‹finite X›*) have "finite (deg_sect X z)" by (rule finite_deg_sect (*‹finite ?X ⟹ finite (deg_sect ?X ?d)›*)) thus "finite (monomial (1::'a) ` deg_sect X z)" by (rule finite_imageI (*‹finite ?F ⟹ finite (?h ` ?F)›*)) next (*goals: 1. ‹hom_deg_set z A ⊆ phull (monomial 1 ` deg_sect X z)› 2. ‹⋀s. s ∈ set (map (hom_deg_set z) ps) ⟹ phull.subspace s›*) from assms(2) (*‹A ⊆ P[X]›*) have "hom_deg_set z A ⊆ hom_deg_set z P[X]" unfolding hom_deg_set_def (*goal: ‹(λa::('x ⇒₀ nat) ⇒₀ 'a. hom_component a (z::nat)) ` (A::(('x ⇒₀ nat) ⇒₀ 'a) set) ⊆ (λa::('x ⇒₀ nat) ⇒₀ 'a. hom_component a z) ` P[X::'x set]›*) by (rule image_mono (*‹(?A::?'a set) ⊆ (?B::?'a set) ⟹ (?f::?'a ⇒ ?'b) ` ?A ⊆ ?f ` ?B›*)) thus "hom_deg_set z A ⊆ phull.span (monomial 1 ` deg_sect X z)" by (simp only: hom_deg_set_Polys_eq_span (*‹hom_deg_set ?z P[?X] = phull (monomial 1 ` deg_sect ?X ?z)›*)) next (*goal: ‹⋀s. s ∈ set (map (hom_deg_set z) ps) ⟹ phull.subspace s›*) fix s assume "s ∈ set (map (hom_deg_set z) ps)" (*‹(s::(('x ⇒₀ nat) ⇒₀ 'a) set) ∈ set (map (hom_deg_set (z::nat)) (ps::(('x ⇒₀ nat) ⇒₀ 'a) set list))›*) then obtain s' where "s' ∈ set ps" and s: "s = hom_deg_set z s'" (*goal: ‹(⋀s'. ⟦s' ∈ set ps; s = hom_deg_set z s'⟧ ⟹ thesis) ⟹ thesis›*) unfolding set_map (*goal: ‹(⋀s'. ⟦s' ∈ set ps; s = hom_deg_set z s'⟧ ⟹ thesis) ⟹ thesis›*) by standard from this(1) (*‹s' ∈ set ps›*) have "phull.subspace s'" by (rule assms( (*‹?s ∈ set ps ⟹ phull.subspace ?s›*) 5)) thus "phull.subspace s" unfolding s (*goal: ‹phull.subspace (hom_deg_set z s')›*) by (rule subspace_hom_deg_set (*‹phull.subspace ?A ⟹ phull.subspace (hom_deg_set ?z ?A)›*)) qed also (*calculation: ‹Hilbert_fun A z = sum phull.dim (set (map (hom_deg_set z) ps))›*) have "… = sum (phull.dim ∘ hom_deg_set z) (set ps)" unfolding set_map (*goal: ‹sum phull.dim (hom_deg_set (z::nat) ` set (ps::(('x ⇒₀ nat) ⇒₀ 'a) set list)) = sum (phull.dim ∘ hom_deg_set z) (set ps)›*) using finite_set (*‹finite (set ?xs)›*) proof (rule sum.reindex_nontrivial (*‹⟦finite ?A; ⋀x y. ⟦x ∈ ?A; y ∈ ?A; x ≠ y; ?h x = ?h y⟧ ⟹ ?g (?h x) = 0⟧ ⟹ sum ?g (?h ` ?A) = sum (?g ∘ ?h) ?A›*)) (*goal: ‹⋀(x::(('x ⇒₀ nat) ⇒₀ 'a) set) y::(('x ⇒₀ nat) ⇒₀ 'a) set. ⟦x ∈ set (ps::(('x ⇒₀ nat) ⇒₀ 'a) set list); y ∈ set ps; x ≠ y; hom_deg_set (z::nat) x = hom_deg_set z y⟧ ⟹ phull.dim (hom_deg_set z x) = (0::nat)›*) fix s1 and s2 note dd (*‹direct_decomp (hom_deg_set z A) (map (hom_deg_set z) ps)›*) moreover assume "s1 ∈ set ps" and "s2 ∈ set ps" and "s1 ≠ s2" (*‹(s1::(('x ⇒₀ nat) ⇒₀ 'a) set) ∈ set (ps::(('x ⇒₀ nat) ⇒₀ 'a) set list)› ‹(s2::(('x ⇒₀ nat) ⇒₀ 'a) set) ∈ set (ps::(('x ⇒₀ nat) ⇒₀ 'a) set list)› ‹(s1::(('x ⇒₀ nat) ⇒₀ 'a) set) ≠ (s2::(('x ⇒₀ nat) ⇒₀ 'a) set)›*) moreover have "0 ∈ hom_deg_set z s" if "s ∈ set ps" for s proof (rule zero_in_hom_deg_set (*‹0 ∈ ?A ⟹ 0 ∈ hom_deg_set ?z ?A›*)) (*goal: ‹0 ∈ s›*) from that (*‹s ∈ set ps›*) have "phull.subspace s" by (rule assms( (*‹?s ∈ set ps ⟹ phull.subspace ?s›*) 5)) thus "0 ∈ s" by (rule phull.subspace_0 (*‹phull.subspace ?S ⟹ 0 ∈ ?S›*)) qed ultimately have "hom_deg_set z s1 ∩ hom_deg_set z s2 = {0}" by (rule direct_decomp_map_Int_zero (*‹⟦direct_decomp ?A (map ?f ?ss); ?s1.0 ∈ set ?ss; ?s2.0 ∈ set ?ss; ?s1.0 ≠ ?s2.0; ⋀s. s ∈ set ?ss ⟹ 0 ∈ ?f s⟧ ⟹ ?f ?s1.0 ∩ ?f ?s2.0 = {0}›*)) moreover assume "hom_deg_set z s1 = hom_deg_set z s2" (*‹hom_deg_set (z::nat) (s1::(('x ⇒₀ nat) ⇒₀ 'a) set) = hom_deg_set z (s2::(('x ⇒₀ nat) ⇒₀ 'a) set)›*) ultimately show "phull.dim (hom_deg_set z s1) = 0" by simp qed also (*calculation: ‹Hilbert_fun A z = sum (phull.dim ∘ hom_deg_set z) (set ps)›*) have "… = (∑p∈set ps. Hilbert_fun p z)" by (simp only: o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*) Hilbert_fun_def (*‹Hilbert_fun ?A ?z = phull.dim (hom_deg_set ?z ?A)›*)) finally (*calculation: ‹Hilbert_fun A z = (∑p∈set ps. Hilbert_fun p z)›*) show "?thesis" (*goal: ‹Hilbert_fun (A::(('x ⇒₀ nat) ⇒₀ 'a) set) (z::nat) = (∑p::(('x ⇒₀ nat) ⇒₀ 'a) set∈set (ps::(('x ⇒₀ nat) ⇒₀ 'a) set list). Hilbert_fun p z)›*) . qed context pm_powerprod begin lemma image_lt_hom_deg_set: assumes "homogeneous_set A" shows "lpp ` (hom_deg_set z A - {0}) = {t ∈ lpp ` (A - {0}). deg_pm t = z}" (is "?B = ?A") proof (intro set_eqI (*‹(⋀x. (x ∈ ?A) = (x ∈ ?B)) ⟹ ?A = ?B›*) iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*)) (*goals: 1. ‹⋀x. x ∈ lpp ` (hom_deg_set z A - {0}) ⟹ x ∈ {t ∈ lpp ` (A - {0}). deg_pm t = z}› 2. ‹⋀x. x ∈ {t ∈ lpp ` (A - {0}). deg_pm t = z} ⟹ x ∈ lpp ` (hom_deg_set z A - {0})›*) fix t assume "t ∈ ?A" (*‹(t::'x ⇒₀ nat) ∈ {t::'x ⇒₀ nat ∈ lpp ` ((A::(('x ⇒₀ nat) ⇒₀ 'a) set) - {0::('x ⇒₀ nat) ⇒₀ 'a}). deg_pm t = (z::nat)}›*) hence "t ∈ lpp ` (A - {0})" and deg_t[symmetric]: "deg_pm t = z" apply - (*goals: 1. ‹t ∈ {t ∈ lpp ` (A - {0}). deg_pm t = z} ⟹ t ∈ lpp ` (A - {0})› 2. ‹t ∈ {t ∈ lpp ` (A - {0}). deg_pm t = z} ⟹ deg_pm t = z› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . from this(1) (*‹(t::'x ⇒₀ nat) ∈ lpp ` ((A::(('x ⇒₀ nat) ⇒₀ 'a) set) - {0::('x ⇒₀ nat) ⇒₀ 'a})›*) obtain p where "p ∈ A - {0}" and t: "t = lpp p" (*goal: ‹(⋀p. ⟦p ∈ A - {0}; t = lpp p⟧ ⟹ thesis) ⟹ thesis›*) by standard from this(1) (*‹(p::('x ⇒₀ nat) ⇒₀ 'a) ∈ (A::(('x ⇒₀ nat) ⇒₀ 'a) set) - {0::('x ⇒₀ nat) ⇒₀ 'a}›*) have "p ∈ A" and "p ≠ 0" apply - (*goals: 1. ‹p ∈ A - {0} ⟹ p ∈ A› 2. ‹p ∈ A - {0} ⟹ p ≠ 0› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . from this(1) (*‹p ∈ A›*) have 1: "hom_component p z ∈ hom_deg_set z A" (is "?p ∈ _") unfolding hom_deg_set_def (*goal: ‹hom_component p z ∈ (λa. hom_component a z) ` A›*) by (rule imageI (*‹(?x::?'a) ∈ (?A::?'a set) ⟹ (?f::?'a ⇒ ?'b) ?x ∈ ?f ` ?A›*)) from ‹p ≠ 0› (*‹p ≠ 0›*) have "?p ≠ 0" and "lpp ?p = t" unfolding t deg_t (*goals: 1. ‹hom_component p (deg_pm (lpp p)) ≠ 0› 2. ‹lpp (hom_component p (deg_pm (lpp p))) = lpp p›*) apply - (*goals: 1. ‹p ≠ 0 ⟹ hom_component p (deg_pm (lpp p)) ≠ 0› 2. ‹p ≠ 0 ⟹ lpp (hom_component p (deg_pm (lpp p))) = lpp p› discuss goal 1*) apply (rule hom_component_lpp (*‹?p ≠ 0 ⟹ hom_component ?p (deg_pm (lpp ?p)) ≠ 0› ‹?p ≠ 0 ⟹ lpp (hom_component ?p (deg_pm (lpp ?p))) = lpp ?p›*)) (*top goal: ‹p ≠ 0 ⟹ hom_component p (deg_pm (lpp p)) ≠ 0› and 1 goal remains*) apply ((msorry)[1]) (*discuss goal 2*) apply ((msorry)[1]) (*proven 2 subgoals*) . note this(2)[symmetric] (*‹t = lpp (hom_component p z)›*) moreover from "1" (*‹hom_component p z ∈ hom_deg_set z A›*) ‹?p ≠ 0› (*‹hom_component (p::('x ⇒₀ nat) ⇒₀ 'a) (z::nat) ≠ (0::('x ⇒₀ nat) ⇒₀ 'a)›*) have "?p ∈ hom_deg_set z A - {0}" by simp ultimately show "t ∈ ?B" by (rule image_eqI (*‹⟦?b = ?f ?x; ?x ∈ ?A⟧ ⟹ ?b ∈ ?f ` ?A›*)) next (*goal: ‹⋀x. x ∈ lpp ` (hom_deg_set z A - {0}) ⟹ x ∈ {t ∈ lpp ` (A - {0}). deg_pm t = z}›*) fix t assume "t ∈ ?B" (*‹(t::'x ⇒₀ nat) ∈ lpp ` (hom_deg_set (z::nat) (A::(('x ⇒₀ nat) ⇒₀ 'a) set) - {0::('x ⇒₀ nat) ⇒₀ 'a})›*) then obtain p where "p ∈ hom_deg_set z A - {0}" and t: "t = lpp p" (*goal: ‹(⋀p::('x::{countable,linorder} ⇒₀ nat) ⇒₀ 'a::zero. ⟦p ∈ hom_deg_set (z::nat) (A::(('x::{countable,linorder} ⇒₀ nat) ⇒₀ 'a::zero) set) - {0::('x::{countable,linorder} ⇒₀ nat) ⇒₀ 'a::zero}; (t::'x::{countable,linorder} ⇒₀ nat) = lpp p⟧ ⟹ thesis::bool) ⟹ thesis›*) by standard from this(1) (*‹p ∈ hom_deg_set z A - {0}›*) have "p ∈ hom_deg_set z A" and "p ≠ 0" apply - (*goals: 1. ‹p ∈ hom_deg_set z A - {0} ⟹ p ∈ hom_deg_set z A› 2. ‹p ∈ hom_deg_set z A - {0} ⟹ p ≠ 0› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . with assms (*‹homogeneous_set A›*) have "p ∈ A" and "homogeneous p" and "poly_deg p = z" apply - (*goals: 1. ‹⟦homogeneous_set A; p ∈ hom_deg_set z A; p ≠ 0⟧ ⟹ p ∈ A› 2. ‹⟦homogeneous_set A; p ∈ hom_deg_set z A; p ≠ 0⟧ ⟹ homogeneous p› 3. ‹⟦homogeneous_set A; p ∈ hom_deg_set z A; p ≠ 0⟧ ⟹ poly_deg p = z› discuss goal 1*) apply (simp add: hom_deg_set_alt_homogeneous_set (*‹homogeneous_set (?A::((?'a ⇒₀ nat) ⇒₀ ?'b) set) ⟹ hom_deg_set (?z::nat) ?A = {p::(?'a ⇒₀ nat) ⇒₀ ?'b ∈ ?A. homogeneous p ∧ (p = (0::(?'a ⇒₀ nat) ⇒₀ ?'b) ∨ poly_deg p = ?z)}›*)) (*discuss goal 2*) apply (simp add: hom_deg_set_alt_homogeneous_set (*‹homogeneous_set ?A ⟹ hom_deg_set ?z ?A = {p ∈ ?A. homogeneous p ∧ (p = 0 ∨ poly_deg p = ?z)}›*)) (*discuss goal 3*) apply (simp add: hom_deg_set_alt_homogeneous_set (*‹homogeneous_set ?A ⟹ hom_deg_set ?z ?A = {p ∈ ?A. homogeneous p ∧ (p = 0 ∨ poly_deg p = ?z)}›*)) (*proven 3 subgoals*) . from this(1) (*‹p ∈ A›*) ‹p ≠ 0› (*‹p ≠ 0›*) have "p ∈ A - {0}" by simp hence 1: "t ∈ lpp ` (A - {0})" using t (*‹t = lpp p›*) by (rule rev_image_eqI (*‹⟦?x ∈ ?A; ?b = ?f ?x⟧ ⟹ ?b ∈ ?f ` ?A›*)) from ‹p ≠ 0› (*‹p ≠ 0›*) have "t ∈ keys p" unfolding t (*goal: ‹lpp p ∈ keys p›*) by (rule punit.lt_in_keys (*‹?p ≠ 0 ⟹ lpp ?p ∈ keys ?p›*)) with ‹homogeneous p› (*‹homogeneous p›*) have "deg_pm t = poly_deg p" by (rule homogeneousD_poly_deg (*‹⟦homogeneous (?p::(?'a ⇒₀ nat) ⇒₀ ?'b); (?t::?'a ⇒₀ nat) ∈ keys ?p⟧ ⟹ deg_pm ?t = poly_deg ?p›*)) with "1" (*‹(t::'x ⇒₀ nat) ∈ lpp ` ((A::(('x ⇒₀ nat) ⇒₀ 'a) set) - {0::('x ⇒₀ nat) ⇒₀ 'a})›*) show "t ∈ ?A" by (simp add: ‹poly_deg p = z›) qed lemma Hilbert_fun_alt: assumes "finite X" and "A ⊆ P[X]" and "phull.subspace A" shows "Hilbert_fun A z = card (lpp ` (hom_deg_set z A - {0}))" (is "_ = card ?A") proof (-) (*goal: ‹Hilbert_fun A z = card (lpp ` (hom_deg_set z A - {0}))›*) have "?A ⊆ lpp ` (hom_deg_set z A - {0})" by simp then obtain B where sub: "B ⊆ hom_deg_set z A - {0}" and eq1: "?A = lpp ` B" and inj: "inj_on lpp B" (*goal: ‹(⋀B. ⟦B ⊆ hom_deg_set z A - {0}; lpp ` (hom_deg_set z A - {0}) = lpp ` B; inj_on lpp B⟧ ⟹ thesis) ⟹ thesis›*) by (rule subset_imageE_inj (*‹⟦?B ⊆ ?f ` ?A; ⋀C. ⟦C ⊆ ?A; ?B = ?f ` C; inj_on ?f C⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) have "Hilbert_fun A z = phull.dim (hom_deg_set z A)" by (fact Hilbert_fun_def (*‹Hilbert_fun ?A ?z = phull.dim (hom_deg_set ?z ?A)›*)) also (*calculation: ‹Hilbert_fun (A::(('x ⇒₀ nat) ⇒₀ 'a) set) (z::nat) = phull.dim (hom_deg_set z A)›*) have "… = card B" proof (rule phull.dim_eq_card (*‹⟦phull ?B = phull ?V; phull.independent ?B⟧ ⟹ phull.dim ?V = card ?B›*)) (*goals: 1. ‹phull B = phull (hom_deg_set z A)› 2. ‹phull.independent B›*) show "phull.span B = phull.span (hom_deg_set z A)" proof (standard) (*goals: 1. ‹phull B ⊆ phull (hom_deg_set z A)› 2. ‹phull (hom_deg_set z A) ⊆ phull B›*) from sub (*‹B ⊆ hom_deg_set z A - {0}›*) have "B ⊆ hom_deg_set z A" by blast thus "phull.span B ⊆ phull.span (hom_deg_set z A)" by (rule phull.span_mono (*‹?A ⊆ ?B ⟹ phull ?A ⊆ phull ?B›*)) next (*goal: ‹phull (hom_deg_set z A) ⊆ phull B›*) from assms(3) (*‹phull.subspace (A::(('x ⇒₀ nat) ⇒₀ 'a) set)›*) have "phull.subspace (hom_deg_set z A)" by (rule subspace_hom_deg_set (*‹phull.subspace ?A ⟹ phull.subspace (hom_deg_set ?z ?A)›*)) hence "phull.span (hom_deg_set z A) = hom_deg_set z A" by (simp only: phull.span_eq_iff (*‹(phull ?s = ?s) = phull.subspace ?s›*)) also (*calculation: ‹phull (hom_deg_set z A) = hom_deg_set z A›*) have "… ⊆ phull.span B" proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹¬ hom_deg_set z A ⊆ phull B ⟹ False›*) assume "¬ hom_deg_set z A ⊆ phull.span B" (*‹¬ hom_deg_set (z::nat) (A::(('x ⇒₀ nat) ⇒₀ 'a) set) ⊆ phull (B::(('x ⇒₀ nat) ⇒₀ 'a) set)›*) then obtain p0 where "p0 ∈ hom_deg_set z A - phull.span B" (is "_ ∈ ?B") (*goal: ‹(⋀p0. p0 ∈ hom_deg_set z A - phull B ⟹ thesis) ⟹ thesis›*) by blast note assms(1) (*‹finite X›*) this (*‹p0 ∈ hom_deg_set z A - phull B›*) moreover have "?B ⊆ P[X]" proof (rule subset_trans (*‹⟦?A ⊆ ?B; ?B ⊆ ?C⟧ ⟹ ?A ⊆ ?C›*)) (*goals: 1. ‹hom_deg_set z A - phull B ⊆ ?B› 2. ‹?B ⊆ P[X]›*) from assms(2) (*‹A ⊆ P[X]›*) show "hom_deg_set z A ⊆ P[X]" by (rule Polys_closed_hom_deg_set (*‹?A ⊆ P[?X] ⟹ hom_deg_set ?z ?A ⊆ P[?X]›*)) qed (blast) (*solved the remaining goal: ‹hom_deg_set z A - phull B ⊆ hom_deg_set z A›*) ultimately obtain p where "p ∈ ?B" and p_min: "⋀q. punit.ord_strict_p q p ⟹ q ∉ ?B" (*goal: ‹(⋀p. ⟦p ∈ hom_deg_set z A - phull B; ⋀q. punit.ord_strict_p q p ⟹ q ∉ hom_deg_set z A - phull B⟧ ⟹ thesis) ⟹ thesis›*) apply (rule punit.ord_p_minimum_dgrad_p_set[OF dickson_grading_varnum, where m=0, simplified dgrad_p_set_varnum] (*‹⟦finite ?X1; ?x ∈ ?Q; ?Q ⊆ P[?X1]; ⋀q. ⟦q ∈ ?Q; ⋀y. punit.ord_strict_p y q ⟹ y ∉ ?Q⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) (*goal: ‹(⋀p::('x ⇒₀ nat) ⇒₀ 'a. ⟦p ∈ hom_deg_set (z::nat) (A::(('x ⇒₀ nat) ⇒₀ 'a) set) - phull (B::(('x ⇒₀ nat) ⇒₀ 'a) set); ⋀q::('x ⇒₀ nat) ⇒₀ 'a. punit.ord_strict_p q p ⟹ q ∉ hom_deg_set z A - phull B⟧ ⟹ thesis::bool) ⟹ thesis›*) by blast from this(1) (*‹p ∈ hom_deg_set z A - phull B›*) have "p ∈ hom_deg_set z A" and "p ∉ phull.span B" apply - (*goals: 1. ‹p ∈ hom_deg_set z A - phull B ⟹ p ∈ hom_deg_set z A› 2. ‹p ∈ hom_deg_set z A - phull B ⟹ p ∉ phull B› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . from phull.span_zero (*‹0 ∈ phull ?S›*) this(2) (*‹p ∉ phull B›*) have "p ≠ 0" by blast with ‹p ∈ hom_deg_set z A› (*‹p ∈ hom_deg_set z A›*) have "p ∈ hom_deg_set z A - {0}" by simp hence "lpp p ∈ lpp ` (hom_deg_set z A - {0})" by (rule imageI (*‹?x ∈ ?A ⟹ ?f ?x ∈ ?f ` ?A›*)) also (*calculation: ‹lpp p ∈ lpp ` (hom_deg_set z A - {0})›*) have "… = lpp ` B" by (simp only: eq1 (*‹lpp ` (hom_deg_set z A - {0}) = lpp ` B›*)) finally (*calculation: ‹lpp p ∈ lpp ` B›*) obtain b where "b ∈ B" and eq2: "lpp p = lpp b" (*goal: ‹(⋀b::('x::{countable,linorder} ⇒₀ nat) ⇒₀ 'a::field. ⟦b ∈ (B::(('x::{countable,linorder} ⇒₀ nat) ⇒₀ 'a::field) set); lpp (p::('x::{countable,linorder} ⇒₀ nat) ⇒₀ 'a::field) = lpp b⟧ ⟹ thesis::bool) ⟹ thesis›*) by standard from this(1) (*‹(b::('x::{countable,linorder} ⇒₀ nat) ⇒₀ 'a::field) ∈ (B::(('x::{countable,linorder} ⇒₀ nat) ⇒₀ 'a::field) set)›*) sub (*‹B ⊆ hom_deg_set z A - {0}›*) have "b ∈ hom_deg_set z A - {0}" by standard hence "b ∈ hom_deg_set z A" and "b ≠ 0" apply - (*goals: 1. ‹(b::('x ⇒₀ nat) ⇒₀ 'a) ∈ hom_deg_set (z::nat) (A::(('x ⇒₀ nat) ⇒₀ 'a) set) - {0::('x ⇒₀ nat) ⇒₀ 'a} ⟹ b ∈ hom_deg_set z A› 2. ‹(b::('x ⇒₀ nat) ⇒₀ 'a) ∈ hom_deg_set (z::nat) (A::(('x ⇒₀ nat) ⇒₀ 'a) set) - {0::('x ⇒₀ nat) ⇒₀ 'a} ⟹ b ≠ (0::('x ⇒₀ nat) ⇒₀ 'a)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . from this(2) (*‹b ≠ 0›*) have lcb: "punit.lc b ≠ 0" by (rule punit.lc_not_0 (*‹?p ≠ 0 ⟹ lcf ?p ≠ 0›*)) from ‹p ≠ 0› (*‹p ≠ 0›*) have lcp: "punit.lc p ≠ 0" by (rule punit.lc_not_0 (*‹?p ≠ 0 ⟹ lcf ?p ≠ 0›*)) from ‹b ∈ B› (*‹b ∈ B›*) have "b ∈ phull.span B" by (rule phull.span_base (*‹?a ∈ ?S ⟹ ?a ∈ phull ?S›*)) hence "(punit.lc p / punit.lc b) ⋅ b ∈ phull.span B" (is "?b ∈ _") by (rule phull.span_scale (*‹?x ∈ phull ?S ⟹ ?c ⋅ ?x ∈ phull ?S›*)) with ‹p ∉ phull.span B› (*‹(p::('x ⇒₀ nat) ⇒₀ 'a) ∉ phull (B::(('x ⇒₀ nat) ⇒₀ 'a) set)›*) have "p - ?b ≠ 0" by auto moreover from lcb (*‹lcf b ≠ 0›*) lcp (*‹lcf p ≠ 0›*) ‹b ≠ 0› (*‹b ≠ 0›*) have "lpp ?b = lpp p" by (simp add: punit.map_scale_eq_monom_mult (*‹?c ⋅ ?p = local.punit.monom_mult ?c 0 ?p›*) punit.lt_monom_mult (*‹⟦?c ≠ 0; ?p ≠ 0⟧ ⟹ lpp (local.punit.monom_mult ?c ?t ?p) = local.punit.splus ?t (lpp ?p)›*) eq2 (*‹lpp p = lpp b›*)) moreover from lcb (*‹lcf b ≠ 0›*) have "punit.lc ?b = punit.lc p" by (simp add: punit.map_scale_eq_monom_mult (*‹?c ⋅ ?p = local.punit.monom_mult ?c 0 ?p›*)) ultimately have "lpp (p - ?b) ≺ lpp p" by (rule punit.lt_minus_lessI (*‹⟦?p - ?q ≠ 0; lpp ?q = lpp ?p; lcf ?q = lcf ?p⟧ ⟹ lpp (?p - ?q) ≺ lpp ?p›*)) hence "punit.ord_strict_p (p - ?b) p" by (rule punit.lt_ord_p (*‹lpp (?p::('x ⇒₀ nat) ⇒₀ ?'b) ≺ lpp (?q::('x ⇒₀ nat) ⇒₀ ?'b) ⟹ punit.ord_strict_p ?p ?q›*)) hence "p - ?b ∉ ?B" by (rule p_min (*‹punit.ord_strict_p ?q5 p ⟹ ?q5 ∉ hom_deg_set z A - phull B›*)) hence "p - ?b ∉ hom_deg_set z A ∨ p - ?b ∈ phull.span B" by simp thus False proof (standard) (*goals: 1. ‹p - (lcf p / lcf b) ⋅ b ∉ hom_deg_set z A ⟹ False› 2. ‹p - (lcf p / lcf b) ⋅ b ∈ phull B ⟹ False›*) assume "*": "p - ?b ∉ hom_deg_set z A" (*‹(p::('x ⇒₀ nat) ⇒₀ 'a) - (lcf p / lcf (b::('x ⇒₀ nat) ⇒₀ 'a)) ⋅ b ∉ hom_deg_set (z::nat) (A::(('x ⇒₀ nat) ⇒₀ 'a) set)›*) from phull.subspace_scale (*‹⟦phull.subspace ?S; ?x ∈ ?S⟧ ⟹ ?c ⋅ ?x ∈ ?S›*) have "?b ∈ hom_deg_set z A" proof (rule hom_deg_set_closed_scalar (*‹⟦⋀a::(?'b ⇒₀ nat) ⇒₀ ?'a. a ∈ (?A::((?'b ⇒₀ nat) ⇒₀ ?'a) set) ⟹ (?c::?'a) ⋅ a ∈ ?A; (?p::(?'b ⇒₀ nat) ⇒₀ ?'a) ∈ hom_deg_set (?z::nat) ?A⟧ ⟹ ?c ⋅ ?p ∈ hom_deg_set ?z ?A›*)) (*goals: 1. ‹⋀a. a ∈ A ⟹ phull.subspace A› 2. ‹⋀a. a ∈ A ⟹ a ∈ A› 3. ‹b ∈ hom_deg_set z A›*) show "phull.subspace A" by fact next (*goals: 1. ‹⋀a. a ∈ A ⟹ a ∈ A› 2. ‹b ∈ hom_deg_set z A›*) show "b ∈ hom_deg_set z A" by fact qed with phull.subspace_diff (*‹⟦phull.subspace ?S; ?x ∈ ?S; ?y ∈ ?S⟧ ⟹ ?x - ?y ∈ ?S›*) ‹p ∈ hom_deg_set z A› (*‹p ∈ hom_deg_set z A›*) have "p - ?b ∈ hom_deg_set z A" apply (rule hom_deg_set_closed_minus (*‹⟦⋀a1 a2. ⟦a1 ∈ ?A; a2 ∈ ?A⟧ ⟹ a1 - a2 ∈ ?A; ?p ∈ hom_deg_set ?z ?A; ?q ∈ hom_deg_set ?z ?A⟧ ⟹ ?p - ?q ∈ hom_deg_set ?z ?A›*)) (*goals: 1. ‹⋀a1 a2. ⟦a1 ∈ A; a2 ∈ A⟧ ⟹ phull.subspace A› 2. ‹⋀a1 a2. ⟦a1 ∈ A; a2 ∈ A⟧ ⟹ a1 ∈ A› 3. ‹⋀a1 a2. ⟦a1 ∈ A; a2 ∈ A⟧ ⟹ a2 ∈ A› discuss goal 1*) apply (rule assms( (*‹phull.subspace A›*) 3)) (*discuss goal 2*) apply ((assumption)[1]) (*discuss goal 3*) . (*proven 3 subgoals*) with "*" (*‹p - (lcf p / lcf b) ⋅ b ∉ hom_deg_set z A›*) show "?thesis" (*goal: ‹False›*) by standard next (*goal: ‹p - (lcf p / lcf b) ⋅ b ∈ phull B ⟹ False›*) assume "p - ?b ∈ phull.span B" (*‹(p::('x ⇒₀ nat) ⇒₀ 'a) - (lcf p / lcf (b::('x ⇒₀ nat) ⇒₀ 'a)) ⋅ b ∈ phull (B::(('x ⇒₀ nat) ⇒₀ 'a) set)›*) hence "p - ?b + ?b ∈ phull.span B" using ‹?b ∈ phull.span B› (*‹(lcf p / lcf b) ⋅ b ∈ phull B›*) by (rule phull.span_add (*‹⟦?x ∈ phull ?S; ?y ∈ phull ?S⟧ ⟹ ?x + ?y ∈ phull ?S›*)) hence "p ∈ phull.span B" by simp with ‹p ∉ phull.span B› (*‹p ∉ phull B›*) show "?thesis" (*goal: ‹False›*) by standard qed qed finally (*calculation: ‹phull (hom_deg_set z A) ⊆ phull B›*) show "phull.span (hom_deg_set z A) ⊆ phull.span B" . qed next (*goal: ‹phull.independent B›*) show "phull.independent B" proof (standard) (*goal: ‹phull.dependent B ⟹ False›*) assume "phull.dependent B" (*‹phull.dependent (B::(('x ⇒₀ nat) ⇒₀ 'a) set)›*) then obtain B' and u and b' where "finite B'" and "B' ⊆ B" and "(∑b∈B'. u b ⋅ b) = 0" and "b' ∈ B'" and "u b' ≠ 0" (*goal: ‹(⋀B' u b'. ⟦finite B'; B' ⊆ B; (∑b∈B'. u b ⋅ b) = 0; b' ∈ B'; u b' ≠ 0⟧ ⟹ thesis) ⟹ thesis›*) unfolding phull.dependent_explicit (*goal: ‹(⋀B' u b'. ⟦finite B'; B' ⊆ B; (∑b∈B'. u b ⋅ b) = 0; b' ∈ B'; u b' ≠ 0⟧ ⟹ thesis) ⟹ thesis›*) by blast define B0 where "B0 = {b ∈ B'. u b ≠ 0}" have "B0 ⊆ B'" by (simp add: B0_def (*‹(B0::(('x ⇒₀ nat) ⇒₀ 'a) set) = {b::('x ⇒₀ nat) ⇒₀ 'a ∈ B'::(('x ⇒₀ nat) ⇒₀ 'a) set. (u::(('x ⇒₀ nat) ⇒₀ 'a) ⇒ 'a) b ≠ (0::'a)}›*)) with ‹finite B'› (*‹finite B'›*) have "(∑b∈B0. u b ⋅ b) = (∑b∈B'. u b ⋅ b)" apply (rule sum.mono_neutral_left (*‹⟦finite ?T; ?S ⊆ ?T; ∀i∈?T - ?S. ?g i = 0⟧ ⟹ sum ?g ?S = sum ?g ?T›*)) (*goal: ‹(∑b∈B0. u b ⋅ b) = (∑b∈B'. u b ⋅ b)›*) by (simp add: B0_def (*‹B0 = {b ∈ B'. u b ≠ 0}›*)) also (*calculation: ‹(∑b∈B0. u b ⋅ b) = (∑b∈B'. u b ⋅ b)›*) have "… = 0" by fact finally (*calculation: ‹(∑b::('x ⇒₀ nat) ⇒₀ 'a∈(B0::(('x ⇒₀ nat) ⇒₀ 'a) set). (u::(('x ⇒₀ nat) ⇒₀ 'a) ⇒ 'a) b ⋅ b) = (0::('x ⇒₀ nat) ⇒₀ 'a)›*) have eq: "(∑b∈B0. u b ⋅ b) = 0" . define t where "t = ordered_powerprod_lin.Max (lpp ` B0)" from ‹b' ∈ B'› (*‹(b'::('x::{countable,linorder} ⇒₀ nat) ⇒₀ 'a::field) ∈ (B'::(('x::{countable,linorder} ⇒₀ nat) ⇒₀ 'a::field) set)›*) ‹u b' ≠ 0› (*‹u b' ≠ 0›*) have "b' ∈ B0" by (simp add: B0_def (*‹B0 = {b ∈ B'. u b ≠ 0}›*)) hence "lpp b' ∈ lpp ` B0" by (rule imageI (*‹(?x::?'a) ∈ (?A::?'a set) ⟹ (?f::?'a ⇒ ?'b) ?x ∈ ?f ` ?A›*)) hence "lpp ` B0 ≠ {}" by blast from ‹B0 ⊆ B'› (*‹B0 ⊆ B'›*) ‹finite B'› (*‹finite B'›*) have "finite B0" by (rule finite_subset (*‹⟦?A ⊆ ?B; finite ?B⟧ ⟹ finite ?A›*)) hence "finite (lpp ` B0)" by (rule finite_imageI (*‹finite ?F ⟹ finite (?h ` ?F)›*)) hence "t ∈ lpp ` B0" unfolding t_def (*goal: ‹ordered_powerprod_lin.Max (lpp ` (B0::(('x ⇒₀ nat) ⇒₀ 'a) set)) ∈ lpp ` B0›*) using ‹lpp ` B0 ≠ {}› (*‹lpp ` B0 ≠ {}›*) by (rule ordered_powerprod_lin.Max_in (*‹⟦finite ?A; ?A ≠ {}⟧ ⟹ ordered_powerprod_lin.Max ?A ∈ ?A›*)) then obtain b0 where "b0 ∈ B0" and t: "t = lpp b0" (*goal: ‹(⋀b0. ⟦b0 ∈ B0; t = lpp b0⟧ ⟹ thesis) ⟹ thesis›*) by standard note this(1) (*‹(b0::('x ⇒₀ nat) ⇒₀ 'a) ∈ (B0::(('x ⇒₀ nat) ⇒₀ 'a) set)›*) moreover from ‹B0 ⊆ B'› (*‹B0 ⊆ B'›*) ‹B' ⊆ B› (*‹B' ⊆ B›*) have "B0 ⊆ B" by (rule subset_trans (*‹⟦?A ⊆ ?B; ?B ⊆ ?C⟧ ⟹ ?A ⊆ ?C›*)) also (*calculation: ‹b0 ∈ B›*) have "… ⊆ hom_deg_set z A - {0}" by fact finally (*calculation: ‹b0 ∈ hom_deg_set z A - {0}›*) have "b0 ∈ hom_deg_set z A - {0}" . hence "b0 ≠ 0" by simp hence "t ∈ keys b0" unfolding t (*goal: ‹lpp b0 ∈ keys b0›*) by (rule punit.lt_in_keys (*‹(?p::('x ⇒₀ nat) ⇒₀ ?'b) ≠ (0::('x ⇒₀ nat) ⇒₀ ?'b) ⟹ lpp ?p ∈ keys ?p›*)) have "lookup (∑b∈B0. u b ⋅ b) t = (∑b∈B0. u b * lookup b t)" by (simp add: lookup_sum (*‹lookup (sum ?pp ?X) ?i = (∑x∈?X. lookup (?pp x) ?i)›*)) also (*calculation: ‹lookup (∑b::('x ⇒₀ nat) ⇒₀ 'a∈(B0::(('x ⇒₀ nat) ⇒₀ 'a) set). (u::(('x ⇒₀ nat) ⇒₀ 'a) ⇒ 'a) b ⋅ b) (t::'x ⇒₀ nat) = (∑b::('x ⇒₀ nat) ⇒₀ 'a∈B0. u b * lookup b t)›*) from ‹finite B0› (*‹finite B0›*) have "… = (∑b∈{b0}. u b * lookup b t)" proof (rule sum.mono_neutral_right (*‹⟦finite ?T; ?S ⊆ ?T; ∀i∈?T - ?S. ?g i = 0⟧ ⟹ sum ?g ?T = sum ?g ?S›*)) (*goals: 1. ‹{b0} ⊆ B0› 2. ‹∀i∈B0 - {b0}. u i * lookup i t = 0›*) from ‹b0 ∈ B0› (*‹b0 ∈ B0›*) show "{b0} ⊆ B0" by simp next (*goal: ‹∀i∈B0 - {b0}. u i * lookup i t = 0›*) show "∀b∈B0 - {b0}. u b * lookup b t = 0" proof (standard) (*goal: ‹⋀b::('x ⇒₀ nat) ⇒₀ 'a. b ∈ (B0::(('x ⇒₀ nat) ⇒₀ 'a) set) - {b0::('x ⇒₀ nat) ⇒₀ 'a} ⟹ (u::(('x ⇒₀ nat) ⇒₀ 'a) ⇒ 'a) b * lookup b (t::'x ⇒₀ nat) = (0::'a)›*) fix b assume "b ∈ B0 - {b0}" (*‹(b::('x ⇒₀ nat) ⇒₀ 'a) ∈ (B0::(('x ⇒₀ nat) ⇒₀ 'a) set) - {b0::('x ⇒₀ nat) ⇒₀ 'a}›*) hence "b ∈ B0" and "b ≠ b0" apply - (*goals: 1. ‹b ∈ B0 - {b0} ⟹ b ∈ B0› 2. ‹b ∈ B0 - {b0} ⟹ b ≠ b0› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . from this(1) (*‹b ∈ B0›*) have "lpp b ∈ lpp ` B0" by (rule imageI (*‹?x ∈ ?A ⟹ ?f ?x ∈ ?f ` ?A›*)) with ‹finite (lpp ` B0)› (*‹finite (lpp ` B0)›*) have "lpp b ≼ t" unfolding t_def (*goal: ‹lpp (b::('x::{countable,linorder} ⇒₀ nat) ⇒₀ 'a::field) ≼ ordered_powerprod_lin.Max (lpp ` (B0::(('x::{countable,linorder} ⇒₀ nat) ⇒₀ 'a::field) set))›*) by (rule ordered_powerprod_lin.Max_ge (*‹⟦finite (?A::('x ⇒₀ nat) set); (?x::'x ⇒₀ nat) ∈ ?A⟧ ⟹ ?x ≼ ordered_powerprod_lin.Max ?A›*)) have "t ∉ keys b" proof (standard) (*goal: ‹t ∈ keys b ⟹ False›*) assume "t ∈ keys b" (*‹(t::'x ⇒₀ nat) ∈ keys (b::('x ⇒₀ nat) ⇒₀ 'a)›*) hence "t ≼ lpp b" by (rule punit.lt_max_keys (*‹?v ∈ keys ?p ⟹ ?v ≼ lpp ?p›*)) with ‹lpp b ≼ t› (*‹lpp (b::('x::{countable,linorder} ⇒₀ nat) ⇒₀ 'a::field) ≼ (t::'x::{countable,linorder} ⇒₀ nat)›*) have "lpp b = lpp b0" unfolding t (*goal: ‹lpp b = lpp b0›*) by simp from inj (*‹inj_on lpp B›*) ‹B0 ⊆ B› (*‹B0 ⊆ B›*) have "inj_on lpp B0" by (rule inj_on_subset (*‹⟦inj_on ?f ?A; ?B ⊆ ?A⟧ ⟹ inj_on ?f ?B›*)) hence "b = b0" using ‹lpp b = lpp b0› (*‹lpp b = lpp b0›*) ‹b ∈ B0› (*‹b ∈ B0›*) ‹b0 ∈ B0› (*‹b0 ∈ B0›*) by (rule inj_onD (*‹⟦inj_on ?f ?A; ?f ?x = ?f ?y; ?x ∈ ?A; ?y ∈ ?A⟧ ⟹ ?x = ?y›*)) with ‹b ≠ b0› (*‹b ≠ b0›*) show False by standard qed thus "u b * lookup b t = 0" by (simp add: in_keys_iff (*‹(?x ∈ keys ?s) = (lookup ?s ?x ≠ 0)›*)) qed qed also (*calculation: ‹lookup (∑b∈B0. u b ⋅ b) t = (∑b∈{b0}. u b * lookup b t)›*) from ‹t ∈ keys b0› (*‹t ∈ keys b0›*) ‹b0 ∈ B0› (*‹b0 ∈ B0›*) have "… ≠ 0" by (simp add: B0_def (*‹B0 = {b ∈ B'. u b ≠ 0}›*) in_keys_iff (*‹(?x ∈ keys ?s) = (lookup ?s ?x ≠ 0)›*)) finally (*calculation: ‹lookup (∑b∈B0. u b ⋅ b) t ≠ 0›*) show False by (simp add: eq (*‹(∑b∈B0. u b ⋅ b) = 0›*)) qed qed also (*calculation: ‹Hilbert_fun A z = card B›*) have "… = card ?A" unfolding eq1 (*goal: ‹card (B::(('x ⇒₀ nat) ⇒₀ 'a) set) = card (lpp ` B)›*) using inj (*‹inj_on lpp B›*) by (rule card_image[symmetric] (*‹inj_on ?f ?A ⟹ card ?A = card (?f ` ?A)›*)) finally (*calculation: ‹Hilbert_fun A z = card (lpp ` (hom_deg_set z A - {0}))›*) show "?thesis" (*goal: ‹Hilbert_fun A z = card (lpp ` (hom_deg_set z A - {0}))›*) . qed end (* pm_powerprod *) end (* theory *)
{ "path": "afp-2025-02-12/thys/Groebner_Macaulay/Hilbert_Function.thy", "repo": "afp-2025-02-12", "sha": "08d7051dabbd35e69891674b559b29d14e5ab930f72c3790d1819808149ebedc" }
section ‹Chain-Complete Partial Orders› theory CCPO_Extensions imports "HOL-Library.Complete_Partial_Order2" ENat_Extensions Set_Extensions begin lemma chain_split[dest]: assumes "Complete_Partial_Order.chain ord C" "x ∈ C" shows "C = {y ∈ C. ord x y} ∪ {y ∈ C. ord y x}" proof (-) (*goal: ‹C = {y ∈ C. ord x y} ∪ {y ∈ C. ord y x}›*) have 1: "⋀ y. y ∈ C ⟹ ord x y ∨ ord y x" using chainD (*‹⟦Complete_Partial_Order.chain ?ord ?S; ?x ∈ ?S; ?y ∈ ?S⟧ ⟹ ?ord ?x ?y ∨ ?ord ?y ?x›*) assms (*‹Complete_Partial_Order.chain ord C› ‹(x::'a::type) ∈ (C::'a::type set)›*) by this show "?thesis" (*goal: ‹(C::'a set) = {y::'a ∈ C. (ord::'a ⇒ 'a ⇒ bool) (x::'a) y} ∪ {y::'a ∈ C. ord y x}›*) using "1" (*‹?y ∈ C ⟹ ord x ?y ∨ ord ?y x›*) by blast qed lemma infinite_chain_below[dest]: assumes "Complete_Partial_Order.chain ord C" "infinite C" "x ∈ C" assumes "finite {y ∈ C. ord x y}" shows "infinite {y ∈ C. ord y x}" proof (-) (*goal: ‹infinite {y ∈ C. ord y x}›*) have 1: "C = {y ∈ C. ord x y} ∪ {y ∈ C. ord y x}" using assms(1,3) (*‹Complete_Partial_Order.chain ord C› ‹x ∈ C›*) by rule show "?thesis" (*goal: ‹infinite {y ∈ C. ord y x}›*) using finite_Un (*‹finite (?F ∪ ?G) = (finite ?F ∧ finite ?G)›*) assms(2,4) (*‹infinite C› ‹finite {y::'a::type ∈ C::'a::type set. (ord::'a::type ⇒ 'a::type ⇒ bool) (x::'a::type) y}›*) "1" (*‹(C::'a::type set) = {y::'a::type ∈ C. (ord::'a::type ⇒ 'a::type ⇒ bool) (x::'a::type) y} ∪ {y::'a::type ∈ C. ord y x}›*) by (metis (poly_guards_query)) qed lemma infinite_chain_above[dest]: assumes "Complete_Partial_Order.chain ord C" "infinite C" "x ∈ C" assumes "finite {y ∈ C. ord y x}" shows "infinite {y ∈ C. ord x y}" proof (-) (*goal: ‹infinite {y ∈ C. ord x y}›*) have 1: "C = {y ∈ C. ord x y} ∪ {y ∈ C. ord y x}" using assms(1,3) (*‹Complete_Partial_Order.chain ord C› ‹x ∈ C›*) by rule show "?thesis" (*goal: ‹infinite {y ∈ C. ord x y}›*) using finite_Un (*‹finite (?F ∪ ?G) = (finite ?F ∧ finite ?G)›*) assms(2,4) (*‹infinite C› ‹finite {y ∈ C. ord y x}›*) "1" (*‹C = {y ∈ C. ord x y} ∪ {y ∈ C. ord y x}›*) by (metis (poly_guards_query)) qed lemma (in ccpo) ccpo_Sup_upper_inv: assumes "Complete_Partial_Order.chain less_eq C" "x > ⨆ C" shows "x ∉ C" using assms (*‹Complete_Partial_Order.chain (≤) C› ‹⨆ (C::'a set) < (x::'a)›*) ccpo_Sup_upper (*‹⟦Complete_Partial_Order.chain (≤) ?A; ?x ∈ ?A⟧ ⟹ ?x ≤ ⨆ ?A›*) by fastforce lemma (in ccpo) ccpo_Sup_least_inv: assumes "Complete_Partial_Order.chain less_eq C" "⨆ C > x" obtains y where "y ∈ C" "¬ y ≤ x" using assms (*‹Complete_Partial_Order.chain (≤) (C::'a set)› ‹x < ⨆ C›*) ccpo_Sup_least (*‹⟦Complete_Partial_Order.chain (≤) ?A; ⋀x. x ∈ ?A ⟹ x ≤ ?z⟧ ⟹ ⨆ ?A ≤ ?z›*) that (*‹⟦?y ∈ C; ¬ ?y ≤ x⟧ ⟹ thesis›*) by fastforce lemma ccpo_Sup_least_inv': fixes C :: "'a :: {ccpo, linorder} set" assumes "Complete_Partial_Order.chain less_eq C" "⨆ C > x" obtains y where "y ∈ C" "y > x" proof (-) (*goal: ‹(⋀y. ⟦y ∈ C; x < y⟧ ⟹ thesis) ⟹ thesis›*) obtain y where 1: "y ∈ C" "¬ y ≤ x" (*goal: ‹(⋀y. ⟦y ∈ C; ¬ y ≤ x⟧ ⟹ thesis) ⟹ thesis›*) using ccpo_Sup_least_inv (*‹⟦Complete_Partial_Order.chain (≤) ?C; ?x < ⨆ ?C; ⋀y. ⟦y ∈ ?C; ¬ y ≤ ?x⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) assms (*‹Complete_Partial_Order.chain (≤) C› ‹x < ⨆ C›*) by this show "?thesis" (*goal: ‹thesis::bool›*) using that (*‹⟦?y ∈ C; x < ?y⟧ ⟹ thesis›*) "1" (*‹y ∈ C› ‹¬ (y::'a::{ccpo,linorder}) ≤ (x::'a::{ccpo,linorder})›*) by simp qed lemma mcont2mcont_lessThan[THEN lfp.mcont2mcont, simp, cont_intro]: shows mcont_lessThan: "mcont Sup less_eq Sup less_eq (lessThan :: 'a :: {ccpo, linorder} ⇒ 'a set)" proof (standard) (*goals: 1. ‹mono lessThan› 2. ‹cont Sup (≤) ⋃ (⊆) lessThan›*) show "monotone less_eq less_eq (lessThan :: 'a ⇒ 'a set)" apply rule (*goal: ‹mono lessThan›*) by auto show "cont Sup less_eq Sup less_eq (lessThan :: 'a ⇒ 'a set)" proof (standard) (*goal: ‹⋀Y. ⟦Complete_Partial_Order.chain (≤) Y; Y ≠ {}⟧ ⟹ {..<⨆ Y} = ⋃ (lessThan ` Y)›*) fix C :: "'a set" assume 1: "Complete_Partial_Order.chain less_eq C" (*‹Complete_Partial_Order.chain (≤) (C::'a set)›*) show "{..< ⨆ C} = ⋃ (lessThan ` C)" proof (intro equalityI (*‹⟦?A ⊆ ?B; ?B ⊆ ?A⟧ ⟹ ?A = ?B›*) subsetI (*‹(⋀x. x ∈ ?A ⟹ x ∈ ?B) ⟹ ?A ⊆ ?B›*)) (*goals: 1. ‹⋀x::'a::{ccpo,linorder}. x ∈ {..<⨆ (C::'a::{ccpo,linorder} set)} ⟹ x ∈ ⋃ (lessThan ` C)› 2. ‹⋀x::'a::{ccpo,linorder}. x ∈ ⋃ (lessThan ` (C::'a::{ccpo,linorder} set)) ⟹ x ∈ {..<⨆ C}›*) fix A assume 2: "A ∈ {..< ⨆ C}" (*‹(A::'a) ∈ {..<⨆ (C::'a set)}›*) obtain B where 3: "B ∈ C" "B > A" (*goal: ‹(⋀B. ⟦B ∈ C; A < B⟧ ⟹ thesis) ⟹ thesis›*) using ccpo_Sup_least_inv' (*‹⟦Complete_Partial_Order.chain (≤) ?C; ?x < ⨆ ?C; ⋀y. ⟦y ∈ ?C; ?x < y⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) "1" (*‹Complete_Partial_Order.chain (≤) C›*) "2" (*‹A ∈ {..<⨆ C}›*) by blast show "A ∈ ⋃ (lessThan ` C)" using "3" (*‹B ∈ C› ‹A < B›*) by auto next (*goal: ‹⋀x. x ∈ ⋃ (lessThan ` C) ⟹ x ∈ {..<⨆ C}›*) fix A assume 2: "A ∈ ⋃ (lessThan ` C)" (*‹(A::'a) ∈ ⋃ (lessThan ` (C::'a set))›*) show "A ∈ {..< ⨆ C}" using ccpo_Sup_upper (*‹⟦Complete_Partial_Order.chain (≤) ?A; ?x ∈ ?A⟧ ⟹ ?x ≤ ⨆ ?A›*) "2" (*‹A ∈ ⋃ (lessThan ` C)›*) by force qed qed qed class esize = fixes esize :: "'a ⇒ enat" class esize_order = esize + order + assumes esize_finite[dest]: "esize x ≠ ∞ ⟹ finite {y. y ≤ x}" assumes esize_mono[intro]: "x ≤ y ⟹ esize x ≤ esize y" assumes esize_strict_mono[intro]: "esize x ≠ ∞ ⟹ x < y ⟹ esize x < esize y" begin lemma infinite_chain_eSuc_esize[dest]: assumes "Complete_Partial_Order.chain less_eq C" "infinite C" "x ∈ C" obtains y where "y ∈ C" "esize y ≥ eSuc (esize x)" proof (cases "esize x") (*goals: 1. ‹⋀nat. ⟦⋀y. ⟦y ∈ C; eSuc (esize x) ≤ esize y⟧ ⟹ thesis; esize x = enat nat⟧ ⟹ thesis› 2. ‹⟦⋀y. ⟦y ∈ C; eSuc (esize x) ≤ esize y⟧ ⟹ thesis; esize x = ∞⟧ ⟹ thesis›*) case (enat k) (*‹esize (x::'a::type) = enat (k::nat)›*) have 1: "finite {y ∈ C. y ≤ x}" using esize_finite (*‹esize ?x ≠ ∞ ⟹ finite {y. y ≤ ?x}›*) enat (*‹esize x = enat k›*) by simp have 2: "infinite {y ∈ C. y ≥ x}" using assms (*‹Complete_Partial_Order.chain (≤) (C::'a set)› ‹infinite C› ‹(x::'a) ∈ (C::'a set)›*) "1" (*‹finite {y ∈ C. y ≤ x}›*) by rule have 3: "{y ∈ C. y > x} = {y ∈ C. y ≥ x} - {x}" by auto have 4: "infinite {y ∈ C. y > x}" using "2" (*‹infinite {y::'a ∈ C::'a set. (x::'a) ≤ y}›*) unfolding "3" (*goal: ‹infinite ({y ∈ C. x ≤ y} - {x})›*) by simp obtain y where 5: "y ∈ C" "y > x" (*goal: ‹(⋀y. ⟦y ∈ C; x < y⟧ ⟹ thesis) ⟹ thesis›*) using "4" (*‹infinite {y::'a::type ∈ C::'a::type set. (x::'a::type) < y}›*) by auto have 6: "esize y > esize x" using esize_strict_mono (*‹⟦esize ?x ≠ ∞; ?x < ?y⟧ ⟹ esize ?x < esize ?y›*) enat (*‹esize x = enat k›*) "5"(2) (*‹x < y›*) by blast show "?thesis" (*goal: ‹thesis::bool›*) using that (*‹⟦(?y::'a) ∈ (C::'a set); eSuc (esize (x::'a)) ≤ esize ?y⟧ ⟹ thesis::bool›*) "5"(1) (*‹y ∈ C›*) "6" (*‹esize x < esize y›*) ileI1 (*‹(?m::enat) < (?n::enat) ⟹ eSuc ?m ≤ ?n›*) by simp next (*goal: ‹⟦⋀y. ⟦y ∈ C; eSuc (esize x) ≤ esize y⟧ ⟹ thesis; esize x = ∞⟧ ⟹ thesis›*) case infinity (*‹esize x = ∞›*) show "?thesis" (*goal: ‹thesis›*) using that (*‹⟦?y ∈ C; eSuc (esize x) ≤ esize ?y⟧ ⟹ thesis›*) infinity (*‹esize x = ∞›*) assms(3) (*‹x ∈ C›*) by simp qed lemma infinite_chain_arbitrary_esize[dest]: assumes "Complete_Partial_Order.chain less_eq C" "infinite C" obtains x where "x ∈ C" "esize x ≥ enat n" proof (induct n arbitrary: thesis) (*goals: 1. ‹⋀thesis. (⋀x. ⟦x ∈ C; enat 0 ≤ esize x⟧ ⟹ thesis) ⟹ thesis› 2. ‹⋀n thesis. ⟦⋀thesis. (⋀x. ⟦x ∈ C; enat n ≤ esize x⟧ ⟹ thesis) ⟹ thesis; ⋀x. ⟦x ∈ C; enat (Suc n) ≤ esize x⟧ ⟹ thesis⟧ ⟹ thesis›*) case 0 (*‹⟦(?x::'a) ∈ (C::'a set); enat (0::nat) ≤ esize ?x⟧ ⟹ thesis::bool›*) show "?case" (*goal: ‹thesis›*) using assms(2) (*‹infinite C›*) "0" (*‹⟦(?x::'a) ∈ (C::'a set); enat (0::nat) ≤ esize ?x⟧ ⟹ thesis::bool›*) by force next (*goal: ‹⋀n thesis. ⟦⋀thesis. (⋀x. ⟦x ∈ C; enat n ≤ esize x⟧ ⟹ thesis) ⟹ thesis; ⋀x. ⟦x ∈ C; enat (Suc n) ≤ esize x⟧ ⟹ thesis⟧ ⟹ thesis›*) case (Suc n) (*‹(⋀x. ⟦x ∈ C; enat n ≤ esize x⟧ ⟹ ?thesis) ⟹ ?thesis› ‹⟦?x ∈ C; enat (Suc n) ≤ esize ?x⟧ ⟹ thesis›*) obtain x where 1: "x ∈ C" "esize x ≥ enat n" (*goal: ‹(⋀x. ⟦x ∈ C; enat n ≤ esize x⟧ ⟹ thesis) ⟹ thesis›*) using Suc(1) (*‹(⋀x. ⟦x ∈ C; enat n ≤ esize x⟧ ⟹ ?thesis) ⟹ ?thesis›*) by blast obtain y where 2: "y ∈ C" "esize y ≥ eSuc (esize x)" (*goal: ‹(⋀y. ⟦y ∈ C; eSuc (esize x) ≤ esize y⟧ ⟹ thesis) ⟹ thesis›*) using assms (*‹Complete_Partial_Order.chain (≤) C› ‹infinite C›*) "1"(1) (*‹(x::'a) ∈ (C::'a set)›*) apply rule (*goals: 1. ‹⋀y. ⟦⋀y. ⟦y ∈ C; eSuc (esize x) ≤ esize y⟧ ⟹ thesis; y ∈ C; eSuc (esize x) ≤ esize y⟧ ⟹ ?thesis2› 2. ‹⟦⋀y. ⟦y ∈ C; eSuc (esize x) ≤ esize y⟧ ⟹ thesis; ?thesis2⟧ ⟹ thesis› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) show "?case" (*goal: ‹thesis::bool›*) using gfp.leq_trans (*‹⟦?y ≤ ?x; ?z ≤ ?y⟧ ⟹ ?z ≤ ?x›*) Suc(2) (*‹⟦(?x::'a) ∈ (C::'a set); enat (Suc (n::nat)) ≤ esize ?x⟧ ⟹ thesis::bool›*) "1"(2) (*‹enat n ≤ esize x›*) "2" (*‹y ∈ C› ‹eSuc (esize x) ≤ esize y›*) by fastforce qed end class esize_ccpo = esize_order + ccpo begin lemma esize_cont[dest]: assumes "Complete_Partial_Order.chain less_eq C" "C ≠ {}" shows "esize (⨆ C) = ⨆ (esize ` C)" proof (cases "finite C") (*goals: 1. ‹finite C ⟹ esize (⨆ C) = ⨆ (esize ` C)› 2. ‹infinite C ⟹ esize (⨆ C) = ⨆ (esize ` C)›*) case False (*‹infinite (C::'a set)›*) have 1: "esize (⨆ C) = ∞" proof (standard) (*goal: ‹⋀n. enat n ≤ esize (⨆ C)›*) fix n obtain A where 1: "A ∈ C" "esize A ≥ enat n" (*goal: ‹(⋀A. ⟦A ∈ C; enat n ≤ esize A⟧ ⟹ thesis) ⟹ thesis›*) using assms(1) (*‹Complete_Partial_Order.chain (≤) (C::'a set)›*) False (*‹infinite C›*) apply rule (*goals: 1. ‹⋀x. ⟦⋀A. ⟦A ∈ C; enat n ≤ esize A⟧ ⟹ thesis; x ∈ C; enat ?n2 ≤ esize x⟧ ⟹ ?thesis2› 2. ‹⟦⋀A. ⟦A ∈ C; enat n ≤ esize A⟧ ⟹ thesis; ?thesis2⟧ ⟹ thesis› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) have 2: "A ≤ ⨆ C" using ccpo_Sup_upper (*‹⟦Complete_Partial_Order.chain (≤) ?A; ?x ∈ ?A⟧ ⟹ ?x ≤ ⨆ ?A›*) assms(1) (*‹Complete_Partial_Order.chain (≤) C›*) "1"(1) (*‹A ∈ C›*) by this have "enat n ≤ esize A" using "1"(2) (*‹enat (n::nat) ≤ esize (A::'a)›*) by this also (*calculation: ‹enat (n::nat) ≤ esize (A::'a)›*) have "… ≤ esize (⨆ C)" using "2" (*‹A ≤ ⨆ C›*) by rule finally (*calculation: ‹enat n ≤ esize (⨆ C)›*) show "enat n ≤ esize (⨆ C)" by this qed have 2: "(⨆ A ∈ C. esize A) = ∞" proof (standard) (*goal: ‹⋀n. enat n ≤ ⨆ (esize ` C)›*) fix n obtain A where 1: "A ∈ C" "esize A ≥ enat n" (*goal: ‹(⋀A. ⟦A ∈ C; enat n ≤ esize A⟧ ⟹ thesis) ⟹ thesis›*) using assms(1) (*‹Complete_Partial_Order.chain (≤) C›*) False (*‹infinite C›*) apply rule (*goals: 1. ‹⋀x::'a. ⟦⋀A::'a. ⟦A ∈ (C::'a set); enat (n::nat) ≤ esize A⟧ ⟹ thesis::bool; x ∈ C; enat (?n2::nat) ≤ esize x⟧ ⟹ ?thesis2::bool› 2. ‹⟦⋀A::'a. ⟦A ∈ (C::'a set); enat (n::nat) ≤ esize A⟧ ⟹ thesis::bool; ?thesis2::bool⟧ ⟹ thesis› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) show "enat n ≤ (⨆ A ∈ C. esize A)" using SUP_upper2 (*‹⟦?i ∈ ?A; ?u ≤ ?f ?i⟧ ⟹ ?u ≤ ⨆ (?f ` ?A)›*) "1" (*‹A ∈ C› ‹enat (n::nat) ≤ esize (A::'a::type)›*) by this qed show "?thesis" (*goal: ‹esize (⨆ C) = ⨆ (esize ` C)›*) using "1" (*‹esize (⨆ C) = ∞›*) "2" (*‹⨆ (esize ` C) = ∞›*) by simp next (*goal: ‹finite C ⟹ esize (⨆ C) = ⨆ (esize ` C)›*) case True (*‹finite C›*) have 1: "esize (⨆ C) = (⨆ x ∈ C. esize x)" proof (intro order_class.order.antisym (*‹⟦(?a::?'a) ≤ (?b::?'a); ?b ≤ ?a⟧ ⟹ ?a = ?b›*) SUP_upper (*‹(?i::?'b) ∈ (?A::?'b set) ⟹ (?f::?'b ⇒ ?'a) ?i ≤ ⨆ (?f ` ?A)›*) SUP_least (*‹(⋀i::?'b. i ∈ (?A::?'b set) ⟹ (?f::?'b ⇒ ?'a) i ≤ (?u::?'a)) ⟹ ⨆ (?f ` ?A) ≤ ?u›*) esize_mono (*‹(?x::'a) ≤ (?y::'a) ⟹ esize ?x ≤ esize ?y›*)) (*goals: 1. ‹⨆ C ∈ C› 2. ‹⋀x. x ∈ C ⟹ x ≤ ⨆ C›*) show "⨆ C ∈ C" using in_chain_finite (*‹⟦Complete_Partial_Order.chain (≤) ?A; finite ?A; ?A ≠ {}⟧ ⟹ ⨆ ?A ∈ ?A›*) assms(1) (*‹Complete_Partial_Order.chain (≤) C›*) True (*‹finite C›*) assms(2) (*‹C ≠ {}›*) by this show "⋀ x. x ∈ C ⟹ x ≤ ⨆ C" using ccpo_Sup_upper (*‹⟦Complete_Partial_Order.chain (≤) ?A; ?x ∈ ?A⟧ ⟹ ?x ≤ ⨆ ?A›*) assms(1) (*‹Complete_Partial_Order.chain (≤) (C::'a set)›*) by this qed show "?thesis" (*goal: ‹esize (⨆ C) = ⨆ (esize ` C)›*) using "1" (*‹esize (⨆ C) = ⨆ (esize ` C)›*) by simp qed lemma esize_mcont: "mcont Sup less_eq Sup less_eq esize" by (blast intro: mcontI (*‹⟦monotone (?orda::?'a ⇒ ?'a ⇒ bool) (?ordb::?'b ⇒ ?'b ⇒ bool) (?f::?'a ⇒ ?'b); cont (?luba::?'a set ⇒ ?'a) ?orda (?lubb::?'b set ⇒ ?'b) ?ordb ?f⟧ ⟹ mcont ?luba ?orda ?lubb ?ordb ?f›*) monotoneI (*‹(⋀(x::?'a) y::?'a. (?orda::?'a ⇒ ?'a ⇒ bool) x y ⟹ (?ordb::?'b ⇒ ?'b ⇒ bool) ((?f::?'a ⇒ ?'b) x) (?f y)) ⟹ monotone ?orda ?ordb ?f›*) contI (*‹(⋀Y::?'a set. ⟦Complete_Partial_Order.chain (?orda::?'a ⇒ ?'a ⇒ bool) Y; Y ≠ {}⟧ ⟹ (?f::?'a ⇒ ?'b) ((?luba::?'a set ⇒ ?'a) Y) = (?lubb::?'b set ⇒ ?'b) (?f ` Y)) ⟹ cont ?luba ?orda ?lubb (?ordb::?'b ⇒ ?'b ⇒ bool) ?f›*)) lemmas mcont2mcont_esize = esize_mcont[THEN lfp.mcont2mcont, simp, cont_intro] end end
{ "path": "afp-2025-02-12/thys/Partial_Order_Reduction/Extensions/CCPO_Extensions.thy", "repo": "afp-2025-02-12", "sha": "75cd235d83dd28fd22c83760c4bc949435c5aa32c65c0db5fb81546204ec4f8d" }
section ‹ Scene Spaces › theory Scene_Spaces imports Scenes begin subsection ‹ Preliminaries › abbreviation foldr_scene :: "'a scene list ⇒ 'a scene" ("⨆⇩S") where "foldr_scene as ≡ foldr (⊔⇩S) as ⊥⇩S" lemma pairwise_indep_then_compat [simp]: "pairwise (⨝⇩S) A ⟹ pairwise (##⇩S) A" by (simp add: pairwise_alt (*‹pairwise (?R::?'a ⇒ ?'a ⇒ bool) (?S::?'a set) = (∀x::?'a∈?S. ∀y::?'a∈?S - {x}. ?R x y)›*)) lemma pairwise_compat_foldr: "⟦ pairwise (##⇩S) (set as); ∀ b ∈ set as. a ##⇩S b ⟧ ⟹ a ##⇩S ⨆⇩S as" apply (induct as) (*goals: 1. ‹⟦pairwise (##⇩S) (set []); Ball (set []) ((##⇩S) a)⟧ ⟹ a ##⇩S ⨆⇩S []› 2. ‹⋀aa as. ⟦⟦pairwise (##⇩S) (set as); Ball (set as) ((##⇩S) a)⟧ ⟹ a ##⇩S ⨆⇩S as; pairwise (##⇩S) (set (aa # as)); Ball (set (aa # as)) ((##⇩S) a)⟧ ⟹ a ##⇩S ⨆⇩S (aa # as)› discuss goal 1*) apply simp (*discuss goal 2*) apply (auto simp add: pairwise_insert (*‹pairwise ?r (insert ?x ?s) = ((∀y. y ∈ ?s ∧ y ≠ ?x ⟶ ?r ?x y ∧ ?r y ?x) ∧ pairwise ?r ?s)›*) scene_union_pres_compat (*‹⟦?A ##⇩S ?B; ?A ##⇩S ?C⟧ ⟹ ?A ##⇩S ?B ⊔⇩S ?C›*)) (*proven 2 subgoals*) . lemma foldr_scene_indep: "⟦ pairwise (##⇩S) (set as); ∀ b ∈ set as. a ⨝⇩S b ⟧ ⟹ a ⨝⇩S ⨆⇩S as" apply (induct as) (*goals: 1. ‹⟦pairwise (##⇩S) (set []); Ball (set []) ((⨝⇩S) a)⟧ ⟹ a ⨝⇩S ⨆⇩S []› 2. ‹⋀aa as. ⟦⟦pairwise (##⇩S) (set as); Ball (set as) ((⨝⇩S) a)⟧ ⟹ a ⨝⇩S ⨆⇩S as; pairwise (##⇩S) (set (aa # as)); Ball (set (aa # as)) ((⨝⇩S) a)⟧ ⟹ a ⨝⇩S ⨆⇩S (aa # as)› discuss goal 1*) apply simp (*discuss goal 2*) apply (auto intro: scene_indep_pres_compat (*‹⟦(?A::?'a::type scene) ⨝⇩S (?B::?'a::type scene); ?A ⨝⇩S (?C::?'a::type scene)⟧ ⟹ ?A ⨝⇩S ?B ⊔⇩S ?C›*) simp add: pairwise_insert (*‹pairwise (?r::?'a::type ⇒ ?'a::type ⇒ bool) (insert (?x::?'a::type) (?s::?'a::type set)) = ((∀y::?'a::type. y ∈ ?s ∧ y ≠ ?x ⟶ ?r ?x y ∧ ?r y ?x) ∧ pairwise ?r ?s)›*)) (*proven 2 subgoals*) . lemma foldr_compat_dist: "pairwise (##⇩S) (set as) ⟹ foldr (⊔⇩S) (map (λa. a ;⇩S x) as) ⊥⇩S = ⨆⇩S as ;⇩S x" apply (induct as) (*goals: 1. ‹pairwise (##⇩S) (set []) ⟹ ⨆⇩S (map (λa. a ;⇩S x) []) = ⨆⇩S [] ;⇩S x› 2. ‹⋀a as. ⟦pairwise (##⇩S) (set as) ⟹ ⨆⇩S (map (λa. a ;⇩S x) as) = ⨆⇩S as ;⇩S x; pairwise (##⇩S) (set (a # as))⟧ ⟹ ⨆⇩S (map (λa. a ;⇩S x) (a # as)) = ⨆⇩S (a # as) ;⇩S x› discuss goal 1*) apply simp (*discuss goal 2*) apply (auto simp add: pairwise_insert (*‹pairwise ?r (insert ?x ?s) = ((∀y. y ∈ ?s ∧ y ≠ ?x ⟶ ?r ?x y ∧ ?r y ?x) ∧ pairwise ?r ?s)›*)) (*goal: ‹⋀a as. ⟦pairwise (##⇩S) (set as) ⟹ ⨆⇩S (map (λa. a ;⇩S x) as) = ⨆⇩S as ;⇩S x; pairwise (##⇩S) (set (a # as))⟧ ⟹ ⨆⇩S (map (λa. a ;⇩S x) (a # as)) = ⨆⇩S (a # as) ;⇩S x›*) apply (metis pairwise_compat_foldr (*‹⟦pairwise (##⇩S) (set ?as); ∀b∈set ?as. ?a ##⇩S b⟧ ⟹ ?a ##⇩S ⨆⇩S ?as›*) scene_compat_refl (*‹?X ##⇩S ?X›*) scene_union_comp_distl (*‹?a ##⇩S ?b ⟹ (?a ⊔⇩S ?b) ;⇩S ?x = ?a ;⇩S ?x ⊔⇩S ?b ;⇩S ?x›*)) (*proven 2 subgoals*) . lemma foldr_compat_quotient_dist: "⟦ pairwise (##⇩S) (set as); ∀ a∈set as. a ≤ ⟦x⟧⇩∼ ⟧ ⟹ foldr (⊔⇩S) (map (λa. a /⇩S x) as) ⊥⇩S = ⨆⇩S as /⇩S x" apply (induct as) (*goal: ‹⟦pairwise (##⇩S) (set as); ∀a∈set as. a ⊆⇩S ⟦x⟧⇩∼⟧ ⟹ ⨆⇩S (map (λa. a /⇩S x) as) = ⨆⇩S as /⇩S x›*) apply (auto simp add: pairwise_insert (*‹pairwise ?r (insert ?x ?s) = ((∀y. y ∈ ?s ∧ y ≠ ?x ⟶ ?r ?x y ∧ ?r y ?x) ∧ pairwise ?r ?s)›*)) (*top goal: ‹⟦pairwise (##⇩S) (set []); ∀a∈set []. a ⊆⇩S ⟦x⟧⇩∼⟧ ⟹ ⨆⇩S (map (λa. a /⇩S x) []) = ⨆⇩S [] /⇩S x› and 1 goal remains*) apply (subst scene_union_quotient (*‹⟦?A ##⇩S ?B; ?A ⊆⇩S ⟦?X⟧⇩∼; ?B ⊆⇩S ⟦?X⟧⇩∼⟧ ⟹ (?A ⊔⇩S ?B) /⇩S ?X = ?A /⇩S ?X ⊔⇩S ?B /⇩S ?X›*)) (*goal: ‹⋀a as. ⟦⨆⇩S (map (λa. a /⇩S x) as) = ⨆⇩S as /⇩S x; ∀y. y ∈ set as ∧ y ≠ a ⟶ a ##⇩S y ∧ y ##⇩S a; pairwise (##⇩S) (set as); a ⊆⇩S ⟦x⟧⇩∼; ∀a∈set as. a ⊆⇩S ⟦x⟧⇩∼⟧ ⟹ a /⇩S x ⊔⇩S ⨆⇩S as /⇩S x = (a ⊔⇩S ⨆⇩S as) /⇩S x›*) apply simp_all (*top goal: ‹⋀a as. ⟦⨆⇩S (map (λa. a /⇩S x) as) = ⨆⇩S as /⇩S x; ∀y. y ∈ set as ∧ y ≠ a ⟶ a ##⇩S y ∧ y ##⇩S a; pairwise (##⇩S) (set as); a ⊆⇩S ⟦x⟧⇩∼; ∀a∈set as. a ⊆⇩S ⟦x⟧⇩∼⟧ ⟹ a ##⇩S ⨆⇩S as› and 3 goals remain*) using pairwise_compat_foldr (*‹⟦pairwise (##⇩S) (set ?as); ∀b∈set ?as. ?a ##⇩S b⟧ ⟹ ?a ##⇩S ⨆⇩S ?as›*) scene_compat_refl (*‹?X ##⇩S ?X›*) (*goals: 1. ‹⋀(a::'a scene) as::'a scene list. ⟦⨆⇩S (map (λa::'a scene. a /⇩S (x::'b ⟹ 'a)) as) = ⨆⇩S as /⇩S x; ∀y::'a scene. y ∈ set as ∧ y ≠ a ⟶ a ##⇩S y ∧ y ##⇩S a; pairwise (##⇩S) (set as); a ⊆⇩S ⟦x⟧⇩∼; ∀a::'a scene∈set as. a ⊆⇩S ⟦x⟧⇩∼⟧ ⟹ a ##⇩S ⨆⇩S as› 2. ‹⋀(a::'a scene) as::'a scene list. ⟦⨆⇩S (map (λa::'a scene. a /⇩S (x::'b ⟹ 'a)) as) = ⨆⇩S as /⇩S x; ∀y::'a scene. y ∈ set as ∧ y ≠ a ⟶ a ##⇩S y ∧ y ##⇩S a; pairwise (##⇩S) (set as); a ⊆⇩S ⟦x⟧⇩∼; ∀a::'a scene∈set as. a ⊆⇩S ⟦x⟧⇩∼⟧ ⟹ ⨆⇩S as ⊆⇩S ⟦x⟧⇩∼› discuss goal 1*) apply blast (*discuss goal 2*) apply (meson foldr_scene_indep (*‹⟦pairwise (##⇩S) (set ?as); ∀b∈set ?as. ?a ⨝⇩S b⟧ ⟹ ?a ⨝⇩S ⨆⇩S ?as›*) scene_indep_sym (*‹?X ⨝⇩S ?Y ⟹ ?Y ⨝⇩S ?X›*) scene_le_iff_indep_inv (*‹(?A ⨝⇩S - ?B) = ?A ⊆⇩S ?B›*)) (*proven 2 subgoals*) . lemma foldr_scene_union_add_tail: "⟦ pairwise (##⇩S) (set xs); ∀ x∈set xs. x ##⇩S b ⟧ ⟹ ⨆⇩S xs ⊔⇩S b = foldr (⊔⇩S) xs b" apply (induct xs) (*goal: ‹⟦pairwise (##⇩S) (set xs); ∀x∈set xs. x ##⇩S b⟧ ⟹ ⨆⇩S xs ⊔⇩S b = foldr (⊔⇩S) xs b›*) apply simp (*top goal: ‹⟦pairwise (##⇩S) (set []); ∀x::'a scene∈set []. x ##⇩S (b::'a scene)⟧ ⟹ ⨆⇩S [] ⊔⇩S b = foldr (⊔⇩S) [] b› and 1 goal remains*) apply simp (*goal: ‹⋀a xs. ⟦⟦pairwise (##⇩S) (set xs); ∀x∈set xs. x ##⇩S b⟧ ⟹ ⨆⇩S xs ⊔⇩S b = foldr (⊔⇩S) xs b; pairwise (##⇩S) (set (a # xs)); ∀x∈set (a # xs). x ##⇩S b⟧ ⟹ ⨆⇩S (a # xs) ⊔⇩S b = foldr (⊔⇩S) (a # xs) b›*) apply (subst scene_union_assoc[THEN sym] (*‹⟦?X1 ##⇩S ?Y1; ?X1 ##⇩S ?Z1; ?Y1 ##⇩S ?Z1⟧ ⟹ ?X1 ⊔⇩S ?Y1 ⊔⇩S ?Z1 = ?X1 ⊔⇩S (?Y1 ⊔⇩S ?Z1)›*)) (*goal: ‹⋀a xs. ⟦pairwise (##⇩S) (set xs) ⟹ ⨆⇩S xs ⊔⇩S b = foldr (⊔⇩S) xs b; pairwise (##⇩S) (insert a (set xs)); a ##⇩S b ∧ (∀x∈set xs. x ##⇩S b)⟧ ⟹ a ⊔⇩S ⨆⇩S xs ⊔⇩S b = a ⊔⇩S foldr (⊔⇩S) xs b›*) apply (auto simp add: pairwise_insert (*‹pairwise (?r::?'a ⇒ ?'a ⇒ bool) (insert (?x::?'a) (?s::?'a set)) = ((∀y::?'a. y ∈ ?s ∧ y ≠ ?x ⟶ ?r ?x y ∧ ?r y ?x) ∧ pairwise ?r ?s)›*)) (*top goal: ‹⋀a xs. ⟦pairwise (##⇩S) (set xs) ⟹ ⨆⇩S xs ⊔⇩S b = foldr (⊔⇩S) xs b; pairwise (##⇩S) (insert a (set xs)); a ##⇩S b ∧ (∀x∈set xs. x ##⇩S b)⟧ ⟹ a ##⇩S ⨆⇩S xs› and 3 goals remain*) using pairwise_compat_foldr (*‹⟦pairwise (##⇩S) (set ?as); ∀b∈set ?as. ?a ##⇩S b⟧ ⟹ ?a ##⇩S ⨆⇩S ?as›*) scene_compat_refl (*‹?X ##⇩S ?X›*) (*goals: 1. ‹⋀a xs. ⟦⨆⇩S xs ⊔⇩S b = foldr (⊔⇩S) xs b; ∀y. y ∈ set xs ∧ y ≠ a ⟶ a ##⇩S y ∧ y ##⇩S a; pairwise (##⇩S) (set xs); a ##⇩S b; ∀x∈set xs. x ##⇩S b⟧ ⟹ a ##⇩S ⨆⇩S xs› 2. ‹⋀a xs. ⟦⨆⇩S xs ⊔⇩S b = foldr (⊔⇩S) xs b; ∀y. y ∈ set xs ∧ y ≠ a ⟶ a ##⇩S y ∧ y ##⇩S a; pairwise (##⇩S) (set xs); a ##⇩S b; ∀x∈set xs. x ##⇩S b⟧ ⟹ ⨆⇩S xs ##⇩S b› discuss goal 1*) apply blast (*discuss goal 2*) apply (meson pairwise_compat_foldr (*‹⟦pairwise (##⇩S) (set ?as); ∀b∈set ?as. ?a ##⇩S b⟧ ⟹ ?a ##⇩S ⨆⇩S ?as›*) scene_compat_sym (*‹?X ##⇩S ?Y ⟹ ?Y ##⇩S ?X›*)) (*proven 2 subgoals*) . lemma pairwise_Diff: "pairwise R A ⟹ pairwise R (A - B)" using pairwise_mono (*‹⟦pairwise ?P ?A; ⋀x y. ?P x y ⟹ ?Q x y; ?B ⊆ ?A⟧ ⟹ pairwise ?Q ?B›*) by fastforce lemma scene_compats_members: "⟦ pairwise (##⇩S) A; x ∈ A; y ∈ A ⟧ ⟹ x ##⇩S y" by (metis pairwise_def (*‹pairwise (?R::?'a::type ⇒ ?'a::type ⇒ bool) (?S::?'a::type set) = (∀x::?'a::type∈?S. ∀y::?'a::type∈?S. x ≠ y ⟶ ?R x y)›*) scene_compat_refl (*‹(?X::?'a::type scene) ##⇩S ?X›*)) corollary foldr_scene_union_removeAll: assumes "pairwise (##⇩S) (set xs)" "x ∈ set xs" shows "⨆⇩S (removeAll x xs) ⊔⇩S x = ⨆⇩S xs" using assms (*‹pairwise (##⇩S) (set (xs::'a scene list))› ‹(x::'a scene) ∈ set (xs::'a scene list)›*) proof (induct xs) (*goals: 1. ‹⟦pairwise (##⇩S) (set []); x ∈ set []⟧ ⟹ ⨆⇩S (removeAll x []) ⊔⇩S x = ⨆⇩S []› 2. ‹⋀a xs. ⟦⟦pairwise (##⇩S) (set xs); x ∈ set xs⟧ ⟹ ⨆⇩S (removeAll x xs) ⊔⇩S x = ⨆⇩S xs; pairwise (##⇩S) (set (a # xs)); x ∈ set (a # xs)⟧ ⟹ ⨆⇩S (removeAll x (a # xs)) ⊔⇩S x = ⨆⇩S (a # xs)›*) case Nil (*‹pairwise (##⇩S) (set [])› ‹x ∈ set []›*) then show "?case" (*goal: ‹⨆⇩S (removeAll x []) ⊔⇩S x = ⨆⇩S []›*) by simp next (*goal: ‹⋀a xs. ⟦⟦pairwise (##⇩S) (set xs); x ∈ set xs⟧ ⟹ ⨆⇩S (removeAll x xs) ⊔⇩S x = ⨆⇩S xs; pairwise (##⇩S) (set (a # xs)); x ∈ set (a # xs)⟧ ⟹ ⨆⇩S (removeAll x (a # xs)) ⊔⇩S x = ⨆⇩S (a # xs)›*) case (Cons a xs) (*‹⟦pairwise (##⇩S) (set xs); x ∈ set xs⟧ ⟹ ⨆⇩S (removeAll x xs) ⊔⇩S x = ⨆⇩S xs› ‹pairwise (##⇩S) (set (a # xs))› ‹x ∈ set (a # xs)›*) have x_compat: "⋀ z. z ∈ set xs ⟹ x ##⇩S z" using Cons.prems(1) (*‹pairwise (##⇩S) (set (a # xs))›*) Cons.prems(2) (*‹(x::'a scene) ∈ set ((a::'a scene) # (xs::'a scene list))›*) scene_compats_members (*‹⟦pairwise (##⇩S) (?A::?'a scene set); (?x::?'a scene) ∈ ?A; (?y::?'a scene) ∈ ?A⟧ ⟹ ?x ##⇩S ?y›*) by auto from Cons (*‹⟦pairwise (##⇩S) (set xs); x ∈ set xs⟧ ⟹ ⨆⇩S (removeAll x xs) ⊔⇩S x = ⨆⇩S xs› ‹pairwise (##⇩S) (set (a # xs))› ‹x ∈ set (a # xs)›*) have x_compats: "x ##⇩S ⨆⇩S (removeAll x xs)" by (metis (no_types, lifting) insert_Diff (*‹?a ∈ ?A ⟹ insert ?a (?A - {?a}) = ?A›*) list.simps( (*‹set (?x21.0 # ?x22.0) = insert ?x21.0 (set ?x22.0)›*) 15) pairwise_compat_foldr (*‹⟦pairwise (##⇩S) (set ?as); ∀b∈set ?as. ?a ##⇩S b⟧ ⟹ ?a ##⇩S ⨆⇩S ?as›*) pairwise_insert (*‹pairwise ?r (insert ?x ?s) = ((∀y. y ∈ ?s ∧ y ≠ ?x ⟶ ?r ?x y ∧ ?r y ?x) ∧ pairwise ?r ?s)›*) removeAll_id (*‹?x ∉ set ?xs ⟹ removeAll ?x ?xs = ?xs›*) set_removeAll (*‹set (removeAll ?x ?xs) = set ?xs - {?x}›*) x_compat (*‹?z ∈ set xs ⟹ x ##⇩S ?z›*)) from Cons (*‹⟦pairwise (##⇩S) (set xs); x ∈ set xs⟧ ⟹ ⨆⇩S (removeAll x xs) ⊔⇩S x = ⨆⇩S xs› ‹pairwise (##⇩S) (set (a # xs))› ‹x ∈ set (a # xs)›*) have a_compats: "a ##⇩S ⨆⇩S (removeAll x xs)" by (metis (no_types, lifting) insert_Diff (*‹?a ∈ ?A ⟹ insert ?a (?A - {?a}) = ?A›*) insert_iff (*‹(?a ∈ insert ?b ?A) = (?a = ?b ∨ ?a ∈ ?A)›*) list.simps( (*‹set (?x21.0 # ?x22.0) = insert ?x21.0 (set ?x22.0)›*) 15) pairwise_compat_foldr (*‹⟦pairwise (##⇩S) (set ?as); ∀b∈set ?as. ?a ##⇩S b⟧ ⟹ ?a ##⇩S ⨆⇩S ?as›*) pairwise_insert (*‹pairwise ?r (insert ?x ?s) = ((∀y. y ∈ ?s ∧ y ≠ ?x ⟶ ?r ?x y ∧ ?r y ?x) ∧ pairwise ?r ?s)›*) scene_compat_refl (*‹?X ##⇩S ?X›*) set_removeAll (*‹set (removeAll ?x ?xs) = set ?xs - {?x}›*) x_compats (*‹x ##⇩S ⨆⇩S (removeAll x xs)›*)) from Cons (*‹⟦pairwise (##⇩S) (set xs); x ∈ set xs⟧ ⟹ ⨆⇩S (removeAll x xs) ⊔⇩S x = ⨆⇩S xs› ‹pairwise (##⇩S) (set (a # xs))› ‹(x::'a scene) ∈ set ((a::'a scene) # (xs::'a scene list))›*) show "?case" (*goal: ‹⨆⇩S (removeAll x (a # xs)) ⊔⇩S x = ⨆⇩S (a # xs)›*) proof (cases "x ∈ set xs") (*goals: 1. ‹⟦⟦pairwise (##⇩S) (set (xs::'a scene list)); (x::'a scene) ∈ set xs⟧ ⟹ ⨆⇩S (removeAll x xs) ⊔⇩S x = ⨆⇩S xs; pairwise (##⇩S) (set ((a::'a scene) # xs)); x ∈ set (a # xs); x ∈ set xs⟧ ⟹ ⨆⇩S (removeAll x (a # xs)) ⊔⇩S x = ⨆⇩S (a # xs)› 2. ‹⟦⟦pairwise (##⇩S) (set (xs::'a scene list)); (x::'a scene) ∈ set xs⟧ ⟹ ⨆⇩S (removeAll x xs) ⊔⇩S x = ⨆⇩S xs; pairwise (##⇩S) (set ((a::'a scene) # xs)); x ∈ set (a # xs); x ∉ set xs⟧ ⟹ ⨆⇩S (removeAll x (a # xs)) ⊔⇩S x = ⨆⇩S (a # xs)›*) case True (*‹x ∈ set xs›*) with Cons (*‹⟦pairwise (##⇩S) (set xs); x ∈ set xs⟧ ⟹ ⨆⇩S (removeAll x xs) ⊔⇩S x = ⨆⇩S xs› ‹pairwise (##⇩S) (set ((a::'a scene) # (xs::'a scene list)))› ‹x ∈ set (a # xs)›*) show "?thesis" (*goal: ‹⨆⇩S (removeAll x (a # xs)) ⊔⇩S x = ⨆⇩S (a # xs)›*) apply (auto simp add: pairwise_insert (*‹pairwise ?r (insert ?x ?s) = ((∀y. y ∈ ?s ∧ y ≠ ?x ⟶ ?r ?x y ∧ ?r y ?x) ∧ pairwise ?r ?s)›*) scene_union_commute (*‹?X ⊔⇩S ?Y = ?Y ⊔⇩S ?X›*)) (*goals: 1. ‹⟦(a::'a scene) ⊔⇩S ⨆⇩S (removeAll a (xs::'a scene list)) = ⨆⇩S xs; a ∈ set xs; ∀y::'a scene. y ∈ set xs ∧ y ≠ a ⟶ a ##⇩S y ∧ y ##⇩S a; pairwise (##⇩S) (set xs); (x::'a scene) = a⟧ ⟹ ⨆⇩S xs = a ⊔⇩S ⨆⇩S xs› 2. ‹⟦(x::'a scene) ⊔⇩S ⨆⇩S (removeAll x (xs::'a scene list)) = ⨆⇩S xs; x ∈ set xs; ∀y::'a scene. y ∈ set xs ∧ y ≠ (a::'a scene) ⟶ a ##⇩S y ∧ y ##⇩S a; pairwise (##⇩S) (set xs); x ≠ a⟧ ⟹ x ⊔⇩S (a ⊔⇩S ⨆⇩S (removeAll x xs)) = a ⊔⇩S ⨆⇩S xs› discuss goal 1*) apply (metis a_compats (*‹(a::'a scene) ##⇩S ⨆⇩S (removeAll (x::'a scene) (xs::'a scene list))›*) scene_compats_members (*‹⟦pairwise (##⇩S) (?A::?'a scene set); (?x::?'a scene) ∈ ?A; (?y::?'a scene) ∈ ?A⟧ ⟹ ?x ##⇩S ?y›*) scene_union_assoc (*‹⟦(?X::?'a scene) ##⇩S (?Y::?'a scene); ?X ##⇩S (?Z::?'a scene); ?Y ##⇩S ?Z⟧ ⟹ ?X ⊔⇩S (?Y ⊔⇩S ?Z) = ?X ⊔⇩S ?Y ⊔⇩S ?Z›*) scene_union_idem (*‹(?X::?'a scene) ⊔⇩S ?X = ?X›*)) (*discuss goal 2*) apply (metis (full_types) a_compats (*‹a ##⇩S ⨆⇩S (removeAll x xs)›*) scene_union_assoc (*‹⟦?X ##⇩S ?Y; ?X ##⇩S ?Z; ?Y ##⇩S ?Z⟧ ⟹ ?X ⊔⇩S (?Y ⊔⇩S ?Z) = ?X ⊔⇩S ?Y ⊔⇩S ?Z›*) scene_union_commute (*‹?X ⊔⇩S ?Y = ?Y ⊔⇩S ?X›*) x_compats (*‹x ##⇩S ⨆⇩S (removeAll x xs)›*)) (*proven 2 subgoals*) . next (*goal: ‹⟦⟦pairwise (##⇩S) (set xs); x ∈ set xs⟧ ⟹ ⨆⇩S (removeAll x xs) ⊔⇩S x = ⨆⇩S xs; pairwise (##⇩S) (set (a # xs)); x ∈ set (a # xs); x ∉ set xs⟧ ⟹ ⨆⇩S (removeAll x (a # xs)) ⊔⇩S x = ⨆⇩S (a # xs)›*) case False (*‹x ∉ set xs›*) with Cons (*‹⟦pairwise (##⇩S) (set xs); x ∈ set xs⟧ ⟹ ⨆⇩S (removeAll x xs) ⊔⇩S x = ⨆⇩S xs› ‹pairwise (##⇩S) (set (a # xs))› ‹x ∈ set (a # xs)›*) show "?thesis" (*goal: ‹⨆⇩S (removeAll (x::'a scene) ((a::'a scene) # (xs::'a scene list))) ⊔⇩S x = ⨆⇩S (a # xs)›*) by (simp add: scene_union_commute (*‹?X ⊔⇩S ?Y = ?Y ⊔⇩S ?X›*)) qed qed lemma foldr_scene_union_eq_sets: assumes "pairwise (##⇩S) (set xs)" "set xs = set ys" shows "⨆⇩S xs = ⨆⇩S ys" using assms (*‹pairwise (##⇩S) (set xs)› ‹set xs = set ys›*) proof (induct xs arbitrary: ys) (*goals: 1. ‹⋀ys::'a scene list. ⟦pairwise (##⇩S) (set []); set [] = set ys⟧ ⟹ ⨆⇩S [] = ⨆⇩S ys› 2. ‹⋀(a::'a scene) (xs::'a scene list) ys::'a scene list. ⟦⋀ys::'a scene list. ⟦pairwise (##⇩S) (set xs); set xs = set ys⟧ ⟹ ⨆⇩S xs = ⨆⇩S ys; pairwise (##⇩S) (set (a # xs)); set (a # xs) = set ys⟧ ⟹ ⨆⇩S (a # xs) = ⨆⇩S ys›*) case Nil (*‹pairwise (##⇩S) (set [])› ‹set [] = set ys›*) then show "?case" (*goal: ‹⨆⇩S [] = ⨆⇩S ys›*) by simp next (*goal: ‹⋀a xs ys. ⟦⋀ys. ⟦pairwise (##⇩S) (set xs); set xs = set ys⟧ ⟹ ⨆⇩S xs = ⨆⇩S ys; pairwise (##⇩S) (set (a # xs)); set (a # xs) = set ys⟧ ⟹ ⨆⇩S (a # xs) = ⨆⇩S ys›*) case (Cons a xs) (*‹⟦pairwise (##⇩S) (set xs); set xs = set ?ys⟧ ⟹ ⨆⇩S xs = ⨆⇩S ?ys› ‹pairwise (##⇩S) (set ((a::'a scene) # (xs::'a scene list)))› ‹set (a # xs) = set ys›*) hence ys: "set ys = insert a (set (removeAll a ys))" by auto then show "?case" (*goal: ‹⨆⇩S ((a::'a::type scene) # (xs::'a::type scene list)) = ⨆⇩S (ys::'a::type scene list)›*) by (metis (no_types, lifting) Cons.hyps (*‹⟦pairwise (##⇩S) (set (xs::'a scene list)); set xs = set (?ys::'a scene list)⟧ ⟹ ⨆⇩S xs = ⨆⇩S ?ys›*) Cons.prems( (*‹pairwise (##⇩S) (set ((a::'a scene) # (xs::'a scene list)))›*) 1) Cons.prems( (*‹set ((a::'a scene) # (xs::'a scene list)) = set (ys::'a scene list)›*) 2) Diff_insert_absorb (*‹(?x::?'a) ∉ (?A::?'a set) ⟹ insert ?x ?A - {?x} = ?A›*) foldr_scene_union_removeAll (*‹⟦pairwise (##⇩S) (set (?xs::?'a scene list)); (?x::?'a scene) ∈ set ?xs⟧ ⟹ ⨆⇩S (removeAll ?x ?xs) ⊔⇩S ?x = ⨆⇩S ?xs›*) insertCI (*‹((?a::?'a) ∉ (?B::?'a set) ⟹ ?a = (?b::?'a)) ⟹ ?a ∈ insert ?b ?B›*) insert_absorb (*‹(?a::?'a) ∈ (?A::?'a set) ⟹ insert ?a ?A = ?A›*) list.simps( (*‹set ((?x21.0::?'a) # (?x22.0::?'a list)) = insert ?x21.0 (set ?x22.0)›*) 15) pairwise_insert (*‹pairwise (?r::?'a ⇒ ?'a ⇒ bool) (insert (?x::?'a) (?s::?'a set)) = ((∀y::?'a. y ∈ ?s ∧ y ≠ ?x ⟶ ?r ?x y ∧ ?r y ?x) ∧ pairwise ?r ?s)›*) set_removeAll (*‹set (removeAll (?x::?'a) (?xs::?'a list)) = set ?xs - {?x}›*)) qed lemma foldr_scene_removeAll: assumes "pairwise (##⇩S) (set xs)" shows "x ⊔⇩S ⨆⇩S (removeAll x xs) = x ⊔⇩S ⨆⇩S xs" by (metis (mono_tags, opaque_lifting) assms (*‹pairwise (##⇩S) (set xs)›*) foldr_Cons (*‹foldr ?f (?x # ?xs) = ?f ?x ∘ foldr ?f ?xs›*) foldr_scene_union_eq_sets (*‹⟦pairwise (##⇩S) (set ?xs); set ?xs = set ?ys⟧ ⟹ ⨆⇩S ?xs = ⨆⇩S ?ys›*) insertCI (*‹(?a ∉ ?B ⟹ ?a = ?b) ⟹ ?a ∈ insert ?b ?B›*) insert_Diff (*‹?a ∈ ?A ⟹ insert ?a (?A - {?a}) = ?A›*) list.simps( (*‹set (?x21.0 # ?x22.0) = insert ?x21.0 (set ?x22.0)›*) 15) o_apply (*‹(?f ∘ ?g) ?x = ?f (?g ?x)›*) removeAll.simps( (*‹removeAll ?x (?y # ?xs) = (if ?x = ?y then removeAll ?x ?xs else ?y # removeAll ?x ?xs)›*) 2) removeAll_id (*‹?x ∉ set ?xs ⟹ removeAll ?x ?xs = ?xs›*) set_removeAll (*‹set (removeAll ?x ?xs) = set ?xs - {?x}›*)) lemma pairwise_Collect: "pairwise R A ⟹ pairwise R {x ∈ A. P x}" by (simp add: pairwise_def (*‹pairwise (?R::?'a ⇒ ?'a ⇒ bool) (?S::?'a set) = (∀x::?'a∈?S. ∀y::?'a∈?S. x ≠ y ⟶ ?R x y)›*)) lemma removeAll_overshadow_filter: "removeAll x (filter (λxa. xa ∉ A - {x}) xs) = removeAll x (filter (λ xa. xa ∉ A) xs)" apply (simp add: removeAll_filter_not_eq (*‹removeAll (?x::?'a::type) = filter ((≠) ?x)›*)) (*goal: ‹removeAll x (filter (λxa. xa ∉ A - {x}) xs) = removeAll x (filter (λxa. xa ∉ A) xs)›*) apply (rule filter_cong (*‹⟦?xs = ?ys; ⋀x. x ∈ set ?ys ⟹ ?P x = ?Q x⟧ ⟹ filter ?P ?xs = filter ?Q ?ys›*)) (*goals: 1. ‹xs = xs› 2. ‹⋀xa. xa ∈ set xs ⟹ ((xa ∈ A ⟶ xa = x) ∧ x ≠ xa) = (xa ∉ A ∧ x ≠ xa)› discuss goal 1*) apply simp (*discuss goal 2*) apply auto (*proven 2 subgoals*) . corollary foldr_scene_union_filter: assumes "pairwise (##⇩S) (set xs)" "set ys ⊆ set xs" shows "⨆⇩S xs = ⨆⇩S (filter (λx. x ∉ set ys) xs) ⊔⇩S ⨆⇩S ys" using assms (*‹pairwise (##⇩S) (set xs)› ‹set ys ⊆ set xs›*) proof (induct xs arbitrary: ys) (*goals: 1. ‹⋀ys::'a::type scene list. ⟦pairwise (##⇩S) (set []); set ys ⊆ set []⟧ ⟹ ⨆⇩S [] = ⨆⇩S (filter (λx::'a::type scene. x ∉ set ys) []) ⊔⇩S ⨆⇩S ys› 2. ‹⋀(a::'a::type scene) (xs::'a::type scene list) ys::'a::type scene list. ⟦⋀ys::'a::type scene list. ⟦pairwise (##⇩S) (set xs); set ys ⊆ set xs⟧ ⟹ ⨆⇩S xs = ⨆⇩S (filter (λx::'a::type scene. x ∉ set ys) xs) ⊔⇩S ⨆⇩S ys; pairwise (##⇩S) (set (a # xs)); set ys ⊆ set (a # xs)⟧ ⟹ ⨆⇩S (a # xs) = ⨆⇩S (filter (λx::'a::type scene. x ∉ set ys) (a # xs)) ⊔⇩S ⨆⇩S ys›*) case Nil (*‹pairwise (##⇩S) (set [])› ‹set ys ⊆ set []›*) then show "?case" (*goal: ‹⨆⇩S [] = ⨆⇩S (filter (λx. x ∉ set ys) []) ⊔⇩S ⨆⇩S ys›*) by simp next (*goal: ‹⋀a xs ys. ⟦⋀ys. ⟦pairwise (##⇩S) (set xs); set ys ⊆ set xs⟧ ⟹ ⨆⇩S xs = ⨆⇩S (filter (λx. x ∉ set ys) xs) ⊔⇩S ⨆⇩S ys; pairwise (##⇩S) (set (a # xs)); set ys ⊆ set (a # xs)⟧ ⟹ ⨆⇩S (a # xs) = ⨆⇩S (filter (λx. x ∉ set ys) (a # xs)) ⊔⇩S ⨆⇩S ys›*) case (Cons x xs) (*‹⟦pairwise (##⇩S) (set xs); set ?ys ⊆ set xs⟧ ⟹ ⨆⇩S xs = ⨆⇩S (filter (λx. x ∉ set ?ys) xs) ⊔⇩S ⨆⇩S ?ys› ‹pairwise (##⇩S) (set (x # xs))› ‹set (ys::'a scene list) ⊆ set ((x::'a scene) # (xs::'a scene list))›*) show "?case" (*goal: ‹⨆⇩S (x # xs) = ⨆⇩S (filter (λx. x ∉ set ys) (x # xs)) ⊔⇩S ⨆⇩S ys›*) proof (cases "x ∈ set ys") (*goals: 1. ‹x ∈ set ys ⟹ ⨆⇩S (x # xs) = ⨆⇩S (filter (λx. x ∉ set ys) (x # xs)) ⊔⇩S ⨆⇩S ys› 2. ‹x ∉ set ys ⟹ ⨆⇩S (x # xs) = ⨆⇩S (filter (λx. x ∉ set ys) (x # xs)) ⊔⇩S ⨆⇩S ys›*) case True (*‹x ∈ set ys›*) with Cons (*‹⟦pairwise (##⇩S) (set xs); set ?ys ⊆ set xs⟧ ⟹ ⨆⇩S xs = ⨆⇩S (filter (λx. x ∉ set ?ys) xs) ⊔⇩S ⨆⇩S ?ys› ‹pairwise (##⇩S) (set (x # xs))› ‹set ys ⊆ set (x # xs)›*) have 1: "set ys - {x} ⊆ set xs" by auto have 2: "x ##⇩S ⨆⇩S (removeAll x ys)" by (metis Cons.prems( (*‹pairwise (##⇩S) (set (x # xs))›*) 1) Cons.prems( (*‹set ys ⊆ set (x # xs)›*) 2) True (*‹x ∈ set ys›*) foldr_scene_removeAll (*‹pairwise (##⇩S) (set ?xs) ⟹ ?x ⊔⇩S ⨆⇩S (removeAll ?x ?xs) = ?x ⊔⇩S ⨆⇩S ?xs›*) foldr_scene_union_removeAll (*‹⟦pairwise (##⇩S) (set ?xs); ?x ∈ set ?xs⟧ ⟹ ⨆⇩S (removeAll ?x ?xs) ⊔⇩S ?x = ⨆⇩S ?xs›*) pairwise_subset (*‹⟦pairwise ?P ?S; ?T ⊆ ?S⟧ ⟹ pairwise ?P ?T›*) scene_compat_bot( (*‹⊥⇩S ##⇩S ?a›*) 2) scene_compat_sym (*‹?X ##⇩S ?Y ⟹ ?Y ##⇩S ?X›*) scene_union_incompat (*‹¬ ?X ##⇩S ?Y ⟹ ?X ⊔⇩S ?Y = ⊥⇩S›*) scene_union_unit( (*‹?X ⊔⇩S ⊥⇩S = ?X›*) 1)) have 3: "⋀ P. x ##⇩S ⨆⇩S (filter P xs)" by (meson Cons.prems( (*‹pairwise (##⇩S) (set ((x::'a::type scene) # (xs::'a::type scene list)))›*) 1) Cons.prems( (*‹set (ys::'a::type scene list) ⊆ set ((x::'a::type scene) # (xs::'a::type scene list))›*) 2) True (*‹(x::'a::type scene) ∈ set (ys::'a::type scene list)›*) filter_is_subset (*‹set (filter (?P::?'a::type ⇒ bool) (?xs::?'a::type list)) ⊆ set ?xs›*) in_mono (*‹(?A::?'a::type set) ⊆ (?B::?'a::type set) ⟹ (?x::?'a::type) ∈ ?A ⟶ ?x ∈ ?B›*) pairwise_compat_foldr (*‹⟦pairwise (##⇩S) (set (?as::?'a::type scene list)); ∀b::?'a::type scene∈set ?as. (?a::?'a::type scene) ##⇩S b⟧ ⟹ ?a ##⇩S ⨆⇩S ?as›*) pairwise_subset (*‹⟦pairwise (?P::?'a::type ⇒ ?'a::type ⇒ bool) (?S::?'a::type set); (?T::?'a::type set) ⊆ ?S⟧ ⟹ pairwise ?P ?T›*) scene_compats_members (*‹⟦pairwise (##⇩S) (?A::?'a::type scene set); (?x::?'a::type scene) ∈ ?A; (?y::?'a::type scene) ∈ ?A⟧ ⟹ ?x ##⇩S ?y›*) set_subset_Cons (*‹set (?xs::?'a::type list) ⊆ set ((?x::?'a::type) # ?xs)›*)) have 4: "⋀ P. ⨆⇩S (filter P xs) ##⇩S ⨆⇩S (removeAll x ys)" apply (rule pairwise_compat_foldr (*‹⟦pairwise (##⇩S) (set ?as); ∀b∈set ?as. ?a ##⇩S b⟧ ⟹ ?a ##⇩S ⨆⇩S ?as›*)) (*goals: 1. ‹⋀P::'a scene ⇒ bool. pairwise (##⇩S) (set (removeAll (x::'a scene) (ys::'a scene list)))› 2. ‹⋀P::'a scene ⇒ bool. ∀b::'a scene∈set (removeAll (x::'a scene) (ys::'a scene list)). ⨆⇩S (filter P (xs::'a scene list)) ##⇩S b› discuss goal 1*) apply (metis Cons.prems( (*‹pairwise (##⇩S) (set ((x::'a::type scene) # (xs::'a::type scene list)))›*) 1) Cons.prems( (*‹set (ys::'a::type scene list) ⊆ set ((x::'a::type scene) # (xs::'a::type scene list))›*) 2) pairwise_Diff (*‹pairwise (?R::?'a::type ⇒ ?'a::type ⇒ bool) (?A::?'a::type set) ⟹ pairwise ?R (?A - (?B::?'a::type set))›*) pairwise_subset (*‹⟦pairwise (?P::?'a::type ⇒ ?'a::type ⇒ bool) (?S::?'a::type set); (?T::?'a::type set) ⊆ ?S⟧ ⟹ pairwise ?P ?T›*) set_removeAll (*‹set (removeAll (?x::?'a::type) (?xs::?'a::type list)) = set ?xs - {?x}›*)) (*discuss goal 2*) apply (metis (no_types, lifting) "1" (*‹set (ys::'a scene list) - {x::'a scene} ⊆ set (xs::'a scene list)›*) Cons.prems( (*‹pairwise (##⇩S) (set ((x::'a scene) # (xs::'a scene list)))›*) 1) filter_is_subset (*‹set (filter (?P::?'a ⇒ bool) (?xs::?'a list)) ⊆ set ?xs›*) pairwise_compat_foldr (*‹⟦pairwise (##⇩S) (set (?as::?'a scene list)); ∀b::?'a scene∈set ?as. (?a::?'a scene) ##⇩S b⟧ ⟹ ?a ##⇩S ⨆⇩S ?as›*) pairwise_subset (*‹⟦pairwise (?P::?'a ⇒ ?'a ⇒ bool) (?S::?'a set); (?T::?'a set) ⊆ ?S⟧ ⟹ pairwise ?P ?T›*) scene_compat_sym (*‹(?X::?'a scene) ##⇩S (?Y::?'a scene) ⟹ ?Y ##⇩S ?X›*) scene_compats_members (*‹⟦pairwise (##⇩S) (?A::?'a scene set); (?x::?'a scene) ∈ ?A; (?y::?'a scene) ∈ ?A⟧ ⟹ ?x ##⇩S ?y›*) set_removeAll (*‹set (removeAll (?x::?'a) (?xs::?'a list)) = set ?xs - {?x}›*) set_subset_Cons (*‹set (?xs::?'a list) ⊆ set ((?x::?'a) # ?xs)›*) subsetD (*‹⟦(?A::?'a set) ⊆ (?B::?'a set); (?c::?'a) ∈ ?A⟧ ⟹ ?c ∈ ?B›*)) (*proven 2 subgoals*) . have "⨆⇩S (x # xs) = x ⊔⇩S ⨆⇩S xs" by simp also (*calculation: ‹⨆⇩S (x # xs) = x ⊔⇩S ⨆⇩S xs›*) have "... = x ⊔⇩S (⨆⇩S (filter (λxa. xa ∉ set ys - {x}) xs) ⊔⇩S ⨆⇩S (removeAll x ys))" using "1" (*‹set ys - {x} ⊆ set xs›*) Cons(1)[where ys = "removeAll x ys"] (*‹⟦pairwise (##⇩S) (set xs); set (removeAll x ys) ⊆ set xs⟧ ⟹ ⨆⇩S xs = ⨆⇩S (filter (λxa. xa ∉ set (removeAll x ys)) xs) ⊔⇩S ⨆⇩S (removeAll x ys)›*) Cons(2) (*‹pairwise (##⇩S) (set (x # xs))›*) by (simp add: pairwise_insert (*‹pairwise (?r::?'a ⇒ ?'a ⇒ bool) (insert (?x::?'a) (?s::?'a set)) = ((∀y::?'a. y ∈ ?s ∧ y ≠ ?x ⟶ ?r ?x y ∧ ?r y ?x) ∧ pairwise ?r ?s)›*)) also (*calculation: ‹⨆⇩S (x # xs) = x ⊔⇩S (⨆⇩S (filter (λxa. xa ∉ set ys - {x}) xs) ⊔⇩S ⨆⇩S (removeAll x ys))›*) have "... = (x ⊔⇩S ⨆⇩S (filter (λxa. xa ∉ set ys - {x}) xs)) ⊔⇩S ⨆⇩S (removeAll x ys)" by (simp add: scene_union_assoc (*‹⟦?X ##⇩S ?Y; ?X ##⇩S ?Z; ?Y ##⇩S ?Z⟧ ⟹ ?X ⊔⇩S (?Y ⊔⇩S ?Z) = ?X ⊔⇩S ?Y ⊔⇩S ?Z›*) 1 (*‹set ys - {x} ⊆ set xs›*) 2 (*‹x ##⇩S ⨆⇩S (removeAll x ys)›*) 3 (*‹x ##⇩S ⨆⇩S (filter ?P xs)›*) 4 (*‹⨆⇩S (filter ?P xs) ##⇩S ⨆⇩S (removeAll x ys)›*)) also (*calculation: ‹⨆⇩S (x # xs) = x ⊔⇩S ⨆⇩S (filter (λxa. xa ∉ set ys - {x}) xs) ⊔⇩S ⨆⇩S (removeAll x ys)›*) have "... = (x ⊔⇩S ⨆⇩S (removeAll x (filter (λxa. xa ∉ set ys - {x}) xs))) ⊔⇩S ⨆⇩S (removeAll x ys)" by (metis (no_types, lifting) Cons.prems( (*‹pairwise (##⇩S) (set (x # xs))›*) 1) filter_is_subset (*‹set (filter ?P ?xs) ⊆ set ?xs›*) foldr_scene_removeAll (*‹pairwise (##⇩S) (set ?xs) ⟹ ?x ⊔⇩S ⨆⇩S (removeAll ?x ?xs) = ?x ⊔⇩S ⨆⇩S ?xs›*) pairwise_subset (*‹⟦pairwise ?P ?S; ?T ⊆ ?S⟧ ⟹ pairwise ?P ?T›*) set_subset_Cons (*‹set ?xs ⊆ set (?x # ?xs)›*)) also (*calculation: ‹⨆⇩S (x # xs) = x ⊔⇩S ⨆⇩S (removeAll x (filter (λxa. xa ∉ set ys - {x}) xs)) ⊔⇩S ⨆⇩S (removeAll x ys)›*) have "... = (x ⊔⇩S ⨆⇩S (removeAll x (filter (λxa. xa ∉ set ys) xs))) ⊔⇩S ⨆⇩S (removeAll x ys)" by (simp only: removeAll_overshadow_filter (*‹removeAll ?x (filter (λxa. xa ∉ ?A - {?x}) ?xs) = removeAll ?x (filter (λxa. xa ∉ ?A) ?xs)›*)) also (*calculation: ‹⨆⇩S (x # xs) = x ⊔⇩S ⨆⇩S (removeAll x (filter (λxa. xa ∉ set ys) xs)) ⊔⇩S ⨆⇩S (removeAll x ys)›*) have "... = (x ⊔⇩S ⨆⇩S (removeAll x (filter (λxa. xa ∉ set ys) (x # xs)))) ⊔⇩S ⨆⇩S (removeAll x ys)" by simp also (*calculation: ‹⨆⇩S (x # xs) = x ⊔⇩S ⨆⇩S (removeAll x (filter (λxa. xa ∉ set ys) (x # xs))) ⊔⇩S ⨆⇩S (removeAll x ys)›*) have "... = (x ⊔⇩S ⨆⇩S (filter (λxa. xa ∉ set ys) (x # xs))) ⊔⇩S ⨆⇩S (removeAll x ys)" by (simp add: True (*‹x ∈ set ys›*)) also (*calculation: ‹⨆⇩S (x # xs) = x ⊔⇩S ⨆⇩S (filter (λxa. xa ∉ set ys) (x # xs)) ⊔⇩S ⨆⇩S (removeAll x ys)›*) have "... = (⨆⇩S (filter (λxa. xa ∉ set ys) (x # xs)) ⊔⇩S x) ⊔⇩S ⨆⇩S (removeAll x ys)" by (simp add: scene_union_commute (*‹?X ⊔⇩S ?Y = ?Y ⊔⇩S ?X›*)) also (*calculation: ‹⨆⇩S (x # xs) = ⨆⇩S (filter (λxa. xa ∉ set ys) (x # xs)) ⊔⇩S x ⊔⇩S ⨆⇩S (removeAll x ys)›*) have "... = ⨆⇩S (filter (λxa. xa ∉ set ys) (x # xs)) ⊔⇩S (x ⊔⇩S ⨆⇩S (removeAll x ys))" by (simp add: scene_union_assoc (*‹⟦(?X::?'a scene) ##⇩S (?Y::?'a scene); ?X ##⇩S (?Z::?'a scene); ?Y ##⇩S ?Z⟧ ⟹ ?X ⊔⇩S (?Y ⊔⇩S ?Z) = ?X ⊔⇩S ?Y ⊔⇩S ?Z›*) True (*‹(x::'a scene) ∈ set (ys::'a scene list)›*) 2 (*‹(x::'a scene) ##⇩S ⨆⇩S (removeAll x (ys::'a scene list))›*) 3 (*‹(x::'a scene) ##⇩S ⨆⇩S (filter (?P::'a scene ⇒ bool) (xs::'a scene list))›*) 4 (*‹⨆⇩S (filter (?P::'a scene ⇒ bool) (xs::'a scene list)) ##⇩S ⨆⇩S (removeAll (x::'a scene) (ys::'a scene list))›*) scene_compat_sym (*‹(?X::?'a scene) ##⇩S (?Y::?'a scene) ⟹ ?Y ##⇩S ?X›*)) also (*calculation: ‹⨆⇩S (x # xs) = ⨆⇩S (filter (λxa. xa ∉ set ys) (x # xs)) ⊔⇩S (x ⊔⇩S ⨆⇩S (removeAll x ys))›*) have "... = ⨆⇩S (filter (λxa. xa ∉ set ys) (x # xs)) ⊔⇩S ⨆⇩S ys" by (metis (no_types, lifting) Cons.prems( (*‹pairwise (##⇩S) (set (x # xs))›*) 1) Cons.prems( (*‹set ys ⊆ set (x # xs)›*) 2) True (*‹x ∈ set ys›*) foldr_scene_union_removeAll (*‹⟦pairwise (##⇩S) (set ?xs); ?x ∈ set ?xs⟧ ⟹ ⨆⇩S (removeAll ?x ?xs) ⊔⇩S ?x = ⨆⇩S ?xs›*) pairwise_subset (*‹⟦pairwise ?P ?S; ?T ⊆ ?S⟧ ⟹ pairwise ?P ?T›*) scene_union_commute (*‹?X ⊔⇩S ?Y = ?Y ⊔⇩S ?X›*)) finally (*calculation: ‹⨆⇩S (x # xs) = ⨆⇩S (filter (λxa. xa ∉ set ys) (x # xs)) ⊔⇩S ⨆⇩S ys›*) show "?thesis" (*goal: ‹⨆⇩S (x # xs) = ⨆⇩S (filter (λx. x ∉ set ys) (x # xs)) ⊔⇩S ⨆⇩S ys›*) . next (*goal: ‹x ∉ set ys ⟹ ⨆⇩S (x # xs) = ⨆⇩S (filter (λx. x ∉ set ys) (x # xs)) ⊔⇩S ⨆⇩S ys›*) case False (*‹x ∉ set ys›*) with Cons(2-3) (*‹pairwise (##⇩S) (set (x # xs))› ‹set ys ⊆ set (x # xs)›*) have 1: "set ys ⊆ set xs" by auto have 2: "x ##⇩S ⨆⇩S (filter (λx. x ∉ set ys) xs)" by (metis (no_types, lifting) Cons.prems( (*‹pairwise (##⇩S) (set ((x::'a scene) # (xs::'a scene list)))›*) 1) filter_is_subset (*‹set (filter (?P::?'a ⇒ bool) (?xs::?'a list)) ⊆ set ?xs›*) filter_set (*‹Set.filter (?P::?'a ⇒ bool) (set (?xs::?'a list)) = set (filter ?P ?xs)›*) list.simps( (*‹set ((?x21.0::?'a) # (?x22.0::?'a list)) = insert ?x21.0 (set ?x22.0)›*) 15) member_filter (*‹((?x::?'a) ∈ Set.filter (?P::?'a ⇒ bool) (?A::?'a set)) = (?x ∈ ?A ∧ ?P ?x)›*) pairwise_compat_foldr (*‹⟦pairwise (##⇩S) (set (?as::?'a scene list)); ∀b::?'a scene∈set ?as. (?a::?'a scene) ##⇩S b⟧ ⟹ ?a ##⇩S ⨆⇩S ?as›*) pairwise_insert (*‹pairwise (?r::?'a ⇒ ?'a ⇒ bool) (insert (?x::?'a) (?s::?'a set)) = ((∀y::?'a. y ∈ ?s ∧ y ≠ ?x ⟶ ?r ?x y ∧ ?r y ?x) ∧ pairwise ?r ?s)›*) pairwise_subset (*‹⟦pairwise (?P::?'a ⇒ ?'a ⇒ bool) (?S::?'a set); (?T::?'a set) ⊆ ?S⟧ ⟹ pairwise ?P ?T›*) scene_compat_refl (*‹(?X::?'a scene) ##⇩S ?X›*)) have 3: "x ##⇩S ⨆⇩S ys" by (meson Cons.prems( (*‹pairwise (##⇩S) (set (x # xs))›*) 1) Cons.prems( (*‹set ys ⊆ set (x # xs)›*) 2) list.set_intros( (*‹?x21.0 ∈ set (?x21.0 # ?x22.0)›*) 1) pairwise_compat_foldr (*‹⟦pairwise (##⇩S) (set ?as); ∀b∈set ?as. ?a ##⇩S b⟧ ⟹ ?a ##⇩S ⨆⇩S ?as›*) pairwise_subset (*‹⟦pairwise ?P ?S; ?T ⊆ ?S⟧ ⟹ pairwise ?P ?T›*) scene_compats_members (*‹⟦pairwise (##⇩S) ?A; ?x ∈ ?A; ?y ∈ ?A⟧ ⟹ ?x ##⇩S ?y›*) subset_code( (*‹(set ?xs ⊆ ?B) = (∀x∈set ?xs. x ∈ ?B)›*) 1)) from Cons(1)[of ys] (*‹⟦pairwise (##⇩S) (set xs); set ys ⊆ set xs⟧ ⟹ ⨆⇩S xs = ⨆⇩S (filter (λx. x ∉ set ys) xs) ⊔⇩S ⨆⇩S ys›*) Cons(2-3) (*‹pairwise (##⇩S) (set (x # xs))› ‹set ys ⊆ set (x # xs)›*) have 4: "⨆⇩S (filter (λx. x ∉ set ys) xs) ##⇩S ⨆⇩S ys" apply (auto simp add: pairwise_insert (*‹pairwise ?r (insert ?x ?s) = ((∀y. y ∈ ?s ∧ y ≠ ?x ⟶ ?r ?x y ∧ ?r y ?x) ∧ pairwise ?r ?s)›*)) (*goal: ‹⨆⇩S (filter (λx. x ∉ set ys) xs) ##⇩S ⨆⇩S ys›*) by (metis (no_types, lifting) "1" (*‹set (ys::'a::type scene list) ⊆ set (xs::'a::type scene list)›*) foldr_append (*‹foldr (?f::?'b::type ⇒ ?'a::type ⇒ ?'a::type) ((?xs::?'b::type list) @ (?ys::?'b::type list)) (?a::?'a::type) = foldr ?f ?xs (foldr ?f ?ys ?a)›*) foldr_scene_union_eq_sets (*‹⟦pairwise (##⇩S) (set (?xs::?'a::type scene list)); set ?xs = set (?ys::?'a::type scene list)⟧ ⟹ ⨆⇩S ?xs = ⨆⇩S ?ys›*) scene_compat_bot( (*‹(?a::?'a::type scene) ##⇩S ⊥⇩S›*) 1) scene_union_incompat (*‹¬ (?X::?'a::type scene) ##⇩S (?Y::?'a::type scene) ⟹ ?X ⊔⇩S ?Y = ⊥⇩S›*) set_append (*‹set ((?xs::?'a::type list) @ (?ys::?'a::type list)) = set ?xs ∪ set ?ys›*) subset_Un_eq (*‹((?A::?'a::type set) ⊆ (?B::?'a::type set)) = (?A ∪ ?B = ?B)›*)) with "1" (*‹set ys ⊆ set xs›*) False (*‹x ∉ set ys›*) Cons(1)[of ys] (*‹⟦pairwise (##⇩S) (set xs); set ys ⊆ set xs⟧ ⟹ ⨆⇩S xs = ⨆⇩S (filter (λx. x ∉ set ys) xs) ⊔⇩S ⨆⇩S ys›*) Cons(2-3) (*‹pairwise (##⇩S) (set ((x::'a scene) # (xs::'a scene list)))› ‹set ys ⊆ set (x # xs)›*) show "?thesis" (*goal: ‹⨆⇩S (x # xs) = ⨆⇩S (filter (λx. x ∉ set ys) (x # xs)) ⊔⇩S ⨆⇩S ys›*) by (auto simp add: pairwise_insert (*‹pairwise ?r (insert ?x ?s) = ((∀y. y ∈ ?s ∧ y ≠ ?x ⟶ ?r ?x y ∧ ?r y ?x) ∧ pairwise ?r ?s)›*) scene_union_assoc (*‹⟦?X ##⇩S ?Y; ?X ##⇩S ?Z; ?Y ##⇩S ?Z⟧ ⟹ ?X ⊔⇩S (?Y ⊔⇩S ?Z) = ?X ⊔⇩S ?Y ⊔⇩S ?Z›*) 2 (*‹x ##⇩S ⨆⇩S (filter (λx. x ∉ set ys) xs)›*) 3 (*‹x ##⇩S ⨆⇩S ys›*) 4 (*‹⨆⇩S (filter (λx. x ∉ set ys) xs) ##⇩S ⨆⇩S ys›*)) qed qed lemma foldr_scene_append: "⟦ pairwise (##⇩S) (set (xs @ ys)) ⟧ ⟹ ⨆⇩S (xs @ ys) = ⨆⇩S xs ⊔⇩S ⨆⇩S ys" by (simp add: foldr_scene_union_add_tail (*‹⟦pairwise (##⇩S) (set ?xs); ∀x∈set ?xs. x ##⇩S ?b⟧ ⟹ ⨆⇩S ?xs ⊔⇩S ?b = foldr (⊔⇩S) ?xs ?b›*) pairwise_compat_foldr (*‹⟦pairwise (##⇩S) (set ?as); ∀b∈set ?as. ?a ##⇩S b⟧ ⟹ ?a ##⇩S ⨆⇩S ?as›*) pairwise_subset (*‹⟦pairwise ?P ?S; ?T ⊆ ?S⟧ ⟹ pairwise ?P ?T›*) scene_compats_members (*‹⟦pairwise (##⇩S) ?A; ?x ∈ ?A; ?y ∈ ?A⟧ ⟹ ?x ##⇩S ?y›*)) lemma foldr_scene_concat: "⟦ pairwise (##⇩S) (set (concat xs)) ⟧ ⟹ ⨆⇩S (concat xs) = ⨆⇩S (map ⨆⇩S xs)" apply (induct xs) (*goals: 1. ‹pairwise (##⇩S) (set (concat [])) ⟹ ⨆⇩S (concat []) = ⨆⇩S (map ⨆⇩S [])› 2. ‹⋀a xs. ⟦pairwise (##⇩S) (set (concat xs)) ⟹ ⨆⇩S (concat xs) = ⨆⇩S (map ⨆⇩S xs); pairwise (##⇩S) (set (concat (a # xs)))⟧ ⟹ ⨆⇩S (concat (a # xs)) = ⨆⇩S (map ⨆⇩S (a # xs))› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*goal: ‹⋀a xs. ⟦pairwise (##⇩S) (set (concat xs)) ⟹ ⨆⇩S (concat xs) = ⨆⇩S (map ⨆⇩S xs); pairwise (##⇩S) (set (concat (a # xs)))⟧ ⟹ ⨆⇩S (concat (a # xs)) = ⨆⇩S (map ⨆⇩S (a # xs))›*) apply (metis foldr_append (*‹foldr ?f (?xs @ ?ys) ?a = foldr ?f ?xs (foldr ?f ?ys ?a)›*) foldr_scene_append (*‹pairwise (##⇩S) (set (?xs @ ?ys)) ⟹ ⨆⇩S (?xs @ ?ys) = ⨆⇩S ?xs ⊔⇩S ⨆⇩S ?ys›*) pairwise_subset (*‹⟦pairwise ?P ?S; ?T ⊆ ?S⟧ ⟹ pairwise ?P ?T›*) set_append (*‹set (?xs @ ?ys) = set ?xs ∪ set ?ys›*) set_concat (*‹set (concat ?xs) = ⋃ (set ` set ?xs)›*) sup_ge2 (*‹?y ≤ sup ?x ?y›*)) (*proven 2 subgoals*) . subsection ‹ Predicates › text ‹ All scenes in the set are independent › definition scene_indeps :: "'s scene set ⇒ bool" where "scene_indeps = pairwise (⨝⇩S)" text ‹ All scenes in the set cover the entire state space › definition scene_span :: "'s scene list ⇒ bool" where "scene_span S = (foldr (⊔⇩S) S ⊥⇩S = ⊤⇩S)" text ‹ cf. @{term finite_dimensional_vector_space}, which scene spaces are based on. › subsection ‹ Scene space class › class scene_space = fixes Vars :: "'a scene list" assumes idem_scene_Vars [simp]: "⋀ x. x ∈ set Vars ⟹ idem_scene x" and indep_Vars: "scene_indeps (set Vars)" and span_Vars: "scene_span Vars" begin lemma scene_space_compats [simp]: "pairwise (##⇩S) (set Vars)" by (metis local.indep_Vars (*‹scene_indeps (set Vars)›*) pairwise_alt (*‹pairwise ?R ?S = (∀x∈?S. ∀y∈?S - {x}. ?R x y)›*) scene_indep_compat (*‹?X ⨝⇩S ?Y ⟹ ?X ##⇩S ?Y›*) scene_indeps_def (*‹scene_indeps = pairwise (⨝⇩S)›*)) lemma Vars_ext_lens_indep: "⟦ a ;⇩S x ≠ b ;⇩S x; a ∈ set Vars; b ∈ set Vars ⟧ ⟹ a ;⇩S x ⨝⇩S b ;⇩S x" by (metis indep_Vars (*‹scene_indeps (set Vars)›*) pairwiseD (*‹⟦pairwise ?R ?S; ?x ∈ ?S; ?y ∈ ?S; ?x ≠ ?y⟧ ⟹ ?R ?x ?y›*) scene_comp_indep (*‹?A ⨝⇩S ?B ⟹ ?A ;⇩S ?X ⨝⇩S ?B ;⇩S ?X›*) scene_indeps_def (*‹scene_indeps = pairwise (⨝⇩S)›*)) inductive_set scene_space :: "'a scene set" where bot_scene_space [intro]: "⊥⇩S ∈ scene_space" | Vars_scene_space [intro]: "x ∈ set Vars ⟹ x ∈ scene_space" | union_scene_space [intro]: "⟦ x ∈ scene_space; y ∈ scene_space ⟧ ⟹ x ⊔⇩S y ∈ scene_space" lemma idem_scene_space: "a ∈ scene_space ⟹ idem_scene a" apply (induct rule: scene_space.induct (*‹⟦?x ∈ scene_space; ?P ⊥⇩S; ⋀x. x ∈ set Vars ⟹ ?P x; ⋀x y. ⟦x ∈ scene_space; ?P x; y ∈ scene_space; ?P y⟧ ⟹ ?P (x ⊔⇩S y)⟧ ⟹ ?P ?x›*)) (*goals: 1. ‹idem_scene ⊥⇩S› 2. ‹⋀x::'a::type scene. x ∈ set Vars ⟹ idem_scene x› 3. ‹⋀(x::'a::type scene) y::'a::type scene. ⟦x ∈ scene_space; idem_scene x; y ∈ scene_space; idem_scene y⟧ ⟹ idem_scene (x ⊔⇩S y)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . lemma set_Vars_scene_space [simp]: "set Vars ⊆ scene_space" by blast lemma pairwise_compat_Vars_subset: "set xs ⊆ set Vars ⟹ pairwise (##⇩S) (set xs)" using pairwise_subset (*‹⟦pairwise ?P ?S; ?T ⊆ ?S⟧ ⟹ pairwise ?P ?T›*) scene_space_compats (*‹pairwise (##⇩S) (set Vars)›*) by blast lemma scene_space_foldr: "set xs ⊆ scene_space ⟹ ⨆⇩S xs ∈ scene_space" apply (induction xs) (*goals: 1. ‹set [] ⊆ scene_space ⟹ ⨆⇩S [] ∈ scene_space› 2. ‹⋀a xs. ⟦set xs ⊆ scene_space ⟹ ⨆⇩S xs ∈ scene_space; set (a # xs) ⊆ scene_space⟧ ⟹ ⨆⇩S (a # xs) ∈ scene_space› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma top_scene_eq: "⊤⇩S = ⨆⇩S Vars" using local.span_Vars (*‹scene_span Vars›*) scene_span_def (*‹scene_span (?S::?'s scene list) = (⨆⇩S ?S = ⊤⇩S)›*) by force lemma top_scene_space: "⊤⇩S ∈ scene_space" proof (-) (*goal: ‹⊤⇩S ∈ scene_space›*) have "⊤⇩S = foldr (⊔⇩S) Vars ⊥⇩S" using span_Vars (*‹scene_span Vars›*) by (simp add: scene_span_def (*‹scene_span ?S = (⨆⇩S ?S = ⊤⇩S)›*)) also (*calculation: ‹⊤⇩S = ⨆⇩S Vars›*) have "... ∈ scene_space" by (simp add: scene_space_foldr (*‹set ?xs ⊆ scene_space ⟹ ⨆⇩S ?xs ∈ scene_space›*)) finally (*calculation: ‹⊤⇩S ∈ scene_space›*) show "?thesis" (*goal: ‹⊤⇩S ∈ scene_space›*) . qed lemma Vars_compat_scene_space: "⟦ b ∈ scene_space; x ∈ set Vars ⟧ ⟹ x ##⇩S b" proof (induct b rule: scene_space.induct (*‹⟦?x ∈ scene_space; ?P ⊥⇩S; ⋀x. x ∈ set Vars ⟹ ?P x; ⋀x y. ⟦x ∈ scene_space; ?P x; y ∈ scene_space; ?P y⟧ ⟹ ?P (x ⊔⇩S y)⟧ ⟹ ?P ?x›*)) (*goals: 1. ‹x ∈ set Vars ⟹ x ##⇩S ⊥⇩S› 2. ‹⋀xa. ⟦xa ∈ set Vars; x ∈ set Vars⟧ ⟹ x ##⇩S xa› 3. ‹⋀xa y. ⟦xa ∈ scene_space; x ∈ set Vars ⟹ x ##⇩S xa; y ∈ scene_space; x ∈ set Vars ⟹ x ##⇩S y; x ∈ set Vars⟧ ⟹ x ##⇩S xa ⊔⇩S y›*) case bot_scene_space (*‹x ∈ set Vars›*) then show "?case" (*goal: ‹(x::'a scene) ##⇩S ⊥⇩S›*) by (metis scene_compat_refl (*‹?X ##⇩S ?X›*) scene_union_incompat (*‹¬ ?X ##⇩S ?Y ⟹ ?X ⊔⇩S ?Y = ⊥⇩S›*) scene_union_unit( (*‹?X ⊔⇩S ⊥⇩S = ?X›*) 1)) next (*goals: 1. ‹⋀xa. ⟦xa ∈ set Vars; x ∈ set Vars⟧ ⟹ x ##⇩S xa› 2. ‹⋀xa y. ⟦xa ∈ scene_space; x ∈ set Vars ⟹ x ##⇩S xa; y ∈ scene_space; x ∈ set Vars ⟹ x ##⇩S y; x ∈ set Vars⟧ ⟹ x ##⇩S xa ⊔⇩S y›*) case (Vars_scene_space a) (*‹(a::'a scene) ∈ set Vars› ‹x ∈ set Vars›*) then show "?case" (*goal: ‹x ##⇩S a›*) by (metis local.indep_Vars (*‹scene_indeps (set Vars)›*) pairwiseD (*‹⟦pairwise ?R ?S; ?x ∈ ?S; ?y ∈ ?S; ?x ≠ ?y⟧ ⟹ ?R ?x ?y›*) scene_compat_refl (*‹?X ##⇩S ?X›*) scene_indep_compat (*‹?X ⨝⇩S ?Y ⟹ ?X ##⇩S ?Y›*) scene_indeps_def (*‹scene_indeps = pairwise (⨝⇩S)›*)) next (*goal: ‹⋀(xa::'a scene) y::'a scene. ⟦xa ∈ scene_space; (x::'a scene) ∈ set Vars ⟹ x ##⇩S xa; y ∈ scene_space; x ∈ set Vars ⟹ x ##⇩S y; x ∈ set Vars⟧ ⟹ x ##⇩S xa ⊔⇩S y›*) case (union_scene_space a b) (*‹a ∈ scene_space› ‹x ∈ set Vars ⟹ x ##⇩S a› ‹b ∈ scene_space› ‹x ∈ set Vars ⟹ x ##⇩S b› ‹(x::'a scene) ∈ set Vars›*) then show "?case" (*goal: ‹x ##⇩S a ⊔⇩S b›*) using scene_union_pres_compat (*‹⟦?A ##⇩S ?B; ?A ##⇩S ?C⟧ ⟹ ?A ##⇩S ?B ⊔⇩S ?C›*) by blast qed lemma scene_space_compat: "⟦ a ∈ scene_space; b ∈ scene_space ⟧ ⟹ a ##⇩S b" proof (induct rule: scene_space.induct (*‹⟦?x ∈ scene_space; ?P ⊥⇩S; ⋀x. x ∈ set Vars ⟹ ?P x; ⋀x y. ⟦x ∈ scene_space; ?P x; y ∈ scene_space; ?P y⟧ ⟹ ?P (x ⊔⇩S y)⟧ ⟹ ?P ?x›*)) (*goals: 1. ‹(b::'a scene) ∈ scene_space ⟹ ⊥⇩S ##⇩S b› 2. ‹⋀x::'a scene. ⟦x ∈ set Vars; (b::'a scene) ∈ scene_space⟧ ⟹ x ##⇩S b› 3. ‹⋀(x::'a scene) y::'a scene. ⟦x ∈ scene_space; (b::'a scene) ∈ scene_space ⟹ x ##⇩S b; y ∈ scene_space; b ∈ scene_space ⟹ y ##⇩S b; b ∈ scene_space⟧ ⟹ x ⊔⇩S y ##⇩S b›*) case bot_scene_space (*‹(b::'a scene) ∈ scene_space›*) then show "?case" (*goal: ‹⊥⇩S ##⇩S b›*) by simp next (*goals: 1. ‹⋀x. ⟦x ∈ set Vars; b ∈ scene_space⟧ ⟹ x ##⇩S b› 2. ‹⋀x y. ⟦x ∈ scene_space; b ∈ scene_space ⟹ x ##⇩S b; y ∈ scene_space; b ∈ scene_space ⟹ y ##⇩S b; b ∈ scene_space⟧ ⟹ x ⊔⇩S y ##⇩S b›*) case (Vars_scene_space x) (*‹(x::'a scene) ∈ set Vars› ‹b ∈ scene_space›*) then show "?case" (*goal: ‹x ##⇩S b›*) by (simp add: Vars_compat_scene_space (*‹⟦?b ∈ scene_space; ?x ∈ set Vars⟧ ⟹ ?x ##⇩S ?b›*)) next (*goal: ‹⋀(x::'a scene) y::'a scene. ⟦x ∈ scene_space; (b::'a scene) ∈ scene_space ⟹ x ##⇩S b; y ∈ scene_space; b ∈ scene_space ⟹ y ##⇩S b; b ∈ scene_space⟧ ⟹ x ⊔⇩S y ##⇩S b›*) case (union_scene_space x y) (*‹x ∈ scene_space› ‹(b::'a scene) ∈ scene_space ⟹ (x::'a scene) ##⇩S b› ‹y ∈ scene_space› ‹b ∈ scene_space ⟹ y ##⇩S b› ‹(b::'a scene) ∈ scene_space›*) then show "?case" (*goal: ‹(x::'a scene) ⊔⇩S (y::'a scene) ##⇩S (b::'a scene)›*) using scene_compat_sym (*‹(?X::?'a scene) ##⇩S (?Y::?'a scene) ⟹ ?Y ##⇩S ?X›*) scene_union_pres_compat (*‹⟦?A ##⇩S ?B; ?A ##⇩S ?C⟧ ⟹ ?A ##⇩S ?B ⊔⇩S ?C›*) by blast qed corollary scene_space_union_assoc: assumes "x ∈ scene_space" "y ∈ scene_space" "z ∈ scene_space" shows "x ⊔⇩S (y ⊔⇩S z) = (x ⊔⇩S y) ⊔⇩S z" by (simp add: assms (*‹x ∈ scene_space› ‹y ∈ scene_space› ‹z ∈ scene_space›*) scene_space_compat (*‹⟦?a ∈ scene_space; ?b ∈ scene_space⟧ ⟹ ?a ##⇩S ?b›*) scene_union_assoc (*‹⟦?X ##⇩S ?Y; ?X ##⇩S ?Z; ?Y ##⇩S ?Z⟧ ⟹ ?X ⊔⇩S (?Y ⊔⇩S ?Z) = ?X ⊔⇩S ?Y ⊔⇩S ?Z›*)) lemma scene_space_vars_decomp: "a ∈ scene_space ⟹ ∃xs. set xs ⊆ set Vars ∧ foldr (⊔⇩S) xs ⊥⇩S = a" proof (induct rule: scene_space.induct (*‹⟦?x ∈ scene_space; ?P ⊥⇩S; ⋀x. x ∈ set Vars ⟹ ?P x; ⋀x y. ⟦x ∈ scene_space; ?P x; y ∈ scene_space; ?P y⟧ ⟹ ?P (x ⊔⇩S y)⟧ ⟹ ?P ?x›*)) (*goals: 1. ‹∃xs. set xs ⊆ set Vars ∧ ⨆⇩S xs = ⊥⇩S› 2. ‹⋀x. x ∈ set Vars ⟹ ∃xs. set xs ⊆ set Vars ∧ ⨆⇩S xs = x› 3. ‹⋀x y. ⟦x ∈ scene_space; ∃xs. set xs ⊆ set Vars ∧ ⨆⇩S xs = x; y ∈ scene_space; ∃xs. set xs ⊆ set Vars ∧ ⨆⇩S xs = y⟧ ⟹ ∃xs. set xs ⊆ set Vars ∧ ⨆⇩S xs = x ⊔⇩S y›*) case bot_scene_space (*no hyothesis introduced yet*) then show "?case" (*goal: ‹∃xs::'a::type scene list. set xs ⊆ set Vars ∧ ⨆⇩S xs = ⊥⇩S›*) by (simp add: exI[where x="[]"] (*‹?P [] ⟹ ∃x. ?P x›*)) next (*goals: 1. ‹⋀x. x ∈ set Vars ⟹ ∃xs. set xs ⊆ set Vars ∧ ⨆⇩S xs = x› 2. ‹⋀x y. ⟦x ∈ scene_space; ∃xs. set xs ⊆ set Vars ∧ ⨆⇩S xs = x; y ∈ scene_space; ∃xs. set xs ⊆ set Vars ∧ ⨆⇩S xs = y⟧ ⟹ ∃xs. set xs ⊆ set Vars ∧ ⨆⇩S xs = x ⊔⇩S y›*) case (Vars_scene_space x) (*‹x ∈ set Vars›*) show "?case" (*goal: ‹∃xs. set xs ⊆ set Vars ∧ ⨆⇩S xs = x›*) apply (rule exI[where x="[x]"] (*‹?P [x] ⟹ ∃x. ?P x›*)) (*goal: ‹∃xs. set xs ⊆ set Vars ∧ ⨆⇩S xs = x›*) using Vars_scene_space (*‹x ∈ set Vars›*) by simp next (*goal: ‹⋀x y. ⟦x ∈ scene_space; ∃xs. set xs ⊆ set Vars ∧ ⨆⇩S xs = x; y ∈ scene_space; ∃xs. set xs ⊆ set Vars ∧ ⨆⇩S xs = y⟧ ⟹ ∃xs. set xs ⊆ set Vars ∧ ⨆⇩S xs = x ⊔⇩S y›*) case (union_scene_space x y) (*‹x ∈ scene_space› ‹∃xs. set xs ⊆ set Vars ∧ ⨆⇩S xs = x› ‹y ∈ scene_space› ‹∃xs. set xs ⊆ set Vars ∧ ⨆⇩S xs = y›*) then obtain xs and ys where xsys: "set xs ⊆ set Vars ∧ foldr (⊔⇩S) xs ⊥⇩S = x" "set ys ⊆ set Vars ∧ foldr (⊔⇩S) ys ⊥⇩S = y" (*goal: ‹(⋀xs ys. ⟦set xs ⊆ set Vars ∧ ⨆⇩S xs = x; set ys ⊆ set Vars ∧ ⨆⇩S ys = y⟧ ⟹ thesis) ⟹ thesis›*) by blast show "?case" (*goal: ‹∃xs. set xs ⊆ set Vars ∧ ⨆⇩S xs = x ⊔⇩S y›*) proof (rule exI[where x="xs @ ys"] (*‹?P (xs @ ys) ⟹ ∃x. ?P x›*)) (*goal: ‹set (xs @ ys) ⊆ set Vars ∧ ⨆⇩S (xs @ ys) = x ⊔⇩S y›*) show "set (xs @ ys) ⊆ set Vars ∧ ⨆⇩S (xs @ ys) = x ⊔⇩S y" apply (auto simp: xsys (*‹set xs ⊆ set Vars ∧ ⨆⇩S xs = x› ‹set ys ⊆ set Vars ∧ ⨆⇩S ys = y›*)) (*goal: ‹set (xs @ ys) ⊆ set Vars ∧ ⨆⇩S (xs @ ys) = x ⊔⇩S y›*) by (metis (full_types) Vars_compat_scene_space (*‹⟦?b ∈ scene_space; ?x ∈ set Vars⟧ ⟹ ?x ##⇩S ?b›*) foldr_scene_union_add_tail (*‹⟦pairwise (##⇩S) (set ?xs); ∀x∈set ?xs. x ##⇩S ?b⟧ ⟹ ⨆⇩S ?xs ⊔⇩S ?b = foldr (⊔⇩S) ?xs ?b›*) pairwise_subset (*‹⟦pairwise ?P ?S; ?T ⊆ ?S⟧ ⟹ pairwise ?P ?T›*) scene_space_compats (*‹pairwise (##⇩S) (set Vars)›*) subsetD (*‹⟦?A ⊆ ?B; ?c ∈ ?A⟧ ⟹ ?c ∈ ?B›*) union_scene_space.hyps( (*‹y ∈ scene_space›*) 3) xsys( (*‹set xs ⊆ set Vars ∧ ⨆⇩S xs = x›*) 1)) qed qed lemma scene_space_vars_decomp_iff: "a ∈ scene_space ⟷ (∃xs. set xs ⊆ set Vars ∧ a = foldr (⊔⇩S) xs ⊥⇩S)" apply (auto simp add: scene_space_vars_decomp (*‹?a ∈ scene_space ⟹ ∃xs. set xs ⊆ set Vars ∧ ⨆⇩S xs = ?a›*) scene_space.Vars_scene_space (*‹?x ∈ set Vars ⟹ ?x ∈ scene_space›*) scene_space_foldr (*‹set ?xs ⊆ scene_space ⟹ ⨆⇩S ?xs ∈ scene_space›*)) (*goal: ‹(a ∈ scene_space) = (∃xs. set xs ⊆ set Vars ∧ a = ⨆⇩S xs)›*) apply (simp add: scene_space.Vars_scene_space (*‹?x ∈ set Vars ⟹ ?x ∈ scene_space›*) scene_space_foldr (*‹set ?xs ⊆ scene_space ⟹ ⨆⇩S ?xs ∈ scene_space›*) subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*)) (*top goal: ‹a ∈ scene_space ⟹ ∃xs. set xs ⊆ set Vars ∧ a = ⨆⇩S xs› and 1 goal remains*) using scene_space_vars_decomp (*‹?a ∈ scene_space ⟹ ∃xs. set xs ⊆ set Vars ∧ ⨆⇩S xs = ?a›*) (*goals: 1. ‹(a::'a scene) ∈ scene_space ⟹ ∃xs::'a scene list. (∀x::'a scene∈set xs. x ∈ set Vars) ∧ a = ⨆⇩S xs› 2. ‹⋀xs::'a scene list. ⟦set xs ⊆ set Vars; (a::'a scene) = ⨆⇩S xs⟧ ⟹ ⨆⇩S xs ∈ scene_space› discuss goal 1*) apply auto (*discuss goal 2*) apply (meson dual_order.trans (*‹⟦?b ≤ ?a; ?c ≤ ?b⟧ ⟹ ?c ≤ ?a›*) scene_space_foldr (*‹set ?xs ⊆ scene_space ⟹ ⨆⇩S ?xs ∈ scene_space›*) set_Vars_scene_space (*‹set Vars ⊆ scene_space›*)) (*proven 2 subgoals*) . lemma "fold (⊔⇩S) (map (λx. x ;⇩S a) Vars) b = ⟦a⟧⇩∼ ⊔⇩S b" oops lemma Vars_indep_foldr: assumes "x ∈ set Vars" "set xs ⊆ set Vars" shows "x ⨝⇩S ⨆⇩S (removeAll x xs)" proof (rule foldr_scene_indep (*‹⟦pairwise (##⇩S) (set ?as); ∀b∈set ?as. ?a ⨝⇩S b⟧ ⟹ ?a ⨝⇩S ⨆⇩S ?as›*)) (*goals: 1. ‹pairwise (##⇩S) (set (removeAll x xs))› 2. ‹∀b∈set (removeAll x xs). x ⨝⇩S b›*) show "pairwise (##⇩S) (set (removeAll x xs))" apply simp (*goal: ‹pairwise (##⇩S) (set (removeAll x xs))›*) by (metis Diff_subset (*‹?A - ?B ⊆ ?A›*) assms( (*‹set xs ⊆ set Vars›*) 2) pairwise_mono (*‹⟦pairwise ?P ?A; ⋀x y. ?P x y ⟹ ?Q x y; ?B ⊆ ?A⟧ ⟹ pairwise ?Q ?B›*) scene_space_compats (*‹pairwise (##⇩S) (set Vars)›*)) from assms (*‹x ∈ set Vars› ‹set xs ⊆ set Vars›*) show "∀b∈set (removeAll x xs). x ⨝⇩S b" apply simp (*goal: ‹∀b∈set (removeAll x xs). x ⨝⇩S b›*) by (metis DiffE (*‹⟦?c ∈ ?A - ?B; ⟦?c ∈ ?A; ?c ∉ ?B⟧ ⟹ ?P⟧ ⟹ ?P›*) insertI1 (*‹?a ∈ insert ?a ?B›*) local.indep_Vars (*‹scene_indeps (set Vars)›*) pairwiseD (*‹⟦pairwise ?R ?S; ?x ∈ ?S; ?y ∈ ?S; ?x ≠ ?y⟧ ⟹ ?R ?x ?y›*) scene_indeps_def (*‹scene_indeps = pairwise (⨝⇩S)›*) subset_iff (*‹(?A ⊆ ?B) = (∀t. t ∈ ?A ⟶ t ∈ ?B)›*)) qed lemma Vars_indeps_foldr: assumes "set xs ⊆ set Vars" shows "foldr (⊔⇩S) xs ⊥⇩S ⨝⇩S foldr (⊔⇩S) (filter (λx. x ∉ set xs) Vars) ⊥⇩S" apply (rule foldr_scene_indep (*‹⟦pairwise (##⇩S) (set ?as); ∀b∈set ?as. ?a ⨝⇩S b⟧ ⟹ ?a ⨝⇩S ⨆⇩S ?as›*)) (*goals: 1. ‹pairwise (##⇩S) (set (filter (λx. x ∉ set xs) Vars))› 2. ‹∀b∈set (filter (λx. x ∉ set xs) Vars). ⨆⇩S xs ⨝⇩S b› discuss goal 1*) apply (meson filter_is_subset (*‹set (filter ?P ?xs) ⊆ set ?xs›*) pairwise_subset (*‹⟦pairwise ?P ?S; ?T ⊆ ?S⟧ ⟹ pairwise ?P ?T›*) scene_space_compats (*‹pairwise (##⇩S) (set Vars)›*)) (*discuss goal 2*) apply simp (*goal: ‹∀b∈set (filter (λx. x ∉ set xs) Vars). ⨆⇩S xs ⨝⇩S b›*) apply auto (*goal: ‹∀x. x ∈ set Vars ∧ x ∉ set xs ⟶ ⨆⇩S xs ⨝⇩S x›*) apply (rule scene_indep_sym (*‹?X ⨝⇩S ?Y ⟹ ?Y ⨝⇩S ?X›*)) (*goal: ‹⋀x. ⟦x ∈ set Vars; x ∉ set xs⟧ ⟹ ⨆⇩S xs ⨝⇩S x›*) apply (metis (no_types, lifting) assms (*‹set xs ⊆ set Vars›*) foldr_scene_indep (*‹⟦pairwise (##⇩S) (set ?as); ∀b∈set ?as. ?a ⨝⇩S b⟧ ⟹ ?a ⨝⇩S ⨆⇩S ?as›*) local.indep_Vars (*‹scene_indeps (set Vars)›*) pairwiseD (*‹⟦pairwise ?R ?S; ?x ∈ ?S; ?y ∈ ?S; ?x ≠ ?y⟧ ⟹ ?R ?x ?y›*) pairwise_mono (*‹⟦pairwise ?P ?A; ⋀x y. ?P x y ⟹ ?Q x y; ?B ⊆ ?A⟧ ⟹ pairwise ?Q ?B›*) scene_indeps_def (*‹scene_indeps = pairwise (⨝⇩S)›*) scene_space_compats (*‹pairwise (##⇩S) (set Vars)›*) subset_iff (*‹(?A ⊆ ?B) = (∀t. t ∈ ?A ⟶ t ∈ ?B)›*)) (*proven 2 subgoals*) . lemma uminus_var_other_vars: assumes "x ∈ set Vars" shows "- x = foldr (⊔⇩S) (removeAll x Vars) ⊥⇩S" proof (rule scene_union_indep_uniq[where Z="x"] (*‹⟦idem_scene (?X::'a scene); idem_scene (?Y::'a scene); idem_scene (x::'a scene); ?X ⨝⇩S x; ?Y ⨝⇩S x; ?X ⊔⇩S x = ?Y ⊔⇩S x⟧ ⟹ ?X = ?Y›*)) (*goals: 1. ‹idem_scene (- x)› 2. ‹idem_scene (⨆⇩S (removeAll x Vars))› 3. ‹idem_scene x› 4. ‹- x ⨝⇩S x› 5. ‹⨆⇩S (removeAll x Vars) ⨝⇩S x› 6. ‹- x ⊔⇩S x = ⨆⇩S (removeAll x Vars) ⊔⇩S x›*) show "idem_scene (foldr (⊔⇩S) (removeAll x Vars) ⊥⇩S)" by (metis Diff_subset (*‹?A - ?B ⊆ ?A›*) idem_scene_space (*‹?a ∈ scene_space ⟹ idem_scene ?a›*) order_trans (*‹⟦?x ≤ ?y; ?y ≤ ?z⟧ ⟹ ?x ≤ ?z›*) scene_space_foldr (*‹set ?xs ⊆ scene_space ⟹ ⨆⇩S ?xs ∈ scene_space›*) set_Vars_scene_space (*‹set Vars ⊆ scene_space›*) set_removeAll (*‹set (removeAll ?x ?xs) = set ?xs - {?x}›*)) show "idem_scene x" "idem_scene (-x)" (*goals: 1. ‹idem_scene x› 2. ‹idem_scene (- x)› discuss goal 1*) apply (simp add: assms (*‹x ∈ set Vars›*) local.idem_scene_Vars (*‹?x ∈ set Vars ⟹ idem_scene ?x›*)) (*discuss goal 2*) apply (simp add: assms (*‹x ∈ set Vars›*) local.idem_scene_Vars (*‹?x ∈ set Vars ⟹ idem_scene ?x›*)) (*proven 2 subgoals*) . show "foldr (⊔⇩S) (removeAll x Vars) ⊥⇩S ⨝⇩S x" using Vars_indep_foldr (*‹⟦?x ∈ set Vars; set ?xs ⊆ set Vars⟧ ⟹ ?x ⨝⇩S ⨆⇩S (removeAll ?x ?xs)›*) assms (*‹(x::'a scene) ∈ set Vars›*) scene_indep_sym (*‹(?X::?'a::type scene) ⨝⇩S (?Y::?'a::type scene) ⟹ ?Y ⨝⇩S ?X›*) by blast show "- x ⨝⇩S x" using scene_indep_self_compl (*‹?A ⨝⇩S - ?A›*) scene_indep_sym (*‹?X ⨝⇩S ?Y ⟹ ?Y ⨝⇩S ?X›*) by blast show "- x ⊔⇩S x = foldr (⊔⇩S) (removeAll x Vars) ⊥⇩S ⊔⇩S x" by (metis ‹idem_scene (- x)› assms (*‹x ∈ set Vars›*) foldr_scene_union_removeAll (*‹⟦pairwise (##⇩S) (set ?xs); ?x ∈ set ?xs⟧ ⟹ ⨆⇩S (removeAll ?x ?xs) ⊔⇩S ?x = ⨆⇩S ?xs›*) local.span_Vars (*‹scene_span Vars›*) scene_space_compats (*‹pairwise (##⇩S) (set Vars)›*) scene_span_def (*‹scene_span ?S = (⨆⇩S ?S = ⊤⇩S)›*) scene_union_compl (*‹idem_scene ?X ⟹ ?X ⊔⇩S - ?X = ⊤⇩S›*) uminus_scene_twice (*‹- (- ?X) = ?X›*)) qed lemma uminus_vars_other_vars: assumes "set xs ⊆ set Vars" shows "- ⨆⇩S xs = ⨆⇩S (filter (λx. x ∉ set xs) Vars)" proof (rule scene_union_indep_uniq[where Z="foldr (⊔⇩S) xs ⊥⇩S"] (*‹⟦idem_scene ?X; idem_scene ?Y; idem_scene (⨆⇩S xs); ?X ⨝⇩S ⨆⇩S xs; ?Y ⨝⇩S ⨆⇩S xs; ?X ⊔⇩S ⨆⇩S xs = ?Y ⊔⇩S ⨆⇩S xs⟧ ⟹ ?X = ?Y›*)) (*goals: 1. ‹idem_scene (- ⨆⇩S xs)› 2. ‹idem_scene (⨆⇩S (filter (λx. x ∉ set xs) Vars))› 3. ‹idem_scene (⨆⇩S xs)› 4. ‹- ⨆⇩S xs ⨝⇩S ⨆⇩S xs› 5. ‹⨆⇩S (filter (λx. x ∉ set xs) Vars) ⨝⇩S ⨆⇩S xs› 6. ‹- ⨆⇩S xs ⊔⇩S ⨆⇩S xs = ⨆⇩S (filter (λx. x ∉ set xs) Vars) ⊔⇩S ⨆⇩S xs›*) show "idem_scene (- foldr (⊔⇩S) xs ⊥⇩S)" "idem_scene (foldr (⊔⇩S) xs ⊥⇩S)" using assms (*‹set xs ⊆ set Vars›*) idem_scene_space (*‹?a ∈ scene_space ⟹ idem_scene ?a›*) idem_scene_uminus (*‹idem_scene (?X::?'a scene) ⟹ idem_scene (- ?X)›*) scene_space_vars_decomp_iff (*‹(?a ∈ scene_space) = (∃xs. set xs ⊆ set Vars ∧ ?a = ⨆⇩S xs)›*) apply - (*goals: 1. ‹⟦set xs ⊆ set Vars; ⋀a. a ∈ scene_space ⟹ idem_scene a; ⋀X. idem_scene X ⟹ idem_scene (- X); ⋀a. (a ∈ scene_space) = (∃xs. set xs ⊆ set Vars ∧ a = ⨆⇩S xs)⟧ ⟹ idem_scene (- ⨆⇩S xs)› 2. ‹⟦set xs ⊆ set Vars; ⋀a. a ∈ scene_space ⟹ idem_scene a; ⋀X. idem_scene X ⟹ idem_scene (- X); ⋀a. (a ∈ scene_space) = (∃xs. set xs ⊆ set Vars ∧ a = ⨆⇩S xs)⟧ ⟹ idem_scene (⨆⇩S xs)› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) . show "idem_scene (foldr (⊔⇩S) (filter (λx. x ∉ set xs) Vars) ⊥⇩S)" by (meson filter_is_subset (*‹set (filter ?P ?xs) ⊆ set ?xs›*) idem_scene_space (*‹?a ∈ scene_space ⟹ idem_scene ?a›*) scene_space_vars_decomp_iff (*‹(?a ∈ scene_space) = (∃xs. set xs ⊆ set Vars ∧ ?a = ⨆⇩S xs)›*)) show "- foldr (⊔⇩S) xs ⊥⇩S ⨝⇩S foldr (⊔⇩S) xs ⊥⇩S" by (metis scene_indep_self_compl (*‹?A ⨝⇩S - ?A›*) uminus_scene_twice (*‹- (- ?X) = ?X›*)) show "foldr (⊔⇩S) (filter (λx. x ∉ set xs) Vars) ⊥⇩S ⨝⇩S foldr (⊔⇩S) xs ⊥⇩S" using Vars_indeps_foldr (*‹set (?xs::'a::type scene list) ⊆ set Vars ⟹ ⨆⇩S ?xs ⨝⇩S ⨆⇩S (filter (λx::'a::type scene. x ∉ set ?xs) Vars)›*) assms (*‹set xs ⊆ set Vars›*) scene_indep_sym (*‹(?X::?'a scene) ⨝⇩S (?Y::?'a scene) ⟹ ?Y ⨝⇩S ?X›*) by blast show "- ⨆⇩S xs ⊔⇩S ⨆⇩S xs = ⨆⇩S (filter (λx. x ∉ set xs) Vars) ⊔⇩S ⨆⇩S xs" using foldr_scene_union_filter[of Vars xs, THEN sym] (*‹⟦pairwise (##⇩S) (set Vars); set xs ⊆ set Vars⟧ ⟹ ⨆⇩S (filter (λx. x ∉ set xs) Vars) ⊔⇩S ⨆⇩S xs = ⨆⇩S Vars›*) apply (simp add: assms (*‹set xs ⊆ set Vars›*)) (*goal: ‹- ⨆⇩S xs ⊔⇩S ⨆⇩S xs = ⨆⇩S (filter (λx. x ∉ set xs) Vars) ⊔⇩S ⨆⇩S xs›*) by (metis ‹idem_scene (- ⨆⇩S xs)› local.span_Vars (*‹scene_span Vars›*) scene_span_def (*‹scene_span ?S = (⨆⇩S ?S = ⊤⇩S)›*) scene_union_compl (*‹idem_scene ?X ⟹ ?X ⊔⇩S - ?X = ⊤⇩S›*) uminus_scene_twice (*‹- (- ?X) = ?X›*)) qed lemma scene_space_uminus: "⟦ a ∈ scene_space ⟧ ⟹ - a ∈ scene_space" apply (auto simp add: scene_space_vars_decomp_iff (*‹(?a ∈ scene_space) = (∃xs. set xs ⊆ set Vars ∧ ?a = ⨆⇩S xs)›*) uminus_vars_other_vars (*‹set ?xs ⊆ set Vars ⟹ - ⨆⇩S ?xs = ⨆⇩S (filter (λx. x ∉ set ?xs) Vars)›*)) (*goal: ‹a ∈ scene_space ⟹ - a ∈ scene_space›*) by (metis filter_is_subset (*‹set (filter ?P ?xs) ⊆ set ?xs›*)) lemma scene_space_inter: "⟦ a ∈ scene_space; b ∈ scene_space ⟧ ⟹ a ⊓⇩S b ∈ scene_space" by (simp add: inf_scene_def (*‹?X ⊓⇩S ?Y = - (- ?X ⊔⇩S - ?Y)›*) scene_space.union_scene_space (*‹⟦?x ∈ scene_space; ?y ∈ scene_space⟧ ⟹ ?x ⊔⇩S ?y ∈ scene_space›*) scene_space_uminus (*‹?a ∈ scene_space ⟹ - ?a ∈ scene_space›*)) lemma scene_union_foldr_remove_element: assumes "set xs ⊆ set Vars" shows "a ⊔⇩S ⨆⇩S xs = a ⊔⇩S ⨆⇩S (removeAll a xs)" using assms (*‹set xs ⊆ set Vars›*) proof (induct xs) (*goals: 1. ‹set [] ⊆ set Vars ⟹ (a::'a::type scene) ⊔⇩S ⨆⇩S [] = a ⊔⇩S ⨆⇩S (removeAll a [])› 2. ‹⋀(aa::'a::type scene) xs::'a::type scene list. ⟦set xs ⊆ set Vars ⟹ (a::'a::type scene) ⊔⇩S ⨆⇩S xs = a ⊔⇩S ⨆⇩S (removeAll a xs); set (aa # xs) ⊆ set Vars⟧ ⟹ a ⊔⇩S ⨆⇩S (aa # xs) = a ⊔⇩S ⨆⇩S (removeAll a (aa # xs))›*) case Nil (*‹set [] ⊆ set Vars›*) then show "?case" (*goal: ‹(a::'a scene) ⊔⇩S ⨆⇩S [] = a ⊔⇩S ⨆⇩S (removeAll a [])›*) by simp next (*goal: ‹⋀aa xs. ⟦set xs ⊆ set Vars ⟹ a ⊔⇩S ⨆⇩S xs = a ⊔⇩S ⨆⇩S (removeAll a xs); set (aa # xs) ⊆ set Vars⟧ ⟹ a ⊔⇩S ⨆⇩S (aa # xs) = a ⊔⇩S ⨆⇩S (removeAll a (aa # xs))›*) case (Cons a xs) (*‹set xs ⊆ set Vars ⟹ a ⊔⇩S ⨆⇩S xs = a ⊔⇩S ⨆⇩S (removeAll a xs)› ‹set ((a::'a scene) # (xs::'a scene list)) ⊆ set Vars›*) then show "?case" (*goal: ‹a ⊔⇩S ⨆⇩S (a # xs) = a ⊔⇩S ⨆⇩S (removeAll a (a # xs))›*) apply auto (*goals: 1. ‹⟦a ⊔⇩S ⨆⇩S xs = a ⊔⇩S ⨆⇩S (removeAll a xs); a ∈ set Vars; set xs ⊆ set Vars; a = a⟧ ⟹ a ⊔⇩S (a ⊔⇩S ⨆⇩S (removeAll a xs)) = a ⊔⇩S ⨆⇩S (removeAll a xs)› 2. ‹⟦a ⊔⇩S ⨆⇩S xs = a ⊔⇩S ⨆⇩S (removeAll a xs); a ∈ set Vars; set xs ⊆ set Vars; a ≠ a⟧ ⟹ a ⊔⇩S (a ⊔⇩S ⨆⇩S xs) = a ⊔⇩S (a ⊔⇩S ⨆⇩S (removeAll a xs))› discuss goal 1*) apply (metis order_trans (*‹⟦(?x::?'a) ≤ (?y::?'a); ?y ≤ (?z::?'a)⟧ ⟹ ?x ≤ ?z›*) scene_space.Vars_scene_space (*‹(?x::'a scene) ∈ set Vars ⟹ ?x ∈ scene_space›*) scene_space_foldr (*‹set (?xs::'a scene list) ⊆ scene_space ⟹ ⨆⇩S ?xs ∈ scene_space›*) scene_space_union_assoc (*‹⟦(?x::'a scene) ∈ scene_space; (?y::'a scene) ∈ scene_space; (?z::'a scene) ∈ scene_space⟧ ⟹ ?x ⊔⇩S (?y ⊔⇩S ?z) = ?x ⊔⇩S ?y ⊔⇩S ?z›*) scene_union_idem (*‹(?X::?'a scene) ⊔⇩S ?X = ?X›*) set_Vars_scene_space (*‹set Vars ⊆ scene_space›*)) (*discuss goal 2*) apply (smt (verit, best) Diff_subset (*‹?A - ?B ⊆ ?A›*) dual_order.trans (*‹⟦?b ≤ ?a; ?c ≤ ?b⟧ ⟹ ?c ≤ ?a›*) removeAll_id (*‹?x ∉ set ?xs ⟹ removeAll ?x ?xs = ?xs›*) scene_space_foldr (*‹set ?xs ⊆ scene_space ⟹ ⨆⇩S ?xs ∈ scene_space›*) scene_space_union_assoc (*‹⟦?x ∈ scene_space; ?y ∈ scene_space; ?z ∈ scene_space⟧ ⟹ ?x ⊔⇩S (?y ⊔⇩S ?z) = ?x ⊔⇩S ?y ⊔⇩S ?z›*) scene_union_commute (*‹?X ⊔⇩S ?Y = ?Y ⊔⇩S ?X›*) set_Vars_scene_space (*‹set Vars ⊆ scene_space›*) set_removeAll (*‹set (removeAll ?x ?xs) = set ?xs - {?x}›*) subset_iff (*‹(?A ⊆ ?B) = (∀t. t ∈ ?A ⟶ t ∈ ?B)›*)) (*proven 2 subgoals*) . qed lemma scene_union_foldr_Cons_removeAll: assumes "set xs ⊆ set Vars" "a ∈ set xs" shows "foldr (⊔⇩S) xs ⊥⇩S = foldr (⊔⇩S) (a # removeAll a xs) ⊥⇩S" by (metis assms( (*‹set xs ⊆ set Vars›*) 1) assms( (*‹a ∈ set xs›*) 2) foldr_scene_union_eq_sets (*‹⟦pairwise (##⇩S) (set ?xs); set ?xs = set ?ys⟧ ⟹ ⨆⇩S ?xs = ⨆⇩S ?ys›*) insert_Diff (*‹?a ∈ ?A ⟹ insert ?a (?A - {?a}) = ?A›*) list.simps( (*‹set (?x21.0 # ?x22.0) = insert ?x21.0 (set ?x22.0)›*) 15) pairwise_subset (*‹⟦pairwise ?P ?S; ?T ⊆ ?S⟧ ⟹ pairwise ?P ?T›*) scene_space_compats (*‹pairwise (##⇩S) (set Vars)›*) set_removeAll (*‹set (removeAll ?x ?xs) = set ?xs - {?x}›*)) lemma scene_union_foldr_Cons_removeAll': assumes "set xs ⊆ set Vars" "a ∈ set Vars" shows "foldr (⊔⇩S) (a # xs) ⊥⇩S = foldr (⊔⇩S) (a # removeAll a xs) ⊥⇩S" by (simp add: assms( (*‹set xs ⊆ set Vars›*) 1) scene_union_foldr_remove_element (*‹set ?xs ⊆ set Vars ⟹ ?a ⊔⇩S ⨆⇩S ?xs = ?a ⊔⇩S ⨆⇩S (removeAll ?a ?xs)›*)) lemma scene_in_foldr: "⟦ a ∈ set xs; set xs ⊆ set Vars ⟧ ⟹ a ⊆⇩S ⨆⇩S xs" apply (induct xs) (*goal: ‹⟦a ∈ set xs; set xs ⊆ set Vars⟧ ⟹ a ⊆⇩S ⨆⇩S xs›*) apply simp (*top goal: ‹⟦a ∈ set []; set [] ⊆ set Vars⟧ ⟹ a ⊆⇩S ⨆⇩S []› and 1 goal remains*) apply (subst scene_union_foldr_Cons_removeAll' (*‹⟦set (?xs::'a scene list) ⊆ set Vars; (?a::'a scene) ∈ set Vars⟧ ⟹ ⨆⇩S (?a # ?xs) = ⨆⇩S (?a # removeAll ?a ?xs)›*)) (*goal: ‹⋀aa xs. ⟦⟦a ∈ set xs; set xs ⊆ set Vars⟧ ⟹ a ⊆⇩S ⨆⇩S xs; a ∈ set (aa # xs); set (aa # xs) ⊆ set Vars⟧ ⟹ a ⊆⇩S ⨆⇩S (aa # xs)›*) apply simp (*top goal: ‹⋀aa xs. ⟦⟦a ∈ set xs; set xs ⊆ set Vars⟧ ⟹ a ⊆⇩S ⨆⇩S xs; a ∈ set (aa # xs); set (aa # xs) ⊆ set Vars⟧ ⟹ set xs ⊆ set Vars› and 2 goals remain*) apply simp (*top goal: ‹⋀(aa::'a scene) xs::'a scene list. ⟦⟦(a::'a scene) ∈ set xs; set xs ⊆ set Vars⟧ ⟹ a ⊆⇩S ⨆⇩S xs; a ∈ set (aa # xs); set (aa # xs) ⊆ set Vars⟧ ⟹ aa ∈ set Vars› and 1 goal remains*) apply auto (*goal: ‹⋀aa xs. ⟦⟦a ∈ set xs; set xs ⊆ set Vars⟧ ⟹ a ⊆⇩S ⨆⇩S xs; a ∈ set (aa # xs); set (aa # xs) ⊆ set Vars⟧ ⟹ a ⊆⇩S ⨆⇩S (aa # removeAll aa xs)›*) apply (rule scene_union_ub (*‹⟦idem_scene ?Y; ?X ⨝⇩S ?Y⟧ ⟹ ?X ⊆⇩S ?X ⊔⇩S ?Y›*)) (*top goal: ‹⋀xs::'a scene list. ⟦(a::'a scene) ∈ set xs ⟹ a ⊆⇩S ⨆⇩S xs; a ∈ set Vars; set xs ⊆ set Vars⟧ ⟹ a ⊆⇩S a ⊔⇩S ⨆⇩S (removeAll a xs)› and 1 goal remains*) apply (metis Diff_subset (*‹?A - ?B ⊆ ?A›*) dual_order.trans (*‹⟦?b ≤ ?a; ?c ≤ ?b⟧ ⟹ ?c ≤ ?a›*) idem_scene_space (*‹?a ∈ scene_space ⟹ idem_scene ?a›*) scene_space_vars_decomp_iff (*‹(?a ∈ scene_space) = (∃xs. set xs ⊆ set Vars ∧ ?a = ⨆⇩S xs)›*) set_removeAll (*‹set (removeAll ?x ?xs) = set ?xs - {?x}›*)) (*top goal: ‹⋀xs. ⟦a ∈ set xs ⟹ a ⊆⇩S ⨆⇩S xs; a ∈ set Vars; set xs ⊆ set Vars⟧ ⟹ idem_scene (⨆⇩S (removeAll a xs))› and 2 goals remain*) using Vars_indep_foldr (*‹⟦?x ∈ set Vars; set ?xs ⊆ set Vars⟧ ⟹ ?x ⨝⇩S ⨆⇩S (removeAll ?x ?xs)›*) (*goals: 1. ‹⋀xs. ⟦a ∈ set xs ⟹ a ⊆⇩S ⨆⇩S xs; a ∈ set Vars; set xs ⊆ set Vars⟧ ⟹ a ⨝⇩S ⨆⇩S (removeAll a xs)› 2. ‹⋀aa xs. ⟦a ⊆⇩S ⨆⇩S xs; aa ∈ set Vars; set xs ⊆ set Vars; a ∈ set xs⟧ ⟹ a ⊆⇩S aa ⊔⇩S ⨆⇩S (removeAll aa xs)› discuss goal 1*) apply blast (*discuss goal 2*) apply (metis Vars_indep_foldr (*‹⟦?x ∈ set Vars; set ?xs ⊆ set Vars⟧ ⟹ ?x ⨝⇩S ⨆⇩S (removeAll ?x ?xs)›*) foldr_scene_union_removeAll (*‹⟦pairwise (##⇩S) (set ?xs); ?x ∈ set ?xs⟧ ⟹ ⨆⇩S (removeAll ?x ?xs) ⊔⇩S ?x = ⨆⇩S ?xs›*) idem_scene_space (*‹?a ∈ scene_space ⟹ idem_scene ?a›*) local.idem_scene_Vars (*‹?x ∈ set Vars ⟹ idem_scene ?x›*) order.trans (*‹⟦?a ≤ ?b; ?b ≤ ?c⟧ ⟹ ?a ≤ ?c›*) pairwise_mono (*‹⟦pairwise ?P ?A; ⋀x y. ?P x y ⟹ ?Q x y; ?B ⊆ ?A⟧ ⟹ pairwise ?Q ?B›*) removeAll_id (*‹?x ∉ set ?xs ⟹ removeAll ?x ?xs = ?xs›*) scene_indep_sym (*‹?X ⨝⇩S ?Y ⟹ ?Y ⨝⇩S ?X›*) scene_space_compats (*‹pairwise (##⇩S) (set Vars)›*) scene_space_foldr (*‹set ?xs ⊆ scene_space ⟹ ⨆⇩S ?xs ∈ scene_space›*) scene_union_commute (*‹?X ⊔⇩S ?Y = ?Y ⊔⇩S ?X›*) scene_union_ub (*‹⟦idem_scene ?Y; ?X ⨝⇩S ?Y⟧ ⟹ ?X ⊆⇩S ?X ⊔⇩S ?Y›*) set_Vars_scene_space (*‹set Vars ⊆ scene_space›*) subscene_trans (*‹⟦idem_scene ?Y; ?X ⊆⇩S ?Y; ?Y ⊆⇩S ?Z⟧ ⟹ ?X ⊆⇩S ?Z›*)) (*proven 2 subgoals*) . lemma scene_union_foldr_subset: assumes "set xs ⊆ set ys" "set ys ⊆ set Vars" shows "⨆⇩S xs ⊆⇩S ⨆⇩S ys" using assms (*‹set (xs::'a scene list) ⊆ set (ys::'a scene list)› ‹set (ys::'a scene list) ⊆ set Vars›*) proof (induct xs arbitrary: ys) (*goals: 1. ‹⋀ys. ⟦set [] ⊆ set ys; set ys ⊆ set Vars⟧ ⟹ ⨆⇩S [] ⊆⇩S ⨆⇩S ys› 2. ‹⋀a xs ys. ⟦⋀ys. ⟦set xs ⊆ set ys; set ys ⊆ set Vars⟧ ⟹ ⨆⇩S xs ⊆⇩S ⨆⇩S ys; set (a # xs) ⊆ set ys; set ys ⊆ set Vars⟧ ⟹ ⨆⇩S (a # xs) ⊆⇩S ⨆⇩S ys›*) case Nil (*‹set [] ⊆ set ys› ‹set ys ⊆ set Vars›*) then show "?case" (*goal: ‹⨆⇩S [] ⊆⇩S ⨆⇩S ys›*) by (simp add: scene_bot_least (*‹⊥⇩S ⊆⇩S ?X›*)) next (*goal: ‹⋀a xs ys. ⟦⋀ys. ⟦set xs ⊆ set ys; set ys ⊆ set Vars⟧ ⟹ ⨆⇩S xs ⊆⇩S ⨆⇩S ys; set (a # xs) ⊆ set ys; set ys ⊆ set Vars⟧ ⟹ ⨆⇩S (a # xs) ⊆⇩S ⨆⇩S ys›*) case (Cons a xs) (*‹⟦set xs ⊆ set ?ys; set ?ys ⊆ set Vars⟧ ⟹ ⨆⇩S xs ⊆⇩S ⨆⇩S ?ys› ‹set (a # xs) ⊆ set ys› ‹set ys ⊆ set Vars›*) { assume "a ∈ set xs" (*‹(a::'a scene) ∈ set (xs::'a scene list)›*) with Cons (*‹⟦set xs ⊆ set ?ys; set ?ys ⊆ set Vars⟧ ⟹ ⨆⇩S xs ⊆⇩S ⨆⇩S ?ys› ‹set ((a::'a scene) # (xs::'a scene list)) ⊆ set (ys::'a scene list)› ‹set (ys::'a scene list) ⊆ set Vars›*) have "foldr (⊔⇩S) xs ⊥⇩S = foldr (⊔⇩S) (a # removeAll a xs) ⊥⇩S" apply (subst scene_union_foldr_Cons_removeAll (*‹⟦set ?xs ⊆ set Vars; ?a ∈ set ?xs⟧ ⟹ ⨆⇩S ?xs = ⨆⇩S (?a # removeAll ?a ?xs)›*)) (*goals: 1. ‹⟦⋀ys::'a scene list. ⟦set (xs::'a scene list) ⊆ set ys; set ys ⊆ set Vars⟧ ⟹ ⨆⇩S xs ⊆⇩S ⨆⇩S ys; set ((a::'a scene) # xs) ⊆ set (ys::'a scene list); set ys ⊆ set Vars; a ∈ set xs⟧ ⟹ set xs ⊆ set Vars› 2. ‹⟦⋀ys::'a scene list. ⟦set (xs::'a scene list) ⊆ set ys; set ys ⊆ set Vars⟧ ⟹ ⨆⇩S xs ⊆⇩S ⨆⇩S ys; set ((a::'a scene) # xs) ⊆ set (ys::'a scene list); set ys ⊆ set Vars; a ∈ set xs⟧ ⟹ (?a5::'a scene) ∈ set xs› 3. ‹⟦⋀ys::'a scene list. ⟦set (xs::'a scene list) ⊆ set ys; set ys ⊆ set Vars⟧ ⟹ ⨆⇩S xs ⊆⇩S ⨆⇩S ys; set ((a::'a scene) # xs) ⊆ set (ys::'a scene list); set ys ⊆ set Vars; a ∈ set xs⟧ ⟹ ⨆⇩S ((?a5::'a scene) # removeAll ?a5 xs) = ⨆⇩S (a # removeAll a xs)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . } note a_in = this (*‹(a::'a scene) ∈ set (xs::'a scene list) ⟹ ⨆⇩S xs = ⨆⇩S (a # removeAll a xs)›*) { assume "a ∉ set xs" (*‹(a::'a scene) ∉ set (xs::'a scene list)›*) then have "a ⊔⇩S foldr (⊔⇩S) xs ⊥⇩S = foldr (⊔⇩S) (a # xs) ⊥⇩S" by simp } note a_out = this (*‹a ∉ set xs ⟹ a ⊔⇩S ⨆⇩S xs = ⨆⇩S (a # xs)›*) show "?case" (*goal: ‹⨆⇩S (a # xs) ⊆⇩S ⨆⇩S ys›*) apply simp (*goal: ‹⨆⇩S (a # xs) ⊆⇩S ⨆⇩S ys›*) apply (cases "a ∈ set xs") (*goal: ‹(a::'a scene) ⊔⇩S ⨆⇩S (xs::'a scene list) ⊆⇩S ⨆⇩S (ys::'a scene list)›*) using a_in (*‹a ∈ set xs ⟹ ⨆⇩S xs = ⨆⇩S (a # removeAll a xs)›*) Cons (*‹⟦set xs ⊆ set ?ys; set ?ys ⊆ set Vars⟧ ⟹ ⨆⇩S xs ⊆⇩S ⨆⇩S ?ys› ‹set (a # xs) ⊆ set ys› ‹set ys ⊆ set Vars›*) apply auto (*top goal: ‹(a::'a scene) ∈ set (xs::'a scene list) ⟹ a ⊔⇩S ⨆⇩S xs ⊆⇩S ⨆⇩S (ys::'a scene list)› and 1 goal remains*) apply (metis dual_order.trans (*‹⟦?b ≤ ?a; ?c ≤ ?b⟧ ⟹ ?c ≤ ?a›*) scene_union_foldr_remove_element (*‹set ?xs ⊆ set Vars ⟹ ?a ⊔⇩S ⨆⇩S ?xs = ?a ⊔⇩S ⨆⇩S (removeAll ?a ?xs)›*)) (*top goal: ‹⟦(a::'a scene) ∈ set (xs::'a scene list); ⨆⇩S xs = a ⊔⇩S ⨆⇩S (removeAll a xs); ⋀ys::'a scene list. ⟦set xs ⊆ set ys; set ys ⊆ set Vars⟧ ⟹ a ⊔⇩S ⨆⇩S (removeAll a xs) ⊆⇩S ⨆⇩S ys; set (ys::'a scene list) ⊆ set Vars; a ∈ set ys; set xs ⊆ set ys⟧ ⟹ a ⊔⇩S (a ⊔⇩S ⨆⇩S (removeAll a xs)) ⊆⇩S ⨆⇩S ys› and 1 goal remains*) using a_out (*‹a ∉ set xs ⟹ a ⊔⇩S ⨆⇩S xs = ⨆⇩S (a # xs)›*) Cons (*‹⟦set xs ⊆ set ?ys; set ?ys ⊆ set Vars⟧ ⟹ ⨆⇩S xs ⊆⇩S ⨆⇩S ?ys› ‹set (a # xs) ⊆ set ys› ‹set ys ⊆ set Vars›*) apply auto (*goal: ‹⟦a ∉ set xs; ⋀ys. ⟦set xs ⊆ set ys; set ys ⊆ set Vars⟧ ⟹ ⨆⇩S xs ⊆⇩S ⨆⇩S ys; set ys ⊆ set Vars; a ∈ set ys; set xs ⊆ set ys⟧ ⟹ a ⊔⇩S ⨆⇩S xs ⊆⇩S ⨆⇩S ys›*) apply (rule scene_union_mono (*‹⟦?a ⊆⇩S ?c; ?b ⊆⇩S ?c; ?a ##⇩S ?b; idem_scene ?a; idem_scene ?b⟧ ⟹ ?a ⊔⇩S ?b ⊆⇩S ?c›*)) (*goal: ‹⟦a ∉ set xs; a ∈ set ys; set xs ⊆ set ys; ⋀ys. ⟦set xs ⊆ set ys; set ys ⊆ set Vars⟧ ⟹ ⨆⇩S xs ⊆⇩S ⨆⇩S ys; set ys ⊆ set Vars⟧ ⟹ a ⊔⇩S ⨆⇩S xs ⊆⇩S ⨆⇩S ys›*) using scene_in_foldr (*‹⟦?a ∈ set ?xs; set ?xs ⊆ set Vars⟧ ⟹ ?a ⊆⇩S ⨆⇩S ?xs›*) apply blast (*top goal: ‹⟦a ∉ set xs; a ∈ set ys; set xs ⊆ set ys; ⋀ys. ⟦set xs ⊆ set ys; set ys ⊆ set Vars⟧ ⟹ ⨆⇩S xs ⊆⇩S ⨆⇩S ys; set ys ⊆ set Vars⟧ ⟹ a ⊆⇩S ⨆⇩S ys› and 4 goals remain*) apply blast (*top goal: ‹⟦a ∉ set xs; a ∈ set ys; set xs ⊆ set ys; ⋀ys. ⟦set xs ⊆ set ys; set ys ⊆ set Vars⟧ ⟹ ⨆⇩S xs ⊆⇩S ⨆⇩S ys; set ys ⊆ set Vars⟧ ⟹ ⨆⇩S xs ⊆⇩S ⨆⇩S ys› and 3 goals remain*) apply (meson Vars_compat_scene_space (*‹⟦?b ∈ scene_space; ?x ∈ set Vars⟧ ⟹ ?x ##⇩S ?b›*) dual_order.trans (*‹⟦?b ≤ ?a; ?c ≤ ?b⟧ ⟹ ?c ≤ ?a›*) scene_space_foldr (*‹set ?xs ⊆ scene_space ⟹ ⨆⇩S ?xs ∈ scene_space›*) set_Vars_scene_space (*‹set Vars ⊆ scene_space›*) subsetD (*‹⟦?A ⊆ ?B; ?c ∈ ?A⟧ ⟹ ?c ∈ ?B›*)) (*top goal: ‹⟦a ∉ set xs; a ∈ set ys; set xs ⊆ set ys; ⋀ys. ⟦set xs ⊆ set ys; set ys ⊆ set Vars⟧ ⟹ ⨆⇩S xs ⊆⇩S ⨆⇩S ys; set ys ⊆ set Vars⟧ ⟹ a ##⇩S ⨆⇩S xs› and 2 goals remain*) using local.idem_scene_Vars (*‹?x ∈ set Vars ⟹ idem_scene ?x›*) (*goals: 1. ‹⟦(a::'a scene) ∉ set (xs::'a scene list); a ∈ set (ys::'a scene list); set xs ⊆ set ys; ⋀ys::'a scene list. ⟦set xs ⊆ set ys; set ys ⊆ set Vars⟧ ⟹ ⨆⇩S xs ⊆⇩S ⨆⇩S ys; set ys ⊆ set Vars⟧ ⟹ idem_scene a› 2. ‹⟦(a::'a scene) ∉ set (xs::'a scene list); a ∈ set (ys::'a scene list); set xs ⊆ set ys; ⋀ys::'a scene list. ⟦set xs ⊆ set ys; set ys ⊆ set Vars⟧ ⟹ ⨆⇩S xs ⊆⇩S ⨆⇩S ys; set ys ⊆ set Vars⟧ ⟹ idem_scene (⨆⇩S xs)› discuss goal 1*) apply blast (*discuss goal 2*) apply (meson idem_scene_space (*‹?a ∈ scene_space ⟹ idem_scene ?a›*) scene_space_foldr (*‹set ?xs ⊆ scene_space ⟹ ⨆⇩S ?xs ∈ scene_space›*) set_Vars_scene_space (*‹set Vars ⊆ scene_space›*) subset_trans (*‹⟦?A ⊆ ?B; ?B ⊆ ?C⟧ ⟹ ?A ⊆ ?C›*)) (*proven 2 subgoals*) . qed lemma union_scene_space_foldrs: assumes "set xs ⊆ set Vars" "set ys ⊆ set Vars" shows "(foldr (⊔⇩S) xs ⊥⇩S) ⊔⇩S (foldr (⊔⇩S) ys ⊥⇩S) = foldr (⊔⇩S) (xs @ ys) ⊥⇩S" using assms (*‹set xs ⊆ set Vars› ‹set ys ⊆ set Vars›*) apply (induct ys) (*goals: 1. ‹⟦set xs ⊆ set Vars; set [] ⊆ set Vars⟧ ⟹ ⨆⇩S xs ⊔⇩S ⨆⇩S [] = ⨆⇩S (xs @ [])› 2. ‹⋀a ys. ⟦⟦set xs ⊆ set Vars; set ys ⊆ set Vars⟧ ⟹ ⨆⇩S xs ⊔⇩S ⨆⇩S ys = ⨆⇩S (xs @ ys); set xs ⊆ set Vars; set (a # ys) ⊆ set Vars⟧ ⟹ ⨆⇩S xs ⊔⇩S ⨆⇩S (a # ys) = ⨆⇩S (xs @ a # ys)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*goal: ‹⋀(a::'a scene) ys::'a scene list. ⟦⟦set (xs::'a scene list) ⊆ set Vars; set ys ⊆ set Vars⟧ ⟹ ⨆⇩S xs ⊔⇩S ⨆⇩S ys = ⨆⇩S (xs @ ys); set xs ⊆ set Vars; set (a # ys) ⊆ set Vars⟧ ⟹ ⨆⇩S xs ⊔⇩S ⨆⇩S (a # ys) = ⨆⇩S (xs @ a # ys)›*) apply (metis Vars_compat_scene_space (*‹⟦?b ∈ scene_space; ?x ∈ set Vars⟧ ⟹ ?x ##⇩S ?b›*) foldr_scene_union_add_tail (*‹⟦pairwise (##⇩S) (set ?xs); ∀x∈set ?xs. x ##⇩S ?b⟧ ⟹ ⨆⇩S ?xs ⊔⇩S ?b = foldr (⊔⇩S) ?xs ?b›*) local.indep_Vars (*‹scene_indeps (set Vars)›*) pairwise_mono (*‹⟦pairwise ?P ?A; ⋀x y. ?P x y ⟹ ?Q x y; ?B ⊆ ?A⟧ ⟹ pairwise ?Q ?B›*) scene_indep_compat (*‹?X ⨝⇩S ?Y ⟹ ?X ##⇩S ?Y›*) scene_indeps_def (*‹scene_indeps = pairwise (⨝⇩S)›*) scene_space.Vars_scene_space (*‹?x ∈ set Vars ⟹ ?x ∈ scene_space›*) scene_space.union_scene_space (*‹⟦?x ∈ scene_space; ?y ∈ scene_space⟧ ⟹ ?x ⊔⇩S ?y ∈ scene_space›*) scene_space_foldr (*‹set ?xs ⊆ scene_space ⟹ ⨆⇩S ?xs ∈ scene_space›*) subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*)) (*proven 2 subgoals*) . lemma scene_space_ub: assumes "a ∈ scene_space" "b ∈ scene_space" shows "a ⊆⇩S a ⊔⇩S b" using assms (*‹(a::'a::type scene) ∈ scene_space› ‹b ∈ scene_space›*) apply (auto simp add: scene_space_vars_decomp_iff (*‹(?a ∈ scene_space) = (∃xs. set xs ⊆ set Vars ∧ ?a = ⨆⇩S xs)›*) union_scene_space_foldrs (*‹⟦set ?xs ⊆ set Vars; set ?ys ⊆ set Vars⟧ ⟹ ⨆⇩S ?xs ⊔⇩S ⨆⇩S ?ys = ⨆⇩S (?xs @ ?ys)›*)) (*goal: ‹a ⊆⇩S a ⊔⇩S b›*) by (smt (verit, ccfv_SIG) foldr_append (*‹foldr ?f (?xs @ ?ys) ?a = foldr ?f ?xs (foldr ?f ?ys ?a)›*) scene_union_foldr_subset (*‹⟦set ?xs ⊆ set ?ys; set ?ys ⊆ set Vars⟧ ⟹ ⨆⇩S ?xs ⊆⇩S ⨆⇩S ?ys›*) set_append (*‹set (?xs @ ?ys) = set ?xs ∪ set ?ys›*) sup.bounded_iff (*‹(sup ?b ?c ≤ ?a) = (?b ≤ ?a ∧ ?c ≤ ?a)›*) sup_commute (*‹sup ?x ?y = sup ?y ?x›*) sup_ge2 (*‹?y ≤ sup ?x ?y›*)) lemma scene_compl_subset_iff: assumes "a ∈ scene_space" "b ∈ scene_space" shows "- a ⊆⇩S -b ⟷ b ⊆⇩S a" by (metis scene_indep_sym (*‹?X ⨝⇩S ?Y ⟹ ?Y ⨝⇩S ?X›*) scene_le_iff_indep_inv (*‹(?A ⨝⇩S - ?B) = ?A ⊆⇩S ?B›*) uminus_scene_twice (*‹- (- ?X) = ?X›*)) lemma inter_scene_space_foldrs: assumes "set xs ⊆ set Vars" "set ys ⊆ set Vars" shows "⨆⇩S xs ⊓⇩S ⨆⇩S ys = ⨆⇩S (filter (λ x. x ∈ set xs ∩ set ys) Vars)" proof (-) (*goal: ‹⨆⇩S xs ⊓⇩S ⨆⇩S ys = ⨆⇩S (filter (λx. x ∈ set xs ∩ set ys) Vars)›*) have "⨆⇩S xs ⊓⇩S ⨆⇩S ys = - (- ⨆⇩S xs ⊔⇩S - ⨆⇩S ys)" by (simp add: inf_scene_def (*‹?X ⊓⇩S ?Y = - (- ?X ⊔⇩S - ?Y)›*)) also (*calculation: ‹⨆⇩S xs ⊓⇩S ⨆⇩S ys = - (- ⨆⇩S xs ⊔⇩S - ⨆⇩S ys)›*) have "... = - (⨆⇩S (filter (λx. x ∉ set xs) Vars) ⊔⇩S ⨆⇩S (filter (λx. x ∉ set ys) Vars))" by (simp add: uminus_vars_other_vars (*‹set (?xs::'a scene list) ⊆ set Vars ⟹ - ⨆⇩S ?xs = ⨆⇩S (filter (λx::'a scene. x ∉ set ?xs) Vars)›*) assms (*‹set (xs::'a scene list) ⊆ set Vars› ‹set (ys::'a scene list) ⊆ set Vars›*)) also (*calculation: ‹⨆⇩S xs ⊓⇩S ⨆⇩S ys = - (⨆⇩S (filter (λx. x ∉ set xs) Vars) ⊔⇩S ⨆⇩S (filter (λx. x ∉ set ys) Vars))›*) have "... = - ⨆⇩S (filter (λx. x ∉ set xs) Vars @ filter (λx. x ∉ set ys) Vars)" by (simp add: union_scene_space_foldrs (*‹⟦set ?xs ⊆ set Vars; set ?ys ⊆ set Vars⟧ ⟹ ⨆⇩S ?xs ⊔⇩S ⨆⇩S ?ys = ⨆⇩S (?xs @ ?ys)›*) assms (*‹set xs ⊆ set Vars› ‹set ys ⊆ set Vars›*)) also (*calculation: ‹⨆⇩S xs ⊓⇩S ⨆⇩S ys = - ⨆⇩S (filter (λx. x ∉ set xs) Vars @ filter (λx. x ∉ set ys) Vars)›*) have "... = ⨆⇩S (filter (λx. x ∉ set (filter (λx. x ∉ set xs) Vars @ filter (λx. x ∉ set ys) Vars)) Vars)" apply (subst uminus_vars_other_vars (*‹set ?xs ⊆ set Vars ⟹ - ⨆⇩S ?xs = ⨆⇩S (filter (λx. x ∉ set ?xs) Vars)›*)) (*goals: 1. ‹set (filter (λx::'a scene. x ∉ set (xs::'a scene list)) Vars @ filter (λx::'a scene. x ∉ set (ys::'a scene list)) Vars) ⊆ set Vars› 2. ‹⨆⇩S (filter (λx::'a scene. x ∉ set (filter (λx::'a scene. x ∉ set (xs::'a scene list)) Vars @ filter (λx::'a scene. x ∉ set (ys::'a scene list)) Vars)) Vars) = ⨆⇩S (filter (λx::'a scene. x ∉ set (filter (λx::'a scene. x ∉ set xs) Vars @ filter (λx::'a scene. x ∉ set ys) Vars)) Vars)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . also (*calculation: ‹⨆⇩S (xs::'a scene list) ⊓⇩S ⨆⇩S (ys::'a scene list) = ⨆⇩S (filter (λx::'a scene. x ∉ set (filter (λx::'a scene. x ∉ set xs) Vars @ filter (λx::'a scene. x ∉ set ys) Vars)) Vars)›*) have "... = ⨆⇩S (filter (λ x. x ∈ set xs ∩ set ys) Vars)" proof (-) (*goal: ‹⨆⇩S (filter (λx::'a::type scene. x ∉ set (filter (λx::'a::type scene. x ∉ set (xs::'a::type scene list)) Vars @ filter (λx::'a::type scene. x ∉ set (ys::'a::type scene list)) Vars)) Vars) = ⨆⇩S (filter (λx::'a::type scene. x ∈ set xs ∩ set ys) Vars)›*) have "⋀x. x ∈ set Vars ⟹ ((x ∈ set Vars ⟶ x ∈ set xs) ∧ (x ∈ set Vars ⟶ x ∈ set ys)) = (x ∈ set xs ∧ x ∈ set ys)" by auto thus "?thesis" (*goal: ‹⨆⇩S (filter (λx. x ∉ set (filter (λx. x ∉ set xs) Vars @ filter (λx. x ∉ set ys) Vars)) Vars) = ⨆⇩S (filter (λx. x ∈ set xs ∩ set ys) Vars)›*) by (simp cong: arg_cong[where f="⨆⇩S"] (*‹(?x::?'b1 scene list) = (?y::?'b1 scene list) ⟹ ⨆⇩S ?x = ⨆⇩S ?y›*) filter_cong (*‹⟦(?xs::?'a list) = (?ys::?'a list); ⋀x::?'a. x ∈ set ?ys ⟹ (?P::?'a ⇒ bool) x = (?Q::?'a ⇒ bool) x⟧ ⟹ filter ?P ?xs = filter ?Q ?ys›*) add: assms (*‹set (xs::'a scene list) ⊆ set Vars› ‹set (ys::'a scene list) ⊆ set Vars›*)) qed finally (*calculation: ‹⨆⇩S xs ⊓⇩S ⨆⇩S ys = ⨆⇩S (filter (λx. x ∈ set xs ∩ set ys) Vars)›*) show "?thesis" (*goal: ‹⨆⇩S (xs::'a scene list) ⊓⇩S ⨆⇩S (ys::'a scene list) = ⨆⇩S (filter (λx::'a scene. x ∈ set xs ∩ set ys) Vars)›*) . qed lemma scene_inter_distrib_lemma: assumes "set xs ⊆ set Vars" "set ys ⊆ set Vars" "set zs ⊆ set Vars" shows "⨆⇩S xs ⊔⇩S (⨆⇩S ys ⊓⇩S ⨆⇩S zs) = (⨆⇩S xs ⊔⇩S ⨆⇩S ys) ⊓⇩S (⨆⇩S xs ⊔⇩S ⨆⇩S zs)" using assms (*‹set (xs::'a scene list) ⊆ set Vars› ‹set ys ⊆ set Vars› ‹set zs ⊆ set Vars›*) apply (simp only: union_scene_space_foldrs (*‹⟦set ?xs ⊆ set Vars; set ?ys ⊆ set Vars⟧ ⟹ ⨆⇩S ?xs ⊔⇩S ⨆⇩S ?ys = ⨆⇩S (?xs @ ?ys)›*) inter_scene_space_foldrs (*‹⟦set ?xs ⊆ set Vars; set ?ys ⊆ set Vars⟧ ⟹ ⨆⇩S ?xs ⊓⇩S ⨆⇩S ?ys = ⨆⇩S (filter (λx. x ∈ set ?xs ∩ set ?ys) Vars)›*)) (*goal: ‹⨆⇩S xs ⊔⇩S ⨆⇩S ys ⊓⇩S ⨆⇩S zs = (⨆⇩S xs ⊔⇩S ⨆⇩S ys) ⊓⇩S (⨆⇩S xs ⊔⇩S ⨆⇩S zs)›*) apply (subst union_scene_space_foldrs (*‹⟦set ?xs ⊆ set Vars; set ?ys ⊆ set Vars⟧ ⟹ ⨆⇩S ?xs ⊔⇩S ⨆⇩S ?ys = ⨆⇩S (?xs @ ?ys)›*)) (*goals: 1. ‹⟦set xs ⊆ set Vars; set ys ⊆ set Vars; set zs ⊆ set Vars⟧ ⟹ set xs ⊆ set Vars› 2. ‹⟦set xs ⊆ set Vars; set ys ⊆ set Vars; set zs ⊆ set Vars⟧ ⟹ set (filter (λx. x ∈ set ys ∩ set zs) Vars) ⊆ set Vars› 3. ‹⟦set xs ⊆ set Vars; set ys ⊆ set Vars; set zs ⊆ set Vars⟧ ⟹ ⨆⇩S (xs @ filter (λx. x ∈ set ys ∩ set zs) Vars) = ⨆⇩S (xs @ ys) ⊓⇩S ⨆⇩S (xs @ zs)› discuss goal 1*) apply (simp add: assms (*‹set xs ⊆ set Vars› ‹set ys ⊆ set Vars› ‹set zs ⊆ set Vars›*)) (*discuss goal 2*) apply (simp add: assms (*‹set xs ⊆ set Vars› ‹set ys ⊆ set Vars› ‹set zs ⊆ set Vars›*)) (*discuss goal 3*) apply (subst inter_scene_space_foldrs (*‹⟦set ?xs ⊆ set Vars; set ?ys ⊆ set Vars⟧ ⟹ ⨆⇩S ?xs ⊓⇩S ⨆⇩S ?ys = ⨆⇩S (filter (λx. x ∈ set ?xs ∩ set ?ys) Vars)›*)) (*goals: 1. ‹⟦set xs ⊆ set Vars; set ys ⊆ set Vars; set zs ⊆ set Vars⟧ ⟹ set (xs @ ys) ⊆ set Vars› 2. ‹⟦set xs ⊆ set Vars; set ys ⊆ set Vars; set zs ⊆ set Vars⟧ ⟹ set (xs @ zs) ⊆ set Vars› 3. ‹⟦set xs ⊆ set Vars; set ys ⊆ set Vars; set zs ⊆ set Vars⟧ ⟹ ⨆⇩S (xs @ filter (λx. x ∈ set ys ∩ set zs) Vars) = ⨆⇩S (filter (λx. x ∈ set (xs @ ys) ∩ set (xs @ zs)) Vars)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply (rule foldr_scene_union_eq_sets (*‹⟦pairwise (##⇩S) (set ?xs); set ?xs = set ?ys⟧ ⟹ ⨆⇩S ?xs = ⨆⇩S ?ys›*)) (*goals: 1. ‹⟦set xs ⊆ set Vars; set ys ⊆ set Vars; set zs ⊆ set Vars⟧ ⟹ pairwise (##⇩S) (set (xs @ filter (λx. x ∈ set ys ∩ set zs) Vars))› 2. ‹⟦set xs ⊆ set Vars; set ys ⊆ set Vars; set zs ⊆ set Vars⟧ ⟹ set (xs @ filter (λx. x ∈ set ys ∩ set zs) Vars) = set (filter (λx. x ∈ set (xs @ ys) ∩ set (xs @ zs)) Vars)› discuss goal 1*) apply simp (*top goal: ‹⟦set xs ⊆ set Vars; set ys ⊆ set Vars; set zs ⊆ set Vars⟧ ⟹ pairwise (##⇩S) (set (xs @ filter (λx. x ∈ set ys ∩ set zs) Vars))› and 1 goal remains*) apply (smt (verit, ccfv_threshold) Un_subset_iff (*‹(?A ∪ ?B ⊆ ?C) = (?A ⊆ ?C ∧ ?B ⊆ ?C)›*) mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*) pairwise_subset (*‹⟦pairwise ?P ?S; ?T ⊆ ?S⟧ ⟹ pairwise ?P ?T›*) scene_space_compats (*‹pairwise (##⇩S) (set Vars)›*) subset_iff (*‹(?A ⊆ ?B) = (∀t. t ∈ ?A ⟶ t ∈ ?B)›*)) (*discuss goal 2*) apply auto (*proven 2 subgoals*) (*proven 3 subgoals*) (*proven 3 subgoals*) . lemma scene_union_inter_distrib: assumes "a ∈ scene_space" "b ∈ scene_space" "c ∈ scene_space" shows "a ⊔⇩S b ⊓⇩S c = (a ⊔⇩S b) ⊓⇩S (a ⊔⇩S c)" using assms (*‹a ∈ scene_space› ‹b ∈ scene_space› ‹c ∈ scene_space›*) by (auto simp add: scene_space_vars_decomp_iff (*‹(?a ∈ scene_space) = (∃xs. set xs ⊆ set Vars ∧ ?a = ⨆⇩S xs)›*) scene_inter_distrib_lemma (*‹⟦set ?xs ⊆ set Vars; set ?ys ⊆ set Vars; set ?zs ⊆ set Vars⟧ ⟹ ⨆⇩S ?xs ⊔⇩S ⨆⇩S ?ys ⊓⇩S ⨆⇩S ?zs = (⨆⇩S ?xs ⊔⇩S ⨆⇩S ?ys) ⊓⇩S (⨆⇩S ?xs ⊔⇩S ⨆⇩S ?zs)›*)) lemma finite_distinct_lists_subset: assumes "finite A" shows "finite {xs. distinct xs ∧ set xs ⊆ A}" by (metis (no_types, lifting) Collect_cong (*‹(⋀x. ?P x = ?Q x) ⟹ {x. ?P x} = {x. ?Q x}›*) finite_subset_distinct[OF assms] (*‹finite {xs. set xs ⊆ A ∧ distinct xs}›*)) lemma foldr_scene_union_remdups: "set xs ⊆ set Vars ⟹ ⨆⇩S (remdups xs) = ⨆⇩S xs" by (auto intro: foldr_scene_union_eq_sets (*‹⟦pairwise (##⇩S) (set ?xs); set ?xs = set ?ys⟧ ⟹ ⨆⇩S ?xs = ⨆⇩S ?ys›*) simp add: pairwise_compat_Vars_subset (*‹set ?xs ⊆ set Vars ⟹ pairwise (##⇩S) (set ?xs)›*)) lemma scene_space_as_lists: "scene_space = {⨆⇩S xs | xs. distinct xs ∧ set xs ⊆ set Vars}" proof (rule Set.set_eqI (*‹(⋀x::?'a. (x ∈ (?A::?'a set)) = (x ∈ (?B::?'a set))) ⟹ ?A = ?B›*), rule iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*)) (*goals: 1. ‹⋀x. x ∈ scene_space ⟹ x ∈ {⨆⇩S xs |xs. distinct xs ∧ set xs ⊆ set Vars}› 2. ‹⋀x. x ∈ {⨆⇩S xs |xs. distinct xs ∧ set xs ⊆ set Vars} ⟹ x ∈ scene_space›*) fix a assume "a ∈ scene_space" (*‹(a::'a scene) ∈ scene_space›*) then obtain xs where xs: "set xs ⊆ set Vars" "⨆⇩S xs = a" (*goal: ‹(⋀xs. ⟦set xs ⊆ set Vars; ⨆⇩S xs = a⟧ ⟹ thesis) ⟹ thesis›*) using scene_space_vars_decomp_iff (*‹(?a ∈ scene_space) = (∃xs. set xs ⊆ set Vars ∧ ?a = ⨆⇩S xs)›*) by auto thus "a ∈ {⨆⇩S xs |xs. distinct xs ∧ set xs ⊆ set Vars}" apply auto (*goal: ‹(a::'a::type scene) ∈ {⨆⇩S xs |xs::'a::type scene list. distinct xs ∧ set xs ⊆ set Vars}›*) by (metis distinct_remdups (*‹distinct (remdups ?xs)›*) foldr_scene_union_remdups (*‹set ?xs ⊆ set Vars ⟹ ⨆⇩S (remdups ?xs) = ⨆⇩S ?xs›*) set_remdups (*‹set (remdups ?xs) = set ?xs›*)) next (*goal: ‹⋀x::'a scene. x ∈ {⨆⇩S xs |xs::'a scene list. distinct xs ∧ set xs ⊆ set Vars} ⟹ x ∈ scene_space›*) fix a assume "a ∈ {⨆⇩S xs |xs. distinct xs ∧ set xs ⊆ set Vars}" (*‹(a::'a scene) ∈ {⨆⇩S xs |xs::'a scene list. distinct xs ∧ set xs ⊆ set Vars}›*) thus "a ∈ scene_space" using scene_space_vars_decomp_iff (*‹(?a ∈ scene_space) = (∃xs. set xs ⊆ set Vars ∧ ?a = ⨆⇩S xs)›*) by auto qed lemma finite_scene_space: "finite scene_space" proof (-) (*goal: ‹finite scene_space›*) have "scene_space = {⨆⇩S xs | xs. distinct xs ∧ set xs ⊆ set Vars}" by (simp add: scene_space_as_lists (*‹scene_space = {⨆⇩S xs |xs. distinct xs ∧ set xs ⊆ set Vars}›*)) also (*calculation: ‹scene_space = {⨆⇩S xs |xs. distinct xs ∧ set xs ⊆ set Vars}›*) have "... = ⨆⇩S ` {xs. distinct xs ∧ set xs ⊆ set Vars}" by auto also (*calculation: ‹scene_space = ⨆⇩S ` {xs. distinct xs ∧ set xs ⊆ set Vars}›*) have "finite ..." apply (rule finite_imageI (*‹finite ?F ⟹ finite (?h ` ?F)›*)) (*goal: ‹finite (⨆⇩S ` {xs. distinct xs ∧ set xs ⊆ set Vars})›*) by (simp add: finite_distinct_lists_subset (*‹finite ?A ⟹ finite {xs. distinct xs ∧ set xs ⊆ ?A}›*)) finally (*calculation: ‹finite scene_space›*) show "?thesis" (*goal: ‹finite scene_space›*) . qed lemma scene_space_inter_assoc: assumes "x ∈ scene_space" "y ∈ scene_space" "z ∈ scene_space" shows "(x ⊓⇩S y) ⊓⇩S z = x ⊓⇩S (y ⊓⇩S z)" proof (-) (*goal: ‹(x::'a::type scene) ⊓⇩S (y::'a::type scene) ⊓⇩S (z::'a::type scene) = x ⊓⇩S (y ⊓⇩S z)›*) have "(x ⊓⇩S y) ⊓⇩S z = - (- x ⊔⇩S - y ⊔⇩S - z)" by (simp add: scene_demorgan1 (*‹- ((?X::?'a scene) ⊔⇩S (?Y::?'a scene)) = - ?X ⊓⇩S - ?Y›*) uminus_scene_twice (*‹- (- (?X::?'s scene)) = ?X›*)) also (*calculation: ‹x ⊓⇩S y ⊓⇩S z = - (- x ⊔⇩S - y ⊔⇩S - z)›*) have "... = - (- x ⊔⇩S (- y ⊔⇩S - z))" by (simp add: assms (*‹x ∈ scene_space› ‹y ∈ scene_space› ‹z ∈ scene_space›*) scene_space_uminus (*‹?a ∈ scene_space ⟹ - ?a ∈ scene_space›*) scene_space_union_assoc (*‹⟦?x ∈ scene_space; ?y ∈ scene_space; ?z ∈ scene_space⟧ ⟹ ?x ⊔⇩S (?y ⊔⇩S ?z) = ?x ⊔⇩S ?y ⊔⇩S ?z›*)) also (*calculation: ‹x ⊓⇩S y ⊓⇩S z = - (- x ⊔⇩S (- y ⊔⇩S - z))›*) have "... = x ⊓⇩S (y ⊓⇩S z)" by (simp add: scene_demorgan1 (*‹- (?X ⊔⇩S ?Y) = - ?X ⊓⇩S - ?Y›*) uminus_scene_twice (*‹- (- ?X) = ?X›*)) finally (*calculation: ‹(x::'a::type scene) ⊓⇩S (y::'a::type scene) ⊓⇩S (z::'a::type scene) = x ⊓⇩S (y ⊓⇩S z)›*) show "?thesis" (*goal: ‹x ⊓⇩S y ⊓⇩S z = x ⊓⇩S (y ⊓⇩S z)›*) . qed lemma scene_inter_union_distrib: assumes "x ∈ scene_space" "y ∈ scene_space" "z ∈ scene_space" shows "x ⊓⇩S (y ⊔⇩S z) = (x ⊓⇩S y) ⊔⇩S (x ⊓⇩S z)" proof (-) (*goal: ‹(x::'a scene) ⊓⇩S ((y::'a scene) ⊔⇩S (z::'a scene)) = x ⊓⇩S y ⊔⇩S x ⊓⇩S z›*) have "x ⊓⇩S (y ⊔⇩S z) = (x ⊓⇩S (x ⊔⇩S z)) ⊓⇩S (y ⊔⇩S z)" by (metis assms( (*‹(x::'a::type scene) ∈ scene_space›*) 1) assms( (*‹(z::'a::type scene) ∈ scene_space›*) 3) idem_scene_space (*‹(?a::'a::type scene) ∈ scene_space ⟹ idem_scene ?a›*) local.scene_union_inter_distrib (*‹⟦(?a::'a::type scene) ∈ scene_space; (?b::'a::type scene) ∈ scene_space; (?c::'a::type scene) ∈ scene_space⟧ ⟹ ?a ⊔⇩S ?b ⊓⇩S ?c = (?a ⊔⇩S ?b) ⊓⇩S (?a ⊔⇩S ?c)›*) scene_indep_bot (*‹(?X::?'a::type scene) ⨝⇩S ⊥⇩S›*) scene_inter_commute (*‹(?X::?'a::type scene) ⊓⇩S (?Y::?'a::type scene) = ?Y ⊓⇩S ?X›*) scene_inter_indep (*‹⟦idem_scene (?X::?'a::type scene); idem_scene (?Y::?'a::type scene); ?X ⨝⇩S ?Y⟧ ⟹ ?X ⊓⇩S ?Y = ⊥⇩S›*) scene_space.simps (*‹((?a::'a::type scene) ∈ scene_space) = (?a = ⊥⇩S ∨ (∃x::'a::type scene. ?a = x ∧ x ∈ set Vars) ∨ (∃(x::'a::type scene) y::'a::type scene. ?a = x ⊔⇩S y ∧ x ∈ scene_space ∧ y ∈ scene_space))›*) scene_union_unit( (*‹(?X::?'a::type scene) ⊔⇩S ⊥⇩S = ?X›*) 1)) also (*calculation: ‹x ⊓⇩S (y ⊔⇩S z) = x ⊓⇩S (x ⊔⇩S z) ⊓⇩S (y ⊔⇩S z)›*) have "... = (y ⊔⇩S z) ⊓⇩S (x ⊓⇩S (x ⊔⇩S z))" by (simp add: scene_union_inter_distrib (*‹⟦?a ∈ scene_space; ?b ∈ scene_space; ?c ∈ scene_space⟧ ⟹ ?a ⊔⇩S ?b ⊓⇩S ?c = (?a ⊔⇩S ?b) ⊓⇩S (?a ⊔⇩S ?c)›*) assms (*‹x ∈ scene_space› ‹y ∈ scene_space› ‹z ∈ scene_space›*) scene_inter_commute (*‹?X ⊓⇩S ?Y = ?Y ⊓⇩S ?X›*) scene_union_assoc (*‹⟦?X ##⇩S ?Y; ?X ##⇩S ?Z; ?Y ##⇩S ?Z⟧ ⟹ ?X ⊔⇩S (?Y ⊔⇩S ?Z) = ?X ⊔⇩S ?Y ⊔⇩S ?Z›*) union_scene_space (*‹⟦?x ∈ scene_space; ?y ∈ scene_space⟧ ⟹ ?x ⊔⇩S ?y ∈ scene_space›*) scene_space_inter (*‹⟦?a ∈ scene_space; ?b ∈ scene_space⟧ ⟹ ?a ⊓⇩S ?b ∈ scene_space›*) scene_union_commute (*‹?X ⊔⇩S ?Y = ?Y ⊔⇩S ?X›*)) also (*calculation: ‹x ⊓⇩S (y ⊔⇩S z) = (y ⊔⇩S z) ⊓⇩S (x ⊓⇩S (x ⊔⇩S z))›*) have "… = x ⊓⇩S ((y ⊔⇩S z) ⊓⇩S (x ⊔⇩S z))" by (metis assms (*‹x ∈ scene_space› ‹y ∈ scene_space› ‹z ∈ scene_space›*) scene_inter_commute (*‹?X ⊓⇩S ?Y = ?Y ⊓⇩S ?X›*) scene_space.union_scene_space (*‹⟦?x ∈ scene_space; ?y ∈ scene_space⟧ ⟹ ?x ⊔⇩S ?y ∈ scene_space›*) scene_space_inter_assoc (*‹⟦?x ∈ scene_space; ?y ∈ scene_space; ?z ∈ scene_space⟧ ⟹ ?x ⊓⇩S ?y ⊓⇩S ?z = ?x ⊓⇩S (?y ⊓⇩S ?z)›*)) also (*calculation: ‹x ⊓⇩S (y ⊔⇩S z) = x ⊓⇩S ((y ⊔⇩S z) ⊓⇩S (x ⊔⇩S z))›*) have "… = x ⊓⇩S (z ⊔⇩S (x ⊓⇩S y))" by (simp add: assms (*‹x ∈ scene_space› ‹y ∈ scene_space› ‹z ∈ scene_space›*) scene_union_inter_distrib (*‹⟦?a ∈ scene_space; ?b ∈ scene_space; ?c ∈ scene_space⟧ ⟹ ?a ⊔⇩S ?b ⊓⇩S ?c = (?a ⊔⇩S ?b) ⊓⇩S (?a ⊔⇩S ?c)›*) scene_inter_commute (*‹?X ⊓⇩S ?Y = ?Y ⊓⇩S ?X›*) scene_union_commute (*‹?X ⊔⇩S ?Y = ?Y ⊔⇩S ?X›*)) also (*calculation: ‹x ⊓⇩S (y ⊔⇩S z) = x ⊓⇩S (z ⊔⇩S x ⊓⇩S y)›*) have "… = ((x ⊓⇩S y) ⊔⇩S x) ⊓⇩S ((x ⊓⇩S y) ⊔⇩S z)" by (metis (no_types, opaque_lifting) assms( (*‹x ∈ scene_space›*) 1) assms( (*‹y ∈ scene_space›*) 2) idem_scene_space (*‹?a ∈ scene_space ⟹ idem_scene ?a›*) local.scene_union_inter_distrib (*‹⟦?a ∈ scene_space; ?b ∈ scene_space; ?c ∈ scene_space⟧ ⟹ ?a ⊔⇩S ?b ⊓⇩S ?c = (?a ⊔⇩S ?b) ⊓⇩S (?a ⊔⇩S ?c)›*) scene_indep_bot (*‹?X ⨝⇩S ⊥⇩S›*) scene_inter_commute (*‹?X ⊓⇩S ?Y = ?Y ⊓⇩S ?X›*) scene_inter_indep (*‹⟦idem_scene ?X; idem_scene ?Y; ?X ⨝⇩S ?Y⟧ ⟹ ?X ⊓⇩S ?Y = ⊥⇩S›*) scene_space.bot_scene_space (*‹⊥⇩S ∈ scene_space›*) scene_union_commute (*‹?X ⊔⇩S ?Y = ?Y ⊔⇩S ?X›*) scene_union_idem (*‹?X ⊔⇩S ?X = ?X›*) scene_union_unit( (*‹?X ⊔⇩S ⊥⇩S = ?X›*) 1)) also (*calculation: ‹x ⊓⇩S (y ⊔⇩S z) = (x ⊓⇩S y ⊔⇩S x) ⊓⇩S (x ⊓⇩S y ⊔⇩S z)›*) have "… = (x ⊓⇩S y) ⊔⇩S (x ⊓⇩S z)" by (simp add: assms (*‹x ∈ scene_space› ‹y ∈ scene_space› ‹z ∈ scene_space›*) scene_union_inter_distrib (*‹⟦?a ∈ scene_space; ?b ∈ scene_space; ?c ∈ scene_space⟧ ⟹ ?a ⊔⇩S ?b ⊓⇩S ?c = (?a ⊔⇩S ?b) ⊓⇩S (?a ⊔⇩S ?c)›*) scene_space_inter (*‹⟦?a ∈ scene_space; ?b ∈ scene_space⟧ ⟹ ?a ⊓⇩S ?b ∈ scene_space›*)) finally (*calculation: ‹(x::'a scene) ⊓⇩S ((y::'a scene) ⊔⇩S (z::'a scene)) = x ⊓⇩S y ⊔⇩S x ⊓⇩S z›*) show "?thesis" (*goal: ‹x ⊓⇩S (y ⊔⇩S z) = x ⊓⇩S y ⊔⇩S x ⊓⇩S z›*) . qed lemma scene_union_inter_minus: assumes "a ∈ scene_space" "b ∈ scene_space" shows "a ⊔⇩S (b ⊓⇩S - a) = a ⊔⇩S b" by (metis assms( (*‹(a::'a scene) ∈ scene_space›*) 1) assms( (*‹(b::'a scene) ∈ scene_space›*) 2) bot_idem_scene (*‹idem_scene ⊥⇩S›*) idem_scene_space (*‹(?a::'a scene) ∈ scene_space ⟹ idem_scene ?a›*) idem_scene_uminus (*‹idem_scene (?X::?'a scene) ⟹ idem_scene (- ?X)›*) local.scene_union_inter_distrib (*‹⟦(?a::'a scene) ∈ scene_space; (?b::'a scene) ∈ scene_space; (?c::'a scene) ∈ scene_space⟧ ⟹ ?a ⊔⇩S ?b ⊓⇩S ?c = (?a ⊔⇩S ?b) ⊓⇩S (?a ⊔⇩S ?c)›*) scene_demorgan1 (*‹- ((?X::?'a scene) ⊔⇩S (?Y::?'a scene)) = - ?X ⊓⇩S - ?Y›*) scene_space_uminus (*‹(?a::'a scene) ∈ scene_space ⟹ - ?a ∈ scene_space›*) scene_union_compl (*‹idem_scene (?X::?'a scene) ⟹ ?X ⊔⇩S - ?X = ⊤⇩S›*) scene_union_unit( (*‹(?X::?'a scene) ⊔⇩S ⊥⇩S = ?X›*) 1) uminus_scene_twice (*‹- (- (?X::?'s scene)) = ?X›*)) lemma scene_union_foldr_minus_element: assumes "a ∈ scene_space" "set xs ⊆ scene_space" shows "a ⊔⇩S ⨆⇩S xs = a ⊔⇩S ⨆⇩S (map (λ x. x ⊓⇩S - a) xs)" using assms (*‹(a::'a::type scene) ∈ scene_space› ‹set xs ⊆ scene_space›*) proof (induct xs) (*goals: 1. ‹⟦(a::'a scene) ∈ scene_space; set [] ⊆ scene_space⟧ ⟹ a ⊔⇩S ⨆⇩S [] = a ⊔⇩S ⨆⇩S (map (λx::'a scene. x ⊓⇩S - a) [])› 2. ‹⋀(aa::'a scene) xs::'a scene list. ⟦⟦(a::'a scene) ∈ scene_space; set xs ⊆ scene_space⟧ ⟹ a ⊔⇩S ⨆⇩S xs = a ⊔⇩S ⨆⇩S (map (λx::'a scene. x ⊓⇩S - a) xs); a ∈ scene_space; set (aa # xs) ⊆ scene_space⟧ ⟹ a ⊔⇩S ⨆⇩S (aa # xs) = a ⊔⇩S ⨆⇩S (map (λx::'a scene. x ⊓⇩S - a) (aa # xs))›*) case Nil (*‹a ∈ scene_space› ‹set [] ⊆ scene_space›*) then show "?case" (*goal: ‹a ⊔⇩S ⨆⇩S [] = a ⊔⇩S ⨆⇩S (map (λx. x ⊓⇩S - a) [])›*) by simp next (*goal: ‹⋀aa xs. ⟦⟦a ∈ scene_space; set xs ⊆ scene_space⟧ ⟹ a ⊔⇩S ⨆⇩S xs = a ⊔⇩S ⨆⇩S (map (λx. x ⊓⇩S - a) xs); a ∈ scene_space; set (aa # xs) ⊆ scene_space⟧ ⟹ a ⊔⇩S ⨆⇩S (aa # xs) = a ⊔⇩S ⨆⇩S (map (λx. x ⊓⇩S - a) (aa # xs))›*) case (Cons y ys) (*‹⟦(a::'a scene) ∈ scene_space; set (ys::'a scene list) ⊆ scene_space⟧ ⟹ a ⊔⇩S ⨆⇩S ys = a ⊔⇩S ⨆⇩S (map (λx::'a scene. x ⊓⇩S - a) ys)› ‹a ∈ scene_space› ‹set (y # ys) ⊆ scene_space›*) have "a ⊔⇩S (y ⊔⇩S ⨆⇩S ys) = y ⊔⇩S (a ⊔⇩S ⨆⇩S ys)" by (metis Cons.prems( (*‹set (y # ys) ⊆ scene_space›*) 2) assms( (*‹a ∈ scene_space›*) 1) insert_subset (*‹(insert ?x ?A ⊆ ?B) = (?x ∈ ?B ∧ ?A ⊆ ?B)›*) list.simps( (*‹set (?x21.0 # ?x22.0) = insert ?x21.0 (set ?x22.0)›*) 15) scene_space_foldr (*‹set ?xs ⊆ scene_space ⟹ ⨆⇩S ?xs ∈ scene_space›*) scene_space_union_assoc (*‹⟦?x ∈ scene_space; ?y ∈ scene_space; ?z ∈ scene_space⟧ ⟹ ?x ⊔⇩S (?y ⊔⇩S ?z) = ?x ⊔⇩S ?y ⊔⇩S ?z›*) scene_union_commute (*‹?X ⊔⇩S ?Y = ?Y ⊔⇩S ?X›*)) also (*calculation: ‹a ⊔⇩S (y ⊔⇩S ⨆⇩S ys) = y ⊔⇩S (a ⊔⇩S ⨆⇩S ys)›*) have "... = y ⊔⇩S (a ⊔⇩S ⨆⇩S (map (λx. x ⊓⇩S - a) ys))" using Cons.hyps (*‹⟦a ∈ scene_space; set ys ⊆ scene_space⟧ ⟹ a ⊔⇩S ⨆⇩S ys = a ⊔⇩S ⨆⇩S (map (λx. x ⊓⇩S - a) ys)›*) Cons.prems(2) (*‹set (y # ys) ⊆ scene_space›*) assms(1) (*‹a ∈ scene_space›*) by auto also (*calculation: ‹a ⊔⇩S (y ⊔⇩S ⨆⇩S ys) = y ⊔⇩S (a ⊔⇩S ⨆⇩S (map (λx. x ⊓⇩S - a) ys))›*) have "... = y ⊔⇩S a ⊔⇩S ⨆⇩S (map (λx. x ⊓⇩S - a) ys)" apply (subst scene_union_assoc (*‹⟦?X ##⇩S ?Y; ?X ##⇩S ?Z; ?Y ##⇩S ?Z⟧ ⟹ ?X ⊔⇩S (?Y ⊔⇩S ?Z) = ?X ⊔⇩S ?Y ⊔⇩S ?Z›*)) (*goal: ‹y ⊔⇩S (a ⊔⇩S ⨆⇩S (map (λx. x ⊓⇩S - a) ys)) = y ⊔⇩S a ⊔⇩S ⨆⇩S (map (λx. x ⊓⇩S - a) ys)›*) using Cons.prems(2) (*‹set (y # ys) ⊆ scene_space›*) assms(1) (*‹a ∈ scene_space›*) scene_space_compat (*‹⟦?a ∈ scene_space; ?b ∈ scene_space⟧ ⟹ ?a ##⇩S ?b›*) (*goals: 1. ‹y ##⇩S a› 2. ‹y ##⇩S ⨆⇩S (map (λx. x ⊓⇩S - a) ys)› 3. ‹a ##⇩S ⨆⇩S (map (λx. x ⊓⇩S - a) ys)› 4. ‹y ⊔⇩S a ⊔⇩S ⨆⇩S (map (λx. x ⊓⇩S - a) ys) = y ⊔⇩S a ⊔⇩S ⨆⇩S (map (λx. x ⊓⇩S - a) ys)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply (rule pairwise_compat_foldr (*‹⟦pairwise (##⇩S) (set ?as); ∀b∈set ?as. ?a ##⇩S b⟧ ⟹ ?a ##⇩S ⨆⇩S ?as›*)) (*goals: 1. ‹pairwise (##⇩S) (set (map (λx::'a scene. x ⊓⇩S - (a::'a scene)) (ys::'a scene list)))› 2. ‹∀b::'a scene∈set (map (λx::'a scene. x ⊓⇩S - (a::'a scene)) (ys::'a scene list)). (y::'a scene) ##⇩S b› discuss goal 1*) apply simp (*top goal: ‹pairwise (##⇩S) (set (map (λx. x ⊓⇩S - a) ys))› and 3 goals remain*) apply (rule pairwise_imageI (*‹(⋀(x::?'a) y::?'a. ⟦x ∈ (?A::?'a set); y ∈ ?A; x ≠ y; (?f::?'a ⇒ ?'b) x ≠ ?f y⟧ ⟹ (?P::?'b ⇒ ?'b ⇒ bool) (?f x) (?f y)) ⟹ pairwise ?P (?f ` ?A)›*)) (*top goal: ‹pairwise (##⇩S) ((λx. x ⊓⇩S - a) ` set ys)› and 3 goals remain*) apply ((meson Cons.prems( (*‹set (y # ys) ⊆ scene_space›*) 2) assms( (*‹a ∈ scene_space›*) 1) scene_space_compat (*‹⟦?a ∈ scene_space; ?b ∈ scene_space⟧ ⟹ ?a ##⇩S ?b›*) scene_space_inter (*‹⟦?a ∈ scene_space; ?b ∈ scene_space⟧ ⟹ ?a ⊓⇩S ?b ∈ scene_space›*) scene_space_uminus (*‹?a ∈ scene_space ⟹ - ?a ∈ scene_space›*) set_subset_Cons (*‹set ?xs ⊆ set (?x # ?xs)›*) subsetD (*‹⟦?A ⊆ ?B; ?c ∈ ?A⟧ ⟹ ?c ∈ ?B›*))[1]) (*discuss goal 2*) apply simp (*top goal: ‹∀b∈set (map (λx. x ⊓⇩S - a) ys). y ##⇩S b› and 2 goals remain*) apply ((meson Cons.prems( (*‹set (y # ys) ⊆ scene_space›*) 2) assms( (*‹a ∈ scene_space›*) 1) in_mono (*‹?A ⊆ ?B ⟹ ?x ∈ ?A ⟶ ?x ∈ ?B›*) list.set_intros( (*‹?x21.0 ∈ set (?x21.0 # ?x22.0)›*) 1) scene_space_compat (*‹⟦?a ∈ scene_space; ?b ∈ scene_space⟧ ⟹ ?a ##⇩S ?b›*) scene_space_inter (*‹⟦?a ∈ scene_space; ?b ∈ scene_space⟧ ⟹ ?a ⊓⇩S ?b ∈ scene_space›*) scene_space_uminus (*‹?a ∈ scene_space ⟹ - ?a ∈ scene_space›*) set_subset_Cons (*‹set ?xs ⊆ set (?x # ?xs)›*))[1]) (*proven 2 subgoals*) (*discuss goal 3*) apply (rule pairwise_compat_foldr (*‹⟦pairwise (##⇩S) (set ?as); ∀b∈set ?as. ?a ##⇩S b⟧ ⟹ ?a ##⇩S ⨆⇩S ?as›*)) (*goals: 1. ‹pairwise (##⇩S) (set (map (λx::'a::type scene. x ⊓⇩S - (a::'a::type scene)) (ys::'a::type scene list)))› 2. ‹∀b::'a::type scene∈set (map (λx::'a::type scene. x ⊓⇩S - (a::'a::type scene)) (ys::'a::type scene list)). a ##⇩S b› discuss goal 1*) apply simp (*top goal: ‹pairwise (##⇩S) (set (map (λx. x ⊓⇩S - a) ys))› and 2 goals remain*) apply (rule pairwise_imageI (*‹(⋀x y. ⟦x ∈ ?A; y ∈ ?A; x ≠ y; ?f x ≠ ?f y⟧ ⟹ ?P (?f x) (?f y)) ⟹ pairwise ?P (?f ` ?A)›*)) (*top goal: ‹pairwise (##⇩S) ((λx. x ⊓⇩S - a) ` set ys)› and 2 goals remain*) apply ((meson Cons.prems( (*‹set (y # ys) ⊆ scene_space›*) 2) assms( (*‹a ∈ scene_space›*) 1) in_mono (*‹?A ⊆ ?B ⟹ ?x ∈ ?A ⟶ ?x ∈ ?B›*) scene_space_compat (*‹⟦?a ∈ scene_space; ?b ∈ scene_space⟧ ⟹ ?a ##⇩S ?b›*) scene_space_inter (*‹⟦?a ∈ scene_space; ?b ∈ scene_space⟧ ⟹ ?a ⊓⇩S ?b ∈ scene_space›*) scene_space_uminus (*‹?a ∈ scene_space ⟹ - ?a ∈ scene_space›*) set_subset_Cons (*‹set ?xs ⊆ set (?x # ?xs)›*))[1]) (*discuss goal 2*) apply simp (*top goal: ‹∀b∈set (map (λx. x ⊓⇩S - a) ys). a ##⇩S b› and 1 goal remains*) apply ((meson Cons.prems( (*‹set (y # ys) ⊆ scene_space›*) 2) assms( (*‹a ∈ scene_space›*) 1) in_mono (*‹?A ⊆ ?B ⟹ ?x ∈ ?A ⟶ ?x ∈ ?B›*) scene_space_compat (*‹⟦?a ∈ scene_space; ?b ∈ scene_space⟧ ⟹ ?a ##⇩S ?b›*) scene_space_inter (*‹⟦?a ∈ scene_space; ?b ∈ scene_space⟧ ⟹ ?a ⊓⇩S ?b ∈ scene_space›*) scene_space_uminus (*‹?a ∈ scene_space ⟹ - ?a ∈ scene_space›*) set_subset_Cons (*‹set ?xs ⊆ set (?x # ?xs)›*))[1]) (*proven 2 subgoals*) (*discuss goal 4*) apply simp (*proven 4 subgoals*) . also (*calculation: ‹(a::'a scene) ⊔⇩S ((y::'a scene) ⊔⇩S ⨆⇩S (ys::'a scene list)) = y ⊔⇩S a ⊔⇩S ⨆⇩S (map (λx::'a scene. x ⊓⇩S - a) ys)›*) have "... = a ⊔⇩S (y ⊓⇩S - a ⊔⇩S ⨆⇩S (map (λx. x ⊓⇩S - a) ys))" apply (subst scene_union_assoc (*‹⟦?X ##⇩S ?Y; ?X ##⇩S ?Z; ?Y ##⇩S ?Z⟧ ⟹ ?X ⊔⇩S (?Y ⊔⇩S ?Z) = ?X ⊔⇩S ?Y ⊔⇩S ?Z›*)) (*goal: ‹y ⊔⇩S a ⊔⇩S ⨆⇩S (map (λx. x ⊓⇩S - a) ys) = a ⊔⇩S (y ⊓⇩S - a ⊔⇩S ⨆⇩S (map (λx. x ⊓⇩S - a) ys))›*) using Cons.prems(2) (*‹set (y # ys) ⊆ scene_space›*) assms(1) (*‹a ∈ scene_space›*) scene_space_compat (*‹⟦?a ∈ scene_space; ?b ∈ scene_space⟧ ⟹ ?a ##⇩S ?b›*) scene_space_inter (*‹⟦?a ∈ scene_space; ?b ∈ scene_space⟧ ⟹ ?a ⊓⇩S ?b ∈ scene_space›*) scene_space_uminus (*‹?a ∈ scene_space ⟹ - ?a ∈ scene_space›*) apply force (*top goal: ‹(a::'a scene) ##⇩S (y::'a scene) ⊓⇩S - a› and 3 goals remain*) apply (metis (no_types, lifting) Cons.hyps (*‹⟦(a::'a scene) ∈ scene_space; set (ys::'a scene list) ⊆ scene_space⟧ ⟹ a ⊔⇩S ⨆⇩S ys = a ⊔⇩S ⨆⇩S (map (λx::'a scene. x ⊓⇩S - a) ys)›*) Cons.prems( (*‹set ((y::'a scene) # (ys::'a scene list)) ⊆ scene_space›*) 2) assms( (*‹(a::'a scene) ∈ scene_space›*) 1) insert_subset (*‹(insert (?x::?'a) (?A::?'a set) ⊆ (?B::?'a set)) = (?x ∈ ?B ∧ ?A ⊆ ?B)›*) list.simps( (*‹set ((?x21.0::?'a) # (?x22.0::?'a list)) = insert ?x21.0 (set ?x22.0)›*) 15) scene_compat_sym (*‹(?X::?'a scene) ##⇩S (?Y::?'a scene) ⟹ ?Y ##⇩S ?X›*) scene_space_compat (*‹⟦(?a::'a scene) ∈ scene_space; (?b::'a scene) ∈ scene_space⟧ ⟹ ?a ##⇩S ?b›*) scene_space_foldr (*‹set (?xs::'a scene list) ⊆ scene_space ⟹ ⨆⇩S ?xs ∈ scene_space›*) scene_union_assoc (*‹⟦(?X::?'a scene) ##⇩S (?Y::?'a scene); ?X ##⇩S (?Z::?'a scene); ?Y ##⇩S ?Z⟧ ⟹ ?X ⊔⇩S (?Y ⊔⇩S ?Z) = ?X ⊔⇩S ?Y ⊔⇩S ?Z›*) scene_union_idem (*‹(?X::?'a scene) ⊔⇩S ?X = ?X›*) scene_union_incompat (*‹¬ (?X::?'a scene) ##⇩S (?Y::?'a scene) ⟹ ?X ⊔⇩S ?Y = ⊥⇩S›*) scene_union_unit( (*‹(?X::?'a scene) ⊔⇩S ⊥⇩S = ?X›*) 1)) (*top goal: ‹(a::'a::type scene) ##⇩S ⨆⇩S (map (λx::'a::type scene. x ⊓⇩S - a) (ys::'a::type scene list))› and 2 goals remain*) apply (rule scene_space_compat (*‹⟦?a ∈ scene_space; ?b ∈ scene_space⟧ ⟹ ?a ##⇩S ?b›*)) (*top goal: ‹y ⊓⇩S - a ##⇩S ⨆⇩S (map (λx. x ⊓⇩S - a) ys)› and 1 goal remains*) using Cons.prems(2) (*‹set (y # ys) ⊆ scene_space›*) assms(1) (*‹(a::'a scene) ∈ scene_space›*) scene_space_inter (*‹⟦?a ∈ scene_space; ?b ∈ scene_space⟧ ⟹ ?a ⊓⇩S ?b ∈ scene_space›*) scene_space_uminus (*‹(?a::'a::type scene) ∈ scene_space ⟹ - ?a ∈ scene_space›*) (*goals: 1. ‹y ⊓⇩S - a ∈ scene_space› 2. ‹⨆⇩S (map (λx. x ⊓⇩S - a) ys) ∈ scene_space› 3. ‹y ⊔⇩S a ⊔⇩S ⨆⇩S (map (λx. x ⊓⇩S - a) ys) = a ⊔⇩S y ⊓⇩S - a ⊔⇩S ⨆⇩S (map (λx. x ⊓⇩S - a) ys)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply (rule scene_space_foldr (*‹set ?xs ⊆ scene_space ⟹ ⨆⇩S ?xs ∈ scene_space›*)) (*top goal: ‹⨆⇩S (map (λx. x ⊓⇩S - a) ys) ∈ scene_space› and 1 goal remains*) apply ((auto)[1]) (*top goal: ‹set (map (λx. x ⊓⇩S - a) ys) ⊆ scene_space› and 1 goal remains*) apply ((meson Cons.prems( (*‹set (y # ys) ⊆ scene_space›*) 2) assms( (*‹a ∈ scene_space›*) 1) in_mono (*‹?A ⊆ ?B ⟹ ?x ∈ ?A ⟶ ?x ∈ ?B›*) scene_space_inter (*‹⟦?a ∈ scene_space; ?b ∈ scene_space⟧ ⟹ ?a ⊓⇩S ?b ∈ scene_space›*) scene_space_uminus (*‹?a ∈ scene_space ⟹ - ?a ∈ scene_space›*) set_subset_Cons (*‹set ?xs ⊆ set (?x # ?xs)›*))[1]) (*discuss goal 3*) apply ((metis Cons.prems( (*‹set (y # ys) ⊆ scene_space›*) 2) assms( (*‹a ∈ scene_space›*) 1) insert_subset (*‹(insert ?x ?A ⊆ ?B) = (?x ∈ ?B ∧ ?A ⊆ ?B)›*) list.simps( (*‹set (?x21.0 # ?x22.0) = insert ?x21.0 (set ?x22.0)›*) 15) scene_union_inter_minus (*‹⟦?a ∈ scene_space; ?b ∈ scene_space⟧ ⟹ ?a ⊔⇩S ?b ⊓⇩S - ?a = ?a ⊔⇩S ?b›*) scene_union_commute (*‹?X ⊔⇩S ?Y = ?Y ⊔⇩S ?X›*))[1]) (*proven 3 subgoals*) . finally (*calculation: ‹a ⊔⇩S (y ⊔⇩S ⨆⇩S ys) = a ⊔⇩S (y ⊓⇩S - a ⊔⇩S ⨆⇩S (map (λx. x ⊓⇩S - a) ys))›*) show "?case" (*goal: ‹a ⊔⇩S ⨆⇩S (y # ys) = a ⊔⇩S ⨆⇩S (map (λx. x ⊓⇩S - a) (y # ys))›*) using Cons (*‹⟦a ∈ scene_space; set ys ⊆ scene_space⟧ ⟹ a ⊔⇩S ⨆⇩S ys = a ⊔⇩S ⨆⇩S (map (λx. x ⊓⇩S - a) ys)› ‹a ∈ scene_space› ‹set (y # ys) ⊆ scene_space›*) by auto qed lemma scene_space_in_foldr: "⟦ a ∈ set xs; set xs ⊆ scene_space ⟧ ⟹ a ⊆⇩S ⨆⇩S xs" proof (induct xs) (*goals: 1. ‹⟦(a::'a scene) ∈ set []; set [] ⊆ scene_space⟧ ⟹ a ⊆⇩S ⨆⇩S []› 2. ‹⋀(aa::'a scene) xs::'a scene list. ⟦⟦(a::'a scene) ∈ set xs; set xs ⊆ scene_space⟧ ⟹ a ⊆⇩S ⨆⇩S xs; a ∈ set (aa # xs); set (aa # xs) ⊆ scene_space⟧ ⟹ a ⊆⇩S ⨆⇩S (aa # xs)›*) case Nil (*‹a ∈ set []› ‹set [] ⊆ scene_space›*) then show "?case" (*goal: ‹a ⊆⇩S ⨆⇩S []›*) by simp next (*goal: ‹⋀(aa::'a scene) xs::'a scene list. ⟦⟦(a::'a scene) ∈ set xs; set xs ⊆ scene_space⟧ ⟹ a ⊆⇩S ⨆⇩S xs; a ∈ set (aa # xs); set (aa # xs) ⊆ scene_space⟧ ⟹ a ⊆⇩S ⨆⇩S (aa # xs)›*) case (Cons y ys) (*‹⟦a ∈ set ys; set ys ⊆ scene_space⟧ ⟹ a ⊆⇩S ⨆⇩S ys› ‹a ∈ set (y # ys)› ‹set ((y::'a scene) # (ys::'a scene list)) ⊆ scene_space›*) have ysp: "y ⊔⇩S ⨆⇩S ys = y ⊔⇩S ⨆⇩S (map (λ x. x ⊓⇩S - y) ys)" using Cons.prems(2) (*‹set (y # ys) ⊆ scene_space›*) scene_union_foldr_minus_element (*‹⟦(?a::'a::type scene) ∈ scene_space; set (?xs::'a::type scene list) ⊆ scene_space⟧ ⟹ ?a ⊔⇩S ⨆⇩S ?xs = ?a ⊔⇩S ⨆⇩S (map (λx::'a::type scene. x ⊓⇩S - ?a) ?xs)›*) by force show "?case" (*goal: ‹a ⊆⇩S ⨆⇩S (y # ys)›*) proof (cases "a ⊆⇩S y") (*goals: 1. ‹a ⊆⇩S y ⟹ a ⊆⇩S ⨆⇩S (y # ys)› 2. ‹¬ a ⊆⇩S y ⟹ a ⊆⇩S ⨆⇩S (y # ys)›*) case False (*‹¬ a ⊆⇩S y›*) with Cons (*‹⟦(a::'a scene) ∈ set (ys::'a scene list); set ys ⊆ scene_space⟧ ⟹ a ⊆⇩S ⨆⇩S ys› ‹a ∈ set (y # ys)› ‹set ((y::'a scene) # (ys::'a scene list)) ⊆ scene_space›*) show "?thesis" (*goal: ‹a ⊆⇩S ⨆⇩S (y # ys)›*) apply simp (*goal: ‹(a::'a::type scene) ⊆⇩S ⨆⇩S ((y::'a::type scene) # (ys::'a::type scene list))›*) by (metis (no_types, lifting) idem_scene_space (*‹?a ∈ scene_space ⟹ idem_scene ?a›*) scene_space_foldr (*‹set ?xs ⊆ scene_space ⟹ ⨆⇩S ?xs ∈ scene_space›*) scene_space_ub (*‹⟦?a ∈ scene_space; ?b ∈ scene_space⟧ ⟹ ?a ⊆⇩S ?a ⊔⇩S ?b›*) scene_union_commute (*‹?X ⊔⇩S ?Y = ?Y ⊔⇩S ?X›*) subscene_trans (*‹⟦idem_scene ?Y; ?X ⊆⇩S ?Y; ?Y ⊆⇩S ?Z⟧ ⟹ ?X ⊆⇩S ?Z›*)) next (*goal: ‹a ⊆⇩S y ⟹ a ⊆⇩S ⨆⇩S (y # ys)›*) case True (*‹(a::'a scene) ⊆⇩S (y::'a scene)›*) with Cons (*‹⟦a ∈ set ys; set ys ⊆ scene_space⟧ ⟹ a ⊆⇩S ⨆⇩S ys› ‹a ∈ set (y # ys)› ‹set (y # ys) ⊆ scene_space›*) show "?thesis" (*goal: ‹(a::'a scene) ⊆⇩S ⨆⇩S ((y::'a scene) # (ys::'a scene list))›*) apply simp (*goal: ‹a ⊆⇩S ⨆⇩S (y # ys)›*) by (meson idem_scene_space (*‹?a ∈ scene_space ⟹ idem_scene ?a›*) scene_space_foldr (*‹set ?xs ⊆ scene_space ⟹ ⨆⇩S ?xs ∈ scene_space›*) scene_space_ub (*‹⟦?a ∈ scene_space; ?b ∈ scene_space⟧ ⟹ ?a ⊆⇩S ?a ⊔⇩S ?b›*) subscene_trans (*‹⟦idem_scene ?Y; ?X ⊆⇩S ?Y; ?Y ⊆⇩S ?Z⟧ ⟹ ?X ⊆⇩S ?Z›*)) qed qed lemma scene_space_foldr_lb: "⟦ a ∈ scene_space; set xs ⊆ scene_space; ∀ b∈set xs. b ≤ a ⟧ ⟹ ⨆⇩S xs ⊆⇩S a" proof (induct xs arbitrary: a) (*goals: 1. ‹⋀a. ⟦a ∈ scene_space; set [] ⊆ scene_space; ∀b∈set []. b ⊆⇩S a⟧ ⟹ ⨆⇩S [] ⊆⇩S a› 2. ‹⋀a xs aa. ⟦⋀a. ⟦a ∈ scene_space; set xs ⊆ scene_space; ∀b∈set xs. b ⊆⇩S a⟧ ⟹ ⨆⇩S xs ⊆⇩S a; aa ∈ scene_space; set (a # xs) ⊆ scene_space; ∀b∈set (a # xs). b ⊆⇩S aa⟧ ⟹ ⨆⇩S (a # xs) ⊆⇩S aa›*) case Nil (*‹a ∈ scene_space› ‹set [] ⊆ scene_space› ‹∀b::'a::type scene∈set []. b ⊆⇩S (a::'a::type scene)›*) then show "?case" (*goal: ‹⨆⇩S [] ⊆⇩S a›*) by (simp add: scene_bot_least (*‹⊥⇩S ⊆⇩S ?X›*)) next (*goal: ‹⋀(a::'a::type scene) (xs::'a::type scene list) aa::'a::type scene. ⟦⋀a::'a::type scene. ⟦a ∈ scene_space; set xs ⊆ scene_space; ∀b::'a::type scene∈set xs. b ⊆⇩S a⟧ ⟹ ⨆⇩S xs ⊆⇩S a; aa ∈ scene_space; set (a # xs) ⊆ scene_space; ∀b::'a::type scene∈set (a # xs). b ⊆⇩S aa⟧ ⟹ ⨆⇩S (a # xs) ⊆⇩S aa›*) case (Cons x xs) (*‹⟦?a ∈ scene_space; set xs ⊆ scene_space; ∀b∈set xs. b ⊆⇩S ?a⟧ ⟹ ⨆⇩S xs ⊆⇩S ?a› ‹a ∈ scene_space› ‹set (x # xs) ⊆ scene_space› ‹∀b∈set (x # xs). b ⊆⇩S a›*) then show "?case" (*goal: ‹⨆⇩S (x # xs) ⊆⇩S a›*) by (simp add: scene_space_compat (*‹⟦?a ∈ scene_space; ?b ∈ scene_space⟧ ⟹ ?a ##⇩S ?b›*) scene_space_foldr (*‹set ?xs ⊆ scene_space ⟹ ⨆⇩S ?xs ∈ scene_space›*) scene_union_lb (*‹⟦?a ##⇩S ?b; ?a ⊆⇩S ?c; ?b ⊆⇩S ?c⟧ ⟹ ?a ⊔⇩S ?b ⊆⇩S ?c›*)) qed lemma var_le_union_choice: "⟦ x ∈ set Vars; a ∈ scene_space; b ∈ scene_space; x ≤ a ⊔⇩S b ⟧ ⟹ (x ≤ a ∨ x ≤ b)" apply (auto simp add: scene_space_vars_decomp_iff (*‹(?a ∈ scene_space) = (∃xs. set xs ⊆ set Vars ∧ ?a = ⨆⇩S xs)›*)) (*goal: ‹⟦x ∈ set Vars; a ∈ scene_space; b ∈ scene_space; x ⊆⇩S a ⊔⇩S b⟧ ⟹ x ⊆⇩S a ∨ x ⊆⇩S b›*) by (metis Vars_indep_foldr (*‹⟦?x ∈ set Vars; set ?xs ⊆ set Vars⟧ ⟹ ?x ⨝⇩S ⨆⇩S (removeAll ?x ?xs)›*) bot_idem_scene (*‹idem_scene ⊥⇩S›*) idem_scene_space (*‹?a ∈ scene_space ⟹ idem_scene ?a›*) removeAll_id (*‹?x ∉ set ?xs ⟹ removeAll ?x ?xs = ?xs›*) scene_bot_least (*‹⊥⇩S ⊆⇩S ?X›*) scene_indep_pres_compat (*‹⟦?A ⨝⇩S ?B; ?A ⨝⇩S ?C⟧ ⟹ ?A ⨝⇩S ?B ⊔⇩S ?C›*) scene_le_iff_indep_inv (*‹(?A ⨝⇩S - ?B) = ?A ⊆⇩S ?B›*) scene_space.union_scene_space (*‹⟦?x ∈ scene_space; ?y ∈ scene_space⟧ ⟹ ?x ⊔⇩S ?y ∈ scene_space›*) scene_space_foldr (*‹set ?xs ⊆ scene_space ⟹ ⨆⇩S ?xs ∈ scene_space›*) scene_space_in_foldr (*‹⟦?a ∈ set ?xs; set ?xs ⊆ scene_space⟧ ⟹ ?a ⊆⇩S ⨆⇩S ?xs›*) scene_union_compl (*‹idem_scene ?X ⟹ ?X ⊔⇩S - ?X = ⊤⇩S›*) set_Vars_scene_space (*‹set Vars ⊆ scene_space›*) subscene_trans (*‹⟦idem_scene ?Y; ?X ⊆⇩S ?Y; ?Y ⊆⇩S ?Z⟧ ⟹ ?X ⊆⇩S ?Z›*) subset_trans (*‹⟦?A ⊆ ?B; ?B ⊆ ?C⟧ ⟹ ?A ⊆ ?C›*) uminus_scene_twice (*‹- (- ?X) = ?X›*) uminus_top_scene (*‹- ⊤⇩S = ⊥⇩S›*)) lemma var_le_union_iff: "⟦ x ∈ set Vars; a ∈ scene_space; b ∈ scene_space ⟧ ⟹ x ≤ a ⊔⇩S b ⟷ (x ≤ a ∨ x ≤ b)" apply (rule iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*)) (*goals: 1. ‹⟦x ∈ set Vars; a ∈ scene_space; b ∈ scene_space; x ⊆⇩S a ⊔⇩S b⟧ ⟹ x ⊆⇩S a ∨ x ⊆⇩S b› 2. ‹⟦x ∈ set Vars; a ∈ scene_space; b ∈ scene_space; x ⊆⇩S a ∨ x ⊆⇩S b⟧ ⟹ x ⊆⇩S a ⊔⇩S b› discuss goal 1*) apply (simp add: var_le_union_choice (*‹⟦?x ∈ set Vars; ?a ∈ scene_space; ?b ∈ scene_space; ?x ⊆⇩S ?a ⊔⇩S ?b⟧ ⟹ ?x ⊆⇩S ?a ∨ ?x ⊆⇩S ?b›*)) (*discuss goal 2*) apply auto (*goals: 1. ‹⟦x ∈ set Vars; a ∈ scene_space; b ∈ scene_space; x ⊆⇩S a⟧ ⟹ x ⊆⇩S a ⊔⇩S b› 2. ‹⟦x ∈ set Vars; a ∈ scene_space; b ∈ scene_space; x ⊆⇩S b⟧ ⟹ x ⊆⇩S a ⊔⇩S b› discuss goal 1*) apply (meson idem_scene_space (*‹(?a::'a::type scene) ∈ scene_space ⟹ idem_scene ?a›*) scene_space_ub (*‹⟦(?a::'a::type scene) ∈ scene_space; (?b::'a::type scene) ∈ scene_space⟧ ⟹ ?a ⊆⇩S ?a ⊔⇩S ?b›*) subscene_trans (*‹⟦idem_scene (?Y::?'a::type scene); (?X::?'a::type scene) ⊆⇩S ?Y; ?Y ⊆⇩S (?Z::?'a::type scene)⟧ ⟹ ?X ⊆⇩S ?Z›*)) (*discuss goal 2*) apply (metis idem_scene_space (*‹(?a::'a scene) ∈ scene_space ⟹ idem_scene ?a›*) scene_space_ub (*‹⟦(?a::'a scene) ∈ scene_space; (?b::'a scene) ∈ scene_space⟧ ⟹ ?a ⊆⇩S ?a ⊔⇩S ?b›*) scene_union_commute (*‹(?X::?'a scene) ⊔⇩S (?Y::?'a scene) = ?Y ⊔⇩S ?X›*) subscene_trans (*‹⟦idem_scene (?Y::?'a scene); (?X::?'a scene) ⊆⇩S ?Y; ?Y ⊆⇩S (?Z::?'a scene)⟧ ⟹ ?X ⊆⇩S ?Z›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) . text ‹ @{term Vars} may contain the empty scene, as we want to allow vacuous lenses in alphabets › lemma le_vars_then_equal: "⟦ x ∈ set Vars; y ∈ set Vars; x ≤ y; x ≠ ⊥⇩S ⟧ ⟹ x = y" by (metis bot_idem_scene (*‹idem_scene ⊥⇩S›*) foldr_scene_removeAll (*‹pairwise (##⇩S) (set ?xs) ⟹ ?x ⊔⇩S ⨆⇩S (removeAll ?x ?xs) = ?x ⊔⇩S ⨆⇩S ?xs›*) local.idem_scene_Vars (*‹?x ∈ set Vars ⟹ idem_scene ?x›*) local.indep_Vars (*‹scene_indeps (set Vars)›*) local.span_Vars (*‹scene_span Vars›*) pairwiseD (*‹⟦pairwise ?R ?S; ?x ∈ ?S; ?y ∈ ?S; ?x ≠ ?y⟧ ⟹ ?R ?x ?y›*) scene_bot_least (*‹⊥⇩S ⊆⇩S ?X›*) scene_indep_pres_compat (*‹⟦?A ⨝⇩S ?B; ?A ⨝⇩S ?C⟧ ⟹ ?A ⨝⇩S ?B ⊔⇩S ?C›*) scene_indeps_def (*‹scene_indeps = pairwise (⨝⇩S)›*) scene_le_iff_indep_inv (*‹(?A ⨝⇩S - ?B) = ?A ⊆⇩S ?B›*) scene_space_compats (*‹pairwise (##⇩S) (set Vars)›*) scene_span_def (*‹scene_span ?S = (⨆⇩S ?S = ⊤⇩S)›*) scene_union_annhil (*‹idem_scene ?X ⟹ ?X ⊔⇩S ⊤⇩S = ⊤⇩S›*) subscene_antisym (*‹⟦idem_scene ?Y; ?X ⊆⇩S ?Y; ?Y ⊆⇩S ?X⟧ ⟹ ?X = ?Y›*) uminus_scene_twice (*‹- (- ?X) = ?X›*) uminus_top_scene (*‹- ⊤⇩S = ⊥⇩S›*) uminus_var_other_vars (*‹?x ∈ set Vars ⟹ - ?x = ⨆⇩S (removeAll ?x Vars)›*)) end lemma foldr_scene_union_eq_scene_space: "⟦ set xs ⊆ scene_space; set xs = set ys ⟧ ⟹ ⨆⇩S xs = ⨆⇩S ys" by (metis foldr_scene_union_eq_sets (*‹⟦pairwise (##⇩S) (set ?xs); set ?xs = set ?ys⟧ ⟹ ⨆⇩S ?xs = ⨆⇩S ?ys›*) pairwise_def (*‹pairwise ?R ?S = (∀x∈?S. ∀y∈?S. x ≠ y ⟶ ?R x y)›*) pairwise_subset (*‹⟦pairwise ?P ?S; ?T ⊆ ?S⟧ ⟹ pairwise ?P ?T›*) scene_space_compat (*‹⟦?a ∈ scene_space; ?b ∈ scene_space⟧ ⟹ ?a ##⇩S ?b›*)) subsection ‹ Mapping a lens over a scene list › definition map_lcomp :: "'b scene list ⇒ ('b ⟹ 'a) ⇒ 'a scene list" where "map_lcomp ss a = map (λ x. x ;⇩S a) ss" lemma map_lcomp_dist: "⟦ pairwise (##⇩S) (set xs); vwb_lens a ⟧ ⟹ ⨆⇩S (map_lcomp xs a) = ⨆⇩S xs ;⇩S a" by (simp add: foldr_compat_dist (*‹pairwise (##⇩S) (set ?as) ⟹ ⨆⇩S (map (λa. a ;⇩S ?x) ?as) = ⨆⇩S ?as ;⇩S ?x›*) map_lcomp_def (*‹map_lcomp ?ss ?a = map (λx. x ;⇩S ?a) ?ss›*)) lemma map_lcomp_Vars_is_lens [simp]: "vwb_lens a ⟹ ⨆⇩S (map_lcomp Vars a) = ⟦a⟧⇩∼" by (metis map_lcomp_dist (*‹⟦pairwise (##⇩S) (set (?xs::?'a scene list)); vwb_lens (?a::?'a ⟹ ?'b)⟧ ⟹ ⨆⇩S (map_lcomp ?xs ?a) = ⨆⇩S ?xs ;⇩S ?a›*) scene_comp_top_scene (*‹vwb_lens (?x::?'a ⟹ ?'b) ⟹ ⊤⇩S ;⇩S ?x = ⟦?x⟧⇩∼›*) scene_space_compats (*‹pairwise (##⇩S) (set Vars)›*) top_scene_eq (*‹⊤⇩S = ⨆⇩S Vars›*)) lemma set_map_lcomp [simp]: "set (map_lcomp xs a) = (λx. x ;⇩S a) ` set xs" by (simp add: map_lcomp_def (*‹map_lcomp ?ss ?a = map (λx. x ;⇩S ?a) ?ss›*)) subsection ‹ Instances › instantiation unit :: scene_space begin definition Vars_unit :: "unit scene list" where [simp]: "Vars_unit = []" instance by (intro_classes, simp_all add: scene_indeps_def scene_span_def unit_scene_top_eq_bot) end instantiation prod :: (scene_space, scene_space) scene_space begin definition Vars_prod :: "('a × 'b) scene list" where "Vars_prod = map_lcomp Vars fst⇩L @ map_lcomp Vars snd⇩L" instance proof have pw: "pairwise (⨝⇩S) (set (map_lcomp Vars fst⇩L @ map_lcomp Vars snd⇩L))" by (auto simp add: pairwise_def Vars_ext_lens_indep scene_comp_pres_indep scene_indep_sym) show "⋀x:: ('a × 'b) scene. x ∈ set Vars ⟹ idem_scene x" by (auto simp add: Vars_prod_def) from pw show "scene_indeps (set (Vars :: ('a × 'b) scene list))" by (simp add: Vars_prod_def scene_indeps_def) show "scene_span (Vars :: ('a × 'b) scene list)" by (simp only: scene_span_def Vars_prod_def foldr_scene_append pw pairwise_indep_then_compat map_lcomp_Vars_is_lens fst_vwb_lens snd_vwb_lens) (metis fst_vwb_lens lens_plus_scene lens_scene_top_iff_bij_lens plus_mwb_lens scene_union_commute snd_fst_lens_indep snd_vwb_lens swap_bij_lens vwb_lens_mwb) qed end subsection ‹ Scene space and basis lenses › locale var_lens = vwb_lens + assumes lens_in_scene_space: "⟦x⟧⇩∼ ∈ scene_space" declare var_lens.lens_in_scene_space [simp] declare var_lens.axioms(1) [simp] locale basis_lens = vwb_lens + assumes lens_in_basis: "⟦x⟧⇩∼ ∈ set Vars" sublocale basis_lens ⊆ var_lens using lens_in_basis (*‹⟦x⟧⇩∼ ∈ set Vars›*) var_lens_axioms_def (*‹var_lens_axioms ?x ≡ ⟦?x⟧⇩∼ ∈ scene_space›*) var_lens_def (*‹var_lens ?x ≡ vwb_lens ?x ∧ var_lens_axioms ?x›*) vwb_lens_axioms (*‹vwb_lens x›*) by blast declare basis_lens.lens_in_basis [simp] text ‹ Effectual variable and basis lenses need to have at least two view elements › abbreviation (input) evar_lens :: "('a::two ⟹ 's::scene_space) ⇒ bool" where "evar_lens ≡ var_lens" abbreviation (input) ebasis_lens :: "('a::two ⟹ 's::scene_space) ⇒ bool" where "ebasis_lens ≡ basis_lens" lemma basis_then_var [simp]: "basis_lens x ⟹ var_lens x" using basis_lens.lens_in_basis (*‹basis_lens ?x ⟹ ⟦?x⟧⇩∼ ∈ set Vars›*) basis_lens_def (*‹basis_lens ?x ≡ vwb_lens ?x ∧ basis_lens_axioms ?x›*) var_lens_axioms_def (*‹var_lens_axioms ?x ≡ ⟦?x⟧⇩∼ ∈ scene_space›*) var_lens_def (*‹var_lens ?x ≡ vwb_lens ?x ∧ var_lens_axioms ?x›*) by blast lemma basis_lens_intro: "⟦ vwb_lens x; ⟦x⟧⇩∼ ∈ set Vars ⟧ ⟹ basis_lens x" using basis_lens.intro (*‹⟦vwb_lens (?x::?'a ⟹ ?'b); basis_lens_axioms ?x⟧ ⟹ basis_lens ?x›*) basis_lens_axioms.intro (*‹⟦?x⟧⇩∼ ∈ set Vars ⟹ basis_lens_axioms ?x›*) by blast subsection ‹ Composite lenses › locale composite_lens = vwb_lens + assumes comp_in_Vars: "(λ a. a ;⇩S x) ` set Vars ⊆ set Vars" begin lemma Vars_closed_comp: "a ∈ set Vars ⟹ a ;⇩S x ∈ set Vars" using comp_in_Vars (*‹(λa::'a scene. a ;⇩S x) ` set Vars ⊆ set Vars›*) by blast lemma scene_space_closed_comp: assumes "a ∈ scene_space" shows "a ;⇩S x ∈ scene_space" proof (-) (*goal: ‹a ;⇩S x ∈ scene_space›*) obtain xs where xs: "a = ⨆⇩S xs" "set xs ⊆ set Vars" (*goal: ‹(⋀xs. ⟦a = ⨆⇩S xs; set xs ⊆ set Vars⟧ ⟹ thesis) ⟹ thesis›*) using assms (*‹(a::'a scene) ∈ scene_space›*) scene_space_vars_decomp (*‹?a ∈ scene_space ⟹ ∃xs. set xs ⊆ set Vars ∧ ⨆⇩S xs = ?a›*) by blast have "(⨆⇩S xs) ;⇩S x = ⨆⇩S (map (λ a. a ;⇩S x) xs)" by (metis foldr_compat_dist (*‹pairwise (##⇩S) (set ?as) ⟹ ⨆⇩S (map (λa. a ;⇩S ?x) ?as) = ⨆⇩S ?as ;⇩S ?x›*) pairwise_subset (*‹⟦pairwise ?P ?S; ?T ⊆ ?S⟧ ⟹ pairwise ?P ?T›*) scene_space_compats (*‹pairwise (##⇩S) (set Vars)›*) xs( (*‹set xs ⊆ set Vars›*) 2)) also (*calculation: ‹⨆⇩S xs ;⇩S x = ⨆⇩S (map (λa. a ;⇩S x) xs)›*) have "... ∈ scene_space" apply (auto simp add: scene_space_vars_decomp_iff (*‹(?a ∈ scene_space) = (∃xs. set xs ⊆ set Vars ∧ ?a = ⨆⇩S xs)›*)) (*goal: ‹⨆⇩S (map (λa::'a scene. a ;⇩S x) (xs::'a scene list)) ∈ scene_space›*) by (metis comp_in_Vars (*‹(λa. a ;⇩S x) ` set Vars ⊆ set Vars›*) image_Un (*‹?f ` (?A ∪ ?B) = ?f ` ?A ∪ ?f ` ?B›*) le_iff_sup (*‹(?x ≤ ?y) = (sup ?x ?y = ?y)›*) le_supE (*‹⟦sup ?a ?b ≤ ?x; ⟦?a ≤ ?x; ?b ≤ ?x⟧ ⟹ ?P⟧ ⟹ ?P›*) list.set_map (*‹set (map ?f ?v) = ?f ` set ?v›*) xs( (*‹set xs ⊆ set Vars›*) 2)) finally (*calculation: ‹⨆⇩S xs ;⇩S x ∈ scene_space›*) show "?thesis" (*goal: ‹a ;⇩S x ∈ scene_space›*) by (simp add: xs (*‹a = ⨆⇩S xs› ‹set xs ⊆ set Vars›*)) qed sublocale var_lens proof (standard) (*goal: ‹⟦x⟧⇩∼ ∈ scene_space›*) show "⟦x⟧⇩∼ ∈ scene_space" by (metis scene_comp_top_scene (*‹vwb_lens ?x ⟹ ⊤⇩S ;⇩S ?x = ⟦?x⟧⇩∼›*) scene_space_closed_comp (*‹?a ∈ scene_space ⟹ ?a ;⇩S x ∈ scene_space›*) top_scene_space (*‹⊤⇩S ∈ scene_space›*) vwb_lens_axioms (*‹vwb_lens x›*)) qed end lemma composite_implies_var_lens [simp]: "composite_lens x ⟹ var_lens x" by (metis composite_lens.axioms( (*‹composite_lens ?x ⟹ vwb_lens ?x›*) 1) composite_lens.scene_space_closed_comp (*‹⟦composite_lens ?x; ?a ∈ scene_space⟧ ⟹ ?a ;⇩S ?x ∈ scene_space›*) scene_comp_top_scene (*‹vwb_lens ?x ⟹ ⊤⇩S ;⇩S ?x = ⟦?x⟧⇩∼›*) top_scene_space (*‹⊤⇩S ∈ scene_space›*) var_lens_axioms.intro (*‹⟦?x⟧⇩∼ ∈ scene_space ⟹ var_lens_axioms ?x›*) var_lens_def (*‹var_lens ?x ≡ vwb_lens ?x ∧ var_lens_axioms ?x›*)) text ‹ The extension of any lens in the scene space remains in the scene space › lemma composite_lens_comp [simp]: "⟦ composite_lens a; var_lens x ⟧ ⟹ var_lens (x ;⇩L a)" by (metis comp_vwb_lens (*‹⟦vwb_lens ?x; vwb_lens ?y⟧ ⟹ vwb_lens (?x ;⇩L ?y)›*) composite_lens.scene_space_closed_comp (*‹⟦composite_lens ?x; ?a ∈ scene_space⟧ ⟹ ?a ;⇩S ?x ∈ scene_space›*) composite_lens_def (*‹composite_lens ?x ≡ vwb_lens ?x ∧ composite_lens_axioms ?x›*) lens_scene_comp (*‹⟦vwb_lens ?X; vwb_lens ?Y⟧ ⟹ ⟦?X ;⇩L ?Y⟧⇩∼ = ⟦?X⟧⇩∼ ;⇩S ?Y›*) var_lens_axioms_def (*‹var_lens_axioms ?x ≡ ⟦?x⟧⇩∼ ∈ scene_space›*) var_lens_def (*‹var_lens ?x ≡ vwb_lens ?x ∧ var_lens_axioms ?x›*)) lemma comp_composite_lens [simp]: "⟦ composite_lens a; composite_lens x ⟧ ⟹ composite_lens (x ;⇩L a)" apply (auto intro!: composite_lens.intro (*‹⟦vwb_lens (?x::?'a ⟹ ?'b); composite_lens_axioms ?x⟧ ⟹ composite_lens ?x›*) simp add: composite_lens_axioms_def (*‹composite_lens_axioms (?x::?'a ⟹ ?'b) ≡ (λa::?'a scene. a ;⇩S ?x) ` set Vars ⊆ set Vars›*)) (*goal: ‹⟦composite_lens (a::'a ⟹ 'b); composite_lens (x::'c ⟹ 'a)⟧ ⟹ composite_lens (x ;⇩L a)›*) by (metis composite_lens.Vars_closed_comp (*‹⟦composite_lens ?x; ?a ∈ set Vars⟧ ⟹ ?a ;⇩S ?x ∈ set Vars›*) composite_lens.axioms( (*‹composite_lens ?x ⟹ vwb_lens ?x›*) 1) scene_comp_assoc (*‹⟦vwb_lens ?X; vwb_lens ?Y⟧ ⟹ ?A ;⇩S ?X ;⇩S ?Y = ?A ;⇩S (?X ;⇩L ?Y)›*)) text ‹ A basis lens within a composite lens remains a basis lens (i.e. it remains atomic) › lemma composite_lens_basis_comp [simp]: "⟦ composite_lens a; basis_lens x ⟧ ⟹ basis_lens (x ;⇩L a)" by (metis basis_lens.lens_in_basis (*‹basis_lens ?x ⟹ ⟦?x⟧⇩∼ ∈ set Vars›*) basis_lens_def (*‹basis_lens ?x ≡ vwb_lens ?x ∧ basis_lens_axioms ?x›*) basis_lens_intro (*‹⟦vwb_lens ?x; ⟦?x⟧⇩∼ ∈ set Vars⟧ ⟹ basis_lens ?x›*) comp_vwb_lens (*‹⟦vwb_lens ?x; vwb_lens ?y⟧ ⟹ vwb_lens (?x ;⇩L ?y)›*) composite_lens.Vars_closed_comp (*‹⟦composite_lens ?x; ?a ∈ set Vars⟧ ⟹ ?a ;⇩S ?x ∈ set Vars›*) composite_lens_def (*‹composite_lens ?x ≡ vwb_lens ?x ∧ composite_lens_axioms ?x›*) lens_scene_comp (*‹⟦vwb_lens ?X; vwb_lens ?Y⟧ ⟹ ⟦?X ;⇩L ?Y⟧⇩∼ = ⟦?X⟧⇩∼ ;⇩S ?Y›*)) lemma id_composite_lens: "composite_lens 1⇩L" by (force intro: composite_lens.intro (*‹⟦vwb_lens ?x; composite_lens_axioms ?x⟧ ⟹ composite_lens ?x›*) composite_lens_axioms.intro (*‹(λa. a ;⇩S ?x) ` set Vars ⊆ set Vars ⟹ composite_lens_axioms ?x›*)) lemma fst_composite_lens: "composite_lens fst⇩L" apply (rule composite_lens.intro (*‹⟦vwb_lens ?x; composite_lens_axioms ?x⟧ ⟹ composite_lens ?x›*)) (*goals: 1. ‹vwb_lens fst⇩L› 2. ‹composite_lens_axioms fst⇩L› discuss goal 1*) apply (simp add: fst_vwb_lens (*‹vwb_lens fst⇩L›*)) (*discuss goal 2*) apply (rule composite_lens_axioms.intro (*‹(λa. a ;⇩S ?x) ` set Vars ⊆ set Vars ⟹ composite_lens_axioms ?x›*)) (*goal: ‹composite_lens_axioms fst⇩L›*) apply (simp add: Vars_prod_def (*‹Vars = map_lcomp Vars fst⇩L @ map_lcomp Vars snd⇩L›*)) (*proven 2 subgoals*) . lemma snd_composite_lens: "composite_lens snd⇩L" apply (rule composite_lens.intro (*‹⟦vwb_lens ?x; composite_lens_axioms ?x⟧ ⟹ composite_lens ?x›*)) (*goals: 1. ‹vwb_lens snd⇩L› 2. ‹composite_lens_axioms snd⇩L› discuss goal 1*) apply (simp add: snd_vwb_lens (*‹vwb_lens snd⇩L›*)) (*discuss goal 2*) apply (rule composite_lens_axioms.intro (*‹(λa. a ;⇩S ?x) ` set Vars ⊆ set Vars ⟹ composite_lens_axioms ?x›*)) (*goal: ‹composite_lens_axioms snd⇩L›*) apply (simp add: Vars_prod_def (*‹Vars = map_lcomp Vars fst⇩L @ map_lcomp Vars snd⇩L›*)) (*proven 2 subgoals*) . end
{ "path": "afp-2025-02-12/thys/Optics/Scene_Spaces.thy", "repo": "afp-2025-02-12", "sha": "9880d169546d01b2f100285d3a8fb2f71ce3088e17ea772efe7fa2bf40a1d06e" }
section ‹Algorithms to compute all complex and real roots of a quartic polynomial› theory Quartic_Polynomials imports Ferraris_Formula Cubic_Polynomials begin text ‹The complex case is straight-forward› definition solve_depressed_quartic_complex :: "complex ⇒ complex ⇒ complex ⇒ complex list" where "solve_depressed_quartic_complex p q r = remdups (if q = 0 then (concat (map (λ z. let y = csqrt z in [y,-y]) (croots2 [:r,p,1:]))) else let cubics = croots3 [: - (q^2), 2 * p^2 - 8 * r, 8 * p, 8:]; m = hd cubics; ― ‹select any root of the cubic polynomial› a = csqrt (2 * m); p2m = p / 2 + m; q2a = q / (2 * a); b1 = p2m - q2a; b2 = p2m + q2a in (croots2 [:b1,a,1:] @ croots2 [:b2,-a,1:]))" lemma solve_depressed_quartic_complex: "x ∈ set (solve_depressed_quartic_complex p q r) ⟷ (x^4 + p * x^2 + q * x + r = 0)" proof (-) (*goal: ‹(x ∈ set (solve_depressed_quartic_complex p q r)) = (x ^ 4 + p * x² + q * x + r = 0)›*) note powers = field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹((?a::?'a) = (?c::?'a) - (?b::?'a)) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹(?a::?'a::ab_group_add) - (?b::?'a::ab_group_add) + (?c::?'a::ab_group_add) = ?a + ?c - ?b› and more 69 facts*) power4_eq_xxxx (*‹?x ^ 4 = ?x * ?x * ?x * ?x›*) power3_eq_cube (*‹?a ^ 3 = ?a * ?a * ?a›*) power2_eq_square (*‹(?a::?'a)² = ?a * ?a›*) show "?thesis" (*goal: ‹(x ∈ set (solve_depressed_quartic_complex p q r)) = (x ^ 4 + p * x² + q * x + r = 0)›*) proof (cases "q = 0") (*goals: 1. ‹q = 0 ⟹ (x ∈ set (solve_depressed_quartic_complex p q r)) = (x ^ 4 + p * x² + q * x + r = 0)› 2. ‹q ≠ 0 ⟹ (x ∈ set (solve_depressed_quartic_complex p q r)) = (x ^ 4 + p * x² + q * x + r = 0)›*) case True (*‹q = 0›*) have csqrt: "z = x^2 ⟷ (x = csqrt z ∨ x = - csqrt z)" for z by (metis power2_csqrt (*‹(csqrt ?z)² = ?z›*) power2_eq_iff (*‹(?x² = ?y²) = (?x = ?y ∨ ?x = - ?y)›*)) have "(x ^ 4 + p * x² + q * x + r = 0) ⟷ (x ^ 4 + p * x² + r = 0)" unfolding True (*goal: ‹(x ^ 4 + p * x² + 0 * x + r = 0) = (x ^ 4 + p * x² + r = 0)›*) by simp also (*calculation: ‹(x ^ 4 + p * x² + q * x + r = 0) = (x ^ 4 + p * x² + r = 0)›*) have "… ⟷ (∃z. z² + p * z + r = 0 ∧ z = x²)" unfolding biquadratic_solution (*goal: ‹(∃z. z² + p * z + r = 0 ∧ z = x²) = (∃z. z² + p * z + r = 0 ∧ z = x²)›*) by simp also (*calculation: ‹((x::complex) ^ (4::nat) + (p::complex) * x² + (q::complex) * x + (r::complex) = (0::complex)) = (∃z::complex. z² + p * z + r = (0::complex) ∧ z = x²)›*) have "… ⟷ (∃ z. poly [:r,p,1:] z = 0 ∧ z = x^2)" by (simp add: powers (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 72 facts*)) also (*calculation: ‹(x ^ 4 + p * x² + q * x + r = 0) = (∃z. poly [:r, p, 1:] z = 0 ∧ z = x²)›*) have "… ⟷ (∃ z ∈ set (croots2 [:r,p,1:]). z = x^2)" apply (subst croots2[symmetric] (*‹degree ?p = 2 ⟹ set (croots2 ?p) = {x. poly ?p x = 0}›*)) (*goals: 1. ‹degree [:r, p, 1:] = 2› 2. ‹(∃z. poly [:r, p, 1:] z = 0 ∧ z = x²) = (∃z∈{x. poly [:r, p, 1:] x = 0}. z = x²)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . also (*calculation: ‹((x::complex) ^ (4::nat) + (p::complex) * x² + (q::complex) * x + (r::complex) = (0::complex)) = (∃z::complex∈set (croots2 [:r, p, 1::complex:]). z = x²)›*) have "… ⟷ (∃ z ∈ set (croots2 [:r,p,1:]). x = csqrt z ∨ x = - csqrt z)" unfolding csqrt (*goal: ‹(∃z::complex∈set (croots2 [:r::complex, p::complex, 1::complex:]). (x::complex) = csqrt z ∨ x = - csqrt z) = (∃z::complex∈set (croots2 [:r, p, 1::complex:]). x = csqrt z ∨ x = - csqrt z)›*) by standard also (*calculation: ‹(x ^ 4 + p * x² + q * x + r = 0) = (∃z∈set (croots2 [:r, p, 1:]). x = csqrt z ∨ x = - csqrt z)›*) have "… ⟷ (x ∈ set (solve_depressed_quartic_complex p q r))" unfolding solve_depressed_quartic_complex_def id (*goal: ‹(∃z::complex∈set (croots2 [:r::complex, p::complex, 1::complex:]). (x::complex) = csqrt z ∨ x = - csqrt z) = (x ∈ set (remdups (if (q::complex) = (0::complex) then concat (map (λz::complex. let y::complex = csqrt z in [y, - y]) (croots2 [:r, p, 1::complex:])) else let cubics::complex list = croots3 [:- q², (2::complex) * p² - (8::complex) * r, (8::complex) * p, 8::complex:]; m::complex = hd cubics; a::complex = csqrt ((2::complex) * m); p2m::complex = p / (2::complex) + m; q2a::complex = q / ((2::complex) * a); b1::complex = p2m - q2a; b2::complex = p2m + q2a in croots2 [:b1, a, 1::complex:] @ croots2 [:b2, - a, 1::complex:])))›*) unfolding True Let_def (*goal: ‹(∃z∈set (croots2 [:r, p, 1:]). x = csqrt z ∨ x = - csqrt z) = (x ∈ set (remdups (if 0 = 0 then concat (map (λz. [csqrt z, - csqrt z]) (croots2 [:r, p, 1:])) else croots2 [:p / 2 + hd (croots3 [:- 0², 2 * p² - 8 * r, 8 * p, 8:]) - 0 / (2 * csqrt (2 * hd (croots3 [:- 0², 2 * p² - 8 * r, 8 * p, 8:]))), csqrt (2 * hd (croots3 [:- 0², 2 * p² - 8 * r, 8 * p, 8:])), 1:] @ croots2 [:p / 2 + hd (croots3 [:- 0², 2 * p² - 8 * r, 8 * p, 8:]) + 0 / (2 * csqrt (2 * hd (croots3 [:- 0², 2 * p² - 8 * r, 8 * p, 8:]))), - csqrt (2 * hd (croots3 [:- 0², 2 * p² - 8 * r, 8 * p, 8:])), 1:])))›*) by auto finally (*calculation: ‹(x ^ 4 + p * x² + q * x + r = 0) = (x ∈ set (solve_depressed_quartic_complex p q r))›*) show "?thesis" (*goal: ‹(x ∈ set (solve_depressed_quartic_complex p q r)) = (x ^ 4 + p * x² + q * x + r = 0)›*) apply - (*goal: ‹(x ∈ set (solve_depressed_quartic_complex p q r)) = (x ^ 4 + p * x² + q * x + r = 0)›*) apply standard (*goals: 1. ‹⟦(x ^ 4 + p * x² + q * x + r = 0) = (x ∈ set (solve_depressed_quartic_complex p q r)); x ∈ set (solve_depressed_quartic_complex p q r)⟧ ⟹ x ^ 4 + p * x² + q * x + r = 0› 2. ‹⟦(x ^ 4 + p * x² + q * x + r = 0) = (x ∈ set (solve_depressed_quartic_complex p q r)); x ^ 4 + p * x² + q * x + r = 0⟧ ⟹ x ∈ set (solve_depressed_quartic_complex p q r)› discuss goal 1*) apply ((msorry)[1]) (*discuss goal 2*) apply ((msorry)[1]) (*proven 2 subgoals*) . next (*goal: ‹q ≠ 0 ⟹ (x ∈ set (solve_depressed_quartic_complex p q r)) = (x ^ 4 + p * x² + q * x + r = 0)›*) case q0: False (*‹q ≠ 0›*) hence id: "(if q = 0 then x else y) = y" for x :: "complex list" and y :: "complex list" by auto note powers = field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹(?a::?'a) - (?b::?'a) - (?c::?'a) = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹((?a::?'a::group_add) - (?b::?'a::group_add) = (?c::?'a::group_add)) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 69 facts*) power4_eq_xxxx (*‹(?x::?'a::monoid_mult) ^ (4::nat) = ?x * ?x * ?x * ?x›*) power3_eq_cube (*‹?a ^ 3 = ?a * ?a * ?a›*) power2_eq_square (*‹?a² = ?a * ?a›*) let ?poly = "[:- q², 2 * p² - 8 * r, 8 * p, 8:]" from croots3[of ?poly] (*‹degree [:- q², 2 * p² - 8 * r, 8 * p, 8:] = 3 ⟹ set (croots3 [:- q², 2 * p² - 8 * r, 8 * p, 8:]) = {x. poly [:- q², 2 * p² - 8 * r, 8 * p, 8:] x = 0}›*) have croots: "set (croots3 ?poly) = {x. poly ?poly x = 0}" by auto from fundamental_theorem_of_algebra_alt[of ?poly] (*‹∄a l. a ≠ 0 ∧ l = 0 ∧ [:- q², 2 * p² - 8 * r, 8 * p, 8:] = pCons a l ⟹ ∃z. poly [:- q², 2 * p² - 8 * r, 8 * p, 8:] z = 0›*) have "{x. poly ?poly x = 0} ≠ {}" by auto with croots (*‹set (croots3 [:- q², 2 * p² - 8 * r, 8 * p, 8:]) = {x. poly [:- q², 2 * p² - 8 * r, 8 * p, 8:] x = 0}›*) have "croots3 ?poly ≠ []" by auto then obtain m and rest where rts: "croots3 ?poly = m # rest" (*goal: ‹(⋀m rest. croots3 [:- q², 2 * p² - 8 * r, 8 * p, 8:] = m # rest ⟹ thesis) ⟹ thesis›*) apply (cases "croots3 ?poly") (*goals: 1. ‹⟦⋀m rest. croots3 [:- q², 2 * p² - 8 * r, 8 * p, 8:] = m # rest ⟹ thesis; croots3 [:- q², 2 * p² - 8 * r, 8 * p, 8:] ≠ []; croots3 [:- q², 2 * p² - 8 * r, 8 * p, 8:] = []⟧ ⟹ thesis› 2. ‹⋀a list. ⟦⋀m rest. croots3 [:- q², 2 * p² - 8 * r, 8 * p, 8:] = m # rest ⟹ thesis; croots3 [:- q², 2 * p² - 8 * r, 8 * p, 8:] ≠ []; croots3 [:- q², 2 * p² - 8 * r, 8 * p, 8:] = a # list⟧ ⟹ thesis› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . hence hd: "hd (croots3 ?poly) = m" by auto from croots[unfolded rts] (*‹set (m # rest) = {x. poly [:- q², 2 * p² - 8 * r, 8 * p, 8:] x = 0}›*) have "poly ?poly m = 0" by auto hence mrt: "8*m^3 + (8 * p) * m^2 + (2 * p^2 - 8 * r) * m - q^2 = 0" and m0: "m ≠ 0" using q0 (*‹q ≠ 0›*) apply - (*goals: 1. ‹⟦poly [:- (q::complex)², (2::complex) * (p::complex)² - (8::complex) * (r::complex), (8::complex) * p, 8::complex:] (m::complex) = (0::complex); q ≠ (0::complex)⟧ ⟹ (8::complex) * m ^ (3::nat) + (8::complex) * p * m² + ((2::complex) * p² - (8::complex) * r) * m - q² = (0::complex)› 2. ‹⟦poly [:- (q::complex)², (2::complex) * (p::complex)² - (8::complex) * (r::complex), (8::complex) * p, 8::complex:] (m::complex) = (0::complex); q ≠ (0::complex)⟧ ⟹ m ≠ (0::complex)› discuss goal 1*) apply ((auto simp: powers (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 72 facts*))[1]) (*discuss goal 2*) apply ((auto simp: powers (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 72 facts*))[1]) (*proven 2 subgoals*) . define b1 where "b1 = p / 2 + m - q / (2 * csqrt (2 * m))" define b2 where "b2 = p / 2 + m + q / (2 * csqrt (2 * m))" have csqrt: "csqrt x * csqrt x = x" for x by (metis power2_csqrt (*‹(csqrt ?z)² = ?z›*) power2_eq_square (*‹?a² = ?a * ?a›*)) show "?thesis" (*goal: ‹(x ∈ set (solve_depressed_quartic_complex p q r)) = (x ^ 4 + p * x² + q * x + r = 0)›*) unfolding solve_depressed_quartic_complex_def id Let_def set_remdups set_append hd (*goal: ‹(x ∈ set (croots2 [:p / 2 + m - q / (2 * csqrt (2 * m)), csqrt (2 * m), 1:]) ∪ set (croots2 [:p / 2 + m + q / (2 * csqrt (2 * m)), - csqrt (2 * m), 1:])) = (x ^ 4 + p * x² + q * x + r = 0)›*) unfolding b1_def[symmetric] b2_def[symmetric] (*goal: ‹(x ∈ set (croots2 [:b1, csqrt (2 * m), 1:]) ∪ set (croots2 [:b2, - csqrt (2 * m), 1:])) = (x ^ 4 + p * x² + q * x + r = 0)›*) apply (subst depressed_quartic_Ferrari[OF mrt q0 csqrt b1_def b2_def] (*‹((?y::complex) ^ (4::nat) + (p::complex) * ?y² + (q::complex) * ?y + (r::complex) = (0::complex)) = (poly [:b1::complex, csqrt ((2::complex) * (m::complex)), 1::complex:] ?y = (0::complex) ∨ poly [:b2::complex, - csqrt ((2::complex) * m), 1::complex:] ?y = (0::complex))›*)) (*goal: ‹(x ∈ set (croots2 [:b1, csqrt (2 * m), 1:]) ∪ set (croots2 [:b2, - csqrt (2 * m), 1:])) = (x ^ 4 + p * x² + q * x + r = 0)›*) apply (subst (1 2) croots2[symmetric] (*‹degree ?p = 2 ⟹ set (croots2 ?p) = {x. poly ?p x = 0}›*)) (*goals: 1. ‹degree [:b2, - csqrt (2 * m), 1:] = 2› 2. ‹degree [:b1, csqrt (2 * m), 1:] = 2› 3. ‹(x ∈ {x. poly [:b1, csqrt (2 * m), 1:] x = 0} ∪ {x. poly [:b2, - csqrt (2 * m), 1:] x = 0}) = (poly [:b1, csqrt (2 * m), 1:] x = 0 ∨ poly [:b2, - csqrt (2 * m), 1:] x = 0)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . qed qed text ‹The main difference in the real case is that a specific cubic root has to be used, namely a positive one. In the soundness proof we show that such a cubic root always exists.› definition solve_depressed_quartic_real :: "real ⇒ real ⇒ real ⇒ real list" where "solve_depressed_quartic_real p q r = remdups (if q = 0 then (concat (map (λ z. rroots2 [:-z,0,1:]) (rroots2 [:r,p,1:]))) else let cubics = rroots3 [: - (q^2), 2 * p^2 - 8 * r, 8 * p, 8:]; m = the (find (λ m. m > 0) cubics); ― ‹select any positive root of the cubic polynomial› a = sqrt (2 * m); p2m = p / 2 + m; q2a = q / (2 * a); b1 = p2m - q2a; b2 = p2m + q2a in (rroots2 [:b1,a,1:] @ rroots2 [:b2,-a,1:]))" lemma solve_depressed_quartic_real: "x ∈ set (solve_depressed_quartic_real p q r) ⟷ (x^4 + p * x^2 + q * x + r = 0)" proof (-) (*goal: ‹((x::real) ∈ set (solve_depressed_quartic_real (p::real) (q::real) (r::real))) = (x ^ (4::nat) + p * x² + q * x + r = (0::real))›*) note powers = field_simps (*‹(?a::?'a::semigroup_add) + (?b::?'a::semigroup_add) + (?c::?'a::semigroup_add) = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹(?a::?'a::ab_semigroup_mult) * (?b::?'a::ab_semigroup_mult) = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹(?a::?'a) - (?b::?'a) - (?c::?'a) = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹((?a::?'a) - (?b::?'a) = (?c::?'a)) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 69 facts*) power4_eq_xxxx (*‹?x ^ 4 = ?x * ?x * ?x * ?x›*) power3_eq_cube (*‹?a ^ 3 = ?a * ?a * ?a›*) power2_eq_square (*‹?a² = ?a * ?a›*) show "?thesis" (*goal: ‹(x ∈ set (solve_depressed_quartic_real p q r)) = (x ^ 4 + p * x² + q * x + r = 0)›*) proof (cases "q = 0") (*goals: 1. ‹q = 0 ⟹ (x ∈ set (solve_depressed_quartic_real p q r)) = (x ^ 4 + p * x² + q * x + r = 0)› 2. ‹q ≠ 0 ⟹ (x ∈ set (solve_depressed_quartic_real p q r)) = (x ^ 4 + p * x² + q * x + r = 0)›*) case True (*‹q = 0›*) have sqrt: "z = x^2 ⟷ (x ∈ set (rroots2 [:-z,0,1:]))" for z apply (subst rroots2[symmetric] (*‹degree ?p = 2 ⟹ set (rroots2 ?p) = {x. poly ?p x = 0}›*)) (*goals: 1. ‹degree [:- z, 0, 1:] = 2› 2. ‹(z = x²) = (x ∈ {x. poly [:- z, 0, 1:] x = 0})› discuss goal 1*) apply ((auto simp: powers (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 72 facts*))[1]) (*discuss goal 2*) apply ((auto simp: powers (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 72 facts*))[1]) (*proven 2 subgoals*) . have "(x ^ 4 + p * x² + q * x + r = 0) ⟷ (x ^ 4 + p * x² + r = 0)" unfolding True (*goal: ‹(x ^ 4 + p * x² + 0 * x + r = 0) = (x ^ 4 + p * x² + r = 0)›*) by simp also (*calculation: ‹(x ^ 4 + p * x² + q * x + r = 0) = (x ^ 4 + p * x² + r = 0)›*) have "… ⟷ (∃z. z² + p * z + r = 0 ∧ z = x²)" unfolding biquadratic_solution (*goal: ‹(∃z. z² + p * z + r = 0 ∧ z = x²) = (∃z. z² + p * z + r = 0 ∧ z = x²)›*) by simp also (*calculation: ‹(x ^ 4 + p * x² + q * x + r = 0) = (∃z. z² + p * z + r = 0 ∧ z = x²)›*) have "… ⟷ (∃ z. poly [:r,p,1:] z = 0 ∧ z = x^2)" by (simp add: powers (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 72 facts*)) also (*calculation: ‹(x ^ 4 + p * x² + q * x + r = 0) = (∃z. poly [:r, p, 1:] z = 0 ∧ z = x²)›*) have "… ⟷ (∃ z ∈ set (rroots2 [:r,p,1:]). z = x^2)" apply (subst rroots2[symmetric] (*‹degree ?p = 2 ⟹ set (rroots2 ?p) = {x. poly ?p x = 0}›*)) (*goals: 1. ‹degree [:r, p, 1:] = 2› 2. ‹(∃z. poly [:r, p, 1:] z = 0 ∧ z = x²) = (∃z∈{x. poly [:r, p, 1:] x = 0}. z = x²)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . also (*calculation: ‹(x ^ 4 + p * x² + q * x + r = 0) = (∃z∈set (rroots2 [:r, p, 1:]). z = x²)›*) have "… ⟷ (∃ z ∈ set (rroots2 [:r,p,1:]). x ∈ set (rroots2 [:-z,0,1:]))" unfolding sqrt (*goal: ‹(∃z::real∈set (rroots2 [:r::real, p::real, 1::real:]). (x::real) ∈ set (rroots2 [:- z, 0::real, 1::real:])) = (∃z::real∈set (rroots2 [:r, p, 1::real:]). x ∈ set (rroots2 [:- z, 0::real, 1::real:]))›*) by standard also (*calculation: ‹(x ^ 4 + p * x² + q * x + r = 0) = (∃z∈set (rroots2 [:r, p, 1:]). x ∈ set (rroots2 [:- z, 0, 1:]))›*) have "… ⟷ (x ∈ set (solve_depressed_quartic_real p q r))" unfolding solve_depressed_quartic_real_def id (*goal: ‹(∃z∈set (rroots2 [:r, p, 1:]). x ∈ set (rroots2 [:- z, 0, 1:])) = (x ∈ set (remdups (if q = 0 then concat (map (λz. rroots2 [:- z, 0, 1:]) (rroots2 [:r, p, 1:])) else let cubics = rroots3 [:- q², 2 * p² - 8 * r, 8 * p, 8:]; m = the (find ((<) 0) cubics); a = sqrt (2 * m); p2m = p / 2 + m; q2a = q / (2 * a); b1 = p2m - q2a; b2 = p2m + q2a in rroots2 [:b1, a, 1:] @ rroots2 [:b2, - a, 1:])))›*) unfolding True Let_def (*goal: ‹(∃z::real∈set (rroots2 [:r::real, p::real, 1::real:]). (x::real) ∈ set (rroots2 [:- z, 0::real, 1::real:])) = (x ∈ set (remdups (if (0::real) = (0::real) then concat (map (λz::real. rroots2 [:- z, 0::real, 1::real:]) (rroots2 [:r, p, 1::real:])) else rroots2 [:p / (2::real) + the (find ((<) (0::real)) (rroots3 [:- (0::real)², (2::real) * p² - (8::real) * r, (8::real) * p, 8::real:])) - (0::real) / ((2::real) * sqrt ((2::real) * the (find ((<) (0::real)) (rroots3 [:- (0::real)², (2::real) * p² - (8::real) * r, (8::real) * p, 8::real:])))), sqrt ((2::real) * the (find ((<) (0::real)) (rroots3 [:- (0::real)², (2::real) * p² - (8::real) * r, (8::real) * p, 8::real:]))), 1::real:] @ rroots2 [:p / (2::real) + the (find ((<) (0::real)) (rroots3 [:- (0::real)², (2::real) * p² - (8::real) * r, (8::real) * p, 8::real:])) + (0::real) / ((2::real) * sqrt ((2::real) * the (find ((<) (0::real)) (rroots3 [:- (0::real)², (2::real) * p² - (8::real) * r, (8::real) * p, 8::real:])))), - sqrt ((2::real) * the (find ((<) (0::real)) (rroots3 [:- (0::real)², (2::real) * p² - (8::real) * r, (8::real) * p, 8::real:]))), 1::real:])))›*) by auto finally (*calculation: ‹((x::real) ^ (4::nat) + (p::real) * x² + (q::real) * x + (r::real) = (0::real)) = (x ∈ set (solve_depressed_quartic_real p q r))›*) show "?thesis" (*goal: ‹(x ∈ set (solve_depressed_quartic_real p q r)) = (x ^ 4 + p * x² + q * x + r = 0)›*) apply - (*goal: ‹(x ∈ set (solve_depressed_quartic_real p q r)) = (x ^ 4 + p * x² + q * x + r = 0)›*) apply standard (*goals: 1. ‹⟦((x::real) ^ (4::nat) + (p::real) * x² + (q::real) * x + (r::real) = (0::real)) = (x ∈ set (solve_depressed_quartic_real p q r)); x ∈ set (solve_depressed_quartic_real p q r)⟧ ⟹ x ^ (4::nat) + p * x² + q * x + r = (0::real)› 2. ‹⟦((x::real) ^ (4::nat) + (p::real) * x² + (q::real) * x + (r::real) = (0::real)) = (x ∈ set (solve_depressed_quartic_real p q r)); x ^ (4::nat) + p * x² + q * x + r = (0::real)⟧ ⟹ x ∈ set (solve_depressed_quartic_real p q r)› discuss goal 1*) apply ((msorry)[1]) (*discuss goal 2*) apply ((msorry)[1]) (*proven 2 subgoals*) . next (*goal: ‹q ≠ 0 ⟹ (x ∈ set (solve_depressed_quartic_real p q r)) = (x ^ 4 + p * x² + q * x + r = 0)›*) case q0: False (*‹(q::real) ≠ (0::real)›*) hence id: "(if q = 0 then x else y) = y" for x :: "real list" and y :: "real list" by auto note powers = field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹(?a::?'a) - (?b::?'a) - (?c::?'a) = ?a - (?b + ?c)› ‹(?a::?'a) + ((?b::?'a) - (?c::?'a)) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 69 facts*) power4_eq_xxxx (*‹?x ^ 4 = ?x * ?x * ?x * ?x›*) power3_eq_cube (*‹?a ^ 3 = ?a * ?a * ?a›*) power2_eq_square (*‹(?a::?'a::monoid_mult)² = ?a * ?a›*) let ?poly = "[:- q², 2 * p² - 8 * r, 8 * p, 8:]" define cubics where "cubics = rroots3 ?poly" from rroots3[of ?poly, folded cubics_def] (*‹degree [:- q², 2 * p² - 8 * r, 8 * p, 8:] = 3 ⟹ set cubics = {x. poly [:- q², 2 * p² - 8 * r, 8 * p, 8:] x = 0}›*) have rroots: "set cubics = {x. poly ?poly x = 0}" by auto from odd_degree_imp_real_root[of ?poly] (*‹odd (degree [:- (q::real)², (2::real) * (p::real)² - (8::real) * (r::real), (8::real) * p, 8::real:]) ⟹ ∃x::real. poly [:- q², (2::real) * p² - (8::real) * r, (8::real) * p, 8::real:] x = (0::real)›*) have "{x. poly ?poly x = 0} ≠ {}" by auto with rroots (*‹set (cubics::real list) = {x::real. poly [:- (q::real)², (2::real) * (p::real)² - (8::real) * (r::real), (8::real) * p, 8::real:] x = (0::real)}›*) have "cubics ≠ []" by auto have "∃ m. m ∈ set cubics ∧ m > 0" proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹∄m::real. m ∈ set (cubics::real list) ∧ (0::real) < m ⟹ False›*) assume "¬ ?thesis" (*‹∄m::real. m ∈ set (cubics::real list) ∧ (0::real) < m›*) from this[unfolded rroots] (*‹∄m::real. m ∈ {x::real. poly [:- (q::real)², (2::real) * (p::real)² - (8::real) * (r::real), (8::real) * p, 8::real:] x = (0::real)} ∧ (0::real) < m›*) have rt: "poly ?poly m = 0 ⟹ m ≤ 0" for m by auto have "poly ?poly 0 = - (q^2)" by simp also (*calculation: ‹poly [:- q², 2 * p² - 8 * r, 8 * p, 8:] 0 = - q²›*) have "… < 0" using q0 (*‹q ≠ 0›*) by auto finally (*calculation: ‹poly [:- q², 2 * p² - 8 * r, 8 * p, 8:] 0 < 0›*) have lt: "poly ?poly 0 ≤ 0" by simp from poly_pinfty_gt_lc[of ?poly] (*‹0 < lead_coeff [:- q², 2 * p² - 8 * r, 8 * p, 8:] ⟹ ∃n. ∀x≥n. lead_coeff [:- q², 2 * p² - 8 * r, 8 * p, 8:] ≤ poly [:- q², 2 * p² - 8 * r, 8 * p, 8:] x›*) obtain n0 where "⋀ n. n ≥ n0 ⟹ 8 ≤ poly ?poly n" (*goal: ‹(⋀n0. (⋀n. n0 ≤ n ⟹ 8 ≤ poly [:- q², 2 * p² - 8 * r, 8 * p, 8:] n) ⟹ thesis) ⟹ thesis›*) by auto from this[of "max n0 0"] (*‹n0 ≤ max n0 0 ⟹ 8 ≤ poly [:- q², 2 * p² - 8 * r, 8 * p, 8:] (max n0 0)›*) have "poly ?poly (max n0 0) ≥ 0" by auto from IVT[of "poly ?poly", OF lt this] (*‹⟦(0::real) ≤ max (n0::real) (0::real); ∀x::real. (0::real) ≤ x ∧ x ≤ max n0 (0::real) ⟶ isCont (poly [:- (q::real)², (2::real) * (p::real)² - (8::real) * (r::real), (8::real) * p, 8::real:]) x⟧ ⟹ ∃x≥0::real. x ≤ max n0 (0::real) ∧ poly [:- q², (2::real) * p² - (8::real) * r, (8::real) * p, 8::real:] x = (0::real)›*) obtain m where "m ≥ 0" and poly: "poly ?poly m = 0" (*goal: ‹(⋀m. ⟦0 ≤ m; poly [:- q², 2 * p² - 8 * r, 8 * p, 8:] m = 0⟧ ⟹ thesis) ⟹ thesis›*) by auto from rt[OF this ( 2 )] (*‹m ≤ 0›*) this(1) (*‹0 ≤ m›*) have "m = 0" by auto thus False using poly (*‹poly [:- q², 2 * p² - 8 * r, 8 * p, 8:] m = 0›*) q0 (*‹(q::real) ≠ (0::real)›*) by simp qed hence "find (λ m. m > 0) cubics ≠ None" unfolding find_None_iff (*goal: ‹¬ (∄x. x ∈ set cubics ∧ 0 < x)›*) by auto then obtain m where find: "find (λ m. m > 0) cubics = Some m" (*goal: ‹(⋀m. find ((<) 0) cubics = Some m ⟹ thesis) ⟹ thesis›*) by auto from find_Some_D[OF this] (*‹(m::real) ∈ set (cubics::real list) ∧ (0::real) < m›*) have m: "m ∈ set cubics" and m_0: "m > 0" apply - (*goals: 1. ‹(m::real) ∈ set (cubics::real list) ∧ (0::real) < m ⟹ m ∈ set cubics› 2. ‹(m::real) ∈ set (cubics::real list) ∧ (0::real) < m ⟹ (0::real) < m› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . with rroots (*‹set cubics = {x. poly [:- q², 2 * p² - 8 * r, 8 * p, 8:] x = 0}›*) have "poly ?poly m = 0" by auto hence mrt: "8*m^3 + (8 * p) * m^2 + (2 * p^2 - 8 * r) * m - q^2 = 0" by (auto simp: powers (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)› ‹(?a::?'a) * (?b::?'a) * (?c::?'a) = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)› ‹(?a::?'a) - (?b::?'a) - (?c::?'a) = ?a - (?b + ?c)› ‹(?a::?'a) + ((?b::?'a) - (?c::?'a)) = ?a + ?b - ?c› ‹((?a::?'a) - (?b::?'a) = (?c::?'a)) = (?a = ?c + ?b)› ‹((?a::?'a) = (?c::?'a) - (?b::?'a)) = (?a + ?b = ?c)› ‹(?a::?'a) - ((?b::?'a) - (?c::?'a)) = ?a + ?c - ?b› ‹(?a::?'a) - (?b::?'a) + (?c::?'a) = ?a + ?c - ?b› and more 72 facts*)) from m_0 (*‹0 < m›*) have sqrt: "sqrt (2 * m) * sqrt (2 * m) = 2 * m" by simp define b1 where "b1 = p / 2 + m - q / (2 * sqrt (2 * m))" define b2 where "b2 = p / 2 + m + q / (2 * sqrt (2 * m))" show "?thesis" (*goal: ‹(x ∈ set (solve_depressed_quartic_real p q r)) = (x ^ 4 + p * x² + q * x + r = 0)›*) unfolding solve_depressed_quartic_real_def id Let_def set_remdups set_append cubics_def[symmetric] find option.sel (*goal: ‹((x::real) ∈ set (rroots2 [:(p::real) / (2::real) + (m::real) - (q::real) / ((2::real) * sqrt ((2::real) * m)), sqrt ((2::real) * m), 1::real:]) ∪ set (rroots2 [:p / (2::real) + m + q / ((2::real) * sqrt ((2::real) * m)), - sqrt ((2::real) * m), 1::real:])) = (x ^ (4::nat) + p * x² + q * x + (r::real) = (0::real))›*) unfolding b1_def[symmetric] b2_def[symmetric] (*goal: ‹(x ∈ set (rroots2 [:b1, sqrt (2 * m), 1:]) ∪ set (rroots2 [:b2, - sqrt (2 * m), 1:])) = (x ^ 4 + p * x² + q * x + r = 0)›*) apply (subst depressed_quartic_Ferrari[OF mrt q0 sqrt b1_def b2_def] (*‹(?y ^ 4 + p * ?y² + q * ?y + r = 0) = (poly [:b1, sqrt (2 * m), 1:] ?y = 0 ∨ poly [:b2, - sqrt (2 * m), 1:] ?y = 0)›*)) (*goal: ‹(x ∈ set (rroots2 [:b1, sqrt (2 * m), 1:]) ∪ set (rroots2 [:b2, - sqrt (2 * m), 1:])) = (x ^ 4 + p * x² + q * x + r = 0)›*) apply (subst (1 2) rroots2[symmetric] (*‹degree ?p = 2 ⟹ set (rroots2 ?p) = {x. poly ?p x = 0}›*)) (*goals: 1. ‹degree [:b2::real, - sqrt ((2::real) * (m::real)), 1::real:] = (2::nat)› 2. ‹degree [:b1::real, sqrt ((2::real) * (m::real)), 1::real:] = (2::nat)› 3. ‹((x::real) ∈ {x::real. poly [:b1::real, sqrt ((2::real) * (m::real)), 1::real:] x = (0::real)} ∪ {x::real. poly [:b2::real, - sqrt ((2::real) * m), 1::real:] x = (0::real)}) = (poly [:b1, sqrt ((2::real) * m), 1::real:] x = (0::real) ∨ poly [:b2, - sqrt ((2::real) * m), 1::real:] x = (0::real))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . qed qed text ‹Combining the various algorithms› lemma numeral_4_eq_4: "4 = Suc (Suc (Suc (Suc 0)))" by (simp add: eval_nat_numeral (*‹Numeral1 = Suc (0::nat)› ‹numeral (num.Bit0 (?n::num)) = Suc (numeral (Num.BitM ?n))› ‹numeral (num.Bit1 (?n::num)) = Suc (numeral (num.Bit0 ?n))›*)) lemma degree4_coeffs: "degree p = 4 ⟹ ∃ a b c d e. p = [: e, d, c, b, a :] ∧ a ≠ 0" using degree3_coeffs (*‹degree ?p = 3 ⟹ ∃a b c d. ?p = [:d, c, b, a:] ∧ a ≠ 0›*) degree_pCons_eq_if (*‹degree (pCons ?a ?p) = (if ?p = 0 then 0 else Suc (degree ?p))›*) nat.inject (*‹(Suc ?x2.0 = Suc ?y2.0) = (?x2.0 = ?y2.0)›*) numeral_3_eq_3 (*‹3 = Suc (Suc (Suc 0))›*) numeral_4_eq_4 (*‹4 = Suc (Suc (Suc (Suc 0)))›*) pCons_cases (*‹(⋀a q. ?p = pCons a q ⟹ ?thesis) ⟹ ?thesis›*) zero_neq_numeral (*‹0 ≠ numeral ?n›*) by metis definition roots4_generic :: "('a :: field_char_0 ⇒ 'a ⇒ 'a ⇒ 'a list) ⇒ 'a poly ⇒ 'a list" where "roots4_generic depressed_solver p = (let cs = coeffs p; cs = coeffs p; a4 = cs ! 4; a3 = cs ! 3; a2 = cs ! 2; a1 = cs ! 1; a0 = cs ! 0; b = a3 / a4; c = a2 / a4; d = a1 / a4; e = a0 / a4; b2 = b * b; b3 = b2 * b; b4 = b3 * b; b4' = b / 4; p = c - 3/8 * b2; q = (b3 - 4*b*c + 8 * d) / 8; r = ( -3 * b4 + 256 * e - 64 * b * d + 16 * b2 * c) / 256; roots = depressed_solver p q r in map (λ y. y - b4') roots)" lemma roots4_generic: assumes deg: "degree p = 4" and solver: "⋀ p q r y. y ∈ set (depressed_solver p q r) ⟷ y^4 + p * y^2 + q * y + r = 0" shows "set (roots4_generic depressed_solver p) = {x. poly p x = 0}" proof (-) (*goal: ‹set (roots4_generic depressed_solver p) = {x. poly p x = 0}›*) note powers = field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹(?a::?'a) + ((?b::?'a) - (?c::?'a)) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹((?a::?'a::group_add) = (?c::?'a::group_add) - (?b::?'a::group_add)) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 69 facts*) power4_eq_xxxx (*‹?x ^ 4 = ?x * ?x * ?x * ?x›*) power3_eq_cube (*‹?a ^ 3 = ?a * ?a * ?a›*) power2_eq_square (*‹?a² = ?a * ?a›*) from degree4_coeffs[OF deg] (*‹∃(a::'a) (b::'a) (c::'a) (d::'a) e::'a. (p::'a poly) = [:e, d, c, b, a:] ∧ a ≠ (0::'a)›*) obtain a4 and a3 and a2 and a1 and a0 where p: "p = [:a0,a1,a2,a3,a4:]" and a4: "a4 ≠ 0" (*goal: ‹(⋀(a0::'a) (a1::'a) (a2::'a) (a3::'a) a4::'a. ⟦(p::'a poly) = [:a0, a1, a2, a3, a4:]; a4 ≠ (0::'a)⟧ ⟹ thesis::bool) ⟹ thesis›*) by auto have coeffs: "coeffs p ! 4 = a4" "coeffs p ! 3 = a3" "coeffs p ! 2 = a2" "coeffs p ! 1 = a1" "coeffs p ! 0 = a0" unfolding p (*goals: 1. ‹coeffs [:a0, a1, a2, a3, a4:] ! 4 = a4› 2. ‹coeffs [:a0, a1, a2, a3, a4:] ! 3 = a3› 3. ‹coeffs [:a0, a1, a2, a3, a4:] ! 2 = a2› 4. ‹coeffs [:a0, a1, a2, a3, a4:] ! 1 = a1› 5. ‹coeffs [:a0, a1, a2, a3, a4:] ! 0 = a0›*) using a4 (*‹a4 ≠ 0›*) apply - (*goals: 1. ‹a4 ≠ 0 ⟹ coeffs [:a0, a1, a2, a3, a4:] ! 4 = a4› 2. ‹a4 ≠ 0 ⟹ coeffs [:a0, a1, a2, a3, a4:] ! 3 = a3› 3. ‹a4 ≠ 0 ⟹ coeffs [:a0, a1, a2, a3, a4:] ! 2 = a2› 4. ‹a4 ≠ 0 ⟹ coeffs [:a0, a1, a2, a3, a4:] ! 1 = a1› 5. ‹a4 ≠ 0 ⟹ coeffs [:a0, a1, a2, a3, a4:] ! 0 = a0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . define b where "b = a3 / a4" define c where "c = a2 / a4" define d where "d = a1 / a4" define e where "e = a0 / a4" note def = roots4_generic_def[of depressed_solver p, unfolded Let_def coeffs, folded b_def c_def d_def e_def, folded power4_eq_xxxx, folded power3_eq_cube, folded power2_eq_square] (*‹roots4_generic depressed_solver p = map (λy. y - b / 4) (depressed_solver (c - 3 / 8 * b²) ((b ^ 3 - 4 * b * c + 8 * d) / 8) ((- 3 * b ^ 4 + 256 * e - 64 * b * d + 16 * b² * c) / 256))›*) let ?p = p { fix x define y where "y = x + b / 4" define p where "p = c - (3/8) * b^2" define q where "q = (b^3 - 4*b*c + 8 * d) / 8" define r where "r = ( -3 * b^4 + 256 * e - 64 * b * d + 16 * b^2 * c) / 256" note def = def[folded p_def q_def r_def] (*‹roots4_generic (depressed_solver::'a ⇒ 'a ⇒ 'a ⇒ 'a list) (p::'a poly) = map (λy::'a. y - (b::'a) / (4::'a)) (depressed_solver (p::'a) (q::'a) (r::'a))›*) have xy: "x = y - b / 4" unfolding y_def (*goal: ‹x = x + b / 4 - b / 4›*) by auto have "poly ?p x = 0 ⟷ a4 * x^4 + a3 * x^3 + a2 * x^2 + a1 * x + a0 = 0" unfolding p (*goal: ‹(poly [:a0, a1, a2, a3, a4:] x = 0) = (a4 * x ^ 4 + a3 * x ^ 3 + a2 * x² + a1 * x + a0 = 0)›*) by (simp add: powers (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 72 facts*)) also (*calculation: ‹(poly p x = 0) = (a4 * x ^ 4 + a3 * x ^ 3 + a2 * x² + a1 * x + a0 = 0)›*) have "… ⟷ (y ^ 4 + p * y² + q * y + r = 0)" unfolding to_depressed_quartic[OF a4 b_def c_def d_def e_def p_def q_def r_def xy] (*goal: ‹(y ^ 4 + p * y² + q * y + r = 0) = (y ^ 4 + p * y² + q * y + r = 0)›*) by standard also (*calculation: ‹(poly p x = 0) = (y ^ 4 + p * y² + q * y + r = 0)›*) have "… ⟷ y ∈ set (depressed_solver p q r)" unfolding solver (*goal: ‹((y::'a::field_char_0) ^ (4::nat) + (p::'a::field_char_0) * y² + (q::'a::field_char_0) * y + (r::'a::field_char_0) = (0::'a::field_char_0)) = (y ^ (4::nat) + p * y² + q * y + r = (0::'a::field_char_0))›*) by standard also (*calculation: ‹(poly p x = 0) = (y ∈ set (depressed_solver p q r))›*) have "… ⟷ x ∈ set (roots4_generic depressed_solver ?p)" unfolding xy def (*goal: ‹(y ∈ set (depressed_solver p q r)) = (y - b / 4 ∈ set (map (λy. y - b / 4) (depressed_solver p q r)))›*) by auto finally (*calculation: ‹(poly p x = 0) = (x ∈ set (roots4_generic depressed_solver p))›*) have "poly ?p x = 0 ⟷ x ∈ set (roots4_generic depressed_solver ?p)" by auto } thus "?thesis" (*goal: ‹set (roots4_generic depressed_solver p) = {x. poly p x = 0}›*) by simp qed definition croots4 :: "complex poly ⇒ complex list" where "croots4 = roots4_generic solve_depressed_quartic_complex" lemma croots4: assumes deg: "degree p = 4" shows "set (croots4 p) = { x. poly p x = 0}" unfolding croots4_def (*goal: ‹set (roots4_generic solve_depressed_quartic_complex (p::complex poly)) = {x::complex. poly p x = (0::complex)}›*) by (rule roots4_generic[OF deg solve_depressed_quartic_complex] (*‹set (roots4_generic solve_depressed_quartic_complex p) = {x. poly p x = 0}›*)) definition rroots4 :: "real poly ⇒ real list" where "rroots4 = roots4_generic solve_depressed_quartic_real" lemma rroots4: assumes deg: "degree p = 4" shows "set (rroots4 p) = { x. poly p x = 0}" unfolding rroots4_def (*goal: ‹set (roots4_generic solve_depressed_quartic_real p) = {x. poly p x = 0}›*) by (rule roots4_generic[OF deg solve_depressed_quartic_real] (*‹set (roots4_generic solve_depressed_quartic_real p) = {x. poly p x = 0}›*)) end
{ "path": "afp-2025-02-12/thys/Cubic_Quartic_Equations/Quartic_Polynomials.thy", "repo": "afp-2025-02-12", "sha": "547fa83bef46f1f1e74ebcce7710ed44536b58f3548b4c6a82add1c4beeb4359" }
theory SM_Datastructures imports Main CAVA_Base.CAVA_Base "../Lib/SOS_Misc_Add" DFS_Framework.Feedback_Arcs (* TODO: Only for oo-symbol !?*) begin lemma [code_unfold]: "{(a,b). (a,b)∈X ∧ P a b} = Set.filter (λ(a,b). P a b) X" by auto lemma in_dom_map_code[code_unfold]: "x∈dom m = (case m x of None ⇒ False | _ ⇒ True)" by (auto split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*)) (* TODO: Move to gen_set. Generic algorithm for set_of_list *) lemma set_by_fold: "set l = fold insert l {}" proof (-) (*goal: ‹set l = fold insert l {}›*) { fix s have "fold insert l s = s ∪ set l" apply (induction l arbitrary: s) (*goals: 1. ‹⋀s. fold insert [] s = s ∪ set []› 2. ‹⋀a l s. (⋀s. fold insert l s = s ∪ set l) ⟹ fold insert (a # l) s = s ∪ set (a # l)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . } from this[of "{}"] (*‹fold insert (l::'a list) {} = {} ∪ set l›*) show "?thesis" (*goal: ‹set l = fold insert l {}›*) by simp qed context begin interpretation autoref_syn . lemma [autoref_itype]: "set ::⇩i ⟨I⟩⇩ii_list →⇩i ⟨I⟩⇩ii_set" by simp end lemma gen_set[autoref_rules_raw]: fixes R :: "('c×'a)set" and Rs :: "('c×'a) set ⇒ (_×'a set) set" assumes [simplified,param]: "GEN_OP em {} (⟨R⟩Rs)" "GEN_OP ins insert (R → ⟨R⟩Rs → ⟨R⟩Rs)" shows "(λli. fold ins li em,set)∈⟨R⟩list_rel → ⟨R⟩Rs" unfolding set_by_fold[abs_def] (*goal: ‹(λli::'c list. fold (ins::'c ⇒ 'd ⇒ 'd) li (em::'d), λl::'a list. fold insert l {}) ∈ ⟨R::('c × 'a) set⟩list_rel → ⟨R⟩(Rs::('c × 'a) set ⇒ ('d × 'a set) set)›*) by parametricity schematic_goal shows "(?c,set [1,2,3::nat])∈⟨nat_rel⟩dflt_ahs_rel" using [autoref_trace_failed_id] (*‹TERM _›*) by (autoref (trace, keep_goal)) (* TODO: Possibly, we can drop the find_min_idx_f - stuff, and formalize our ample-set using the abstract LEAST, which is then implemented by collecti_index. *) text ‹Find minimum index and result where function returns non-none value› primrec find_min_idx_f :: "('a ⇀ 'b) ⇒ 'a list ⇀ (nat × 'b)" where "find_min_idx_f f [] = None" | "find_min_idx_f f (x#xs) = ( case f x of Some r ⇒ Some (0,r) | None ⇒ map_option (map_prod Suc id) (find_min_idx_f f xs) )" lemma find_min_idx_f_None_conv: "find_min_idx_f f l = None ⟷ (∀a∈set l. f a = None)" apply (induction l) (*goals: 1. ‹(find_min_idx_f f [] = None) = (∀a∈set []. f a = None)› 2. ‹⋀a l. (find_min_idx_f f l = None) = (∀a∈set l. f a = None) ⟹ (find_min_idx_f f (a # l) = None) = (∀a∈set (a # l). f a = None)› discuss goal 1*) apply ((auto split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*))[1]) (*discuss goal 2*) apply ((auto split: option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*))[1]) (*proven 2 subgoals*) . lemma find_min_idx_f_SomeD: "find_min_idx_f f l = Some (i,r) ⟹ f (l!i) = Some r ∧ i < length l" apply (induction l arbitrary: i) (*goals: 1. ‹⋀i. find_min_idx_f f [] = Some (i, r) ⟹ f ([] ! i) = Some r ∧ i < length []› 2. ‹⋀a l i. ⟦⋀i. find_min_idx_f f l = Some (i, r) ⟹ f (l ! i) = Some r ∧ i < length l; find_min_idx_f f (a # l) = Some (i, r)⟧ ⟹ f ((a # l) ! i) = Some r ∧ i < length (a # l)› discuss goal 1*) apply ((auto split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*))[1]) (*discuss goal 2*) apply ((auto split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*))[1]) (*proven 2 subgoals*) . lemma find_min_idx_f_SomeD_complete: "find_min_idx_f f l = Some (i,r) ⟹ (f (l!i) = Some r ∧ i < length l ∧ (∀j<i. f (l!j) = None))" apply (induction l arbitrary: i) (*goals: 1. ‹⋀i::nat. find_min_idx_f (f::'b::type ⇒ 'a::type option) [] = Some (i, r::'a::type) ⟹ f ([] ! i) = Some r ∧ i < length [] ∧ (∀j<i. f ([] ! j) = None)› 2. ‹⋀(a::'b::type) (l::'b::type list) i::nat. ⟦⋀i::nat. find_min_idx_f (f::'b::type ⇒ 'a::type option) l = Some (i, r::'a::type) ⟹ f (l ! i) = Some r ∧ i < length l ∧ (∀j<i. f (l ! j) = None); find_min_idx_f f (a # l) = Some (i, r)⟧ ⟹ f ((a # l) ! i) = Some r ∧ i < length (a # l) ∧ (∀j<i. f ((a # l) ! j) = None)› discuss goal 1*) apply ((auto split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*))[1]) (*discuss goal 2*) apply ((auto split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) option.splits (*‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = ((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) = (¬ (?option = None ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?option = Some x2 ∧ ¬ ?P (?f2.0 x2))))›*))[1]) (*goal: ‹⋀(a::'b::type) (l::'b::type list) i::nat. ⟦⋀i::nat. find_min_idx_f (f::'b::type ⇒ 'a::type option) l = Some (i, r::'a::type) ⟹ f (l ! i) = Some r ∧ i < length l ∧ (∀j<i. f (l ! j) = None); find_min_idx_f f (a # l) = Some (i, r)⟧ ⟹ f ((a # l) ! i) = Some r ∧ i < length (a # l) ∧ (∀j<i. f ((a # l) ! j) = None)›*) apply (case_tac j) (*goals: 1. ‹⋀a l aa j. ⟦f a = None; find_min_idx_f f l = Some (aa, r); j < Suc aa; f (l ! aa) = Some r; aa < length l; ∀j<aa. f (l ! j) = None; j = 0⟧ ⟹ f ((a # l) ! j) = None› 2. ‹⋀a l aa j nat. ⟦f a = None; find_min_idx_f f l = Some (aa, r); j < Suc aa; f (l ! aa) = Some r; aa < length l; ∀j<aa. f (l ! j) = None; j = Suc nat⟧ ⟹ f ((a # l) ! j) = None› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma find_min_idx_f_LEAST_eq: "find_min_idx_f f l = ( if ∃i<length l. f (l!i) ≠ None then let i = LEAST i. i<length l ∧ f (l!i) ≠ None in Some (i,the (f (l!i))) else None )" proof (cases "find_min_idx_f f l") (*goals: 1. ‹find_min_idx_f f l = None ⟹ find_min_idx_f f l = (if ∃i<length l. f (l ! i) ≠ None then let i = LEAST i. i < length l ∧ f (l ! i) ≠ None in Some (i, the (f (l ! i))) else None)› 2. ‹⋀a. find_min_idx_f f l = Some a ⟹ find_min_idx_f f l = (if ∃i<length l. f (l ! i) ≠ None then let i = LEAST i. i < length l ∧ f (l ! i) ≠ None in Some (i, the (f (l ! i))) else None)›*) case None (*‹find_min_idx_f f l = None›*) show "?thesis" (*goal: ‹find_min_idx_f f l = (if ∃i<length l. f (l ! i) ≠ None then let i = LEAST i. i < length l ∧ f (l ! i) ≠ None in Some (i, the (f (l ! i))) else None)›*) using None (*‹find_min_idx_f f l = None›*) by (auto simp: find_min_idx_f_None_conv (*‹(find_min_idx_f ?f ?l = None) = (∀a∈set ?l. ?f a = None)›*)) next (*goal: ‹⋀a. find_min_idx_f f l = Some a ⟹ find_min_idx_f f l = (if ∃i<length l. f (l ! i) ≠ None then let i = LEAST i. i < length l ∧ f (l ! i) ≠ None in Some (i, the (f (l ! i))) else None)›*) case (Some a) (*‹find_min_idx_f (f::'b ⇒ 'a option) (l::'b list) = Some (a::nat × 'a)›*) obtain i and r where 1: "a = (i, r)" (*goal: ‹(⋀(i::nat) r::'a. (a::nat × 'a) = (i, r) ⟹ thesis::bool) ⟹ thesis›*) by force have 2: "f (l ! i) = Some r" "i < length l" "∀ j < i. f (l ! j) = None" using find_min_idx_f_SomeD_complete[OF Some [ unfolded 1 ]] (*‹f (l ! i) = Some r ∧ i < length l ∧ (∀j<i. f (l ! j) = None)›*) apply - (*goals: 1. ‹f (l ! i) = Some r ∧ i < length l ∧ (∀j<i. f (l ! j) = None) ⟹ f (l ! i) = Some r› 2. ‹f (l ! i) = Some r ∧ i < length l ∧ (∀j<i. f (l ! j) = None) ⟹ i < length l› 3. ‹f (l ! i) = Some r ∧ i < length l ∧ (∀j<i. f (l ! j) = None) ⟹ ∀j<i. f (l ! j) = None› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . have 3: "(LEAST i. i < length l ∧ (∃ y. f (l ! i) = Some y)) = i" using "2" (*‹f (l ! i) = Some r› ‹(i::nat) < length (l::'b list)› ‹∀j<i. f (l ! j) = None›*) linorder_neqE_nat (*‹⟦?x ≠ ?y; ?x < ?y ⟹ ?R; ?y < ?x ⟹ ?R⟧ ⟹ ?R›*) by (force intro!: Least_equality (*‹⟦?P ?x; ⋀y. ?P y ⟹ ?x ≤ y⟧ ⟹ Least ?P = ?x›*)) show "?thesis" (*goal: ‹find_min_idx_f f l = (if ∃i<length l. f (l ! i) ≠ None then let i = LEAST i. i < length l ∧ f (l ! i) ≠ None in Some (i, the (f (l ! i))) else None)›*) unfolding Some "1" (*goal: ‹Some (i, r) = (if ∃i<length l. f (l ! i) ≠ None then let i = LEAST i. i < length l ∧ f (l ! i) ≠ None in Some (i, the (f (l ! i))) else None)›*) using "2" (*‹(f::'b ⇒ 'a option) ((l::'b list) ! (i::nat)) = Some (r::'a)› ‹i < length l› ‹∀j<i. f (l ! j) = None›*) "3" (*‹(LEAST i. i < length l ∧ (∃y. f (l ! i) = Some y)) = i›*) by auto qed primrec collect_indexr' :: "nat ⇒ (nat×'b) set ⇒ (nat ⇒ 'a ⇒ 'b set) ⇒ 'a list ⇒ (nat×'b) set" where "collect_indexr' i a c [] = a" | "collect_indexr' i a c (x#xs) = (collect_indexr' (Suc i) (a∪({i} × c i x)) c xs)" abbreviation "collect_indexr ≡ collect_indexr' 0 {}" lemma collect_indexr'_collect: "collect_indexr' i0 a f l = a ∪ {(i0+i,x) | i x. i<length l ∧ x∈f (i0+i) (l!i)}" apply (induction l arbitrary: i0 a) (*goals: 1. ‹⋀i0 a. collect_indexr' i0 a f [] = a ∪ {(i0 + i, x) |i x. i < length [] ∧ x ∈ f (i0 + i) ([] ! i)}› 2. ‹⋀a l i0 aa. (⋀i0 a. collect_indexr' i0 a f l = a ∪ {(i0 + i, x) |i x. i < length l ∧ x ∈ f (i0 + i) (l ! i)}) ⟹ collect_indexr' i0 aa f (a # l) = aa ∪ {(i0 + i, x) |i x. i < length (a # l) ∧ x ∈ f (i0 + i) ((a # l) ! i)}› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*goal: ‹⋀a l i0 aa. (⋀i0 a. collect_indexr' i0 a f l = a ∪ {(i0 + i, x) |i x. i < length l ∧ x ∈ f (i0 + i) (l ! i)}) ⟹ collect_indexr' i0 aa f (a # l) = aa ∪ {(i0 + i, x) |i x. i < length (a # l) ∧ x ∈ f (i0 + i) ((a # l) ! i)}›*) apply auto (*goals: 1. ‹⋀a l i0 aa i x. ⟦⋀i0 a. collect_indexr' i0 a f l = a ∪ {(i0 + i, x) |i x. i < length l ∧ x ∈ f (i0 + i) (l ! i)}; (i0 + i, x) ∉ aa; i < Suc (length l); x ∈ f (i0 + i) ((a # l) ! i); ∀ia<length l. i = Suc ia ⟶ x ∉ f (Suc (i0 + ia)) (l ! ia)⟧ ⟹ i = 0› 2. ‹⋀a l i0 aa i x. ⟦⋀i0 a. collect_indexr' i0 a f l = a ∪ {(i0 + i, x) |i x. i < length l ∧ x ∈ f (i0 + i) (l ! i)}; (i0 + i, x) ∉ aa; i < Suc (length l); x ∈ f (i0 + i) ((a # l) ! i); ∀ia<length l. i = Suc ia ⟶ x ∉ f (Suc (i0 + ia)) (l ! ia)⟧ ⟹ x ∈ f i0 a› discuss goal 1*) apply (case_tac i) (*goals: 1. ‹⋀a l i0 aa i x. ⟦⋀i0 a. collect_indexr' i0 a f l = a ∪ {(i0 + i, x) |i x. i < length l ∧ x ∈ f (i0 + i) (l ! i)}; (i0 + i, x) ∉ aa; i < Suc (length l); x ∈ f (i0 + i) ((a # l) ! i); ∀ia<length l. i = Suc ia ⟶ x ∉ f (Suc (i0 + ia)) (l ! ia); i = 0⟧ ⟹ i = 0› 2. ‹⋀a l i0 aa i x nat. ⟦⋀i0 a. collect_indexr' i0 a f l = a ∪ {(i0 + i, x) |i x. i < length l ∧ x ∈ f (i0 + i) (l ! i)}; (i0 + i, x) ∉ aa; i < Suc (length l); x ∈ f (i0 + i) ((a # l) ! i); ∀ia<length l. i = Suc ia ⟶ x ∉ f (Suc (i0 + ia)) (l ! ia); i = Suc nat⟧ ⟹ i = 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*discuss goal 2*) apply (case_tac i) (*goals: 1. ‹⋀a l i0 aa i x. ⟦⋀i0 a. collect_indexr' i0 a f l = a ∪ {(i0 + i, x) |i x. i < length l ∧ x ∈ f (i0 + i) (l ! i)}; (i0 + i, x) ∉ aa; i < Suc (length l); x ∈ f (i0 + i) ((a # l) ! i); ∀ia<length l. i = Suc ia ⟶ x ∉ f (Suc (i0 + ia)) (l ! ia); i = 0⟧ ⟹ x ∈ f i0 a› 2. ‹⋀a l i0 aa i x nat. ⟦⋀i0 a. collect_indexr' i0 a f l = a ∪ {(i0 + i, x) |i x. i < length l ∧ x ∈ f (i0 + i) (l ! i)}; (i0 + i, x) ∉ aa; i < Suc (length l); x ∈ f (i0 + i) ((a # l) ! i); ∀ia<length l. i = Suc ia ⟶ x ∉ f (Suc (i0 + ia)) (l ! ia); i = Suc nat⟧ ⟹ x ∈ f i0 a› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma collect_indexr_collect: "collect_indexr f l = {(i,x) | i x. i<length l ∧ x∈f i (l!i)}" by (simp add: collect_indexr'_collect (*‹collect_indexr' ?i0.0 ?a ?f ?l = ?a ∪ {(?i0.0 + i, x) |i x. i < length ?l ∧ x ∈ ?f (?i0.0 + i) (?l ! i)}›*)) primrec collecti_index' :: "nat ⇒ (nat×'b) set ⇒ (nat ⇒ 'a ⇒ (bool × 'b set)) ⇒ 'a list ⇒ (nat×'b) set" where "collecti_index' i a c [] = a" | "collecti_index' i a c (x#xs) = (case c i x of (False,s) ⇒ collecti_index' (Suc i) (a ∪ {i}×s) c xs | (True,s) ⇒ {i}×s)" abbreviation "collecti_index ≡ collecti_index' 0 {}" lemma collecti_index'_collect: "collecti_index' i0 a0 f l = ( if ∃i<length l. fst (f (i0+i) (l!i)) then let i=LEAST i . i<length l ∧ fst (f (i0+i) (l!i)) in {i0+i} × snd (f (i0+i) (l!i)) else a0 ∪ {(i0+i,x) | i x. i<length l ∧ x∈snd (f (i0+i) (l!i))})" proof (cases "∃i<length l. fst (f (i0+i) (l!i))") (*goals: 1. ‹∃i<length l. fst (f (i0 + i) (l ! i)) ⟹ collecti_index' i0 a0 f l = (if ∃i<length l. fst (f (i0 + i) (l ! i)) then let i = LEAST i. i < length l ∧ fst (f (i0 + i) (l ! i)) in {i0 + i} × snd (f (i0 + i) (l ! i)) else a0 ∪ {(i0 + i, x) |i x. i < length l ∧ x ∈ snd (f (i0 + i) (l ! i))})› 2. ‹¬ (∃i<length l. fst (f (i0 + i) (l ! i))) ⟹ collecti_index' i0 a0 f l = (if ∃i<length l. fst (f (i0 + i) (l ! i)) then let i = LEAST i. i < length l ∧ fst (f (i0 + i) (l ! i)) in {i0 + i} × snd (f (i0 + i) (l ! i)) else a0 ∪ {(i0 + i, x) |i x. i < length l ∧ x ∈ snd (f (i0 + i) (l ! i))})›*) case False (*‹¬ (∃i<length (l::'b::type list). fst ((f::nat ⇒ 'b::type ⇒ bool × 'a::type set) ((i0::nat) + i) (l ! i)))›*) note False[simp] (*‹¬ (∃i<length (l::'b list). fst ((f::nat ⇒ 'b ⇒ bool × 'a set) ((i0::nat) + i) (l ! i)))›*) hence "∀i<length l. ¬fst (f (i0+i) (l!i))" by blast hence "collecti_index' i0 a0 f l = collect_indexr' i0 a0 (snd oo f) l" proof (induction l arbitrary: i0 a0) (*goals: 1. ‹⋀i0 a0. ∀i<length []. ¬ fst (f (i0 + i) ([] ! i)) ⟹ collecti_index' i0 a0 f [] = collect_indexr' i0 a0 (snd ∘∘ f) []› 2. ‹⋀a l i0 a0. ⟦⋀i0 a0. ∀i<length l. ¬ fst (f (i0 + i) (l ! i)) ⟹ collecti_index' i0 a0 f l = collect_indexr' i0 a0 (snd ∘∘ f) l; ∀i<length (a # l). ¬ fst (f (i0 + i) ((a # l) ! i))⟧ ⟹ collecti_index' i0 a0 f (a # l) = collect_indexr' i0 a0 (snd ∘∘ f) (a # l)›*) case (Cons x l) (*‹∀i<length l. ¬ fst (f (?i0.0 + i) (l ! i)) ⟹ collecti_index' ?i0.0 ?a0.0 f l = collect_indexr' ?i0.0 ?a0.0 (snd ∘∘ f) l› ‹∀i<length (x # l). ¬ fst (f (i0 + i) ((x # l) ! i))›*) from Cons.prems (*‹∀i<length (x # l). ¬ fst (f (i0 + i) ((x # l) ! i))›*) have "¬fst (f i0 x)" by auto hence [simp]: "⋀v. f i0 x ≠ (True,v)" by auto have "collecti_index' i0 a0 f (x#l) = collecti_index' (Suc i0) (a0 ∪ {i0} × (snd (f i0 x))) f l" by (simp split: prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*) bool.splits (*‹?P (case ?bool of True ⇒ ?f1.0 | False ⇒ ?f2.0) = ((?bool = True ⟶ ?P ?f1.0) ∧ (?bool = False ⟶ ?P ?f2.0))› ‹?P (case ?bool of True ⇒ ?f1.0 | False ⇒ ?f2.0) = (¬ (?bool = True ∧ ¬ ?P ?f1.0 ∨ ?bool = False ∧ ¬ ?P ?f2.0))›*)) also (*calculation: ‹collecti_index' i0 a0 f (x # l) = collecti_index' (Suc i0) (a0 ∪ {i0} × snd (f i0 x)) f l›*) have "… = collect_indexr' (Suc i0) ((a0 ∪ {i0} × (snd (f i0 x)))) (snd oo f) l" apply (subst Cons.IH (*‹∀i<length (l::'b list). ¬ fst ((f::nat ⇒ 'b ⇒ bool × 'a set) ((?i0.0::nat) + i) (l ! i)) ⟹ collecti_index' ?i0.0 (?a0.0::(nat × 'a) set) f l = collect_indexr' ?i0.0 ?a0.0 (snd ∘∘ f) l›*)) (*goal: ‹collecti_index' (Suc (i0::nat)) ((a0::(nat × 'a) set) ∪ {i0} × snd ((f::nat ⇒ 'b ⇒ bool × 'a set) i0 (x::'b))) f (l::'b list) = collect_indexr' (Suc i0) (a0 ∪ {i0} × snd (f i0 x)) (snd ∘∘ f) l›*) using Cons.prems (*‹∀i<length (x # l). ¬ fst (f (i0 + i) ((x # l) ! i))›*) apply - (*goals: 1. ‹∀i<length ((x::'b::type) # (l::'b::type list)). ¬ fst ((f::nat ⇒ 'b::type ⇒ bool × 'a::type set) ((i0::nat) + i) ((x # l) ! i)) ⟹ ∀i<length l. ¬ fst (f (Suc i0 + i) (l ! i))› 2. ‹∀i<length ((x::'b::type) # (l::'b::type list)). ¬ fst ((f::nat ⇒ 'b::type ⇒ bool × 'a::type set) ((i0::nat) + i) ((x # l) ! i)) ⟹ collect_indexr' (Suc i0) ((a0::(nat × 'a::type) set) ∪ {i0} × snd (f i0 x)) (snd ∘∘ f) l = collect_indexr' (Suc i0) (a0 ∪ {i0} × snd (f i0 x)) (snd ∘∘ f) l› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . finally (*calculation: ‹collecti_index' i0 a0 f (x # l) = collect_indexr' (Suc i0) (a0 ∪ {i0} × snd (f i0 x)) (snd ∘∘ f) l›*) have 1: "collecti_index' i0 a0 f (x # l) = collect_indexr' (Suc i0) (a0 ∪ {i0} × snd (f i0 x)) (snd ∘∘ f) l" . show "?case" (*goal: ‹collecti_index' i0 a0 f (x # l) = collect_indexr' i0 a0 (snd ∘∘ f) (x # l)›*) apply (subst 1 (*‹collecti_index' i0 a0 f (x # l) = collect_indexr' (Suc i0) (a0 ∪ {i0} × snd (f i0 x)) (snd ∘∘ f) l›*)) (*goal: ‹collecti_index' (i0::nat) (a0::(nat × 'a::type) set) (f::nat ⇒ 'b::type ⇒ bool × 'a::type set) ((x::'b::type) # (l::'b::type list)) = collect_indexr' i0 a0 (snd ∘∘ f) (x # l)›*) by simp qed (simp) (*solved the remaining goal: ‹⋀(i0::nat) a0::(nat × 'a) set. ∀i<length []. ¬ fst ((f::nat ⇒ 'b ⇒ bool × 'a set) (i0 + i) ([] ! i)) ⟹ collecti_index' i0 a0 f [] = collect_indexr' i0 a0 (snd ∘∘ f) []›*) also (*calculation: ‹collecti_index' (i0::nat) (a0::(nat × 'a) set) (f::nat ⇒ 'b ⇒ bool × 'a set) (l::'b list) = collect_indexr' i0 a0 (snd ∘∘ f) l›*) note collect_indexr'_collect (*‹collect_indexr' ?i0.0 ?a ?f ?l = ?a ∪ {(?i0.0 + i, x) |i x. i < length ?l ∧ x ∈ ?f (?i0.0 + i) (?l ! i)}›*) finally (*calculation: ‹collecti_index' i0 a0 f l = a0 ∪ {(i0 + i, x) |i x. i < length l ∧ x ∈ (snd ∘∘ f) (i0 + i) (l ! i)}›*) show "?thesis" (*goal: ‹collecti_index' i0 a0 f l = (if ∃i<length l. fst (f (i0 + i) (l ! i)) then let i = LEAST i. i < length l ∧ fst (f (i0 + i) (l ! i)) in {i0 + i} × snd (f (i0 + i) (l ! i)) else a0 ∪ {(i0 + i, x) |i x. i < length l ∧ x ∈ snd (f (i0 + i) (l ! i))})›*) by simp next (*goal: ‹∃i<length l. fst (f (i0 + i) (l ! i)) ⟹ collecti_index' i0 a0 f l = (if ∃i<length l. fst (f (i0 + i) (l ! i)) then let i = LEAST i. i < length l ∧ fst (f (i0 + i) (l ! i)) in {i0 + i} × snd (f (i0 + i) (l ! i)) else a0 ∪ {(i0 + i, x) |i x. i < length l ∧ x ∈ snd (f (i0 + i) (l ! i))})›*) case True (*‹∃i<length l. fst (f (i0 + i) (l ! i))›*) note True[simp] (*‹∃i<length l. fst (f (i0 + i) (l ! i))›*) define im where "im ≡ λl (i0::nat). LEAST i . i<length l ∧ fst (f (i0+i) (l!i))" from LeastI_ex[OF True] (*‹(LEAST i. i < length l ∧ fst (f (i0 + i) (l ! i))) < length l ∧ fst (f (i0 + (LEAST i. i < length l ∧ fst (f (i0 + i) (l ! i)))) (l ! (LEAST i. i < length l ∧ fst (f (i0 + i) (l ! i)))))›*) have 1: "im l i0<length l" "fst (f (i0+im l i0) (l!im l i0))" unfolding im_def (*goals: 1. ‹(LEAST i. i < length l ∧ fst (f (i0 + i) (l ! i))) < length l› 2. ‹fst (f (i0 + (LEAST i. i < length l ∧ fst (f (i0 + i) (l ! i)))) (l ! (LEAST i. i < length l ∧ fst (f (i0 + i) (l ! i)))))›*) apply - (*goals: 1. ‹(LEAST i. i < length l ∧ fst (f (i0 + i) (l ! i))) < length l ∧ fst (f (i0 + (LEAST i. i < length l ∧ fst (f (i0 + i) (l ! i)))) (l ! (LEAST i. i < length l ∧ fst (f (i0 + i) (l ! i))))) ⟹ (LEAST i. i < length l ∧ fst (f (i0 + i) (l ! i))) < length l› 2. ‹(LEAST i. i < length l ∧ fst (f (i0 + i) (l ! i))) < length l ∧ fst (f (i0 + (LEAST i. i < length l ∧ fst (f (i0 + i) (l ! i)))) (l ! (LEAST i. i < length l ∧ fst (f (i0 + i) (l ! i))))) ⟹ fst (f (i0 + (LEAST i. i < length l ∧ fst (f (i0 + i) (l ! i)))) (l ! (LEAST i. i < length l ∧ fst (f (i0 + i) (l ! i)))))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have 2: "∀i<im l i0. ¬ fst (f (i0+i) (l!i))" proof (safe) (*goal: ‹⋀i. ⟦i < im l i0; fst (f (i0 + i) (l ! i))⟧ ⟹ False›*) fix i assume A: "i<im l i0" (*‹(i::nat) < (im::'b list ⇒ nat ⇒ nat) (l::'b list) (i0::nat)›*) with "1" (*‹im l i0 < length l› ‹fst (f (i0 + im l i0) (l ! im l i0))›*) have "i<length l" by simp moreover assume "fst (f (i0+i) (l!i))" (*‹fst ((f::nat ⇒ 'b ⇒ bool × 'a set) ((i0::nat) + (i::nat)) ((l::'b list) ! i))›*) ultimately have "im l i0 ≤ i" unfolding im_def (*goal: ‹(LEAST i. i < length l ∧ fst (f (i0 + i) (l ! i))) ≤ i›*) by (auto intro: Least_le (*‹?P ?k ⟹ (LEAST x. ?P x) ≤ ?k›*)) with A (*‹i < im l i0›*) show False by simp qed from "1" (*‹im l i0 < length l› ‹fst (f (i0 + im l i0) (l ! im l i0))›*) "2" (*‹∀i<im l i0. ¬ fst (f (i0 + i) (l ! i))›*) have "collecti_index' i0 a0 f l = {i0+im l i0} × snd (f (i0+im l i0) (l!im l i0))" proof (induction l arbitrary: i0 a0) (*goals: 1. ‹⋀i0 a0. ⟦im [] i0 < length []; fst (f (i0 + im [] i0) ([] ! im [] i0)); ∀i<im [] i0. ¬ fst (f (i0 + i) ([] ! i))⟧ ⟹ collecti_index' i0 a0 f [] = {i0 + im [] i0} × snd (f (i0 + im [] i0) ([] ! im [] i0))› 2. ‹⋀a l i0 a0. ⟦⋀i0 a0. ⟦im l i0 < length l; fst (f (i0 + im l i0) (l ! im l i0)); ∀i<im l i0. ¬ fst (f (i0 + i) (l ! i))⟧ ⟹ collecti_index' i0 a0 f l = {i0 + im l i0} × snd (f (i0 + im l i0) (l ! im l i0)); im (a # l) i0 < length (a # l); fst (f (i0 + im (a # l) i0) ((a # l) ! im (a # l) i0)); ∀i<im (a # l) i0. ¬ fst (f (i0 + i) ((a # l) ! i))⟧ ⟹ collecti_index' i0 a0 f (a # l) = {i0 + im (a # l) i0} × snd (f (i0 + im (a # l) i0) ((a # l) ! im (a # l) i0))›*) case (Cons x l) (*‹⟦im l ?i0.0 < length l; fst (f (?i0.0 + im l ?i0.0) (l ! im l ?i0.0)); ∀i<im l ?i0.0. ¬ fst (f (?i0.0 + i) (l ! i))⟧ ⟹ collecti_index' ?i0.0 ?a0.0 f l = {?i0.0 + im l ?i0.0} × snd (f (?i0.0 + im l ?i0.0) (l ! im l ?i0.0))› ‹(im::'b list ⇒ nat ⇒ nat) ((x::'b) # (l::'b list)) (i0::nat) < length (x # l)› ‹fst (f (i0 + im (x # l) i0) ((x # l) ! im (x # l) i0))› ‹∀i<im (x # l) i0. ¬ fst (f (i0 + i) ((x # l) ! i))›*) show "?case" (*goal: ‹collecti_index' i0 a0 f (x # l) = {i0 + im (x # l) i0} × snd (f (i0 + im (x # l) i0) ((x # l) ! im (x # l) i0))›*) proof (cases "fst (f i0 x)") (*goals: 1. ‹fst (f i0 x) ⟹ collecti_index' i0 a0 f (x # l) = {i0 + im (x # l) i0} × snd (f (i0 + im (x # l) i0) ((x # l) ! im (x # l) i0))› 2. ‹¬ fst (f i0 x) ⟹ collecti_index' i0 a0 f (x # l) = {i0 + im (x # l) i0} × snd (f (i0 + im (x # l) i0) ((x # l) ! im (x # l) i0))›*) case True (*‹fst (f i0 x)›*) hence [simp]: "⋀y. f i0 x ≠ (False,y)" by auto note [simp] = True (*‹fst (f i0 x)›*) from Cons.prems(3) (*‹∀i<im (x # l) i0. ¬ fst (f (i0 + i) ((x # l) ! i))›*) have [simp]: "im (x#l) i0 = 0" by auto thus "?thesis" (*goal: ‹collecti_index' i0 a0 f (x # l) = {i0 + im (x # l) i0} × snd (f (i0 + im (x # l) i0) ((x # l) ! im (x # l) i0))›*) by (auto split: prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*) bool.splits (*‹?P (case ?bool of True ⇒ ?f1.0 | False ⇒ ?f2.0) = ((?bool = True ⟶ ?P ?f1.0) ∧ (?bool = False ⟶ ?P ?f2.0))› ‹?P (case ?bool of True ⇒ ?f1.0 | False ⇒ ?f2.0) = (¬ (?bool = True ∧ ¬ ?P ?f1.0 ∨ ?bool = False ∧ ¬ ?P ?f2.0))›*)) next (*goal: ‹¬ fst (f i0 x) ⟹ collecti_index' i0 a0 f (x # l) = {i0 + im (x # l) i0} × snd (f (i0 + im (x # l) i0) ((x # l) ! im (x # l) i0))›*) case False (*‹¬ fst (f i0 x)›*) hence "im (x#l) i0 = Suc (im l (Suc i0))" unfolding im_def (*goal: ‹(LEAST i. i < length (x # l) ∧ fst (f (i0 + i) ((x # l) ! i))) = Suc (LEAST i. i < length l ∧ fst (f (Suc i0 + i) (l ! i)))›*) apply (subst Least_Suc (*‹⟦?P ?n; ¬ ?P 0⟧ ⟹ (LEAST n. ?P n) = Suc (LEAST m. ?P (Suc m))›*)) (*goals: 1. ‹¬ fst (f i0 x) ⟹ ?n1 < length (x # l) ∧ fst (f (i0 + ?n1) ((x # l) ! ?n1))› 2. ‹¬ fst (f i0 x) ⟹ ¬ (0 < length (x # l) ∧ fst (f (i0 + 0) ((x # l) ! 0)))› 3. ‹¬ fst (f i0 x) ⟹ Suc (LEAST m. Suc m < length (x # l) ∧ fst (f (i0 + Suc m) ((x # l) ! Suc m))) = Suc (LEAST i. i < length l ∧ fst (f (Suc i0 + i) (l ! i)))› discuss goal 1*) apply (rule conjI (*‹⟦?P::bool; ?Q::bool⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹¬ fst ((f::nat ⇒ 'b ⇒ bool × 'a set) (i0::nat) (x::'b)) ⟹ (?n1::nat) < length (x # (l::'b list))› 2. ‹¬ fst ((f::nat ⇒ 'b ⇒ bool × 'a set) (i0::nat) (x::'b)) ⟹ fst (f (i0 + (?n1::nat)) ((x # (l::'b list)) ! ?n1))› discuss goal 1*) apply (rule Cons.prems (*‹im (x # l) i0 < length (x # l)› ‹fst (f (i0 + im (x # l) i0) ((x # l) ! im (x # l) i0))› ‹∀i<im (x # l) i0. ¬ fst (f (i0 + i) ((x # l) ! i))›*)) (*discuss goal 2*) apply (rule Cons.prems (*‹im (x # l) i0 < length (x # l)› ‹fst (f (i0 + im (x # l) i0) ((x # l) ! im (x # l) i0))› ‹∀i<im (x # l) i0. ¬ fst (f (i0 + i) ((x # l) ! i))›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*proven 3 subgoals*) . hence ims: "im (x#l) i0 > 0" "im l (Suc i0) = im (x#l) i0 - 1" apply - (*goals: 1. ‹im (x # l) i0 = Suc (im l (Suc i0)) ⟹ 0 < im (x # l) i0› 2. ‹im (x # l) i0 = Suc (im l (Suc i0)) ⟹ im l (Suc i0) = im (x # l) i0 - 1› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . from False (*‹¬ fst (f i0 x)›*) have 1: "collecti_index' i0 a0 f (x # l) = collecti_index' (Suc i0) (a0 ∪ {i0} × (snd (f i0 x))) f l" by auto show "?thesis" (*goal: ‹collecti_index' i0 a0 f (x # l) = {i0 + im (x # l) i0} × snd (f (i0 + im (x # l) i0) ((x # l) ! im (x # l) i0))›*) apply (subst 1 (*‹collecti_index' i0 a0 f (x # l) = collecti_index' (Suc i0) (a0 ∪ {i0} × snd (f i0 x)) f l›*)) (*goal: ‹collecti_index' (i0::nat) (a0::(nat × 'a::type) set) (f::nat ⇒ 'b::type ⇒ bool × 'a::type set) ((x::'b::type) # (l::'b::type list)) = {i0 + (im::'b::type list ⇒ nat ⇒ nat) (x # l) i0} × snd (f (i0 + im (x # l) i0) ((x # l) ! im (x # l) i0))›*) apply (subst Cons.IH (*‹⟦im l ?i0.0 < length l; fst (f (?i0.0 + im l ?i0.0) (l ! im l ?i0.0)); ∀i<im l ?i0.0. ¬ fst (f (?i0.0 + i) (l ! i))⟧ ⟹ collecti_index' ?i0.0 ?a0.0 f l = {?i0.0 + im l ?i0.0} × snd (f (?i0.0 + im l ?i0.0) (l ! im l ?i0.0))›*)) (*goal: ‹collecti_index' (Suc i0) (a0 ∪ {i0} × snd (f i0 x)) f l = {i0 + im (x # l) i0} × snd (f (i0 + im (x # l) i0) ((x # l) ! im (x # l) i0))›*) using Cons.prems(1) (*‹im (x # l) i0 < length (x # l)›*) ims (*‹0 < im (x # l) i0› ‹(im::'b::type list ⇒ nat ⇒ nat) (l::'b::type list) (Suc (i0::nat)) = im ((x::'b::type) # l) i0 - (1::nat)›*) apply simp (*top goal: ‹im l (Suc i0) < length l› and 3 goals remain*) using Cons.prems(2) (*‹fst (f (i0 + im (x # l) i0) ((x # l) ! im (x # l) i0))›*) ims (*‹0 < im (x # l) i0› ‹im l (Suc i0) = im (x # l) i0 - 1›*) apply simp (*top goal: ‹fst (f (Suc i0 + im l (Suc i0)) (l ! im l (Suc i0)))› and 2 goals remain*) using Cons.prems(3) (*‹∀i<(im::'b list ⇒ nat ⇒ nat) ((x::'b) # (l::'b list)) (i0::nat). ¬ fst ((f::nat ⇒ 'b ⇒ bool × 'a set) (i0 + i) ((x # l) ! i))›*) apply ((auto simp: ims (*‹0 < im (x # l) i0› ‹im l (Suc i0) = im (x # l) i0 - 1›*) nth_Cons (*‹(?x # ?xs) ! ?n = (case ?n of 0 ⇒ ?x | Suc k ⇒ ?xs ! k)›*) less_diff_conv (*‹(?i < ?j - ?k) = (?i + ?k < ?j)›*) split: nat.splits (*‹?P (case ?nat of 0 ⇒ ?f1.0 | Suc x ⇒ ?f2.0 x) = ((?nat = 0 ⟶ ?P ?f1.0) ∧ (∀x2. ?nat = Suc x2 ⟶ ?P (?f2.0 x2)))› ‹?P (case ?nat of 0 ⇒ ?f1.0 | Suc x ⇒ ?f2.0 x) = (¬ (?nat = 0 ∧ ¬ ?P ?f1.0 ∨ (∃x2. ?nat = Suc x2 ∧ ¬ ?P (?f2.0 x2))))›*))[1]) (*top goal: ‹∀i<im l (Suc i0). ¬ fst (f (Suc i0 + i) (l ! i))› and 1 goal remains*) using ims(1) (*‹0 < im (x # l) i0›*) by (auto simp: ims( (*‹im l (Suc i0) = im (x # l) i0 - 1›*) 2)) qed qed (simp) (*solved the remaining goal: ‹⋀(i0::nat) a0::(nat × 'a::type) set. ⟦(im::'b::type list ⇒ nat ⇒ nat) [] i0 < length []; fst ((f::nat ⇒ 'b::type ⇒ bool × 'a::type set) (i0 + im [] i0) ([] ! im [] i0)); ∀i<im [] i0. ¬ fst (f (i0 + i) ([] ! i))⟧ ⟹ collecti_index' i0 a0 f [] = {i0 + im [] i0} × snd (f (i0 + im [] i0) ([] ! im [] i0))›*) thus "?thesis" (*goal: ‹collecti_index' i0 a0 f l = (if ∃i<length l. fst (f (i0 + i) (l ! i)) then let i = LEAST i. i < length l ∧ fst (f (i0 + i) (l ! i)) in {i0 + i} × snd (f (i0 + i) (l ! i)) else a0 ∪ {(i0 + i, x) |i x. i < length l ∧ x ∈ snd (f (i0 + i) (l ! i))})›*) by (simp add: im_def (*‹im ≡ λl i0. LEAST i. i < length l ∧ fst (f (i0 + i) (l ! i))›*)) qed lemma collecti_index_collect: "collecti_index f l = ( if ∃i<length l. fst (f i (l!i)) then let i=LEAST i . i<length l ∧ fst (f i (l!i)) in {i} × snd (f i (l!i)) else {(i,x) | i x. i<length l ∧ x∈snd (f i (l!i))})" using collecti_index'_collect[of 0 "{}" f l] (*‹collecti_index f l = (if ∃i<length l. fst (f (0 + i) (l ! i)) then let i = LEAST i. i < length l ∧ fst (f (0 + i) (l ! i)) in {0 + i} × snd (f (0 + i) (l ! i)) else {} ∪ {(0 + i, x) |i x. i < length l ∧ x ∈ snd (f (0 + i) (l ! i))})›*) by (simp cong: if_cong (*‹⟦?b = ?c; ?c ⟹ ?x = ?u; ¬ ?c ⟹ ?y = ?v⟧ ⟹ (if ?b then ?x else ?y) = (if ?c then ?u else ?v)›*)) primrec collecti_index'_list :: "nat ⇒ (nat×'b) list ⇒ (nat ⇒ 'a ⇒ (bool × 'b list)) ⇒ 'a list ⇒ (nat×'b) list" where "collecti_index'_list i a c [] = a" | "collecti_index'_list i a c (x#xs) = (case c i x of (False,s) ⇒ collecti_index'_list (Suc i) (a @ map (Pair i) s) c xs | (True,s) ⇒ map (Pair i) s)" abbreviation "collecti_index_list ≡ collecti_index'_list 0 []" lemma collecti_index'_list_invar: assumes "⋀i x b l. c i x = (b,l) ⟹ distinct l" assumes "fst`set a ⊆ {0..<i0}" "distinct a" shows "distinct (collecti_index'_list i0 a c l)" using assms (*‹c ?i ?x = (?b, ?l) ⟹ distinct ?l› ‹fst ` set (a::(nat × 'b) list) ⊆ {0::nat..<i0::nat}› ‹distinct (a::(nat × 'b) list)›*) apply (induction l arbitrary: i0 a) (*goals: 1. ‹⋀(i0::nat) a::(nat × 'b) list. ⟦⋀(i::nat) (x::'a) (b::bool) l::'b list. (c::nat ⇒ 'a ⇒ bool × 'b list) i x = (b, l) ⟹ distinct l; fst ` set a ⊆ {0::nat..<i0}; distinct a⟧ ⟹ distinct (collecti_index'_list i0 a c [])› 2. ‹⋀(a::'a) (l::'a list) (i0::nat) aa::(nat × 'b) list. ⟦⋀(i0::nat) a::(nat × 'b) list. ⟦⋀(i::nat) (x::'a) (b::bool) l::'b list. (c::nat ⇒ 'a ⇒ bool × 'b list) i x = (b, l) ⟹ distinct l; fst ` set a ⊆ {0::nat..<i0}; distinct a⟧ ⟹ distinct (collecti_index'_list i0 a c l); ⋀(i::nat) (x::'a) (b::bool) l::'b list. c i x = (b, l) ⟹ distinct l; fst ` set aa ⊆ {0::nat..<i0}; distinct aa⟧ ⟹ distinct (collecti_index'_list i0 aa c (a # l))› discuss goal 1*) apply simp (*discuss goal 2*) apply (auto split: prod.splits (*‹(?P::?'c ⇒ bool) (case ?prod::?'a × ?'b of (x::?'a, xa::?'b) ⇒ (?f::?'a ⇒ ?'b ⇒ ?'c) x xa) = (∀(x1::?'a) x2::?'b. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹(?P::?'c ⇒ bool) (case ?prod::?'a × ?'b of (x::?'a, xa::?'b) ⇒ (?f::?'a ⇒ ?'b ⇒ ?'c) x xa) = (∄(x1::?'a) x2::?'b. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*) bool.splits (*‹(?P::?'a ⇒ bool) (case ?bool::bool of True ⇒ ?f1.0::?'a | False ⇒ ?f2.0::?'a) = ((?bool = True ⟶ ?P ?f1.0) ∧ (?bool = False ⟶ ?P ?f2.0))› ‹(?P::?'a ⇒ bool) (case ?bool::bool of True ⇒ ?f1.0::?'a | False ⇒ ?f2.0::?'a) = (¬ (?bool = True ∧ ¬ ?P ?f1.0 ∨ ?bool = False ∧ ¬ ?P ?f2.0))›*) simp: nth_Cons' (*‹((?x::?'a) # (?xs::?'a list)) ! (?n::nat) = (if ?n = (0::nat) then ?x else ?xs ! (?n - (1::nat)))›*) distinct_map (*‹distinct (map (?f::?'b ⇒ ?'a) (?xs::?'b list)) = (distinct ?xs ∧ inj_on ?f (set ?xs))›*)) (*goal: ‹⋀a l i0 aa. ⟦⋀i0 a. ⟦⋀i x b l. c i x = (b, l) ⟹ distinct l; fst ` set a ⊆ {0..<i0}; distinct a⟧ ⟹ distinct (collecti_index'_list i0 a c l); ⋀i x b l. c i x = (b, l) ⟹ distinct l; fst ` set aa ⊆ {0..<i0}; distinct aa⟧ ⟹ distinct (collecti_index'_list i0 aa c (a # l))›*) apply rprems (*goals: 1. ‹⋀a l i0 aa x1 x2. ⟦⋀i x b l. c i x = (b, l) ⟹ distinct l; fst ` set aa ⊆ {0..<i0}; distinct aa; ¬ x1; c i0 a = (False, x2)⟧ ⟹ fst ` set (aa @ map (Pair i0) x2) ⊆ {0..<Suc i0}› 2. ‹⋀a l i0 aa x1 x2. ⟦⋀i x b l. c i x = (b, l) ⟹ distinct l; fst ` set aa ⊆ {0..<i0}; distinct aa; ¬ x1; c i0 a = (False, x2)⟧ ⟹ distinct (aa @ map (Pair i0) x2)› discuss goal 1*) apply ((auto simp: distinct_map (*‹distinct (map ?f ?xs) = (distinct ?xs ∧ inj_on ?f (set ?xs))›*))[1]) (*discuss goal 2*) apply ((auto simp: distinct_map (*‹distinct (map (?f::?'b ⇒ ?'a) (?xs::?'b list)) = (distinct ?xs ∧ inj_on ?f (set ?xs))›*))[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) . lemma image_Pair_eq_prod_sng[simp]: "Pair x ` s = {x}×s" by auto lemma collecti_index'_list_α: assumes "⋀i x b l. ci i x = (b,l) ⟹ c i x = (b,set l)" shows "set (collecti_index'_list i0 ai ci l) = collecti_index' i0 (set ai) c l" proof (-) (*goal: ‹set (collecti_index'_list i0 ai ci l) = collecti_index' i0 (set ai) c l›*) from assms (*‹ci ?i ?x = (?b, ?l) ⟹ c ?i ?x = (?b, set ?l)›*) have A: "⋀i x b s. c i x = (b,s) ⟷ (∃l. ci i x = (b, l) ∧ s=set l)" apply auto (*goal: ‹⋀i x b s. (c i x = (b, s)) = (∃l. ci i x = (b, l) ∧ s = set l)›*) apply (case_tac "ci i x") (*goal: ‹⋀i x b s. ⟦⋀i x b l. ci i x = (b, l) ⟹ c i x = (b, set l); c i x = (b, s)⟧ ⟹ ∃l. ci i x = (b, l) ∧ s = set l›*) by auto show "?thesis" (*goal: ‹set (collecti_index'_list i0 ai ci l) = collecti_index' i0 (set ai) c l›*) apply (induction l arbitrary: i0 ai) (*goals: 1. ‹⋀i0 ai. set (collecti_index'_list i0 ai ci []) = collecti_index' i0 (set ai) c []› 2. ‹⋀a l i0 ai. (⋀i0 ai. set (collecti_index'_list i0 ai ci l) = collecti_index' i0 (set ai) c l) ⟹ set (collecti_index'_list i0 ai ci (a # l)) = collecti_index' i0 (set ai) c (a # l)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*goal: ‹⋀a l i0 ai. (⋀i0 ai. set (collecti_index'_list i0 ai ci l) = collecti_index' i0 (set ai) c l) ⟹ set (collecti_index'_list i0 ai ci (a # l)) = collecti_index' i0 (set ai) c (a # l)›*) apply (split prod.split) (*goal: ‹⋀a l i0 ai. (⋀i0 ai. set (collecti_index'_list i0 ai ci l) = collecti_index' i0 (set ai) c l) ⟹ {x. ∃uu_ uua_. (uua_, uu_) = ci i0 a ∧ x ∈ set (case uua_ of True ⇒ map (Pair i0) uu_ | False ⇒ collecti_index'_list (Suc i0) (ai @ map (Pair i0) uu_) ci l)} = (case c i0 a of (True, s) ⇒ {i0} × s | (False, s) ⇒ collecti_index' (Suc i0) (set ai ∪ {i0} × s) c l)›*) apply clarsimp (*goal: ‹⋀a l i0 ai. (⋀i0 ai. set (collecti_index'_list i0 ai ci l) = collecti_index' i0 (set ai) c l) ⟹ ∀x1 x2. c i0 a = (x1, x2) ⟶ {x. ∃uu_ uua_. (uua_, uu_) = ci i0 a ∧ x ∈ set (case uua_ of True ⇒ map (Pair i0) uu_ | False ⇒ collecti_index'_list (Suc i0) (ai @ map (Pair i0) uu_) ci l)} = (case x1 of True ⇒ {i0} × x2 | False ⇒ collecti_index' (Suc i0) (set ai ∪ {i0} × x2) c l)›*) apply (split bool.split) (*goal: ‹⋀a l i0 ai x1 x2. ⟦⋀i0 ai. set (collecti_index'_list i0 ai ci l) = collecti_index' i0 (set ai) c l; c i0 a = (x1, x2)⟧ ⟹ {x. ∃uu_ uua_. (uua_, uu_) = ci i0 a ∧ x ∈ set (case uua_ of True ⇒ map (Pair i0) uu_ | False ⇒ collecti_index'_list (Suc i0) (ai @ map (Pair i0) uu_) ci l)} = (case x1 of True ⇒ {i0} × x2 | False ⇒ collecti_index' (Suc i0) (set ai ∪ {i0} × x2) c l)›*) apply clarsimp (*goal: ‹⋀a l i0 ai x1 x2. ⟦⋀i0 ai. set (collecti_index'_list i0 ai ci l) = collecti_index' i0 (set ai) c l; c i0 a = (x1, x2)⟧ ⟹ (x1 = True ⟶ {x. ∃uu_ uua_. (uua_, uu_) = ci i0 a ∧ x ∈ set (case uua_ of True ⇒ map (Pair i0) uu_ | False ⇒ collecti_index'_list (Suc i0) (ai @ map (Pair i0) uu_) ci l)} = {i0} × x2) ∧ (x1 = False ⟶ {x. ∃uu_ uua_. (uua_, uu_) = ci i0 a ∧ x ∈ set (case uua_ of True ⇒ map (Pair i0) uu_ | False ⇒ collecti_index'_list (Suc i0) (ai @ map (Pair i0) uu_) ci l)} = collecti_index' (Suc i0) (set ai ∪ {i0} × x2) c l)›*) apply (intro allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*) impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*) conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹⋀a l i0 ai x1 x2. ⟦⋀i0 ai. set (collecti_index'_list i0 ai ci l) = collecti_index' i0 (set ai) c l; c i0 a = (x1, x2); x1⟧ ⟹ {x. ∃uu_ uua_. (uua_, uu_) = ci i0 a ∧ x ∈ set (case uua_ of True ⇒ map (Pair i0) uu_ | False ⇒ collecti_index'_list (Suc i0) (ai @ map (Pair i0) uu_) ci l)} = {i0} × x2› 2. ‹⋀a l i0 ai x1 x2. ⟦⋀i0 ai. set (collecti_index'_list i0 ai ci l) = collecti_index' i0 (set ai) c l; c i0 a = (x1, x2); ¬ x1⟧ ⟹ {x. ∃uu_ uua_. (uua_, uu_) = ci i0 a ∧ x ∈ set (case uua_ of True ⇒ map (Pair i0) uu_ | False ⇒ collecti_index'_list (Suc i0) (ai @ map (Pair i0) uu_) ci l)} = collecti_index' (Suc i0) (set ai ∪ {i0} × x2) c l› discuss goal 1*) apply (force simp add: A (*‹(c ?i ?x = (?b, ?s)) = (∃l. ci ?i ?x = (?b, l) ∧ ?s = set l)›*)) (*discuss goal 2*) apply (simp split: prod.splits (*‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∀x1 x2. ?prod = (x1, x2) ⟶ ?P (?f x1 x2))› ‹?P (case ?prod of (x, xa) ⇒ ?f x xa) = (∄x1 x2. ?prod = (x1, x2) ∧ ¬ ?P (?f x1 x2))›*) bool.splits (*‹?P (case ?bool of True ⇒ ?f1.0 | False ⇒ ?f2.0) = ((?bool = True ⟶ ?P ?f1.0) ∧ (?bool = False ⟶ ?P ?f2.0))› ‹?P (case ?bool of True ⇒ ?f1.0 | False ⇒ ?f2.0) = (¬ (?bool = True ∧ ¬ ?P ?f1.0 ∨ ?bool = False ∧ ¬ ?P ?f2.0))›*) add: A (*‹(c ?i ?x = (?b, ?s)) = (∃l. ci ?i ?x = (?b, l) ∧ ?s = set l)›*)) (*goal: ‹⋀a l i0 ai x1 x2. ⟦⋀i0 ai. set (collecti_index'_list i0 ai ci l) = collecti_index' i0 (set ai) c l; c i0 a = (x1, x2); ¬ x1⟧ ⟹ {x. ∃uu_ uua_. (uua_, uu_) = ci i0 a ∧ x ∈ set (case uua_ of True ⇒ map (Pair i0) uu_ | False ⇒ collecti_index'_list (Suc i0) (ai @ map (Pair i0) uu_) ci l)} = collecti_index' (Suc i0) (set ai ∪ {i0} × x2) c l›*) apply safe (*goals: 1. ‹⋀(a::'a) (l::'a list) (i0::nat) (ai::(nat × 'b) list) (x1::bool) (x2::'b set) (la::'b list) (aa::nat) (b::'b) (uu_::'b list) uua_::bool. ⟦⋀(i0::nat) ai::(nat × 'b) list. set (collecti_index'_list i0 ai (ci::nat ⇒ 'a ⇒ bool × 'b list) l) = collecti_index' i0 (set ai) (c::nat ⇒ 'a ⇒ bool × 'b set) l; ¬ x1; ci i0 a = (False, la); ¬ uua_; (False, uu_) = ci i0 a; (aa, b) ∈ collecti_index' (Suc i0) (set ai ∪ {i0} × set uu_) c l⟧ ⟹ (aa, b) ∈ collecti_index' (Suc i0) (set ai ∪ {i0} × set la) c l› 2. ‹⋀(a::'a) (l::'a list) (i0::nat) (ai::(nat × 'b) list) (x1::bool) (x2::'b set) (la::'b list) (aa::nat) (b::'b) (uu_::'b list) uua_::bool. ⟦⋀(i0::nat) ai::(nat × 'b) list. set (collecti_index'_list i0 ai (ci::nat ⇒ 'a ⇒ bool × 'b list) l) = collecti_index' i0 (set ai) (c::nat ⇒ 'a ⇒ bool × 'b set) l; ¬ x1; ci i0 a = (False, la); (True, uu_) = ci i0 a; b ∈ set uu_; (i0, b) ∉ collecti_index' (Suc i0) (set ai ∪ {i0} × set la) c l; uua_⟧ ⟹ False› 3. ‹⋀(a::'a) (l::'a list) (i0::nat) (ai::(nat × 'b) list) (x1::bool) (x2::'b set) (la::'b list) (aa::nat) (b::'b) (uu_::'b list) _::bool. ⟦⋀(i0::nat) ai::(nat × 'b) list. set (collecti_index'_list i0 ai (ci::nat ⇒ 'a ⇒ bool × 'b list) l) = collecti_index' i0 (set ai) (c::nat ⇒ 'a ⇒ bool × 'b set) l; ¬ x1; ci i0 a = (False, la); (True, uu_) = ci i0 a; b ∈ set uu_; (False, uu_) = ci i0 a; (i0, b) ∈ collecti_index' (Suc i0) (set ai ∪ {i0} × set uu_) c l⟧ ⟹ (i0, b) ∈ collecti_index' (Suc i0) (set ai ∪ {i0} × set la) c l› 4. ‹⋀(a::'a) (l::'a list) (i0::nat) (ai::(nat × 'b) list) (x1::bool) (x2::'b set) (la::'b list) (aa::nat) b::'b. ⟦⋀(i0::nat) ai::(nat × 'b) list. set (collecti_index'_list i0 ai (ci::nat ⇒ 'a ⇒ bool × 'b list) l) = collecti_index' i0 (set ai) (c::nat ⇒ 'a ⇒ bool × 'b set) l; ¬ x1; ci i0 a = (False, la); (aa, b) ∈ collecti_index' (Suc i0) (set ai ∪ {i0} × set la) c l⟧ ⟹ ∃(uu_::'b list) uua_::bool. (uua_ ⟶ (True, uu_) = ci i0 a ∧ (aa, b) ∈ {i0} × set uu_) ∧ (¬ uua_ ⟶ (False, uu_) = ci i0 a ∧ (aa, b) ∈ collecti_index' (Suc i0) (set ai ∪ {i0} × set uu_) c l)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*discuss goal 3*) apply simp (*discuss goal 4*) apply simp (*goal: ‹⋀a l i0 ai x1 x2 la aa b. ⟦⋀i0 ai. set (collecti_index'_list i0 ai ci l) = collecti_index' i0 (set ai) c l; ¬ x1; ci i0 a = (False, la); (aa, b) ∈ collecti_index' (Suc i0) (set ai ∪ {i0} × set la) c l⟧ ⟹ ∃uu_ uua_. (uua_ ⟶ (True, uu_) = ci i0 a ∧ (aa, b) ∈ {i0} × set uu_) ∧ (¬ uua_ ⟶ (False, uu_) = ci i0 a ∧ (aa, b) ∈ collecti_index' (Suc i0) (set ai ∪ {i0} × set uu_) c l)›*) apply blast (*proven 4 subgoals*) (*proven 2 subgoals*) (*proven 2 subgoals*) . qed lemma collecti_index_list_refine: "(collecti_index_list,collecti_index)∈ (nat_rel → Id → bool_rel ×⇩r ⟨Id⟩list_set_rel) → ⟨Id⟩list_rel → ⟨nat_rel×⇩rId⟩list_set_rel" apply ((intro fun_relI (*‹(⋀(a::?'a) a'::?'b. (a, a') ∈ (?A::(?'a × ?'b) set) ⟹ ((?f::?'a ⇒ ?'c) a, (?f'::?'b ⇒ ?'d) a') ∈ (?B::(?'c × ?'d) set)) ⟹ (?f, ?f') ∈ ?A → ?B›*))[1]) (*goal: ‹(collecti_index_list, collecti_index) ∈ (nat_rel → Id → bool_rel ×⇩r ⟨Id⟩list_set_rel) → ⟨Id⟩list_rel → ⟨nat_rel ×⇩r Id⟩list_set_rel›*) apply (simp add: list_set_rel_def (*‹⟨?R::(?'a × ?'b) set⟩list_set_rel ≡ ⟨?R⟩list_rel O br set distinct›*)) (*goal: ‹⋀a a' aa a'a. ⟦(a, a') ∈ nat_rel → Id → bool_rel ×⇩r ⟨Id⟩list_set_rel; (aa, a'a) ∈ ⟨Id⟩list_rel⟧ ⟹ (collecti_index_list a aa, collecti_index a' a'a) ∈ ⟨nat_rel ×⇩r Id⟩list_set_rel›*) apply (rule brI (*‹⟦?a = ?α ?c; ?I ?c⟧ ⟹ (?c, ?a) ∈ br ?α ?I›*)) (*goals: 1. ‹⋀a a' aa a'a. ⟦(a, a') ∈ nat_rel → Id → bool_rel ×⇩r br set distinct; aa = a'a⟧ ⟹ collecti_index a' a'a = set (collecti_index_list a a'a)› 2. ‹⋀a a' aa a'a. ⟦(a, a') ∈ nat_rel → Id → bool_rel ×⇩r br set distinct; aa = a'a⟧ ⟹ distinct (collecti_index_list a a'a)› discuss goal 1*) apply (simp add: br_def (*‹br ?α ?I ≡ {(c, a). a = ?α c ∧ ?I c}›*)) (*top goal: ‹⋀a a' aa a'a. ⟦(a, a') ∈ nat_rel → Id → bool_rel ×⇩r br set distinct; aa = a'a⟧ ⟹ collecti_index a' a'a = set (collecti_index_list a a'a)› and 1 goal remains*) apply (rule collecti_index'_list_α[of _ _ 0 "[]", simplified, symmetric] (*‹(⋀i x b l. ?ci i x = (b, l) ⟹ ?c i x = (b, set l)) ⟹ collecti_index ?c ?l = set (collecti_index_list ?ci ?l)›*)) (*top goal: ‹⋀a a' aa a'a. ⟦(a, a') ∈ nat_rel → Id → bool_rel ×⇩r {(c, a). a = set c ∧ distinct c}; aa = a'a⟧ ⟹ collecti_index a' a'a = set (collecti_index_list a a'a)› and 1 goal remains*) apply ((drule_tac x=i and x'=i in fun_relD (*‹⟦(?f, ?f') ∈ ?A → ?B; (?x, ?x') ∈ ?A⟧ ⟹ (?f ?x, ?f' ?x') ∈ ?B›*))[1]) (*goals: 1. ‹⋀a a' aa a'a i x b l. ⟦aa = a'a; a i x = (b, l)⟧ ⟹ (i, i) ∈ nat_rel› 2. ‹⋀a a' aa a'a i x b l. ⟦aa = a'a; a i x = (b, l); (a i, a' i) ∈ Id → bool_rel ×⇩r {(c, a). a = set c ∧ distinct c}⟧ ⟹ a' i x = (b, set l)› discuss goal 1*) apply simp (*discuss goal 2*) apply ((drule_tac x=x and x'=x in fun_relD (*‹⟦(?f, ?f') ∈ ?A → ?B; (?x, ?x') ∈ ?A⟧ ⟹ (?f ?x, ?f' ?x') ∈ ?B›*))[1]) (*goals: 1. ‹⋀a a' aa a'a i x b l. ⟦aa = a'a; a i x = (b, l)⟧ ⟹ (x, x) ∈ Id› 2. ‹⋀a a' aa a'a i x b l. ⟦aa = a'a; a i x = (b, l); (a i x, a' i x) ∈ bool_rel ×⇩r {(c, a). a = set c ∧ distinct c}⟧ ⟹ a' i x = (b, set l)› discuss goal 1*) apply simp (*discuss goal 2*) apply ((auto simp: prod_rel_def (*‹?R1.0 ×⇩r ?R2.0 ≡ {((a, b), a', b'). (a, a') ∈ ?R1.0 ∧ (b, b') ∈ ?R2.0}›*))[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply (rule collecti_index'_list_invar (*‹⟦⋀i x b l. ?c i x = (b, l) ⟹ distinct l; fst ` set ?a ⊆ {0..<?i0.0}; distinct ?a⟧ ⟹ distinct (collecti_index'_list ?i0.0 ?a ?c ?l)›*)) (*goals: 1. ‹⋀a a' aa a'a i x b l. ⟦(a, a') ∈ nat_rel → Id → bool_rel ×⇩r br set distinct; aa = a'a; a i x = (b, l)⟧ ⟹ distinct l› 2. ‹⋀a a' aa a'a. ⟦(a, a') ∈ nat_rel → Id → bool_rel ×⇩r br set distinct; aa = a'a⟧ ⟹ fst ` set [] ⊆ {0..<0}› 3. ‹⋀a a' aa a'a. ⟦(a, a') ∈ nat_rel → Id → bool_rel ×⇩r br set distinct; aa = a'a⟧ ⟹ distinct []› discuss goal 1*) apply ((auto)[1]) (*top goal: ‹⋀a a' aa a'a i x b l. ⟦(a, a') ∈ nat_rel → Id → bool_rel ×⇩r br set distinct; aa = a'a; a i x = (b, l)⟧ ⟹ distinct l› and 2 goals remain*) apply ((drule_tac x=i and x'=i in fun_relD (*‹⟦(?f::?'a ⇒ ?'b, ?f'::?'c ⇒ ?'d) ∈ (?A::(?'a × ?'c) set) → (?B::(?'b × ?'d) set); (?x::?'a, ?x'::?'c) ∈ ?A⟧ ⟹ (?f ?x, ?f' ?x') ∈ ?B›*))[1]) (*goals: 1. ‹⋀a a' i x b l. a i x = (b, l) ⟹ (i, i) ∈ nat_rel› 2. ‹⋀a a' i x b l. ⟦a i x = (b, l); (a i, a' i) ∈ Id → bool_rel ×⇩r br set distinct⟧ ⟹ distinct l› discuss goal 1*) apply simp (*discuss goal 2*) apply ((drule_tac x=x and x'=x in fun_relD (*‹⟦(?f, ?f') ∈ ?A → ?B; (?x, ?x') ∈ ?A⟧ ⟹ (?f ?x, ?f' ?x') ∈ ?B›*))[1]) (*goals: 1. ‹⋀a a' i x b l. a i x = (b, l) ⟹ (x, x) ∈ Id› 2. ‹⋀a a' i x b l. ⟦a i x = (b, l); (a i x, a' i x) ∈ bool_rel ×⇩r br set distinct⟧ ⟹ distinct l› discuss goal 1*) apply simp (*discuss goal 2*) apply ((auto simp: prod_rel_def (*‹(?R1.0::(?'a × ?'c) set) ×⇩r (?R2.0::(?'b × ?'d) set) ≡ {((a::?'a, b::?'b), a'::?'c, b'::?'d). (a, a') ∈ ?R1.0 ∧ (b, b') ∈ ?R2.0}›*) br_def (*‹br (?α::?'a ⇒ ?'b) (?I::?'a ⇒ bool) ≡ {(c::?'a, a::?'b). a = ?α c ∧ ?I c}›*))[1]) (*proven 2 subgoals*) (*proven 2 subgoals*) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) (*proven 2 subgoals*) . end
{ "path": "afp-2025-02-12/thys/CAVA_LTL_Modelchecker/SM/Impl/SM_Datastructures.thy", "repo": "afp-2025-02-12", "sha": "87d20a73699671313d7491079c892d89bfd41569a84a1096aef0598d388c582a" }
(* Title: Omega Algebra Author: Alasdair Armstrong, Georg Struth, Tjark Weber Maintainer: Georg Struth <g.struth at sheffield.ac.uk> Tjark Weber <tjark.weber at it.uu.se> *) section ‹Omega Algebras› theory Omega_Algebra imports Kleene_Algebra begin text ‹ \emph{Omega algebras}~\<^cite>‹"cohen00omega"› extend Kleene algebras by an $\omega$-operation that axiomatizes infinite iteration (just like the Kleene star axiomatizes finite iteration). › subsection ‹Left Omega Algebras› text ‹ In this section we consider \emph{left omega algebras}, i.e., omega algebras based on left Kleene algebras. Surprisingly, we are still looking for statements mentioning~$\omega$ that are true in omega algebras, but do not already hold in left omega algebras. › class left_omega_algebra = left_kleene_algebra_zero + omega_op + assumes omega_unfold: "x⇧ω ≤ x ⋅ x⇧ω" and omega_coinduct: "y ≤ z + x ⋅ y ⟹ y ≤ x⇧ω + x⇧⋆ ⋅ z" begin text ‹First we prove some variants of the coinduction axiom.› lemma omega_coinduct_var1: "y ≤ 1 + x ⋅ y ⟹ y ≤ x⇧ω + x⇧⋆" using local.omega_coinduct (*‹?y ≤ ?z + ?x ⋅ ?y ⟹ ?y ≤ ?x⇧ω + ?x⇧⋆ ⋅ ?z›*) by fastforce lemma omega_coinduct_var2: "y ≤ x ⋅ y ⟹ y ≤ x⇧ω" by (metis add.commute (*‹(?a::'a) + (?b::'a) = ?b + ?a›*) add_zero_l (*‹(0::'a) + (?x::'a) = ?x›*) annir (*‹(?x::'a) ⋅ (0::'a) = (0::'a)›*) omega_coinduct (*‹(?y::'a) ≤ (?z::'a) + (?x::'a) ⋅ ?y ⟹ ?y ≤ ?x⇧ω + ?x⇧⋆ ⋅ ?z›*)) lemma omega_coinduct_eq: "y = z + x ⋅ y ⟹ y ≤ x⇧ω + x⇧⋆ ⋅ z" by (simp add: local.omega_coinduct (*‹?y ≤ ?z + ?x ⋅ ?y ⟹ ?y ≤ ?x⇧ω + ?x⇧⋆ ⋅ ?z›*)) lemma omega_coinduct_eq_var1: "y = 1 + x ⋅ y ⟹ y ≤ x⇧ω + x⇧⋆" by (simp add: omega_coinduct_var1 (*‹?y ≤ 1 + ?x ⋅ ?y ⟹ ?y ≤ ?x⇧ω + ?x⇧⋆›*)) lemma omega_coinduct_eq_var2: "y = x ⋅ y ⟹ y ≤ x⇧ω" by (simp add: omega_coinduct_var2 (*‹?y ≤ ?x ⋅ ?y ⟹ ?y ≤ ?x⇧ω›*)) lemma "y = x ⋅ y + z ⟹ y = x⇧⋆ ⋅ z + x⇧ω" (* nitpick [expect=genuine] -- "2-element counterexample" *) oops lemma "y = 1 + x ⋅ y ⟹ y = x⇧ω + x⇧⋆" (* nitpick [expect=genuine] -- "3-element counterexample" *) oops lemma "y = x ⋅ y ⟹ y = x⇧ω" (* nitpick [expect=genuine] -- "2-element counterexample" *) oops text ‹Next we strengthen the unfold law to an equation.› lemma omega_unfold_eq [simp]: "x ⋅ x⇧ω = x⇧ω" proof (rule order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹x ⋅ x⇧ω ≤ x⇧ω› 2. ‹x⇧ω ≤ x ⋅ x⇧ω›*) have "x ⋅ x⇧ω ≤ x ⋅ x ⋅ x⇧ω" by (simp add: local.mult_isol (*‹?x ≤ ?y ⟹ ?z ⋅ ?x ≤ ?z ⋅ ?y›*) local.omega_unfold (*‹?x⇧ω ≤ ?x ⋅ ?x⇧ω›*) mult_assoc (*‹?a ⋅ ?b ⋅ ?c = ?a ⋅ (?b ⋅ ?c)›*)) thus "x ⋅ x⇧ω ≤ x⇧ω" by (simp add: mult_assoc (*‹?a ⋅ ?b ⋅ ?c = ?a ⋅ (?b ⋅ ?c)›*) omega_coinduct_var2 (*‹?y ≤ ?x ⋅ ?y ⟹ ?y ≤ ?x⇧ω›*)) show "x⇧ω ≤ x ⋅ x⇧ω" by (fact omega_unfold (*‹?x⇧ω ≤ ?x ⋅ ?x⇧ω›*)) qed lemma omega_unfold_var: "z + x ⋅ x⇧ω ≤ x⇧ω + x⇧⋆ ⋅ z" by (simp add: local.omega_coinduct (*‹?y ≤ ?z + ?x ⋅ ?y ⟹ ?y ≤ ?x⇧ω + ?x⇧⋆ ⋅ ?z›*)) lemma "z + x ⋅ x⇧ω = x⇧ω + x⇧⋆ ⋅ z" (* nitpick [expect=genuine] -- "4-element counterexample" *) oops text ‹We now prove subdistributivity and isotonicity of omega.› lemma omega_subdist: "x⇧ω ≤ (x + y)⇧ω" proof (-) (*goal: ‹(x::'a::type)⇧ω ≤ (x + (y::'a::type))⇧ω›*) have "x⇧ω ≤ (x + y) ⋅ x⇧ω" by simp thus "?thesis" (*goal: ‹x⇧ω ≤ (x + y)⇧ω›*) by (rule omega_coinduct_var2 (*‹?y ≤ ?x ⋅ ?y ⟹ ?y ≤ ?x⇧ω›*)) qed lemma omega_iso: "x ≤ y ⟹ x⇧ω ≤ y⇧ω" by (metis less_eq_def (*‹(?x ≤ ?y) = (?x + ?y = ?y)›*) omega_subdist (*‹?x⇧ω ≤ (?x + ?y)⇧ω›*)) lemma omega_subdist_var: "x⇧ω + y⇧ω ≤ (x + y)⇧ω" by (simp add: omega_iso (*‹?x ≤ ?y ⟹ ?x⇧ω ≤ ?y⇧ω›*)) lemma zero_omega [simp]: "0⇧ω = 0" by (metis annil (*‹0 ⋅ ?x = 0›*) omega_unfold_eq (*‹?x ⋅ ?x⇧ω = ?x⇧ω›*)) text ‹The next lemma is another variant of omega unfold› lemma star_omega_1 [simp]: "x⇧⋆ ⋅ x⇧ω = x⇧ω" proof (rule order.antisym (*‹⟦(?a::'a::type) ≤ (?b::'a::type); ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹(x::'a::type)⇧⋆ ⋅ x⇧ω ≤ x⇧ω› 2. ‹(x::'a::type)⇧ω ≤ x⇧⋆ ⋅ x⇧ω›*) have "x ⋅ x⇧ω ≤ x⇧ω" by simp thus "x⇧⋆ ⋅ x⇧ω ≤ x⇧ω" by simp show "x⇧ω ≤ x⇧⋆ ⋅ x⇧ω" using local.star_inductl_var_eq2 (*‹?y = ?x ⋅ ?y ⟹ ?y = ?x⇧⋆ ⋅ ?y›*) by auto qed text ‹The next lemma says that~@{term "1⇧ω"} is the maximal element of omega algebra. We therefore baptise it~$\top$.› lemma max_element: "x ≤ 1⇧ω" by (simp add: omega_coinduct_eq_var2 (*‹?y = ?x ⋅ ?y ⟹ ?y ≤ ?x⇧ω›*)) definition top ("⊤") where "⊤ = 1⇧ω" lemma star_omega_3 [simp]: "(x⇧⋆)⇧ω = ⊤" proof (-) (*goal: ‹(x⇧⋆)⇧ω = ⊤›*) have "1 ≤ x⇧⋆" by (fact star_ref (*‹1 ≤ ?x⇧⋆›*)) hence "⊤ ≤ (x⇧⋆)⇧ω" by (simp add: omega_iso (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x⇧ω ≤ ?y⇧ω›*) top_def (*‹⊤ = (1::'a)⇧ω›*)) thus "?thesis" (*goal: ‹(x⇧⋆)⇧ω = ⊤›*) by (simp add: local.order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*) max_element (*‹?x ≤ 1⇧ω›*) top_def (*‹⊤ = 1⇧ω›*)) qed text ‹The following lemma is strange since it is counterintuitive that one should be able to append something after an infinite iteration.› lemma omega_1: "x⇧ω ⋅ y ≤ x⇧ω" proof (-) (*goal: ‹x⇧ω ⋅ y ≤ x⇧ω›*) have "x⇧ω ⋅ y ≤ x ⋅ x⇧ω ⋅ y" by simp thus "?thesis" (*goal: ‹x⇧ω ⋅ y ≤ x⇧ω›*) by (metis mult.assoc (*‹?a ⋅ ?b ⋅ ?c = ?a ⋅ (?b ⋅ ?c)›*) omega_coinduct_var2 (*‹?y ≤ ?x ⋅ ?y ⟹ ?y ≤ ?x⇧ω›*)) qed lemma "x⇧ω ⋅ y = x⇧ω" (*nitpick [expect=genuine] -- "2-element counterexample"*) oops lemma omega_sup_id: "1 ≤ y ⟹ x⇧ω ⋅ y = x⇧ω" using order.eq_iff (*‹(?a = ?b) = (?a ≤ ?b ∧ ?b ≤ ?a)›*) local.mult_isol (*‹?x ≤ ?y ⟹ ?z ⋅ ?x ≤ ?z ⋅ ?y›*) omega_1 (*‹?x⇧ω ⋅ ?y ≤ ?x⇧ω›*) by fastforce lemma omega_top [simp]: "x⇧ω ⋅ ⊤ = x⇧ω" by (simp add: max_element (*‹(?x::'a::type) ≤ (1::'a::type)⇧ω›*) omega_sup_id (*‹(1::'a::type) ≤ (?y::'a::type) ⟹ (?x::'a::type)⇧ω ⋅ ?y = ?x⇧ω›*) top_def (*‹⊤ = (1::'a::type)⇧ω›*)) lemma supid_omega: "1 ≤ x ⟹ x⇧ω = ⊤" by (simp add: local.order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*) max_element (*‹?x ≤ 1⇧ω›*) omega_iso (*‹?x ≤ ?y ⟹ ?x⇧ω ≤ ?y⇧ω›*) top_def (*‹⊤ = 1⇧ω›*)) lemma "x⇧ω = ⊤ ⟹ 1 ≤ x" (* nitpick [expect=genuine] -- "4-element counterexample" *) oops text ‹Next we prove a simulation law for the omega operation› lemma omega_simulation: "z ⋅ x ≤ y ⋅ z ⟹ z ⋅ x⇧ω ≤ y⇧ω" proof (-) (*goal: ‹z ⋅ x ≤ y ⋅ z ⟹ z ⋅ x⇧ω ≤ y⇧ω›*) assume hyp: "z ⋅ x ≤ y ⋅ z" (*‹(z::'a) ⋅ (x::'a) ≤ (y::'a) ⋅ z›*) have "z ⋅ x⇧ω = z ⋅ x ⋅ x⇧ω" by (simp add: mult_assoc (*‹?a ⋅ ?b ⋅ ?c = ?a ⋅ (?b ⋅ ?c)›*)) also (*calculation: ‹(z::'a) ⋅ (x::'a)⇧ω = z ⋅ x ⋅ x⇧ω›*) have "... ≤ y ⋅ z ⋅ x⇧ω" by (simp add: hyp (*‹z ⋅ x ≤ y ⋅ z›*) local.mult_isor (*‹?x ≤ ?y ⟹ ?x ⋅ ?z ≤ ?y ⋅ ?z›*)) finally (*calculation: ‹z ⋅ x⇧ω ≤ y ⋅ z ⋅ x⇧ω›*) show "z ⋅ x⇧ω ≤ y⇧ω" by (simp add: mult_assoc (*‹?a ⋅ ?b ⋅ ?c = ?a ⋅ (?b ⋅ ?c)›*) omega_coinduct_var2 (*‹?y ≤ ?x ⋅ ?y ⟹ ?y ≤ ?x⇧ω›*)) qed lemma "z ⋅ x ≤ y ⋅ z ⟹ z ⋅ x⇧ω ≤ y⇧ω ⋅ z" (* nitpick [expect=genuine] -- "4-element counterexample" *) oops lemma "y ⋅ z ≤ z ⋅ x ⟹ y⇧ω ≤ z ⋅ x⇧ω" (* nitpick [expect=genuine] -- "2-element counterexample" *) oops lemma "y ⋅ z ≤ z ⋅ x ⟹ y⇧ω ⋅ z ≤ x⇧ω" (* nitpick [expect=genuine] -- "4-element counterexample" *) oops text ‹Next we prove transitivity of omega elements.› lemma omega_omega: "(x⇧ω)⇧ω ≤ x⇧ω" by (metis omega_1 (*‹(?x::'a::type)⇧ω ⋅ (?y::'a::type) ≤ ?x⇧ω›*) omega_unfold_eq (*‹(?x::'a::type) ⋅ ?x⇧ω = ?x⇧ω›*)) (* lemma "x⇧ω ⋅ x⇧ω = x⇧ω" nitpick -- "no proof, no counterexample" lemma "(x⇧ω)⇧ω = x⇧ω" nitpick -- "no proof, no counterexample" *) text ‹The next lemmas are axioms of Wagner's complete axiomatisation for omega-regular languages~\<^cite>‹"wagner77omega"›, but in a slightly different setting.› lemma wagner_1 [simp]: "(x ⋅ x⇧⋆)⇧ω = x⇧ω" proof (rule order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹((x::'a::type) ⋅ x⇧⋆)⇧ω ≤ x⇧ω› 2. ‹(x::'a::type)⇧ω ≤ (x ⋅ x⇧⋆)⇧ω›*) have "(x ⋅ x⇧⋆)⇧ω = x ⋅ x⇧⋆ ⋅ x ⋅ x⇧⋆ ⋅ (x ⋅ x⇧⋆)⇧ω" by (metis mult.assoc (*‹(?a::'a) ⋅ (?b::'a) ⋅ (?c::'a) = ?a ⋅ (?b ⋅ ?c)›*) omega_unfold_eq (*‹(?x::'a) ⋅ ?x⇧ω = ?x⇧ω›*)) also (*calculation: ‹(x ⋅ x⇧⋆)⇧ω = x ⋅ x⇧⋆ ⋅ x ⋅ x⇧⋆ ⋅ (x ⋅ x⇧⋆)⇧ω›*) have "... = x ⋅ x ⋅ x⇧⋆ ⋅ x⇧⋆ ⋅ (x ⋅ x⇧⋆)⇧ω" by (simp add: local.star_slide_var (*‹(?x::'a)⇧⋆ ⋅ ?x = ?x ⋅ ?x⇧⋆›*) mult_assoc (*‹(?a::'a) ⋅ (?b::'a) ⋅ (?c::'a) = ?a ⋅ (?b ⋅ ?c)›*)) also (*calculation: ‹(x ⋅ x⇧⋆)⇧ω = x ⋅ x ⋅ x⇧⋆ ⋅ x⇧⋆ ⋅ (x ⋅ x⇧⋆)⇧ω›*) have "... = x ⋅ x ⋅ x⇧⋆ ⋅ (x ⋅ x⇧⋆)⇧ω" by (simp add: mult_assoc (*‹(?a::'a) ⋅ (?b::'a) ⋅ (?c::'a) = ?a ⋅ (?b ⋅ ?c)›*)) also (*calculation: ‹(x ⋅ x⇧⋆)⇧ω = x ⋅ x ⋅ x⇧⋆ ⋅ (x ⋅ x⇧⋆)⇧ω›*) have "... = x ⋅ (x ⋅ x⇧⋆)⇧ω" by (simp add: mult_assoc (*‹?a ⋅ ?b ⋅ ?c = ?a ⋅ (?b ⋅ ?c)›*)) thus "(x ⋅ x⇧⋆)⇧ω ≤ x⇧ω" using calculation (*‹(x ⋅ x⇧⋆)⇧ω = x ⋅ x ⋅ x⇧⋆ ⋅ (x ⋅ x⇧⋆)⇧ω›*) omega_coinduct_eq_var2 (*‹?y = ?x ⋅ ?y ⟹ ?y ≤ ?x⇧ω›*) by auto show "x⇧ω ≤ (x ⋅ x⇧⋆)⇧ω" by (simp add: mult_assoc (*‹?a ⋅ ?b ⋅ ?c = ?a ⋅ (?b ⋅ ?c)›*) omega_coinduct_eq_var2 (*‹?y = ?x ⋅ ?y ⟹ ?y ≤ ?x⇧ω›*)) qed lemma wagner_2_var: "x ⋅ (y ⋅ x)⇧ω ≤ (x ⋅ y)⇧ω" proof (-) (*goal: ‹x ⋅ (y ⋅ x)⇧ω ≤ (x ⋅ y)⇧ω›*) have "x ⋅ y ⋅ x ≤ x ⋅ y ⋅ x" by auto thus "x ⋅ (y ⋅ x)⇧ω ≤ (x ⋅ y)⇧ω" by (simp add: mult_assoc (*‹?a ⋅ ?b ⋅ ?c = ?a ⋅ (?b ⋅ ?c)›*) omega_simulation (*‹?z ⋅ ?x ≤ ?y ⋅ ?z ⟹ ?z ⋅ ?x⇧ω ≤ ?y⇧ω›*)) qed lemma wagner_2 [simp]: "x ⋅ (y ⋅ x)⇧ω = (x ⋅ y)⇧ω" proof (rule order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹x ⋅ (y ⋅ x)⇧ω ≤ (x ⋅ y)⇧ω› 2. ‹(x ⋅ y)⇧ω ≤ x ⋅ (y ⋅ x)⇧ω›*) show "x ⋅ (y ⋅ x)⇧ω ≤ (x ⋅ y)⇧ω" by (rule wagner_2_var (*‹?x ⋅ (?y ⋅ ?x)⇧ω ≤ (?x ⋅ ?y)⇧ω›*)) have "(x ⋅ y)⇧ω = x ⋅ y ⋅ (x ⋅ y)⇧ω" by simp thus "(x ⋅ y)⇧ω ≤ x ⋅ (y ⋅ x)⇧ω" by (metis mult.assoc (*‹?a ⋅ ?b ⋅ ?c = ?a ⋅ (?b ⋅ ?c)›*) mult_isol (*‹?x ≤ ?y ⟹ ?z ⋅ ?x ≤ ?z ⋅ ?y›*) wagner_2_var (*‹?x ⋅ (?y ⋅ ?x)⇧ω ≤ (?x ⋅ ?y)⇧ω›*)) qed text ‹ This identity is called~(A8) in Wagner's paper. › lemma wagner_3: assumes "x ⋅ (x + y)⇧ω + z = (x + y)⇧ω" shows "(x + y)⇧ω = x⇧ω + x⇧⋆ ⋅ z" proof (rule order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹(x + y)⇧ω ≤ x⇧ω + x⇧⋆ ⋅ z› 2. ‹x⇧ω + x⇧⋆ ⋅ z ≤ (x + y)⇧ω›*) show "(x + y)⇧ω ≤ x⇧ω + x⇧⋆ ⋅ z" using assms (*‹x ⋅ (x + y)⇧ω + z = (x + y)⇧ω›*) local.join.sup_commute (*‹?x + ?y = ?y + ?x›*) omega_coinduct_eq (*‹(?y::'a) = (?z::'a) + (?x::'a) ⋅ ?y ⟹ ?y ≤ ?x⇧ω + ?x⇧⋆ ⋅ ?z›*) by auto have "x⇧⋆ ⋅ z ≤ (x + y)⇧ω" using assms (*‹(x::'a) ⋅ (x + (y::'a))⇧ω + (z::'a) = (x + y)⇧ω›*) local.join.sup_commute (*‹?x + ?y = ?y + ?x›*) local.star_inductl_eq (*‹?z + ?x ⋅ ?y = ?y ⟹ ?x⇧⋆ ⋅ ?z ≤ ?y›*) by auto thus "x⇧ω + x⇧⋆ ⋅ z ≤ (x + y)⇧ω" by (simp add: omega_subdist (*‹(?x::'a)⇧ω ≤ (?x + (?y::'a))⇧ω›*)) qed text ‹ This identity is called~(R4) in Wagner's paper. › lemma wagner_1_var [simp]: "(x⇧⋆ ⋅ x)⇧ω = x⇧ω" by (simp add: local.star_slide_var (*‹?x⇧⋆ ⋅ ?x = ?x ⋅ ?x⇧⋆›*)) lemma star_omega_4 [simp]: "(x⇧ω)⇧⋆ = 1 + x⇧ω" proof (rule order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹((x::'a::type)⇧ω)⇧⋆ ≤ (1::'a::type) + x⇧ω› 2. ‹(1::'a::type) + (x::'a::type)⇧ω ≤ (x⇧ω)⇧⋆›*) have "(x⇧ω)⇧⋆ = 1 + x⇧ω ⋅ (x⇧ω)⇧⋆" by simp also (*calculation: ‹(x⇧ω)⇧⋆ = 1 + x⇧ω ⋅ (x⇧ω)⇧⋆›*) have "... ≤ 1 + x⇧ω ⋅ ⊤" by (simp add: omega_sup_id (*‹1 ≤ ?y ⟹ ?x⇧ω ⋅ ?y = ?x⇧ω›*)) finally (*calculation: ‹(x⇧ω)⇧⋆ ≤ 1 + x⇧ω ⋅ ⊤›*) show "(x⇧ω)⇧⋆ ≤ 1 + x⇧ω" by simp show "1 + x⇧ω ≤ (x⇧ω)⇧⋆" by simp qed lemma star_omega_5 [simp]: "x⇧ω ⋅ (x⇧ω)⇧⋆ = x⇧ω" proof (rule order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹x⇧ω ⋅ (x⇧ω)⇧⋆ ≤ x⇧ω› 2. ‹x⇧ω ≤ x⇧ω ⋅ (x⇧ω)⇧⋆›*) show "x⇧ω ⋅ (x⇧ω)⇧⋆ ≤ x⇧ω" by (rule omega_1 (*‹(?x::'a)⇧ω ⋅ (?y::'a) ≤ ?x⇧ω›*)) show "x⇧ω ≤ x⇧ω ⋅ (x⇧ω)⇧⋆" by (simp add: omega_sup_id (*‹1 ≤ ?y ⟹ ?x⇧ω ⋅ ?y = ?x⇧ω›*)) qed text ‹The next law shows how omegas below a sum can be unfolded.› lemma omega_sum_unfold: "x⇧ω + x⇧⋆ ⋅ y ⋅ (x + y)⇧ω = (x + y)⇧ω" proof (-) (*goal: ‹(x::'a)⇧ω + x⇧⋆ ⋅ (y::'a) ⋅ (x + y)⇧ω = (x + y)⇧ω›*) have "(x + y)⇧ω = x ⋅ (x + y)⇧ω + y ⋅ (x+y)⇧ω" by (metis distrib_right (*‹(?a + ?b) ⋅ ?c = ?a ⋅ ?c + ?b ⋅ ?c›*) omega_unfold_eq (*‹?x ⋅ ?x⇧ω = ?x⇧ω›*)) thus "?thesis" (*goal: ‹x⇧ω + x⇧⋆ ⋅ y ⋅ (x + y)⇧ω = (x + y)⇧ω›*) by (metis mult.assoc (*‹?a ⋅ ?b ⋅ ?c = ?a ⋅ (?b ⋅ ?c)›*) wagner_3 (*‹?x ⋅ (?x + ?y)⇧ω + ?z = (?x + ?y)⇧ω ⟹ (?x + ?y)⇧ω = ?x⇧ω + ?x⇧⋆ ⋅ ?z›*)) qed text ‹ The next two lemmas apply induction and coinduction to this law. › lemma omega_sum_unfold_coind: "(x + y)⇧ω ≤ (x⇧⋆ ⋅ y)⇧ω + (x⇧⋆ ⋅ y)⇧⋆ ⋅ x⇧ω" by (simp add: omega_coinduct_eq (*‹?y = ?z + ?x ⋅ ?y ⟹ ?y ≤ ?x⇧ω + ?x⇧⋆ ⋅ ?z›*) omega_sum_unfold (*‹?x⇧ω + ?x⇧⋆ ⋅ ?y ⋅ (?x + ?y)⇧ω = (?x + ?y)⇧ω›*)) lemma omega_sum_unfold_ind: "(x⇧⋆ ⋅ y)⇧⋆ ⋅ x⇧ω ≤ (x + y)⇧ω" by (simp add: local.star_inductl_eq (*‹(?z::'a) + (?x::'a) ⋅ (?y::'a) = ?y ⟹ ?x⇧⋆ ⋅ ?z ≤ ?y›*) omega_sum_unfold (*‹(?x::'a)⇧ω + ?x⇧⋆ ⋅ (?y::'a) ⋅ (?x + ?y)⇧ω = (?x + ?y)⇧ω›*)) lemma wagner_1_gen: "(x ⋅ y⇧⋆)⇧ω ≤ (x + y)⇧ω" proof (-) (*goal: ‹(x ⋅ y⇧⋆)⇧ω ≤ (x + y)⇧ω›*) have "(x ⋅ y⇧⋆)⇧ω ≤ ((x + y) ⋅ (x + y)⇧⋆)⇧ω" using local.join.le_sup_iff (*‹(?x + ?y ≤ ?z) = (?x ≤ ?z ∧ ?y ≤ ?z)›*) local.join.sup.cobounded1 (*‹?a ≤ ?a + ?b›*) local.mult_isol_var (*‹⟦?u ≤ ?x; ?v ≤ ?y⟧ ⟹ ?u ⋅ ?v ≤ ?x ⋅ ?y›*) local.star_subdist_var (*‹?x⇧⋆ + ?y⇧⋆ ≤ (?x + ?y)⇧⋆›*) omega_iso (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x⇧ω ≤ ?y⇧ω›*) by presburger thus "?thesis" (*goal: ‹(x ⋅ y⇧⋆)⇧ω ≤ (x + y)⇧ω›*) by (metis wagner_1 (*‹(?x ⋅ ?x⇧⋆)⇧ω = ?x⇧ω›*)) qed lemma wagner_1_var_gen: "(x⇧⋆ ⋅ y)⇧ω ≤ (x + y)⇧ω" proof (-) (*goal: ‹(x⇧⋆ ⋅ y)⇧ω ≤ (x + y)⇧ω›*) have "(x⇧⋆ ⋅ y)⇧ω = x⇧⋆ ⋅ (y ⋅ x⇧⋆)⇧ω" by simp also (*calculation: ‹(x⇧⋆ ⋅ y)⇧ω = x⇧⋆ ⋅ (y ⋅ x⇧⋆)⇧ω›*) have "... ≤ x⇧⋆ ⋅ (x + y)⇧ω" by (metis add.commute (*‹?a + ?b = ?b + ?a›*) mult_isol (*‹?x ≤ ?y ⟹ ?z ⋅ ?x ≤ ?z ⋅ ?y›*) wagner_1_gen (*‹(?x ⋅ ?y⇧⋆)⇧ω ≤ (?x + ?y)⇧ω›*)) also (*calculation: ‹(x⇧⋆ ⋅ y)⇧ω ≤ x⇧⋆ ⋅ (x + y)⇧ω›*) have "... ≤ (x + y)⇧⋆ ⋅ (x + y)⇧ω" using local.mult_isor (*‹?x ≤ ?y ⟹ ?x ⋅ ?z ≤ ?y ⋅ ?z›*) local.star_subdist (*‹?x⇧⋆ ≤ (?x + ?y)⇧⋆›*) by auto thus "?thesis" (*goal: ‹(x⇧⋆ ⋅ y)⇧ω ≤ (x + y)⇧ω›*) by (metis calculation (*‹(x⇧⋆ ⋅ y)⇧ω ≤ x⇧⋆ ⋅ (x + y)⇧ω›*) order_trans (*‹⟦?x ≤ ?y; ?y ≤ ?z⟧ ⟹ ?x ≤ ?z›*) star_omega_1 (*‹?x⇧⋆ ⋅ ?x⇧ω = ?x⇧ω›*)) qed text ‹The next lemma is a variant of the denest law for the star at the level of omega.› lemma omega_denest [simp]: "(x + y)⇧ω = (x⇧⋆ ⋅ y)⇧ω + (x⇧⋆ ⋅ y)⇧⋆ ⋅ x⇧ω" proof (rule order.antisym (*‹⟦(?a::'a) ≤ (?b::'a); ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹((x::'a) + (y::'a))⇧ω ≤ (x⇧⋆ ⋅ y)⇧ω + (x⇧⋆ ⋅ y)⇧⋆ ⋅ x⇧ω› 2. ‹((x::'a)⇧⋆ ⋅ (y::'a))⇧ω + (x⇧⋆ ⋅ y)⇧⋆ ⋅ x⇧ω ≤ (x + y)⇧ω›*) show "(x + y)⇧ω ≤ (x⇧⋆ ⋅ y)⇧ω + (x⇧⋆ ⋅ y)⇧⋆ ⋅ x⇧ω" by (rule omega_sum_unfold_coind (*‹(?x + ?y)⇧ω ≤ (?x⇧⋆ ⋅ ?y)⇧ω + (?x⇧⋆ ⋅ ?y)⇧⋆ ⋅ ?x⇧ω›*)) have "(x⇧⋆ ⋅ y)⇧ω ≤ (x + y)⇧ω" by (rule wagner_1_var_gen (*‹(?x⇧⋆ ⋅ ?y)⇧ω ≤ (?x + ?y)⇧ω›*)) hence "(x⇧⋆ ⋅ y)⇧⋆ ⋅ x⇧ω ≤ (x + y)⇧ω" by (simp add: omega_sum_unfold_ind (*‹((?x::'a)⇧⋆ ⋅ (?y::'a))⇧⋆ ⋅ ?x⇧ω ≤ (?x + ?y)⇧ω›*)) thus "(x⇧⋆ ⋅ y)⇧ω + (x⇧⋆ ⋅ y)⇧⋆ ⋅ x⇧ω ≤ (x + y)⇧ω" by (simp add: wagner_1_var_gen (*‹(?x⇧⋆ ⋅ ?y)⇧ω ≤ (?x + ?y)⇧ω›*)) qed text ‹The next lemma yields a separation theorem for infinite iteration in the presence of a quasicommutation property. A nondeterministic loop over~@{term x} and~@{term y} can be refined into separate infinite loops over~@{term x} and~@{term y}.› lemma omega_sum_refine: assumes "y ⋅ x ≤ x ⋅ (x + y)⇧⋆" shows "(x + y)⇧ω = x⇧ω + x⇧⋆ ⋅ y⇧ω" proof (rule order.antisym (*‹⟦(?a::'a::type) ≤ (?b::'a::type); ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹(x + y)⇧ω ≤ x⇧ω + x⇧⋆ ⋅ y⇧ω› 2. ‹x⇧ω + x⇧⋆ ⋅ y⇧ω ≤ (x + y)⇧ω›*) have a: "y⇧⋆ ⋅ x ≤ x ⋅ (x + y)⇧⋆" using assms (*‹(y::'a) ⋅ (x::'a) ≤ x ⋅ (x + y)⇧⋆›*) local.quasicomm_var (*‹((?y::'a) ⋅ (?x::'a) ≤ ?x ⋅ (?x + ?y)⇧⋆) = (?y⇧⋆ ⋅ ?x ≤ ?x ⋅ (?x + ?y)⇧⋆)›*) by blast have "(x + y)⇧ω = y⇧ω + y⇧⋆ ⋅ x ⋅ (x + y)⇧ω" by (metis add.commute (*‹?a + ?b = ?b + ?a›*) omega_sum_unfold (*‹?x⇧ω + ?x⇧⋆ ⋅ ?y ⋅ (?x + ?y)⇧ω = (?x + ?y)⇧ω›*)) also (*calculation: ‹(x + y)⇧ω = y⇧ω + y⇧⋆ ⋅ x ⋅ (x + y)⇧ω›*) have "... ≤ y⇧ω + x ⋅ (x + y)⇧⋆ ⋅ (x + y)⇧ω" using a (*‹y⇧⋆ ⋅ x ≤ x ⋅ (x + y)⇧⋆›*) local.join.sup_mono (*‹⟦?a ≤ ?c; ?b ≤ ?d⟧ ⟹ ?a + ?b ≤ ?c + ?d›*) local.mult_isol_var (*‹⟦(?u::'a::type) ≤ (?x::'a::type); (?v::'a::type) ≤ (?y::'a::type)⟧ ⟹ ?u ⋅ ?v ≤ ?x ⋅ ?y›*) by blast also (*calculation: ‹(x + y)⇧ω ≤ y⇧ω + x ⋅ (x + y)⇧⋆ ⋅ (x + y)⇧ω›*) have "... ≤ x ⋅ (x + y)⇧ω + y⇧ω" using local.eq_refl (*‹?x = ?y ⟹ ?x ≤ ?y›*) local.join.sup_commute (*‹?x + ?y = ?y + ?x›*) mult_assoc (*‹?a ⋅ ?b ⋅ ?c = ?a ⋅ (?b ⋅ ?c)›*) star_omega_1 (*‹?x⇧⋆ ⋅ ?x⇧ω = ?x⇧ω›*) by presburger finally (*calculation: ‹(x + y)⇧ω ≤ x ⋅ (x + y)⇧ω + y⇧ω›*) show "(x + y)⇧ω ≤ x⇧ω + x⇧⋆ ⋅ y⇧ω" by (metis add_commute (*‹(?a::'a) + (?b::'a) = ?b + ?a›*) local.omega_coinduct (*‹(?y::'a) ≤ (?z::'a) + (?x::'a) ⋅ ?y ⟹ ?y ≤ ?x⇧ω + ?x⇧⋆ ⋅ ?z›*)) have "x⇧ω + x⇧⋆ ⋅ y⇧ω ≤ (x + y)⇧ω + (x + y)⇧⋆ ⋅ (x + y)⇧ω" using local.join.sup.cobounded2 (*‹?b ≤ ?a + ?b›*) local.join.sup.mono (*‹⟦(?c::'a) ≤ (?a::'a); (?d::'a) ≤ (?b::'a)⟧ ⟹ ?c + ?d ≤ ?a + ?b›*) local.mult_isol_var (*‹⟦?u ≤ ?x; ?v ≤ ?y⟧ ⟹ ?u ⋅ ?v ≤ ?x ⋅ ?y›*) local.star_subdist (*‹?x⇧⋆ ≤ (?x + ?y)⇧⋆›*) omega_iso (*‹(?x::'a) ≤ (?y::'a) ⟹ ?x⇧ω ≤ ?y⇧ω›*) omega_subdist (*‹?x⇧ω ≤ (?x + ?y)⇧ω›*) by presburger thus "x⇧ω + x⇧⋆ ⋅ y⇧ω ≤ (x + y)⇧ω" by (metis local.join.sup_idem (*‹(?x::'a) + ?x = ?x›*) star_omega_1 (*‹(?x::'a)⇧⋆ ⋅ ?x⇧ω = ?x⇧ω›*)) qed text ‹The following theorem by Bachmair and Dershowitz~\<^cite>‹"bachmair86commutation"› is a corollary.› lemma bachmair_dershowitz: assumes "y ⋅ x ≤ x ⋅ (x + y)⇧⋆" shows "(x + y)⇧ω = 0 ⟷ x⇧ω + y⇧ω = 0" by (metis add_commute (*‹?a + ?b = ?b + ?a›*) assms (*‹y ⋅ x ≤ x ⋅ (x + y)⇧⋆›*) local.annir (*‹?x ⋅ 0 = 0›*) local.join.le_bot (*‹?a ≤ 0 ⟹ ?a = 0›*) local.no_trivial_inverse (*‹?x ≠ 0 ⟹ ∄y. ?x + y = 0›*) omega_subdist (*‹?x⇧ω ≤ (?x + ?y)⇧ω›*) omega_sum_refine (*‹?y ⋅ ?x ≤ ?x ⋅ (?x + ?y)⇧⋆ ⟹ (?x + ?y)⇧ω = ?x⇧ω + ?x⇧⋆ ⋅ ?y⇧ω›*)) text ‹ The next lemmas consider an abstract variant of the empty word property from language theory and match it with the absence of infinite iteration~\<^cite>‹"struth12regeq"›. › definition (in dioid_one_zero) ewp where "ewp x ≡ ¬(∀y. y ≤ x ⋅ y ⟶ y = 0)" lemma ewp_super_id1: "0 ≠ 1 ⟹ 1 ≤ x ⟹ ewp x" by (metis ewp_def (*‹ewp ?x ≡ ¬ (∀y. y ≤ ?x ⋅ y ⟶ y = 0)›*) mult_oner (*‹?x ⋅ 1 = ?x›*)) lemma "0 ≠ 1 ⟹ 1 ≤ x ⟷ ewp x" (* nitpick [expect=genuine] -- "3-element counterexample" *) oops text ‹The next facts relate the absence of the empty word property with the absence of infinite iteration.› lemma ewp_neg_and_omega: "¬ ewp x ⟷ x⇧ω = 0" proof (standard) (*goals: 1. ‹¬ ewp x ⟹ x⇧ω = 0› 2. ‹x⇧ω = 0 ⟹ ¬ ewp x›*) assume "¬ ewp x" (*‹¬ ewp (x::'a)›*) hence "∀ y. y ≤ x ⋅ y ⟶ y = 0" by (meson ewp_def (*‹ewp ?x ≡ ¬ (∀y. y ≤ ?x ⋅ y ⟶ y = 0)›*)) thus "x⇧ω = 0" by simp next (*goal: ‹x⇧ω = 0 ⟹ ¬ ewp x›*) assume "x⇧ω = 0" (*‹(x::'a)⇧ω = (0::'a)›*) hence "∀ y. y ≤ x ⋅ y ⟶ y = 0" using local.join.le_bot (*‹?a ≤ 0 ⟹ ?a = 0›*) local.omega_coinduct_var2 (*‹?y ≤ ?x ⋅ ?y ⟹ ?y ≤ ?x⇧ω›*) by blast thus "¬ ewp x" by (meson ewp_def (*‹ewp ?x ≡ ¬ (∀y. y ≤ ?x ⋅ y ⟶ y = 0)›*)) qed lemma ewp_alt1: "(∀z. x⇧ω ≤ x⇧⋆ ⋅ z) ⟷ (∀y z. y ≤ x ⋅ y + z ⟶ y ≤ x⇧⋆ ⋅ z)" by (metis add_comm (*‹?x + ?y = ?y + ?x›*) less_eq_def (*‹(?x ≤ ?y) = (?x + ?y = ?y)›*) omega_coinduct (*‹?y ≤ ?z + ?x ⋅ ?y ⟹ ?y ≤ ?x⇧ω + ?x⇧⋆ ⋅ ?z›*) omega_unfold_eq (*‹?x ⋅ ?x⇧ω = ?x⇧ω›*) order_prop (*‹(?x ≤ ?y) = (∃z. ?x + z = ?y)›*)) lemma ewp_alt: "x⇧ω = 0 ⟷ (∀y z. y ≤ x ⋅ y + z ⟶ y ≤ x⇧⋆ ⋅ z)" by (metis annir (*‹?x ⋅ 0 = 0›*) order.antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*) ewp_alt1 (*‹(∀z. ?x⇧ω ≤ ?x⇧⋆ ⋅ z) = (∀y z. y ≤ ?x ⋅ y + z ⟶ y ≤ ?x⇧⋆ ⋅ z)›*) join.bot_least (*‹0 ≤ ?a›*)) text ‹So we have obtained a condition for Arden's lemma in omega algebra.› lemma omega_super_id1: "0 ≠ 1 ⟹ 1 ≤ x ⟹ x⇧ω ≠ 0" using ewp_neg_and_omega (*‹(¬ ewp (?x::'a)) = (?x⇧ω = (0::'a))›*) ewp_super_id1 (*‹⟦0 ≠ 1; 1 ≤ ?x⟧ ⟹ ewp ?x›*) by blast lemma omega_super_id2: "0 ≠ 1 ⟹ x⇧ω = 0 ⟹ ¬(1 ≤ x)" using omega_super_id1 (*‹⟦0 ≠ 1; 1 ≤ ?x⟧ ⟹ ?x⇧ω ≠ 0›*) by blast text ‹The next lemmas are abstract versions of Arden's lemma from language theory.› lemma ardens_lemma_var: assumes "x⇧ω = 0" and "z + x ⋅ y = y" shows "x⇧⋆ ⋅ z = y" proof (-) (*goal: ‹x⇧⋆ ⋅ z = y›*) have "y ≤ x⇧ω + x⇧⋆ ⋅ z" by (simp add: assms( (*‹z + x ⋅ y = y›*) 2) local.omega_coinduct_eq (*‹?y = ?z + ?x ⋅ ?y ⟹ ?y ≤ ?x⇧ω + ?x⇧⋆ ⋅ ?z›*)) hence "y ≤ x⇧⋆ ⋅ z" by (simp add: assms( (*‹x⇧ω = 0›*) 1)) thus "x⇧⋆ ⋅ z = y" by (simp add: assms( (*‹z + x ⋅ y = y›*) 2) order.eq_iff (*‹(?a = ?b) = (?a ≤ ?b ∧ ?b ≤ ?a)›*) local.star_inductl_eq (*‹?z + ?x ⋅ ?y = ?y ⟹ ?x⇧⋆ ⋅ ?z ≤ ?y›*)) qed lemma ardens_lemma: "¬ ewp x ⟹ z + x ⋅ y = y ⟹ x⇧⋆ ⋅ z = y" by (simp add: ardens_lemma_var (*‹⟦?x⇧ω = 0; ?z + ?x ⋅ ?y = ?y⟧ ⟹ ?x⇧⋆ ⋅ ?z = ?y›*) ewp_neg_and_omega (*‹(¬ ewp ?x) = (?x⇧ω = 0)›*)) lemma ardens_lemma_equiv: assumes "¬ ewp x" shows "z + x ⋅ y = y ⟷ x⇧⋆ ⋅ z = y" by (metis ardens_lemma_var (*‹⟦?x⇧ω = 0; ?z + ?x ⋅ ?y = ?y⟧ ⟹ ?x⇧⋆ ⋅ ?z = ?y›*) assms (*‹¬ ewp x›*) ewp_neg_and_omega (*‹(¬ ewp ?x) = (?x⇧ω = 0)›*) local.conway.dagger_unfoldl_distr (*‹?y + ?x ⋅ ?x⇧⋆ ⋅ ?y = ?x⇧⋆ ⋅ ?y›*) mult_assoc (*‹?a ⋅ ?b ⋅ ?c = ?a ⋅ (?b ⋅ ?c)›*)) lemma ardens_lemma_var_equiv: "x⇧ω = 0 ⟹ (z + x ⋅ y = y ⟷ x⇧⋆ ⋅ z = y)" by (simp add: ardens_lemma_equiv (*‹¬ ewp ?x ⟹ (?z + ?x ⋅ ?y = ?y) = (?x⇧⋆ ⋅ ?z = ?y)›*) ewp_neg_and_omega (*‹(¬ ewp ?x) = (?x⇧ω = 0)›*)) lemma arden_conv1: "(∀y z. z + x ⋅ y = y ⟶ x⇧⋆ ⋅ z = y) ⟹ ¬ ewp x" by (metis add_zero_l (*‹0 + ?x = ?x›*) annir (*‹?x ⋅ 0 = 0›*) ewp_neg_and_omega (*‹(¬ ewp ?x) = (?x⇧ω = 0)›*) omega_unfold_eq (*‹?x ⋅ ?x⇧ω = ?x⇧ω›*)) lemma arden_conv2: "(∀y z. z + x ⋅ y = y ⟶ x⇧⋆ ⋅ z = y) ⟹ x⇧ω = 0" using arden_conv1 (*‹∀y z. z + ?x ⋅ y = y ⟶ ?x⇧⋆ ⋅ z = y ⟹ ¬ ewp ?x›*) ewp_neg_and_omega (*‹(¬ ewp (?x::'a)) = (?x⇧ω = (0::'a))›*) by blast lemma arden_var3: "(∀y z. z + x ⋅ y = y ⟶ x⇧⋆ ⋅ z = y) ⟷ x⇧ω = 0" using arden_conv2 (*‹∀y z. z + ?x ⋅ y = y ⟶ ?x⇧⋆ ⋅ z = y ⟹ ?x⇧ω = 0›*) ardens_lemma_var (*‹⟦(?x::'a)⇧ω = (0::'a); (?z::'a) + ?x ⋅ (?y::'a) = ?y⟧ ⟹ ?x⇧⋆ ⋅ ?z = ?y›*) by blast end subsection ‹Omega Algebras› class omega_algebra = kleene_algebra + left_omega_algebra end
{ "path": "afp-2025-02-12/thys/Kleene_Algebra/Omega_Algebra.thy", "repo": "afp-2025-02-12", "sha": "8c58889d11250d05e1433f3bc8607062c5f830dbc559343d510231b081386474" }
section "Kruskal Implementation" theory Kruskal_Impl imports Kruskal_Refine Refine_Imperative_HOL.IICF begin subsection ‹Refinement III: concrete edges› text ‹Given a concrete representation of edges and their endpoints as a pair, we refine Kruskal's algorithm to work on these concrete edges.› locale Kruskal_concrete = Kruskal_interface E V vertices joins forest connected weight for E V vertices joins forest connected and weight :: "'edge ⇒ int" + fixes α :: "'cedge ⇒ 'edge" and endpoints :: "'cedge ⇒ ('a*'a) nres" assumes endpoints_refine: "α xi = x ⟹ endpoints xi ≤ ⇓ Id (a_endpoints x)" begin definition wsorted' where "wsorted' == sorted_wrt (λx y. weight (α x) ≤ weight (α y))" lemma wsorted_mapα[simp]: "wsorted' s ⟹ wsorted (map α s)" by (auto simp: wsorted'_def (*‹wsorted' ≡ sorted_wrt (λx y. weight (α x) ≤ weight (α y))›*) sorted_wrt_map (*‹sorted_wrt ?R (map ?f ?xs) = sorted_wrt (λx y. ?R (?f x) (?f y)) ?xs›*)) definition "obtain_sorted_carrier' == SPEC (λL. wsorted' L ∧ α ` set L = E)" abbreviation concrete_edge_rel :: "('cedge × 'edge) set" where "concrete_edge_rel ≡ br α (λ_. True)" lemma obtain_sorted_carrier'_refine: "(obtain_sorted_carrier', obtain_sorted_carrier) ∈ ⟨⟨concrete_edge_rel⟩list_rel⟩nres_rel" unfolding obtain_sorted_carrier'_def obtain_sorted_carrier_def (*goal: ‹(SPEC (λL. wsorted' L ∧ α ` set L = E), SPEC (λL. wsorted L ∧ set L = E)) ∈ ⟨⟨concrete_edge_rel⟩list_rel⟩nres_rel›*) apply refine_vcg (*goal: ‹(SPEC (λL::'cedge list. wsorted' L ∧ (α::'cedge ⇒ 'edge) ` set L = (E::'edge set)), SPEC (λL::'edge list. wsorted L ∧ set L = E)) ∈ ⟨⟨concrete_edge_rel⟩list_rel⟩nres_rel›*) apply (auto intro!: RES_refine (*‹(⋀s. s ∈ ?S ⟹ ∃s'∈?S'. (s, s') ∈ ?R) ⟹ RES ?S ≤ ⇓ ?R (RES ?S')›*) simp:) (*goal: ‹SPEC (λL. wsorted' L ∧ α ` set L = E) ≤ ⇓ (⟨concrete_edge_rel⟩list_rel) (SPEC (λL. wsorted L ∧ set L = E))›*) subgoal for s apply (rule exI[where x="map α s"] (*‹?P (map α s) ⟹ ∃x. ?P x›*)) (*goal: ‹⟦wsorted' s; E = α ` set s⟧ ⟹ ∃s'. wsorted s' ∧ set s' = α ` set s ∧ (s, s') ∈ ⟨concrete_edge_rel⟩list_rel›*) by (auto simp: map_in_list_rel_conv (*‹((?l, ?l') ∈ ⟨br ?α ?I⟩list_rel) = ((∀x∈set ?l. ?I x) ∧ ?l' = map ?α ?l)›*) in_br_conv (*‹((?c, ?a) ∈ br ?α ?I) = (?a = ?α ?c ∧ ?I ?c)›*)) . definition kruskal2 where "kruskal2 ≡ do { l ← obtain_sorted_carrier'; let initial_union_find = per_init V; (per, spanning_forest) ← nfoldli l (λ_. True) (λce (uf, T). do { ASSERT (α ce ∈ E); (a,b) ← endpoints ce; ASSERT (a∈V ∧ b∈V ∧ a ∈ Domain uf ∧ b ∈ Domain uf ); if ¬ per_compare uf a b then do { let uf = per_union uf a b; ASSERT (ce ∉ set T); RETURN (uf, T@[ce]) } else RETURN (uf,T) }) (initial_union_find, []); RETURN spanning_forest }" lemma lst_graph_rel_empty[simp]: "([], {}) ∈ ⟨concrete_edge_rel⟩list_set_rel" unfolding list_set_rel_def (*goal: ‹([], {}) ∈ ⟨concrete_edge_rel⟩list_rel O br set distinct›*) apply (rule relcompI[where b="[]"] (*‹⟦(?a, []) ∈ ?r; ([], ?c) ∈ ?s⟧ ⟹ (?a, ?c) ∈ ?r O ?s›*)) (*goals: 1. ‹([], []) ∈ ⟨concrete_edge_rel⟩list_rel› 2. ‹([], {}) ∈ br set distinct› discuss goal 1*) apply ((auto simp add: in_br_conv (*‹((?c, ?a) ∈ br ?α ?I) = (?a = ?α ?c ∧ ?I ?c)›*))[1]) (*discuss goal 2*) apply ((auto simp add: in_br_conv (*‹((?c::?'a::type, ?a::?'b::type) ∈ br (?α::?'a::type ⇒ ?'b::type) (?I::?'a::type ⇒ bool)) = (?a = ?α ?c ∧ ?I ?c)›*))[1]) (*proven 2 subgoals*) . lemma loop_initial_rel: "((per_init V, []), per_init V, {}) ∈ Id ×⇩r ⟨concrete_edge_rel⟩list_set_rel" by simp lemma concrete_edge_rel_list_set_rel: "(a, b) ∈ ⟨concrete_edge_rel⟩list_set_rel ⟹ α ` (set a) = b" by (auto simp: in_br_conv (*‹((?c, ?a) ∈ br ?α ?I) = (?a = ?α ?c ∧ ?I ?c)›*) list_set_rel_def (*‹⟨?R⟩list_set_rel ≡ ⟨?R⟩list_rel O br set distinct›*) dest: list_relD2 (*‹(?x, ?y) ∈ ⟨br ?a ?I⟩list_rel ⟹ ?y = map ?a ?x ∧ (∀x∈set ?x. ?I x)›*)) theorem kruskal2_refine: "(kruskal2, kruskal1)∈⟨⟨concrete_edge_rel⟩list_set_rel⟩nres_rel" unfolding kruskal1_def kruskal2_def Let_def (*goal: ‹(obtain_sorted_carrier' ⤜ (λl. nfoldli l (λ_. True) (λce (uf, T). ASSERT (α ce ∈ E) ⤜ (λ_. endpoints ce ⤜ (λ(a, b). ASSERT (a ∈ V ∧ b ∈ V ∧ a ∈ Domain uf ∧ b ∈ Domain uf) ⤜ (λ_. if ¬ per_compare uf a b then ASSERT (ce ∉ set T) ⤜ (λ_. RETURN (per_union uf a b, T @ [ce])) else RETURN (uf, T))))) (per_init V, []) ⤜ (λ(per, y). RETURN y)), obtain_sorted_carrier ⤜ (λl. nfoldli l (λ_. True) (λe (uf, T). ASSERT (e ∈ E) ⤜ (λ_. a_endpoints e ⤜ (λ(a, b). ASSERT (a ∈ V ∧ b ∈ V ∧ a ∈ Domain uf ∧ b ∈ Domain uf ∧ T ⊆ E) ⤜ (λ_. if ¬ per_compare uf a b then ASSERT (e ∉ T) ⤜ (λ_. RETURN (per_union uf a b, insert e T)) else RETURN (uf, T))))) (per_init V, {}) ⤜ (λ(per, y). RETURN y))) ∈ ⟨⟨concrete_edge_rel⟩list_set_rel⟩nres_rel›*) apply (refine_rcg obtain_sorted_carrier'_refine[THEN nres_relD] endpoints_refine loop_initial_rel) (*goals: 1. ‹⋀l la. (l, la) ∈ ⟨concrete_edge_rel⟩list_rel ⟹ (l, la) ∈ ⟨?S5 l la⟩list_rel› 2. ‹⋀l la a a'. ⟦(l, la) ∈ ⟨concrete_edge_rel⟩list_rel; (a, a') ∈ Id ×⇩r ⟨concrete_edge_rel⟩list_set_rel⟧ ⟹ (True, True) ∈ bool_rel› 3. ‹⋀l la xi x si s x1 x2 x1a x2a. ⟦(l, la) ∈ ⟨concrete_edge_rel⟩list_rel; (xi, x) ∈ ?S5 l la; (si, s) ∈ Id ×⇩r ⟨concrete_edge_rel⟩list_set_rel; True; s = (x1, x2); si = (x1a, x2a); x ∈ E⟧ ⟹ α xi ∈ E› 4. ‹⋀l la xi x si s x1 x2 x1a x2a. ⟦(l, la) ∈ ⟨concrete_edge_rel⟩list_rel; (xi, x) ∈ ?S5 l la; (si, s) ∈ Id ×⇩r ⟨concrete_edge_rel⟩list_set_rel; True; s = (x1, x2); si = (x1a, x2a); x ∈ E; α xi ∈ E⟧ ⟹ α xi = x› 5. ‹⋀l la xi x si s x1 x2 x1a x2a xa x' x1b x2b x1c x2c. ⟦(l, la) ∈ ⟨concrete_edge_rel⟩list_rel; (xi, x) ∈ ?S5 l la; (si, s) ∈ Id ×⇩r ⟨concrete_edge_rel⟩list_set_rel; True; s = (x1, x2); si = (x1a, x2a); x ∈ E; α xi ∈ E; (xa, x') ∈ Id; x' ∈ {(a, b). joins a b x}; x' = (x1b, x2b); xa = (x1c, x2c); x1b ∈ V ∧ x2b ∈ V ∧ x1b ∈ Domain x1 ∧ x2b ∈ Domain x1 ∧ x2 ⊆ E⟧ ⟹ x1c ∈ V› 6. ‹⋀l la xi x si s x1 x2 x1a x2a xa x' x1b x2b x1c x2c. ⟦(l, la) ∈ ⟨concrete_edge_rel⟩list_rel; (xi, x) ∈ ?S5 l la; (si, s) ∈ Id ×⇩r ⟨concrete_edge_rel⟩list_set_rel; True; s = (x1, x2); si = (x1a, x2a); x ∈ E; α xi ∈ E; (xa, x') ∈ Id; x' ∈ {(a, b). joins a b x}; x' = (x1b, x2b); xa = (x1c, x2c); x1b ∈ V ∧ x2b ∈ V ∧ x1b ∈ Domain x1 ∧ x2b ∈ Domain x1 ∧ x2 ⊆ E⟧ ⟹ x2c ∈ V› 7. ‹⋀l la xi x si s x1 x2 x1a x2a xa x' x1b x2b x1c x2c. ⟦(l, la) ∈ ⟨concrete_edge_rel⟩list_rel; (xi, x) ∈ ?S5 l la; (si, s) ∈ Id ×⇩r ⟨concrete_edge_rel⟩list_set_rel; True; s = (x1, x2); si = (x1a, x2a); x ∈ E; α xi ∈ E; (xa, x') ∈ Id; x' ∈ {(a, b). joins a b x}; x' = (x1b, x2b); xa = (x1c, x2c); x1b ∈ V ∧ x2b ∈ V ∧ x1b ∈ Domain x1 ∧ x2b ∈ Domain x1 ∧ x2 ⊆ E⟧ ⟹ x1c ∈ Domain x1a› 8. ‹⋀l la xi x si s x1 x2 x1a x2a xa x' x1b x2b x1c x2c. ⟦(l, la) ∈ ⟨concrete_edge_rel⟩list_rel; (xi, x) ∈ ?S5 l la; (si, s) ∈ Id ×⇩r ⟨concrete_edge_rel⟩list_set_rel; True; s = (x1, x2); si = (x1a, x2a); x ∈ E; α xi ∈ E; (xa, x') ∈ Id; x' ∈ {(a, b). joins a b x}; x' = (x1b, x2b); xa = (x1c, x2c); x1b ∈ V ∧ x2b ∈ V ∧ x1b ∈ Domain x1 ∧ x2b ∈ Domain x1 ∧ x2 ⊆ E⟧ ⟹ x2c ∈ Domain x1a› 9. ‹⋀l la xi x si s x1 x2 x1a x2a xa x' x1b x2b x1c x2c. ⟦(l, la) ∈ ⟨concrete_edge_rel⟩list_rel; (xi, x) ∈ ?S5 l la; (si, s) ∈ Id ×⇩r ⟨concrete_edge_rel⟩list_set_rel; True; s = (x1, x2); si = (x1a, x2a); x ∈ E; α xi ∈ E; (xa, x') ∈ Id; x' ∈ {(a, b). joins a b x}; x' = (x1b, x2b); xa = (x1c, x2c); x1b ∈ V ∧ x2b ∈ V ∧ x1b ∈ Domain x1 ∧ x2b ∈ Domain x1 ∧ x2 ⊆ E; x1c ∈ V ∧ x2c ∈ V ∧ x1c ∈ Domain x1a ∧ x2c ∈ Domain x1a⟧ ⟹ (¬ per_compare x1a x1c x2c) = (¬ per_compare x1 x1b x2b)› 10. ‹⋀l la xi x si s x1 x2 x1a x2a xa x' x1b x2b x1c x2c. ⟦(l, la) ∈ ⟨concrete_edge_rel⟩list_rel; (xi, x) ∈ ?S5 l la; (si, s) ∈ Id ×⇩r ⟨concrete_edge_rel⟩list_set_rel; True; s = (x1, x2); si = (x1a, x2a); x ∈ E; α xi ∈ E; (xa, x') ∈ Id; x' ∈ {(a, b). joins a b x}; x' = (x1b, x2b); xa = (x1c, x2c); x1b ∈ V ∧ x2b ∈ V ∧ x1b ∈ Domain x1 ∧ x2b ∈ Domain x1 ∧ x2 ⊆ E; x1c ∈ V ∧ x2c ∈ V ∧ x1c ∈ Domain x1a ∧ x2c ∈ Domain x1a; ¬ per_compare x1a x1c x2c; ¬ per_compare x1 x1b x2b; x ∉ x2⟧ ⟹ xi ∉ set x2a› 11. ‹⋀l la xi x si s x1 x2 x1a x2a xa x' x1b x2b x1c x2c. ⟦(l, la) ∈ ⟨concrete_edge_rel⟩list_rel; (xi, x) ∈ ?S5 l la; (si, s) ∈ Id ×⇩r ⟨concrete_edge_rel⟩list_set_rel; True; s = (x1, x2); si = (x1a, x2a); x ∈ E; α xi ∈ E; (xa, x') ∈ Id; x' ∈ {(a, b). joins a b x}; x' = (x1b, x2b); xa = (x1c, x2c); x1b ∈ V ∧ x2b ∈ V ∧ x1b ∈ Domain x1 ∧ x2b ∈ Domain x1 ∧ x2 ⊆ E; x1c ∈ V ∧ x2c ∈ V ∧ x1c ∈ Domain x1a ∧ x2c ∈ Domain x1a; ¬ per_compare x1a x1c x2c; ¬ per_compare x1 x1b x2b; x ∉ x2; xi ∉ set x2a⟧ ⟹ ((per_union x1a x1c x2c, x2a @ [xi]), per_union x1 x1b x2b, insert x x2) ∈ Id ×⇩r ⟨concrete_edge_rel⟩list_set_rel› 12. ‹⋀l la xi x si s x1 x2 x1a x2a xa x' x1b x2b x1c x2c. ⟦(l, la) ∈ ⟨concrete_edge_rel⟩list_rel; (xi, x) ∈ ?S5 l la; (si, s) ∈ Id ×⇩r ⟨concrete_edge_rel⟩list_set_rel; True; s = (x1, x2); si = (x1a, x2a); x ∈ E; α xi ∈ E; (xa, x') ∈ Id; x' ∈ {(a, b). joins a b x}; x' = (x1b, x2b); xa = (x1c, x2c); x1b ∈ V ∧ x2b ∈ V ∧ x1b ∈ Domain x1 ∧ x2b ∈ Domain x1 ∧ x2 ⊆ E; x1c ∈ V ∧ x2c ∈ V ∧ x1c ∈ Domain x1a ∧ x2c ∈ Domain x1a; ¬ ¬ per_compare x1a x1c x2c; ¬ ¬ per_compare x1 x1b x2b⟧ ⟹ ((x1a, x2a), x1, x2) ∈ Id ×⇩r ⟨concrete_edge_rel⟩list_set_rel› 13. ‹⋀l la x x' x1 x2 x1a x2a. ⟦(l, la) ∈ ⟨concrete_edge_rel⟩list_rel; (x, x') ∈ Id ×⇩r ⟨concrete_edge_rel⟩list_set_rel; x' = (x1, x2); x = (x1a, x2a)⟧ ⟹ (x2a, x2) ∈ ⟨concrete_edge_rel⟩list_set_rel› discuss goal 1*) apply ((auto intro!: list_set_rel_append (*‹⟦(?x::?'a, ?s::?'b) ∈ br (?a::?'a ⇒ ?'b) (?I::?'a ⇒ bool); (?xs::?'a list, ?S::?'b set) ∈ ⟨br ?a ?I⟩list_set_rel; ?s ∉ ?S⟧ ⟹ (?xs @ [?x], insert ?s ?S) ∈ ⟨br ?a ?I⟩list_set_rel›*) dest: concrete_edge_rel_list_set_rel (*‹(?a::'cedge list, ?b::'edge set) ∈ ⟨concrete_edge_rel⟩list_set_rel ⟹ (α::'cedge ⇒ 'edge) ` set ?a = ?b›*) simp: in_br_conv (*‹((?c::?'a, ?a::?'b) ∈ br (?α::?'a ⇒ ?'b) (?I::?'a ⇒ bool)) = (?a = ?α ?c ∧ ?I ?c)›*))[1]) (*discuss goal 2*) apply ((auto intro!: list_set_rel_append (*‹⟦(?x::?'a, ?s::?'b) ∈ br (?a::?'a ⇒ ?'b) (?I::?'a ⇒ bool); (?xs::?'a list, ?S::?'b set) ∈ ⟨br ?a ?I⟩list_set_rel; ?s ∉ ?S⟧ ⟹ (?xs @ [?x], insert ?s ?S) ∈ ⟨br ?a ?I⟩list_set_rel›*) dest: concrete_edge_rel_list_set_rel (*‹(?a::'cedge list, ?b::'edge set) ∈ ⟨concrete_edge_rel⟩list_set_rel ⟹ (α::'cedge ⇒ 'edge) ` set ?a = ?b›*) simp: in_br_conv (*‹((?c::?'a, ?a::?'b) ∈ br (?α::?'a ⇒ ?'b) (?I::?'a ⇒ bool)) = (?a = ?α ?c ∧ ?I ?c)›*))[1]) (*discuss goal 3*) apply ((auto intro!: list_set_rel_append (*‹⟦(?x, ?s) ∈ br ?a ?I; (?xs, ?S) ∈ ⟨br ?a ?I⟩list_set_rel; ?s ∉ ?S⟧ ⟹ (?xs @ [?x], insert ?s ?S) ∈ ⟨br ?a ?I⟩list_set_rel›*) dest: concrete_edge_rel_list_set_rel (*‹(?a, ?b) ∈ ⟨concrete_edge_rel⟩list_set_rel ⟹ α ` set ?a = ?b›*) simp: in_br_conv (*‹((?c, ?a) ∈ br ?α ?I) = (?a = ?α ?c ∧ ?I ?c)›*))[1]) (*discuss goal 4*) apply ((auto intro!: list_set_rel_append (*‹⟦(?x, ?s) ∈ br ?a ?I; (?xs, ?S) ∈ ⟨br ?a ?I⟩list_set_rel; ?s ∉ ?S⟧ ⟹ (?xs @ [?x], insert ?s ?S) ∈ ⟨br ?a ?I⟩list_set_rel›*) dest: concrete_edge_rel_list_set_rel (*‹(?a, ?b) ∈ ⟨concrete_edge_rel⟩list_set_rel ⟹ α ` set ?a = ?b›*) simp: in_br_conv (*‹((?c, ?a) ∈ br ?α ?I) = (?a = ?α ?c ∧ ?I ?c)›*))[1]) (*discuss goal 5*) apply ((auto intro!: list_set_rel_append (*‹⟦(?x::?'a::type, ?s::?'b::type) ∈ br (?a::?'a::type ⇒ ?'b::type) (?I::?'a::type ⇒ bool); (?xs::?'a::type list, ?S::?'b::type set) ∈ ⟨br ?a ?I⟩list_set_rel; ?s ∉ ?S⟧ ⟹ (?xs @ [?x], insert ?s ?S) ∈ ⟨br ?a ?I⟩list_set_rel›*) dest: concrete_edge_rel_list_set_rel (*‹(?a::'cedge::type list, ?b::'edge::type set) ∈ ⟨concrete_edge_rel⟩list_set_rel ⟹ (α::'cedge::type ⇒ 'edge::type) ` set ?a = ?b›*) simp: in_br_conv (*‹((?c::?'a::type, ?a::?'b::type) ∈ br (?α::?'a::type ⇒ ?'b::type) (?I::?'a::type ⇒ bool)) = (?a = ?α ?c ∧ ?I ?c)›*))[1]) (*discuss goal 6*) apply ((auto intro!: list_set_rel_append (*‹⟦(?x::?'a, ?s::?'b) ∈ br (?a::?'a ⇒ ?'b) (?I::?'a ⇒ bool); (?xs::?'a list, ?S::?'b set) ∈ ⟨br ?a ?I⟩list_set_rel; ?s ∉ ?S⟧ ⟹ (?xs @ [?x], insert ?s ?S) ∈ ⟨br ?a ?I⟩list_set_rel›*) dest: concrete_edge_rel_list_set_rel (*‹(?a::'cedge list, ?b::'edge set) ∈ ⟨concrete_edge_rel⟩list_set_rel ⟹ (α::'cedge ⇒ 'edge) ` set ?a = ?b›*) simp: in_br_conv (*‹((?c::?'a, ?a::?'b) ∈ br (?α::?'a ⇒ ?'b) (?I::?'a ⇒ bool)) = (?a = ?α ?c ∧ ?I ?c)›*))[1]) (*discuss goal 7*) apply ((auto intro!: list_set_rel_append (*‹⟦(?x, ?s) ∈ br ?a ?I; (?xs, ?S) ∈ ⟨br ?a ?I⟩list_set_rel; ?s ∉ ?S⟧ ⟹ (?xs @ [?x], insert ?s ?S) ∈ ⟨br ?a ?I⟩list_set_rel›*) dest: concrete_edge_rel_list_set_rel (*‹(?a, ?b) ∈ ⟨concrete_edge_rel⟩list_set_rel ⟹ α ` set ?a = ?b›*) simp: in_br_conv (*‹((?c, ?a) ∈ br ?α ?I) = (?a = ?α ?c ∧ ?I ?c)›*))[1]) (*discuss goal 8*) apply ((auto intro!: list_set_rel_append (*‹⟦(?x::?'a::type, ?s::?'b::type) ∈ br (?a::?'a::type ⇒ ?'b::type) (?I::?'a::type ⇒ bool); (?xs::?'a::type list, ?S::?'b::type set) ∈ ⟨br ?a ?I⟩list_set_rel; ?s ∉ ?S⟧ ⟹ (?xs @ [?x], insert ?s ?S) ∈ ⟨br ?a ?I⟩list_set_rel›*) dest: concrete_edge_rel_list_set_rel (*‹(?a::'cedge::type list, ?b::'edge::type set) ∈ ⟨concrete_edge_rel⟩list_set_rel ⟹ (α::'cedge::type ⇒ 'edge::type) ` set ?a = ?b›*) simp: in_br_conv (*‹((?c::?'a::type, ?a::?'b::type) ∈ br (?α::?'a::type ⇒ ?'b::type) (?I::?'a::type ⇒ bool)) = (?a = ?α ?c ∧ ?I ?c)›*))[1]) (*discuss goal 9*) apply ((auto intro!: list_set_rel_append (*‹⟦(?x::?'a, ?s::?'b) ∈ br (?a::?'a ⇒ ?'b) (?I::?'a ⇒ bool); (?xs::?'a list, ?S::?'b set) ∈ ⟨br ?a ?I⟩list_set_rel; ?s ∉ ?S⟧ ⟹ (?xs @ [?x], insert ?s ?S) ∈ ⟨br ?a ?I⟩list_set_rel›*) dest: concrete_edge_rel_list_set_rel (*‹(?a::'cedge list, ?b::'edge set) ∈ ⟨concrete_edge_rel⟩list_set_rel ⟹ (α::'cedge ⇒ 'edge) ` set ?a = ?b›*) simp: in_br_conv (*‹((?c::?'a, ?a::?'b) ∈ br (?α::?'a ⇒ ?'b) (?I::?'a ⇒ bool)) = (?a = ?α ?c ∧ ?I ?c)›*))[1]) (*discuss goal 10*) apply ((auto intro!: list_set_rel_append (*‹⟦(?x, ?s) ∈ br ?a ?I; (?xs, ?S) ∈ ⟨br ?a ?I⟩list_set_rel; ?s ∉ ?S⟧ ⟹ (?xs @ [?x], insert ?s ?S) ∈ ⟨br ?a ?I⟩list_set_rel›*) dest: concrete_edge_rel_list_set_rel (*‹(?a, ?b) ∈ ⟨concrete_edge_rel⟩list_set_rel ⟹ α ` set ?a = ?b›*) simp: in_br_conv (*‹((?c, ?a) ∈ br ?α ?I) = (?a = ?α ?c ∧ ?I ?c)›*))[1]) (*discuss goal 11*) apply ((auto intro!: list_set_rel_append (*‹⟦(?x::?'a, ?s::?'b) ∈ br (?a::?'a ⇒ ?'b) (?I::?'a ⇒ bool); (?xs::?'a list, ?S::?'b set) ∈ ⟨br ?a ?I⟩list_set_rel; ?s ∉ ?S⟧ ⟹ (?xs @ [?x], insert ?s ?S) ∈ ⟨br ?a ?I⟩list_set_rel›*) dest: concrete_edge_rel_list_set_rel (*‹(?a::'cedge list, ?b::'edge set) ∈ ⟨concrete_edge_rel⟩list_set_rel ⟹ (α::'cedge ⇒ 'edge) ` set ?a = ?b›*) simp: in_br_conv (*‹((?c::?'a, ?a::?'b) ∈ br (?α::?'a ⇒ ?'b) (?I::?'a ⇒ bool)) = (?a = ?α ?c ∧ ?I ?c)›*))[1]) (*discuss goal 12*) apply ((auto intro!: list_set_rel_append (*‹⟦(?x, ?s) ∈ br ?a ?I; (?xs, ?S) ∈ ⟨br ?a ?I⟩list_set_rel; ?s ∉ ?S⟧ ⟹ (?xs @ [?x], insert ?s ?S) ∈ ⟨br ?a ?I⟩list_set_rel›*) dest: concrete_edge_rel_list_set_rel (*‹(?a, ?b) ∈ ⟨concrete_edge_rel⟩list_set_rel ⟹ α ` set ?a = ?b›*) simp: in_br_conv (*‹((?c, ?a) ∈ br ?α ?I) = (?a = ?α ?c ∧ ?I ?c)›*))[1]) (*discuss goal 13*) apply ((auto intro!: list_set_rel_append (*‹⟦(?x::?'a::type, ?s::?'b::type) ∈ br (?a::?'a::type ⇒ ?'b::type) (?I::?'a::type ⇒ bool); (?xs::?'a::type list, ?S::?'b::type set) ∈ ⟨br ?a ?I⟩list_set_rel; ?s ∉ ?S⟧ ⟹ (?xs @ [?x], insert ?s ?S) ∈ ⟨br ?a ?I⟩list_set_rel›*) dest: concrete_edge_rel_list_set_rel (*‹(?a::'cedge::type list, ?b::'edge::type set) ∈ ⟨concrete_edge_rel⟩list_set_rel ⟹ (α::'cedge::type ⇒ 'edge::type) ` set ?a = ?b›*) simp: in_br_conv (*‹((?c::?'a::type, ?a::?'b::type) ∈ br (?α::?'a::type ⇒ ?'b::type) (?I::?'a::type ⇒ bool)) = (?a = ?α ?c ∧ ?I ?c)›*))[1]) (*proven 13 subgoals*) . end subsection ‹Refinement to Imperative/HOL with Sepref-Tool› text ‹Given implementations for the operations of getting a list of concrete edges and getting the endpoints of a concrete edge we synthesize Kruskal in Imperative/HOL.› locale Kruskal_Impl = Kruskal_concrete E V vertices joins forest connected weight α endpoints for E V vertices joins forest connected and weight :: "'edge ⇒ int" and α and endpoints :: "nat × int × nat ⇒ (nat × nat) nres" + fixes getEdges :: "(nat × int × nat) list nres" and getEdges_impl :: "(nat × int × nat) list Heap" and superE :: "(nat × int × nat) set" and endpoints_impl :: "(nat × int × nat) ⇒ (nat × nat) Heap" assumes getEdges_refine: "getEdges ≤ SPEC (λL. α ` set L = E ∧ (∀(a,wv,b)∈set L. weight (α (a,wv,b)) = wv) ∧ set L ⊆ superE)" and getEdges_impl: "(uncurry0 getEdges_impl, uncurry0 getEdges) ∈ unit_assn⇧k →⇩a list_assn (nat_assn ×⇩a int_assn ×⇩a nat_assn)" and max_node_is_Max_V: "E = α ` set la ⟹ max_node la = Max (insert 0 V)" and endpoints_impl: "( endpoints_impl, endpoints) ∈ (nat_assn ×⇩a int_assn ×⇩a nat_assn)⇧k →⇩a (nat_assn ×⇩a nat_assn)" begin lemma this_loc: "Kruskal_Impl E V vertices joins forest connected weight α endpoints getEdges getEdges_impl superE endpoints_impl" by unfold_locales subsubsection ‹Refinement IV: given an edge set› text ‹We now assume to have an implementation of the operation to obtain a list of the edges of a graph. By sorting this list we refine @{term obtain_sorted_carrier'}.› definition "obtain_sorted_carrier'' = do { l ← SPEC (λL. α ` set L = E ∧ (∀(a,wv,b)∈set L. weight (α (a,wv,b)) = wv) ∧ set L ⊆ superE); SPEC (λL. sorted_wrt edges_less_eq L ∧ set L = set l) }" lemma wsorted'_sorted_wrt_edges_less_eq: assumes "∀(a,wv,b)∈set s. weight (α (a,wv,b)) = wv" "sorted_wrt edges_less_eq s" shows "wsorted' s" using assms (*‹∀(a, wv, b)∈set s. weight (α (a, wv, b)) = wv› ‹sorted_wrt edges_less_eq s›*) apply - (*goal: ‹wsorted' s›*) unfolding wsorted'_def (*goal: ‹⟦∀(a, wv, b)∈set s. weight (α (a, wv, b)) = wv; sorted_wrt edges_less_eq s⟧ ⟹ sorted_wrt (λx y. weight (α x) ≤ weight (α y)) s›*) unfolding edges_less_eq_def (*goal: ‹⟦∀(a, wv, b)∈set s. weight (α (a, wv, b)) = wv; sorted_wrt (λa b. fst (snd a) ≤ fst (snd b)) s⟧ ⟹ sorted_wrt (λx y. weight (α x) ≤ weight (α y)) s›*) apply (rule sorted_wrt_mono_rel (*‹⟦⋀x y. ⟦x ∈ set ?xs; y ∈ set ?xs; ?P x y⟧ ⟹ ?Q x y; sorted_wrt ?P ?xs⟧ ⟹ sorted_wrt ?Q ?xs›*)) (*goals: 1. ‹⋀x y. ⟦∀(a, wv, b)∈set s. weight (α (a, wv, b)) = wv; sorted_wrt (λa b. fst (snd a) ≤ fst (snd b)) s; x ∈ set s; y ∈ set s; ?P2 x y⟧ ⟹ weight (α x) ≤ weight (α y)› 2. ‹⟦∀(a, wv, b)∈set s. weight (α (a, wv, b)) = wv; sorted_wrt (λa b. fst (snd a) ≤ fst (snd b)) s⟧ ⟹ sorted_wrt ?P2 s› discuss goal 1*) apply ((auto simp: case_prod_beta (*‹(case ?p of (x, xa) ⇒ ?f x xa) = ?f (fst ?p) (snd ?p)›*))[1]) (*discuss goal 2*) apply ((auto simp: case_prod_beta (*‹(case ?p of (x, xa) ⇒ ?f x xa) = ?f (fst ?p) (snd ?p)›*))[1]) (*proven 2 subgoals*) . lemma obtain_sorted_carrier''_refine: "(obtain_sorted_carrier'', obtain_sorted_carrier') ∈ ⟨Id⟩nres_rel" unfolding obtain_sorted_carrier''_def obtain_sorted_carrier'_def (*goal: ‹(SPEC (λL::(nat × int × nat) list. (α::nat × int × nat ⇒ 'edge) ` set L = (E::'edge set) ∧ (∀(a::nat, wv::int, b::nat)∈set L. (weight::'edge ⇒ int) (α (a, wv, b)) = wv) ∧ set L ⊆ (superE::(nat × int × nat) set)) ⤜ (λl::(nat × int × nat) list. SPEC (λL::(nat × int × nat) list. sorted_wrt edges_less_eq L ∧ set L = set l)), SPEC (λL::(nat × int × nat) list. wsorted' L ∧ α ` set L = E)) ∈ ⟨Id⟩nres_rel›*) apply refine_vcg (*goals: 1. ‹⋀x xa. ⟦α ` set x = E ∧ (∀(a, wv, b)∈set x. weight (α (a, wv, b)) = wv) ∧ set x ⊆ superE; sorted_wrt edges_less_eq xa ∧ set xa = set x⟧ ⟹ wsorted' xa› 2. ‹⋀x xa. ⟦α ` set x = E ∧ (∀(a, wv, b)∈set x. weight (α (a, wv, b)) = wv) ∧ set x ⊆ superE; sorted_wrt edges_less_eq xa ∧ set xa = set x⟧ ⟹ α ` set xa = E› discuss goal 1*) apply ((auto simp: in_br_conv (*‹((?c, ?a) ∈ br ?α ?I) = (?a = ?α ?c ∧ ?I ?c)›*) wsorted'_sorted_wrt_edges_less_eq (*‹⟦∀(a, wv, b)∈set ?s. weight (α (a, wv, b)) = wv; sorted_wrt edges_less_eq ?s⟧ ⟹ wsorted' ?s›*) distinct_map (*‹distinct (map ?f ?xs) = (distinct ?xs ∧ inj_on ?f (set ?xs))›*) map_in_list_rel_conv (*‹((?l, ?l') ∈ ⟨br ?α ?I⟩list_rel) = ((∀x∈set ?l. ?I x) ∧ ?l' = map ?α ?l)›*))[1]) (*discuss goal 2*) apply ((auto simp: in_br_conv (*‹((?c, ?a) ∈ br ?α ?I) = (?a = ?α ?c ∧ ?I ?c)›*) wsorted'_sorted_wrt_edges_less_eq (*‹⟦∀(a, wv, b)∈set ?s. weight (α (a, wv, b)) = wv; sorted_wrt edges_less_eq ?s⟧ ⟹ wsorted' ?s›*) distinct_map (*‹distinct (map ?f ?xs) = (distinct ?xs ∧ inj_on ?f (set ?xs))›*) map_in_list_rel_conv (*‹((?l, ?l') ∈ ⟨br ?α ?I⟩list_rel) = ((∀x∈set ?l. ?I x) ∧ ?l' = map ?α ?l)›*))[1]) (*proven 2 subgoals*) . definition "obtain_sorted_carrier''' = do { l ← getEdges; RETURN (quicksort_by_rel edges_less_eq [] l, max_node l) }" definition "add_size_rel = br fst (λ(l,n). n= Max (insert 0 V))" lemma obtain_sorted_carrier'''_refine: "(obtain_sorted_carrier''', obtain_sorted_carrier'') ∈ ⟨add_size_rel⟩nres_rel" unfolding obtain_sorted_carrier'''_def obtain_sorted_carrier''_def (*goal: ‹(getEdges ⤜ (λl. RETURN (quicksort_by_rel edges_less_eq [] l, max_node l)), SPEC (λL. α ` set L = E ∧ (∀(a, wv, b)∈set L. weight (α (a, wv, b)) = wv) ∧ set L ⊆ superE) ⤜ (λl. SPEC (λL. sorted_wrt edges_less_eq L ∧ set L = set l))) ∈ ⟨add_size_rel⟩nres_rel›*) apply (refine_rcg getEdges_refine) (*goal: ‹(getEdges ⤜ (λl. RETURN (quicksort_by_rel edges_less_eq [] l, max_node l)), SPEC (λL. α ` set L = E ∧ (∀(a, wv, b)∈set L. weight (α (a, wv, b)) = wv) ∧ set L ⊆ superE) ⤜ (λl. SPEC (λL. sorted_wrt edges_less_eq L ∧ set L = set l))) ∈ ⟨add_size_rel⟩nres_rel›*) by (auto intro!: RETURN_SPEC_refine (*‹∃x'. (?x, x') ∈ ?R ∧ ?Φ x' ⟹ RETURN ?x ≤ ⇓ ?R (SPEC ?Φ)›*) simp: quicksort_by_rel_distinct (*‹distinct ?l ⟹ distinct (quicksort_by_rel edges_less_eq [] ?l)›*) sort_edges_correct (*‹sorted_wrt edges_less_eq (quicksort_by_rel edges_less_eq [] ?l)›*) add_size_rel_def (*‹add_size_rel = br fst (λ(l, n). n = Max (insert 0 V))›*) in_br_conv (*‹((?c, ?a) ∈ br ?α ?I) = (?a = ?α ?c ∧ ?I ?c)›*) max_node_is_Max_V (*‹E = α ` set ?la ⟹ max_node ?la = Max (insert 0 V)›*) dest!: distinct_mapI (*‹distinct (map ?f ?l) ⟹ distinct ?l›*)) lemmas osc_refine = obtain_sorted_carrier'''_refine[FCOMP obtain_sorted_carrier''_refine, to_foparam, simplified] definition kruskal3 :: "(nat × int × nat) list nres" where "kruskal3 ≡ do { (sl,mn) ← obtain_sorted_carrier'''; let initial_union_find = per_init' (mn + 1); (per, spanning_forest) ← nfoldli sl (λ_. True) (λce (uf, T). do { ASSERT (α ce ∈ E); (a,b) ← endpoints ce; ASSERT (a ∈ Domain uf ∧ b ∈ Domain uf); if ¬ per_compare uf a b then do { let uf = per_union uf a b; ASSERT (ce∉set T); RETURN (uf, T@[ce]) } else RETURN (uf,T) }) (initial_union_find, []); RETURN spanning_forest }" lemma endpoints_spec: "endpoints ce ≤ SPEC (λ_. True)" apply (rule order.trans[OF endpoints_refine] (*‹⟦α ?xi1 = ?x1; ⇓ Id (a_endpoints ?x1) ≤ ?c⟧ ⟹ endpoints ?xi1 ≤ ?c›*)) (*goals: 1. ‹(α::nat × int × nat ⇒ 'edge::type) (ce::nat × int × nat) = (?x1::'edge::type)› 2. ‹⇓ Id (a_endpoints (?x1::'edge::type)) ≤ SPEC (λ_::nat × nat. True)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma kruskal3_subset: shows "kruskal3 ≤⇩n SPEC (λT. distinct T ∧ set T ⊆ superE )" unfolding kruskal3_def obtain_sorted_carrier'''_def (*goal: ‹getEdges ⤜ (λl. RETURN (quicksort_by_rel edges_less_eq [] l, max_node l)) ⤜ (λ(sl, mn). let initial_union_find = per_init' (mn + 1) in nfoldli sl (λ_. True) (λce (uf, T). ASSERT (α ce ∈ E) ⤜ (λ_. endpoints ce ⤜ (λ(a, b). ASSERT (a ∈ Domain uf ∧ b ∈ Domain uf) ⤜ (λ_. if ¬ per_compare uf a b then let uf = per_union uf a b in ASSERT (ce ∉ set T) ⤜ (λ_. RETURN (uf, T @ [ce])) else RETURN (uf, T))))) (initial_union_find, []) ⤜ (λ(per, spanning_forest). RETURN spanning_forest)) ≤⇩n SPEC (λT. distinct T ∧ set T ⊆ superE)›*) apply (refine_vcg getEdges_refine[THEN leof_lift] endpoints_spec[THEN leof_lift] nfoldli_leof_rule[where I="λ_ _ (_, T). distinct T ∧ set T ⊆ superE "]) (*goal: ‹(getEdges::(nat × int × nat) list nres) ⤜ (λl::(nat × int × nat) list. RETURN (quicksort_by_rel edges_less_eq [] l, max_node l)) ⤜ (λ(sl::(nat × int × nat) list, mn::nat). let initial_union_find::(nat × nat) set = per_init' (mn + (1::nat)) in nfoldli sl (λ_::(nat × nat) set × (nat × int × nat) list. True) (λ(ce::nat × int × nat) (uf::(nat × nat) set, T::(nat × int × nat) list). ASSERT ((α::nat × int × nat ⇒ 'edge::type) ce ∈ (E::'edge::type set)) ⤜ (λ_::unit. (endpoints::nat × int × nat ⇒ (nat × nat) nres) ce ⤜ (λ(a::nat, b::nat). ASSERT (a ∈ Domain uf ∧ b ∈ Domain uf) ⤜ (λ_::unit. if ¬ per_compare uf a b then let uf::(nat × nat) set = per_union uf a b in ASSERT (ce ∉ set T) ⤜ (λ_::unit. RETURN (uf, T @ [ce])) else RETURN (uf, T))))) (initial_union_find, []) ⤜ (λ(per::(nat × nat) set, spanning_forest::(nat × int × nat) list). RETURN spanning_forest)) ≤⇩n SPEC (λT::(nat × int × nat) list. distinct T ∧ set T ⊆ (superE::(nat × int × nat) set))›*) apply auto (*top goal: ‹⋀x x1 x2 x1a x2a. ⟦α ` set x = E ∧ (∀(a, wv, b)∈set x. weight (α (a, wv, b)) = wv) ∧ set x ⊆ superE; (quicksort_by_rel edges_less_eq [] x, max_node x) = (x1, x2); (per_init' (x2 + 1), []) = (x1a, x2a)⟧ ⟹ distinct x2a› and 9 goals remain*) subgoal for by (metis append_self_conv (*‹(?xs @ ?ys = ?xs) = (?ys = [])›*) in_set_conv_decomp (*‹(?x ∈ set ?xs) = (∃ys zs. ?xs = ys @ ?x # zs)›*) set_quicksort_by_rel (*‹set (quicksort_by_rel ?R ?sl ?xs) = set (?xs @ ?sl)›*) subset_iff (*‹(?A ⊆ ?B) = (∀t. t ∈ ?A ⟶ t ∈ ?B)›*)) . definition per_supset_rel :: "('a per × 'a per) set" where "per_supset_rel ≡ {(p1,p2). p1 ∩ Domain p2 × Domain p2 = p2 ∧ p1 - (Domain p2 × Domain p2) ⊆ Id}" lemma per_supset_rel_dom: "(p1, p2) ∈ per_supset_rel ⟹ Domain p1 ⊇ Domain p2" by (auto simp: per_supset_rel_def (*‹local.per_supset_rel ≡ {(p1::(?'a × ?'a) set, p2::(?'a × ?'a) set). Restr p1 (Domain p2) = p2 ∧ p1 - Domain p2 × Domain p2 ⊆ Id}›*)) lemma per_supset_compare: "(p1, p2) ∈ per_supset_rel ⟹ x1∈Domain p2 ⟹ x2∈Domain p2 ⟹ per_compare p1 x1 x2 ⟷ per_compare p2 x1 x2" by (auto simp: per_supset_rel_def (*‹local.per_supset_rel ≡ {(p1, p2). Restr p1 (Domain p2) = p2 ∧ p1 - Domain p2 × Domain p2 ⊆ Id}›*)) lemma per_supset_union: "(p1, p2) ∈ per_supset_rel ⟹ x1∈Domain p2 ⟹ x2∈Domain p2 ⟹ (per_union p1 x1 x2, per_union p2 x1 x2) ∈ per_supset_rel" apply (clarsimp simp: per_supset_rel_def (*‹local.per_supset_rel ≡ {(p1, p2). Restr p1 (Domain p2) = p2 ∧ p1 - Domain p2 × Domain p2 ⊆ Id}›*) per_union_def (*‹per_union ?R ?a ?b ≡ ?R ∪ {(x, y). (x, ?a) ∈ ?R ∧ (y, ?b) ∈ ?R} ∪ {(y, x). (x, ?a) ∈ ?R ∧ (y, ?b) ∈ ?R}›*) Domain_unfold (*‹Domain ?r = {x. ∃y. (x, y) ∈ ?r}›*)) (*goal: ‹⟦(p1, p2) ∈ local.per_supset_rel; x1 ∈ Domain p2; x2 ∈ Domain p2⟧ ⟹ (per_union p1 x1 x2, per_union p2 x1 x2) ∈ local.per_supset_rel›*) apply (intro subsetI (*‹(⋀x. x ∈ ?A ⟹ x ∈ ?B) ⟹ ?A ⊆ ?B›*) conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹⋀y ya. ⟦(x1, y) ∈ p2; (x2, ya) ∈ p2; Restr p1 {x. ∃y. (x, y) ∈ p2} = p2; p1 - {x. ∃y. (x, y) ∈ p2} × {x. ∃y. (x, y) ∈ p2} ⊆ Id⟧ ⟹ Restr (p1 ∪ {x. (x, x1) ∈ p1} × {y. (y, x2) ∈ p1} ∪ {(y, x). (x, x1) ∈ p1 ∧ (y, x2) ∈ p1}) {x. ∃y. (x, y) ∈ p2 ∨ (x, x1) ∈ p2 ∧ (y, x2) ∈ p2 ∨ (y, x1) ∈ p2 ∧ (x, x2) ∈ p2} = p2 ∪ {x. (x, x1) ∈ p2} × {y. (y, x2) ∈ p2} ∪ {(y, x). (x, x1) ∈ p2 ∧ (y, x2) ∈ p2}› 2. ‹⋀y ya x. ⟦(x1, y) ∈ p2; (x2, ya) ∈ p2; Restr p1 {x. ∃y. (x, y) ∈ p2} = p2; p1 - {x. ∃y. (x, y) ∈ p2} × {x. ∃y. (x, y) ∈ p2} ⊆ Id; x ∈ p1 ∪ {x. (x, x1) ∈ p1} × {y. (y, x2) ∈ p1} ∪ {(y, x). (x, x1) ∈ p1 ∧ (y, x2) ∈ p1} - {x. ∃y. (x, y) ∈ p2 ∨ (x, x1) ∈ p2 ∧ (y, x2) ∈ p2 ∨ (y, x1) ∈ p2 ∧ (x, x2) ∈ p2} × {x. ∃y. (x, y) ∈ p2 ∨ (x, x1) ∈ p2 ∧ (y, x2) ∈ p2 ∨ (y, x1) ∈ p2 ∧ (x, x2) ∈ p2}⟧ ⟹ x ∈ Id› discuss goal 1*) apply blast (*discuss goal 2*) apply force (*proven 2 subgoals*) . lemma per_initN_refine: "(per_init' (Max (insert 0 V) + 1), per_init V) ∈ per_supset_rel" unfolding per_supset_rel_def per_init'_def per_init_def max_node_def (*goal: ‹({(i, i) |i. i < Max (insert 0 V) + 1}, {(i, i) |i. i ∈ V}) ∈ {(p1, p2). Restr p1 (Domain p2) = p2 ∧ p1 - Domain p2 × Domain p2 ⊆ nat_rel}›*) by (auto simp: less_Suc_eq_le (*‹((?m::nat) < Suc (?n::nat)) = (?m ≤ ?n)›*)) theorem kruskal3_refine: "(kruskal3, kruskal2)∈⟨Id⟩nres_rel" unfolding kruskal2_def kruskal3_def Let_def apply (refine_rcg osc_refine[THEN nres_relD] ) supply RELATESI[where R="per_supset_rel::(nat per × _) set", refine_dref_RELATES] apply refine_dref_type subgoal by (simp add: add_size_rel_def in_br_conv) subgoal using per_initN_refine by (simp add: add_size_rel_def in_br_conv) by (auto simp add: add_size_rel_def in_br_conv per_supset_compare per_supset_union dest: per_supset_rel_dom simp del: per_compare_def ) subsubsection ‹Synthesis of Kruskal by SepRef› lemma [sepref_import_param]: "(sort_edges,sort_edges)∈⟨Id×⇩rId×⇩rId⟩list_rel →⟨Id×⇩rId×⇩rId⟩list_rel" by simp lemma [sepref_import_param]: "(max_node, max_node) ∈ ⟨Id×⇩rId×⇩rId⟩list_rel → nat_rel" by simp sepref_register "getEdges" :: "(nat × int × nat) list nres" sepref_register "endpoints" :: "(nat × int × nat) ⇒ (nat*nat) nres" declare getEdges_impl [sepref_fr_rules] declare endpoints_impl [sepref_fr_rules] schematic_goal kruskal_impl: "(uncurry0 ?c, uncurry0 kruskal3 ) ∈ (unit_assn)⇧k →⇩a list_assn (nat_assn ×⇩a int_assn ×⇩a nat_assn)" unfolding kruskal3_def obtain_sorted_carrier'''_def (*goal: ‹(uncurry0 ?c, uncurry0 (getEdges ⤜ (λl. RETURN (quicksort_by_rel edges_less_eq [] l, max_node l)) ⤜ (λ(sl, mn). let initial_union_find = per_init' (mn + 1) in nfoldli sl (λ_. True) (λce (uf, T). ASSERT (α ce ∈ E) ⤜ (λ_. endpoints ce ⤜ (λ(a, b). ASSERT (a ∈ Domain uf ∧ b ∈ Domain uf) ⤜ (λ_. if ¬ per_compare uf a b then let uf = per_union uf a b in ASSERT (ce ∉ set T) ⤜ (λ_. RETURN (uf, T @ [ce])) else RETURN (uf, T))))) (initial_union_find, []) ⤜ (λ(per, spanning_forest). RETURN spanning_forest)))) ∈ unit_assn⇧k →⇩a list_assn (nat_assn ×⇩a int_assn ×⇩a nat_assn)›*) unfolding sort_edges_def[symmetric] (*goal: ‹(uncurry0 ?c, uncurry0 (getEdges ⤜ (λl. RETURN (sort_edges l, max_node l)) ⤜ (λ(sl, mn). let initial_union_find = per_init' (mn + 1) in nfoldli sl (λ_. True) (λce (uf, T). ASSERT (α ce ∈ E) ⤜ (λ_. endpoints ce ⤜ (λ(a, b). ASSERT (a ∈ Domain uf ∧ b ∈ Domain uf) ⤜ (λ_. if ¬ per_compare uf a b then let uf = per_union uf a b in ASSERT (ce ∉ set T) ⤜ (λ_. RETURN (uf, T @ [ce])) else RETURN (uf, T))))) (initial_union_find, []) ⤜ (λ(per, spanning_forest). RETURN spanning_forest)))) ∈ unit_assn⇧k →⇩a list_assn (nat_assn ×⇩a int_assn ×⇩a nat_assn)›*) apply (rewrite at "nfoldli _ _ _ (_,rewrite_HOLE)" HOL_list.fold_custom_empty) (*goal: ‹(uncurry0 ?c, uncurry0 (getEdges ⤜ (λl. RETURN (sort_edges l, max_node l)) ⤜ (λ(sl, mn). let initial_union_find = per_init' (mn + 1) in nfoldli sl (λ_. True) (λce (uf, T). ASSERT (α ce ∈ E) ⤜ (λ_. endpoints ce ⤜ (λ(a, b). ASSERT (a ∈ Domain uf ∧ b ∈ Domain uf) ⤜ (λ_. if ¬ per_compare uf a b then let uf = per_union uf a b in ASSERT (ce ∉ set T) ⤜ (λ_. RETURN (uf, T @ [ce])) else RETURN (uf, T))))) (initial_union_find, []) ⤜ (λ(per, spanning_forest). RETURN spanning_forest)))) ∈ unit_assn⇧k →⇩a list_assn (nat_assn ×⇩a int_assn ×⇩a nat_assn)›*) by sepref concrete_definition (in -) kruskal uses Kruskal_Impl.kruskal_impl prepare_code_thms (in -) kruskal_def lemmas kruskal_refine = kruskal.refine[OF this_loc] abbreviation "MSF == minBasis" abbreviation "SpanningForest == basis" lemmas SpanningForest_def = basis_def lemmas MSF_def = minBasis_def lemmas kruskal3_ref_spec_ = kruskal3_refine[FCOMP kruskal2_refine, FCOMP kruskal1_refine, FCOMP kruskal0_refine, FCOMP minWeightBasis_refine] lemma kruskal3_ref_spec': "(uncurry0 kruskal3, uncurry0 (SPEC (λr. MSF (α ` set r)))) ∈ unit_rel →⇩f ⟨Id⟩nres_rel" unfolding fref_def (*goal: ‹(uncurry0 kruskal3, uncurry0 (SPEC (λr. MSF (α ` set r)))) ∈ {(f, g). ∀x y. True ∧ (x, y) ∈ unit_rel ⟶ (f x, g y) ∈ ⟨Id⟩nres_rel}›*) apply auto (*goal: ‹(uncurry0 kruskal3, uncurry0 (SPEC (λr. MSF (α ` set r)))) ∈ {(f, g). ∀x y. True ∧ (x, y) ∈ unit_rel ⟶ (f x, g y) ∈ ⟨Id⟩nres_rel}›*) apply (rule nres_relI (*‹?c ≤ ⇓ ?R ?a ⟹ (?c, ?a) ∈ ⟨?R⟩nres_rel›*)) (*goal: ‹(kruskal3, SPEC (λr. MSF (α ` set r))) ∈ ⟨Id⟩nres_rel›*) apply (rule order.trans[OF kruskal3_ref_spec_[unfolded fref_def, simplified, THEN nres_relD]] (*‹⇓ (⟨concrete_edge_rel⟩list_set_rel) (SPEC MSF) ≤ ?c ⟹ kruskal3 ≤ ?c›*)) (*goal: ‹kruskal3 ≤ ⇓ Id (SPEC (λr. MSF (α ` set r)))›*) by (auto simp: conc_fun_def (*‹⇓ ?R ?m ≡ case ?m of FAILi ⇒ FAIL | RES X ⇒ RES (?R¯ `` X)›*) list_set_rel_def (*‹⟨?R⟩list_set_rel ≡ ⟨?R⟩list_rel O br set distinct›*) in_br_conv (*‹((?c, ?a) ∈ br ?α ?I) = (?a = ?α ?c ∧ ?I ?c)›*) dest!: list_relD2 (*‹(?x, ?y) ∈ ⟨br ?a ?I⟩list_rel ⟹ ?y = map ?a ?x ∧ (∀x∈set ?x. ?I x)›*)) lemma kruskal3_ref_spec: "(uncurry0 kruskal3, uncurry0 (SPEC (λr. distinct r ∧ set r ⊆ superE ∧ MSF (α ` set r)))) ∈ unit_rel →⇩f ⟨Id⟩nres_rel" unfolding fref_def (*goal: ‹(uncurry0 kruskal3, uncurry0 (SPEC (λr. distinct r ∧ set r ⊆ superE ∧ MSF (α ` set r)))) ∈ {(f, g). ∀x y. True ∧ (x, y) ∈ unit_rel ⟶ (f x, g y) ∈ ⟨Id⟩nres_rel}›*) apply auto (*goal: ‹(uncurry0 kruskal3, uncurry0 (SPEC (λr. distinct r ∧ set r ⊆ superE ∧ MSF (α ` set r)))) ∈ {(f, g). ∀x y. True ∧ (x, y) ∈ unit_rel ⟶ (f x, g y) ∈ ⟨Id⟩nres_rel}›*) apply (rule nres_relI (*‹?c ≤ ⇓ ?R ?a ⟹ (?c, ?a) ∈ ⟨?R⟩nres_rel›*)) (*goal: ‹(kruskal3, SPEC (λr. distinct r ∧ set r ⊆ superE ∧ MSF (α ` set r))) ∈ ⟨Id⟩nres_rel›*) apply simp (*goal: ‹kruskal3 ≤ ⇓ Id (SPEC (λr. distinct r ∧ set r ⊆ superE ∧ MSF (α ` set r)))›*) using SPEC_rule_conj_leofI2[OF kruskal3_subset kruskal3_ref_spec' [ unfolded fref_def , simplified , THEN nres_relD , simplified ]] (*‹kruskal3 ≤ SPEC (λs. (distinct s ∧ set s ⊆ superE) ∧ MSF (α ` set s))›*) by simp lemma [fcomp_norm_simps]: "list_assn (nat_assn ×⇩a int_assn ×⇩a nat_assn) = id_assn" by (auto simp: list_assn_pure_conv (*‹list_assn (pure ?R) = pure (⟨?R⟩list_rel)›*)) lemmas kruskal_ref_spec = kruskal_refine[FCOMP kruskal3_ref_spec] text ‹The final correctness lemma for Kruskal's algorithm. › lemma kruskal_correct_forest: shows "<emp> kruskal getEdges_impl endpoints_impl () <λr. ↑( distinct r ∧ set r ⊆ superE ∧ MSF (set (map α r)))>⇩t" proof (-) (*goal: ‹<emp> kruskal getEdges_impl endpoints_impl () <λr. ↑ (distinct r ∧ set r ⊆ superE ∧ MSF (set (map α r)))>⇩t›*) show "?thesis" (*goal: ‹<emp> kruskal (getEdges_impl::(nat × int × nat) list Heap) (endpoints_impl::nat × int × nat ⇒ (nat × nat) Heap) () <λr::(nat × int × nat) list. ↑ (distinct r ∧ set r ⊆ (superE::(nat × int × nat) set) ∧ MSF (set (map (α::nat × int × nat ⇒ 'edge::type) r)))>⇩t›*) using kruskal_ref_spec[to_hnr] (*‹hn_refine emp (kruskal getEdges_impl endpoints_impl $ ?xi) emp id_assn (SPEC (λr. distinct r ∧ set r ⊆ superE ∧ MSF (α ` set r)))›*) unfolding hn_refine_def (*goal: ‹<emp> kruskal getEdges_impl endpoints_impl () <λr. ↑ (distinct r ∧ set r ⊆ superE ∧ MSF (set (map α r)))>⇩t›*) apply clarsimp (*goal: ‹<emp> kruskal getEdges_impl endpoints_impl () <λr. ↑ (distinct r ∧ set r ⊆ superE ∧ MSF (set (map α r)))>⇩t›*) apply (erule cons_post_rule (*‹⟦<?P> ?c <?Q>; ⋀x. ?Q x ⟹⇩A ?Q' x⟧ ⟹ <?P> ?c <?Q'>›*)) (*goal: ‹<emp> kruskal getEdges_impl endpoints_impl () <λr. ∃⇩Ax. id_assn x r * true * ↑ (distinct x ∧ set x ⊆ superE ∧ MSF (α ` set x))> ⟹ <emp> kruskal getEdges_impl endpoints_impl () <λr. true * ↑ (distinct r ∧ set r ⊆ superE ∧ MSF (α ` set r))>›*) by (sep_auto simp: hn_ctxt_def pure_def list_set_rel_def in_br_conv dest: list_relD) qed end ― ‹locale @{text Kruskal_Impl}› end
{ "path": "afp-2025-02-12/thys/Kruskal/Kruskal_Impl.thy", "repo": "afp-2025-02-12", "sha": "7992eae3c1d5cd874a146b9e867f47bbc7c491eeeaa885f217fa6c636d975b7b" }
(* Author: Alexander Katovsky *) section "Category" theory Category imports "HOL-Library.FuncSet" begin record ('o,'m) Category = Obj :: "'o set" ("objı" 70) Mor :: "'m set" ("morı" 70) Dom :: "'m ⇒ 'o" ("domı _" [80] 70) Cod :: "'m ⇒ 'o" ("codı _" [80] 70) Id :: "'o ⇒ 'm" ("idı _" [80] 75) Comp :: "'m ⇒ 'm ⇒ 'm" (infixl ";;ı" 70) definition MapsTo :: "('o,'m,'a) Category_scheme ⇒ 'm ⇒ 'o ⇒ 'o ⇒ bool" ("_ mapsı _ to _" [60, 60, 60] 65) where "MapsTo CC f X Y ≡ f ∈ Mor CC ∧ Dom CC f = X ∧ Cod CC f = Y" definition CompDefined :: "('o,'m,'a) Category_scheme ⇒ 'm ⇒ 'm ⇒ bool" (infixl "≈>ı" 65) where "CompDefined CC f g ≡ f ∈ Mor CC ∧ g ∈ Mor CC ∧ Cod CC f = Dom CC g" locale ExtCategory = fixes C :: "('o,'m,'a) Category_scheme" (structure) assumes CdomExt: "(Dom C) ∈ extensional (Mor C)" and CcodExt: "(Cod C) ∈ extensional (Mor C)" and CidExt: "(Id C) ∈ extensional (Obj C)" and CcompExt: "(case_prod (Comp C)) ∈ extensional ({(f,g) | f g . f ≈> g})" locale Category = ExtCategory + assumes Cdom : "f ∈ mor ⟹ dom f ∈ obj" and Ccod : "f ∈ mor ⟹ cod f ∈ obj" and Cidm [dest]: "X ∈ obj ⟹ (id X) maps X to X" and Cidl : "f ∈ mor ⟹ id (dom f) ;; f = f" and Cidr : "f ∈ mor ⟹ f ;; id (cod f) = f" and Cassoc : "⟦f ≈> g ; g ≈> h⟧ ⟹ (f ;; g) ;; h = f ;; (g ;; h)" and Ccompt : "⟦f maps X to Y ; g maps Y to Z⟧ ⟹ (f ;; g) maps X to Z" definition MakeCat :: "('o,'m,'a) Category_scheme ⇒ ('o,'m,'a) Category_scheme" where "MakeCat C ≡ ⦇ Obj = Obj C , Mor = Mor C , Dom = restrict (Dom C) (Mor C) , Cod = restrict (Cod C) (Mor C) , Id = restrict (Id C) (Obj C) , Comp = λ f g . (restrict (case_prod (Comp C)) ({(f,g) | f g . f ≈>⇘C⇙ g})) (f,g), … = Category.more C ⦈" lemma MakeCatMapsTo: "f maps⇘C⇙ X to Y ⟹ f maps⇘MakeCat C⇙ X to Y" by (auto simp add: MapsTo_def (*‹?f maps⇘?CC⇙ ?X to ?Y ≡ ?f ∈ mor⇘?CC⇙ ∧ dom⇘?CC⇙ ?f = ?X ∧ cod⇘?CC⇙ ?f = ?Y›*) MakeCat_def (*‹MakeCat ?C ≡ ⦇Obj = obj⇘?C⇙, Mor = mor⇘?C⇙, Dom = restrict (Dom ?C) (mor⇘?C⇙), Cod = restrict (Cod ?C) (mor⇘?C⇙), Id = restrict (Category.Id ?C) (obj⇘?C⇙), Comp = λf g. (λ(x, y)∈{(f, g) |f g. f ≈>⇘?C⇙ g}. x ;;⇘?C⇙ y) (f, g), … = more ?C⦈›*)) lemma MakeCatComp: "f ≈>⇘C⇙ g ⟹ f ;;⇘MakeCat C⇙ g = f ;;⇘C⇙ g" by (auto simp add: MapsTo_def (*‹?f maps⇘?CC⇙ ?X to ?Y ≡ ?f ∈ mor⇘?CC⇙ ∧ dom⇘?CC⇙ ?f = ?X ∧ cod⇘?CC⇙ ?f = ?Y›*) MakeCat_def (*‹MakeCat ?C ≡ ⦇Obj = obj⇘?C⇙, Mor = mor⇘?C⇙, Dom = restrict (Dom ?C) (mor⇘?C⇙), Cod = restrict (Cod ?C) (mor⇘?C⇙), Id = restrict (Category.Id ?C) (obj⇘?C⇙), Comp = λf g. (λ(x, y)∈{(f, g) |f g. f ≈>⇘?C⇙ g}. x ;;⇘?C⇙ y) (f, g), … = more ?C⦈›*)) lemma MakeCatId: "X ∈ obj⇘C⇙ ⟹ id⇘C⇙ X = id⇘MakeCat C⇙ X" by (auto simp add: MapsTo_def (*‹?f maps⇘?CC⇙ ?X to ?Y ≡ ?f ∈ mor⇘?CC⇙ ∧ dom⇘?CC⇙ ?f = ?X ∧ cod⇘?CC⇙ ?f = ?Y›*) MakeCat_def (*‹MakeCat ?C ≡ ⦇Obj = obj⇘?C⇙, Mor = mor⇘?C⇙, Dom = restrict (Dom ?C) (mor⇘?C⇙), Cod = restrict (Cod ?C) (mor⇘?C⇙), Id = restrict (Category.Id ?C) (obj⇘?C⇙), Comp = λf g. (λ(x, y)∈{(f, g) |f g. f ≈>⇘?C⇙ g}. x ;;⇘?C⇙ y) (f, g), … = more ?C⦈›*)) lemma MakeCatObj: "obj⇘MakeCat C⇙ = obj⇘C⇙" by (simp add: MakeCat_def (*‹MakeCat ?C ≡ ⦇Obj = obj⇘?C⇙, Mor = mor⇘?C⇙, Dom = restrict (Dom ?C) (mor⇘?C⇙), Cod = restrict (Cod ?C) (mor⇘?C⇙), Id = restrict (Category.Id ?C) (obj⇘?C⇙), Comp = λf g. (λ(x, y)∈{(f, g) |f g. f ≈>⇘?C⇙ g}. x ;;⇘?C⇙ y) (f, g), … = more ?C⦈›*)) lemma MakeCatMor: "mor⇘MakeCat C⇙ = mor⇘C⇙" by (simp add: MakeCat_def (*‹MakeCat ?C ≡ ⦇Obj = obj⇘?C⇙, Mor = mor⇘?C⇙, Dom = restrict (Dom ?C) (mor⇘?C⇙), Cod = restrict (Cod ?C) (mor⇘?C⇙), Id = restrict (Category.Id ?C) (obj⇘?C⇙), Comp = λf g. (λ(x, y)∈{(f, g) |f g. f ≈>⇘?C⇙ g}. x ;;⇘?C⇙ y) (f, g), … = more ?C⦈›*)) lemma MakeCatDom: "f ∈ mor⇘C⇙ ⟹ dom⇘C⇙ f = dom⇘MakeCat C⇙ f" by (simp add: MakeCat_def (*‹MakeCat ?C ≡ ⦇Obj = obj⇘?C⇙, Mor = mor⇘?C⇙, Dom = restrict (Dom ?C) (mor⇘?C⇙), Cod = restrict (Cod ?C) (mor⇘?C⇙), Id = restrict (Category.Id ?C) (obj⇘?C⇙), Comp = λf g. (λ(x, y)∈{(f, g) |f g. f ≈>⇘?C⇙ g}. x ;;⇘?C⇙ y) (f, g), … = more ?C⦈›*)) lemma MakeCatCod: "f ∈ mor⇘C⇙ ⟹ cod⇘C⇙ f = cod⇘MakeCat C⇙ f" by (simp add: MakeCat_def (*‹MakeCat ?C ≡ ⦇Obj = obj⇘?C⇙, Mor = mor⇘?C⇙, Dom = restrict (Dom ?C) (mor⇘?C⇙), Cod = restrict (Cod ?C) (mor⇘?C⇙), Id = restrict (Category.Id ?C) (obj⇘?C⇙), Comp = λf g. (λ(x, y)∈{(f, g) |f g. f ≈>⇘?C⇙ g}. x ;;⇘?C⇙ y) (f, g), … = more ?C⦈›*)) lemma MakeCatCompDef: "f ≈>⇘MakeCat C⇙ g = f ≈>⇘C⇙ g" by (auto simp add: CompDefined_def (*‹?f ≈>⇘?CC⇙ ?g ≡ ?f ∈ mor⇘?CC⇙ ∧ ?g ∈ mor⇘?CC⇙ ∧ cod⇘?CC⇙ ?f = dom⇘?CC⇙ ?g›*) MakeCat_def (*‹MakeCat ?C ≡ ⦇Obj = obj⇘?C⇙, Mor = mor⇘?C⇙, Dom = restrict (Dom ?C) (mor⇘?C⇙), Cod = restrict (Cod ?C) (mor⇘?C⇙), Id = restrict (Category.Id ?C) (obj⇘?C⇙), Comp = λf g. (λ(x, y)∈{(f, g) |f g. f ≈>⇘?C⇙ g}. x ;;⇘?C⇙ y) (f, g), … = more ?C⦈›*)) lemma MakeCatComp2: "f ≈>⇘MakeCat C⇙ g ⟹ f ;;⇘MakeCat C⇙ g = f ;;⇘C⇙ g" by (simp add: MakeCatCompDef (*‹?f ≈>⇘MakeCat ?C⇙ ?g = ?f ≈>⇘?C⇙ ?g›*) MakeCatComp (*‹?f ≈>⇘?C⇙ ?g ⟹ ?f ;;⇘MakeCat ?C⇙ ?g = ?f ;;⇘?C⇙ ?g›*)) lemma ExtCategoryMakeCat: "ExtCategory (MakeCat C)" apply unfold_locales (*goals: 1. ‹Dom (MakeCat C) ∈ extensional (mor⇘MakeCat C⇙)› 2. ‹Cod (MakeCat C) ∈ extensional (mor⇘MakeCat C⇙)› 3. ‹Category.Id (MakeCat C) ∈ extensional (obj⇘MakeCat C⇙)› 4. ‹(λ(x, y). x ;;⇘MakeCat C⇙ y) ∈ extensional {(f, g) |f g. f ≈>⇘MakeCat C⇙ g}› discuss goal 1*) apply (simp add: MakeCat_def (*‹MakeCat ?C ≡ ⦇Obj = obj⇘?C⇙, Mor = mor⇘?C⇙, Dom = restrict (Dom ?C) (mor⇘?C⇙), Cod = restrict (Cod ?C) (mor⇘?C⇙), Id = restrict (Category.Id ?C) (obj⇘?C⇙), Comp = λf g. (λ(x, y)∈{(f, g) |f g. f ≈>⇘?C⇙ g}. x ;;⇘?C⇙ y) (f, g), … = more ?C⦈›*) extensional_def (*‹extensional ?A = {f. ∀x. x ∉ ?A ⟶ f x = undefined}›*) CompDefined_def (*‹?f ≈>⇘?CC⇙ ?g ≡ ?f ∈ mor⇘?CC⇙ ∧ ?g ∈ mor⇘?CC⇙ ∧ cod⇘?CC⇙ ?f = dom⇘?CC⇙ ?g›*)) (*discuss goal 2*) apply (simp add: MakeCat_def (*‹MakeCat ?C ≡ ⦇Obj = obj⇘?C⇙, Mor = mor⇘?C⇙, Dom = restrict (Dom ?C) (mor⇘?C⇙), Cod = restrict (Cod ?C) (mor⇘?C⇙), Id = restrict (Category.Id ?C) (obj⇘?C⇙), Comp = λf g. (λ(x, y)∈{(f, g) |f g. f ≈>⇘?C⇙ g}. x ;;⇘?C⇙ y) (f, g), … = more ?C⦈›*) extensional_def (*‹extensional ?A = {f. ∀x. x ∉ ?A ⟶ f x = undefined}›*) CompDefined_def (*‹?f ≈>⇘?CC⇙ ?g ≡ ?f ∈ mor⇘?CC⇙ ∧ ?g ∈ mor⇘?CC⇙ ∧ cod⇘?CC⇙ ?f = dom⇘?CC⇙ ?g›*)) (*discuss goal 3*) apply (simp add: MakeCat_def (*‹MakeCat ?C ≡ ⦇Obj = obj⇘?C⇙, Mor = mor⇘?C⇙, Dom = restrict (Dom ?C) (mor⇘?C⇙), Cod = restrict (Cod ?C) (mor⇘?C⇙), Id = restrict (Category.Id ?C) (obj⇘?C⇙), Comp = λf g. (λ(x, y)∈{(f, g) |f g. f ≈>⇘?C⇙ g}. x ;;⇘?C⇙ y) (f, g), … = more ?C⦈›*) extensional_def (*‹extensional ?A = {f. ∀x. x ∉ ?A ⟶ f x = undefined}›*) CompDefined_def (*‹?f ≈>⇘?CC⇙ ?g ≡ ?f ∈ mor⇘?CC⇙ ∧ ?g ∈ mor⇘?CC⇙ ∧ cod⇘?CC⇙ ?f = dom⇘?CC⇙ ?g›*)) (*discuss goal 4*) apply (simp add: MakeCat_def (*‹MakeCat ?C ≡ ⦇Obj = obj⇘?C⇙, Mor = mor⇘?C⇙, Dom = restrict (Dom ?C) (mor⇘?C⇙), Cod = restrict (Cod ?C) (mor⇘?C⇙), Id = restrict (Category.Id ?C) (obj⇘?C⇙), Comp = λf g. (λ(x, y)∈{(f, g) |f g. f ≈>⇘?C⇙ g}. x ;;⇘?C⇙ y) (f, g), … = more ?C⦈›*) extensional_def (*‹extensional ?A = {f. ∀x. x ∉ ?A ⟶ f x = undefined}›*) CompDefined_def (*‹?f ≈>⇘?CC⇙ ?g ≡ ?f ∈ mor⇘?CC⇙ ∧ ?g ∈ mor⇘?CC⇙ ∧ cod⇘?CC⇙ ?f = dom⇘?CC⇙ ?g›*)) (*proven 4 subgoals*) . lemma MakeCat: "Category_axioms C ⟹ Category (MakeCat C)" apply intro_locales (*goals: 1. ‹Category_axioms C ⟹ ExtCategory (MakeCat C)› 2. ‹Category_axioms C ⟹ Category_axioms (MakeCat C)› discuss goal 1*) apply (simp add: ExtCategoryMakeCat (*‹ExtCategory (MakeCat ?C)›*)) (*discuss goal 2*) apply (simp add: Category_axioms_def (*‹Category_axioms ?C ≡ ((∀f. f ∈ mor⇘?C⇙ ⟶ dom⇘?C⇙ f ∈ obj⇘?C⇙) ∧ (∀f. f ∈ mor⇘?C⇙ ⟶ cod⇘?C⇙ f ∈ obj⇘?C⇙) ∧ (∀X. X ∈ obj⇘?C⇙ ⟶ id⇘?C⇙ X maps⇘?C⇙ X to X)) ∧ ((∀f. f ∈ mor⇘?C⇙ ⟶ id⇘?C⇙ (dom⇘?C⇙ f) ;;⇘?C⇙ f = f) ∧ (∀f. f ∈ mor⇘?C⇙ ⟶ f ;;⇘?C⇙ id⇘?C⇙ (cod⇘?C⇙ f) = f)) ∧ (∀f g h. f ≈>⇘?C⇙ g ⟶ g ≈>⇘?C⇙ h ⟶ f ;;⇘?C⇙ g ;;⇘?C⇙ h = f ;;⇘?C⇙ (g ;;⇘?C⇙ h)) ∧ (∀f X Y g Z. f maps⇘?C⇙ X to Y ⟶ g maps⇘?C⇙ Y to Z ⟶ f ;;⇘?C⇙ g maps⇘?C⇙ X to Z)›*)) (*goal: ‹Category_axioms C ⟹ Category_axioms (MakeCat C)›*) apply (auto simp add: MakeCat_def (*‹MakeCat ?C ≡ ⦇Obj = obj⇘?C⇙, Mor = mor⇘?C⇙, Dom = restrict (Dom ?C) (mor⇘?C⇙), Cod = restrict (Cod ?C) (mor⇘?C⇙), Id = restrict (Category.Id ?C) (obj⇘?C⇙), Comp = λf g. (λ(x, y)∈{(f, g) |f g. f ≈>⇘?C⇙ g}. x ;;⇘?C⇙ y) (f, g), … = more ?C⦈›*) CompDefined_def (*‹?f ≈>⇘?CC⇙ ?g ≡ ?f ∈ mor⇘?CC⇙ ∧ ?g ∈ mor⇘?CC⇙ ∧ cod⇘?CC⇙ ?f = dom⇘?CC⇙ ?g›*) MapsTo_def (*‹?f maps⇘?CC⇙ ?X to ?Y ≡ ?f ∈ mor⇘?CC⇙ ∧ dom⇘?CC⇙ ?f = ?X ∧ cod⇘?CC⇙ ?f = ?Y›*)) (*proven 2 subgoals*) . lemma MapsToE[elim]: "⟦f maps⇘C⇙ X to Y ; ⟦f ∈ mor⇘C⇙ ; dom⇘C⇙ f = X ; cod⇘C⇙ f = Y⟧ ⟹ R⟧ ⟹ R" by (auto simp add: MapsTo_def (*‹?f maps⇘?CC⇙ ?X to ?Y ≡ ?f ∈ mor⇘?CC⇙ ∧ dom⇘?CC⇙ ?f = ?X ∧ cod⇘?CC⇙ ?f = ?Y›*)) lemma MapsToI[intro]: "⟦f ∈ mor⇘C⇙ ; dom⇘C⇙ f = X ; cod⇘C⇙ f = Y⟧ ⟹ f maps⇘C⇙ X to Y" by (auto simp add: MapsTo_def (*‹?f maps⇘?CC⇙ ?X to ?Y ≡ ?f ∈ mor⇘?CC⇙ ∧ dom⇘?CC⇙ ?f = ?X ∧ cod⇘?CC⇙ ?f = ?Y›*)) lemma CompDefinedE[elim]: "⟦f ≈>⇘C⇙ g ; ⟦f ∈ mor⇘C⇙ ; g ∈ mor⇘C⇙ ; cod⇘C⇙ f = dom⇘C⇙ g⟧ ⟹ R⟧ ⟹ R" by (auto simp add: CompDefined_def (*‹?f ≈>⇘?CC⇙ ?g ≡ ?f ∈ mor⇘?CC⇙ ∧ ?g ∈ mor⇘?CC⇙ ∧ cod⇘?CC⇙ ?f = dom⇘?CC⇙ ?g›*)) lemma CompDefinedI[intro]: "⟦f ∈ mor⇘C⇙ ; g ∈ mor⇘C⇙ ; cod⇘C⇙ f = dom⇘C⇙ g⟧ ⟹ f ≈>⇘C⇙ g" by (auto simp add: CompDefined_def (*‹?f ≈>⇘?CC⇙ ?g ≡ ?f ∈ mor⇘?CC⇙ ∧ ?g ∈ mor⇘?CC⇙ ∧ cod⇘?CC⇙ ?f = dom⇘?CC⇙ ?g›*)) lemma (in Category) MapsToCompI: assumes "f ≈> g" shows "(f ;; g) maps (dom f) to (cod g)" proof (-) (*goal: ‹f ;; g maps dom f to cod g›*) have "f maps (dom f) to (dom g)" and "g maps (dom g) to (cod g)" using assms (*‹f ≈> g›*) apply - (*goals: 1. ‹f ≈> g ⟹ f maps dom f to dom g› 2. ‹f ≈> g ⟹ g maps dom g to cod g› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . thus "?thesis" (*goal: ‹f ;; g maps dom f to cod g›*) by (simp add: Ccompt[of f "dom f" "dom g" g "cod g"] (*‹⟦f maps dom f to dom g; g maps dom g to cod g⟧ ⟹ f ;; g maps dom f to cod g›*)) qed lemma MapsToCompDef: assumes "f maps⇘C⇙ X to Y" and "g maps⇘C⇙ Y to Z" shows "f ≈>⇘C⇙ g" proof (rule CompDefinedI (*‹⟦?f ∈ mor⇘?C⇙; ?g ∈ mor⇘?C⇙; cod⇘?C⇙ ?f = dom⇘?C⇙ ?g⟧ ⟹ ?f ≈>⇘?C⇙ ?g›*)) (*goals: 1. ‹f ∈ mor⇘C⇙› 2. ‹g ∈ mor⇘C⇙› 3. ‹cod⇘C⇙ f = dom⇘C⇙ g›*) show "f ∈ mor⇘C⇙" and "g ∈ mor⇘C⇙" using assms (*‹f maps⇘C⇙ X to Y› ‹g maps⇘C⇙ Y to Z›*) apply - (*goals: 1. ‹⟦f maps⇘C⇙ X to Y; g maps⇘C⇙ Y to Z⟧ ⟹ f ∈ mor⇘C⇙› 2. ‹⟦f maps⇘C⇙ X to Y; g maps⇘C⇙ Y to Z⟧ ⟹ g ∈ mor⇘C⇙› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have "cod⇘C⇙ f = Y" and "dom⇘C⇙ g = Y" using assms (*‹f maps⇘C⇙ X to Y› ‹g maps⇘C⇙ Y to Z›*) apply - (*goals: 1. ‹⟦f maps⇘C⇙ X to Y; g maps⇘C⇙ Y to Z⟧ ⟹ cod⇘C⇙ f = Y› 2. ‹⟦f maps⇘C⇙ X to Y; g maps⇘C⇙ Y to Z⟧ ⟹ dom⇘C⇙ g = Y› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . thus "cod⇘C⇙ f = dom⇘C⇙ g" by simp qed lemma (in Category) MapsToMorDomCod: assumes "f ≈> g" shows "f ;; g ∈ mor" and "dom (f ;; g) = dom f" and "cod (f ;; g) = cod g" proof (-) (*goals: 1. ‹f ;; g ∈ mor› 2. ‹dom (f ;; g) = dom f› 3. ‹cod (f ;; g) = cod g›*) have "(f ;; g) maps (dom f) to (cod g)" using assms (*‹f ≈> g›*) by (simp add: MapsToCompI (*‹(?f::'b::type) ≈> (?g::'b::type) ⟹ ?f ;; ?g maps dom ?f to cod ?g›*)) thus "f ;; g ∈ mor" and "dom (f ;; g) = dom f" and "cod (f ;; g) = cod g" apply - (*goals: 1. ‹f ;; g maps dom f to cod g ⟹ f ;; g ∈ mor› 2. ‹f ;; g maps dom f to cod g ⟹ dom (f ;; g) = dom f› 3. ‹f ;; g maps dom f to cod g ⟹ cod (f ;; g) = cod g› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . qed lemma (in Category) MapsToObj: assumes "f maps X to Y" shows "X ∈ obj" and "Y ∈ obj" proof (-) (*goals: 1. ‹X ∈ obj› 2. ‹Y ∈ obj›*) have "dom f = X" and "cod f = Y" and "f ∈ mor" using assms (*‹f maps X to Y›*) apply - (*goals: 1. ‹f maps X to Y ⟹ dom f = X› 2. ‹f maps X to Y ⟹ cod f = Y› 3. ‹f maps X to Y ⟹ f ∈ mor› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . thus "X ∈ obj" and "Y ∈ obj" apply - (*goals: 1. ‹⟦dom f = X; cod f = Y; f ∈ mor⟧ ⟹ X ∈ obj› 2. ‹⟦dom f = X; cod f = Y; f ∈ mor⟧ ⟹ Y ∈ obj› discuss goal 1*) apply ((auto simp add: Cdom (*‹?f ∈ mor ⟹ dom ?f ∈ obj›*) Ccod (*‹?f ∈ mor ⟹ cod ?f ∈ obj›*))[1]) (*discuss goal 2*) apply ((auto simp add: Cdom (*‹?f ∈ mor ⟹ dom ?f ∈ obj›*) Ccod (*‹?f ∈ mor ⟹ cod ?f ∈ obj›*))[1]) (*proven 2 subgoals*) . qed lemma (in Category) IdInj: assumes "X ∈ obj" and "Y ∈ obj" and "id X = id Y" shows "X = Y" proof (-) (*goal: ‹X = Y›*) have "dom (id X) = dom (id Y)" using assms (*‹X ∈ obj› ‹Y ∈ obj› ‹id (X::'a::type) = id (Y::'a::type)›*) by simp moreover have "dom (id X) = X" and "dom (id Y) = Y" using assms (*‹(X::'a) ∈ obj› ‹Y ∈ obj› ‹id X = id Y›*) apply - (*goals: 1. ‹⟦X ∈ obj; Y ∈ obj; id X = id Y⟧ ⟹ dom (id X) = X› 2. ‹⟦X ∈ obj; Y ∈ obj; id X = id Y⟧ ⟹ dom (id Y) = Y› discuss goal 1*) apply ((auto simp add: MapsTo_def (*‹?f maps⇘?CC⇙ ?X to ?Y ≡ ?f ∈ mor⇘?CC⇙ ∧ dom⇘?CC⇙ ?f = ?X ∧ cod⇘?CC⇙ ?f = ?Y›*))[1]) (*discuss goal 2*) apply ((auto simp add: MapsTo_def (*‹(?f::?'m) maps⇘?CC::(?'o, ?'m, ?'a) Category_scheme⇙ (?X::?'o) to (?Y::?'o) ≡ ?f ∈ mor⇘?CC⇙ ∧ dom⇘?CC⇙ ?f = ?X ∧ cod⇘?CC⇙ ?f = ?Y›*))[1]) (*proven 2 subgoals*) . ultimately show "?thesis" (*goal: ‹X = Y›*) by simp qed lemma (in Category) CompDefComp: assumes "f ≈> g" and "g ≈> h" shows "f ≈> (g ;; h)" and "(f ;; g) ≈> h" proof (auto simp add: CompDefined_def (*‹?f ≈>⇘?CC⇙ ?g ≡ ?f ∈ mor⇘?CC⇙ ∧ ?g ∈ mor⇘?CC⇙ ∧ cod⇘?CC⇙ ?f = dom⇘?CC⇙ ?g›*)) (*goals: 1. ‹f ∈ mor› 2. ‹g ;; h ∈ mor› 3. ‹cod f = dom (g ;; h)› 4. ‹f ;; g ∈ mor› 5. ‹h ∈ mor› 6. ‹cod (f ;; g) = dom h›*) show "f ∈ mor" and "h ∈ mor" using assms (*‹f ≈> g› ‹(g::'b) ≈> (h::'b)›*) apply - (*goals: 1. ‹⟦(f::'b::type) ≈> (g::'b::type); g ≈> (h::'b::type)⟧ ⟹ f ∈ mor› 2. ‹⟦(f::'b::type) ≈> (g::'b::type); g ≈> (h::'b::type)⟧ ⟹ h ∈ mor› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have 1: "g ;; h maps (dom g) to (cod h)" and 2: "f ;; g maps (dom f) to (cod g)" using assms (*‹f ≈> g› ‹g ≈> h›*) apply - (*goals: 1. ‹⟦f ≈> g; g ≈> h⟧ ⟹ g ;; h maps dom g to cod h› 2. ‹⟦f ≈> g; g ≈> h⟧ ⟹ f ;; g maps dom f to cod g› discuss goal 1*) apply (simp add: MapsToCompI (*‹?f ≈> ?g ⟹ ?f ;; ?g maps dom ?f to cod ?g›*)) (*discuss goal 2*) apply (simp add: MapsToCompI (*‹?f ≈> ?g ⟹ ?f ;; ?g maps dom ?f to cod ?g›*)) (*proven 2 subgoals*) . thus "g ;; h ∈ mor" and "f ;; g ∈ mor" apply - (*goals: 1. ‹⟦g ;; h maps dom g to cod h; f ;; g maps dom f to cod g⟧ ⟹ g ;; h ∈ mor› 2. ‹⟦g ;; h maps dom g to cod h; f ;; g maps dom f to cod g⟧ ⟹ f ;; g ∈ mor› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have "cod f = dom g" using assms (*‹f ≈> g› ‹(g::'b) ≈> (h::'b)›*) by auto also (*calculation: ‹cod (f::'b) = dom (g::'b)›*) have "... = dom (g ;; h)" using "1" (*‹(g::'b) ;; (h::'b) maps dom g to cod h›*) by auto finally (*calculation: ‹cod (f::'b) = dom ((g::'b) ;; (h::'b))›*) show "cod f = dom (g ;; h)" . have "dom h = cod g" using assms (*‹f ≈> g› ‹g ≈> h›*) by auto also (*calculation: ‹dom h = cod g›*) have "... = cod (f ;; g)" using "2" (*‹f ;; g maps dom f to cod g›*) by auto finally (*calculation: ‹dom (h::'b) = cod ((f::'b) ;; (g::'b))›*) show "cod (f ;; g) = dom h" by simp qed lemma (in Category) CatIdInMor: "X ∈ obj ⟹ id X ∈ mor" by (auto simp add: Cidm (*‹(?X::'a) ∈ obj ⟹ id ?X maps ?X to ?X›*)) lemma (in Category) MapsToId: assumes "X ∈ obj" shows "id X ≈> id X" proof (rule CompDefinedI (*‹⟦?f ∈ mor⇘?C⇙; ?g ∈ mor⇘?C⇙; cod⇘?C⇙ ?f = dom⇘?C⇙ ?g⟧ ⟹ ?f ≈>⇘?C⇙ ?g›*)) (*goals: 1. ‹id X ∈ mor› 2. ‹id X ∈ mor› 3. ‹cod (id X) = dom (id X)›*) have "id X maps X to X" using assms (*‹(X::'a::type) ∈ obj›*) by (simp add: Cidm (*‹?X ∈ obj ⟹ id ?X maps ?X to ?X›*)) thus "id X ∈ mor" and "id X ∈ mor" and "cod (id X) = dom (id X)" apply - (*goals: 1. ‹id X maps X to X ⟹ id X ∈ mor› 2. ‹id X maps X to X ⟹ id X ∈ mor› 3. ‹id X maps X to X ⟹ cod (id X) = dom (id X)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . qed lemmas (in Category) Simps = Cdom Ccod Cidm Cidl Cidr MapsToCompI IdInj MapsToId lemma (in Category) LeftRightInvUniq: assumes 0: "h ≈> f" and z: "f ≈> g" assumes 1: "f ;; g = id (dom f)" and 2: "h ;; f = id (cod f)" shows "h = g" proof (-) (*goal: ‹h = g›*) have mor: "h ∈ mor ∧ g ∈ mor" and dc: "dom f = cod h ∧ cod f = dom g" using "0" (*‹h ≈> f›*) z (*‹f ≈> g›*) apply - (*goals: 1. ‹⟦h ≈> f; f ≈> g⟧ ⟹ h ∈ mor ∧ g ∈ mor› 2. ‹⟦h ≈> f; f ≈> g⟧ ⟹ dom f = cod h ∧ cod f = dom g› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . then have "h = h ;; id (dom f)" by (auto simp add: Simps (*‹?f ∈ mor ⟹ dom ?f ∈ obj› ‹?f ∈ mor ⟹ cod ?f ∈ obj› ‹?X ∈ obj ⟹ id ?X maps ?X to ?X› ‹?f ∈ mor ⟹ id (dom ?f) ;; ?f = ?f› ‹?f ∈ mor ⟹ ?f ;; id (cod ?f) = ?f› ‹?f ≈> ?g ⟹ ?f ;; ?g maps dom ?f to cod ?g› ‹⟦?X ∈ obj; ?Y ∈ obj; id ?X = id ?Y⟧ ⟹ ?X = ?Y› ‹?X ∈ obj ⟹ id ?X ≈> id ?X›*)) also (*calculation: ‹h = h ;; id (dom f)›*) have "... = h ;; (f ;; g)" using "1" (*‹f ;; g = id (dom f)›*) by simp also (*calculation: ‹h = h ;; (f ;; g)›*) have "... = (h ;; f) ;; g" using "0" (*‹h ≈> f›*) z (*‹f ≈> g›*) by (simp add: Cassoc (*‹⟦?f ≈> ?g; ?g ≈> ?h⟧ ⟹ ?f ;; ?g ;; ?h = ?f ;; (?g ;; ?h)›*)) also (*calculation: ‹(h::'b::type) = h ;; (f::'b::type) ;; (g::'b::type)›*) have "... = (id (cod f)) ;; g" using "2" (*‹(h::'b::type) ;; (f::'b::type) = id (cod f)›*) by simp also (*calculation: ‹h = id (cod f) ;; g›*) have "... = g" using mor (*‹h ∈ mor ∧ g ∈ mor›*) dc (*‹dom f = cod h ∧ cod f = dom g›*) by (auto simp add: Simps (*‹?f ∈ mor ⟹ dom ?f ∈ obj› ‹?f ∈ mor ⟹ cod ?f ∈ obj› ‹?X ∈ obj ⟹ id ?X maps ?X to ?X› ‹?f ∈ mor ⟹ id (dom ?f) ;; ?f = ?f› ‹?f ∈ mor ⟹ ?f ;; id (cod ?f) = ?f› ‹?f ≈> ?g ⟹ ?f ;; ?g maps dom ?f to cod ?g› ‹⟦?X ∈ obj; ?Y ∈ obj; id ?X = id ?Y⟧ ⟹ ?X = ?Y› ‹?X ∈ obj ⟹ id ?X ≈> id ?X›*)) finally (*calculation: ‹(h::'b) = (g::'b)›*) show "?thesis" (*goal: ‹h = g›*) . qed lemma (in Category) CatIdDomCod: assumes "X ∈ obj" shows "dom (id X) = X" and "cod (id X) = X" proof (-) (*goals: 1. ‹dom (id X) = X› 2. ‹cod (id X) = X›*) have "id X maps X to X" using assms (*‹(X::'a::type) ∈ obj›*) by (simp add: Simps (*‹?f ∈ mor ⟹ dom ?f ∈ obj› ‹?f ∈ mor ⟹ cod ?f ∈ obj› ‹?X ∈ obj ⟹ id ?X maps ?X to ?X› ‹?f ∈ mor ⟹ id (dom ?f) ;; ?f = ?f› ‹?f ∈ mor ⟹ ?f ;; id (cod ?f) = ?f› ‹?f ≈> ?g ⟹ ?f ;; ?g maps dom ?f to cod ?g› ‹⟦?X ∈ obj; ?Y ∈ obj; id ?X = id ?Y⟧ ⟹ ?X = ?Y› ‹?X ∈ obj ⟹ id ?X ≈> id ?X›*)) thus "dom (id X) = X" and "cod (id X) = X" apply - (*goals: 1. ‹id X maps X to X ⟹ dom (id X) = X› 2. ‹id X maps X to X ⟹ cod (id X) = X› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed lemma (in Category) CatIdCompId: assumes "X ∈ obj" shows "id X ;; id X = id X" proof (-) (*goal: ‹id X ;; id X = id X›*) have 0: "id X ∈ mor" using assms (*‹X ∈ obj›*) by (auto simp add: Simps (*‹?f ∈ mor ⟹ dom ?f ∈ obj› ‹?f ∈ mor ⟹ cod ?f ∈ obj› ‹?X ∈ obj ⟹ id ?X maps ?X to ?X› ‹?f ∈ mor ⟹ id (dom ?f) ;; ?f = ?f› ‹?f ∈ mor ⟹ ?f ;; id (cod ?f) = ?f› ‹?f ≈> ?g ⟹ ?f ;; ?g maps dom ?f to cod ?g› ‹⟦?X ∈ obj; ?Y ∈ obj; id ?X = id ?Y⟧ ⟹ ?X = ?Y› ‹?X ∈ obj ⟹ id ?X ≈> id ?X›*)) moreover have "cod (id X) = X" using assms (*‹X ∈ obj›*) by auto moreover have "id X ;; id (cod (id X)) = id X" using "0" (*‹id (X::'a::type) ∈ mor›*) by (simp add: Simps (*‹?f ∈ mor ⟹ dom ?f ∈ obj› ‹?f ∈ mor ⟹ cod ?f ∈ obj› ‹?X ∈ obj ⟹ id ?X maps ?X to ?X› ‹?f ∈ mor ⟹ id (dom ?f) ;; ?f = ?f› ‹?f ∈ mor ⟹ ?f ;; id (cod ?f) = ?f› ‹?f ≈> ?g ⟹ ?f ;; ?g maps dom ?f to cod ?g› ‹⟦?X ∈ obj; ?Y ∈ obj; id ?X = id ?Y⟧ ⟹ ?X = ?Y› ‹?X ∈ obj ⟹ id ?X ≈> id ?X›*)) ultimately show "?thesis" (*goal: ‹id (X::'a::type) ;; id X = id X›*) by simp qed (*lemmas (in Category) simps2 = simps CatIdCompId Cassoc CatIdDomCod*) lemma (in Category) CatIdUniqR: assumes iota: "ι maps X to X" and rid: "∀ f . f ≈> ι ⟶ f ;; ι = f" shows "id X = ι" proof (rule LeftRightInvUniq [of "id X" "id X" ι (*‹⟦id X ≈> id X; id X ≈> ι; id X ;; ι = id (dom (id X)); id X ;; id X = id (cod (id X))⟧ ⟹ id X = ι›*) ]) (*goals: 1. ‹id (X::'a) ≈> id X› 2. ‹id (X::'a) ≈> (ι::'b)› 3. ‹id (X::'a) ;; (ι::'b) = id (dom (id X))› 4. ‹id (X::'a) ;; id X = id (cod (id X))›*) have 0: "X ∈ obj" using iota (*‹ι maps X to X›*) by (auto simp add: Simps (*‹?f ∈ mor ⟹ dom ?f ∈ obj› ‹?f ∈ mor ⟹ cod ?f ∈ obj› ‹?X ∈ obj ⟹ id ?X maps ?X to ?X› ‹?f ∈ mor ⟹ id (dom ?f) ;; ?f = ?f› ‹?f ∈ mor ⟹ ?f ;; id (cod ?f) = ?f› ‹?f ≈> ?g ⟹ ?f ;; ?g maps dom ?f to cod ?g› ‹⟦?X ∈ obj; ?Y ∈ obj; id ?X = id ?Y⟧ ⟹ ?X = ?Y› ‹?X ∈ obj ⟹ id ?X ≈> id ?X›*)) hence "id X maps X to X" by (simp add: Cidm (*‹?X ∈ obj ⟹ id ?X maps ?X to ?X›*)) thus 1: "id X ≈> ι" using iota (*‹ι maps X to X›*) by (auto simp add: Simps (*‹?f ∈ mor ⟹ dom ?f ∈ obj› ‹?f ∈ mor ⟹ cod ?f ∈ obj› ‹?X ∈ obj ⟹ id ?X maps ?X to ?X› ‹?f ∈ mor ⟹ id (dom ?f) ;; ?f = ?f› ‹?f ∈ mor ⟹ ?f ;; id (cod ?f) = ?f› ‹?f ≈> ?g ⟹ ?f ;; ?g maps dom ?f to cod ?g› ‹⟦?X ∈ obj; ?Y ∈ obj; id ?X = id ?Y⟧ ⟹ ?X = ?Y› ‹?X ∈ obj ⟹ id ?X ≈> id ?X›*)) show "id X ≈> id X" using "0" (*‹X ∈ obj›*) by (auto simp add: Simps (*‹?f ∈ mor ⟹ dom ?f ∈ obj› ‹?f ∈ mor ⟹ cod ?f ∈ obj› ‹?X ∈ obj ⟹ id ?X maps ?X to ?X› ‹?f ∈ mor ⟹ id (dom ?f) ;; ?f = ?f› ‹?f ∈ mor ⟹ ?f ;; id (cod ?f) = ?f› ‹?f ≈> ?g ⟹ ?f ;; ?g maps dom ?f to cod ?g› ‹⟦?X ∈ obj; ?Y ∈ obj; id ?X = id ?Y⟧ ⟹ ?X = ?Y› ‹?X ∈ obj ⟹ id ?X ≈> id ?X›*)) show "(id X) ;; ι = (id (dom (id X)))" using "0" (*‹X ∈ obj›*) "1" (*‹id X ≈> ι›*) rid (*‹∀f::'b::type. f ≈> (ι::'b::type) ⟶ f ;; ι = f›*) by (auto simp add: Simps (*‹?f ∈ mor ⟹ dom ?f ∈ obj› ‹?f ∈ mor ⟹ cod ?f ∈ obj› ‹?X ∈ obj ⟹ id ?X maps ?X to ?X› ‹?f ∈ mor ⟹ id (dom ?f) ;; ?f = ?f› ‹?f ∈ mor ⟹ ?f ;; id (cod ?f) = ?f› ‹?f ≈> ?g ⟹ ?f ;; ?g maps dom ?f to cod ?g› ‹⟦?X ∈ obj; ?Y ∈ obj; id ?X = id ?Y⟧ ⟹ ?X = ?Y› ‹?X ∈ obj ⟹ id ?X ≈> id ?X›*) CompDefined_def (*‹?f ≈>⇘?CC⇙ ?g ≡ ?f ∈ mor⇘?CC⇙ ∧ ?g ∈ mor⇘?CC⇙ ∧ cod⇘?CC⇙ ?f = dom⇘?CC⇙ ?g›*) MapsTo_def (*‹?f maps⇘?CC⇙ ?X to ?Y ≡ ?f ∈ mor⇘?CC⇙ ∧ dom⇘?CC⇙ ?f = ?X ∧ cod⇘?CC⇙ ?f = ?Y›*)) show "(id X) ;; (id X) = (id (cod (id X)))" using "0" (*‹X ∈ obj›*) by (auto simp add: CatIdCompId (*‹?X ∈ obj ⟹ id ?X ;; id ?X = id ?X›*) CompDefined_def (*‹?f ≈>⇘?CC⇙ ?g ≡ ?f ∈ mor⇘?CC⇙ ∧ ?g ∈ mor⇘?CC⇙ ∧ cod⇘?CC⇙ ?f = dom⇘?CC⇙ ?g›*) MapsTo_def (*‹?f maps⇘?CC⇙ ?X to ?Y ≡ ?f ∈ mor⇘?CC⇙ ∧ dom⇘?CC⇙ ?f = ?X ∧ cod⇘?CC⇙ ?f = ?Y›*)) qed definition inverse_rel :: "('o,'m,'a) Category_scheme ⇒ 'm ⇒ 'm ⇒ bool" ("cinvı _ _" 60) where "inverse_rel C f g ≡ (f ≈>⇘C⇙ g) ∧ (f ;;⇘C⇙ g) = (id⇘C⇙ (dom⇘C⇙ f)) ∧ (g ;;⇘C⇙ f) = (id⇘C⇙ (cod⇘C⇙ f))" definition isomorphism :: "('o,'m,'a) Category_scheme ⇒ 'm ⇒ bool" ("cisoı _" [70]) where "isomorphism C f ≡ ∃ g . inverse_rel C f g" lemma (in Category) Inverse_relI: "⟦f ≈> g ; f ;; g = id (dom f) ; g ;; f = id (cod f)⟧ ⟹ (cinv f g)" by (auto simp add: inverse_rel_def (*‹cinv⇘?C::(?'o, ?'m, ?'a) Category_scheme⇙ ?f::?'m ?g::?'m ≡ ?f ≈>⇘?C⇙ ?g ∧ ?f ;;⇘?C⇙ ?g = id⇘?C⇙ (dom⇘?C⇙ ?f) ∧ ?g ;;⇘?C⇙ ?f = id⇘?C⇙ (cod⇘?C⇙ ?f)›*)) lemma (in Category) Inverse_relE[elim]: "⟦cinv f g ; ⟦f ≈> g ; f ;; g = id (dom f) ; g ;; f = id (cod f)⟧ ⟹ P⟧ ⟹ P" by (auto simp add: inverse_rel_def (*‹cinv⇘?C⇙ ?f ?g ≡ ?f ≈>⇘?C⇙ ?g ∧ ?f ;;⇘?C⇙ ?g = id⇘?C⇙ (dom⇘?C⇙ ?f) ∧ ?g ;;⇘?C⇙ ?f = id⇘?C⇙ (cod⇘?C⇙ ?f)›*)) lemma (in Category) Inverse_relSym: assumes "cinv f g" shows "cinv g f" proof (rule Inverse_relI (*‹⟦?f ≈> ?g; ?f ;; ?g = id (dom ?f); ?g ;; ?f = id (cod ?f)⟧ ⟹ cinv ?f ?g›*)) (*goals: 1. ‹(g::'b) ≈> (f::'b)› 2. ‹(g::'b) ;; (f::'b) = id (dom g)› 3. ‹(f::'b) ;; (g::'b) = id (cod g)›*) have 1: "f ≈> g" using assms (*‹cinv f g›*) by auto show 2: "g ≈> f" proof (rule CompDefinedI (*‹⟦(?f::?'a) ∈ mor⇘?C::(?'b, ?'a, ?'c) Category_scheme⇙; (?g::?'a) ∈ mor⇘?C⇙; cod⇘?C⇙ ?f = dom⇘?C⇙ ?g⟧ ⟹ ?f ≈>⇘?C⇙ ?g›*)) (*goals: 1. ‹(g::'b) ∈ mor› 2. ‹(f::'b) ∈ mor› 3. ‹cod (g::'b) = dom (f::'b)›*) show "g ∈ mor" and 0: "f ∈ mor" using assms (*‹cinv f g›*) apply - (*goals: 1. ‹cinv f g ⟹ g ∈ mor› 2. ‹cinv f g ⟹ f ∈ mor› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have "f ;; g maps dom f to cod g" using "1" (*‹f ≈> g›*) by (simp add: MapsToCompI (*‹?f ≈> ?g ⟹ ?f ;; ?g maps dom ?f to cod ?g›*)) hence "cod g = cod (f ;; g)" by auto also (*calculation: ‹cod g = cod (f ;; g)›*) have "... = cod (id (dom f))" using assms (*‹cinv f g›*) by (auto simp add: inverse_rel_def (*‹cinv⇘?C⇙ ?f ?g ≡ ?f ≈>⇘?C⇙ ?g ∧ ?f ;;⇘?C⇙ ?g = id⇘?C⇙ (dom⇘?C⇙ ?f) ∧ ?g ;;⇘?C⇙ ?f = id⇘?C⇙ (cod⇘?C⇙ ?f)›*)) also (*calculation: ‹cod g = cod (id (dom f))›*) have "... = dom f" proof (-) (*goal: ‹cod (id (dom (f::'b))) = dom f›*) have "dom f ∈ obj" using "0" (*‹f ∈ mor›*) by (simp add: Simps (*‹(?f::'b) ∈ mor ⟹ dom ?f ∈ obj› ‹(?f::'b) ∈ mor ⟹ cod ?f ∈ obj› ‹(?X::'a) ∈ obj ⟹ id ?X maps ?X to ?X› ‹(?f::'b) ∈ mor ⟹ id (dom ?f) ;; ?f = ?f› ‹(?f::'b) ∈ mor ⟹ ?f ;; id (cod ?f) = ?f› ‹(?f::'b) ≈> (?g::'b) ⟹ ?f ;; ?g maps dom ?f to cod ?g› ‹⟦(?X::'a) ∈ obj; (?Y::'a) ∈ obj; id ?X = id ?Y⟧ ⟹ ?X = ?Y› ‹(?X::'a) ∈ obj ⟹ id ?X ≈> id ?X›*)) hence "id (dom f) maps (dom f) to (dom f)" by (simp add: Simps (*‹(?f::'b) ∈ mor ⟹ dom ?f ∈ obj› ‹(?f::'b) ∈ mor ⟹ cod ?f ∈ obj› ‹(?X::'a) ∈ obj ⟹ id ?X maps ?X to ?X› ‹(?f::'b) ∈ mor ⟹ id (dom ?f) ;; ?f = ?f› ‹(?f::'b) ∈ mor ⟹ ?f ;; id (cod ?f) = ?f› ‹(?f::'b) ≈> (?g::'b) ⟹ ?f ;; ?g maps dom ?f to cod ?g› ‹⟦(?X::'a) ∈ obj; (?Y::'a) ∈ obj; id ?X = id ?Y⟧ ⟹ ?X = ?Y› ‹(?X::'a) ∈ obj ⟹ id ?X ≈> id ?X›*)) thus "?thesis" (*goal: ‹cod (id (dom f)) = dom f›*) by auto qed finally (*calculation: ‹cod g = dom f›*) show 2: "cod g = dom f" by simp qed show "g ;; f = id (dom g)" using assms (*‹cinv f::'b g::'b›*) by (auto simp add: inverse_rel_def (*‹cinv⇘?C⇙ ?f ?g ≡ ?f ≈>⇘?C⇙ ?g ∧ ?f ;;⇘?C⇙ ?g = id⇘?C⇙ (dom⇘?C⇙ ?f) ∧ ?g ;;⇘?C⇙ ?f = id⇘?C⇙ (cod⇘?C⇙ ?f)›*)) show "f ;; g = id (cod g)" using assms (*‹cinv f g›*) "1" (*‹f ≈> g›*) "2" (*‹g ≈> f›*) by (auto simp add: inverse_rel_def (*‹cinv⇘?C⇙ ?f ?g ≡ ?f ≈>⇘?C⇙ ?g ∧ ?f ;;⇘?C⇙ ?g = id⇘?C⇙ (dom⇘?C⇙ ?f) ∧ ?g ;;⇘?C⇙ ?f = id⇘?C⇙ (cod⇘?C⇙ ?f)›*)) qed lemma (in Category) InverseUnique: assumes 1: "cinv f g" and 2: "cinv f h" shows "g = h" proof (rule LeftRightInvUniq [of g f h] (*‹⟦g ≈> f; f ≈> h; f ;; h = id (dom f); g ;; f = id (cod f)⟧ ⟹ g = h›*)) (*goals: 1. ‹g ≈> f› 2. ‹f ≈> h› 3. ‹f ;; h = id (dom f)› 4. ‹g ;; f = id (cod f)›*) have "cinv g f" using "1" (*‹cinv f g›*) "2" (*‹cinv f h›*) by (simp only: Inverse_relSym[of f g] (*‹cinv f g ⟹ cinv g f›*)) thus "g ≈> f" and "g ;; f = id (cod f)" using "1" (*‹cinv f g›*) apply - (*goals: 1. ‹⟦cinv g f; cinv f g⟧ ⟹ g ≈> f› 2. ‹⟦cinv g f; cinv f g⟧ ⟹ g ;; f = id (cod f)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . show "f ≈> h" using "2" (*‹cinv f h›*) by auto show "f ;; h = id (dom f)" using "2" (*‹cinv f h›*) by auto qed lemma (in Category) InvId: assumes "X ∈ obj" shows "(cinv (id X) (id X))" proof (rule Inverse_relI (*‹⟦?f ≈> ?g; ?f ;; ?g = id (dom ?f); ?g ;; ?f = id (cod ?f)⟧ ⟹ cinv ?f ?g›*)) (*goals: 1. ‹id X ≈> id X› 2. ‹id X ;; id X = id (dom (id X))› 3. ‹id X ;; id X = id (cod (id X))›*) show "id X ≈> id X" using assms (*‹X ∈ obj›*) by (simp add: Simps (*‹?f ∈ mor ⟹ dom ?f ∈ obj› ‹?f ∈ mor ⟹ cod ?f ∈ obj› ‹?X ∈ obj ⟹ id ?X maps ?X to ?X› ‹?f ∈ mor ⟹ id (dom ?f) ;; ?f = ?f› ‹?f ∈ mor ⟹ ?f ;; id (cod ?f) = ?f› ‹?f ≈> ?g ⟹ ?f ;; ?g maps dom ?f to cod ?g› ‹⟦?X ∈ obj; ?Y ∈ obj; id ?X = id ?Y⟧ ⟹ ?X = ?Y› ‹?X ∈ obj ⟹ id ?X ≈> id ?X›*)) have "dom (id X) = X" and "dom (id X) = X" using assms (*‹X ∈ obj›*) apply - (*goals: 1. ‹X ∈ obj ⟹ dom (id X) = X› 2. ‹X ∈ obj ⟹ dom (id X) = X› discuss goal 1*) apply (simp add: CatIdDomCod (*‹?X ∈ obj ⟹ dom (id ?X) = ?X› ‹?X ∈ obj ⟹ cod (id ?X) = ?X›*)) (*discuss goal 2*) apply (simp add: CatIdDomCod (*‹?X ∈ obj ⟹ dom (id ?X) = ?X› ‹?X ∈ obj ⟹ cod (id ?X) = ?X›*)) (*proven 2 subgoals*) . thus "id X ;; id X = id (dom (id X))" and "id X ;; id X = id (cod (id X))" using assms (*‹X ∈ obj›*) apply - (*goals: 1. ‹⟦dom (id X) = X; dom (id X) = X; X ∈ obj⟧ ⟹ id X ;; id X = id (dom (id X))› 2. ‹⟦dom (id X) = X; dom (id X) = X; X ∈ obj⟧ ⟹ id X ;; id X = id (cod (id X))› discuss goal 1*) apply (simp add: CatIdCompId (*‹?X ∈ obj ⟹ id ?X ;; id ?X = id ?X›*) CatIdDomCod (*‹?X ∈ obj ⟹ dom (id ?X) = ?X› ‹?X ∈ obj ⟹ cod (id ?X) = ?X›*)) (*discuss goal 2*) apply (simp add: CatIdCompId (*‹?X ∈ obj ⟹ id ?X ;; id ?X = id ?X›*) CatIdDomCod (*‹?X ∈ obj ⟹ dom (id ?X) = ?X› ‹?X ∈ obj ⟹ cod (id ?X) = ?X›*)) (*proven 2 subgoals*) . qed definition inverse :: "('o,'m,'a) Category_scheme ⇒ 'm ⇒ 'm" ("Cinvı _" [70]) where "inverse C f ≡ THE g . inverse_rel C f g" lemma (in Category) inv2Inv: assumes "cinv f g" shows "ciso f" and "Cinv f = g" proof (-) (*goals: 1. ‹ciso f› 2. ‹Cinv f = g›*) show "ciso f" using assms (*‹cinv f::'b::type g::'b::type›*) by (auto simp add: isomorphism_def (*‹ciso⇘?C⇙ ?f ≡ ∃g. cinv⇘?C⇙ ?f g›*)) hence "∃! g . cinv f g" using assms (*‹cinv f g›*) by (auto simp add: InverseUnique (*‹⟦cinv ?f ?g; cinv ?f ?h⟧ ⟹ ?g = ?h›*)) thus "Cinv f = g" using assms (*‹cinv f::'b g::'b›*) by (auto simp add: inverse_def (*‹Cinv⇘?C::(?'o, ?'m, ?'a) Category_scheme⇙ (?f::?'m) ≡ THE g::?'m. cinv⇘?C⇙ ?f g›*)) qed lemma (in Category) iso2Inv: assumes "ciso f" shows "cinv f (Cinv f)" proof (-) (*goal: ‹cinv f Cinv f›*) have "∃! g . cinv f g" using assms (*‹ciso (f::'b)›*) by (auto simp add: InverseUnique (*‹⟦cinv ?f ?g; cinv ?f ?h⟧ ⟹ ?g = ?h›*) isomorphism_def (*‹ciso⇘?C⇙ ?f ≡ ∃g. cinv⇘?C⇙ ?f g›*)) thus "?thesis" (*goal: ‹cinv f Cinv f›*) by (auto simp add: inverse_def (*‹Cinv⇘?C::(?'o, ?'m, ?'a) Category_scheme⇙ (?f::?'m) ≡ THE g::?'m. cinv⇘?C⇙ ?f g›*) intro:theI' (*‹∃!x::?'a. (?P::?'a ⇒ bool) x ⟹ ?P (THE x::?'a. ?P x)›*)) qed lemma (in Category) InvInv: assumes "ciso f" shows "ciso (Cinv f)" and "(Cinv (Cinv f)) = f" proof (-) (*goals: 1. ‹ciso Cinv f› 2. ‹Cinv Cinv f = f›*) have "cinv f (Cinv f)" using assms (*‹ciso f›*) by (simp add: iso2Inv (*‹ciso ?f ⟹ cinv ?f Cinv ?f›*)) hence "cinv (Cinv f) f" by (simp add: Inverse_relSym[of f] (*‹cinv f ?g ⟹ cinv ?g f›*)) thus "ciso (Cinv f)" and "Cinv (Cinv f) = f" apply - (*goals: 1. ‹cinv Cinv f f ⟹ ciso Cinv f› 2. ‹cinv Cinv f f ⟹ Cinv Cinv f = f› discuss goal 1*) apply ((auto simp add: inv2Inv (*‹cinv ?f ?g ⟹ ciso ?f› ‹cinv ?f ?g ⟹ Cinv ?f = ?g›*))[1]) (*discuss goal 2*) apply ((auto simp add: inv2Inv (*‹cinv ?f ?g ⟹ ciso ?f› ‹cinv ?f ?g ⟹ Cinv ?f = ?g›*))[1]) (*proven 2 subgoals*) . qed lemma (in Category) InvIsMor: "(cinv f g) ⟹ (f ∈ mor ∧ g ∈ mor)" by (auto simp add: inverse_rel_def (*‹cinv⇘?C⇙ ?f ?g ≡ ?f ≈>⇘?C⇙ ?g ∧ ?f ;;⇘?C⇙ ?g = id⇘?C⇙ (dom⇘?C⇙ ?f) ∧ ?g ;;⇘?C⇙ ?f = id⇘?C⇙ (cod⇘?C⇙ ?f)›*)) lemma (in Category) IsoIsMor: "ciso f ⟹ f ∈ mor" by (auto simp add: InvIsMor (*‹cinv ?f ?g ⟹ ?f ∈ mor ∧ ?g ∈ mor›*) dest: iso2Inv (*‹ciso ?f ⟹ cinv ?f Cinv ?f›*)) lemma (in Category) InvDomCod: assumes "ciso f" shows "dom (Cinv f) = cod f" and "cod (Cinv f) = dom f" and "Cinv f ∈ mor" proof (-) (*goals: 1. ‹dom Cinv (f::'b) = cod f› 2. ‹cod Cinv (f::'b) = dom f› 3. ‹Cinv (f::'b) ∈ mor›*) have 1: "cinv f (Cinv f)" using assms (*‹ciso f›*) by (auto simp add: iso2Inv (*‹ciso (?f::'b) ⟹ cinv ?f Cinv ?f›*)) thus "dom (Cinv f) = cod f" by (auto simp add: inverse_rel_def (*‹cinv⇘?C⇙ ?f ?g ≡ ?f ≈>⇘?C⇙ ?g ∧ ?f ;;⇘?C⇙ ?g = id⇘?C⇙ (dom⇘?C⇙ ?f) ∧ ?g ;;⇘?C⇙ ?f = id⇘?C⇙ (cod⇘?C⇙ ?f)›*)) from "1" (*‹cinv f Cinv f›*) have "cinv (Cinv f) f" by (auto simp add: Inverse_relSym[of f] (*‹cinv f ?g ⟹ cinv ?g f›*)) thus "cod (Cinv f) = dom f" by (auto simp add: inverse_rel_def (*‹cinv⇘?C⇙ ?f ?g ≡ ?f ≈>⇘?C⇙ ?g ∧ ?f ;;⇘?C⇙ ?g = id⇘?C⇙ (dom⇘?C⇙ ?f) ∧ ?g ;;⇘?C⇙ ?f = id⇘?C⇙ (cod⇘?C⇙ ?f)›*)) show "Cinv f ∈ mor" using "1" (*‹cinv f Cinv f›*) by (auto simp add: inverse_rel_def (*‹cinv⇘?C::(?'o, ?'m, ?'a) Category_scheme⇙ ?f::?'m ?g::?'m ≡ ?f ≈>⇘?C⇙ ?g ∧ ?f ;;⇘?C⇙ ?g = id⇘?C⇙ (dom⇘?C⇙ ?f) ∧ ?g ;;⇘?C⇙ ?f = id⇘?C⇙ (cod⇘?C⇙ ?f)›*)) qed lemma (in Category) IsoCompInv: "ciso f ⟹ f ≈> Cinv f" sorry lemma (in Category) InvCompIso: "ciso f ⟹ Cinv f ≈> f" by (auto simp add: IsoIsMor (*‹ciso ?f ⟹ ?f ∈ mor›*) InvDomCod (*‹ciso ?f ⟹ dom Cinv ?f = cod ?f› ‹ciso ?f ⟹ cod Cinv ?f = dom ?f› ‹ciso ?f ⟹ Cinv ?f ∈ mor›*)) lemma (in Category) IsoInvId1 : "ciso f ⟹ (Cinv f) ;; f = (id (cod f))" by (auto dest: iso2Inv (*‹ciso (?f::'b) ⟹ cinv ?f Cinv ?f›*)) lemma (in Category) IsoInvId2 : "ciso f ⟹ f ;; (Cinv f) = (id (dom f))" by (auto dest: iso2Inv (*‹ciso ?f ⟹ cinv ?f Cinv ?f›*)) lemma (in Category) IsoCompDef: assumes 1: "f ≈> g" and 2: "ciso f" and 3: "ciso g" shows "(Cinv g) ≈> (Cinv f)" proof (rule CompDefinedI (*‹⟦(?f::?'a) ∈ mor⇘?C::(?'b, ?'a, ?'c) Category_scheme⇙; (?g::?'a) ∈ mor⇘?C⇙; cod⇘?C⇙ ?f = dom⇘?C⇙ ?g⟧ ⟹ ?f ≈>⇘?C⇙ ?g›*)) (*goals: 1. ‹Cinv g ∈ mor› 2. ‹Cinv f ∈ mor› 3. ‹cod Cinv g = dom Cinv f›*) show "Cinv g ∈ mor" and "Cinv f ∈ mor" using assms (*‹f ≈> g› ‹ciso f› ‹ciso g›*) apply - (*goals: 1. ‹⟦f ≈> g; ciso f; ciso g⟧ ⟹ Cinv g ∈ mor› 2. ‹⟦f ≈> g; ciso f; ciso g⟧ ⟹ Cinv f ∈ mor› discuss goal 1*) apply ((auto simp add: InvDomCod (*‹ciso ?f ⟹ dom Cinv ?f = cod ?f› ‹ciso ?f ⟹ cod Cinv ?f = dom ?f› ‹ciso ?f ⟹ Cinv ?f ∈ mor›*))[1]) (*discuss goal 2*) apply ((auto simp add: InvDomCod (*‹ciso ?f ⟹ dom Cinv ?f = cod ?f› ‹ciso ?f ⟹ cod Cinv ?f = dom ?f› ‹ciso ?f ⟹ Cinv ?f ∈ mor›*))[1]) (*proven 2 subgoals*) . have "cod (Cinv g) = dom g" using "3" (*‹ciso g›*) by (simp add: InvDomCod (*‹ciso (?f::'b) ⟹ dom Cinv ?f = cod ?f› ‹ciso (?f::'b) ⟹ cod Cinv ?f = dom ?f› ‹ciso (?f::'b) ⟹ Cinv ?f ∈ mor›*)) also (*calculation: ‹cod Cinv g = dom g›*) have "... = cod f" using "1" (*‹f ≈> g›*) by auto also (*calculation: ‹cod Cinv g = cod f›*) have "... = dom (Cinv f)" using "2" (*‹ciso f›*) by (simp add: InvDomCod (*‹ciso ?f ⟹ dom Cinv ?f = cod ?f› ‹ciso ?f ⟹ cod Cinv ?f = dom ?f› ‹ciso ?f ⟹ Cinv ?f ∈ mor›*)) finally (*calculation: ‹cod Cinv g = dom Cinv f›*) show "cod (Cinv g) = dom (Cinv f)" . qed lemma (in Category) IsoCompose: assumes 1: "f ≈> g" and 2: "ciso f" and 3: "ciso g" shows "ciso (f ;; g)" and "Cinv (f ;; g) = (Cinv g) ;; (Cinv f)" proof (-) (*goals: 1. ‹ciso (f::'b) ;; (g::'b)› 2. ‹Cinv (f::'b) ;; (g::'b) = Cinv g ;; Cinv f›*) have a: "(Cinv g) ≈> (Cinv f)" using assms (*‹(f::'b::type) ≈> (g::'b::type)› ‹ciso f› ‹ciso g›*) by (simp add: IsoCompDef (*‹⟦?f ≈> ?g; ciso ?f; ciso ?g⟧ ⟹ Cinv ?g ≈> Cinv ?f›*)) hence b: "(Cinv g) ;; (Cinv f) maps (dom (Cinv g)) to (cod (Cinv f))" by (simp add: MapsToCompI (*‹?f ≈> ?g ⟹ ?f ;; ?g maps dom ?f to cod ?g›*)) hence c: "(Cinv g) ;; (Cinv f) maps (cod g) to (dom f)" using "2" (*‹ciso f›*) "3" (*‹ciso g›*) by (simp add: InvDomCod (*‹ciso ?f ⟹ dom Cinv ?f = cod ?f› ‹ciso ?f ⟹ cod Cinv ?f = dom ?f› ‹ciso ?f ⟹ Cinv ?f ∈ mor›*)) have d: "f ;; g maps (dom f) to (cod g)" using "1" (*‹f ≈> g›*) by (simp add: Simps (*‹?f ∈ mor ⟹ dom ?f ∈ obj› ‹?f ∈ mor ⟹ cod ?f ∈ obj› ‹?X ∈ obj ⟹ id ?X maps ?X to ?X› ‹?f ∈ mor ⟹ id (dom ?f) ;; ?f = ?f› ‹?f ∈ mor ⟹ ?f ;; id (cod ?f) = ?f› ‹?f ≈> ?g ⟹ ?f ;; ?g maps dom ?f to cod ?g› ‹⟦?X ∈ obj; ?Y ∈ obj; id ?X = id ?Y⟧ ⟹ ?X = ?Y› ‹?X ∈ obj ⟹ id ?X ≈> id ?X›*)) have "cinv (f ;; g) ((Cinv g) ;; (Cinv f))" proof (auto simp add: inverse_rel_def (*‹cinv⇘?C⇙ ?f ?g ≡ ?f ≈>⇘?C⇙ ?g ∧ ?f ;;⇘?C⇙ ?g = id⇘?C⇙ (dom⇘?C⇙ ?f) ∧ ?g ;;⇘?C⇙ ?f = id⇘?C⇙ (cod⇘?C⇙ ?f)›*)) (*goals: 1. ‹f ;; g ≈> Cinv g ;; Cinv f› 2. ‹f ;; g ;; (Cinv g ;; Cinv f) = id (dom (f ;; g))› 3. ‹Cinv g ;; Cinv f ;; (f ;; g) = id (cod (f ;; g))›*) show "f ;; g ≈> (Cinv g) ;; (Cinv f)" proof (rule CompDefinedI (*‹⟦(?f::?'a::type) ∈ mor⇘?C::(?'b, ?'a, ?'c) Category_scheme⇙; (?g::?'a::type) ∈ mor⇘?C⇙; cod⇘?C⇙ ?f = dom⇘?C⇙ ?g⟧ ⟹ ?f ≈>⇘?C⇙ ?g›*)) (*goals: 1. ‹f ;; g ∈ mor› 2. ‹Cinv g ;; Cinv f ∈ mor› 3. ‹cod (f ;; g) = dom (Cinv g ;; Cinv f)›*) show "f ;; g ∈ mor" using d (*‹f ;; g maps dom f to cod g›*) by auto show "(Cinv g) ;; (Cinv f) ∈ mor" using c (*‹Cinv (g::'b::type) ;; Cinv (f::'b::type) maps cod g to dom f›*) by auto have "cod (f ;; g) = cod g" using d (*‹f ;; g maps dom f to cod g›*) by auto also (*calculation: ‹cod (f ;; g) = cod g›*) have "... = dom (Cinv g)" using assms (*‹f ≈> g› ‹ciso f› ‹ciso g›*) by (simp add: InvDomCod (*‹ciso ?f ⟹ dom Cinv ?f = cod ?f› ‹ciso ?f ⟹ cod Cinv ?f = dom ?f› ‹ciso ?f ⟹ Cinv ?f ∈ mor›*)) also (*calculation: ‹cod (f ;; g) = dom Cinv g›*) have "... = dom ((Cinv g) ;; (Cinv f))" using b (*‹Cinv g ;; Cinv f maps dom Cinv g to cod Cinv f›*) by auto finally (*calculation: ‹cod (f ;; g) = dom (Cinv g ;; Cinv f)›*) show "cod (f ;; g) = dom ((Cinv g) ;; (Cinv f))" . qed show "f ;; g ;; ((Cinv g) ;; (Cinv f)) = id (dom (f ;; g))" proof (-) (*goal: ‹f ;; g ;; (Cinv g ;; Cinv f) = id (dom (f ;; g))›*) have e: "g ≈> (Cinv g)" using assms (*‹f ≈> g› ‹ciso f› ‹ciso g›*) by (simp add: IsoCompInv (*‹ciso ?f ⟹ ?f ≈> Cinv ?f›*)) have f: "f ∈ mor" using "1" (*‹f ≈> g›*) by auto have "(f ;; g) ;; ((Cinv g) ;; (Cinv f)) = (f ;; (g ;; (Cinv g))) ;; (Cinv f)" using "1" (*‹f ≈> g›*) e (*‹(g::'b::type) ≈> Cinv g›*) a (*‹Cinv g ≈> Cinv f›*) by (auto simp add: Cassoc (*‹⟦?f ≈> ?g; ?g ≈> ?h⟧ ⟹ ?f ;; ?g ;; ?h = ?f ;; (?g ;; ?h)›*) CompDefComp (*‹⟦?f ≈> ?g; ?g ≈> ?h⟧ ⟹ ?f ≈> ?g ;; ?h› ‹⟦?f ≈> ?g; ?g ≈> ?h⟧ ⟹ ?f ;; ?g ≈> ?h›*)) also (*calculation: ‹f ;; g ;; (Cinv g ;; Cinv f) = f ;; (g ;; Cinv g) ;; Cinv f›*) have "... = f ;; (id (dom g)) ;; (Cinv f)" using "3" (*‹ciso (g::'b)›*) by (simp add: IsoInvId2 (*‹ciso ?f ⟹ ?f ;; Cinv ?f = id (dom ?f)›*)) also (*calculation: ‹f ;; g ;; (Cinv g ;; Cinv f) = f ;; id (dom g) ;; Cinv f›*) have "... = f ;; id (cod f) ;; (Cinv f)" using "1" (*‹f ≈> g›*) by (auto simp add: Simps (*‹?f ∈ mor ⟹ dom ?f ∈ obj› ‹?f ∈ mor ⟹ cod ?f ∈ obj› ‹?X ∈ obj ⟹ id ?X maps ?X to ?X› ‹?f ∈ mor ⟹ id (dom ?f) ;; ?f = ?f› ‹?f ∈ mor ⟹ ?f ;; id (cod ?f) = ?f› ‹?f ≈> ?g ⟹ ?f ;; ?g maps dom ?f to cod ?g› ‹⟦?X ∈ obj; ?Y ∈ obj; id ?X = id ?Y⟧ ⟹ ?X = ?Y› ‹?X ∈ obj ⟹ id ?X ≈> id ?X›*)) also (*calculation: ‹(f::'b) ;; (g::'b) ;; (Cinv g ;; Cinv f) = f ;; id (cod f) ;; Cinv f›*) have "... = f ;; (Cinv f)" using f (*‹(f::'b) ∈ mor›*) by (auto simp add: Cidr (*‹(?f::'b) ∈ mor ⟹ ?f ;; id (cod ?f) = ?f›*)) also (*calculation: ‹f ;; g ;; (Cinv g ;; Cinv f) = f ;; Cinv f›*) have "... = id (dom f)" using "2" (*‹ciso f›*) by (simp add: IsoInvId2 (*‹ciso ?f ⟹ ?f ;; Cinv ?f = id (dom ?f)›*)) also (*calculation: ‹f ;; g ;; (Cinv g ;; Cinv f) = id (dom f)›*) have "... = id (dom (f ;; g))" using d (*‹f ;; g maps dom f to cod g›*) by auto finally (*calculation: ‹f ;; g ;; (Cinv g ;; Cinv f) = id (dom (f ;; g))›*) show "?thesis" (*goal: ‹(f::'b) ;; (g::'b) ;; (Cinv g ;; Cinv f) = id (dom (f ;; g))›*) by simp qed show "((Cinv g) ;; (Cinv f)) ;; (f ;; g) = id (cod (f ;; g))" proof (-) (*goal: ‹Cinv g ;; Cinv f ;; (f ;; g) = id (cod (f ;; g))›*) have e: "(Cinv f) ≈> f" using assms (*‹f ≈> g› ‹ciso f› ‹ciso g›*) by (simp add: InvCompIso (*‹ciso ?f ⟹ Cinv ?f ≈> ?f›*)) have f: "g ∈ mor" using "1" (*‹(f::'b) ≈> (g::'b)›*) by auto have "((Cinv g) ;; (Cinv f)) ;; (f ;; g) = (Cinv g) ;; (((Cinv f) ;; f) ;; g)" using "1" (*‹f ≈> g›*) e (*‹Cinv f ≈> f›*) a (*‹Cinv g ≈> Cinv f›*) by (auto simp add: Cassoc (*‹⟦(?f::'b::type) ≈> (?g::'b::type); ?g ≈> (?h::'b::type)⟧ ⟹ ?f ;; ?g ;; ?h = ?f ;; (?g ;; ?h)›*) CompDefComp (*‹⟦(?f::'b::type) ≈> (?g::'b::type); ?g ≈> (?h::'b::type)⟧ ⟹ ?f ≈> ?g ;; ?h› ‹⟦(?f::'b::type) ≈> (?g::'b::type); ?g ≈> (?h::'b::type)⟧ ⟹ ?f ;; ?g ≈> ?h›*)) also (*calculation: ‹Cinv g ;; Cinv f ;; (f ;; g) = Cinv g ;; (Cinv f ;; f ;; g)›*) have "... = (Cinv g) ;; ((id (cod f)) ;; g)" using "2" (*‹ciso f›*) by (simp add: IsoInvId1 (*‹ciso (?f::'b) ⟹ Cinv ?f ;; ?f = id (cod ?f)›*)) also (*calculation: ‹Cinv g ;; Cinv f ;; (f ;; g) = Cinv g ;; (id (cod f) ;; g)›*) have "... = (Cinv g) ;; ((id (dom g)) ;; g)" using "1" (*‹f ≈> g›*) by (auto simp add: Simps (*‹?f ∈ mor ⟹ dom ?f ∈ obj› ‹?f ∈ mor ⟹ cod ?f ∈ obj› ‹?X ∈ obj ⟹ id ?X maps ?X to ?X› ‹?f ∈ mor ⟹ id (dom ?f) ;; ?f = ?f› ‹?f ∈ mor ⟹ ?f ;; id (cod ?f) = ?f› ‹?f ≈> ?g ⟹ ?f ;; ?g maps dom ?f to cod ?g› ‹⟦?X ∈ obj; ?Y ∈ obj; id ?X = id ?Y⟧ ⟹ ?X = ?Y› ‹?X ∈ obj ⟹ id ?X ≈> id ?X›*)) also (*calculation: ‹Cinv g ;; Cinv f ;; (f ;; g) = Cinv g ;; (id (dom g) ;; g)›*) have "... = (Cinv g) ;; g" using f (*‹g ∈ mor›*) by (auto simp add: Cidl (*‹?f ∈ mor ⟹ id (dom ?f) ;; ?f = ?f›*)) also (*calculation: ‹Cinv g ;; Cinv f ;; (f ;; g) = Cinv g ;; g›*) have "... = id (cod g)" using "3" (*‹ciso g›*) by (simp add: IsoInvId1 (*‹ciso (?f::'b) ⟹ Cinv ?f ;; ?f = id (cod ?f)›*)) also (*calculation: ‹Cinv g ;; Cinv f ;; (f ;; g) = id (cod g)›*) have "... = id (cod (f ;; g))" using d (*‹f ;; g maps dom f to cod g›*) by auto finally (*calculation: ‹Cinv (g::'b) ;; Cinv (f::'b) ;; (f ;; g) = id (cod (f ;; g))›*) show "?thesis" (*goal: ‹Cinv g ;; Cinv f ;; (f ;; g) = id (cod (f ;; g))›*) by simp qed qed thus "ciso (f ;; g)" and "Cinv (f ;; g) = (Cinv g) ;; (Cinv f)" apply - (*goals: 1. ‹cinv (f::'b::type) ;; (g::'b::type) Cinv g ;; Cinv f ⟹ ciso f ;; g› 2. ‹cinv (f::'b::type) ;; (g::'b::type) Cinv g ;; Cinv f ⟹ Cinv f ;; g = Cinv g ;; Cinv f› discuss goal 1*) apply ((auto simp add: inv2Inv (*‹cinv ?f ?g ⟹ ciso ?f› ‹cinv ?f ?g ⟹ Cinv ?f = ?g›*))[1]) (*discuss goal 2*) apply ((auto simp add: inv2Inv (*‹cinv ?f ?g ⟹ ciso ?f› ‹cinv ?f ?g ⟹ Cinv ?f = ?g›*))[1]) (*proven 2 subgoals*) . qed definition "ObjIso C A B ≡ ∃ k . (k maps⇘C⇙ A to B) ∧ ciso⇘C ⇙k" definition UnitCategory :: "(unit, unit) Category" where "UnitCategory = MakeCat ⦇ Obj = {()} , Mor = {()} , Dom = (λf.()) , Cod = (λf.()) , Id = (λf.()) , Comp = (λf g. ()) ⦈" lemma [simp]: "Category(UnitCategory)" apply (simp add: UnitCategory_def (*‹UnitCategory = MakeCat ⦇Obj = {()}, Mor = {()}, Dom = λf::unit. (), Cod = λf::unit. (), Id = λf::unit. (), Comp = λ(f::unit) g::unit. ()⦈›*)) (*goal: ‹Category UnitCategory›*) apply (rule MakeCat (*‹Category_axioms (?C::(?'a, ?'b, ?'c) Category_scheme) ⟹ Category (MakeCat ?C)›*)) (*goal: ‹Category (MakeCat ⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈)›*) apply unfold_locales (*goals: 1. ‹⋀f. f ∈ mor⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ ⟹ dom⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ f ∈ obj⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙› 2. ‹⋀f. f ∈ mor⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ ⟹ cod⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ f ∈ obj⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙› 3. ‹⋀X. X ∈ obj⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ ⟹ id⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ X maps⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ X to X› 4. ‹⋀f. f ∈ mor⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ ⟹ id⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ (dom⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ f) ;;⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ f = f› 5. ‹⋀f. f ∈ mor⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ ⟹ f ;;⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ id⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ (cod⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ f) = f› 6. ‹⋀f g h. ⟦f ≈>⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ g; g ≈>⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ h⟧ ⟹ f ;;⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ g ;;⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ h = f ;;⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ (g ;;⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ h)› 7. ‹⋀f X Y g Z. ⟦f maps⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ X to Y; g maps⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ Y to Z⟧ ⟹ f ;;⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ g maps⇘⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈⇙ X to Z› discuss goal 1*) apply ((auto simp add: UnitCategory_def (*‹UnitCategory = MakeCat ⦇Obj = {()}, Mor = {()}, Dom = λf::unit. (), Cod = λf::unit. (), Id = λf::unit. (), Comp = λ(f::unit) g::unit. ()⦈›*))[1]) (*discuss goal 2*) apply ((auto simp add: UnitCategory_def (*‹UnitCategory = MakeCat ⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈›*))[1]) (*discuss goal 3*) apply ((auto simp add: UnitCategory_def (*‹UnitCategory = MakeCat ⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈›*))[1]) (*discuss goal 4*) apply ((auto simp add: UnitCategory_def (*‹UnitCategory = MakeCat ⦇Obj = {()}, Mor = {()}, Dom = λf::unit. (), Cod = λf::unit. (), Id = λf::unit. (), Comp = λ(f::unit) g::unit. ()⦈›*))[1]) (*discuss goal 5*) apply ((auto simp add: UnitCategory_def (*‹UnitCategory = MakeCat ⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈›*))[1]) (*discuss goal 6*) apply ((auto simp add: UnitCategory_def (*‹UnitCategory = MakeCat ⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈›*))[1]) (*discuss goal 7*) apply ((auto simp add: UnitCategory_def (*‹UnitCategory = MakeCat ⦇Obj = {()}, Mor = {()}, Dom = λf. (), Cod = λf. (), Id = λf. (), Comp = λf g. ()⦈›*))[1]) (*proven 7 subgoals*) . definition OppositeCategory :: "('o,'m,'a) Category_scheme ⇒ ('o,'m,'a) Category_scheme" ("Op _" [65] 65) where "OppositeCategory C ≡ ⦇ Obj = Obj C , Mor = Mor C , Dom = Cod C , Cod = Dom C , Id = Id C , Comp = (λf g. g ;;⇘C⇙ f), … = Category.more C ⦈" lemma OpCatOpCat: "Op (Op C) = C" by (simp add: OppositeCategory_def (*‹Op ?C ≡ ⦇Obj = obj⇘?C⇙, Mor = mor⇘?C⇙, Dom = Cod ?C, Cod = Dom ?C, Id = Category.Id ?C, Comp = λf g. g ;;⇘?C⇙ f, … = more ?C⦈›*)) lemma OpCatCatAx: "Category_axioms C ⟹ Category_axioms (Op C)" by (simp add: OppositeCategory_def (*‹Op (?C::(?'o, ?'m, ?'a) Category_scheme) ≡ ⦇Obj = obj⇘?C⇙, Mor = mor⇘?C⇙, Dom = Cod ?C, Cod = Dom ?C, Id = Category.Id ?C, Comp = λ(f::?'m::type) g::?'m::type. g ;;⇘?C⇙ f, … = more ?C⦈›*) Category_axioms_def (*‹Category_axioms (?C::(?'a, ?'b, ?'c) Category_scheme) ≡ ((∀f::?'b::type. f ∈ mor⇘?C⇙ ⟶ dom⇘?C⇙ f ∈ obj⇘?C⇙) ∧ (∀f::?'b::type. f ∈ mor⇘?C⇙ ⟶ cod⇘?C⇙ f ∈ obj⇘?C⇙) ∧ (∀X::?'a::type. X ∈ obj⇘?C⇙ ⟶ id⇘?C⇙ X maps⇘?C⇙ X to X)) ∧ ((∀f::?'b::type. f ∈ mor⇘?C⇙ ⟶ id⇘?C⇙ (dom⇘?C⇙ f) ;;⇘?C⇙ f = f) ∧ (∀f::?'b::type. f ∈ mor⇘?C⇙ ⟶ f ;;⇘?C⇙ id⇘?C⇙ (cod⇘?C⇙ f) = f)) ∧ (∀(f::?'b::type) (g::?'b::type) h::?'b::type. f ≈>⇘?C⇙ g ⟶ g ≈>⇘?C⇙ h ⟶ f ;;⇘?C⇙ g ;;⇘?C⇙ h = f ;;⇘?C⇙ (g ;;⇘?C⇙ h)) ∧ (∀(f::?'b::type) (X::?'a::type) (Y::?'a::type) (g::?'b::type) Z::?'a::type. f maps⇘?C⇙ X to Y ⟶ g maps⇘?C⇙ Y to Z ⟶ f ;;⇘?C⇙ g maps⇘?C⇙ X to Z)›*) MapsTo_def (*‹(?f::?'m::type) maps⇘?CC::(?'o, ?'m, ?'a) Category_scheme⇙ (?X::?'o::type) to (?Y::?'o::type) ≡ ?f ∈ mor⇘?CC⇙ ∧ dom⇘?CC⇙ ?f = ?X ∧ cod⇘?CC⇙ ?f = ?Y›*) CompDefined_def (*‹(?f::?'m::type) ≈>⇘?CC::(?'o, ?'m, ?'a) Category_scheme⇙ (?g::?'m::type) ≡ ?f ∈ mor⇘?CC⇙ ∧ ?g ∈ mor⇘?CC⇙ ∧ cod⇘?CC⇙ ?f = dom⇘?CC⇙ ?g›*)) lemma OpCatCatExt: "ExtCategory C ⟹ ExtCategory (Op C)" by (auto simp add: OppositeCategory_def (*‹Op ?C ≡ ⦇Obj = obj⇘?C⇙, Mor = mor⇘?C⇙, Dom = Cod ?C, Cod = Dom ?C, Id = Category.Id ?C, Comp = λf g. g ;;⇘?C⇙ f, … = more ?C⦈›*) ExtCategory_def (*‹ExtCategory ?C ≡ (Dom ?C ∈ extensional (mor⇘?C⇙) ∧ Cod ?C ∈ extensional (mor⇘?C⇙)) ∧ Category.Id ?C ∈ extensional (obj⇘?C⇙) ∧ (λ(x, y). x ;;⇘?C⇙ y) ∈ extensional {(f, g) |f g. f ≈>⇘?C⇙ g}›*) MapsTo_def (*‹?f maps⇘?CC⇙ ?X to ?Y ≡ ?f ∈ mor⇘?CC⇙ ∧ dom⇘?CC⇙ ?f = ?X ∧ cod⇘?CC⇙ ?f = ?Y›*) CompDefined_def (*‹?f ≈>⇘?CC⇙ ?g ≡ ?f ∈ mor⇘?CC⇙ ∧ ?g ∈ mor⇘?CC⇙ ∧ cod⇘?CC⇙ ?f = dom⇘?CC⇙ ?g›*) extensional_def (*‹extensional ?A = {f. ∀x. x ∉ ?A ⟶ f x = undefined}›*)) lemma OpCatCat: "Category C ⟹ Category (Op C)" apply intro_locales (*goals: 1. ‹Category C ⟹ ExtCategory (Op C)› 2. ‹Category C ⟹ Category_axioms (Op C)› discuss goal 1*) apply (simp add: Category_def (*‹Category ?C ≡ ExtCategory ?C ∧ Category_axioms ?C›*) OpCatCatAx (*‹Category_axioms ?C ⟹ Category_axioms (Op ?C)›*) OpCatCatExt (*‹ExtCategory ?C ⟹ ExtCategory (Op ?C)›*)) (*discuss goal 2*) apply (simp add: Category_def (*‹Category (?C::(?'a, ?'b, ?'c) Category_scheme) ≡ ExtCategory ?C ∧ Category_axioms ?C›*) OpCatCatAx (*‹Category_axioms (?C::(?'a, ?'b, ?'c) Category_scheme) ⟹ Category_axioms (Op ?C)›*) OpCatCatExt (*‹ExtCategory (?C::(?'a, ?'b, ?'c) Category_scheme) ⟹ ExtCategory (Op ?C)›*)) (*proven 2 subgoals*) . lemma MapsToOp: "f maps⇘C ⇙X to Y ⟹ f maps⇘Op C ⇙Y to X" by (simp add: MapsTo_def (*‹?f maps⇘?CC⇙ ?X to ?Y ≡ ?f ∈ mor⇘?CC⇙ ∧ dom⇘?CC⇙ ?f = ?X ∧ cod⇘?CC⇙ ?f = ?Y›*) OppositeCategory_def (*‹Op ?C ≡ ⦇Obj = obj⇘?C⇙, Mor = mor⇘?C⇙, Dom = Cod ?C, Cod = Dom ?C, Id = Category.Id ?C, Comp = λf g. g ;;⇘?C⇙ f, … = more ?C⦈›*)) lemma MapsToOpOp: "f maps⇘Op C ⇙X to Y ⟹ f maps⇘C ⇙Y to X" by (simp add: MapsTo_def (*‹(?f::?'m::type) maps⇘?CC::(?'o, ?'m, ?'a) Category_scheme⇙ (?X::?'o::type) to (?Y::?'o::type) ≡ ?f ∈ mor⇘?CC⇙ ∧ dom⇘?CC⇙ ?f = ?X ∧ cod⇘?CC⇙ ?f = ?Y›*) OppositeCategory_def (*‹Op (?C::(?'o, ?'m, ?'a) Category_scheme) ≡ ⦇Obj = obj⇘?C⇙, Mor = mor⇘?C⇙, Dom = Cod ?C, Cod = Dom ?C, Id = Category.Id ?C, Comp = λ(f::?'m::type) g::?'m::type. g ;;⇘?C⇙ f, … = more ?C⦈›*)) lemma CompDefOp: "f ≈>⇘C⇙ g ⟹ g ≈>⇘Op C⇙ f" by (simp add: CompDefined_def (*‹?f ≈>⇘?CC⇙ ?g ≡ ?f ∈ mor⇘?CC⇙ ∧ ?g ∈ mor⇘?CC⇙ ∧ cod⇘?CC⇙ ?f = dom⇘?CC⇙ ?g›*) OppositeCategory_def (*‹Op ?C ≡ ⦇Obj = obj⇘?C⇙, Mor = mor⇘?C⇙, Dom = Cod ?C, Cod = Dom ?C, Id = Category.Id ?C, Comp = λf g. g ;;⇘?C⇙ f, … = more ?C⦈›*)) end
{ "path": "afp-2025-02-12/thys/Category2/Category.thy", "repo": "afp-2025-02-12", "sha": "edbf406349a21f15ea803e694bdb72b2c584285c382301d907ccfa2ff8ed6482" }
section ‹The Hadjicostas--Chapman formula› theory Hadjicostas_Chapman imports Zeta_Laurent_Expansion begin text ‹ In this section, we will derive a formula for the ‹ζ› function that was conjectured by Hadjicostas~\<^cite>‹"hadjicostas2004"› and proven shortly afterwards by Chapman~\<^cite>‹"chapman2004"›. The formula is: \begin{align*} &\int_0^1 \int_0^1 \frac{(-\ln (xy))^z (1-x)}{1-xy}\ \text{d}x\,\text{d}y\\ &\quad = \int_0^1 \frac{(-\ln u)^z(-\ln u + u - 1)}{1-u}\ \text{d}u\\ &\quad = \Gamma(z + 2) \left(\zeta(z + 2) - \frac{1}{z+1}\right) \end{align*} for any ‹z› with $\mathfrak{R}(z) > -2$. In particular, setting $z = 1$, we can derive the following formula for the Euler--Mascheroni constant ‹γ›: \[-\int_0^1 \int_0^1 \frac{1-x}{(1-xy) \ln (xy)}\ \text{d}x\,\text{d}y = \gamma\] This formula was first proven by Sondow~\<^cite>‹"sondow2002"›. › subsection ‹The real case› text ‹ We first define the integral for real ‹z > -2›. This is then a non-negative integral, so that we can ignore the issue of integrability and use the Lebesgue integral on the extended non-negative reals We first show the equivalence of the single-integral and the double-integral form. › definition Hadjicostas_nn_integral :: "real ⇒ ennreal" where "Hadjicostas_nn_integral z = set_nn_integral lborel {0<..<1} (λu. ennreal ((-ln u) powr z / (1 - u) * (-ln u + u - 1)))" definition Hadjicostas_integral :: "complex ⇒ complex" where "Hadjicostas_integral z = (LBINT u=0..1. of_real (-ln u) powr z / of_real (1 - u) * of_real (-ln u + u - 1))" lemma Hadjicostas_nn_integral_altdef: "Hadjicostas_nn_integral z = (∫⁺(x,y)∈{0<..<1}×{0<..<1}. ((-ln (x*y)) powr z * (1-x) / (1-x*y)) ∂lborel)" proof (-) (*goal: ‹Hadjicostas_nn_integral z = (∫⁺x∈{0<..<1} × {0<..<1}. ennreal (case x of (x, y) ⇒ (- ln (x * y)) powr z * (1 - x) / (1 - x * y))∂lborel)›*) define f where "f ≡ (λu. ((-ln u) powr z / (1 - u) * (-ln u + u - 1)))" let ?I = "Gamma (z + 2) * (Re (zeta (z + 2)) - 1 / (z + 1))" let ?f = "λu. ((-ln u) powr z / (1 - u) * (-ln u + u - 1))" define D :: "(real × real) set" where "D = {0<..<1} × {0<..<1}" define D1 where "D1 = (SIGMA x:{0<..<1}. {0<..<(x::real)})" define D2 where "D2 = (SIGMA u:{0<..<1}. {u<..<(1::real)})" have [measurable]: "D1 ∈ sets (lborel ⨂⇩M lborel)" proof (-) (*goal: ‹(D1::(real × real) set) ∈ sets (lborel ⨂⇩M lborel)›*) have "D1 = {x∈space (lborel ⨂⇩M lborel). snd x > 0 ∧ fst x > snd x ∧ fst x < 1}" by (auto simp: D1_def (*‹D1 = Sigma {0<..<1} (greaterThanLessThan 0)›*) space_pair_measure (*‹space (?A ⨂⇩M ?B) = space ?A × space ?B›*)) also (*calculation: ‹D1 = {x ∈ space (lborel ⨂⇩M lborel). 0 < snd x ∧ snd x < fst x ∧ fst x < 1}›*) have "… ∈ sets (lborel ⨂⇩M lborel)" by measurable finally (*calculation: ‹D1 ∈ sets (lborel ⨂⇩M lborel)›*) show "?thesis" (*goal: ‹D1 ∈ sets (lborel ⨂⇩M lborel)›*) . qed have [measurable]: "D2 ∈ sets (lborel ⨂⇩M lborel)" proof (-) (*goal: ‹D2 ∈ sets (lborel ⨂⇩M lborel)›*) have "D2 = {x∈space (lborel ⨂⇩M lborel). fst x > 0 ∧ fst x < snd x ∧ snd x < 1}" by (auto simp: D2_def (*‹D2 = (SIGMA u:{0<..<1}. {u<..<1})›*) space_pair_measure (*‹space (?A ⨂⇩M ?B) = space ?A × space ?B›*)) also (*calculation: ‹(D2::(real × real) set) = {x::real × real ∈ space (lborel ⨂⇩M lborel). (0::real) < fst x ∧ fst x < snd x ∧ snd x < (1::real)}›*) have "… ∈ sets (lborel ⨂⇩M lborel)" by measurable finally (*calculation: ‹D2 ∈ sets (lborel ⨂⇩M lborel)›*) show "?thesis" (*goal: ‹D2 ∈ sets (lborel ⨂⇩M lborel)›*) . qed have "(∫⁺(x,y)∈D. ((-ln (x*y)) powr z * (1-x) / (1-x*y)) ∂lborel) = (∫⁺x∈{0<..<1}. (∫⁺y∈{0<..<1}. ((-ln (x*y)) powr z / (1-x*y) * (1-x)) ∂lborel) ∂lborel)" unfolding lborel_prod[symmetric] case_prod_unfold D_def (*goal: ‹(∫⁺x∈{0<..<1} × {0<..<1}. ennreal ((- ln (fst x * snd x)) powr z * (1 - fst x) / (1 - fst x * snd x))∂(lborel ⨂⇩M lborel)) = (∫⁺x∈{0<..<1}. ∫⁺xa∈{0<..<1}. ennreal ((- ln (x * xa)) powr z / (1 - x * xa) * (1 - x))∂lborel∂lborel)›*) apply (subst lborel.nn_integral_fst[symmetric] (*‹(?f::?'b × ?'a ⇒ ennreal) ∈ borel_measurable ((?M1.0::?'b measure) ⨂⇩M lborel) ⟹ integral⇧N (?M1.0 ⨂⇩M lborel) ?f = ∫⁺ (x::?'b). ∫⁺ (y::?'a). ?f (x, y) ∂lborel ∂?M1.0›*)) (*goals: 1. ‹(λx. ennreal ((- ln (fst x * snd x)) powr z * (1 - fst x) / (1 - fst x * snd x)) * indicator ({0<..<1} × {0<..<1}) x) ∈ borel_measurable (lborel ⨂⇩M lborel)› 2. ‹∫⁺ x. ∫⁺ y. ennreal ((- ln (fst (x, y) * snd (x, y))) powr z * (1 - fst (x, y)) / (1 - fst (x, y) * snd (x, y))) * indicator ({0<..<1} × {0<..<1}) (x, y) ∂lborel ∂lborel = (∫⁺x∈{0<..<1}. ∫⁺xa∈{0<..<1}. ennreal ((- ln (x * xa)) powr z / (1 - x * xa) * (1 - x))∂lborel∂lborel)› discuss goal 1*) apply ((auto intro!: nn_integral_cong (*‹(⋀x. x ∈ space ?M ⟹ ?u x = ?v x) ⟹ integral⇧N ?M ?u = integral⇧N ?M ?v›*) simp: indicator_def (*‹indicator ?S ?x = of_bool (?x ∈ ?S)›*))[1]) (*discuss goal 2*) apply ((auto intro!: nn_integral_cong (*‹(⋀x. x ∈ space ?M ⟹ ?u x = ?v x) ⟹ integral⇧N ?M ?u = integral⇧N ?M ?v›*) simp: indicator_def (*‹indicator ?S ?x = of_bool (?x ∈ ?S)›*))[1]) (*proven 2 subgoals*) . also (*calculation: ‹(∫⁺x∈D. ennreal (case x of (x, y) ⇒ (- ln (x * y)) powr z * (1 - x) / (1 - x * y))∂lborel) = (∫⁺x∈{0<..<1}. ∫⁺xa∈{0<..<1}. ennreal ((- ln (x * xa)) powr z / (1 - x * xa) * (1 - x))∂lborel∂lborel)›*) have "… = (∫⁺x∈{0<..<1}. (∫⁺u∈{0<..<x}. ((- ln u) powr z / (1 - u) * (1 - x) / x) ∂lborel) ∂lborel)" proof (rule set_nn_integral_cong (*‹⟦?M = ?M'; ?A = ?B; ⋀x. x ∈ space ?M ∩ ?A ⟹ ?f x = ?g x⟧ ⟹ set_nn_integral ?M ?A ?f = set_nn_integral ?M' ?B ?g›*)) (*goals: 1. ‹lborel = lborel› 2. ‹{0<..<1} = {0<..<1}› 3. ‹⋀x. x ∈ space lborel ∩ {0<..<1} ⟹ (∫⁺xa∈{0<..<1}. ennreal ((- ln (x * xa)) powr z / (1 - x * xa) * (1 - x))∂lborel) = (∫⁺xa∈{0<..<x}. ennreal ((- ln xa) powr z / (1 - xa) * (1 - x) / x)∂lborel)›*) fix x :: real assume x: "x ∈ space lborel ∩ {0<..<1}" (*‹(x::real) ∈ space lborel ∩ {0::real<..<1::real}›*) show "(∫⁺y∈{0<..<1}. ((-ln (x*y)) powr z / (1-x*y) * (1-x)) ∂lborel) = (∫⁺u∈{0<..<x}. ((- ln u) powr z / (1 - u) * (1 - x) / x) ∂lborel)" using x (*‹x ∈ space lborel ∩ {0<..<1}›*) apply (subst lborel_distr_mult'[of "1/x"] (*‹1 / x ≠ 0 ⟹ lborel = density (distr lborel borel ((*) (1 / x))) (λxa. ennreal ¦1 / x¦)›*)) (*goals: 1. ‹x ∈ space lborel ∩ {0<..<1} ⟹ 1 / x ≠ 0› 2. ‹x ∈ space lborel ∩ {0<..<1} ⟹ (∫⁺xa∈{0<..<1}. ennreal ((- ln (x * xa)) powr z / (1 - x * xa) * (1 - x))∂density (distr lborel borel ((*) (1 / x))) (λxa. ennreal ¦1 / x¦)) = (∫⁺xa∈{0<..<x}. ennreal ((- ln xa) powr z / (1 - xa) * (1 - x) / x)∂lborel)› discuss goal 1*) apply ((auto simp: nn_integral_density (*‹⟦?f ∈ borel_measurable ?M; ?g ∈ borel_measurable ?M⟧ ⟹ integral⇧N (density ?M ?f) ?g = ∫⁺ x. ?f x * ?g x ∂?M›*) nn_integral_distr (*‹⟦?T ∈ ?M →⇩M ?M'; ?f ∈ borel_measurable (distr ?M ?M' ?T)⟧ ⟹ integral⇧N (distr ?M ?M' ?T) ?f = ∫⁺ x. ?f (?T x) ∂?M›*) indicator_def (*‹indicator ?S ?x = of_bool (?x ∈ ?S)›*) field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 77 facts*) simp flip: ennreal_mult' (*‹0 ≤ ?a ⟹ ennreal (?a * ?b) = ennreal ?a * ennreal ?b›*) intro!: nn_integral_cong (*‹(⋀x. x ∈ space ?M ⟹ ?u x = ?v x) ⟹ integral⇧N ?M ?u = integral⇧N ?M ?v›*))[1]) (*discuss goal 2*) apply ((auto simp: nn_integral_density (*‹⟦?f ∈ borel_measurable ?M; ?g ∈ borel_measurable ?M⟧ ⟹ integral⇧N (density ?M ?f) ?g = ∫⁺ x. ?f x * ?g x ∂?M›*) nn_integral_distr (*‹⟦?T ∈ ?M →⇩M ?M'; ?f ∈ borel_measurable (distr ?M ?M' ?T)⟧ ⟹ integral⇧N (distr ?M ?M' ?T) ?f = ∫⁺ x. ?f (?T x) ∂?M›*) indicator_def (*‹indicator ?S ?x = of_bool (?x ∈ ?S)›*) field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 77 facts*) simp flip: ennreal_mult' (*‹0 ≤ ?a ⟹ ennreal (?a * ?b) = ennreal ?a * ennreal ?b›*) intro!: nn_integral_cong (*‹(⋀x. x ∈ space ?M ⟹ ?u x = ?v x) ⟹ integral⇧N ?M ?u = integral⇧N ?M ?v›*))[1]) (*proven 2 subgoals*) . qed (auto) (*solves the remaining goals: 1. ‹lborel = lborel› 2. ‹{0<..<1} = {0<..<1}›*) also (*calculation: ‹(∫⁺x∈D. ennreal (case x of (x, y) ⇒ (- ln (x * y)) powr z * (1 - x) / (1 - x * y))∂lborel) = (∫⁺x∈{0<..<1}. ∫⁺xa∈{0<..<x}. ennreal ((- ln xa) powr z / (1 - xa) * (1 - x) / x)∂lborel∂lborel)›*) have "… = (∫⁺(x,u)∈D1. ((- ln u) powr z / (1 - u) * (1 - x) / x) ∂lborel)" unfolding lborel_prod[symmetric] case_prod_unfold D_def (*goal: ‹(∫⁺x::real∈{0::real<..<1::real}. ∫⁺xa::real∈{0::real<..<x}. ennreal ((- ln xa) powr (z::real) / ((1::real) - xa) * ((1::real) - x) / x)∂lborel∂lborel) = (∫⁺x::real × real∈D1::(real × real) set. ennreal ((- ln (snd x)) powr z / ((1::real) - snd x) * ((1::real) - fst x) / fst x)∂(lborel ⨂⇩M lborel))›*) apply (subst lborel.nn_integral_fst[symmetric] (*‹?f ∈ borel_measurable (?M1.0 ⨂⇩M lborel) ⟹ integral⇧N (?M1.0 ⨂⇩M lborel) ?f = ∫⁺ x. ∫⁺ y. ?f (x, y) ∂lborel ∂?M1.0›*)) (*goals: 1. ‹(λx. ennreal ((- ln (snd x)) powr z / (1 - snd x) * (1 - fst x) / fst x) * indicator D1 x) ∈ borel_measurable (lborel ⨂⇩M lborel)› 2. ‹(∫⁺x∈{0<..<1}. ∫⁺xa∈{0<..<x}. ennreal ((- ln xa) powr z / (1 - xa) * (1 - x) / x)∂lborel∂lborel) = ∫⁺ x. ∫⁺ y. ennreal ((- ln (snd (x, y))) powr z / (1 - snd (x, y)) * (1 - fst (x, y)) / fst (x, y)) * indicator D1 (x, y) ∂lborel ∂lborel› discuss goal 1*) apply measurable (*discuss goal 2*) apply (auto intro!: nn_integral_cong (*‹(⋀x. x ∈ space ?M ⟹ ?u x = ?v x) ⟹ integral⇧N ?M ?u = integral⇧N ?M ?v›*) simp: indicator_def (*‹indicator ?S ?x = of_bool (?x ∈ ?S)›*) D1_def (*‹D1 = Sigma {0<..<1} (greaterThanLessThan 0)›*)) (*proven 2 subgoals*) . also (*calculation: ‹(∫⁺x∈D. ennreal (case x of (x, y) ⇒ (- ln (x * y)) powr z * (1 - x) / (1 - x * y))∂lborel) = (∫⁺x∈D1. ennreal (case x of (x, u) ⇒ (- ln u) powr z / (1 - u) * (1 - x) / x)∂lborel)›*) have "… = (∫⁺(x,u). indicator D2 (u,x) * ((- ln u) powr z / (1 - u) * (1 - x) / x) ∂lborel)" apply (intro nn_integral_cong (*‹(⋀x. x ∈ space ?M ⟹ ?u x = ?v x) ⟹ integral⇧N ?M ?u = integral⇧N ?M ?v›*)) (*goal: ‹(∫⁺x∈D1. ennreal (case x of (x, u) ⇒ (- ln u) powr z / (1 - u) * (1 - x) / x)∂lborel) = ∫⁺ x. ennreal (case x of (x, u) ⇒ indicat_real D2 (u, x) * ((- ln u) powr z / (1 - u) * (1 - x) / x)) ∂lborel›*) by (auto simp: D1_def (*‹D1 = Sigma {0<..<1} (greaterThanLessThan 0)›*) D2_def (*‹D2 = (SIGMA u:{0<..<1}. {u<..<1})›*) indicator_def (*‹indicator ?S ?x = of_bool (?x ∈ ?S)›*) split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) also (*calculation: ‹(∫⁺x∈D. ennreal (case x of (x, y) ⇒ (- ln (x * y)) powr z * (1 - x) / (1 - x * y))∂lborel) = ∫⁺ x. ennreal (case x of (x, u) ⇒ indicat_real D2 (u, x) * ((- ln u) powr z / (1 - u) * (1 - x) / x)) ∂lborel›*) have "… = (∫⁺u∈{0<..<1}. (∫⁺x∈{u<..<1}. ((- ln u) powr z / (1 - u) * (1 - x) / x) ∂lborel) ∂lborel)" unfolding case_prod_unfold lborel_prod[symmetric] (*goal: ‹∫⁺ x. ennreal (indicat_real D2 (snd x, fst x) * ((- ln (snd x)) powr z / (1 - snd x) * (1 - fst x) / fst x)) ∂lborel ⨂⇩M lborel = (∫⁺x∈{0<..<1}. ∫⁺xa∈{x<..<1}. ennreal ((- ln x) powr z / (1 - x) * (1 - xa) / xa)∂lborel∂lborel)›*) apply (subst lborel_pair.nn_integral_snd [symmetric] (*‹(?f::?'a × ?'b ⇒ ennreal) ∈ borel_measurable (lborel ⨂⇩M lborel) ⟹ integral⇧N (lborel ⨂⇩M lborel) ?f = ∫⁺ (y::?'b). ∫⁺ (x::?'a). ?f (x, y) ∂lborel ∂lborel›*)) (*goals: 1. ‹(λx. ennreal (indicat_real D2 (snd x, fst x) * ((- ln (snd x)) powr z / (1 - snd x) * (1 - fst x) / fst x))) ∈ borel_measurable (lborel ⨂⇩M lborel)› 2. ‹∫⁺ y. ∫⁺ x. ennreal (indicat_real D2 (snd (x, y), fst (x, y)) * ((- ln (snd (x, y))) powr z / (1 - snd (x, y)) * (1 - fst (x, y)) / fst (x, y))) ∂lborel ∂lborel = (∫⁺x∈{0<..<1}. ∫⁺xa∈{x<..<1}. ennreal ((- ln x) powr z / (1 - x) * (1 - xa) / xa)∂lborel∂lborel)› discuss goal 1*) apply measurable (*discuss goal 2*) apply (auto intro!: nn_integral_cong (*‹(⋀x. x ∈ space ?M ⟹ ?u x = ?v x) ⟹ integral⇧N ?M ?u = integral⇧N ?M ?v›*) simp: D2_def (*‹D2 = (SIGMA u:{0<..<1}. {u<..<1})›*) indicator_def (*‹indicator ?S ?x = of_bool (?x ∈ ?S)›*)) (*proven 2 subgoals*) . also (*calculation: ‹(∫⁺x∈D. ennreal (case x of (x, y) ⇒ (- ln (x * y)) powr z * (1 - x) / (1 - x * y))∂lborel) = (∫⁺x∈{0<..<1}. ∫⁺xa∈{x<..<1}. ennreal ((- ln x) powr z / (1 - x) * (1 - xa) / xa)∂lborel∂lborel)›*) have "… = (∫⁺u∈{0<..<1}. ((-ln u) powr z / (1 - u) * (-ln u + u - 1)) ∂lborel)" proof (intro set_nn_integral_cong (*‹⟦?M = ?M'; ?A = ?B; ⋀x. x ∈ space ?M ∩ ?A ⟹ ?f x = ?g x⟧ ⟹ set_nn_integral ?M ?A ?f = set_nn_integral ?M' ?B ?g›*) refl (*‹?t = ?t›*)) (*goal: ‹⋀x. x ∈ space lborel ∩ {0<..<1} ⟹ (∫⁺xa∈{x<..<1}. ennreal ((- ln x) powr z / (1 - x) * (1 - xa) / xa)∂lborel) = ennreal ((- ln x) powr z / (1 - x) * (- ln x + x - 1))›*) fix u :: real assume u: "u ∈ space lborel ∩ {0<..<1}" (*‹(u::real) ∈ space lborel ∩ {0::real<..<1::real}›*) let ?F = "λx. (- ln u) powr z / (1 - u) * (ln x - x)" have "(∫⁺x∈{u<..<1}. ennreal ((- ln u) powr z / (1 - u) * (1 - x) / x) ∂lborel) = (∫⁺x∈{u..1}. ennreal ((- ln u) powr z / (1 - u) * (1 - x) / x) ∂lborel)" apply (rule nn_integral_cong_AE (*‹AE x in ?M. ?u x = ?v x ⟹ integral⇧N ?M ?u = integral⇧N ?M ?v›*)) (*goal: ‹(∫⁺x∈{u<..<1}. ennreal ((- ln u) powr z / (1 - u) * (1 - x) / x)∂lborel) = (∫⁺x∈{u..1}. ennreal ((- ln u) powr z / (1 - u) * (1 - x) / x)∂lborel)›*) apply (rule AE_I[of _ _ "{u,1}"] (*‹⟦{x ∈ space ?M. ¬ ?P x} ⊆ {u, 1}; emeasure ?M {u, 1} = 0; {u, 1} ∈ sets ?M⟧ ⟹ almost_everywhere ?M ?P›*)) (*goals: 1. ‹{x ∈ space lborel. ennreal ((- ln u) powr z / (1 - u) * (1 - x) / x) * indicator {u<..<1} x ≠ ennreal ((- ln u) powr z / (1 - u) * (1 - x) / x) * indicator {u..1} x} ⊆ {u, 1}› 2. ‹emeasure lborel {u, 1} = 0› 3. ‹{u, 1} ∈ sets lborel› discuss goal 1*) apply ((auto simp: emeasure_lborel_countable (*‹countable ?A ⟹ emeasure lborel ?A = 0›*) indicator_def (*‹indicator ?S ?x = of_bool (?x ∈ ?S)›*))[1]) (*discuss goal 2*) apply ((auto simp: emeasure_lborel_countable (*‹countable ?A ⟹ emeasure lborel ?A = 0›*) indicator_def (*‹indicator ?S ?x = of_bool (?x ∈ ?S)›*))[1]) (*discuss goal 3*) apply ((auto simp: emeasure_lborel_countable (*‹countable ?A ⟹ emeasure lborel ?A = 0›*) indicator_def (*‹indicator ?S ?x = of_bool (?x ∈ ?S)›*))[1]) (*proven 3 subgoals*) . also (*calculation: ‹(∫⁺x∈{u<..<1}. ennreal ((- ln u) powr z / (1 - u) * (1 - x) / x)∂lborel) = (∫⁺x∈{u..1}. ennreal ((- ln u) powr z / (1 - u) * (1 - x) / x)∂lborel)›*) have "… = ennreal (?F 1 - ?F u)" using u (*‹u ∈ space lborel ∩ {0<..<1}›*) apply (intro nn_integral_FTC_Icc (*‹⟦?f ∈ borel_measurable borel; ⋀x. x ∈ {?a..?b} ⟹ (?F has_real_derivative ?f x) (at x); ⋀x. x ∈ {?a..?b} ⟹ 0 ≤ ?f x; ?a ≤ ?b⟧ ⟹ (∫⁺x∈{?a..?b}. ennreal (?f x)∂lborel) = ennreal (?F ?b - ?F ?a)›*)) (*goals: 1. ‹(u::real) ∈ space lborel ∩ {0::real<..<1::real} ⟹ (λx::real. (- ln u) powr (z::real) / ((1::real) - u) * ((1::real) - x) / x) ∈ borel_measurable borel› 2. ‹⋀x::real. ⟦(u::real) ∈ space lborel ∩ {0::real<..<1::real}; x ∈ {u..1::real}⟧ ⟹ ((λa::real. (- ln u) powr (z::real) / ((1::real) - u) * (ln a - a)) has_real_derivative (- ln u) powr z / ((1::real) - u) * ((1::real) - x) / x) (at x)› 3. ‹⋀x::real. ⟦(u::real) ∈ space lborel ∩ {0::real<..<1::real}; x ∈ {u..1::real}⟧ ⟹ (0::real) ≤ (- ln u) powr (z::real) / ((1::real) - u) * ((1::real) - x) / x› 4. ‹(u::real) ∈ space lborel ∩ {0::real<..<1::real} ⟹ u ≤ (1::real)› discuss goal 1*) apply ((auto intro!: derivative_eq_intros (*‹(λx. x) = ?g' ⟹ ((λx. x) has_derivative ?g') ?F› ‹id = ?g' ⟹ (id has_derivative ?g') ?F› ‹(λx. 0) = ?g' ⟹ ((λx. ?f2) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?r1 *⇩R ?g'1 x) = ?g'⟧ ⟹ ((λx. ?r1 *⇩R ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x *⇩R ?x1) = ?g'⟧ ⟹ ((λx. ?g1 x *⇩R ?x1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?x1 * ?g'1 x) = ?g'⟧ ⟹ ((λx. ?x1 * ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x * ?y1) = ?g'⟧ ⟹ ((λx. ?g1 x * ?y1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. of_real (?g'1 x)) = ?g'⟧ ⟹ ((λx. of_real (?g1 x)) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x + ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x + ?g1 x) has_derivative ?g') ?F› ‹⟦⋀i. i ∈ ?I1 ⟹ (?f1 i has_derivative ?f'1 i) ?F; (λx. ∑i∈?I1. ?f'1 i x) = ?g'⟧ ⟹ ((λx. ∑i∈?I1. ?f1 i x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (λx. - ?f'1 x) = ?g'⟧ ⟹ ((λx. - ?f1 x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x - ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x - ?g1 x) has_derivative ?g') ?F› and more 140 facts*) simp: divide_simps (*‹inverse ?a = 1 / ?a› ‹?a + ?b / ?z = (if ?z = 0 then ?a else (?a * ?z + ?b) / ?z)› ‹?a / ?z + ?b = (if ?z = 0 then ?b else (?a + ?b * ?z) / ?z)› ‹- (?a / ?z) + ?b = (if ?z = 0 then ?b else (- ?a + ?b * ?z) / ?z)› ‹?a - ?b / ?z = (if ?z = 0 then ?a else (?a * ?z - ?b) / ?z)› ‹?a / ?z - ?b = (if ?z = 0 then - ?b else (?a - ?b * ?z) / ?z)› ‹- (?a / ?z) - ?b = (if ?z = 0 then - ?b else (- ?a - ?b * ?z) / ?z)› ‹(?b / ?c = ?a) = (if ?c ≠ 0 then ?b = ?a * ?c else ?a = 0)› ‹(?a = ?b / ?c) = (if ?c ≠ 0 then ?a * ?c = ?b else ?a = 0)› ‹(- (?b / ?c) = ?a) = (if ?c ≠ 0 then - ?b = ?a * ?c else ?a = 0)› ‹(?a = - (?b / ?c)) = (if ?c ≠ 0 then ?a * ?c = - ?b else ?a = 0)› ‹(?a ≤ ?b / ?c) = (if 0 < ?c then ?a * ?c ≤ ?b else if ?c < 0 then ?b ≤ ?a * ?c else ?a ≤ 0)› and more 13 facts*))[1]) (*discuss goal 2*) apply ((auto intro!: derivative_eq_intros (*‹(λx. x) = ?g' ⟹ ((λx. x) has_derivative ?g') ?F› ‹id = ?g' ⟹ (id has_derivative ?g') ?F› ‹(λx. 0) = ?g' ⟹ ((λx. ?f2) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?r1 *⇩R ?g'1 x) = ?g'⟧ ⟹ ((λx. ?r1 *⇩R ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x *⇩R ?x1) = ?g'⟧ ⟹ ((λx. ?g1 x *⇩R ?x1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?x1 * ?g'1 x) = ?g'⟧ ⟹ ((λx. ?x1 * ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x * ?y1) = ?g'⟧ ⟹ ((λx. ?g1 x * ?y1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. of_real (?g'1 x)) = ?g'⟧ ⟹ ((λx. of_real (?g1 x)) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x + ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x + ?g1 x) has_derivative ?g') ?F› ‹⟦⋀i. i ∈ ?I1 ⟹ (?f1 i has_derivative ?f'1 i) ?F; (λx. ∑i∈?I1. ?f'1 i x) = ?g'⟧ ⟹ ((λx. ∑i∈?I1. ?f1 i x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (λx. - ?f'1 x) = ?g'⟧ ⟹ ((λx. - ?f1 x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x - ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x - ?g1 x) has_derivative ?g') ?F› and more 140 facts*) simp: divide_simps (*‹inverse ?a = 1 / ?a› ‹?a + ?b / ?z = (if ?z = 0 then ?a else (?a * ?z + ?b) / ?z)› ‹?a / ?z + ?b = (if ?z = 0 then ?b else (?a + ?b * ?z) / ?z)› ‹- (?a / ?z) + ?b = (if ?z = 0 then ?b else (- ?a + ?b * ?z) / ?z)› ‹?a - ?b / ?z = (if ?z = 0 then ?a else (?a * ?z - ?b) / ?z)› ‹?a / ?z - ?b = (if ?z = 0 then - ?b else (?a - ?b * ?z) / ?z)› ‹- (?a / ?z) - ?b = (if ?z = 0 then - ?b else (- ?a - ?b * ?z) / ?z)› ‹(?b / ?c = ?a) = (if ?c ≠ 0 then ?b = ?a * ?c else ?a = 0)› ‹(?a = ?b / ?c) = (if ?c ≠ 0 then ?a * ?c = ?b else ?a = 0)› ‹(- (?b / ?c) = ?a) = (if ?c ≠ 0 then - ?b = ?a * ?c else ?a = 0)› ‹(?a = - (?b / ?c)) = (if ?c ≠ 0 then ?a * ?c = - ?b else ?a = 0)› ‹(?a ≤ ?b / ?c) = (if 0 < ?c then ?a * ?c ≤ ?b else if ?c < 0 then ?b ≤ ?a * ?c else ?a ≤ 0)› and more 13 facts*))[1]) (*discuss goal 3*) apply ((auto intro!: derivative_eq_intros (*‹(λx. x) = ?g' ⟹ ((λx. x) has_derivative ?g') ?F› ‹id = ?g' ⟹ (id has_derivative ?g') ?F› ‹(λx. 0) = ?g' ⟹ ((λx. ?f2) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?r1 *⇩R ?g'1 x) = ?g'⟧ ⟹ ((λx. ?r1 *⇩R ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x *⇩R ?x1) = ?g'⟧ ⟹ ((λx. ?g1 x *⇩R ?x1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?x1 * ?g'1 x) = ?g'⟧ ⟹ ((λx. ?x1 * ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x * ?y1) = ?g'⟧ ⟹ ((λx. ?g1 x * ?y1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. of_real (?g'1 x)) = ?g'⟧ ⟹ ((λx. of_real (?g1 x)) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x + ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x + ?g1 x) has_derivative ?g') ?F› ‹⟦⋀i. i ∈ ?I1 ⟹ (?f1 i has_derivative ?f'1 i) ?F; (λx. ∑i∈?I1. ?f'1 i x) = ?g'⟧ ⟹ ((λx. ∑i∈?I1. ?f1 i x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (λx. - ?f'1 x) = ?g'⟧ ⟹ ((λx. - ?f1 x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x - ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x - ?g1 x) has_derivative ?g') ?F› and more 140 facts*) simp: divide_simps (*‹inverse ?a = 1 / ?a› ‹?a + ?b / ?z = (if ?z = 0 then ?a else (?a * ?z + ?b) / ?z)› ‹?a / ?z + ?b = (if ?z = 0 then ?b else (?a + ?b * ?z) / ?z)› ‹- (?a / ?z) + ?b = (if ?z = 0 then ?b else (- ?a + ?b * ?z) / ?z)› ‹?a - ?b / ?z = (if ?z = 0 then ?a else (?a * ?z - ?b) / ?z)› ‹?a / ?z - ?b = (if ?z = 0 then - ?b else (?a - ?b * ?z) / ?z)› ‹- (?a / ?z) - ?b = (if ?z = 0 then - ?b else (- ?a - ?b * ?z) / ?z)› ‹(?b / ?c = ?a) = (if ?c ≠ 0 then ?b = ?a * ?c else ?a = 0)› ‹(?a = ?b / ?c) = (if ?c ≠ 0 then ?a * ?c = ?b else ?a = 0)› ‹(- (?b / ?c) = ?a) = (if ?c ≠ 0 then - ?b = ?a * ?c else ?a = 0)› ‹(?a = - (?b / ?c)) = (if ?c ≠ 0 then ?a * ?c = - ?b else ?a = 0)› ‹(?a ≤ ?b / ?c) = (if 0 < ?c then ?a * ?c ≤ ?b else if ?c < 0 then ?b ≤ ?a * ?c else ?a ≤ 0)› and more 13 facts*))[1]) (*discuss goal 4*) apply ((auto intro!: derivative_eq_intros (*‹(λx. x) = ?g' ⟹ ((λx. x) has_derivative ?g') ?F› ‹id = ?g' ⟹ (id has_derivative ?g') ?F› ‹(λx. 0) = ?g' ⟹ ((λx. ?f2) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?r1 *⇩R ?g'1 x) = ?g'⟧ ⟹ ((λx. ?r1 *⇩R ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x *⇩R ?x1) = ?g'⟧ ⟹ ((λx. ?g1 x *⇩R ?x1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?x1 * ?g'1 x) = ?g'⟧ ⟹ ((λx. ?x1 * ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x * ?y1) = ?g'⟧ ⟹ ((λx. ?g1 x * ?y1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. of_real (?g'1 x)) = ?g'⟧ ⟹ ((λx. of_real (?g1 x)) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x + ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x + ?g1 x) has_derivative ?g') ?F› ‹⟦⋀i. i ∈ ?I1 ⟹ (?f1 i has_derivative ?f'1 i) ?F; (λx. ∑i∈?I1. ?f'1 i x) = ?g'⟧ ⟹ ((λx. ∑i∈?I1. ?f1 i x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (λx. - ?f'1 x) = ?g'⟧ ⟹ ((λx. - ?f1 x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x - ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x - ?g1 x) has_derivative ?g') ?F› and more 140 facts*) simp: divide_simps (*‹inverse ?a = 1 / ?a› ‹?a + ?b / ?z = (if ?z = 0 then ?a else (?a * ?z + ?b) / ?z)› ‹?a / ?z + ?b = (if ?z = 0 then ?b else (?a + ?b * ?z) / ?z)› ‹- (?a / ?z) + ?b = (if ?z = 0 then ?b else (- ?a + ?b * ?z) / ?z)› ‹?a - ?b / ?z = (if ?z = 0 then ?a else (?a * ?z - ?b) / ?z)› ‹?a / ?z - ?b = (if ?z = 0 then - ?b else (?a - ?b * ?z) / ?z)› ‹- (?a / ?z) - ?b = (if ?z = 0 then - ?b else (- ?a - ?b * ?z) / ?z)› ‹(?b / ?c = ?a) = (if ?c ≠ 0 then ?b = ?a * ?c else ?a = 0)› ‹(?a = ?b / ?c) = (if ?c ≠ 0 then ?a * ?c = ?b else ?a = 0)› ‹(- (?b / ?c) = ?a) = (if ?c ≠ 0 then - ?b = ?a * ?c else ?a = 0)› ‹(?a = - (?b / ?c)) = (if ?c ≠ 0 then ?a * ?c = - ?b else ?a = 0)› ‹(?a ≤ ?b / ?c) = (if 0 < ?c then ?a * ?c ≤ ?b else if ?c < 0 then ?b ≤ ?a * ?c else ?a ≤ 0)› and more 13 facts*))[1]) (*proven 4 subgoals*) . also (*calculation: ‹(∫⁺x::real∈{u::real<..<1::real}. ennreal ((- ln u) powr (z::real) / ((1::real) - u) * ((1::real) - x) / x)∂lborel) = ennreal ((- ln u) powr z / ((1::real) - u) * (ln (1::real) - (1::real)) - (- ln u) powr z / ((1::real) - u) * (ln u - u))›*) have "?F 1 - ?F u = (-ln u) powr z / (1 - u) * (-ln u + u - 1)" using u (*‹u ∈ space lborel ∩ {0<..<1}›*) apply (simp add: divide_simps (*‹inverse ?a = 1 / ?a› ‹?a + ?b / ?z = (if ?z = 0 then ?a else (?a * ?z + ?b) / ?z)› ‹?a / ?z + ?b = (if ?z = 0 then ?b else (?a + ?b * ?z) / ?z)› ‹- (?a / ?z) + ?b = (if ?z = 0 then ?b else (- ?a + ?b * ?z) / ?z)› ‹?a - ?b / ?z = (if ?z = 0 then ?a else (?a * ?z - ?b) / ?z)› ‹?a / ?z - ?b = (if ?z = 0 then - ?b else (?a - ?b * ?z) / ?z)› ‹- (?a / ?z) - ?b = (if ?z = 0 then - ?b else (- ?a - ?b * ?z) / ?z)› ‹(?b / ?c = ?a) = (if ?c ≠ 0 then ?b = ?a * ?c else ?a = 0)› ‹(?a = ?b / ?c) = (if ?c ≠ 0 then ?a * ?c = ?b else ?a = 0)› ‹(- (?b / ?c) = ?a) = (if ?c ≠ 0 then - ?b = ?a * ?c else ?a = 0)› ‹(?a = - (?b / ?c)) = (if ?c ≠ 0 then ?a * ?c = - ?b else ?a = 0)› ‹(?a ≤ ?b / ?c) = (if 0 < ?c then ?a * ?c ≤ ?b else if ?c < 0 then ?b ≤ ?a * ?c else ?a ≤ 0)› and more 13 facts*)) (*goal: ‹(- ln (u::real)) powr (z::real) / ((1::real) - u) * (ln (1::real) - (1::real)) - (- ln u) powr z / ((1::real) - u) * (ln u - u) = (- ln u) powr z / ((1::real) - u) * (- ln u + u - (1::real))›*) by (simp add: algebra_simps (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)› ‹(?a::?'a) * (?b::?'a) * (?c::?'a) = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)› ‹(?a::?'a) - (?b::?'a) - (?c::?'a) = ?a - (?b + ?c)› ‹(?a::?'a) + ((?b::?'a) - (?c::?'a)) = ?a + ?b - ?c› ‹((?a::?'a) - (?b::?'a) = (?c::?'a)) = (?a = ?c + ?b)› ‹((?a::?'a) = (?c::?'a) - (?b::?'a)) = (?a + ?b = ?c)› ‹(?a::?'a) - ((?b::?'a) - (?c::?'a)) = ?a + ?c - ?b› ‹(?a::?'a) - (?b::?'a) + (?c::?'a) = ?a + ?c - ?b› and more 34 facts*)) finally (*calculation: ‹(∫⁺x∈{u<..<1}. ennreal ((- ln u) powr z / (1 - u) * (1 - x) / x)∂lborel) = ennreal ((- ln u) powr z / (1 - u) * (- ln u + u - 1))›*) show "(∫⁺x∈{u<..<1}. ((- ln u) powr z / (1 - u) * (1 - x) / x) ∂lborel) = ennreal …" . qed also (*calculation: ‹(∫⁺x::real × real∈D::(real × real) set. ennreal (case x of (x::real, y::real) ⇒ (- ln (x * y)) powr (z::real) * ((1::real) - x) / ((1::real) - x * y))∂lborel) = (∫⁺x::real∈{0::real<..<1::real}. ennreal ((- ln x) powr z / ((1::real) - x) * (- ln x + x - (1::real)))∂lborel)›*) have "… = Hadjicostas_nn_integral z" by (simp add: Hadjicostas_nn_integral_def (*‹Hadjicostas_nn_integral ?z = (∫⁺x∈{0<..<1}. ennreal ((- ln x) powr ?z / (1 - x) * (- ln x + x - 1))∂lborel)›*)) finally (*calculation: ‹(∫⁺x∈D. ennreal (case x of (x, y) ⇒ (- ln (x * y)) powr z * (1 - x) / (1 - x * y))∂lborel) = Hadjicostas_nn_integral z›*) show "?thesis" (*goal: ‹Hadjicostas_nn_integral z = (∫⁺x∈{0<..<1} × {0<..<1}. ennreal (case x of (x, y) ⇒ (- ln (x * y)) powr z * (1 - x) / (1 - x * y))∂lborel)›*) by (simp add: D_def (*‹D = {0<..<1} × {0<..<1}›*)) qed text ‹ We now solve the single integral for real ‹z > -1›. › lemma Hadjicostas_Chapman_aux: fixes z :: real assumes z: "z > -1" defines "f ≡ (λu. ((-ln u) powr z / (1 - u) * (-ln u + u - 1)))" shows "(f has_integral (Gamma (z + 2) * (Re (zeta (z + 2)) - 1 / (z + 1)))) {0<..<1}" proof (-) (*goal: ‹((f::real ⇒ real) has_integral Gamma ((z::real) + (2::real)) * (Re (zeta (complex_of_real (z + (2::real)))) - (1::real) / (z + (1::real)))) {0::real<..<1::real}›*) let ?I = "Gamma (z + 2) * (Re (zeta (z + 2)) - 1 / (z + 1))" have nonneg: "1 ≤ x + exp (- x)" if "x ≥ 0" for x :: real proof (-) (*goal: ‹1 ≤ x + exp (- x)›*) have "x + (1 + (-x)) ≤ x + exp (-x)" by (intro add_left_mono (*‹(?a::?'a::ordered_ab_semigroup_add) ≤ (?b::?'a::ordered_ab_semigroup_add) ⟹ (?c::?'a::ordered_ab_semigroup_add) + ?a ≤ ?c + ?b›*) exp_ge_add_one_self (*‹(1::real) + (?x::real) ≤ exp ?x›*)) thus "?thesis" (*goal: ‹1 ≤ x + exp (- x)›*) by simp qed have eq: "((λt::real. exp (-t)) ` {0<..}) = {0<..<1}" proof (safe) (*goals: 1. ‹⋀x t. 0 < t ⟹ exp (- t) ∈ {0<..<1}› 2. ‹⋀x. x ∈ {0<..<1} ⟹ x ∈ (λt. exp (- t)) ` {0<..}›*) fix x :: real assume x: "x ∈ {0<..<1}" (*‹(x::real) ∈ {0::real<..<1::real}›*) hence "x = exp (-(-ln x))" and "-ln x ∈ {0<..}" apply - (*goals: 1. ‹x ∈ {0<..<1} ⟹ x = exp (- (- ln x))› 2. ‹x ∈ {0<..<1} ⟹ - ln x ∈ {0<..}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . thus "x ∈ (λt. exp (-t)) ` {0<..}" by blast qed (auto) (*solved the remaining goal: ‹⋀x t. 0 < t ⟹ exp (- t) ∈ {0<..<1}›*) have I: "((λx. x powr (z+1) / (exp x - 1) - x powr z / exp x) has_integral ?I) {0<..}" proof (-) (*goal: ‹((λx::real. x powr ((z::real) + (1::real)) / (exp x - (1::real)) - x powr z / exp x) has_integral Gamma (z + (2::real)) * (Re (zeta (complex_of_real (z + (2::real)))) - (1::real) / (z + (1::real)))) {0::real<..}›*) from z (*‹- 1 < z›*) have "z + 1 ∉ ℝ⇩≤₀" by (auto simp: nonpos_Reals_def (*‹ℝ⇩≤₀ = {of_real r |r. r ≤ 0}›*)) hence z': "z + 1 ∉ ℤ⇩≤₀" using nonpos_Ints_subset_nonpos_Reals (*‹ℤ⇩≤₀ ⊆ ℝ⇩≤₀›*) by blast have "((λx. x powr (z + 2 - 1) / (exp x - 1) - x powr (z + 1 - 1) / exp x) has_integral (Gamma (z + 2) * Re (zeta (z + 2)) - Gamma (z + 1))) {0<..}" using z (*‹- 1 < z›*) apply (intro has_integral_diff (*‹⟦(?f has_integral ?k) ?S; (?g has_integral ?l) ?S⟧ ⟹ ((λx. ?f x - ?g x) has_integral ?k - ?l) ?S›*) Gamma_integral_real' (*‹0 < ?x ⟹ ((λt. t powr (?x - 1) / exp t) has_integral Gamma ?x) {0<..}›*) Gamma_times_zeta_has_integral_real (*‹1 < ?z ⟹ ((λx. x powr (?z - 1) / (exp x - 1)) has_integral Gamma ?z * Re (zeta (complex_of_real ?z))) {0<..}›*)) (*goals: 1. ‹- (1::real) < (z::real) ⟹ (1::real) < z + (2::real)› 2. ‹- (1::real) < (z::real) ⟹ (0::real) < z + (1::real)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . also (*calculation: ‹((λx. x powr (z + 2 - 1) / (exp x - 1) - x powr (z + 1 - 1) / exp x) has_integral Gamma (z + 2) * Re (zeta (complex_of_real (z + 2))) - Gamma (z + 1)) {0<..}›*) have "Gamma (z + 2) * Re (zeta (z + 2)) - Gamma (z + 1) = Gamma (z + 2) * (Re (zeta (z + 2)) - 1 / (z + 1))" using Gamma_plus1[of "z+1"] (*‹(z::real) + (1::real) ∉ ℤ⇩≤₀ ⟹ Gamma (z + (1::real) + (1::real)) = (z + (1::real)) * Gamma (z + (1::real))›*) z (*‹- 1 < z›*) z' (*‹(z::real) + (1::real) ∉ ℤ⇩≤₀›*) by (auto simp: field_simps (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)› ‹(?a::?'a) * (?b::?'a) * (?c::?'a) = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)› ‹(?a::?'a) - (?b::?'a) - (?c::?'a) = ?a - (?b + ?c)› ‹(?a::?'a) + ((?b::?'a) - (?c::?'a)) = ?a + ?b - ?c› ‹((?a::?'a) - (?b::?'a) = (?c::?'a)) = (?a = ?c + ?b)› ‹((?a::?'a) = (?c::?'a) - (?b::?'a)) = (?a + ?b = ?c)› ‹(?a::?'a) - ((?b::?'a) - (?c::?'a)) = ?a + ?c - ?b› ‹(?a::?'a) - (?b::?'a) + (?c::?'a) = ?a + ?c - ?b› and more 77 facts*)) finally (*calculation: ‹((λx. x powr (z + 2 - 1) / (exp x - 1) - x powr (z + 1 - 1) / exp x) has_integral Gamma (z + 2) * (Re (zeta (complex_of_real (z + 2))) - 1 / (z + 1))) {0<..}›*) show "?thesis" (*goal: ‹((λx::real. x powr ((z::real) + (1::real)) / (exp x - (1::real)) - x powr z / exp x) has_integral Gamma (z + (2::real)) * (Re (zeta (complex_of_real (z + (2::real)))) - (1::real) / (z + (1::real)))) {0::real<..}›*) by (simp add: add_ac (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)›*)) qed also (*calculation: ‹((λx::real. x powr ((z::real) + (1::real)) / (exp x - (1::real)) - x powr z / exp x) has_integral Gamma (z + (2::real)) * (Re (zeta (complex_of_real (z + (2::real)))) - (1::real) / (z + (1::real)))) {0::real<..}›*) have "?this ⟷ ((λx. ¦-exp (-x)¦ * f (exp (-x))) has_integral ?I) {0<..}" unfolding f_def (*goal: ‹((λx. x powr (z + 1) / (exp x - 1) - x powr z / exp x) has_integral Gamma (z + 2) * (Re (zeta (complex_of_real (z + 2))) - 1 / (z + 1))) {0<..} = ((λx. ¦- exp (- x)¦ * ((- ln (exp (- x))) powr z / (1 - exp (- x)) * (- ln (exp (- x)) + exp (- x) - 1))) has_integral Gamma (z + 2) * (Re (zeta (complex_of_real (z + 2))) - 1 / (z + 1))) {0<..}›*) apply (intro has_integral_cong (*‹(⋀x::?'a::euclidean_space. x ∈ (?s::?'a::euclidean_space set) ⟹ (?f::?'a::euclidean_space ⇒ ?'b::real_normed_vector) x = (?g::?'a::euclidean_space ⇒ ?'b::real_normed_vector) x) ⟹ (?f has_integral (?i::?'b::real_normed_vector)) ?s = (?g has_integral ?i) ?s›*)) (*goal: ‹((λx::real. x powr ((z::real) + (1::real)) / (exp x - (1::real)) - x powr z / exp x) has_integral Gamma (z + (2::real)) * (Re (zeta (complex_of_real (z + (2::real)))) - (1::real) / (z + (1::real)))) {0::real<..} = ((λx::real. ¦- exp (- x)¦ * ((- ln (exp (- x))) powr z / ((1::real) - exp (- x)) * (- ln (exp (- x)) + exp (- x) - (1::real)))) has_integral Gamma (z + (2::real)) * (Re (zeta (complex_of_real (z + (2::real)))) - (1::real) / (z + (1::real)))) {0::real<..}›*) apply (auto simp: field_simps (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)› ‹(?a::?'a) * (?b::?'a) * (?c::?'a) = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)› ‹(?a::?'a) - (?b::?'a) - (?c::?'a) = ?a - (?b + ?c)› ‹(?a::?'a) + ((?b::?'a) - (?c::?'a)) = ?a + ?b - ?c› ‹((?a::?'a) - (?b::?'a) = (?c::?'a)) = (?a = ?c + ?b)› ‹((?a::?'a) = (?c::?'a) - (?b::?'a)) = (?a + ?b = ?c)› ‹(?a::?'a) - ((?b::?'a) - (?c::?'a)) = ?a + ?c - ?b› ‹(?a::?'a) - (?b::?'a) + (?c::?'a) = ?a + ?c - ?b› and more 77 facts*) powr_add (*‹(?x::?'a) powr ((?a::?'a) + (?b::?'a)) = ?x powr ?a * ?x powr ?b›*) powr_def (*‹(?x::?'a) powr (?a::?'a) ≡ if ?x = (0::?'a) then 0::?'a else exp (?a * ln ?x)›*) exp_add (*‹exp ((?x::?'a) + (?y::?'a)) = exp ?x * exp ?y›*)) (*goal: ‹⋀x. x ∈ {0<..} ⟹ x powr (z + 1) / (exp x - 1) - x powr z / exp x = ¦- exp (- x)¦ * ((- ln (exp (- x))) powr z / (1 - exp (- x)) * (- ln (exp (- x)) + exp (- x) - 1))›*) by (simp flip: exp_add (*‹exp (?x + ?y) = exp ?x * exp ?y›*)) finally (*calculation: ‹((λx. ¦- exp (- x)¦ * f (exp (- x))) has_integral Gamma (z + 2) * (Re (zeta (complex_of_real (z + 2))) - 1 / (z + 1))) {0<..}›*) have "*": "((λx. ¦-exp (-x)¦ * f (exp (-x))) has_integral ?I) {0<..}" . have "((λx. ¦-exp (-x)¦ *⇩R f (exp (-x))) absolutely_integrable_on {0<..}) ∧ integral {0<..} (λx. ¦-exp (-x)¦ *⇩R f (exp (-x))) = ?I" proof (intro conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*) nonnegative_absolutely_integrable_1 (*‹⟦?f integrable_on ?A; ⋀x. x ∈ ?A ⟹ 0 ≤ ?f x⟧ ⟹ ?f absolutely_integrable_on ?A›*)) (*goals: 1. ‹(λx::real. ¦- exp (- x)¦ *⇩R (f::real ⇒ real) (exp (- x))) integrable_on {0::real<..}› 2. ‹⋀x::real. x ∈ {0::real<..} ⟹ (0::real) ≤ ¦- exp (- x)¦ *⇩R (f::real ⇒ real) (exp (- x))› 3. ‹integral {0::real<..} (λx::real. ¦- exp (- x)¦ *⇩R (f::real ⇒ real) (exp (- x))) = Gamma ((z::real) + (2::real)) * (Re (zeta (complex_of_real (z + (2::real)))) - (1::real) / (z + (1::real)))›*) fix x :: real assume x: "x ∈ {0<..}" (*‹(x::real) ∈ {0::real<..}›*) thus "¦-exp (-x)¦ *⇩R f (exp (-x)) ≥ 0" unfolding f_def (*goal: ‹0 ≤ ¦- exp (- x)¦ *⇩R ((- ln (exp (- x))) powr z / (1 - exp (- x)) * (- ln (exp (- x)) + exp (- x) - 1))›*) using nonneg (*‹0 ≤ ?x ⟹ 1 ≤ ?x + exp (- ?x)›*) apply (intro scaleR_nonneg_nonneg (*‹⟦0 ≤ ?a; 0 ≤ ?x⟧ ⟹ 0 ≤ ?a *⇩R ?x›*) mult_nonneg_nonneg (*‹⟦0 ≤ ?a; 0 ≤ ?b⟧ ⟹ 0 ≤ ?a * ?b›*) divide_nonneg_nonneg (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ 0 ≤ ?x / ?y›*)) (*goals: 1. ‹⟦x ∈ {0<..}; ⋀x. 0 ≤ x ⟹ 1 ≤ x + exp (- x)⟧ ⟹ 0 ≤ ¦- exp (- x)¦› 2. ‹⟦x ∈ {0<..}; ⋀x. 0 ≤ x ⟹ 1 ≤ x + exp (- x)⟧ ⟹ 0 ≤ (- ln (exp (- x))) powr z› 3. ‹⟦x ∈ {0<..}; ⋀x. 0 ≤ x ⟹ 1 ≤ x + exp (- x)⟧ ⟹ 0 ≤ 1 - exp (- x)› 4. ‹⟦x ∈ {0<..}; ⋀x. 0 ≤ x ⟹ 1 ≤ x + exp (- x)⟧ ⟹ 0 ≤ - ln (exp (- x)) + exp (- x) - 1› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . qed (use * in ‹simp_all add: has_integral_iff›) (*solves the remaining goals: 1. ‹(λx::real. ¦- exp (- x)¦ *⇩R (f::real ⇒ real) (exp (- x))) integrable_on {0::real<..}› 2. ‹integral {0::real<..} (λx::real. ¦- exp (- x)¦ *⇩R (f::real ⇒ real) (exp (- x))) = Gamma ((z::real) + (2::real)) * (Re (zeta (complex_of_real (z + (2::real)))) - (1::real) / (z + (1::real)))›*) also (*calculation: ‹(λx. ¦- exp (- x)¦ *⇩R f (exp (- x))) absolutely_integrable_on {0<..} ∧ integral {0<..} (λx. ¦- exp (- x)¦ *⇩R f (exp (- x))) = Gamma (z + 2) * (Re (zeta (complex_of_real (z + 2))) - 1 / (z + 1))›*) have "?this ⟷ f absolutely_integrable_on (λx. exp (- x)) ` {0<..} ∧ integral ((λx. exp (- x)) ` {0<..}) f = ?I" apply (intro has_absolute_integral_change_of_variables_1' (*‹⟦?S ∈ sets lebesgue; ⋀x. x ∈ ?S ⟹ (?g has_real_derivative ?g' x) (at x within ?S); inj_on ?g ?S⟧ ⟹ ((λx. ¦?g' x¦ *⇩R ?f (?g x)) absolutely_integrable_on ?S ∧ integral ?S (λx. ¦?g' x¦ *⇩R ?f (?g x)) = ?b) = (?f absolutely_integrable_on ?g ` ?S ∧ integral (?g ` ?S) ?f = ?b)›*)) (*goals: 1. ‹{0<..} ∈ sets lebesgue› 2. ‹⋀x. x ∈ {0<..} ⟹ ((λx. exp (- x)) has_real_derivative - exp (- x)) (at x within {0<..})› 3. ‹inj_on (λx. exp (- x)) {0<..}› discuss goal 1*) apply ((auto intro!: derivative_eq_intros (*‹(λx. x) = ?g' ⟹ ((λx. x) has_derivative ?g') ?F› ‹id = ?g' ⟹ (id has_derivative ?g') ?F› ‹(λx. 0) = ?g' ⟹ ((λx. ?f2) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?r1 *⇩R ?g'1 x) = ?g'⟧ ⟹ ((λx. ?r1 *⇩R ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x *⇩R ?x1) = ?g'⟧ ⟹ ((λx. ?g1 x *⇩R ?x1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?x1 * ?g'1 x) = ?g'⟧ ⟹ ((λx. ?x1 * ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x * ?y1) = ?g'⟧ ⟹ ((λx. ?g1 x * ?y1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. of_real (?g'1 x)) = ?g'⟧ ⟹ ((λx. of_real (?g1 x)) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x + ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x + ?g1 x) has_derivative ?g') ?F› ‹⟦⋀i. i ∈ ?I1 ⟹ (?f1 i has_derivative ?f'1 i) ?F; (λx. ∑i∈?I1. ?f'1 i x) = ?g'⟧ ⟹ ((λx. ∑i∈?I1. ?f1 i x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (λx. - ?f'1 x) = ?g'⟧ ⟹ ((λx. - ?f1 x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x - ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x - ?g1 x) has_derivative ?g') ?F› and more 140 facts*) inj_onI (*‹(⋀x y. ⟦x ∈ ?A; y ∈ ?A; ?f x = ?f y⟧ ⟹ x = y) ⟹ inj_on ?f ?A›*))[1]) (*discuss goal 2*) apply ((auto intro!: derivative_eq_intros (*‹(λx. x) = ?g' ⟹ ((λx. x) has_derivative ?g') ?F› ‹id = ?g' ⟹ (id has_derivative ?g') ?F› ‹(λx. 0) = ?g' ⟹ ((λx. ?f2) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?r1 *⇩R ?g'1 x) = ?g'⟧ ⟹ ((λx. ?r1 *⇩R ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x *⇩R ?x1) = ?g'⟧ ⟹ ((λx. ?g1 x *⇩R ?x1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?x1 * ?g'1 x) = ?g'⟧ ⟹ ((λx. ?x1 * ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x * ?y1) = ?g'⟧ ⟹ ((λx. ?g1 x * ?y1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. of_real (?g'1 x)) = ?g'⟧ ⟹ ((λx. of_real (?g1 x)) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x + ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x + ?g1 x) has_derivative ?g') ?F› ‹⟦⋀i. i ∈ ?I1 ⟹ (?f1 i has_derivative ?f'1 i) ?F; (λx. ∑i∈?I1. ?f'1 i x) = ?g'⟧ ⟹ ((λx. ∑i∈?I1. ?f1 i x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (λx. - ?f'1 x) = ?g'⟧ ⟹ ((λx. - ?f1 x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x - ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x - ?g1 x) has_derivative ?g') ?F› and more 140 facts*) inj_onI (*‹(⋀x y. ⟦x ∈ ?A; y ∈ ?A; ?f x = ?f y⟧ ⟹ x = y) ⟹ inj_on ?f ?A›*))[1]) (*discuss goal 3*) apply ((auto intro!: derivative_eq_intros (*‹(λx. x) = ?g' ⟹ ((λx. x) has_derivative ?g') ?F› ‹id = ?g' ⟹ (id has_derivative ?g') ?F› ‹(λx. 0) = ?g' ⟹ ((λx. ?f2) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?r1 *⇩R ?g'1 x) = ?g'⟧ ⟹ ((λx. ?r1 *⇩R ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x *⇩R ?x1) = ?g'⟧ ⟹ ((λx. ?g1 x *⇩R ?x1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?x1 * ?g'1 x) = ?g'⟧ ⟹ ((λx. ?x1 * ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x * ?y1) = ?g'⟧ ⟹ ((λx. ?g1 x * ?y1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. of_real (?g'1 x)) = ?g'⟧ ⟹ ((λx. of_real (?g1 x)) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x + ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x + ?g1 x) has_derivative ?g') ?F› ‹⟦⋀i. i ∈ ?I1 ⟹ (?f1 i has_derivative ?f'1 i) ?F; (λx. ∑i∈?I1. ?f'1 i x) = ?g'⟧ ⟹ ((λx. ∑i∈?I1. ?f1 i x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (λx. - ?f'1 x) = ?g'⟧ ⟹ ((λx. - ?f1 x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x - ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x - ?g1 x) has_derivative ?g') ?F› and more 140 facts*) inj_onI (*‹(⋀x y. ⟦x ∈ ?A; y ∈ ?A; ?f x = ?f y⟧ ⟹ x = y) ⟹ inj_on ?f ?A›*))[1]) (*proven 3 subgoals*) . also (*calculation: ‹f absolutely_integrable_on (λx. exp (- x)) ` {0<..} ∧ integral ((λx. exp (- x)) ` {0<..}) f = Gamma (z + 2) * (Re (zeta (complex_of_real (z + 2))) - 1 / (z + 1))›*) have "(λx::real. exp (- x)) ` {0<..} = {0<..<1}" by (fact eq (*‹(λt. exp (- t)) ` {0<..} = {0<..<1}›*)) finally (*calculation: ‹f absolutely_integrable_on {0<..<1} ∧ integral {0<..<1} f = Gamma (z + 2) * (Re (zeta (complex_of_real (z + 2))) - 1 / (z + 1))›*) show "(f has_integral ?I) {0<..<1}" by (auto simp: has_integral_iff (*‹(?f has_integral ?i) ?S = (?f integrable_on ?S ∧ integral ?S ?f = ?i)›*) dest: set_lebesgue_integral_eq_integral (*‹?f absolutely_integrable_on ?S ⟹ ?f integrable_on ?S› ‹?f absolutely_integrable_on ?S ⟹ set_lebesgue_integral lebesgue ?S ?f = integral ?S ?f›*)) qed lemma real_zeta_ge_one_over_minus_one: fixes z :: real assumes z: "z > 1" shows "Re (zeta (complex_of_real z)) ≥ 1 / (z - 1)" proof (-) (*goal: ‹1 / (z - 1) ≤ Re (zeta (complex_of_real z))›*) have ineq: "1 ≤ x - ln x" if "x ∈ {0<..<1}" for x :: real using ln_le_minus_one[of x] (*‹0 < x ⟹ ln x ≤ x - 1›*) that (*‹x ∈ {0<..<1}›*) by simp have "*": "((λu. (- ln u) powr (z - 2) * (u - ln u - 1) / (1 - u)) has_integral Gamma z * (Re (zeta (complex_of_real z)) - 1 / (z - 1))) {0<..<1}" using Hadjicostas_Chapman_aux[of "z - 2"] (*‹- 1 < z - 2 ⟹ ((λu. (- ln u) powr (z - 2) / (1 - u) * (- ln u + u - 1)) has_integral Gamma (z - 2 + 2) * (Re (zeta (complex_of_real (z - 2 + 2))) - 1 / (z - 2 + 1))) {0<..<1}›*) z (*‹1 < z›*) by simp from ineq (*‹?x ∈ {0<..<1} ⟹ 1 ≤ ?x - ln ?x›*) have "Gamma z * (Re (zeta (complex_of_real z)) - 1 / (z - 1)) ≥ 0" apply (intro has_integral_nonneg[OF *] (*‹(⋀x. x ∈ {0<..<1} ⟹ 0 ≤ (- ln x) powr (z - 2) * (x - ln x - 1) / (1 - x)) ⟹ 0 ≤ Gamma z * (Re (zeta (complex_of_real z)) - 1 / (z - 1))›*) z (*‹1 < z›*) mult_nonneg_nonneg (*‹⟦0 ≤ ?a; 0 ≤ ?b⟧ ⟹ 0 ≤ ?a * ?b›*) divide_nonneg_nonneg (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ 0 ≤ ?x / ?y›*)) (*goals: 1. ‹⋀x. ⟦⋀x. x ∈ {0<..<1} ⟹ 1 ≤ x - ln x; x ∈ {0<..<1}⟧ ⟹ 0 ≤ (- ln x) powr (z - 2)› 2. ‹⋀x. ⟦⋀x. x ∈ {0<..<1} ⟹ 1 ≤ x - ln x; x ∈ {0<..<1}⟧ ⟹ 0 ≤ x - ln x - 1› 3. ‹⋀x. ⟦⋀x. x ∈ {0<..<1} ⟹ 1 ≤ x - ln x; x ∈ {0<..<1}⟧ ⟹ 0 ≤ 1 - x› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . moreover have "Gamma z > 0" using assms (*‹1 < z›*) apply (intro Gamma_real_pos (*‹0 < ?x ⟹ 0 < Gamma ?x›*)) (*goal: ‹0 < Gamma z›*) by auto ultimately show "Re (zeta (complex_of_real z)) ≥ 1 / (z - 1)" apply (subst (asm) zero_le_mult_iff (*‹((0::?'a::linordered_ring_strict) ≤ (?a::?'a::linordered_ring_strict) * (?b::?'a::linordered_ring_strict)) = ((0::?'a::linordered_ring_strict) ≤ ?a ∧ (0::?'a::linordered_ring_strict) ≤ ?b ∨ ?a ≤ (0::?'a::linordered_ring_strict) ∧ ?b ≤ (0::?'a::linordered_ring_strict))›*)) (*goal: ‹(1::real) / ((z::real) - (1::real)) ≤ Re (zeta (complex_of_real z))›*) by auto qed text ‹ We now have the formula for real ‹z > -1›. › lemma Hadjicostas_Chapman_formula_real: fixes z :: real assumes z: "z > -1" shows "Hadjicostas_nn_integral z = ennreal (Gamma (z + 2) * (Re (zeta (z + 2)) - 1 / (z + 1)))" proof (-) (*goal: ‹Hadjicostas_nn_integral (z::real) = ennreal (Gamma (z + (2::real)) * (Re (zeta (complex_of_real (z + (2::real)))) - (1::real) / (z + (1::real))))›*) have nonneg: "1 ≤ x - ln x" if "x > 0" "x < 1" for x :: real proof (-) (*goal: ‹(1::real) ≤ (x::real) - ln x›*) have "ln x + (1 + ln x) ≤ ln x + exp (ln x)" by (intro add_left_mono (*‹?a ≤ ?b ⟹ ?c + ?a ≤ ?c + ?b›*) exp_ge_add_one_self (*‹1 + ?x ≤ exp ?x›*)) thus "?thesis" (*goal: ‹(1::real) ≤ (x::real) - ln x›*) using that (*‹(0::real) < (x::real)› ‹x < 1›*) by (simp add: exp_minus (*‹exp (- (?x::?'a)) = inverse (exp ?x)›*)) qed show "?thesis" (*goal: ‹Hadjicostas_nn_integral z = ennreal (Gamma (z + 2) * (Re (zeta (complex_of_real (z + 2))) - 1 / (z + 1)))›*) unfolding Hadjicostas_nn_integral_def (*goal: ‹(∫⁺x::real∈{0::real<..<1::real}. ennreal ((- ln x) powr (z::real) / ((1::real) - x) * (- ln x + x - (1::real)))∂lborel) = ennreal (Gamma (z + (2::real)) * (Re (zeta (complex_of_real (z + (2::real)))) - (1::real) / (z + (1::real))))›*) using nonneg (*‹⟦0 < ?x; ?x < 1⟧ ⟹ 1 ≤ ?x - ln ?x›*) Hadjicostas_Chapman_aux[OF z] (*‹((λu. (- ln u) powr z / (1 - u) * (- ln u + u - 1)) has_integral Gamma (z + 2) * (Re (zeta (complex_of_real (z + 2))) - 1 / (z + 1))) {0<..<1}›*) apply (intro nn_integral_has_integral_lebesgue' (*‹⟦⋀x. x ∈ ?Ω ⟹ 0 ≤ ?f x; (?f has_integral ?I) ?Ω⟧ ⟹ (∫⁺x∈?Ω. ennreal (?f x)∂lborel) = ennreal ?I›*) mult_nonneg_nonneg (*‹⟦0 ≤ ?a; 0 ≤ ?b⟧ ⟹ 0 ≤ ?a * ?b›*) divide_nonneg_nonneg (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ 0 ≤ ?x / ?y›*)) (*goals: 1. ‹⋀x. ⟦⋀x. ⟦0 < x; x < 1⟧ ⟹ 1 ≤ x - ln x; ((λu. (- ln u) powr z / (1 - u) * (- ln u + u - 1)) has_integral Gamma (z + 2) * (Re (zeta (complex_of_real (z + 2))) - 1 / (z + 1))) {0<..<1}; x ∈ {0<..<1}⟧ ⟹ 0 ≤ (- ln x) powr z› 2. ‹⋀x. ⟦⋀x. ⟦0 < x; x < 1⟧ ⟹ 1 ≤ x - ln x; ((λu. (- ln u) powr z / (1 - u) * (- ln u + u - 1)) has_integral Gamma (z + 2) * (Re (zeta (complex_of_real (z + 2))) - 1 / (z + 1))) {0<..<1}; x ∈ {0<..<1}⟧ ⟹ 0 ≤ 1 - x› 3. ‹⋀x. ⟦⋀x. ⟦0 < x; x < 1⟧ ⟹ 1 ≤ x - ln x; ((λu. (- ln u) powr z / (1 - u) * (- ln u + u - 1)) has_integral Gamma (z + 2) * (Re (zeta (complex_of_real (z + 2))) - 1 / (z + 1))) {0<..<1}; x ∈ {0<..<1}⟧ ⟹ 0 ≤ - ln x + x - 1› 4. ‹⟦⋀x. ⟦0 < x; x < 1⟧ ⟹ 1 ≤ x - ln x; ((λu. (- ln u) powr z / (1 - u) * (- ln u + u - 1)) has_integral Gamma (z + 2) * (Re (zeta (complex_of_real (z + 2))) - 1 / (z + 1))) {0<..<1}⟧ ⟹ ((λx. (- ln x) powr z / (1 - x) * (- ln x + x - 1)) has_integral Gamma (z + 2) * (Re (zeta (complex_of_real (z + 2))) - 1 / (z + 1))) {0<..<1}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . qed subsection ‹Analyticity of the integral› text ‹ To extend the formula to its full domain of validity (any complex ‹z› with $\mathfrak{R}(z)>-2$), we will use analytic continuation. To do this, we first have to show that the integral is an analytic function of ‹z› on that domain. This is unfortunately somewhat involved, since the integral is an improper one and we first need to show uniform convergence so that we can pull the derivative inside the integral sign. We will use the single-integral form so that we only have to deal with one integral and not two. › context fixes f :: "complex ⇒ real ⇒ complex" defines "f ≡ (λz u. of_real (-ln u) powr z / of_real (1 - u) * of_real (-ln u + u - 1))" begin context fixes x y :: real and g1 g2 :: "real ⇒ real" assumes "x > -2" defines "g1 ≡ (λx. (- ln x) powr y * (x - ln x - 1) / (1 - x))" defines "g2 ≡ (λu. (-ln u) powr x * (u - ln u - 1) / (1 - u))" begin lemma integrable_bound1: "interval_lebesgue_integrable lborel 0 (ereal (exp (- 1))) g1" unfolding zero_ereal_def (*goal: ‹interval_lebesgue_integrable lborel (ereal 0) (ereal (exp (- 1))) g1›*) proof (rule interval_lebesgue_integrable_bigo_left (*‹⟦(?f::real ⇒ real) ∈ O[at_right (?A::real)](?g::real ⇒ real); continuous_on {?A<..?B::real} ?f; set_borel_measurable borel {?A<..<?B} ?f; interval_lebesgue_integrable lborel (ereal ?A) (ereal ?B) ?g; ?A < ?B⟧ ⟹ interval_lebesgue_integrable lborel (ereal ?A) (ereal ?B) ?f›*)) (*goals: 1. ‹g1 ∈ O[at_right 0](?g)› 2. ‹continuous_on {0<..exp (- 1)} g1› 3. ‹set_borel_measurable borel {0<..<exp (- 1)} g1› 4. ‹interval_lebesgue_integrable lborel (ereal 0) (ereal (exp (- 1))) ?g› 5. ‹0 < exp (- 1)›*) show "g1 ∈ O[at_right 0](λu. u powr (-1/2))" unfolding g1_def (*goal: ‹(λx. (- ln x) powr y * (x - ln x - 1) / (1 - x)) ∈ O[at_right 0](λu. u powr (- 1 / 2))›*) by real_asymp show "continuous_on {0<..exp(-1)} g1" unfolding g1_def (*goal: ‹continuous_on {0<..exp (- 1)} (λx. (- ln x) powr y * (x - ln x - 1) / (1 - x))›*) by (auto intro!: continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 286 facts*)) have "set_integrable lborel (einterval 0 (exp (-1))) (λu. u powr (-1/2))" proof (rule interval_integral_FTC_nonneg (*‹⟦?a < ?b; ⋀x. ⟦?a < ereal x; ereal x < ?b⟧ ⟹ (?F has_real_derivative ?f x) (at x); ⋀x. ⟦?a < ereal x; ereal x < ?b⟧ ⟹ isCont ?f x; AE x in lborel. ?a < ereal x ⟶ ereal x < ?b ⟶ 0 ≤ ?f x; ((?F ∘ real_of_ereal) ⤏ ?A) (at_right ?a); ((?F ∘ real_of_ereal) ⤏ ?B) (at_left ?b)⟧ ⟹ set_integrable lborel (einterval ?a ?b) ?f› ‹⟦?a < ?b; ⋀x. ⟦?a < ereal x; ereal x < ?b⟧ ⟹ (?F has_real_derivative ?f x) (at x); ⋀x. ⟦?a < ereal x; ereal x < ?b⟧ ⟹ isCont ?f x; AE x in lborel. ?a < ereal x ⟶ ereal x < ?b ⟶ 0 ≤ ?f x; ((?F ∘ real_of_ereal) ⤏ ?A) (at_right ?a); ((?F ∘ real_of_ereal) ⤏ ?B) (at_left ?b)⟧ ⟹ interval_lebesgue_integral lborel ?a ?b ?f = ?B - ?A›*)) (*goals: 1. ‹0 < ereal (exp (- 1))› 2. ‹⋀x. ⟦0 < ereal x; ereal x < ereal (exp (- 1))⟧ ⟹ (?F has_real_derivative x powr (- 1 / 2)) (at x)› 3. ‹⋀x. ⟦0 < ereal x; ereal x < ereal (exp (- 1))⟧ ⟹ isCont (λu. u powr (- 1 / 2)) x› 4. ‹AE x in lborel. 0 < ereal x ⟶ ereal x < ereal (exp (- 1)) ⟶ 0 ≤ x powr (- 1 / 2)› 5. ‹((?F ∘ real_of_ereal) ⤏ ?A) (at_right 0)› 6. ‹((?F ∘ real_of_ereal) ⤏ ?B) (at_left (ereal (exp (- 1))))›*) fix u :: real assume u: "0 < ereal u" "ereal u < ereal (exp (-1))" (*‹(0::ereal) < ereal (u::real)› ‹ereal (u::real) < ereal (exp (- (1::real)))›*) show "((λu. 2 * u powr (1/2)) has_field_derivative (u powr (-1/2))) (at u)" using u (*‹0 < ereal u› ‹ereal u < ereal (exp (- 1))›*) by (auto intro!: derivative_eq_intros (*‹(λx. x) = ?g' ⟹ ((λx. x) has_derivative ?g') ?F› ‹id = ?g' ⟹ (id has_derivative ?g') ?F› ‹(λx. 0) = ?g' ⟹ ((λx. ?f2) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?r1 *⇩R ?g'1 x) = ?g'⟧ ⟹ ((λx. ?r1 *⇩R ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x *⇩R ?x1) = ?g'⟧ ⟹ ((λx. ?g1 x *⇩R ?x1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?x1 * ?g'1 x) = ?g'⟧ ⟹ ((λx. ?x1 * ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x * ?y1) = ?g'⟧ ⟹ ((λx. ?g1 x * ?y1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. of_real (?g'1 x)) = ?g'⟧ ⟹ ((λx. of_real (?g1 x)) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x + ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x + ?g1 x) has_derivative ?g') ?F› ‹⟦⋀i. i ∈ ?I1 ⟹ (?f1 i has_derivative ?f'1 i) ?F; (λx. ∑i∈?I1. ?f'1 i x) = ?g'⟧ ⟹ ((λx. ∑i∈?I1. ?f1 i x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (λx. - ?f'1 x) = ?g'⟧ ⟹ ((λx. - ?f1 x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x - ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x - ?g1 x) has_derivative ?g') ?F› and more 140 facts*) simp: power2_eq_square (*‹?a² = ?a * ?a›*)) show "isCont (λu. u powr (-1/2)) u" using u (*‹0 < ereal u› ‹ereal u < ereal (exp (- 1))›*) by (auto intro!: continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 286 facts*)) next (*goals: 1. ‹0 < ereal (exp (- 1))› 2. ‹AE x in lborel. 0 < ereal x ⟶ ereal x < ereal (exp (- 1)) ⟶ 0 ≤ x powr (- 1 / 2)› 3. ‹(((λu. 2 * u powr (1 / 2)) ∘ real_of_ereal) ⤏ ?A) (at_right 0)› 4. ‹(((λu. 2 * u powr (1 / 2)) ∘ real_of_ereal) ⤏ ?B) (at_left (ereal (exp (- 1))))›*) show "(((λu. 2 * u powr (1/2)) ∘ real_of_ereal) ⤏ 2 * exp (-1) powr (1/2)) (at_left (ereal (exp (- 1))))" unfolding ereal_tendsto_simps (*goal: ‹((λu::real. (2::real) * u powr ((1::real) / (2::real))) ⤏ (2::real) * exp (- (1::real)) powr ((1::real) / (2::real))) (at_left (exp (- (1::real))))›*) by real_asymp show "(((λu. 2 * u powr (1/2)) ∘ real_of_ereal) ⤏ 0) (at_right 0)" unfolding zero_ereal_def (*goal: ‹(((λu. 2 * u powr (1 / 2)) ∘ real_of_ereal) ⤏ 0) (at_right (ereal 0))›*) unfolding ereal_tendsto_simps (*goal: ‹((λu. 2 * u powr (1 / 2)) ⤏ 0) (at_right 0)›*) by real_asymp qed (auto) (*solves the remaining goals: 1. ‹0 < ereal (exp (- 1))› 2. ‹AE x in lborel. 0 < ereal x ⟶ ereal x < ereal (exp (- 1)) ⟶ 0 ≤ x powr (- 1 / 2)›*) thus "interval_lebesgue_integrable lborel (ereal 0) (ereal (exp (- 1))) (λu. u powr (-1/2))" by (simp add: interval_lebesgue_integrable_def (*‹interval_lebesgue_integrable ?M ?a ?b ?f = (if ?a ≤ ?b then set_integrable ?M (einterval ?a ?b) ?f else set_integrable ?M (einterval ?b ?a) ?f)›*) zero_ereal_def (*‹0 = ereal 0›*)) qed (auto simp add: g1_def (*‹g1::real ⇒ real ≡ λx::real. (- ln x) powr (y::real) * (x - ln x - (1::real)) / ((1::real) - x)›*) set_borel_measurable_def (*‹set_borel_measurable (?M::?'a::type measure) (?A::?'a::type set) (?f::?'a::type ⇒ ?'b::{scaleR,topological_space}) ≡ (λx::?'a::type. indicat_real ?A x *⇩R ?f x) ∈ borel_measurable ?M›*)) (*solves the remaining goals: 1. ‹set_borel_measurable borel {0<..<exp (- 1)} g1› 2. ‹0 < exp (- 1)›*) lemma integrable_bound2: "interval_lebesgue_integrable lborel (exp (-1)) 1 g2" unfolding one_ereal_def (*goal: ‹interval_lebesgue_integrable lborel (ereal (exp (- 1))) (ereal 1) g2›*) proof (rule interval_lebesgue_integrable_bigo_right (*‹⟦?f ∈ O[at_left ?B](?g); continuous_on {?A..<?B} ?f; set_borel_measurable borel {?A<..<?B} ?f; interval_lebesgue_integrable lborel (ereal ?A) (ereal ?B) ?g; ?A < ?B⟧ ⟹ interval_lebesgue_integrable lborel (ereal ?A) (ereal ?B) ?f›*)) (*goals: 1. ‹g2 ∈ O[at_left 1](?g)› 2. ‹continuous_on {exp (- 1)..<1} g2› 3. ‹set_borel_measurable borel {exp (- 1)<..<1} g2› 4. ‹interval_lebesgue_integrable lborel (ereal (exp (- 1))) (ereal 1) ?g› 5. ‹exp (- 1) < 1›*) show "g2 ∈ O[at_left 1](λu. (1 - u) powr (x + 1))" unfolding g2_def (*goal: ‹(λu. (- ln u) powr x * (u - ln u - 1) / (1 - u)) ∈ O[at_left 1](λu. (1 - u) powr (x + 1))›*) by real_asymp have "ln x ≠ 0" if "x ∈ {exp (-1)..<1}" for x :: real proof (-) (*goal: ‹ln x ≠ 0›*) have "0 < exp (-1 :: real)" by simp also (*calculation: ‹(0::real) < exp (- (1::real))›*) have "… ≤ x" using that (*‹x ∈ {exp (- 1)..<1}›*) by auto finally (*calculation: ‹0 < x›*) have "x > 0" . from that (*‹(x::real) ∈ {exp (- (1::real))..<1::real}›*) ‹x > 0› (*‹(0::real) < (x::real)›*) have "ln x < ln 1" apply (subst ln_less_cancel_iff (*‹⟦0 < ?x; 0 < ?y⟧ ⟹ (ln ?x < ln ?y) = (?x < ?y)›*)) (*goals: 1. ‹⟦x ∈ {exp (- 1)..<1}; 0 < x⟧ ⟹ 0 < x› 2. ‹⟦x ∈ {exp (- 1)..<1}; 0 < x⟧ ⟹ 0 < 1› 3. ‹⟦x ∈ {exp (- 1)..<1}; 0 < x⟧ ⟹ x < 1› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . thus "ln x ≠ 0" by simp qed thus "continuous_on {exp (- 1)..<1} g2" unfolding g2_def (*goal: ‹continuous_on {exp (- 1)..<1} (λu. (- ln u) powr x * (u - ln u - 1) / (1 - u))›*) by (auto intro!: continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 286 facts*)) let ?F = "(λu. -1 / (x + 2) * (1 - u) powr (x + 2))" have "set_integrable lborel (einterval (exp (-1)) 1) (λu. (1 - u) powr (x + 1))" proof (rule interval_integral_FTC_nonneg[where F = ?F] (*‹⟦?a < ?b; ⋀xa. ⟦?a < ereal xa; ereal xa < ?b⟧ ⟹ ((λu. - 1 / (x + 2) * (1 - u) powr (x + 2)) has_real_derivative ?f xa) (at xa); ⋀x. ⟦?a < ereal x; ereal x < ?b⟧ ⟹ isCont ?f x; AE x in lborel. ?a < ereal x ⟶ ereal x < ?b ⟶ 0 ≤ ?f x; (((λu. - 1 / (x + 2) * (1 - u) powr (x + 2)) ∘ real_of_ereal) ⤏ ?A) (at_right ?a); (((λu. - 1 / (x + 2) * (1 - u) powr (x + 2)) ∘ real_of_ereal) ⤏ ?B) (at_left ?b)⟧ ⟹ set_integrable lborel (einterval ?a ?b) ?f› ‹⟦?a < ?b; ⋀xa. ⟦?a < ereal xa; ereal xa < ?b⟧ ⟹ ((λu. - 1 / (x + 2) * (1 - u) powr (x + 2)) has_real_derivative ?f xa) (at xa); ⋀x. ⟦?a < ereal x; ereal x < ?b⟧ ⟹ isCont ?f x; AE x in lborel. ?a < ereal x ⟶ ereal x < ?b ⟶ 0 ≤ ?f x; (((λu. - 1 / (x + 2) * (1 - u) powr (x + 2)) ∘ real_of_ereal) ⤏ ?A) (at_right ?a); (((λu. - 1 / (x + 2) * (1 - u) powr (x + 2)) ∘ real_of_ereal) ⤏ ?B) (at_left ?b)⟧ ⟹ interval_lebesgue_integral lborel ?a ?b ?f = ?B - ?A›*)) (*goals: 1. ‹ereal (exp (- (1::real))) < (1::ereal)› 2. ‹⋀xa::real. ⟦ereal (exp (- (1::real))) < ereal xa; ereal xa < (1::ereal)⟧ ⟹ ((λu::real. - (1::real) / ((x::real) + (2::real)) * ((1::real) - u) powr (x + (2::real))) has_real_derivative ((1::real) - xa) powr (x + (1::real))) (at xa)› 3. ‹⋀xa::real. ⟦ereal (exp (- (1::real))) < ereal xa; ereal xa < (1::ereal)⟧ ⟹ isCont (λu::real. ((1::real) - u) powr ((x::real) + (1::real))) xa› 4. ‹AE xa::real in lborel. ereal (exp (- (1::real))) < ereal xa ⟶ ereal xa < (1::ereal) ⟶ (0::real) ≤ ((1::real) - xa) powr ((x::real) + (1::real))› 5. ‹(((λu::real. - (1::real) / ((x::real) + (2::real)) * ((1::real) - u) powr (x + (2::real))) ∘ real_of_ereal) ⤏ (?A::real)) (at_right (ereal (exp (- (1::real)))))› 6. ‹(((λu::real. - (1::real) / ((x::real) + (2::real)) * ((1::real) - u) powr (x + (2::real))) ∘ real_of_ereal) ⤏ (?B::real)) (at_left (1::ereal))›*) fix u :: real assume u: "ereal (exp (-1)) < ereal u" "ereal u < 1" (*‹ereal (exp (- (1::real))) < ereal (u::real)› ‹ereal (u::real) < (1::ereal)›*) show "(?F has_field_derivative (1 - u) powr (x + 1)) (at u)" using u (*‹ereal (exp (- 1)) < ereal u› ‹ereal u < 1›*) ‹x > -2› (*‹- 2 < x›*) by (auto intro!: derivative_eq_intros (*‹(λx. x) = ?g' ⟹ ((λx. x) has_derivative ?g') ?F› ‹id = ?g' ⟹ (id has_derivative ?g') ?F› ‹(λx. 0) = ?g' ⟹ ((λx. ?f2) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?r1 *⇩R ?g'1 x) = ?g'⟧ ⟹ ((λx. ?r1 *⇩R ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x *⇩R ?x1) = ?g'⟧ ⟹ ((λx. ?g1 x *⇩R ?x1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?x1 * ?g'1 x) = ?g'⟧ ⟹ ((λx. ?x1 * ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x * ?y1) = ?g'⟧ ⟹ ((λx. ?g1 x * ?y1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. of_real (?g'1 x)) = ?g'⟧ ⟹ ((λx. of_real (?g1 x)) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x + ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x + ?g1 x) has_derivative ?g') ?F› ‹⟦⋀i. i ∈ ?I1 ⟹ (?f1 i has_derivative ?f'1 i) ?F; (λx. ∑i∈?I1. ?f'1 i x) = ?g'⟧ ⟹ ((λx. ∑i∈?I1. ?f1 i x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (λx. - ?f'1 x) = ?g'⟧ ⟹ ((λx. - ?f1 x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x - ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x - ?g1 x) has_derivative ?g') ?F› and more 140 facts*) simp: one_ereal_def (*‹1 = ereal 1›*) add_ac (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)›*)) show "isCont (λu. (1 - u) powr (x + 1)) u" using u (*‹ereal (exp (- (1::real))) < ereal (u::real)› ‹ereal u < 1›*) by (auto intro!: continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 286 facts*)) next (*goals: 1. ‹ereal (exp (- 1)) < 1› 2. ‹AE xa in lborel. ereal (exp (- 1)) < ereal xa ⟶ ereal xa < 1 ⟶ 0 ≤ (1 - xa) powr (x + 1)› 3. ‹(((λu. - 1 / (x + 2) * (1 - u) powr (x + 2)) ∘ real_of_ereal) ⤏ ?A) (at_right (ereal (exp (- 1))))› 4. ‹(((λu. - 1 / (x + 2) * (1 - u) powr (x + 2)) ∘ real_of_ereal) ⤏ ?B) (at_left 1)›*) show "(((λu. - 1 / (x + 2) * (1 - u) powr (x + 2)) ∘ real_of_ereal) ⤏ - 1 / (x + 2) * (1 - exp (-1)) powr (x + 2)) (at_right (ereal (exp (- 1))))" unfolding ereal_tendsto_simps (*goal: ‹((λu. - 1 / (x + 2) * (1 - u) powr (x + 2)) ⤏ - 1 / (x + 2) * (1 - exp (- 1)) powr (x + 2)) (at_right (exp (- 1)))›*) by real_asymp show "(((λu. - 1 / (x + 2) * (1 - u) powr (x + 2)) ∘ real_of_ereal) ⤏ 0) (at_left 1)" unfolding one_ereal_def (*goal: ‹(((λu::real. - (1::real) / ((x::real) + (2::real)) * ((1::real) - u) powr (x + (2::real))) ∘ real_of_ereal) ⤏ (0::real)) (at_left (ereal (1::real)))›*) unfolding ereal_tendsto_simps (*goal: ‹((λu::real. - (1::real) / ((x::real) + (2::real)) * ((1::real) - u) powr (x + (2::real))) ⤏ (0::real)) (at_left (1::real))›*) using ‹x > -2› (*‹- 2 < x›*) by real_asymp qed (auto) (*solves the remaining goals: 1. ‹ereal (exp (- 1)) < 1› 2. ‹AE xa in lborel. ereal (exp (- 1)) < ereal xa ⟶ ereal xa < 1 ⟶ 0 ≤ (1 - xa) powr (x + 1)›*) thus "interval_lebesgue_integrable lborel (ereal (exp (- 1))) (ereal 1) (λu. (1 - u) powr (x + 1))" by (simp add: interval_lebesgue_integrable_def (*‹interval_lebesgue_integrable ?M ?a ?b ?f = (if ?a ≤ ?b then set_integrable ?M (einterval ?a ?b) ?f else set_integrable ?M (einterval ?b ?a) ?f)›*) one_ereal_def (*‹1 = ereal 1›*)) qed (auto simp add: g2_def (*‹g2 ≡ λu. (- ln u) powr x * (u - ln u - 1) / (1 - u)›*) set_borel_measurable_def (*‹set_borel_measurable ?M ?A ?f ≡ (λx. indicat_real ?A x *⇩R ?f x) ∈ borel_measurable ?M›*)) (*solves the remaining goals: 1. ‹set_borel_measurable borel {exp (- 1)<..<1} g2› 2. ‹exp (- 1) < 1›*) lemma bound2: "norm (f z u) ≤ g2 u" if z: "Re z ∈ {x..y}" and u: "u ∈ {exp (-1)<..<1}" for z u proof (-) (*goal: ‹cmod ((f::complex ⇒ real ⇒ complex) (z::complex) (u::real)) ≤ (g2::real ⇒ real) u›*) have "0 < exp (-1::real)" by simp also (*calculation: ‹0 < exp (- 1)›*) have "… ≤ u" using u (*‹u ∈ {exp (- 1)<..<1}›*) by (simp add: einterval_def (*‹einterval ?a ?b = {x. ?a < ereal x ∧ ereal x < ?b}›*)) finally (*calculation: ‹0 < u›*) have "u > 0" . from u (*‹u ∈ {exp (- 1)<..<1}›*) ‹u > 0› (*‹0 < u›*) have ln_u: "ln u > ln (exp (-1))" apply (subst ln_less_cancel_iff (*‹⟦0 < ?x; 0 < ?y⟧ ⟹ (ln ?x < ln ?y) = (?x < ?y)›*)) (*goals: 1. ‹⟦u ∈ {exp (- 1)<..<1}; 0 < u⟧ ⟹ 0 < exp (- 1)› 2. ‹⟦u ∈ {exp (- 1)<..<1}; 0 < u⟧ ⟹ 0 < u› 3. ‹⟦u ∈ {exp (- 1)<..<1}; 0 < u⟧ ⟹ exp (- 1) < u› discuss goal 1*) apply ((auto simp: einterval_def (*‹einterval (?a::ereal) (?b::ereal) = {x::real. ?a < ereal x ∧ ereal x < ?b}›*))[1]) (*discuss goal 2*) apply ((auto simp: einterval_def (*‹einterval (?a::ereal) (?b::ereal) = {x::real. ?a < ereal x ∧ ereal x < ?b}›*))[1]) (*discuss goal 3*) apply ((auto simp: einterval_def (*‹einterval (?a::ereal) (?b::ereal) = {x::real. ?a < ereal x ∧ ereal x < ?b}›*))[1]) (*proven 3 subgoals*) . from z (*‹Re z ∈ {x..y}›*) u (*‹u ∈ {exp (- 1)<..<1}›*) ‹u > 0› (*‹0 < u›*) have "norm (f z u) = (- ln u) powr Re z * ¦u - ln u - 1¦ / (1 - u)" unfolding f_def norm_mult norm_divide norm_of_real (*goal: ‹cmod (complex_of_real (- ln u) powr z) / ¦1 - u¦ * ¦- ln u + u - 1¦ = (- ln u) powr Re z * ¦u - ln u - 1¦ / (1 - u)›*) by (simp add: norm_powr_real_powr (*‹⟦(?w::complex) ∈ ℝ; (0::real) ≤ Re ?w⟧ ⟹ cmod (?w powr (?z::complex)) = Re ?w powr Re ?z›*) einterval_def (*‹einterval (?a::ereal) (?b::ereal) = {x::real. ?a < ereal x ∧ ereal x < ?b}›*)) also (*calculation: ‹cmod (f z u) = (- ln u) powr Re z * ¦u - ln u - 1¦ / (1 - u)›*) have "¦u - ln u - 1¦ = u - ln u - 1" using u (*‹u ∈ {exp (- 1)<..<1}›*) ‹u > 0› (*‹(0::real) < (u::real)›*) ln_add_one_self_le_self2[of "u - 1"] (*‹- 1 < u - 1 ⟹ ln (1 + (u - 1)) ≤ u - 1›*) by (simp add: einterval_def (*‹einterval ?a ?b = {x. ?a < ereal x ∧ ereal x < ?b}›*)) also (*calculation: ‹cmod ((f::complex ⇒ real ⇒ complex) (z::complex) (u::real)) = (- ln u) powr Re z * (u - ln u - (1::real)) / ((1::real) - u)›*) have "(- ln u) powr Re z * (u - ln u - 1) / (1 - u) ≤ (- ln u) powr x * (u - ln u - 1) / (1 - u)" using z (*‹Re z ∈ {x..y}›*) u (*‹(u::real) ∈ {exp (- (1::real))<..<1::real}›*) ‹u > 0› (*‹(0::real) < (u::real)›*) ln_u (*‹ln (exp (- 1)) < ln u›*) ln_add_one_self_le_self2[of "u - 1"] (*‹- 1 < u - 1 ⟹ ln (1 + (u - 1)) ≤ u - 1›*) apply (intro mult_right_mono (*‹⟦?a ≤ ?b; 0 ≤ ?c⟧ ⟹ ?a * ?c ≤ ?b * ?c›*) divide_right_mono (*‹⟦?a ≤ ?b; 0 ≤ ?c⟧ ⟹ ?a / ?c ≤ ?b / ?c›*) powr_mono' (*‹⟦?a ≤ ?b; 0 ≤ ?x; ?x ≤ 1⟧ ⟹ ?x powr ?b ≤ ?x powr ?a›*)) (*goals: 1. ‹⟦Re z ∈ {x..y}; u ∈ {exp (- 1)<..<1}; 0 < u; ln (exp (- 1)) < ln u; - 1 < u - 1 ⟹ ln (1 + (u - 1)) ≤ u - 1⟧ ⟹ x ≤ Re z› 2. ‹⟦Re z ∈ {x..y}; u ∈ {exp (- 1)<..<1}; 0 < u; ln (exp (- 1)) < ln u; - 1 < u - 1 ⟹ ln (1 + (u - 1)) ≤ u - 1⟧ ⟹ 0 ≤ - ln u› 3. ‹⟦Re z ∈ {x..y}; u ∈ {exp (- 1)<..<1}; 0 < u; ln (exp (- 1)) < ln u; - 1 < u - 1 ⟹ ln (1 + (u - 1)) ≤ u - 1⟧ ⟹ - ln u ≤ 1› 4. ‹⟦Re z ∈ {x..y}; u ∈ {exp (- 1)<..<1}; 0 < u; ln (exp (- 1)) < ln u; - 1 < u - 1 ⟹ ln (1 + (u - 1)) ≤ u - 1⟧ ⟹ 0 ≤ u - ln u - 1› 5. ‹⟦Re z ∈ {x..y}; u ∈ {exp (- 1)<..<1}; 0 < u; ln (exp (- 1)) < ln u; - 1 < u - 1 ⟹ ln (1 + (u - 1)) ≤ u - 1⟧ ⟹ 0 ≤ 1 - u› discuss goal 1*) apply ((auto simp: einterval_def (*‹einterval ?a ?b = {x. ?a < ereal x ∧ ereal x < ?b}›*))[1]) (*discuss goal 2*) apply ((auto simp: einterval_def (*‹einterval ?a ?b = {x. ?a < ereal x ∧ ereal x < ?b}›*))[1]) (*discuss goal 3*) apply ((auto simp: einterval_def (*‹einterval ?a ?b = {x. ?a < ereal x ∧ ereal x < ?b}›*))[1]) (*discuss goal 4*) apply ((auto simp: einterval_def (*‹einterval ?a ?b = {x. ?a < ereal x ∧ ereal x < ?b}›*))[1]) (*discuss goal 5*) apply ((auto simp: einterval_def (*‹einterval ?a ?b = {x. ?a < ereal x ∧ ereal x < ?b}›*))[1]) (*proven 5 subgoals*) . finally (*calculation: ‹cmod (f z u) ≤ (- ln u) powr x * (u - ln u - 1) / (1 - u)›*) show "norm (f z u) ≤ g2 u" by (simp add: g2_def (*‹g2 ≡ λu. (- ln u) powr x * (u - ln u - 1) / (1 - u)›*)) qed lemma integrable2_aux: "interval_lebesgue_integrable lborel (exp (-1)) 1 (f z)" if z: "Re z ∈ {x..y}" for z proof (-) (*goal: ‹complex_interval_lebesgue_integrable lborel (ereal (exp (- 1))) 1 (f z)›*) have "set_integrable lborel {exp (-1)<..<1} (f z)" proof (rule set_integrable_bound[OF _ _ AE_I2[OF impI]] (*‹⟦set_integrable ?M ?A ?f; set_borel_measurable ?M ?A ?g; ⋀x. ⟦x ∈ space ?M; x ∈ ?A⟧ ⟹ norm (?g x) ≤ norm (?f x)⟧ ⟹ set_integrable ?M ?A ?g›*)) (*goals: 1. ‹set_integrable lborel {exp (- 1)<..<1} ?f› 2. ‹set_borel_measurable lborel {exp (- 1)<..<1} (f z)› 3. ‹⋀x. ⟦x ∈ space lborel; x ∈ {exp (- 1)<..<1}⟧ ⟹ cmod (f z x) ≤ norm (?f x)›*) fix u :: real assume "u ∈ {exp (-1)<..<1}" (*‹(u::real) ∈ {exp (- (1::real))<..<1::real}›*) hence "norm (f z u) ≤ g2 u" using z (*‹Re z ∈ {x..y}›*) apply (intro bound2 (*‹⟦Re ?z ∈ {x..y}; ?u ∈ {exp (- 1)<..<1}⟧ ⟹ cmod (f ?z ?u) ≤ g2 ?u›*)) (*goals: 1. ‹⟦u ∈ {exp (- 1)<..<1}; Re z ∈ {x..y}⟧ ⟹ Re z ∈ {x..y}› 2. ‹⟦u ∈ {exp (- 1)<..<1}; Re z ∈ {x..y}⟧ ⟹ u ∈ {exp (- 1)<..<1}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . also (*calculation: ‹cmod (f z u) ≤ g2 u›*) have "… ≤ norm (g2 u)" by simp finally (*calculation: ‹cmod (f z u) ≤ norm (g2 u)›*) show "norm (f z u) ≤ norm (g2 u)" . qed (use integrable_bound2 in ‹simp_all add: interval_lebesgue_integrable_def one_ereal_def set_borel_measurable_def f_def›) (*solves the remaining goals: 1. ‹set_integrable lborel {exp (- 1)<..<1} g2› 2. ‹set_borel_measurable lborel {exp (- 1)<..<1} (f z)›*) thus "?thesis" (*goal: ‹complex_interval_lebesgue_integrable lborel (ereal (exp (- 1))) 1 (f z)›*) by (simp add: interval_lebesgue_integrable_def (*‹interval_lebesgue_integrable ?M ?a ?b ?f = (if ?a ≤ ?b then set_integrable ?M (einterval ?a ?b) ?f else set_integrable ?M (einterval ?b ?a) ?f)›*) one_ereal_def (*‹1 = ereal 1›*)) qed lemma uniform_limit2: "uniform_limit {z. Re z ∈ {x..y}} (λa z. LBINT u=exp (-1)..a. f z u) (λz. LBINT u=exp (-1)..1. f z u) (at_left 1)" apply (intro uniform_limit_interval_integral_right[of _ _ g2] (*‹⟦interval_lebesgue_integrable lborel ?a ?b g2; ⋀y. y ∈ ?Y ⟹ set_borel_measurable borel (einterval ?a ?b) (?f y); ⋀y. y ∈ ?Y ⟹ AE x∈einterval ?a ?b in lborel. norm (?f y x) ≤ g2 x; ?a < ?b⟧ ⟹ uniform_limit ?Y (λb' y. interval_lebesgue_integral lborel ?a b' (?f y)) (λy. interval_lebesgue_integral lborel ?a ?b (?f y)) (at_left ?b)›*) AE_I2 (*‹(⋀x. x ∈ space ?M ⟹ ?P x) ⟹ almost_everywhere ?M ?P›*) impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goals: 1. ‹interval_lebesgue_integrable lborel (ereal (exp (- 1))) 1 g2› 2. ‹⋀z. z ∈ {z. Re z ∈ {x..y}} ⟹ set_borel_measurable borel (einterval (ereal (exp (- 1))) 1) (f z)› 3. ‹⋀z xa. ⟦z ∈ {z. Re z ∈ {x..y}}; xa ∈ space lborel; xa ∈ einterval (ereal (exp (- 1))) 1⟧ ⟹ cmod (f z xa) ≤ g2 xa› 4. ‹ereal (exp (- 1)) < 1› discuss goal 1*) apply ((use bound2 integrable_bound2 in ‹simp_all add: einterval_def f_def set_borel_measurable_def›)[1]) (*discuss goal 2*) apply ((use bound2 integrable_bound2 in ‹simp_all add: einterval_def f_def set_borel_measurable_def›)[1]) (*discuss goal 3*) apply ((use bound2 integrable_bound2 in ‹simp_all add: einterval_def f_def set_borel_measurable_def›)[1]) (*discuss goal 4*) apply ((use bound2 integrable_bound2 in ‹simp_all add: einterval_def f_def set_borel_measurable_def›)[1]) (*proven 4 subgoals*) . lemma uniform_limit2': "uniform_limit {z. Re z ∈ {x..y}} (λn z. LBINT u=exp (-1)..ereal (1-(1/2)^Suc n). f z u) (λz. LBINT u=exp (-1)..1. f z u) sequentially" proof (rule filterlim_compose[OF uniform_limit2] (*‹filterlim (?f::?'c ⇒ ereal) (at_left (1::ereal)) (?F1.0::?'c filter) ⟹ uniform_limit {z::complex. Re z ∈ {x::real..y::real}} (λ(x::?'c) z::complex. complex_interval_lebesgue_integral lborel (ereal (exp (- (1::real)))) (?f x) ((f::complex ⇒ real ⇒ complex) z)) (λz::complex. complex_interval_lebesgue_integral lborel (ereal (exp (- (1::real)))) (1::ereal) (f z)) ?F1.0›*)) (*goal: ‹LIM x sequentially. ereal (1 - (1 / 2) ^ Suc x) :> at_left 1›*) have "filterlim (λn. 1 - (1/2)^Suc n :: real) (at_left 1) sequentially" by real_asymp hence "filtermap ereal (filtermap (λn. (1 - (1 / 2) ^ Suc n)) sequentially) ≤ filtermap ereal (at_left 1)" unfolding filterlim_def (*goal: ‹filtermap ereal (filtermap (λn. 1 - (1 / 2) ^ Suc n) sequentially) ≤ filtermap ereal (at_left 1)›*) by (rule filtermap_mono (*‹?F ≤ ?F' ⟹ filtermap ?f ?F ≤ filtermap ?f ?F'›*)) thus "filterlim (λn. ereal (1 - (1/2)^Suc n)) (at_left 1) sequentially" unfolding one_ereal_def at_left_ereal (*goal: ‹LIM n sequentially. ereal (1 - (1 / 2) ^ Suc n) :> filtermap ereal (at_left 1)›*) by (simp add: filterlim_def (*‹filterlim ?f ?F2.0 ?F1.0 = (filtermap ?f ?F1.0 ≤ ?F2.0)›*) filtermap_filtermap (*‹filtermap ?f (filtermap ?g ?F) = filtermap (λx. ?f (?g x)) ?F›*)) qed lemma bound1: "norm (f z u) ≤ g1 u" if z: "Re z ∈ {x..y}" and u: "u ∈ {0<..<exp (-1)}" for z u proof (-) (*goal: ‹cmod (f z u) ≤ g1 u›*) from u (*‹u ∈ {0<..<exp (- 1)}›*) have "u ≤ exp (-1)" by (simp add: einterval_def (*‹einterval ?a ?b = {x. ?a < ereal x ∧ ereal x < ?b}›*)) also (*calculation: ‹(u::real) ≤ exp (- (1::real))›*) have "exp (-1) < exp (0::real)" apply (subst exp_less_cancel_iff (*‹(exp ?x < exp ?y) = (?x < ?y)›*)) (*goal: ‹exp (- 1) < exp 0›*) by auto also (*calculation: ‹u < exp 0›*) have "exp (0::real) = 1" by simp finally (*calculation: ‹u < 1›*) have "u < 1" . from u (*‹u ∈ {0<..<exp (- 1)}›*) have "ln u < ln (exp (-1))" apply (subst ln_less_cancel_iff (*‹⟦(0::real) < (?x::real); (0::real) < (?y::real)⟧ ⟹ (ln ?x < ln ?y) = (?x < ?y)›*)) (*goals: 1. ‹u ∈ {0<..<exp (- 1)} ⟹ 0 < u› 2. ‹u ∈ {0<..<exp (- 1)} ⟹ 0 < exp (- 1)› 3. ‹u ∈ {0<..<exp (- 1)} ⟹ u < exp (- 1)› discuss goal 1*) apply ((auto simp: einterval_def (*‹einterval ?a ?b = {x. ?a < ereal x ∧ ereal x < ?b}›*))[1]) (*discuss goal 2*) apply ((auto simp: einterval_def (*‹einterval (?a::ereal) (?b::ereal) = {x::real. ?a < ereal x ∧ ereal x < ?b}›*))[1]) (*discuss goal 3*) apply ((auto simp: einterval_def (*‹einterval ?a ?b = {x. ?a < ereal x ∧ ereal x < ?b}›*))[1]) (*proven 3 subgoals*) . hence ln_u: "ln u < -1" by simp from z (*‹Re (z::complex) ∈ {x::real..y::real}›*) u (*‹u ∈ {0<..<exp (- 1)}›*) ‹u < 1› (*‹u < 1›*) have "norm (f z u) = (- ln u) powr Re z * ¦u - ln u - 1¦ / (1 - u)" unfolding f_def norm_mult norm_divide norm_of_real (*goal: ‹cmod (complex_of_real (- ln u) powr z) / ¦1 - u¦ * ¦- ln u + u - 1¦ = (- ln u) powr Re z * ¦u - ln u - 1¦ / (1 - u)›*) by (simp add: norm_powr_real_powr (*‹⟦?w ∈ ℝ; 0 ≤ Re ?w⟧ ⟹ cmod (?w powr ?z) = Re ?w powr Re ?z›*) einterval_def (*‹einterval ?a ?b = {x. ?a < ereal x ∧ ereal x < ?b}›*)) also (*calculation: ‹cmod (f z u) = (- ln u) powr Re z * ¦u - ln u - 1¦ / (1 - u)›*) have "¦u - ln u - 1¦ = u - ln u - 1" using u (*‹(u::real) ∈ {0::real<..<exp (- (1::real))}›*) ln_add_one_self_le_self2[of "u - 1"] (*‹- 1 < u - 1 ⟹ ln (1 + (u - 1)) ≤ u - 1›*) by (simp add: einterval_def (*‹einterval ?a ?b = {x. ?a < ereal x ∧ ereal x < ?b}›*)) also (*calculation: ‹cmod (f z u) = (- ln u) powr Re z * (u - ln u - 1) / (1 - u)›*) have "(- ln u) powr Re z * (u - ln u - 1) / (1 - u) ≤ (- ln u) powr y * (u - ln u - 1) / (1 - u)" using z (*‹Re (z::complex) ∈ {x::real..y::real}›*) u (*‹u ∈ {0<..<exp (- 1)}›*) ln_u (*‹ln u < - 1›*) ‹u < 1› (*‹u < 1›*) apply (intro mult_right_mono (*‹⟦(?a::?'a) ≤ (?b::?'a); (0::?'a) ≤ (?c::?'a)⟧ ⟹ ?a * ?c ≤ ?b * ?c›*) divide_right_mono (*‹⟦(?a::?'a) ≤ (?b::?'a); (0::?'a) ≤ (?c::?'a)⟧ ⟹ ?a / ?c ≤ ?b / ?c›*) powr_mono (*‹⟦(?a::real) ≤ (?b::real); (1::real) ≤ (?x::real)⟧ ⟹ ?x powr ?a ≤ ?x powr ?b›*)) (*goals: 1. ‹⟦Re z ∈ {x..y}; u ∈ {0<..<exp (- 1)}; ln u < - 1; u < 1⟧ ⟹ Re z ≤ y› 2. ‹⟦Re z ∈ {x..y}; u ∈ {0<..<exp (- 1)}; ln u < - 1; u < 1⟧ ⟹ 1 ≤ - ln u› 3. ‹⟦Re z ∈ {x..y}; u ∈ {0<..<exp (- 1)}; ln u < - 1; u < 1⟧ ⟹ 0 ≤ u - ln u - 1› 4. ‹⟦Re z ∈ {x..y}; u ∈ {0<..<exp (- 1)}; ln u < - 1; u < 1⟧ ⟹ 0 ≤ 1 - u› discuss goal 1*) apply ((auto simp: einterval_def (*‹einterval ?a ?b = {x. ?a < ereal x ∧ ereal x < ?b}›*))[1]) (*discuss goal 2*) apply ((auto simp: einterval_def (*‹einterval ?a ?b = {x. ?a < ereal x ∧ ereal x < ?b}›*))[1]) (*discuss goal 3*) apply ((auto simp: einterval_def (*‹einterval ?a ?b = {x. ?a < ereal x ∧ ereal x < ?b}›*))[1]) (*discuss goal 4*) apply ((auto simp: einterval_def (*‹einterval ?a ?b = {x. ?a < ereal x ∧ ereal x < ?b}›*))[1]) (*proven 4 subgoals*) . finally (*calculation: ‹cmod (f z u) ≤ (- ln u) powr y * (u - ln u - 1) / (1 - u)›*) show "norm (f z u) ≤ g1 u" by (simp add: g1_def (*‹g1 ≡ λx. (- ln x) powr y * (x - ln x - 1) / (1 - x)›*)) qed lemma integrable1_aux: "interval_lebesgue_integrable lborel 0 (exp (-1)) (f z)" if z: "Re z ∈ {x..y}" for z proof (-) (*goal: ‹complex_interval_lebesgue_integrable lborel (0::ereal) (ereal (exp (- (1::real)))) ((f::complex ⇒ real ⇒ complex) (z::complex))›*) have "set_integrable lborel {0<..<exp (-1)} (f z)" proof (rule set_integrable_bound[OF _ _ AE_I2[OF impI]] (*‹⟦set_integrable ?M ?A ?f; set_borel_measurable ?M ?A ?g; ⋀x. ⟦x ∈ space ?M; x ∈ ?A⟧ ⟹ norm (?g x) ≤ norm (?f x)⟧ ⟹ set_integrable ?M ?A ?g›*)) (*goals: 1. ‹set_integrable lborel {0<..<exp (- 1)} ?f› 2. ‹set_borel_measurable lborel {0<..<exp (- 1)} (f z)› 3. ‹⋀x. ⟦x ∈ space lborel; x ∈ {0<..<exp (- 1)}⟧ ⟹ cmod (f z x) ≤ norm (?f x)›*) fix u :: real assume "u ∈ {0<..<exp (-1)}" (*‹(u::real) ∈ {0::real<..<exp (- (1::real))}›*) hence "norm (f z u) ≤ g1 u" using z (*‹Re z ∈ {x..y}›*) apply (intro bound1 (*‹⟦Re ?z ∈ {x..y}; ?u ∈ {0<..<exp (- 1)}⟧ ⟹ cmod (f ?z ?u) ≤ g1 ?u›*)) (*goals: 1. ‹⟦u ∈ {0<..<exp (- 1)}; Re z ∈ {x..y}⟧ ⟹ Re z ∈ {x..y}› 2. ‹⟦u ∈ {0<..<exp (- 1)}; Re z ∈ {x..y}⟧ ⟹ u ∈ {0<..<exp (- 1)}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . also (*calculation: ‹cmod ((f::complex ⇒ real ⇒ complex) (z::complex) (u::real)) ≤ (g1::real ⇒ real) u›*) have "… ≤ norm (g1 u)" by simp finally (*calculation: ‹cmod (f z u) ≤ norm (g1 u)›*) show "norm (f z u) ≤ norm (g1 u)" . qed (use integrable_bound1 in ‹simp_all add: interval_lebesgue_integrable_def zero_ereal_def set_borel_measurable_def f_def›) (*solves the remaining goals: 1. ‹set_integrable lborel {0<..<exp (- 1)} g1› 2. ‹set_borel_measurable lborel {0<..<exp (- 1)} (f z)›*) thus "?thesis" (*goal: ‹complex_interval_lebesgue_integrable lborel (0::ereal) (ereal (exp (- (1::real)))) ((f::complex ⇒ real ⇒ complex) (z::complex))›*) by (simp add: interval_lebesgue_integrable_def (*‹interval_lebesgue_integrable ?M ?a ?b ?f = (if ?a ≤ ?b then set_integrable ?M (einterval ?a ?b) ?f else set_integrable ?M (einterval ?b ?a) ?f)›*) zero_ereal_def (*‹0 = ereal 0›*)) qed lemma uniform_limit1: "uniform_limit {z. Re z ∈ {x..y}} (λa z. LBINT u=a..exp (-1). f z u) (λz. LBINT u=0..exp (-1). f z u) (at_right 0)" apply (intro uniform_limit_interval_integral_left[of _ _ g1] (*‹⟦interval_lebesgue_integrable lborel ?a ?b g1; ⋀y. y ∈ ?Y ⟹ set_borel_measurable borel (einterval ?a ?b) (?f y); ⋀y. y ∈ ?Y ⟹ AE x∈einterval ?a ?b in lborel. norm (?f y x) ≤ g1 x; ?a < ?b⟧ ⟹ uniform_limit ?Y (λa' y. interval_lebesgue_integral lborel a' ?b (?f y)) (λy. interval_lebesgue_integral lborel ?a ?b (?f y)) (at_right ?a)›*) AE_I2 (*‹(⋀x. x ∈ space ?M ⟹ ?P x) ⟹ almost_everywhere ?M ?P›*) impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goals: 1. ‹interval_lebesgue_integrable lborel 0 (ereal (exp (- 1))) g1› 2. ‹⋀z. z ∈ {z. Re z ∈ {x..y}} ⟹ set_borel_measurable borel (einterval 0 (ereal (exp (- 1)))) (f z)› 3. ‹⋀z xa. ⟦z ∈ {z. Re z ∈ {x..y}}; xa ∈ space lborel; xa ∈ einterval 0 (ereal (exp (- 1)))⟧ ⟹ cmod (f z xa) ≤ g1 xa› 4. ‹0 < ereal (exp (- 1))› discuss goal 1*) apply ((use bound1 integrable_bound1 in ‹simp_all add: einterval_def f_def set_borel_measurable_def›)[1]) (*discuss goal 2*) apply ((use bound1 integrable_bound1 in ‹simp_all add: einterval_def f_def set_borel_measurable_def›)[1]) (*discuss goal 3*) apply ((use bound1 integrable_bound1 in ‹simp_all add: einterval_def f_def set_borel_measurable_def›)[1]) (*discuss goal 4*) apply ((use bound1 integrable_bound1 in ‹simp_all add: einterval_def f_def set_borel_measurable_def›)[1]) (*proven 4 subgoals*) . lemma uniform_limit1': "uniform_limit {z. Re z ∈ {x..y}} (λn z. LBINT u=ereal ((1/2)^Suc n)..exp (-1). f z u) (λz. LBINT u=0..exp (-1). f z u) sequentially" proof (rule filterlim_compose[OF uniform_limit1] (*‹filterlim ?f (at_right 0) ?F1.0 ⟹ uniform_limit {z. Re z ∈ {x..y}} (λx z. complex_interval_lebesgue_integral lborel (?f x) (ereal (exp (- 1))) (f z)) (λz. complex_interval_lebesgue_integral lborel 0 (ereal (exp (- 1))) (f z)) ?F1.0›*)) (*goal: ‹LIM x sequentially. ereal ((1 / 2) ^ Suc x) :> at_right 0›*) have "filterlim (λn. (1/2)^Suc n :: real) (at_right 0) sequentially" by real_asymp hence "filtermap ereal (filtermap (λn. ((1 / 2) ^ Suc n)) sequentially) ≤ filtermap ereal (at_right 0)" unfolding filterlim_def (*goal: ‹filtermap ereal (filtermap (λn. (1 / 2) ^ Suc n) sequentially) ≤ filtermap ereal (at_right 0)›*) by (rule filtermap_mono (*‹?F ≤ ?F' ⟹ filtermap ?f ?F ≤ filtermap ?f ?F'›*)) thus "filterlim (λn. ereal ((1/2)^Suc n)) (at_right 0) sequentially" unfolding zero_ereal_def at_right_ereal (*goal: ‹LIM n sequentially. ereal ((1 / 2) ^ Suc n) :> filtermap ereal (at_right 0)›*) by (simp add: filterlim_def (*‹filterlim ?f ?F2.0 ?F1.0 = (filtermap ?f ?F1.0 ≤ ?F2.0)›*) filtermap_filtermap (*‹filtermap ?f (filtermap ?g ?F) = filtermap (λx. ?f (?g x)) ?F›*)) qed end text ‹ With all of the above bounds, we have shown that the integral exists for any ‹z› with $\mathfrak{R}(z) > -2$. › theorem Hadjicostas_integral_integrable: "interval_lebesgue_integrable lborel 0 1 (f z)" if z: "Re z > -2" proof (-) (*goal: ‹complex_interval_lebesgue_integrable lborel 0 1 (f z)›*) from dense[OF z] (*‹∃za>- 2. za < Re z›*) obtain x where x: "x > -2" "Re z > x" (*goal: ‹(⋀x. ⟦- 2 < x; x < Re z⟧ ⟹ thesis) ⟹ thesis›*) by blast have "interval_lebesgue_integrable lborel 0 (exp(-1)) (f z)" apply (rule integrable1_aux[of x _ "Re z + 1"] (*‹⟦- 2 < x; Re ?z ∈ {x..Re z + 1}⟧ ⟹ complex_interval_lebesgue_integrable lborel 0 (ereal (exp (- 1))) (f ?z)›*)) (*goals: 1. ‹- 2 < x› 2. ‹Re z ∈ {x..Re z + 1}› discuss goal 1*) apply ((use x in auto)[1]) (*discuss goal 2*) apply ((use x in auto)[1]) (*proven 2 subgoals*) . moreover have "interval_lebesgue_integrable lborel (exp(-1)) 1 (f z)" apply (rule integrable2_aux[of x _ "Re z + 1"] (*‹⟦- 2 < x; Re ?z ∈ {x..Re z + 1}⟧ ⟹ complex_interval_lebesgue_integrable lborel (ereal (exp (- 1))) 1 (f ?z)›*)) (*goals: 1. ‹- 2 < x› 2. ‹Re z ∈ {x..Re z + 1}› discuss goal 1*) apply ((use x in auto)[1]) (*discuss goal 2*) apply ((use x in auto)[1]) (*proven 2 subgoals*) . ultimately show "interval_lebesgue_integrable lborel 0 1 (f z)" apply (rule interval_lebesgue_integrable_combine (*‹⟦interval_lebesgue_integrable lborel ?A ?B ?f; interval_lebesgue_integrable lborel ?B ?C ?f; set_borel_measurable borel (einterval ?A ?C) ?f; ?A ≤ ?B; ?B ≤ ?C⟧ ⟹ interval_lebesgue_integrable lborel ?A ?C ?f›*)) (*goals: 1. ‹set_borel_measurable borel (einterval 0 1) (f z)› 2. ‹0 ≤ ereal (exp (- 1))› 3. ‹ereal (exp (- 1)) ≤ 1› discuss goal 1*) apply ((auto simp: f_def (*‹f ≡ λz u. complex_of_real (- ln u) powr z / complex_of_real (1 - u) * complex_of_real (- ln u + u - 1)›*) set_borel_measurable_def (*‹set_borel_measurable ?M ?A ?f ≡ (λx. indicat_real ?A x *⇩R ?f x) ∈ borel_measurable ?M›*))[1]) (*discuss goal 2*) apply ((auto simp: f_def (*‹f ≡ λz u. complex_of_real (- ln u) powr z / complex_of_real (1 - u) * complex_of_real (- ln u + u - 1)›*) set_borel_measurable_def (*‹set_borel_measurable ?M ?A ?f ≡ (λx. indicat_real ?A x *⇩R ?f x) ∈ borel_measurable ?M›*))[1]) (*discuss goal 3*) apply ((auto simp: f_def (*‹f ≡ λz u. complex_of_real (- ln u) powr z / complex_of_real (1 - u) * complex_of_real (- ln u + u - 1)›*) set_borel_measurable_def (*‹set_borel_measurable ?M ?A ?f ≡ (λx. indicat_real ?A x *⇩R ?f x) ∈ borel_measurable ?M›*))[1]) (*proven 3 subgoals*) . qed lemma integral_holo_aux: assumes ab: "a > 0" "a ≤ b" "b < 1" shows "(λz. LBINT u=ereal a..ereal b. f z u) holomorphic_on A" proof (-) (*goal: ‹(λz. complex_interval_lebesgue_integral lborel (ereal a) (ereal b) (f z)) holomorphic_on A›*) define f' :: "complex ⇒ real ⇒ complex" where "f' ≡ (λz u. ln (-ln u) * f z u)" note [derivative_intros] = has_field_derivative_complex_powr_right' (*‹⟦(?w::complex) ≠ (0::complex); ((?g::complex ⇒ complex) has_field_derivative (?Db::complex)) (at (?x::complex) within (?s::complex set))⟧ ⟹ ((λx::complex. ?w powr ?g x) has_field_derivative Ln ?w * ?w powr ?g ?x * ?Db) (at ?x within ?s)›*) have "(λz. integral (cbox a b) (f z)) holomorphic_on UNIV" proof (rule leibniz_rule_holomorphic[of _ _ _ _ f'] (*‹⟦⋀(x::complex) t::real. ⟦x ∈ (?U::complex set); t ∈ cbox (?a::real) (?b::real)⟧ ⟹ ((λx::complex. (?f::complex ⇒ real ⇒ complex) x t) has_field_derivative (f'::complex ⇒ real ⇒ complex) x t) (at x within ?U); ⋀x::complex. x ∈ ?U ⟹ ?f x integrable_on cbox ?a ?b; continuous_on (?U × cbox ?a ?b) (λ(x::complex, t::real). f' x t); convex ?U⟧ ⟹ (λx::complex. integral (cbox ?a ?b) (?f x)) holomorphic_on ?U›*), goal_cases) (*goals: 1. ‹⋀z t. ⟦z ∈ UNIV; t ∈ cbox a b⟧ ⟹ ((λz. f z t) has_field_derivative f' z t) (at z)› 2. ‹⋀z. z ∈ UNIV ⟹ f z integrable_on cbox a b› 3. ‹continuous_on (UNIV × cbox a b) (λ(z, t). f' z t)› 4. ‹convex UNIV›*) case (1 z t) (*‹z ∈ UNIV› ‹(t::real) ∈ cbox (a::real) (b::real)›*) show "?case" (*goal: ‹((λz. f z t) has_field_derivative f' z t) (at z)›*) unfolding f_def (*goal: ‹((λz. complex_of_real (- ln t) powr z / complex_of_real (1 - t) * complex_of_real (- ln t + t - 1)) has_field_derivative f' z t) (at z)›*) apply (insert 1 (*‹(z::complex) ∈ UNIV› ‹(t::real) ∈ cbox (a::real) (b::real)›*) ab (*‹(0::real) < (a::real)› ‹(a::real) ≤ (b::real)› ‹(b::real) < (1::real)›*)) (*goal: ‹((λz. complex_of_real (- ln t) powr z / complex_of_real (1 - t) * complex_of_real (- ln t + t - 1)) has_field_derivative f' z t) (at z)›*) apply (rule derivative_eq_intros (*‹(λx. x) = ?g' ⟹ ((λx. x) has_derivative ?g') ?F› ‹id = ?g' ⟹ (id has_derivative ?g') ?F› ‹(λx. 0) = ?g' ⟹ ((λx. ?f2) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?r1 *⇩R ?g'1 x) = ?g'⟧ ⟹ ((λx. ?r1 *⇩R ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x *⇩R ?x1) = ?g'⟧ ⟹ ((λx. ?g1 x *⇩R ?x1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?x1 * ?g'1 x) = ?g'⟧ ⟹ ((λx. ?x1 * ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x * ?y1) = ?g'⟧ ⟹ ((λx. ?g1 x * ?y1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. of_real (?g'1 x)) = ?g'⟧ ⟹ ((λx. of_real (?g1 x)) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x + ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x + ?g1 x) has_derivative ?g') ?F› ‹⟦⋀i. i ∈ ?I1 ⟹ (?f1 i has_derivative ?f'1 i) ?F; (λx. ∑i∈?I1. ?f'1 i x) = ?g'⟧ ⟹ ((λx. ∑i∈?I1. ?f1 i x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (λx. - ?f'1 x) = ?g'⟧ ⟹ ((λx. - ?f1 x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x - ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x - ?g1 x) has_derivative ?g') ?F› and more 141 facts*) refl (*‹?t = ?t›*)) (*goals: 1. ‹⟦z ∈ UNIV; t ∈ cbox a b; 0 < a; a ≤ b; b < 1⟧ ⟹ ((λx. complex_of_real (- ln t) powr x / complex_of_real (1 - t)) has_field_derivative ?Da6) (at z)› 2. ‹⟦z ∈ UNIV; t ∈ cbox a b; 0 < a; a ≤ b; b < 1⟧ ⟹ ((λx. complex_of_real (- ln t + t - 1)) has_field_derivative ?Db6) (at z)› 3. ‹⟦z ∈ UNIV; t ∈ cbox a b; 0 < a; a ≤ b; b < 1⟧ ⟹ ?Da6 * complex_of_real (- ln t + t - 1) + ?Db6 * (complex_of_real (- ln t) powr z / complex_of_real (1 - t)) = f' z t› discuss goal 1*) apply (rule derivative_eq_intros (*‹(λx::?'b. x) = (?g'::?'b ⇒ ?'b) ⟹ ((λx::?'b. x) has_derivative ?g') (?F::?'b filter)› ‹id = (?g'::?'b ⇒ ?'b) ⟹ (id has_derivative ?g') (?F::?'b filter)› ‹(λx::?'a. 0::?'b) = (?g'::?'a ⇒ ?'b) ⟹ ((λx::?'a. ?f2::?'b) has_derivative ?g') (?F::?'a filter)› ‹⟦((?g1::?'a ⇒ ?'b) has_derivative (?g'1::?'a ⇒ ?'b)) (?F::?'a filter); (λx::?'a. (?r1::real) *⇩R ?g'1 x) = (?g'::?'a ⇒ ?'b)⟧ ⟹ ((λx::?'a. ?r1 *⇩R ?g1 x) has_derivative ?g') ?F› ‹⟦((?g1::?'a ⇒ real) has_derivative (?g'1::?'a ⇒ real)) (?F::?'a filter); (λx::?'a. ?g'1 x *⇩R (?x1::?'b)) = (?g'::?'a ⇒ ?'b)⟧ ⟹ ((λx::?'a. ?g1 x *⇩R ?x1) has_derivative ?g') ?F› ‹⟦((?g1::?'a ⇒ ?'a1) has_derivative (?g'1::?'a ⇒ ?'a1)) (?F::?'a filter); (λx::?'a. (?x1::?'a1) * ?g'1 x) = (?g'::?'a ⇒ ?'a1)⟧ ⟹ ((λx::?'a. ?x1 * ?g1 x) has_derivative ?g') ?F› ‹⟦((?g1::?'a ⇒ ?'a1) has_derivative (?g'1::?'a ⇒ ?'a1)) (?F::?'a filter); (λx::?'a. ?g'1 x * (?y1::?'a1)) = (?g'::?'a ⇒ ?'a1)⟧ ⟹ ((λx::?'a. ?g1 x * ?y1) has_derivative ?g') ?F› ‹⟦((?g1::?'a ⇒ real) has_derivative (?g'1::?'a ⇒ real)) (?F::?'a filter); (λx::?'a. of_real (?g'1 x)) = (?g'::?'a ⇒ ?'a1)⟧ ⟹ ((λx::?'a. of_real (?g1 x)) has_derivative ?g') ?F› ‹⟦((?f1::?'a ⇒ ?'b) has_derivative (?f'1::?'a ⇒ ?'b)) (?F::?'a filter); ((?g1::?'a ⇒ ?'b) has_derivative (?g'1::?'a ⇒ ?'b)) ?F; (λx::?'a. ?f'1 x + ?g'1 x) = (?g'::?'a ⇒ ?'b)⟧ ⟹ ((λx::?'a. ?f1 x + ?g1 x) has_derivative ?g') ?F› ‹⟦⋀i::?'a1. i ∈ (?I1::?'a1 set) ⟹ ((?f1::?'a1 ⇒ ?'a ⇒ ?'b) i has_derivative (?f'1::?'a1 ⇒ ?'a ⇒ ?'b) i) (?F::?'a filter); (λx::?'a. ∑i::?'a1∈?I1. ?f'1 i x) = (?g'::?'a ⇒ ?'b)⟧ ⟹ ((λx::?'a. ∑i::?'a1∈?I1. ?f1 i x) has_derivative ?g') ?F› ‹⟦((?f1::?'a ⇒ ?'b) has_derivative (?f'1::?'a ⇒ ?'b)) (?F::?'a filter); (λx::?'a. - ?f'1 x) = (?g'::?'a ⇒ ?'b)⟧ ⟹ ((λx::?'a. - ?f1 x) has_derivative ?g') ?F› ‹⟦((?f1::?'a ⇒ ?'b) has_derivative (?f'1::?'a ⇒ ?'b)) (?F::?'a filter); ((?g1::?'a ⇒ ?'b) has_derivative (?g'1::?'a ⇒ ?'b)) ?F; (λx::?'a. ?f'1 x - ?g'1 x) = (?g'::?'a ⇒ ?'b)⟧ ⟹ ((λx::?'a. ?f1 x - ?g1 x) has_derivative ?g') ?F› and more 141 facts*) refl (*‹(?t::?'a) = ?t›*)) (*goals: 1. ‹⟦z ∈ UNIV; t ∈ cbox a b; 0 < a; a ≤ b; b < 1⟧ ⟹ ((powr) (complex_of_real (- ln t)) has_field_derivative ?D11) (at z)› 2. ‹⟦z ∈ UNIV; t ∈ cbox a b; 0 < a; a ≤ b; b < 1⟧ ⟹ ((λx. complex_of_real (1 - t)) has_field_derivative ?E11) (at z)› 3. ‹⟦z ∈ UNIV; t ∈ cbox a b; 0 < a; a ≤ b; b < 1⟧ ⟹ complex_of_real (1 - t) ≠ 0› 4. ‹⟦z ∈ UNIV; t ∈ cbox a b; 0 < a; a ≤ b; b < 1⟧ ⟹ (?D11 * complex_of_real (1 - t) - complex_of_real (- ln t) powr z * ?E11) / (complex_of_real (1 - t) * complex_of_real (1 - t)) = ?Da6› discuss goal 1*) apply (rule derivative_eq_intros (*‹(λx. x) = ?g' ⟹ ((λx. x) has_derivative ?g') ?F› ‹id = ?g' ⟹ (id has_derivative ?g') ?F› ‹(λx. 0) = ?g' ⟹ ((λx. ?f2) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?r1 *⇩R ?g'1 x) = ?g'⟧ ⟹ ((λx. ?r1 *⇩R ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x *⇩R ?x1) = ?g'⟧ ⟹ ((λx. ?g1 x *⇩R ?x1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?x1 * ?g'1 x) = ?g'⟧ ⟹ ((λx. ?x1 * ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x * ?y1) = ?g'⟧ ⟹ ((λx. ?g1 x * ?y1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. of_real (?g'1 x)) = ?g'⟧ ⟹ ((λx. of_real (?g1 x)) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x + ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x + ?g1 x) has_derivative ?g') ?F› ‹⟦⋀i. i ∈ ?I1 ⟹ (?f1 i has_derivative ?f'1 i) ?F; (λx. ∑i∈?I1. ?f'1 i x) = ?g'⟧ ⟹ ((λx. ∑i∈?I1. ?f1 i x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (λx. - ?f'1 x) = ?g'⟧ ⟹ ((λx. - ?f1 x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x - ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x - ?g1 x) has_derivative ?g') ?F› and more 141 facts*) refl (*‹?t = ?t›*)) (*goals: 1. ‹⟦(z::complex) ∈ UNIV; (t::real) ∈ cbox (a::real) (b::real); (0::real) < a; a ≤ b; b < (1::real)⟧ ⟹ complex_of_real (- ln t) ≠ (0::complex)› 2. ‹⟦(z::complex) ∈ UNIV; (t::real) ∈ cbox (a::real) (b::real); (0::real) < a; a ≤ b; b < (1::real)⟧ ⟹ Ln (complex_of_real (- ln t)) * complex_of_real (- ln t) powr z = (?D11::complex)› discuss goal 1*) apply simp (*discuss goal 2*) apply (rule derivative_eq_intros (*‹(λx. x) = ?g' ⟹ ((λx. x) has_derivative ?g') ?F› ‹id = ?g' ⟹ (id has_derivative ?g') ?F› ‹(λx. 0) = ?g' ⟹ ((λx. ?f2) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?r1 *⇩R ?g'1 x) = ?g'⟧ ⟹ ((λx. ?r1 *⇩R ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x *⇩R ?x1) = ?g'⟧ ⟹ ((λx. ?g1 x *⇩R ?x1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?x1 * ?g'1 x) = ?g'⟧ ⟹ ((λx. ?x1 * ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x * ?y1) = ?g'⟧ ⟹ ((λx. ?g1 x * ?y1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. of_real (?g'1 x)) = ?g'⟧ ⟹ ((λx. of_real (?g1 x)) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x + ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x + ?g1 x) has_derivative ?g') ?F› ‹⟦⋀i. i ∈ ?I1 ⟹ (?f1 i has_derivative ?f'1 i) ?F; (λx. ∑i∈?I1. ?f'1 i x) = ?g'⟧ ⟹ ((λx. ∑i∈?I1. ?f1 i x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (λx. - ?f'1 x) = ?g'⟧ ⟹ ((λx. - ?f1 x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x - ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x - ?g1 x) has_derivative ?g') ?F› and more 141 facts*) refl (*‹?t = ?t›*)) (*proven 2 subgoals*) (*discuss goal 2*) apply (rule derivative_eq_intros (*‹(λx. x) = ?g' ⟹ ((λx. x) has_derivative ?g') ?F› ‹id = ?g' ⟹ (id has_derivative ?g') ?F› ‹(λx. 0) = ?g' ⟹ ((λx. ?f2) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?r1 *⇩R ?g'1 x) = ?g'⟧ ⟹ ((λx. ?r1 *⇩R ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x *⇩R ?x1) = ?g'⟧ ⟹ ((λx. ?g1 x *⇩R ?x1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?x1 * ?g'1 x) = ?g'⟧ ⟹ ((λx. ?x1 * ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x * ?y1) = ?g'⟧ ⟹ ((λx. ?g1 x * ?y1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. of_real (?g'1 x)) = ?g'⟧ ⟹ ((λx. of_real (?g1 x)) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x + ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x + ?g1 x) has_derivative ?g') ?F› ‹⟦⋀i. i ∈ ?I1 ⟹ (?f1 i has_derivative ?f'1 i) ?F; (λx. ∑i∈?I1. ?f'1 i x) = ?g'⟧ ⟹ ((λx. ∑i∈?I1. ?f1 i x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (λx. - ?f'1 x) = ?g'⟧ ⟹ ((λx. - ?f1 x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x - ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x - ?g1 x) has_derivative ?g') ?F› and more 141 facts*) refl (*‹?t = ?t›*)) (*top goal: ‹⟦z ∈ UNIV; t ∈ cbox a b; 0 < a; a ≤ b; b < 1⟧ ⟹ ((λx. complex_of_real (1 - t)) has_field_derivative ?E11) (at z)› and 4 goals remain*) apply (rule derivative_eq_intros (*‹(λx. x) = ?g' ⟹ ((λx. x) has_derivative ?g') ?F› ‹id = ?g' ⟹ (id has_derivative ?g') ?F› ‹(λx. 0) = ?g' ⟹ ((λx. ?f2) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?r1 *⇩R ?g'1 x) = ?g'⟧ ⟹ ((λx. ?r1 *⇩R ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x *⇩R ?x1) = ?g'⟧ ⟹ ((λx. ?g1 x *⇩R ?x1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?x1 * ?g'1 x) = ?g'⟧ ⟹ ((λx. ?x1 * ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x * ?y1) = ?g'⟧ ⟹ ((λx. ?g1 x * ?y1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. of_real (?g'1 x)) = ?g'⟧ ⟹ ((λx. of_real (?g1 x)) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x + ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x + ?g1 x) has_derivative ?g') ?F› ‹⟦⋀i. i ∈ ?I1 ⟹ (?f1 i has_derivative ?f'1 i) ?F; (λx. ∑i∈?I1. ?f'1 i x) = ?g'⟧ ⟹ ((λx. ∑i∈?I1. ?f1 i x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (λx. - ?f'1 x) = ?g'⟧ ⟹ ((λx. - ?f1 x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x - ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x - ?g1 x) has_derivative ?g') ?F› and more 141 facts*) refl (*‹?t = ?t›*)) (*discuss goal 3*) apply simp (*discuss goal 4*) apply (rule derivative_eq_intros (*‹(λx. x) = ?g' ⟹ ((λx. x) has_derivative ?g') ?F› ‹id = ?g' ⟹ (id has_derivative ?g') ?F› ‹(λx. 0) = ?g' ⟹ ((λx. ?f2) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?r1 *⇩R ?g'1 x) = ?g'⟧ ⟹ ((λx. ?r1 *⇩R ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x *⇩R ?x1) = ?g'⟧ ⟹ ((λx. ?g1 x *⇩R ?x1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?x1 * ?g'1 x) = ?g'⟧ ⟹ ((λx. ?x1 * ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x * ?y1) = ?g'⟧ ⟹ ((λx. ?g1 x * ?y1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. of_real (?g'1 x)) = ?g'⟧ ⟹ ((λx. of_real (?g1 x)) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x + ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x + ?g1 x) has_derivative ?g') ?F› ‹⟦⋀i. i ∈ ?I1 ⟹ (?f1 i has_derivative ?f'1 i) ?F; (λx. ∑i∈?I1. ?f'1 i x) = ?g'⟧ ⟹ ((λx. ∑i∈?I1. ?f1 i x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (λx. - ?f'1 x) = ?g'⟧ ⟹ ((λx. - ?f1 x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x - ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x - ?g1 x) has_derivative ?g') ?F› and more 141 facts*) refl (*‹?t = ?t›*)) (*proven 4 subgoals*) (*discuss goal 2*) apply (rule derivative_eq_intros (*‹(λx. x) = ?g' ⟹ ((λx. x) has_derivative ?g') ?F› ‹id = ?g' ⟹ (id has_derivative ?g') ?F› ‹(λx. 0) = ?g' ⟹ ((λx. ?f2) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?r1 *⇩R ?g'1 x) = ?g'⟧ ⟹ ((λx. ?r1 *⇩R ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x *⇩R ?x1) = ?g'⟧ ⟹ ((λx. ?g1 x *⇩R ?x1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?x1 * ?g'1 x) = ?g'⟧ ⟹ ((λx. ?x1 * ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x * ?y1) = ?g'⟧ ⟹ ((λx. ?g1 x * ?y1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. of_real (?g'1 x)) = ?g'⟧ ⟹ ((λx. of_real (?g1 x)) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x + ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x + ?g1 x) has_derivative ?g') ?F› ‹⟦⋀i. i ∈ ?I1 ⟹ (?f1 i has_derivative ?f'1 i) ?F; (λx. ∑i∈?I1. ?f'1 i x) = ?g'⟧ ⟹ ((λx. ∑i∈?I1. ?f1 i x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (λx. - ?f'1 x) = ?g'⟧ ⟹ ((λx. - ?f1 x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x - ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x - ?g1 x) has_derivative ?g') ?F› and more 141 facts*) refl (*‹?t = ?t›*)) (*top goal: ‹⟦z ∈ UNIV; t ∈ cbox a b; 0 < a; a ≤ b; b < 1⟧ ⟹ ((λx. complex_of_real (- ln t + t - 1)) has_field_derivative ?Db6) (at z)› and 1 goal remains*) apply (rule derivative_eq_intros (*‹(λx. x) = ?g' ⟹ ((λx. x) has_derivative ?g') ?F› ‹id = ?g' ⟹ (id has_derivative ?g') ?F› ‹(λx. 0) = ?g' ⟹ ((λx. ?f2) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?r1 *⇩R ?g'1 x) = ?g'⟧ ⟹ ((λx. ?r1 *⇩R ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x *⇩R ?x1) = ?g'⟧ ⟹ ((λx. ?g1 x *⇩R ?x1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?x1 * ?g'1 x) = ?g'⟧ ⟹ ((λx. ?x1 * ?g1 x) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. ?g'1 x * ?y1) = ?g'⟧ ⟹ ((λx. ?g1 x * ?y1) has_derivative ?g') ?F› ‹⟦(?g1 has_derivative ?g'1) ?F; (λx. of_real (?g'1 x)) = ?g'⟧ ⟹ ((λx. of_real (?g1 x)) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x + ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x + ?g1 x) has_derivative ?g') ?F› ‹⟦⋀i. i ∈ ?I1 ⟹ (?f1 i has_derivative ?f'1 i) ?F; (λx. ∑i∈?I1. ?f'1 i x) = ?g'⟧ ⟹ ((λx. ∑i∈?I1. ?f1 i x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (λx. - ?f'1 x) = ?g'⟧ ⟹ ((λx. - ?f1 x) has_derivative ?g') ?F› ‹⟦(?f1 has_derivative ?f'1) ?F; (?g1 has_derivative ?g'1) ?F; (λx. ?f'1 x - ?g'1 x) = ?g'⟧ ⟹ ((λx. ?f1 x - ?g1 x) has_derivative ?g') ?F› and more 141 facts*) refl (*‹?t = ?t›*)) (*discuss goal 3*) apply simp (*goal: ‹⟦z ∈ UNIV; t ∈ cbox a b; 0 < a; a ≤ b; b < 1⟧ ⟹ (Ln (complex_of_real (- ln t)) * complex_of_real (- ln t) powr z * complex_of_real (1 - t) - complex_of_real (- ln t) powr z * 0) / (complex_of_real (1 - t) * complex_of_real (1 - t)) * complex_of_real (- ln t + t - 1) + 0 * (complex_of_real (- ln t) powr z / complex_of_real (1 - t)) = f' z t›*) apply (auto simp: f'_def (*‹f' ≡ λz u. Ln (- Ln (complex_of_real u)) * f z u›*) field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 77 facts*) f_def (*‹f ≡ λz u. complex_of_real (- ln u) powr z / complex_of_real (1 - u) * complex_of_real (- ln u + u - 1)›*) Ln_of_real (*‹0 < ?z ⟹ Ln (complex_of_real ?z) = complex_of_real (ln ?z)›*)) (*proven 3 subgoals*) . next (*goals: 1. ‹⋀z. z ∈ UNIV ⟹ f z integrable_on cbox a b› 2. ‹continuous_on (UNIV × cbox a b) (λ(z, t). f' z t)› 3. ‹convex UNIV›*) from ab (*‹0 < a› ‹a ≤ b› ‹(b::real) < (1::real)›*) show "continuous_on (UNIV × cbox a b) (λ(z, t). f' z t)" by (auto simp: case_prod_unfold (*‹case_prod = (λ(c::?'a::type ⇒ ?'b::type ⇒ ?'c::type) p::?'a::type × ?'b::type. c (fst p) (snd p))›*) f'_def (*‹f'::complex ⇒ real ⇒ complex ≡ λ(z::complex) u::real. Ln (- Ln (complex_of_real u)) * (f::complex ⇒ real ⇒ complex) z u›*) f_def (*‹f::complex ⇒ real ⇒ complex ≡ λ(z::complex) u::real. complex_of_real (- ln u) powr z / complex_of_real ((1::real) - u) * complex_of_real (- ln u + u - (1::real))›*) Ln_of_real (*‹(0::real) < (?z::real) ⟹ Ln (complex_of_real ?z) = complex_of_real (ln ?z)›*) intro!: continuous_intros (*‹open {}› ‹⟦open (?S::?'a::topological_space set); open (?T::?'a::topological_space set)⟧ ⟹ open (?S ∪ ?T)› ‹∀x::?'b::type∈?A::?'b::type set. open ((?B::?'b::type ⇒ ?'a::topological_space set) x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite (?S::?'a::topological_space set set); ∀T::?'a::topological_space set∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite (?A::?'b::type set); ∀x::?'b::type∈?A. open ((?B::?'b::type ⇒ ?'a::topological_space set) x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed (?S::?'a::topological_space set); closed (?T::?'a::topological_space set)⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed (?S::?'a::topological_space set); closed (?T::?'a::topological_space set)⟧ ⟹ closed (?S ∩ ?T)› ‹∀x::?'b::type∈?A::?'b::type set. closed ((?B::?'b::type ⇒ ?'a::topological_space set) x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S::?'a::topological_space set∈?K::?'a::topological_space set set. closed S ⟹ closed (⋂ ?K)› ‹⟦finite (?S::?'a::topological_space set set); ∀T::?'a::topological_space set∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 286 facts*)) next (*goals: 1. ‹⋀z::complex. z ∈ UNIV ⟹ (f::complex ⇒ real ⇒ complex) z integrable_on cbox (a::real) (b::real)› 2. ‹convex UNIV›*) fix z :: complex show "f z integrable_on cbox a b" unfolding f_def f'_def (*goal: ‹(λu::real. complex_of_real (- ln u) powr (z::complex) / complex_of_real ((1::real) - u) * complex_of_real (- ln u + u - (1::real))) integrable_on cbox (a::real) (b::real)›*) using ab (*‹0 < a› ‹a ≤ b› ‹b < 1›*) apply (intro integrable_continuous (*‹continuous_on (cbox ?a ?b) ?f ⟹ ?f integrable_on cbox ?a ?b›*) continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 286 facts*)) (*goals: 1. ‹⟦0 < a; a ≤ b; b < 1⟧ ⟹ cbox a b ⊆ {x. 0 ≤ Re (complex_of_real (- ln x)) ∨ Im (complex_of_real (- ln x)) ≠ 0}› 2. ‹⋀x. ⟦0 < a; a ≤ b; b < 1; x ∈ cbox a b; complex_of_real (- ln x) = 0⟧ ⟹ 0 < Re z› 3. ‹⟦0 < a; a ≤ b; b < 1⟧ ⟹ ∀x∈cbox a b. x ≠ 0› 4. ‹⟦0 < a; a ≤ b; b < 1⟧ ⟹ ∀x∈cbox a b. complex_of_real (1 - x) ≠ 0› 5. ‹⟦0 < a; a ≤ b; b < 1⟧ ⟹ ∀x∈cbox a b. x ≠ 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . qed (auto simp: convex_halfspace_Re_gt (*‹convex {x. ?b < Re x}›*)) (*solved the remaining goal: ‹convex UNIV›*) also (*calculation: ‹(λz. integral (cbox a b) (f z)) holomorphic_on UNIV›*) have "(λz. integral (cbox a b) (f z)) = (λz. ∫u∈cbox a b. f z u ∂lborel)" proof (intro ext (*‹(⋀x::?'a. (?f::?'a ⇒ ?'b) x = (?g::?'a ⇒ ?'b) x) ⟹ ?f = ?g›*) set_borel_integral_eq_integral(2) [symmetric] (*‹set_integrable lborel (?S::?'a set) (?f::?'a ⇒ ?'b) ⟹ integral ?S ?f = set_lebesgue_integral lborel ?S ?f›*)) (*goal: ‹⋀z. complex_set_integrable lborel (cbox a b) (f z)›*) fix z :: complex show "complex_set_integrable lborel (cbox a b) (f z)" unfolding f_def (*goal: ‹complex_set_integrable lborel (cbox (a::real) (b::real)) (λu::real. complex_of_real (- ln u) powr (z::complex) / complex_of_real ((1::real) - u) * complex_of_real (- ln u + u - (1::real)))›*) using ab (*‹0 < a› ‹(a::real) ≤ (b::real)› ‹b < 1›*) apply (intro continuous_on_imp_set_integrable_cbox (*‹continuous_on (cbox ?a ?b) ?h ⟹ set_integrable lborel (cbox ?a ?b) ?h›*) continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 286 facts*)) (*goals: 1. ‹⟦(0::real) < (a::real); a ≤ (b::real); b < (1::real)⟧ ⟹ cbox a b ⊆ {x::real. (0::real) ≤ Re (complex_of_real (- ln x)) ∨ Im (complex_of_real (- ln x)) ≠ (0::real)}› 2. ‹⋀x::real. ⟦(0::real) < (a::real); a ≤ (b::real); b < (1::real); x ∈ cbox a b; complex_of_real (- ln x) = (0::complex)⟧ ⟹ (0::real) < Re (z::complex)› 3. ‹⟦(0::real) < (a::real); a ≤ (b::real); b < (1::real)⟧ ⟹ ∀x::real∈cbox a b. x ≠ (0::real)› 4. ‹⟦(0::real) < (a::real); a ≤ (b::real); b < (1::real)⟧ ⟹ ∀x::real∈cbox a b. complex_of_real ((1::real) - x) ≠ (0::complex)› 5. ‹⟦(0::real) < (a::real); a ≤ (b::real); b < (1::real)⟧ ⟹ ∀x::real∈cbox a b. x ≠ (0::real)› discuss goal 1*) apply ((auto simp: Ln_of_real (*‹(0::real) < (?z::real) ⟹ Ln (complex_of_real ?z) = complex_of_real (ln ?z)›*))[1]) (*discuss goal 2*) apply ((auto simp: Ln_of_real (*‹0 < ?z ⟹ Ln (complex_of_real ?z) = complex_of_real (ln ?z)›*))[1]) (*discuss goal 3*) apply ((auto simp: Ln_of_real (*‹0 < ?z ⟹ Ln (complex_of_real ?z) = complex_of_real (ln ?z)›*))[1]) (*discuss goal 4*) apply ((auto simp: Ln_of_real (*‹0 < ?z ⟹ Ln (complex_of_real ?z) = complex_of_real (ln ?z)›*))[1]) (*discuss goal 5*) apply ((auto simp: Ln_of_real (*‹(0::real) < (?z::real) ⟹ Ln (complex_of_real ?z) = complex_of_real (ln ?z)›*))[1]) (*proven 5 subgoals*) . qed also (*calculation: ‹(λz. complex_set_lebesgue_integral lborel (cbox a b) (f z)) holomorphic_on UNIV›*) have "… = (λz. LBINT u=a..b. f z u)" using ab (*‹0 < a› ‹a ≤ b› ‹b < 1›*) by (simp add: interval_integral_Icc (*‹?a ≤ ?b ⟹ interval_lebesgue_integral lborel (ereal ?a) (ereal ?b) ?f = set_lebesgue_integral lborel {?a..?b} ?f›*)) finally (*calculation: ‹(λz::complex. complex_interval_lebesgue_integral lborel (ereal (a::real)) (ereal (b::real)) ((f::complex ⇒ real ⇒ complex) z)) holomorphic_on UNIV›*) show "?thesis" (*goal: ‹(λz. complex_interval_lebesgue_integral lborel (ereal a) (ereal b) (f z)) holomorphic_on A›*) apply (rule holomorphic_on_subset (*‹⟦?f holomorphic_on ?s; ?t ⊆ ?s⟧ ⟹ ?f holomorphic_on ?t›*)) (*goal: ‹(λz. complex_interval_lebesgue_integral lborel (ereal a) (ereal b) (f z)) holomorphic_on A›*) by auto qed lemma integral_holo: assumes ab: "min a b > 0" "max a b < 1" shows "(λz. LBINT u=ereal a..ereal b. f z u) holomorphic_on A" proof (cases "a ≤ b") (*goals: 1. ‹a ≤ b ⟹ (λz. complex_interval_lebesgue_integral lborel (ereal a) (ereal b) (f z)) holomorphic_on A› 2. ‹¬ a ≤ b ⟹ (λz. complex_interval_lebesgue_integral lborel (ereal a) (ereal b) (f z)) holomorphic_on A›*) case True (*‹a ≤ b›*) thus "?thesis" (*goal: ‹(λz. complex_interval_lebesgue_integral lborel (ereal a) (ereal b) (f z)) holomorphic_on A›*) using assms (*‹0 < min a b› ‹max a b < 1›*) integral_holo_aux[of a b] (*‹⟦0 < a; a ≤ b; b < 1⟧ ⟹ (λz. complex_interval_lebesgue_integral lborel (ereal a) (ereal b) (f z)) holomorphic_on ?A›*) by auto next (*goal: ‹¬ (a::real) ≤ (b::real) ⟹ (λz::complex. complex_interval_lebesgue_integral lborel (ereal a) (ereal b) ((f::complex ⇒ real ⇒ complex) z)) holomorphic_on (A::complex set)›*) case False (*‹¬ a ≤ b›*) have "(λz. -(LBINT u=ereal b..ereal a. f z u)) holomorphic_on A" using False (*‹¬ a ≤ b›*) assms (*‹0 < min a b› ‹max a b < 1›*) apply (intro holomorphic_intros (*‹?f holomorphic_on {}› ‹(*) ?c holomorphic_on ?s› ‹(λz. ?c) holomorphic_on ?s› ‹(λx. x) holomorphic_on ?s› ‹id holomorphic_on ?s› ‹?f holomorphic_on ?A ⟹ (λz. - ?f z) holomorphic_on ?A› ‹⟦?f holomorphic_on ?A; ?g holomorphic_on ?A⟧ ⟹ (λz. ?f z + ?g z) holomorphic_on ?A› ‹⟦?f holomorphic_on ?A; ?g holomorphic_on ?A⟧ ⟹ (λz. ?f z - ?g z) holomorphic_on ?A› ‹⟦?f holomorphic_on ?A; ?g holomorphic_on ?A⟧ ⟹ (λz. ?f z * ?g z) holomorphic_on ?A› ‹⟦?f holomorphic_on ?A; ⋀z. z ∈ ?A ⟹ ?f z ≠ 0⟧ ⟹ (λz. inverse (?f z)) holomorphic_on ?A› ‹⟦?f holomorphic_on ?A; ?g holomorphic_on ?A; ⋀z. z ∈ ?A ⟹ ?g z ≠ 0⟧ ⟹ (λz. ?f z / ?g z) holomorphic_on ?A› ‹?f holomorphic_on ?A ⟹ (λz. ?f z ^ ?n) holomorphic_on ?A› and more 35 facts*) integral_holo_aux (*‹⟦0 < ?a; ?a ≤ ?b; ?b < 1⟧ ⟹ (λz. complex_interval_lebesgue_integral lborel (ereal ?a) (ereal ?b) (f z)) holomorphic_on ?A›*)) (*goals: 1. ‹⟦¬ a ≤ b; 0 < min a b; max a b < 1⟧ ⟹ 0 < b› 2. ‹⟦¬ a ≤ b; 0 < min a b; max a b < 1⟧ ⟹ b ≤ a› 3. ‹⟦¬ a ≤ b; 0 < min a b; max a b < 1⟧ ⟹ a < 1› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . thus "?thesis" (*goal: ‹(λz. complex_interval_lebesgue_integral lborel (ereal a) (ereal b) (f z)) holomorphic_on A›*) by (subst interval_integral_endpoints_reverse (*‹interval_lebesgue_integral lborel ?a ?b ?f = - interval_lebesgue_integral lborel ?b ?a ?f›*)) qed lemma holo1: "(λz. LBINT u=0..exp (-1). f z u) holomorphic_on {z. Re z > -2}" proof (rule holomorphic_uniform_sequence [where f = "(λn z. LBINT u=ereal ((1/2)^Suc n)..exp (-1). f z u)"] (*‹⟦open ?S; ⋀n. (λz. complex_interval_lebesgue_integral lborel (ereal ((1 / 2) ^ Suc n)) (ereal (exp (- 1))) (f z)) holomorphic_on ?S; ⋀x. x ∈ ?S ⟹ ∃d>0. cball x d ⊆ ?S ∧ uniform_limit (cball x d) (λn z. complex_interval_lebesgue_integral lborel (ereal ((1 / 2) ^ Suc n)) (ereal (exp (- 1))) (f z)) ?g sequentially⟧ ⟹ ?g holomorphic_on ?S›*), goal_cases) (*goals: 1. ‹open {z. - 2 < Re z}› 2. ‹⋀n. (λz. complex_interval_lebesgue_integral lborel (ereal ((1 / 2) ^ Suc n)) (ereal (exp (- 1))) (f z)) holomorphic_on {z. - 2 < Re z}› 3. ‹⋀x. x ∈ {z. - 2 < Re z} ⟹ ∃d>0. cball x d ⊆ {z. - 2 < Re z} ∧ uniform_limit (cball x d) (λn z. complex_interval_lebesgue_integral lborel (ereal ((1 / 2) ^ Suc n)) (ereal (exp (- 1))) (f z)) (λz. complex_interval_lebesgue_integral lborel 0 (ereal (exp (- 1))) (f z)) sequentially›*) case (3 z) (*‹(z::complex) ∈ {z::complex. - (2::real) < Re z}›*) define ε where "ε = (Re z + 2) / 2" from "3" (*‹z ∈ {z. - 2 < Re z}›*) have "ε > 0" by (auto simp: ε_def (*‹(ε::real) = (Re (z::complex) + (2::real)) / (2::real)›*)) have subset: "cball z ε ⊆ {s. Re s ∈ {Re z - ε..Re z + ε}}" proof (safe) (*goal: ‹⋀x. x ∈ cball z ε ⟹ Re x ∈ {Re z - ε..Re z + ε}›*) fix s assume s: "s ∈ cball z ε" (*‹(s::complex) ∈ cball (z::complex) (ε::real)›*) have "¦Re (s - z)¦ ≤ norm (s - z)" by (rule abs_Re_le_cmod (*‹¦Re ?x¦ ≤ cmod ?x›*)) also (*calculation: ‹¦Re (s - z)¦ ≤ cmod (s - z)›*) have "… ≤ ε" using s (*‹(s::complex) ∈ cball (z::complex) (ε::real)›*) by (simp add: dist_norm (*‹dist ?x ?y = norm (?x - ?y)›*) norm_minus_commute (*‹norm (?a - ?b) = norm (?b - ?a)›*)) finally (*calculation: ‹¦Re (s - z)¦ ≤ ε›*) show "Re s ∈ {Re z - ε..Re z + ε}" by auto qed show "?case" (*goal: ‹∃d>0. cball z d ⊆ {z. - 2 < Re z} ∧ uniform_limit (cball z d) (λn z. complex_interval_lebesgue_integral lborel (ereal ((1 / 2) ^ Suc n)) (ereal (exp (- 1))) (f z)) (λz. complex_interval_lebesgue_integral lborel 0 (ereal (exp (- 1))) (f z)) sequentially›*) proof (rule exI[of _ ε] (*‹?P ε ⟹ ∃x. ?P x›*), intro conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹0 < ε› 2. ‹cball z ε ⊆ {z. - 2 < Re z}› 3. ‹uniform_limit (cball z ε) (λn z. complex_interval_lebesgue_integral lborel (ereal ((1 / 2) ^ Suc n)) (ereal (exp (- 1))) (f z)) (λz. complex_interval_lebesgue_integral lborel 0 (ereal (exp (- 1))) (f z)) sequentially›*) have "cball z ε ⊆ {s. Re s ∈ {Re z - ε..Re z + ε}}" by fact also (*calculation: ‹cball z ε ⊆ {s. Re s ∈ {Re z - ε..Re z + ε}}›*) have "… ⊆ {s. Re s > -2}" using "3" (*‹(z::complex) ∈ {z::complex. - (2::real) < Re z}›*) by (auto simp: ε_def (*‹ε = (Re z + 2) / 2›*) field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 77 facts*)) finally (*calculation: ‹cball z ε ⊆ {s. - 2 < Re s}›*) show "cball z ε ⊆ {s. Re s > -2}" . next (*goals: 1. ‹0 < ε› 2. ‹uniform_limit (cball z ε) (λn z. complex_interval_lebesgue_integral lborel (ereal ((1 / 2) ^ Suc n)) (ereal (exp (- 1))) (f z)) (λz. complex_interval_lebesgue_integral lborel 0 (ereal (exp (- 1))) (f z)) sequentially›*) from "3" (*‹z ∈ {z. - 2 < Re z}›*) have "Re z - ε > -2" by (simp add: ε_def (*‹ε = (Re z + 2) / 2›*) field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 77 facts*)) thus "uniform_limit (cball z ε) (λn z. LBINT u=ereal ((1 / 2) ^ Suc n)..ereal (exp (- 1)). f z u) (λz. LBINT u=0..ereal (exp(-1)). f z u) sequentially" using uniform_limit_on_subset[OF uniform_limit1' subset] (*‹- 2 < Re z - ε ⟹ uniform_limit (cball z ε) (λn z. complex_interval_lebesgue_integral lborel (ereal ((1 / 2) ^ Suc n)) (ereal (exp (- 1))) (f z)) (λz. complex_interval_lebesgue_integral lborel 0 (ereal (exp (- 1))) (f z)) sequentially›*) by simp qed ((fact)+) (*solved the remaining goal: ‹(0::real) < (ε::real)›*) next (*goals: 1. ‹open {z::complex. - (2::real) < Re z}› 2. ‹⋀n::nat. (λz::complex. complex_interval_lebesgue_integral lborel (ereal (((1::real) / (2::real)) ^ Suc n)) (ereal (exp (- (1::real)))) ((f::complex ⇒ real ⇒ complex) z)) holomorphic_on {z::complex. - (2::real) < Re z}›*) fix n :: nat have "(1 / 2) ^ Suc n < (1 / 2 :: real) ^ 0" apply (subst power_strict_decreasing_iff (*‹⟦0 < ?b; ?b < 1⟧ ⟹ (?b ^ ?m < ?b ^ ?n) = (?n < ?m)›*)) (*goals: 1. ‹0 < 1 / 2› 2. ‹1 / 2 < 1› 3. ‹0 < Suc n› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . thus "(λz. LBINT u=ereal ((1 / 2) ^ Suc n)..ereal (exp (- 1)). f z u) holomorphic_on {z. Re z > -2}" apply (intro integral_holo (*‹⟦0 < min ?a ?b; max ?a ?b < 1⟧ ⟹ (λz. complex_interval_lebesgue_integral lborel (ereal ?a) (ereal ?b) (f z)) holomorphic_on ?A›*)) (*goals: 1. ‹(1 / 2) ^ Suc n < (1 / 2) ^ 0 ⟹ 0 < min ((1 / 2) ^ Suc n) (exp (- 1))› 2. ‹(1 / 2) ^ Suc n < (1 / 2) ^ 0 ⟹ max ((1 / 2) ^ Suc n) (exp (- 1)) < 1› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed (auto simp: open_halfspace_Re_gt (*‹open {z. ?b < Re z}›*)) (*solved the remaining goal: ‹open {z. - 2 < Re z}›*) lemma holo2: "(λz. LBINT u=exp (-1)..1. f z u) holomorphic_on {z. Re z > -2}" proof (rule holomorphic_uniform_sequence [where f = "(λn z. LBINT u=exp (-1)..ereal (1-(1/2)^Suc n). f z u)"] (*‹⟦open (?S::complex set); ⋀n::nat. (λz::complex. complex_interval_lebesgue_integral lborel (ereal (exp (- (1::real)))) (ereal ((1::real) - ((1::real) / (2::real)) ^ Suc n)) ((f::complex ⇒ real ⇒ complex) z)) holomorphic_on ?S; ⋀x::complex. x ∈ ?S ⟹ ∃d>0::real. cball x d ⊆ ?S ∧ uniform_limit (cball x d) (λ(n::nat) z::complex. complex_interval_lebesgue_integral lborel (ereal (exp (- (1::real)))) (ereal ((1::real) - ((1::real) / (2::real)) ^ Suc n)) (f z)) (?g::complex ⇒ complex) sequentially⟧ ⟹ ?g holomorphic_on ?S›*), goal_cases) (*goals: 1. ‹open {z. - 2 < Re z}› 2. ‹⋀n. (λz. complex_interval_lebesgue_integral lborel (ereal (exp (- 1))) (ereal (1 - (1 / 2) ^ Suc n)) (f z)) holomorphic_on {z. - 2 < Re z}› 3. ‹⋀x. x ∈ {z. - 2 < Re z} ⟹ ∃d>0. cball x d ⊆ {z. - 2 < Re z} ∧ uniform_limit (cball x d) (λn z. complex_interval_lebesgue_integral lborel (ereal (exp (- 1))) (ereal (1 - (1 / 2) ^ Suc n)) (f z)) (λz. complex_interval_lebesgue_integral lborel (ereal (exp (- 1))) 1 (f z)) sequentially›*) case (3 z) (*‹z ∈ {z. - 2 < Re z}›*) define ε where "ε = (Re z + 2) / 2" from "3" (*‹z ∈ {z. - 2 < Re z}›*) have "ε > 0" by (auto simp: ε_def (*‹ε = (Re z + 2) / 2›*)) have subset: "cball z ε ⊆ {s. Re s ∈ {Re z - ε..Re z + ε}}" proof (safe) (*goal: ‹⋀x. x ∈ cball z ε ⟹ Re x ∈ {Re z - ε..Re z + ε}›*) fix s assume s: "s ∈ cball z ε" (*‹(s::complex) ∈ cball (z::complex) (ε::real)›*) have "¦Re (s - z)¦ ≤ norm (s - z)" by (rule abs_Re_le_cmod (*‹¦Re (?x::complex)¦ ≤ cmod ?x›*)) also (*calculation: ‹¦Re (s - z)¦ ≤ cmod (s - z)›*) have "… ≤ ε" using s (*‹s ∈ cball z ε›*) by (simp add: dist_norm (*‹dist ?x ?y = norm (?x - ?y)›*) norm_minus_commute (*‹norm (?a - ?b) = norm (?b - ?a)›*)) finally (*calculation: ‹¦Re (s - z)¦ ≤ ε›*) show "Re s ∈ {Re z - ε..Re z + ε}" by auto qed show "?case" (*goal: ‹∃d>0. cball z d ⊆ {z. - 2 < Re z} ∧ uniform_limit (cball z d) (λn z. complex_interval_lebesgue_integral lborel (ereal (exp (- 1))) (ereal (1 - (1 / 2) ^ Suc n)) (f z)) (λz. complex_interval_lebesgue_integral lborel (ereal (exp (- 1))) 1 (f z)) sequentially›*) proof (rule exI[of _ ε] (*‹(?P::real ⇒ bool) (ε::real) ⟹ ∃x::real. ?P x›*), intro conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*)) (*goals: 1. ‹0 < ε› 2. ‹cball z ε ⊆ {z. - 2 < Re z}› 3. ‹uniform_limit (cball z ε) (λn z. complex_interval_lebesgue_integral lborel (ereal (exp (- 1))) (ereal (1 - (1 / 2) ^ Suc n)) (f z)) (λz. complex_interval_lebesgue_integral lborel (ereal (exp (- 1))) 1 (f z)) sequentially›*) have "cball z ε ⊆ {s. Re s ∈ {Re z - ε..Re z + ε}}" by fact also (*calculation: ‹cball (z::complex) (ε::real) ⊆ {s::complex. Re s ∈ {Re z - ε..Re z + ε}}›*) have "… ⊆ {s. Re s > -2}" using "3" (*‹z ∈ {z. - 2 < Re z}›*) by (auto simp: ε_def (*‹ε = (Re z + 2) / 2›*) field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 77 facts*)) finally (*calculation: ‹cball z ε ⊆ {s. - 2 < Re s}›*) show "cball z ε ⊆ {s. Re s > -2}" . next (*goals: 1. ‹0 < ε› 2. ‹uniform_limit (cball z ε) (λn z. complex_interval_lebesgue_integral lborel (ereal (exp (- 1))) (ereal (1 - (1 / 2) ^ Suc n)) (f z)) (λz. complex_interval_lebesgue_integral lborel (ereal (exp (- 1))) 1 (f z)) sequentially›*) from "3" (*‹(z::complex) ∈ {z::complex. - (2::real) < Re z}›*) have "Re z - ε > -2" by (simp add: ε_def (*‹ε = (Re z + 2) / 2›*) field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 77 facts*)) thus "uniform_limit (cball z ε) (λn z. LBINT u=ereal (exp (- 1))..ereal (1-(1/2)^Suc n). f z u) (λz. LBINT u=ereal (exp(-1))..1. f z u) sequentially" using uniform_limit_on_subset[OF uniform_limit2' subset] (*‹- 2 < Re z - ε ⟹ uniform_limit (cball z ε) (λn z. complex_interval_lebesgue_integral lborel (ereal (exp (- 1))) (ereal (1 - (1 / 2) ^ Suc n)) (f z)) (λz. complex_interval_lebesgue_integral lborel (ereal (exp (- 1))) 1 (f z)) sequentially›*) by simp qed ((fact)+) (*solved the remaining goal: ‹0 < ε›*) next (*goals: 1. ‹open {z. - 2 < Re z}› 2. ‹⋀n. (λz. complex_interval_lebesgue_integral lborel (ereal (exp (- 1))) (ereal (1 - (1 / 2) ^ Suc n)) (f z)) holomorphic_on {z. - 2 < Re z}›*) fix n :: nat have "(1 / 2) ^ Suc n < (1 / 2 :: real) ^ 0" apply (subst power_strict_decreasing_iff (*‹⟦(0::?'a::linordered_semidom) < (?b::?'a::linordered_semidom); ?b < (1::?'a::linordered_semidom)⟧ ⟹ (?b ^ (?m::nat) < ?b ^ (?n::nat)) = (?n < ?m)›*)) (*goals: 1. ‹0 < 1 / 2› 2. ‹1 / 2 < 1› 3. ‹0 < Suc n› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . thus "(λz. LBINT u=ereal (exp (-1))..ereal (1-(1/2)^Suc n). f z u) holomorphic_on {z. Re z > -2}" apply (intro integral_holo (*‹⟦(0::real) < min (?a::real) (?b::real); max ?a ?b < (1::real)⟧ ⟹ (λz::complex. complex_interval_lebesgue_integral lborel (ereal ?a) (ereal ?b) ((f::complex ⇒ real ⇒ complex) z)) holomorphic_on (?A::complex set)›*)) (*goals: 1. ‹(1 / 2) ^ Suc n < (1 / 2) ^ 0 ⟹ 0 < min (exp (- 1)) (1 - (1 / 2) ^ Suc n)› 2. ‹(1 / 2) ^ Suc n < (1 / 2) ^ 0 ⟹ max (exp (- 1)) (1 - (1 / 2) ^ Suc n) < 1› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed (auto simp: open_halfspace_Re_gt (*‹open {z. ?b < Re z}›*)) (*solved the remaining goal: ‹open {z. - 2 < Re z}›*) text ‹ Finally, we have shown that Hadjicostas's integral is an analytic function of ‹z› in the domain $\mathfrak{R}(z) > -2$. › lemma holomorphic_Hadjicostas_integral: "Hadjicostas_integral holomorphic_on {z. Re z > -2}" proof (-) (*goal: ‹Hadjicostas_integral holomorphic_on {z. - 2 < Re z}›*) have "(λz. (LBINT u=0..exp(-1). f z u) + (LBINT u=exp(-1)..1. f z u)) holomorphic_on {z. Re z > -2}" by (intro holomorphic_intros (*‹(?f::complex ⇒ complex) holomorphic_on {}› ‹(*) (?c::complex) holomorphic_on (?s::complex set)› ‹(λz::complex. ?c::complex) holomorphic_on (?s::complex set)› ‹(λx::complex. x) holomorphic_on (?s::complex set)› ‹id holomorphic_on (?s::complex set)› ‹(?f::complex ⇒ complex) holomorphic_on (?A::complex set) ⟹ (λz::complex. - ?f z) holomorphic_on ?A› ‹⟦(?f::complex ⇒ complex) holomorphic_on (?A::complex set); (?g::complex ⇒ complex) holomorphic_on ?A⟧ ⟹ (λz::complex. ?f z + ?g z) holomorphic_on ?A› ‹⟦(?f::complex ⇒ complex) holomorphic_on (?A::complex set); (?g::complex ⇒ complex) holomorphic_on ?A⟧ ⟹ (λz::complex. ?f z - ?g z) holomorphic_on ?A› ‹⟦(?f::complex ⇒ complex) holomorphic_on (?A::complex set); (?g::complex ⇒ complex) holomorphic_on ?A⟧ ⟹ (λz::complex. ?f z * ?g z) holomorphic_on ?A› ‹⟦(?f::complex ⇒ complex) holomorphic_on (?A::complex set); ⋀z::complex. z ∈ ?A ⟹ ?f z ≠ (0::complex)⟧ ⟹ (λz::complex. inverse (?f z)) holomorphic_on ?A› ‹⟦(?f::complex ⇒ complex) holomorphic_on (?A::complex set); (?g::complex ⇒ complex) holomorphic_on ?A; ⋀z::complex. z ∈ ?A ⟹ ?g z ≠ (0::complex)⟧ ⟹ (λz::complex. ?f z / ?g z) holomorphic_on ?A› ‹(?f::complex ⇒ complex) holomorphic_on (?A::complex set) ⟹ (λz::complex. ?f z ^ (?n::nat)) holomorphic_on ?A› and more 35 facts*) holo1 (*‹(λz::complex. complex_interval_lebesgue_integral lborel (0::ereal) (ereal (exp (- (1::real)))) ((f::complex ⇒ real ⇒ complex) z)) holomorphic_on {z::complex. - (2::real) < Re z}›*) holo2 (*‹(λz::complex. complex_interval_lebesgue_integral lborel (ereal (exp (- (1::real)))) (1::ereal) ((f::complex ⇒ real ⇒ complex) z)) holomorphic_on {z::complex. - (2::real) < Re z}›*)) also (*calculation: ‹(λz::complex. complex_interval_lebesgue_integral lborel (0::ereal) (ereal (exp (- (1::real)))) ((f::complex ⇒ real ⇒ complex) z) + complex_interval_lebesgue_integral lborel (ereal (exp (- (1::real)))) (1::ereal) (f z)) holomorphic_on {z::complex. - (2::real) < Re z}›*) have "?this ⟷ (λz. LBINT u=0..1. f z u) holomorphic_on {z. Re z > -2}" using Hadjicostas_integral_integrable (*‹- 2 < Re ?z ⟹ complex_interval_lebesgue_integrable lborel 0 1 (f ?z)›*) apply (intro holomorphic_cong (*‹⟦(?s::complex set) = (?t::complex set); ⋀x::complex. x ∈ ?s ⟹ (?f::complex ⇒ complex) x = (?g::complex ⇒ complex) x⟧ ⟹ (?f holomorphic_on ?s) = (?g holomorphic_on ?t)›*) interval_integral_sum (*‹interval_lebesgue_integrable lborel (min (?a::ereal) (min (?b::ereal) (?c::ereal))) (max ?a (max ?b ?c)) (?f::real ⇒ ?'a::{second_countable_topology,banach}) ⟹ interval_lebesgue_integral lborel ?a ?b ?f + interval_lebesgue_integral lborel ?b ?c ?f = interval_lebesgue_integral lborel ?a ?c ?f›*)) (*goals: 1. ‹(⋀z. - 2 < Re z ⟹ complex_interval_lebesgue_integrable lborel 0 1 (f z)) ⟹ {z. - 2 < Re z} = {z. - 2 < Re z}› 2. ‹⋀x. ⟦⋀z. - 2 < Re z ⟹ complex_interval_lebesgue_integrable lborel 0 1 (f z); x ∈ {z. - 2 < Re z}⟧ ⟹ complex_interval_lebesgue_integrable lborel (min 0 (min (ereal (exp (- 1))) 1)) (max 0 (max (ereal (exp (- 1))) 1)) (f x)› discuss goal 1*) apply (simp add: zero_ereal_def (*‹(0::ereal) = ereal (0::real)›*) one_ereal_def (*‹(1::ereal) = ereal (1::real)›*) min_def (*‹min (?a::?'a) (?b::?'a) = (if ?a ≤ ?b then ?a else ?b)›*) max_def (*‹max (?a::?'a) (?b::?'a) = (if ?a ≤ ?b then ?b else ?a)›*)) (*discuss goal 2*) apply (simp add: zero_ereal_def (*‹(0::ereal) = ereal (0::real)›*) one_ereal_def (*‹(1::ereal) = ereal (1::real)›*) min_def (*‹min (?a::?'a) (?b::?'a) = (if ?a ≤ ?b then ?a else ?b)›*) max_def (*‹max (?a::?'a) (?b::?'a) = (if ?a ≤ ?b then ?b else ?a)›*)) (*proven 2 subgoals*) . also (*calculation: ‹(λz. complex_interval_lebesgue_integral lborel 0 1 (f z)) holomorphic_on {z. - 2 < Re z}›*) have "(λz. LBINT u=0..1. f z u) = Hadjicostas_integral" by (simp add: Hadjicostas_integral_def[abs_def] (*‹Hadjicostas_integral ≡ λz. CLBINT u=0..1. complex_of_real (- ln u) powr z / complex_of_real (1 - u) * complex_of_real (- ln u + u - 1)›*) f_def (*‹f ≡ λz u. complex_of_real (- ln u) powr z / complex_of_real (1 - u) * complex_of_real (- ln u + u - 1)›*)) finally (*calculation: ‹Hadjicostas_integral holomorphic_on {z. - 2 < Re z}›*) show "?thesis" (*goal: ‹Hadjicostas_integral holomorphic_on {z. - 2 < Re z}›*) . qed lemma analytic_Hadjicostas_integral: "Hadjicostas_integral analytic_on {z. Re z > -2}" by (simp add: analytic_on_open (*‹open ?S ⟹ (?f analytic_on ?S) = (?f holomorphic_on ?S)›*) open_halfspace_Re_gt (*‹open {z. ?b < Re z}›*) holomorphic_Hadjicostas_integral (*‹Hadjicostas_integral holomorphic_on {z. - 2 < Re z}›*)) end subsection ‹Analytic continuation and main result› text ‹ Since we have already shown the formula for any real ‹z > -1› and e.\,g.\ 0 is a limit point of that set, it extends to the full domain by analytic continuation. As a caveat, note that $\zeta(s)$ is ∗‹not› analytic at ‹z = 1›, so that we use an analytic continuation of $\zeta(z) - \frac{1}{z-1}$ to state the formula. This continuation is @{term "pre_zeta 1"}. › lemma Hadjicostas_Chapman_formula_aux: assumes z: "Re z > -2" shows "Hadjicostas_integral z = Gamma (z + 2) * pre_zeta 1 (z + 2)" (is "_ z = ?f z") proof (rule analytic_continuation'[of Hadjicostas_integral] (*‹⟦Hadjicostas_integral holomorphic_on (?S::complex set); (?g::complex ⇒ complex) holomorphic_on ?S; open ?S; connected ?S; (?U::complex set) ⊆ ?S; (?ξ::complex) ∈ ?S; ?ξ islimpt ?U; ⋀z::complex. z ∈ ?U ⟹ Hadjicostas_integral z = ?g z; (?w::complex) ∈ ?S⟧ ⟹ Hadjicostas_integral ?w = ?g ?w›*)) (*goals: 1. ‹Hadjicostas_integral holomorphic_on ?S› 2. ‹(λa. Gamma (a + 2) * pre_zeta 1 (a + 2)) holomorphic_on ?S› 3. ‹open ?S› 4. ‹connected ?S› 5. ‹?U ⊆ ?S› 6. ‹?ξ ∈ ?S› 7. ‹?ξ islimpt ?U› 8. ‹⋀z. z ∈ ?U ⟹ Hadjicostas_integral z = Gamma (z + 2) * pre_zeta 1 (z + 2)› 9. ‹z ∈ ?S›*) show "Hadjicostas_integral holomorphic_on {z. Re z > -2}" by (rule holomorphic_Hadjicostas_integral (*‹Hadjicostas_integral holomorphic_on {z. - 2 < Re z}›*)) show "connected {z. Re z > -2}" by (intro convex_connected (*‹convex ?S ⟹ connected ?S›*) convex_halfspace_Re_gt (*‹convex {x. ?b < Re x}›*)) show "open {z. Re z > -2}" by (auto simp: open_halfspace_Re_gt (*‹open {z. ?b < Re z}›*)) show "{z. Re z > -1 ∧ Im z = 0} ⊆ {z. Re z > -2}" and "0 ∈ {z. Re z > -2}" (*goals: 1. ‹{z. - 1 < Re z ∧ Im z = 0} ⊆ {z. - 2 < Re z}› 2. ‹0 ∈ {z. - 2 < Re z}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have "∀n. 1 / (of_nat (Suc n)) ∈ {z. Re z > -1 ∧ Im z = 0} - {0}" by (auto simp: field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 77 facts*) simp flip: of_nat_Suc (*‹of_nat (Suc ?m) = 1 + of_nat ?m›*)) moreover have "(λn. 1 / of_nat (Suc n) :: complex) ⇢ 0" apply (rule tendsto_divide_0[OF tendsto_const] (*‹filterlim ?g at_infinity ?F ⟹ ((λx. ?c / ?g x) ⤏ 0) ?F›*) filterlim_compose[OF tendsto_of_nat] (*‹filterlim ?f sequentially ?F1.0 ⟹ LIM x ?F1.0. of_nat (?f x) :> at_infinity›*) filterlim_Suc (*‹filterlim Suc sequentially sequentially›*)) (*goal: ‹(λn. 1 / complex_of_nat (Suc n)) ⇢ 0›*) apply (rule tendsto_divide_0[OF tendsto_const] (*‹filterlim ?g at_infinity ?F ⟹ ((λx. ?c / ?g x) ⤏ 0) ?F›*) filterlim_compose[OF tendsto_of_nat] (*‹filterlim ?f sequentially ?F1.0 ⟹ LIM x ?F1.0. of_nat (?f x) :> at_infinity›*) filterlim_Suc (*‹filterlim Suc sequentially sequentially›*)) (*goal: ‹LIM n sequentially. complex_of_nat (Suc n) :> at_infinity›*) by (rule tendsto_divide_0[OF tendsto_const] (*‹filterlim ?g at_infinity ?F ⟹ ((λx. ?c / ?g x) ⤏ 0) ?F›*) filterlim_compose[OF tendsto_of_nat] (*‹filterlim ?f sequentially ?F1.0 ⟹ LIM x ?F1.0. of_nat (?f x) :> at_infinity›*) filterlim_Suc (*‹filterlim Suc sequentially sequentially›*)) ultimately show "0 islimpt {z. Re z > -1 ∧ Im z = 0}" unfolding islimpt_sequential (*goal: ‹∃f. (∀n. f n ∈ {z. - 1 < Re z ∧ Im z = 0} - {0}) ∧ f ⇢ 0›*) apply (intro exI[of _ "λn. 1 / of_nat (Suc n) :: complex"] (*‹?P (λn. 1 / complex_of_nat (Suc n)) ⟹ ∃x. ?P x›*)) (*goal: ‹∃f. (∀n. f n ∈ {z. - 1 < Re z ∧ Im z = 0} - {0}) ∧ f ⇢ 0›*) by simp show "?f holomorphic_on {z. - 2 < Re z}" proof (intro holomorphic_intros (*‹?f holomorphic_on {}› ‹(*) ?c holomorphic_on ?s› ‹(λz. ?c) holomorphic_on ?s› ‹(λx. x) holomorphic_on ?s› ‹id holomorphic_on ?s› ‹?f holomorphic_on ?A ⟹ (λz. - ?f z) holomorphic_on ?A› ‹⟦?f holomorphic_on ?A; ?g holomorphic_on ?A⟧ ⟹ (λz. ?f z + ?g z) holomorphic_on ?A› ‹⟦?f holomorphic_on ?A; ?g holomorphic_on ?A⟧ ⟹ (λz. ?f z - ?g z) holomorphic_on ?A› ‹⟦?f holomorphic_on ?A; ?g holomorphic_on ?A⟧ ⟹ (λz. ?f z * ?g z) holomorphic_on ?A› ‹⟦?f holomorphic_on ?A; ⋀z. z ∈ ?A ⟹ ?f z ≠ 0⟧ ⟹ (λz. inverse (?f z)) holomorphic_on ?A› ‹⟦?f holomorphic_on ?A; ?g holomorphic_on ?A; ⋀z. z ∈ ?A ⟹ ?g z ≠ 0⟧ ⟹ (λz. ?f z / ?g z) holomorphic_on ?A› ‹?f holomorphic_on ?A ⟹ (λz. ?f z ^ ?n) holomorphic_on ?A› and more 35 facts*)) (*goals: 1. ‹⋀z. z ∈ {z. - 2 < Re z} ⟹ z + 2 ∉ ℤ⇩≤₀› 2. ‹0 < 1›*) fix z assume z: "z ∈ {z. Re z > -2}" (*‹(z::complex) ∈ {z::complex. - (2::real) < Re z}›*) hence "z + 2 ∉ ℝ⇩≤₀" by (auto elim!: nonpos_Reals_cases (*‹⟦?x ∈ ℝ⇩≤₀; ⋀r. ⟦?x = of_real r; r ≤ 0⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) simp: complex_eq_iff (*‹(?x = ?y) = (Re ?x = Re ?y ∧ Im ?x = Im ?y)›*)) thus "z + 2 ∉ ℤ⇩≤₀" using nonpos_Ints_subset_nonpos_Reals (*‹ℤ⇩≤₀ ⊆ ℝ⇩≤₀›*) by blast qed (auto) (*solved the remaining goal: ‹0 < 1›*) next (*goals: 1. ‹⋀z. z ∈ {z. - 1 < Re z ∧ Im z = 0} ⟹ Hadjicostas_integral z = Gamma (z + 2) * pre_zeta 1 (z + 2)› 2. ‹z ∈ {z. - 2 < Re z}›*) fix s assume s: "s ∈ {z. - 1 < Re z ∧ Im z = 0}" (*‹(s::complex) ∈ {z::complex. - (1::real) < Re z ∧ Im z = (0::real)}›*) hence "s + 2 ≠ 1" by (simp add: algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 34 facts*) complex_eq_iff (*‹(?x = ?y) = (Re ?x = Re ?y ∧ Im ?x = Im ?y)›*)) have ineq: "x - ln x ≥ 1" if "x ∈ {0<..<1}" for x :: real using ln_le_minus_one[of x] (*‹0 < x ⟹ ln x ≤ x - 1›*) that (*‹(x::real) ∈ {0::real<..<1::real}›*) by (simp add: algebra_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 34 facts*)) define x where "x = Re s" from s (*‹s ∈ {z. - 1 < Re z ∧ Im z = 0}›*) have x: "x > -1" and [simp]: "s = of_real x" apply - (*goals: 1. ‹s ∈ {z. - 1 < Re z ∧ Im z = 0} ⟹ - 1 < x› 2. ‹s ∈ {z. - 1 < Re z ∧ Im z = 0} ⟹ s = complex_of_real x› discuss goal 1*) apply ((auto simp: x_def (*‹x = Re s›*) complex_eq_iff (*‹(?x = ?y) = (Re ?x = Re ?y ∧ Im ?x = Im ?y)›*))[1]) (*discuss goal 2*) apply ((auto simp: x_def (*‹x = Re s›*) complex_eq_iff (*‹(?x = ?y) = (Re ?x = Re ?y ∧ Im ?x = Im ?y)›*))[1]) (*proven 2 subgoals*) . have "Hadjicostas_integral s = (LBINT u=0..1. of_real ((-ln u) powr x / (1-u) * (-ln u + u - 1)))" unfolding Hadjicostas_integral_def (*goal: ‹CLBINT u::real=(0::ereal)..(1::ereal). complex_of_real (- ln u) powr (s::complex) / complex_of_real ((1::real) - u) * complex_of_real (- ln u + u - (1::real)) = CLBINT u::real=(0::ereal)..(1::ereal). complex_of_real ((- ln u) powr (x::real) / ((1::real) - u) * (- ln u + u - (1::real)))›*) apply (intro interval_lebesgue_integral_cong (*‹⟦?a ≤ ?b; ⋀x. x ∈ einterval ?a ?b ⟹ ?f x = ?g x; einterval ?a ?b ∈ sets ?M⟧ ⟹ interval_lebesgue_integral ?M ?a ?b ?f = interval_lebesgue_integral ?M ?a ?b ?g›*)) (*goals: 1. ‹0 ≤ 1› 2. ‹⋀xa. xa ∈ einterval 0 1 ⟹ complex_of_real (- ln xa) powr s / complex_of_real (1 - xa) * complex_of_real (- ln xa + xa - 1) = complex_of_real ((- ln xa) powr x / (1 - xa) * (- ln xa + xa - 1))› 3. ‹einterval 0 1 ∈ sets lborel› discuss goal 1*) apply ((auto simp: einterval_def (*‹einterval ?a ?b = {x. ?a < ereal x ∧ ereal x < ?b}›*) powr_Reals_eq (*‹⟦?x ∈ ℝ; ?y ∈ ℝ; 0 ≤ Re ?x⟧ ⟹ ?x powr ?y = complex_of_real (Re ?x powr Re ?y)›*))[1]) (*discuss goal 2*) apply ((auto simp: einterval_def (*‹einterval ?a ?b = {x. ?a < ereal x ∧ ereal x < ?b}›*) powr_Reals_eq (*‹⟦?x ∈ ℝ; ?y ∈ ℝ; 0 ≤ Re ?x⟧ ⟹ ?x powr ?y = complex_of_real (Re ?x powr Re ?y)›*))[1]) (*discuss goal 3*) apply ((auto simp: einterval_def (*‹einterval ?a ?b = {x. ?a < ereal x ∧ ereal x < ?b}›*) powr_Reals_eq (*‹⟦?x ∈ ℝ; ?y ∈ ℝ; 0 ≤ Re ?x⟧ ⟹ ?x powr ?y = complex_of_real (Re ?x powr Re ?y)›*))[1]) (*proven 3 subgoals*) . also (*calculation: ‹Hadjicostas_integral s = CLBINT u=0..1. complex_of_real ((- ln u) powr x / (1 - u) * (- ln u + u - 1))›*) have "… = of_real (LBINT u=0..1. (-ln u) powr x / (1-u) * (-ln u + u - 1))" apply (subst interval_lebesgue_integral_of_real (*‹complex_interval_lebesgue_integral (?M::real measure) (?a::ereal) (?b::ereal) (λx::real. complex_of_real ((?f::real ⇒ real) x)) = complex_of_real (interval_lebesgue_integral ?M ?a ?b ?f)›*)) (*goal: ‹CLBINT u=0..1. complex_of_real ((- ln u) powr x / (1 - u) * (- ln u + u - 1)) = complex_of_real (LBINT u=0..1. (- ln u) powr x / (1 - u) * (- ln u + u - 1))›*) by auto also (*calculation: ‹Hadjicostas_integral s = complex_of_real (LBINT u=0..1. (- ln u) powr x / (1 - u) * (- ln u + u - 1))›*) have "(LBINT u=0..1. (- ln u) powr x / (1 - u) * (- ln u + u - 1)) = (∫u. (- ln u) powr x / (1-u) * (- ln u + u - 1) * indicator {0<..<1} u ∂lborel)" by (simp add: interval_integral_Ioo (*‹⟦?a ≤ ?b; ¦?a¦ < ∞; ¦?b¦ < ∞⟧ ⟹ interval_lebesgue_integral lborel ?a ?b ?f = set_lebesgue_integral lborel {real_of_ereal ?a<..<real_of_ereal ?b} ?f›*) zero_ereal_def (*‹0 = ereal 0›*) one_ereal_def (*‹1 = ereal 1›*) set_lebesgue_integral_def (*‹set_lebesgue_integral ?M ?A ?f ≡ LINT x|?M. indicat_real ?A x *⇩R ?f x›*) mult_ac (*‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)›*)) also (*calculation: ‹Hadjicostas_integral s = complex_of_real (LBINT u. (- ln u) powr x / (1 - u) * (- ln u + u - 1) * indicat_real {0<..<1} u)›*) have "… = enn2real (Hadjicostas_nn_integral x)" unfolding Hadjicostas_nn_integral_def (*goal: ‹(LBINT u. (- ln u) powr x / (1 - u) * (- ln u + u - 1) * indicat_real {0<..<1} u) = enn2real (∫⁺xa∈{0<..<1}. ennreal ((- ln xa) powr x / (1 - xa) * (- ln xa + xa - 1))∂lborel)›*) using ineq (*‹?x ∈ {0<..<1} ⟹ 1 ≤ ?x - ln ?x›*) apply (subst integral_eq_nn_integral (*‹⟦?f ∈ borel_measurable ?M; AE x in ?M. 0 ≤ ?f x⟧ ⟹ integral⇧L ?M ?f = enn2real (∫⁺ x. ennreal (?f x) ∂?M)›*)) (*goals: 1. ‹(⋀x. x ∈ {0<..<1} ⟹ 1 ≤ x - ln x) ⟹ (λu. (- ln u) powr x / (1 - u) * (- ln u + u - 1) * indicat_real {0<..<1} u) ∈ borel_measurable lborel› 2. ‹(⋀x. x ∈ {0<..<1} ⟹ 1 ≤ x - ln x) ⟹ AE xa in lborel. 0 ≤ (- ln xa) powr x / (1 - xa) * (- ln xa + xa - 1) * indicat_real {0<..<1} xa› 3. ‹(⋀x. x ∈ {0<..<1} ⟹ 1 ≤ x - ln x) ⟹ enn2real (∫⁺ xa. ennreal ((- ln xa) powr x / (1 - xa) * (- ln xa + xa - 1) * indicat_real {0<..<1} xa) ∂lborel) = enn2real (∫⁺xa∈{0<..<1}. ennreal ((- ln xa) powr x / (1 - xa) * (- ln xa + xa - 1))∂lborel)› discuss goal 1*) apply ((auto intro!: AE_I2 (*‹(⋀x. x ∈ space ?M ⟹ ?P x) ⟹ almost_everywhere ?M ?P›*) divide_nonneg_nonneg (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ 0 ≤ ?x / ?y›*) mult_nonneg_nonneg (*‹⟦0 ≤ ?a; 0 ≤ ?b⟧ ⟹ 0 ≤ ?a * ?b›*) arg_cong[where f = enn2real] (*‹?x = ?y ⟹ enn2real ?x = enn2real ?y›*) nn_integral_cong (*‹(⋀x. x ∈ space ?M ⟹ ?u x = ?v x) ⟹ integral⇧N ?M ?u = integral⇧N ?M ?v›*) simp: indicator_def (*‹indicator ?S ?x = of_bool (?x ∈ ?S)›*))[1]) (*discuss goal 2*) apply ((auto intro!: AE_I2 (*‹(⋀x. x ∈ space ?M ⟹ ?P x) ⟹ almost_everywhere ?M ?P›*) divide_nonneg_nonneg (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ 0 ≤ ?x / ?y›*) mult_nonneg_nonneg (*‹⟦0 ≤ ?a; 0 ≤ ?b⟧ ⟹ 0 ≤ ?a * ?b›*) arg_cong[where f = enn2real] (*‹?x = ?y ⟹ enn2real ?x = enn2real ?y›*) nn_integral_cong (*‹(⋀x. x ∈ space ?M ⟹ ?u x = ?v x) ⟹ integral⇧N ?M ?u = integral⇧N ?M ?v›*) simp: indicator_def (*‹indicator ?S ?x = of_bool (?x ∈ ?S)›*))[1]) (*discuss goal 3*) apply ((auto intro!: AE_I2 (*‹(⋀x. x ∈ space ?M ⟹ ?P x) ⟹ almost_everywhere ?M ?P›*) divide_nonneg_nonneg (*‹⟦0 ≤ ?x; 0 ≤ ?y⟧ ⟹ 0 ≤ ?x / ?y›*) mult_nonneg_nonneg (*‹⟦0 ≤ ?a; 0 ≤ ?b⟧ ⟹ 0 ≤ ?a * ?b›*) arg_cong[where f = enn2real] (*‹?x = ?y ⟹ enn2real ?x = enn2real ?y›*) nn_integral_cong (*‹(⋀x. x ∈ space ?M ⟹ ?u x = ?v x) ⟹ integral⇧N ?M ?u = integral⇧N ?M ?v›*) simp: indicator_def (*‹indicator ?S ?x = of_bool (?x ∈ ?S)›*))[1]) (*proven 3 subgoals*) . also (*calculation: ‹Hadjicostas_integral s = complex_of_real (enn2real (Hadjicostas_nn_integral x))›*) have "… = enn2real (ennreal (Gamma (x + 2) * (Re (zeta (x + 2)) - 1 / (x + 1))))" using x (*‹- 1 < x›*) apply (subst Hadjicostas_Chapman_formula_real (*‹- 1 < ?z ⟹ Hadjicostas_nn_integral ?z = ennreal (Gamma (?z + 2) * (Re (zeta (complex_of_real (?z + 2))) - 1 / (?z + 1)))›*)) (*goals: 1. ‹- 1 < x ⟹ - 1 < x› 2. ‹- 1 < x ⟹ enn2real (ennreal (Gamma (x + 2) * (Re (zeta (complex_of_real (x + 2))) - 1 / (x + 1)))) = enn2real (ennreal (Gamma (x + 2) * (Re (zeta (complex_of_real (x + 2))) - 1 / (x + 1))))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . also (*calculation: ‹Hadjicostas_integral s = complex_of_real (enn2real (ennreal (Gamma (x + 2) * (Re (zeta (complex_of_real (x + 2))) - 1 / (x + 1)))))›*) have "… = Gamma (x + 2) * (Re (zeta (x + 2)) - 1 / (x + 1))" using x (*‹- 1 < x›*) real_zeta_ge_one_over_minus_one[of "x + 2"] (*‹(1::real) < (x::real) + (2::real) ⟹ (1::real) / (x + (2::real) - (1::real)) ≤ Re (zeta (complex_of_real (x + (2::real))))›*) apply (intro enn2real_ennreal (*‹(0::real) ≤ (?r::real) ⟹ enn2real (ennreal ?r) = ?r›*) mult_nonneg_nonneg (*‹⟦(0::?'a) ≤ (?a::?'a); (0::?'a) ≤ (?b::?'a)⟧ ⟹ (0::?'a) ≤ ?a * ?b›*) Gamma_real_nonneg (*‹(0::real) < (?x::real) ⟹ (0::real) ≤ Gamma ?x›*)) (*goals: 1. ‹⟦- 1 < x; 1 < x + 2 ⟹ 1 / (x + 2 - 1) ≤ Re (zeta (complex_of_real (x + 2)))⟧ ⟹ 0 < x + 2› 2. ‹⟦- 1 < x; 1 < x + 2 ⟹ 1 / (x + 2 - 1) ≤ Re (zeta (complex_of_real (x + 2)))⟧ ⟹ 0 ≤ Re (zeta (complex_of_real (x + 2))) - 1 / (x + 1)› discuss goal 1*) apply ((auto simp: add_ac (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)›*))[1]) (*discuss goal 2*) apply ((auto simp: add_ac (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)›*))[1]) (*proven 2 subgoals*) . also (*calculation: ‹Hadjicostas_integral s = complex_of_real (Gamma (x + 2) * (Re (zeta (complex_of_real (x + 2))) - 1 / (x + 1)))›*) have "complex_of_real … = Gamma (s + 2) * (zeta (s + 2) - 1 / (s + 1))" using x (*‹- 1 < x›*) Gamma_complex_of_real[of "x + 2"] (*‹Gamma (complex_of_real (x + 2)) = complex_of_real (Gamma (x + 2))›*) by (simp add: zeta_real' (*‹?z ∈ ℝ ⟹ zeta ?z ∈ ℝ›*)) also (*calculation: ‹Hadjicostas_integral s = Gamma (s + 2) * (zeta (s + 2) - 1 / (s + 1))›*) have "(zeta (s + 2) - 1 / (s + 1)) = pre_zeta 1 (s + 2)" using ‹s + 2 ≠ 1› (*‹s + 2 ≠ 1›*) apply (subst zeta_minus_pole_eq [symmetric] (*‹?s ≠ 1 ⟹ pre_zeta 1 ?s = zeta ?s - 1 / (?s - 1)›*)) (*goals: 1. ‹s + 2 ≠ 1 ⟹ s + 2 ≠ 1› 2. ‹s + 2 ≠ 1 ⟹ zeta (s + 2) - 1 / (s + 1) = zeta (s + 2) - 1 / (s + 2 - 1)› discuss goal 1*) apply ((auto simp flip: of_nat_Suc (*‹of_nat (Suc ?m) = 1 + of_nat ?m›*))[1]) (*discuss goal 2*) apply ((auto simp flip: of_nat_Suc (*‹of_nat (Suc ?m) = 1 + of_nat ?m›*))[1]) (*proven 2 subgoals*) . finally (*calculation: ‹Hadjicostas_integral s = Gamma (s + 2) * pre_zeta 1 (s + 2)›*) show "Hadjicostas_integral s = Gamma (s + 2) * pre_zeta 1 (s + 2)" . qed (use assms in auto) (*solved the remaining goal: ‹z ∈ {z. - 2 < Re z}›*) text ‹ The following form and the corollary are perhaps a bit nicer to read. › theorem Hadjicostas_Chapman_formula: assumes z: "Re z > -2" "z ≠ -1" shows "Hadjicostas_integral z = Gamma (z + 2) * (zeta (z + 2) - 1 / (z + 1))" proof (-) (*goal: ‹Hadjicostas_integral (z::complex) = Gamma (z + (2::complex)) * (zeta (z + (2::complex)) - (1::complex) / (z + (1::complex)))›*) from z (*‹- 2 < Re z› ‹z ≠ - 1›*) have "z + 1 ≠ 0" by (auto simp: complex_eq_iff (*‹(?x = ?y) = (Re ?x = Re ?y ∧ Im ?x = Im ?y)›*)) thus "?thesis" (*goal: ‹Hadjicostas_integral z = Gamma (z + 2) * (zeta (z + 2) - 1 / (z + 1))›*) using Hadjicostas_Chapman_formula_aux[of z] (*‹- 2 < Re z ⟹ Hadjicostas_integral z = Gamma (z + 2) * pre_zeta 1 (z + 2)›*) assms (*‹- 2 < Re z› ‹z ≠ - 1›*) apply (subst (asm) zeta_minus_pole_eq [symmetric] (*‹(?s::complex) ≠ (1::complex) ⟹ pre_zeta (1::real) ?s = zeta ?s - (1::complex) / (?s - (1::complex))›*)) (*goals: 1. ‹⟦- (2::real) < Re (z::complex) ⟹ Hadjicostas_integral z = Gamma (z + (2::complex)) * pre_zeta (1::real) (z + (2::complex)); z ≠ - (1::complex); z + (1::complex) ≠ (0::complex)⟧ ⟹ z + (2::complex) ≠ (1::complex)› 2. ‹⟦(z::complex) + (1::complex) ≠ (0::complex); - (2::real) < Re z; - (2::real) < Re z ⟹ Hadjicostas_integral z = Gamma (z + (2::complex)) * pre_zeta (1::real) (z + (2::complex)); z ≠ - (1::complex)⟧ ⟹ Hadjicostas_integral z = Gamma (z + (2::complex)) * pre_zeta (1::real) (z + (2::complex))› 3. ‹⟦- (2::real) < Re (z::complex) ⟹ Hadjicostas_integral z = Gamma (z + (2::complex)) * pre_zeta (1::real) (z + (2::complex)); z ≠ - (1::complex); z + (1::complex) ≠ (0::complex); Hadjicostas_integral z = Gamma (z + (2::complex)) * (zeta (z + (2::complex)) - (1::complex) / (z + (2::complex) - (1::complex)))⟧ ⟹ Hadjicostas_integral z = Gamma (z + (2::complex)) * (zeta (z + (2::complex)) - (1::complex) / (z + (1::complex)))› discuss goal 1*) apply ((auto simp: add_ac (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)›*))[1]) (*discuss goal 2*) apply ((auto simp: add_ac (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)›*))[1]) (*discuss goal 3*) apply ((auto simp: add_ac (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)›*))[1]) (*proven 3 subgoals*) . qed corollary euler_mascheroni_integral_form: "Hadjicostas_integral (-1) = euler_mascheroni" using Hadjicostas_Chapman_formula_aux[of "-1"] (*‹- (2::real) < Re (- (1::complex)) ⟹ Hadjicostas_integral (- (1::complex)) = Gamma (- (1::complex) + (2::complex)) * pre_zeta (1::real) (- (1::complex) + (2::complex))›*) by simp end
{ "path": "afp-2025-02-12/thys/Zeta_Function/Hadjicostas_Chapman.thy", "repo": "afp-2025-02-12", "sha": "2950183625215df4c8efb4e4bd9b0a010ad4194faa57cac5014064b9c665e24c" }
(* Title: HOL/Analysis/Infinite_Sum.thy Author: Dominique Unruh, University of Tartu Manuel Eberl, University of Innsbruck A theory of sums over possibly infinite sets. *) section ‹Infinite sums› \<^latex>‹\label{section:Infinite_Sum}› text ‹In this theory, we introduce the definition of infinite sums, i.e., sums ranging over an infinite, potentially uncountable index set with no particular ordering. (This is different from series. Those are sums indexed by natural numbers, and the order of the index set matters.) Our definition is quite standard: $s:=\sum_{x\in A} f(x)$ is the limit of finite sums $s_F:=\sum_{x\in F} f(x)$ for increasing $F$. That is, $s$ is the limit of the net $s_F$ where $F$ are finite subsets of $A$ ordered by inclusion. We believe that this is the standard definition for such sums. See, e.g., Definition 4.11 in \<^cite>‹"conway2013course"›. This definition is quite general: it is well-defined whenever $f$ takes values in some commutative monoid endowed with a Hausdorff topology. (Examples are reals, complex numbers, normed vector spaces, and more.)› theory Infinite_Sum imports Elementary_Topology "HOL-Library.Extended_Nonnegative_Real" "HOL-Library.Complex_Order" begin subsection ‹Definition and syntax› definition HAS_SUM :: ‹('a ⇒ 'b :: {comm_monoid_add, topological_space}) ⇒ 'a set ⇒ 'b ⇒ bool› where has_sum_def: ‹HAS_SUM f A x ≡ (sum f ⤏ x) (finite_subsets_at_top A)› abbreviation has_sum (infixr "has'_sum" 46) where "(f has_sum S) A ≡ HAS_SUM f A S" definition summable_on :: "('a ⇒ 'b::{comm_monoid_add, topological_space}) ⇒ 'a set ⇒ bool" (infixr "summable'_on" 46) where "f summable_on A ≡ (∃x. (f has_sum x) A)" definition infsum :: "('a ⇒ 'b::{comm_monoid_add,t2_space}) ⇒ 'a set ⇒ 'b" where "infsum f A = (if f summable_on A then Lim (finite_subsets_at_top A) (sum f) else 0)" abbreviation abs_summable_on :: "('a ⇒ 'b::real_normed_vector) ⇒ 'a set ⇒ bool" (infixr "abs'_summable'_on" 46) where "f abs_summable_on A ≡ (λx. norm (f x)) summable_on A" syntax (ASCII) "_infsum" :: "pttrn ⇒ 'a set ⇒ 'b ⇒ 'b::topological_comm_monoid_add" ("(3INFSUM (_/:_)./ _)" [0, 51, 10] 10) syntax "_infsum" :: "pttrn ⇒ 'a set ⇒ 'b ⇒ 'b::topological_comm_monoid_add" ("(2∑⇩∞(_/∈_)./ _)" [0, 51, 10] 10) translations ― ‹Beware of argument permutation!› "∑⇩∞i∈A. b" ⇌ "CONST infsum (λi. b) A" syntax (ASCII) "_univinfsum" :: "pttrn ⇒ 'a ⇒ 'a" ("(3INFSUM _./ _)" [0, 10] 10) syntax "_univinfsum" :: "pttrn ⇒ 'a ⇒ 'a" ("(2∑⇩∞_./ _)" [0, 10] 10) translations "∑⇩∞x. t" ⇌ "CONST infsum (λx. t) (CONST UNIV)" syntax (ASCII) "_qinfsum" :: "pttrn ⇒ bool ⇒ 'a ⇒ 'a" ("(3INFSUM _ |/ _./ _)" [0, 0, 10] 10) syntax "_qinfsum" :: "pttrn ⇒ bool ⇒ 'a ⇒ 'a" ("(2∑⇩∞_ | (_)./ _)" [0, 0, 10] 10) translations "∑⇩∞x|P. t" => "CONST infsum (λx. t) {x. P}" print_translation ‹ let fun sum_tr' [Abs (x, Tx, t), Const (@{const_syntax Collect}, _) $ Abs (y, Ty, P)] = if x <> y then raise Match else let val x' = Syntax_Trans.mark_bound_body (x, Tx); val t' = subst_bound (x', t); val P' = subst_bound (x', P); in Syntax.const @{syntax_const "_qinfsum"} $ Syntax_Trans.mark_bound_abs (x, Tx) $ P' $ t' end | sum_tr' _ = raise Match; in [(@{const_syntax infsum}, K sum_tr')] end › subsection ‹General properties› lemma infsumI: fixes f g :: ‹'a ⇒ 'b::{comm_monoid_add, t2_space}› assumes ‹(f has_sum x) A› shows ‹infsum f A = x› by (metis assms (*‹(f has_sum x) A›*) finite_subsets_at_top_neq_bot (*‹finite_subsets_at_top ?A ≠ bot›*) infsum_def (*‹infsum ?f ?A = (if ?f summable_on ?A then Lim (finite_subsets_at_top ?A) (sum ?f) else 0)›*) summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*) has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*) tendsto_Lim (*‹⟦?net ≠ bot; (?f ⤏ ?l) ?net⟧ ⟹ Lim ?net ?f = ?l›*)) lemma infsum_eqI: fixes f g :: ‹'a ⇒ 'b::{comm_monoid_add, t2_space}› assumes ‹x = y› assumes ‹(f has_sum x) A› assumes ‹(g has_sum y) B› shows ‹infsum f A = infsum g B› using assms (*‹x = y› ‹(f has_sum x) A› ‹(g has_sum y) B›*) infsumI (*‹(?f has_sum ?x) ?A ⟹ infsum ?f ?A = ?x›*) by blast lemma infsum_eqI': fixes f g :: ‹'a ⇒ 'b::{comm_monoid_add, t2_space}› assumes ‹⋀x. (f has_sum x) A ⟷ (g has_sum x) B› shows ‹infsum f A = infsum g B› by (metis assms (*‹((f::'a ⇒ 'b) has_sum (?x::'b)) (A::'a set) = ((g::'a ⇒ 'b) has_sum ?x) (B::'a set)›*) infsum_def (*‹infsum (?f::?'a ⇒ ?'b) (?A::?'a set) = (if ?f summable_on ?A then Lim (finite_subsets_at_top ?A) (sum ?f) else (0::?'b))›*) infsum_eqI (*‹⟦(?x::?'b) = (?y::?'b); ((?f::?'a ⇒ ?'b) has_sum ?x) (?A::?'a set); ((?g::?'a ⇒ ?'b) has_sum ?y) (?B::?'a set)⟧ ⟹ infsum ?f ?A = infsum ?g ?B›*) summable_on_def (*‹(?f::?'a ⇒ ?'b) summable_on (?A::?'a set) ≡ ∃x::?'b. (?f has_sum x) ?A›*)) lemma infsum_not_exists: fixes f :: ‹'a ⇒ 'b::{comm_monoid_add, t2_space}› assumes ‹¬ f summable_on A› shows ‹infsum f A = 0› by (simp add: assms (*‹¬ f summable_on A›*) infsum_def (*‹infsum ?f ?A = (if ?f summable_on ?A then Lim (finite_subsets_at_top ?A) (sum ?f) else 0)›*)) lemma summable_iff_has_sum_infsum: "f summable_on A ⟷ (f has_sum (infsum f A)) A" using infsumI (*‹(?f has_sum ?x) ?A ⟹ infsum ?f ?A = ?x›*) summable_on_def (*‹(?f::?'a::type ⇒ ?'b::{comm_monoid_add,topological_space}) summable_on (?A::?'a::type set) ≡ ∃x::?'b::{comm_monoid_add,topological_space}. (?f has_sum x) ?A›*) by blast lemma has_sum_infsum[simp]: assumes ‹f summable_on S› shows ‹(f has_sum (infsum f S)) S› using assms (*‹f summable_on S›*) summable_iff_has_sum_infsum (*‹(?f summable_on ?A) = (?f has_sum infsum ?f ?A) ?A›*) by blast lemma has_sum_cong_neutral: fixes f g :: ‹'a ⇒ 'b::{comm_monoid_add, topological_space}› assumes ‹⋀x. x∈T-S ⟹ g x = 0› assumes ‹⋀x. x∈S-T ⟹ f x = 0› assumes ‹⋀x. x∈S∩T ⟹ f x = g x› shows "(f has_sum x) S ⟷ (g has_sum x) T" proof (-) (*goal: ‹((f::'a ⇒ 'b) has_sum (x::'b)) (S::'a set) = ((g::'a ⇒ 'b) has_sum x) (T::'a set)›*) have "eventually P (filtermap (sum f) (finite_subsets_at_top S)) = eventually P (filtermap (sum g) (finite_subsets_at_top T))" for P proof (standard) (*goals: 1. ‹eventually (P::'b ⇒ bool) (filtermap (sum (f::'a ⇒ 'b)) (finite_subsets_at_top (S::'a set))) ⟹ eventually P (filtermap (sum (g::'a ⇒ 'b)) (finite_subsets_at_top (T::'a set)))› 2. ‹eventually (P::'b ⇒ bool) (filtermap (sum (g::'a ⇒ 'b)) (finite_subsets_at_top (T::'a set))) ⟹ eventually P (filtermap (sum (f::'a ⇒ 'b)) (finite_subsets_at_top (S::'a set)))›*) assume "eventually P (filtermap (sum f) (finite_subsets_at_top S))" (*‹eventually (P::'b ⇒ bool) (filtermap (sum (f::'a ⇒ 'b)) (finite_subsets_at_top (S::'a set)))›*) then obtain F0 where "finite F0" and "F0 ⊆ S" and F0_P: "⋀F. finite F ⟹ F ⊆ S ⟹ F ⊇ F0 ⟹ P (sum f F)" (*goal: ‹(⋀F0. ⟦finite F0; F0 ⊆ S; ⋀F. ⟦finite F; F ⊆ S; F0 ⊆ F⟧ ⟹ P (sum f F)⟧ ⟹ thesis) ⟹ thesis›*) by (metis (no_types, lifting) eventually_filtermap (*‹eventually ?P (filtermap ?f ?F) = (∀⇩F x in ?F. ?P (?f x))›*) eventually_finite_subsets_at_top (*‹eventually ?P (finite_subsets_at_top ?A) = (∃X. finite X ∧ X ⊆ ?A ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ ?A ⟶ ?P Y))›*)) define F0' where "F0' = F0 ∩ T" have [simp]: "finite F0'" "F0' ⊆ T" (*goals: 1. ‹finite F0'› 2. ‹F0' ⊆ T› discuss goal 1*) apply (simp add: F0'_def (*‹F0' = F0 ∩ T›*) ‹finite F0›) (*discuss goal 2*) apply (simp add: F0'_def (*‹F0' = F0 ∩ T›*) ‹finite F0›) (*proven 2 subgoals*) . have "P (sum g F)" if "finite F" "F ⊆ T" "F ⊇ F0'" for F proof (-) (*goal: ‹P (sum g F)›*) have "P (sum f ((F∩S) ∪ (F0∩S)))" apply (intro F0_P (*‹⟦finite ?F; ?F ⊆ S; F0 ⊆ ?F⟧ ⟹ P (sum f ?F)›*)) (*goals: 1. ‹finite (F ∩ S ∪ F0 ∩ S)› 2. ‹F ∩ S ∪ F0 ∩ S ⊆ S› 3. ‹F0 ⊆ F ∩ S ∪ F0 ∩ S› discuss goal 1*) apply ((use ‹F0 ⊆ S› ‹finite F0› that in auto)[1]) (*discuss goal 2*) apply ((use ‹F0 ⊆ S› ‹finite F0› that in auto)[1]) (*discuss goal 3*) apply ((use ‹F0 ⊆ S› ‹finite F0› that in auto)[1]) (*proven 3 subgoals*) . also (*calculation: ‹P (sum f (F ∩ S ∪ F0 ∩ S))›*) have "sum f ((F∩S) ∪ (F0∩S)) = sum g F" apply (intro sum.mono_neutral_cong (*‹⟦finite ?T; finite ?S; ⋀i. i ∈ ?T - ?S ⟹ ?h i = 0; ⋀i. i ∈ ?S - ?T ⟹ ?g i = 0; ⋀x. x ∈ ?S ∩ ?T ⟹ ?g x = ?h x⟧ ⟹ sum ?g ?S = sum ?h ?T›*)) (*goals: 1. ‹finite F› 2. ‹finite (F ∩ S ∪ F0 ∩ S)› 3. ‹⋀i. i ∈ F - (F ∩ S ∪ F0 ∩ S) ⟹ g i = 0› 4. ‹⋀i. i ∈ F ∩ S ∪ F0 ∩ S - F ⟹ f i = 0› 5. ‹⋀x. x ∈ (F ∩ S ∪ F0 ∩ S) ∩ F ⟹ f x = g x› discuss goal 1*) apply ((use that ‹finite F0› F0'_def assms in auto)[1]) (*discuss goal 2*) apply ((use that ‹finite F0› F0'_def assms in auto)[1]) (*discuss goal 3*) apply ((use that ‹finite F0› F0'_def assms in auto)[1]) (*discuss goal 4*) apply ((use that ‹finite F0› F0'_def assms in auto)[1]) (*discuss goal 5*) apply ((use that ‹finite F0› F0'_def assms in auto)[1]) (*proven 5 subgoals*) . finally (*calculation: ‹P (sum g F)›*) show "?thesis" (*goal: ‹(P::'b::{comm_monoid_add,topological_space} ⇒ bool) (sum (g::'a::type ⇒ 'b::{comm_monoid_add,topological_space}) (F::'a::type set))›*) . qed with ‹F0' ⊆ T› (*‹(F0'::'a::type set) ⊆ (T::'a::type set)›*) ‹finite F0'› (*‹finite F0'›*) show "eventually P (filtermap (sum g) (finite_subsets_at_top T))" by (metis (no_types, lifting) eventually_filtermap (*‹eventually ?P (filtermap ?f ?F) = (∀⇩F x in ?F. ?P (?f x))›*) eventually_finite_subsets_at_top (*‹eventually ?P (finite_subsets_at_top ?A) = (∃X. finite X ∧ X ⊆ ?A ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ ?A ⟶ ?P Y))›*)) next (*goal: ‹eventually P (filtermap (sum g) (finite_subsets_at_top T)) ⟹ eventually P (filtermap (sum f) (finite_subsets_at_top S))›*) assume "eventually P (filtermap (sum g) (finite_subsets_at_top T))" (*‹eventually (P::'b ⇒ bool) (filtermap (sum (g::'a ⇒ 'b)) (finite_subsets_at_top (T::'a set)))›*) then obtain F0 where "finite F0" and "F0 ⊆ T" and F0_P: "⋀F. finite F ⟹ F ⊆ T ⟹ F ⊇ F0 ⟹ P (sum g F)" (*goal: ‹(⋀F0. ⟦finite F0; F0 ⊆ T; ⋀F. ⟦finite F; F ⊆ T; F0 ⊆ F⟧ ⟹ P (sum g F)⟧ ⟹ thesis) ⟹ thesis›*) by (metis (no_types, lifting) eventually_filtermap (*‹eventually (?P::?'a ⇒ bool) (filtermap (?f::?'b ⇒ ?'a) (?F::?'b filter)) = (∀⇩F x::?'b in ?F. ?P (?f x))›*) eventually_finite_subsets_at_top (*‹eventually (?P::?'a set ⇒ bool) (finite_subsets_at_top (?A::?'a set)) = (∃X::?'a set. finite X ∧ X ⊆ ?A ∧ (∀Y::?'a set. finite Y ∧ X ⊆ Y ∧ Y ⊆ ?A ⟶ ?P Y))›*)) define F0' where "F0' = F0 ∩ S" have [simp]: "finite F0'" "F0' ⊆ S" (*goals: 1. ‹finite (F0'::'a::type set)› 2. ‹(F0'::'a::type set) ⊆ (S::'a::type set)› discuss goal 1*) apply (simp add: F0'_def (*‹F0' = F0 ∩ S›*) ‹finite F0›) (*discuss goal 2*) apply (simp add: F0'_def (*‹F0' = F0 ∩ S›*) ‹finite F0›) (*proven 2 subgoals*) . have "P (sum f F)" if "finite F" "F ⊆ S" "F ⊇ F0'" for F proof (-) (*goal: ‹P (sum f F)›*) have "P (sum g ((F∩T) ∪ (F0∩T)))" apply (intro F0_P (*‹⟦finite (?F::'a::type set); ?F ⊆ (T::'a::type set); (F0::'a::type set) ⊆ ?F⟧ ⟹ (P::'b::{comm_monoid_add,topological_space} ⇒ bool) (sum (g::'a::type ⇒ 'b::{comm_monoid_add,topological_space}) ?F)›*)) (*goals: 1. ‹finite ((F::'a set) ∩ (T::'a set) ∪ (F0::'a set) ∩ T)› 2. ‹(F::'a set) ∩ (T::'a set) ∪ (F0::'a set) ∩ T ⊆ T› 3. ‹(F0::'a set) ⊆ (F::'a set) ∩ (T::'a set) ∪ F0 ∩ T› discuss goal 1*) apply ((use ‹F0 ⊆ T› ‹finite F0› that in auto)[1]) (*discuss goal 2*) apply ((use ‹F0 ⊆ T› ‹finite F0› that in auto)[1]) (*discuss goal 3*) apply ((use ‹F0 ⊆ T› ‹finite F0› that in auto)[1]) (*proven 3 subgoals*) . also (*calculation: ‹P (sum g (F ∩ T ∪ F0 ∩ T))›*) have "sum g ((F∩T) ∪ (F0∩T)) = sum f F" apply (intro sum.mono_neutral_cong (*‹⟦finite ?T; finite ?S; ⋀i. i ∈ ?T - ?S ⟹ ?h i = 0; ⋀i. i ∈ ?S - ?T ⟹ ?g i = 0; ⋀x. x ∈ ?S ∩ ?T ⟹ ?g x = ?h x⟧ ⟹ sum ?g ?S = sum ?h ?T›*)) (*goals: 1. ‹finite F› 2. ‹finite (F ∩ T ∪ F0 ∩ T)› 3. ‹⋀i. i ∈ F - (F ∩ T ∪ F0 ∩ T) ⟹ f i = 0› 4. ‹⋀i. i ∈ F ∩ T ∪ F0 ∩ T - F ⟹ g i = 0› 5. ‹⋀x. x ∈ (F ∩ T ∪ F0 ∩ T) ∩ F ⟹ g x = f x› discuss goal 1*) apply ((use that ‹finite F0› F0'_def assms in auto)[1]) (*discuss goal 2*) apply ((use that ‹finite F0› F0'_def assms in auto)[1]) (*discuss goal 3*) apply ((use that ‹finite F0› F0'_def assms in auto)[1]) (*discuss goal 4*) apply ((use that ‹finite F0› F0'_def assms in auto)[1]) (*discuss goal 5*) apply ((use that ‹finite F0› F0'_def assms in auto)[1]) (*proven 5 subgoals*) . finally (*calculation: ‹P (sum f F)›*) show "?thesis" (*goal: ‹P (sum f F)›*) . qed with ‹F0' ⊆ S› (*‹(F0'::'a set) ⊆ (S::'a set)›*) ‹finite F0'› (*‹finite F0'›*) show "eventually P (filtermap (sum f) (finite_subsets_at_top S))" by (metis (no_types, lifting) eventually_filtermap (*‹eventually ?P (filtermap ?f ?F) = (∀⇩F x in ?F. ?P (?f x))›*) eventually_finite_subsets_at_top (*‹eventually ?P (finite_subsets_at_top ?A) = (∃X. finite X ∧ X ⊆ ?A ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ ?A ⟶ ?P Y))›*)) qed then have tendsto_x: "(sum f ⤏ x) (finite_subsets_at_top S) ⟷ (sum g ⤏ x) (finite_subsets_at_top T)" for x by (simp add: le_filter_def (*‹(?F ≤ ?F') = (∀P. eventually P ?F' ⟶ eventually P ?F)›*) filterlim_def (*‹filterlim ?f ?F2.0 ?F1.0 = (filtermap ?f ?F1.0 ≤ ?F2.0)›*)) then show "?thesis" (*goal: ‹(f has_sum x) S = (g has_sum x) T›*) by (simp add: has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*)) qed lemma summable_on_cong_neutral: fixes f g :: ‹'a ⇒ 'b::{comm_monoid_add, topological_space}› assumes ‹⋀x. x∈T-S ⟹ g x = 0› assumes ‹⋀x. x∈S-T ⟹ f x = 0› assumes ‹⋀x. x∈S∩T ⟹ f x = g x› shows "f summable_on S ⟷ g summable_on T" using has_sum_cong_neutral[of T S g f, OF assms] (*‹⟦⋀x. x ∈ T - S ⟹ x ∈ T - S; ⋀x. x ∈ S - T ⟹ x ∈ S - T; ⋀x. x ∈ S ∩ T ⟹ x ∈ S ∩ T⟧ ⟹ (f has_sum ?x) S = (g has_sum ?x) T›*) by (simp add: summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*)) lemma infsum_cong_neutral: fixes f g :: ‹'a ⇒ 'b::{comm_monoid_add, t2_space}› assumes ‹⋀x. x∈T-S ⟹ g x = 0› assumes ‹⋀x. x∈S-T ⟹ f x = 0› assumes ‹⋀x. x∈S∩T ⟹ f x = g x› shows ‹infsum f S = infsum g T› by (smt (verit, best) assms (*‹?x ∈ T - S ⟹ g ?x = 0› ‹?x ∈ S - T ⟹ f ?x = 0› ‹?x ∈ S ∩ T ⟹ f ?x = g ?x›*) has_sum_cong_neutral (*‹⟦⋀x. x ∈ ?T - ?S ⟹ ?g x = 0; ⋀x. x ∈ ?S - ?T ⟹ ?f x = 0; ⋀x. x ∈ ?S ∩ ?T ⟹ ?f x = ?g x⟧ ⟹ (?f has_sum ?x) ?S = (?g has_sum ?x) ?T›*) infsum_eqI' (*‹(⋀x. (?f has_sum x) ?A = (?g has_sum x) ?B) ⟹ infsum ?f ?A = infsum ?g ?B›*)) lemma has_sum_cong: assumes "⋀x. x∈A ⟹ f x = g x" shows "(f has_sum x) A ⟷ (g has_sum x) A" using assms (*‹?x ∈ A ⟹ f ?x = g ?x›*) apply (intro has_sum_cong_neutral (*‹⟦⋀x. x ∈ ?T - ?S ⟹ ?g x = 0; ⋀x. x ∈ ?S - ?T ⟹ ?f x = 0; ⋀x. x ∈ ?S ∩ ?T ⟹ ?f x = ?g x⟧ ⟹ (?f has_sum ?x) ?S = (?g has_sum ?x) ?T›*)) (*goals: 1. ‹⋀x. ⟦⋀x. x ∈ A ⟹ f x = g x; x ∈ A - A⟧ ⟹ g x = 0› 2. ‹⋀x. ⟦⋀x. x ∈ A ⟹ f x = g x; x ∈ A - A⟧ ⟹ f x = 0› 3. ‹⋀x. ⟦⋀x. x ∈ A ⟹ f x = g x; x ∈ A ∩ A⟧ ⟹ f x = g x› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . lemma summable_on_cong: assumes "⋀x. x∈A ⟹ f x = g x" shows "f summable_on A ⟷ g summable_on A" by (metis assms (*‹?x ∈ A ⟹ f ?x = g ?x›*) summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*) has_sum_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ (?f has_sum ?x) ?A = (?g has_sum ?x) ?A›*)) lemma infsum_cong: assumes "⋀x. x∈A ⟹ f x = g x" shows "infsum f A = infsum g A" using assms (*‹?x ∈ A ⟹ f ?x = g ?x›*) infsum_eqI' (*‹(⋀x::?'b. ((?f::?'a ⇒ ?'b) has_sum x) (?A::?'a set) = ((?g::?'a ⇒ ?'b) has_sum x) (?B::?'a set)) ⟹ infsum ?f ?A = infsum ?g ?B›*) has_sum_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ (?f has_sum ?x) ?A = (?g has_sum ?x) ?A›*) by blast lemma summable_on_cofin_subset: fixes f :: "'a ⇒ 'b::topological_ab_group_add" assumes "f summable_on A" and [simp]: "finite F" shows "f summable_on (A - F)" proof (-) (*goal: ‹f summable_on A - F›*) from assms(1) (*‹f summable_on A›*) obtain x where lim_f: "(sum f ⤏ x) (finite_subsets_at_top A)" (*goal: ‹(⋀x::'b. (sum (f::'a ⇒ 'b) ⤏ x) (finite_subsets_at_top (A::'a set)) ⟹ thesis::bool) ⟹ thesis›*) unfolding summable_on_def has_sum_def (*goal: ‹(⋀x. (sum f ⤏ x) (finite_subsets_at_top A) ⟹ thesis) ⟹ thesis›*) by auto define F' where "F' = F∩A" with assms (*‹f summable_on A› ‹finite F›*) have "finite F'" and "A-F = A-F'" apply - (*goals: 1. ‹⟦f summable_on A; finite F; F' = F ∩ A⟧ ⟹ finite F'› 2. ‹⟦f summable_on A; finite F; F' = F ∩ A⟧ ⟹ A - F = A - F'› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have "filtermap ((∪)F') (finite_subsets_at_top (A-F)) ≤ finite_subsets_at_top A" proof (rule filter_leI (*‹(⋀P. eventually P ?F' ⟹ eventually P ?F) ⟹ ?F ≤ ?F'›*)) (*goal: ‹⋀P. eventually P (finite_subsets_at_top A) ⟹ eventually P (filtermap ((∪) F') (finite_subsets_at_top (A - F)))›*) fix P assume "eventually P (finite_subsets_at_top A)" (*‹eventually (P::'a set ⇒ bool) (finite_subsets_at_top (A::'a set))›*) then obtain X where [simp]: "finite X" and XA: "X ⊆ A" and P: "∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ A ⟶ P Y" (*goal: ‹(⋀X::'a::type set. ⟦finite X; X ⊆ (A::'a::type set); ∀Y::'a::type set. finite Y ∧ X ⊆ Y ∧ Y ⊆ A ⟶ (P::'a::type set ⇒ bool) Y⟧ ⟹ thesis::bool) ⟹ thesis›*) unfolding eventually_finite_subsets_at_top (*goal: ‹(⋀X. ⟦finite X; X ⊆ A; ∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ A ⟶ P Y⟧ ⟹ thesis) ⟹ thesis›*) by auto define X' where "X' = X-F" hence [simp]: "finite X'" and [simp]: "X' ⊆ A-F" using XA (*‹X ⊆ A›*) apply - (*goals: 1. ‹⟦X' = X - F; X ⊆ A⟧ ⟹ finite X'› 2. ‹⟦X' = X - F; X ⊆ A⟧ ⟹ X' ⊆ A - F› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . hence "finite Y ∧ X' ⊆ Y ∧ Y ⊆ A - F ⟶ P (F' ∪ Y)" for Y using P (*‹∀Y::'a set. finite Y ∧ (X::'a set) ⊆ Y ∧ Y ⊆ (A::'a set) ⟶ (P::'a set ⇒ bool) Y›*) XA (*‹X ⊆ A›*) unfolding X'_def (*goal: ‹finite Y ∧ X - F ⊆ Y ∧ Y ⊆ A - F ⟶ P (F' ∪ Y)›*) using F'_def (*‹F' = F ∩ A›*) ‹finite F'› (*‹finite F'›*) by blast thus "eventually P (filtermap ((∪) F') (finite_subsets_at_top (A - F)))" unfolding eventually_filtermap eventually_finite_subsets_at_top (*goal: ‹∃X. finite X ∧ X ⊆ A - F ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ A - F ⟶ P (F' ∪ Y))›*) apply (rule_tac x=X' in exI (*‹?P ?x ⟹ ∃x. ?P x›*)) (*goal: ‹∃X. finite X ∧ X ⊆ A - F ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ A - F ⟶ P (F' ∪ Y))›*) by simp qed with lim_f (*‹(sum f ⤏ x) (finite_subsets_at_top A)›*) have "(sum f ⤏ x) (filtermap ((∪)F') (finite_subsets_at_top (A-F)))" using tendsto_mono (*‹⟦(?F::?'b filter) ≤ (?F'::?'b filter); ((?f::?'b ⇒ ?'a) ⤏ (?l::?'a)) ?F'⟧ ⟹ (?f ⤏ ?l) ?F›*) by blast have "((λG. sum f (F' ∪ G)) ⤏ x) (finite_subsets_at_top (A - F))" if "((sum f ∘ (∪) F') ⤏ x) (finite_subsets_at_top (A - F))" using that (*‹((sum f ∘ (∪) F') ⤏ x) (finite_subsets_at_top (A - F))›*) unfolding o_def (*goal: ‹((λG. sum f (F' ∪ G)) ⤏ x) (finite_subsets_at_top (A - F))›*) by auto hence "((λG. sum f (F' ∪ G)) ⤏ x) (finite_subsets_at_top (A-F))" using tendsto_compose_filtermap[symmetric] (*‹(?g ⤏ ?T) (filtermap ?f ?F) = ((?g ∘ ?f) ⤏ ?T) ?F›*) by (simp add: ‹(sum f ⤏ x) (filtermap ((∪) F') (finite_subsets_at_top (A - F)))› tendsto_compose_filtermap (*‹((?g ∘ ?f) ⤏ ?T) ?F = (?g ⤏ ?T) (filtermap ?f ?F)›*)) have "∀Y. finite Y ∧ Y ⊆ A - F ⟶ sum f (F' ∪ Y) = sum f F' + sum f Y" by (metis Diff_disjoint (*‹?A ∩ (?B - ?A) = {}›*) Int_Diff (*‹?A ∩ ?B - ?C = ?A ∩ (?B - ?C)›*) ‹A - F = A - F'› ‹finite F'› inf.orderE (*‹⟦?a ≤ ?b; ?a = inf ?a ?b ⟹ ?thesis⟧ ⟹ ?thesis›*) sum.union_disjoint (*‹⟦finite ?A; finite ?B; ?A ∩ ?B = {}⟧ ⟹ sum ?g (?A ∪ ?B) = sum ?g ?A + sum ?g ?B›*)) hence "∀⇩F x in finite_subsets_at_top (A - F). sum f (F' ∪ x) = sum f F' + sum f x" unfolding eventually_finite_subsets_at_top (*goal: ‹∃X. finite X ∧ X ⊆ A - F ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ A - F ⟶ sum f (F' ∪ Y) = sum f F' + sum f Y)›*) using exI[where x = "{}"] (*‹(?P::?'c1 set ⇒ bool) {} ⟹ ∃x::?'c1 set. ?P x›*) by (simp add: ‹⋀P. P {} ⟹ ∃x. P x›) hence "((λG. sum f F' + sum f G) ⤏ x) (finite_subsets_at_top (A-F))" using tendsto_cong[THEN iffD1, rotated] (*‹⟦(?f1 ⤏ ?c1) ?F1; ∀⇩F x in ?F1. ?f1 x = ?g1 x⟧ ⟹ (?g1 ⤏ ?c1) ?F1›*) ‹((λG. sum f (F' ∪ G)) ⤏ x) (finite_subsets_at_top (A - F))› (*‹((λG. sum f (F' ∪ G)) ⤏ x) (finite_subsets_at_top (A - F))›*) by fastforce hence "((λG. sum f F' + sum f G) ⤏ sum f F' + (x-sum f F')) (finite_subsets_at_top (A-F))" by simp hence "(sum f ⤏ x - sum f F') (finite_subsets_at_top (A-F))" using tendsto_add_const_iff (*‹((λx::?'b::type. (?c::?'a::topological_group_add) + (?f::?'b::type ⇒ ?'a::topological_group_add) x) ⤏ ?c + (?d::?'a::topological_group_add)) (?F::?'b::type filter) = (?f ⤏ ?d) ?F›*) by blast thus "f summable_on (A - F)" unfolding summable_on_def has_sum_def (*goal: ‹∃x. (sum f ⤏ x) (finite_subsets_at_top (A - F))›*) by auto qed lemma fixes f :: "'a ⇒ 'b::{topological_ab_group_add}" assumes ‹(f has_sum b) B› and ‹(f has_sum a) A› and AB: "A ⊆ B" shows has_sum_Diff: "(f has_sum (b - a)) (B - A)" proof (-) (*goal: ‹(f has_sum b - a) (B - A)›*) have finite_subsets1: "finite_subsets_at_top (B - A) ≤ filtermap (λF. F - A) (finite_subsets_at_top B)" proof (rule filter_leI (*‹(⋀P. eventually P ?F' ⟹ eventually P ?F) ⟹ ?F ≤ ?F'›*)) (*goal: ‹⋀P. eventually P (filtermap (λF. F - A) (finite_subsets_at_top B)) ⟹ eventually P (finite_subsets_at_top (B - A))›*) fix P assume "eventually P (filtermap (λF. F - A) (finite_subsets_at_top B))" (*‹eventually (P::'a set ⇒ bool) (filtermap (λF::'a set. F - (A::'a set)) (finite_subsets_at_top (B::'a set)))›*) then obtain X where "finite X" and "X ⊆ B" and P: "finite Y ∧ X ⊆ Y ∧ Y ⊆ B ⟶ P (Y - A)" for Y (*goal: ‹(⋀X. ⟦finite X; X ⊆ B; ⋀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ B ⟶ P (Y - A)⟧ ⟹ thesis) ⟹ thesis›*) unfolding eventually_filtermap eventually_finite_subsets_at_top (*goal: ‹(⋀X. ⟦finite X; X ⊆ B; ⋀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ B ⟶ P (Y - A)⟧ ⟹ thesis) ⟹ thesis›*) by auto hence "finite (X-A)" and "X-A ⊆ B - A" apply - (*goals: 1. ‹⟦finite X; X ⊆ B; ⋀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ B ⟶ P (Y - A)⟧ ⟹ finite (X - A)› 2. ‹⟦finite X; X ⊆ B; ⋀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ B ⟶ P (Y - A)⟧ ⟹ X - A ⊆ B - A› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . moreover have "finite Y ∧ X-A ⊆ Y ∧ Y ⊆ B - A ⟶ P Y" for Y using P[where Y = "Y∪X"] (*‹finite (Y ∪ X) ∧ X ⊆ Y ∪ X ∧ Y ∪ X ⊆ B ⟶ P (Y ∪ X - A)›*) ‹finite X› (*‹finite X›*) ‹X ⊆ B› (*‹X ⊆ B›*) by (metis Diff_subset (*‹?A - ?B ⊆ ?A›*) Int_Diff (*‹?A ∩ ?B - ?C = ?A ∩ (?B - ?C)›*) Un_Diff (*‹?A ∪ ?B - ?C = ?A - ?C ∪ (?B - ?C)›*) finite_Un (*‹finite (?F ∪ ?G) = (finite ?F ∧ finite ?G)›*) inf.orderE (*‹⟦?a ≤ ?b; ?a = inf ?a ?b ⟹ ?thesis⟧ ⟹ ?thesis›*) le_sup_iff (*‹(sup ?x ?y ≤ ?z) = (?x ≤ ?z ∧ ?y ≤ ?z)›*) sup.orderE (*‹⟦?b ≤ ?a; ?a = sup ?a ?b ⟹ ?thesis⟧ ⟹ ?thesis›*) sup_ge2 (*‹?y ≤ sup ?x ?y›*)) ultimately show "eventually P (finite_subsets_at_top (B - A))" unfolding eventually_finite_subsets_at_top (*goal: ‹∃X. finite X ∧ X ⊆ B - A ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ B - A ⟶ P Y)›*) by meson qed have finite_subsets2: "filtermap (λF. F ∩ A) (finite_subsets_at_top B) ≤ finite_subsets_at_top A" apply (rule filter_leI (*‹(⋀P. eventually P ?F' ⟹ eventually P ?F) ⟹ ?F ≤ ?F'›*)) (*goal: ‹filtermap (λF. F ∩ A) (finite_subsets_at_top B) ≤ finite_subsets_at_top A›*) using assms (*‹((f::'a ⇒ 'b) has_sum (b::'b)) (B::'a set)› ‹(f has_sum a) A› ‹A ⊆ B›*) unfolding eventually_filtermap eventually_finite_subsets_at_top (*goal: ‹⋀P. ∃X. finite X ∧ X ⊆ A ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ A ⟶ P Y) ⟹ ∃X. finite X ∧ X ⊆ B ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ B ⟶ P (Y ∩ A))›*) by (metis Int_subset_iff (*‹(?C ⊆ ?A ∩ ?B) = (?C ⊆ ?A ∧ ?C ⊆ ?B)›*) finite_Int (*‹finite ?F ∨ finite ?G ⟹ finite (?F ∩ ?G)›*) inf_le2 (*‹inf ?x ?y ≤ ?y›*) subset_trans (*‹⟦?A ⊆ ?B; ?B ⊆ ?C⟧ ⟹ ?A ⊆ ?C›*)) from assms(1) (*‹(f has_sum b) B›*) have limB: "(sum f ⤏ b) (finite_subsets_at_top B)" using has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*) by auto from assms(2) (*‹((f::'a::type ⇒ 'b::topological_ab_group_add) has_sum (a::'b::topological_ab_group_add)) (A::'a::type set)›*) have limA: "(sum f ⤏ a) (finite_subsets_at_top A)" using has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*) by blast have "((λF. sum f (F∩A)) ⤏ a) (finite_subsets_at_top B)" proof (subst asm_rl [of "(λF. sum f (F∩A)) = sum f ∘ (λF. F∩A)"] (*‹(λF. sum f (F ∩ A)) = sum f ∘ (λF. F ∩ A) ⟹ (λF. sum f (F ∩ A)) = sum f ∘ (λF. F ∩ A)›*)) (*goals: 1. ‹(λF. sum f (F ∩ A)) = sum f ∘ (λF. F ∩ A)› 2. ‹((sum f ∘ (λF. F ∩ A)) ⤏ a) (finite_subsets_at_top B)›*) show "(λF. sum f (F ∩ A)) = sum f ∘ (λF. F ∩ A)" unfolding o_def (*goal: ‹(λF. sum f (F ∩ A)) = (λx. sum f (x ∩ A))›*) by auto show "((sum f ∘ (λF. F ∩ A)) ⤏ a) (finite_subsets_at_top B)" unfolding o_def (*goal: ‹((λx::'a::type set. sum (f::'a::type ⇒ 'b::topological_ab_group_add) (x ∩ (A::'a::type set))) ⤏ (a::'b::topological_ab_group_add)) (finite_subsets_at_top (B::'a::type set))›*) using tendsto_compose_filtermap (*‹((?g ∘ ?f) ⤏ ?T) ?F = (?g ⤏ ?T) (filtermap ?f ?F)›*) finite_subsets2 (*‹filtermap (λF::'a set. F ∩ (A::'a set)) (finite_subsets_at_top (B::'a set)) ≤ finite_subsets_at_top A›*) limA (*‹(sum f ⤏ a) (finite_subsets_at_top A)›*) tendsto_mono (*‹⟦?F ≤ ?F'; (?f ⤏ ?l) ?F'⟧ ⟹ (?f ⤏ ?l) ?F›*) ‹(λF. sum f (F ∩ A)) = sum f ∘ (λF. F ∩ A)› (*‹(λF. sum f (F ∩ A)) = sum f ∘ (λF. F ∩ A)›*) by fastforce qed with limB (*‹(sum f ⤏ b) (finite_subsets_at_top B)›*) have "((λF. sum f F - sum f (F∩A)) ⤏ b - a) (finite_subsets_at_top B)" using tendsto_diff (*‹⟦(?f ⤏ ?a) ?F; (?g ⤏ ?b) ?F⟧ ⟹ ((λx. ?f x - ?g x) ⤏ ?a - ?b) ?F›*) by blast have "sum f X - sum f (X ∩ A) = sum f (X - A)" if "finite X" and "X ⊆ B" for X :: "'a set" using that (*‹finite X› ‹X ⊆ B›*) by (metis add_diff_cancel_left' (*‹?a + ?b - ?a = ?b›*) sum.Int_Diff (*‹finite ?A ⟹ sum ?g ?A = sum ?g (?A ∩ ?B) + sum ?g (?A - ?B)›*)) hence "∀⇩F x in finite_subsets_at_top B. sum f x - sum f (x ∩ A) = sum f (x - A)" apply (rule eventually_finite_subsets_at_top_weakI (*‹(⋀X. ⟦finite X; X ⊆ ?A⟧ ⟹ ?P X) ⟹ eventually ?P (finite_subsets_at_top ?A)›*)) (*goals: 1. ‹⋀x. ⟦finite x; x ⊆ B⟧ ⟹ finite x› 2. ‹⋀x. ⟦finite x; x ⊆ B⟧ ⟹ x ⊆ B› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) hence "((λF. sum f (F-A)) ⤏ b - a) (finite_subsets_at_top B)" using tendsto_cong[THEN iffD1, rotated] (*‹⟦(?f1 ⤏ ?c1) ?F1; ∀⇩F x in ?F1. ?f1 x = ?g1 x⟧ ⟹ (?g1 ⤏ ?c1) ?F1›*) ‹((λF. sum f F - sum f (F ∩ A)) ⤏ b - a) (finite_subsets_at_top B)› (*‹((λF::'a::type set. sum (f::'a::type ⇒ 'b::topological_ab_group_add) F - sum f (F ∩ (A::'a::type set))) ⤏ (b::'b::topological_ab_group_add) - (a::'b::topological_ab_group_add)) (finite_subsets_at_top (B::'a::type set))›*) by fastforce hence "(sum f ⤏ b - a) (filtermap (λF. F-A) (finite_subsets_at_top B))" apply (subst tendsto_compose_filtermap[symmetric] (*‹(?g ⤏ ?T) (filtermap ?f ?F) = ((?g ∘ ?f) ⤏ ?T) ?F›*)) (*goal: ‹(sum f ⤏ b - a) (filtermap (λF. F - A) (finite_subsets_at_top B))›*) by (simp add: o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*)) thus "?thesis" (*goal: ‹((f::'a ⇒ 'b) has_sum (b::'b) - (a::'b)) ((B::'a set) - (A::'a set))›*) using finite_subsets1 (*‹finite_subsets_at_top (B - A) ≤ filtermap (λF. F - A) (finite_subsets_at_top B)›*) has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*) tendsto_mono (*‹⟦?F ≤ ?F'; (?f ⤏ ?l) ?F'⟧ ⟹ (?f ⤏ ?l) ?F›*) by blast qed lemma fixes f :: "'a ⇒ 'b::{topological_ab_group_add}" assumes "f summable_on B" and "f summable_on A" and "A ⊆ B" shows summable_on_Diff: "f summable_on (B-A)" by (meson assms (*‹f summable_on B› ‹f summable_on A› ‹A ⊆ B›*) summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*) has_sum_Diff (*‹⟦(?f has_sum ?b) ?B; (?f has_sum ?a) ?A; ?A ⊆ ?B⟧ ⟹ (?f has_sum ?b - ?a) (?B - ?A)›*)) lemma fixes f :: "'a ⇒ 'b::{topological_ab_group_add,t2_space}" assumes "f summable_on B" and "f summable_on A" and AB: "A ⊆ B" shows infsum_Diff: "infsum f (B - A) = infsum f B - infsum f A" by (metis AB (*‹A ⊆ B›*) assms (*‹f summable_on B› ‹f summable_on A› ‹A ⊆ B›*) has_sum_Diff (*‹⟦(?f has_sum ?b) ?B; (?f has_sum ?a) ?A; ?A ⊆ ?B⟧ ⟹ (?f has_sum ?b - ?a) (?B - ?A)›*) infsumI (*‹(?f has_sum ?x) ?A ⟹ infsum ?f ?A = ?x›*) summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*)) lemma has_sum_mono_neutral: fixes f :: "'a⇒'b::{ordered_comm_monoid_add,linorder_topology}" (* Does this really require a linorder topology? (Instead of order topology.) *) assumes ‹(f has_sum a) A› and "(g has_sum b) B" assumes ‹⋀x. x ∈ A∩B ⟹ f x ≤ g x› assumes ‹⋀x. x ∈ A-B ⟹ f x ≤ 0› assumes ‹⋀x. x ∈ B-A ⟹ g x ≥ 0› shows "a ≤ b" proof (-) (*goal: ‹a ≤ b›*) define f' and g' where "f' x = (if x ∈ A then f x else 0)" and "g' x = (if x ∈ B then g x else 0)" for x have [simp]: "f summable_on A" "g summable_on B" using assms(1,2) (*‹((f::'a ⇒ 'b) has_sum (a::'b)) (A::'a set)› ‹(g has_sum b) B›*) summable_on_def (*‹(?f::?'a ⇒ ?'b) summable_on (?A::?'a set) ≡ ∃x::?'b. (?f has_sum x) ?A›*) apply - (*goals: 1. ‹⟦(f has_sum a) A; (g has_sum b) B; ⋀f A. f summable_on A ≡ ∃x. (f has_sum x) A⟧ ⟹ f summable_on A› 2. ‹⟦(f has_sum a) A; (g has_sum b) B; ⋀f A. f summable_on A ≡ ∃x. (f has_sum x) A⟧ ⟹ g summable_on B› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have "(f' has_sum a) (A∪B)" by (smt (verit, best) DiffE (*‹⟦(?c::?'a::type) ∈ (?A::?'a::type set) - (?B::?'a::type set); ⟦?c ∈ ?A; ?c ∉ ?B⟧ ⟹ ?P::bool⟧ ⟹ ?P›*) IntE (*‹⟦(?c::?'a::type) ∈ (?A::?'a::type set) ∩ (?B::?'a::type set); ⟦?c ∈ ?A; ?c ∈ ?B⟧ ⟹ ?P::bool⟧ ⟹ ?P›*) Un_iff (*‹((?c::?'a::type) ∈ (?A::?'a::type set) ∪ (?B::?'a::type set)) = (?c ∈ ?A ∨ ?c ∈ ?B)›*) f'_def (*‹(f'::'a::type ⇒ 'b::{ordered_comm_monoid_add,linorder_topology}) (?x::'a::type) = (if ?x ∈ (A::'a::type set) then (f::'a::type ⇒ 'b::{ordered_comm_monoid_add,linorder_topology}) ?x else (0::'b::{ordered_comm_monoid_add,linorder_topology}))›*) assms( (*‹((f::'a::type ⇒ 'b::{ordered_comm_monoid_add,linorder_topology}) has_sum (a::'b::{ordered_comm_monoid_add,linorder_topology})) (A::'a::type set)›*) 1) has_sum_cong_neutral (*‹⟦⋀x::?'a::type. x ∈ (?T::?'a::type set) - (?S::?'a::type set) ⟹ (?g::?'a::type ⇒ ?'b::{comm_monoid_add,topological_space}) x = (0::?'b::{comm_monoid_add,topological_space}); ⋀x::?'a::type. x ∈ ?S - ?T ⟹ (?f::?'a::type ⇒ ?'b::{comm_monoid_add,topological_space}) x = (0::?'b::{comm_monoid_add,topological_space}); ⋀x::?'a::type. x ∈ ?S ∩ ?T ⟹ ?f x = ?g x⟧ ⟹ (?f has_sum (?x::?'b::{comm_monoid_add,topological_space})) ?S = (?g has_sum ?x) ?T›*)) then have f'_lim: "(sum f' ⤏ a) (finite_subsets_at_top (A∪B))" by (meson has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*)) have "(g' has_sum b) (A∪B)" by (smt (verit, best) DiffD1 (*‹?c ∈ ?A - ?B ⟹ ?c ∈ ?A›*) DiffD2 (*‹⟦?c ∈ ?A - ?B; ?c ∈ ?B⟧ ⟹ ?P›*) IntE (*‹⟦?c ∈ ?A ∩ ?B; ⟦?c ∈ ?A; ?c ∈ ?B⟧ ⟹ ?P⟧ ⟹ ?P›*) UnCI (*‹(?c ∉ ?B ⟹ ?c ∈ ?A) ⟹ ?c ∈ ?A ∪ ?B›*) g'_def (*‹g' ?x = (if ?x ∈ B then g ?x else 0)›*) assms( (*‹(g has_sum b) B›*) 2) has_sum_cong_neutral (*‹⟦⋀x. x ∈ ?T - ?S ⟹ ?g x = 0; ⋀x. x ∈ ?S - ?T ⟹ ?f x = 0; ⋀x. x ∈ ?S ∩ ?T ⟹ ?f x = ?g x⟧ ⟹ (?f has_sum ?x) ?S = (?g has_sum ?x) ?T›*)) then have g'_lim: "(sum g' ⤏ b) (finite_subsets_at_top (A∪B))" using has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*) by blast have "⋀X i. ⟦X ⊆ A ∪ B; i ∈ X⟧ ⟹ f' i ≤ g' i" using assms (*‹(f has_sum a) A› ‹(g has_sum b) B› ‹(?x::'a) ∈ (A::'a set) ∩ (B::'a set) ⟹ (f::'a ⇒ 'b) ?x ≤ (g::'a ⇒ 'b) ?x› ‹?x ∈ A - B ⟹ f ?x ≤ 0› ‹?x ∈ B - A ⟹ 0 ≤ g ?x›*) by (auto simp: f'_def (*‹(f'::'a::type ⇒ 'b::{ordered_comm_monoid_add,linorder_topology}) (?x::'a::type) = (if ?x ∈ (A::'a::type set) then (f::'a::type ⇒ 'b::{ordered_comm_monoid_add,linorder_topology}) ?x else (0::'b::{ordered_comm_monoid_add,linorder_topology}))›*) g'_def (*‹(g'::'a::type ⇒ 'b::{ordered_comm_monoid_add,linorder_topology}) (?x::'a::type) = (if ?x ∈ (B::'a::type set) then (g::'a::type ⇒ 'b::{ordered_comm_monoid_add,linorder_topology}) ?x else (0::'b::{ordered_comm_monoid_add,linorder_topology}))›*)) then have "∀⇩F x in finite_subsets_at_top (A ∪ B). sum f' x ≤ sum g' x" by (intro eventually_finite_subsets_at_top_weakI (*‹(⋀X. ⟦finite X; X ⊆ ?A⟧ ⟹ ?P X) ⟹ eventually ?P (finite_subsets_at_top ?A)›*) sum_mono (*‹(⋀i. i ∈ ?K ⟹ ?f i ≤ ?g i) ⟹ sum ?f ?K ≤ sum ?g ?K›*)) then show "?thesis" (*goal: ‹a ≤ b›*) using f'_lim (*‹(sum (f'::'a ⇒ 'b) ⤏ (a::'b)) (finite_subsets_at_top ((A::'a set) ∪ (B::'a set)))›*) finite_subsets_at_top_neq_bot (*‹finite_subsets_at_top (?A::?'a set) ≠ bot›*) g'_lim (*‹(sum g' ⤏ b) (finite_subsets_at_top (A ∪ B))›*) tendsto_le (*‹⟦?F ≠ bot; (?f ⤏ ?x) ?F; (?g ⤏ ?y) ?F; ∀⇩F x in ?F. ?g x ≤ ?f x⟧ ⟹ ?y ≤ ?x›*) by blast qed lemma infsum_mono_neutral: fixes f :: "'a⇒'b::{ordered_comm_monoid_add,linorder_topology}" assumes "f summable_on A" and "g summable_on B" assumes ‹⋀x. x ∈ A∩B ⟹ f x ≤ g x› assumes ‹⋀x. x ∈ A-B ⟹ f x ≤ 0› assumes ‹⋀x. x ∈ B-A ⟹ g x ≥ 0› shows "infsum f A ≤ infsum g B" by (smt (verit, best) assms (*‹f summable_on A› ‹g summable_on B› ‹?x ∈ A ∩ B ⟹ f ?x ≤ g ?x› ‹?x ∈ A - B ⟹ f ?x ≤ 0› ‹?x ∈ B - A ⟹ 0 ≤ g ?x›*) has_sum_infsum (*‹?f summable_on ?S ⟹ (?f has_sum infsum ?f ?S) ?S›*) has_sum_mono_neutral (*‹⟦(?f has_sum ?a) ?A; (?g has_sum ?b) ?B; ⋀x. x ∈ ?A ∩ ?B ⟹ ?f x ≤ ?g x; ⋀x. x ∈ ?A - ?B ⟹ ?f x ≤ 0; ⋀x. x ∈ ?B - ?A ⟹ 0 ≤ ?g x⟧ ⟹ ?a ≤ ?b›*)) lemma has_sum_mono: fixes f :: "'a⇒'b::{ordered_comm_monoid_add,linorder_topology}" assumes "(f has_sum x) A" and "(g has_sum y) A" assumes ‹⋀x. x ∈ A ⟹ f x ≤ g x› shows "x ≤ y" using assms (*‹(f has_sum x) A› ‹((g::'a::type ⇒ 'b::{ordered_comm_monoid_add,linorder_topology}) has_sum (y::'b::{ordered_comm_monoid_add,linorder_topology})) (A::'a::type set)› ‹?x ∈ A ⟹ f ?x ≤ g ?x›*) has_sum_mono_neutral (*‹⟦((?f::?'a::type ⇒ ?'b::{ordered_comm_monoid_add,linorder_topology}) has_sum (?a::?'b::{ordered_comm_monoid_add,linorder_topology})) (?A::?'a::type set); ((?g::?'a::type ⇒ ?'b::{ordered_comm_monoid_add,linorder_topology}) has_sum (?b::?'b::{ordered_comm_monoid_add,linorder_topology})) (?B::?'a::type set); ⋀x::?'a::type. x ∈ ?A ∩ ?B ⟹ ?f x ≤ ?g x; ⋀x::?'a::type. x ∈ ?A - ?B ⟹ ?f x ≤ (0::?'b::{ordered_comm_monoid_add,linorder_topology}); ⋀x::?'a::type. x ∈ ?B - ?A ⟹ (0::?'b::{ordered_comm_monoid_add,linorder_topology}) ≤ ?g x⟧ ⟹ ?a ≤ ?b›*) by force lemma infsum_mono: fixes f :: "'a⇒'b::{ordered_comm_monoid_add,linorder_topology}" assumes "f summable_on A" and "g summable_on A" assumes ‹⋀x. x ∈ A ⟹ f x ≤ g x› shows "infsum f A ≤ infsum g A" by (meson assms (*‹f summable_on A› ‹g summable_on A› ‹?x ∈ A ⟹ f ?x ≤ g ?x›*) has_sum_infsum (*‹?f summable_on ?S ⟹ (?f has_sum infsum ?f ?S) ?S›*) has_sum_mono (*‹⟦(?f has_sum ?x) ?A; (?g has_sum ?y) ?A; ⋀x. x ∈ ?A ⟹ ?f x ≤ ?g x⟧ ⟹ ?x ≤ ?y›*)) lemma has_sum_finite[simp]: assumes "finite F" shows "(f has_sum (sum f F)) F" using assms (*‹finite F›*) by (auto intro: tendsto_Lim (*‹⟦(?net::?'a filter) ≠ bot; ((?f::?'a ⇒ ?'b) ⤏ (?l::?'b)) ?net⟧ ⟹ Lim ?net ?f = ?l›*) simp: finite_subsets_at_top_finite (*‹finite (?A::?'a set) ⟹ finite_subsets_at_top ?A = principal {?A}›*) infsum_def (*‹infsum (?f::?'a ⇒ ?'b) (?A::?'a set) = (if ?f summable_on ?A then Lim (finite_subsets_at_top ?A) (sum ?f) else (0::?'b))›*) has_sum_def (*‹((?f::?'a ⇒ ?'b) has_sum (?x::?'b)) (?A::?'a set) ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*) principal_eq_bot_iff (*‹(principal (?X::?'a set) = bot) = (?X = {})›*)) lemma summable_on_finite[simp]: fixes f :: ‹'a ⇒ 'b::{comm_monoid_add,topological_space}› assumes "finite F" shows "f summable_on F" using assms (*‹finite F›*) summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*) has_sum_finite (*‹finite ?F ⟹ (?f has_sum sum ?f ?F) ?F›*) by blast lemma infsum_finite[simp]: assumes "finite F" shows "infsum f F = sum f F" by (simp add: assms (*‹finite F›*) infsumI (*‹(?f has_sum ?x) ?A ⟹ infsum ?f ?A = ?x›*)) lemma has_sum_finite_approximation: fixes f :: "'a ⇒ 'b::{comm_monoid_add,metric_space}" assumes "(f has_sum x) A" and "ε > 0" shows "∃F. finite F ∧ F ⊆ A ∧ dist (sum f F) x ≤ ε" proof (-) (*goal: ‹∃F. finite F ∧ F ⊆ A ∧ dist (sum f F) x ≤ ε›*) have "(sum f ⤏ x) (finite_subsets_at_top A)" by (meson assms( (*‹(f has_sum x) A›*) 1) has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*)) hence "*": "∀⇩F F in (finite_subsets_at_top A). dist (sum f F) x < ε" using assms(2) (*‹0 < ε›*) by (rule tendstoD (*‹⟦(?f ⤏ ?l) ?F; 0 < ?e⟧ ⟹ ∀⇩F x in ?F. dist (?f x) ?l < ?e›*)) thus "?thesis" (*goal: ‹∃F. finite F ∧ F ⊆ A ∧ dist (sum f F) x ≤ ε›*) unfolding eventually_finite_subsets_at_top (*goal: ‹∃F::'a::type set. finite F ∧ F ⊆ (A::'a::type set) ∧ dist (sum (f::'a::type ⇒ 'b::{comm_monoid_add,metric_space}) F) (x::'b::{comm_monoid_add,metric_space}) ≤ (ε::real)›*) by fastforce qed lemma infsum_finite_approximation: fixes f :: "'a ⇒ 'b::{comm_monoid_add,metric_space}" assumes "f summable_on A" and "ε > 0" shows "∃F. finite F ∧ F ⊆ A ∧ dist (sum f F) (infsum f A) ≤ ε" proof (-) (*goal: ‹∃F. finite F ∧ F ⊆ A ∧ dist (sum f F) (infsum f A) ≤ ε›*) from assms (*‹f summable_on A› ‹0 < ε›*) have "(f has_sum (infsum f A)) A" by (simp add: summable_iff_has_sum_infsum (*‹(?f summable_on ?A) = (?f has_sum infsum ?f ?A) ?A›*)) from this (*‹(f has_sum infsum f A) A›*) ‹ε > 0› (*‹0 < ε›*) show "?thesis" (*goal: ‹∃F. finite F ∧ F ⊆ A ∧ dist (sum f F) (infsum f A) ≤ ε›*) by (rule has_sum_finite_approximation (*‹⟦((?f::?'a::type ⇒ ?'b::{comm_monoid_add,metric_space}) has_sum (?x::?'b::{comm_monoid_add,metric_space})) (?A::?'a::type set); (0::real) < (?ε::real)⟧ ⟹ ∃F::?'a::type set. finite F ∧ F ⊆ ?A ∧ dist (sum ?f F) ?x ≤ ?ε›*)) qed lemma abs_summable_summable: fixes f :: ‹'a ⇒ 'b :: banach› assumes ‹f abs_summable_on A› shows ‹f summable_on A› proof (-) (*goal: ‹f summable_on A›*) from assms (*‹f abs_summable_on A›*) obtain L where lim: "(sum (λx. norm (f x)) ⤏ L) (finite_subsets_at_top A)" (*goal: ‹(⋀L. (sum (λx. norm (f x)) ⤏ L) (finite_subsets_at_top A) ⟹ thesis) ⟹ thesis›*) unfolding has_sum_def summable_on_def (*goal: ‹(⋀L. (sum (λx. norm (f x)) ⤏ L) (finite_subsets_at_top A) ⟹ thesis) ⟹ thesis›*) by blast then have "*": "cauchy_filter (filtermap (sum (λx. norm (f x))) (finite_subsets_at_top A))" by (auto intro!: nhds_imp_cauchy_filter (*‹?F ≤ nhds ?x ⟹ cauchy_filter ?F›*) simp: filterlim_def (*‹filterlim ?f ?F2.0 ?F1.0 = (filtermap ?f ?F1.0 ≤ ?F2.0)›*)) have "∃P. eventually P (finite_subsets_at_top A) ∧ (∀F F'. P F ∧ P F' ⟶ dist (sum f F) (sum f F') < e)" if "e>0" for e proof (-) (*goal: ‹∃P. eventually P (finite_subsets_at_top A) ∧ (∀F F'. P F ∧ P F' ⟶ dist (sum f F) (sum f F') < e)›*) define d and P where "d = e/4" and "P F ⟷ finite F ∧ F ⊆ A ∧ dist (sum (λx. norm (f x)) F) L < d" for F then have "d > 0" by (simp add: d_def (*‹d = e / 4›*) that (*‹0 < e›*)) have ev_P: "eventually P (finite_subsets_at_top A)" using lim (*‹(sum (λx::'a. norm ((f::'a ⇒ 'b) x)) ⤏ (L::real)) (finite_subsets_at_top (A::'a set))›*) by (auto simp add: P_def[abs_def] (*‹P ≡ λF. finite F ∧ F ⊆ A ∧ dist (∑x∈F. norm (f x)) L < d›*) ‹0 < d› eventually_conj_iff (*‹(∀⇩F x in ?F. ?P x ∧ ?Q x) = (eventually ?P ?F ∧ eventually ?Q ?F)›*) eventually_finite_subsets_at_top_weakI (*‹(⋀X. ⟦finite X; X ⊆ ?A⟧ ⟹ ?P X) ⟹ eventually ?P (finite_subsets_at_top ?A)›*) tendsto_iff (*‹(?f ⤏ ?l) ?F = (∀e>0. ∀⇩F x in ?F. dist (?f x) ?l < e)›*)) moreover have "dist (sum f F1) (sum f F2) < e" if "P F1" and "P F2" for F1 and F2 proof (-) (*goal: ‹dist (sum f F1) (sum f F2) < e›*) from ev_P (*‹eventually P (finite_subsets_at_top A)›*) obtain F' where "finite F'" and "F' ⊆ A" and P_sup_F': "finite F ∧ F ⊇ F' ∧ F ⊆ A ⟹ P F" for F (*goal: ‹(⋀F'. ⟦finite F'; F' ⊆ A; ⋀F. finite F ∧ F' ⊆ F ∧ F ⊆ A ⟹ P F⟧ ⟹ thesis) ⟹ thesis›*) apply atomize_elim (*goal: ‹(⋀F'. ⟦finite F'; F' ⊆ A; ⋀F. finite F ∧ F' ⊆ F ∧ F ⊆ A ⟹ P F⟧ ⟹ thesis) ⟹ thesis›*) by (simp add: eventually_finite_subsets_at_top (*‹eventually ?P (finite_subsets_at_top ?A) = (∃X. finite X ∧ X ⊆ ?A ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ ?A ⟶ ?P Y))›*)) define F where "F = F' ∪ F1 ∪ F2" have "finite F" and "F ⊆ A" using F_def (*‹(F::'a::type set) = (F'::'a::type set) ∪ (F1::'a::type set) ∪ (F2::'a::type set)›*) P_def[abs_def] (*‹P ≡ λF. finite F ∧ F ⊆ A ∧ dist (∑x∈F. norm (f x)) L < d›*) that (*‹P F1› ‹(P::'a set ⇒ bool) (F2::'a set)›*) ‹finite F'› (*‹finite F'›*) ‹F' ⊆ A› (*‹F' ⊆ A›*) apply - (*goals: 1. ‹⟦F = F' ∪ F1 ∪ F2; P ≡ λF. finite F ∧ F ⊆ A ∧ dist (∑x∈F. norm (f x)) L < d; P F1; P F2; finite F'; F' ⊆ A⟧ ⟹ finite F› 2. ‹⟦F = F' ∪ F1 ∪ F2; P ≡ λF. finite F ∧ F ⊆ A ∧ dist (∑x∈F. norm (f x)) L < d; P F1; P F2; finite F'; F' ⊆ A⟧ ⟹ F ⊆ A› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have dist_F: "dist (sum (λx. norm (f x)) F) L < d" by (metis F_def (*‹F = F' ∪ F1 ∪ F2›*) ‹F ⊆ A› P_def (*‹P ?F = (finite ?F ∧ ?F ⊆ A ∧ dist (∑x∈?F. norm (f x)) L < d)›*) P_sup_F' (*‹finite ?F ∧ F' ⊆ ?F ∧ ?F ⊆ A ⟹ P ?F›*) ‹finite F› le_supE (*‹⟦sup ?a ?b ≤ ?x; ⟦?a ≤ ?x; ?b ≤ ?x⟧ ⟹ ?P⟧ ⟹ ?P›*) order_refl (*‹?x ≤ ?x›*)) have dist_F_subset: "dist (sum f F) (sum f F') < 2*d" if F': "F' ⊆ F" "P F'" for F' proof (-) (*goal: ‹dist (sum f F) (sum f F') < 2 * d›*) have "dist (sum f F) (sum f F') = norm (sum f (F-F'))" unfolding dist_norm (*goal: ‹norm (sum (f::'a ⇒ 'b) (F::'a set) - sum f (F'::'a set)) = norm (sum f (F - F'))›*) using ‹finite F› (*‹finite F›*) F' (*‹(F'::'a set) ⊆ (F::'a set)› ‹P F'›*) apply (subst sum_diff (*‹⟦finite ?A; ?B ⊆ ?A⟧ ⟹ sum ?f (?A - ?B) = sum ?f ?A - sum ?f ?B›*)) (*goals: 1. ‹⟦finite F; F' ⊆ F; P F'⟧ ⟹ finite F› 2. ‹⟦finite F; F' ⊆ F; P F'⟧ ⟹ F' ⊆ F› 3. ‹⟦finite F; F' ⊆ F; P F'⟧ ⟹ norm (sum f F - sum f F') = norm (sum f F - sum f F')› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . also (*calculation: ‹dist (sum f F) (sum f F') = norm (sum f (F - F'))›*) have "… ≤ norm (∑x∈F-F'. norm (f x))" apply (rule order.trans[OF sum_norm_le[OF order.refl]] (*‹(∑x::?'b1::type∈(?S1::?'b1::type set). norm ((?f1::?'b1::type ⇒ ?'a1::real_normed_vector) x)) ≤ (?c::real) ⟹ norm (sum ?f1 ?S1) ≤ ?c›*)) (*goal: ‹norm (sum f (F - F')) ≤ norm (∑x∈F - F'. norm (f x))›*) by auto also (*calculation: ‹dist (sum f F) (sum f F') ≤ norm (∑x∈F - F'. norm (f x))›*) have "… = dist (∑x∈F. norm (f x)) (∑x∈F'. norm (f x))" unfolding dist_norm (*goal: ‹norm (∑x∈F - F'. norm (f x)) = norm ((∑x∈F. norm (f x)) - (∑x∈F'. norm (f x)))›*) using ‹finite F› (*‹finite F›*) F' (*‹F' ⊆ F› ‹(P::'a set ⇒ bool) (F'::'a set)›*) apply (subst sum_diff (*‹⟦finite ?A; ?B ⊆ ?A⟧ ⟹ sum ?f (?A - ?B) = sum ?f ?A - sum ?f ?B›*)) (*goals: 1. ‹⟦finite F; F' ⊆ F; P F'⟧ ⟹ finite F› 2. ‹⟦finite F; F' ⊆ F; P F'⟧ ⟹ F' ⊆ F› 3. ‹⟦finite F; F' ⊆ F; P F'⟧ ⟹ norm ((∑x∈F. norm (f x)) - (∑x∈F'. norm (f x))) = norm ((∑x∈F. norm (f x)) - (∑x∈F'. norm (f x)))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . also (*calculation: ‹dist (sum (f::'a::type ⇒ 'b::banach) (F::'a::type set)) (sum f (F'::'a::type set)) ≤ dist (∑x::'a::type∈F. norm (f x)) (∑x::'a::type∈F'. norm (f x))›*) have "… < 2 * d" using dist_F (*‹dist (∑x∈F. norm (f x)) L < d›*) F' (*‹F' ⊆ F› ‹P F'›*) unfolding P_def dist_norm real_norm_def (*goal: ‹¦(∑x::'a∈(F::'a set). norm ((f::'a ⇒ 'b) x)) - (∑x::'a∈(F'::'a set). norm (f x))¦ < (2::real) * (d::real)›*) by linarith finally (*calculation: ‹dist (sum f F) (sum f F') < 2 * d›*) show "dist (sum f F) (sum f F') < 2*d" . qed have "dist (sum f F1) (sum f F2) ≤ dist (sum f F) (sum f F1) + dist (sum f F) (sum f F2)" by (rule dist_triangle3 (*‹dist (?x::?'a) (?y::?'a) ≤ dist (?a::?'a) ?x + dist ?a ?y›*)) also (*calculation: ‹dist (sum f F1) (sum f F2) ≤ dist (sum f F) (sum f F1) + dist (sum f F) (sum f F2)›*) have "… < 2 * d + 2 * d" apply (intro add_strict_mono (*‹⟦(?a::?'a::strict_ordered_ab_semigroup_add) < (?b::?'a::strict_ordered_ab_semigroup_add); (?c::?'a::strict_ordered_ab_semigroup_add) < (?d::?'a::strict_ordered_ab_semigroup_add)⟧ ⟹ ?a + ?c < ?b + ?d›*) dist_F_subset (*‹⟦(?F'::'a::type set) ⊆ (F::'a::type set); (P::'a::type set ⇒ bool) ?F'⟧ ⟹ dist (sum (f::'a::type ⇒ 'b::banach) F) (sum f ?F') < (2::real) * (d::real)›*) that (*‹(P::'a::type set ⇒ bool) (F1::'a::type set)› ‹(P::'a::type set ⇒ bool) (F2::'a::type set)›*)) (*goals: 1. ‹F1 ⊆ F› 2. ‹F2 ⊆ F› discuss goal 1*) apply ((auto simp: F_def (*‹F = F' ∪ F1 ∪ F2›*))[1]) (*discuss goal 2*) apply ((auto simp: F_def (*‹F = F' ∪ F1 ∪ F2›*))[1]) (*proven 2 subgoals*) . also (*calculation: ‹dist (sum f F1) (sum f F2) < 2 * d + 2 * d›*) have "… ≤ e" by (auto simp: d_def (*‹d = e / 4›*)) finally (*calculation: ‹dist (sum f F1) (sum f F2) < e›*) show "dist (sum f F1) (sum f F2) < e" . qed then show "?thesis" (*goal: ‹∃P::'a::type set ⇒ bool. eventually P (finite_subsets_at_top (A::'a::type set)) ∧ (∀(F::'a::type set) F'::'a::type set. P F ∧ P F' ⟶ dist (sum (f::'a::type ⇒ 'b::banach) F) (sum f F') < (e::real))›*) using ev_P (*‹eventually (P::'a::type set ⇒ bool) (finite_subsets_at_top (A::'a::type set))›*) by blast qed then have "cauchy_filter (filtermap (sum f) (finite_subsets_at_top A))" by (simp add: cauchy_filter_metric_filtermap (*‹cauchy_filter (filtermap ?f ?F) = (∀e>0. ∃P. eventually P ?F ∧ (∀x y. P x ∧ P y ⟶ dist (?f x) (?f y) < e))›*)) moreover have "complete (UNIV::'b set)" by (meson Cauchy_convergent (*‹Cauchy ?X ⟹ convergent ?X›*) UNIV_I (*‹?x ∈ UNIV›*) complete_def (*‹complete ?S = (∀f. (∀n. f n ∈ ?S) ∧ Cauchy f ⟶ (∃l∈?S. f ⇢ l))›*) convergent_def (*‹convergent ?X = (∃L. ?X ⇢ L)›*)) ultimately obtain L' where "(sum f ⤏ L') (finite_subsets_at_top A)" (*goal: ‹(⋀L'::'b. (sum (f::'a ⇒ 'b) ⤏ L') (finite_subsets_at_top (A::'a set)) ⟹ thesis::bool) ⟹ thesis›*) using complete_uniform[where S = UNIV] (*‹complete UNIV = (∀F≤principal UNIV. F ≠ bot ⟶ cauchy_filter F ⟶ (∃x∈UNIV. F ≤ nhds x))›*) by (force simp add: filterlim_def (*‹filterlim (?f::?'a ⇒ ?'b) (?F2.0::?'b filter) (?F1.0::?'a filter) = (filtermap ?f ?F1.0 ≤ ?F2.0)›*)) then show "?thesis" (*goal: ‹(f::'a ⇒ 'b) summable_on (A::'a set)›*) using summable_on_def (*‹(?f::?'a ⇒ ?'b) summable_on (?A::?'a set) ≡ ∃x::?'b. (?f has_sum x) ?A›*) has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*) by blast qed text ‹The converse of @{thm [source] abs_summable_summable} does not hold: Consider the Hilbert space of square-summable sequences. Let $e_i$ denote the sequence with 1 in the $i$th position and 0 elsewhere. Let $f(i) := e_i/i$ for $i\geq1$. We have \<^term>‹¬ f abs_summable_on UNIV› because $\lVert f(i)\rVert=1/i$ and thus the sum over $\lVert f(i)\rVert$ diverges. On the other hand, we have \<^term>‹f summable_on UNIV›; the limit is the sequence with $1/i$ in the $i$th position. (We have not formalized this separating example here because to the best of our knowledge, this Hilbert space has not been formalized in Isabelle/HOL yet.)› lemma norm_has_sum_bound: fixes f :: "'b ⇒ 'a::real_normed_vector" and A :: "'b set" assumes "((λx. norm (f x)) has_sum n) A" assumes "(f has_sum a) A" shows "norm a ≤ n" proof (-) (*goal: ‹norm a ≤ n›*) have "norm a ≤ n + ε" if "ε>0" for ε proof (-) (*goal: ‹norm a ≤ n + ε›*) have "∃F. norm (a - sum f F) ≤ ε ∧ finite F ∧ F ⊆ A" using has_sum_finite_approximation[where A = A and f = f and ε = "ε"] (*‹⟦(f has_sum ?x) A; 0 < ε⟧ ⟹ ∃F. finite F ∧ F ⊆ A ∧ dist (sum f F) ?x ≤ ε›*) assms (*‹((λx. norm (f x)) has_sum n) A› ‹(f has_sum a) A›*) ‹0 < ε› (*‹0 < ε›*) by (metis dist_commute (*‹dist ?x ?y = dist ?y ?x›*) dist_norm (*‹dist ?x ?y = norm (?x - ?y)›*)) then obtain F where "norm (a - sum f F) ≤ ε" and "finite F" and "F ⊆ A" (*goal: ‹(⋀F. ⟦norm (a - sum f F) ≤ ε; finite F; F ⊆ A⟧ ⟹ thesis) ⟹ thesis›*) by (simp add: atomize_elim (*‹(⋀x. ?P x ⟹ ?Q) ≡ (∃x. ?P x ⟹ ?Q)› ‹(⟦?A; ?B⟧ ⟹ ?C) ≡ (?A ∧ ?B ⟹ ?C)› ‹(⟦?A ⟹ ?C; ?B ⟹ ?C⟧ ⟹ ?C) ≡ ((?A ∨ ?B ⟹ ?C) ⟹ ?C)› ‹(⋀B. (?A ⟹ B) ⟹ B) ≡ ?A›*)) hence "norm a ≤ norm (sum f F) + ε" by (metis add.commute (*‹?a + ?b = ?b + ?a›*) diff_add_cancel (*‹?a - ?b + ?b = ?a›*) dual_order.refl (*‹?a ≤ ?a›*) norm_triangle_mono (*‹⟦norm ?a ≤ ?r; norm ?b ≤ ?s⟧ ⟹ norm (?a + ?b) ≤ ?r + ?s›*)) also (*calculation: ‹norm a ≤ norm (sum f F) + ε›*) have "… ≤ sum (λx. norm (f x)) F + ε" using norm_sum (*‹norm (sum (?f::?'b ⇒ ?'a) (?A::?'b set)) ≤ (∑i::?'b∈?A. norm (?f i))›*) by auto also (*calculation: ‹norm a ≤ (∑x∈F. norm (f x)) + ε›*) have "… ≤ n + ε" proof (intro add_right_mono [OF has_sum_mono_neutral] (*‹⟦(?f1 has_sum ?a) ?A1; (?g1 has_sum ?b) ?B1; ⋀x. x ∈ ?A1 ∩ ?B1 ⟹ ?f1 x ≤ ?g1 x; ⋀x. x ∈ ?A1 - ?B1 ⟹ ?f1 x ≤ 0; ⋀x. x ∈ ?B1 - ?A1 ⟹ 0 ≤ ?g1 x⟧ ⟹ ?a + ?c ≤ ?b + ?c›*)) (*goals: 1. ‹((?f1::?'a1 ⇒ real) has_sum (∑x::'b∈(F::'b set). norm ((f::'b ⇒ 'a) x))) (?A1::?'a1 set)› 2. ‹((?g1::?'a1 ⇒ real) has_sum (n::real)) (?B1::?'a1 set)› 3. ‹⋀x::?'a1. x ∈ (?A1::?'a1 set) ∩ (?B1::?'a1 set) ⟹ (?f1::?'a1 ⇒ real) x ≤ (?g1::?'a1 ⇒ real) x› 4. ‹⋀x::?'a1. x ∈ (?A1::?'a1 set) - (?B1::?'a1 set) ⟹ (?f1::?'a1 ⇒ real) x ≤ (0::real)› 5. ‹⋀x::?'a1. x ∈ (?B1::?'a1 set) - (?A1::?'a1 set) ⟹ (0::real) ≤ (?g1::?'a1 ⇒ real) x›*) show "((λx. norm (f x)) has_sum (∑x∈F. norm (f x))) F" by (simp add: ‹finite F›) qed (use ‹F ⊆ A› assms in auto) (*solves the remaining goals: 1. ‹(?g1 has_sum n) ?B1› 2. ‹⋀x. x ∈ F ∩ ?B1 ⟹ norm (f x) ≤ ?g1 x› 3. ‹⋀x. x ∈ F - ?B1 ⟹ norm (f x) ≤ 0› 4. ‹⋀x. x ∈ ?B1 - F ⟹ 0 ≤ ?g1 x›*) finally (*calculation: ‹norm (a::'a) ≤ (n::real) + (ε::real)›*) show "?thesis" (*goal: ‹norm a ≤ n + ε›*) by assumption qed thus "?thesis" (*goal: ‹norm a ≤ n›*) using linordered_field_class.field_le_epsilon (*‹(⋀e. 0 < e ⟹ ?x ≤ ?y + e) ⟹ ?x ≤ ?y›*) by blast qed lemma norm_infsum_bound: fixes f :: "'b ⇒ 'a::real_normed_vector" and A :: "'b set" assumes "f abs_summable_on A" shows "norm (infsum f A) ≤ infsum (λx. norm (f x)) A" proof (cases "f summable_on A") (*goals: 1. ‹f summable_on A ⟹ norm (infsum f A) ≤ (∑⇩∞x∈A. norm (f x))› 2. ‹¬ f summable_on A ⟹ norm (infsum f A) ≤ (∑⇩∞x∈A. norm (f x))›*) case True (*‹f summable_on A›*) have "((λx. norm (f x)) has_sum (∑⇩∞x∈A. norm (f x))) A" by (simp add: assms (*‹(f::'b::type ⇒ 'a::real_normed_vector) abs_summable_on (A::'b::type set)›*)) then show "?thesis" (*goal: ‹norm (infsum f A) ≤ (∑⇩∞x∈A. norm (f x))›*) by (metis True (*‹f summable_on A›*) has_sum_infsum (*‹?f summable_on ?S ⟹ (?f has_sum infsum ?f ?S) ?S›*) norm_has_sum_bound (*‹⟦((λx. norm (?f x)) has_sum ?n) ?A; (?f has_sum ?a) ?A⟧ ⟹ norm ?a ≤ ?n›*)) next (*goal: ‹¬ (f::'b::type ⇒ 'a::real_normed_vector) summable_on (A::'b::type set) ⟹ norm (infsum f A) ≤ (∑⇩∞x::'b::type∈A. norm (f x))›*) case False (*‹¬ f summable_on A›*) obtain t where t_def: "(sum (λx. norm (f x)) ⤏ t) (finite_subsets_at_top A)" (*goal: ‹(⋀t. (sum (λx. norm (f x)) ⤏ t) (finite_subsets_at_top A) ⟹ thesis) ⟹ thesis›*) using assms (*‹f abs_summable_on A›*) unfolding summable_on_def has_sum_def (*goal: ‹(⋀t. (sum (λx. norm (f x)) ⤏ t) (finite_subsets_at_top A) ⟹ thesis) ⟹ thesis›*) by blast have sumpos: "sum (λx. norm (f x)) X ≥ 0" for X by (simp add: sum_nonneg (*‹(⋀x::?'b::type. x ∈ (?A::?'b::type set) ⟹ (0::?'a::ordered_comm_monoid_add) ≤ (?f::?'b::type ⇒ ?'a::ordered_comm_monoid_add) x) ⟹ (0::?'a::ordered_comm_monoid_add) ≤ sum ?f ?A›*)) have tgeq0: "t ≥ 0" proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹¬ 0 ≤ t ⟹ False›*) define S :: "real set" where "S = {s. s < 0}" assume "¬ 0 ≤ t" (*‹¬ (0::real) ≤ (t::real)›*) hence "t < 0" by simp hence "t ∈ S" unfolding S_def (*goal: ‹t ∈ {s. s < 0}›*) by blast moreover have "open S" by (metis S_def (*‹S = {s. s < 0}›*) lessThan_def (*‹{..<?u} ≡ {x. x < ?u}›*) open_real_lessThan (*‹open {..<?a}›*)) ultimately have "∀⇩F X in finite_subsets_at_top A. (∑x∈X. norm (f x)) ∈ S" using t_def (*‹(sum (λx::'b. norm ((f::'b ⇒ 'a) x)) ⤏ (t::real)) (finite_subsets_at_top (A::'b set))›*) unfolding tendsto_def (*goal: ‹∀⇩F X in finite_subsets_at_top A. (∑x∈X. norm (f x)) ∈ S›*) by blast hence "∃X. (∑x∈X. norm (f x)) ∈ S" by (metis (no_types, lifting) eventually_mono (*‹⟦eventually ?P ?F; ⋀x. ?P x ⟹ ?Q x⟧ ⟹ eventually ?Q ?F›*) filterlim_iff (*‹filterlim ?f ?F2.0 ?F1.0 = (∀P. eventually P ?F2.0 ⟶ (∀⇩F x in ?F1.0. P (?f x)))›*) finite_subsets_at_top_neq_bot (*‹finite_subsets_at_top ?A ≠ bot›*) tendsto_Lim (*‹⟦?net ≠ bot; (?f ⤏ ?l) ?net⟧ ⟹ Lim ?net ?f = ?l›*)) then obtain X where "(∑x∈X. norm (f x)) ∈ S" (*goal: ‹(⋀X. (∑x∈X. norm (f x)) ∈ S ⟹ thesis) ⟹ thesis›*) by blast hence "(∑x∈X. norm (f x)) < 0" unfolding S_def (*goal: ‹(∑x∈X. norm (f x)) < 0›*) by auto thus False by (simp add: leD (*‹?y ≤ ?x ⟹ ¬ ?x < ?y›*) sumpos (*‹0 ≤ (∑x∈?X. norm (f x))›*)) qed have "∃!h. (sum (λx. norm (f x)) ⤏ h) (finite_subsets_at_top A)" using t_def (*‹(sum (λx. norm (f x)) ⤏ t) (finite_subsets_at_top A)›*) finite_subsets_at_top_neq_bot (*‹finite_subsets_at_top ?A ≠ bot›*) tendsto_unique (*‹⟦?F ≠ bot; (?f ⤏ ?a) ?F; (?f ⤏ ?b) ?F⟧ ⟹ ?a = ?b›*) by blast hence "t = (Topological_Spaces.Lim (finite_subsets_at_top A) (sum (λx. norm (f x))))" using t_def (*‹(sum (λx::'b. norm ((f::'b ⇒ 'a) x)) ⤏ (t::real)) (finite_subsets_at_top (A::'b set))›*) unfolding Topological_Spaces.Lim_def (*goal: ‹t = (THE l. (sum (λx. norm (f x)) ⤏ l) (finite_subsets_at_top A))›*) by (metis the_equality (*‹⟦?P ?a; ⋀x. ?P x ⟹ x = ?a⟧ ⟹ (THE x. ?P x) = ?a›*)) hence "Lim (finite_subsets_at_top A) (sum (λx. norm (f x))) ≥ 0" using tgeq0 (*‹0 ≤ t›*) by blast thus "?thesis" (*goal: ‹norm (infsum f A) ≤ (∑⇩∞x∈A. norm (f x))›*) unfolding infsum_def (*goal: ‹norm (if f summable_on A then Lim (finite_subsets_at_top A) (sum f) else 0) ≤ (if f abs_summable_on A then Lim (finite_subsets_at_top A) (sum (λx. norm (f x))) else 0)›*) using False (*‹¬ f summable_on A›*) by auto qed lemma infsum_tendsto: assumes ‹f summable_on S› shows ‹((λF. sum f F) ⤏ infsum f S) (finite_subsets_at_top S)› using assms (*‹f summable_on S›*) has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*) has_sum_infsum (*‹(?f::?'a ⇒ ?'b) summable_on (?S::?'a set) ⟹ (?f has_sum infsum ?f ?S) ?S›*) by blast lemma has_sum_0: assumes ‹⋀x. x∈M ⟹ f x = 0› shows ‹(f has_sum 0) M› by (metis assms (*‹?x ∈ M ⟹ f ?x = 0›*) finite.intros( (*‹finite {}›*) 1) has_sum_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ (?f has_sum ?x) ?A = (?g has_sum ?x) ?A›*) has_sum_cong_neutral (*‹⟦⋀x. x ∈ ?T - ?S ⟹ ?g x = 0; ⋀x. x ∈ ?S - ?T ⟹ ?f x = 0; ⋀x. x ∈ ?S ∩ ?T ⟹ ?f x = ?g x⟧ ⟹ (?f has_sum ?x) ?S = (?g has_sum ?x) ?T›*) has_sum_finite (*‹finite ?F ⟹ (?f has_sum sum ?f ?F) ?F›*) sum.neutral_const (*‹(∑_∈?A. 0) = 0›*)) lemma summable_on_0: assumes ‹⋀x. x∈M ⟹ f x = 0› shows ‹f summable_on M› using assms (*‹?x ∈ M ⟹ f ?x = 0›*) summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*) has_sum_0 (*‹(⋀x::?'a::type. x ∈ (?M::?'a::type set) ⟹ (?f::?'a::type ⇒ ?'b::{comm_monoid_add,topological_space}) x = (0::?'b::{comm_monoid_add,topological_space})) ⟹ (?f has_sum (0::?'b::{comm_monoid_add,topological_space})) ?M›*) by blast lemma infsum_0: assumes ‹⋀x. x∈M ⟹ f x = 0› shows ‹infsum f M = 0› by (metis assms (*‹(?x::'a) ∈ (M::'a set) ⟹ (f::'a ⇒ 'b) ?x = (0::'b)›*) finite_subsets_at_top_neq_bot (*‹finite_subsets_at_top (?A::?'a set) ≠ bot›*) infsum_def (*‹infsum (?f::?'a ⇒ ?'b) (?A::?'a set) = (if ?f summable_on ?A then Lim (finite_subsets_at_top ?A) (sum ?f) else (0::?'b))›*) has_sum_0 (*‹(⋀x::?'a. x ∈ (?M::?'a set) ⟹ (?f::?'a ⇒ ?'b) x = (0::?'b)) ⟹ (?f has_sum (0::?'b)) ?M›*) has_sum_def (*‹((?f::?'a ⇒ ?'b) has_sum (?x::?'b)) (?A::?'a set) ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*) tendsto_Lim (*‹⟦(?net::?'a filter) ≠ bot; ((?f::?'a ⇒ ?'b) ⤏ (?l::?'b)) ?net⟧ ⟹ Lim ?net ?f = ?l›*)) text ‹Variants of @{thm [source] infsum_0} etc. suitable as simp-rules› lemma infsum_0_simp[simp]: ‹infsum (λ_. 0) M = 0› by (simp add: infsum_0 (*‹(⋀x. x ∈ ?M ⟹ ?f x = 0) ⟹ infsum ?f ?M = 0›*)) lemma summable_on_0_simp[simp]: ‹(λ_. 0) summable_on M› by (simp add: summable_on_0 (*‹(⋀x::?'a::type. x ∈ (?M::?'a::type set) ⟹ (?f::?'a::type ⇒ ?'b::{comm_monoid_add,topological_space}) x = (0::?'b::{comm_monoid_add,topological_space})) ⟹ ?f summable_on ?M›*)) lemma has_sum_0_simp[simp]: ‹((λ_. 0) has_sum 0) M› by (simp add: has_sum_0 (*‹(⋀x. x ∈ ?M ⟹ ?f x = 0) ⟹ (?f has_sum 0) ?M›*)) lemma has_sum_add: fixes f g :: "'a ⇒ 'b::{topological_comm_monoid_add}" assumes ‹(f has_sum a) A› assumes ‹(g has_sum b) A› shows ‹((λx. f x + g x) has_sum (a + b)) A› proof (-) (*goal: ‹((λx. f x + g x) has_sum a + b) A›*) from assms (*‹(f has_sum a) A› ‹((g::'a::type ⇒ 'b::topological_comm_monoid_add) has_sum (b::'b::topological_comm_monoid_add)) (A::'a::type set)›*) have lim_f: "(sum f ⤏ a) (finite_subsets_at_top A)" and lim_g: "(sum g ⤏ b) (finite_subsets_at_top A)" apply - (*goals: 1. ‹⟦(f has_sum a) A; (g has_sum b) A⟧ ⟹ (sum f ⤏ a) (finite_subsets_at_top A)› 2. ‹⟦(f has_sum a) A; (g has_sum b) A⟧ ⟹ (sum g ⤏ b) (finite_subsets_at_top A)› discuss goal 1*) apply (simp add: has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*)) (*discuss goal 2*) apply (simp add: has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*)) (*proven 2 subgoals*) . then have lim: "(sum (λx. f x + g x) ⤏ a + b) (finite_subsets_at_top A)" unfolding sum.distrib (*goal: ‹((λA. sum f A + sum g A) ⤏ a + b) (finite_subsets_at_top A)›*) by (rule tendsto_add (*‹⟦(?f ⤏ ?a) ?F; (?g ⤏ ?b) ?F⟧ ⟹ ((λx. ?f x + ?g x) ⤏ ?a + ?b) ?F›*)) then show "?thesis" (*goal: ‹((λx. f x + g x) has_sum a + b) A›*) by (simp add: has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*)) qed lemma summable_on_add: fixes f g :: "'a ⇒ 'b::{topological_comm_monoid_add}" assumes ‹f summable_on A› assumes ‹g summable_on A› shows ‹(λx. f x + g x) summable_on A› by (metis (full_types) assms (*‹f summable_on A› ‹g summable_on A›*) summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*) has_sum_add (*‹⟦(?f has_sum ?a) ?A; (?g has_sum ?b) ?A⟧ ⟹ ((λx. ?f x + ?g x) has_sum ?a + ?b) ?A›*)) lemma infsum_add: fixes f g :: "'a ⇒ 'b::{topological_comm_monoid_add, t2_space}" assumes ‹f summable_on A› assumes ‹g summable_on A› shows ‹infsum (λx. f x + g x) A = infsum f A + infsum g A› proof (-) (*goal: ‹(∑⇩∞x∈A. f x + g x) = infsum f A + infsum g A›*) have "((λx. f x + g x) has_sum (infsum f A + infsum g A)) A" by (simp add: assms (*‹f summable_on A› ‹g summable_on A›*) has_sum_add (*‹⟦(?f has_sum ?a) ?A; (?g has_sum ?b) ?A⟧ ⟹ ((λx. ?f x + ?g x) has_sum ?a + ?b) ?A›*)) then show "?thesis" (*goal: ‹(∑⇩∞x∈A. f x + g x) = infsum f A + infsum g A›*) using infsumI (*‹((?f::?'a ⇒ ?'b) has_sum (?x::?'b)) (?A::?'a set) ⟹ infsum ?f ?A = ?x›*) by blast qed lemma has_sum_Un_disjoint: fixes f :: "'a ⇒ 'b::topological_comm_monoid_add" assumes "(f has_sum a) A" assumes "(f has_sum b) B" assumes disj: "A ∩ B = {}" shows ‹(f has_sum (a + b)) (A ∪ B)› proof (-) (*goal: ‹((f::'a ⇒ 'b) has_sum (a::'b) + (b::'b)) ((A::'a set) ∪ (B::'a set))›*) define fA and fB where "fA x = (if x ∈ A then f x else 0)" and "fB x = (if x ∉ A then f x else 0)" for x have fA: "(fA has_sum a) (A ∪ B)" by (smt (verit, ccfv_SIG) DiffD1 (*‹?c ∈ ?A - ?B ⟹ ?c ∈ ?A›*) DiffD2 (*‹⟦?c ∈ ?A - ?B; ?c ∈ ?B⟧ ⟹ ?P›*) UnCI (*‹(?c ∉ ?B ⟹ ?c ∈ ?A) ⟹ ?c ∈ ?A ∪ ?B›*) fA_def (*‹fA ?x = (if ?x ∈ A then f ?x else 0)›*) assms( (*‹(f has_sum a) A›*) 1) has_sum_cong_neutral (*‹⟦⋀x. x ∈ ?T - ?S ⟹ ?g x = 0; ⋀x. x ∈ ?S - ?T ⟹ ?f x = 0; ⋀x. x ∈ ?S ∩ ?T ⟹ ?f x = ?g x⟧ ⟹ (?f has_sum ?x) ?S = (?g has_sum ?x) ?T›*) inf_sup_absorb (*‹inf ?x (sup ?x ?y) = ?x›*)) have fB: "(fB has_sum b) (A ∪ B)" by (smt (verit, best) DiffD1 (*‹?c ∈ ?A - ?B ⟹ ?c ∈ ?A›*) DiffD2 (*‹⟦?c ∈ ?A - ?B; ?c ∈ ?B⟧ ⟹ ?P›*) IntE (*‹⟦?c ∈ ?A ∩ ?B; ⟦?c ∈ ?A; ?c ∈ ?B⟧ ⟹ ?P⟧ ⟹ ?P›*) Un_iff (*‹(?c ∈ ?A ∪ ?B) = (?c ∈ ?A ∨ ?c ∈ ?B)›*) fB_def (*‹fB ?x = (if ?x ∉ A then f ?x else 0)›*) assms( (*‹(f has_sum b) B›*) 2) disj (*‹A ∩ B = {}›*) disjoint_iff (*‹(?A ∩ ?B = {}) = (∀x. x ∈ ?A ⟶ x ∉ ?B)›*) has_sum_cong_neutral (*‹⟦⋀x. x ∈ ?T - ?S ⟹ ?g x = 0; ⋀x. x ∈ ?S - ?T ⟹ ?f x = 0; ⋀x. x ∈ ?S ∩ ?T ⟹ ?f x = ?g x⟧ ⟹ (?f has_sum ?x) ?S = (?g has_sum ?x) ?T›*)) have fAB: "f x = fA x + fB x" for x unfolding fA_def fB_def (*goal: ‹(f::'a ⇒ 'b) (x::'a) = (if x ∈ (A::'a set) then f x else (0::'b)) + (if x ∉ A then f x else (0::'b))›*) by simp show "?thesis" (*goal: ‹((f::'a ⇒ 'b) has_sum (a::'b) + (b::'b)) ((A::'a set) ∪ (B::'a set))›*) unfolding fAB (*goal: ‹((λx. fA x + fB x) has_sum a + b) (A ∪ B)›*) using fA (*‹(fA has_sum a) (A ∪ B)›*) fB (*‹(fB has_sum b) (A ∪ B)›*) by (rule has_sum_add (*‹⟦(?f has_sum ?a) ?A; (?g has_sum ?b) ?A⟧ ⟹ ((λx. ?f x + ?g x) has_sum ?a + ?b) ?A›*)) qed lemma summable_on_Un_disjoint: fixes f :: "'a ⇒ 'b::topological_comm_monoid_add" assumes "f summable_on A" assumes "f summable_on B" assumes disj: "A ∩ B = {}" shows ‹f summable_on (A ∪ B)› by (meson assms (*‹f summable_on A› ‹f summable_on B› ‹A ∩ B = {}›*) disj (*‹A ∩ B = {}›*) summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*) has_sum_Un_disjoint (*‹⟦(?f has_sum ?a) ?A; (?f has_sum ?b) ?B; ?A ∩ ?B = {}⟧ ⟹ (?f has_sum ?a + ?b) (?A ∪ ?B)›*)) lemma infsum_Un_disjoint: fixes f :: "'a ⇒ 'b::{topological_comm_monoid_add, t2_space}" assumes "f summable_on A" assumes "f summable_on B" assumes disj: "A ∩ B = {}" shows ‹infsum f (A ∪ B) = infsum f A + infsum f B› by (intro infsumI (*‹(?f has_sum ?x) ?A ⟹ infsum ?f ?A = ?x›*) has_sum_Un_disjoint (*‹⟦(?f has_sum ?a) ?A; (?f has_sum ?b) ?B; ?A ∩ ?B = {}⟧ ⟹ (?f has_sum ?a + ?b) (?A ∪ ?B)›*) has_sum_infsum (*‹?f summable_on ?S ⟹ (?f has_sum infsum ?f ?S) ?S›*) assms (*‹f summable_on A› ‹f summable_on B› ‹A ∩ B = {}›*)) lemma norm_summable_imp_has_sum: fixes f :: "nat ⇒ 'a :: banach" assumes "summable (λn. norm (f n))" and "f sums S" shows "(f has_sum S) (UNIV :: nat set)" unfolding has_sum_def tendsto_iff eventually_finite_subsets_at_top (*goal: ‹∀e>0. ∃X. finite X ∧ X ⊆ UNIV ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ UNIV ⟶ dist (sum f Y) S < e)›*) proof (clarsimp) (*goal: ‹⋀e. 0 < e ⟹ ∃X. finite X ∧ (∀Y. finite Y ∧ X ⊆ Y ⟶ dist (sum f Y) S < e)›*) fix ε :: real assume "ε > 0" (*‹(0::real) < (ε::real)›*) from assms (*‹summable (λn. norm (f n))› ‹f sums S›*) obtain S' where S': "(λn. norm (f n)) sums S'" (*goal: ‹(⋀S'. (λn. norm (f n)) sums S' ⟹ thesis) ⟹ thesis›*) by (auto simp: summable_def (*‹summable ?f = (∃s. ?f sums s)›*)) with ‹ε > 0› (*‹0 < ε›*) obtain N where N: "⋀n. n ≥ N ⟹ ¦S' - (∑i<n. norm (f i))¦ < ε" (*goal: ‹(⋀N. (⋀n. N ≤ n ⟹ ¦S' - (∑i<n. norm (f i))¦ < ε) ⟹ thesis) ⟹ thesis›*) by (auto simp: tendsto_iff (*‹((?f::?'b ⇒ ?'a) ⤏ (?l::?'a)) (?F::?'b filter) = (∀e>0::real. ∀⇩F x::?'b in ?F. dist (?f x) ?l < e)›*) eventually_at_top_linorder (*‹eventually (?P::?'a ⇒ bool) at_top = (∃N::?'a. ∀n≥N. ?P n)›*) sums_def (*‹(?f::nat ⇒ ?'a) sums (?s::?'a) = (λn::nat. sum ?f {..<n}) ⇢ ?s›*) dist_norm (*‹dist (?x::?'a) (?y::?'a) = norm (?x - ?y)›*) abs_minus_commute (*‹¦(?a::?'a) - (?b::?'a)¦ = ¦?b - ?a¦›*)) have "dist (sum f Y) S < ε" if "finite Y" "{..<N} ⊆ Y" for Y proof (-) (*goal: ‹dist (sum (f::nat ⇒ 'a::banach) (Y::nat set)) (S::'a::banach) < (ε::real)›*) from that (*‹finite Y› ‹{..<N} ⊆ Y›*) have "(λn. if n ∈ Y then 0 else f n) sums (S - sum f Y)" apply (intro sums_If_finite_set'[OF ‹f sums S›] (*‹⟦finite ?A; ?S' = S + (∑n∈?A. ?f n - f n)⟧ ⟹ (λn. if n ∈ ?A then ?f n else f n) sums ?S'›*)) (*goals: 1. ‹⟦finite Y; {..<N} ⊆ Y⟧ ⟹ finite Y› 2. ‹⟦finite Y; {..<N} ⊆ Y⟧ ⟹ S - sum f Y = S + (∑n∈Y. 0 - f n)› discuss goal 1*) apply ((auto simp: sum_negf (*‹(∑x∈?A. - ?f x) = - sum ?f ?A›*))[1]) (*discuss goal 2*) apply ((auto simp: sum_negf (*‹(∑x∈?A. - ?f x) = - sum ?f ?A›*))[1]) (*proven 2 subgoals*) . hence "S - sum f Y = (∑n. if n ∈ Y then 0 else f n)" by (simp add: sums_iff (*‹?f sums ?x = (summable ?f ∧ suminf ?f = ?x)›*)) also (*calculation: ‹S - sum f Y = (∑n. if n ∈ Y then 0 else f n)›*) have "norm … ≤ (∑n. norm (if n ∈ Y then 0 else f n))" apply (rule summable_norm[OF summable_comparison_test'[OF assms(1)]] (*‹(⋀n. ?N1 ≤ n ⟹ norm (norm (?f n)) ≤ norm (f n)) ⟹ norm (suminf ?f) ≤ (∑n. norm (?f n))›*)) (*goal: ‹norm (∑n. if n ∈ Y then 0 else f n) ≤ (∑n. norm (if n ∈ Y then 0 else f n))›*) by auto also (*calculation: ‹norm (S - sum f Y) ≤ (∑n. norm (if n ∈ Y then 0 else f n))›*) have "… ≤ (∑n. if n < N then 0 else norm (f n))" using that (*‹finite (Y::nat set)› ‹{..<N::nat} ⊆ (Y::nat set)›*) apply (intro suminf_le (*‹⟦⋀n. ?f n ≤ ?g n; summable ?f; summable ?g⟧ ⟹ suminf ?f ≤ suminf ?g›*) summable_comparison_test'[OF assms(1)] (*‹(⋀n. ?N ≤ n ⟹ norm (?f n) ≤ norm (f n)) ⟹ summable ?f›*)) (*goals: 1. ‹⋀n::nat. ⟦finite (Y::nat set); {..<N::nat} ⊆ Y⟧ ⟹ norm (if n ∈ Y then 0::'a else (f::nat ⇒ 'a) n) ≤ (if n < N then 0::real else norm (f n))› 2. ‹⋀n::nat. ⟦finite (Y::nat set); {..<N::nat} ⊆ Y; (?N4::nat) ≤ n⟧ ⟹ norm (norm (if n ∈ Y then 0::'a else (f::nat ⇒ 'a) n)) ≤ norm (f n)› 3. ‹⋀n::nat. ⟦finite (Y::nat set); {..<N::nat} ⊆ Y; (?N3::nat) ≤ n⟧ ⟹ norm (if n < N then 0::real else norm ((f::nat ⇒ 'a) n)) ≤ norm (f n)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . also (*calculation: ‹norm (S - sum f Y) ≤ (∑n. if n < N then 0 else norm (f n))›*) have "(λn. if n ∈ {..<N} then 0 else norm (f n)) sums (S' - (∑i<N. norm (f i)))" apply (intro sums_If_finite_set'[OF S'] (*‹⟦finite (?A::nat set); (?S'::real) = (S'::real) + (∑n::nat∈?A. (?f::nat ⇒ real) n - norm ((f::nat ⇒ 'a::banach) n))⟧ ⟹ (λn::nat. if n ∈ ?A then ?f n else norm (f n)) sums ?S'›*)) (*goals: 1. ‹finite {..<N::nat}› 2. ‹(S'::real) - (∑i::nat<N::nat. norm ((f::nat ⇒ 'a) i)) = S' + (∑n::nat<N. (0::real) - norm (f n))› discuss goal 1*) apply ((auto simp: sum_negf (*‹(∑x∈?A. - ?f x) = - sum ?f ?A›*))[1]) (*discuss goal 2*) apply ((auto simp: sum_negf (*‹(∑x∈?A. - ?f x) = - sum ?f ?A›*))[1]) (*proven 2 subgoals*) . hence "(∑n. if n < N then 0 else norm (f n)) = S' - (∑i<N. norm (f i))" by (simp add: sums_iff (*‹?f sums ?x = (summable ?f ∧ suminf ?f = ?x)›*)) also (*calculation: ‹norm (S - sum f Y) ≤ S' - (∑i<N. norm (f i))›*) have "S' - (∑i<N. norm (f i)) ≤ ¦S' - (∑i<N. norm (f i))¦" by simp also (*calculation: ‹norm (S - sum f Y) ≤ ¦S' - (∑i<N. norm (f i))¦›*) have "… < ε" apply (rule N (*‹N ≤ ?n ⟹ ¦S' - (∑i<?n. norm (f i))¦ < ε›*)) (*goal: ‹¦S' - (∑i<N. norm (f i))¦ < ε›*) by auto finally (*calculation: ‹norm (S - sum f Y) < ε›*) show "?thesis" (*goal: ‹dist (sum f Y) S < ε›*) by (simp add: dist_norm (*‹dist ?x ?y = norm (?x - ?y)›*) norm_minus_commute (*‹norm (?a - ?b) = norm (?b - ?a)›*)) qed then show "∃X. finite X ∧ (∀Y. finite Y ∧ X ⊆ Y ⟶ dist (sum f Y) S < ε)" by (meson finite_lessThan (*‹finite {..<?k}›*) subset_UNIV (*‹?A ⊆ UNIV›*)) qed lemma norm_summable_imp_summable_on: fixes f :: "nat ⇒ 'a :: banach" assumes "summable (λn. norm (f n))" shows "f summable_on UNIV" using norm_summable_imp_has_sum[OF assms, of "suminf f"] (*‹f sums suminf f ⟹ (f has_sum suminf f) UNIV›*) assms (*‹summable (λn. norm (f n))›*) by (auto simp: sums_iff (*‹?f sums ?x = (summable ?f ∧ suminf ?f = ?x)›*) summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*) dest: summable_norm_cancel (*‹summable (λn. norm (?f n)) ⟹ summable ?f›*)) text ‹The following lemma indeed needs a complete space (as formalized by the premise \<^term>‹complete UNIV›). The following two counterexamples show this: \begin{itemize} \item Consider the real vector space $V$ of sequences with finite support, and with the $\ell_2$-norm (sum of squares). Let $e_i$ denote the sequence with a $1$ at position $i$. Let $f : \mathbb Z \to V$ be defined as $f(n) := e_{\lvert n\rvert} / n$ (with $f(0) := 0$). We have that $\sum_{n\in\mathbb Z} f(n) = 0$ (it even converges absolutely). But $\sum_{n\in\mathbb N} f(n)$ does not exist (it would converge against a sequence with infinite support). \item Let $f$ be a positive rational valued function such that $\sum_{x\in B} f(x)$ is $\sqrt 2$ and $\sum_{x\in A} f(x)$ is 1 (over the reals, with $A\subseteq B$). Then $\sum_{x\in B} f(x)$ does not exist over the rationals. But $\sum_{x\in A} f(x)$ exists. \end{itemize} The lemma also requires uniform continuity of the addition. And example of a topological group with continuous but not uniformly continuous addition would be the positive reals with the usual multiplication as the addition. We do not know whether the lemma would also hold for such topological groups.› lemma summable_on_subset_aux: fixes A B and f :: ‹'a ⇒ 'b::{ab_group_add, uniform_space}› assumes ‹complete (UNIV :: 'b set)› assumes plus_cont: ‹uniformly_continuous_on UNIV (λ(x::'b,y). x+y)› assumes ‹f summable_on A› assumes ‹B ⊆ A› shows ‹f summable_on B› proof (-) (*goal: ‹f summable_on B›*) let ?filter_fB = "filtermap (sum f) (finite_subsets_at_top B)" from ‹f summable_on A› (*‹f summable_on A›*) obtain S where "(sum f ⤏ S) (finite_subsets_at_top A)" (is "(sum f ⤏ S) ?filter_A") (*goal: ‹(⋀S. (sum f ⤏ S) (finite_subsets_at_top A) ⟹ thesis) ⟹ thesis›*) using summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*) has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*) by blast then have cauchy_fA: "cauchy_filter (filtermap (sum f) (finite_subsets_at_top A))" (is "cauchy_filter ?filter_fA") by (auto intro!: nhds_imp_cauchy_filter (*‹(?F::?'a filter) ≤ nhds (?x::?'a) ⟹ cauchy_filter ?F›*) simp: filterlim_def (*‹filterlim (?f::?'a ⇒ ?'b) (?F2.0::?'b filter) (?F1.0::?'a filter) = (filtermap ?f ?F1.0 ≤ ?F2.0)›*)) have "cauchy_filter (filtermap (sum f) (finite_subsets_at_top B))" apply (unfold cauchy_filter_def (*‹cauchy_filter ?F = (?F ×⇩F ?F ≤ uniformity)›*)) (*goal: ‹cauchy_filter (filtermap (sum f) (finite_subsets_at_top B))›*) proof (rule filter_leI (*‹(⋀P. eventually P ?F' ⟹ eventually P ?F) ⟹ ?F ≤ ?F'›*)) (*goal: ‹⋀P. eventually P uniformity ⟹ eventually P (filtermap (sum f) (finite_subsets_at_top B) ×⇩F filtermap (sum f) (finite_subsets_at_top B))›*) fix E :: "('b×'b) ⇒ bool" assume "eventually E uniformity" (*‹eventually (E::'b × 'b ⇒ bool) uniformity›*) then obtain E' where "eventually E' uniformity" and E'E'E: "E' (x, y) ⟶ E' (y, z) ⟶ E (x, z)" for x and y and z (*goal: ‹(⋀E'::'b::{ab_group_add,uniform_space} × 'b::{ab_group_add,uniform_space} ⇒ bool. ⟦eventually E' uniformity; ⋀(x::'b::{ab_group_add,uniform_space}) (y::'b::{ab_group_add,uniform_space}) z::'b::{ab_group_add,uniform_space}. E' (x, y) ⟶ E' (y, z) ⟶ (E::'b::{ab_group_add,uniform_space} × 'b::{ab_group_add,uniform_space} ⇒ bool) (x, z)⟧ ⟹ thesis::bool) ⟹ thesis›*) using uniformity_trans (*‹eventually (?E::?'a × ?'a ⇒ bool) uniformity ⟹ ∃D::?'a × ?'a ⇒ bool. eventually D uniformity ∧ (∀(x::?'a) (y::?'a) z::?'a. D (x, y) ⟶ D (y, z) ⟶ ?E (x, z))›*) by blast obtain D where "eventually D uniformity" and DE: "D (x, y) ⟹ E' (x+c, y+c)" for x and y and c (*goal: ‹(⋀D. ⟦eventually D uniformity; ⋀x y c. D (x, y) ⟹ E' (x + c, y + c)⟧ ⟹ thesis) ⟹ thesis›*) using plus_cont (*‹uniformly_continuous_on UNIV (λ(x, y). x + y)›*) ‹eventually E' uniformity› (*‹eventually E' uniformity›*) unfolding uniformly_continuous_on_uniformity filterlim_def le_filter_def uniformity_prod_def (*goal: ‹(⋀D. ⟦eventually D uniformity; ⋀x y c. D (x, y) ⟹ E' (x + c, y + c)⟧ ⟹ thesis) ⟹ thesis›*) by (auto simp: case_prod_beta (*‹(case ?p of (x, xa) ⇒ ?f x xa) = ?f (fst ?p) (snd ?p)›*) eventually_filtermap (*‹eventually ?P (filtermap ?f ?F) = (∀⇩F x in ?F. ?P (?f x))›*) eventually_prod_same (*‹eventually ?P (?F ×⇩F ?F) = (∃Q. eventually Q ?F ∧ (∀x y. Q x ⟶ Q y ⟶ ?P (x, y)))›*) uniformity_refl (*‹eventually ?E uniformity ⟹ ?E (?x, ?x)›*)) have DE': "E' (x, y)" if "D (x + c, y + c)" for x and y and c using DE[of "x + c" "y + c" "-c"] (*‹D (x + c, y + c) ⟹ E' (x + c + - c, y + c + - c)›*) that (*‹D (x + c, y + c)›*) by simp from ‹eventually D uniformity› (*‹eventually D uniformity›*) cauchy_fA (*‹cauchy_filter (filtermap (sum (f::'a::type ⇒ 'b::{ab_group_add,uniform_space})) (finite_subsets_at_top (A::'a::type set)))›*) have "eventually D (?filter_fA ×⇩F ?filter_fA)" unfolding cauchy_filter_def le_filter_def (*goal: ‹eventually D (filtermap (sum f) (finite_subsets_at_top A) ×⇩F filtermap (sum f) (finite_subsets_at_top A))›*) by simp then obtain P1 and P2 where ev_P1: "eventually (λF. P1 (sum f F)) ?filter_A" and ev_P2: "eventually (λF. P2 (sum f F)) ?filter_A" and P1P2E: "P1 x ⟹ P2 y ⟹ D (x, y)" for x and y (*goal: ‹(⋀P1 P2. ⟦∀⇩F F in finite_subsets_at_top A. P1 (sum f F); ∀⇩F F in finite_subsets_at_top A. P2 (sum f F); ⋀x y. ⟦P1 x; P2 y⟧ ⟹ D (x, y)⟧ ⟹ thesis) ⟹ thesis›*) unfolding eventually_prod_filter eventually_filtermap (*goal: ‹(⋀(P1::'b::{ab_group_add,uniform_space} ⇒ bool) P2::'b::{ab_group_add,uniform_space} ⇒ bool. ⟦∀⇩F F::'a::type set in finite_subsets_at_top (A::'a::type set). P1 (sum (f::'a::type ⇒ 'b::{ab_group_add,uniform_space}) F); ∀⇩F F::'a::type set in finite_subsets_at_top A. P2 (sum f F); ⋀(x::'b::{ab_group_add,uniform_space}) y::'b::{ab_group_add,uniform_space}. ⟦P1 x; P2 y⟧ ⟹ (D::'b::{ab_group_add,uniform_space} × 'b::{ab_group_add,uniform_space} ⇒ bool) (x, y)⟧ ⟹ thesis::bool) ⟹ thesis›*) by auto from ev_P1 (*‹∀⇩F F in finite_subsets_at_top A. P1 (sum f F)›*) obtain F1 where F1: "finite F1" "F1 ⊆ A" "⋀F. F⊇F1 ⟹ finite F ⟹ F⊆A ⟹ P1 (sum f F)" (*goal: ‹(⋀F1. ⟦finite F1; F1 ⊆ A; ⋀F. ⟦F1 ⊆ F; finite F; F ⊆ A⟧ ⟹ P1 (sum f F)⟧ ⟹ thesis) ⟹ thesis›*) by (metis eventually_finite_subsets_at_top (*‹eventually ?P (finite_subsets_at_top ?A) = (∃X. finite X ∧ X ⊆ ?A ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ ?A ⟶ ?P Y))›*)) from ev_P2 (*‹∀⇩F F in finite_subsets_at_top A. P2 (sum f F)›*) obtain F2 where F2: "finite F2" "F2 ⊆ A" "⋀F. F⊇F2 ⟹ finite F ⟹ F⊆A ⟹ P2 (sum f F)" (*goal: ‹(⋀F2. ⟦finite F2; F2 ⊆ A; ⋀F. ⟦F2 ⊆ F; finite F; F ⊆ A⟧ ⟹ P2 (sum f F)⟧ ⟹ thesis) ⟹ thesis›*) by (metis eventually_finite_subsets_at_top (*‹eventually ?P (finite_subsets_at_top ?A) = (∃X. finite X ∧ X ⊆ ?A ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ ?A ⟶ ?P Y))›*)) define F0 and F0A and F0B where "F0 ≡ F1 ∪ F2" and "F0A ≡ F0 - B" and "F0B ≡ F0 ∩ B" have [simp]: "finite F0" "F0 ⊆ A" using ‹F1 ⊆ A› (*‹F1 ⊆ A›*) ‹F2 ⊆ A› (*‹(F2::'a set) ⊆ (A::'a set)›*) ‹finite F1› (*‹finite F1›*) ‹finite F2› (*‹finite F2›*) unfolding F0_def (*goals: 1. ‹finite (F1 ∪ F2)› 2. ‹F1 ∪ F2 ⊆ A›*) apply - (*goals: 1. ‹⟦F1 ⊆ A; F2 ⊆ A; finite F1; finite F2⟧ ⟹ finite (F1 ∪ F2)› 2. ‹⟦F1 ⊆ A; F2 ⊆ A; finite F1; finite F2⟧ ⟹ F1 ∪ F2 ⊆ A› discuss goal 1*) apply blast (*discuss goal 2*) apply blast (*proven 2 subgoals*) . have "*": "E' (sum f F1', sum f F2')" if "F1'⊇F0B" "F2'⊇F0B" "finite F1'" "finite F2'" "F1'⊆B" "F2'⊆B" for F1' and F2' proof (intro DE'[where c = "sum f F0A"] (*‹D (?x + sum f F0A, ?y + sum f F0A) ⟹ E' (?x, ?y)›*) P1P2E (*‹⟦P1 ?x; P2 ?y⟧ ⟹ D (?x, ?y)›*)) (*goals: 1. ‹P1 (sum f F1' + sum f F0A)› 2. ‹P2 (sum f F2' + sum f F0A)›*) have "P1 (sum f (F1' ∪ F0A))" using that (*‹F0B ⊆ F1'› ‹(F0B::'a::type set) ⊆ (F2'::'a::type set)› ‹finite F1'› ‹finite F2'› ‹F1' ⊆ B› ‹F2' ⊆ B›*) assms (*‹complete UNIV› ‹uniformly_continuous_on UNIV (λ(x, y). x + y)› ‹f summable_on A› ‹B ⊆ A›*) F1(1,2) (*‹finite F1› ‹F1 ⊆ A›*) F2(1,2) (*‹finite (F2::'a::type set)› ‹(F2::'a set) ⊆ (A::'a set)›*) apply (intro F1 (*‹finite F1› ‹F1 ⊆ A› ‹⟦F1 ⊆ ?F; finite ?F; ?F ⊆ A⟧ ⟹ P1 (sum f ?F)›*)) (*goals: 1. ‹⟦F0B ⊆ F1'; F0B ⊆ F2'; finite F1'; finite F2'; F1' ⊆ B; F2' ⊆ B; complete UNIV; uniformly_continuous_on UNIV (λ(x, y). x + y); f summable_on A; B ⊆ A; finite F1; F1 ⊆ A; finite F2; F2 ⊆ A⟧ ⟹ F1 ⊆ F1' ∪ F0A› 2. ‹⟦F0B ⊆ F1'; F0B ⊆ F2'; finite F1'; finite F2'; F1' ⊆ B; F2' ⊆ B; complete UNIV; uniformly_continuous_on UNIV (λ(x, y). x + y); f summable_on A; B ⊆ A; finite F1; F1 ⊆ A; finite F2; F2 ⊆ A⟧ ⟹ finite (F1' ∪ F0A)› 3. ‹⟦F0B ⊆ F1'; F0B ⊆ F2'; finite F1'; finite F2'; F1' ⊆ B; F2' ⊆ B; complete UNIV; uniformly_continuous_on UNIV (λ(x, y). x + y); f summable_on A; B ⊆ A; finite F1; F1 ⊆ A; finite F2; F2 ⊆ A⟧ ⟹ F1' ∪ F0A ⊆ A› discuss goal 1*) apply ((auto simp: F0A_def (*‹F0A ≡ F0 - B›*) F0B_def (*‹F0B ≡ F0 ∩ B›*) F0_def (*‹F0 ≡ F1 ∪ F2›*))[1]) (*discuss goal 2*) apply ((auto simp: F0A_def (*‹F0A ≡ F0 - B›*) F0B_def (*‹F0B ≡ F0 ∩ B›*) F0_def (*‹F0 ≡ F1 ∪ F2›*))[1]) (*discuss goal 3*) apply ((auto simp: F0A_def (*‹F0A ≡ F0 - B›*) F0B_def (*‹F0B ≡ F0 ∩ B›*) F0_def (*‹F0 ≡ F1 ∪ F2›*))[1]) (*proven 3 subgoals*) . thus "P1 (sum f F1' + sum f F0A)" apply (subst (asm) sum.union_disjoint (*‹⟦finite ?A; finite ?B; ?A ∩ ?B = {}⟧ ⟹ sum ?g (?A ∪ ?B) = sum ?g ?A + sum ?g ?B›*)) (*goals: 1. ‹finite (F1'::'a set)› 2. ‹finite (F0A::'a set)› 3. ‹(F1'::'a set) ∩ (F0A::'a set) = {}› 4. ‹(P1::'b ⇒ bool) (sum (f::'a ⇒ 'b) (F1'::'a set) + sum f (F0A::'a set)) ⟹ P1 (sum f F1' + sum f F0A)› discuss goal 1*) apply ((use that in ‹auto simp: F0A_def›)[1]) (*discuss goal 2*) apply ((use that in ‹auto simp: F0A_def›)[1]) (*discuss goal 3*) apply ((use that in ‹auto simp: F0A_def›)[1]) (*discuss goal 4*) apply ((use that in ‹auto simp: F0A_def›)[1]) (*proven 4 subgoals*) . next (*goal: ‹P2 (sum f F2' + sum f F0A)›*) have "P2 (sum f (F2' ∪ F0A))" using that (*‹(F0B::'a set) ⊆ (F1'::'a set)› ‹(F0B::'a::type set) ⊆ (F2'::'a::type set)› ‹finite F1'› ‹finite F2'› ‹F1' ⊆ B› ‹F2' ⊆ B›*) assms (*‹complete UNIV› ‹uniformly_continuous_on UNIV (λ(x, y). x + y)› ‹f summable_on A› ‹B ⊆ A›*) F1(1,2) (*‹finite F1› ‹(F1::'a set) ⊆ (A::'a set)›*) F2(1,2) (*‹finite (F2::'a set)› ‹(F2::'a::type set) ⊆ (A::'a::type set)›*) apply (intro F2 (*‹finite (F2::'a::type set)› ‹(F2::'a::type set) ⊆ (A::'a::type set)› ‹⟦(F2::'a::type set) ⊆ (?F::'a::type set); finite ?F; ?F ⊆ (A::'a::type set)⟧ ⟹ (P2::'b::{ab_group_add,uniform_space} ⇒ bool) (sum (f::'a::type ⇒ 'b::{ab_group_add,uniform_space}) ?F)›*)) (*goals: 1. ‹⟦F0B ⊆ F1'; F0B ⊆ F2'; finite F1'; finite F2'; F1' ⊆ B; F2' ⊆ B; complete UNIV; uniformly_continuous_on UNIV (λ(x, y). x + y); f summable_on A; B ⊆ A; finite F1; F1 ⊆ A; finite F2; F2 ⊆ A⟧ ⟹ F2 ⊆ F2' ∪ F0A› 2. ‹⟦F0B ⊆ F1'; F0B ⊆ F2'; finite F1'; finite F2'; F1' ⊆ B; F2' ⊆ B; complete UNIV; uniformly_continuous_on UNIV (λ(x, y). x + y); f summable_on A; B ⊆ A; finite F1; F1 ⊆ A; finite F2; F2 ⊆ A⟧ ⟹ finite (F2' ∪ F0A)› 3. ‹⟦F0B ⊆ F1'; F0B ⊆ F2'; finite F1'; finite F2'; F1' ⊆ B; F2' ⊆ B; complete UNIV; uniformly_continuous_on UNIV (λ(x, y). x + y); f summable_on A; B ⊆ A; finite F1; F1 ⊆ A; finite F2; F2 ⊆ A⟧ ⟹ F2' ∪ F0A ⊆ A› discuss goal 1*) apply ((auto simp: F0A_def (*‹F0A ≡ F0 - B›*) F0B_def (*‹F0B ≡ F0 ∩ B›*) F0_def (*‹F0 ≡ F1 ∪ F2›*))[1]) (*discuss goal 2*) apply ((auto simp: F0A_def (*‹F0A ≡ F0 - B›*) F0B_def (*‹F0B ≡ F0 ∩ B›*) F0_def (*‹F0 ≡ F1 ∪ F2›*))[1]) (*discuss goal 3*) apply ((auto simp: F0A_def (*‹F0A ≡ F0 - B›*) F0B_def (*‹F0B ≡ F0 ∩ B›*) F0_def (*‹F0 ≡ F1 ∪ F2›*))[1]) (*proven 3 subgoals*) . thus "P2 (sum f F2' + sum f F0A)" apply (subst (asm) sum.union_disjoint (*‹⟦finite (?A::?'b::type set); finite (?B::?'b::type set); ?A ∩ ?B = {}⟧ ⟹ sum (?g::?'b::type ⇒ ?'a::comm_monoid_add) (?A ∪ ?B) = sum ?g ?A + sum ?g ?B›*)) (*goals: 1. ‹finite F2'› 2. ‹finite F0A› 3. ‹F2' ∩ F0A = {}› 4. ‹P2 (sum f F2' + sum f F0A) ⟹ P2 (sum f F2' + sum f F0A)› discuss goal 1*) apply ((use that in ‹auto simp: F0A_def›)[1]) (*discuss goal 2*) apply ((use that in ‹auto simp: F0A_def›)[1]) (*discuss goal 3*) apply ((use that in ‹auto simp: F0A_def›)[1]) (*discuss goal 4*) apply ((use that in ‹auto simp: F0A_def›)[1]) (*proven 4 subgoals*) . qed have "eventually (λx. E' (x, sum f F0B)) (filtermap (sum f) (finite_subsets_at_top B))" and "eventually (λx. E' (sum f F0B, x)) (filtermap (sum f) (finite_subsets_at_top B))" unfolding eventually_filtermap eventually_finite_subsets_at_top (*goals: 1. ‹∃X. finite X ∧ X ⊆ B ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ B ⟶ E' (sum f Y, sum f F0B))› 2. ‹∃X. finite X ∧ X ⊆ B ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ B ⟶ E' (sum f F0B, sum f Y))›*) (*goals: 1. ‹∃X::'a set. finite X ∧ X ⊆ (B::'a set) ∧ (∀Y::'a set. finite Y ∧ X ⊆ Y ∧ Y ⊆ B ⟶ (E'::'b × 'b ⇒ bool) (sum (f::'a ⇒ 'b) Y, sum f (F0B::'a set)))› 2. ‹∃X::'a set. finite X ∧ X ⊆ (B::'a set) ∧ (∀Y::'a set. finite Y ∧ X ⊆ Y ∧ Y ⊆ B ⟶ (E'::'b × 'b ⇒ bool) (sum (f::'a ⇒ 'b) (F0B::'a set), sum f Y))› discuss goal 1*) apply (rule exI[of _ F0B] (*‹?P F0B ⟹ ∃x. ?P x›*)) (*top goal: ‹∃X. finite X ∧ X ⊆ B ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ B ⟶ E' (sum f Y, sum f F0B))› and 1 goal remains*) apply (use * in ‹force simp: F0B_def›) (*discuss goal 2*) apply (rule exI[of _ F0B] (*‹?P F0B ⟹ ∃x. ?P x›*)) (*goal: ‹∃X::'a set. finite X ∧ X ⊆ (B::'a set) ∧ (∀Y::'a set. finite Y ∧ X ⊆ Y ∧ Y ⊆ B ⟶ (E'::'b × 'b ⇒ bool) (sum (f::'a ⇒ 'b) (F0B::'a set), sum f Y))›*) apply (use * in ‹force simp: F0B_def›) (*proven 2 subgoals*) . then show "eventually E (?filter_fB ×⇩F ?filter_fB)" unfolding eventually_prod_filter (*goal: ‹∃Pf Pg. eventually Pf (filtermap (sum f) (finite_subsets_at_top B)) ∧ eventually Pg (filtermap (sum f) (finite_subsets_at_top B)) ∧ (∀x y. Pf x ⟶ Pg y ⟶ E (x, y))›*) using E'E'E (*‹E' (?x, ?y) ⟶ E' (?y, ?z) ⟶ E (?x, ?z)›*) by blast qed then obtain x where "?filter_fB ≤ nhds x" (*goal: ‹(⋀x. filtermap (sum f) (finite_subsets_at_top B) ≤ nhds x ⟹ thesis) ⟹ thesis›*) using cauchy_filter_complete_converges[of ?filter_fB UNIV] (*‹⟦cauchy_filter (filtermap (sum f) (finite_subsets_at_top B)); complete UNIV; filtermap (sum f) (finite_subsets_at_top B) ≤ principal UNIV; filtermap (sum f) (finite_subsets_at_top B) ≠ bot⟧ ⟹ ∃c. filtermap (sum f) (finite_subsets_at_top B) ≤ nhds c›*) ‹complete (UNIV :: _)› (*‹complete UNIV›*) by (auto simp: filtermap_bot_iff (*‹(filtermap ?f ?F = bot) = (?F = bot)›*)) then have "(sum f ⤏ x) (finite_subsets_at_top B)" by (auto simp: filterlim_def (*‹filterlim ?f ?F2.0 ?F1.0 = (filtermap ?f ?F1.0 ≤ ?F2.0)›*)) then show "?thesis" (*goal: ‹f summable_on B›*) by (auto simp: summable_on_def (*‹(?f::?'a ⇒ ?'b) summable_on (?A::?'a set) ≡ ∃x::?'b. (?f has_sum x) ?A›*) has_sum_def (*‹((?f::?'a ⇒ ?'b) has_sum (?x::?'b)) (?A::?'a set) ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*)) qed text ‹A special case of @{thm [source] summable_on_subset_aux} for Banach spaces with fewer premises.› lemma summable_on_subset_banach: fixes A B and f :: ‹'a ⇒ 'b::banach› assumes ‹f summable_on A› assumes ‹B ⊆ A› shows ‹f summable_on B› by (meson Cauchy_convergent (*‹Cauchy ?X ⟹ convergent ?X›*) UNIV_I (*‹?x ∈ UNIV›*) assms (*‹f summable_on A› ‹B ⊆ A›*) complete_def (*‹complete ?S = (∀f. (∀n. f n ∈ ?S) ∧ Cauchy f ⟶ (∃l∈?S. f ⇢ l))›*) convergent_def (*‹convergent ?X = (∃L. ?X ⇢ L)›*) isUCont_plus (*‹isUCont (λ(x, y). x + y)›*) summable_on_subset_aux (*‹⟦complete UNIV; uniformly_continuous_on UNIV (λ(x, y). x + y); ?f summable_on ?A; ?B ⊆ ?A⟧ ⟹ ?f summable_on ?B›*)) lemma has_sum_empty[simp]: ‹(f has_sum 0) {}› by (meson ex_in_conv (*‹(∃x. x ∈ ?A) = (?A ≠ {})›*) has_sum_0 (*‹(⋀x. x ∈ ?M ⟹ ?f x = 0) ⟹ (?f has_sum 0) ?M›*)) lemma summable_on_empty[simp]: ‹f summable_on {}› by auto lemma infsum_empty[simp]: ‹infsum f {} = 0› by simp lemma sum_has_sum: fixes f :: "'a ⇒ 'b::topological_comm_monoid_add" assumes ‹finite A› assumes ‹⋀a. a ∈ A ⟹ (f has_sum (s a)) (B a)› assumes ‹⋀a a'. a∈A ⟹ a'∈A ⟹ a≠a' ⟹ B a ∩ B a' = {}› shows ‹(f has_sum (sum s A)) (⋃a∈A. B a)› using assms (*‹finite A› ‹?a ∈ A ⟹ (f has_sum s ?a) (B ?a)› ‹⟦?a ∈ A; ?a' ∈ A; ?a ≠ ?a'⟧ ⟹ B ?a ∩ B ?a' = {}›*) proof (induction) (*goals: 1. ‹⟦⋀a. a ∈ {} ⟹ (f has_sum s a) (B a); ⋀a a'. ⟦a ∈ {}; a' ∈ {}; a ≠ a'⟧ ⟹ B a ∩ B a' = {}⟧ ⟹ (f has_sum sum s {}) (⋃ (B ` {}))› 2. ‹⋀x F. ⟦finite F; x ∉ F; ⟦⋀a. a ∈ F ⟹ (f has_sum s a) (B a); ⋀a a'. ⟦a ∈ F; a' ∈ F; a ≠ a'⟧ ⟹ B a ∩ B a' = {}⟧ ⟹ (f has_sum sum s F) (⋃ (B ` F)); ⋀a. a ∈ insert x F ⟹ (f has_sum s a) (B a); ⋀a a'. ⟦a ∈ insert x F; a' ∈ insert x F; a ≠ a'⟧ ⟹ B a ∩ B a' = {}⟧ ⟹ (f has_sum sum s (insert x F)) (⋃ (B ` insert x F))›*) case empty (*‹(?a::'c::type) ∈ {} ⟹ ((f::'a::type ⇒ 'b::topological_comm_monoid_add) has_sum (s::'c::type ⇒ 'b::topological_comm_monoid_add) ?a) ((B::'c::type ⇒ 'a::type set) ?a)› ‹⟦?a ∈ {}; ?a' ∈ {}; ?a ≠ ?a'⟧ ⟹ B ?a ∩ B ?a' = {}›*) then show "?case" (*goal: ‹(f has_sum sum s {}) (⋃ (B ` {}))›*) by simp next (*goal: ‹⋀x F. ⟦finite F; x ∉ F; ⟦⋀a. a ∈ F ⟹ (f has_sum s a) (B a); ⋀a a'. ⟦a ∈ F; a' ∈ F; a ≠ a'⟧ ⟹ B a ∩ B a' = {}⟧ ⟹ (f has_sum sum s F) (⋃ (B ` F)); ⋀a. a ∈ insert x F ⟹ (f has_sum s a) (B a); ⋀a a'. ⟦a ∈ insert x F; a' ∈ insert x F; a ≠ a'⟧ ⟹ B a ∩ B a' = {}⟧ ⟹ (f has_sum sum s (insert x F)) (⋃ (B ` insert x F))›*) case (insert x A) (*‹finite A› ‹(x::'c) ∉ (A::'c set)› ‹⟦⋀a. a ∈ A ⟹ (f has_sum s a) (B a); ⋀a a'. ⟦a ∈ A; a' ∈ A; a ≠ a'⟧ ⟹ B a ∩ B a' = {}⟧ ⟹ (f has_sum sum s A) (⋃ (B ` A))› ‹?a ∈ insert x A ⟹ (f has_sum s ?a) (B ?a)› ‹⟦?a ∈ insert x A; ?a' ∈ insert x A; ?a ≠ ?a'⟧ ⟹ B ?a ∩ B ?a' = {}›*) have "(f has_sum (s x)) (B x)" by (simp add: insert.prems (*‹?a ∈ insert x A ⟹ (f has_sum s ?a) (B ?a)› ‹⟦?a ∈ insert x A; ?a' ∈ insert x A; ?a ≠ ?a'⟧ ⟹ B ?a ∩ B ?a' = {}›*)) moreover have IH: "(f has_sum (sum s A)) (⋃a∈A. B a)" using insert (*‹finite (A::'c::type set)› ‹x ∉ A› ‹⟦⋀a. a ∈ A ⟹ (f has_sum s a) (B a); ⋀a a'. ⟦a ∈ A; a' ∈ A; a ≠ a'⟧ ⟹ B a ∩ B a' = {}⟧ ⟹ (f has_sum sum s A) (⋃ (B ` A))› ‹?a ∈ insert x A ⟹ (f has_sum s ?a) (B ?a)› ‹⟦?a ∈ insert x A; ?a' ∈ insert x A; ?a ≠ ?a'⟧ ⟹ B ?a ∩ B ?a' = {}›*) by simp ultimately have "(f has_sum (s x + sum s A)) (B x ∪ (⋃a∈A. B a))" using insert (*‹finite (A::'c set)› ‹x ∉ A› ‹⟦⋀a. a ∈ A ⟹ (f has_sum s a) (B a); ⋀a a'. ⟦a ∈ A; a' ∈ A; a ≠ a'⟧ ⟹ B a ∩ B a' = {}⟧ ⟹ (f has_sum sum s A) (⋃ (B ` A))› ‹?a ∈ insert x A ⟹ (f has_sum s ?a) (B ?a)› ‹⟦?a ∈ insert x A; ?a' ∈ insert x A; ?a ≠ ?a'⟧ ⟹ B ?a ∩ B ?a' = {}›*) apply (intro has_sum_Un_disjoint (*‹⟦(?f has_sum ?a) ?A; (?f has_sum ?b) ?B; ?A ∩ ?B = {}⟧ ⟹ (?f has_sum ?a + ?b) (?A ∪ ?B)›*)) (*goals: 1. ‹⟦(f has_sum s x) (B x); (f has_sum sum s A) (⋃ (B ` A)); finite A; x ∉ A; ⟦⋀a. a ∈ A ⟹ (f has_sum s a) (B a); ⋀a a'. ⟦a ∈ A; a' ∈ A; a ≠ a'⟧ ⟹ B a ∩ B a' = {}⟧ ⟹ (f has_sum sum s A) (⋃ (B ` A)); ⋀a. a ∈ insert x A ⟹ (f has_sum s a) (B a); ⋀a a'. ⟦a ∈ insert x A; a' ∈ insert x A; a ≠ a'⟧ ⟹ B a ∩ B a' = {}⟧ ⟹ (f has_sum s x) (B x)› 2. ‹⟦(f has_sum s x) (B x); (f has_sum sum s A) (⋃ (B ` A)); finite A; x ∉ A; ⟦⋀a. a ∈ A ⟹ (f has_sum s a) (B a); ⋀a a'. ⟦a ∈ A; a' ∈ A; a ≠ a'⟧ ⟹ B a ∩ B a' = {}⟧ ⟹ (f has_sum sum s A) (⋃ (B ` A)); ⋀a. a ∈ insert x A ⟹ (f has_sum s a) (B a); ⋀a a'. ⟦a ∈ insert x A; a' ∈ insert x A; a ≠ a'⟧ ⟹ B a ∩ B a' = {}⟧ ⟹ (f has_sum sum s A) (⋃ (B ` A))› 3. ‹⟦(f has_sum s x) (B x); (f has_sum sum s A) (⋃ (B ` A)); finite A; x ∉ A; ⟦⋀a. a ∈ A ⟹ (f has_sum s a) (B a); ⋀a a'. ⟦a ∈ A; a' ∈ A; a ≠ a'⟧ ⟹ B a ∩ B a' = {}⟧ ⟹ (f has_sum sum s A) (⋃ (B ` A)); ⋀a. a ∈ insert x A ⟹ (f has_sum s a) (B a); ⋀a a'. ⟦a ∈ insert x A; a' ∈ insert x A; a ≠ a'⟧ ⟹ B a ∩ B a' = {}⟧ ⟹ B x ∩ ⋃ (B ` A) = {}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . then show "?case" (*goal: ‹(f has_sum sum s (insert x A)) (⋃ (B ` insert x A))›*) using insert.hyps (*‹finite A› ‹(x::'c) ∉ (A::'c set)›*) by auto qed lemma summable_on_finite_union_disjoint: fixes f :: "'a ⇒ 'b::topological_comm_monoid_add" assumes finite: ‹finite A› assumes conv: ‹⋀a. a ∈ A ⟹ f summable_on (B a)› assumes disj: ‹⋀a a'. a∈A ⟹ a'∈A ⟹ a≠a' ⟹ B a ∩ B a' = {}› shows ‹f summable_on (⋃a∈A. B a)› using sum_has_sum[of A f B] (*‹⟦finite A; ⋀a. a ∈ A ⟹ (f has_sum ?s a) (B a); ⋀a a'. ⟦a ∈ A; a' ∈ A; a ≠ a'⟧ ⟹ B a ∩ B a' = {}⟧ ⟹ (f has_sum sum ?s A) (⋃ (B ` A))›*) assms (*‹finite A› ‹?a ∈ A ⟹ f summable_on B ?a› ‹⟦?a ∈ A; ?a' ∈ A; ?a ≠ ?a'⟧ ⟹ B ?a ∩ B ?a' = {}›*) unfolding summable_on_def (*goal: ‹∃x. (f has_sum x) (⋃ (B ` A))›*) by metis lemma sum_infsum: fixes f :: "'a ⇒ 'b::{topological_comm_monoid_add, t2_space}" assumes finite: ‹finite A› assumes conv: ‹⋀a. a ∈ A ⟹ f summable_on (B a)› assumes disj: ‹⋀a a'. a∈A ⟹ a'∈A ⟹ a≠a' ⟹ B a ∩ B a' = {}› shows ‹sum (λa. infsum f (B a)) A = infsum f (⋃a∈A. B a)› by (metis (no_types, lifting) assms (*‹finite A› ‹?a ∈ A ⟹ f summable_on B ?a› ‹⟦?a ∈ A; ?a' ∈ A; ?a ≠ ?a'⟧ ⟹ B ?a ∩ B ?a' = {}›*) has_sum_infsum (*‹?f summable_on ?S ⟹ (?f has_sum infsum ?f ?S) ?S›*) infsumI (*‹(?f has_sum ?x) ?A ⟹ infsum ?f ?A = ?x›*) sum_has_sum (*‹⟦finite ?A; ⋀a. a ∈ ?A ⟹ (?f has_sum ?s a) (?B a); ⋀a a'. ⟦a ∈ ?A; a' ∈ ?A; a ≠ a'⟧ ⟹ ?B a ∩ ?B a' = {}⟧ ⟹ (?f has_sum sum ?s ?A) (⋃ (?B ` ?A))›*)) text ‹The lemmas ‹infsum_comm_additive_general› and ‹infsum_comm_additive› (and variants) below both state that the infinite sum commutes with a continuous additive function. ‹infsum_comm_additive_general› is stated more for more general type classes at the expense of a somewhat less compact formulation of the premises. E.g., by avoiding the constant \<^const>‹additive› which introduces an additional sort constraint (group instead of monoid). For example, extended reals (\<^typ>‹ereal›, \<^typ>‹ennreal›) are not covered by ‹infsum_comm_additive›.› lemma has_sum_comm_additive_general: fixes f :: ‹'b :: {comm_monoid_add,topological_space} ⇒ 'c :: {comm_monoid_add,topological_space}› assumes f_sum: ‹⋀F. finite F ⟹ F ⊆ S ⟹ sum (f ∘ g) F = f (sum g F)› ― ‹Not using \<^const>‹additive› because it would add sort constraint \<^class>‹ab_group_add›› assumes cont: ‹f ─x→ f x› ― ‹For \<^class>‹t2_space›, this is equivalent to ‹isCont f x› by @{thm [source] isCont_def}.› assumes infsum: ‹(g has_sum x) S› shows ‹((f ∘ g) has_sum (f x)) S› proof (-) (*goal: ‹((f::'b ⇒ 'c) ∘ (g::'a ⇒ 'b) has_sum f (x::'b)) (S::'a set)›*) have "(sum g ⤏ x) (finite_subsets_at_top S)" using infsum (*‹(g has_sum x) S›*) has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*) by blast then have "((f ∘ sum g) ⤏ f x) (finite_subsets_at_top S)" by (meson cont (*‹f ─x→ f x›*) filterlim_def (*‹filterlim ?f ?F2.0 ?F1.0 = (filtermap ?f ?F1.0 ≤ ?F2.0)›*) tendsto_at_iff_tendsto_nhds (*‹?g ─?l→ ?g ?l = (?g ⤏ ?g ?l) (nhds ?l)›*) tendsto_compose_filtermap (*‹((?g ∘ ?f) ⤏ ?T) ?F = (?g ⤏ ?T) (filtermap ?f ?F)›*) tendsto_mono (*‹⟦?F ≤ ?F'; (?f ⤏ ?l) ?F'⟧ ⟹ (?f ⤏ ?l) ?F›*)) then have "(sum (f ∘ g) ⤏ f x) (finite_subsets_at_top S)" using tendsto_cong (*‹∀⇩F x in ?F. ?f x = ?g x ⟹ (?f ⤏ ?c) ?F = (?g ⤏ ?c) ?F›*) f_sum (*‹⟦finite (?F::'a set); ?F ⊆ (S::'a set)⟧ ⟹ sum ((f::'b ⇒ 'c) ∘ (g::'a ⇒ 'b)) ?F = f (sum g ?F)›*) by (simp add: Lim_transform_eventually (*‹⟦(?f ⤏ ?l) ?F; ∀⇩F x in ?F. ?f x = ?g x⟧ ⟹ (?g ⤏ ?l) ?F›*) eventually_finite_subsets_at_top_weakI (*‹(⋀X. ⟦finite X; X ⊆ ?A⟧ ⟹ ?P X) ⟹ eventually ?P (finite_subsets_at_top ?A)›*)) then show "((f ∘ g) has_sum (f x)) S" using has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*) by blast qed lemma summable_on_comm_additive_general: fixes f :: ‹'b :: {comm_monoid_add,topological_space} ⇒ 'c :: {comm_monoid_add,topological_space}› assumes ‹⋀F. finite F ⟹ F ⊆ S ⟹ sum (f ∘ g) F = f (sum g F)› ― ‹Not using \<^const>‹additive› because it would add sort constraint \<^class>‹ab_group_add›› assumes ‹⋀x. (g has_sum x) S ⟹ f ─x→ f x› ― ‹For \<^class>‹t2_space›, this is equivalent to ‹isCont f x› by @{thm [source] isCont_def}.› assumes ‹g summable_on S› shows ‹(f ∘ g) summable_on S› by (meson assms (*‹⟦finite ?F; ?F ⊆ S⟧ ⟹ sum (f ∘ g) ?F = f (sum g ?F)› ‹(g has_sum ?x) S ⟹ f ─?x→ f ?x› ‹g summable_on S›*) summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*) has_sum_comm_additive_general (*‹⟦⋀F. ⟦finite F; F ⊆ ?S⟧ ⟹ sum (?f ∘ ?g) F = ?f (sum ?g F); ?f ─?x→ ?f ?x; (?g has_sum ?x) ?S⟧ ⟹ (?f ∘ ?g has_sum ?f ?x) ?S›*) has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*) infsum_tendsto (*‹?f summable_on ?S ⟹ (sum ?f ⤏ infsum ?f ?S) (finite_subsets_at_top ?S)›*)) lemma infsum_comm_additive_general: fixes f :: ‹'b :: {comm_monoid_add,t2_space} ⇒ 'c :: {comm_monoid_add,t2_space}› assumes f_sum: ‹⋀F. finite F ⟹ F ⊆ S ⟹ sum (f ∘ g) F = f (sum g F)› ― ‹Not using \<^const>‹additive› because it would add sort constraint \<^class>‹ab_group_add›› assumes ‹isCont f (infsum g S)› assumes ‹g summable_on S› shows ‹infsum (f ∘ g) S = f (infsum g S)› using assms (*‹⟦finite ?F; ?F ⊆ S⟧ ⟹ sum (f ∘ g) ?F = f (sum g ?F)› ‹isCont f (infsum g S)› ‹g summable_on S›*) apply (intro infsumI (*‹(?f has_sum ?x) ?A ⟹ infsum ?f ?A = ?x›*) has_sum_comm_additive_general (*‹⟦⋀F. ⟦finite F; F ⊆ ?S⟧ ⟹ sum (?f ∘ ?g) F = ?f (sum ?g F); ?f ─?x→ ?f ?x; (?g has_sum ?x) ?S⟧ ⟹ (?f ∘ ?g has_sum ?f ?x) ?S›*) has_sum_infsum (*‹?f summable_on ?S ⟹ (?f has_sum infsum ?f ?S) ?S›*)) (*goals: 1. ‹⋀F::'a set. ⟦⋀F::'a set. ⟦finite F; F ⊆ (S::'a set)⟧ ⟹ sum ((f::'b ⇒ 'c) ∘ (g::'a ⇒ 'b)) F = f (sum g F); isCont f (infsum g S); g summable_on S; finite F; F ⊆ S⟧ ⟹ sum (f ∘ g) F = f (sum g F)› 2. ‹⟦⋀F::'a set. ⟦finite F; F ⊆ (S::'a set)⟧ ⟹ sum ((f::'b ⇒ 'c) ∘ (g::'a ⇒ 'b)) F = f (sum g F); isCont f (infsum g S); g summable_on S⟧ ⟹ f ─infsum g S→ f (infsum g S)› 3. ‹⟦⋀F::'a set. ⟦finite F; F ⊆ (S::'a set)⟧ ⟹ sum ((f::'b ⇒ 'c) ∘ (g::'a ⇒ 'b)) F = f (sum g F); isCont f (infsum g S); g summable_on S⟧ ⟹ g summable_on S› discuss goal 1*) apply ((auto simp: isCont_def (*‹isCont ?f ?a = ?f ─?a→ ?f ?a›*))[1]) (*discuss goal 2*) apply ((auto simp: isCont_def (*‹isCont ?f ?a = ?f ─?a→ ?f ?a›*))[1]) (*discuss goal 3*) apply ((auto simp: isCont_def (*‹isCont ?f ?a = ?f ─?a→ ?f ?a›*))[1]) (*proven 3 subgoals*) . lemma has_sum_comm_additive: fixes f :: ‹'b :: {ab_group_add,topological_space} ⇒ 'c :: {ab_group_add,topological_space}› assumes ‹additive f› assumes ‹f ─x→ f x› ― ‹For \<^class>‹t2_space›, this is equivalent to ‹isCont f x› by @{thm [source] isCont_def}.› assumes infsum: ‹(g has_sum x) S› shows ‹((f ∘ g) has_sum (f x)) S› using assms (*‹additive f› ‹f ─x→ f x› ‹(g has_sum x) S›*) apply (intro has_sum_comm_additive_general (*‹⟦⋀F. ⟦finite F; F ⊆ ?S⟧ ⟹ sum (?f ∘ ?g) F = ?f (sum ?g F); ?f ─?x→ ?f ?x; (?g has_sum ?x) ?S⟧ ⟹ (?f ∘ ?g has_sum ?f ?x) ?S›*) has_sum_infsum (*‹?f summable_on ?S ⟹ (?f has_sum infsum ?f ?S) ?S›*)) (*goals: 1. ‹⋀F. ⟦additive f; f ─x→ f x; (g has_sum x) S; finite F; F ⊆ S⟧ ⟹ sum (f ∘ g) F = f (sum g F)› 2. ‹⟦additive f; f ─x→ f x; (g has_sum x) S⟧ ⟹ f ─x→ f x› 3. ‹⟦additive f; f ─x→ f x; (g has_sum x) S⟧ ⟹ (g has_sum x) S› discuss goal 1*) apply ((auto simp: isCont_def (*‹isCont ?f ?a = ?f ─?a→ ?f ?a›*) additive.sum (*‹additive ?f ⟹ ?f (sum ?g ?A) = (∑x∈?A. ?f (?g x))›*))[1]) (*discuss goal 2*) apply ((auto simp: isCont_def (*‹isCont (?f::?'a ⇒ ?'b) (?a::?'a) = ?f ─?a→ ?f ?a›*) additive.sum (*‹additive (?f::?'a ⇒ ?'b) ⟹ ?f (sum (?g::?'c ⇒ ?'a) (?A::?'c set)) = (∑x::?'c∈?A. ?f (?g x))›*))[1]) (*discuss goal 3*) apply ((auto simp: isCont_def (*‹isCont ?f ?a = ?f ─?a→ ?f ?a›*) additive.sum (*‹additive ?f ⟹ ?f (sum ?g ?A) = (∑x∈?A. ?f (?g x))›*))[1]) (*proven 3 subgoals*) . lemma summable_on_comm_additive: fixes f :: ‹'b :: {ab_group_add,t2_space} ⇒ 'c :: {ab_group_add,topological_space}› assumes ‹additive f› assumes ‹isCont f (infsum g S)› assumes ‹g summable_on S› shows ‹(f ∘ g) summable_on S› by (meson assms (*‹additive (f::'b ⇒ 'c)› ‹isCont (f::'b ⇒ 'c) (infsum (g::'a ⇒ 'b) (S::'a set))› ‹(g::'a ⇒ 'b) summable_on (S::'a set)›*) summable_on_def (*‹(?f::?'a ⇒ ?'b) summable_on (?A::?'a set) ≡ ∃x::?'b. (?f has_sum x) ?A›*) has_sum_comm_additive (*‹⟦additive (?f::?'b ⇒ ?'c); ?f ─?x::?'b→ ?f ?x; ((?g::?'a ⇒ ?'b) has_sum ?x) (?S::?'a set)⟧ ⟹ (?f ∘ ?g has_sum ?f ?x) ?S›*) has_sum_infsum (*‹(?f::?'a ⇒ ?'b) summable_on (?S::?'a set) ⟹ (?f has_sum infsum ?f ?S) ?S›*) isContD (*‹isCont (?f::?'a ⇒ ?'b) (?x::?'a) ⟹ ?f ─?x→ ?f ?x›*)) lemma infsum_comm_additive: fixes f :: ‹'b :: {ab_group_add,t2_space} ⇒ 'c :: {ab_group_add,t2_space}› assumes ‹additive f› assumes ‹isCont f (infsum g S)› assumes ‹g summable_on S› shows ‹infsum (f ∘ g) S = f (infsum g S)› apply (rule infsum_comm_additive_general (*‹⟦⋀F. ⟦finite F; F ⊆ ?S⟧ ⟹ sum (?f ∘ ?g) F = ?f (sum ?g F); isCont ?f (infsum ?g ?S); ?g summable_on ?S⟧ ⟹ infsum (?f ∘ ?g) ?S = ?f (infsum ?g ?S)›*)) (*goals: 1. ‹⋀F::'a set. ⟦finite F; F ⊆ (S::'a set)⟧ ⟹ sum ((f::'b ⇒ 'c) ∘ (g::'a ⇒ 'b)) F = f (sum g F)› 2. ‹isCont (f::'b ⇒ 'c) (infsum (g::'a ⇒ 'b) (S::'a set))› 3. ‹(g::'a ⇒ 'b) summable_on (S::'a set)› discuss goal 1*) apply ((auto simp: assms (*‹additive f› ‹isCont f (infsum g S)› ‹g summable_on S›*) additive.sum (*‹additive ?f ⟹ ?f (sum ?g ?A) = (∑x∈?A. ?f (?g x))›*))[1]) (*discuss goal 2*) apply ((auto simp: assms (*‹additive f› ‹isCont f (infsum g S)› ‹g summable_on S›*) additive.sum (*‹additive ?f ⟹ ?f (sum ?g ?A) = (∑x∈?A. ?f (?g x))›*))[1]) (*discuss goal 3*) apply ((auto simp: assms (*‹additive f› ‹isCont f (infsum g S)› ‹g summable_on S›*) additive.sum (*‹additive ?f ⟹ ?f (sum ?g ?A) = (∑x∈?A. ?f (?g x))›*))[1]) (*proven 3 subgoals*) . lemma nonneg_bdd_above_has_sum: fixes f :: ‹'a ⇒ 'b :: {conditionally_complete_linorder, ordered_comm_monoid_add, linorder_topology}› assumes ‹⋀x. x∈A ⟹ f x ≥ 0› assumes ‹bdd_above (sum f ` {F. F⊆A ∧ finite F})› shows ‹(f has_sum (SUP F∈{F. finite F ∧ F⊆A}. sum f F)) A› proof (-) (*goal: ‹(f has_sum Sup (sum f ` {F. finite F ∧ F ⊆ A})) A›*) have "(sum f ⤏ (SUP F∈{F. finite F ∧ F⊆A}. sum f F)) (finite_subsets_at_top A)" proof (rule order_tendstoI (*‹⟦⋀a::?'a::order_topology. a < (?y::?'a::order_topology) ⟹ ∀⇩F x::?'b::type in ?F::?'b::type filter. a < (?f::?'b::type ⇒ ?'a::order_topology) x; ⋀a::?'a::order_topology. ?y < a ⟹ ∀⇩F x::?'b::type in ?F. ?f x < a⟧ ⟹ (?f ⤏ ?y) ?F›*)) (*goals: 1. ‹⋀a. a < Sup (sum f ` {F. finite F ∧ F ⊆ A}) ⟹ ∀⇩F x in finite_subsets_at_top A. a < sum f x› 2. ‹⋀a. Sup (sum f ` {F. finite F ∧ F ⊆ A}) < a ⟹ ∀⇩F x in finite_subsets_at_top A. sum f x < a›*) fix a assume "a < (SUP F∈{F. finite F ∧ F⊆A}. sum f F)" (*‹(a::'b) < Sup (sum (f::'a ⇒ 'b) ` {F::'a set. finite F ∧ F ⊆ (A::'a set)})›*) then obtain F where "a < sum f F" and "finite F" and "F ⊆ A" (*goal: ‹(⋀F. ⟦a < sum f F; finite F; F ⊆ A⟧ ⟹ thesis) ⟹ thesis›*) by (metis (mono_tags, lifting) Collect_cong (*‹(⋀x::?'a. (?P::?'a ⇒ bool) x = (?Q::?'a ⇒ bool) x) ⟹ {x::?'a. ?P x} = {x::?'a. ?Q x}›*) Collect_empty_eq (*‹(Collect (?P::?'a ⇒ bool) = {}) = (∀x::?'a. ¬ ?P x)›*) assms( (*‹bdd_above (sum (f::'a ⇒ 'b) ` {F::'a set. F ⊆ (A::'a set) ∧ finite F})›*) 2) empty_subsetI (*‹{} ⊆ (?A::?'a set)›*) finite.emptyI (*‹finite {}›*) less_cSUP_iff (*‹⟦(?A::?'b set) ≠ {}; bdd_above ((?f::?'b ⇒ ?'a) ` ?A)⟧ ⟹ ((?a::?'a) < Sup (?f ` ?A)) = (∃x::?'b∈?A. ?a < ?f x)›*) mem_Collect_eq (*‹((?a::?'a) ∈ Collect (?P::?'a ⇒ bool)) = ?P ?a›*)) have "⋀Y. ⟦finite Y; F ⊆ Y; Y ⊆ A⟧ ⟹ a < sum f Y" by (meson DiffE (*‹⟦?c ∈ ?A - ?B; ⟦?c ∈ ?A; ?c ∉ ?B⟧ ⟹ ?P⟧ ⟹ ?P›*) ‹a < sum f F› assms( (*‹?x ∈ A ⟹ 0 ≤ f ?x›*) 1) less_le_trans (*‹⟦?x < ?y; ?y ≤ ?z⟧ ⟹ ?x < ?z›*) subset_iff (*‹(?A ⊆ ?B) = (∀t. t ∈ ?A ⟶ t ∈ ?B)›*) sum_mono2 (*‹⟦finite ?B; ?A ⊆ ?B; ⋀b. b ∈ ?B - ?A ⟹ 0 ≤ ?f b⟧ ⟹ sum ?f ?A ≤ sum ?f ?B›*)) then show "∀⇩F x in finite_subsets_at_top A. a < sum f x" by (metis ‹F ⊆ A› ‹finite F› eventually_finite_subsets_at_top (*‹eventually ?P (finite_subsets_at_top ?A) = (∃X. finite X ∧ X ⊆ ?A ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ ?A ⟶ ?P Y))›*)) next (*goal: ‹⋀a. Sup (sum f ` {F. finite F ∧ F ⊆ A}) < a ⟹ ∀⇩F x in finite_subsets_at_top A. sum f x < a›*) fix a assume "*": "(SUP F∈{F. finite F ∧ F⊆A}. sum f F) < a" (*‹Sup (sum (f::'a ⇒ 'b) ` {F::'a set. finite F ∧ F ⊆ (A::'a set)}) < (a::'b)›*) have "sum f F ≤ (SUP F∈{F. finite F ∧ F⊆A}. sum f F)" if "F⊆A" and "finite F" for F apply (rule cSUP_upper (*‹⟦(?x::?'b) ∈ (?A::?'b set); bdd_above ((?f::?'b ⇒ ?'a) ` ?A)⟧ ⟹ ?f ?x ≤ Sup (?f ` ?A)›*)) (*goals: 1. ‹F ∈ {F. finite F ∧ F ⊆ A}› 2. ‹bdd_above (sum f ` {F. finite F ∧ F ⊆ A})› discuss goal 1*) apply ((use that assms(2) in ‹auto simp: conj_commute›)[1]) (*discuss goal 2*) apply ((use that assms(2) in ‹auto simp: conj_commute›)[1]) (*proven 2 subgoals*) . then show "∀⇩F x in finite_subsets_at_top A. sum f x < a" by (metis (no_types, lifting) "*" (*‹Sup (sum f ` {F. finite F ∧ F ⊆ A}) < a›*) eventually_finite_subsets_at_top_weakI (*‹(⋀X. ⟦finite X; X ⊆ ?A⟧ ⟹ ?P X) ⟹ eventually ?P (finite_subsets_at_top ?A)›*) order_le_less_trans (*‹⟦?x ≤ ?y; ?y < ?z⟧ ⟹ ?x < ?z›*)) qed then show "?thesis" (*goal: ‹(f has_sum Sup (sum f ` {F. finite F ∧ F ⊆ A})) A›*) using has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*) by blast qed lemma nonneg_bdd_above_summable_on: fixes f :: ‹'a ⇒ 'b :: {conditionally_complete_linorder, ordered_comm_monoid_add, linorder_topology}› assumes ‹⋀x. x∈A ⟹ f x ≥ 0› assumes ‹bdd_above (sum f ` {F. F⊆A ∧ finite F})› shows ‹f summable_on A› using assms (*‹(?x::'a::type) ∈ (A::'a::type set) ⟹ (0::'b::{conditionally_complete_linorder,ordered_comm_monoid_add,linorder_topology}) ≤ (f::'a::type ⇒ 'b::{conditionally_complete_linorder,ordered_comm_monoid_add,linorder_topology}) ?x› ‹bdd_above (sum (f::'a::type ⇒ 'b::{conditionally_complete_linorder,ordered_comm_monoid_add,linorder_topology}) ` {F::'a::type set. F ⊆ (A::'a::type set) ∧ finite F})›*) summable_on_def (*‹(?f::?'a ⇒ ?'b) summable_on (?A::?'a set) ≡ ∃x::?'b. (?f has_sum x) ?A›*) nonneg_bdd_above_has_sum (*‹⟦⋀x. x ∈ ?A ⟹ 0 ≤ ?f x; bdd_above (sum ?f ` {F. F ⊆ ?A ∧ finite F})⟧ ⟹ (?f has_sum Sup (sum ?f ` {F. finite F ∧ F ⊆ ?A})) ?A›*) by blast lemma nonneg_bdd_above_infsum: fixes f :: ‹'a ⇒ 'b :: {conditionally_complete_linorder, ordered_comm_monoid_add, linorder_topology}› assumes ‹⋀x. x∈A ⟹ f x ≥ 0› assumes ‹bdd_above (sum f ` {F. F⊆A ∧ finite F})› shows ‹infsum f A = (SUP F∈{F. finite F ∧ F⊆A}. sum f F)› using assms (*‹?x ∈ A ⟹ 0 ≤ f ?x› ‹bdd_above (sum f ` {F. F ⊆ A ∧ finite F})›*) by (auto intro!: infsumI (*‹(?f has_sum ?x) ?A ⟹ infsum ?f ?A = ?x›*) nonneg_bdd_above_has_sum (*‹⟦⋀x. x ∈ ?A ⟹ 0 ≤ ?f x; bdd_above (sum ?f ` {F. F ⊆ ?A ∧ finite F})⟧ ⟹ (?f has_sum Sup (sum ?f ` {F. finite F ∧ F ⊆ ?A})) ?A›*)) lemma nonneg_has_sum_complete: fixes f :: ‹'a ⇒ 'b :: {complete_linorder, ordered_comm_monoid_add, linorder_topology}› assumes ‹⋀x. x∈A ⟹ f x ≥ 0› shows ‹(f has_sum (SUP F∈{F. finite F ∧ F⊆A}. sum f F)) A› using assms (*‹?x ∈ A ⟹ 0 ≤ f ?x›*) nonneg_bdd_above_has_sum (*‹⟦⋀x::?'a::type. x ∈ (?A::?'a::type set) ⟹ (0::?'b::{conditionally_complete_linorder,ordered_comm_monoid_add,linorder_topology}) ≤ (?f::?'a::type ⇒ ?'b::{conditionally_complete_linorder,ordered_comm_monoid_add,linorder_topology}) x; bdd_above (sum ?f ` {F::?'a::type set. F ⊆ ?A ∧ finite F})⟧ ⟹ (?f has_sum Sup (sum ?f ` {F::?'a::type set. finite F ∧ F ⊆ ?A})) ?A›*) by blast lemma nonneg_summable_on_complete: fixes f :: ‹'a ⇒ 'b :: {complete_linorder, ordered_comm_monoid_add, linorder_topology}› assumes ‹⋀x. x∈A ⟹ f x ≥ 0› shows ‹f summable_on A› using assms (*‹?x ∈ A ⟹ 0 ≤ f ?x›*) nonneg_bdd_above_summable_on (*‹⟦⋀x. x ∈ ?A ⟹ 0 ≤ ?f x; bdd_above (sum ?f ` {F. F ⊆ ?A ∧ finite F})⟧ ⟹ ?f summable_on ?A›*) by blast lemma nonneg_infsum_complete: fixes f :: ‹'a ⇒ 'b :: {complete_linorder, ordered_comm_monoid_add, linorder_topology}› assumes ‹⋀x. x∈A ⟹ f x ≥ 0› shows ‹infsum f A = (SUP F∈{F. finite F ∧ F⊆A}. sum f F)› using assms (*‹?x ∈ A ⟹ 0 ≤ f ?x›*) nonneg_bdd_above_infsum (*‹⟦⋀x. x ∈ ?A ⟹ 0 ≤ ?f x; bdd_above (sum ?f ` {F. F ⊆ ?A ∧ finite F})⟧ ⟹ infsum ?f ?A = Sup (sum ?f ` {F. finite F ∧ F ⊆ ?A})›*) by blast lemma has_sum_nonneg: fixes f :: "'a ⇒ 'b::{ordered_comm_monoid_add,linorder_topology}" assumes "(f has_sum a) M" and "⋀x. x ∈ M ⟹ 0 ≤ f x" shows "a ≥ 0" by (metis (no_types, lifting) DiffD1 (*‹?c ∈ ?A - ?B ⟹ ?c ∈ ?A›*) assms (*‹(f has_sum a) M› ‹?x ∈ M ⟹ 0 ≤ f ?x›*) empty_iff (*‹(?c ∈ {}) = False›*) has_sum_0 (*‹(⋀x. x ∈ ?M ⟹ ?f x = 0) ⟹ (?f has_sum 0) ?M›*) has_sum_mono_neutral (*‹⟦(?f has_sum ?a) ?A; (?g has_sum ?b) ?B; ⋀x. x ∈ ?A ∩ ?B ⟹ ?f x ≤ ?g x; ⋀x. x ∈ ?A - ?B ⟹ ?f x ≤ 0; ⋀x. x ∈ ?B - ?A ⟹ 0 ≤ ?g x⟧ ⟹ ?a ≤ ?b›*) order_refl (*‹?x ≤ ?x›*)) lemma infsum_nonneg: fixes f :: "'a ⇒ 'b::{ordered_comm_monoid_add,linorder_topology}" assumes "⋀x. x ∈ M ⟹ 0 ≤ f x" shows "infsum f M ≥ 0" (is "?lhs ≥ _") by (metis assms (*‹?x ∈ M ⟹ 0 ≤ f ?x›*) has_sum_infsum (*‹?f summable_on ?S ⟹ (?f has_sum infsum ?f ?S) ?S›*) has_sum_nonneg (*‹⟦(?f has_sum ?a) ?M; ⋀x. x ∈ ?M ⟹ 0 ≤ ?f x⟧ ⟹ 0 ≤ ?a›*) infsum_not_exists (*‹¬ ?f summable_on ?A ⟹ infsum ?f ?A = 0›*) linorder_linear (*‹?x ≤ ?y ∨ ?y ≤ ?x›*)) lemma has_sum_mono2: fixes f :: "'a ⇒ 'b::{topological_ab_group_add, ordered_comm_monoid_add,linorder_topology}" assumes "(f has_sum S) A" "(f has_sum S') B" "A ⊆ B" assumes "⋀x. x ∈ B - A ⟹ f x ≥ 0" shows "S ≤ S'" by (metis add_0 (*‹0 + ?a = ?a›*) add_right_mono (*‹?a ≤ ?b ⟹ ?a + ?c ≤ ?b + ?c›*) assms (*‹(f has_sum S) A› ‹(f has_sum S') B› ‹A ⊆ B› ‹?x ∈ B - A ⟹ 0 ≤ f ?x›*) diff_add_cancel (*‹?a - ?b + ?b = ?a›*) has_sum_Diff (*‹⟦(?f has_sum ?b) ?B; (?f has_sum ?a) ?A; ?A ⊆ ?B⟧ ⟹ (?f has_sum ?b - ?a) (?B - ?A)›*) has_sum_nonneg (*‹⟦(?f has_sum ?a) ?M; ⋀x. x ∈ ?M ⟹ 0 ≤ ?f x⟧ ⟹ 0 ≤ ?a›*)) lemma infsum_mono2: fixes f :: "'a ⇒ 'b::{topological_ab_group_add, ordered_comm_monoid_add,linorder_topology}" assumes "f summable_on A" "f summable_on B" "A ⊆ B" assumes "⋀x. x ∈ B - A ⟹ f x ≥ 0" shows "infsum f A ≤ infsum f B" apply (rule has_sum_mono2[OF has_sum_infsum has_sum_infsum] (*‹⟦?f summable_on ?A; ?f summable_on ?B; ?A ⊆ ?B; ⋀x. x ∈ ?B - ?A ⟹ 0 ≤ ?f x⟧ ⟹ infsum ?f ?A ≤ infsum ?f ?B›*)) (*goals: 1. ‹(f::'a ⇒ 'b) summable_on (A::'a set)› 2. ‹(f::'a ⇒ 'b) summable_on (B::'a set)› 3. ‹(A::'a set) ⊆ (B::'a set)› 4. ‹⋀x::'a. x ∈ (B::'a set) - (A::'a set) ⟹ (0::'b) ≤ (f::'a ⇒ 'b) x› discuss goal 1*) apply ((use assms in auto)[1]) (*discuss goal 2*) apply ((use assms in auto)[1]) (*discuss goal 3*) apply ((use assms in auto)[1]) (*discuss goal 4*) apply ((use assms in auto)[1]) (*proven 4 subgoals*) . lemma finite_sum_le_has_sum: fixes f :: "'a ⇒ 'b::{topological_ab_group_add, ordered_comm_monoid_add,linorder_topology}" assumes "(f has_sum S) A" "finite B" "B ⊆ A" assumes "⋀x. x ∈ A - B ⟹ f x ≥ 0" shows "sum f B ≤ S" by (meson assms (*‹(f has_sum S) A› ‹finite B› ‹B ⊆ A› ‹?x ∈ A - B ⟹ 0 ≤ f ?x›*) has_sum_finite (*‹finite ?F ⟹ (?f has_sum sum ?f ?F) ?F›*) has_sum_mono2 (*‹⟦(?f has_sum ?S) ?A; (?f has_sum ?S') ?B; ?A ⊆ ?B; ⋀x. x ∈ ?B - ?A ⟹ 0 ≤ ?f x⟧ ⟹ ?S ≤ ?S'›*)) lemma finite_sum_le_infsum: fixes f :: "'a ⇒ 'b::{topological_ab_group_add, ordered_comm_monoid_add,linorder_topology}" assumes "f summable_on A" "finite B" "B ⊆ A" assumes "⋀x. x ∈ A - B ⟹ f x ≥ 0" shows "sum f B ≤ infsum f A" apply (rule finite_sum_le_has_sum[OF has_sum_infsum] (*‹⟦?f summable_on ?A; finite ?B; ?B ⊆ ?A; ⋀x. x ∈ ?A - ?B ⟹ 0 ≤ ?f x⟧ ⟹ sum ?f ?B ≤ infsum ?f ?A›*)) (*goals: 1. ‹f summable_on A› 2. ‹finite B› 3. ‹B ⊆ A› 4. ‹⋀x. x ∈ A - B ⟹ 0 ≤ f x› discuss goal 1*) apply ((use assms in auto)[1]) (*discuss goal 2*) apply ((use assms in auto)[1]) (*discuss goal 3*) apply ((use assms in auto)[1]) (*discuss goal 4*) apply ((use assms in auto)[1]) (*proven 4 subgoals*) . lemma has_sum_reindex: assumes ‹inj_on h A› shows ‹(g has_sum x) (h ` A) ⟷ ((g ∘ h) has_sum x) A› proof (-) (*goal: ‹(g has_sum x) (h ` A) = (g ∘ h has_sum x) A›*) have "(g has_sum x) (h ` A) ⟷ (sum g ⤏ x) (finite_subsets_at_top (h ` A))" by (simp add: has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*)) also (*calculation: ‹(g has_sum x) (h ` A) = (sum g ⤏ x) (finite_subsets_at_top (h ` A))›*) have "… ⟷ ((λF. sum g (h ` F)) ⤏ x) (finite_subsets_at_top A)" by (metis assms (*‹inj_on h A›*) filterlim_filtermap (*‹filterlim ?f ?F1.0 (filtermap ?g ?F2.0) = (LIM x ?F2.0. ?f (?g x) :> ?F1.0)›*) filtermap_image_finite_subsets_at_top (*‹inj_on ?f ?A ⟹ filtermap ((`) ?f) (finite_subsets_at_top ?A) = finite_subsets_at_top (?f ` ?A)›*)) also (*calculation: ‹(g has_sum x) (h ` A) = ((λF. sum g (h ` F)) ⤏ x) (finite_subsets_at_top A)›*) have "… ⟷ (sum (g ∘ h) ⤏ x) (finite_subsets_at_top A)" proof (intro tendsto_cong (*‹∀⇩F x in ?F. ?f x = ?g x ⟹ (?f ⤏ ?c) ?F = (?g ⤏ ?c) ?F›*) eventually_finite_subsets_at_top_weakI (*‹(⋀X. ⟦finite X; X ⊆ ?A⟧ ⟹ ?P X) ⟹ eventually ?P (finite_subsets_at_top ?A)›*) sum.reindex (*‹inj_on ?h ?A ⟹ sum ?g (?h ` ?A) = sum (?g ∘ ?h) ?A›*)) (*goal: ‹⋀X. ⟦finite X; X ⊆ A⟧ ⟹ inj_on h X›*) show "⋀X. ⟦finite X; X ⊆ A⟧ ⟹ inj_on h X" using assms (*‹inj_on h A›*) subset_inj_on (*‹⟦inj_on ?f ?B; ?A ⊆ ?B⟧ ⟹ inj_on ?f ?A›*) by blast qed also (*calculation: ‹(g has_sum x) (h ` A) = (sum (g ∘ h) ⤏ x) (finite_subsets_at_top A)›*) have "… ⟷ ((g ∘ h) has_sum x) A" by (simp add: has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*)) finally (*calculation: ‹(g has_sum x) (h ` A) = (g ∘ h has_sum x) A›*) show "?thesis" (*goal: ‹(g has_sum x) (h ` A) = (g ∘ h has_sum x) A›*) . qed lemma summable_on_reindex: assumes ‹inj_on h A› shows ‹g summable_on (h ` A) ⟷ (g ∘ h) summable_on A› by (simp add: assms (*‹inj_on h A›*) summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*) has_sum_reindex (*‹inj_on ?h ?A ⟹ (?g has_sum ?x) (?h ` ?A) = (?g ∘ ?h has_sum ?x) ?A›*)) lemma infsum_reindex: assumes ‹inj_on h A› shows ‹infsum g (h ` A) = infsum (g ∘ h) A› by (metis assms (*‹inj_on h A›*) has_sum_infsum (*‹?f summable_on ?S ⟹ (?f has_sum infsum ?f ?S) ?S›*) has_sum_reindex (*‹inj_on ?h ?A ⟹ (?g has_sum ?x) (?h ` ?A) = (?g ∘ ?h has_sum ?x) ?A›*) infsumI (*‹(?f has_sum ?x) ?A ⟹ infsum ?f ?A = ?x›*) infsum_def (*‹infsum ?f ?A = (if ?f summable_on ?A then Lim (finite_subsets_at_top ?A) (sum ?f) else 0)›*)) lemma summable_on_reindex_bij_betw: assumes "bij_betw g A B" shows "(λx. f (g x)) summable_on A ⟷ f summable_on B" by (smt (verit) assms (*‹bij_betw g A B›*) bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*) o_apply (*‹(?f ∘ ?g) ?x = ?f (?g ?x)›*) summable_on_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ (?f summable_on ?A) = (?g summable_on ?A)›*) summable_on_reindex (*‹inj_on ?h ?A ⟹ (?g summable_on ?h ` ?A) = (?g ∘ ?h summable_on ?A)›*)) lemma infsum_reindex_bij_betw: assumes "bij_betw g A B" shows "infsum (λx. f (g x)) A = infsum f B" by (metis (mono_tags, lifting) assms (*‹bij_betw g A B›*) bij_betw_def (*‹bij_betw ?f ?A ?B = (inj_on ?f ?A ∧ ?f ` ?A = ?B)›*) infsum_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ infsum ?f ?A = infsum ?g ?A›*) infsum_reindex (*‹inj_on ?h ?A ⟹ infsum ?g (?h ` ?A) = infsum (?g ∘ ?h) ?A›*) o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*)) lemma sum_uniformity: assumes plus_cont: ‹uniformly_continuous_on UNIV (λ(x::'b::{uniform_space,comm_monoid_add},y). x+y)› assumes EE: ‹eventually E uniformity› obtains D where ‹eventually D uniformity› and ‹⋀M::'a set. ⋀f f' :: 'a ⇒ 'b. card M ≤ n ∧ (∀m∈M. D (f m, f' m)) ⟹ E (sum f M, sum f' M)› proof (atomize_elim, insert EE (*‹eventually (E::'b::{comm_monoid_add,uniform_space} × 'b::{comm_monoid_add,uniform_space} ⇒ bool) uniformity›*), induction n arbitrary: E rule:nat_induct) (*goals: 1. ‹⋀E. eventually E uniformity ⟹ ∃D. eventually D uniformity ∧ (∀M f f'. card M ≤ 0 ∧ (∀m∈M. D (f m, f' m)) ⟶ E (sum f M, sum f' M))› 2. ‹⋀n E. ⟦⋀E. eventually E uniformity ⟹ ∃D. eventually D uniformity ∧ (∀M f f'. card M ≤ n ∧ (∀m∈M. D (f m, f' m)) ⟶ E (sum f M, sum f' M)); eventually E uniformity⟧ ⟹ ∃D. eventually D uniformity ∧ (∀M f f'. card M ≤ Suc n ∧ (∀m∈M. D (f m, f' m)) ⟶ E (sum f M, sum f' M))›*) case 0 (*‹eventually E uniformity›*) then show "?case" (*goal: ‹∃D. eventually D uniformity ∧ (∀M f f'. card M ≤ 0 ∧ (∀m∈M. D (f m, f' m)) ⟶ E (sum f M, sum f' M))›*) by (metis card_eq_0_iff (*‹(card (?A::?'a::type set) = (0::nat)) = (?A = {} ∨ infinite ?A)›*) equals0D (*‹(?A::?'a::type set) = {} ⟹ (?a::?'a::type) ∉ ?A›*) le_zero_eq (*‹((?n::?'a::canonically_ordered_monoid_add) ≤ (0::?'a::canonically_ordered_monoid_add)) = (?n = (0::?'a::canonically_ordered_monoid_add))›*) sum.infinite (*‹infinite (?A::?'b::type set) ⟹ sum (?g::?'b::type ⇒ ?'a::comm_monoid_add) ?A = (0::?'a::comm_monoid_add)›*) sum.not_neutral_contains_not_neutral (*‹⟦sum (?g::?'b::type ⇒ ?'a::comm_monoid_add) (?A::?'b::type set) ≠ (0::?'a::comm_monoid_add); ⋀a::?'b::type. ⟦a ∈ ?A; ?g a ≠ (0::?'a::comm_monoid_add)⟧ ⟹ ?thesis::bool⟧ ⟹ ?thesis›*) uniformity_refl (*‹eventually (?E::?'a::uniform_space × ?'a::uniform_space ⇒ bool) uniformity ⟹ ?E (?x::?'a::uniform_space, ?x)›*)) next (*goal: ‹⋀n E. ⟦⋀E. eventually E uniformity ⟹ ∃D. eventually D uniformity ∧ (∀M f f'. card M ≤ n ∧ (∀m∈M. D (f m, f' m)) ⟶ E (sum f M, sum f' M)); eventually E uniformity⟧ ⟹ ∃D. eventually D uniformity ∧ (∀M f f'. card M ≤ Suc n ∧ (∀m∈M. D (f m, f' m)) ⟶ E (sum f M, sum f' M))›*) case (Suc n) (*‹eventually ?E uniformity ⟹ ∃D. eventually D uniformity ∧ (∀M f f'. card M ≤ n ∧ (∀m∈M. D (f m, f' m)) ⟶ ?E (sum f M, sum f' M))› ‹eventually E uniformity›*) from plus_cont[unfolded uniformly_continuous_on_uniformity filterlim_def le_filter_def, rule_format, OF Suc.prems] (*‹eventually E (filtermap (λ(x, y). (case x of (x, xa) ⇒ x + xa, case y of (x, xa) ⇒ x + xa)) (uniformity_on UNIV))›*) obtain D1 and D2 where "eventually D1 uniformity" and "eventually D2 uniformity" and D1D2E: "D1 (x, y) ⟹ D2 (x', y') ⟹ E (x + x', y + y')" for x and y and x' and y' (*goal: ‹(⋀D1 D2. ⟦eventually D1 uniformity; eventually D2 uniformity; ⋀x y x' y'. ⟦D1 (x, y); D2 (x', y')⟧ ⟹ E (x + x', y + y')⟧ ⟹ thesis) ⟹ thesis›*) apply atomize_elim (*goal: ‹(⋀D1 D2. ⟦eventually D1 uniformity; eventually D2 uniformity; ⋀x y x' y'. ⟦D1 (x, y); D2 (x', y')⟧ ⟹ E (x + x', y + y')⟧ ⟹ thesis) ⟹ thesis›*) by (auto simp: eventually_prod_filter (*‹eventually ?P (?F ×⇩F ?G) = (∃Pf Pg. eventually Pf ?F ∧ eventually Pg ?G ∧ (∀x y. Pf x ⟶ Pg y ⟶ ?P (x, y)))›*) case_prod_beta (*‹(case ?p of (x, xa) ⇒ ?f x xa) = ?f (fst ?p) (snd ?p)›*) uniformity_prod_def (*‹uniformity = filtermap (λ((x1, x2), y1, y2). ((x1, y1), x2, y2)) (uniformity ×⇩F uniformity)›*) eventually_filtermap (*‹eventually ?P (filtermap ?f ?F) = (∀⇩F x in ?F. ?P (?f x))›*)) from Suc.IH[OF ‹eventually D2 uniformity›] (*‹∃D. eventually D uniformity ∧ (∀M f f'. card M ≤ n ∧ (∀m∈M. D (f m, f' m)) ⟶ D2 (sum f M, sum f' M))›*) obtain D3 where "eventually D3 uniformity" and D3: "card M ≤ n ⟹ (∀m∈M. D3 (f m, f' m)) ⟹ D2 (sum f M, sum f' M)" for M :: "'a set" and f and f' (*goal: ‹(⋀D3. ⟦eventually D3 uniformity; ⋀M f f'. ⟦card M ≤ n; ∀m∈M. D3 (f m, f' m)⟧ ⟹ D2 (sum f M, sum f' M)⟧ ⟹ thesis) ⟹ thesis›*) by metis define D where "D x ≡ D1 x ∧ D3 x" for x have "eventually D uniformity" using D_def (*‹D ?x ≡ D1 ?x ∧ D3 ?x›*) ‹eventually D1 uniformity› (*‹eventually D1 uniformity›*) ‹eventually D3 uniformity› (*‹eventually D3 uniformity›*) eventually_elim2 (*‹⟦eventually ?P ?F; eventually ?Q ?F; ⋀i. ⟦?P i; ?Q i⟧ ⟹ ?R i⟧ ⟹ eventually ?R ?F›*) by blast have "E (sum f M, sum f' M)" if "card M ≤ Suc n" and DM: "∀m∈M. D (f m, f' m)" for M :: "'a set" and f and f' proof (cases ‹card M = 0›) (*goals: 1. ‹card M = 0 ⟹ E (sum f M, sum f' M)› 2. ‹card M ≠ 0 ⟹ E (sum f M, sum f' M)›*) case True (*‹card M = 0›*) then show "?thesis" (*goal: ‹E (sum f M, sum f' M)›*) by (metis Suc.prems (*‹eventually (E::'b::{comm_monoid_add,uniform_space} × 'b::{comm_monoid_add,uniform_space} ⇒ bool) uniformity›*) card_eq_0_iff (*‹(card (?A::?'a::type set) = (0::nat)) = (?A = {} ∨ infinite ?A)›*) sum.empty (*‹sum (?g::?'b::type ⇒ ?'a::comm_monoid_add) {} = (0::?'a::comm_monoid_add)›*) sum.infinite (*‹infinite (?A::?'b::type set) ⟹ sum (?g::?'b::type ⇒ ?'a::comm_monoid_add) ?A = (0::?'a::comm_monoid_add)›*) uniformity_refl (*‹eventually (?E::?'a::uniform_space × ?'a::uniform_space ⇒ bool) uniformity ⟹ ?E (?x::?'a::uniform_space, ?x)›*)) next (*goal: ‹card M ≠ 0 ⟹ E (sum f M, sum f' M)›*) case False (*‹card M ≠ 0›*) with ‹card M ≤ Suc n› (*‹card (M::'a::type set) ≤ Suc (n::nat)›*) obtain N and x where "card N ≤ n" and "x ∉ N" and "M = insert x N" (*goal: ‹(⋀N x. ⟦card N ≤ n; x ∉ N; M = insert x N⟧ ⟹ thesis) ⟹ thesis›*) by (metis card_Suc_eq (*‹(card ?A = Suc ?k) = (∃b B. ?A = insert b B ∧ b ∉ B ∧ card B = ?k ∧ (?k = 0 ⟶ B = {}))›*) less_Suc_eq_0_disj (*‹(?m < Suc ?n) = (?m = 0 ∨ (∃j. ?m = Suc j ∧ j < ?n))›*) less_Suc_eq_le (*‹(?m < Suc ?n) = (?m ≤ ?n)›*)) from DM (*‹∀m∈M. D (f m, f' m)›*) have "⋀m. m∈N ⟹ D (f m, f' m)" using ‹M = insert x N› (*‹M = insert x N›*) by blast with D3[OF ‹card N ≤ n›] (*‹∀m::'a∈N::'a set. (D3::'b × 'b ⇒ bool) ((?f::'a ⇒ 'b) m, (?f'::'a ⇒ 'b) m) ⟹ (D2::'b × 'b ⇒ bool) (sum ?f N, sum ?f' N)›*) have D2_N: "D2 (sum f N, sum f' N)" using D_def (*‹(D::'b × 'b ⇒ bool) (?x::'b × 'b) ≡ (D1::'b × 'b ⇒ bool) ?x ∧ (D3::'b × 'b ⇒ bool) ?x›*) by blast from DM (*‹∀m∈M. D (f m, f' m)›*) have "D (f x, f' x)" using ‹M = insert x N› (*‹M = insert x N›*) by blast then have "D1 (f x, f' x)" by (simp add: D_def (*‹D ?x ≡ D1 ?x ∧ D3 ?x›*)) with D2_N (*‹D2 (sum f N, sum f' N)›*) have "E (f x + sum f N, f' x + sum f' N)" using D1D2E (*‹⟦D1 (?x, ?y); D2 (?x', ?y')⟧ ⟹ E (?x + ?x', ?y + ?y')›*) by presburger then show "E (sum f M, sum f' M)" by (metis False (*‹card (M::'a::type set) ≠ (0::nat)›*) ‹M = insert x N› ‹x ∉ N› card.infinite (*‹infinite (?A::?'a::type set) ⟹ card ?A = (0::nat)›*) finite_insert (*‹finite (insert (?a::?'a::type) (?A::?'a::type set)) = finite ?A›*) sum.insert (*‹⟦finite (?A::?'b::type set); (?x::?'b::type) ∉ ?A⟧ ⟹ sum (?g::?'b::type ⇒ ?'a::comm_monoid_add) (insert ?x ?A) = ?g ?x + sum ?g ?A›*)) qed with ‹eventually D uniformity› (*‹eventually D uniformity›*) show "?case" (*goal: ‹∃D. eventually D uniformity ∧ (∀M f f'. card M ≤ Suc n ∧ (∀m∈M. D (f m, f' m)) ⟶ E (sum f M, sum f' M))›*) by auto qed lemma has_sum_Sigma: fixes A :: "'a set" and B :: "'a ⇒ 'b set" and f :: ‹'a × 'b ⇒ 'c::{comm_monoid_add,uniform_space}› assumes plus_cont: ‹uniformly_continuous_on UNIV (λ(x::'c,y). x+y)› assumes summableAB: "(f has_sum a) (Sigma A B)" assumes summableB: ‹⋀x. x∈A ⟹ ((λy. f (x, y)) has_sum b x) (B x)› shows "(b has_sum a) A" proof (-) (*goal: ‹(b has_sum a) A›*) define F and FB and FA where "F = finite_subsets_at_top (Sigma A B)" and "FB x = finite_subsets_at_top (B x)" and "FA = finite_subsets_at_top A" for x from summableB (*‹?x ∈ A ⟹ ((λy. f (?x, y)) has_sum b ?x) (B ?x)›*) have sum_b: "(sum (λy. f (x, y)) ⤏ b x) (FB x)" if "x ∈ A" for x using FB_def[abs_def] (*‹FB ≡ λx. finite_subsets_at_top (B x)›*) has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*) that (*‹(x::'a) ∈ (A::'a set)›*) by auto from summableAB (*‹(f has_sum a) (Sigma A B)›*) have sum_S: "(sum f ⤏ a) F" using F_def (*‹F = finite_subsets_at_top (Sigma A B)›*) has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*) by blast have finite_proj: "finite {b| b. (a,b) ∈ H}" if "finite H" for H :: "('a×'b) set" and a by (metis (no_types, lifting) finite_imageI (*‹finite ?F ⟹ finite (?h ` ?F)›*) finite_subset (*‹⟦?A ⊆ ?B; finite ?B⟧ ⟹ finite ?A›*) image_eqI (*‹⟦?b = ?f ?x; ?x ∈ ?A⟧ ⟹ ?b ∈ ?f ` ?A›*) mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*) snd_conv (*‹snd (?x1.0, ?x2.0) = ?x2.0›*) subsetI (*‹(⋀x. x ∈ ?A ⟹ x ∈ ?B) ⟹ ?A ⊆ ?B›*) that (*‹finite H›*)) have "(sum b ⤏ a) FA" proof (rule tendsto_iff_uniformity[THEN iffD2, rule_format] (*‹(⋀E. eventually E uniformity ⟹ ∀⇩F x in ?F. E (?f x, ?l)) ⟹ (?f ⤏ ?l) ?F›*)) (*goal: ‹⋀E. eventually E uniformity ⟹ ∀⇩F x in FA. E (sum b x, a)›*) fix E :: "('c × 'c) ⇒ bool" assume "eventually E uniformity" (*‹eventually (E::'c × 'c ⇒ bool) uniformity›*) then obtain D where D_uni: "eventually D uniformity" and DDE': "⋀x y z. D (x, y) ⟹ D (y, z) ⟹ E (x, z)" (*goal: ‹(⋀D::'c × 'c ⇒ bool. ⟦eventually D uniformity; ⋀(x::'c) (y::'c) z::'c. ⟦D (x, y); D (y, z)⟧ ⟹ (E::'c × 'c ⇒ bool) (x, z)⟧ ⟹ thesis::bool) ⟹ thesis›*) by (metis (no_types, lifting) ‹eventually E uniformity› uniformity_transE (*‹⟦eventually ?E uniformity; ⋀D. ⟦eventually D uniformity; ⋀x y z. ⟦D (x, y); D (y, z)⟧ ⟹ ?E (x, z)⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*)) from sum_S (*‹(sum f ⤏ a) F›*) obtain G where "finite G" and "G ⊆ Sigma A B" and G_sum: "G ⊆ H ⟹ H ⊆ Sigma A B ⟹ finite H ⟹ D (sum f H, a)" for H (*goal: ‹(⋀G::('a::type × 'b::type) set. ⟦finite G; G ⊆ Sigma (A::'a::type set) (B::'a::type ⇒ 'b::type set); ⋀H::('a::type × 'b::type) set. ⟦G ⊆ H; H ⊆ Sigma A B; finite H⟧ ⟹ (D::'c::{comm_monoid_add,uniform_space} × 'c::{comm_monoid_add,uniform_space} ⇒ bool) (sum (f::'a::type × 'b::type ⇒ 'c::{comm_monoid_add,uniform_space}) H, a::'c::{comm_monoid_add,uniform_space})⟧ ⟹ thesis::bool) ⟹ thesis›*) unfolding tendsto_iff_uniformity (*goal: ‹(⋀G. ⟦finite G; G ⊆ Sigma A B; ⋀H. ⟦G ⊆ H; H ⊆ Sigma A B; finite H⟧ ⟹ D (sum f H, a)⟧ ⟹ thesis) ⟹ thesis›*) by (metis (mono_tags, lifting) D_uni (*‹eventually D uniformity›*) F_def (*‹F = finite_subsets_at_top (Sigma A B)›*) eventually_finite_subsets_at_top (*‹eventually ?P (finite_subsets_at_top ?A) = (∃X. finite X ∧ X ⊆ ?A ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ ?A ⟶ ?P Y))›*)) have "finite (fst ` G)" and "fst ` G ⊆ A" using ‹finite G› (*‹finite G›*) ‹G ⊆ Sigma A B› (*‹(G::('a × 'b) set) ⊆ Sigma (A::'a set) (B::'a ⇒ 'b set)›*) apply - (*goals: 1. ‹⟦finite G; G ⊆ Sigma A B⟧ ⟹ finite (fst ` G)› 2. ‹⟦finite G; G ⊆ Sigma A B⟧ ⟹ fst ` G ⊆ A› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . thm uniformity_prod_def define Ga where "Ga a = {b. (a,b) ∈ G}" for a have Ga_fin: "finite (Ga a)" and Ga_B: "Ga a ⊆ B a" for a using ‹finite G› (*‹finite G›*) ‹G ⊆ Sigma A B› (*‹G ⊆ Sigma A B›*) finite_proj (*‹finite ?H ⟹ finite {b |b. (?a, b) ∈ ?H}›*) apply - (*goals: 1. ‹⟦finite (G::('a × 'b) set); G ⊆ Sigma (A::'a set) (B::'a ⇒ 'b set); ⋀(H::('a × 'b) set) a::'a. finite H ⟹ finite {b |b::'b. (a, b) ∈ H}⟧ ⟹ finite ((Ga::'a ⇒ 'b set) (a::'a))› 2. ‹⟦finite (G::('a × 'b) set); G ⊆ Sigma (A::'a set) (B::'a ⇒ 'b set); ⋀(H::('a × 'b) set) a::'a. finite H ⟹ finite {b |b::'b. (a, b) ∈ H}⟧ ⟹ (Ga::'a ⇒ 'b set) (a::'a) ⊆ B a› discuss goal 1*) apply ((auto simp: Ga_def (*‹Ga ?a = {b. (?a, b) ∈ G}›*) finite_proj (*‹finite ?H ⟹ finite {b |b. (?a, b) ∈ ?H}›*))[1]) (*discuss goal 2*) apply ((auto simp: Ga_def (*‹(Ga::'a ⇒ 'b set) (?a::'a) = {b::'b. (?a, b) ∈ (G::('a × 'b) set)}›*) finite_proj (*‹finite (?H::('a × 'b) set) ⟹ finite {b |b::'b. (?a::'a, b) ∈ ?H}›*))[1]) (*proven 2 subgoals*) . have "E (sum b M, a)" if "M ⊇ fst ` G" and "finite M" and "M ⊆ A" for M proof (-) (*goal: ‹E (sum b M, a)›*) define FMB where "FMB = finite_subsets_at_top (Sigma M B)" have "eventually (λH. D (∑a∈M. b a, ∑(a,b)∈H. f (a,b))) FMB" proof (-) (*goal: ‹∀⇩F H in FMB. D (sum b M, ∑(a, b)∈H. f (a, b))›*) obtain D' where D'_uni: "eventually D' uniformity" and "card M' ≤ card M ∧ (∀m∈M'. D' (g m, g' m)) ⟹ D (sum g M', sum g' M')" for M' :: "'a set" and g and g' (*goal: ‹(⋀D'::'c::{comm_monoid_add,uniform_space} × 'c::{comm_monoid_add,uniform_space} ⇒ bool. ⟦eventually D' uniformity; ⋀(M'::'a::type set) (g::'a::type ⇒ 'c::{comm_monoid_add,uniform_space}) g'::'a::type ⇒ 'c::{comm_monoid_add,uniform_space}. card M' ≤ card (M::'a::type set) ∧ (∀m::'a::type∈M'. D' (g m, g' m)) ⟹ (D::'c::{comm_monoid_add,uniform_space} × 'c::{comm_monoid_add,uniform_space} ⇒ bool) (sum g M', sum g' M')⟧ ⟹ thesis::bool) ⟹ thesis›*) using sum_uniformity[OF plus_cont ‹eventually D uniformity›] (*‹(⋀Da. ⟦eventually Da uniformity; ⋀M f f'. card M ≤ ?n ∧ (∀m∈M. Da (f m, f' m)) ⟹ D (sum f M, sum f' M)⟧ ⟹ ?thesis) ⟹ ?thesis›*) by blast then have D'_sum_D: "(∀m∈M. D' (g m, g' m)) ⟹ D (sum g M, sum g' M)" for g and g' by auto obtain Ha where "Ha a ⊇ Ga a" and Ha_fin: "finite (Ha a)" and Ha_B: "Ha a ⊆ B a" and D'_sum_Ha: "Ha a ⊆ L ⟹ L ⊆ B a ⟹ finite L ⟹ D' (b a, sum (λb. f (a,b)) L)" if "a ∈ A" for a and L (*goal: ‹(⋀Ha::'a ⇒ 'b set. ⟦⋀a::'a. a ∈ (A::'a set) ⟹ (Ga::'a ⇒ 'b set) a ⊆ Ha a; ⋀a::'a. a ∈ A ⟹ finite (Ha a); ⋀a::'a. a ∈ A ⟹ Ha a ⊆ (B::'a ⇒ 'b set) a; ⋀(a::'a) L::'b set. ⟦a ∈ A; Ha a ⊆ L; L ⊆ B a; finite L⟧ ⟹ (D'::'c × 'c ⇒ bool) ((b::'a ⇒ 'c) a, ∑b::'b∈L. (f::'a × 'b ⇒ 'c) (a, b))⟧ ⟹ thesis::bool) ⟹ thesis›*) proof (-) (*goal: ‹(⋀Ha. ⟦⋀a. a ∈ A ⟹ Ga a ⊆ Ha a; ⋀a. a ∈ A ⟹ finite (Ha a); ⋀a. a ∈ A ⟹ Ha a ⊆ B a; ⋀a L. ⟦a ∈ A; Ha a ⊆ L; L ⊆ B a; finite L⟧ ⟹ D' (b a, ∑b∈L. f (a, b))⟧ ⟹ thesis) ⟹ thesis›*) from sum_b[unfolded tendsto_iff_uniformity, rule_format, OF _ D'_uni [ THEN uniformity_sym ]] (*‹?x ∈ A ⟹ ∀⇩F x in FB ?x. case (∑y∈x. f (?x, y), b ?x) of (x, y) ⇒ D' (y, x)›*) obtain Ha0 where "finite (Ha0 a)" and "Ha0 a ⊆ B a" and "Ha0 a ⊆ L ⟹ L ⊆ B a ⟹ finite L ⟹ D' (b a, sum (λb. f (a,b)) L)" if "a ∈ A" for a and L (*goal: ‹(⋀Ha0. ⟦⋀a. a ∈ A ⟹ finite (Ha0 a); ⋀a. a ∈ A ⟹ Ha0 a ⊆ B a; ⋀a L. ⟦a ∈ A; Ha0 a ⊆ L; L ⊆ B a; finite L⟧ ⟹ D' (b a, ∑b∈L. f (a, b))⟧ ⟹ thesis) ⟹ thesis›*) unfolding FB_def eventually_finite_subsets_at_top (*goal: ‹(⋀Ha0. ⟦⋀a. a ∈ A ⟹ finite (Ha0 a); ⋀a. a ∈ A ⟹ Ha0 a ⊆ B a; ⋀a L. ⟦a ∈ A; Ha0 a ⊆ L; L ⊆ B a; finite L⟧ ⟹ D' (b a, ∑b∈L. f (a, b))⟧ ⟹ thesis) ⟹ thesis›*) unfolding prod.case (*goal: ‹(⋀Ha0. ⟦⋀a. a ∈ A ⟹ finite (Ha0 a); ⋀a. a ∈ A ⟹ Ha0 a ⊆ B a; ⋀a L. ⟦a ∈ A; Ha0 a ⊆ L; L ⊆ B a; finite L⟧ ⟹ D' (b a, ∑b∈L. f (a, b))⟧ ⟹ thesis) ⟹ thesis›*) by metis moreover define Ha where "Ha a = Ha0 a ∪ Ga a" for a ultimately show "?thesis" (*goal: ‹thesis›*) using that[where Ha = Ha] (*‹⟦⋀a. a ∈ A ⟹ Ga a ⊆ Ha a; ⋀a. a ∈ A ⟹ finite (Ha a); ⋀a. a ∈ A ⟹ Ha a ⊆ B a; ⋀a L. ⟦a ∈ A; Ha a ⊆ L; L ⊆ B a; finite L⟧ ⟹ D' (b a, ∑b∈L. f (a, b))⟧ ⟹ thesis›*) using Ga_fin (*‹finite (Ga ?a)›*) Ga_B (*‹(Ga::'a::type ⇒ 'b::type set) (?a::'a::type) ⊆ (B::'a::type ⇒ 'b::type set) ?a›*) by auto qed have "D (∑a∈M. b a, ∑(a,b)∈H. f (a,b))" if "finite H" and "H ⊆ Sigma M B" and "H ⊇ Sigma M Ha" for H proof (-) (*goal: ‹D (sum b M, ∑(a, b)∈H. f (a, b))›*) define Ha' where "Ha' a = {b| b. (a,b) ∈ H}" for a have [simp]: "finite (Ha' a)" and [simp]: "Ha' a ⊇ Ha a" and [simp]: "Ha' a ⊆ B a" if "a ∈ M" for a unfolding Ha'_def (*goals: 1. ‹finite {b |b::'b::type. (a::'a::type, b) ∈ (H::('a::type × 'b::type) set)}› 2. ‹(Ha::'a::type ⇒ 'b::type set) (a::'a::type) ⊆ {b |b::'b::type. (a, b) ∈ (H::('a::type × 'b::type) set)}› 3. ‹{b |b::'b::type. (a::'a::type, b) ∈ (H::('a::type × 'b::type) set)} ⊆ (B::'a::type ⇒ 'b::type set) a›*) using ‹finite H› (*‹finite H›*) ‹H ⊆ Sigma M B› (*‹H ⊆ Sigma M B›*) ‹Sigma M Ha ⊆ H› (*‹Sigma M Ha ⊆ H›*) that (*‹(a::'a) ∈ (M::'a set)›*) finite_proj (*‹finite ?H ⟹ finite {b |b. (?a, b) ∈ ?H}›*) apply - (*goals: 1. ‹⟦finite (H::('a × 'b) set); H ⊆ Sigma (M::'a set) (B::'a ⇒ 'b set); Sigma M (Ha::'a ⇒ 'b set) ⊆ H; (a::'a) ∈ M; ⋀(H::('a × 'b) set) a::'a. finite H ⟹ finite {b |b::'b. (a, b) ∈ H}⟧ ⟹ finite {b |b::'b. (a, b) ∈ H}› 2. ‹⟦finite (H::('a × 'b) set); H ⊆ Sigma (M::'a set) (B::'a ⇒ 'b set); Sigma M (Ha::'a ⇒ 'b set) ⊆ H; (a::'a) ∈ M; ⋀(H::('a × 'b) set) a::'a. finite H ⟹ finite {b |b::'b. (a, b) ∈ H}⟧ ⟹ Ha a ⊆ {b |b::'b. (a, b) ∈ H}› 3. ‹⟦finite (H::('a × 'b) set); H ⊆ Sigma (M::'a set) (B::'a ⇒ 'b set); Sigma M (Ha::'a ⇒ 'b set) ⊆ H; (a::'a) ∈ M; ⋀(H::('a × 'b) set) a::'a. finite H ⟹ finite {b |b::'b. (a, b) ∈ H}⟧ ⟹ {b |b::'b. (a, b) ∈ H} ⊆ B a› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . have "Sigma M Ha' = H" using that (*‹finite H› ‹H ⊆ Sigma M B› ‹Sigma M Ha ⊆ H›*) by (auto simp: Ha'_def (*‹Ha' ?a = {b |b. (?a, b) ∈ H}›*)) then have "*": "(∑(a,b)∈H. f (a,b)) = (∑a∈M. ∑b∈Ha' a. f (a,b))" by (simp add: ‹finite M› sum.Sigma (*‹⟦finite ?A; ∀x∈?A. finite (?B x)⟧ ⟹ (∑x∈?A. sum (?g x) (?B x)) = (∑(x, y)∈Sigma ?A ?B. ?g x y)›*)) have "D' (b a, sum (λb. f (a,b)) (Ha' a))" if "a ∈ M" for a using D'_sum_Ha (*‹⟦(?a::'a) ∈ (A::'a set); (Ha::'a ⇒ 'b set) ?a ⊆ (?L::'b set); ?L ⊆ (B::'a ⇒ 'b set) ?a; finite ?L⟧ ⟹ (D'::'c × 'c ⇒ bool) ((b::'a ⇒ 'c) ?a, ∑b::'b∈?L. (f::'a × 'b ⇒ 'c) (?a, b))›*) ‹M ⊆ A› (*‹M ⊆ A›*) that (*‹a ∈ M›*) by auto then have "D (∑a∈M. b a, ∑a∈M. sum (λb. f (a,b)) (Ha' a))" apply (rule_tac D'_sum_D (*‹∀m∈M. D' (?g m, ?g' m) ⟹ D (sum ?g M, sum ?g' M)›*)) (*goal: ‹D (sum b M, ∑a∈M. ∑b∈Ha' a. f (a, b))›*) by auto with "*" (*‹(∑(a::'a, b::'b)∈(H::('a × 'b) set). (f::'a × 'b ⇒ 'c) (a, b)) = (∑a::'a∈(M::'a set). ∑b::'b∈(Ha'::'a ⇒ 'b set) a. f (a, b))›*) show "?thesis" (*goal: ‹D (sum b M, ∑(a, b)∈H. f (a, b))›*) by auto qed moreover have "Sigma M Ha ⊆ Sigma M B" using Ha_B (*‹?a ∈ A ⟹ Ha ?a ⊆ B ?a›*) ‹M ⊆ A› (*‹M ⊆ A›*) by auto ultimately show "?thesis" (*goal: ‹∀⇩F H in FMB. D (sum b M, ∑(a, b)∈H. f (a, b))›*) unfolding FMB_def eventually_finite_subsets_at_top (*goal: ‹∃X. finite X ∧ X ⊆ Sigma M B ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ Sigma M B ⟶ D (sum b M, ∑(a, b)∈Y. f (a, b)))›*) by (metis (no_types, lifting) Ha_fin (*‹(?a::'a) ∈ (A::'a set) ⟹ finite ((Ha::'a ⇒ 'b set) ?a)›*) finite_SigmaI (*‹⟦finite (?A::?'a set); ⋀a::?'a. a ∈ ?A ⟹ finite ((?B::?'a ⇒ ?'b set) a)⟧ ⟹ finite (Sigma ?A ?B)›*) subsetD (*‹⟦(?A::?'a set) ⊆ (?B::?'a set); (?c::?'a) ∈ ?A⟧ ⟹ ?c ∈ ?B›*) that( (*‹finite (M::'a set)›*) 2) that( (*‹(M::'a set) ⊆ (A::'a set)›*) 3)) qed moreover have "eventually (λH. D (∑(a,b)∈H. f (a,b), a)) FMB" unfolding FMB_def eventually_finite_subsets_at_top (*goal: ‹∃X. finite X ∧ X ⊆ Sigma M B ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ Sigma M B ⟶ D (∑(a, b)∈Y. f (a, b), a))›*) proof (rule exI[of _ G] (*‹?P G ⟹ ∃x. ?P x›*), safe) (*goals: 1. ‹finite G› 2. ‹⋀a b. (a, b) ∈ G ⟹ a ∈ M› 3. ‹⋀a b. (a, b) ∈ G ⟹ b ∈ B a› 4. ‹⋀Y. ⟦finite Y; G ⊆ Y; Y ⊆ Sigma M B⟧ ⟹ D (∑(a, b)∈Y. f (a, b), a)›*) fix Y assume Y: "finite Y" "G ⊆ Y" "Y ⊆ Sigma M B" (*‹finite (Y::('a × 'b) set)› ‹(G::('a × 'b) set) ⊆ (Y::('a × 'b) set)› ‹(Y::('a × 'b) set) ⊆ Sigma (M::'a set) (B::'a ⇒ 'b set)›*) thus "D (∑(a,b)∈Y. f (a, b), a)" using G_sum[of Y] (*‹⟦G ⊆ Y; Y ⊆ Sigma A B; finite Y⟧ ⟹ D (sum f Y, a)›*) Y (*‹finite Y› ‹(G::('a × 'b) set) ⊆ (Y::('a × 'b) set)› ‹Y ⊆ Sigma M B›*) using that(3) (*‹M ⊆ A›*) by fastforce qed (use ‹finite G› ‹G ⊆ Sigma A B› that in auto) (*solves the remaining goals: 1. ‹finite G› 2. ‹⋀a b. (a, b) ∈ G ⟹ a ∈ M› 3. ‹⋀a b. (a, b) ∈ G ⟹ b ∈ B a›*) ultimately have "∀⇩F x in FMB. E (sum b M, a)" apply eventually_elim (*goal: ‹∀⇩F x in FMB. E (sum b M, a)›*) by (use DDE' in auto) then show "E (sum b M, a)" using FMB_def (*‹(FMB::('a × 'b) set filter) = finite_subsets_at_top (Sigma (M::'a set) (B::'a ⇒ 'b set))›*) by force qed then show "∀⇩F x in FA. E (sum b x, a)" using ‹finite (fst ` G)› (*‹finite (fst ` (G::('a × 'b) set))›*) ‹fst ` G ⊆ A› (*‹fst ` G ⊆ A›*) by (metis (mono_tags, lifting) FA_def (*‹FA = finite_subsets_at_top A›*) eventually_finite_subsets_at_top (*‹eventually ?P (finite_subsets_at_top ?A) = (∃X. finite X ∧ X ⊆ ?A ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ ?A ⟶ ?P Y))›*)) qed then show "?thesis" (*goal: ‹(b has_sum a) A›*) by (simp add: FA_def (*‹FA = finite_subsets_at_top A›*) has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*)) qed lemma summable_on_Sigma: fixes A :: "'a set" and B :: "'a ⇒ 'b set" and f :: ‹'a ⇒ 'b ⇒ 'c::{comm_monoid_add, t2_space, uniform_space}› assumes plus_cont: ‹uniformly_continuous_on UNIV (λ(x::'c,y). x+y)› assumes summableAB: "(λ(x,y). f x y) summable_on (Sigma A B)" assumes summableB: ‹⋀x. x∈A ⟹ (f x) summable_on (B x)› shows ‹(λx. infsum (f x) (B x)) summable_on A› proof (-) (*goal: ‹(λx. infsum (f x) (B x)) summable_on A›*) from summableAB (*‹(λ(x, y). f x y) summable_on Sigma A B›*) obtain a where a: "((λ(x,y). f x y) has_sum a) (Sigma A B)" (*goal: ‹(⋀a. ((λ(x, y). f x y) has_sum a) (Sigma A B) ⟹ thesis) ⟹ thesis›*) using has_sum_infsum (*‹(?f::?'a::type ⇒ ?'b::{comm_monoid_add,t2_space}) summable_on (?S::?'a::type set) ⟹ (?f has_sum infsum ?f ?S) ?S›*) by blast from summableB (*‹?x ∈ A ⟹ f ?x summable_on B ?x›*) have b: "⋀x. x∈A ⟹ (f x has_sum infsum (f x) (B x)) (B x)" by (auto intro!: has_sum_infsum (*‹?f summable_on ?S ⟹ (?f has_sum infsum ?f ?S) ?S›*)) show "?thesis" (*goal: ‹(λx. infsum (f x) (B x)) summable_on A›*) using plus_cont (*‹uniformly_continuous_on UNIV (λ(x::'c::{comm_monoid_add,t2_space,uniform_space}, y::'c::{comm_monoid_add,t2_space,uniform_space}). x + y)›*) a (*‹((λ(x, y). f x y) has_sum a) (Sigma A B)›*) b (*‹?x ∈ A ⟹ (f ?x has_sum infsum (f ?x) (B ?x)) (B ?x)›*) by (smt (verit) has_sum_Sigma[where f=‹λ(x,y). f x y›] (*‹⟦uniformly_continuous_on UNIV (λ(x, y). x + y); ((λ(x, y). f x y) has_sum ?a) (Sigma ?A ?B); ⋀x. x ∈ ?A ⟹ ((λy. case (x, y) of (x, y) ⇒ f x y) has_sum ?b x) (?B x)⟧ ⟹ (?b has_sum ?a) ?A›*) has_sum_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ (?f has_sum ?x) ?A = (?g has_sum ?x) ?A›*) old.prod.case (*‹(case (?x1.0, ?x2.0) of (x, xa) ⇒ ?f x xa) = ?f ?x1.0 ?x2.0›*) summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*)) qed lemma infsum_Sigma: fixes A :: "'a set" and B :: "'a ⇒ 'b set" and f :: ‹'a × 'b ⇒ 'c::{comm_monoid_add, t2_space, uniform_space}› assumes plus_cont: ‹uniformly_continuous_on UNIV (λ(x::'c,y). x+y)› assumes summableAB: "f summable_on (Sigma A B)" assumes summableB: ‹⋀x. x∈A ⟹ (λy. f (x, y)) summable_on (B x)› shows "infsum f (Sigma A B) = infsum (λx. infsum (λy. f (x, y)) (B x)) A" proof (-) (*goal: ‹infsum (f::'a × 'b ⇒ 'c) (Sigma (A::'a set) (B::'a ⇒ 'b set)) = (∑⇩∞x::'a∈A. ∑⇩∞y::'b∈B x. f (x, y))›*) from summableAB (*‹(f::'a::type × 'b::type ⇒ 'c::{comm_monoid_add,t2_space,uniform_space}) summable_on Sigma (A::'a::type set) (B::'a::type ⇒ 'b::type set)›*) have a: "(f has_sum infsum f (Sigma A B)) (Sigma A B)" using has_sum_infsum (*‹?f summable_on ?S ⟹ (?f has_sum infsum ?f ?S) ?S›*) by blast from summableB (*‹(?x::'a) ∈ (A::'a set) ⟹ (λy::'b. (f::'a × 'b ⇒ 'c) (?x, y)) summable_on (B::'a ⇒ 'b set) ?x›*) have b: "⋀x. x∈A ⟹ ((λy. f (x, y)) has_sum infsum (λy. f (x, y)) (B x)) (B x)" by (auto intro!: has_sum_infsum (*‹?f summable_on ?S ⟹ (?f has_sum infsum ?f ?S) ?S›*)) show "?thesis" (*goal: ‹infsum f (Sigma A B) = (∑⇩∞x∈A. ∑⇩∞y∈B x. f (x, y))›*) using plus_cont (*‹uniformly_continuous_on UNIV (λ(x, y). x + y)›*) a (*‹(f has_sum infsum f (Sigma A B)) (Sigma A B)›*) b (*‹?x ∈ A ⟹ ((λy. f (?x, y)) has_sum (∑⇩∞y∈B ?x. f (?x, y))) (B ?x)›*) by (auto intro: infsumI[symmetric] (*‹((?f::?'a::type ⇒ ?'b::{comm_monoid_add,t2_space}) has_sum (?t::?'b::{comm_monoid_add,t2_space})) (?A::?'a::type set) ⟹ ?t = infsum ?f ?A›*) has_sum_Sigma (*‹⟦uniformly_continuous_on UNIV (λ(x::?'c::{comm_monoid_add,uniform_space}, y::?'c::{comm_monoid_add,uniform_space}). x + y); ((?f::?'a::type × ?'b::type ⇒ ?'c::{comm_monoid_add,uniform_space}) has_sum (?a::?'c::{comm_monoid_add,uniform_space})) (Sigma (?A::?'a::type set) (?B::?'a::type ⇒ ?'b::type set)); ⋀x::?'a::type. x ∈ ?A ⟹ ((λy::?'b::type. ?f (x, y)) has_sum (?b::?'a::type ⇒ ?'c::{comm_monoid_add,uniform_space}) x) (?B x)⟧ ⟹ (?b has_sum ?a) ?A›*) simp: summable_on_def (*‹(?f::?'a::type ⇒ ?'b::{comm_monoid_add,topological_space}) summable_on (?A::?'a::type set) ≡ ∃x::?'b::{comm_monoid_add,topological_space}. (?f has_sum x) ?A›*)) qed lemma infsum_Sigma': fixes A :: "'a set" and B :: "'a ⇒ 'b set" and f :: ‹'a ⇒ 'b ⇒ 'c::{comm_monoid_add, t2_space, uniform_space}› assumes plus_cont: ‹uniformly_continuous_on UNIV (λ(x::'c,y). x+y)› assumes summableAB: "(λ(x,y). f x y) summable_on (Sigma A B)" assumes summableB: ‹⋀x. x∈A ⟹ (f x) summable_on (B x)› shows ‹infsum (λx. infsum (f x) (B x)) A = infsum (λ(x,y). f x y) (Sigma A B)› using infsum_Sigma[of ‹λ(x,y). f x y› A B] (*‹⟦uniformly_continuous_on UNIV (λ(x, y). x + y); (λ(x, y). f x y) summable_on Sigma A B; ⋀x. x ∈ A ⟹ (λy. case (x, y) of (x, y) ⇒ f x y) summable_on B x⟧ ⟹ (∑⇩∞(x, y)∈Sigma A B. f x y) = (∑⇩∞x∈A. ∑⇩∞y∈B x. case (x, y) of (x, y) ⇒ f x y)›*) using assms (*‹uniformly_continuous_on UNIV (λ(x, y). x + y)› ‹(λ(x, y). f x y) summable_on Sigma A B› ‹?x ∈ A ⟹ f ?x summable_on B ?x›*) by auto text ‹A special case of @{thm [source] infsum_Sigma} etc. for Banach spaces. It has less premises.› lemma fixes A :: "'a set" and B :: "'a ⇒ 'b set" and f :: ‹'a ⇒ 'b ⇒ 'c::banach› assumes [simp]: "(λ(x,y). f x y) summable_on (Sigma A B)" shows infsum_Sigma'_banach: ‹infsum (λx. infsum (f x) (B x)) A = infsum (λ(x,y). f x y) (Sigma A B)› (is ?thesis1) and summable_on_Sigma_banach: ‹(λx. infsum (f x) (B x)) summable_on A› (is ?thesis2) proof (-) (*goals: 1. ‹(∑⇩∞x::'a::type∈(A::'a::type set). infsum ((f::'a::type ⇒ 'b::type ⇒ 'c::banach) x) ((B::'a::type ⇒ 'b::type set) x)) = (∑⇩∞(x::'a::type, y::'b::type)∈Sigma A B. f x y)› 2. ‹(λx::'a::type. infsum ((f::'a::type ⇒ 'b::type ⇒ 'c::banach) x) ((B::'a::type ⇒ 'b::type set) x)) summable_on (A::'a::type set)›*) have fsum: "(f x) summable_on (B x)" if "x ∈ A" for x proof (-) (*goal: ‹f x summable_on B x›*) from assms (*‹(λ(x, y). f x y) summable_on Sigma A B›*) have "(λ(x,y). f x y) summable_on (Pair x ` B x)" by (meson image_subset_iff (*‹((?f::?'b ⇒ ?'a) ` (?A::?'b set) ⊆ (?B::?'a set)) = (∀x::?'b∈?A. ?f x ∈ ?B)›*) summable_on_subset_banach (*‹⟦(?f::?'a ⇒ ?'b) summable_on (?A::?'a set); (?B::?'a set) ⊆ ?A⟧ ⟹ ?f summable_on ?B›*) mem_Sigma_iff (*‹((?a::?'a, ?b::?'b) ∈ Sigma (?A::?'a set) (?B::?'a ⇒ ?'b set)) = (?a ∈ ?A ∧ ?b ∈ ?B ?a)›*) that (*‹(x::'a) ∈ (A::'a set)›*)) then have "((λ(x,y). f x y) ∘ Pair x) summable_on (B x)" by (metis summable_on_reindex (*‹inj_on ?h ?A ⟹ (?g summable_on ?h ` ?A) = (?g ∘ ?h summable_on ?A)›*) inj_on_def (*‹inj_on ?f ?A = (∀x∈?A. ∀y∈?A. ?f x = ?f y ⟶ x = y)›*) prod.inject (*‹((?x1.0, ?x2.0) = (?y1.0, ?y2.0)) = (?x1.0 = ?y1.0 ∧ ?x2.0 = ?y2.0)›*)) then show "?thesis" (*goal: ‹f x summable_on B x›*) by (auto simp: o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*)) qed show "?thesis1" (*goal: ‹(∑⇩∞x∈A. infsum (f x) (B x)) = (∑⇩∞(x, y)∈Sigma A B. f x y)›*) using fsum (*‹?x ∈ A ⟹ f ?x summable_on B ?x›*) assms (*‹(λ(x, y). f x y) summable_on Sigma A B›*) infsum_Sigma' (*‹⟦uniformly_continuous_on UNIV (λ(x::?'c, y::?'c). x + y); (λ(x::?'a, y::?'b). (?f::?'a ⇒ ?'b ⇒ ?'c) x y) summable_on Sigma (?A::?'a set) (?B::?'a ⇒ ?'b set); ⋀x::?'a. x ∈ ?A ⟹ ?f x summable_on ?B x⟧ ⟹ (∑⇩∞x::?'a∈?A. infsum (?f x) (?B x)) = (∑⇩∞(x::?'a, y::?'b)∈Sigma ?A ?B. ?f x y)›*) isUCont_plus (*‹isUCont (λ(x, y). x + y)›*) by blast show "?thesis2" (*goal: ‹(λx::'a. infsum ((f::'a ⇒ 'b ⇒ 'c) x) ((B::'a ⇒ 'b set) x)) summable_on (A::'a set)›*) using fsum (*‹?x ∈ A ⟹ f ?x summable_on B ?x›*) assms (*‹(λ(x, y). f x y) summable_on Sigma A B›*) isUCont_plus (*‹isUCont (λ(x, y). x + y)›*) summable_on_Sigma (*‹⟦uniformly_continuous_on UNIV (λ(x, y). x + y); (λ(x, y). ?f x y) summable_on Sigma ?A ?B; ⋀x. x ∈ ?A ⟹ ?f x summable_on ?B x⟧ ⟹ (λx. infsum (?f x) (?B x)) summable_on ?A›*) by blast qed lemma infsum_Sigma_banach: fixes A :: "'a set" and B :: "'a ⇒ 'b set" and f :: ‹'a × 'b ⇒ 'c::banach› assumes [simp]: "f summable_on (Sigma A B)" shows ‹infsum (λx. infsum (λy. f (x,y)) (B x)) A = infsum f (Sigma A B)› using assms (*‹f summable_on Sigma A B›*) by (simp add: infsum_Sigma'_banach (*‹(λ(x, y). ?f x y) summable_on Sigma ?A ?B ⟹ (∑⇩∞x∈?A. infsum (?f x) (?B x)) = (∑⇩∞(x, y)∈Sigma ?A ?B. ?f x y)›*)) lemma infsum_swap: fixes A :: "'a set" and B :: "'b set" fixes f :: "'a ⇒ 'b ⇒ 'c::{comm_monoid_add,t2_space,uniform_space}" assumes plus_cont: ‹uniformly_continuous_on UNIV (λ(x::'c,y). x+y)› assumes ‹(λ(x, y). f x y) summable_on (A × B)› assumes ‹⋀a. a∈A ⟹ (f a) summable_on B› assumes ‹⋀b. b∈B ⟹ (λa. f a b) summable_on A› shows ‹infsum (λx. infsum (λy. f x y) B) A = infsum (λy. infsum (λx. f x y) A) B› proof (-) (*goal: ‹(∑⇩∞x::'a∈(A::'a set). infsum ((f::'a ⇒ 'b ⇒ 'c) x) (B::'b set)) = (∑⇩∞y::'b∈B. ∑⇩∞x::'a∈A. f x y)›*) have "(λ(x, y). f y x) ∘ prod.swap summable_on A × B" by (simp add: assms( (*‹(λ(x, y). f x y) summable_on A × B›*) 2) summable_on_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ (?f summable_on ?A) = (?g summable_on ?A)›*)) then have fyx: "(λ(x, y). f y x) summable_on (B × A)" by (metis has_sum_reindex (*‹inj_on ?h ?A ⟹ (?g has_sum ?x) (?h ` ?A) = (?g ∘ ?h has_sum ?x) ?A›*) infsum_reindex (*‹inj_on ?h ?A ⟹ infsum ?g (?h ` ?A) = infsum (?g ∘ ?h) ?A›*) inj_swap (*‹inj_on prod.swap ?A›*) product_swap (*‹prod.swap ` (?A × ?B) = ?B × ?A›*) summable_iff_has_sum_infsum (*‹(?f summable_on ?A) = (?f has_sum infsum ?f ?A) ?A›*)) have "infsum (λx. infsum (λy. f x y) B) A = infsum (λ(x,y). f x y) (A × B)" using assms (*‹uniformly_continuous_on UNIV (λ(x, y). x + y)› ‹(λ(x, y). f x y) summable_on A × B› ‹?a ∈ A ⟹ f ?a summable_on B› ‹?b ∈ B ⟹ (λa. f a ?b) summable_on A›*) infsum_Sigma' (*‹⟦uniformly_continuous_on UNIV (λ(x, y). x + y); (λ(x, y). ?f x y) summable_on Sigma ?A ?B; ⋀x. x ∈ ?A ⟹ ?f x summable_on ?B x⟧ ⟹ (∑⇩∞x∈?A. infsum (?f x) (?B x)) = (∑⇩∞(x, y)∈Sigma ?A ?B. ?f x y)›*) by blast also (*calculation: ‹(∑⇩∞x∈A. infsum (f x) B) = (∑⇩∞(x, y)∈A × B. f x y)›*) have "… = infsum (λ(x,y). f y x) (B × A)" apply (subst product_swap[symmetric] (*‹?B × ?A = prod.swap ` (?A × ?B)›*)) (*goal: ‹(∑⇩∞(x, y)∈A × B. f x y) = (∑⇩∞(x, y)∈B × A. f y x)›*) apply (subst infsum_reindex (*‹inj_on ?h ?A ⟹ infsum ?g (?h ` ?A) = infsum (?g ∘ ?h) ?A›*)) (*goal: ‹(∑⇩∞(x, y)∈prod.swap ` (B × A). f x y) = (∑⇩∞(x, y)∈B × A. f y x)›*) using assms (*‹uniformly_continuous_on UNIV (λ(x, y). x + y)› ‹(λ(x, y). f x y) summable_on A × B› ‹?a ∈ A ⟹ f ?a summable_on B› ‹?b ∈ B ⟹ (λa. f a ?b) summable_on A›*) (*goals: 1. ‹inj_on prod.swap (B × A)› 2. ‹infsum ((λ(x, y). f x y) ∘ prod.swap) (B × A) = (∑⇩∞(x, y)∈B × A. f y x)› discuss goal 1*) apply ((auto simp: o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*))[1]) (*discuss goal 2*) apply ((auto simp: o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*))[1]) (*proven 2 subgoals*) . also (*calculation: ‹(∑⇩∞x::'a∈(A::'a set). infsum ((f::'a ⇒ 'b ⇒ 'c) x) (B::'b set)) = (∑⇩∞(x::'b, y::'a)∈B × A. f y x)›*) have "… = infsum (λy. infsum (λx. f x y) A) B" by (smt (verit) fyx (*‹(λ(x::'b, y::'a). (f::'a ⇒ 'b ⇒ 'c) y x) summable_on (B::'b set) × (A::'a set)›*) assms( (*‹uniformly_continuous_on UNIV (λ(x::'c, y::'c). x + y)›*) 1) assms( (*‹(?b::'b) ∈ (B::'b set) ⟹ (λa::'a. (f::'a ⇒ 'b ⇒ 'c) a ?b) summable_on (A::'a set)›*) 4) infsum_Sigma' (*‹⟦uniformly_continuous_on UNIV (λ(x::?'c, y::?'c). x + y); (λ(x::?'a, y::?'b). (?f::?'a ⇒ ?'b ⇒ ?'c) x y) summable_on Sigma (?A::?'a set) (?B::?'a ⇒ ?'b set); ⋀x::?'a. x ∈ ?A ⟹ ?f x summable_on ?B x⟧ ⟹ (∑⇩∞x::?'a∈?A. infsum (?f x) (?B x)) = (∑⇩∞(x::?'a, y::?'b)∈Sigma ?A ?B. ?f x y)›*) infsum_cong (*‹(⋀x::?'a. x ∈ (?A::?'a set) ⟹ (?f::?'a ⇒ ?'b) x = (?g::?'a ⇒ ?'b) x) ⟹ infsum ?f ?A = infsum ?g ?A›*)) finally (*calculation: ‹(∑⇩∞x∈A. infsum (f x) B) = (∑⇩∞y∈B. ∑⇩∞x∈A. f x y)›*) show "?thesis" (*goal: ‹(∑⇩∞x::'a::type∈(A::'a::type set). infsum ((f::'a::type ⇒ 'b::type ⇒ 'c::{comm_monoid_add,t2_space,uniform_space}) x) (B::'b::type set)) = (∑⇩∞y::'b::type∈B. ∑⇩∞x::'a::type∈A. f x y)›*) . qed lemma infsum_swap_banach: fixes A :: "'a set" and B :: "'b set" fixes f :: "'a ⇒ 'b ⇒ 'c::banach" assumes ‹(λ(x, y). f x y) summable_on (A × B)› shows "infsum (λx. infsum (λy. f x y) B) A = infsum (λy. infsum (λx. f x y) A) B" proof (-) (*goal: ‹(∑⇩∞x∈A. infsum (f x) B) = (∑⇩∞y∈B. ∑⇩∞x∈A. f x y)›*) have "§": "(λ(x, y). f y x) summable_on (B × A)" by (metis (mono_tags, lifting) assms (*‹(λ(x, y). f x y) summable_on A × B›*) case_swap (*‹(case prod.swap ?p of (y, x) ⇒ ?f x y) = (case ?p of (x, y) ⇒ ?f x y)›*) inj_swap (*‹inj_on prod.swap ?A›*) o_apply (*‹(?f ∘ ?g) ?x = ?f (?g ?x)›*) product_swap (*‹prod.swap ` (?A × ?B) = ?B × ?A›*) summable_on_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ (?f summable_on ?A) = (?g summable_on ?A)›*) summable_on_reindex (*‹inj_on ?h ?A ⟹ (?g summable_on ?h ` ?A) = (?g ∘ ?h summable_on ?A)›*)) have "infsum (λx. infsum (λy. f x y) B) A = infsum (λ(x,y). f x y) (A × B)" using assms (*‹(λ(x, y). f x y) summable_on A × B›*) infsum_Sigma'_banach (*‹(λ(x, y). ?f x y) summable_on Sigma ?A ?B ⟹ (∑⇩∞x∈?A. infsum (?f x) (?B x)) = (∑⇩∞(x, y)∈Sigma ?A ?B. ?f x y)›*) by blast also (*calculation: ‹(∑⇩∞x∈A. infsum (f x) B) = (∑⇩∞(x, y)∈A × B. f x y)›*) have "… = infsum (λ(x,y). f y x) (B × A)" apply (subst product_swap[symmetric] (*‹?B × ?A = prod.swap ` (?A × ?B)›*)) (*goal: ‹(∑⇩∞(x::'a, y::'b)∈(A::'a set) × (B::'b set). (f::'a ⇒ 'b ⇒ 'c) x y) = (∑⇩∞(x::'b, y::'a)∈B × A. f y x)›*) apply (subst infsum_reindex (*‹inj_on ?h ?A ⟹ infsum ?g (?h ` ?A) = infsum (?g ∘ ?h) ?A›*)) (*goal: ‹(∑⇩∞(x, y)∈prod.swap ` (B × A). f x y) = (∑⇩∞(x, y)∈B × A. f y x)›*) using assms (*‹(λ(x, y). f x y) summable_on A × B›*) (*goals: 1. ‹inj_on prod.swap (B × A)› 2. ‹infsum ((λ(x, y). f x y) ∘ prod.swap) (B × A) = (∑⇩∞(x, y)∈B × A. f y x)› discuss goal 1*) apply ((auto simp: o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*))[1]) (*discuss goal 2*) apply ((auto simp: o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*))[1]) (*proven 2 subgoals*) . also (*calculation: ‹(∑⇩∞x∈A. infsum (f x) B) = (∑⇩∞(x, y)∈B × A. f y x)›*) have "… = infsum (λy. infsum (λx. f x y) A) B" by (metis (mono_tags, lifting) § (*‹(λ(x, y). f y x) summable_on B × A›*) infsum_Sigma'_banach (*‹(λ(x, y). ?f x y) summable_on Sigma ?A ?B ⟹ (∑⇩∞x∈?A. infsum (?f x) (?B x)) = (∑⇩∞(x, y)∈Sigma ?A ?B. ?f x y)›*) infsum_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ infsum ?f ?A = infsum ?g ?A›*)) finally (*calculation: ‹(∑⇩∞x∈A. infsum (f x) B) = (∑⇩∞y∈B. ∑⇩∞x∈A. f x y)›*) show "?thesis" (*goal: ‹(∑⇩∞x∈A. infsum (f x) B) = (∑⇩∞y∈B. ∑⇩∞x∈A. f x y)›*) . qed lemma nonneg_infsum_le_0D: fixes f :: "'a ⇒ 'b::{topological_ab_group_add,ordered_ab_group_add,linorder_topology}" assumes "infsum f A ≤ 0" and abs_sum: "f summable_on A" and nneg: "⋀x. x ∈ A ⟹ f x ≥ 0" and "x ∈ A" shows "f x = 0" proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹f x ≠ 0 ⟹ False›*) assume "f x ≠ 0" (*‹(f::'a ⇒ 'b) (x::'a) ≠ (0::'b)›*) have ex: "f summable_on (A-{x})" apply (rule summable_on_cofin_subset (*‹⟦?f summable_on ?A; finite ?F⟧ ⟹ ?f summable_on ?A - ?F›*)) (*goals: 1. ‹f summable_on A› 2. ‹finite {x}› discuss goal 1*) apply ((use assms in auto)[1]) (*discuss goal 2*) apply ((use assms in auto)[1]) (*proven 2 subgoals*) . have pos: "infsum f (A - {x}) ≥ 0" apply (rule infsum_nonneg (*‹(⋀x. x ∈ ?M ⟹ 0 ≤ ?f x) ⟹ 0 ≤ infsum ?f ?M›*)) (*goal: ‹(0::'b) ≤ infsum (f::'a ⇒ 'b) ((A::'a set) - {x::'a})›*) by (use nneg in auto) have [trans]: "x ≥ y ⟹ y > z ⟹ x > z" for x :: 'b and y :: 'b and z :: 'b by auto have "infsum f A = infsum f (A-{x}) + infsum f {x}" apply (subst infsum_Un_disjoint[symmetric] (*‹⟦(?f::?'a ⇒ ?'b) summable_on (?A::?'a set); ?f summable_on (?B::?'a set); ?A ∩ ?B = {}⟧ ⟹ infsum ?f ?A + infsum ?f ?B = infsum ?f (?A ∪ ?B)›*)) (*goals: 1. ‹f summable_on A - {x}› 2. ‹f summable_on {x}› 3. ‹(A - {x}) ∩ {x} = {}› 4. ‹infsum f A = infsum f (A - {x} ∪ {x})› discuss goal 1*) apply ((use assms ex in ‹auto simp: insert_absorb›)[1]) (*discuss goal 2*) apply ((use assms ex in ‹auto simp: insert_absorb›)[1]) (*discuss goal 3*) apply ((use assms ex in ‹auto simp: insert_absorb›)[1]) (*discuss goal 4*) apply ((use assms ex in ‹auto simp: insert_absorb›)[1]) (*proven 4 subgoals*) . also (*calculation: ‹infsum f A = infsum f (A - {x}) + infsum f {x}›*) have "… ≥ infsum f {x}" (is "_ ≥ …") using pos (*‹0 ≤ infsum f (A - {x})›*) apply (rule add_increasing (*‹⟦0 ≤ ?a; ?b ≤ ?c⟧ ⟹ ?b ≤ ?a + ?c›*)) (*goal: ‹infsum f {x} ≤ infsum f (A - {x}) + infsum f {x}›*) by simp also (*calculation: ‹infsum f {x} ≤ infsum f A›*) have "… = f x" (is "_ = …") apply (subst infsum_finite (*‹finite ?F ⟹ infsum ?f ?F = sum ?f ?F›*)) (*goals: 1. ‹finite {x}› 2. ‹sum f {x} = f x› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . also (*calculation: ‹f x ≤ infsum f A›*) have "… > 0" using ‹f x ≠ 0› (*‹f x ≠ 0›*) assms(4) (*‹x ∈ A›*) nneg (*‹?x ∈ A ⟹ 0 ≤ f ?x›*) by fastforce finally (*calculation: ‹0 < infsum f A›*) show False using assms (*‹infsum (f::'a ⇒ 'b) (A::'a set) ≤ (0::'b)› ‹(f::'a ⇒ 'b) summable_on (A::'a set)› ‹?x ∈ A ⟹ 0 ≤ f ?x› ‹(x::'a) ∈ (A::'a set)›*) by auto qed lemma nonneg_has_sum_le_0D: fixes f :: "'a ⇒ 'b::{topological_ab_group_add,ordered_ab_group_add,linorder_topology}" assumes "(f has_sum a) A" ‹a ≤ 0› and "⋀x. x ∈ A ⟹ f x ≥ 0" and "x ∈ A" shows "f x = 0" by (metis assms (*‹(f has_sum a) A› ‹a ≤ 0› ‹?x ∈ A ⟹ 0 ≤ f ?x› ‹x ∈ A›*) infsumI (*‹(?f has_sum ?x) ?A ⟹ infsum ?f ?A = ?x›*) nonneg_infsum_le_0D (*‹⟦infsum ?f ?A ≤ 0; ?f summable_on ?A; ⋀x. x ∈ ?A ⟹ 0 ≤ ?f x; ?x ∈ ?A⟧ ⟹ ?f ?x = 0›*) summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*)) lemma has_sum_cmult_left: fixes f :: "'a ⇒ 'b :: {topological_semigroup_mult, semiring_0}" assumes ‹(f has_sum a) A› shows "((λx. f x * c) has_sum (a * c)) A" using assms (*‹(f has_sum a) A›*) tendsto_mult_right (*‹(?f ⤏ ?l) ?F ⟹ ((λx. ?f x * ?c) ⤏ ?l * ?c) ?F›*) by (force simp add: has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*) sum_distrib_right (*‹sum ?f ?A * ?r = (∑n∈?A. ?f n * ?r)›*)) lemma infsum_cmult_left: fixes f :: "'a ⇒ 'b :: {t2_space, topological_semigroup_mult, semiring_0}" assumes ‹c ≠ 0 ⟹ f summable_on A› shows "infsum (λx. f x * c) A = infsum f A * c" using assms (*‹c ≠ 0 ⟹ f summable_on A›*) has_sum_cmult_left (*‹(?f has_sum ?a) ?A ⟹ ((λx. ?f x * ?c) has_sum ?a * ?c) ?A›*) infsumI (*‹(?f has_sum ?x) ?A ⟹ infsum ?f ?A = ?x›*) summable_iff_has_sum_infsum (*‹(?f summable_on ?A) = (?f has_sum infsum ?f ?A) ?A›*) by fastforce lemma summable_on_cmult_left: fixes f :: "'a ⇒ 'b :: {t2_space, topological_semigroup_mult, semiring_0}" assumes ‹f summable_on A› shows "(λx. f x * c) summable_on A" using assms (*‹f summable_on A›*) summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*) has_sum_cmult_left (*‹(?f has_sum ?a) ?A ⟹ ((λx. ?f x * ?c) has_sum ?a * ?c) ?A›*) by blast lemma has_sum_cmult_right: fixes f :: "'a ⇒ 'b :: {topological_semigroup_mult, semiring_0}" assumes ‹(f has_sum a) A› shows "((λx. c * f x) has_sum (c * a)) A" using assms (*‹(f has_sum a) A›*) tendsto_mult_left (*‹(?f ⤏ ?l) ?F ⟹ ((λx. ?c * ?f x) ⤏ ?c * ?l) ?F›*) by (force simp add: has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*) sum_distrib_left (*‹?r * sum ?f ?A = (∑n∈?A. ?r * ?f n)›*)) lemma infsum_cmult_right: fixes f :: "'a ⇒ 'b :: {t2_space, topological_semigroup_mult, semiring_0}" assumes ‹c ≠ 0 ⟹ f summable_on A› shows ‹infsum (λx. c * f x) A = c * infsum f A› using assms (*‹c ≠ 0 ⟹ f summable_on A›*) has_sum_cmult_right (*‹(?f has_sum ?a) ?A ⟹ ((λx. ?c * ?f x) has_sum ?c * ?a) ?A›*) infsumI (*‹(?f has_sum ?x) ?A ⟹ infsum ?f ?A = ?x›*) summable_iff_has_sum_infsum (*‹(?f summable_on ?A) = (?f has_sum infsum ?f ?A) ?A›*) by fastforce lemma summable_on_cmult_right: fixes f :: "'a ⇒ 'b :: {t2_space, topological_semigroup_mult, semiring_0}" assumes ‹f summable_on A› shows "(λx. c * f x) summable_on A" using assms (*‹f summable_on A›*) summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*) has_sum_cmult_right (*‹(?f has_sum ?a) ?A ⟹ ((λx. ?c * ?f x) has_sum ?c * ?a) ?A›*) by blast lemma summable_on_cmult_left': fixes f :: "'a ⇒ 'b :: {t2_space, topological_semigroup_mult, division_ring}" assumes ‹c ≠ 0› shows "(λx. f x * c) summable_on A ⟷ f summable_on A" proof (standard) (*goals: 1. ‹(λx. f x * c) summable_on A ⟹ f summable_on A› 2. ‹f summable_on A ⟹ (λx. f x * c) summable_on A›*) assume "f summable_on A" (*‹(f::'a ⇒ 'b) summable_on (A::'a set)›*) then show "(λx. f x * c) summable_on A" by (rule summable_on_cmult_left (*‹?f summable_on ?A ⟹ (λx. ?f x * ?c) summable_on ?A›*)) next (*goal: ‹(λx. f x * c) summable_on A ⟹ f summable_on A›*) assume "(λx. f x * c) summable_on A" (*‹(λx::'a. (f::'a ⇒ 'b) x * (c::'b)) summable_on (A::'a set)›*) then have "(λx. f x * c * inverse c) summable_on A" by (rule summable_on_cmult_left (*‹?f summable_on ?A ⟹ (λx. ?f x * ?c) summable_on ?A›*)) then show "f summable_on A" by (smt (verit, del_insts) assms (*‹c ≠ 0›*) divide_inverse (*‹?a / ?b = ?a * inverse ?b›*) nonzero_divide_eq_eq (*‹?c ≠ 0 ⟹ (?b / ?c = ?a) = (?b = ?a * ?c)›*) summable_on_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ (?f summable_on ?A) = (?g summable_on ?A)›*)) qed lemma summable_on_cmult_right': fixes f :: "'a ⇒ 'b :: {t2_space, topological_semigroup_mult, division_ring}" assumes ‹c ≠ 0› shows "(λx. c * f x) summable_on A ⟷ f summable_on A" by (metis (no_types, lifting) assms (*‹c ≠ 0›*) left_inverse (*‹?a ≠ 0 ⟹ inverse ?a * ?a = 1›*) mult.assoc (*‹?a * ?b * ?c = ?a * (?b * ?c)›*) mult_1 (*‹1 * ?a = ?a›*) summable_on_cmult_right (*‹?f summable_on ?A ⟹ (λx. ?c * ?f x) summable_on ?A›*) summable_on_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ (?f summable_on ?A) = (?g summable_on ?A)›*)) lemma infsum_cmult_left': fixes f :: "'a ⇒ 'b :: {t2_space, topological_semigroup_mult, division_ring}" shows "infsum (λx. f x * c) A = infsum f A * c" by (metis (full_types) infsum_cmult_left (*‹(?c ≠ 0 ⟹ ?f summable_on ?A) ⟹ (∑⇩∞x∈?A. ?f x * ?c) = infsum ?f ?A * ?c›*) infsum_not_exists (*‹¬ ?f summable_on ?A ⟹ infsum ?f ?A = 0›*) mult_eq_0_iff (*‹(?a * ?b = 0) = (?a = 0 ∨ ?b = 0)›*) summable_on_cmult_left' (*‹?c ≠ 0 ⟹ ((λx. ?f x * ?c) summable_on ?A) = (?f summable_on ?A)›*)) lemma infsum_cmult_right': fixes f :: "'a ⇒ 'b :: {t2_space,topological_semigroup_mult,division_ring}" shows "infsum (λx. c * f x) A = c * infsum f A" by (metis (full_types) infsum_cmult_right (*‹(?c ≠ 0 ⟹ ?f summable_on ?A) ⟹ (∑⇩∞x∈?A. ?c * ?f x) = ?c * infsum ?f ?A›*) infsum_not_exists (*‹¬ ?f summable_on ?A ⟹ infsum ?f ?A = 0›*) mult_eq_0_iff (*‹(?a * ?b = 0) = (?a = 0 ∨ ?b = 0)›*) summable_on_cmult_right' (*‹?c ≠ 0 ⟹ ((λx. ?c * ?f x) summable_on ?A) = (?f summable_on ?A)›*)) lemma has_sum_constant[simp]: assumes ‹finite F› shows ‹((λ_. c) has_sum of_nat (card F) * c) F› by (metis assms (*‹finite F›*) has_sum_finite (*‹finite ?F ⟹ (?f has_sum sum ?f ?F) ?F›*) sum_constant (*‹(∑x∈?A. ?y) = of_nat (card ?A) * ?y›*)) lemma infsum_constant[simp]: assumes ‹finite F› shows ‹infsum (λ_. c) F = of_nat (card F) * c› by (simp add: assms (*‹finite F›*)) lemma infsum_diverge_constant: ― ‹This probably does not really need all of \<^class>‹archimedean_field› but Isabelle/HOL has no type class such as, e.g., "archimedean ring".› fixes c :: ‹'a::{archimedean_field, comm_monoid_add, linorder_topology, topological_semigroup_mult}› assumes ‹infinite A› and ‹c ≠ 0› shows ‹¬ (λ_. c) summable_on A› proof (rule notI (*‹(?P ⟹ False) ⟹ ¬ ?P›*)) (*goal: ‹(λ_::'b::type. c::'a::{archimedean_field,topological_semigroup_mult,linorder_topology}) summable_on (A::'b::type set) ⟹ False›*) assume "(λ_. c) summable_on A" (*‹(λ_::'b. c::'a) summable_on (A::'b set)›*) then have "(λ_. inverse c * c) summable_on A" by (rule summable_on_cmult_right (*‹?f summable_on ?A ⟹ (λx. ?c * ?f x) summable_on ?A›*)) then have [simp]: "(λ_. 1::'a) summable_on A" using assms (*‹infinite (A::'b set)› ‹c ≠ 0›*) by auto have "infsum (λ_. 1) A ≥ d" for d :: 'a proof (-) (*goal: ‹d ≤ (∑⇩∞_∈A. 1)›*) obtain n :: nat where "of_nat n ≥ d" (*goal: ‹(⋀n. d ≤ of_nat n ⟹ thesis) ⟹ thesis›*) by (meson real_arch_simple (*‹∃n. ?x ≤ of_nat n›*)) from assms (*‹infinite A› ‹c ≠ 0›*) obtain F where "F ⊆ A" and "finite F" and "card F = n" (*goal: ‹(⋀F. ⟦F ⊆ A; finite F; card F = n⟧ ⟹ thesis) ⟹ thesis›*) by (meson infinite_arbitrarily_large (*‹infinite ?A ⟹ ∃B. finite B ∧ card B = ?n ∧ B ⊆ ?A›*)) note ‹d ≤ of_nat n› (*‹(d::'a::{archimedean_field,topological_semigroup_mult,linorder_topology}) ≤ of_nat (n::nat)›*) also (*calculation: ‹(d::'a::{archimedean_field,topological_semigroup_mult,linorder_topology}) ≤ of_nat (n::nat)›*) have "of_nat n = infsum (λ_. 1::'a) F" by (simp add: ‹card F = n› ‹finite F›) also (*calculation: ‹d ≤ (∑⇩∞_∈F. 1)›*) have "… ≤ infsum (λ_. 1::'a) A" apply (rule infsum_mono_neutral (*‹⟦?f summable_on ?A; ?g summable_on ?B; ⋀x. x ∈ ?A ∩ ?B ⟹ ?f x ≤ ?g x; ⋀x. x ∈ ?A - ?B ⟹ ?f x ≤ 0; ⋀x. x ∈ ?B - ?A ⟹ 0 ≤ ?g x⟧ ⟹ infsum ?f ?A ≤ infsum ?g ?B›*)) (*goal: ‹(∑⇩∞_∈F. 1) ≤ (∑⇩∞_∈A. 1)›*) using ‹finite F› (*‹finite F›*) ‹F ⊆ A› (*‹F ⊆ A›*) apply - (*goals: 1. ‹⟦finite (F::'b set); F ⊆ (A::'b set)⟧ ⟹ (λ_::'b. 1::'a) summable_on F› 2. ‹⟦finite (F::'b set); F ⊆ (A::'b set)⟧ ⟹ (λ_::'b. 1::'a) summable_on A› 3. ‹⋀x::'b. ⟦x ∈ (F::'b set) ∩ (A::'b set); finite F; F ⊆ A⟧ ⟹ (1::'a) ≤ (1::'a)› 4. ‹⋀x::'b. ⟦x ∈ (F::'b set) - (A::'b set); finite F; F ⊆ A⟧ ⟹ (1::'a) ≤ (0::'a)› 5. ‹⋀x::'b. ⟦x ∈ (A::'b set) - (F::'b set); finite F; F ⊆ A⟧ ⟹ (0::'a) ≤ (1::'a)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*proven 5 subgoals*) . finally (*calculation: ‹d ≤ (∑⇩∞_∈A. 1)›*) show "?thesis" (*goal: ‹d ≤ (∑⇩∞_∈A. 1)›*) . qed then show False by (meson linordered_field_no_ub (*‹∀x::?'a. ∃y::?'a. x < y›*) not_less (*‹(¬ (?x::?'a) < (?y::?'a)) = (?y ≤ ?x)›*)) qed lemma has_sum_constant_archimedean[simp]: ― ‹This probably does not really need all of \<^class>‹archimedean_field› but Isabelle/HOL has no type class such as, e.g., "archimedean ring".› fixes c :: ‹'a::{archimedean_field, comm_monoid_add, linorder_topology, topological_semigroup_mult}› shows ‹infsum (λ_. c) A = of_nat (card A) * c› by (metis infsum_0 (*‹(⋀x. x ∈ ?M ⟹ ?f x = 0) ⟹ infsum ?f ?M = 0›*) infsum_constant (*‹finite ?F ⟹ (∑⇩∞_∈?F. ?c) = of_nat (card ?F) * ?c›*) infsum_diverge_constant (*‹⟦infinite ?A; ?c ≠ 0⟧ ⟹ ¬ (λ_. ?c) summable_on ?A›*) infsum_not_exists (*‹¬ ?f summable_on ?A ⟹ infsum ?f ?A = 0›*) sum.infinite (*‹infinite ?A ⟹ sum ?g ?A = 0›*) sum_constant (*‹(∑x∈?A. ?y) = of_nat (card ?A) * ?y›*)) lemma has_sum_uminus: fixes f :: ‹'a ⇒ 'b::topological_ab_group_add› shows ‹((λx. - f x) has_sum a) A ⟷ (f has_sum (- a)) A› by (auto simp add: sum_negf[abs_def] (*‹sum (λx. - ?f x) ≡ λA. - sum ?f A›*) tendsto_minus_cancel_left (*‹(?f ⤏ - ?y) ?F = ((λx. - ?f x) ⤏ ?y) ?F›*) has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*)) lemma summable_on_uminus: fixes f :: ‹'a ⇒ 'b::topological_ab_group_add› shows‹(λx. - f x) summable_on A ⟷ f summable_on A› by (metis summable_on_def (*‹(?f::?'a ⇒ ?'b) summable_on (?A::?'a set) ≡ ∃x::?'b. (?f has_sum x) ?A›*) has_sum_uminus (*‹((λx::?'a. - (?f::?'a ⇒ ?'b) x) has_sum (?a::?'b)) (?A::?'a set) = (?f has_sum - ?a) ?A›*) verit_minus_simplify( (*‹- (- (?b::?'b)) = ?b›*) 4)) lemma infsum_uminus: fixes f :: ‹'a ⇒ 'b::{topological_ab_group_add, t2_space}› shows ‹infsum (λx. - f x) A = - infsum f A› by (metis (full_types) add.inverse_inverse (*‹- (- ?a) = ?a›*) add.inverse_neutral (*‹- 0 = 0›*) infsumI (*‹(?f has_sum ?x) ?A ⟹ infsum ?f ?A = ?x›*) infsum_def (*‹infsum ?f ?A = (if ?f summable_on ?A then Lim (finite_subsets_at_top ?A) (sum ?f) else 0)›*) has_sum_infsum (*‹?f summable_on ?S ⟹ (?f has_sum infsum ?f ?S) ?S›*) has_sum_uminus (*‹((λx. - ?f x) has_sum ?a) ?A = (?f has_sum - ?a) ?A›*)) lemma has_sum_le_finite_sums: fixes a :: ‹'a::{comm_monoid_add,topological_space,linorder_topology}› assumes ‹(f has_sum a) A› assumes ‹⋀F. finite F ⟹ F ⊆ A ⟹ sum f F ≤ b› shows ‹a ≤ b› by (metis assms (*‹((f::'b ⇒ 'a) has_sum (a::'a)) (A::'b set)› ‹⟦finite (?F::'b set); ?F ⊆ (A::'b set)⟧ ⟹ sum (f::'b ⇒ 'a) ?F ≤ (b::'a)›*) eventually_finite_subsets_at_top_weakI (*‹(⋀X::?'a set. ⟦finite X; X ⊆ (?A::?'a set)⟧ ⟹ (?P::?'a set ⇒ bool) X) ⟹ eventually ?P (finite_subsets_at_top ?A)›*) finite_subsets_at_top_neq_bot (*‹finite_subsets_at_top (?A::?'a set) ≠ bot›*) has_sum_def (*‹((?f::?'a ⇒ ?'b) has_sum (?x::?'b)) (?A::?'a set) ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*) tendsto_upperbound (*‹⟦((?f::?'b ⇒ ?'a) ⤏ (?x::?'a)) (?F::?'b filter); ∀⇩F i::?'b in ?F. ?f i ≤ (?a::?'a); ?F ≠ bot⟧ ⟹ ?x ≤ ?a›*)) lemma infsum_le_finite_sums: fixes b :: ‹'a::{comm_monoid_add,topological_space,linorder_topology}› assumes ‹f summable_on A› assumes ‹⋀F. finite F ⟹ F ⊆ A ⟹ sum f F ≤ b› shows ‹infsum f A ≤ b› by (meson assms (*‹f summable_on A› ‹⟦finite ?F; ?F ⊆ A⟧ ⟹ sum f ?F ≤ b›*) has_sum_infsum (*‹?f summable_on ?S ⟹ (?f has_sum infsum ?f ?S) ?S›*) has_sum_le_finite_sums (*‹⟦(?f has_sum ?a) ?A; ⋀F. ⟦finite F; F ⊆ ?A⟧ ⟹ sum ?f F ≤ ?b⟧ ⟹ ?a ≤ ?b›*)) lemma summable_on_scaleR_left [intro]: fixes c :: ‹'a :: real_normed_vector› assumes "c ≠ 0 ⟹ f summable_on A" shows "(λx. f x *⇩R c) summable_on A" proof (cases ‹c = 0›) (*goals: 1. ‹c = 0 ⟹ (λx. f x *⇩R c) summable_on A› 2. ‹c ≠ 0 ⟹ (λx. f x *⇩R c) summable_on A›*) case False (*‹c ≠ 0›*) then have "(λy. y *⇩R c) ∘ f summable_on A" using assms (*‹c ≠ 0 ⟹ f summable_on A›*) by (auto simp add: scaleR_left.additive_axioms (*‹additive (λa. a *⇩R ?x)›*) summable_on_comm_additive (*‹⟦additive ?f; isCont ?f (infsum ?g ?S); ?g summable_on ?S⟧ ⟹ ?f ∘ ?g summable_on ?S›*)) then show "?thesis" (*goal: ‹(λx::'b. (f::'b ⇒ real) x *⇩R (c::'a)) summable_on (A::'b set)›*) by (metis (mono_tags, lifting) comp_apply (*‹(?f ∘ ?g) ?x = ?f (?g ?x)›*) summable_on_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ (?f summable_on ?A) = (?g summable_on ?A)›*)) qed (auto) (*solved the remaining goal: ‹c = 0 ⟹ (λx. f x *⇩R c) summable_on A›*) lemma summable_on_scaleR_right [intro]: fixes f :: ‹'a ⇒ 'b :: real_normed_vector› assumes "c ≠ 0 ⟹ f summable_on A" shows "(λx. c *⇩R f x) summable_on A" proof (cases ‹c = 0›) (*goals: 1. ‹(c::real) = (0::real) ⟹ (λx::'a. c *⇩R (f::'a ⇒ 'b) x) summable_on (A::'a set)› 2. ‹(c::real) ≠ (0::real) ⟹ (λx::'a. c *⇩R (f::'a ⇒ 'b) x) summable_on (A::'a set)›*) case False (*‹c ≠ 0›*) then have "(*⇩R) c ∘ f summable_on A" using assms (*‹c ≠ 0 ⟹ f summable_on A›*) by (auto simp add: scaleR_right.additive_axioms (*‹additive ((*⇩R) ?a)›*) summable_on_comm_additive (*‹⟦additive ?f; isCont ?f (infsum ?g ?S); ?g summable_on ?S⟧ ⟹ ?f ∘ ?g summable_on ?S›*)) then show "?thesis" (*goal: ‹(λx. c *⇩R f x) summable_on A›*) by (metis (mono_tags, lifting) comp_apply (*‹(?f ∘ ?g) ?x = ?f (?g ?x)›*) summable_on_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ (?f summable_on ?A) = (?g summable_on ?A)›*)) qed (auto) (*solved the remaining goal: ‹c = 0 ⟹ (λx. c *⇩R f x) summable_on A›*) lemma infsum_scaleR_left: fixes c :: ‹'a :: real_normed_vector› assumes "c ≠ 0 ⟹ f summable_on A" shows "infsum (λx. f x *⇩R c) A = infsum f A *⇩R c" proof (cases ‹c = 0›) (*goals: 1. ‹c = 0 ⟹ (∑⇩∞x∈A. f x *⇩R c) = infsum f A *⇩R c› 2. ‹c ≠ 0 ⟹ (∑⇩∞x∈A. f x *⇩R c) = infsum f A *⇩R c›*) case False (*‹c ≠ 0›*) then have "infsum ((λy. y *⇩R c) ∘ f) A = infsum f A *⇩R c" using assms (*‹c ≠ 0 ⟹ f summable_on A›*) by (auto simp add: scaleR_left.additive_axioms (*‹additive (λa. a *⇩R ?x)›*) infsum_comm_additive (*‹⟦additive ?f; isCont ?f (infsum ?g ?S); ?g summable_on ?S⟧ ⟹ infsum (?f ∘ ?g) ?S = ?f (infsum ?g ?S)›*)) then show "?thesis" (*goal: ‹(∑⇩∞x∈A. f x *⇩R c) = infsum f A *⇩R c›*) by (metis (mono_tags, lifting) comp_apply (*‹(?f ∘ ?g) ?x = ?f (?g ?x)›*) infsum_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ infsum ?f ?A = infsum ?g ?A›*)) qed (auto) (*solved the remaining goal: ‹c = 0 ⟹ (∑⇩∞x∈A. f x *⇩R c) = infsum f A *⇩R c›*) lemma infsum_scaleR_right: fixes f :: ‹'a ⇒ 'b :: real_normed_vector› shows "infsum (λx. c *⇩R f x) A = c *⇩R infsum f A" proof - consider (summable) ‹f summable_on A› | (c0) ‹c = 0› | (not_summable) ‹¬ f summable_on A› ‹c ≠ 0› by auto then show ?thesis proof cases case summable then have "infsum ((*⇩R) c ∘ f) A = c *⇩R infsum f A" by (auto simp add: scaleR_right.additive_axioms infsum_comm_additive) then show ?thesis by (metis (mono_tags, lifting) comp_apply infsum_cong) next case c0 then show ?thesis by auto next case not_summable have ‹¬ (λx. c *⇩R f x) summable_on A› proof (rule notI) assume ‹(λx. c *⇩R f x) summable_on A› then have ‹(λx. inverse c *⇩R c *⇩R f x) summable_on A› using summable_on_scaleR_right by blast with not_summable show False by simp qed then show ?thesis by (simp add: infsum_not_exists not_summable(1)) qed qed lemma infsum_Un_Int: fixes f :: "'a ⇒ 'b::{topological_ab_group_add, t2_space}" assumes "f summable_on A - B" "f summable_on B - A" ‹f summable_on A ∩ B› shows "infsum f (A ∪ B) = infsum f A + infsum f B - infsum f (A ∩ B)" proof (-) (*goal: ‹infsum f (A ∪ B) = infsum f A + infsum f B - infsum f (A ∩ B)›*) obtain "f summable_on A" "f summable_on B" (*goal: ‹(⟦f summable_on A; f summable_on B⟧ ⟹ thesis) ⟹ thesis›*) using assms (*‹f summable_on A - B› ‹f summable_on B - A› ‹f summable_on A ∩ B›*) by (metis Int_Diff_Un (*‹?A ∩ ?B ∪ (?A - ?B) = ?A›*) Int_Diff_disjoint (*‹?A ∩ ?B ∩ (?A - ?B) = {}›*) inf_commute (*‹inf ?x ?y = inf ?y ?x›*) summable_on_Un_disjoint (*‹⟦?f summable_on ?A; ?f summable_on ?B; ?A ∩ ?B = {}⟧ ⟹ ?f summable_on ?A ∪ ?B›*)) then have "infsum f (A ∪ B) = infsum f A + infsum f (B - A)" using assms(2) (*‹f summable_on B - A›*) infsum_Un_disjoint (*‹⟦(?f::?'a ⇒ ?'b) summable_on (?A::?'a set); ?f summable_on (?B::?'a set); ?A ∩ ?B = {}⟧ ⟹ infsum ?f (?A ∪ ?B) = infsum ?f ?A + infsum ?f ?B›*) by fastforce moreover have "infsum f (B - A) = infsum f B - infsum f (A ∩ B)" using assms (*‹f summable_on A - B› ‹f summable_on B - A› ‹f summable_on A ∩ B›*) by (metis Diff_Int2 (*‹(?A::?'a set) ∩ (?C::?'a set) - (?B::?'a set) ∩ ?C = ?A ∩ ?C - ?B›*) Un_Int_eq( (*‹((?S::?'a set) ∪ (?T::?'a set)) ∩ ?T = ?T›*) 2) ‹f summable_on B› inf_le2 (*‹inf (?x::?'a) (?y::?'a) ≤ ?y›*) infsum_Diff (*‹⟦(?f::?'a ⇒ ?'b) summable_on (?B::?'a set); ?f summable_on (?A::?'a set); ?A ⊆ ?B⟧ ⟹ infsum ?f (?B - ?A) = infsum ?f ?B - infsum ?f ?A›*)) ultimately show "?thesis" (*goal: ‹infsum f (A ∪ B) = infsum f A + infsum f B - infsum f (A ∩ B)›*) by auto qed lemma inj_combinator': assumes "x ∉ F" shows ‹inj_on (λ(g, y). g(x := y)) (Pi⇩E F B × B x)› proof (-) (*goal: ‹inj_on (λ(g, y). g(x := y)) (Pi⇩E F B × B x)›*) have "inj_on ((λ(y, g). g(x := y)) ∘ prod.swap) (Pi⇩E F B × B x)" using inj_combinator[of x F B] (*‹x ∉ F ⟹ inj_on (λ(y, g). g(x := y)) (B x × Pi⇩E F B)›*) assms (*‹x ∉ F›*) apply (intro comp_inj_on (*‹⟦inj_on (?f::?'a ⇒ ?'b) (?A::?'a set); inj_on (?g::?'b ⇒ ?'c) (?f ` ?A)⟧ ⟹ inj_on (?g ∘ ?f) ?A›*)) (*goals: 1. ‹⟦x ∉ F ⟹ inj_on (λ(y, g). g(x := y)) (B x × Pi⇩E F B); x ∉ F⟧ ⟹ inj_on prod.swap (Pi⇩E F B × B x)› 2. ‹⟦x ∉ F ⟹ inj_on (λ(y, g). g(x := y)) (B x × Pi⇩E F B); x ∉ F⟧ ⟹ inj_on (λ(y, g). g(x := y)) (prod.swap ` (Pi⇩E F B × B x))› discuss goal 1*) apply ((auto simp: product_swap (*‹prod.swap ` (?A × ?B) = ?B × ?A›*))[1]) (*discuss goal 2*) apply ((auto simp: product_swap (*‹prod.swap ` (?A × ?B) = ?B × ?A›*))[1]) (*proven 2 subgoals*) . thus "?thesis" (*goal: ‹inj_on (λ(g::'a ⇒ 'b, y::'b). g(x::'a := y)) (Pi⇩E (F::'a set) (B::'a ⇒ 'b set) × B x)›*) by (simp add: o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*)) qed lemma infsum_prod_PiE: ― ‹See also ‹infsum_prod_PiE_abs› below with incomparable premises.› fixes f :: "'a ⇒ 'b ⇒ 'c :: {comm_monoid_mult, topological_semigroup_mult, division_ring, banach}" assumes finite: "finite A" assumes "⋀x. x ∈ A ⟹ f x summable_on B x" assumes "(λg. ∏x∈A. f x (g x)) summable_on (PiE A B)" shows "infsum (λg. ∏x∈A. f x (g x)) (PiE A B) = (∏x∈A. infsum (f x) (B x))" proof (use finite assms(2-) in induction) (*goals: 1. ‹⟦⋀x. x ∈ {} ⟹ f x summable_on B x; (λg. ∏x∈{}. f x (g x)) summable_on Pi⇩E {} B⟧ ⟹ (∑⇩∞g∈Pi⇩E {} B. ∏x∈{}. f x (g x)) = (∏x∈{}. infsum (f x) (B x))› 2. ‹⋀x F. ⟦finite F; x ∉ F; ⟦⋀x. x ∈ F ⟹ f x summable_on B x; (λg. ∏x∈F. f x (g x)) summable_on Pi⇩E F B⟧ ⟹ (∑⇩∞g∈Pi⇩E F B. ∏x∈F. f x (g x)) = (∏x∈F. infsum (f x) (B x)); ⋀xa. xa ∈ insert x F ⟹ f xa summable_on B xa; (λg. ∏x∈insert x F. f x (g x)) summable_on Pi⇩E (insert x F) B⟧ ⟹ (∑⇩∞g∈Pi⇩E (insert x F) B. ∏x∈insert x F. f x (g x)) = (∏x∈insert x F. infsum (f x) (B x))›*) case empty (*‹?x ∈ {} ⟹ f ?x summable_on B ?x› ‹(λg. ∏x∈{}. f x (g x)) summable_on Pi⇩E {} B›*) then show "?case" (*goal: ‹(∑⇩∞g∈Pi⇩E {} B. ∏x∈{}. f x (g x)) = (∏x∈{}. infsum (f x) (B x))›*) by auto next (*goal: ‹⋀x F. ⟦finite F; x ∉ F; ⟦⋀x. x ∈ F ⟹ f x summable_on B x; (λg. ∏x∈F. f x (g x)) summable_on Pi⇩E F B⟧ ⟹ (∑⇩∞g∈Pi⇩E F B. ∏x∈F. f x (g x)) = (∏x∈F. infsum (f x) (B x)); ⋀xa. xa ∈ insert x F ⟹ f xa summable_on B xa; (λg. ∏x∈insert x F. f x (g x)) summable_on Pi⇩E (insert x F) B⟧ ⟹ (∑⇩∞g∈Pi⇩E (insert x F) B. ∏x∈insert x F. f x (g x)) = (∏x∈insert x F. infsum (f x) (B x))›*) case (insert x F) (*‹finite F› ‹(x::'a::type) ∉ (F::'a::type set)› ‹⟦⋀x. x ∈ F ⟹ f x summable_on B x; (λg. ∏x∈F. f x (g x)) summable_on Pi⇩E F B⟧ ⟹ (∑⇩∞g∈Pi⇩E F B. ∏x∈F. f x (g x)) = (∏x∈F. infsum (f x) (B x))› ‹?x ∈ insert x F ⟹ f ?x summable_on B ?x› ‹(λg. ∏x∈insert x F. f x (g x)) summable_on Pi⇩E (insert x F) B›*) have pi: "Pi⇩E (insert x F) B = (λ(g,y). g(x:=y)) ` (Pi⇩E F B × B x)" unfolding PiE_insert_eq (*goal: ‹(λ(y, g). g(x := y)) ` (B x × Pi⇩E F B) = (λ(g, y). g(x := y)) ` (Pi⇩E F B × B x)›*) apply (subst swap_product [symmetric] (*‹(?B::?'a::type set) × (?A::?'b::type set) = (λ(i::?'b::type, j::?'a::type). (j, i)) ` (?A × ?B)›*)) (*goal: ‹(λ(y, g). g(x := y)) ` (B x × Pi⇩E F B) = (λ(g, y). g(x := y)) ` (Pi⇩E F B × B x)›*) by (simp add: image_image (*‹(?f::?'b ⇒ ?'a) ` (?g::?'c ⇒ ?'b) ` (?A::?'c set) = (λx::?'c. ?f (?g x)) ` ?A›*) case_prod_unfold (*‹case_prod = (λ(c::?'a ⇒ ?'b ⇒ ?'c) p::?'a × ?'b. c (fst p) (snd p))›*)) have prod: "(∏x'∈F. f x' ((p(x:=y)) x')) = (∏x'∈F. f x' (p x'))" for p and y apply (rule prod.cong (*‹⟦?A = ?B; ⋀x. x ∈ ?B ⟹ ?g x = ?h x⟧ ⟹ prod ?g ?A = prod ?h ?B›*)) (*goals: 1. ‹(F::'a::type set) = F› 2. ‹⋀xa::'a::type. xa ∈ (F::'a::type set) ⟹ (f::'a::type ⇒ 'b::type ⇒ 'c::{division_ring,comm_monoid_mult,topological_semigroup_mult,banach}) xa (((p::'a::type ⇒ 'b::type)(x::'a::type := y::'b::type)) xa) = f xa (p xa)› discuss goal 1*) apply ((use insert.hyps in auto)[1]) (*discuss goal 2*) apply ((use insert.hyps in auto)[1]) (*proven 2 subgoals*) . have inj: "inj_on (λ(g, y). g(x := y)) (Pi⇩E F B × B x)" using ‹x ∉ F› (*‹(x::'a) ∉ (F::'a set)›*) by (rule inj_combinator' (*‹(?x::?'a) ∉ (?F::?'a set) ⟹ inj_on (λ(g::?'a ⇒ ?'b, y::?'b). g(?x := y)) (Pi⇩E ?F (?B::?'a ⇒ ?'b set) × ?B ?x)›*)) have summable1: "(λg. ∏x∈insert x F. f x (g x)) summable_on Pi⇩E (insert x F) B" using insert.prems(2) (*‹(λg. ∏x∈insert x F. f x (g x)) summable_on Pi⇩E (insert x F) B›*) . also (*calculation: ‹(λg. ∏x∈insert x F. f x (g x)) summable_on Pi⇩E (insert x F) B›*) have "Pi⇩E (insert x F) B = (λ(g,y). g(x:=y)) ` (Pi⇩E F B × B x)" by (simp only: pi (*‹Pi⇩E (insert x F) B = (λ(g, y). g(x := y)) ` (Pi⇩E F B × B x)›*)) also (*calculation: ‹(λg::'a ⇒ 'b. ∏x::'a∈insert (x::'a) (F::'a set). (f::'a ⇒ 'b ⇒ 'c) x (g x)) summable_on (λ(g::'a ⇒ 'b, y::'b). g(x := y)) ` (Pi⇩E F (B::'a ⇒ 'b set) × B x)›*) have "(λg. ∏x∈insert x F. f x (g x)) summable_on … ⟷ ((λg. ∏x∈insert x F. f x (g x)) ∘ (λ(g,y). g(x:=y))) summable_on (Pi⇩E F B × B x)" using inj (*‹inj_on (λ(g, y). g(x := y)) (Pi⇩E F B × B x)›*) by (rule summable_on_reindex (*‹inj_on ?h ?A ⟹ (?g summable_on ?h ` ?A) = (?g ∘ ?h summable_on ?A)›*)) also (*calculation: ‹(λg. ∏x∈insert x F. f x (g x)) ∘ (λ(g, y). g(x := y)) summable_on Pi⇩E F B × B x›*) have "(∏z∈F. f z ((g(x := y)) z)) = (∏z∈F. f z (g z))" for g and y using insert.hyps (*‹finite (F::'a set)› ‹x ∉ F›*) apply (intro prod.cong (*‹⟦(?A::?'b set) = (?B::?'b set); ⋀x::?'b. x ∈ ?B ⟹ (?g::?'b ⇒ ?'a) x = (?h::?'b ⇒ ?'a) x⟧ ⟹ prod ?g ?A = prod ?h ?B›*)) (*goals: 1. ‹⟦finite F; x ∉ F⟧ ⟹ F = F› 2. ‹⋀xa. ⟦finite F; x ∉ F; xa ∈ F⟧ ⟹ f xa ((g(x := y)) xa) = f xa (g xa)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . hence "((λg. ∏x∈insert x F. f x (g x)) ∘ (λ(g,y). g(x:=y))) = (λ(p, y). f x y * (∏x'∈F. f x' (p x')))" using insert.hyps (*‹finite F› ‹x ∉ F›*) by (auto simp: fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) cong: prod.cong_simp (*‹⟦?A = ?B; ⋀x. x ∈ ?B =simp=> ?g x = ?h x⟧ ⟹ prod ?g ?A = prod ?h ?B›*)) finally (*calculation: ‹(λa. case a of (p, y) ⇒ f x y * (∏x'∈F. f x' (p x'))) summable_on Pi⇩E F B × B x›*) have summable2: "(λ(p, y). f x y * (∏x'∈F. f x' (p x'))) summable_on Pi⇩E F B × B x" . then have "(λp. ∑⇩∞y∈B x. f x y * (∏x'∈F. f x' (p x'))) summable_on Pi⇩E F B" by (rule summable_on_Sigma_banach (*‹(λ(x, y). ?f x y) summable_on Sigma ?A ?B ⟹ (λx. infsum (?f x) (?B x)) summable_on ?A›*)) then have "(λp. (∑⇩∞y∈B x. f x y) * (∏x'∈F. f x' (p x'))) summable_on Pi⇩E F B" by (metis (mono_tags, lifting) infsum_cmult_left' (*‹(∑⇩∞x∈?A. ?f x * ?c) = infsum ?f ?A * ?c›*) infsum_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ infsum ?f ?A = infsum ?g ?A›*) summable_on_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ (?f summable_on ?A) = (?g summable_on ?A)›*)) then have summable3: "(λp. (∏x'∈F. f x' (p x'))) summable_on Pi⇩E F B" if "(∑⇩∞y∈B x. f x y) ≠ 0" using summable_on_cmult_right' (*‹(?c::?'b::{division_ring,topological_semigroup_mult,t2_space}) ≠ (0::?'b::{division_ring,topological_semigroup_mult,t2_space}) ⟹ ((λx::?'a::type. ?c * (?f::?'a::type ⇒ ?'b::{division_ring,topological_semigroup_mult,t2_space}) x) summable_on (?A::?'a::type set)) = (?f summable_on ?A)›*) that (*‹infsum (f x) (B x) ≠ 0›*) by blast have "(∑⇩∞g∈Pi⇩E (insert x F) B. ∏x∈insert x F. f x (g x)) = (∑⇩∞(p,y)∈Pi⇩E F B × B x. ∏x'∈insert x F. f x' ((p(x:=y)) x'))" by (smt (verit, ccfv_SIG) comp_apply (*‹(?f ∘ ?g) ?x = ?f (?g ?x)›*) infsum_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ infsum ?f ?A = infsum ?g ?A›*) infsum_reindex (*‹inj_on ?h ?A ⟹ infsum ?g (?h ` ?A) = infsum (?g ∘ ?h) ?A›*) inj (*‹inj_on (λ(g, y). g(x := y)) (Pi⇩E F B × B x)›*) pi (*‹Pi⇩E (insert x F) B = (λ(g, y). g(x := y)) ` (Pi⇩E F B × B x)›*) prod.cong (*‹⟦?A = ?B; ⋀x. x ∈ ?B ⟹ ?g x = ?h x⟧ ⟹ prod ?g ?A = prod ?h ?B›*) split_def (*‹case_prod = (λc p. c (fst p) (snd p))›*)) also (*calculation: ‹(∑⇩∞g::'a ⇒ 'b∈Pi⇩E (insert x F) (B::'a ⇒ 'b set). ∏x::'a∈insert (x::'a) (F::'a set). (f::'a ⇒ 'b ⇒ 'c) x (g x)) = (∑⇩∞(p::'a ⇒ 'b, y::'b)∈Pi⇩E F B × B x. ∏x'::'a∈insert x F. f x' ((p(x := y)) x'))›*) have "… = (∑⇩∞(p, y)∈Pi⇩E F B × B x. f x y * (∏x'∈F. f x' ((p(x:=y)) x')))" using insert.hyps (*‹finite F› ‹x ∉ F›*) by auto also (*calculation: ‹(∑⇩∞g::'a ⇒ 'b∈Pi⇩E (insert x F) (B::'a ⇒ 'b set). ∏x::'a∈insert (x::'a) (F::'a set). (f::'a ⇒ 'b ⇒ 'c) x (g x)) = (∑⇩∞(p::'a ⇒ 'b, y::'b)∈Pi⇩E F B × B x. f x y * (∏x'::'a∈F. f x' ((p(x := y)) x')))›*) have "… = (∑⇩∞(p, y)∈Pi⇩E F B × B x. f x y * (∏x'∈F. f x' (p x')))" using prod (*‹(∏x'∈F. f x' ((?p(x := ?y)) x')) = (∏x'∈F. f x' (?p x'))›*) by presburger also (*calculation: ‹(∑⇩∞g∈Pi⇩E (insert x F) B. ∏x∈insert x F. f x (g x)) = (∑⇩∞(p, y)∈Pi⇩E F B × B x. f x y * (∏x'∈F. f x' (p x')))›*) have "… = (∑⇩∞p∈Pi⇩E F B. ∑⇩∞y∈B x. f x y * (∏x'∈F. f x' (p x')))" using infsum_Sigma'_banach (*‹(λ(x, y). ?f x y) summable_on Sigma ?A ?B ⟹ (∑⇩∞x∈?A. infsum (?f x) (?B x)) = (∑⇩∞(x, y)∈Sigma ?A ?B. ?f x y)›*) summable2 (*‹(λ(p, y). f x y * (∏x'∈F. f x' (p x'))) summable_on Pi⇩E F B × B x›*) by force also (*calculation: ‹(∑⇩∞g∈Pi⇩E (insert x F) B. ∏x∈insert x F. f x (g x)) = (∑⇩∞p∈Pi⇩E F B. ∑⇩∞y∈B x. f x y * (∏x'∈F. f x' (p x')))›*) have "… = (∑⇩∞y∈B x. f x y) * (∑⇩∞p∈Pi⇩E F B. ∏x'∈F. f x' (p x'))" by (smt (verit) infsum_cmult_left' (*‹(∑⇩∞x∈?A. ?f x * ?c) = infsum ?f ?A * ?c›*) infsum_cmult_right' (*‹(∑⇩∞x∈?A. ?c * ?f x) = ?c * infsum ?f ?A›*) infsum_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ infsum ?f ?A = infsum ?g ?A›*)) also (*calculation: ‹(∑⇩∞g∈Pi⇩E (insert x F) B. ∏x∈insert x F. f x (g x)) = infsum (f x) (B x) * (∑⇩∞p∈Pi⇩E F B. ∏x'∈F. f x' (p x'))›*) have "… = (∏x∈insert x F. infsum (f x) (B x))" using insert (*‹finite F› ‹x ∉ F› ‹⟦⋀x. x ∈ F ⟹ f x summable_on B x; (λg. ∏x∈F. f x (g x)) summable_on Pi⇩E F B⟧ ⟹ (∑⇩∞g∈Pi⇩E F B. ∏x∈F. f x (g x)) = (∏x∈F. infsum (f x) (B x))› ‹?x ∈ insert x F ⟹ f ?x summable_on B ?x› ‹(λg. ∏x∈insert x F. f x (g x)) summable_on Pi⇩E (insert x F) B›*) summable3 (*‹infsum (f x) (B x) ≠ 0 ⟹ (λp. ∏x'∈F. f x' (p x')) summable_on Pi⇩E F B›*) by auto finally (*calculation: ‹(∑⇩∞g∈Pi⇩E (insert x F) B. ∏x∈insert x F. f x (g x)) = (∏x∈insert x F. infsum (f x) (B x))›*) show "?case" (*goal: ‹(∑⇩∞g∈Pi⇩E (insert x F) B. ∏x∈insert x F. f x (g x)) = (∏x∈insert x F. infsum (f x) (B x))›*) by simp qed lemma infsum_prod_PiE_abs: ― ‹See also @{thm [source] infsum_prod_PiE} above with incomparable premises.› fixes f :: "'a ⇒ 'b ⇒ 'c :: {banach, real_normed_div_algebra, comm_semiring_1}" assumes finite: "finite A" assumes "⋀x. x ∈ A ⟹ f x abs_summable_on B x" shows "infsum (λg. ∏x∈A. f x (g x)) (PiE A B) = (∏x∈A. infsum (f x) (B x))" proof (use finite assms(2) in induction) (*goals: 1. ‹(⋀x. x ∈ {} ⟹ f x abs_summable_on B x) ⟹ (∑⇩∞g∈Pi⇩E {} B. ∏x∈{}. f x (g x)) = (∏x∈{}. infsum (f x) (B x))› 2. ‹⋀x F. ⟦finite F; x ∉ F; (⋀x. x ∈ F ⟹ f x abs_summable_on B x) ⟹ (∑⇩∞g∈Pi⇩E F B. ∏x∈F. f x (g x)) = (∏x∈F. infsum (f x) (B x)); ⋀xa. xa ∈ insert x F ⟹ f xa abs_summable_on B xa⟧ ⟹ (∑⇩∞g∈Pi⇩E (insert x F) B. ∏x∈insert x F. f x (g x)) = (∏x∈insert x F. infsum (f x) (B x))›*) case empty (*‹?x ∈ {} ⟹ f ?x abs_summable_on B ?x›*) then show "?case" (*goal: ‹(∑⇩∞g∈Pi⇩E {} B. ∏x∈{}. f x (g x)) = (∏x∈{}. infsum (f x) (B x))›*) by auto next (*goal: ‹⋀(x::'a::type) F::'a::type set. ⟦finite F; x ∉ F; (⋀x::'a::type. x ∈ F ⟹ (f::'a::type ⇒ 'b::type ⇒ 'c::{banach,real_normed_div_algebra,comm_semiring_1}) x abs_summable_on (B::'a::type ⇒ 'b::type set) x) ⟹ (∑⇩∞g::'a::type ⇒ 'b::type∈Pi⇩E F B. ∏x::'a::type∈F. f x (g x)) = (∏x::'a::type∈F. infsum (f x) (B x)); ⋀xa::'a::type. xa ∈ insert x F ⟹ f xa abs_summable_on B xa⟧ ⟹ (∑⇩∞g::'a::type ⇒ 'b::type∈Pi⇩E (insert x F) B. ∏x::'a::type∈insert x F. f x (g x)) = (∏x::'a::type∈insert x F. infsum (f x) (B x))›*) case (insert x A) (*‹finite A› ‹x ∉ A› ‹(⋀x. x ∈ A ⟹ f x abs_summable_on B x) ⟹ (∑⇩∞g∈Pi⇩E A B. ∏x∈A. f x (g x)) = (∏x∈A. infsum (f x) (B x))› ‹(?x::'a) ∈ insert (x::'a) (A::'a set) ⟹ (f::'a ⇒ 'b ⇒ 'c) ?x abs_summable_on (B::'a ⇒ 'b set) ?x›*) have pi: "Pi⇩E (insert x F) B = (λ(g,y). g(x:=y)) ` (Pi⇩E F B × B x)" for x and F and B :: "'a ⇒ 'b set" unfolding PiE_insert_eq (*goal: ‹(λ(y, g). g(x := y)) ` (B x × Pi⇩E F B) = (λ(g, y). g(x := y)) ` (Pi⇩E F B × B x)›*) apply (subst swap_product [symmetric] (*‹?B × ?A = (λ(i, j). (j, i)) ` (?A × ?B)›*)) (*goal: ‹(λ(y, g). g(x := y)) ` (B x × Pi⇩E F B) = (λ(g, y). g(x := y)) ` (Pi⇩E F B × B x)›*) by (simp add: image_image (*‹?f ` ?g ` ?A = (λx. ?f (?g x)) ` ?A›*) case_prod_unfold (*‹case_prod = (λc p. c (fst p) (snd p))›*)) have prod: "(∏x'∈A. f x' ((p(x:=y)) x')) = (∏x'∈A. f x' (p x'))" for p and y apply (rule prod.cong (*‹⟦?A = ?B; ⋀x. x ∈ ?B ⟹ ?g x = ?h x⟧ ⟹ prod ?g ?A = prod ?h ?B›*)) (*goals: 1. ‹A = A› 2. ‹⋀xa. xa ∈ A ⟹ f xa ((p(x := y)) xa) = f xa (p xa)› discuss goal 1*) apply ((use insert.hyps in auto)[1]) (*discuss goal 2*) apply ((use insert.hyps in auto)[1]) (*proven 2 subgoals*) . have inj: "inj_on (λ(g, y). g(x := y)) (Pi⇩E A B × B x)" using ‹x ∉ A› (*‹x ∉ A›*) by (rule inj_combinator' (*‹?x ∉ ?F ⟹ inj_on (λ(g, y). g(?x := y)) (Pi⇩E ?F ?B × ?B ?x)›*)) define s where "s x = infsum (λy. norm (f x y)) (B x)" for x have "(∑p∈P. norm (∏x∈F. f x (p x))) ≤ prod s F" if P: "P ⊆ Pi⇩E F B" and [simp]: "finite P" "finite F" and sum: "⋀x. x ∈ F ⟹ f x abs_summable_on B x" for P and F proof (-) (*goal: ‹(∑p∈P. norm (∏x∈F. f x (p x))) ≤ prod s F›*) define B' where "B' x = {p x| p. p∈P}" for x have fin_B'[simp]: "finite (B' x)" for x using that (*‹P ⊆ Pi⇩E F B› ‹finite P› ‹finite F› ‹(?x::'a) ∈ (F::'a set) ⟹ (f::'a ⇒ 'b ⇒ 'c) ?x abs_summable_on (B::'a ⇒ 'b set) ?x›*) by (auto simp: B'_def (*‹B' ?x = {p ?x |p. p ∈ P}›*)) have [simp]: "finite (Pi⇩E F B')" by (simp add: finite_PiE (*‹⟦finite ?S; ⋀i. i ∈ ?S ⟹ finite (?T i)⟧ ⟹ finite (Pi⇩E ?S ?T)›*)) have [simp]: "P ⊆ Pi⇩E F B'" using that (*‹P ⊆ Pi⇩E F B› ‹finite P› ‹finite F› ‹?x ∈ F ⟹ f ?x abs_summable_on B ?x›*) by (auto simp: B'_def (*‹B' ?x = {p ?x |p. p ∈ P}›*)) have B'B: "B' x ⊆ B x" if "x ∈ F" for x unfolding B'_def (*goal: ‹{p (x::'a::type) |p::'a::type ⇒ 'b::type. p ∈ (P::('a::type ⇒ 'b::type) set)} ⊆ (B::'a::type ⇒ 'b::type set) x›*) using P (*‹(P::('a ⇒ 'b) set) ⊆ Pi⇩E (F::'a set) (B::'a ⇒ 'b set)›*) that (*‹x ∈ F›*) by auto have s_bound: "(∑y∈B' x. norm (f x y)) ≤ s x" if "x ∈ F" for x by (metis B'B (*‹(?x::'a) ∈ (F::'a set) ⟹ (B'::'a ⇒ 'b set) ?x ⊆ (B::'a ⇒ 'b set) ?x›*) fin_B' (*‹finite ((B'::'a ⇒ 'b set) (?x::'a))›*) finite_sum_le_has_sum (*‹⟦((?f::?'a ⇒ ?'b) has_sum (?S::?'b)) (?A::?'a set); finite (?B::?'a set); ?B ⊆ ?A; ⋀x::?'a. x ∈ ?A - ?B ⟹ (0::?'b) ≤ ?f x⟧ ⟹ sum ?f ?B ≤ ?S›*) has_sum_infsum (*‹(?f::?'a ⇒ ?'b) summable_on (?S::?'a set) ⟹ (?f has_sum infsum ?f ?S) ?S›*) norm_ge_zero (*‹(0::real) ≤ norm (?x::?'a)›*) s_def (*‹(s::'a ⇒ real) (?x::'a) = (∑⇩∞y::'b∈(B::'a ⇒ 'b set) ?x. norm ((f::'a ⇒ 'b ⇒ 'c) ?x y))›*) sum (*‹(?x::'a) ∈ (F::'a set) ⟹ (f::'a ⇒ 'b ⇒ 'c) ?x abs_summable_on (B::'a ⇒ 'b set) ?x›*) that (*‹(x::'a) ∈ (F::'a set)›*)) have "(∑p∈P. norm (∏x∈F. f x (p x))) ≤ (∑p∈Pi⇩E F B'. norm (∏x∈F. f x (p x)))" by (simp add: sum_mono2 (*‹⟦finite ?B; ?A ⊆ ?B; ⋀b. b ∈ ?B - ?A ⟹ 0 ≤ ?f b⟧ ⟹ sum ?f ?A ≤ sum ?f ?B›*)) also (*calculation: ‹(∑p∈P. norm (∏x∈F. f x (p x))) ≤ (∑p∈Pi⇩E F B'. norm (∏x∈F. f x (p x)))›*) have "… = (∑p∈Pi⇩E F B'. ∏x∈F. norm (f x (p x)))" by (simp add: prod_norm (*‹(∏x∈?A. norm (?f x)) = norm (prod ?f ?A)›*)) also (*calculation: ‹(∑p∈P. norm (∏x∈F. f x (p x))) ≤ (∑p∈Pi⇩E F B'. ∏x∈F. norm (f x (p x)))›*) have "… = (∏x∈F. ∑y∈B' x. norm (f x y))" proof (use ‹finite F› in induction) (*goals: 1. ‹(∑p::'a::type ⇒ 'b::type∈Pi⇩E {} (B'::'a::type ⇒ 'b::type set). ∏x::'a::type∈{}. norm ((f::'a::type ⇒ 'b::type ⇒ 'c::{banach,real_normed_div_algebra,comm_semiring_1}) x (p x))) = (∏x::'a::type∈{}. ∑y::'b::type∈B' x. norm (f x y))› 2. ‹⋀(x::'a::type) F::'a::type set. ⟦finite F; x ∉ F; (∑p::'a::type ⇒ 'b::type∈Pi⇩E F (B'::'a::type ⇒ 'b::type set). ∏x::'a::type∈F. norm ((f::'a::type ⇒ 'b::type ⇒ 'c::{banach,real_normed_div_algebra,comm_semiring_1}) x (p x))) = (∏x::'a::type∈F. ∑y::'b::type∈B' x. norm (f x y))⟧ ⟹ (∑p::'a::type ⇒ 'b::type∈Pi⇩E (insert x F) B'. ∏x::'a::type∈insert x F. norm (f x (p x))) = (∏x::'a::type∈insert x F. ∑y::'b::type∈B' x. norm (f x y))›*) case empty (*no hyothesis introduced yet*) then show "?case" (*goal: ‹(∑p∈Pi⇩E {} B'. ∏x∈{}. norm (f x (p x))) = (∏x∈{}. ∑y∈B' x. norm (f x y))›*) by simp next (*goal: ‹⋀x F. ⟦finite F; x ∉ F; (∑p∈Pi⇩E F B'. ∏x∈F. norm (f x (p x))) = (∏x∈F. ∑y∈B' x. norm (f x y))⟧ ⟹ (∑p∈Pi⇩E (insert x F) B'. ∏x∈insert x F. norm (f x (p x))) = (∏x∈insert x F. ∑y∈B' x. norm (f x y))›*) case (insert x F) (*‹finite F› ‹x ∉ F› ‹(∑p∈Pi⇩E F B'. ∏x∈F. norm (f x (p x))) = (∏x∈F. ∑y∈B' x. norm (f x y))›*) have inj: "inj_on (λ(g, y). g(x := y)) (Pi⇩E F B' × B' x)" by (simp add: inj_combinator' (*‹?x ∉ ?F ⟹ inj_on (λ(g, y). g(?x := y)) (Pi⇩E ?F ?B × ?B ?x)›*) insert.hyps (*‹finite F› ‹x ∉ F›*)) then have "(∑p∈Pi⇩E (insert x F) B'. ∏x∈insert x F. norm (f x (p x))) = (∑(p,y)∈Pi⇩E F B' × B' x. ∏x'∈insert x F. norm (f x' ((p(x := y)) x')))" by (simp add: pi (*‹Pi⇩E (insert (?x::'a) (?F::'a set)) (?B::'a ⇒ 'b set) = (λ(g::'a ⇒ 'b, y::'b). g(?x := y)) ` (Pi⇩E ?F ?B × ?B ?x)›*) sum.reindex (*‹inj_on (?h::?'b ⇒ ?'c) (?A::?'b set) ⟹ sum (?g::?'c ⇒ ?'a) (?h ` ?A) = sum (?g ∘ ?h) ?A›*) case_prod_unfold (*‹case_prod = (λ(c::?'a ⇒ ?'b ⇒ ?'c) p::?'a × ?'b. c (fst p) (snd p))›*)) also (*calculation: ‹(∑p∈Pi⇩E (insert x F) B'. ∏x∈insert x F. norm (f x (p x))) = (∑(p, y)∈Pi⇩E F B' × B' x. ∏x'∈insert x F. norm (f x' ((p(x := y)) x')))›*) have "… = (∑(p, y)∈Pi⇩E F B' × B' x. norm (f x y) * (∏x'∈F. norm (f x' (p x'))))" by (smt (verit, del_insts) fun_upd_apply (*‹(?f(?x := ?y)) ?z = (if ?z = ?x then ?y else ?f ?z)›*) insert.hyps (*‹finite F› ‹x ∉ F›*) prod.cong (*‹⟦?A = ?B; ⋀x. x ∈ ?B ⟹ ?g x = ?h x⟧ ⟹ prod ?g ?A = prod ?h ?B›*) prod.insert (*‹⟦finite ?A; ?x ∉ ?A⟧ ⟹ prod ?g (insert ?x ?A) = ?g ?x * prod ?g ?A›*) split_def (*‹case_prod = (λc p. c (fst p) (snd p))›*) sum.cong (*‹⟦?A = ?B; ⋀x. x ∈ ?B ⟹ ?g x = ?h x⟧ ⟹ sum ?g ?A = sum ?h ?B›*)) also (*calculation: ‹(∑p∈Pi⇩E (insert x F) B'. ∏x∈insert x F. norm (f x (p x))) = (∑(p, y)∈Pi⇩E F B' × B' x. norm (f x y) * (∏x'∈F. norm (f x' (p x'))))›*) have "… = (∑y∈B' x. norm (f x y)) * (∑p∈Pi⇩E F B'. ∏x'∈F. norm (f x' (p x')))" by (simp add: sum_product (*‹sum ?f ?A * sum ?g ?B = (∑i∈?A. ∑j∈?B. ?f i * ?g j)›*) sum.swap [of _ "Pi⇩E F B'"] (*‹(∑i∈?A. sum (?g i) (Pi⇩E F B')) = (∑j∈Pi⇩E F B'. ∑i∈?A. ?g i j)›*) sum.cartesian_product (*‹(∑x∈?A. sum (?g x) ?B) = (∑(x, y)∈?A × ?B. ?g x y)›*)) also (*calculation: ‹(∑p∈Pi⇩E (insert x F) B'. ∏x∈insert x F. norm (f x (p x))) = (∑y∈B' x. norm (f x y)) * (∑p∈Pi⇩E F B'. ∏x'∈F. norm (f x' (p x')))›*) have "… = (∏x∈insert x F. ∑y∈B' x. norm (f x y))" using insert (*‹finite F› ‹x ∉ F› ‹(∑p∈Pi⇩E F B'. ∏x∈F. norm (f x (p x))) = (∏x∈F. ∑y∈B' x. norm (f x y))›*) by force finally (*calculation: ‹(∑p∈Pi⇩E (insert x F) B'. ∏x∈insert x F. norm (f x (p x))) = (∏x∈insert x F. ∑y∈B' x. norm (f x y))›*) show "?case" (*goal: ‹(∑p∈Pi⇩E (insert x F) B'. ∏x∈insert x F. norm (f x (p x))) = (∏x∈insert x F. ∑y∈B' x. norm (f x y))›*) . qed also (*calculation: ‹(∑p::'a::type ⇒ 'b::type∈(P::('a::type ⇒ 'b::type) set). norm (∏x::'a::type∈(F::'a::type set). (f::'a::type ⇒ 'b::type ⇒ 'c::{banach,real_normed_div_algebra,comm_semiring_1}) x (p x))) ≤ (∏x::'a::type∈F. ∑y::'b::type∈(B'::'a::type ⇒ 'b::type set) x. norm (f x y))›*) have "… ≤ (∏x∈F. s x)" using s_bound (*‹(?x::'a) ∈ (F::'a set) ⟹ (∑y::'b∈(B'::'a ⇒ 'b set) ?x. norm ((f::'a ⇒ 'b ⇒ 'c) ?x y)) ≤ (s::'a ⇒ real) ?x›*) by (simp add: prod_mono (*‹(⋀i. i ∈ ?A ⟹ 0 ≤ ?f i ∧ ?f i ≤ ?g i) ⟹ prod ?f ?A ≤ prod ?g ?A›*) sum_nonneg (*‹(⋀x. x ∈ ?A ⟹ 0 ≤ ?f x) ⟹ 0 ≤ sum ?f ?A›*)) finally (*calculation: ‹(∑p∈P. norm (∏x∈F. f x (p x))) ≤ prod s F›*) show "?thesis" (*goal: ‹(∑p∈P. norm (∏x∈F. f x (p x))) ≤ prod s F›*) . qed then have "bdd_above (sum (λg. norm (∏x∈insert x A. f x (g x))) ` {F. F ⊆ Pi⇩E (insert x A) B ∧ finite F})" using insert.hyps (*‹finite A› ‹x ∉ A›*) insert.prems (*‹?x ∈ insert x A ⟹ f ?x abs_summable_on B ?x›*) apply (intro bdd_aboveI (*‹(⋀x. x ∈ ?A ⟹ x ≤ ?M) ⟹ bdd_above ?A›*)) (*goal: ‹bdd_above (sum (λg. norm (∏x∈insert x A. f x (g x))) ` {F. F ⊆ Pi⇩E (insert x A) B ∧ finite F})›*) by blast then have "(λg. ∏x∈insert x A. f x (g x)) abs_summable_on Pi⇩E (insert x A) B" using nonneg_bdd_above_summable_on (*‹⟦⋀x. x ∈ ?A ⟹ 0 ≤ ?f x; bdd_above (sum ?f ` {F. F ⊆ ?A ∧ finite F})⟧ ⟹ ?f summable_on ?A›*) by (metis (mono_tags, lifting) Collect_cong (*‹(⋀x::?'a::type. (?P::?'a::type ⇒ bool) x = (?Q::?'a::type ⇒ bool) x) ⟹ {x::?'a::type. ?P x} = {x::?'a::type. ?Q x}›*) norm_ge_zero (*‹(0::real) ≤ norm (?x::?'a::real_normed_vector)›*)) also (*calculation: ‹(λxa. ∏x∈insert x A. f x (xa x)) abs_summable_on Pi⇩E (insert x A) B›*) have "Pi⇩E (insert x A) B = (λ(g,y). g(x:=y)) ` (Pi⇩E A B × B x)" by (simp only: pi (*‹Pi⇩E (insert ?x ?F) ?B = (λ(g, y). g(?x := y)) ` (Pi⇩E ?F ?B × ?B ?x)›*)) also (*calculation: ‹(λxa. ∏x∈insert x A. f x (xa x)) abs_summable_on (λ(g, y). g(x := y)) ` (Pi⇩E A B × B x)›*) have "(λg. ∏x∈insert x A. f x (g x)) abs_summable_on … ⟷ ((λg. ∏x∈insert x A. f x (g x)) ∘ (λ(g,y). g(x:=y))) abs_summable_on (Pi⇩E A B × B x)" using inj (*‹inj_on (λ(g, y). g(x := y)) (Pi⇩E A B × B x)›*) apply (subst summable_on_reindex (*‹inj_on ?h ?A ⟹ (?g summable_on ?h ` ?A) = (?g ∘ ?h summable_on ?A)›*)) (*goals: 1. ‹inj_on (λ(g, y). g(x := y)) (Pi⇩E A B × B x) ⟹ inj_on (λ(g, y). g(x := y)) (Pi⇩E A B × B x)› 2. ‹inj_on (λ(g, y). g(x := y)) (Pi⇩E A B × B x) ⟹ ((λxa. norm (∏x∈insert x A. f x (xa x))) ∘ (λ(g, y). g(x := y)) summable_on Pi⇩E A B × B x) = ((λg. ∏x∈insert x A. f x (g x)) ∘ (λ(g, y). g(x := y)) abs_summable_on Pi⇩E A B × B x)› discuss goal 1*) apply ((auto simp: o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*))[1]) (*discuss goal 2*) apply ((auto simp: o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*))[1]) (*proven 2 subgoals*) . also (*calculation: ‹(λg::'a ⇒ 'b. ∏x::'a∈insert (x::'a) (A::'a set). (f::'a ⇒ 'b ⇒ 'c) x (g x)) ∘ (λ(g::'a ⇒ 'b, y::'b). g(x := y)) abs_summable_on Pi⇩E A (B::'a ⇒ 'b set) × B x›*) have "(∏z∈A. f z ((g(x := y)) z)) = (∏z∈A. f z (g z))" for g and y using insert.hyps (*‹finite A› ‹(x::'a) ∉ (A::'a set)›*) apply (intro prod.cong (*‹⟦(?A::?'b::type set) = (?B::?'b::type set); ⋀x::?'b::type. x ∈ ?B ⟹ (?g::?'b::type ⇒ ?'a::comm_monoid_mult) x = (?h::?'b::type ⇒ ?'a::comm_monoid_mult) x⟧ ⟹ prod ?g ?A = prod ?h ?B›*)) (*goals: 1. ‹⟦finite (A::'a::type set); (x::'a::type) ∉ A⟧ ⟹ A = A› 2. ‹⋀xa::'a::type. ⟦finite (A::'a::type set); (x::'a::type) ∉ A; xa ∈ A⟧ ⟹ (f::'a::type ⇒ 'b::type ⇒ 'c::{banach,real_normed_div_algebra,comm_semiring_1}) xa (((g::'a::type ⇒ 'b::type)(x := y::'b::type)) xa) = f xa (g xa)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . hence "((λg. ∏x∈insert x A. f x (g x)) ∘ (λ(g,y). g(x:=y))) = (λ(p, y). f x y * (∏x'∈A. f x' (p x')))" using insert.hyps (*‹finite A› ‹(x::'a) ∉ (A::'a set)›*) by (auto simp: fun_eq_iff (*‹(?f = ?g) = (∀x. ?f x = ?g x)›*) cong: prod.cong_simp (*‹⟦?A = ?B; ⋀x. x ∈ ?B =simp=> ?g x = ?h x⟧ ⟹ prod ?g ?A = prod ?h ?B›*)) finally (*calculation: ‹(λxa. case xa of (p, y) ⇒ f x y * (∏x'∈A. f x' (p x'))) abs_summable_on Pi⇩E A B × B x›*) have summable2: "(λ(p, y). f x y * (∏x'∈A. f x' (p x'))) abs_summable_on Pi⇩E A B × B x" . have "(∑⇩∞g∈Pi⇩E (insert x A) B. ∏x∈insert x A. f x (g x)) = (∑⇩∞(p,y)∈Pi⇩E A B × B x. ∏x'∈insert x A. f x' ((p(x:=y)) x'))" using inj (*‹inj_on (λ(g::'a ⇒ 'b, y::'b). g(x::'a := y)) (Pi⇩E (A::'a set) (B::'a ⇒ 'b set) × B x)›*) by (simp add: pi (*‹Pi⇩E (insert (?x::'a) (?F::'a set)) (?B::'a ⇒ 'b set) = (λ(g::'a ⇒ 'b, y::'b). g(?x := y)) ` (Pi⇩E ?F ?B × ?B ?x)›*) infsum_reindex (*‹inj_on (?h::?'a ⇒ ?'b) (?A::?'a set) ⟹ infsum (?g::?'b ⇒ ?'c) (?h ` ?A) = infsum (?g ∘ ?h) ?A›*) o_def (*‹(?f::?'b ⇒ ?'c) ∘ (?g::?'a ⇒ ?'b) = (λx::?'a. ?f (?g x))›*) case_prod_unfold (*‹case_prod = (λ(c::?'a ⇒ ?'b ⇒ ?'c) p::?'a × ?'b. c (fst p) (snd p))›*)) also (*calculation: ‹(∑⇩∞g∈Pi⇩E (insert x A) B. ∏x∈insert x A. f x (g x)) = (∑⇩∞(p, y)∈Pi⇩E A B × B x. ∏x'∈insert x A. f x' ((p(x := y)) x'))›*) have "… = (∑⇩∞(p,y) ∈ Pi⇩E A B × B x. f x y * (∏x'∈A. f x' (p x')))" using prod (*‹(∏x'::'a∈(A::'a set). (f::'a ⇒ 'b ⇒ 'c) x' (((?p::'a ⇒ 'b)(x::'a := ?y::'b)) x')) = (∏x'::'a∈A. f x' (?p x'))›*) insert.hyps (*‹finite (A::'a set)› ‹x ∉ A›*) by auto also (*calculation: ‹(∑⇩∞g∈Pi⇩E (insert x A) B. ∏x∈insert x A. f x (g x)) = (∑⇩∞(p, y)∈Pi⇩E A B × B x. f x y * (∏x'∈A. f x' (p x')))›*) have "… = (∑⇩∞p∈Pi⇩E A B. ∑⇩∞y∈B x. f x y * (∏x'∈A. f x' (p x')))" using abs_summable_summable (*‹?f abs_summable_on ?A ⟹ ?f summable_on ?A›*) infsum_Sigma'_banach (*‹(λ(x, y). ?f x y) summable_on Sigma ?A ?B ⟹ (∑⇩∞x∈?A. infsum (?f x) (?B x)) = (∑⇩∞(x, y)∈Sigma ?A ?B. ?f x y)›*) summable2 (*‹(λxa. case xa of (p, y) ⇒ f x y * (∏x'∈A. f x' (p x'))) abs_summable_on Pi⇩E A B × B x›*) by fastforce also (*calculation: ‹(∑⇩∞g::'a ⇒ 'b∈Pi⇩E (insert x A) (B::'a ⇒ 'b set). ∏x::'a∈insert (x::'a) (A::'a set). (f::'a ⇒ 'b ⇒ 'c) x (g x)) = (∑⇩∞p::'a ⇒ 'b∈Pi⇩E A B. ∑⇩∞y::'b∈B x. f x y * (∏x'::'a∈A. f x' (p x')))›*) have "… = (∑⇩∞y∈B x. f x y) * (∑⇩∞p∈Pi⇩E A B. ∏x'∈A. f x' (p x'))" by (smt (verit, best) infsum_cmult_left' (*‹(∑⇩∞x∈?A. ?f x * ?c) = infsum ?f ?A * ?c›*) infsum_cmult_right' (*‹(∑⇩∞x∈?A. ?c * ?f x) = ?c * infsum ?f ?A›*) infsum_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ infsum ?f ?A = infsum ?g ?A›*)) finally (*calculation: ‹(∑⇩∞g∈Pi⇩E (insert x A) B. ∏x∈insert x A. f x (g x)) = infsum (f x) (B x) * (∑⇩∞p∈Pi⇩E A B. ∏x'∈A. f x' (p x'))›*) show "?case" (*goal: ‹(∑⇩∞g∈Pi⇩E (insert x A) B. ∏x∈insert x A. f x (g x)) = (∏x∈insert x A. infsum (f x) (B x))›*) by (simp add: insert (*‹finite A› ‹x ∉ A› ‹(⋀x. x ∈ A ⟹ f x abs_summable_on B x) ⟹ (∑⇩∞g∈Pi⇩E A B. ∏x∈A. f x (g x)) = (∏x∈A. infsum (f x) (B x))› ‹?x ∈ insert x A ⟹ f ?x abs_summable_on B ?x›*)) qed subsection ‹Absolute convergence› lemma abs_summable_countable: assumes ‹f abs_summable_on A› shows ‹countable {x∈A. f x ≠ 0}› proof (-) (*goal: ‹countable {x ∈ A. f x ≠ 0}›*) have fin: "finite {x∈A. norm (f x) ≥ t}" if "t > 0" for t proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹infinite {x ∈ A. t ≤ norm (f x)} ⟹ False›*) assume "*": "infinite {x ∈ A. t ≤ norm (f x)}" (*‹infinite {x::'a ∈ A::'a set. (t::real) ≤ norm ((f::'a ⇒ 'b) x)}›*) have "infsum (λx. norm (f x)) A ≥ b" for b proof (-) (*goal: ‹b ≤ (∑⇩∞x∈A. norm (f x))›*) obtain b' where b': "of_nat b' ≥ b / t" (*goal: ‹(⋀b'. b / t ≤ real b' ⟹ thesis) ⟹ thesis›*) by (meson real_arch_simple (*‹∃n. ?x ≤ of_nat n›*)) from "*" (*‹infinite {x ∈ A. t ≤ norm (f x)}›*) obtain F where cardF: "card F ≥ b'" and "finite F" and F: "F ⊆ {x ∈ A. t ≤ norm (f x)}" (*goal: ‹(⋀F. ⟦b' ≤ card F; finite F; F ⊆ {x ∈ A. t ≤ norm (f x)}⟧ ⟹ thesis) ⟹ thesis›*) by (meson finite_if_finite_subsets_card_bdd (*‹(⋀G::?'a set. ⟦G ⊆ (?F::?'a set); finite G⟧ ⟹ card G ≤ (?C::nat)) ⟹ finite ?F ∧ card ?F ≤ ?C›*) nle_le (*‹(¬ (?a::?'a) ≤ (?b::?'a)) = (?b ≤ ?a ∧ ?b ≠ ?a)›*)) have "b ≤ of_nat b' * t" using b' (*‹b / t ≤ real b'›*) ‹t > 0› (*‹0 < t›*) by (simp add: field_simps (*‹(?a::?'a::semigroup_add) + (?b::?'a::semigroup_add) + (?c::?'a::semigroup_add) = ?a + (?b + ?c)› ‹(?a::?'a::ab_semigroup_add) + (?b::?'a::ab_semigroup_add) = ?b + ?a› ‹(?b::?'a::ab_semigroup_add) + ((?a::?'a::ab_semigroup_add) + (?c::?'a::ab_semigroup_add)) = ?a + (?b + ?c)› ‹(?a::?'a::semigroup_mult) * (?b::?'a::semigroup_mult) * (?c::?'a::semigroup_mult) = ?a * (?b * ?c)› ‹(?a::?'a::ab_semigroup_mult) * (?b::?'a::ab_semigroup_mult) = ?b * ?a› ‹(?b::?'a::ab_semigroup_mult) * ((?a::?'a::ab_semigroup_mult) * (?c::?'a::ab_semigroup_mult)) = ?a * (?b * ?c)› ‹(?a::?'a::cancel_ab_semigroup_add) - (?b::?'a::cancel_ab_semigroup_add) - (?c::?'a::cancel_ab_semigroup_add) = ?a - (?b + ?c)› ‹(?a::?'a::group_add) + ((?b::?'a::group_add) - (?c::?'a::group_add)) = ?a + ?b - ?c› ‹((?a::?'a::group_add) - (?b::?'a::group_add) = (?c::?'a::group_add)) = (?a = ?c + ?b)› ‹((?a::?'a::group_add) = (?c::?'a::group_add) - (?b::?'a::group_add)) = (?a + ?b = ?c)› ‹(?a::?'a::group_add) - ((?b::?'a::group_add) - (?c::?'a::group_add)) = ?a + ?c - ?b› ‹(?a::?'a::ab_group_add) - (?b::?'a::ab_group_add) + (?c::?'a::ab_group_add) = ?a + ?c - ?b› and more 69 facts*) split: if_splits (*‹(?P::?'a::type ⇒ bool) (if ?Q::bool then ?x::?'a::type else (?y::?'a::type)) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹(?P::?'a::type ⇒ bool) (if ?Q::bool then ?x::?'a::type else (?y::?'a::type)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) also (*calculation: ‹(b::real) ≤ real (b'::nat) * (t::real)›*) have "… ≤ of_nat (card F) * t" by (simp add: cardF (*‹b' ≤ card F›*) that (*‹0 < t›*)) also (*calculation: ‹b ≤ real (card F) * t›*) have "… = sum (λx. t) F" by simp also (*calculation: ‹(b::real) ≤ (∑x::'a∈(F::'a set). (t::real))›*) have "… ≤ sum (λx. norm (f x)) F" by (metis (mono_tags, lifting) F (*‹F ⊆ {x ∈ A. t ≤ norm (f x)}›*) in_mono (*‹?A ⊆ ?B ⟹ ?x ∈ ?A ⟶ ?x ∈ ?B›*) mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*) sum_mono (*‹(⋀i. i ∈ ?K ⟹ ?f i ≤ ?g i) ⟹ sum ?f ?K ≤ sum ?g ?K›*)) also (*calculation: ‹b ≤ (∑x∈F. norm (f x))›*) have "… = infsum (λx. norm (f x)) F" using ‹finite F› (*‹finite F›*) by (rule infsum_finite[symmetric] (*‹finite ?F ⟹ sum ?f ?F = infsum ?f ?F›*)) also (*calculation: ‹b ≤ (∑⇩∞x∈F. norm (f x))›*) have "… ≤ infsum (λx. norm (f x)) A" apply (rule infsum_mono_neutral (*‹⟦?f summable_on ?A; ?g summable_on ?B; ⋀x. x ∈ ?A ∩ ?B ⟹ ?f x ≤ ?g x; ⋀x. x ∈ ?A - ?B ⟹ ?f x ≤ 0; ⋀x. x ∈ ?B - ?A ⟹ 0 ≤ ?g x⟧ ⟹ infsum ?f ?A ≤ infsum ?g ?B›*)) (*goals: 1. ‹f abs_summable_on F› 2. ‹f abs_summable_on A› 3. ‹⋀x. x ∈ F ∩ A ⟹ norm (f x) ≤ norm (f x)› 4. ‹⋀x. x ∈ F - A ⟹ norm (f x) ≤ 0› 5. ‹⋀x. x ∈ A - F ⟹ 0 ≤ norm (f x)› discuss goal 1*) apply ((use ‹finite F› assms F in auto)[1]) (*discuss goal 2*) apply ((use ‹finite F› assms F in auto)[1]) (*discuss goal 3*) apply ((use ‹finite F› assms F in auto)[1]) (*discuss goal 4*) apply ((use ‹finite F› assms F in auto)[1]) (*discuss goal 5*) apply ((use ‹finite F› assms F in auto)[1]) (*proven 5 subgoals*) . finally (*calculation: ‹b ≤ (∑⇩∞x∈A. norm (f x))›*) show "?thesis" (*goal: ‹b ≤ (∑⇩∞x∈A. norm (f x))›*) . qed then show False by (meson gt_ex (*‹∃y. ?x < y›*) linorder_not_less (*‹(¬ ?x < ?y) = (?y ≤ ?x)›*)) qed have "countable (⋃i∈{1..}. {x∈A. norm (f x) ≥ 1/of_nat i})" apply (rule countable_UN (*‹⟦countable (?I::?'i set); ⋀i::?'i. i ∈ ?I ⟹ countable ((?A::?'i ⇒ ?'a set) i)⟧ ⟹ countable (⋃ (?A ` ?I))›*)) (*goals: 1. ‹countable {1..}› 2. ‹⋀i. i ∈ {1..} ⟹ countable {x ∈ A. 1 / real i ≤ norm (f x)}› discuss goal 1*) apply ((use fin in ‹auto intro!: countable_finite›)[1]) (*discuss goal 2*) apply ((use fin in ‹auto intro!: countable_finite›)[1]) (*proven 2 subgoals*) . also (*calculation: ‹countable (⋃i::nat∈{1::nat..}. {x::'a::type ∈ A::'a::type set. (1::real) / real i ≤ norm ((f::'a::type ⇒ 'b::real_normed_vector) x)})›*) have "… = {x∈A. f x ≠ 0}" proof (safe) (*goals: 1. ‹⋀x i. ⟦1 ≤ i; x ∈ A; 1 / real i ≤ norm (f x); f x = 0⟧ ⟹ False› 2. ‹⋀x. ⟦x ∈ A; f x ≠ 0⟧ ⟹ x ∈ (⋃i∈{1..}. {x ∈ A. 1 / real i ≤ norm (f x)})›*) fix x assume x: "x ∈ A" "f x ≠ 0" (*‹(x::'a) ∈ (A::'a set)› ‹(f::'a ⇒ 'b) (x::'a) ≠ (0::'b)›*) define i where "i = max 1 (nat (ceiling (1 / norm (f x))))" have "i ≥ 1" by (simp add: i_def (*‹i = max 1 (nat ⌈1 / norm (f x)⌉)›*)) moreover have "real i ≥ 1 / norm (f x)" unfolding i_def (*goal: ‹1 / norm (f x) ≤ real (max 1 (nat ⌈1 / norm (f x)⌉))›*) by linarith hence "1 / real i ≤ norm (f x)" using ‹f x ≠ 0› (*‹f x ≠ 0›*) by (auto simp: divide_simps (*‹inverse ?a = 1 / ?a› ‹?a + ?b / ?z = (if ?z = 0 then ?a else (?a * ?z + ?b) / ?z)› ‹?a / ?z + ?b = (if ?z = 0 then ?b else (?a + ?b * ?z) / ?z)› ‹- (?a / ?z) + ?b = (if ?z = 0 then ?b else (- ?a + ?b * ?z) / ?z)› ‹?a - ?b / ?z = (if ?z = 0 then ?a else (?a * ?z - ?b) / ?z)› ‹?a / ?z - ?b = (if ?z = 0 then - ?b else (?a - ?b * ?z) / ?z)› ‹- (?a / ?z) - ?b = (if ?z = 0 then - ?b else (- ?a - ?b * ?z) / ?z)› ‹(?b / ?c = ?a) = (if ?c ≠ 0 then ?b = ?a * ?c else ?a = 0)› ‹(?a = ?b / ?c) = (if ?c ≠ 0 then ?a * ?c = ?b else ?a = 0)› ‹(- (?b / ?c) = ?a) = (if ?c ≠ 0 then - ?b = ?a * ?c else ?a = 0)› ‹(?a = - (?b / ?c)) = (if ?c ≠ 0 then ?a * ?c = - ?b else ?a = 0)› ‹(?a ≤ ?b / ?c) = (if 0 < ?c then ?a * ?c ≤ ?b else if ?c < 0 then ?b ≤ ?a * ?c else ?a ≤ 0)› and more 13 facts*) mult_ac (*‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)›*)) ultimately show "x ∈ (⋃i∈{1..}. {x ∈ A. 1 / real i ≤ norm (f x)})" using ‹x ∈ A› (*‹(x::'a::type) ∈ (A::'a::type set)›*) by auto qed (auto) (*solved the remaining goal: ‹⋀x i. ⟦1 ≤ i; x ∈ A; 1 / real i ≤ norm (f x); f x = 0⟧ ⟹ False›*) finally (*calculation: ‹countable {x::'a ∈ A::'a set. (f::'a ⇒ 'b) x ≠ (0::'b)}›*) show "?thesis" (*goal: ‹countable {x::'a ∈ A::'a set. (f::'a ⇒ 'b) x ≠ (0::'b)}›*) . qed (* Logically belongs in the section about reals, but needed as a dependency here *) lemma summable_on_iff_abs_summable_on_real: fixes f :: ‹'a ⇒ real› shows ‹f summable_on A ⟷ f abs_summable_on A› proof (rule iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*)) (*goals: 1. ‹f summable_on A ⟹ f abs_summable_on A› 2. ‹f abs_summable_on A ⟹ f summable_on A›*) assume "f summable_on A" (*‹(f::'a ⇒ real) summable_on (A::'a set)›*) define n and A⇩p and A⇩n where "n ≡ λx. norm (f x)" and "A⇩p = {x∈A. f x ≥ 0}" and "A⇩n = {x∈A. f x < 0}" for x have A: "A⇩p ∪ A⇩n = A" "A⇩p ∩ A⇩n = {}" (*goals: 1. ‹A⇩p ∪ A⇩n = A› 2. ‹A⇩p ∩ A⇩n = {}› discuss goal 1*) apply ((auto simp: A⇩p_def (*‹A⇩p = {x ∈ A. 0 ≤ f x}›*) A⇩n_def (*‹A⇩n = {x ∈ A. f x < 0}›*))[1]) (*discuss goal 2*) apply ((auto simp: A⇩p_def (*‹A⇩p = {x ∈ A. 0 ≤ f x}›*) A⇩n_def (*‹A⇩n = {x ∈ A. f x < 0}›*))[1]) (*proven 2 subgoals*) . from ‹f summable_on A› (*‹f summable_on A›*) have "f summable_on A⇩p" "f summable_on A⇩n" using "A⇩p_def" (*‹(A⇩p::'a set) = {x::'a ∈ A::'a set. (0::real) ≤ (f::'a ⇒ real) x}›*) "A⇩n_def" (*‹A⇩n = {x ∈ A. f x < 0}›*) summable_on_subset_banach (*‹⟦?f summable_on ?A; ?B ⊆ ?A⟧ ⟹ ?f summable_on ?B›*) apply - (*goals: 1. ‹⟦f summable_on A; A⇩p = {x ∈ A. 0 ≤ f x}; A⇩n = {x ∈ A. f x < 0}; ⋀f A B. ⟦f summable_on A; B ⊆ A⟧ ⟹ f summable_on B⟧ ⟹ f summable_on A⇩p› 2. ‹⟦f summable_on A; A⇩p = {x ∈ A. 0 ≤ f x}; A⇩n = {x ∈ A. f x < 0}; ⋀f A B. ⟦f summable_on A; B ⊆ A⟧ ⟹ f summable_on B⟧ ⟹ f summable_on A⇩n› discuss goal 1*) apply fastforce (*discuss goal 2*) apply fastforce (*proven 2 subgoals*) . then have "n summable_on A⇩p" by (smt (verit) A⇩p_def (*‹A⇩p = {x ∈ A. 0 ≤ f x}›*) n_def (*‹n ≡ λx. norm (f x)›*) mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*) real_norm_def (*‹norm ?r = ¦?r¦›*) summable_on_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ (?f summable_on ?A) = (?g summable_on ?A)›*)) moreover have "n summable_on A⇩n" by (smt (verit, best) ‹f summable_on A⇩n› summable_on_uminus (*‹((λx. - ?f x) summable_on ?A) = (?f summable_on ?A)›*) A⇩n_def (*‹A⇩n = {x ∈ A. f x < 0}›*) n_def (*‹n ≡ λx. norm (f x)›*) summable_on_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ (?f summable_on ?A) = (?g summable_on ?A)›*) mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*) real_norm_def (*‹norm ?r = ¦?r¦›*)) ultimately show "n summable_on A" using A (*‹A⇩p ∪ A⇩n = A› ‹A⇩p ∩ A⇩n = {}›*) summable_on_Un_disjoint (*‹⟦?f summable_on ?A; ?f summable_on ?B; ?A ∩ ?B = {}⟧ ⟹ ?f summable_on ?A ∪ ?B›*) by blast next (*goal: ‹f abs_summable_on A ⟹ f summable_on A›*) show "f abs_summable_on A ⟹ f summable_on A" using abs_summable_summable (*‹?f abs_summable_on ?A ⟹ ?f summable_on ?A›*) by blast qed lemma abs_summable_on_Sigma_iff: shows "f abs_summable_on Sigma A B ⟷ (∀x∈A. (λy. f (x, y)) abs_summable_on B x) ∧ ((λx. infsum (λy. norm (f (x, y))) (B x)) abs_summable_on A)" proof (intro iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*) conjI (*‹⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q›*) ballI (*‹(⋀x. x ∈ ?A ⟹ ?P x) ⟹ ∀x∈?A. ?P x›*)) (*goals: 1. ‹⋀x. ⟦f abs_summable_on Sigma A B; x ∈ A⟧ ⟹ (λxa. f (x, xa)) abs_summable_on B x› 2. ‹f abs_summable_on Sigma A B ⟹ (λx. ∑⇩∞y∈B x. norm (f (x, y))) abs_summable_on A› 3. ‹(∀x∈A. (λxa. f (x, xa)) abs_summable_on B x) ∧ (λx. ∑⇩∞y∈B x. norm (f (x, y))) abs_summable_on A ⟹ f abs_summable_on Sigma A B›*) assume asm: "f abs_summable_on Sigma A B" (*‹(f::'a × 'b ⇒ 'c) abs_summable_on Sigma (A::'a set) (B::'a ⇒ 'b set)›*) then have "(λx. infsum (λy. norm (f (x,y))) (B x)) summable_on A" by (simp add: cond_case_prod_eta (*‹(⋀x y. ?f x y = ?g (x, y)) ⟹ (λ(x, y). ?f x y) = ?g›*) summable_on_Sigma_banach (*‹(λ(x, y). ?f x y) summable_on Sigma ?A ?B ⟹ (λx. infsum (?f x) (?B x)) summable_on ?A›*)) then show "(λx. ∑⇩∞y∈B x. norm (f (x, y))) abs_summable_on A" using summable_on_iff_abs_summable_on_real (*‹(?f summable_on ?A) = (?f abs_summable_on ?A)›*) by force show "(λy. f (x, y)) abs_summable_on B x" if "x ∈ A" for x proof (-) (*goal: ‹(λxa. f (x, xa)) abs_summable_on B x›*) from asm (*‹f abs_summable_on Sigma A B›*) have "f abs_summable_on Pair x ` B x" by (simp add: image_subset_iff (*‹(?f ` ?A ⊆ ?B) = (∀x∈?A. ?f x ∈ ?B)›*) summable_on_subset_banach (*‹⟦?f summable_on ?A; ?B ⊆ ?A⟧ ⟹ ?f summable_on ?B›*) that (*‹x ∈ A›*)) then show "?thesis" (*goal: ‹(λxa::'b. (f::'a × 'b ⇒ 'c) (x::'a, xa)) abs_summable_on (B::'a ⇒ 'b set) x›*) by (metis (mono_tags, lifting) o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*) inj_on_def (*‹inj_on ?f ?A = (∀x∈?A. ∀y∈?A. ?f x = ?f y ⟶ x = y)›*) summable_on_reindex (*‹inj_on ?h ?A ⟹ (?g summable_on ?h ` ?A) = (?g ∘ ?h summable_on ?A)›*) prod.inject (*‹((?x1.0, ?x2.0) = (?y1.0, ?y2.0)) = (?x1.0 = ?y1.0 ∧ ?x2.0 = ?y2.0)›*) summable_on_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ (?f summable_on ?A) = (?g summable_on ?A)›*)) qed next (*goal: ‹(∀x∈A. (λxa. f (x, xa)) abs_summable_on B x) ∧ (λx. ∑⇩∞y∈B x. norm (f (x, y))) abs_summable_on A ⟹ f abs_summable_on Sigma A B›*) assume asm: "(∀x∈A. (λxa. f (x, xa)) abs_summable_on B x) ∧ (λx. ∑⇩∞y∈B x. norm (f (x, y))) abs_summable_on A" (*‹(∀x::'a∈A::'a set. (λxa::'b. (f::'a × 'b ⇒ 'c) (x, xa)) abs_summable_on (B::'a ⇒ 'b set) x) ∧ (λx::'a. ∑⇩∞y::'b∈B x. norm (f (x, y))) abs_summable_on A›*) have "(∑xy∈F. norm (f xy)) ≤ (∑⇩∞x∈A. ∑⇩∞y∈B x. norm (f (x, y)))" if "F ⊆ Sigma A B" and [simp]: "finite F" for F proof (-) (*goal: ‹(∑xy∈F. norm (f xy)) ≤ (∑⇩∞x∈A. ∑⇩∞y∈B x. norm (f (x, y)))›*) have [simp]: "(SIGMA x:fst ` F. {y. (x, y) ∈ F}) = F" by (auto intro!: set_eqI (*‹(⋀x. (x ∈ ?A) = (x ∈ ?B)) ⟹ ?A = ?B›*) simp add: Domain.DomainI (*‹(?a, ?b) ∈ ?r ⟹ ?a ∈ Domain ?r›*) fst_eq_Domain (*‹fst ` ?R = Domain ?R›*)) have [simp]: "finite {y. (x, y) ∈ F}" for x by (metis ‹finite F› Range.intros (*‹(?a, ?b) ∈ ?r ⟹ ?b ∈ Range ?r›*) finite_Range (*‹finite ?r ⟹ finite (Range ?r)›*) finite_subset (*‹⟦?A ⊆ ?B; finite ?B⟧ ⟹ finite ?A›*) mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*) subsetI (*‹(⋀x. x ∈ ?A ⟹ x ∈ ?B) ⟹ ?A ⊆ ?B›*)) have "(∑xy∈F. norm (f xy)) = (∑x∈fst ` F. ∑y∈{y. (x,y)∈F}. norm (f (x,y)))" by (simp add: sum.Sigma (*‹⟦finite ?A; ∀x∈?A. finite (?B x)⟧ ⟹ (∑x∈?A. sum (?g x) (?B x)) = (∑(x, y)∈Sigma ?A ?B. ?g x y)›*)) also (*calculation: ‹(∑xy∈F. norm (f xy)) = (∑x∈fst ` F. ∑y | (x, y) ∈ F. norm (f (x, y)))›*) have "… = (∑⇩∞x∈fst ` F. ∑⇩∞y∈{y. (x,y)∈F}. norm (f (x,y)))" by auto also (*calculation: ‹(∑xy∈F. norm (f xy)) = (∑⇩∞x∈fst ` F. ∑⇩∞y | (x, y) ∈ F. norm (f (x, y)))›*) have "… ≤ (∑⇩∞x∈fst ` F. ∑⇩∞y∈B x. norm (f (x,y)))" using asm (*‹(∀x∈A. (λxa. f (x, xa)) abs_summable_on B x) ∧ (λx. ∑⇩∞y∈B x. norm (f (x, y))) abs_summable_on A›*) that(1) (*‹F ⊆ Sigma A B›*) apply (intro infsum_mono (*‹⟦?f summable_on ?A; ?g summable_on ?A; ⋀x. x ∈ ?A ⟹ ?f x ≤ ?g x⟧ ⟹ infsum ?f ?A ≤ infsum ?g ?A›*) infsum_mono_neutral (*‹⟦?f summable_on ?A; ?g summable_on ?B; ⋀x. x ∈ ?A ∩ ?B ⟹ ?f x ≤ ?g x; ⋀x. x ∈ ?A - ?B ⟹ ?f x ≤ 0; ⋀x. x ∈ ?B - ?A ⟹ 0 ≤ ?g x⟧ ⟹ infsum ?f ?A ≤ infsum ?g ?B›*)) (*goals: 1. ‹⟦(∀x∈A. (λxa. f (x, xa)) abs_summable_on B x) ∧ (λx. ∑⇩∞y∈B x. norm (f (x, y))) abs_summable_on A; F ⊆ Sigma A B⟧ ⟹ (λx. ∑⇩∞y | (x, y) ∈ F. norm (f (x, y))) summable_on fst ` F› 2. ‹⟦(∀x∈A. (λxa. f (x, xa)) abs_summable_on B x) ∧ (λx. ∑⇩∞y∈B x. norm (f (x, y))) abs_summable_on A; F ⊆ Sigma A B⟧ ⟹ (λx. ∑⇩∞y∈B x. norm (f (x, y))) summable_on fst ` F› 3. ‹⋀x. ⟦(∀x∈A. (λxa. f (x, xa)) abs_summable_on B x) ∧ (λx. ∑⇩∞y∈B x. norm (f (x, y))) abs_summable_on A; F ⊆ Sigma A B; x ∈ fst ` F⟧ ⟹ (λy. f (x, y)) abs_summable_on {y. (x, y) ∈ F}› 4. ‹⋀x. ⟦(∀x∈A. (λxa. f (x, xa)) abs_summable_on B x) ∧ (λx. ∑⇩∞y∈B x. norm (f (x, y))) abs_summable_on A; F ⊆ Sigma A B; x ∈ fst ` F⟧ ⟹ (λy. f (x, y)) abs_summable_on B x› 5. ‹⋀x xa. ⟦(∀x∈A. (λxa. f (x, xa)) abs_summable_on B x) ∧ (λx. ∑⇩∞y∈B x. norm (f (x, y))) abs_summable_on A; F ⊆ Sigma A B; x ∈ fst ` F; xa ∈ {y. (x, y) ∈ F} ∩ B x⟧ ⟹ norm (f (x, xa)) ≤ norm (f (x, xa))› 6. ‹⋀x xa. ⟦(∀x∈A. (λxa. f (x, xa)) abs_summable_on B x) ∧ (λx. ∑⇩∞y∈B x. norm (f (x, y))) abs_summable_on A; F ⊆ Sigma A B; x ∈ fst ` F; xa ∈ {y. (x, y) ∈ F} - B x⟧ ⟹ norm (f (x, xa)) ≤ 0› 7. ‹⋀x xa. ⟦(∀x∈A. (λxa. f (x, xa)) abs_summable_on B x) ∧ (λx. ∑⇩∞y∈B x. norm (f (x, y))) abs_summable_on A; F ⊆ Sigma A B; x ∈ fst ` F; xa ∈ B x - {y. (x, y) ∈ F}⟧ ⟹ 0 ≤ norm (f (x, xa))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*proven 7 subgoals*) . also (*calculation: ‹(∑xy∈F. norm (f xy)) ≤ (∑⇩∞x∈fst ` F. ∑⇩∞y∈B x. norm (f (x, y)))›*) have "… ≤ (∑⇩∞x∈A. ∑⇩∞y∈B x. norm (f (x,y)))" apply (rule infsum_mono_neutral (*‹⟦?f summable_on ?A; ?g summable_on ?B; ⋀x. x ∈ ?A ∩ ?B ⟹ ?f x ≤ ?g x; ⋀x. x ∈ ?A - ?B ⟹ ?f x ≤ 0; ⋀x. x ∈ ?B - ?A ⟹ 0 ≤ ?g x⟧ ⟹ infsum ?f ?A ≤ infsum ?g ?B›*)) (*goals: 1. ‹(λx. ∑⇩∞y∈B x. norm (f (x, y))) summable_on fst ` F› 2. ‹(λx. ∑⇩∞y∈B x. norm (f (x, y))) summable_on A› 3. ‹⋀x. x ∈ fst ` F ∩ A ⟹ (∑⇩∞y∈B x. norm (f (x, y))) ≤ (∑⇩∞y∈B x. norm (f (x, y)))› 4. ‹⋀x. x ∈ fst ` F - A ⟹ (∑⇩∞y∈B x. norm (f (x, y))) ≤ 0› 5. ‹⋀x. x ∈ A - fst ` F ⟹ 0 ≤ (∑⇩∞y∈B x. norm (f (x, y)))› discuss goal 1*) apply ((use asm that(1) in ‹auto simp add: infsum_nonneg›)[1]) (*discuss goal 2*) apply ((use asm that(1) in ‹auto simp add: infsum_nonneg›)[1]) (*discuss goal 3*) apply ((use asm that(1) in ‹auto simp add: infsum_nonneg›)[1]) (*discuss goal 4*) apply ((use asm that(1) in ‹auto simp add: infsum_nonneg›)[1]) (*discuss goal 5*) apply ((use asm that(1) in ‹auto simp add: infsum_nonneg›)[1]) (*proven 5 subgoals*) . finally (*calculation: ‹(∑xy∈F. norm (f xy)) ≤ (∑⇩∞x∈A. ∑⇩∞y∈B x. norm (f (x, y)))›*) show "?thesis" (*goal: ‹(∑xy∈F. norm (f xy)) ≤ (∑⇩∞x∈A. ∑⇩∞y∈B x. norm (f (x, y)))›*) . qed then show "f abs_summable_on Sigma A B" apply (intro nonneg_bdd_above_summable_on (*‹⟦⋀x. x ∈ ?A ⟹ 0 ≤ ?f x; bdd_above (sum ?f ` {F. F ⊆ ?A ∧ finite F})⟧ ⟹ ?f summable_on ?A›*)) (*goals: 1. ‹⋀x. ⟦⋀F. ⟦F ⊆ Sigma A B; finite F⟧ ⟹ (∑xy∈F. norm (f xy)) ≤ (∑⇩∞x∈A. ∑⇩∞y∈B x. norm (f (x, y))); x ∈ Sigma A B⟧ ⟹ 0 ≤ norm (f x)› 2. ‹(⋀F. ⟦F ⊆ Sigma A B; finite F⟧ ⟹ (∑xy∈F. norm (f xy)) ≤ (∑⇩∞x∈A. ∑⇩∞y∈B x. norm (f (x, y)))) ⟹ bdd_above (sum (λx. norm (f x)) ` {F. F ⊆ Sigma A B ∧ finite F})› discuss goal 1*) apply ((auto simp: bdd_above_def (*‹bdd_above ?A = (∃M. ∀x∈?A. x ≤ M)›*))[1]) (*discuss goal 2*) apply ((auto simp: bdd_above_def (*‹bdd_above ?A = (∃M. ∀x∈?A. x ≤ M)›*))[1]) (*proven 2 subgoals*) . qed lemma abs_summable_on_comparison_test: assumes "g abs_summable_on A" assumes "⋀x. x ∈ A ⟹ norm (f x) ≤ norm (g x)" shows "f abs_summable_on A" proof (rule nonneg_bdd_above_summable_on (*‹⟦⋀x. x ∈ ?A ⟹ 0 ≤ ?f x; bdd_above (sum ?f ` {F. F ⊆ ?A ∧ finite F})⟧ ⟹ ?f summable_on ?A›*)) (*goals: 1. ‹⋀x. x ∈ A ⟹ 0 ≤ norm (f x)› 2. ‹bdd_above (sum (λx. norm (f x)) ` {F. F ⊆ A ∧ finite F})›*) show "bdd_above (sum (λx. norm (f x)) ` {F. F ⊆ A ∧ finite F})" proof (rule bdd_aboveI2 (*‹(⋀x::?'b. x ∈ (?A::?'b set) ⟹ (?f::?'b ⇒ ?'a) x ≤ (?M::?'a)) ⟹ bdd_above (?f ` ?A)›*)) (*goal: ‹⋀x. x ∈ {F. F ⊆ A ∧ finite F} ⟹ (∑x∈x. norm (f x)) ≤ ?M›*) fix F assume F: "F ∈ {F. F ⊆ A ∧ finite F}" (*‹(F::'a set) ∈ {F::'a set. F ⊆ (A::'a set) ∧ finite F}›*) have "sum (λx. norm (f x)) F ≤ sum (λx. norm (g x)) F" using assms (*‹g abs_summable_on A› ‹?x ∈ A ⟹ norm (f ?x) ≤ norm (g ?x)›*) F (*‹F ∈ {F. F ⊆ A ∧ finite F}›*) apply (intro sum_mono (*‹(⋀i. i ∈ ?K ⟹ ?f i ≤ ?g i) ⟹ sum ?f ?K ≤ sum ?g ?K›*)) (*goal: ‹(∑x∈F. norm (f x)) ≤ (∑x∈F. norm (g x))›*) by auto also (*calculation: ‹(∑x∈F. norm (f x)) ≤ (∑x∈F. norm (g x))›*) have "… = infsum (λx. norm (g x)) F" using F (*‹F ∈ {F. F ⊆ A ∧ finite F}›*) by simp also (*calculation: ‹(∑x∈F. norm (f x)) ≤ (∑⇩∞x∈F. norm (g x))›*) have "… ≤ infsum (λx. norm (g x)) A" by (smt (verit) F (*‹F ∈ {F. F ⊆ A ∧ finite F}›*) assms( (*‹g abs_summable_on A›*) 1) infsum_mono2 (*‹⟦?f summable_on ?A; ?f summable_on ?B; ?A ⊆ ?B; ⋀x. x ∈ ?B - ?A ⟹ 0 ≤ ?f x⟧ ⟹ infsum ?f ?A ≤ infsum ?f ?B›*) mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*) norm_ge_zero (*‹0 ≤ norm ?x›*) summable_on_subset_banach (*‹⟦?f summable_on ?A; ?B ⊆ ?A⟧ ⟹ ?f summable_on ?B›*)) finally (*calculation: ‹(∑x∈F. norm (f x)) ≤ (∑⇩∞x∈A. norm (g x))›*) show "(∑x∈F. norm (f x)) ≤ (∑⇩∞x∈A. norm (g x))" . qed qed (auto) (*solved the remaining goal: ‹⋀x. x ∈ A ⟹ 0 ≤ norm (f x)›*) lemma abs_summable_iff_bdd_above: fixes f :: ‹'a ⇒ 'b::real_normed_vector› shows ‹f abs_summable_on A ⟷ bdd_above (sum (λx. norm (f x)) ` {F. F⊆A ∧ finite F})› proof (rule iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*)) (*goals: 1. ‹(f::'a ⇒ 'b) abs_summable_on (A::'a set) ⟹ bdd_above (sum (λx::'a. norm (f x)) ` {F::'a set. F ⊆ A ∧ finite F})› 2. ‹bdd_above (sum (λx::'a. norm ((f::'a ⇒ 'b) x)) ` {F::'a set. F ⊆ (A::'a set) ∧ finite F}) ⟹ f abs_summable_on A›*) assume "f abs_summable_on A" (*‹(f::'a ⇒ 'b) abs_summable_on (A::'a set)›*) show "bdd_above (sum (λx. norm (f x)) ` {F. F ⊆ A ∧ finite F})" proof (rule bdd_aboveI2 (*‹(⋀x. x ∈ ?A ⟹ ?f x ≤ ?M) ⟹ bdd_above (?f ` ?A)›*)) (*goal: ‹⋀x. x ∈ {F. F ⊆ A ∧ finite F} ⟹ (∑x∈x. norm (f x)) ≤ ?M›*) fix F assume F: "F ∈ {F. F ⊆ A ∧ finite F}" (*‹(F::'a set) ∈ {F::'a set. F ⊆ (A::'a set) ∧ finite F}›*) show "(∑x∈F. norm (f x)) ≤ (∑⇩∞x∈A. norm (f x))" apply (rule finite_sum_le_infsum (*‹⟦?f summable_on ?A; finite ?B; ?B ⊆ ?A; ⋀x. x ∈ ?A - ?B ⟹ 0 ≤ ?f x⟧ ⟹ sum ?f ?B ≤ infsum ?f ?A›*)) (*goals: 1. ‹f abs_summable_on A› 2. ‹finite F› 3. ‹F ⊆ A› 4. ‹⋀x. x ∈ A - F ⟹ 0 ≤ norm (f x)› discuss goal 1*) apply ((use ‹f abs_summable_on A› F in auto)[1]) (*discuss goal 2*) apply ((use ‹f abs_summable_on A› F in auto)[1]) (*discuss goal 3*) apply ((use ‹f abs_summable_on A› F in auto)[1]) (*discuss goal 4*) apply ((use ‹f abs_summable_on A› F in auto)[1]) (*proven 4 subgoals*) . qed next (*goal: ‹bdd_above (sum (λx. norm (f x)) ` {F. F ⊆ A ∧ finite F}) ⟹ f abs_summable_on A›*) assume "bdd_above (sum (λx. norm (f x)) ` {F. F⊆A ∧ finite F})" (*‹bdd_above (sum (λx::'a. norm ((f::'a ⇒ 'b) x)) ` {F::'a set. F ⊆ (A::'a set) ∧ finite F})›*) then show "f abs_summable_on A" by (simp add: nonneg_bdd_above_summable_on (*‹⟦⋀x. x ∈ ?A ⟹ 0 ≤ ?f x; bdd_above (sum ?f ` {F. F ⊆ ?A ∧ finite F})⟧ ⟹ ?f summable_on ?A›*)) qed lemma abs_summable_product: fixes x :: "'a ⇒ 'b::{real_normed_div_algebra,banach,second_countable_topology}" assumes x2_sum: "(λi. (x i) * (x i)) abs_summable_on A" and y2_sum: "(λi. (y i) * (y i)) abs_summable_on A" shows "(λi. x i * y i) abs_summable_on A" proof (rule nonneg_bdd_above_summable_on (*‹⟦⋀x. x ∈ ?A ⟹ 0 ≤ ?f x; bdd_above (sum ?f ` {F. F ⊆ ?A ∧ finite F})⟧ ⟹ ?f summable_on ?A›*)) (*goals: 1. ‹⋀xa. xa ∈ A ⟹ 0 ≤ norm (x xa * y xa)› 2. ‹bdd_above (sum (λxa. norm (x xa * y xa)) ` {F. F ⊆ A ∧ finite F})›*) show "bdd_above (sum (λxa. norm (x xa * y xa)) ` {F. F ⊆ A ∧ finite F})" proof (rule bdd_aboveI2 (*‹(⋀x. x ∈ ?A ⟹ ?f x ≤ ?M) ⟹ bdd_above (?f ` ?A)›*)) (*goal: ‹⋀xa::'a set. xa ∈ {F::'a set. F ⊆ (A::'a set) ∧ finite F} ⟹ (∑xa::'a∈xa. norm ((x::'a ⇒ 'b) xa * (y::'a ⇒ 'b) xa)) ≤ (?M::real)›*) fix F assume F: "F ∈ {F. F ⊆ A ∧ finite F}" (*‹(F::'a set) ∈ {F::'a set. F ⊆ (A::'a set) ∧ finite F}›*) then have r1: "finite F" and b4: "F ⊆ A" apply - (*goals: 1. ‹F ∈ {F. F ⊆ A ∧ finite F} ⟹ finite F› 2. ‹F ∈ {F. F ⊆ A ∧ finite F} ⟹ F ⊆ A› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have a1: "(∑⇩∞i∈F. norm (x i * x i)) ≤ (∑⇩∞i∈A. norm (x i * x i))" by (metis (no_types, lifting) b4 (*‹F ⊆ A›*) infsum_mono2 (*‹⟦?f summable_on ?A; ?f summable_on ?B; ?A ⊆ ?B; ⋀x. x ∈ ?B - ?A ⟹ 0 ≤ ?f x⟧ ⟹ infsum ?f ?A ≤ infsum ?f ?B›*) norm_ge_zero (*‹0 ≤ norm ?x›*) summable_on_subset_banach (*‹⟦?f summable_on ?A; ?B ⊆ ?A⟧ ⟹ ?f summable_on ?B›*) x2_sum (*‹(λxa. x xa * x xa) abs_summable_on A›*)) have "norm (x i * y i) ≤ norm (x i * x i) + norm (y i * y i)" for i unfolding norm_mult (*goal: ‹norm (x i) * norm (y i) ≤ norm (x i) * norm (x i) + norm (y i) * norm (y i)›*) by (smt (verit, best) abs_norm_cancel (*‹¦norm ?a¦ = norm ?a›*) mult_mono (*‹⟦?a ≤ ?b; ?c ≤ ?d; 0 ≤ ?b; 0 ≤ ?c⟧ ⟹ ?a * ?c ≤ ?b * ?d›*) not_sum_squares_lt_zero (*‹¬ ?x * ?x + ?y * ?y < 0›*)) hence "(∑i∈F. norm (x i * y i)) ≤ (∑i∈F. norm (x i * x i) + norm (y i * y i))" by (simp add: sum_mono (*‹(⋀i. i ∈ ?K ⟹ ?f i ≤ ?g i) ⟹ sum ?f ?K ≤ sum ?g ?K›*)) also (*calculation: ‹(∑i::'a∈(F::'a set). norm ((x::'a ⇒ 'b) i * (y::'a ⇒ 'b) i)) ≤ (∑i::'a∈F. norm (x i * x i) + norm (y i * y i))›*) have "… = (∑i∈F. norm (x i * x i)) + (∑i∈F. norm (y i * y i))" by (simp add: sum.distrib (*‹(∑x∈?A. ?g x + ?h x) = sum ?g ?A + sum ?h ?A›*)) also (*calculation: ‹(∑i∈F. norm (x i * y i)) ≤ (∑i∈F. norm (x i * x i)) + (∑i∈F. norm (y i * y i))›*) have "… = (∑⇩∞i∈F. norm (x i * x i)) + (∑⇩∞i∈F. norm (y i * y i))" by (simp add: ‹finite F›) also (*calculation: ‹(∑i::'a∈(F::'a set). norm ((x::'a ⇒ 'b) i * (y::'a ⇒ 'b) i)) ≤ (∑⇩∞i::'a∈F. norm (x i * x i)) + (∑⇩∞i::'a∈F. norm (y i * y i))›*) have "… ≤ (∑⇩∞i∈A. norm (x i * x i)) + (∑⇩∞i∈A. norm (y i * y i))" using F (*‹F ∈ {F. F ⊆ A ∧ finite F}›*) assms (*‹(λxa. x xa * x xa) abs_summable_on A› ‹(λx. y x * y x) abs_summable_on A›*) apply (intro add_mono (*‹⟦?a ≤ ?b; ?c ≤ ?d⟧ ⟹ ?a + ?c ≤ ?b + ?d›*) infsum_mono2 (*‹⟦?f summable_on ?A; ?f summable_on ?B; ?A ⊆ ?B; ⋀x. x ∈ ?B - ?A ⟹ 0 ≤ ?f x⟧ ⟹ infsum ?f ?A ≤ infsum ?f ?B›*)) (*goals: 1. ‹⟦F ∈ {F. F ⊆ A ∧ finite F}; (λxa. x xa * x xa) abs_summable_on A; (λx. y x * y x) abs_summable_on A⟧ ⟹ (λi. x i * x i) abs_summable_on F› 2. ‹⟦F ∈ {F. F ⊆ A ∧ finite F}; (λxa. x xa * x xa) abs_summable_on A; (λx. y x * y x) abs_summable_on A⟧ ⟹ (λi. x i * x i) abs_summable_on A› 3. ‹⟦F ∈ {F. F ⊆ A ∧ finite F}; (λxa. x xa * x xa) abs_summable_on A; (λx. y x * y x) abs_summable_on A⟧ ⟹ F ⊆ A› 4. ‹⋀xa. ⟦F ∈ {F. F ⊆ A ∧ finite F}; (λxa. x xa * x xa) abs_summable_on A; (λx. y x * y x) abs_summable_on A; xa ∈ A - F⟧ ⟹ 0 ≤ norm (x xa * x xa)› 5. ‹⟦F ∈ {F. F ⊆ A ∧ finite F}; (λxa. x xa * x xa) abs_summable_on A; (λx. y x * y x) abs_summable_on A⟧ ⟹ (λi. y i * y i) abs_summable_on F› 6. ‹⟦F ∈ {F. F ⊆ A ∧ finite F}; (λxa. x xa * x xa) abs_summable_on A; (λx. y x * y x) abs_summable_on A⟧ ⟹ (λi. y i * y i) abs_summable_on A› 7. ‹⟦F ∈ {F. F ⊆ A ∧ finite F}; (λxa. x xa * x xa) abs_summable_on A; (λx. y x * y x) abs_summable_on A⟧ ⟹ F ⊆ A› 8. ‹⋀xa. ⟦F ∈ {F. F ⊆ A ∧ finite F}; (λxa. x xa * x xa) abs_summable_on A; (λx. y x * y x) abs_summable_on A; xa ∈ A - F⟧ ⟹ 0 ≤ norm (y xa * y xa)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*discuss goal 7*) apply ((auto)[1]) (*discuss goal 8*) apply ((auto)[1]) (*proven 8 subgoals*) . finally (*calculation: ‹(∑i∈F. norm (x i * y i)) ≤ (∑⇩∞i∈A. norm (x i * x i)) + (∑⇩∞i∈A. norm (y i * y i))›*) show "(∑xa∈F. norm (x xa * y xa)) ≤ (∑⇩∞i∈A. norm (x i * x i)) + (∑⇩∞i∈A. norm (y i * y i))" by simp qed qed (auto) (*solved the remaining goal: ‹⋀xa. xa ∈ A ⟹ 0 ≤ norm (x xa * y xa)›*) subsection ‹Extended reals and nats› lemma summable_on_ennreal[simp]: ‹(f::_ ⇒ ennreal) summable_on S› and summable_on_enat[simp]: ‹(f::_ ⇒ enat) summable_on S› (*goals: 1. ‹(λx::'a::type. ennreal_of_enat ((f::'a::type ⇒ enat) x)) summable_on (S::'a::type set)› 2. ‹(f::'a::type ⇒ enat) summable_on (S::'a::type set)› discuss goal 1*) apply (simp add: nonneg_summable_on_complete (*‹(⋀x. x ∈ ?A ⟹ 0 ≤ ?f x) ⟹ ?f summable_on ?A›*)) (*discuss goal 2*) apply (simp add: nonneg_summable_on_complete (*‹(⋀x. x ∈ ?A ⟹ 0 ≤ ?f x) ⟹ ?f summable_on ?A›*)) (*proven 2 subgoals*) . lemma has_sum_superconst_infinite_ennreal: fixes f :: ‹'a ⇒ ennreal› assumes geqb: ‹⋀x. x ∈ S ⟹ f x ≥ b› assumes b: ‹b > 0› assumes ‹infinite S› shows "(f has_sum ∞) S" proof (-) (*goal: ‹(f has_sum ∞) S›*) have "(sum f ⤏ ∞) (finite_subsets_at_top S)" proof (rule order_tendstoI (*‹⟦⋀a. a < ?y ⟹ ∀⇩F x in ?F. a < ?f x; ⋀a. ?y < a ⟹ ∀⇩F x in ?F. ?f x < a⟧ ⟹ (?f ⤏ ?y) ?F›*)) (*goals: 1. ‹⋀a. a < ∞ ⟹ ∀⇩F x in finite_subsets_at_top S. a < sum f x› 2. ‹⋀a. ∞ < a ⟹ ∀⇩F x in finite_subsets_at_top S. sum f x < a›*) fix y :: ennreal assume "y < ∞" (*‹(y::ennreal) < ∞›*) then have "y / b < ∞" "y < top" using b (*‹(0::ennreal) < (b::ennreal)›*) ennreal_divide_eq_top_iff (*‹(?a / ?b = top) = (?a ≠ 0 ∧ ?b = 0 ∨ ?a = top ∧ ?b ≠ top)›*) top.not_eq_extremum (*‹((?a::?'a) ≠ top) = (?a < top)›*) apply - (*goals: 1. ‹⟦y < ∞; 0 < b; ⋀a b. (a / b = top) = (a ≠ 0 ∧ b = 0 ∨ a = top ∧ b ≠ top); ⋀a. (a ≠ top) = (a < top)⟧ ⟹ y / b < ∞› 2. ‹⟦y < ∞; 0 < b; ⋀a b. (a / b = top) = (a ≠ 0 ∧ b = 0 ∨ a = top ∧ b ≠ top); ⋀a. (a ≠ top) = (a < top)⟧ ⟹ y < top› discuss goal 1*) apply force (*discuss goal 2*) apply force (*proven 2 subgoals*) . then obtain F where "finite F" and "F ⊆ S" and cardF: "card F > y / b" (*goal: ‹(⋀F::'a set. ⟦finite F; F ⊆ (S::'a set); (y::ennreal) / (b::ennreal) < of_nat (card F)⟧ ⟹ thesis::bool) ⟹ thesis›*) using ‹infinite S› (*‹infinite S›*) by (metis ennreal_Ex_less_of_nat (*‹?x < top ⟹ ∃n. ?x < of_nat n›*) infinite_arbitrarily_large (*‹infinite ?A ⟹ ∃B. finite B ∧ card B = ?n ∧ B ⊆ ?A›*) infinity_ennreal_def (*‹∞ = top›*)) moreover have "sum f Y > y" if "finite Y" and "F ⊆ Y" and "Y ⊆ S" for Y proof (-) (*goal: ‹y < sum f Y›*) have "y < b * card F" by (metis b (*‹0 < b›*) ‹y < top› cardF (*‹y / b < of_nat (card F)›*) divide_less_ennreal (*‹⟦?b ≠ 0; ?b < top⟧ ⟹ (?a / ?b < ?c) = (?a < ?c * ?b)›*) ennreal_mult_eq_top_iff (*‹(?a * ?b = top) = (?a = top ∧ ?b ≠ 0 ∨ ?b = top ∧ ?a ≠ 0)›*) gr_implies_not_zero (*‹?m < ?n ⟹ ?n ≠ 0›*) mult.commute (*‹?a * ?b = ?b * ?a›*) top.not_eq_extremum (*‹(?a ≠ top) = (?a < top)›*)) also (*calculation: ‹y < b * of_nat (card F)›*) have "… ≤ b * card Y" by (meson b (*‹0 < b›*) card_mono (*‹⟦finite ?B; ?A ⊆ ?B⟧ ⟹ card ?A ≤ card ?B›*) less_imp_le (*‹?x < ?y ⟹ ?x ≤ ?y›*) mult_left_mono (*‹⟦?a ≤ ?b; 0 ≤ ?c⟧ ⟹ ?c * ?a ≤ ?c * ?b›*) of_nat_le_iff (*‹(of_nat ?m ≤ of_nat ?n) = (?m ≤ ?n)›*) that (*‹finite Y› ‹F ⊆ Y› ‹Y ⊆ S›*)) also (*calculation: ‹y < b * of_nat (card Y)›*) have "… = sum (λ_. b) Y" by (simp add: mult.commute (*‹(?a::?'a) * (?b::?'a) = ?b * ?a›*)) also (*calculation: ‹y < (∑_∈Y. b)›*) have "… ≤ sum f Y" using geqb (*‹(?x::'a) ∈ (S::'a set) ⟹ (b::ennreal) ≤ (f::'a ⇒ ennreal) ?x›*) by (meson subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*) sum_mono (*‹(⋀i. i ∈ ?K ⟹ ?f i ≤ ?g i) ⟹ sum ?f ?K ≤ sum ?g ?K›*) that( (*‹Y ⊆ S›*) 3)) finally (*calculation: ‹y < sum f Y›*) show "?thesis" (*goal: ‹y < sum f Y›*) . qed ultimately show "∀⇩F x in finite_subsets_at_top S. y < sum f x" unfolding eventually_finite_subsets_at_top (*goal: ‹∃X::'a set. finite X ∧ X ⊆ (S::'a set) ∧ (∀Y::'a set. finite Y ∧ X ⊆ Y ∧ Y ⊆ S ⟶ (y::ennreal) < sum (f::'a ⇒ ennreal) Y)›*) by auto qed (auto) (*solved the remaining goal: ‹⋀a. ∞ < a ⟹ ∀⇩F x in finite_subsets_at_top S. sum f x < a›*) then show "?thesis" (*goal: ‹((f::'a ⇒ ennreal) has_sum ∞) (S::'a set)›*) by (simp add: has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*)) qed lemma infsum_superconst_infinite_ennreal: fixes f :: ‹'a ⇒ ennreal› assumes ‹⋀x. x ∈ S ⟹ f x ≥ b› assumes ‹b > 0› assumes ‹infinite S› shows "infsum f S = ∞" using assms (*‹?x ∈ S ⟹ b ≤ f ?x› ‹0 < b› ‹infinite S›*) infsumI (*‹(?f has_sum ?x) ?A ⟹ infsum ?f ?A = ?x›*) has_sum_superconst_infinite_ennreal (*‹⟦⋀x. x ∈ ?S ⟹ ?b ≤ ?f x; 0 < ?b; infinite ?S⟧ ⟹ (?f has_sum ∞) ?S›*) by blast lemma infsum_superconst_infinite_ereal: fixes f :: ‹'a ⇒ ereal› assumes geqb: ‹⋀x. x ∈ S ⟹ f x ≥ b› assumes b: ‹b > 0› assumes ‹infinite S› shows "infsum f S = ∞" proof (-) (*goal: ‹infsum f S = ∞›*) obtain b' where b': "e2ennreal b' = b" and "b' > 0" (*goal: ‹(⋀b'. ⟦e2ennreal b' = e2ennreal b; 0 < b'⟧ ⟹ thesis) ⟹ thesis›*) using b (*‹0 < b›*) by blast have "0 < e2ennreal b" using b' (*‹e2ennreal b' = e2ennreal b›*) b (*‹(0::ereal) < (b::ereal)›*) by (metis dual_order.refl (*‹(?a::?'a) ≤ ?a›*) enn2ereal_e2ennreal (*‹(0::ereal) ≤ (?x::ereal) ⟹ enn2ereal (e2ennreal ?x) = ?x›*) gr_zeroI (*‹((?n::?'a) = (0::?'a) ⟹ False) ⟹ (0::?'a) < ?n›*) order_less_le (*‹((?x::?'a) < (?y::?'a)) = (?x ≤ ?y ∧ ?x ≠ ?y)›*) zero_ennreal.abs_eq (*‹(0::ennreal) = e2ennreal (0::ereal)›*)) hence "*": "infsum (e2ennreal ∘ f) S = ∞" using assms (*‹?x ∈ S ⟹ b ≤ f ?x› ‹0 < b› ‹infinite S›*) b' (*‹e2ennreal b' = e2ennreal b›*) apply (intro infsum_superconst_infinite_ennreal[where b=b'] (*‹⟦⋀x. x ∈ ?S ⟹ e2ennreal b' ≤ ?f x; 0 < e2ennreal b'; infinite ?S⟧ ⟹ infsum ?f ?S = ∞›*)) (*goals: 1. ‹⋀x. ⟦0 < e2ennreal b; ⋀x. x ∈ S ⟹ b ≤ f x; 0 < b; infinite S; e2ennreal b' = e2ennreal b; x ∈ S⟧ ⟹ e2ennreal b' ≤ (e2ennreal ∘ f) x› 2. ‹⟦0 < e2ennreal b; ⋀x. x ∈ S ⟹ b ≤ f x; 0 < b; infinite S; e2ennreal b' = e2ennreal b⟧ ⟹ 0 < e2ennreal b'› 3. ‹⟦0 < e2ennreal b; ⋀x. x ∈ S ⟹ b ≤ f x; 0 < b; infinite S; e2ennreal b' = e2ennreal b⟧ ⟹ infinite S› discuss goal 1*) apply ((auto intro!: e2ennreal_mono (*‹(?x::ereal) ≤ (?y::ereal) ⟹ e2ennreal ?x ≤ e2ennreal ?y›*))[1]) (*discuss goal 2*) apply ((auto intro!: e2ennreal_mono (*‹?x ≤ ?y ⟹ e2ennreal ?x ≤ e2ennreal ?y›*))[1]) (*discuss goal 3*) apply ((auto intro!: e2ennreal_mono (*‹?x ≤ ?y ⟹ e2ennreal ?x ≤ e2ennreal ?y›*))[1]) (*proven 3 subgoals*) . have "infsum f S = infsum (enn2ereal ∘ (e2ennreal ∘ f)) S" using geqb (*‹(?x::'a) ∈ (S::'a set) ⟹ (b::ereal) ≤ (f::'a ⇒ ereal) ?x›*) b (*‹0 < b›*) apply (intro infsum_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ infsum ?f ?A = infsum ?g ?A›*)) (*goal: ‹infsum f S = infsum (enn2ereal ∘ (e2ennreal ∘ f)) S›*) by (fastforce simp: enn2ereal_e2ennreal (*‹0 ≤ ?x ⟹ enn2ereal (e2ennreal ?x) = ?x›*)) also (*calculation: ‹infsum f S = infsum (enn2ereal ∘ (e2ennreal ∘ f)) S›*) have "… = enn2ereal ∞" using "*" (*‹infsum (e2ennreal ∘ f) S = ∞›*) by (simp add: infsum_comm_additive_general (*‹⟦⋀F. ⟦finite F; F ⊆ ?S⟧ ⟹ sum (?f ∘ ?g) F = ?f (sum ?g F); isCont ?f (infsum ?g ?S); ?g summable_on ?S⟧ ⟹ infsum (?f ∘ ?g) ?S = ?f (infsum ?g ?S)›*) continuous_at_enn2ereal (*‹continuous (at ?x within ?A) enn2ereal›*) nonneg_summable_on_complete (*‹(⋀x. x ∈ ?A ⟹ 0 ≤ ?f x) ⟹ ?f summable_on ?A›*)) also (*calculation: ‹infsum f S = enn2ereal ∞›*) have "… = ∞" by simp finally (*calculation: ‹infsum f S = ∞›*) show "?thesis" (*goal: ‹infsum f S = ∞›*) . qed lemma has_sum_superconst_infinite_ereal: fixes f :: ‹'a ⇒ ereal› assumes ‹⋀x. x ∈ S ⟹ f x ≥ b› assumes ‹b > 0› assumes ‹infinite S› shows "(f has_sum ∞) S" by (metis Infty_neq_0( (*‹∞ ≠ 0›*) 1) assms (*‹?x ∈ S ⟹ b ≤ f ?x› ‹0 < b› ‹infinite S›*) infsum_def (*‹infsum ?f ?A = (if ?f summable_on ?A then Lim (finite_subsets_at_top ?A) (sum ?f) else 0)›*) has_sum_infsum (*‹?f summable_on ?S ⟹ (?f has_sum infsum ?f ?S) ?S›*) infsum_superconst_infinite_ereal (*‹⟦⋀x. x ∈ ?S ⟹ ?b ≤ ?f x; 0 < ?b; infinite ?S⟧ ⟹ infsum ?f ?S = ∞›*)) lemma infsum_superconst_infinite_enat: fixes f :: ‹'a ⇒ enat› assumes geqb: ‹⋀x. x ∈ S ⟹ f x ≥ b› assumes b: ‹b > 0› assumes ‹infinite S› shows "infsum f S = ∞" proof (-) (*goal: ‹infsum f S = ∞›*) have "ennreal_of_enat (infsum f S) = infsum (ennreal_of_enat ∘ f) S" by (simp flip: infsum_comm_additive_general (*‹⟦⋀F. ⟦finite F; F ⊆ ?S⟧ ⟹ sum (?f ∘ ?g) F = ?f (sum ?g F); isCont ?f (infsum ?g ?S); ?g summable_on ?S⟧ ⟹ infsum (?f ∘ ?g) ?S = ?f (infsum ?g ?S)›*)) also (*calculation: ‹ennreal_of_enat (infsum f S) = infsum (ennreal_of_enat ∘ f) S›*) have "… = ∞" by (metis assms( (*‹infinite S›*) 3) b (*‹0 < b›*) comp_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*) ennreal_of_enat_0 (*‹ennreal_of_enat 0 = 0›*) ennreal_of_enat_le_iff (*‹(ennreal_of_enat ?m ≤ ennreal_of_enat ?n) = (?m ≤ ?n)›*) geqb (*‹?x ∈ S ⟹ b ≤ f ?x›*) infsum_superconst_infinite_ennreal (*‹⟦⋀x. x ∈ ?S ⟹ ?b ≤ ?f x; 0 < ?b; infinite ?S⟧ ⟹ infsum ?f ?S = ∞›*) leD (*‹?y ≤ ?x ⟹ ¬ ?x < ?y›*) leI (*‹¬ ?x < ?y ⟹ ?y ≤ ?x›*)) also (*calculation: ‹ennreal_of_enat (infsum f S) = ∞›*) have "… = ennreal_of_enat ∞" by simp finally (*calculation: ‹ennreal_of_enat (infsum f S) = ennreal_of_enat ∞›*) show "?thesis" (*goal: ‹infsum f S = ∞›*) by (rule ennreal_of_enat_inj[THEN iffD1] (*‹ennreal_of_enat ?i1 = ennreal_of_enat ?j1 ⟹ ?i1 = ?j1›*)) qed lemma has_sum_superconst_infinite_enat: fixes f :: ‹'a ⇒ enat› assumes ‹⋀x. x ∈ S ⟹ f x ≥ b› assumes ‹b > 0› assumes ‹infinite S› shows "(f has_sum ∞) S" by (metis assms (*‹?x ∈ S ⟹ b ≤ f ?x› ‹0 < b› ‹infinite S›*) i0_lb (*‹0 ≤ ?n›*) has_sum_infsum (*‹?f summable_on ?S ⟹ (?f has_sum infsum ?f ?S) ?S›*) infsum_superconst_infinite_enat (*‹⟦⋀x. x ∈ ?S ⟹ ?b ≤ ?f x; 0 < ?b; infinite ?S⟧ ⟹ infsum ?f ?S = ∞›*) nonneg_summable_on_complete (*‹(⋀x. x ∈ ?A ⟹ 0 ≤ ?f x) ⟹ ?f summable_on ?A›*)) text ‹This lemma helps to relate a real-valued infsum to a supremum over extended nonnegative reals.› lemma infsum_nonneg_is_SUPREMUM_ennreal: fixes f :: "'a ⇒ real" assumes summable: "f summable_on A" and fnn: "⋀x. x∈A ⟹ f x ≥ 0" shows "ennreal (infsum f A) = (SUP F∈{F. finite F ∧ F ⊆ A}. (ennreal (sum f F)))" proof (-) (*goal: ‹ennreal (infsum f A) = (SUP F∈{F. finite F ∧ F ⊆ A}. ennreal (sum f F))›*) have "§": "⋀F. ⟦finite F; F ⊆ A⟧ ⟹ sum (ennreal ∘ f) F = ennreal (sum f F)" by (metis (mono_tags, lifting) comp_def (*‹(?f::?'b ⇒ ?'c) ∘ (?g::?'a ⇒ ?'b) = (λx::?'a. ?f (?g x))›*) fnn (*‹(?x::'a) ∈ (A::'a set) ⟹ (0::real) ≤ (f::'a ⇒ real) ?x›*) subsetD (*‹⟦(?A::?'a set) ⊆ (?B::?'a set); (?c::?'a) ∈ ?A⟧ ⟹ ?c ∈ ?B›*) sum.cong (*‹⟦(?A::?'b set) = (?B::?'b set); ⋀x::?'b. x ∈ ?B ⟹ (?g::?'b ⇒ ?'a) x = (?h::?'b ⇒ ?'a) x⟧ ⟹ sum ?g ?A = sum ?h ?B›*) sum_ennreal (*‹(⋀i::?'a. i ∈ (?I::?'a set) ⟹ (0::real) ≤ (?f::?'a ⇒ real) i) ⟹ (∑i::?'a∈?I. ennreal (?f i)) = ennreal (sum ?f ?I)›*)) then have "ennreal (infsum f A) = infsum (ennreal ∘ f) A" by (simp add: infsum_comm_additive_general (*‹⟦⋀F. ⟦finite F; F ⊆ ?S⟧ ⟹ sum (?f ∘ ?g) F = ?f (sum ?g F); isCont ?f (infsum ?g ?S); ?g summable_on ?S⟧ ⟹ infsum (?f ∘ ?g) ?S = ?f (infsum ?g ?S)›*) local.summable (*‹f summable_on A›*)) also (*calculation: ‹ennreal (infsum f A) = infsum (ennreal ∘ f) A›*) have "… = (SUP F∈{F. finite F ∧ F ⊆ A}. (ennreal (sum f F)))" by (metis (mono_tags, lifting) § (*‹⟦finite ?F; ?F ⊆ A⟧ ⟹ sum (ennreal ∘ f) ?F = ennreal (sum f ?F)›*) image_cong (*‹⟦?M = ?N; ⋀x. x ∈ ?N ⟹ ?f x = ?g x⟧ ⟹ ?f ` ?M = ?g ` ?N›*) mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*) nonneg_infsum_complete (*‹(⋀x. x ∈ ?A ⟹ 0 ≤ ?f x) ⟹ infsum ?f ?A = Sup (sum ?f ` {F. finite F ∧ F ⊆ ?A})›*) zero_le (*‹0 ≤ ?x›*)) finally (*calculation: ‹ennreal (infsum f A) = (SUP F∈{F. finite F ∧ F ⊆ A}. ennreal (sum f F))›*) show "?thesis" (*goal: ‹ennreal (infsum (f::'a::type ⇒ real) (A::'a::type set)) = (SUP F::'a::type set∈{F::'a::type set. finite F ∧ F ⊆ A}. ennreal (sum f F))›*) . qed text ‹This lemma helps to related a real-valued infsum to a supremum over extended reals.› lemma infsum_nonneg_is_SUPREMUM_ereal: fixes f :: "'a ⇒ real" assumes summable: "f summable_on A" and fnn: "⋀x. x∈A ⟹ f x ≥ 0" shows "ereal (infsum f A) = (SUP F∈{F. finite F ∧ F ⊆ A}. (ereal (sum f F)))" proof (-) (*goal: ‹ereal (infsum (f::'a ⇒ real) (A::'a set)) = (SUP F::'a set∈{F::'a set. finite F ∧ F ⊆ A}. ereal (sum f F))›*) have "⋀F. ⟦finite F; F ⊆ A⟧ ⟹ sum (ereal ∘ f) F = ereal (sum f F)" by auto then have "ereal (infsum f A) = infsum (ereal ∘ f) A" by (simp add: infsum_comm_additive_general (*‹⟦⋀F. ⟦finite F; F ⊆ ?S⟧ ⟹ sum (?f ∘ ?g) F = ?f (sum ?g F); isCont ?f (infsum ?g ?S); ?g summable_on ?S⟧ ⟹ infsum (?f ∘ ?g) ?S = ?f (infsum ?g ?S)›*) local.summable (*‹f summable_on A›*)) also (*calculation: ‹ereal (infsum (f::'a ⇒ real) (A::'a set)) = infsum (ereal ∘ f) A›*) have "… = (SUP F∈{F. finite F ∧ F ⊆ A}. (ereal (sum f F)))" apply (subst nonneg_infsum_complete (*‹(⋀x. x ∈ ?A ⟹ 0 ≤ ?f x) ⟹ infsum ?f ?A = Sup (sum ?f ` {F. finite F ∧ F ⊆ ?A})›*)) (*goals: 1. ‹⋀x::'a. x ∈ (A::'a set) ⟹ (0::ereal) ≤ (ereal ∘ (f::'a ⇒ real)) x› 2. ‹Sup (sum (ereal ∘ (f::'a ⇒ real)) ` {F::'a set. finite F ∧ F ⊆ (A::'a set)}) = (SUP F::'a set∈{F::'a set. finite F ∧ F ⊆ A}. ereal (sum f F))› discuss goal 1*) apply (simp add: assms (*‹f summable_on A› ‹?x ∈ A ⟹ 0 ≤ f ?x›*)) (*discuss goal 2*) apply (simp add: assms (*‹f summable_on A› ‹?x ∈ A ⟹ 0 ≤ f ?x›*)) (*proven 2 subgoals*) . finally (*calculation: ‹ereal (infsum (f::'a ⇒ real) (A::'a set)) = (SUP F::'a set∈{F::'a set. finite F ∧ F ⊆ A}. ereal (sum f F))›*) show "?thesis" (*goal: ‹ereal (infsum f A) = (SUP F∈{F. finite F ∧ F ⊆ A}. ereal (sum f F))›*) . qed subsection ‹Real numbers› text ‹Most lemmas in the general property section already apply to real numbers. A few ones that are specific to reals are given here.› lemma infsum_nonneg_is_SUPREMUM_real: fixes f :: "'a ⇒ real" assumes summable: "f summable_on A" and fnn: "⋀x. x∈A ⟹ f x ≥ 0" shows "infsum f A = (SUP F∈{F. finite F ∧ F ⊆ A}. (sum f F))" proof (-) (*goal: ‹infsum f A = Sup (sum f ` {F. finite F ∧ F ⊆ A})›*) have "*": "ereal (infsum f A) = (SUP F∈{F. finite F ∧ F ⊆ A}. (ereal (sum f F)))" using assms (*‹f summable_on A› ‹(?x::'a) ∈ (A::'a set) ⟹ (0::real) ≤ (f::'a ⇒ real) ?x›*) by (rule infsum_nonneg_is_SUPREMUM_ereal (*‹⟦?f summable_on ?A; ⋀x. x ∈ ?A ⟹ 0 ≤ ?f x⟧ ⟹ ereal (infsum ?f ?A) = (SUP F∈{F. finite F ∧ F ⊆ ?A}. ereal (sum ?f F))›*)) also (*calculation: ‹ereal (infsum f A) = (SUP F∈{F. finite F ∧ F ⊆ A}. ereal (sum f F))›*) have "… = ereal (SUP F∈{F. finite F ∧ F ⊆ A}. (sum f F))" by (metis (no_types, lifting) * (*‹ereal (infsum f A) = (SUP F∈{F. finite F ∧ F ⊆ A}. ereal (sum f F))›*) MInfty_neq_ereal( (*‹- ∞ ≠ ereal ?r›*) 2) PInfty_neq_ereal( (*‹∞ ≠ ereal ?r›*) 2) SUP_cong (*‹⟦?A = ?B; ⋀x. x ∈ ?B ⟹ ?C x = ?D x⟧ ⟹ Sup (?C ` ?A) = Sup (?D ` ?B)›*) abs_eq_infinity_cases (*‹⟦¦?x¦ = ∞; ?x = ∞ ⟹ ?thesis; ?x = - ∞ ⟹ ?thesis⟧ ⟹ ?thesis›*) ereal_SUP (*‹¦SUP a∈?A. ereal (?f a)¦ ≠ ∞ ⟹ ereal (Sup (?f ` ?A)) = (SUP a∈?A. ereal (?f a))›*)) finally (*calculation: ‹ereal (infsum f A) = ereal (Sup (sum f ` {F. finite F ∧ F ⊆ A}))›*) show "?thesis" (*goal: ‹infsum f A = Sup (sum f ` {F. finite F ∧ F ⊆ A})›*) by simp qed lemma has_sum_nonneg_SUPREMUM_real: fixes f :: "'a ⇒ real" assumes "f summable_on A" and "⋀x. x∈A ⟹ f x ≥ 0" shows "(f has_sum (SUP F∈{F. finite F ∧ F ⊆ A}. (sum f F))) A" by (metis (mono_tags, lifting) assms (*‹(f::'a ⇒ real) summable_on (A::'a set)› ‹(?x::'a) ∈ (A::'a set) ⟹ (0::real) ≤ (f::'a ⇒ real) ?x›*) has_sum_infsum (*‹(?f::?'a ⇒ ?'b) summable_on (?S::?'a set) ⟹ (?f has_sum infsum ?f ?S) ?S›*) infsum_nonneg_is_SUPREMUM_real (*‹⟦(?f::?'a ⇒ real) summable_on (?A::?'a set); ⋀x::?'a. x ∈ ?A ⟹ (0::real) ≤ ?f x⟧ ⟹ infsum ?f ?A = Sup (sum ?f ` {F::?'a set. finite F ∧ F ⊆ ?A})›*)) lemma summable_countable_real: fixes f :: ‹'a ⇒ real› assumes ‹f summable_on A› shows ‹countable {x∈A. f x ≠ 0}› using abs_summable_countable (*‹(?f::?'a::type ⇒ ?'b::real_normed_vector) abs_summable_on (?A::?'a::type set) ⟹ countable {x::?'a::type ∈ ?A. ?f x ≠ (0::?'b::real_normed_vector)}›*) assms (*‹f summable_on A›*) summable_on_iff_abs_summable_on_real (*‹(?f summable_on ?A) = (?f abs_summable_on ?A)›*) by blast subsection ‹Complex numbers› lemma has_sum_cnj_iff[simp]: fixes f :: ‹'a ⇒ complex› shows ‹((λx. cnj (f x)) has_sum cnj a) M ⟷ (f has_sum a) M› by (simp add: has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*) lim_cnj (*‹((λx. cnj (?f x)) ⤏ cnj ?l) ?F = (?f ⤏ ?l) ?F›*) del: cnj_sum (*‹cnj (sum ?f ?s) = (∑x∈?s. cnj (?f x))›*) add: cnj_sum[symmetric, abs_def, of f] (*‹sum (λx. cnj (f x)) ≡ λs. cnj (sum f s)›*)) lemma summable_on_cnj_iff[simp]: "(λi. cnj (f i)) summable_on A ⟷ f summable_on A" by (metis complex_cnj_cnj (*‹cnj (cnj ?z) = ?z›*) summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*) has_sum_cnj_iff (*‹((λx. cnj (?f x)) has_sum cnj ?a) ?M = (?f has_sum ?a) ?M›*)) lemma infsum_cnj[simp]: ‹infsum (λx. cnj (f x)) M = cnj (infsum f M)› by (metis complex_cnj_zero (*‹cnj (0::complex) = (0::complex)›*) infsumI (*‹((?f::?'a::type ⇒ ?'b::{comm_monoid_add,t2_space}) has_sum (?x::?'b::{comm_monoid_add,t2_space})) (?A::?'a::type set) ⟹ infsum ?f ?A = ?x›*) has_sum_cnj_iff (*‹((λx::?'a::type. cnj ((?f::?'a::type ⇒ complex) x)) has_sum cnj (?a::complex)) (?M::?'a::type set) = (?f has_sum ?a) ?M›*) infsum_def (*‹infsum (?f::?'a::type ⇒ ?'b::{comm_monoid_add,t2_space}) (?A::?'a::type set) = (if ?f summable_on ?A then Lim (finite_subsets_at_top ?A) (sum ?f) else (0::?'b::{comm_monoid_add,t2_space}))›*) summable_on_cnj_iff (*‹((λi::?'a::type. cnj ((?f::?'a::type ⇒ complex) i)) summable_on (?A::?'a::type set)) = (?f summable_on ?A)›*) has_sum_infsum (*‹(?f::?'a::type ⇒ ?'b::{comm_monoid_add,t2_space}) summable_on (?S::?'a::type set) ⟹ (?f has_sum infsum ?f ?S) ?S›*)) lemma has_sum_Re: assumes "(f has_sum a) M" shows "((λx. Re (f x)) has_sum Re a) M" using has_sum_comm_additive[where f = Re] (*‹⟦additive Re; Re ─?x→ Re ?x; (?g has_sum ?x) ?S⟧ ⟹ (Re ∘ ?g has_sum Re ?x) ?S›*) using assms (*‹(f has_sum a) M›*) tendsto_Re (*‹((?g::?'c::type ⇒ complex) ⤏ (?a::complex)) (?F::?'c::type filter) ⟹ ((λx::?'c::type. Re (?g x)) ⤏ Re ?a) ?F›*) by (fastforce simp add: o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*) additive_def (*‹additive ?f ≡ ∀x y. ?f (x + y) = ?f x + ?f y›*)) lemma infsum_Re: assumes "f summable_on M" shows "infsum (λx. Re (f x)) M = Re (infsum f M)" by (simp add: assms (*‹f summable_on M›*) has_sum_Re (*‹(?f has_sum ?a) ?M ⟹ ((λx. Re (?f x)) has_sum Re ?a) ?M›*) infsumI (*‹(?f has_sum ?x) ?A ⟹ infsum ?f ?A = ?x›*)) lemma summable_on_Re: assumes "f summable_on M" shows "(λx. Re (f x)) summable_on M" by (metis assms (*‹f summable_on M›*) has_sum_Re (*‹(?f has_sum ?a) ?M ⟹ ((λx. Re (?f x)) has_sum Re ?a) ?M›*) summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*)) lemma has_sum_Im: assumes "(f has_sum a) M" shows "((λx. Im (f x)) has_sum Im a) M" using has_sum_comm_additive[where f = Im] (*‹⟦additive Im; Im ─?x::complex→ Im ?x; ((?g::?'a::type ⇒ complex) has_sum ?x) (?S::?'a::type set)⟧ ⟹ (Im ∘ ?g has_sum Im ?x) ?S›*) using assms (*‹(f has_sum a) M›*) tendsto_Im (*‹((?g::?'c ⇒ complex) ⤏ (?a::complex)) (?F::?'c filter) ⟹ ((λx::?'c. Im (?g x)) ⤏ Im ?a) ?F›*) by (fastforce simp add: o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*) additive_def (*‹additive ?f ≡ ∀x y. ?f (x + y) = ?f x + ?f y›*)) lemma infsum_Im: assumes "f summable_on M" shows "infsum (λx. Im (f x)) M = Im (infsum f M)" by (simp add: assms (*‹f summable_on M›*) has_sum_Im (*‹(?f has_sum ?a) ?M ⟹ ((λx. Im (?f x)) has_sum Im ?a) ?M›*) infsumI (*‹(?f has_sum ?x) ?A ⟹ infsum ?f ?A = ?x›*)) lemma summable_on_Im: assumes "f summable_on M" shows "(λx. Im (f x)) summable_on M" by (metis assms (*‹f summable_on M›*) has_sum_Im (*‹(?f has_sum ?a) ?M ⟹ ((λx. Im (?f x)) has_sum Im ?a) ?M›*) summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*)) lemma nonneg_infsum_le_0D_complex: fixes f :: "'a ⇒ complex" assumes "infsum f A ≤ 0" and abs_sum: "f summable_on A" and nneg: "⋀x. x ∈ A ⟹ f x ≥ 0" and "x ∈ A" shows "f x = 0" proof (-) (*goal: ‹(f::'a ⇒ complex) (x::'a) = (0::complex)›*) have "Im (f x) = 0" using assms(4) (*‹x ∈ A›*) less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*) nneg (*‹?x ∈ A ⟹ 0 ≤ f ?x›*) by auto moreover have "Re (f x) = 0" using assms (*‹infsum f A ≤ 0› ‹f summable_on A› ‹?x ∈ A ⟹ 0 ≤ f ?x› ‹x ∈ A›*) by (auto simp add: summable_on_Re (*‹(?f::?'a::type ⇒ complex) summable_on (?M::?'a::type set) ⟹ (λx::?'a::type. Re (?f x)) summable_on ?M›*) infsum_Re (*‹(?f::?'a::type ⇒ complex) summable_on (?M::?'a::type set) ⟹ (∑⇩∞x::?'a::type∈?M. Re (?f x)) = Re (infsum ?f ?M)›*) less_eq_complex_def (*‹((?x::complex) ≤ (?y::complex)) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*) intro: nonneg_infsum_le_0D[where A=A] (*‹⟦infsum (?f::'a::type ⇒ ?'b::{ordered_ab_group_add,topological_ab_group_add,linorder_topology}) (A::'a::type set) ≤ (0::?'b::{ordered_ab_group_add,topological_ab_group_add,linorder_topology}); ?f summable_on A; ⋀x::'a::type. x ∈ A ⟹ (0::?'b::{ordered_ab_group_add,topological_ab_group_add,linorder_topology}) ≤ ?f x; (?x::'a::type) ∈ A⟧ ⟹ ?f ?x = (0::?'b::{ordered_ab_group_add,topological_ab_group_add,linorder_topology})›*)) ultimately show "?thesis" (*goal: ‹f x = 0›*) by (simp add: complex_eqI (*‹⟦Re (?x::complex) = Re (?y::complex); Im ?x = Im ?y⟧ ⟹ ?x = ?y›*)) qed lemma nonneg_has_sum_le_0D_complex: fixes f :: "'a ⇒ complex" assumes "(f has_sum a) A" and ‹a ≤ 0› and "⋀x. x ∈ A ⟹ f x ≥ 0" and "x ∈ A" shows "f x = 0" by (metis assms (*‹((f::'a ⇒ complex) has_sum (a::complex)) (A::'a set)› ‹(a::complex) ≤ (0::complex)› ‹(?x::'a) ∈ (A::'a set) ⟹ (0::complex) ≤ (f::'a ⇒ complex) ?x› ‹(x::'a) ∈ (A::'a set)›*) infsumI (*‹((?f::?'a ⇒ ?'b) has_sum (?x::?'b)) (?A::?'a set) ⟹ infsum ?f ?A = ?x›*) nonneg_infsum_le_0D_complex (*‹⟦infsum (?f::?'a ⇒ complex) (?A::?'a set) ≤ (0::complex); ?f summable_on ?A; ⋀x::?'a. x ∈ ?A ⟹ (0::complex) ≤ ?f x; (?x::?'a) ∈ ?A⟧ ⟹ ?f ?x = (0::complex)›*) summable_on_def (*‹(?f::?'a ⇒ ?'b) summable_on (?A::?'a set) ≡ ∃x::?'b. (?f has_sum x) ?A›*)) text ‹The lemma @{thm [source] infsum_mono_neutral} above applies to various linear ordered monoids such as the reals but not to the complex numbers. Thus we have a separate corollary for those:› lemma infsum_mono_neutral_complex: fixes f :: "'a ⇒ complex" assumes [simp]: "f summable_on A" and [simp]: "g summable_on B" assumes ‹⋀x. x ∈ A∩B ⟹ f x ≤ g x› assumes ‹⋀x. x ∈ A-B ⟹ f x ≤ 0› assumes ‹⋀x. x ∈ B-A ⟹ g x ≥ 0› shows ‹infsum f A ≤ infsum g B› proof (-) (*goal: ‹infsum f A ≤ infsum g B›*) have "infsum (λx. Re (f x)) A ≤ infsum (λx. Re (g x)) B" by (smt (verit) assms (*‹(f::'a ⇒ complex) summable_on (A::'a set)› ‹(g::'a ⇒ complex) summable_on (B::'a set)› ‹(?x::'a) ∈ (A::'a set) ∩ (B::'a set) ⟹ (f::'a ⇒ complex) ?x ≤ (g::'a ⇒ complex) ?x› ‹(?x::'a) ∈ (A::'a set) - (B::'a set) ⟹ (f::'a ⇒ complex) ?x ≤ (0::complex)› ‹(?x::'a) ∈ (B::'a set) - (A::'a set) ⟹ (0::complex) ≤ (g::'a ⇒ complex) ?x›*) infsum_cong (*‹(⋀x::?'a. x ∈ (?A::?'a set) ⟹ (?f::?'a ⇒ ?'b) x = (?g::?'a ⇒ ?'b) x) ⟹ infsum ?f ?A = infsum ?g ?A›*) infsum_mono_neutral (*‹⟦(?f::?'a ⇒ ?'b) summable_on (?A::?'a set); (?g::?'a ⇒ ?'b) summable_on (?B::?'a set); ⋀x::?'a. x ∈ ?A ∩ ?B ⟹ ?f x ≤ ?g x; ⋀x::?'a. x ∈ ?A - ?B ⟹ ?f x ≤ (0::?'b); ⋀x::?'a. x ∈ ?B - ?A ⟹ (0::?'b) ≤ ?g x⟧ ⟹ infsum ?f ?A ≤ infsum ?g ?B›*) less_eq_complex_def (*‹((?x::complex) ≤ (?y::complex)) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*) summable_on_Re (*‹(?f::?'a ⇒ complex) summable_on (?M::?'a set) ⟹ (λx::?'a. Re (?f x)) summable_on ?M›*) zero_complex.simps( (*‹Re (0::complex) = (0::real)›*) 1)) then have Re: "Re (infsum f A) ≤ Re (infsum g B)" by (metis assms( (*‹f summable_on A› ‹g summable_on B›*) 1-2) infsum_Re (*‹?f summable_on ?M ⟹ (∑⇩∞x∈?M. Re (?f x)) = Re (infsum ?f ?M)›*)) have "infsum (λx. Im (f x)) A = infsum (λx. Im (g x)) B" by (smt (verit, best) assms( (*‹?x ∈ A ∩ B ⟹ f ?x ≤ g ?x› ‹?x ∈ A - B ⟹ f ?x ≤ 0› ‹?x ∈ B - A ⟹ 0 ≤ g ?x›*) 3-5) infsum_cong_neutral (*‹⟦⋀x. x ∈ ?T - ?S ⟹ ?g x = 0; ⋀x. x ∈ ?S - ?T ⟹ ?f x = 0; ⋀x. x ∈ ?S ∩ ?T ⟹ ?f x = ?g x⟧ ⟹ infsum ?f ?S = infsum ?g ?T›*) less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*) zero_complex.simps( (*‹Im 0 = 0›*) 2)) then have Im: "Im (infsum f A) = Im (infsum g B)" by (metis assms( (*‹f summable_on A› ‹g summable_on B›*) 1-2) infsum_Im (*‹?f summable_on ?M ⟹ (∑⇩∞x∈?M. Im (?f x)) = Im (infsum ?f ?M)›*)) from Re (*‹Re (infsum f A) ≤ Re (infsum g B)›*) Im (*‹Im (infsum f A) = Im (infsum g B)›*) show "?thesis" (*goal: ‹infsum f A ≤ infsum g B›*) by (auto simp: less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*)) qed lemma infsum_mono_complex: ― ‹For \<^typ>‹real›, @{thm [source] infsum_mono} can be used. But \<^typ>‹complex› does not have the right typeclass.› fixes f g :: "'a ⇒ complex" assumes f_sum: "f summable_on A" and g_sum: "g summable_on A" assumes leq: "⋀x. x ∈ A ⟹ f x ≤ g x" shows "infsum f A ≤ infsum g A" by (metis DiffE (*‹⟦?c ∈ ?A - ?B; ⟦?c ∈ ?A; ?c ∉ ?B⟧ ⟹ ?P⟧ ⟹ ?P›*) IntD1 (*‹?c ∈ ?A ∩ ?B ⟹ ?c ∈ ?A›*) f_sum (*‹f summable_on A›*) g_sum (*‹g summable_on A›*) infsum_mono_neutral_complex (*‹⟦?f summable_on ?A; ?g summable_on ?B; ⋀x. x ∈ ?A ∩ ?B ⟹ ?f x ≤ ?g x; ⋀x. x ∈ ?A - ?B ⟹ ?f x ≤ 0; ⋀x. x ∈ ?B - ?A ⟹ 0 ≤ ?g x⟧ ⟹ infsum ?f ?A ≤ infsum ?g ?B›*) leq (*‹?x ∈ A ⟹ f ?x ≤ g ?x›*)) lemma infsum_nonneg_complex: fixes f :: "'a ⇒ complex" assumes "f summable_on M" and "⋀x. x ∈ M ⟹ 0 ≤ f x" shows "infsum f M ≥ 0" (is "?lhs ≥ _") by (metis assms (*‹f summable_on M› ‹?x ∈ M ⟹ 0 ≤ f ?x›*) infsum_0_simp (*‹(∑⇩∞_∈?M. 0) = 0›*) summable_on_0_simp (*‹(λ_. 0) summable_on ?M›*) infsum_mono_complex (*‹⟦?f summable_on ?A; ?g summable_on ?A; ⋀x. x ∈ ?A ⟹ ?f x ≤ ?g x⟧ ⟹ infsum ?f ?A ≤ infsum ?g ?A›*)) lemma infsum_cmod: assumes "f summable_on M" and fnn: "⋀x. x ∈ M ⟹ 0 ≤ f x" shows "infsum (λx. cmod (f x)) M = cmod (infsum f M)" proof (-) (*goal: ‹(∑⇩∞x∈M. cmod (f x)) = cmod (infsum f M)›*) have "complex_of_real (infsum (λx. cmod (f x)) M) = infsum (λx. complex_of_real (cmod (f x))) M" proof (rule infsum_comm_additive[symmetric, unfolded o_def] (*‹⟦additive ?f; isCont ?f (infsum ?g ?S); ?g summable_on ?S⟧ ⟹ ?f (infsum ?g ?S) = (∑⇩∞x∈?S. ?f (?g x))›*)) (*goals: 1. ‹additive complex_of_real› 2. ‹isCont complex_of_real (∑⇩∞x∈M. cmod (f x))› 3. ‹f abs_summable_on M›*) have "(λz. Re (f z)) summable_on M" using assms (*‹(f::'a ⇒ complex) summable_on (M::'a set)› ‹(?x::'a) ∈ (M::'a set) ⟹ (0::complex) ≤ (f::'a ⇒ complex) ?x›*) summable_on_Re (*‹?f summable_on ?M ⟹ (λx. Re (?f x)) summable_on ?M›*) by blast also (*calculation: ‹(λz. Re (f z)) summable_on M›*) have "?this ⟷ f abs_summable_on M" using fnn (*‹?x ∈ M ⟹ 0 ≤ f ?x›*) apply (intro summable_on_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ (?f summable_on ?A) = (?g summable_on ?A)›*)) (*goal: ‹((λz. Re (f z)) summable_on M) = (f abs_summable_on M)›*) by (auto simp: less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*) cmod_def (*‹cmod ?z = sqrt ((Re ?z)² + (Im ?z)²)›*)) finally (*calculation: ‹f abs_summable_on M›*) show "…" . qed (auto simp: additive_def (*‹additive ?f ≡ ∀x y. ?f (x + y) = ?f x + ?f y›*)) (*solves the remaining goals: 1. ‹additive complex_of_real› 2. ‹isCont complex_of_real (∑⇩∞x::'a::type∈(M::'a::type set). cmod ((f::'a::type ⇒ complex) x))›*) also (*calculation: ‹complex_of_real (∑⇩∞x∈M. cmod (f x)) = (∑⇩∞x∈M. complex_of_real (cmod (f x)))›*) have "… = infsum f M" using fnn (*‹?x ∈ M ⟹ 0 ≤ f ?x›*) cmod_eq_Re (*‹Im ?z = 0 ⟹ cmod ?z = ¦Re ?z¦›*) complex_is_Real_iff (*‹(?z ∈ ℝ) = (Im ?z = 0)›*) less_eq_complex_def (*‹(?x ≤ ?y) = (Re ?x ≤ Re ?y ∧ Im ?x = Im ?y)›*) by (force cong: infsum_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ infsum ?f ?A = infsum ?g ?A›*)) finally (*calculation: ‹complex_of_real (∑⇩∞x∈M. cmod (f x)) = infsum f M›*) show "?thesis" (*goal: ‹(∑⇩∞x∈M. cmod (f x)) = cmod (infsum f M)›*) by (metis abs_of_nonneg (*‹0 ≤ ?a ⟹ ¦?a¦ = ?a›*) infsum_def (*‹infsum ?f ?A = (if ?f summable_on ?A then Lim (finite_subsets_at_top ?A) (sum ?f) else 0)›*) le_less_trans (*‹⟦?x ≤ ?y; ?y < ?z⟧ ⟹ ?x < ?z›*) norm_ge_zero (*‹0 ≤ norm ?x›*) norm_infsum_bound (*‹?f abs_summable_on ?A ⟹ norm (infsum ?f ?A) ≤ (∑⇩∞x∈?A. norm (?f x))›*) norm_of_real (*‹norm (of_real ?r) = ¦?r¦›*) not_le (*‹(¬ ?x ≤ ?y) = (?y < ?x)›*) order_refl (*‹?x ≤ ?x›*)) qed lemma summable_on_iff_abs_summable_on_complex: fixes f :: ‹'a ⇒ complex› shows ‹f summable_on A ⟷ f abs_summable_on A› proof (rule iffI (*‹⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q›*)) (*goals: 1. ‹(f::'a ⇒ complex) summable_on (A::'a set) ⟹ f abs_summable_on A› 2. ‹(f::'a ⇒ complex) abs_summable_on (A::'a set) ⟹ f summable_on A›*) assume "f summable_on A" (*‹(f::'a ⇒ complex) summable_on (A::'a set)›*) define i and r and ni and nr and n where "i x = Im (f x)" and "r x = Re (f x)" and "ni x = norm (i x)" and "nr x = norm (r x)" and "n x = norm (f x)" for x from ‹f summable_on A› (*‹f summable_on A›*) have "i summable_on A" by (simp add: i_def[abs_def] (*‹i ≡ λx. Im (f x)›*) summable_on_Im (*‹?f summable_on ?M ⟹ (λx. Im (?f x)) summable_on ?M›*)) then have [simp]: "ni summable_on A" using ni_def[abs_def] (*‹ni ≡ λx. norm (i x)›*) summable_on_iff_abs_summable_on_real (*‹(?f summable_on ?A) = (?f abs_summable_on ?A)›*) by force from ‹f summable_on A› (*‹f summable_on A›*) have "r summable_on A" by (simp add: r_def[abs_def] (*‹r ≡ λx. Re (f x)›*) summable_on_Re (*‹?f summable_on ?M ⟹ (λx. Re (?f x)) summable_on ?M›*)) then have [simp]: "nr summable_on A" by (metis nr_def (*‹nr ?x = norm (r ?x)›*) summable_on_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ (?f summable_on ?A) = (?g summable_on ?A)›*) summable_on_iff_abs_summable_on_real (*‹(?f summable_on ?A) = (?f abs_summable_on ?A)›*)) have n_sum: "n x ≤ nr x + ni x" for x by (simp add: n_def (*‹n ?x = cmod (f ?x)›*) nr_def (*‹nr ?x = norm (r ?x)›*) ni_def (*‹ni ?x = norm (i ?x)›*) r_def (*‹r ?x = Re (f ?x)›*) i_def (*‹i ?x = Im (f ?x)›*) cmod_le (*‹cmod ?z ≤ ¦Re ?z¦ + ¦Im ?z¦›*)) have "*": "(λx. nr x + ni x) summable_on A" by (simp add: summable_on_add (*‹⟦(?f::?'a ⇒ ?'b) summable_on (?A::?'a set); (?g::?'a ⇒ ?'b) summable_on ?A⟧ ⟹ (λx::?'a. ?f x + ?g x) summable_on ?A›*)) have "bdd_above (sum n ` {F. F ⊆ A ∧ finite F})" apply (rule bdd_aboveI[where M=‹infsum (λx. nr x + ni x) A›] (*‹(⋀x. x ∈ ?A ⟹ x ≤ (∑⇩∞x∈A. nr x + ni x)) ⟹ bdd_above ?A›*)) (*goal: ‹bdd_above (sum n ` {F. F ⊆ A ∧ finite F})›*) using "*" (*‹(λx. nr x + ni x) summable_on A›*) n_sum (*‹n ?x ≤ nr ?x + ni ?x›*) by (auto simp flip: infsum_finite (*‹finite ?F ⟹ infsum ?f ?F = sum ?f ?F›*) simp: ni_def (*‹ni ?x = norm (i ?x)›*) nr_def (*‹nr ?x = norm (r ?x)›*) intro!: infsum_mono_neutral (*‹⟦?f summable_on ?A; ?g summable_on ?B; ⋀x. x ∈ ?A ∩ ?B ⟹ ?f x ≤ ?g x; ⋀x. x ∈ ?A - ?B ⟹ ?f x ≤ 0; ⋀x. x ∈ ?B - ?A ⟹ 0 ≤ ?g x⟧ ⟹ infsum ?f ?A ≤ infsum ?g ?B›*)) then show "n summable_on A" by (simp add: n_def (*‹n ?x = cmod (f ?x)›*) nonneg_bdd_above_summable_on (*‹⟦⋀x. x ∈ ?A ⟹ 0 ≤ ?f x; bdd_above (sum ?f ` {F. F ⊆ ?A ∧ finite F})⟧ ⟹ ?f summable_on ?A›*)) next (*goal: ‹f abs_summable_on A ⟹ f summable_on A›*) show "f abs_summable_on A ⟹ f summable_on A" using abs_summable_summable (*‹?f abs_summable_on ?A ⟹ ?f summable_on ?A›*) by blast qed lemma summable_countable_complex: fixes f :: ‹'a ⇒ complex› assumes ‹f summable_on A› shows ‹countable {x∈A. f x ≠ 0}› using abs_summable_countable (*‹(?f::?'a ⇒ ?'b) abs_summable_on (?A::?'a set) ⟹ countable {x::?'a ∈ ?A. ?f x ≠ (0::?'b)}›*) assms (*‹f summable_on A›*) summable_on_iff_abs_summable_on_complex (*‹((?f::?'a ⇒ complex) summable_on (?A::?'a set)) = (?f abs_summable_on ?A)›*) by blast (* TODO: figure all this out *) inductive (in topological_space) convergent_filter :: "'a filter ⇒ bool" where "F ≤ nhds x ⟹ convergent_filter F" lemma (in topological_space) convergent_filter_iff: "convergent_filter F ⟷ (∃x. F ≤ nhds x)" by (auto simp: convergent_filter.simps (*‹convergent_filter ?a = (∃F x. ?a = F ∧ F ≤ nhds x)›*)) lemma (in uniform_space) cauchy_filter_mono: "cauchy_filter F ⟹ F' ≤ F ⟹ cauchy_filter F'" unfolding cauchy_filter_def (*goal: ‹⟦F ×⇩F F ≤ uniformity; F' ≤ F⟧ ⟹ F' ×⇩F F' ≤ uniformity›*) by (meson dual_order.trans (*‹⟦?b ≤ ?a; ?c ≤ ?b⟧ ⟹ ?c ≤ ?a›*) prod_filter_mono (*‹⟦?F ≤ ?F'; ?G ≤ ?G'⟧ ⟹ ?F ×⇩F ?G ≤ ?F' ×⇩F ?G'›*)) lemma (in uniform_space) convergent_filter_cauchy: assumes "convergent_filter F" shows "cauchy_filter F" using assms (*‹convergent_filter F›*) cauchy_filter_mono (*‹⟦cauchy_filter ?F; ?F' ≤ ?F⟧ ⟹ cauchy_filter ?F'›*) nhds_imp_cauchy_filter[OF order.refl] (*‹cauchy_filter (nhds ?x)›*) by (auto simp: convergent_filter_iff (*‹convergent_filter ?F = (∃x. ?F ≤ nhds x)›*)) lemma (in topological_space) convergent_filter_bot [simp, intro]: "convergent_filter bot" by (simp add: convergent_filter_iff (*‹convergent_filter ?F = (∃x. ?F ≤ nhds x)›*)) class complete_uniform_space = uniform_space + assumes cauchy_filter_convergent': "cauchy_filter (F :: 'a filter) ⟹ F ≠ bot ⟹ convergent_filter F" lemma (in complete_uniform_space) cauchy_filter_convergent: "cauchy_filter (F :: 'a filter) ⟹ convergent_filter F" using cauchy_filter_convergent'[of F] (*‹⟦cauchy_filter F; F ≠ bot⟧ ⟹ convergent_filter F›*) apply (cases "F = bot") (*goals: 1. ‹⟦cauchy_filter F; ⟦cauchy_filter F; F ≠ bot⟧ ⟹ convergent_filter F; F = bot⟧ ⟹ convergent_filter F› 2. ‹⟦cauchy_filter F; ⟦cauchy_filter F; F ≠ bot⟧ ⟹ convergent_filter F; F ≠ bot⟧ ⟹ convergent_filter F› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma (in complete_uniform_space) convergent_filter_iff_cauchy: "convergent_filter F ⟷ cauchy_filter F" using convergent_filter_cauchy (*‹convergent_filter ?F ⟹ cauchy_filter ?F›*) cauchy_filter_convergent (*‹cauchy_filter ?F ⟹ convergent_filter ?F›*) by blast definition countably_generated_filter :: "'a filter ⇒ bool" where "countably_generated_filter F ⟷ (∃U :: nat ⇒ 'a set. F = (INF (n::nat). principal (U n)))" lemma countably_generated_filter_has_antimono_basis: assumes "countably_generated_filter F" obtains B :: "nat ⇒ 'a set" where "antimono B" and "F = (INF n. principal (B n))" and "⋀P. eventually P F ⟷ (∃i. ∀x∈B i. P x)" proof (-) (*goal: ‹(⋀B::nat ⇒ 'a::type set. ⟦monotone (≤) (λ(x::'a::type set) y::'a::type set. y ⊆ x) B; (F::'a::type filter) = (INF n::nat. principal (B n)); ⋀P::'a::type ⇒ bool. eventually P F = (∃i::nat. ∀x::'a::type∈B i. P x)⟧ ⟹ thesis::bool) ⟹ thesis›*) from assms (*‹countably_generated_filter F›*) obtain B where B: "F = (INF (n::nat). principal (B n))" (*goal: ‹(⋀B. F = (INF n. principal (B n)) ⟹ thesis) ⟹ thesis›*) unfolding countably_generated_filter_def (*goal: ‹(⋀B. F = (INF n. principal (B n)) ⟹ thesis) ⟹ thesis›*) by blast define B' where "B' = (λn. ⋂k≤n. B k)" have "antimono B'" unfolding decseq_def B'_def (*goal: ‹∀(m::nat) n::nat. m ≤ n ⟶ ⋂ ((B::nat ⇒ 'a set) ` {..n}) ⊆ ⋂ (B ` {..m})›*) by force have "(INF n. principal (B' n)) = (INF n. INF k∈{..n}. principal (B k))" unfolding B'_def (*goal: ‹(INF n::nat. principal (⋂ ((B::nat ⇒ 'a::type set) ` {..n}))) = (INF n::nat. INF k::nat∈{..n}. principal (B k))›*) apply (intro INF_cong (*‹⟦(?A::?'b set) = (?B::?'b set); ⋀x::?'b. x ∈ ?B ⟹ (?C::?'b ⇒ ?'a) x = (?D::?'b ⇒ ?'a) x⟧ ⟹ Inf (?C ` ?A) = Inf (?D ` ?B)›*) refl (*‹(?t::?'a) = ?t›*) INF_principal_finite [symmetric] (*‹finite (?X::?'a set) ⟹ principal (⋂ ((?f::?'a ⇒ ?'b set) ` ?X)) = (INF x::?'a∈?X. principal (?f x))›*)) (*goal: ‹(INF n. principal (⋂ (B ` {..n}))) = (INF n. INF k∈{..n}. principal (B k))›*) by auto also (*calculation: ‹(INF n::nat. principal ((B'::nat ⇒ 'a::type set) n)) = (INF n::nat. INF k::nat∈{..n}. principal ((B::nat ⇒ 'a::type set) k))›*) have "… = (INF (n::nat). principal (B n))" apply (intro antisym (*‹⟦(?a::?'a) ≤ (?b::?'a); ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹(INF n. INF k∈{..n}. principal (B k)) ≤ (INF n. principal (B n))› 2. ‹(INF n. principal (B n)) ≤ (INF n. INF k∈{..n}. principal (B k))› discuss goal 1*) apply (meson INF_lower (*‹(?i::?'b) ∈ (?A::?'b set) ⟹ Inf ((?f::?'b ⇒ ?'a) ` ?A) ≤ ?f ?i›*) INF_mono (*‹(⋀m::?'b. m ∈ (?B::?'b set) ⟹ ∃n::?'c∈?A::?'c set. (?f::?'c ⇒ ?'a) n ≤ (?g::?'b ⇒ ?'a) m) ⟹ Inf (?f ` ?A) ≤ Inf (?g ` ?B)›*) atMost_iff (*‹((?i::?'a) ∈ {..?k::?'a}) = (?i ≤ ?k)›*) order_refl (*‹(?x::?'a) ≤ ?x›*)) (*discuss goal 2*) apply (meson INF_greatest (*‹(⋀i. i ∈ ?A ⟹ ?u ≤ ?f i) ⟹ ?u ≤ Inf (?f ` ?A)›*) INF_lower (*‹?i ∈ ?A ⟹ Inf (?f ` ?A) ≤ ?f ?i›*) UNIV_I (*‹?x ∈ UNIV›*)) (*proven 2 subgoals*) . also (*calculation: ‹(INF n::nat. principal ((B'::nat ⇒ 'a set) n)) = (INF n::nat. principal ((B::nat ⇒ 'a set) n))›*) have "… = F" by (simp add: B (*‹F = (INF n. principal (B n))›*)) finally (*calculation: ‹(INF n. principal (B' n)) = F›*) have F: "F = (INF n. principal (B' n))" by standard moreover have "eventually P F ⟷ (∃i. eventually P (principal (B' i)))" for P unfolding F (*goal: ‹eventually P (INF n. principal (B' n)) = (∃i. eventually P (principal (B' i)))›*) using ‹antimono B'› (*‹monotone (≤) (λx y. y ⊆ x) B'›*) apply (subst eventually_INF_base (*‹⟦?B ≠ {}; ⋀a b. ⟦a ∈ ?B; b ∈ ?B⟧ ⟹ ∃x∈?B. ?F x ≤ inf (?F a) (?F b)⟧ ⟹ eventually ?P (Inf (?F ` ?B)) = (∃b∈?B. eventually ?P (?F b))›*)) (*goals: 1. ‹monotone (≤) (λx y. y ⊆ x) B' ⟹ UNIV ≠ {}› 2. ‹⋀a b. ⟦monotone (≤) (λx y. y ⊆ x) B'; a ∈ UNIV; b ∈ UNIV⟧ ⟹ ∃x∈UNIV. principal (B' x) ≤ inf (principal (B' a)) (principal (B' b))› 3. ‹monotone (≤) (λx y. y ⊆ x) B' ⟹ (∃b∈UNIV. eventually P (principal (B' b))) = (∃i. eventually P (principal (B' i)))› discuss goal 1*) apply ((auto simp: decseq_def (*‹decseq ?X = (∀m n. m ≤ n ⟶ ?X n ≤ ?X m)›*))[1]) (*discuss goal 2*) apply ((auto simp: decseq_def (*‹decseq ?X = (∀m n. m ≤ n ⟶ ?X n ≤ ?X m)›*))[1]) (*top goal: ‹⋀a b. ⟦monotone (≤) (λx y. y ⊆ x) B'; a ∈ UNIV; b ∈ UNIV⟧ ⟹ ∃x∈UNIV. principal (B' x) ≤ inf (principal (B' a)) (principal (B' b))› and 1 goal remains*) apply (meson nat_le_linear (*‹?m ≤ ?n ∨ ?n ≤ ?m›*)) (*discuss goal 3*) apply ((auto simp: decseq_def (*‹decseq (?X::nat ⇒ ?'a) = (∀(m::nat) n::nat. m ≤ n ⟶ ?X n ≤ ?X m)›*))[1]) (*proven 3 subgoals*) . ultimately show "?thesis" (*goal: ‹thesis›*) using ‹antimono B'› (*‹monotone (≤) (λx y. y ⊆ x) B'›*) that[of B'] (*‹⟦monotone (≤) (λx y. y ⊆ x) B'; F = (INF n. principal (B' n)); ⋀P. eventually P F = (∃i. ∀x∈B' i. P x)⟧ ⟹ thesis›*) unfolding eventually_principal (*goal: ‹thesis›*) by blast qed lemma (in uniform_space) cauchy_filter_iff: "cauchy_filter F ⟷ (∀P. eventually P uniformity ⟶ (∃X. eventually (λx. x ∈ X) F ∧ (∀z∈X×X. P z)))" unfolding cauchy_filter_def le_filter_def (*goal: ‹(∀P. eventually P uniformity ⟶ eventually P (F ×⇩F F)) = (∀P. eventually P uniformity ⟶ (∃X. (∀⇩F x in F. x ∈ X) ∧ (∀z∈X × X. P z)))›*) apply (auto simp: eventually_prod_same (*‹eventually ?P (?F ×⇩F ?F) = (∃Q. eventually Q ?F ∧ (∀x y. Q x ⟶ Q y ⟶ ?P (x, y)))›*)) (*goals: 1. ‹⋀P. ⟦∀P. eventually P uniformity ⟶ (∃Q. eventually Q F ∧ (∀x. Q x ⟶ (∀y. Q y ⟶ P (x, y)))); eventually P uniformity⟧ ⟹ ∃X. (∀⇩F x in F. x ∈ X) ∧ (∀x∈X. ∀y∈X. P (x, y))› 2. ‹⋀P. ⟦∀P. eventually P uniformity ⟶ (∃X. (∀⇩F x in F. x ∈ X) ∧ (∀x∈X. ∀y∈X. P (x, y))); eventually P uniformity⟧ ⟹ ∃Q. eventually Q F ∧ (∀x. Q x ⟶ (∀y. Q y ⟶ P (x, y)))› discuss goal 1*) apply (metis (full_types) eventually_mono (*‹⟦eventually ?P ?F; ⋀x. ?P x ⟹ ?Q x⟧ ⟹ eventually ?Q ?F›*) mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*)) (*discuss goal 2*) apply blast (*proven 2 subgoals*) . lemma (in uniform_space) controlled_sequences_convergent_imp_complete_aux_sequence: fixes U :: "nat ⇒ ('a × 'a) set" fixes F :: "'a filter" assumes "cauchy_filter F" "F ≠ bot" assumes "⋀n. eventually (λz. z ∈ U n) uniformity" obtains g G where "antimono G" "⋀n. g n ∈ G n" "⋀n. eventually (λx. x ∈ G n) F" "⋀n. G n × G n ⊆ U n" proof (-) (*goal: ‹(⋀G g. ⟦monotone (≤) (λx y. y ⊆ x) G; ⋀n. g n ∈ G n; ⋀n. ∀⇩F x in F. x ∈ G n; ⋀n. G n × G n ⊆ U n⟧ ⟹ thesis) ⟹ thesis›*) have "∃C. eventually (λx. x ∈ C) F ∧ C × C ⊆ U n" for n using assms(1) (*‹cauchy_filter F›*) assms(3)[of n] (*‹∀⇩F z in uniformity. z ∈ U n›*) unfolding cauchy_filter_iff (*goal: ‹∃C::'a::type set. (∀⇩F x::'a::type in F::'a::type filter. x ∈ C) ∧ C × C ⊆ (U::nat ⇒ ('a::type × 'a::type) set) (n::nat)›*) by blast then obtain G where G: "⋀n. eventually (λx. x ∈ G n) F" "⋀n. G n × G n ⊆ U n" (*goal: ‹(⋀G::nat ⇒ 'a set. ⟦⋀n::nat. ∀⇩F x::'a in F::'a filter. x ∈ G n; ⋀n::nat. G n × G n ⊆ (U::nat ⇒ ('a × 'a) set) n⟧ ⟹ thesis::bool) ⟹ thesis›*) by metis define G' where "G' = (λn. ⋂k≤n. G k)" have 1: "eventually (λx. x ∈ G' n) F" for n using G (*‹∀⇩F x in F. x ∈ G ?n› ‹G ?n × G ?n ⊆ U ?n›*) by (auto simp: G'_def (*‹G' = (λn. ⋂ (G ` {..n}))›*) intro: eventually_ball_finite (*‹⟦finite ?A; ∀y∈?A. ∀⇩F x in ?net. ?P x y⟧ ⟹ ∀⇩F x in ?net. ∀y∈?A. ?P x y›*)) have 2: "G' n × G' n ⊆ U n" for n using G (*‹∀⇩F x in F. x ∈ G ?n› ‹G ?n × G ?n ⊆ U ?n›*) unfolding G'_def (*goal: ‹⋂ (G ` {..n}) × ⋂ (G ` {..n}) ⊆ U n›*) by fast have 3: "antimono G'" unfolding G'_def decseq_def (*goal: ‹∀m n. m ≤ n ⟶ ⋂ (G ` {..n}) ⊆ ⋂ (G ` {..m})›*) by force have "∃g. g ∈ G' n" for n using "1" (*‹∀⇩F x::'a::type in F::'a::type filter. x ∈ (G'::nat ⇒ 'a::type set) (?n::nat)›*) assms(2) (*‹F ≠ bot›*) eventually_happens' (*‹⟦?F ≠ bot; eventually ?P ?F⟧ ⟹ ∃x. ?P x›*) by auto then obtain g where g: "⋀n. g n ∈ G' n" (*goal: ‹(⋀g. (⋀n. g n ∈ G' n) ⟹ thesis) ⟹ thesis›*) by metis from g (*‹g ?n ∈ G' ?n›*) "1" (*‹∀⇩F x in F. x ∈ G' ?n›*) "2" (*‹G' ?n × G' ?n ⊆ U ?n›*) "3" (*‹monotone (≤) (λx y. y ⊆ x) G'›*) that[of G' g] (*‹⟦monotone (≤) (λx y. y ⊆ x) G'; ⋀n. g n ∈ G' n; ⋀n. ∀⇩F x in F. x ∈ G' n; ⋀n. G' n × G' n ⊆ U n⟧ ⟹ thesis›*) show "?thesis" (*goal: ‹thesis::bool›*) by metis qed definition lift_filter :: "('a set ⇒ 'b filter) ⇒ 'a filter ⇒ 'b filter" where "lift_filter f F = (INF X∈{X. eventually (λx. x ∈ X) F}. f X)" lemma lift_filter_top [simp]: "lift_filter g top = g UNIV" proof (-) (*goal: ‹lift_filter g top = g UNIV›*) have "{X. ∀x::'b. x ∈ X} = {UNIV}" by auto thus "?thesis" (*goal: ‹lift_filter g top = g UNIV›*) by (simp add: lift_filter_def (*‹lift_filter ?f ?F = Inf (?f ` {X. ∀⇩F x in ?F. x ∈ X})›*)) qed lemma eventually_lift_filter_iff: assumes "mono g" shows "eventually P (lift_filter g F) ⟷ (∃X. eventually (λx. x ∈ X) F ∧ eventually P (g X))" unfolding lift_filter_def (*goal: ‹eventually P (Inf (g ` {X. ∀⇩F x in F. x ∈ X})) = (∃X. (∀⇩F x in F. x ∈ X) ∧ eventually P (g X))›*) proof (subst eventually_INF_base (*‹⟦?B ≠ {}; ⋀a b. ⟦a ∈ ?B; b ∈ ?B⟧ ⟹ ∃x∈?B. ?F x ≤ inf (?F a) (?F b)⟧ ⟹ eventually ?P (Inf (?F ` ?B)) = (∃b∈?B. eventually ?P (?F b))›*), goal_cases) (*goals: 1. ‹{X. ∀⇩F x in F. x ∈ X} ≠ {}› 2. ‹⋀a b. ⟦a ∈ {X. ∀⇩F x in F. x ∈ X}; b ∈ {X. ∀⇩F x in F. x ∈ X}⟧ ⟹ ∃x∈{X. ∀⇩F x in F. x ∈ X}. g x ≤ inf (g a) (g b)› 3. ‹(∃b∈{X. ∀⇩F x in F. x ∈ X}. eventually P (g b)) = (∃X. (∀⇩F x in F. x ∈ X) ∧ eventually P (g X))›*) case 1 (*no hyothesis introduced yet*) thus "?case" (*goal: ‹{X::'a::type set. ∀⇩F x::'a::type in F::'a::type filter. x ∈ X} ≠ {}›*) by (auto intro: exI[of _ UNIV] (*‹?P UNIV ⟹ ∃x. ?P x›*)) next (*goals: 1. ‹⋀a b. ⟦a ∈ {X. ∀⇩F x in F. x ∈ X}; b ∈ {X. ∀⇩F x in F. x ∈ X}⟧ ⟹ ∃x∈{X. ∀⇩F x in F. x ∈ X}. g x ≤ inf (g a) (g b)› 2. ‹(∃b∈{X. ∀⇩F x in F. x ∈ X}. eventually P (g b)) = (∃X. (∀⇩F x in F. x ∈ X) ∧ eventually P (g X))›*) case (2 X Y) (*‹(X::'a set) ∈ {X::'a set. ∀⇩F x::'a in F::'a filter. x ∈ X}› ‹Y ∈ {X. ∀⇩F x in F. x ∈ X}›*) thus "?case" (*goal: ‹∃x::'a set∈{X::'a set. ∀⇩F x::'a in F::'a filter. x ∈ X}. (g::'a set ⇒ 'b filter) x ≤ inf (g (X::'a set)) (g (Y::'a set))›*) by (auto intro!: exI[of _ "X ∩ Y"] (*‹?P (X ∩ Y) ⟹ ∃x. ?P x›*) eventually_conj (*‹⟦eventually ?P ?F; eventually ?Q ?F⟧ ⟹ ∀⇩F x in ?F. ?P x ∧ ?Q x›*) monoD[OF assms] (*‹?x ⊆ ?y ⟹ g ?x ≤ g ?y›*)) qed (auto) (*solved the remaining goal: ‹(∃b∈{X. ∀⇩F x in F. x ∈ X}. eventually P (g b)) = (∃X. (∀⇩F x in F. x ∈ X) ∧ eventually P (g X))›*) lemma lift_filter_le: assumes "eventually (λx. x ∈ X) F" "g X ≤ F'" shows "lift_filter g F ≤ F'" unfolding lift_filter_def (*goal: ‹Inf ((g::'a set ⇒ 'b filter) ` {X::'a set. ∀⇩F x::'a in F::'a filter. x ∈ X}) ≤ (F'::'b filter)›*) by (metis INF_lower2 (*‹⟦?i ∈ ?A; ?f ?i ≤ ?u⟧ ⟹ Inf (?f ` ?A) ≤ ?u›*) assms (*‹∀⇩F x in F. x ∈ X› ‹g X ≤ F'›*) mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*)) definition lift_filter' :: "('a set ⇒ 'b set) ⇒ 'a filter ⇒ 'b filter" where "lift_filter' f F = lift_filter (principal ∘ f) F" lemma lift_filter'_top [simp]: "lift_filter' g top = principal (g UNIV)" by (simp add: lift_filter'_def (*‹lift_filter' ?f ?F = lift_filter (principal ∘ ?f) ?F›*)) lemma eventually_lift_filter'_iff: assumes "mono g" shows "eventually P (lift_filter' g F) ⟷ (∃X. eventually (λx. x ∈ X) F ∧ (∀x∈g X. P x))" unfolding lift_filter'_def (*goal: ‹eventually (P::'b::type ⇒ bool) (lift_filter (principal ∘ (g::'a::type set ⇒ 'b::type set)) (F::'a::type filter)) = (∃X::'a::type set. (∀⇩F x::'a::type in F. x ∈ X) ∧ (∀x::'b::type∈g X. P x))›*) using assms (*‹mono g›*) apply (subst eventually_lift_filter_iff (*‹mono (?g::?'a set ⇒ ?'b filter) ⟹ eventually (?P::?'b ⇒ bool) (lift_filter ?g (?F::?'a filter)) = (∃X::?'a set. (∀⇩F x::?'a in ?F. x ∈ X) ∧ eventually ?P (?g X))›*)) (*goals: 1. ‹mono (g::'a set ⇒ 'b set) ⟹ mono (principal ∘ g)› 2. ‹mono (g::'a set ⇒ 'b set) ⟹ (∃X::'a set. (∀⇩F x::'a in F::'a filter. x ∈ X) ∧ eventually (P::'b ⇒ bool) ((principal ∘ g) X)) = (∃X::'a set. (∀⇩F x::'a in F. x ∈ X) ∧ Ball (g X) P)› discuss goal 1*) apply ((auto simp: mono_def (*‹mono ?f = (∀x y. x ≤ y ⟶ ?f x ≤ ?f y)›*) eventually_principal (*‹eventually ?P (principal ?S) = (∀x∈?S. ?P x)›*))[1]) (*discuss goal 2*) apply ((auto simp: mono_def (*‹mono ?f = (∀x y. x ≤ y ⟶ ?f x ≤ ?f y)›*) eventually_principal (*‹eventually ?P (principal ?S) = (∀x∈?S. ?P x)›*))[1]) (*proven 2 subgoals*) . lemma lift_filter'_le: assumes "eventually (λx. x ∈ X) F" "principal (g X) ≤ F'" shows "lift_filter' g F ≤ F'" unfolding lift_filter'_def (*goal: ‹lift_filter (principal ∘ g) F ≤ F'›*) using assms (*‹∀⇩F x in F. x ∈ X› ‹principal (g X) ≤ F'›*) apply (intro lift_filter_le[where X = X] (*‹⟦∀⇩F x in ?F. x ∈ X; ?g X ≤ ?F'⟧ ⟹ lift_filter ?g ?F ≤ ?F'›*)) (*goals: 1. ‹⟦∀⇩F x::'a in F::'a filter. x ∈ (X::'a set); principal ((g::'a set ⇒ 'b set) X) ≤ (F'::'b filter)⟧ ⟹ ∀⇩F x::'a in F. x ∈ X› 2. ‹⟦∀⇩F x::'a in F::'a filter. x ∈ (X::'a set); principal ((g::'a set ⇒ 'b set) X) ≤ (F'::'b filter)⟧ ⟹ (principal ∘ g) X ≤ F'› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma (in uniform_space) comp_uniformity_le_uniformity: "lift_filter' (λX. X O X) uniformity ≤ uniformity" unfolding le_filter_def (*goal: ‹∀P::'a × 'a ⇒ bool. eventually P uniformity ⟶ eventually P (lift_filter' (λX::('a × 'a) set. X O X) uniformity)›*) proof (safe) (*goal: ‹⋀P::'a::type × 'a::type ⇒ bool. eventually P uniformity ⟹ eventually P (lift_filter' (λX::('a::type × 'a::type) set. X O X) uniformity)›*) fix P assume P: "eventually P uniformity" (*‹eventually (P::'a × 'a ⇒ bool) uniformity›*) have [simp]: "mono (λX::('a × 'a) set. X O X)" apply (intro monoI (*‹(⋀x y. x ≤ y ⟹ ?f x ≤ ?f y) ⟹ mono ?f›*)) (*goal: ‹mono (λX::('a × 'a) set. X O X)›*) by auto from P (*‹eventually P uniformity›*) obtain P' where P': "eventually P' uniformity " "(⋀x y z. P' (x, y) ⟹ P' (y, z) ⟹ P (x, z))" (*goal: ‹(⋀P'::'a × 'a ⇒ bool. ⟦eventually P' uniformity; ⋀(x::'a) (y::'a) z::'a. ⟦P' (x, y); P' (y, z)⟧ ⟹ (P::'a × 'a ⇒ bool) (x, z)⟧ ⟹ thesis::bool) ⟹ thesis›*) using uniformity_transE (*‹⟦eventually ?E uniformity; ⋀D. ⟦eventually D uniformity; ⋀x y z. ⟦D (x, y); D (y, z)⟧ ⟹ ?E (x, z)⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) by blast show "eventually P (lift_filter' (λX. X O X) uniformity)" by (auto simp: eventually_lift_filter'_iff (*‹mono (?g::?'a set ⇒ ?'b set) ⟹ eventually (?P::?'b ⇒ bool) (lift_filter' ?g (?F::?'a filter)) = (∃X::?'a set. (∀⇩F x::?'a in ?F. x ∈ X) ∧ (∀x::?'b∈?g X. ?P x))›*) intro!: exI[of _ "{x. P' x}"] (*‹(?P::('a × 'a) set ⇒ bool) {x::'a × 'a. (P'::'a × 'a ⇒ bool) x} ⟹ ∃x::('a × 'a) set. ?P x›*) P' (*‹eventually (P'::'a × 'a ⇒ bool) uniformity› ‹⟦(P'::'a × 'a ⇒ bool) (?x::'a, ?y::'a); P' (?y, ?z::'a)⟧ ⟹ (P::'a × 'a ⇒ bool) (?x, ?z)›*)) qed lemma (in uniform_space) comp_mem_uniformity_sets: assumes "eventually (λz. z ∈ X) uniformity" obtains Y where "eventually (λz. z ∈ Y) uniformity" "Y O Y ⊆ X" proof (-) (*goal: ‹(⋀Y. ⟦∀⇩F z in uniformity. z ∈ Y; Y O Y ⊆ X⟧ ⟹ thesis) ⟹ thesis›*) have [simp]: "mono (λX::('a × 'a) set. X O X)" apply (intro monoI (*‹(⋀x y. x ≤ y ⟹ ?f x ≤ ?f y) ⟹ mono ?f›*)) (*goal: ‹mono (λX. X O X)›*) by auto have "eventually (λz. z ∈ X) (lift_filter' (λX. X O X) uniformity)" using assms (*‹∀⇩F z::'a × 'a in uniformity. z ∈ (X::('a × 'a) set)›*) comp_uniformity_le_uniformity (*‹lift_filter' (λX. X O X) uniformity ≤ uniformity›*) using filter_leD (*‹⟦?F ≤ ?F'; eventually ?P ?F'⟧ ⟹ eventually ?P ?F›*) by blast thus "?thesis" (*goal: ‹thesis›*) using that (*‹⟦∀⇩F z in uniformity. z ∈ ?Y; ?Y O ?Y ⊆ X⟧ ⟹ thesis›*) by (auto simp: eventually_lift_filter'_iff (*‹mono ?g ⟹ eventually ?P (lift_filter' ?g ?F) = (∃X. (∀⇩F x in ?F. x ∈ X) ∧ (∀x∈?g X. ?P x))›*)) qed lemma (in uniform_space) le_nhds_of_cauchy_adhp_aux: assumes "⋀P. eventually P uniformity ⟹ (∃X. eventually (λy. y ∈ X) F ∧ (∀z∈X × X. P z) ∧ (∃y. P (x, y) ∧ y ∈ X))" shows "F ≤ nhds x" unfolding le_filter_def (*goal: ‹∀P. eventually P (nhds x) ⟶ eventually P F›*) proof (safe) (*goal: ‹⋀P. eventually P (nhds x) ⟹ eventually P F›*) fix P assume "eventually P (nhds x)" (*‹eventually (P::'a ⇒ bool) (nhds (x::'a))›*) hence "∀⇩F z in uniformity. z ∈ {z. fst z = x ⟶ P (snd z)}" by (simp add: eventually_nhds_uniformity (*‹eventually ?P (nhds ?x) = (∀⇩F (x', y) in uniformity. x' = ?x ⟶ ?P y)›*) case_prod_unfold (*‹case_prod = (λc p. c (fst p) (snd p))›*)) then obtain Y where Y: "∀⇩F z in uniformity. z ∈ Y" "Y O Y ⊆ {z. fst z = x ⟶ P (snd z)}" (*goal: ‹(⋀Y. ⟦∀⇩F z in uniformity. z ∈ Y; Y O Y ⊆ {z. fst z = x ⟶ P (snd z)}⟧ ⟹ thesis) ⟹ thesis›*) using comp_mem_uniformity_sets (*‹⟦∀⇩F z in uniformity. z ∈ ?X; ⋀Y. ⟦∀⇩F z in uniformity. z ∈ Y; Y O Y ⊆ ?X⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) by blast obtain X and y where Xy: "eventually (λy. y ∈ X) F" "X×X ⊆ Y" "(x, y) ∈ Y" "y ∈ X" (*goal: ‹(⋀X y. ⟦∀⇩F y in F. y ∈ X; X × X ⊆ Y; (x, y) ∈ Y; y ∈ X⟧ ⟹ thesis) ⟹ thesis›*) using assms[OF Y ( 1 )] (*‹∃X::'a::type set. (∀⇩F y::'a::type in F::'a::type filter. y ∈ X) ∧ (∀z::'a::type × 'a::type∈X × X. z ∈ (Y::('a::type × 'a::type) set)) ∧ (∃y::'a::type. (x::'a::type, y) ∈ Y ∧ y ∈ X)›*) by blast have "*": "P x" if "x ∈ X" for x using Y(2) (*‹Y O Y ⊆ {z. fst z = x ⟶ P (snd z)}›*) Xy(2-4) (*‹X × X ⊆ Y› ‹(x, y) ∈ Y› ‹y ∈ X›*) that (*‹x ∈ X›*) unfolding relcomp_unfold (*goal: ‹P x›*) by force show "eventually P F" apply (rule eventually_mono[OF Xy(1)] (*‹(⋀x::'a::type. x ∈ (X::'a::type set) ⟹ (?Q::'a::type ⇒ bool) x) ⟹ eventually ?Q (F::'a::type filter)›*)) (*goal: ‹eventually (P::'a ⇒ bool) (F::'a filter)›*) by (use * in auto) qed lemma (in uniform_space) eventually_uniformity_imp_nhds: assumes "eventually P uniformity" shows "eventually (λy. P (x, y)) (nhds x)" using assms (*‹eventually (P::'a × 'a ⇒ bool) uniformity›*) unfolding eventually_nhds_uniformity (*goal: ‹∀⇩F (x', y) in uniformity. x' = x ⟶ P (x, y)›*) apply (elim eventually_mono (*‹⟦eventually (?P::?'a ⇒ bool) (?F::?'a filter); ⋀x::?'a. ?P x ⟹ (?Q::?'a ⇒ bool) x⟧ ⟹ eventually ?Q ?F›*)) (*goal: ‹∀⇩F (x', y) in uniformity. x' = x ⟶ P (x, y)›*) by auto lemma (in uniform_space) controlled_sequences_convergent_imp_complete_aux: fixes U :: "nat ⇒ ('a × 'a) set" assumes gen: "countably_generated_filter (uniformity :: ('a × 'a) filter)" assumes U: "⋀n. eventually (λz. z ∈ U n) uniformity" assumes conv: "⋀(u :: nat ⇒ 'a). (⋀N m n. N ≤ m ⟹ N ≤ n ⟹ (u m, u n) ∈ U N) ⟹ convergent u" assumes "cauchy_filter F" shows "convergent_filter F" proof (cases "F = bot") (*goals: 1. ‹F = bot ⟹ convergent_filter F› 2. ‹F ≠ bot ⟹ convergent_filter F›*) case False (*‹F ≠ bot›*) note F = ‹cauchy_filter F› (*‹cauchy_filter F›*) ‹F ≠ bot› (*‹F ≠ bot›*) from gen (*‹countably_generated_filter uniformity›*) obtain B :: "nat ⇒ ('a × 'a) set" where B: "antimono B" "uniformity = (INF n. principal (B n))" "⋀P. eventually P uniformity ⟷ (∃i. ∀x∈B i. P x)" (*goal: ‹(⋀B::nat ⇒ ('a::type × 'a::type) set. ⟦monotone (≤) (λ(x::('a::type × 'a::type) set) y::('a::type × 'a::type) set. y ⊆ x) B; uniformity = (INF n::nat. principal (B n)); ⋀P::'a::type × 'a::type ⇒ bool. eventually P uniformity = (∃i::nat. ∀x::'a::type × 'a::type∈B i. P x)⟧ ⟹ thesis::bool) ⟹ thesis›*) using countably_generated_filter_has_antimono_basis (*‹⟦countably_generated_filter (?F::?'a::type filter); ⋀B::nat ⇒ ?'a::type set. ⟦monotone (≤) (λ(x::?'a::type set) y::?'a::type set. y ⊆ x) B; ?F = (INF n::nat. principal (B n)); ⋀P::?'a::type ⇒ bool. eventually P ?F = (∃i::nat. ∀x::?'a::type∈B i. P x)⟧ ⟹ ?thesis::bool⟧ ⟹ ?thesis›*) by blast have ev_B: "eventually (λz. z ∈ B n) uniformity" for n apply (subst B( (*‹eventually ?P uniformity = (∃i. ∀x∈B i. ?P x)›*) 3)) (*goal: ‹∀⇩F z in uniformity. z ∈ B n›*) by auto hence ev_B': "eventually (λz. z ∈ B n ∩ U n) uniformity" for n using U (*‹∀⇩F z::'a × 'a in uniformity. z ∈ (U::nat ⇒ ('a × 'a) set) (?n::nat)›*) by (auto intro: eventually_conj (*‹⟦eventually ?P ?F; eventually ?Q ?F⟧ ⟹ ∀⇩F x in ?F. ?P x ∧ ?Q x›*)) obtain g and G where gG: "antimono G" "⋀n. g n ∈ G n" "⋀n. eventually (λx. x ∈ G n) F" "⋀n. G n × G n ⊆ B n ∩ U n" (*goal: ‹(⋀G g. ⟦monotone (≤) (λx y. y ⊆ x) G; ⋀n. g n ∈ G n; ⋀n. ∀⇩F x in F. x ∈ G n; ⋀n. G n × G n ⊆ B n ∩ U n⟧ ⟹ thesis) ⟹ thesis›*) using controlled_sequences_convergent_imp_complete_aux_sequence[of F "λn. B n ∩ U n", OF F ev_B'] (*‹(⋀g G. ⟦monotone (≤) (λx y. y ⊆ x) G; ⋀n. g n ∈ G n; ⋀n. ∀⇩F x in F. x ∈ G n; ⋀n. G n × G n ⊆ B n ∩ U n⟧ ⟹ ?thesis) ⟹ ?thesis›*) by metis have "convergent g" proof (rule conv (*‹(⋀N m n. ⟦N ≤ m; N ≤ n⟧ ⟹ (?u m, ?u n) ∈ U N) ⟹ convergent ?u›*)) (*goal: ‹⋀N m n. ⟦N ≤ m; N ≤ n⟧ ⟹ (g m, g n) ∈ U N›*) fix N :: nat and m :: nat and n :: nat assume mn: "N ≤ m" "N ≤ n" (*‹(N::nat) ≤ (m::nat)› ‹(N::nat) ≤ (n::nat)›*) have "(g m, g n) ∈ G m × G n" using gG (*‹monotone (≤) (λx y. y ⊆ x) G› ‹g ?n ∈ G ?n› ‹∀⇩F x in F. x ∈ G ?n› ‹G ?n × G ?n ⊆ B ?n ∩ U ?n›*) by auto also (*calculation: ‹(g m, g n) ∈ G m × G n›*) from mn (*‹(N::nat) ≤ (m::nat)› ‹N ≤ n›*) have "… ⊆ G N × G N" apply (intro Sigma_mono (*‹⟦?A ⊆ ?C; ⋀x. x ∈ ?A ⟹ ?B x ⊆ ?D x⟧ ⟹ Sigma ?A ?B ⊆ Sigma ?C ?D›*) gG (*‹monotone (≤) (λx y. y ⊆ x) G› ‹g ?n ∈ G ?n› ‹∀⇩F x in F. x ∈ G ?n› ‹G ?n × G ?n ⊆ B ?n ∩ U ?n›*) antimonoD[OF gG(1)] (*‹?x ≤ ?y ⟹ G ?y ⊆ G ?x›*)) (*goals: 1. ‹⟦N ≤ m; N ≤ n⟧ ⟹ N ≤ m› 2. ‹⋀x. ⟦N ≤ m; N ≤ n; x ∈ G m⟧ ⟹ N ≤ n› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) also (*calculation: ‹(g m, g n) ∈ G N × G N›*) have "… ⊆ U N" using gG (*‹monotone (≤) (λx y. y ⊆ x) G› ‹g ?n ∈ G ?n› ‹∀⇩F x in F. x ∈ G ?n› ‹G ?n × G ?n ⊆ B ?n ∩ U ?n›*) by blast finally (*calculation: ‹(g m, g n) ∈ U N›*) show "(g m, g n) ∈ U N" . qed then obtain L where G: "g ⇢ L" (*goal: ‹(⋀L. g ⇢ L ⟹ thesis) ⟹ thesis›*) unfolding convergent_def (*goal: ‹(⋀L. g ⇢ L ⟹ thesis) ⟹ thesis›*) by blast have "F ≤ nhds L" proof (rule le_nhds_of_cauchy_adhp_aux (*‹(⋀P::'a × 'a ⇒ bool. eventually P uniformity ⟹ ∃X::'a set. (∀⇩F y::'a in ?F::'a filter. y ∈ X) ∧ (∀z::'a × 'a∈X × X. P z) ∧ (∃y::'a. P (?x::'a, y) ∧ y ∈ X)) ⟹ ?F ≤ nhds ?x›*)) (*goal: ‹⋀P::'a × 'a ⇒ bool. eventually P uniformity ⟹ ∃X::'a set. (∀⇩F y::'a in F::'a filter. y ∈ X) ∧ (∀z::'a × 'a∈X × X. P z) ∧ (∃y::'a. P (L::'a, y) ∧ y ∈ X)›*) fix P :: "'a × 'a ⇒ bool" assume P: "eventually P uniformity" (*‹eventually (P::'a × 'a ⇒ bool) uniformity›*) hence "eventually (λn. ∀x∈B n. P x) sequentially" using ‹antimono B› (*‹monotone (≤) (λx y. y ⊆ x) B›*) unfolding B(3) eventually_sequentially decseq_def (*goal: ‹∃N. ∀n≥N. Ball (B n) P›*) by blast moreover have "eventually (λn. P (L, g n)) sequentially" using P (*‹eventually P uniformity›*) eventually_compose_filterlim (*‹⟦eventually ?P ?F; filterlim ?f ?F ?G⟧ ⟹ ∀⇩F x in ?G. ?P (?f x)›*) eventually_uniformity_imp_nhds (*‹eventually ?P uniformity ⟹ ∀⇩F y in nhds ?x. ?P (?x, y)›*) G (*‹g ⇢ L›*) by blast ultimately have "eventually (λn. (∀x∈B n. P x) ∧ P (L, g n)) sequentially" apply eventually_elim (*goal: ‹∀⇩F n::nat in sequentially. (∀x::'a × 'a∈(B::nat ⇒ ('a × 'a) set) n. (P::'a × 'a ⇒ bool) x) ∧ P (L::'a, (g::nat ⇒ 'a) n)›*) by auto then obtain n where "∀x∈B n. P x" "P (L, g n)" (*goal: ‹(⋀n. ⟦∀x∈B n. P x; P (L, g n)⟧ ⟹ thesis) ⟹ thesis›*) unfolding eventually_at_top_linorder (*goal: ‹(⋀n::nat. ⟦∀x::'a × 'a∈(B::nat ⇒ ('a × 'a) set) n. (P::'a × 'a ⇒ bool) x; P (L::'a, (g::nat ⇒ 'a) n)⟧ ⟹ thesis::bool) ⟹ thesis›*) by blast then show "∃X. (∀⇩F y in F. y ∈ X) ∧ (∀z∈X × X. P z) ∧ (∃y. P (L, y) ∧ y ∈ X)" using gG (*‹monotone (≤) (λx y. y ⊆ x) G› ‹g ?n ∈ G ?n› ‹∀⇩F x in F. x ∈ G ?n› ‹G ?n × G ?n ⊆ B ?n ∩ U ?n›*) by blast qed thus "convergent_filter F" by (auto simp: convergent_filter_iff (*‹convergent_filter ?F = (∃x. ?F ≤ nhds x)›*)) qed (auto) (*solved the remaining goal: ‹F = bot ⟹ convergent_filter F›*) theorem (in uniform_space) controlled_sequences_convergent_imp_complete: fixes U :: "nat ⇒ ('a × 'a) set" assumes gen: "countably_generated_filter (uniformity :: ('a × 'a) filter)" assumes U: "⋀n. eventually (λz. z ∈ U n) uniformity" assumes conv: "⋀(u :: nat ⇒ 'a). (⋀N m n. N ≤ m ⟹ N ≤ n ⟹ (u m, u n) ∈ U N) ⟹ convergent u" shows "class.complete_uniform_space open uniformity" apply unfold_locales (*goal: ‹class.complete_uniform_space open uniformity›*) by (use assms controlled_sequences_convergent_imp_complete_aux in blast) lemma filtermap_prod_filter: "filtermap (map_prod f g) (F ×⇩F G) = filtermap f F ×⇩F filtermap g G" proof (intro antisym (*‹⟦(?a::?'a) ≤ (?b::?'a); ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹filtermap (map_prod f g) (F ×⇩F G) ≤ filtermap f F ×⇩F filtermap g G› 2. ‹filtermap f F ×⇩F filtermap g G ≤ filtermap (map_prod f g) (F ×⇩F G)›*) show "filtermap (map_prod f g) (F ×⇩F G) ≤ filtermap f F ×⇩F filtermap g G" by (auto simp: le_filter_def (*‹(?F ≤ ?F') = (∀P. eventually P ?F' ⟶ eventually P ?F)›*) eventually_filtermap (*‹eventually ?P (filtermap ?f ?F) = (∀⇩F x in ?F. ?P (?f x))›*) eventually_prod_filter (*‹eventually ?P (?F ×⇩F ?G) = (∃Pf Pg. eventually Pf ?F ∧ eventually Pg ?G ∧ (∀x y. Pf x ⟶ Pg y ⟶ ?P (x, y)))›*)) next (*goal: ‹filtermap f F ×⇩F filtermap g G ≤ filtermap (map_prod f g) (F ×⇩F G)›*) show "filtermap f F ×⇩F filtermap g G ≤ filtermap (map_prod f g) (F ×⇩F G)" unfolding le_filter_def (*goal: ‹∀P. eventually P (filtermap (map_prod f g) (F ×⇩F G)) ⟶ eventually P (filtermap f F ×⇩F filtermap g G)›*) proof (safe) (*goal: ‹⋀P. eventually P (filtermap (map_prod f g) (F ×⇩F G)) ⟹ eventually P (filtermap f F ×⇩F filtermap g G)›*) fix P assume P: "eventually P (filtermap (map_prod f g) (F ×⇩F G))" (*‹eventually (P::'a × 'b ⇒ bool) (filtermap (map_prod (f::'c ⇒ 'a) (g::'d ⇒ 'b)) ((F::'c filter) ×⇩F (G::'d filter)))›*) then obtain Pf and Pg where "*": "eventually Pf F" "eventually Pg G" "∀x. Pf x ⟶ (∀y. Pg y ⟶ P (f x, g y))" (*goal: ‹(⋀Pf Pg. ⟦eventually Pf F; eventually Pg G; ∀x. Pf x ⟶ (∀y. Pg y ⟶ P (f x, g y))⟧ ⟹ thesis) ⟹ thesis›*) by (auto simp: eventually_filtermap (*‹eventually ?P (filtermap ?f ?F) = (∀⇩F x in ?F. ?P (?f x))›*) eventually_prod_filter (*‹eventually ?P (?F ×⇩F ?G) = (∃Pf Pg. eventually Pf ?F ∧ eventually Pg ?G ∧ (∀x y. Pf x ⟶ Pg y ⟶ ?P (x, y)))›*)) define Pf' where "Pf' = (λx. ∃y. x = f y ∧ Pf y)" define Pg' where "Pg' = (λx. ∃y. x = g y ∧ Pg y)" from "*"(1) (*‹eventually Pf F›*) have "∀⇩F x in F. Pf' (f x)" apply eventually_elim (*goal: ‹∀⇩F x in F. Pf' (f x)›*) by (auto simp: Pf'_def (*‹(Pf'::'a::type ⇒ bool) = (λx::'a::type. ∃y::'c::type. x = (f::'c::type ⇒ 'a::type) y ∧ (Pf::'c::type ⇒ bool) y)›*)) moreover from "*"(2) (*‹eventually Pg G›*) have "∀⇩F x in G. Pg' (g x)" apply eventually_elim (*goal: ‹∀⇩F x in G. Pg' (g x)›*) by (auto simp: Pg'_def (*‹Pg' = (λx. ∃y. x = g y ∧ Pg y)›*)) moreover have "(∀x y. Pf' x ⟶ Pg' y ⟶ P (x, y))" using "*"(3) (*‹∀x. Pf x ⟶ (∀y. Pg y ⟶ P (f x, g y))›*) by (auto simp: Pf'_def (*‹Pf' = (λx. ∃y. x = f y ∧ Pf y)›*) Pg'_def (*‹Pg' = (λx. ∃y. x = g y ∧ Pg y)›*)) ultimately show "eventually P (filtermap f F ×⇩F filtermap g G)" unfolding eventually_prod_filter eventually_filtermap (*goal: ‹∃(Pf::'a ⇒ bool) Pg::'b ⇒ bool. (∀⇩F x::'c in F::'c filter. Pf ((f::'c ⇒ 'a) x)) ∧ (∀⇩F x::'d in G::'d filter. Pg ((g::'d ⇒ 'b) x)) ∧ (∀(x::'a) y::'b. Pf x ⟶ Pg y ⟶ (P::'a × 'b ⇒ bool) (x, y))›*) by blast qed qed lemma (in uniform_space) Cauchy_seq_iff_tendsto: "Cauchy f ⟷ filterlim (map_prod f f) uniformity (at_top ×⇩F at_top)" unfolding Cauchy_uniform cauchy_filter_def filterlim_def filtermap_prod_filter (*goal: ‹(filtermap (f::nat ⇒ 'a::type) sequentially ×⇩F filtermap f sequentially ≤ uniformity) = (filtermap f sequentially ×⇩F filtermap f sequentially ≤ uniformity)›*) by standard theorem (in uniform_space) controlled_seq_imp_Cauchy_seq: fixes U :: "nat ⇒ ('a × 'a) set" assumes U: "⋀P. eventually P uniformity ⟹ (∃n. ∀x∈U n. P x)" assumes controlled: "⋀N m n. N ≤ m ⟹ N ≤ n ⟹ (f m, f n) ∈ U N" shows "Cauchy f" unfolding Cauchy_seq_iff_tendsto (*goal: ‹filterlim (map_prod f f) uniformity (sequentially ×⇩F sequentially)›*) proof (-) (*goal: ‹filterlim (map_prod (f::nat ⇒ 'a) f) uniformity (sequentially ×⇩F sequentially)›*) show "filterlim (map_prod f f) uniformity (sequentially ×⇩F sequentially)" unfolding filterlim_def le_filter_def (*goal: ‹∀P::'a::type × 'a::type ⇒ bool. eventually P uniformity ⟶ eventually P (filtermap (map_prod (f::nat ⇒ 'a::type) f) (sequentially ×⇩F sequentially))›*) proof (safe) (*goal: ‹⋀P. eventually P uniformity ⟹ eventually P (filtermap (map_prod f f) (sequentially ×⇩F sequentially))›*) fix P :: "'a × 'a ⇒ bool" assume P: "eventually P uniformity" (*‹eventually (P::'a × 'a ⇒ bool) uniformity›*) from U[OF this] (*‹∃n. ∀x∈U n. P x›*) obtain N where "∀x∈U N. P x" (*goal: ‹(⋀N. ∀x∈U N. P x ⟹ thesis) ⟹ thesis›*) by blast then show "eventually P (filtermap (map_prod f f) (sequentially ×⇩F sequentially))" unfolding eventually_filtermap eventually_prod_sequentially (*goal: ‹∃N. ∀m≥N. ∀n≥N. P (map_prod f f (n, m))›*) by (metis controlled (*‹⟦?N ≤ ?m; ?N ≤ ?n⟧ ⟹ (f ?m, f ?n) ∈ U ?N›*) map_prod_simp (*‹map_prod ?f ?g (?a, ?b) = (?f ?a, ?g ?b)›*)) qed qed lemma (in uniform_space) Cauchy_seq_convergent_imp_complete_aux: fixes U :: "nat ⇒ ('a × 'a) set" assumes gen: "countably_generated_filter (uniformity :: ('a × 'a) filter)" assumes conv: "⋀(u :: nat ⇒ 'a). Cauchy u ⟹ convergent u" assumes "cauchy_filter F" shows "convergent_filter F" proof (-) (*goal: ‹convergent_filter (F::'a filter)›*) from gen (*‹countably_generated_filter uniformity›*) obtain B :: "nat ⇒ ('a × 'a) set" where B: "antimono B" "uniformity = (INF n. principal (B n))" "⋀P. eventually P uniformity ⟷ (∃i. ∀x∈B i. P x)" (*goal: ‹(⋀B. ⟦monotone (≤) (λx y. y ⊆ x) B; uniformity = (INF n. principal (B n)); ⋀P. eventually P uniformity = (∃i. ∀x∈B i. P x)⟧ ⟹ thesis) ⟹ thesis›*) using countably_generated_filter_has_antimono_basis (*‹⟦countably_generated_filter ?F; ⋀B. ⟦monotone (≤) (λx y. y ⊆ x) B; ?F = (INF n. principal (B n)); ⋀P. eventually P ?F = (∃i. ∀x∈B i. P x)⟧ ⟹ ?thesis⟧ ⟹ ?thesis›*) by blast show "?thesis" (*goal: ‹convergent_filter F›*) proof (rule controlled_sequences_convergent_imp_complete_aux[where U = B] (*‹⟦countably_generated_filter uniformity; ⋀n. ∀⇩F z in uniformity. z ∈ B n; ⋀u. (⋀N m n. ⟦N ≤ m; N ≤ n⟧ ⟹ (u m, u n) ∈ B N) ⟹ convergent u; cauchy_filter ?F⟧ ⟹ convergent_filter ?F›*)) (*goals: 1. ‹countably_generated_filter uniformity› 2. ‹⋀n::nat. ∀⇩F z::'a::type × 'a::type in uniformity. z ∈ (B::nat ⇒ ('a::type × 'a::type) set) n› 3. ‹⋀u::nat ⇒ 'a::type. (⋀(N::nat) (m::nat) n::nat. ⟦N ≤ m; N ≤ n⟧ ⟹ (u m, u n) ∈ (B::nat ⇒ ('a::type × 'a::type) set) N) ⟹ convergent u› 4. ‹cauchy_filter (F::'a::type filter)›*) show "∀⇩F z in uniformity. z ∈ B n" for n unfolding B(3) (*goal: ‹∃i. ∀z∈B i. z ∈ B n›*) by blast next (*goals: 1. ‹countably_generated_filter uniformity› 2. ‹⋀u. (⋀N m n. ⟦N ≤ m; N ≤ n⟧ ⟹ (u m, u n) ∈ B N) ⟹ convergent u› 3. ‹cauchy_filter F›*) fix f :: "nat ⇒ 'a" assume f: "⋀N m n. N ≤ m ⟹ N ≤ n ⟹ (f m, f n) ∈ B N" (*‹⟦(?N::nat) ≤ (?m::nat); ?N ≤ (?n::nat)⟧ ⟹ ((f::nat ⇒ 'a) ?m, f ?n) ∈ (B::nat ⇒ ('a × 'a) set) ?N›*) have "Cauchy f" using f (*‹⟦?N ≤ ?m; ?N ≤ ?n⟧ ⟹ (f ?m, f ?n) ∈ B ?N›*) B (*‹monotone (≤) (λx y. y ⊆ x) B› ‹uniformity = (INF n. principal (B n))› ‹eventually ?P uniformity = (∃i. ∀x∈B i. ?P x)›*) apply (intro controlled_seq_imp_Cauchy_seq[where U = B] (*‹⟦⋀P::'a × 'a ⇒ bool. eventually P uniformity ⟹ ∃n::nat. ∀x::'a × 'a∈(B::nat ⇒ ('a × 'a) set) n. P x; ⋀(N::nat) (m::nat) n::nat. ⟦N ≤ m; N ≤ n⟧ ⟹ ((?f::nat ⇒ 'a) m, ?f n) ∈ B N⟧ ⟹ Cauchy ?f›*)) (*goals: 1. ‹⋀P. ⟦⋀N m n. ⟦N ≤ m; N ≤ n⟧ ⟹ (f m, f n) ∈ B N; monotone (≤) (λx y. y ⊆ x) B; uniformity = (INF n. principal (B n)); ⋀P. eventually P uniformity = (∃i. ∀x∈B i. P x); eventually P uniformity⟧ ⟹ ∃n. ∀x∈B n. P x› 2. ‹⋀N m n. ⟦⋀N m n. ⟦N ≤ m; N ≤ n⟧ ⟹ (f m, f n) ∈ B N; monotone (≤) (λx y. y ⊆ x) B; uniformity = (INF n. principal (B n)); ⋀P. eventually P uniformity = (∃i. ∀x∈B i. P x); N ≤ m; N ≤ n⟧ ⟹ (f m, f n) ∈ B N› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . with conv (*‹Cauchy ?u ⟹ convergent ?u›*) show "convergent f" by simp qed ((fact)+) (*solves the remaining goals: 1. ‹countably_generated_filter uniformity› 2. ‹cauchy_filter F›*) qed theorem (in uniform_space) Cauchy_seq_convergent_imp_complete: fixes U :: "nat ⇒ ('a × 'a) set" assumes gen: "countably_generated_filter (uniformity :: ('a × 'a) filter)" assumes conv: "⋀(u :: nat ⇒ 'a). Cauchy u ⟹ convergent u" shows "class.complete_uniform_space open uniformity" apply unfold_locales (*goal: ‹class.complete_uniform_space open uniformity›*) by (use assms Cauchy_seq_convergent_imp_complete_aux in blast) lemma (in metric_space) countably_generated_uniformity: "countably_generated_filter uniformity" proof (-) (*goal: ‹countably_generated_filter uniformity›*) have "(INF e∈{0<..}. principal {(x, y). dist (x::'a) y < e}) = (INF n∈UNIV. principal {(x, y). dist x y < 1 / real (Suc n)})" (is "?F = ?G") unfolding uniformity_dist (*goal: ‹(INF e::real∈{0::real<..}. principal {(x::'a::type, y::'a::type). dist x y < e}) = (INF n::nat. principal {(x::'a::type, y::'a::type). dist x y < (1::real) / real (Suc n)})›*) proof (intro antisym (*‹⟦?a ≤ ?b; ?b ≤ ?a⟧ ⟹ ?a = ?b›*)) (*goals: 1. ‹(INF e∈{0<..}. principal {(x, y). dist x y < e}) ≤ (INF n. principal {(x, y). dist x y < 1 / real (Suc n)})› 2. ‹(INF n. principal {(x, y). dist x y < 1 / real (Suc n)}) ≤ (INF e∈{0<..}. principal {(x, y). dist x y < e})›*) have "?G = (INF e∈(λn. 1 / real (Suc n)) ` UNIV. principal {(x, y). dist x y < e})" by (simp add: image_image (*‹(?f::?'b::type ⇒ ?'a::type) ` (?g::?'c::type ⇒ ?'b::type) ` (?A::?'c::type set) = (λx::?'c::type. ?f (?g x)) ` ?A›*)) also (*calculation: ‹(INF n. principal {(x, y). dist x y < 1 / real (Suc n)}) = (INF e∈range (λn. 1 / real (Suc n)). principal {(x, y). dist x y < e})›*) have "… ≥ ?F" apply (intro INF_superset_mono (*‹⟦?B ⊆ ?A; ⋀x. x ∈ ?B ⟹ ?f x ≤ ?g x⟧ ⟹ Inf (?f ` ?A) ≤ Inf (?g ` ?B)›*)) (*goals: 1. ‹range (λn. 1 / real (Suc n)) ⊆ {0<..}› 2. ‹⋀e. e ∈ range (λn. 1 / real (Suc n)) ⟹ principal {(x, y). dist x y < e} ≤ principal {(x, y). dist x y < e}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . finally (*calculation: ‹(INF e∈{0<..}. principal {a. case a of (x, y) ⇒ dist x y < e}) ≤ (INF n. principal {(x, y). dist x y < 1 / real (Suc n)})›*) show "?F ≤ ?G" . next (*goal: ‹(INF n::nat. principal {(x::'a, y::'a). dist x y < (1::real) / real (Suc n)}) ≤ (INF e::real∈{0::real<..}. principal {(x::'a, y::'a). dist x y < e})›*) show "?G ≤ ?F" unfolding le_filter_def (*goal: ‹∀P. eventually P (INF e∈{0<..}. principal {(x, y). dist x y < e}) ⟶ eventually P (INF n. principal {(x, y). dist x y < 1 / real (Suc n)})›*) proof (safe) (*goal: ‹⋀P::'a::type × 'a::type ⇒ bool. eventually P (INF e::real∈{0::real<..}. principal {(x::'a::type, y::'a::type). dist x y < e}) ⟹ eventually P (INF n::nat. principal {(x::'a::type, y::'a::type). dist x y < (1::real) / real (Suc n)})›*) fix P assume "eventually P ?F" (*‹eventually (P::'a × 'a ⇒ bool) (INF e::real∈{0::real<..}. principal {(x::'a, y::'a). dist x y < e})›*) then obtain ε where "ε": "ε > 0" "eventually P (principal {(x, y). dist x y < ε})" (*goal: ‹(⋀ε. ⟦0 < ε; eventually P (principal {(x, y). dist x y < ε})⟧ ⟹ thesis) ⟹ thesis›*) proof (subst (asm) eventually_INF_base (*‹⟦?B ≠ {}; ⋀a b. ⟦a ∈ ?B; b ∈ ?B⟧ ⟹ ∃x∈?B. ?F x ≤ inf (?F a) (?F b)⟧ ⟹ eventually ?P (Inf (?F ` ?B)) = (∃b∈?B. eventually ?P (?F b))›*), goal_cases) (*goals: 1. ‹(⋀ε::real. ⟦(0::real) < ε; eventually (P::'a × 'a ⇒ bool) (principal {(x::'a, y::'a). dist x y < ε})⟧ ⟹ thesis::bool) ⟹ {0::real<..} ≠ {}› 2. ‹⋀(a::real) b::real. ⟦⋀ε::real. ⟦(0::real) < ε; eventually (P::'a × 'a ⇒ bool) (principal {(x::'a, y::'a). dist x y < ε})⟧ ⟹ thesis::bool; a ∈ {0::real<..}; b ∈ {0::real<..}⟧ ⟹ ∃x::real∈{0::real<..}. principal {(xa::'a, y::'a). dist xa y < x} ≤ inf (principal {(x::'a, y::'a). dist x y < a}) (principal {(x::'a, y::'a). dist x y < b})› 3. ‹⟦⋀ε::real. ⟦(0::real) < ε; eventually (P::'a × 'a ⇒ bool) (principal {(x::'a, y::'a). dist x y < ε})⟧ ⟹ thesis::bool; ∃b::real∈{0::real<..}. eventually P (principal {(x::'a, y::'a). dist x y < b})⟧ ⟹ thesis›*) case (2 ε1 ε2) (*‹⟦0 < ?ε; eventually P (principal {(x, y). dist x y < ?ε})⟧ ⟹ thesis› ‹ε1 ∈ {0<..}› ‹ε2 ∈ {0<..}›*) thus "?case" (*goal: ‹∃x∈{0<..}. principal {(xa, y). dist xa y < x} ≤ inf (principal {(x, y). dist x y < ε1}) (principal {(x, y). dist x y < ε2})›*) apply (intro bexI[of _ "min ε1 ε2"] (*‹⟦?P (min ε1 ε2); min ε1 ε2 ∈ ?A⟧ ⟹ ∃x∈?A. ?P x›*)) (*goals: 1. ‹⟦⋀ε. ⟦0 < ε; eventually P (principal {(x, y). dist x y < ε})⟧ ⟹ thesis; ε1 ∈ {0<..}; ε2 ∈ {0<..}⟧ ⟹ principal {(x, y). dist x y < min ε1 ε2} ≤ inf (principal {(x, y). dist x y < ε1}) (principal {(x, y). dist x y < ε2})› 2. ‹⟦⋀ε. ⟦0 < ε; eventually P (principal {(x, y). dist x y < ε})⟧ ⟹ thesis; ε1 ∈ {0<..}; ε2 ∈ {0<..}⟧ ⟹ min ε1 ε2 ∈ {0<..}› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed (auto) (*solves the remaining goals: 1. ‹(⋀ε. ⟦0 < ε; eventually P (principal {(x, y). dist x y < ε})⟧ ⟹ thesis) ⟹ {0<..} ≠ {}› 2. ‹⟦⋀ε. ⟦0 < ε; eventually P (principal {(x, y). dist x y < ε})⟧ ⟹ thesis; ∃b∈{0<..}. eventually P (principal {(x, y). dist x y < b})⟧ ⟹ thesis›*) from ‹ε > 0› (*‹0 < ε›*) obtain n where "1 / real (Suc n) < ε" (*goal: ‹(⋀n. 1 / real (Suc n) < ε ⟹ thesis) ⟹ thesis›*) using nat_approx_posE (*‹⟦0 < ?e; ⋀n. 1 / of_nat (Suc n) < ?e ⟹ ?thesis⟧ ⟹ ?thesis›*) by blast then have "eventually P (principal {(x, y). dist x y < 1 / real (Suc n)})" using "ε"(2) (*‹eventually P (principal {(x, y). dist x y < ε})›*) by (auto simp: eventually_principal (*‹eventually (?P::?'a ⇒ bool) (principal (?S::?'a set)) = (∀x::?'a∈?S. ?P x)›*)) thus "eventually P ?G" apply (intro eventually_INF1 (*‹⟦(?i::?'a) ∈ (?I::?'a set); eventually (?P::?'b ⇒ bool) ((?F::?'a ⇒ ?'b filter) ?i)⟧ ⟹ eventually ?P (Inf (?F ` ?I))›*)) (*goals: 1. ‹eventually P (principal {(x, y). dist x y < 1 / real (Suc n)}) ⟹ ?n1 ∈ UNIV› 2. ‹eventually P (principal {(x, y). dist x y < 1 / real (Suc n)}) ⟹ eventually P (principal {(x, y). dist x y < 1 / real (Suc ?n1)})› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed qed thus "countably_generated_filter uniformity" unfolding countably_generated_filter_def uniformity_dist (*goal: ‹∃U. (INF e∈{0<..}. principal {(x, y). dist x y < e}) = (INF n. principal (U n))›*) by fast qed subclass (in complete_space) complete_uniform_space proof (rule Cauchy_seq_convergent_imp_complete) show "convergent f" if "Cauchy f" for f using Cauchy_convergent that by blast qed (fact countably_generated_uniformity) lemma (in complete_uniform_space) complete_UNIV_cuspace [intro]: "complete UNIV" unfolding complete_uniform (*goal: ‹∀F≤principal UNIV. F ≠ bot ⟶ cauchy_filter F ⟶ (∃x∈UNIV. F ≤ nhds x)›*) using cauchy_filter_convergent (*‹cauchy_filter (?F::'a filter) ⟹ convergent_filter ?F›*) by (auto simp: convergent_filter.simps (*‹convergent_filter ?a = (∃F x. ?a = F ∧ F ≤ nhds x)›*)) lemma norm_infsum_le: assumes "(f has_sum S) X" assumes "(g has_sum T) X" assumes "⋀x. x ∈ X ⟹ norm (f x) ≤ g x" shows "norm S ≤ T" proof (rule tendsto_le (*‹⟦(?F::?'b filter) ≠ bot; ((?f::?'b ⇒ ?'a) ⤏ (?x::?'a)) ?F; ((?g::?'b ⇒ ?'a) ⤏ (?y::?'a)) ?F; ∀⇩F x::?'b in ?F. ?g x ≤ ?f x⟧ ⟹ ?y ≤ ?x›*)) (*goals: 1. ‹?F ≠ bot› 2. ‹(?f ⤏ T) ?F› 3. ‹(?g ⤏ norm S) ?F› 4. ‹∀⇩F x in ?F. ?g x ≤ ?f x›*) show "((λY. norm (∑x∈Y. f x)) ⤏ norm S) (finite_subsets_at_top X)" using assms(1) (*‹(f has_sum S) X›*) unfolding has_sum_def (*goal: ‹((λY. norm (sum f Y)) ⤏ norm S) (finite_subsets_at_top X)›*) by (intro tendsto_norm (*‹(?f ⤏ ?a) ?F ⟹ ((λx. norm (?f x)) ⤏ norm ?a) ?F›*)) show "((λY. ∑x∈Y. g x) ⤏ T) (finite_subsets_at_top X)" using assms(2) (*‹(g has_sum T) X›*) unfolding has_sum_def (*goal: ‹(sum g ⤏ T) (finite_subsets_at_top X)›*) . show "∀⇩F x in finite_subsets_at_top X. norm (sum f x) ≤ (∑x∈x. g x)" by (simp add: assms( (*‹?x ∈ X ⟹ norm (f ?x) ≤ g ?x›*) 3) eventually_finite_subsets_at_top_weakI (*‹(⋀X. ⟦finite X; X ⊆ ?A⟧ ⟹ ?P X) ⟹ eventually ?P (finite_subsets_at_top ?A)›*) subsetD (*‹⟦?A ⊆ ?B; ?c ∈ ?A⟧ ⟹ ?c ∈ ?B›*) sum_norm_le (*‹(⋀x. x ∈ ?S ⟹ norm (?f x) ≤ ?g x) ⟹ norm (sum ?f ?S) ≤ sum ?g ?S›*)) qed (auto) (*solved the remaining goal: ‹finite_subsets_at_top X ≠ bot›*) (* lemma summable_on_Sigma: fixes A :: "'a set" and B :: "'a ⇒ 'b set" and f :: ‹'a ⇒ 'b ⇒ 'c::{comm_monoid_add, t2_space, uniform_space}› assumes plus_cont: ‹uniformly_continuous_on UNIV (λ(x::'c,y). x+y)› assumes summableAB: "(λ(x,y). f x y) summable_on (Sigma A B)" assumes summableB: ‹⋀x. x∈A ⟹ (f x) summable_on (B x)› shows ‹(λx. infsum (f x) (B x)) summable_on A› *) lemma has_sum_imp_summable: "(f has_sum S) A ⟹ f summable_on A" by (auto simp: summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*)) lemma has_sum_reindex_bij_betw: assumes "bij_betw g A B" shows "((λx. f (g x)) has_sum S) A = (f has_sum S) B" proof (-) (*goal: ‹((λx. f (g x)) has_sum S) A = (f has_sum S) B›*) have "((λx. f (g x)) has_sum S) A ⟷ (f has_sum S) (g ` A)" apply (subst has_sum_reindex (*‹inj_on (?h::?'a ⇒ ?'b) (?A::?'a set) ⟹ ((?g::?'b ⇒ ?'c) has_sum (?x::?'c)) (?h ` ?A) = (?g ∘ ?h has_sum ?x) ?A›*)) (*goals: 1. ‹inj_on g A› 2. ‹((λx. f (g x)) has_sum S) A = (f ∘ g has_sum S) A› discuss goal 1*) apply ((use assms in ‹auto dest: bij_betw_imp_inj_on simp: o_def›)[1]) (*discuss goal 2*) apply ((use assms in ‹auto dest: bij_betw_imp_inj_on simp: o_def›)[1]) (*proven 2 subgoals*) . then show "?thesis" (*goal: ‹((λx. f (g x)) has_sum S) A = (f has_sum S) B›*) using assms (*‹bij_betw g A B›*) bij_betw_imp_surj_on (*‹bij_betw ?f ?A ?B ⟹ ?f ` ?A = ?B›*) by blast qed lemma has_sum_reindex_bij_witness: assumes "⋀a. a ∈ S ⟹ i (j a) = a" assumes "⋀a. a ∈ S ⟹ j a ∈ T" assumes "⋀b. b ∈ T ⟹ j (i b) = b" assumes "⋀b. b ∈ T ⟹ i b ∈ S" assumes "⋀a. a ∈ S ⟹ h (j a) = g a" assumes "s = s'" shows "(g has_sum s) S = (h has_sum s') T" by (smt (verit, del_insts) assms (*‹?a ∈ S ⟹ i (j ?a) = ?a› ‹?a ∈ S ⟹ j ?a ∈ T› ‹?b ∈ T ⟹ j (i ?b) = ?b› ‹?b ∈ T ⟹ i ?b ∈ S› ‹?a ∈ S ⟹ h (j ?a) = g ?a› ‹s = s'›*) bij_betwI' (*‹⟦⋀x y. ⟦x ∈ ?X; y ∈ ?X⟧ ⟹ (?f x = ?f y) = (x = y); ⋀x. x ∈ ?X ⟹ ?f x ∈ ?Y; ⋀y. y ∈ ?Y ⟹ ∃x∈?X. y = ?f x⟧ ⟹ bij_betw ?f ?X ?Y›*) has_sum_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ (?f has_sum ?x) ?A = (?g has_sum ?x) ?A›*) has_sum_reindex_bij_betw (*‹bij_betw ?g ?A ?B ⟹ ((λx. ?f (?g x)) has_sum ?S) ?A = (?f has_sum ?S) ?B›*)) lemma has_sum_homomorphism: assumes "(f has_sum S) A" "h 0 = 0" "⋀a b. h (a + b) = h a + h b" "continuous_on UNIV h" shows "((λx. h (f x)) has_sum (h S)) A" proof (-) (*goal: ‹((λx. h (f x)) has_sum h S) A›*) have "sum (h ∘ f) X = h (sum f X)" for X apply (induction X rule: infinite_finite_induct (*‹⟦⋀A::?'a set. infinite A ⟹ (?P::?'a set ⇒ bool) A; ?P {}; ⋀(x::?'a) F::?'a set. ⟦finite F; x ∉ F; ?P F⟧ ⟹ ?P (insert x F)⟧ ⟹ ?P (?A::?'a set)›*)) (*goals: 1. ‹⋀A::'a::type set. infinite A ⟹ sum ((h::'b::{comm_monoid_add,topological_space} ⇒ 'c::{comm_monoid_add,topological_space}) ∘ (f::'a::type ⇒ 'b::{comm_monoid_add,topological_space})) A = h (sum f A)› 2. ‹sum ((h::'b::{comm_monoid_add,topological_space} ⇒ 'c::{comm_monoid_add,topological_space}) ∘ (f::'a::type ⇒ 'b::{comm_monoid_add,topological_space})) {} = h (sum f {})› 3. ‹⋀(x::'a::type) F::'a::type set. ⟦finite F; x ∉ F; sum ((h::'b::{comm_monoid_add,topological_space} ⇒ 'c::{comm_monoid_add,topological_space}) ∘ (f::'a::type ⇒ 'b::{comm_monoid_add,topological_space})) F = h (sum f F)⟧ ⟹ sum (h ∘ f) (insert x F) = h (sum f (insert x F))› discuss goal 1*) apply (simp add: assms (*‹(f has_sum S) A› ‹h 0 = 0› ‹h (?a + ?b) = h ?a + h ?b› ‹continuous_on UNIV h›*)) (*discuss goal 2*) apply (simp add: assms (*‹(f has_sum S) A› ‹h 0 = 0› ‹h (?a + ?b) = h ?a + h ?b› ‹continuous_on UNIV h›*)) (*discuss goal 3*) apply (simp add: assms (*‹(f has_sum S) A› ‹h 0 = 0› ‹h (?a + ?b) = h ?a + h ?b› ‹continuous_on UNIV h›*)) (*proven 3 subgoals*) . hence sum_h: "sum (h ∘ f) = h ∘ sum f" apply (intro ext (*‹(⋀x. ?f x = ?g x) ⟹ ?f = ?g›*)) (*goal: ‹sum (h ∘ f) = h ∘ sum f›*) by auto then have "((h ∘ f) has_sum h S) A" using assms (*‹(f has_sum S) A› ‹h 0 = 0› ‹h (?a + ?b) = h ?a + h ?b› ‹continuous_on UNIV (h::'b::{comm_monoid_add,topological_space} ⇒ 'c::{comm_monoid_add,topological_space})›*) by (metis UNIV_I (*‹?x ∈ UNIV›*) continuous_on_def (*‹continuous_on ?s ?f = (∀x∈?s. (?f ⤏ ?f x) (at x within ?s))›*) has_sum_comm_additive_general (*‹⟦⋀F. ⟦finite F; F ⊆ ?S⟧ ⟹ sum (?f ∘ ?g) F = ?f (sum ?g F); ?f ─?x→ ?f ?x; (?g has_sum ?x) ?S⟧ ⟹ (?f ∘ ?g has_sum ?f ?x) ?S›*) o_apply (*‹(?f ∘ ?g) ?x = ?f (?g ?x)›*)) thus "?thesis" (*goal: ‹((λx. h (f x)) has_sum h S) A›*) by (simp add: o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*)) qed lemma summable_on_homomorphism: assumes "f summable_on A" "h 0 = 0" "⋀a b. h (a + b) = h a + h b" "continuous_on UNIV h" shows "(λx. h (f x)) summable_on A" proof (-) (*goal: ‹(λx. h (f x)) summable_on A›*) from assms(1) (*‹f summable_on A›*) obtain S where "(f has_sum S) A" (*goal: ‹(⋀S. (f has_sum S) A ⟹ thesis) ⟹ thesis›*) by (auto simp: summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*)) hence "((λx. h (f x)) has_sum h S) A" apply (rule has_sum_homomorphism (*‹⟦(?f has_sum ?S) ?A; ?h 0 = 0; ⋀a b. ?h (a + b) = ?h a + ?h b; continuous_on UNIV ?h⟧ ⟹ ((λx. ?h (?f x)) has_sum ?h ?S) ?A›*)) (*goals: 1. ‹h 0 = 0› 2. ‹⋀a b. h (a + b) = h a + h b› 3. ‹continuous_on UNIV h› discuss goal 1*) apply ((use assms in auto)[1]) (*discuss goal 2*) apply ((use assms in auto)[1]) (*discuss goal 3*) apply ((use assms in auto)[1]) (*proven 3 subgoals*) . thus "?thesis" (*goal: ‹(λx::'a. (h::'b ⇒ 'c) ((f::'a ⇒ 'b) x)) summable_on (A::'a set)›*) by (auto simp: summable_on_def (*‹(?f::?'a ⇒ ?'b) summable_on (?A::?'a set) ≡ ∃x::?'b. (?f has_sum x) ?A›*)) qed lemma infsum_homomorphism_strong: fixes h :: "'a :: {t2_space, topological_comm_monoid_add} ⇒ 'b :: {t2_space, topological_comm_monoid_add}" assumes "(λx. h (f x)) summable_on A ⟷ f summable_on A" assumes "h 0 = 0" assumes "⋀S. (f has_sum S) A ⟹ ((λx. h (f x)) has_sum (h S)) A" shows "infsum (λx. h (f x)) A = h (infsum f A)" by (metis assms (*‹((λx. h (f x)) summable_on A) = (f summable_on A)› ‹h 0 = 0› ‹(f has_sum ?S) A ⟹ ((λx. h (f x)) has_sum h ?S) A›*) has_sum_infsum (*‹?f summable_on ?S ⟹ (?f has_sum infsum ?f ?S) ?S›*) infsumI (*‹(?f has_sum ?x) ?A ⟹ infsum ?f ?A = ?x›*) infsum_not_exists (*‹¬ ?f summable_on ?A ⟹ infsum ?f ?A = 0›*)) lemma has_sum_bounded_linear: assumes "bounded_linear h" and "(f has_sum S) A" shows "((λx. h (f x)) has_sum h S) A" proof (-) (*goal: ‹((λx. h (f x)) has_sum h S) A›*) interpret bounded_linear h by fact from assms(2) (*‹(f has_sum S) A›*) show "?thesis" (*goal: ‹((λx::'c::type. (h::'a::real_normed_vector ⇒ 'b::real_normed_vector) ((f::'c::type ⇒ 'a::real_normed_vector) x)) has_sum h (S::'a::real_normed_vector)) (A::'c::type set)›*) apply (rule has_sum_homomorphism (*‹⟦(?f has_sum ?S) ?A; ?h 0 = 0; ⋀a b. ?h (a + b) = ?h a + ?h b; continuous_on UNIV ?h⟧ ⟹ ((λx. ?h (?f x)) has_sum ?h ?S) ?A›*)) (*goals: 1. ‹h 0 = 0› 2. ‹⋀a b. h (a + b) = h a + h b› 3. ‹continuous_on UNIV h› discuss goal 1*) apply ((auto simp: add (*‹(h::'a ⇒ 'b) ((?b1.0::'a) + (?b2.0::'a)) = h ?b1.0 + h ?b2.0›*) intro!: continuous_on (*‹continuous_on (?s::?'c set) (?g::?'c ⇒ 'a) ⟹ continuous_on ?s (λx::?'c. (h::'a ⇒ 'b) (?g x))›*))[1]) (*discuss goal 2*) apply ((auto simp: add (*‹(h::'a ⇒ 'b) ((?b1.0::'a) + (?b2.0::'a)) = h ?b1.0 + h ?b2.0›*) intro!: continuous_on (*‹continuous_on (?s::?'c set) (?g::?'c ⇒ 'a) ⟹ continuous_on ?s (λx::?'c. (h::'a ⇒ 'b) (?g x))›*))[1]) (*discuss goal 3*) apply ((auto simp: add (*‹h (?b1.0 + ?b2.0) = h ?b1.0 + h ?b2.0›*) intro!: continuous_on (*‹continuous_on ?s ?g ⟹ continuous_on ?s (λx. h (?g x))›*))[1]) (*proven 3 subgoals*) . qed lemma summable_on_bounded_linear: assumes "bounded_linear h" and "f summable_on A" shows "(λx. h (f x)) summable_on A" by (metis assms (*‹bounded_linear h› ‹f summable_on A›*) has_sum_bounded_linear (*‹⟦bounded_linear ?h; (?f has_sum ?S) ?A⟧ ⟹ ((λx. ?h (?f x)) has_sum ?h ?S) ?A›*) summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*)) lemma summable_on_bounded_linear_iff: assumes "bounded_linear h" and "bounded_linear h'" and "⋀x. h' (h x) = x" shows "(λx. h (f x)) summable_on A ⟷ f summable_on A" by (metis (full_types) assms (*‹bounded_linear h› ‹bounded_linear h'› ‹h' (h ?x) = ?x›*) summable_on_bounded_linear (*‹⟦bounded_linear ?h; ?f summable_on ?A⟧ ⟹ (λx. ?h (?f x)) summable_on ?A›*) summable_on_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ (?f summable_on ?A) = (?g summable_on ?A)›*)) lemma infsum_bounded_linear_strong: fixes h :: "'a :: real_normed_vector ⇒ 'b :: real_normed_vector" assumes "(λx. h (f x)) summable_on A ⟷ f summable_on A" assumes "bounded_linear h" shows "infsum (λx. h (f x)) A = h (infsum f A)" proof (-) (*goal: ‹(∑⇩∞x∈A. h (f x)) = h (infsum f A)›*) interpret bounded_linear h by fact show "?thesis" (*goal: ‹(∑⇩∞x∈A. h (f x)) = h (infsum f A)›*) apply (rule infsum_homomorphism_strong (*‹⟦((λx. ?h (?f x)) summable_on ?A) = (?f summable_on ?A); ?h 0 = 0; ⋀S. (?f has_sum S) ?A ⟹ ((λx. ?h (?f x)) has_sum ?h S) ?A⟧ ⟹ (∑⇩∞x∈?A. ?h (?f x)) = ?h (infsum ?f ?A)›*)) (*goals: 1. ‹((λx::'c::type. (h::'a::real_normed_vector ⇒ 'b::real_normed_vector) ((f::'c::type ⇒ 'a::real_normed_vector) x)) summable_on (A::'c::type set)) = (f summable_on A)› 2. ‹(h::'a::real_normed_vector ⇒ 'b::real_normed_vector) (0::'a::real_normed_vector) = (0::'b::real_normed_vector)› 3. ‹⋀S::'a::real_normed_vector. ((f::'c::type ⇒ 'a::real_normed_vector) has_sum S) (A::'c::type set) ⟹ ((λx::'c::type. (h::'a::real_normed_vector ⇒ 'b::real_normed_vector) (f x)) has_sum h S) A› discuss goal 1*) apply ((insert assms (*‹((λx. h (f x)) summable_on A) = (f summable_on A)› ‹bounded_linear h›*))[1]) (*top goal: ‹((λx::'c::type. (h::'a::real_normed_vector ⇒ 'b::real_normed_vector) ((f::'c::type ⇒ 'a::real_normed_vector) x)) summable_on (A::'c::type set)) = (f summable_on A)› and 2 goals remain*) apply ((auto intro: add (*‹(h::'a ⇒ 'b) ((?b1.0::'a) + (?b2.0::'a)) = h ?b1.0 + h ?b2.0›*) continuous_on (*‹continuous_on (?s::?'c set) (?g::?'c ⇒ 'a) ⟹ continuous_on ?s (λx::?'c. (h::'a ⇒ 'b) (?g x))›*) has_sum_bounded_linear (*‹⟦bounded_linear (?h::?'a ⇒ ?'b); ((?f::?'c ⇒ ?'a) has_sum (?S::?'a)) (?A::?'c set)⟧ ⟹ ((λx::?'c. ?h (?f x)) has_sum ?h ?S) ?A›*))[1]) (*discuss goal 2*) apply ((insert assms (*‹((λx::'c::type. (h::'a::real_normed_vector ⇒ 'b::real_normed_vector) ((f::'c::type ⇒ 'a::real_normed_vector) x)) summable_on (A::'c::type set)) = (f summable_on A)› ‹bounded_linear (h::'a::real_normed_vector ⇒ 'b::real_normed_vector)›*))[1]) (*top goal: ‹(h::'a ⇒ 'b) (0::'a) = (0::'b)› and 1 goal remains*) apply ((auto intro: add (*‹h (?b1.0 + ?b2.0) = h ?b1.0 + h ?b2.0›*) continuous_on (*‹continuous_on ?s ?g ⟹ continuous_on ?s (λx. h (?g x))›*) has_sum_bounded_linear (*‹⟦bounded_linear ?h; (?f has_sum ?S) ?A⟧ ⟹ ((λx. ?h (?f x)) has_sum ?h ?S) ?A›*))[1]) (*discuss goal 3*) apply ((insert assms (*‹((λx::'c. (h::'a ⇒ 'b) ((f::'c ⇒ 'a) x)) summable_on (A::'c set)) = (f summable_on A)› ‹bounded_linear (h::'a ⇒ 'b)›*))[1]) (*goal: ‹⋀S. (f has_sum S) A ⟹ ((λx. h (f x)) has_sum h S) A›*) apply ((auto intro: add (*‹h (?b1.0 + ?b2.0) = h ?b1.0 + h ?b2.0›*) continuous_on (*‹continuous_on ?s ?g ⟹ continuous_on ?s (λx. h (?g x))›*) has_sum_bounded_linear (*‹⟦bounded_linear ?h; (?f has_sum ?S) ?A⟧ ⟹ ((λx. ?h (?f x)) has_sum ?h ?S) ?A›*))[1]) (*proven 3 subgoals*) . qed lemma infsum_bounded_linear_strong': fixes mult :: "'c :: zero ⇒ 'a :: real_normed_vector ⇒ 'b :: real_normed_vector" assumes "c ≠ 0 ⟹ (λx. mult c (f x)) summable_on A ⟷ f summable_on A" assumes "bounded_linear (mult c)" assumes [simp]: "⋀x. mult 0 x = 0" shows "infsum (λx. mult c (f x)) A = mult c (infsum f A)" by (metis assms (*‹(c::'c) ≠ (0::'c) ⟹ ((λx::'d. (mult::'c ⇒ 'a ⇒ 'b) c ((f::'d ⇒ 'a) x)) summable_on (A::'d set)) = (f summable_on A)› ‹bounded_linear ((mult::'c ⇒ 'a ⇒ 'b) (c::'c))› ‹(mult::'c ⇒ 'a ⇒ 'b) (0::'c) (?x::'a) = (0::'b)›*) infsum_0 (*‹(⋀x::?'a. x ∈ (?M::?'a set) ⟹ (?f::?'a ⇒ ?'b) x = (0::?'b)) ⟹ infsum ?f ?M = (0::?'b)›*) infsum_bounded_linear_strong (*‹⟦((λx::?'c. (?h::?'a ⇒ ?'b) ((?f::?'c ⇒ ?'a) x)) summable_on (?A::?'c set)) = (?f summable_on ?A); bounded_linear ?h⟧ ⟹ (∑⇩∞x::?'c∈?A. ?h (?f x)) = ?h (infsum ?f ?A)›*)) lemma has_sum_of_nat: "(f has_sum S) A ⟹ ((λx. of_nat (f x)) has_sum of_nat S) A" apply (erule has_sum_homomorphism (*‹⟦(?f has_sum ?S) ?A; ?h 0 = 0; ⋀a b. ?h (a + b) = ?h a + ?h b; continuous_on UNIV ?h⟧ ⟹ ((λx. ?h (?f x)) has_sum ?h ?S) ?A›*)) (*goals: 1. ‹of_nat (0::nat) = (0::'b)› 2. ‹⋀(a::nat) b::nat. of_nat (a + b) = of_nat a + of_nat b› 3. ‹continuous_on UNIV of_nat› discuss goal 1*) apply ((auto intro!: continuous_intros (*‹open {}› ‹⟦open (?S::?'a set); open (?T::?'a set)⟧ ⟹ open (?S ∪ ?T)› ‹∀x::?'b∈?A::?'b set. open ((?B::?'b ⇒ ?'a set) x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite (?S::?'a set set); ∀T::?'a set∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite (?A::?'b set); ∀x::?'b∈?A. open ((?B::?'b ⇒ ?'a set) x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed (?S::?'a set); closed (?T::?'a set)⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed (?S::?'a set); closed (?T::?'a set)⟧ ⟹ closed (?S ∩ ?T)› ‹∀x::?'b∈?A::?'b set. closed ((?B::?'b ⇒ ?'a set) x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S::?'a set∈?K::?'a set set. closed S ⟹ closed (⋂ ?K)› ‹⟦finite (?S::?'a set set); ∀T::?'a set∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 144 facts*))[1]) (*discuss goal 2*) apply ((auto intro!: continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 144 facts*))[1]) (*discuss goal 3*) apply ((auto intro!: continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 144 facts*))[1]) (*proven 3 subgoals*) . lemma has_sum_of_int: "(f has_sum S) A ⟹ ((λx. of_int (f x)) has_sum of_int S) A" apply (erule has_sum_homomorphism (*‹⟦(?f has_sum ?S) ?A; ?h 0 = 0; ⋀a b. ?h (a + b) = ?h a + ?h b; continuous_on UNIV ?h⟧ ⟹ ((λx. ?h (?f x)) has_sum ?h ?S) ?A›*)) (*goals: 1. ‹of_int (0::int) = (0::'b::{ring_1,topological_space})› 2. ‹⋀(a::int) b::int. of_int (a + b) = of_int a + of_int b› 3. ‹continuous_on UNIV of_int› discuss goal 1*) apply ((auto intro!: continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 144 facts*))[1]) (*discuss goal 2*) apply ((auto intro!: continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 144 facts*))[1]) (*discuss goal 3*) apply ((auto intro!: continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 144 facts*))[1]) (*proven 3 subgoals*) . lemma summable_on_of_nat: "f summable_on A ⟹ (λx. of_nat (f x)) summable_on A" apply (erule summable_on_homomorphism (*‹⟦?f summable_on ?A; ?h 0 = 0; ⋀a b. ?h (a + b) = ?h a + ?h b; continuous_on UNIV ?h⟧ ⟹ (λx. ?h (?f x)) summable_on ?A›*)) (*goals: 1. ‹of_nat 0 = 0› 2. ‹⋀a b. of_nat (a + b) = of_nat a + of_nat b› 3. ‹continuous_on UNIV of_nat› discuss goal 1*) apply ((auto intro!: continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 144 facts*))[1]) (*discuss goal 2*) apply ((auto intro!: continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 144 facts*))[1]) (*discuss goal 3*) apply ((auto intro!: continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 144 facts*))[1]) (*proven 3 subgoals*) . lemma summable_on_of_int: "f summable_on A ⟹ (λx. of_int (f x)) summable_on A" apply (erule summable_on_homomorphism (*‹⟦?f summable_on ?A; ?h 0 = 0; ⋀a b. ?h (a + b) = ?h a + ?h b; continuous_on UNIV ?h⟧ ⟹ (λx. ?h (?f x)) summable_on ?A›*)) (*goals: 1. ‹of_int 0 = 0› 2. ‹⋀a b. of_int (a + b) = of_int a + of_int b› 3. ‹continuous_on UNIV of_int› discuss goal 1*) apply ((auto intro!: continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 144 facts*))[1]) (*discuss goal 2*) apply ((auto intro!: continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 144 facts*))[1]) (*discuss goal 3*) apply ((auto intro!: continuous_intros (*‹open {}› ‹⟦open ?S; open ?T⟧ ⟹ open (?S ∪ ?T)› ‹∀x∈?A. open (?B x) ⟹ open (⋃ (?B ` ?A))› ‹⟦finite ?S; ∀T∈?S. open T⟧ ⟹ open (⋂ ?S)› ‹⟦finite ?A; ∀x∈?A. open (?B x)⟧ ⟹ open (⋂ (?B ` ?A))› ‹closed {}› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∪ ?T)› ‹closed UNIV› ‹⟦closed ?S; closed ?T⟧ ⟹ closed (?S ∩ ?T)› ‹∀x∈?A. closed (?B x) ⟹ closed (⋂ (?B ` ?A))› ‹∀S∈?K. closed S ⟹ closed (⋂ ?K)› ‹⟦finite ?S; ∀T∈?S. closed T⟧ ⟹ closed (⋃ ?S)› and more 144 facts*))[1]) (*proven 3 subgoals*) . lemma summable_on_discrete_iff: fixes f :: "'a ⇒ 'b :: {discrete_topology, topological_comm_monoid_add, cancel_comm_monoid_add}" shows "f summable_on A ⟷ finite {x∈A. f x ≠ 0}" proof (standard) (*goals: 1. ‹f summable_on A ⟹ finite {x ∈ A. f x ≠ 0}› 2. ‹finite {x ∈ A. f x ≠ 0} ⟹ f summable_on A›*) assume "*": "finite {x∈A. f x ≠ 0}" (*‹finite {x::'a ∈ A::'a set. (f::'a ⇒ 'b) x ≠ (0::'b)}›*) hence "f summable_on {x∈A. f x ≠ 0}" by (rule summable_on_finite (*‹finite ?F ⟹ ?f summable_on ?F›*)) then show "f summable_on A" by (smt (verit) DiffE (*‹⟦(?c::?'a::type) ∈ (?A::?'a::type set) - (?B::?'a::type set); ⟦?c ∈ ?A; ?c ∉ ?B⟧ ⟹ ?P::bool⟧ ⟹ ?P›*) mem_Collect_eq (*‹((?a::?'a::type) ∈ Collect (?P::?'a::type ⇒ bool)) = ?P ?a›*) summable_on_cong_neutral (*‹⟦⋀x::?'a::type. x ∈ (?T::?'a::type set) - (?S::?'a::type set) ⟹ (?g::?'a::type ⇒ ?'b::{comm_monoid_add,topological_space}) x = (0::?'b::{comm_monoid_add,topological_space}); ⋀x::?'a::type. x ∈ ?S - ?T ⟹ (?f::?'a::type ⇒ ?'b::{comm_monoid_add,topological_space}) x = (0::?'b::{comm_monoid_add,topological_space}); ⋀x::?'a::type. x ∈ ?S ∩ ?T ⟹ ?f x = ?g x⟧ ⟹ (?f summable_on ?S) = (?g summable_on ?T)›*)) next (*goal: ‹(f::'a ⇒ 'b) summable_on (A::'a set) ⟹ finite {x::'a ∈ A. f x ≠ (0::'b)}›*) assume "f summable_on A" (*‹(f::'a ⇒ 'b) summable_on (A::'a set)›*) then obtain S where "(f has_sum S) A" (*goal: ‹(⋀S. (f has_sum S) A ⟹ thesis) ⟹ thesis›*) by (auto simp: summable_on_def (*‹(?f::?'a ⇒ ?'b) summable_on (?A::?'a set) ≡ ∃x::?'b. (?f has_sum x) ?A›*)) hence "∀⇩F x in finite_subsets_at_top A. sum f x = S" unfolding has_sum_def tendsto_discrete (*goal: ‹∀⇩F x in finite_subsets_at_top A. sum f x = S›*) . then obtain X where X: "finite X" "X ⊆ A" "⋀Y. finite Y ⟹ X ⊆ Y ⟹ Y ⊆ A ⟹ sum f Y = S" (*goal: ‹(⋀X. ⟦finite X; X ⊆ A; ⋀Y. ⟦finite Y; X ⊆ Y; Y ⊆ A⟧ ⟹ sum f Y = S⟧ ⟹ thesis) ⟹ thesis›*) unfolding eventually_finite_subsets_at_top (*goal: ‹(⋀X::'a set. ⟦finite X; X ⊆ (A::'a set); ⋀Y::'a set. ⟦finite Y; X ⊆ Y; Y ⊆ A⟧ ⟹ sum (f::'a ⇒ 'b) Y = (S::'b)⟧ ⟹ thesis::bool) ⟹ thesis›*) by metis have "{x∈A. f x ≠ 0} ⊆ X" proof (standard) (*goal: ‹⋀x. x ∈ {x ∈ A. f x ≠ 0} ⟹ x ∈ X›*) fix x assume x: "x ∈ {x∈A. f x ≠ 0}" (*‹(x::'a) ∈ {x::'a ∈ A::'a set. (f::'a ⇒ 'b) x ≠ (0::'b)}›*) show "x ∈ X" proof (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹x ∉ X ⟹ False›*) assume [simp]: "x ∉ X" (*‹(x::'a) ∉ (X::'a set)›*) have "sum f (insert x X) = S" using X (*‹finite (X::'a set)› ‹X ⊆ A› ‹⟦finite ?Y; X ⊆ ?Y; ?Y ⊆ A⟧ ⟹ sum f ?Y = S›*) x (*‹x ∈ {x ∈ A. f x ≠ 0}›*) apply (intro X (*‹finite X› ‹X ⊆ A› ‹⟦finite ?Y; X ⊆ ?Y; ?Y ⊆ A⟧ ⟹ sum f ?Y = S›*)) (*goals: 1. ‹⟦finite X; X ⊆ A; ⋀Y. ⟦finite Y; X ⊆ Y; Y ⊆ A⟧ ⟹ sum f Y = S; x ∈ {x ∈ A. f x ≠ 0}⟧ ⟹ finite (insert x X)› 2. ‹⟦finite X; X ⊆ A; ⋀Y. ⟦finite Y; X ⊆ Y; Y ⊆ A⟧ ⟹ sum f Y = S; x ∈ {x ∈ A. f x ≠ 0}⟧ ⟹ X ⊆ insert x X› 3. ‹⟦finite X; X ⊆ A; ⋀Y. ⟦finite Y; X ⊆ Y; Y ⊆ A⟧ ⟹ sum f Y = S; x ∈ {x ∈ A. f x ≠ 0}⟧ ⟹ insert x X ⊆ A› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . then have "f x = 0" using X (*‹finite X› ‹X ⊆ A› ‹⟦finite ?Y; X ⊆ ?Y; ?Y ⊆ A⟧ ⟹ sum f ?Y = S›*) by auto with x (*‹x ∈ {x ∈ A. f x ≠ 0}›*) show False by auto qed qed thus "finite {x∈A. f x ≠ 0}" using X(1) (*‹finite X›*) finite_subset (*‹⟦?A ⊆ ?B; finite ?B⟧ ⟹ finite ?A›*) by blast qed lemma has_sum_imp_sums: "(f has_sum S) (UNIV :: nat set) ⟹ f sums S" unfolding sums_def has_sum_def (*goal: ‹(sum f ⤏ S) (finite_subsets_at_top UNIV) ⟹ (λn. sum f {..<n}) ⇢ S›*) by (rule filterlim_compose[OF _ filterlim_lessThan_at_top] (*‹filterlim ?g ?F3.0 (finite_subsets_at_top UNIV) ⟹ LIM x sequentially. ?g {..<x} :> ?F3.0›*)) lemma summable_on_imp_summable: "f summable_on (UNIV :: nat set) ⟹ summable f" unfolding summable_on_def summable_def (*goal: ‹∃x::'a. ((f::nat ⇒ 'a) has_sum x) UNIV ⟹ Ex ((sums) f)›*) by (auto dest: has_sum_imp_sums (*‹(?f has_sum ?S) UNIV ⟹ ?f sums ?S›*)) lemma summable_on_UNIV_nonneg_real_iff: assumes "⋀n. f n ≥ (0 :: real)" shows "f summable_on UNIV ⟷ summable f" using assms (*‹0 ≤ f ?n›*) by (auto intro: norm_summable_imp_summable_on (*‹summable (λn. norm (?f n)) ⟹ ?f summable_on UNIV›*) summable_on_imp_summable (*‹?f summable_on UNIV ⟹ summable ?f›*)) lemma summable_on_imp_bounded_partial_sums: fixes f :: "_ ⇒ 'a :: {topological_comm_monoid_add, linorder_topology}" assumes f: "f summable_on A" shows "∃C. eventually (λX. sum f X ≤ C) (finite_subsets_at_top A)" proof (-) (*goal: ‹∃C. ∀⇩F X in finite_subsets_at_top A. sum f X ≤ C›*) from assms (*‹f summable_on A›*) obtain S where S: "(sum f ⤏ S) (finite_subsets_at_top A)" (*goal: ‹(⋀S. (sum f ⤏ S) (finite_subsets_at_top A) ⟹ thesis) ⟹ thesis›*) unfolding summable_on_def has_sum_def (*goal: ‹(⋀S::'a. (sum (f::'c ⇒ 'a) ⤏ S) (finite_subsets_at_top (A::'c set)) ⟹ thesis::bool) ⟹ thesis›*) by blast show "?thesis" (*goal: ‹∃C::'a::{topological_comm_monoid_add,linorder_topology}. ∀⇩F X::'c::type set in finite_subsets_at_top (A::'c::type set). sum (f::'c::type ⇒ 'a::{topological_comm_monoid_add,linorder_topology}) X ≤ C›*) proof (cases "∃C. C > S") (*goals: 1. ‹∃C::'a. (S::'a) < C ⟹ ∃C::'a. ∀⇩F X::'c set in finite_subsets_at_top (A::'c set). sum (f::'c ⇒ 'a) X ≤ C› 2. ‹∄C::'a. (S::'a) < C ⟹ ∃C::'a. ∀⇩F X::'c set in finite_subsets_at_top (A::'c set). sum (f::'c ⇒ 'a) X ≤ C›*) case True (*‹∃C. S < C›*) then obtain C where C: "C > S" (*goal: ‹(⋀C::'a. (S::'a) < C ⟹ thesis::bool) ⟹ thesis›*) by blast have "∀⇩F X in finite_subsets_at_top A. sum f X < C" using S (*‹(sum f ⤏ S) (finite_subsets_at_top A)›*) C (*‹S < C›*) by (rule order_tendstoD( (*‹⟦(?f ⤏ ?y) ?F; ?y < ?a⟧ ⟹ ∀⇩F x in ?F. ?f x < ?a›*) 2)) thus "?thesis" (*goal: ‹∃C::'a. ∀⇩F X::'c set in finite_subsets_at_top (A::'c set). sum (f::'c ⇒ 'a) X ≤ C›*) by (meson eventually_mono (*‹⟦eventually ?P ?F; ⋀x. ?P x ⟹ ?Q x⟧ ⟹ eventually ?Q ?F›*) nless_le (*‹(¬ ?a < ?b) = (¬ ?a ≤ ?b ∨ ?a = ?b)›*)) next (*goal: ‹∄C. S < C ⟹ ∃C. ∀⇩F X in finite_subsets_at_top A. sum f X ≤ C›*) case False (*‹∄C. S < C›*) thus "?thesis" (*goal: ‹∃C. ∀⇩F X in finite_subsets_at_top A. sum f X ≤ C›*) by (meson not_eventuallyD (*‹¬ eventually ?P ?F ⟹ ∃x. ¬ ?P x›*) not_le_imp_less (*‹¬ ?y ≤ ?x ⟹ ?x < ?y›*)) qed qed lemma has_sum_mono': fixes S S' :: "'a :: {linorder_topology, ordered_comm_monoid_add, topological_comm_monoid_add}" assumes f: "(f has_sum S) A" "(f has_sum S') B" and AB: "A ⊆ B" "⋀x. x ∈ B - A ⟹ f x ≥ 0" shows "S ≤ S'" using AB (*‹A ⊆ B› ‹?x ∈ B - A ⟹ 0 ≤ f ?x›*) has_sum_mono_neutral[OF f] (*‹⟦⋀x. x ∈ A ∩ B ⟹ f x ≤ f x; ⋀x. x ∈ A - B ⟹ f x ≤ 0; ⋀x. x ∈ B - A ⟹ 0 ≤ f x⟧ ⟹ S ≤ S'›*) by fastforce context assumes "SORT_CONSTRAINT('a :: {topological_comm_monoid_add, order_topology, ordered_comm_monoid_add, conditionally_complete_linorder})" begin text ‹ Any family of non-negative numbers with bounded partial sums is summable, and the sum is simply the supremum of the partial sums. › lemma nonneg_bounded_partial_sums_imp_has_sum_SUP: assumes nonneg: "⋀x. x ∈ A ⟹ f x ≥ (0::'a)" and bound: "eventually (λX. sum f X ≤ C) (finite_subsets_at_top A)" shows "(f has_sum (SUP X∈{X. X ⊆ A ∧ finite X}. sum f X)) A" proof (-) (*goal: ‹(f has_sum Sup (sum f ` {X. X ⊆ A ∧ finite X})) A›*) from bound (*‹∀⇩F X::'b::type set in finite_subsets_at_top (A::'b::type set). sum (f::'b::type ⇒ 'a::{conditionally_complete_linorder,ordered_comm_monoid_add,topological_comm_monoid_add,order_topology}) X ≤ (C::'a::{conditionally_complete_linorder,ordered_comm_monoid_add,topological_comm_monoid_add,order_topology})›*) obtain X0 where X0: "X0 ⊆ A" "finite X0" "⋀X. X0 ⊆ X ⟹ X ⊆ A ⟹ finite X ⟹ sum f X ≤ C" (*goal: ‹(⋀X0. ⟦X0 ⊆ A; finite X0; ⋀X. ⟦X0 ⊆ X; X ⊆ A; finite X⟧ ⟹ sum f X ≤ C⟧ ⟹ thesis) ⟹ thesis›*) by (force simp: eventually_finite_subsets_at_top (*‹eventually ?P (finite_subsets_at_top ?A) = (∃X. finite X ∧ X ⊆ ?A ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ ?A ⟶ ?P Y))›*)) have bound': "sum f X ≤ C" if "X ⊆ A" "finite X" for X proof (-) (*goal: ‹sum f X ≤ C›*) have "sum f X ≤ sum f (X ∪ X0)" using that (*‹(X::'b set) ⊆ (A::'b set)› ‹finite X›*) X0 (*‹X0 ⊆ A› ‹finite X0› ‹⟦X0 ⊆ ?X; ?X ⊆ A; finite ?X⟧ ⟹ sum f ?X ≤ C›*) assms(1) (*‹?x ∈ A ⟹ 0 ≤ f ?x›*) apply (intro sum_mono2 (*‹⟦finite ?B; ?A ⊆ ?B; ⋀b. b ∈ ?B - ?A ⟹ 0 ≤ ?f b⟧ ⟹ sum ?f ?A ≤ sum ?f ?B›*)) (*goals: 1. ‹⟦(X::'b set) ⊆ (A::'b set); finite X; (X0::'b set) ⊆ A; finite X0; ⋀X::'b set. ⟦X0 ⊆ X; X ⊆ A; finite X⟧ ⟹ sum (f::'b ⇒ 'a) X ≤ (C::'a); ⋀x::'b. x ∈ A ⟹ (0::'a) ≤ f x⟧ ⟹ finite (X ∪ X0)› 2. ‹⟦(X::'b set) ⊆ (A::'b set); finite X; (X0::'b set) ⊆ A; finite X0; ⋀X::'b set. ⟦X0 ⊆ X; X ⊆ A; finite X⟧ ⟹ sum (f::'b ⇒ 'a) X ≤ (C::'a); ⋀x::'b. x ∈ A ⟹ (0::'a) ≤ f x⟧ ⟹ X ⊆ X ∪ X0› 3. ‹⋀b::'b. ⟦(X::'b set) ⊆ (A::'b set); finite X; (X0::'b set) ⊆ A; finite X0; ⋀X::'b set. ⟦X0 ⊆ X; X ⊆ A; finite X⟧ ⟹ sum (f::'b ⇒ 'a) X ≤ (C::'a); ⋀x::'b. x ∈ A ⟹ (0::'a) ≤ f x; b ∈ X ∪ X0 - X⟧ ⟹ (0::'a) ≤ f b› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . also (*calculation: ‹sum f X ≤ sum f (X ∪ X0)›*) have "… ≤ C" by (simp add: X0 (*‹X0 ⊆ A› ‹finite X0› ‹⟦X0 ⊆ ?X; ?X ⊆ A; finite ?X⟧ ⟹ sum f ?X ≤ C›*) that (*‹X ⊆ A› ‹finite X›*)) finally (*calculation: ‹sum f X ≤ C›*) show "?thesis" (*goal: ‹sum f X ≤ C›*) . qed hence bdd: "bdd_above (sum f ` {X. X ⊆ A ∧ finite X})" by (auto simp: bdd_above_def (*‹bdd_above ?A = (∃M. ∀x∈?A. x ≤ M)›*)) show "?thesis" (*goal: ‹(f has_sum Sup (sum f ` {X. X ⊆ A ∧ finite X})) A›*) unfolding has_sum_def (*goal: ‹(sum f ⤏ Sup (sum f ` {X. X ⊆ A ∧ finite X})) (finite_subsets_at_top A)›*) proof (rule increasing_tendsto (*‹⟦∀⇩F n in ?F. ?f n ≤ ?l; ⋀x. x < ?l ⟹ ∀⇩F n in ?F. x < ?f n⟧ ⟹ (?f ⤏ ?l) ?F›*)) (*goals: 1. ‹∀⇩F n in finite_subsets_at_top A. sum f n ≤ Sup (sum f ` {X. X ⊆ A ∧ finite X})› 2. ‹⋀x. x < Sup (sum f ` {X. X ⊆ A ∧ finite X}) ⟹ ∀⇩F n in finite_subsets_at_top A. x < sum f n›*) show "∀⇩F X in finite_subsets_at_top A. sum f X ≤ Sup (sum f ` {X. X ⊆ A ∧ finite X})" apply (intro eventually_finite_subsets_at_top_weakI (*‹(⋀X. ⟦finite X; X ⊆ ?A⟧ ⟹ ?P X) ⟹ eventually ?P (finite_subsets_at_top ?A)›*) cSUP_upper[OF _ bdd] (*‹?x ∈ {X. X ⊆ A ∧ finite X} ⟹ sum f ?x ≤ Sup (sum f ` {X. X ⊆ A ∧ finite X})›*)) (*goal: ‹∀⇩F X in finite_subsets_at_top A. sum f X ≤ Sup (sum f ` {X. X ⊆ A ∧ finite X})›*) by auto next (*goal: ‹⋀x::'a::{conditionally_complete_linorder,ordered_comm_monoid_add,topological_comm_monoid_add,order_topology}. x < Sup (sum (f::'b::type ⇒ 'a::{conditionally_complete_linorder,ordered_comm_monoid_add,topological_comm_monoid_add,order_topology}) ` {X::'b::type set. X ⊆ (A::'b::type set) ∧ finite X}) ⟹ ∀⇩F n::'b::type set in finite_subsets_at_top A. x < sum f n›*) fix y assume "y < Sup (sum f ` {X. X ⊆ A ∧ finite X})" (*‹(y::'a) < Sup (sum (f::'b ⇒ 'a) ` {X::'b set. X ⊆ (A::'b set) ∧ finite X})›*) then obtain X where X: "X ⊆ A" "finite X" "y < sum f X" (*goal: ‹(⋀X. ⟦X ⊆ A; finite X; y < sum f X⟧ ⟹ thesis) ⟹ thesis›*) apply (subst (asm) less_cSUP_iff[OF _ bdd] (*‹{X. X ⊆ A ∧ finite X} ≠ {} ⟹ (?a < Sup (sum f ` {X. X ⊆ A ∧ finite X})) = (∃x∈{X. X ⊆ A ∧ finite X}. ?a < sum f x)›*)) (*goals: 1. ‹(⋀X. ⟦X ⊆ A; finite X; y < sum f X⟧ ⟹ thesis) ⟹ {X. X ⊆ A ∧ finite X} ≠ {}› 2. ‹⟦⋀X. ⟦X ⊆ A; finite X; y < sum f X⟧ ⟹ thesis; ∃x∈{X. X ⊆ A ∧ finite X}. y < sum f x⟧ ⟹ thesis› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . from X (*‹(X::'b set) ⊆ (A::'b set)› ‹finite X› ‹y < sum f X›*) have "eventually (λX'. X ⊆ X' ∧ X' ⊆ A ∧ finite X') (finite_subsets_at_top A)" by (auto simp: eventually_finite_subsets_at_top (*‹eventually ?P (finite_subsets_at_top ?A) = (∃X. finite X ∧ X ⊆ ?A ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ ?A ⟶ ?P Y))›*)) thus "eventually (λX'. y < sum f X') (finite_subsets_at_top A)" proof (eventually_elim) (*goal: ‹⋀X'. X ⊆ X' ∧ X' ⊆ A ∧ finite X' ⟹ y < sum f X'›*) case (elim X') (*‹X ⊆ X' ∧ X' ⊆ A ∧ finite X'›*) note ‹y < sum f X› (*‹y < sum f X›*) also (*calculation: ‹y < sum f X›*) have "sum f X ≤ sum f X'" using nonneg (*‹?x ∈ A ⟹ 0 ≤ f ?x›*) elim (*‹(X::'b set) ⊆ (X'::'b set) ∧ X' ⊆ (A::'b set) ∧ finite X'›*) apply (intro sum_mono2 (*‹⟦finite ?B; ?A ⊆ ?B; ⋀b. b ∈ ?B - ?A ⟹ 0 ≤ ?f b⟧ ⟹ sum ?f ?A ≤ sum ?f ?B›*)) (*goals: 1. ‹⟦⋀x::'b. x ∈ (A::'b set) ⟹ (0::'a) ≤ (f::'b ⇒ 'a) x; (X::'b set) ⊆ (X'::'b set) ∧ X' ⊆ A ∧ finite X'⟧ ⟹ finite X'› 2. ‹⟦⋀x::'b. x ∈ (A::'b set) ⟹ (0::'a) ≤ (f::'b ⇒ 'a) x; (X::'b set) ⊆ (X'::'b set) ∧ X' ⊆ A ∧ finite X'⟧ ⟹ X ⊆ X'› 3. ‹⋀b::'b. ⟦⋀x::'b. x ∈ (A::'b set) ⟹ (0::'a) ≤ (f::'b ⇒ 'a) x; (X::'b set) ⊆ (X'::'b set) ∧ X' ⊆ A ∧ finite X'; b ∈ X' - X⟧ ⟹ (0::'a) ≤ f b› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . finally (*calculation: ‹y < sum f X'›*) show "?case" (*goal: ‹(y::'a) < sum (f::'b ⇒ 'a) (X'::'b set)›*) . qed qed qed lemma nonneg_bounded_partial_sums_imp_summable_on: assumes nonneg: "⋀x. x ∈ A ⟹ f x ≥ (0::'a)" and bound: "eventually (λX. sum f X ≤ C) (finite_subsets_at_top A)" shows "f summable_on A" using nonneg_bounded_partial_sums_imp_has_sum_SUP[OF assms] (*‹(⋀x. x ∈ A ⟹ x ∈ A) ⟹ (f has_sum Sup (sum f ` {X. X ⊆ A ∧ finite X})) A›*) by (auto simp: summable_on_def (*‹(?f::?'a::type ⇒ ?'b::{comm_monoid_add,topological_space}) summable_on (?A::?'a::type set) ≡ ∃x::?'b::{comm_monoid_add,topological_space}. (?f has_sum x) ?A›*)) end context assumes "SORT_CONSTRAINT('a :: {topological_comm_monoid_add, linorder_topology, ordered_comm_monoid_add, conditionally_complete_linorder})" begin lemma summable_on_comparison_test: assumes "f summable_on A" and "⋀x. x ∈ A ⟹ g x ≤ f x" and "⋀x. x ∈ A ⟹ (0::'a) ≤ g x" shows "g summable_on A" proof (-) (*goal: ‹g summable_on A›*) obtain C where C: "∀⇩F X in finite_subsets_at_top A. sum f X ≤ C" (*goal: ‹(⋀C. ∀⇩F X in finite_subsets_at_top A. sum f X ≤ C ⟹ thesis) ⟹ thesis›*) using assms(1) (*‹f summable_on A›*) summable_on_imp_bounded_partial_sums (*‹?f summable_on ?A ⟹ ∃C. ∀⇩F X in finite_subsets_at_top ?A. sum ?f X ≤ C›*) by blast show "?thesis" (*goal: ‹g summable_on A›*) proof (rule nonneg_bounded_partial_sums_imp_summable_on (*‹⟦⋀x::?'b::type. x ∈ (?A::?'b::type set) ⟹ (0::?'a::{conditionally_complete_linorder,ordered_comm_monoid_add,topological_comm_monoid_add,order_topology}) ≤ (?f::?'b::type ⇒ ?'a::{conditionally_complete_linorder,ordered_comm_monoid_add,topological_comm_monoid_add,order_topology}) x; ∀⇩F X::?'b::type set in finite_subsets_at_top ?A. sum ?f X ≤ (?C::?'a::{conditionally_complete_linorder,ordered_comm_monoid_add,topological_comm_monoid_add,order_topology})⟧ ⟹ ?f summable_on ?A›*)) (*goals: 1. ‹⋀x. x ∈ A ⟹ 0 ≤ g x› 2. ‹∀⇩F X in finite_subsets_at_top A. sum g X ≤ ?C›*) show "∀⇩F X in finite_subsets_at_top A. sum g X ≤ C" using C (*‹∀⇩F X::'b set in finite_subsets_at_top (A::'b set). sum (f::'b ⇒ 'a) X ≤ (C::'a)›*) assms (*‹f summable_on A› ‹?x ∈ A ⟹ g ?x ≤ f ?x› ‹?x ∈ A ⟹ 0 ≤ g ?x›*) unfolding eventually_finite_subsets_at_top (*goal: ‹∃X::'b::type set. finite X ∧ X ⊆ (A::'b::type set) ∧ (∀Y::'b::type set. finite Y ∧ X ⊆ Y ∧ Y ⊆ A ⟶ sum (g::'b::type ⇒ 'a::{conditionally_complete_linorder,ordered_comm_monoid_add,topological_comm_monoid_add,linorder_topology}) Y ≤ (C::'a::{conditionally_complete_linorder,ordered_comm_monoid_add,topological_comm_monoid_add,linorder_topology}))›*) by (smt (verit, ccfv_SIG) order_trans (*‹⟦(?x::?'a::preorder) ≤ (?y::?'a::preorder); ?y ≤ (?z::?'a::preorder)⟧ ⟹ ?x ≤ ?z›*) subsetD (*‹⟦(?A::?'a::type set) ⊆ (?B::?'a::type set); (?c::?'a::type) ∈ ?A⟧ ⟹ ?c ∈ ?B›*) sum_mono (*‹(⋀i::?'b::type. i ∈ (?K::?'b::type set) ⟹ (?f::?'b::type ⇒ ?'a::ordered_comm_monoid_add) i ≤ (?g::?'b::type ⇒ ?'a::ordered_comm_monoid_add) i) ⟹ sum ?f ?K ≤ sum ?g ?K›*)) qed (use assms in auto) (*solved the remaining goal: ‹⋀x. x ∈ A ⟹ 0 ≤ g x›*) qed end lemma summable_on_subset: fixes f :: "_ ⇒ 'a :: {uniform_topological_group_add, topological_comm_monoid_add, ab_group_add, complete_uniform_space}" assumes "f summable_on A" "B ⊆ A" shows "f summable_on B" apply (rule summable_on_subset_aux[OF _ _ assms] (*‹⟦complete UNIV; uniformly_continuous_on UNIV (λ(x::'a::{ab_group_add,complete_uniform_space,topological_comm_monoid_add,uniform_topological_group_add}, y::'a::{ab_group_add,complete_uniform_space,topological_comm_monoid_add,uniform_topological_group_add}). x + y)⟧ ⟹ (f::'c::type ⇒ 'a::{ab_group_add,complete_uniform_space,topological_comm_monoid_add,uniform_topological_group_add}) summable_on (B::'c::type set)›*)) (*goals: 1. ‹complete UNIV› 2. ‹uniformly_continuous_on UNIV (λ(x, y). x + y)› discuss goal 1*) apply ((auto simp: uniformly_continuous_add (*‹uniformly_continuous_on UNIV (λ(x::?'a, y::?'a). x + y)›*))[1]) (*discuss goal 2*) apply ((auto simp: uniformly_continuous_add (*‹uniformly_continuous_on UNIV (λ(x, y). x + y)›*))[1]) (*proven 2 subgoals*) . lemma summable_on_union: fixes f :: "_ ⇒ 'a :: {uniform_topological_group_add, topological_comm_monoid_add, ab_group_add, complete_uniform_space}" assumes "f summable_on A" "f summable_on B" shows "f summable_on (A ∪ B)" proof (-) (*goal: ‹(f::'c ⇒ 'a) summable_on (A::'c set) ∪ (B::'c set)›*) have "f summable_on (A ∪ (B - A))" by (meson Diff_disjoint (*‹?A ∩ (?B - ?A) = {}›*) Diff_subset (*‹?A - ?B ⊆ ?A›*) assms (*‹f summable_on A› ‹f summable_on B›*) summable_on_Un_disjoint (*‹⟦?f summable_on ?A; ?f summable_on ?B; ?A ∩ ?B = {}⟧ ⟹ ?f summable_on ?A ∪ ?B›*) summable_on_subset (*‹⟦?f summable_on ?A; ?B ⊆ ?A⟧ ⟹ ?f summable_on ?B›*)) also (*calculation: ‹f summable_on A ∪ (B - A)›*) have "A ∪ (B - A) = A ∪ B" by blast finally (*calculation: ‹f summable_on A ∪ B›*) show "?thesis" (*goal: ‹f summable_on A ∪ B›*) . qed lemma summable_on_insert_iff: fixes f :: "_ ⇒ 'a :: {uniform_topological_group_add, topological_comm_monoid_add, ab_group_add, complete_uniform_space}" shows "f summable_on insert x A ⟷ f summable_on A" using summable_on_union[of f A "{x}"] (*‹⟦f summable_on A; f summable_on {x}⟧ ⟹ f summable_on A ∪ {x}›*) by (auto intro: summable_on_subset (*‹⟦?f summable_on ?A; ?B ⊆ ?A⟧ ⟹ ?f summable_on ?B›*)) lemma has_sum_finiteI: "finite A ⟹ S = sum f A ⟹ (f has_sum S) A" by simp lemma has_sum_insert: fixes f :: "'a ⇒ 'b :: topological_comm_monoid_add" assumes "x ∉ A" and "(f has_sum S) A" shows "(f has_sum (f x + S)) (insert x A)" proof (-) (*goal: ‹(f has_sum f x + S) (insert x A)›*) have "(f has_sum (f x + S)) ({x} ∪ A)" using assms (*‹x ∉ A› ‹(f has_sum S) A›*) apply (intro has_sum_Un_disjoint (*‹⟦(?f has_sum ?a) ?A; (?f has_sum ?b) ?B; ?A ∩ ?B = {}⟧ ⟹ (?f has_sum ?a + ?b) (?A ∪ ?B)›*)) (*goals: 1. ‹⟦x ∉ A; (f has_sum S) A⟧ ⟹ (f has_sum f x) {x}› 2. ‹⟦x ∉ A; (f has_sum S) A⟧ ⟹ (f has_sum S) A› 3. ‹⟦x ∉ A; (f has_sum S) A⟧ ⟹ {x} ∩ A = {}› discuss goal 1*) apply ((auto intro: has_sum_finiteI (*‹⟦finite ?A; ?S = sum ?f ?A⟧ ⟹ (?f has_sum ?S) ?A›*))[1]) (*discuss goal 2*) apply ((auto intro: has_sum_finiteI (*‹⟦finite ?A; ?S = sum ?f ?A⟧ ⟹ (?f has_sum ?S) ?A›*))[1]) (*discuss goal 3*) apply ((auto intro: has_sum_finiteI (*‹⟦finite ?A; ?S = sum ?f ?A⟧ ⟹ (?f has_sum ?S) ?A›*))[1]) (*proven 3 subgoals*) . thus "?thesis" (*goal: ‹(f has_sum f x + S) (insert x A)›*) by simp qed lemma infsum_insert: fixes f :: "_ ⇒ 'a :: {topological_comm_monoid_add, t2_space}" assumes "f summable_on A" "a ∉ A" shows "infsum f (insert a A) = f a + infsum f A" by (meson assms (*‹f summable_on A› ‹a ∉ A›*) has_sum_insert (*‹⟦?x ∉ ?A; (?f has_sum ?S) ?A⟧ ⟹ (?f has_sum ?f ?x + ?S) (insert ?x ?A)›*) infsumI (*‹(?f has_sum ?x) ?A ⟹ infsum ?f ?A = ?x›*) summable_iff_has_sum_infsum (*‹(?f summable_on ?A) = (?f has_sum infsum ?f ?A) ?A›*)) lemma has_sum_SigmaD: fixes f :: "'b × 'c ⇒ 'a :: {topological_comm_monoid_add,t3_space}" assumes sum1: "(f has_sum S) (Sigma A B)" assumes sum2: "⋀x. x ∈ A ⟹ ((λy. f (x, y)) has_sum g x) (B x)" shows "(g has_sum S) A" unfolding has_sum_def tendsto_def eventually_finite_subsets_at_top (*goal: ‹∀Sa::'a set. open Sa ⟶ (S::'a) ∈ Sa ⟶ (∃X::'b set. finite X ∧ X ⊆ (A::'b set) ∧ (∀Y::'b set. finite Y ∧ X ⊆ Y ∧ Y ⊆ A ⟶ sum (g::'b ⇒ 'a) Y ∈ Sa))›*) apply safe (*goal: ‹∀Sa. open Sa ⟶ S ∈ Sa ⟶ (∃X. finite X ∧ X ⊆ A ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ A ⟶ sum g Y ∈ Sa))›*) proof (goal_cases) (*goal: ‹⋀Sa::'a set. ⟦open Sa; (S::'a) ∈ Sa⟧ ⟹ ∃X::'b set. finite X ∧ X ⊆ (A::'b set) ∧ (∀Y::'b set. finite Y ∧ X ⊆ Y ∧ Y ⊆ A ⟶ sum (g::'b ⇒ 'a) Y ∈ Sa)›*) case (1 X) (*‹open X› ‹S ∈ X›*) with nhds_closed[of S X] (*‹⟦S ∈ X; open X⟧ ⟹ ∃A'. S ∈ A' ∧ closed A' ∧ A' ⊆ X ∧ (∀⇩F y in nhds S. y ∈ A')›*) obtain X' where X': "S ∈ X'" "closed X'" "X' ⊆ X" "eventually (λy. y ∈ X') (nhds S)" (*goal: ‹(⋀X'. ⟦S ∈ X'; closed X'; X' ⊆ X; ∀⇩F y in nhds S. y ∈ X'⟧ ⟹ thesis) ⟹ thesis›*) by blast from X'(4) (*‹∀⇩F y in nhds S. y ∈ X'›*) obtain X'' where X'': "S ∈ X''" "open X''" "X'' ⊆ X'" (*goal: ‹(⋀X''. ⟦S ∈ X''; open X''; X'' ⊆ X'⟧ ⟹ thesis) ⟹ thesis›*) by (auto simp: eventually_nhds (*‹eventually ?P (nhds ?a) = (∃S. open S ∧ ?a ∈ S ∧ (∀x∈S. ?P x))›*)) with sum1 (*‹(f has_sum S) (Sigma A B)›*) obtain Y :: "('b × 'c) set" where Y: "Y ⊆ Sigma A B" "finite Y" "⋀Z. Y ⊆ Z ⟹ Z ⊆ Sigma A B ⟹ finite Z ⟹ sum f Z ∈ X''" (*goal: ‹(⋀Y. ⟦Y ⊆ Sigma A B; finite Y; ⋀Z. ⟦Y ⊆ Z; Z ⊆ Sigma A B; finite Z⟧ ⟹ sum f Z ∈ X''⟧ ⟹ thesis) ⟹ thesis›*) unfolding has_sum_def tendsto_def eventually_finite_subsets_at_top (*goal: ‹(⋀Y. ⟦Y ⊆ Sigma A B; finite Y; ⋀Z. ⟦Y ⊆ Z; Z ⊆ Sigma A B; finite Z⟧ ⟹ sum f Z ∈ X''⟧ ⟹ thesis) ⟹ thesis›*) by force define Y1 :: "'b set" where "Y1 = fst ` Y" from Y (*‹Y ⊆ Sigma A B› ‹finite Y› ‹⟦Y ⊆ ?Z; ?Z ⊆ Sigma A B; finite ?Z⟧ ⟹ sum f ?Z ∈ X''›*) have Y1: "Y1 ⊆ A" by (auto simp: Y1_def (*‹Y1 = fst ` Y›*)) define Y2 :: "'b ⇒ 'c set" where "Y2 = (λx. {y. (x, y) ∈ Y})" have Y2: "finite (Y2 x)" "Y2 x ⊆ B x" if "x ∈ A" for x using that (*‹(x::'b) ∈ (A::'b set)›*) Y(1,2) (*‹Y ⊆ Sigma A B› ‹finite Y›*) unfolding Y2_def (*goals: 1. ‹finite {y. (x, y) ∈ Y}› 2. ‹{y. (x, y) ∈ Y} ⊆ B x›*) apply - (*goals: 1. ‹⟦x ∈ A; Y ⊆ Sigma A B; finite Y⟧ ⟹ finite {y. (x, y) ∈ Y}› 2. ‹⟦x ∈ A; Y ⊆ Sigma A B; finite Y⟧ ⟹ {y. (x, y) ∈ Y} ⊆ B x› discuss goal 1*) apply (force simp: image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*) intro: finite_subset[of _ "snd ` Y"] (*‹⟦?A ⊆ snd ` Y; finite (snd ` Y)⟧ ⟹ finite ?A›*)) (*discuss goal 2*) apply (force simp: image_iff (*‹(?z ∈ ?f ` ?A) = (∃x∈?A. ?z = ?f x)›*) intro: finite_subset[of _ "snd ` Y"] (*‹⟦?A ⊆ snd ` Y; finite (snd ` Y)⟧ ⟹ finite ?A›*)) (*proven 2 subgoals*) . show "?case" (*goal: ‹∃Xa. finite Xa ∧ Xa ⊆ A ∧ (∀Y. finite Y ∧ Xa ⊆ Y ∧ Y ⊆ A ⟶ sum g Y ∈ X)›*) proof (rule exI[of _ Y1] (*‹?P Y1 ⟹ ∃x. ?P x›*), safe, goal_cases) (*goals: 1. ‹finite Y1› 2. ‹⋀x. x ∈ Y1 ⟹ x ∈ A› 3. ‹⋀Y. ⟦finite Y; Y1 ⊆ Y; Y ⊆ A⟧ ⟹ sum g Y ∈ X›*) case (3 Z) (*‹finite (Z::'b::type set)› ‹(Y1::'b set) ⊆ (Z::'b set)› ‹(Z::'b set) ⊆ (A::'b set)›*) define H where "H = (INF x∈Z. filtercomap (λp. p x) (finite_subsets_at_top (B x)))" have "sum g Z ∈ X'" proof (rule Lim_in_closed_set (*‹⟦closed ?S; ∀⇩F x in ?F. ?f x ∈ ?S; ?F ≠ bot; (?f ⤏ ?l) ?F⟧ ⟹ ?l ∈ ?S›*)) (*goals: 1. ‹closed X'› 2. ‹∀⇩F x in ?F. ?f x ∈ X'› 3. ‹?F ≠ bot› 4. ‹(?f ⤏ sum g Z) ?F›*) show "closed X'" by fact next (*goals: 1. ‹∀⇩F x::?'b in ?F::?'b filter. (?f::?'b ⇒ 'a) x ∈ (X'::'a set)› 2. ‹(?F::?'b filter) ≠ bot› 3. ‹((?f::?'b ⇒ 'a) ⤏ sum (g::'b ⇒ 'a) (Z::'b set)) (?F::?'b filter)›*) show "((λB'. sum (λx. sum (λy. f (x, y)) (B' x)) Z) ⤏ sum g Z) H" unfolding H_def (*goal: ‹((λB'::'b ⇒ 'c set. ∑x::'b∈(Z::'b set). ∑y::'c∈B' x. (f::'b × 'c ⇒ 'a) (x, y)) ⤏ sum (g::'b ⇒ 'a) Z) (INF x::'b∈Z. filtercomap (λp::'b ⇒ 'c set. p x) (finite_subsets_at_top ((B::'b ⇒ 'c set) x)))›*) proof (intro tendsto_sum (*‹(⋀i. i ∈ ?I ⟹ (?f i ⤏ ?a i) ?F) ⟹ ((λx. ∑i∈?I. ?f i x) ⤏ sum ?a ?I) ?F›*) filterlim_INF' (*‹⟦?x ∈ ?A; filterlim ?f ?F (?G ?x)⟧ ⟹ filterlim ?f ?F (Inf (?G ` ?A))›*)) (*goals: 1. ‹⋀x::'b. x ∈ (Z::'b set) ⟹ (?x1::'b ⇒ 'b) x ∈ Z› 2. ‹⋀x::'b. x ∈ (Z::'b set) ⟹ ((λxa::'b ⇒ 'c set. ∑y::'c∈xa x. (f::'b × 'c ⇒ 'a) (x, y)) ⤏ (g::'b ⇒ 'a) x) (filtercomap (λp::'b ⇒ 'c set. p ((?x1::'b ⇒ 'b) x)) (finite_subsets_at_top ((B::'b ⇒ 'c set) (?x1 x))))›*) fix x assume x: "x ∈ Z" (*‹(x::'b) ∈ (Z::'b set)›*) with "3" (*‹finite Z› ‹Y1 ⊆ Z› ‹(Z::'b set) ⊆ (A::'b set)›*) have "x ∈ A" by auto from sum2[OF this] (*‹((λy. f (x, y)) has_sum g x) (B x)›*) have "(sum (λy. f (x, y)) ⤏ g x) (finite_subsets_at_top (B x))" by (simp add: has_sum_def (*‹(?f has_sum ?x) ?A ≡ (sum ?f ⤏ ?x) (finite_subsets_at_top ?A)›*)) thus "((λB'. sum (λy. f (x, y)) (B' x)) ⤏ g x) (filtercomap (λp. p x) (finite_subsets_at_top (B x)))" by (rule filterlim_compose[OF _ filterlim_filtercomap] (*‹filterlim ?g ?F3.0 ?F2.0 ⟹ LIM x filtercomap ?f ?F2.0. ?g (?f x) :> ?F3.0›*)) qed (auto) (*solved the remaining goal: ‹⋀x. x ∈ Z ⟹ x ∈ Z›*) next (*goals: 1. ‹∀⇩F x in H. (∑xa∈Z. ∑y∈x xa. f (xa, y)) ∈ X'› 2. ‹H ≠ bot›*) show "∀⇩F h in H. sum (λx. sum (λy. f (x, y)) (h x)) Z ∈ X'" unfolding H_def (*goal: ‹∀⇩F h in INF x∈Z. filtercomap (λp. p x) (finite_subsets_at_top (B x)). (∑x∈Z. ∑y∈h x. f (x, y)) ∈ X'›*) proof (subst eventually_INF_finite[OF ‹finite Z›] (*‹eventually ?P (Inf (?F ` Z)) = (∃Q. (∀x∈Z. eventually (Q x) (?F x)) ∧ (∀y. (∀x∈Z. Q x y) ⟶ ?P y))›*), rule exI (*‹?P ?x ⟹ ∃x. ?P x›*), safe) (*goals: 1. ‹⋀x::'b. x ∈ (Z::'b set) ⟹ eventually ((?Q::'b ⇒ ('b ⇒ 'c set) ⇒ bool) x) (filtercomap (λp::'b ⇒ 'c set. p x) (finite_subsets_at_top ((B::'b ⇒ 'c set) x)))› 2. ‹⋀y::'b ⇒ 'c set. ∀x::'b∈Z::'b set. (?Q::'b ⇒ ('b ⇒ 'c set) ⇒ bool) x y ⟹ (∑x::'b∈Z. ∑y::'c∈y x. (f::'b × 'c ⇒ 'a) (x, y)) ∈ (X'::'a set)›*) fix x assume x: "x ∈ Z" (*‹(x::'b) ∈ (Z::'b set)›*) hence x': "x ∈ A" using "3" (*‹finite Z› ‹Y1 ⊆ Z› ‹(Z::'b::type set) ⊆ (A::'b::type set)›*) by auto show "eventually (λh. finite (h x) ∧ Y2 x ⊆ h x ∧ h x ⊆ B x) (filtercomap (λp. p x) (finite_subsets_at_top (B x)))" using "3" (*‹finite Z› ‹(Y1::'b set) ⊆ (Z::'b set)› ‹Z ⊆ A›*) Y2[OF x'] (*‹finite (Y2 x)› ‹Y2 x ⊆ B x›*) apply (intro eventually_filtercomapI (*‹eventually ?P ?F ⟹ ∀⇩F x in filtercomap ?f ?F. ?P (?f x)›*)) (*goal: ‹∀⇩F h in filtercomap (λp. p x) (finite_subsets_at_top (B x)). finite (h x) ∧ Y2 x ⊆ h x ∧ h x ⊆ B x›*) by (auto simp: eventually_finite_subsets_at_top (*‹eventually ?P (finite_subsets_at_top ?A) = (∃X. finite X ∧ X ⊆ ?A ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ ?A ⟶ ?P Y))›*) intro: exI[of _ "Y2 x"] (*‹?P (Y2 x) ⟹ ∃x. ?P x›*)) next (*goal: ‹⋀y::'b::type ⇒ 'c::type set. ∀x::'b::type∈Z::'b::type set. finite (y x) ∧ (Y2::'b::type ⇒ 'c::type set) x ⊆ y x ∧ y x ⊆ (B::'b::type ⇒ 'c::type set) x ⟹ (∑x::'b::type∈Z. ∑y::'c::type∈y x. (f::'b::type × 'c::type ⇒ 'a::{topological_comm_monoid_add,t3_space}) (x, y)) ∈ (X'::'a::{topological_comm_monoid_add,t3_space} set)›*) fix h assume "*": "∀x∈Z. finite (h x) ∧ Y2 x ⊆ h x ∧ h x ⊆ B x" (*‹∀x::'b∈Z::'b set. finite ((h::'b ⇒ 'c set) x) ∧ (Y2::'b ⇒ 'c set) x ⊆ h x ∧ h x ⊆ (B::'b ⇒ 'c set) x›*) hence "sum (λx. sum (λy. f (x, y)) (h x)) Z = sum f (Sigma Z h)" using ‹finite Z› (*‹finite Z›*) apply (subst sum.Sigma (*‹⟦finite (?A::?'b set); ∀x::?'b∈?A. finite ((?B::?'b ⇒ ?'c set) x)⟧ ⟹ (∑x::?'b∈?A. sum ((?g::?'b ⇒ ?'c ⇒ ?'a) x) (?B x)) = (∑(x::?'b, y::?'c)∈Sigma ?A ?B. ?g x y)›*)) (*goals: 1. ‹⟦∀x∈Z. finite (h x) ∧ Y2 x ⊆ h x ∧ h x ⊆ B x; finite Z⟧ ⟹ finite Z› 2. ‹⟦∀x∈Z. finite (h x) ∧ Y2 x ⊆ h x ∧ h x ⊆ B x; finite Z⟧ ⟹ ∀x∈Z. finite (h x)› 3. ‹⟦∀x∈Z. finite (h x) ∧ Y2 x ⊆ h x ∧ h x ⊆ B x; finite Z⟧ ⟹ (∑(x, y)∈Sigma Z h. f (x, y)) = sum f (Sigma Z h)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . also (*calculation: ‹(∑x∈Z. ∑y∈h x. f (x, y)) = sum f (Sigma Z h)›*) have "… ∈ X''" using "*" (*‹∀x∈Z. finite (h x) ∧ Y2 x ⊆ h x ∧ h x ⊆ B x›*) "3" (*‹finite Z› ‹(Y1::'b::type set) ⊆ (Z::'b::type set)› ‹Z ⊆ A›*) Y(1,2) (*‹(Y::('b::type × 'c::type) set) ⊆ Sigma (A::'b::type set) (B::'b::type ⇒ 'c::type set)› ‹finite Y›*) apply (intro Y (*‹Y ⊆ Sigma A B› ‹finite Y› ‹⟦Y ⊆ ?Z; ?Z ⊆ Sigma A B; finite ?Z⟧ ⟹ sum f ?Z ∈ X''›*)) (*goals: 1. ‹⟦∀x∈Z. finite (h x) ∧ Y2 x ⊆ h x ∧ h x ⊆ B x; finite Z; Y1 ⊆ Z; Z ⊆ A; Y ⊆ Sigma A B; finite Y⟧ ⟹ Y ⊆ Sigma Z h› 2. ‹⟦∀x∈Z. finite (h x) ∧ Y2 x ⊆ h x ∧ h x ⊆ B x; finite Z; Y1 ⊆ Z; Z ⊆ A; Y ⊆ Sigma A B; finite Y⟧ ⟹ Sigma Z h ⊆ Sigma A B› 3. ‹⟦∀x∈Z. finite (h x) ∧ Y2 x ⊆ h x ∧ h x ⊆ B x; finite Z; Y1 ⊆ Z; Z ⊆ A; Y ⊆ Sigma A B; finite Y⟧ ⟹ finite (Sigma Z h)› discuss goal 1*) apply (force simp: Y1_def (*‹Y1 = fst ` Y›*) Y2_def (*‹Y2 = (λx. {y. (x, y) ∈ Y})›*)) (*discuss goal 2*) apply (force simp: Y1_def (*‹(Y1::'b::type set) = fst ` (Y::('b::type × 'c::type) set)›*) Y2_def (*‹(Y2::'b::type ⇒ 'c::type set) = (λx::'b::type. {y::'c::type. (x, y) ∈ (Y::('b::type × 'c::type) set)})›*)) (*discuss goal 3*) apply (force simp: Y1_def (*‹Y1 = fst ` Y›*) Y2_def (*‹Y2 = (λx. {y. (x, y) ∈ Y})›*)) (*proven 3 subgoals*) . also (*calculation: ‹(∑x∈Z. ∑y∈h x. f (x, y)) ∈ X''›*) have "X'' ⊆ X'" by fact finally (*calculation: ‹(∑x::'b∈(Z::'b set). ∑y::'c∈(h::'b ⇒ 'c set) x. (f::'b × 'c ⇒ 'a) (x, y)) ∈ (X'::'a set)›*) show "sum (λx. sum (λy. f (x, y)) (h x)) Z ∈ X'" . qed next (*goal: ‹H ≠ bot›*) have "H = (INF x∈SIGMA x:Z. {X. finite X ∧ X ⊆ B x}. principal {y. finite (y (fst x)) ∧ snd x ⊆ y (fst x) ∧ y (fst x) ⊆ B (fst x)})" unfolding H_def finite_subsets_at_top_def filtercomap_INF filtercomap_principal (*goal: ‹(INF x∈Z. INF b∈{X. finite X ∧ X ⊆ B x}. principal ((λp. p x) -` {Y. finite Y ∧ b ⊆ Y ∧ Y ⊆ B x})) = (INF x∈SIGMA x:Z. {X. finite X ∧ X ⊆ B x}. principal {y. finite (y (fst x)) ∧ snd x ⊆ y (fst x) ∧ y (fst x) ⊆ B (fst x)})›*) by (simp add: INF_Sigma (*‹(INF i∈?A. Inf (?f i ` ?B i)) = (INF p∈Sigma ?A ?B. ?f (fst p) (snd p))›*)) also (*calculation: ‹(H::('b::type ⇒ 'c::type set) filter) = (INF x::'b::type × 'c::type set∈SIGMA x::'b::type:Z::'b::type set. {X::'c::type set. finite X ∧ X ⊆ B x}. principal {y::'b::type ⇒ 'c::type set. finite (y (fst x)) ∧ snd x ⊆ y (fst x) ∧ y (fst x) ⊆ (B::'b::type ⇒ 'c::type set) (fst x)})›*) have "… ≠ bot" proof (rule INF_filter_not_bot (*‹(⋀X::?'i set. ⟦X ⊆ (?B::?'i set); finite X⟧ ⟹ Inf ((?F::?'i ⇒ ?'a filter) ` X) ≠ bot) ⟹ Inf (?F ` ?B) ≠ bot›*), subst INF_principal_finite (*‹finite ?X ⟹ (INF x∈?X. principal (?f x)) = principal (⋂ (?f ` ?X))›*), goal_cases) (*goals: 1. ‹⋀X. ⟦X ⊆ (SIGMA x:Z. {X. finite X ∧ X ⊆ B x}); finite X⟧ ⟹ finite X› 2. ‹⋀X. ⟦X ⊆ (SIGMA x:Z. {X. finite X ∧ X ⊆ B x}); finite X⟧ ⟹ principal (⋂x∈X. {y. finite (y (fst x)) ∧ snd x ⊆ y (fst x) ∧ y (fst x) ⊆ B (fst x)}) ≠ bot›*) case (2 X) (*‹X ⊆ (SIGMA x:Z. {X. finite X ∧ X ⊆ B x})› ‹finite X›*) define H' where "H' = (⋂x∈X. {y. finite (y (fst x)) ∧ snd x ⊆ y (fst x) ∧ y (fst x) ⊆ B (fst x)})" from "2" (*‹X ⊆ (SIGMA x:Z. {X. finite X ∧ X ⊆ B x})› ‹finite X›*) have "(λx. ⋃(y,Y)∈X. if x = y then Y else {}) ∈ H'" by (force split: if_splits (*‹?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))› ‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*) simp: H'_def (*‹H' = (⋂x∈X. {y. finite (y (fst x)) ∧ snd x ⊆ y (fst x) ∧ y (fst x) ⊆ B (fst x)})›*)) hence "H' ≠ {}" by blast thus "principal H' ≠ bot" by (simp add: principal_eq_bot_iff (*‹(principal ?X = bot) = (?X = {})›*)) qed finally (*calculation: ‹H ≠ bot›*) show "H ≠ bot" . qed also (*calculation: ‹sum (g::'b::type ⇒ 'a::{topological_comm_monoid_add,t3_space}) (Z::'b::type set) ∈ (X'::'a::{topological_comm_monoid_add,t3_space} set)›*) have "X' ⊆ X" by fact finally (*calculation: ‹sum (g::'b ⇒ 'a) (Z::'b set) ∈ (X::'a set)›*) show "sum g Z ∈ X" . qed (insert Y( (*‹Y ⊆ Sigma A B› ‹finite Y›*) 1,2), auto simp: Y1_def (*‹Y1 = fst ` Y›*)) (*solves the remaining goals: 1. ‹finite (Y1::'b set)› 2. ‹⋀x::'b. x ∈ (Y1::'b set) ⟹ x ∈ (A::'b set)›*) qed lemma has_sum_unique: fixes f :: "_ ⇒ 'a :: {topological_comm_monoid_add, t2_space}" assumes "(f has_sum x) A" "(f has_sum y) A" shows "x = y" using assms (*‹(f has_sum x) A› ‹(f has_sum y) A›*) unfolding has_sum_def (*goal: ‹x = y›*) using tendsto_unique (*‹⟦?F ≠ bot; (?f ⤏ ?a) ?F; (?f ⤏ ?b) ?F⟧ ⟹ ?a = ?b›*) finite_subsets_at_top_neq_bot (*‹finite_subsets_at_top ?A ≠ bot›*) by blast lemma has_sum_SigmaI: fixes f :: "_ ⇒ 'a :: {topological_comm_monoid_add, t3_space}" assumes f: "⋀x. x ∈ A ⟹ ((λy. f (x, y)) has_sum g x) (B x)" assumes g: "(g has_sum S) A" assumes summable: "f summable_on Sigma A B" shows "(f has_sum S) (Sigma A B)" by (metis f (*‹?x ∈ A ⟹ ((λy. f (?x, y)) has_sum g ?x) (B ?x)›*) g (*‹(g has_sum S) A›*) has_sum_SigmaD (*‹⟦(?f has_sum ?S) (Sigma ?A ?B); ⋀x. x ∈ ?A ⟹ ((λy. ?f (x, y)) has_sum ?g x) (?B x)⟧ ⟹ (?g has_sum ?S) ?A›*) has_sum_infsum (*‹?f summable_on ?S ⟹ (?f has_sum infsum ?f ?S) ?S›*) has_sum_unique (*‹⟦(?f has_sum ?x) ?A; (?f has_sum ?y) ?A⟧ ⟹ ?x = ?y›*) local.summable (*‹f summable_on Sigma A B›*)) lemma summable_on_SigmaD1: fixes f :: "_ ⇒ _ ⇒ 'a :: {complete_uniform_space, uniform_topological_group_add, ab_group_add, topological_comm_monoid_add}" assumes f: "(λ(x,y). f x y) summable_on Sigma A B" assumes x: "x ∈ A" shows "f x summable_on B x" proof (-) (*goal: ‹f x summable_on B x›*) have "(λ(x,y). f x y) summable_on Sigma {x} B" using f (*‹(λ(x, y). f x y) summable_on Sigma A B›*) apply (rule summable_on_subset (*‹⟦?f summable_on ?A; ?B ⊆ ?A⟧ ⟹ ?f summable_on ?B›*)) (*goal: ‹(λ(x, y). f x y) summable_on Sigma {x} B›*) by (use x in auto) also (*calculation: ‹(λ(x::'d, y::'e). (f::'d ⇒ 'e ⇒ 'a) x y) summable_on Sigma {x::'d} (B::'d ⇒ 'e set)›*) have "?this ⟷ ((λy. f x y) ∘ snd) summable_on Sigma {x} B" apply (intro summable_on_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ (?f summable_on ?A) = (?g summable_on ?A)›*)) (*goal: ‹((λ(x, y). f x y) summable_on Sigma {x} B) = (f x ∘ snd summable_on Sigma {x} B)›*) by auto also (*calculation: ‹f x ∘ snd summable_on Sigma {x} B›*) have "… ⟷ (λy. f x y) summable_on snd ` Sigma {x} B" apply (intro summable_on_reindex [symmetric] (*‹inj_on (?h::?'a ⇒ ?'b) (?A::?'a set) ⟹ ((?g::?'b ⇒ ?'c) ∘ ?h summable_on ?A) = (?g summable_on ?h ` ?A)›*) inj_onI (*‹(⋀(x::?'a) y::?'a. ⟦x ∈ (?A::?'a set); y ∈ ?A; (?f::?'a ⇒ ?'b) x = ?f y⟧ ⟹ x = y) ⟹ inj_on ?f ?A›*)) (*goal: ‹((f::'d::type ⇒ 'e::type ⇒ 'a::{ab_group_add,complete_uniform_space,topological_comm_monoid_add,uniform_topological_group_add}) (x::'d::type) ∘ snd summable_on Sigma {x} (B::'d::type ⇒ 'e::type set)) = (f x summable_on snd ` Sigma {x} B)›*) by auto also (*calculation: ‹f x summable_on snd ` Sigma {x} B›*) have "snd ` Sigma {x} B = B x" by (force simp: Sigma_def (*‹Sigma ?A ?B ≡ ⋃x∈?A. ⋃y∈?B x. {(x, y)}›*)) finally (*calculation: ‹f x summable_on B x›*) show "?thesis" (*goal: ‹f x summable_on B x›*) . qed lemma has_sum_swap: "(f has_sum S) (A × B) ⟷ ((λ(x,y). f (y,x)) has_sum S) (B × A)" proof (-) (*goal: ‹((f::'a × 'b ⇒ 'c) has_sum (S::'c)) ((A::'a set) × (B::'b set)) = ((λ(x::'b, y::'a). f (y, x)) has_sum S) (B × A)›*) have "bij_betw (λ(x,y). (y,x)) (B × A) (A × B)" apply (rule bij_betwI[of _ _ _ "λ(x,y). (y,x)"] (*‹⟦?f ∈ ?A → ?B; (λ(x, y). (y, x)) ∈ ?B → ?A; ⋀x. x ∈ ?A ⟹ (case ?f x of (x, y) ⇒ (y, x)) = x; ⋀y. y ∈ ?B ⟹ ?f (case y of (x, y) ⇒ (y, x)) = y⟧ ⟹ bij_betw ?f ?A ?B›*)) (*goals: 1. ‹(λ(x, y). (y, x)) ∈ B × A → A × B› 2. ‹(λ(x, y). (y, x)) ∈ A × B → B × A› 3. ‹⋀x. x ∈ B × A ⟹ (case case x of (x, y) ⇒ (y, x) of (x, y) ⇒ (y, x)) = x› 4. ‹⋀y. y ∈ A × B ⟹ (case case y of (x, y) ⇒ (y, x) of (x, y) ⇒ (y, x)) = y› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . from has_sum_reindex_bij_betw[OF this, where f = f] (*‹((λx::'b × 'a. (f::'a × 'b ⇒ 'c) (case x of (x::'b, y::'a) ⇒ (y, x))) has_sum (?S::'c)) ((B::'b set) × (A::'a set)) = (f has_sum ?S) (A × B)›*) show "?thesis" (*goal: ‹((f::'a × 'b ⇒ 'c) has_sum (S::'c)) ((A::'a set) × (B::'b set)) = ((λ(x::'b, y::'a). f (y, x)) has_sum S) (B × A)›*) by (simp add: case_prod_unfold (*‹case_prod = (λ(c::?'a ⇒ ?'b ⇒ ?'c) p::?'a × ?'b. c (fst p) (snd p))›*)) qed lemma summable_on_swap: "f summable_on (A × B) ⟷ (λ(x,y). f (y,x)) summable_on (B × A)" by (metis has_sum_swap (*‹(?f has_sum ?S) (?A × ?B) = ((λ(x, y). ?f (y, x)) has_sum ?S) (?B × ?A)›*) summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*)) lemma has_sum_cmult_right_iff: fixes c :: "'a :: {topological_semigroup_mult, field}" assumes "c ≠ 0" shows "((λx. c * f x) has_sum S) A ⟷ (f has_sum (S / c)) A" using has_sum_cmult_right[of f A "S/c" c] (*‹(f has_sum S / c) A ⟹ ((λx. c * f x) has_sum c * (S / c)) A›*) has_sum_cmult_right[of "λx. c * f x" A S "inverse c"] (*‹((λx. c * f x) has_sum S) A ⟹ ((λx. inverse c * (c * f x)) has_sum inverse c * S) A›*) assms (*‹c ≠ 0›*) by (auto simp: field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 69 facts*)) lemma has_sum_cmult_left_iff: fixes c :: "'a :: {topological_semigroup_mult, field}" assumes "c ≠ 0" shows "((λx. f x * c) has_sum S) A ⟷ (f has_sum (S / c)) A" by (smt (verit, best) assms (*‹c ≠ 0›*) has_sum_cmult_right_iff (*‹?c ≠ 0 ⟹ ((λx. ?c * ?f x) has_sum ?S) ?A = (?f has_sum ?S / ?c) ?A›*) has_sum_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ (?f has_sum ?x) ?A = (?g has_sum ?x) ?A›*) mult.commute (*‹?a * ?b = ?b * ?a›*)) lemma finite_nonzero_values_imp_summable_on: assumes "finite {x∈X. f x ≠ 0}" shows "f summable_on X" by (smt (verit, del_insts) Diff_iff (*‹(?c ∈ ?A - ?B) = (?c ∈ ?A ∧ ?c ∉ ?B)›*) assms (*‹finite {x ∈ X. f x ≠ 0}›*) mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*) summable_on_cong_neutral (*‹⟦⋀x. x ∈ ?T - ?S ⟹ ?g x = 0; ⋀x. x ∈ ?S - ?T ⟹ ?f x = 0; ⋀x. x ∈ ?S ∩ ?T ⟹ ?f x = ?g x⟧ ⟹ (?f summable_on ?S) = (?g summable_on ?T)›*) summable_on_finite (*‹finite ?F ⟹ ?f summable_on ?F›*)) lemma summable_on_of_int_iff: "(λx::'a. of_int (f x) :: 'b :: real_normed_algebra_1) summable_on A ⟷ f summable_on A" proof (standard) (*goals: 1. ‹(λx. of_int (f x)) summable_on A ⟹ f summable_on A› 2. ‹f summable_on A ⟹ (λx. of_int (f x)) summable_on A›*) assume "f summable_on A" (*‹(f::'a ⇒ int) summable_on (A::'a set)›*) thus "(λx. of_int (f x)) summable_on A" apply (rule summable_on_homomorphism (*‹⟦?f summable_on ?A; ?h 0 = 0; ⋀a b. ?h (a + b) = ?h a + ?h b; continuous_on UNIV ?h⟧ ⟹ (λx. ?h (?f x)) summable_on ?A›*)) (*goals: 1. ‹of_int 0 = 0› 2. ‹⋀a b. of_int (a + b) = of_int a + of_int b› 3. ‹continuous_on UNIV of_int› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . next (*goal: ‹(λx. of_int (f x)) summable_on A ⟹ f summable_on A›*) assume "(λx. of_int (f x) :: 'b) summable_on A" (*‹(λx::'a. of_int ((f::'a ⇒ int) x)) summable_on (A::'a set)›*) then obtain S where "((λx. of_int (f x) :: 'b) has_sum S) A" (*goal: ‹(⋀S. ((λx. of_int (f x)) has_sum S) A ⟹ thesis) ⟹ thesis›*) by (auto simp: summable_on_def (*‹?f summable_on ?A ≡ ∃x. (?f has_sum x) ?A›*)) hence "(sum (λx. of_int (f x) :: 'b) ⤏ S) (finite_subsets_at_top A)" unfolding has_sum_def (*goal: ‹(sum (λx. of_int (f x)) ⤏ S) (finite_subsets_at_top A)›*) . moreover have "1/2 > (0 :: real)" by auto ultimately have "eventually (λX. dist (sum (λx. of_int (f x) :: 'b) X) S < 1/2) (finite_subsets_at_top A)" unfolding tendsto_iff (*goal: ‹∀⇩F X in finite_subsets_at_top A. dist (∑x∈X. of_int (f x)) S < 1 / 2›*) by blast then obtain X where X: "finite X" "X ⊆ A" "⋀Y. finite Y ⟹ X ⊆ Y ⟹ Y ⊆ A ⟹ dist (sum (λx. of_int (f x)) Y) S < 1/2" (*goal: ‹(⋀X. ⟦finite X; X ⊆ A; ⋀Y. ⟦finite Y; X ⊆ Y; Y ⊆ A⟧ ⟹ dist (∑x∈Y. of_int (f x)) S < 1 / 2⟧ ⟹ thesis) ⟹ thesis›*) unfolding eventually_finite_subsets_at_top (*goal: ‹(⋀X::'a set. ⟦finite X; X ⊆ (A::'a set); ⋀Y::'a set. ⟦finite Y; X ⊆ Y; Y ⊆ A⟧ ⟹ dist (∑x::'a∈Y. of_int ((f::'a ⇒ int) x)) (S::'b) < (1::real) / (2::real)⟧ ⟹ thesis::bool) ⟹ thesis›*) by metis have "sum f Y = sum f X" if "finite Y" "X ⊆ Y" "Y ⊆ A" for Y proof (-) (*goal: ‹sum (f::'a ⇒ int) (Y::'a set) = sum f (X::'a set)›*) have "dist (sum (λx. of_int (f x)) X) S < 1/2" apply (intro X (*‹finite X› ‹X ⊆ A› ‹⟦finite ?Y; X ⊆ ?Y; ?Y ⊆ A⟧ ⟹ dist (∑x∈?Y. of_int (f x)) S < 1 / 2›*)) (*goal: ‹dist (∑x::'a∈(X::'a set). of_int ((f::'a ⇒ int) x)) (S::'b) < (1::real) / (2::real)›*) by auto moreover have "dist (sum (λx. of_int (f x)) Y) S < 1/2" by (intro X (*‹finite X› ‹X ⊆ A› ‹⟦finite ?Y; X ⊆ ?Y; ?Y ⊆ A⟧ ⟹ dist (∑x∈?Y. of_int (f x)) S < 1 / 2›*) that (*‹finite Y› ‹X ⊆ Y› ‹Y ⊆ A›*)) ultimately have "dist (sum (λx. of_int (f x)) X) (sum (λx. of_int (f x) :: 'b) Y) < 1/2 + 1/2" using dist_triangle_less_add (*‹⟦dist ?x1.0 ?y < ?e1.0; dist ?x2.0 ?y < ?e2.0⟧ ⟹ dist ?x1.0 ?x2.0 < ?e1.0 + ?e2.0›*) by blast thus "?thesis" (*goal: ‹sum (f::'a::type ⇒ int) (Y::'a::type set) = sum f (X::'a::type set)›*) by (simp add: dist_norm (*‹dist ?x ?y = norm (?x - ?y)›*) flip: of_int_sum (*‹of_int (sum ?f ?A) = (∑x∈?A. of_int (?f x))›*) of_int_diff (*‹of_int (?w - ?z) = of_int ?w - of_int ?z›*)) qed then have "{x∈A. f x ≠ 0} ⊆ X" by (smt (verit) X (*‹finite X› ‹X ⊆ A› ‹⟦finite ?Y; X ⊆ ?Y; ?Y ⊆ A⟧ ⟹ dist (∑x∈?Y. of_int (f x)) S < 1 / 2›*) finite_insert (*‹finite (insert ?a ?A) = finite ?A›*) insert_iff (*‹(?a ∈ insert ?b ?A) = (?a = ?b ∨ ?a ∈ ?A)›*) mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*) subset_eq (*‹(?A ⊆ ?B) = (∀x∈?A. x ∈ ?B)›*) sum.insert (*‹⟦finite ?A; ?x ∉ ?A⟧ ⟹ sum ?g (insert ?x ?A) = ?g ?x + sum ?g ?A›*)) with ‹finite X› (*‹finite X›*) have "finite {x∈A. f x ≠ 0}" using finite_subset (*‹⟦(?A::?'a::type set) ⊆ (?B::?'a::type set); finite ?B⟧ ⟹ finite ?A›*) by blast thus "f summable_on A" by (rule finite_nonzero_values_imp_summable_on (*‹finite {x::?'a::type ∈ ?X::?'a::type set. (?f::?'a::type ⇒ ?'b::{comm_monoid_add,topological_space}) x ≠ (0::?'b::{comm_monoid_add,topological_space})} ⟹ ?f summable_on ?X›*)) qed lemma summable_on_of_nat_iff: "(λx::'a. of_nat (f x) :: 'b :: real_normed_algebra_1) summable_on A ⟷ f summable_on A" proof (standard) (*goals: 1. ‹(λx::'a. of_nat ((f::'a ⇒ nat) x)) summable_on (A::'a set) ⟹ f summable_on A› 2. ‹(f::'a ⇒ nat) summable_on (A::'a set) ⟹ (λx::'a. of_nat (f x)) summable_on A›*) assume "f summable_on A" (*‹(f::'a ⇒ nat) summable_on (A::'a set)›*) thus "(λx. of_nat (f x) :: 'b) summable_on A" apply (rule summable_on_homomorphism (*‹⟦?f summable_on ?A; ?h 0 = 0; ⋀a b. ?h (a + b) = ?h a + ?h b; continuous_on UNIV ?h⟧ ⟹ (λx. ?h (?f x)) summable_on ?A›*)) (*goals: 1. ‹of_nat 0 = 0› 2. ‹⋀a b. of_nat (a + b) = of_nat a + of_nat b› 3. ‹continuous_on UNIV of_nat› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . next (*goal: ‹(λx. of_nat (f x)) summable_on A ⟹ f summable_on A›*) assume "(λx. of_nat (f x) :: 'b) summable_on A" (*‹(λx::'a. of_nat ((f::'a ⇒ nat) x)) summable_on (A::'a set)›*) hence "(λx. of_int (int (f x)) :: 'b) summable_on A" by simp also (*calculation: ‹(λx::'a::type. of_int (int ((f::'a::type ⇒ nat) x))) summable_on (A::'a::type set)›*) have "?this ⟷ (λx. int (f x)) summable_on A" by (rule summable_on_of_int_iff (*‹((λx::?'a. of_int ((?f::?'a ⇒ int) x)) summable_on (?A::?'a set)) = (?f summable_on ?A)›*)) also (*calculation: ‹(λx. int (f x)) summable_on A›*) have "… ⟷ f summable_on A" by (simp add: summable_on_discrete_iff (*‹(?f summable_on ?A) = finite {x ∈ ?A. ?f x ≠ 0}›*)) finally (*calculation: ‹f summable_on A›*) show "f summable_on A" . qed lemma infsum_of_nat: "infsum (λx::'a. of_nat (f x) :: 'b :: {real_normed_algebra_1}) A = of_nat (infsum f A)" by (metis has_sum_infsum (*‹?f summable_on ?S ⟹ (?f has_sum infsum ?f ?S) ?S›*) has_sum_of_nat (*‹(?f has_sum ?S) ?A ⟹ ((λx. of_nat (?f x)) has_sum of_nat ?S) ?A›*) infsumI (*‹(?f has_sum ?x) ?A ⟹ infsum ?f ?A = ?x›*) infsum_def (*‹infsum ?f ?A = (if ?f summable_on ?A then Lim (finite_subsets_at_top ?A) (sum ?f) else 0)›*) of_nat_0 (*‹of_nat 0 = 0›*) summable_on_of_nat_iff (*‹((λx. of_nat (?f x)) summable_on ?A) = (?f summable_on ?A)›*)) lemma infsum_of_int: "infsum (λx::'a. of_int (f x) :: 'b :: {real_normed_algebra_1}) A = of_int (infsum f A)" by (metis has_sum_infsum (*‹(?f::?'a ⇒ ?'b) summable_on (?S::?'a set) ⟹ (?f has_sum infsum ?f ?S) ?S›*) has_sum_of_int (*‹((?f::?'a ⇒ int) has_sum (?S::int)) (?A::?'a set) ⟹ ((λx::?'a. of_int (?f x)) has_sum of_int ?S) ?A›*) infsumI (*‹((?f::?'a ⇒ ?'b) has_sum (?x::?'b)) (?A::?'a set) ⟹ infsum ?f ?A = ?x›*) infsum_not_exists (*‹¬ (?f::?'a ⇒ ?'b) summable_on (?A::?'a set) ⟹ infsum ?f ?A = (0::?'b)›*) of_int_0 (*‹of_int (0::int) = (0::?'a)›*) summable_on_of_int_iff (*‹((λx::?'a. of_int ((?f::?'a ⇒ int) x)) summable_on (?A::?'a set)) = (?f summable_on ?A)›*)) lemma summable_on_SigmaI: fixes f :: "_ ⇒ 'a :: {linorder_topology, ordered_comm_monoid_add, topological_comm_monoid_add, conditionally_complete_linorder}" assumes f: "⋀x. x ∈ A ⟹ ((λy. f (x, y)) has_sum g x) (B x)" assumes g: "g summable_on A" assumes f_nonneg: "⋀x y. x ∈ A ⟹ y ∈ B x ⟹ f (x, y) ≥ (0 :: 'a)" shows "f summable_on Sigma A B" proof (-) (*goal: ‹f summable_on Sigma A B›*) have g_nonneg: "g x ≥ 0" if "x ∈ A" for x using f (*‹?x ∈ A ⟹ ((λy. f (?x, y)) has_sum g ?x) (B ?x)›*) apply (rule has_sum_nonneg (*‹⟦(?f has_sum ?a) ?M; ⋀x. x ∈ ?M ⟹ 0 ≤ ?f x⟧ ⟹ 0 ≤ ?a›*)) (*goals: 1. ‹x ∈ A› 2. ‹⋀xa. xa ∈ B x ⟹ 0 ≤ f (x, xa)› discuss goal 1*) apply ((use f_nonneg that in auto)[1]) (*discuss goal 2*) apply ((use f_nonneg that in auto)[1]) (*proven 2 subgoals*) . obtain C where C: "eventually (λX. sum g X ≤ C) (finite_subsets_at_top A)" (*goal: ‹(⋀C. ∀⇩F X in finite_subsets_at_top A. sum g X ≤ C ⟹ thesis) ⟹ thesis›*) using summable_on_imp_bounded_partial_sums[OF g] (*‹∃C. ∀⇩F X in finite_subsets_at_top A. sum g X ≤ C›*) by blast have sum_g_le: "sum g X ≤ C" if X: "finite X" "X ⊆ A" for X proof (-) (*goal: ‹sum g X ≤ C›*) from C (*‹∀⇩F X in finite_subsets_at_top A. sum g X ≤ C›*) obtain X' where X': "finite X'" "X' ⊆ A" "⋀Y. finite Y ⟹ X' ⊆ Y ⟹ Y ⊆ A ⟹ sum g Y ≤ C" (*goal: ‹(⋀X'. ⟦finite X'; X' ⊆ A; ⋀Y. ⟦finite Y; X' ⊆ Y; Y ⊆ A⟧ ⟹ sum g Y ≤ C⟧ ⟹ thesis) ⟹ thesis›*) unfolding eventually_finite_subsets_at_top (*goal: ‹(⋀X'. ⟦finite X'; X' ⊆ A; ⋀Y. ⟦finite Y; X' ⊆ Y; Y ⊆ A⟧ ⟹ sum g Y ≤ C⟧ ⟹ thesis) ⟹ thesis›*) by metis have "sum g X ≤ sum g (X ∪ X')" using X (*‹finite X› ‹X ⊆ A›*) X' (*‹finite X'› ‹X' ⊆ A› ‹⟦finite ?Y; X' ⊆ ?Y; ?Y ⊆ A⟧ ⟹ sum g ?Y ≤ C›*) apply (intro sum_mono2 (*‹⟦finite ?B; ?A ⊆ ?B; ⋀b. b ∈ ?B - ?A ⟹ 0 ≤ ?f b⟧ ⟹ sum ?f ?A ≤ sum ?f ?B›*) g_nonneg (*‹?x ∈ A ⟹ 0 ≤ g ?x›*)) (*goals: 1. ‹⟦finite (X::'c set); X ⊆ (A::'c set); finite (X'::'c set); X' ⊆ A; ⋀Y::'c set. ⟦finite Y; X' ⊆ Y; Y ⊆ A⟧ ⟹ sum (g::'c ⇒ 'a) Y ≤ (C::'a)⟧ ⟹ finite (X ∪ X')› 2. ‹⟦finite (X::'c set); X ⊆ (A::'c set); finite (X'::'c set); X' ⊆ A; ⋀Y::'c set. ⟦finite Y; X' ⊆ Y; Y ⊆ A⟧ ⟹ sum (g::'c ⇒ 'a) Y ≤ (C::'a)⟧ ⟹ X ⊆ X ∪ X'› 3. ‹⋀b::'c. ⟦finite (X::'c set); X ⊆ (A::'c set); finite (X'::'c set); X' ⊆ A; ⋀Y::'c set. ⟦finite Y; X' ⊆ Y; Y ⊆ A⟧ ⟹ sum (g::'c ⇒ 'a) Y ≤ (C::'a); b ∈ X ∪ X' - X⟧ ⟹ b ∈ A› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . also (*calculation: ‹sum g X ≤ sum g (X ∪ X')›*) have "… ≤ C" using X (*‹finite X› ‹X ⊆ A›*) X'(1,2) (*‹finite X'› ‹X' ⊆ A›*) apply (intro X'( (*‹⟦finite ?Y; X' ⊆ ?Y; ?Y ⊆ A⟧ ⟹ sum g ?Y ≤ C›*) 3)) (*goals: 1. ‹⟦finite X; X ⊆ A; finite X'; X' ⊆ A⟧ ⟹ finite (X ∪ X')› 2. ‹⟦finite X; X ⊆ A; finite X'; X' ⊆ A⟧ ⟹ X' ⊆ X ∪ X'› 3. ‹⟦finite X; X ⊆ A; finite X'; X' ⊆ A⟧ ⟹ X ∪ X' ⊆ A› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . finally (*calculation: ‹sum (g::'c ⇒ 'a) (X::'c set) ≤ (C::'a)›*) show "?thesis" (*goal: ‹sum g X ≤ C›*) . qed have "sum f Y ≤ C" if Y: "finite Y" "Y ⊆ Sigma A B" for Y proof (-) (*goal: ‹sum f Y ≤ C›*) define Y1 and Y2 where "Y1 = fst ` Y" and "Y2 = (λx. snd ` {z∈Y. fst z = x})" have Y12: "Y = Sigma Y1 Y2" unfolding Y1_def Y2_def (*goal: ‹Y = (SIGMA x:fst ` Y. snd ` {z ∈ Y. fst z = x})›*) by force have [intro]: "finite Y1" "⋀x. x ∈ Y1 ⟹ finite (Y2 x)" using Y (*‹finite Y› ‹Y ⊆ Sigma A B›*) unfolding Y1_def Y2_def (*goals: 1. ‹finite (fst ` Y)› 2. ‹⋀x. x ∈ fst ` Y ⟹ finite (snd ` {z ∈ Y. fst z = x})›*) apply - (*goals: 1. ‹⟦finite Y; Y ⊆ Sigma A B⟧ ⟹ finite (fst ` Y)› 2. ‹⋀x. ⟦x ∈ fst ` Y; finite Y; Y ⊆ Sigma A B⟧ ⟹ finite (snd ` {z ∈ Y. fst z = x})› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . have Y12_subset: "Y1 ⊆ A" "⋀x. Y2 x ⊆ B x" using Y (*‹finite (Y::('c × 'd) set)› ‹Y ⊆ Sigma A B›*) apply - (*goals: 1. ‹⟦finite Y; Y ⊆ Sigma A B⟧ ⟹ Y1 ⊆ A› 2. ‹⋀x. ⟦finite Y; Y ⊆ Sigma A B⟧ ⟹ Y2 x ⊆ B x› discuss goal 1*) apply ((auto simp: Y1_def (*‹Y1 = fst ` Y›*) Y2_def (*‹Y2 = (λx. snd ` {z ∈ Y. fst z = x})›*))[1]) (*discuss goal 2*) apply ((auto simp: Y1_def (*‹Y1 = fst ` Y›*) Y2_def (*‹Y2 = (λx. snd ` {z ∈ Y. fst z = x})›*))[1]) (*proven 2 subgoals*) . have "sum f Y = sum f (Sigma Y1 Y2)" by (simp add: Y12 (*‹Y = Sigma Y1 Y2›*)) also (*calculation: ‹sum f Y = sum f (Sigma Y1 Y2)›*) have "… = (∑x∈Y1. ∑y∈Y2 x. f (x, y))" apply (subst sum.Sigma (*‹⟦finite (?A::?'b set); ∀x::?'b∈?A. finite ((?B::?'b ⇒ ?'c set) x)⟧ ⟹ (∑x::?'b∈?A. sum ((?g::?'b ⇒ ?'c ⇒ ?'a) x) (?B x)) = (∑(x::?'b, y::?'c)∈Sigma ?A ?B. ?g x y)›*)) (*goals: 1. ‹finite (Y1::'c set)› 2. ‹∀x::'c∈Y1::'c set. finite ((Y2::'c ⇒ 'd set) x)› 3. ‹sum (f::'c × 'd ⇒ 'a) (Sigma (Y1::'c set) (Y2::'c ⇒ 'd set)) = (∑(x::'c, y::'d)∈Sigma Y1 Y2. f (x, y))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . also (*calculation: ‹sum f Y = (∑x∈Y1. ∑y∈Y2 x. f (x, y))›*) have "… ≤ (∑x∈Y1. g x)" proof (rule sum_mono (*‹(⋀i. i ∈ ?K ⟹ ?f i ≤ ?g i) ⟹ sum ?f ?K ≤ sum ?g ?K›*)) (*goal: ‹⋀x. x ∈ Y1 ⟹ (∑y∈Y2 x. f (x, y)) ≤ g x›*) fix x assume x: "x ∈ Y1" (*‹(x::'c) ∈ (Y1::'c set)›*) show "(∑y∈Y2 x. f (x, y)) ≤ g x" proof (rule has_sum_mono' (*‹⟦(?f has_sum ?S) ?A; (?f has_sum ?S') ?B; ?A ⊆ ?B; ⋀x. x ∈ ?B - ?A ⟹ 0 ≤ ?f x⟧ ⟹ ?S ≤ ?S'›*)) (*goals: 1. ‹((?f::?'b ⇒ 'a) has_sum (∑y::'d∈(Y2::'c ⇒ 'd set) x. (f::'c × 'd ⇒ 'a) (x::'c, y))) (?A::?'b set)› 2. ‹((?f::?'b ⇒ 'a) has_sum (g::'c ⇒ 'a) (x::'c)) (?B::?'b set)› 3. ‹(?A::?'b set) ⊆ (?B::?'b set)› 4. ‹⋀x::?'b. x ∈ (?B::?'b set) - (?A::?'b set) ⟹ (0::'a) ≤ (?f::?'b ⇒ 'a) x›*) show "((λy. f (x, y)) has_sum (∑y∈Y2 x. f (x, y))) (Y2 x)" using x (*‹x ∈ Y1›*) apply (intro has_sum_finite (*‹finite ?F ⟹ (?f has_sum sum ?f ?F) ?F›*)) (*goal: ‹((λy. f (x, y)) has_sum (∑y∈Y2 x. f (x, y))) (Y2 x)›*) by auto show "((λy. f (x, y)) has_sum g x) (B x)" apply (rule f (*‹?x ∈ A ⟹ ((λy. f (?x, y)) has_sum g ?x) (B ?x)›*)) (*goal: ‹((λy. f (x, y)) has_sum g x) (B x)›*) by (use x Y12_subset in auto) show "f (x, y) ≥ 0" if "y ∈ B x - Y2 x" for y using x (*‹x ∈ Y1›*) that (*‹y ∈ B x - Y2 x›*) Y12_subset (*‹Y1 ⊆ A› ‹Y2 ?x ⊆ B ?x›*) apply (intro f_nonneg (*‹⟦?x ∈ A; ?y ∈ B ?x⟧ ⟹ 0 ≤ f (?x, ?y)›*)) (*goals: 1. ‹⟦x ∈ Y1; y ∈ B x - Y2 x; Y1 ⊆ A; ⋀x. Y2 x ⊆ B x⟧ ⟹ x ∈ A› 2. ‹⟦x ∈ Y1; y ∈ B x - Y2 x; Y1 ⊆ A; ⋀x. Y2 x ⊆ B x⟧ ⟹ y ∈ B x› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . qed (use Y12_subset in auto) (*solved the remaining goal: ‹Y2 x ⊆ B x›*) qed also (*calculation: ‹sum f Y ≤ sum g Y1›*) have "… ≤ C" using Y12_subset (*‹Y1 ⊆ A› ‹Y2 ?x ⊆ B ?x›*) apply (intro sum_g_le (*‹⟦finite ?X; ?X ⊆ A⟧ ⟹ sum g ?X ≤ C›*)) (*goals: 1. ‹⟦Y1 ⊆ A; ⋀x. Y2 x ⊆ B x⟧ ⟹ finite Y1› 2. ‹⟦Y1 ⊆ A; ⋀x. Y2 x ⊆ B x⟧ ⟹ Y1 ⊆ A› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . finally (*calculation: ‹sum (f::'c × 'd ⇒ 'a) (Y::('c × 'd) set) ≤ (C::'a)›*) show "?thesis" (*goal: ‹sum f Y ≤ C›*) . qed hence "∀⇩F X in finite_subsets_at_top (Sigma A B). sum f X ≤ C" unfolding eventually_finite_subsets_at_top (*goal: ‹∃X. finite X ∧ X ⊆ Sigma A B ∧ (∀Y. finite Y ∧ X ⊆ Y ∧ Y ⊆ Sigma A B ⟶ sum f Y ≤ C)›*) by auto thus "?thesis" (*goal: ‹(f::'c × 'd ⇒ 'a) summable_on Sigma (A::'c set) (B::'c ⇒ 'd set)›*) by (metis SigmaE (*‹⟦?c ∈ Sigma ?A ?B; ⋀x y. ⟦x ∈ ?A; y ∈ ?B x; ?c = (x, y)⟧ ⟹ ?P⟧ ⟹ ?P›*) f_nonneg (*‹⟦?x ∈ A; ?y ∈ B ?x⟧ ⟹ 0 ≤ f (?x, ?y)›*) nonneg_bounded_partial_sums_imp_summable_on (*‹⟦⋀x. x ∈ ?A ⟹ 0 ≤ ?f x; ∀⇩F X in finite_subsets_at_top ?A. sum ?f X ≤ ?C⟧ ⟹ ?f summable_on ?A›*)) qed lemma summable_on_UnionI: fixes f :: "_ ⇒ 'a :: {linorder_topology, ordered_comm_monoid_add, topological_comm_monoid_add, conditionally_complete_linorder}" assumes f: "⋀x. x ∈ A ⟹ (f has_sum g x) (B x)" assumes g: "g summable_on A" assumes f_nonneg: "⋀x y. x ∈ A ⟹ y ∈ B x ⟹ f y ≥ (0 :: 'a)" assumes disj: "disjoint_family_on B A" shows "f summable_on (⋃x∈A. B x)" proof (-) (*goal: ‹f summable_on ⋃ (B ` A)›*) have "f ∘ snd summable_on Sigma A B" using assms (*‹?x ∈ A ⟹ (f has_sum g ?x) (B ?x)› ‹g summable_on A› ‹⟦?x ∈ A; ?y ∈ B ?x⟧ ⟹ 0 ≤ f ?y› ‹disjoint_family_on B A›*) apply (intro summable_on_SigmaI[where g = g] (*‹⟦⋀x. x ∈ ?A ⟹ ((λy. ?f (x, y)) has_sum g x) (?B x); g summable_on ?A; ⋀x y. ⟦x ∈ ?A; y ∈ ?B x⟧ ⟹ 0 ≤ ?f (x, y)⟧ ⟹ ?f summable_on Sigma ?A ?B›*)) (*goals: 1. ‹⋀x::'c. ⟦⋀x::'c. x ∈ (A::'c set) ⟹ ((f::'d ⇒ 'a) has_sum (g::'c ⇒ 'a) x) ((B::'c ⇒ 'd set) x); g summable_on A; ⋀(x::'c) y::'d. ⟦x ∈ A; y ∈ B x⟧ ⟹ (0::'a) ≤ f y; disjoint_family_on B A; x ∈ A⟧ ⟹ ((λy::'d. (f ∘ snd) (x, y)) has_sum g x) (B x)› 2. ‹⟦⋀x::'c. x ∈ (A::'c set) ⟹ ((f::'d ⇒ 'a) has_sum (g::'c ⇒ 'a) x) ((B::'c ⇒ 'd set) x); g summable_on A; ⋀(x::'c) y::'d. ⟦x ∈ A; y ∈ B x⟧ ⟹ (0::'a) ≤ f y; disjoint_family_on B A⟧ ⟹ g summable_on A› 3. ‹⋀(x::'c) y::'d. ⟦⋀x::'c. x ∈ (A::'c set) ⟹ ((f::'d ⇒ 'a) has_sum (g::'c ⇒ 'a) x) ((B::'c ⇒ 'd set) x); g summable_on A; ⋀(x::'c) y::'d. ⟦x ∈ A; y ∈ B x⟧ ⟹ (0::'a) ≤ f y; disjoint_family_on B A; x ∈ A; y ∈ B x⟧ ⟹ (0::'a) ≤ (f ∘ snd) (x, y)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . also (*calculation: ‹f ∘ snd summable_on Sigma A B›*) have "?this ⟷ f summable_on (snd ` Sigma A B)" using assms (*‹?x ∈ A ⟹ (f has_sum g ?x) (B ?x)› ‹(g::'c ⇒ 'a) summable_on (A::'c set)› ‹⟦?x ∈ A; ?y ∈ B ?x⟧ ⟹ 0 ≤ f ?y› ‹disjoint_family_on B A›*) apply (subst summable_on_reindex (*‹inj_on ?h ?A ⟹ (?g summable_on ?h ` ?A) = (?g ∘ ?h summable_on ?A)›*)) (*goals: 1. ‹⟦⋀x::'c. x ∈ (A::'c set) ⟹ ((f::'d ⇒ 'a) has_sum (g::'c ⇒ 'a) x) ((B::'c ⇒ 'd set) x); g summable_on A; ⋀(x::'c) y::'d. ⟦x ∈ A; y ∈ B x⟧ ⟹ (0::'a) ≤ f y; disjoint_family_on B A⟧ ⟹ inj_on snd (Sigma A B)› 2. ‹⟦⋀x::'c. x ∈ (A::'c set) ⟹ ((f::'d ⇒ 'a) has_sum (g::'c ⇒ 'a) x) ((B::'c ⇒ 'd set) x); g summable_on A; ⋀(x::'c) y::'d. ⟦x ∈ A; y ∈ B x⟧ ⟹ (0::'a) ≤ f y; disjoint_family_on B A⟧ ⟹ (f ∘ snd summable_on Sigma A B) = (f ∘ snd summable_on Sigma A B)› discuss goal 1*) apply (force simp: disjoint_family_on_def (*‹disjoint_family_on ?A ?S = (∀m∈?S. ∀n∈?S. m ≠ n ⟶ ?A m ∩ ?A n = {})›*) inj_on_def (*‹inj_on ?f ?A = (∀x∈?A. ∀y∈?A. ?f x = ?f y ⟶ x = y)›*)) (*discuss goal 2*) apply (force simp: disjoint_family_on_def (*‹disjoint_family_on (?A::?'i::type ⇒ ?'a::type set) (?S::?'i::type set) = (∀m::?'i::type∈?S. ∀n::?'i::type∈?S. m ≠ n ⟶ ?A m ∩ ?A n = {})›*) inj_on_def (*‹inj_on (?f::?'a::type ⇒ ?'b::type) (?A::?'a::type set) = (∀x::?'a::type∈?A. ∀y::?'a::type∈?A. ?f x = ?f y ⟶ x = y)›*)) (*proven 2 subgoals*) . also (*calculation: ‹f summable_on snd ` Sigma A B›*) have "snd ` (Sigma A B) = (⋃x∈A. B x)" by force finally (*calculation: ‹f summable_on ⋃ (B ` A)›*) show "?thesis" (*goal: ‹f summable_on ⋃ (B ` A)›*) . qed lemma summable_on_SigmaD: fixes f :: "'a × 'b ⇒ 'c :: {topological_comm_monoid_add,t3_space}" assumes sum1: "f summable_on (Sigma A B)" assumes sum2: "⋀x. x ∈ A ⟹ (λy. f (x, y)) summable_on (B x)" shows "(λx. infsum (λy. f (x, y)) (B x)) summable_on A" using assms (*‹f summable_on Sigma A B› ‹?x ∈ A ⟹ (λy. f (?x, y)) summable_on B ?x›*) unfolding summable_on_def (*goal: ‹∃x. ((λx. ∑⇩∞y∈B x. f (x, y)) has_sum x) A›*) by (smt (verit, del_insts) assms (*‹f summable_on Sigma A B› ‹?x ∈ A ⟹ (λy. f (?x, y)) summable_on B ?x›*) has_sum_SigmaD (*‹⟦(?f has_sum ?S) (Sigma ?A ?B); ⋀x. x ∈ ?A ⟹ ((λy. ?f (x, y)) has_sum ?g x) (?B x)⟧ ⟹ (?g has_sum ?S) ?A›*) has_sum_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ (?f has_sum ?x) ?A = (?g has_sum ?x) ?A›*) has_sum_infsum (*‹?f summable_on ?S ⟹ (?f has_sum infsum ?f ?S) ?S›*)) lemma summable_on_UnionD: fixes f :: "'a ⇒ 'c :: {topological_comm_monoid_add,t3_space}" assumes sum1: "f summable_on (⋃x∈A. B x)" assumes sum2: "⋀x. x ∈ A ⟹ f summable_on (B x)" assumes disj: "disjoint_family_on B A" shows "(λx. infsum f (B x)) summable_on A" proof (-) (*goal: ‹(λx. infsum f (B x)) summable_on A›*) have "(⋃x∈A. B x) = snd ` Sigma A B" by (force simp: Sigma_def (*‹Sigma ?A ?B ≡ ⋃x∈?A. ⋃y∈?B x. {(x, y)}›*)) with sum1 (*‹f summable_on ⋃ (B ` A)›*) have "f summable_on (snd ` Sigma A B)" by simp also (*calculation: ‹f summable_on snd ` Sigma A B›*) have "?this ⟷ (f ∘ snd) summable_on (Sigma A B)" using disj (*‹disjoint_family_on B A›*) apply (intro summable_on_reindex (*‹inj_on ?h ?A ⟹ (?g summable_on ?h ` ?A) = (?g ∘ ?h summable_on ?A)›*) inj_onI (*‹(⋀x y. ⟦x ∈ ?A; y ∈ ?A; ?f x = ?f y⟧ ⟹ x = y) ⟹ inj_on ?f ?A›*)) (*goal: ‹(f summable_on snd ` Sigma A B) = (f ∘ snd summable_on Sigma A B)›*) by (force simp: disjoint_family_on_def (*‹disjoint_family_on (?A::?'i ⇒ ?'a set) (?S::?'i set) = (∀m::?'i∈?S. ∀n::?'i∈?S. m ≠ n ⟶ ?A m ∩ ?A n = {})›*)) finally (*calculation: ‹f ∘ snd summable_on Sigma A B›*) show "(λx. infsum f (B x)) summable_on A" using summable_on_SigmaD[of "f ∘ snd" A B] (*‹⟦f ∘ snd summable_on Sigma A B; ⋀x. x ∈ A ⟹ (λy. (f ∘ snd) (x, y)) summable_on B x⟧ ⟹ (λx. ∑⇩∞y∈B x. (f ∘ snd) (x, y)) summable_on A›*) sum2 (*‹(?x::'b) ∈ (A::'b set) ⟹ (f::'a ⇒ 'c) summable_on (B::'b ⇒ 'a set) ?x›*) by simp qed lemma summable_on_Union_iff: fixes f :: "_ ⇒ 'a :: {linorder_topology, ordered_comm_monoid_add, topological_comm_monoid_add, conditionally_complete_linorder, t3_space}" assumes f: "⋀x. x ∈ A ⟹ (f has_sum g x) (B x)" assumes f_nonneg: "⋀x y. x ∈ A ⟹ y ∈ B x ⟹ f y ≥ 0" assumes disj: "disjoint_family_on B A" shows "f summable_on (⋃x∈A. B x) ⟷ g summable_on A" proof (standard) (*goals: 1. ‹f summable_on ⋃ (B ` A) ⟹ g summable_on A› 2. ‹g summable_on A ⟹ f summable_on ⋃ (B ` A)›*) assume "g summable_on A" (*‹(g::'c ⇒ 'a) summable_on (A::'c set)›*) thus "f summable_on (⋃x∈A. B x)" using summable_on_UnionI[of A f B g] (*‹⟦⋀x::'c::type. x ∈ (A::'c::type set) ⟹ ((f::'d::type ⇒ 'a::{conditionally_complete_linorder,ordered_comm_monoid_add,topological_comm_monoid_add,linorder_topology,t3_space}) has_sum (g::'c::type ⇒ 'a::{conditionally_complete_linorder,ordered_comm_monoid_add,topological_comm_monoid_add,linorder_topology,t3_space}) x) ((B::'c::type ⇒ 'd::type set) x); g summable_on A; ⋀(x::'c::type) y::'d::type. ⟦x ∈ A; y ∈ B x⟧ ⟹ (0::'a::{conditionally_complete_linorder,ordered_comm_monoid_add,topological_comm_monoid_add,linorder_topology,t3_space}) ≤ f y; disjoint_family_on B A⟧ ⟹ f summable_on ⋃ (B ` A)›*) assms (*‹?x ∈ A ⟹ (f has_sum g ?x) (B ?x)› ‹⟦?x ∈ A; ?y ∈ B ?x⟧ ⟹ 0 ≤ f ?y› ‹disjoint_family_on B A›*) by auto next (*goal: ‹f summable_on ⋃ (B ` A) ⟹ g summable_on A›*) assume "f summable_on (⋃x∈A. B x)" (*‹(f::'d ⇒ 'a) summable_on ⋃ ((B::'c ⇒ 'd set) ` (A::'c set))›*) hence "(λx. infsum f (B x)) summable_on A" using assms (*‹?x ∈ A ⟹ (f has_sum g ?x) (B ?x)› ‹⟦?x ∈ A; ?y ∈ B ?x⟧ ⟹ 0 ≤ f ?y› ‹disjoint_family_on B A›*) apply (intro summable_on_UnionD (*‹⟦?f summable_on ⋃ (?B ` ?A); ⋀x. x ∈ ?A ⟹ ?f summable_on ?B x; disjoint_family_on ?B ?A⟧ ⟹ (λx. infsum ?f (?B x)) summable_on ?A›*)) (*goals: 1. ‹⟦f summable_on ⋃ (B ` A); ⋀x. x ∈ A ⟹ (f has_sum g x) (B x); ⋀x y. ⟦x ∈ A; y ∈ B x⟧ ⟹ 0 ≤ f y; disjoint_family_on B A⟧ ⟹ f summable_on ⋃ (B ` A)› 2. ‹⋀x. ⟦f summable_on ⋃ (B ` A); ⋀x. x ∈ A ⟹ (f has_sum g x) (B x); ⋀x y. ⟦x ∈ A; y ∈ B x⟧ ⟹ 0 ≤ f y; disjoint_family_on B A; x ∈ A⟧ ⟹ f summable_on B x› 3. ‹⟦f summable_on ⋃ (B ` A); ⋀x. x ∈ A ⟹ (f has_sum g x) (B x); ⋀x y. ⟦x ∈ A; y ∈ B x⟧ ⟹ 0 ≤ f y; disjoint_family_on B A⟧ ⟹ disjoint_family_on B A› discuss goal 1*) apply ((auto dest: has_sum_imp_summable (*‹(?f has_sum ?S) ?A ⟹ ?f summable_on ?A›*))[1]) (*discuss goal 2*) apply ((auto dest: has_sum_imp_summable (*‹(?f has_sum ?S) ?A ⟹ ?f summable_on ?A›*))[1]) (*discuss goal 3*) apply ((auto dest: has_sum_imp_summable (*‹(?f has_sum ?S) ?A ⟹ ?f summable_on ?A›*))[1]) (*proven 3 subgoals*) . also (*calculation: ‹(λx. infsum f (B x)) summable_on A›*) have "?this ⟷ g summable_on A" using assms (*‹?x ∈ A ⟹ (f has_sum g ?x) (B ?x)› ‹⟦?x ∈ A; ?y ∈ B ?x⟧ ⟹ 0 ≤ f ?y› ‹disjoint_family_on B A›*) apply (intro summable_on_cong (*‹(⋀x. x ∈ ?A ⟹ ?f x = ?g x) ⟹ (?f summable_on ?A) = (?g summable_on ?A)›*)) (*goal: ‹((λx. infsum f (B x)) summable_on A) = (g summable_on A)›*) by (auto simp: infsumI (*‹(?f has_sum ?x) ?A ⟹ infsum ?f ?A = ?x›*)) finally (*calculation: ‹g summable_on A›*) show "g summable_on A" . qed lemma has_sum_Sigma': fixes A :: "'a set" and B :: "'a ⇒ 'b set" and f :: ‹'a × 'b ⇒ 'c::{comm_monoid_add,uniform_space,uniform_topological_group_add}› assumes summableAB: "(f has_sum a) (Sigma A B)" assumes summableB: ‹⋀x. x∈A ⟹ ((λy. f (x, y)) has_sum (b x)) (B x)› shows "(b has_sum a) A" by (intro has_sum_Sigma[OF _ assms] (*‹⟦uniformly_continuous_on UNIV (λ(x, y). x + y); ⋀x. x ∈ A ⟹ x ∈ A⟧ ⟹ (b has_sum a) A›*) uniformly_continuous_add (*‹uniformly_continuous_on UNIV (λ(x, y). x + y)›*)) lemma abs_summable_on_comparison_test': assumes "g summable_on A" assumes "⋀x. x ∈ A ⟹ norm (f x) ≤ g x" shows "(λx. norm (f x)) summable_on A" proof (rule Infinite_Sum.abs_summable_on_comparison_test (*‹⟦?g abs_summable_on ?A; ⋀x. x ∈ ?A ⟹ norm (?f x) ≤ norm (?g x)⟧ ⟹ ?f abs_summable_on ?A›*)) (*goals: 1. ‹?g abs_summable_on A› 2. ‹⋀x. x ∈ A ⟹ norm (f x) ≤ norm (?g x)›*) have "g summable_on A ⟷ (λx. norm (g x)) summable_on A" by (metis summable_on_iff_abs_summable_on_real (*‹(?f summable_on ?A) = (?f abs_summable_on ?A)›*)) with assms (*‹g summable_on A› ‹?x ∈ A ⟹ norm (f ?x) ≤ g ?x›*) show "(λx. norm (g x)) summable_on A" by blast qed (use assms in fastforce) (*solved the remaining goal: ‹⋀x. x ∈ A ⟹ norm (f x) ≤ norm (g x)›*) lemma has_sum_geometric_from_1: fixes z :: "'a :: {real_normed_field, banach}" assumes "norm z < 1" shows "((λn. z ^ n) has_sum (z / (1 - z))) {1..}" proof (-) (*goal: ‹((^) z has_sum z / (1 - z)) {1..}›*) have [simp]: "z ≠ 1" using assms (*‹norm (z::'a::{banach,real_normed_field}) < (1::real)›*) by auto have "(λn. z ^ Suc n) sums (1 / (1 - z) - 1)" using geometric_sums[of z] (*‹norm z < 1 ⟹ (^) z sums (1 / (1 - z))›*) assms (*‹norm z < 1›*) apply (subst sums_Suc_iff (*‹(λn::nat. (?f::nat ⇒ ?'a::real_normed_vector) (Suc n)) sums (?s::?'a::real_normed_vector) = ?f sums (?s + ?f (0::nat))›*)) (*goal: ‹(λn. z ^ Suc n) sums (1 / (1 - z) - 1)›*) by auto also (*calculation: ‹(λn. z ^ Suc n) sums (1 / (1 - z) - 1)›*) have "1 / (1 - z) - 1 = z / (1 - z)" by (auto simp: field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 69 facts*)) finally (*calculation: ‹(λn. z ^ Suc n) sums (z / (1 - z))›*) have "(λn. z ^ Suc n) sums (z / (1 - z))" . moreover have "summable (λn. norm (z ^ Suc n))" using assms (*‹norm z < 1›*) apply (subst summable_Suc_iff (*‹summable (λn. ?f (Suc n)) = summable ?f›*)) (*goal: ‹summable (λn. norm (z ^ Suc n))›*) by (auto simp: norm_power (*‹norm (?x ^ ?n) = norm ?x ^ ?n›*) intro!: summable_geometric (*‹norm ?c < 1 ⟹ summable ((^) ?c)›*)) ultimately have "((λn. z ^ Suc n) has_sum (z / (1 - z))) UNIV" apply (intro norm_summable_imp_has_sum (*‹⟦summable (λn. norm (?f n)); ?f sums ?S⟧ ⟹ (?f has_sum ?S) UNIV›*)) (*goals: 1. ‹⟦(λn. z ^ Suc n) sums (z / (1 - z)); summable (λn. norm (z ^ Suc n))⟧ ⟹ summable (λn. norm (z ^ Suc n))› 2. ‹⟦(λn. z ^ Suc n) sums (z / (1 - z)); summable (λn. norm (z ^ Suc n))⟧ ⟹ (λn. z ^ Suc n) sums (z / (1 - z))› discuss goal 1*) apply ((assumption)[1]) (*discuss goal 2*) . (*proven 2 subgoals*) also (*calculation: ‹((λn. z ^ Suc n) has_sum z / (1 - z)) UNIV›*) have "?this ⟷ ?thesis" apply (intro has_sum_reindex_bij_witness[of _ "λn. n-1" "λn. n+1"] (*‹⟦⋀a::?'b1. a ∈ (?S::?'b1 set) ⟹ a + (1::?'b1) - (1::?'b1) = a; ⋀a::?'b1. a ∈ ?S ⟹ a + (1::?'b1) ∈ (?T::?'b1 set); ⋀b::?'b1. b ∈ ?T ⟹ b - (1::?'b1) + (1::?'b1) = b; ⋀b::?'b1. b ∈ ?T ⟹ b - (1::?'b1) ∈ ?S; ⋀a::?'b1. a ∈ ?S ⟹ (?h::?'b1 ⇒ ?'c) (a + (1::?'b1)) = (?g::?'b1 ⇒ ?'c) a; (?s::?'c) = (?s'::?'c)⟧ ⟹ (?g has_sum ?s) ?S = (?h has_sum ?s') ?T›*)) (*goals: 1. ‹⋀a. a ∈ UNIV ⟹ a + 1 - 1 = a› 2. ‹⋀a. a ∈ UNIV ⟹ a + 1 ∈ {1..}› 3. ‹⋀b. b ∈ {1..} ⟹ b - 1 + 1 = b› 4. ‹⋀b. b ∈ {1..} ⟹ b - 1 ∈ UNIV› 5. ‹⋀a. a ∈ UNIV ⟹ z ^ (a + 1) = z ^ Suc a› 6. ‹z / (1 - z) = z / (1 - z)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*discuss goal 5*) apply ((auto)[1]) (*discuss goal 6*) apply ((auto)[1]) (*proven 6 subgoals*) . finally (*calculation: ‹((^) z has_sum z / (1 - z)) {1..}›*) show "?thesis" (*goal: ‹((^) z has_sum z / (1 - z)) {1..}›*) . qed lemma has_sum_divide_const: fixes f :: "'a ⇒ 'b :: {topological_semigroup_mult, field, semiring_0}" shows "(f has_sum S) A ⟹ ((λx. f x / c) has_sum (S / c)) A" using has_sum_cmult_right[of f A S "inverse c"] (*‹(f has_sum S) A ⟹ ((λx. inverse c * f x) has_sum inverse c * S) A›*) by (simp add: field_simps (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)› ‹(?a::?'a) * (?b::?'a) * (?c::?'a) = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)› ‹(?a::?'a) - (?b::?'a) - (?c::?'a) = ?a - (?b + ?c)› ‹(?a::?'a) + ((?b::?'a) - (?c::?'a)) = ?a + ?b - ?c› ‹((?a::?'a) - (?b::?'a) = (?c::?'a)) = (?a = ?c + ?b)› ‹((?a::?'a) = (?c::?'a) - (?b::?'a)) = (?a + ?b = ?c)› ‹(?a::?'a) - ((?b::?'a) - (?c::?'a)) = ?a + ?c - ?b› ‹(?a::?'a) - (?b::?'a) + (?c::?'a) = ?a + ?c - ?b› and more 69 facts*)) lemma has_sum_uminusI: fixes f :: "'a ⇒ 'b :: {topological_semigroup_mult, ring_1}" shows "(f has_sum S) A ⟹ ((λx. -f x) has_sum (-S)) A" using has_sum_cmult_right[of f A S "-1"] (*‹(f has_sum S) A ⟹ ((λx. - 1 * f x) has_sum - 1 * S) A›*) by simp end
{ "path": "Isabelle2024/src/HOL/Analysis/Infinite_Sum.thy", "repo": "Isabelle2024", "sha": "bc79361c2879d9ba15f9faa14569ad35506e77beda849fb6f30f4930fa80e951" }
(* Title: Miscellaneous results Author: Tim Makarios <tjm1983 at gmail.com>, 2012 Maintainer: Tim Makarios <tjm1983 at gmail.com> *) (*Some of these theorems were moved to the Isabelle repository *) section "Miscellaneous results" theory Miscellany imports Metric begin lemma unordered_pair_element_equality: assumes "{p, q} = {r, s}" and "p = r" shows "q = s" using assms (*‹{p::'a::type, q::'a::type} = {r::'a::type, s::'a::type}› ‹p = r›*) by (auto simp: doubleton_eq_iff (*‹({?a, ?b} = {?c, ?d}) = (?a = ?c ∧ ?b = ?d ∨ ?a = ?d ∧ ?b = ?c)›*)) lemma unordered_pair_equality: "{p, q} = {q, p}" by auto lemma cosine_rule: fixes a b c :: "real ^ ('n::finite)" shows "(norm_dist a c)² = (norm_dist a b)² + (norm_dist b c)² + 2 * ((a - b) ∙ (b - c))" proof (-) (*goal: ‹(norm_dist a c)² = (norm_dist a b)² + (norm_dist b c)² + 2 * ((a - b) ∙ (b - c))›*) have "(a - b) + (b - c) = a - c" by simp with dot_norm[of "a - b" "b - c"] (*‹((a::(real, 'n) vec) - (b::(real, 'n) vec)) ∙ (b - (c::(real, 'n) vec)) = ((norm (a - b + (b - c)))² - (norm (a - b))² - (norm (b - c))²) / (2::real)›*) have "(a - b) ∙ (b - c) = ((norm (a - c))² - (norm (a - b))² - (norm (b - c))²) / 2" by simp thus "?thesis" (*goal: ‹(norm_dist a c)² = (norm_dist a b)² + (norm_dist b c)² + 2 * ((a - b) ∙ (b - c))›*) by simp qed lemma scalar_equiv: "r *s x = r *⇩R x" by vector lemma norm_dist_dot: "(norm_dist x y)² = (x - y) ∙ (x - y)" by (simp add: power2_norm_eq_inner (*‹(norm ?x)² = ?x ∙ ?x›*)) definition dep2 :: "'a::real_vector ⇒ 'a ⇒ bool" where "dep2 u v ≡ ∃w r s. u = r *⇩R w ∧ v = s *⇩R w" lemma real2_eq: fixes u v :: "real^2" assumes "u$1 = v$1" and "u$2 = v$2" shows "u = v" by (simp add: vec_eq_iff [of u v] (*‹((u::(real, 2) vec) = (v::(real, 2) vec)) = (∀i::2. u $ i = v $ i)›*) forall_2 (*‹(∀i::2. (?P::2 ⇒ bool) i) = (?P (1::2) ∧ ?P (2::2))›*) assms (*‹(u::(real, 2) vec) $ (1::2) = (v::(real, 2) vec) $ (1::2)› ‹(u::(real, 2) vec) $ (2::2) = (v::(real, 2) vec) $ (2::2)›*)) definition rotate2 :: "real^2 ⇒ real^2" where "rotate2 x ≡ vector [-x$2, x$1]" declare vector_2 [simp] lemma rotate2 [simp]: "(rotate2 x)$1 = -x$2" "(rotate2 x)$2 = x$1" (*goals: 1. ‹rotate2 x $ 1 = - x $ 2› 2. ‹rotate2 x $ 2 = x $ 1› discuss goal 1*) apply (simp add: rotate2_def (*‹rotate2 ?x ≡ vector [- ?x $ 2, ?x $ 1]›*)) (*discuss goal 2*) apply (simp add: rotate2_def (*‹rotate2 ?x ≡ vector [- ?x $ 2, ?x $ 1]›*)) (*proven 2 subgoals*) . lemma rotate2_rotate2 [simp]: "rotate2 (rotate2 x) = -x" proof (-) (*goal: ‹rotate2 (rotate2 x) = - x›*) have "(rotate2 (rotate2 x))$1 = -x$1" and "(rotate2 (rotate2 x))$2 = -x$2" (*goals: 1. ‹rotate2 (rotate2 x) $ 1 = - x $ 1› 2. ‹rotate2 (rotate2 x) $ 2 = - x $ 2› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . with real2_eq (*‹⟦?u $ 1 = ?v $ 1; ?u $ 2 = ?v $ 2⟧ ⟹ ?u = ?v›*) show "rotate2 (rotate2 x) = -x" by simp qed lemma rotate2_dot [simp]: "(rotate2 u) ∙ (rotate2 v) = u ∙ v" unfolding inner_vec_def (*goal: ‹(∑i::2∈UNIV. rotate2 (u::(real, 2) vec) $ i ∙ rotate2 (v::(real, 2) vec) $ i) = (∑i::2∈UNIV. u $ i ∙ v $ i)›*) by (simp add: sum_2 (*‹sum ?f UNIV = ?f 1 + ?f 2›*)) lemma rotate2_scaleR [simp]: "rotate2 (k *⇩R x) = k *⇩R (rotate2 x)" proof (-) (*goal: ‹rotate2 ((k::real) *⇩R (x::(real, 2) vec)) = k *⇩R rotate2 x›*) have "(rotate2 (k *⇩R x))$1 = (k *⇩R (rotate2 x))$1" and "(rotate2 (k *⇩R x))$2 = (k *⇩R (rotate2 x))$2" (*goals: 1. ‹rotate2 (k *⇩R x) $ 1 = (k *⇩R rotate2 x) $ 1› 2. ‹rotate2 (k *⇩R x) $ 2 = (k *⇩R rotate2 x) $ 2› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . with real2_eq (*‹⟦?u $ 1 = ?v $ 1; ?u $ 2 = ?v $ 2⟧ ⟹ ?u = ?v›*) show "?thesis" (*goal: ‹rotate2 (k *⇩R x) = k *⇩R rotate2 x›*) by simp qed lemma rotate2_uminus [simp]: "rotate2 (-x) = -(rotate2 x)" proof (-) (*goal: ‹rotate2 (- x) = - rotate2 x›*) from scaleR_minus_left[of 1] (*‹- (1::real) *⇩R (?x::?'a::real_vector) = - ((1::real) *⇩R ?x)›*) have "-1 *⇩R x = -x" and "-1 *⇩R (rotate2 x) = -(rotate2 x)" (*goals: 1. ‹- 1 *⇩R x = - x› 2. ‹- 1 *⇩R rotate2 x = - rotate2 x› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . with rotate2_scaleR[of "-1" x] (*‹rotate2 (- 1 *⇩R x) = - 1 *⇩R rotate2 x›*) show "?thesis" (*goal: ‹rotate2 (- (x::(real, 2) vec)) = - rotate2 x›*) by simp qed lemma rotate2_eq [iff]: "rotate2 x = rotate2 y ⟷ x = y" proof (standard) (*goals: 1. ‹rotate2 x = rotate2 y ⟹ x = y› 2. ‹x = y ⟹ rotate2 x = rotate2 y›*) assume "x = y" (*‹(x::(real, 2) vec) = (y::(real, 2) vec)›*) thus "rotate2 x = rotate2 y" by simp next (*goal: ‹rotate2 x = rotate2 y ⟹ x = y›*) assume "rotate2 x = rotate2 y" (*‹rotate2 (x::(real, 2) vec) = rotate2 (y::(real, 2) vec)›*) hence "rotate2 (rotate2 x) = rotate2 (rotate2 y)" by simp hence "-(-x) = -(-y)" by simp thus "x = y" by simp qed lemma dot2_rearrange_1: fixes u x :: "real^2" assumes "u ∙ x = 0" and "x$1 ≠ 0" shows "u = (u$2 / x$1) *⇩R (rotate2 x)" (is "u = ?u'") proof (-) (*goal: ‹(u::(real, 2) vec) = (u $ (2::2) / (x::(real, 2) vec) $ (1::2)) *⇩R rotate2 x›*) from ‹u ∙ x = 0› (*‹(u::(real, 2) vec) ∙ (x::(real, 2) vec) = (0::real)›*) have "u$1 * x$1 = -(u$2) * (x$2)" unfolding inner_vec_def (*goal: ‹(u::(real, 2) vec) $ (1::2) * (x::(real, 2) vec) $ (1::2) = - u $ (2::2) * x $ (2::2)›*) by (simp add: sum_2 (*‹sum ?f UNIV = ?f 1 + ?f 2›*)) hence "u$1 * x$1 / x$1 = -u$2 / x$1 * x$2" by simp with ‹x$1 ≠ 0› (*‹x $ 1 ≠ 0›*) have "u$1 = ?u'$1" by simp from ‹x$1 ≠ 0› (*‹x $ 1 ≠ 0›*) have "u$2 = ?u'$2" by simp with ‹u$1 = ?u'$1› (*‹u $ 1 = ((u $ 2 / x $ 1) *⇩R rotate2 x) $ 1›*) real2_eq (*‹⟦?u $ 1 = ?v $ 1; ?u $ 2 = ?v $ 2⟧ ⟹ ?u = ?v›*) show "u = ?u'" by simp qed lemma dot2_rearrange_2: fixes u x :: "real^2" assumes "u ∙ x = 0" and "x$2 ≠ 0" shows "u = -(u$1 / x$2) *⇩R (rotate2 x)" (is "u = ?u'") proof (-) (*goal: ‹u = - (u $ 1 / x $ 2) *⇩R rotate2 x›*) from assms (*‹(u::(real, 2) vec) ∙ (x::(real, 2) vec) = (0::real)› ‹(x::(real, 2) vec) $ (2::2) ≠ (0::real)›*) dot2_rearrange_1[of "rotate2 u" "rotate2 x"] (*‹⟦rotate2 u ∙ rotate2 x = 0; rotate2 x $ 1 ≠ 0⟧ ⟹ rotate2 u = (rotate2 u $ 2 / rotate2 x $ 1) *⇩R rotate2 (rotate2 x)›*) have "rotate2 u = rotate2 ?u'" by simp thus "u = ?u'" by blast qed lemma dot2_rearrange: fixes u x :: "real^2" assumes "u ∙ x = 0" and "x ≠ 0" shows "∃k. u = k *⇩R (rotate2 x)" proof (cases) (*goals: 1. ‹?P ⟹ ∃k. u = k *⇩R rotate2 x› 2. ‹¬ ?P ⟹ ∃k. u = k *⇩R rotate2 x›*) assume "x$1 = 0" (*‹(x::(real, 2) vec) $ (1::2) = (0::real)›*) with real2_eq[of x 0] (*‹⟦x $ 1 = 0 $ 1; x $ 2 = 0 $ 2⟧ ⟹ x = 0›*) ‹x ≠ 0› (*‹x ≠ 0›*) have "x$2 ≠ 0" by auto with dot2_rearrange_2 (*‹⟦?u ∙ ?x = 0; ?x $ 2 ≠ 0⟧ ⟹ ?u = - (?u $ 1 / ?x $ 2) *⇩R rotate2 ?x›*) ‹u ∙ x = 0› (*‹u ∙ x = 0›*) show "?thesis" (*goal: ‹∃k. u = k *⇩R rotate2 x›*) by blast next (*goal: ‹x $ 1 ≠ 0 ⟹ ∃k. u = k *⇩R rotate2 x›*) assume "x$1 ≠ 0" (*‹(x::(real, 2) vec) $ (1::2) ≠ (0::real)›*) with dot2_rearrange_1 (*‹⟦?u ∙ ?x = 0; ?x $ 1 ≠ 0⟧ ⟹ ?u = (?u $ 2 / ?x $ 1) *⇩R rotate2 ?x›*) ‹u ∙ x = 0› (*‹u ∙ x = 0›*) show "?thesis" (*goal: ‹∃k. u = k *⇩R rotate2 x›*) by blast qed lemma real2_orthogonal_dep2: fixes u v x :: "real^2" assumes "x ≠ 0" and "u ∙ x = 0" and "v ∙ x = 0" shows "dep2 u v" sorry lemma dot_left_diff_distrib: fixes u v x :: "real^'n" shows "(u - v) ∙ x = (u ∙ x) - (v ∙ x)" proof (-) (*goal: ‹((u::(real, 'n) vec) - (v::(real, 'n) vec)) ∙ (x::(real, 'n) vec) = u ∙ x - v ∙ x›*) have "(u ∙ x) - (v ∙ x) = (∑i∈UNIV. u$i * x$i) - (∑i∈UNIV. v$i * x$i)" unfolding inner_vec_def (*goal: ‹(∑i∈UNIV. u $ i ∙ x $ i) - (∑i∈UNIV. v $ i ∙ x $ i) = (∑i∈UNIV. u $ i * x $ i) - (∑i∈UNIV. v $ i * x $ i)›*) by simp also (*calculation: ‹(u::(real, 'n::finite) vec) ∙ (x::(real, 'n::finite) vec) - (v::(real, 'n::finite) vec) ∙ x = (∑i::'n::finite∈UNIV. u $ i * x $ i) - (∑i::'n::finite∈UNIV. v $ i * x $ i)›*) from sum_subtractf[of "λ i. u$i * x$i" "λ i. v$i * x$i"] (*‹(∑xa∈?A. u $ xa * x $ xa - v $ xa * x $ xa) = (∑xa∈?A. u $ xa * x $ xa) - (∑xa∈?A. v $ xa * x $ xa)›*) have "… = (∑i∈UNIV. u$i * x$i - v$i * x$i)" by simp also (*calculation: ‹u ∙ x - v ∙ x = (∑i∈UNIV. u $ i * x $ i - v $ i * x $ i)›*) from left_diff_distrib[where 'a = real] (*‹((?a::real) - (?b::real)) * (?c::real) = ?a * ?c - ?b * ?c›*) have "… = (∑i∈UNIV. (u$i - v$i) * x$i)" by simp also (*calculation: ‹u ∙ x - v ∙ x = (∑i∈UNIV. (u $ i - v $ i) * x $ i)›*) have "… = (u - v) ∙ x" unfolding inner_vec_def (*goal: ‹(∑i::'n∈UNIV. ((u::(real, 'n) vec) $ i - (v::(real, 'n) vec) $ i) * (x::(real, 'n) vec) $ i) = (∑i::'n∈UNIV. (u - v) $ i ∙ x $ i)›*) by simp finally (*calculation: ‹u ∙ x - v ∙ x = (u - v) ∙ x›*) show "?thesis" (*goal: ‹(u - v) ∙ x = u ∙ x - v ∙ x›*) by standard qed lemma dot_right_diff_distrib: fixes u v x :: "real^'n" shows "x ∙ (u - v) = (x ∙ u) - (x ∙ v)" proof (-) (*goal: ‹x ∙ (u - v) = x ∙ u - x ∙ v›*) from inner_commute (*‹?x ∙ ?y = ?y ∙ ?x›*) have "x ∙ (u - v) = (u - v) ∙ x" by auto also (*calculation: ‹x ∙ (u - v) = (u - v) ∙ x›*) from dot_left_diff_distrib[of u v x] (*‹(u - v) ∙ x = u ∙ x - v ∙ x›*) have "… = u ∙ x - v ∙ x" . also (*calculation: ‹x ∙ (u - v) = u ∙ x - v ∙ x›*) from inner_commute[of x] (*‹x ∙ ?y = ?y ∙ x›*) have "… = x ∙ u - x ∙ v" by simp finally (*calculation: ‹x ∙ (u - v) = x ∙ u - x ∙ v›*) show "?thesis" (*goal: ‹x ∙ (u - v) = x ∙ u - x ∙ v›*) . qed lemma am_gm2: fixes a b :: real assumes "a ≥ 0" and "b ≥ 0" shows "sqrt (a * b) ≤ (a + b) / 2" and "sqrt (a * b) = (a + b) / 2 ⟷ a = b" proof (-) (*goals: 1. ‹sqrt ((a::real) * (b::real)) ≤ (a + b) / (2::real)› 2. ‹(sqrt ((a::real) * (b::real)) = (a + b) / (2::real)) = (a = b)›*) have "0 ≤ (a - b) * (a - b)" and "0 = (a - b) * (a - b) ⟷ a = b" (*goals: 1. ‹0 ≤ (a - b) * (a - b)› 2. ‹(0 = (a - b) * (a - b)) = (a = b)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . with right_diff_distrib[of "a - b" a b] (*‹(a - b) * (a - b) = (a - b) * a - (a - b) * b›*) left_diff_distrib[of a b] (*‹(a - b) * ?c = a * ?c - b * ?c›*) have "0 ≤ a * a - 2 * a * b + b * b" and "0 = a * a - 2 * a * b + b * b ⟷ a = b" apply - (*goals: 1. ‹⟦(a - b) * (a - b) = (a - b) * a - (a - b) * b; ⋀c. (a - b) * c = a * c - b * c; 0 ≤ (a - b) * (a - b); (0 = (a - b) * (a - b)) = (a = b)⟧ ⟹ 0 ≤ a * a - 2 * a * b + b * b› 2. ‹⟦(a - b) * (a - b) = (a - b) * a - (a - b) * b; ⋀c. (a - b) * c = a * c - b * c; 0 ≤ (a - b) * (a - b); (0 = (a - b) * (a - b)) = (a = b)⟧ ⟹ (0 = a * a - 2 * a * b + b * b) = (a = b)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . hence "4 * a * b ≤ a * a + 2 * a * b + b * b" and "4 * a * b = a * a + 2 * a * b + b * b ⟷ a = b" apply - (*goals: 1. ‹⟦0 ≤ a * a - 2 * a * b + b * b; (0 = a * a - 2 * a * b + b * b) = (a = b)⟧ ⟹ 4 * a * b ≤ a * a + 2 * a * b + b * b› 2. ‹⟦0 ≤ a * a - 2 * a * b + b * b; (0 = a * a - 2 * a * b + b * b) = (a = b)⟧ ⟹ (4 * a * b = a * a + 2 * a * b + b * b) = (a = b)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . with distrib_right[of "a + b" a b] (*‹((a::real) + (b::real) + a) * b = (a + b) * b + a * b›*) distrib_left[of a b] (*‹a * (b + ?c) = a * b + a * ?c›*) have "4 * a * b ≤ (a + b) * (a + b)" and "4 * a * b = (a + b) * (a + b) ⟷ a = b" apply - (*goals: 1. ‹⟦(a + b + a) * b = (a + b) * b + a * b; ⋀c. a * (b + c) = a * b + a * c; 4 * a * b ≤ a * a + 2 * a * b + b * b; (4 * a * b = a * a + 2 * a * b + b * b) = (a = b)⟧ ⟹ 4 * a * b ≤ (a + b) * (a + b)› 2. ‹⟦(a + b + a) * b = (a + b) * b + a * b; ⋀c. a * (b + c) = a * b + a * c; 4 * a * b ≤ a * a + 2 * a * b + b * b; (4 * a * b = a * a + 2 * a * b + b * b) = (a = b)⟧ ⟹ (4 * a * b = (a + b) * (a + b)) = (a = b)› discuss goal 1*) apply (simp add: field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 77 facts*)) (*discuss goal 2*) apply (simp add: field_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹?a - ?b - ?c = ?a - (?b + ?c)› ‹?a + (?b - ?c) = ?a + ?b - ?c› ‹(?a - ?b = ?c) = (?a = ?c + ?b)› ‹(?a = ?c - ?b) = (?a + ?b = ?c)› ‹?a - (?b - ?c) = ?a + ?c - ?b› ‹?a - ?b + ?c = ?a + ?c - ?b› and more 77 facts*)) (*proven 2 subgoals*) . with real_sqrt_le_mono[of "4 * a * b" "(a + b) * (a + b)"] (*‹4 * a * b ≤ (a + b) * (a + b) ⟹ sqrt (4 * a * b) ≤ sqrt ((a + b) * (a + b))›*) real_sqrt_eq_iff[of "4 * a * b" "(a + b) * (a + b)"] (*‹(sqrt (4 * a * b) = sqrt ((a + b) * (a + b))) = (4 * a * b = (a + b) * (a + b))›*) have "sqrt (4 * a * b) ≤ sqrt ((a + b) * (a + b))" and "sqrt (4 * a * b) = sqrt ((a + b) * (a + b)) ⟷ a = b" apply - (*goals: 1. ‹⟦4 * a * b ≤ (a + b) * (a + b) ⟹ sqrt (4 * a * b) ≤ sqrt ((a + b) * (a + b)); (sqrt (4 * a * b) = sqrt ((a + b) * (a + b))) = (4 * a * b = (a + b) * (a + b)); 4 * a * b ≤ (a + b) * (a + b); (4 * a * b = (a + b) * (a + b)) = (a = b)⟧ ⟹ sqrt (4 * a * b) ≤ sqrt ((a + b) * (a + b))› 2. ‹⟦4 * a * b ≤ (a + b) * (a + b) ⟹ sqrt (4 * a * b) ≤ sqrt ((a + b) * (a + b)); (sqrt (4 * a * b) = sqrt ((a + b) * (a + b))) = (4 * a * b = (a + b) * (a + b)); 4 * a * b ≤ (a + b) * (a + b); (4 * a * b = (a + b) * (a + b)) = (a = b)⟧ ⟹ (sqrt (4 * a * b) = sqrt ((a + b) * (a + b))) = (a = b)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . with ‹a ≥ 0› (*‹0 ≤ a›*) ‹b ≥ 0› (*‹0 ≤ b›*) have "sqrt (4 * a * b) ≤ a + b" and "sqrt (4 * a * b) = a + b ⟷ a = b" apply - (*goals: 1. ‹⟦0 ≤ a; 0 ≤ b; sqrt (4 * a * b) ≤ sqrt ((a + b) * (a + b)); (sqrt (4 * a * b) = sqrt ((a + b) * (a + b))) = (a = b)⟧ ⟹ sqrt (4 * a * b) ≤ a + b› 2. ‹⟦0 ≤ a; 0 ≤ b; sqrt (4 * a * b) ≤ sqrt ((a + b) * (a + b)); (sqrt (4 * a * b) = sqrt ((a + b) * (a + b))) = (a = b)⟧ ⟹ (sqrt (4 * a * b) = a + b) = (a = b)› discuss goal 1*) apply simp (*discuss goal 2*) apply simp (*proven 2 subgoals*) . with real_sqrt_abs2[of 2] (*‹sqrt (2 * 2) = ¦2¦›*) real_sqrt_mult[of 4 "a * b"] (*‹sqrt (4 * (a * b)) = sqrt 4 * sqrt (a * b)›*) show "sqrt (a * b) ≤ (a + b) / 2" and "sqrt (a * b) = (a + b) / 2 ⟷ a = b" apply - (*goals: 1. ‹⟦sqrt (2 * 2) = ¦2¦; sqrt (4 * (a * b)) = sqrt 4 * sqrt (a * b); sqrt (4 * a * b) ≤ a + b; (sqrt (4 * a * b) = a + b) = (a = b)⟧ ⟹ sqrt (a * b) ≤ (a + b) / 2› 2. ‹⟦sqrt (2 * 2) = ¦2¦; sqrt (4 * (a * b)) = sqrt 4 * sqrt (a * b); sqrt (4 * a * b) ≤ a + b; (sqrt (4 * a * b) = a + b) = (a = b)⟧ ⟹ (sqrt (a * b) = (a + b) / 2) = (a = b)› discuss goal 1*) apply (simp add: ac_simps (*‹?a + ?b + ?c = ?a + (?b + ?c)› ‹?a + ?b = ?b + ?a› ‹?b + (?a + ?c) = ?a + (?b + ?c)› ‹?a * ?b * ?c = ?a * (?b * ?c)› ‹?a * ?b = ?b * ?a› ‹?b * (?a * ?c) = ?a * (?b * ?c)› ‹((?a ∧ ?b) ∧ ?c) = (?a ∧ ?b ∧ ?c)› ‹(?a ∧ ?b) = (?b ∧ ?a)› ‹(?b ∧ ?a ∧ ?c) = (?a ∧ ?b ∧ ?c)› ‹((?a ∨ ?b) ∨ ?c) = (?a ∨ ?b ∨ ?c)› ‹(?a ∨ ?b) = (?b ∨ ?a)› ‹(?b ∨ ?a ∨ ?c) = (?a ∨ ?b ∨ ?c)› and more 37 facts*)) (*discuss goal 2*) apply (simp add: ac_simps (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)› ‹(?a::?'a) + (?b::?'a) = ?b + ?a› ‹(?b::?'a) + ((?a::?'a) + (?c::?'a)) = ?a + (?b + ?c)› ‹(?a::?'a) * (?b::?'a) * (?c::?'a) = ?a * (?b * ?c)› ‹(?a::?'a) * (?b::?'a) = ?b * ?a› ‹(?b::?'a) * ((?a::?'a) * (?c::?'a)) = ?a * (?b * ?c)› ‹(((?a::bool) ∧ (?b::bool)) ∧ (?c::bool)) = (?a ∧ ?b ∧ ?c)› ‹((?a::bool) ∧ (?b::bool)) = (?b ∧ ?a)› ‹((?b::bool) ∧ (?a::bool) ∧ (?c::bool)) = (?a ∧ ?b ∧ ?c)› ‹(((?a::bool) ∨ (?b::bool)) ∨ (?c::bool)) = (?a ∨ ?b ∨ ?c)› ‹((?a::bool) ∨ (?b::bool)) = (?b ∨ ?a)› ‹((?b::bool) ∨ (?a::bool) ∨ (?c::bool)) = (?a ∨ ?b ∨ ?c)› and more 37 facts*)) (*proven 2 subgoals*) . qed lemma refl_on_allrel: "refl_on A (A × A)" unfolding refl_on_def (*goal: ‹A × A ⊆ A × A ∧ (∀x∈A. (x, x) ∈ A × A)›*) by simp lemma refl_on_restrict: assumes "refl_on A r" shows "refl_on (A ∩ B) (r ∩ B × B)" proof (-) (*goal: ‹refl_on ((A::'a::type set) ∩ (B::'a::type set)) (Restr (r::('a::type × 'a::type) set) B)›*) from ‹refl_on A r› (*‹refl_on (A::'a::type set) (r::('a::type × 'a::type) set)›*) refl_on_allrel[of B] (*‹refl_on B (B × B)›*) refl_on_Int (*‹⟦refl_on ?A ?r; refl_on ?B ?s⟧ ⟹ refl_on (?A ∩ ?B) (?r ∩ ?s)›*) show "?thesis" (*goal: ‹refl_on (A ∩ B) (Restr r B)›*) by auto qed lemma sym_allrel: "sym (A × A)" unfolding sym_def (*goal: ‹∀(x::'a) y::'a. (x, y) ∈ (A::'a set) × A ⟶ (y, x) ∈ A × A›*) by simp lemma sym_restrict: assumes "sym r" shows "sym (r ∩ A × A)" proof (-) (*goal: ‹sym (Restr r A)›*) from ‹sym r› (*‹sym r›*) sym_allrel (*‹sym (?A × ?A)›*) sym_Int (*‹⟦sym ?r; sym ?s⟧ ⟹ sym (?r ∩ ?s)›*) show "?thesis" (*goal: ‹sym (Restr r A)›*) by auto qed lemma trans_allrel: "trans (A × A)" unfolding trans_def (*goal: ‹∀x y z. (x, y) ∈ A × A ⟶ (y, z) ∈ A × A ⟶ (x, z) ∈ A × A›*) by simp lemma equiv_Int: assumes "equiv A r" and "equiv B s" shows "equiv (A ∩ B) (r ∩ s)" proof (-) (*goal: ‹equiv (A ∩ B) (r ∩ s)›*) from assms (*‹equiv (A::'a set) (r::('a × 'a) set)› ‹equiv B s›*) refl_on_Int[of A r B s] (*‹⟦refl_on A r; refl_on B s⟧ ⟹ refl_on (A ∩ B) (r ∩ s)›*) sym_Int (*‹⟦sym ?r; sym ?s⟧ ⟹ sym (?r ∩ ?s)›*) trans_Int (*‹⟦trans ?r; trans ?s⟧ ⟹ trans (?r ∩ ?s)›*) show "?thesis" (*goal: ‹equiv (A ∩ B) (r ∩ s)›*) unfolding equiv_def (*goal: ‹refl_on (A ∩ B) (r ∩ s) ∧ sym (r ∩ s) ∧ trans (r ∩ s)›*) by auto qed lemma equiv_allrel: "equiv A (A × A)" unfolding equiv_def (*goal: ‹refl_on A (A × A) ∧ sym (A × A) ∧ trans (A × A)›*) by (simp add: refl_on_allrel (*‹refl_on ?A (?A × ?A)›*) sym_allrel (*‹sym (?A × ?A)›*) trans_allrel (*‹trans (?A × ?A)›*)) lemma equiv_restrict: assumes "equiv A r" shows "equiv (A ∩ B) (r ∩ B × B)" proof (-) (*goal: ‹equiv (A ∩ B) (Restr r B)›*) from ‹equiv A r› (*‹equiv A r›*) equiv_allrel[of B] (*‹equiv B (B × B)›*) equiv_Int (*‹⟦equiv ?A ?r; equiv ?B ?s⟧ ⟹ equiv (?A ∩ ?B) (?r ∩ ?s)›*) show "?thesis" (*goal: ‹equiv (A ∩ B) (Restr r B)›*) by auto qed lemma invertible_times_eq_zero: fixes x :: "real^'n" and A :: "real^'n^'n" assumes "invertible A" and "A *v x = 0" shows "x = 0" using assms (*‹invertible (A::((real, 'n) vec, 'n) vec)› ‹A *v x = 0›*) invertible_def (*‹invertible ?A = (∃A'. ?A ** A' = mat 1 ∧ A' ** ?A = mat 1)›*) matrix_left_invertible_ker (*‹(∃B. B ** ?A = mat 1) = (∀x. ?A *v x = 0 ⟶ x = 0)›*) by blast lemma times_invertible_eq_zero: fixes x :: "real^'n" and A :: "real^'n^'n" assumes "invertible A" and "x v* A = 0" shows "x = 0" using transpose_invertible (*‹invertible (?A::((real, ?'n::finite) vec, ?'n::finite) vec) ⟹ invertible (Finite_Cartesian_Product.transpose ?A)›*) assms (*‹invertible A› ‹(x::(real, 'n) vec) v* (A::((real, 'n) vec, 'n) vec) = (0::(real, 'n) vec)›*) invertible_times_eq_zero (*‹⟦invertible ?A; ?A *v ?x = 0⟧ ⟹ ?x = 0›*) by fastforce lemma matrix_id_invertible: "invertible (mat 1 :: ('a::semiring_1)^'n^'n)" by (simp add: invertible_def (*‹invertible ?A = (∃A'. ?A ** A' = mat 1 ∧ A' ** ?A = mat 1)›*)) lemma Image_refl_on_nonempty: assumes "refl_on A r" and "x ∈ A" shows "x ∈ r``{x}" proof (standard) (*goal: ‹(x, x) ∈ r›*) from ‹refl_on A r› (*‹refl_on A r›*) ‹x ∈ A› (*‹(x::'a::type) ∈ (A::'a::type set)›*) show "(x, x) ∈ r" unfolding refl_on_def (*goal: ‹(x, x) ∈ r›*) by simp qed lemma quotient_element_nonempty: assumes "equiv A r" and "X ∈ A//r" shows "∃ x. x ∈ X" using assms (*‹equiv A r› ‹X ∈ A // r›*) in_quotient_imp_non_empty (*‹⟦equiv ?A ?r; ?X ∈ ?A // ?r⟧ ⟹ ?X ≠ {}›*) by fastforce lemma zero_3: "(3::3) = 0" by simp lemma card_suc_ge_insert: fixes A and x shows "card A + 1 ≥ card (insert x A)" using card_insert_le_m1 (*‹⟦0 < ?n; card ?y ≤ ?n - 1⟧ ⟹ card (insert ?x ?y) ≤ ?n›*) by fastforce lemma card_le_UNIV: fixes A :: "('n::finite) set" shows "card A ≤ CARD('n)" by (simp add: card_mono (*‹⟦finite ?B; ?A ⊆ ?B⟧ ⟹ card ?A ≤ card ?B›*)) lemma partition_Image_element: assumes "equiv A r" and "X ∈ A//r" and "x ∈ X" shows "r``{x} = X" by (metis Image_singleton_iff (*‹(?b ∈ ?r `` {?a}) = ((?a, ?b) ∈ ?r)›*) assms (*‹equiv A r› ‹X ∈ A // r› ‹x ∈ X›*) equiv_class_eq_iff (*‹equiv ?A ?r ⟹ ((?x, ?y) ∈ ?r) = (?r `` {?x} = ?r `` {?y} ∧ ?x ∈ ?A ∧ ?y ∈ ?A)›*) quotientE (*‹⟦?X ∈ ?A // ?r; ⋀x. ⟦?X = ?r `` {x}; x ∈ ?A⟧ ⟹ ?P⟧ ⟹ ?P›*)) lemma card_insert_ge: "card (insert x A) ≥ card A" by (metis card.infinite (*‹infinite (?A::?'a set) ⟹ card ?A = (0::nat)›*) card_insert_le (*‹card (?A::?'a set) ≤ card (insert (?x::?'a) ?A)›*) zero_le (*‹(0::?'a) ≤ (?x::?'a)›*)) lemma choose_1: assumes "card S = 1" shows "∃ x. S = {x}" using ‹card S = 1› (*‹card S = 1›*) card_eq_SucD[of S 0] (*‹card S = Suc 0 ⟹ ∃b B. S = insert b B ∧ b ∉ B ∧ card B = 0 ∧ (0 = 0 ⟶ B = {})›*) by simp lemma choose_2: assumes "card S = 2" shows "∃ x y. S = {x,y}" proof (-) (*goal: ‹∃x y. S = {x, y}›*) from ‹card S = 2› (*‹card S = 2›*) card_eq_SucD[of S 1] (*‹card S = Suc 1 ⟹ ∃b B. S = insert b B ∧ b ∉ B ∧ card B = 1 ∧ (1 = 0 ⟶ B = {})›*) obtain x and T where "S = insert x T" and "card T = 1" (*goal: ‹(⋀x T. ⟦S = insert x T; card T = 1⟧ ⟹ thesis) ⟹ thesis›*) by auto from ‹card T = 1› (*‹card T = 1›*) choose_1 (*‹card (?S::?'a set) = (1::nat) ⟹ ∃x::?'a. ?S = {x}›*) obtain y where "T = {y}" (*goal: ‹(⋀y::'a. (T::'a set) = {y} ⟹ thesis::bool) ⟹ thesis›*) by auto with ‹S = insert x T› (*‹(S::'a::type set) = insert (x::'a::type) (T::'a::type set)›*) have "S = {x,y}" by simp thus "∃ x y. S = {x,y}" by auto qed lemma choose_3: assumes "card S = 3" shows "∃ x y z. S = {x,y,z}" proof (-) (*goal: ‹∃x y z. S = {x, y, z}›*) from ‹card S = 3› (*‹card S = 3›*) card_eq_SucD[of S 2] (*‹card S = Suc 2 ⟹ ∃b B. S = insert b B ∧ b ∉ B ∧ card B = 2 ∧ (2 = 0 ⟶ B = {})›*) obtain x and T where "S = insert x T" and "card T = 2" (*goal: ‹(⋀x T. ⟦S = insert x T; card T = 2⟧ ⟹ thesis) ⟹ thesis›*) by auto from ‹card T = 2› (*‹card T = 2›*) choose_2[of T] (*‹card T = 2 ⟹ ∃x y. T = {x, y}›*) obtain y and z where "T = {y,z}" (*goal: ‹(⋀y z. T = {y, z} ⟹ thesis) ⟹ thesis›*) by auto with ‹S = insert x T› (*‹(S::'a set) = insert (x::'a) (T::'a set)›*) have "S = {x,y,z}" by simp thus "∃ x y z. S = {x,y,z}" by auto qed lemma card_gt_0_diff_singleton: assumes "card S > 0" and "x ∈ S" shows "card (S - {x}) = card S - 1" proof (-) (*goal: ‹card (S - {x}) = card S - 1›*) from ‹card S > 0› (*‹0 < card S›*) have "finite S" by (rule card_ge_0_finite (*‹0 < card ?A ⟹ finite ?A›*)) with ‹x ∈ S› (*‹(x::'a) ∈ (S::'a set)›*) show "card (S - {x}) = card S - 1" by (simp add: card_Diff_singleton (*‹?x ∈ ?A ⟹ card (?A - {?x}) = card ?A - 1›*)) qed lemma eq_3_or_of_3: fixes j :: 4 shows "j = 3 ∨ (∃ j'::3. j = of_int (Rep_bit1 j'))" proof (induct j) (*goal: ‹⋀z. ⟦0 ≤ z; z < int CARD(4)⟧ ⟹ of_int z = 3 ∨ (∃j'. of_int z = of_int (Rep_bit1 j'))›*) fix j_int :: int assume "0 ≤ j_int" (*‹(0::int) ≤ (j_int::int)›*) assume "j_int < int CARD(4)" (*‹(j_int::int) < int CARD(4)›*) hence "j_int ≤ 3" by simp show "of_int j_int = (3::4) ∨ (∃ j'::3. of_int j_int = of_int (Rep_bit1 j'))" proof (cases) (*goals: 1. ‹?P ⟹ of_int j_int = 3 ∨ (∃j'. of_int j_int = of_int (Rep_bit1 j'))› 2. ‹¬ ?P ⟹ of_int j_int = 3 ∨ (∃j'. of_int j_int = of_int (Rep_bit1 j'))›*) assume "j_int = 3" (*‹(j_int::int) = (3::int)›*) thus "of_int j_int = (3::4) ∨ (∃ j'::3. of_int j_int = of_int (Rep_bit1 j'))" by simp next (*goal: ‹j_int ≠ 3 ⟹ of_int j_int = 3 ∨ (∃j'. of_int j_int = of_int (Rep_bit1 j'))›*) assume "j_int ≠ 3" (*‹(j_int::int) ≠ (3::int)›*) with ‹j_int ≤ 3› (*‹j_int ≤ 3›*) have "j_int < 3" by simp with ‹0 ≤ j_int› (*‹0 ≤ j_int›*) have "j_int ∈ {0..<3}" by simp hence "Rep_bit1 (Abs_bit1 j_int :: 3) = j_int" by (simp add: bit1.Abs_inverse (*‹?m ∈ {0..<int CARD(?'a bit1)} ⟹ Rep_bit1 (Abs_bit1 ?m) = ?m›*)) hence "of_int j_int = of_int (Rep_bit1 (Abs_bit1 j_int :: 3))" by simp thus "of_int j_int = (3::4) ∨ (∃ j'::3. of_int j_int = of_int (Rep_bit1 j'))" by auto qed qed lemma sgn_plus: fixes x y :: "'a::linordered_idom" assumes "sgn x = sgn y" shows "sgn (x + y) = sgn x" by (simp add: assms (*‹sgn x = sgn y›*) same_sgn_sgn_add (*‹sgn ?b = sgn ?a ⟹ sgn (?a + ?b) = sgn ?a›*)) lemma sgn_div: fixes x y :: "'a::linordered_field" assumes "y ≠ 0" and "sgn x = sgn y" shows "x / y > 0" using assms (*‹y ≠ 0› ‹sgn x = sgn y›*) sgn_1_pos (*‹(sgn ?a = 1) = (0 < ?a)›*) sgn_eq_0_iff (*‹(sgn ?a = 0) = (?a = 0)›*) by fastforce lemma abs_plus: fixes x y :: "'a::linordered_idom" assumes "sgn x = sgn y" shows "¦x + y¦ = ¦x¦ + ¦y¦" by (simp add: assms (*‹sgn x = sgn y›*) same_sgn_abs_add (*‹sgn ?b = sgn ?a ⟹ ¦?a + ?b¦ = ¦?a¦ + ¦?b¦›*)) lemma sgn_plus_abs: fixes x y :: "'a::linordered_idom" assumes "¦x¦ > ¦y¦" shows "sgn (x + y) = sgn x" apply (cases "x > 0") (*goals: 1. ‹0 < x ⟹ sgn (x + y) = sgn x› 2. ‹¬ 0 < x ⟹ sgn (x + y) = sgn x› discuss goal 1*) apply ((use assms in auto)[1]) (*discuss goal 2*) apply ((use assms in auto)[1]) (*proven 2 subgoals*) . end
{ "path": "afp-2025-02-12/thys/Tarskis_Geometry/Miscellany.thy", "repo": "afp-2025-02-12", "sha": "18f5efe3581d5f7d146102856023e81a5ad349cca855c8d87384ef39d55d3117" }
theory RM_Sums_Diophantine imports Equation_Setup "../Diophantine/Register_Machine_Sums" "../Diophantine/Binary_And" begin context register_machine begin definition sum_ssub_nzero_of_bit_and :: "polynomial ⇒ nat ⇒ polynomial list ⇒ polynomial list ⇒ relation" ("[_ = ∑S- _ '(_ && _')]") where "[x = ∑S- d (s && z)] ≡ let x' = push_param x (length p); s' = push_param_list s (length p); z' = push_param_list z (length p) in [∃length p] [∀<length p] (λi. [Param i = s'!i && z'!i]) [∧] x' [=] ([∑S-] p d Param)" lemma sum_ssub_nzero_of_bit_and_dioph[dioph]: fixes s z :: "polynomial list" and d :: nat and x shows "is_dioph_rel [x = ∑S- d (s && z)]" unfolding sum_ssub_nzero_of_bit_and_def (*goal: ‹is_dioph_rel (let x' = push_param x (length p); s' = push_param_list s (length p); z' = push_param_list z (length p) in [∃length p] [∀<length p] λi. [polynomial.Param i = s' ! i && z' ! i] [∧] x' [=] [∑S-] p d polynomial.Param)›*) by (auto simp add: dioph (*‹⟦is_dioph_rel ?A; is_dioph_rel ?B⟧ ⟹ is_dioph_rel (?A [∨] ?B)› ‹⟦is_dioph_rel ?A; is_dioph_rel ?B⟧ ⟹ is_dioph_rel (?A [∧] ?B)› ‹is_dioph_rel TRUE› ‹is_dioph_rel (?Q [=] ?R)› ‹is_dioph_rel (?Q [<] ?R)› ‹is_dioph_rel ([0=] ?Q)› ‹is_dioph_rel (?Q [>] ?R)› ‹is_dioph_rel (?Q [≤] ?R)› ‹is_dioph_rel (?Q [≥] ?R)› ‹list_all (is_dioph_rel ∘ ?DF) ?L ⟹ is_dioph_rel [∀ in ?L] ?DF› ‹∀i<?n. is_dioph_rel (?DF i) ⟹ is_dioph_rel [∀<?n] ?DF› ‹is_dioph_rel ?D ⟹ is_dioph_rel ([∃?n] ?D)› and more 11 facts*)) lemma sum_rsub_nzero_of_bit_and_eval: fixes z s :: "polynomial list" and d :: nat and x :: polynomial assumes "length s = Suc m" "length z = Suc m" "length p > 0" shows "eval [x = ∑S- d (s && z)] a ⟷ peval x a = ∑S- p d (λk. peval (s!k) a && peval (z!k) a)" (is "?P ⟷ ?Q") proof (-) (*goal: ‹eval [x = ∑S- d (s && z)] a = (peval x a = ∑S- p d (λk. peval (s ! k) a && peval (z ! k) a) )›*) have invariance: "∀k<length p. y1 k = y2 k ⟹ ∑S- p d y1 = ∑S- p d y2" for y1 and y2 unfolding sum_ssub_nzero.simps (*goal: ‹∀k<length p. y1 k = y2 k ⟹ (∑k = 0..length p - 1. if issub (p ! k) ∧ d = goes_to (p ! k) then y1 k else 0) = (∑k = 0..length p - 1. if issub (p ! k) ∧ d = goes_to (p ! k) then y2 k else 0)›*) apply (intro sum.cong (*‹⟦?A = ?B; ⋀x. x ∈ ?B ⟹ ?g x = ?h x⟧ ⟹ sum ?g ?A = sum ?h ?B›*), simp) (*goal: ‹∀k<length p. y1 k = y2 k ⟹ (∑k = 0..length p - 1. if issub (p ! k) ∧ d = goes_to (p ! k) then y1 k else 0) = (∑k = 0..length p - 1. if issub (p ! k) ∧ d = goes_to (p ! k) then y2 k else 0)›*) using ‹length p > 0› (*‹(0::nat) < length (p::instruction list)›*) apply auto (*goal: ‹⋀x. ⟦∀k<length p. y1 k = y2 k; x ∈ {0..length p - 1}⟧ ⟹ (if issub (p ! x) ∧ d = goes_to (p ! x) then y1 x else 0) = (if issub (p ! x) ∧ d = goes_to (p ! x) then y2 x else 0)›*) by (metis Suc_pred (*‹0 < ?n ⟹ Suc (?n - Suc 0) = ?n›*) le_imp_less_Suc (*‹?m ≤ ?n ⟹ ?m < Suc ?n›*) length_greater_0_conv (*‹(0 < length ?xs) = (?xs ≠ [])›*)) have len_ps: "length s = length p" using m_def (*‹m ≡ length (p::instruction list) - (1::nat)›*) ‹length s = Suc m› (*‹length s = Suc m›*) ‹length p > 0› (*‹0 < length p›*) by auto have len_pz: "length z = length p" using m_def (*‹m ≡ length (p::instruction list) - (1::nat)›*) ‹length z = Suc m› (*‹length z = Suc m›*) ‹length p > 0› (*‹0 < length p›*) by auto show "?thesis" (*goal: ‹eval [x = ∑S- d (s && z)] a = (peval x a = ∑S- p d (λk. peval (s ! k) a && peval (z ! k) a) )›*) proof (rule) (*goals: 1. ‹eval [x = ∑S- d (s && z)] a ⟹ peval x a = ∑S- p d (λk. peval (s ! k) a && peval (z ! k) a) › 2. ‹peval x a = ∑S- p d (λk. peval (s ! k) a && peval (z ! k) a) ⟹ eval [x = ∑S- d (s && z)] a›*) assume "?P" (*‹eval [x::polynomial = ∑S- d::nat (s::polynomial list && z::polynomial list)] (a::nat ⇒ nat)›*) thus "?Q" using sum_ssub_nzero_of_bit_and_def (*‹[?x = ∑S- ?d (?s && ?z)] ≡ let x' = push_param ?x (length p); s' = push_param_list ?s (length p); z' = push_param_list ?z (length p) in [∃length p] [∀<length p] λi. [polynomial.Param i = s' ! i && z' ! i] [∧] x' [=] [∑S-] p ?d polynomial.Param›*) ‹length p > 0› (*‹0 < length p›*) apply (auto simp add: defs (*‹❙0 = polynomial.Const (0::nat)› ‹❙1 = polynomial.Const (1::nat)› ‹(?Q::polynomial) [=] (?R::polynomial) ≡ BINARY (=) ?Q ?R› ‹(?Q::polynomial) [<] (?R::polynomial) ≡ BINARY (<) ?Q ?R› ‹(?Q::polynomial) [≤] (?R::polynomial) ≡ ?Q [<] ?R [∨] ?Q [=] ?R› ‹(?Q::polynomial) [>] (?R::polynomial) ≡ ?R [<] ?Q› ‹(?Q::polynomial) [≥] (?R::polynomial) ≡ ?Q [>] ?R [∨] ?Q [=] ?R› ‹eval (LARY (?R::nat list list ⇒ bool) (?PLL::polynomial list list)) (?a::nat ⇒ nat) = ?R (map (map (λP::polynomial. peval P ?a)) ?PLL)› ‹UNARY (?R::nat ⇒ bool) (?P::polynomial) = NARY (λl::nat list. ?R (l ! (0::nat))) [?P]› ‹BINARY (?R::nat ⇒ nat ⇒ bool) (?P₁::polynomial) (?P₂::polynomial) = NARY (λl::nat list. ?R (l ! (0::nat)) (l ! (1::nat))) [?P₁, ?P₂]› ‹TERNARY (?R::nat ⇒ nat ⇒ nat ⇒ bool) (?P₁::polynomial) (?P₂::polynomial) (?P₃::polynomial) = NARY (λl::nat list. ?R (l ! (0::nat)) (l ! (1::nat)) (l ! (2::nat))) [?P₁, ?P₂, ?P₃]› ‹QUATERNARY (?R::nat ⇒ nat ⇒ nat ⇒ nat ⇒ bool) (?P₁::polynomial) (?P₂::polynomial) (?P₃::polynomial) (?P₄::polynomial) = NARY (λl::nat list. ?R (l ! (0::nat)) (l ! (1::nat)) (l ! (2::nat)) (l ! (3::nat))) [?P₁, ?P₂, ?P₃, ?P₄]› and more 19 facts*) push_push (*‹length (?ns::nat list) = (?n::nat) ⟹ peval (push_param (?P::polynomial) ?n) (push_list (?a::nat ⇒ nat) ?ns) = peval ?P ?a›*)) (*goal: ‹peval x a = ∑S- p d (λk. peval (s ! k) a && peval (z ! k) a) ›*) using push_push_map_i (*‹⟦length ?ns = ?n; ?i < length ?ls⟧ ⟹ peval (map (λx. push_param x ?n) ?ls ! ?i) (push_list ?a ?ns) = list_eval ?ls ?a ?i›*) apply (simp add: push_param_list_def (*‹push_param_list ?s ?k ≡ map (λx. push_param x ?k) ?s›*) len_ps (*‹length s = length p›*) len_pz (*‹length z = length p›*)) (*goal: ‹⋀ks. ⟦⋀x d s z. [x = ∑S- d (s && z)] ≡ [∃length ks] [∀<length ks] λi. NARY (λl. l ! 0 = l ! Suc 0 && l ! 2) [polynomial.Param i, push_param_list s (length ks) ! i, push_param_list z (length ks) ! i] [∧] NARY (λl. l ! 0 = l ! Suc 0) [push_param x (length ks), [∑S-] p d polynomial.Param]; p ≠ []; length p = length ks; ∀k<length ks. push_list a ks k = peval (push_param_list s (length ks) ! k) (push_list a ks) && peval (push_param_list z (length ks) ! k) (push_list a ks); peval x a = ∑S- p d push_list a ks ⟧ ⟹ ∑S- p d push_list a ks = ∑S- p d (λk. peval (s ! k) a && peval (z ! k) a) ›*) unfolding list_eval_def (*goal: ‹⋀ks::nat list. ⟦⋀(x::polynomial) (d::nat) (s::polynomial list) z::polynomial list. [x = ∑S- d (s && z)] ≡ [∃length ks] [∀<length ks] λi::nat. NARY (λl::nat list. l ! (0::nat) = l ! Suc (0::nat) && l ! (2::nat)) [polynomial.Param i, map (λx::polynomial. push_param x (length ks)) s ! i, map (λx::polynomial. push_param x (length ks)) z ! i] [∧] NARY (λl::nat list. l ! (0::nat) = l ! Suc (0::nat)) [push_param x (length ks), [∑S-] p::instruction list d polynomial.Param]; p ≠ []; length p = length ks; ∀k<length ks. push_list (a::nat ⇒ nat) ks k = map (λx::polynomial. peval x a) (s::polynomial list) ! k && map (λx::polynomial. peval x a) (z::polynomial list) ! k; peval (x::polynomial) a = ∑S- p (d::nat) push_list a ks ; ⋀(ns::nat list) (n::nat) (i::nat) (ls::polynomial list) a::nat ⇒ nat. ⟦length ns = n; i < length ls⟧ ⟹ peval (push_param (ls ! i) n) (push_list a ns) = map (λx::polynomial. peval x a) ls ! i⟧ ⟹ ∑S- p d push_list a ks = ∑S- p d (λk::nat. peval (s ! k) a && peval (z ! k) a) ›*) apply (auto simp: assms (*‹length s = Suc m› ‹length z = Suc m› ‹0 < length p›*) len_ps (*‹length s = length p›*) len_pz (*‹length z = length p›*) invariance (*‹∀k<length p. ?y1.0 k = ?y2.0 k ⟹ ∑S- p d ?y1.0 = ∑S- p d ?y2.0 ›*)) (*goal: ‹⋀ks. ⟦⋀x d s z. [x = ∑S- d (s && z)] ≡ [∃length ks] [∀<length ks] λi. NARY (λl. l ! 0 = l ! Suc 0 && l ! 2) [polynomial.Param i, map (λx. push_param x (length ks)) s ! i, map (λx. push_param x (length ks)) z ! i] [∧] NARY (λl. l ! 0 = l ! Suc 0) [push_param x (length ks), [∑S-] p d polynomial.Param]; p ≠ []; length p = length ks; ∀k<length ks. push_list a ks k = map (λx. peval x a) s ! k && map (λx. peval x a) z ! k; peval x a = ∑S- p d push_list a ks ; ⋀ns n i ls a. ⟦length ns = n; i < length ls⟧ ⟹ peval (push_param (ls ! i) n) (push_list a ns) = map (λx. peval x a) ls ! i⟧ ⟹ ∑S- p d push_list a ks = ∑S- p d (λk. peval (s ! k) a && peval (z ! k) a) ›*) apply (rule sum_ssub_nzero_cong (*‹∀k. k ≤ length ?p - 1 ∧ issub (?p ! k) ∧ ?l = goes_to (?p ! k) ⟶ ?f k = ?g k ⟹ ∑S- ?p ?l ?f = ∑S- ?p ?l ?g ›*)) (*goal: ‹⋀ks. ⟦⋀x d s z. [x = ∑S- d (s && z)] ≡ [∃length ks] [∀<length ks] λi. NARY (λl. l ! 0 = l ! Suc 0 && l ! 2) [polynomial.Param i, map (λx. push_param x (length ks)) s ! i, map (λx. push_param x (length ks)) z ! i] [∧] NARY (λl. l ! 0 = l ! Suc 0) [push_param x (length ks), [∑S-] p d polynomial.Param]; p ≠ []; length p = length ks; ∀k<length ks. push_list a ks k = map (λx. peval x a) s ! k && map (λx. peval x a) z ! k; peval x a = ∑S- p d push_list a ks ; ⋀ns n i ls a. ⟦length ns = n; i < length ls⟧ ⟹ peval (push_param (ls ! i) n) (push_list a ns) = peval (ls ! i) a⟧ ⟹ ∑S- p d push_list a ks = ∑S- p d (λk. peval (s ! k) a && peval (z ! k) a) ›*) apply auto (*goal: ‹⋀ks. ⟦⋀x d s z. [x = ∑S- d (s && z)] ≡ [∃length ks] [∀<length ks] λi. NARY (λl. l ! 0 = l ! Suc 0 && l ! 2) [polynomial.Param i, map (λx. push_param x (length ks)) s ! i, map (λx. push_param x (length ks)) z ! i] [∧] NARY (λl. l ! 0 = l ! Suc 0) [push_param x (length ks), [∑S-] p d polynomial.Param]; p ≠ []; length p = length ks; ∀k<length ks. push_list a ks k = map (λx. peval x a) s ! k && map (λx. peval x a) z ! k; peval x a = ∑S- p d push_list a ks ; ⋀ns n i ls a. ⟦length ns = n; i < length ls⟧ ⟹ peval (push_param (ls ! i) n) (push_list a ns) = peval (ls ! i) a⟧ ⟹ ∀k. k ≤ length p - 1 ∧ issub (p ! k) ∧ d = goes_to (p ! k) ⟶ push_list a ks k = peval (s ! k) a && peval (z ! k) a›*) by (metis (no_types, lifting) One_nat_def (*‹1 = Suc 0›*) assms( (*‹length s = Suc m›*) 1) assms( (*‹length z = Suc m›*) 2) le_imp_less_Suc (*‹?m ≤ ?n ⟹ ?m < Suc ?n›*) len_ps (*‹length s = length p›*) m_def (*‹m ≡ length p - 1›*) nth_map (*‹?n < length ?xs ⟹ map ?f ?xs ! ?n = ?f (?xs ! ?n)›*)) next (*goal: ‹peval x a = ∑S- p d (λk. peval (s ! k) a && peval (z ! k) a) ⟹ eval [x = ∑S- d (s && z)] a›*) assume "?Q" (*‹peval (x::polynomial) (a::nat ⇒ nat) = ∑S- (p::instruction list) (d::nat) (λk::nat. peval ((s::polynomial list) ! k) a && peval ((z::polynomial list) ! k) a) ›*) thus "?P" using sum_ssub_nzero_of_bit_and_def (*‹[?x = ∑S- ?d (?s && ?z)] ≡ let x' = push_param ?x (length p); s' = push_param_list ?s (length p); z' = push_param_list ?z (length p) in [∃length p] [∀<length p] λi. [polynomial.Param i = s' ! i && z' ! i] [∧] x' [=] [∑S-] p ?d polynomial.Param›*) ‹length p > 0› (*‹0 < length p›*) apply (auto simp add: defs (*‹❙0 = polynomial.Const 0› ‹❙1 = polynomial.Const 1› ‹?Q [=] ?R ≡ BINARY (=) ?Q ?R› ‹?Q [<] ?R ≡ BINARY (<) ?Q ?R› ‹?Q [≤] ?R ≡ ?Q [<] ?R [∨] ?Q [=] ?R› ‹?Q [>] ?R ≡ ?R [<] ?Q› ‹?Q [≥] ?R ≡ ?Q [>] ?R [∨] ?Q [=] ?R› ‹eval (LARY ?R ?PLL) ?a = ?R (map (map (λP. peval P ?a)) ?PLL)› ‹UNARY ?R ?P = NARY (λl. ?R (l ! 0)) [?P]› ‹BINARY ?R ?P₁ ?P₂ = NARY (λl. ?R (l ! 0) (l ! 1)) [?P₁, ?P₂]› ‹TERNARY ?R ?P₁ ?P₂ ?P₃ = NARY (λl. ?R (l ! 0) (l ! 1) (l ! 2)) [?P₁, ?P₂, ?P₃]› ‹QUATERNARY ?R ?P₁ ?P₂ ?P₃ ?P₄ = NARY (λl. ?R (l ! 0) (l ! 1) (l ! 2) (l ! 3)) [?P₁, ?P₂, ?P₃, ?P₄]› and more 19 facts*) push_push (*‹length ?ns = ?n ⟹ peval (push_param ?P ?n) (push_list ?a ?ns) = peval ?P ?a›*)) (*goal: ‹eval [x = ∑S- d (s && z)] a›*) apply (rule exI[of _ "map (λk. peval (s ! k) a && peval (z ! k) a) [0..<length p]"] (*‹?P (map (λk. peval (s ! k) a && peval (z ! k) a) [0..<length p]) ⟹ ∃x. ?P x›*), simp) (*goal: ‹⟦peval x a = ∑S- p d (λk. peval (s ! k) a && peval (z ! k) a) ; ⋀x d s z. [x = ∑S- d (s && z)] ≡ [∃length p] [∀<length p] λi. NARY (λl. l ! 0 = l ! Suc 0 && l ! 2) [polynomial.Param i, push_param_list s (length p) ! i, push_param_list z (length p) ! i] [∧] NARY (λl. l ! 0 = l ! Suc 0) [push_param x (length p), [∑S-] p d polynomial.Param]; p ≠ []⟧ ⟹ ∃ks. length p = length ks ∧ (∀k<length p. push_list a ks k = peval (push_param_list s (length p) ! k) (push_list a ks) && peval (push_param_list z (length p) ! k) (push_list a ks)) ∧ peval (push_param x (length p)) (push_list a ks) = ∑S- p d push_list a ks ›*) using push_push (*‹length ?ns = ?n ⟹ peval (push_param ?P ?n) (push_list ?a ?ns) = peval ?P ?a›*) push_push_map_i (*‹⟦length (?ns::nat list) = (?n::nat); (?i::nat) < length (?ls::polynomial list)⟧ ⟹ peval (map (λx::polynomial. push_param x ?n) ?ls ! ?i) (push_list (?a::nat ⇒ nat) ?ns) = list_eval ?ls ?a ?i›*) by (simp add: push_param_list_def (*‹push_param_list (?s::polynomial list) (?k::nat) ≡ map (λx::polynomial. push_param x ?k) ?s›*) invariance (*‹∀k<length (p::instruction list). (?y1.0::nat ⇒ nat) k = (?y2.0::nat ⇒ nat) k ⟹ ∑S- p (d::nat) ?y1.0 = ∑S- p d ?y2.0 ›*) push_list_eval (*‹(?i::nat) < length (?ns::nat list) ⟹ push_list (?a::nat ⇒ nat) ?ns ?i = ?ns ! ?i›*) len_ps (*‹length (s::polynomial list) = length (p::instruction list)›*) len_pz (*‹length (z::polynomial list) = length (p::instruction list)›*)) qed qed definition sum_ssub_zero_of_bit_and :: "polynomial ⇒ nat ⇒ polynomial list ⇒ polynomial list ⇒ relation" ("[_ = ∑S0 _ '(_ && _')]") where "[x = ∑S0 d (s && z)] ≡ let x' = push_param x (length p); s' = push_param_list s (length p); z' = push_param_list z (length p) in [∃length p] [∀<length p] (λi. [Param i = s'!i && z'!i]) [∧] x' [=] [∑S0] p d Param" lemma sum_ssub_zero_of_bit_and_dioph[dioph]: fixes s z :: "polynomial list" and d :: nat and x shows "is_dioph_rel [x = ∑S0 d (s && z)]" unfolding sum_ssub_zero_of_bit_and_def (*goal: ‹is_dioph_rel (let x' = push_param x (length p); s' = push_param_list s (length p); z' = push_param_list z (length p) in [∃length p] [∀<length p] λi. [polynomial.Param i = s' ! i && z' ! i] [∧] x' [=] [∑S0] p d polynomial.Param)›*) by (auto simp add: dioph (*‹⟦is_dioph_rel ?A; is_dioph_rel ?B⟧ ⟹ is_dioph_rel (?A [∨] ?B)› ‹⟦is_dioph_rel ?A; is_dioph_rel ?B⟧ ⟹ is_dioph_rel (?A [∧] ?B)› ‹is_dioph_rel TRUE› ‹is_dioph_rel (?Q [=] ?R)› ‹is_dioph_rel (?Q [<] ?R)› ‹is_dioph_rel ([0=] ?Q)› ‹is_dioph_rel (?Q [>] ?R)› ‹is_dioph_rel (?Q [≤] ?R)› ‹is_dioph_rel (?Q [≥] ?R)› ‹list_all (is_dioph_rel ∘ ?DF) ?L ⟹ is_dioph_rel [∀ in ?L] ?DF› ‹∀i<?n. is_dioph_rel (?DF i) ⟹ is_dioph_rel [∀<?n] ?DF› ‹is_dioph_rel ?D ⟹ is_dioph_rel ([∃?n] ?D)› and more 12 facts*)) lemma sum_rsub_zero_of_bit_and_eval: fixes z s :: "polynomial list" and d :: nat and x :: polynomial assumes "length s = Suc m" "length z = Suc m" "length p > 0" shows "eval [x = ∑S0 d (s && z)] a ⟷ peval x a = ∑S0 p d (λk. peval (s!k) a && peval (z!k) a)" (is "?P ⟷ ?Q") proof (-) (*goal: ‹eval [x::polynomial = ∑S0 d::nat (s::polynomial list && z::polynomial list)] (a::nat ⇒ nat) = (peval x a = ∑S0 (p::instruction list) d (λk::nat. peval (s ! k) a && peval (z ! k) a) )›*) have invariance: "∀k<length p. y1 k = y2 k ⟹ ∑S0 p d y1 = ∑S0 p d y2" for y1 and y2 unfolding sum_ssub_zero.simps (*goal: ‹∀k<length p. y1 k = y2 k ⟹ (∑k = 0..length p - 1. if issub (p ! k) ∧ d = goes_to_alt (p ! k) then y1 k else 0) = (∑k = 0..length p - 1. if issub (p ! k) ∧ d = goes_to_alt (p ! k) then y2 k else 0)›*) apply (intro sum.cong (*‹⟦?A = ?B; ⋀x. x ∈ ?B ⟹ ?g x = ?h x⟧ ⟹ sum ?g ?A = sum ?h ?B›*), simp) (*goal: ‹∀k<length p. y1 k = y2 k ⟹ (∑k = 0..length p - 1. if issub (p ! k) ∧ d = goes_to_alt (p ! k) then y1 k else 0) = (∑k = 0..length p - 1. if issub (p ! k) ∧ d = goes_to_alt (p ! k) then y2 k else 0)›*) using ‹length p > 0› (*‹0 < length p›*) apply auto (*goal: ‹⋀x. ⟦∀k<length p. y1 k = y2 k; x ∈ {0..length p - 1}⟧ ⟹ (if issub (p ! x) ∧ d = goes_to_alt (p ! x) then y1 x else 0) = (if issub (p ! x) ∧ d = goes_to_alt (p ! x) then y2 x else 0)›*) by (metis Suc_pred (*‹0 < ?n ⟹ Suc (?n - Suc 0) = ?n›*) le_imp_less_Suc (*‹?m ≤ ?n ⟹ ?m < Suc ?n›*) length_greater_0_conv (*‹(0 < length ?xs) = (?xs ≠ [])›*)) have len_ps: "length s = length p" using m_def (*‹m ≡ length p - 1›*) ‹length s = Suc m› (*‹length (s::polynomial list) = Suc m›*) ‹length p > 0› (*‹0 < length p›*) by auto have len_pz: "length z = length p" using m_def (*‹m ≡ length (p::instruction list) - (1::nat)›*) ‹length z = Suc m› (*‹length z = Suc m›*) ‹length p > 0› (*‹0 < length p›*) by auto show "?thesis" (*goal: ‹eval [x = ∑S0 d (s && z)] a = (peval x a = ∑S0 p d (λk. peval (s ! k) a && peval (z ! k) a) )›*) proof (rule) (*goals: 1. ‹eval [x = ∑S0 d (s && z)] a ⟹ peval x a = ∑S0 p d (λk. peval (s ! k) a && peval (z ! k) a) › 2. ‹peval x a = ∑S0 p d (λk. peval (s ! k) a && peval (z ! k) a) ⟹ eval [x = ∑S0 d (s && z)] a›*) assume "?P" (*‹eval [x::polynomial = ∑S0 d::nat (s::polynomial list && z::polynomial list)] (a::nat ⇒ nat)›*) thus "?Q" using sum_ssub_zero_of_bit_and_def (*‹[?x = ∑S0 ?d (?s && ?z)] ≡ let x' = push_param ?x (length p); s' = push_param_list ?s (length p); z' = push_param_list ?z (length p) in [∃length p] [∀<length p] λi. [polynomial.Param i = s' ! i && z' ! i] [∧] x' [=] [∑S0] p ?d polynomial.Param›*) ‹length p > 0› (*‹0 < length p›*) apply (auto simp add: defs (*‹❙0 = polynomial.Const 0› ‹❙1 = polynomial.Const 1› ‹?Q [=] ?R ≡ BINARY (=) ?Q ?R› ‹?Q [<] ?R ≡ BINARY (<) ?Q ?R› ‹?Q [≤] ?R ≡ ?Q [<] ?R [∨] ?Q [=] ?R› ‹?Q [>] ?R ≡ ?R [<] ?Q› ‹?Q [≥] ?R ≡ ?Q [>] ?R [∨] ?Q [=] ?R› ‹eval (LARY ?R ?PLL) ?a = ?R (map (map (λP. peval P ?a)) ?PLL)› ‹UNARY ?R ?P = NARY (λl. ?R (l ! 0)) [?P]› ‹BINARY ?R ?P₁ ?P₂ = NARY (λl. ?R (l ! 0) (l ! 1)) [?P₁, ?P₂]› ‹TERNARY ?R ?P₁ ?P₂ ?P₃ = NARY (λl. ?R (l ! 0) (l ! 1) (l ! 2)) [?P₁, ?P₂, ?P₃]› ‹QUATERNARY ?R ?P₁ ?P₂ ?P₃ ?P₄ = NARY (λl. ?R (l ! 0) (l ! 1) (l ! 2) (l ! 3)) [?P₁, ?P₂, ?P₃, ?P₄]› and more 19 facts*) push_push (*‹length ?ns = ?n ⟹ peval (push_param ?P ?n) (push_list ?a ?ns) = peval ?P ?a›*)) (*goal: ‹peval x a = ∑S0 p d (λk. peval (s ! k) a && peval (z ! k) a) ›*) using push_push_map_i (*‹⟦length ?ns = ?n; ?i < length ?ls⟧ ⟹ peval (map (λx. push_param x ?n) ?ls ! ?i) (push_list ?a ?ns) = list_eval ?ls ?a ?i›*) apply (simp add: push_param_list_def (*‹push_param_list ?s ?k ≡ map (λx. push_param x ?k) ?s›*) len_ps (*‹length s = length p›*) len_pz (*‹length z = length p›*)) (*goal: ‹⋀ks. ⟦⋀x d s z. [x = ∑S0 d (s && z)] ≡ [∃length ks] [∀<length ks] λi. NARY (λl. l ! 0 = l ! Suc 0 && l ! 2) [polynomial.Param i, push_param_list s (length ks) ! i, push_param_list z (length ks) ! i] [∧] NARY (λl. l ! 0 = l ! Suc 0) [push_param x (length ks), [∑S0] p d polynomial.Param]; p ≠ []; length p = length ks; ∀k<length ks. push_list a ks k = peval (push_param_list s (length ks) ! k) (push_list a ks) && peval (push_param_list z (length ks) ! k) (push_list a ks); peval x a = ∑S0 p d push_list a ks ⟧ ⟹ ∑S0 p d push_list a ks = ∑S0 p d (λk. peval (s ! k) a && peval (z ! k) a) ›*) unfolding list_eval_def (*goal: ‹⋀ks. ⟦⋀x d s z. [x = ∑S0 d (s && z)] ≡ [∃length ks] [∀<length ks] λi. NARY (λl. l ! 0 = l ! Suc 0 && l ! 2) [polynomial.Param i, map (λx. push_param x (length ks)) s ! i, map (λx. push_param x (length ks)) z ! i] [∧] NARY (λl. l ! 0 = l ! Suc 0) [push_param x (length ks), [∑S0] p d polynomial.Param]; p ≠ []; length p = length ks; ∀k<length ks. push_list a ks k = map (λx. peval x a) s ! k && map (λx. peval x a) z ! k; peval x a = ∑S0 p d push_list a ks ; ⋀ns n i ls a. ⟦length ns = n; i < length ls⟧ ⟹ peval (push_param (ls ! i) n) (push_list a ns) = map (λx. peval x a) ls ! i⟧ ⟹ ∑S0 p d push_list a ks = ∑S0 p d (λk. peval (s ! k) a && peval (z ! k) a) ›*) apply (auto simp: assms (*‹length s = Suc m› ‹length z = Suc m› ‹0 < length p›*) len_ps (*‹length s = length p›*) len_pz (*‹length z = length p›*) invariance (*‹∀k<length p. ?y1.0 k = ?y2.0 k ⟹ ∑S0 p d ?y1.0 = ∑S0 p d ?y2.0 ›*)) (*goal: ‹⋀ks. ⟦⋀x d s z. [x = ∑S0 d (s && z)] ≡ [∃length ks] [∀<length ks] λi. NARY (λl. l ! 0 = l ! Suc 0 && l ! 2) [polynomial.Param i, map (λx. push_param x (length ks)) s ! i, map (λx. push_param x (length ks)) z ! i] [∧] NARY (λl. l ! 0 = l ! Suc 0) [push_param x (length ks), [∑S0] p d polynomial.Param]; p ≠ []; length p = length ks; ∀k<length ks. push_list a ks k = map (λx. peval x a) s ! k && map (λx. peval x a) z ! k; peval x a = ∑S0 p d push_list a ks ; ⋀ns n i ls a. ⟦length ns = n; i < length ls⟧ ⟹ peval (push_param (ls ! i) n) (push_list a ns) = map (λx. peval x a) ls ! i⟧ ⟹ ∑S0 p d push_list a ks = ∑S0 p d (λk. peval (s ! k) a && peval (z ! k) a) ›*) apply (rule sum_ssub_zero_cong (*‹∀k. k ≤ length ?p - 1 ∧ issub (?p ! k) ∧ ?l = goes_to_alt (?p ! k) ⟶ ?f k = ?g k ⟹ ∑S0 ?p ?l ?f = ∑S0 ?p ?l ?g ›*)) (*goal: ‹⋀ks. ⟦⋀x d s z. [x = ∑S0 d (s && z)] ≡ [∃length ks] [∀<length ks] λi. NARY (λl. l ! 0 = l ! Suc 0 && l ! 2) [polynomial.Param i, map (λx. push_param x (length ks)) s ! i, map (λx. push_param x (length ks)) z ! i] [∧] NARY (λl. l ! 0 = l ! Suc 0) [push_param x (length ks), [∑S0] p d polynomial.Param]; p ≠ []; length p = length ks; ∀k<length ks. push_list a ks k = map (λx. peval x a) s ! k && map (λx. peval x a) z ! k; peval x a = ∑S0 p d push_list a ks ; ⋀ns n i ls a. ⟦length ns = n; i < length ls⟧ ⟹ peval (push_param (ls ! i) n) (push_list a ns) = peval (ls ! i) a⟧ ⟹ ∑S0 p d push_list a ks = ∑S0 p d (λk. peval (s ! k) a && peval (z ! k) a) ›*) apply auto (*goal: ‹⋀ks. ⟦⋀x d s z. [x = ∑S0 d (s && z)] ≡ [∃length ks] [∀<length ks] λi. NARY (λl. l ! 0 = l ! Suc 0 && l ! 2) [polynomial.Param i, map (λx. push_param x (length ks)) s ! i, map (λx. push_param x (length ks)) z ! i] [∧] NARY (λl. l ! 0 = l ! Suc 0) [push_param x (length ks), [∑S0] p d polynomial.Param]; p ≠ []; length p = length ks; ∀k<length ks. push_list a ks k = map (λx. peval x a) s ! k && map (λx. peval x a) z ! k; peval x a = ∑S0 p d push_list a ks ; ⋀ns n i ls a. ⟦length ns = n; i < length ls⟧ ⟹ peval (push_param (ls ! i) n) (push_list a ns) = peval (ls ! i) a⟧ ⟹ ∀k. k ≤ length p - 1 ∧ issub (p ! k) ∧ d = goes_to_alt (p ! k) ⟶ push_list a ks k = peval (s ! k) a && peval (z ! k) a›*) by (metis (no_types, lifting) One_nat_def (*‹(1::nat) = Suc (0::nat)›*) assms( (*‹length (s::polynomial list) = Suc m›*) 1) assms( (*‹length (z::polynomial list) = Suc m›*) 2) le_imp_less_Suc (*‹(?m::nat) ≤ (?n::nat) ⟹ ?m < Suc ?n›*) len_ps (*‹length (s::polynomial list) = length (p::instruction list)›*) m_def (*‹m ≡ length (p::instruction list) - (1::nat)›*) nth_map (*‹(?n::nat) < length (?xs::?'a list) ⟹ map (?f::?'a ⇒ ?'b) ?xs ! ?n = ?f (?xs ! ?n)›*)) next (*goal: ‹peval x a = ∑S0 p d (λk. peval (s ! k) a && peval (z ! k) a) ⟹ eval [x = ∑S0 d (s && z)] a›*) assume "?Q" (*‹peval (x::polynomial) (a::nat ⇒ nat) = ∑S0 (p::instruction list) (d::nat) (λk::nat. peval ((s::polynomial list) ! k) a && peval ((z::polynomial list) ! k) a) ›*) thus "?P" using sum_ssub_zero_of_bit_and_def (*‹[?x = ∑S0 ?d (?s && ?z)] ≡ let x' = push_param ?x (length p); s' = push_param_list ?s (length p); z' = push_param_list ?z (length p) in [∃length p] [∀<length p] λi. [polynomial.Param i = s' ! i && z' ! i] [∧] x' [=] [∑S0] p ?d polynomial.Param›*) ‹length p > 0› (*‹0 < length p›*) apply (auto simp add: defs (*‹❙0 = polynomial.Const 0› ‹❙1 = polynomial.Const 1› ‹?Q [=] ?R ≡ BINARY (=) ?Q ?R› ‹?Q [<] ?R ≡ BINARY (<) ?Q ?R› ‹?Q [≤] ?R ≡ ?Q [<] ?R [∨] ?Q [=] ?R› ‹?Q [>] ?R ≡ ?R [<] ?Q› ‹?Q [≥] ?R ≡ ?Q [>] ?R [∨] ?Q [=] ?R› ‹eval (LARY ?R ?PLL) ?a = ?R (map (map (λP. peval P ?a)) ?PLL)› ‹UNARY ?R ?P = NARY (λl. ?R (l ! 0)) [?P]› ‹BINARY ?R ?P₁ ?P₂ = NARY (λl. ?R (l ! 0) (l ! 1)) [?P₁, ?P₂]› ‹TERNARY ?R ?P₁ ?P₂ ?P₃ = NARY (λl. ?R (l ! 0) (l ! 1) (l ! 2)) [?P₁, ?P₂, ?P₃]› ‹QUATERNARY ?R ?P₁ ?P₂ ?P₃ ?P₄ = NARY (λl. ?R (l ! 0) (l ! 1) (l ! 2) (l ! 3)) [?P₁, ?P₂, ?P₃, ?P₄]› and more 19 facts*) push_push (*‹length ?ns = ?n ⟹ peval (push_param ?P ?n) (push_list ?a ?ns) = peval ?P ?a›*)) (*goal: ‹eval [x = ∑S0 d (s && z)] a›*) apply (rule exI[of _ "map (λk. peval (s ! k) a && peval (z!k) a) [0..<length p]"] (*‹(?P::nat list ⇒ bool) (map (λk::nat. peval ((s::polynomial list) ! k) (a::nat ⇒ nat) && peval ((z::polynomial list) ! k) a) [0::nat..<length (p::instruction list)]) ⟹ ∃x::nat list. ?P x›*), simp) (*goal: ‹⟦peval x a = ∑S0 p d (λk. peval (s ! k) a && peval (z ! k) a) ; ⋀x d s z. [x = ∑S0 d (s && z)] ≡ [∃length p] [∀<length p] λi. NARY (λl. l ! 0 = l ! Suc 0 && l ! 2) [polynomial.Param i, push_param_list s (length p) ! i, push_param_list z (length p) ! i] [∧] NARY (λl. l ! 0 = l ! Suc 0) [push_param x (length p), [∑S0] p d polynomial.Param]; p ≠ []⟧ ⟹ ∃ks. length p = length ks ∧ (∀k<length p. push_list a ks k = peval (push_param_list s (length p) ! k) (push_list a ks) && peval (push_param_list z (length p) ! k) (push_list a ks)) ∧ peval (push_param x (length p)) (push_list a ks) = ∑S0 p d push_list a ks ›*) using push_push (*‹length (?ns::nat list) = (?n::nat) ⟹ peval (push_param (?P::polynomial) ?n) (push_list (?a::nat ⇒ nat) ?ns) = peval ?P ?a›*) push_push_map_i (*‹⟦length ?ns = ?n; ?i < length ?ls⟧ ⟹ peval (map (λx. push_param x ?n) ?ls ! ?i) (push_list ?a ?ns) = list_eval ?ls ?a ?i›*) by (simp add: push_param_list_def (*‹push_param_list ?s ?k ≡ map (λx. push_param x ?k) ?s›*) invariance (*‹∀k<length p. ?y1.0 k = ?y2.0 k ⟹ ∑S0 p d ?y1.0 = ∑S0 p d ?y2.0 ›*) push_list_eval (*‹?i < length ?ns ⟹ push_list ?a ?ns ?i = ?ns ! ?i›*) len_ps (*‹length s = length p›*) len_pz (*‹length z = length p›*)) qed qed end end
{ "path": "afp-2025-02-12/thys/DPRM_Theorem/Machine_Equations/RM_Sums_Diophantine.thy", "repo": "afp-2025-02-12", "sha": "f3d636e55d659cfa2e5a0371507c37e5fb2a7c95f1037605c302539899fad61d" }
(* Title: JinjaThreads/Framework/FWWellform.thy Author: Andreas Lochbihler *) section ‹Wellformedness conditions for the multithreaded state› theory FWWellform imports FWLocking FWThread FWWait FWCondAction begin text‹Well-formedness property: Locks are held by real threads› definition lock_thread_ok :: "('l, 't) locks ⇒ ('l, 't,'x) thread_info ⇒ bool" where [code del]: "lock_thread_ok ls ts ≡ ∀l t. has_lock (ls $ l) t ⟶ (∃xw. ts t = ⌊xw⌋)" lemma lock_thread_ok_code [code]: "lock_thread_ok ls ts = finfun_All ((λl. case l of None ⇒ True | ⌊(t, n)⌋ ⇒ (ts t ≠ None)) ∘$ ls)" by (simp add: lock_thread_ok_def (*‹lock_thread_ok ?ls ?ts ≡ ∀l t. has_lock (?ls $ l) t ⟶ (∃xw. ?ts t = ⌊xw⌋)›*) finfun_All_All (*‹finfun_All ?P = All (($) ?P)›*) has_lock_has_locks_conv (*‹has_lock ?l ?t = (∃n. has_locks ?l ?t = Suc n)›*) has_locks_iff (*‹(has_locks ?l ?t = ?n) = (?l = None ∧ ?n = 0 ∨ (∃n'. ?l = ⌊(?t, n')⌋ ∧ Suc n' = ?n) ∨ (∃t' n'. ?l = ⌊(t', n')⌋ ∧ t' ≠ ?t ∧ ?n = 0))›*) o_def (*‹?f ∘ ?g = (λx. ?f (?g x))›*)) lemma lock_thread_okI: "(⋀l t. has_lock (ls $ l) t ⟹ ∃xw. ts t = ⌊xw⌋) ⟹ lock_thread_ok ls ts" by (auto simp add: lock_thread_ok_def (*‹lock_thread_ok ?ls ?ts ≡ ∀l t. has_lock (?ls $ l) t ⟶ (∃xw. ?ts t = ⌊xw⌋)›*)) lemma lock_thread_okD: "⟦ lock_thread_ok ls ts; has_lock (ls $ l) t ⟧ ⟹ ∃xw. ts t = ⌊xw⌋" by (fastforce simp add: lock_thread_ok_def (*‹lock_thread_ok ?ls ?ts ≡ ∀l t. has_lock (?ls $ l) t ⟶ (∃xw. ?ts t = ⌊xw⌋)›*)) lemma lock_thread_okD': "⟦ lock_thread_ok ls ts; has_locks (ls $ l) t = Suc n ⟧ ⟹ ∃xw. ts t = ⌊xw⌋" by (auto elim: lock_thread_okD[where l=l] (*‹⟦lock_thread_ok ?ls ?ts; has_lock (?ls $ l) ?t⟧ ⟹ ∃xw. ?ts ?t = ⌊xw⌋›*) simp del: split_paired_Ex (*‹(∃x. ?P x) = (∃a b. ?P (a, b))›*)) lemma lock_thread_okE: "⟦ lock_thread_ok ls ts; ∀l t. has_lock (ls $ l) t ⟶ (∃xw. ts t = ⌊xw⌋) ⟹ P ⟧ ⟹ P" by (auto simp add: lock_thread_ok_def (*‹lock_thread_ok ?ls ?ts ≡ ∀l t. has_lock (?ls $ l) t ⟶ (∃xw. ?ts t = ⌊xw⌋)›*) simp del: split_paired_Ex (*‹(∃x. ?P x) = (∃a b. ?P (a, b))›*)) lemma lock_thread_ok_upd: "lock_thread_ok ls ts ⟹ lock_thread_ok ls (ts(t ↦ xw))" by (auto intro!: lock_thread_okI (*‹(⋀l t. has_lock (?ls $ l) t ⟹ ∃xw. ?ts t = ⌊xw⌋) ⟹ lock_thread_ok ?ls ?ts›*) dest: lock_thread_okD (*‹⟦lock_thread_ok ?ls ?ts; has_lock (?ls $ ?l) ?t⟧ ⟹ ∃xw. ?ts ?t = ⌊xw⌋›*)) lemma lock_thread_ok_has_lockE: assumes "lock_thread_ok ls ts" and "has_lock (ls $ l) t" obtains x ln' where "ts t = ⌊(x, ln')⌋" using assms (*‹lock_thread_ok ls ts› ‹has_lock (ls $ l) t›*) by (auto dest!: lock_thread_okD (*‹⟦lock_thread_ok ?ls ?ts; has_lock (?ls $ ?l) ?t⟧ ⟹ ∃xw. ?ts ?t = ⌊xw⌋›*)) lemma redT_updLs_preserves_lock_thread_ok: assumes lto: "lock_thread_ok ls ts" and tst: "ts t = ⌊xw⌋" shows "lock_thread_ok (redT_updLs ls t las) ts" proof (rule lock_thread_okI (*‹(⋀l t. has_lock (?ls $ l) t ⟹ ∃xw. ?ts t = ⌊xw⌋) ⟹ lock_thread_ok ?ls ?ts›*)) (*goal: ‹⋀l ta. has_lock (redT_updLs ls t las $ l) ta ⟹ ∃xw. ts ta = ⌊xw⌋›*) fix L and T assume ru: "has_lock (redT_updLs ls t las $ L) T" (*‹has_lock (redT_updLs (ls::('a, 'b) locks) (t::'b) (las::'a lock_actions) $ (L::'a)) (T::'b)›*) show "∃xw. ts T = ⌊xw⌋" proof (cases "t = T") (*goals: 1. ‹t = T ⟹ ∃xw. ts T = ⌊xw⌋› 2. ‹t ≠ T ⟹ ∃xw. ts T = ⌊xw⌋›*) case True (*‹(t::'b::type) = (T::'b::type)›*) thus "?thesis" (*goal: ‹∃xw. ts T = ⌊xw⌋›*) using tst (*‹(ts::'b ⇒ ('c × 'a ⇒f nat) option) (t::'b) = ⌊xw::'c × 'a ⇒f nat⌋›*) lto (*‹lock_thread_ok (ls::('a, 'b) locks) (ts::'b ⇒ ('c × 'a ⇒f nat) option)›*) by (auto elim: lock_thread_okE (*‹⟦lock_thread_ok ?ls ?ts; ∀l t. has_lock (?ls $ l) t ⟶ (∃xw. ?ts t = ⌊xw⌋) ⟹ ?P⟧ ⟹ ?P›*)) next (*goal: ‹t ≠ T ⟹ ∃xw. ts T = ⌊xw⌋›*) case False (*‹t ≠ T›*) with ru (*‹has_lock (redT_updLs ls t las $ L) T›*) have "has_lock (ls $ L) T" by (rule redT_updLs_Some_thread_idD (*‹⟦has_lock (redT_updLs ?ls ?t ?las $ ?l) ?t'; ?t ≠ ?t'⟧ ⟹ has_lock (?ls $ ?l) ?t'›*)) thus "?thesis" (*goal: ‹∃xw. ts T = ⌊xw⌋›*) using lto (*‹lock_thread_ok ls ts›*) by (auto elim!: lock_thread_okE (*‹⟦lock_thread_ok ?ls ?ts; ∀l t. has_lock (?ls $ l) t ⟶ (∃xw. ?ts t = ⌊xw⌋) ⟹ ?P⟧ ⟹ ?P›*) simp del: split_paired_Ex (*‹(∃x. ?P x) = (∃a b. ?P (a, b))›*)) qed qed lemma redT_updTs_preserves_lock_thread_ok: assumes lto: "lock_thread_ok ls ts" shows "lock_thread_ok ls (redT_updTs ts nts)" proof (rule lock_thread_okI (*‹(⋀l t. has_lock (?ls $ l) t ⟹ ∃xw. ?ts t = ⌊xw⌋) ⟹ lock_thread_ok ?ls ?ts›*)) (*goal: ‹⋀l t. has_lock (ls $ l) t ⟹ ∃xw. redT_updTs ts nts t = ⌊xw⌋›*) fix l and t assume "has_lock (ls $ l) t" (*‹has_lock ((ls::('a, 'b) locks) $ (l::'a)) (t::'b)›*) with lto (*‹lock_thread_ok ls ts›*) have "∃xw. ts t = ⌊xw⌋" by (auto elim!: lock_thread_okE (*‹⟦lock_thread_ok ?ls ?ts; ∀l t. has_lock (?ls $ l) t ⟶ (∃xw. ?ts t = ⌊xw⌋) ⟹ ?P⟧ ⟹ ?P›*) simp del: split_paired_Ex (*‹(∃x. ?P x) = (∃a b. ?P (a, b))›*)) thus "∃xw. redT_updTs ts nts t = ⌊xw⌋" by (auto intro: redT_updTs_Some1 (*‹?ts ?t = ⌊?xw⌋ ⟹ ∃xw. redT_updTs ?ts ?tas ?t = ⌊xw⌋›*) simp del: split_paired_Ex (*‹(∃x. ?P x) = (∃a b. ?P (a, b))›*)) qed lemma lock_thread_ok_has_lock: assumes "lock_thread_ok ls ts" and "has_lock (ls $ l) t" obtains xw where "ts t = ⌊xw⌋" sorry lemma lock_thread_ok_None_has_locks_0: "⟦ lock_thread_ok ls ts; ts t = None ⟧ ⟹ has_locks (ls $ l) t = 0" apply (rule ccontr (*‹(¬ (?P::bool) ⟹ False) ⟹ ?P›*)) (*goal: ‹⟦lock_thread_ok (ls::('a, 'b) locks) (ts::'b ⇒ ('c × 'a ⇒f nat) option); ts (t::'b) = None⟧ ⟹ has_locks (ls $ (l::'a)) t = (0::nat)›*) by (auto dest: lock_thread_okD (*‹⟦lock_thread_ok ?ls ?ts; has_lock (?ls $ ?l) ?t⟧ ⟹ ∃xw. ?ts ?t = ⌊xw⌋›*)) lemma redT_upds_preserves_lock_thread_ok: "⟦lock_thread_ok ls ts; ts t = ⌊xw⌋; thread_oks ts tas⟧ ⟹ lock_thread_ok (redT_updLs ls t las) ((redT_updTs ts tas)(t ↦ xw'))" apply (rule lock_thread_okI (*‹(⋀l t. has_lock (?ls $ l) t ⟹ ∃xw. ?ts t = ⌊xw⌋) ⟹ lock_thread_ok ?ls ?ts›*)) (*goal: ‹⟦lock_thread_ok ls ts; ts t = ⌊xw⌋; thread_oks ts tas⟧ ⟹ lock_thread_ok (redT_updLs ls t las) ((redT_updTs ts tas)(t ↦ xw'))›*) apply (clarsimp simp del: split_paired_Ex (*‹(∃x::?'a::type × ?'b::type. (?P::?'a::type × ?'b::type ⇒ bool) x) = (∃(a::?'a::type) b::?'b::type. ?P (a, b))›*)) (*goal: ‹⋀l ta. ⟦lock_thread_ok ls ts; ts t = ⌊xw⌋; thread_oks ts tas; has_lock (redT_updLs ls t las $ l) ta⟧ ⟹ ∃xw. ((redT_updTs ts tas)(t ↦ xw')) ta = ⌊xw⌋›*) apply (drule has_lock_upd_locks_implies_has_lock (*‹⟦has_lock (upd_locks (?l::(?'a × nat) option) (?t::?'a) (?Ls::lock_action list)) (?t'::?'a); ?t ≠ ?t'⟧ ⟹ has_lock ?l ?t'›*)) (*goals: 1. ‹⋀(l::'a) ta::'b. ⟦lock_thread_ok (ls::('a, 'b) locks) (ts::'b ⇒ ('c × 'a ⇒f nat) option); ts (t::'b) = ⌊xw::'c × 'a ⇒f nat⌋; thread_oks ts (tas::('b, 'c, 'd) new_thread_action list); ta ≠ t⟧ ⟹ t ≠ ta› 2. ‹⋀(l::'a) ta::'b. ⟦lock_thread_ok (ls::('a, 'b) locks) (ts::'b ⇒ ('c × 'a ⇒f nat) option); ts (t::'b) = ⌊xw::'c × 'a ⇒f nat⌋; thread_oks ts (tas::('b, 'c, 'd) new_thread_action list); ta ≠ t; has_lock (ls $ l) ta⟧ ⟹ ∃xw::'c × 'a ⇒f nat. redT_updTs ts tas ta = ⌊xw⌋› discuss goal 1*) apply simp (*discuss goal 2*) apply (drule lock_thread_okD (*‹⟦lock_thread_ok (?ls::(?'a, ?'b) locks) (?ts::?'b ⇒ (?'c × ?'a ⇒f nat) option); has_lock (?ls $ (?l::?'a)) (?t::?'b)⟧ ⟹ ∃xw::?'c × ?'a ⇒f nat. ?ts ?t = ⌊xw⌋›*)) (*goals: 1. ‹⋀(l::'a::type) ta::'b::type. ⟦(ts::'b::type ⇒ ('c::type × 'a::type ⇒f nat) option) (t::'b::type) = ⌊xw::'c::type × 'a::type ⇒f nat⌋; thread_oks ts (tas::('b::type, 'c::type, 'd::type) new_thread_action list); ta ≠ t; has_lock ((ls::('a::type, 'b::type) locks) $ l) ta⟧ ⟹ has_lock (ls $ ((?l10::'a::type ⇒ 'b::type ⇒ 'a::type) l ta)) ((?t10::'a::type ⇒ 'b::type ⇒ 'b::type) l ta)› 2. ‹⋀(l::'a::type) ta::'b::type. ⟦(ts::'b::type ⇒ ('c::type × 'a::type ⇒f nat) option) (t::'b::type) = ⌊xw::'c::type × 'a::type ⇒f nat⌋; thread_oks ts (tas::('b::type, 'c::type, 'd::type) new_thread_action list); ta ≠ t; has_lock ((ls::('a::type, 'b::type) locks) $ l) ta; ∃xw::'c::type × 'a::type ⇒f nat. ts ((?t10::'a::type ⇒ 'b::type ⇒ 'b::type) l ta) = ⌊xw⌋⟧ ⟹ ∃xw::'c::type × 'a::type ⇒f nat. redT_updTs ts tas ta = ⌊xw⌋› discuss goal 1*) apply assumption (*discuss goal 2*) apply (erule exE (*‹⟦∃x::?'a::type. (?P::?'a::type ⇒ bool) x; ⋀x::?'a::type. ?P x ⟹ ?Q::bool⟧ ⟹ ?Q›*)) (*goal: ‹⋀l ta. ⟦ts t = ⌊xw⌋; thread_oks ts tas; ta ≠ t; has_lock (ls $ l) ta; ∃xw. ts ta = ⌊xw⌋⟧ ⟹ ∃xw. redT_updTs ts tas ta = ⌊xw⌋›*) by (rule redT_updTs_Some1 (*‹?ts ?t = ⌊?xw⌋ ⟹ ∃xw. redT_updTs ?ts ?tas ?t = ⌊xw⌋›*)) (*proven 2 subgoals*) (*proven 2 subgoals*) lemma acquire_all_preserves_lock_thread_ok: fixes ln shows "⟦ lock_thread_ok ls ts; ts t = ⌊(x, ln)⌋ ⟧ ⟹ lock_thread_ok (acquire_all ls t ln) (ts(t ↦ xw))" apply (rule lock_thread_okI (*‹(⋀l t. has_lock (?ls $ l) t ⟹ ∃xw. ?ts t = ⌊xw⌋) ⟹ lock_thread_ok ?ls ?ts›*)) (*goal: ‹⟦lock_thread_ok ls ts; ts t = ⌊(x, ln)⌋⟧ ⟹ lock_thread_ok (acquire_all ls t ln) (ts(t ↦ xw))›*) by (auto dest!: has_lock_acquire_locks_implies_has_lock (*‹⟦has_lock (acquire_locks ?l ?t ?n) ?t'; ?t ≠ ?t'⟧ ⟹ has_lock ?l ?t'›*) dest: lock_thread_okD (*‹⟦lock_thread_ok ?ls ?ts; has_lock (?ls $ ?l) ?t⟧ ⟹ ∃xw. ?ts ?t = ⌊xw⌋›*)) text ‹Well-formedness condition: Wait sets contain only real threads› definition wset_thread_ok :: "('w, 't) wait_sets ⇒ ('l, 't, 'x) thread_info ⇒ bool" where "wset_thread_ok ws ts ≡ ∀t. ts t = None ⟶ ws t = None" lemma wset_thread_okI: "(⋀t. ts t = None ⟹ ws t = None) ⟹ wset_thread_ok ws ts" by (simp add: wset_thread_ok_def (*‹wset_thread_ok ?ws ?ts ≡ ∀t. ?ts t = None ⟶ ?ws t = None›*)) lemma wset_thread_okD: "⟦ wset_thread_ok ws ts; ts t = None ⟧ ⟹ ws t = None" by (simp add: wset_thread_ok_def (*‹wset_thread_ok ?ws ?ts ≡ ∀t. ?ts t = None ⟶ ?ws t = None›*)) lemma wset_thread_ok_conv_dom: "wset_thread_ok ws ts ⟷ dom ws ⊆ dom ts" by (auto simp add: wset_thread_ok_def (*‹wset_thread_ok ?ws ?ts ≡ ∀t. ?ts t = None ⟶ ?ws t = None›*)) lemma wset_thread_ok_upd: "wset_thread_ok ls ts ⟹ wset_thread_ok ls (ts(t ↦ xw))" by (auto intro!: wset_thread_okI (*‹(⋀t. ?ts t = None ⟹ ?ws t = None) ⟹ wset_thread_ok ?ws ?ts›*) dest: wset_thread_okD (*‹⟦wset_thread_ok ?ws ?ts; ?ts ?t = None⟧ ⟹ ?ws ?t = None›*) split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) lemma wset_thread_ok_upd_None: "wset_thread_ok ws ts ⟹ wset_thread_ok (ws(t := None)) (ts(t := None))" by (auto intro!: wset_thread_okI (*‹(⋀t. ?ts t = None ⟹ ?ws t = None) ⟹ wset_thread_ok ?ws ?ts›*) dest: wset_thread_okD (*‹⟦wset_thread_ok ?ws ?ts; ?ts ?t = None⟧ ⟹ ?ws ?t = None›*) split: if_split_asm (*‹?P (if ?Q then ?x else ?y) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) lemma wset_thread_ok_upd_Some: "wset_thread_ok ws ts ⟹ wset_thread_ok (ws(t := wo)) (ts(t ↦ xln))" by (auto intro!: wset_thread_okI (*‹(⋀t::?'a::type. (?ts::?'a::type ⇒ (?'b::type × ?'c::type ⇒f nat) option) t = None ⟹ (?ws::?'a::type ⇒ ?'d::type wait_set_status option) t = None) ⟹ wset_thread_ok ?ws ?ts›*) dest: wset_thread_okD (*‹⟦wset_thread_ok (?ws::?'a::type ⇒ ?'b::type wait_set_status option) (?ts::?'a::type ⇒ (?'c::type × ?'d::type ⇒f nat) option); ?ts (?t::?'a::type) = None⟧ ⟹ ?ws ?t = None›*) split: if_split_asm (*‹(?P::?'a::type ⇒ bool) (if ?Q::bool then ?x::?'a::type else (?y::?'a::type)) = (¬ (?Q ∧ ¬ ?P ?x ∨ ¬ ?Q ∧ ¬ ?P ?y))›*)) lemma wset_thread_ok_upd_ws: "⟦ wset_thread_ok ws ts; ts t = ⌊xln⌋ ⟧ ⟹ wset_thread_ok (ws(t := w)) ts" by (auto intro!: wset_thread_okI (*‹(⋀t::?'a. (?ts::?'a ⇒ (?'b × ?'c ⇒f nat) option) t = None ⟹ (?ws::?'a ⇒ ?'d wait_set_status option) t = None) ⟹ wset_thread_ok ?ws ?ts›*) dest: wset_thread_okD (*‹⟦wset_thread_ok (?ws::?'a ⇒ ?'b wait_set_status option) (?ts::?'a ⇒ (?'c × ?'d ⇒f nat) option); ?ts (?t::?'a) = None⟧ ⟹ ?ws ?t = None›*)) lemma wset_thread_ok_NotifyAllI: "wset_thread_ok ws ts ⟹ wset_thread_ok (λt. if ws t = ⌊w t⌋ then ⌊w' t⌋ else ws t) ts" by (simp add: wset_thread_ok_def (*‹wset_thread_ok (?ws::?'t::type ⇒ ?'w::type wait_set_status option) (?ts::?'t::type ⇒ (?'x::type × ?'l::type ⇒f nat) option) ≡ ∀t::?'t::type. ?ts t = None ⟶ ?ws t = None›*)) lemma redT_updTs_preserves_wset_thread_ok: assumes wto: "wset_thread_ok ws ts" shows "wset_thread_ok ws (redT_updTs ts nts)" proof (rule wset_thread_okI (*‹(⋀t. ?ts t = None ⟹ ?ws t = None) ⟹ wset_thread_ok ?ws ?ts›*)) (*goal: ‹⋀t. redT_updTs ts nts t = None ⟹ ws t = None›*) fix t assume "redT_updTs ts nts t = None" (*‹redT_updTs (ts::'a ⇒ ('c × 'd ⇒f nat) option) (nts::('a, 'c, 'e) new_thread_action list) (t::'a) = None›*) hence "ts t = None" by (rule redT_updTs_None (*‹redT_updTs ?ts ?tas ?t = None ⟹ ?ts ?t = None›*)) with wto (*‹wset_thread_ok ws ts›*) show "ws t = None" by (rule wset_thread_okD (*‹⟦wset_thread_ok ?ws ?ts; ?ts ?t = None⟧ ⟹ ?ws ?t = None›*)) qed lemma redT_updW_preserve_wset_thread_ok: "⟦ wset_thread_ok ws ts; redT_updW t ws wa ws'; ts t = ⌊xln⌋ ⟧ ⟹ wset_thread_ok ws' ts" by (fastforce simp add: redT_updW.simps (*‹redT_updW ?t ?ws ?a1.0 ?a2.0 = ((∃t' w. ?a1.0 = Notify w ∧ ?a2.0 = ?ws(t' ↦ PostWS WSNotified) ∧ ?ws t' = ⌊InWS w⌋) ∨ (∃w. ?a1.0 = Notify w ∧ ?a2.0 = ?ws ∧ (∀x. ?ws x ≠ ⌊InWS w⌋)) ∨ (∃w. ?a1.0 = NotifyAll w ∧ ?a2.0 = (λt. if ?ws t = ⌊InWS w⌋ then ⌊PostWS WSNotified⌋ else ?ws t)) ∨ (∃w. ?a1.0 = Suspend w ∧ ?a2.0 = ?ws(?t ↦ InWS w)) ∨ (∃t' w WSInterrupted. ?a1.0 = WakeUp t' ∧ ?a2.0 = ?ws(t' ↦ PostWS WSInterrupted) ∧ ?ws t' = ⌊InWS w⌋) ∨ (∃t'. ?a1.0 = WakeUp t' ∧ ?a2.0 = ?ws ∧ (∀x. ?ws t' ≠ ⌊InWS x⌋)) ∨ ?a1.0 = Notified ∧ ?a2.0 = ?ws(?t := None) ∨ ?a1.0 = WokenUp ∧ ?a2.0 = ?ws(?t := None))›*) intro: wset_thread_okI (*‹(⋀t. ?ts t = None ⟹ ?ws t = None) ⟹ wset_thread_ok ?ws ?ts›*) wset_thread_ok_NotifyAllI (*‹wset_thread_ok ?ws ?ts ⟹ wset_thread_ok (λt. if ?ws t = ⌊?w t⌋ then ⌊?w' t⌋ else ?ws t) ?ts›*) wset_thread_ok_upd_ws (*‹⟦wset_thread_ok ?ws ?ts; ?ts ?t = ⌊?xln⌋⟧ ⟹ wset_thread_ok (?ws(?t := ?w)) ?ts›*) dest: wset_thread_okD (*‹⟦wset_thread_ok ?ws ?ts; ?ts ?t = None⟧ ⟹ ?ws ?t = None›*)) lemma redT_updWs_preserve_wset_thread_ok: "⟦ wset_thread_ok ws ts; redT_updWs t ws was ws'; ts t = ⌊xln⌋ ⟧ ⟹ wset_thread_ok ws' ts" unfolding redT_updWs_def (*goal: ‹⟦wset_thread_ok ws ts; rtrancl3p (redT_updW t) ws was ws'; ts t = ⌊xln⌋⟧ ⟹ wset_thread_ok ws' ts›*) apply (rotate_tac 1) (*goal: ‹⟦wset_thread_ok (ws::'a ⇒ 'b wait_set_status option) (ts::'a ⇒ ('c × 'd ⇒f nat) option); rtrancl3p (redT_updW (t::'a)) ws (was::('a, 'b) wait_set_action list) (ws'::'a ⇒ 'b wait_set_status option); ts t = ⌊xln::'c × 'd ⇒f nat⌋⟧ ⟹ wset_thread_ok ws' ts›*) apply (induct rule: rtrancl3p_converse_induct (*‹⟦rtrancl3p ?r ?a ?bs ?a''; ⋀a. ?P a [] a; ⋀a b a' bs a''. ⟦rtrancl3p ?r a' bs a''; ?r a b a'; ?P a' bs a''⟧ ⟹ ?P a (b # bs) a''⟧ ⟹ ?P ?a ?bs ?a''›*)) (*goals: 1. ‹⋀a. ⟦ts t = ⌊xln⌋; wset_thread_ok a ts⟧ ⟹ wset_thread_ok a ts› 2. ‹⋀a b a' bs a''. ⟦rtrancl3p (redT_updW t) a' bs a''; redT_updW t a b a'; ⟦ts t = ⌊xln⌋; wset_thread_ok a' ts⟧ ⟹ wset_thread_ok a'' ts; ts t = ⌊xln⌋; wset_thread_ok a ts⟧ ⟹ wset_thread_ok a'' ts› discuss goal 1*) apply ((auto intro: redT_updW_preserve_wset_thread_ok (*‹⟦wset_thread_ok ?ws ?ts; redT_updW ?t ?ws ?wa ?ws'; ?ts ?t = ⌊?xln⌋⟧ ⟹ wset_thread_ok ?ws' ?ts›*))[1]) (*discuss goal 2*) apply ((auto intro: redT_updW_preserve_wset_thread_ok (*‹⟦wset_thread_ok ?ws ?ts; redT_updW ?t ?ws ?wa ?ws'; ?ts ?t = ⌊?xln⌋⟧ ⟹ wset_thread_ok ?ws' ?ts›*))[1]) (*proven 2 subgoals*) . text ‹Well-formedness condition: Wait sets contain only non-final threads› context final_thread begin definition wset_final_ok :: "('w, 't) wait_sets ⇒ ('l, 't, 'x) thread_info ⇒ bool" where "wset_final_ok ws ts ⟷ (∀t ∈ dom ws. ∃x ln. ts t = ⌊(x, ln)⌋ ∧ ¬ final x)" lemma wset_final_okI: "(⋀t w. ws t = ⌊w⌋ ⟹ ∃x ln. ts t = ⌊(x, ln)⌋ ∧ ¬ final x) ⟹ wset_final_ok ws ts" unfolding wset_final_ok_def (*goal: ‹(⋀t w. ws t = ⌊w⌋ ⟹ ∃x ln. ts t = ⌊(x, ln)⌋ ∧ ¬ final x) ⟹ ∀t∈dom ws. ∃x ln. ts t = ⌊(x, ln)⌋ ∧ ¬ final x›*) by blast lemma wset_final_okD: "⟦ wset_final_ok ws ts; ws t = ⌊w⌋ ⟧ ⟹ ∃x ln. ts t = ⌊(x, ln)⌋ ∧ ¬ final x" unfolding wset_final_ok_def (*goal: ‹⟦∀t∈dom ws. ∃x ln. ts t = ⌊(x, ln)⌋ ∧ ¬ final x; ws t = ⌊w⌋⟧ ⟹ ∃x ln. ts t = ⌊(x, ln)⌋ ∧ ¬ final x›*) by blast lemma wset_final_okE: assumes "wset_final_ok ws ts" "ws t = ⌊w⌋" and "⋀x ln. ts t = ⌊(x, ln)⌋ ⟹ ¬ final x ⟹ thesis" shows thesis using assms (*‹wset_final_ok (ws::'a::type ⇒ 'b::type wait_set_status option) (ts::'a::type ⇒ ('x::type × 'c::type ⇒f nat) option)› ‹ws t = ⌊w⌋› ‹⟦ts t = ⌊(?x5, ?ln5)⌋; ¬ final ?x5⟧ ⟹ thesis›*) by (blast dest: wset_final_okD (*‹⟦wset_final_ok (?ws::?'a ⇒ ?'b wait_set_status option) (?ts::?'a ⇒ ('x × ?'c ⇒f nat) option); ?ws (?t::?'a) = ⌊?w::?'b wait_set_status⌋⟧ ⟹ ∃(x::'x) ln::?'c ⇒f nat. ?ts ?t = ⌊(x, ln)⌋ ∧ ¬ (final::'x ⇒ bool) x›*)) lemma wset_final_ok_imp_wset_thread_ok: "wset_final_ok ws ts ⟹ wset_thread_ok ws ts" apply (rule wset_thread_okI (*‹(⋀t. ?ts t = None ⟹ ?ws t = None) ⟹ wset_thread_ok ?ws ?ts›*)) (*goal: ‹wset_final_ok (ws::'a ⇒ 'b wait_set_status option) (ts::'a ⇒ ('x × 'c ⇒f nat) option) ⟹ wset_thread_ok ws ts›*) apply (rule ccontr (*‹(¬ ?P ⟹ False) ⟹ ?P›*)) (*goal: ‹⋀t. ⟦wset_final_ok ws ts; ts t = None⟧ ⟹ ws t = None›*) by (auto elim: wset_final_okE (*‹⟦wset_final_ok (?ws::?'a ⇒ ?'b wait_set_status option) (?ts::?'a ⇒ ('x × ?'c ⇒f nat) option); ?ws (?t::?'a) = ⌊?w::?'b wait_set_status⌋; ⋀(x::'x) ln::?'c ⇒f nat. ⟦?ts ?t = ⌊(x, ln)⌋; ¬ (final::'x ⇒ bool) x⟧ ⟹ ?thesis::bool⟧ ⟹ ?thesis›*)) end end
{ "path": "afp-2025-02-12/thys/JinjaThreads/Framework/FWWellform.thy", "repo": "afp-2025-02-12", "sha": "99efa4d1b22480765e290fc944a853fe9df6e899850543f3ee550b0106c1a9cb" }
(* Authors: Hanna Lachnitt, TU Wien, lachnitt@student.tuwien.ac.at Anthony Bordg, University of Cambridge, apdb3@cam.ac.uk *) section ‹The Deutsch-Jozsa Algorithm› theory Deutsch_Jozsa imports Deutsch More_Tensor Binary_Nat begin text ‹ Given a function $f:{0,1}^n \mapsto {0,1}$, the Deutsch-Jozsa algorithm decides if this function is constant or balanced with a single $f(x)$ circuit to evaluate the function for multiple values of $x$ simultaneously. The algorithm makes use of quantum parallelism and quantum interference. A constant function with values in {0,1} returns either always 0 or always 1. A balanced function is 0 for half of the inputs and 1 for the other half. › locale bob_fun = fixes f:: "nat ⇒ nat" and n:: "nat" assumes dom: "f ∈ ({(i::nat). i < 2^n} →⇩E {0,1})" assumes dim: "n ≥ 1" context bob_fun begin definition const:: "nat ⇒ bool" where "const c = (∀x∈{i::nat. i<2^n}. f x = c)" definition is_const:: bool where "is_const ≡ const 0 ∨ const 1" definition is_balanced:: bool where "is_balanced ≡ ∃A B ::nat set. A ⊆ {i::nat. i < 2^n} ∧ B ⊆ {i::nat. i < 2^n} ∧ card A = 2^(n-1) ∧ card B = 2^(n-1) ∧ (∀x∈A. f x = 0) ∧ (∀x∈B. f x = 1)" lemma is_balanced_inter: fixes A B:: "nat set" assumes "∀x ∈ A. f x = 0" and "∀x ∈ B. f x = 1" shows "A ∩ B = {}" using assms (*‹∀x∈A. f x = 0› ‹∀x∈B. f x = 1›*) by auto lemma is_balanced_union: fixes A B:: "nat set" assumes "A ⊆ {i::nat. i < 2^n}" and "B ⊆ {i::nat. i < 2^n}" and "card A = 2^(n-1)" and "card B = 2^(n-1)" and "A ∩ B = {}" shows "A ∪ B = {i::nat. i < 2^n}" proof (-) (*goal: ‹A ∪ B = {i. i < 2 ^ n}›*) have "finite A" and "finite B" (*goals: 1. ‹finite A› 2. ‹finite B› discuss goal 1*) apply (simp add: assms( (*‹card (A::nat set) = (2::nat) ^ ((n::nat) - (1::nat))›*) 3) card_ge_0_finite (*‹(0::nat) < card (?A::?'a::type set) ⟹ finite ?A›*)) (*discuss goal 2*) apply (simp add: assms( (*‹card (B::nat set) = (2::nat) ^ ((n::nat) - (1::nat))›*) 4) card_ge_0_finite (*‹(0::nat) < card (?A::?'a set) ⟹ finite ?A›*)) (*proven 2 subgoals*) . then have "card(A ∪ B) = 2 * 2^(n-1)" using assms(3-5) (*‹card A = 2 ^ (n - 1)› ‹card (B::nat set) = (2::nat) ^ ((n::nat) - (1::nat))› ‹A ∩ B = {}›*) by (simp add: card_Un_disjoint (*‹⟦finite ?A; finite ?B; ?A ∩ ?B = {}⟧ ⟹ card (?A ∪ ?B) = card ?A + card ?B›*)) then have "card(A ∪ B) = 2^n" by (metis Nat.nat.simps( (*‹Suc ?x2.0 ≠ 0›*) 3) One_nat_def (*‹1 = Suc 0›*) dim (*‹1 ≤ n›*) le_0_eq (*‹(?n ≤ 0) = (?n = 0)›*) power_eq_if (*‹?p ^ ?m = (if ?m = 0 then 1 else ?p * ?p ^ (?m - 1))›*)) moreover have "… = card({i::nat. i < 2^n})" by simp moreover have "A ∪ B ⊆ {i::nat. i < 2^n}" using assms(1,2) (*‹A ⊆ {i. i < 2 ^ n}› ‹B ⊆ {i. i < 2 ^ n}›*) by simp moreover have "finite ({i::nat. i < 2^n})" by simp ultimately show "?thesis" (*goal: ‹A ∪ B = {i. i < 2 ^ n}›*) using card_subset_eq[of "{i::nat. i < 2^n}" "A ∪ B"] (*‹⟦finite {i. i < 2 ^ n}; A ∪ B ⊆ {i. i < 2 ^ n}; card (A ∪ B) = card {i. i < 2 ^ n}⟧ ⟹ A ∪ B = {i. i < 2 ^ n}›*) by simp qed lemma f_ge_0: "∀x. f x ≥ 0" by simp lemma f_dom_not_zero: shows "f ∈ ({i::nat. n ≥ 1 ∧ i < 2^n} →⇩E {0,1})" using dim (*‹(1::nat) ≤ (n::nat)›*) dom (*‹f ∈ {i. i < 2 ^ n} →⇩E {0, 1}›*) by simp lemma f_values: "∀x ∈ {(i::nat). i < 2^n} . f x = 0 ∨ f x = 1" using dom (*‹f ∈ {i. i < 2 ^ n} →⇩E {0, 1}›*) by auto end (* bob_fun *) text ‹The input function has to be constant or balanced.› locale jozsa = bob_fun + assumes const_or_balanced: "is_const ∨ is_balanced " text ‹ Introduce two customised rules: disjunctions with four disjuncts and induction starting from one instead of zero. › (* To deal with Uf it is often necessary to do a case distinction with four different cases.*) lemma disj_four_cases: assumes "A ∨ B ∨ C ∨ D" and "A ⟹ P" and "B ⟹ P" and "C ⟹ P" and "D ⟹ P" shows "P" using assms (*‹A ∨ B ∨ C ∨ D› ‹A ⟹ P› ‹B ⟹ P› ‹C::bool ⟹ P::bool› ‹D::bool ⟹ P::bool›*) by auto text ‹The unitary transform @{term U⇩f}.› definition (in jozsa) jozsa_transform:: "complex Matrix.mat" ("U⇩f") where "U⇩f ≡ Matrix.mat (2^(n+1)) (2^(n+1)) (λ(i,j). if i = j then (1-f(i div 2)) else if i = j + 1 ∧ odd i then f(i div 2) else if i = j - 1 ∧ even i ∧ j≥1 then f(i div 2) else 0)" lemma (in jozsa) jozsa_transform_dim [simp]: shows "dim_row U⇩f = 2^(n+1)" and "dim_col U⇩f = 2^(n+1)" (*goals: 1. ‹dim_row U⇩f = 2 ^ (n + 1)› 2. ‹dim_col U⇩f = 2 ^ (n + 1)› discuss goal 1*) apply ((auto simp add: jozsa_transform_def (*‹U⇩f ≡ Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) ((2::nat) ^ (n + (1::nat))) (λx::nat × nat. complex_of_nat (case x of (i::nat, j::nat) ⇒ if i = j then (1::nat) - (f::nat ⇒ nat) (i div (2::nat)) else if i = j + (1::nat) ∧ odd i then f (i div (2::nat)) else if i = j - (1::nat) ∧ even i ∧ (1::nat) ≤ j then f (i div (2::nat)) else (0::nat)))›*))[1]) (*discuss goal 2*) apply ((auto simp add: jozsa_transform_def (*‹U⇩f ≡ Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_nat (case x of (i, j) ⇒ if i = j then 1 - f (i div 2) else if i = j + 1 ∧ odd i then f (i div 2) else if i = j - 1 ∧ even i ∧ 1 ≤ j then f (i div 2) else 0))›*))[1]) (*proven 2 subgoals*) . lemma (in jozsa) jozsa_transform_coeff_is_zero [simp]: assumes "i < dim_row U⇩f ∧ j < dim_col U⇩f" shows "(i≠j ∧ ¬(i=j+1 ∧ odd i) ∧ ¬ (i=j-1 ∧ even i ∧ j≥1)) ⟶ U⇩f $$ (i,j) = 0" using jozsa_transform_def (*‹U⇩f ≡ Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_nat (case x of (i, j) ⇒ if i = j then 1 - f (i div 2) else if i = j + 1 ∧ odd i then f (i div 2) else if i = j - 1 ∧ even i ∧ 1 ≤ j then f (i div 2) else 0))›*) assms (*‹(i::nat) < dim_row U⇩f ∧ (j::nat) < dim_col U⇩f›*) by auto lemma (in jozsa) jozsa_transform_coeff [simp]: assumes "i < dim_row U⇩f ∧ j < dim_col U⇩f" shows "i = j ⟶ U⇩f $$ (i,j) = 1 - f (i div 2)" and "i = j + 1 ∧ odd i ⟶ U⇩f $$ (i,j) = f (i div 2)" and "j ≥ 1 ∧ i = j - 1 ∧ even i ⟶ U⇩f $$ (i,j) = f (i div 2)" using jozsa_transform_def (*‹U⇩f ≡ Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_nat (case x of (i, j) ⇒ if i = j then 1 - f (i div 2) else if i = j + 1 ∧ odd i then f (i div 2) else if i = j - 1 ∧ even i ∧ 1 ≤ j then f (i div 2) else 0))›*) assms (*‹i < dim_row U⇩f ∧ j < dim_col U⇩f›*) apply - (*goals: 1. ‹⟦U⇩f ≡ Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_nat (case x of (i, j) ⇒ if i = j then 1 - f (i div 2) else if i = j + 1 ∧ odd i then f (i div 2) else if i = j - 1 ∧ even i ∧ 1 ≤ j then f (i div 2) else 0)); i < dim_row U⇩f ∧ j < dim_col U⇩f⟧ ⟹ i = j ⟶ U⇩f $$ (i, j) = complex_of_nat (1 - f (i div 2))› 2. ‹⟦U⇩f ≡ Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_nat (case x of (i, j) ⇒ if i = j then 1 - f (i div 2) else if i = j + 1 ∧ odd i then f (i div 2) else if i = j - 1 ∧ even i ∧ 1 ≤ j then f (i div 2) else 0)); i < dim_row U⇩f ∧ j < dim_col U⇩f⟧ ⟹ i = j + 1 ∧ odd i ⟶ U⇩f $$ (i, j) = complex_of_nat (f (i div 2))› 3. ‹⟦U⇩f ≡ Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_nat (case x of (i, j) ⇒ if i = j then 1 - f (i div 2) else if i = j + 1 ∧ odd i then f (i div 2) else if i = j - 1 ∧ even i ∧ 1 ≤ j then f (i div 2) else 0)); i < dim_row U⇩f ∧ j < dim_col U⇩f⟧ ⟹ 1 ≤ j ∧ i = j - 1 ∧ even i ⟶ U⇩f $$ (i, j) = complex_of_nat (f (i div 2))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . lemma (in jozsa) U⇩f_mult_without_empty_summands_sum_even: fixes i j A assumes "i < dim_row U⇩f" and "j < dim_col A" and "even i" and "dim_col U⇩f = dim_row A" shows "(∑k∈{0..< dim_row A}. U⇩f $$ (i,k) * A $$ (k,j)) =(∑k∈{i,i+1}. U⇩f $$ (i,k) * A $$ (k,j))" proof (-) (*goal: ‹(∑k = 0..<dim_row A. U⇩f $$ (i, k) * A $$ (k, j)) = (∑k∈{i, i + 1}. U⇩f $$ (i, k) * A $$ (k, j))›*) have "(∑k ∈ {0..< 2^(n+1)}. U⇩f $$ (i,k) * A $$ (k,j)) = (∑k ∈ {0..<i}. U⇩f $$ (i,k) * A $$ (k,j)) + (∑k ∈ {i,i+1}. U⇩f $$ (i,k) * A $$ (k,j)) + (∑k ∈ {(i+2)..< 2^(n+1)}. U⇩f $$ (i,k) * A $$ (k,j))" proof (-) (*goal: ‹(∑k = 0..<2 ^ (n + 1). U⇩f $$ (i, k) * A $$ (k, j)) = (∑k = 0..<i. U⇩f $$ (i, k) * A $$ (k, j)) + (∑k∈{i, i + 1}. U⇩f $$ (i, k) * A $$ (k, j)) + (∑k = i + 2..<2 ^ (n + 1). U⇩f $$ (i, k) * A $$ (k, j))›*) have "{0..< 2^(n+1)} = {0..<i} ∪ {i..< 2^(n+1)} ∧ {i..< 2^(n+1)} = {i,i+1} ∪ {(i+2)..<2^(n+1)}" using assms(1-3) (*‹i < dim_row U⇩f› ‹j < dim_col A› ‹even i›*) by auto moreover have "{0..<i} ∩ {i,i+1} = {} ∧ {i,i+1} ∩ {(i+2)..< 2^(n+1)} = {} ∧ {0..<i} ∩ {(i+2)..< 2^(n+1)} = {}" using assms (*‹i < dim_row U⇩f› ‹j < dim_col A› ‹even i› ‹dim_col U⇩f = dim_row A›*) by simp ultimately show "?thesis" (*goal: ‹(∑k = 0..<2 ^ (n + 1). U⇩f $$ (i, k) * A $$ (k, j)) = (∑k = 0..<i. U⇩f $$ (i, k) * A $$ (k, j)) + (∑k∈{i, i + 1}. U⇩f $$ (i, k) * A $$ (k, j)) + (∑k = i + 2..<2 ^ (n + 1). U⇩f $$ (i, k) * A $$ (k, j))›*) using sum.union_disjoint (*‹⟦finite (?A::?'b set); finite (?B::?'b set); ?A ∩ ?B = {}⟧ ⟹ sum (?g::?'b ⇒ ?'a) (?A ∪ ?B) = sum ?g ?A + sum ?g ?B›*) by (metis (no_types, lifting) finite_Un (*‹finite (?F ∪ ?G) = (finite ?F ∧ finite ?G)›*) finite_atLeastLessThan (*‹finite {?l..<?u}›*) is_num_normalize( (*‹?a + ?b + ?c = ?a + (?b + ?c)›*) 1) ivl_disj_int_two( (*‹{?l..<?m} ∩ {?m..<?u} = {}›*) 3)) qed moreover have "(∑k ∈ {0..<i}. U⇩f $$ (i,k) * A $$ (k,j)) = 0" proof (-) (*goal: ‹(∑k = 0..<i. U⇩f $$ (i, k) * A $$ (k, j)) = 0›*) have "k ∈ {0..<i} ⟶ (i≠k ∧ ¬(i=k+1 ∧ odd i) ∧ ¬ (i=k-1 ∧ even i ∧ k≥1))" for k using assms (*‹(i::nat) < dim_row U⇩f› ‹j < dim_col A› ‹even i› ‹dim_col U⇩f = dim_row (A::complex Matrix.mat)›*) by auto then have "k ∈ {0..<i} ⟶ U⇩f $$ (i,k) = 0" for k using assms(1) (*‹i < dim_row U⇩f›*) by auto then show "?thesis" (*goal: ‹(∑k = 0..<i. U⇩f $$ (i, k) * A $$ (k, j)) = 0›*) by simp qed moreover have "(∑k ∈ {(i+2)..< 2^(n+1)}. U⇩f $$ (i,k) * A $$ (k,j)) = 0" proof (-) (*goal: ‹(∑k = i + 2..<2 ^ (n + 1). U⇩f $$ (i, k) * A $$ (k, j)) = 0›*) have "k∈{(i+2)..< 2^(n+1)} ⟶ (i≠k ∧ ¬(i=k+1 ∧ odd i) ∧ ¬ (i=k-1 ∧ even i ∧ k≥1))" for k by auto then have "k ∈ {(i+2)..< 2^(n+1)}⟶ U⇩f $$ (i,k) = 0" for k using assms(1) (*‹i < dim_row U⇩f›*) by auto then show "?thesis" (*goal: ‹(∑k::nat = i + (2::nat)..<(2::nat) ^ ((n::nat) + (1::nat)). U⇩f $$ (i::nat, k) * (A::complex Matrix.mat) $$ (k, j::nat)) = (0::complex)›*) by simp qed moreover have "dim_row A = 2^(n+1)" using assms(4) (*‹dim_col U⇩f = dim_row (A::complex Matrix.mat)›*) by simp ultimately show "?thesis" (*goal: ‹(∑k::nat = 0::nat..<dim_row A. U⇩f $$ (i::nat, k) * (A::complex Matrix.mat) $$ (k, j::nat)) = (∑k::nat∈{i, i + (1::nat)}. U⇩f $$ (i, k) * A $$ (k, j))›*) by (metis (no_types, lifting) add.left_neutral (*‹0 + ?a = ?a›*) add.right_neutral (*‹?a + 0 = ?a›*)) qed lemma (in jozsa) U⇩f_mult_without_empty_summands_even: fixes i j A assumes "i < dim_row U⇩f" and "j < dim_col A" and "even i" and "dim_col U⇩f = dim_row A" shows "(U⇩f * A) $$ (i,j) = (∑k ∈ {i,i+1}. U⇩f $$ (i,k) * A $$ (k,j))" proof (-) (*goal: ‹(U⇩f * A) $$ (i, j) = (∑k∈{i, i + 1}. U⇩f $$ (i, k) * A $$ (k, j))›*) have "(U⇩f * A) $$ (i,j) = (∑ k∈{0..< dim_row A}. (U⇩f $$ (i,k)) * (A $$ (k,j)))" using assms(1,2,4) (*‹i < dim_row U⇩f› ‹(j::nat) < dim_col (A::complex Matrix.mat)› ‹dim_col U⇩f = dim_row A›*) index_matrix_prod (*‹⟦?i < dim_row ?A; ?j < dim_col ?B; dim_col ?A = dim_row ?B⟧ ⟹ (?A * ?B) $$ (?i, ?j) = (∑k<dim_row ?B. ?A $$ (?i, k) * ?B $$ (k, ?j))›*) by (simp add: atLeast0LessThan (*‹{0..<?n} = {..<?n}›*)) then show "?thesis" (*goal: ‹(U⇩f * A) $$ (i, j) = (∑k∈{i, i + 1}. U⇩f $$ (i, k) * A $$ (k, j))›*) using assms (*‹(i::nat) < dim_row U⇩f› ‹(j::nat) < dim_col (A::complex Matrix.mat)› ‹even i› ‹dim_col U⇩f = dim_row A›*) "U⇩f_mult_without_empty_summands_sum_even" (*‹⟦?i < dim_row U⇩f; ?j < dim_col ?A; even ?i; dim_col U⇩f = dim_row ?A⟧ ⟹ (∑k = 0..<dim_row ?A. U⇩f $$ (?i, k) * ?A $$ (k, ?j)) = (∑k∈{?i, ?i + 1}. U⇩f $$ (?i, k) * ?A $$ (k, ?j))›*) by simp qed lemma (in jozsa) U⇩f_mult_without_empty_summands_sum_odd: fixes i j A assumes "i < dim_row U⇩f" and "j < dim_col A" and "odd i" and "dim_col U⇩f = dim_row A" shows "(∑k∈{0..< dim_row A}. U⇩f $$ (i,k) * A $$ (k,j)) =(∑k∈{i-1,i}. U⇩f $$ (i,k) * A $$ (k,j))" proof (-) (*goal: ‹(∑k = 0..<dim_row A. U⇩f $$ (i, k) * A $$ (k, j)) = (∑k∈{i - 1, i}. U⇩f $$ (i, k) * A $$ (k, j))›*) have "(∑k∈{0..< 2^(n+1)}. U⇩f $$ (i,k) * A $$ (k,j)) = (∑k ∈ {0..<i-1}. U⇩f $$ (i,k) * A $$ (k,j)) + (∑k ∈ {i-1,i}. U⇩f $$ (i,k) * A $$ (k,j)) + (∑k ∈ {i+1..< 2^(n+1)}. U⇩f $$ (i,k) * A $$ (k,j))" proof (-) (*goal: ‹(∑k = 0..<2 ^ (n + 1). U⇩f $$ (i, k) * A $$ (k, j)) = (∑k = 0..<i - 1. U⇩f $$ (i, k) * A $$ (k, j)) + (∑k∈{i - 1, i}. U⇩f $$ (i, k) * A $$ (k, j)) + (∑k = i + 1..<2 ^ (n + 1). U⇩f $$ (i, k) * A $$ (k, j))›*) have "{0..< 2^(n+1)} = {0..<i-1} ∪ {i-1..< 2^(n+1)} ∧ {i-1..< 2^(n+1)} = {i-1,i} ∪ {i+1..<2^(n+1)}" using assms(1-3) (*‹i < dim_row U⇩f› ‹j < dim_col A› ‹odd i›*) by auto moreover have "{0..<i-1} ∩ {i-1,i} = {} ∧ {i-1,i} ∩ {i+1..< 2^(n+1)} = {} ∧ {0..<i-1} ∩ {i+1..< 2^(n+1)} = {}" using assms (*‹i < dim_row U⇩f› ‹j < dim_col A› ‹odd i› ‹dim_col U⇩f = dim_row A›*) by simp ultimately show "?thesis" (*goal: ‹(∑k = 0..<2 ^ (n + 1). U⇩f $$ (i, k) * A $$ (k, j)) = (∑k = 0..<i - 1. U⇩f $$ (i, k) * A $$ (k, j)) + (∑k∈{i - 1, i}. U⇩f $$ (i, k) * A $$ (k, j)) + (∑k = i + 1..<2 ^ (n + 1). U⇩f $$ (i, k) * A $$ (k, j))›*) using sum.union_disjoint (*‹⟦finite ?A; finite ?B; ?A ∩ ?B = {}⟧ ⟹ sum ?g (?A ∪ ?B) = sum ?g ?A + sum ?g ?B›*) by (metis (no_types, lifting) finite_Un (*‹finite ((?F::?'a set) ∪ (?G::?'a set)) = (finite ?F ∧ finite ?G)›*) finite_atLeastLessThan (*‹finite {?l::nat..<?u::nat}›*) is_num_normalize( (*‹(?a::?'a) + (?b::?'a) + (?c::?'a) = ?a + (?b + ?c)›*) 1) ivl_disj_int_two( (*‹{?l::?'a..<?m::?'a} ∩ {?m..<?u::?'a} = {}›*) 3)) qed moreover have "(∑k ∈ {0..<i-1}. U⇩f $$ (i,k) * A $$ (k,j)) = 0" proof (-) (*goal: ‹(∑k::nat = 0::nat..<i - (1::nat). U⇩f $$ (i::nat, k) * (A::complex Matrix.mat) $$ (k, j::nat)) = (0::complex)›*) have "k ∈ {0..<i-1} ⟶ (i≠k ∧ ¬(i=k+1 ∧ odd i) ∧ ¬ (i=k-1 ∧ even i ∧ k≥1))" for k by auto then have "k ∈ {0..<i-1} ⟶ U⇩f $$ (i,k) = 0" for k using assms(1) (*‹i < dim_row U⇩f›*) by auto then show "?thesis" (*goal: ‹(∑k = 0..<i - 1. U⇩f $$ (i, k) * A $$ (k, j)) = 0›*) by simp qed moreover have "(∑k ∈ {i+1..< 2^(n+1)}. U⇩f $$ (i,k) * A $$ (k,j)) = 0" using assms(3) (*‹odd i›*) by auto moreover have "dim_row A = 2^(n+1)" using assms(4) (*‹dim_col U⇩f = dim_row A›*) by simp ultimately show "?thesis" (*goal: ‹(∑k = 0..<dim_row A. U⇩f $$ (i, k) * A $$ (k, j)) = (∑k∈{i - 1, i}. U⇩f $$ (i, k) * A $$ (k, j))›*) by (metis (no_types, lifting) add.left_neutral (*‹0 + ?a = ?a›*) add.right_neutral (*‹?a + 0 = ?a›*)) qed lemma (in jozsa) U⇩f_mult_without_empty_summands_odd: fixes i j A assumes "i < dim_row U⇩f" and "j < dim_col A" and "odd i" and "dim_col U⇩f = dim_row A" shows "(U⇩f * A) $$ (i,j) = (∑k ∈ {i-1,i}. U⇩f $$ (i,k) * A $$ (k,j)) " proof (-) (*goal: ‹(U⇩f * A) $$ (i, j) = (∑k∈{i - 1, i}. U⇩f $$ (i, k) * A $$ (k, j))›*) have "(U⇩f * A) $$ (i,j) = (∑k ∈ {0 ..< dim_row A}. (U⇩f $$ (i,k)) * (A $$ (k,j)))" using assms(1,2,4) (*‹i < dim_row U⇩f› ‹(j::nat) < dim_col (A::complex Matrix.mat)› ‹dim_col U⇩f = dim_row (A::complex Matrix.mat)›*) index_matrix_prod (*‹⟦?i < dim_row ?A; ?j < dim_col ?B; dim_col ?A = dim_row ?B⟧ ⟹ (?A * ?B) $$ (?i, ?j) = (∑k<dim_row ?B. ?A $$ (?i, k) * ?B $$ (k, ?j))›*) by (simp add: atLeast0LessThan (*‹{0..<?n} = {..<?n}›*)) then show "?thesis" (*goal: ‹(U⇩f * A) $$ (i, j) = (∑k∈{i - 1, i}. U⇩f $$ (i, k) * A $$ (k, j))›*) using assms (*‹i < dim_row U⇩f› ‹j < dim_col A› ‹odd i› ‹dim_col U⇩f = dim_row A›*) "U⇩f_mult_without_empty_summands_sum_odd" (*‹⟦?i < dim_row U⇩f; ?j < dim_col ?A; odd ?i; dim_col U⇩f = dim_row ?A⟧ ⟹ (∑k = 0..<dim_row ?A. U⇩f $$ (?i, k) * ?A $$ (k, ?j)) = (∑k∈{?i - 1, ?i}. U⇩f $$ (?i, k) * ?A $$ (k, ?j))›*) by auto qed text ‹@{term U⇩f} is a gate.› lemma (in jozsa) transpose_of_jozsa_transform: shows "(U⇩f)⇧t = U⇩f" proof (standard) (*goals: 1. ‹⋀i j. ⟦i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧t $$ (i, j) = U⇩f $$ (i, j)› 2. ‹dim_row U⇩f⇧t = dim_row U⇩f› 3. ‹dim_col U⇩f⇧t = dim_col U⇩f›*) show "dim_row (U⇩f⇧t) = dim_row U⇩f" by simp next (*goals: 1. ‹⋀(i::nat) j::nat. ⟦i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧t $$ (i, j) = U⇩f $$ (i, j)› 2. ‹dim_col U⇩f⇧t = dim_col U⇩f›*) show "dim_col (U⇩f⇧t) = dim_col U⇩f" by simp next (*goal: ‹⋀i j. ⟦i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧t $$ (i, j) = U⇩f $$ (i, j)›*) fix i :: nat and j :: nat assume a0: "i < dim_row U⇩f" and a1: "j < dim_col U⇩f" (*‹(i::nat) < dim_row U⇩f› ‹(j::nat) < dim_col U⇩f›*) then show "U⇩f⇧t $$ (i, j) = U⇩f $$ (i, j)" proof (induct rule: disj_four_cases (*‹⟦?A ∨ ?B ∨ ?C ∨ ?D; ?A ⟹ ?P; ?B ⟹ ?P; ?C ⟹ ?P; ?D ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹?A4 ∨ ?B4 ∨ ?C4 ∨ ?D4› 2. ‹⟦?A4; i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧t $$ (i, j) = U⇩f $$ (i, j)› 3. ‹⟦?B4; i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧t $$ (i, j) = U⇩f $$ (i, j)› 4. ‹⟦?C4; i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧t $$ (i, j) = U⇩f $$ (i, j)› 5. ‹⟦?D4; i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧t $$ (i, j) = U⇩f $$ (i, j)›*) show "i=j ∨ (i=j+1 ∧ odd i) ∨ (i=j-1 ∧ even i ∧ j≥1) ∨ (i≠j ∧ ¬(i=j+1 ∧ odd i) ∧ ¬ (i=j-1 ∧ even i ∧ j≥1))" by linarith next (*goals: 1. ‹⟦i = j; i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧t $$ (i, j) = U⇩f $$ (i, j)› 2. ‹⟦i = j + 1 ∧ odd i; i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧t $$ (i, j) = U⇩f $$ (i, j)› 3. ‹⟦i = j - 1 ∧ even i ∧ 1 ≤ j; i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧t $$ (i, j) = U⇩f $$ (i, j)› 4. ‹⟦i ≠ j ∧ ¬ (i = j + 1 ∧ odd i) ∧ ¬ (i = j - 1 ∧ even i ∧ 1 ≤ j); i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧t $$ (i, j) = U⇩f $$ (i, j)›*) assume "i = j" (*‹(i::nat) = (j::nat)›*) then show "U⇩f⇧t $$ (i,j) = U⇩f $$ (i,j)" using a0 (*‹i < dim_row U⇩f›*) by simp next (*goals: 1. ‹⟦i = j + 1 ∧ odd i; i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧t $$ (i, j) = U⇩f $$ (i, j)› 2. ‹⟦i = j - 1 ∧ even i ∧ 1 ≤ j; i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧t $$ (i, j) = U⇩f $$ (i, j)› 3. ‹⟦i ≠ j ∧ ¬ (i = j + 1 ∧ odd i) ∧ ¬ (i = j - 1 ∧ even i ∧ 1 ≤ j); i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧t $$ (i, j) = U⇩f $$ (i, j)›*) assume "(i=j+1 ∧ odd i)" (*‹(i::nat) = (j::nat) + (1::nat) ∧ odd i›*) then show "U⇩f⇧t $$ (i,j) = U⇩f $$ (i,j)" using transpose_mat_def (*‹?A⇧t ≡ Matrix.mat (dim_col ?A) (dim_row ?A) (λ(i, j). ?A $$ (j, i))›*) a0 (*‹i < dim_row U⇩f›*) a1 (*‹(j::nat) < dim_col U⇩f›*) by auto next (*goals: 1. ‹⟦i = j - 1 ∧ even i ∧ 1 ≤ j; i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧t $$ (i, j) = U⇩f $$ (i, j)› 2. ‹⟦i ≠ j ∧ ¬ (i = j + 1 ∧ odd i) ∧ ¬ (i = j - 1 ∧ even i ∧ 1 ≤ j); i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧t $$ (i, j) = U⇩f $$ (i, j)›*) assume a2: "(i=j-1 ∧ even i ∧ j≥1)" (*‹(i::nat) = (j::nat) - (1::nat) ∧ even i ∧ (1::nat) ≤ j›*) then have "U⇩f $$ (i,j) = f (i div 2)" using a0 (*‹(i::nat) < dim_row U⇩f›*) a1 (*‹j < dim_col U⇩f›*) jozsa_transform_coeff (*‹(?i::nat) < dim_row U⇩f ∧ (?j::nat) < dim_col U⇩f ⟹ ?i = ?j ⟶ U⇩f $$ (?i, ?j) = complex_of_nat ((1::nat) - (f::nat ⇒ nat) (?i div (2::nat)))› ‹?i < dim_row U⇩f ∧ ?j < dim_col U⇩f ⟹ ?i = ?j + 1 ∧ odd ?i ⟶ U⇩f $$ (?i, ?j) = complex_of_nat (f (?i div 2))› ‹?i < dim_row U⇩f ∧ ?j < dim_col U⇩f ⟹ 1 ≤ ?j ∧ ?i = ?j - 1 ∧ even ?i ⟶ U⇩f $$ (?i, ?j) = complex_of_nat (f (?i div 2))›*) by auto moreover have "U⇩f $$ (j,i) = f (i div 2)" using a0 (*‹i < dim_row U⇩f›*) a1 (*‹(j::nat) < dim_col U⇩f›*) a2 (*‹i = j - 1 ∧ even i ∧ 1 ≤ j›*) jozsa_transform_coeff (*‹?i < dim_row U⇩f ∧ ?j < dim_col U⇩f ⟹ ?i = ?j ⟶ U⇩f $$ (?i, ?j) = complex_of_nat (1 - f (?i div 2))› ‹?i < dim_row U⇩f ∧ ?j < dim_col U⇩f ⟹ ?i = ?j + 1 ∧ odd ?i ⟶ U⇩f $$ (?i, ?j) = complex_of_nat (f (?i div 2))› ‹?i < dim_row U⇩f ∧ ?j < dim_col U⇩f ⟹ 1 ≤ ?j ∧ ?i = ?j - 1 ∧ even ?i ⟶ U⇩f $$ (?i, ?j) = complex_of_nat (f (?i div 2))›*) by (metis add_diff_assoc2 (*‹(?k::nat) ≤ (?j::nat) ⟹ ?j - ?k + (?i::nat) = ?j + ?i - ?k›*) diff_add_inverse2 (*‹(?m::nat) + (?n::nat) - ?n = ?m›*) even_plus_one_iff (*‹even ((?a::?'a) + (1::?'a)) = odd ?a›*) even_succ_div_two (*‹even (?a::?'a) ⟹ (?a + (1::?'a)) div (2::?'a) = ?a div (2::?'a)›*) jozsa_transform_dim (*‹dim_row U⇩f = (2::nat) ^ ((n::nat) + (1::nat))› ‹dim_col U⇩f = (2::nat) ^ ((n::nat) + (1::nat))›*)) ultimately show "?thesis" (*goal: ‹U⇩f⇧t $$ (i::nat, j::nat) = U⇩f $$ (i, j)›*) using transpose_mat_def (*‹?A⇧t ≡ Matrix.mat (dim_col ?A) (dim_row ?A) (λ(i, j). ?A $$ (j, i))›*) a0 (*‹i < dim_row U⇩f›*) a1 (*‹j < dim_col U⇩f›*) by simp next (*goal: ‹⟦i ≠ j ∧ ¬ (i = j + 1 ∧ odd i) ∧ ¬ (i = j - 1 ∧ even i ∧ 1 ≤ j); i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧t $$ (i, j) = U⇩f $$ (i, j)›*) assume a2: "(i≠j ∧ ¬(i=j+1 ∧ odd i) ∧ ¬ (i=j-1 ∧ even i ∧ j≥1))" (*‹(i::nat) ≠ (j::nat) ∧ ¬ (i = j + (1::nat) ∧ odd i) ∧ ¬ (i = j - (1::nat) ∧ even i ∧ (1::nat) ≤ j)›*) then have "(j≠i ∧ ¬(j=i+1 ∧ odd j) ∧ ¬ (j=i-1 ∧ even j ∧ i≥1))" by (metis le_imp_diff_is_add (*‹?i ≤ ?j ⟹ (?j - ?i = ?k) = (?j = ?k + ?i)›*) diff_add_inverse (*‹?n + ?m - ?n = ?m›*) even_plus_one_iff (*‹even (?a + 1) = odd ?a›*) le_add1 (*‹?n ≤ ?n + ?m›*)) then have "U⇩f $$ (j,i) = 0" using jozsa_transform_coeff_is_zero (*‹?i < dim_row U⇩f ∧ ?j < dim_col U⇩f ⟹ ?i ≠ ?j ∧ ¬ (?i = ?j + 1 ∧ odd ?i) ∧ ¬ (?i = ?j - 1 ∧ even ?i ∧ 1 ≤ ?j) ⟶ U⇩f $$ (?i, ?j) = 0›*) a0 (*‹i < dim_row U⇩f›*) a1 (*‹j < dim_col U⇩f›*) by auto moreover have "U⇩f $$ (i,j) = 0" using jozsa_transform_coeff_is_zero (*‹?i < dim_row U⇩f ∧ ?j < dim_col U⇩f ⟹ ?i ≠ ?j ∧ ¬ (?i = ?j + 1 ∧ odd ?i) ∧ ¬ (?i = ?j - 1 ∧ even ?i ∧ 1 ≤ ?j) ⟶ U⇩f $$ (?i, ?j) = 0›*) a0 (*‹i < dim_row U⇩f›*) a1 (*‹j < dim_col U⇩f›*) a2 (*‹i ≠ j ∧ ¬ (i = j + 1 ∧ odd i) ∧ ¬ (i = j - 1 ∧ even i ∧ 1 ≤ j)›*) by auto ultimately show "U⇩f⇧t $$ (i,j) = U⇩f $$ (i,j)" using transpose_mat_def (*‹?A⇧t ≡ Matrix.mat (dim_col ?A) (dim_row ?A) (λ(i, j). ?A $$ (j, i))›*) a0 (*‹(i::nat) < dim_row U⇩f›*) a1 (*‹(j::nat) < dim_col U⇩f›*) by simp qed qed lemma (in jozsa) adjoint_of_jozsa_transform: shows "(U⇩f)⇧† = U⇩f" proof (standard) (*goals: 1. ‹⋀i j. ⟦i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧† $$ (i, j) = U⇩f $$ (i, j)› 2. ‹dim_row U⇩f⇧† = dim_row U⇩f› 3. ‹dim_col U⇩f⇧† = dim_col U⇩f›*) show "dim_row (U⇩f⇧†) = dim_row U⇩f" by simp next (*goals: 1. ‹⋀(i::nat) j::nat. ⟦i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧† $$ (i, j) = U⇩f $$ (i, j)› 2. ‹dim_col U⇩f⇧† = dim_col U⇩f›*) show "dim_col (U⇩f⇧†) = dim_col U⇩f" by simp next (*goal: ‹⋀i j. ⟦i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧† $$ (i, j) = U⇩f $$ (i, j)›*) fix i :: nat and j :: nat assume a0: "i < dim_row U⇩f" and a1: "j < dim_col U⇩f" (*‹(i::nat) < dim_row U⇩f› ‹(j::nat) < dim_col U⇩f›*) then show "U⇩f⇧† $$ (i,j) = U⇩f $$ (i,j)" proof (induct rule: disj_four_cases (*‹⟦(?A::bool) ∨ (?B::bool) ∨ (?C::bool) ∨ (?D::bool); ?A ⟹ ?P::bool; ?B ⟹ ?P; ?C ⟹ ?P; ?D ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹?A4 ∨ ?B4 ∨ ?C4 ∨ ?D4› 2. ‹⟦?A4; i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧† $$ (i, j) = U⇩f $$ (i, j)› 3. ‹⟦?B4; i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧† $$ (i, j) = U⇩f $$ (i, j)› 4. ‹⟦?C4; i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧† $$ (i, j) = U⇩f $$ (i, j)› 5. ‹⟦?D4; i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧† $$ (i, j) = U⇩f $$ (i, j)›*) show "i=j ∨ (i=j+1 ∧ odd i) ∨ (i=j-1 ∧ even i ∧ j≥1) ∨ (i≠j ∧ ¬(i=j+1 ∧ odd i) ∧ ¬ (i=j-1 ∧ even i ∧ j≥1))" by linarith next (*goals: 1. ‹⟦i = j; i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧† $$ (i, j) = U⇩f $$ (i, j)› 2. ‹⟦i = j + 1 ∧ odd i; i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧† $$ (i, j) = U⇩f $$ (i, j)› 3. ‹⟦i = j - 1 ∧ even i ∧ 1 ≤ j; i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧† $$ (i, j) = U⇩f $$ (i, j)› 4. ‹⟦i ≠ j ∧ ¬ (i = j + 1 ∧ odd i) ∧ ¬ (i = j - 1 ∧ even i ∧ 1 ≤ j); i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧† $$ (i, j) = U⇩f $$ (i, j)›*) assume "i=j" (*‹(i::nat) = (j::nat)›*) then show "U⇩f⇧† $$ (i,j) = U⇩f $$ (i,j)" using a0 (*‹i < dim_row U⇩f›*) dagger_def (*‹?M⇧† ≡ Matrix.mat (dim_col ?M) (dim_row ?M) (λ(i, j). cnj (?M $$ (j, i)))›*) by simp next (*goals: 1. ‹⟦(i::nat) = (j::nat) + (1::nat) ∧ odd i; i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧† $$ (i, j) = U⇩f $$ (i, j)› 2. ‹⟦(i::nat) = (j::nat) - (1::nat) ∧ even i ∧ (1::nat) ≤ j; i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧† $$ (i, j) = U⇩f $$ (i, j)› 3. ‹⟦(i::nat) ≠ (j::nat) ∧ ¬ (i = j + (1::nat) ∧ odd i) ∧ ¬ (i = j - (1::nat) ∧ even i ∧ (1::nat) ≤ j); i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧† $$ (i, j) = U⇩f $$ (i, j)›*) assume "(i=j+1 ∧ odd i)" (*‹(i::nat) = (j::nat) + (1::nat) ∧ odd i›*) then show "U⇩f⇧† $$ (i,j) = U⇩f $$ (i,j)" using a0 (*‹(i::nat) < dim_row U⇩f›*) dagger_def (*‹?M⇧† ≡ Matrix.mat (dim_col ?M) (dim_row ?M) (λ(i, j). cnj (?M $$ (j, i)))›*) by auto next (*goals: 1. ‹⟦i = j - 1 ∧ even i ∧ 1 ≤ j; i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧† $$ (i, j) = U⇩f $$ (i, j)› 2. ‹⟦i ≠ j ∧ ¬ (i = j + 1 ∧ odd i) ∧ ¬ (i = j - 1 ∧ even i ∧ 1 ≤ j); i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧† $$ (i, j) = U⇩f $$ (i, j)›*) assume a2: "(i=j-1 ∧ even i ∧ j≥1)" (*‹(i::nat) = (j::nat) - (1::nat) ∧ even i ∧ (1::nat) ≤ j›*) then have "U⇩f $$ (i,j) = f (i div 2)" using a0 (*‹(i::nat) < dim_row U⇩f›*) a1 (*‹j < dim_col U⇩f›*) jozsa_transform_coeff (*‹?i < dim_row U⇩f ∧ ?j < dim_col U⇩f ⟹ ?i = ?j ⟶ U⇩f $$ (?i, ?j) = complex_of_nat (1 - f (?i div 2))› ‹?i < dim_row U⇩f ∧ ?j < dim_col U⇩f ⟹ ?i = ?j + 1 ∧ odd ?i ⟶ U⇩f $$ (?i, ?j) = complex_of_nat (f (?i div 2))› ‹?i < dim_row U⇩f ∧ ?j < dim_col U⇩f ⟹ 1 ≤ ?j ∧ ?i = ?j - 1 ∧ even ?i ⟶ U⇩f $$ (?i, ?j) = complex_of_nat (f (?i div 2))›*) by auto moreover have "U⇩f⇧† $$ (j,i) = f (i div 2)" using a1 (*‹j < dim_col U⇩f›*) a2 (*‹i = j - 1 ∧ even i ∧ 1 ≤ j›*) jozsa_transform_coeff (*‹?i < dim_row U⇩f ∧ ?j < dim_col U⇩f ⟹ ?i = ?j ⟶ U⇩f $$ (?i, ?j) = complex_of_nat (1 - f (?i div 2))› ‹?i < dim_row U⇩f ∧ ?j < dim_col U⇩f ⟹ ?i = ?j + 1 ∧ odd ?i ⟶ U⇩f $$ (?i, ?j) = complex_of_nat (f (?i div 2))› ‹?i < dim_row U⇩f ∧ ?j < dim_col U⇩f ⟹ 1 ≤ ?j ∧ ?i = ?j - 1 ∧ even ?i ⟶ U⇩f $$ (?i, ?j) = complex_of_nat (f (?i div 2))›*) dagger_def (*‹?M⇧† ≡ Matrix.mat (dim_col ?M) (dim_row ?M) (λ(i, j). cnj (?M $$ (j, i)))›*) by auto ultimately show "U⇩f⇧† $$ (i,j) = U⇩f $$ (i,j)" by (metis a0 (*‹i < dim_row U⇩f›*) a1 (*‹j < dim_col U⇩f›*) cnj_transpose_is_dagger (*‹?M⇧⋆⇧t = ?M⇧†›*) dim_row_of_dagger (*‹dim_row ?M⇧† = dim_col ?M›*) index_transpose_mat (*‹⟦?i < dim_col ?A; ?j < dim_row ?A⟧ ⟹ ?A⇧t $$ (?i, ?j) = ?A $$ (?j, ?i)› ‹dim_row ?A⇧t = dim_col ?A› ‹dim_col ?A⇧t = dim_row ?A›*) dagger_of_transpose_is_cnj (*‹?M⇧t⇧† = ?M⇧⋆›*) transpose_of_jozsa_transform (*‹U⇩f⇧t = U⇩f›*)) next (*goal: ‹⟦i ≠ j ∧ ¬ (i = j + 1 ∧ odd i) ∧ ¬ (i = j - 1 ∧ even i ∧ 1 ≤ j); i < dim_row U⇩f; j < dim_col U⇩f⟧ ⟹ U⇩f⇧† $$ (i, j) = U⇩f $$ (i, j)›*) assume a2: "(i≠j ∧ ¬(i=j+1 ∧ odd i) ∧ ¬ (i=j-1 ∧ even i ∧ j≥1))" (*‹(i::nat) ≠ (j::nat) ∧ ¬ (i = j + (1::nat) ∧ odd i) ∧ ¬ (i = j - (1::nat) ∧ even i ∧ (1::nat) ≤ j)›*) then have f0: "(i≠j ∧ ¬(j=i+1 ∧ odd j) ∧ ¬ (j=i-1 ∧ even j ∧ i≥1))" by (metis le_imp_diff_is_add (*‹?i ≤ ?j ⟹ (?j - ?i = ?k) = (?j = ?k + ?i)›*) diff_add_inverse (*‹?n + ?m - ?n = ?m›*) even_plus_one_iff (*‹even (?a + 1) = odd ?a›*) le_add1 (*‹?n ≤ ?n + ?m›*)) then have "U⇩f $$ (j,i) = 0" and "cnj 0 = 0" using jozsa_transform_coeff_is_zero (*‹?i < dim_row U⇩f ∧ ?j < dim_col U⇩f ⟹ ?i ≠ ?j ∧ ¬ (?i = ?j + 1 ∧ odd ?i) ∧ ¬ (?i = ?j - 1 ∧ even ?i ∧ 1 ≤ ?j) ⟶ U⇩f $$ (?i, ?j) = 0›*) a0 (*‹(i::nat) < dim_row U⇩f›*) a1 (*‹j < dim_col U⇩f›*) a2 (*‹i ≠ j ∧ ¬ (i = j + 1 ∧ odd i) ∧ ¬ (i = j - 1 ∧ even i ∧ 1 ≤ j)›*) apply - (*goals: 1. ‹⟦i ≠ j ∧ ¬ (j = i + 1 ∧ odd j) ∧ ¬ (j = i - 1 ∧ even j ∧ 1 ≤ i); ⋀i j. i < dim_row U⇩f ∧ j < dim_col U⇩f ⟹ i ≠ j ∧ ¬ (i = j + 1 ∧ odd i) ∧ ¬ (i = j - 1 ∧ even i ∧ 1 ≤ j) ⟶ U⇩f $$ (i, j) = 0; i < dim_row U⇩f; j < dim_col U⇩f; i ≠ j ∧ ¬ (i = j + 1 ∧ odd i) ∧ ¬ (i = j - 1 ∧ even i ∧ 1 ≤ j)⟧ ⟹ U⇩f $$ (j, i) = 0› 2. ‹⟦i ≠ j ∧ ¬ (j = i + 1 ∧ odd j) ∧ ¬ (j = i - 1 ∧ even j ∧ 1 ≤ i); ⋀i j. i < dim_row U⇩f ∧ j < dim_col U⇩f ⟹ i ≠ j ∧ ¬ (i = j + 1 ∧ odd i) ∧ ¬ (i = j - 1 ∧ even i ∧ 1 ≤ j) ⟶ U⇩f $$ (i, j) = 0; i < dim_row U⇩f; j < dim_col U⇩f; i ≠ j ∧ ¬ (i = j + 1 ∧ odd i) ∧ ¬ (i = j - 1 ∧ even i ∧ 1 ≤ j)⟧ ⟹ cnj 0 = 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . then have "U⇩f⇧† $$ (i,j) = 0" using a0 (*‹i < dim_row U⇩f›*) a1 (*‹j < dim_col U⇩f›*) dagger_def (*‹?M⇧† ≡ Matrix.mat (dim_col ?M) (dim_row ?M) (λ(i, j). cnj (?M $$ (j, i)))›*) by simp then show "U⇩f⇧† $$ (i, j) = U⇩f $$ (i, j)" using a0 (*‹i < dim_row U⇩f›*) a1 (*‹j < dim_col U⇩f›*) a2 (*‹(i::nat) ≠ (j::nat) ∧ ¬ (i = j + (1::nat) ∧ odd i) ∧ ¬ (i = j - (1::nat) ∧ even i ∧ (1::nat) ≤ j)›*) jozsa_transform_coeff_is_zero (*‹?i < dim_row U⇩f ∧ ?j < dim_col U⇩f ⟹ ?i ≠ ?j ∧ ¬ (?i = ?j + 1 ∧ odd ?i) ∧ ¬ (?i = ?j - 1 ∧ even ?i ∧ 1 ≤ ?j) ⟶ U⇩f $$ (?i, ?j) = 0›*) by auto qed qed lemma (in jozsa) jozsa_transform_is_unitary_index_even: fixes i j:: nat assumes "i < dim_row U⇩f" and "j < dim_col U⇩f" and "even i" shows "(U⇩f * U⇩f) $$ (i,j) = 1⇩m (dim_col U⇩f) $$ (i,j)" proof (-) (*goal: ‹(U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)›*) have "(U⇩f * U⇩f) $$ (i,j) = (∑k ∈ {i,i+1}. U⇩f $$ (i,k) * U⇩f $$ (k,j)) " using "U⇩f_mult_without_empty_summands_even"[of i j U⇩f] (*‹⟦i < dim_row U⇩f; j < dim_col U⇩f; even i; dim_col U⇩f = dim_row U⇩f⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = (∑k∈{i, i + 1}. U⇩f $$ (i, k) * U⇩f $$ (k, j))›*) assms (*‹i < dim_row U⇩f› ‹(j::nat) < dim_col U⇩f› ‹even i›*) by simp moreover have "U⇩f $$ (i,i) * U⇩f $$ (i,j) = (1-f(i div 2)) * U⇩f $$ (i,j)" using assms(1,3) (*‹i < dim_row U⇩f› ‹even i›*) by simp moreover have f0: "U⇩f $$ (i,i+1) * U⇩f $$ (i+1,j) = f(i div 2) * U⇩f $$ (i+1,j)" by (metis One_nat_def (*‹1 = Suc 0›*) Suc_leI (*‹?m < ?n ⟹ Suc ?m ≤ ?n›*) add.right_neutral (*‹?a + 0 = ?a›*) add_Suc_right (*‹?m + Suc ?n = Suc (?m + ?n)›*) assms( (*‹i < dim_row U⇩f›*) 1) assms( (*‹even i›*) 3) diff_add_inverse2 (*‹?m + ?n - ?n = ?m›*) even_add (*‹even (?a + ?b) = (even ?a = even ?b)›*) even_mult_iff (*‹even (?a * ?b) = (even ?a ∨ even ?b)›*) jozsa_transform_coeff( (*‹?i < dim_row U⇩f ∧ ?j < dim_col U⇩f ⟹ 1 ≤ ?j ∧ ?i = ?j - 1 ∧ even ?i ⟶ U⇩f $$ (?i, ?j) = complex_of_nat (f (?i div 2))›*) 3) jozsa_transform_dim (*‹dim_row U⇩f = 2 ^ (n + 1)› ‹dim_col U⇩f = 2 ^ (n + 1)›*) le_add2 (*‹?n ≤ ?m + ?n›*) le_eq_less_or_eq (*‹(?m ≤ ?n) = (?m < ?n ∨ ?m = ?n)›*) odd_one (*‹odd 1›*) one_add_one (*‹1 + 1 = 2›*) power.simps( (*‹?a ^ Suc ?n = ?a * ?a ^ ?n›*) 2)) ultimately have f1: "(U⇩f * U⇩f) $$ (i,j) = (1-f(i div 2)) * U⇩f $$ (i,j) + f(i div 2) * U⇩f $$ (i+1,j)" by auto thus "?thesis" (*goal: ‹(U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)›*) proof (induct rule: disj_four_cases (*‹⟦?A ∨ ?B ∨ ?C ∨ ?D; ?A ⟹ ?P; ?B ⟹ ?P; ?C ⟹ ?P; ?D ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹(?A2::bool) ∨ (?B2::bool) ∨ (?C2::bool) ∨ (?D2::bool)› 2. ‹⟦?A2::bool; (U⇩f * U⇩f) $$ (i::nat, j::nat) = complex_of_nat ((1::nat) - (f::nat ⇒ nat) (i div (2::nat))) * U⇩f $$ (i, j) + complex_of_nat (f (i div (2::nat))) * U⇩f $$ (i + (1::nat), j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)› 3. ‹⟦?B2::bool; (U⇩f * U⇩f) $$ (i::nat, j::nat) = complex_of_nat ((1::nat) - (f::nat ⇒ nat) (i div (2::nat))) * U⇩f $$ (i, j) + complex_of_nat (f (i div (2::nat))) * U⇩f $$ (i + (1::nat), j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)› 4. ‹⟦?C2::bool; (U⇩f * U⇩f) $$ (i::nat, j::nat) = complex_of_nat ((1::nat) - (f::nat ⇒ nat) (i div (2::nat))) * U⇩f $$ (i, j) + complex_of_nat (f (i div (2::nat))) * U⇩f $$ (i + (1::nat), j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)› 5. ‹⟦?D2::bool; (U⇩f * U⇩f) $$ (i::nat, j::nat) = complex_of_nat ((1::nat) - (f::nat ⇒ nat) (i div (2::nat))) * U⇩f $$ (i, j) + complex_of_nat (f (i div (2::nat))) * U⇩f $$ (i + (1::nat), j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)›*) show "j=i ∨ (j=i+1 ∧ odd j) ∨ (j=i-1 ∧ even j ∧ i≥1) ∨ (j≠i ∧ ¬(j=i+1 ∧ odd j) ∧ ¬ (j=i-1 ∧ even j ∧ i≥1))" by linarith next (*goals: 1. ‹⟦(j::nat) = (i::nat); (U⇩f * U⇩f) $$ (i, j) = complex_of_nat ((1::nat) - (f::nat ⇒ nat) (i div (2::nat))) * U⇩f $$ (i, j) + complex_of_nat (f (i div (2::nat))) * U⇩f $$ (i + (1::nat), j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)› 2. ‹⟦(j::nat) = (i::nat) + (1::nat) ∧ odd j; (U⇩f * U⇩f) $$ (i, j) = complex_of_nat ((1::nat) - (f::nat ⇒ nat) (i div (2::nat))) * U⇩f $$ (i, j) + complex_of_nat (f (i div (2::nat))) * U⇩f $$ (i + (1::nat), j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)› 3. ‹⟦(j::nat) = (i::nat) - (1::nat) ∧ even j ∧ (1::nat) ≤ i; (U⇩f * U⇩f) $$ (i, j) = complex_of_nat ((1::nat) - (f::nat ⇒ nat) (i div (2::nat))) * U⇩f $$ (i, j) + complex_of_nat (f (i div (2::nat))) * U⇩f $$ (i + (1::nat), j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)› 4. ‹⟦(j::nat) ≠ (i::nat) ∧ ¬ (j = i + (1::nat) ∧ odd j) ∧ ¬ (j = i - (1::nat) ∧ even j ∧ (1::nat) ≤ i); (U⇩f * U⇩f) $$ (i, j) = complex_of_nat ((1::nat) - (f::nat ⇒ nat) (i div (2::nat))) * U⇩f $$ (i, j) + complex_of_nat (f (i div (2::nat))) * U⇩f $$ (i + (1::nat), j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)›*) assume a0: "j=i" (*‹(j::nat) = (i::nat)›*) then have "U⇩f $$ (i,j) = (1-f(i div 2))" using assms(1,2) (*‹i < dim_row U⇩f› ‹j < dim_col U⇩f›*) a0 (*‹j = i›*) by simp moreover have "U⇩f $$ (i+1,j) = f(i div 2)" using assms(1,3) (*‹i < dim_row U⇩f› ‹even i›*) a0 (*‹j = i›*) by auto ultimately have "(U⇩f * U⇩f) $$ (i,j) = (1-f(i div 2)) * (1-f(i div 2)) + f(i div 2) * f(i div 2)" using f1 (*‹(U⇩f * U⇩f) $$ (i::nat, j::nat) = complex_of_nat ((1::nat) - (f::nat ⇒ nat) (i div (2::nat))) * U⇩f $$ (i, j) + complex_of_nat (f (i div (2::nat))) * U⇩f $$ (i + (1::nat), j)›*) by simp moreover have "(1-f(i div 2)) * (1-f(i div 2)) + f(i div 2) * f(i div 2) = 1" using f_values (*‹∀x∈{i. i < 2 ^ n}. f x = 0 ∨ f x = 1›*) assms(1) (*‹(i::nat) < dim_row U⇩f›*) by (metis (no_types, lifting) Nat.minus_nat.diff_0 (*‹?m - 0 = ?m›*) diff_add_0 (*‹?n - (?n + ?m) = 0›*) diff_add_inverse (*‹?n + ?m - ?n = ?m›*) jozsa_transform_dim( (*‹dim_row U⇩f = 2 ^ (n + 1)›*) 1) less_power_add_imp_div_less (*‹?i < 2 ^ (?m + ?n) ⟹ ?i div 2 ^ ?n < 2 ^ ?m›*) mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*) mult_eq_if (*‹?m * ?n = (if ?m = 0 then 0 else ?n + (?m - 1) * ?n)›*) one_power2 (*‹1² = 1›*) power2_eq_square (*‹?a² = ?a * ?a›*) power_one_right (*‹?a ^ 1 = ?a›*)) ultimately show "(U⇩f * U⇩f) $$ (i,j) = 1⇩m (dim_col U⇩f) $$ (i,j)" by (metis assms( (*‹j < dim_col U⇩f›*) 2) a0 (*‹j = i›*) index_one_mat( (*‹⟦?i < ?n; ?j < ?n⟧ ⟹ 1⇩m ?n $$ (?i, ?j) = (if ?i = ?j then 1 else 0)›*) 1) of_nat_1 (*‹of_nat 1 = 1›*)) next (*goals: 1. ‹⟦j = i + 1 ∧ odd j; (U⇩f * U⇩f) $$ (i, j) = complex_of_nat (1 - f (i div 2)) * U⇩f $$ (i, j) + complex_of_nat (f (i div 2)) * U⇩f $$ (i + 1, j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)› 2. ‹⟦j = i - 1 ∧ even j ∧ 1 ≤ i; (U⇩f * U⇩f) $$ (i, j) = complex_of_nat (1 - f (i div 2)) * U⇩f $$ (i, j) + complex_of_nat (f (i div 2)) * U⇩f $$ (i + 1, j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)› 3. ‹⟦j ≠ i ∧ ¬ (j = i + 1 ∧ odd j) ∧ ¬ (j = i - 1 ∧ even j ∧ 1 ≤ i); (U⇩f * U⇩f) $$ (i, j) = complex_of_nat (1 - f (i div 2)) * U⇩f $$ (i, j) + complex_of_nat (f (i div 2)) * U⇩f $$ (i + 1, j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)›*) assume a0: "(j=i+1 ∧ odd j)" (*‹(j::nat) = (i::nat) + (1::nat) ∧ odd j›*) then have "U⇩f $$ (i,j) = f(i div 2)" using assms(1,2) (*‹i < dim_row U⇩f› ‹j < dim_col U⇩f›*) a0 (*‹(j::nat) = (i::nat) + (1::nat) ∧ odd j›*) by simp moreover have "U⇩f $$ (i+1,j) = (1-f(i div 2))" using assms(2,3) (*‹j < dim_col U⇩f› ‹even (i::nat)›*) a0 (*‹(j::nat) = (i::nat) + (1::nat) ∧ odd j›*) by simp ultimately have "(U⇩f * U⇩f) $$ (i,j) = (1-f(i div 2)) * f(i div 2) + f(i div 2) * (1-f(i div 2))" using f0 (*‹U⇩f $$ (i, i + 1) * U⇩f $$ (i + 1, j) = complex_of_nat (f (i div 2)) * U⇩f $$ (i + 1, j)›*) f1 (*‹(U⇩f * U⇩f) $$ (i, j) = complex_of_nat (1 - f (i div 2)) * U⇩f $$ (i, j) + complex_of_nat (f (i div 2)) * U⇩f $$ (i + 1, j)›*) assms (*‹(i::nat) < dim_row U⇩f› ‹j < dim_col U⇩f› ‹even i›*) by simp then show "(U⇩f * U⇩f) $$ (i,j) = 1⇩m (dim_col U⇩f) $$ (i,j)" using assms(1,2) (*‹i < dim_row U⇩f› ‹j < dim_col U⇩f›*) a0 (*‹(j::nat) = (i::nat) + (1::nat) ∧ odd j›*) by auto next (*goals: 1. ‹⟦j = i - 1 ∧ even j ∧ 1 ≤ i; (U⇩f * U⇩f) $$ (i, j) = complex_of_nat (1 - f (i div 2)) * U⇩f $$ (i, j) + complex_of_nat (f (i div 2)) * U⇩f $$ (i + 1, j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)› 2. ‹⟦j ≠ i ∧ ¬ (j = i + 1 ∧ odd j) ∧ ¬ (j = i - 1 ∧ even j ∧ 1 ≤ i); (U⇩f * U⇩f) $$ (i, j) = complex_of_nat (1 - f (i div 2)) * U⇩f $$ (i, j) + complex_of_nat (f (i div 2)) * U⇩f $$ (i + 1, j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)›*) assume "(j=i-1 ∧ even j ∧ i≥1)" (*‹(j::nat) = (i::nat) - (1::nat) ∧ even j ∧ (1::nat) ≤ i›*) then show "(U⇩f * U⇩f) $$ (i,j) = 1⇩m (dim_col U⇩f) $$ (i,j)" using assms(3) (*‹even i›*) dvd_diffD1 (*‹⟦(?k::nat) dvd (?m::nat) - (?n::nat); ?k dvd ?m; ?n ≤ ?m⟧ ⟹ ?k dvd ?n›*) odd_one (*‹odd (1::?'a)›*) by blast next (*goal: ‹⟦(j::nat) ≠ (i::nat) ∧ ¬ (j = i + (1::nat) ∧ odd j) ∧ ¬ (j = i - (1::nat) ∧ even j ∧ (1::nat) ≤ i); (U⇩f * U⇩f) $$ (i, j) = complex_of_nat ((1::nat) - (f::nat ⇒ nat) (i div (2::nat))) * U⇩f $$ (i, j) + complex_of_nat (f (i div (2::nat))) * U⇩f $$ (i + (1::nat), j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)›*) assume a0: "(j≠i ∧ ¬(j=i+1 ∧ odd j) ∧ ¬ (j=i-1 ∧ even j ∧ i≥1))" (*‹(j::nat) ≠ (i::nat) ∧ ¬ (j = i + (1::nat) ∧ odd j) ∧ ¬ (j = i - (1::nat) ∧ even j ∧ (1::nat) ≤ i)›*) then have "U⇩f $$ (i,j) = 0" using assms(1,2) (*‹i < dim_row U⇩f› ‹j < dim_col U⇩f›*) by (metis index_transpose_mat( (*‹⟦?i < dim_col ?A; ?j < dim_row ?A⟧ ⟹ ?A⇧t $$ (?i, ?j) = ?A $$ (?j, ?i)›*) 1) jozsa_transform_coeff_is_zero (*‹?i < dim_row U⇩f ∧ ?j < dim_col U⇩f ⟹ ?i ≠ ?j ∧ ¬ (?i = ?j + 1 ∧ odd ?i) ∧ ¬ (?i = ?j - 1 ∧ even ?i ∧ 1 ≤ ?j) ⟶ U⇩f $$ (?i, ?j) = 0›*) jozsa_transform_dim (*‹dim_row U⇩f = 2 ^ (n + 1)› ‹dim_col U⇩f = 2 ^ (n + 1)›*) transpose_of_jozsa_transform (*‹U⇩f⇧t = U⇩f›*)) moreover have "U⇩f $$ (i+1,j) = 0" using assms (*‹i < dim_row U⇩f› ‹(j::nat) < dim_col U⇩f› ‹even i›*) a0 (*‹j ≠ i ∧ ¬ (j = i + 1 ∧ odd j) ∧ ¬ (j = i - 1 ∧ even j ∧ 1 ≤ i)›*) by auto ultimately have "(U⇩f * U⇩f) $$ (i,j) = (1-f(i div 2)) * 0 + f(i div 2) * 0" by (simp add: f1 (*‹(U⇩f * U⇩f) $$ (i::nat, j::nat) = complex_of_nat ((1::nat) - (f::nat ⇒ nat) (i div (2::nat))) * U⇩f $$ (i, j) + complex_of_nat (f (i div (2::nat))) * U⇩f $$ (i + (1::nat), j)›*)) then show "(U⇩f * U⇩f) $$ (i,j) = 1⇩m (dim_col U⇩f) $$ (i,j)" using a0 (*‹j ≠ i ∧ ¬ (j = i + 1 ∧ odd j) ∧ ¬ (j = i - 1 ∧ even j ∧ 1 ≤ i)›*) assms(1,2) (*‹i < dim_row U⇩f› ‹j < dim_col U⇩f›*) by (metis add.left_neutral (*‹0 + ?a = ?a›*) index_one_mat( (*‹⟦?i < ?n; ?j < ?n⟧ ⟹ 1⇩m ?n $$ (?i, ?j) = (if ?i = ?j then 1 else 0)›*) 1) jozsa_transform_dim (*‹dim_row U⇩f = 2 ^ (n + 1)› ‹dim_col U⇩f = 2 ^ (n + 1)›*) mult_0_right (*‹?m * 0 = 0›*) of_nat_0 (*‹of_nat 0 = 0›*)) qed qed lemma (in jozsa) jozsa_transform_is_unitary_index_odd: fixes i j:: nat assumes "i < dim_row U⇩f" and "j < dim_col U⇩f" and "odd i" shows "(U⇩f * U⇩f) $$ (i,j) = 1⇩m (dim_col U⇩f) $$ (i,j)" proof (-) (*goal: ‹(U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)›*) have f0: "i ≥ 1" using linorder_not_less (*‹(¬ (?x::?'a) < (?y::?'a)) = (?y ≤ ?x)›*) assms(3) (*‹odd i›*) by auto have "(U⇩f * U⇩f) $$ (i,j) = (∑k ∈ {i-1,i}. U⇩f $$ (i,k) * U⇩f $$ (k,j)) " using "U⇩f_mult_without_empty_summands_odd"[of i j U⇩f] (*‹⟦i < dim_row U⇩f; j < dim_col U⇩f; odd i; dim_col U⇩f = dim_row U⇩f⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = (∑k∈{i - 1, i}. U⇩f $$ (i, k) * U⇩f $$ (k, j))›*) assms (*‹i < dim_row U⇩f› ‹(j::nat) < dim_col U⇩f› ‹odd i›*) by simp moreover have "(∑k ∈ {i-1,i}. U⇩f $$ (i,k) * U⇩f $$ (k,j)) = U⇩f $$ (i,i-1) * U⇩f $$ (i-1,j) + U⇩f $$ (i,i) * U⇩f $$ (i,j)" using f0 (*‹1 ≤ i›*) by simp moreover have "U⇩f $$ (i,i) * U⇩f $$ (i,j) = (1-f(i div 2)) * U⇩f $$ (i,j)" using assms(1,2) (*‹i < dim_row U⇩f› ‹j < dim_col U⇩f›*) by simp moreover have f1: "U⇩f $$ (i,i-1) * U⇩f $$ (i-1,j) = f(i div 2) * U⇩f $$ (i-1,j)" using assms(1) (*‹i < dim_row U⇩f›*) assms(3) (*‹odd i›*) by simp ultimately have f2: "(U⇩f * U⇩f) $$ (i,j) = f(i div 2) * U⇩f $$ (i-1,j) + (1-f(i div 2)) * U⇩f $$ (i,j)" by simp then show "?thesis" (*goal: ‹(U⇩f * U⇩f) $$ (i::nat, j::nat) = 1⇩m (dim_col U⇩f) $$ (i, j)›*) proof (induct rule: disj_four_cases (*‹⟦?A ∨ ?B ∨ ?C ∨ ?D; ?A ⟹ ?P; ?B ⟹ ?P; ?C ⟹ ?P; ?D ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹?A2 ∨ ?B2 ∨ ?C2 ∨ ?D2› 2. ‹⟦?A2; (U⇩f * U⇩f) $$ (i, j) = complex_of_nat (f (i div 2)) * U⇩f $$ (i - 1, j) + complex_of_nat (1 - f (i div 2)) * U⇩f $$ (i, j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)› 3. ‹⟦?B2; (U⇩f * U⇩f) $$ (i, j) = complex_of_nat (f (i div 2)) * U⇩f $$ (i - 1, j) + complex_of_nat (1 - f (i div 2)) * U⇩f $$ (i, j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)› 4. ‹⟦?C2; (U⇩f * U⇩f) $$ (i, j) = complex_of_nat (f (i div 2)) * U⇩f $$ (i - 1, j) + complex_of_nat (1 - f (i div 2)) * U⇩f $$ (i, j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)› 5. ‹⟦?D2; (U⇩f * U⇩f) $$ (i, j) = complex_of_nat (f (i div 2)) * U⇩f $$ (i - 1, j) + complex_of_nat (1 - f (i div 2)) * U⇩f $$ (i, j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)›*) show "j=i ∨ (j=i+1 ∧ odd j) ∨ (j=i-1 ∧ even j ∧ i≥1) ∨ (j≠i ∧ ¬(j=i+1 ∧ odd j) ∧ ¬ (j=i-1 ∧ even j ∧ i≥1))" by linarith next (*goals: 1. ‹⟦j = i; (U⇩f * U⇩f) $$ (i, j) = complex_of_nat (f (i div 2)) * U⇩f $$ (i - 1, j) + complex_of_nat (1 - f (i div 2)) * U⇩f $$ (i, j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)› 2. ‹⟦j = i + 1 ∧ odd j; (U⇩f * U⇩f) $$ (i, j) = complex_of_nat (f (i div 2)) * U⇩f $$ (i - 1, j) + complex_of_nat (1 - f (i div 2)) * U⇩f $$ (i, j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)› 3. ‹⟦j = i - 1 ∧ even j ∧ 1 ≤ i; (U⇩f * U⇩f) $$ (i, j) = complex_of_nat (f (i div 2)) * U⇩f $$ (i - 1, j) + complex_of_nat (1 - f (i div 2)) * U⇩f $$ (i, j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)› 4. ‹⟦j ≠ i ∧ ¬ (j = i + 1 ∧ odd j) ∧ ¬ (j = i - 1 ∧ even j ∧ 1 ≤ i); (U⇩f * U⇩f) $$ (i, j) = complex_of_nat (f (i div 2)) * U⇩f $$ (i - 1, j) + complex_of_nat (1 - f (i div 2)) * U⇩f $$ (i, j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)›*) assume a0: "j=i" (*‹(j::nat) = (i::nat)›*) then have "U⇩f $$ (i,j) = (1-f(i div 2))" using assms(1,2) (*‹i < dim_row U⇩f› ‹j < dim_col U⇩f›*) by simp moreover have "U⇩f $$ (i-1,j) = f(i div 2)" using a0 (*‹j = i›*) assms (*‹(i::nat) < dim_row U⇩f› ‹j < dim_col U⇩f› ‹odd i›*) by (metis index_transpose_mat( (*‹⟦?i < dim_col ?A; ?j < dim_row ?A⟧ ⟹ ?A⇧t $$ (?i, ?j) = ?A $$ (?j, ?i)›*) 1) jozsa_transform_coeff( (*‹?i < dim_row U⇩f ∧ ?j < dim_col U⇩f ⟹ ?i = ?j + 1 ∧ odd ?i ⟶ U⇩f $$ (?i, ?j) = complex_of_nat (f (?i div 2))›*) 2) less_imp_diff_less (*‹?j < ?k ⟹ ?j - ?n < ?k›*) odd_two_times_div_two_nat (*‹odd ?n ⟹ 2 * (?n div 2) = ?n - 1›*) odd_two_times_div_two_succ (*‹odd ?a ⟹ 2 * (?a div 2) + 1 = ?a›*) transpose_of_jozsa_transform (*‹U⇩f⇧t = U⇩f›*)) ultimately have "(U⇩f * U⇩f) $$ (i,j) = f(i div 2) * f(i div 2) + (1-f(i div 2)) * (1-f(i div 2))" using f2 (*‹(U⇩f * U⇩f) $$ (i, j) = complex_of_nat (f (i div 2)) * U⇩f $$ (i - 1, j) + complex_of_nat (1 - f (i div 2)) * U⇩f $$ (i, j)›*) by simp moreover have "f(i div 2) * f(i div 2) + (1-f(i div 2)) * (1-f(i div 2)) = 1" using f_values (*‹∀x∈{i. i < 2 ^ n}. f x = 0 ∨ f x = 1›*) assms(1) (*‹i < dim_row U⇩f›*) by (metis (no_types, lifting) Nat.minus_nat.diff_0 (*‹?m - 0 = ?m›*) diff_add_0 (*‹?n - (?n + ?m) = 0›*) diff_add_inverse (*‹?n + ?m - ?n = ?m›*) jozsa_transform_dim( (*‹dim_row U⇩f = 2 ^ (n + 1)›*) 1) less_power_add_imp_div_less (*‹?i < 2 ^ (?m + ?n) ⟹ ?i div 2 ^ ?n < 2 ^ ?m›*) mem_Collect_eq (*‹(?a ∈ Collect ?P) = ?P ?a›*) mult_eq_if (*‹?m * ?n = (if ?m = 0 then 0 else ?n + (?m - 1) * ?n)›*) one_power2 (*‹1² = 1›*) power2_eq_square (*‹?a² = ?a * ?a›*) power_one_right (*‹?a ^ 1 = ?a›*)) ultimately show "(U⇩f * U⇩f) $$ (i,j) = 1⇩m (dim_col U⇩f) $$ (i,j)" by (metis assms( (*‹j < dim_col U⇩f›*) 2) a0 (*‹j = i›*) index_one_mat( (*‹⟦?i < ?n; ?j < ?n⟧ ⟹ 1⇩m ?n $$ (?i, ?j) = (if ?i = ?j then 1 else 0)›*) 1) of_nat_1 (*‹of_nat 1 = 1›*)) next (*goals: 1. ‹⟦(j::nat) = (i::nat) + (1::nat) ∧ odd j; (U⇩f * U⇩f) $$ (i, j) = complex_of_nat ((f::nat ⇒ nat) (i div (2::nat))) * U⇩f $$ (i - (1::nat), j) + complex_of_nat ((1::nat) - f (i div (2::nat))) * U⇩f $$ (i, j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)› 2. ‹⟦(j::nat) = (i::nat) - (1::nat) ∧ even j ∧ (1::nat) ≤ i; (U⇩f * U⇩f) $$ (i, j) = complex_of_nat ((f::nat ⇒ nat) (i div (2::nat))) * U⇩f $$ (i - (1::nat), j) + complex_of_nat ((1::nat) - f (i div (2::nat))) * U⇩f $$ (i, j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)› 3. ‹⟦(j::nat) ≠ (i::nat) ∧ ¬ (j = i + (1::nat) ∧ odd j) ∧ ¬ (j = i - (1::nat) ∧ even j ∧ (1::nat) ≤ i); (U⇩f * U⇩f) $$ (i, j) = complex_of_nat ((f::nat ⇒ nat) (i div (2::nat))) * U⇩f $$ (i - (1::nat), j) + complex_of_nat ((1::nat) - f (i div (2::nat))) * U⇩f $$ (i, j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)›*) assume a0: "(j=i+1 ∧ odd j)" (*‹(j::nat) = (i::nat) + (1::nat) ∧ odd j›*) then show "(U⇩f * U⇩f) $$ (i,j) = 1⇩m (dim_col U⇩f) $$ (i,j)" using assms(3) (*‹odd i›*) dvd_diffD1 (*‹⟦?k dvd ?m - ?n; ?k dvd ?m; ?n ≤ ?m⟧ ⟹ ?k dvd ?n›*) odd_one (*‹odd 1›*) even_plus_one_iff (*‹even (?a + 1) = odd ?a›*) by blast next (*goals: 1. ‹⟦(j::nat) = (i::nat) - (1::nat) ∧ even j ∧ (1::nat) ≤ i; (U⇩f * U⇩f) $$ (i, j) = complex_of_nat ((f::nat ⇒ nat) (i div (2::nat))) * U⇩f $$ (i - (1::nat), j) + complex_of_nat ((1::nat) - f (i div (2::nat))) * U⇩f $$ (i, j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)› 2. ‹⟦(j::nat) ≠ (i::nat) ∧ ¬ (j = i + (1::nat) ∧ odd j) ∧ ¬ (j = i - (1::nat) ∧ even j ∧ (1::nat) ≤ i); (U⇩f * U⇩f) $$ (i, j) = complex_of_nat ((f::nat ⇒ nat) (i div (2::nat))) * U⇩f $$ (i - (1::nat), j) + complex_of_nat ((1::nat) - f (i div (2::nat))) * U⇩f $$ (i, j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)›*) assume a0: "(j=i-1 ∧ even j ∧ i≥1)" (*‹(j::nat) = (i::nat) - (1::nat) ∧ even j ∧ (1::nat) ≤ i›*) then have "(U⇩f * U⇩f) $$ (i,j) = f(i div 2) * (1-f(i div 2)) + (1-f(i div 2)) * f(i div 2)" using f0 (*‹1 ≤ i›*) f1 (*‹U⇩f $$ (i, i - 1) * U⇩f $$ (i - 1, j) = complex_of_nat (f (i div 2)) * U⇩f $$ (i - 1, j)›*) f2 (*‹(U⇩f * U⇩f) $$ (i, j) = complex_of_nat (f (i div 2)) * U⇩f $$ (i - 1, j) + complex_of_nat (1 - f (i div 2)) * U⇩f $$ (i, j)›*) assms (*‹i < dim_row U⇩f› ‹(j::nat) < dim_col U⇩f› ‹odd i›*) by (metis jozsa_transform_coeff( (*‹(?i::nat) < dim_row U⇩f ∧ (?j::nat) < dim_col U⇩f ⟹ ?i = ?j ⟶ U⇩f $$ (?i, ?j) = complex_of_nat ((1::nat) - (f::nat ⇒ nat) (?i div (2::nat)))›*) 1) Groups.ab_semigroup_mult_class.mult.commute (*‹(?a::?'a::ab_semigroup_mult) * (?b::?'a::ab_semigroup_mult) = ?b * ?a›*) even_succ_div_two (*‹even (?a::?'a::linordered_euclidean_semiring) ⟹ (?a + (1::?'a::linordered_euclidean_semiring)) div (2::?'a::linordered_euclidean_semiring) = ?a div (2::?'a::linordered_euclidean_semiring)›*) f2 (*‹(U⇩f * U⇩f) $$ (i::nat, j::nat) = complex_of_nat ((f::nat ⇒ nat) (i div (2::nat))) * U⇩f $$ (i - (1::nat), j) + complex_of_nat ((1::nat) - f (i div (2::nat))) * U⇩f $$ (i, j)›*) jozsa_transform_dim (*‹dim_row U⇩f = (2::nat) ^ ((n::nat) + (1::nat))› ‹dim_col U⇩f = (2::nat) ^ ((n::nat) + (1::nat))›*) odd_two_times_div_two_nat (*‹odd (?n::nat) ⟹ (2::nat) * (?n div (2::nat)) = ?n - (1::nat)›*) odd_two_times_div_two_succ (*‹odd (?a::?'a::linordered_euclidean_semiring) ⟹ (2::?'a::linordered_euclidean_semiring) * (?a div (2::?'a::linordered_euclidean_semiring)) + (1::?'a::linordered_euclidean_semiring) = ?a›*) of_nat_add (*‹of_nat ((?m::nat) + (?n::nat)) = of_nat ?m + of_nat ?n›*) of_nat_mult (*‹of_nat ((?m::nat) * (?n::nat)) = of_nat ?m * of_nat ?n›*)) then show "(U⇩f * U⇩f) $$ (i,j) = 1⇩m (dim_col U⇩f) $$ (i,j)" using assms(1) (*‹i < dim_row U⇩f›*) a0 (*‹(j::nat) = (i::nat) - (1::nat) ∧ even j ∧ (1::nat) ≤ i›*) by auto next (*goal: ‹⟦j ≠ i ∧ ¬ (j = i + 1 ∧ odd j) ∧ ¬ (j = i - 1 ∧ even j ∧ 1 ≤ i); (U⇩f * U⇩f) $$ (i, j) = complex_of_nat (f (i div 2)) * U⇩f $$ (i - 1, j) + complex_of_nat (1 - f (i div 2)) * U⇩f $$ (i, j)⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)›*) assume a0: "j≠i ∧ ¬(j=i+1 ∧ odd j) ∧ ¬ (j=i-1 ∧ even j ∧ i≥1)" (*‹(j::nat) ≠ (i::nat) ∧ ¬ (j = i + (1::nat) ∧ odd j) ∧ ¬ (j = i - (1::nat) ∧ even j ∧ (1::nat) ≤ i)›*) then have "U⇩f $$ (i,j) = 0" by (metis assms( (*‹(i::nat) < dim_row U⇩f› ‹(j::nat) < dim_col U⇩f›*) 1,2) index_transpose_mat( (*‹⟦(?i::nat) < dim_col (?A::?'a Matrix.mat); (?j::nat) < dim_row ?A⟧ ⟹ ?A⇧t $$ (?i, ?j) = ?A $$ (?j, ?i)›*) 1) jozsa_transform_coeff_is_zero (*‹(?i::nat) < dim_row U⇩f ∧ (?j::nat) < dim_col U⇩f ⟹ ?i ≠ ?j ∧ ¬ (?i = ?j + (1::nat) ∧ odd ?i) ∧ ¬ (?i = ?j - (1::nat) ∧ even ?i ∧ (1::nat) ≤ ?j) ⟶ U⇩f $$ (?i, ?j) = (0::complex)›*) jozsa_transform_dim (*‹dim_row U⇩f = (2::nat) ^ ((n::nat) + (1::nat))› ‹dim_col U⇩f = (2::nat) ^ ((n::nat) + (1::nat))›*) transpose_of_jozsa_transform (*‹U⇩f⇧t = U⇩f›*)) moreover have "U⇩f $$ (i-1,j) = 0" using assms (*‹i < dim_row U⇩f› ‹j < dim_col U⇩f› ‹odd (i::nat)›*) a0 (*‹j ≠ i ∧ ¬ (j = i + 1 ∧ odd j) ∧ ¬ (j = i - 1 ∧ even j ∧ 1 ≤ i)›*) f0 (*‹(1::nat) ≤ (i::nat)›*) apply auto (*goal: ‹U⇩f $$ (i - 1, j) = 0›*) by (smt (verit) One_nat_def (*‹1 = Suc 0›*) Suc_n_not_le_n (*‹¬ Suc ?n ≤ ?n›*) add_diff_inverse_nat (*‹¬ ?m < ?n ⟹ ?n + (?m - ?n) = ?m›*) assms( (*‹i < dim_row U⇩f›*) 1) assms( (*‹j < dim_col U⇩f›*) 2) diff_Suc_less (*‹0 < ?n ⟹ ?n - Suc ?i < ?n›*) even_add (*‹even (?a + ?b) = (even ?a = even ?b)›*) jozsa_transform_coeff_is_zero (*‹?i < dim_row U⇩f ∧ ?j < dim_col U⇩f ⟹ ?i ≠ ?j ∧ ¬ (?i = ?j + 1 ∧ odd ?i) ∧ ¬ (?i = ?j - 1 ∧ even ?i ∧ 1 ≤ ?j) ⟶ U⇩f $$ (?i, ?j) = 0›*) jozsa_axioms (*‹jozsa f n›*) less_imp_le (*‹?x < ?y ⟹ ?x ≤ ?y›*) less_le_trans (*‹⟦?x < ?y; ?y ≤ ?z⟧ ⟹ ?x < ?z›*) less_one (*‹(?n < 1) = (?n = 0)›*) odd_one (*‹odd 1›*)) ultimately have "(U⇩f * U⇩f) $$ (i,j) = (1-f(i div 2)) * 0 + f(i div 2) * 0" using f2 (*‹(U⇩f * U⇩f) $$ (i, j) = complex_of_nat (f (i div 2)) * U⇩f $$ (i - 1, j) + complex_of_nat (1 - f (i div 2)) * U⇩f $$ (i, j)›*) by simp then show "(U⇩f * U⇩f) $$ (i,j) = 1⇩m (dim_col U⇩f) $$ (i,j)" using a0 (*‹j ≠ i ∧ ¬ (j = i + 1 ∧ odd j) ∧ ¬ (j = i - 1 ∧ even j ∧ 1 ≤ i)›*) assms (*‹i < dim_row U⇩f› ‹(j::nat) < dim_col U⇩f› ‹odd i›*) by (metis add.left_neutral (*‹0 + ?a = ?a›*) index_one_mat( (*‹⟦?i < ?n; ?j < ?n⟧ ⟹ 1⇩m ?n $$ (?i, ?j) = (if ?i = ?j then 1 else 0)›*) 1) jozsa_transform_dim (*‹dim_row U⇩f = 2 ^ (n + 1)› ‹dim_col U⇩f = 2 ^ (n + 1)›*) mult_0_right (*‹?m * 0 = 0›*) of_nat_0 (*‹of_nat 0 = 0›*)) qed qed lemma (in jozsa) jozsa_transform_is_gate: shows "gate (n+1) U⇩f" proof (standard) (*goals: 1. ‹dim_row U⇩f = 2 ^ (n + 1)› 2. ‹square_mat U⇩f› 3. ‹unitary U⇩f›*) show "dim_row U⇩f = 2^(n+1)" by simp next (*goals: 1. ‹square_mat U⇩f› 2. ‹unitary U⇩f›*) show "square_mat U⇩f" by simp next (*goal: ‹unitary U⇩f›*) show "unitary U⇩f" proof (-) (*goal: ‹unitary U⇩f›*) have "U⇩f * U⇩f = 1⇩m (dim_col U⇩f)" proof (standard) (*goals: 1. ‹⋀i j. ⟦i < dim_row (1⇩m (dim_col U⇩f)); j < dim_col (1⇩m (dim_col U⇩f))⟧ ⟹ (U⇩f * U⇩f) $$ (i, j) = 1⇩m (dim_col U⇩f) $$ (i, j)› 2. ‹dim_row (U⇩f * U⇩f) = dim_row (1⇩m (dim_col U⇩f))› 3. ‹dim_col (U⇩f * U⇩f) = dim_col (1⇩m (dim_col U⇩f))›*) show "dim_row (U⇩f * U⇩f) = dim_row (1⇩m (dim_col U⇩f))" by simp show "dim_col (U⇩f * U⇩f) = dim_col (1⇩m (dim_col U⇩f))" by simp fix i :: nat and j :: nat assume "i < dim_row (1⇩m (dim_col U⇩f))" and "j < dim_col (1⇩m (dim_col U⇩f))" (*‹(i::nat) < dim_row (1⇩m (dim_col U⇩f))› ‹(j::nat) < dim_col (1⇩m (dim_col U⇩f))›*) then have "i < dim_row U⇩f" and "j < dim_col U⇩f" apply - (*goals: 1. ‹⟦i < dim_row (1⇩m (dim_col U⇩f)); j < dim_col (1⇩m (dim_col U⇩f))⟧ ⟹ i < dim_row U⇩f› 2. ‹⟦i < dim_row (1⇩m (dim_col U⇩f)); j < dim_col (1⇩m (dim_col U⇩f))⟧ ⟹ j < dim_col U⇩f› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . then show "(U⇩f * U⇩f) $$ (i,j) = 1⇩m (dim_col U⇩f) $$ (i,j)" using jozsa_transform_is_unitary_index_odd (*‹⟦(?i::nat) < dim_row U⇩f; (?j::nat) < dim_col U⇩f; odd ?i⟧ ⟹ (U⇩f * U⇩f) $$ (?i, ?j) = 1⇩m (dim_col U⇩f) $$ (?i, ?j)›*) jozsa_transform_is_unitary_index_even (*‹⟦?i < dim_row U⇩f; ?j < dim_col U⇩f; even ?i⟧ ⟹ (U⇩f * U⇩f) $$ (?i, ?j) = 1⇩m (dim_col U⇩f) $$ (?i, ?j)›*) by blast qed thus "?thesis" (*goal: ‹unitary U⇩f›*) by (simp add: adjoint_of_jozsa_transform (*‹U⇩f⇧† = U⇩f›*) unitary_def (*‹unitary (?M::complex Matrix.mat) ≡ ?M⇧† * ?M = 1⇩m (dim_col ?M) ∧ ?M * ?M⇧† = 1⇩m (dim_row ?M)›*)) qed qed text ‹N-fold application of the tensor product› fun iter_tensor:: "complex Matrix.mat ⇒ nat ⇒ complex Matrix.mat" ("_ ⊗⇗_⇖" 75) where "A ⊗⇗(Suc 0)⇖ = A" | "A ⊗⇗(Suc k)⇖ = A ⨂ (A ⊗⇗k⇖)" lemma one_tensor_is_id [simp]: fixes A shows "A ⊗⇗1⇖ = A" using one_mat_def (*‹1⇩m (?n::nat) ≡ Matrix.mat ?n ?n (λ(i::nat, j::nat). if i = j then 1::?'a else (0::?'a))›*) by simp lemma iter_tensor_suc: fixes n assumes "n ≥ 1" shows " A ⊗⇗(Suc n)⇖ = A ⨂ (A ⊗⇗n⇖)" using assms (*‹1 ≤ n›*) by (metis Deutsch_Jozsa.iter_tensor.simps( (*‹?A ⊗⇗Suc (Suc ?v)⇖ = ?A ⨂ ?A ⊗⇗Suc ?v⇖›*) 2) One_nat_def (*‹1 = Suc 0›*) Suc_le_D (*‹Suc ?n ≤ ?m' ⟹ ∃m. ?m' = Suc m›*)) lemma dim_row_of_iter_tensor [simp]: fixes A n assumes "n ≥ 1" shows "dim_row(A ⊗⇗n⇖) = (dim_row A)^n" using assms (*‹1 ≤ n›*) proof (rule nat_induct_at_least (*‹⟦?m ≤ ?n; ?P ?m; ⋀n. ⟦?m ≤ n; ?P n⟧ ⟹ ?P (Suc n)⟧ ⟹ ?P ?n›*)) (*goals: 1. ‹dim_row (A ⊗⇗1⇖) = dim_row A ^ 1› 2. ‹⋀n. ⟦1 ≤ n; dim_row (A ⊗⇗n⇖) = dim_row A ^ n⟧ ⟹ dim_row (A ⊗⇗Suc n⇖) = dim_row A ^ Suc n›*) show "dim_row (A ⊗⇗1⇖) = (dim_row A)^1" using one_tensor_is_id (*‹?A ⊗⇗1⇖ = ?A›*) by simp fix n :: nat assume "n ≥ 1" and "dim_row (A ⊗⇗n⇖) = (dim_row A)^n" (*‹(1::nat) ≤ (n::nat)› ‹dim_row (A::complex Matrix.mat ⊗⇗n::nat⇖) = dim_row A ^ n›*) then show "dim_row (A ⊗⇗Suc n⇖) = (dim_row A)^Suc n" using iter_tensor_suc (*‹1 ≤ ?n ⟹ ?A ⊗⇗Suc ?n⇖ = ?A ⨂ ?A ⊗⇗?n⇖›*) assms (*‹1 ≤ n›*) dim_row_tensor_mat (*‹dim_row (?A ⨂ ?B) = dim_row ?A * dim_row ?B›*) by simp qed lemma dim_col_of_iter_tensor [simp]: fixes A n assumes "n ≥ 1" shows "dim_col(A ⊗⇗n⇖) = (dim_col A)^n" using assms (*‹1 ≤ n›*) proof (rule nat_induct_at_least (*‹⟦?m ≤ ?n; ?P ?m; ⋀n. ⟦?m ≤ n; ?P n⟧ ⟹ ?P (Suc n)⟧ ⟹ ?P ?n›*)) (*goals: 1. ‹dim_col (A ⊗⇗1⇖) = dim_col A ^ 1› 2. ‹⋀n. ⟦1 ≤ n; dim_col (A ⊗⇗n⇖) = dim_col A ^ n⟧ ⟹ dim_col (A ⊗⇗Suc n⇖) = dim_col A ^ Suc n›*) show "dim_col (A ⊗⇗1⇖) = (dim_col A)^1" using one_tensor_is_id (*‹?A ⊗⇗1⇖ = ?A›*) by simp fix n :: nat assume "n ≥ 1" and "dim_col (A ⊗⇗n⇖) = (dim_col A)^n" (*‹(1::nat) ≤ (n::nat)› ‹dim_col (A::complex Matrix.mat ⊗⇗n::nat⇖) = dim_col A ^ n›*) then show "dim_col (A ⊗⇗Suc n⇖) = (dim_col A)^Suc n" using iter_tensor_suc (*‹1 ≤ ?n ⟹ ?A ⊗⇗Suc ?n⇖ = ?A ⨂ ?A ⊗⇗?n⇖›*) assms (*‹(1::nat) ≤ (n::nat)›*) dim_col_tensor_mat (*‹dim_col (?A ⨂ ?B) = dim_col ?A * dim_col ?B›*) by simp qed lemma iter_tensor_values: fixes A n i j assumes "n ≥ 1" and "i < dim_row (A ⨂ (A ⊗⇗n⇖))" and "j < dim_col (A ⨂ (A ⊗⇗n⇖))" shows "(A ⊗⇗(Suc n)⇖) $$ (i,j) = (A ⨂ (A ⊗⇗n⇖)) $$ (i,j)" using assms (*‹1 ≤ n› ‹(i::nat) < dim_row ((A::complex Matrix.mat) ⨂ A ⊗⇗n::nat⇖)› ‹(j::nat) < dim_col ((A::complex Matrix.mat) ⨂ A ⊗⇗n::nat⇖)›*) by (metis One_nat_def (*‹1 = Suc 0›*) le_0_eq (*‹(?n ≤ 0) = (?n = 0)›*) not0_implies_Suc (*‹?n ≠ 0 ⟹ ∃m. ?n = Suc m›*) iter_tensor.simps( (*‹?A ⊗⇗Suc (Suc ?v)⇖ = ?A ⨂ ?A ⊗⇗Suc ?v⇖›*) 2)) lemma iter_tensor_mult_distr: assumes "n ≥ 1" and "dim_col A = dim_row B" and "dim_col A > 0" and "dim_col B > 0" shows "(A ⊗⇗(Suc n)⇖) * (B ⊗⇗(Suc n)⇖) = (A * B) ⨂ ((A ⊗⇗n⇖) * (B ⊗⇗n⇖))" proof (-) (*goal: ‹A::complex Matrix.mat ⊗⇗Suc (n::nat)⇖ * B::complex Matrix.mat ⊗⇗Suc n⇖ = A * B ⨂ A ⊗⇗n⇖ * B ⊗⇗n⇖›*) have "(A ⊗⇗(Suc n)⇖) * (B ⊗⇗(Suc n)⇖) = (A ⨂ (A ⊗⇗n⇖)) * (B ⨂ (B ⊗⇗n⇖))" using Suc_le_D (*‹Suc ?n ≤ ?m' ⟹ ∃m. ?m' = Suc m›*) assms(1) (*‹1 ≤ n›*) by fastforce then show "?thesis" (*goal: ‹A::complex Matrix.mat ⊗⇗Suc (n::nat)⇖ * B::complex Matrix.mat ⊗⇗Suc n⇖ = A * B ⨂ A ⊗⇗n⇖ * B ⊗⇗n⇖›*) using mult_distr_tensor[of "A" "B" "(iter_tensor A n)" "(iter_tensor B n)"] (*‹⟦dim_col A = dim_row B; dim_col (A ⊗⇗n⇖) = dim_row (B ⊗⇗n⇖); 0 < dim_col A; 0 < dim_col B; 0 < dim_col (A ⊗⇗n⇖); 0 < dim_col (B ⊗⇗n⇖)⟧ ⟹ A * B ⨂ A ⊗⇗n⇖ * B ⊗⇗n⇖ = (A ⨂ A ⊗⇗n⇖) * (B ⨂ B ⊗⇗n⇖)›*) assms (*‹1 ≤ n› ‹dim_col A = dim_row B› ‹0 < dim_col A› ‹0 < dim_col B›*) by simp qed lemma index_tensor_mat_with_vec2_row_cond: fixes A B:: "complex Matrix.mat" and i:: "nat" assumes "i < 2 * (dim_row B)" and "i ≥ dim_row B" and "dim_col B > 0" and "dim_row A = 2" and "dim_col A = 1" shows "(A ⨂ B) $$ (i,0) = (A $$ (1,0)) * (B $$ (i-dim_row B,0))" proof (-) (*goal: ‹(A ⨂ B) $$ (i, 0) = A $$ (1, 0) * B $$ (i - dim_row B, 0)›*) have "(A ⨂ B) $$ (i,0) = A $$ (i div (dim_row B),0) * B $$ (i mod (dim_row B),0)" using assms (*‹i < 2 * dim_row B› ‹dim_row B ≤ i› ‹0 < dim_col B› ‹dim_row (A::complex Matrix.mat) = (2::nat)› ‹dim_col (A::complex Matrix.mat) = (1::nat)›*) index_tensor_mat[of A "dim_row A" "dim_col A" B "dim_row B" "dim_col B" i 0] (*‹⟦dim_row A = dim_row A; dim_col A = dim_col A; dim_row B = dim_row B; dim_col B = dim_col B; i < dim_row A * dim_row B; 0 < dim_col A * dim_col B; 0 < dim_col A; 0 < dim_col B⟧ ⟹ (A ⨂ B) $$ (i, 0) = A $$ (i div dim_row B, 0 div dim_col B) * B $$ (i mod dim_row B, 0 mod dim_col B)›*) by simp moreover have "i div (dim_row B) = 1" using assms(1,2,4) (*‹i < 2 * dim_row B› ‹dim_row B ≤ i› ‹dim_row A = 2›*) by simp then have "i mod (dim_row B) = i - (dim_row B)" by (simp add: modulo_nat_def (*‹?m mod ?n = ?m - ?m div ?n * ?n›*)) ultimately show "(A ⨂ B) $$ (i,0) = (A $$ (1,0)) * (B $$ (i-dim_row B,0))" by (simp add: ‹i div dim_row B = 1›) qed lemma iter_tensor_of_gate_is_gate: fixes A:: "complex Matrix.mat" and n m:: "nat" assumes "gate m A" and "n ≥ 1" shows "gate (m*n) (A ⊗⇗n⇖)" using assms(2) (*‹1 ≤ n›*) proof (rule nat_induct_at_least (*‹⟦?m ≤ ?n; ?P ?m; ⋀n. ⟦?m ≤ n; ?P n⟧ ⟹ ?P (Suc n)⟧ ⟹ ?P ?n›*)) (*goals: 1. ‹gate (m * 1) (A ⊗⇗1⇖)› 2. ‹⋀n. ⟦1 ≤ n; gate (m * n) (A ⊗⇗n⇖)⟧ ⟹ gate (m * Suc n) (A ⊗⇗Suc n⇖)›*) show "gate (m * 1) (A ⊗⇗1⇖)" using assms(1) (*‹gate (m::nat) (A::complex Matrix.mat)›*) by simp fix n :: nat assume "n ≥ 1" and IH: "gate (m * n) (A ⊗⇗n⇖)" (*‹(1::nat) ≤ (n::nat)› ‹gate ((m::nat) * (n::nat)) (A::complex Matrix.mat ⊗⇗n⇖)›*) then have "A ⊗⇗(Suc n)⇖ = A ⨂ (A ⊗⇗n⇖)" by (simp add: iter_tensor_suc (*‹(1::nat) ≤ (?n::nat) ⟹ ?A::complex Matrix.mat ⊗⇗Suc ?n⇖ = ?A ⨂ ?A ⊗⇗?n⇖›*)) moreover have "gate (m*n + m) (A ⊗⇗(Suc n)⇖)" using tensor_gate (*‹⟦gate ?m ?G1.0; gate ?n ?G2.0⟧ ⟹ gate (?m + ?n) (?G1.0 ⨂ ?G2.0)›*) assms(1) (*‹gate m A›*) by (simp add: IH (*‹gate ((m::nat) * (n::nat)) (A::complex Matrix.mat ⊗⇗n⇖)›*) add.commute (*‹(?a::?'a) + (?b::?'a) = ?b + ?a›*) calculation( (*‹A::complex Matrix.mat ⊗⇗Suc (n::nat)⇖ = A ⨂ A ⊗⇗n⇖›*) 1)) then show "gate (m*(Suc n)) (A ⊗⇗(Suc n)⇖)" by (simp add: add.commute (*‹?a + ?b = ?b + ?a›*)) qed lemma iter_tensor_of_state_is_state: fixes A:: "complex Matrix.mat" and n m:: "nat" assumes "state m A" and "n≥1" shows "state (m*n) (A ⊗⇗n⇖)" using assms(2) (*‹1 ≤ n›*) proof (rule nat_induct_at_least (*‹⟦?m ≤ ?n; ?P ?m; ⋀n. ⟦?m ≤ n; ?P n⟧ ⟹ ?P (Suc n)⟧ ⟹ ?P ?n›*)) (*goals: 1. ‹state (m * 1) (A ⊗⇗1⇖)› 2. ‹⋀n. ⟦1 ≤ n; state (m * n) (A ⊗⇗n⇖)⟧ ⟹ state (m * Suc n) (A ⊗⇗Suc n⇖)›*) show "state (m * 1) (A ⊗⇗1⇖)" using one_tensor_is_id (*‹?A::complex Matrix.mat ⊗⇗1::nat⇖ = ?A›*) assms(1) (*‹state m A›*) by simp fix n :: nat assume "n ≥ 1" and IH: "state (m * n) (A ⊗⇗n⇖)" (*‹(1::nat) ≤ (n::nat)› ‹state ((m::nat) * (n::nat)) (A::complex Matrix.mat ⊗⇗n⇖)›*) then have "A ⊗⇗(Suc n)⇖ = A ⨂ (A ⊗⇗n⇖)" by (simp add: iter_tensor_suc (*‹1 ≤ ?n ⟹ ?A ⊗⇗Suc ?n⇖ = ?A ⨂ ?A ⊗⇗?n⇖›*)) moreover have "state (m*n + m) (A ⊗⇗(Suc n)⇖)" using tensor_gate (*‹⟦gate ?m ?G1.0; gate ?n ?G2.0⟧ ⟹ gate (?m + ?n) (?G1.0 ⨂ ?G2.0)›*) assms(1) (*‹state m A›*) by (simp add: IH (*‹state (m * n) (A ⊗⇗n⇖)›*) add.commute (*‹?a + ?b = ?b + ?a›*) calculation (*‹A ⊗⇗Suc n⇖ = A ⨂ A ⊗⇗n⇖›*)) then show "state (m*(Suc n)) (A ⊗⇗(Suc n)⇖)" by (simp add: add.commute (*‹?a + ?b = ?b + ?a›*)) qed text ‹ We prepare n+1 qubits. The first n qubits in the state $|0\rangle$, the last one in the state $|1\rangle$. › abbreviation ψ₁₀:: "nat ⇒ complex Matrix.mat" where "ψ₁₀ n ≡ Matrix.mat (2^n) 1 (λ(i,j). 1/(sqrt 2)^n)" lemma ψ₁₀_values: fixes i j n assumes "i < dim_row (ψ₁₀ n)" and "j < dim_col (ψ₁₀ n)" shows "(ψ₁₀ n) $$ (i,j) = 1/(sqrt 2)^n" using assms (*‹i < dim_row (Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n)))› ‹j < dim_col (Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n)))›*) case_prod_conv (*‹(case (?a::?'b::type, ?b::?'c::type) of (c::?'b::type, d::?'c::type) ⇒ (?f::?'b::type ⇒ ?'c::type ⇒ ?'a::type) c d) = ?f ?a ?b›*) by simp text ‹$H^{\otimes n}$ is applied to $|0\rangle^{\otimes n}$.› lemma H_on_ket_zero: shows "(H * |zero⟩) = ψ₁₀ 1" proof (standard) (*goals: 1. ‹⋀(i::nat) j::nat. ⟦i < dim_row (Matrix.mat ((2::nat) ^ (1::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ (1::nat)))); j < dim_col (Matrix.mat ((2::nat) ^ (1::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ (1::nat))))⟧ ⟹ (H * |Deutsch.zero⟩) $$ (i, j) = Matrix.mat ((2::nat) ^ (1::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ (1::nat))) $$ (i, j)› 2. ‹dim_row (H * |Deutsch.zero⟩) = dim_row (Matrix.mat ((2::nat) ^ (1::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ (1::nat))))› 3. ‹dim_col (H * |Deutsch.zero⟩) = dim_col (Matrix.mat ((2::nat) ^ (1::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ (1::nat))))›*) fix i :: nat and j :: nat assume "i < dim_row (ψ₁₀ 1)" and "j < dim_col (ψ₁₀ 1)" (*‹(i::nat) < dim_row (Matrix.mat ((2::nat) ^ (1::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ (1::nat))))› ‹(j::nat) < dim_col (Matrix.mat ((2::nat) ^ (1::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ (1::nat))))›*) then have f1: "i ∈ {0,1} ∧ j = 0" by (simp add: less_2_cases (*‹?n < 2 ⟹ ?n = 0 ∨ ?n = Suc 0›*)) then show "(H * |zero⟩) $$ (i,j) = (ψ₁₀ 1) $$ (i,j)" by (auto simp add: times_mat_def (*‹(?A::?'a Matrix.mat) * (?B::?'a Matrix.mat) ≡ Matrix.mat (dim_row ?A) (dim_col ?B) (λ(i::nat, j::nat). Matrix.row ?A i ∙ Matrix.col ?B j)›*) scalar_prod_def (*‹(?v::?'a Matrix.vec) ∙ (?w::?'a Matrix.vec) ≡ ∑i::nat = 0::nat..<dim_vec ?w. ?v $ i * ?w $ i›*) H_def (*‹H ≡ complex_of_real ((1::real) / sqrt (2::real)) ⋅⇩m Matrix.mat (2::nat) (2::nat) (λ(i::nat, j::nat). if i ≠ j then 1::complex else if i = (0::nat) then 1::complex else - (1::complex))›*) ket_vec_def (*‹|?v::complex Matrix.vec⟩ ≡ Matrix.mat (dim_vec ?v) (1::nat) (λ(i::nat, j::nat). ?v $ i)›*)) next (*goals: 1. ‹dim_row (H * |Deutsch.zero⟩) = dim_row (Matrix.mat (2 ^ 1) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ 1)))› 2. ‹dim_col (H * |Deutsch.zero⟩) = dim_col (Matrix.mat (2 ^ 1) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ 1)))›*) show "dim_row (H * |zero⟩) = dim_row (ψ₁₀ 1)" by (simp add: H_def (*‹H ≡ complex_of_real (1 / sqrt 2) ⋅⇩m Matrix.mat 2 2 (λ(i, j). if i ≠ j then 1 else if i = 0 then 1 else - 1)›*)) show "dim_col (H * |zero⟩) = dim_col (ψ₁₀ 1)" using H_def (*‹H ≡ complex_of_real (1 / sqrt 2) ⋅⇩m Matrix.mat 2 2 (λ(i, j). if i ≠ j then 1 else if i = 0 then 1 else - 1)›*) by (simp add: ket_vec_def (*‹|?v⟩ ≡ Matrix.mat (dim_vec ?v) 1 (λ(i, j). ?v $ i)›*)) qed lemma ψ₁₀_tensor: assumes "n ≥ 1" shows "(ψ₁₀ 1) ⨂ (ψ₁₀ n) = (ψ₁₀ (Suc n))" proof (standard) (*goals: 1. ‹⋀i j. ⟦i < dim_row (Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n))); j < dim_col (Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n)))⟧ ⟹ (Matrix.mat (2 ^ 1) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ 1)) ⨂ Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n))) $$ (i, j) = Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n)) $$ (i, j)› 2. ‹dim_row (Matrix.mat (2 ^ 1) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ 1)) ⨂ Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n))) = dim_row (Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n)))› 3. ‹dim_col (Matrix.mat (2 ^ 1) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ 1)) ⨂ Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n))) = dim_col (Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n)))›*) have "dim_row (ψ₁₀ 1) * dim_row (ψ₁₀ n) = 2^(Suc n)" by simp then show "dim_row ((ψ₁₀ 1) ⨂ (ψ₁₀ n)) = dim_row (ψ₁₀ (Suc n))" by simp have "dim_col (ψ₁₀ 1) * dim_col (ψ₁₀ n) = 1" by simp then show "dim_col ((ψ₁₀ 1) ⨂ (ψ₁₀ n)) = dim_col (ψ₁₀ (Suc n))" by simp next (*goal: ‹⋀i j. ⟦i < dim_row (Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n))); j < dim_col (Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n)))⟧ ⟹ (Matrix.mat (2 ^ 1) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ 1)) ⨂ Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n))) $$ (i, j) = Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n)) $$ (i, j)›*) fix i :: nat and j :: nat assume a0: "i < dim_row (ψ₁₀ (Suc n))" and a1: "j < dim_col (ψ₁₀ (Suc n))" (*‹(i::nat) < dim_row (Matrix.mat ((2::nat) ^ Suc (n::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ Suc n)))› ‹(j::nat) < dim_col (Matrix.mat ((2::nat) ^ Suc (n::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ Suc n)))›*) then have f0: "j = 0" and f1: "i < 2^(Suc n)" apply - (*goals: 1. ‹⟦i < dim_row (Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n))); j < dim_col (Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n)))⟧ ⟹ j = 0› 2. ‹⟦i < dim_row (Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n))); j < dim_col (Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n)))⟧ ⟹ i < 2 ^ Suc n› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . then have f2: "(ψ₁₀ (Suc n)) $$ (i,j) = 1/(sqrt 2)^(Suc n)" using "ψ₁₀_values"[of "i" "(Suc n)" "j"] (*‹⟦i < dim_row (Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n))); j < dim_col (Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n)))⟧ ⟹ Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n)) $$ (i, j) = complex_of_real (1 / sqrt 2 ^ Suc n)›*) a0 (*‹i < dim_row (Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n)))›*) a1 (*‹j < dim_col (Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n)))›*) by simp show "((ψ₁₀ 1) ⨂ (ψ₁₀ n)) $$ (i,j) = (ψ₁₀ (Suc n)) $$ (i,j)" proof (rule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹?P ∨ ?Q› 2. ‹?P ⟹ (Matrix.mat (2 ^ 1) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ 1)) ⨂ Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n))) $$ (i, j) = Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n)) $$ (i, j)› 3. ‹?Q ⟹ (Matrix.mat (2 ^ 1) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ 1)) ⨂ Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n))) $$ (i, j) = Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n)) $$ (i, j)›*) show "i < dim_row (ψ₁₀ n) ∨ i ≥ dim_row (ψ₁₀ n)" by linarith next (*goals: 1. ‹i < dim_row (Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n))) ⟹ (Matrix.mat (2 ^ 1) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ 1)) ⨂ Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n))) $$ (i, j) = Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n)) $$ (i, j)› 2. ‹dim_row (Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n))) ≤ i ⟹ (Matrix.mat (2 ^ 1) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ 1)) ⨂ Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n))) $$ (i, j) = Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n)) $$ (i, j)›*) assume a2: "i < dim_row (ψ₁₀ n)" (*‹(i::nat) < dim_row (Matrix.mat ((2::nat) ^ (n::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ n)))›*) then have "((ψ₁₀ 1) ⨂ (ψ₁₀ n)) $$ (i,j) = (ψ₁₀ 1) $$ (0,0) * (ψ₁₀ n) $$ (i,0)" using index_tensor_mat (*‹⟦dim_row (?A::complex Matrix.mat) = (?rA::nat); dim_col ?A = (?cA::nat); dim_row (?B::complex Matrix.mat) = (?rB::nat); dim_col ?B = (?cB::nat); (?i::nat) < ?rA * ?rB; (?j::nat) < ?cA * ?cB; (0::nat) < ?cA; (0::nat) < ?cB⟧ ⟹ (?A ⨂ ?B) $$ (?i, ?j) = ?A $$ (?i div ?rB, ?j div ?cB) * ?B $$ (?i mod ?rB, ?j mod ?cB)›*) f0 (*‹j = 0›*) assms (*‹1 ≤ n›*) by simp also (*calculation: ‹(Matrix.mat (2 ^ 1) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ 1)) ⨂ Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n))) $$ (i, j) = Matrix.mat (2 ^ 1) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ 1)) $$ (0, 0) * Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n)) $$ (i, 0)›*) have "... = 1/sqrt(2) * 1/(sqrt(2)^n)" using "ψ₁₀_values" (*‹⟦?i < dim_row (Matrix.mat (2 ^ ?n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ ?n))); ?j < dim_col (Matrix.mat (2 ^ ?n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ ?n)))⟧ ⟹ Matrix.mat (2 ^ ?n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ ?n)) $$ (?i, ?j) = complex_of_real (1 / sqrt 2 ^ ?n)›*) a2 (*‹(i::nat) < dim_row (Matrix.mat ((2::nat) ^ (n::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ n)))›*) assms (*‹1 ≤ n›*) by simp finally (*calculation: ‹(Matrix.mat (2 ^ 1) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ 1)) ⨂ Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n))) $$ (i, j) = complex_of_real (1 / sqrt 2 * 1 / sqrt 2 ^ n)›*) show "((ψ₁₀ 1) ⨂ (ψ₁₀ n)) $$ (i,j) = (ψ₁₀ (Suc n)) $$ (i,j)" using f2 (*‹Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n)) $$ (i, j) = complex_of_real (1 / sqrt 2 ^ Suc n)›*) divide_divide_eq_left (*‹?a / ?b / ?c = ?a / (?b * ?c)›*) power_Suc (*‹(?a::?'a) ^ Suc (?n::nat) = ?a * ?a ^ ?n›*) by simp next (*goal: ‹dim_row (Matrix.mat ((2::nat) ^ (n::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ n))) ≤ (i::nat) ⟹ (Matrix.mat ((2::nat) ^ (1::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ (1::nat))) ⨂ Matrix.mat ((2::nat) ^ n) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ n))) $$ (i, j::nat) = Matrix.mat ((2::nat) ^ Suc n) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ Suc n)) $$ (i, j)›*) assume "i ≥ dim_row (ψ₁₀ n)" (*‹dim_row (Matrix.mat ((2::nat) ^ (n::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ n))) ≤ (i::nat)›*) then have "((ψ₁₀ 1) ⨂ (ψ₁₀ n)) $$ (i,0) = ((ψ₁₀ 1) $$ (1, 0)) * ((ψ₁₀ n) $$ ( i -dim_row (ψ₁₀ n),0))" using index_tensor_mat_with_vec2_row_cond[of i "(ψ₁₀ 1)" "(ψ₁₀ n)"] (*‹⟦(i::nat) < (2::nat) * dim_row (Matrix.mat ((2::nat) ^ (1::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ (1::nat)))); dim_row (Matrix.mat ((2::nat) ^ (1::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ (1::nat)))) ≤ i; (0::nat) < dim_col (Matrix.mat ((2::nat) ^ (1::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ (1::nat)))); dim_row (Matrix.mat ((2::nat) ^ (n::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ n))) = (2::nat); dim_col (Matrix.mat ((2::nat) ^ n) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ n))) = (1::nat)⟧ ⟹ (Matrix.mat ((2::nat) ^ n) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ n)) ⨂ Matrix.mat ((2::nat) ^ (1::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ (1::nat)))) $$ (i, 0::nat) = Matrix.mat ((2::nat) ^ n) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ n)) $$ (1::nat, 0::nat) * Matrix.mat ((2::nat) ^ (1::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ (1::nat))) $$ (i - dim_row (Matrix.mat ((2::nat) ^ (1::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ (1::nat)))), 0::nat)›*) a0 (*‹(i::nat) < dim_row (Matrix.mat ((2::nat) ^ Suc (n::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ Suc n)))›*) a1 (*‹j < dim_col (Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n)))›*) f0 (*‹j = 0›*) by (metis dim_col_mat( (*‹dim_col (Matrix.mat ?nr ?nc ?f) = ?nc›*) 1) dim_row_mat( (*‹dim_row (Matrix.mat ?nr ?nc ?f) = ?nr›*) 1) index_tensor_mat_with_vec2_row_cond (*‹⟦?i < 2 * dim_row ?B; dim_row ?B ≤ ?i; 0 < dim_col ?B; dim_row ?A = 2; dim_col ?A = 1⟧ ⟹ (?A ⨂ ?B) $$ (?i, 0) = ?A $$ (1, 0) * ?B $$ (?i - dim_row ?B, 0)›*) power_Suc (*‹?a ^ Suc ?n = ?a * ?a ^ ?n›*) power_one_right (*‹?a ^ 1 = ?a›*)) then have "((ψ₁₀ 1) ⨂ (ψ₁₀ n)) $$ (i,0) = 1/sqrt(2) * 1/(sqrt 2)^n" using "ψ₁₀_values"[of "i -dim_row (ψ₁₀ n)" "n" "j"] (*‹⟦i - dim_row (Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n))) < dim_row (Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n))); j < dim_col (Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n)))⟧ ⟹ Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n)) $$ (i - dim_row (Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n))), j) = complex_of_real (1 / sqrt 2 ^ n)›*) a0 (*‹i < dim_row (Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n)))›*) a1 (*‹j < dim_col (Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n)))›*) by simp then show "((ψ₁₀ 1) ⨂ (ψ₁₀ n)) $$ (i,j) = (ψ₁₀ (Suc n)) $$ (i,j)" using f0 (*‹j = 0›*) f1 (*‹(i::nat) < (2::nat) ^ Suc (n::nat)›*) divide_divide_eq_left (*‹?a / ?b / ?c = ?a / (?b * ?c)›*) power_Suc (*‹?a ^ Suc ?n = ?a * ?a ^ ?n›*) by simp qed qed lemma ψ₁₀_tensor_is_state: assumes "n ≥ 1" shows "state n ( |zero⟩ ⊗⇗n⇖)" using iter_tensor_of_state_is_state (*‹⟦state ?m ?A; 1 ≤ ?n⟧ ⟹ state (?m * ?n) (?A ⊗⇗?n⇖)›*) ket_zero_is_state (*‹state 1 |Deutsch.zero⟩›*) assms (*‹1 ≤ n›*) by fastforce lemma iter_tensor_of_H_is_gate: assumes "n ≥ 1" shows "gate n (H ⊗⇗n⇖)" using iter_tensor_of_gate_is_gate (*‹⟦gate (?m::nat) (?A::complex Matrix.mat); (1::nat) ≤ (?n::nat)⟧ ⟹ gate (?m * ?n) (?A ⊗⇗?n⇖)›*) H_is_gate (*‹gate 1 H›*) assms (*‹1 ≤ n›*) by fastforce lemma iter_tensor_of_H_on_zero_tensor: assumes "n ≥ 1" shows "(H ⊗⇗n⇖) * ( |zero⟩ ⊗⇗n⇖) = ψ₁₀ n" using assms (*‹1 ≤ n›*) proof (rule nat_induct_at_least (*‹⟦?m ≤ ?n; ?P ?m; ⋀n. ⟦?m ≤ n; ?P n⟧ ⟹ ?P (Suc n)⟧ ⟹ ?P ?n›*)) (*goals: 1. ‹H ⊗⇗1::nat⇖ * |Deutsch.zero⟩ ⊗⇗1::nat⇖ = Matrix.mat ((2::nat) ^ (1::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ (1::nat)))› 2. ‹⋀n::nat. ⟦(1::nat) ≤ n; H ⊗⇗n⇖ * |Deutsch.zero⟩ ⊗⇗n⇖ = Matrix.mat ((2::nat) ^ n) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ n))⟧ ⟹ H ⊗⇗Suc n⇖ * |Deutsch.zero⟩ ⊗⇗Suc n⇖ = Matrix.mat ((2::nat) ^ Suc n) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ Suc n))›*) show "(H ⊗⇗1⇖) * ( |zero⟩ ⊗⇗1⇖) = ψ₁₀ 1" using H_on_ket_zero (*‹H * |Deutsch.zero⟩ = Matrix.mat ((2::nat) ^ (1::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ (1::nat)))›*) by simp next (*goal: ‹⋀n. ⟦1 ≤ n; H ⊗⇗n⇖ * |Deutsch.zero⟩ ⊗⇗n⇖ = Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n))⟧ ⟹ H ⊗⇗Suc n⇖ * |Deutsch.zero⟩ ⊗⇗Suc n⇖ = Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n))›*) fix n :: nat assume a0: "n ≥ 1" and IH: "(H ⊗⇗n⇖) * ( |zero⟩ ⊗⇗n⇖) = ψ₁₀ n" (*‹(1::nat) ≤ (n::nat)› ‹H ⊗⇗n::nat⇖ * |Deutsch.zero⟩ ⊗⇗n⇖ = Matrix.mat ((2::nat) ^ n) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ n))›*) then have "(H ⊗⇗(Suc n)⇖) * ( |zero⟩ ⊗⇗(Suc n)⇖) = (H * |zero⟩) ⨂ ((H ⊗⇗n⇖) * ( |zero⟩ ⊗⇗n⇖))" using iter_tensor_mult_distr[of "n" "H" "|zero⟩"] (*‹⟦1 ≤ n; dim_col H = dim_row |Deutsch.zero⟩; 0 < dim_col H; 0 < dim_col |Deutsch.zero⟩⟧ ⟹ H ⊗⇗Suc n⇖ * |Deutsch.zero⟩ ⊗⇗Suc n⇖ = H * |Deutsch.zero⟩ ⨂ H ⊗⇗n⇖ * |Deutsch.zero⟩ ⊗⇗n⇖›*) a0 (*‹1 ≤ n›*) ket_vec_def (*‹|?v⟩ ≡ Matrix.mat (dim_vec ?v) 1 (λ(i, j). ?v $ i)›*) H_def (*‹H ≡ complex_of_real (1 / sqrt 2) ⋅⇩m Matrix.mat 2 2 (λ(i, j). if i ≠ j then 1 else if i = 0 then 1 else - 1)›*) by (simp add: H_def (*‹H ≡ complex_of_real (1 / sqrt 2) ⋅⇩m Matrix.mat 2 2 (λ(i, j). if i ≠ j then 1 else if i = 0 then 1 else - 1)›*)) also (*calculation: ‹H ⊗⇗Suc n⇖ * |Deutsch.zero⟩ ⊗⇗Suc n⇖ = H * |Deutsch.zero⟩ ⨂ H ⊗⇗n⇖ * |Deutsch.zero⟩ ⊗⇗n⇖›*) have "... = (H * |zero⟩) ⨂ (ψ₁₀ n)" using IH (*‹H ⊗⇗n⇖ * |Deutsch.zero⟩ ⊗⇗n⇖ = Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n))›*) by simp also (*calculation: ‹H ⊗⇗Suc n⇖ * |Deutsch.zero⟩ ⊗⇗Suc n⇖ = H * |Deutsch.zero⟩ ⨂ Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n))›*) have "... = (ψ₁₀ 1) ⨂ (ψ₁₀ n)" using H_on_ket_zero (*‹H * |Deutsch.zero⟩ = Matrix.mat ((2::nat) ^ (1::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ (1::nat)))›*) by simp also (*calculation: ‹H ⊗⇗Suc n⇖ * |Deutsch.zero⟩ ⊗⇗Suc n⇖ = Matrix.mat (2 ^ 1) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ 1)) ⨂ Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n))›*) have "... = (ψ₁₀ (Suc n))" using "ψ₁₀_tensor" (*‹(1::nat) ≤ (?n::nat) ⟹ Matrix.mat ((2::nat) ^ (1::nat)) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ (1::nat))) ⨂ Matrix.mat ((2::nat) ^ ?n) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ ?n)) = Matrix.mat ((2::nat) ^ Suc ?n) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ Suc ?n))›*) a0 (*‹1 ≤ n›*) by simp finally (*calculation: ‹H ⊗⇗Suc n⇖ * |Deutsch.zero⟩ ⊗⇗Suc n⇖ = Matrix.mat (2 ^ Suc n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ Suc n))›*) show "(H ⊗⇗(Suc n)⇖) * ( |zero⟩ ⊗⇗(Suc n)⇖) = (ψ₁₀ (Suc n))" by simp qed lemma ψ₁₀_is_state: assumes "n ≥ 1" shows "state n (ψ₁₀ n)" using iter_tensor_of_H_is_gate (*‹1 ≤ ?n ⟹ gate ?n (H ⊗⇗?n⇖)›*) "ψ₁₀_tensor_is_state" (*‹1 ≤ ?n ⟹ state ?n (|Deutsch.zero⟩ ⊗⇗?n⇖)›*) assms (*‹1 ≤ n›*) gate_on_state_is_state (*‹⟦gate ?n ?A; state ?n ?v⟧ ⟹ state ?n (?A * ?v)›*) iter_tensor_of_H_on_zero_tensor (*‹(1::nat) ≤ (?n::nat) ⟹ H ⊗⇗?n⇖ * |Deutsch.zero⟩ ⊗⇗?n⇖ = Matrix.mat ((2::nat) ^ ?n) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (1::real) / sqrt (2::real) ^ ?n))›*) assms (*‹1 ≤ n›*) by metis abbreviation ψ₁₁:: "complex Matrix.mat" where "ψ₁₁ ≡ Matrix.mat 2 1 (λ(i,j). if i=0 then 1/sqrt(2) else -1/sqrt(2))" lemma H_on_ket_one_is_ψ₁₁: shows "(H * |one⟩) = ψ₁₁" proof (standard) (*goals: 1. ‹⋀i j. ⟦i < dim_row (Matrix.mat 2 1 (λx. complex_of_real (case x of (i, j) ⇒ if i = 0 then 1 / sqrt 2 else - 1 / sqrt 2))); j < dim_col (Matrix.mat 2 1 (λx. complex_of_real (case x of (i, j) ⇒ if i = 0 then 1 / sqrt 2 else - 1 / sqrt 2)))⟧ ⟹ (H * |Deutsch.one⟩) $$ (i, j) = Matrix.mat 2 1 (λx. complex_of_real (case x of (i, j) ⇒ if i = 0 then 1 / sqrt 2 else - 1 / sqrt 2)) $$ (i, j)› 2. ‹dim_row (H * |Deutsch.one⟩) = dim_row (Matrix.mat 2 1 (λx. complex_of_real (case x of (i, j) ⇒ if i = 0 then 1 / sqrt 2 else - 1 / sqrt 2)))› 3. ‹dim_col (H * |Deutsch.one⟩) = dim_col (Matrix.mat 2 1 (λx. complex_of_real (case x of (i, j) ⇒ if i = 0 then 1 / sqrt 2 else - 1 / sqrt 2)))›*) fix i :: nat and j :: nat assume "i < dim_row ψ₁₁" and "j < dim_col ψ₁₁" (*‹(i::nat) < dim_row (Matrix.mat (2::nat) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if i = (0::nat) then (1::real) / sqrt (2::real) else - (1::real) / sqrt (2::real))))› ‹(j::nat) < dim_col (Matrix.mat (2::nat) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if i = (0::nat) then (1::real) / sqrt (2::real) else - (1::real) / sqrt (2::real))))›*) then have "i ∈ {0,1} ∧ j = 0" by (simp add: less_2_cases (*‹?n < 2 ⟹ ?n = 0 ∨ ?n = Suc 0›*)) then show "(H * |one⟩) $$ (i,j) = ψ₁₁ $$ (i,j)" by (auto simp add: times_mat_def (*‹?A * ?B ≡ Matrix.mat (dim_row ?A) (dim_col ?B) (λ(i, j). Matrix.row ?A i ∙ Matrix.col ?B j)›*) scalar_prod_def (*‹?v ∙ ?w ≡ ∑i = 0..<dim_vec ?w. ?v $ i * ?w $ i›*) H_def (*‹H ≡ complex_of_real (1 / sqrt 2) ⋅⇩m Matrix.mat 2 2 (λ(i, j). if i ≠ j then 1 else if i = 0 then 1 else - 1)›*) ket_vec_def (*‹|?v⟩ ≡ Matrix.mat (dim_vec ?v) 1 (λ(i, j). ?v $ i)›*)) next (*goals: 1. ‹dim_row (H * |Deutsch.one⟩) = dim_row (Matrix.mat (2::nat) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if i = (0::nat) then (1::real) / sqrt (2::real) else - (1::real) / sqrt (2::real))))› 2. ‹dim_col (H * |Deutsch.one⟩) = dim_col (Matrix.mat (2::nat) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if i = (0::nat) then (1::real) / sqrt (2::real) else - (1::real) / sqrt (2::real))))›*) show "dim_row (H * |one⟩) = dim_row ψ₁₁" by (simp add: H_def (*‹H ≡ complex_of_real ((1::real) / sqrt (2::real)) ⋅⇩m Matrix.mat (2::nat) (2::nat) (λ(i::nat, j::nat). if i ≠ j then 1::complex else if i = (0::nat) then 1::complex else - (1::complex))›*)) next (*goal: ‹dim_col (H * |Deutsch.one⟩) = dim_col (Matrix.mat 2 1 (λx. complex_of_real (case x of (i, j) ⇒ if i = 0 then 1 / sqrt 2 else - 1 / sqrt 2)))›*) show "dim_col (H * |one⟩) = dim_col ψ₁₁" by (simp add: H_def (*‹H ≡ complex_of_real ((1::real) / sqrt (2::real)) ⋅⇩m Matrix.mat (2::nat) (2::nat) (λ(i::nat, j::nat). if i ≠ j then 1::complex else if i = (0::nat) then 1::complex else - (1::complex))›*) ket_vec_def (*‹|?v::complex Matrix.vec⟩ ≡ Matrix.mat (dim_vec ?v) (1::nat) (λ(i::nat, j::nat). ?v $ i)›*)) qed abbreviation ψ₁:: "nat ⇒ complex Matrix.mat" where "ψ₁ n ≡ Matrix.mat (2^(n+1)) 1 (λ(i,j). if even i then 1/(sqrt 2)^(n+1) else -1/(sqrt 2)^(n+1))" lemma ψ₁_values_even[simp]: fixes i j n assumes "i < dim_row (ψ₁ n)" and "j < dim_col (ψ₁ n)" and "even i" shows "(ψ₁ n) $$ (i,j) = 1/(sqrt 2)^(n+1)" using assms (*‹i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))))› ‹j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))))› ‹even (i::nat)›*) case_prod_conv (*‹(case (?a, ?b) of (c, d) ⇒ ?f c d) = ?f ?a ?b›*) by simp lemma ψ₁_values_odd [simp]: fixes i j n assumes "i < dim_row (ψ₁ n)" and "j < dim_col (ψ₁ n)" and "odd i" shows "(ψ₁ n) $$ (i,j) = -1/(sqrt 2)^(n+1)" using assms (*‹(i::nat) < dim_row (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (1::real) / sqrt (2::real) ^ (n + (1::nat)) else - (1::real) / sqrt (2::real) ^ (n + (1::nat)))))› ‹j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))))› ‹odd i›*) case_prod_conv (*‹(case (?a, ?b) of (c, d) ⇒ ?f c d) = ?f ?a ?b›*) by simp lemma "ψ₁₀_tensor_ψ₁₁_is_ψ₁": assumes "n ≥ 1" shows "(ψ₁₀ n) ⨂ ψ₁₁ = ψ₁ n" proof (standard) (*goals: 1. ‹⋀i j. ⟦i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))); j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))))⟧ ⟹ (Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n)) ⨂ Matrix.mat 2 1 (λx. complex_of_real (case x of (i, j) ⇒ if i = 0 then 1 / sqrt 2 else - 1 / sqrt 2))) $$ (i, j) = Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))) $$ (i, j)› 2. ‹dim_row (Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n)) ⨂ Matrix.mat 2 1 (λx. complex_of_real (case x of (i, j) ⇒ if i = 0 then 1 / sqrt 2 else - 1 / sqrt 2))) = dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))))› 3. ‹dim_col (Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n)) ⨂ Matrix.mat 2 1 (λx. complex_of_real (case x of (i, j) ⇒ if i = 0 then 1 / sqrt 2 else - 1 / sqrt 2))) = dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))))›*) show "dim_col ((ψ₁₀ n) ⨂ ψ₁₁) = dim_col (ψ₁ n)" by simp next (*goals: 1. ‹⋀i j. ⟦i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))); j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))))⟧ ⟹ (Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n)) ⨂ Matrix.mat 2 1 (λx. complex_of_real (case x of (i, j) ⇒ if i = 0 then 1 / sqrt 2 else - 1 / sqrt 2))) $$ (i, j) = Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))) $$ (i, j)› 2. ‹dim_row (Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n)) ⨂ Matrix.mat 2 1 (λx. complex_of_real (case x of (i, j) ⇒ if i = 0 then 1 / sqrt 2 else - 1 / sqrt 2))) = dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))))›*) show "dim_row ((ψ₁₀ n) ⨂ ψ₁₁) = dim_row (ψ₁ n)" by simp next (*goal: ‹⋀i j. ⟦i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))); j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))))⟧ ⟹ (Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n)) ⨂ Matrix.mat 2 1 (λx. complex_of_real (case x of (i, j) ⇒ if i = 0 then 1 / sqrt 2 else - 1 / sqrt 2))) $$ (i, j) = Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))) $$ (i, j)›*) fix i :: nat and j :: nat assume a0: "i < dim_row (ψ₁ n)" and a1: "j < dim_col (ψ₁ n)" (*‹(i::nat) < dim_row (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (1::real) / sqrt (2::real) ^ (n + (1::nat)) else - (1::real) / sqrt (2::real) ^ (n + (1::nat)))))› ‹(j::nat) < dim_col (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (1::real) / sqrt (2::real) ^ (n + (1::nat)) else - (1::real) / sqrt (2::real) ^ (n + (1::nat)))))›*) then have "i < 2^(n+1)" and "j = 0" apply - (*goals: 1. ‹⟦i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))); j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))))⟧ ⟹ i < 2 ^ (n + 1)› 2. ‹⟦i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))); j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))))⟧ ⟹ j = 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . then have f0: "((ψ₁₀ n) ⨂ ψ₁₁) $$ (i,j) = 1/(sqrt 2)^n * ψ₁₁ $$ (i mod 2, j)" using "ψ₁₀_values"[of "i div 2" n "j div 1"] (*‹⟦i div 2 < dim_row (Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n))); j div 1 < dim_col (Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n)))⟧ ⟹ Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n)) $$ (i div 2, j div 1) = complex_of_real (1 / sqrt 2 ^ n)›*) a0 (*‹i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))))›*) a1 (*‹j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))))›*) by simp show "((ψ₁₀ n) ⨂ ψ₁₁) $$ (i,j) = (ψ₁ n) $$ (i,j)" using f0 (*‹(Matrix.mat (2 ^ n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ n)) ⨂ Matrix.mat 2 1 (λx. complex_of_real (case x of (i, j) ⇒ if i = 0 then 1 / sqrt 2 else - 1 / sqrt 2))) $$ (i, j) = complex_of_real (1 / sqrt 2 ^ n) * Matrix.mat 2 1 (λx. complex_of_real (case x of (i, j) ⇒ if i = 0 then 1 / sqrt 2 else - 1 / sqrt 2)) $$ (i mod 2, j)›*) "ψ₁_values_even" (*‹⟦?i < dim_row (Matrix.mat (2 ^ (?n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (?n + 1) else - 1 / sqrt 2 ^ (?n + 1)))); ?j < dim_col (Matrix.mat (2 ^ (?n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (?n + 1) else - 1 / sqrt 2 ^ (?n + 1)))); even ?i⟧ ⟹ Matrix.mat (2 ^ (?n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (?n + 1) else - 1 / sqrt 2 ^ (?n + 1))) $$ (?i, ?j) = complex_of_real (1 / sqrt 2 ^ (?n + 1))›*) "ψ₁_values_odd" (*‹⟦?i < dim_row (Matrix.mat (2 ^ (?n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (?n + 1) else - 1 / sqrt 2 ^ (?n + 1)))); ?j < dim_col (Matrix.mat (2 ^ (?n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (?n + 1) else - 1 / sqrt 2 ^ (?n + 1)))); odd ?i⟧ ⟹ Matrix.mat (2 ^ (?n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (?n + 1) else - 1 / sqrt 2 ^ (?n + 1))) $$ (?i, ?j) = complex_of_real (- 1 / sqrt 2 ^ (?n + 1))›*) a0 (*‹i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))))›*) a1 (*‹j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))))›*) by auto qed lemma ψ₁_is_state: assumes "n ≥ 1" shows "state (n+1) (ψ₁ n)" using assms (*‹1 ≤ n›*) "ψ₁₀_tensor_ψ₁₁_is_ψ₁" (*‹1 ≤ ?n ⟹ Matrix.mat (2 ^ ?n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ ?n)) ⨂ Matrix.mat 2 1 (λx. complex_of_real (case x of (i, j) ⇒ if i = 0 then 1 / sqrt 2 else - 1 / sqrt 2)) = Matrix.mat (2 ^ (?n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (?n + 1) else - 1 / sqrt 2 ^ (?n + 1)))›*) "ψ₁₀_is_state" (*‹1 ≤ ?n ⟹ state ?n (Matrix.mat (2 ^ ?n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ ?n)))›*) H_on_ket_one_is_state (*‹state (1::nat) (H * |Deutsch.one⟩)›*) "H_on_ket_one_is_ψ₁₁" (*‹H * |Deutsch.one⟩ = Matrix.mat 2 1 (λx. complex_of_real (case x of (i, j) ⇒ if i = 0 then 1 / sqrt 2 else - 1 / sqrt 2))›*) tensor_state (*‹⟦state ?m ?u; state ?n ?v⟧ ⟹ state (?m + ?n) (?u ⨂ ?v)›*) by metis abbreviation (in jozsa) ψ₂:: "complex Matrix.mat" where "ψ₂ ≡ Matrix.mat (2^(n+1)) 1 (λ(i,j). if even i then (-1)^f(i div 2)/(sqrt 2)^(n+1) else (-1)^(f(i div 2)+1)/(sqrt 2)^(n+1))" lemma (in jozsa) ψ₂_values_even [simp]: fixes i j assumes "i < dim_row ψ₂ " and "j < dim_col ψ₂" and "even i" shows "ψ₂ $$ (i,j) = (-1)^f(i div 2)/(sqrt 2)^(n+1)" using assms (*‹i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))))› ‹j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))))› ‹even i›*) case_prod_conv (*‹(case (?a::?'b, ?b::?'c) of (c::?'b, d::?'c) ⇒ (?f::?'b ⇒ ?'c ⇒ ?'a) c d) = ?f ?a ?b›*) by simp lemma (in jozsa) ψ₂_values_odd [simp]: fixes i j assumes "i < dim_row ψ₂" and "j < dim_col ψ₂" and "odd i" shows "ψ₂ $$ (i,j) = (-1)^(f(i div 2)+1)/(sqrt 2)^(n+1)" using assms (*‹i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))))› ‹j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))))› ‹odd i›*) case_prod_conv (*‹(case (?a, ?b) of (c, d) ⇒ ?f c d) = ?f ?a ?b›*) by simp lemma (in jozsa) ψ₂_values_odd_hidden [simp]: assumes "2*k+1 < dim_row ψ₂" and "j < dim_col ψ₂" shows "ψ₂ $$ (2*k+1,j) = ((-1)^(f((2*k+1) div 2)+1))/(sqrt 2)^(n+1)" using assms (*‹(2::nat) * (k::nat) + (1::nat) < dim_row (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (- (1::real)) ^ (f::nat ⇒ nat) (i div (2::nat)) / sqrt (2::real) ^ (n + (1::nat)) else (- (1::real)) ^ (f (i div (2::nat)) + (1::nat)) / sqrt (2::real) ^ (n + (1::nat)))))› ‹j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))))›*) by simp lemma (in jozsa) snd_rep_of_ψ₂: assumes "i < dim_row ψ₂" shows "((1-f(i div 2)) + -f(i div 2)) * 1/(sqrt 2)^(n+1) = (-1)^f(i div 2)/(sqrt 2)^(n+1)" and "(-(1-f(i div 2))+(f(i div 2)))* 1/(sqrt 2)^(n+1) = (-1)^(f(i div 2)+1)/(sqrt 2)^(n+1)" proof (-) (*goals: 1. ‹real_of_int ((int (1 - f (i div 2)) + - int (f (i div 2))) * 1) / sqrt 2 ^ (n + 1) = (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1)› 2. ‹real_of_int ((- int (1 - f (i div 2)) + int (f (i div 2))) * 1) / sqrt 2 ^ (n + 1) = (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)›*) have "i div 2 ∈ {i. i < 2 ^ n}" using assms (*‹(i::nat) < dim_row (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (- (1::real)) ^ (f::nat ⇒ nat) (i div (2::nat)) / sqrt (2::real) ^ (n + (1::nat)) else (- (1::real)) ^ (f (i div (2::nat)) + (1::nat)) / sqrt (2::real) ^ (n + (1::nat)))))›*) by auto then have "real (Suc 0 - f (i div 2)) - real (f (i div 2)) = (- 1) ^ f (i div 2)" using assms (*‹i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))))›*) f_values (*‹∀x∈{i. i < 2 ^ n}. f x = 0 ∨ f x = 1›*) by auto thus "((1-f(i div 2)) + -f(i div 2)) * 1/(sqrt 2)^(n+1) = (-1)^f(i div 2)/(sqrt 2)^(n+1)" by auto next (*goal: ‹real_of_int ((- int (1 - f (i div 2)) + int (f (i div 2))) * 1) / sqrt 2 ^ (n + 1) = (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)›*) have "i div 2 ∈ {i. i < 2^n}" using assms (*‹i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))))›*) by simp then have "(real (f (i div 2)) - real (Suc 0 - f (i div 2))) / (sqrt 2 ^ (n+1)) = - ((- 1) ^ f (i div 2) / (sqrt 2 ^ (n+1)))" using assms (*‹i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))))›*) f_values (*‹∀x∈{i. i < 2 ^ n}. f x = 0 ∨ f x = 1›*) by fastforce then show "(-(1-f(i div 2))+(f(i div 2)))* 1/(sqrt 2)^(n+1) = (-1)^(f(i div 2)+1)/(sqrt 2)^(n+1)" by simp qed lemma (in jozsa) jozsa_transform_times_ψ₁_is_ψ₂: shows "U⇩f * (ψ₁ n) = ψ₂" proof (standard) (*goals: 1. ‹⋀i j. ⟦i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)))); j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))))⟧ ⟹ (U⇩f * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))) $$ (i, j) = Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))) $$ (i, j)› 2. ‹dim_row (U⇩f * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))) = dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))))› 3. ‹dim_col (U⇩f * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))) = dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))))›*) show "dim_row (U⇩f * (ψ₁ n)) = dim_row ψ₂" by simp next (*goals: 1. ‹⋀i j. ⟦i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)))); j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))))⟧ ⟹ (U⇩f * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))) $$ (i, j) = Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))) $$ (i, j)› 2. ‹dim_col (U⇩f * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))) = dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))))›*) show "dim_col (U⇩f * (ψ₁ n)) = dim_col ψ₂" by simp next (*goal: ‹⋀i j. ⟦i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)))); j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))))⟧ ⟹ (U⇩f * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))) $$ (i, j) = Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))) $$ (i, j)›*) fix i :: nat and j :: nat assume a0: "i < dim_row ψ₂" and a1: "j < dim_col ψ₂" (*‹(i::nat) < dim_row (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (- (1::real)) ^ (f::nat ⇒ nat) (i div (2::nat)) / sqrt (2::real) ^ (n + (1::nat)) else (- (1::real)) ^ (f (i div (2::nat)) + (1::nat)) / sqrt (2::real) ^ (n + (1::nat)))))› ‹(j::nat) < dim_col (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (- (1::real)) ^ (f::nat ⇒ nat) (i div (2::nat)) / sqrt (2::real) ^ (n + (1::nat)) else (- (1::real)) ^ (f (i div (2::nat)) + (1::nat)) / sqrt (2::real) ^ (n + (1::nat)))))›*) then have f0: "i ∈ {0..2^(n+1)} ∧ j=0" by simp then have f1: "i < dim_row U⇩f ∧ j < dim_col U⇩f " using a0 (*‹(i::nat) < dim_row (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (- (1::real)) ^ (f::nat ⇒ nat) (i div (2::nat)) / sqrt (2::real) ^ (n + (1::nat)) else (- (1::real)) ^ (f (i div (2::nat)) + (1::nat)) / sqrt (2::real) ^ (n + (1::nat)))))›*) by simp have f2: "i < dim_row (ψ₁ n) ∧ j < dim_col (ψ₁ n)" using a0 (*‹(i::nat) < dim_row (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (- (1::real)) ^ (f::nat ⇒ nat) (i div (2::nat)) / sqrt (2::real) ^ (n + (1::nat)) else (- (1::real)) ^ (f (i div (2::nat)) + (1::nat)) / sqrt (2::real) ^ (n + (1::nat)))))›*) a1 (*‹j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))))›*) by simp show "(U⇩f * (ψ₁ n)) $$ (i,j) = ψ₂ $$ (i,j)" proof (rule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹?P ∨ ?Q› 2. ‹?P ⟹ (U⇩f * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))) $$ (i, j) = Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))) $$ (i, j)› 3. ‹?Q ⟹ (U⇩f * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))) $$ (i, j) = Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))) $$ (i, j)›*) show "even i ∨ odd i" by auto next (*goals: 1. ‹even i ⟹ (U⇩f * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))) $$ (i, j) = Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))) $$ (i, j)› 2. ‹odd i ⟹ (U⇩f * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))) $$ (i, j) = Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))) $$ (i, j)›*) assume a2: "even i" (*‹even (i::nat)›*) then have "(U⇩f * (ψ₁ n)) $$ (i,j) = (∑k ∈ {i,i+1}. U⇩f $$ (i,k) * (ψ₁ n) $$ (k,j))" using f1 (*‹i < dim_row U⇩f ∧ j < dim_col U⇩f›*) f2 (*‹i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))) ∧ j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))))›*) "U⇩f_mult_without_empty_summands_even"[of i j "(ψ₁ n)"] (*‹⟦i < dim_row U⇩f; j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))); even i; dim_col U⇩f = dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))))⟧ ⟹ (U⇩f * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))) $$ (i, j) = (∑k∈{i, i + 1}. U⇩f $$ (i, k) * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))) $$ (k, j))›*) by simp moreover have "U⇩f $$ (i,i) * (ψ₁ n) $$ (i,j) = (1-f(i div 2))* 1/(sqrt 2)^(n+1)" using f0 (*‹i ∈ {0..2 ^ (n + 1)} ∧ j = 0›*) f1 (*‹(i::nat) < dim_row U⇩f ∧ (j::nat) < dim_col U⇩f›*) a2 (*‹even (i::nat)›*) by simp moreover have "U⇩f $$ (i,i+1) * (ψ₁ n) $$ (i+1,j) = (-f(i div 2))* 1/(sqrt 2)^(n+1)" using f0 (*‹i ∈ {0..2 ^ (n + 1)} ∧ j = 0›*) f1 (*‹i < dim_row U⇩f ∧ j < dim_col U⇩f›*) a2 (*‹even i›*) by auto ultimately have "(U⇩f * (ψ₁ n)) $$ (i,j) = (1-f(i div 2))* 1/(sqrt 2)^(n+1) + (-f(i div 2))* 1/(sqrt 2)^(n+1)" by simp also (*calculation: ‹(U⇩f * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))) $$ (i, j) = complex_of_real (real ((1 - f (i div 2)) * 1) / sqrt 2 ^ (n + 1) + real_of_int (- int (f (i div 2)) * 1) / sqrt 2 ^ (n + 1))›*) have "... = ((1-f(i div 2))+-f(i div 2)) * 1/(sqrt 2)^(n+1)" using add_divide_distrib (*‹(?a + ?b) / ?c = ?a / ?c + ?b / ?c›*) by (metis (no_types, opaque_lifting) mult.right_neutral (*‹?a * 1 = ?a›*) of_int_add (*‹of_int (?w + ?z) = of_int ?w + of_int ?z›*) of_int_of_nat_eq (*‹of_int (int ?n) = of_nat ?n›*)) also (*calculation: ‹(U⇩f * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))) $$ (i, j) = complex_of_real (real_of_int ((int (1 - f (i div 2)) + - int (f (i div 2))) * 1) / sqrt 2 ^ (n + 1))›*) have "... = ψ₂ $$ (i,j)" using a0 (*‹i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))))›*) a1 (*‹j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))))›*) a2 (*‹even i›*) "snd_rep_of_ψ₂" (*‹(?i::nat) < dim_row (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (- (1::real)) ^ (f::nat ⇒ nat) (i div (2::nat)) / sqrt (2::real) ^ (n + (1::nat)) else (- (1::real)) ^ (f (i div (2::nat)) + (1::nat)) / sqrt (2::real) ^ (n + (1::nat))))) ⟹ real_of_int ((int ((1::nat) - f (?i div (2::nat))) + - int (f (?i div (2::nat)))) * (1::int)) / sqrt (2::real) ^ (n + (1::nat)) = (- (1::real)) ^ f (?i div (2::nat)) / sqrt (2::real) ^ (n + (1::nat))› ‹(?i::nat) < dim_row (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (- (1::real)) ^ (f::nat ⇒ nat) (i div (2::nat)) / sqrt (2::real) ^ (n + (1::nat)) else (- (1::real)) ^ (f (i div (2::nat)) + (1::nat)) / sqrt (2::real) ^ (n + (1::nat))))) ⟹ real_of_int ((- int ((1::nat) - f (?i div (2::nat))) + int (f (?i div (2::nat)))) * (1::int)) / sqrt (2::real) ^ (n + (1::nat)) = (- (1::real)) ^ (f (?i div (2::nat)) + (1::nat)) / sqrt (2::real) ^ (n + (1::nat))›*) by simp finally (*calculation: ‹(U⇩f * Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (1::real) / sqrt (2::real) ^ (n + (1::nat)) else - (1::real) / sqrt (2::real) ^ (n + (1::nat))))) $$ (i::nat, j::nat) = Matrix.mat ((2::nat) ^ (n + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (- (1::real)) ^ (f::nat ⇒ nat) (i div (2::nat)) / sqrt (2::real) ^ (n + (1::nat)) else (- (1::real)) ^ (f (i div (2::nat)) + (1::nat)) / sqrt (2::real) ^ (n + (1::nat)))) $$ (i, j)›*) show "(U⇩f * (ψ₁ n)) $$ (i,j) = ψ₂ $$ (i,j)" by simp next (*goal: ‹odd (i::nat) ⟹ (U⇩f * Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (1::real) / sqrt (2::real) ^ (n + (1::nat)) else - (1::real) / sqrt (2::real) ^ (n + (1::nat))))) $$ (i, j::nat) = Matrix.mat ((2::nat) ^ (n + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (- (1::real)) ^ (f::nat ⇒ nat) (i div (2::nat)) / sqrt (2::real) ^ (n + (1::nat)) else (- (1::real)) ^ (f (i div (2::nat)) + (1::nat)) / sqrt (2::real) ^ (n + (1::nat)))) $$ (i, j)›*) assume a2: "odd i" (*‹odd (i::nat)›*) then have f6: "i≥1" using linorder_not_less (*‹(¬ ?x < ?y) = (?y ≤ ?x)›*) by auto have "(U⇩f * (ψ₁ n)) $$ (i,j) = (∑k ∈ {i-1,i}. U⇩f $$ (i,k) * (ψ₁ n) $$ (k,j))" using f1 (*‹i < dim_row U⇩f ∧ j < dim_col U⇩f›*) f2 (*‹(i::nat) < dim_row (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (1::real) / sqrt (2::real) ^ (n + (1::nat)) else - (1::real) / sqrt (2::real) ^ (n + (1::nat))))) ∧ (j::nat) < dim_col (Matrix.mat ((2::nat) ^ (n + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (1::real) / sqrt (2::real) ^ (n + (1::nat)) else - (1::real) / sqrt (2::real) ^ (n + (1::nat)))))›*) a2 (*‹odd i›*) "U⇩f_mult_without_empty_summands_odd"[of i j "(ψ₁ n)"] (*‹⟦i < dim_row U⇩f; j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))); odd i; dim_col U⇩f = dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))))⟧ ⟹ (U⇩f * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))) $$ (i, j) = (∑k∈{i - 1, i}. U⇩f $$ (i, k) * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))) $$ (k, j))›*) by (metis dim_row_mat( (*‹dim_row (Matrix.mat ?nr ?nc ?f) = ?nr›*) 1) jozsa_transform_dim( (*‹dim_col U⇩f = 2 ^ (n + 1)›*) 2)) moreover have "(∑k ∈ {i-1,i}. U⇩f $$ (i,k) * (ψ₁ n) $$ (k,j)) = U⇩f $$ (i,i-1) * (ψ₁ n) $$ (i-1,j) + U⇩f $$ (i,i) * (ψ₁ n) $$ (i,j)" using a2 (*‹odd i›*) f6 (*‹1 ≤ i›*) by simp moreover have "U⇩f $$ (i,i) * (ψ₁ n) $$ (i,j) = (1-f(i div 2))* -1/(sqrt 2)^(n+1)" using f1 (*‹i < dim_row U⇩f ∧ j < dim_col U⇩f›*) f2 (*‹i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))) ∧ j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))))›*) a2 (*‹odd i›*) by simp moreover have "U⇩f $$ (i,i-1) * (ψ₁ n) $$ (i-1,j) = f(i div 2)* 1/(sqrt 2)^(n+1)" using a0 (*‹i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))))›*) a1 (*‹(j::nat) < dim_col (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (- (1::real)) ^ (f::nat ⇒ nat) (i div (2::nat)) / sqrt (2::real) ^ (n + (1::nat)) else (- (1::real)) ^ (f (i div (2::nat)) + (1::nat)) / sqrt (2::real) ^ (n + (1::nat)))))›*) a2 (*‹odd i›*) by simp ultimately have "(U⇩f * (ψ₁ n)) $$ (i,j) = (1-f(i div 2))* -1/(sqrt 2)^(n+1) +(f(i div 2))* 1/(sqrt 2)^(n+1)" using of_real_add (*‹of_real (?x + ?y) = of_real ?x + of_real ?y›*) by simp also (*calculation: ‹(U⇩f * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1)))) $$ (i, j) = complex_of_real (real_of_int (int (1 - f (i div 2)) * - 1) / sqrt 2 ^ (n + 1) + real (f (i div 2) * 1) / sqrt 2 ^ (n + 1))›*) have "... = (-(1-f(i div 2)) + (f(i div 2))) * 1/(sqrt 2)^(n+1)" by (metis (no_types, opaque_lifting) mult.right_neutral (*‹?a * 1 = ?a›*) add_divide_distrib (*‹(?a + ?b) / ?c = ?a / ?c + ?b / ?c›*) mult_minus1_right (*‹?z * - 1 = - ?z›*) of_int_add (*‹of_int (?w + ?z) = of_int ?w + of_int ?z›*) of_int_of_nat_eq (*‹of_int (int ?n) = of_nat ?n›*)) also (*calculation: ‹(U⇩f * Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (1::real) / sqrt (2::real) ^ (n + (1::nat)) else - (1::real) / sqrt (2::real) ^ (n + (1::nat))))) $$ (i::nat, j::nat) = complex_of_real (real_of_int ((- int ((1::nat) - (f::nat ⇒ nat) (i div (2::nat))) + int (f (i div (2::nat)))) * (1::int)) / sqrt (2::real) ^ (n + (1::nat)))›*) have "... = (-1)^(f(i div 2)+1)/(sqrt 2)^(n+1)" using a0 (*‹(i::nat) < dim_row (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (- (1::real)) ^ (f::nat ⇒ nat) (i div (2::nat)) / sqrt (2::real) ^ (n + (1::nat)) else (- (1::real)) ^ (f (i div (2::nat)) + (1::nat)) / sqrt (2::real) ^ (n + (1::nat)))))›*) a1 (*‹(j::nat) < dim_col (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (- (1::real)) ^ (f::nat ⇒ nat) (i div (2::nat)) / sqrt (2::real) ^ (n + (1::nat)) else (- (1::real)) ^ (f (i div (2::nat)) + (1::nat)) / sqrt (2::real) ^ (n + (1::nat)))))›*) a2 (*‹odd i›*) "snd_rep_of_ψ₂" (*‹?i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)))) ⟹ real_of_int ((int (1 - f (?i div 2)) + - int (f (?i div 2))) * 1) / sqrt 2 ^ (n + 1) = (- 1) ^ f (?i div 2) / sqrt 2 ^ (n + 1)› ‹(?i::nat) < dim_row (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (- (1::real)) ^ (f::nat ⇒ nat) (i div (2::nat)) / sqrt (2::real) ^ (n + (1::nat)) else (- (1::real)) ^ (f (i div (2::nat)) + (1::nat)) / sqrt (2::real) ^ (n + (1::nat))))) ⟹ real_of_int ((- int ((1::nat) - f (?i div (2::nat))) + int (f (?i div (2::nat)))) * (1::int)) / sqrt (2::real) ^ (n + (1::nat)) = (- (1::real)) ^ (f (?i div (2::nat)) + (1::nat)) / sqrt (2::real) ^ (n + (1::nat))›*) by simp finally (*calculation: ‹(U⇩f * Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (1::real) / sqrt (2::real) ^ (n + (1::nat)) else - (1::real) / sqrt (2::real) ^ (n + (1::nat))))) $$ (i::nat, j::nat) = complex_of_real ((- (1::real)) ^ ((f::nat ⇒ nat) (i div (2::nat)) + (1::nat)) / sqrt (2::real) ^ (n + (1::nat)))›*) show "(U⇩f * (ψ₁ n)) $$ (i,j) = ψ₂ $$ (i,j)" using a0 (*‹i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))))›*) a1 (*‹j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))))›*) a2 (*‹odd i›*) by simp qed qed lemma (in jozsa) ψ₂_is_state: shows "state (n+1) ψ₂" using "jozsa_transform_times_ψ₁_is_ψ₂" (*‹U⇩f * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))) = Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)))›*) jozsa_transform_is_gate (*‹gate (n + 1) U⇩f›*) "ψ₁_is_state" (*‹1 ≤ ?n ⟹ state (?n + 1) (Matrix.mat (2 ^ (?n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (?n + 1) else - 1 / sqrt 2 ^ (?n + 1))))›*) dim (*‹1 ≤ n›*) gate_on_state_is_state (*‹⟦gate ?n ?A; state ?n ?v⟧ ⟹ state ?n (?A * ?v)›*) by fastforce text ‹@{text "H^⇩⊗ n"} is the result of taking the nth tensor product of H› abbreviation iter_tensor_of_H_rep:: "nat ⇒ complex Matrix.mat" ("H^⇩⊗ _") where "iter_tensor_of_H_rep n ≡ Matrix.mat (2^n) (2^n) (λ(i,j).(-1)^(i ⋅⇘n⇙ j)/(sqrt 2)^n)" lemma tensor_of_H_values [simp]: fixes n i j:: nat assumes "i < dim_row (H^⇩⊗ n)" and "j < dim_col (H^⇩⊗ n)" shows "(H^⇩⊗ n) $$ (i,j) = (-1)^(i ⋅⇘n⇙ j)/(sqrt 2)^n" using assms (*‹i < dim_row (Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)))› ‹j < dim_col (Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)))›*) by simp lemma dim_row_of_iter_tensor_of_H [simp]: assumes "n ≥ 1" shows "1 < dim_row (H^⇩⊗ n)" using assms (*‹1 ≤ n›*) by (metis One_nat_def (*‹1 = Suc 0›*) Suc_1 (*‹Suc 1 = 2›*) dim_row_mat( (*‹dim_row (Matrix.mat ?nr ?nc ?f) = ?nr›*) 1) le_trans (*‹⟦?i ≤ ?j; ?j ≤ ?k⟧ ⟹ ?i ≤ ?k›*) lessI (*‹?n < Suc ?n›*) linorder_not_less (*‹(¬ ?x < ?y) = (?y ≤ ?x)›*) one_less_power (*‹⟦1 < ?a; 0 < ?n⟧ ⟹ 1 < ?a ^ ?n›*)) lemma iter_tensor_of_H_fst_pos: fixes n i j:: nat assumes "i < 2^n ∨ j < 2^n" and "i < 2^(n+1) ∧ j < 2^(n+1)" shows "(H^⇩⊗ (Suc n)) $$ (i,j) = 1/sqrt(2) * ((H^⇩⊗ n) $$ (i mod 2^n, j mod 2^n))" proof (-) (*goal: ‹Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n)) $$ (i, j) = complex_of_real (1 / sqrt 2) * Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) $$ (i mod 2 ^ n, j mod 2 ^ n)›*) have "(H^⇩⊗ (Suc n)) $$ (i,j) = (-1)^(bip i (Suc n) j)/(sqrt 2)^(Suc n)" using assms (*‹i < 2 ^ n ∨ j < 2 ^ n› ‹(i::nat) < (2::nat) ^ ((n::nat) + (1::nat)) ∧ (j::nat) < (2::nat) ^ (n + (1::nat))›*) by simp moreover have "bip i (Suc n) j = bip (i mod 2^n) n (j mod 2^n)" using bitwise_inner_prod_fst_el_0 (*‹?i < 2 ^ ?n ∨ ?j < 2 ^ ?n ⟹ ?i ⋅⇘Suc ?n⇙ ?j = ?i mod 2 ^ ?n ⋅⇘?n⇙ ?j mod 2 ^ ?n›*) assms(1) (*‹i < 2 ^ n ∨ j < 2 ^ n›*) by simp ultimately show "?thesis" (*goal: ‹Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n)) $$ (i, j) = complex_of_real (1 / sqrt 2) * Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) $$ (i mod 2 ^ n, j mod 2 ^ n)›*) using bitwise_inner_prod_def (*‹?i ⋅⇘?n⇙ ?j = (∑k = 0..<?n. bin_rep ?n ?i ! k * bin_rep ?n ?j ! k)›*) by simp qed lemma iter_tensor_of_H_fst_neg: fixes n i j:: nat assumes "i ≥ 2^n ∧ j ≥ 2^n" and "i < 2^(n+1) ∧ j < 2^(n+1)" shows "(H^⇩⊗ (Suc n)) $$ (i,j) = -1/sqrt(2) * (H^⇩⊗ n) $$ (i mod 2^n, j mod 2^n)" proof (-) (*goal: ‹Matrix.mat ((2::nat) ^ Suc (n::nat)) ((2::nat) ^ Suc n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘Suc n⇙ j / sqrt (2::real) ^ Suc n)) $$ (i::nat, j::nat) = complex_of_real (- (1::real) / sqrt (2::real)) * Matrix.mat ((2::nat) ^ n) ((2::nat) ^ n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘n⇙ j / sqrt (2::real) ^ n)) $$ (i mod (2::nat) ^ n, j mod (2::nat) ^ n)›*) have "(H^⇩⊗ (Suc n)) $$ (i,j) = (-1)^(bip i (n+1) j)/(sqrt 2)^(n+1)" using assms(2) (*‹i < 2 ^ (n + 1) ∧ j < 2 ^ (n + 1)›*) by simp moreover have "bip i (n+1) j = 1 + bip (i mod 2^n) n (j mod 2^n)" using bitwise_inner_prod_fst_el_is_1 (*‹⟦2 ^ ?n ≤ ?i ∧ 2 ^ ?n ≤ ?j; ?i < 2 ^ (?n + 1) ∧ ?j < 2 ^ (?n + 1)⟧ ⟹ ?i ⋅⇘?n + 1⇙ ?j = 1 + ?i mod 2 ^ ?n ⋅⇘?n⇙ ?j mod 2 ^ ?n›*) assms (*‹2 ^ n ≤ i ∧ 2 ^ n ≤ j› ‹i < 2 ^ (n + 1) ∧ j < 2 ^ (n + 1)›*) by simp ultimately show "?thesis" (*goal: ‹Matrix.mat ((2::nat) ^ Suc (n::nat)) ((2::nat) ^ Suc n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘Suc n⇙ j / sqrt (2::real) ^ Suc n)) $$ (i::nat, j::nat) = complex_of_real (- (1::real) / sqrt (2::real)) * Matrix.mat ((2::nat) ^ n) ((2::nat) ^ n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘n⇙ j / sqrt (2::real) ^ n)) $$ (i mod (2::nat) ^ n, j mod (2::nat) ^ n)›*) by simp qed lemma H_tensor_iter_tensor_of_H: fixes n:: nat shows "(H ⨂ H^⇩⊗ n) = H^⇩⊗ (Suc n)" proof (standard) (*goals: 1. ‹⋀i j. ⟦i < dim_row (Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n))); j < dim_col (Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n)))⟧ ⟹ (H ⨂ Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n))) $$ (i, j) = Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n)) $$ (i, j)› 2. ‹dim_row (H ⨂ Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n))) = dim_row (Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n)))› 3. ‹dim_col (H ⨂ Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n))) = dim_col (Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n)))›*) fix i :: nat and j :: nat assume a0: "i < dim_row (H^⇩⊗ (Suc n))" and a1: "j < dim_col (H^⇩⊗ (Suc n))" (*‹(i::nat) < dim_row (Matrix.mat ((2::nat) ^ Suc (n::nat)) ((2::nat) ^ Suc n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘Suc n⇙ j / sqrt (2::real) ^ Suc n)))› ‹(j::nat) < dim_col (Matrix.mat ((2::nat) ^ Suc (n::nat)) ((2::nat) ^ Suc n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘Suc n⇙ j / sqrt (2::real) ^ Suc n)))›*) then have f0: "i ∈ {0..<2^(n+1)} ∧ j ∈ {0..<2^(n+1)}" by simp then have f1: "(H ⨂ H^⇩⊗ n) $$ (i,j) = H $$ (i div (dim_row (H^⇩⊗ n)),j div (dim_col (H^⇩⊗ n))) * (H^⇩⊗ n) $$ (i mod (dim_row (H^⇩⊗ n)),j mod (dim_col (H^⇩⊗ n)))" by (simp add: H_without_scalar_prod (*‹H = Matrix.mat 2 2 (λx. complex_of_real (case x of (i, j) ⇒ if i ≠ j then 1 / sqrt 2 else if i = 0 then 1 / sqrt 2 else - (1 / sqrt 2)))›*)) show "(H ⨂ H^⇩⊗ n) $$ (i,j) = (H^⇩⊗ (Suc n)) $$ (i,j)" proof (rule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹?P ∨ ?Q› 2. ‹?P ⟹ (H ⨂ Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n))) $$ (i, j) = Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n)) $$ (i, j)› 3. ‹?Q ⟹ (H ⨂ Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n))) $$ (i, j) = Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n)) $$ (i, j)›*) show "(i < 2^n ∨ j < 2^n) ∨ ¬(i < 2^n ∨ j < 2^n)" by auto next (*goals: 1. ‹i < 2 ^ n ∨ j < 2 ^ n ⟹ (H ⨂ Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n))) $$ (i, j) = Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n)) $$ (i, j)› 2. ‹¬ (i < 2 ^ n ∨ j < 2 ^ n) ⟹ (H ⨂ Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n))) $$ (i, j) = Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n)) $$ (i, j)›*) assume a2: "(i < 2^n ∨ j < 2^n)" (*‹(i::nat) < (2::nat) ^ (n::nat) ∨ (j::nat) < (2::nat) ^ n›*) then have "(H^⇩⊗ (Suc n)) $$ (i,j) = 1/sqrt(2) * ((H^⇩⊗ n) $$ (i mod 2^n, j mod 2^n))" using a0 (*‹(i::nat) < dim_row (Matrix.mat ((2::nat) ^ Suc (n::nat)) ((2::nat) ^ Suc n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘Suc n⇙ j / sqrt (2::real) ^ Suc n)))›*) a1 (*‹j < dim_col (Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n)))›*) f0 (*‹i ∈ {0..<2 ^ (n + 1)} ∧ j ∈ {0..<2 ^ (n + 1)}›*) iter_tensor_of_H_fst_pos (*‹⟦(?i::nat) < (2::nat) ^ (?n::nat) ∨ (?j::nat) < (2::nat) ^ ?n; ?i < (2::nat) ^ (?n + (1::nat)) ∧ ?j < (2::nat) ^ (?n + (1::nat))⟧ ⟹ Matrix.mat ((2::nat) ^ Suc ?n) ((2::nat) ^ Suc ?n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘Suc ?n⇙ j / sqrt (2::real) ^ Suc ?n)) $$ (?i, ?j) = complex_of_real ((1::real) / sqrt (2::real)) * Matrix.mat ((2::nat) ^ ?n) ((2::nat) ^ ?n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘?n⇙ j / sqrt (2::real) ^ ?n)) $$ (?i mod (2::nat) ^ ?n, ?j mod (2::nat) ^ ?n)›*) by (metis (mono_tags, lifting) atLeastLessThan_iff (*‹(?i ∈ {?l..<?u}) = (?l ≤ ?i ∧ ?i < ?u)›*)) moreover have "H $$ (i div (dim_row (H^⇩⊗ n)),j div (dim_col (H^⇩⊗ n))) = 1/sqrt 2" using a0 (*‹i < dim_row (Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n)))›*) a1 (*‹j < dim_col (Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n)))›*) f0 (*‹i ∈ {0..<2 ^ (n + 1)} ∧ j ∈ {0..<2 ^ (n + 1)}›*) H_without_scalar_prod (*‹H = Matrix.mat 2 2 (λx. complex_of_real (case x of (i, j) ⇒ if i ≠ j then 1 / sqrt 2 else if i = 0 then 1 / sqrt 2 else - (1 / sqrt 2)))›*) H_values (*‹⟦?i < dim_row H; ?j < dim_col H; ?i ≠ 1 ∨ ?j ≠ 1⟧ ⟹ H $$ (?i, ?j) = complex_of_real (1 / sqrt 2)›*) a2 (*‹i < 2 ^ n ∨ j < 2 ^ n›*) by (metis (no_types, lifting) dim_col_mat( (*‹dim_col (Matrix.mat (?nr::nat) (?nc::nat) (?f::nat × nat ⇒ ?'a)) = ?nc›*) 1) dim_row_mat( (*‹dim_row (Matrix.mat (?nr::nat) (?nc::nat) (?f::nat × nat ⇒ ?'a)) = ?nr›*) 1) div_less (*‹(?m::nat) < (?n::nat) ⟹ ?m div ?n = (0::nat)›*) le_eq_less_or_eq (*‹((?m::nat) ≤ (?n::nat)) = (?m < ?n ∨ ?m = ?n)›*) le_numeral_extra( (*‹¬ (1::?'a) ≤ (0::?'a)›*) 2) less_power_add_imp_div_less (*‹(?i::nat) < (2::nat) ^ ((?m::nat) + (?n::nat)) ⟹ ?i div (2::nat) ^ ?n < (2::nat) ^ ?m›*) plus_1_eq_Suc (*‹(+) (1::nat) = Suc›*) power_one_right (*‹(?a::?'a) ^ (1::nat) = ?a›*)) ultimately show "(H ⨂ H^⇩⊗ n) $$ (i,j) = (H^⇩⊗ (Suc n)) $$ (i,j)" using f1 (*‹(H ⨂ Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n))) $$ (i, j) = H $$ (i div dim_row (Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n))), j div dim_col (Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)))) * Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) $$ (i mod dim_row (Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n))), j mod dim_col (Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n))))›*) by simp next (*goal: ‹¬ (i < 2 ^ n ∨ j < 2 ^ n) ⟹ (H ⨂ Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n))) $$ (i, j) = Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n)) $$ (i, j)›*) assume a2: "¬(i < 2^n ∨ j < 2^n)" (*‹¬ ((i::nat) < (2::nat) ^ (n::nat) ∨ (j::nat) < (2::nat) ^ n)›*) then have "i ≥ 2^n ∧ j ≥ 2^n" by simp then have f2: "(H^⇩⊗ (Suc n)) $$ (i,j) = -1/sqrt(2) * ((H^⇩⊗ n) $$ (i mod 2^n, j mod 2^n))" using a0 (*‹i < dim_row (Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n)))›*) a1 (*‹j < dim_col (Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n)))›*) f0 (*‹i ∈ {0..<2 ^ (n + 1)} ∧ j ∈ {0..<2 ^ (n + 1)}›*) iter_tensor_of_H_fst_neg (*‹⟦(2::nat) ^ (?n::nat) ≤ (?i::nat) ∧ (2::nat) ^ ?n ≤ (?j::nat); ?i < (2::nat) ^ (?n + (1::nat)) ∧ ?j < (2::nat) ^ (?n + (1::nat))⟧ ⟹ Matrix.mat ((2::nat) ^ Suc ?n) ((2::nat) ^ Suc ?n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘Suc ?n⇙ j / sqrt (2::real) ^ Suc ?n)) $$ (?i, ?j) = complex_of_real (- (1::real) / sqrt (2::real)) * Matrix.mat ((2::nat) ^ ?n) ((2::nat) ^ ?n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘?n⇙ j / sqrt (2::real) ^ ?n)) $$ (?i mod (2::nat) ^ ?n, ?j mod (2::nat) ^ ?n)›*) by simp have "i div (dim_row (H^⇩⊗ n)) =1" and "j div (dim_row (H^⇩⊗ n)) = 1" using a2 (*‹¬ (i < 2 ^ n ∨ j < 2 ^ n)›*) a0 (*‹(i::nat) < dim_row (Matrix.mat ((2::nat) ^ Suc (n::nat)) ((2::nat) ^ Suc n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘Suc n⇙ j / sqrt (2::real) ^ Suc n)))›*) a1 (*‹j < dim_col (Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n)))›*) apply - (*goals: 1. ‹⟦¬ ((i::nat) < (2::nat) ^ (n::nat) ∨ (j::nat) < (2::nat) ^ n); i < dim_row (Matrix.mat ((2::nat) ^ Suc n) ((2::nat) ^ Suc n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘Suc n⇙ j / sqrt (2::real) ^ Suc n))); j < dim_col (Matrix.mat ((2::nat) ^ Suc n) ((2::nat) ^ Suc n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘Suc n⇙ j / sqrt (2::real) ^ Suc n)))⟧ ⟹ i div dim_row (Matrix.mat ((2::nat) ^ n) ((2::nat) ^ n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘n⇙ j / sqrt (2::real) ^ n))) = (1::nat)› 2. ‹⟦¬ ((i::nat) < (2::nat) ^ (n::nat) ∨ (j::nat) < (2::nat) ^ n); i < dim_row (Matrix.mat ((2::nat) ^ Suc n) ((2::nat) ^ Suc n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘Suc n⇙ j / sqrt (2::real) ^ Suc n))); j < dim_col (Matrix.mat ((2::nat) ^ Suc n) ((2::nat) ^ Suc n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘Suc n⇙ j / sqrt (2::real) ^ Suc n)))⟧ ⟹ j div dim_row (Matrix.mat ((2::nat) ^ n) ((2::nat) ^ n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘n⇙ j / sqrt (2::real) ^ n))) = (1::nat)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . then have "H $$ (i div (dim_row (H^⇩⊗ n)),j div (dim_col (H^⇩⊗ n))) = -1/sqrt 2" using a0 (*‹(i::nat) < dim_row (Matrix.mat ((2::nat) ^ Suc (n::nat)) ((2::nat) ^ Suc n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘Suc n⇙ j / sqrt (2::real) ^ Suc n)))›*) a1 (*‹j < dim_col (Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n)))›*) f0 (*‹i ∈ {0..<2 ^ (n + 1)} ∧ j ∈ {0..<2 ^ (n + 1)}›*) H_values_right_bottom[of "i div (dim_row (H^⇩⊗ n))" "j div (dim_col (H^⇩⊗ n))"] (*‹i div dim_row (Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n))) = 1 ∧ j div dim_col (Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n))) = 1 ⟹ H $$ (i div dim_row (Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n))), j div dim_col (Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)))) = complex_of_real (- 1 / sqrt 2)›*) a2 (*‹¬ (i < 2 ^ n ∨ j < 2 ^ n)›*) by fastforce then show "(H ⨂ H^⇩⊗ n) $$ (i,j) = (H^⇩⊗ (Suc n)) $$ (i,j)" using f1 (*‹(H ⨂ Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n))) $$ (i, j) = H $$ (i div dim_row (Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n))), j div dim_col (Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)))) * Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) $$ (i mod dim_row (Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n))), j mod dim_col (Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n))))›*) f2 (*‹Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n)) $$ (i, j) = complex_of_real (- 1 / sqrt 2) * Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) $$ (i mod 2 ^ n, j mod 2 ^ n)›*) by simp qed next (*goals: 1. ‹dim_row (H ⨂ Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n))) = dim_row (Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n)))› 2. ‹dim_col (H ⨂ Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n))) = dim_col (Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n)))›*) show "dim_row (H ⨂ H^⇩⊗ n) = dim_row (H^⇩⊗ (Suc n))" by (simp add: H_without_scalar_prod (*‹H = Matrix.mat 2 2 (λx. complex_of_real (case x of (i, j) ⇒ if i ≠ j then 1 / sqrt 2 else if i = 0 then 1 / sqrt 2 else - (1 / sqrt 2)))›*)) next (*goal: ‹dim_col (H ⨂ Matrix.mat ((2::nat) ^ (n::nat)) ((2::nat) ^ n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘n⇙ j / sqrt (2::real) ^ n))) = dim_col (Matrix.mat ((2::nat) ^ Suc n) ((2::nat) ^ Suc n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘Suc n⇙ j / sqrt (2::real) ^ Suc n)))›*) show "dim_col (H ⨂ H^⇩⊗ n) = dim_col (H^⇩⊗ (Suc n))" by (simp add: H_without_scalar_prod (*‹H = Matrix.mat 2 2 (λx. complex_of_real (case x of (i, j) ⇒ if i ≠ j then 1 / sqrt 2 else if i = 0 then 1 / sqrt 2 else - (1 / sqrt 2)))›*)) qed text ‹ We prove that @{term "H^⇩⊗ n"} is indeed the matrix representation of @{term "H ⊗⇗n⇖"}, the iterated tensor product of the Hadamard gate H. › lemma one_tensor_of_H_is_H: shows "(H^⇩⊗ 1) = H" proof (rule eq_matI (*‹⟦⋀i j. ⟦i < dim_row ?B; j < dim_col ?B⟧ ⟹ ?A $$ (i, j) = ?B $$ (i, j); dim_row ?A = dim_row ?B; dim_col ?A = dim_col ?B⟧ ⟹ ?A = ?B›*)) (*goals: 1. ‹⋀i j. ⟦i < dim_row H; j < dim_col H⟧ ⟹ Matrix.mat (2 ^ 1) (2 ^ 1) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘1⇙ j / sqrt 2 ^ 1)) $$ (i, j) = H $$ (i, j)› 2. ‹dim_row (Matrix.mat (2 ^ 1) (2 ^ 1) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘1⇙ j / sqrt 2 ^ 1))) = dim_row H› 3. ‹dim_col (Matrix.mat (2 ^ 1) (2 ^ 1) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘1⇙ j / sqrt 2 ^ 1))) = dim_col H›*) show "dim_row (H^⇩⊗ 1) = dim_row H" by (simp add: H_without_scalar_prod (*‹H = Matrix.mat 2 2 (λx. complex_of_real (case x of (i, j) ⇒ if i ≠ j then 1 / sqrt 2 else if i = 0 then 1 / sqrt 2 else - (1 / sqrt 2)))›*)) show "dim_col (H^⇩⊗ 1) = dim_col H" by (simp add: H_without_scalar_prod (*‹H = Matrix.mat (2::nat) (2::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if i ≠ j then (1::real) / sqrt (2::real) else if i = (0::nat) then (1::real) / sqrt (2::real) else - ((1::real) / sqrt (2::real))))›*)) next (*goal: ‹⋀(i::nat) j::nat. ⟦i < dim_row H; j < dim_col H⟧ ⟹ Matrix.mat ((2::nat) ^ (1::nat)) ((2::nat) ^ (1::nat)) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘1::nat⇙ j / sqrt (2::real) ^ (1::nat))) $$ (i, j) = H $$ (i, j)›*) fix i :: nat and j :: nat assume a0: "i < dim_row H" and a1: "j < dim_col H" (*‹(i::nat) < dim_row H› ‹(j::nat) < dim_col H›*) then show "(H^⇩⊗ 1) $$ (i,j) = H $$ (i,j)" proof (-) (*goal: ‹⟦i < dim_row H; j < dim_col H⟧ ⟹ Matrix.mat (2 ^ 1) (2 ^ 1) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘1⇙ j / sqrt 2 ^ 1)) $$ (i, j) = H $$ (i, j)›*) have "(H^⇩⊗ 1) $$ (0, 0) = 1/sqrt(2)" using bitwise_inner_prod_def (*‹?i ⋅⇘?n⇙ ?j = (∑k = 0..<?n. bin_rep ?n ?i ! k * bin_rep ?n ?j ! k)›*) bin_rep_def (*‹bin_rep ?n ?m = butlast (bin_rep_aux ?n ?m)›*) by simp moreover have "(H^⇩⊗ 1) $$ (0,1) = 1/sqrt(2)" using bitwise_inner_prod_def (*‹?i ⋅⇘?n⇙ ?j = (∑k = 0..<?n. bin_rep ?n ?i ! k * bin_rep ?n ?j ! k)›*) bin_rep_def (*‹bin_rep ?n ?m = butlast (bin_rep_aux ?n ?m)›*) by simp moreover have "(H^⇩⊗ 1) $$ (1,0) = 1/sqrt(2)" using bitwise_inner_prod_def (*‹?i::nat ⋅⇘?n::nat⇙ ?j::nat = (∑k::nat = 0::nat..<?n. bin_rep ?n ?i ! k * bin_rep ?n ?j ! k)›*) bin_rep_def (*‹bin_rep ?n ?m = butlast (bin_rep_aux ?n ?m)›*) by simp moreover have "(H^⇩⊗ 1) $$ (1,1) = -1/sqrt(2)" using bitwise_inner_prod_def (*‹?i ⋅⇘?n⇙ ?j = (∑k = 0..<?n. bin_rep ?n ?i ! k * bin_rep ?n ?j ! k)›*) bin_rep_def (*‹bin_rep (?n::nat) (?m::nat) = butlast (bin_rep_aux ?n ?m)›*) by simp ultimately show "(H^⇩⊗ 1) $$ (i,j) = H $$ (i,j)" using a0 (*‹i < dim_row H›*) a1 (*‹j < dim_col H›*) H_values (*‹⟦?i < dim_row H; ?j < dim_col H; ?i ≠ 1 ∨ ?j ≠ 1⟧ ⟹ H $$ (?i, ?j) = complex_of_real (1 / sqrt 2)›*) H_values_right_bottom (*‹?i = 1 ∧ ?j = 1 ⟹ H $$ (?i, ?j) = complex_of_real (- 1 / sqrt 2)›*) by (metis (no_types, lifting) H_without_scalar_prod (*‹H = Matrix.mat 2 2 (λx. complex_of_real (case x of (i, j) ⇒ if i ≠ j then 1 / sqrt 2 else if i = 0 then 1 / sqrt 2 else - (1 / sqrt 2)))›*) One_nat_def (*‹1 = Suc 0›*) dim_col_mat( (*‹dim_col (Matrix.mat ?nr ?nc ?f) = ?nc›*) 1) dim_row_mat( (*‹dim_row (Matrix.mat ?nr ?nc ?f) = ?nr›*) 1) divide_minus_left (*‹- ?a / ?b = - (?a / ?b)›*) less_2_cases (*‹?n < 2 ⟹ ?n = 0 ∨ ?n = Suc 0›*)) qed qed lemma iter_tensor_of_H_rep_is_correct: fixes n:: nat assumes "n ≥ 1" shows "(H ⊗⇗n⇖) = H^⇩⊗ n" using assms (*‹1 ≤ n›*) proof (rule nat_induct_at_least (*‹⟦(?m::nat) ≤ (?n::nat); (?P::nat ⇒ bool) ?m; ⋀n::nat. ⟦?m ≤ n; ?P n⟧ ⟹ ?P (Suc n)⟧ ⟹ ?P ?n›*)) (*goals: 1. ‹H ⊗⇗1::nat⇖ = Matrix.mat ((2::nat) ^ (1::nat)) ((2::nat) ^ (1::nat)) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘1::nat⇙ j / sqrt (2::real) ^ (1::nat)))› 2. ‹⋀n::nat. ⟦(1::nat) ≤ n; H ⊗⇗n⇖ = Matrix.mat ((2::nat) ^ n) ((2::nat) ^ n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘n⇙ j / sqrt (2::real) ^ n))⟧ ⟹ H ⊗⇗Suc n⇖ = Matrix.mat ((2::nat) ^ Suc n) ((2::nat) ^ Suc n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘Suc n⇙ j / sqrt (2::real) ^ Suc n))›*) show "(H ⊗⇗1⇖) = H^⇩⊗ 1" using one_tensor_is_id (*‹?A ⊗⇗1⇖ = ?A›*) one_tensor_of_H_is_H (*‹Matrix.mat (2 ^ 1) (2 ^ 1) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘1⇙ j / sqrt 2 ^ 1)) = H›*) by simp next (*goal: ‹⋀n. ⟦1 ≤ n; H ⊗⇗n⇖ = Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n))⟧ ⟹ H ⊗⇗Suc n⇖ = Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n))›*) fix n :: nat assume a0: "n ≥ 1" and IH: "(H ⊗⇗n⇖) = H^⇩⊗ n" (*‹(1::nat) ≤ (n::nat)› ‹H ⊗⇗n::nat⇖ = Matrix.mat ((2::nat) ^ n) ((2::nat) ^ n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘n⇙ j / sqrt (2::real) ^ n))›*) then have "(H ⊗⇗(Suc n)⇖) = H ⨂ (H ⊗⇗n⇖)" using iter_tensor_suc (*‹1 ≤ ?n ⟹ ?A ⊗⇗Suc ?n⇖ = ?A ⨂ ?A ⊗⇗?n⇖›*) Nat.Suc_eq_plus1 (*‹Suc ?n = ?n + 1›*) by metis also (*calculation: ‹H ⊗⇗Suc n⇖ = H ⨂ H ⊗⇗n⇖›*) have "... = H ⨂ (H^⇩⊗ n)" using IH (*‹H ⊗⇗n::nat⇖ = Matrix.mat ((2::nat) ^ n) ((2::nat) ^ n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘n⇙ j / sqrt (2::real) ^ n))›*) by simp also (*calculation: ‹H ⊗⇗Suc (n::nat)⇖ = H ⨂ Matrix.mat ((2::nat) ^ n) ((2::nat) ^ n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘n⇙ j / sqrt (2::real) ^ n))›*) have "... = H^⇩⊗ (Suc n)" using a0 (*‹1 ≤ n›*) H_tensor_iter_tensor_of_H (*‹H ⨂ Matrix.mat (2 ^ ?n) (2 ^ ?n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘?n⇙ j / sqrt 2 ^ ?n)) = Matrix.mat (2 ^ Suc ?n) (2 ^ Suc ?n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc ?n⇙ j / sqrt 2 ^ Suc ?n))›*) by simp finally (*calculation: ‹H ⊗⇗Suc n⇖ = Matrix.mat (2 ^ Suc n) (2 ^ Suc n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘Suc n⇙ j / sqrt 2 ^ Suc n))›*) show "(H ⊗⇗(Suc n)⇖) = H^⇩⊗ (Suc n)" by simp qed text ‹@{text "HId^⇩⊗ 1"} is the result of taking the tensor product of the nth tensor of H and Id 1 › abbreviation tensor_of_H_tensor_Id:: "nat ⇒ complex Matrix.mat" ("HId^⇩⊗ _") where "tensor_of_H_tensor_Id n ≡ Matrix.mat (2^(n+1)) (2^(n+1)) (λ(i,j). if (i mod 2 = j mod 2) then (-1)^((i div 2) ⋅⇘n⇙ (j div 2))/(sqrt 2)^n else 0)" lemma mod_2_is_both_even_or_odd: "((even i ∧ even j) ∨ (odd i ∧ odd j)) ⟷ (i mod 2 = j mod 2)" by (metis even_iff_mod_2_eq_zero (*‹even ?a = (?a mod 2 = 0)›*) odd_iff_mod_2_eq_one (*‹odd ?a = (?a mod 2 = 1)›*)) lemma HId_values [simp]: assumes "n ≥ 1" and "i < dim_row (HId^⇩⊗ n)" and "j < dim_col (HId^⇩⊗ n)" shows "even i ∧ even j ⟶ (HId^⇩⊗ n) $$ (i,j) = (-1)^((i div 2) ⋅⇘n⇙ (j div 2))/(sqrt 2)^n" and "odd i ∧ odd j ⟶ (HId^⇩⊗ n) $$ (i,j) = (-1)^((i div 2) ⋅⇘n⇙ (j div 2))/(sqrt 2)^n" and "(i mod 2 = j mod 2) ⟶ (HId^⇩⊗ n) $$ (i,j) = (-1)^((i div 2) ⋅⇘n⇙ (j div 2))/(sqrt 2)^n" and "¬(i mod 2 = j mod 2) ⟶ (HId^⇩⊗ n) $$ (i,j) = 0" using assms (*‹(1::nat) ≤ (n::nat)› ‹i < dim_row (Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0)))› ‹j < dim_col (Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0)))›*) mod_2_is_both_even_or_odd (*‹(even (?i::?'a::semiring_parity) ∧ even (?j::?'a::semiring_parity) ∨ odd ?i ∧ odd ?j) = (?i mod (2::?'a::semiring_parity) = ?j mod (2::?'a::semiring_parity))›*) apply - (*goals: 1. ‹⟦1 ≤ n; i < dim_row (Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0))); j < dim_col (Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0))); ⋀i j. (even i ∧ even j ∨ odd i ∧ odd j) = (i mod 2 = j mod 2)⟧ ⟹ even i ∧ even j ⟶ Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0)) $$ (i, j) = complex_of_real ((- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n)› 2. ‹⟦1 ≤ n; i < dim_row (Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0))); j < dim_col (Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0))); ⋀i j. (even i ∧ even j ∨ odd i ∧ odd j) = (i mod 2 = j mod 2)⟧ ⟹ odd i ∧ odd j ⟶ Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0)) $$ (i, j) = complex_of_real ((- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n)› 3. ‹⟦1 ≤ n; i < dim_row (Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0))); j < dim_col (Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0))); ⋀i j. (even i ∧ even j ∨ odd i ∧ odd j) = (i mod 2 = j mod 2)⟧ ⟹ i mod 2 = j mod 2 ⟶ Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0)) $$ (i, j) = complex_of_real ((- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n)› 4. ‹⟦1 ≤ n; i < dim_row (Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0))); j < dim_col (Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0))); ⋀i j. (even i ∧ even j ∨ odd i ∧ odd j) = (i mod 2 = j mod 2)⟧ ⟹ i mod 2 ≠ j mod 2 ⟶ Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0)) $$ (i, j) = 0› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*discuss goal 4*) apply ((auto)[1]) (*proven 4 subgoals*) . lemma iter_tensor_of_H_tensor_Id_is_HId: shows "(H^⇩⊗ n) ⨂ Id 1 = HId^⇩⊗ n" proof (standard) (*goals: 1. ‹⋀i j. ⟦i < dim_row (Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0))); j < dim_col (Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0)))⟧ ⟹ (Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) ⨂ Quantum.Id 1) $$ (i, j) = Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0)) $$ (i, j)› 2. ‹dim_row (Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) ⨂ Quantum.Id 1) = dim_row (Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0)))› 3. ‹dim_col (Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) ⨂ Quantum.Id 1) = dim_col (Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0)))›*) show "dim_row ((H^⇩⊗ n) ⨂ Id 1) = dim_row (HId^⇩⊗ n)" by (simp add: Quantum.Id_def (*‹Quantum.Id (?n::nat) ≡ 1⇩m ((2::nat) ^ ?n)›*)) show "dim_col ((H^⇩⊗ n) ⨂ Id 1) = dim_col (HId^⇩⊗ n)" by (simp add: Quantum.Id_def (*‹Quantum.Id (?n::nat) ≡ 1⇩m ((2::nat) ^ ?n)›*)) next (*goal: ‹⋀(i::nat) j::nat. ⟦i < dim_row (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) ((2::nat) ^ (n + (1::nat))) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if i mod (2::nat) = j mod (2::nat) then (- (1::real)) ^ i div (2::nat) ⋅⇘n⇙ j div (2::nat) / sqrt (2::real) ^ n else (0::real)))); j < dim_col (Matrix.mat ((2::nat) ^ (n + (1::nat))) ((2::nat) ^ (n + (1::nat))) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if i mod (2::nat) = j mod (2::nat) then (- (1::real)) ^ i div (2::nat) ⋅⇘n⇙ j div (2::nat) / sqrt (2::real) ^ n else (0::real))))⟧ ⟹ (Matrix.mat ((2::nat) ^ n) ((2::nat) ^ n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘n⇙ j / sqrt (2::real) ^ n)) ⨂ Quantum.Id (1::nat)) $$ (i, j) = Matrix.mat ((2::nat) ^ (n + (1::nat))) ((2::nat) ^ (n + (1::nat))) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if i mod (2::nat) = j mod (2::nat) then (- (1::real)) ^ i div (2::nat) ⋅⇘n⇙ j div (2::nat) / sqrt (2::real) ^ n else (0::real))) $$ (i, j)›*) fix i :: nat and j :: nat assume a0: "i < dim_row (HId^⇩⊗ n)" and a1: "j < dim_col (HId^⇩⊗ n)" (*‹(i::nat) < dim_row (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) ((2::nat) ^ (n + (1::nat))) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if i mod (2::nat) = j mod (2::nat) then (- (1::real)) ^ i div (2::nat) ⋅⇘n⇙ j div (2::nat) / sqrt (2::real) ^ n else (0::real))))› ‹(j::nat) < dim_col (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) ((2::nat) ^ (n + (1::nat))) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if i mod (2::nat) = j mod (2::nat) then (- (1::real)) ^ i div (2::nat) ⋅⇘n⇙ j div (2::nat) / sqrt (2::real) ^ n else (0::real))))›*) then have f0: "i < (2^(n+1)) ∧ j < (2^(n+1))" by simp then have "i < dim_row (H^⇩⊗ n) * dim_row (Id 1) ∧ j < dim_col (H^⇩⊗ n) * dim_col (Id 1)" using Id_def (*‹Quantum.Id ?n ≡ 1⇩m (2 ^ ?n)›*) by simp moreover have "dim_col (H^⇩⊗ n) ≥ 0 ∧ dim_col (Id 1) ≥ 0" using Id_def (*‹Quantum.Id ?n ≡ 1⇩m (2 ^ ?n)›*) by simp ultimately have f1: "((H^⇩⊗ n) ⨂ (Id 1)) $$ (i,j) = (H^⇩⊗ n) $$ (i div (dim_row (Id 1)),j div (dim_col (Id 1))) * (Id 1) $$ (i mod (dim_row (Id 1)),j mod (dim_col (Id 1)))" by (simp add: Quantum.Id_def (*‹Quantum.Id (?n::nat) ≡ 1⇩m ((2::nat) ^ ?n)›*)) show "((H^⇩⊗ n)⨂Id 1) $$ (i,j) = (HId^⇩⊗ n) $$ (i,j)" proof (rule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹?P ∨ ?Q› 2. ‹?P ⟹ (Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) ⨂ Quantum.Id 1) $$ (i, j) = Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0)) $$ (i, j)› 3. ‹?Q ⟹ (Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) ⨂ Quantum.Id 1) $$ (i, j) = Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0)) $$ (i, j)›*) show "(i mod 2 = j mod 2) ∨ ¬ (i mod 2 = j mod 2)" by simp next (*goals: 1. ‹(i::nat) mod (2::nat) = (j::nat) mod (2::nat) ⟹ (Matrix.mat ((2::nat) ^ (n::nat)) ((2::nat) ^ n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘n⇙ j / sqrt (2::real) ^ n)) ⨂ Quantum.Id (1::nat)) $$ (i, j) = Matrix.mat ((2::nat) ^ (n + (1::nat))) ((2::nat) ^ (n + (1::nat))) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if i mod (2::nat) = j mod (2::nat) then (- (1::real)) ^ i div (2::nat) ⋅⇘n⇙ j div (2::nat) / sqrt (2::real) ^ n else (0::real))) $$ (i, j)› 2. ‹(i::nat) mod (2::nat) ≠ (j::nat) mod (2::nat) ⟹ (Matrix.mat ((2::nat) ^ (n::nat)) ((2::nat) ^ n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘n⇙ j / sqrt (2::real) ^ n)) ⨂ Quantum.Id (1::nat)) $$ (i, j) = Matrix.mat ((2::nat) ^ (n + (1::nat))) ((2::nat) ^ (n + (1::nat))) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if i mod (2::nat) = j mod (2::nat) then (- (1::real)) ^ i div (2::nat) ⋅⇘n⇙ j div (2::nat) / sqrt (2::real) ^ n else (0::real))) $$ (i, j)›*) assume a2: "(i mod 2 = j mod 2)" (*‹(i::nat) mod (2::nat) = (j::nat) mod (2::nat)›*) then have "(Id 1) $$ (i mod (dim_row (Id 1)),j mod (dim_col (Id 1))) = 1" by (simp add: Quantum.Id_def (*‹Quantum.Id ?n ≡ 1⇩m (2 ^ ?n)›*)) moreover have "(H^⇩⊗ n) $$ (i div (dim_row (Id 1)), j div (dim_col (Id 1))) = (-1)^((i div (dim_row (Id 1))) ⋅⇘n⇙ (j div (dim_col (Id 1))))/(sqrt 2)^n" using tensor_of_H_values (*‹⟦(?i::nat) < dim_row (Matrix.mat ((2::nat) ^ (?n::nat)) ((2::nat) ^ ?n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘?n⇙ j / sqrt (2::real) ^ ?n))); (?j::nat) < dim_col (Matrix.mat ((2::nat) ^ ?n) ((2::nat) ^ ?n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘?n⇙ j / sqrt (2::real) ^ ?n)))⟧ ⟹ Matrix.mat ((2::nat) ^ ?n) ((2::nat) ^ ?n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘?n⇙ j / sqrt (2::real) ^ ?n)) $$ (?i, ?j) = complex_of_real ((- (1::real)) ^ ?i ⋅⇘?n⇙ ?j / sqrt (2::real) ^ ?n)›*) Id_def (*‹Quantum.Id ?n ≡ 1⇩m (2 ^ ?n)›*) f0 (*‹i < 2 ^ (n + 1) ∧ j < 2 ^ (n + 1)›*) less_mult_imp_div_less (*‹?m < ?i * ?n ⟹ ?m div ?n < ?i›*) by simp ultimately show "((H^⇩⊗ n) ⨂ Id 1) $$ (i,j) = (HId^⇩⊗ n) $$ (i,j)" using a2 (*‹i mod 2 = j mod 2›*) f0 (*‹i < 2 ^ (n + 1) ∧ j < 2 ^ (n + 1)›*) f1 (*‹(Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) ⨂ Quantum.Id 1) $$ (i, j) = Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) $$ (i div dim_row (Quantum.Id 1), j div dim_col (Quantum.Id 1)) * Quantum.Id 1 $$ (i mod dim_row (Quantum.Id 1), j mod dim_col (Quantum.Id 1))›*) Id_def (*‹Quantum.Id (?n::nat) ≡ 1⇩m ((2::nat) ^ ?n)›*) by simp next (*goal: ‹i mod 2 ≠ j mod 2 ⟹ (Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) ⨂ Quantum.Id 1) $$ (i, j) = Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0)) $$ (i, j)›*) assume a2: "¬(i mod 2 = j mod 2)" (*‹(i::nat) mod (2::nat) ≠ (j::nat) mod (2::nat)›*) then have "(Id 1) $$ (i mod (dim_row (Id 1)),j mod (dim_col (Id 1))) = 0" by (simp add: Quantum.Id_def (*‹Quantum.Id ?n ≡ 1⇩m (2 ^ ?n)›*)) then show "((H^⇩⊗ n) ⨂ Id 1) $$ (i,j) = (HId^⇩⊗ n) $$ (i,j)" using a2 (*‹i mod 2 ≠ j mod 2›*) f0 (*‹i < 2 ^ (n + 1) ∧ j < 2 ^ (n + 1)›*) f1 (*‹(Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) ⨂ Quantum.Id 1) $$ (i, j) = Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) $$ (i div dim_row (Quantum.Id 1), j div dim_col (Quantum.Id 1)) * Quantum.Id 1 $$ (i mod dim_row (Quantum.Id 1), j mod dim_col (Quantum.Id 1))›*) by simp qed qed lemma HId_is_gate: assumes "n ≥ 1" shows "gate (n+1) (HId^⇩⊗ n)" proof (-) (*goal: ‹gate (n + 1) (Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0)))›*) have "(HId^⇩⊗ n) = (H^⇩⊗ n) ⨂ Id 1" using iter_tensor_of_H_tensor_Id_is_HId (*‹Matrix.mat ((2::nat) ^ (?n::nat)) ((2::nat) ^ ?n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘?n⇙ j / sqrt (2::real) ^ ?n)) ⨂ Quantum.Id (1::nat) = Matrix.mat ((2::nat) ^ (?n + (1::nat))) ((2::nat) ^ (?n + (1::nat))) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if i mod (2::nat) = j mod (2::nat) then (- (1::real)) ^ i div (2::nat) ⋅⇘?n⇙ j div (2::nat) / sqrt (2::real) ^ ?n else (0::real)))›*) by simp moreover have "gate 1 (Id 1)" using id_is_gate (*‹gate (?n::nat) (Quantum.Id ?n)›*) by simp moreover have "gate n (H^⇩⊗ n)" using H_is_gate (*‹gate 1 H›*) iter_tensor_of_gate_is_gate[of 1 H n] (*‹⟦gate 1 H; 1 ≤ n⟧ ⟹ gate (1 * n) (H ⊗⇗n⇖)›*) assms (*‹1 ≤ n›*) by (simp add: iter_tensor_of_H_rep_is_correct (*‹1 ≤ ?n ⟹ H ⊗⇗?n⇖ = Matrix.mat (2 ^ ?n) (2 ^ ?n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘?n⇙ j / sqrt 2 ^ ?n))›*)) ultimately show "gate (n+1) (HId^⇩⊗ n)" using tensor_gate (*‹⟦gate ?m ?G1.0; gate ?n ?G2.0⟧ ⟹ gate (?m + ?n) (?G1.0 ⨂ ?G2.0)›*) by presburger qed text ‹State @{term "ψ₃"} is obtained by the multiplication of @{term "HId^⇩⊗ n"} and @{term "ψ₂"}› abbreviation (in jozsa) ψ₃:: "complex Matrix.mat" where "ψ₃ ≡ Matrix.mat (2^(n+1)) 1 (λ(i,j). if even i then (∑k<2^n. (-1)^(f(k) + ((i div 2) ⋅⇘n⇙ k))/((sqrt 2)^n * (sqrt 2)^(n+1))) else (∑k<2^n. (-1)^(f(k)+ 1 + ((i div 2) ⋅⇘n⇙ k)) /((sqrt 2)^n * (sqrt 2)^(n+1))))" lemma (in jozsa) ψ₃_values: assumes "i < dim_row ψ₃" shows "odd i ⟶ ψ₃ $$ (i,0) = (∑k<2^n. (-1)^(f(k) + 1 + ((i div 2) ⋅⇘n⇙ k))/((sqrt 2)^n * (sqrt 2)^(n+1)))" using assms (*‹(i::nat) < dim_row (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ ((f::nat ⇒ nat) k + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))) else ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ (f k + (1::nat) + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))))))›*) by simp lemma (in jozsa) ψ₃_dim [simp]: shows "1 < dim_row ψ₃" using dim_row_mat(1) (*‹dim_row (Matrix.mat ?nr ?nc ?f) = ?nr›*) nat_neq_iff (*‹(?m ≠ ?n) = (?m < ?n ∨ ?n < ?m)›*) by fastforce lemma sum_every_odd_summand_is_zero: fixes n:: nat assumes "n ≥ 1" shows "∀f::(nat ⇒ complex).(∀i. i<2^(n+1) ∧ odd i ⟶ f i = 0) ⟶ (∑k∈{0..<2^(n+1)}. f k) = (∑k∈{0..<2^n}. f (2*k))" using assms (*‹1 ≤ n›*) proof (rule nat_induct_at_least (*‹⟦?m ≤ ?n; ?P ?m; ⋀n. ⟦?m ≤ n; ?P n⟧ ⟹ ?P (Suc n)⟧ ⟹ ?P ?n›*)) (*goals: 1. ‹∀f. (∀i. i < 2 ^ (1 + 1) ∧ odd i ⟶ f i = 0) ⟶ sum f {0..<2 ^ (1 + 1)} = (∑k = 0..<2 ^ 1. f (2 * k))› 2. ‹⋀n. ⟦1 ≤ n; ∀f. (∀i. i < 2 ^ (n + 1) ∧ odd i ⟶ f i = 0) ⟶ sum f {0..<2 ^ (n + 1)} = (∑k = 0..<2 ^ n. f (2 * k))⟧ ⟹ ∀f. (∀i. i < 2 ^ (Suc n + 1) ∧ odd i ⟶ f i = 0) ⟶ sum f {0..<2 ^ (Suc n + 1)} = (∑k = 0..<2 ^ Suc n. f (2 * k))›*) show "∀f::(nat ⇒ complex).(∀i. i<2^(1+1) ∧ odd i ⟶ f i = 0) ⟶ (∑k∈{0..<2^(1+1)}. f k) = (∑k ∈ {0..<2^1}. f (2*k))" apply (rule allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*)) (*goal: ‹∀f. (∀i. i < 2 ^ (1 + 1) ∧ odd i ⟶ f i = 0) ⟶ sum f {0..<2 ^ (1 + 1)} = (∑k = 0..<2 ^ 1. f (2 * k))›*) proof (rule impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goal: ‹⋀f. ∀i. i < 2 ^ (1 + 1) ∧ odd i ⟶ f i = 0 ⟹ sum f {0..<2 ^ (1 + 1)} = (∑k = 0..<2 ^ 1. f (2 * k))›*) fix f :: "(nat ⇒ complex)" assume asm: "(∀i. i<2^(1+1) ∧ odd i ⟶ f i = 0)" (*‹∀i::nat. i < (2::nat) ^ ((1::nat) + (1::nat)) ∧ odd i ⟶ (f::nat ⇒ complex) i = (0::complex)›*) moreover have "(∑k∈{0..<4}. f k) = f 0 + f 1 + f 2 + f 3" by (simp add: add.commute (*‹?a + ?b = ?b + ?a›*) add.left_commute (*‹?b + (?a + ?c) = ?a + (?b + ?c)›*)) moreover have "f 1 = 0" using asm (*‹∀i::nat. i < (2::nat) ^ ((1::nat) + (1::nat)) ∧ odd i ⟶ (f::nat ⇒ complex) i = (0::complex)›*) by simp moreover have "f 3 = 0" using asm (*‹∀i::nat. i < (2::nat) ^ ((1::nat) + (1::nat)) ∧ odd i ⟶ (f::nat ⇒ complex) i = (0::complex)›*) by simp moreover have "(∑k∈{0..<2^1}. f (2*k)) = f 0 + f 2" using add.commute (*‹?a + ?b = ?b + ?a›*) add.left_commute (*‹?b + (?a + ?c) = ?a + (?b + ?c)›*) by simp ultimately show "(∑k∈{0..<2^(1+1)}. f k) = (∑k∈{0..<2^1}. f (2*k))" by simp qed next (*goal: ‹⋀n::nat. ⟦(1::nat) ≤ n; ∀f::nat ⇒ complex. (∀i::nat. i < (2::nat) ^ (n + (1::nat)) ∧ odd i ⟶ f i = (0::complex)) ⟶ sum f {0::nat..<(2::nat) ^ (n + (1::nat))} = (∑k::nat = 0::nat..<(2::nat) ^ n. f ((2::nat) * k))⟧ ⟹ ∀f::nat ⇒ complex. (∀i::nat. i < (2::nat) ^ (Suc n + (1::nat)) ∧ odd i ⟶ f i = (0::complex)) ⟶ sum f {0::nat..<(2::nat) ^ (Suc n + (1::nat))} = (∑k::nat = 0::nat..<(2::nat) ^ Suc n. f ((2::nat) * k))›*) fix n :: nat assume "n ≥ 1" and IH: "∀f::(nat ⇒complex).(∀i. i<2^(n+1) ∧ odd i ⟶ f i = 0) ⟶ (∑k∈{0..<2^(n+1)}. f k) = (∑k∈{0..<2^n}. f (2*k))" (*‹(1::nat) ≤ (n::nat)› ‹∀f::nat ⇒ complex. (∀i::nat. i < (2::nat) ^ ((n::nat) + (1::nat)) ∧ odd i ⟶ f i = (0::complex)) ⟶ sum f {0::nat..<(2::nat) ^ (n + (1::nat))} = (∑k::nat = 0::nat..<(2::nat) ^ n. f ((2::nat) * k))›*) show "∀f::(nat ⇒complex).(∀i. i<2^(Suc n +1) ∧ odd i ⟶ f i = 0) ⟶ (∑k∈{0..<2^(Suc n +1)}. f k) = (∑k∈{0..< 2^(Suc n)}. f (2*k))" apply (rule allI (*‹(⋀x::?'a. (?P::?'a ⇒ bool) x) ⟹ ∀x::?'a. ?P x›*)) (*goal: ‹∀f::nat ⇒ complex. (∀i::nat. i < (2::nat) ^ (Suc (n::nat) + (1::nat)) ∧ odd i ⟶ f i = (0::complex)) ⟶ sum f {0::nat..<(2::nat) ^ (Suc n + (1::nat))} = (∑k::nat = 0::nat..<(2::nat) ^ Suc n. f ((2::nat) * k))›*) proof (rule impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goal: ‹⋀f. ∀i. i < 2 ^ (Suc n + 1) ∧ odd i ⟶ f i = 0 ⟹ sum f {0..<2 ^ (Suc n + 1)} = (∑k = 0..<2 ^ Suc n. f (2 * k))›*) fix f :: "nat ⇒ complex" assume asm: "(∀i. i<2^(Suc n +1) ∧ odd i ⟶ f i = 0)" (*‹∀i::nat. i < (2::nat) ^ (Suc (n::nat) + (1::nat)) ∧ odd i ⟶ (f::nat ⇒ complex) i = (0::complex)›*) have f0: "(∑k∈{0..<2^(n+1)}. f k) = (∑k∈{0..<2^n}. f (2*k))" using asm (*‹∀i. i < 2 ^ (Suc n + 1) ∧ odd i ⟶ f i = 0›*) IH (*‹∀f. (∀i. i < 2 ^ (n + 1) ∧ odd i ⟶ f i = 0) ⟶ sum f {0..<2 ^ (n + 1)} = (∑k = 0..<2 ^ n. f (2 * k))›*) by simp have f1: "(∑k∈{0..<2^(n+1)}. (λx. f (x+2^(n+1))) k) = (∑k∈{0..< 2^n}. (λx. f (x+2^(n+1))) (2*k))" using asm (*‹∀i::nat. i < (2::nat) ^ (Suc (n::nat) + (1::nat)) ∧ odd i ⟶ (f::nat ⇒ complex) i = (0::complex)›*) IH (*‹∀f. (∀i. i < 2 ^ (n + 1) ∧ odd i ⟶ f i = 0) ⟶ sum f {0..<2 ^ (n + 1)} = (∑k = 0..<2 ^ n. f (2 * k))›*) by simp have "(∑k∈{0..<2^(n+2)}. f k) = (∑k∈{0..<2^(n+1)}. f k) + (∑k∈{2^(n+1)..<2^(n+2)}. f k)" by (simp add: sum.atLeastLessThan_concat (*‹⟦?m ≤ ?n; ?n ≤ ?p⟧ ⟹ sum ?g {?m..<?n} + sum ?g {?n..<?p} = sum ?g {?m..<?p}›*)) also (*calculation: ‹sum (f::nat ⇒ complex) {0::nat..<(2::nat) ^ ((n::nat) + (2::nat))} = sum f {0::nat..<(2::nat) ^ (n + (1::nat))} + sum f {(2::nat) ^ (n + (1::nat))..<(2::nat) ^ (n + (2::nat))}›*) have "... = (∑k∈{0..<2^n}. f (2*k)) + (∑k∈{2^(n+1)..<2^(n+2)}. f k)" using f0 (*‹sum f {0..<2 ^ (n + 1)} = (∑k = 0..<2 ^ n. f (2 * k))›*) by simp also (*calculation: ‹sum f {0..<2 ^ (n + 2)} = (∑k = 0..<2 ^ n. f (2 * k)) + sum f {2 ^ (n + 1)..<2 ^ (n + 2)}›*) have "... = (∑k∈{0..<2^n}. f (2*k)) + (∑k∈{0..<2^(n+1)}. f (k+2^(n+1)))" using sum.shift_bounds_nat_ivl[of "f" "0" "2^(n+1)" "2^(n+1)"] (*‹sum f {0 + 2 ^ (n + 1)..<2 ^ (n + 1) + 2 ^ (n + 1)} = (∑i = 0..<2 ^ (n + 1). f (i + 2 ^ (n + 1)))›*) by simp also (*calculation: ‹sum f {0..<2 ^ (n + 2)} = (∑k = 0..<2 ^ n. f (2 * k)) + (∑k = 0..<2 ^ (n + 1). f (k + 2 ^ (n + 1)))›*) have "... = (∑k∈{0..<2^n}. f (2*k)) + (∑k∈{0..< 2^n}. (λx. f (x+2^(n+1))) (2*k))" using f1 (*‹(∑k::nat = 0::nat..<(2::nat) ^ (n + (1::nat)). (f::nat ⇒ complex) (k + (2::nat) ^ ((n::nat) + (1::nat)))) = (∑k::nat = 0::nat..<(2::nat) ^ n. f ((2::nat) * k + (2::nat) ^ (n + (1::nat))))›*) by simp also (*calculation: ‹sum (f::nat ⇒ complex) {0::nat..<(2::nat) ^ ((n::nat) + (2::nat))} = (∑k::nat = 0::nat..<(2::nat) ^ n. f ((2::nat) * k)) + (∑k::nat = 0::nat..<(2::nat) ^ n. f ((2::nat) * k + (2::nat) ^ (n + (1::nat))))›*) have "... = (∑k∈{0..<2^n}. f (2*k)) + (∑k∈{2^n..< 2^(n+1)}. f (2 *k))" using sum.shift_bounds_nat_ivl[of "λx. (f::nat⇒complex) (2*(x-2^n)+2^(n+1))" "0" "2^n" "2^n"] (*‹(∑x = 0 + 2 ^ n..<2 ^ n + 2 ^ n. f (2 * (x - 2 ^ n) + 2 ^ (n + 1))) = (∑i = 0..<2 ^ n. f (2 * (i + 2 ^ n - 2 ^ n) + 2 ^ (n + 1)))›*) by (simp add: mult_2 (*‹2 * ?z = ?z + ?z›*)) also (*calculation: ‹sum f {0..<2 ^ (n + 2)} = (∑k = 0..<2 ^ n. f (2 * k)) + (∑k = 2 ^ n..<2 ^ (n + 1). f (2 * k))›*) have "... = (∑k ∈ {0..<2^(n+1)}. f (2*k))" by (metis Suc_eq_plus1 (*‹Suc ?n = ?n + 1›*) lessI (*‹?n < Suc ?n›*) less_imp_le_nat (*‹?m < ?n ⟹ ?m ≤ ?n›*) one_le_numeral (*‹1 ≤ numeral ?n›*) power_increasing (*‹⟦?n ≤ ?N; 1 ≤ ?a⟧ ⟹ ?a ^ ?n ≤ ?a ^ ?N›*) sum.atLeastLessThan_concat (*‹⟦?m ≤ ?n; ?n ≤ ?p⟧ ⟹ sum ?g {?m..<?n} + sum ?g {?n..<?p} = sum ?g {?m..<?p}›*) zero_le (*‹0 ≤ ?x›*)) finally (*calculation: ‹sum f {0..<2 ^ (n + 2)} = (∑k = 0..<2 ^ (n + 1). f (2 * k))›*) show "(∑k∈{0..<2^((Suc n)+1)}. f k) = (∑k∈{0..< 2^(Suc n)}. f (2*k))" by (metis Suc_eq_plus1 (*‹Suc ?n = ?n + 1›*) add_2_eq_Suc' (*‹?n + 2 = Suc (Suc ?n)›*)) qed qed lemma sum_every_even_summand_is_zero: fixes n:: nat assumes "n ≥ 1" shows "∀f::(nat ⇒ complex).(∀i. i<2^(n+1) ∧ even i ⟶ f i = 0) ⟶ (∑k∈{0..<2^(n+1)}. f k) = (∑k∈{0..< 2^n}. f (2*k+1))" using assms (*‹1 ≤ n›*) proof (rule nat_induct_at_least (*‹⟦(?m::nat) ≤ (?n::nat); (?P::nat ⇒ bool) ?m; ⋀n::nat. ⟦?m ≤ n; ?P n⟧ ⟹ ?P (Suc n)⟧ ⟹ ?P ?n›*)) (*goals: 1. ‹∀f. (∀i. i < 2 ^ (1 + 1) ∧ even i ⟶ f i = 0) ⟶ sum f {0..<2 ^ (1 + 1)} = (∑k = 0..<2 ^ 1. f (2 * k + 1))› 2. ‹⋀n. ⟦1 ≤ n; ∀f. (∀i. i < 2 ^ (n + 1) ∧ even i ⟶ f i = 0) ⟶ sum f {0..<2 ^ (n + 1)} = (∑k = 0..<2 ^ n. f (2 * k + 1))⟧ ⟹ ∀f. (∀i. i < 2 ^ (Suc n + 1) ∧ even i ⟶ f i = 0) ⟶ sum f {0..<2 ^ (Suc n + 1)} = (∑k = 0..<2 ^ Suc n. f (2 * k + 1))›*) show "∀f::(nat ⇒ complex).(∀i. i<2^(1+1) ∧ even i ⟶ f i = 0) ⟶ (∑k∈{0..<2^(1+1)}. f k) = (∑k∈{0..< 2^1}. f (2*k+1))" apply (rule allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*)) (*goal: ‹∀f. (∀i. i < 2 ^ (1 + 1) ∧ even i ⟶ f i = 0) ⟶ sum f {0..<2 ^ (1 + 1)} = (∑k = 0..<2 ^ 1. f (2 * k + 1))›*) proof (rule impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goal: ‹⋀f. ∀i. i < 2 ^ (1 + 1) ∧ even i ⟶ f i = 0 ⟹ sum f {0..<2 ^ (1 + 1)} = (∑k = 0..<2 ^ 1. f (2 * k + 1))›*) fix f :: "nat ⇒complex" assume asm: "(∀i. i<2^(1+1) ∧ even i ⟶ f i = 0)" (*‹∀i::nat. i < (2::nat) ^ ((1::nat) + (1::nat)) ∧ even i ⟶ (f::nat ⇒ complex) i = (0::complex)›*) moreover have "(∑k∈{0..<4}. f k) = f 0 + f 1 + f 2 + f 3" by (simp add: add.commute (*‹?a + ?b = ?b + ?a›*) add.left_commute (*‹?b + (?a + ?c) = ?a + (?b + ?c)›*)) moreover have "f 0 = 0" using asm (*‹∀i. i < 2 ^ (1 + 1) ∧ even i ⟶ f i = 0›*) by simp moreover have "f 2 = 0" using asm (*‹∀i. i < 2 ^ (1 + 1) ∧ even i ⟶ f i = 0›*) by simp moreover have "(∑k ∈ {0..< 2^1}. f (2*k+1)) = f 1 + f 3" using add.commute (*‹?a + ?b = ?b + ?a›*) add.left_commute (*‹?b + (?a + ?c) = ?a + (?b + ?c)›*) by simp ultimately show "(∑k∈{0..<2^(1+1)}. f k) = (∑k∈{0..< 2^1}. f (2*k+1))" by simp qed next (*goal: ‹⋀n. ⟦1 ≤ n; ∀f. (∀i. i < 2 ^ (n + 1) ∧ even i ⟶ f i = 0) ⟶ sum f {0..<2 ^ (n + 1)} = (∑k = 0..<2 ^ n. f (2 * k + 1))⟧ ⟹ ∀f. (∀i. i < 2 ^ (Suc n + 1) ∧ even i ⟶ f i = 0) ⟶ sum f {0..<2 ^ (Suc n + 1)} = (∑k = 0..<2 ^ Suc n. f (2 * k + 1))›*) fix n :: nat assume "n ≥ 1" and IH: "∀f::(nat ⇒complex).(∀i. i<2^(n+1) ∧ even i ⟶ f i = 0) ⟶ (∑k∈{0..<2^(n+1)}. f k) = (∑k∈{0..< 2^n}. f (2*k+1))" (*‹(1::nat) ≤ (n::nat)› ‹∀f::nat ⇒ complex. (∀i::nat. i < (2::nat) ^ ((n::nat) + (1::nat)) ∧ even i ⟶ f i = (0::complex)) ⟶ sum f {0::nat..<(2::nat) ^ (n + (1::nat))} = (∑k::nat = 0::nat..<(2::nat) ^ n. f ((2::nat) * k + (1::nat)))›*) show "∀f::(nat ⇒complex).(∀i. i<2^((Suc n)+1) ∧ even i ⟶ f i = 0) ⟶ (∑k∈{0..<2^((Suc n)+1)}. f k) = (∑k∈{0..< 2^(Suc n)}. f (2*k+1))" apply (rule allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*)) (*goal: ‹∀f. (∀i. i < 2 ^ (Suc n + 1) ∧ even i ⟶ f i = 0) ⟶ sum f {0..<2 ^ (Suc n + 1)} = (∑k = 0..<2 ^ Suc n. f (2 * k + 1))›*) proof (rule impI (*‹(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q›*)) (*goal: ‹⋀f. ∀i. i < 2 ^ (Suc n + 1) ∧ even i ⟶ f i = 0 ⟹ sum f {0..<2 ^ (Suc n + 1)} = (∑k = 0..<2 ^ Suc n. f (2 * k + 1))›*) fix f :: "nat ⇒complex" assume asm: "(∀i. i<2^((Suc n)+1) ∧ even i ⟶ f i = 0)" (*‹∀i::nat. i < (2::nat) ^ (Suc (n::nat) + (1::nat)) ∧ even i ⟶ (f::nat ⇒ complex) i = (0::complex)›*) have f0: "(∑k ∈{0..<2^(n+1)}. f k) = (∑k ∈ {0..< 2^n}. f (2*k+1))" using asm (*‹∀i::nat. i < (2::nat) ^ (Suc (n::nat) + (1::nat)) ∧ even i ⟶ (f::nat ⇒ complex) i = (0::complex)›*) IH (*‹∀f. (∀i. i < 2 ^ (n + 1) ∧ even i ⟶ f i = 0) ⟶ sum f {0..<2 ^ (n + 1)} = (∑k = 0..<2 ^ n. f (2 * k + 1))›*) by simp have f1: "(∑k∈{0..<2^(n+1)}. (λx. f (x+2^(n+1))) k) = (∑k∈{0..< 2^n}. (λx. f (x+2^(n+1))) (2*k+1))" using asm (*‹∀i. i < 2 ^ (Suc n + 1) ∧ even i ⟶ f i = 0›*) IH (*‹∀f. (∀i. i < 2 ^ (n + 1) ∧ even i ⟶ f i = 0) ⟶ sum f {0..<2 ^ (n + 1)} = (∑k = 0..<2 ^ n. f (2 * k + 1))›*) by simp have "(∑k∈{0..<2^(n+2)}. f k) = (∑k∈{0..<2^(n+1)}. f k) + (∑k∈{2^(n+1)..<2^(n+2)}. f k)" by (simp add: sum.atLeastLessThan_concat (*‹⟦?m ≤ ?n; ?n ≤ ?p⟧ ⟹ sum ?g {?m..<?n} + sum ?g {?n..<?p} = sum ?g {?m..<?p}›*)) also (*calculation: ‹sum (f::nat ⇒ complex) {0::nat..<(2::nat) ^ ((n::nat) + (2::nat))} = sum f {0::nat..<(2::nat) ^ (n + (1::nat))} + sum f {(2::nat) ^ (n + (1::nat))..<(2::nat) ^ (n + (2::nat))}›*) have "... = (∑k∈{0..< 2^n}. f (2*k+1)) + (∑k∈{2^(n+1)..<2^(n+2)}. f k)" using f0 (*‹sum (f::nat ⇒ complex) {0::nat..<(2::nat) ^ ((n::nat) + (1::nat))} = (∑k::nat = 0::nat..<(2::nat) ^ n. f ((2::nat) * k + (1::nat)))›*) by simp also (*calculation: ‹sum f {0..<2 ^ (n + 2)} = (∑k = 0..<2 ^ n. f (2 * k + 1)) + sum f {2 ^ (n + 1)..<2 ^ (n + 2)}›*) have "... = (∑k∈{0..< 2^n}. f (2*k+1)) + (∑k∈{0..<2^(n+1)}. f (k+(2^(n+1))))" using sum.shift_bounds_nat_ivl[of "f" "0" "2^(n+1)" "2^(n+1)"] (*‹sum f {0 + 2 ^ (n + 1)..<2 ^ (n + 1) + 2 ^ (n + 1)} = (∑i = 0..<2 ^ (n + 1). f (i + 2 ^ (n + 1)))›*) by simp also (*calculation: ‹sum f {0..<2 ^ (n + 2)} = (∑k = 0..<2 ^ n. f (2 * k + 1)) + (∑k = 0..<2 ^ (n + 1). f (k + 2 ^ (n + 1)))›*) have "... = (∑k∈{0..< 2^n}. f (2*k+1)) + (∑k∈{0..< 2^n}. (λx. f (x+2^(n+1))) (2*k+1))" using f1 (*‹(∑k = 0..<2 ^ (n + 1). f (k + 2 ^ (n + 1))) = (∑k = 0..<2 ^ n. f (2 * k + 1 + 2 ^ (n + 1)))›*) by simp also (*calculation: ‹sum f {0..<2 ^ (n + 2)} = (∑k = 0..<2 ^ n. f (2 * k + 1)) + (∑k = 0..<2 ^ n. f (2 * k + 1 + 2 ^ (n + 1)))›*) have "... = (∑k∈{0..< 2^n}. f (2*k+1)) + (∑k∈{2^n..< 2^(n+1)}. f (2 *k+1))" using sum.shift_bounds_nat_ivl[of "λx. (f::nat⇒complex) (2*(x-2^n)+1+2^(n+1))" "0" "2^n" "2^n"] (*‹(∑x = 0 + 2 ^ n..<2 ^ n + 2 ^ n. f (2 * (x - 2 ^ n) + 1 + 2 ^ (n + 1))) = (∑i = 0..<2 ^ n. f (2 * (i + 2 ^ n - 2 ^ n) + 1 + 2 ^ (n + 1)))›*) by (simp add: mult_2 (*‹2 * ?z = ?z + ?z›*)) also (*calculation: ‹sum f {0..<2 ^ (n + 2)} = (∑k = 0..<2 ^ n. f (2 * k + 1)) + (∑k = 2 ^ n..<2 ^ (n + 1). f (2 * k + 1))›*) have "... = (∑k∈{0..< 2^(n+1)}. f (2*k+1))" by (metis Suc_eq_plus1 (*‹Suc (?n::nat) = ?n + (1::nat)›*) lessI (*‹(?n::nat) < Suc ?n›*) less_imp_le_nat (*‹(?m::nat) < (?n::nat) ⟹ ?m ≤ ?n›*) one_le_numeral (*‹(1::?'a) ≤ numeral (?n::num)›*) power_increasing (*‹⟦(?n::nat) ≤ (?N::nat); (1::?'a) ≤ (?a::?'a)⟧ ⟹ ?a ^ ?n ≤ ?a ^ ?N›*) sum.atLeastLessThan_concat (*‹⟦(?m::nat) ≤ (?n::nat); ?n ≤ (?p::nat)⟧ ⟹ sum (?g::nat ⇒ ?'a) {?m..<?n} + sum ?g {?n..<?p} = sum ?g {?m..<?p}›*) zero_le (*‹(0::?'a) ≤ (?x::?'a)›*)) finally (*calculation: ‹sum f {0..<2 ^ (n + 2)} = (∑k = 0..<2 ^ (n + 1). f (2 * k + 1))›*) show "(∑k∈{0..<2^((Suc n)+1)}. f k) = (∑k∈{0..< 2^(Suc n)}. f (2*k+1))" by (metis Suc_eq_plus1 (*‹Suc ?n = ?n + 1›*) add_2_eq_Suc' (*‹?n + 2 = Suc (Suc ?n)›*)) qed qed lemma (in jozsa) iter_tensor_of_H_times_ψ₂_is_ψ₃: shows "((H^⇩⊗ n) ⨂ Id 1) * ψ₂ = ψ₃" proof (standard) (*goals: 1. ‹⋀i j. ⟦i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1))))); j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))⟧ ⟹ ((Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) ⨂ Quantum.Id 1) * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)))) $$ (i, j) = Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))) $$ (i, j)› 2. ‹dim_row ((Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) ⨂ Quantum.Id 1) * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)))) = dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))› 3. ‹dim_col ((Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) ⨂ Quantum.Id 1) * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)))) = dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))›*) fix i and j assume a0: "i < dim_row ψ₃" and a1: "j < dim_col ψ₃" (*‹(i::nat) < dim_row (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ ((f::nat ⇒ nat) k + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))) else ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ (f k + (1::nat) + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))))))› ‹(j::nat) < dim_col (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ ((f::nat ⇒ nat) k + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))) else ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ (f k + (1::nat) + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))))))›*) then have f0: "i < (2^(n+1)) ∧ j = 0" by simp have f1: "((HId^⇩⊗ n)* ψ₂) $$ (i,j) = (∑k<(2^(n+1)). ((HId^⇩⊗ n) $$ (i,k)) * (ψ₂ $$ (k,j)))" using a1 (*‹(j::nat) < dim_col (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ ((f::nat ⇒ nat) k + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))) else ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ (f k + (1::nat) + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))))))›*) f0 (*‹i < 2 ^ (n + 1) ∧ j = 0›*) by (simp add: atLeast0LessThan (*‹{0..<?n} = {..<?n}›*)) show "(((H^⇩⊗ n) ⨂ Id 1) * ψ₂) $$ (i,j) = ψ₃ $$ (i,j)" proof (rule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹?P ∨ ?Q› 2. ‹?P ⟹ ((Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) ⨂ Quantum.Id 1) * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)))) $$ (i, j) = Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))) $$ (i, j)› 3. ‹?Q ⟹ ((Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) ⨂ Quantum.Id 1) * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)))) $$ (i, j) = Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))) $$ (i, j)›*) show "even i ∨ odd i" by simp next (*goals: 1. ‹even i ⟹ ((Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) ⨂ Quantum.Id 1) * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)))) $$ (i, j) = Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))) $$ (i, j)› 2. ‹odd i ⟹ ((Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) ⨂ Quantum.Id 1) * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)))) $$ (i, j) = Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))) $$ (i, j)›*) assume a2: "even i" (*‹even (i::nat)›*) have "(¬(i mod 2 = k mod 2) ∧ k<dim_col (HId^⇩⊗ n)) ⟶ ((HId^⇩⊗ n) $$ (i,k)) * (ψ₂ $$ (k,j)) = 0" for k using f0 (*‹i < 2 ^ (n + 1) ∧ j = 0›*) by simp then have "k<(2^(n+1)) ∧ odd k ⟶ ((HId^⇩⊗ n) $$ (i,k)) * (ψ₂ $$ (k,j)) = 0" for k using a2 (*‹even i›*) mod_2_is_both_even_or_odd (*‹(even ?i ∧ even ?j ∨ odd ?i ∧ odd ?j) = (?i mod 2 = ?j mod 2)›*) f0 (*‹i < 2 ^ (n + 1) ∧ j = 0›*) by (metis (no_types, lifting) dim_col_mat( (*‹dim_col (Matrix.mat ?nr ?nc ?f) = ?nc›*) 1)) then have "(∑k∈{(0::nat)..<(2^(n+1))}. ((HId^⇩⊗ n) $$ (i,k)) * (ψ₂ $$ (k,j))) = (∑k∈{(0::nat)..< (2^n)}. ((HId^⇩⊗ n) $$ (i,2*k)) * (ψ₂ $$ (2*k,j)))" using sum_every_odd_summand_is_zero (*‹1 ≤ ?n ⟹ ∀f. (∀i. i < 2 ^ (?n + 1) ∧ odd i ⟶ f i = 0) ⟶ sum f {0..<2 ^ (?n + 1)} = (∑k = 0..<2 ^ ?n. f (2 * k))›*) dim (*‹1 ≤ n›*) by simp moreover have "(∑k<2^n. ((HId^⇩⊗ n) $$ (i,2*k)) * (ψ₂ $$ (2*k,j))) = (∑k<2^n.(-1)^((i div 2) ⋅⇘n⇙ k)/(sqrt(2)^n) *((-1)^f(k))/(sqrt(2)^(n+1)))" proof (-) (*goal: ‹(∑k<2 ^ n. Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0)) $$ (i, 2 * k) * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))) $$ (2 * k, j)) = complex_of_real (∑k<2 ^ n. (- 1) ^ i div 2 ⋅⇘n⇙ k / sqrt 2 ^ n * (- 1) ^ f k / sqrt 2 ^ (n + 1))›*) have "(even k ∧ k<dim_row ψ₂) ⟶ (ψ₂ $$ (k,j)) = ((-1)^f(k div 2))/(sqrt(2)^(n+1))" for k using a0 (*‹(i::nat) < dim_row (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ ((f::nat ⇒ nat) k + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))) else ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ (f k + (1::nat) + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))))))›*) a1 (*‹j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))›*) by simp then have "(∑k<2^n. ((HId^⇩⊗ n) $$ (i,2*k)) * (ψ₂ $$ (2*k,j))) = (∑k<2^n. ((HId^⇩⊗ n) $$ (i,2*k)) *((-1)^f((2*k) div 2))/(sqrt(2)^(n+1)))" by simp moreover have "(even k ∧ k<dim_col (HId^⇩⊗ n)) ⟶ ((HId^⇩⊗ n) $$ (i,k)) = (-1)^ ((i div 2) ⋅⇘n⇙ (k div 2))/(sqrt(2)^n)" for k using a2 (*‹even i›*) a0 (*‹i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))›*) a1 (*‹j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))›*) by simp ultimately have "(∑k<2^n. ((HId^⇩⊗ n) $$ (i,2*k)) * (ψ₂ $$ (2*k,j))) = (∑k<2^n. (-1)^((i div 2) ⋅⇘n⇙ ((2*k) div 2))/(sqrt(2)^n) * ((-1)^f((2*k) div 2))/(sqrt(2)^(n+1)))" by simp then show "(∑k<2^n. ((HId^⇩⊗ n) $$ (i,2*k)) * (ψ₂ $$ (2*k,j))) = (∑k<2^n. (-1)^((i div 2) ⋅⇘n⇙ k)/(sqrt(2)^n) *((-1)^f(k))/(sqrt(2)^(n+1)))" by simp qed ultimately have "((HId^⇩⊗ n)* ψ₂) $$ (i,j) = (∑k<2^n. (-1)^((i div 2) ⋅⇘n⇙ k)/(sqrt(2)^n) * ((-1)^f(k))/(sqrt(2)^(n+1)))" using f1 (*‹(Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) ((2::nat) ^ (n + (1::nat))) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if i mod (2::nat) = j mod (2::nat) then (- (1::real)) ^ i div (2::nat) ⋅⇘n⇙ j div (2::nat) / sqrt (2::real) ^ n else (0::real))) * Matrix.mat ((2::nat) ^ (n + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (- (1::real)) ^ (f::nat ⇒ nat) (i div (2::nat)) / sqrt (2::real) ^ (n + (1::nat)) else (- (1::real)) ^ (f (i div (2::nat)) + (1::nat)) / sqrt (2::real) ^ (n + (1::nat))))) $$ (i::nat, j::nat) = (∑k::nat<(2::nat) ^ (n + (1::nat)). Matrix.mat ((2::nat) ^ (n + (1::nat))) ((2::nat) ^ (n + (1::nat))) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if i mod (2::nat) = j mod (2::nat) then (- (1::real)) ^ i div (2::nat) ⋅⇘n⇙ j div (2::nat) / sqrt (2::real) ^ n else (0::real))) $$ (i, k) * Matrix.mat ((2::nat) ^ (n + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (- (1::real)) ^ f (i div (2::nat)) / sqrt (2::real) ^ (n + (1::nat)) else (- (1::real)) ^ (f (i div (2::nat)) + (1::nat)) / sqrt (2::real) ^ (n + (1::nat)))) $$ (k, j))›*) by (metis atLeast0LessThan (*‹{0..<?n} = {..<?n}›*)) also (*calculation: ‹(Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0)) * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)))) $$ (i, j) = complex_of_real (∑k<2 ^ n. (- 1) ^ i div 2 ⋅⇘n⇙ k / sqrt 2 ^ n * (- 1) ^ f k / sqrt 2 ^ (n + 1))›*) have "... = (∑k<2^n. (-1)^(f(k)+((i div 2) ⋅⇘n⇙ k))/((sqrt(2)^n)*(sqrt(2)^(n+1))))" by (simp add: power_add (*‹?a ^ (?m + ?n) = ?a ^ ?m * ?a ^ ?n›*) mult.commute (*‹?a * ?b = ?b * ?a›*)) finally (*calculation: ‹(Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0)) * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)))) $$ (i, j) = complex_of_real (∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))›*) have "((HId^⇩⊗ n)* ψ₂) $$ (i,j) = (∑k<2^n. (-1)^(f(k)+((i div 2) ⋅⇘n⇙ k))/((sqrt(2)^n)*(sqrt(2)^(n+1))))" by simp moreover have "ψ₃ $$ (i,j) = (∑k<2^n. (-1)^(f(k) + ((i div 2) ⋅⇘n⇙ k))/(sqrt(2)^n * sqrt(2)^(n+1)))" using a0 (*‹(i::nat) < dim_row (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ ((f::nat ⇒ nat) k + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))) else ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ (f k + (1::nat) + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))))))›*) a1 (*‹(j::nat) < dim_col (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ ((f::nat ⇒ nat) k + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))) else ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ (f k + (1::nat) + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))))))›*) a2 (*‹even i›*) by simp ultimately show "(((H^⇩⊗ n) ⨂ Id 1)* ψ₂) $$ (i,j) = ψ₃ $$ (i,j)" using iter_tensor_of_H_tensor_Id_is_HId (*‹Matrix.mat ((2::nat) ^ (?n::nat)) ((2::nat) ^ ?n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘?n⇙ j / sqrt (2::real) ^ ?n)) ⨂ Quantum.Id (1::nat) = Matrix.mat ((2::nat) ^ (?n + (1::nat))) ((2::nat) ^ (?n + (1::nat))) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if i mod (2::nat) = j mod (2::nat) then (- (1::real)) ^ i div (2::nat) ⋅⇘?n⇙ j div (2::nat) / sqrt (2::real) ^ ?n else (0::real)))›*) dim (*‹1 ≤ n›*) by simp next (*goal: ‹odd i ⟹ ((Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) ⨂ Quantum.Id 1) * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)))) $$ (i, j) = Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))) $$ (i, j)›*) assume a2: "odd i" (*‹odd (i::nat)›*) have "(¬(i mod 2 = k mod 2) ∧ k<dim_col (HId^⇩⊗ n)) ⟶ ((HId^⇩⊗ n) $$ (i,k)) * (ψ₂ $$ (k,j)) = 0" for k using f0 (*‹i < 2 ^ (n + 1) ∧ j = 0›*) by simp then have "k<(2^(n+1)) ∧ even k ⟶ ((HId^⇩⊗ n) $$ (i,k)) * (ψ₂ $$ (k,j)) = 0" for k using a2 (*‹odd i›*) mod_2_is_both_even_or_odd (*‹(even (?i::?'a::semiring_parity) ∧ even (?j::?'a::semiring_parity) ∨ odd ?i ∧ odd ?j) = (?i mod (2::?'a::semiring_parity) = ?j mod (2::?'a::semiring_parity))›*) f0 (*‹i < 2 ^ (n + 1) ∧ j = 0›*) by (metis (no_types, lifting) dim_col_mat( (*‹dim_col (Matrix.mat ?nr ?nc ?f) = ?nc›*) 1)) then have "(∑k∈{0..<2^(n+1)}. ((HId^⇩⊗ n) $$ (i,k)) * (ψ₂ $$ (k,j))) = (∑k∈{0..<2^n}. ((HId^⇩⊗ n) $$ (i,2*k+1)) * (ψ₂ $$ (2*k+1,j)))" using sum_every_even_summand_is_zero (*‹1 ≤ ?n ⟹ ∀f. (∀i. i < 2 ^ (?n + 1) ∧ even i ⟶ f i = 0) ⟶ sum f {0..<2 ^ (?n + 1)} = (∑k = 0..<2 ^ ?n. f (2 * k + 1))›*) dim (*‹1 ≤ n›*) by simp moreover have "(∑k<2^n. ((HId^⇩⊗ n) $$ (i,2*k+1)) * (ψ₂ $$ (2*k+1,j))) = (∑ k<2^n. (-1)^((i div 2) ⋅⇘n⇙ k)/(sqrt(2)^n) * ((-1)^(f(k)+1))/(sqrt(2)^(n+1)))" proof (-) (*goal: ‹(∑k<2 ^ n. Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0)) $$ (i, 2 * k + 1) * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))) $$ (2 * k + 1, j)) = complex_of_real (∑k<2 ^ n. (- 1) ^ i div 2 ⋅⇘n⇙ k / sqrt 2 ^ n * (- 1) ^ (f k + 1) / sqrt 2 ^ (n + 1))›*) have "(odd k ∧ k<dim_row ψ₂) ⟶ (ψ₂ $$ (k,j)) = ((-1)^(f(k div 2)+1))/(sqrt(2)^(n+1))" for k using a0 (*‹i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))›*) a1 (*‹j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))›*) a2 (*‹odd i›*) by simp then have f2: "(∑k<2^n. ((HId^⇩⊗ n) $$ (i,2*k+1)) * (ψ₂ $$ (2*k+1,j))) = (∑k<2^n. ((HId^⇩⊗ n) $$ (i,2*k+1)) * ((-1)^(f((2*k+1) div 2)+1))/(sqrt(2)^(n+1)))" by simp have "i < dim_row (HId^⇩⊗ n)" using f0 (*‹i < 2 ^ (n + 1) ∧ j = 0›*) a2 (*‹odd i›*) mod_2_is_both_even_or_odd (*‹(even ?i ∧ even ?j ∨ odd ?i ∧ odd ?j) = (?i mod 2 = ?j mod 2)›*) by simp then have "((i mod 2 = k mod 2) ∧ k<dim_col (HId^⇩⊗ n)) ⟶ ((HId^⇩⊗ n) $$ (i,k)) = (-1)^((i div 2) ⋅⇘n⇙ (k div 2))/(sqrt(2)^n) " for k using a2 (*‹odd (i::nat)›*) a0 (*‹i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))›*) a1 (*‹(j::nat) < dim_col (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ ((f::nat ⇒ nat) k + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))) else ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ (f k + (1::nat) + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))))))›*) f0 (*‹i < 2 ^ (n + 1) ∧ j = 0›*) dim (*‹(1::nat) ≤ (n::nat)›*) HId_values (*‹⟦1 ≤ ?n; ?i < dim_row (Matrix.mat (2 ^ (?n + 1)) (2 ^ (?n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘?n⇙ j div 2 / sqrt 2 ^ ?n else 0))); ?j < dim_col (Matrix.mat (2 ^ (?n + 1)) (2 ^ (?n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘?n⇙ j div 2 / sqrt 2 ^ ?n else 0)))⟧ ⟹ even ?i ∧ even ?j ⟶ Matrix.mat (2 ^ (?n + 1)) (2 ^ (?n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘?n⇙ j div 2 / sqrt 2 ^ ?n else 0)) $$ (?i, ?j) = complex_of_real ((- 1) ^ ?i div 2 ⋅⇘?n⇙ ?j div 2 / sqrt 2 ^ ?n)› ‹⟦1 ≤ ?n; ?i < dim_row (Matrix.mat (2 ^ (?n + 1)) (2 ^ (?n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘?n⇙ j div 2 / sqrt 2 ^ ?n else 0))); ?j < dim_col (Matrix.mat (2 ^ (?n + 1)) (2 ^ (?n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘?n⇙ j div 2 / sqrt 2 ^ ?n else 0)))⟧ ⟹ odd ?i ∧ odd ?j ⟶ Matrix.mat (2 ^ (?n + 1)) (2 ^ (?n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘?n⇙ j div 2 / sqrt 2 ^ ?n else 0)) $$ (?i, ?j) = complex_of_real ((- 1) ^ ?i div 2 ⋅⇘?n⇙ ?j div 2 / sqrt 2 ^ ?n)› ‹⟦1 ≤ ?n; ?i < dim_row (Matrix.mat (2 ^ (?n + 1)) (2 ^ (?n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘?n⇙ j div 2 / sqrt 2 ^ ?n else 0))); ?j < dim_col (Matrix.mat (2 ^ (?n + 1)) (2 ^ (?n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘?n⇙ j div 2 / sqrt 2 ^ ?n else 0)))⟧ ⟹ ?i mod 2 = ?j mod 2 ⟶ Matrix.mat (2 ^ (?n + 1)) (2 ^ (?n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘?n⇙ j div 2 / sqrt 2 ^ ?n else 0)) $$ (?i, ?j) = complex_of_real ((- 1) ^ ?i div 2 ⋅⇘?n⇙ ?j div 2 / sqrt 2 ^ ?n)› ‹⟦(1::nat) ≤ (?n::nat); (?i::nat) < dim_row (Matrix.mat ((2::nat) ^ (?n + (1::nat))) ((2::nat) ^ (?n + (1::nat))) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if i mod (2::nat) = j mod (2::nat) then (- (1::real)) ^ i div (2::nat) ⋅⇘?n⇙ j div (2::nat) / sqrt (2::real) ^ ?n else (0::real)))); (?j::nat) < dim_col (Matrix.mat ((2::nat) ^ (?n + (1::nat))) ((2::nat) ^ (?n + (1::nat))) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if i mod (2::nat) = j mod (2::nat) then (- (1::real)) ^ i div (2::nat) ⋅⇘?n⇙ j div (2::nat) / sqrt (2::real) ^ ?n else (0::real))))⟧ ⟹ ?i mod (2::nat) ≠ ?j mod (2::nat) ⟶ Matrix.mat ((2::nat) ^ (?n + (1::nat))) ((2::nat) ^ (?n + (1::nat))) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if i mod (2::nat) = j mod (2::nat) then (- (1::real)) ^ i div (2::nat) ⋅⇘?n⇙ j div (2::nat) / sqrt (2::real) ^ ?n else (0::real))) $$ (?i, ?j) = (0::complex)›*) by simp moreover have "odd k ⟶ (i mod 2 = k mod 2)" for k using a2 (*‹odd i›*) mod_2_is_both_even_or_odd (*‹(even ?i ∧ even ?j ∨ odd ?i ∧ odd ?j) = (?i mod 2 = ?j mod 2)›*) by auto ultimately have "(odd k ∧ k<dim_col (HId^⇩⊗ n)) ⟶ ((HId^⇩⊗ n) $$ (i,k)) = (-1)^((i div 2) ⋅⇘n⇙ (k div 2))/(sqrt(2)^n)" for k by simp then have "k<2^n ⟶ ((HId^⇩⊗ n) $$ (i,2*k+1)) = (-1)^((i div 2) ⋅⇘n⇙ ((2*k+1) div 2))/(sqrt(2)^n) " for k by simp then have "(∑k<2^n. ((HId^⇩⊗ n) $$ (i,2*k+1)) * (ψ₂ $$ (2*k+1,j))) = (∑k<2^n. (-1)^((i div 2) ⋅⇘n⇙ ((2*k+1) div 2))/(sqrt(2)^n) * ((-1)^(f((2*k+1) div 2)+1))/(sqrt(2)^(n+1)))" using f2 (*‹(∑k::nat<(2::nat) ^ n. Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) ((2::nat) ^ (n + (1::nat))) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if i mod (2::nat) = j mod (2::nat) then (- (1::real)) ^ i div (2::nat) ⋅⇘n⇙ j div (2::nat) / sqrt (2::real) ^ n else (0::real))) $$ (i::nat, (2::nat) * k + (1::nat)) * Matrix.mat ((2::nat) ^ (n + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then (- (1::real)) ^ (f::nat ⇒ nat) (i div (2::nat)) / sqrt (2::real) ^ (n + (1::nat)) else (- (1::real)) ^ (f (i div (2::nat)) + (1::nat)) / sqrt (2::real) ^ (n + (1::nat)))) $$ ((2::nat) * k + (1::nat), j::nat)) = (∑k::nat<(2::nat) ^ n. Matrix.mat ((2::nat) ^ (n + (1::nat))) ((2::nat) ^ (n + (1::nat))) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if i mod (2::nat) = j mod (2::nat) then (- (1::real)) ^ i div (2::nat) ⋅⇘n⇙ j div (2::nat) / sqrt (2::real) ^ n else (0::real))) $$ (i, (2::nat) * k + (1::nat)) * (- (1::complex)) ^ (f (((2::nat) * k + (1::nat)) div (2::nat)) + (1::nat)) / complex_of_real (sqrt (2::real) ^ (n + (1::nat))))›*) by simp then show "(∑k<2^n. ((HId^⇩⊗ n) $$ (i,2*k+1)) * (ψ₂ $$ (2*k+1,j))) = (∑k<2^n. (-1)^((i div 2) ⋅⇘n⇙ k)/(sqrt(2)^n) *((-1)^(f(k)+1))/(sqrt(2)^(n+1)))" by simp qed ultimately have "((HId^⇩⊗ n)* ψ₂) $$ (i,j) = (∑k<2^n. (-1)^((i div 2) ⋅⇘n⇙ k)/(sqrt(2)^n) * ((-1)^(f(k)+1))/(sqrt(2)^(n+1)))" using f1 (*‹(Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0)) * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)))) $$ (i, j) = (∑k<2 ^ (n + 1). Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0)) $$ (i, k) * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))) $$ (k, j))›*) by (metis atLeast0LessThan (*‹{0::nat..<?n::nat} = {..<?n}›*)) also (*calculation: ‹(Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0)) * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)))) $$ (i, j) = complex_of_real (∑k<2 ^ n. (- 1) ^ i div 2 ⋅⇘n⇙ k / sqrt 2 ^ n * (- 1) ^ (f k + 1) / sqrt 2 ^ (n + 1))›*) have "... = (∑k<2^n. (-1)^(f(k)+1+((i div 2) ⋅⇘n⇙ k))/((sqrt(2)^n)*(sqrt(2)^(n+1))))" by (simp add: mult.commute (*‹?a * ?b = ?b * ?a›*) power_add (*‹?a ^ (?m + ?n) = ?a ^ ?m * ?a ^ ?n›*)) finally (*calculation: ‹(Matrix.mat (2 ^ (n + 1)) (2 ^ (n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘n⇙ j div 2 / sqrt 2 ^ n else 0)) * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)))) $$ (i, j) = complex_of_real (∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))›*) have "((HId^⇩⊗ n)* ψ₂) $$ (i,j) = (∑k< 2^n. (-1)^(f(k)+1+((i div 2) ⋅⇘n⇙ k))/((sqrt(2)^n)*(sqrt(2)^(n+1))))" by simp then show "(((H^⇩⊗ n) ⨂ Id 1)* ψ₂) $$ (i,j) = ψ₃ $$ (i,j)" using iter_tensor_of_H_tensor_Id_is_HId (*‹Matrix.mat (2 ^ ?n) (2 ^ ?n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘?n⇙ j / sqrt 2 ^ ?n)) ⨂ Quantum.Id 1 = Matrix.mat (2 ^ (?n + 1)) (2 ^ (?n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘?n⇙ j div 2 / sqrt 2 ^ ?n else 0))›*) dim (*‹1 ≤ n›*) a2 (*‹odd (i::nat)›*) a0 (*‹(i::nat) < dim_row (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ ((f::nat ⇒ nat) k + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))) else ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ (f k + (1::nat) + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))))))›*) a1 (*‹j < dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))›*) by simp qed next (*goals: 1. ‹dim_row ((Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) ⨂ Quantum.Id 1) * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)))) = dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))› 2. ‹dim_col ((Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) ⨂ Quantum.Id 1) * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)))) = dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))›*) show "dim_row (((H^⇩⊗ n) ⨂ Id 1) * ψ₂) = dim_row ψ₃" using iter_tensor_of_H_tensor_Id_is_HId (*‹Matrix.mat ((2::nat) ^ (?n::nat)) ((2::nat) ^ ?n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘?n⇙ j / sqrt (2::real) ^ ?n)) ⨂ Quantum.Id (1::nat) = Matrix.mat ((2::nat) ^ (?n + (1::nat))) ((2::nat) ^ (?n + (1::nat))) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if i mod (2::nat) = j mod (2::nat) then (- (1::real)) ^ i div (2::nat) ⋅⇘?n⇙ j div (2::nat) / sqrt (2::real) ^ ?n else (0::real)))›*) dim (*‹1 ≤ n›*) by simp next (*goal: ‹dim_col ((Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) ⨂ Quantum.Id 1) * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)))) = dim_col (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))›*) show "dim_col (((H^⇩⊗ n) ⨂ Id 1)* ψ₂) = dim_col ψ₃" using iter_tensor_of_H_tensor_Id_is_HId (*‹Matrix.mat ((2::nat) ^ (?n::nat)) ((2::nat) ^ ?n) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ (- (1::real)) ^ i ⋅⇘?n⇙ j / sqrt (2::real) ^ ?n)) ⨂ Quantum.Id (1::nat) = Matrix.mat ((2::nat) ^ (?n + (1::nat))) ((2::nat) ^ (?n + (1::nat))) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if i mod (2::nat) = j mod (2::nat) then (- (1::real)) ^ i div (2::nat) ⋅⇘?n⇙ j div (2::nat) / sqrt (2::real) ^ ?n else (0::real)))›*) dim (*‹1 ≤ n›*) by simp qed lemma (in jozsa) ψ₃_is_state: shows "state (n+1) ψ₃" proof (-) (*goal: ‹state (n + 1) (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))›*) have "((H^⇩⊗ n) ⨂ Id 1) * ψ₂ = ψ₃" using "iter_tensor_of_H_times_ψ₂_is_ψ₃" (*‹(Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) ⨂ Quantum.Id 1) * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))) = Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1))))›*) by simp moreover have "gate (n+1) ((H^⇩⊗ n) ⨂ Id 1)" using iter_tensor_of_H_tensor_Id_is_HId (*‹Matrix.mat (2 ^ ?n) (2 ^ ?n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘?n⇙ j / sqrt 2 ^ ?n)) ⨂ Quantum.Id 1 = Matrix.mat (2 ^ (?n + 1)) (2 ^ (?n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘?n⇙ j div 2 / sqrt 2 ^ ?n else 0))›*) HId_is_gate (*‹1 ≤ ?n ⟹ gate (?n + 1) (Matrix.mat (2 ^ (?n + 1)) (2 ^ (?n + 1)) (λx. complex_of_real (case x of (i, j) ⇒ if i mod 2 = j mod 2 then (- 1) ^ i div 2 ⋅⇘?n⇙ j div 2 / sqrt 2 ^ ?n else 0)))›*) dim (*‹1 ≤ n›*) by simp moreover have "state (n+1) ψ₂" using "ψ₂_is_state" (*‹state (n + 1) (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))))›*) by simp ultimately show "state (n+1) ψ₃" using gate_on_state_is_state (*‹⟦gate ?n ?A; state ?n ?v⟧ ⟹ state ?n (?A * ?v)›*) dim (*‹(1::nat) ≤ (n::nat)›*) by (metis (no_types, lifting)) qed text ‹ Finally, all steps are put together. The result depends on the function f. If f is constant the first n qubits are 0, if f is balanced there is at least one qubit in state 1 among the first n qubits. The algorithm only uses one evaluation of f(x) and will always succeed. › definition (in jozsa) jozsa_algo:: "complex Matrix.mat" where "jozsa_algo ≡ ((H ⊗⇗n⇖) ⨂ Id 1) * (U⇩f * (((H ⊗⇗n⇖) * ( |zero⟩ ⊗⇗n⇖)) ⨂ (H * |one⟩)))" lemma (in jozsa) jozsa_algo_result [simp]: shows "jozsa_algo = ψ₃" using jozsa_algo_def (*‹jozsa_algo ≡ (H ⊗⇗n::nat⇖ ⨂ Quantum.Id (1::nat)) * (U⇩f * (H ⊗⇗n⇖ * |Deutsch.zero⟩ ⊗⇗n⇖ ⨂ H * |Deutsch.one⟩))›*) "H_on_ket_one_is_ψ₁₁" (*‹H * |Deutsch.one⟩ = Matrix.mat 2 1 (λx. complex_of_real (case x of (i, j) ⇒ if i = 0 then 1 / sqrt 2 else - 1 / sqrt 2))›*) iter_tensor_of_H_on_zero_tensor (*‹1 ≤ ?n ⟹ H ⊗⇗?n⇖ * |Deutsch.zero⟩ ⊗⇗?n⇖ = Matrix.mat (2 ^ ?n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ ?n))›*) "ψ₁₀_tensor_ψ₁₁_is_ψ₁" (*‹1 ≤ ?n ⟹ Matrix.mat (2 ^ ?n) 1 (λx. complex_of_real (case x of (i, j) ⇒ 1 / sqrt 2 ^ ?n)) ⨂ Matrix.mat 2 1 (λx. complex_of_real (case x of (i, j) ⇒ if i = 0 then 1 / sqrt 2 else - 1 / sqrt 2)) = Matrix.mat (2 ^ (?n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (?n + 1) else - 1 / sqrt 2 ^ (?n + 1)))›*) "jozsa_transform_times_ψ₁_is_ψ₂" (*‹U⇩f * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then 1 / sqrt 2 ^ (n + 1) else - 1 / sqrt 2 ^ (n + 1))) = Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1)))›*) "iter_tensor_of_H_times_ψ₂_is_ψ₃" (*‹(Matrix.mat (2 ^ n) (2 ^ n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘n⇙ j / sqrt 2 ^ n)) ⨂ Quantum.Id 1) * Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then (- 1) ^ f (i div 2) / sqrt 2 ^ (n + 1) else (- 1) ^ (f (i div 2) + 1) / sqrt 2 ^ (n + 1))) = Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1))))›*) dim (*‹1 ≤ n›*) iter_tensor_of_H_rep_is_correct (*‹1 ≤ ?n ⟹ H ⊗⇗?n⇖ = Matrix.mat (2 ^ ?n) (2 ^ ?n) (λx. complex_of_real (case x of (i, j) ⇒ (- 1) ^ i ⋅⇘?n⇙ j / sqrt 2 ^ ?n))›*) by simp lemma (in jozsa) jozsa_algo_result_is_state: shows "state (n+1) jozsa_algo" using "ψ₃_is_state" (*‹state (n + 1) (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))›*) by simp lemma (in jozsa) prob0_fst_qubits_of_jozsa_algo: shows "(prob0_fst_qubits n jozsa_algo) = (∑j∈{0,1}. (cmod(jozsa_algo $$ (j,0)))²)" using prob0_fst_qubits_eq (*‹prob0_fst_qubits ?n ?v = (cmod (?v $$ (0, 0)))² + (cmod (?v $$ (1, 0)))²›*) by simp text ‹General lemmata required to compute probabilities.› lemma aux_comp_with_sqrt2: shows "(sqrt 2)^n * (sqrt 2)^n = 2^n" by (smt (verit) power_mult_distrib (*‹((?a::?'a) * (?b::?'a)) ^ (?n::nat) = ?a ^ ?n * ?b ^ ?n›*) real_sqrt_mult_self (*‹sqrt (?a::real) * sqrt ?a = ¦?a¦›*)) lemma aux_comp_with_sqrt2_bis [simp]: shows "2^n/(sqrt(2)^n * sqrt(2)^(n+1)) = 1/sqrt 2" using aux_comp_with_sqrt2 (*‹sqrt 2 ^ ?n * sqrt 2 ^ ?n = 2 ^ ?n›*) by (simp add: mult.left_commute (*‹(?b::?'a::ab_semigroup_mult) * ((?a::?'a::ab_semigroup_mult) * (?c::?'a::ab_semigroup_mult)) = ?a * (?b * ?c)›*)) lemma aux_ineq_with_card: fixes g:: "nat ⇒ nat" and A:: "nat set" assumes "finite A" shows "(∑k∈A. (-1)^(g k)) ≤ card A" and "(∑k∈A. (-1)^(g k)) ≥ -card A" (*goals: 1. ‹(∑k∈A. (- 1) ^ g k) ≤ int (card A)› 2. ‹- int (card A) ≤ (∑k∈A. (- 1) ^ g k)› discuss goal 1*) apply (smt (verit) assms (*‹finite A›*) neg_one_even_power (*‹even ?n ⟹ (- 1) ^ ?n = 1›*) neg_one_odd_power (*‹odd ?n ⟹ (- 1) ^ ?n = - 1›*) card_eq_sum (*‹card ?A = (∑x∈?A. 1)›*) of_nat_1 (*‹of_nat 1 = 1›*) of_nat_sum (*‹of_nat (sum ?f ?A) = (∑x∈?A. of_nat (?f x))›*) sum_mono (*‹(⋀i. i ∈ ?K ⟹ ?f i ≤ ?g i) ⟹ sum ?f ?K ≤ sum ?g ?K›*)) (*discuss goal 2*) apply (smt (verit) assms (*‹finite A›*) neg_one_even_power (*‹even ?n ⟹ (- 1) ^ ?n = 1›*) neg_one_odd_power (*‹odd ?n ⟹ (- 1) ^ ?n = - 1›*) card_eq_sum (*‹card ?A = (∑x∈?A. 1)›*) of_nat_1 (*‹of_nat 1 = 1›*) of_nat_sum (*‹of_nat (sum ?f ?A) = (∑x∈?A. of_nat (?f x))›*) sum_mono (*‹(⋀i. i ∈ ?K ⟹ ?f i ≤ ?g i) ⟹ sum ?f ?K ≤ sum ?g ?K›*) sum_negf (*‹(∑x∈?A. - ?f x) = - sum ?f ?A›*)) (*proven 2 subgoals*) . lemma aux_comp_with_cmod: fixes g:: "nat ⇒ nat" assumes "(∀x<2^n. g x = 0) ∨ (∀x<2^n. g x = 1)" shows "(cmod (∑k<2^n. (-1)^(g k)))² = 2^(2*n)" proof (rule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹?P ∨ ?Q› 2. ‹?P ⟹ (cmod (∑k<2 ^ n. (- 1) ^ g k))² = 2 ^ (2 * n)› 3. ‹?Q ⟹ (cmod (∑k<2 ^ n. (- 1) ^ g k))² = 2 ^ (2 * n)›*) show "(∀x<2^n. g x = 0) ∨ (∀x<2^n. g x = 1)" using assms (*‹(∀x<2 ^ n. g x = 0) ∨ (∀x<2 ^ n. g x = 1)›*) by simp next (*goals: 1. ‹∀x<2 ^ n. g x = 0 ⟹ (cmod (∑k<2 ^ n. (- 1) ^ g k))² = 2 ^ (2 * n)› 2. ‹∀x<2 ^ n. g x = 1 ⟹ (cmod (∑k<2 ^ n. (- 1) ^ g k))² = 2 ^ (2 * n)›*) assume "∀x<2^n. g x = 0" (*‹∀x<(2::nat) ^ (n::nat). (g::nat ⇒ nat) x = (0::nat)›*) then have "(cmod (∑k<2^n. (-1)^(g k)))² = (2^n)²" by (simp add: norm_power (*‹norm ((?x::?'a) ^ (?n::nat)) = norm ?x ^ ?n›*)) then show "?thesis" (*goal: ‹(cmod (∑k::nat<(2::nat) ^ (n::nat). (- (1::complex)) ^ (g::nat ⇒ nat) k))² = (2::real) ^ ((2::nat) * n)›*) by (simp add: power_even_eq (*‹?a ^ (2 * ?n) = (?a ^ ?n)²›*)) next (*goal: ‹∀x<2 ^ n. g x = 1 ⟹ (cmod (∑k<2 ^ n. (- 1) ^ g k))² = 2 ^ (2 * n)›*) assume "∀x<2^n. g x = 1" (*‹∀x<(2::nat) ^ (n::nat). (g::nat ⇒ nat) x = (1::nat)›*) then have "(cmod (∑k<2^n. (-1)^(g k)))² = (2^n)²" by (simp add: norm_power (*‹norm ((?x::?'a::real_normed_div_algebra) ^ (?n::nat)) = norm ?x ^ ?n›*)) then show "?thesis" (*goal: ‹(cmod (∑k<2 ^ n. (- 1) ^ g k))² = 2 ^ (2 * n)›*) by (simp add: power_even_eq (*‹?a ^ (2 * ?n) = (?a ^ ?n)²›*)) qed lemma cmod_less: fixes a n:: int assumes "a < n" and "a > -n" shows "cmod a < n" using assms (*‹a < n› ‹- n < a›*) by simp lemma square_less: fixes a n:: real assumes "a < n" and "a > -n" shows "a² < n²" using assms (*‹a < n› ‹- (n::real) < (a::real)›*) by (smt (verit) power2_eq_iff (*‹(?x² = ?y²) = (?x = ?y ∨ ?x = - ?y)›*) power2_minus (*‹(- ?a)² = ?a²›*) power_less_imp_less_base (*‹⟦?a ^ ?n < ?b ^ ?n; 0 ≤ ?b⟧ ⟹ ?a < ?b›*)) lemma cmod_square_real [simp]: fixes n:: real shows "(cmod n)² = n²" by simp lemma aux_comp_sum_divide_cmod: fixes n:: nat and g:: "nat ⇒ int" and a:: real shows "(cmod(complex_of_real(∑k<n. g k / a)))² = (cmod (∑k<n. g k) / a)²" by (metis cmod_square_real (*‹(cmod (complex_of_real (?n::real)))² = ?n²›*) of_int_sum (*‹of_int (sum (?f::?'b::type ⇒ int) (?A::?'b::type set)) = (∑x::?'b::type∈?A. of_int (?f x))›*) of_real_of_int_eq (*‹of_real (real_of_int (?z::int)) = of_int ?z›*) power_divide (*‹((?a::?'a::field) / (?b::?'a::field)) ^ (?n::nat) = ?a ^ ?n / ?b ^ ?n›*) sum_divide_distrib (*‹sum (?f::?'b::type ⇒ ?'a::field) (?A::?'b::type set) / (?r::?'a::field) = (∑n::?'b::type∈?A. ?f n / ?r)›*)) text ‹ The function is constant if and only if the first n qubits are 0. So, if the function is constant, then the probability of measuring 0 for the first n qubits is 1. › lemma (in jozsa) prob0_jozsa_algo_of_const_0: assumes "const 0" shows "prob0_fst_qubits n jozsa_algo = 1" proof (-) (*goal: ‹prob0_fst_qubits n jozsa_algo = 1›*) have "prob0_fst_qubits n jozsa_algo = (∑j∈{0,1}. (cmod(jozsa_algo $$ (j,0)))²)" using prob0_fst_qubits_of_jozsa_algo (*‹prob0_fst_qubits (n::nat) jozsa_algo = (∑j::nat∈{0::nat, 1::nat}. (cmod (jozsa_algo $$ (j, 0::nat)))²)›*) by simp moreover have "(cmod(jozsa_algo $$ (0,0)))² = 1/2" proof (-) (*goal: ‹(cmod (jozsa_algo $$ (0, 0)))² = 1 / 2›*) have "k<2^n ⟶ ((0 div 2) ⋅⇘n⇙ k) = 0" for k :: nat using bitwise_inner_prod_with_zero (*‹(?m::nat) < (2::nat) ^ (?n::nat) ⟹ 0::nat ⋅⇘?n⇙ ?m = (0::nat)›*) by simp then have "(cmod(jozsa_algo $$ (0,0)))² = (cmod(∑k::nat<2^n. 1/(sqrt(2)^n * sqrt(2)^(n+1))))²" using jozsa_algo_result (*‹jozsa_algo = Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ ((f::nat ⇒ nat) k + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))) else ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ (f k + (1::nat) + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat)))))›*) const_def (*‹const ?c = (∀x∈{i. i < 2 ^ n}. f x = ?c)›*) assms (*‹const 0›*) by simp also (*calculation: ‹(cmod (jozsa_algo $$ (0, 0)))² = (cmod (complex_of_real (∑k<2 ^ n. 1 / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))²›*) have "... = (cmod((2::nat)^n/(sqrt(2)^n * sqrt(2)^(n+1))))²" by simp also (*calculation: ‹(cmod (jozsa_algo $$ (0, 0)))² = (cmod (complex_of_real (real (2 ^ n) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))²›*) have "... = (cmod(1/(sqrt(2))))²" using aux_comp_with_sqrt2_bis (*‹2 ^ ?n / (sqrt 2 ^ ?n * sqrt 2 ^ (?n + 1)) = 1 / sqrt 2›*) by simp also (*calculation: ‹(cmod (jozsa_algo $$ (0::nat, 0::nat)))² = (cmod (complex_of_real ((1::real) / sqrt (2::real))))²›*) have "... = 1/2" by (simp add: norm_divide (*‹norm (?a / ?b) = norm ?a / norm ?b›*) power2_eq_square (*‹?a² = ?a * ?a›*)) finally (*calculation: ‹(cmod (jozsa_algo $$ (0, 0)))² = 1 / 2›*) show "?thesis" (*goal: ‹(cmod (jozsa_algo $$ (0, 0)))² = 1 / 2›*) by simp qed moreover have "(cmod(jozsa_algo $$ (1,0)))² = 1/2" proof (-) (*goal: ‹(cmod (jozsa_algo $$ (1, 0)))² = 1 / 2›*) have "k<2^n ⟶ ((1 div 2) ⋅⇘n⇙ k) = 0" for k :: nat using bitwise_inner_prod_with_zero (*‹(?m::nat) < (2::nat) ^ (?n::nat) ⟹ 0::nat ⋅⇘?n⇙ ?m = (0::nat)›*) by simp then have "k<2^n ⟶ f k + 1 + ((1 div 2) ⋅⇘n⇙ k) = 1" for k :: nat using const_def (*‹const ?c = (∀x∈{i. i < 2 ^ n}. f x = ?c)›*) assms (*‹const 0›*) by simp moreover have "(cmod(jozsa_algo $$ (1,0)))² = (cmod (∑k::nat<2^n. (-1)^(f k + 1 + ((1 div 2) ⋅⇘n⇙ k))/(sqrt(2)^n * sqrt(2)^(n+1))))²" using "ψ₃_dim" (*‹1 < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))›*) by simp ultimately have "(cmod(jozsa_algo $$ (1,0)))² = (cmod(∑k::nat<2^n. -1/(sqrt(2)^n * sqrt(2)^(n+1))))²" by (smt (verit) lessThan_iff (*‹(?i ∈ {..<?k}) = (?i < ?k)›*) power_one_right (*‹?a ^ 1 = ?a›*) sum.cong (*‹⟦?A = ?B; ⋀x. x ∈ ?B ⟹ ?g x = ?h x⟧ ⟹ sum ?g ?A = sum ?h ?B›*)) also (*calculation: ‹(cmod (jozsa_algo $$ (1, 0)))² = (cmod (complex_of_real (∑k<2 ^ n. - 1 / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))²›*) have "... = (cmod(-1/(sqrt(2))))²" using aux_comp_with_sqrt2_bis (*‹2 ^ ?n / (sqrt 2 ^ ?n * sqrt 2 ^ (?n + 1)) = 1 / sqrt 2›*) by simp also (*calculation: ‹(cmod (jozsa_algo $$ (1, 0)))² = (cmod (complex_of_real (- 1 / sqrt 2)))²›*) have "... = 1/2" by (simp add: norm_divide (*‹norm (?a / ?b) = norm ?a / norm ?b›*) power2_eq_square (*‹?a² = ?a * ?a›*)) finally (*calculation: ‹(cmod (jozsa_algo $$ (1::nat, 0::nat)))² = (1::real) / (2::real)›*) show "?thesis" (*goal: ‹(cmod (jozsa_algo $$ (1::nat, 0::nat)))² = (1::real) / (2::real)›*) by simp qed ultimately have "prob0_fst_qubits n jozsa_algo = 1/2 + 1/2" by simp then show "?thesis" (*goal: ‹prob0_fst_qubits n jozsa_algo = 1›*) by simp qed lemma (in jozsa) prob0_jozsa_algo_of_const_1: assumes "const 1" shows "prob0_fst_qubits n jozsa_algo = 1" proof (-) (*goal: ‹prob0_fst_qubits n jozsa_algo = 1›*) have "prob0_fst_qubits n jozsa_algo = (∑j∈{0,1}. (cmod(jozsa_algo $$ (j,0)))²)" using prob0_fst_qubits_of_jozsa_algo (*‹prob0_fst_qubits n jozsa_algo = (∑j∈{0, 1}. (cmod (jozsa_algo $$ (j, 0)))²)›*) by simp moreover have "(cmod(jozsa_algo $$ (0,0)))² = 1/2" proof (-) (*goal: ‹(cmod (jozsa_algo $$ (0::nat, 0::nat)))² = (1::real) / (2::real)›*) have "k<2^n ⟶ ((0 div 2) ⋅⇘n⇙ k) = 0" for k :: nat using bitwise_inner_prod_with_zero (*‹?m < 2 ^ ?n ⟹ 0 ⋅⇘?n⇙ ?m = 0›*) by simp then have "(cmod(jozsa_algo $$ (0,0)))² = (cmod(∑k::nat<2^n. 1/(sqrt(2)^n * sqrt(2)^(n+1))))²" using jozsa_algo_result (*‹jozsa_algo = Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1))))›*) const_def (*‹const ?c = (∀x∈{i. i < 2 ^ n}. f x = ?c)›*) assms (*‹const 1›*) by simp also (*calculation: ‹(cmod (jozsa_algo $$ (0, 0)))² = (cmod (complex_of_real (∑k<2 ^ n. 1 / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))²›*) have "... = (cmod((-1)/(sqrt(2))))² " using aux_comp_with_sqrt2_bis (*‹2 ^ ?n / (sqrt 2 ^ ?n * sqrt 2 ^ (?n + 1)) = 1 / sqrt 2›*) by simp also (*calculation: ‹(cmod (jozsa_algo $$ (0, 0)))² = (cmod (complex_of_real (- 1 / sqrt 2)))²›*) have "... = 1/2" by (simp add: norm_divide (*‹norm ((?a::?'a) / (?b::?'a)) = norm ?a / norm ?b›*) power2_eq_square (*‹(?a::?'a)² = ?a * ?a›*)) finally (*calculation: ‹(cmod (jozsa_algo $$ (0, 0)))² = 1 / 2›*) show "?thesis" (*goal: ‹(cmod (jozsa_algo $$ (0, 0)))² = 1 / 2›*) by simp qed moreover have "(cmod(jozsa_algo $$ (1,0)))² = 1/2" proof (-) (*goal: ‹(cmod (jozsa_algo $$ (1::nat, 0::nat)))² = (1::real) / (2::real)›*) have "k<2^n ⟶ ((1 div 2) ⋅⇘n⇙ k) = 0" for k :: nat using bitwise_inner_prod_with_zero (*‹?m < 2 ^ ?n ⟹ 0 ⋅⇘?n⇙ ?m = 0›*) by simp then have "(∑k::nat<2^n. (-1)^(f k +1 + ((1 div 2) ⋅⇘n⇙ k))/(sqrt(2)^n * sqrt(2)^(n+1))) = (∑k::nat<2^n. 1/(sqrt(2)^n * sqrt(2)^(n+1)))" using const_def (*‹const (?c::nat) = (∀x::nat∈{i::nat. i < (2::nat) ^ (n::nat)}. (f::nat ⇒ nat) x = ?c)›*) assms (*‹const (1::nat)›*) by simp moreover have "(cmod(jozsa_algo $$ (1,0)))² = (cmod (∑k::nat<2^n. (-1)^(f k + 1 + ((1 div 2) ⋅⇘n⇙ k))/(sqrt(2)^n * sqrt(2)^(n+1))))²" using "ψ₃_dim" (*‹(1::nat) < dim_row (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ ((f::nat ⇒ nat) k + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))) else ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ (f k + (1::nat) + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))))))›*) by simp ultimately have "(cmod(jozsa_algo $$ (1,0)))² = (cmod(∑k::nat<2^n. 1/(sqrt(2)^n * sqrt(2)^(n+1))))²" by simp also (*calculation: ‹(cmod (jozsa_algo $$ (1, 0)))² = (cmod (complex_of_real (∑k<2 ^ n. 1 / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))²›*) have "... = (cmod(1/(sqrt(2))))² " using aux_comp_with_sqrt2_bis (*‹2 ^ ?n / (sqrt 2 ^ ?n * sqrt 2 ^ (?n + 1)) = 1 / sqrt 2›*) by simp also (*calculation: ‹(cmod (jozsa_algo $$ (1::nat, 0::nat)))² = (cmod (complex_of_real ((1::real) / sqrt (2::real))))²›*) have "... = 1/2" by (simp add: norm_divide (*‹norm (?a / ?b) = norm ?a / norm ?b›*) power2_eq_square (*‹?a² = ?a * ?a›*)) finally (*calculation: ‹(cmod (jozsa_algo $$ (1, 0)))² = 1 / 2›*) show "?thesis" (*goal: ‹(cmod (jozsa_algo $$ (1, 0)))² = 1 / 2›*) by simp qed ultimately have "prob0_fst_qubits n jozsa_algo = 1/2 + 1/2" by simp then show "?thesis" (*goal: ‹prob0_fst_qubits n jozsa_algo = 1›*) by simp qed text ‹If the probability of measuring 0 for the first n qubits is 1, then the function is constant.› lemma (in jozsa) max_value_of_not_const_less: assumes "¬ const 0" and "¬ const 1" shows "(cmod (∑k::nat<2^n. (-(1::nat))^(f k)))² < (2::nat)^(2*n)" proof (-) (*goal: ‹(cmod (complex_of_int (∑k<2 ^ n. (- int 1) ^ f k)))² < real (2 ^ (2 * n))›*) have "cmod (∑k::nat<2^n. (-(1::nat))^(f k)) < 2^n" proof (-) (*goal: ‹cmod (complex_of_int (∑k::nat<(2::nat) ^ (n::nat). (- int (1::nat)) ^ (f::nat ⇒ nat) k)) < (2::real) ^ n›*) have "(∑k::nat<2^n. (-(1::nat))^(f k)) < 2^n" proof (-) (*goal: ‹(∑k<2 ^ n. (- int 1) ^ f k) < 2 ^ n›*) obtain x where f0: "x < 2^n" and f1: "f x = 1" (*goal: ‹(⋀x. ⟦x < 2 ^ n; f x = 1⟧ ⟹ thesis) ⟹ thesis›*) using assms(1) (*‹¬ const 0›*) const_def (*‹const (?c::nat) = (∀x::nat∈{i::nat. i < (2::nat) ^ (n::nat)}. (f::nat ⇒ nat) x = ?c)›*) f_values (*‹∀x∈{i. i < 2 ^ n}. f x = 0 ∨ f x = 1›*) by auto then have "(∑k::nat<2^n. (-(1::nat))^(f k)) < (∑k∈{i| i:: nat. i < 2^n}-{x}. (-(1::nat))^(f k))" proof (-) (*goal: ‹⟦x < 2 ^ n; f x = 1⟧ ⟹ (∑k<2 ^ n. (- int 1) ^ f k) < (∑k∈{i |i. i < 2 ^ n} - {x}. (- int 1) ^ f k)›*) have "(-(1::nat))^ f x = -1" using f1 (*‹f x = 1›*) by simp moreover have "x∈{i| i::nat. i<2^n}" using f0 (*‹x < 2 ^ n›*) by simp moreover have "finite {i| i::nat. i<2^n}" by simp moreover have "(∑k∈{i| i::nat. i<2^n}. (-(1::nat))^(f k)) < (∑k∈{i| i:: nat. i<2^n}-{x}. (-(1::nat))^(f k))" using calculation(1,2,3) (*‹(- int 1) ^ f x = - 1› ‹x ∈ {i |i. i < 2 ^ n}› ‹finite {i |i::nat. i < (2::nat) ^ (n::nat)}›*) sum_diff1 (*‹finite ?A ⟹ sum ?f (?A - {?a}) = (if ?a ∈ ?A then sum ?f ?A - ?f ?a else sum ?f ?A)›*) by (simp add: sum_diff1 (*‹finite ?A ⟹ sum ?f (?A - {?a}) = (if ?a ∈ ?A then sum ?f ?A - ?f ?a else sum ?f ?A)›*)) ultimately show "?thesis" (*goal: ‹(∑k<2 ^ n. (- int 1) ^ f k) < (∑k∈{i |i. i < 2 ^ n} - {x}. (- int 1) ^ f k)›*) by (metis Collect_cong (*‹(⋀x. ?P x = ?Q x) ⟹ {x. ?P x} = {x. ?Q x}›*) Collect_mem_eq (*‹{x. x ∈ ?A} = ?A›*) lessThan_iff (*‹(?i ∈ {..<?k}) = (?i < ?k)›*)) qed moreover have "… ≤ int (2^n - 1)" using aux_ineq_with_card(1)[of "{i| i:: nat. i<2^n}-{x}"] (*‹finite ({i |i. i < 2 ^ n} - {x}) ⟹ (∑k∈{i |i. i < 2 ^ n} - {x}. (- 1) ^ ?g k) ≤ int (card ({i |i. i < 2 ^ n} - {x}))›*) f0 (*‹x < 2 ^ n›*) by simp ultimately show "?thesis" (*goal: ‹(∑k<2 ^ n. (- int 1) ^ f k) < 2 ^ n›*) by (meson diff_le_self (*‹?m - ?n ≤ ?m›*) less_le_trans (*‹⟦?x < ?y; ?y ≤ ?z⟧ ⟹ ?x < ?z›*) of_nat_le_numeral_power_cancel_iff (*‹(of_nat ?x ≤ numeral ?i ^ ?n) = (?x ≤ numeral ?i ^ ?n)›*)) qed moreover have "(∑k::nat<2^n. (-(1::nat))^(f k)) > - (2^n)" proof (-) (*goal: ‹- ((2::int) ^ (n::nat)) < (∑k::nat<(2::nat) ^ n. (- int (1::nat)) ^ (f::nat ⇒ nat) k)›*) obtain x where f0: "x < 2^n" and f1: "f x = 0" (*goal: ‹(⋀x. ⟦x < 2 ^ n; f x = 0⟧ ⟹ thesis) ⟹ thesis›*) using assms(2) (*‹¬ const 1›*) const_def (*‹const ?c = (∀x∈{i. i < 2 ^ n}. f x = ?c)›*) f_values (*‹∀x∈{i. i < 2 ^ n}. f x = 0 ∨ f x = 1›*) by auto then have "(∑k::nat<2^n. (-(1::nat))^(f k)) > (∑k∈{i| i:: nat. i < 2^n}-{x}. (-(1::nat))^(f k))" proof (-) (*goal: ‹⟦(x::nat) < (2::nat) ^ (n::nat); (f::nat ⇒ nat) x = (0::nat)⟧ ⟹ (∑k::nat∈{i |i::nat. i < (2::nat) ^ n} - {x}. (- int (1::nat)) ^ f k) < (∑k::nat<(2::nat) ^ n. (- int (1::nat)) ^ f k)›*) have "(-(1::nat))^ f x = 1" using f1 (*‹f x = 0›*) by simp moreover have "x∈{i| i::nat. i<2^n}" using f0 (*‹x < 2 ^ n›*) by simp moreover have "finite {i| i::nat. i<2^n}" by simp moreover have "(∑k∈{i| i::nat. i<2^n}. (-(1::nat))^(f k)) > (∑k∈{i| i:: nat. i<2^n}-{x}. (-(1::nat))^(f k))" using calculation(1,2,3) (*‹(- int 1) ^ f x = 1› ‹x ∈ {i |i. i < 2 ^ n}› ‹finite {i |i. i < 2 ^ n}›*) sum_diff1 (*‹finite ?A ⟹ sum ?f (?A - {?a}) = (if ?a ∈ ?A then sum ?f ?A - ?f ?a else sum ?f ?A)›*) by (simp add: sum_diff1 (*‹finite ?A ⟹ sum ?f (?A - {?a}) = (if ?a ∈ ?A then sum ?f ?A - ?f ?a else sum ?f ?A)›*)) ultimately show "?thesis" (*goal: ‹(∑k∈{i |i. i < 2 ^ n} - {x}. (- int 1) ^ f k) < (∑k<2 ^ n. (- int 1) ^ f k)›*) by (metis Collect_cong (*‹(⋀x. ?P x = ?Q x) ⟹ {x. ?P x} = {x. ?Q x}›*) Collect_mem_eq (*‹{x. x ∈ ?A} = ?A›*) lessThan_iff (*‹(?i ∈ {..<?k}) = (?i < ?k)›*)) qed moreover have "- int (2^n - 1) ≤ (∑k∈{i| i:: nat. i < 2^n}-{x}. (-(1::nat))^(f k))" using aux_ineq_with_card(2)[of "{i| i:: nat. i<2^n}-{x}"] (*‹finite ({i |i. i < 2 ^ n} - {x}) ⟹ - int (card ({i |i. i < 2 ^ n} - {x})) ≤ (∑k∈{i |i. i < 2 ^ n} - {x}. (- 1) ^ ?g k)›*) f0 (*‹x < 2 ^ n›*) by simp ultimately show "?thesis" (*goal: ‹- (2 ^ n) < (∑k<2 ^ n. (- int 1) ^ f k)›*) by (smt (verit) diff_le_self (*‹?m - ?n ≤ ?m›*) of_nat_1 (*‹of_nat 1 = 1›*) of_nat_add (*‹of_nat (?m + ?n) = of_nat ?m + of_nat ?n›*) of_nat_power_le_of_nat_cancel_iff (*‹(of_nat ?x ≤ of_nat ?b ^ ?w) = (?x ≤ ?b ^ ?w)›*) one_add_one (*‹1 + 1 = 2›*)) qed ultimately show "?thesis" (*goal: ‹cmod (complex_of_int (∑k::nat<(2::nat) ^ (n::nat). (- int (1::nat)) ^ (f::nat ⇒ nat) k)) < (2::real) ^ n›*) using cmod_less (*‹⟦?a < ?n; - ?n < ?a⟧ ⟹ cmod (complex_of_int ?a) < real_of_int ?n›*) of_int_of_nat_eq (*‹of_int (int (?n::nat)) = of_nat ?n›*) of_nat_numeral (*‹of_nat (numeral ?n) = numeral ?n›*) of_nat_power (*‹of_nat (?m ^ ?n) = of_nat ?m ^ ?n›*) by (metis (no_types, lifting)) qed then have "(cmod (∑k::nat<2^n. (-(1::nat))^(f k)))² < (2^n)²" using square_less (*‹⟦?a < ?n; - ?n < ?a⟧ ⟹ ?a² < ?n²›*) norm_ge_zero (*‹0 ≤ norm ?x›*) by (smt (verit)) thus "?thesis" (*goal: ‹(cmod (complex_of_int (∑k::nat<(2::nat) ^ (n::nat). (- int (1::nat)) ^ (f::nat ⇒ nat) k)))² < real ((2::nat) ^ ((2::nat) * n))›*) by (simp add: power_even_eq (*‹(?a::?'a) ^ ((2::nat) * (?n::nat)) = (?a ^ ?n)²›*)) qed lemma (in jozsa) max_value_of_not_const_less_bis: assumes "¬ const 0" and "¬ const 1" shows "(cmod (∑k::nat<2^n. (-(1::nat))^(f k + 1)))² < (2::nat)^(2*n)" proof (-) (*goal: ‹(cmod (complex_of_int (∑k<2 ^ n. (- int 1) ^ (f k + 1))))² < real (2 ^ (2 * n))›*) have "cmod (∑k::nat<2^n. (-(1::nat))^(f k + 1)) < 2^n" proof (-) (*goal: ‹cmod (complex_of_int (∑k::nat<(2::nat) ^ (n::nat). (- int (1::nat)) ^ ((f::nat ⇒ nat) k + (1::nat)))) < (2::real) ^ n›*) have "(∑k::nat<2^n. (-(1::nat))^(f k + 1)) < 2^n" proof (-) (*goal: ‹(∑k<2 ^ n. (- int 1) ^ (f k + 1)) < 2 ^ n›*) obtain x where f0: "x < 2^n" and f1: "f x = 0" (*goal: ‹(⋀x. ⟦x < 2 ^ n; f x = 0⟧ ⟹ thesis) ⟹ thesis›*) using assms(2) (*‹¬ const 1›*) const_def (*‹const ?c = (∀x∈{i. i < 2 ^ n}. f x = ?c)›*) f_values (*‹∀x∈{i. i < 2 ^ n}. f x = 0 ∨ f x = 1›*) by auto then have "(∑k::nat<2^n. (-(1::nat))^(f k + 1)) < (∑k∈{i| i:: nat. i < 2^n}-{x}. (-(1::nat))^(f k + 1))" proof (-) (*goal: ‹⟦x < 2 ^ n; f x = 0⟧ ⟹ (∑k<2 ^ n. (- int 1) ^ (f k + 1)) < (∑k∈{i |i. i < 2 ^ n} - {x}. (- int 1) ^ (f k + 1))›*) have "(-(1::nat))^ (f x + 1) = -1" using f1 (*‹(f::nat ⇒ nat) (x::nat) = (0::nat)›*) by simp moreover have "x∈{i| i::nat. i<2^n}" using f0 (*‹x < 2 ^ n›*) by simp moreover have "finite {i| i::nat. i<2^n}" by simp moreover have "(∑k∈{i| i::nat. i<2^n}. (-(1::nat))^(f k + 1)) < (∑k∈{i| i:: nat. i<2^n}-{x}. (-(1::nat))^(f k + 1))" using calculation(1,2,3) (*‹(- int (1::nat)) ^ ((f::nat ⇒ nat) (x::nat) + (1::nat)) = - (1::int)› ‹x ∈ {i |i. i < 2 ^ n}› ‹finite {i |i. i < 2 ^ n}›*) sum_diff1 (*‹finite ?A ⟹ sum ?f (?A - {?a}) = (if ?a ∈ ?A then sum ?f ?A - ?f ?a else sum ?f ?A)›*) by (simp add: sum_diff1 (*‹finite (?A::?'b set) ⟹ sum (?f::?'b ⇒ ?'a) (?A - {?a::?'b}) = (if ?a ∈ ?A then sum ?f ?A - ?f ?a else sum ?f ?A)›*)) ultimately show "?thesis" (*goal: ‹(∑k<2 ^ n. (- int 1) ^ (f k + 1)) < (∑k∈{i |i. i < 2 ^ n} - {x}. (- int 1) ^ (f k + 1))›*) by (metis Collect_cong (*‹(⋀x::?'a::type. (?P::?'a::type ⇒ bool) x = (?Q::?'a::type ⇒ bool) x) ⟹ {x::?'a::type. ?P x} = {x::?'a::type. ?Q x}›*) Collect_mem_eq (*‹{x::?'a::type. x ∈ (?A::?'a::type set)} = ?A›*) lessThan_iff (*‹((?i::?'a::ord) ∈ {..<?k::?'a::ord}) = (?i < ?k)›*)) qed moreover have "… ≤ int (2^n - 1)" using aux_ineq_with_card(1)[of "{i| i:: nat. i<2^n}-{x}" "λk. f k + 1"] (*‹finite ({i |i. i < 2 ^ n} - {x}) ⟹ (∑k∈{i |i. i < 2 ^ n} - {x}. (- 1) ^ (f k + 1)) ≤ int (card ({i |i. i < 2 ^ n} - {x}))›*) f0 (*‹x < 2 ^ n›*) by simp ultimately show "?thesis" (*goal: ‹(∑k<2 ^ n. (- int 1) ^ (f k + 1)) < 2 ^ n›*) by (meson diff_le_self (*‹?m - ?n ≤ ?m›*) less_le_trans (*‹⟦?x < ?y; ?y ≤ ?z⟧ ⟹ ?x < ?z›*) of_nat_le_numeral_power_cancel_iff (*‹(of_nat ?x ≤ numeral ?i ^ ?n) = (?x ≤ numeral ?i ^ ?n)›*)) qed moreover have "(∑k::nat<2^n. (-(1::nat))^(f k + 1)) > - (2^n)" proof (-) (*goal: ‹- (2 ^ n) < (∑k<2 ^ n. (- int 1) ^ (f k + 1))›*) obtain x where f0: "x < 2^n" and f1: "f x = 1" (*goal: ‹(⋀x::nat. ⟦x < (2::nat) ^ (n::nat); (f::nat ⇒ nat) x = (1::nat)⟧ ⟹ thesis::bool) ⟹ thesis›*) using assms(1) (*‹¬ const 0›*) const_def (*‹const (?c::nat) = (∀x::nat∈{i::nat. i < (2::nat) ^ (n::nat)}. (f::nat ⇒ nat) x = ?c)›*) f_values (*‹∀x∈{i. i < 2 ^ n}. f x = 0 ∨ f x = 1›*) by auto then have "(∑k::nat<2^n. (-(1::nat))^(f k + 1)) > (∑k∈{i| i:: nat. i < 2^n}-{x}. (-(1::nat))^(f k + 1))" proof (-) (*goal: ‹⟦x < 2 ^ n; f x = 1⟧ ⟹ (∑k∈{i |i. i < 2 ^ n} - {x}. (- int 1) ^ (f k + 1)) < (∑k<2 ^ n. (- int 1) ^ (f k + 1))›*) have "(-(1::nat))^ (f x + 1) = 1" using f1 (*‹f x = 1›*) by simp moreover have "x∈{i| i::nat. i<2^n}" using f0 (*‹x < 2 ^ n›*) by simp moreover have "finite {i| i::nat. i<2^n}" by simp moreover have "(∑k∈{i| i::nat. i<2^n}. (-(1::nat))^(f k + 1)) > (∑k∈{i| i:: nat. i<2^n}-{x}. (-(1::nat))^(f k + 1))" using calculation(1,2,3) (*‹(- int 1) ^ (f x + 1) = 1› ‹(x::nat) ∈ {i |i::nat. i < (2::nat) ^ (n::nat)}› ‹finite {i |i. i < 2 ^ n}›*) sum_diff1 (*‹finite ?A ⟹ sum ?f (?A - {?a}) = (if ?a ∈ ?A then sum ?f ?A - ?f ?a else sum ?f ?A)›*) by (simp add: sum_diff1 (*‹finite ?A ⟹ sum ?f (?A - {?a}) = (if ?a ∈ ?A then sum ?f ?A - ?f ?a else sum ?f ?A)›*)) ultimately show "?thesis" (*goal: ‹(∑k∈{i |i. i < 2 ^ n} - {x}. (- int 1) ^ (f k + 1)) < (∑k<2 ^ n. (- int 1) ^ (f k + 1))›*) by (metis Collect_cong (*‹(⋀x. ?P x = ?Q x) ⟹ {x. ?P x} = {x. ?Q x}›*) Collect_mem_eq (*‹{x. x ∈ ?A} = ?A›*) lessThan_iff (*‹(?i ∈ {..<?k}) = (?i < ?k)›*)) qed moreover have "- int (2^n - 1) ≤ (∑k∈{i| i:: nat. i < 2^n}-{x}. (-(1::nat))^(f k + 1))" using aux_ineq_with_card(2)[of "{i| i:: nat. i<2^n}-{x}" "λk. f k + 1"] (*‹finite ({i |i. i < 2 ^ n} - {x}) ⟹ - int (card ({i |i. i < 2 ^ n} - {x})) ≤ (∑k∈{i |i. i < 2 ^ n} - {x}. (- 1) ^ (f k + 1))›*) f0 (*‹(x::nat) < (2::nat) ^ (n::nat)›*) by simp ultimately show "?thesis" (*goal: ‹- (2 ^ n) < (∑k<2 ^ n. (- int 1) ^ (f k + 1))›*) by (smt (verit) diff_le_self (*‹?m - ?n ≤ ?m›*) of_nat_1 (*‹of_nat 1 = 1›*) of_nat_add (*‹of_nat (?m + ?n) = of_nat ?m + of_nat ?n›*) of_nat_power_le_of_nat_cancel_iff (*‹(of_nat ?x ≤ of_nat ?b ^ ?w) = (?x ≤ ?b ^ ?w)›*) one_add_one (*‹1 + 1 = 2›*)) qed ultimately show "?thesis" (*goal: ‹cmod (complex_of_int (∑k<2 ^ n. (- int 1) ^ (f k + 1))) < 2 ^ n›*) using cmod_less (*‹⟦?a < ?n; - ?n < ?a⟧ ⟹ cmod (complex_of_int ?a) < real_of_int ?n›*) of_int_of_nat_eq (*‹of_int (int ?n) = of_nat ?n›*) of_nat_numeral (*‹of_nat (numeral ?n) = numeral ?n›*) of_nat_power (*‹of_nat (?m ^ ?n) = of_nat ?m ^ ?n›*) by (metis (no_types, lifting)) qed then have "(cmod (∑k::nat<2^n. (-(1::nat))^(f k + 1)))² < (2^n)²" using square_less (*‹⟦?a < ?n; - ?n < ?a⟧ ⟹ ?a² < ?n²›*) norm_ge_zero (*‹0 ≤ norm ?x›*) by (smt (verit)) thus "?thesis" (*goal: ‹(cmod (complex_of_int (∑k<2 ^ n. (- int 1) ^ (f k + 1))))² < real (2 ^ (2 * n))›*) by (simp add: power_even_eq (*‹?a ^ (2 * ?n) = (?a ^ ?n)²›*)) qed lemma (in jozsa) f_const_has_max_value: assumes "const 0 ∨ const 1" shows "(cmod (∑k<(2::nat)^n. (-1)^(f k)))² = (2::nat)^(2*n)" and "(cmod (∑k<(2::nat)^n. (-1)^(f k + 1)))² = (2::nat)^(2*n)" using aux_comp_with_cmod[of n "λk. f k"] (*‹(∀x<2 ^ n. f x = 0) ∨ (∀x<2 ^ n. f x = 1) ⟹ (cmod (∑k<2 ^ n. (- 1) ^ f k))² = 2 ^ (2 * n)›*) aux_comp_with_cmod[of n "λk. f k + 1"] (*‹(∀x<2 ^ n. f x + 1 = 0) ∨ (∀x<2 ^ n. f x + 1 = 1) ⟹ (cmod (∑k<2 ^ n. (- 1) ^ (f k + 1)))² = 2 ^ (2 * n)›*) const_def (*‹const ?c = (∀x∈{i. i < 2 ^ n}. f x = ?c)›*) assms (*‹const (0::nat) ∨ const (1::nat)›*) apply - (*goals: 1. ‹⟦(∀x<2 ^ n. f x = 0) ∨ (∀x<2 ^ n. f x = 1) ⟹ (cmod (∑k<2 ^ n. (- 1) ^ f k))² = 2 ^ (2 * n); (∀x<2 ^ n. f x + 1 = 0) ∨ (∀x<2 ^ n. f x + 1 = 1) ⟹ (cmod (∑k<2 ^ n. (- 1) ^ (f k + 1)))² = 2 ^ (2 * n); ⋀c. const c = (∀x∈{i. i < 2 ^ n}. f x = c); const 0 ∨ const 1⟧ ⟹ (cmod (∑k<2 ^ n. (- 1) ^ f k))² = real (2 ^ (2 * n))› 2. ‹⟦(∀x<2 ^ n. f x = 0) ∨ (∀x<2 ^ n. f x = 1) ⟹ (cmod (∑k<2 ^ n. (- 1) ^ f k))² = 2 ^ (2 * n); (∀x<2 ^ n. f x + 1 = 0) ∨ (∀x<2 ^ n. f x + 1 = 1) ⟹ (cmod (∑k<2 ^ n. (- 1) ^ (f k + 1)))² = 2 ^ (2 * n); ⋀c. const c = (∀x∈{i. i < 2 ^ n}. f x = c); const 0 ∨ const 1⟧ ⟹ (cmod (∑k<2 ^ n. (- 1) ^ (f k + 1)))² = real (2 ^ (2 * n))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma (in jozsa) prob0_fst_qubits_leq: shows "(cmod (∑k<(2::nat)^n. (-1)^(f k)))² ≤ (2::nat)^(2*n)" and "(cmod (∑k<(2::nat)^n. (-1)^(f k + 1)))² ≤ (2::nat)^(2*n)" proof (-) (*goals: 1. ‹(cmod (∑k<2 ^ n. (- 1) ^ f k))² ≤ real (2 ^ (2 * n))› 2. ‹(cmod (∑k<2 ^ n. (- 1) ^ (f k + 1)))² ≤ real (2 ^ (2 * n))›*) show "(cmod (∑k<(2::nat)^n. (-1)^(f k)))² ≤ (2::nat)^(2*n)" proof (rule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹(?P::bool) ∨ (?Q::bool)› 2. ‹?P::bool ⟹ (cmod (∑k::nat<(2::nat) ^ (n::nat). (- (1::complex)) ^ (f::nat ⇒ nat) k))² ≤ real ((2::nat) ^ ((2::nat) * n))› 3. ‹?Q::bool ⟹ (cmod (∑k::nat<(2::nat) ^ (n::nat). (- (1::complex)) ^ (f::nat ⇒ nat) k))² ≤ real ((2::nat) ^ ((2::nat) * n))›*) show "(const 0 ∨ const 1) ∨ (¬ const 0 ∧ ¬ const 1)" by auto next (*goals: 1. ‹const 0 ∨ const 1 ⟹ (cmod (∑k<2 ^ n. (- 1) ^ f k))² ≤ real (2 ^ (2 * n))› 2. ‹¬ const 0 ∧ ¬ const 1 ⟹ (cmod (∑k<2 ^ n. (- 1) ^ f k))² ≤ real (2 ^ (2 * n))›*) assume "const 0 ∨ const 1" (*‹const (0::nat) ∨ const (1::nat)›*) then show "(cmod (∑k<(2::nat)^n. (-1)^(f k)))² ≤ (2::nat)^(2*n)" using f_const_has_max_value (*‹const 0 ∨ const 1 ⟹ (cmod (∑k<2 ^ n. (- 1) ^ f k))² = real (2 ^ (2 * n))› ‹const 0 ∨ const 1 ⟹ (cmod (∑k<2 ^ n. (- 1) ^ (f k + 1)))² = real (2 ^ (2 * n))›*) by simp next (*goal: ‹¬ const (0::nat) ∧ ¬ const (1::nat) ⟹ (cmod (∑k::nat<(2::nat) ^ (n::nat). (- (1::complex)) ^ (f::nat ⇒ nat) k))² ≤ real ((2::nat) ^ ((2::nat) * n))›*) assume "¬ const 0 ∧ ¬ const 1" (*‹¬ const (0::nat) ∧ ¬ const (1::nat)›*) then show "(cmod (∑k<(2::nat)^n. (-1)^(f k)))² ≤ (2::nat)^(2*n)" using max_value_of_not_const_less (*‹⟦¬ const 0; ¬ const 1⟧ ⟹ (cmod (complex_of_int (∑k<2 ^ n. (- int 1) ^ f k)))² < real (2 ^ (2 * n))›*) by simp qed next (*goal: ‹(cmod (∑k<2 ^ n. (- 1) ^ (f k + 1)))² ≤ real (2 ^ (2 * n))›*) show "(cmod (∑k<(2::nat)^n. (-1)^(f k + 1)))² ≤ (2::nat)^(2*n)" proof (rule disjE (*‹⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R›*)) (*goals: 1. ‹?P ∨ ?Q› 2. ‹?P ⟹ (cmod (∑k<2 ^ n. (- 1) ^ (f k + 1)))² ≤ real (2 ^ (2 * n))› 3. ‹?Q ⟹ (cmod (∑k<2 ^ n. (- 1) ^ (f k + 1)))² ≤ real (2 ^ (2 * n))›*) show "(const 0 ∨ const 1) ∨ (¬ const 0 ∧ ¬ const 1)" by auto next (*goals: 1. ‹const 0 ∨ const 1 ⟹ (cmod (∑k<2 ^ n. (- 1) ^ (f k + 1)))² ≤ real (2 ^ (2 * n))› 2. ‹¬ const 0 ∧ ¬ const 1 ⟹ (cmod (∑k<2 ^ n. (- 1) ^ (f k + 1)))² ≤ real (2 ^ (2 * n))›*) assume "const 0 ∨ const 1" (*‹const (0::nat) ∨ const (1::nat)›*) then show "(cmod (∑k<(2::nat)^n. (-1)^(f k + 1)))² ≤ (2::nat)^(2*n)" using f_const_has_max_value (*‹const 0 ∨ const 1 ⟹ (cmod (∑k<2 ^ n. (- 1) ^ f k))² = real (2 ^ (2 * n))› ‹const 0 ∨ const 1 ⟹ (cmod (∑k<2 ^ n. (- 1) ^ (f k + 1)))² = real (2 ^ (2 * n))›*) by simp next (*goal: ‹¬ const 0 ∧ ¬ const 1 ⟹ (cmod (∑k<2 ^ n. (- 1) ^ (f k + 1)))² ≤ real (2 ^ (2 * n))›*) assume "¬ const 0 ∧ ¬ const 1" (*‹¬ const (0::nat) ∧ ¬ const (1::nat)›*) then show "(cmod (∑k<(2::nat)^n. (-1)^(f k + 1)))² ≤ (2::nat)^(2*n)" using max_value_of_not_const_less_bis (*‹⟦¬ const 0; ¬ const 1⟧ ⟹ (cmod (complex_of_int (∑k<2 ^ n. (- int 1) ^ (f k + 1))))² < real (2 ^ (2 * n))›*) by simp qed qed lemma (in jozsa) prob0_jozsa_algo_1_is_const: assumes "prob0_fst_qubits n jozsa_algo = 1" shows "const 0 ∨ const 1" proof (-) (*goal: ‹const (0::nat) ∨ const (1::nat)›*) have f0: "(∑j∈{0,1}. (cmod(jozsa_algo $$ (j,0)))²) = 1" using prob0_fst_qubits_of_jozsa_algo (*‹prob0_fst_qubits n jozsa_algo = (∑j∈{0, 1}. (cmod (jozsa_algo $$ (j, 0)))²)›*) assms (*‹prob0_fst_qubits n jozsa_algo = 1›*) by simp have "k < 2^n⟶((0 div 2) ⋅⇘n⇙ k) = 0" for k :: nat using bitwise_inner_prod_with_zero (*‹?m < 2 ^ ?n ⟹ 0 ⋅⇘?n⇙ ?m = 0›*) by simp then have f1: "(cmod(jozsa_algo $$ (0,0)))² = (cmod(∑k<(2::nat)^n. (-1)^(f k)/(sqrt(2)^n * sqrt(2)^(n+1))))²" by simp have "k < 2^n⟶((1 div 2) ⋅⇘n⇙ k) = 0" for k :: nat using bitwise_inner_prod_with_zero (*‹?m < 2 ^ ?n ⟹ 0 ⋅⇘?n⇙ ?m = 0›*) by simp moreover have "(cmod(jozsa_algo $$ (1,0)))² = (cmod (∑k<(2::nat)^n. (-1)^(f k+ 1 + ((1 div 2) ⋅⇘n⇙ k))/(sqrt(2)^n * sqrt(2)^(n+1))))²" using "ψ₃_dim" (*‹(1::nat) < dim_row (Matrix.mat ((2::nat) ^ ((n::nat) + (1::nat))) (1::nat) (λx::nat × nat. complex_of_real (case x of (i::nat, j::nat) ⇒ if even i then ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ ((f::nat ⇒ nat) k + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))) else ∑k::nat<(2::nat) ^ n. (- (1::real)) ^ (f k + (1::nat) + i div (2::nat) ⋅⇘n⇙ k) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))))))›*) by simp ultimately have f2: "(cmod(jozsa_algo $$ (1,0)))² = (cmod (∑k<(2::nat)^n. (-1)^(f k + 1)/(sqrt(2)^n * sqrt(2)^(n+1))))²" by simp have f3: "1 = (cmod(∑k::nat<(2::nat)^n.(-1)^(f k)/(sqrt(2)^n * sqrt(2)^(n+1))))² + (cmod (∑k::nat<(2::nat)^n. (-1)^(f k + 1)/(sqrt(2)^n * sqrt(2)^(n+1))))²" using f0 (*‹(∑j∈{0, 1}. (cmod (jozsa_algo $$ (j, 0)))²) = 1›*) f1 (*‹(cmod (jozsa_algo $$ (0, 0)))² = (cmod (complex_of_real (∑k<2 ^ n. (- 1) ^ f k / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))²›*) f2 (*‹(cmod (jozsa_algo $$ (1, 0)))² = (cmod (complex_of_real (∑k<2 ^ n. (- 1) ^ (f k + 1) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))²›*) by simp also (*calculation: ‹1 = (cmod (complex_of_real (∑k<2 ^ n. (- 1) ^ f k / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))² + (cmod (complex_of_real (∑k<2 ^ n. (- 1) ^ (f k + 1) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))²›*) have "... = ((cmod (∑k::nat<(2::nat)^n. (-1)^(f k)) ) /(sqrt(2)^n * sqrt(2)^(n+1)))² + ((cmod(∑k::nat<(2::nat)^n. (-1)^(f k + 1))) /(sqrt(2)^n * sqrt(2)^(n+1)))²" using aux_comp_sum_divide_cmod[of "λk. (-1)^(f k)" "(sqrt(2)^n * sqrt(2)^(n+1))" "(2::nat)^n"] (*‹(cmod (complex_of_real (∑k::nat<(2::nat) ^ n. real_of_int ((- (1::int)) ^ (f::nat ⇒ nat) k) / (sqrt (2::real) ^ (n::nat) * sqrt (2::real) ^ (n + (1::nat))))))² = (cmod (complex_of_int (∑k::nat<(2::nat) ^ n. (- (1::int)) ^ f k)) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))))²›*) aux_comp_sum_divide_cmod[of "λk. (-1)^(f k + 1)" "(sqrt(2)^n * sqrt(2)^(n+1))" "(2::nat)^n"] (*‹(cmod (complex_of_real (∑k<2 ^ n. real_of_int ((- 1) ^ (f k + 1)) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))² = (cmod (complex_of_int (∑k<2 ^ n. (- 1) ^ (f k + 1))) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))²›*) by simp also (*calculation: ‹1 = (cmod (∑k<2 ^ n. (- 1) ^ f k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))² + (cmod (∑k<2 ^ n. (- 1) ^ (f k + 1)) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))²›*) have "... = ((cmod (∑k::nat<(2::nat)^n. (-1)^(f k))))² /((sqrt(2)^n * sqrt(2)^(n+1)))² + ((cmod(∑k::nat<(2::nat)^n. (-1)^(f k +1))))² /((sqrt(2)^n * sqrt(2)^(n+1)))²" by (simp add: power_divide (*‹(?a / ?b) ^ ?n = ?a ^ ?n / ?b ^ ?n›*)) also (*calculation: ‹(1::real) = (cmod (∑k::nat<(2::nat) ^ (n::nat). (- (1::complex)) ^ (f::nat ⇒ nat) k))² / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat)))² + (cmod (∑k::nat<(2::nat) ^ n. (- (1::complex)) ^ (f k + (1::nat))))² / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat)))²›*) have "... = ((cmod (∑k::nat<(2::nat)^n. (-1)^(f k)) ) )²/(2^(2*n+1)) + ((cmod(∑k::nat<(2::nat)^n. (-1)^(f k + 1))))² /(2^(2*n+1))" by (smt (verit) left_add_twice (*‹?a + (?a + ?b) = 2 * ?a + ?b›*) power2_eq_square (*‹?a² = ?a * ?a›*) power_add (*‹?a ^ (?m + ?n) = ?a ^ ?m * ?a ^ ?n›*) power_mult_distrib (*‹(?a * ?b) ^ ?n = ?a ^ ?n * ?b ^ ?n›*) real_sqrt_pow2 (*‹0 ≤ ?x ⟹ (sqrt ?x)² = ?x›*)) also (*calculation: ‹1 = (cmod (∑k<2 ^ n. (- 1) ^ f k))² / 2 ^ (2 * n + 1) + (cmod (∑k<2 ^ n. (- 1) ^ (f k + 1)))² / 2 ^ (2 * n + 1)›*) have "... = (((cmod (∑k::nat<(2::nat)^n. (-1)^(f k))))² + ((cmod(∑k::nat<(2::nat)^n. (-1)^(f k + 1))))²)/(2^(2*n+1)) " by (simp add: add_divide_distrib (*‹(?a + ?b) / ?c = ?a / ?c + ?b / ?c›*)) finally (*calculation: ‹1 = ((cmod (∑k<2 ^ n. (- 1) ^ f k))² + (cmod (∑k<2 ^ n. (- 1) ^ (f k + 1)))²) / 2 ^ (2 * n + 1)›*) have "((2::nat)^(2*n+1)) = (((cmod (∑k::nat<(2::nat)^n. (-1)^(f k))))² + ((cmod(∑k::nat<(2::nat)^n. (-1)^(f k + 1))))²)" by simp moreover have "((2::nat)^(2*n+1)) = 2^(2*n) + 2^(2*n)" by auto moreover have "(cmod (∑k<(2::nat)^n. (-1)^(f k)))² ≤ 2^(2*n)" using prob0_fst_qubits_leq (*‹(cmod (∑k<2 ^ n. (- 1) ^ f k))² ≤ real (2 ^ (2 * n))› ‹(cmod (∑k<2 ^ n. (- 1) ^ (f k + 1)))² ≤ real (2 ^ (2 * n))›*) by simp moreover have "(cmod (∑k<(2::nat)^n. (-1)^(f k + 1)))² ≤ 2^(2*n)" using prob0_fst_qubits_leq (*‹(cmod (∑k<2 ^ n. (- 1) ^ f k))² ≤ real (2 ^ (2 * n))› ‹(cmod (∑k<2 ^ n. (- 1) ^ (f k + 1)))² ≤ real (2 ^ (2 * n))›*) by simp ultimately have "2^(2*n) = ((cmod (∑k::nat<(2::nat)^n. (-1)^(f k))))²" by simp then show "?thesis" (*goal: ‹const 0 ∨ const 1›*) using max_value_of_not_const_less (*‹⟦¬ const (0::nat); ¬ const (1::nat)⟧ ⟹ (cmod (complex_of_int (∑k::nat<(2::nat) ^ (n::nat). (- int (1::nat)) ^ (f::nat ⇒ nat) k)))² < real ((2::nat) ^ ((2::nat) * n))›*) by auto qed text ‹ The function is balanced if and only if at least one qubit among the first n qubits is not zero. So, if the function is balanced then the probability of measuring 0 for the first n qubits is 0. › lemma sum_union_disjoint_finite_set: fixes C::"nat set" and g::"nat ⇒ int" assumes "finite C" shows "∀A B. A ∩ B = {} ∧ A ∪ B = C ⟶ (∑k∈C. g k) = (∑k∈A. g k) + (∑k∈B. g k)" using assms (*‹finite C›*) sum.union_disjoint (*‹⟦finite ?A; finite ?B; ?A ∩ ?B = {}⟧ ⟹ sum ?g (?A ∪ ?B) = sum ?g ?A + sum ?g ?B›*) by auto lemma (in jozsa) balanced_pos_and_neg_terms_cancel_out1: assumes "is_balanced" shows "(∑k<(2::nat)^n. (-(1::nat))^(f k)) = 0" sorry lemma (in jozsa) balanced_pos_and_neg_terms_cancel_out2: assumes "is_balanced" shows "(∑k<(2::nat)^n. (-(1::nat))^(f k + 1)) = 0" proof (-) (*goal: ‹(∑k<2 ^ n. (- int 1) ^ (f k + 1)) = 0›*) have "⋀A B. A ⊆ {i::nat. i < (2::nat)^n} ∧ B ⊆ {i::nat. i < (2::nat)^n} ∧ card A = ((2::nat)^(n-1)) ∧ card B = ((2::nat)^(n-1)) ∧ (∀(x::nat)∈A. f x = (0::nat)) ∧ (∀(x::nat)∈B. f x = 1) ⟶ (∑k<(2::nat)^n. (-(1::nat))^(f k + 1)) = 0" proof (standard) (*goal: ‹⋀A B. A ⊆ {i. i < 2 ^ n} ∧ B ⊆ {i. i < 2 ^ n} ∧ card A = 2 ^ (n - 1) ∧ card B = 2 ^ (n - 1) ∧ (∀x∈A. f x = 0) ∧ (∀x∈B. f x = 1) ⟹ (∑k<2 ^ n. (- int 1) ^ (f k + 1)) = 0›*) fix A :: "nat set" and B :: "nat set" assume asm: "A ⊆ {i::nat. i < (2::nat)^n} ∧ B ⊆ {i::nat. i < (2::nat)^n} ∧ card A = ((2::nat)^(n-1)) ∧ card B = ((2::nat)^(n-1)) ∧ (∀(x::nat) ∈ A. f x = (0::nat)) ∧ (∀(x::nat) ∈ B. f x = 1)" (*‹(A::nat set) ⊆ {i::nat. i < (2::nat) ^ (n::nat)} ∧ (B::nat set) ⊆ {i::nat. i < (2::nat) ^ n} ∧ card A = (2::nat) ^ (n - (1::nat)) ∧ card B = (2::nat) ^ (n - (1::nat)) ∧ (∀x::nat∈A. (f::nat ⇒ nat) x = (0::nat)) ∧ (∀x::nat∈B. f x = (1::nat))›*) have "A ∩ B = {}" and "{0..<(2::nat)^n} = A ∪ B" using is_balanced_union (*‹⟦?A ⊆ {i. i < 2 ^ n}; ?B ⊆ {i. i < 2 ^ n}; card ?A = 2 ^ (n - 1); card ?B = 2 ^ (n - 1); ?A ∩ ?B = {}⟧ ⟹ ?A ∪ ?B = {i. i < 2 ^ n}›*) is_balanced_inter (*‹⟦∀x∈?A. f x = 0; ∀x∈?B. f x = 1⟧ ⟹ ?A ∩ ?B = {}›*) asm (*‹A ⊆ {i. i < 2 ^ n} ∧ B ⊆ {i. i < 2 ^ n} ∧ card A = 2 ^ (n - 1) ∧ card B = 2 ^ (n - 1) ∧ (∀x∈A. f x = 0) ∧ (∀x∈B. f x = 1)›*) apply - (*goals: 1. ‹⟦⋀A B. ⟦A ⊆ {i. i < 2 ^ n}; B ⊆ {i. i < 2 ^ n}; card A = 2 ^ (n - 1); card B = 2 ^ (n - 1); A ∩ B = {}⟧ ⟹ A ∪ B = {i. i < 2 ^ n}; ⋀A B. ⟦∀x∈A. f x = 0; ∀x∈B. f x = 1⟧ ⟹ A ∩ B = {}; A ⊆ {i. i < 2 ^ n} ∧ B ⊆ {i. i < 2 ^ n} ∧ card A = 2 ^ (n - 1) ∧ card B = 2 ^ (n - 1) ∧ (∀x∈A. f x = 0) ∧ (∀x∈B. f x = 1)⟧ ⟹ A ∩ B = {}› 2. ‹⟦⋀A B. ⟦A ⊆ {i. i < 2 ^ n}; B ⊆ {i. i < 2 ^ n}; card A = 2 ^ (n - 1); card B = 2 ^ (n - 1); A ∩ B = {}⟧ ⟹ A ∪ B = {i. i < 2 ^ n}; ⋀A B. ⟦∀x∈A. f x = 0; ∀x∈B. f x = 1⟧ ⟹ A ∩ B = {}; A ⊆ {i. i < 2 ^ n} ∧ B ⊆ {i. i < 2 ^ n} ∧ card A = 2 ^ (n - 1) ∧ card B = 2 ^ (n - 1) ∧ (∀x∈A. f x = 0) ∧ (∀x∈B. f x = 1)⟧ ⟹ {0..<2 ^ n} = A ∪ B› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . then have "(∑k∈{0..<(2::nat)^n}. (-(1::nat))^(f k + 1)) = (∑k∈A. (-(1::nat))^(f k + 1)) + (∑k∈B. (-(1::nat))^(f k + 1))" by (metis finite_atLeastLessThan (*‹finite {?l..<?u}›*) sum_union_disjoint_finite_set (*‹finite ?C ⟹ ∀A B. A ∩ B = {} ∧ A ∪ B = ?C ⟶ sum ?g ?C = sum ?g A + sum ?g B›*)) moreover have "(∑k∈A. (-1)^(f k + 1)) = -((2::nat)^(n-1))" using asm (*‹(A::nat set) ⊆ {i::nat. i < (2::nat) ^ (n::nat)} ∧ (B::nat set) ⊆ {i::nat. i < (2::nat) ^ n} ∧ card A = (2::nat) ^ (n - (1::nat)) ∧ card B = (2::nat) ^ (n - (1::nat)) ∧ (∀x::nat∈A. (f::nat ⇒ nat) x = (0::nat)) ∧ (∀x::nat∈B. f x = (1::nat))›*) by simp moreover have "(∑k∈B. (-1)^(f k + 1)) = ((2::nat)^(n-1))" using asm (*‹A ⊆ {i. i < 2 ^ n} ∧ B ⊆ {i. i < 2 ^ n} ∧ card A = 2 ^ (n - 1) ∧ card B = 2 ^ (n - 1) ∧ (∀x∈A. f x = 0) ∧ (∀x∈B. f x = 1)›*) by simp ultimately have "(∑k∈{0..<(2::nat)^n}. (-(1::nat))^(f k + 1)) = 0 " by simp then show "(∑k<(2::nat)^n. (-(1::nat))^(f k + 1)) = 0" by (simp add: lessThan_atLeast0 (*‹{..<?n} = {0..<?n}›*)) qed then show "(∑k<(2::nat)^n. (-(1::nat))^(f k + 1)) = 0" using assms (*‹is_balanced›*) is_balanced_def (*‹is_balanced ≡ ∃A B. A ⊆ {i. i < 2 ^ n} ∧ B ⊆ {i. i < 2 ^ n} ∧ card A = 2 ^ (n - 1) ∧ card B = 2 ^ (n - 1) ∧ (∀x∈A. f x = 0) ∧ (∀x∈B. f x = 1)›*) by auto qed lemma (in jozsa) prob0_jozsa_algo_of_balanced: assumes "is_balanced" shows "prob0_fst_qubits n jozsa_algo = 0" proof (-) (*goal: ‹prob0_fst_qubits n jozsa_algo = 0›*) have "prob0_fst_qubits n jozsa_algo = (∑j∈{0,1}. (cmod(jozsa_algo $$ (j,0)))²)" using prob0_fst_qubits_of_jozsa_algo (*‹prob0_fst_qubits n jozsa_algo = (∑j∈{0, 1}. (cmod (jozsa_algo $$ (j, 0)))²)›*) by simp moreover have "(cmod(jozsa_algo $$ (0,0)))² = 0" proof (-) (*goal: ‹(cmod (jozsa_algo $$ (0, 0)))² = 0›*) have "k < 2^n⟶((1 div 2) ⋅⇘n⇙ k) = 0" for k :: nat using bitwise_inner_prod_with_zero (*‹?m < 2 ^ ?n ⟹ 0 ⋅⇘?n⇙ ?m = 0›*) by simp then have "(cmod(jozsa_algo $$ (0,0)))² = (cmod(∑ k < (2::nat)^n. (-1)^(f k)/(sqrt(2)^n * sqrt(2)^(n+1))))²" using "ψ₃_values" (*‹?i < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1))))) ⟹ odd ?i ⟶ Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))) $$ (?i, 0) = complex_of_real (∑k<2 ^ n. (- 1) ^ (f k + 1 + ?i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))›*) by simp also (*calculation: ‹(cmod (jozsa_algo $$ (0, 0)))² = (cmod (complex_of_real (∑k<2 ^ n. (- 1) ^ f k / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))²›*) have "... = (cmod(∑k<(2::nat)^n. (-(1::nat))^(f k))/(sqrt(2)^n * sqrt(2)^(n+1)))²" using aux_comp_sum_divide_cmod[of "λk.(-(1::nat))^(f k)" "(sqrt(2)^n * sqrt(2)^(n+1))" "2^n"] (*‹(cmod (complex_of_real (∑k<2 ^ n. real_of_int ((- int 1) ^ f k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))² = (cmod (complex_of_int (∑k<2 ^ n. (- int 1) ^ f k)) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))²›*) by simp also (*calculation: ‹(cmod (jozsa_algo $$ (0, 0)))² = (cmod (complex_of_int (∑k<2 ^ n. (- int 1) ^ f k)) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))²›*) have "... = (cmod ((0::int)/(sqrt(2)^n * sqrt(2)^(n+1))))²" using balanced_pos_and_neg_terms_cancel_out1 (*‹is_balanced ⟹ (∑k::nat<(2::nat) ^ (n::nat). (- int (1::nat)) ^ (f::nat ⇒ nat) k) = (0::int)›*) assms (*‹is_balanced›*) by (simp add: bob_fun_axioms (*‹bob_fun f n›*)) also (*calculation: ‹(cmod (jozsa_algo $$ (0, 0)))² = (cmod (complex_of_real (real_of_int 0 / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))²›*) have "... = 0" by simp finally (*calculation: ‹(cmod (jozsa_algo $$ (0, 0)))² = 0›*) show "?thesis" (*goal: ‹(cmod (jozsa_algo $$ (0, 0)))² = 0›*) by simp qed moreover have "(cmod(jozsa_algo $$ (1,0)))² = 0" proof (-) (*goal: ‹(cmod (jozsa_algo $$ (1::nat, 0::nat)))² = (0::real)›*) have "k < 2^n ⟶ (((1::nat) div 2) ⋅⇘n⇙ k) = 0" for k :: nat using bitwise_inner_prod_with_zero (*‹?m < 2 ^ ?n ⟹ 0 ⋅⇘?n⇙ ?m = 0›*) by auto moreover have "(cmod(jozsa_algo $$ (1,0)))² = (cmod (∑k<(2::nat)^n. (-(1::nat))^(f k + (1::nat) + ((1 div 2) ⋅⇘n⇙ k))/(sqrt(2)^n * sqrt(2)^(n+1))))²" using "ψ₃_dim" (*‹1 < dim_row (Matrix.mat (2 ^ (n + 1)) 1 (λx. complex_of_real (case x of (i, j) ⇒ if even i then ∑k<2 ^ n. (- 1) ^ (f k + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)) else ∑k<2 ^ n. (- 1) ^ (f k + 1 + i div 2 ⋅⇘n⇙ k) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))›*) by simp ultimately have "(cmod(jozsa_algo $$ (1,0)))² = (cmod(∑k<(2::nat)^n. (-(1::nat))^(f k + (1::nat))/(sqrt(2)^n * sqrt(2)^(n+1))))²" by simp also (*calculation: ‹(cmod (jozsa_algo $$ (1, 0)))² = (cmod (complex_of_real (∑k<2 ^ n. real_of_int ((- int 1) ^ (f k + 1)) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))))²›*) have "... = (cmod(∑k<(2::nat)^n. (-(1::nat))^(f k + 1))/(sqrt(2)^n * sqrt(2)^(n+1)))²" using aux_comp_sum_divide_cmod[of "λk.(-(1::nat))^(f k + 1)" "(sqrt(2)^n * sqrt(2)^(n+1))" "2^n"] (*‹(cmod (complex_of_real (∑k::nat<(2::nat) ^ n. real_of_int ((- int (1::nat)) ^ ((f::nat ⇒ nat) k + (1::nat))) / (sqrt (2::real) ^ (n::nat) * sqrt (2::real) ^ (n + (1::nat))))))² = (cmod (complex_of_int (∑k::nat<(2::nat) ^ n. (- int (1::nat)) ^ (f k + (1::nat)))) / (sqrt (2::real) ^ n * sqrt (2::real) ^ (n + (1::nat))))²›*) by simp also (*calculation: ‹(cmod (jozsa_algo $$ (1, 0)))² = (cmod (complex_of_int (∑k<2 ^ n. (- int 1) ^ (f k + 1))) / (sqrt 2 ^ n * sqrt 2 ^ (n + 1)))²›*) have "... = (cmod ((0::int)/(sqrt(2)^n * sqrt(2)^(n+1))))²" using balanced_pos_and_neg_terms_cancel_out2 (*‹is_balanced ⟹ (∑k<2 ^ n. (- int 1) ^ (f k + 1)) = 0›*) assms (*‹is_balanced›*) by (simp add: bob_fun_axioms (*‹bob_fun f n›*)) also (*calculation: ‹(cmod (jozsa_algo $$ (1::nat, 0::nat)))² = (cmod (complex_of_real (real_of_int (0::int) / (sqrt (2::real) ^ (n::nat) * sqrt (2::real) ^ (n + (1::nat))))))²›*) have "... = 0" by simp finally (*calculation: ‹(cmod (jozsa_algo $$ (1, 0)))² = 0›*) show "?thesis" (*goal: ‹(cmod (jozsa_algo $$ (1::nat, 0::nat)))² = (0::real)›*) by simp qed ultimately have "prob0_fst_qubits n jozsa_algo = 0 + 0" by simp then show "?thesis" (*goal: ‹prob0_fst_qubits n jozsa_algo = 0›*) by simp qed text ‹If the probability that the first n qubits are 0 is 0, then the function is balanced.› lemma (in jozsa) balanced_prob0_jozsa_algo: assumes "prob0_fst_qubits n jozsa_algo = 0" shows "is_balanced" proof (-) (*goal: ‹is_balanced›*) have "is_const ∨ is_balanced" using const_or_balanced (*‹is_const ∨ is_balanced›*) by simp moreover have "is_const ⟶ ¬ prob0_fst_qubits n jozsa_algo = 0" using is_const_def (*‹is_const ≡ const (0::nat) ∨ const (1::nat)›*) prob0_jozsa_algo_of_const_0 (*‹const 0 ⟹ prob0_fst_qubits n jozsa_algo = 1›*) prob0_jozsa_algo_of_const_1 (*‹const (1::nat) ⟹ prob0_fst_qubits (n::nat) jozsa_algo = (1::real)›*) by simp ultimately show "?thesis" (*goal: ‹is_balanced›*) using assms (*‹prob0_fst_qubits n jozsa_algo = 0›*) by simp qed text ‹We prove the correctness of the algorithm.› definition (in jozsa) jozsa_algo_eval:: "real" where "jozsa_algo_eval ≡ prob0_fst_qubits n jozsa_algo" theorem (in jozsa) jozsa_algo_is_correct: shows "jozsa_algo_eval = 1 ⟷ is_const" and "jozsa_algo_eval = 0 ⟷ is_balanced" using prob0_jozsa_algo_of_const_1 (*‹const 1 ⟹ prob0_fst_qubits n jozsa_algo = 1›*) prob0_jozsa_algo_of_const_0 (*‹const 0 ⟹ prob0_fst_qubits n jozsa_algo = 1›*) jozsa_algo_eval_def (*‹jozsa_algo_eval ≡ prob0_fst_qubits (n::nat) jozsa_algo›*) prob0_jozsa_algo_1_is_const (*‹prob0_fst_qubits n jozsa_algo = 1 ⟹ const 0 ∨ const 1›*) is_const_def (*‹is_const ≡ const 0 ∨ const 1›*) balanced_prob0_jozsa_algo (*‹prob0_fst_qubits (n::nat) jozsa_algo = (0::real) ⟹ is_balanced›*) prob0_jozsa_algo_of_balanced (*‹is_balanced ⟹ prob0_fst_qubits n jozsa_algo = 0›*) apply - (*goals: 1. ‹⟦const 1 ⟹ prob0_fst_qubits n jozsa_algo = 1; const 0 ⟹ prob0_fst_qubits n jozsa_algo = 1; jozsa_algo_eval ≡ prob0_fst_qubits n jozsa_algo; prob0_fst_qubits n jozsa_algo = 1 ⟹ const 0 ∨ const 1; is_const ≡ const 0 ∨ const 1; prob0_fst_qubits n jozsa_algo = 0 ⟹ is_balanced; is_balanced ⟹ prob0_fst_qubits n jozsa_algo = 0⟧ ⟹ (jozsa_algo_eval = 1) = is_const› 2. ‹⟦const 1 ⟹ prob0_fst_qubits n jozsa_algo = 1; const 0 ⟹ prob0_fst_qubits n jozsa_algo = 1; jozsa_algo_eval ≡ prob0_fst_qubits n jozsa_algo; prob0_fst_qubits n jozsa_algo = 1 ⟹ const 0 ∨ const 1; is_const ≡ const 0 ∨ const 1; prob0_fst_qubits n jozsa_algo = 0 ⟹ is_balanced; is_balanced ⟹ prob0_fst_qubits n jozsa_algo = 0⟧ ⟹ (jozsa_algo_eval = 0) = is_balanced› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . end
{ "path": "afp-2025-02-12/thys/Isabelle_Marries_Dirac/Deutsch_Jozsa.thy", "repo": "afp-2025-02-12", "sha": "a3a135605aa0c8b6a893c9f6fbfb40e656eda61f597c54b631c8a2c92a92ba77" }
(* Title: variants/a_norreqid/Loop_Freedom.thy License: BSD 2-Clause. See LICENSE. Author: Timothy Bourke, Inria *) section "Routing graphs and loop freedom" theory A_Loop_Freedom imports A_Aodv_Predicates A_Fresher begin text ‹Define the central theorem that relates an invariant over network states to the absence of loops in the associate routing graph.› definition rt_graph :: "(ip ⇒ state) ⇒ ip ⇒ ip rel" where "rt_graph σ = (λdip. {(ip, ip') | ip ip' dsn dsk hops pre. ip ≠ dip ∧ rt (σ ip) dip = Some (dsn, dsk, val, hops, ip', pre)})" text ‹Given the state of a network @{term σ}, a routing graph for a given destination ip address @{term dip} abstracts the details of routing tables into nodes (ip addresses) and vertices (valid routes between ip addresses).› lemma rt_graphE [elim]: fixes n dip ip ip' assumes "(ip, ip') ∈ rt_graph σ dip" shows "ip ≠ dip ∧ (∃r. rt (σ ip) = r ∧ (∃dsn dsk hops pre. r dip = Some (dsn, dsk, val, hops, ip', pre)))" using assms (*‹(ip, ip') ∈ rt_graph σ dip›*) unfolding rt_graph_def (*goal: ‹ip ≠ dip ∧ (∃r. rt (σ ip) = r ∧ (∃dsn dsk hops pre. r dip = Some (dsn, dsk, val, hops, ip', pre)))›*) by auto lemma rt_graph_vD [dest]: "⋀ip ip' σ dip. (ip, ip') ∈ rt_graph σ dip ⟹ dip ∈ vD(rt (σ ip))" unfolding rt_graph_def vD_def (*goal: ‹⋀ip ip' σ dip. (ip, ip') ∈ {uu_. ∃ip ip' dsn dsk hops pre. uu_ = (ip, ip') ∧ ip ≠ dip ∧ rt (σ ip) dip = Some (dsn, dsk, val, hops, ip', pre)} ⟹ dip ∈ {dip. flag (rt (σ ip)) dip = Some val}›*) by auto lemma rt_graph_vD_trans [dest]: "⋀ip ip' σ dip. (ip, ip') ∈ (rt_graph σ dip)⁺ ⟹ dip ∈ vD(rt (σ ip))" apply (erule converse_tranclE (*‹⟦(?x::?'a::type, ?z::?'a::type) ∈ (?r::(?'a::type × ?'a::type) set)⁺; (?x, ?z) ∈ ?r ⟹ ?P::bool; ⋀y::?'a::type. ⟦(?x, y) ∈ ?r; (y, ?z) ∈ ?r⁺⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹⋀ip ip' σ dip. (ip, ip') ∈ rt_graph σ dip ⟹ dip ∈ vD (rt (σ ip))› 2. ‹⋀ip ip' σ dip y. ⟦(ip, y) ∈ rt_graph σ dip; (y, ip') ∈ (rt_graph σ dip)⁺⟧ ⟹ dip ∈ vD (rt (σ ip))› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . lemma rt_graph_not_dip [dest]: "⋀ip ip' σ dip. (ip, ip') ∈ rt_graph σ dip ⟹ ip ≠ dip" unfolding rt_graph_def (*goal: ‹⋀ip ip' σ dip. (ip, ip') ∈ {uu_. ∃ip ip' dsn dsk hops pre. uu_ = (ip, ip') ∧ ip ≠ dip ∧ rt (σ ip) dip = Some (dsn, dsk, val, hops, ip', pre)} ⟹ ip ≠ dip›*) by auto lemma rt_graph_not_dip_trans [dest]: "⋀ip ip' σ dip. (ip, ip') ∈ (rt_graph σ dip)⁺ ⟹ ip ≠ dip" apply (erule converse_tranclE (*‹⟦(?x, ?z) ∈ ?r⁺; (?x, ?z) ∈ ?r ⟹ ?P; ⋀y. ⟦(?x, y) ∈ ?r; (y, ?z) ∈ ?r⁺⟧ ⟹ ?P⟧ ⟹ ?P›*)) (*goals: 1. ‹⋀ip ip' σ dip. (ip, ip') ∈ rt_graph σ dip ⟹ ip ≠ dip› 2. ‹⋀ip ip' σ dip y. ⟦(ip, y) ∈ rt_graph σ dip; (y, ip') ∈ (rt_graph σ dip)⁺⟧ ⟹ ip ≠ dip› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . text "NB: the property below cannot be lifted to the transitive closure" lemma rt_graph_nhip_is_nhop [dest]: "⋀ip ip' σ dip. (ip, ip') ∈ rt_graph σ dip ⟹ ip' = the (nhop (rt (σ ip)) dip)" unfolding rt_graph_def (*goal: ‹⋀ip ip' σ dip. (ip, ip') ∈ {uu_. ∃ip ip' dsn dsk hops pre. uu_ = (ip, ip') ∧ ip ≠ dip ∧ rt (σ ip) dip = Some (dsn, dsk, val, hops, ip', pre)} ⟹ ip' = the (nhop (rt (σ ip)) dip)›*) by auto theorem inv_to_loop_freedom: assumes "∀i dip. let nhip = the (nhop (rt (σ i)) dip) in dip ∈ vD (rt (σ i)) ∩ vD (rt (σ nhip)) ∧ nhip ≠ dip ⟶ (rt (σ i)) ⊏⇘dip⇙ (rt (σ nhip))" shows "∀dip. irrefl ((rt_graph σ dip)⁺)" using assms (*‹∀i dip. let nhip = the (nhop (rt (σ i)) dip) in dip ∈ vD (rt (σ i)) ∩ vD (rt (σ nhip)) ∧ nhip ≠ dip ⟶ rt (σ i) ⊏⇘dip⇙ rt (σ nhip)›*) proof (intro allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*)) (*goal: ‹⋀dip. ∀i dip. let nhip = the (nhop (rt (σ i)) dip) in dip ∈ vD (rt (σ i)) ∩ vD (rt (σ nhip)) ∧ nhip ≠ dip ⟶ rt (σ i) ⊏⇘dip⇙ rt (σ nhip) ⟹ irrefl ((rt_graph σ dip)⁺)›*) fix σ :: "ip ⇒ state" and dip assume inv: "∀ip dip. let nhip = the (nhop (rt (σ ip)) dip) in dip ∈ vD(rt (σ ip)) ∩ vD(rt (σ nhip)) ∧ nhip ≠ dip ⟶ rt (σ ip) ⊏⇘dip⇙ rt (σ nhip)" (*‹∀(ip::nat) dip::nat. let nhip::nat = the (nhop (rt ((σ::nat ⇒ state) ip)) dip) in dip ∈ vD (rt (σ ip)) ∩ vD (rt (σ nhip)) ∧ nhip ≠ dip ⟶ rt (σ ip) ⊏⇘dip⇙ rt (σ nhip)›*) { fix ip and ip' assume "(ip, ip') ∈ (rt_graph σ dip)⁺" and "dip ∈ vD(rt (σ ip'))" and "ip' ≠ dip" (*‹(ip::nat, ip'::nat) ∈ (rt_graph (σ::nat ⇒ state) (dip::nat))⁺› ‹(dip::nat) ∈ vD (rt ((σ::nat ⇒ state) (ip'::nat)))› ‹(ip'::nat) ≠ (dip::nat)›*) hence "rt (σ ip) ⊏⇘dip⇙ rt (σ ip')" proof (induction) (*goals: 1. ‹⋀y. ⟦(ip, y) ∈ rt_graph σ dip; dip ∈ vD (rt (σ y)); y ≠ dip⟧ ⟹ rt (σ ip) ⊏⇘dip⇙ rt (σ y)› 2. ‹⋀y z. ⟦(ip, y) ∈ (rt_graph σ dip)⁺; (y, z) ∈ rt_graph σ dip; ⟦dip ∈ vD (rt (σ y)); y ≠ dip⟧ ⟹ rt (σ ip) ⊏⇘dip⇙ rt (σ y); dip ∈ vD (rt (σ z)); z ≠ dip⟧ ⟹ rt (σ ip) ⊏⇘dip⇙ rt (σ z)›*) fix nhip assume "(ip, nhip) ∈ rt_graph σ dip" and "dip ∈ vD(rt (σ nhip))" and "nhip ≠ dip" (*‹(ip::nat, nhip::nat) ∈ rt_graph (σ::nat ⇒ state) (dip::nat)› ‹(dip::nat) ∈ vD (rt ((σ::nat ⇒ state) (nhip::nat)))› ‹(nhip::nat) ≠ (dip::nat)›*) from ‹(ip, nhip) ∈ rt_graph σ dip› (*‹(ip, nhip) ∈ rt_graph σ dip›*) have "dip ∈ vD(rt (σ ip))" and "nhip = the (nhop (rt (σ ip)) dip)" apply - (*goals: 1. ‹(ip::nat, nhip::nat) ∈ rt_graph (σ::nat ⇒ state) (dip::nat) ⟹ dip ∈ vD (rt (σ ip))› 2. ‹(ip::nat, nhip::nat) ∈ rt_graph (σ::nat ⇒ state) (dip::nat) ⟹ nhip = the (nhop (rt (σ ip)) dip)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . from ‹dip ∈ vD(rt (σ ip))› (*‹dip ∈ vD (rt (σ ip))›*) ‹dip ∈ vD(rt (σ nhip))› (*‹dip ∈ vD (rt (σ nhip))›*) have "dip ∈ vD(rt (σ ip)) ∩ vD(rt (σ nhip))" by standard with ‹nhip = the (nhop (rt (σ ip)) dip)› (*‹(nhip::nat) = the (nhop (rt ((σ::nat ⇒ state) (ip::nat))) (dip::nat))›*) ‹nhip ≠ dip› (*‹(nhip::nat) ≠ (dip::nat)›*) inv (*‹∀(ip::nat) dip::nat. let nhip::nat = the (nhop (rt ((σ::nat ⇒ state) ip)) dip) in dip ∈ vD (rt (σ ip)) ∩ vD (rt (σ nhip)) ∧ nhip ≠ dip ⟶ rt (σ ip) ⊏⇘dip⇙ rt (σ nhip)›*) show "rt (σ ip) ⊏⇘dip⇙ rt (σ nhip)" by (clarsimp simp: Let_def (*‹Let ?s ?f ≡ ?f ?s›*)) next (*goal: ‹⋀y z. ⟦(ip, y) ∈ (rt_graph σ dip)⁺; (y, z) ∈ rt_graph σ dip; ⟦dip ∈ vD (rt (σ y)); y ≠ dip⟧ ⟹ rt (σ ip) ⊏⇘dip⇙ rt (σ y); dip ∈ vD (rt (σ z)); z ≠ dip⟧ ⟹ rt (σ ip) ⊏⇘dip⇙ rt (σ z)›*) fix nhip and nhip' assume "(ip, nhip) ∈ (rt_graph σ dip)⁺" and "(nhip, nhip') ∈ rt_graph σ dip" and IH: "⟦ dip ∈ vD(rt (σ nhip)); nhip ≠ dip ⟧ ⟹ rt (σ ip) ⊏⇘dip⇙ rt (σ nhip)" and "dip ∈ vD(rt (σ nhip'))" and "nhip' ≠ dip" (*‹(ip::nat, nhip::nat) ∈ (rt_graph (σ::nat ⇒ state) (dip::nat))⁺› ‹(nhip::nat, nhip'::nat) ∈ rt_graph (σ::nat ⇒ state) (dip::nat)› ‹⟦(dip::nat) ∈ vD (rt ((σ::nat ⇒ state) (nhip::nat))); nhip ≠ dip⟧ ⟹ rt (σ (ip::nat)) ⊏⇘dip⇙ rt (σ nhip)› ‹(dip::nat) ∈ vD (rt ((σ::nat ⇒ state) (nhip'::nat)))› ‹(nhip'::nat) ≠ (dip::nat)›*) from ‹(nhip, nhip') ∈ rt_graph σ dip› (*‹(nhip, nhip') ∈ rt_graph σ dip›*) have 1: "dip ∈ vD(rt (σ nhip))" and 2: "nhip ≠ dip" and "nhip' = the (nhop (rt (σ nhip)) dip)" apply - (*goals: 1. ‹(nhip, nhip') ∈ rt_graph σ dip ⟹ dip ∈ vD (rt (σ nhip))› 2. ‹(nhip, nhip') ∈ rt_graph σ dip ⟹ nhip ≠ dip› 3. ‹(nhip, nhip') ∈ rt_graph σ dip ⟹ nhip' = the (nhop (rt (σ nhip)) dip)› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*discuss goal 3*) apply ((auto)[1]) (*proven 3 subgoals*) . from "1" (*‹dip ∈ vD (rt (σ nhip))›*) "2" (*‹(nhip::nat) ≠ (dip::nat)›*) have "rt (σ ip) ⊏⇘dip⇙ rt (σ nhip)" by (rule IH (*‹⟦dip ∈ vD (rt (σ nhip)); nhip ≠ dip⟧ ⟹ rt (σ ip) ⊏⇘dip⇙ rt (σ nhip)›*)) also (*calculation: ‹rt ((σ::nat ⇒ state) (ip::nat)) ⊏⇘(dip::nat)⇙ rt (σ (nhip::nat))›*) have "rt (σ nhip) ⊏⇘dip⇙ rt (σ nhip')" proof (-) (*goal: ‹rt ((σ::nat ⇒ state) (nhip::nat)) ⊏⇘(dip::nat)⇙ rt (σ (nhip'::nat))›*) from ‹dip ∈ vD(rt (σ nhip))› (*‹dip ∈ vD (rt (σ nhip))›*) ‹dip ∈ vD(rt (σ nhip'))› (*‹dip ∈ vD (rt (σ nhip'))›*) have "dip ∈ vD(rt (σ nhip)) ∩ vD(rt (σ nhip'))" by standard with ‹nhip' ≠ dip› (*‹nhip' ≠ dip›*) ‹nhip' = the (nhop (rt (σ nhip)) dip)› (*‹(nhip'::nat) = the (nhop (rt ((σ::nat ⇒ state) (nhip::nat))) (dip::nat))›*) inv (*‹∀ip dip. let nhip = the (nhop (rt (σ ip)) dip) in dip ∈ vD (rt (σ ip)) ∩ vD (rt (σ nhip)) ∧ nhip ≠ dip ⟶ rt (σ ip) ⊏⇘dip⇙ rt (σ nhip)›*) show "rt (σ nhip) ⊏⇘dip⇙ rt (σ nhip')" by (clarsimp simp: Let_def (*‹Let (?s::?'a::type) (?f::?'a::type ⇒ ?'b::type) ≡ ?f ?s›*)) qed finally (*calculation: ‹rt (σ ip) ⊏⇘dip⇙ rt (σ nhip')›*) show "rt (σ ip) ⊏⇘dip⇙ rt (σ nhip')" . qed } note fresher = this (*‹⟦(?ip2, ?ip'2) ∈ (rt_graph σ dip)⁺; dip ∈ vD (rt (σ ?ip'2)); ?ip'2 ≠ dip⟧ ⟹ rt (σ ?ip2) ⊏⇘dip⇙ rt (σ ?ip'2)›*) show "irrefl ((rt_graph σ dip)⁺)" unfolding irrefl_def (*goal: ‹∀a. (a, a) ∉ (rt_graph σ dip)⁺›*) proof (intro allI (*‹(⋀x. ?P x) ⟹ ∀x. ?P x›*) notI (*‹(?P ⟹ False) ⟹ ¬ ?P›*)) (*goal: ‹⋀a. (a, a) ∈ (rt_graph σ dip)⁺ ⟹ False›*) fix ip assume "(ip, ip) ∈ (rt_graph σ dip)⁺" (*‹(ip::nat, ip) ∈ (rt_graph (σ::nat ⇒ state) (dip::nat))⁺›*) moreover then have "dip ∈ vD(rt (σ ip))" and "ip ≠ dip" apply - (*goals: 1. ‹(ip, ip) ∈ (rt_graph σ dip)⁺ ⟹ dip ∈ vD (rt (σ ip))› 2. ‹(ip, ip) ∈ (rt_graph σ dip)⁺ ⟹ ip ≠ dip› discuss goal 1*) apply ((auto)[1]) (*discuss goal 2*) apply ((auto)[1]) (*proven 2 subgoals*) . ultimately have "rt (σ ip) ⊏⇘dip⇙ rt (σ ip)" by (rule fresher (*‹⟦(?ip2, ?ip'2) ∈ (rt_graph σ dip)⁺; dip ∈ vD (rt (σ ?ip'2)); ?ip'2 ≠ dip⟧ ⟹ rt (σ ?ip2) ⊏⇘dip⇙ rt (σ ?ip'2)›*)) thus False by simp qed qed end
{ "path": "afp-2025-02-12/thys/AODV/variants/a_norreqid/A_Loop_Freedom.thy", "repo": "afp-2025-02-12", "sha": "c6234458e16f884cc7b13d457dae6a2d35c10643028bd8ce549b129f107b0586" }